VOL-3344 - Enabled default linters and fixed found issues.
Also disabled govet's variable shadowing check, since this is very useful for isolating multiple "err"ors in a row.
Change-Id: Icd70c723c406c5986b8cfe4535ad7daa0752e48c
diff --git a/internal/pkg/config/common.go b/internal/pkg/config/common.go
deleted file mode 100644
index 1b05963..0000000
--- a/internal/pkg/config/common.go
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Copyright 2020-present Open Networking Foundation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-// Package config Common Logger initialization
-package config
-
-import (
- "github.com/opencord/voltha-lib-go/v3/pkg/log"
-)
-
-var logger log.CLogger
-
-func init() {
- // Setup this package so that it's log level can be modified at run time
- var err error
- logger, err = log.RegisterPackage(log.JSON, log.ErrorLevel, log.Fields{"pkg": "config"})
- if err != nil {
- panic(err)
- }
-}
diff --git a/internal/pkg/core/device_handler.go b/internal/pkg/core/device_handler.go
index aa6e59f..4452b8f 100644
--- a/internal/pkg/core/device_handler.go
+++ b/internal/pkg/core/device_handler.go
@@ -308,16 +308,15 @@
return nil
}
-func (dh *DeviceHandler) updateLocalDevice(ctx context.Context) error {
+func (dh *DeviceHandler) updateLocalDevice(ctx context.Context) {
dh.lockDevice.Lock()
defer dh.lockDevice.Unlock()
device, err := dh.coreProxy.GetDevice(context.TODO(), dh.device.Id, dh.device.Id)
if err != nil || device == nil {
- logger.Errorf(ctx, "device", log.Fields{"device-id": dh.device.Id}, err)
- return olterrors.NewErrNotFound("device", log.Fields{"device-id": dh.device.Id}, err)
+ logger.Errorf(ctx, "device-not-found", log.Fields{"device-id": dh.device.Id}, err)
+ return
}
dh.device = device
- return nil
}
// nolint: gocyclo
@@ -480,13 +479,13 @@
switch indication.Data.(type) {
case *oop.Indication_OltInd:
if err := dh.handleOltIndication(ctx, indication.GetOltInd()); err != nil {
- olterrors.NewErrAdapter("handle-indication-error", log.Fields{"type": "olt", "device-id": dh.device.Id}, err).Log()
+ _ = olterrors.NewErrAdapter("handle-indication-error", log.Fields{"type": "olt", "device-id": dh.device.Id}, err).Log()
}
case *oop.Indication_IntfInd:
intfInd := indication.GetIntfInd()
go func() {
if err := dh.addPort(ctx, intfInd.GetIntfId(), voltha.Port_PON_OLT, intfInd.GetOperState()); err != nil {
- olterrors.NewErrAdapter("handle-indication-error", log.Fields{"type": "interface", "device-id": dh.device.Id}, err).Log()
+ _ = olterrors.NewErrAdapter("handle-indication-error", log.Fields{"type": "interface", "device-id": dh.device.Id}, err).Log()
}
}()
logger.Infow(ctx, "received-interface-indication", log.Fields{"InterfaceInd": intfInd, "device-id": dh.device.Id})
@@ -495,16 +494,18 @@
if intfOperInd.GetType() == "nni" {
go func() {
if err := dh.addPort(ctx, intfOperInd.GetIntfId(), voltha.Port_ETHERNET_NNI, intfOperInd.GetOperState()); err != nil {
- olterrors.NewErrAdapter("handle-indication-error", log.Fields{"type": "interface-oper-nni", "device-id": dh.device.Id}, err).Log()
+ _ = olterrors.NewErrAdapter("handle-indication-error", log.Fields{"type": "interface-oper-nni", "device-id": dh.device.Id}, err).Log()
}
}()
- dh.resourceMgr.AddNNIToKVStore(ctx, intfOperInd.GetIntfId())
+ if err := dh.resourceMgr.AddNNIToKVStore(ctx, intfOperInd.GetIntfId()); err != nil {
+ logger.Warn(ctx, err)
+ }
} else if intfOperInd.GetType() == "pon" {
// TODO: Check what needs to be handled here for When PON PORT down, ONU will be down
// Handle pon port update
go func() {
if err := dh.addPort(ctx, intfOperInd.GetIntfId(), voltha.Port_PON_OLT, intfOperInd.GetOperState()); err != nil {
- olterrors.NewErrAdapter("handle-indication-error", log.Fields{"type": "interface-oper-pon", "device-id": dh.device.Id}, err).Log()
+ _ = olterrors.NewErrAdapter("handle-indication-error", log.Fields{"type": "interface-oper-pon", "device-id": dh.device.Id}, err).Log()
}
}()
go dh.eventMgr.oltIntfOperIndication(ctx, indication.GetIntfOperInd(), dh.device.Id, raisedTs)
@@ -518,7 +519,7 @@
sn := dh.stringifySerialNumber(onuDiscInd.SerialNumber)
go func() {
if err := dh.onuDiscIndication(ctx, onuDiscInd, sn); err != nil {
- olterrors.NewErrAdapter("handle-indication-error", log.Fields{"type": "onu-discovery", "device-id": dh.device.Id}, err).Log()
+ _ = olterrors.NewErrAdapter("handle-indication-error", log.Fields{"type": "onu-discovery", "device-id": dh.device.Id}, err).Log()
}
}()
case *oop.Indication_OnuInd:
@@ -526,7 +527,7 @@
logger.Infow(ctx, "received-onu-indication", log.Fields{"OnuInd": onuInd, "device-id": dh.device.Id})
go func() {
if err := dh.onuIndication(ctx, onuInd); err != nil {
- olterrors.NewErrAdapter("handle-indication-error", log.Fields{"type": "onu", "device-id": dh.device.Id}, err).Log()
+ _ = olterrors.NewErrAdapter("handle-indication-error", log.Fields{"type": "onu", "device-id": dh.device.Id}, err).Log()
}
}()
case *oop.Indication_OmciInd:
@@ -534,7 +535,7 @@
logger.Debugw(ctx, "received-omci-indication", log.Fields{"intf-id": omciInd.IntfId, "onu-id": omciInd.OnuId, "device-id": dh.device.Id})
go func() {
if err := dh.omciIndication(ctx, omciInd); err != nil {
- olterrors.NewErrAdapter("handle-indication-error", log.Fields{"type": "omci", "device-id": dh.device.Id}, err).Log()
+ _ = olterrors.NewErrAdapter("handle-indication-error", log.Fields{"type": "omci", "device-id": dh.device.Id}, err).Log()
}
}()
case *oop.Indication_PktInd:
@@ -560,7 +561,7 @@
go func() {
if err := dh.handlePacketIndication(ctx, pktInd); err != nil {
- olterrors.NewErrAdapter("handle-indication-error", log.Fields{"type": "packet", "device-id": dh.device.Id}, err).Log()
+ _ = olterrors.NewErrAdapter("handle-indication-error", log.Fields{"type": "packet", "device-id": dh.device.Id}, err).Log()
}
}()
case *oop.Indication_PortStats:
@@ -624,7 +625,7 @@
err := dh.AdapterProxy.SendInterAdapterMessage(ctx, &onuInd, ic.InterAdapterMessageType_ONU_IND_REQUEST,
"openolt", onuDevice.Type, onuDevice.Id, onuDevice.ProxyAddress.DeviceId, "")
if err != nil {
- olterrors.NewErrCommunication("inter-adapter-send-failed", log.Fields{
+ _ = olterrors.NewErrCommunication("inter-adapter-send-failed", log.Fields{
"source": "openolt",
"onu-indicator": onuInd,
"device-type": onuDevice.Type,
@@ -695,7 +696,7 @@
// Start reading indications
go func() {
if err = dh.readIndications(ctx); err != nil {
- olterrors.NewErrAdapter("indication-read-failure", log.Fields{"device-id": dh.device.Id}, err).LogAt(log.ErrorLevel)
+ _ = olterrors.NewErrAdapter("indication-read-failure", log.Fields{"device-id": dh.device.Id}, err).LogAt(log.ErrorLevel)
}
}()
return nil
@@ -718,7 +719,7 @@
// Start reading indications
go func() {
if err := dh.readIndications(ctx); err != nil {
- olterrors.NewErrAdapter("read-indications-failure", log.Fields{"device-id": dh.device.Id}, err).Log()
+ _ = olterrors.NewErrAdapter("read-indications-failure", log.Fields{"device-id": dh.device.Id}, err).Log()
}
}()
go dh.updateLocalDevice(ctx)
@@ -843,8 +844,8 @@
dh.transitionMap.Handle(ctx, DeviceInit)
// Now, set the initial PM configuration for that device
- if err := dh.coreProxy.DevicePMConfigUpdate(nil, dh.metrics.ToPmConfigs()); err != nil {
- olterrors.NewErrAdapter("error-updating-performance-metrics", log.Fields{"device-id": device.Id}, err).LogAt(log.ErrorLevel)
+ if err := dh.coreProxy.DevicePMConfigUpdate(ctx, dh.metrics.ToPmConfigs()); err != nil {
+ _ = olterrors.NewErrAdapter("error-updating-performance-metrics", log.Fields{"device-id": device.Id}, err).LogAt(log.ErrorLevel)
}
go startHeartbeatCheck(ctx, dh)
@@ -1073,7 +1074,11 @@
alarmInd.IntfId = onuInCache.(*OnuDevice).intfID
alarmInd.OnuId = onuInCache.(*OnuDevice).onuID
alarmInd.LosStatus = statusCheckOff
- go dh.eventMgr.onuAlarmIndication(ctx, &alarmInd, onuInCache.(*OnuDevice).deviceID, raisedTs)
+ go func() {
+ if err := dh.eventMgr.onuAlarmIndication(ctx, &alarmInd, onuInCache.(*OnuDevice).deviceID, raisedTs); err != nil {
+ logger.Debugw(ctx, "indication-failed", log.Fields{"error": err})
+ }
+ }()
}
return true
})
@@ -1132,7 +1137,9 @@
"pon-intf-id": ponintfid,
"serial-number": sn}, err)
}
- dh.eventMgr.OnuDiscoveryIndication(ctx, onuDiscInd, dh.device.Id, onuDevice.Id, onuID, sn, time.Now().UnixNano())
+ if err := dh.eventMgr.OnuDiscoveryIndication(ctx, onuDiscInd, dh.device.Id, onuDevice.Id, onuID, sn, time.Now().UnixNano()); err != nil {
+ logger.Warnw(ctx, "discovery-indication-failed", log.Fields{"error": err})
+ }
logger.Infow(ctx, "onu-child-device-added",
log.Fields{"onuDevice": onuDevice,
"sn": sn,
@@ -1156,13 +1163,13 @@
log.Fields{"onu": onuDev,
"sn": sn})
- if err = dh.coreProxy.DeviceStateUpdate(ctx, onuDevice.Id, common.ConnectStatus_REACHABLE, common.OperStatus_DISCOVERED); err != nil {
+ if err := dh.coreProxy.DeviceStateUpdate(ctx, onuDevice.Id, common.ConnectStatus_REACHABLE, common.OperStatus_DISCOVERED); err != nil {
return olterrors.NewErrAdapter("failed-to-update-device-state", log.Fields{
"device-id": onuDevice.Id,
"serial-number": sn}, err)
}
logger.Infow(ctx, "onu-discovered-reachable", log.Fields{"device-id": onuDevice.Id, "sn": sn})
- if err = dh.activateONU(ctx, onuDiscInd.IntfId, int64(onuID), onuDiscInd.SerialNumber, sn); err != nil {
+ if err := dh.activateONU(ctx, onuDiscInd.IntfId, int64(onuID), onuDiscInd.SerialNumber, sn); err != nil {
return olterrors.NewErrAdapter("onu-activation-failed", log.Fields{
"device-id": onuDevice.Id,
"serial-number": sn}, err)
@@ -1191,7 +1198,7 @@
//If ONU id is discovered before then use GetDevice to get onuDevice because it is cheaper.
foundInCache = true
errFields["onu-id"] = onuInCache.(*OnuDevice).deviceID
- onuDevice, err = dh.coreProxy.GetDevice(nil, dh.device.Id, onuInCache.(*OnuDevice).deviceID)
+ onuDevice, err = dh.coreProxy.GetDevice(ctx, dh.device.Id, onuInCache.(*OnuDevice).deviceID)
} else {
//If ONU not found in adapter cache then we have to use GetChildDevice to get onuDevice
if serialNumber != "" {
@@ -1235,7 +1242,6 @@
}
func (dh *DeviceHandler) updateOnuStates(ctx context.Context, onuDevice *voltha.Device, onuInd *oop.OnuIndication) error {
- ctx = context.TODO()
logger.Debugw(ctx, "onu-indication-for-state", log.Fields{"onuIndication": onuInd, "device-id": onuDevice.Id, "operStatus": onuDevice.OperStatus, "adminStatus": onuDevice.AdminState})
if onuInd.AdminState == "down" || onuInd.OperState == "down" {
// The ONU has gone admin_state "down" or oper_state "down" - we expect the ONU to send discovery again
@@ -1384,7 +1390,7 @@
logger.Debugf(ctx, "frequency-updated")
}
- if pmConfigs.Grouped == false {
+ if !pmConfigs.Grouped {
metrics := dh.metrics.GetSubscriberMetrics()
for _, m := range pmConfigs.Metrics {
metrics[m.Name].Enabled = m.Enabled
@@ -1649,7 +1655,7 @@
}
return nil
}
-func (dh *DeviceHandler) cleanupDeviceResources(ctx context.Context) error {
+func (dh *DeviceHandler) cleanupDeviceResources(ctx context.Context) {
if dh.resourceMgr != nil {
noOfPonPorts := dh.resourceMgr.DevInfo.GetPonPorts()
var ponPort uint32
@@ -1657,9 +1663,9 @@
var onuGemData []rsrcMgr.OnuGemInfo
err := dh.resourceMgr.ResourceMgrs[ponPort].GetOnuGemInfo(ctx, ponPort, &onuGemData)
if err != nil {
- return olterrors.NewErrNotFound("onu", log.Fields{
+ _ = olterrors.NewErrNotFound("onu", log.Fields{
"device-id": dh.device.Id,
- "pon-port": ponPort}, err)
+ "pon-port": ponPort}, err).Log()
}
for _, onu := range onuGemData {
onuID := make([]uint32, 1)
@@ -1689,7 +1695,11 @@
}
/* Clear the resource pool for each PON port in the background */
- go dh.resourceMgr.Delete(ctx)
+ go func() {
+ if err := dh.resourceMgr.Delete(ctx); err != nil {
+ logger.Debug(ctx, err)
+ }
+ }()
}
/*Delete ONU map for the device*/
@@ -1703,8 +1713,6 @@
dh.discOnus.Delete(key)
return true
})
-
- return nil
}
//RebootDevice reboots the given device
@@ -1913,15 +1921,15 @@
func (dh *DeviceHandler) updateStateUnreachable(ctx context.Context) {
device, err := dh.coreProxy.GetDevice(ctx, dh.device.Id, dh.device.Id)
if err != nil || device == nil {
- olterrors.NewErrNotFound("device", log.Fields{"device-id": dh.device.Id}, err).Log()
+ _ = olterrors.NewErrNotFound("device", log.Fields{"device-id": dh.device.Id}, err).Log()
}
if device.ConnectStatus == voltha.ConnectStatus_REACHABLE {
if err = dh.coreProxy.DeviceStateUpdate(ctx, dh.device.Id, voltha.ConnectStatus_UNREACHABLE, voltha.OperStatus_UNKNOWN); err != nil {
- olterrors.NewErrAdapter("device-state-update-failed", log.Fields{"device-id": dh.device.Id}, err).LogAt(log.ErrorLevel)
+ _ = olterrors.NewErrAdapter("device-state-update-failed", log.Fields{"device-id": dh.device.Id}, err).LogAt(log.ErrorLevel)
}
if err = dh.coreProxy.PortsStateUpdate(ctx, dh.device.Id, 0, voltha.OperStatus_UNKNOWN); err != nil {
- olterrors.NewErrAdapter("port-update-failed", log.Fields{"device-id": dh.device.Id}, err).Log()
+ _ = olterrors.NewErrAdapter("port-update-failed", log.Fields{"device-id": dh.device.Id}, err).Log()
}
go dh.cleanupDeviceResources(ctx)
@@ -2279,15 +2287,6 @@
dh.onus.Store(onuKey, onuDevice)
}
-// setOnuITUPonAlarmConfig sets the parameters in the openolt agent for raising the ONU ITU PON alarms.
-func (dh *DeviceHandler) setOnuITUPonAlarmConfig(ctx context.Context, config *oop.OnuItuPonAlarm) error {
- if _, err := dh.Client.OnuItuPonAlarmSet(context.Background(), config); err != nil {
- return err
- }
- logger.Debugw(ctx, "onu-itu-pon-alarm-config-set-successful", log.Fields{"config": config})
- return nil
-}
-
func (dh *DeviceHandler) getExtValue(device *voltha.Device, value voltha.ValueType_Type) (*voltha.ReturnValues, error) {
var err error
var sn *oop.SerialNumber
diff --git a/internal/pkg/core/device_handler_test.go b/internal/pkg/core/device_handler_test.go
index 1507f2f..6ec5ddd 100644
--- a/internal/pkg/core/device_handler_test.go
+++ b/internal/pkg/core/device_handler_test.go
@@ -25,13 +25,12 @@
"testing"
"time"
- "github.com/opencord/voltha-lib-go/v3/pkg/pmmetrics"
-
"github.com/golang/protobuf/ptypes"
"github.com/golang/protobuf/ptypes/any"
"github.com/opencord/voltha-lib-go/v3/pkg/db"
fu "github.com/opencord/voltha-lib-go/v3/pkg/flows"
"github.com/opencord/voltha-lib-go/v3/pkg/log"
+ "github.com/opencord/voltha-lib-go/v3/pkg/pmmetrics"
ponrmgr "github.com/opencord/voltha-lib-go/v3/pkg/ponresourcemanager"
"github.com/opencord/voltha-openolt-adapter/internal/pkg/olterrors"
"github.com/opencord/voltha-openolt-adapter/internal/pkg/resourcemanager"
@@ -567,7 +566,8 @@
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
- tt.devicehandler.sendProxiedMessage(ctx, tt.args.onuDevice, tt.args.omciMsg)
+ _ = tt.devicehandler.sendProxiedMessage(ctx, tt.args.onuDevice, tt.args.omciMsg)
+ //TODO: actually verify test cases
})
}
}
@@ -591,7 +591,8 @@
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
- tt.devicehandler.SendPacketInToCore(context.Background(), tt.args.logicalPort, tt.args.packetPayload)
+ _ = tt.devicehandler.SendPacketInToCore(context.Background(), tt.args.logicalPort, tt.args.packetPayload)
+ //TODO: actually verify test cases
})
}
}
@@ -613,7 +614,6 @@
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
-
if err := tt.devicehandler.DisableDevice(context.Background(), tt.args.device); (err != nil) != tt.wantErr {
t.Errorf("DeviceHandler.DisableDevice() error = %v, wantErr %v", err, tt.wantErr)
}
@@ -784,7 +784,8 @@
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
- tt.devicehandler.addPort(context.Background(), tt.args.intfID, tt.args.portType, tt.args.state)
+ _ = tt.devicehandler.addPort(context.Background(), tt.args.intfID, tt.args.portType, tt.args.state)
+ //TODO: actually verify test cases
})
}
}
@@ -829,7 +830,9 @@
dh := newMockDeviceHandler()
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
- dh.handleOltIndication(ctx, tt.args.oltIndication)
+ if err := dh.handleOltIndication(ctx, tt.args.oltIndication); err != nil {
+ t.Error(err)
+ }
})
}
}
@@ -856,7 +859,9 @@
//dh.AdoptDevice(tt.args.device)
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
- tt.devicehandler.postInit(ctx)
+ if err := tt.devicehandler.postInit(ctx); err != nil {
+ t.Error(err)
+ }
})
}
}
@@ -882,11 +887,10 @@
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
-
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
- tt.devicehandler.activateONU(ctx, tt.args.intfID, tt.args.onuID,
- tt.args.serialNum, tt.args.serialNumber)
+ _ = tt.devicehandler.activateONU(ctx, tt.args.intfID, tt.args.onuID, tt.args.serialNum, tt.args.serialNumber)
+ //TODO: actually verify test cases
})
}
}
@@ -989,6 +993,7 @@
defer cancel()
if err := tt.devicehandler.doStateDown(ctx); (err != nil) != tt.wantErr {
t.Logf("DeviceHandler.doStateDown() error = %v", err)
+ //TODO: should fail this test case (Errorf) if result is not as expected
}
})
}
@@ -1059,7 +1064,8 @@
t.Run(tt.name, func(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
- tt.devicehandler.onuDiscIndication(ctx, tt.args.onuDiscInd, tt.args.sn)
+ _ = tt.devicehandler.onuDiscIndication(ctx, tt.args.onuDiscInd, tt.args.sn)
+ //TODO: actually verify test cases
})
}
}
@@ -1117,7 +1123,8 @@
t.Run(tt.name, func(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
- tt.devicehandler.readIndications(ctx)
+ _ = tt.devicehandler.readIndications(ctx)
+ // TODO: actually verify test cases
})
}
}
diff --git a/internal/pkg/core/olt_platform.go b/internal/pkg/core/olt_platform.go
index 4b36102..897f4cb 100644
--- a/internal/pkg/core/olt_platform.go
+++ b/internal/pkg/core/olt_platform.go
@@ -19,6 +19,7 @@
import (
"context"
+
"github.com/opencord/voltha-lib-go/v3/pkg/flows"
"github.com/opencord/voltha-lib-go/v3/pkg/log"
"github.com/opencord/voltha-openolt-adapter/internal/pkg/olterrors"
@@ -93,19 +94,17 @@
bitsForONUID = 8
// Number of bits for PON ID
bitsForPONID = 8
- // Number of bits to differentiate between UNI and NNI Logical Port
- bitsForUNINNIDiff = 1
- //MaxOnusPerPon is Max number of ONUs on any PON port
+ // MaxOnusPerPon is Max number of ONUs on any PON port
MaxOnusPerPon = (1 << bitsForONUID)
- //MaxPonsPerOlt is Max number of PON ports on any OLT
+ // MaxPonsPerOlt is Max number of PON ports on any OLT
MaxPonsPerOlt = (1 << bitsForPONID)
- //MaxUnisPerOnu is the Max number of UNI ports on any ONU
+ // MaxUnisPerOnu is the Max number of UNI ports on any ONU
MaxUnisPerOnu = (1 << bitsForUniID)
- //Bit position where the differentiation bit is located
+ // Bit position where the differentiation bit is located
nniUniDiffPos = (bitsForUniID + bitsForONUID + bitsForPONID)
- //Bit position where the marker for PON port type of OF port is present
+ // Bit position where the marker for PON port type of OF port is present
ponIntfMarkerPos = 28
- //Value of marker used to distinguish PON port type of OF port
+ // Value of marker used to distinguish PON port type of OF port
ponIntfMarkerValue = 0x2
// Number of bits for NNI ID
bitsforNNIID = 20
diff --git a/internal/pkg/core/olt_platform_test.go b/internal/pkg/core/olt_platform_test.go
index 71414c1..7661869 100644
--- a/internal/pkg/core/olt_platform_test.go
+++ b/internal/pkg/core/olt_platform_test.go
@@ -200,8 +200,7 @@
type args struct {
intfID uint32
}
- var input uint32
- input = uint32(2*math.Pow(2, 28)) | 3
+ input := uint32(2*math.Pow(2, 28)) | 3
tests := []struct {
name string
args args
diff --git a/internal/pkg/core/openolt.go b/internal/pkg/core/openolt.go
index fe33876..702a1a2 100644
--- a/internal/pkg/core/openolt.go
+++ b/internal/pkg/core/openolt.go
@@ -87,18 +87,6 @@
return nil
}
-func sendResponse(ctx context.Context, ch chan interface{}, result interface{}) {
- if ctx.Err() == nil {
- // Returned response only of the ctx has not been canceled/timeout/etc
- // Channel is automatically closed when a context is Done
- ch <- result
- logger.Debugw(ctx, "sendResponse", log.Fields{"result": result})
- } else {
- // Should the transaction be reverted back?
- logger.Debugw(ctx, "sendResponse-context-error", log.Fields{"context-error": ctx.Err()})
- }
-}
-
func (oo *OpenOLT) addDeviceHandlerToMap(agent *DeviceHandler) {
oo.lockDeviceHandlersMap.Lock()
defer oo.lockDeviceHandlersMap.Unlock()
@@ -122,18 +110,6 @@
return nil
}
-//createDeviceTopic returns
-func (oo *OpenOLT) createDeviceTopic(ctx context.Context, device *voltha.Device) error {
- logger.Infow(ctx, "create-device-topic", log.Fields{"deviceId": device.Id})
- defaultTopic := oo.kafkaICProxy.GetDefaultTopic()
- deviceTopic := kafka.Topic{Name: defaultTopic.Name + "_" + device.Id}
- // TODO for the offset
- if err := oo.kafkaICProxy.SubscribeWithDefaultRequestHandler(ctx, deviceTopic, 0); err != nil {
- return olterrors.NewErrAdapter("subscribe-for-device-topic-failed", log.Fields{"device-topic": deviceTopic}, err)
- }
- return nil
-}
-
// Adopt_device creates a new device handler if not present already and then adopts the device
func (oo *OpenOLT) Adopt_device(ctx context.Context, device *voltha.Device) error {
if device == nil {
diff --git a/internal/pkg/core/openolt_eventmgr.go b/internal/pkg/core/openolt_eventmgr.go
index 6f1fd68..8a58303 100644
--- a/internal/pkg/core/openolt_eventmgr.go
+++ b/internal/pkg/core/openolt_eventmgr.go
@@ -45,8 +45,6 @@
onuSignalDegradeEvent = "ONU_SIGNAL_DEGRADE"
onuDriftOfWindowEvent = "ONU_DRIFT_OF_WINDOW"
onuActivationFailEvent = "ONU_ACTIVATION_FAIL"
- onuProcessingErrorEvent = "ONU_PROCESSING_ERROR"
- onuTiwiEvent = "ONU_TRANSMISSION_WARNING"
onuLossOmciEvent = "ONU_LOSS_OF_OMCI_CHANNEL"
onuLossOfKeySyncEvent = "ONU_LOSS_OF_KEY_SYNC"
onuLossOfFrameEvent = "ONU_LOSS_OF_FRAME"
@@ -61,20 +59,6 @@
)
const (
- pon = voltha.EventSubCategory_PON
- olt = voltha.EventSubCategory_OLT
- ont = voltha.EventSubCategory_ONT
- onu = voltha.EventSubCategory_ONU
- nni = voltha.EventSubCategory_NNI
- service = voltha.EventCategory_SERVICE
- security = voltha.EventCategory_SECURITY
- equipment = voltha.EventCategory_EQUIPMENT
- processing = voltha.EventCategory_PROCESSING
- environment = voltha.EventCategory_ENVIRONMENT
- communication = voltha.EventCategory_COMMUNICATION
-)
-
-const (
// statusCheckOn represents status check On
statusCheckOn = "on"
// statusCheckOff represents status check Off
@@ -134,7 +118,7 @@
// ProcessEvents is function to process and publish OpenOLT event
// nolint: gocyclo
-func (em *OpenOltEventMgr) ProcessEvents(ctx context.Context, alarmInd *oop.AlarmIndication, deviceID string, raisedTs int64) error {
+func (em *OpenOltEventMgr) ProcessEvents(ctx context.Context, alarmInd *oop.AlarmIndication, deviceID string, raisedTs int64) {
var err error
switch alarmInd.Data.(type) {
case *oop.AlarmIndication_LosInd:
@@ -192,9 +176,8 @@
err = olterrors.NewErrInvalidValue(log.Fields{"indication-type": alarmInd}, nil)
}
if err != nil {
- return olterrors.NewErrCommunication("publish-message", log.Fields{"indication-type": alarmInd}, err).Log()
+ _ = olterrors.NewErrCommunication("publish-message", log.Fields{"indication-type": alarmInd}, err).LogAt(log.WarnLevel)
}
- return nil
}
// oltUpDownIndication handles Up and Down state of an OLT
@@ -212,7 +195,7 @@
de.DeviceEventName = fmt.Sprintf("%s_%s", oltIndicationDown, "CLEAR_EVENT")
}
/* Send event to KAFKA */
- if err := em.eventProxy.SendDeviceEvent(ctx, &de, communication, olt, raisedTs); err != nil {
+ if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_OLT, raisedTs); err != nil {
return olterrors.NewErrCommunication("send-olt-event", log.Fields{"device-id": deviceID}, err)
}
logger.Debugw(ctx, "olt-updown-event-sent-to-kafka", log.Fields{})
@@ -233,7 +216,7 @@
de.ResourceId = oltDeviceID
de.DeviceEventName = fmt.Sprintf("%s_%s", onuDiscoveryEvent, "RAISE_EVENT")
/* Send event to KAFKA */
- if err := em.eventProxy.SendDeviceEvent(ctx, &de, equipment, pon, raisedTs); err != nil {
+ if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_EQUIPMENT, voltha.EventSubCategory_PON, raisedTs); err != nil {
return olterrors.NewErrCommunication("send-onu-discovery-event",
log.Fields{
"serial-number": serialNumber,
@@ -282,7 +265,7 @@
de.DeviceEventName = fmt.Sprintf("%s_%s", oltLosEvent, "CLEAR_EVENT")
}
/* Send event to KAFKA */
- if err := em.eventProxy.SendDeviceEvent(ctx, &de, communication, olt, raisedTs); err != nil {
+ if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_OLT, raisedTs); err != nil {
return err
}
logger.Debugw(ctx, "olt-los-event-sent-to-kafka", log.Fields{"intf-id": oltLos.IntfId})
@@ -316,7 +299,7 @@
de.ResourceId = deviceID
de.DeviceEventName = fmt.Sprintf("%s_%s", onuDyingGaspEvent, "EVENT")
/* Send event to KAFKA */
- if err := em.eventProxy.SendDeviceEvent(ctx, &de, communication, pon, raisedTs); err != nil {
+ if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_PON, raisedTs); err != nil {
return err
}
logger.Debugw(ctx, "onu-dying-gasp-event-sent-to-kafka", log.Fields{"intf-id": dgi.IntfId})
@@ -433,7 +416,7 @@
}
/* Send event to KAFKA */
- if err := em.eventProxy.SendDeviceEvent(ctx, &de, communication, onu, raisedTs); err != nil {
+ if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_ONU, raisedTs); err != nil {
return err
}
logger.Debugw(ctx, "onu-los-event-sent-to-kafka", log.Fields{"onu-id": onuAlarm.OnuId, "intf-id": onuAlarm.IntfId})
@@ -455,7 +438,7 @@
de.ResourceId = deviceID
de.DeviceEventName = fmt.Sprintf("%s_%s", onuActivationFailEvent, "RAISE_EVENT")
/* Send event to KAFKA */
- if err := em.eventProxy.SendDeviceEvent(ctx, &de, equipment, pon, raisedTs); err != nil {
+ if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_EQUIPMENT, voltha.EventSubCategory_PON, raisedTs); err != nil {
return err
}
logger.Debugw(ctx, "onu-activation-failure-event-sent-to-kafka", log.Fields{"onu-id": oaf.OnuId, "intf-id": oaf.IntfId})
@@ -480,7 +463,7 @@
de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOmciEvent, "CLEAR_EVENT")
}
/* Send event to KAFKA */
- if err := em.eventProxy.SendDeviceEvent(ctx, &de, communication, pon, raisedTs); err != nil {
+ if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_PON, raisedTs); err != nil {
return err
}
logger.Debugw(ctx, "onu-loss-of-omci-channel-event-sent-to-kafka", log.Fields{"onu-id": onuLossOmci.OnuId, "intf-id": onuLossOmci.IntfId})
@@ -507,7 +490,7 @@
de.DeviceEventName = fmt.Sprintf("%s_%s", onuDriftOfWindowEvent, "CLEAR_EVENT")
}
/* Send event to KAFKA */
- if err := em.eventProxy.SendDeviceEvent(ctx, &de, communication, pon, raisedTs); err != nil {
+ if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_PON, raisedTs); err != nil {
return err
}
logger.Debugw(ctx, "onu-drift-of-window-event-sent-to-kafka", log.Fields{"onu-id": onuDriftWindow.OnuId, "intf-id": onuDriftWindow.IntfId})
@@ -533,7 +516,7 @@
de.DeviceEventName = fmt.Sprintf("%s_%s", onuSignalDegradeEvent, "CLEAR_EVENT")
}
/* Send event to KAFKA */
- if err := em.eventProxy.SendDeviceEvent(ctx, &de, communication, pon, raisedTs); err != nil {
+ if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_PON, raisedTs); err != nil {
return err
}
logger.Debugw(ctx, "onu-signal-degrade-event-sent-to-kafka", log.Fields{"onu-id": onuSignalDegrade.OnuId, "intf-id": onuSignalDegrade.IntfId})
@@ -558,7 +541,7 @@
de.DeviceEventName = fmt.Sprintf("%s_%s", onuSignalsFailEvent, "CLEAR_EVENT")
}
/* Send event to KAFKA */
- if err := em.eventProxy.SendDeviceEvent(ctx, &de, communication, pon, raisedTs); err != nil {
+ if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_PON, raisedTs); err != nil {
return err
}
logger.Debugw(ctx, "onu-signals-fail-event-sent-to-kafka", log.Fields{"onu-id": onuSignalsFail.OnuId, "intf-id": onuSignalsFail.IntfId})
@@ -583,7 +566,7 @@
de.DeviceEventName = fmt.Sprintf("%s_%s", onuStartupFailEvent, "CLEAR_EVENT")
}
/* Send event to KAFKA */
- if err := em.eventProxy.SendDeviceEvent(ctx, &de, communication, pon, raisedTs); err != nil {
+ if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_PON, raisedTs); err != nil {
return err
}
logger.Debugw(ctx, "onu-startup-fail-event-sent-to-kafka", log.Fields{"onu-id": onuStartupFail.OnuId, "intf-id": onuStartupFail.IntfId})
@@ -608,7 +591,7 @@
}
/* Send event to KAFKA */
- if err := em.eventProxy.SendDeviceEvent(ctx, &de, security, onu, raisedTs); err != nil {
+ if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_SECURITY, voltha.EventSubCategory_ONU, raisedTs); err != nil {
return err
}
logger.Debugw(ctx, "onu-loss-of-key-sync-event-sent-to-kafka", log.Fields{"onu-id": onuLOKI.OnuId, "intf-id": onuLOKI.IntfId})
@@ -616,13 +599,13 @@
}
// oltIntfOperIndication handles Up and Down state of an OLT PON ports
-func (em *OpenOltEventMgr) oltIntfOperIndication(ctx context.Context, ifindication *oop.IntfOperIndication, deviceID string, raisedTs int64) error {
+func (em *OpenOltEventMgr) oltIntfOperIndication(ctx context.Context, ifindication *oop.IntfOperIndication, deviceID string, raisedTs int64) {
portNo := IntfIDToPortNo(ifindication.IntfId, voltha.Port_PON_OLT)
if port, err := em.handler.coreProxy.GetDevicePort(ctx, deviceID, portNo); err != nil {
logger.Warnw(ctx, "Error while fetching port object", log.Fields{"device-id": deviceID, "error": err})
} else if port.AdminState != common.AdminState_ENABLED {
logger.Debugw(ctx, "port-disable/enable-event-not-generated--the-port-is-not-enabled-by-operator", log.Fields{"device-id": deviceID, "port": port})
- return nil
+ return
}
/* Populating event context */
context := map[string]string{ContextOltPonIntfOperState: ifindication.GetOperState()}
@@ -637,11 +620,11 @@
de.DeviceEventName = fmt.Sprintf("%s_%s", ponIntfDownIndiction, "CLEAR_EVENT")
}
/* Send event to KAFKA */
- if err := em.eventProxy.SendDeviceEvent(ctx, &de, communication, olt, raisedTs); err != nil {
- return olterrors.NewErrCommunication("send-olt-intf-oper-status-event", log.Fields{"device-id": deviceID, "intf-id": ifindication.IntfId, "oper-state": ifindication.OperState}, err).Log()
+ if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_OLT, raisedTs); err != nil {
+ _ = olterrors.NewErrCommunication("send-olt-intf-oper-status-event", log.Fields{"device-id": deviceID, "intf-id": ifindication.IntfId, "oper-state": ifindication.OperState}, err).LogAt(log.WarnLevel)
+ return
}
logger.Debug(ctx, "sent-olt-intf-oper-status-event-to-kafka")
- return nil
}
func (em *OpenOltEventMgr) onuDeactivationFailureIndication(ctx context.Context, onuDFI *oop.OnuDeactivationFailureIndication, deviceID string, raisedTs int64) error {
@@ -661,7 +644,7 @@
de.DeviceEventName = fmt.Sprintf("%s_%s", onuDeactivationFailureEvent, "CLEAR_EVENT")
}
/* Send event to KAFKA */
- if err := em.eventProxy.SendDeviceEvent(ctx, &de, equipment, onu, raisedTs); err != nil {
+ if err := em.eventProxy.SendDeviceEvent(ctx, &de, voltha.EventCategory_EQUIPMENT, voltha.EventSubCategory_ONU, raisedTs); err != nil {
return err
}
logger.Debugw(ctx, "onu-deactivation-failure-event-sent-to-kafka", log.Fields{"onu-id": onuDFI.OnuId, "intf-id": onuDFI.IntfId})
@@ -688,7 +671,7 @@
de.DeviceEventName = fmt.Sprintf("%s_%s", onuRemoteDefectIndication, "CLEAR_EVENT")
}
/* Send event to KAFKA */
- if err := em.eventProxy.SendDeviceEvent(ctx, de, equipment, onu, raisedTs); err != nil {
+ if err := em.eventProxy.SendDeviceEvent(ctx, de, voltha.EventCategory_EQUIPMENT, voltha.EventSubCategory_ONU, raisedTs); err != nil {
return err
}
logger.Debugw(ctx, "onu-remote-defect-event-sent-to-kafka", log.Fields{"onu-id": onuID, "intf-id": intfID})
@@ -738,7 +721,7 @@
de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOfGEMChannelDelineationEvent, "CLEAR_EVENT")
}
/* Send event to KAFKA */
- if err := em.eventProxy.SendDeviceEvent(ctx, de, communication, onu, raisedTs); err != nil {
+ if err := em.eventProxy.SendDeviceEvent(ctx, de, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_ONU, raisedTs); err != nil {
return err
}
logger.Debugw(ctx, "onu-loss-of-gem-channel-delineation-event-sent-to-kafka", log.Fields{"onu-id": onuGCD.OnuId, "intf-id": onuGCD.IntfId})
@@ -763,7 +746,7 @@
de.DeviceEventName = fmt.Sprintf("%s_%s", onuPhysicalEquipmentErrorEvent, "CLEAR_EVENT")
}
/* Send event to KAFKA */
- if err := em.eventProxy.SendDeviceEvent(ctx, de, equipment, onu, raisedTs); err != nil {
+ if err := em.eventProxy.SendDeviceEvent(ctx, de, voltha.EventCategory_EQUIPMENT, voltha.EventSubCategory_ONU, raisedTs); err != nil {
return err
}
logger.Debugw(ctx, "onu-physical-equipment-error-event-sent-to-kafka", log.Fields{"onu-id": onuErr.OnuId, "intf-id": onuErr.IntfId})
@@ -789,7 +772,7 @@
de.DeviceEventName = fmt.Sprintf("%s_%s", onuLossOfAcknowledgementEvent, "CLEAR_EVENT")
}
/* Send event to KAFKA */
- if err := em.eventProxy.SendDeviceEvent(ctx, de, equipment, onu, raisedTs); err != nil {
+ if err := em.eventProxy.SendDeviceEvent(ctx, de, voltha.EventCategory_EQUIPMENT, voltha.EventSubCategory_ONU, raisedTs); err != nil {
return err
}
logger.Debugw(ctx, "onu-physical-equipment-error-event-sent-to-kafka", log.Fields{"onu-id": onuLOA.OnuId, "intf-id": onuLOA.IntfId})
@@ -816,7 +799,7 @@
de.DeviceEventName = fmt.Sprintf("%s_%s", onuDifferentialReachExceededEvent, "CLEAR_EVENT")
}
/* Send event to KAFKA */
- if err := em.eventProxy.SendDeviceEvent(ctx, de, equipment, onu, raisedTs); err != nil {
+ if err := em.eventProxy.SendDeviceEvent(ctx, de, voltha.EventCategory_EQUIPMENT, voltha.EventSubCategory_ONU, raisedTs); err != nil {
return err
}
log.Debugw("onu-differential-reach-exceeded–event-sent-to-kafka", log.Fields{"onu-id": onuDRE.OnuId, "intf-id": onuDRE.IntfId})
diff --git a/internal/pkg/core/openolt_eventmgr_test.go b/internal/pkg/core/openolt_eventmgr_test.go
index fbc3539..84dff0b 100644
--- a/internal/pkg/core/openolt_eventmgr_test.go
+++ b/internal/pkg/core/openolt_eventmgr_test.go
@@ -19,11 +19,12 @@
import (
"context"
- "github.com/opencord/voltha-openolt-adapter/pkg/mocks"
- oop "github.com/opencord/voltha-protos/v3/go/openolt"
"sync"
"testing"
"time"
+
+ "github.com/opencord/voltha-openolt-adapter/pkg/mocks"
+ oop "github.com/opencord/voltha-protos/v3/go/openolt"
)
func mockEventMgr() *OpenOltEventMgr {
@@ -158,7 +159,8 @@
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
- em.OnuDiscoveryIndication(context.Background(), tt.args.onuDisc, tt.args.oltDeviceID, tt.args.onuDeviceID, tt.args.OnuID, tt.args.serialNumber, tt.args.raisedTs)
+ _ = em.OnuDiscoveryIndication(context.Background(), tt.args.onuDisc, tt.args.oltDeviceID, tt.args.onuDeviceID, tt.args.OnuID, tt.args.serialNumber, tt.args.raisedTs)
+ //TODO: actually verify test cases
})
}
}
diff --git a/internal/pkg/core/openolt_flowmgr.go b/internal/pkg/core/openolt_flowmgr.go
index f2fec23..6ad1b60 100644
--- a/internal/pkg/core/openolt_flowmgr.go
+++ b/internal/pkg/core/openolt_flowmgr.go
@@ -264,22 +264,7 @@
return &flowMgr
}
-func (f *OpenOltFlowMgr) generateStoredFlowID(ctx context.Context, flowID uint32, direction string) (uint64, error) {
- if direction == Upstream {
- logger.Debugw(ctx, "upstream-flow-shifting-id", log.Fields{"device-id": f.deviceHandler.device.Id})
- return 0x1<<15 | uint64(flowID), nil
- } else if direction == Downstream {
- logger.Debugw(ctx, "downstream-flow-not-shifting-id", log.Fields{"device-id": f.deviceHandler.device.Id})
- return uint64(flowID), nil
- } else if direction == Multicast {
- logger.Debugw(ctx, "multicast-flow-shifting-id", log.Fields{"device-id": f.deviceHandler.device.Id})
- return 0x2<<15 | uint64(flowID), nil
- } else {
- return 0, olterrors.NewErrInvalidValue(log.Fields{"direction": direction}, nil).Log()
- }
-}
-
-func (f *OpenOltFlowMgr) registerFlow(ctx context.Context, flowFromCore *ofp.OfpFlowStats, deviceFlow *openoltpb2.Flow) {
+func (f *OpenOltFlowMgr) registerFlow(ctx context.Context, flowFromCore *ofp.OfpFlowStats, deviceFlow *openoltpb2.Flow) error {
logger.Debugw(ctx, "registering-flow-for-device ",
log.Fields{
"flow": flowFromCore,
@@ -292,7 +277,7 @@
flowIDList = appendUnique(flowIDList, deviceFlow.FlowId)
f.flowsUsedByGemPort[gemPK] = flowIDList
// update the flowids for a gem to the KVstore
- f.resourceMgr.UpdateFlowIDsForGem(ctx, uint32(deviceFlow.AccessIntfId), uint32(deviceFlow.GemportId), flowIDList)
+ return f.resourceMgr.UpdateFlowIDsForGem(ctx, uint32(deviceFlow.AccessIntfId), uint32(deviceFlow.GemportId), flowIDList)
}
func (f *OpenOltFlowMgr) divideAndAddFlow(ctx context.Context, intfID uint32, onuID uint32, uniID uint32, portNo uint32,
@@ -316,7 +301,7 @@
// only create tcont/gemports if there is actually an onu id. otherwise BAL throws an error. Usually this
// is because the flow is an NNI flow and there would be no onu resources associated with it
// TODO: properly deal with NNI flows
- if onuID <= 0 {
+ if onuID == 0 {
logger.Errorw(ctx, "no-onu-id-for-flow",
log.Fields{
"port-no": portNo,
@@ -566,9 +551,10 @@
servicePriority: multicastQueuePerPonPort.Priority,
}
//also store the queue info in kv store
- f.resourceMgr.AddMcastQueueForIntf(ctx, sq.intfID,
- multicastQueuePerPonPort.GemportId,
- multicastQueuePerPonPort.Priority)
+ if err := f.resourceMgr.AddMcastQueueForIntf(ctx, sq.intfID, multicastQueuePerPonPort.GemportId, multicastQueuePerPonPort.Priority); err != nil {
+ logger.Errorw(ctx, "failed-to-add-mcast-queue", log.Fields{"error": err})
+ return err
+ }
logger.Infow(ctx, "multicast-queues-successfully-updated", log.Fields{"device-id": f.deviceHandler.device.Id})
}
@@ -725,7 +711,9 @@
"device-id": f.deviceHandler.device.Id})
return 0, nil, nil
}
- f.resourceMgr.UpdateTechProfileIDForOnu(ctx, intfID, onuID, uniID, TpID)
+ if err := f.resourceMgr.UpdateTechProfileIDForOnu(ctx, intfID, onuID, uniID, TpID); err != nil {
+ logger.Warnw(ctx, "failed-to-update-tech-profile-id", log.Fields{"error": err})
+ }
} else {
logger.Debugw(ctx, "tech-profile-instance-already-exist-for-given port-name",
log.Fields{
@@ -1469,7 +1457,7 @@
for _, tpID := range tpIDList {
if err := f.DeleteTechProfileInstance(ctx, intfID, onuID, uniID, uniPortName, tpID); err != nil {
- olterrors.NewErrAdapter("delete-tech-profile-failed", log.Fields{"device-id": f.deviceHandler.device.Id}, err).Log()
+ _ = olterrors.NewErrAdapter("delete-tech-profile-failed", log.Fields{"device-id": f.deviceHandler.device.Id}, err).Log()
// return err
// We should continue to delete tech-profile instances for other TP IDs
}
@@ -1619,7 +1607,10 @@
}
if deviceFlow.GemportId != -1 {
// No need to register the flow if it is a trap on nni flow.
- f.registerFlow(ctx, logicalFlow, deviceFlow)
+ if err := f.registerFlow(ctx, logicalFlow, deviceFlow); err != nil {
+ logger.Errorw(ctx, "failed-to-register-flow", log.Fields{"err": err})
+ return err
+ }
}
logger.Infow(ctx, "flow-added-to-device-successfully ",
log.Fields{
@@ -1823,22 +1814,6 @@
return onuDevice, nil
}
-func findNextFlow(ctx context.Context, flow *ofp.OfpFlowStats) *ofp.OfpFlowStats {
- logger.Info(ctx, "unimplemented-flow %v", flow)
- return nil
-}
-
-func (f *OpenOltFlowMgr) clearFlowsAndSchedulerForLogicalPort(ctx context.Context, childDevice *voltha.Device, logicalPort *voltha.LogicalPort) {
- logger.Info(ctx, "unimplemented-device %v, logicalport %v", childDevice, logicalPort)
-}
-
-func (f *OpenOltFlowMgr) decodeStoredID(id uint64) (uint64, string) {
- if id>>15 == 0x1 {
- return id & 0x7fff, Upstream
- }
- return id, Downstream
-}
-
func (f *OpenOltFlowMgr) sendDeleteGemPortToChild(ctx context.Context, intfID uint32, onuID uint32, uniID uint32, gemPortID uint32, tpPath string) error {
onuDev, err := f.getOnuDevice(ctx, intfID, onuID)
if err != nil {
@@ -2017,7 +1992,7 @@
// For ex: Case of HSIA where same flow is shared
// between DS and US.
if err := f.updateFlowInfoToKVStore(ctx, int32(Intf), int32(onuID), int32(uniID), flowID, &updatedFlows); err != nil {
- olterrors.NewErrPersistence("update", "flow", flowID,
+ _ = olterrors.NewErrPersistence("update", "flow", flowID,
log.Fields{
"flow": updatedFlows,
"device-id": f.deviceHandler.device.Id}, err).Log()
@@ -2083,7 +2058,9 @@
// everytime flowsUsedByGemPort cache is updated the same should be updated
// in kv store by calling UpdateFlowIDsForGem
f.flowsUsedByGemPort[gemPK] = flowIDs
- f.resourceMgr.UpdateFlowIDsForGem(ctx, Intf, uint32(gemPortID), flowIDs)
+ if err := f.resourceMgr.UpdateFlowIDsForGem(ctx, Intf, uint32(gemPortID), flowIDs); err != nil {
+ return err
+ }
break
}
}
@@ -2122,10 +2099,18 @@
case *tp.TechProfile:
ok, _ := f.isTechProfileUsedByAnotherGem(ctx, Intf, uint32(onuID), uint32(uniID), tpID, techprofileInst, uint32(gemPortID))
if !ok {
- f.resourceMgr.RemoveTechProfileIDForOnu(ctx, Intf, uint32(onuID), uint32(uniID), tpID)
- f.DeleteTechProfileInstance(ctx, Intf, uint32(onuID), uint32(uniID), "", tpID)
- f.RemoveSchedulerQueues(ctx, schedQueue{direction: tp_pb.Direction_UPSTREAM, intfID: Intf, onuID: uint32(onuID), uniID: uint32(uniID), tpID: tpID, uniPort: portNum, tpInst: techprofileInst})
- f.RemoveSchedulerQueues(ctx, schedQueue{direction: tp_pb.Direction_DOWNSTREAM, intfID: Intf, onuID: uint32(onuID), uniID: uint32(uniID), tpID: tpID, uniPort: portNum, tpInst: techprofileInst})
+ if err := f.resourceMgr.RemoveTechProfileIDForOnu(ctx, Intf, uint32(onuID), uint32(uniID), tpID); err != nil {
+ logger.Warn(ctx, err)
+ }
+ if err := f.DeleteTechProfileInstance(ctx, Intf, uint32(onuID), uint32(uniID), "", tpID); err != nil {
+ logger.Warn(ctx, err)
+ }
+ if err := f.RemoveSchedulerQueues(ctx, schedQueue{direction: tp_pb.Direction_UPSTREAM, intfID: Intf, onuID: uint32(onuID), uniID: uint32(uniID), tpID: tpID, uniPort: portNum, tpInst: techprofileInst}); err != nil {
+ logger.Warn(ctx, err)
+ }
+ if err := f.RemoveSchedulerQueues(ctx, schedQueue{direction: tp_pb.Direction_DOWNSTREAM, intfID: Intf, onuID: uint32(onuID), uniID: uint32(uniID), tpID: tpID, uniPort: portNum, tpInst: techprofileInst}); err != nil {
+ logger.Warn(ctx, err)
+ }
f.resourceMgr.FreeAllocID(ctx, Intf, uint32(onuID), uint32(uniID), techprofileInst.UsScheduler.AllocID)
// Delete the TCONT on the ONU.
if err := f.sendDeleteTcontToChild(ctx, Intf, uint32(onuID), uint32(uniID), uint32(techprofileInst.UsScheduler.AllocID), tpPath); err != nil {
@@ -2139,8 +2124,12 @@
}
}
case *tp.EponProfile:
- f.resourceMgr.RemoveTechProfileIDForOnu(ctx, Intf, uint32(onuID), uint32(uniID), tpID)
- f.DeleteTechProfileInstance(ctx, Intf, uint32(onuID), uint32(uniID), "", tpID)
+ if err := f.resourceMgr.RemoveTechProfileIDForOnu(ctx, Intf, uint32(onuID), uint32(uniID), tpID); err != nil {
+ logger.Warn(ctx, err)
+ }
+ if err := f.DeleteTechProfileInstance(ctx, Intf, uint32(onuID), uint32(uniID), "", tpID); err != nil {
+ logger.Warn(ctx, err)
+ }
f.resourceMgr.FreeAllocID(ctx, Intf, uint32(onuID), uint32(uniID), techprofileInst.AllocID)
// Delete the TCONT on the ONU.
if err := f.sendDeleteTcontToChild(ctx, Intf, uint32(onuID), uint32(uniID), uint32(techprofileInst.AllocID), tpPath); err != nil {
@@ -2176,7 +2165,6 @@
return
}
- var updatedFlows []rsrcMgr.FlowInfo
classifierInfo := make(map[string]interface{})
portNum, Intf, onu, uni, inPort, ethType, err := FlowExtractInfo(ctx, flow, flowDirection)
@@ -2226,11 +2214,8 @@
"flow-id": flowID})
return
}
- updatedFlows = nil
- for _, flow := range *flowInfo {
- updatedFlows = append(updatedFlows, flow)
- }
+ updatedFlows := *flowInfo
for i, storedFlow := range updatedFlows {
if flow.Id == storedFlow.LogicalFlowID {
removeFlowMessage := openoltpb2.Flow{FlowId: storedFlow.Flow.FlowId, FlowType: storedFlow.Flow.FlowType}
@@ -2282,7 +2267,6 @@
var onuID = int32(NoneOnuID)
var uniID = int32(NoneUniID)
var flowID uint32
- var updatedFlows []rsrcMgr.FlowInfo
flowIds := f.resourceMgr.GetCurrentFlowIDsForOnu(ctx, networkInterfaceID, onuID, uniID)
@@ -2297,10 +2281,7 @@
"flow-id": flowID})
continue
}
- updatedFlows = nil
- for _, flow := range *flowInfo {
- updatedFlows = append(updatedFlows, flow)
- }
+ updatedFlows := *flowInfo
for i, storedFlow := range updatedFlows {
if flow.Id == storedFlow.LogicalFlowID {
removeFlowMessage := openoltpb2.Flow{FlowId: storedFlow.Flow.FlowId, FlowType: storedFlow.Flow.FlowType}
@@ -2603,20 +2584,20 @@
Priority: int32(flow.Priority),
Cookie: flow.Cookie}
- if err = f.addFlowToDevice(ctx, flow, &multicastFlow); err != nil {
+ if err := f.addFlowToDevice(ctx, flow, &multicastFlow); err != nil {
return olterrors.NewErrFlowOp("add", flowID, log.Fields{"flow": multicastFlow}, err)
}
logger.Info(ctx, "multicast-flow-added-to-device-successfully")
//get cached group
- group, _, err := f.GetFlowGroupFromKVStore(ctx, groupID, true)
- if err == nil {
+ if group, _, err := f.GetFlowGroupFromKVStore(ctx, groupID, true); err == nil {
//calling groupAdd to set group members after multicast flow creation
- if err = f.ModifyGroup(ctx, group); err == nil {
- //cached group can be removed now
- f.resourceMgr.RemoveFlowGroupFromKVStore(ctx, groupID, true)
- } else {
+ if err := f.ModifyGroup(ctx, group); err != nil {
return olterrors.NewErrGroupOp("modify", groupID, log.Fields{"group": group}, err)
}
+ //cached group can be removed now
+ if err := f.resourceMgr.RemoveFlowGroupFromKVStore(ctx, groupID, true); err != nil {
+ logger.Warnw(ctx, "failed-to-remove-flow-group", log.Fields{"group-id": groupID, "error": err})
+ }
}
flowsToKVStore := f.getUpdatedFlowInfo(ctx, &multicastFlow, flowStoreCookie, MulticastFlow, flowID, flow.Id)
@@ -2753,13 +2734,13 @@
GroupId: group.Desc.GroupId,
}
var errAdd, errRemoved error
- if membersToBeAdded != nil && len(membersToBeAdded) > 0 {
+ if len(membersToBeAdded) > 0 {
groupToOlt.Command = openoltpb2.Group_ADD_MEMBERS
groupToOlt.Members = membersToBeAdded
//execute addMembers
errAdd = f.callGroupAddRemove(ctx, &groupToOlt)
}
- if membersToBeRemoved != nil && len(membersToBeRemoved) > 0 {
+ if len(membersToBeRemoved) > 0 {
groupToOlt.Command = openoltpb2.Group_REMOVE_MEMBERS
groupToOlt.Members = membersToBeRemoved
//execute removeMembers
@@ -2838,12 +2819,10 @@
group := openoltpb2.Group{
GroupId: groupID}
// create members of the group
- if buckets != nil {
- for _, ofBucket := range buckets {
- member := f.buildMember(ctx, ofBucket)
- if member != nil && !f.contains(group.Members, member) {
- group.Members = append(group.Members, member)
- }
+ for _, ofBucket := range buckets {
+ member := f.buildMember(ctx, ofBucket)
+ if member != nil && !f.contains(group.Members, member) {
+ group.Members = append(group.Members, member)
}
}
return &group
@@ -3018,7 +2997,7 @@
logger.Errorw(ctx, "onu-id-from-gem-port-not-found", log.Fields{
"gem-port-id": gemPortID,
"interface-id": intfID,
- "all-gems-on-port": onu,
+ "all-gems-on-port": onugem,
})
return uint32(0), olterrors.NewErrNotFound("onu-id", log.Fields{
"interface-id": intfID,
@@ -3147,18 +3126,26 @@
if allPbitsMarked(gemPortAttribute.PbitMap) {
classifier[VlanPcp] = uint32(VlanPCPMask)
if FlowType == DhcpFlow || FlowType == IgmpFlow || FlowType == HsiaFlow {
- f1(ctx, args["intfId"], args["onuId"], args["uniId"], args["portNo"], classifier, action, logicalFlow, args["allocId"], gemPortID, tpID)
+ if err := f1(ctx, args["intfId"], args["onuId"], args["uniId"], args["portNo"], classifier, action, logicalFlow, args["allocId"], gemPortID, tpID); err != nil {
+ logger.Warn(ctx, err)
+ }
} else if FlowType == EapolFlow {
- f2(ctx, args["intfId"], args["onuId"], args["uniId"], args["portNo"], classifier, action, logicalFlow, args["allocId"], gemPortID, vlanID[0], tpID)
+ if err := f2(ctx, args["intfId"], args["onuId"], args["uniId"], args["portNo"], classifier, action, logicalFlow, args["allocId"], gemPortID, vlanID[0], tpID); err != nil {
+ logger.Warn(ctx, err)
+ }
}
} else {
for pos, pbitSet := range strings.TrimPrefix(gemPortAttribute.PbitMap, BinaryStringPrefix) {
if pbitSet == BinaryBit1 {
classifier[VlanPcp] = uint32(len(strings.TrimPrefix(gemPortAttribute.PbitMap, BinaryStringPrefix))) - 1 - uint32(pos)
if FlowType == DhcpFlow || FlowType == IgmpFlow || FlowType == HsiaFlow {
- f1(ctx, args["intfId"], args["onuId"], args["uniId"], args["portNo"], classifier, action, logicalFlow, args["allocId"], gemPortID, tpID)
+ if err := f1(ctx, args["intfId"], args["onuId"], args["uniId"], args["portNo"], classifier, action, logicalFlow, args["allocId"], gemPortID, tpID); err != nil {
+ logger.Warn(ctx, err)
+ }
} else if FlowType == EapolFlow {
- f2(ctx, args["intfId"], args["onuId"], args["uniId"], args["portNo"], classifier, action, logicalFlow, args["allocId"], gemPortID, vlanID[0], tpID)
+ if err := f2(ctx, args["intfId"], args["onuId"], args["uniId"], args["portNo"], classifier, action, logicalFlow, args["allocId"], gemPortID, vlanID[0], tpID); err != nil {
+ logger.Warn(ctx, err)
+ }
}
}
}
@@ -3172,18 +3159,26 @@
if allPbitsMarked(queueAttribute.PbitMap) {
classifier[VlanPcp] = uint32(VlanPCPMask)
if FlowType == DhcpFlow || FlowType == IgmpFlow || FlowType == HsiaFlow {
- f1(ctx, args["intfId"], args["onuId"], args["uniId"], args["portNo"], classifier, action, logicalFlow, args["allocId"], gemPortID, tpID)
+ if err := f1(ctx, args["intfId"], args["onuId"], args["uniId"], args["portNo"], classifier, action, logicalFlow, args["allocId"], gemPortID, tpID); err != nil {
+ logger.Warn(ctx, err)
+ }
} else if FlowType == EapolFlow {
- f2(ctx, args["intfId"], args["onuId"], args["uniId"], args["portNo"], classifier, action, logicalFlow, args["allocId"], gemPortID, vlanID[0], tpID)
+ if err := f2(ctx, args["intfId"], args["onuId"], args["uniId"], args["portNo"], classifier, action, logicalFlow, args["allocId"], gemPortID, vlanID[0], tpID); err != nil {
+ logger.Warn(ctx, err)
+ }
}
} else {
for pos, pbitSet := range strings.TrimPrefix(queueAttribute.PbitMap, BinaryStringPrefix) {
if pbitSet == BinaryBit1 {
classifier[VlanPcp] = uint32(len(strings.TrimPrefix(queueAttribute.PbitMap, BinaryStringPrefix))) - 1 - uint32(pos)
if FlowType == DhcpFlow || FlowType == IgmpFlow || FlowType == HsiaFlow {
- f1(ctx, args["intfId"], args["onuId"], args["uniId"], args["portNo"], classifier, action, logicalFlow, args["allocId"], gemPortID, tpID)
+ if err := f1(ctx, args["intfId"], args["onuId"], args["uniId"], args["portNo"], classifier, action, logicalFlow, args["allocId"], gemPortID, tpID); err != nil {
+ logger.Warn(ctx, err)
+ }
} else if FlowType == EapolFlow {
- f2(ctx, args["intfId"], args["onuId"], args["uniId"], args["portNo"], classifier, action, logicalFlow, args["allocId"], gemPortID, vlanID[0], tpID)
+ if err := f2(ctx, args["intfId"], args["onuId"], args["uniId"], args["portNo"], classifier, action, logicalFlow, args["allocId"], gemPortID, vlanID[0], tpID); err != nil {
+ logger.Warn(ctx, err)
+ }
}
}
}
@@ -3196,18 +3191,26 @@
if allPbitsMarked(queueAttribute.PbitMap) {
classifier[VlanPcp] = uint32(VlanPCPMask)
if FlowType == DhcpFlow || FlowType == IgmpFlow || FlowType == HsiaFlow {
- f1(ctx, args["intfId"], args["onuId"], args["uniId"], args["portNo"], classifier, action, logicalFlow, args["allocId"], gemPortID, tpID)
+ if err := f1(ctx, args["intfId"], args["onuId"], args["uniId"], args["portNo"], classifier, action, logicalFlow, args["allocId"], gemPortID, tpID); err != nil {
+ logger.Warn(ctx, err)
+ }
} else if FlowType == EapolFlow {
- f2(ctx, args["intfId"], args["onuId"], args["uniId"], args["portNo"], classifier, action, logicalFlow, args["allocId"], gemPortID, vlanID[0], tpID)
+ if err := f2(ctx, args["intfId"], args["onuId"], args["uniId"], args["portNo"], classifier, action, logicalFlow, args["allocId"], gemPortID, vlanID[0], tpID); err != nil {
+ logger.Warn(ctx, err)
+ }
}
} else {
for pos, pbitSet := range strings.TrimPrefix(queueAttribute.PbitMap, BinaryStringPrefix) {
if pbitSet == BinaryBit1 {
classifier[VlanPcp] = uint32(len(strings.TrimPrefix(queueAttribute.PbitMap, BinaryStringPrefix))) - 1 - uint32(pos)
if FlowType == DhcpFlow || FlowType == IgmpFlow || FlowType == HsiaFlow {
- f1(ctx, args["intfId"], args["onuId"], args["uniId"], args["portNo"], classifier, action, logicalFlow, args["allocId"], gemPortID, tpID)
+ if err := f1(ctx, args["intfId"], args["onuId"], args["uniId"], args["portNo"], classifier, action, logicalFlow, args["allocId"], gemPortID, tpID); err != nil {
+ logger.Warn(ctx, err)
+ }
} else if FlowType == EapolFlow {
- f2(ctx, args["intfId"], args["onuId"], args["uniId"], args["portNo"], classifier, action, logicalFlow, args["allocId"], gemPortID, vlanID[0], tpID)
+ if err := f2(ctx, args["intfId"], args["onuId"], args["uniId"], args["portNo"], classifier, action, logicalFlow, args["allocId"], gemPortID, vlanID[0], tpID); err != nil {
+ logger.Warn(ctx, err)
+ }
}
}
}
@@ -3429,6 +3432,7 @@
return "", nil
}
+// nolint: gocyclo
func (f *OpenOltFlowMgr) checkAndAddFlow(ctx context.Context, args map[string]uint32, classifierInfo map[string]interface{},
actionInfo map[string]interface{}, flow *ofp.OfpFlowStats, TpInst interface{}, gemPorts []uint32,
tpID uint32, uni string) {
@@ -3453,7 +3457,9 @@
pcp.(uint32))
//Adding DHCP upstream flow
- f.addDHCPTrapFlow(ctx, intfID, onuID, uniID, portNo, classifierInfo, actionInfo, flow, allocID, gemPort, tpID)
+ if err := f.addDHCPTrapFlow(ctx, intfID, onuID, uniID, portNo, classifierInfo, actionInfo, flow, allocID, gemPort, tpID); err != nil {
+ logger.Warn(ctx, err)
+ }
} else {
//Adding DHCP upstream flow to all gemports
installFlowOnAllGemports(ctx, f.addDHCPTrapFlow, nil, args, classifierInfo, actionInfo, flow, gemPorts, TpInst, DhcpFlow, Upstream, tpID)
@@ -3470,7 +3476,9 @@
gemPort = f.techprofile[intfID].GetGemportIDForPbit(ctx, TpInst,
tp_pb.Direction_UPSTREAM,
pcp.(uint32))
- f.addIGMPTrapFlow(ctx, intfID, onuID, uniID, portNo, classifierInfo, actionInfo, flow, allocID, gemPort, tpID)
+ if err := f.addIGMPTrapFlow(ctx, intfID, onuID, uniID, portNo, classifierInfo, actionInfo, flow, allocID, gemPort, tpID); err != nil {
+ logger.Warn(ctx, err)
+ }
} else {
//Adding IGMP upstream flow to all gem ports
installFlowOnAllGemports(ctx, f.addIGMPTrapFlow, nil, args, classifierInfo, actionInfo, flow, gemPorts, TpInst, IgmpFlow, Upstream, tpID)
@@ -3497,7 +3505,9 @@
tp_pb.Direction_UPSTREAM,
pcp.(uint32))
- f.addEAPOLFlow(ctx, intfID, onuID, uniID, portNo, classifierInfo, actionInfo, flow, allocID, gemPort, vlanID, tpID)
+ if err := f.addEAPOLFlow(ctx, intfID, onuID, uniID, portNo, classifierInfo, actionInfo, flow, allocID, gemPort, vlanID, tpID); err != nil {
+ logger.Warn(ctx, err)
+ }
} else {
installFlowOnAllGemports(ctx, nil, f.addEAPOLFlow, args, classifierInfo, actionInfo, flow, gemPorts, TpInst, EapolFlow, Upstream, tpID, vlanID)
}
@@ -3513,7 +3523,9 @@
tp_pb.Direction_UPSTREAM,
pcp.(uint32))
//Adding HSIA upstream flow
- f.addUpstreamDataFlow(ctx, intfID, onuID, uniID, portNo, classifierInfo, actionInfo, flow, allocID, gemPort, tpID)
+ if err := f.addUpstreamDataFlow(ctx, intfID, onuID, uniID, portNo, classifierInfo, actionInfo, flow, allocID, gemPort, tpID); err != nil {
+ logger.Warn(ctx, err)
+ }
} else {
//Adding HSIA upstream flow to all gemports
installFlowOnAllGemports(ctx, f.addUpstreamDataFlow, nil, args, classifierInfo, actionInfo, flow, gemPorts, TpInst, HsiaFlow, Upstream, tpID)
@@ -3529,7 +3541,9 @@
tp_pb.Direction_DOWNSTREAM,
pcp.(uint32))
//Adding HSIA downstream flow
- f.addDownstreamDataFlow(ctx, intfID, onuID, uniID, portNo, classifierInfo, actionInfo, flow, allocID, gemPort, tpID)
+ if err := f.addDownstreamDataFlow(ctx, intfID, onuID, uniID, portNo, classifierInfo, actionInfo, flow, allocID, gemPort, tpID); err != nil {
+ logger.Warn(ctx, err)
+ }
} else {
//Adding HSIA downstream flow to all gemports
installFlowOnAllGemports(ctx, f.addDownstreamDataFlow, nil, args, classifierInfo, actionInfo, flow, gemPorts, TpInst, HsiaFlow, Downstream, tpID)
@@ -3546,15 +3560,16 @@
return
}
// Send Techprofile download event to child device in go routine as it takes time
- go f.sendTPDownloadMsgToChild(ctx, intfID, onuID, uniID, uni, tpID)
+ go func() {
+ if err := f.sendTPDownloadMsgToChild(ctx, intfID, onuID, uniID, uni, tpID); err != nil {
+ logger.Warn(ctx, err)
+ }
+ }()
}
func (f *OpenOltFlowMgr) isGemPortUsedByAnotherFlow(gemPK gemPortKey) bool {
flowIDList := f.flowsUsedByGemPort[gemPK]
- if len(flowIDList) > 1 {
- return true
- }
- return false
+ return len(flowIDList) > 1
}
func (f *OpenOltFlowMgr) isTechProfileUsedByAnotherGem(ctx context.Context, ponIntf uint32, onuID uint32, uniID uint32, tpID uint32, tpInst *tp.TechProfile, gemPortID uint32) (bool, uint32) {
@@ -3569,8 +3584,12 @@
}
if tpInst.InstanceCtrl.Onu == "single-instance" {
// The TP information for the given TP ID, PON ID, ONU ID, UNI ID should be removed.
- f.resourceMgr.RemoveTechProfileIDForOnu(ctx, ponIntf, uint32(onuID), uint32(uniID), tpID)
- f.DeleteTechProfileInstance(ctx, ponIntf, uint32(onuID), uint32(uniID), "", tpID)
+ if err := f.resourceMgr.RemoveTechProfileIDForOnu(ctx, ponIntf, uint32(onuID), uint32(uniID), tpID); err != nil {
+ logger.Warn(ctx, err)
+ }
+ if err := f.DeleteTechProfileInstance(ctx, ponIntf, uint32(onuID), uint32(uniID), "", tpID); err != nil {
+ logger.Warn(ctx, err)
+ }
// Although we cleaned up TP Instance for the given (PON ID, ONU ID, UNI ID), the TP might
// still be used on other uni ports.
@@ -3851,8 +3870,6 @@
log.Fields{
"pktinkey": pktInkey,
"gem": gemPort})
- return
-
}
//getCTagFromPacket retrieves and returns c-tag and priority value from a packet.
@@ -3915,7 +3932,6 @@
gemPK := gemPortKey{intf, uint32(gem)}
f.flowsUsedByGemPort[gemPK] = FlowIDs
}
- return
}
//loadInterfaceToMulticastQueueMap reads multicast queues per interface from the KV store
diff --git a/internal/pkg/core/openolt_flowmgr_test.go b/internal/pkg/core/openolt_flowmgr_test.go
index c13bd5e..490a40c 100644
--- a/internal/pkg/core/openolt_flowmgr_test.go
+++ b/internal/pkg/core/openolt_flowmgr_test.go
@@ -45,7 +45,7 @@
var flowMgr *OpenOltFlowMgr
func init() {
- log.SetDefaultLogger(log.JSON, log.DebugLevel, nil)
+ _, _ = log.SetDefaultLogger(log.JSON, log.DebugLevel, nil)
flowMgr = newMockFlowmgr()
}
func newMockResourceMgr() *resourcemanager.OpenOltResourceMgr {
@@ -134,16 +134,6 @@
flowmetadata := &voltha.FlowMetadata{
Meters: []*ofp.OfpMeterConfig{ofpMeterConfig},
}
- type args struct {
- Dir tp_pb.Direction
- IntfID uint32
- OnuID uint32
- UniID uint32
- UniPort uint32
- TpInst *tp.TechProfile
- MeterID uint32
- flowMetadata *voltha.FlowMetadata
- }
tests := []struct {
name string
schedQueue schedQueue
@@ -192,14 +182,6 @@
tprofile2.DsScheduler.AdditionalBw = "AdditionalBW_None"
tprofile2.DsScheduler.QSchedPolicy = "WRR"
//defTprofile := &tp.DefaultTechProfile{}
- type args struct {
- Dir tp_pb.Direction
- IntfID uint32
- OnuID uint32
- UniID uint32
- UniPort uint32
- TpInst *tp.TechProfile
- }
tests := []struct {
name string
schedQueue schedQueue
@@ -352,7 +334,9 @@
defer cancel()
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
- flowMgr.RemoveFlow(ctx, tt.args.flow)
+ if err := flowMgr.RemoveFlow(ctx, tt.args.flow); err != nil {
+ logger.Warn(ctx, err)
+ }
})
}
// t.Error("=====")
@@ -597,7 +581,8 @@
defer cancel()
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
- flowMgr.AddFlow(ctx, tt.args.flow, tt.args.flowMetadata)
+ _ = flowMgr.AddFlow(ctx, tt.args.flow, tt.args.flowMetadata)
+ // TODO: actually verify test cases
})
}
}
@@ -617,7 +602,8 @@
for j := 0; j < onuCount; j++ {
wg.Add(1)
go func(i uint32, j uint32) {
- flwMgr.UpdateOnuInfo(ctx, i, i, fmt.Sprintf("onu-%d", i))
+ // TODO: actually verify success
+ _ = flwMgr.UpdateOnuInfo(ctx, i, i, fmt.Sprintf("onu-%d", i))
wg.Done()
}(uint32(i), uint32(j))
}
@@ -641,7 +627,8 @@
// Create OnuInfo
for i := 0; i < intfNum; i++ {
for o := 0; o < onuNum; o++ {
- flowMgr.UpdateOnuInfo(ctx, uint32(i), uint32(o), fmt.Sprintf("i%do%d", i, o))
+ // TODO: actually verify success
+ _ = flowMgr.UpdateOnuInfo(ctx, uint32(i), uint32(o), fmt.Sprintf("i%do%d", i, o))
}
}
@@ -716,7 +703,8 @@
defer cancel()
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
- flwMgr.UpdateOnuInfo(ctx, tt.args.intfID, tt.args.onuID, tt.args.serialNum)
+ // TODO: should check returned errors are as expected?
+ _ = flwMgr.UpdateOnuInfo(ctx, tt.args.intfID, tt.args.onuID, tt.args.serialNum)
for _, gemPort := range tt.args.gemPortIDs {
flwMgr.addGemPortToOnuInfoMap(ctx, tt.args.intfID, tt.args.onuID, gemPort)
}
@@ -1008,11 +996,6 @@
},
}
- type fields struct {
- techprofile []tp.TechProfileIf
- deviceHandler *DeviceHandler
- resourceMgr *rsrcMgr.OpenOltResourceMgr
- }
type args struct {
args map[string]uint32
classifierInfo map[string]interface{}
@@ -1030,9 +1013,8 @@
uni string
}
tests := []struct {
- name string
- fields fields
- args args
+ name string
+ args args
}{
{
name: "checkAndAddFlow-1",
diff --git a/internal/pkg/core/openolt_test.go b/internal/pkg/core/openolt_test.go
index a2ac77b..08c2f52 100644
--- a/internal/pkg/core/openolt_test.go
+++ b/internal/pkg/core/openolt_test.go
@@ -26,7 +26,6 @@
"context"
"errors"
"reflect"
- "sync"
"testing"
com "github.com/opencord/voltha-lib-go/v3/pkg/adapters/common"
@@ -43,17 +42,16 @@
// mocks the OpenOLT struct.
type fields struct {
- deviceHandlers map[string]*DeviceHandler
- coreProxy *com.CoreProxy
- adapterProxy *com.AdapterProxy
- eventProxy *com.EventProxy
- kafkaICProxy kafka.InterContainerProxy
- numOnus int
- KVStoreAddress string
- KVStoreType string
- exitChannel chan int
- lockDeviceHandlersMap sync.RWMutex
- ctx context.Context
+ deviceHandlers map[string]*DeviceHandler
+ coreProxy *com.CoreProxy
+ adapterProxy *com.AdapterProxy
+ eventProxy *com.EventProxy
+ kafkaICProxy kafka.InterContainerProxy
+ numOnus int
+ KVStoreAddress string
+ KVStoreType string
+ exitChannel chan int
+ ctx context.Context
}
// mockOlt mocks OpenOLT struct.
@@ -728,7 +726,9 @@
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
oo := testOltObject(tt.fields)
- oo.Start(tt.args.ctx)
+ if err := oo.Start(tt.args.ctx); err != nil {
+ t.Error(err)
+ }
if err := oo.Stop(tt.args.ctx); err != nil {
t.Errorf("Stop() error = %v, wantErr %v", err, tt.wantErr)
}
diff --git a/internal/pkg/core/statsmanager.go b/internal/pkg/core/statsmanager.go
index 6427a0c..53f81ab 100755
--- a/internal/pkg/core/statsmanager.go
+++ b/internal/pkg/core/statsmanager.go
@@ -288,12 +288,9 @@
metricNames := StatMgr.Device.metrics.GetSubscriberMetrics()
var metrics []string
-
- if metricNames != nil && len(metricNames) > 0 {
- for metric := range metricNames {
- if metricNames[metric].Enabled {
- metrics = append(metrics, metric)
- }
+ for metric := range metricNames {
+ if metricNames[metric].Enabled {
+ metrics = append(metrics, metric)
}
}
@@ -332,12 +329,9 @@
metricNames := StatMgr.Device.metrics.GetSubscriberMetrics()
var metrics []string
-
- if metricNames != nil && len(metricNames) > 0 {
- for metric := range metricNames {
- if metricNames[metric].Enabled {
- metrics = append(metrics, metric)
- }
+ for metric := range metricNames {
+ if metricNames[metric].Enabled {
+ metrics = append(metrics, metric)
}
}
diff --git a/internal/pkg/core/statsmanager_test.go b/internal/pkg/core/statsmanager_test.go
index cfbc04a..0155330 100644
--- a/internal/pkg/core/statsmanager_test.go
+++ b/internal/pkg/core/statsmanager_test.go
@@ -20,10 +20,11 @@
import (
"context"
"fmt"
- "github.com/opencord/voltha-protos/v3/go/openolt"
- "github.com/opencord/voltha-protos/v3/go/voltha"
"reflect"
"testing"
+
+ "github.com/opencord/voltha-protos/v3/go/openolt"
+ "github.com/opencord/voltha-protos/v3/go/voltha"
)
func TestOpenOltStatisticsMgr_PortStatisticsIndication(t *testing.T) {
@@ -68,10 +69,8 @@
SouthBoundPort map[uint32]*PonPort
}
type args struct {
- portType voltha.Port_PortType
- val map[string]float32
- port *voltha.Port
- context map[string]string
+ val map[string]float32
+ port *voltha.Port
}
ponmap := map[uint32]*PonPort{}
ponmap[0] = &PonPort{
diff --git a/internal/pkg/resourcemanager/resourcemanager.go b/internal/pkg/resourcemanager/resourcemanager.go
index 58414f0..0504eaf 100755
--- a/internal/pkg/resourcemanager/resourcemanager.go
+++ b/internal/pkg/resourcemanager/resourcemanager.go
@@ -22,11 +22,12 @@
"encoding/json"
"errors"
"fmt"
- "github.com/opencord/voltha-openolt-adapter/internal/pkg/olterrors"
"strconv"
"sync"
"time"
+ "github.com/opencord/voltha-openolt-adapter/internal/pkg/olterrors"
+
"github.com/opencord/voltha-lib-go/v3/pkg/db"
"github.com/opencord/voltha-lib-go/v3/pkg/db/kvstore"
"github.com/opencord/voltha-lib-go/v3/pkg/log"
@@ -1162,7 +1163,6 @@
logger.Errorw(ctx, "Failed to add uin port in onugem to kv store", log.Fields{"uni": portNo})
return
}
- return
}
//UpdateGemPortForPktIn updates gemport for pkt in path to kvstore, path being intfid, onuid, portno, vlan id, priority bit
@@ -1179,8 +1179,6 @@
return
}
logger.Debugw(ctx, "added gem packet in successfully", log.Fields{"path": path, "gem": gemPort})
-
- return
}
// GetGemPortFromOnuPktIn gets the gem port from onu pkt in path, path being intfid, onuid, portno, vlan id, priority bit
@@ -1252,7 +1250,7 @@
var nni []uint32
var Val []byte
- path := fmt.Sprintf(NnniIntfID)
+ path := NnniIntfID
value, err := RsrcMgr.KVStore.Get(ctx, path)
if err != nil {
logger.Error(ctx, "failed to get data from kv store")
@@ -1281,7 +1279,7 @@
return err
}
- path := fmt.Sprintf(NnniIntfID)
+ path := NnniIntfID
nni = append(nni, nniIntf)
Value, err = json.Marshal(nni)
if err != nil {
@@ -1298,7 +1296,7 @@
// DelNNiFromKVStore deletes nni interface list from kv store.
func (RsrcMgr *OpenOltResourceMgr) DelNNiFromKVStore(ctx context.Context) error {
- path := fmt.Sprintf(NnniIntfID)
+ path := NnniIntfID
if err := RsrcMgr.KVStore.Delete(ctx, path); err != nil {
logger.Errorw(ctx, "Failed to delete nni interfaces from kv store", log.Fields{"path": path})
@@ -1364,9 +1362,7 @@
defer RsrcMgr.flowIDToGemInfoLock.Unlock()
if err = RsrcMgr.KVStore.Put(ctx, path, val); err != nil {
logger.Errorw(ctx, "Failed to put to kvstore", log.Fields{"error": err, "path": path, "value": val})
- return
}
- return
}
//GetFlowIDsGemMapForInterface gets flowids per gemport and interface
@@ -1401,9 +1397,7 @@
defer RsrcMgr.flowIDToGemInfoLock.Unlock()
if err := RsrcMgr.KVStore.Delete(ctx, path); err != nil {
logger.Errorw(ctx, "Failed to delete nni interfaces from kv store", log.Fields{"path": path})
- return
}
- return
}
// RemoveResourceMap Clear resource map associated with (intfid, onuid, uniid) tuple.
@@ -1414,7 +1408,7 @@
//GetMcastQueuePerInterfaceMap gets multicast queue info per pon interface
func (RsrcMgr *OpenOltResourceMgr) GetMcastQueuePerInterfaceMap(ctx context.Context) (map[uint32][]uint32, error) {
- path := fmt.Sprintf(McastQueuesForIntf)
+ path := McastQueuesForIntf
var mcastQueueToIntfMap map[uint32][]uint32
var val []byte
@@ -1439,7 +1433,7 @@
//AddMcastQueueForIntf adds multicast queue for pon interface
func (RsrcMgr *OpenOltResourceMgr) AddMcastQueueForIntf(ctx context.Context, intf uint32, gem uint32, servicePriority uint32) error {
var val []byte
- path := fmt.Sprintf(McastQueuesForIntf)
+ path := McastQueuesForIntf
mcastQueues, err := RsrcMgr.GetMcastQueuePerInterfaceMap(ctx)
if err != nil {
diff --git a/internal/pkg/resourcemanager/resourcemanager_test.go b/internal/pkg/resourcemanager/resourcemanager_test.go
index 73b74df..562bc08 100644
--- a/internal/pkg/resourcemanager/resourcemanager_test.go
+++ b/internal/pkg/resourcemanager/resourcemanager_test.go
@@ -43,14 +43,14 @@
)
func init() {
- log.SetDefaultLogger(log.JSON, log.DebugLevel, nil)
+ _, _ = log.SetDefaultLogger(log.JSON, log.DebugLevel, nil)
}
const (
// MeterConfig meter to extract meter
MeterConfig = "meter_id"
// TpIDSuffixPath to extract Techprofile
- TpIDSuffixPath = "tp_id"
+ // TpIDSuffixPath = "tp_id"
// FlowIDInfo to extract flows
FlowIDInfo = "flow_id_info"
// FlowIds to extract flows