From 34379e17889178c4f21b14c5bdf0e1ca8237f277 Mon Sep 17 00:00:00 2001 From: Nathan Skrzypczak Date: Mon, 30 May 2022 18:42:41 +0200 Subject: [PATCH] linter: move to staticcheck As golint is now deprecated, this patch proposes to switch to staticcheck [0] as an alternative, in addition to `go vet`. This patch contains fixes addressing the linter's reported issues, with two added exceptions : - The MemoryStats deprectated fields are still for us to update - In `gen_encoding.go` we need to add an extra comment to account for the unused variable. This is probably worth addressing in another patch to not generate a variable we don't use. [0] https://staticcheck.io/ Signed-off-by: Nathan Skrzypczak Change-Id: I0562f290fb908bc610c44d675e21e466d0badc27 --- Makefile | 8 +- adapter/socketclient/socketclient.go | 18 +- adapter/statsclient/statsclient.go | 2 +- adapter/statsclient/statseg_v1.go | 5 - api/errors.go | 254 ++++++++++++------------ binapi/abf/abf.ba.go | 2 + binapi/acl/acl.ba.go | 5 + binapi/bier/bier.ba.go | 4 + binapi/cnat/cnat.ba.go | 2 + binapi/dhcp/dhcp.ba.go | 7 + binapi/igmp/igmp.ba.go | 1 + binapi/ip/ip.ba.go | 10 + binapi/ip6_nd/ip6_nd.ba.go | 1 + binapi/l2/l2.ba.go | 2 + binapi/l3xc/l3xc.ba.go | 2 + binapi/lisp/lisp.ba.go | 3 + binapi/lisp_gpe/lisp_gpe.ba.go | 3 + binapi/mactime/mactime.ba.go | 2 + binapi/memclnt/memclnt.ba.go | 2 + binapi/mpls/mpls.ba.go | 4 + binapi/nat44_ed/nat44_ed.ba.go | 2 + binapi/one/one.ba.go | 5 + binapi/sr/sr.ba.go | 2 + binapi/vlib/vlib.ba.go | 1 + binapi/vrrp/vrrp.ba.go | 6 + binapi/wireguard/wireguard.ba.go | 2 + binapigen/binapigen.go | 21 -- binapigen/gen_encoding.go | 5 +- binapigen/gen_rpc.go | 3 +- binapigen/generator_test.go | 47 ----- binapigen/strings.go | 6 +- binapigen/types.go | 5 - codec/msg_codec.go | 2 +- core/request_handler.go | 26 ++- core/stats.go | 4 +- core/trace.go | 4 +- examples/multi-vpp/multi_vpp.go | 8 +- examples/perf-bench/perf-bench.go | 22 +- examples/simple-client/simple_client.go | 8 +- examples/stats-client/stats_api.go | 48 ++--- examples/stream-client/stream_client.go | 9 +- go.mod | 1 + 42 files changed, 281 insertions(+), 293 deletions(-) diff --git a/Makefile b/Makefile index 81f46efc..c34b4ba1 100644 --- a/Makefile +++ b/Makefile @@ -82,10 +82,10 @@ 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: + @go vet ./... + @staticcheck ./... .PHONY: install install: install-generator install-proxy ## Install all diff --git a/adapter/socketclient/socketclient.go b/adapter/socketclient/socketclient.go index c9aa2b4b..dc7a82fc 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)) @@ -375,12 +376,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 @@ -499,14 +500,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 dd848978..2a79ec21 100644 --- a/adapter/statsclient/statsclient.go +++ b/adapter/statsclient/statsclient.go @@ -607,7 +607,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..1d3e04be 100644 --- a/api/errors.go +++ b/api/errors.go @@ -42,133 +42,133 @@ 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 + _ VPPApiError = 0 + 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/abf/abf.ba.go b/binapi/abf/abf.ba.go index e523e8f8..9065791d 100644 --- a/binapi/abf/abf.ba.go +++ b/binapi/abf/abf.ba.go @@ -292,6 +292,7 @@ func (m *AbfPolicyAddDel) Size() (size int) { var s2 fib_types.FibPath _ = s2 if j2 < len(m.Policy.Paths) { + //lint:ignore SA4006 we might not use this variable s2 = m.Policy.Paths[j2] } size += 4 // s2.SwIfIndex @@ -441,6 +442,7 @@ func (m *AbfPolicyDetails) Size() (size int) { var s2 fib_types.FibPath _ = s2 if j2 < len(m.Policy.Paths) { + //lint:ignore SA4006 we might not use this variable s2 = m.Policy.Paths[j2] } size += 4 // s2.SwIfIndex diff --git a/binapi/acl/acl.ba.go b/binapi/acl/acl.ba.go index 958593f5..91728237 100644 --- a/binapi/acl/acl.ba.go +++ b/binapi/acl/acl.ba.go @@ -58,6 +58,7 @@ func (m *ACLAddReplace) Size() (size int) { var s1 acl_types.ACLRule _ = s1 if j1 < len(m.R) { + //lint:ignore SA4006 we might not use this variable s1 = m.R[j1] } size += 1 // s1.IsPermit @@ -261,6 +262,7 @@ func (m *ACLDetails) Size() (size int) { var s1 acl_types.ACLRule _ = s1 if j1 < len(m.R) { + //lint:ignore SA4006 we might not use this variable s1 = m.R[j1] } size += 1 // s1.IsPermit @@ -1226,6 +1228,7 @@ func (m *MacipACLAdd) Size() (size int) { var s1 acl_types.MacipACLRule _ = s1 if j1 < len(m.R) { + //lint:ignore SA4006 we might not use this variable s1 = m.R[j1] } size += 1 // s1.IsPermit @@ -1300,6 +1303,7 @@ func (m *MacipACLAddReplace) Size() (size int) { var s1 acl_types.MacipACLRule _ = s1 if j1 < len(m.R) { + //lint:ignore SA4006 we might not use this variable s1 = m.R[j1] } size += 1 // s1.IsPermit @@ -1516,6 +1520,7 @@ func (m *MacipACLDetails) Size() (size int) { var s1 acl_types.MacipACLRule _ = s1 if j1 < len(m.R) { + //lint:ignore SA4006 we might not use this variable s1 = m.R[j1] } size += 1 // s1.IsPermit diff --git a/binapi/bier/bier.ba.go b/binapi/bier/bier.ba.go index f663e516..3e38f892 100644 --- a/binapi/bier/bier.ba.go +++ b/binapi/bier/bier.ba.go @@ -76,6 +76,7 @@ func (m *BierDispEntryAddDel) Size() (size int) { var s1 fib_types.FibPath _ = s1 if j1 < len(m.BdePaths) { + //lint:ignore SA4006 we might not use this variable s1 = m.BdePaths[j1] } size += 4 // s1.SwIfIndex @@ -232,6 +233,7 @@ func (m *BierDispEntryDetails) Size() (size int) { var s1 fib_types.FibPath _ = s1 if j1 < len(m.BdePaths) { + //lint:ignore SA4006 we might not use this variable s1 = m.BdePaths[j1] } size += 4 // s1.SwIfIndex @@ -751,6 +753,7 @@ func (m *BierRouteAddDel) Size() (size int) { var s2 fib_types.FibPath _ = s2 if j2 < len(m.BrRoute.BrPaths) { + //lint:ignore SA4006 we might not use this variable s2 = m.BrRoute.BrPaths[j2] } size += 4 // s2.SwIfIndex @@ -906,6 +909,7 @@ func (m *BierRouteDetails) Size() (size int) { var s2 fib_types.FibPath _ = s2 if j2 < len(m.BrRoute.BrPaths) { + //lint:ignore SA4006 we might not use this variable s2 = m.BrRoute.BrPaths[j2] } size += 4 // s2.SwIfIndex diff --git a/binapi/cnat/cnat.ba.go b/binapi/cnat/cnat.ba.go index ca357548..9c6f852c 100644 --- a/binapi/cnat/cnat.ba.go +++ b/binapi/cnat/cnat.ba.go @@ -902,6 +902,7 @@ func (m *CnatTranslationDetails) Size() (size int) { var s2 CnatEndpointTuple _ = s2 if j2 < len(m.Translation.Paths) { + //lint:ignore SA4006 we might not use this variable s2 = m.Translation.Paths[j2] } size += 1 // s2.DstEp.Addr.Af @@ -1043,6 +1044,7 @@ func (m *CnatTranslationUpdate) Size() (size int) { var s2 CnatEndpointTuple _ = s2 if j2 < len(m.Translation.Paths) { + //lint:ignore SA4006 we might not use this variable s2 = m.Translation.Paths[j2] } size += 1 // s2.DstEp.Addr.Af diff --git a/binapi/dhcp/dhcp.ba.go b/binapi/dhcp/dhcp.ba.go index 941447f6..ba5ef06e 100644 --- a/binapi/dhcp/dhcp.ba.go +++ b/binapi/dhcp/dhcp.ba.go @@ -383,6 +383,7 @@ func (m *DHCP6PdReplyEvent) Size() (size int) { var s1 DHCP6PdPrefixInfo _ = s1 if j1 < len(m.Prefixes) { + //lint:ignore SA4006 we might not use this variable s1 = m.Prefixes[j1] } size += 1 * 16 // s1.Prefix.Address @@ -483,6 +484,7 @@ func (m *DHCP6PdSendClientMessage) Size() (size int) { var s1 DHCP6PdPrefixInfo _ = s1 if j1 < len(m.Prefixes) { + //lint:ignore SA4006 we might not use this variable s1 = m.Prefixes[j1] } size += 1 * 16 // s1.Prefix.Address @@ -618,6 +620,7 @@ func (m *DHCP6ReplyEvent) Size() (size int) { var s1 DHCP6AddressInfo _ = s1 if j1 < len(m.Addresses) { + //lint:ignore SA4006 we might not use this variable s1 = m.Addresses[j1] } size += 1 * 16 // s1.Address @@ -715,6 +718,7 @@ func (m *DHCP6SendClientMessage) Size() (size int) { var s1 DHCP6AddressInfo _ = s1 if j1 < len(m.Addresses) { + //lint:ignore SA4006 we might not use this variable s1 = m.Addresses[j1] } size += 1 * 16 // s1.Address @@ -933,6 +937,7 @@ func (m *DHCPClientDetails) Size() (size int) { var s2 DomainServer _ = s2 if j2 < len(m.Lease.DomainServer) { + //lint:ignore SA4006 we might not use this variable s2 = m.Lease.DomainServer[j2] } size += 1 // s2.Address.Af @@ -1062,6 +1067,7 @@ func (m *DHCPComplEvent) Size() (size int) { var s2 DomainServer _ = s2 if j2 < len(m.Lease.DomainServer) { + //lint:ignore SA4006 we might not use this variable s2 = m.Lease.DomainServer[j2] } size += 1 // s2.Address.Af @@ -1375,6 +1381,7 @@ func (m *DHCPProxyDetails) Size() (size int) { var s1 DHCPServer _ = s1 if j1 < len(m.Servers) { + //lint:ignore SA4006 we might not use this variable s1 = m.Servers[j1] } size += 4 // s1.ServerVrfID diff --git a/binapi/igmp/igmp.ba.go b/binapi/igmp/igmp.ba.go index 8dc9a3da..b6fb5ad2 100644 --- a/binapi/igmp/igmp.ba.go +++ b/binapi/igmp/igmp.ba.go @@ -530,6 +530,7 @@ func (m *IgmpListen) Size() (size int) { var s2 ip_types.IP4Address _ = s2 if j2 < len(m.Group.Saddrs) { + //lint:ignore SA4006 we might not use this variable s2 = m.Group.Saddrs[j2] } size += 1 * 4 // s2 diff --git a/binapi/ip/ip.ba.go b/binapi/ip/ip.ba.go index 78ea15e0..fc2685d3 100644 --- a/binapi/ip/ip.ba.go +++ b/binapi/ip/ip.ba.go @@ -213,6 +213,7 @@ func (m *AddDelIPPuntRedirectV2) Size() (size int) { var s2 fib_types.FibPath _ = s2 if j2 < len(m.Punt.Paths) { + //lint:ignore SA4006 we might not use this variable s2 = m.Punt.Paths[j2] } size += 4 // s2.SwIfIndex @@ -825,6 +826,7 @@ func (m *IPMrouteAddDel) Size() (size int) { var s2 mfib_types.MfibPath _ = s2 if j2 < len(m.Route.Paths) { + //lint:ignore SA4006 we might not use this variable s2 = m.Route.Paths[j2] } size += 4 // s2.ItfFlags @@ -996,6 +998,7 @@ func (m *IPMrouteDetails) Size() (size int) { var s2 mfib_types.MfibPath _ = s2 if j2 < len(m.Route.Paths) { + //lint:ignore SA4006 we might not use this variable s2 = m.Route.Paths[j2] } size += 4 // s2.ItfFlags @@ -1779,6 +1782,7 @@ func (m *IPPuntRedirectV2Details) Size() (size int) { var s2 fib_types.FibPath _ = s2 if j2 < len(m.Punt.Paths) { + //lint:ignore SA4006 we might not use this variable s2 = m.Punt.Paths[j2] } size += 4 // s2.SwIfIndex @@ -2191,6 +2195,7 @@ func (m *IPRouteAddDel) Size() (size int) { var s2 fib_types.FibPath _ = s2 if j2 < len(m.Route.Paths) { + //lint:ignore SA4006 we might not use this variable s2 = m.Route.Paths[j2] } size += 4 // s2.SwIfIndex @@ -2359,6 +2364,7 @@ func (m *IPRouteAddDelV2) Size() (size int) { var s2 fib_types.FibPath _ = s2 if j2 < len(m.Route.Paths) { + //lint:ignore SA4006 we might not use this variable s2 = m.Route.Paths[j2] } size += 4 // s2.SwIfIndex @@ -2524,6 +2530,7 @@ func (m *IPRouteDetails) Size() (size int) { var s2 fib_types.FibPath _ = s2 if j2 < len(m.Route.Paths) { + //lint:ignore SA4006 we might not use this variable s2 = m.Route.Paths[j2] } size += 4 // s2.SwIfIndex @@ -2733,6 +2740,7 @@ func (m *IPRouteLookupReply) Size() (size int) { var s2 fib_types.FibPath _ = s2 if j2 < len(m.Route.Paths) { + //lint:ignore SA4006 we might not use this variable s2 = m.Route.Paths[j2] } size += 4 // s2.SwIfIndex @@ -2908,6 +2916,7 @@ func (m *IPRouteLookupV2Reply) Size() (size int) { var s2 fib_types.FibPath _ = s2 if j2 < len(m.Route.Paths) { + //lint:ignore SA4006 we might not use this variable s2 = m.Route.Paths[j2] } size += 4 // s2.SwIfIndex @@ -3035,6 +3044,7 @@ func (m *IPRouteV2Details) Size() (size int) { var s2 fib_types.FibPath _ = s2 if j2 < len(m.Route.Paths) { + //lint:ignore SA4006 we might not use this variable s2 = m.Route.Paths[j2] } size += 4 // s2.SwIfIndex diff --git a/binapi/ip6_nd/ip6_nd.ba.go b/binapi/ip6_nd/ip6_nd.ba.go index 9db08c31..e67da51e 100644 --- a/binapi/ip6_nd/ip6_nd.ba.go +++ b/binapi/ip6_nd/ip6_nd.ba.go @@ -77,6 +77,7 @@ func (m *IP6RaEvent) Size() (size int) { var s1 IP6RaPrefixInfo _ = s1 if j1 < len(m.Prefixes) { + //lint:ignore SA4006 we might not use this variable s1 = m.Prefixes[j1] } size += 1 // s1.Prefix.Address.Af diff --git a/binapi/l2/l2.ba.go b/binapi/l2/l2.ba.go index df379d32..fc07df78 100644 --- a/binapi/l2/l2.ba.go +++ b/binapi/l2/l2.ba.go @@ -544,6 +544,7 @@ func (m *BridgeDomainDetails) Size() (size int) { var s1 BridgeDomainSwIf _ = s1 if j1 < len(m.SwIfDetails) { + //lint:ignore SA4006 we might not use this variable s1 = m.SwIfDetails[j1] } size += 4 // s1.Context @@ -1612,6 +1613,7 @@ func (m *L2MacsEvent) Size() (size int) { var s1 MacEntry _ = s1 if j1 < len(m.Mac) { + //lint:ignore SA4006 we might not use this variable s1 = m.Mac[j1] } size += 4 // s1.SwIfIndex diff --git a/binapi/l3xc/l3xc.ba.go b/binapi/l3xc/l3xc.ba.go index 77c323b9..a67e5b38 100644 --- a/binapi/l3xc/l3xc.ba.go +++ b/binapi/l3xc/l3xc.ba.go @@ -133,6 +133,7 @@ func (m *L3xcDetails) Size() (size int) { var s2 fib_types.FibPath _ = s2 if j2 < len(m.L3xc.Paths) { + //lint:ignore SA4006 we might not use this variable s2 = m.L3xc.Paths[j2] } size += 4 // s2.SwIfIndex @@ -342,6 +343,7 @@ func (m *L3xcUpdate) Size() (size int) { var s2 fib_types.FibPath _ = s2 if j2 < len(m.L3xc.Paths) { + //lint:ignore SA4006 we might not use this variable s2 = m.L3xc.Paths[j2] } size += 4 // s2.SwIfIndex diff --git a/binapi/lisp/lisp.ba.go b/binapi/lisp/lisp.ba.go index e6928169..a04f66fb 100644 --- a/binapi/lisp/lisp.ba.go +++ b/binapi/lisp/lisp.ba.go @@ -353,6 +353,7 @@ func (m *LispAddDelLocatorSet) Size() (size int) { var s1 lisp_types.LocalLocator _ = s1 if j1 < len(m.Locators) { + //lint:ignore SA4006 we might not use this variable s1 = m.Locators[j1] } size += 4 // s1.SwIfIndex @@ -689,6 +690,7 @@ func (m *LispAddDelRemoteMapping) Size() (size int) { var s1 lisp_types.RemoteLocator _ = s1 if j1 < len(m.Rlocs) { + //lint:ignore SA4006 we might not use this variable s1 = m.Rlocs[j1] } size += 1 // s1.Priority @@ -839,6 +841,7 @@ func (m *LispAdjacenciesGetReply) Size() (size int) { var s1 LispAdjacency _ = s1 if j1 < len(m.Adjacencies) { + //lint:ignore SA4006 we might not use this variable s1 = m.Adjacencies[j1] } size += 1 // s1.Reid.Type diff --git a/binapi/lisp_gpe/lisp_gpe.ba.go b/binapi/lisp_gpe/lisp_gpe.ba.go index 8ca08893..5d8e1372 100644 --- a/binapi/lisp_gpe/lisp_gpe.ba.go +++ b/binapi/lisp_gpe/lisp_gpe.ba.go @@ -92,6 +92,7 @@ func (m *GpeAddDelFwdEntry) Size() (size int) { var s1 GpeLocator _ = s1 if j1 < len(m.Locs) { + //lint:ignore SA4006 we might not use this variable s1 = m.Locs[j1] } size += 1 // s1.Weight @@ -466,6 +467,7 @@ func (m *GpeFwdEntriesGetReply) Size() (size int) { var s1 GpeFwdEntry _ = s1 if j1 < len(m.Entries) { + //lint:ignore SA4006 we might not use this variable s1 = m.Entries[j1] } size += 4 // s1.FwdEntryIndex @@ -800,6 +802,7 @@ func (m *GpeNativeFwdRpathsGetReply) Size() (size int) { var s1 GpeNativeFwdRpath _ = s1 if j1 < len(m.Entries) { + //lint:ignore SA4006 we might not use this variable s1 = m.Entries[j1] } size += 4 // s1.FibIndex diff --git a/binapi/mactime/mactime.ba.go b/binapi/mactime/mactime.ba.go index 22fd871c..d501a8c2 100644 --- a/binapi/mactime/mactime.ba.go +++ b/binapi/mactime/mactime.ba.go @@ -81,6 +81,7 @@ func (m *MactimeAddDelRange) Size() (size int) { var s1 TimeRange _ = s1 if j1 < len(m.Ranges) { + //lint:ignore SA4006 we might not use this variable s1 = m.Ranges[j1] } size += 8 // s1.Start @@ -198,6 +199,7 @@ func (m *MactimeDetails) Size() (size int) { var s1 MactimeTimeRange _ = s1 if j1 < len(m.Ranges) { + //lint:ignore SA4006 we might not use this variable s1 = m.Ranges[j1] } size += 8 // s1.Start diff --git a/binapi/memclnt/memclnt.ba.go b/binapi/memclnt/memclnt.ba.go index c97c5312..73a07f92 100644 --- a/binapi/memclnt/memclnt.ba.go +++ b/binapi/memclnt/memclnt.ba.go @@ -94,6 +94,7 @@ func (m *APIVersionsReply) Size() (size int) { var s1 ModuleVersion _ = s1 if j1 < len(m.APIVersions) { + //lint:ignore SA4006 we might not use this variable s1 = m.APIVersions[j1] } size += 4 // s1.Major @@ -839,6 +840,7 @@ func (m *SockclntCreateReply) Size() (size int) { var s1 MessageTableEntry _ = s1 if j1 < len(m.MessageTable) { + //lint:ignore SA4006 we might not use this variable s1 = m.MessageTable[j1] } size += 2 // s1.Index diff --git a/binapi/mpls/mpls.ba.go b/binapi/mpls/mpls.ba.go index 471e187e..4485a965 100644 --- a/binapi/mpls/mpls.ba.go +++ b/binapi/mpls/mpls.ba.go @@ -178,6 +178,7 @@ func (m *MplsRouteAddDel) Size() (size int) { var s2 fib_types.FibPath _ = s2 if j2 < len(m.MrRoute.MrPaths) { + //lint:ignore SA4006 we might not use this variable s2 = m.MrRoute.MrPaths[j2] } size += 4 // s2.SwIfIndex @@ -340,6 +341,7 @@ func (m *MplsRouteDetails) Size() (size int) { var s2 fib_types.FibPath _ = s2 if j2 < len(m.MrRoute.MrPaths) { + //lint:ignore SA4006 we might not use this variable s2 = m.MrRoute.MrPaths[j2] } size += 4 // s2.SwIfIndex @@ -635,6 +637,7 @@ func (m *MplsTunnelAddDel) Size() (size int) { var s2 fib_types.FibPath _ = s2 if j2 < len(m.MtTunnel.MtPaths) { + //lint:ignore SA4006 we might not use this variable s2 = m.MtTunnel.MtPaths[j2] } size += 4 // s2.SwIfIndex @@ -799,6 +802,7 @@ func (m *MplsTunnelDetails) Size() (size int) { var s2 fib_types.FibPath _ = s2 if j2 < len(m.MtTunnel.MtPaths) { + //lint:ignore SA4006 we might not use this variable s2 = m.MtTunnel.MtPaths[j2] } size += 4 // s2.SwIfIndex diff --git a/binapi/nat44_ed/nat44_ed.ba.go b/binapi/nat44_ed/nat44_ed.ba.go index 938940e3..e5628f8b 100644 --- a/binapi/nat44_ed/nat44_ed.ba.go +++ b/binapi/nat44_ed/nat44_ed.ba.go @@ -390,6 +390,7 @@ func (m *Nat44AddDelLbStaticMapping) Size() (size int) { var s1 Nat44LbAddrPort _ = s1 if j1 < len(m.Locals) { + //lint:ignore SA4006 we might not use this variable s1 = m.Locals[j1] } size += 1 * 4 // s1.Addr @@ -2035,6 +2036,7 @@ func (m *Nat44LbStaticMappingDetails) Size() (size int) { var s1 Nat44LbAddrPort _ = s1 if j1 < len(m.Locals) { + //lint:ignore SA4006 we might not use this variable s1 = m.Locals[j1] } size += 1 * 4 // s1.Addr diff --git a/binapi/one/one.ba.go b/binapi/one/one.ba.go index 89fca1d5..3bc2ce34 100644 --- a/binapi/one/one.ba.go +++ b/binapi/one/one.ba.go @@ -469,6 +469,7 @@ func (m *OneAddDelLocatorSet) Size() (size int) { var s1 lisp_types.LocalLocator _ = s1 if j1 < len(m.Locators) { + //lint:ignore SA4006 we might not use this variable s1 = m.Locators[j1] } size += 4 // s1.SwIfIndex @@ -882,6 +883,7 @@ func (m *OneAddDelRemoteMapping) Size() (size int) { var s1 lisp_types.RemoteLocator _ = s1 if j1 < len(m.Rlocs) { + //lint:ignore SA4006 we might not use this variable s1 = m.Rlocs[j1] } size += 1 // s1.Priority @@ -1032,6 +1034,7 @@ func (m *OneAdjacenciesGetReply) Size() (size int) { var s1 OneAdjacency _ = s1 if j1 < len(m.Adjacencies) { + //lint:ignore SA4006 we might not use this variable s1 = m.Adjacencies[j1] } size += 1 // s1.Reid.Type @@ -1945,6 +1948,7 @@ func (m *OneL2ArpEntriesGetReply) Size() (size int) { var s1 OneL2ArpEntry _ = s1 if j1 < len(m.Entries) { + //lint:ignore SA4006 we might not use this variable s1 = m.Entries[j1] } size += 1 * 6 // s1.Mac @@ -2674,6 +2678,7 @@ func (m *OneNdpEntriesGetReply) Size() (size int) { var s1 OneNdpEntry _ = s1 if j1 < len(m.Entries) { + //lint:ignore SA4006 we might not use this variable s1 = m.Entries[j1] } size += 1 * 6 // s1.Mac diff --git a/binapi/sr/sr.ba.go b/binapi/sr/sr.ba.go index 44d5f8fb..befb7973 100644 --- a/binapi/sr/sr.ba.go +++ b/binapi/sr/sr.ba.go @@ -261,6 +261,7 @@ func (m *SrPoliciesDetails) Size() (size int) { var s1 Srv6SidList _ = s1 if j1 < len(m.SidLists) { + //lint:ignore SA4006 we might not use this variable s1 = m.SidLists[j1] } size += 1 // s1.NumSids @@ -372,6 +373,7 @@ func (m *SrPoliciesWithSlIndexDetails) Size() (size int) { var s1 Srv6SidListWithSlIndex _ = s1 if j1 < len(m.SidLists) { + //lint:ignore SA4006 we might not use this variable s1 = m.SidLists[j1] } size += 1 // s1.NumSids diff --git a/binapi/vlib/vlib.ba.go b/binapi/vlib/vlib.ba.go index 37f75871..cab8ab56 100644 --- a/binapi/vlib/vlib.ba.go +++ b/binapi/vlib/vlib.ba.go @@ -653,6 +653,7 @@ func (m *ShowThreadsReply) Size() (size int) { var s1 ThreadData _ = s1 if j1 < len(m.ThreadData) { + //lint:ignore SA4006 we might not use this variable s1 = m.ThreadData[j1] } size += 4 // s1.ID diff --git a/binapi/vrrp/vrrp.ba.go b/binapi/vrrp/vrrp.ba.go index 752a6f92..6fa43a5c 100644 --- a/binapi/vrrp/vrrp.ba.go +++ b/binapi/vrrp/vrrp.ba.go @@ -192,6 +192,7 @@ func (m *VrrpVrAddDel) Size() (size int) { var s1 ip_types.Address _ = s1 if j1 < len(m.Addrs) { + //lint:ignore SA4006 we might not use this variable s1 = m.Addrs[j1] } size += 1 // s1.Af @@ -307,6 +308,7 @@ func (m *VrrpVrDetails) Size() (size int) { var s1 ip_types.Address _ = s1 if j1 < len(m.Addrs) { + //lint:ignore SA4006 we might not use this variable s1 = m.Addrs[j1] } size += 1 // s1.Af @@ -477,6 +479,7 @@ func (m *VrrpVrPeerDetails) Size() (size int) { var s1 ip_types.Address _ = s1 if j1 < len(m.PeerAddrs) { + //lint:ignore SA4006 we might not use this variable s1 = m.PeerAddrs[j1] } size += 1 // s1.Af @@ -586,6 +589,7 @@ func (m *VrrpVrSetPeers) Size() (size int) { var s1 ip_types.Address _ = s1 if j1 < len(m.Addrs) { + //lint:ignore SA4006 we might not use this variable s1 = m.Addrs[j1] } size += 1 // s1.Af @@ -767,6 +771,7 @@ func (m *VrrpVrTrackIfAddDel) Size() (size int) { var s1 VrrpVrTrackIf _ = s1 if j1 < len(m.Ifs) { + //lint:ignore SA4006 we might not use this variable s1 = m.Ifs[j1] } size += 4 // s1.SwIfIndex @@ -870,6 +875,7 @@ func (m *VrrpVrTrackIfDetails) Size() (size int) { var s1 VrrpVrTrackIf _ = s1 if j1 < len(m.Ifs) { + //lint:ignore SA4006 we might not use this variable s1 = m.Ifs[j1] } size += 4 // s1.SwIfIndex diff --git a/binapi/wireguard/wireguard.ba.go b/binapi/wireguard/wireguard.ba.go index 227e93ac..a2790236 100644 --- a/binapi/wireguard/wireguard.ba.go +++ b/binapi/wireguard/wireguard.ba.go @@ -543,6 +543,7 @@ func (m *WireguardPeerAdd) Size() (size int) { var s2 ip_types.Prefix _ = s2 if j2 < len(m.Peer.AllowedIps) { + //lint:ignore SA4006 we might not use this variable s2 = m.Peer.AllowedIps[j2] } size += 1 // s2.Address.Af @@ -775,6 +776,7 @@ func (m *WireguardPeersDetails) Size() (size int) { var s2 ip_types.Prefix _ = s2 if j2 < len(m.Peer.AllowedIps) { + //lint:ignore SA4006 we might not use this variable s2 = m.Peer.AllowedIps[j2] } size += 1 // s2.Address.Af 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_encoding.go b/binapigen/gen_encoding.go index ca1e8486..e62ef0ba 100644 --- a/binapigen/gen_encoding.go +++ b/binapigen/gen_encoding.go @@ -81,7 +81,10 @@ func genMessageSize(g *GenFile, name string, fields []*Field) { char := fmt.Sprintf("s%d", lvl) g.P("var ", char, " ", fieldGoType(g, field)) g.P("_ = ", char) - g.P("if ", index, " < len(", name, ") { ", char, " = ", name, "[", index, "] }") + g.P("if ", index, " < len(", name, ") {") + g.P("//lint:ignore SA4006 we might not use this variable") + g.P(char, " = ", name, "[", index, "]") + g.P("}") name = char } else { name = fmt.Sprintf("%s[%s]", name, index) 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_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/strings.go b/binapigen/strings.go index 1ab24e9b..62232c7b 100644 --- a/binapigen/strings.go +++ b/binapigen/strings.go @@ -19,6 +19,8 @@ import ( "strings" "unicode" "unicode/utf8" + "golang.org/x/text/cases" + "golang.org/x/text/language" ) // commonInitialisms is a set of common initialisms that need to stay in upper case. @@ -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/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/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..b520f82d 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,8 +574,10 @@ func (c *StatsConnection) GetMemoryStats(memStats *api.MemoryStats) (err error) } switch f { case MemoryStats_Total: + //lint:ignore SA1019 deprecated but still update it memStats.Total = val case MemoryStats_Used: + //lint:ignore SA1019 deprecated but still update it memStats.Used = val } } else if string(stat.Name) == MemoryStatSegment { 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/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..26a655b5 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) - } else { - // run asynchronous test - asyncTest(ch, cnt) - //asyncTest2(conn, cnt) + if testV2 { + if sync { + syncTest2(conn, cnt) + } else { + asyncTest2(conn, cnt) + } + } else { + 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/go.mod b/go.mod index 3c5f0d01..c7b2dcc9 100644 --- a/go.mod +++ b/go.mod @@ -12,5 +12,6 @@ require ( github.com/pkg/profile v1.2.1 github.com/sirupsen/logrus v1.6.0 golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6 // indirect + golang.org/x/text v0.3.7 gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect )