-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 7526ba6
Showing
19 changed files
with
809 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
version: 2 | ||
updates: | ||
# Maintain dependencies for GitHub Actions | ||
- package-ecosystem: "github-actions" | ||
directory: "/" | ||
schedule: | ||
interval: "daily" | ||
assignees: | ||
- "louisroyer" | ||
- package-ecosystem: "gomod" | ||
directory: "/" | ||
schedule: | ||
interval: "daily" | ||
assignees: | ||
- "louisroyer" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
name: Release | ||
on: | ||
push: | ||
tags: | ||
- "v[0-9]+.[0-9]+.[0-9]+" | ||
|
||
jobs: | ||
release: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: write | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
- name: Get version number | ||
id: version | ||
run: echo "version=$(echo ${{ github.ref_name }} | cut -c2- -)" >> $GITHUB_OUTPUT | ||
- name: Release | ||
uses: ncipollo/release-action@v1 | ||
with: | ||
generateReleaseNotes: true | ||
makeLatest: "legacy" | ||
name: "Version ${{ steps.version.outputs.version }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# This is a basic workflow to help you get started with Actions | ||
|
||
name: CI | ||
|
||
# Controls when the workflow will run | ||
on: | ||
# Triggers the workflow on push or pull request events but only for the "master" branch | ||
push: | ||
branches: [ "master" ] | ||
pull_request: | ||
branches: [ "master" ] | ||
|
||
# Allows you to run this workflow manually from the Actions tab | ||
workflow_dispatch: | ||
jobs: | ||
go_build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
- name: Setup Go | ||
uses: actions/setup-go@v5 | ||
- name: Install depends | ||
run: go get . | ||
- name: Build | ||
run: go build -v ./... | ||
- name: Vet | ||
run: go vet ./... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
repos: | ||
- repo: https://github.com/pre-commit/pre-commit-hooks | ||
rev: v4.6.0 | ||
hooks: | ||
- id: end-of-file-fixer | ||
- id: trailing-whitespace | ||
- id: mixed-line-ending | ||
exclude: ^.github/.*$ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright © 2023 Louis Royer | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# RFC 9433 | ||
This package provides functions to implement RFC 9433 (Segment Routing over IPv6 for the Mobile User Plane). | ||
|
||
## Licence | ||
MIT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// Copyright 2023 Louis Royer and the NextMN contributors. All rights reserved. | ||
// Use of this source code is governed by a MIT-style license that can be | ||
// found in the LICENSE file. | ||
// SPDX-License-Identifier: MIT | ||
|
||
// Package rfc9433 provides functions to implement RFC9433 (Segment Routing over IPv6 for the Mobile User Plane). | ||
package rfc9433 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
// Copyright 2023 Louis Royer and the NextMN contributors. All rights reserved. | ||
// Use of this source code is governed by a MIT-style license that can be | ||
// found in the LICENSE file. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package rfc9433 | ||
|
||
import "encoding/binary" | ||
import "github.com/nextmn/rfc9433/encoding/errors" | ||
|
||
const ( | ||
// Field TEID | ||
teidSizeByte = 4 // size of the field in bytes | ||
teidSizeBit = teidSizeByte * 8 // size of the field in bits | ||
teidPosByte = 1 // position of the field from the left in bytes | ||
|
||
// Field QFI | ||
qfiSizeBit = 6 // size of the field | ||
qfiPosBit = 2 // position from right of the byte in bits | ||
qfiPosByte = 0 // position from left in bytes | ||
qfiMask = (0xFF >> (8 - qfiSizeBit)) // mask (decoding: after shift to right; encoding before shift to left) | ||
|
||
// Field R | ||
rSizeBit = 1 // size of the field | ||
rPosBit = 1 // position from right of the byte in bits | ||
rPosByte = 0 // position from left in bytes | ||
rMask = (0xFF >> (8 - rSizeBit)) // mask (decoding: after shift to right; encoding before shift to left) | ||
|
||
// Field U | ||
uSizeBit = 1 // size of the field | ||
uPosBit = 0 // position from right of the byte in bits | ||
uPosByte = 0 // position from left in bytes | ||
uMask = (0xFF >> (8 - uSizeBit)) // mask (decoding: after shift to right; encoding before shift to left) | ||
) | ||
|
||
// Args.Mob.Session as defined in RFC 9433, section 6.1: | ||
// | ||
// 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 | ||
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
// | QFI |R|U| PDU Session ID | | ||
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
// |PDU Sess(cont')| | ||
// +-+-+-+-+-+-+-+-+ | ||
// Figure 8: Args.Mob.Session Format | ||
type ArgsMobSession struct { | ||
qfi uint8 // QoS Flow Identifier (6 bits) | ||
r uint8 // Reflective QoS Indication (1 bit) | ||
u uint8 // Unused and for future use (1 bit) | ||
pduSessionID uint32 // Identifier of PDU Session. The GTP-U equivalent is TEID (32 bits) | ||
} | ||
|
||
// NewArgsMobSession creates an ArgsMobSession. | ||
func NewArgsMobSession(qfi uint8, r bool, u bool, pduSessionID uint32) *ArgsMobSession { | ||
var ruint uint8 = 0 | ||
if r { | ||
ruint = 1 | ||
} | ||
var uuint uint8 = 0 | ||
if u { | ||
uuint = 1 | ||
} | ||
return &ArgsMobSession{ | ||
qfi: qfi, | ||
r: ruint, | ||
u: uuint, | ||
pduSessionID: pduSessionID, | ||
} | ||
} | ||
|
||
// ParseArgsMobSession parses given byte sequence as an ArgsMobSession. | ||
func ParseArgsMobSession(b []byte) (*ArgsMobSession, error) { | ||
a := &ArgsMobSession{} | ||
if err := a.UnmarshalBinary(b); err != nil { | ||
return nil, err | ||
} | ||
return a, nil | ||
} | ||
|
||
// QFI returns the Qos Flow Identifier for this ArgsMobSession. | ||
func (a *ArgsMobSession) QFI() uint8 { | ||
return a.qfi | ||
} | ||
|
||
// R returns the Reflective QoS Indication for this ArgsMobSession. | ||
func (a *ArgsMobSession) R() bool { | ||
if a.r == 0 { | ||
return false | ||
} | ||
return true | ||
} | ||
|
||
// U returns the U bit for this ArgsMobSession. | ||
func (a *ArgsMobSession) U() bool { | ||
if a.u == 0 { | ||
return false | ||
} | ||
return true | ||
} | ||
|
||
// PDUSessionID returns the PDU Session Identifier for this ArgsMobSession. The GTP-U equivalent is TEID. | ||
func (a *ArgsMobSession) PDUSessionID() uint32 { | ||
return a.pduSessionID | ||
} | ||
|
||
// MarshalLen returns the serial length of ArgsMobSession. | ||
func (a *ArgsMobSession) MarshalLen() int { | ||
return 5 | ||
} | ||
|
||
// Marshal returns the byte sequence generated from ArgsMobSession. | ||
func (a *ArgsMobSession) Marshal() ([]byte, error) { | ||
b := make([]byte, a.MarshalLen()) | ||
if err := a.MarshalTo(b); err != nil { | ||
return nil, err | ||
} | ||
return b, nil | ||
} | ||
|
||
// MarshalTo puts the byte sequence in the byte array given as b. | ||
func (a *ArgsMobSession) MarshalTo(b []byte) error { | ||
if len(b) < a.MarshalLen() { | ||
return errors.ErrTooShortToMarshal | ||
} | ||
b[qfiPosByte] |= (qfiMask & a.qfi) << qfiPosBit | ||
b[rPosByte] |= (rMask & a.r) << rPosBit | ||
b[uPosByte] |= (uMask & a.u) << uPosBit | ||
binary.BigEndian.PutUint32(b[teidPosByte:teidPosByte+teidSizeByte], a.pduSessionID) | ||
return nil | ||
} | ||
|
||
// UnmarshalBinary sets the values retrieved from byte sequence in an ArgsMobSession. | ||
func (a *ArgsMobSession) UnmarshalBinary(b []byte) error { | ||
if len(b) < 5 { | ||
return errors.ErrTooShortToParse | ||
} | ||
a.qfi = qfiMask & (b[qfiPosByte] >> qfiPosBit) | ||
a.r = rMask & (b[rPosByte] >> rPosBit) | ||
a.u = uMask & (b[uPosByte] >> uPosBit) | ||
a.pduSessionID = binary.BigEndian.Uint32(b[teidPosByte : teidPosByte+teidSizeByte]) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// Copyright 2023 Louis Royer and the NextMN contributors. All rights reserved. | ||
// Use of this source code is governed by a MIT-style license that can be | ||
// found in the LICENSE file. | ||
// SPDX-License-Identifier: MIT | ||
|
||
// Package encoding provides encoding and decoding of IPv6 Addresses | ||
// used by RFC 9433 (Segment Routing over IPv6 for the Mobile User Plane). | ||
package rfc9433 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// Copyright 2023 Louis Royer and the NextMN contributors. All rights reserved. | ||
// Use of this source code is governed by a MIT-style license that can be | ||
// found in the LICENSE file. | ||
// SPDX-License-Identifier: MIT | ||
|
||
// Package errors provides common encoding errors used by rfc9433 package. | ||
package errors |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Copyright 2023 Louis Royer and the NextMN contributors. All rights reserved. | ||
// Use of this source code is governed by a MIT-style license that can be | ||
// found in the LICENSE file. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package errors | ||
|
||
import "errors" | ||
|
||
var ( | ||
ErrTooShortToMarshal = errors.New("too short to serialize") | ||
ErrTooShortToParse = errors.New("too short to parse") | ||
ErrPrefixLength = errors.New("wrong prefix length") | ||
ErrOutOfRange = errors.New("out of range") | ||
) |
Oops, something went wrong.