blob: f1101fef450807e11a3957481dc8c08a294642f0 [file] [log] [blame]
kelvin-onlabd9e23de2015-08-06 10:34:44 -07001"""
2 These functions can be used for topology comparisons
3"""
4
5import time
6import os
7import json
8
9def getAllDevices( main ):
10 """
11 Return a list containing the devices output from each ONOS node
12 """
13 devices = []
14 threads = []
GlennRC632e2892015-10-19 18:58:41 -070015 for i in main.activeNodes:
kelvin-onlabd9e23de2015-08-06 10:34:44 -070016 t = main.Thread( target=main.CLIs[i].devices,
17 name="devices-" + str( i ),
18 args=[ ] )
19 threads.append( t )
20 t.start()
21
22 for t in threads:
23 t.join()
24 devices.append( t.result )
25 return devices
26
27def getAllHosts( main ):
28 """
29 Return a list containing the hosts output from each ONOS node
30 """
31 hosts = []
32 ipResult = main.TRUE
33 threads = []
GlennRC632e2892015-10-19 18:58:41 -070034 for i in main.activeNodes:
kelvin-onlabd9e23de2015-08-06 10:34:44 -070035 t = main.Thread( target=main.CLIs[i].hosts,
36 name="hosts-" + str( i ),
37 args=[ ] )
38 threads.append( t )
39 t.start()
40
41 for t in threads:
42 t.join()
43 hosts.append( t.result )
44 return hosts
45
46def getAllPorts( main ):
47 """
48 Return a list containing the ports output from each ONOS node
49 """
50 ports = []
51 threads = []
GlennRC632e2892015-10-19 18:58:41 -070052 for i in main.activeNodes:
kelvin-onlabd9e23de2015-08-06 10:34:44 -070053 t = main.Thread( target=main.CLIs[i].ports,
54 name="ports-" + str( i ),
55 args=[ ] )
56 threads.append( t )
57 t.start()
58
59 for t in threads:
60 t.join()
61 ports.append( t.result )
62 return ports
63
64def getAllLinks( main ):
65 """
66 Return a list containing the links output from each ONOS node
67 """
68 links = []
69 threads = []
GlennRC632e2892015-10-19 18:58:41 -070070 for i in main.activeNodes:
kelvin-onlabd9e23de2015-08-06 10:34:44 -070071 t = main.Thread( target=main.CLIs[i].links,
72 name="links-" + str( i ),
73 args=[ ] )
74 threads.append( t )
75 t.start()
76
77 for t in threads:
78 t.join()
79 links.append( t.result )
80 return links
81
82def getAllClusters( main ):
83 """
84 Return a list containing the clusters output from each ONOS node
85 """
86 clusters = []
87 threads = []
GlennRC632e2892015-10-19 18:58:41 -070088 for i in main.activeNodes:
kelvin-onlabd9e23de2015-08-06 10:34:44 -070089 t = main.Thread( target=main.CLIs[i].clusters,
90 name="clusters-" + str( i ),
91 args=[ ] )
92 threads.append( t )
93 t.start()
94
95 for t in threads:
96 t.join()
97 clusters.append( t.result )
98 return clusters
99
YPZhang81a7d4e2016-04-18 13:10:17 -0700100def sendArpPackage( main, hostList ):
101 import json
YPZhang26a139e2016-04-25 14:01:55 -0700102 import time
YPZhang81a7d4e2016-04-18 13:10:17 -0700103 """
104 send arping package from host
105 return the total hosts number from Onos
106 """
107 main.log.info("Sending Arping package...")
108 if isinstance(hostList, list):
109 threads = []
110 for h in hostList:
YPZhang26a139e2016-04-25 14:01:55 -0700111 main.Mininet1.arping( srcHost=h, dstHost="10.0.0.1", output=main.FALSE, noResult=True )
112 time.sleep(1)
YPZhang81a7d4e2016-04-18 13:10:17 -0700113 else:
114 main.Mininet1.arping(srcHost=hostList)
115 summaryStr = json.loads( main.CLIs[0].summary().encode() )
116 hostNum = summaryStr.get('hosts')
117 return hostNum