blob: 4a5c9bc4ff3587abe4f0ff1c44a720dabae09493 [file] [log] [blame]
Florin Coras3ea6ce22017-12-11 09:09:05 -08001#!/usr/bin/env python
2
3import unittest
4
5from framework import VppTestCase, VppTestRunner
Florin Corasb795bd02017-12-14 11:30:48 -08006from vpp_ip_route import VppIpTable, VppIpRoute, VppRoutePath
Florin Coras3ea6ce22017-12-11 09:09:05 -08007
8
9class TestTCP(VppTestCase):
10 """ TCP Test Case """
11
12 @classmethod
13 def setUpClass(cls):
14 super(TestTCP, cls).setUpClass()
15
16 def setUp(self):
17 super(TestTCP, self).setUp()
18 self.vapi.session_enable_disable(is_enabled=1)
Klement Sekerab9ef2732018-06-24 22:49:33 +020019 self.create_loopback_interfaces(2)
Florin Corasb795bd02017-12-14 11:30:48 -080020
21 table_id = 0
22
23 for i in self.lo_interfaces:
24 i.admin_up()
25
26 if table_id != 0:
27 tbl = VppIpTable(self, table_id)
28 tbl.add_vpp_config()
29
30 i.set_table_ip4(table_id)
31 i.config_ip4()
32 table_id += 1
33
34 # Configure namespaces
35 self.vapi.app_namespace_add(namespace_id="0",
36 sw_if_index=self.loop0.sw_if_index)
37 self.vapi.app_namespace_add(namespace_id="1",
38 sw_if_index=self.loop1.sw_if_index)
Florin Coras3ea6ce22017-12-11 09:09:05 -080039
40 def tearDown(self):
Florin Corasb795bd02017-12-14 11:30:48 -080041 for i in self.lo_interfaces:
42 i.unconfig_ip4()
43 i.set_table_ip4(0)
44 i.admin_down()
45 self.vapi.session_enable_disable(is_enabled=0)
Florin Coras3ea6ce22017-12-11 09:09:05 -080046 super(TestTCP, self).tearDown()
47
Florin Corasb795bd02017-12-14 11:30:48 -080048 def test_tcp_unittest(self):
Florin Coras3ea6ce22017-12-11 09:09:05 -080049 """ TCP Unit Tests """
50 error = self.vapi.cli("test tcp all")
51
52 if error:
53 self.logger.critical(error)
Florin Corasb795bd02017-12-14 11:30:48 -080054 self.assertEqual(error.find("failed"), -1)
55
56 def test_tcp_transfer(self):
Florin Coras4399c2e2018-01-25 06:34:42 -080057 """ TCP echo client/server transfer """
Florin Corasb795bd02017-12-14 11:30:48 -080058
59 # Add inter-table routes
60 ip_t01 = VppIpRoute(self, self.loop1.local_ip4, 32,
61 [VppRoutePath("0.0.0.0",
62 0xffffffff,
63 nh_table_id=1)])
64 ip_t10 = VppIpRoute(self, self.loop0.local_ip4, 32,
65 [VppRoutePath("0.0.0.0",
66 0xffffffff,
67 nh_table_id=0)], table_id=1)
68 ip_t01.add_vpp_config()
69 ip_t10.add_vpp_config()
70
71 # Start builtin server and client
72 uri = "tcp://" + self.loop0.local_ip4 + "/1234"
Florin Coras4399c2e2018-01-25 06:34:42 -080073 error = self.vapi.cli("test echo server appns 0 fifo-size 4 uri " +
Florin Corasb795bd02017-12-14 11:30:48 -080074 uri)
75 if error:
76 self.logger.critical(error)
Florin Coras4399c2e2018-01-25 06:34:42 -080077 self.assertEqual(error.find("failed"), -1)
Florin Corasb795bd02017-12-14 11:30:48 -080078
Florin Coras4399c2e2018-01-25 06:34:42 -080079 error = self.vapi.cli("test echo client mbytes 10 appns 1 " +
80 "fifo-size 4 no-output test-bytes " +
81 "syn-timeout 2 uri " + uri)
Florin Corasb795bd02017-12-14 11:30:48 -080082 if error:
83 self.logger.critical(error)
Florin Coras4399c2e2018-01-25 06:34:42 -080084 self.assertEqual(error.find("failed"), -1)
Florin Corasb795bd02017-12-14 11:30:48 -080085
86 # Delete inter-table routes
87 ip_t01.remove_vpp_config()
88 ip_t10.remove_vpp_config()
Florin Coras3ea6ce22017-12-11 09:09:05 -080089
90if __name__ == '__main__':
91 unittest.main(testRunner=VppTestRunner)