kelvin-onlab | d9e23de | 2015-08-06 10:34:44 -0700 | [diff] [blame] | 1 | """ |
| 2 | These functions can be used for topology comparisons |
| 3 | """ |
| 4 | |
| 5 | import time |
| 6 | import os |
| 7 | import json |
| 8 | |
| 9 | def getAllDevices( main ): |
| 10 | """ |
| 11 | Return a list containing the devices output from each ONOS node |
| 12 | """ |
| 13 | devices = [] |
| 14 | threads = [] |
GlennRC | 632e289 | 2015-10-19 18:58:41 -0700 | [diff] [blame] | 15 | for i in main.activeNodes: |
kelvin-onlab | d9e23de | 2015-08-06 10:34:44 -0700 | [diff] [blame] | 16 | 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 | |
| 27 | def getAllHosts( main ): |
| 28 | """ |
| 29 | Return a list containing the hosts output from each ONOS node |
| 30 | """ |
| 31 | hosts = [] |
| 32 | ipResult = main.TRUE |
| 33 | threads = [] |
GlennRC | 632e289 | 2015-10-19 18:58:41 -0700 | [diff] [blame] | 34 | for i in main.activeNodes: |
kelvin-onlab | d9e23de | 2015-08-06 10:34:44 -0700 | [diff] [blame] | 35 | 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 | |
| 46 | def getAllPorts( main ): |
| 47 | """ |
| 48 | Return a list containing the ports output from each ONOS node |
| 49 | """ |
| 50 | ports = [] |
| 51 | threads = [] |
GlennRC | 632e289 | 2015-10-19 18:58:41 -0700 | [diff] [blame] | 52 | for i in main.activeNodes: |
kelvin-onlab | d9e23de | 2015-08-06 10:34:44 -0700 | [diff] [blame] | 53 | 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 | |
| 64 | def getAllLinks( main ): |
| 65 | """ |
| 66 | Return a list containing the links output from each ONOS node |
| 67 | """ |
| 68 | links = [] |
| 69 | threads = [] |
GlennRC | 632e289 | 2015-10-19 18:58:41 -0700 | [diff] [blame] | 70 | for i in main.activeNodes: |
kelvin-onlab | d9e23de | 2015-08-06 10:34:44 -0700 | [diff] [blame] | 71 | 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 | |
| 82 | def getAllClusters( main ): |
| 83 | """ |
| 84 | Return a list containing the clusters output from each ONOS node |
| 85 | """ |
| 86 | clusters = [] |
| 87 | threads = [] |
GlennRC | 632e289 | 2015-10-19 18:58:41 -0700 | [diff] [blame] | 88 | for i in main.activeNodes: |
kelvin-onlab | d9e23de | 2015-08-06 10:34:44 -0700 | [diff] [blame] | 89 | 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 | |
YPZhang | 81a7d4e | 2016-04-18 13:10:17 -0700 | [diff] [blame] | 100 | def sendArpPackage( main, hostList ): |
| 101 | import json |
YPZhang | 26a139e | 2016-04-25 14:01:55 -0700 | [diff] [blame] | 102 | import time |
YPZhang | 81a7d4e | 2016-04-18 13:10:17 -0700 | [diff] [blame] | 103 | """ |
| 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: |
YPZhang | 26a139e | 2016-04-25 14:01:55 -0700 | [diff] [blame] | 111 | main.Mininet1.arping( srcHost=h, dstHost="10.0.0.1", output=main.FALSE, noResult=True ) |
| 112 | time.sleep(1) |
YPZhang | 81a7d4e | 2016-04-18 13:10:17 -0700 | [diff] [blame] | 113 | else: |
| 114 | main.Mininet1.arping(srcHost=hostList) |
| 115 | summaryStr = json.loads( main.CLIs[0].summary().encode() ) |
| 116 | hostNum = summaryStr.get('hosts') |
| 117 | return hostNum |