From 249016594748cf84c9020ef7e403b7edcec814fb Mon Sep 17 00:00:00 2001 From: "Marikkannu, Suresh" Date: Wed, 29 May 2024 16:44:17 -0700 Subject: [PATCH] Update GHAs, Dockerfile, license headers and Makefile --- .github/workflows/docker.yml | 72 ------------ .github/workflows/main.yml | 17 ++- .github/workflows/push.yml | 207 +++++++++++++++++++++++++++++++++++ .reuse/dep5 | 12 -- Dockerfile | 24 ++-- Makefile | 17 +-- README.md | 37 +++++-- VERSION.license | 3 + go.mod.license | 3 + go.sum.license | 3 + 10 files changed, 275 insertions(+), 120 deletions(-) delete mode 100644 .github/workflows/docker.yml create mode 100644 .github/workflows/push.yml delete mode 100644 .reuse/dep5 create mode 100644 VERSION.license create mode 100644 go.mod.license create mode 100644 go.sum.license diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml deleted file mode 100644 index a36a5f8..0000000 --- a/.github/workflows/docker.yml +++ /dev/null @@ -1,72 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 -# Copyright 2022-present Open Networking Foundation - -name: Publish pfcpsim -on: - push: - branches: - - main - -jobs: - push-images: - if: github.repository_owner == 'omec-project' - runs-on: ubuntu-latest - timeout-minutes: 20 - env: - DOCKER_REPO: 'opennetworking/pfcpsim' - - steps: - - name: Checkout this repository - uses: actions/checkout@v4 - - - name: Read version file - run: echo VERSION=$(cat ./VERSION) >> $GITHUB_ENV - - - name: Build protobuf - id: check - run: | - make build-proto - echo "::set-output name=PORCELAIN::`git status --porcelain`" - # Verify that protobuf is in sync with changes - - name: Check protobuf is sync - if: ${{ steps.check.outputs.PORCELAIN != '' }} - uses: actions/github-script@v7 - with: - script: | - core.setFailed('Please run make build-proto and commit changes to compiled protobuf') - - - uses: docker/login-action@v3.1.0 - with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} - - - name: Get short SHA - run: echo GIT_SHA_SHORT=$(git rev-parse --short HEAD) >> $GITHUB_ENV - - - name: Build with Docker - uses: docker/build-push-action@v5 - with: - context: . - push: false - load: true - tags: | - ${{ env.DOCKER_REPO }}:${{ env.VERSION }} - ${{ env.DOCKER_REPO }}:latest - ${{ env.DOCKER_REPO }}:${{ env.GIT_SHA_SHORT }} - target: 'pfcpsim' - - - name: Test docker build - run: | - docker run --rm ${{ env.DOCKER_REPO }}:latest --help - docker run --rm --entrypoint pfcpctl ${{ env.DOCKER_REPO }}:latest --help - - - name: Push to registry - uses: docker/build-push-action@v5 - with: - context: . - push: true - tags: | - ${{ env.DOCKER_REPO }}:${{ env.VERSION }} - ${{ env.DOCKER_REPO }}:latest - ${{ env.DOCKER_REPO }}:${{ env.GIT_SHA_SHORT }} - target: 'pfcpsim' diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index b56bc36..27a323f 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -2,7 +2,7 @@ # Copyright 2022-present Open Networking Foundation # Copyright 2024-present Intel Corporation -name: Master workflow +name: Main workflow on: push: branches: @@ -46,6 +46,21 @@ jobs: version: latest args: -v --config ./.golangci.yml + hadolint: + name: hadolint + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: Dockerfile linter + uses: hadolint/hadolint-action@v3.1.0 + # For now, ignoring: + # DL3018 warning: Pin versions in apk add (e.g., apk add =) + with: + dockerfile: Dockerfile + ignore: DL3018 + license-check: runs-on: ubuntu-latest steps: diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml new file mode 100644 index 0000000..8184ab1 --- /dev/null +++ b/.github/workflows/push.yml @@ -0,0 +1,207 @@ +# SPDX-License-Identifier: Apache-2.0 +# Copyright 2022-present Open Networking Foundation +name: GitHub release and Docker images + +on: + push: + branches: + - main + tags: + - v* + +jobs: + push-images: + runs-on: ubuntu-latest + if: github.repository_owner == 'omec-project' + timeout-minutes: 20 + env: + REGISTRY: registry.aetherproject.org + DOCKER_REGISTRY: registry.aetherproject.org/ + DOCKER_REPOSITORY: sdcore/ + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-go@v5 + with: + go-version-file: 'go.mod' + + - name: Build protobuf + id: check + run: | + make build-proto + echo "porcelain=$(git status --porcelain)" >> $GITHUB_OUTPUT + + # Verify that protobuf is in-sync with changes + - name: Check protobuf is sync + if: ${{ steps.check.outputs.porcelain != '' }} + uses: actions/github-script@v7 + with: + script: | + core.setFailed('Please run make build-proto to compile protobuf and commit changes') + + - run: echo GIT_SHA_SHORT=$(git rev-parse --short HEAD) >> $GITHUB_ENV + + - uses: docker/login-action@v3.1.0 + with: + registry: ${{ env.REGISTRY }} + username: ${{ secrets.AETHER_REGISTRY_USERNAME }} + password: ${{ secrets.AETHER_REGISTRY_PASSWORD }} + + - name: Build and push "latest" Docker image + env: + DOCKER_TAG: latest + run: | + make docker-build + make docker-push + + - name: Build and push "GIT_SHA" Docker image + env: + DOCKER_TAG: ${{ env.GIT_SHA_SHORT }} + run: | + make docker-build + make docker-push + + # CAUTION: Other actions depend on this name "tag-github" + tag-github: + runs-on: ubuntu-latest + if: github.repository_owner == 'omec-project' + outputs: + changed: ${{ steps.version-change.outputs.changed }} + version: ${{ steps.version-change.outputs.version }} + release_branch: ${{ steps.version-change.outputs.release_branch }} + version_branch: ${{ steps.version-change.outputs.version_branch }} + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Get changes + id: version-file + run: | + if git diff --name-only ${{ github.event.before }} ${{ github.event.after }} | grep VERSION; then + echo "changed=true" >> $GITHUB_OUTPUT + version_before=$(git show ${{ github.event.before }}:VERSION) + echo "version_before=$version_before" >> $GITHUB_OUTPUT + else + echo "VERSION file was not changed" + fi + + - name: Validate change in version file + id: version-change + if: steps.version-file.outputs.changed == 'true' + run: | + version=$(cat VERSION) + version_before_full=${{ steps.version-file.outputs.version_before }} + version_before=${version_before_full::-4} + echo "version=$version" + echo "version_before=$version_before" + validate="^[0-9]+\.[0-9]+\.[0-9]+$" + if [[ $version =~ $validate ]]; then + echo "changed=true" >> $GITHUB_OUTPUT + echo "version=$version" >> $GITHUB_OUTPUT + else + echo "Version change not for release" + fi + if [[ $version_before =~ $validate ]]; then + IFS='.' read -r major minor patch <<< "$version" + IFS='.' read -r major_b minor_b patch_b <<< "$version_before" + if [[ "$major" -ne "$major_b" ]] || [[ "$minor" -ne "$minor_b" ]]; then + version_branch="$major_b.$minor_b" + echo "release_branch=true" >> $GITHUB_OUTPUT + echo "version_branch=$version_branch" >> $GITHUB_OUTPUT + fi + else + echo "Version change not for branch release" + fi + + - name: Create release using REST API + if: steps.version-change.outputs.changed == 'true' + run: | + curl -L \ + -X POST \ + -H "Accept: application/vnd.github+json" \ + -H "Authorization: Bearer ${{ secrets.GH_OMEC_PAT }}" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + https://api.github.com/repos/${{ github.repository }}/releases \ + -d '{ + "tag_name": "v${{ steps.version-change.outputs.version }}", + "target_commitish": "${{ github.event.repository.default_branch }}", + "name": "v${{ steps.version-change.outputs.version }}", + "draft": false, + "prerelease": false, + "generate_release_notes": true + }' + + release-image: + runs-on: ubuntu-latest + needs: tag-github + if: needs.tag-github.outputs.changed == 'true' + env: + REGISTRY: docker.io + DOCKER_REGISTRY: docker.io/ + DOCKER_REPOSITORY: omecproject/ + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-go@v5 + with: + go-version-file: 'go.mod' + + - uses: docker/login-action@v3.1.0 + with: + registry: ${{ env.REGISTRY }} + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_PASSWORD }} + + - name: Build and push release Docker image + env: + DOCKER_TAG: rel-${{ needs.tag-github.outputs.version }} + run: | + make docker-build + make docker-push + + update-version: + runs-on: ubuntu-latest + needs: tag-github + if: needs.tag-github.outputs.changed == 'true' + steps: + - uses: actions/checkout@v4 + + - name: Increment version + run: | + version=${{ needs.tag-github.outputs.version }} + IFS='.' read -r major minor patch <<< "$version" + patch_update=$((patch+1)) + NEW_VERSION="$major.$minor.$patch_update-dev" + echo $NEW_VERSION > VERSION + echo "Updated version: $NEW_VERSION" + + - name: Create Pull Request + uses: peter-evans/create-pull-request@v6 + with: + token: ${{ secrets.GH_OMEC_PAT }} + commit-message: Update version + committer: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> + author: ${{ github.actor }} <${{ github.actor_id }}+${{ github.actor }}@users.noreply.github.com> + signoff: false + branch: version-update + delete-branch: true + title: Update version + body: | + Update VERSION file + add-paths: | + VERSION + + branch-release: + runs-on: ubuntu-latest + needs: tag-github + if: (needs.tag-github.outputs.changed == 'true') && (needs.tag-github.outputs.release_branch == 'true') + env: + GITHUB_TOKEN: ${{ secrets.GH_OMEC_PAT }} + steps: + - uses: actions/checkout@v4 + + - uses: peterjgrainger/action-create-branch@v3.0.0 + with: + branch: "rel-${{ needs.tag-github.outputs.version_branch }}" + sha: '${{ github.event.pull_request.head.sha }}' diff --git a/.reuse/dep5 b/.reuse/dep5 deleted file mode 100644 index cb7ca2e..0000000 --- a/.reuse/dep5 +++ /dev/null @@ -1,12 +0,0 @@ -Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ -Upstream-Name: pfcpsim -Upstream-Contact: OMEC Developers -Source: https://github.com/omec-project/pfcpsim - -Files: api/**/*.pb.go -Copyright: 2022-present Open Networking Foundation -License: Apache-2.0 - -Files: VERSION README.md go.mod go.sum docs/images/schema.svg -Copyright: 2022-present Open Networking Foundation -License: Apache-2.0 diff --git a/Dockerfile b/Dockerfile index 77b9712..70ea439 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,29 +1,21 @@ # SPDX-License-Identifier: Apache-2.0 # Copyright 2022-present Open Networking Foundation +# Copyright 2024-present Intel Corporation # Stage pfcpsim-build: builds the pfcpsim docker image -FROM golang:alpine AS builder +FROM golang:1.22.3-bookworm AS builder WORKDIR /pfcpctl -COPY go.mod ./go.mod -COPY go.sum ./go.sum +COPY . . -RUN go mod download -# exploit local cache -VOLUME $(go env GOCACHE):/root/.cache/go-build - -COPY . ./ -RUN CGO_ENABLED=0 go build -o /bin/pfcpctl cmd/pfcpctl/main.go -RUN CGO_ENABLED=0 go build -o /bin/pfcpsim cmd/pfcpsim/main.go +RUN CGO_ENABLED=0 go build -o ./pfcpctl cmd/pfcpctl/main.go && \ + CGO_ENABLED=0 go build -o ./pfcpsim cmd/pfcpsim/main.go # Stage pfcpsim: runtime image of pfcpsim, containing also pfcpctl -FROM alpine AS pfcpsim - -RUN apk update && apk add tcpdump +FROM alpine:3.20 AS pfcpsim -COPY --from=builder /bin/pfcpctl /bin -COPY --from=builder /bin/pfcpsim /bin +RUN apk update && apk add --no-cache -U tcpdump -RUN echo "export PATH=/bin:${PATH}" >> /root/.bashrc +COPY --from=builder /pfcpctl/pfcp* /usr/local/bin ENTRYPOINT [ "pfcpsim" ] diff --git a/Makefile b/Makefile index fdf887c..66e039b 100644 --- a/Makefile +++ b/Makefile @@ -1,23 +1,26 @@ # SPDX-License-Identifier: Apache-2.0 # Copyright 2022-present Open Networking Foundation -PROJECT_NAME := pfcpsim -VERSION ?= $(shell cat ./VERSION) +PROJECT_NAME := sdcore +DOCKER_VERSION ?= $(shell cat ./VERSION) ## Docker related DOCKER_REGISTRY ?= DOCKER_REPOSITORY ?= -DOCKER_TAG ?= ${VERSION} +DOCKER_TAG ?= ${DOCKER_VERSION} DOCKER_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}${PROJECT_NAME}:${DOCKER_TAG} DOCKER_BUILDKIT ?= 1 DOCKER_TARGET ?= pfcpsim docker-build: - DOCKER_BUILDKIT=$(DOCKER_BUILDKIT) docker build -f Dockerfile . \ - --target $(DOCKER_TARGET) \ - --cache-from ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}$(DOCKER_TARGET):${DOCKER_TAG} \ - --tag ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}$(DOCKER_TARGET):${DOCKER_TAG} + DOCKER_BUILDKIT=$(DOCKER_BUILDKIT) docker build \ + --target $(DOCKER_TARGET) \ + --tag ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}$(DOCKER_TARGET):${DOCKER_TAG} \ + . + +docker-push: + docker push ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}$(DOCKER_TARGET):${DOCKER_TAG} golint: @docker run --rm -v $(CURDIR):/app -w /app/pkg/pfcpsim golangci/golangci-lint:latest golangci-lint run -v --config /app/.golangci.yml diff --git a/README.md b/README.md index fd21e93..6f83947 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,25 @@ + [![Go Report Card](https://goreportcard.com/badge/github.com/omec-project/pfcpsim)](https://goreportcard.com/report/github.com/omec-project/pfcpsim) # pfcpsim -pfcpsim is a simulator to interact with PFCP agents. Can be used to simulate a 4G SGW-C / 5G SMF. +pfcpsim is a PFCP simulator to interact with PFCP agents and can be used to +simulate a 4G SGW-C or 5G SMF. + +> All related features are implemented according to the 3GPP TS 29.244 V16.3.1 (2020-04). -> All related features are implemented according to the 3GPP TS 29.244 V16.3.1(2020-04). ## Overview -pfcpsim is designed to work within a containerized environment. The docker image comes with both client (`pfcpctl`) and server (`pfcpsim`). +pfcpsim is designed to work within a containerized environment. The docker image +comes with both client (`pfcpctl`) and server (`pfcpsim`). -`PFCPClient` is embedded in a gRPC Server. Interaction between pfcpsim and pfcpctl is performed through RPCs, as shown in the following schema: +`PFCPClient` is embedded in a gRPC Server. Interaction between pfcpsim and pfcpctl +is performed through RPCs, as shown in the following schema: ![Alt text](docs/images/schema.svg) @@ -16,12 +27,14 @@ pfcpsim is designed to work within a containerized environment. The docker image ### Normal Case -#### 1. Create the container. Images are available on [DockerHub](https://hub.docker.com/r/opennetworking/pfcpsim/tags): +#### 1. Deploy container +Note: Release images are available on [DockerHub](https://hub.docker.com/r/omecproject/pfcpsim/tags), +while per-PR images are available on [Aether registry](https://registry.aetherproject.org/harbor/projects/9/repositories/pfcpsim/artifacts-tab) ```bash docker container run --rm -d --name pfcpsim pfcpsim: -p 12345 --interface ``` - `-p` (**optional**, default is 54321): to set a custom gRPC listening port - - `--interface` (**optional**, default is first non-loopback interface): to specify a specific interface from which retrieve local IP address + - `--interface` (**optional**, default is first non-loopback interface): to indicate a specific interface from which retrieve the local IP address #### 2. Use `pfcpctl` to configure server's remote peer address and N3 interface address: ```bash @@ -47,7 +60,7 @@ docker exec pfcpsim pfcpctl -s localhost:12345 session create --count 5 --baseID - `--count` the amount of sessions to create - `--baseID` the base ID used to incrementally create sessions - `--ue-pool` the IP pool from which UE addresses will be generated (e.g. `17.0.0.0/24`) - - `--gnb-addr` the (e/g)NodeB address + - `--gnb-addr` the (e/g)NodeB address - `--sdf-filter` (optional) the SDF Filter to use when creating PDRs. If not set, PDI will contain a SDF Filter IE with an empty string as SDF Filter. #### 5. Delete the sessions @@ -89,7 +102,7 @@ sim := export.NewPfcpSimCfg(iface, upfN3, upfN4) You can run the fuzzing test by the following command: ``` -go test -fuzz=Fuzz -p 1 -parallel 1 -fuzztime 15m ./fuzz/... +go test -fuzz=Fuzz -p 1 -parallel 1 -fuzztime 15m ./fuzz/... ``` To specify args: ``` @@ -119,7 +132,7 @@ failure while testing seed corpus entry: Fuzz/seed#0 fuzz: elapsed: 5s, gathering baseline coverage: 0/106 completed --- FAIL: Fuzz (5.02s) --- FAIL: Fuzz (5.00s) - ie_fuzz_test.go:57: + ie_fuzz_test.go:57: Error Trace: /home/xxxx/pfcpsim/fuzz/ie_fuzz_test.go:57 /usr/local/go/src/reflect/value.go:556 /usr/local/go/src/reflect/value.go:339 @@ -128,7 +141,7 @@ fuzz: elapsed: 5s, gathering baseline coverage: 0/106 completed route ip+net: no such network interface Test: Fuzz Messages: InitPFCPSim failed - + FAIL exit status 1 FAIL github.com/omec-project/pfcpsim/fuzz 5.023s @@ -153,8 +166,8 @@ go build -o client cmd/pfcpctl/main.go ``` You can now place `server` and `client` wherever you want. -To setup pfcpsim use the same steps shown above (without executing `docker`). E.G: +To setup `pfcpsim` use the same steps shown above (without executing `docker`) +as shown below: ```bash ./server -p 12345 --interface ``` - diff --git a/VERSION.license b/VERSION.license new file mode 100644 index 0000000..98a91cd --- /dev/null +++ b/VERSION.license @@ -0,0 +1,3 @@ +SPDX-FileCopyrightText: 2022-present Open Networking Foundation + +SPDX-License-Identifier: Apache-2.0 diff --git a/go.mod.license b/go.mod.license new file mode 100644 index 0000000..98a91cd --- /dev/null +++ b/go.mod.license @@ -0,0 +1,3 @@ +SPDX-FileCopyrightText: 2022-present Open Networking Foundation + +SPDX-License-Identifier: Apache-2.0 diff --git a/go.sum.license b/go.sum.license new file mode 100644 index 0000000..98a91cd --- /dev/null +++ b/go.sum.license @@ -0,0 +1,3 @@ +SPDX-FileCopyrightText: 2022-present Open Networking Foundation + +SPDX-License-Identifier: Apache-2.0