sctp: add option to enable/disable
[vpp.git] / test / test_sctp.py
1 #!/usr/bin/env python
2
3 import unittest
4
5 from framework import VppTestCase, VppTestRunner
6 from vpp_ip_route import VppIpTable, VppIpRoute, VppRoutePath
7
8
9 class TestSCTP(VppTestCase):
10     """ SCTP Test Case """
11
12     @classmethod
13     def setUpClass(cls):
14         super(TestSCTP, cls).setUpClass()
15
16     @classmethod
17     def tearDownClass(cls):
18         super(TestSCTP, cls).tearDownClass()
19
20     def setUp(self):
21         super(TestSCTP, self).setUp()
22         self.vapi.session_enable_disable(is_enabled=1)
23         self.vapi.cli("sctp enable")
24         self.create_loopback_interfaces(2)
25
26         table_id = 0
27
28         for i in self.lo_interfaces:
29             i.admin_up()
30
31             if table_id != 0:
32                 tbl = VppIpTable(self, table_id)
33                 tbl.add_vpp_config()
34
35             i.set_table_ip4(table_id)
36             i.config_ip4()
37             table_id += 1
38
39         # Configure namespaces
40         self.vapi.app_namespace_add_del(namespace_id=b"0",
41                                         sw_if_index=self.loop0.sw_if_index)
42         self.vapi.app_namespace_add_del(namespace_id=b"1",
43                                         sw_if_index=self.loop1.sw_if_index)
44
45     def tearDown(self):
46         for i in self.lo_interfaces:
47             i.unconfig_ip4()
48             i.set_table_ip4(0)
49             i.admin_down()
50         self.vapi.session_enable_disable(is_enabled=0)
51         super(TestSCTP, self).tearDown()
52
53     def test_sctp_transfer(self):
54         """ SCTP echo client/server transfer """
55
56         # Add inter-table routes
57         ip_t01 = VppIpRoute(self, self.loop1.local_ip4, 32,
58                             [VppRoutePath("0.0.0.0",
59                                           0xffffffff,
60                                           nh_table_id=1)])
61         ip_t10 = VppIpRoute(self, self.loop0.local_ip4, 32,
62                             [VppRoutePath("0.0.0.0",
63                                           0xffffffff,
64                                           nh_table_id=0)], table_id=1)
65         ip_t01.add_vpp_config()
66         ip_t10.add_vpp_config()
67
68         # Start builtin server and client
69         uri = "sctp://" + self.loop0.local_ip4 + "/1234"
70         error = self.vapi.cli("test echo server appns 0 fifo-size 4 " +
71                               "no-echo uri " + uri)
72         if error:
73             self.logger.critical(error)
74             self.assertNotIn("failed", error)
75
76         error = self.vapi.cli("test echo client mbytes 10 no-return " +
77                               " appns 1" +
78                               " fifo-size 4" +
79                               " no-output test-bytes syn-timeout 3" +
80                               " test-timeout 30" +
81                               " uri " + uri)
82         if error:
83             self.logger.critical(error)
84             self.assertNotIn("failed", error)
85
86         # Delete inter-table routes
87         ip_t01.remove_vpp_config()
88         ip_t10.remove_vpp_config()
89
90 if __name__ == '__main__':
91     unittest.main(testRunner=VppTestRunner)