Skip to content

Commit 24eb418

Browse files
committed
Remove tap interface filtering - return all port mappings
1 parent f2dc1f6 commit 24eb418

File tree

2 files changed

+49
-24
lines changed

2 files changed

+49
-24
lines changed

ovs/openflow.go

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323
"io"
2424
"regexp"
2525
"strconv"
26-
"strings"
2726
)
2827

2928
var (
@@ -337,8 +336,7 @@ func (o *OpenFlowService) DumpAggregate(bridge string, flow *MatchFlow) (*FlowSt
337336
}
338337

339338
// DumpPortMappings retrieves port mappings (ofport and MAC address) for all
340-
// tap interfaces and the LOCAL port from the specified bridge. The output is
341-
// parsed from 'ovs-ofctl show' command.
339+
// interfaces from the specified bridge. The output is parsed from 'ovs-ofctl show' command.
342340
func (o *OpenFlowService) DumpPortMappings(bridge string) (map[string]*PortMapping, error) {
343341
args := []string{"show", bridge}
344342
args = append(args, o.c.ofctlFlags...)
@@ -360,11 +358,6 @@ func (o *OpenFlowService) DumpPortMappings(bridge string) (map[string]*PortMappi
360358
}
361359

362360
interfaceName := string(matches[2])
363-
// Filter: only include interfaces starting with "tap" or "LOCAL"
364-
if !strings.HasPrefix(interfaceName, "tap") && interfaceName != "LOCAL" {
365-
continue
366-
}
367-
368361
ofport, err := strconv.Atoi(string(matches[1]))
369362
if err != nil {
370363
// Skip malformed ofport numbers
@@ -405,7 +398,7 @@ var (
405398
//dumpAggregatePrefix = []byte("NXST_AGGREGATE reply")
406399

407400
// portMappingPattern matches port lines from 'ovs-ofctl show' output.
408-
// Pattern matches: " 7(tapext10396233): addr:fe:4f:76:09:88:2b"
401+
// Pattern matches: " 7(interface1): addr:fe:4f:76:09:88:2b"
409402
// or " 65534(LOCAL): addr:fe:4f:76:09:88:2b"
410403
portMappingPattern = regexp.MustCompile(`^\s*(\d+)\(([^)]+)\):\s*addr:([a-fA-F0-9:]+)`)
411404
)

ovs/openflow_test.go

Lines changed: 47 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1418,26 +1418,30 @@ func mustVerifyFlowBundle(t *testing.T, stdin io.Reader, flows []*Flow, matchFlo
14181418

14191419
func TestClientOpenFlowDumpPortMappingsOK(t *testing.T) {
14201420
want := map[string]*PortMapping{
1421-
"tapext10396233": {
1421+
"interface1": {
14221422
OfPort: 7,
14231423
MACAddress: "fe:4f:76:09:88:2b",
14241424
},
1425-
"tapext12716181": {
1425+
"interface2": {
14261426
OfPort: 8,
14271427
MACAddress: "fe:be:7b:0d:53:d8",
14281428
},
1429-
"tapext10864673": {
1429+
"interface3": {
14301430
OfPort: 9,
14311431
MACAddress: "fe:b6:4c:d5:40:79",
14321432
},
1433-
"tapint10396233": {
1433+
"interface4": {
14341434
OfPort: 20,
14351435
MACAddress: "fe:cf:a6:90:30:29",
14361436
},
14371437
"LOCAL": {
14381438
OfPort: 65534,
14391439
MACAddress: "fe:74:0f:80:cf:9a",
14401440
},
1441+
"eth0": {
1442+
OfPort: 1,
1443+
MACAddress: "aa:bb:cc:dd:ee:ff",
1444+
},
14411445
}
14421446

14431447
bridge := "br0"
@@ -1460,22 +1464,22 @@ OFPT_FEATURES_REPLY (xid=0x2): dpid:0000000000000001
14601464
n_tables:254, n_buffers:256
14611465
capabilities: FLOW_STATS TABLE_STATS PORT_STATS QUEUE_STATS ARP_MATCH_IP
14621466
actions: output enqueue set_vlan_vid set_vlan_pcp strip_vlan mod_dl_src mod_dl_dst mod_nw_src mod_nw_dst mod_nw_tos mod_tp_src mod_tp_dst
1463-
7(tapext10396233): addr:fe:4f:76:09:88:2b
1467+
7(interface1): addr:fe:4f:76:09:88:2b
14641468
config: 0
14651469
state: 0
14661470
current: 10GB-FD COPPER
14671471
speed: 10000 Mbps now, 0 Mbps max
1468-
8(tapext12716181): addr:fe:be:7b:0d:53:d8
1472+
8(interface2): addr:fe:be:7b:0d:53:d8
14691473
config: 0
14701474
state: 0
14711475
current: 10GB-FD COPPER
14721476
speed: 10000 Mbps now, 0 Mbps max
1473-
9(tapext10864673): addr:fe:b6:4c:d5:40:79
1477+
9(interface3): addr:fe:b6:4c:d5:40:79
14741478
config: 0
14751479
state: 0
14761480
current: 10GB-FD COPPER
14771481
speed: 10000 Mbps now, 0 Mbps max
1478-
20(tapint10396233): addr:fe:cf:a6:90:30:29
1482+
20(interface4): addr:fe:cf:a6:90:30:29
14791483
config: 0
14801484
state: 0
14811485
current: 10GB-FD COPPER
@@ -1485,7 +1489,7 @@ actions: output enqueue set_vlan_vid set_vlan_pcp strip_vlan mod_dl_src mod_dl_d
14851489
state: 0
14861490
current: 10GB-FD COPPER
14871491
speed: 10000 Mbps now, 0 Mbps max
1488-
1(non-tap-interface): addr:aa:bb:cc:dd:ee:ff
1492+
1(eth0): addr:aa:bb:cc:dd:ee:ff
14891493
config: 0
14901494
state: 0
14911495
`), nil
@@ -1518,9 +1522,9 @@ actions: output enqueue set_vlan_vid set_vlan_pcp strip_vlan mod_dl_src mod_dl_d
15181522
}
15191523
}
15201524

1521-
// Verify non-tap interfaces are filtered out
1522-
if _, ok := got["non-tap-interface"]; ok {
1523-
t.Fatalf("non-tap interface should be filtered out")
1525+
// Verify all interfaces are included
1526+
if _, ok := got["eth0"]; !ok {
1527+
t.Fatalf("all interfaces should be included, eth0 missing")
15241528
}
15251529
}
15261530

@@ -1541,7 +1545,18 @@ func TestClientOpenFlowDumpPortMappingsEmptyOutput(t *testing.T) {
15411545
}
15421546
}
15431547

1544-
func TestClientOpenFlowDumpPortMappingsNoTapInterfaces(t *testing.T) {
1548+
func TestClientOpenFlowDumpPortMappingsAllInterfaces(t *testing.T) {
1549+
want := map[string]*PortMapping{
1550+
"eth0": {
1551+
OfPort: 1,
1552+
MACAddress: "aa:bb:cc:dd:ee:ff",
1553+
},
1554+
"eth1": {
1555+
OfPort: 2,
1556+
MACAddress: "11:22:33:44:55:66",
1557+
},
1558+
}
1559+
15451560
bridge := "br0"
15461561

15471562
c := testClient(nil, func(cmd string, args ...string) ([]byte, error) {
@@ -1557,8 +1572,25 @@ OFPT_FEATURES_REPLY (xid=0x2): dpid:0000000000000001
15571572
t.Fatalf("unexpected error: %v", err)
15581573
}
15591574

1560-
if len(got) != 0 {
1561-
t.Fatalf("unexpected mappings (should be empty):\n- want: 0\n- got: %d", len(got))
1575+
if len(want) != len(got) {
1576+
t.Fatalf("unexpected number of mappings:\n- want: %d\n- got: %d", len(want), len(got))
1577+
}
1578+
1579+
for name, wantMapping := range want {
1580+
gotMapping, ok := got[name]
1581+
if !ok {
1582+
t.Fatalf("missing mapping for interface %q", name)
1583+
}
1584+
1585+
if wantMapping.OfPort != gotMapping.OfPort {
1586+
t.Fatalf("unexpected OfPort for %q:\n- want: %d\n- got: %d",
1587+
name, wantMapping.OfPort, gotMapping.OfPort)
1588+
}
1589+
1590+
if wantMapping.MACAddress != gotMapping.MACAddress {
1591+
t.Fatalf("unexpected MACAddress for %q:\n- want: %q\n- got: %q",
1592+
name, wantMapping.MACAddress, gotMapping.MACAddress)
1593+
}
15621594
}
15631595
}
15641596

0 commit comments

Comments
 (0)