Skip to content

Commit

Permalink
Fixed constructing endpointID (#210)
Browse files Browse the repository at this point in the history
  • Loading branch information
tamilmani1989 authored and sharmasushant committed Jul 25, 2018
1 parent 8620eac commit 59ae2cd
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 27 deletions.
28 changes: 2 additions & 26 deletions network/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package network

import (
"net"
"strings"

"github.com/Azure/azure-container-networking/log"
"github.com/Azure/azure-container-networking/network/policy"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
15 changes: 14 additions & 1 deletion network/endpoint_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
26 changes: 26 additions & 0 deletions network/endpoint_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 10 additions & 0 deletions network/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 59ae2cd

Please sign in to comment.