blob: 22505ff19e40ab0020ff2c6c92a151033ba4ea47 [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 """
YPZhangacaaf422016-07-26 09:34:03 -0700107 main.log.info( "Sending Arping package..." )
YPZhang81a7d4e2016-04-18 13:10:17 -0700108 if isinstance(hostList, list):
YPZhang81a7d4e2016-04-18 13:10:17 -0700109 for h in hostList:
YPZhang26a139e2016-04-25 14:01:55 -0700110 main.Mininet1.arping( srcHost=h, dstHost="10.0.0.1", output=main.FALSE, noResult=True )
YPZhang0f874862016-04-27 11:14:10 -0700111 time.sleep(0.5)
YPZhang81a7d4e2016-04-18 13:10:17 -0700112 else:
YPZhangacaaf422016-07-26 09:34:03 -0700113 main.Mininet1.arping( srcHost=hostList, dstHost="10.0.0.1", output=main.FALSE, noResult=True )
114 try:
115 summaryStr = ""
116 summaryStr = json.loads( main.CLIs[0].summary().encode() )
117 hostNum = summaryStr.get( 'hosts' )
118
119 except (TypeError, ValueError):
120 main.log.exception( " Object not as expected: {!r}".format( summaryStr) )
121 return -1
122 except Exception:
123 main.log.exception( self.name + ": Uncaught exception!" )
124 return -1
125
YPZhang81a7d4e2016-04-18 13:10:17 -0700126 return hostNum