Skip to content

Commit

Permalink
Support ICMPv4 match/set action and fix a typo (#11)
Browse files Browse the repository at this point in the history
1, support ICMPv4 match/set action;
2, fix a typo "SLL" -> "TLL" in NdTll match action.

Co-authored-by: Linan Zheng
Signed-off-by: Linan Zheng
Signed-off-by: Gao Jinjun <[email protected]>

Co-authored-by: Gao Jinjun <[email protected]>
  • Loading branch information
commandgjj and Gao Jinjun authored Dec 1, 2021
1 parent 2bbc405 commit 0de53e8
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 2 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v0.2.4
v0.2.5
16 changes: 15 additions & 1 deletion ofctrl/fgraphFlow.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ type FlowMatch struct {
CtTpDstPort uint16 // Dest port in the transport layer in ct
Icmp6Code *uint8 // ICMPv6 code
Icmp6Type *uint8 // ICMPv6 type
Icmp4Code *uint8 // ICMPv4 code
Icmp4Type *uint8 // ICMPv4 type
NdTarget *net.IP // ICMPv6 Neighbor Discovery Target
NdTargetMask *net.IP // Mask for ICMPv6 Neighbor Discovery Target
NdSll *net.HardwareAddr // ICMPv6 Neighbor Discovery Source Ethernet Address
Expand Down Expand Up @@ -567,7 +569,7 @@ func (self *Flow) xlateMatch() openflow13.Match {
}

if self.Match.NdTll != nil {
ndTllField, _ := openflow13.FindFieldHeaderByName("NXM_NX_ND_SLL", false)
ndTllField, _ := openflow13.FindFieldHeaderByName("NXM_NX_ND_TLL", false)
ndTllField.Value = &openflow13.EthDstField{EthDst: *self.Match.NdTll}
ofMatch.AddField(*ndTllField)
}
Expand All @@ -582,6 +584,18 @@ func (self *Flow) xlateMatch() openflow13.Match {
ofMatch.AddField(*pktMarkField)
}

if self.Match.Icmp4Code != nil {
icmp4CodeField, _ := openflow13.FindFieldHeaderByName("NXM_OF_ICMP_CODE", false)
icmp4CodeField.Value = &openflow13.IcmpCodeField{Code: *self.Match.Icmp4Code}
ofMatch.AddField(*icmp4CodeField)
}

if self.Match.Icmp4Type != nil {
icmp4TypeField, _ := openflow13.FindFieldHeaderByName("NXM_OF_ICMP_TYPE", false)
icmp4TypeField.Value = &openflow13.IcmpTypeField{Type: *self.Match.Icmp4Type}
ofMatch.AddField(*icmp4TypeField)
}

return *ofMatch
}

Expand Down
38 changes: 38 additions & 0 deletions ofctrl/ofAction.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ const (
ActTypeSetNDTLL = "setNDTLL"
ActTypeSetICMP6Type = "setICMPv6Type"
ActTypeSetICMP6Code = "setICMPv6Code"
ActTypeSetICMP4Type = "setICMPv4Type"
ActTypeSetICMP4Code = "setICMPv4Code"
ActTypeNXLoad = "loadReg"
ActTypeNXMove = "moveReg"
ActTypeNXCT = "ct"
Expand Down Expand Up @@ -686,3 +688,39 @@ func (a *SetICMPv6CodeAction) GetActionMessage() openflow13.Action {
func (a *SetICMPv6CodeAction) GetActionType() string {
return ActTypeSetICMP6Code
}

// Currently, we only support Flow.Send() function to generate
// ICMP match/set flow message. We can also support Flow.Next()
// function to generate ICMP match/set flow message in future once
// libOpenflow support NewICMPXxxxField API.
type SetICMPv4TypeAction struct {
Type uint8
}

func (a *SetICMPv4TypeAction) GetActionMessage() openflow13.Action {
field, _ := openflow13.FindFieldHeaderByName("NXM_OF_ICMP_TYPE", false)
field.Value = &openflow13.IcmpTypeField{Type: a.Type}
return openflow13.NewActionSetField(*field)
}

func (a *SetICMPv4TypeAction) GetActionType() string {
return ActTypeSetICMP4Type
}

// Currently, we only support Flow.Send() function to generate
// ICMP match/set flow message. We can also support Flow.Next()
// function to generate ICMP match/set flow message in future once
// libOpenflow support NewICMPXxxxField API.
type SetICMPv4CodeAction struct {
Code uint8
}

func (a *SetICMPv4CodeAction) GetActionMessage() openflow13.Action {
field, _ := openflow13.FindFieldHeaderByName("NXM_OF_ICMP_CODE", false)
field.Value = &openflow13.IcmpCodeField{Code: a.Code}
return openflow13.NewActionSetField(*field)
}

func (a *SetICMPv4CodeAction) GetActionType() string {
return ActTypeSetICMP4Code
}

0 comments on commit 0de53e8

Please sign in to comment.