From 90aa2d005f6fb231643b8694b234bd21bbad48d3 Mon Sep 17 00:00:00 2001 From: Ghislain Bourgeois Date: Wed, 24 Jan 2024 11:26:12 -0500 Subject: [PATCH 1/4] chore: Fix golangci-lint and standardize CI with other projects --- .github/workflows/go.yml | 29 ------------ .github/workflows/golangci-lint.yml | 38 --------------- .github/workflows/main.yml | 71 +++++++++++++++++++++++++++++ .golangci.yml | 11 +---- ngapConvert/TimeStamp.go | 49 ++++++++++---------- 5 files changed, 97 insertions(+), 101 deletions(-) delete mode 100644 .github/workflows/go.yml delete mode 100644 .github/workflows/golangci-lint.yml create mode 100644 .github/workflows/main.yml diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml deleted file mode 100644 index 827472a..0000000 --- a/.github/workflows/go.yml +++ /dev/null @@ -1,29 +0,0 @@ -# Copyright 2019 Communication Service/Software Laboratory, National Chiao Tung University (free5gc.org) -# -# SPDX-License-Identifier: Apache-2.0 - -name: Go - -on: - push: - branches: [ main ] - pull_request: - branches: [ main ] - -jobs: - - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - - name: Set up Go - uses: actions/setup-go@v2 - with: - go-version: '1.14.4' - - - name: Build - run: go build -v ./... - - - name: Test - run: go test -v ./... diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml deleted file mode 100644 index 4e754bd..0000000 --- a/.github/workflows/golangci-lint.yml +++ /dev/null @@ -1,38 +0,0 @@ -# Copyright 2019 Communication Service/Software Laboratory, National Chiao Tung University (free5gc.org) -# -# SPDX-License-Identifier: Apache-2.0 - -name: golangci-lint - -on: - push: - tags: - - v* - branches: [ main ] - pull_request: - branches: [ main ] - -jobs: - - golangci: - name: lint - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: Run golangci-lint - uses: golangci/golangci-lint-action@v2 - with: - # Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version. - version: v1.35.0 - - # Optional: working directory, useful for monorepos - # working-directory: somedir - - # Optional: golangci-lint command line arguments. - # args: --issues-exit-code=0 - - # Optional: show only new issues if it's a pull request. The default value is `false`. - # only-new-issues: true - - # Optional: if set to true then the action will use pre-installed Go - # skip-go-installation: true diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..7b2415b --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,71 @@ +# SPDX-License-Identifier: Apache-2.0 +# Copyright 2024 Canonical Ltd. + +name: Main workflow + +on: + pull_request: + branches: + - main + push: + branches: + - main + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-go@v5 + with: + go-version-file: 'go.mod' + + - name: Build + run: go build + + lint: + name: lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-go@v5 + with: + go-version-file: 'go.mod' + + - name: golangci-lint + uses: golangci/golangci-lint-action@v3.7.0 + with: + version: latest + args: -v --config ./.golangci.yml + + license-check: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: reuse lint + uses: fsfe/reuse-action@v2 + + fossa-check: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: FOSSA scan + uses: fossa-contrib/fossa-action@v3 + with: + fossa-api-key: 9dc8fa92e3dd565687317beb87b56d89 + + unit-tests: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-go@v5 + with: + go-version-file: 'go.mod' + + - name: Unit tests + run: go test ./... diff --git a/.golangci.yml b/.golangci.yml index 3c26314..dfe232a 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -213,9 +213,6 @@ linters-settings: 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. @@ -246,18 +243,14 @@ linters: - staticcheck - unused - gosimple - - structcheck - - varcheck - ineffassign - - deadcode - typecheck # Additional - lll - godox #- gomnd - #- goconst + - goconst # - gocognit - # - maligned # - nestif # - gomodguard - nakedret @@ -272,7 +265,7 @@ linters: - bodyclose - asciicheck #- stylecheck - # - unparam + - unparam # - wsl #disable-all: false diff --git a/ngapConvert/TimeStamp.go b/ngapConvert/TimeStamp.go index 48b39a5..84816c7 100644 --- a/ngapConvert/TimeStamp.go +++ b/ngapConvert/TimeStamp.go @@ -14,31 +14,30 @@ import ( /* RFC 5905 Section 6 https://tools.ietf.org/html/rfc5905#section-6 - 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Seconds | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Fraction | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - - NTP Timestamp Format - - The 64-bit timestamp format is used in packet headers and other - places with limited word size. It includes a 32-bit unsigned seconds - field spanning 136 years and a 32-bit fraction field resolving 232 - picoseconds. The 32-bit short format is used in delay and dispersion - header fields where the full resolution and range of the other - formats are not justified. It includes a 16-bit unsigned seconds - field and a 16-bit fraction field. - - In the date and timestamp formats, the prime epoch, or base date of - era 0, is 0 h 1 January 1900 UTC, when all bits are zero. It should - be noted that strictly speaking, UTC did not exist prior to 1 January - 1972, but it is convenient to assume it has existed for all eternity, - even if all knowledge of historic leap seconds has been lost. Dates - are relative to the prime epoch; values greater than zero represent - + 0 1 2 3 + 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Seconds | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Fraction | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + + NTP Timestamp Format + + The 64-bit timestamp format is used in packet headers and other + places with limited word size. It includes a 32-bit unsigned seconds + field spanning 136 years and a 32-bit fraction field resolving 232 + picoseconds. The 32-bit short format is used in delay and dispersion + header fields where the full resolution and range of the other + formats are not justified. It includes a 16-bit unsigned seconds + field and a 16-bit fraction field. + + In the date and timestamp formats, the prime epoch, or base date of + era 0, is 0 h 1 January 1900 UTC, when all bits are zero. It should + be noted that strictly speaking, UTC did not exist prior to 1 January + 1972, but it is convenient to assume it has existed for all eternity, + even if all knowledge of historic leap seconds has been lost. Dates + are relative to the prime epoch; values greater than zero represent */ func TimeStampToInt32(timeStampNgap aper.OctetString) (timeStamp int32) { if len(timeStampNgap) != 4 { From de1b7b4f5c4621ddc0ede9bda3824bc081661adc Mon Sep 17 00:00:00 2001 From: Ghislain Bourgeois Date: Wed, 24 Jan 2024 11:28:51 -0500 Subject: [PATCH 2/4] chore: Bump golang to 1.21 --- go.mod | 7 ++++++- go.sum | 3 --- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/go.mod b/go.mod index e78f017..8e53534 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ module github.com/omec-project/ngap -go 1.14 +go 1.21 require ( github.com/antonfisher/nested-logrus-formatter v1.3.1 @@ -12,3 +12,8 @@ require ( github.com/omec-project/openapi v1.1.0 github.com/sirupsen/logrus v1.8.1 ) + +require ( + github.com/golang-jwt/jwt v3.2.1+incompatible // indirect + golang.org/x/sys v0.0.0-20210423082822-04245dca01da // indirect +) diff --git a/go.sum b/go.sum index 1e18d19..e331c26 100644 --- a/go.sum +++ b/go.sum @@ -106,10 +106,8 @@ github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1: github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= -github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= -github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/mitchellh/mapstructure v1.4.1/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32/go.mod h1:9wM+0iRr9ahx58uYLpLIr5fm8diHn0JbqRycJi6w0Ms= @@ -369,7 +367,6 @@ google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpAD google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4= google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/h2non/gock.v1 v1.1.2/go.mod h1:n7UGz/ckNChHiK05rDoiC4MYSunEC/lyaUm2WWaDva0= From 45d5d018e15e6a90cdc05d102f14ded14beb2799 Mon Sep 17 00:00:00 2001 From: Ghislain Bourgeois Date: Wed, 24 Jan 2024 14:21:59 -0500 Subject: [PATCH 3/4] chore: Add simple unit test for encoding and decoding PDUs --- ngap_test.go | 97 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 ngap_test.go diff --git a/ngap_test.go b/ngap_test.go new file mode 100644 index 0000000..ce329b5 --- /dev/null +++ b/ngap_test.go @@ -0,0 +1,97 @@ +// Copyright 2024 Canonical, Ltd. +// +// SPDX-License-Identifier: Apache-2.0 + +package ngap_test + +import ( + "testing" + + "github.com/omec-project/aper" + "github.com/omec-project/ngap" + "github.com/omec-project/ngap/ngapType" +) + +// globalRANIDIE for MCC 208, MNC 93 +var globalRANIDIE ngapType.NGSetupRequestIEs = ngapType.NGSetupRequestIEs{ + Id: ngapType.ProtocolIEID{Value: ngapType.ProtocolIEIDGlobalRANNodeID}, + Criticality: ngapType.Criticality{Value: ngapType.CriticalityPresentReject}, + Value: ngapType.NGSetupRequestIEsValue{ + Present: ngapType.GlobalRANNodeIDPresentGlobalGNBID, + GlobalRANNodeID: &ngapType.GlobalRANNodeID{ + Present: ngapType.GlobalRANNodeIDPresentGlobalGNBID, + GlobalGNBID: &ngapType.GlobalGNBID{ + PLMNIdentity: ngapType.PLMNIdentity{Value: aper.OctetString{0x02, 0xF8, 0x39}}, + GNBID: ngapType.GNBID{ + Present: ngapType.GNBIDPresentGNBID, + GNBID: &aper.BitString{ + Bytes: []byte{0x00, 0x01, 0x02}, + BitLength: 24, + }, + }, + }, + }, + }, +} + +func TestSimplePDUEncoding(t *testing.T) { + // NGSetupRequest PDU + pdu := ngapType.NGAPPDU{ + Present: ngapType.NGAPPDUPresentInitiatingMessage, + InitiatingMessage: &ngapType.InitiatingMessage{ + ProcedureCode: ngapType.ProcedureCode{Value: ngapType.ProcedureCodeNGSetup}, + Criticality: ngapType.Criticality{Value: ngapType.CriticalityPresentReject}, + Value: ngapType.InitiatingMessageValue{ + Present: ngapType.InitiatingMessagePresentNGSetupRequest, + NGSetupRequest: &ngapType.NGSetupRequest{ + ProtocolIEs: ngapType.ProtocolIEContainerNGSetupRequestIEs{ + List: []ngapType.NGSetupRequestIEs{ + globalRANIDIE, + }, + }, + }, + }, + }, + } + + result, err := ngap.Encoder(pdu) + if err != nil { + t.Errorf("Could not encode simple PDU: %v; got error: %v\n", pdu, err) + } + + expected := []byte{ + 0x00, 0x15, 0x00, 0x0F, 0x00, 0x00, 0x01, 0x00, 0x1B, 0x00, + 0x08, 0x00, 0x02, 0xF8, 0x39, 0x10, 0x00, 0x01, 0x02, + } + + if len(result) != len(expected) { + t.Errorf("Got wrong result length: %v\n", len(result)) + } + + for i, b := range result { + if b != expected[i] { + t.Errorf("Byte %d was %v, expected %v\n", i, b, expected[i]) + } + } +} + +func TestSimplePDUDecoding(t *testing.T) { + // ASN.1 PER encoded PDU + pdu_bytes := []byte{ + 0x00, 0x15, 0x00, 0x0F, 0x00, 0x00, 0x01, 0x00, 0x1B, 0x00, + 0x08, 0x00, 0x02, 0xF8, 0x39, 0x10, 0x00, 0x01, 0x02, + } + + pdu, err := ngap.Decoder(pdu_bytes) + if err != nil { + t.Errorf("Could not decode simple PDU bytes: %v; got error: %v\n", pdu_bytes, err) + } + + ie := pdu.InitiatingMessage.Value.NGSetupRequest.ProtocolIEs.List[0] + plmn := ie.Value.GlobalRANNodeID.GlobalGNBID.PLMNIdentity.Value + + if len(plmn) != 3 || plmn[0] != 0x02 || plmn[1] != 0xF8 || plmn[2] != 0x39 { + t.Errorf("Failed decoding simple PDU: %v; Expected PLMN: %v, got %v\n", + pdu_bytes, []byte{0x02, 0xF8, 0x39}, plmn) + } +} From 5762f035ebd7dcbf32073b331233e1150ceb1f9e Mon Sep 17 00:00:00 2001 From: Ghislain Bourgeois Date: Wed, 24 Jan 2024 14:23:54 -0500 Subject: [PATCH 4/4] chore: Add dependabot configuration --- .github/dependabot.yml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 .github/dependabot.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..5b8854c --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,17 @@ +# SPDX-License-Identifier: Apache-2.0 +# Copyright 2022 Intel Corporation + +# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates +version: 2 +updates: + + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "daily" + + - package-ecosystem: "gomod" + directory: "/" + schedule: + interval: "daily" +