summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKlement Sekera <ksekera@cisco.com>2018-02-22 11:41:12 +0100
committerDamjan Marion <dmarion.lists@gmail.com>2018-03-21 00:01:44 +0000
commit4c53313cd7e9b866412ad3e04b2d91ac098c1398 (patch)
tree185aa1f368ea2eb997c2ed46433b31178efc71c9
parent2303cb181b51f63c909cd506125c1f832432865a (diff)
reassembly: feature/concurrency
This change makes ip reassembly an interface feature, while adding concurrency support. Due to this, punt is no longer needed to test reassembly. Change-Id: I467669514ec33283ce935be0f1dd08f07684f0c7 Signed-off-by: Klement Sekera <ksekera@cisco.com>
-rw-r--r--src/vnet/buffer.h25
-rw-r--r--src/vnet/ip/ip.api16
-rw-r--r--src/vnet/ip/ip46_cli.c83
-rw-r--r--src/vnet/ip/ip4_forward.c17
-rw-r--r--src/vnet/ip/ip4_reassembly.c428
-rw-r--r--src/vnet/ip/ip4_reassembly.h3
-rw-r--r--src/vnet/ip/ip6_forward.c1
-rw-r--r--src/vnet/ip/ip6_reassembly.c549
-rw-r--r--src/vnet/ip/ip6_reassembly.h3
-rw-r--r--src/vnet/ip/ip_api.c20
-rw-r--r--src/vnet/ip/lookup.c2
-rw-r--r--src/vnet/ip/lookup.h1
-rw-r--r--test/framework.py4
-rwxr-xr-xtest/sys_req/set_system_parameters.sh68
-rw-r--r--test/sys_req/system_parameters18
-rw-r--r--test/test_reassembly.py (renamed from test/test_reassembly.py.disabled)374
-rw-r--r--test/vpp_papi_provider.py9
-rw-r--r--test/vpp_punt_socket.py75
18 files changed, 998 insertions, 698 deletions
diff --git a/src/vnet/buffer.h b/src/vnet/buffer.h
index e785145c0b5..02688e26530 100644
--- a/src/vnet/buffer.h
+++ b/src/vnet/buffer.h
@@ -161,15 +161,24 @@ typedef struct
} icmp;
/* reassembly */
- struct
+ union
{
- u16 fragment_first;
- u16 fragment_last;
- u16 range_first;
- u16 range_last;
- u32 next_range_bi;
- u16 ip6_frag_hdr_offset;
- u16 estimated_mtu;
+ /* in/out variables */
+ struct
+ {
+ u32 next_index; /* index of next node - ignored if "feature" node */
+ u16 estimated_mtu; /* estimated MTU calculated during reassembly */
+ };
+ /* internal variables used during reassembly */
+ struct
+ {
+ u16 fragment_first;
+ u16 fragment_last;
+ u16 range_first;
+ u16 range_last;
+ u32 next_range_bi;
+ u16 ip6_frag_hdr_offset;
+ };
} reass;
};
diff --git a/src/vnet/ip/ip.api b/src/vnet/ip/ip.api
index d6c5f6bcd02..2ca2f56c58b 100644
--- a/src/vnet/ip/ip.api
+++ b/src/vnet/ip/ip.api
@@ -910,6 +910,22 @@ define ip_reassembly_get_reply
u8 is_ip6;
};
+/** \brief Enable/disable reassembly feature
+ @param client_index - opaque cookie to identify the sender
+ @param context - sender context, to match reply w/ request
+ @param sw_if_index - interface to enable/disable feature on
+ @param enable_ip4 - enable ip4 reassembly if non-zero, disable if 0
+ @param enable_ip6 - enable ip6 reassembly if non-zero, disable if 0
+*/
+autoreply define ip_reassembly_enable_disable
+{
+ u32 client_index;
+ u32 context;
+ u32 sw_if_index;
+ u8 enable_ip4;
+ u8 enable_ip6;
+};
+
/*
* Local Variables:
* eval: (c-set-style "gnu")
diff --git a/src/vnet/ip/ip46_cli.c b/src/vnet/ip/ip46_cli.c
index 668c650682f..2508f0e8ee6 100644
--- a/src/vnet/ip/ip46_cli.c
+++ b/src/vnet/ip/ip46_cli.c
@@ -38,6 +38,8 @@
*/
#include <vnet/ip/ip.h>
+#include <vnet/ip/ip4_reassembly.h>
+#include <vnet/ip/ip6_reassembly.h>
/**
* @file
@@ -218,6 +220,87 @@ VLIB_CLI_COMMAND (set_interface_ip_address_command, static) = {
};
/* *INDENT-ON* */
+static clib_error_t *
+set_reassembly_command_fn (vlib_main_t * vm,
+ unformat_input_t * input, vlib_cli_command_t * cmd)
+{
+ vnet_main_t *vnm = vnet_get_main ();
+ unformat_input_t _line_input, *line_input = &_line_input;
+ u32 sw_if_index = ~0;
+ u8 ip4_on = 0;
+ u8 ip6_on = 0;
+
+ /* Get a line of input. */
+ if (!unformat_user (input, unformat_line_input, line_input))
+ {
+ return NULL;
+ }
+
+ if (!unformat (input, "%U", unformat_vnet_sw_interface, vnm, &sw_if_index))
+ {
+ return clib_error_return (0, "Invalid interface name");
+ }
+
+ if (unformat (input, "on"))
+ {
+ ip4_on = 1;
+ ip6_on = 1;
+ }
+ else if (unformat (input, "off"))
+ {
+ ip4_on = 0;
+ ip6_on = 0;
+ }
+ else if (unformat (input, "ip4"))
+ {
+ ip4_on = 1;
+ ip6_on = 0;
+ }
+ else if (unformat (input, "ip6"))
+ {
+ ip4_on = 0;
+ ip6_on = 1;
+ }
+ else
+ {
+ return clib_error_return (0, "Unknown input `%U'",
+ format_unformat_error, line_input);
+ }
+
+
+ vnet_api_error_t rv4 = ip4_reass_enable_disable (sw_if_index, ip4_on);
+ vnet_api_error_t rv6 = ip6_reass_enable_disable (sw_if_index, ip6_on);
+ if (rv4 && rv6)
+ {
+ return clib_error_return (0,
+ "`ip4_reass_enable_disable' API call failed, rv=%d:%U, "
+ "`ip6_reass_enable_disable' API call failed, rv=%d:%U",
+ (int) rv4, format_vnet_api_errno, rv4,
+ (int) rv6, format_vnet_api_errno, rv6);
+ }
+ else if (rv4)
+ {
+ return clib_error_return (0,
+ "`ip4_reass_enable_disable' API call failed, rv=%d:%U",
+ (int) rv4, format_vnet_api_errno, rv4);
+ }
+ else if (rv6)
+ {
+ return clib_error_return (0,
+ "`ip6_reass_enable_disable' API call failed, rv=%d:%U",
+ (int) rv6, format_vnet_api_errno, rv6);
+ }
+ return NULL;
+}
+
+/* *INDENT-OFF* */
+VLIB_CLI_COMMAND (set_reassembly_command, static) = {
+ .path = "set interface reassembly",
+ .short_help = "set interface reassembly <interface-name> [on|off|ip4|ip6]",
+ .function = set_reassembly_command_fn,
+};
+/* *INDENT-ON* */
+
/* Dummy init function to get us linked in. */
static clib_error_t *
ip4_cli_init (vlib_main_t * vm)
diff --git a/src/vnet/ip/ip4_forward.c b/src/vnet/ip/ip4_forward.c
index 19babced33f..7c56a294436 100644
--- a/src/vnet/ip/ip4_forward.c
+++ b/src/vnet/ip/ip4_forward.c
@@ -1217,14 +1217,8 @@ ip4_local_inline (vlib_main_t * vm,
sw_if_index0 = vnet_buffer (p0)->sw_if_index[VLIB_RX];
sw_if_index1 = vnet_buffer (p1)->sw_if_index[VLIB_RX];
- /* Treat IP frag packets as "experimental" protocol for now
- until support of IP frag reassembly is implemented */
- proto0 =
- ip4_is_fragment (ip0) ? IP_PROTOCOL_VPP_FRAGMENTATION :
- ip0->protocol;
- proto1 =
- ip4_is_fragment (ip1) ? IP_PROTOCOL_VPP_FRAGMENTATION :
- ip1->protocol;
+ proto0 = ip0->protocol;
+ proto1 = ip1->protocol;
if (head_of_feature_arc == 0)
goto skip_checks;
@@ -1387,11 +1381,7 @@ ip4_local_inline (vlib_main_t * vm,
vnet_buffer (p0)->l3_hdr_offset = p0->current_data;
sw_if_index0 = vnet_buffer (p0)->sw_if_index[VLIB_RX];
- /* Treat IP frag packets as "experimental" protocol for now
- until support of IP frag reassembly is implemented */
- proto0 =
- ip4_is_fragment (ip0) ? IP_PROTOCOL_VPP_FRAGMENTATION :
- ip0->protocol;
+ proto0 = ip0->protocol;
if (head_of_feature_arc == 0 || p0->flags & VNET_BUFFER_F_IS_NATED)
goto skip_check;
@@ -1482,7 +1472,6 @@ VLIB_REGISTER_NODE (ip4_local_node) =
[IP_LOCAL_NEXT_PUNT] = "ip4-punt",
[IP_LOCAL_NEXT_UDP_LOOKUP] = "ip4-udp-lookup",
[IP_LOCAL_NEXT_ICMP] = "ip4-icmp-input",
- [IP_LOCAL_NEXT_REASSEMBLY] = "ip4-reassembly",
},
};
/* *INDENT-ON* */
diff --git a/src/vnet/ip/ip4_reassembly.c b/src/vnet/ip/ip4_reassembly.c
index ac3db16a3ad..114d8e052f8 100644
--- a/src/vnet/ip/ip4_reassembly.c
+++ b/src/vnet/ip/ip4_reassembly.c
@@ -29,7 +29,7 @@
#define MSEC_PER_SEC 1000
#define IP4_REASS_TIMEOUT_DEFAULT_MS 100
#define IP4_REASS_EXPIRE_WALK_INTERVAL_DEFAULT_MS 10000 // 10 seconds default
-#define IP4_REASS_MAX_REASSEMBLIES_DEAFULT 1024
+#define IP4_REASS_MAX_REASSEMBLIES_DEFAULT 1024
#define IP4_REASS_HT_LOAD_FACTOR (0.75)
#define IP4_REASS_DEBUG_BUFFERS 0
@@ -111,11 +111,10 @@ typedef struct
{
// hash table key
ip4_reass_key_t key;
- f64 first_heard;
// time when last packet was received
f64 last_heard;
// internal id of this reassembly
- u32 id;
+ u64 id;
// buffer index of first buffer in this reassembly context
u32 first_bi;
// last octet of packet, ~0 until fragment without more_fragments arrives
@@ -124,10 +123,23 @@ typedef struct
u32 data_len;
// trace operation counter
u32 trace_op_counter;
+ // next index - used by non-feature node
+ u8 next_index;
+ // minimum fragment length for this reassembly - used to estimate MTU
+ u16 min_fragment_length;
} ip4_reass_t;
typedef struct
{
+ ip4_reass_t *pool;
+ u32 reass_n;
+ u32 buffers_n;
+ u32 id_counter;
+ clib_spinlock_t lock;
+} ip4_reass_per_thread_t;
+
+typedef struct
+{
// IPv4 config
u32 timeout_ms;
f64 timeout;
@@ -135,11 +147,9 @@ typedef struct
u32 max_reass_n;
// IPv4 runtime
- ip4_reass_t *pool;
clib_bihash_24_8_t hash;
- u32 reass_n;
- u32 id_counter;
- u32 buffers_n;
+ // per-thread data
+ ip4_reass_per_thread_t *per_thread_data;
// convenience
vlib_main_t *vlib_main;
@@ -148,7 +158,6 @@ typedef struct
// node index of ip4-drop node
u32 ip4_drop_idx;
u32 ip4_reass_expire_node_idx;
-
} ip4_reass_main_t;
ip4_reass_main_t ip4_reass_main;
@@ -182,7 +191,6 @@ typedef struct
typedef struct
{
ip4_reass_trace_operation_e action;
- u32 pool_index;
u32 reass_id;
ip4_reass_range_trace_t trace_range;
u32 size_diff;
@@ -192,7 +200,7 @@ typedef struct
u32 total_data_len;
} ip4_reass_trace_t;
-void
+static void
ip4_reass_trace_details (vlib_main_t * vm, u32 bi,
ip4_reass_range_trace_t * trace)
{
@@ -205,7 +213,7 @@ ip4_reass_trace_details (vlib_main_t * vm, u32 bi,
trace->range_bi = bi;
}
-u8 *
+static u8 *
format_ip4_reass_range_trace (u8 * s, va_list * args)
{
ip4_reass_range_trace_t *trace = va_arg (*args, ip4_reass_range_trace_t *);
@@ -252,15 +260,20 @@ format_ip4_reass_trace (u8 * s, va_list * args)
return s;
}
-void
+static void
ip4_reass_add_trace (vlib_main_t * vm, vlib_node_runtime_t * node,
ip4_reass_main_t * rm, ip4_reass_t * reass, u32 bi,
ip4_reass_trace_operation_e action, u32 size_diff)
{
vlib_buffer_t *b = vlib_get_buffer (vm, bi);
vnet_buffer_opaque_t *vnb = vnet_buffer (b);
+ if (pool_is_free_index (vm->trace_main.trace_buffer_pool, b->trace_index))
+ {
+ // this buffer's trace is gone
+ b->flags &= ~VLIB_BUFFER_IS_TRACED;
+ return;
+ }
ip4_reass_trace_t *t = vlib_add_trace (vm, node, b, sizeof (t[0]));
- t->pool_index = reass - rm->pool;
t->reass_id = reass->id;
t->action = action;
ip4_reass_trace_details (vm, bi, &t->trace_range);
@@ -280,19 +293,20 @@ ip4_reass_add_trace (vlib_main_t * vm, vlib_node_runtime_t * node,
#endif
}
-void
-ip4_reass_free (ip4_reass_main_t * rm, ip4_reass_t * reass)
+always_inline void
+ip4_reass_free (ip4_reass_main_t * rm, ip4_reass_per_thread_t * rt,
+ ip4_reass_t * reass)
{
clib_bihash_kv_24_8_t kv;
kv.key[0] = reass->key.as_u64[0];
kv.key[1] = reass->key.as_u64[1];
kv.key[2] = reass->key.as_u64[2];
clib_bihash_add_del_24_8 (&rm->hash, &kv, 0);
- pool_put (rm->pool, reass);
- --rm->reass_n;
+ pool_put (rt->pool, reass);
+ --rt->reass_n;
}
-static void
+always_inline void
ip4_reass_on_timeout (vlib_main_t * vm, ip4_reass_main_t * rm,
ip4_reass_t * reass, u32 ** vec_drop_timeout)
{
@@ -324,6 +338,7 @@ ip4_reass_on_timeout (vlib_main_t * vm, ip4_reass_main_t * rm,
ip4_reass_t *
ip4_reass_find_or_create (vlib_main_t * vm, ip4_reass_main_t * rm,
+ ip4_reass_per_thread_t * rt,
ip4_reass_key_t * k, u32 ** vec_drop_timeout)
{
ip4_reass_t *reass = NULL;
@@ -335,11 +350,11 @@ ip4_reass_find_or_create (vlib_main_t * vm, ip4_reass_main_t * rm,
if (!clib_bihash_search_24_8 (&rm->hash, &kv, &value))
{
- reass = pool_elt_at_index (rm->pool, value.value);
+ reass = pool_elt_at_index (rt->pool, value.value);
if (now > reass->last_heard + rm->timeout)
{
ip4_reass_on_timeout (vm, rm, reass, vec_drop_timeout);
- ip4_reass_free (rm, reass);
+ ip4_reass_free (rm, rt, reass);
reass = NULL;
}
}
@@ -350,43 +365,45 @@ ip4_reass_find_or_create (vlib_main_t * vm, ip4_reass_main_t * rm,
return reass;
}
- if (rm->reass_n >= rm->max_reass_n)
+ if (rt->reass_n >= rm->max_reass_n)
{
reass = NULL;
return reass;
}
else
{
- pool_get (rm->pool, reass);
+ pool_get (rt->pool, reass);
memset (reass, 0, sizeof (*reass));
- reass->id = rm->id_counter;
- ++rm->id_counter;
+ reass->id =
+ ((u64) os_get_thread_index () * 1000000000) + rt->id_counter;
+ ++rt->id_counter;
reass->first_bi = ~0;
reass->last_packet_octet = ~0;
reass->data_len = 0;
- ++rm->reass_n;
+ ++rt->reass_n;
}
reass->key.as_u64[0] = kv.key[0] = k->as_u64[0];
reass->key.as_u64[1] = kv.key[1] = k->as_u64[1];
reass->key.as_u64[2] = kv.key[2] = k->as_u64[2];
- kv.value = reass - rm->pool;
+ kv.value = reass - rt->pool;
reass->last_heard = now;
if (clib_bihash_add_del_24_8 (&rm->hash, &kv, 1))
{
- ip4_reass_free (rm, reass);
+ ip4_reass_free (rm, rt, reass);
reass = NULL;
}
return reass;
}
-void
+always_inline void
ip4_reass_finalize (vlib_main_t * vm, vlib_node_runtime_t * node,
- ip4_reass_main_t * rm, ip4_reass_t * reass, u32 * bi0,
- u32 * next0, vlib_error_t * error0, u32 next_input,
- u32 ** vec_drop_compress, u32 ** vec_drop_overlap)
+ ip4_reass_main_t * rm, ip4_reass_per_thread_t * rt,
+ ip4_reass_t * reass, u32 * bi0, u32 * next0,
+ vlib_error_t * error0, u32 ** vec_drop_compress,
+ u32 ** vec_drop_overlap, bool is_feature)
{
ASSERT (~0 != reass->first_bi);
vlib_buffer_t *first_b = vlib_get_buffer (vm, reass->first_bi);
@@ -481,8 +498,8 @@ ip4_reass_finalize (vlib_main_t * vm, vlib_node_runtime_t * node,
}
while (~0 != sub_chain_bi);
last_b->flags &= ~VLIB_BUFFER_NEXT_PRESENT;
- ASSERT (rm->buffers_n >= (buf_cnt - dropped_cnt));
- rm->buffers_n -= buf_cnt - dropped_cnt;
+ ASSERT (rt->buffers_n >= (buf_cnt - dropped_cnt));
+ rt->buffers_n -= buf_cnt - dropped_cnt;
ASSERT (total_length >= first_b->current_length);
total_length -= first_b->current_length;
first_b->flags |= VLIB_BUFFER_TOTAL_LENGTH_VALID;
@@ -523,13 +540,21 @@ ip4_reass_finalize (vlib_main_t * vm, vlib_node_runtime_t * node,
#endif
}
*bi0 = reass->first_bi;
- *next0 = next_input;
+ if (is_feature)
+ {
+ *next0 = IP4_REASSEMBLY_NEXT_INPUT;
+ }
+ else
+ {
+ *next0 = reass->next_index;
+ }
+ vnet_buffer (first_b)->ip.reass.estimated_mtu = reass->min_fragment_length;
*error0 = IP4_ERROR_NONE;
- ip4_reass_free (rm, reass);
+ ip4_reass_free (rm, rt, reass);
reass = NULL;
}
-static u32
+always_inline u32
ip4_reass_get_buffer_chain_length (vlib_main_t * vm, vlib_buffer_t * b)
{
u32 len = 0;
@@ -548,9 +573,10 @@ ip4_reass_get_buffer_chain_length (vlib_main_t * vm, vlib_buffer_t * b)
return len;
}
-static void
+always_inline void
ip4_reass_insert_range_in_chain (vlib_main_t * vm,
ip4_reass_main_t * rm,
+ ip4_reass_per_thread_t * rt,
ip4_reass_t * reass,
u32 prev_range_bi, u32 new_next_bi)
{
@@ -573,10 +599,10 @@ ip4_reass_insert_range_in_chain (vlib_main_t * vm,
reass->first_bi = new_next_bi;
}
reass->data_len += ip4_reass_buffer_get_data_len (new_next_b);
- rm->buffers_n += ip4_reass_get_buffer_chain_length (vm, new_next_b);
+ rt->buffers_n += ip4_reass_get_buffer_chain_length (vm, new_next_b);
}
-static void
+always_inline void
ip4_reass_remove_range_from_chain (vlib_main_t * vm,
vlib_node_runtime_t * node,
ip4_reass_main_t * rm,
@@ -619,12 +645,12 @@ ip4_reass_remove_range_from_chain (vlib_main_t * vm,
}
}
-void
+always_inline void
ip4_reass_update (vlib_main_t * vm, vlib_node_runtime_t * node,
- ip4_reass_main_t * rm, ip4_reass_t * reass, u32 * bi0,
- u32 * next0, vlib_error_t * error0,
- u32 ** vec_drop_overlap, u32 ** vec_drop_compress,
- u32 next_input, u32 next_drop)
+ ip4_reass_main_t * rm, ip4_reass_per_thread_t * rt,
+ ip4_reass_t * reass, u32 * bi0, u32 * next0,
+ vlib_error_t * error0, u32 ** vec_drop_overlap,
+ u32 ** vec_drop_compress, bool is_feature)
{
int consumed = 0;
vlib_buffer_t *fb = vlib_get_buffer (vm, *bi0);
@@ -640,6 +666,7 @@ ip4_reass_update (vlib_main_t * vm, vlib_node_runtime_t * node,
int more_fragments = ip4_get_fragment_more (fip);
u32 candidate_range_bi = reass->first_bi;
u32 prev_range_bi = ~0;
+ reass->next_index = fvnb->ip.reass.next_index; // store next_index before it's overwritten
fvnb->ip.reass.range_first = fragment_first;
fvnb->ip.reass.range_last = fragment_last;
fvnb->ip.reass.next_range_bi = ~0;
@@ -650,17 +677,18 @@ ip4_reass_update (vlib_main_t * vm, vlib_node_runtime_t * node,
if (~0 == reass->first_bi)
{
// starting a new reassembly
- ip4_reass_insert_range_in_chain (vm, rm, reass, prev_range_bi, *bi0);
+ ip4_reass_insert_range_in_chain (vm, rm, rt, reass, prev_range_bi,
+ *bi0);
if (PREDICT_FALSE (fb->flags & VLIB_BUFFER_IS_TRACED))
{
ip4_reass_add_trace (vm, node, rm, reass, *bi0, RANGE_NEW, 0);
}
*bi0 = ~0;
- fvnb->ip.reass.estimated_mtu = clib_net_to_host_u16 (fip->length);
+ reass->min_fragment_length = clib_net_to_host_u16 (fip->length);
return;
}
- fvnb->ip.reass.estimated_mtu = clib_min (clib_net_to_host_u16 (fip->length),
- fvnb->ip.reass.estimated_mtu);
+ reass->min_fragment_length = clib_min (clib_net_to_host_u16 (fip->length),
+ fvnb->ip.reass.estimated_mtu);
while (~0 != candidate_range_bi)
{
vlib_buffer_t *candidate_b = vlib_get_buffer (vm, candidate_range_bi);
@@ -674,8 +702,8 @@ ip4_reass_update (vlib_main_t * vm, vlib_node_runtime_t * node,
~0 == candidate_range_bi)
{
// special case - this fragment falls beyond all known ranges
- ip4_reass_insert_range_in_chain (vm, rm, reass, prev_range_bi,
- *bi0);
+ ip4_reass_insert_range_in_chain (vm, rm, rt, reass,
+ prev_range_bi, *bi0);
consumed = 1;
break;
}
@@ -684,7 +712,7 @@ ip4_reass_update (vlib_main_t * vm, vlib_node_runtime_t * node,
if (fragment_last < candidate_vnb->ip.reass.range_first)
{
// this fragment ends before candidate range without any overlap
- ip4_reass_insert_range_in_chain (vm, rm, reass, prev_range_bi,
+ ip4_reass_insert_range_in_chain (vm, rm, rt, reass, prev_range_bi,
*bi0);
consumed = 1;
}
@@ -717,7 +745,7 @@ ip4_reass_update (vlib_main_t * vm, vlib_node_runtime_t * node,
candidate_range_bi, RANGE_SHRINK,
overlap);
}
- ip4_reass_insert_range_in_chain (vm, rm, reass,
+ ip4_reass_insert_range_in_chain (vm, rm, rt, reass,
prev_range_bi, *bi0);
consumed = 1;
}
@@ -743,7 +771,7 @@ ip4_reass_update (vlib_main_t * vm, vlib_node_runtime_t * node,
else
{
// special case - last range discarded
- ip4_reass_insert_range_in_chain (vm, rm, reass,
+ ip4_reass_insert_range_in_chain (vm, rm, rt, reass,
candidate_range_bi,
*bi0);
consumed = 1;
@@ -774,7 +802,7 @@ ip4_reass_update (vlib_main_t * vm, vlib_node_runtime_t * node,
else
{
// special case - last range discarded
- ip4_reass_insert_range_in_chain (vm, rm, reass,
+ ip4_reass_insert_range_in_chain (vm, rm, rt, reass,
prev_range_bi, *bi0);
consumed = 1;
}
@@ -792,8 +820,8 @@ ip4_reass_update (vlib_main_t * vm, vlib_node_runtime_t * node,
if (~0 != reass->last_packet_octet &&
reass->data_len == reass->last_packet_octet + 1)
{
- ip4_reass_finalize (vm, node, rm, reass, bi0, next0, error0, next_input,
- vec_drop_compress, vec_drop_overlap);
+ ip4_reass_finalize (vm, node, rm, rt, reass, bi0, next0, error0,
+ vec_drop_compress, vec_drop_overlap, is_feature);
}
else
{
@@ -803,19 +831,22 @@ ip4_reass_update (vlib_main_t * vm, vlib_node_runtime_t * node,
}
else
{
- *next0 = next_drop;
+ *next0 = IP4_REASSEMBLY_NEXT_DROP;
*error0 = IP4_ERROR_REASS_DUPLICATE_FRAGMENT;
}
}
}
always_inline uword
-ip4_reassembly (vlib_main_t * vm, vlib_node_runtime_t * node,
- vlib_frame_t * frame)
+ip4_reassembly_inline (vlib_main_t * vm,
+ vlib_node_runtime_t * node,
+ vlib_frame_t * frame, bool is_feature)
{
u32 *from = vlib_frame_vector_args (frame);
u32 n_left_from, n_left_to_next, *to_next, next_index;
ip4_reass_main_t *rm = &ip4_reass_main;
+ ip4_reass_per_thread_t *rt = &rm->per_thread_data[os_get_thread_index ()];
+ clib_spinlock_lock (&rt->lock);
n_left_from = frame->n_vectors;
next_index = node->cached_next_index;
@@ -823,7 +854,7 @@ ip4_reassembly (vlib_main_t * vm, vlib_node_runtime_t * node,
static u32 *vec_drop_overlap = NULL; // indexes of buffers which were discarded due to overlap
static u32 *vec_drop_compress = NULL; // indexes of buffers dicarded due to buffer compression
while (n_left_from > 0 || vec_len (vec_drop_timeout) > 0 ||
- vec_len (vec_drop_overlap) > 0)
+ vec_len (vec_drop_overlap) > 0 || vec_len (vec_drop_compress) > 0)
{
vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
@@ -839,8 +870,8 @@ ip4_reassembly (vlib_main_t * vm, vlib_node_runtime_t * node,
n_left_to_next, bi,
IP4_REASSEMBLY_NEXT_DROP);
IP4_REASS_DEBUG_BUFFER (bi, enqueue_drop_timeout);
- ASSERT (rm->buffers_n > 0);
- --rm->buffers_n;
+ ASSERT (rt->buffers_n > 0);
+ --rt->buffers_n;
}
while (vec_len (vec_drop_overlap) > 0 && n_left_to_next > 0)
@@ -855,8 +886,8 @@ ip4_reassembly (vlib_main_t * vm, vlib_node_runtime_t * node,
n_left_to_next, bi,
IP4_REASSEMBLY_NEXT_DROP);
IP4_REASS_DEBUG_BUFFER (bi, enqueue_drop_duplicate_fragment);
- ASSERT (rm->buffers_n > 0);
- --rm->buffers_n;
+ ASSERT (rt->buffers_n > 0);
+ --rt->buffers_n;
}
while (vec_len (vec_drop_compress) > 0 && n_left_to_next > 0)
@@ -871,51 +902,70 @@ ip4_reassembly (vlib_main_t * vm, vlib_node_runtime_t * node,
n_left_to_next, bi,
IP4_REASSEMBLY_NEXT_DROP);
IP4_REASS_DEBUG_BUFFER (bi, enqueue_drop_compress);
- ASSERT (rm->buffers_n > 0);
- --rm->buffers_n;
+ ASSERT (rt->buffers_n > 0);
+ --rt->buffers_n;
}
while (n_left_from > 0 && n_left_to_next > 0)
{
u32 bi0;
vlib_buffer_t *b0;
- u32 next0; //, error0;
+ u32 next0;
+ u32 error0 = IP4_ERROR_NONE;
bi0 = from[0];
b0 = vlib_get_buffer (vm, bi0);
ip4_header_t *ip0 = vlib_buffer_get_current (b0);
- ip4_reass_key_t k;
- k.src.as_u32 = ip0->src_address.as_u32;
- k.dst.as_u32 = ip0->dst_address.as_u32;
- k.xx_id = vnet_buffer (b0)->sw_if_index[VLIB_RX];
- k.frag_id = ip0->fragment_id;
- k.proto = ip0->protocol;
- k.unused = 0;
- ip4_reass_t *reass =
- ip4_reass_find_or_create (vm, rm, &k, &vec_drop_timeout);
-
- u32 error0 = IP4_ERROR_NONE;
- if (reass)
+ if (!ip4_get_fragment_more (ip0) && !ip4_get_fragment_offset (ip0))
{
- ip4_reass_update (vm, node, rm, reass, &bi0, &next0, &error0,
- &vec_drop_overlap, &vec_drop_compress,
- IP4_REASSEMBLY_NEXT_INPUT,
- IP4_REASSEMBLY_NEXT_DROP);
+ // this is a whole packet - no fragmentation
+ if (is_feature)
+ {
+ next0 = IP4_REASSEMBLY_NEXT_INPUT;
+ }
+ else
+ {
+ next0 = vnet_buffer (b0)->ip.reass.next_index;
+ }
}
else
{
- next0 = IP4_REASSEMBLY_NEXT_DROP;
- error0 = IP4_ERROR_REASS_LIMIT_REACHED;
- }
+ ip4_reass_key_t k;
+ k.src.as_u32 = ip0->src_address.as_u32;
+ k.dst.as_u32 = ip0->dst_address.as_u32;
+ k.xx_id = vnet_buffer (b0)->sw_if_index[VLIB_RX];
+ k.frag_id = ip0->fragment_id;
+ k.proto = ip0->protocol;
+ k.unused = 0;
+ ip4_reass_t *reass =
+ ip4_reass_find_or_create (vm, rm, rt, &k, &vec_drop_timeout);
+
+ if (reass)
+ {
+ ip4_reass_update (vm, node, rm, rt, reass, &bi0, &next0,
+ &error0, &vec_drop_overlap,
+ &vec_drop_compress, is_feature);
+ }
+ else
+ {
+ next0 = IP4_REASSEMBLY_NEXT_DROP;
+ error0 = IP4_ERROR_REASS_LIMIT_REACHED;
+ }
- b0->error = node->errors[error0];
+ b0->error = node->errors[error0];
+ }
if (bi0 != ~0)
{
to_next[0] = bi0;
to_next += 1;
n_left_to_next -= 1;
+ if (is_feature && IP4_ERROR_NONE == error0)
+ {
+ vnet_feature_next (vnet_buffer (b0)->sw_if_index[VLIB_RX],
+ &next0, b0);
+ }
vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
n_left_to_next, bi0, next0);
IP4_REASS_DEBUG_BUFFER (bi0, enqueue_next);
@@ -928,6 +978,7 @@ ip4_reassembly (vlib_main_t * vm, vlib_node_runtime_t * node,
vlib_put_next_frame (vm, node, next_index, n_left_to_next);
}
+ clib_spinlock_unlock (&rt->lock);
return frame->n_vectors;
}
@@ -937,6 +988,13 @@ static char *ip4_reassembly_error_strings[] = {
#undef _
};
+always_inline uword
+ip4_reassembly (vlib_main_t * vm, vlib_node_runtime_t * node,
+ vlib_frame_t * frame)
+{
+ return ip4_reassembly_inline (vm, node, frame, false /* is_feature */ );
+}
+
/* *INDENT-OFF* */
VLIB_REGISTER_NODE (ip4_reass_node, static) = {
.function = ip4_reassembly,
@@ -954,8 +1012,45 @@ VLIB_REGISTER_NODE (ip4_reass_node, static) = {
};
/* *INDENT-ON* */
-VLIB_NODE_FUNCTION_MULTIARCH (ip4_reass_node, ip4_reassembly)
- static u32 ip4_reass_get_nbuckets ()
+VLIB_NODE_FUNCTION_MULTIARCH (ip4_reass_node, ip4_reassembly);
+
+always_inline uword
+ip4_reassembly_feature (vlib_main_t * vm,
+ vlib_node_runtime_t * node, vlib_frame_t * frame)
+{
+ return ip4_reassembly_inline (vm, node, frame, true /* is_feature */ );
+}
+
+/* *INDENT-OFF* */
+VLIB_REGISTER_NODE (ip4_reass_node_feature, static) = {
+ .function = ip4_reassembly_feature,
+ .name = "ip4-reassembly-feature",
+ .vector_size = sizeof (u32),
+ .format_trace = format_ip4_reass_trace,
+ .n_errors = ARRAY_LEN (ip4_reassembly_error_strings),
+ .error_strings = ip4_reassembly_error_strings,
+ .n_next_nodes = IP4_REASSEMBLY_N_NEXT,
+ .next_nodes =
+ {
+ [IP4_REASSEMBLY_NEXT_INPUT] = "ip4-input",
+ [IP4_REASSEMBLY_NEXT_DROP] = "ip4-drop",
+ },
+};
+/* *INDENT-ON* */
+
+VLIB_NODE_FUNCTION_MULTIARCH (ip4_reass_node_feature, ip4_reassembly_feature);
+
+/* *INDENT-OFF* */
+VNET_FEATURE_INIT (ip4_reassembly_feature, static) = {
+ .arc_name = "ip4-unicast",
+ .node_name = "ip4-reassembly-feature",
+ .runs_before = VNET_FEATURES ("ip4-lookup"),
+ .runs_after = 0,
+};
+/* *INDENT-ON* */
+
+always_inline u32
+ip4_reass_get_nbuckets ()
{
ip4_reass_main_t *rm = &ip4_reass_main;
u32 nbuckets;
@@ -982,7 +1077,7 @@ typedef struct
clib_bihash_24_8_t *new_hash;
} ip4_rehash_cb_ctx;
-void
+static void
ip4_rehash_cb (clib_bihash_kv_24_8_t * kv, void *_ctx)
{
ip4_rehash_cb_ctx *ctx = _ctx;
@@ -992,16 +1087,23 @@ ip4_rehash_cb (clib_bihash_kv_24_8_t * kv, void *_ctx)
}
}
-vnet_api_error_t
-ip4_reass_set (u32 timeout_ms, u32 max_reassemblies,
- u32 expire_walk_interval_ms)
+static void
+ip4_reass_set_params (u32 timeout_ms, u32 max_reassemblies,
+ u32 expire_walk_interval_ms)
{
- u32 old_nbuckets = ip4_reass_get_nbuckets ();
ip4_reass_main.timeout_ms = timeout_ms;
ip4_reass_main.timeout = (f64) timeout_ms / (f64) MSEC_PER_SEC;
ip4_reass_main.max_reass_n = max_reassemblies;
ip4_reass_main.expire_walk_interval_ms = expire_walk_interval_ms;
+}
+vnet_api_error_t
+ip4_reass_set (u32 timeout_ms, u32 max_reassemblies,
+ u32 expire_walk_interval_ms)
+{
+ u32 old_nbuckets = ip4_reass_get_nbuckets ();
+ ip4_reass_set_params (timeout_ms, max_reassemblies,
+ expire_walk_interval_ms);
vlib_process_signal_event (ip4_reass_main.vlib_main,
ip4_reass_main.ip4_reass_expire_node_idx,
IP4_EVENT_CONFIG_CHANGED, 0);
@@ -1043,7 +1145,7 @@ ip4_reass_get (u32 * timeout_ms, u32 * max_reassemblies,
return 0;
}
-clib_error_t *
+static clib_error_t *
ip4_reass_init_function (vlib_main_t * vm)
{
ip4_reass_main_t *rm = &ip4_reass_main;
@@ -1054,23 +1156,29 @@ ip4_reass_init_function (vlib_main_t * vm)
rm->vlib_main = vm;
rm->vnet_main = vnet_get_main ();
- rm->reass_n = 0;
- pool_alloc (rm->pool, rm->max_reass_n);
+ vec_validate (rm->per_thread_data, vlib_num_workers () + 1);
+ ip4_reass_per_thread_t *rt;
+ vec_foreach (rt, rm->per_thread_data)
+ {
+ clib_spinlock_init (&rt->lock);
+ pool_alloc (rt->pool, rm->max_reass_n);
+ }
node = vlib_get_node_by_name (vm, (u8 *) "ip4-reassembly-expire-walk");
ASSERT (node);
rm->ip4_reass_expire_node_idx = node->index;
- ip4_reass_set (IP4_REASS_TIMEOUT_DEFAULT_MS,
- IP4_REASS_MAX_REASSEMBLIES_DEAFULT,
- IP4_REASS_EXPIRE_WALK_INTERVAL_DEFAULT_MS);
-
nbuckets = ip4_reass_get_nbuckets ();
clib_bihash_init_24_8 (&rm->hash, "ip4-reass", nbuckets, nbuckets * 1024);
node = vlib_get_node_by_name (vm, (u8 *) "ip4-drop");
ASSERT (node);
rm->ip4_drop_idx = node->index;
+
+ ip4_reass_set_params (IP4_REASS_TIMEOUT_DEFAULT_MS,
+ IP4_REASS_MAX_REASSEMBLIES_DEFAULT,
+ IP4_REASS_EXPIRE_WALK_INTERVAL_DEFAULT_MS);
+
return error;
}
@@ -1107,32 +1215,57 @@ ip4_reass_walk_expired (vlib_main_t * vm,
u32 *vec_drop_timeout = NULL;
int *pool_indexes_to_free = NULL;
+ uword thread_index = 0;
int index;
- /* *INDENT-OFF* */
- pool_foreach_index (index, rm->pool, ({
- reass = pool_elt_at_index (rm->pool, index);
- if (now > reass->last_heard + rm->timeout)
- {
- vec_add1 (pool_indexes_to_free, index);
- }
- }));
- /* *INDENT-ON* */
- int *i;
- /* *INDENT-OFF* */
- vec_foreach (i, pool_indexes_to_free)
- {
- ip4_reass_t *reass = pool_elt_at_index (rm->pool, i[0]);
- ip4_reass_on_timeout (vm, rm, reass, &vec_drop_timeout);
- ip4_reass_free (rm, reass);
- }
- /* *INDENT-ON* */
+ const uword nthreads = os_get_nthreads ();
+ for (thread_index = 0; thread_index < nthreads; ++thread_index)
+ {
+ ip4_reass_per_thread_t *rt = &rm->per_thread_data[thread_index];
+ clib_spinlock_lock (&rt->lock);
+
+ vec_reset_length (pool_indexes_to_free);
+ /* *INDENT-OFF* */
+ pool_foreach_index (index, rt->pool, ({
+ reass = pool_elt_at_index (rt->pool, index);
+ if (now > reass->last_heard + rm->timeout)
+ {
+ vec_add1 (pool_indexes_to_free, index);
+ }
+ }));
+ /* *INDENT-ON* */
+ int *i;
+ /* *INDENT-OFF* */
+ vec_foreach (i, pool_indexes_to_free)
+ {
+ ip4_reass_t *reass = pool_elt_at_index (rt->pool, i[0]);
+ u32 before = vec_len (vec_drop_timeout);
+ vlib_buffer_t *b = vlib_get_buffer (vm, reass->first_bi);
+ if (PREDICT_FALSE (b->flags & VLIB_BUFFER_IS_TRACED))
+ {
+ if (pool_is_free_index (vm->trace_main.trace_buffer_pool,
+ b->trace_index))
+ {
+ /* the trace is gone, don't trace this buffer anymore */
+ b->flags &= ~VLIB_BUFFER_IS_TRACED;
+ }
+ }
+ ip4_reass_on_timeout (vm, rm, reass, &vec_drop_timeout);
+ u32 after = vec_len (vec_drop_timeout);
+ ASSERT (rt->buffers_n >= (after - before));
+ rt->buffers_n -= (after - before);
+ ip4_reass_free (rm, rt, reass);
+ }
+ /* *INDENT-ON* */
+
+ clib_spinlock_unlock (&rt->lock);
+ }
while (vec_len (vec_drop_timeout) > 0)
{
vlib_frame_t *f = vlib_get_frame_to_node (vm, rm->ip4_drop_idx);
u32 *to_next = vlib_frame_vector_args (f);
u32 n_left_to_next = VLIB_FRAME_SIZE - f->n_vectors;
- u32 n_trace = 0;
+ int trace_frame = 0;
while (vec_len (vec_drop_timeout) > 0 && n_left_to_next > 0)
{
u32 bi = vec_pop (vec_drop_timeout);
@@ -1147,7 +1280,7 @@ ip4_reass_walk_expired (vlib_main_t * vm,
}
else
{
- ++n_trace;
+ trace_frame = 1;
}
}
b->error = node->errors[IP4_ERROR_REASS_TIMEOUT];
@@ -1156,13 +1289,8 @@ ip4_reass_walk_expired (vlib_main_t * vm,
to_next += 1;
n_left_to_next -= 1;
IP4_REASS_DEBUG_BUFFER (bi, enqueue_drop_timeout_walk);
- ASSERT (rm->buffers_n > 0);
- --rm->buffers_n;
- }
- if (PREDICT_FALSE (n_trace > 0))
- {
- f->flags |= VLIB_FRAME_TRACE;
}
+ f->flags |= (trace_frame * VLIB_FRAME_TRACE);
vlib_put_frame_to_node (vm, rm->ip4_drop_idx, f);
}
@@ -1207,7 +1335,7 @@ format_ip4_reass (u8 * s, va_list * args)
vlib_main_t *vm = va_arg (*args, vlib_main_t *);
ip4_reass_t *reass = va_arg (*args, ip4_reass_t *);
- s = format (s, "ID: %u, key: %U\n first_bi: %u, data_len: %u, "
+ s = format (s, "ID: %lu, key: %U\n first_bi: %u, data_len: %u, "
"last_packet_octet: %u, trace_op_counter: %u\n",
reass->id, format_ip4_reass_key, &reass->key, reass->first_bi,
reass->data_len, reass->last_packet_octet,
@@ -1246,22 +1374,41 @@ show_ip4_reass (vlib_main_t * vm, unformat_input_t * input,
vlib_cli_output (vm, "---------------------");
vlib_cli_output (vm, "IP4 reassembly status");
vlib_cli_output (vm, "---------------------");
+ bool details = false;
if (unformat (input, "details"))
{
- ip4_reass_t *reass;
- /* *INDENT-OFF* */
- pool_foreach (reass, rm->pool, {
- vlib_cli_output (vm, "%U", format_ip4_reass, vm, reass);
- });
- /* *INDENT-ON* */
+ details = true;
+ }
+
+ u32 sum_reass_n = 0;
+ u64 sum_buffers_n = 0;
+ ip4_reass_t *reass;
+ uword thread_index;
+ const uword nthreads = os_get_nthreads ();
+ for (thread_index = 0; thread_index < nthreads; ++thread_index)
+ {
+ ip4_reass_per_thread_t *rt = &rm->per_thread_data[thread_index];
+ clib_spinlock_lock (&rt->lock);
+ if (details)
+ {
+ /* *INDENT-OFF* */
+ pool_foreach (reass, rt->pool, {
+ vlib_cli_output (vm, "%U", format_ip4_reass, vm, reass);
+ });
+ /* *INDENT-ON* */
+ }
+ sum_reass_n += rt->reass_n;
+ sum_buffers_n += rt->buffers_n;
+ clib_spinlock_unlock (&rt->lock);
}
vlib_cli_output (vm, "---------------------");
- vlib_cli_output (vm, "Current IP4 reassemblies count: %lu\n", rm->reass_n);
+ vlib_cli_output (vm, "Current IP4 reassemblies count: %lu\n",
+ (long unsigned) sum_reass_n);
vlib_cli_output (vm,
- "Maximum configured concurrent IP4 reassemblies: %lu\n",
+ "Maximum configured concurrent IP4 reassemblies per worker-thread: %lu\n",
(long unsigned) rm->max_reass_n);
vlib_cli_output (vm, "Buffers in use: %lu\n",
- (long unsigned) rm->buffers_n);
+ (long unsigned) sum_buffers_n);
return 0;
}
@@ -1273,6 +1420,13 @@ VLIB_CLI_COMMAND (show_ip4_reassembly_cmd, static) = {
};
/* *INDENT-ON* */
+vnet_api_error_t
+ip4_reass_enable_disable (u32 sw_if_index, u8 enable_disable)
+{
+ return vnet_feature_enable_disable ("ip4-unicast", "ip4-reassembly-feature",
+ sw_if_index, enable_disable, 0, 0);
+}
+
/*
* fd.io coding-style-patch-verification: ON
*
diff --git a/src/vnet/ip/ip4_reassembly.h b/src/vnet/ip/ip4_reassembly.h
index a48c07ef061..521ca0f1998 100644
--- a/src/vnet/ip/ip4_reassembly.h
+++ b/src/vnet/ip/ip4_reassembly.h
@@ -38,6 +38,9 @@ vnet_api_error_t ip4_reass_set (u32 timeout_ms, u32 max_reassemblies,
vnet_api_error_t ip4_reass_get (u32 * timeout_ms, u32 * max_reassemblies,
u32 * expire_walk_interval_ms);
+vnet_api_error_t ip4_reass_enable_disable (u32 sw_if_index,
+ u8 enable_disable);
+
#endif /* __included_ip4_reassembly_h */
/*
diff --git a/src/vnet/ip/ip6_forward.c b/src/vnet/ip/ip6_forward.c
index 3eb84e8b9ef..2c001115262 100644
--- a/src/vnet/ip/ip6_forward.c
+++ b/src/vnet/ip/ip6_forward.c
@@ -1352,7 +1352,6 @@ VLIB_REGISTER_NODE (ip6_local_node, static) =
[IP_LOCAL_NEXT_PUNT] = "ip6-punt",
[IP_LOCAL_NEXT_UDP_LOOKUP] = "ip6-udp-lookup",
[IP_LOCAL_NEXT_ICMP] = "ip6-icmp-input",
- [IP_LOCAL_NEXT_REASSEMBLY] = "ip6-reassembly",
},
};
/* *INDENT-ON* */
diff --git a/src/vnet/ip/ip6_reassembly.c b/src/vnet/ip/ip6_reassembly.c
index df9c4fbcdf8..c6424a7309c 100644
--- a/src/vnet/ip/ip6_reassembly.c
+++ b/src/vnet/ip/ip6_reassembly.c
@@ -29,7 +29,7 @@
#define MSEC_PER_SEC 1000
#define IP6_REASS_TIMEOUT_DEFAULT_MS 100
#define IP6_REASS_EXPIRE_WALK_INTERVAL_DEFAULT_MS 10000 // 10 seconds default
-#define IP6_REASS_MAX_REASSEMBLIES_DEAFULT 1024
+#define IP6_REASS_MAX_REASSEMBLIES_DEFAULT 1024
#define IP6_REASS_HT_LOAD_FACTOR (0.75)
static vlib_node_registration_t ip6_reass_node;
@@ -89,12 +89,10 @@ typedef struct
{
// hash table key
ip6_reass_key_t key;
- // time when first packet was received
- f64 first_heard;
// time when last packet was received
f64 last_heard;
// internal id of this reassembly
- u32 id;
+ u64 id;
// buffer index of first buffer in this reassembly context
u32 first_bi;
// last octet of packet, ~0 until fragment without more_fragments arrives
@@ -103,10 +101,23 @@ typedef struct
u32 data_len;
// trace operation counter
u32 trace_op_counter;
+ // next index - used by non-feature node
+ u8 next_index;
+ // minimum fragment length for this reassembly - used to estimate MTU
+ u16 min_fragment_length;
} ip6_reass_t;
typedef struct
{
+ ip6_reass_t *pool;
+ u32 reass_n;
+ u32 buffers_n;
+ u32 id_counter;
+ clib_spinlock_t lock;
+} ip6_reass_per_thread_t;
+
+typedef struct
+{
// IPv6 config
u32 timeout_ms;
f64 timeout;
@@ -114,11 +125,10 @@ typedef struct
u32 max_reass_n;
// IPv6 runtime
- ip6_reass_t *pool;
clib_bihash_48_8_t hash;
- u32 reass_n;
- u32 id_counter;
- u32 buffers_n;
+
+ // per-thread data
+ ip6_reass_per_thread_t *per_thread_data;
// convenience
vlib_main_t *vlib_main;
@@ -164,7 +174,6 @@ typedef struct
typedef struct
{
ip6_reass_trace_operation_e action;
- u32 pool_index;
u32 reass_id;
ip6_reass_range_trace_t trace_range;
u32 size_diff;
@@ -187,7 +196,7 @@ ip6_reass_trace_details (vlib_main_t * vm, u32 bi,
trace->range_bi = bi;
}
-u8 *
+static u8 *
format_ip6_reass_range_trace (u8 * s, va_list * args)
{
ip6_reass_range_trace_t *trace = va_arg (*args, ip6_reass_range_trace_t *);
@@ -197,7 +206,7 @@ format_ip6_reass_range_trace (u8 * s, va_list * args)
return s;
}
-u8 *
+static u8 *
format_ip6_reass_trace (u8 * s, va_list * args)
{
CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
@@ -247,8 +256,13 @@ ip6_reass_add_trace (vlib_main_t * vm, vlib_node_runtime_t * node,
{
vlib_buffer_t *b = vlib_get_buffer (vm, bi);
vnet_buffer_opaque_t *vnb = vnet_buffer (b);
+ if (pool_is_free_index (vm->trace_main.trace_buffer_pool, b->trace_index))
+ {
+ // this buffer's trace is gone
+ b->flags &= ~VLIB_BUFFER_IS_TRACED;
+ return;
+ }
ip6_reass_trace_t *t = vlib_add_trace (vm, node, b, sizeof (t[0]));
- t->pool_index = reass - rm->pool;
t->reass_id = reass->id;
t->action = action;
ip6_reass_trace_details (vm, bi, &t->trace_range);
@@ -268,8 +282,9 @@ ip6_reass_add_trace (vlib_main_t * vm, vlib_node_runtime_t * node,
#endif
}
-static void
-ip6_reass_free (ip6_reass_main_t * rm, ip6_reass_t * reass)
+always_inline void
+ip6_reass_free (ip6_reass_main_t * rm, ip6_reass_per_thread_t * rt,
+ ip6_reass_t * reass)
{
clib_bihash_kv_48_8_t kv;
kv.key[0] = reass->key.as_u64[0];
@@ -279,11 +294,11 @@ ip6_reass_free (ip6_reass_main_t * rm, ip6_reass_t * reass)
kv.key[4] = reass->key.as_u64[4];
kv.key[5] = reass->key.as_u64[5];
clib_bihash_add_del_48_8 (&rm->hash, &kv, 0);
- pool_put (rm->pool, reass);
- --rm->reass_n;
+ pool_put (rt->pool, reass);
+ --rt->reass_n;
}
-static void
+always_inline void
ip6_reass_drop_all (vlib_main_t * vm, ip6_reass_main_t * rm,
ip6_reass_t * reass, u32 ** vec_drop_bi)
{
@@ -313,7 +328,7 @@ ip6_reass_drop_all (vlib_main_t * vm, ip6_reass_main_t * rm,
}
}
-static void
+always_inline void
ip6_reass_on_timeout (vlib_main_t * vm, vlib_node_runtime_t * node,
ip6_reass_main_t * rm, ip6_reass_t * reass,
u32 * icmp_bi, u32 ** vec_timeout)
@@ -349,10 +364,9 @@ ip6_reass_on_timeout (vlib_main_t * vm, vlib_node_runtime_t * node,
ip6_reass_drop_all (vm, rm, reass, vec_timeout);
}
-static ip6_reass_t *
-ip6_reass_find_or_create (vlib_main_t * vm,
- vlib_node_runtime_t * node,
- ip6_reass_main_t * rm,
+always_inline ip6_reass_t *
+ip6_reass_find_or_create (vlib_main_t * vm, vlib_node_runtime_t * node,
+ ip6_reass_main_t * rm, ip6_reass_per_thread_t * rt,
ip6_reass_key_t * k, u32 * icmp_bi,
u32 ** vec_timeout)
{
@@ -368,11 +382,11 @@ ip6_reass_find_or_create (vlib_main_t * vm,
if (!clib_bihash_search_48_8 (&rm->hash, &kv, &value))
{
- reass = pool_elt_at_index (rm->pool, value.value);
+ reass = pool_elt_at_index (rt->pool, value.value);
if (now > reass->last_heard + rm->timeout)
{
ip6_reass_on_timeout (vm, node, rm, reass, icmp_bi, vec_timeout);
- ip6_reass_free (rm, reass);
+ ip6_reass_free (rm, rt, reass);
reass = NULL;
}
}
@@ -383,21 +397,22 @@ ip6_reass_find_or_create (vlib_main_t * vm,
return reass;
}
- if (rm->reass_n >= rm->max_reass_n)
+ if (rt->reass_n >= rm->max_reass_n)
{
reass = NULL;
return reass;
}
else
{
- pool_get (rm->pool, reass);
+ pool_get (rt->pool, reass);
memset (reass, 0, sizeof (*reass));
- reass->id = rm->id_counter;
- ++rm->id_counter;
+ reass->id =
+ ((u64) os_get_thread_index () * 1000000000) + rt->id_counter;
+ ++rt->id_counter;
reass->first_bi = ~0;
reass->last_packet_octet = ~0;
reass->data_len = 0;
- ++rm->reass_n;
+ ++rt->reass_n;
}
reass->key.as_u64[0] = kv.key[0] = k->as_u64[0];
@@ -406,27 +421,27 @@ ip6_reass_find_or_create (vlib_main_t * vm,
reass->key.as_u64[3] = kv.key[3] = k->as_u64[3];
reass->key.as_u64[4] = kv.key[4] = k->as_u64[4];
reass->key.as_u64[5] = kv.key[5] = k->as_u64[5];
- kv.value = reass - rm->pool;
+ kv.value = reass - rt->pool;
reass->last_heard = now;
if (clib_bihash_add_del_48_8 (&rm->hash, &kv, 1))
{
- ip6_reass_free (rm, reass);
+ ip6_reass_free (rm, rt, reass);
reass = NULL;
}
return reass;
}
-void
+always_inline void
ip6_reass_finalize (vlib_main_t * vm, vlib_node_runtime_t * node,
- ip6_reass_main_t * rm, ip6_reass_t * reass, u32 * bi0,
- u32 * next0, vlib_error_t * error0, u32 next_input,
- u32 ** vec_drop_compress)
+ ip6_reass_main_t * rm, ip6_reass_per_thread_t * rt,
+ ip6_reass_t * reass, u32 * bi0, u32 * next0,
+ vlib_error_t * error0, u32 ** vec_drop_compress,
+ bool is_feature)
{
ASSERT (~0 != reass->first_bi);
*bi0 = reass->first_bi;
- *next0 = next_input;
*error0 = IP6_ERROR_NONE;
ip6_frag_hdr_t *frag_hdr;
vlib_buffer_t *last_b = NULL;
@@ -548,7 +563,6 @@ ip6_reass_finalize (vlib_main_t * vm, vlib_node_runtime_t * node,
ip->payload_length =
clib_host_to_net_u16 (total_length + first_b->current_length -
sizeof (*ip));
- ip6_reass_free (rm, reass);
vlib_buffer_chain_compress (vm, first_b, vec_drop_compress);
if (PREDICT_FALSE (first_b->flags & VLIB_BUFFER_IS_TRACED))
{
@@ -580,10 +594,20 @@ ip6_reass_finalize (vlib_main_t * vm, vlib_node_runtime_t * node,
while (0);
#endif
}
+ if (is_feature)
+ {
+ *next0 = IP6_REASSEMBLY_NEXT_INPUT;
+ }
+ else
+ {
+ *next0 = reass->next_index;
+ }
+ vnet_buffer (first_b)->ip.reass.estimated_mtu = reass->min_fragment_length;
+ ip6_reass_free (rm, rt, reass);
reass = NULL;
}
-static u32
+always_inline u32
ip6_reass_get_buffer_chain_length (vlib_main_t * vm, vlib_buffer_t * b)
{
u32 len = 0;
@@ -602,11 +626,11 @@ ip6_reass_get_buffer_chain_length (vlib_main_t * vm, vlib_buffer_t * b)
return len;
}
-static void
-ip6_reass_insert_range_in_chain (vlib_main_t * vm,
- ip6_reass_main_t * rm,
- ip6_reass_t * reass,
- u32 prev_range_bi, u32 new_next_bi)
+always_inline void
+ip6_reass_insert_range_in_chain (vlib_main_t * vm, ip6_reass_main_t * rm,
+ ip6_reass_per_thread_t * rt,
+ ip6_reass_t * reass, u32 prev_range_bi,
+ u32 new_next_bi)
{
vlib_buffer_t *new_next_b = vlib_get_buffer (vm, new_next_bi);
@@ -627,16 +651,16 @@ ip6_reass_insert_range_in_chain (vlib_main_t * vm,
reass->first_bi = new_next_bi;
}
reass->data_len += ip6_reass_buffer_get_data_len (new_next_b);
- rm->buffers_n += ip6_reass_get_buffer_chain_length (vm, new_next_b);
+ rt->buffers_n += ip6_reass_get_buffer_chain_length (vm, new_next_b);
}
-void
+always_inline void
ip6_reass_update (vlib_main_t * vm, vlib_node_runtime_t * node,
- ip6_reass_main_t * rm, ip6_reass_t * reass, u32 * bi0,
- u32 * next0, vlib_error_t * error0,
- ip6_frag_hdr_t * frag_hdr, u32 ** vec_drop_overlap,
- u32 ** vec_drop_compress, u32 next_input, u32 next_drop,
- u32 next_icmp_error)
+ ip6_reass_main_t * rm, ip6_reass_per_thread_t * rt,
+ ip6_reass_t * reass, u32 * bi0, u32 * next0,
+ vlib_error_t * error0, ip6_frag_hdr_t * frag_hdr,
+ u32 ** vec_drop_overlap, u32 ** vec_drop_compress,
+ bool is_feature)
{
int consumed = 0;
vlib_buffer_t *fb = vlib_get_buffer (vm, *bi0);
@@ -660,34 +684,6 @@ ip6_reass_update (vlib_main_t * vm, vlib_node_runtime_t * node,
fvnb->ip.reass.range_first = fragment_first;
fvnb->ip.reass.range_last = fragment_last;
fvnb->ip.reass.next_range_bi = ~0;
- if (more_fragments && 0 != fragment_length % 8)
- {
- if (PREDICT_FALSE (fb->flags & VLIB_BUFFER_IS_TRACED))
- {
- ip6_reass_add_trace (vm, node, rm, reass, *bi0,
- ICMP_ERROR_FL_NOT_MULT_8, 0);
- }
- *next0 = next_icmp_error;
- icmp6_error_set_vnet_buffer (fb, ICMP6_parameter_problem,
- ICMP6_parameter_problem_erroneous_header_field,
- (u8 *) & fip->payload_length - (u8 *) fip);
- return;
- }
- if (fragment_first + fragment_length > 65535)
- {
- if (PREDICT_FALSE (fb->flags & VLIB_BUFFER_IS_TRACED))
- {
- ip6_reass_add_trace (vm, node, rm, reass, *bi0,
- ICMP_ERROR_FL_TOO_BIG, 0);
- }
- *next0 = next_icmp_error;
- ip6_header_t *ip0 = vlib_buffer_get_current (fb);
- icmp6_error_set_vnet_buffer (fb, ICMP6_parameter_problem,
- ICMP6_parameter_problem_erroneous_header_field,
- (u8 *) & frag_hdr->fragment_offset_and_more
- - (u8 *) ip0);
- return;
- }
if (!more_fragments)
{
reass->last_packet_octet = fragment_last;
@@ -695,15 +691,17 @@ ip6_reass_update (vlib_main_t * vm, vlib_node_runtime_t * node,
if (~0 == reass->first_bi)
{
// starting a new reassembly
- ip6_reass_insert_range_in_chain (vm, rm, reass, prev_range_bi, *bi0);
+ ip6_reass_insert_range_in_chain (vm, rm, rt, reass, prev_range_bi,
+ *bi0);
if (PREDICT_FALSE (fb->flags & VLIB_BUFFER_IS_TRACED))
{
ip6_reass_add_trace (vm, node, rm, reass, *bi0, RANGE_NEW, 0);
}
+ reass->min_fragment_length = clib_net_to_host_u16 (fip->payload_length);
*bi0 = ~0;
return;
}
- fvnb->ip.reass.estimated_mtu =
+ reass->min_fragment_length =
clib_min (clib_net_to_host_u16 (fip->payload_length),
fvnb->ip.reass.estimated_mtu);
while (~0 != candidate_range_bi)
@@ -719,8 +717,8 @@ ip6_reass_update (vlib_main_t * vm, vlib_node_runtime_t * node,
~0 == candidate_range_bi)
{
// special case - this fragment falls beyond all known ranges
- ip6_reass_insert_range_in_chain (vm, rm, reass, prev_range_bi,
- *bi0);
+ ip6_reass_insert_range_in_chain (vm, rm, rt, reass,
+ prev_range_bi, *bi0);
consumed = 1;
break;
}
@@ -729,7 +727,7 @@ ip6_reass_update (vlib_main_t * vm, vlib_node_runtime_t * node,
if (fragment_last < candidate_vnb->ip.reass.range_first)
{
// this fragment ends before candidate range without any overlap
- ip6_reass_insert_range_in_chain (vm, rm, reass, prev_range_bi,
+ ip6_reass_insert_range_in_chain (vm, rm, rt, reass, prev_range_bi,
*bi0);
consumed = 1;
}
@@ -742,13 +740,13 @@ ip6_reass_update (vlib_main_t * vm, vlib_node_runtime_t * node,
{
// overlapping fragment - not allowed by RFC 8200
ip6_reass_drop_all (vm, rm, reass, vec_drop_overlap);
- ip6_reass_free (rm, reass);
+ ip6_reass_free (rm, rt, reass);
if (PREDICT_FALSE (fb->flags & VLIB_BUFFER_IS_TRACED))
{
ip6_reass_add_trace (vm, node, rm, reass, *bi0, RANGE_OVERLAP,
0);
}
- *next0 = next_drop;
+ *next0 = IP6_REASSEMBLY_NEXT_DROP;
*error0 = IP6_ERROR_REASS_OVERLAPPING_FRAGMENT;
}
break;
@@ -763,8 +761,8 @@ ip6_reass_update (vlib_main_t * vm, vlib_node_runtime_t * node,
if (~0 != reass->last_packet_octet &&
reass->data_len == reass->last_packet_octet + 1)
{
- ip6_reass_finalize (vm, node, rm, reass, bi0, next0, error0, next_input,
- vec_drop_compress);
+ ip6_reass_finalize (vm, node, rm, rt, reass, bi0, next0, error0,
+ vec_drop_compress, is_feature);
}
else
{
@@ -774,19 +772,90 @@ ip6_reass_update (vlib_main_t * vm, vlib_node_runtime_t * node,
}
else
{
- *next0 = next_drop;
+ *next0 = IP6_REASSEMBLY_NEXT_DROP;
+ ;
*error0 = IP6_ERROR_REASS_DUPLICATE_FRAGMENT;
}
}
}
+always_inline bool
+ip6_reass_verify_upper_layer_present (vlib_node_runtime_t * node,
+ vlib_buffer_t * b,
+ ip6_frag_hdr_t * frag_hdr)
+{
+ ip6_ext_header_t *tmp = (ip6_ext_header_t *) frag_hdr;
+ while (ip6_ext_hdr (tmp->next_hdr))
+ {
+ tmp = ip6_ext_next_header (tmp);
+ }
+ if (IP_PROTOCOL_IP6_NONXT == tmp->next_hdr)
+ {
+ icmp6_error_set_vnet_buffer (b, ICMP6_parameter_problem,
+ ICMP6_parameter_problem_first_fragment_has_incomplete_header_chain,
+ 0);
+ b->error = node->errors[IP6_ERROR_REASS_MISSING_UPPER];
+
+ return false;
+ }
+ return true;
+}
+
+always_inline bool
+ip6_reass_verify_fragment_multiple_8 (vlib_main_t * vm,
+ vlib_node_runtime_t * node,
+ vlib_buffer_t * b,
+ ip6_frag_hdr_t * frag_hdr)
+{
+ vnet_buffer_opaque_t *vnb = vnet_buffer (b);
+ ip6_header_t *ip = vlib_buffer_get_current (b);
+ int more_fragments = ip6_frag_hdr_more (frag_hdr);
+ u32 fragment_length =
+ vlib_buffer_length_in_chain (vm, b) -
+ (vnb->ip.reass.ip6_frag_hdr_offset + sizeof (*frag_hdr));
+ if (more_fragments && 0 != fragment_length % 8)
+ {
+ icmp6_error_set_vnet_buffer (b, ICMP6_parameter_problem,
+ ICMP6_parameter_problem_erroneous_header_field,
+ (u8 *) & ip->payload_length - (u8 *) ip);
+ return false;
+ }
+ return true;
+}
+
+always_inline bool
+ip6_reass_verify_packet_size_lt_64k (vlib_main_t * vm,
+ vlib_node_runtime_t * node,
+ vlib_buffer_t * b,
+ ip6_frag_hdr_t * frag_hdr)
+{
+ vnet_buffer_opaque_t *vnb = vnet_buffer (b);
+ u32 fragment_first = ip6_frag_hdr_offset_bytes (frag_hdr);
+ u32 fragment_length =
+ vlib_buffer_length_in_chain (vm, b) -
+ (vnb->ip.reass.ip6_frag_hdr_offset + sizeof (*frag_hdr));
+ if (fragment_first + fragment_length > 65535)
+ {
+ ip6_header_t *ip0 = vlib_buffer_get_current (b);
+ icmp6_error_set_vnet_buffer (b, ICMP6_parameter_problem,
+ ICMP6_parameter_problem_erroneous_header_field,
+ (u8 *) & frag_hdr->fragment_offset_and_more
+ - (u8 *) ip0);
+ return false;
+ }
+ return true;
+}
+
always_inline uword
-ip6_reassembly (vlib_main_t * vm, vlib_node_runtime_t * node,
- vlib_frame_t * frame)
+ip6_reassembly_inline (vlib_main_t * vm,
+ vlib_node_runtime_t * node,
+ vlib_frame_t * frame, bool is_feature)
{
u32 *from = vlib_frame_vector_args (frame);
u32 n_left_from, n_left_to_next, *to_next, next_index;
ip6_reass_main_t *rm = &ip6_reass_main;
+ ip6_reass_per_thread_t *rt = &rm->per_thread_data[os_get_thread_index ()];
+ clib_spinlock_lock (&rt->lock);
n_left_from = frame->n_vectors;
next_index = node->cached_next_index;
@@ -794,7 +863,7 @@ ip6_reassembly (vlib_main_t * vm, vlib_node_runtime_t * node,
static u32 *vec_drop_overlap = NULL; // indexes of buffers dropped due to overlap
static u32 *vec_drop_compress = NULL; // indexes of buffers dropped due to buffer compression
while (n_left_from > 0 || vec_len (vec_timeout) > 0 ||
- vec_len (vec_drop_overlap) > 0)
+ vec_len (vec_drop_overlap) > 0 || vec_len (vec_drop_compress) > 0)
{
vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
@@ -809,8 +878,8 @@ ip6_reassembly (vlib_main_t * vm, vlib_node_runtime_t * node,
vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
n_left_to_next, bi,
IP6_REASSEMBLY_NEXT_DROP);
- ASSERT (rm->buffers_n > 0);
- --rm->buffers_n;
+ ASSERT (rt->buffers_n > 0);
+ --rt->buffers_n;
}
while (vec_len (vec_drop_overlap) > 0 && n_left_to_next > 0)
@@ -824,8 +893,8 @@ ip6_reassembly (vlib_main_t * vm, vlib_node_runtime_t * node,
vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
n_left_to_next, bi,
IP6_REASSEMBLY_NEXT_DROP);
- ASSERT (rm->buffers_n > 0);
- --rm->buffers_n;
+ ASSERT (rt->buffers_n > 0);
+ --rt->buffers_n;
}
while (vec_len (vec_drop_compress) > 0 && n_left_to_next > 0)
@@ -839,15 +908,17 @@ ip6_reassembly (vlib_main_t * vm, vlib_node_runtime_t * node,
vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
n_left_to_next, bi,
IP6_REASSEMBLY_NEXT_DROP);
- ASSERT (rm->buffers_n > 0);
- --rm->buffers_n;
+ ASSERT (rt->buffers_n > 0);
+ --rt->buffers_n;
}
while (n_left_from > 0 && n_left_to_next > 0)
{
u32 bi0;
vlib_buffer_t *b0;
- u32 next0; //, error0;
+ u32 next0;
+ u32 error0 = IP6_ERROR_NONE;
+ u32 icmp_bi = ~0;
bi0 = from[0];
b0 = vlib_get_buffer (vm, bi0);
@@ -857,31 +928,28 @@ ip6_reassembly (vlib_main_t * vm, vlib_node_runtime_t * node,
ip6_ext_header_t *prev_hdr;
ip6_ext_header_find_t (ip0, prev_hdr, frag_hdr,
IP_PROTOCOL_IPV6_FRAGMENTATION);
+ if (!frag_hdr)
+ {
+ // this is a regular packet - no fragmentation
+ next0 = IP6_REASSEMBLY_NEXT_INPUT;
+ goto skip_reass;
+ }
if (0 == ip6_frag_hdr_offset (frag_hdr))
{
// first fragment - verify upper-layer is present
- ip6_ext_header_t *tmp = (ip6_ext_header_t *) frag_hdr;
- while (ip6_ext_hdr (tmp->next_hdr))
- {
- tmp = ip6_ext_next_header (tmp);
- }
- if (IP_PROTOCOL_IP6_NONXT == tmp->next_hdr)
+ if (!ip6_reass_verify_upper_layer_present (node, b0, frag_hdr))
{
- icmp6_error_set_vnet_buffer (b0, ICMP6_parameter_problem,
- ICMP6_parameter_problem_first_fragment_has_incomplete_header_chain,
- 0);
- b0->error = node->errors[IP6_ERROR_REASS_MISSING_UPPER];
-
- to_next[0] = bi0;
- to_next += 1;
- n_left_to_next -= 1;
- vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
- to_next, n_left_to_next,
- bi0,
- IP6_REASSEMBLY_NEXT_ICMP_ERROR);
- goto next;
+ next0 = IP6_REASSEMBLY_NEXT_ICMP_ERROR;
+ goto skip_reass;
}
}
+ if (!ip6_reass_verify_fragment_multiple_8 (vm, node, b0, frag_hdr)
+ || !ip6_reass_verify_packet_size_lt_64k (vm, node, b0,
+ frag_hdr))
+ {
+ next0 = IP6_REASSEMBLY_NEXT_ICMP_ERROR;
+ goto skip_reass;
+ }
vnet_buffer (b0)->ip.reass.ip6_frag_hdr_offset =
(u8 *) frag_hdr - (u8 *) ip0;
@@ -894,19 +962,15 @@ ip6_reassembly (vlib_main_t * vm, vlib_node_runtime_t * node,
k.frag_id = frag_hdr->identification;
k.proto = ip0->protocol;
k.unused = 0;
- u32 icmp_bi = ~0;
ip6_reass_t *reass =
- ip6_reass_find_or_create (vm, node, rm, &k, &icmp_bi,
+ ip6_reass_find_or_create (vm, node, rm, rt, &k, &icmp_bi,
&vec_timeout);
- u32 error0 = IP6_ERROR_NONE;
if (reass)
{
- ip6_reass_update (vm, node, rm, reass, &bi0, &next0, &error0,
- frag_hdr, &vec_drop_overlap,
- &vec_drop_compress, IP6_REASSEMBLY_NEXT_INPUT,
- IP6_REASSEMBLY_NEXT_DROP,
- IP6_REASSEMBLY_NEXT_ICMP_ERROR);
+ ip6_reass_update (vm, node, rm, rt, reass, &bi0, &next0,
+ &error0, frag_hdr, &vec_drop_overlap,
+ &vec_drop_compress, is_feature);
}
else
{
@@ -918,9 +982,15 @@ ip6_reassembly (vlib_main_t * vm, vlib_node_runtime_t * node,
if (~0 != bi0)
{
+ skip_reass:
to_next[0] = bi0;
to_next += 1;
n_left_to_next -= 1;
+ if (is_feature && IP6_ERROR_NONE == error0)
+ {
+ vnet_feature_next (vnet_buffer (b0)->sw_if_index[VLIB_RX],
+ &next0, b0);
+ }
vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
n_left_to_next, bi0, next0);
}
@@ -935,7 +1005,6 @@ ip6_reassembly (vlib_main_t * vm, vlib_node_runtime_t * node,
n_left_to_next, icmp_bi,
next0);
}
- next:
from += 1;
n_left_from -= 1;
}
@@ -943,6 +1012,7 @@ ip6_reassembly (vlib_main_t * vm, vlib_node_runtime_t * node,
vlib_put_next_frame (vm, node, next_index, n_left_to_next);
}
+ clib_spinlock_unlock (&rt->lock);
return frame->n_vectors;
}
@@ -952,6 +1022,13 @@ static char *ip6_reassembly_error_strings[] = {
#undef _
};
+always_inline uword
+ip6_reassembly (vlib_main_t * vm, vlib_node_runtime_t * node,
+ vlib_frame_t * frame)
+{
+ return ip6_reassembly_inline (vm, node, frame, false /* is_feature */ );
+}
+
/* *INDENT-OFF* */
VLIB_REGISTER_NODE (ip6_reass_node, static) = {
.function = ip6_reassembly,
@@ -970,8 +1047,46 @@ VLIB_REGISTER_NODE (ip6_reass_node, static) = {
};
/* *INDENT-ON* */
-VLIB_NODE_FUNCTION_MULTIARCH (ip6_reass_node, ip6_reassembly)
- static u32 ip6_reass_get_nbuckets ()
+VLIB_NODE_FUNCTION_MULTIARCH (ip6_reass_node, ip6_reassembly);
+
+always_inline uword
+ip6_reassembly_feature (vlib_main_t * vm,
+ vlib_node_runtime_t * node, vlib_frame_t * frame)
+{
+ return ip6_reassembly_inline (vm, node, frame, true /* is_feature */ );
+}
+
+/* *INDENT-OFF* */
+VLIB_REGISTER_NODE (ip6_reass_node_feature, static) = {
+ .function = ip6_reassembly_feature,
+ .name = "ip6-reassembly-feature",
+ .vector_size = sizeof (u32),
+ .format_trace = format_ip6_reass_trace,
+ .n_errors = ARRAY_LEN (ip6_reassembly_error_strings),
+ .error_strings = ip6_reassembly_error_strings,
+ .n_next_nodes = IP6_REASSEMBLY_N_NEXT,
+ .next_nodes =
+ {
+ [IP6_REASSEMBLY_NEXT_INPUT] = "ip6-input",
+ [IP6_REASSEMBLY_NEXT_DROP] = "ip6-drop",
+ [IP6_REASSEMBLY_NEXT_ICMP_ERROR] = "ip6-icmp-error",
+ },
+};
+/* *INDENT-ON* */
+
+VLIB_NODE_FUNCTION_MULTIARCH (ip6_reass_node_feature, ip6_reassembly_feature);
+
+/* *INDENT-OFF* */
+VNET_FEATURE_INIT (ip6_reassembly_feature, static) = {
+ .arc_name = "ip6-unicast",
+ .node_name = "ip6-reassembly-feature",
+ .runs_before = VNET_FEATURES ("ip6-lookup"),
+ .runs_after = 0,
+};
+/* *INDENT-ON* */
+
+static u32
+ip6_reass_get_nbuckets ()
{
ip6_reass_main_t *rm = &ip6_reass_main;
u32 nbuckets;
@@ -998,7 +1113,7 @@ typedef struct
clib_bihash_48_8_t *new_hash;
} ip6_rehash_cb_ctx;
-void
+static void
ip6_rehash_cb (clib_bihash_kv_48_8_t * kv, void *_ctx)
{
ip6_rehash_cb_ctx *ctx = _ctx;
@@ -1008,15 +1123,23 @@ ip6_rehash_cb (clib_bihash_kv_48_8_t * kv, void *_ctx)
}
}
-vnet_api_error_t
-ip6_reass_set (u32 timeout_ms, u32 max_reassemblies,
- u32 expire_walk_interval_ms)
+static void
+ip6_reass_set_params (u32 timeout_ms, u32 max_reassemblies,
+ u32 expire_walk_interval_ms)
{
- u32 old_nbuckets = ip6_reass_get_nbuckets ();
ip6_reass_main.timeout_ms = timeout_ms;
ip6_reass_main.timeout = (f64) timeout_ms / (f64) MSEC_PER_SEC;
ip6_reass_main.max_reass_n = max_reassemblies;
ip6_reass_main.expire_walk_interval_ms = expire_walk_interval_ms;
+}
+
+vnet_api_error_t
+ip6_reass_set (u32 timeout_ms, u32 max_reassemblies,
+ u32 expire_walk_interval_ms)
+{
+ u32 old_nbuckets = ip6_reass_get_nbuckets ();
+ ip6_reass_set_params (timeout_ms, max_reassemblies,
+ expire_walk_interval_ms);
vlib_process_signal_event (ip6_reass_main.vlib_main,
ip6_reass_main.ip6_reass_expire_node_idx,
IP6_EVENT_CONFIG_CHANGED, 0);
@@ -1058,7 +1181,7 @@ ip6_reass_get (u32 * timeout_ms, u32 * max_reassemblies,
return 0;
}
-clib_error_t *
+static clib_error_t *
ip6_reass_init_function (vlib_main_t * vm)
{
ip6_reass_main_t *rm = &ip6_reass_main;
@@ -1069,17 +1192,18 @@ ip6_reass_init_function (vlib_main_t * vm)
rm->vlib_main = vm;
rm->vnet_main = vnet_get_main ();
- rm->reass_n = 0;
- pool_alloc (rm->pool, rm->max_reass_n);
+ vec_validate (rm->per_thread_data, vlib_num_workers () + 1);
+ ip6_reass_per_thread_t *rt;
+ vec_foreach (rt, rm->per_thread_data)
+ {
+ clib_spinlock_init (&rt->lock);
+ pool_alloc (rt->pool, rm->max_reass_n);
+ }
node = vlib_get_node_by_name (vm, (u8 *) "ip6-reassembly-expire-walk");
ASSERT (node);
rm->ip6_reass_expire_node_idx = node->index;
- ip6_reass_set (IP6_REASS_TIMEOUT_DEFAULT_MS,
- IP6_REASS_MAX_REASSEMBLIES_DEAFULT,
- IP6_REASS_EXPIRE_WALK_INTERVAL_DEFAULT_MS);
-
nbuckets = ip6_reass_get_nbuckets ();
clib_bihash_init_48_8 (&rm->hash, "ip6-reass", nbuckets, nbuckets * 1024);
@@ -1094,6 +1218,11 @@ ip6_reass_init_function (vlib_main_t * vm)
return error;
ip6_register_protocol (IP_PROTOCOL_IPV6_FRAGMENTATION,
ip6_reass_node.index);
+
+ ip6_reass_set_params (IP6_REASS_TIMEOUT_DEFAULT_MS,
+ IP6_REASS_MAX_REASSEMBLIES_DEFAULT,
+ IP6_REASS_EXPIRE_WALK_INTERVAL_DEFAULT_MS);
+
return error;
}
@@ -1130,38 +1259,65 @@ ip6_reass_walk_expired (vlib_main_t * vm,
u32 *vec_timeout = NULL;
int *pool_indexes_to_free = NULL;
+ uword thread_index = 0;
int index;
- /* *INDENT-OFF* */
- pool_foreach_index (index, rm->pool, ({
- reass = pool_elt_at_index (rm->pool, index);
- if (now > reass->last_heard + rm->timeout)
- {
- vec_add1 (pool_indexes_to_free, index);
- }
- }));
- /* *INDENT-ON* */
- int *i;
+ const uword nthreads = os_get_nthreads ();
u32 *vec_icmp_bi = NULL;
- /* *INDENT-OFF* */
- vec_foreach (i, pool_indexes_to_free)
- {
- ip6_reass_t *reass = pool_elt_at_index (rm->pool, i[0]);
- u32 icmp_bi = ~0;
- ip6_reass_on_timeout (vm, node, rm, reass, &icmp_bi, &vec_timeout);
- if (~0 != icmp_bi)
+ for (thread_index = 0; thread_index < nthreads; ++thread_index)
+ {
+ ip6_reass_per_thread_t *rt = &rm->per_thread_data[thread_index];
+ clib_spinlock_lock (&rt->lock);
+
+ vec_reset_length (pool_indexes_to_free);
+ /* *INDENT-OFF* */
+ pool_foreach_index (index, rt->pool, ({
+ reass = pool_elt_at_index (rt->pool, index);
+ if (now > reass->last_heard + rm->timeout)
+ {
+ vec_add1 (pool_indexes_to_free, index);
+ }
+ }));
+ /* *INDENT-ON* */
+ int *i;
+ /* *INDENT-OFF* */
+ vec_foreach (i, pool_indexes_to_free)
{
- vec_add1 (vec_icmp_bi, icmp_bi);
+ ip6_reass_t *reass = pool_elt_at_index (rt->pool, i[0]);
+ u32 icmp_bi = ~0;
+ u32 before = vec_len (vec_timeout);
+ vlib_buffer_t *b = vlib_get_buffer (vm, reass->first_bi);
+ if (PREDICT_FALSE (b->flags & VLIB_BUFFER_IS_TRACED))
+ {
+ if (pool_is_free_index (vm->trace_main.trace_buffer_pool,
+ b->trace_index))
+ {
+ /* the trace is gone, don't trace this buffer anymore */
+ b->flags &= ~VLIB_BUFFER_IS_TRACED;
+ }
+ }
+ ip6_reass_on_timeout (vm, node, rm, reass, &icmp_bi, &vec_timeout);
+ u32 after = vec_len (vec_timeout);
+ ASSERT (rt->buffers_n >= (after - before));
+ rt->buffers_n -= (after - before);
+ if (~0 != icmp_bi)
+ {
+ vec_add1 (vec_icmp_bi, icmp_bi);
+ ASSERT (rt->buffers_n > 0);
+ --rt->buffers_n;
+ }
+ ip6_reass_free (rm, rt, reass);
}
- ip6_reass_free (rm, reass);
- }
- /* *INDENT-ON* */
+ /* *INDENT-ON* */
+
+ clib_spinlock_unlock (&rt->lock);
+ }
while (vec_len (vec_timeout) > 0)
{
vlib_frame_t *f = vlib_get_frame_to_node (vm, rm->ip6_drop_idx);
u32 *to_next = vlib_frame_vector_args (f);
u32 n_left_to_next = VLIB_FRAME_SIZE - f->n_vectors;
- u32 n_trace = 0;
+ int trace_frame = 0;
while (vec_len (vec_timeout) > 0 && n_left_to_next > 0)
{
u32 bi = vec_pop (vec_timeout);
@@ -1176,7 +1332,7 @@ ip6_reass_walk_expired (vlib_main_t * vm,
}
else
{
- ++n_trace;
+ trace_frame = 1;
}
}
b->error = node->errors[IP6_ERROR_REASS_TIMEOUT];
@@ -1184,13 +1340,8 @@ ip6_reass_walk_expired (vlib_main_t * vm,
++f->n_vectors;
to_next += 1;
n_left_to_next -= 1;
- ASSERT (rm->buffers_n > 0);
- --rm->buffers_n;
- }
- if (PREDICT_FALSE (n_trace > 0))
- {
- f->flags |= VLIB_FRAME_TRACE;
}
+ f->flags |= (trace_frame * VLIB_FRAME_TRACE);
vlib_put_frame_to_node (vm, rm->ip6_drop_idx, f);
}
@@ -1200,7 +1351,7 @@ ip6_reass_walk_expired (vlib_main_t * vm,
vlib_get_frame_to_node (vm, rm->ip6_icmp_error_idx);
u32 *to_next = vlib_frame_vector_args (f);
u32 n_left_to_next = VLIB_FRAME_SIZE - f->n_vectors;
- u32 n_trace = 0;
+ int trace_frame = 0;
while (vec_len (vec_icmp_bi) > 0 && n_left_to_next > 0)
{
u32 bi = vec_pop (vec_icmp_bi);
@@ -1215,7 +1366,7 @@ ip6_reass_walk_expired (vlib_main_t * vm,
}
else
{
- ++n_trace;
+ trace_frame = 1;
}
}
b->error = node->errors[IP6_ERROR_REASS_TIMEOUT];
@@ -1223,13 +1374,8 @@ ip6_reass_walk_expired (vlib_main_t * vm,
++f->n_vectors;
to_next += 1;
n_left_to_next -= 1;
- ASSERT (rm->buffers_n > 0);
- --rm->buffers_n;
- }
- if (PREDICT_FALSE (n_trace > 0))
- {
- f->flags |= VLIB_FRAME_TRACE;
}
+ f->flags |= (trace_frame * VLIB_FRAME_TRACE);
vlib_put_frame_to_node (vm, rm->ip6_icmp_error_idx, f);
}
@@ -1276,7 +1422,7 @@ format_ip6_reass (u8 * s, va_list * args)
vlib_main_t *vm = va_arg (*args, vlib_main_t *);
ip6_reass_t *reass = va_arg (*args, ip6_reass_t *);
- s = format (s, "ID: %u, key: %U\n first_bi: %u, data_len: %u, "
+ s = format (s, "ID: %lu, key: %U\n first_bi: %u, data_len: %u, "
"last_packet_octet: %u, trace_op_counter: %u\n",
reass->id, format_ip6_reass_key, &reass->key, reass->first_bi,
reass->data_len, reass->last_packet_octet,
@@ -1315,22 +1461,40 @@ show_ip6_reass (vlib_main_t * vm, unformat_input_t * input,
vlib_cli_output (vm, "---------------------");
vlib_cli_output (vm, "IP6 reassembly status");
vlib_cli_output (vm, "---------------------");
+ bool details = false;
if (unformat (input, "details"))
{
- ip6_reass_t *reass;
- /* *INDENT-OFF* */
- pool_foreach (reass, rm->pool, {
- vlib_cli_output (vm, "%U", format_ip6_reass, vm, reass);
- });
- /* *INDENT-ON* */
+ details = true;
+ }
+
+ u32 sum_reass_n = 0;
+ u64 sum_buffers_n = 0;
+ ip6_reass_t *reass;
+ uword thread_index;
+ const uword nthreads = os_get_nthreads ();
+ for (thread_index = 0; thread_index < nthreads; ++thread_index)
+ {
+ ip6_reass_per_thread_t *rt = &rm->per_thread_data[thread_index];
+ clib_spinlock_lock (&rt->lock);
+ if (details)
+ {
+ /* *INDENT-OFF* */
+ pool_foreach (reass, rt->pool, {
+ vlib_cli_output (vm, "%U", format_ip6_reass, vm, reass);
+ });
+ /* *INDENT-ON* */
+ }
+ sum_reass_n += rt->reass_n;
+ sum_buffers_n += rt->buffers_n;
+ clib_spinlock_unlock (&rt->lock);
}
vlib_cli_output (vm, "---------------------");
- vlib_cli_output (vm, "Current IP6 reassemblies count: %lu\n", rm->reass_n);
- vlib_cli_output (vm,
- "Maximum configured concurrent IP6 reassemblies: %lu\n",
- (long unsigned) rm->max_reass_n);
+ vlib_cli_output (vm, "Current IP6 reassemblies count: %lu\n",
+ (long unsigned) sum_reass_n);
+ vlib_cli_output (vm, "Maximum configured concurrent IP6 reassemblies per "
+ "worker-thread: %lu\n", (long unsigned) rm->max_reass_n);
vlib_cli_output (vm, "Buffers in use: %lu\n",
- (long unsigned) rm->buffers_n);
+ (long unsigned) sum_buffers_n);
return 0;
}
@@ -1342,6 +1506,13 @@ VLIB_CLI_COMMAND (show_ip6_reassembly_cmd, static) = {
};
/* *INDENT-ON* */
+vnet_api_error_t
+ip6_reass_enable_disable (u32 sw_if_index, u8 enable_disable)
+{
+ return vnet_feature_enable_disable ("ip6-unicast", "ip6-reassembly-feature",
+ sw_if_index, enable_disable, 0, 0);
+}
+
/*
* fd.io coding-style-patch-verification: ON
*
diff --git a/src/vnet/ip/ip6_reassembly.h b/src/vnet/ip/ip6_reassembly.h
index 0de4e04bb2b..5084edaaf8c 100644
--- a/src/vnet/ip/ip6_reassembly.h
+++ b/src/vnet/ip/ip6_reassembly.h
@@ -38,6 +38,9 @@ vnet_api_error_t ip6_reass_set (u32 timeout_ms, u32 max_reassemblies,
vnet_api_error_t ip6_reass_get (u32 * timeout_ms, u32 * max_reassemblies,
u32 * expire_walk_interval_ms);
+vnet_api_error_t ip6_reass_enable_disable (u32 sw_if_index,
+ u8 enable_disable);
+
#endif /* __included_ip6_reassembly_h */
/*
diff --git a/src/vnet/ip/ip_api.c b/src/vnet/ip/ip_api.c
index 0a055118732..a8dbb3ae36c 100644
--- a/src/vnet/ip/ip_api.c
+++ b/src/vnet/ip/ip_api.c
@@ -103,7 +103,8 @@ _(IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL, \
_(IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL, \
ip_source_and_port_range_check_interface_add_del) \
_(IP_REASSEMBLY_SET, ip_reassembly_set) \
-_(IP_REASSEMBLY_GET, ip_reassembly_get)
+_(IP_REASSEMBLY_GET, ip_reassembly_get) \
+_(IP_REASSEMBLY_ENABLE_DISABLE, ip_reassembly_enable_disable)
extern void stats_dslock_with_hint (int hint, int tag);
extern void stats_dsunlock (void);
@@ -2904,6 +2905,23 @@ vl_api_ip_reassembly_get_t_handler (vl_api_ip_reassembly_get_t * mp)
vl_msg_api_send_shmem (q, (u8 *) & rmp);
}
+void
+ vl_api_ip_reassembly_enable_disable_t_handler
+ (vl_api_ip_reassembly_enable_disable_t * mp)
+{
+ vl_api_ip_reassembly_enable_disable_reply_t *rmp;
+ int rv = 0;
+ rv = ip4_reass_enable_disable (clib_net_to_host_u32 (mp->sw_if_index),
+ mp->enable_ip4);
+ if (0 == rv)
+ {
+ rv = ip6_reass_enable_disable (clib_net_to_host_u32 (mp->sw_if_index),
+ mp->enable_ip6);
+ }
+
+ REPLY_MACRO (VL_API_IP_REASSEMBLY_SET_REPLY);
+}
+
#define vl_msg_name_crc_list
#include <vnet/ip/ip.api.h>
#undef vl_msg_name_crc_list
diff --git a/src/vnet/ip/lookup.c b/src/vnet/ip/lookup.c
index 3bbf2abd8dc..216af4ce371 100644
--- a/src/vnet/ip/lookup.c
+++ b/src/vnet/ip/lookup.c
@@ -230,8 +230,6 @@ ip_lookup_init (ip_lookup_main_t * lm, u32 is_ip6)
}
lm->local_next_by_ip_protocol[IP_PROTOCOL_UDP] = IP_LOCAL_NEXT_UDP_LOOKUP;
- lm->local_next_by_ip_protocol[IP_PROTOCOL_VPP_FRAGMENTATION] =
- IP_LOCAL_NEXT_REASSEMBLY;
lm->local_next_by_ip_protocol[is_ip6 ? IP_PROTOCOL_ICMP6 :
IP_PROTOCOL_ICMP] = IP_LOCAL_NEXT_ICMP;
lm->builtin_protocol_by_ip_protocol[IP_PROTOCOL_UDP] =
diff --git a/src/vnet/ip/lookup.h b/src/vnet/ip/lookup.h
index 9fe7a1b0085..a89546f5d92 100644
--- a/src/vnet/ip/lookup.h
+++ b/src/vnet/ip/lookup.h
@@ -111,7 +111,6 @@ typedef enum
IP_LOCAL_NEXT_PUNT,
IP_LOCAL_NEXT_UDP_LOOKUP,
IP_LOCAL_NEXT_ICMP,
- IP_LOCAL_NEXT_REASSEMBLY,
IP_LOCAL_N_NEXT,
} ip_local_next_t;
diff --git a/test/framework.py b/test/framework.py
index 423feaf7545..2167399b122 100644
--- a/test/framework.py
+++ b/test/framework.py
@@ -377,6 +377,10 @@ class VppTestCase(unittest.TestCase):
try:
cls.vapi.connect()
except:
+ try:
+ cls.vapi.disconnect()
+ except:
+ pass
if cls.debug_gdbserver:
print(colorize("You're running VPP inside gdbserver but "
"VPP-API connection failed, did you forget "
diff --git a/test/sys_req/set_system_parameters.sh b/test/sys_req/set_system_parameters.sh
deleted file mode 100755
index aa23634b435..00000000000
--- a/test/sys_req/set_system_parameters.sh
+++ /dev/null
@@ -1,68 +0,0 @@
-#!/bin/bash
-
-file="$1"
-
-usage(){
- echo "Usage: $0 <requirements file>"
-}
-
-if [ "$file" == "" ]
-then
- echo "Invalid parameters specified."
- usage
- exit 1
-fi
-
-if [ ! -f $file ]
-then
- echo "File '$file' does not exist."
- usage
- exit 1
-fi
-
-if test "$DOCKER_TEST" = "True"
-then
- echo "=============================================================================="
- echo "DOCKER_TEST is set to '$DOCKER_TEST'."
- echo "Skipping verification of some system parameters."
- echo "Make sure these are set properly, otherwise tests might fail."
- echo "Required values/criteria are in '`readlink -e $file`'."
- echo "=============================================================================="
- exit 0
-fi
-
-cat $file | grep -v -e '^#.*$' | grep -v -e '^ *$' | while read line
-do
- value_file=`echo $line | awk '{print $1}'`
- operator=`echo $line | awk '{print $2}'`
- value=`echo $line | awk '{print $3}'`
- set_value=`echo $line | awk '{print $4}'`
- if [[ "$value_file" == "" || "$operator" == "" || "$value" == "" || "$set_value" == "" ]]
- then
- echo "Syntax error in requirements file."
- exit 1
- fi
- current_value=`cat $value_file`
- if test "$current_value" $operator "$value"
- then
- if test "$V" = "2"
- then
- echo "Requirement '$value_file $operator $value' satisfied."
- fi
- else
- echo "Requirement '$value_file $operator $value' not satisfied."
- echo "Writing '$set_value' to '$value_file'."
- echo "$set_value" | tee "$value_file" > /dev/null
- if ! test "`cat $value_file`" = "$set_value"
- then
- echo "Repeating the write using sudo..."
- echo "$set_value" | sudo -n tee "$value_file" > /dev/null
- if ! test "`cat $value_file`" = "$set_value"
- then
- echo "Couldn't set the required value. Is that value allowed? Is sudo working?"
- exit 1
- fi
- fi
- echo "Succesfully wrote '$set_value' to '$value_file'."
- fi
-done
diff --git a/test/sys_req/system_parameters b/test/sys_req/system_parameters
deleted file mode 100644
index 6373774dd94..00000000000
--- a/test/sys_req/system_parameters
+++ /dev/null
@@ -1,18 +0,0 @@
-# test framework system requirements
-# format of this file is
-# <path> <operator> <comparison-value> <set-value>
-#
-# path - path to value e.g. in /proc which needs to be checked
-# operator - test operator (e.g. -gt)
-# comparison-value - value, against which the value read from <path> is compared
-# set-value - value, to which the path is set if the test fails
-#
-# the comparison is done using `test' command
-
-
-# test_reassembly.py
-# needed by test_reassembly which uses udp punt via unix domain sockets
-# to ensure that all data which vpp might produce in a burst fits into
-# the socket send buffer
-/proc/sys/net/core/wmem_max -ge 4636252 4636252
-/proc/sys/net/core/wmem_default -ge 4636252 4636252
diff --git a/test/test_reassembly.py.disabled b/test/test_reassembly.py
index a2d77d493de..531caa46257 100644
--- a/test/test_reassembly.py.disabled
+++ b/test/test_reassembly.py
@@ -8,7 +8,6 @@ from scapy.packet import Raw
from scapy.layers.l2 import Ether, GRE
from scapy.layers.inet import IP, UDP
from util import ppp, fragment_rfc791, fragment_rfc8200
-from vpp_punt_socket import VppUDSPuntSocket
from scapy.layers.inet6 import IPv6, IPv6ExtHdrFragment, ICMPv6ParamProblem,\
ICMPv6TimeExceeded
from vpp_gre_interface import VppGreInterface, VppGre6Interface
@@ -24,8 +23,9 @@ class TestIPv4Reassembly(VppTestCase):
def setUpClass(cls):
super(TestIPv4Reassembly, cls).setUpClass()
- cls.create_pg_interfaces([0])
- cls.pg_if = cls.pg0
+ cls.create_pg_interfaces([0, 1])
+ cls.src_if = cls.pg0
+ cls.dst_if = cls.pg1
# setup all interfaces
for i in cls.pg_interfaces:
@@ -33,9 +33,6 @@ class TestIPv4Reassembly(VppTestCase):
i.config_ip4()
i.resolve_arp()
- cls.punt_port = 9999
- cls.punt_socket = VppUDSPuntSocket(cls, cls.punt_port)
-
# packet sizes
cls.packet_sizes = [64, 512, 1518, 9018]
cls.padding = " abcdefghijklmn"
@@ -45,6 +42,8 @@ class TestIPv4Reassembly(VppTestCase):
def setUp(self):
""" Test setup - force timeout on existing reassemblies """
super(TestIPv4Reassembly, self).setUp()
+ self.vapi.ip_reassembly_enable_disable(
+ sw_if_index=self.src_if.sw_if_index, enable_ip4=True)
self.vapi.ip_reassembly_set(timeout_ms=0, max_reassemblies=1000,
expire_walk_interval_ms=10)
self.sleep(.25)
@@ -62,12 +61,12 @@ class TestIPv4Reassembly(VppTestCase):
:param list packet_sizes: Required packet sizes.
"""
for i in range(0, packet_count):
- info = cls.create_packet_info(cls.pg_if, cls.pg_if)
+ info = cls.create_packet_info(cls.src_if, cls.src_if)
payload = cls.info_to_payload(info)
- p = (Ether(dst=cls.pg_if.local_mac, src=cls.pg_if.remote_mac) /
- IP(id=info.index, src=cls.pg_if.remote_ip4,
- dst=cls.pg_if.local_ip4) /
- UDP(sport=1234, dport=cls.punt_port) /
+ p = (Ether(dst=cls.src_if.local_mac, src=cls.src_if.remote_mac) /
+ IP(id=info.index, src=cls.src_if.remote_ip4,
+ dst=cls.dst_if.remote_ip4) /
+ UDP(sport=1234, dport=5678) /
Raw(payload))
size = packet_sizes[(i // 2) % len(packet_sizes)]
cls.extend_packet(p, size, cls.padding)
@@ -79,7 +78,7 @@ class TestIPv4Reassembly(VppTestCase):
cls.pkt_infos = []
for index, info in infos.iteritems():
p = info.data
- # self.logger.debug(ppp("Packet:", p.__class__(str(p))))
+ # cls.logger.debug(ppp("Packet:", p.__class__(str(p))))
fragments_400 = fragment_rfc791(p, 400)
fragments_300 = fragment_rfc791(p, 300)
fragments_200 = [
@@ -106,11 +105,7 @@ class TestIPv4Reassembly(VppTestCase):
seen = set()
for packet in capture:
try:
- sw_if_index = packet['sw_if_index']
- punt_action = packet['punt_action']
- packet = Ether(packet['packet'])
- self.logger.debug(ppp("Got packet from %s, action %s" %
- (sw_if_index, punt_action), packet))
+ self.logger.debug(ppp("Got packet:", packet))
ip = packet[IP]
udp = packet[UDP]
payload_info = self.payload_to_info(str(packet[Raw]))
@@ -121,7 +116,7 @@ class TestIPv4Reassembly(VppTestCase):
if packet_index in seen:
raise Exception(ppp("Duplicate packet received", packet))
seen.add(packet_index)
- self.assertEqual(payload_info.dst, self.pg_if.sw_if_index)
+ self.assertEqual(payload_info.dst, self.src_if.sw_if_index)
info = self._packet_infos[packet_index]
self.assertTrue(info is not None)
self.assertEqual(packet_index, info.index)
@@ -129,7 +124,7 @@ class TestIPv4Reassembly(VppTestCase):
self.assertEqual(ip.src, saved_packet[IP].src)
self.assertEqual(ip.dst, saved_packet[IP].dst)
self.assertEqual(udp.payload, saved_packet[UDP].payload)
- except:
+ except Exception:
self.logger.error(ppp("Unexpected or invalid packet:", packet))
raise
for index in self._packet_infos:
@@ -140,21 +135,21 @@ class TestIPv4Reassembly(VppTestCase):
""" basic reassembly """
self.pg_enable_capture()
- self.pg_if.add_stream(self.fragments_200)
+ self.src_if.add_stream(self.fragments_200)
self.pg_start()
- packets = self.punt_socket.wait_for_packets(len(self.pkt_infos))
+ packets = self.dst_if.get_capture(len(self.pkt_infos))
self.verify_capture(packets)
- self.pg_if.assert_nothing_captured()
+ self.src_if.assert_nothing_captured()
# run it all again to verify correctness
self.pg_enable_capture()
- self.pg_if.add_stream(self.fragments_200)
+ self.src_if.add_stream(self.fragments_200)
self.pg_start()
- packets = self.punt_socket.wait_for_packets(len(self.pkt_infos))
+ packets = self.dst_if.get_capture(len(self.pkt_infos))
self.verify_capture(packets)
- self.pg_if.assert_nothing_captured()
+ self.src_if.assert_nothing_captured()
def test_reversed(self):
""" reverse order reassembly """
@@ -163,21 +158,21 @@ class TestIPv4Reassembly(VppTestCase):
fragments.reverse()
self.pg_enable_capture()
- self.pg_if.add_stream(fragments)
+ self.src_if.add_stream(fragments)
self.pg_start()
- packets = self.punt_socket.wait_for_packets(len(self.packet_infos))
+ packets = self.dst_if.get_capture(len(self.packet_infos))
self.verify_capture(packets)
- self.pg_if.assert_nothing_captured()
+ self.src_if.assert_nothing_captured()
# run it all again to verify correctness
self.pg_enable_capture()
- self.pg_if.add_stream(fragments)
+ self.src_if.add_stream(fragments)
self.pg_start()
- packets = self.punt_socket.wait_for_packets(len(self.packet_infos))
+ packets = self.dst_if.get_capture(len(self.packet_infos))
self.verify_capture(packets)
- self.pg_if.assert_nothing_captured()
+ self.src_if.assert_nothing_captured()
def test_random(self):
""" random order reassembly """
@@ -186,21 +181,21 @@ class TestIPv4Reassembly(VppTestCase):
shuffle(fragments)
self.pg_enable_capture()
- self.pg_if.add_stream(fragments)
+ self.src_if.add_stream(fragments)
self.pg_start()
- packets = self.punt_socket.wait_for_packets(len(self.packet_infos))
+ packets = self.dst_if.get_capture(len(self.packet_infos))
self.verify_capture(packets)
- self.pg_if.assert_nothing_captured()
+ self.src_if.assert_nothing_captured()
# run it all again to verify correctness
self.pg_enable_capture()
- self.pg_if.add_stream(fragments)
+ self.src_if.add_stream(fragments)
self.pg_start()
- packets = self.punt_socket.wait_for_packets(len(self.packet_infos))
+ packets = self.dst_if.get_capture(len(self.packet_infos))
self.verify_capture(packets)
- self.pg_if.assert_nothing_captured()
+ self.src_if.assert_nothing_captured()
def test_duplicates(self):
""" duplicate fragments """
@@ -212,12 +207,12 @@ class TestIPv4Reassembly(VppTestCase):
]
self.pg_enable_capture()
- self.pg_if.add_stream(fragments)
+ self.src_if.add_stream(fragments)
self.pg_start()
- packets = self.punt_socket.wait_for_packets(len(self.pkt_infos))
+ packets = self.dst_if.get_capture(len(self.pkt_infos))
self.verify_capture(packets)
- self.pg_if.assert_nothing_captured()
+ self.src_if.assert_nothing_captured()
def test_overlap1(self):
""" overlapping fragments case #1 """
@@ -232,21 +227,21 @@ class TestIPv4Reassembly(VppTestCase):
fragments.extend(j)
self.pg_enable_capture()
- self.pg_if.add_stream(fragments)
+ self.src_if.add_stream(fragments)
self.pg_start()
- packets = self.punt_socket.wait_for_packets(len(self.pkt_infos))
+ packets = self.dst_if.get_capture(len(self.pkt_infos))
self.verify_capture(packets)
- self.pg_if.assert_nothing_captured()
+ self.src_if.assert_nothing_captured()
# run it all to verify correctness
self.pg_enable_capture()
- self.pg_if.add_stream(fragments)
+ self.src_if.add_stream(fragments)
self.pg_start()
- packets = self.punt_socket.wait_for_packets(len(self.pkt_infos))
+ packets = self.dst_if.get_capture(len(self.pkt_infos))
self.verify_capture(packets)
- self.pg_if.assert_nothing_captured()
+ self.src_if.assert_nothing_captured()
def test_overlap2(self):
""" overlapping fragments case #2 """
@@ -267,21 +262,21 @@ class TestIPv4Reassembly(VppTestCase):
fragments.append(zipped[-1][0])
self.pg_enable_capture()
- self.pg_if.add_stream(fragments)
+ self.src_if.add_stream(fragments)
self.pg_start()
- packets = self.punt_socket.wait_for_packets(len(self.pkt_infos))
+ packets = self.dst_if.get_capture(len(self.pkt_infos))
self.verify_capture(packets)
- self.pg_if.assert_nothing_captured()
+ self.src_if.assert_nothing_captured()
# run it all to verify correctness
self.pg_enable_capture()
- self.pg_if.add_stream(fragments)
+ self.src_if.add_stream(fragments)
self.pg_start()
- packets = self.punt_socket.wait_for_packets(len(self.pkt_infos))
+ packets = self.dst_if.get_capture(len(self.pkt_infos))
self.verify_capture(packets)
- self.pg_if.assert_nothing_captured()
+ self.src_if.assert_nothing_captured()
def test_timeout_inline(self):
""" timeout (inline) """
@@ -294,13 +289,13 @@ class TestIPv4Reassembly(VppTestCase):
expire_walk_interval_ms=10000)
self.pg_enable_capture()
- self.pg_if.add_stream(self.fragments_400)
+ self.src_if.add_stream(self.fragments_400)
self.pg_start()
- packets = self.punt_socket.wait_for_packets(
+ packets = self.dst_if.get_capture(
len(self.pkt_infos) - len(dropped_packet_indexes))
self.verify_capture(packets, dropped_packet_indexes)
- self.pg_if.assert_nothing_captured()
+ self.src_if.assert_nothing_captured()
def test_timeout_cleanup(self):
""" timeout (cleanup) """
@@ -324,19 +319,18 @@ class TestIPv4Reassembly(VppTestCase):
expire_walk_interval_ms=50)
self.pg_enable_capture()
- self.pg_if.add_stream(fragments)
+ self.src_if.add_stream(fragments)
self.pg_start()
self.sleep(.25, "wait before sending rest of fragments")
- self.pg_if.add_stream(fragments2)
+ self.src_if.add_stream(fragments2)
self.pg_start()
- self.sleep(.25, "wait for vpp to process packets")
- packets = self.punt_socket.wait_for_packets(
+ packets = self.dst_if.get_capture(
len(self.pkt_infos) - len(dropped_packet_indexes))
self.verify_capture(packets, dropped_packet_indexes)
- self.pg_if.assert_nothing_captured()
+ self.src_if.assert_nothing_captured()
def test_disabled(self):
""" reassembly disabled """
@@ -349,13 +343,13 @@ class TestIPv4Reassembly(VppTestCase):
expire_walk_interval_ms=10000)
self.pg_enable_capture()
- self.pg_if.add_stream(self.fragments_400)
+ self.src_if.add_stream(self.fragments_400)
self.pg_start()
- packets = self.punt_socket.wait_for_packets(
+ packets = self.dst_if.get_capture(
len(self.pkt_infos) - len(dropped_packet_indexes))
self.verify_capture(packets, dropped_packet_indexes)
- self.pg_if.assert_nothing_captured()
+ self.src_if.assert_nothing_captured()
class TestIPv6Reassembly(VppTestCase):
@@ -365,8 +359,9 @@ class TestIPv6Reassembly(VppTestCase):
def setUpClass(cls):
super(TestIPv6Reassembly, cls).setUpClass()
- cls.create_pg_interfaces([0])
- cls.pg_if = cls.pg0
+ cls.create_pg_interfaces([0, 1])
+ cls.src_if = cls.pg0
+ cls.dst_if = cls.pg1
# setup all interfaces
for i in cls.pg_interfaces:
@@ -374,9 +369,6 @@ class TestIPv6Reassembly(VppTestCase):
i.config_ip6()
i.resolve_ndp()
- cls.punt_port = 9999
- cls.punt_socket = VppUDSPuntSocket(cls, cls.punt_port, is_ip4=0)
-
# packet sizes
cls.packet_sizes = [64, 512, 1518, 9018]
cls.padding = " abcdefghijklmn"
@@ -386,11 +378,14 @@ class TestIPv6Reassembly(VppTestCase):
def setUp(self):
""" Test setup - force timeout on existing reassemblies """
super(TestIPv6Reassembly, self).setUp()
+ self.vapi.ip_reassembly_enable_disable(
+ sw_if_index=self.src_if.sw_if_index, enable_ip6=True)
self.vapi.ip_reassembly_set(timeout_ms=0, max_reassemblies=1000,
expire_walk_interval_ms=10, is_ip6=1)
self.sleep(.25)
self.vapi.ip_reassembly_set(timeout_ms=1000000, max_reassemblies=1000,
expire_walk_interval_ms=10000, is_ip6=1)
+ self.logger.debug(self.vapi.ppcli("show ip6-reassembly details"))
def tearDown(self):
super(TestIPv6Reassembly, self).tearDown()
@@ -403,12 +398,12 @@ class TestIPv6Reassembly(VppTestCase):
:param list packet_sizes: Required packet sizes.
"""
for i in range(0, packet_count):
- info = cls.create_packet_info(cls.pg_if, cls.pg_if)
+ info = cls.create_packet_info(cls.src_if, cls.src_if)
payload = cls.info_to_payload(info)
- p = (Ether(dst=cls.pg_if.local_mac, src=cls.pg_if.remote_mac) /
- IPv6(src=cls.pg_if.remote_ip6,
- dst=cls.pg_if.local_ip6) /
- UDP(sport=1234, dport=cls.punt_port) /
+ p = (Ether(dst=cls.src_if.local_mac, src=cls.src_if.remote_mac) /
+ IPv6(src=cls.src_if.remote_ip6,
+ dst=cls.dst_if.remote_ip6) /
+ UDP(sport=1234, dport=5678) /
Raw(payload))
size = packet_sizes[(i // 2) % len(packet_sizes)]
cls.extend_packet(p, size, cls.padding)
@@ -420,7 +415,7 @@ class TestIPv6Reassembly(VppTestCase):
cls.pkt_infos = []
for index, info in infos.iteritems():
p = info.data
- # self.logger.debug(ppp("Packet:", p.__class__(str(p))))
+ # cls.logger.debug(ppp("Packet:", p.__class__(str(p))))
fragments_400 = fragment_rfc8200(p, info.index, 400)
fragments_300 = fragment_rfc8200(p, info.index, 300)
cls.pkt_infos.append((index, fragments_400, fragments_300))
@@ -442,11 +437,7 @@ class TestIPv6Reassembly(VppTestCase):
seen = set()
for packet in capture:
try:
- sw_if_index = packet['sw_if_index']
- punt_action = packet['punt_action']
- packet = Ether(packet['packet'])
- self.logger.debug(ppp("Got packet from %s, action %s" %
- (sw_if_index, punt_action), packet))
+ self.logger.debug(ppp("Got packet:", packet))
ip = packet[IPv6]
udp = packet[UDP]
payload_info = self.payload_to_info(str(packet[Raw]))
@@ -457,7 +448,7 @@ class TestIPv6Reassembly(VppTestCase):
if packet_index in seen:
raise Exception(ppp("Duplicate packet received", packet))
seen.add(packet_index)
- self.assertEqual(payload_info.dst, self.pg_if.sw_if_index)
+ self.assertEqual(payload_info.dst, self.src_if.sw_if_index)
info = self._packet_infos[packet_index]
self.assertTrue(info is not None)
self.assertEqual(packet_index, info.index)
@@ -465,7 +456,7 @@ class TestIPv6Reassembly(VppTestCase):
self.assertEqual(ip.src, saved_packet[IPv6].src)
self.assertEqual(ip.dst, saved_packet[IPv6].dst)
self.assertEqual(udp.payload, saved_packet[UDP].payload)
- except:
+ except Exception:
self.logger.error(ppp("Unexpected or invalid packet:", packet))
raise
for index in self._packet_infos:
@@ -476,21 +467,21 @@ class TestIPv6Reassembly(VppTestCase):
""" basic reassembly """
self.pg_enable_capture()
- self.pg_if.add_stream(self.fragments_400)
+ self.src_if.add_stream(self.fragments_400)
self.pg_start()
- packets = self.punt_socket.wait_for_packets(len(self.pkt_infos))
+ packets = self.dst_if.get_capture(len(self.pkt_infos))
self.verify_capture(packets)
- self.pg_if.assert_nothing_captured()
+ self.src_if.assert_nothing_captured()
# run it all again to verify correctness
self.pg_enable_capture()
- self.pg_if.add_stream(self.fragments_400)
+ self.src_if.add_stream(self.fragments_400)
self.pg_start()
- packets = self.punt_socket.wait_for_packets(len(self.pkt_infos))
+ packets = self.dst_if.get_capture(len(self.pkt_infos))
self.verify_capture(packets)
- self.pg_if.assert_nothing_captured()
+ self.src_if.assert_nothing_captured()
def test_reversed(self):
""" reverse order reassembly """
@@ -499,21 +490,21 @@ class TestIPv6Reassembly(VppTestCase):
fragments.reverse()
self.pg_enable_capture()
- self.pg_if.add_stream(fragments)
+ self.src_if.add_stream(fragments)
self.pg_start()
- packets = self.punt_socket.wait_for_packets(len(self.pkt_infos))
+ packets = self.dst_if.get_capture(len(self.pkt_infos))
self.verify_capture(packets)
- self.pg_if.assert_nothing_captured()
+ self.src_if.assert_nothing_captured()
# run it all again to verify correctness
self.pg_enable_capture()
- self.pg_if.add_stream(fragments)
+ self.src_if.add_stream(fragments)
self.pg_start()
- packets = self.punt_socket.wait_for_packets(len(self.pkt_infos))
+ packets = self.dst_if.get_capture(len(self.pkt_infos))
self.verify_capture(packets)
- self.pg_if.assert_nothing_captured()
+ self.src_if.assert_nothing_captured()
def test_random(self):
""" random order reassembly """
@@ -522,21 +513,21 @@ class TestIPv6Reassembly(VppTestCase):
shuffle(fragments)
self.pg_enable_capture()
- self.pg_if.add_stream(fragments)
+ self.src_if.add_stream(fragments)
self.pg_start()
- packets = self.punt_socket.wait_for_packets(len(self.pkt_infos))
+ packets = self.dst_if.get_capture(len(self.pkt_infos))
self.verify_capture(packets)
- self.pg_if.assert_nothing_captured()
+ self.src_if.assert_nothing_captured()
# run it all again to verify correctness
self.pg_enable_capture()
- self.pg_if.add_stream(fragments)
+ self.src_if.add_stream(fragments)
self.pg_start()
- packets = self.punt_socket.wait_for_packets(len(self.pkt_infos))
+ packets = self.dst_if.get_capture(len(self.pkt_infos))
self.verify_capture(packets)
- self.pg_if.assert_nothing_captured()
+ self.src_if.assert_nothing_captured()
def test_duplicates(self):
""" duplicate fragments """
@@ -548,12 +539,12 @@ class TestIPv6Reassembly(VppTestCase):
]
self.pg_enable_capture()
- self.pg_if.add_stream(fragments)
+ self.src_if.add_stream(fragments)
self.pg_start()
- packets = self.punt_socket.wait_for_packets(len(self.pkt_infos))
+ packets = self.dst_if.get_capture(len(self.pkt_infos))
self.verify_capture(packets)
- self.pg_if.assert_nothing_captured()
+ self.src_if.assert_nothing_captured()
def test_overlap1(self):
""" overlapping fragments case #1 """
@@ -572,20 +563,19 @@ class TestIPv6Reassembly(VppTestCase):
)
self.pg_enable_capture()
- self.pg_if.add_stream(fragments)
+ self.src_if.add_stream(fragments)
self.pg_start()
- self.sleep(.1, "wait for vpp to process packets")
- packets = self.punt_socket.wait_for_packets(
+ packets = self.dst_if.get_capture(
len(self.pkt_infos) - len(dropped_packet_indexes))
self.verify_capture(packets, dropped_packet_indexes)
- self.pg_if.assert_nothing_captured()
+ self.src_if.assert_nothing_captured()
def test_overlap2(self):
""" overlapping fragments case #2 """
fragments = []
- for _, frags_400, frags_30 in self.pkt_infos:
+ for _, frags_400, frags_300 in self.pkt_infos:
if len(frags_400) == 1:
fragments.extend(frags_400)
else:
@@ -593,7 +583,7 @@ class TestIPv6Reassembly(VppTestCase):
# received by vpp after reassembly is finished, otherwise
# new reassemblies will be started and packet generator will
# freak out when it detects unfreed buffers
- zipped = zip(frags_400, frags_30)
+ zipped = zip(frags_400, frags_300)
for i, j in zipped[:-1]:
fragments.extend(i)
fragments.extend(j)
@@ -604,14 +594,13 @@ class TestIPv6Reassembly(VppTestCase):
)
self.pg_enable_capture()
- self.pg_if.add_stream(fragments)
+ self.src_if.add_stream(fragments)
self.pg_start()
- self.sleep(.1, "wait for vpp to process packets")
- packets = self.punt_socket.wait_for_packets(
+ packets = self.dst_if.get_capture(
len(self.pkt_infos) - len(dropped_packet_indexes))
self.verify_capture(packets, dropped_packet_indexes)
- self.pg_if.assert_nothing_captured()
+ self.src_if.assert_nothing_captured()
def test_timeout_inline(self):
""" timeout (inline) """
@@ -624,13 +613,13 @@ class TestIPv6Reassembly(VppTestCase):
expire_walk_interval_ms=10000, is_ip6=1)
self.pg_enable_capture()
- self.pg_if.add_stream(self.fragments_400)
+ self.src_if.add_stream(self.fragments_400)
self.pg_start()
- packets = self.punt_socket.wait_for_packets(
+ packets = self.dst_if.get_capture(
len(self.pkt_infos) - len(dropped_packet_indexes))
self.verify_capture(packets, dropped_packet_indexes)
- pkts = self.pg_if.get_capture(
+ pkts = self.src_if.get_capture(
expected_count=len(dropped_packet_indexes))
for icmp in pkts:
self.assertIn(ICMPv6TimeExceeded, icmp)
@@ -663,19 +652,18 @@ class TestIPv6Reassembly(VppTestCase):
expire_walk_interval_ms=50, is_ip6=1)
self.pg_enable_capture()
- self.pg_if.add_stream(fragments)
+ self.src_if.add_stream(fragments)
self.pg_start()
self.sleep(.25, "wait before sending rest of fragments")
- self.pg_if.add_stream(fragments2)
+ self.src_if.add_stream(fragments2)
self.pg_start()
- self.sleep(.25, "wait for vpp to process packets")
- packets = self.punt_socket.wait_for_packets(
+ packets = self.dst_if.get_capture(
len(self.pkt_infos) - len(dropped_packet_indexes))
self.verify_capture(packets, dropped_packet_indexes)
- pkts = self.pg_if.get_capture(
+ pkts = self.src_if.get_capture(
expected_count=len(dropped_packet_indexes))
for icmp in pkts:
self.assertIn(ICMPv6TimeExceeded, icmp)
@@ -694,20 +682,20 @@ class TestIPv6Reassembly(VppTestCase):
expire_walk_interval_ms=10000, is_ip6=1)
self.pg_enable_capture()
- self.pg_if.add_stream(self.fragments_400)
+ self.src_if.add_stream(self.fragments_400)
self.pg_start()
- packets = self.punt_socket.wait_for_packets(
+ packets = self.dst_if.get_capture(
len(self.pkt_infos) - len(dropped_packet_indexes))
self.verify_capture(packets, dropped_packet_indexes)
- self.pg_if.assert_nothing_captured()
+ self.src_if.assert_nothing_captured()
def test_missing_upper(self):
""" missing upper layer """
- p = (Ether(dst=self.pg_if.local_mac, src=self.pg_if.remote_mac) /
- IPv6(src=self.pg_if.remote_ip6,
- dst=self.pg_if.local_ip6) /
- UDP(sport=1234, dport=self.punt_port) /
+ p = (Ether(dst=self.src_if.local_mac, src=self.src_if.remote_mac) /
+ IPv6(src=self.src_if.remote_ip6,
+ dst=self.src_if.local_ip6) /
+ UDP(sport=1234, dport=5678) /
Raw())
self.extend_packet(p, 1000, self.padding)
fragments = fragment_rfc8200(p, 1, 500)
@@ -715,52 +703,53 @@ class TestIPv6Reassembly(VppTestCase):
bad_fragment[IPv6ExtHdrFragment].nh = 59
bad_fragment[IPv6ExtHdrFragment].offset = 0
self.pg_enable_capture()
- self.pg_if.add_stream([bad_fragment])
+ self.src_if.add_stream([bad_fragment])
self.pg_start()
- pkts = self.pg_if.get_capture(expected_count=1)
+ pkts = self.src_if.get_capture(expected_count=1)
icmp = pkts[0]
self.assertIn(ICMPv6ParamProblem, icmp)
self.assert_equal(icmp[ICMPv6ParamProblem].code, 3, "ICMP code")
def test_invalid_frag_size(self):
""" fragment size not a multiple of 8 """
- p = (Ether(dst=self.pg_if.local_mac, src=self.pg_if.remote_mac) /
- IPv6(src=self.pg_if.remote_ip6,
- dst=self.pg_if.local_ip6) /
- UDP(sport=1234, dport=self.punt_port) /
+ p = (Ether(dst=self.src_if.local_mac, src=self.src_if.remote_mac) /
+ IPv6(src=self.src_if.remote_ip6,
+ dst=self.src_if.local_ip6) /
+ UDP(sport=1234, dport=5678) /
Raw())
self.extend_packet(p, 1000, self.padding)
fragments = fragment_rfc8200(p, 1, 500)
bad_fragment = fragments[0]
self.extend_packet(bad_fragment, len(bad_fragment) + 5)
self.pg_enable_capture()
- self.pg_if.add_stream([bad_fragment])
+ self.src_if.add_stream([bad_fragment])
self.pg_start()
- pkts = self.pg_if.get_capture(expected_count=1)
+ pkts = self.src_if.get_capture(expected_count=1)
icmp = pkts[0]
self.assertIn(ICMPv6ParamProblem, icmp)
self.assert_equal(icmp[ICMPv6ParamProblem].code, 0, "ICMP code")
def test_invalid_packet_size(self):
""" total packet size > 65535 """
- p = (Ether(dst=self.pg_if.local_mac, src=self.pg_if.remote_mac) /
- IPv6(src=self.pg_if.remote_ip6,
- dst=self.pg_if.local_ip6) /
- UDP(sport=1234, dport=self.punt_port) /
+ p = (Ether(dst=self.src_if.local_mac, src=self.src_if.remote_mac) /
+ IPv6(src=self.src_if.remote_ip6,
+ dst=self.src_if.local_ip6) /
+ UDP(sport=1234, dport=5678) /
Raw())
self.extend_packet(p, 1000, self.padding)
fragments = fragment_rfc8200(p, 1, 500)
bad_fragment = fragments[1]
bad_fragment[IPv6ExtHdrFragment].offset = 65500
self.pg_enable_capture()
- self.pg_if.add_stream([bad_fragment])
+ self.src_if.add_stream([bad_fragment])
self.pg_start()
- pkts = self.pg_if.get_capture(expected_count=1)
+ pkts = self.src_if.get_capture(expected_count=1)
icmp = pkts[0]
self.assertIn(ICMPv6ParamProblem, icmp)
self.assert_equal(icmp[ICMPv6ParamProblem].code, 0, "ICMP code")
+@unittest.skip("removing GRE tunnels broken, need fix")
class TestFIFReassembly(VppTestCase):
""" Fragments in fragments reassembly """
@@ -768,23 +757,28 @@ class TestFIFReassembly(VppTestCase):
def setUpClass(cls):
super(TestFIFReassembly, cls).setUpClass()
- cls.create_pg_interfaces([0])
- cls.pg_if = cls.pg0
- cls.pg_if.admin_up()
- cls.pg_if.config_ip4()
- cls.pg_if.resolve_arp()
- cls.pg_if.config_ip6()
- cls.pg_if.resolve_ndp()
-
- cls.punt_port = 9999
- cls.punt4_socket = VppUDSPuntSocket(cls, cls.punt_port)
- cls.punt6_socket = VppUDSPuntSocket(cls, cls.punt_port, is_ip4=0)
+ cls.create_pg_interfaces([0, 1])
+ cls.src_if = cls.pg0
+ cls.dst_if = cls.pg1
+ for i in cls.pg_interfaces:
+ i.admin_up()
+ i.config_ip4()
+ i.resolve_arp()
+ i.config_ip6()
+ i.resolve_ndp()
+
cls.packet_sizes = [64, 512, 1518, 9018]
cls.padding = " abcdefghijklmn"
def setUp(self):
""" Test setup - force timeout on existing reassemblies """
super(TestFIFReassembly, self).setUp()
+ self.vapi.ip_reassembly_enable_disable(
+ sw_if_index=self.src_if.sw_if_index, enable_ip4=True,
+ enable_ip6=True)
+ self.vapi.ip_reassembly_enable_disable(
+ sw_if_index=self.dst_if.sw_if_index, enable_ip4=True,
+ enable_ip6=True)
self.vapi.ip_reassembly_set(timeout_ms=0, max_reassemblies=1000,
expire_walk_interval_ms=10)
self.vapi.ip_reassembly_set(timeout_ms=0, max_reassemblies=1000,
@@ -809,11 +803,7 @@ class TestFIFReassembly(VppTestCase):
seen = set()
for packet in capture:
try:
- sw_if_index = packet['sw_if_index']
- punt_action = packet['punt_action']
- packet = Ether(packet['packet'])
- self.logger.debug(ppp("Got packet from %s, action %s" %
- (sw_if_index, punt_action), packet))
+ self.logger.debug(ppp("Got packet:", packet))
ip = packet[ip_class]
udp = packet[UDP]
payload_info = self.payload_to_info(str(packet[Raw]))
@@ -824,7 +814,7 @@ class TestFIFReassembly(VppTestCase):
if packet_index in seen:
raise Exception(ppp("Duplicate packet received", packet))
seen.add(packet_index)
- self.assertEqual(payload_info.dst, self.pg_if.sw_if_index)
+ self.assertEqual(payload_info.dst, self.dst_if.sw_if_index)
info = self._packet_infos[packet_index]
self.assertTrue(info is not None)
self.assertEqual(packet_index, info.index)
@@ -832,7 +822,7 @@ class TestFIFReassembly(VppTestCase):
self.assertEqual(ip.src, saved_packet[ip_class].src)
self.assertEqual(ip.dst, saved_packet[ip_class].dst)
self.assertEqual(udp.payload, saved_packet[UDP].payload)
- except:
+ except Exception:
self.logger.error(ppp("Unexpected or invalid packet:", packet))
raise
for index in self._packet_infos:
@@ -848,33 +838,41 @@ class TestFIFReassembly(VppTestCase):
# it shared for multiple test cases
self.tun_ip4 = "1.1.1.2"
- self.gre4 = VppGreInterface(self, self.pg0.local_ip4, self.tun_ip4)
+ self.gre4 = VppGreInterface(self, self.src_if.local_ip4, self.tun_ip4)
self.gre4.add_vpp_config()
self.gre4.admin_up()
self.gre4.config_ip4()
+ self.vapi.ip_reassembly_enable_disable(
+ sw_if_index=self.gre4.sw_if_index, enable_ip4=True)
+
self.route4 = VppIpRoute(self, self.tun_ip4, 32,
- [VppRoutePath(self.pg0.remote_ip4,
- self.pg0.sw_if_index)])
+ [VppRoutePath(self.src_if.remote_ip4,
+ self.src_if.sw_if_index)])
self.route4.add_vpp_config()
self.reset_packet_infos()
for i in range(test_packet_count):
- info = self.create_packet_info(self.pg0, self.pg0)
+ info = self.create_packet_info(self.src_if, self.dst_if)
payload = self.info_to_payload(info)
- p = (IP(id=i, src=self.pg0.remote_ip4, dst=self.pg0.local_ip4) /
- UDP(sport=1234, dport=self.punt_port) /
+ # Ethernet header here is only for size calculation, thus it
+ # doesn't matter how it's initialized. This is to ensure that
+ # reassembled packet is not > 9000 bytes, so that it's not dropped
+ p = (Ether() /
+ IP(id=i, src=self.src_if.remote_ip4,
+ dst=self.dst_if.remote_ip4) /
+ UDP(sport=1234, dport=5678) /
Raw(payload))
size = self.packet_sizes[(i // 2) % len(self.packet_sizes)]
self.extend_packet(p, size, self.padding)
- info.data = p
+ info.data = p[IP] # use only IP part, without ethernet header
fragments = [x for _, p in self._packet_infos.iteritems()
for x in fragment_rfc791(p.data, 400)]
encapped_fragments = \
- [Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
- IP(src=self.tun_ip4, dst=self.pg0.local_ip4) /
+ [Ether(dst=self.src_if.local_mac, src=self.src_if.remote_mac) /
+ IP(src=self.tun_ip4, dst=self.src_if.local_ip4) /
GRE() /
p
for p in fragments]
@@ -883,18 +881,19 @@ class TestFIFReassembly(VppTestCase):
[x for p in encapped_fragments
for x in fragment_rfc791(p, 200)]
- self.pg0.add_stream(fragmented_encapped_fragments)
+ self.src_if.add_stream(fragmented_encapped_fragments)
self.pg_enable_capture(self.pg_interfaces)
self.pg_start()
- self.pg0.assert_nothing_captured()
- packets = self.punt4_socket.wait_for_packets(len(self._packet_infos))
+ self.src_if.assert_nothing_captured()
+ packets = self.dst_if.get_capture(len(self._packet_infos))
self.verify_capture(packets, IP)
# TODO remove gre vpp config by hand until VppIpRoute gets fixed
# so that it's query_vpp_config() works as it should
self.gre4.remove_vpp_config()
+ self.logger.debug(self.vapi.ppcli("show interface"))
def test_fif6(self):
""" Fragments in fragments (6o6) """
@@ -904,36 +903,43 @@ class TestFIFReassembly(VppTestCase):
# it shared for multiple test cases
self.tun_ip6 = "1002::1"
- self.gre6 = VppGre6Interface(self, self.pg0.local_ip6, self.tun_ip6)
+ self.gre6 = VppGre6Interface(self, self.src_if.local_ip6, self.tun_ip6)
self.gre6.add_vpp_config()
self.gre6.admin_up()
self.gre6.config_ip6()
+ self.vapi.ip_reassembly_enable_disable(
+ sw_if_index=self.gre6.sw_if_index, enable_ip6=True)
+
self.route6 = VppIpRoute(self, self.tun_ip6, 128,
- [VppRoutePath(self.pg0.remote_ip6,
- self.pg0.sw_if_index,
+ [VppRoutePath(self.src_if.remote_ip6,
+ self.src_if.sw_if_index,
proto=DpoProto.DPO_PROTO_IP6)],
is_ip6=1)
self.route6.add_vpp_config()
self.reset_packet_infos()
for i in range(test_packet_count):
- info = self.create_packet_info(self.pg0, self.pg0)
+ info = self.create_packet_info(self.src_if, self.dst_if)
payload = self.info_to_payload(info)
- p = (IPv6(src=self.pg0.remote_ip6, dst=self.pg0.local_ip6) /
- UDP(sport=1234, dport=self.punt_port) /
+ # Ethernet header here is only for size calculation, thus it
+ # doesn't matter how it's initialized. This is to ensure that
+ # reassembled packet is not > 9000 bytes, so that it's not dropped
+ p = (Ether() /
+ IPv6(src=self.src_if.remote_ip6, dst=self.dst_if.remote_ip6) /
+ UDP(sport=1234, dport=5678) /
Raw(payload))
size = self.packet_sizes[(i // 2) % len(self.packet_sizes)]
self.extend_packet(p, size, self.padding)
- info.data = p
+ info.data = p[IPv6] # use only IPv6 part, without ethernet header
fragments = [x for _, i in self._packet_infos.iteritems()
for x in fragment_rfc8200(
i.data, i.index, 400)]
encapped_fragments = \
- [Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
- IPv6(src=self.tun_ip6, dst=self.pg0.local_ip6) /
+ [Ether(dst=self.src_if.local_mac, src=self.src_if.remote_mac) /
+ IPv6(src=self.tun_ip6, dst=self.src_if.local_ip6) /
GRE() /
p
for p in fragments]
@@ -948,18 +954,18 @@ class TestFIFReassembly(VppTestCase):
)
]
- self.pg0.add_stream(fragmented_encapped_fragments)
+ self.src_if.add_stream(fragmented_encapped_fragments)
self.pg_enable_capture(self.pg_interfaces)
self.pg_start()
- self.pg0.assert_nothing_captured()
- packets = self.punt6_socket.wait_for_packets(len(self._packet_infos))
+ self.src_if.assert_nothing_captured()
+ packets = self.dst_if.get_capture(len(self._packet_infos))
self.verify_capture(packets, IPv6)
# TODO remove gre vpp config by hand until VppIpRoute gets fixed
# so that it's query_vpp_config() works as it should
- self.gre6.remove_vpp_config()
+ # self.gre6.remove_vpp_config()
if __name__ == '__main__':
diff --git a/test/vpp_papi_provider.py b/test/vpp_papi_provider.py
index dd553cb473e..52fc3641672 100644
--- a/test/vpp_papi_provider.py
+++ b/test/vpp_papi_provider.py
@@ -3203,6 +3203,15 @@ class VppPapiProvider(object):
""" Get IP reassembly parameters """
return self.api(self.papi.ip_reassembly_get, {'is_ip6': is_ip6})
+ def ip_reassembly_enable_disable(self, sw_if_index, enable_ip4=False,
+ enable_ip6=False):
+ """ Enable/disable IP reassembly """
+ return self.api(self.papi.ip_reassembly_enable_disable,
+ {'sw_if_index': sw_if_index,
+ 'enable_ip4': 1 if enable_ip4 else 0,
+ 'enable_ip6': 1 if enable_ip6 else 0,
+ })
+
def gbp_endpoint_add_del(self, is_add, sw_if_index, addr, is_ip6, epg):
""" GBP endpoint Add/Del """
return self.api(self.papi.gbp_endpoint_add_del,
diff --git a/test/vpp_punt_socket.py b/test/vpp_punt_socket.py
deleted file mode 100644
index 5004b23396d..00000000000
--- a/test/vpp_punt_socket.py
+++ /dev/null
@@ -1,75 +0,0 @@
-from socket import socket, AF_UNIX, SOCK_DGRAM
-from select import select
-from time import time
-from struct import unpack, calcsize
-from util import ppc
-from scapy.layers.l2 import Ether
-
-client_uds_socket_name = "client-uds-socket"
-vpp_uds_socket_name = "vpp-uds-socket"
-
-VPP_PUNT_HEADER_FMT = '=Ii'
-VPP_PUNT_HEADER_SIZE = calcsize(VPP_PUNT_HEADER_FMT)
-
-
-class VppPuntAction:
- PUNT_L2 = 0
- PUNT_IP4_ROUTED = 1
- PUNT_IP6_ROUTED = 2
-
-
-class VppUDSPuntSocket(object):
- def __init__(self, testcase, port, is_ip4=1, l4_protocol=0x11):
- client_path = '%s/%s-%s-%s' % (testcase.tempdir,
- client_uds_socket_name,
- "4" if is_ip4 else "6", port)
- testcase.vapi.punt_socket_register(
- port, client_path, is_ip4=is_ip4, l4_protocol=l4_protocol)
- self.testcase = testcase
- self.uds = socket(AF_UNIX, SOCK_DGRAM)
- self.uds.bind(client_path)
- self.uds.connect(testcase.punt_socket_path)
-
- def wait_for_packets(self, count, timeout=1):
- packets = []
- now = time()
- deadline = now + timeout
- while len(packets) < count and now < deadline:
- r, w, e = select([self.uds], [], [self.uds], deadline - now)
- if self.uds in r:
- x = self.uds.recv(1024 * 1024)
- sw_if_index, punt_action = unpack(
- VPP_PUNT_HEADER_FMT, x[:VPP_PUNT_HEADER_SIZE])
- packets.append({'sw_if_index': sw_if_index,
- 'punt_action': punt_action,
- 'packet': x[VPP_PUNT_HEADER_SIZE:]})
-
- if self.uds in e:
- raise Exception("select() indicates error on UDS socket")
- now = time()
-
- if len(packets) != count:
- raise Exception("Unexpected packet count received, got %s packets,"
- " expected %s packets" % (len(packets), count))
- self.testcase.logger.debug(
- "Got %s packets via punt socket" % len(packets))
- return packets
-
- def assert_nothing_captured(self, timeout=.25):
- packets = []
- now = time()
- deadline = now + timeout
- while now < deadline:
- r, w, e = select([self.uds], [], [self.uds], deadline - now)
- if self.uds in r:
- x = self.uds.recv(1024 * 1024)
- packets.append(Ether(x[VPP_PUNT_HEADER_SIZE:]))
- if self.uds in e:
- raise Exception("select() indicates error on UDS socket")
- now = time()
-
- if len(packets) > 0:
- self.testcase.logger.error(
- ppc("Unexpected packets captured:", packets))
- raise Exception("Unexpected packet count received, got %s packets,"
- " expected no packets" % len(packets))