Skip to content

Commit 8e8a5fd

Browse files
authored
Remove l2bridge checker on windows and l2tunnel mode (#3113)
* remove l2bridge checker and l2tunnel mode * fix l2bridge type * fix the comment to add an UT to ensure hcn network type is always l2bridge * go format to fix the linter issue
1 parent 5011d9a commit 8e8a5fd

File tree

7 files changed

+45
-30
lines changed

7 files changed

+45
-30
lines changed

cni/azure-windows-swift-overlay-dualstack.conflist

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
"plugins": [
66
{
77
"type": "azure-vnet",
8-
"mode": "bridge",
98
"bridge": "azure0",
109
"capabilities": {
1110
"portMappings": true,

cni/azure-windows-swift-overlay.conflist

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
"plugins": [
66
{
77
"type": "azure-vnet",
8-
"mode": "bridge",
98
"bridge": "azure0",
109
"capabilities": {
1110
"portMappings": true,

cni/azure-windows-swift.conflist

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
"plugins": [
66
{
77
"type": "azure-vnet",
8-
"mode": "bridge",
98
"bridge": "azure0",
109
"executionMode": "v4swift",
1110
"capabilities": {

cns/hnsclient/hnsclient_windows.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ const (
3030

3131
// HNS network types
3232
hnsL2Bridge = "l2bridge"
33-
hnsL2Tunnel = "l2tunnel"
3433

3534
// hcnSchemaVersionMajor indicates major version number for hcn schema
3635
hcnSchemaVersionMajor = 2
@@ -145,7 +144,7 @@ func CreateDefaultExtNetwork(networkType string) error {
145144
return nil
146145
}
147146

148-
if networkType != hnsL2Bridge && networkType != hnsL2Tunnel {
147+
if networkType != hnsL2Bridge {
149148
return fmt.Errorf("Invalid hns network type %s", networkType)
150149
}
151150

cns/service/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ var args = acn.ArgumentList{
244244
{
245245
Name: acn.OptCreateDefaultExtNetworkType,
246246
Shorthand: acn.OptCreateDefaultExtNetworkTypeAlias,
247-
Description: "Create default external network for windows platform with the specified type (l2bridge or l2tunnel)",
247+
Description: "Create default external network for windows platform with the specified type (l2bridge)",
248248
Type: "string",
249249
DefaultValue: "",
250250
},

network/network_windows.go

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import (
2424
const (
2525
// HNS network types.
2626
hnsL2bridge = "l2bridge"
27-
hnsL2tunnel = "l2tunnel"
2827
CnetAddressSpace = "cnetAddressSpace"
2928
vEthernetAdapterPrefix = "vEthernet"
3029
baseDecimal = 10
@@ -113,6 +112,7 @@ func (nm *networkManager) newNetworkImplHnsV1(nwInfo *EndpointInfo, extIf *exter
113112
// Initialize HNS network.
114113
hnsNetwork := &hcsshim.HNSNetwork{
115114
Name: nwInfo.NetworkID,
115+
Type: hnsL2bridge,
116116
NetworkAdapterName: networkAdapterName,
117117
Policies: policy.SerializePolicies(policy.NetworkPolicy, nwInfo.NetworkPolicies, nil, false, false),
118118
}
@@ -132,16 +132,6 @@ func (nm *networkManager) newNetworkImplHnsV1(nwInfo *EndpointInfo, extIf *exter
132132
vlanid = (int)(vlanPolicy.VLAN)
133133
}
134134

135-
// Set network mode.
136-
switch nwInfo.Mode {
137-
case opModeBridge:
138-
hnsNetwork.Type = hnsL2bridge
139-
case opModeTunnel:
140-
hnsNetwork.Type = hnsL2tunnel
141-
default:
142-
return nil, errNetworkModeInvalid
143-
}
144-
145135
// Populate subnets.
146136
for _, subnet := range nwInfo.Subnets {
147137
hnsSubnet := hcsshim.Subnet{
@@ -233,6 +223,7 @@ func (nm *networkManager) configureHcnNetwork(nwInfo *EndpointInfo, extIf *exter
233223
// Initialize HNS network.
234224
hcnNetwork := &hcn.HostComputeNetwork{
235225
Name: nwInfo.NetworkID,
226+
Type: hcn.L2Bridge,
236227
Ipams: []hcn.Ipam{
237228
{
238229
Type: hcnIpamTypeStatic,
@@ -287,16 +278,6 @@ func (nm *networkManager) configureHcnNetwork(nwInfo *EndpointInfo, extIf *exter
287278
vlanid = (int)(vlanID)
288279
}
289280

290-
// Set network mode.
291-
switch nwInfo.Mode {
292-
case opModeBridge:
293-
hcnNetwork.Type = hcn.L2Bridge
294-
case opModeTunnel:
295-
hcnNetwork.Type = hcn.L2Tunnel
296-
default:
297-
return nil, errNetworkModeInvalid
298-
}
299-
300281
// AccelnetNIC flag: hcn.EnableIov(9216) - treat Delegated/FrontendNIC also the same as Accelnet
301282
// For L1VH with accelnet, hcn.DisableHostPort and hcn.EnableIov must be configured
302283
if nwInfo.NICType == cns.NodeNetworkInterfaceFrontendNIC {

network/network_windows_test.go

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ func TestNewAndDeleteNetworkImplHnsV2(t *testing.T) {
6060
}
6161

6262
err = nm.deleteNetworkImplHnsV2(network)
63-
6463
if err != nil {
6564
fmt.Printf("+%v", err)
6665
t.Fatal(err)
@@ -95,7 +94,6 @@ func TestSuccesfulNetworkCreationWhenAlreadyExists(t *testing.T) {
9594
}
9695

9796
_, err = nm.newNetworkImplHnsV2(nwInfo, extInterface)
98-
9997
if err != nil {
10098
fmt.Printf("+%v", err)
10199
t.Fatal(err)
@@ -468,7 +466,6 @@ func TestNewAndDeleteNetworkImplHnsV2ForDelegated(t *testing.T) {
468466
}
469467

470468
err = nm.deleteNetworkImpl(network, cns.NodeNetworkInterfaceFrontendNIC)
471-
472469
if err != nil {
473470
fmt.Printf("+%v", err)
474471
t.Fatal(err)
@@ -522,6 +519,47 @@ func TestTransparentNetworkCreationForDelegated(t *testing.T) {
522519
}
523520
}
524521

522+
// Test Configure HNC network for infraNIC ensuring the hcn network type is always l2 bridge
523+
func TestConfigureHCNNetworkInfraNIC(t *testing.T) {
524+
expectedHcnNetworkType := hcn.L2Bridge
525+
526+
nm := &networkManager{
527+
ExternalInterfaces: map[string]*externalInterface{},
528+
}
529+
530+
extIf := externalInterface{
531+
Name: "eth0",
532+
}
533+
534+
nwInfo := &EndpointInfo{
535+
AdapterName: "eth0",
536+
NetworkID: "d3e97a83-ba4c-45d5-ba88-dc56757ece28",
537+
MasterIfName: "eth0",
538+
NICType: cns.InfraNIC,
539+
IfIndex: 1,
540+
EndpointID: "753d3fb6-e9b3-49e2-a109-2acc5dda61f1",
541+
ContainerID: "545055c2-1462-42c8-b222-e75d0b291632",
542+
NetNsPath: "fakeNameSpace",
543+
IfName: "eth0",
544+
Data: make(map[string]interface{}),
545+
EndpointDNS: DNSInfo{
546+
Suffix: "10.0.0.0",
547+
Servers: []string{"10.0.0.1, 10.0.0.2"},
548+
Options: nil,
549+
},
550+
HNSNetworkID: "853d3fb6-e9b3-49e2-a109-2acc5dda61f1",
551+
}
552+
553+
hostComputeNetwork, err := nm.configureHcnNetwork(nwInfo, &extIf)
554+
if err != nil {
555+
t.Fatalf("Failed to configure hcn network for infraNIC interface due to: %v", err)
556+
}
557+
558+
if hostComputeNetwork.Type != expectedHcnNetworkType {
559+
t.Fatalf("Host network mode is not configured as %v mode when interface NIC type is infraNIC", expectedHcnNetworkType)
560+
}
561+
}
562+
525563
// Test Configure HCN Network for Swiftv2 DelegatedNIC HostComputeNetwork fields
526564
func TestConfigureHCNNetworkSwiftv2DelegatedNIC(t *testing.T) {
527565
expectedSwiftv2NetworkMode := hcn.Transparent

0 commit comments

Comments
 (0)