Skip to content

Commit

Permalink
upgrade packages version in go.mod and add golangci rules
Browse files Browse the repository at this point in the history
  • Loading branch information
free5gc-org committed Oct 14, 2021
1 parent fb08751 commit 7fc3f3c
Show file tree
Hide file tree
Showing 13 changed files with 349 additions and 393 deletions.
17 changes: 17 additions & 0 deletions .drone.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
kind: pipeline
name: development

steps:
- name: Check coding style
pull: never
image: drone/base:golangci-lint
depends_on: [ clone ]
commands:
- golangci-lint run ./...

- name: Unit test and build
pull: never
image: drone/base:gotest
depends_on: [ clone ]
commands:
- gotestsum ./... -v -cover -race
52 changes: 47 additions & 5 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ run:
# exit code when at least one issue was found, default is 1
issues-exit-code: 1
# include test files or not, default is true
tests: false
tests: true
# list of build tags, all linters use it. Default is empty list.
build-tags:
# which dirs to skip: issues from them won't be reported;
Expand Down Expand Up @@ -204,6 +204,33 @@ linters-settings:
whitespace:
multi-if: false # Enforces newlines (or comments) after every multi-line if statement
multi-func: false # Enforces newlines (or comments) after every multi-line function signature
gci:
local-prefixes: "github.com/free5gc"
misspell:
#locale: US
ignore-words:
whitespace:
multi-if: false # Enforces newlines (or comments) after every multi-line if statement
multi-func: false # Enforces newlines (or comments) after every multi-line function signature
wsl:
# If true append is only allowed to be cuddled if appending value is
# matching variables, fields or types on line above. Default is true.
strict-append: true
# Allow calls and assignments to be cuddled as long as the lines have any
# matching variables, fields or types. Default is true.
allow-assign-and-call: true
# Allow multiline assignments to be cuddled. Default is true.
allow-multiline-assign: true
# Allow declarations (var) to be cuddled.
allow-cuddle-declarations: false
# Allow trailing comments in ending of blocks
allow-trailing-comment: true
# Force newlines in end of case at this limit (0 = never).
force-case-trailing-whitespace: 0
# Force cuddling of err checks with err var assignment
force-err-cuddling: false
# Allow leading comments to be separated with empty liens
allow-separated-leading-comment: false
custom:
# Each custom linter should have a unique name.

Expand All @@ -223,12 +250,27 @@ linters:
# Additional
- lll
- godox
# - gomnd
#- maligned
#- nestif
#- gomnd
#- goconst
#- gocognit
# - gocognit
# - maligned
# - nestif
# - gomodguard
- nakedret
- gci
- misspell
- gofumpt
- whitespace
- unconvert
- predeclared
- noctx
- dogsled
- bodyclose
- asciicheck
#- stylecheck
# - unparam
# - wsl

#disable-all: false
fast: true
issues:
Expand Down
11 changes: 4 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@ module github.com/free5gc/ngap
go 1.14

require (
github.com/antonfisher/nested-logrus-formatter v1.3.0
github.com/free5gc/aper v1.0.1
github.com/free5gc/logger_conf v1.0.0
github.com/free5gc/logger_util v1.0.0
github.com/free5gc/openapi v1.0.0
github.com/sirupsen/logrus v1.7.0
github.com/stretchr/testify v1.6.1
github.com/antonfisher/nested-logrus-formatter v1.3.1
github.com/free5gc/aper v1.0.2
github.com/free5gc/openapi v1.0.2
github.com/sirupsen/logrus v1.8.1
)
112 changes: 24 additions & 88 deletions go.sum

Large diffs are not rendered by default.

30 changes: 11 additions & 19 deletions logger/logger.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
package logger

import (
"os"
"time"

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

"github.com/free5gc/logger_conf"
"github.com/free5gc/logger_util"
)

var log *logrus.Logger
var NgapLog *logrus.Entry
var (
log *logrus.Logger
NgapLog *logrus.Entry
)

func init() {
log = logrus.New()
Expand All @@ -26,25 +24,19 @@ func init() {
FieldsOrder: []string{"component", "category"},
}

free5gcLogHook, err := logger_util.NewFileHook(logger_conf.Free5gcLogFile, os.O_CREATE|os.O_APPEND|os.O_RDWR, 0666)
if err == nil {
log.Hooks.Add(free5gcLogHook)
}

selfLogHook, err := logger_util.NewFileHook(logger_conf.LibLogDir+"ngap.log", os.O_CREATE|os.O_APPEND|os.O_RDWR, 0666)
if err == nil {
log.Hooks.Add(selfLogHook)
}

NgapLog = log.WithFields(logrus.Fields{"component": "LIB", "category": "NGAP"})
}

func GetLogger() *logrus.Logger {
return log
}

func SetLogLevel(level logrus.Level) {
NgapLog.Infoln("set log level :", level)
log.SetLevel(level)
}

func SetReportCaller(bool bool) {
NgapLog.Infoln("set report call :", bool)
log.SetReportCaller(bool)
func SetReportCaller(enable bool) {
NgapLog.Infoln("set report call :", enable)
log.SetReportCaller(enable)
}
2 changes: 0 additions & 2 deletions ngap.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ func Encoder(pdu ngapType.NGAPPDU) ([]byte, error) {
}

func PrintResult(v reflect.Value, layer int) string {

fieldType := v.Type()
if v.Kind() == reflect.Ptr {
return "&" + PrintResult(v.Elem(), layer)
Expand Down Expand Up @@ -85,7 +84,6 @@ func PrintResult(v reflect.Value, layer int) string {
s = fmt.Sprintf("INTEGER(%d)\n", v.Int())
default:
fmt.Printf("Type: %s does not handle", v.Type())

}
return s
}
4 changes: 2 additions & 2 deletions ngapConvert/IpAddress.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package ngapConvert

import (
"net"

"github.com/free5gc/aper"
"github.com/free5gc/ngap/logger"
"github.com/free5gc/ngap/ngapType"
"net"
)

func IPAddressToString(ipAddr ngapType.TransportLayerAddress) (ipv4Addr, ipv6Addr string) {

ip := ipAddr.Value

// Described in 38.414
Expand Down
1 change: 0 additions & 1 deletion ngapConvert/RATRestrictionInformation.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (

// TS 38.413 9.3.1.85
func RATRestrictionInformationToNgap(ratType models.RatType) (ratResInfo ngapType.RATRestrictionInformation) {

// Only support EUTRA & NR in version15.2.0
switch ratType {
case models.RatType_EUTRA:
Expand Down
3 changes: 0 additions & 3 deletions ngapConvert/RanId.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,10 @@ func RanIdToModels(ranNodeId ngapType.GlobalRANNodeID) (ranId models.GlobalRanNo
} else if ngapNgENBID.NgENBID.Present == ngapType.NgENBIDPresentShortMacroNgENBID {
shortMacroNgENBID := ngapNgENBID.NgENBID.ShortMacroNgENBID
ranId.NgeNbId = "SMacroNGeNB-" + BitStringToHex(shortMacroNgENBID)

} else if ngapNgENBID.NgENBID.Present == ngapType.NgENBIDPresentLongMacroNgENBID {
longMacroNgENBID := ngapNgENBID.NgENBID.LongMacroNgENBID
ranId.NgeNbId = "LMacroNGeNB-" + BitStringToHex(longMacroNgENBID)
}

case ngapType.GlobalRANNodeIDPresentGlobalN3IWFID:
ngapN3IWFID := ranNodeId.GlobalN3IWFID
plmnid := PlmnIdToModels(ngapN3IWFID.PLMNIdentity)
Expand All @@ -61,7 +59,6 @@ func RanIDToNgap(modelsRanNodeId models.GlobalRanNodeId) ngapType.GlobalRANNodeI
globalGNBID.GNBID.Present = ngapType.GNBIDPresentGNBID
globalGNBID.GNBID.GNBID = new(aper.BitString)
*globalGNBID.GNBID.GNBID = HexToBitString(modelsRanNodeId.GNbId.GNBValue, int(modelsRanNodeId.GNbId.BitLength))

} else if modelsRanNodeId.NgeNbId != "" {
ngapRanNodeId.Present = ngapType.GlobalRANNodeIDPresentGlobalNgENBID
ngapRanNodeId.GlobalNgENBID = new(ngapType.GlobalNgENBID)
Expand Down
108 changes: 55 additions & 53 deletions ngapType/ProcedureCode.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,56 +6,58 @@ type ProcedureCode struct {
Value int64 `aper:"valueLB:0,valueUB:255"`
}

const ProcedureCodeAMFConfigurationUpdate int64 = 0
const ProcedureCodeAMFStatusIndication int64 = 1
const ProcedureCodeCellTrafficTrace int64 = 2
const ProcedureCodeDeactivateTrace int64 = 3
const ProcedureCodeDownlinkNASTransport int64 = 4
const ProcedureCodeDownlinkNonUEAssociatedNRPPaTransport int64 = 5
const ProcedureCodeDownlinkRANConfigurationTransfer int64 = 6
const ProcedureCodeDownlinkRANStatusTransfer int64 = 7
const ProcedureCodeDownlinkUEAssociatedNRPPaTransport int64 = 8
const ProcedureCodeErrorIndication int64 = 9
const ProcedureCodeHandoverCancel int64 = 10
const ProcedureCodeHandoverNotification int64 = 11
const ProcedureCodeHandoverPreparation int64 = 12
const ProcedureCodeHandoverResourceAllocation int64 = 13
const ProcedureCodeInitialContextSetup int64 = 14
const ProcedureCodeInitialUEMessage int64 = 15
const ProcedureCodeLocationReportingControl int64 = 16
const ProcedureCodeLocationReportingFailureIndication int64 = 17
const ProcedureCodeLocationReport int64 = 18
const ProcedureCodeNASNonDeliveryIndication int64 = 19
const ProcedureCodeNGReset int64 = 20
const ProcedureCodeNGSetup int64 = 21
const ProcedureCodeOverloadStart int64 = 22
const ProcedureCodeOverloadStop int64 = 23
const ProcedureCodePaging int64 = 24
const ProcedureCodePathSwitchRequest int64 = 25
const ProcedureCodePDUSessionResourceModify int64 = 26
const ProcedureCodePDUSessionResourceModifyIndication int64 = 27
const ProcedureCodePDUSessionResourceRelease int64 = 28
const ProcedureCodePDUSessionResourceSetup int64 = 29
const ProcedureCodePDUSessionResourceNotify int64 = 30
const ProcedureCodePrivateMessage int64 = 31
const ProcedureCodePWSCancel int64 = 32
const ProcedureCodePWSFailureIndication int64 = 33
const ProcedureCodePWSRestartIndication int64 = 34
const ProcedureCodeRANConfigurationUpdate int64 = 35
const ProcedureCodeRerouteNASRequest int64 = 36
const ProcedureCodeRRCInactiveTransitionReport int64 = 37
const ProcedureCodeTraceFailureIndication int64 = 38
const ProcedureCodeTraceStart int64 = 39
const ProcedureCodeUEContextModification int64 = 40
const ProcedureCodeUEContextRelease int64 = 41
const ProcedureCodeUEContextReleaseRequest int64 = 42
const ProcedureCodeUERadioCapabilityCheck int64 = 43
const ProcedureCodeUERadioCapabilityInfoIndication int64 = 44
const ProcedureCodeUETNLABindingRelease int64 = 45
const ProcedureCodeUplinkNASTransport int64 = 46
const ProcedureCodeUplinkNonUEAssociatedNRPPaTransport int64 = 47
const ProcedureCodeUplinkRANConfigurationTransfer int64 = 48
const ProcedureCodeUplinkRANStatusTransfer int64 = 49
const ProcedureCodeUplinkUEAssociatedNRPPaTransport int64 = 50
const ProcedureCodeWriteReplaceWarning int64 = 51
const ProcedureCodeSecondaryRATDataUsageReport int64 = 52
const (
ProcedureCodeAMFConfigurationUpdate int64 = 0
ProcedureCodeAMFStatusIndication int64 = 1
ProcedureCodeCellTrafficTrace int64 = 2
ProcedureCodeDeactivateTrace int64 = 3
ProcedureCodeDownlinkNASTransport int64 = 4
ProcedureCodeDownlinkNonUEAssociatedNRPPaTransport int64 = 5
ProcedureCodeDownlinkRANConfigurationTransfer int64 = 6
ProcedureCodeDownlinkRANStatusTransfer int64 = 7
ProcedureCodeDownlinkUEAssociatedNRPPaTransport int64 = 8
ProcedureCodeErrorIndication int64 = 9
ProcedureCodeHandoverCancel int64 = 10
ProcedureCodeHandoverNotification int64 = 11
ProcedureCodeHandoverPreparation int64 = 12
ProcedureCodeHandoverResourceAllocation int64 = 13
ProcedureCodeInitialContextSetup int64 = 14
ProcedureCodeInitialUEMessage int64 = 15
ProcedureCodeLocationReportingControl int64 = 16
ProcedureCodeLocationReportingFailureIndication int64 = 17
ProcedureCodeLocationReport int64 = 18
ProcedureCodeNASNonDeliveryIndication int64 = 19
ProcedureCodeNGReset int64 = 20
ProcedureCodeNGSetup int64 = 21
ProcedureCodeOverloadStart int64 = 22
ProcedureCodeOverloadStop int64 = 23
ProcedureCodePaging int64 = 24
ProcedureCodePathSwitchRequest int64 = 25
ProcedureCodePDUSessionResourceModify int64 = 26
ProcedureCodePDUSessionResourceModifyIndication int64 = 27
ProcedureCodePDUSessionResourceRelease int64 = 28
ProcedureCodePDUSessionResourceSetup int64 = 29
ProcedureCodePDUSessionResourceNotify int64 = 30
ProcedureCodePrivateMessage int64 = 31
ProcedureCodePWSCancel int64 = 32
ProcedureCodePWSFailureIndication int64 = 33
ProcedureCodePWSRestartIndication int64 = 34
ProcedureCodeRANConfigurationUpdate int64 = 35
ProcedureCodeRerouteNASRequest int64 = 36
ProcedureCodeRRCInactiveTransitionReport int64 = 37
ProcedureCodeTraceFailureIndication int64 = 38
ProcedureCodeTraceStart int64 = 39
ProcedureCodeUEContextModification int64 = 40
ProcedureCodeUEContextRelease int64 = 41
ProcedureCodeUEContextReleaseRequest int64 = 42
ProcedureCodeUERadioCapabilityCheck int64 = 43
ProcedureCodeUERadioCapabilityInfoIndication int64 = 44
ProcedureCodeUETNLABindingRelease int64 = 45
ProcedureCodeUplinkNASTransport int64 = 46
ProcedureCodeUplinkNonUEAssociatedNRPPaTransport int64 = 47
ProcedureCodeUplinkRANConfigurationTransfer int64 = 48
ProcedureCodeUplinkRANStatusTransfer int64 = 49
ProcedureCodeUplinkUEAssociatedNRPPaTransport int64 = 50
ProcedureCodeWriteReplaceWarning int64 = 51
ProcedureCodeSecondaryRATDataUsageReport int64 = 52
)
6 changes: 3 additions & 3 deletions ngapType/ProtocolIEField.go
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ type InitialContextSetupRequestIEsValue struct {
EmergencyFallbackIndicator *EmergencyFallbackIndicator `aper:"valueExt,referenceFieldValue:24"`
RRCInactiveTransitionReportRequest *RRCInactiveTransitionReportRequest `aper:"referenceFieldValue:91"`
UERadioCapabilityForPaging *UERadioCapabilityForPaging `aper:"valueExt,referenceFieldValue:118"`
RedirectionVoiceFallback *RedirectionVoiceFallback /* Do not find the Reference Field Value */
RedirectionVoiceFallback *RedirectionVoiceFallback `aper:"referenceFieldValue:146"`
}

type InitialContextSetupResponseIEs struct {
Expand Down Expand Up @@ -985,7 +985,7 @@ type HandoverRequestIEsValue struct {
LocationReportingRequestType *LocationReportingRequestType `aper:"valueExt,referenceFieldValue:33"`
RRCInactiveTransitionReportRequest *RRCInactiveTransitionReportRequest `aper:"referenceFieldValue:91"`
GUAMI *GUAMI `aper:"valueExt,referenceFieldValue:28"`
RedirectionVoiceFallback *RedirectionVoiceFallback /* Do not find the Reference Field Value */
RedirectionVoiceFallback *RedirectionVoiceFallback `aper:"referenceFieldValue:146"`
}

type HandoverRequestAcknowledgeIEs struct {
Expand Down Expand Up @@ -1115,7 +1115,7 @@ type PathSwitchRequestAcknowledgeIEsValue struct {
CoreNetworkAssistanceInformation *CoreNetworkAssistanceInformation `aper:"valueExt,referenceFieldValue:18"`
RRCInactiveTransitionReportRequest *RRCInactiveTransitionReportRequest `aper:"referenceFieldValue:91"`
CriticalityDiagnostics *CriticalityDiagnostics `aper:"valueExt,referenceFieldValue:19"`
RedirectionVoiceFallback *RedirectionVoiceFallback /* Do not find the Reference Field Value */
RedirectionVoiceFallback *RedirectionVoiceFallback `aper:"referenceFieldValue:146"`
}

type PathSwitchRequestFailureIEs struct {
Expand Down
Loading

0 comments on commit 7fc3f3c

Please sign in to comment.