Skip to content

Commit

Permalink
Use IP mapped MAC address for internal management interface
Browse files Browse the repository at this point in the history
Currently a randomly generated MAC address will be assigned to the
internal management interface, but in the case of dpu, the MAC will
be derived from the IP of management interface, for example, IP
10.244.2.2 will be mapped to MAC `0a:58:0a:f4:02:02`.
This commit makes both DPU and non-DPU cases to use IP derived
MAC address for the management interface.

Signed-off-by: Xiaobin Qu <xqu@nvidia.com>
  • Loading branch information
Xiaobin Qu committed Jun 4, 2024
1 parent ce6445d commit 070fbe8
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 23 deletions.
34 changes: 20 additions & 14 deletions go-controller/pkg/node/management-port.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,29 +85,18 @@ func (mp *managementPort) Create(routeManager *routemanager.Controller, nodeAnno

// Create a OVS internal interface.
legacyMgmtIntfName := util.GetLegacyK8sMgmtIntfName(mp.nodeName)
macAddress := util.IPAddrToHWAddr(util.GetNodeManagementIfAddr(mp.hostSubnets[0]).IP)
stdout, stderr, err := util.RunOVSVsctl(
"--", "--if-exists", "del-port", "br-int", legacyMgmtIntfName,
"--", "--may-exist", "add-port", "br-int", types.K8sMgmtIntfName,
"--", "set", "interface", types.K8sMgmtIntfName,
"type=internal", "mtu_request="+fmt.Sprintf("%d", config.Default.MTU),
"external-ids:iface-id="+types.K8sPrefix+mp.nodeName)
"external-ids:iface-id="+types.K8sPrefix+mp.nodeName,
"mac="+strings.ReplaceAll(macAddress.String(), ":", "\\:"))
if err != nil {
klog.Errorf("Failed to add port to br-int, stdout: %q, stderr: %q, error: %v", stdout, stderr, err)
return nil, err
}
macAddress, err := util.GetOVSPortMACAddress(types.K8sMgmtIntfName)
if err != nil {
klog.Errorf("Failed to get management port MAC address: %v", err)
return nil, err
}
// persist the MAC address so that upon node reboot we get back the same mac address.
_, stderr, err = util.RunOVSVsctl("set", "interface", types.K8sMgmtIntfName,
fmt.Sprintf("mac=%s", strings.ReplaceAll(macAddress.String(), ":", "\\:")))
if err != nil {
klog.Errorf("Failed to persist MAC address %q for %q: stderr:%s (%v)", macAddress.String(),
types.K8sMgmtIntfName, stderr, err)
return nil, err
}

cfg, err := createPlatformManagementPort(routeManager, types.K8sMgmtIntfName, mp.hostSubnets)
if err != nil {
Expand Down Expand Up @@ -158,6 +147,23 @@ func managementPortReady() (bool, error) {
if !strings.Contains(stdout, "actions=output:"+ofport) {
return false, nil
}

// In the case of transitioning from random MAC to ip-mapped MAC, following code will get the
// MAC from mgmt port, and check if the address is applied in openflow table 35 or not
mac, _, err := util.RunOVSVsctl("--if-exists", "get", "interface", k8sMgmtIntfName, "mac")
if err != nil {
return false, nil
}
// check mac address in openflow
stdout, _, err = util.RunOVSOfctl("--no-stats", "--no-names", "dump-flows", "br-int",
"table=35,dl_dst="+mac)
if err != nil {
return false, nil
}
if stdout == "" {
return false, nil
}

klog.Infof("Management port %s is ready", k8sMgmtIntfName)
return true, nil
}
27 changes: 18 additions & 9 deletions go-controller/pkg/node/management-port_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,12 +195,12 @@ func testManagementPort(ctx *cli.Context, fexec *ovntest.FakeExec, testNS ns.Net
configs []managementPortTestConfig, expectedLRPMAC string) {
const (
nodeName string = "node1"
mgtPortMAC string = "00:00:00:55:66:77"
mgtPort string = types.K8sMgmtIntfName
legacyMgtPort string = types.K8sPrefix + nodeName
mtu string = "1400"
)

mgtPortMAC := util.IPAddrToHWAddr(configs[0].GetMgtPortAddr().IP).String()
// generic setup
fexec.AddFakeCmd(&ovntest.ExpectedCmd{
Cmd: "ovs-vsctl --timeout=15 --no-headings --data bare --format csv --columns type,name find Interface name=" + mgtPort,
Expand All @@ -211,14 +211,7 @@ func testManagementPort(ctx *cli.Context, fexec *ovntest.FakeExec, testNS ns.Net
Output: "internal," + mgtPort + "_0",
})
fexec.AddFakeCmdsNoOutputNoError([]string{
"ovs-vsctl --timeout=15 -- --if-exists del-port br-int " + legacyMgtPort + " -- --may-exist add-port br-int " + mgtPort + " -- set interface " + mgtPort + " type=internal mtu_request=" + mtu + " external-ids:iface-id=" + legacyMgtPort,
})
fexec.AddFakeCmd(&ovntest.ExpectedCmd{
Cmd: "ovs-vsctl --timeout=15 --if-exists get interface " + mgtPort + " mac_in_use",
Output: mgtPortMAC,
})
fexec.AddFakeCmdsNoOutputNoError([]string{
"ovs-vsctl --timeout=15 set interface " + mgtPort + " " + fmt.Sprintf("mac=%s", strings.ReplaceAll(mgtPortMAC, ":", "\\:")),
"ovs-vsctl --timeout=15 -- --if-exists del-port br-int " + legacyMgtPort + " -- --may-exist add-port br-int " + mgtPort + " -- set interface " + mgtPort + " type=internal mtu_request=" + mtu + " external-ids:iface-id=" + legacyMgtPort + " mac=" + strings.ReplaceAll(mgtPortMAC, ":", "\\:"),
})
for _, cfg := range configs {
if cfg.family == netlink.FAMILY_V4 {
Expand All @@ -241,6 +234,14 @@ func testManagementPort(ctx *cli.Context, fexec *ovntest.FakeExec, testNS ns.Net
Cmd: "ovs-ofctl --no-stats --no-names dump-flows br-int table=65,out_port=1",
Output: " table=65, priority=100,reg15=0x2,metadata=0x2 actions=output:1",
})
fexec.AddFakeCmd(&ovntest.ExpectedCmd{
Cmd: "ovs-vsctl --timeout=15 --if-exists get interface " + mgtPort + " mac",
Output: mgtPortMAC,
})
fexec.AddFakeCmd(&ovntest.ExpectedCmd{
Cmd: "ovs-ofctl --no-stats --no-names dump-flows br-int table=35,dl_dst=" + mgtPortMAC,
Output: " table=35, priority=50,metadata=0x5,dl_dst=" + mgtPortMAC,
})

err := util.SetExec(fexec)
Expect(err).NotTo(HaveOccurred())
Expand Down Expand Up @@ -338,6 +339,14 @@ func testManagementPortDPU(ctx *cli.Context, fexec *ovntest.FakeExec, testNS ns.
Cmd: "ovs-ofctl --no-stats --no-names dump-flows br-int table=65,out_port=1",
Output: " table=65, priority=100,reg15=0x2,metadata=0x2 actions=output:1",
})
fexec.AddFakeCmd(&ovntest.ExpectedCmd{
Cmd: "ovs-vsctl --timeout=15 --if-exists get interface " + mgtPort + " mac",
Output: mgtPortMAC,
})
fexec.AddFakeCmd(&ovntest.ExpectedCmd{
Cmd: "ovs-ofctl --no-stats --no-names dump-flows br-int table=35,dl_dst=" + mgtPortMAC,
Output: " table=35, priority=50,metadata=0x5,dl_dst=" + mgtPortMAC,
})

err := util.SetExec(fexec)
Expect(err).NotTo(HaveOccurred())
Expand Down

0 comments on commit 070fbe8

Please sign in to comment.