Skip to content

Commit

Permalink
chore: Adds govet lint check in CI (#211)
Browse files Browse the repository at this point in the history
* Enable go vet checks in CI

Signed-off-by: Patricia Reinoso <[email protected]>

* Fix nil values comparison

Signed-off-by: Patricia Reinoso <[email protected]>

---------

Signed-off-by: Patricia Reinoso <[email protected]>
Co-authored-by: gab-arrobo <[email protected]>
  • Loading branch information
patriciareinoso and gab-arrobo authored Jan 24, 2024
1 parent aec5344 commit e710ec0
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 34 deletions.
11 changes: 4 additions & 7 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -170,13 +170,10 @@ linters-settings:
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf
# enable or disable analyzers by name
enable:
- atomicalign
enable-all: false
# enable all analyzers
enable-all: true
disable:
- shadow
disable-all: false
- fieldalignment
depguard:
list-type: blacklist
include-go-root: false
Expand Down Expand Up @@ -220,7 +217,7 @@ linters-settings:
linters:
enable:
- gofmt
# - govet
- govet
# - errcheck
# - staticcheck
- unused
Expand Down
20 changes: 12 additions & 8 deletions context/datapath.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ func (node *DataPathNode) Prev() *DataPathNode {

func (node *DataPathNode) ActivateUpLinkTunnel(smContext *SMContext) error {
var err error
var pdr *PDR
var flowQer *QER
logger.CtxLog.Traceln("In ActivateUpLinkTunnel")
node.UpLinkTunnel.SrcEndPoint = node.Prev()
node.UpLinkTunnel.DestEndPoint = node
Expand All @@ -127,9 +129,9 @@ func (node *DataPathNode) ActivateUpLinkTunnel(smContext *SMContext) error {
addRules := pccRuleUpdate.GetAddPccRuleUpdate()

for name, rule := range addRules {
if pdr, err := destUPF.BuildCreatePdrFromPccRule(rule); err == nil {
if pdr, err = destUPF.BuildCreatePdrFromPccRule(rule); err == nil {
//Add PCC Rule Qos Data QER
if flowQer, err := node.CreatePccRuleQer(smContext, rule.RefQosData[0], rule.RefTcData[0]); err == nil {
if flowQer, err = node.CreatePccRuleQer(smContext, rule.RefQosData[0], rule.RefTcData[0]); err == nil {
pdr.QER = append(pdr.QER, flowQer)
}
//Set PDR in Tunnel
Expand All @@ -138,7 +140,7 @@ func (node *DataPathNode) ActivateUpLinkTunnel(smContext *SMContext) error {
}
} else {
//Default PDR
if pdr, err := destUPF.AddPDR(); err != nil {
if pdr, err = destUPF.AddPDR(); err != nil {
logger.CtxLog.Errorln("In ActivateUpLinkTunnel UPF IP: ", node.UPF.NodeID.ResolveNodeIdToIp().String())
logger.CtxLog.Errorln("Allocate PDR Error: ", err)
return fmt.Errorf("add PDR failed: %s", err)
Expand All @@ -164,6 +166,8 @@ func (node *DataPathNode) ActivateUpLinkTunnel(smContext *SMContext) error {

func (node *DataPathNode) ActivateDownLinkTunnel(smContext *SMContext) error {
var err error
var pdr *PDR
var flowQer *QER
node.DownLinkTunnel.SrcEndPoint = node.Next()
node.DownLinkTunnel.DestEndPoint = node

Expand All @@ -173,9 +177,9 @@ func (node *DataPathNode) ActivateDownLinkTunnel(smContext *SMContext) error {
if pccRuleUpdate != nil {
addRules := pccRuleUpdate.GetAddPccRuleUpdate()
for name, rule := range addRules {
if pdr, err := destUPF.BuildCreatePdrFromPccRule(rule); err == nil {
if pdr, err = destUPF.BuildCreatePdrFromPccRule(rule); err == nil {
//Add PCC Rule Qos Data QER
if flowQer, err := node.CreatePccRuleQer(smContext, rule.RefQosData[0], rule.RefTcData[0]); err == nil {
if flowQer, err = node.CreatePccRuleQer(smContext, rule.RefQosData[0], rule.RefTcData[0]); err == nil {
pdr.QER = append(pdr.QER, flowQer)
}
//Set PDR in Tunnel
Expand All @@ -184,7 +188,7 @@ func (node *DataPathNode) ActivateDownLinkTunnel(smContext *SMContext) error {
}
} else {
//Default PDR
if pdr, err := destUPF.AddPDR(); err != nil {
if pdr, err = destUPF.AddPDR(); err != nil {
logger.CtxLog.Errorln("In ActivateDownLinkTunnel UPF IP: ", node.UPF.NodeID.ResolveNodeIdToIp().String())
logger.CtxLog.Errorln("Allocate PDR Error: ", err)
return fmt.Errorf("add PDR failed: %s", err)
Expand Down Expand Up @@ -648,8 +652,8 @@ func (dpNode *DataPathNode) ActivateDlLinkPdr(smContext *SMContext, defQER *QER,
} else {
if anIP := smContext.Tunnel.ANInformation.IPAddress; anIP != nil {
ANUPF := dataPath.FirstDPNode
DLPDR := ANUPF.DownLinkTunnel.PDR["default"] //TODO: Iterate over all PDRs
DLFAR := DLPDR.FAR
DefaultDLPDR := ANUPF.DownLinkTunnel.PDR["default"] //TODO: Iterate over all PDRs
DLFAR := DefaultDLPDR.FAR
DLFAR.ForwardingParameters = new(ForwardingParameters)
DLFAR.ForwardingParameters.DestinationInterface.InterfaceValue = pfcpType.DestinationInterfaceAccess
DLFAR.ForwardingParameters.NetworkInstance = []byte(smContext.Dnn)
Expand Down
8 changes: 4 additions & 4 deletions context/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"encoding/json"
"fmt"
"net"
"reflect"
"sync"

"github.com/omec-project/MongoDBLibrary"
Expand Down Expand Up @@ -167,9 +168,8 @@ func (smContext *SMContext) UnmarshalJSON(data []byte) error {

var dataPathInDBIf interface{}
var FirstDPNodeIf interface{}
var nilVal *UPTunnelInDB = nil
smContext.Tunnel = &UPTunnel{}
if &aux.Tunnel != nilVal {
if !reflect.DeepEqual(aux.Tunnel, UPTunnelInDB{}) {
smContext.Tunnel.ANInformation = aux.Tunnel.ANInformation
smContext.Tunnel.PathIDGenerator = idgenerator.NewGenerator(1, 2147483647)
smContext.Tunnel.DataPathPool = NewDataPathPool()
Expand Down Expand Up @@ -383,8 +383,8 @@ func ShowSmContextPool() {
})
}

func GetSmContextPool() sync.Map {
return smContextPool
func GetSmContextPool() *sync.Map {
return &smContextPool
}

func StoreSmContextPool(smContext *SMContext) {
Expand Down
17 changes: 8 additions & 9 deletions context/db_uptunnel.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,14 @@ func testEq(a, b []byte) bool {
}

func RecoverTunnel(tunnelInfo *TunnelInfo) (tunnel *GTPTunnel) {
tunnel = &GTPTunnel{
TEID: tunnelInfo.TEID,
PDR: tunnelInfo.PDR,
}
var nilVal *NodeIDInDB = nil
var nilValNode *DataPathNode = nil
empty_nodeID := &NodeIDInDB{}
if &tunnelInfo.DataPathNodeUPFNodeID != nilVal {
// fmt.Println("In RecoverTunnel &tunnelInfo.DataPathNodeUPFNodeID != nilVal")
if tunnelInfo != nil {
tunnel = &GTPTunnel{
TEID: tunnelInfo.TEID,
PDR: tunnelInfo.PDR,
}
var nilValNode *DataPathNode = nil
empty_nodeID := &NodeIDInDB{}

if (tunnelInfo.DataPathNodeUPFNodeID.NodeIdType == empty_nodeID.NodeIdType) && (testEq(tunnelInfo.DataPathNodeUPFNodeID.NodeIdValue, empty_nodeID.NodeIdValue)) {
endPoint := nilValNode
tunnel.SrcEndPoint = endPoint
Expand Down
7 changes: 1 addition & 6 deletions context/sm_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import (
"github.com/omec-project/nas/nasConvert"
"github.com/omec-project/nas/nasMessage"
nrf_cache "github.com/omec-project/nrf/nrfcache"
"github.com/omec-project/openapi"
"github.com/omec-project/openapi/Namf_Communication"
"github.com/omec-project/openapi/Nnrf_NFDiscovery"
"github.com/omec-project/openapi/Npcf_SMPolicyControl"
Expand Down Expand Up @@ -421,12 +420,8 @@ func (smContext *SMContext) PCFSelection() error {

if res != nil {
if status := res.StatusCode; status != http.StatusOK {
metrics.IncrementSvcNrfMsgStats(SMF_Self().NfInstanceID, string(svcmsgtypes.NnrfNFDiscoveryPcf), "In", "Failure", err.Error())
apiError := err.(openapi.GenericOpenAPIError)
problemDetails := apiError.Model().(models.ProblemDetails)

metrics.IncrementSvcNrfMsgStats(SMF_Self().NfInstanceID, string(svcmsgtypes.NnrfNFDiscoveryPcf), "In", "Failure", "")
logger.CtxLog.Warningf("NFDiscovery PCF return status: %d\n", status)
logger.CtxLog.Warningf("Detail: %v\n", problemDetails.Title)
}
}

Expand Down

0 comments on commit e710ec0

Please sign in to comment.