Skip to content

Commit

Permalink
ovs: make MatchFlow --strict aware
Browse files Browse the repository at this point in the history
  • Loading branch information
yousong committed Jul 19, 2018
1 parent cb908b2 commit 4caa7c7
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
8 changes: 8 additions & 0 deletions ovs/flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,14 @@ func (f *Flow) MatchFlow() *MatchFlow {
}
}

// MatchFlowStrict converts Flow into a strict-matching-aware MatchFlow
func (f *Flow) MatchFlowStrict() *MatchFlow {
mf := f.MatchFlow()
mf.Priority = f.Priority
mf.Strict = true
return mf
}

// marshalActions marshals all Actions in a Flow to their text form.
func (f *Flow) marshalActions() ([]string, error) {
fns := make([]func() ([]byte, error), 0, len(f.Actions))
Expand Down
12 changes: 12 additions & 0 deletions ovs/flow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1118,6 +1118,18 @@ func TestFlowMatchFlow(t *testing.T) {
}
})
}
for _, tt := range tests {
t.Run(tt.desc, func(t *testing.T) {
want, got := tt.m, tt.f.MatchFlowStrict()
wantStrict := &(*want)
wantStrict.Strict = true
wantStrict.Priority = tt.f.Priority
if !reflect.DeepEqual(wantStrict, got) {
t.Fatalf("unexpected MatchFlowStrict:\n- want: %#v\n- got: %#v",
wantStrict, got)
}
})
}
}

// flowsEqual determines if two possible Flows are equal.
Expand Down
9 changes: 8 additions & 1 deletion ovs/matchflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ var (
// A MatchFlow is an OpenFlow flow intended for flow deletion. It can be marshaled to its textual
// form for use with Open vSwitch.
type MatchFlow struct {
Protocol Protocol
Strict bool
InPort int
Priority int
Protocol Protocol
Matches []Match
Table int

Expand Down Expand Up @@ -83,6 +85,11 @@ func (f *MatchFlow) MarshalText() ([]byte, error) {

var b []byte

if f.Strict {
b = append(b, priority+"="...)
b = strconv.AppendInt(b, int64(f.Priority), 10)
b = append(b, ',')
}
if f.Protocol != "" {
b = append(b, f.Protocol...)
b = append(b, ',')
Expand Down

0 comments on commit 4caa7c7

Please sign in to comment.