Skip to content

Commit 4caa7c7

Browse files
committed
ovs: make MatchFlow --strict aware
1 parent cb908b2 commit 4caa7c7

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
@@ -1118,6 +1118,18 @@ func TestFlowMatchFlow(t *testing.T) {
11181118
}
11191119
})
11201120
}
1121+
for _, tt := range tests {
1122+
t.Run(tt.desc, func(t *testing.T) {
1123+
want, got := tt.m, tt.f.MatchFlowStrict()
1124+
wantStrict := &(*want)
1125+
wantStrict.Strict = true
1126+
wantStrict.Priority = tt.f.Priority
1127+
if !reflect.DeepEqual(wantStrict, got) {
1128+
t.Fatalf("unexpected MatchFlowStrict:\n- want: %#v\n- got: %#v",
1129+
wantStrict, got)
1130+
}
1131+
})
1132+
}
11211133
}
11221134

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