Skip to content

Commit

Permalink
Merge pull request #3 from joyent/fix_some
Browse files Browse the repository at this point in the history
Fix some of bugs
  • Loading branch information
jiho-jung authored Jan 11, 2025
2 parents 4aa0797 + df25eb5 commit b289dab
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 32 deletions.
2 changes: 1 addition & 1 deletion openflow15/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 4 additions & 0 deletions openflow15/instruction.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions openflow15/match.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
36 changes: 7 additions & 29 deletions openflow15/multipart.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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:])
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions openflow15/openflow15.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit b289dab

Please sign in to comment.