tcp/session: add make tests
Change-Id: Icb93ab80c5a6432d7b2b698a47e8b612c6f06fbd Signed-off-by: Florin Coras <fcoras@cisco.com>
This commit is contained in:

committed by
Dave Barach

parent
19b1f6ae21
commit
3ea6ce235e
@ -1557,9 +1557,12 @@ tcp_test_lookup (vlib_main_t * vm, unformat_input_t * input)
|
|||||||
tcp_main_t *tm = &tcp_main;
|
tcp_main_t *tm = &tcp_main;
|
||||||
transport_connection_t _tc1, *tc1 = &_tc1, _tc2, *tc2 = &_tc2, *tconn;
|
transport_connection_t _tc1, *tc1 = &_tc1, _tc2, *tc2 = &_tc2, *tconn;
|
||||||
tcp_connection_t *tc;
|
tcp_connection_t *tc;
|
||||||
stream_session_t *s;
|
stream_session_t *s, *s1;
|
||||||
u8 cmp = 0, is_filtered = 0;
|
u8 cmp = 0, is_filtered = 0;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Allocate fake session and connection 1
|
||||||
|
*/
|
||||||
pool_get (smm->sessions[0], s);
|
pool_get (smm->sessions[0], s);
|
||||||
memset (s, 0, sizeof (*s));
|
memset (s, 0, sizeof (*s));
|
||||||
s->session_index = s - smm->sessions[0];
|
s->session_index = s - smm->sessions[0];
|
||||||
@ -1574,12 +1577,18 @@ tcp_test_lookup (vlib_main_t * vm, unformat_input_t * input)
|
|||||||
tc->connection.rmt_ip.ip4.as_u32 = clib_host_to_net_u32 (0x06000103);
|
tc->connection.rmt_ip.ip4.as_u32 = clib_host_to_net_u32 (0x06000103);
|
||||||
tc->connection.lcl_port = 35051;
|
tc->connection.lcl_port = 35051;
|
||||||
tc->connection.rmt_port = 53764;
|
tc->connection.rmt_port = 53764;
|
||||||
tc->connection.proto = 0;
|
tc->connection.proto = TRANSPORT_PROTO_TCP;
|
||||||
|
tc->connection.is_ip4 = 1;
|
||||||
clib_memcpy (tc1, &tc->connection, sizeof (*tc1));
|
clib_memcpy (tc1, &tc->connection, sizeof (*tc1));
|
||||||
|
s1 = s;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Allocate fake session and connection 2
|
||||||
|
*/
|
||||||
pool_get (session_manager_main.sessions[0], s);
|
pool_get (session_manager_main.sessions[0], s);
|
||||||
memset (s, 0, sizeof (*s));
|
memset (s, 0, sizeof (*s));
|
||||||
s->session_index = s - smm->sessions[0];
|
s->session_index = s - smm->sessions[0];
|
||||||
|
|
||||||
pool_get (tm->connections[0], tc);
|
pool_get (tm->connections[0], tc);
|
||||||
memset (tc, 0, sizeof (*tc));
|
memset (tc, 0, sizeof (*tc));
|
||||||
tc->connection.c_index = tc - tm->connections[0];
|
tc->connection.c_index = tc - tm->connections[0];
|
||||||
@ -1590,18 +1599,21 @@ tcp_test_lookup (vlib_main_t * vm, unformat_input_t * input)
|
|||||||
tc->connection.rmt_ip.ip4.as_u32 = clib_host_to_net_u32 (0x06000102);
|
tc->connection.rmt_ip.ip4.as_u32 = clib_host_to_net_u32 (0x06000102);
|
||||||
tc->connection.lcl_port = 38225;
|
tc->connection.lcl_port = 38225;
|
||||||
tc->connection.rmt_port = 53764;
|
tc->connection.rmt_port = 53764;
|
||||||
tc->connection.proto = 0;
|
tc->connection.proto = TRANSPORT_PROTO_TCP;
|
||||||
|
tc->connection.is_ip4 = 1;
|
||||||
clib_memcpy (tc2, &tc->connection, sizeof (*tc2));
|
clib_memcpy (tc2, &tc->connection, sizeof (*tc2));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Confirm that connection lookup works
|
* Confirm that connection lookup works
|
||||||
*/
|
*/
|
||||||
|
|
||||||
session_lookup_add_connection (tc1, tc1->s_index);
|
session_lookup_add_connection (tc1, session_handle (s1));
|
||||||
tconn = session_lookup_connection_wt4 (0, &tc1->lcl_ip.ip4,
|
tconn = session_lookup_connection_wt4 (0, &tc1->lcl_ip.ip4,
|
||||||
&tc1->rmt_ip.ip4,
|
&tc1->rmt_ip.ip4,
|
||||||
tc1->lcl_port, tc1->rmt_port,
|
tc1->lcl_port, tc1->rmt_port,
|
||||||
tc1->proto, 0, &is_filtered);
|
tc1->proto, 0, &is_filtered);
|
||||||
|
|
||||||
|
TCP_TEST ((tconn != 0), "connection exists");
|
||||||
cmp = (memcmp (&tconn->rmt_ip, &tc1->rmt_ip, sizeof (tc1->rmt_ip)) == 0);
|
cmp = (memcmp (&tconn->rmt_ip, &tc1->rmt_ip, sizeof (tc1->rmt_ip)) == 0);
|
||||||
TCP_TEST ((cmp), "rmt ip is identical %d", cmp);
|
TCP_TEST ((cmp), "rmt ip is identical %d", cmp);
|
||||||
TCP_TEST ((tconn->lcl_port == tc1->lcl_port),
|
TCP_TEST ((tconn->lcl_port == tc1->lcl_port),
|
||||||
@ -1730,18 +1742,23 @@ tcp_test (vlib_main_t * vm,
|
|||||||
{
|
{
|
||||||
res = tcp_test_lookup (vm, input);
|
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
|
else
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
done:
|
||||||
if (res)
|
if (res)
|
||||||
{
|
return clib_error_return (0, "TCP unit test failed");
|
||||||
return clib_error_return (0, "TCP unit test failed");
|
return 0;
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* *INDENT-OFF* */
|
/* *INDENT-OFF* */
|
||||||
|
31
test/test_session.py
Normal file
31
test/test_session.py
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
from framework import VppTestCase, VppTestRunner
|
||||||
|
|
||||||
|
|
||||||
|
class TestSession(VppTestCase):
|
||||||
|
""" Session Test Case """
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def setUpClass(cls):
|
||||||
|
super(TestSession, cls).setUpClass()
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
super(TestSession, self).setUp()
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
super(TestSession, self).tearDown()
|
||||||
|
self.vapi.session_enable_disable(is_enabled=1)
|
||||||
|
|
||||||
|
def test_session(self):
|
||||||
|
""" Session Unit Tests """
|
||||||
|
error = self.vapi.cli("test session all")
|
||||||
|
|
||||||
|
if error:
|
||||||
|
self.logger.critical(error)
|
||||||
|
self.assertEqual(error.find("Failed"), -1)
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main(testRunner=VppTestRunner)
|
31
test/test_tcp.py
Normal file
31
test/test_tcp.py
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
from framework import VppTestCase, VppTestRunner
|
||||||
|
|
||||||
|
|
||||||
|
class TestTCP(VppTestCase):
|
||||||
|
""" TCP Test Case """
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def setUpClass(cls):
|
||||||
|
super(TestTCP, cls).setUpClass()
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
super(TestTCP, self).setUp()
|
||||||
|
self.vapi.session_enable_disable(is_enabled=1)
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
super(TestTCP, self).tearDown()
|
||||||
|
|
||||||
|
def test_tcp(self):
|
||||||
|
""" TCP Unit Tests """
|
||||||
|
error = self.vapi.cli("test tcp all")
|
||||||
|
|
||||||
|
if error:
|
||||||
|
self.logger.critical(error)
|
||||||
|
self.assertEqual(error.find("Failed"), -1)
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main(testRunner=VppTestRunner)
|
@ -2806,3 +2806,8 @@ class VppPapiProvider(object):
|
|||||||
return self.api(self.papi.add_node_next,
|
return self.api(self.papi.add_node_next,
|
||||||
{'node_name': node_name,
|
{'node_name': node_name,
|
||||||
'next_name': next_name})
|
'next_name': next_name})
|
||||||
|
|
||||||
|
def session_enable_disable(self, is_enabled):
|
||||||
|
return self.api(
|
||||||
|
self.papi.session_enable_disable,
|
||||||
|
{'is_enable': is_enabled})
|
||||||
|
Reference in New Issue
Block a user