diff --git a/openflow15/action.go b/openflow15/action.go index 559457e..a3bfe3c 100644 --- a/openflow15/action.go +++ b/openflow15/action.go @@ -88,7 +88,7 @@ func DecodeAction(data []byte) (Action, error) { case ActionType_PushVlan: a = new(ActionPush) case ActionType_PopVlan: - a = new(ActionHeader) + a = new(ActionPopVlan) case ActionType_PushMpls: a = new(ActionPush) case ActionType_PopMpls: diff --git a/openflow15/instruction.go b/openflow15/instruction.go index 69fe787..688f0a5 100644 --- a/openflow15/instruction.go +++ b/openflow15/instruction.go @@ -80,6 +80,10 @@ func DecodeInstr(data []byte) (Instruction, error) { return nil, fmt.Errorf("unknown Instrheader type: %v", t) } + if a == nil { + return nil, fmt.Errorf("No supported Instrheader type: %v", t) + } + err := a.UnmarshalBinary(data) if err != nil { klog.ErrorS(err, "Failed to unmarshal Instruction", "data", data) diff --git a/openflow15/match.go b/openflow15/match.go index bb06fa9..9b79135 100644 --- a/openflow15/match.go +++ b/openflow15/match.go @@ -566,6 +566,11 @@ func DecodeMatchField(class uint16, field uint8, length uint8, hasMask bool, dat return nil, err } + if val == nil { + err := fmt.Errorf("Not supported field for nxm_1: %v", field) + return nil, err + } + err := val.UnmarshalBinary(data) if err != nil { klog.ErrorS(err, "Failed to unmarshal Nxm Field", "data", data) diff --git a/openflow15/multipart.go b/openflow15/multipart.go index ac10a7f..859f8ce 100644 --- a/openflow15/multipart.go +++ b/openflow15/multipart.go @@ -83,7 +83,7 @@ func (s *MultipartRequest) UnmarshalBinary(data []byte) error { // The request body is empty. case MultipartType_Port: // The request body is struct ofp_port_multipart_request. - req = new(PortMultipartRequst) + req = new(PortMultipartRequest) case MultipartType_QueueStats: // The request body is struct ofp_queue_multipart_request. req = new(QueueMultipartRequest) @@ -189,7 +189,6 @@ func (s *MultipartReply) UnmarshalBinary(data []byte) error { return err } n := s.Header.Len() - s.Type = binary.BigEndian.Uint16(data[n:]) n += 2 s.Flags = binary.BigEndian.Uint16(data[n:]) @@ -863,29 +862,29 @@ const ( ) // ofp_port_multipart_request -type PortMultipartRequst struct { +type PortMultipartRequest struct { PortNo uint32 pad []uint8 // Size 4 } -func NewPortStatsRequest(port uint32) *PortMultipartRequst { - p := new(PortMultipartRequst) +func NewPortStatsRequest(port uint32) *PortMultipartRequest { + p := new(PortMultipartRequest) p.pad = make([]byte, 4) p.PortNo = port return p } -func (s *PortMultipartRequst) Len() (n uint16) { +func (s *PortMultipartRequest) Len() (n uint16) { return 8 } -func (s *PortMultipartRequst) MarshalBinary() (data []byte, err error) { +func (s *PortMultipartRequest) MarshalBinary() (data []byte, err error) { data = make([]byte, int(s.Len())) binary.BigEndian.PutUint32(data, s.PortNo) return } -func (s *PortMultipartRequst) UnmarshalBinary(data []byte) error { +func (s *PortMultipartRequest) UnmarshalBinary(data []byte) error { s.PortNo = binary.BigEndian.Uint32(data) return nil } @@ -2867,33 +2866,12 @@ func (m *MeterFeatures) UnmarshalBinary(data []byte) (err error) { return } -// ofp_port_multipart_request -type PortMultipartRequest struct { - PortNo uint32 - Pad []byte // 4 bytes -} - func NewPortMultipartRequest(num uint32) *PortMultipartRequest { n := new(PortMultipartRequest) n.PortNo = num return n } -func (p *PortMultipartRequest) Len() uint16 { - return 8 -} - -func (p *PortMultipartRequest) MarshalBinary() (data []byte, err error) { - data = make([]byte, p.Len()) - binary.BigEndian.PutUint32(data[0:], p.PortNo) - return -} - -func (p *PortMultipartRequest) UnmarshalBinary(data []byte) (err error) { - p.PortNo = binary.BigEndian.Uint32(data) - return -} - // ofp_queue_desc type QueueDesc struct { PortNo uint32 diff --git a/openflow15/openflow15.go b/openflow15/openflow15.go index fd58f47..11ccd87 100644 --- a/openflow15/openflow15.go +++ b/openflow15/openflow15.go @@ -1510,7 +1510,9 @@ func (p *PropExperimenter) Len() uint16 { l := uint16(len(p.Data) * 4) n += l //n += uint16((8 - (l % 8)) % 8) // pad to make multiple of 8 - n += uint16(8 - (l % 8)) // pad to make multiple of 8 + //n += uint16(8 - (l % 8)) // pad to make multiple of 8 + n += uint16((8 - (n % 8)) % 8) // pad to make multiple of 8 + return n } @@ -1547,7 +1549,7 @@ func (p *PropExperimenter) UnmarshalBinary(data []byte) (err error) { p.ExpType = binary.BigEndian.Uint32(data[n:]) n += 4 - for n < p.Header.Length+p.Header.Len() { + for n < p.Header.Length { d := binary.BigEndian.Uint32(data[n:]) p.Data = append(p.Data, d) n += 4