Skip to content

Commit ae697ea

Browse files
committed
Add "filter" arg to ovs.DumpFlows so we can have fewer flows to parse
1 parent ade593c commit ae697ea

File tree

8 files changed

+131
-74
lines changed

8 files changed

+131
-74
lines changed

pkg/network/node/egressip_test.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func TestEgressIP(t *testing.T) {
4444
if err != nil {
4545
t.Fatalf("%v", err)
4646
}
47-
flows, err := ovsif.DumpFlows()
47+
flows, err := ovsif.DumpFlows("")
4848
if err != nil {
4949
t.Fatalf("Unexpected error dumping flows: %v", err)
5050
}
@@ -59,7 +59,7 @@ func TestEgressIP(t *testing.T) {
5959
if err != nil {
6060
t.Fatalf("%v", err)
6161
}
62-
flows, err = ovsif.DumpFlows()
62+
flows, err = ovsif.DumpFlows("")
6363
if err != nil {
6464
t.Fatalf("Unexpected error dumping flows: %v", err)
6565
}
@@ -78,7 +78,7 @@ func TestEgressIP(t *testing.T) {
7878
if err != nil {
7979
t.Fatalf("%v", err)
8080
}
81-
flows, err = ovsif.DumpFlows()
81+
flows, err = ovsif.DumpFlows("")
8282
if err != nil {
8383
t.Fatalf("Unexpected error dumping flows: %v", err)
8484
}
@@ -99,7 +99,7 @@ func TestEgressIP(t *testing.T) {
9999
if err != nil {
100100
t.Fatalf("%v", err)
101101
}
102-
flows, err = ovsif.DumpFlows()
102+
flows, err = ovsif.DumpFlows("")
103103
if err != nil {
104104
t.Fatalf("Unexpected error dumping flows: %v", err)
105105
}
@@ -113,7 +113,7 @@ func TestEgressIP(t *testing.T) {
113113
if err != nil {
114114
t.Fatalf("%v", err)
115115
}
116-
flows, err = ovsif.DumpFlows()
116+
flows, err = ovsif.DumpFlows("")
117117
if err != nil {
118118
t.Fatalf("Unexpected error dumping flows: %v", err)
119119
}
@@ -134,7 +134,7 @@ func TestEgressIP(t *testing.T) {
134134
if err != nil {
135135
t.Fatalf("%v", err)
136136
}
137-
flows, err = ovsif.DumpFlows()
137+
flows, err = ovsif.DumpFlows("")
138138
if err != nil {
139139
t.Fatalf("Unexpected error dumping flows: %v", err)
140140
}
@@ -153,7 +153,7 @@ func TestEgressIP(t *testing.T) {
153153
if err != nil {
154154
t.Fatalf("%v", err)
155155
}
156-
flows, err = ovsif.DumpFlows()
156+
flows, err = ovsif.DumpFlows("")
157157
if err != nil {
158158
t.Fatalf("Unexpected error dumping flows: %v", err)
159159
}
@@ -174,7 +174,7 @@ func TestEgressIP(t *testing.T) {
174174
if err != nil {
175175
t.Fatalf("%v", err)
176176
}
177-
flows, err = ovsif.DumpFlows()
177+
flows, err = ovsif.DumpFlows("")
178178
if err != nil {
179179
t.Fatalf("Unexpected error dumping flows: %v", err)
180180
}
@@ -188,7 +188,7 @@ func TestEgressIP(t *testing.T) {
188188
if err != nil {
189189
t.Fatalf("%v", err)
190190
}
191-
flows, err = ovsif.DumpFlows()
191+
flows, err = ovsif.DumpFlows("")
192192
if err != nil {
193193
t.Fatalf("Unexpected error dumping flows: %v", err)
194194
}
@@ -209,7 +209,7 @@ func TestEgressIP(t *testing.T) {
209209
if err != nil {
210210
t.Fatalf("%v", err)
211211
}
212-
flows, err = ovsif.DumpFlows()
212+
flows, err = ovsif.DumpFlows("")
213213
if err != nil {
214214
t.Fatalf("Unexpected error dumping flows: %v", err)
215215
}
@@ -230,7 +230,7 @@ func TestEgressIP(t *testing.T) {
230230
if err != nil {
231231
t.Fatalf("%v", err)
232232
}
233-
flows, err = ovsif.DumpFlows()
233+
flows, err = ovsif.DumpFlows("")
234234
if err != nil {
235235
t.Fatalf("Unexpected error dumping flows: %v", err)
236236
}
@@ -255,7 +255,7 @@ func TestEgressIP(t *testing.T) {
255255
if err != nil {
256256
t.Fatalf("%v", err)
257257
}
258-
flows, err = ovsif.DumpFlows()
258+
flows, err = ovsif.DumpFlows("")
259259
if err != nil {
260260
t.Fatalf("Unexpected error dumping flows: %v", err)
261261
}
@@ -280,7 +280,7 @@ func TestEgressIP(t *testing.T) {
280280
if err != nil {
281281
t.Fatalf("%v", err)
282282
}
283-
flows, err = ovsif.DumpFlows()
283+
flows, err = ovsif.DumpFlows("")
284284
if err != nil {
285285
t.Fatalf("Unexpected error dumping flows: %v", err)
286286
}

pkg/network/node/metrics.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ func gatherPeriodicMetrics(ovs ovs.Interface) {
123123
}
124124

125125
func updateOVSMetrics(ovs ovs.Interface) {
126-
flows, err := ovs.DumpFlows()
126+
flows, err := ovs.DumpFlows("")
127127
if err == nil {
128128
OVSFlows.Set(float64(len(flows)))
129129
} else {

pkg/network/node/ovscontroller.go

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,12 @@ func (oc *ovsController) getVersionNote() string {
5353
}
5454

5555
func (oc *ovsController) AlreadySetUp() bool {
56-
flows, err := oc.ovs.DumpFlows()
57-
if err != nil {
56+
flows, err := oc.ovs.DumpFlows("table=%d", ruleVersionTable)
57+
if err != nil || len(flows) != 1 {
5858
return false
5959
}
60-
expectedVersionNote := oc.getVersionNote()
61-
// The "version" flow should be the last one, so scan from the end
62-
for i := len(flows) - 1; i >= 0; i-- {
63-
parsed, err := ovs.ParseFlow(ovs.ParseForDump, flows[i])
64-
if err == nil && parsed.Table == ruleVersionTable {
65-
return parsed.NoteHasPrefix(expectedVersionNote)
66-
}
60+
if parsed, err := ovs.ParseFlow(ovs.ParseForDump, flows[0]); err == nil {
61+
return parsed.NoteHasPrefix(oc.getVersionNote())
6762
}
6863
return false
6964
}
@@ -343,18 +338,18 @@ func (oc *ovsController) getPodDetailsBySandboxID(sandboxID string) (int, string
343338
if err != nil {
344339
return 0, "", "", "", err
345340
}
346-
flows, err := oc.ovs.DumpFlows()
341+
flows, err := oc.ovs.DumpFlows("table=20,arp")
347342
if err != nil {
348343
return 0, "", "", "", err
349344
}
350345

351-
// Find the table=20 flow with the given note and extract the podIP, ofport, and MAC from them
346+
// Find the flow with the given note and extract the podIP, ofport, and MAC from them
352347
for _, flow := range flows {
353348
parsed, err := ovs.ParseFlow(ovs.ParseForDump, flow)
354349
if err != nil {
355350
return 0, "", "", "", err
356351
}
357-
if parsed.Table != 20 || !parsed.NoteHasPrefix(note) {
352+
if !parsed.NoteHasPrefix(note) {
358353
continue
359354
}
360355

@@ -615,7 +610,7 @@ func (oc *ovsController) UpdateVXLANMulticastFlows(remoteIPs []string) error {
615610
// pod/service-specific rules before they call policy.EnsureVNIDRules(), then there is no
616611
// race condition.
617612
func (oc *ovsController) FindUnusedVNIDs() []int {
618-
flows, err := oc.ovs.DumpFlows()
613+
flows, err := oc.ovs.DumpFlows("")
619614
if err != nil {
620615
glog.Errorf("FindUnusedVNIDs: could not DumpFlows: %v", err)
621616
return nil

0 commit comments

Comments
 (0)