Skip to content

Commit

Permalink
rework v2
Browse files Browse the repository at this point in the history
  • Loading branch information
mogaika committed Feb 9, 2024
1 parent 644cf51 commit c15836f
Show file tree
Hide file tree
Showing 10 changed files with 241 additions and 360 deletions.
8 changes: 6 additions & 2 deletions upf/flowtable.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ typedef struct flow_side_tcp_t_

typedef struct flow_ipfix_t_
{
u32 next_export_at;
u32 next_export_at; // in seconds
u16 context_index;
u16 forwarding_policy_index;
// up_dst means "upload destination"
Expand Down Expand Up @@ -179,14 +179,18 @@ typedef struct flow_entry
u8 is_redirect : 1;
u8 is_l3_proxy : 1;
u8 is_spliced : 1;

u8 spliced_dirty : 1;
u8 dont_splice : 1;
u8 app_detection_done : 1;
u8 exported : 1;
u8 ipfix_exported : 1; // exported at least once

u8 tcp_state : 4; // TODO: needs only 3 bits?

// should be updated in classify and based on PDR during flow creation
u8 uplink_direction : 2;
// do not need to perform ipfix operations for this flow anymore
u8 ipfix_disabled : 1;

// use macro since unsigned will not expand to ~0
// direction impossible to detect or not yet detected
Expand Down
44 changes: 26 additions & 18 deletions upf/upf.h
Original file line number Diff line number Diff line change
Expand Up @@ -402,11 +402,20 @@ typedef struct
upf_pdi_t pdi;
u8 outer_header_removal;
u16 far_id;
u16 ipfix_cached_context_id;
u16 *urr_ids;
u32 *qer_ids;
} upf_pdr_t;

typedef enum
{
UPF_IPFIX_POLICY_NONE,
UPF_IPFIX_POLICY_DEFAULT,
UPF_IPFIX_POLICY_DEST,
UPF_IPFIX_N_POLICIES,
// used only in FAR to indicate "do not override"
UPF_IPFIX_POLICY_UNSPECIFIED = UPF_IPFIX_N_POLICIES
} __clib_packed upf_ipfix_policy_t;

/* Forward Action Rules - Forwarding Parameters */
typedef struct
{
Expand Down Expand Up @@ -462,15 +471,6 @@ typedef struct
fib_route_path_t *rpaths;
} upf_forwarding_policy_t;

typedef enum
{
UPF_IPFIX_POLICY_NONE,
UPF_IPFIX_POLICY_DEFAULT,
UPF_IPFIX_POLICY_DEST,
UPF_IPFIX_N_POLICIES,
UPF_IPFIX_POLICY_UNSPECIFIED = UPF_IPFIX_N_POLICIES
} __clib_packed upf_ipfix_policy_t;

/* Forward Action Rules */
typedef struct
{
Expand Down Expand Up @@ -805,6 +805,21 @@ typedef struct
u32 mask;
} upf_upip_res_t;

typedef struct
{
/* TODO: this contexts can be used in far instead of
own bihash lookup */
u32 contexts[FIB_PROTOCOL_IP_MAX][UPF_IPFIX_N_POLICIES];

upf_ipfix_policy_t default_policy;
ip_address_t collector_ip;
u32 report_interval;

u32 observation_domain_id;
u64 observation_point_id;
u8 *observation_domain_name;
} upf_nwi_ipfix_t;

typedef struct
{
u8 *name;
Expand All @@ -814,14 +829,7 @@ typedef struct
u32 sw_if_index;
u32 hw_if_index;

upf_ipfix_policy_t ipfix_policy;
ip_address_t ipfix_collector_ip;
u32 ipfix_report_interval;
u32 ipfix_cached_context_id;

u32 observation_domain_id;
u64 observation_point_id;
u8 *observation_domain_name;
upf_nwi_ipfix_t ipfix;
} upf_nwi_t;

typedef struct
Expand Down
15 changes: 8 additions & 7 deletions upf/upf_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ send_upf_nwi_details (vl_api_registration_t *reg, upf_nwi_t *nwi, u32 context)
upf_main_t *sm = &upf_main;
u32 name_len, ipfix_policy_len, observation_domain_name_len;
u8 *ipfix_policy =
format (0, "%U", format_upf_ipfix_policy, nwi->ipfix_policy);
format (0, "%U", format_upf_ipfix_policy, nwi->ipfix.default_policy);

name_len = vec_len (nwi->name);
mp = vl_msg_api_alloc (sizeof (*mp) + name_len * sizeof (u8));
Expand All @@ -595,21 +595,22 @@ send_upf_nwi_details (vl_api_registration_t *reg, upf_nwi_t *nwi, u32 context)
mp->ipfix_policy[ipfix_policy_len] = 0;

mp->ipfix_report_interval =
clib_host_to_net_u32 (nwi->ipfix_report_interval);
clib_host_to_net_u32 (nwi->ipfix.report_interval);
mp->observation_domain_id =
clib_host_to_net_u32 (nwi->observation_domain_id);
clib_host_to_net_u32 (nwi->ipfix.observation_domain_id);
observation_domain_name_len =
clib_min (sizeof (mp->observation_domain_name) - 1,
vec_len (nwi->observation_domain_name));
memcpy (mp->observation_domain_name, nwi->observation_domain_name,
vec_len (nwi->ipfix.observation_domain_name));
memcpy (mp->observation_domain_name, nwi->ipfix.observation_domain_name,
observation_domain_name_len);
mp->observation_domain_name[observation_domain_name_len] = 0;
mp->observation_point_id = clib_host_to_net_u64 (nwi->observation_point_id);
mp->observation_point_id =
clib_host_to_net_u64 (nwi->ipfix.observation_point_id);

memcpy (mp->nwi, nwi->name, name_len);
mp->nwi_len = name_len;

ip_address_encode (&ip_addr_46 (&nwi->ipfix_collector_ip), IP46_TYPE_ANY,
ip_address_encode (&ip_addr_46 (&nwi->ipfix.collector_ip), IP46_TYPE_ANY,
&mp->ipfix_collector_ip);

vl_api_send_msg (reg, (u8 *) mp);
Expand Down
4 changes: 2 additions & 2 deletions upf/upf_cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -551,8 +551,8 @@ upf_show_nwi_command_fn (vlib_main_t *vm, unformat_input_t *main_input,
"%U, ipfix-collector-ip %U\n",
format_pfcp_dns_labels, nwi->name, fib4->hash.table_id,
fib6->table_id, format_upf_ipfix_policy,
nwi->ipfix_policy, format_ip_address,
&nwi->ipfix_collector_ip);
nwi->ipfix.default_policy, format_ip_address,
&nwi->ipfix.collector_ip);
}

done:
Expand Down
Loading

0 comments on commit c15836f

Please sign in to comment.