Skip to content
This repository was archived by the owner on Apr 8, 2025. It is now read-only.

Commit 3e6f6d2

Browse files
committed
api updates
updates flagged by golangci-lint Signed-off-by: John O'Loughlin <[email protected]>
1 parent 4e5d240 commit 3e6f6d2

File tree

15 files changed

+114
-142
lines changed

15 files changed

+114
-142
lines changed

Diff for: cniovs/cniovs.go

+5-7
Original file line numberDiff line numberDiff line change
@@ -48,23 +48,17 @@ import (
4848
"github.com/intel/userspace-cni-network-plugin/pkg/types"
4949
)
5050

51-
//
5251
// Constants
53-
//
5452
const (
5553
defaultBridge = "br0"
5654
DefaultHostVhostuserBaseDir = "/var/lib/vhost_sockets/"
5755
)
5856

59-
//
6057
// Types
61-
//
6258
type CniOvs struct {
6359
}
6460

65-
//
6661
// API Functions
67-
//
6862
func (cniOvs CniOvs) AddOnHost(conf *types.NetConf,
6963
args *skel.CmdArgs,
7064
kubeClient kubernetes.Interface,
@@ -196,7 +190,11 @@ func (cniOvs CniOvs) DelFromHost(conf *types.NetConf, args *skel.CmdArgs, shared
196190
func (cniOvs CniOvs) DelFromContainer(conf *types.NetConf, args *skel.CmdArgs, sharedDir string, pod *v1.Pod) error {
197191
logging.Infof("OVS DelFromContainer: ENTER - Container %s Iface %s", args.ContainerID[:12], args.IfName)
198192

199-
configdata.FileCleanup(sharedDir, "")
193+
var err = configdata.FileCleanup(sharedDir, "")
194+
195+
if err != nil {
196+
logging.Debugf("DelFromContainer(ovs): %v", err)
197+
}
200198

201199
return nil
202200
}

Diff for: cnivpp/api/bridge/bridge.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func DeleteBridge(ch api.Channel, bridgeDomain uint32) error {
7777

7878
// Determine if bridge domain exists
7979
exists, count := findBridge(ch, bridgeDomain)
80-
if exists == false || count != 0 {
80+
if !exists || count != 0 {
8181
return nil
8282
}
8383

Diff for: cnivpp/api/memif/memif.go

+5-6
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ import (
3838

3939
const debugMemif = false
4040

41-
type MemifRole uint8
41+
type MemifRole uint32
4242

4343
const (
4444
RoleMaster MemifRole = 0
4545
RoleSlave MemifRole = 1
4646
)
4747

48-
type MemifMode uint8
48+
type MemifMode uint32
4949

5050
const (
5151
ModeEthernet MemifMode = 0
@@ -56,7 +56,6 @@ const (
5656
// Dump Strings
5757
var modeStr = [...]string{"eth", "ip ", "pnt"}
5858
var roleStr = [...]string{"master", "slave "}
59-
var stateStr = [...]string{"dn", "up"}
6059

6160
//
6261
// API Functions
@@ -108,7 +107,7 @@ func DeleteMemifInterface(ch api.Channel, swIfIndex interface_types.InterfaceInd
108107
// Determine if memif interface exists
109108
socketId, exist := findMemifInterface(ch, swIfIndex)
110109
if debugMemif {
111-
if exist == false {
110+
if !exist {
112111
logging.Verbosef("Error deleting memif interface: memif interface (swIfIndex=%d) Does NOT Exist", swIfIndex)
113112
} else {
114113
logging.Verbosef("Attempting to delete memif interface %d with SocketId %d", swIfIndex, socketId)
@@ -428,10 +427,10 @@ func findMemifSocket(ch api.Channel, socketFilename string) (found bool, socketI
428427
// If input SocketFilename has not been created, then loop
429428
// through the list of existing SocketIds and find an unused Id.
430429
//
431-
if found == false {
430+
if !found {
432431
socketId = 1
433432

434-
for done == false {
433+
for !done {
435434

436435
done = true
437436
for i := 0; i < count; i++ {

Diff for: cnivpp/api/vhostuser/vhostuser.go

+19-19
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ package vppvhostuser
2222
import (
2323
"fmt"
2424

25-
"go.fd.io/govpp/api"
25+
"github.com/intel/userspace-cni-network-plugin/cnivpp/bin_api/interface_types"
2626
"github.com/intel/userspace-cni-network-plugin/cnivpp/bin_api/vhost_user"
27+
"go.fd.io/govpp/api"
2728
)
2829

2930
//
@@ -32,34 +33,32 @@ import (
3233

3334
const debugVhost = false
3435

35-
type VhostUserMode uint8
36+
type VhostUserMode bool
3637

3738
const (
38-
ModeClient VhostUserMode = 0
39-
ModeServer VhostUserMode = 1
39+
ModeClient VhostUserMode = false
40+
ModeServer VhostUserMode = true
4041
)
4142

42-
// Dump Strings
43-
var modeStr = [...]string{"client", "server"}
44-
4543
//
4644
// API Functions
4745
//
4846

4947
// Attempt to create a Vhost-User Interface.
5048
// Input:
51-
// ch api.Channel
52-
// mode VhostUserMode - ModeClient or ModeServer
53-
// socketFile string - Directory and Filename of socket file
54-
func CreateVhostUserInterface(ch api.Channel, mode VhostUserMode, socketFile string) (swIfIndex uint32, err error) {
49+
//
50+
// ch api.Channel
51+
// mode VhostUserMode - ModeClient or ModeServer
52+
// socketFile string - Directory and Filename of socket file
53+
func CreateVhostUserInterface(ch api.Channel, mode bool, socketFile string) (swIfIndex interface_types.InterfaceIndex, err error) {
5554

5655
// Populate the Add Structure
5756
req := &vhost_user.CreateVhostUserIf{
58-
IsServer: uint8(mode),
59-
SockFilename: []byte(socketFile),
60-
Renumber: 0,
57+
IsServer: mode,
58+
SockFilename: socketFile,
59+
Renumber: false,
6160
CustomDevInstance: 0,
62-
UseCustomMac: 0,
61+
UseCustomMac: false,
6362
//MacAddress: "",
6463
//Tag: "",
6564
}
@@ -81,7 +80,7 @@ func CreateVhostUserInterface(ch api.Channel, mode VhostUserMode, socketFile str
8180
}
8281

8382
// Attempt to delete a Vhost-User interface.
84-
func DeleteVhostUserInterface(ch api.Channel, swIfIndex uint32) (err error) {
83+
func DeleteVhostUserInterface(ch api.Channel, swIfIndex interface_types.InterfaceIndex) (err error) {
8584

8685
// Populate the Delete Structure
8786
req := &vhost_user.DeleteVhostUserIf{
@@ -122,13 +121,14 @@ func DumpVhostUser(ch api.Channel) {
122121
}
123122
//fmt.Printf("%+v\n", reply)
124123

125-
fmt.Printf(" SwIfId=%d Mode=%s IfName=%s NumReg=%d SockErrno=%d Feature=0x16%x HdrSz=%d SockFile=%s\n",
124+
fmt.Printf(" SwIfId=%d Mode=%t IfName=%s NumReg=%d SockErrno=%d FeaturesFirst32=%d FeaturesLast32=%d HdrSz=%d SockFile=%s\n",
126125
reply.SwIfIndex,
127-
modeStr[reply.IsServer],
126+
reply.IsServer,
128127
string(reply.InterfaceName),
129128
reply.NumRegions,
130129
reply.SockErrno,
131-
reply.Features,
130+
reply.FeaturesFirst32,
131+
reply.FeaturesLast32,
132132
reply.VirtioNetHdrSz,
133133
string(reply.SockFilename))
134134

Diff for: cnivpp/cnivpp.go

+5-7
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ import (
3737
"github.com/containernetworking/cni/pkg/skel"
3838
current "github.com/containernetworking/cni/pkg/types/100"
3939

40-
"github.com/intel/userspace-cni-network-plugin/cnivpp/api/bridge"
41-
"github.com/intel/userspace-cni-network-plugin/cnivpp/api/infra"
42-
"github.com/intel/userspace-cni-network-plugin/cnivpp/api/interface"
43-
"github.com/intel/userspace-cni-network-plugin/cnivpp/api/memif"
44-
"github.com/intel/userspace-cni-network-plugin/cnivpp/bin_api/memif"
40+
vppbridge "github.com/intel/userspace-cni-network-plugin/cnivpp/api/bridge"
41+
vppinfra "github.com/intel/userspace-cni-network-plugin/cnivpp/api/infra"
42+
vppinterface "github.com/intel/userspace-cni-network-plugin/cnivpp/api/interface"
43+
vppmemif "github.com/intel/userspace-cni-network-plugin/cnivpp/api/memif"
4544
"github.com/intel/userspace-cni-network-plugin/cnivpp/bin_api/interface_types"
45+
"github.com/intel/userspace-cni-network-plugin/cnivpp/bin_api/memif"
4646
"github.com/intel/userspace-cni-network-plugin/logging"
4747
"github.com/intel/userspace-cni-network-plugin/pkg/configdata"
4848
"github.com/intel/userspace-cni-network-plugin/pkg/types"
@@ -231,8 +231,6 @@ func (cniVpp CniVpp) DelFromHost(conf *types.NetConf, args *skel.CmdArgs, shared
231231
} else {
232232
return fmt.Errorf("ERROR: Unknown HostConf.Type:" + conf.HostConf.IfType)
233233
}
234-
235-
return err
236234
}
237235

238236
func (cniVpp CniVpp) DelFromContainer(conf *types.NetConf, args *skel.CmdArgs, sharedDir string, pod *v1.Pod) error {

Diff for: cnivpp/localdb.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,7 @@ import (
4040
"github.com/intel/userspace-cni-network-plugin/pkg/types"
4141
)
4242

43-
//
4443
// Constants
45-
//
4644
const debugVppDb = false
4745

4846
//
@@ -53,15 +51,16 @@ const debugVppDb = false
5351
// interfaces) that need to be preserved for later use.
5452
type VppSavedData struct {
5553
interfaceSwIfIndex interface_types.InterfaceIndex `json:"swIfIndex"` // Software Index, used to access the created interface, needed to delete interface.
56-
MemifSocketId uint32 `json:"memifSocketId"` // Memif SocketId, used to access the created memif Socket File, used for debug only.
54+
MemifSocketId uint32 `json:"memifSocketId"` // Memif SocketId, used to access the created memif Socket File, used for debug only.
5755
}
5856

5957
//
6058
// API Functions
6159
//
6260

6361
// saveVppConfig() - Some data needs to be saved, like the swIfIndex, for cmdDel().
64-
// This function squirrels the data away to be retrieved later.
62+
//
63+
// This function squirrels the data away to be retrieved later.
6564
func SaveVppConfig(conf *types.NetConf, args *skel.CmdArgs, data *VppSavedData) error {
6665

6766
// Current implementation is to write data to a file with the name:

Diff for: cnivpp/test/ipAddDel/ipAddDel.go

+11-13
Original file line numberDiff line numberDiff line change
@@ -26,26 +26,24 @@ import (
2626
"runtime"
2727
"time"
2828

29-
_ "go.fd.io/govpp/core"
3029
current "github.com/containernetworking/cni/pkg/types/100"
3130
_ "github.com/sirupsen/logrus"
31+
_ "go.fd.io/govpp/core"
3232

33-
"github.com/intel/userspace-cni-network-plugin/cnivpp/api/infra"
34-
"github.com/intel/userspace-cni-network-plugin/cnivpp/api/interface"
35-
"github.com/intel/userspace-cni-network-plugin/cnivpp/api/memif"
33+
vppinfra "github.com/intel/userspace-cni-network-plugin/cnivpp/api/infra"
34+
vppinterface "github.com/intel/userspace-cni-network-plugin/cnivpp/api/interface"
35+
vppmemif "github.com/intel/userspace-cni-network-plugin/cnivpp/api/memif"
36+
"github.com/intel/userspace-cni-network-plugin/cnivpp/bin_api/interface_types"
37+
"github.com/intel/userspace-cni-network-plugin/cnivpp/bin_api/memif"
3638
)
3739

38-
//
3940
// Constants
40-
//
4141
const (
4242
dbgIp = true
4343
dbgMemif = true
4444
)
4545

46-
//
4746
// Functions
48-
//
4947
func init() {
5048
// this ensures that main runs only on main thread (thread group leader).
5149
// since namespace ops (unshare, setns) are done for a single thread, we
@@ -56,15 +54,15 @@ func init() {
5654
func main() {
5755
var vppCh vppinfra.ConnectionData
5856
var err error
59-
var swIfIndex uint32
57+
var swIfIndex interface_types.InterfaceIndex
6058

6159
// Dummy Input Data
6260
var ipString string = "192.168.172.100/24"
6361
var ipResult *current.Result
6462
var memifSocketId uint32
6563
var memifSocketFile string = "/var/run/vpp/123456/memif-3.sock"
66-
var memifRole vppmemif.MemifRole = vppmemif.RoleMaster
67-
var memifMode vppmemif.MemifMode = vppmemif.ModeEthernet
64+
var memifRole memif.MemifRole = 0
65+
var memifMode memif.MemifMode = 0
6866

6967
// Set log level
7068
// Logrus has six logging levels: DebugLevel, InfoLevel, WarningLevel, ErrorLevel, FatalLevel and PanicLevel.
@@ -112,7 +110,7 @@ func main() {
112110
}
113111

114112
// Add IP to MemIf to Bridge.
115-
err = vppinterface.AddDelIpAddress(vppCh.Ch, swIfIndex, 1, ipResult)
113+
err = vppinterface.AddDelIpAddress(vppCh.Ch, swIfIndex, true, ipResult)
116114
if err != nil {
117115
fmt.Println("Error:", err)
118116
os.Exit(1)
@@ -125,7 +123,7 @@ func main() {
125123
fmt.Println("User Space VPP client wakeup.")
126124

127125
// Remove IP from MemIf.
128-
err = vppinterface.AddDelIpAddress(vppCh.Ch, swIfIndex, 0, ipResult)
126+
err = vppinterface.AddDelIpAddress(vppCh.Ch, swIfIndex, false, ipResult)
129127

130128
if err != nil {
131129
fmt.Println("Error:", err)

Diff for: cnivpp/test/memifAddDel/memifAddDel.go

+9-11
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,23 @@ import (
2626
"runtime"
2727
"time"
2828

29-
_ "go.fd.io/govpp/core"
3029
_ "github.com/sirupsen/logrus"
30+
_ "go.fd.io/govpp/core"
3131

32-
"github.com/intel/userspace-cni-network-plugin/cnivpp/api/bridge"
33-
"github.com/intel/userspace-cni-network-plugin/cnivpp/api/infra"
34-
"github.com/intel/userspace-cni-network-plugin/cnivpp/api/memif"
32+
vppbridge "github.com/intel/userspace-cni-network-plugin/cnivpp/api/bridge"
33+
vppinfra "github.com/intel/userspace-cni-network-plugin/cnivpp/api/infra"
34+
vppmemif "github.com/intel/userspace-cni-network-plugin/cnivpp/api/memif"
35+
"github.com/intel/userspace-cni-network-plugin/cnivpp/bin_api/interface_types"
36+
"github.com/intel/userspace-cni-network-plugin/cnivpp/bin_api/memif"
3537
)
3638

37-
//
3839
// Constants
39-
//
4040
const (
4141
dbgBridge = true
4242
dbgMemif = true
4343
)
4444

45-
//
4645
// Functions
47-
//
4846
func init() {
4947
// this ensures that main runs only on main thread (thread group leader).
5048
// since namespace ops (unshare, setns) are done for a single thread, we
@@ -55,14 +53,14 @@ func init() {
5553
func main() {
5654
var vppCh vppinfra.ConnectionData
5755
var err error
58-
var swIfIndex uint32
56+
var swIfIndex interface_types.InterfaceIndex
5957

6058
// Dummy Input Data
6159
var bridgeDomain uint32 = 4
6260
var memifSocketId uint32
6361
var memifSocketFile string = "/var/run/vpp/123456/memif-3.sock"
64-
var memifRole vppmemif.MemifRole = vppmemif.RoleMaster
65-
var memifMode vppmemif.MemifMode = vppmemif.ModeEthernet
62+
var memifRole memif.MemifRole = 0
63+
var memifMode memif.MemifMode = 0
6664

6765
// Set log level
6866
// Logrus has six logging levels: DebugLevel, InfoLevel, WarningLevel, ErrorLevel, FatalLevel and PanicLevel.

Diff for: cnivpp/test/vhostUserAddDel/vhostUserAddDel.go

+4-8
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,22 @@ import (
2626
"runtime"
2727
"time"
2828

29-
_ "go.fd.io/govpp/core"
3029
_ "github.com/sirupsen/logrus"
30+
_ "go.fd.io/govpp/core"
3131

3232
vppbridge "github.com/intel/userspace-cni-network-plugin/cnivpp/api/bridge"
3333
vppinfra "github.com/intel/userspace-cni-network-plugin/cnivpp/api/infra"
3434
vppvhostuser "github.com/intel/userspace-cni-network-plugin/cnivpp/api/vhostuser"
35+
"github.com/intel/userspace-cni-network-plugin/cnivpp/bin_api/interface_types"
3536
)
3637

37-
//
3838
// Constants
39-
//
4039
const (
4140
dbgBridge = true
4241
dbgVhostUser = true
4342
)
4443

45-
//
4644
// Functions
47-
//
4845
func init() {
4946
// this ensures that main runs only on main thread (thread group leader).
5047
// since namespace ops (unshare, setns) are done for a single thread, we
@@ -55,13 +52,12 @@ func init() {
5552
func main() {
5653
var vppCh vppinfra.ConnectionData
5754
var err error
58-
var swIfIndex uint32
55+
var swIfIndex interface_types.InterfaceIndex
5956

6057
// Dummy Input Data
6158
var bridgeDomain uint32 = 4
6259
var vhostUserSocketFile string = "/var/run/vpp/123456/vhost3.sock"
63-
var vhostUserMode vppvhostuser.VhostUserMode = vppvhostuser.ModeServer
64-
60+
var vhostUserMode bool = true
6561
// Set log level
6662
// Logrus has six logging levels: DebugLevel, InfoLevel, WarningLevel, ErrorLevel, FatalLevel and PanicLevel.
6763
//core.SetLogger(&logrus.Logger{Level: logrus.InfoLevel})

0 commit comments

Comments
 (0)