Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Emanuele Gallone committed Mar 21, 2022
1 parent 6be4ce2 commit 111b306
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 84 deletions.
128 changes: 64 additions & 64 deletions api/pfcpsim.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion api/pfcpsim.proto
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ message CreateSessionRequest {
int32 baseID = 2;
string nodeBAddress = 3;
string ueAddressPool = 4;
string appFilter = 5;
repeated string appFilters = 5;
int32 qfi = 6; // Should be uint8
}

Expand Down
20 changes: 13 additions & 7 deletions internal/pfcpctl/commands/sessions.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import (
)

type commonArgs struct {
Count int `short:"c" long:"count" default:"1" description:"The number of sessions to create"`
BaseID int `short:"i" long:"baseID" default:"1" description:"The base ID to use"`
UePool string `short:"u" long:"ue-pool" default:"17.0.0.0/24" description:"The UE pool address"`
GnBAddress string `short:"g" long:"gnb-addr" description:"The UE pool address"`
AppFilterString string `short:"a" long:"app-filter" description:"Specify an application filter. Format: '{ip | udp | tcp}:{IPv4 Prefix | any}:{<lower-L4-port>-<upper-L4-port> | any}:{allow | deny}' . e.g. 'udp:10.0.0.0/8:80-88:allow'"`
QFI uint8 `short:"q" long:"qfi" description:"The QFI value for QERs. Max value 64."`
Count int `short:"c" long:"count" default:"1" description:"The number of sessions to create"`
BaseID int `short:"i" long:"baseID" default:"1" description:"The base ID to use"`
UePool string `short:"u" long:"ue-pool" default:"17.0.0.0/24" description:"The UE pool address"`
GnBAddress string `short:"g" long:"gnb-addr" description:"The UE pool address"`
AppFilterString []string `short:"a" long:"app-filter" description:"Specify an application filter. Format: '{ip | udp | tcp}:{IPv4 Prefix | any}:{<lower-L4-port>-<upper-L4-port> | any}:{allow | deny}' . e.g. 'udp:10.0.0.0/8:80-88:allow'"`
QFI uint8 `short:"q" long:"qfi" description:"The QFI value for QERs. Max value 64."`
}

type sessionCreate struct {
Expand Down Expand Up @@ -59,12 +59,18 @@ func (s *sessionCreate) Execute(args []string) error {
client := connect()
defer disconnect()

var appFilters []string

for _, s := range s.Args.AppFilterString {
appFilters = append(appFilters, s)
}

res, err := client.CreateSession(context.Background(), &pb.CreateSessionRequest{
Count: int32(s.Args.Count),
BaseID: int32(s.Args.BaseID),
NodeBAddress: s.Args.GnBAddress,
UeAddressPool: s.Args.UePool,
AppFilter: s.Args.AppFilterString,
AppFilters: appFilters,
Qfi: int32(s.Args.QFI),
})

Expand Down
62 changes: 50 additions & 12 deletions internal/pfcpsim/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (
// Its state is handled in internal/pfcpsim/state.go
type pfcpSimService struct{}

const SessionStep = 20 // identifies the step in loops, used while creating/modifying/deleting sessions and rules IDs

func NewPFCPSimService(iface string) *pfcpSimService {
interfaceName = iface
return &pfcpSimService{}
Expand Down Expand Up @@ -127,20 +129,11 @@ func (P pfcpSimService) CreateSession(ctx context.Context, request *pb.CreateSes
var SDFFilter = ""
var qfi, gateStatus uint8 = 0, ieLib.GateStatusOpen

if request.AppFilter != "" {
SDFFilter, gateStatus, err = parseAppFilter(request.AppFilter)
if err != nil {
return &pb.Response{}, status.Error(codes.Aborted, err.Error())
}

log.Infof("Successfully parsed application filter. SDF Filter: %v", SDFFilter)
}

if request.Qfi != 0 {
qfi = uint8(request.Qfi)
}

for i := baseID; i < (count*2 + baseID); i = i + 2 {
for i := baseID; i < (count*SessionStep + baseID); i = i + SessionStep { //FIXME step should include the number of PDRs created
// using variables to ease comprehension on how rules are linked together
uplinkTEID := uint32(i)

Expand Down Expand Up @@ -237,6 +230,51 @@ func (P pfcpSimService) CreateSession(ctx context.Context, request *pb.CreateSes
Build(),
}

// create as many PDRs as the number of app filters provided through pfcpctl
if len(request.AppFilters) > 0 {
pdrs = []*ieLib.IE{} // reset pdr slice
ID := uint16(i)

for _, appFilter := range request.AppFilters {
SDFFilter, gateStatus, err = parseAppFilter(appFilter)
if err != nil {
return &pb.Response{}, status.Error(codes.Aborted, err.Error())
}

log.Infof("Successfully parsed application filter. SDF Filter: %v", SDFFilter)

uplinkPDR := session.NewPDRBuilder().
WithID(ID).
WithMethod(session.Create).
WithTEID(uplinkTEID).
WithFARID(uplinkFarID).
AddQERID(sessQerID).
AddQERID(uplinkAppQerID).
WithN3Address(upfN3Address).
WithSDFFilter(SDFFilter).
WithPrecedence(uint32(ID + 100)). // FIXME can precedence between these PDRs be the same?
MarkAsUplink().
BuildPDR()

downlinkPDR := session.NewPDRBuilder().
WithID(ID + 1).
WithMethod(session.Create).
WithPrecedence(uint32(ID + 100)).
WithUEAddress(ueAddress.String()).
WithSDFFilter(SDFFilter).
AddQERID(sessQerID).
AddQERID(downlinkAppQerID).
WithFARID(downlinkFarID).
MarkAsDownlink().
BuildPDR()

pdrs = append(pdrs, uplinkPDR)
pdrs = append(pdrs, downlinkPDR)

ID++
}
}

sess, err := sim.EstablishSession(pdrs, fars, qers)
if err != nil {
return &pb.Response{}, status.Error(codes.Internal, err.Error())
Expand Down Expand Up @@ -280,7 +318,7 @@ func (P pfcpSimService) ModifySession(ctx context.Context, request *pb.ModifySes
actions |= session.ActionForward
}

for i := baseID; i < (count*2 + baseID); i = i + 2 {
for i := baseID; i < (count*SessionStep + baseID); i = i + SessionStep {
teid := uint32(i + 1)

if request.BufferFlag || request.NotifyCPFlag {
Expand Down Expand Up @@ -335,7 +373,7 @@ func (P pfcpSimService) DeleteSession(ctx context.Context, request *pb.DeleteSes
return &pb.Response{}, status.Error(codes.Aborted, err.Error())
}

for i := baseID; i < (count*2 + baseID); i = i + 2 {
for i := baseID; i < (count*SessionStep + baseID); i = i + SessionStep {
sess, ok := getSession(i)
if !ok {
errMsg := "Session was nil. Check baseID"
Expand Down

0 comments on commit 111b306

Please sign in to comment.