Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MultipartType_PortDesc and PortStatus #4

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 46 additions & 2 deletions openflow13/multipart.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ package openflow13

import (
"encoding/binary"

"fmt"
log "github.com/Sirupsen/logrus"

"github.com/contiv/libOpenflow/common"
"github.com/contiv/libOpenflow/util"
)
Expand Down Expand Up @@ -141,9 +140,13 @@ func (s *MultipartReply) UnmarshalBinary(data []byte) error {
repl = new(TableStats)
case MultipartType_Queue:
repl = new(QueueStats)
case MultipartType_PortDesc:
repl = new(PortDesc)
// FIXME: Support all types
case MultipartType_Experimenter:
break
default:
return fmt.Errorf("No kown mp type ")
}

err = repl.UnmarshalBinary(data[n:])
Expand Down Expand Up @@ -919,6 +922,7 @@ func NewPortStatus() *PortStatus {
p := new(PortStatus)
p.Header = NewOfp13Header()
p.pad = make([]byte, 7)
p.Desc = *NewPhyPort()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please nil check.

return p
}

Expand Down Expand Up @@ -958,6 +962,46 @@ func (s *PortStatus) UnmarshalBinary(data []byte) error {
return err
}

///Port Description reply
type PortDesc struct {
ports []*PhyPort
}

func (s PortDesc) Len() (n uint16) {
n = 0
for _, r := range s.ports {
n += uint16(r.Len())
}
return
}

func (s *PortDesc) MarshalBinary() (data []byte, err error) {
b := make([]byte, 8)

for _, r := range s.ports {
b, err = r.MarshalBinary()
data = append(data, b...)
}
return
}
func (s *PortDesc) UnmarshalBinary(data []byte) error {

nPorts := (len(data)) / 64
if nPorts == 0 {
return nil
}
s.ports = make([]*PhyPort, nPorts)
for i := 0; i < nPorts; i++ {
buf := data[i*64:]
s.ports[i] = NewPhyPort()
if err := s.ports[i].UnmarshalBinary(buf[0:64]); err != nil {
return err
}
}

return nil
}

// ofp_port_reason 1.0
const (
PR_ADD = iota
Expand Down
2 changes: 1 addition & 1 deletion openflow13/openflow13.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func Parse(b []byte) (message util.Message, err error) {
message = NewFlowRemoved()
err = message.UnmarshalBinary(b)
case Type_PortStatus:
message = new(PortStatus)
message = NewPortStatus()
err = message.UnmarshalBinary(b)
case Type_PacketOut:
break
Expand Down
2 changes: 2 additions & 0 deletions openflow13/port.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ func NewPhyPort() *PhyPort {
p := new(PhyPort)
p.HWAddr = make([]byte, ETH_ALEN)
p.Name = make([]byte, 16)
p.pad = make([]byte, 4)
p.pad2 = make([]byte, 2)
return p
}

Expand Down