From 2af154331bf9f2bb8e2aaeaa4edb14862a5d7876 Mon Sep 17 00:00:00 2001 From: paulyufan2 Date: Tue, 16 Apr 2024 18:48:29 -0400 Subject: [PATCH] add L1VH windows support --- cni/network/invoker_cns.go | 6 ++++++ network/endpoint_windows.go | 27 +++++++++++++++++++++++++-- network/network_windows.go | 6 ++++++ 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/cni/network/invoker_cns.go b/cni/network/invoker_cns.go index 8702e20638..4fd3729334 100644 --- a/cni/network/invoker_cns.go +++ b/cni/network/invoker_cns.go @@ -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 } @@ -476,6 +481,7 @@ func configureSecondaryAddResult(info *IPResultInfo, addResult *IPAMAddResult, p IP: ip, Mask: ipnet.Mask, }, + Gateway: net.ParseIP(info.ncGatewayIPAddress), }, }, Routes: routes, diff --git a/network/endpoint_windows.go b/network/endpoint_windows.go index 586c8237bf..cc28a4a56e 100644 --- a/network/endpoint_windows.go +++ b/network/endpoint_windows.go @@ -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" @@ -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 + if useHnsV2, err := UseHnsV2(epInfo.NetNsPath); useHnsV2 { if err != nil { return nil, err @@ -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 @@ -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) @@ -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 { @@ -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 + // ep.SecondaryInterfaces[ep.IfName] = &InterfaceInfo{ + // MacAddress: ep.MacAddress, + // IPConfigs: ipconfigs, + // Routes: ep.Routes, + // } + return ep, nil } diff --git a/network/network_windows.go b/network/network_windows.go index 913bf029b6..6fb92ea923 100644 --- a/network/network_windows.go +++ b/network/network_windows.go @@ -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" @@ -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{