diff --git a/openflow13/multipart.go b/openflow13/multipart.go index 38cb1bc..505a600 100644 --- a/openflow13/multipart.go +++ b/openflow13/multipart.go @@ -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" ) @@ -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:]) @@ -919,6 +922,7 @@ func NewPortStatus() *PortStatus { p := new(PortStatus) p.Header = NewOfp13Header() p.pad = make([]byte, 7) + p.Desc = *NewPhyPort() return p } @@ -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 diff --git a/openflow13/openflow13.go b/openflow13/openflow13.go index ea83c9b..72c008b 100644 --- a/openflow13/openflow13.go +++ b/openflow13/openflow13.go @@ -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 diff --git a/openflow13/port.go b/openflow13/port.go index 57c6b30..a5535c0 100644 --- a/openflow13/port.go +++ b/openflow13/port.go @@ -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 }