diff --git a/ovs/openflow.go b/ovs/openflow.go index 2171c26..e318356 100644 --- a/ovs/openflow.go +++ b/ovs/openflow.go @@ -71,8 +71,9 @@ type flowDirective struct { // Possible flowDirective directive values. const ( - dirAdd = "add" - dirDelete = "delete" + dirAdd = "add" + dirDelete = "delete" + dirDeleteStrict = "delete_strict" ) // Add pushes zero or more Flows on to the transaction, to be added by @@ -107,6 +108,21 @@ func (tx *FlowTransaction) Delete(flows ...*MatchFlow) { tx.push(dirDelete, tms...) } +// DeleteStrict is almost the same as Delete, except that the matching process +// will be strict. +func (tx *FlowTransaction) DeleteStrict(flows ...*MatchFlow) { + if tx.err != nil { + return + } + + tms := make([]encoding.TextMarshaler, 0, len(flows)) + for _, f := range flows { + tms = append(tms, f) + } + + tx.push(dirDeleteStrict, tms...) +} + // push pushes zero or more encoding.TextMarshalers on to the transaction // (typically a Flow or MatchFlow). func (tx *FlowTransaction) push(directive string, flows ...encoding.TextMarshaler) { diff --git a/ovs/openflow_test.go b/ovs/openflow_test.go index 6c21276..e659be9 100644 --- a/ovs/openflow_test.go +++ b/ovs/openflow_test.go @@ -143,9 +143,15 @@ func TestClientOpenFlowAddFlowBundleOK(t *testing.T) { } // Flows for deletion - matchFlows := []*MatchFlow{{ - Cookie: 0xdeadbeef, - }} + matchFlows := []*MatchFlow{ + { + Cookie: 0xdeadbeef, + }, + { + Strict: true, + Priority: 0, + }, + } pipe := Pipe(func(stdin io.Reader, cmd string, args ...string) ([]byte, error) { if want, got := "ovs-ofctl", cmd; want != got { @@ -1079,7 +1085,7 @@ func mustVerifyFlowBundle(t *testing.T, stdin io.Reader, flows []*Flow, matchFlo } gotFlows = append(gotFlows, flow) - case dirDelete: + case dirDelete, dirDeleteStrict: gotMatchFlows = append(gotMatchFlows, string(bb[1])) default: t.Fatalf("unexpected directive in flow bundle: %q", keyword)