Skip to content

Commit

Permalink
Fix client node detection.
Browse files Browse the repository at this point in the history
Signed-off-by: Vitaliy Guschin <[email protected]>
  • Loading branch information
Vitaliy Guschin committed Apr 25, 2024
1 parent 5f9d0de commit 166ac78
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 14 deletions.
2 changes: 2 additions & 0 deletions model.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ const (
managerNT NodeType = "manager"
endpointNT NodeType = "endpoint"
serviceNT NodeType = "service"
unknownNT NodeType = "unknown"
// registryNT NodeType = "registry"
)

Expand All @@ -69,4 +70,5 @@ const (
const (
clientInterface string = "client_interface"
serverInterface string = "server_interface"
unknown string = "unknown"
)
12 changes: 7 additions & 5 deletions model_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ func parceConnectionsToGraphicalModel() {
interfaceType = interfaceNT
}
var previousInterfaceID string
for _, segment := range pathSegments {
segmentType := getPathSegmentType(segment.GetName())
for i, segment := range pathSegments {
segmentType := getPathSegmentType(i, segment.GetName())

// Add segment node
node := makeSegmentNode(nodeMap, segment.GetName(), clusterLocal.Data.ID, ns.Data.ID, segmentType)
Expand Down Expand Up @@ -212,7 +212,7 @@ func getInterfaceLabelFromMetrics(segment *networkservice.PathSegment, interface
if metrics != nil && metrics[interfaceType] != "" {
return metrics[interfaceType]
}
return "unknown"
return unknown
}

func duplicateNodeExists(nodeMap map[string]Node, id string) bool {
Expand All @@ -230,16 +230,18 @@ func mapToArray(nodeMap map[string]Node) []Node {
return nodes
}

func getPathSegmentType(name string) NodeType {
func getPathSegmentType(index int, name string) NodeType {
switch {
case index == 0:
return clientNT
case strings.HasPrefix(name, "nsmgr-"):
return managerNT
case strings.HasPrefix(name, "forwarder-") || strings.HasPrefix(name, "fwd-"):
return forwarderNT
case strings.HasPrefix(name, "nse-"):
return endpointNT
default:
return clientNT
return unknownNT
}
}

Expand Down
32 changes: 23 additions & 9 deletions model_utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ func Test_Interface_Order(t *testing.T) {
Name: fwd1Name,
Id: "23456",
Metrics: map[string]string{
"client_interface": cifFwd1Name,
"server_interface": sifFwd1Name,
"client_interface": cifFwd1Name,
},
},
{
Expand All @@ -74,8 +74,8 @@ func Test_Interface_Order(t *testing.T) {
Name: fwd2Name,
Id: "45678",
Metrics: map[string]string{
"client_interface": cifFwd2Name,
"server_interface": sifFwd2Name,
"client_interface": cifFwd2Name,
},
},
{
Expand Down Expand Up @@ -144,7 +144,7 @@ func Test_NSE_To_NSE_Connection(t *testing.T) {
Name: "nse-vl3-vpp-9ln7f",
Id: "12345",
Metrics: map[string]string{
"server_interface": "MEMIF/memif2670642822/2",
"client_interface": "KERNEL/nsmf{[CkfpGN2We",
},
},
{
Expand All @@ -155,8 +155,8 @@ func Test_NSE_To_NSE_Connection(t *testing.T) {
Name: "forwarder-vpp-zpg6b",
Id: "34567",
Metrics: map[string]string{
"server_interface": "VIRTIO/tun0",
"client_interface": "WIREGUARD TUNNEL/wg1",
"server_interface": "MEMIF/memif2670642822/0",
},
},
{
Expand All @@ -167,8 +167,8 @@ func Test_NSE_To_NSE_Connection(t *testing.T) {
Name: "forwarder-vpp-s7sw5",
Id: "56789",
Metrics: map[string]string{
"client_interface": "MEMIF/memif2670642822/0",
"server_interface": "WIREGUARD TUNNEL/wg1",
"client_interface": "MEMIF/memif2670642822/0",
},
},
{
Expand Down Expand Up @@ -209,6 +209,10 @@ func Test_Looped_NSE_To_NSE_Connection(t *testing.T) {
})

const nsmgrAddr = "10.244.1.6:5001"
const cifNseName = "KERNEL/nsmf{[CkfpGN2We"
const sifFwd1Name = "VIRTIO/tun0"
const cifFwd1Name = "MEMIF/memif3519870697/0"
const sifNseName = "MEMIF/memif2670642822/1"

connection := &networkservice.Connection{
NetworkService: "ns2",
Expand All @@ -218,7 +222,7 @@ func Test_Looped_NSE_To_NSE_Connection(t *testing.T) {
Name: "nse-vl3-vpp-gcf6j",
Id: "12345",
Metrics: map[string]string{
"server_interface": "MEMIF/memif2670642822/2",
"client_interface": cifNseName,
},
},
{
Expand All @@ -229,15 +233,15 @@ func Test_Looped_NSE_To_NSE_Connection(t *testing.T) {
Name: "forwarder-vpp-s7sw5",
Id: "34567",
Metrics: map[string]string{
"client_interface": "MEMIF/memif3519870697/0",
"server_interface": "VIRTIO/tun0",
"server_interface": sifFwd1Name,
"client_interface": cifFwd1Name,
},
},
{
Name: "nse-vl3-vpp-gcf6j",
Id: "12345",
Metrics: map[string]string{
"server_interface": "MEMIF/memif2670642822/1",
"server_interface": sifNseName,
},
},
},
Expand All @@ -260,6 +264,16 @@ func Test_Looped_NSE_To_NSE_Connection(t *testing.T) {
require.Equal(t, interfaceLoopedConnection, edge.Data.Type)
}

// Check interface names
found := 0
for _, node := range storageData.Nodes {
switch node.Data.Label {
case cifNseName, sifFwd1Name, cifFwd1Name, sifNseName:
found++
}
}
require.Equal(t, 4, found, "Unexpected interface names count detected")

// Cleanup
connections.Delete(connectionID)
managerConnections.Delete(nsmgrAddr)
Expand Down

0 comments on commit 166ac78

Please sign in to comment.