Skip to content

Commit 59ae2cd

Browse files
tamilmani1989sharmasushant
authored andcommitted
Fixed constructing endpointID (#210)
1 parent 8620eac commit 59ae2cd

File tree

4 files changed

+52
-27
lines changed

4 files changed

+52
-27
lines changed

network/endpoint.go

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ package network
55

66
import (
77
"net"
8-
"strings"
98

109
"github.com/Azure/azure-container-networking/log"
1110
"github.com/Azure/azure-container-networking/network/policy"
@@ -52,31 +51,6 @@ type RouteInfo struct {
5251
DevName string
5352
}
5453

55-
// ConstructEndpointID constructs endpoint name from netNsPath.
56-
func ConstructEndpointID(containerID string, netNsPath string, ifName string) (string, string) {
57-
infraEpName, workloadEpName := "", ""
58-
59-
if len(containerID) > 8 {
60-
containerID = containerID[:8]
61-
}
62-
63-
if netNsPath != "" {
64-
splits := strings.Split(netNsPath, ":")
65-
// For workload containers, we extract its linking infrastructure container ID.
66-
if len(splits) == 2 {
67-
if len(splits[1]) > 8 {
68-
splits[1] = splits[1][:8]
69-
}
70-
infraEpName = splits[1] + "-" + ifName
71-
workloadEpName = containerID + "-" + ifName
72-
} else {
73-
// For infrastructure containers, we just use its container ID.
74-
infraEpName = containerID + "-" + ifName
75-
}
76-
}
77-
return infraEpName, workloadEpName
78-
}
79-
8054
// NewEndpoint creates a new endpoint in the network.
8155
func (nw *network) newEndpoint(epInfo *EndpointInfo) (*endpoint, error) {
8256
var ep *endpoint
@@ -135,6 +109,8 @@ func (nw *network) deleteEndpoint(endpointId string) error {
135109

136110
// GetEndpoint returns the endpoint with the given ID.
137111
func (nw *network) getEndpoint(endpointId string) (*endpoint, error) {
112+
log.Printf("Trying to retrieve endpoint id %v", endpointId)
113+
138114
ep := nw.Endpoints[endpointId]
139115

140116
if ep == nil {

network/endpoint_linux.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,19 @@ func generateVethName(key string) string {
3131
return hex.EncodeToString(h.Sum(nil))[:11]
3232
}
3333

34+
func ConstructEndpointID(containerID string, netNsPath string, ifName string) (string, string) {
35+
if len(containerID) > 8 {
36+
containerID = containerID[:8]
37+
} else {
38+
log.Printf("Container ID is not greater than 8 ID: %v", containerID)
39+
return "", ""
40+
}
41+
42+
infraEpName := containerID + "-" + ifName
43+
44+
return infraEpName, ""
45+
}
46+
3447
// newEndpointImpl creates a new endpoint in the network.
3548
func (nw *network) newEndpointImpl(epInfo *EndpointInfo) (*endpoint, error) {
3649
var containerIf *net.Interface
@@ -159,7 +172,7 @@ func (nw *network) newEndpointImpl(epInfo *EndpointInfo) (*endpoint, error) {
159172
// Create the endpoint object.
160173
ep = &endpoint{
161174
Id: epInfo.Id,
162-
IfName: contIfName,
175+
IfName: epInfo.IfName,
163176
HostIfName: hostIfName,
164177
MacAddress: containerIf.HardwareAddr,
165178
IPAddresses: epInfo.IPAddresses,

network/endpoint_windows.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,32 @@ func (endpoint *EndpointInfo) HotAttachEndpoint(containerID string) error {
2020
return hcsshim.HotAttachEndpoint(containerID, endpoint.Id)
2121
}
2222

23+
// ConstructEndpointID constructs endpoint name from netNsPath.
24+
func ConstructEndpointID(containerID string, netNsPath string, ifName string) (string, string) {
25+
infraEpName, workloadEpName := "", ""
26+
27+
if len(containerID) > 8 {
28+
containerID = containerID[:8]
29+
}
30+
31+
if netNsPath != "" {
32+
splits := strings.Split(netNsPath, ":")
33+
// For workload containers, we extract its linking infrastructure container ID.
34+
if len(splits) == 2 {
35+
if len(splits[1]) > 8 {
36+
splits[1] = splits[1][:8]
37+
}
38+
infraEpName = splits[1] + "-" + ifName
39+
workloadEpName = containerID + "-" + ifName
40+
} else {
41+
// For infrastructure containers, we just use its container ID.
42+
infraEpName = containerID + "-" + ifName
43+
}
44+
}
45+
46+
return infraEpName, workloadEpName
47+
}
48+
2349
// newEndpointImpl creates a new endpoint in the network.
2450
func (nw *network) newEndpointImpl(epInfo *EndpointInfo) (*endpoint, error) {
2551
// Get Infrastructure containerID. Handle ADD calls for workload container.

network/manager.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,16 @@ func (nm *networkManager) restore() error {
152152
}
153153

154154
log.Printf("[net] Restored state, %+v\n", nm)
155+
for _, extIf := range nm.ExternalInterfaces {
156+
log.Printf("External Interface %v", extIf)
157+
for _, nw := range extIf.Networks {
158+
log.Printf("network %v", nw)
159+
for _, ep := range nw.Endpoints {
160+
log.Printf("endpoint %v", ep)
161+
}
162+
}
163+
}
164+
155165
return nil
156166
}
157167

0 commit comments

Comments
 (0)