-
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 f0cc1d4
Showing
12 changed files
with
735 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,2 @@ | ||
nextmn-srv6-ctlr | ||
!bash-completion/completions/nextmn-srv6-ctlr |
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,29 @@ | ||
prefix = /usr/local | ||
exec_prefix = $(prefix) | ||
bindir = $(exec_prefix)/bin | ||
BASHCOMPLETIONSDIR = $(exec_prefix)/share/bash-completion/completions | ||
|
||
|
||
RM = rm -f | ||
INSTALL = install -D | ||
|
||
.PHONY: install uninstall update build clean default | ||
default: build | ||
build: | ||
go build | ||
clean: | ||
go clean | ||
reinstall: uninstall install | ||
update: | ||
go get -u github.com/louisroyer/go-pfcp-networking@master | ||
go mod tidy | ||
install: | ||
$(INSTALL) nextmn-srv6-ctrl $(DESTDIR)$(bindir)/nextmn-srv6-ctrl | ||
$(INSTALL) bash-completion/completions/nextmn-srv6-ctrl $(DESTDIR)$(BASHCOMPLETIONSDIR)/nextmn-srv6-ctrl | ||
@echo "=================================" | ||
@echo ">> Now run the following command:" | ||
@echo "\tsource $(DESTDIR)$(BASHCOMPLETIONSDIR)/nextmn-srv6-ctrl" | ||
@echo "=================================" | ||
uninstall: | ||
$(RM) $(DESTDIR)$(bindir)/nextmn-srv6-ctrl | ||
$(RM) $(DESTDIR)$(BASHCOMPLETIONSDIR)/nextmn-srv6-ctrl |
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,17 @@ | ||
# NextMN-SRv6-ctrl | ||
NextMN-SRv6-ctrl is a controller for NextMN-SRv6. It acts as a dummy UPF. | ||
|
||
## Getting started | ||
### Build dependencies | ||
- golang | ||
- make (optional) | ||
|
||
### Build and install | ||
Simply run `make build` and `make install`. | ||
|
||
|
||
## Author | ||
Louis Royer | ||
|
||
## License | ||
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,21 @@ | ||
#! /bin/bash | ||
|
||
: ${PROG:=$(basename ${BASH_SOURCE})} | ||
|
||
_cli_bash_autocomplete() { | ||
if [[ "${COMP_WORDS[0]}" != "source" ]]; then | ||
local cur opts base | ||
COMPREPLY=() | ||
cur="${COMP_WORDS[COMP_CWORD]}" | ||
if [[ "$cur" == "-"* ]]; then | ||
opts=$( ${COMP_WORDS[@]:0:$COMP_CWORD} ${cur} --generate-bash-completion ) | ||
else | ||
opts=$( ${COMP_WORDS[@]:0:$COMP_CWORD} --generate-bash-completion ) | ||
fi | ||
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) | ||
return 0 | ||
fi | ||
} | ||
|
||
complete -o bashdefault -o default -o nospace -F _cli_bash_autocomplete $PROG | ||
unset PROG |
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 @@ | ||
pfcp-address: "10.0.60.3" |
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,13 @@ | ||
module github.com/louisroyer/nextmn-srv6-ctrl | ||
|
||
go 1.15 | ||
|
||
require ( | ||
github.com/cpuguy83/go-md2man/v2 v2.0.1 // indirect | ||
github.com/louisroyer/go-pfcp-networking v0.0.24-0.20230113122010-1b98989277a2 | ||
github.com/urfave/cli/v2 v2.3.0 | ||
github.com/vishvananda/netns v0.0.0-20211101163701-50045581ed74 // indirect | ||
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd // indirect | ||
golang.org/x/sys v0.0.0-20220209214540-3681064d5158 // indirect | ||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b | ||
) |
Large diffs are not rendered by default.
Oops, something went wrong.
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,66 @@ | ||
// Copyright 2023 Louis Royer and the NextMN-SRv6-ctrl 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 main | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"os" | ||
"os/signal" | ||
"syscall" | ||
|
||
ctrl "github.com/louisroyer/nextmn-srv6-ctrl/runtime" | ||
"github.com/urfave/cli/v2" | ||
) | ||
|
||
func initSignals() { | ||
cancelChan := make(chan os.Signal, 1) | ||
signal.Notify(cancelChan, syscall.SIGTERM, syscall.SIGINT) | ||
func(_ os.Signal) {}(<-cancelChan) | ||
ctrl.Exit() | ||
os.Exit(0) | ||
} | ||
|
||
func main() { | ||
log.SetPrefix("[nextmn-upf] ") | ||
var config string | ||
app := &cli.App{ | ||
Name: "NextMN-SRv6-ctrl", | ||
Usage: "Controller for NextMN-SRv6", | ||
EnableBashCompletion: true, | ||
Authors: []*cli.Author{ | ||
{Name: "Louis Royer"}, | ||
}, | ||
Flags: []cli.Flag{ | ||
&cli.StringFlag{ | ||
Name: "config", | ||
Aliases: []string{"c"}, | ||
Usage: "Load configuration from `FILE`", | ||
Destination: &config, | ||
Required: true, | ||
DefaultText: "not set", | ||
}, | ||
}, | ||
Action: func(c *cli.Context) error { | ||
err := ctrl.ParseConf(config) | ||
if err != nil { | ||
fmt.Println("Error loading config, exiting…") | ||
os.Exit(1) | ||
} | ||
err = ctrl.Run() | ||
if err != nil { | ||
fmt.Println("Error while running, exiting…") | ||
log.Fatal(err) | ||
os.Exit(2) | ||
} | ||
return nil | ||
}, | ||
} | ||
go initSignals() | ||
err := app.Run(os.Args) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
} |
Binary file not shown.
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,29 @@ | ||
// Copyright 2023 Louis Royer and the NextMN-SRv6-ctrl 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 ctrl | ||
|
||
import ( | ||
"io/ioutil" | ||
"path/filepath" | ||
|
||
"gopkg.in/yaml.v3" | ||
) | ||
|
||
func ParseConf(file string) error { | ||
path, err := filepath.Abs(file) | ||
yamlFile, err := ioutil.ReadFile(path) | ||
if err != nil { | ||
return err | ||
} | ||
err = yaml.Unmarshal(yamlFile, &Ctrl) | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} | ||
|
||
type CtrlConfig struct { | ||
PFCPAddress *string `yaml:"pfcp-address,omitempty"` | ||
} |
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,38 @@ | ||
// Copyright 2023 Louis Royer and the NextMN-SRv6-ctrl 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 ctrl | ||
|
||
import ( | ||
"fmt" | ||
|
||
pfcp_networking "github.com/louisroyer/go-pfcp-networking/pfcp" | ||
) | ||
|
||
var Ctrl *CtrlConfig | ||
var PFCPServer *pfcp_networking.PFCPEntityUP | ||
|
||
func Run() error { | ||
err := createPFCPNode() | ||
if err != nil { | ||
return err | ||
} | ||
for { | ||
select {} | ||
} | ||
return nil | ||
} | ||
|
||
func createPFCPNode() error { | ||
if Ctrl.PFCPAddress == nil { | ||
return fmt.Errorf("Missing pfcp address") | ||
} | ||
PFCPServer = pfcp_networking.NewPFCPEntityUP(*Ctrl.PFCPAddress) | ||
PFCPServer.Start() | ||
return nil | ||
} | ||
|
||
func Exit() error { | ||
return nil | ||
} |