diff --git a/network/endpoint.go b/network/endpoint.go index ee0e945573..12cb53206c 100644 --- a/network/endpoint.go +++ b/network/endpoint.go @@ -5,7 +5,6 @@ package network import ( "net" - "strings" "github.com/Azure/azure-container-networking/log" "github.com/Azure/azure-container-networking/network/policy" @@ -52,31 +51,6 @@ type RouteInfo struct { DevName string } -// ConstructEndpointID constructs endpoint name from netNsPath. -func ConstructEndpointID(containerID string, netNsPath string, ifName string) (string, string) { - infraEpName, workloadEpName := "", "" - - if len(containerID) > 8 { - containerID = containerID[:8] - } - - if netNsPath != "" { - splits := strings.Split(netNsPath, ":") - // For workload containers, we extract its linking infrastructure container ID. - if len(splits) == 2 { - if len(splits[1]) > 8 { - splits[1] = splits[1][:8] - } - infraEpName = splits[1] + "-" + ifName - workloadEpName = containerID + "-" + ifName - } else { - // For infrastructure containers, we just use its container ID. - infraEpName = containerID + "-" + ifName - } - } - return infraEpName, workloadEpName -} - // NewEndpoint creates a new endpoint in the network. func (nw *network) newEndpoint(epInfo *EndpointInfo) (*endpoint, error) { var ep *endpoint @@ -135,6 +109,8 @@ func (nw *network) deleteEndpoint(endpointId string) error { // GetEndpoint returns the endpoint with the given ID. func (nw *network) getEndpoint(endpointId string) (*endpoint, error) { + log.Printf("Trying to retrieve endpoint id %v", endpointId) + ep := nw.Endpoints[endpointId] if ep == nil { diff --git a/network/endpoint_linux.go b/network/endpoint_linux.go index 690fab492e..4862b5c35d 100644 --- a/network/endpoint_linux.go +++ b/network/endpoint_linux.go @@ -31,6 +31,19 @@ func generateVethName(key string) string { return hex.EncodeToString(h.Sum(nil))[:11] } +func ConstructEndpointID(containerID string, netNsPath string, ifName string) (string, string) { + if len(containerID) > 8 { + containerID = containerID[:8] + } else { + log.Printf("Container ID is not greater than 8 ID: %v", containerID) + return "", "" + } + + infraEpName := containerID + "-" + ifName + + return infraEpName, "" +} + // newEndpointImpl creates a new endpoint in the network. func (nw *network) newEndpointImpl(epInfo *EndpointInfo) (*endpoint, error) { var containerIf *net.Interface @@ -159,7 +172,7 @@ func (nw *network) newEndpointImpl(epInfo *EndpointInfo) (*endpoint, error) { // Create the endpoint object. ep = &endpoint{ Id: epInfo.Id, - IfName: contIfName, + IfName: epInfo.IfName, HostIfName: hostIfName, MacAddress: containerIf.HardwareAddr, IPAddresses: epInfo.IPAddresses, diff --git a/network/endpoint_windows.go b/network/endpoint_windows.go index aa76b6a89f..5d2b70ba19 100644 --- a/network/endpoint_windows.go +++ b/network/endpoint_windows.go @@ -20,6 +20,32 @@ func (endpoint *EndpointInfo) HotAttachEndpoint(containerID string) error { return hcsshim.HotAttachEndpoint(containerID, endpoint.Id) } +// ConstructEndpointID constructs endpoint name from netNsPath. +func ConstructEndpointID(containerID string, netNsPath string, ifName string) (string, string) { + infraEpName, workloadEpName := "", "" + + if len(containerID) > 8 { + containerID = containerID[:8] + } + + if netNsPath != "" { + splits := strings.Split(netNsPath, ":") + // For workload containers, we extract its linking infrastructure container ID. + if len(splits) == 2 { + if len(splits[1]) > 8 { + splits[1] = splits[1][:8] + } + infraEpName = splits[1] + "-" + ifName + workloadEpName = containerID + "-" + ifName + } else { + // For infrastructure containers, we just use its container ID. + infraEpName = containerID + "-" + ifName + } + } + + return infraEpName, workloadEpName +} + // newEndpointImpl creates a new endpoint in the network. func (nw *network) newEndpointImpl(epInfo *EndpointInfo) (*endpoint, error) { // Get Infrastructure containerID. Handle ADD calls for workload container. diff --git a/network/manager.go b/network/manager.go index 1a3d8d96a9..e40ca78a7f 100644 --- a/network/manager.go +++ b/network/manager.go @@ -152,6 +152,16 @@ func (nm *networkManager) restore() error { } log.Printf("[net] Restored state, %+v\n", nm) + for _, extIf := range nm.ExternalInterfaces { + log.Printf("External Interface %v", extIf) + for _, nw := range extIf.Networks { + log.Printf("network %v", nw) + for _, ep := range nw.Endpoints { + log.Printf("endpoint %v", ep) + } + } + } + return nil }