From 150067bfe0497aa26faeea56d337d5382da22405 Mon Sep 17 00:00:00 2001 From: Emanuele Gallone Date: Tue, 8 Mar 2022 20:34:03 +0100 Subject: [PATCH 01/18] First commit --- api/pfcpsim.pb.go | 16 +++--- api/pfcpsim.proto | 2 +- internal/pfcpctl/commands/sessions.go | 2 +- internal/pfcpsim/server.go | 80 ++++++++++++++------------- 4 files changed, 53 insertions(+), 47 deletions(-) diff --git a/api/pfcpsim.pb.go b/api/pfcpsim.pb.go index 3232810..0bb5c32 100644 --- a/api/pfcpsim.pb.go +++ b/api/pfcpsim.pb.go @@ -40,11 +40,11 @@ type CreateSessionRequest struct { // count represents the number of session Count int32 `protobuf:"varint,1,opt,name=count,proto3" json:"count,omitempty"` // baseID is used to create incremental IDs for PDRs, FARs, QERs - BaseID int32 `protobuf:"varint,2,opt,name=baseID,proto3" json:"baseID,omitempty"` - NodeBAddress string `protobuf:"bytes,3,opt,name=nodeBAddress,proto3" json:"nodeBAddress,omitempty"` - UeAddressPool string `protobuf:"bytes,4,opt,name=ueAddressPool,proto3" json:"ueAddressPool,omitempty"` - SdfFilter string `protobuf:"bytes,5,opt,name=sdfFilter,proto3" json:"sdfFilter,omitempty"` - Qfi int32 `protobuf:"varint,6,opt,name=qfi,proto3" json:"qfi,omitempty"` // Should be uint8 + BaseID int32 `protobuf:"varint,2,opt,name=baseID,proto3" json:"baseID,omitempty"` + NodeBAddress string `protobuf:"bytes,3,opt,name=nodeBAddress,proto3" json:"nodeBAddress,omitempty"` + UeAddressPool string `protobuf:"bytes,4,opt,name=ueAddressPool,proto3" json:"ueAddressPool,omitempty"` + SdfFilter []string `protobuf:"bytes,5,rep,name=sdfFilter,proto3" json:"sdfFilter,omitempty"` + Qfi int32 `protobuf:"varint,6,opt,name=qfi,proto3" json:"qfi,omitempty"` // Should be uint8 } func (x *CreateSessionRequest) Reset() { @@ -107,11 +107,11 @@ func (x *CreateSessionRequest) GetUeAddressPool() string { return "" } -func (x *CreateSessionRequest) GetSdfFilter() string { +func (x *CreateSessionRequest) GetSdfFilter() []string { if x != nil { return x.SdfFilter } - return "" + return nil } func (x *CreateSessionRequest) GetQfi() int32 { @@ -430,7 +430,7 @@ var file_pfcpsim_proto_rawDesc = []byte{ 0x24, 0x0a, 0x0d, 0x75, 0x65, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x50, 0x6f, 0x6f, 0x6c, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x75, 0x65, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x50, 0x6f, 0x6f, 0x6c, 0x12, 0x1c, 0x0a, 0x09, 0x73, 0x64, 0x66, 0x46, 0x69, 0x6c, 0x74, - 0x65, 0x72, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x73, 0x64, 0x66, 0x46, 0x69, 0x6c, + 0x65, 0x72, 0x18, 0x05, 0x20, 0x03, 0x28, 0x09, 0x52, 0x09, 0x73, 0x64, 0x66, 0x46, 0x69, 0x6c, 0x74, 0x65, 0x72, 0x12, 0x10, 0x0a, 0x03, 0x71, 0x66, 0x69, 0x18, 0x06, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x71, 0x66, 0x69, 0x22, 0xd2, 0x01, 0x0a, 0x14, 0x4d, 0x6f, 0x64, 0x69, 0x66, 0x79, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x14, diff --git a/api/pfcpsim.proto b/api/pfcpsim.proto index 29317fb..65106d8 100644 --- a/api/pfcpsim.proto +++ b/api/pfcpsim.proto @@ -13,7 +13,7 @@ message CreateSessionRequest { int32 baseID = 2; string nodeBAddress = 3; string ueAddressPool = 4; - string sdfFilter = 5; + repeated string sdfFilter = 5; int32 qfi = 6; // Should be uint8 } diff --git a/internal/pfcpctl/commands/sessions.go b/internal/pfcpctl/commands/sessions.go index c1218ba..c458e94 100644 --- a/internal/pfcpctl/commands/sessions.go +++ b/internal/pfcpctl/commands/sessions.go @@ -16,7 +16,7 @@ type commonArgs struct { 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"` - SDFfilter string `short:"s" long:"sdf-filter" description:"The SDF Filter to use"` + SDFfilter []string `short:"s" long:"sdf-filter" description:"The SDF Filter to use. Note that each entered SDF Filter will have incremental Precedence set in pfcpsim."` QFI uint8 `short:"q" long:"qfi" description:"The QFI value for QERs. Max value 64."` } diff --git a/internal/pfcpsim/server.go b/internal/pfcpsim/server.go index e84fb8b..8b7fd37 100644 --- a/internal/pfcpsim/server.go +++ b/internal/pfcpsim/server.go @@ -124,18 +124,19 @@ func (P pfcpSimService) CreateSession(ctx context.Context, request *pb.CreateSes return &pb.Response{}, status.Error(codes.Aborted, errMsg) } - var SDFFilter = "" + //var SDFFilter = "" //FIXME var qfi uint8 = 0 if request.Qfi != 0 { qfi = uint8(request.Qfi) } - if request.SdfFilter != "" { - SDFFilter = request.SdfFilter - } + //if len(request.SdfFilter) == 0 != "" { + // SDFFilter = request.SdfFilter + //} - for i := baseID; i < (count*2 + baseID); i = i + 2 { + + for i := baseID; i < (count*2 + baseID); i = i + 2 { //FIXME increment step should take into account the number of SDF Filters // using variables to ease comprehension on how rules are linked together uplinkTEID := uint32(i) @@ -145,43 +146,12 @@ func (P pfcpSimService) CreateSession(ctx context.Context, request *pb.CreateSes uplinkFarID := uint32(i) downlinkFarID := uint32(i + 1) - uplinkPdrID := uint16(i) - dowlinkPdrID := uint16(i + 1) - sessQerID := uint32(i + 3) uplinkAppQerID := uint32(i) downlinkAppQerID := uint32(i + 1) - pdrs := []*ieLib.IE{ - // UplinkPDR - session.NewPDRBuilder(). - WithID(uplinkPdrID). - WithMethod(session.Create). - WithTEID(uplinkTEID). - WithFARID(uplinkFarID). - AddQERID(sessQerID). - AddQERID(uplinkAppQerID). - WithN3Address(upfN3Address). - WithSDFFilter(SDFFilter). - WithPrecedence(100). - MarkAsUplink(). - BuildPDR(), - - // DownlinkPDR - session.NewPDRBuilder(). - WithID(dowlinkPdrID). - WithMethod(session.Create). - WithPrecedence(100). - WithUEAddress(ueAddress.String()). - WithSDFFilter(SDFFilter). - AddQERID(sessQerID). - AddQERID(downlinkAppQerID). - WithFARID(downlinkFarID). - MarkAsDownlink(). - BuildPDR(), - } - + pdrs := []*ieLib.IE{} // Updated below fars := []*ieLib.IE{ // UplinkFAR session.NewFARBuilder(). @@ -230,6 +200,42 @@ func (P pfcpSimService) CreateSession(ctx context.Context, request *pb.CreateSes Build(), } + j := i + for _, sdf := range request.SdfFilter { + // Create as many Uplink and Downlink PDRs as provided SDF filters + uplinkPDRID := uint16(j) + downlinkPDRID := uint16(j + 1) + precedence := uint32(j) + + uplinkPDR := session.NewPDRBuilder(). + WithID(uplinkPDRID). + WithMethod(session.Create). + WithTEID(uplinkTEID). + WithFARID(uplinkFarID). + AddQERID(sessQerID). + AddQERID(uplinkAppQerID). + WithN3Address(upfN3Address). + WithSDFFilter(sdf). + WithPrecedence(precedence). + MarkAsUplink(). + BuildPDR() + + downlinkPDR := session.NewPDRBuilder(). + WithID(downlinkPDRID). + WithMethod(session.Create). + WithPrecedence(precedence). + WithUEAddress(ueAddress.String()). + WithSDFFilter(sdf). + AddQERID(sessQerID). + AddQERID(downlinkAppQerID). + WithFARID(downlinkFarID). + MarkAsDownlink(). + BuildPDR() + + pdrs = append(pdrs, uplinkPDR) + pdrs = append(pdrs, downlinkPDR) + } + sess, err := sim.EstablishSession(pdrs, fars, qers) if err != nil { return &pb.Response{}, status.Error(codes.Internal, err.Error()) From 8cad9be56ff8961de78ca457549dc11faad4fc87 Mon Sep 17 00:00:00 2001 From: Emanuele Gallone Date: Wed, 9 Mar 2022 15:46:28 +0100 Subject: [PATCH 02/18] Fix increment of internal loop --- internal/pfcpsim/server.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/internal/pfcpsim/server.go b/internal/pfcpsim/server.go index 8b7fd37..f718676 100644 --- a/internal/pfcpsim/server.go +++ b/internal/pfcpsim/server.go @@ -234,6 +234,8 @@ func (P pfcpSimService) CreateSession(ctx context.Context, request *pb.CreateSes pdrs = append(pdrs, uplinkPDR) pdrs = append(pdrs, downlinkPDR) + + j = j + 2 } sess, err := sim.EstablishSession(pdrs, fars, qers) From 97244510baba0b9733cd82d4a28cdc96b35d589e Mon Sep 17 00:00:00 2001 From: Emanuele Gallone Date: Thu, 10 Mar 2022 11:24:16 +0100 Subject: [PATCH 03/18] Add QER gating parameters --- pkg/pfcpsim/session/qer_builder.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/pkg/pfcpsim/session/qer_builder.go b/pkg/pfcpsim/session/qer_builder.go index a107e08..b8fa7fc 100644 --- a/pkg/pfcpsim/session/qer_builder.go +++ b/pkg/pfcpsim/session/qer_builder.go @@ -15,6 +15,8 @@ type qerBuilder struct { isGbrSet bool ulGbr uint64 dlGbr uint64 + ulQerGate uint8 + dlQerGate uint8 isIDSet bool } @@ -64,6 +66,13 @@ func (b *qerBuilder) WithDownlinkGBR(dlGbr uint64) *qerBuilder { return b } +func (b *qerBuilder) WithGateRates(uplinkRate, downlinkRate uint8) *qerBuilder { + b.ulQerGate = uplinkRate + b.dlQerGate = downlinkRate + + return b +} + func (b *qerBuilder) validate() { if !b.isIDSet { panic("Tried to build a QER without setting the QER ID") @@ -86,8 +95,7 @@ func (b *qerBuilder) Build() *ie.IE { qer := createFunc( ie.NewQERID(b.qerID), ie.NewQFI(b.qfi), - // FIXME: we don't support gating, always OPEN - ie.NewGateStatus(0, 0), + ie.NewGateStatus(b.ulQerGate, b.dlQerGate), ) if b.isMbrSet { From e1e93decdcd66e2dba9008ef781626898e912543 Mon Sep 17 00:00:00 2001 From: Emanuele Gallone Date: Thu, 10 Mar 2022 11:27:49 +0100 Subject: [PATCH 04/18] Refactor --- pkg/pfcpsim/session/qer_builder.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/pfcpsim/session/qer_builder.go b/pkg/pfcpsim/session/qer_builder.go index b8fa7fc..27328ba 100644 --- a/pkg/pfcpsim/session/qer_builder.go +++ b/pkg/pfcpsim/session/qer_builder.go @@ -66,7 +66,7 @@ func (b *qerBuilder) WithDownlinkGBR(dlGbr uint64) *qerBuilder { return b } -func (b *qerBuilder) WithGateRates(uplinkRate, downlinkRate uint8) *qerBuilder { +func (b *qerBuilder) WithGateStatus(uplinkRate, downlinkRate uint8) *qerBuilder { b.ulQerGate = uplinkRate b.dlQerGate = downlinkRate From 010096235e5e44884bd5328e2537dfada6a5e646 Mon Sep 17 00:00:00 2001 From: Emanuele Gallone Date: Thu, 10 Mar 2022 11:41:13 +0100 Subject: [PATCH 05/18] Fix gate status --- pkg/pfcpsim/session/ies.go | 4 ++++ pkg/pfcpsim/session/qer_builder.go | 15 +++++++++------ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/pkg/pfcpsim/session/ies.go b/pkg/pfcpsim/session/ies.go index d2f2c32..4e75a3a 100644 --- a/pkg/pfcpsim/session/ies.go +++ b/pkg/pfcpsim/session/ies.go @@ -8,6 +8,7 @@ type IEMethod uint8 // Definitions for session rules type direction int +type gateStatus int const ( notSet direction = iota @@ -23,5 +24,8 @@ const ( ActionBuffer uint8 = 0x4 ActionNotify uint8 = 0x8 + GateOpen gateStatus = iota + GateClosed + S_TAG = 0x100 // Refer to table 8.2.56-1 in PFCP specs Release 16 ) diff --git a/pkg/pfcpsim/session/qer_builder.go b/pkg/pfcpsim/session/qer_builder.go index 27328ba..c263204 100644 --- a/pkg/pfcpsim/session/qer_builder.go +++ b/pkg/pfcpsim/session/qer_builder.go @@ -15,8 +15,7 @@ type qerBuilder struct { isGbrSet bool ulGbr uint64 dlGbr uint64 - ulQerGate uint8 - dlQerGate uint8 + gateStatus gateStatus isIDSet bool } @@ -66,9 +65,8 @@ func (b *qerBuilder) WithDownlinkGBR(dlGbr uint64) *qerBuilder { return b } -func (b *qerBuilder) WithGateStatus(uplinkRate, downlinkRate uint8) *qerBuilder { - b.ulQerGate = uplinkRate - b.dlQerGate = downlinkRate +func (b *qerBuilder) WithGateStatus(status gateStatus) *qerBuilder { + b.gateStatus = status return b } @@ -92,10 +90,15 @@ func (b *qerBuilder) Build() *ie.IE { createFunc = ie.NewUpdateQER } + gate := ie.NewGateStatus(0, 0) //Open + if b.gateStatus == GateClosed { + gate = ie.NewGateStatus(1, 1) + } + qer := createFunc( ie.NewQERID(b.qerID), ie.NewQFI(b.qfi), - ie.NewGateStatus(b.ulQerGate, b.dlQerGate), + gate, ) if b.isMbrSet { From 78a8373dcc6cb011a75157cf8297267d21d46518 Mon Sep 17 00:00:00 2001 From: Emanuele Gallone Date: Thu, 10 Mar 2022 11:43:35 +0100 Subject: [PATCH 06/18] Fix gate status --- pkg/pfcpsim/session/ies.go | 4 ---- pkg/pfcpsim/session/qer_builder.go | 8 ++++---- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/pkg/pfcpsim/session/ies.go b/pkg/pfcpsim/session/ies.go index 4e75a3a..d2f2c32 100644 --- a/pkg/pfcpsim/session/ies.go +++ b/pkg/pfcpsim/session/ies.go @@ -8,7 +8,6 @@ type IEMethod uint8 // Definitions for session rules type direction int -type gateStatus int const ( notSet direction = iota @@ -24,8 +23,5 @@ const ( ActionBuffer uint8 = 0x4 ActionNotify uint8 = 0x8 - GateOpen gateStatus = iota - GateClosed - S_TAG = 0x100 // Refer to table 8.2.56-1 in PFCP specs Release 16 ) diff --git a/pkg/pfcpsim/session/qer_builder.go b/pkg/pfcpsim/session/qer_builder.go index c263204..0dfa242 100644 --- a/pkg/pfcpsim/session/qer_builder.go +++ b/pkg/pfcpsim/session/qer_builder.go @@ -14,8 +14,8 @@ type qerBuilder struct { dlMbr uint64 isGbrSet bool ulGbr uint64 - dlGbr uint64 - gateStatus gateStatus + dlGbr uint64 + gateStatus GateStatus isIDSet bool } @@ -65,7 +65,7 @@ func (b *qerBuilder) WithDownlinkGBR(dlGbr uint64) *qerBuilder { return b } -func (b *qerBuilder) WithGateStatus(status gateStatus) *qerBuilder { +func (b *qerBuilder) WithGateStatus(status uint8) *qerBuilder { b.gateStatus = status return b @@ -91,7 +91,7 @@ func (b *qerBuilder) Build() *ie.IE { } gate := ie.NewGateStatus(0, 0) //Open - if b.gateStatus == GateClosed { + if b.gateStatus == ie.GateStatusClosed { gate = ie.NewGateStatus(1, 1) } From df35a4658e3b0dbb71773c83a2dc8f675fca1b19 Mon Sep 17 00:00:00 2001 From: Emanuele Gallone Date: Thu, 10 Mar 2022 11:43:59 +0100 Subject: [PATCH 07/18] Refactor --- pkg/pfcpsim/session/qer_builder.go | 18 +++++++++--------- pkg/pfcpsim/session/qer_builder_test.go | 15 ++++++++++++++- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/pkg/pfcpsim/session/qer_builder.go b/pkg/pfcpsim/session/qer_builder.go index 0dfa242..42a88b9 100644 --- a/pkg/pfcpsim/session/qer_builder.go +++ b/pkg/pfcpsim/session/qer_builder.go @@ -6,16 +6,16 @@ package session import "github.com/wmnsk/go-pfcp/ie" type qerBuilder struct { - method IEMethod - qerID uint32 - qfi uint8 - isMbrSet bool - ulMbr uint64 - dlMbr uint64 - isGbrSet bool - ulGbr uint64 + method IEMethod + qerID uint32 + qfi uint8 + isMbrSet bool + ulMbr uint64 + dlMbr uint64 + isGbrSet bool + ulGbr uint64 dlGbr uint64 - gateStatus GateStatus + gateStatus uint8 isIDSet bool } diff --git a/pkg/pfcpsim/session/qer_builder_test.go b/pkg/pfcpsim/session/qer_builder_test.go index fa4f521..be7de69 100644 --- a/pkg/pfcpsim/session/qer_builder_test.go +++ b/pkg/pfcpsim/session/qer_builder_test.go @@ -54,7 +54,20 @@ func TestQERBuilder(t *testing.T) { ie.NewQFI(2), ie.NewGateStatus(0, 0), ), - description: "Valid Create QER", + description: "Valid Create QER with gate open", + }, + { + input: NewQERBuilder(). + WithID(1). + WithMethod(Create). + WithQFI(2). + WithGateStatus(ie.GateStatusClosed), + expected: ie.NewCreateQER( + ie.NewQERID(1), + ie.NewQFI(2), + ie.NewGateStatus(1, 1), + ), + description: "Valid Create QER with Gate closed", }, { input: NewQERBuilder(). From 62db8f1a0e32ae7e4ab4847b2040643ecd2ff4f9 Mon Sep 17 00:00:00 2001 From: Emanuele Gallone Date: Thu, 10 Mar 2022 11:57:06 +0100 Subject: [PATCH 08/18] Allow to set gate status --- api/pfcpsim.pb.go | 14 ++++++++++++-- api/pfcpsim.proto | 1 + internal/pfcpctl/commands/sessions.go | 2 ++ internal/pfcpsim/server.go | 7 ++++++- 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/api/pfcpsim.pb.go b/api/pfcpsim.pb.go index 3232810..72aaf98 100644 --- a/api/pfcpsim.pb.go +++ b/api/pfcpsim.pb.go @@ -45,6 +45,7 @@ type CreateSessionRequest struct { UeAddressPool string `protobuf:"bytes,4,opt,name=ueAddressPool,proto3" json:"ueAddressPool,omitempty"` SdfFilter string `protobuf:"bytes,5,opt,name=sdfFilter,proto3" json:"sdfFilter,omitempty"` Qfi int32 `protobuf:"varint,6,opt,name=qfi,proto3" json:"qfi,omitempty"` // Should be uint8 + GateStatus bool `protobuf:"varint,7,opt,name=gateStatus,proto3" json:"gateStatus,omitempty"` } func (x *CreateSessionRequest) Reset() { @@ -121,6 +122,13 @@ func (x *CreateSessionRequest) GetQfi() int32 { return 0 } +func (x *CreateSessionRequest) GetGateStatus() bool { + if x != nil { + return x.GateStatus + } + return false +} + type ModifySessionRequest struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -420,7 +428,7 @@ var File_pfcpsim_proto protoreflect.FileDescriptor var file_pfcpsim_proto_rawDesc = []byte{ 0x0a, 0x0d, 0x70, 0x66, 0x63, 0x70, 0x73, 0x69, 0x6d, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, - 0x03, 0x61, 0x70, 0x69, 0x22, 0xbe, 0x01, 0x0a, 0x14, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x53, + 0x03, 0x61, 0x70, 0x69, 0x22, 0xde, 0x01, 0x0a, 0x14, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x16, 0x0a, 0x06, 0x62, 0x61, 0x73, 0x65, 0x49, 0x44, 0x18, 0x02, 0x20, @@ -432,7 +440,9 @@ var file_pfcpsim_proto_rawDesc = []byte{ 0x73, 0x50, 0x6f, 0x6f, 0x6c, 0x12, 0x1c, 0x0a, 0x09, 0x73, 0x64, 0x66, 0x46, 0x69, 0x6c, 0x74, 0x65, 0x72, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x73, 0x64, 0x66, 0x46, 0x69, 0x6c, 0x74, 0x65, 0x72, 0x12, 0x10, 0x0a, 0x03, 0x71, 0x66, 0x69, 0x18, 0x06, 0x20, 0x01, 0x28, 0x05, - 0x52, 0x03, 0x71, 0x66, 0x69, 0x22, 0xd2, 0x01, 0x0a, 0x14, 0x4d, 0x6f, 0x64, 0x69, 0x66, 0x79, + 0x52, 0x03, 0x71, 0x66, 0x69, 0x12, 0x1e, 0x0a, 0x0a, 0x67, 0x61, 0x74, 0x65, 0x53, 0x74, 0x61, + 0x74, 0x75, 0x73, 0x18, 0x07, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0a, 0x67, 0x61, 0x74, 0x65, 0x53, + 0x74, 0x61, 0x74, 0x75, 0x73, 0x22, 0xd2, 0x01, 0x0a, 0x14, 0x4d, 0x6f, 0x64, 0x69, 0x66, 0x79, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x16, 0x0a, 0x06, 0x62, 0x61, 0x73, 0x65, 0x49, 0x44, 0x18, 0x02, diff --git a/api/pfcpsim.proto b/api/pfcpsim.proto index 29317fb..fc14c97 100644 --- a/api/pfcpsim.proto +++ b/api/pfcpsim.proto @@ -15,6 +15,7 @@ message CreateSessionRequest { string ueAddressPool = 4; string sdfFilter = 5; int32 qfi = 6; // Should be uint8 + bool gateStatus = 7; } message ModifySessionRequest { diff --git a/internal/pfcpctl/commands/sessions.go b/internal/pfcpctl/commands/sessions.go index e1f0fb7..f47811a 100644 --- a/internal/pfcpctl/commands/sessions.go +++ b/internal/pfcpctl/commands/sessions.go @@ -18,6 +18,7 @@ type commonArgs struct { GnBAddress string `short:"g" long:"gnb-addr" description:"The (g/e)nodeB address"` SDFfilter string `short:"s" long:"sdf-filter" description:"The SDF Filter to use"` QFI uint8 `short:"q" long:"qfi" description:"The QFI value for QERs. Max value 64."` + GateStatus bool `short:"u" long:"gate-status" description:"If set, the QER gate status will be 'CLOSED'"` } type sessionCreate struct { @@ -66,6 +67,7 @@ func (s *sessionCreate) Execute(args []string) error { UeAddressPool: s.Args.UePool, SdfFilter: s.Args.SDFfilter, Qfi: int32(s.Args.QFI), + GateStatus: s.Args.GateStatus, }) if err != nil { diff --git a/internal/pfcpsim/server.go b/internal/pfcpsim/server.go index e84fb8b..89b98d6 100644 --- a/internal/pfcpsim/server.go +++ b/internal/pfcpsim/server.go @@ -125,7 +125,11 @@ func (P pfcpSimService) CreateSession(ctx context.Context, request *pb.CreateSes } var SDFFilter = "" - var qfi uint8 = 0 + var qfi, gateStatus uint8 = 0, ieLib.GateStatusOpen + + if request.GateStatus { + gateStatus = ieLib.GateStatusClosed + } if request.Qfi != 0 { qfi = uint8(request.Qfi) @@ -209,6 +213,7 @@ func (P pfcpSimService) CreateSession(ctx context.Context, request *pb.CreateSes WithMethod(session.Create). WithUplinkMBR(60000). WithDownlinkMBR(60000). + WithGateStatus(gateStatus). Build(), // Uplink application QER From eae561a186dae03adc54342b1e4b8d115e713847 Mon Sep 17 00:00:00 2001 From: Emanuele Gallone Date: Thu, 10 Mar 2022 14:28:04 +0100 Subject: [PATCH 09/18] Fix short command --- internal/pfcpctl/commands/sessions.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/pfcpctl/commands/sessions.go b/internal/pfcpctl/commands/sessions.go index f47811a..93dc448 100644 --- a/internal/pfcpctl/commands/sessions.go +++ b/internal/pfcpctl/commands/sessions.go @@ -18,7 +18,7 @@ type commonArgs struct { GnBAddress string `short:"g" long:"gnb-addr" description:"The (g/e)nodeB address"` SDFfilter string `short:"s" long:"sdf-filter" description:"The SDF Filter to use"` QFI uint8 `short:"q" long:"qfi" description:"The QFI value for QERs. Max value 64."` - GateStatus bool `short:"u" long:"gate-status" description:"If set, the QER gate status will be 'CLOSED'"` + GateStatus bool `short:"t" long:"gate-status" description:"If set, the QER gate status will be CLOSED"` } type sessionCreate struct { From 53e0065defa2587cee29b70c3809dbefc06c3951 Mon Sep 17 00:00:00 2001 From: Emanuele Gallone Date: Thu, 10 Mar 2022 15:01:50 +0100 Subject: [PATCH 10/18] Fix incorrect gate setting. Use app QER --- internal/pfcpsim/server.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/internal/pfcpsim/server.go b/internal/pfcpsim/server.go index 89b98d6..cbe6e19 100644 --- a/internal/pfcpsim/server.go +++ b/internal/pfcpsim/server.go @@ -213,7 +213,6 @@ func (P pfcpSimService) CreateSession(ctx context.Context, request *pb.CreateSes WithMethod(session.Create). WithUplinkMBR(60000). WithDownlinkMBR(60000). - WithGateStatus(gateStatus). Build(), // Uplink application QER @@ -223,6 +222,7 @@ func (P pfcpSimService) CreateSession(ctx context.Context, request *pb.CreateSes WithQFI(qfi). WithUplinkMBR(50000). WithDownlinkMBR(30000). + WithGateStatus(gateStatus). Build(), // Downlink application QER @@ -232,6 +232,7 @@ func (P pfcpSimService) CreateSession(ctx context.Context, request *pb.CreateSes WithQFI(qfi). WithUplinkMBR(50000). WithDownlinkMBR(30000). + WithGateStatus(gateStatus). Build(), } From ab39d386ff4f687923080163813fcd3a7079726e Mon Sep 17 00:00:00 2001 From: Emanuele Gallone Date: Thu, 10 Mar 2022 19:35:23 +0100 Subject: [PATCH 11/18] Partial implementation of app filter flag --- api/pfcpsim.pb.go | 179 +++++++++++++++----------- api/pfcpsim.proto | 10 +- internal/pfcpctl/commands/sessions.go | 13 +- internal/pfcpsim/server.go | 11 +- 4 files changed, 136 insertions(+), 77 deletions(-) diff --git a/api/pfcpsim.pb.go b/api/pfcpsim.pb.go index 9ad2974..db4de2f 100644 --- a/api/pfcpsim.pb.go +++ b/api/pfcpsim.pb.go @@ -40,12 +40,17 @@ type CreateSessionRequest struct { // count represents the number of session Count int32 `protobuf:"varint,1,opt,name=count,proto3" json:"count,omitempty"` // baseID is used to create incremental IDs for PDRs, FARs, QERs - BaseID int32 `protobuf:"varint,2,opt,name=baseID,proto3" json:"baseID,omitempty"` - NodeBAddress string `protobuf:"bytes,3,opt,name=nodeBAddress,proto3" json:"nodeBAddress,omitempty"` - UeAddressPool string `protobuf:"bytes,4,opt,name=ueAddressPool,proto3" json:"ueAddressPool,omitempty"` - SdfFilter []string `protobuf:"bytes,5,rep,name=sdfFilter,proto3" json:"sdfFilter,omitempty"` - Qfi int32 `protobuf:"varint,6,opt,name=qfi,proto3" json:"qfi,omitempty"` // Should be uint8 - GateStatus bool `protobuf:"varint,7,opt,name=gateStatus,proto3" json:"gateStatus,omitempty"` + BaseID int32 `protobuf:"varint,2,opt,name=baseID,proto3" json:"baseID,omitempty"` + NodeBAddress string `protobuf:"bytes,3,opt,name=nodeBAddress,proto3" json:"nodeBAddress,omitempty"` + UeAddressPool string `protobuf:"bytes,4,opt,name=ueAddressPool,proto3" json:"ueAddressPool,omitempty"` + // string sdfFilter = 5; + Qfi int32 `protobuf:"varint,6,opt,name=qfi,proto3" json:"qfi,omitempty"` // Should be uint8 + // **** SDF filter-related fields **** // + SetGateStatusToClosed bool `protobuf:"varint,7,opt,name=setGateStatusToClosed,proto3" json:"setGateStatusToClosed,omitempty"` // If set, the application QERs will have the Gate status to closed. + Protocol string `protobuf:"bytes,8,opt,name=protocol,proto3" json:"protocol,omitempty"` + DestinationIPCIDR string `protobuf:"bytes,9,opt,name=destinationIPCIDR,proto3" json:"destinationIPCIDR,omitempty"` // must be in CIDR notation e.g. 192.168.0.1/24 + LowerPortRange int32 `protobuf:"varint,11,opt,name=lowerPortRange,proto3" json:"lowerPortRange,omitempty"` + UpperPortRange int32 `protobuf:"varint,12,opt,name=upperPortRange,proto3" json:"upperPortRange,omitempty"` // **** End of SDF filter-related fields **** // } func (x *CreateSessionRequest) Reset() { @@ -108,25 +113,46 @@ func (x *CreateSessionRequest) GetUeAddressPool() string { return "" } -func (x *CreateSessionRequest) GetSdfFilter() []string { +func (x *CreateSessionRequest) GetQfi() int32 { if x != nil { - return x.SdfFilter + return x.Qfi } - return nil + return 0 } -func (x *CreateSessionRequest) GetQfi() int32 { +func (x *CreateSessionRequest) GetSetGateStatusToClosed() bool { if x != nil { - return x.Qfi + return x.SetGateStatusToClosed + } + return false +} + +func (x *CreateSessionRequest) GetProtocol() string { + if x != nil { + return x.Protocol + } + return "" +} + +func (x *CreateSessionRequest) GetDestinationIPCIDR() string { + if x != nil { + return x.DestinationIPCIDR + } + return "" +} + +func (x *CreateSessionRequest) GetLowerPortRange() int32 { + if x != nil { + return x.LowerPortRange } return 0 } -func (x *CreateSessionRequest) GetGateStatus() bool { +func (x *CreateSessionRequest) GetUpperPortRange() int32 { if x != nil { - return x.GateStatus + return x.UpperPortRange } - return false + return 0 } type ModifySessionRequest struct { @@ -428,7 +454,7 @@ var File_pfcpsim_proto protoreflect.FileDescriptor var file_pfcpsim_proto_rawDesc = []byte{ 0x0a, 0x0d, 0x70, 0x66, 0x63, 0x70, 0x73, 0x69, 0x6d, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, - 0x03, 0x61, 0x70, 0x69, 0x22, 0xde, 0x01, 0x0a, 0x14, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x53, + 0x03, 0x61, 0x70, 0x69, 0x22, 0xf0, 0x02, 0x0a, 0x14, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x16, 0x0a, 0x06, 0x62, 0x61, 0x73, 0x65, 0x49, 0x44, 0x18, 0x02, 0x20, @@ -437,64 +463,73 @@ var file_pfcpsim_proto_rawDesc = []byte{ 0x09, 0x52, 0x0c, 0x6e, 0x6f, 0x64, 0x65, 0x42, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x12, 0x24, 0x0a, 0x0d, 0x75, 0x65, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x50, 0x6f, 0x6f, 0x6c, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x75, 0x65, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, - 0x73, 0x50, 0x6f, 0x6f, 0x6c, 0x12, 0x1c, 0x0a, 0x09, 0x73, 0x64, 0x66, 0x46, 0x69, 0x6c, 0x74, - 0x65, 0x72, 0x18, 0x05, 0x20, 0x03, 0x28, 0x09, 0x52, 0x09, 0x73, 0x64, 0x66, 0x46, 0x69, 0x6c, - 0x74, 0x65, 0x72, 0x12, 0x10, 0x0a, 0x03, 0x71, 0x66, 0x69, 0x18, 0x06, 0x20, 0x01, 0x28, 0x05, - 0x52, 0x03, 0x71, 0x66, 0x69, 0x12, 0x1e, 0x0a, 0x0a, 0x67, 0x61, 0x74, 0x65, 0x53, 0x74, 0x61, - 0x74, 0x75, 0x73, 0x18, 0x07, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0a, 0x67, 0x61, 0x74, 0x65, 0x53, - 0x74, 0x61, 0x74, 0x75, 0x73, 0x22, 0xd2, 0x01, 0x0a, 0x14, 0x4d, 0x6f, 0x64, 0x69, 0x66, 0x79, - 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x14, - 0x0a, 0x05, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x63, - 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x16, 0x0a, 0x06, 0x62, 0x61, 0x73, 0x65, 0x49, 0x44, 0x18, 0x02, - 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x62, 0x61, 0x73, 0x65, 0x49, 0x44, 0x12, 0x22, 0x0a, 0x0c, - 0x6e, 0x6f, 0x64, 0x65, 0x42, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x18, 0x03, 0x20, 0x01, - 0x28, 0x09, 0x52, 0x0c, 0x6e, 0x6f, 0x64, 0x65, 0x42, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, - 0x12, 0x24, 0x0a, 0x0d, 0x75, 0x65, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x50, 0x6f, 0x6f, - 0x6c, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x75, 0x65, 0x41, 0x64, 0x64, 0x72, 0x65, - 0x73, 0x73, 0x50, 0x6f, 0x6f, 0x6c, 0x12, 0x1e, 0x0a, 0x0a, 0x62, 0x75, 0x66, 0x66, 0x65, 0x72, - 0x46, 0x6c, 0x61, 0x67, 0x18, 0x05, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0a, 0x62, 0x75, 0x66, 0x66, - 0x65, 0x72, 0x46, 0x6c, 0x61, 0x67, 0x12, 0x22, 0x0a, 0x0c, 0x6e, 0x6f, 0x74, 0x69, 0x66, 0x79, - 0x43, 0x50, 0x46, 0x6c, 0x61, 0x67, 0x18, 0x06, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0c, 0x6e, 0x6f, - 0x74, 0x69, 0x66, 0x79, 0x43, 0x50, 0x46, 0x6c, 0x61, 0x67, 0x22, 0x64, 0x0a, 0x10, 0x43, 0x6f, - 0x6e, 0x66, 0x69, 0x67, 0x75, 0x72, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x22, - 0x0a, 0x0c, 0x75, 0x70, 0x66, 0x4e, 0x33, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x18, 0x01, - 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x75, 0x70, 0x66, 0x4e, 0x33, 0x41, 0x64, 0x64, 0x72, 0x65, - 0x73, 0x73, 0x12, 0x2c, 0x0a, 0x11, 0x72, 0x65, 0x6d, 0x6f, 0x74, 0x65, 0x50, 0x65, 0x65, 0x72, - 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x11, 0x72, - 0x65, 0x6d, 0x6f, 0x74, 0x65, 0x50, 0x65, 0x65, 0x72, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, - 0x22, 0x44, 0x0a, 0x14, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, - 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x63, 0x6f, 0x75, 0x6e, - 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x16, - 0x0a, 0x06, 0x62, 0x61, 0x73, 0x65, 0x49, 0x44, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, - 0x62, 0x61, 0x73, 0x65, 0x49, 0x44, 0x22, 0x0e, 0x0a, 0x0c, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x52, - 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x22, 0x45, 0x0a, 0x08, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, - 0x73, 0x65, 0x12, 0x1f, 0x0a, 0x0b, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x5f, 0x63, 0x6f, 0x64, - 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x0a, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x43, - 0x6f, 0x64, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x02, - 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x32, 0xda, 0x02, - 0x0a, 0x07, 0x50, 0x46, 0x43, 0x50, 0x53, 0x69, 0x6d, 0x12, 0x33, 0x0a, 0x09, 0x43, 0x6f, 0x6e, - 0x66, 0x69, 0x67, 0x75, 0x72, 0x65, 0x12, 0x15, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x43, 0x6f, 0x6e, - 0x66, 0x69, 0x67, 0x75, 0x72, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x0d, 0x2e, - 0x61, 0x70, 0x69, 0x2e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x2f, - 0x0a, 0x09, 0x41, 0x73, 0x73, 0x6f, 0x63, 0x69, 0x61, 0x74, 0x65, 0x12, 0x11, 0x2e, 0x61, 0x70, - 0x69, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x0d, - 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, - 0x32, 0x0a, 0x0c, 0x44, 0x69, 0x73, 0x61, 0x73, 0x73, 0x6f, 0x63, 0x69, 0x61, 0x74, 0x65, 0x12, - 0x11, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, - 0x73, 0x74, 0x1a, 0x0d, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, - 0x65, 0x22, 0x00, 0x12, 0x3b, 0x0a, 0x0d, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x53, 0x65, 0x73, - 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x19, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, - 0x65, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, + 0x73, 0x50, 0x6f, 0x6f, 0x6c, 0x12, 0x10, 0x0a, 0x03, 0x71, 0x66, 0x69, 0x18, 0x06, 0x20, 0x01, + 0x28, 0x05, 0x52, 0x03, 0x71, 0x66, 0x69, 0x12, 0x34, 0x0a, 0x15, 0x73, 0x65, 0x74, 0x47, 0x61, + 0x74, 0x65, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x54, 0x6f, 0x43, 0x6c, 0x6f, 0x73, 0x65, 0x64, + 0x18, 0x07, 0x20, 0x01, 0x28, 0x08, 0x52, 0x15, 0x73, 0x65, 0x74, 0x47, 0x61, 0x74, 0x65, 0x53, + 0x74, 0x61, 0x74, 0x75, 0x73, 0x54, 0x6f, 0x43, 0x6c, 0x6f, 0x73, 0x65, 0x64, 0x12, 0x1a, 0x0a, + 0x08, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x6c, 0x18, 0x08, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x08, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x6c, 0x12, 0x2c, 0x0a, 0x11, 0x64, 0x65, 0x73, + 0x74, 0x69, 0x6e, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x49, 0x50, 0x43, 0x49, 0x44, 0x52, 0x18, 0x09, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x11, 0x64, 0x65, 0x73, 0x74, 0x69, 0x6e, 0x61, 0x74, 0x69, 0x6f, + 0x6e, 0x49, 0x50, 0x43, 0x49, 0x44, 0x52, 0x12, 0x26, 0x0a, 0x0e, 0x6c, 0x6f, 0x77, 0x65, 0x72, + 0x50, 0x6f, 0x72, 0x74, 0x52, 0x61, 0x6e, 0x67, 0x65, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x05, 0x52, + 0x0e, 0x6c, 0x6f, 0x77, 0x65, 0x72, 0x50, 0x6f, 0x72, 0x74, 0x52, 0x61, 0x6e, 0x67, 0x65, 0x12, + 0x26, 0x0a, 0x0e, 0x75, 0x70, 0x70, 0x65, 0x72, 0x50, 0x6f, 0x72, 0x74, 0x52, 0x61, 0x6e, 0x67, + 0x65, 0x18, 0x0c, 0x20, 0x01, 0x28, 0x05, 0x52, 0x0e, 0x75, 0x70, 0x70, 0x65, 0x72, 0x50, 0x6f, + 0x72, 0x74, 0x52, 0x61, 0x6e, 0x67, 0x65, 0x22, 0xd2, 0x01, 0x0a, 0x14, 0x4d, 0x6f, 0x64, 0x69, + 0x66, 0x79, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, + 0x12, 0x14, 0x0a, 0x05, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, + 0x05, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x16, 0x0a, 0x06, 0x62, 0x61, 0x73, 0x65, 0x49, 0x44, + 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x62, 0x61, 0x73, 0x65, 0x49, 0x44, 0x12, 0x22, + 0x0a, 0x0c, 0x6e, 0x6f, 0x64, 0x65, 0x42, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x18, 0x03, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x6e, 0x6f, 0x64, 0x65, 0x42, 0x41, 0x64, 0x64, 0x72, 0x65, + 0x73, 0x73, 0x12, 0x24, 0x0a, 0x0d, 0x75, 0x65, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x50, + 0x6f, 0x6f, 0x6c, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x75, 0x65, 0x41, 0x64, 0x64, + 0x72, 0x65, 0x73, 0x73, 0x50, 0x6f, 0x6f, 0x6c, 0x12, 0x1e, 0x0a, 0x0a, 0x62, 0x75, 0x66, 0x66, + 0x65, 0x72, 0x46, 0x6c, 0x61, 0x67, 0x18, 0x05, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0a, 0x62, 0x75, + 0x66, 0x66, 0x65, 0x72, 0x46, 0x6c, 0x61, 0x67, 0x12, 0x22, 0x0a, 0x0c, 0x6e, 0x6f, 0x74, 0x69, + 0x66, 0x79, 0x43, 0x50, 0x46, 0x6c, 0x61, 0x67, 0x18, 0x06, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0c, + 0x6e, 0x6f, 0x74, 0x69, 0x66, 0x79, 0x43, 0x50, 0x46, 0x6c, 0x61, 0x67, 0x22, 0x64, 0x0a, 0x10, + 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x75, 0x72, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, + 0x12, 0x22, 0x0a, 0x0c, 0x75, 0x70, 0x66, 0x4e, 0x33, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, + 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x75, 0x70, 0x66, 0x4e, 0x33, 0x41, 0x64, 0x64, + 0x72, 0x65, 0x73, 0x73, 0x12, 0x2c, 0x0a, 0x11, 0x72, 0x65, 0x6d, 0x6f, 0x74, 0x65, 0x50, 0x65, + 0x65, 0x72, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x11, 0x72, 0x65, 0x6d, 0x6f, 0x74, 0x65, 0x50, 0x65, 0x65, 0x72, 0x41, 0x64, 0x64, 0x72, 0x65, + 0x73, 0x73, 0x22, 0x44, 0x0a, 0x14, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x53, 0x65, 0x73, 0x73, + 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x63, 0x6f, + 0x75, 0x6e, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x63, 0x6f, 0x75, 0x6e, 0x74, + 0x12, 0x16, 0x0a, 0x06, 0x62, 0x61, 0x73, 0x65, 0x49, 0x44, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, + 0x52, 0x06, 0x62, 0x61, 0x73, 0x65, 0x49, 0x44, 0x22, 0x0e, 0x0a, 0x0c, 0x45, 0x6d, 0x70, 0x74, + 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x22, 0x45, 0x0a, 0x08, 0x52, 0x65, 0x73, 0x70, + 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x1f, 0x0a, 0x0b, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x5f, 0x63, + 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x0a, 0x73, 0x74, 0x61, 0x74, 0x75, + 0x73, 0x43, 0x6f, 0x64, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, + 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x32, + 0xda, 0x02, 0x0a, 0x07, 0x50, 0x46, 0x43, 0x50, 0x53, 0x69, 0x6d, 0x12, 0x33, 0x0a, 0x09, 0x43, + 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x75, 0x72, 0x65, 0x12, 0x15, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x43, + 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x75, 0x72, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x0d, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, - 0x12, 0x3b, 0x0a, 0x0d, 0x4d, 0x6f, 0x64, 0x69, 0x66, 0x79, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, - 0x6e, 0x12, 0x19, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x4d, 0x6f, 0x64, 0x69, 0x66, 0x79, 0x53, 0x65, - 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x0d, 0x2e, 0x61, - 0x70, 0x69, 0x2e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x3b, 0x0a, - 0x0d, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x19, - 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x53, 0x65, 0x73, 0x73, 0x69, - 0x6f, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x0d, 0x2e, 0x61, 0x70, 0x69, 0x2e, - 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, 0x07, 0x5a, 0x05, 0x2e, 0x3b, - 0x61, 0x70, 0x69, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x12, 0x2f, 0x0a, 0x09, 0x41, 0x73, 0x73, 0x6f, 0x63, 0x69, 0x61, 0x74, 0x65, 0x12, 0x11, 0x2e, + 0x61, 0x70, 0x69, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, + 0x1a, 0x0d, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, + 0x00, 0x12, 0x32, 0x0a, 0x0c, 0x44, 0x69, 0x73, 0x61, 0x73, 0x73, 0x6f, 0x63, 0x69, 0x61, 0x74, + 0x65, 0x12, 0x11, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x52, 0x65, 0x71, + 0x75, 0x65, 0x73, 0x74, 0x1a, 0x0d, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x52, 0x65, 0x73, 0x70, 0x6f, + 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x3b, 0x0a, 0x0d, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x53, + 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x19, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x43, 0x72, 0x65, + 0x61, 0x74, 0x65, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, + 0x74, 0x1a, 0x0d, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, + 0x22, 0x00, 0x12, 0x3b, 0x0a, 0x0d, 0x4d, 0x6f, 0x64, 0x69, 0x66, 0x79, 0x53, 0x65, 0x73, 0x73, + 0x69, 0x6f, 0x6e, 0x12, 0x19, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x4d, 0x6f, 0x64, 0x69, 0x66, 0x79, + 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x0d, + 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, + 0x3b, 0x0a, 0x0d, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, + 0x12, 0x19, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x53, 0x65, 0x73, + 0x73, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x0d, 0x2e, 0x61, 0x70, + 0x69, 0x2e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, 0x07, 0x5a, 0x05, + 0x2e, 0x3b, 0x61, 0x70, 0x69, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/api/pfcpsim.proto b/api/pfcpsim.proto index a18871f..f982349 100644 --- a/api/pfcpsim.proto +++ b/api/pfcpsim.proto @@ -13,9 +13,15 @@ message CreateSessionRequest { int32 baseID = 2; string nodeBAddress = 3; string ueAddressPool = 4; - repeated string sdfFilter = 5; +// string sdfFilter = 5; int32 qfi = 6; // Should be uint8 - bool gateStatus = 7; + // **** SDF filter-related fields **** // + bool setGateStatusToClosed = 7; // If set, the application QERs will have the Gate status to closed. + string protocol = 8; + string destinationIPCIDR = 9; // must be in CIDR notation e.g. 192.168.0.1/24 + int32 lowerPortRange = 10; + int32 upperPortRange = 11; + // **** End of SDF filter-related fields **** // } message ModifySessionRequest { diff --git a/internal/pfcpctl/commands/sessions.go b/internal/pfcpctl/commands/sessions.go index a2370e2..5f3efea 100644 --- a/internal/pfcpctl/commands/sessions.go +++ b/internal/pfcpctl/commands/sessions.go @@ -5,6 +5,7 @@ package commands import ( "context" + "strings" "github.com/jessevdk/go-flags" pb "github.com/omec-project/pfcpsim/api" @@ -16,7 +17,7 @@ type commonArgs struct { 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"` - SDFfilter []string `short:"s" long:"sdf-filter" description:"The SDF Filter to use. Note that each entered SDF Filter will have incremental Precedence set in pfcpsim."` + AppFilterString string `short:"a" long:"app-filter" description:"Specify an application filter. Format: ':/:-:' . 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."` GateStatus bool `short:"t" long:"gate-status" description:"If set, the QER gate status will be CLOSED"` } @@ -60,6 +61,16 @@ func (s *sessionCreate) Execute(args []string) error { client := connect() defer disconnect() + if s.Args.AppFilterString != "" { + splittedString := strings.Split(s.Args.AppFilterString, ":") + if len (splittedString) != 4 { + log.Fatalf("Provided an incorrect/incomplete app filter string: %v", s.Args.AppFilterString) + } + + proto, ipNetAddr, portRange, action := splittedString[0], splittedString[1], splittedString[2], splittedString[3] + //FIXME incomplete + } + res, err := client.CreateSession(context.Background(), &pb.CreateSessionRequest{ Count: int32(s.Args.Count), BaseID: int32(s.Args.BaseID), diff --git a/internal/pfcpsim/server.go b/internal/pfcpsim/server.go index dee3fc7..49b3174 100644 --- a/internal/pfcpsim/server.go +++ b/internal/pfcpsim/server.go @@ -17,6 +17,8 @@ import ( "google.golang.org/grpc/codes" "google.golang.org/grpc/status" ) +// e.g. --app-filter udp:10.0.0.0/8:80-88:allow. allow will select the gate-status to open. deny closed. +const SDFFilterFormat = "permit out %s from %s to assigned %d-%d" // pfcpSimService implements the Protobuf interface and keeps a connection to a remote PFCP Agent peer. // Its state is handled in internal/pfcpsim/state.go @@ -125,10 +127,15 @@ func (P pfcpSimService) CreateSession(ctx context.Context, request *pb.CreateSes } - var SDFFilter = "" + var SDFFilter = fmt.Sprintf(SDFFilterFormat, + request.Protocol, + request.DestinationIPCIDR, + request.LowerPortRange, + request.UpperPortRange, + ) var qfi, gateStatus uint8 = 0, ieLib.GateStatusOpen - if request.GateStatus { + if request.SetGateStatusToClosed { gateStatus = ieLib.GateStatusClosed } From 4dfd9fe61d6d4cf2fe020ade85e6c6a0ff3564a6 Mon Sep 17 00:00:00 2001 From: Emanuele Gallone Date: Thu, 10 Mar 2022 19:37:21 +0100 Subject: [PATCH 12/18] Address review comments --- internal/pfcpctl/commands/sessions.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/pfcpctl/commands/sessions.go b/internal/pfcpctl/commands/sessions.go index 93dc448..ba0d388 100644 --- a/internal/pfcpctl/commands/sessions.go +++ b/internal/pfcpctl/commands/sessions.go @@ -18,7 +18,7 @@ type commonArgs struct { GnBAddress string `short:"g" long:"gnb-addr" description:"The (g/e)nodeB address"` SDFfilter string `short:"s" long:"sdf-filter" description:"The SDF Filter to use"` QFI uint8 `short:"q" long:"qfi" description:"The QFI value for QERs. Max value 64."` - GateStatus bool `short:"t" long:"gate-status" description:"If set, the QER gate status will be CLOSED"` + GateStatus bool `short:"t" long:"gate-closed" description:"If set, the application QER gate status will be CLOSED"` } type sessionCreate struct { From 495184ac7719dbf1a56ba90bd12beabc0a090194 Mon Sep 17 00:00:00 2001 From: Emanuele Gallone Date: Thu, 10 Mar 2022 19:47:18 +0100 Subject: [PATCH 13/18] Address review comments --- api/pfcpsim.pb.go | 12 ++++++------ api/pfcpsim.proto | 2 +- internal/pfcpctl/commands/sessions.go | 6 +++--- internal/pfcpsim/server.go | 2 +- pkg/pfcpsim/session/qer_builder.go | 4 ++-- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/api/pfcpsim.pb.go b/api/pfcpsim.pb.go index 72aaf98..358fcad 100644 --- a/api/pfcpsim.pb.go +++ b/api/pfcpsim.pb.go @@ -45,7 +45,7 @@ type CreateSessionRequest struct { UeAddressPool string `protobuf:"bytes,4,opt,name=ueAddressPool,proto3" json:"ueAddressPool,omitempty"` SdfFilter string `protobuf:"bytes,5,opt,name=sdfFilter,proto3" json:"sdfFilter,omitempty"` Qfi int32 `protobuf:"varint,6,opt,name=qfi,proto3" json:"qfi,omitempty"` // Should be uint8 - GateStatus bool `protobuf:"varint,7,opt,name=gateStatus,proto3" json:"gateStatus,omitempty"` + GateClosed bool `protobuf:"varint,7,opt,name=gateClosed,proto3" json:"gateClosed,omitempty"` } func (x *CreateSessionRequest) Reset() { @@ -122,9 +122,9 @@ func (x *CreateSessionRequest) GetQfi() int32 { return 0 } -func (x *CreateSessionRequest) GetGateStatus() bool { +func (x *CreateSessionRequest) GetGateClosed() bool { if x != nil { - return x.GateStatus + return x.GateClosed } return false } @@ -440,9 +440,9 @@ var file_pfcpsim_proto_rawDesc = []byte{ 0x73, 0x50, 0x6f, 0x6f, 0x6c, 0x12, 0x1c, 0x0a, 0x09, 0x73, 0x64, 0x66, 0x46, 0x69, 0x6c, 0x74, 0x65, 0x72, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x73, 0x64, 0x66, 0x46, 0x69, 0x6c, 0x74, 0x65, 0x72, 0x12, 0x10, 0x0a, 0x03, 0x71, 0x66, 0x69, 0x18, 0x06, 0x20, 0x01, 0x28, 0x05, - 0x52, 0x03, 0x71, 0x66, 0x69, 0x12, 0x1e, 0x0a, 0x0a, 0x67, 0x61, 0x74, 0x65, 0x53, 0x74, 0x61, - 0x74, 0x75, 0x73, 0x18, 0x07, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0a, 0x67, 0x61, 0x74, 0x65, 0x53, - 0x74, 0x61, 0x74, 0x75, 0x73, 0x22, 0xd2, 0x01, 0x0a, 0x14, 0x4d, 0x6f, 0x64, 0x69, 0x66, 0x79, + 0x52, 0x03, 0x71, 0x66, 0x69, 0x12, 0x1e, 0x0a, 0x0a, 0x67, 0x61, 0x74, 0x65, 0x43, 0x6c, 0x6f, + 0x73, 0x65, 0x64, 0x18, 0x07, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0a, 0x67, 0x61, 0x74, 0x65, 0x43, + 0x6c, 0x6f, 0x73, 0x65, 0x64, 0x22, 0xd2, 0x01, 0x0a, 0x14, 0x4d, 0x6f, 0x64, 0x69, 0x66, 0x79, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x16, 0x0a, 0x06, 0x62, 0x61, 0x73, 0x65, 0x49, 0x44, 0x18, 0x02, diff --git a/api/pfcpsim.proto b/api/pfcpsim.proto index fc14c97..84edc2a 100644 --- a/api/pfcpsim.proto +++ b/api/pfcpsim.proto @@ -15,7 +15,7 @@ message CreateSessionRequest { string ueAddressPool = 4; string sdfFilter = 5; int32 qfi = 6; // Should be uint8 - bool gateStatus = 7; + bool gateClosed = 7; } message ModifySessionRequest { diff --git a/internal/pfcpctl/commands/sessions.go b/internal/pfcpctl/commands/sessions.go index ba0d388..4449602 100644 --- a/internal/pfcpctl/commands/sessions.go +++ b/internal/pfcpctl/commands/sessions.go @@ -17,8 +17,8 @@ type commonArgs struct { 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 (g/e)nodeB address"` SDFfilter string `short:"s" long:"sdf-filter" description:"The SDF Filter to use"` - QFI uint8 `short:"q" long:"qfi" description:"The QFI value for QERs. Max value 64."` - GateStatus bool `short:"t" long:"gate-closed" description:"If set, the application QER gate status will be CLOSED"` + QFI uint8 `short:"q" long:"qfi" description:"The QFI value for QERs. Max value 64."` + GateClosed bool `short:"t" long:"gate-closed" description:"If set, the application QER gate status will be CLOSED"` } type sessionCreate struct { @@ -67,7 +67,7 @@ func (s *sessionCreate) Execute(args []string) error { UeAddressPool: s.Args.UePool, SdfFilter: s.Args.SDFfilter, Qfi: int32(s.Args.QFI), - GateStatus: s.Args.GateStatus, + GateClosed: s.Args.GateClosed, }) if err != nil { diff --git a/internal/pfcpsim/server.go b/internal/pfcpsim/server.go index cbe6e19..d08ee73 100644 --- a/internal/pfcpsim/server.go +++ b/internal/pfcpsim/server.go @@ -127,7 +127,7 @@ func (P pfcpSimService) CreateSession(ctx context.Context, request *pb.CreateSes var SDFFilter = "" var qfi, gateStatus uint8 = 0, ieLib.GateStatusOpen - if request.GateStatus { + if request.GateClosed { gateStatus = ieLib.GateStatusClosed } diff --git a/pkg/pfcpsim/session/qer_builder.go b/pkg/pfcpsim/session/qer_builder.go index 42a88b9..4bce00e 100644 --- a/pkg/pfcpsim/session/qer_builder.go +++ b/pkg/pfcpsim/session/qer_builder.go @@ -90,9 +90,9 @@ func (b *qerBuilder) Build() *ie.IE { createFunc = ie.NewUpdateQER } - gate := ie.NewGateStatus(0, 0) //Open + gate := ie.NewGateStatus(ie.GateStatusOpen, ie.GateStatusOpen) if b.gateStatus == ie.GateStatusClosed { - gate = ie.NewGateStatus(1, 1) + gate = ie.NewGateStatus(ie.GateStatusClosed, ie.GateStatusClosed) } qer := createFunc( From a63006e682d8141b5b60f48b30568eba103fc8fb Mon Sep 17 00:00:00 2001 From: Emanuele Gallone Date: Fri, 11 Mar 2022 10:39:36 +0100 Subject: [PATCH 14/18] Add support for app-filter string --- api/pfcpsim.pb.go | 168 ++++++++++---------------- api/pfcpsim.proto | 8 +- internal/pfcpctl/commands/services.go | 6 +- internal/pfcpctl/commands/sessions.go | 37 ++---- internal/pfcpsim/helpers.go | 56 +++++++++ internal/pfcpsim/server.go | 97 +++++++-------- pkg/pfcpsim/errors.go | 7 ++ 7 files changed, 190 insertions(+), 189 deletions(-) diff --git a/api/pfcpsim.pb.go b/api/pfcpsim.pb.go index 9921795..b34d2af 100644 --- a/api/pfcpsim.pb.go +++ b/api/pfcpsim.pb.go @@ -43,14 +43,9 @@ type CreateSessionRequest struct { BaseID int32 `protobuf:"varint,2,opt,name=baseID,proto3" json:"baseID,omitempty"` NodeBAddress string `protobuf:"bytes,3,opt,name=nodeBAddress,proto3" json:"nodeBAddress,omitempty"` UeAddressPool string `protobuf:"bytes,4,opt,name=ueAddressPool,proto3" json:"ueAddressPool,omitempty"` - // string sdfFilter = 5; - Qfi int32 `protobuf:"varint,6,opt,name=qfi,proto3" json:"qfi,omitempty"` // Should be uint8 - // **** SDF filter-related fields **** // - GateClosed bool `protobuf:"varint,7,opt,name=gateClosed,proto3" json:"gateClosed,omitempty"` // If set, the application QERs will have the Gate status to closed. - Protocol string `protobuf:"bytes,8,opt,name=protocol,proto3" json:"protocol,omitempty"` - DestinationIPCIDR string `protobuf:"bytes,9,opt,name=destinationIPCIDR,proto3" json:"destinationIPCIDR,omitempty"` // must be in CIDR notation e.g. 192.168.0.1/24 - LowerPortRange int32 `protobuf:"varint,10,opt,name=lowerPortRange,proto3" json:"lowerPortRange,omitempty"` - UpperPortRange int32 `protobuf:"varint,11,opt,name=upperPortRange,proto3" json:"upperPortRange,omitempty"` // **** End of SDF filter-related fields **** // + AppFilter string `protobuf:"bytes,5,opt,name=appFilter,proto3" json:"appFilter,omitempty"` + Qfi int32 `protobuf:"varint,6,opt,name=qfi,proto3" json:"qfi,omitempty"` // Should be uint8 + GateClosed bool `protobuf:"varint,7,opt,name=gateClosed,proto3" json:"gateClosed,omitempty"` // If set, the application QERs will have the Gate status to closed. } func (x *CreateSessionRequest) Reset() { @@ -113,46 +108,25 @@ func (x *CreateSessionRequest) GetUeAddressPool() string { return "" } -func (x *CreateSessionRequest) GetQfi() int32 { +func (x *CreateSessionRequest) GetAppFilter() string { if x != nil { - return x.Qfi - } - return 0 -} - -func (x *CreateSessionRequest) GetGateClosed() bool { - if x != nil { - return x.GateClosed - } - return false -} - -func (x *CreateSessionRequest) GetProtocol() string { - if x != nil { - return x.Protocol - } - return "" -} - -func (x *CreateSessionRequest) GetDestinationIPCIDR() string { - if x != nil { - return x.DestinationIPCIDR + return x.AppFilter } return "" } -func (x *CreateSessionRequest) GetLowerPortRange() int32 { +func (x *CreateSessionRequest) GetQfi() int32 { if x != nil { - return x.LowerPortRange + return x.Qfi } return 0 } -func (x *CreateSessionRequest) GetUpperPortRange() int32 { +func (x *CreateSessionRequest) GetGateClosed() bool { if x != nil { - return x.UpperPortRange + return x.GateClosed } - return 0 + return false } type ModifySessionRequest struct { @@ -454,7 +428,7 @@ var File_pfcpsim_proto protoreflect.FileDescriptor var file_pfcpsim_proto_rawDesc = []byte{ 0x0a, 0x0d, 0x70, 0x66, 0x63, 0x70, 0x73, 0x69, 0x6d, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, - 0x03, 0x61, 0x70, 0x69, 0x22, 0xda, 0x02, 0x0a, 0x14, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x53, + 0x03, 0x61, 0x70, 0x69, 0x22, 0xde, 0x01, 0x0a, 0x14, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x16, 0x0a, 0x06, 0x62, 0x61, 0x73, 0x65, 0x49, 0x44, 0x18, 0x02, 0x20, @@ -463,72 +437,64 @@ var file_pfcpsim_proto_rawDesc = []byte{ 0x09, 0x52, 0x0c, 0x6e, 0x6f, 0x64, 0x65, 0x42, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x12, 0x24, 0x0a, 0x0d, 0x75, 0x65, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x50, 0x6f, 0x6f, 0x6c, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x75, 0x65, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, - 0x73, 0x50, 0x6f, 0x6f, 0x6c, 0x12, 0x10, 0x0a, 0x03, 0x71, 0x66, 0x69, 0x18, 0x06, 0x20, 0x01, - 0x28, 0x05, 0x52, 0x03, 0x71, 0x66, 0x69, 0x12, 0x1e, 0x0a, 0x0a, 0x67, 0x61, 0x74, 0x65, 0x43, - 0x6c, 0x6f, 0x73, 0x65, 0x64, 0x18, 0x07, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0a, 0x67, 0x61, 0x74, - 0x65, 0x43, 0x6c, 0x6f, 0x73, 0x65, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x63, 0x6f, 0x6c, 0x18, 0x08, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x63, 0x6f, 0x6c, 0x12, 0x2c, 0x0a, 0x11, 0x64, 0x65, 0x73, 0x74, 0x69, 0x6e, 0x61, 0x74, 0x69, - 0x6f, 0x6e, 0x49, 0x50, 0x43, 0x49, 0x44, 0x52, 0x18, 0x09, 0x20, 0x01, 0x28, 0x09, 0x52, 0x11, - 0x64, 0x65, 0x73, 0x74, 0x69, 0x6e, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x49, 0x50, 0x43, 0x49, 0x44, - 0x52, 0x12, 0x26, 0x0a, 0x0e, 0x6c, 0x6f, 0x77, 0x65, 0x72, 0x50, 0x6f, 0x72, 0x74, 0x52, 0x61, - 0x6e, 0x67, 0x65, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x05, 0x52, 0x0e, 0x6c, 0x6f, 0x77, 0x65, 0x72, - 0x50, 0x6f, 0x72, 0x74, 0x52, 0x61, 0x6e, 0x67, 0x65, 0x12, 0x26, 0x0a, 0x0e, 0x75, 0x70, 0x70, - 0x65, 0x72, 0x50, 0x6f, 0x72, 0x74, 0x52, 0x61, 0x6e, 0x67, 0x65, 0x18, 0x0b, 0x20, 0x01, 0x28, - 0x05, 0x52, 0x0e, 0x75, 0x70, 0x70, 0x65, 0x72, 0x50, 0x6f, 0x72, 0x74, 0x52, 0x61, 0x6e, 0x67, - 0x65, 0x22, 0xd2, 0x01, 0x0a, 0x14, 0x4d, 0x6f, 0x64, 0x69, 0x66, 0x79, 0x53, 0x65, 0x73, 0x73, - 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x63, 0x6f, - 0x75, 0x6e, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x63, 0x6f, 0x75, 0x6e, 0x74, - 0x12, 0x16, 0x0a, 0x06, 0x62, 0x61, 0x73, 0x65, 0x49, 0x44, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, - 0x52, 0x06, 0x62, 0x61, 0x73, 0x65, 0x49, 0x44, 0x12, 0x22, 0x0a, 0x0c, 0x6e, 0x6f, 0x64, 0x65, - 0x42, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, - 0x6e, 0x6f, 0x64, 0x65, 0x42, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x12, 0x24, 0x0a, 0x0d, - 0x75, 0x65, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x50, 0x6f, 0x6f, 0x6c, 0x18, 0x04, 0x20, - 0x01, 0x28, 0x09, 0x52, 0x0d, 0x75, 0x65, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x50, 0x6f, - 0x6f, 0x6c, 0x12, 0x1e, 0x0a, 0x0a, 0x62, 0x75, 0x66, 0x66, 0x65, 0x72, 0x46, 0x6c, 0x61, 0x67, - 0x18, 0x05, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0a, 0x62, 0x75, 0x66, 0x66, 0x65, 0x72, 0x46, 0x6c, - 0x61, 0x67, 0x12, 0x22, 0x0a, 0x0c, 0x6e, 0x6f, 0x74, 0x69, 0x66, 0x79, 0x43, 0x50, 0x46, 0x6c, - 0x61, 0x67, 0x18, 0x06, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0c, 0x6e, 0x6f, 0x74, 0x69, 0x66, 0x79, - 0x43, 0x50, 0x46, 0x6c, 0x61, 0x67, 0x22, 0x64, 0x0a, 0x10, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, - 0x75, 0x72, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x22, 0x0a, 0x0c, 0x75, 0x70, - 0x66, 0x4e, 0x33, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, - 0x52, 0x0c, 0x75, 0x70, 0x66, 0x4e, 0x33, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x12, 0x2c, - 0x0a, 0x11, 0x72, 0x65, 0x6d, 0x6f, 0x74, 0x65, 0x50, 0x65, 0x65, 0x72, 0x41, 0x64, 0x64, 0x72, - 0x65, 0x73, 0x73, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x11, 0x72, 0x65, 0x6d, 0x6f, 0x74, - 0x65, 0x50, 0x65, 0x65, 0x72, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x22, 0x44, 0x0a, 0x14, - 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x71, - 0x75, 0x65, 0x73, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x01, 0x20, - 0x01, 0x28, 0x05, 0x52, 0x05, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x16, 0x0a, 0x06, 0x62, 0x61, - 0x73, 0x65, 0x49, 0x44, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x62, 0x61, 0x73, 0x65, - 0x49, 0x44, 0x22, 0x0e, 0x0a, 0x0c, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, - 0x73, 0x74, 0x22, 0x45, 0x0a, 0x08, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x1f, - 0x0a, 0x0b, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x5f, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, - 0x01, 0x28, 0x05, 0x52, 0x0a, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x43, 0x6f, 0x64, 0x65, 0x12, - 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, - 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x32, 0xda, 0x02, 0x0a, 0x07, 0x50, 0x46, - 0x43, 0x50, 0x53, 0x69, 0x6d, 0x12, 0x33, 0x0a, 0x09, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x75, - 0x72, 0x65, 0x12, 0x15, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x75, - 0x72, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x0d, 0x2e, 0x61, 0x70, 0x69, 0x2e, - 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x2f, 0x0a, 0x09, 0x41, 0x73, - 0x73, 0x6f, 0x63, 0x69, 0x61, 0x74, 0x65, 0x12, 0x11, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x45, 0x6d, - 0x70, 0x74, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x0d, 0x2e, 0x61, 0x70, 0x69, - 0x2e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x32, 0x0a, 0x0c, 0x44, - 0x69, 0x73, 0x61, 0x73, 0x73, 0x6f, 0x63, 0x69, 0x61, 0x74, 0x65, 0x12, 0x11, 0x2e, 0x61, 0x70, + 0x73, 0x50, 0x6f, 0x6f, 0x6c, 0x12, 0x1c, 0x0a, 0x09, 0x61, 0x70, 0x70, 0x46, 0x69, 0x6c, 0x74, + 0x65, 0x72, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x61, 0x70, 0x70, 0x46, 0x69, 0x6c, + 0x74, 0x65, 0x72, 0x12, 0x10, 0x0a, 0x03, 0x71, 0x66, 0x69, 0x18, 0x06, 0x20, 0x01, 0x28, 0x05, + 0x52, 0x03, 0x71, 0x66, 0x69, 0x12, 0x1e, 0x0a, 0x0a, 0x67, 0x61, 0x74, 0x65, 0x43, 0x6c, 0x6f, + 0x73, 0x65, 0x64, 0x18, 0x07, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0a, 0x67, 0x61, 0x74, 0x65, 0x43, + 0x6c, 0x6f, 0x73, 0x65, 0x64, 0x22, 0xd2, 0x01, 0x0a, 0x14, 0x4d, 0x6f, 0x64, 0x69, 0x66, 0x79, + 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x14, + 0x0a, 0x05, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x63, + 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x16, 0x0a, 0x06, 0x62, 0x61, 0x73, 0x65, 0x49, 0x44, 0x18, 0x02, + 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x62, 0x61, 0x73, 0x65, 0x49, 0x44, 0x12, 0x22, 0x0a, 0x0c, + 0x6e, 0x6f, 0x64, 0x65, 0x42, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x18, 0x03, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x0c, 0x6e, 0x6f, 0x64, 0x65, 0x42, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, + 0x12, 0x24, 0x0a, 0x0d, 0x75, 0x65, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x50, 0x6f, 0x6f, + 0x6c, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x75, 0x65, 0x41, 0x64, 0x64, 0x72, 0x65, + 0x73, 0x73, 0x50, 0x6f, 0x6f, 0x6c, 0x12, 0x1e, 0x0a, 0x0a, 0x62, 0x75, 0x66, 0x66, 0x65, 0x72, + 0x46, 0x6c, 0x61, 0x67, 0x18, 0x05, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0a, 0x62, 0x75, 0x66, 0x66, + 0x65, 0x72, 0x46, 0x6c, 0x61, 0x67, 0x12, 0x22, 0x0a, 0x0c, 0x6e, 0x6f, 0x74, 0x69, 0x66, 0x79, + 0x43, 0x50, 0x46, 0x6c, 0x61, 0x67, 0x18, 0x06, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0c, 0x6e, 0x6f, + 0x74, 0x69, 0x66, 0x79, 0x43, 0x50, 0x46, 0x6c, 0x61, 0x67, 0x22, 0x64, 0x0a, 0x10, 0x43, 0x6f, + 0x6e, 0x66, 0x69, 0x67, 0x75, 0x72, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x22, + 0x0a, 0x0c, 0x75, 0x70, 0x66, 0x4e, 0x33, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x75, 0x70, 0x66, 0x4e, 0x33, 0x41, 0x64, 0x64, 0x72, 0x65, + 0x73, 0x73, 0x12, 0x2c, 0x0a, 0x11, 0x72, 0x65, 0x6d, 0x6f, 0x74, 0x65, 0x50, 0x65, 0x65, 0x72, + 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x11, 0x72, + 0x65, 0x6d, 0x6f, 0x74, 0x65, 0x50, 0x65, 0x65, 0x72, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, + 0x22, 0x44, 0x0a, 0x14, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, + 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x63, 0x6f, 0x75, 0x6e, + 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x16, + 0x0a, 0x06, 0x62, 0x61, 0x73, 0x65, 0x49, 0x44, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, + 0x62, 0x61, 0x73, 0x65, 0x49, 0x44, 0x22, 0x0e, 0x0a, 0x0c, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x52, + 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x22, 0x45, 0x0a, 0x08, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, + 0x73, 0x65, 0x12, 0x1f, 0x0a, 0x0b, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x5f, 0x63, 0x6f, 0x64, + 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x0a, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x43, + 0x6f, 0x64, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x02, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x32, 0xda, 0x02, + 0x0a, 0x07, 0x50, 0x46, 0x43, 0x50, 0x53, 0x69, 0x6d, 0x12, 0x33, 0x0a, 0x09, 0x43, 0x6f, 0x6e, + 0x66, 0x69, 0x67, 0x75, 0x72, 0x65, 0x12, 0x15, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x43, 0x6f, 0x6e, + 0x66, 0x69, 0x67, 0x75, 0x72, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x0d, 0x2e, + 0x61, 0x70, 0x69, 0x2e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x2f, + 0x0a, 0x09, 0x41, 0x73, 0x73, 0x6f, 0x63, 0x69, 0x61, 0x74, 0x65, 0x12, 0x11, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x0d, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, - 0x3b, 0x0a, 0x0d, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, - 0x12, 0x19, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x53, 0x65, 0x73, - 0x73, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x0d, 0x2e, 0x61, 0x70, - 0x69, 0x2e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x3b, 0x0a, 0x0d, - 0x4d, 0x6f, 0x64, 0x69, 0x66, 0x79, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x19, 0x2e, - 0x61, 0x70, 0x69, 0x2e, 0x4d, 0x6f, 0x64, 0x69, 0x66, 0x79, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, - 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x0d, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x52, - 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x3b, 0x0a, 0x0d, 0x44, 0x65, 0x6c, - 0x65, 0x74, 0x65, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x19, 0x2e, 0x61, 0x70, 0x69, - 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x52, 0x65, - 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x0d, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x52, 0x65, 0x73, 0x70, - 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, 0x07, 0x5a, 0x05, 0x2e, 0x3b, 0x61, 0x70, 0x69, 0x62, - 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x32, 0x0a, 0x0c, 0x44, 0x69, 0x73, 0x61, 0x73, 0x73, 0x6f, 0x63, 0x69, 0x61, 0x74, 0x65, 0x12, + 0x11, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x1a, 0x0d, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, + 0x65, 0x22, 0x00, 0x12, 0x3b, 0x0a, 0x0d, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x53, 0x65, 0x73, + 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x19, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, + 0x65, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, + 0x0d, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, + 0x12, 0x3b, 0x0a, 0x0d, 0x4d, 0x6f, 0x64, 0x69, 0x66, 0x79, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, + 0x6e, 0x12, 0x19, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x4d, 0x6f, 0x64, 0x69, 0x66, 0x79, 0x53, 0x65, + 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x0d, 0x2e, 0x61, + 0x70, 0x69, 0x2e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x3b, 0x0a, + 0x0d, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x19, + 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x53, 0x65, 0x73, 0x73, 0x69, + 0x6f, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x0d, 0x2e, 0x61, 0x70, 0x69, 0x2e, + 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, 0x07, 0x5a, 0x05, 0x2e, 0x3b, + 0x61, 0x70, 0x69, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/api/pfcpsim.proto b/api/pfcpsim.proto index 3e85829..ec36ce5 100644 --- a/api/pfcpsim.proto +++ b/api/pfcpsim.proto @@ -13,15 +13,9 @@ message CreateSessionRequest { int32 baseID = 2; string nodeBAddress = 3; string ueAddressPool = 4; -// string sdfFilter = 5; + string appFilter = 5; int32 qfi = 6; // Should be uint8 - // **** SDF filter-related fields **** // bool gateClosed = 7; // If set, the application QERs will have the Gate status to closed. - string protocol = 8; - string destinationIPCIDR = 9; // must be in CIDR notation e.g. 192.168.0.1/24 - int32 lowerPortRange = 10; - int32 upperPortRange = 11; - // **** End of SDF filter-related fields **** // } message ModifySessionRequest { diff --git a/internal/pfcpctl/commands/services.go b/internal/pfcpctl/commands/services.go index 48e8053..735b8d4 100644 --- a/internal/pfcpctl/commands/services.go +++ b/internal/pfcpctl/commands/services.go @@ -11,10 +11,10 @@ import ( log "github.com/sirupsen/logrus" ) -type associate struct {} -type disassociate struct {} +type associate struct{} +type disassociate struct{} type configureRemoteAddresses struct { - RemotePeerAddress string `short:"r" long:"remote-peer-addr" default:"" description:"The remote PFCP agent address."` + RemotePeerAddress string `short:"r" long:"remote-peer-addr" default:"" description:"The remote PFCP agent address."` N3InterfaceAddress string `short:"n" long:"n3-addr" default:"" description:"The IPv4 address of the UPF's N3 interface"` } diff --git a/internal/pfcpctl/commands/sessions.go b/internal/pfcpctl/commands/sessions.go index 6d147a6..e42e5f1 100644 --- a/internal/pfcpctl/commands/sessions.go +++ b/internal/pfcpctl/commands/sessions.go @@ -5,7 +5,6 @@ package commands import ( "context" - "strings" "github.com/jessevdk/go-flags" pb "github.com/omec-project/pfcpsim/api" @@ -13,17 +12,17 @@ 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"` + 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: ':/:-:' . 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."` - GateClosed bool `short:"t" long:"gate-status" description:"If set, the QER gate status will be CLOSED"` + QFI uint8 `short:"q" long:"qfi" description:"The QFI value for QERs. Max value 64."` + GateClosed bool `short:"t" long:"gate-closed" description:"If set, the QER gate status will be CLOSED"` } type sessionCreate struct { - Args struct{ + Args struct { commonArgs } } @@ -31,14 +30,14 @@ type sessionCreate struct { type sessionModify struct { Args struct { commonArgs - BufferFlag bool `short:"b" long:"buffer" description:"If set, downlink FARs will have the buffer flag set to true"` + BufferFlag bool `short:"b" long:"buffer" description:"If set, downlink FARs will have the buffer flag set to true"` NotifyCPFlag bool `short:"n" long:"notifycp" description:"If set, downlink FARs will have the notify CP flag set to true"` } } type sessionDelete struct { - Args struct{ - Count int `short:"c" long:"count" default:"1" description:"The number of sessions to create"` + Args 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"` } } @@ -61,24 +60,14 @@ func (s *sessionCreate) Execute(args []string) error { client := connect() defer disconnect() - if s.Args.AppFilterString != "" { - splittedString := strings.Split(s.Args.AppFilterString, ":") - if len (splittedString) != 4 { - log.Fatalf("Provided an incorrect/incomplete app filter string: %v", s.Args.AppFilterString) - } - - proto, ipNetAddr, portRange, action := splittedString[0], splittedString[1], splittedString[2], splittedString[3] - //FIXME incomplete - } - 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, - SdfFilter: s.Args.SDFfilter, - Qfi: int32(s.Args.QFI), - GateClosed: s.Args.GateClosed, + AppFilter: s.Args.AppFilterString, + Qfi: int32(s.Args.QFI), + GateClosed: s.Args.GateClosed, }) if err != nil { diff --git a/internal/pfcpsim/helpers.go b/internal/pfcpsim/helpers.go index 3ca108e..28577da 100644 --- a/internal/pfcpsim/helpers.go +++ b/internal/pfcpsim/helpers.go @@ -4,11 +4,17 @@ package pfcpsim import ( + "fmt" "net" + "strconv" + "strings" "github.com/omec-project/pfcpsim/pkg/pfcpsim" + "github.com/wmnsk/go-pfcp/ie" ) +const sdfFilterFormat = "permit out %v from %v to assigned %v-%v" + func connectPFCPSim() error { if sim == nil { localAddr, err := getLocalAddress(interfaceName) @@ -71,3 +77,53 @@ func getLocalAddress(interfaceName string) (net.IP, error) { return nil, pfcpsim.NewNoValidInterfaceError() } + +// parseAppFilter parses an application filter. Returns a tuple formed by a formatted SDF filter +// and a uint8 representing the Application QER gate status. Returns error if fail occurs while validating the filter string. +func parseAppFilter(filter string) (string, uint8, error) { + result := strings.Split(filter, ":") + if len(result) != 4 { + return "", 0, pfcpsim.NewInvalidFormatError("Parser was not able to generate the correct number of arguments." + + " Please make sure to use the right format") + } + + proto, ipNetAddr, portRange, action := result[0], result[1], result[2], result[3] + + if !(proto == "ip" || proto == "udp" || proto == "tcp") { + return "", 0, pfcpsim.NewInvalidFormatError("Unsupported or unknown protocol.") + } + + _, _, err := net.ParseCIDR(ipNetAddr) + if err != nil { + return "", 0, pfcpsim.NewInvalidFormatError("IP and subnet mask.", err) + } + + portList := strings.Split(portRange, "-") + if !(len(portList) == 2) { + return "", 0, pfcpsim.NewInvalidFormatError("Port range. Please make sure to use dash '-' to separate the two ports") + } + + lowerPort, err := strconv.Atoi(portList[0]) + if err != nil { + return "", 0, pfcpsim.NewInvalidFormatError("Port range.", err) + } + + upperPort, err := strconv.Atoi(portList[1]) + if err != nil { + return "", 0, pfcpsim.NewInvalidFormatError("Port range.", err) + } + + if lowerPort > upperPort { + return "", 0, pfcpsim.NewInvalidFormatError("Port range. Lower port is greater than upper port") + } + + if !(action == "allow" || action == "deny") { + return "", 0, pfcpsim.NewInvalidFormatError("Action. Please make sure to use 'allow' or 'deny'") + } + + if action == "allow" { + return fmt.Sprintf(sdfFilterFormat, proto, ipNetAddr, lowerPort, upperPort), ie.GateStatusOpen, nil + } + + return fmt.Sprintf(sdfFilterFormat, proto, ipNetAddr, lowerPort, upperPort), ie.GateStatusClosed, nil +} diff --git a/internal/pfcpsim/server.go b/internal/pfcpsim/server.go index 512e6e0..c2912db 100644 --- a/internal/pfcpsim/server.go +++ b/internal/pfcpsim/server.go @@ -17,8 +17,6 @@ import ( "google.golang.org/grpc/codes" "google.golang.org/grpc/status" ) -// e.g. --app-filter udp:10.0.0.0/8:80-88:allow. allow will select the gate-status to open. deny closed. -const SDFFilterFormat = "permit out %s from %s to assigned %d-%d" // pfcpSimService implements the Protobuf interface and keeps a connection to a remote PFCP Agent peer. // Its state is handled in internal/pfcpsim/state.go @@ -126,15 +124,18 @@ func (P pfcpSimService) CreateSession(ctx context.Context, request *pb.CreateSes return &pb.Response{}, status.Error(codes.Aborted, errMsg) } - - var SDFFilter = fmt.Sprintf(SDFFilterFormat, - request.Protocol, - request.DestinationIPCIDR, - request.LowerPortRange, - request.UpperPortRange, - ) + 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.GateClosed { gateStatus = ieLib.GateStatusClosed } @@ -143,12 +144,7 @@ func (P pfcpSimService) CreateSession(ctx context.Context, request *pb.CreateSes qfi = uint8(request.Qfi) } - //if len(request.SdfFilter) == 0 != "" { - // SDFFilter = request.SdfFilter - //} - - - for i := baseID; i < (count*2 + baseID); i = i + 2 { //FIXME increment step should take into account the number of SDF Filters + for i := baseID; i < (count*2 + baseID); i = i + 2 { // using variables to ease comprehension on how rules are linked together uplinkTEID := uint32(i) @@ -158,12 +154,43 @@ func (P pfcpSimService) CreateSession(ctx context.Context, request *pb.CreateSes uplinkFarID := uint32(i) downlinkFarID := uint32(i + 1) + uplinkPdrID := uint16(i) + downlinkPdrID := uint16(i + 1) + sessQerID := uint32(i + 3) uplinkAppQerID := uint32(i) downlinkAppQerID := uint32(i + 1) - pdrs := []*ieLib.IE{} // Updated below + pdrs := []*ieLib.IE{ + // UplinkPDR + session.NewPDRBuilder(). + WithID(uplinkPdrID). + WithMethod(session.Create). + WithTEID(uplinkTEID). + WithFARID(uplinkFarID). + AddQERID(sessQerID). + AddQERID(uplinkAppQerID). + WithN3Address(upfN3Address). + WithSDFFilter(SDFFilter). + WithPrecedence(100). + MarkAsUplink(). + BuildPDR(), + + // DownlinkPDR + session.NewPDRBuilder(). + WithID(downlinkPdrID). + WithMethod(session.Create). + WithPrecedence(100). + WithUEAddress(ueAddress.String()). + WithSDFFilter(SDFFilter). + AddQERID(sessQerID). + AddQERID(downlinkAppQerID). + WithFARID(downlinkFarID). + MarkAsDownlink(). + BuildPDR(), + } + fars := []*ieLib.IE{ // UplinkFAR session.NewFARBuilder(). @@ -214,44 +241,6 @@ func (P pfcpSimService) CreateSession(ctx context.Context, request *pb.CreateSes Build(), } - j := i - for _, sdf := range request.SdfFilter { - // Create as many Uplink and Downlink PDRs as provided SDF filters - uplinkPDRID := uint16(j) - downlinkPDRID := uint16(j + 1) - precedence := uint32(j) - - uplinkPDR := session.NewPDRBuilder(). - WithID(uplinkPDRID). - WithMethod(session.Create). - WithTEID(uplinkTEID). - WithFARID(uplinkFarID). - AddQERID(sessQerID). - AddQERID(uplinkAppQerID). - WithN3Address(upfN3Address). - WithSDFFilter(sdf). - WithPrecedence(precedence). - MarkAsUplink(). - BuildPDR() - - downlinkPDR := session.NewPDRBuilder(). - WithID(downlinkPDRID). - WithMethod(session.Create). - WithPrecedence(precedence). - WithUEAddress(ueAddress.String()). - WithSDFFilter(sdf). - AddQERID(sessQerID). - AddQERID(downlinkAppQerID). - WithFARID(downlinkFarID). - MarkAsDownlink(). - BuildPDR() - - pdrs = append(pdrs, uplinkPDR) - pdrs = append(pdrs, downlinkPDR) - - j = j + 2 - } - sess, err := sim.EstablishSession(pdrs, fars, qers) if err != nil { return &pb.Response{}, status.Error(codes.Internal, err.Error()) diff --git a/pkg/pfcpsim/errors.go b/pkg/pfcpsim/errors.go index a5af560..829067c 100644 --- a/pkg/pfcpsim/errors.go +++ b/pkg/pfcpsim/errors.go @@ -42,6 +42,13 @@ func NewNotEnoughSessionsError(err ...error) *pfcpSimError { } } +func NewInvalidFormatError(what string, err ...error) *pfcpSimError { + return &pfcpSimError{ + message: fmt.Sprintf("Invalid format: %v", what), + error: err, + } +} + func NewNoValidInterfaceError(err ...error) *pfcpSimError { return &pfcpSimError{ message: "No valid interface found", From 6c6d7629ea1ac96230e1955799a8550b363a36c8 Mon Sep 17 00:00:00 2001 From: Emanuele Gallone Date: Fri, 11 Mar 2022 19:35:36 +0100 Subject: [PATCH 15/18] Address review comments --- api/pfcpsim.pb.go | 16 ++------ api/pfcpsim.proto | 1 - internal/pfcpsim/helpers_test.go | 67 ++++++++++++++++++++++++++++++++ internal/pfcpsim/server.go | 4 -- 4 files changed, 70 insertions(+), 18 deletions(-) create mode 100644 internal/pfcpsim/helpers_test.go diff --git a/api/pfcpsim.pb.go b/api/pfcpsim.pb.go index b34d2af..cbaf33f 100644 --- a/api/pfcpsim.pb.go +++ b/api/pfcpsim.pb.go @@ -44,8 +44,7 @@ type CreateSessionRequest struct { NodeBAddress string `protobuf:"bytes,3,opt,name=nodeBAddress,proto3" json:"nodeBAddress,omitempty"` UeAddressPool string `protobuf:"bytes,4,opt,name=ueAddressPool,proto3" json:"ueAddressPool,omitempty"` AppFilter string `protobuf:"bytes,5,opt,name=appFilter,proto3" json:"appFilter,omitempty"` - Qfi int32 `protobuf:"varint,6,opt,name=qfi,proto3" json:"qfi,omitempty"` // Should be uint8 - GateClosed bool `protobuf:"varint,7,opt,name=gateClosed,proto3" json:"gateClosed,omitempty"` // If set, the application QERs will have the Gate status to closed. + Qfi int32 `protobuf:"varint,6,opt,name=qfi,proto3" json:"qfi,omitempty"` // Should be uint8 } func (x *CreateSessionRequest) Reset() { @@ -122,13 +121,6 @@ func (x *CreateSessionRequest) GetQfi() int32 { return 0 } -func (x *CreateSessionRequest) GetGateClosed() bool { - if x != nil { - return x.GateClosed - } - return false -} - type ModifySessionRequest struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -428,7 +420,7 @@ var File_pfcpsim_proto protoreflect.FileDescriptor var file_pfcpsim_proto_rawDesc = []byte{ 0x0a, 0x0d, 0x70, 0x66, 0x63, 0x70, 0x73, 0x69, 0x6d, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, - 0x03, 0x61, 0x70, 0x69, 0x22, 0xde, 0x01, 0x0a, 0x14, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x53, + 0x03, 0x61, 0x70, 0x69, 0x22, 0xbe, 0x01, 0x0a, 0x14, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x16, 0x0a, 0x06, 0x62, 0x61, 0x73, 0x65, 0x49, 0x44, 0x18, 0x02, 0x20, @@ -440,9 +432,7 @@ var file_pfcpsim_proto_rawDesc = []byte{ 0x73, 0x50, 0x6f, 0x6f, 0x6c, 0x12, 0x1c, 0x0a, 0x09, 0x61, 0x70, 0x70, 0x46, 0x69, 0x6c, 0x74, 0x65, 0x72, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x61, 0x70, 0x70, 0x46, 0x69, 0x6c, 0x74, 0x65, 0x72, 0x12, 0x10, 0x0a, 0x03, 0x71, 0x66, 0x69, 0x18, 0x06, 0x20, 0x01, 0x28, 0x05, - 0x52, 0x03, 0x71, 0x66, 0x69, 0x12, 0x1e, 0x0a, 0x0a, 0x67, 0x61, 0x74, 0x65, 0x43, 0x6c, 0x6f, - 0x73, 0x65, 0x64, 0x18, 0x07, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0a, 0x67, 0x61, 0x74, 0x65, 0x43, - 0x6c, 0x6f, 0x73, 0x65, 0x64, 0x22, 0xd2, 0x01, 0x0a, 0x14, 0x4d, 0x6f, 0x64, 0x69, 0x66, 0x79, + 0x52, 0x03, 0x71, 0x66, 0x69, 0x22, 0xd2, 0x01, 0x0a, 0x14, 0x4d, 0x6f, 0x64, 0x69, 0x66, 0x79, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x16, 0x0a, 0x06, 0x62, 0x61, 0x73, 0x65, 0x49, 0x44, 0x18, 0x02, diff --git a/api/pfcpsim.proto b/api/pfcpsim.proto index ec36ce5..4a623cd 100644 --- a/api/pfcpsim.proto +++ b/api/pfcpsim.proto @@ -15,7 +15,6 @@ message CreateSessionRequest { string ueAddressPool = 4; string appFilter = 5; int32 qfi = 6; // Should be uint8 - bool gateClosed = 7; // If set, the application QERs will have the Gate status to closed. } message ModifySessionRequest { diff --git a/internal/pfcpsim/helpers_test.go b/internal/pfcpsim/helpers_test.go new file mode 100644 index 0000000..670f527 --- /dev/null +++ b/internal/pfcpsim/helpers_test.go @@ -0,0 +1,67 @@ +package pfcpsim + +import ( + "testing" + + "github.com/stretchr/testify/require" + "github.com/wmnsk/go-pfcp/ie" +) + +func Test_parseAppFilter(t *testing.T) { + type args struct { + filterString string + } + + type want struct { + SDFFilter string + gateStatus uint8 + } + + tests := []struct { + name string + args *args + want *want + wantErr bool + }{ + {name: "Correct app filter", + args: &args{ + filterString: "udp:10.0.0.0/8:80-80:allow", + }, + want: &want{ + SDFFilter: "permit out udp from 10.0.0.0/8 to assigned 80-80", + gateStatus: ie.GateStatusOpen, + }, + }, + {name: "Correct app filter with deny", + args: &args{ + filterString: "udp:10.0.0.0/8:80-80:deny", + }, + want: &want{ + SDFFilter: "permit out udp from 10.0.0.0/8 to assigned 80-80", + gateStatus: ie.GateStatusClosed, + }, + }, + {name: "incorrect app filter", + args: &args{ + filterString: "test:10.0.0.0/8:80-80:allow", + }, + want: &want{}, + wantErr: true, + }, + } + + for _, tt := range tests { + t.Run( + tt.name, func(t *testing.T) { + filter, gateStatus, err := parseAppFilter(tt.args.filterString) + if tt.wantErr { + require.Error(t, err) + return + } + + require.Equal(t, tt.want.SDFFilter, filter) + require.Equal(t, tt.want.gateStatus, gateStatus) + }, + ) + } +} diff --git a/internal/pfcpsim/server.go b/internal/pfcpsim/server.go index c2912db..ded8067 100644 --- a/internal/pfcpsim/server.go +++ b/internal/pfcpsim/server.go @@ -136,10 +136,6 @@ func (P pfcpSimService) CreateSession(ctx context.Context, request *pb.CreateSes log.Infof("Successfully parsed application filter. SDF Filter: %v", SDFFilter) } - if request.GateClosed { - gateStatus = ieLib.GateStatusClosed - } - if request.Qfi != 0 { qfi = uint8(request.Qfi) } From a32b45034b608fea22628126e1e96f6d8bf54faf Mon Sep 17 00:00:00 2001 From: Emanuele Gallone Date: Fri, 11 Mar 2022 19:38:51 +0100 Subject: [PATCH 16/18] Address review comments --- internal/pfcpctl/commands/sessions.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/internal/pfcpctl/commands/sessions.go b/internal/pfcpctl/commands/sessions.go index e42e5f1..67f0b87 100644 --- a/internal/pfcpctl/commands/sessions.go +++ b/internal/pfcpctl/commands/sessions.go @@ -18,7 +18,6 @@ type commonArgs struct { 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: ':/:-:' . 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."` - GateClosed bool `short:"t" long:"gate-closed" description:"If set, the QER gate status will be CLOSED"` } type sessionCreate struct { @@ -67,7 +66,6 @@ func (s *sessionCreate) Execute(args []string) error { UeAddressPool: s.Args.UePool, AppFilter: s.Args.AppFilterString, Qfi: int32(s.Args.QFI), - GateClosed: s.Args.GateClosed, }) if err != nil { From 944d8eff1254bf5f52ab7cb682bc62e64dd8cf2d Mon Sep 17 00:00:00 2001 From: Emanuele Gallone Date: Fri, 11 Mar 2022 19:40:28 +0100 Subject: [PATCH 17/18] Add copyright header --- internal/pfcpsim/helpers_test.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/internal/pfcpsim/helpers_test.go b/internal/pfcpsim/helpers_test.go index 670f527..d41781f 100644 --- a/internal/pfcpsim/helpers_test.go +++ b/internal/pfcpsim/helpers_test.go @@ -1,3 +1,6 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2022-present Open Networking Foundation + package pfcpsim import ( From eda1d983044e6829bdb3916e6705cebc7e500da6 Mon Sep 17 00:00:00 2001 From: Emanuele Gallone Date: Fri, 11 Mar 2022 19:41:54 +0100 Subject: [PATCH 18/18] Address review comments --- internal/pfcpsim/helpers_test.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/internal/pfcpsim/helpers_test.go b/internal/pfcpsim/helpers_test.go index d41781f..166cf21 100644 --- a/internal/pfcpsim/helpers_test.go +++ b/internal/pfcpsim/helpers_test.go @@ -44,13 +44,20 @@ func Test_parseAppFilter(t *testing.T) { gateStatus: ie.GateStatusClosed, }, }, - {name: "incorrect app filter", + {name: "incorrect app filter bad protocol", args: &args{ filterString: "test:10.0.0.0/8:80-80:allow", }, want: &want{}, wantErr: true, }, + {name: "incorrect app filter bad IP format", + args: &args{ + filterString: "ip:10/8:80-80:allow", + }, + want: &want{}, + wantErr: true, + }, } for _, tt := range tests {