Skip to content

Commit

Permalink
Support CT zone with field or subfield (#18)
Browse files Browse the repository at this point in the history
libOpenflow supports immediate and field/subfield for conntrack zone field.
But ofnet only support zone with immediate. This patch will add zone with
field/subfield support.

Signed-off-by: Jinjun Gao <gjinjun@gmail.com>
  • Loading branch information
commandgjj authored Feb 16, 2022
1 parent 0d6f2b1 commit 636ddea
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 13 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v0.4.0
v0.5.0
2 changes: 1 addition & 1 deletion ofctrl/fgraphFlow.go
Original file line number Diff line number Diff line change
Expand Up @@ -1716,7 +1716,7 @@ func (self *Flow) ConnTrack(commit bool, force bool, tableID *uint8, zoneID *uin
commit: commit,
force: force,
table: tableID,
zone: zoneID,
zoneImm: zoneID,
actions: execActions,
}
action := new(FlowAction)
Expand Down
40 changes: 32 additions & 8 deletions ofctrl/ofAction.go
Original file line number Diff line number Diff line change
Expand Up @@ -500,11 +500,13 @@ func NewNXMoveAction(srcName string, dstName string, srcRange *openflow13.NXRang
}

type NXConnTrackAction struct {
commit bool
force bool
table *uint8
zone *uint16
actions []openflow13.Action
commit bool
force bool
table *uint8
zoneImm *uint16
zoneSrcField *openflow13.MatchField
zoneSrcRange *openflow13.NXRange
actions []openflow13.Action
}

func (a *NXConnTrackAction) GetActionMessage() openflow13.Action {
Expand All @@ -518,8 +520,10 @@ func (a *NXConnTrackAction) GetActionMessage() openflow13.Action {
if a.table != nil {
ctAction.Table(*a.table)
}
if a.zone != nil {
ctAction.ZoneImm(*a.zone)
if a.zoneSrcField != nil {
ctAction.ZoneRange(a.zoneSrcField, a.zoneSrcRange)
} else if a.zoneImm != nil {
ctAction.ZoneImm(*a.zoneImm)
}
if a.actions != nil {
ctAction = ctAction.AddAction(a.actions...)
Expand All @@ -531,16 +535,36 @@ func (a *NXConnTrackAction) GetActionType() string {
return ActTypeNXCT
}

// This function only support immediate number for ct_zone
func NewNXConnTrackAction(commit bool, force bool, table *uint8, zone *uint16, actions ...openflow13.Action) *NXConnTrackAction {
return &NXConnTrackAction{
commit: commit,
force: force,
table: table,
zone: zone,
zoneImm: zone,
actions: actions,
}
}

// This function support immediate number and field or subfield for ct_zone
func NewNXConnTrackActionWithZoneField(commit bool, force bool, table *uint8, zoneImm *uint16, zoneSrcFieldName string, zoneSrcRange *openflow13.NXRange, actions ...openflow13.Action) *NXConnTrackAction {
var zoneSrc *openflow13.MatchField
var zoneSrcRng *openflow13.NXRange
if zoneSrcFieldName != "" {
zoneSrc, _ = openflow13.FindFieldHeaderByName(zoneSrcFieldName, true)
zoneSrcRng = zoneSrcRange
}
return &NXConnTrackAction{
commit: commit,
force: force,
table: table,
zoneImm: zoneImm,
zoneSrcField: zoneSrc,
zoneSrcRange: zoneSrcRng,
actions: actions,
}
}

type NXConjunctionAction struct {
ID uint32
Clause uint8
Expand Down
8 changes: 5 additions & 3 deletions ofctrl/ofctrl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1126,7 +1126,7 @@ func TestNewFlowActionAPIs(t *testing.T) {
"priority=100,ip,in_port=108",
"ct(commit,table=1,zone=65281,exec(load:0xf009->NXM_NX_CT_MARK[])),resubmit(,1),resubmit(,2)")

// Test action: ct(table=1,zone=0xff01,nat)
// Test action: ct(table=1,zone=NXM_NX_REG1[0..15],nat)
flow80 := &Flow{
Table: ofActor.inputTable,
Match: FlowMatch{
Expand All @@ -1135,13 +1135,15 @@ func TestNewFlowActionAPIs(t *testing.T) {
InputPort: inPort6,
},
}
ctZoneFieldName := "NXM_NX_REG1"
ctZoneFieldRange := openflow13.NewNXRange(0, 15)
natAction0 := openflow13.NewNXActionCTNAT()
conntrack2 := NewNXConnTrackAction(false, false, &ctTable, &ctZone, natAction0)
conntrack2 := NewNXConnTrackActionWithZoneField(false, false, &ctTable, nil, ctZoneFieldName, ctZoneFieldRange, natAction0)
flow80.ApplyActions([]OFAction{conntrack2})
flow80.Goto(ofActor.nextTable.TableId)
verifyNewFlowInstallAndDelete(t, flow80, brName, ofActor.inputTable.TableId,
"priority=100,ip,in_port=108",
"ct(table=1,zone=65281,nat),goto_table:1")
"ct(table=1,zone=NXM_NX_REG1[0..15],nat),goto_table:1")
// Test action: dec_ttl
inPort7 := uint32(109)
flow9 := &Flow{
Expand Down

0 comments on commit 636ddea

Please sign in to comment.