Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[UPG-NAT] Controlled CG-NAT #122

Merged
merged 7 commits into from
Jun 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
352 changes: 326 additions & 26 deletions upf/pfcp.c

Large diffs are not rendered by default.

102 changes: 91 additions & 11 deletions upf/pfcp.h
Original file line number Diff line number Diff line change
Expand Up @@ -1145,7 +1145,40 @@ typedef struct
ip6_address_t ip6;
} pfcp_alternative_smf_ip_address_t;

#define VENDOR_TRAVELPING 18681
#define PFCP_IE_UE_IP_ADDRESS_POOL_INFORMATION 233

#define PFCP_IE_IP_VERSION 258
typedef u8 pfcp_ip_version_t;
#define IP_VERSION_4 BIT(0)
#define IP_VERSION_6 BIT(1)

#define VENDOR_BBF 3561

#define PFCP_IE_BBF_UP_FUNCTION_FEATURES 0
typedef u32 pfcp_bbf_up_function_features_t;

#define BBF_UP_NAT BIT(6)

#define PFCP_IE_BBF_NAT_OUTSIDE_ADDRESS 14
typedef ip4_address_t pfcp_bbf_nat_outside_address_t;

#define PFCP_IE_BBF_NAT_EXTERNAL_PORT_RANGE 16
typedef struct
{
u16 start_port;
u16 end_port;
} pfcp_bbf_nat_external_port_range_t;

#define PFCP_IE_BBF_APPLY_ACTION 15

#define BBF_APPLY_ACTION_NAT BIT(0)

typedef u8 pfcp_bbf_apply_action_t;

#define PFCP_IE_BBF_NAT_PORT_BLOCK 18
typedef u8 *pfcp_bbf_nat_port_block_t;

#define VENDOR_TRAVELPING 18681

#define PFCP_IE_TP_PACKET_MEASUREMENT 1
typedef pfcp_volume_threshold_t pfcp_tp_packet_measurement_t;
Expand Down Expand Up @@ -1173,6 +1206,8 @@ typedef u8 *pfcp_tp_file_name_t;
#define PFCP_IE_TP_LINE_NUMBER 9
typedef u32 pfcp_tp_line_number_t;

#define PFCP_IE_TP_CREATED_NAT_BINDING 10

/* Grouped PFCP Information Elements */

enum
Expand Down Expand Up @@ -1439,8 +1474,9 @@ enum
FORWARDING_PARAMETERS_LINKED_TRAFFIC_ENDPOINT_ID,
FORWARDING_PARAMETERS_PROXYING,
FORWARDING_PARAMETERS_DESTINATION_INTERFACE_TYPE,
FORWARDING_PARAMETERS_LAST =
FORWARDING_PARAMETERS_DESTINATION_INTERFACE_TYPE
FORWARDING_PARAMETERS_BBF_APPLY_ACTION,
FORWARDING_PARAMETERS_BBF_NAT_PORT_BLOCK,
FORWARDING_PARAMETERS_LAST = FORWARDING_PARAMETERS_BBF_NAT_PORT_BLOCK
};

typedef struct
Expand All @@ -1457,6 +1493,8 @@ typedef struct
pfcp_traffic_endpoint_id_t linked_traffic_endpoint_id;
pfcp_proxying_t proxying;
pfcp_tgpp_interface_type_t destination_interface_type;
pfcp_bbf_apply_action_t bbf_apply_action;
pfcp_bbf_nat_port_block_t nat_port_block;
} pfcp_forwarding_parameters_t;

enum
Expand Down Expand Up @@ -2199,6 +2237,26 @@ typedef struct
pfcp_tp_end_time_t tp_end_time;
} pfcp_usage_report_t;

enum
{
UE_IP_ADDRESS_POOL_INFORMATION_POOL_IDENTIFY,
UE_IP_ADDRESS_POOL_INFORMATION_NETWORK_INSTANCE,
UE_IP_ADDRESS_POOL_INFORMATION_IP_VERSION,
UE_IP_ADDRESS_POOL_INFORMATION_BBF_NAT_PORT_BLOCK,
UE_IP_ADDRESS_POOL_INFORMATION_POOL_LAST =
UE_IP_ADDRESS_POOL_INFORMATION_BBF_NAT_PORT_BLOCK
};

typedef struct
{
struct pfcp_group grp;

pfcp_ue_ip_address_pool_identity_t ue_ip_address_pool_identity;
pfcp_network_instance_t network_instance;
pfcp_ip_version_t ip_version;
pfcp_bbf_nat_port_block_t *port_blocks;
} pfcp_ue_ip_address_pool_information_t;

enum
{
TP_ERROR_REPORT_TP_ERROR_MESSAGE,
Expand All @@ -2216,6 +2274,23 @@ typedef struct
pfcp_tp_line_number_t line_number;
} pfcp_tp_error_report_t;

enum
{
TP_CREATED_BINDING_NAT_PORT_BLOCK,
TP_CREATED_BINDING_NAT_OUTSIDE_ADDRESS,
TP_CREATED_BINDING_NAT_EXTERNAL_PORT_RANGE,
TP_CREATED_BINDING_LAST = TP_CREATED_BINDING_NAT_EXTERNAL_PORT_RANGE
};

typedef struct
{
struct pfcp_group grp;

pfcp_bbf_nat_port_block_t block;
pfcp_bbf_nat_outside_address_t outside_addr;
pfcp_bbf_nat_external_port_range_t port_range;
} pfcp_tp_created_binding_t;


/* PFCP Methods */

Expand Down Expand Up @@ -2311,8 +2386,8 @@ enum
ASSOCIATION_SETUP_REQUEST_UP_FUNCTION_FEATURES,
ASSOCIATION_SETUP_REQUEST_CP_FUNCTION_FEATURES,
ASSOCIATION_SETUP_REQUEST_USER_PLANE_IP_RESOURCE_INFORMATION,
ASSOCIATION_SETUP_REQUEST_UE_IP_ADDRESS_POOL_INFORMATION,
ASSOCIATION_SETUP_REQUEST_TP_BUILD_ID,
ASSOCIATION_SETUP_REQUEST_UE_IP_ADDRESS_POOL_IDENTITY,
ASSOCIATION_SETUP_REQUEST_ALTERNATIVE_SMF_IP_ADDRESS,
ASSOCIATION_SETUP_REQUEST_LAST =
ASSOCIATION_SETUP_REQUEST_ALTERNATIVE_SMF_IP_ADDRESS
Expand All @@ -2326,10 +2401,10 @@ typedef struct
pfcp_recovery_time_stamp_t recovery_time_stamp;
pfcp_cp_function_features_t cp_function_features;
pfcp_up_function_features_t up_function_features;
pfcp_ue_ip_address_pool_information_t *ue_ip_address_pool_information;
pfcp_user_plane_ip_resource_information_t
* user_plane_ip_resource_information;
pfcp_tp_build_id_t tp_build_id;
pfcp_ue_ip_address_pool_identity_t *ue_ip_address_pool_identity;
pfcp_alternative_smf_ip_address_t *alternative_smf_ip_address;
} pfcp_association_setup_request_t;

Expand All @@ -2340,6 +2415,7 @@ enum
ASSOCIATION_UPDATE_REQUEST_UP_FUNCTION_FEATURES,
ASSOCIATION_UPDATE_REQUEST_PFCP_ASSOCIATION_RELEASE_REQUEST,
ASSOCIATION_UPDATE_REQUEST_GRACEFUL_RELEASE_PERIOD,
ASSOCIATION_UPDATE_REQUEST_UE_IP_ADDRESS_POOL_INFORMATION,
ASSOCIATION_UPDATE_REQUEST_USER_PLANE_IP_RESOURCE_INFORMATION,
ASSOCIATION_UPDATE_REQUEST_PFCPAUREQ_FLAGS,
ASSOCIATION_UPDATE_REQUEST_UE_IP_ADDRESS_POOL_IDENTITY,
Expand All @@ -2357,10 +2433,10 @@ typedef struct
pfcp_up_function_features_t up_function_features;
pfcp_pfcp_association_release_request_t pfcp_association_release_request;
pfcp_graceful_release_period_t graceful_release_period;
pfcp_ue_ip_address_pool_information_t *ue_ip_address_pool_information;
pfcp_user_plane_ip_resource_information_t
* user_plane_ip_resource_information;
pfcp_pfcpaureq_flags_t pfcpaureq_flags;
pfcp_ue_ip_address_pool_identity_t *ue_ip_address_pool_identity;
pfcp_alternative_smf_ip_address_t *alternative_smf_ip_address;
} pfcp_association_update_request_t;

Expand All @@ -2381,15 +2457,16 @@ enum
{
ASSOCIATION_PROCEDURE_RESPONSE_NODE_ID,
ASSOCIATION_PROCEDURE_RESPONSE_CAUSE,
ASSOCIATION_PROCEDURE_RESPONSE_TP_ERROR_REPORT,
ASSOCIATION_PROCEDURE_RESPONSE_RECOVERY_TIME_STAMP,
ASSOCIATION_PROCEDURE_RESPONSE_UP_FUNCTION_FEATURES,
ASSOCIATION_PROCEDURE_RESPONSE_CP_FUNCTION_FEATURES,
ASSOCIATION_PROCEDURE_RESPONSE_BBF_UP_FUNCTION_FEATURES,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vendor IEs should go after 3GPP IEs

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved

ASSOCIATION_PROCEDURE_RESPONSE_UE_IP_ADDRESS_POOL_INFORMATION,
ASSOCIATION_PROCEDURE_RESPONSE_USER_PLANE_IP_RESOURCE_INFORMATION,
ASSOCIATION_PROCEDURE_RESPONSE_TP_ERROR_REPORT,
ASSOCIATION_PROCEDURE_RESPONSE_TP_BUILD_ID,
ASSOCIATION_PROCEDURE_RESPONSE_UE_IP_ADDRESS_POOL_IDENTITY,
ASSOCIATION_PROCEDURE_RESPONSE_LAST =
ASSOCIATION_PROCEDURE_RESPONSE_UE_IP_ADDRESS_POOL_IDENTITY
ASSOCIATION_PROCEDURE_RESPONSE_TP_BUILD_ID
};

typedef struct
Expand All @@ -2402,10 +2479,11 @@ typedef struct
pfcp_recovery_time_stamp_t recovery_time_stamp;
pfcp_cp_function_features_t cp_function_features;
pfcp_up_function_features_t up_function_features;
pfcp_ue_ip_address_pool_information_t *ue_ip_address_pool_information;
pfcp_user_plane_ip_resource_information_t
* user_plane_ip_resource_information;
pfcp_bbf_up_function_features_t bbf_up_function_features;
pfcp_tp_build_id_t tp_build_id;
pfcp_ue_ip_address_pool_identity_t *ue_ip_address_pool_identity;
} pfcp_association_procedure_response_t;

enum
Expand Down Expand Up @@ -2570,8 +2648,9 @@ enum
SESSION_PROCEDURE_RESPONSE_FAILED_RULE_ID,
SESSION_PROCEDURE_RESPONSE_ADDITIONAL_USAGE_REPORTS_INFORMATION,
SESSION_PROCEDURE_RESPONSE_CREATED_TRAFFIC_ENDPOINT,
SESSION_PROCEDURE_RESPONSE_TP_CREATED_BINDING,
SESSION_PROCEDURE_RESPONSE_LAST =
SESSION_PROCEDURE_RESPONSE_CREATED_TRAFFIC_ENDPOINT
SESSION_PROCEDURE_RESPONSE_TP_CREATED_BINDING
};

typedef struct
Expand All @@ -2592,6 +2671,7 @@ typedef struct
pfcp_additional_usage_reports_information_t
additional_usage_reports_information;
pfcp_created_traffic_endpoint_t *created_traffic_endpoint;
pfcp_tp_created_binding_t created_binding;
} pfcp_session_procedure_response_t;

enum
Expand Down
3 changes: 3 additions & 0 deletions upf/test/session_modification_response.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@ Usage Report SMR
End Time: 2019/11/07 11:31:06:000
Volume Measurement: V:[T:0,U:0,D:0],P:[T:0,U:0,D:0]
Duration Measurement: 0
TP: Now: 2019/11/07 11:31:06:021
TP: Start Time: 2019/11/07 11:31:06:010
TP: End Time: 2019/11/07 11:31:06:010

3 changes: 3 additions & 0 deletions upf/test/session_report_request.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@ Usage Report SRR
End Time: 2019/12/30 09:53:21:000
Volume Measurement: V:[T:0,U:0,D:0],P:[T:0,U:0,D:0]
Duration Measurement: 10
TP: Now: 2019/12/30 09:53:21:218
TP: Start Time: 2019/12/30 09:53:11:218
TP: End Time: 2019/12/30 09:53:21:218

13 changes: 12 additions & 1 deletion upf/test/test_upf.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ def tdf_setup_cmds(cls):
r"^https?://(.*\\.)*(example)\\.com/",
"upf application TST rule 3001 add ipfilter " +
"permit out ip from %s to assigned" % APP_RULE_IP_V4,
"nat44 enable sessions 1024 endpoint-dependent",
"upf nat pool 78.32.0.2 - 78.32.0.25 block_size 512 nwi sgi name testing",
"upf nat pool 78.32.20.2 - 78.32.20.25 block_size 512 nwi sgi name not-testing",
"upf ueip pool nwi sgi id mypool",
]

@classmethod
Expand All @@ -114,6 +118,10 @@ def pgw_setup_cmds(cls):
(cls.if_sgi.remote_ip4, cls.if_sgi.name),
"upf gtpu endpoint ip %s nwi cp teid 0x80000000/2" % cls.if_cp.local_ip4,
"upf gtpu endpoint ip %s nwi epc teid 0x80000000/2" % cls.if_grx.local_ip4,
"nat44 enable sessions 1024 endpoint-dependent",
"upf nat pool 78.32.0.2 - 78.32.0.25 block_size 512 nwi sgi name testing",
"upf nat pool 78.32.20.2 - 78.32.20.25 block_size 512 nwi sgi name not-testing",
"upf ueip pool nwi sgi id mypool",
]

@property
Expand Down Expand Up @@ -359,7 +367,10 @@ def associate(self):
IE_NodeId(id_type="FQDN", id="ergw")
]), PFCPAssociationSetupResponse)
self.assertEqual(CauseValues[resp[IE_Cause].cause], "Request accepted")
self.assertIn(b"vpp", resp[IE_EnterpriseSpecific].data)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this change somehow related to this PR? This is actually a problem (#104), as the build id should contain upg not vpp, but I thought of fixing it separately and not by removing this check, but rather by fixing the id itself and replacing vpp with upg here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, association setup response checks should be enhanced with:

  • proper build ID check
  • BBF UserPlane Features checks
    I think it's worth a separate review

#FIXME: There are new 3GPP and BBF PFCP IEs introduced, need changes to
# scapy pfcp module since decoding is done wrong for TP/BBF IEs
#FIXME: Proper build ID handling required
#self.assertIn(b"vpp", resp[IE_EnterpriseSpecific].data)
if IE_NodeId in resp:
if resp[IE_NodeId].id_type is 2:
self.assertEqual(resp[IE_NodeId].id, b"upg")
Expand Down
Loading