Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run simulation mode as part of pfcp agent #362

Merged
merged 3 commits into from
Dec 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 64 additions & 9 deletions pfcpiface/grpcsim.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,72 @@
package main

import (
"fmt"
"time"

log "github.com/sirupsen/logrus"
"github.com/wmnsk/go-pfcp/ie"
)

func (u *upf) sim(method string, s *SimModeInfo) {
log.Infoln(*simulate, "sessions:", s.MaxSessions)
// simMode : Type indicating the desired simulation mode.
type simMode int

const (
simModeDisable simMode = iota
simModeCreate
simModeDelete
simModeCreateAndContinue
)

func (s *simMode) String() string {
switch *s {
case simModeDisable:
return "disable"
case simModeCreate:
return "create"
case simModeDelete:
return "delete"
case simModeCreateAndContinue:
return "create_continue"
default:
return "unknown sim mode"
}
}

func (s *simMode) Set(value string) error {
switch value {
case "disable":
*s = simModeDisable
case "create":
*s = simModeCreate
case "delete":
*s = simModeDelete
case "create_continue":
*s = simModeCreateAndContinue
default:
return fmt.Errorf("unknown sim mode %v", value)
}
return nil
}

func (s simMode) create() bool {
return s == simModeCreate || s == simModeCreateAndContinue
}

func (s simMode) delete() bool {
return s == simModeDelete
}

func (s simMode) keepGoing() bool {
return s == simModeCreateAndContinue
}

func (s simMode) enable() bool {
return s != simModeDisable
}

func (u *upf) sim(mode simMode, s *SimModeInfo) {
log.Infoln(simulate.String(), "sessions:", s.MaxSessions)

start := time.Now()
ueip := s.StartUEIP
Expand Down Expand Up @@ -189,15 +247,12 @@ func (u *upf) sim(method string, s *SimModeInfo) {

qers = append(qers, sessionQer)

switch method {
case "create":
if mode.create() {
u.sendMsgToUPF(upfMsgTypeAdd, pdrs, fars, qers)

case "delete":
} else if mode.delete() {
u.sendMsgToUPF(upfMsgTypeDel, pdrs, fars, qers)

default:
log.Fatalln("Unsupported method", method)
} else {
log.Fatalln("Unsupported method", mode)
}
}

Expand Down
14 changes: 6 additions & 8 deletions pfcpiface/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
var (
configPath = flag.String("config", "upf.json", "path to upf config")
httpAddr = flag.String("http", "0.0.0.0:8080", "http IP/port combo")
simulate = flag.String("simulate", "", "create|delete simulated sessions")
simulate = simModeDisable
pfcpsim = flag.Bool("pfcpsim", false, "simulate PFCP")
)

Expand Down Expand Up @@ -151,6 +151,7 @@ func ParseIP(name string, iface string) net.IP {
}

func init() {
flag.Var(&simulate, "simulate", "create|delete|create_continue simulated sessions")
// Set up logger
log.SetReportCaller(true)
log.SetFormatter(&log.TextFormatter{
Expand Down Expand Up @@ -191,14 +192,11 @@ func main() {
return
}

if *simulate != "" {
if *simulate != "create" && *simulate != "delete" {
log.Fatalln("Invalid simulate method", simulate)
if simulate.enable() {
upf.sim(simulate, &conf.SimInfo)
if !simulate.keepGoing() {
return
}

upf.sim(*simulate, &conf.SimInfo)

return
}

setupConfigHandler(upf)
Expand Down