Skip to content

Commit

Permalink
feat(evpn): enable tls on godpu
Browse files Browse the repository at this point in the history
Signed-off-by: atulpatel261194 <Atul.Patel@intel.com>
  • Loading branch information
atulpatel261194 committed May 17, 2024
1 parent e4af793 commit de1bf20
Show file tree
Hide file tree
Showing 31 changed files with 516 additions and 194 deletions.
51 changes: 51 additions & 0 deletions cmd/cmd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright (c) 2022-2023 Dell Inc, or its subsidiaries.

// Package cmd implements the ipsec related CLI commands
package cmd

import (
"log"
"os"

"github.com/opiproject/godpu/cmd/inventory"
"github.com/opiproject/godpu/cmd/ipsec"
"github.com/opiproject/godpu/cmd/network"
"github.com/opiproject/godpu/cmd/storage"
"github.com/spf13/cobra"
)

// AddrCmdLineArg cmdline arg name for address
const AddrCmdLineArg = "addr"

// TLSFiles cmdline arg name for tls files
const TLSFiles = "tlsfiles"

// NewCommand handles the cli for evpn, ipsec, invetory and storage
func NewCommand() *cobra.Command {
//
// This is the root command for the CLI
//

c := &cobra.Command{
Use: "godpu",
Short: "godpu - DPUs and IPUs cli commands",
Run: func(cmd *cobra.Command, _ []string) {
err := cmd.Help()
if err != nil {
log.Fatalf("[ERROR] %s", err.Error())
}
os.Exit(1)

Check warning on line 38 in cmd/cmd.go

View check run for this annotation

Codecov / codecov/patch

cmd/cmd.go#L25-L38

Added lines #L25 - L38 were not covered by tests
},
}
c.AddCommand(inventory.NewInventoryCommand())
c.AddCommand(ipsec.NewIPSecCommand())
c.AddCommand(storage.NewStorageCommand())
c.AddCommand(network.NewEvpnCommand())

flags := c.PersistentFlags()
flags.String(AddrCmdLineArg, "localhost:50151", "address of OPI gRPC server")
flags.String(TLSFiles, "", "TLS files in client_cert:client_key:ca_cert format.")

return c

Check warning on line 50 in cmd/cmd.go

View check run for this annotation

Codecov / codecov/patch

cmd/cmd.go#L41-L50

Added lines #L41 - L50 were not covered by tests
}
20 changes: 13 additions & 7 deletions cmd/inventory/inventory-get.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,26 @@ import (
"github.com/spf13/cobra"
)

// AddrCmdLineArg cmdline arg name for address
const AddrCmdLineArg = "addr"

// TLSFiles cmdline arg name for tls files
const TLSFiles = "tlsfiles"

// NewGetCommand returns the inventory get command
func NewGetCommand() *cobra.Command {
var (
addr string
)
cmd := &cobra.Command{
Use: "get",
Aliases: []string{"g"},
Short: "Gets DPU inventory information",
Args: cobra.NoArgs,
Run: func(_ *cobra.Command, _ []string) {
invClient, err := inventory.New(addr)
Run: func(c *cobra.Command, _ []string) {
tlsFiles, err := c.Flags().GetString(TLSFiles)
cobra.CheckErr(err)

addr, err := c.Flags().GetString(AddrCmdLineArg)
cobra.CheckErr(err)
invClient, err := inventory.New(addr, tlsFiles)

Check warning on line 35 in cmd/inventory/inventory-get.go

View check run for this annotation

Codecov / codecov/patch

cmd/inventory/inventory-get.go#L29-L35

Added lines #L29 - L35 were not covered by tests
if err != nil {
log.Fatalf("could create gRPC client: %v", err)
}
Expand All @@ -39,8 +47,6 @@ func NewGetCommand() *cobra.Command {
log.Printf("%s", data)
},
}
flags := cmd.Flags()
flags.StringVar(&addr, "addr", "localhost:50151", "address of OPI gRPC server")
return cmd
}

Expand Down
16 changes: 10 additions & 6 deletions cmd/ipsec/ipsec-stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,27 @@ import (
"github.com/spf13/cobra"
)

// AddrCmdLineArg cmdline arg name for address
const AddrCmdLineArg = "addr"

// TLSFiles cmdline arg name for tls files
const TLSFiles = "tlsfiles"

// NewStatsCommand returns the ipsec stats command
func NewStatsCommand() *cobra.Command {
var (
addr string
)
cmd := &cobra.Command{
Use: "stats",
Aliases: []string{"c"},
Short: "Queries ipsec statistics",
Args: cobra.NoArgs,
Run: func(_ *cobra.Command, _ []string) {
Run: func(c *cobra.Command, _ []string) {
addr, err := c.Flags().GetString(AddrCmdLineArg)
cobra.CheckErr(err)

Check warning on line 31 in cmd/ipsec/ipsec-stats.go

View check run for this annotation

Codecov / codecov/patch

cmd/ipsec/ipsec-stats.go#L28-L31

Added lines #L28 - L31 were not covered by tests
res := ipsec.Stats(addr)
fmt.Println(res)
},
}
flags := cmd.Flags()
flags.StringVar(&addr, "addr", "localhost:50151", "address or OPI gRPC server")
return cmd
}

Expand Down
7 changes: 4 additions & 3 deletions cmd/ipsec/ipsec-test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,22 @@ import (
// NewTestCommand returns the ipsec tests command
func NewTestCommand() *cobra.Command {
var (
addr string
pingaddr string
)
cmd := &cobra.Command{
Use: "test",
Aliases: []string{"c"},
Short: "Test ipsec functionality",
Args: cobra.NoArgs,
Run: func(_ *cobra.Command, _ []string) {
Run: func(c *cobra.Command, _ []string) {
addr, err := c.Flags().GetString(AddrCmdLineArg)
cobra.CheckErr(err)

Check warning on line 27 in cmd/ipsec/ipsec-test.go

View check run for this annotation

Codecov / codecov/patch

cmd/ipsec/ipsec-test.go#L24-L27

Added lines #L24 - L27 were not covered by tests
res := ipsec.TestIpsec(addr, pingaddr)
fmt.Println(res)
},
}
flags := cmd.Flags()
flags.StringVar(&addr, "addr", "localhost:50151", "address or OPI gRPC server")
flags.StringVar(&pingaddr, "pingaddr", "localhost", "address of other tunnel end to Ping")
return cmd
}
66 changes: 46 additions & 20 deletions cmd/network/evpn-bridge-port.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (

// CreateBridgePort creates an Bridge Port an OPI server
func CreateBridgePort() *cobra.Command {
var addr string
var name string
var mac string
var bridgePortType string
Expand All @@ -27,9 +26,15 @@ func CreateBridgePort() *cobra.Command {
Use: "create-bp",
Short: "Create a bridge port",
Long: "Create a BridgePort with the specified name, MAC address, type, and VLAN IDs",
Run: func(_ *cobra.Command, _ []string) {
Run: func(c *cobra.Command, _ []string) {

Check warning on line 29 in cmd/network/evpn-bridge-port.go

View check run for this annotation

Codecov / codecov/patch

cmd/network/evpn-bridge-port.go#L29

Added line #L29 was not covered by tests
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
evpnClient, err := network.NewBridgePort(addr)

tlsFiles, err := c.Flags().GetString(TLSFiles)
cobra.CheckErr(err)

addr, err := c.Flags().GetString(AddrCmdLineArg)
cobra.CheckErr(err)
evpnClient, err := network.NewBridgePort(addr, tlsFiles)

Check warning on line 37 in cmd/network/evpn-bridge-port.go

View check run for this annotation

Codecov / codecov/patch

cmd/network/evpn-bridge-port.go#L31-L37

Added lines #L31 - L37 were not covered by tests
if err != nil {
log.Fatalf("could not create gRPC client: %v", err)
}
Expand All @@ -49,7 +54,6 @@ func CreateBridgePort() *cobra.Command {
cmd.Flags().StringVar(&mac, "mac", "", "Specify the MAC address")
cmd.Flags().StringVarP(&bridgePortType, "type", "t", "", "Specify the type (access or trunk)")
cmd.Flags().StringSliceVar(&logicalBridges, "logicalBridges", []string{}, "Specify VLAN IDs (multiple values supported)")
cmd.Flags().StringVar(&addr, "addr", "localhost:50151", "address of OPI gRPC server")

if err := cmd.MarkFlagRequired("mac"); err != nil {
log.Fatalf("Error marking flag as required: %v", err)
Expand All @@ -70,17 +74,23 @@ func CreateBridgePort() *cobra.Command {

// DeleteBridgePort delete an Bridge Port an OPI server
func DeleteBridgePort() *cobra.Command {
var addr string
var name string
var allowMissing bool

cmd := &cobra.Command{
Use: "delete-bp",
Short: "Delete a bridge port",
Long: "Delete a BridgePort with the specified name",
Run: func(_ *cobra.Command, _ []string) {
Run: func(c *cobra.Command, _ []string) {

Check warning on line 84 in cmd/network/evpn-bridge-port.go

View check run for this annotation

Codecov / codecov/patch

cmd/network/evpn-bridge-port.go#L84

Added line #L84 was not covered by tests
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
evpnClient, err := network.NewBridgePort(addr)

tlsFiles, err := c.Flags().GetString(TLSFiles)
cobra.CheckErr(err)

addr, err := c.Flags().GetString(AddrCmdLineArg)
cobra.CheckErr(err)

evpnClient, err := network.NewBridgePort(addr, tlsFiles)

Check warning on line 93 in cmd/network/evpn-bridge-port.go

View check run for this annotation

Codecov / codecov/patch

cmd/network/evpn-bridge-port.go#L86-L93

Added lines #L86 - L93 were not covered by tests
if err != nil {
log.Fatalf("could not create gRPC client: %v", err)
}
Expand All @@ -97,23 +107,28 @@ func DeleteBridgePort() *cobra.Command {

cmd.Flags().StringVarP(&name, "name", "n", "", "Specify the name of the BridgePort")
cmd.Flags().BoolVarP(&allowMissing, "allowMissing", "a", false, "Specify if missing allowed")
cmd.Flags().StringVar(&addr, "addr", "localhost:50151", "address of OPI gRPC server")

return cmd
}

// GetBridgePort Get Bridge Port details
func GetBridgePort() *cobra.Command {
var addr string
var name string

cmd := &cobra.Command{
Use: "get-bp",
Short: "Show details of a bridge port",
Long: "Show details of a BridgePort with the specified name",
Run: func(_ *cobra.Command, _ []string) {
Run: func(c *cobra.Command, _ []string) {

Check warning on line 122 in cmd/network/evpn-bridge-port.go

View check run for this annotation

Codecov / codecov/patch

cmd/network/evpn-bridge-port.go#L122

Added line #L122 was not covered by tests
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
evpnClient, err := network.NewBridgePort(addr)

tlsFiles, err := c.Flags().GetString(TLSFiles)
cobra.CheckErr(err)

addr, err := c.Flags().GetString(AddrCmdLineArg)
cobra.CheckErr(err)

evpnClient, err := network.NewBridgePort(addr, tlsFiles)

Check warning on line 131 in cmd/network/evpn-bridge-port.go

View check run for this annotation

Codecov / codecov/patch

cmd/network/evpn-bridge-port.go#L124-L131

Added lines #L124 - L131 were not covered by tests
if err != nil {
log.Fatalf("could not create gRPC client: %v", err)
}
Expand All @@ -130,7 +145,6 @@ func GetBridgePort() *cobra.Command {
}

cmd.Flags().StringVarP(&name, "name", "n", "", "Specify the name of the BridgePort")
cmd.Flags().StringVar(&addr, "addr", "localhost:50151", "address of OPI gRPC server")

if err := cmd.MarkFlagRequired("name"); err != nil {
log.Fatalf("Error marking flag as required: %v", err)
Expand All @@ -140,16 +154,22 @@ func GetBridgePort() *cobra.Command {

// ListBridgePorts list all the Bridge Port an OPI server
func ListBridgePorts() *cobra.Command {
var addr string
var pageSize int32
var pageToken string

cmd := &cobra.Command{
Use: "list-bps",
Short: "Show details of all bridge ports",
Run: func(_ *cobra.Command, _ []string) {
Run: func(c *cobra.Command, _ []string) {

Check warning on line 163 in cmd/network/evpn-bridge-port.go

View check run for this annotation

Codecov / codecov/patch

cmd/network/evpn-bridge-port.go#L163

Added line #L163 was not covered by tests
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
evpnClient, err := network.NewBridgePort(addr)

tlsFiles, err := c.Flags().GetString(TLSFiles)
cobra.CheckErr(err)

addr, err := c.Flags().GetString(AddrCmdLineArg)
cobra.CheckErr(err)

evpnClient, err := network.NewBridgePort(addr, tlsFiles)

Check warning on line 172 in cmd/network/evpn-bridge-port.go

View check run for this annotation

Codecov / codecov/patch

cmd/network/evpn-bridge-port.go#L165-L172

Added lines #L165 - L172 were not covered by tests
if err != nil {
log.Fatalf("could not create gRPC client: %v", err)
}
Expand Down Expand Up @@ -178,13 +198,12 @@ func ListBridgePorts() *cobra.Command {
}
cmd.Flags().Int32VarP(&pageSize, "pagesize", "s", 0, "Specify page size")
cmd.Flags().StringVarP(&pageToken, "pagetoken", "t", "", "Specify the token")
cmd.Flags().StringVar(&addr, "addr", "localhost:50151", "address of OPI gRPC server")

Check warning on line 201 in cmd/network/evpn-bridge-port.go

View check run for this annotation

Codecov / codecov/patch

cmd/network/evpn-bridge-port.go#L201

Added line #L201 was not covered by tests
return cmd
}

// UpdateBridgePort update the Bridge Port on OPI server
func UpdateBridgePort() *cobra.Command {
var addr string
var name string
var updateMask []string
var allowMissing bool
Expand All @@ -193,9 +212,16 @@ func UpdateBridgePort() *cobra.Command {
Use: "update-bp",
Short: "Update the bridge port",
Long: "updates the Bridge Port with updated mask",
Run: func(_ *cobra.Command, _ []string) {
Run: func(c *cobra.Command, _ []string) {

Check warning on line 215 in cmd/network/evpn-bridge-port.go

View check run for this annotation

Codecov / codecov/patch

cmd/network/evpn-bridge-port.go#L215

Added line #L215 was not covered by tests
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
evpnClient, err := network.NewBridgePort(addr)

tlsFiles, err := c.Flags().GetString(TLSFiles)
cobra.CheckErr(err)

addr, err := c.Flags().GetString(AddrCmdLineArg)
cobra.CheckErr(err)

evpnClient, err := network.NewBridgePort(addr, tlsFiles)

Check warning on line 224 in cmd/network/evpn-bridge-port.go

View check run for this annotation

Codecov / codecov/patch

cmd/network/evpn-bridge-port.go#L217-L224

Added lines #L217 - L224 were not covered by tests
if err != nil {
log.Fatalf("could not create gRPC client: %v", err)
}
Expand All @@ -214,6 +240,6 @@ func UpdateBridgePort() *cobra.Command {
cmd.Flags().StringVar(&name, "name", "", "name of the Bridge Port")
cmd.Flags().StringSliceVar(&updateMask, "update-mask", nil, "update mask")
cmd.Flags().BoolVarP(&allowMissing, "allowMissing", "a", false, "allow the missing")
cmd.Flags().StringVar(&addr, "addr", "localhost:50151", "address of OPI gRPC server")

Check warning on line 243 in cmd/network/evpn-bridge-port.go

View check run for this annotation

Codecov / codecov/patch

cmd/network/evpn-bridge-port.go#L243

Added line #L243 was not covered by tests
return cmd
}
Loading

0 comments on commit de1bf20

Please sign in to comment.