blob: 91c1878a30102436a30af3b55d8cfd1015e9a442 [file] [log] [blame]
pingping-lin8b306ac2014-11-17 18:13:51 -08001
2#Testing the basic functionality of SDN-IP
3
4class SdnIpTest:
5 def __init__(self):
6 self.default = ''
7
8 def CASE1(self, main):
9
10 '''
11 Test the SDN-IP functionality
pingping-lin6f6332e2014-11-19 19:13:58 -080012 allRoutes_expected: all expected routes for all BGP peers
13 routeIntents_expected: all expected MultiPointToSinglePointIntent intents
14 bgpIntents_expected: expected PointToPointIntent intents
15 allRoutes_actual: all routes from ONOS LCI
16 routeIntents_actual: actual MultiPointToSinglePointIntent intents from ONOS CLI
17 bgpIntents_actual: actual PointToPointIntent intents from ONOS CLI
pingping-lin8b306ac2014-11-17 18:13:51 -080018 '''
19 import time
20 import json
21 from operator import eq
22
pingping-lin6f6332e2014-11-19 19:13:58 -080023 SDNIP_JSON_FILE_PATH = "../tests/SdnIpTest/sdnip.json"
24 # all expected routes for all BGP peers
25 allRoutes_expected = []
pingping-lin8b306ac2014-11-17 18:13:51 -080026 main.step("Start to generate routes for BGP peer on host1")
pingping-lin6f6332e2014-11-19 19:13:58 -080027 prefixes = main.Quaggacli.generate_prefixes(1, 3)
28 main.log.info(prefixes)
29
30 # TODO: delete the static prefix below after integration with Demo Mininet script
31 prefixes = []
32 prefixes.append("172.16.30.0/24")
33 prefixes.append("1.0.0.0/24")
34 prefixes.append("2.0.0.0/24")
35 prefixes.append("3.0.0.0/24")
36
37
38 for prefix in prefixes:
39 # generate route with next hop
40 allRoutes_expected.append(prefix + "/" + "1.1.1.1")
41
42 routeIntents_expected = main.Quaggacli.generate_expected_onePeerRouteIntents(prefixes, "192.168.30.1", "00:00:00:00:03:01", SDNIP_JSON_FILE_PATH)
pingping-lin8b306ac2014-11-17 18:13:51 -080043
44 # start to insert routes into the bgp peer
45 main.step("Start Quagga-cli on host1")
46 main.Quaggacli.loginQuagga("1.1.1.1")
47
48 main.step("Start to configure Quagga on host1")
49 main.Quaggacli.enter_config(64513)
50
pingping-lin6f6332e2014-11-19 19:13:58 -080051 main.step("Start to generate and add routes for BGP peer on host1")
52 routes = main.Quaggacli.generate_prefixes(8, 3)
pingping-lin8b306ac2014-11-17 18:13:51 -080053 main.Quaggacli.add_routes(routes, 1)
54
55 # add generates routes to allRoutes
56 for route in routes:
pingping-lin6f6332e2014-11-19 19:13:58 -080057 allRoutes_expected.append(route + "/" + "1.1.1.1")
pingping-lin8b306ac2014-11-17 18:13:51 -080058
59 cell_name = main.params['ENV']['cellName']
60 ONOS1_ip = main.params['CTRL']['ip1']
61
62 main.step("Starting ONOS service")
63 # TODO: start ONOS from Mininet Script
64 # start_result = main.ONOSbench.onos_start("127.0.0.1")
65
66 main.step("Set cell for ONOS-cli environment")
67 main.ONOScli.set_cell(cell_name)
68
69 main.step("Start ONOS-cli")
70 # TODO: change the hardcode in start_onos_cli method in ONOS CLI driver
71 time.sleep(5)
72 main.ONOScli.start_onos_cli(ONOS1_ip)
73
74 main.step("Get devices in the network")
75 list_result = main.ONOScli.devices(json_format=False)
76 main.log.info(list_result)
77
78 #get all routes inside SDN-IP
79 get_routes_result = main.ONOScli.routes(json_format=True)
80
81 # parse routes from ONOS CLI
pingping-lin6f6332e2014-11-19 19:13:58 -080082 allRoutes_actual = main.Quaggacli.extract_actual_routes(get_routes_result)
pingping-lin8b306ac2014-11-17 18:13:51 -080083
pingping-lin6f6332e2014-11-19 19:13:58 -080084 main.step("Check routes installed")
85 main.log.info("Routes expected:")
86 main.log.info(sorted(allRoutes_expected))
pingping-lin8b306ac2014-11-17 18:13:51 -080087 main.log.info("Routes get from ONOS CLI:")
pingping-lin6f6332e2014-11-19 19:13:58 -080088 main.log.info(allRoutes_actual)
89 utilities.assert_equals(expect=sorted(allRoutes_expected), actual=allRoutes_actual,
90 onpass="***Routes in SDN-IP are correct!***",
91 onfail="***Routes in SDN-IP are wrong!***")
pingping-lin8b306ac2014-11-17 18:13:51 -080092
pingping-lin6f6332e2014-11-19 19:13:58 -080093 time.sleep(2)
94 get_intents_result = main.ONOScli.intents(json_format=True)
95
96
97 main.step("Check MultiPointToSinglePointIntent intents installed")
98 # route_intents_expected are generated when generating routes
99 # get rpoute intents from ONOS CLI
100 routeIntents_actual = main.Quaggacli.extract_actual_routeIntents(get_intents_result)
101 main.log.info("MultiPointToSinglePoint intents expected:")
102 main.log.info(routeIntents_expected)
103 main.log.info("MultiPointToSinglePoint intents get from ONOS CLI:")
104 main.log.info(routeIntents_actual)
105 utilities.assert_equals(expect=True, actual=eq(routeIntents_expected, routeIntents_actual),
106 onpass="***MultiPointToSinglePoint Intents in SDN-IP are correct!***",
107 onfail="***MultiPointToSinglePoint Intents in SDN-IP are wrong!***")
108
109
110 main.step("Check BGP PointToPointIntent intents installed")
111 # bgp intents expected
112 bgpIntents_expected = main.Quaggacli.generate_expected_bgpIntents(SDNIP_JSON_FILE_PATH)
113 # get BGP intents from ONOS CLI
114 bgpIntents_actual = main.Quaggacli.extract_actual_bgpIntents(get_intents_result)
115 main.log.info("PointToPointIntent intents expected:")
116 main.log.info(str(bgpIntents_expected).replace('u',""))
117 main.log.info("PointToPointIntent intents get from ONOS CLI:")
118 main.log.info(bgpIntents_actual)
119 utilities.assert_equals(expect=True, actual=eq(str(bgpIntents_expected).replace('u',""), str(bgpIntents_actual)),
120 onpass="***PointToPointIntent Intents in SDN-IP are correct!***",
121 onfail="***PointToPointIntent Intents in SDN-IP are wrong!***")
pingping-lin8b306ac2014-11-17 18:13:51 -0800122
123 #main.step("Test whether Mininet is started")
124 #main.Mininet2.handle.sendline("xterm host1")
125 #main.Mininet2.handle.expect("mininet>")
126