Skip to content

Commit b312e1d

Browse files
committed
Capture actions from the trace output into a slice of strings
1 parent 9d885f6 commit b312e1d

File tree

2 files changed

+95
-10
lines changed

2 files changed

+95
-10
lines changed

ovs/proto_trace.go

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ var (
3030
datapathActionsRegexp = regexp.MustCompile(`Datapath actions: (.*)`)
3131
initialFlowRegexp = regexp.MustCompile(`Flow: (.*)`)
3232
finalFlowRegexp = regexp.MustCompile(`Final flow: (.*)`)
33+
megaFlowRegexp = regexp.MustCompile(`Megaflow: (.*)`)
34+
traceStartRegexp = regexp.MustCompile(`bridge\("(.*)"\)`)
35+
traceFlowRegexp = regexp.MustCompile(` *[[:digit:]]+[.] ([[:alpha:]].*)`)
36+
traceActionRegexp = regexp.MustCompile(` +([[:alpha:]].*)`)
3337

3438
pushVLANPattern = `push_vlan(vid=[0-9]+,pcp=[0-9]+)`
3539
)
@@ -113,6 +117,7 @@ type ProtoTrace struct {
113117
InputFlow *DataPathFlows
114118
FinalFlow *DataPathFlows
115119
DataPathActions DataPathActions
120+
FlowActions []string
116121
}
117122

118123
// UnmarshalText unmarshals ProtoTrace text into a ProtoTrace type.
@@ -151,6 +156,23 @@ func (pt *ProtoTrace) UnmarshalText(b []byte) error {
151156
pt.FinalFlow = flow
152157
continue
153158
}
159+
160+
if _, matched := checkForMegaFlow(line); matched {
161+
continue
162+
}
163+
164+
if _, matched := checkForTraceStart(line); matched {
165+
continue
166+
}
167+
168+
if _, matched := checkForTraceFlow(line); matched {
169+
continue
170+
}
171+
172+
if matches, matched := checkForTraceAction(line); matched {
173+
pt.FlowActions = append(pt.FlowActions, matches[1])
174+
continue
175+
}
154176
}
155177

156178
return nil
@@ -182,3 +204,39 @@ func checkForFinalFlow(s string) ([]string, bool) {
182204

183205
return matches, true
184206
}
207+
208+
func checkForMegaFlow(s string) ([]string, bool) {
209+
matches := megaFlowRegexp.FindStringSubmatch(s)
210+
if len(matches) == 0 {
211+
return matches, false
212+
}
213+
214+
return matches, true
215+
}
216+
217+
func checkForTraceStart(s string) ([]string, bool) {
218+
matches := traceStartRegexp.FindStringSubmatch(s)
219+
if len(matches) == 0 {
220+
return matches, false
221+
}
222+
223+
return matches, true
224+
}
225+
226+
func checkForTraceFlow(s string) ([]string, bool) {
227+
matches := traceFlowRegexp.FindStringSubmatch(s)
228+
if len(matches) == 0 {
229+
return matches, false
230+
}
231+
232+
return matches, true
233+
}
234+
235+
func checkForTraceAction(s string) ([]string, bool) {
236+
matches := traceActionRegexp.FindStringSubmatch(s)
237+
if len(matches) == 0 {
238+
return matches, false
239+
}
240+
241+
return matches, true
242+
}

ovs/proto_trace_test.go

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@ import (
2121

2222
func Test_UnmarshalText(t *testing.T) {
2323
testcases := []struct {
24-
name string
25-
output string
26-
actions DataPathActions
24+
name string
25+
output string
26+
datapathActions DataPathActions
27+
flowActions []string
2728
}{
2829
{
2930
name: "action output port",
@@ -39,7 +40,11 @@ bridge("br0")
3940
Final flow: unchanged
4041
Megaflow: recirc_id=0,tcp,in_port=3,nw_src=192.0.2.0/24,nw_frag=no,tp_dst=22
4142
Datapath actions: 1`,
42-
actions: NewDataPathActions("1"),
43+
datapathActions: NewDataPathActions("1"),
44+
flowActions: []string{
45+
"resubmit(,2)",
46+
"output:1",
47+
},
4348
},
4449
{
4550
name: "in_port is LOCAL",
@@ -55,7 +60,11 @@ bridge("br0")
5560
Final flow: unchanged
5661
Megaflow: recirc_id=0,tcp,in_port=LOCAL,nw_src=192.0.2.0/24,nw_frag=no,tp_dst=22
5762
Datapath actions: 1`,
58-
actions: NewDataPathActions("1"),
63+
datapathActions: NewDataPathActions("1"),
64+
flowActions: []string{
65+
"resubmit(,2)",
66+
"output:1",
67+
},
5968
},
6069
{
6170
name: "popvlan and output port",
@@ -71,7 +80,11 @@ bridge("br0")
7180
Final flow: unchanged
7281
Megaflow: recirc_id=0,tcp,in_port=3,nw_src=192.0.2.0/24,nw_frag=no,tp_dst=22
7382
Datapath actions: popvlan,1`,
74-
actions: NewDataPathActions("popvlan,1"),
83+
datapathActions: NewDataPathActions("popvlan,1"),
84+
flowActions: []string{
85+
"resubmit(,2)",
86+
"output:1",
87+
},
7588
},
7689
{
7790
name: "pushvlan and output port",
@@ -87,7 +100,11 @@ bridge("br0")
87100
Final flow: unchanged
88101
Megaflow: recirc_id=0,tcp,in_port=3,nw_src=192.0.2.0/24,nw_frag=no,tp_dst=22
89102
Datapath actions: push_vlan(vid=20,pcp=0),4`,
90-
actions: NewDataPathActions("push_vlan(vid=20,pcp=0),4"),
103+
datapathActions: NewDataPathActions("push_vlan(vid=20,pcp=0),4"),
104+
flowActions: []string{
105+
"resubmit(,2)",
106+
"output:1",
107+
},
91108
},
92109
{
93110
name: "drop",
@@ -103,7 +120,11 @@ bridge("br0")
103120
Final flow: unchanged
104121
Megaflow: recirc_id=0,tcp,in_port=3,nw_src=192.0.2.0/24,nw_frag=no,tp_dst=22
105122
Datapath actions: drop`,
106-
actions: NewDataPathActions("drop"),
123+
datapathActions: NewDataPathActions("drop"),
124+
flowActions: []string{
125+
"resubmit(,2)",
126+
"output:1",
127+
},
107128
},
108129
}
109130

@@ -115,11 +136,17 @@ Datapath actions: drop`,
115136
t.Errorf("error unmarshalling tests: %q", err)
116137
}
117138

118-
if !reflect.DeepEqual(testcase.actions, pt.DataPathActions) {
119-
t.Logf("expected: %v", testcase.actions)
139+
if !reflect.DeepEqual(testcase.datapathActions, pt.DataPathActions) {
140+
t.Logf("expected: %v", testcase.datapathActions)
120141
t.Logf("actual: %v", pt.DataPathActions)
121142
t.Error("unexpected datapath actions")
122143
}
144+
145+
if !reflect.DeepEqual(testcase.flowActions, pt.FlowActions) {
146+
t.Logf("expected: %v", testcase.flowActions)
147+
t.Logf("actual: %v", pt.FlowActions)
148+
t.Error("unexpected trace actions")
149+
}
123150
})
124151
}
125152
}

0 commit comments

Comments
 (0)