Skip to content

Commit

Permalink
Enable linters and add GO report card (#118)
Browse files Browse the repository at this point in the history
* Apply `gofmt` to all files

* Enable `ineffassign` and `goconst`

* Apply `gci` to all files

* Apply `gofumpt` to all files

* Enable `unconvert`

* Add GO report card
  • Loading branch information
gab-arrobo authored May 31, 2024
1 parent 0f94135 commit 562ad84
Show file tree
Hide file tree
Showing 40 changed files with 164 additions and 158 deletions.
13 changes: 6 additions & 7 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -221,31 +221,30 @@ linters:
- staticcheck
- unused
- gosimple
# - ineffassign
- ineffassign
- typecheck
# Additional
# - lll
- godox
#- gomnd
#- goconst
- goconst
# - gocognit
# - maligned
# - nestif
# - gomodguard
# - nakedret
# - gci
- gci
- misspell
# - gofumpt
- gofumpt
- whitespace
# - unconvert
- unconvert
- predeclared
- noctx
- dogsled
# - bodyclose
- asciicheck
#- stylecheck
# - unparam
#- wsl
# - wsl

#disable-all: false
fast: true
Expand Down
32 changes: 19 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,46 @@ SPDX-FileCopyrightText: 2021 Open Networking Foundation <info@opennetworking.org
Copyright 2019 free5GC.org
SPDX-License-Identifier: Apache-2.0
-->
[![Go Report Card](https://goreportcard.com/badge/github.com/omec-project/pcf)](https://goreportcard.com/report/github.com/omec-project/pcf)

# pcf

The Policy Control Function (PCF) supports unified policy framework to govern network behaviour,
provides policy rules to Control Plane function(s) to enforce them and Accesses subscription information
relevant for policy decisions in a Unified Data Repository (UDR)
The Policy Control Function (PCF) supports unified policy framework to govern
network behaviour, provides policy rules to Control Plane function(s) to enforce
them and Accesses subscription information relevant for policy decisions in a
Unified Data Repository (UDR)

The reference 3GPP specification for PCF are as follows
- PCC framework Specification 23.503,
- Session Management Policy Control - Specification 29.512
- Policy and Charging Control signalling flows and QoS parameter mapping- Specification 29513
- Policy and Charging Control signalling flows and QoS parameter mapping (Spec 29.513)


## PCF Block Diagram
![PCF Block Diagram](/docs/images/README-PCF.png)

## Supported Features
- PCF provides Access and Mobility Management related policies to the AMF Subscription Data retrieval and AM Policy management
- PCF provides Session Management Policy Control Service to the SMF Subscription Data retrieval and SM Policy management
- Policy Control Function (PCF) shall support interactions with the access and mobility policy enforcement in the AMF, through service-based interfaces
- PCF provides Access and Mobility Management related policies to the AMF
Subscription Data retrieval and AM Policy management
- PCF provides Session Management Policy Control Service to the SMF Subscription
Data retrieval and SM Policy management
- Policy Control Function (PCF) shall support interactions with the access and
mobility policy enforcement in the AMF, through service-based interfaces

## Upcoming Changes in PCF
- Process configuration received from Configuration Service and prepare PCC Rules, Session Rules and Qos Flows
- Process configuration received from Configuration Service and prepare PCC
Rules, Session Rules and Qos Flows
- Send PCC Rules, Session Rules to SMF when a SMF Creates Policy subscriber
- Send notification towards SMF PDU Session when PCF detects any changes in Subscriber’s Rule/Qos information.
- Dedicated QoS flows addition & removal through APIs
- Send notification towards SMF PDU Session when PCF detects any changes in
Subscriber’s Rule/Qos information.
- Dedicated QoS flows addition and removal through APIs



Compliance of the 5G Network functions can be found at [5G Compliance ](https://docs.sd-core.opennetworking.org/master/overview/3gpp-compliance-5g.html)
Compliance of the 5G Network functions can be found at [5G Compliance](https://docs.sd-core.opennetworking.org/master/overview/3gpp-compliance-5g.html)

## Reach out to us thorugh
## Reach out to us thorugh

1. #sdcore-dev channel in [ONF Community Slack](https://onf-community.slack.com/)
2. Raise Github issues
3 changes: 1 addition & 2 deletions ampolicy/api_default.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,12 @@ import (
"net/http"

"github.com/gin-gonic/gin"

"github.com/omec-project/util/httpwrapper"
"github.com/omec-project/openapi"
"github.com/omec-project/openapi/models"
"github.com/omec-project/pcf/logger"
"github.com/omec-project/pcf/producer"
"github.com/omec-project/pcf/util"
"github.com/omec-project/util/httpwrapper"
)

func HTTPPoliciesPolAssoIdDelete(c *gin.Context) {
Expand Down
3 changes: 1 addition & 2 deletions ampolicy/routers.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ import (
"strings"

"github.com/gin-gonic/gin"

logger_util "github.com/omec-project/util/logger"
"github.com/omec-project/pcf/logger"
logger_util "github.com/omec-project/util/logger"
)

// Route is the information for every URI.
Expand Down
3 changes: 1 addition & 2 deletions bdtpolicy/api_bdt_policies_collection_routers.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@ import (
"net/http"

"github.com/gin-gonic/gin"

"github.com/omec-project/util/httpwrapper"
"github.com/omec-project/openapi"
"github.com/omec-project/openapi/models"
"github.com/omec-project/pcf/logger"
"github.com/omec-project/pcf/producer"
"github.com/omec-project/util/httpwrapper"
)

// CreateBDTPolicy - Create a new Individual BDT policy
Expand Down
3 changes: 1 addition & 2 deletions bdtpolicy/api_individual_bdt_policy_document_routers.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@ import (
"net/http"

"github.com/gin-gonic/gin"

"github.com/omec-project/util/httpwrapper"
"github.com/omec-project/openapi"
"github.com/omec-project/openapi/models"
"github.com/omec-project/pcf/logger"
"github.com/omec-project/pcf/producer"
"github.com/omec-project/util/httpwrapper"
)

// GetBDTPolicy - Read an Individual BDT policy
Expand Down
3 changes: 1 addition & 2 deletions bdtpolicy/routers.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ import (
"strings"

"github.com/gin-gonic/gin"

logger_util "github.com/omec-project/util/logger"
"github.com/omec-project/pcf/logger"
logger_util "github.com/omec-project/util/logger"
)

// Route is the information for every URI.
Expand Down
6 changes: 3 additions & 3 deletions consumer/communication.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ import (
)

func AmfStatusChangeSubscribe(amfUri string, guamiList []models.Guami) (
problemDetails *models.ProblemDetails, err error) {
problemDetails *models.ProblemDetails, err error,
) {
logger.Consumerlog.Debugf("PCF Subscribe to AMF status[%+v]", amfUri)
pcfSelf := pcf_context.PCF_Self()
client := util.GetNamfClient(amfUri)
Expand All @@ -29,8 +30,7 @@ func AmfStatusChangeSubscribe(amfUri string, guamiList []models.Guami) (
GuamiList: guamiList,
}

res, httpResp, localErr :=
client.SubscriptionsCollectionDocumentApi.AMFStatusChangeSubscribe(context.Background(), subscriptionData)
res, httpResp, localErr := client.SubscriptionsCollectionDocumentApi.AMFStatusChangeSubscribe(context.Background(), subscriptionData)
if localErr == nil {
locationHeader := httpResp.Header.Get("Location")
logger.Consumerlog.Debugf("location header: %+v", locationHeader)
Expand Down
4 changes: 2 additions & 2 deletions consumer/nf_discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"net/http"

"github.com/antihax/optional"

"github.com/omec-project/openapi/Nnrf_NFDiscovery"
"github.com/omec-project/openapi/models"
"github.com/omec-project/pcf/logger"
Expand All @@ -21,7 +20,8 @@ import (

var SendSearchNFInstances = func(
nrfUri string, targetNfType, requestNfType models.NfType, param Nnrf_NFDiscovery.SearchNFInstancesParamOpts) (
*models.SearchResult, error) {
*models.SearchResult, error,
) {
// Set client and set url
configuration := Nnrf_NFDiscovery.NewConfiguration()
configuration.SetBasePath(nrfUri)
Expand Down
3 changes: 2 additions & 1 deletion consumer/nf_management.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ func BuildNFInstance(context *pcf_context.PCFContext) (profile models.NfProfile,
}

var SendRegisterNFInstance = func(nrfUri, nfInstanceId string, profile models.NfProfile) (
nfProfile models.NfProfile, resouceNrfUri string, retrieveNfInstanceID string, err error) {
nfProfile models.NfProfile, resouceNrfUri string, retrieveNfInstanceID string, err error,
) {
// Set client and set url
configuration := Nnrf_NFManagement.NewConfiguration()
configuration.SetBasePath(nrfUri)
Expand Down
2 changes: 1 addition & 1 deletion context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ type PccPolicy struct {
PccRules map[string]*models.PccRule
QosDecs map[string]*models.QosData
TraffContDecs map[string]*models.TrafficControlData
SessionPolicy map[string]*SessionPolicy //dnn is key
SessionPolicy map[string]*SessionPolicy // dnn is key
IdGenerator *idgenerator.IDGenerator
}
type PcfSubscriberPolicyData struct {
Expand Down
6 changes: 4 additions & 2 deletions context/ue.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ func (ue *UeContext) NewUeAMPolicyData(assolId string, req models.PolicyAssociat

// returns UeSmPolicyData and insert related info to Ue with smPolId
func (ue *UeContext) NewUeSmPolicyData(
key string, request models.SmPolicyContextData, smData *models.SmPolicyData) *UeSmPolicyData {
key string, request models.SmPolicyContextData, smData *models.SmPolicyData,
) *UeSmPolicyData {
if smData == nil {
return nil
}
Expand Down Expand Up @@ -426,7 +427,8 @@ func (ue *UeContext) SMPolicyFindByIpv6(v6 string) *UeSmPolicyData {

// returns SM Policy by IPv4
func (ue *UeContext) SMPolicyFindByIdentifiersIpv4(
v4 string, sNssai *models.Snssai, dnn string, ipDomain string) *UeSmPolicyData {
v4 string, sNssai *models.Snssai, dnn string, ipDomain string,
) *UeSmPolicyData {
for _, smPolicy := range ue.SmPolicyData {
policyContext := smPolicy.PolicyContext
if policyContext.Ipv4Address == v4 {
Expand Down
3 changes: 1 addition & 2 deletions factory/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ import (
"fmt"
"os"

"gopkg.in/yaml.v2"

"github.com/omec-project/pcf/logger"
"gopkg.in/yaml.v2"
)

var PcfConfig Config
Expand Down
1 change: 0 additions & 1 deletion httpcallback/amf_status_change_notify.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"net/http"

"github.com/gin-gonic/gin"

"github.com/omec-project/openapi"
"github.com/omec-project/openapi/models"
"github.com/omec-project/pcf/logger"
Expand Down
1 change: 0 additions & 1 deletion httpcallback/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"net/http"

"github.com/gin-gonic/gin"

"github.com/omec-project/pcf/logger"
logger_util "github.com/omec-project/util/logger"
)
Expand Down
1 change: 0 additions & 1 deletion httpcallback/sm_policy_notify.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"net/http"

"github.com/gin-gonic/gin"

"github.com/omec-project/openapi"
"github.com/omec-project/openapi/models"
"github.com/omec-project/pcf/logger"
Expand Down
3 changes: 1 addition & 2 deletions internal/notifyevent/dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
package notifyevent

import (
"github.com/tim-ywliu/event"

"github.com/omec-project/openapi/models"
"github.com/omec-project/pcf/logger"
"github.com/tim-ywliu/event"
)

var notifyDispatcher *event.Dispatcher
Expand Down
6 changes: 2 additions & 4 deletions internal/notifyevent/send_smpolicy_termination.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@ import (
"context"
"net/http"

"github.com/tim-ywliu/event"

"github.com/omec-project/openapi/models"
"github.com/omec-project/pcf/logger"
"github.com/omec-project/pcf/util"
"github.com/tim-ywliu/event"
)

const SendSMpolicyTerminationNotifyEventName event.Name = "SendSMpolicyTerminationNotify"
Expand All @@ -31,8 +30,7 @@ func (e SendSMpolicyTerminationNotifyEvent) Handle() {
}
client := util.GetNpcfSMPolicyCallbackClient()
logger.NotifyEventLog.Infof("SM Policy Termination Request Notification to SMF")
rsp, err :=
client.DefaultCallbackApi.SmPolicyControlTerminationRequestNotification(context.Background(), e.uri, *e.request)
rsp, err := client.DefaultCallbackApi.SmPolicyControlTerminationRequestNotification(context.Background(), e.uri, *e.request)
if err != nil {
if rsp != nil {
logger.NotifyEventLog.Warnf("SM Policy Termination Request Notification Error[%s]", rsp.Status)
Expand Down
6 changes: 2 additions & 4 deletions internal/notifyevent/send_smpolicy_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@ import (
"context"
"net/http"

"github.com/tim-ywliu/event"

"github.com/omec-project/openapi/models"
"github.com/omec-project/pcf/logger"
"github.com/omec-project/pcf/util"
"github.com/tim-ywliu/event"
)

const SendSMpolicyUpdateNotifyEventName event.Name = "SendSMpolicyUpdateNotify"
Expand All @@ -31,8 +30,7 @@ func (e SendSMpolicyUpdateNotifyEvent) Handle() {
}
client := util.GetNpcfSMPolicyCallbackClient()
logger.NotifyEventLog.Infof("Send SM Policy Update Notification to SMF")
_, httpResponse, err :=
client.DefaultCallbackApi.SmPolicyUpdateNotification(context.Background(), e.uri, *e.request)
_, httpResponse, err := client.DefaultCallbackApi.SmPolicyUpdateNotification(context.Background(), e.uri, *e.request)
if err != nil {
if httpResponse != nil {
logger.NotifyEventLog.Warnf("SM Policy Update Notification Error[%s]", httpResponse.Status)
Expand Down
3 changes: 1 addition & 2 deletions logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ import (
"time"

formatter "github.com/antonfisher/nested-logrus-formatter"
"github.com/sirupsen/logrus"

"github.com/omec-project/util/logger"
"github.com/omec-project/util/logger_conf"
"github.com/sirupsen/logrus"
)

var (
Expand Down
3 changes: 1 addition & 2 deletions oam/api_get_am_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@ import (
"net/http"

"github.com/gin-gonic/gin"

"github.com/omec-project/util/httpwrapper"
"github.com/omec-project/openapi"
"github.com/omec-project/openapi/models"
"github.com/omec-project/pcf/logger"
"github.com/omec-project/pcf/producer"
"github.com/omec-project/util/httpwrapper"
)

func setCorsHeader(c *gin.Context) {
Expand Down
3 changes: 1 addition & 2 deletions oam/routers.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ import (
"net/http"

"github.com/gin-gonic/gin"

logger_util "github.com/omec-project/util/logger"
"github.com/omec-project/pcf/logger"
logger_util "github.com/omec-project/util/logger"
)

// Route is the information for every URI.
Expand Down
5 changes: 2 additions & 3 deletions pcf.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@ import (
"os"
"runtime"

"github.com/sirupsen/logrus"
"github.com/urfave/cli"

"github.com/omec-project/pcf/logger"
"github.com/omec-project/pcf/service"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
)

var PCF = &service.PCF{}
Expand Down
6 changes: 4 additions & 2 deletions pcf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ import (
"github.com/stretchr/testify/require"
)

var PCFTest = &service.PCF{}
var bitRateValues = make(map[int64]string)
var (
PCFTest = &service.PCF{}
bitRateValues = make(map[int64]string)
)

func init() {
bitRateValues = map[int64]string{
Expand Down
Loading

0 comments on commit 562ad84

Please sign in to comment.