Skip to content

Commit

Permalink
hotfix: set hcnNetwork flag as non-persistent mode (#2911)
Browse files Browse the repository at this point in the history
* hotfix: set hcnNetwork flag as non-persistent

* add acomment
  • Loading branch information
paulyufan2 authored Aug 10, 2024
1 parent 383acdb commit a39d8c4
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 3 deletions.
9 changes: 6 additions & 3 deletions network/network_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
72 changes: 72 additions & 0 deletions network/network_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

0 comments on commit a39d8c4

Please sign in to comment.