return res;
}
+static int
+tcp_test_lookup (vlib_main_t * vm, unformat_input_t * input)
+{
+ session_manager_main_t *smm = &session_manager_main;
+ tcp_main_t *tm = &tcp_main;
+ transport_connection_t _tc1, *tc1 = &_tc1, _tc2, *tc2 = &_tc2, *tconn;
+ tcp_connection_t *tc;
+ stream_session_t *s, *s1;
+ u8 cmp = 0, is_filtered = 0;
+
+ /*
+ * Allocate fake session and connection 1
+ */
+ pool_get (smm->sessions[0], s);
+ memset (s, 0, sizeof (*s));
+ s->session_index = s - smm->sessions[0];
+
+ pool_get (tm->connections[0], tc);
+ memset (tc, 0, sizeof (*tc));
+ tc->connection.c_index = tc - tm->connections[0];
+ tc->connection.s_index = s->session_index;
+ s->connection_index = tc->connection.c_index;
+
+ tc->connection.lcl_ip.ip4.as_u32 = clib_host_to_net_u32 (0x06000101);
+ tc->connection.rmt_ip.ip4.as_u32 = clib_host_to_net_u32 (0x06000103);
+ tc->connection.lcl_port = 35051;
+ tc->connection.rmt_port = 53764;
+ tc->connection.proto = TRANSPORT_PROTO_TCP;
+ tc->connection.is_ip4 = 1;
+ clib_memcpy (tc1, &tc->connection, sizeof (*tc1));
+ s1 = s;
+
+ /*
+ * Allocate fake session and connection 2
+ */
+ pool_get (session_manager_main.sessions[0], s);
+ memset (s, 0, sizeof (*s));
+ s->session_index = s - smm->sessions[0];
+
+ pool_get (tm->connections[0], tc);
+ memset (tc, 0, sizeof (*tc));
+ tc->connection.c_index = tc - tm->connections[0];
+ tc->connection.s_index = s->session_index;
+ s->connection_index = tc->connection.c_index;
+
+ tc->connection.lcl_ip.ip4.as_u32 = clib_host_to_net_u32 (0x06000101);
+ tc->connection.rmt_ip.ip4.as_u32 = clib_host_to_net_u32 (0x06000102);
+ tc->connection.lcl_port = 38225;
+ tc->connection.rmt_port = 53764;
+ tc->connection.proto = TRANSPORT_PROTO_TCP;
+ tc->connection.is_ip4 = 1;
+ clib_memcpy (tc2, &tc->connection, sizeof (*tc2));
+
+ /*
+ * Confirm that connection lookup works
+ */
+
+ session_lookup_add_connection (tc1, session_handle (s1));
+ tconn = session_lookup_connection_wt4 (0, &tc1->lcl_ip.ip4,
+ &tc1->rmt_ip.ip4,
+ tc1->lcl_port, tc1->rmt_port,
+ tc1->proto, 0, &is_filtered);
+
+ TCP_TEST ((tconn != 0), "connection exists");
+ cmp = (memcmp (&tconn->rmt_ip, &tc1->rmt_ip, sizeof (tc1->rmt_ip)) == 0);
+ TCP_TEST ((cmp), "rmt ip is identical %d", cmp);
+ TCP_TEST ((tconn->lcl_port == tc1->lcl_port),
+ "rmt port is identical %d", tconn->lcl_port == tc1->lcl_port);
+
+ /*
+ * Non-existing connection lookup should not work
+ */
+
+ tconn = session_lookup_connection_wt4 (0, &tc2->lcl_ip.ip4,
+ &tc2->rmt_ip.ip4,
+ tc2->lcl_port, tc2->rmt_port,
+ tc2->proto, 0, &is_filtered);
+ TCP_TEST ((tconn == 0), "lookup result should be null");
+
+ /*
+ * Delete and lookup again
+ */
+ session_lookup_del_connection (tc1);
+ tconn = session_lookup_connection_wt4 (0, &tc1->lcl_ip.ip4,
+ &tc1->rmt_ip.ip4,
+ tc1->lcl_port, tc1->rmt_port,
+ tc1->proto, 0, &is_filtered);
+ TCP_TEST ((tconn == 0), "lookup result should be null");
+ tconn = session_lookup_connection_wt4 (0, &tc2->lcl_ip.ip4,
+ &tc2->rmt_ip.ip4,
+ tc2->lcl_port, tc2->rmt_port,
+ tc2->proto, 0, &is_filtered);
+ TCP_TEST ((tconn == 0), "lookup result should be null");
+
+ /*
+ * Re-add and lookup tc2
+ */
+ session_lookup_add_connection (tc1, tc1->s_index);
+ tconn = session_lookup_connection_wt4 (0, &tc2->lcl_ip.ip4,
+ &tc2->rmt_ip.ip4,
+ tc2->lcl_port, tc2->rmt_port,
+ tc2->proto, 0, &is_filtered);
+ TCP_TEST ((tconn == 0), "lookup result should be null");
+
+ return 0;
+}
+
static int
tcp_test_session (vlib_main_t * vm, unformat_input_t * input)
{
int rv = 0;
tcp_connection_t *tc0;
- u8 sst = SESSION_TYPE_IP4_TCP;
ip4_address_t local, remote;
u16 local_port, remote_port;
tcp_main_t *tm = vnet_get_tcp_main ();
TCP_EVT_DBG (TCP_EVT_OPEN, tc0);
if (stream_session_accept (&tc0->connection, 0 /* listener index */ ,
- sst, 0 /* notify */ ))
+ 0 /* notify */ ))
clib_warning ("stream_session_accept failed");
stream_session_accept_notify (&tc0->connection);
{
res = tcp_test_session (vm, input);
}
+ else if (unformat (input, "lookup"))
+ {
+ res = tcp_test_lookup (vm, input);
+ }
+ else if (unformat (input, "all"))
+ {
+ if ((res = tcp_test_sack (vm, input)))
+ goto done;
+ if ((res = tcp_test_fifo (vm, input)))
+ goto done;
+ if ((res = tcp_test_lookup (vm, input)))
+ goto done;
+ }
else
break;
}
+done:
if (res)
- {
- return clib_error_return (0, "TCP unit test failed");
- }
- else
- {
- return 0;
- }
+ return clib_error_return (0, "TCP unit test failed");
+ return 0;
}
/* *INDENT-OFF* */
};
/* *INDENT-ON* */
-
/*
* fd.io coding-style-patch-verification: ON
*