Skip to content

Commit a39d8c4

Browse files
authored
hotfix: set hcnNetwork flag as non-persistent mode (#2911)
* hotfix: set hcnNetwork flag as non-persistent * add acomment
1 parent 383acdb commit a39d8c4

File tree

2 files changed

+78
-3
lines changed

2 files changed

+78
-3
lines changed

network/network_windows.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -300,15 +300,18 @@ func (nm *networkManager) configureHcnNetwork(nwInfo *EndpointInfo, extIf *exter
300300
// DelegatedNIC flag: hcn.DisableHostPort(1024)
301301
if nwInfo.NICType == cns.NodeNetworkInterfaceFrontendNIC {
302302
hcnNetwork.Type = hcn.Transparent
303-
hcnNetwork.Flags = hcn.DisableHostPort
303+
// set transparent network as non-persistent so that networks will be gone after the node gets rebooted
304+
// hcnNetwork.flags = hcn.DisableHostPort | hcn.EnableNonPersistent (1024 + 8 = 1032)
305+
hcnNetwork.Flags = hcn.DisableHostPort | hcn.EnableNonPersistent
304306
}
305307

306308
// AccelnetNIC flag: hcn.EnableIov(9216)
307309
// For L1VH with accelnet, hcn.DisableHostPort and hcn.EnableIov must be configured
308-
// To set this, need do OR operation: hcnNetwork.flags = hcn.DisableHostPort | hcn.EnableIov: (1024 + 8192 = 9216)
309310
if nwInfo.NICType == cns.NodeNetworkInterfaceAccelnetFrontendNIC {
310311
hcnNetwork.Type = hcn.Transparent
311-
hcnNetwork.Flags = hcn.DisableHostPort | hcn.EnableIov
312+
// set transparent network as non-persistent so that networks will be gone after the node gets rebooted
313+
// hcnNetwork.flags = hcn.DisableHostPort | hcn.EnableIov | hcn.EnableNonPersistent (1024 + 8192 + 8 = 9224)
314+
hcnNetwork.Flags = hcn.DisableHostPort | hcn.EnableIov | hcn.EnableNonPersistent
312315
}
313316

314317
// Populate subnets.

network/network_windows_test.go

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,3 +592,75 @@ func TestTransparentNetworkCreationForDelegated(t *testing.T) {
592592
t.Fatal("network creation does not return error")
593593
}
594594
}
595+
596+
// Test Configure HCN Network for Swiftv2 DelegatedNIC HostComputeNetwork fields
597+
func TestConfigureHCNNetworkSwiftv2DelegatedNIC(t *testing.T) {
598+
expectedSwiftv2NetworkMode := hcn.Transparent
599+
expectedSwifv2NetworkFlags := hcn.EnableNonPersistent | hcn.DisableHostPort
600+
601+
nm := &networkManager{
602+
ExternalInterfaces: map[string]*externalInterface{},
603+
}
604+
605+
extIf := externalInterface{
606+
Name: "eth1",
607+
}
608+
609+
nwInfo := &EndpointInfo{
610+
AdapterName: "eth1",
611+
NetworkID: "d3e97a83-ba4c-45d5-ba88-dc56757ece28",
612+
MasterIfName: "eth1",
613+
Mode: "bridge",
614+
NICType: cns.NodeNetworkInterfaceFrontendNIC,
615+
}
616+
617+
hostComputeNetwork, err := nm.configureHcnNetwork(nwInfo, &extIf)
618+
if err != nil {
619+
t.Fatalf("Failed to configure hcn network for delegatedVMNIC interface due to: %v", err)
620+
}
621+
622+
if hostComputeNetwork.Type != expectedSwiftv2NetworkMode {
623+
t.Fatalf("host network mode is not configured as %v mode when interface NIC type is delegatedVMNIC", expectedSwiftv2NetworkMode)
624+
}
625+
626+
// make sure network type is transparent and flags is 1032
627+
if hostComputeNetwork.Flags != expectedSwifv2NetworkFlags {
628+
t.Fatalf("host network flags is not configured as %v when interface NIC type is delegatedVMNIC", expectedSwifv2NetworkFlags)
629+
}
630+
}
631+
632+
// Test Configure HCN Network for Swiftv2 AccelnetNIC HostComputeNetwork fields
633+
func TestConfigureHCNNetworkSwiftv2AccelnetNIC(t *testing.T) {
634+
expectedSwiftv2NetworkMode := hcn.Transparent
635+
expectedSwifv2NetworkFlags := hcn.EnableNonPersistent | hcn.DisableHostPort | hcn.EnableIov
636+
637+
nm := &networkManager{
638+
ExternalInterfaces: map[string]*externalInterface{},
639+
}
640+
641+
extIf := externalInterface{
642+
Name: "eth1",
643+
}
644+
645+
nwInfo := &EndpointInfo{
646+
AdapterName: "eth1",
647+
NetworkID: "d3e97a83-ba4c-45d5-ba88-dc56757ece28",
648+
MasterIfName: "eth1",
649+
Mode: "bridge",
650+
NICType: cns.NodeNetworkInterfaceAccelnetFrontendNIC,
651+
}
652+
653+
hostComputeNetwork, err := nm.configureHcnNetwork(nwInfo, &extIf)
654+
if err != nil {
655+
t.Fatalf("Failed to configure hcn network for accelnetNIC interface due to: %v", err)
656+
}
657+
658+
if hostComputeNetwork.Type != expectedSwiftv2NetworkMode {
659+
t.Fatalf("host network mode is not configured as %v mode when interface NIC type is accelnetNIC", expectedSwiftv2NetworkMode)
660+
}
661+
662+
// make sure network type is transparent and flags is 9224
663+
if hostComputeNetwork.Flags != expectedSwifv2NetworkFlags {
664+
t.Fatalf("host network flags is not configured as %v when interface NIC type is accelnetNIC", expectedSwifv2NetworkFlags)
665+
}
666+
}

0 commit comments

Comments
 (0)