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

[SDFAB-1110] Add support for multiple application filters #60

Merged
merged 22 commits into from
Mar 28, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
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
14 changes: 7 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 @@ -64,7 +64,7 @@ func (s *sessionCreate) Execute(args []string) error {
BaseID: int32(s.Args.BaseID),
NodeBAddress: s.Args.GnBAddress,
UeAddressPool: s.Args.UePool,
AppFilter: s.Args.AppFilterString,
AppFilters: s.Args.AppFilterString,
Qfi: int32(s.Args.QFI),
})

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

// SessionStep identifies the step in loops, used while creating/modifying/deleting sessions and rules IDs.
// It should be high enough to avoid IDs overlap when creating sessions.
const SessionStep = 10
daniele-moro marked this conversation as resolved.
Show resolved Hide resolved

func NewPFCPSimService(iface string) *pfcpSimService {
interfaceName = iface
return &pfcpSimService{}
Expand Down Expand Up @@ -127,20 +131,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 {
// using variables to ease comprehension on how rules are linked together
uplinkTEID := uint32(i)

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

daniele-moro marked this conversation as resolved.
Show resolved Hide resolved
// 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).
daniele-moro marked this conversation as resolved.
Show resolved Hide resolved
WithN3Address(upfN3Address).
WithSDFFilter(SDFFilter).
WithPrecedence(100).
MarkAsUplink().
BuildPDR()

downlinkPDR := session.NewPDRBuilder().
WithID(ID + 1).
WithMethod(session.Create).
WithPrecedence(100).
WithUEAddress(ueAddress.String()).
WithSDFFilter(SDFFilter).
AddQERID(sessQerID).
AddQERID(downlinkAppQerID).
daniele-moro marked this conversation as resolved.
Show resolved Hide resolved
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 +320,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 +375,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