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 <[email protected]>
  • Loading branch information
atulpatel261194 authored and artek-koltun committed May 21, 2024
1 parent 745a92f commit 9cf56d1
Show file tree
Hide file tree
Showing 29 changed files with 507 additions and 201 deletions.
46 changes: 46 additions & 0 deletions cmd/cmd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// 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/common"
"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"
)

// 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)
},
}
c.AddCommand(inventory.NewInventoryCommand())
c.AddCommand(ipsec.NewIPSecCommand())
c.AddCommand(storage.NewStorageCommand())
c.AddCommand(network.NewEvpnCommand())

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

return c
}
3 changes: 3 additions & 0 deletions cmd/storage/common/common.go → cmd/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ const AddrCmdLineArg = "addr"
// TimeoutCmdLineArg cmdline arg name for timeout
const TimeoutCmdLineArg = "timeout"

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

// PrintResponse prints only response string into stdout without any
// additional information
func PrintResponse(response string) {
Expand Down
15 changes: 8 additions & 7 deletions cmd/inventory/inventory-get.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,25 @@ import (
"log"
"time"

"github.com/opiproject/godpu/cmd/common"
"github.com/opiproject/godpu/inventory"
"github.com/spf13/cobra"
)

// 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(common.TLSFiles)
cobra.CheckErr(err)

addr, err := c.Flags().GetString(common.AddrCmdLineArg)
cobra.CheckErr(err)
invClient, err := inventory.New(addr, tlsFiles)
if err != nil {
log.Fatalf("could create gRPC client: %v", err)
}
Expand All @@ -39,8 +42,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
11 changes: 5 additions & 6 deletions cmd/ipsec/ipsec-stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,26 @@ import (
"fmt"
"log"

"github.com/opiproject/godpu/cmd/common"
"github.com/opiproject/godpu/ipsec"
"github.com/spf13/cobra"
)

// 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(common.AddrCmdLineArg)
cobra.CheckErr(err)

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
8 changes: 5 additions & 3 deletions cmd/ipsec/ipsec-test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,30 @@ package ipsec
import (
"fmt"

"github.com/opiproject/godpu/cmd/common"
"github.com/opiproject/godpu/ipsec"
"github.com/spf13/cobra"
)

// 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(common.AddrCmdLineArg)
cobra.CheckErr(err)

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
}
67 changes: 47 additions & 20 deletions cmd/network/evpn-bridge-port.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import (
"log"
"time"

"github.com/opiproject/godpu/cmd/common"
"github.com/opiproject/godpu/network"
"github.com/spf13/cobra"
)

// 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 +27,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) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
evpnClient, err := network.NewBridgePort(addr)

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

addr, err := c.Flags().GetString(common.AddrCmdLineArg)
cobra.CheckErr(err)
evpnClient, err := network.NewBridgePort(addr, tlsFiles)
if err != nil {
log.Fatalf("could not create gRPC client: %v", err)
}
Expand All @@ -49,7 +55,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 +75,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) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
evpnClient, err := network.NewBridgePort(addr)

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

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

evpnClient, err := network.NewBridgePort(addr, tlsFiles)
if err != nil {
log.Fatalf("could not create gRPC client: %v", err)
}
Expand All @@ -97,23 +108,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) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
evpnClient, err := network.NewBridgePort(addr)

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

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

evpnClient, err := network.NewBridgePort(addr, tlsFiles)
if err != nil {
log.Fatalf("could not create gRPC client: %v", err)
}
Expand All @@ -130,7 +146,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 +155,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) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
evpnClient, err := network.NewBridgePort(addr)

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

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

evpnClient, err := network.NewBridgePort(addr, tlsFiles)
if err != nil {
log.Fatalf("could not create gRPC client: %v", err)
}
Expand Down Expand Up @@ -178,13 +199,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")

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 +213,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) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
evpnClient, err := network.NewBridgePort(addr)

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

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

evpnClient, err := network.NewBridgePort(addr, tlsFiles)
if err != nil {
log.Fatalf("could not create gRPC client: %v", err)
}
Expand All @@ -214,6 +241,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")

return cmd
}
Loading

0 comments on commit 9cf56d1

Please sign in to comment.