Skip to content

Commit

Permalink
ovs: support delete_strict in FlowTransaction
Browse files Browse the repository at this point in the history
  • Loading branch information
yousong committed Jul 19, 2018
1 parent 4caa7c7 commit 1a7a1d0
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
20 changes: 18 additions & 2 deletions ovs/openflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
14 changes: 10 additions & 4 deletions ovs/openflow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 1a7a1d0

Please sign in to comment.