From 34d259a373a7afc61fb00e51d7d0a343aa06d7d0 Mon Sep 17 00:00:00 2001 From: Emanuele Gallone Date: Fri, 11 Mar 2022 10:39:36 +0100 Subject: [PATCH] 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 | 47 +++++++ internal/pfcpsim/server.go | 97 +++++++-------- pkg/pfcpsim/errors.go | 7 ++ 7 files changed, 181 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..6260d76 100644 --- a/internal/pfcpsim/helpers.go +++ b/internal/pfcpsim/helpers.go @@ -4,11 +4,16 @@ package pfcpsim import ( + "fmt" "net" + "strings" "github.com/omec-project/pfcpsim/pkg/pfcpsim" + "github.com/wmnsk/go-pfcp/ie" ) +const sdfFilterFormat = "permit out %s from %s to assigned %s-%s" + func connectPFCPSim() error { if sim == nil { localAddr, err := getLocalAddress(interfaceName) @@ -71,3 +76,45 @@ 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 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, upperPort := portList[0], portList[1] + + 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",