+
+ /* Adjust the flow type */
+ if (outer_ip4_set == true)
+ outer_type = VNET_FLOW_TYPE_IP4_N_TUPLE;
+ else if (outer_ip6_set == true)
+ outer_type = VNET_FLOW_TYPE_IP6_N_TUPLE;
+ if (inner_ip4_set == true)
+ inner_type = VNET_FLOW_TYPE_IP4_N_TUPLE;
+ else if (inner_ip6_set == true)
+ inner_type = VNET_FLOW_TYPE_IP6_N_TUPLE;
+
+ if (outer_type == VNET_FLOW_TYPE_UNKNOWN)
+ return clib_error_return (0, "Please specify a supported flow type");
+
+ if (outer_type == VNET_FLOW_TYPE_IP4_N_TUPLE)
+ {
+ type = VNET_FLOW_TYPE_IP4_N_TUPLE;
+
+ if (inner_type == VNET_FLOW_TYPE_UNKNOWN)
+ {
+ if (is_gtpc_set)
+ type = VNET_FLOW_TYPE_IP4_GTPC;
+ else if (is_gtpu_set)
+ type = VNET_FLOW_TYPE_IP4_GTPU;
+ }
+ else if (inner_type == VNET_FLOW_TYPE_IP4_N_TUPLE)
+ {
+ if (is_gtpu_set)
+ type = VNET_FLOW_TYPE_IP4_GTPU_IP4;
+ }
+ else if (inner_type == VNET_FLOW_TYPE_IP6_N_TUPLE)
+ {
+ if (is_gtpu_set)
+ type = VNET_FLOW_TYPE_IP4_GTPU_IP6;
+ }
+ }
+ else if (outer_type == VNET_FLOW_TYPE_IP6_N_TUPLE)
+ {
+ type = VNET_FLOW_TYPE_IP6_N_TUPLE;
+
+ if (inner_type == VNET_FLOW_TYPE_UNKNOWN)
+ {
+ if (is_gtpc_set)
+ type = VNET_FLOW_TYPE_IP6_GTPC;
+ else if (is_gtpu_set)
+ type = VNET_FLOW_TYPE_IP6_GTPU;
+ }
+ else if (inner_type == VNET_FLOW_TYPE_IP4_N_TUPLE)
+ {
+ if (is_gtpu_set)
+ type = VNET_FLOW_TYPE_IP6_GTPU_IP4;
+ }
+ else if (inner_type == VNET_FLOW_TYPE_IP6_N_TUPLE)
+ {
+ if (is_gtpu_set)
+ type = VNET_FLOW_TYPE_IP6_GTPU_IP6;
+ }
+ }
+
+ //assign specific field values per flow type
+ switch (type)
+ {
+ case VNET_FLOW_TYPE_IP4_N_TUPLE:
+ case VNET_FLOW_TYPE_IP4_GTPC:
+ case VNET_FLOW_TYPE_IP4_GTPU:
+ case VNET_FLOW_TYPE_IP4_GTPU_IP4:
+ case VNET_FLOW_TYPE_IP4_GTPU_IP6:
+ clib_memcpy (&flow.ip4_n_tuple.src_addr, &ip4s,
+ sizeof (ip4_address_and_mask_t));
+ clib_memcpy (&flow.ip4_n_tuple.dst_addr, &ip4d,
+ sizeof (ip4_address_and_mask_t));
+ clib_memcpy (&flow.ip4_n_tuple.src_port, &sport,
+ sizeof (ip_port_and_mask_t));
+ clib_memcpy (&flow.ip4_n_tuple.dst_port, &dport,
+ sizeof (ip_port_and_mask_t));
+ flow.ip4_n_tuple.protocol = prot;
+
+ if (type == VNET_FLOW_TYPE_IP4_GTPC)
+ flow.ip4_gtpc.teid = teid;
+ else if (type == VNET_FLOW_TYPE_IP4_GTPU)
+ flow.ip4_gtpu.teid = teid;
+ else if (type == VNET_FLOW_TYPE_IP4_GTPU_IP4)
+ {
+ flow.ip4_gtpu_ip4.teid = teid;
+ clib_memcpy (&flow.ip4_gtpu_ip4.inner_src_addr, &inner_ip4s,
+ sizeof (ip4_address_and_mask_t));
+ clib_memcpy (&flow.ip4_gtpu_ip4.inner_dst_addr, &inner_ip4d,
+ sizeof (ip4_address_and_mask_t));
+ }
+ else if (type == VNET_FLOW_TYPE_IP4_GTPU_IP6)
+ {
+ flow.ip4_gtpu_ip6.teid = teid;
+ clib_memcpy (&flow.ip4_gtpu_ip6.inner_src_addr, &inner_ip6s,
+ sizeof (ip6_address_and_mask_t));
+ clib_memcpy (&flow.ip4_gtpu_ip6.inner_dst_addr, &inner_ip6d,
+ sizeof (ip6_address_and_mask_t));
+ }
+
+ if (flow.ip4_n_tuple.protocol == (ip_protocol_t) ~ 0)
+ return clib_error_return (0, "Please specify ip protocol");
+ if ((type != VNET_FLOW_TYPE_IP4_N_TUPLE) &&
+ (flow.ip4_n_tuple.protocol != IP_PROTOCOL_UDP))
+ return clib_error_return (0,
+ "For GTP related flow, ip protocol must be UDP");
+ break;
+
+ case VNET_FLOW_TYPE_IP6_N_TUPLE:
+ case VNET_FLOW_TYPE_IP6_GTPC:
+ case VNET_FLOW_TYPE_IP6_GTPU:
+ case VNET_FLOW_TYPE_IP6_GTPU_IP4:
+ case VNET_FLOW_TYPE_IP6_GTPU_IP6:
+ clib_memcpy (&flow.ip6_n_tuple.src_addr, &ip6s,
+ sizeof (ip6_address_and_mask_t));
+ clib_memcpy (&flow.ip6_n_tuple.dst_addr, &ip6d,
+ sizeof (ip6_address_and_mask_t));
+ clib_memcpy (&flow.ip6_n_tuple.src_port, &sport,
+ sizeof (ip_port_and_mask_t));
+ clib_memcpy (&flow.ip6_n_tuple.dst_port, &dport,
+ sizeof (ip_port_and_mask_t));
+ flow.ip6_n_tuple.protocol = prot;
+
+ if (type == VNET_FLOW_TYPE_IP6_GTPC)
+ flow.ip6_gtpc.teid = teid;
+ else if (type == VNET_FLOW_TYPE_IP6_GTPU)
+ flow.ip6_gtpu.teid = teid;
+ else if (type == VNET_FLOW_TYPE_IP6_GTPU_IP4)
+ {
+ flow.ip6_gtpu_ip4.teid = teid;
+ clib_memcpy (&flow.ip6_gtpu_ip4.inner_src_addr, &inner_ip4s,
+ sizeof (ip4_address_and_mask_t));
+ clib_memcpy (&flow.ip6_gtpu_ip4.inner_dst_addr, &inner_ip4d,
+ sizeof (ip4_address_and_mask_t));
+ }
+ else if (type == VNET_FLOW_TYPE_IP6_GTPU_IP6)
+ {
+ flow.ip6_gtpu_ip6.teid = teid;
+ clib_memcpy (&flow.ip6_gtpu_ip6.inner_src_addr, &inner_ip6s,
+ sizeof (ip6_address_and_mask_t));
+ clib_memcpy (&flow.ip6_gtpu_ip6.inner_dst_addr, &inner_ip6d,
+ sizeof (ip6_address_and_mask_t));
+ }
+
+ if (flow.ip6_n_tuple.protocol == (ip_protocol_t) ~ 0)
+ return clib_error_return (0, "Please specify ip protocol");
+ if ((type != VNET_FLOW_TYPE_IP4_N_TUPLE) &&
+ (flow.ip6_n_tuple.protocol != IP_PROTOCOL_UDP))
+ return clib_error_return (0,
+ "For GTP related flow, ip protocol must be UDP");
+ break;
+
+ default:
+ break;
+ }
+
+ flow.type = type;