Skip to content

Commit 69a8d8b

Browse files
committed
ovs: support delete_strict in FlowTransaction
1 parent 291a942 commit 69a8d8b

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed

ovs/openflow.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,9 @@ type flowDirective struct {
7171

7272
// Possible flowDirective directive values.
7373
const (
74-
dirAdd = "add"
75-
dirDelete = "delete"
74+
dirAdd = "add"
75+
dirDelete = "delete"
76+
dirDeleteStrict = "delete_strict"
7677
)
7778

7879
// Add pushes zero or more Flows on to the transaction, to be added by
@@ -107,6 +108,21 @@ func (tx *FlowTransaction) Delete(flows ...*MatchFlow) {
107108
tx.push(dirDelete, tms...)
108109
}
109110

111+
// DeleteStrict is almost the same as Delete, except that the matching process
112+
// will be strict.
113+
func (tx *FlowTransaction) DeleteStrict(flows ...*MatchFlow) {
114+
if tx.err != nil {
115+
return
116+
}
117+
118+
tms := make([]encoding.TextMarshaler, 0, len(flows))
119+
for _, f := range flows {
120+
tms = append(tms, f)
121+
}
122+
123+
tx.push(dirDeleteStrict, tms...)
124+
}
125+
110126
// push pushes zero or more encoding.TextMarshalers on to the transaction
111127
// (typically a Flow or MatchFlow).
112128
func (tx *FlowTransaction) push(directive string, flows ...encoding.TextMarshaler) {

ovs/openflow_test.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,15 @@ func TestClientOpenFlowAddFlowBundleOK(t *testing.T) {
143143
}
144144

145145
// Flows for deletion
146-
matchFlows := []*MatchFlow{{
147-
Cookie: 0xdeadbeef,
148-
}}
146+
matchFlows := []*MatchFlow{
147+
{
148+
Cookie: 0xdeadbeef,
149+
},
150+
{
151+
Strict: true,
152+
Priority: 0,
153+
},
154+
}
149155

150156
pipe := Pipe(func(stdin io.Reader, cmd string, args ...string) ([]byte, error) {
151157
if want, got := "ovs-ofctl", cmd; want != got {
@@ -1079,7 +1085,7 @@ func mustVerifyFlowBundle(t *testing.T, stdin io.Reader, flows []*Flow, matchFlo
10791085
}
10801086

10811087
gotFlows = append(gotFlows, flow)
1082-
case dirDelete:
1088+
case dirDelete, dirDeleteStrict:
10831089
gotMatchFlows = append(gotMatchFlows, string(bb[1]))
10841090
default:
10851091
t.Fatalf("unexpected directive in flow bundle: %q", keyword)

0 commit comments

Comments
 (0)