Skip to content

Commit

Permalink
Move simMode to grpcsim.go
Browse files Browse the repository at this point in the history
  • Loading branch information
pudelkoM committed Dec 1, 2021
1 parent ff4fe80 commit fa4a3eb
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 43 deletions.
58 changes: 58 additions & 0 deletions pfcpiface/grpcsim.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,70 @@
package main

import (
"fmt"
"time"

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

// 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)

Expand Down
47 changes: 4 additions & 43 deletions pfcpiface/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,21 @@ import (
"context"
"encoding/json"
"flag"
"fmt"
"io/ioutil"
"net"
"net/http"
"os"
"os/signal"
"strings"
"syscall"

log "github.com/sirupsen/logrus"
)

var (
configPath = flag.String("config", "upf.json", "path to upf config")
httpAddr = flag.String("http", "0.0.0.0:8080", "http IP/port combo")
pfcpsim = flag.Bool("pfcpsim", false, "simulate PFCP")
simulate simMode = ""
configPath = flag.String("config", "upf.json", "path to upf config")
httpAddr = flag.String("http", "0.0.0.0:8080", "http IP/port combo")
simulate = simModeDisable
pfcpsim = flag.Bool("pfcpsim", false, "simulate PFCP")
)

// Conf : Json conf struct.
Expand Down Expand Up @@ -92,43 +90,6 @@ type IfaceType struct {
IfName string `json:"ifname"`
}

// simMode : Type indicating the desired simulation mode.
type simMode string

func (s *simMode) String() string {
return string(*s)
}

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

func (s *simMode) create() bool {
return strings.Contains(string(*s), "create")
}

func (s *simMode) delete() bool {
return strings.Contains(string(*s), "delete")
}

func (s *simMode) keepGoing() bool {
return strings.Contains(string(*s), "continue")
}

func (s *simMode) enable() bool {
return string(*s) != ""
}

// ParseJSON : parse json file and populate corresponding struct.
func ParseJSON(filepath *string, conf *Conf) {
/* Open up file */
Expand Down

0 comments on commit fa4a3eb

Please sign in to comment.