Skip to content

Commit 277dd0b

Browse files
committed
ovs: make MatchFlow --strict aware
1 parent 6bbc8f1 commit 277dd0b

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

ovs/flow.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,14 @@ func (f *Flow) MatchFlow() *MatchFlow {
437437
}
438438
}
439439

440+
// MatchFlowStrict converts Flow into a strict-matching-aware MatchFlow
441+
func (f *Flow) MatchFlowStrict() *MatchFlow {
442+
mf := f.MatchFlow()
443+
mf.Priority = f.Priority
444+
mf.Strict = true
445+
return mf
446+
}
447+
440448
// marshalActions marshals all provided Actions to their text form.
441449
func marshalActions(aa []Action) ([]string, error) {
442450
fns := make([]func() ([]byte, error), 0, len(aa))

ovs/flow_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1203,6 +1203,18 @@ func TestFlowMatchFlow(t *testing.T) {
12031203
}
12041204
})
12051205
}
1206+
for _, tt := range tests {
1207+
t.Run(tt.desc, func(t *testing.T) {
1208+
want, got := tt.m, tt.f.MatchFlowStrict()
1209+
wantStrict := &(*want)
1210+
wantStrict.Strict = true
1211+
wantStrict.Priority = tt.f.Priority
1212+
if !reflect.DeepEqual(wantStrict, got) {
1213+
t.Fatalf("unexpected MatchFlowStrict:\n- want: %#v\n- got: %#v",
1214+
wantStrict, got)
1215+
}
1216+
})
1217+
}
12061218
}
12071219

12081220
// flowsEqual determines if two possible Flows are equal.

ovs/matchflow.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,10 @@ var (
3737
// A MatchFlow is an OpenFlow flow intended for flow deletion. It can be marshaled to its textual
3838
// form for use with Open vSwitch.
3939
type MatchFlow struct {
40-
Protocol Protocol
40+
Strict bool
4141
InPort int
42+
Priority int
43+
Protocol Protocol
4244
Matches []Match
4345
Table int
4446

@@ -83,6 +85,11 @@ func (f *MatchFlow) MarshalText() ([]byte, error) {
8385

8486
var b []byte
8587

88+
if f.Strict {
89+
b = append(b, priority+"="...)
90+
b = strconv.AppendInt(b, int64(f.Priority), 10)
91+
b = append(b, ',')
92+
}
8693
if f.Protocol != "" {
8794
b = append(b, f.Protocol...)
8895
b = append(b, ',')

0 commit comments

Comments
 (0)