Skip to content

feat: add network interface capability #457

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ run:
# output configuration options
output:
# colored-line-number|line-number|json|tab|checkstyle|code-climate, default is "colored-line-number"
format: colored-line-number
formats: colored-line-number

linters-settings:
funlen:
Expand All @@ -17,13 +17,18 @@ linters-settings:
threshold: 200
gocognit:
min-complexity: 32
gosec:
excludes:
# TODO: Re-enable the checks when fixes to gosec for false positives are done.
# The issue began in gosec 2.21.0 and its inclusion in golangci-lint
- G115 # Potential integer overflow when converting between integer types

linters:
enable:
- bodyclose
- dogsled
- errcheck
- exportloopref
- copyloopvar
- funlen
- gochecknoinits
- gocognit
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright (c) 2022-2023 Dell Inc, or its subsidiaries.
FROM docker.io/library/golang:1.21.5-alpine3.17 as builder
FROM docker.io/library/golang:1.23.4-alpine3.21 as builder

Check warning

Code scanning / Scorecard

Pinned-Dependencies Medium

score is 0: containerImage not pinned by hash
Click Remediation section below to solve this issue

WORKDIR /app

Expand All @@ -15,7 +15,7 @@
COPY . .
RUN go build -v -o /dpu .

FROM alpine:3.19
FROM alpine:3.21

Check warning

Code scanning / Scorecard

Pinned-Dependencies Medium

score is 0: containerImage not pinned by hash
Remediation tip: pin your Docker image by updating alpine:3.21 to alpine:3.21@sha256:56fa17d2a7e7f168a043a2712e63aed1f8543aeafdcee47c58dcffe38ed51099
Click Remediation section below for further remediation help

WORKDIR /

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ go-build:

go-get:
@echo " > Checking if there are any missing dependencies..."
@CGO_ENABLED=0 go get .
@CGO_ENABLED=0 go get ./...

go-test:
@echo " > Running ginkgo test suites..."
Expand Down
4 changes: 2 additions & 2 deletions cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"github.com/spf13/cobra"
)

// NewCommand handles the cli for evpn, ipsec, invetory and storage
// NewCommand handles the cli for network, ipsec, invetory and storage
func NewCommand() *cobra.Command {
//
// This is the root command for the CLI
Expand All @@ -36,7 +36,7 @@ func NewCommand() *cobra.Command {
c.AddCommand(inventory.NewInventoryCommand())
c.AddCommand(ipsec.NewIPSecCommand())
c.AddCommand(storage.NewStorageCommand())
c.AddCommand(network.NewEvpnCommand())
c.AddCommand(network.NewNetworkCommand())

flags := c.PersistentFlags()
flags.String(common.AddrCmdLineArg, "localhost:50151", "address of OPI gRPC server")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
// Copyright (c) 2022-2023 Dell Inc, or its subsidiaries.
// Copyright (c) 2024 Ericsson AB.

// Package network implements the network related CLI commands
package network
// Package evpn implements the evpn network related CLI commands
package evpn

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
// Copyright (c) 2022-2023 Dell Inc, or its subsidiaries.
// Copyright (c) 2024 Ericsson AB.

// Package network implements the network related CLI commands
package network
// Package evpn implements the evpn network related CLI commands
package evpn

import (
"context"
Expand Down
4 changes: 2 additions & 2 deletions cmd/network/evpn-svi.go → cmd/network/evpn/evpn-svi.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
// Copyright (c) 2022-2023 Dell Inc, or its subsidiaries.
// Copyright (c) 2024 Ericsson AB.

// Package network implements the network related CLI commands
package network
// Package evpn implements the evpn related CLI commands
package evpn

import (
"context"
Expand Down
4 changes: 2 additions & 2 deletions cmd/network/evpn-test.go → cmd/network/evpn/evpn-test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Copyright (c) 2022-2023 Intel Corporation, or its subsidiaries.
// Copyright (c) 2022-2023 Dell Inc, or its subsidiaries.

// Package network implements the network related CLI commands
package network
// Package evpn implements the evpn related CLI commands
package evpn

import (
"log"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
// Copyright (c) 2022-2023 Dell Inc, or its subsidiaries.
// Copyright (c) 2024 Ericsson AB.

// Package network implements the network related CLI commands
package network
// Package evpn implements the evpn related CLI commands
package evpn

import (
"fmt"
Expand Down
4 changes: 2 additions & 2 deletions cmd/network/evpn-vrf.go → cmd/network/evpn/evpn-vrf.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
// Copyright (c) 2022-2023 Dell Inc, or its subsidiaries.
// Copyright (c) 2024 Ericsson AB.

// Package network implements the network related CLI commands
package network
// Package evpn implements the evpn network related CLI commands
package evpn

import (
"context"
Expand Down
71 changes: 71 additions & 0 deletions cmd/network/netintf/netintf.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright (c) 2025 Dell Inc, or its subsidiaries.

// Package netintf implements the network interface related CLI commands
package netintf

import (
"context"
"log"

"github.com/opiproject/godpu/cmd/common"
network "github.com/opiproject/godpu/network"
"github.com/spf13/cobra"
"google.golang.org/protobuf/encoding/protojson"
)

// ListNetworkInterfaces lists all Network Interface details from OPI server
func ListNetworkInterfaces() *cobra.Command {
var pageSize int32
var pageToken string

cmd := &cobra.Command{
Use: "list-net-interfaces",
Short: "List the network interfaces",
Run: func(c *cobra.Command, _ []string) {
addr, err := c.Flags().GetString(common.AddrCmdLineArg)
cobra.CheckErr(err)

timeout, err := c.Flags().GetDuration(common.TimeoutCmdLineArg)
cobra.CheckErr(err)

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

ctx, cancel := context.WithTimeout(context.Background(), timeout)

netifClient, err := network.NewNetInterface(addr, tlsFiles)
if err != nil {
log.Fatalf("could not create gRPC client: %v", err)
}
defer cancel()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would it make sense to create ctx and cancel right here and keep them close to this defer call?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will look at this one to determine if it needs to move or change in future addition.


for {
resp, err := netifClient.ListNetInterfaces(ctx, pageSize, pageToken)
if err != nil {
log.Fatalf("Failed to get items: %v", err)
}

// Process the response
log.Println("List Network Interfaces:")
for _, lif := range resp.NetInterfaces {
log.Println("Interface with: ")
common.PrintResponse(protojson.Format(lif))
}

// Are there more pages
if resp.NextPageToken == "" {
// if no then break
break
}
// update to next token
pageToken = resp.NextPageToken
}
},
}

cmd.Flags().Int32VarP(&pageSize, "pagesize", "s", 0, "Specify page size")
cmd.Flags().StringVarP(&pageToken, "pagetoken", "t", "", "Specify the token")

return cmd
}
105 changes: 105 additions & 0 deletions cmd/network/network.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright (c) 2022-2023 Intel Corporation, or its subsidiaries.
// Copyright (c) 2024 Dell Inc, or its subsidiaries.

// Package network implements the network related CLI commands
package network

import (
"log"
"time"

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

// NewNetworkCommand tests the Network functionality command
func NewNetworkCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "network",
Aliases: []string{"g"},
Short: "Tests DPU networking functionality",
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, _ []string) {
err := cmd.Help()
if err != nil {
log.Fatalf("[ERROR] %s", err.Error())
}
},
}

flags := cmd.PersistentFlags()
flags.Duration(common.TimeoutCmdLineArg, 10*time.Second, "timeout for a cmd")

cmd.AddCommand(NewEvpnCommand())
cmd.AddCommand(NewNetIntfCommand())

return cmd
}

// NewNetIntfCommand tests the Network functionality command
func NewNetIntfCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "intf",
Aliases: []string{"g"},
Short: "Tests DPU network interface functionality",
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, _ []string) {
err := cmd.Help()
if err != nil {
log.Fatalf("[ERROR] %s", err.Error())
}
},
}

flags := cmd.PersistentFlags()
flags.Duration(common.TimeoutCmdLineArg, 10*time.Second, "timeout for a cmd")

cmd.AddCommand(netintf.ListNetworkInterfaces())

return cmd
}

// NewEvpnCommand tests the EVPN functionality command
func NewEvpnCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "evpn",
Aliases: []string{"g"},
Short: "Tests DPU evpn functionality",
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, _ []string) {
err := cmd.Help()
if err != nil {
log.Fatalf("[ERROR] %s", err.Error())
}
},
}
// Bridge cli's
cmd.AddCommand(evpn.CreateLogicalBridge())
cmd.AddCommand(evpn.DeleteLogicalBridge())
cmd.AddCommand(evpn.GetLogicalBridge())
cmd.AddCommand(evpn.ListLogicalBridges())
cmd.AddCommand(evpn.UpdateLogicalBridge())
// Port cli's
cmd.AddCommand(evpn.CreateBridgePort())
cmd.AddCommand(evpn.DeleteBridgePort())
cmd.AddCommand(evpn.GetBridgePort())
cmd.AddCommand(evpn.ListBridgePorts())
cmd.AddCommand(evpn.UpdateBridgePort())
// VRF cli's
cmd.AddCommand(evpn.CreateVRF())
cmd.AddCommand(evpn.DeleteVRF())
cmd.AddCommand(evpn.GetVRF())
cmd.AddCommand(evpn.ListVRFs())
cmd.AddCommand(evpn.UpdateVRF())
// SVI cli's
cmd.AddCommand(evpn.CreateSVI())
cmd.AddCommand(evpn.DeleteSVI())
cmd.AddCommand(evpn.GetSVI())
cmd.AddCommand(evpn.ListSVIs())
cmd.AddCommand(evpn.UpdateSVI())

return cmd
}
10 changes: 5 additions & 5 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Copyright (c) 2022-2023 Dell Inc, or its subsidiaries.
# Copyright (C) 2023 Intel Corporation
---
version: "3.7"
# version: "3.7" - version is obsolete and can be removed/commented out
services:
spdk:
image: docker.io/opiproject/spdk:v24.01
Expand Down Expand Up @@ -96,7 +96,7 @@ services:
sleep infinity'

redis:
image: redis:7.2.3-alpine3.18
image: redis:7.2.7-alpine3.21
networks:
- opi
healthcheck:
Expand Down Expand Up @@ -161,7 +161,7 @@ services:
depends_on:
opi-evpn-server:
condition: service_healthy
command: evpn create-vrf --name blue --vni 100 --vtep 10.0.0.100/24 --loopback 10.100.0.1/24 --addr opi-evpn-server:50151
command: network evpn create-vrf --name blue --vni 100 --vtep 10.0.0.100/24 --loopback 10.100.0.1/24 --addr opi-evpn-server:50151

opi-smbios-test:
build:
Expand Down Expand Up @@ -198,7 +198,7 @@ services:
/dpu storage delete backend nvme controller --addr=opi-spdk-server:50051 --name "$$nvmf0" && \

opi-test:
image: docker.io/library/alpine:3.19
image: docker.io/library/alpine:3.21
networks:
- opi
depends_on:
Expand All @@ -209,7 +209,7 @@ services:
opi-storage-test:
condition: service_completed_successfully
command: |
sh -c 'exit 0'
sh -c 'sleep 60 && exit 0'

networks:
opi:
Loading
Loading