Skip to content

Commit

Permalink
add L1VH windows support
Browse files Browse the repository at this point in the history
  • Loading branch information
paulyufan2 committed Apr 16, 2024
1 parent c8a1156 commit 2af1543
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
6 changes: 6 additions & 0 deletions cni/network/invoker_cns.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,11 @@ func (invoker *CNSIPAMInvoker) Add(addConfig IPAMAddConfig) (IPAMAddResult, erro
numInterfacesWithDefaultRoutes++
}

// Add secondary interface info from podIPInfo to ipamAddResult
info.hostSubnet = response.PodIPInfo[i].HostPrimaryIPInfo.Subnet
info.hostPrimaryIP = response.PodIPInfo[i].HostPrimaryIPInfo.PrimaryIP
info.hostGateway = response.PodIPInfo[i].HostPrimaryIPInfo.Gateway

if err := configureSecondaryAddResult(&info, &addResult, &response.PodIPInfo[i].PodIPConfig); err != nil {
return IPAMAddResult{}, err
}
Expand Down Expand Up @@ -476,6 +481,7 @@ func configureSecondaryAddResult(info *IPResultInfo, addResult *IPAMAddResult, p
IP: ip,
Mask: ipnet.Mask,
},
Gateway: net.ParseIP(info.ncGatewayIPAddress),
},
},
Routes: routes,
Expand Down
27 changes: 25 additions & 2 deletions network/endpoint_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"net"
"strings"

"github.com/Azure/azure-container-networking/cns"
"github.com/Azure/azure-container-networking/netio"
"github.com/Azure/azure-container-networking/netlink"
"github.com/Azure/azure-container-networking/network/policy"
Expand Down Expand Up @@ -75,7 +76,7 @@ func (nw *network) newEndpointImpl(
_ ipTablesClient,
epInfo *EndpointInfo,
) (*endpoint, error) {
// there is only 1 epInfo for windows, multiple interfaces will be added in the future

Check failure on line 79 in network/endpoint_windows.go

View workflow job for this annotation

GitHub Actions / Lint (1.21.x, windows-latest)

File is not `gofumpt`-ed (gofumpt)
if useHnsV2, err := UseHnsV2(epInfo.NetNsPath); useHnsV2 {
if err != nil {
return nil, err
Expand All @@ -85,6 +86,7 @@ func (nw *network) newEndpointImpl(
}

return nw.newEndpointImplHnsV1(epInfo, plc)
// TODO: add switch statement for NIC type for IB and Accelnet NIC support to create endpoint here in the future
}

// newEndpointImplHnsV1 creates a new endpoint in the network using HnsV1
Expand Down Expand Up @@ -220,9 +222,16 @@ func (nw *network) configureHcnEndpoint(epInfo *EndpointInfo) (*hcn.HostComputeE
Major: hcnSchemaVersionMajor,
Minor: hcnSchemaVersionMinor,
},
MacAddress: epInfo.MacAddress.String(),
}

// macAddress type for InfraNIC is like "60:45:bd:12:45:65"
macAddress := epInfo.MacAddress.String()
if epInfo.NICType != cns.InfraNIC {
// convert the format of macAddress that HNS can accept, i.e, "60-45-bd-12-45-65" if NIC type is delegated NIC
macAddress = strings.Join(strings.Split(macAddress, ":"), "-")
}
hcnEndpoint.MacAddress = macAddress

if endpointPolicies, err := policy.GetHcnEndpointPolicies(policy.EndpointPolicy, epInfo.Policies, epInfo.Data, epInfo.EnableSnatForDns, epInfo.EnableMultiTenancy, epInfo.NATInfo); err == nil {
for _, epPolicy := range endpointPolicies {
hcnEndpoint.Policies = append(hcnEndpoint.Policies, epPolicy)
Expand Down Expand Up @@ -399,6 +408,7 @@ func (nw *network) newEndpointImplHnsV2(cli apipaClient, epInfo *EndpointInfo) (
ContainerID: epInfo.ContainerID,
PODName: epInfo.PODName,
PODNameSpace: epInfo.PODNameSpace,
// SecondaryInterfaces: make(map[string]*InterfaceInfo),
}

for _, route := range epInfo.Routes {
Expand All @@ -407,6 +417,19 @@ func (nw *network) newEndpointImplHnsV2(cli apipaClient, epInfo *EndpointInfo) (

ep.MacAddress, _ = net.ParseMAC(hnsResponse.MacAddress)

// Confirm with TM: when we delete an endpoint, this code is to find ifName from endpoint and then we can delete this endpoint
// ipconfigs := make([]*IPConfig, len(ep.IPAddresses))
// for i, ipconfig := range ep.IPAddresses {
// ipconfigs[i] = &IPConfig{Address: ipconfig}
// }

// // Add secondary interfaces info to CNI state file

Check failure on line 426 in network/endpoint_windows.go

View workflow job for this annotation

GitHub Actions / Lint (1.21.x, windows-latest)

commentedOutCode: may want to remove commented-out code (gocritic)
// ep.SecondaryInterfaces[ep.IfName] = &InterfaceInfo{
// MacAddress: ep.MacAddress,
// IPConfigs: ipconfigs,
// Routes: ep.Routes,
// }

return ep, nil
}

Expand Down
6 changes: 6 additions & 0 deletions network/network_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"strings"
"time"

"github.com/Azure/azure-container-networking/cns"
"github.com/Azure/azure-container-networking/network/hnswrapper"
"github.com/Azure/azure-container-networking/network/policy"
"github.com/Azure/azure-container-networking/platform"
Expand Down Expand Up @@ -299,6 +300,11 @@ func (nm *networkManager) configureHcnNetwork(nwInfo *EndpointInfo, extIf *exter
return nil, errNetworkModeInvalid
}

if nwInfo.NICType == cns.DelegatedVMNIC {
hcnNetwork.Type = hcn.Transparent
hcnNetwork.Flags = hcn.DisableHostPort
}

// Populate subnets.
for _, subnet := range nwInfo.Subnets {
hnsSubnet := hcn.Subnet{
Expand Down

0 comments on commit 2af1543

Please sign in to comment.