diff --git a/.golangci.yml b/.golangci.yml index 2e1cfdc6..40fd2440 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -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 @@ -220,7 +217,7 @@ linters-settings: linters: enable: - gofmt - # - govet + - govet # - errcheck # - staticcheck - unused diff --git a/context/datapath.go b/context/datapath.go index b596403a..4310d18a 100644 --- a/context/datapath.go +++ b/context/datapath.go @@ -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 @@ -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 @@ -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) @@ -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 @@ -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 @@ -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) @@ -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) diff --git a/context/db.go b/context/db.go index 8870d2bb..6af3ce20 100644 --- a/context/db.go +++ b/context/db.go @@ -11,6 +11,7 @@ import ( "encoding/json" "fmt" "net" + "reflect" "sync" "github.com/omec-project/MongoDBLibrary" @@ -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() @@ -383,8 +383,8 @@ func ShowSmContextPool() { }) } -func GetSmContextPool() sync.Map { - return smContextPool +func GetSmContextPool() *sync.Map { + return &smContextPool } func StoreSmContextPool(smContext *SMContext) { diff --git a/context/db_uptunnel.go b/context/db_uptunnel.go index 7438cba8..b7455d04 100644 --- a/context/db_uptunnel.go +++ b/context/db_uptunnel.go @@ -102,15 +102,14 @@ func testEq(a, b []byte) bool { } func RecoverTunnel(tunnelInfo *TunnelInfo) (tunnel *GTPTunnel) { - tunnel = >PTunnel{ - 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 = >PTunnel{ + 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 diff --git a/context/sm_context.go b/context/sm_context.go index aba31308..0845dca0 100644 --- a/context/sm_context.go +++ b/context/sm_context.go @@ -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" @@ -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) } }