Skip to content

Commit 291a942

Browse files
committed
ovs: make MatchFlow --strict aware
1 parent 4c0a147 commit 291a942

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
@@ -339,6 +339,14 @@ func (f *Flow) MatchFlow() *MatchFlow {
339339
}
340340
}
341341

342+
// MatchFlowStrict converts Flow into a strict-matching-aware MatchFlow
343+
func (f *Flow) MatchFlowStrict() *MatchFlow {
344+
mf := f.MatchFlow()
345+
mf.Priority = f.Priority
346+
mf.Strict = true
347+
return mf
348+
}
349+
342350
// marshalActions marshals all Actions in a Flow to their text form.
343351
func (f *Flow) marshalActions() ([]string, error) {
344352
fns := make([]func() ([]byte, error), 0, len(f.Actions))

ovs/flow_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1162,6 +1162,18 @@ func TestFlowMatchFlow(t *testing.T) {
11621162
}
11631163
})
11641164
}
1165+
for _, tt := range tests {
1166+
t.Run(tt.desc, func(t *testing.T) {
1167+
want, got := tt.m, tt.f.MatchFlowStrict()
1168+
wantStrict := &(*want)
1169+
wantStrict.Strict = true
1170+
wantStrict.Priority = tt.f.Priority
1171+
if !reflect.DeepEqual(wantStrict, got) {
1172+
t.Fatalf("unexpected MatchFlowStrict:\n- want: %#v\n- got: %#v",
1173+
wantStrict, got)
1174+
}
1175+
})
1176+
}
11651177
}
11661178

11671179
// 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)