[VOL-3285] Resolving statis code analysis warnings
Change-Id: Iaddaae92c649fd27ce0a63f1786af594667c9e8e
diff --git a/internal/bbr/devices/olt.go b/internal/bbr/devices/olt.go
index bd35f68..01aa411 100644
--- a/internal/bbr/devices/olt.go
+++ b/internal/bbr/devices/olt.go
@@ -20,6 +20,10 @@
"context"
"errors"
"fmt"
+ "io"
+ "reflect"
+ "time"
+
"github.com/google/gopacket"
"github.com/google/gopacket/layers"
"github.com/opencord/bbsim/internal/bbsim/devices"
@@ -28,9 +32,6 @@
"github.com/opencord/voltha-protos/v2/go/openolt"
log "github.com/sirupsen/logrus"
"google.golang.org/grpc"
- "io"
- "reflect"
- "time"
)
type OltMock struct {
@@ -238,7 +239,7 @@
}()
for message := range onu.DoneChannel {
- if message == true {
+ if message {
o.CompletedOnus++
if o.CompletedOnus == o.TargetOnus {
// NOTE once all the ONUs are completed, exit
@@ -317,7 +318,6 @@
"pktType": pktType,
}).Trace("Received PktIndication")
- msg := devices.Message{}
if pktIndication.IntfType == "nni" {
// This is an packet that is arriving from the NNI and needs to be sent to an ONU
// in this case we need to fin the ONU from the C/S tags
@@ -335,7 +335,7 @@
}).Fatalf("Can't find ONU from c/s tags")
}
- msg = devices.Message{
+ msg := devices.Message{
Type: devices.OnuPacketIn,
Data: devices.OnuPacketMessage{
IntfId: pktIndication.IntfId,
@@ -367,7 +367,7 @@
}
// NOTE when we push the EAPOL flow we set the PortNo = OnuId for convenience sake
// BBsim responds setting the port number that was sent with the flow
- msg = devices.Message{
+ msg := devices.Message{
Type: devices.OnuPacketIn,
Data: devices.OnuPacketMessage{
IntfId: pktIndication.IntfId,
diff --git a/internal/bbr/devices/validate.go b/internal/bbr/devices/validate.go
index cb2551f..e6d9594 100644
--- a/internal/bbr/devices/validate.go
+++ b/internal/bbr/devices/validate.go
@@ -19,10 +19,11 @@
import (
"context"
"fmt"
+ "time"
+
"github.com/opencord/bbsim/api/bbsim"
log "github.com/sirupsen/logrus"
"google.golang.org/grpc"
- "time"
)
func ValidateAndClose(olt *OltMock) {
@@ -57,7 +58,7 @@
}
}
- if res == true {
+ if res {
log.WithFields(log.Fields{
"ExpectedState": expectedState,
}).Infof("%d ONUs matching expected state", len(onus.Items))
diff --git a/internal/bbsim/alarmsim/alarmsim.go b/internal/bbsim/alarmsim/alarmsim.go
index b5b62c1..d7c0b54 100644
--- a/internal/bbsim/alarmsim/alarmsim.go
+++ b/internal/bbsim/alarmsim/alarmsim.go
@@ -19,9 +19,10 @@
import (
"context"
"fmt"
- "github.com/opencord/bbsim/internal/common"
"strconv"
+ "github.com/opencord/bbsim/internal/common"
+
"github.com/opencord/bbsim/api/bbsim"
"github.com/opencord/bbsim/internal/bbsim/devices"
"github.com/opencord/voltha-protos/v2/go/openolt"
@@ -74,7 +75,7 @@
switch alarmType {
case bbsim.AlarmType_DYING_GASP:
alarm = &openolt.AlarmIndication{
- Data: &openolt.AlarmIndication_DyingGaspInd{&openolt.DyingGaspIndication{
+ Data: &openolt.AlarmIndication_DyingGaspInd{DyingGaspInd: &openolt.DyingGaspIndication{
Status: req.Status,
OnuId: onu.ID,
IntfId: onu.PonPortID,
@@ -82,7 +83,7 @@
}
case bbsim.AlarmType_ONU_STARTUP_FAILURE:
alarm = &openolt.AlarmIndication{
- Data: &openolt.AlarmIndication_OnuStartupFailInd{&openolt.OnuStartupFailureIndication{
+ Data: &openolt.AlarmIndication_OnuStartupFailInd{OnuStartupFailInd: &openolt.OnuStartupFailureIndication{
Status: req.Status,
OnuId: onu.ID,
IntfId: onu.PonPortID,
@@ -90,7 +91,7 @@
}
case bbsim.AlarmType_ONU_SIGNAL_DEGRADE:
alarm = &openolt.AlarmIndication{
- Data: &openolt.AlarmIndication_OnuSignalDegradeInd{&openolt.OnuSignalDegradeIndication{
+ Data: &openolt.AlarmIndication_OnuSignalDegradeInd{OnuSignalDegradeInd: &openolt.OnuSignalDegradeIndication{
Status: req.Status,
OnuId: onu.ID,
IntfId: onu.PonPortID,
@@ -99,7 +100,7 @@
}
case bbsim.AlarmType_ONU_SIGNALS_FAILURE:
alarm = &openolt.AlarmIndication{
- Data: &openolt.AlarmIndication_OnuSignalsFailInd{&openolt.OnuSignalsFailureIndication{
+ Data: &openolt.AlarmIndication_OnuSignalsFailInd{OnuSignalsFailInd: &openolt.OnuSignalsFailureIndication{
Status: req.Status,
OnuId: onu.ID,
IntfId: onu.PonPortID,
@@ -108,7 +109,7 @@
}
case bbsim.AlarmType_ONU_DRIFT_OF_WINDOW:
alarm = &openolt.AlarmIndication{
- Data: &openolt.AlarmIndication_OnuDriftOfWindowInd{&openolt.OnuDriftOfWindowIndication{
+ Data: &openolt.AlarmIndication_OnuDriftOfWindowInd{OnuDriftOfWindowInd: &openolt.OnuDriftOfWindowIndication{
Status: req.Status,
OnuId: onu.ID,
IntfId: onu.PonPortID,
@@ -118,7 +119,7 @@
}
case bbsim.AlarmType_ONU_LOSS_OF_OMCI_CHANNEL:
alarm = &openolt.AlarmIndication{
- Data: &openolt.AlarmIndication_OnuLossOmciInd{&openolt.OnuLossOfOmciChannelIndication{
+ Data: &openolt.AlarmIndication_OnuLossOmciInd{OnuLossOmciInd: &openolt.OnuLossOfOmciChannelIndication{
Status: req.Status,
OnuId: onu.ID,
IntfId: onu.PonPortID,
@@ -126,7 +127,7 @@
}
case bbsim.AlarmType_ONU_TRANSMISSION_INTERFERENCE_WARNING:
alarm = &openolt.AlarmIndication{
- Data: &openolt.AlarmIndication_OnuTiwiInd{&openolt.OnuTransmissionInterferenceWarning{
+ Data: &openolt.AlarmIndication_OnuTiwiInd{OnuTiwiInd: &openolt.OnuTransmissionInterferenceWarning{
Status: req.Status,
OnuId: onu.ID,
IntfId: onu.PonPortID,
@@ -135,7 +136,7 @@
}
case bbsim.AlarmType_ONU_ACTIVATION_FAILURE:
alarm = &openolt.AlarmIndication{
- Data: &openolt.AlarmIndication_OnuActivationFailInd{&openolt.OnuActivationFailureIndication{
+ Data: &openolt.AlarmIndication_OnuActivationFailInd{OnuActivationFailInd: &openolt.OnuActivationFailureIndication{
OnuId: onu.ID,
IntfId: onu.PonPortID,
FailReason: uint32(extractInt(req.Parameters, "FailReason", 0)),
@@ -143,14 +144,14 @@
}
case bbsim.AlarmType_ONU_PROCESSING_ERROR:
alarm = &openolt.AlarmIndication{
- Data: &openolt.AlarmIndication_OnuProcessingErrorInd{&openolt.OnuProcessingErrorIndication{
+ Data: &openolt.AlarmIndication_OnuProcessingErrorInd{OnuProcessingErrorInd: &openolt.OnuProcessingErrorIndication{
OnuId: onu.ID,
IntfId: onu.PonPortID,
}},
}
case bbsim.AlarmType_ONU_LOSS_OF_KEY_SYNC_FAILURE:
alarm = &openolt.AlarmIndication{
- Data: &openolt.AlarmIndication_OnuLossOfSyncFailInd{&openolt.OnuLossOfKeySyncFailureIndication{
+ Data: &openolt.AlarmIndication_OnuLossOfSyncFailInd{OnuLossOfSyncFailInd: &openolt.OnuLossOfKeySyncFailureIndication{
OnuId: onu.ID,
IntfId: onu.PonPortID,
Status: req.Status,
@@ -158,7 +159,7 @@
}
case bbsim.AlarmType_ONU_ITU_PON_STATS:
alarm = &openolt.AlarmIndication{
- Data: &openolt.AlarmIndication_OnuItuPonStatsInd{&openolt.OnuItuPonStatsIndication{
+ Data: &openolt.AlarmIndication_OnuItuPonStatsInd{OnuItuPonStatsInd: &openolt.OnuItuPonStatsIndication{
OnuId: onu.ID,
IntfId: onu.PonPortID,
RdiErrors: uint32(extractInt(req.Parameters, "RdiErrors", 0)),
@@ -166,7 +167,7 @@
}
case bbsim.AlarmType_ONU_ALARM_LOS:
alarm = &openolt.AlarmIndication{
- Data: &openolt.AlarmIndication_OnuAlarmInd{&openolt.OnuAlarmIndication{
+ Data: &openolt.AlarmIndication_OnuAlarmInd{OnuAlarmInd: &openolt.OnuAlarmIndication{
LosStatus: req.Status,
OnuId: onu.ID,
IntfId: onu.PonPortID,
@@ -174,7 +175,7 @@
}
case bbsim.AlarmType_ONU_ALARM_LOB:
alarm = &openolt.AlarmIndication{
- Data: &openolt.AlarmIndication_OnuAlarmInd{&openolt.OnuAlarmIndication{
+ Data: &openolt.AlarmIndication_OnuAlarmInd{OnuAlarmInd: &openolt.OnuAlarmIndication{
LobStatus: req.Status,
OnuId: onu.ID,
IntfId: onu.PonPortID,
@@ -182,7 +183,7 @@
}
case bbsim.AlarmType_ONU_ALARM_LOPC_MISS:
alarm = &openolt.AlarmIndication{
- Data: &openolt.AlarmIndication_OnuAlarmInd{&openolt.OnuAlarmIndication{
+ Data: &openolt.AlarmIndication_OnuAlarmInd{OnuAlarmInd: &openolt.OnuAlarmIndication{
LopcMissStatus: req.Status,
OnuId: onu.ID,
IntfId: onu.PonPortID,
@@ -190,7 +191,7 @@
}
case bbsim.AlarmType_ONU_ALARM_LOPC_MIC_ERROR:
alarm = &openolt.AlarmIndication{
- Data: &openolt.AlarmIndication_OnuAlarmInd{&openolt.OnuAlarmIndication{
+ Data: &openolt.AlarmIndication_OnuAlarmInd{OnuAlarmInd: &openolt.OnuAlarmIndication{
LopcMicErrorStatus: req.Status,
OnuId: onu.ID,
IntfId: onu.PonPortID,
@@ -198,7 +199,7 @@
}
case bbsim.AlarmType_ONU_ALARM_LOFI:
alarm = &openolt.AlarmIndication{
- Data: &openolt.AlarmIndication_OnuAlarmInd{&openolt.OnuAlarmIndication{
+ Data: &openolt.AlarmIndication_OnuAlarmInd{OnuAlarmInd: &openolt.OnuAlarmIndication{
LofiStatus: req.Status,
OnuId: onu.ID,
IntfId: onu.PonPortID,
@@ -206,7 +207,7 @@
}
case bbsim.AlarmType_ONU_ALARM_LOAMI:
alarm = &openolt.AlarmIndication{
- Data: &openolt.AlarmIndication_OnuAlarmInd{&openolt.OnuAlarmIndication{
+ Data: &openolt.AlarmIndication_OnuAlarmInd{OnuAlarmInd: &openolt.OnuAlarmIndication{
LoamiStatus: req.Status,
OnuId: onu.ID,
IntfId: onu.PonPortID,
@@ -274,7 +275,7 @@
}
}
alarmIndication = &openolt.AlarmIndication{
- Data: &openolt.AlarmIndication_LosInd{&openolt.LosIndication{
+ Data: &openolt.AlarmIndication_LosInd{LosInd: &openolt.LosIndication{
Status: req.Status,
IntfId: devices.InterfaceIDToPortNo(req.InterfaceID, req.InterfaceType),
}},
diff --git a/internal/bbsim/api/grpc_api_server.go b/internal/bbsim/api/grpc_api_server.go
index c17c6a9..72f999e 100644
--- a/internal/bbsim/api/grpc_api_server.go
+++ b/internal/bbsim/api/grpc_api_server.go
@@ -122,7 +122,7 @@
func (s BBSimServer) RebootOlt(ctx context.Context, req *bbsim.Empty) (*bbsim.Response, error) {
res := &bbsim.Response{}
o := devices.GetOLT()
- go o.RestartOLT()
+ go func() { _ = o.RestartOLT() }()
res.StatusCode = int32(codes.OK)
res.Message = fmt.Sprintf("OLT restart triggered.")
return res, nil
diff --git a/internal/bbsim/api/grpc_api_server_legacy.go b/internal/bbsim/api/grpc_api_server_legacy.go
index 0c03d81..5a1a410 100644
--- a/internal/bbsim/api/grpc_api_server_legacy.go
+++ b/internal/bbsim/api/grpc_api_server_legacy.go
@@ -199,11 +199,12 @@
}
}()
- select {
- case <-channel:
+ x := <-channel
+ if x {
logger.Warnf("Stopping legacy API REST server")
- s.Shutdown(ctx)
+ if err := s.Shutdown(ctx); err != nil {
+ logger.Errorf("Could not stop server: %v", err)
+ }
group.Done()
}
- return
}
diff --git a/internal/bbsim/api/legacy_api_handler.go b/internal/bbsim/api/legacy_api_handler.go
index 018162f..ed60238 100644
--- a/internal/bbsim/api/legacy_api_handler.go
+++ b/internal/bbsim/api/legacy_api_handler.go
@@ -17,15 +17,12 @@
package api
import (
- "encoding/hex"
- "errors"
"net"
"strconv"
"github.com/opencord/bbsim/api/legacy"
api "github.com/opencord/bbsim/api/legacy"
"github.com/opencord/bbsim/internal/bbsim/devices"
- "github.com/opencord/voltha-protos/v2/go/openolt"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
@@ -118,28 +115,6 @@
return portInfo, status.Errorf(codes.NotFound, "Invalid port %s-%d", portType, intfID)
}
-func getOpenoltSerialNumber(SerialNumber string) (*openolt.SerialNumber, error) {
- var VendorIDLength = 4
- var SerialNumberLength = 12
-
- if len(SerialNumber) != SerialNumberLength {
- logger.Errorf("Invalid serial number %s", SerialNumber)
- return nil, errors.New("invalid serial number")
- }
- // First four characters are vendorId
- vendorID := SerialNumber[:VendorIDLength]
- vendorSpecific := SerialNumber[VendorIDLength:]
-
- vsbyte, _ := hex.DecodeString(vendorSpecific)
-
- // Convert to Openolt serial number
- serialNum := new(openolt.SerialNumber)
- serialNum.VendorId = []byte(vendorID)
- serialNum.VendorSpecific = vsbyte
-
- return serialNum, nil
-}
-
// ConvB2S converts byte array to string
func ConvB2S(b []byte) string {
s := ""
diff --git a/internal/bbsim/devices/helpers_test.go b/internal/bbsim/devices/helpers_test.go
index 818009f..2d23a70 100644
--- a/internal/bbsim/devices/helpers_test.go
+++ b/internal/bbsim/devices/helpers_test.go
@@ -17,9 +17,10 @@
package devices
import (
+ "testing"
+
"github.com/looplab/fsm"
"gotest.tools/assert"
- "testing"
)
var (
@@ -60,7 +61,6 @@
cb_called := 0
cb := func(e *fsm.Event) {
cb_called++
- return
}
// calling the method under test
@@ -79,7 +79,7 @@
assert.Equal(t, args.events[1].Dst, "down")
// this is to test that the callback is called when the state change
- sm.Event("enable")
+ _ = sm.Event("enable")
assert.Equal(t, cb_called, 1)
tearDownHelpers()
diff --git a/internal/bbsim/devices/messageTypes.go b/internal/bbsim/devices/messageTypes.go
index 5652520..f59ea5c 100644
--- a/internal/bbsim/devices/messageTypes.go
+++ b/internal/bbsim/devices/messageTypes.go
@@ -140,7 +140,7 @@
const (
UP OperState = iota
- DOWN // The device has been discovered, but not yet activated
+ DOWN // The device has been discovered, but not yet activated
)
func (m OperState) String() string {
diff --git a/internal/bbsim/devices/nni.go b/internal/bbsim/devices/nni.go
index fabe69c..e74e97b 100644
--- a/internal/bbsim/devices/nni.go
+++ b/internal/bbsim/devices/nni.go
@@ -71,7 +71,7 @@
}),
Type: "nni",
}
- createNNIPair(executor, olt, &nniPort)
+ _ = createNNIPair(executor, olt, &nniPort)
return nniPort, nil
}
@@ -81,7 +81,7 @@
isDhcp := packetHandlers.IsDhcpPacket(packet)
isLldp := packetHandlers.IsLldpPacket(packet)
- if isDhcp == false && isLldp == false {
+ if !isDhcp && !isLldp {
nniLogger.WithFields(log.Fields{
"packet": packet,
}).Trace("Dropping NNI packet as it's not DHCP")
@@ -145,14 +145,6 @@
return nil
}
-func deleteNNIPair(executor Executor, nniPort *NniPort) error {
- if err := executor.Command("ip", "link", "del", nniPort.nniVeth).Run(); err != nil {
- nniLogger.Errorf("Couldn't delete veth pair between %s and %s", nniPort.nniVeth, nniPort.upstreamVeth)
- return err
- }
- return nil
-}
-
// NewVethChan returns a new channel for receiving packets over the NNI interface
func (n *NniPort) NewVethChan() (chan *types.PacketMsg, *pcap.Handle, error) {
ch, handle, err := listenOnVeth(n.nniVeth)
diff --git a/internal/bbsim/devices/olt.go b/internal/bbsim/devices/olt.go
index e0d1556..21b57f2 100644
--- a/internal/bbsim/devices/olt.go
+++ b/internal/bbsim/devices/olt.go
@@ -18,7 +18,6 @@
import (
"context"
- "errors"
"fmt"
"net"
"sync"
@@ -137,7 +136,7 @@
},
)
- if isMock != true {
+ if !isMock {
// create NNI Port
nniPort, err := CreateNNI(&olt)
if err != nil {
@@ -187,7 +186,7 @@
}
}
- if isMock != true {
+ if !isMock {
if err := olt.InternalState.Event("initialize"); err != nil {
log.Errorf("Error initializing OLT: %v", err)
return nil
@@ -203,7 +202,7 @@
return &olt
}
-func (o *OltDevice) InitOlt() error {
+func (o *OltDevice) InitOlt() {
if oltServer == nil {
oltServer, _ = o.newOltServer()
@@ -235,8 +234,6 @@
oltLogger.Errorf("Error getting NNI channel: %v", err)
}
}
-
- return nil
}
func (o *OltDevice) RestartOLT() error {
@@ -274,7 +271,7 @@
for _, onu := range pon.Onus {
if onu.InternalState.Current() != "initialized" {
- onu.InternalState.Event("disable")
+ _ = onu.InternalState.Event("disable")
}
}
}
@@ -312,7 +309,7 @@
reflection.Register(grpcServer)
- go grpcServer.Serve(lis)
+ go func() { _ = grpcServer.Serve(lis) }()
oltLogger.Debugf("OLT listening on %v", address)
return grpcServer, nil
@@ -335,7 +332,7 @@
// Device Methods
// Enable implements the OpenOLT EnableIndicationServer functionality
-func (o *OltDevice) Enable(stream openolt.Openolt_EnableIndicationServer) error {
+func (o *OltDevice) Enable(stream openolt.Openolt_EnableIndicationServer) {
oltLogger.Debug("Enable OLT called")
rebootFlag := false
@@ -383,7 +380,7 @@
go o.processOmciMessages(o.enableContext, stream, &wg)
- if rebootFlag == true {
+ if rebootFlag {
for _, pon := range o.Pons {
if pon.InternalState.Current() == "disabled" {
msg := Message{
@@ -424,7 +421,6 @@
}
wg.Wait()
- return nil
}
func (o *OltDevice) processOmciMessages(ctx context.Context, stream openolt.Openolt_EnableIndicationServer, wg *sync.WaitGroup) {
@@ -499,22 +495,22 @@
// Helpers method
-func (o OltDevice) GetPonById(id uint32) (*PonPort, error) {
+func (o *OltDevice) GetPonById(id uint32) (*PonPort, error) {
for _, pon := range o.Pons {
if pon.ID == id {
return pon, nil
}
}
- return nil, errors.New(fmt.Sprintf("Cannot find PonPort with id %d in OLT %d", id, o.ID))
+ return nil, fmt.Errorf("Cannot find PonPort with id %d in OLT %d", id, o.ID)
}
-func (o OltDevice) getNniById(id uint32) (*NniPort, error) {
+func (o *OltDevice) getNniById(id uint32) (*NniPort, error) {
for _, nni := range o.Nnis {
if nni.ID == id {
return nni, nil
}
}
- return nil, errors.New(fmt.Sprintf("Cannot find NniPort with id %d in OLT %d", id, o.ID))
+ return nil, fmt.Errorf("Cannot find NniPort with id %d in OLT %d", id, o.ID)
}
func (o *OltDevice) sendAlarmIndication(alarmInd *openolt.AlarmIndication, stream openolt.Openolt_EnableIndicationServer) {
@@ -662,11 +658,11 @@
case OltIndication:
msg, _ := message.Data.(OltIndicationMessage)
if msg.OperState == UP {
- o.InternalState.Event("enable")
- o.OperState.Event("enable")
+ _ = o.InternalState.Event("enable")
+ _ = o.OperState.Event("enable")
} else if msg.OperState == DOWN {
- o.InternalState.Event("disable")
- o.OperState.Event("disable")
+ _ = o.InternalState.Event("disable")
+ _ = o.OperState.Event("disable")
}
o.sendOltIndication(msg, stream)
case AlarmIndication:
@@ -789,7 +785,7 @@
}
// returns an ONU with a given Serial Number
-func (o OltDevice) FindOnuBySn(serialNumber string) (*Onu, error) {
+func (o *OltDevice) FindOnuBySn(serialNumber string) (*Onu, error) {
// TODO this function can be a performance bottleneck when we have many ONUs,
// memoizing it will remove the bottleneck
for _, pon := range o.Pons {
@@ -800,11 +796,11 @@
}
}
- return &Onu{}, errors.New(fmt.Sprintf("cannot-find-onu-by-serial-number-%s", serialNumber))
+ return &Onu{}, fmt.Errorf("cannot-find-onu-by-serial-number-%s", serialNumber)
}
// returns an ONU with a given interface/Onu Id
-func (o OltDevice) FindOnuById(intfId uint32, onuId uint32) (*Onu, error) {
+func (o *OltDevice) FindOnuById(intfId uint32, onuId uint32) (*Onu, error) {
// TODO this function can be a performance bottleneck when we have many ONUs,
// memoizing it will remove the bottleneck
for _, pon := range o.Pons {
@@ -816,11 +812,11 @@
}
}
}
- return &Onu{}, errors.New(fmt.Sprintf("cannot-find-onu-by-id-%v-%v", intfId, onuId))
+ return &Onu{}, fmt.Errorf("cannot-find-onu-by-id-%v-%v", intfId, onuId)
}
// returns an ONU with a given Mac Address
-func (o OltDevice) FindOnuByMacAddress(mac net.HardwareAddr) (*Onu, error) {
+func (o *OltDevice) FindOnuByMacAddress(mac net.HardwareAddr) (*Onu, error) {
// TODO this function can be a performance bottleneck when we have many ONUs,
// memoizing it will remove the bottleneck
for _, pon := range o.Pons {
@@ -831,12 +827,12 @@
}
}
- return &Onu{}, errors.New(fmt.Sprintf("cannot-find-onu-by-mac-address-%s", mac))
+ return &Onu{}, fmt.Errorf("cannot-find-onu-by-mac-address-%s", mac)
}
// GRPC Endpoints
-func (o OltDevice) ActivateOnu(context context.Context, onu *openolt.Onu) (*openolt.Empty, error) {
+func (o *OltDevice) ActivateOnu(context context.Context, onu *openolt.Onu) (*openolt.Empty, error) {
oltLogger.WithFields(log.Fields{
"OnuSn": onuSnToString(onu.SerialNumber),
}).Info("Received ActivateOnu call from VOLTHA")
@@ -866,12 +862,12 @@
return new(openolt.Empty), nil
}
-func (o OltDevice) DeactivateOnu(context.Context, *openolt.Onu) (*openolt.Empty, error) {
+func (o *OltDevice) DeactivateOnu(context.Context, *openolt.Onu) (*openolt.Empty, error) {
oltLogger.Error("DeactivateOnu not implemented")
return new(openolt.Empty), nil
}
-func (o OltDevice) DeleteOnu(_ context.Context, onu *openolt.Onu) (*openolt.Empty, error) {
+func (o *OltDevice) DeleteOnu(_ context.Context, onu *openolt.Onu) (*openolt.Empty, error) {
oltLogger.WithFields(log.Fields{
"IntfId": onu.IntfId,
"OnuId": onu.OnuId,
@@ -910,7 +906,7 @@
return new(openolt.Empty), nil
}
-func (o OltDevice) DisableOlt(context.Context, *openolt.Empty) (*openolt.Empty, error) {
+func (o *OltDevice) DisableOlt(context.Context, *openolt.Empty) (*openolt.Empty, error) {
// NOTE when we disable the OLT should we disable NNI, PONs and ONUs altogether?
oltLogger.WithFields(log.Fields{
"oltId": o.ID,
@@ -945,7 +941,7 @@
return new(openolt.Empty), nil
}
-func (o OltDevice) DisablePonIf(_ context.Context, intf *openolt.Interface) (*openolt.Empty, error) {
+func (o *OltDevice) DisablePonIf(_ context.Context, intf *openolt.Interface) (*openolt.Empty, error) {
oltLogger.Infof("DisablePonIf request received for PON %d", intf.IntfId)
ponID := intf.GetIntfId()
pon, _ := o.GetPonById(intf.IntfId)
@@ -981,7 +977,7 @@
return nil
}
-func (o OltDevice) EnablePonIf(_ context.Context, intf *openolt.Interface) (*openolt.Empty, error) {
+func (o *OltDevice) EnablePonIf(_ context.Context, intf *openolt.Interface) (*openolt.Empty, error) {
oltLogger.Infof("EnablePonIf request received for PON %d", intf.IntfId)
ponID := intf.GetIntfId()
pon, _ := o.GetPonById(intf.IntfId)
@@ -1010,7 +1006,7 @@
return new(openolt.Empty), nil
}
-func (o OltDevice) FlowAdd(ctx context.Context, flow *openolt.Flow) (*openolt.Empty, error) {
+func (o *OltDevice) FlowAdd(ctx context.Context, flow *openolt.Flow) (*openolt.Empty, error) {
oltLogger.WithFields(log.Fields{
"IntfId": flow.AccessIntfId,
"OnuId": flow.OnuId,
@@ -1078,7 +1074,7 @@
}
// FlowRemove request from VOLTHA
-func (o OltDevice) FlowRemove(_ context.Context, flow *openolt.Flow) (*openolt.Empty, error) {
+func (o *OltDevice) FlowRemove(_ context.Context, flow *openolt.Flow) (*openolt.Empty, error) {
oltLogger.WithFields(log.Fields{
"FlowId": flow.FlowId,
@@ -1150,7 +1146,7 @@
return new(openolt.Empty), nil
}
-func (o OltDevice) HeartbeatCheck(context.Context, *openolt.Empty) (*openolt.Heartbeat, error) {
+func (o *OltDevice) HeartbeatCheck(context.Context, *openolt.Empty) (*openolt.Heartbeat, error) {
res := openolt.Heartbeat{HeartbeatSignature: uint32(time.Now().Unix())}
oltLogger.WithFields(log.Fields{
"signature": res.HeartbeatSignature,
@@ -1168,10 +1164,10 @@
}
}
}
- return nil, errors.New(fmt.Sprintf("Cannot find Onu by flowId %d", flowId))
+ return nil, fmt.Errorf("Cannot find Onu by flowId %d", flowId)
}
-func (o OltDevice) GetDeviceInfo(context.Context, *openolt.Empty) (*openolt.DeviceInfo, error) {
+func (o *OltDevice) GetDeviceInfo(context.Context, *openolt.Empty) (*openolt.DeviceInfo, error) {
oltLogger.WithFields(log.Fields{
"oltId": o.ID,
@@ -1198,7 +1194,7 @@
return devinfo, nil
}
-func (o OltDevice) OmciMsgOut(ctx context.Context, omci_msg *openolt.OmciMsg) (*openolt.Empty, error) {
+func (o *OltDevice) OmciMsgOut(ctx context.Context, omci_msg *openolt.OmciMsg) (*openolt.Empty, error) {
pon, err := o.GetPonById(omci_msg.IntfId)
if err != nil {
oltLogger.WithFields(log.Fields{
@@ -1236,7 +1232,7 @@
return new(openolt.Empty), nil
}
-func (o OltDevice) OnuPacketOut(ctx context.Context, onuPkt *openolt.OnuPacket) (*openolt.Empty, error) {
+func (o *OltDevice) OnuPacketOut(ctx context.Context, onuPkt *openolt.OnuPacket) (*openolt.Empty, error) {
pon, err := o.GetPonById(onuPkt.IntfId)
if err != nil {
oltLogger.WithFields(log.Fields{
@@ -1261,7 +1257,7 @@
}).Tracef("Received OnuPacketOut")
rawpkt := gopacket.NewPacket(onuPkt.Pkt, layers.LayerTypeEthernet, gopacket.Default)
- pktType, err := packetHandlers.IsEapolOrDhcp(rawpkt)
+ pktType, _ := packetHandlers.IsEapolOrDhcp(rawpkt)
msg := Message{
Type: OnuPacketOut,
@@ -1277,16 +1273,16 @@
return new(openolt.Empty), nil
}
-func (o OltDevice) Reboot(context.Context, *openolt.Empty) (*openolt.Empty, error) {
+func (o *OltDevice) Reboot(context.Context, *openolt.Empty) (*openolt.Empty, error) {
oltLogger.WithFields(log.Fields{
"oltId": o.ID,
}).Info("Shutting down")
publishEvent("OLT-reboot-received", -1, -1, "")
- go o.RestartOLT()
+ go func() { _ = o.RestartOLT() }()
return new(openolt.Empty), nil
}
-func (o OltDevice) ReenableOlt(context.Context, *openolt.Empty) (*openolt.Empty, error) {
+func (o *OltDevice) ReenableOlt(context.Context, *openolt.Empty) (*openolt.Empty, error) {
oltLogger.WithFields(log.Fields{
"oltId": o.ID,
}).Info("Received ReenableOlt request from VOLTHA")
@@ -1317,40 +1313,40 @@
return new(openolt.Empty), nil
}
-func (o OltDevice) UplinkPacketOut(context context.Context, packet *openolt.UplinkPacket) (*openolt.Empty, error) {
+func (o *OltDevice) UplinkPacketOut(context context.Context, packet *openolt.UplinkPacket) (*openolt.Empty, error) {
pkt := gopacket.NewPacket(packet.Pkt, layers.LayerTypeEthernet, gopacket.Default)
- o.Nnis[0].sendNniPacket(pkt) // FIXME we are assuming we have only one NNI
+ _ = o.Nnis[0].sendNniPacket(pkt) // FIXME we are assuming we have only one NNI
// NOTE should we return an error if sendNniPakcet fails?
return new(openolt.Empty), nil
}
-func (o OltDevice) CollectStatistics(context.Context, *openolt.Empty) (*openolt.Empty, error) {
+func (o *OltDevice) CollectStatistics(context.Context, *openolt.Empty) (*openolt.Empty, error) {
oltLogger.Error("CollectStatistics not implemented")
return new(openolt.Empty), nil
}
-func (o OltDevice) GetOnuInfo(context context.Context, packet *openolt.Onu) (*openolt.OnuIndication, error) {
+func (o *OltDevice) GetOnuInfo(context context.Context, packet *openolt.Onu) (*openolt.OnuIndication, error) {
oltLogger.Error("GetOnuInfo not implemented")
return new(openolt.OnuIndication), nil
}
-func (o OltDevice) GetPonIf(context context.Context, packet *openolt.Interface) (*openolt.IntfIndication, error) {
+func (o *OltDevice) GetPonIf(context context.Context, packet *openolt.Interface) (*openolt.IntfIndication, error) {
oltLogger.Error("GetPonIf not implemented")
return new(openolt.IntfIndication), nil
}
-func (s OltDevice) CreateTrafficQueues(context.Context, *tech_profile.TrafficQueues) (*openolt.Empty, error) {
+func (s *OltDevice) CreateTrafficQueues(context.Context, *tech_profile.TrafficQueues) (*openolt.Empty, error) {
oltLogger.Info("received CreateTrafficQueues")
return new(openolt.Empty), nil
}
-func (s OltDevice) RemoveTrafficQueues(context.Context, *tech_profile.TrafficQueues) (*openolt.Empty, error) {
+func (s *OltDevice) RemoveTrafficQueues(context.Context, *tech_profile.TrafficQueues) (*openolt.Empty, error) {
oltLogger.Info("received RemoveTrafficQueues")
return new(openolt.Empty), nil
}
-func (s OltDevice) CreateTrafficSchedulers(context context.Context, trafficSchedulers *tech_profile.TrafficSchedulers) (*openolt.Empty, error) {
+func (s *OltDevice) CreateTrafficSchedulers(context context.Context, trafficSchedulers *tech_profile.TrafficSchedulers) (*openolt.Empty, error) {
oltLogger.WithFields(log.Fields{
"OnuId": trafficSchedulers.OnuId,
"IntfId": trafficSchedulers.IntfId,
@@ -1373,7 +1369,7 @@
return new(openolt.Empty), nil
}
-func (s OltDevice) RemoveTrafficSchedulers(context context.Context, trafficSchedulers *tech_profile.TrafficSchedulers) (*openolt.Empty, error) {
+func (s *OltDevice) RemoveTrafficSchedulers(context context.Context, trafficSchedulers *tech_profile.TrafficSchedulers) (*openolt.Empty, error) {
oltLogger.WithFields(log.Fields{
"OnuId": trafficSchedulers.OnuId,
"IntfId": trafficSchedulers.IntfId,
@@ -1397,7 +1393,7 @@
}
// assumes caller has properly formulated an openolt.AlarmIndication
-func (o OltDevice) SendAlarmIndication(context context.Context, ind *openolt.AlarmIndication) error {
+func (o *OltDevice) SendAlarmIndication(context context.Context, ind *openolt.AlarmIndication) error {
msg := Message{
Type: AlarmIndication,
Data: ind,
@@ -1406,21 +1402,3 @@
o.channel <- msg
return nil
}
-
-func getOltIP() net.IP {
- conn, err := net.Dial("udp", "8.8.8.8:80")
- if err != nil {
- oltLogger.Error(err.Error())
- return net.IP{}
- }
- defer func() {
- err := conn.Close()
- if err != nil {
- oltLogger.Error(err.Error())
- }
- }()
-
- localAddr := conn.LocalAddr().(*net.UDPAddr)
-
- return localAddr.IP
-}
diff --git a/internal/bbsim/devices/olt_test.go b/internal/bbsim/devices/olt_test.go
index 747ddf8..8aa0ae6 100644
--- a/internal/bbsim/devices/olt_test.go
+++ b/internal/bbsim/devices/olt_test.go
@@ -17,14 +17,15 @@
package devices
import (
- "github.com/opencord/voltha-protos/v2/go/openolt"
- "gotest.tools/assert"
"net"
"testing"
+
+ "github.com/opencord/voltha-protos/v2/go/openolt"
+ "gotest.tools/assert"
)
-func createMockOlt(numPon int, numOnu int) OltDevice {
- olt := OltDevice{
+func createMockOlt(numPon int, numOnu int) *OltDevice {
+ olt := &OltDevice{
ID: 0,
}
@@ -116,7 +117,7 @@
// Add the flows to onus (to be found)
onu1, _ := olt.FindOnuBySn("BBSM00000303")
flow1 := openolt.Flow{
- FlowId: 64,
+ FlowId: 64,
Classifier: &openolt.Classifier{},
}
msg1 := OnuFlowUpdateMessage{
@@ -128,7 +129,7 @@
onu2, _ := olt.FindOnuBySn("BBSM00000103")
flow2 := openolt.Flow{
- FlowId: 72,
+ FlowId: 72,
Classifier: &openolt.Classifier{},
}
msg2 := OnuFlowUpdateMessage{
@@ -138,10 +139,8 @@
}
onu2.handleFlowAdd(msg2)
-
-
found, err := olt.GetOnuByFlowId(flow1.FlowId)
assert.Equal(t, err, nil)
assert.Equal(t, found.Sn(), onu1.Sn())
-}
\ No newline at end of file
+}
diff --git a/internal/bbsim/devices/onu.go b/internal/bbsim/devices/onu.go
index beb3779..6c53b68 100644
--- a/internal/bbsim/devices/onu.go
+++ b/internal/bbsim/devices/onu.go
@@ -253,11 +253,11 @@
}
},
"before_start_auth": func(e *fsm.Event) {
- if o.EapolFlowReceived == false {
+ if !o.EapolFlowReceived {
e.Cancel(errors.New("cannot-go-to-auth-started-as-eapol-flow-is-missing"))
return
}
- if o.GemPortAdded == false {
+ if !o.GemPortAdded {
e.Cancel(errors.New("cannot-go-to-auth-started-as-gemport-is-missing"))
return
}
@@ -291,12 +291,12 @@
return
}
- if o.DhcpFlowReceived == false {
+ if !o.DhcpFlowReceived {
e.Cancel(errors.New("cannot-go-to-dhcp-started-as-dhcp-flow-is-missing"))
return
}
- if o.GemPortAdded == false {
+ if !o.GemPortAdded {
e.Cancel(errors.New("cannot-go-to-dhcp-started-as-gemport-is-missing"))
return
}
@@ -432,7 +432,7 @@
} else if msg.Type == packetHandlers.DHCP {
// NOTE here we receive packets going from the DHCP Server to the ONU
// for now we expect them to be double-tagged, but ideally the should be single tagged
- dhcp.HandleNextPacket(o.PonPort.Olt.ID, o.ID, o.PonPortID, o.Sn(), o.PortNo, o.HwAddress, o.CTag, o.InternalState, msg.Packet, stream)
+ _ = dhcp.HandleNextPacket(o.PonPort.Olt.ID, o.ID, o.PonPortID, o.Sn(), o.PortNo, o.HwAddress, o.CTag, o.InternalState, msg.Packet, stream)
}
case OnuPacketIn:
// NOTE we only receive BBR packets here.
@@ -449,7 +449,7 @@
if msg.Type == packetHandlers.EAPOL {
eapol.HandleNextPacket(msg.OnuId, msg.IntfId, o.Sn(), o.PortNo, o.InternalState, msg.Packet, stream, client)
} else if msg.Type == packetHandlers.DHCP {
- dhcp.HandleNextBbrPacket(o.ID, o.PonPortID, o.Sn(), o.STag, o.HwAddress, o.DoneChannel, msg.Packet, client)
+ _ = dhcp.HandleNextBbrPacket(o.ID, o.PonPortID, o.Sn(), o.STag, o.HwAddress, o.DoneChannel, msg.Packet, client)
}
case OmciIndication:
msg, _ := message.Data.(OmciIndicationMessage)
@@ -460,13 +460,13 @@
o.sendDhcpFlow(client)
case IGMPMembershipReportV2:
log.Infof("Recieved IGMPMembershipReportV2 message on ONU channel")
- igmp.SendIGMPMembershipReportV2(o.PonPortID, o.ID, o.Sn(), o.PortNo, o.HwAddress, stream)
+ _ = igmp.SendIGMPMembershipReportV2(o.PonPortID, o.ID, o.Sn(), o.PortNo, o.HwAddress, stream)
case IGMPLeaveGroup:
log.Infof("Recieved IGMPLeaveGroupV2 message on ONU channel")
- igmp.SendIGMPLeaveGroupV2(o.PonPortID, o.ID, o.Sn(), o.PortNo, o.HwAddress, stream)
+ _ = igmp.SendIGMPLeaveGroupV2(o.PonPortID, o.ID, o.Sn(), o.PortNo, o.HwAddress, stream)
case IGMPMembershipReportV3:
log.Infof("Recieved IGMPMembershipReportV3 message on ONU channel")
- igmp.SendIGMPMembershipReportV3(o.PonPortID, o.ID, o.Sn(), o.PortNo, o.HwAddress, stream)
+ _ = igmp.SendIGMPMembershipReportV3(o.PonPortID, o.ID, o.Sn(), o.PortNo, o.HwAddress, stream)
default:
onuLogger.Warnf("Received unknown message data %v for type %v in OLT Channel", message.Data, message.Type)
}
@@ -534,14 +534,14 @@
func (o *Onu) handleEAPOLStart(stream openolt.Openolt_EnableIndicationServer) {
log.Infof("Receive StartEAPOL message on ONU Channel")
- eapol.SendEapStart(o.ID, o.PonPortID, o.Sn(), o.PortNo, o.HwAddress, o.InternalState, stream)
+ _ = eapol.SendEapStart(o.ID, o.PonPortID, o.Sn(), o.PortNo, o.HwAddress, o.InternalState, stream)
go func(delay time.Duration) {
time.Sleep(delay)
if (o.InternalState.Current() == "eap_start_sent" ||
o.InternalState.Current() == "eap_response_identity_sent" ||
o.InternalState.Current() == "eap_response_challenge_sent" ||
o.InternalState.Current() == "auth_failed") && common.Options.BBSim.AuthRetry {
- o.InternalState.Event("start_auth")
+ _ = o.InternalState.Event("start_auth")
} else if o.InternalState.Current() == "eap_response_success_received" {
o.Backoff.Reset()
}
@@ -551,13 +551,13 @@
func (o *Onu) handleDHCPStart(stream openolt.Openolt_EnableIndicationServer) {
log.Infof("Receive StartDHCP message on ONU Channel")
// FIXME use id, ponId as SendEapStart
- dhcp.SendDHCPDiscovery(o.PonPort.Olt.ID, o.PonPortID, o.ID, o.Sn(), o.PortNo, o.InternalState, o.HwAddress, o.CTag, stream)
+ _ = dhcp.SendDHCPDiscovery(o.PonPort.Olt.ID, o.PonPortID, o.ID, o.Sn(), o.PortNo, o.InternalState, o.HwAddress, o.CTag, stream)
go func(delay time.Duration) {
time.Sleep(delay)
if (o.InternalState.Current() == "dhcp_discovery_sent" ||
o.InternalState.Current() == "dhcp_request_sent" ||
o.InternalState.Current() == "dhcp_failed") && common.Options.BBSim.DhcpRetry {
- o.InternalState.Event("start_dhcp")
+ _ = o.InternalState.Event("start_dhcp")
} else if o.InternalState.Current() == "dhcp_ack_received" {
o.Backoff.Reset()
}
@@ -728,7 +728,7 @@
// TODO: Implement some delay between the TestResponse and the TestResult
isTest, err := omcilib.IsTestRequest(HexDecode(msg.omciMsg.Pkt))
if (err == nil) && (isTest) {
- o.sendTestResult(msg, stream)
+ _ = o.sendTestResult(msg, stream)
}
}
@@ -803,7 +803,7 @@
// wait for Gem and then start auth
go func() {
for v := range o.GetGemPortChan() {
- if v == true {
+ if v {
if err := o.InternalState.Event("start_auth"); err != nil {
onuLogger.Warnf("Can't go to auth_started: %v", err)
}
@@ -829,8 +829,8 @@
msg.Flow.Classifier.DstPort == uint32(67) &&
(msg.Flow.Classifier.OPbits == 0 || msg.Flow.Classifier.OPbits == 255) {
- if o.Dhcp == true {
- if o.DhcpFlowReceived == false {
+ if o.Dhcp {
+ if !o.DhcpFlowReceived {
// keep track that we received the DHCP Flows
// so that we can transition the state to dhcp_started
// this is needed as a check in case someone trigger DHCP from the CLI
@@ -840,7 +840,7 @@
// wait for Gem and then start DHCP
go func() {
for v := range o.GetGemPortChan() {
- if v == true {
+ if v {
if err := o.InternalState.Event("start_dhcp"); err != nil {
log.Errorf("Can't go to dhcp_started: %v", err)
}
diff --git a/internal/bbsim/devices/onu_flow_test.go b/internal/bbsim/devices/onu_flow_test.go
index e1c801f..4ff33a7 100644
--- a/internal/bbsim/devices/onu_flow_test.go
+++ b/internal/bbsim/devices/onu_flow_test.go
@@ -52,7 +52,7 @@
onu := createMockOnu(1, 1, 900, 900, true, false)
flow := openolt.Flow{
- FlowId: 64,
+ FlowId: 64,
Classifier: &openolt.Classifier{},
}
msg := OnuFlowUpdateMessage{
@@ -491,7 +491,7 @@
onu.FlowIds = []uint32{1, 2, 34, 64, 92}
flow := openolt.Flow{
- FlowId: 64,
+ FlowId: 64,
Classifier: &openolt.Classifier{},
}
msg := OnuFlowUpdateMessage{
@@ -526,7 +526,7 @@
onu.FlowIds = []uint32{64}
flow := openolt.Flow{
- FlowId: 64,
+ FlowId: 64,
Classifier: &openolt.Classifier{},
}
msg := OnuFlowUpdateMessage{
diff --git a/internal/bbsim/devices/onu_indications_test.go b/internal/bbsim/devices/onu_indications_test.go
index 37008a2..433b776 100644
--- a/internal/bbsim/devices/onu_indications_test.go
+++ b/internal/bbsim/devices/onu_indications_test.go
@@ -19,11 +19,12 @@
import (
"context"
"errors"
+ "testing"
+ "time"
+
"github.com/opencord/voltha-protos/v2/go/openolt"
"google.golang.org/grpc"
"gotest.tools/assert"
- "testing"
- "time"
)
type mockStream struct {
@@ -56,9 +57,10 @@
ctx, cancel := context.WithCancel(context.TODO())
go onu.ProcessOnuMessages(ctx, stream, nil)
onu.InternalState.SetState("initialized")
- onu.InternalState.Event("discover")
+ _ = onu.InternalState.Event("discover")
select {
+ default:
case <-time.After(90 * time.Millisecond):
assert.Equal(t, stream.CallCount, 1)
assert.Equal(t, stream.Calls[1].IntfId, onu.PonPortID)
@@ -79,9 +81,10 @@
ctx, cancel := context.WithCancel(context.TODO())
go onu.ProcessOnuMessages(ctx, stream, nil)
onu.InternalState.SetState("initialized")
- onu.InternalState.Event("discover")
+ _ = onu.InternalState.Event("discover")
select {
+ default:
case <-time.After(400 * time.Millisecond):
assert.Equal(t, stream.CallCount, 4)
}
@@ -101,7 +104,7 @@
ctx, cancel := context.WithCancel(context.TODO())
go onu.ProcessOnuMessages(ctx, stream, nil)
onu.InternalState.SetState("initialized")
- onu.InternalState.Event("discover")
+ _ = onu.InternalState.Event("discover")
go func() {
for calls := range stream.channel {
@@ -112,8 +115,8 @@
}()
select {
+ default:
case <-time.After(1 * time.Second):
-
assert.Equal(t, stream.CallCount, 2)
}
cancel()
diff --git a/internal/bbsim/devices/onu_state_machine_test.go b/internal/bbsim/devices/onu_state_machine_test.go
index b2b292b..fdecc3f 100644
--- a/internal/bbsim/devices/onu_state_machine_test.go
+++ b/internal/bbsim/devices/onu_state_machine_test.go
@@ -25,9 +25,9 @@
func Test_Onu_StateMachine_enable(t *testing.T) {
onu := createTestOnu()
assert.Equal(t, onu.InternalState.Current(), "initialized")
- onu.InternalState.Event("discover")
+ _ = onu.InternalState.Event("discover")
assert.Equal(t, onu.InternalState.Current(), "discovered")
- onu.InternalState.Event("enable")
+ _ = onu.InternalState.Event("enable")
assert.Equal(t, onu.InternalState.Current(), "enabled")
}
@@ -41,11 +41,11 @@
onu.EapolFlowReceived = true
onu.GemPortAdded = true
onu.Flows = []FlowKey{
- FlowKey{ID: 1, Direction: "upstream"},
- FlowKey{ID: 2, Direction: "downstream"},
+ {ID: 1, Direction: "upstream"},
+ {ID: 2, Direction: "downstream"},
}
- onu.InternalState.Event("disable")
+ _ = onu.InternalState.Event("disable")
assert.Equal(t, onu.InternalState.Current(), "disabled")
assert.Equal(t, onu.DhcpFlowReceived, false)
@@ -100,7 +100,7 @@
// succeed
onu.EapolFlowReceived = true
onu.GemPortAdded = true
- onu.InternalState.Event("start_auth")
+ _ = onu.InternalState.Event("start_auth")
assert.Equal(t, onu.InternalState.Current(), "auth_started")
}
@@ -113,13 +113,13 @@
onu.InternalState.SetState("auth_started")
assert.Equal(t, onu.InternalState.Current(), "auth_started")
- onu.InternalState.Event("eap_start_sent")
+ _ = onu.InternalState.Event("eap_start_sent")
assert.Equal(t, onu.InternalState.Current(), "eap_start_sent")
- onu.InternalState.Event("eap_response_identity_sent")
+ _ = onu.InternalState.Event("eap_response_identity_sent")
assert.Equal(t, onu.InternalState.Current(), "eap_response_identity_sent")
- onu.InternalState.Event("eap_response_challenge_sent")
+ _ = onu.InternalState.Event("eap_response_challenge_sent")
assert.Equal(t, onu.InternalState.Current(), "eap_response_challenge_sent")
- onu.InternalState.Event("eap_response_success_received")
+ _ = onu.InternalState.Event("eap_response_success_received")
assert.Equal(t, onu.InternalState.Current(), "eap_response_success_received")
// test that we can retrigger EAPOL
@@ -194,7 +194,7 @@
assert.Equal(t, onu.InternalState.Current(), "eap_response_success_received")
// default transition
- onu.InternalState.Event("start_dhcp")
+ _ = onu.InternalState.Event("start_dhcp")
assert.Equal(t, onu.InternalState.Current(), "dhcp_started")
}
@@ -207,11 +207,11 @@
onu.InternalState.SetState("dhcp_started")
assert.Equal(t, onu.InternalState.Current(), "dhcp_started")
- onu.InternalState.Event("dhcp_discovery_sent")
+ _ = onu.InternalState.Event("dhcp_discovery_sent")
assert.Equal(t, onu.InternalState.Current(), "dhcp_discovery_sent")
- onu.InternalState.Event("dhcp_request_sent")
+ _ = onu.InternalState.Event("dhcp_request_sent")
assert.Equal(t, onu.InternalState.Current(), "dhcp_request_sent")
- onu.InternalState.Event("dhcp_ack_received")
+ _ = onu.InternalState.Event("dhcp_ack_received")
assert.Equal(t, onu.InternalState.Current(), "dhcp_ack_received")
// test that we can retrigger DHCP
diff --git a/internal/bbsim/devices/onu_test_helpers.go b/internal/bbsim/devices/onu_test_helpers.go
index b35dff0..5e4b584 100644
--- a/internal/bbsim/devices/onu_test_helpers.go
+++ b/internal/bbsim/devices/onu_test_helpers.go
@@ -19,11 +19,12 @@
import (
"context"
"errors"
+ "net"
+ "time"
+
"github.com/opencord/voltha-protos/v2/go/openolt"
"github.com/opencord/voltha-protos/v2/go/tech_profile"
"google.golang.org/grpc"
- "net"
- "time"
)
type FlowAddSpy struct {
@@ -133,7 +134,7 @@
}
onu := CreateONU(&olt, &pon, 1, 900, 900, false, false, time.Duration(1*time.Millisecond), true)
// NOTE we need this in order to create the OnuChannel
- onu.InternalState.Event("initialize")
+ _ = onu.InternalState.Event("initialize")
onu.DiscoveryRetryDelay = 100 * time.Millisecond
return onu
}
diff --git a/internal/bbsim/devices/pon.go b/internal/bbsim/devices/pon.go
index 225a45f..54301fa 100644
--- a/internal/bbsim/devices/pon.go
+++ b/internal/bbsim/devices/pon.go
@@ -18,7 +18,6 @@
import (
"bytes"
- "errors"
"fmt"
"github.com/looplab/fsm"
@@ -163,7 +162,7 @@
return onu, nil
}
}
- return nil, errors.New(fmt.Sprintf("Cannot find Onu with serial number %d in PonPort %d", sn, p.ID))
+ return nil, fmt.Errorf("Cannot find Onu with serial number %d in PonPort %d", sn, p.ID)
}
func (p PonPort) GetOnuById(id uint32) (*Onu, error) {
@@ -172,7 +171,7 @@
return onu, nil
}
}
- return nil, errors.New(fmt.Sprintf("Cannot find Onu with id %d in PonPort %d", id, p.ID))
+ return nil, fmt.Errorf("Cannot find Onu with id %d in PonPort %d", id, p.ID)
}
// GetNumOfActiveOnus returns number of active ONUs for PON port
diff --git a/internal/bbsim/packetHandlers/packet_tags.go b/internal/bbsim/packetHandlers/packet_tags.go
index ebcb96c..e028adb 100644
--- a/internal/bbsim/packetHandlers/packet_tags.go
+++ b/internal/bbsim/packetHandlers/packet_tags.go
@@ -18,6 +18,7 @@
import (
"errors"
+
"github.com/google/gopacket"
"github.com/google/gopacket/layers"
)
@@ -37,7 +38,7 @@
}
buffer := gopacket.NewSerializeBuffer()
- gopacket.SerializeLayers(
+ _ = gopacket.SerializeLayers(
buffer,
gopacket.SerializeOptions{
FixLengths: false,
@@ -84,7 +85,7 @@
EthernetType: layer.Type,
}
buffer := gopacket.NewSerializeBuffer()
- gopacket.SerializeLayers(buffer, gopacket.SerializeOptions{},
+ _ = gopacket.SerializeLayers(buffer, gopacket.SerializeOptions{},
ethernetLayer,
gopacket.Payload(layer.Payload),
)
@@ -120,9 +121,8 @@
}
func getDot1QLayer(pkt gopacket.Packet) (*layers.Dot1Q, error) {
- dot1q := &layers.Dot1Q{}
if dot1qLayer := pkt.Layer(layers.LayerTypeDot1Q); dot1qLayer != nil {
- dot1q = dot1qLayer.(*layers.Dot1Q)
+ dot1q := dot1qLayer.(*layers.Dot1Q)
return dot1q, nil
}
return nil, errors.New("no-dot1q-layer-in-packet")
diff --git a/internal/bbsim/packetHandlers/packet_tags_test.go b/internal/bbsim/packetHandlers/packet_tags_test.go
index 9ab5112..b2696a6 100644
--- a/internal/bbsim/packetHandlers/packet_tags_test.go
+++ b/internal/bbsim/packetHandlers/packet_tags_test.go
@@ -17,12 +17,13 @@
package packetHandlers_test
import (
+ "net"
+ "testing"
+
"github.com/google/gopacket"
"github.com/google/gopacket/layers"
"github.com/opencord/bbsim/internal/bbsim/packetHandlers"
"gotest.tools/assert"
- "net"
- "testing"
)
func TestPushSingleTag(t *testing.T) {
@@ -37,7 +38,7 @@
}
buffer := gopacket.NewSerializeBuffer()
- gopacket.SerializeLayers(
+ _ = gopacket.SerializeLayers(
buffer,
gopacket.SerializeOptions{
FixLengths: false,
@@ -69,7 +70,7 @@
}
buffer := gopacket.NewSerializeBuffer()
- gopacket.SerializeLayers(
+ _ = gopacket.SerializeLayers(
buffer,
gopacket.SerializeOptions{
FixLengths: false,
@@ -119,7 +120,7 @@
}
buffer := gopacket.NewSerializeBuffer()
- gopacket.SerializeLayers(
+ _ = gopacket.SerializeLayers(
buffer,
gopacket.SerializeOptions{
FixLengths: false,
@@ -136,7 +137,7 @@
t.Logf("Error in PushSingleTag: %v", err)
}
- vlan, err := packetHandlers.GetVlanTag(taggedPkt)
+ vlan, _ := packetHandlers.GetVlanTag(taggedPkt)
assert.Equal(t, vlan, uint16(2580)) // FIXME where dows 2056 comes from??
}
@@ -157,7 +158,7 @@
}
buffer := gopacket.NewSerializeBuffer()
- gopacket.SerializeLayers(
+ _ = gopacket.SerializeLayers(
buffer,
gopacket.SerializeOptions{
FixLengths: false,
diff --git a/internal/bbsim/responders/dhcp/dhcp.go b/internal/bbsim/responders/dhcp/dhcp.go
index 1ce71d6..227ce8e 100644
--- a/internal/bbsim/responders/dhcp/dhcp.go
+++ b/internal/bbsim/responders/dhcp/dhcp.go
@@ -20,6 +20,10 @@
"context"
"errors"
"fmt"
+ "net"
+ "reflect"
+ "strconv"
+
"github.com/google/gopacket"
"github.com/google/gopacket/layers"
"github.com/looplab/fsm"
@@ -28,9 +32,6 @@
omci "github.com/opencord/omci-sim"
"github.com/opencord/voltha-protos/v2/go/openolt"
log "github.com/sirupsen/logrus"
- "net"
- "reflect"
- "strconv"
)
var GetGemPortId = omci.GetGemPortId
@@ -100,7 +101,7 @@
func createDHCPDisc(oltId int, intfId uint32, onuId uint32, macAddress net.HardwareAddr) *layers.DHCPv4 {
dhcpLayer := createDefaultDHCPReq(oltId, intfId, onuId, macAddress)
defaultOpts := createDefaultOpts(intfId, onuId)
- dhcpLayer.Options = append([]layers.DHCPOption{layers.DHCPOption{
+ dhcpLayer.Options = append([]layers.DHCPOption{{
Type: layers.DHCPOptMessageType,
Data: []byte{byte(layers.DHCPMsgTypeDiscover)},
Length: 1,
@@ -179,7 +180,7 @@
DstPort: 67,
}
- udpLayer.SetNetworkLayerForChecksum(ipLayer)
+ _ = udpLayer.SetNetworkLayerForChecksum(ipLayer)
if err := gopacket.SerializeLayers(buffer, options, ethernetLayer, ipLayer, udpLayer, dhcp); err != nil {
dhcpLogger.Error("SerializeLayers")
return nil, err
@@ -253,10 +254,10 @@
}
log.WithFields(log.Fields{
- "OnuId": msg.OnuId,
- "IntfId": msg.IntfId,
+ "OnuId": msg.OnuId,
+ "IntfId": msg.IntfId,
"GemPort": gemid,
- "Type": "DHCP",
+ "Type": "DHCP",
}).Trace("sending-pkt")
data := &openolt.Indication_PktInd{PktInd: &openolt.PacketIndication{
@@ -493,7 +494,7 @@
srcMac, _ := packetHandlers.GetSrcMacAddressFromPacket(pkt)
dstMac, _ := packetHandlers.GetDstMacAddressFromPacket(pkt)
- if isIncoming == true {
+ if isIncoming {
onuPacket := openolt.OnuPacket{
IntfId: ponPortId,
diff --git a/internal/bbsim/responders/dhcp/dhcp_test.go b/internal/bbsim/responders/dhcp/dhcp_test.go
index 03e40b7..ff9b943 100644
--- a/internal/bbsim/responders/dhcp/dhcp_test.go
+++ b/internal/bbsim/responders/dhcp/dhcp_test.go
@@ -18,12 +18,13 @@
import (
"errors"
+ "net"
+ "testing"
+
"github.com/looplab/fsm"
"github.com/opencord/voltha-protos/v2/go/openolt"
"google.golang.org/grpc"
"gotest.tools/assert"
- "net"
- "testing"
)
// MOCKS
@@ -104,15 +105,15 @@
var serialNumber string = "BBSM00000001"
dhcpStateMachine.SetState("dhcp_started")
- updateDhcpFailed(onuId, ponPortId, serialNumber, dhcpStateMachine)
+ _ = updateDhcpFailed(onuId, ponPortId, serialNumber, dhcpStateMachine)
assert.Equal(t, dhcpStateMachine.Current(), "dhcp_failed")
dhcpStateMachine.SetState("dhcp_discovery_sent")
- updateDhcpFailed(onuId, ponPortId, serialNumber, dhcpStateMachine)
+ _ = updateDhcpFailed(onuId, ponPortId, serialNumber, dhcpStateMachine)
assert.Equal(t, dhcpStateMachine.Current(), "dhcp_failed")
dhcpStateMachine.SetState("dhcp_request_sent")
- updateDhcpFailed(onuId, ponPortId, serialNumber, dhcpStateMachine)
+ _ = updateDhcpFailed(onuId, ponPortId, serialNumber, dhcpStateMachine)
assert.Equal(t, dhcpStateMachine.Current(), "dhcp_failed")
dhcpStateMachine.SetState("dhcp_ack_received")
diff --git a/internal/bbsim/responders/eapol/eapol.go b/internal/bbsim/responders/eapol/eapol.go
index 7ee36fc..cd0606e 100644
--- a/internal/bbsim/responders/eapol/eapol.go
+++ b/internal/bbsim/responders/eapol/eapol.go
@@ -20,6 +20,8 @@
"context"
"crypto/md5"
"errors"
+ "net"
+
"github.com/google/gopacket"
"github.com/google/gopacket/layers"
"github.com/looplab/fsm"
@@ -27,7 +29,6 @@
omci "github.com/opencord/omci-sim"
"github.com/opencord/voltha-protos/v2/go/openolt"
log "github.com/sirupsen/logrus"
- "net"
)
var eapolLogger = log.WithFields(log.Fields{
@@ -49,10 +50,10 @@
}
log.WithFields(log.Fields{
- "OnuId": msg.OnuId,
- "IntfId": msg.IntfId,
+ "OnuId": msg.OnuId,
+ "IntfId": msg.IntfId,
"GemPort": gemid,
- "Type": "EAPOL",
+ "Type": "EAPOL",
}).Trace("sending-pkt")
data := &openolt.Indication_PktInd{PktInd: &openolt.PacketIndication{
@@ -141,7 +142,7 @@
EthernetType: layers.EthernetTypeEAPOL,
}
- gopacket.SerializeLayers(buffer, options,
+ _ = gopacket.SerializeLayers(buffer, options,
ethernetLayer,
&layers.EAPOL{Version: eapolVersion, Type: 0, Length: eap.Length},
eap,
@@ -223,7 +224,7 @@
EthernetType: layers.EthernetTypeEAPOL,
}
- gopacket.SerializeLayers(buffer, options,
+ _ = gopacket.SerializeLayers(buffer, options,
ethernetLayer,
&layers.EAPOL{Version: eapolVersion, Type: 1, Length: 0},
)
diff --git a/internal/bbsim/responders/eapol/eapol_test.go b/internal/bbsim/responders/eapol/eapol_test.go
index 0a2051e..9f8ff22 100644
--- a/internal/bbsim/responders/eapol/eapol_test.go
+++ b/internal/bbsim/responders/eapol/eapol_test.go
@@ -18,12 +18,13 @@
import (
"errors"
+ "net"
+ "testing"
+
"github.com/looplab/fsm"
"github.com/opencord/voltha-protos/v2/go/openolt"
"google.golang.org/grpc"
"gotest.tools/assert"
- "net"
- "testing"
)
// MOCKS
@@ -163,19 +164,19 @@
var serialNumber string = "BBSM00000001"
eapolStateMachine.SetState("auth_started")
- updateAuthFailed(onuId, ponPortId, serialNumber, eapolStateMachine)
+ _ = updateAuthFailed(onuId, ponPortId, serialNumber, eapolStateMachine)
assert.Equal(t, eapolStateMachine.Current(), "auth_failed")
eapolStateMachine.SetState("eap_start_sent")
- updateAuthFailed(onuId, ponPortId, serialNumber, eapolStateMachine)
+ _ = updateAuthFailed(onuId, ponPortId, serialNumber, eapolStateMachine)
assert.Equal(t, eapolStateMachine.Current(), "auth_failed")
eapolStateMachine.SetState("eap_response_identity_sent")
- updateAuthFailed(onuId, ponPortId, serialNumber, eapolStateMachine)
+ _ = updateAuthFailed(onuId, ponPortId, serialNumber, eapolStateMachine)
assert.Equal(t, eapolStateMachine.Current(), "auth_failed")
eapolStateMachine.SetState("eap_response_challenge_sent")
- updateAuthFailed(onuId, ponPortId, serialNumber, eapolStateMachine)
+ _ = updateAuthFailed(onuId, ponPortId, serialNumber, eapolStateMachine)
assert.Equal(t, eapolStateMachine.Current(), "auth_failed")
eapolStateMachine.SetState("eap_response_success_received")
diff --git a/internal/bbsim/responders/sadis/sadis.go b/internal/bbsim/responders/sadis/sadis.go
index ac084a5..75a6fd9 100644
--- a/internal/bbsim/responders/sadis/sadis.go
+++ b/internal/bbsim/responders/sadis/sadis.go
@@ -38,10 +38,10 @@
// bandwidthProfiles contains some dummy profiles
var bandwidthProfiles = []*SadisBWPEntry{
- &SadisBWPEntry{ID: "User_Bandwidth1", AIR: 100000, CBS: 10000, CIR: 30000, EBS: 1000, EIR: 100000},
- &SadisBWPEntry{ID: "User_Bandwidth2", AIR: 100000, CBS: 5000, CIR: 100000, EBS: 5000, EIR: 100000},
- &SadisBWPEntry{ID: "User_Bandwidth3", AIR: 100000, CBS: 5000, CIR: 1000000, EBS: 5000, EIR: 1000000},
- &SadisBWPEntry{ID: "Default", AIR: 100000, CBS: 30, CIR: 600, EBS: 30, EIR: 400},
+ {ID: "User_Bandwidth1", AIR: 100000, CBS: 10000, CIR: 30000, EBS: 1000, EIR: 100000},
+ {ID: "User_Bandwidth2", AIR: 100000, CBS: 5000, CIR: 100000, EBS: 5000, EIR: 100000},
+ {ID: "User_Bandwidth3", AIR: 100000, CBS: 5000, CIR: 1000000, EBS: 5000, EIR: 1000000},
+ {ID: "Default", AIR: 100000, CBS: 30, CIR: 600, EBS: 30, EIR: 400},
}
// SadisConfig is the top-level SADIS configuration struct
@@ -97,22 +97,22 @@
}
type SadisUniTagAtt struct {
- PonCTag int `json:"ponCTag, omitempty"`
- PonSTag int `json:"ponSTag, omitempty"`
- TechnologyProfileID int `json:"technologyProfileId, omitempty"`
- UpstreamBandwidthProfile string `json:"upstreamBandwidthProfile, omitempty"`
- DownstreamBandwidthProfile string `json:"downstreamBandwidthProfile, omitempty"`
- IsDhcpRequired bool `json:"isDhcpRequired, omitempty"`
- IsIgmpRequired bool `json:"isIgmpRequired, omitempty"`
+ PonCTag int `json:"ponCTag,omitempty"`
+ PonSTag int `json:"ponSTag,omitempty"`
+ TechnologyProfileID int `json:"technologyProfileId,omitempty"`
+ UpstreamBandwidthProfile string `json:"upstreamBandwidthProfile,omitempty"`
+ DownstreamBandwidthProfile string `json:"downstreamBandwidthProfile,omitempty"`
+ IsDhcpRequired bool `json:"isDhcpRequired,omitempty"`
+ IsIgmpRequired bool `json:"isIgmpRequired,omitempty"`
}
type SadisUniTagDt struct {
- UniTagMatch int `json:"uniTagMatch, omitempty"`
- PonCTag int `json:"ponCTag, omitempty"`
- PonSTag int `json:"ponSTag, omitempty"`
- TechnologyProfileID int `json:"technologyProfileId, omitempty"`
- UpstreamBandwidthProfile string `json:"upstreamBandwidthProfile, omitempty"`
- DownstreamBandwidthProfile string `json:"downstreamBandwidthProfile, omitempty"`
+ UniTagMatch int `json:"uniTagMatch,omitempty"`
+ PonCTag int `json:"ponCTag,omitempty"`
+ PonSTag int `json:"ponSTag,omitempty"`
+ TechnologyProfileID int `json:"technologyProfileId,omitempty"`
+ UpstreamBandwidthProfile string `json:"upstreamBandwidthProfile,omitempty"`
+ DownstreamBandwidthProfile string `json:"downstreamBandwidthProfile,omitempty"`
}
// SADIS BandwithProfile Entry
@@ -256,7 +256,7 @@
if vars["version"] != "v1" && vars["version"] != "v2" {
w.WriteHeader(http.StatusNotFound)
- w.Write([]byte("{}"))
+ _, _ = w.Write([]byte("{}"))
return
}
@@ -265,7 +265,7 @@
sadisJSON, _ := json.Marshal(sadisConf)
sadisLogger.Tracef("SADIS JSON: %s", sadisJSON)
- w.Write([]byte(sadisJSON))
+ _, _ = w.Write([]byte(sadisJSON))
}
@@ -296,7 +296,7 @@
sadisJSON, _ := json.Marshal(sadisConf)
sadisLogger.Tracef("SADIS JSON: %s", sadisJSON)
- w.Write([]byte(sadisJSON))
+ _, _ = w.Write([]byte(sadisJSON))
}
@@ -313,14 +313,14 @@
sadisConf, _ := GetOltEntry(s.olt)
w.WriteHeader(http.StatusOK)
- json.NewEncoder(w).Encode(sadisConf)
+ _ = json.NewEncoder(w).Encode(sadisConf)
return
}
i := strings.Split(vars["ID"], "-") // split ID to get serial number and uni port
if len(i) != 2 {
w.WriteHeader(http.StatusUnprocessableEntity)
- w.Write([]byte("{}"))
+ _, _ = w.Write([]byte("{}"))
sadisLogger.Warnf("Received invalid SADIS SubscriberId: %s", vars["ID"])
return
}
@@ -329,7 +329,7 @@
onu, err := s.olt.FindOnuBySn(sn)
if err != nil {
w.WriteHeader(http.StatusNotFound)
- w.Write([]byte("{}"))
+ _, _ = w.Write([]byte("{}"))
sadisLogger.WithFields(log.Fields{
"OnuSn": sn,
"OnuId": "NA",
@@ -346,10 +346,10 @@
w.WriteHeader(http.StatusOK)
if vars["version"] == "v1" {
sadisConf, _ := GetOnuEntryV1(s.olt, onu, uni)
- json.NewEncoder(w).Encode(sadisConf)
+ _ = json.NewEncoder(w).Encode(sadisConf)
} else if vars["version"] == "v2" {
sadisConf, _ := GetOnuEntryV2(s.olt, onu, uni)
- json.NewEncoder(w).Encode(sadisConf)
+ _ = json.NewEncoder(w).Encode(sadisConf)
}
}
@@ -361,7 +361,7 @@
if vars["version"] != "v1" && vars["version"] != "v2" {
w.WriteHeader(http.StatusNotFound)
- w.Write([]byte("{}"))
+ _, _ = w.Write([]byte("{}"))
return
}
@@ -370,13 +370,13 @@
for _, bwpEntry := range bandwidthProfiles {
if bwpEntry.ID == id {
w.WriteHeader(http.StatusOK)
- json.NewEncoder(w).Encode(bwpEntry)
+ _ = json.NewEncoder(w).Encode(bwpEntry)
return
}
}
w.WriteHeader(http.StatusNotFound)
- w.Write([]byte("{}"))
+ _, _ = w.Write([]byte("{}"))
}
// StartRestServer starts REST server which returns a SADIS configuration for the currently simulated OLT
diff --git a/internal/bbsim/responders/sadis/sadis_test.go b/internal/bbsim/responders/sadis/sadis_test.go
index 59c3874..04e0240 100644
--- a/internal/bbsim/responders/sadis/sadis_test.go
+++ b/internal/bbsim/responders/sadis/sadis_test.go
@@ -26,12 +26,12 @@
"gotest.tools/assert"
)
-func createMockDevices() (devices.OltDevice, devices.Onu) {
- olt := devices.OltDevice{
+func createMockDevices() (*devices.OltDevice, *devices.Onu) {
+ olt := &devices.OltDevice{
ID: 0,
}
- onu := devices.Onu{
+ onu := &devices.Onu{
ID: 1,
PonPortID: 1,
STag: 900,
@@ -50,7 +50,7 @@
uni := "1"
- res, err := GetOnuEntryV1(&olt, &onu, uni)
+ res, err := GetOnuEntryV1(olt, onu, uni)
if err != nil {
t.Fatal(err)
}
@@ -70,7 +70,7 @@
uni := "1"
- res, err := GetOnuEntryV2(&olt, &onu, uni)
+ res, err := GetOnuEntryV2(olt, onu, uni)
if err != nil {
t.Fatal(err)
}
@@ -99,7 +99,7 @@
uni := "1"
- res, err := GetOnuEntryV2(&olt, &onu, uni)
+ res, err := GetOnuEntryV2(olt, onu, uni)
if err != nil {
t.Fatal(err)
}
diff --git a/internal/bbsimctl/commands/completion.go b/internal/bbsimctl/commands/completion.go
index d7ad19f..27811f3 100644
--- a/internal/bbsimctl/commands/completion.go
+++ b/internal/bbsimctl/commands/completion.go
@@ -17,6 +17,7 @@
import (
"fmt"
+
"github.com/jessevdk/go-flags"
"github.com/opencord/bbsim/internal/bbsimctl/completion"
)
@@ -28,7 +29,7 @@
}
func RegisterCompletionCommands(parent *flags.Parser) {
- parent.AddCommand("completion", "generate shell compleition", "Commands to generate shell completion information", &CompletionOptions{})
+ _, _ = parent.AddCommand("completion", "generate shell compleition", "Commands to generate shell completion information", &CompletionOptions{})
}
func (options *BashOptions) Execute(args []string) error {
diff --git a/internal/bbsimctl/commands/config.go b/internal/bbsimctl/commands/config.go
index b05bb5b..c3d8a14 100644
--- a/internal/bbsimctl/commands/config.go
+++ b/internal/bbsimctl/commands/config.go
@@ -19,6 +19,7 @@
import (
"fmt"
+
"github.com/jessevdk/go-flags"
"github.com/opencord/bbsim/internal/bbsimctl/config"
"gopkg.in/yaml.v2"
@@ -45,7 +46,7 @@
type ConfigOptions struct{}
func RegisterConfigCommands(parent *flags.Parser) {
- parent.AddCommand("config", "generate bbsimctl configuration", "Commands to generate bbsimctl configuration", &ConfigOptions{})
+ _, _ = parent.AddCommand("config", "generate bbsimctl configuration", "Commands to generate bbsimctl configuration", &ConfigOptions{})
}
func (options *ConfigOptions) Execute(args []string) error {
diff --git a/internal/bbsimctl/commands/handler.go b/internal/bbsimctl/commands/handler.go
index 3c4b0ff..6b05534 100644
--- a/internal/bbsimctl/commands/handler.go
+++ b/internal/bbsimctl/commands/handler.go
@@ -16,12 +16,13 @@
package commands
import (
+ "io"
+
"github.com/golang/protobuf/proto"
"github.com/jhump/protoreflect/desc"
"github.com/jhump/protoreflect/dynamic"
"google.golang.org/grpc/metadata"
"google.golang.org/grpc/status"
- "io"
)
type RpcEventHandler struct {
@@ -64,7 +65,10 @@
}
for k, v := range fields {
- dmsg.TrySetFieldByName(k, v)
+ err := dmsg.TrySetFieldByName(k, v)
+ if err != nil {
+ return err
+ }
}
delete(h.Fields, dmsg.XXX_MessageName())
diff --git a/internal/bbsimctl/commands/logging.go b/internal/bbsimctl/commands/logging.go
index 42e4771..b9a66b7 100644
--- a/internal/bbsimctl/commands/logging.go
+++ b/internal/bbsimctl/commands/logging.go
@@ -19,6 +19,7 @@
import (
"context"
"fmt"
+
"github.com/jessevdk/go-flags"
pb "github.com/opencord/bbsim/api/bbsim"
"github.com/opencord/bbsim/internal/bbsimctl/config"
@@ -34,7 +35,7 @@
}
func RegisterLoggingCommands(parent *flags.Parser) {
- parent.AddCommand("log", "set bbsim log level", "Commands to set the log level", &LoggingOptions{})
+ _, _ = parent.AddCommand("log", "set bbsim log level", "Commands to set the log level", &LoggingOptions{})
}
func (options *LoggingOptions) Execute(args []string) error {
@@ -59,6 +60,10 @@
logLevel, err := c.SetLogLevel(ctx, &req)
+ if err != nil {
+ log.Fatalf("could not set log level: %v", err)
+ }
+
fmt.Println("New log settings:")
fmt.Println(fmt.Sprintf("\tLevel: %s", logLevel.Level))
fmt.Println(fmt.Sprintf("\tReportCaller: %t", logLevel.Caller))
diff --git a/internal/bbsimctl/commands/olt.go b/internal/bbsimctl/commands/olt.go
index a16edef..5f6747e 100644
--- a/internal/bbsimctl/commands/olt.go
+++ b/internal/bbsimctl/commands/olt.go
@@ -69,7 +69,7 @@
}
func RegisterOltCommands(parser *flags.Parser) {
- parser.AddCommand("olt", "OLT Commands", "Commands to query and manipulate the OLT device", &oltOptions{})
+ _, _ = parser.AddCommand("olt", "OLT Commands", "Commands to query and manipulate the OLT device", &oltOptions{})
}
func getOLT() *pb.Olt {
@@ -103,7 +103,7 @@
// print out
tableFormat := format.Format(DEFAULT_OLT_DEVICE_HEADER_FORMAT)
- tableFormat.Execute(os.Stdout, true, olt)
+ _ = tableFormat.Execute(os.Stdout, true, olt)
return nil
}
@@ -114,7 +114,7 @@
printOltHeader("NNI Ports for", olt)
tableFormat := format.Format(DEFAULT_PORT_HEADER_FORMAT)
- tableFormat.Execute(os.Stdout, true, olt.NNIPorts)
+ _ = tableFormat.Execute(os.Stdout, true, olt.NNIPorts)
return nil
}
@@ -125,7 +125,7 @@
printOltHeader("PON Ports for", olt)
tableFormat := format.Format(DEFAULT_PORT_HEADER_FORMAT)
- tableFormat.Execute(os.Stdout, true, olt.PONPorts)
+ _ = tableFormat.Execute(os.Stdout, true, olt.PONPorts)
return nil
}
diff --git a/internal/bbsimctl/commands/onu.go b/internal/bbsimctl/commands/onu.go
index c331502..771df4c 100644
--- a/internal/bbsimctl/commands/onu.go
+++ b/internal/bbsimctl/commands/onu.go
@@ -109,7 +109,7 @@
}
func RegisterONUCommands(parser *flags.Parser) {
- parser.AddCommand("onu", "ONU Commands", "Commands to query and manipulate ONU devices", &ONUOptions{})
+ _, _ = parser.AddCommand("onu", "ONU Commands", "Commands to query and manipulate ONU devices", &ONUOptions{})
}
func connect() (pb.BBSimClient, *grpc.ClientConn) {
diff --git a/internal/bbsimctl/commands/pon.go b/internal/bbsimctl/commands/pon.go
index 885fb75..332f748 100644
--- a/internal/bbsimctl/commands/pon.go
+++ b/internal/bbsimctl/commands/pon.go
@@ -45,7 +45,7 @@
}
func RegisterPonCommands(parser *flags.Parser) {
- parser.AddCommand("pon", "PON Commands", "Commands to query and manipulate the PON port", &PONOptions{})
+ _, _ = parser.AddCommand("pon", "PON Commands", "Commands to query and manipulate the PON port", &PONOptions{})
}
func (pon *PonPoweronAllOnus) Execute(args []string) error {
diff --git a/internal/common/kafka_utils.go b/internal/common/kafka_utils.go
index 780093a..c999539 100644
--- a/internal/common/kafka_utils.go
+++ b/internal/common/kafka_utils.go
@@ -39,10 +39,6 @@
Timestamp string
}
-type saramaIf interface {
- NewAsyncProducer(addrs []string, conf *sarama.Config) (sarama.AsyncProducer, error)
-}
-
// InitializePublisher initalizes kafka publisher
func InitializePublisher(NewAsyncProducer func([]string, *sarama.Config) (sarama.AsyncProducer, error), oltID int) error {
@@ -68,35 +64,34 @@
func KafkaPublisher(eventChannel chan Event) {
defer log.Debugf("KafkaPublisher stopped")
for {
- select {
- case event := <-eventChannel:
- log.WithFields(log.Fields{
- "EventType": event.EventType,
- "OnuSerial": event.OnuSerial,
- "OltID": event.OltID,
- "IntfID": event.IntfID,
- "OnuID": event.OnuID,
- "EpochTime": event.EpochTime,
- "Timestamp": event.Timestamp,
- }).Trace("Received event on channel")
- jsonEvent, err := json.Marshal(event)
- if err != nil {
- log.Errorf("Failed to get json event %v", err)
- continue
- }
- producer.Input() <- &sarama.ProducerMessage{
- Topic: topic,
- Value: sarama.ByteEncoder(jsonEvent),
- }
- log.WithFields(log.Fields{
- "EventType": event.EventType,
- "OnuSerial": event.OnuSerial,
- "OltID": event.OltID,
- "IntfID": event.IntfID,
- "OnuID": event.OnuID,
- "EpochTime": event.EpochTime,
- "Timestamp": event.Timestamp,
- }).Debug("Event sent on kafka")
+ event := <-eventChannel
+ log.WithFields(log.Fields{
+ "EventType": event.EventType,
+ "OnuSerial": event.OnuSerial,
+ "OltID": event.OltID,
+ "IntfID": event.IntfID,
+ "OnuID": event.OnuID,
+ "EpochTime": event.EpochTime,
+ "Timestamp": event.Timestamp,
+ }).Trace("Received event on channel")
+ jsonEvent, err := json.Marshal(event)
+ if err != nil {
+ log.Errorf("Failed to get json event %v", err)
+ continue
}
+ producer.Input() <- &sarama.ProducerMessage{
+ Topic: topic,
+ Value: sarama.ByteEncoder(jsonEvent),
+ }
+ log.WithFields(log.Fields{
+ "EventType": event.EventType,
+ "OnuSerial": event.OnuSerial,
+ "OltID": event.OltID,
+ "IntfID": event.IntfID,
+ "OnuID": event.OnuID,
+ "EpochTime": event.EpochTime,
+ "Timestamp": event.Timestamp,
+ }).Debug("Event sent on kafka")
}
+
}
diff --git a/internal/common/options.go b/internal/common/options.go
index 6c728fb..5dd1553 100644
--- a/internal/common/options.go
+++ b/internal/common/options.go
@@ -17,7 +17,6 @@
package common
import (
- "errors"
"flag"
"fmt"
"io/ioutil"
@@ -49,7 +48,7 @@
log.WithFields(log.Fields{
"ValidValues": strings.Join(tagAllocationValues[1:], ", "),
}).Errorf("%s-is-not-a-valid-tag-allocation", s)
- return TagAllocation(0), errors.New(fmt.Sprintf("%s-is-not-a-valid-tag-allocation", s))
+ return TagAllocation(0), fmt.Errorf("%s-is-not-a-valid-tag-allocation", s)
}
const (
@@ -80,7 +79,7 @@
log.WithFields(log.Fields{
"ValidValues": strings.Join(sadisFormatValues[1:], ", "),
}).Errorf("%s-is-not-a-valid-sadis-format", s)
- return SadisFormat(0), errors.New(fmt.Sprintf("%s-is-not-a-valid-sadis-format", s))
+ return SadisFormat(0), fmt.Errorf("%s-is-not-a-valid-sadis-format", s)
}
const (
@@ -117,7 +116,7 @@
Technology string `yaml:"technology"`
ID int `yaml:"id"`
OltRebootDelay int `yaml:"reboot_delay"`
- PortStatsInterval int `yaml: "port_stats_interval"`
+ PortStatsInterval int `yaml:"port_stats_interval"`
}
type BBSimConfig struct {
@@ -146,7 +145,7 @@
Events bool `yaml:"enable_events"`
ControlledActivation string `yaml:"controlled_activation"`
EnablePerf bool `yaml:"enable_perf"`
- KafkaEventTopic string `yaml:"kafka_event_topic`
+ KafkaEventTopic string `yaml:"kafka_event_topic"`
}
type BBRConfig struct {