From fd89a9c58b7bb2694913c647a1fde77e395ef54a Mon Sep 17 00:00:00 2001 From: Nathan Skrzypczak Date: Wed, 28 Sep 2022 10:37:55 +0200 Subject: [PATCH] linter: fixes for staticcheck (#27) --- Makefile | 10 +- adapter/mock/mock_vpp_adapter.go | 16 +- adapter/socketclient/doc.go | 4 +- adapter/socketclient/socketclient.go | 38 +-- adapter/statsclient/statsclient.go | 4 +- adapter/statsclient/statseg_v1.go | 5 - api/errors.go | 252 +++++++++--------- binapi/pp2/pp2.ba.go | 7 +- binapigen/binapigen.go | 21 -- binapigen/gen_rpc.go | 3 +- binapigen/generator.go | 3 +- binapigen/generator_test.go | 47 ---- binapigen/run.go | 3 +- binapigen/strings.go | 6 +- binapigen/types.go | 5 - binapigen/vppapi/integration_test.go | 1 + binapigen/vppapi/util.go | 3 +- binapigen/vppapi/vppapi.go | 6 +- binapigen/vppapi/vppapi_test.go | 6 +- cmd/binapi-generator/doc.go | 3 +- cmd/govpp/main.go | 20 +- codec/marshaler_test.go | 4 +- codec/msg_codec.go | 2 +- core/channel_test.go | 3 +- core/doc.go | 55 ++-- core/request_handler.go | 26 +- core/stats.go | 6 +- core/trace.go | 4 +- core/trace_test.go | 2 +- examples/multi-vpp/multi_vpp.go | 8 +- examples/perf-bench/perf-bench.go | 20 +- examples/simple-client/simple_client.go | 8 +- examples/stats-client/stats_api.go | 48 ++-- examples/stream-client/stream_client.go | 9 +- extras/libmemif/adapter.go | 1 + extras/libmemif/error.go | 1 + extras/libmemif/examples/gopacket/gopacket.go | 36 +-- .../examples/icmp-responder/icmp-responder.go | 34 +-- .../examples/jumbo-frames/jumbo-frames.go | 2 +- extras/libmemif/examples/raw-data/raw-data.go | 4 +- test/integration/stats_integration_test.go | 1 + 41 files changed, 330 insertions(+), 407 deletions(-) diff --git a/Makefile b/Makefile index 3cf04151..2a4756f3 100644 --- a/Makefile +++ b/Makefile @@ -82,10 +82,12 @@ test-integration: ## Run integration tests @echo "# running integration tests" go test -tags="integration ${GO_BUILD_TAGS}" ./test/integration -.PHONY: lint -lint: ## Run code linter - @echo "# running linter" - @golint ./... +.PHONY: lint ## Run code linter +lint: + @gofmt -s -l . | diff -u /dev/null - + @go vet ./... + @golangci-lint run + @echo "Done" .PHONY: install install: install-generator install-proxy ## Install all diff --git a/adapter/mock/mock_vpp_adapter.go b/adapter/mock/mock_vpp_adapter.go index cb37dd21..2170716a 100644 --- a/adapter/mock/mock_vpp_adapter.go +++ b/adapter/mock/mock_vpp_adapter.go @@ -356,17 +356,17 @@ func (a *VppAdapter) WaitReady() error { // exactly two calls of this method. // For example: // -// mockVpp.MockReply( // push multipart messages all at once -// &interfaces.SwInterfaceDetails{SwIfIndex:1}, -// &interfaces.SwInterfaceDetails{SwIfIndex:2}, -// &interfaces.SwInterfaceDetails{SwIfIndex:3}, -// ) -// mockVpp.MockReply(&vpe.ControlPingReply{}) +// mockVpp.MockReply( // push multipart messages all at once +// &interfaces.SwInterfaceDetails{SwIfIndex:1}, +// &interfaces.SwInterfaceDetails{SwIfIndex:2}, +// &interfaces.SwInterfaceDetails{SwIfIndex:3}, +// ) +// mockVpp.MockReply(&vpe.ControlPingReply{}) // // Even if the multipart request has no replies, MockReply has to be called twice: // -// mockVpp.MockReply() // zero multipart messages -// mockVpp.MockReply(&vpe.ControlPingReply{}) +// mockVpp.MockReply() // zero multipart messages +// mockVpp.MockReply(&vpe.ControlPingReply{}) func (a *VppAdapter) MockReply(msgs ...api.Message) { a.repliesLock.Lock() defer a.repliesLock.Unlock() diff --git a/adapter/socketclient/doc.go b/adapter/socketclient/doc.go index cbb00a21..9c483086 100644 --- a/adapter/socketclient/doc.go +++ b/adapter/socketclient/doc.go @@ -18,8 +18,7 @@ // The current implementation only supports VPP binary API, the VPP stats API // is not supported and clients still have to use vppapiclient for retrieving stats. // -// -// Requirements +// # Requirements // // The socketclient connects to unix domain socket defined in VPP configuration. // @@ -34,5 +33,4 @@ // socksvr { // socket-name /run/vpp/api.sock // } -// package socketclient diff --git a/adapter/socketclient/socketclient.go b/adapter/socketclient/socketclient.go index c9aa2b4b..ccaabf52 100644 --- a/adapter/socketclient/socketclient.go +++ b/adapter/socketclient/socketclient.go @@ -108,7 +108,8 @@ func NewVppClient(socket string) *Client { connectTimeout: DefaultConnectTimeout, disconnectTimeout: DefaultDisconnectTimeout, headerPool: &sync.Pool{New: func() interface{} { - return make([]byte, 16) + x := make([]byte, 16) + return &x }}, msgCallback: func(msgID uint16, data []byte) { log.Debugf("no callback set, dropping message: ID=%v len=%d", msgID, len(data)) @@ -358,12 +359,11 @@ func (c *Client) SendMsg(context uint32, data []byte) error { // // Message request has following structure: // -// type msgRequestHeader struct { -// MsgID uint16 -// ClientIndex uint32 -// Context uint32 -// } -// +// type msgRequestHeader struct { +// MsgID uint16 +// ClientIndex uint32 +// Context uint32 +// } func setMsgRequestHeader(data []byte, clientIndex, context uint32) { // message ID is already set binary.BigEndian.PutUint32(data[2:6], clientIndex) @@ -375,12 +375,12 @@ func (c *Client) writeMsg(msg []byte) error { c.writeMu.Lock() defer c.writeMu.Unlock() - header := c.headerPool.Get().([]byte) - err := writeMsgHeader(c.writer, header, len(msg)) + header := c.headerPool.Get().(*[]byte) + err := writeMsgHeader(c.writer, *header, len(msg)) if err != nil { return err } - c.headerPool.Put(header) + c.headerPool.Put(&header) if err := writeMsgData(c.writer, msg, c.writer.Size()); err != nil { return err @@ -464,11 +464,10 @@ func (c *Client) readerLoop() { // // Message reply has following structure: // -// type msgReplyHeader struct { -// MsgID uint16 -// Context uint32 -// } -// +// type msgReplyHeader struct { +// MsgID uint16 +// Context uint32 +// } func getMsgReplyHeader(msg []byte) (msgID uint16, context uint32) { msgID = binary.BigEndian.Uint16(msg[0:2]) context = binary.BigEndian.Uint32(msg[2:6]) @@ -499,14 +498,17 @@ func (c *Client) readMsgTimeout(buf []byte, timeout time.Duration) ([]byte, erro func (c *Client) readMsg(buf []byte) ([]byte, error) { log.Debug("reading msg..") - header := c.headerPool.Get().([]byte) - msgLen, err := readMsgHeader(c.reader, header) + header := c.headerPool.Get().(*[]byte) + msgLen, err := readMsgHeader(c.reader, *header) if err != nil { return nil, err } - c.headerPool.Put(header) + c.headerPool.Put(&header) msg, err := readMsgData(c.reader, buf, msgLen) + if err != nil { + return nil, err + } log.Debugf(" -- readMsg done (buffered: %d)", c.reader.Buffered()) diff --git a/adapter/statsclient/statsclient.go b/adapter/statsclient/statsclient.go index 73c9cf67..fb4dcd9f 100644 --- a/adapter/statsclient/statsclient.go +++ b/adapter/statsclient/statsclient.go @@ -26,10 +26,10 @@ import ( "syscall" "time" - "go.fd.io/govpp/adapter" "github.com/fsnotify/fsnotify" "github.com/ftrvxmtrx/fd" logger "github.com/sirupsen/logrus" + "go.fd.io/govpp/adapter" ) const ( @@ -610,7 +610,7 @@ func (sc *StatsClient) updateStatOnIndex(entry *adapter.StatEntry, vector dirVec return nil } if err := sc.UpdateEntryData(dirPtr, &entry.Data); err != nil { - err = fmt.Errorf("updating stat data for entry %s failed: %v", dirName, err) + return fmt.Errorf("updating stat data for entry %s failed: %v", dirName, err) } return } diff --git a/adapter/statsclient/statseg_v1.go b/adapter/statsclient/statseg_v1.go index 9e0e4694..a5315d56 100644 --- a/adapter/statsclient/statseg_v1.go +++ b/adapter/statsclient/statseg_v1.go @@ -15,7 +15,6 @@ package statsclient import ( - "fmt" "sync/atomic" "unsafe" @@ -71,10 +70,6 @@ func (ss *statSegmentV1) GetDirectoryVector() dirVector { return dirVector(&ss.sharedHeader[dirOffset]) } -func (ss *statSegmentV1) getErrorVector() (unsafe.Pointer, error) { - return nil, fmt.Errorf("error vector is not defined for stats API v1") -} - func (ss *statSegmentV1) GetStatDirOnIndex(v dirVector, index uint32) (dirSegment, dirName, adapter.StatType) { statSegDir := dirSegment(uintptr(v) + uintptr(index)*unsafe.Sizeof(statSegDirectoryEntryV1{})) dir := (*statSegDirectoryEntryV1)(statSegDir) diff --git a/api/errors.go b/api/errors.go index 32cc6772..8203f464 100644 --- a/api/errors.go +++ b/api/errors.go @@ -43,132 +43,132 @@ func (e VPPApiError) Error() string { // definitions from: vpp/src/vnet/api_errno.h const ( _ VPPApiError = 0 - UNSPECIFIED = -1 - INVALID_SW_IF_INDEX = -2 - NO_SUCH_FIB = -3 - NO_SUCH_INNER_FIB = -4 - NO_SUCH_LABEL = -5 - NO_SUCH_ENTRY = -6 - INVALID_VALUE = -7 - INVALID_VALUE_2 = -8 - UNIMPLEMENTED = -9 - INVALID_SW_IF_INDEX_2 = -10 - SYSCALL_ERROR_1 = -11 - SYSCALL_ERROR_2 = -12 - SYSCALL_ERROR_3 = -13 - SYSCALL_ERROR_4 = -14 - SYSCALL_ERROR_5 = -15 - SYSCALL_ERROR_6 = -16 - SYSCALL_ERROR_7 = -17 - SYSCALL_ERROR_8 = -18 - SYSCALL_ERROR_9 = -19 - SYSCALL_ERROR_10 = -20 - FEATURE_DISABLED = -30 - INVALID_REGISTRATION = -31 - NEXT_HOP_NOT_IN_FIB = -50 - UNKNOWN_DESTINATION = -51 - PREFIX_MATCHES_NEXT_HOP = -52 - NEXT_HOP_NOT_FOUND_MP = -53 - NO_MATCHING_INTERFACE = -54 - INVALID_VLAN = -55 - VLAN_ALREADY_EXISTS = -56 - INVALID_SRC_ADDRESS = -57 - INVALID_DST_ADDRESS = -58 - ADDRESS_LENGTH_MISMATCH = -59 - ADDRESS_NOT_FOUND_FOR_INTERFACE = -60 - ADDRESS_NOT_DELETABLE = -61 - IP6_NOT_ENABLED = -62 - IN_PROGRESS = 10 - NO_SUCH_NODE = -63 - NO_SUCH_NODE2 = -64 - NO_SUCH_TABLE = -65 - NO_SUCH_TABLE2 = -66 - NO_SUCH_TABLE3 = -67 - SUBIF_ALREADY_EXISTS = -68 - SUBIF_CREATE_FAILED = -69 - INVALID_MEMORY_SIZE = -70 - INVALID_INTERFACE = -71 - INVALID_VLAN_TAG_COUNT = -72 - INVALID_ARGUMENT = -73 - UNEXPECTED_INTF_STATE = -74 - TUNNEL_EXIST = -75 - INVALID_DECAP_NEXT = -76 - RESPONSE_NOT_READY = -77 - NOT_CONNECTED = -78 - IF_ALREADY_EXISTS = -79 - BOND_SLAVE_NOT_ALLOWED = -80 - VALUE_EXIST = -81 - SAME_SRC_DST = -82 - IP6_MULTICAST_ADDRESS_NOT_PRESENT = -83 - SR_POLICY_NAME_NOT_PRESENT = -84 - NOT_RUNNING_AS_ROOT = -85 - ALREADY_CONNECTED = -86 - UNSUPPORTED_JNI_VERSION = -87 - FAILED_TO_ATTACH_TO_JAVA_THREAD = -88 - INVALID_WORKER = -89 - LISP_DISABLED = -90 - CLASSIFY_TABLE_NOT_FOUND = -91 - INVALID_EID_TYPE = -92 - CANNOT_CREATE_PCAP_FILE = -93 - INCORRECT_ADJACENCY_TYPE = -94 - EXCEEDED_NUMBER_OF_RANGES_CAPACITY = -95 - EXCEEDED_NUMBER_OF_PORTS_CAPACITY = -96 - INVALID_ADDRESS_FAMILY = -97 - INVALID_SUB_SW_IF_INDEX = -98 - TABLE_TOO_BIG = -99 - CANNOT_ENABLE_DISABLE_FEATURE = -100 - BFD_EEXIST = -101 - BFD_ENOENT = -102 - BFD_EINUSE = -103 - BFD_NOTSUPP = -104 - ADDRESS_IN_USE = -105 - ADDRESS_NOT_IN_USE = -106 - QUEUE_FULL = -107 - APP_UNSUPPORTED_CFG = -108 - URI_FIFO_CREATE_FAILED = -109 - LISP_RLOC_LOCAL = -110 - BFD_EAGAIN = -111 - INVALID_GPE_MODE = -112 - LISP_GPE_ENTRIES_PRESENT = -113 - ADDRESS_FOUND_FOR_INTERFACE = -114 - SESSION_CONNECT = -115 - ENTRY_ALREADY_EXISTS = -116 - SVM_SEGMENT_CREATE_FAIL = -117 - APPLICATION_NOT_ATTACHED = -118 - BD_ALREADY_EXISTS = -119 - BD_IN_USE = -120 - BD_NOT_MODIFIABLE = -121 - BD_ID_EXCEED_MAX = -122 - SUBIF_DOESNT_EXIST = -123 - L2_MACS_EVENT_CLINET_PRESENT = -124 - INVALID_QUEUE = -125 - UNSUPPORTED = -126 - DUPLICATE_IF_ADDRESS = -127 - APP_INVALID_NS = -128 - APP_WRONG_NS_SECRET = -129 - APP_CONNECT_SCOPE = -130 - APP_ALREADY_ATTACHED = -131 - SESSION_REDIRECT = -132 - ILLEGAL_NAME = -133 - NO_NAME_SERVERS = -134 - NAME_SERVER_NOT_FOUND = -135 - NAME_RESOLUTION_NOT_ENABLED = -136 - NAME_SERVER_FORMAT_ERROR = -137 - NAME_SERVER_NO_SUCH_NAME = -138 - NAME_SERVER_NO_ADDRESSES = -139 - NAME_SERVER_NEXT_SERVER = -140 - APP_CONNECT_FILTERED = -141 - ACL_IN_USE_INBOUND = -142 - ACL_IN_USE_OUTBOUND = -143 - INIT_FAILED = -144 - NETLINK_ERROR = -145 - BIER_BSL_UNSUP = -146 - INSTANCE_IN_USE = -147 - INVALID_SESSION_ID = -148 - ACL_IN_USE_BY_LOOKUP_CONTEXT = -149 - INVALID_VALUE_3 = -150 - NON_ETHERNET = -151 - BD_ALREADY_HAS_BVI = -152 + UNSPECIFIED VPPApiError = -1 + INVALID_SW_IF_INDEX VPPApiError = -2 + NO_SUCH_FIB VPPApiError = -3 + NO_SUCH_INNER_FIB VPPApiError = -4 + NO_SUCH_LABEL VPPApiError = -5 + NO_SUCH_ENTRY VPPApiError = -6 + INVALID_VALUE VPPApiError = -7 + INVALID_VALUE_2 VPPApiError = -8 + UNIMPLEMENTED VPPApiError = -9 + INVALID_SW_IF_INDEX_2 VPPApiError = -10 + SYSCALL_ERROR_1 VPPApiError = -11 + SYSCALL_ERROR_2 VPPApiError = -12 + SYSCALL_ERROR_3 VPPApiError = -13 + SYSCALL_ERROR_4 VPPApiError = -14 + SYSCALL_ERROR_5 VPPApiError = -15 + SYSCALL_ERROR_6 VPPApiError = -16 + SYSCALL_ERROR_7 VPPApiError = -17 + SYSCALL_ERROR_8 VPPApiError = -18 + SYSCALL_ERROR_9 VPPApiError = -19 + SYSCALL_ERROR_10 VPPApiError = -20 + FEATURE_DISABLED VPPApiError = -30 + INVALID_REGISTRATION VPPApiError = -31 + NEXT_HOP_NOT_IN_FIB VPPApiError = -50 + UNKNOWN_DESTINATION VPPApiError = -51 + PREFIX_MATCHES_NEXT_HOP VPPApiError = -52 + NEXT_HOP_NOT_FOUND_MP VPPApiError = -53 + NO_MATCHING_INTERFACE VPPApiError = -54 + INVALID_VLAN VPPApiError = -55 + VLAN_ALREADY_EXISTS VPPApiError = -56 + INVALID_SRC_ADDRESS VPPApiError = -57 + INVALID_DST_ADDRESS VPPApiError = -58 + ADDRESS_LENGTH_MISMATCH VPPApiError = -59 + ADDRESS_NOT_FOUND_FOR_INTERFACE VPPApiError = -60 + ADDRESS_NOT_DELETABLE VPPApiError = -61 + IP6_NOT_ENABLED VPPApiError = -62 + IN_PROGRESS VPPApiError = 10 + NO_SUCH_NODE VPPApiError = -63 + NO_SUCH_NODE2 VPPApiError = -64 + NO_SUCH_TABLE VPPApiError = -65 + NO_SUCH_TABLE2 VPPApiError = -66 + NO_SUCH_TABLE3 VPPApiError = -67 + SUBIF_ALREADY_EXISTS VPPApiError = -68 + SUBIF_CREATE_FAILED VPPApiError = -69 + INVALID_MEMORY_SIZE VPPApiError = -70 + INVALID_INTERFACE VPPApiError = -71 + INVALID_VLAN_TAG_COUNT VPPApiError = -72 + INVALID_ARGUMENT VPPApiError = -73 + UNEXPECTED_INTF_STATE VPPApiError = -74 + TUNNEL_EXIST VPPApiError = -75 + INVALID_DECAP_NEXT VPPApiError = -76 + RESPONSE_NOT_READY VPPApiError = -77 + NOT_CONNECTED VPPApiError = -78 + IF_ALREADY_EXISTS VPPApiError = -79 + BOND_SLAVE_NOT_ALLOWED VPPApiError = -80 + VALUE_EXIST VPPApiError = -81 + SAME_SRC_DST VPPApiError = -82 + IP6_MULTICAST_ADDRESS_NOT_PRESENT VPPApiError = -83 + SR_POLICY_NAME_NOT_PRESENT VPPApiError = -84 + NOT_RUNNING_AS_ROOT VPPApiError = -85 + ALREADY_CONNECTED VPPApiError = -86 + UNSUPPORTED_JNI_VERSION VPPApiError = -87 + FAILED_TO_ATTACH_TO_JAVA_THREAD VPPApiError = -88 + INVALID_WORKER VPPApiError = -89 + LISP_DISABLED VPPApiError = -90 + CLASSIFY_TABLE_NOT_FOUND VPPApiError = -91 + INVALID_EID_TYPE VPPApiError = -92 + CANNOT_CREATE_PCAP_FILE VPPApiError = -93 + INCORRECT_ADJACENCY_TYPE VPPApiError = -94 + EXCEEDED_NUMBER_OF_RANGES_CAPACITY VPPApiError = -95 + EXCEEDED_NUMBER_OF_PORTS_CAPACITY VPPApiError = -96 + INVALID_ADDRESS_FAMILY VPPApiError = -97 + INVALID_SUB_SW_IF_INDEX VPPApiError = -98 + TABLE_TOO_BIG VPPApiError = -99 + CANNOT_ENABLE_DISABLE_FEATURE VPPApiError = -100 + BFD_EEXIST VPPApiError = -101 + BFD_ENOENT VPPApiError = -102 + BFD_EINUSE VPPApiError = -103 + BFD_NOTSUPP VPPApiError = -104 + ADDRESS_IN_USE VPPApiError = -105 + ADDRESS_NOT_IN_USE VPPApiError = -106 + QUEUE_FULL VPPApiError = -107 + APP_UNSUPPORTED_CFG VPPApiError = -108 + URI_FIFO_CREATE_FAILED VPPApiError = -109 + LISP_RLOC_LOCAL VPPApiError = -110 + BFD_EAGAIN VPPApiError = -111 + INVALID_GPE_MODE VPPApiError = -112 + LISP_GPE_ENTRIES_PRESENT VPPApiError = -113 + ADDRESS_FOUND_FOR_INTERFACE VPPApiError = -114 + SESSION_CONNECT VPPApiError = -115 + ENTRY_ALREADY_EXISTS VPPApiError = -116 + SVM_SEGMENT_CREATE_FAIL VPPApiError = -117 + APPLICATION_NOT_ATTACHED VPPApiError = -118 + BD_ALREADY_EXISTS VPPApiError = -119 + BD_IN_USE VPPApiError = -120 + BD_NOT_MODIFIABLE VPPApiError = -121 + BD_ID_EXCEED_MAX VPPApiError = -122 + SUBIF_DOESNT_EXIST VPPApiError = -123 + L2_MACS_EVENT_CLINET_PRESENT VPPApiError = -124 + INVALID_QUEUE VPPApiError = -125 + UNSUPPORTED VPPApiError = -126 + DUPLICATE_IF_ADDRESS VPPApiError = -127 + APP_INVALID_NS VPPApiError = -128 + APP_WRONG_NS_SECRET VPPApiError = -129 + APP_CONNECT_SCOPE VPPApiError = -130 + APP_ALREADY_ATTACHED VPPApiError = -131 + SESSION_REDIRECT VPPApiError = -132 + ILLEGAL_NAME VPPApiError = -133 + NO_NAME_SERVERS VPPApiError = -134 + NAME_SERVER_NOT_FOUND VPPApiError = -135 + NAME_RESOLUTION_NOT_ENABLED VPPApiError = -136 + NAME_SERVER_FORMAT_ERROR VPPApiError = -137 + NAME_SERVER_NO_SUCH_NAME VPPApiError = -138 + NAME_SERVER_NO_ADDRESSES VPPApiError = -139 + NAME_SERVER_NEXT_SERVER VPPApiError = -140 + APP_CONNECT_FILTERED VPPApiError = -141 + ACL_IN_USE_INBOUND VPPApiError = -142 + ACL_IN_USE_OUTBOUND VPPApiError = -143 + INIT_FAILED VPPApiError = -144 + NETLINK_ERROR VPPApiError = -145 + BIER_BSL_UNSUP VPPApiError = -146 + INSTANCE_IN_USE VPPApiError = -147 + INVALID_SESSION_ID VPPApiError = -148 + ACL_IN_USE_BY_LOOKUP_CONTEXT VPPApiError = -149 + INVALID_VALUE_3 VPPApiError = -150 + NON_ETHERNET VPPApiError = -151 + BD_ALREADY_HAS_BVI VPPApiError = -152 ) var vppApiErrors = map[VPPApiError]string{ diff --git a/binapi/pp2/pp2.ba.go b/binapi/pp2/pp2.ba.go index 250695fa..2a44e6a0 100644 --- a/binapi/pp2/pp2.ba.go +++ b/binapi/pp2/pp2.ba.go @@ -1,14 +1,13 @@ // Code generated by GoVPP's binapi-generator. DO NOT EDIT. // versions: -// binapi-generator: v0.6.0-dev -// VPP: 22.02-release +// binapi-generator: v0.6.0 +// VPP: 22.06-release // source: /usr/share/vpp/api/plugins/pp2.api.json // Package pp2 contains generated bindings for API file pp2.api. // // Contents: -// 4 messages -// +// - 4 messages package pp2 import ( diff --git a/binapigen/binapigen.go b/binapigen/binapigen.go index 5c9553f3..c671b643 100644 --- a/binapigen/binapigen.go +++ b/binapigen/binapigen.go @@ -124,14 +124,6 @@ func newFile(gen *Generator, apifile *vppapi.File, packageName GoPackageName, im return file, nil } -func (file *File) isTypesFile() bool { - return strings.HasSuffix(file.Desc.Name, "_types") -} - -func (file *File) hasService() bool { - return file.Service != nil && len(file.Service.RPCs) > 0 -} - func (file *File) importedFiles(gen *Generator) []*File { var files []*File for _, imp := range file.Imports { @@ -145,19 +137,6 @@ func (file *File) importedFiles(gen *Generator) []*File { return files } -func (file *File) dependsOnFile(gen *Generator, dep string) bool { - for _, imp := range file.Imports { - if imp == dep { - return true - } - impFile, ok := gen.FilesByName[imp] - if ok && impFile.dependsOnFile(gen, dep) { - return true - } - } - return false -} - const ( enumFlagSuffix = "_flags" ) diff --git a/binapigen/gen_rpc.go b/binapigen/gen_rpc.go index fa123f08..33602ccc 100644 --- a/binapigen/gen_rpc.go +++ b/binapigen/gen_rpc.go @@ -110,8 +110,7 @@ func genService(g *GenFile, svc *Service) { streamImpl := fmt.Sprintf("%s_%sClient", serviceImplName, rpc.GoName) streamApi := fmt.Sprintf("%s_%sClient", serviceApiName, rpc.GoName) - msgDetails := rpc.MsgReply - var msgReply *Message + var msgReply, msgDetails *Message if rpc.MsgStream != nil { msgDetails = rpc.MsgStream msgReply = rpc.MsgReply diff --git a/binapigen/generator.go b/binapigen/generator.go index 009c0ecc..126c1636 100644 --- a/binapigen/generator.go +++ b/binapigen/generator.go @@ -22,7 +22,6 @@ import ( "go/parser" "go/printer" "go/token" - "io/ioutil" "os" "path" "path/filepath" @@ -327,7 +326,7 @@ func writeSourceTo(outputFile string, b []byte) error { } // write generated code to output file - if err := ioutil.WriteFile(outputFile, b, 0666); err != nil { + if err := os.WriteFile(outputFile, b, 0666); err != nil { return fmt.Errorf("writing to output file %s failed: %v", outputFile, err) } diff --git a/binapigen/generator_test.go b/binapigen/generator_test.go index 8c2046d9..40b70fa8 100644 --- a/binapigen/generator_test.go +++ b/binapigen/generator_test.go @@ -17,7 +17,6 @@ package binapigen import ( "bufio" "fmt" - "go.fd.io/govpp/binapigen/vppapi" . "github.com/onsi/gomega" "os" "strings" @@ -96,49 +95,3 @@ func TestBinapiUnionSizes(t *testing.T) { // ensure all union sizes were found and tested Expect(index).To(Equal(len(sizes))) } - -// Typed data used for union size evaluation testing. -type typeTestData struct { - typ string - value string - fields []*typeTestData -} - -func (t typeTestData) getUnion(name string) *Union { - return &Union{ - UnionType: vppapi.UnionType{Name: name}, - Fields: t.getUnionFields(name), - } -} - -func (t typeTestData) getUnionFields(parentName string) (fields []*Field) { - for i, field := range t.fields { - var ( - dataType string - aliasType *Alias - enumType *Enum - structType *Struct - unionType *Union - ) - switch field.typ { - case "alias": - aliasType = &Alias{AliasType: vppapi.AliasType{Name: fmt.Sprintf("%s_alias_%d", parentName, i), Type: field.value}} - case "enum": - enumType = &Enum{EnumType: vppapi.EnumType{Name: fmt.Sprintf("%s_enum_%d", parentName, i), Type: field.value}} - case "struct": - structType = &Struct{Fields: field.getUnionFields(fmt.Sprintf("%s_struct_%d", parentName, i))} - case "union": - unionType = field.getUnion(parentName) - default: - dataType = field.value - } - fields = append(fields, &Field{ - Field: vppapi.Field{Name: fmt.Sprintf("%s_field_%d", parentName, i), Type: dataType}, - TypeAlias: aliasType, - TypeEnum: enumType, - TypeStruct: structType, - TypeUnion: unionType, - }) - } - return fields -} diff --git a/binapigen/run.go b/binapigen/run.go index 5a1059a9..08af97b6 100644 --- a/binapigen/run.go +++ b/binapigen/run.go @@ -16,7 +16,6 @@ package binapigen import ( "fmt" - "io/ioutil" "os" "path" "path/filepath" @@ -144,7 +143,7 @@ var modulePathRE = regexp.MustCompile(`module[ \t]+([^ \t\r\n]+)`) // readModulePath reads module path from go.mod file. func readModulePath(gomod string) (string, error) { - data, err := ioutil.ReadFile(gomod) + data, err := os.ReadFile(gomod) if err != nil { return "", err } diff --git a/binapigen/strings.go b/binapigen/strings.go index 1ab24e9b..348954c4 100644 --- a/binapigen/strings.go +++ b/binapigen/strings.go @@ -16,6 +16,8 @@ package binapigen import ( "go/token" + "golang.org/x/text/cases" + "golang.org/x/text/language" "strings" "unicode" "unicode/utf8" @@ -87,7 +89,9 @@ func usesInitialism(s string) string { // camelCaseName returns correct name identifier (camelCase). func camelCaseName(name string) (should string) { - name = strings.Title(name) + + name = cases.Title(language.Zulu).String(name) + // name = strings.Title(name) // Fast path for simple cases: "_" and all lowercase. if name == "_" { diff --git a/binapigen/types.go b/binapigen/types.go index addb1221..483e8209 100644 --- a/binapigen/types.go +++ b/binapigen/types.go @@ -27,11 +27,6 @@ const ( defineApiSuffix = "_t" ) -// toApiType returns name that is used as type reference in VPP binary API -func toApiType(name string) string { - return defineApiPrefix + name + defineApiSuffix -} - func fromApiType(typ string) string { name := typ name = strings.TrimPrefix(name, defineApiPrefix) diff --git a/binapigen/vppapi/integration_test.go b/binapigen/vppapi/integration_test.go index c3df45c4..b4d1ee71 100644 --- a/binapigen/vppapi/integration_test.go +++ b/binapigen/vppapi/integration_test.go @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +//go:build integration // +build integration package vppapi_test diff --git a/binapigen/vppapi/util.go b/binapigen/vppapi/util.go index 1374bb91..63f32c4f 100644 --- a/binapigen/vppapi/util.go +++ b/binapigen/vppapi/util.go @@ -16,7 +16,6 @@ package vppapi import ( "fmt" - "io/ioutil" "os" "os/exec" "path" @@ -68,7 +67,7 @@ func ResolveVPPVersion(apidir string) string { } // try to read VPP_VERSION file - data, err := ioutil.ReadFile(path.Join(repoDir, "VPP_VERSION")) + data, err := os.ReadFile(path.Join(repoDir, "VPP_VERSION")) if err == nil { return strings.TrimSpace(string(data)) } diff --git a/binapigen/vppapi/vppapi.go b/binapigen/vppapi/vppapi.go index b54d287c..91bcba0e 100644 --- a/binapigen/vppapi/vppapi.go +++ b/binapigen/vppapi/vppapi.go @@ -16,7 +16,7 @@ package vppapi import ( "fmt" - "io/ioutil" + "os" "path/filepath" "strings" ) @@ -31,7 +31,7 @@ const ( // FindFiles finds API files located in dir or in a nested directory that is not nested deeper than deep. func FindFiles(dir string, deep int) (files []string, err error) { - entries, err := ioutil.ReadDir(dir) + entries, err := os.ReadDir(dir) if err != nil { return nil, fmt.Errorf("reading directory %s failed: %v", dir, err) } @@ -82,7 +82,7 @@ func ParseFile(apiFile string) (*File, error) { return nil, fmt.Errorf("unsupported file format: %q", apiFile) } - data, err := ioutil.ReadFile(apiFile) + data, err := os.ReadFile(apiFile) if err != nil { return nil, fmt.Errorf("reading file %s failed: %v", apiFile, err) } diff --git a/binapigen/vppapi/vppapi_test.go b/binapigen/vppapi/vppapi_test.go index a555d9fe..0a65678a 100644 --- a/binapigen/vppapi/vppapi_test.go +++ b/binapigen/vppapi/vppapi_test.go @@ -16,7 +16,7 @@ package vppapi import ( "encoding/json" - "io/ioutil" + "os" "testing" . "github.com/onsi/gomega" @@ -44,7 +44,7 @@ func TestGetInputFilesError(t *testing.T) { func TestReadJson(t *testing.T) { RegisterTestingT(t) - inputData, err := ioutil.ReadFile("testdata/af_packet.api.json") + inputData, err := os.ReadFile("testdata/af_packet.api.json") Expect(err).ShouldNot(HaveOccurred()) result, err := ParseRaw(inputData) Expect(err).ShouldNot(HaveOccurred()) @@ -58,7 +58,7 @@ func TestReadJson(t *testing.T) { func TestReadJsonError(t *testing.T) { RegisterTestingT(t) - inputData, err := ioutil.ReadFile("testdata/input-read-json-error.json") + inputData, err := os.ReadFile("testdata/input-read-json-error.json") Expect(err).ShouldNot(HaveOccurred()) result, err := ParseRaw(inputData) Expect(err).Should(HaveOccurred()) diff --git a/cmd/binapi-generator/doc.go b/cmd/binapi-generator/doc.go index 9be49e2d..d27bad91 100644 --- a/cmd/binapi-generator/doc.go +++ b/cmd/binapi-generator/doc.go @@ -21,6 +21,5 @@ // where each Go package will be placed into its own separate directory, // for example: // -// binapi-generator --input-file=/usr/share/vpp/api/core/interface.api.json --output-dir=. -// +// binapi-generator --input-file=/usr/share/vpp/api/core/interface.api.json --output-dir=. package main diff --git a/cmd/govpp/main.go b/cmd/govpp/main.go index 6deca099..1edf17c8 100644 --- a/cmd/govpp/main.go +++ b/cmd/govpp/main.go @@ -21,7 +21,6 @@ import ( "flag" "fmt" "io" - "io/ioutil" "log" "net/http" "os" @@ -204,7 +203,7 @@ func rpcHandler(apifile *vppapi.File) func(http.ResponseWriter, *http.Request) { return } - input, err := ioutil.ReadAll(req.Body) + input, err := io.ReadAll(req.Body) if err != nil { http.Error(w, err.Error(), 500) return @@ -239,7 +238,10 @@ func apiHandler(apifiles []*vppapi.File) func(http.ResponseWriter, *http.Request http.Error(w, err.Error(), 500) return } - w.Write(b) + _, err = w.Write(b) + if err != nil { + http.Error(w, err.Error(), 500) + } } } @@ -250,17 +252,23 @@ func apiFileHandler(apifile *vppapi.File) func(http.ResponseWriter, *http.Reques http.Error(w, err.Error(), 500) return } - w.Write(b) + _, err = w.Write(b) + if err != nil { + http.Error(w, err.Error(), 500) + } } } func rawHandler(apifile *vppapi.File) func(http.ResponseWriter, *http.Request) { return func(w http.ResponseWriter, req *http.Request) { - b, err := ioutil.ReadFile(apifile.Path) + b, err := os.ReadFile(apifile.Path) if err != nil { http.Error(w, err.Error(), 500) return } - w.Write(b) + _, err = w.Write(b) + if err != nil { + http.Error(w, err.Error(), 500) + } } } diff --git a/codec/marshaler_test.go b/codec/marshaler_test.go index 2a9cb942..920255ab 100644 --- a/codec/marshaler_test.go +++ b/codec/marshaler_test.go @@ -20,11 +20,11 @@ import ( "testing" "go.fd.io/govpp/api" + interfaces "go.fd.io/govpp/binapi/interface" + "go.fd.io/govpp/binapi/interface_types" "go.fd.io/govpp/binapi/ip_types" "go.fd.io/govpp/binapi/sr" "go.fd.io/govpp/codec" - interfaces "go.fd.io/govpp/binapi/interface" - "go.fd.io/govpp/binapi/interface_types" ) // CliInband represents VPP binary API message 'cli_inband'. diff --git a/codec/msg_codec.go b/codec/msg_codec.go index 68c495b8..308f79d3 100644 --- a/codec/msg_codec.go +++ b/codec/msg_codec.go @@ -98,7 +98,7 @@ func (*MsgCodec) DecodeMsg(data []byte, msg api.Message) (err error) { offset := getOffset(msg) - err = marshaller.Unmarshal(data[offset:len(data)]) + err = marshaller.Unmarshal(data[offset:]) if err != nil { return err } diff --git a/core/channel_test.go b/core/channel_test.go index 6b12d683..d3773123 100644 --- a/core/channel_test.go +++ b/core/channel_test.go @@ -163,7 +163,8 @@ func TestNotificationEvent(t *testing.T) { SwIfIndex: 2, Flags: interface_types.IF_STATUS_API_FLAG_LINK_UP, }) - ctx.mockVpp.SendMsg(0, []byte("")) + err = ctx.mockVpp.SendMsg(0, []byte("")) + Expect(err).ShouldNot(HaveOccurred()) // receive the notification var notif *interfaces.SwInterfaceEvent diff --git a/core/doc.go b/core/doc.go index 5b0b40e2..8a82085e 100644 --- a/core/doc.go +++ b/core/doc.go @@ -36,67 +36,63 @@ // } // defer ch.Close() // -// -// Simple Request-Reply API +// # Simple Request-Reply API // // The simple version of the API is based on blocking SendRequest / ReceiveReply calls, where a single request // message is sent to VPP and a single reply message is filled in when the reply comes from VPP: // -// req := &acl.ACLPluginGetVersion{} -// reply := &acl.ACLPluginGetVersionReply{} +// req := &acl.ACLPluginGetVersion{} +// reply := &acl.ACLPluginGetVersionReply{} // -// err := ch.SendRequest(req).ReceiveReply(reply) -// // process the reply +// err := ch.SendRequest(req).ReceiveReply(reply) +// // process the reply // // Note that if the reply message type that comes from VPP does not match with provided one, you'll get an error. // -// -// Multipart Reply API +// # Multipart Reply API // // If multiple messages are expected as a reply to a request, SendMultiRequest API must be used: // -// req := &interfaces.SwInterfaceDump{} -// reqCtx := ch.SendMultiRequest(req) +// req := &interfaces.SwInterfaceDump{} +// reqCtx := ch.SendMultiRequest(req) // // for { -// reply := &interfaces.SwInterfaceDetails{} -// stop, err := reqCtx.ReceiveReply(reply) -// if stop { -// break // break out of the loop +// reply := &interfaces.SwInterfaceDetails{} +// stop, err := reqCtx.ReceiveReply(reply) +// if stop { +// break // break out of the loop // } // // process the reply -// } +// } // // Note that if the last reply has been already consumed, stop boolean return value is set to true. // Do not use the message itself if stop is true - it won't be filled with actual data. // -// -// Go Channels API +// # Go Channels API // // The blocking API introduced above may be not sufficient for some management applications that strongly // rely on usage of Go channels. In this case, the API allows to access the underlying Go channels directly, e.g. // the following replacement of the SendRequest / ReceiveReply API: // -// req := &acl.ACLPluginGetVersion{} -// // send the request to the request go channel -// ch.GetRequestChannel <- &api.VppRequest{Message: req} -// -// // receive a reply from the reply go channel -// vppReply := <-ch.GetReplyChannel +// req := &acl.ACLPluginGetVersion{} +// // send the request to the request go channel +// ch.GetRequestChannel <- &api.VppRequest{Message: req} // -// // decode the message -// reply := &acl.ACLPluginGetVersionReply{} -// err := ch.MsgDecoder.DecodeMsg(vppReply.Data, reply) +// // receive a reply from the reply go channel +// vppReply := <-ch.GetReplyChannel // -// // process the reply +// // decode the message +// reply := &acl.ACLPluginGetVersionReply{} +// err := ch.MsgDecoder.DecodeMsg(vppReply.Data, reply) // +// // process the reply // -// Notifications API +// # Notifications API // // to subscribe for receiving of the specified notification messages via provided Go channel, use the // SubscribeNotification API: // -// // subscribe for specific notification message +// // subscribe for specific notification message // notifChan := make(chan api.Message, 100) // subs, _ := ch.SubscribeNotification(notifChan, interfaces.NewSwInterfaceSetFlags) // @@ -107,5 +103,4 @@ // // Note that the caller is responsible for creating the Go channel with preferred buffer size. If the channel's // buffer is full, the notifications will not be delivered into it. -// package core diff --git a/core/request_handler.go b/core/request_handler.go index 851ac64c..7ef6a643 100644 --- a/core/request_handler.go +++ b/core/request_handler.go @@ -36,20 +36,18 @@ var ( // watchRequests watches for requests on the request API channel and forwards them as messages to VPP. func (c *Connection) watchRequests(ch *Channel) { for { - select { - case req, ok := <-ch.reqChan: - // new request on the request channel - if !ok { - // after closing the request channel, release API channel and return - c.releaseAPIChannel(ch) - return - } - if err := c.processRequest(ch, req); err != nil { - sendReply(ch, &vppReply{ - seqNum: req.seqNum, - err: fmt.Errorf("unable to process request: %w", err), - }) - } + req, ok := <-ch.reqChan + // new request on the request channel + if !ok { + // after closing the request channel, release API channel and return + c.releaseAPIChannel(ch) + return + } + if err := c.processRequest(ch, req); err != nil { + sendReply(ch, &vppReply{ + seqNum: req.seqNum, + err: fmt.Errorf("unable to process request: %w", err), + }) } } } diff --git a/core/stats.go b/core/stats.go index 897a475a..f4bd6f00 100644 --- a/core/stats.go +++ b/core/stats.go @@ -199,7 +199,7 @@ func (c *StatsConnection) monitorSocket() { case <-c.done: log.Debugf("health check watcher closed") c.sendStatsConnEvent(ConnectionEvent{Timestamp: time.Now(), State: Disconnected, Error: nil}) - break + return } } } @@ -574,9 +574,9 @@ func (c *StatsConnection) GetMemoryStats(memStats *api.MemoryStats) (err error) } switch f { case MemoryStats_Total: - memStats.Total = val + memStats.Total = val //nolint:staticcheck case MemoryStats_Used: - memStats.Used = val + memStats.Used = val //nolint:staticcheck } } else if string(stat.Name) == MemoryStatSegment { if perHeapStats, ok := stat.Data.(adapter.SimpleCounterStat); ok { diff --git a/core/trace.go b/core/trace.go index b818657a..5c5bdddc 100644 --- a/core/trace.go +++ b/core/trace.go @@ -39,9 +39,7 @@ func (c *trace) Enable(enable bool) { func (c *trace) GetRecords() (list []*api.Record) { c.mux.Lock() - for _, entry := range c.list { - list = append(list, entry) - } + list = append(list, c.list...) c.mux.Unlock() sort.Slice(list, func(i, j int) bool { return list[i].Timestamp.Before(list[j].Timestamp) diff --git a/core/trace_test.go b/core/trace_test.go index 6d1d5ba8..b6eb2ed2 100644 --- a/core/trace_test.go +++ b/core/trace_test.go @@ -1,6 +1,7 @@ package core_test import ( + . "github.com/onsi/gomega" "go.fd.io/govpp/api" interfaces "go.fd.io/govpp/binapi/interface" "go.fd.io/govpp/binapi/ip" @@ -8,7 +9,6 @@ import ( memclnt "go.fd.io/govpp/binapi/memclnt" "go.fd.io/govpp/binapi/memif" "go.fd.io/govpp/core" - . "github.com/onsi/gomega" "strings" "testing" ) diff --git a/examples/multi-vpp/multi_vpp.go b/examples/multi-vpp/multi_vpp.go index 10f2e709..cad250e5 100644 --- a/examples/multi-vpp/multi_vpp.go +++ b/examples/multi-vpp/multi_vpp.go @@ -140,11 +140,9 @@ func connectBinapi(socket string, attempts int) (api.Channel, func(), error) { if err != nil { return nil, nil, err } - select { - case e := <-event: - if e.State != core.Connected { - return nil, nil, err - } + e := <-event + if e.State != core.Connected { + return nil, nil, err } ch, err := getAPIChannel(conn) if err != nil { diff --git a/examples/perf-bench/perf-bench.go b/examples/perf-bench/perf-bench.go index 6e251854..1710f395 100644 --- a/examples/perf-bench/perf-bench.go +++ b/examples/perf-bench/perf-bench.go @@ -44,11 +44,13 @@ func main() { var sync bool var cnt int var sock, prof string + var testV2 bool flag.BoolVar(&sync, "sync", false, "run synchronous perf test") flag.StringVar(&sock, "api-socket", socketclient.DefaultSocketName, "Path to VPP API socket") flag.String("stats-socket", statsclient.DefaultSocketName, "Path to VPP stats socket") flag.IntVar(&cnt, "count", 0, "count of requests to be sent to VPP") flag.StringVar(&prof, "prof", "", "enable profiling mode [mem, cpu]") + flag.BoolVar(&testV2, "v2", false, "Use test function v2") flag.Parse() if cnt == 0 { @@ -96,14 +98,18 @@ func main() { // run the test & measure the time start := time.Now() - if sync { - // run synchronous test - syncTest(ch, cnt) - //syncTest2(conn, cnt) + if testV2 { + if sync { + syncTest2(conn, cnt) + } else { + asyncTest2(conn, cnt) + } } else { - // run asynchronous test - asyncTest(ch, cnt) - //asyncTest2(conn, cnt) + if sync { + syncTest(ch, cnt) + } else { + asyncTest(ch, cnt) + } } elapsed := time.Since(start) diff --git a/examples/simple-client/simple_client.go b/examples/simple-client/simple_client.go index fea3e43b..c65d58f3 100644 --- a/examples/simple-client/simple_client.go +++ b/examples/simple-client/simple_client.go @@ -52,11 +52,9 @@ func main() { defer conn.Disconnect() // wait for Connected event - select { - case e := <-connEv: - if e.State != core.Connected { - log.Fatalln("ERROR: connecting to VPP failed:", e.Error) - } + e := <-connEv + if e.State != core.Connected { + log.Fatalln("ERROR: connecting to VPP failed:", e.Error) } // check compatibility of used messages diff --git a/examples/stats-client/stats_api.go b/examples/stats-client/stats_api.go index 562c2f9f..6ed16fc3 100644 --- a/examples/stats-client/stats_api.go +++ b/examples/stats-client/stats_api.go @@ -81,13 +81,11 @@ func main() { if err != nil { log.Fatalln("Asynchronous connecting failed:", err) } - select { - case e := <-statsChan: - if e.State == core.Connected { - // OK - } else { - log.Fatalf("VPP stats asynchronous connection failed: %s\n", e.State.String()) - } + e := <-statsChan + if e.State == core.Connected { + // OK + } else { + log.Fatalf("VPP stats asynchronous connection failed: %s\n", e.State.String()) } } else { client = statsclient.NewStatsClient(*statsSocket) @@ -246,9 +244,7 @@ func dumpStats(client adapter.StatsAPI, patterns []string, indexes []uint32, ski if err != nil { log.Fatalln("dumping stats failed:", err) } - for _, onIndexSi := range dir.Entries { - stats = append(stats, onIndexSi) - } + stats = append(stats, dir.Entries...) } n := 0 @@ -282,17 +278,15 @@ func pollStats(client adapter.StatsAPI, patterns []string, skipZeros bool) { } fmt.Println() - select { - case <-tick: - if err := client.UpdateDir(dir); err != nil { - if err == adapter.ErrStatsDirStale { - if dir, err = client.PrepareDir(patterns...); err != nil { - log.Fatalln("preparing dir failed:", err) - } - continue + <-tick + if err := client.UpdateDir(dir); err != nil { + if err == adapter.ErrStatsDirStale { + if dir, err = client.PrepareDir(patterns...); err != nil { + log.Fatalln("preparing dir failed:", err) } - log.Fatalln("updating dir failed:", err) + continue } + log.Fatalln("updating dir failed:", err) } } } @@ -309,11 +303,9 @@ func pollSystem(client api.StatsProvider) { fmt.Printf("System stats: %+v\n", stats) fmt.Println() - select { - case <-tick: - if err := client.GetSystemStats(stats); err != nil { - log.Println("updating system stats failed:", err) - } + <-tick + if err := client.GetSystemStats(stats); err != nil { + log.Println("updating system stats failed:", err) } } } @@ -333,11 +325,9 @@ func pollInterfaces(client api.StatsProvider) { } fmt.Println() - select { - case <-tick: - if err := client.GetInterfaceStats(stats); err != nil { - log.Println("updating system stats failed:", err) - } + <-tick + if err := client.GetInterfaceStats(stats); err != nil { + log.Println("updating system stats failed:", err) } } } diff --git a/examples/stream-client/stream_client.go b/examples/stream-client/stream_client.go index e36e9437..9b68d966 100644 --- a/examples/stream-client/stream_client.go +++ b/examples/stream-client/stream_client.go @@ -55,11 +55,9 @@ func main() { defer conn.Disconnect() // wait for Connected event - select { - case e := <-connEv: - if e.State != core.Connected { - log.Fatalln("ERROR: connecting to VPP failed:", e.Error) - } + e := <-connEv + if e.State != core.Connected { + log.Fatalln("ERROR: connecting to VPP failed:", e.Error) } // check compatibility of used messages @@ -104,7 +102,6 @@ func main() { addIPAddressStream(stream, idx) ipAddressDumpStream(stream, idx) mactimeDump(stream) - return } func getVppVersionStream(stream api.Stream) { diff --git a/extras/libmemif/adapter.go b/extras/libmemif/adapter.go index ac8a8278..23e27276 100644 --- a/extras/libmemif/adapter.go +++ b/extras/libmemif/adapter.go @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +//go:build !windows && !darwin // +build !windows,!darwin package libmemif diff --git a/extras/libmemif/error.go b/extras/libmemif/error.go index 58da7008..18efaf08 100644 --- a/extras/libmemif/error.go +++ b/extras/libmemif/error.go @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +//go:build !windows && !darwin // +build !windows,!darwin package libmemif diff --git a/extras/libmemif/examples/gopacket/gopacket.go b/extras/libmemif/examples/gopacket/gopacket.go index 24d58008..73262de8 100644 --- a/extras/libmemif/examples/gopacket/gopacket.go +++ b/extras/libmemif/examples/gopacket/gopacket.go @@ -4,34 +4,38 @@ // read and write packets using gopacket API. // // The appropriate VPP configuration for the opposite memif is: -// vpp$ create memif socket id 1 filename /tmp/gopacket-example -// vpp$ create interface memif id 1 socket-id 1 slave secret secret no-zero-copy -// vpp$ set int state memif1/1 up -// vpp$ set int ip address memif1/1 192.168.1.2/24 +// +// vpp$ create memif socket id 1 filename /tmp/gopacket-example +// vpp$ create interface memif id 1 socket-id 1 slave secret secret no-zero-copy +// vpp$ set int state memif1/1 up +// vpp$ set int ip address memif1/1 192.168.1.2/24 // // To start the example, simply type: -// root$ ./gopacket +// +// root$ ./gopacket // // gopacket needs to be run as root so that it can access the socket // created by VPP. // // Normally, the memif interface is in the master mode. Pass CLI flag "--slave" // to create memif in the slave mode: -// root$ ./gopacket --slave +// +// root$ ./gopacket --slave // // Don't forget to put the opposite memif into the master mode in that case. // // To verify the connection, run: -// vpp$ ping 192.168.1.1 -// 64 bytes from 192.168.1.1: icmp_seq=2 ttl=255 time=.6974 ms -// 64 bytes from 192.168.1.1: icmp_seq=3 ttl=255 time=.6310 ms -// 64 bytes from 192.168.1.1: icmp_seq=4 ttl=255 time=1.0350 ms -// 64 bytes from 192.168.1.1: icmp_seq=5 ttl=255 time=.5359 ms // -// Statistics: 5 sent, 4 received, 20% packet loss -// vpp$ sh ip arp -// Time IP4 Flags Ethernet Interface -// 68.5648 192.168.1.1 D aa:aa:aa:aa:aa:aa memif0/1 +// vpp$ ping 192.168.1.1 +// 64 bytes from 192.168.1.1: icmp_seq=2 ttl=255 time=.6974 ms +// 64 bytes from 192.168.1.1: icmp_seq=3 ttl=255 time=.6310 ms +// 64 bytes from 192.168.1.1: icmp_seq=4 ttl=255 time=1.0350 ms +// 64 bytes from 192.168.1.1: icmp_seq=5 ttl=255 time=.5359 ms +// +// Statistics: 5 sent, 4 received, 20% packet loss +// vpp$ sh ip arp +// Time IP4 Flags Ethernet Interface +// 68.5648 192.168.1.1 D aa:aa:aa:aa:aa:aa memif0/1 // // Note: it is expected that the first ping is shown as lost. It was actually // converted to an ARP request. This is a VPP feature common to all interface @@ -43,9 +47,9 @@ package main import ( "errors" "fmt" - "go.fd.io/govpp/extras/libmemif" "github.com/google/gopacket" "github.com/google/gopacket/layers" + "go.fd.io/govpp/extras/libmemif" "io" "net" "os" diff --git a/extras/libmemif/examples/icmp-responder/icmp-responder.go b/extras/libmemif/examples/icmp-responder/icmp-responder.go index 85ec8e33..de029247 100644 --- a/extras/libmemif/examples/icmp-responder/icmp-responder.go +++ b/extras/libmemif/examples/icmp-responder/icmp-responder.go @@ -3,34 +3,38 @@ // and construct packets. // // The appropriate VPP configuration for the opposite memif is: -// vpp$ create memif socket id 1 filename /tmp/icmp-responder-example -// vpp$ create interface memif id 1 socket-id 1 slave secret secret no-zero-copy -// vpp$ set int state memif1/1 up -// vpp$ set int ip address memif1/1 192.168.1.2/24 +// +// vpp$ create memif socket id 1 filename /tmp/icmp-responder-example +// vpp$ create interface memif id 1 socket-id 1 slave secret secret no-zero-copy +// vpp$ set int state memif1/1 up +// vpp$ set int ip address memif1/1 192.168.1.2/24 // // To start the example, simply type: -// root$ ./icmp-responder +// +// root$ ./icmp-responder // // icmp-responder needs to be run as root so that it can access the socket // created by VPP. // // Normally, the memif interface is in the master mode. Pass CLI flag "--slave" // to create memif in the slave mode: -// root$ ./icmp-responder --slave +// +// root$ ./icmp-responder --slave // // Don't forget to put the opposite memif into the master mode in that case. // // To verify the connection, run: -// vpp$ ping 192.168.1.1 -// 64 bytes from 192.168.1.1: icmp_seq=2 ttl=255 time=.6974 ms -// 64 bytes from 192.168.1.1: icmp_seq=3 ttl=255 time=.6310 ms -// 64 bytes from 192.168.1.1: icmp_seq=4 ttl=255 time=1.0350 ms -// 64 bytes from 192.168.1.1: icmp_seq=5 ttl=255 time=.5359 ms // -// Statistics: 5 sent, 4 received, 20% packet loss -// vpp$ sh ip arp -// Time IP4 Flags Ethernet Interface -// 68.5648 192.168.1.1 D aa:aa:aa:aa:aa:aa memif0/1 +// vpp$ ping 192.168.1.1 +// 64 bytes from 192.168.1.1: icmp_seq=2 ttl=255 time=.6974 ms +// 64 bytes from 192.168.1.1: icmp_seq=3 ttl=255 time=.6310 ms +// 64 bytes from 192.168.1.1: icmp_seq=4 ttl=255 time=1.0350 ms +// 64 bytes from 192.168.1.1: icmp_seq=5 ttl=255 time=.5359 ms +// +// Statistics: 5 sent, 4 received, 20% packet loss +// vpp$ sh ip arp +// Time IP4 Flags Ethernet Interface +// 68.5648 192.168.1.1 D aa:aa:aa:aa:aa:aa memif0/1 // // Note: it is expected that the first ping is shown as lost. It was actually // converted to an ARP request. This is a VPP feature common to all interface diff --git a/extras/libmemif/examples/jumbo-frames/jumbo-frames.go b/extras/libmemif/examples/jumbo-frames/jumbo-frames.go index b0456ce5..0b137d62 100644 --- a/extras/libmemif/examples/jumbo-frames/jumbo-frames.go +++ b/extras/libmemif/examples/jumbo-frames/jumbo-frames.go @@ -95,7 +95,7 @@ func SendPackets(memif *libmemif.Memif, queueID uint8) { select { case <-time.After(3 * time.Second): counter++ - packetMul := counter % 100 + 1 // Limit max iterations to 100 to not go out of bounds + packetMul := counter%100 + 1 // Limit max iterations to 100 to not go out of bounds packets := []libmemif.RawPacketData{ make([]byte, 128*packetMul), make([]byte, 256*packetMul), diff --git a/extras/libmemif/examples/raw-data/raw-data.go b/extras/libmemif/examples/raw-data/raw-data.go index 1e218d48..e47592d2 100644 --- a/extras/libmemif/examples/raw-data/raw-data.go +++ b/extras/libmemif/examples/raw-data/raw-data.go @@ -9,9 +9,9 @@ // // To create a connection of two raw-data instances, run two processes // concurrently: -// - master memif: +// - master memif: // $ ./raw-data -// - slave memif: +// - slave memif: // $ ./raw-data --slave // // Every 3 seconds both sides send 3 raw-data packets to the opposite end through diff --git a/test/integration/stats_integration_test.go b/test/integration/stats_integration_test.go index 1dca9a28..f8afe8f0 100644 --- a/test/integration/stats_integration_test.go +++ b/test/integration/stats_integration_test.go @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +//go:build integration // +build integration package integration