Skip to content

Commit acb3a85

Browse files
atulpatel261194Dimitrios MarkouvenkyvspInbanoth
authored andcommitted
fix(evpn): use latest evpn opi-api
Signed-off-by: Atul Patel <[email protected]> Co-authored-by: Dimitrios Markou <[email protected]> Co-authored-by: Venkatesh Vemula <[email protected]> Co-authored-by: Banoth Saikumar <[email protected]>
1 parent 6e3f317 commit acb3a85

File tree

7 files changed

+145
-47
lines changed

7 files changed

+145
-47
lines changed

cmd/network/evpn-bridge-port.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// SPDX-License-Identifier: Apache-2.0
22
// Copyright (c) 2022-2023 Intel Corporation, or its subsidiaries.
33
// Copyright (c) 2022-2023 Dell Inc, or its subsidiaries.
4+
// Copyright (c) 2024 Ericsson AB.
45

56
// Package network implements the network related CLI commands
67
package network
@@ -38,8 +39,9 @@ func CreateBridgePort() *cobra.Command {
3839
if err != nil {
3940
log.Fatalf("could not create Bridge Port: %v", err)
4041
}
41-
log.Printf("Created Bridge Port:\n status: %s\n type: %s\n name: %s\n bridges: %s\n mac: %s\n", bridgePort.GetStatus().GetOperStatus(), bridgePort.GetSpec().GetPtype(),
42-
bridgePort.GetName(), bridgePort.GetSpec().GetLogicalBridges(), bridgePort.GetSpec().GetMacAddress())
42+
43+
log.Println("Created Bridge Port:")
44+
PrintBP(bridgePort)
4345
},
4446
}
4547

@@ -89,7 +91,7 @@ func DeleteBridgePort() *cobra.Command {
8991
if err != nil {
9092
log.Fatalf("DeleteBridgePort: Error occurred while deleting Bridge Port: %q", err)
9193
}
92-
log.Printf("Deleted BridgePort ")
94+
log.Printf("Deleted BridgePort: %s\n", name)
9395
},
9496
}
9597

@@ -122,8 +124,8 @@ func GetBridgePort() *cobra.Command {
122124
if err != nil {
123125
log.Fatalf("GetBridgePort: Error occurred while creating Bridge Port: %q", err)
124126
}
125-
log.Printf("Bridge Port:\n status: %s\n type: %s\n name: %s\n bridges: %s\n mac: %s\n", bridgePort.GetStatus().GetOperStatus(), bridgePort.GetSpec().GetPtype(),
126-
bridgePort.GetName(), bridgePort.GetSpec().GetLogicalBridges(), bridgePort.GetSpec().GetMacAddress())
127+
log.Println("Get Bridge Port:")
128+
PrintBP(bridgePort)
127129
},
128130
}
129131

@@ -158,9 +160,10 @@ func ListBridgePorts() *cobra.Command {
158160
log.Fatalf("Failed to get items: %v", err)
159161
}
160162
// Process the server response
163+
log.Println("List Bridge Ports:")
161164
for _, bridgePort := range resp.BridgePorts {
162-
log.Printf("Bridge Port:\n status: %s\n type: %s\n name: %s\n bridges: %s\n mac: %s\n", bridgePort.GetStatus().GetOperStatus(), bridgePort.GetSpec().GetPtype(),
163-
bridgePort.GetName(), bridgePort.GetSpec().GetLogicalBridges(), bridgePort.GetSpec().GetMacAddress())
165+
log.Println("Bridge Port with:")
166+
PrintBP(bridgePort)
164167
}
165168

166169
// Check if there are more pages to retrieve
@@ -203,8 +206,9 @@ func UpdateBridgePort() *cobra.Command {
203206
if err != nil {
204207
log.Fatalf("UpdateBridgePort: Error occurred while creating Bridge Port: %q", err)
205208
}
206-
log.Printf("Bridge Port:\n status: %s\n type: %s\n name: %s\n bridges: %s\n mac: %s\n", bridgePort.GetStatus().GetOperStatus(), bridgePort.GetSpec().GetPtype(),
207-
bridgePort.GetName(), bridgePort.GetSpec().GetLogicalBridges(), bridgePort.GetSpec().GetMacAddress())
209+
210+
log.Println("Updated Bridge Port:")
211+
PrintBP(bridgePort)
208212
},
209213
}
210214
cmd.Flags().StringVar(&name, "name", "", "name of the Bridge Port")

cmd/network/evpn-logical-brige.go

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// SPDX-License-Identifier: Apache-2.0
22
// Copyright (c) 2022-2023 Intel Corporation, or its subsidiaries.
33
// Copyright (c) 2022-2023 Dell Inc, or its subsidiaries.
4+
// Copyright (c) 2024 Ericsson AB.
45

56
// Package network implements the network related CLI commands
67
package network
@@ -34,13 +35,13 @@ func CreateLogicalBridge() *cobra.Command {
3435
}
3536
defer cancel()
3637

37-
resp, err := evpnClient.CreateLogicalBridge(ctx, name, vlanID, vni, vtep)
38+
lb, err := evpnClient.CreateLogicalBridge(ctx, name, vlanID, vni, vtep)
3839
if err != nil {
3940
log.Fatalf("failed to create logical bridge: %v", err)
4041
}
4142

42-
log.Printf(" Created Logical Bridge \n name: %s\n vlan: %d\n vni: %d\n status: %s\n VtepIpPrefix:%s", resp.GetName(), resp.GetSpec().GetVlanId(),
43-
resp.GetSpec().GetVni(), resp.GetStatus(), resp.GetSpec().GetVtepIpPrefix())
43+
log.Println("Created Logical Bridge:")
44+
PrintLB(lb)
4445
},
4546
}
4647
cmd.Flags().StringVar(&addr, "addr", "localhost:50151", "address of OPI gRPC server")
@@ -83,12 +84,12 @@ func DeleteLogicalBridge() *cobra.Command {
8384
}
8485
defer cancel()
8586

86-
resp, err := evpnClient.DeleteLogicalBridge(ctx, name, allowMissing)
87+
_, err = evpnClient.DeleteLogicalBridge(ctx, name, allowMissing)
8788
if err != nil {
8889
log.Fatalf("failed to delete logical bridge: %v", err)
8990
}
9091

91-
log.Printf("Deleted Logical Bridge: %s\n", resp)
92+
log.Printf("Deleted Logical Bridge: %s\n", name)
9293
},
9394
}
9495

@@ -119,13 +120,13 @@ func GetLogicalBridge() *cobra.Command {
119120
}
120121
defer cancel()
121122

122-
resp, err := evpnClient.GetLogicalBridge(ctx, name)
123+
lb, err := evpnClient.GetLogicalBridge(ctx, name)
123124
if err != nil {
124125
log.Fatalf("failed to get logical bridge: %v", err)
125126
}
126127

127-
log.Printf(" Created Logical Bridge \n name: %s\n vlan: %d\n vni: %d\n status: %s\n VtepIpPrefix:%s", resp.GetName(), resp.GetSpec().GetVlanId(),
128-
resp.GetSpec().GetVni(), resp.GetStatus(), resp.GetSpec().GetVtepIpPrefix())
128+
log.Println("Get Logical Bridge:")
129+
PrintLB(lb)
129130
},
130131
}
131132

@@ -160,9 +161,10 @@ func ListLogicalBridges() *cobra.Command {
160161
log.Fatalf("Failed to get items: %v", err)
161162
}
162163
// Process the server response
163-
for _, item := range resp.LogicalBridges {
164-
log.Printf(" Created Logical Bridge \n name: %s\n vlan: %d\n vni: %d\n status: %s\n VtepIpPrefix:%s", item.GetName(), item.GetSpec().GetVlanId(),
165-
item.GetSpec().GetVni(), item.GetStatus(), item.GetSpec().GetVtepIpPrefix())
164+
log.Println("List Logical Bridges:")
165+
for _, lb := range resp.LogicalBridges {
166+
log.Println("Logical Bridge with: ")
167+
PrintLB(lb)
166168
}
167169

168170
// Check if there are more pages to retrieve
@@ -198,13 +200,12 @@ func UpdateLogicalBridge() *cobra.Command {
198200
}
199201
defer cancel()
200202

201-
resp, err := evpnClient.UpdateLogicalBridge(ctx, name, updateMask)
203+
lb, err := evpnClient.UpdateLogicalBridge(ctx, name, updateMask)
202204
if err != nil {
203205
log.Fatalf("failed to update logical bridge: %v", err)
204206
}
205-
206-
log.Printf(" Updated Logical Bridge \n name: %s\n vlan: %d\n vni: %d\n status: %s\n VtepIpPrefix:%s", resp.GetName(), resp.GetSpec().GetVlanId(),
207-
resp.GetSpec().GetVni(), resp.GetStatus(), resp.GetSpec().GetVtepIpPrefix())
207+
log.Println("Updated Logical Bridge:")
208+
PrintLB(lb)
208209
},
209210
}
210211
cmd.Flags().StringVar(&name, "name", "", "name of the logical bridge")

cmd/network/evpn-svi.go

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// SPDX-License-Identifier: Apache-2.0
22
// Copyright (c) 2022-2023 Intel Corporation, or its subsidiaries.
33
// Copyright (c) 2022-2023 Dell Inc, or its subsidiaries.
4+
// Copyright (c) 2024 Ericsson AB.
45

56
// Package network implements the network related CLI commands
67
package network
@@ -42,11 +43,11 @@ func CreateSVI() *cobra.Command {
4243
log.Fatalf("failed to create logical bridge: %v", err)
4344
}
4445

45-
log.Printf("CreateSVI: Created SVI \n name: %s\n status: %d\n Vrf: %s\n LogicalBridge: %s\n MacAddress: %s\n EnableBgp: %t\n GwIPs: %s\nremoteAS: %d\n",
46-
svi.GetName(), svi.GetStatus().GetOperStatus(), svi.GetSpec().GetVrf(), svi.GetSpec().GetLogicalBridge(), svi.GetSpec().GetMacAddress(),
47-
svi.GetSpec().GetEnableBgp(), svi.GetSpec().GetGwIpPrefix(), svi.GetSpec().GetRemoteAs())
46+
log.Println("Created SVI:")
47+
PrintSvi(svi)
4848
},
4949
}
50+
cmd.Flags().StringVar(&name, "name", "", "SVI Name")
5051
cmd.Flags().StringVar(&vrf, "vrf", "", "Must be unique")
5152
cmd.Flags().StringVar(&logicalBridge, "logicalBridge", "", "Pair of vni and vlan_id must be unique")
5253
cmd.Flags().StringVar(&mac, "mac", "", "GW MAC address, random MAC assigned if not specified")
@@ -95,7 +96,7 @@ func DeleteSVI() *cobra.Command {
9596
log.Fatalf("failed to create logical bridge: %v", err)
9697
}
9798

98-
log.Printf("Deleted SVI ")
99+
log.Printf("Deleted SVI: %s\n", name)
99100
},
100101
}
101102

@@ -129,9 +130,8 @@ func GetSVI() *cobra.Command {
129130
if err != nil {
130131
log.Fatalf("GetSVI: Error occurred while creating Bridge Port: %q", err)
131132
}
132-
log.Printf("GetSVI: Created SVI \n name: %s\n status: %d\n Vrf: %s\n LogicalBridge: %s\n MacAddress: %s\n EnableBgp: %t\n GwIPs: %s\nremoteAS: %d\n",
133-
svi.GetName(), svi.GetStatus().GetOperStatus(), svi.GetSpec().GetVrf(), svi.GetSpec().GetLogicalBridge(), svi.GetSpec().GetMacAddress(),
134-
svi.GetSpec().GetEnableBgp(), svi.GetSpec().GetGwIpPrefix(), svi.GetSpec().GetRemoteAs())
133+
log.Println("Get SVI:")
134+
PrintSvi(svi)
135135
},
136136
}
137137

@@ -166,10 +166,10 @@ func ListSVIs() *cobra.Command {
166166
log.Fatalf("Failed to get items: %v", err)
167167
}
168168
// Process the server response
169+
log.Println("List SVIs:")
169170
for _, svi := range resp.Svis {
170-
log.Printf("ListSVIs: SVI \n name: %s\n status: %d\n Vrf: %s\n LogicalBridge: %s\n MacAddress: %s\n EnableBgp: %t\n GwIPs: %s\nremoteAS: %d\n",
171-
svi.GetName(), svi.GetStatus().GetOperStatus(), svi.GetSpec().GetVrf(), svi.GetSpec().GetLogicalBridge(), svi.GetSpec().GetMacAddress(),
172-
svi.GetSpec().GetEnableBgp(), svi.GetSpec().GetGwIpPrefix(), svi.GetSpec().GetRemoteAs())
171+
log.Println("SVI with:")
172+
PrintSvi(svi)
173173
}
174174

175175
// Check if there are more pages to retrieve
@@ -212,9 +212,8 @@ func UpdateSVI() *cobra.Command {
212212
if err != nil {
213213
log.Fatalf("GetBridgePort: Error occurred while creating Bridge Port: %q", err)
214214
}
215-
log.Printf("UpdateSVI: SVI \n name: %s\n status: %d\n Vrf: %s\n LogicalBridge: %s\n MacAddress: %s\n EnableBgp: %t\n GwIPs: %s\nremoteAS: %d\n",
216-
svi.GetName(), svi.GetStatus().GetOperStatus(), svi.GetSpec().GetVrf(), svi.GetSpec().GetLogicalBridge(), svi.GetSpec().GetMacAddress(),
217-
svi.GetSpec().GetEnableBgp(), svi.GetSpec().GetGwIpPrefix(), svi.GetSpec().GetRemoteAs())
215+
log.Println("Updated SVI:")
216+
PrintSvi(svi)
218217
},
219218
}
220219
cmd.Flags().StringVar(&addr, "addr", "localhost:50151", "address of OPI gRPC server")

cmd/network/evpn-utils.go

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
// Copyright (c) 2022-2023 Intel Corporation, or its subsidiaries.
3+
// Copyright (c) 2022-2023 Dell Inc, or its subsidiaries.
4+
// Copyright (c) 2024 Ericsson AB.
5+
6+
// Package network implements the network related CLI commands
7+
package network
8+
9+
import (
10+
"fmt"
11+
"log"
12+
13+
"github.com/PraserX/ipconv"
14+
pb "github.com/opiproject/opi-api/network/evpn-gw/v1alpha1/gen/go"
15+
pc "github.com/opiproject/opi-api/network/opinetcommon/v1alpha1/gen/go"
16+
)
17+
18+
// ComposeComponentsInfo composes the components with their details
19+
func ComposeComponentsInfo(comp []*pb.Component) string {
20+
var status string
21+
for i := 0; i < len(comp); i++ {
22+
str := fmt.Sprintf(" %+v\n", comp[i])
23+
status += str
24+
}
25+
return status
26+
}
27+
28+
// ComposeGwIps compose the gw ips string
29+
func ComposeGwIps(comp []*pc.IPPrefix) string {
30+
var status string
31+
for i := 0; i < len(comp); i++ {
32+
str := fmt.Sprintf("%+v/%v ", ipconv.IntToIPv4(comp[i].GetAddr().GetV4Addr()), comp[i].GetLen())
33+
status += str
34+
}
35+
return status
36+
}
37+
38+
// PrintLB prints the logical bridge fields in human readable format
39+
func PrintLB(lb *pb.LogicalBridge) {
40+
Vteip := fmt.Sprintf("%+v/%v", ipconv.IntToIPv4(lb.GetSpec().GetVtepIpPrefix().GetAddr().GetV4Addr()), lb.GetSpec().GetVtepIpPrefix().GetLen())
41+
log.Println("name:", lb.GetName())
42+
log.Println("status:", lb.GetStatus().GetOperStatus().String())
43+
log.Println("vlan:", lb.GetSpec().GetVlanId())
44+
log.Println("vni:", lb.GetSpec().GetVni())
45+
log.Println("VtepIpPrefix:", Vteip)
46+
log.Println("Component Status:")
47+
log.Println(ComposeComponentsInfo(lb.GetStatus().GetComponents()))
48+
}
49+
50+
// PrintBP prints the bridge Port fields in human readable format
51+
func PrintBP(bp *pb.BridgePort) {
52+
log.Println("name:", bp.GetName())
53+
log.Println("status:", bp.GetStatus().GetOperStatus().String())
54+
log.Println("ptype:", bp.GetSpec().GetPtype())
55+
log.Println("mac:", bp.GetSpec().GetMacAddress())
56+
log.Println("bridges:", bp.GetSpec().GetLogicalBridges())
57+
log.Println("Component Status:")
58+
log.Println(ComposeComponentsInfo(bp.GetStatus().GetComponents()))
59+
}
60+
61+
// PrintSvi prints the svi fields in human readable format
62+
func PrintSvi(svi *pb.Svi) {
63+
log.Println("name:", svi.GetName())
64+
log.Println("status:", svi.GetStatus().GetOperStatus().String())
65+
log.Println("Vrf:", svi.GetSpec().GetVrf())
66+
log.Println("LogicalBridge:", svi.GetSpec().GetLogicalBridge())
67+
log.Println("MacAddress:", svi.GetSpec().GetMacAddress())
68+
log.Println("EnableBgp:", svi.GetSpec().GetEnableBgp())
69+
log.Println("GwIPs:", ComposeGwIps(svi.GetSpec().GetGwIpPrefix()))
70+
log.Println("remoteAS:", svi.GetSpec().GetRemoteAs())
71+
log.Println("Component Status:")
72+
log.Println(ComposeComponentsInfo(svi.GetStatus().GetComponents()))
73+
}
74+
75+
// PrintVrf prints the vrf fields in human readable format
76+
func PrintVrf(vrf *pb.Vrf) {
77+
Vteip := fmt.Sprintf("%+v/%v", ipconv.IntToIPv4(vrf.GetSpec().GetVtepIpPrefix().GetAddr().GetV4Addr()), vrf.GetSpec().GetVtepIpPrefix().GetLen())
78+
Loopback := fmt.Sprintf("%+v/%+v", ipconv.IntToIPv4(vrf.GetSpec().GetLoopbackIpPrefix().GetAddr().GetV4Addr()), vrf.GetSpec().GetLoopbackIpPrefix().GetLen())
79+
log.Println("name:", vrf.GetName())
80+
log.Println("operation status:", vrf.GetStatus().GetOperStatus().String())
81+
log.Println("vni:", vrf.GetSpec().GetVni())
82+
log.Println("vtep ip:", Vteip)
83+
log.Println("loopback ip:", Loopback)
84+
log.Println("Component Status:")
85+
log.Println(ComposeComponentsInfo(vrf.GetStatus().GetComponents()))
86+
}

cmd/network/evpn-vrf.go

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// SPDX-License-Identifier: Apache-2.0
22
// Copyright (c) 2022-2023 Intel Corporation, or its subsidiaries.
33
// Copyright (c) 2022-2023 Dell Inc, or its subsidiaries.
4+
// Copyright (c) 2024 Ericsson AB.
45

56
// Package network implements the network related CLI commands
67
package network
@@ -37,8 +38,8 @@ func CreateVRF() *cobra.Command {
3738
if err != nil {
3839
log.Fatalf("failed to create vrf: %v", err)
3940
}
40-
log.Printf("Created VRF with \n name: %s\n operation status: %d\n vni : %d\n vtep ip : %s\n loopback ip: %s\n", vrf.GetName(), vrf.GetStatus().GetOperStatus(),
41-
vrf.GetSpec().GetVni(), vrf.GetSpec().GetVtepIpPrefix(), vrf.GetSpec().GetLoopbackIpPrefix())
41+
log.Println("Created VRF:")
42+
PrintVrf(vrf)
4243
},
4344
}
4445

@@ -80,7 +81,7 @@ func DeleteVRF() *cobra.Command {
8081
if err != nil {
8182
log.Fatalf("DeleteVRF: Error occurred while creating Bridge Port: %q", err)
8283
}
83-
log.Printf("Deleted VRF with VPort ID: %s\n", name)
84+
log.Printf("Deleted VRF: %s\n", name)
8485
},
8586
}
8687

@@ -112,8 +113,9 @@ func GetVRF() *cobra.Command {
112113
if err != nil {
113114
log.Fatalf("DeleteVRF: Error occurred while creating Bridge Port: %q", err)
114115
}
115-
log.Printf("VRF with \n name: %s\n operation status: %d\n vni : %d\n vtep ip : %s\n loopback ip: %s\n", vrf.GetName(), vrf.GetStatus().GetOperStatus(),
116-
vrf.GetSpec().GetVni(), vrf.GetSpec().GetVtepIpPrefix(), vrf.GetSpec().GetLoopbackIpPrefix())
116+
117+
log.Println("Get VRF:")
118+
PrintVrf(vrf)
117119
},
118120
}
119121

@@ -148,9 +150,10 @@ func ListVRFs() *cobra.Command {
148150
log.Fatalf("Failed to get items: %v", err)
149151
}
150152
// Process the server response
153+
log.Println("list VRFs:")
151154
for _, vrf := range resp.Vrfs {
152-
log.Printf("VRF with \n name: %s\n operation status: %d\n vni : %d\n vtep ip : %s\n loopback ip: %s\n", vrf.GetName(), vrf.GetStatus().GetOperStatus(),
153-
vrf.GetSpec().GetVni(), vrf.GetSpec().GetVtepIpPrefix(), vrf.GetSpec().GetLoopbackIpPrefix())
155+
log.Println("VRF with:")
156+
PrintVrf(vrf)
154157
}
155158

156159
// Check if there are more pages to retrieve
@@ -192,8 +195,8 @@ func UpdateVRF() *cobra.Command {
192195
if err != nil {
193196
log.Fatalf("GetBridgePort: Error occurred while creating Bridge Port: %q", err)
194197
}
195-
log.Printf("Updated VRF with \n name: %s\n operation status: %d\n vni : %d\n vtep ip : %s\n loopback ip: %s\n", vrf.GetName(), vrf.GetStatus().GetOperStatus(),
196-
vrf.GetSpec().GetVni(), vrf.GetSpec().GetVtepIpPrefix(), vrf.GetSpec().GetLoopbackIpPrefix())
198+
log.Println("Updated VRF:")
199+
PrintVrf(vrf)
197200
},
198201
}
199202
cmd.Flags().StringVar(&addr, "addr", "localhost:50151", "address of OPI gRPC server")

go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@ module github.com/opiproject/godpu
33
go 1.19
44

55
require (
6+
github.com/PraserX/ipconv v1.2.0
67
github.com/go-chi/chi v1.5.5
78
github.com/go-ping/ping v1.1.0
89
github.com/google/uuid v1.5.0
910
github.com/lithammer/fuzzysearch v1.1.8
1011
github.com/onsi/ginkgo/v2 v2.14.0
1112
github.com/onsi/gomega v1.30.0
12-
github.com/opiproject/opi-api v0.0.0-20240118183513-e44db269fba4
13+
github.com/opiproject/opi-api v0.0.0-20240304222410-5dba226aaa9e
1314
github.com/spf13/cobra v1.8.0
1415
github.com/stretchr/testify v1.8.4
1516
go.einride.tech/aip v0.66.0

0 commit comments

Comments
 (0)