From a39d8c4c779f1d5130dd807f7b391d7c87250abd Mon Sep 17 00:00:00 2001 From: Paul Yu <129891899+paulyufan2@users.noreply.github.com> Date: Sat, 10 Aug 2024 12:29:30 -0400 Subject: [PATCH] hotfix: set hcnNetwork flag as non-persistent mode (#2911) * hotfix: set hcnNetwork flag as non-persistent * add acomment --- network/network_windows.go | 9 +++-- network/network_windows_test.go | 72 +++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+), 3 deletions(-) diff --git a/network/network_windows.go b/network/network_windows.go index 5174f3294f..41093eb0fe 100644 --- a/network/network_windows.go +++ b/network/network_windows.go @@ -300,15 +300,18 @@ func (nm *networkManager) configureHcnNetwork(nwInfo *EndpointInfo, extIf *exter // DelegatedNIC flag: hcn.DisableHostPort(1024) if nwInfo.NICType == cns.NodeNetworkInterfaceFrontendNIC { hcnNetwork.Type = hcn.Transparent - hcnNetwork.Flags = hcn.DisableHostPort + // set transparent network as non-persistent so that networks will be gone after the node gets rebooted + // hcnNetwork.flags = hcn.DisableHostPort | hcn.EnableNonPersistent (1024 + 8 = 1032) + hcnNetwork.Flags = hcn.DisableHostPort | hcn.EnableNonPersistent } // AccelnetNIC flag: hcn.EnableIov(9216) // For L1VH with accelnet, hcn.DisableHostPort and hcn.EnableIov must be configured - // To set this, need do OR operation: hcnNetwork.flags = hcn.DisableHostPort | hcn.EnableIov: (1024 + 8192 = 9216) if nwInfo.NICType == cns.NodeNetworkInterfaceAccelnetFrontendNIC { hcnNetwork.Type = hcn.Transparent - hcnNetwork.Flags = hcn.DisableHostPort | hcn.EnableIov + // set transparent network as non-persistent so that networks will be gone after the node gets rebooted + // hcnNetwork.flags = hcn.DisableHostPort | hcn.EnableIov | hcn.EnableNonPersistent (1024 + 8192 + 8 = 9224) + hcnNetwork.Flags = hcn.DisableHostPort | hcn.EnableIov | hcn.EnableNonPersistent } // Populate subnets. diff --git a/network/network_windows_test.go b/network/network_windows_test.go index 9d647e6cb2..1aa0cbb670 100644 --- a/network/network_windows_test.go +++ b/network/network_windows_test.go @@ -592,3 +592,75 @@ func TestTransparentNetworkCreationForDelegated(t *testing.T) { t.Fatal("network creation does not return error") } } + +// Test Configure HCN Network for Swiftv2 DelegatedNIC HostComputeNetwork fields +func TestConfigureHCNNetworkSwiftv2DelegatedNIC(t *testing.T) { + expectedSwiftv2NetworkMode := hcn.Transparent + expectedSwifv2NetworkFlags := hcn.EnableNonPersistent | hcn.DisableHostPort + + nm := &networkManager{ + ExternalInterfaces: map[string]*externalInterface{}, + } + + extIf := externalInterface{ + Name: "eth1", + } + + nwInfo := &EndpointInfo{ + AdapterName: "eth1", + NetworkID: "d3e97a83-ba4c-45d5-ba88-dc56757ece28", + MasterIfName: "eth1", + Mode: "bridge", + NICType: cns.NodeNetworkInterfaceFrontendNIC, + } + + hostComputeNetwork, err := nm.configureHcnNetwork(nwInfo, &extIf) + if err != nil { + t.Fatalf("Failed to configure hcn network for delegatedVMNIC interface due to: %v", err) + } + + if hostComputeNetwork.Type != expectedSwiftv2NetworkMode { + t.Fatalf("host network mode is not configured as %v mode when interface NIC type is delegatedVMNIC", expectedSwiftv2NetworkMode) + } + + // make sure network type is transparent and flags is 1032 + if hostComputeNetwork.Flags != expectedSwifv2NetworkFlags { + t.Fatalf("host network flags is not configured as %v when interface NIC type is delegatedVMNIC", expectedSwifv2NetworkFlags) + } +} + +// Test Configure HCN Network for Swiftv2 AccelnetNIC HostComputeNetwork fields +func TestConfigureHCNNetworkSwiftv2AccelnetNIC(t *testing.T) { + expectedSwiftv2NetworkMode := hcn.Transparent + expectedSwifv2NetworkFlags := hcn.EnableNonPersistent | hcn.DisableHostPort | hcn.EnableIov + + nm := &networkManager{ + ExternalInterfaces: map[string]*externalInterface{}, + } + + extIf := externalInterface{ + Name: "eth1", + } + + nwInfo := &EndpointInfo{ + AdapterName: "eth1", + NetworkID: "d3e97a83-ba4c-45d5-ba88-dc56757ece28", + MasterIfName: "eth1", + Mode: "bridge", + NICType: cns.NodeNetworkInterfaceAccelnetFrontendNIC, + } + + hostComputeNetwork, err := nm.configureHcnNetwork(nwInfo, &extIf) + if err != nil { + t.Fatalf("Failed to configure hcn network for accelnetNIC interface due to: %v", err) + } + + if hostComputeNetwork.Type != expectedSwiftv2NetworkMode { + t.Fatalf("host network mode is not configured as %v mode when interface NIC type is accelnetNIC", expectedSwiftv2NetworkMode) + } + + // make sure network type is transparent and flags is 9224 + if hostComputeNetwork.Flags != expectedSwifv2NetworkFlags { + t.Fatalf("host network flags is not configured as %v when interface NIC type is accelnetNIC", expectedSwifv2NetworkFlags) + } +}