3 mininet_rest_test.py: Validate mininet_rest works within the mininet framework, focused on PING 5 This will launch an example network, with switches and hosts and rules, confirming that 6 ping will work across hosts that are connected properly. 9 This class depends on a controller - it is best to launch both mininet and floodlight. 10 $ docker-compose up -d mininet floodlight 12 If possible, bring up the entire kilda controller. 14 Usage (example uses VLAN ID=1000): 15 From the command line - run as a MODULE so that mininet_rest can be imported) 16 cd /; python -m app.examples.mininet_rest_test 20 from ..
import mininet_rest
24 from functools
import partial
26 logger = logging.getLogger(__name__)
64 "dpid":
"deadbeef00000001",
68 "dpid":
"deadbeef00000002",
72 "dpid":
"deadbeef00000003",
76 "dpid":
"deadbeef00000004",
80 "dpid":
"deadbeef00000005",
84 "dpid":
"deadbeef00000006",
88 "dpid":
"deadbeef00000007",
96 result = requests.post(url=
"http://localhost:38080/cleanup")
101 result = requests.post(url=
"http://localhost:38080/topology",json=topo_json)
105 def test_ping(src_switch, src_port, src_vlan, dst_switch, dst_port, dst_vlan):
106 """setup our rules for host / switch / switch and see if we can ping""" 107 urlbase =
"http://localhost:38080/checkpingtraffic" 108 args =
"srcswitch={}&srcport={}&srcvlan={}&dstswitch={}&dstport={}&dstvlan={}".
format(
109 src_switch,src_port,src_vlan,dst_switch,dst_port,dst_vlan)
110 url =
"{}?{}".
format(urlbase,args)
111 print (
"** PING: {}".
format(url))
112 result = requests.get(url=url)
117 if response.status_code == 503:
119 print "FAILURE - CAN'T PING" 121 print "SUCCESS - NO PING" 122 elif response.status_code == 200:
124 print "SUCCESS - CAN PING" 126 print "FAILURE - CAN PING" 128 print "ERROR - WRONG CODE" 134 if result.status_code == 503
and not should_ping:
136 elif result.status_code == 200
and should_ping:
158 if total_result == total_expected:
159 print (
"\n{} ... ALL TESTS PASSED\n".
format(name))
161 print (
"\n{} ... FAILURE: {} of {} passed\n".
format(name, total_result, total_expected))
173 This test is similar to the Kilda single switch test(s), but without kilda issuing the rules. 174 The intent is to confirm that the test harness works (ie pingable works as intended), but also 175 serve as an example of what the rules may look like for the kilda deployment. 177 Examples: # flows without transit vlans and intermediate switches 178 | flow_id | source_switch | source_port | source_vlan | destination_switch | destination_port | destination_vlan | bandwidth | 179 | c1none | de:ad:be:ef:00:00:00:03 | 1 | 0 | de:ad:be:ef:00:00:00:03 | 2 | 0 | 10000 | 183 pingable = partial(test_ping,s2,2,0,s4,1,0)
184 psetup = [ partial(mininet_rest.add_single_switch_rules, s3, 1, 2, 0, 0 ) ]
185 pclear = [ partial(mininet_rest.clear_single_switch_rules, s3, 1, 2) ]
186 test_scenario(
"test_single_switch_scenario", pingable, psetup, pclear)
191 Examples: # flows with transit vlans and without intermediate switches 192 | flow_id | source_switch | source_port | source_vlan | destination_switch | destination_port | destination_vlan | bandwidth | 193 | c2none | de:ad:be:ef:00:00:00:03 | 1 | 0 | de:ad:be:ef:00:00:00:04 | 2 | 0 | 10000 | 196 pingable = partial(test_ping, s2, 2, 0, s5, 1, 0)
198 partial( mininet_rest.add_single_switch_rules, s3, 1, 2, 0, 0 ),
199 partial( mininet_rest.add_single_switch_rules, s4, 1, 2, 0, 0 )
202 partial(mininet_rest.clear_single_switch_rules, s3, 1, 2),
203 partial(mininet_rest.clear_single_switch_rules, s4, 1, 2)
205 test_scenario(
"test_two_switch_scenario", pingable, psetup, pclear)
210 Examples: # flows with transit vlans and intermediate switches 211 | flow_id | source_switch | source_port | source_vlan | destination_switch | destination_port | destination_vlan | bandwidth | 212 | c3none | de:ad:be:ef:00:00:00:02 | 1 | 0 | de:ad:be:ef:00:00:00:04 | 2 | 0 | 10000 | 215 pingable = partial(test_ping, s2, 2, 0, s6, 1, 0)
217 partial( mininet_rest.add_single_switch_rules, s3, 1, 2, 0, 0 ),
218 partial( mininet_rest.add_single_switch_rules, s4, 1, 2, 0, 0 ),
219 partial( mininet_rest.add_single_switch_rules, s5, 1, 2, 0, 0 )
222 partial(mininet_rest.clear_single_switch_rules, s3, 1, 2),
223 partial(mininet_rest.clear_single_switch_rules, s4, 1, 2),
224 partial(mininet_rest.clear_single_switch_rules, s5, 1, 2)
226 test_scenario(
"test_three_switch_scenario", pingable, psetup, pclear)
239 if __name__ ==
'__main__':
def test_two_switch_scenario()
def test_ping(src_switch, src_port, src_vlan, dst_switch, dst_port, dst_vlan)
def test_scenario(name, pingable, psetup, pclear)
def pingable(host1, host2)
def print_ping_result(response, should_ping)
def call_pingagle(pingable, should_ping)
def test_three_switch_scenario()
def test_single_switch_scenario()