Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1 | """ |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 2 | Description: This test is to determine if the HA test setup is |
| 3 | working correctly. There are no failures so this test should |
| 4 | have a 100% pass rate |
| 5 | |
| 6 | List of test cases: |
| 7 | CASE1: Compile ONOS and push it to the test machines |
| 8 | CASE2: Assign mastership to controllers |
| 9 | CASE3: Assign intents |
| 10 | CASE4: Ping across added host intents |
| 11 | CASE5: Reading state of ONOS |
| 12 | CASE6: The Failure case. Since this is the Sanity test, we do nothing. |
Jon Hall | 368769f | 2014-11-19 15:43:35 -0800 | [diff] [blame] | 13 | CASE7: Check state after control plane failure |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 14 | CASE8: Compare topo |
| 15 | CASE9: Link s3-s28 down |
| 16 | CASE10: Link s3-s28 up |
| 17 | CASE11: Switch down |
| 18 | CASE12: Switch up |
| 19 | CASE13: Clean up |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 20 | CASE14: start election app on all onos nodes |
| 21 | CASE15: Check that Leadership Election is still functional |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 22 | """ |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 23 | class HATestSanity: |
| 24 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 25 | def __init__( self ): |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 26 | self.default = '' |
| 27 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 28 | def CASE1( self, main ): |
| 29 | """ |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 30 | CASE1 is to compile ONOS and push it to the test machines |
| 31 | |
| 32 | Startup sequence: |
| 33 | git pull |
| 34 | mvn clean install |
| 35 | onos-package |
| 36 | cell <name> |
| 37 | onos-verify-cell |
| 38 | NOTE: temporary - onos-remove-raft-logs |
| 39 | onos-install -f |
| 40 | onos-wait-for-start |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 41 | """ |
| 42 | main.log.report( "ONOS HA Sanity test - initialization" ) |
| 43 | main.case( "Setting up test environment" ) |
| 44 | # TODO: save all the timers and output them for plotting |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 45 | |
| 46 | # load some vairables from the params file |
| 47 | PULL_CODE = False |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 48 | if main.params[ 'Git' ] == 'True': |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 49 | PULL_CODE = True |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 50 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 51 | cell_name = main.params[ 'ENV' ][ 'cellName' ] |
| 52 | |
| 53 | # set global variables |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 54 | global ONOS1_ip |
| 55 | global ONOS1_port |
| 56 | global ONOS2_ip |
| 57 | global ONOS2_port |
| 58 | global ONOS3_ip |
| 59 | global ONOS3_port |
| 60 | global ONOS4_ip |
| 61 | global ONOS4_port |
| 62 | global ONOS5_ip |
| 63 | global ONOS5_port |
| 64 | global ONOS6_ip |
| 65 | global ONOS6_port |
| 66 | global ONOS7_ip |
| 67 | global ONOS7_port |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 68 | global num_controllers |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 69 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 70 | ONOS1_ip = main.params[ 'CTRL' ][ 'ip1' ] |
| 71 | ONOS1_port = main.params[ 'CTRL' ][ 'port1' ] |
| 72 | ONOS2_ip = main.params[ 'CTRL' ][ 'ip2' ] |
| 73 | ONOS2_port = main.params[ 'CTRL' ][ 'port2' ] |
| 74 | ONOS3_ip = main.params[ 'CTRL' ][ 'ip3' ] |
| 75 | ONOS3_port = main.params[ 'CTRL' ][ 'port3' ] |
| 76 | ONOS4_ip = main.params[ 'CTRL' ][ 'ip4' ] |
| 77 | ONOS4_port = main.params[ 'CTRL' ][ 'port4' ] |
| 78 | ONOS5_ip = main.params[ 'CTRL' ][ 'ip5' ] |
| 79 | ONOS5_port = main.params[ 'CTRL' ][ 'port5' ] |
| 80 | ONOS6_ip = main.params[ 'CTRL' ][ 'ip6' ] |
| 81 | ONOS6_port = main.params[ 'CTRL' ][ 'port6' ] |
| 82 | ONOS7_ip = main.params[ 'CTRL' ][ 'ip7' ] |
| 83 | ONOS7_port = main.params[ 'CTRL' ][ 'port7' ] |
| 84 | num_controllers = int( main.params[ 'num_controllers' ] ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 85 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 86 | main.step( "Applying cell variable to environment" ) |
| 87 | cell_result = main.ONOSbench.set_cell( cell_name ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 88 | verify_result = main.ONOSbench.verify_cell() |
Jon Hall | 368769f | 2014-11-19 15:43:35 -0800 | [diff] [blame] | 89 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 90 | # FIXME:this is short term fix |
| 91 | main.log.report( "Removing raft logs" ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 92 | main.ONOSbench.onos_remove_raft_logs() |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 93 | main.log.report( "Uninstalling ONOS" ) |
| 94 | main.ONOSbench.onos_uninstall( ONOS1_ip ) |
| 95 | main.ONOSbench.onos_uninstall( ONOS2_ip ) |
| 96 | main.ONOSbench.onos_uninstall( ONOS3_ip ) |
| 97 | main.ONOSbench.onos_uninstall( ONOS4_ip ) |
| 98 | main.ONOSbench.onos_uninstall( ONOS5_ip ) |
| 99 | main.ONOSbench.onos_uninstall( ONOS6_ip ) |
| 100 | main.ONOSbench.onos_uninstall( ONOS7_ip ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 101 | |
| 102 | clean_install_result = main.TRUE |
| 103 | git_pull_result = main.TRUE |
| 104 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 105 | main.step( "Compiling the latest version of ONOS" ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 106 | if PULL_CODE: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 107 | # TODO Configure branch in params |
| 108 | main.step( "Git checkout and pull master" ) |
| 109 | main.ONOSbench.git_checkout( "master" ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 110 | git_pull_result = main.ONOSbench.git_pull() |
| 111 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 112 | main.step( "Using mvn clean & install" ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 113 | clean_install_result = main.TRUE |
| 114 | if git_pull_result == main.TRUE: |
| 115 | clean_install_result = main.ONOSbench.clean_install() |
| 116 | else: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 117 | main.log.warn( "Did not pull new code so skipping mvn " + |
| 118 | "clean install" ) |
| 119 | main.ONOSbench.get_version( report=True ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 120 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 121 | main.step( "Creating ONOS package" ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 122 | package_result = main.ONOSbench.onos_package() |
| 123 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 124 | main.step( "Installing ONOS package" ) |
| 125 | onos1_install_result = main.ONOSbench.onos_install( options="-f", |
| 126 | node=ONOS1_ip ) |
| 127 | onos2_install_result = main.ONOSbench.onos_install( options="-f", |
| 128 | node=ONOS2_ip ) |
| 129 | onos3_install_result = main.ONOSbench.onos_install( options="-f", |
| 130 | node=ONOS3_ip ) |
| 131 | onos4_install_result = main.ONOSbench.onos_install( options="-f", |
| 132 | node=ONOS4_ip ) |
| 133 | onos5_install_result = main.ONOSbench.onos_install( options="-f", |
| 134 | node=ONOS5_ip ) |
| 135 | onos6_install_result = main.ONOSbench.onos_install( options="-f", |
| 136 | node=ONOS6_ip ) |
| 137 | onos7_install_result = main.ONOSbench.onos_install( options="-f", |
| 138 | node=ONOS7_ip ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 139 | onos_install_result = onos1_install_result and onos2_install_result\ |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 140 | and onos3_install_result and onos4_install_result\ |
| 141 | and onos5_install_result and onos6_install_result\ |
| 142 | and onos7_install_result |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 143 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 144 | main.step( "Checking if ONOS is up yet" ) |
| 145 | # TODO check bundle:list? |
| 146 | for i in range( 2 ): |
| 147 | onos1_isup = main.ONOSbench.isup( ONOS1_ip ) |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 148 | if not onos1_isup: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 149 | main.log.report( "ONOS1 didn't start!" ) |
| 150 | onos2_isup = main.ONOSbench.isup( ONOS2_ip ) |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 151 | if not onos2_isup: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 152 | main.log.report( "ONOS2 didn't start!" ) |
| 153 | onos3_isup = main.ONOSbench.isup( ONOS3_ip ) |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 154 | if not onos3_isup: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 155 | main.log.report( "ONOS3 didn't start!" ) |
| 156 | onos4_isup = main.ONOSbench.isup( ONOS4_ip ) |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 157 | if not onos4_isup: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 158 | main.log.report( "ONOS4 didn't start!" ) |
| 159 | onos5_isup = main.ONOSbench.isup( ONOS5_ip ) |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 160 | if not onos5_isup: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 161 | main.log.report( "ONOS5 didn't start!" ) |
| 162 | onos6_isup = main.ONOSbench.isup( ONOS6_ip ) |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 163 | if not onos6_isup: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 164 | main.log.report( "ONOS6 didn't start!" ) |
| 165 | onos7_isup = main.ONOSbench.isup( ONOS7_ip ) |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 166 | if not onos7_isup: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 167 | main.log.report( "ONOS7 didn't start!" ) |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 168 | onos_isup_result = onos1_isup and onos2_isup and onos3_isup\ |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 169 | and onos4_isup and onos5_isup and onos6_isup and onos7_isup |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 170 | if onos_isup_result == main.TRUE: |
| 171 | break |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 172 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 173 | cli_result1 = main.ONOScli1.start_onos_cli( ONOS1_ip ) |
| 174 | cli_result2 = main.ONOScli2.start_onos_cli( ONOS2_ip ) |
| 175 | cli_result3 = main.ONOScli3.start_onos_cli( ONOS3_ip ) |
| 176 | cli_result4 = main.ONOScli4.start_onos_cli( ONOS4_ip ) |
| 177 | cli_result5 = main.ONOScli5.start_onos_cli( ONOS5_ip ) |
| 178 | cli_result6 = main.ONOScli6.start_onos_cli( ONOS6_ip ) |
| 179 | cli_result7 = main.ONOScli7.start_onos_cli( ONOS7_ip ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 180 | cli_results = cli_result1 and cli_result2 and cli_result3 and\ |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 181 | cli_result4 and cli_result5 and cli_result6 and cli_result7 |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 182 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 183 | main.step( "Start Packet Capture MN" ) |
Jon Hall | 368769f | 2014-11-19 15:43:35 -0800 | [diff] [blame] | 184 | main.Mininet2.start_tcpdump( |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 185 | str( main.params[ 'MNtcpdump' ][ 'folder' ] ) + str( main.TEST ) |
| 186 | + "-MN.pcap", |
| 187 | intf=main.params[ 'MNtcpdump' ][ 'intf' ], |
| 188 | port=main.params[ 'MNtcpdump' ][ 'port' ] ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 189 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 190 | case1_result = ( clean_install_result and package_result and |
| 191 | cell_result and verify_result and onos_install_result |
| 192 | and onos_isup_result and cli_results ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 193 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 194 | utilities.assert_equals( expect=main.TRUE, actual=case1_result, |
| 195 | onpass="Test startup successful", |
| 196 | onfail="Test startup NOT successful" ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 197 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 198 | if case1_result == main.FALSE: |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 199 | main.cleanup() |
| 200 | main.exit() |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 201 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 202 | def CASE2( self, main ): |
| 203 | """ |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 204 | Assign mastership to controllers |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 205 | """ |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 206 | import re |
| 207 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 208 | main.log.report( "Assigning switches to controllers" ) |
| 209 | main.case( "Assigning Controllers" ) |
| 210 | main.step( "Assign switches to controllers" ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 211 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 212 | for i in range( 1, 29 ): |
| 213 | main.Mininet1.assign_sw_controller( |
| 214 | sw=str( i ), |
| 215 | count=num_controllers, |
| 216 | ip1=ONOS1_ip, port1=ONOS1_port, |
| 217 | ip2=ONOS2_ip, port2=ONOS2_port, |
| 218 | ip3=ONOS3_ip, port3=ONOS3_port, |
| 219 | ip4=ONOS4_ip, port4=ONOS4_port, |
| 220 | ip5=ONOS5_ip, port5=ONOS5_port, |
| 221 | ip6=ONOS6_ip, port6=ONOS6_port, |
| 222 | ip7=ONOS7_ip, port7=ONOS7_port ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 223 | |
| 224 | mastership_check = main.TRUE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 225 | for i in range( 1, 29 ): |
| 226 | response = main.Mininet1.get_sw_controller( "s" + str( i ) ) |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 227 | try: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 228 | main.log.info( str( response ) ) |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 229 | except: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 230 | main.log.info( repr( response ) ) |
| 231 | if re.search( "tcp:" + ONOS1_ip, response )\ |
| 232 | and re.search( "tcp:" + ONOS2_ip, response )\ |
| 233 | and re.search( "tcp:" + ONOS3_ip, response )\ |
| 234 | and re.search( "tcp:" + ONOS4_ip, response )\ |
| 235 | and re.search( "tcp:" + ONOS5_ip, response )\ |
| 236 | and re.search( "tcp:" + ONOS6_ip, response )\ |
| 237 | and re.search( "tcp:" + ONOS7_ip, response ): |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 238 | mastership_check = mastership_check and main.TRUE |
| 239 | else: |
| 240 | mastership_check = main.FALSE |
| 241 | if mastership_check == main.TRUE: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 242 | main.log.report( "Switch mastership assigned correctly" ) |
| 243 | utilities.assert_equals( |
| 244 | expect=main.TRUE, |
| 245 | actual=mastership_check, |
| 246 | onpass="Switch mastership assigned correctly", |
| 247 | onfail="Switches not assigned correctly to controllers" ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 248 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 249 | # Manually assign mastership to the controller we want |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 250 | role_call = main.TRUE |
| 251 | role_check = main.TRUE |
| 252 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 253 | # Assign switch |
| 254 | device_id = main.ONOScli1.get_device( "1000" ).get( 'id' ) |
| 255 | role_call = role_call and main.ONOScli1.device_role( |
| 256 | device_id, |
| 257 | ONOS1_ip ) |
| 258 | # Check assignment |
| 259 | if ONOS1_ip in main.ONOScli1.get_role( device_id ).get( 'master' ): |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 260 | role_check = role_check and main.TRUE |
| 261 | else: |
| 262 | role_check = role_check and main.FALSE |
| 263 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 264 | # Assign switch |
| 265 | device_id = main.ONOScli1.get_device( "2800" ).get( 'id' ) |
| 266 | role_call = role_call and main.ONOScli1.device_role( |
| 267 | device_id, |
| 268 | ONOS1_ip ) |
| 269 | # Check assignment |
| 270 | if ONOS1_ip in main.ONOScli1.get_role( device_id ).get( 'master' ): |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 271 | role_check = role_check and main.TRUE |
| 272 | else: |
| 273 | role_check = role_check and main.FALSE |
| 274 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 275 | # Assign switch |
| 276 | device_id = main.ONOScli1.get_device( "2000" ).get( 'id' ) |
| 277 | role_call = role_call and main.ONOScli1.device_role( |
| 278 | device_id, |
| 279 | ONOS2_ip ) |
| 280 | # Check assignment |
| 281 | if ONOS2_ip in main.ONOScli1.get_role( device_id ).get( 'master' ): |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 282 | role_check = role_check and main.TRUE |
| 283 | else: |
| 284 | role_check = role_check and main.FALSE |
| 285 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 286 | # Assign switch |
| 287 | device_id = main.ONOScli1.get_device( "3000" ).get( 'id' ) |
| 288 | role_call = role_call and main.ONOScli1.device_role( |
| 289 | device_id, |
| 290 | ONOS2_ip ) |
| 291 | # Check assignment |
| 292 | if ONOS2_ip in main.ONOScli1.get_role( device_id ).get( 'master' ): |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 293 | role_check = role_check and main.TRUE |
| 294 | else: |
| 295 | role_check = role_check and main.FALSE |
| 296 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 297 | # Assign switch |
| 298 | device_id = main.ONOScli1.get_device( "5000" ).get( 'id' ) |
| 299 | role_call = role_call and main.ONOScli1.device_role( |
| 300 | device_id, |
| 301 | ONOS3_ip ) |
| 302 | # Check assignment |
| 303 | if ONOS3_ip in main.ONOScli1.get_role( device_id ).get( 'master' ): |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 304 | role_check = role_check and main.TRUE |
| 305 | else: |
| 306 | role_check = role_check and main.FALSE |
| 307 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 308 | # Assign switch |
| 309 | device_id = main.ONOScli1.get_device( "6000" ).get( 'id' ) |
| 310 | role_call = role_call and main.ONOScli1.device_role( |
| 311 | device_id, |
| 312 | ONOS3_ip ) |
| 313 | # Check assignment |
| 314 | if ONOS3_ip in main.ONOScli1.get_role( device_id ).get( 'master' ): |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 315 | role_check = role_check and main.TRUE |
| 316 | else: |
| 317 | role_check = role_check and main.FALSE |
| 318 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 319 | # Assign switch |
| 320 | device_id = main.ONOScli1.get_device( "3004" ).get( 'id' ) |
| 321 | role_call = role_call and main.ONOScli1.device_role( |
| 322 | device_id, |
| 323 | ONOS4_ip ) |
| 324 | # Check assignment |
| 325 | if ONOS4_ip in main.ONOScli1.get_role( device_id ).get( 'master' ): |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 326 | role_check = role_check and main.TRUE |
| 327 | else: |
| 328 | role_check = role_check and main.FALSE |
| 329 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 330 | for i in range( 8, 18 ): |
| 331 | dpid = '3' + str( i ).zfill( 3 ) |
| 332 | device_id = main.ONOScli1.get_device( dpid ).get( 'id' ) |
| 333 | role_call = role_call and main.ONOScli1.device_role( |
| 334 | device_id, |
| 335 | ONOS5_ip ) |
| 336 | # Check assignment |
| 337 | if ONOS5_ip in main.ONOScli1.get_role( device_id ).get( 'master' ): |
| 338 | role_check = role_check and main.TRUE |
| 339 | else: |
| 340 | role_check = role_check and main.FALSE |
| 341 | |
| 342 | device_id = main.ONOScli1.get_device( "6007" ).get( 'id' ) |
| 343 | role_call = role_call and main.ONOScli1.device_role( |
| 344 | device_id, |
| 345 | ONOS6_ip ) |
| 346 | # Check assignment |
| 347 | if ONOS6_ip in main.ONOScli1.get_role( device_id ).get( 'master' ): |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 348 | role_check = role_check and main.TRUE |
| 349 | else: |
| 350 | role_check = role_check and main.FALSE |
| 351 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 352 | for i in range( 18, 28 ): |
| 353 | dpid = '6' + str( i ).zfill( 3 ) |
| 354 | device_id = main.ONOScli1.get_device( dpid ).get( 'id' ) |
| 355 | role_call = role_call and main.ONOScli1.device_role( |
| 356 | device_id, |
| 357 | ONOS7_ip ) |
| 358 | # Check assignment |
| 359 | if ONOS7_ip in main.ONOScli1.get_role( device_id ).get( 'master' ): |
| 360 | role_check = role_check and main.TRUE |
| 361 | else: |
| 362 | role_check = role_check and main.FALSE |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 363 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 364 | utilities.assert_equals( |
| 365 | expect=main.TRUE, |
| 366 | actual=role_call, |
| 367 | onpass="Re-assigned switch mastership to designated controller", |
| 368 | onfail="Something wrong with device_role calls" ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 369 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 370 | utilities.assert_equals( |
| 371 | expect=main.TRUE, |
| 372 | actual=role_check, |
| 373 | onpass="Switches were successfully reassigned to designated " + |
| 374 | "controller", |
| 375 | onfail="Switches were not successfully reassigned" ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 376 | mastership_check = mastership_check and role_call and role_check |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 377 | utilities.assert_equals( expect=main.TRUE, actual=mastership_check, |
| 378 | onpass="Switch mastership correctly assigned", |
| 379 | onfail="Error in (re)assigning switch" + |
| 380 | " mastership" ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 381 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 382 | def CASE3( self, main ): |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 383 | """ |
| 384 | Assign intents |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 385 | """ |
| 386 | import time |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 387 | main.log.report( "Adding host intents" ) |
| 388 | main.case( "Adding host Intents" ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 389 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 390 | main.step( "Discovering Hosts( Via pingall for now)" ) |
| 391 | # FIXME: Once we have a host discovery mechanism, use that instead |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 392 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 393 | # install onos-app-fwd |
| 394 | main.log.info( "Install reactive forwarding app" ) |
| 395 | main.ONOScli1.feature_install( "onos-app-fwd" ) |
| 396 | main.ONOScli2.feature_install( "onos-app-fwd" ) |
| 397 | main.ONOScli3.feature_install( "onos-app-fwd" ) |
| 398 | main.ONOScli4.feature_install( "onos-app-fwd" ) |
| 399 | main.ONOScli5.feature_install( "onos-app-fwd" ) |
| 400 | main.ONOScli6.feature_install( "onos-app-fwd" ) |
| 401 | main.ONOScli7.feature_install( "onos-app-fwd" ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 402 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 403 | # REACTIVE FWD test |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 404 | ping_result = main.FALSE |
| 405 | time1 = time.time() |
| 406 | ping_result = main.Mininet1.pingall() |
| 407 | time2 = time.time() |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 408 | main.log.info( "Time for pingall: %2f seconds" % ( time2 - time1 ) ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 409 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 410 | # uninstall onos-app-fwd |
| 411 | main.log.info( "Uninstall reactive forwarding app" ) |
| 412 | main.ONOScli1.feature_uninstall( "onos-app-fwd" ) |
| 413 | main.ONOScli2.feature_uninstall( "onos-app-fwd" ) |
| 414 | main.ONOScli3.feature_uninstall( "onos-app-fwd" ) |
| 415 | main.ONOScli4.feature_uninstall( "onos-app-fwd" ) |
| 416 | main.ONOScli5.feature_uninstall( "onos-app-fwd" ) |
| 417 | main.ONOScli6.feature_uninstall( "onos-app-fwd" ) |
| 418 | main.ONOScli7.feature_uninstall( "onos-app-fwd" ) |
| 419 | # timeout for fwd flows |
| 420 | time.sleep( 10 ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 421 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 422 | main.step( "Add host intents" ) |
| 423 | # TODO: move the host numbers to params |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 424 | intent_add_result = True |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 425 | for i in range( 8, 18 ): |
| 426 | main.log.info( "Adding host intent between h" + str( i ) + |
| 427 | " and h" + str( i + 10 ) ) |
| 428 | host1 = "00:00:00:00:00:" + \ |
| 429 | str( hex( i )[ 2: ] ).zfill( 2 ).upper() |
| 430 | host2 = "00:00:00:00:00:" + \ |
| 431 | str( hex( i + 10 )[ 2: ] ).zfill( 2 ).upper() |
| 432 | host1_id = main.ONOScli1.get_host( host1 )[ 'id' ] |
| 433 | host2_id = main.ONOScli1.get_host( host2 )[ 'id' ] |
| 434 | # NOTE: get host can return None |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 435 | if host1_id and host2_id: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 436 | tmp_result = main.ONOScli1.add_host_intent( |
| 437 | host1_id, |
| 438 | host2_id ) |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 439 | else: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 440 | main.log.error( "Error, get_host() failed" ) |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 441 | tmp_result = main.FALSE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 442 | intent_add_result = bool( ping_result and intent_add_result |
| 443 | and tmp_result ) |
| 444 | utilities.assert_equals( |
| 445 | expect=True, |
| 446 | actual=intent_add_result, |
| 447 | onpass="Switch mastership correctly assigned", |
| 448 | onfail="Error in (re)assigning switch mastership" ) |
| 449 | # TODO Check if intents all exist in datastore |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 450 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 451 | def CASE4( self, main ): |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 452 | """ |
| 453 | Ping across added host intents |
| 454 | """ |
Jon Hall | 368769f | 2014-11-19 15:43:35 -0800 | [diff] [blame] | 455 | description = " Ping across added host intents" |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 456 | main.log.report( description ) |
| 457 | main.case( description ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 458 | Ping_Result = main.TRUE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 459 | for i in range( 8, 18 ): |
| 460 | ping = main.Mininet1.pingHost( |
| 461 | src="h" + str( i ), target="h" + str( i + 10 ) ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 462 | Ping_Result = Ping_Result and ping |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 463 | if ping == main.FALSE: |
| 464 | main.log.warn( "Ping failed between h" + str( i ) + |
| 465 | " and h" + str( i + 10 ) ) |
| 466 | elif ping == main.TRUE: |
| 467 | main.log.info( "Ping test passed!" ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 468 | Ping_Result = main.TRUE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 469 | if Ping_Result == main.FALSE: |
| 470 | main.log.report( |
| 471 | "Intents have not been installed correctly, pings failed." ) |
| 472 | if Ping_Result == main.TRUE: |
| 473 | main.log.report( |
| 474 | "Intents have been installed correctly and verified by pings" ) |
| 475 | utilities.assert_equals( |
| 476 | expect=main.TRUE, |
| 477 | actual=Ping_Result, |
| 478 | onpass="Intents have been installed correctly and pings work", |
| 479 | onfail="Intents have not been installed correctly, pings failed." ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 480 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 481 | def CASE5( self, main ): |
| 482 | """ |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 483 | Reading state of ONOS |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 484 | """ |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 485 | import json |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 486 | # assumes that sts is already in you PYTHONPATH |
| 487 | from sts.topology.teston_topology import TestONTopology |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 488 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 489 | main.log.report( "Setting up and gathering data for current state" ) |
| 490 | main.case( "Setting up and gathering data for current state" ) |
| 491 | # The general idea for this test case is to pull the state of |
| 492 | # ( intents,flows, topology,... ) from each ONOS node |
| 493 | # We can then compare them with eachother and also with past states |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 494 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 495 | main.step( "Get the Mastership of each switch from each controller" ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 496 | global mastership_state |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 497 | mastership_state = [] |
| 498 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 499 | # Assert that each device has a master |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 500 | ONOS1_master_not_null = main.ONOScli1.roles_not_null() |
| 501 | ONOS2_master_not_null = main.ONOScli2.roles_not_null() |
| 502 | ONOS3_master_not_null = main.ONOScli3.roles_not_null() |
| 503 | ONOS4_master_not_null = main.ONOScli4.roles_not_null() |
| 504 | ONOS5_master_not_null = main.ONOScli5.roles_not_null() |
| 505 | ONOS6_master_not_null = main.ONOScli6.roles_not_null() |
| 506 | ONOS7_master_not_null = main.ONOScli7.roles_not_null() |
| 507 | roles_not_null = ONOS1_master_not_null and ONOS2_master_not_null and\ |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 508 | ONOS3_master_not_null and ONOS4_master_not_null and\ |
| 509 | ONOS5_master_not_null and ONOS6_master_not_null and\ |
| 510 | ONOS7_master_not_null |
| 511 | utilities.assert_equals( |
| 512 | expect=main.TRUE, |
| 513 | actual=roles_not_null, |
| 514 | onpass="Each device has a master", |
| 515 | onfail="Some devices don't have a master assigned" ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 516 | |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 517 | ONOS1_mastership = main.ONOScli1.roles() |
| 518 | ONOS2_mastership = main.ONOScli2.roles() |
| 519 | ONOS3_mastership = main.ONOScli3.roles() |
| 520 | ONOS4_mastership = main.ONOScli4.roles() |
| 521 | ONOS5_mastership = main.ONOScli5.roles() |
| 522 | ONOS6_mastership = main.ONOScli6.roles() |
| 523 | ONOS7_mastership = main.ONOScli7.roles() |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 524 | # print json.dumps( json.loads( ONOS1_mastership ), sort_keys=True, |
| 525 | # indent=4, separators=( ',', ': ' ) ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 526 | if "Error" in ONOS1_mastership or not ONOS1_mastership\ |
| 527 | or "Error" in ONOS2_mastership or not ONOS2_mastership\ |
| 528 | or "Error" in ONOS3_mastership or not ONOS3_mastership\ |
| 529 | or "Error" in ONOS4_mastership or not ONOS4_mastership\ |
| 530 | or "Error" in ONOS5_mastership or not ONOS5_mastership\ |
| 531 | or "Error" in ONOS6_mastership or not ONOS6_mastership\ |
| 532 | or "Error" in ONOS7_mastership or not ONOS7_mastership: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 533 | main.log.report( "Error in getting ONOS roles" ) |
| 534 | main.log.warn( |
| 535 | "ONOS1 mastership response: " + |
| 536 | repr( ONOS1_mastership ) ) |
| 537 | main.log.warn( |
| 538 | "ONOS2 mastership response: " + |
| 539 | repr( ONOS2_mastership ) ) |
| 540 | main.log.warn( |
| 541 | "ONOS3 mastership response: " + |
| 542 | repr( ONOS3_mastership ) ) |
| 543 | main.log.warn( |
| 544 | "ONOS4 mastership response: " + |
| 545 | repr( ONOS4_mastership ) ) |
| 546 | main.log.warn( |
| 547 | "ONOS5 mastership response: " + |
| 548 | repr( ONOS5_mastership ) ) |
| 549 | main.log.warn( |
| 550 | "ONOS6 mastership response: " + |
| 551 | repr( ONOS6_mastership ) ) |
| 552 | main.log.warn( |
| 553 | "ONOS7 mastership response: " + |
| 554 | repr( ONOS7_mastership ) ) |
| 555 | consistent_mastership = main.FALSE |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 556 | elif ONOS1_mastership == ONOS2_mastership\ |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 557 | and ONOS1_mastership == ONOS3_mastership\ |
| 558 | and ONOS1_mastership == ONOS4_mastership\ |
| 559 | and ONOS1_mastership == ONOS5_mastership\ |
| 560 | and ONOS1_mastership == ONOS6_mastership\ |
| 561 | and ONOS1_mastership == ONOS7_mastership: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 562 | mastership_state = ONOS1_mastership |
| 563 | consistent_mastership = main.TRUE |
| 564 | main.log.report( |
| 565 | "Switch roles are consistent across all ONOS nodes" ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 566 | else: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 567 | main.log.warn( |
| 568 | "ONOS1 roles: ", |
| 569 | json.dumps( |
| 570 | json.loads( ONOS1_mastership ), |
| 571 | sort_keys=True, |
| 572 | indent=4, |
| 573 | separators=( |
| 574 | ',', |
| 575 | ': ' ) ) ) |
| 576 | main.log.warn( |
| 577 | "ONOS2 roles: ", |
| 578 | json.dumps( |
| 579 | json.loads( ONOS2_mastership ), |
| 580 | sort_keys=True, |
| 581 | indent=4, |
| 582 | separators=( |
| 583 | ',', |
| 584 | ': ' ) ) ) |
| 585 | main.log.warn( |
| 586 | "ONOS3 roles: ", |
| 587 | json.dumps( |
| 588 | json.loads( ONOS3_mastership ), |
| 589 | sort_keys=True, |
| 590 | indent=4, |
| 591 | separators=( |
| 592 | ',', |
| 593 | ': ' ) ) ) |
| 594 | main.log.warn( |
| 595 | "ONOS4 roles: ", |
| 596 | json.dumps( |
| 597 | json.loads( ONOS4_mastership ), |
| 598 | sort_keys=True, |
| 599 | indent=4, |
| 600 | separators=( |
| 601 | ',', |
| 602 | ': ' ) ) ) |
| 603 | main.log.warn( |
| 604 | "ONOS5 roles: ", |
| 605 | json.dumps( |
| 606 | json.loads( ONOS5_mastership ), |
| 607 | sort_keys=True, |
| 608 | indent=4, |
| 609 | separators=( |
| 610 | ',', |
| 611 | ': ' ) ) ) |
| 612 | main.log.warn( |
| 613 | "ONOS6 roles: ", |
| 614 | json.dumps( |
| 615 | json.loads( ONOS6_mastership ), |
| 616 | sort_keys=True, |
| 617 | indent=4, |
| 618 | separators=( |
| 619 | ',', |
| 620 | ': ' ) ) ) |
| 621 | main.log.warn( |
| 622 | "ONOS7 roles: ", |
| 623 | json.dumps( |
| 624 | json.loads( ONOS7_mastership ), |
| 625 | sort_keys=True, |
| 626 | indent=4, |
| 627 | separators=( |
| 628 | ',', |
| 629 | ': ' ) ) ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 630 | consistent_mastership = main.FALSE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 631 | utilities.assert_equals( |
| 632 | expect=main.TRUE, |
| 633 | actual=consistent_mastership, |
| 634 | onpass="Switch roles are consistent across all ONOS nodes", |
| 635 | onfail="ONOS nodes have different views of switch roles" ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 636 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 637 | main.step( "Get the intents from each controller" ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 638 | global intent_state |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 639 | intent_state = [] |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 640 | ONOS1_intents = main.ONOScli1.intents( json_format=True ) |
| 641 | ONOS2_intents = main.ONOScli2.intents( json_format=True ) |
| 642 | ONOS3_intents = main.ONOScli3.intents( json_format=True ) |
| 643 | ONOS4_intents = main.ONOScli4.intents( json_format=True ) |
| 644 | ONOS5_intents = main.ONOScli5.intents( json_format=True ) |
| 645 | ONOS6_intents = main.ONOScli6.intents( json_format=True ) |
| 646 | ONOS7_intents = main.ONOScli7.intents( json_format=True ) |
| 647 | intent_check = main.FALSE |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 648 | if "Error" in ONOS1_intents or not ONOS1_intents\ |
| 649 | or "Error" in ONOS2_intents or not ONOS2_intents\ |
| 650 | or "Error" in ONOS3_intents or not ONOS3_intents\ |
| 651 | or "Error" in ONOS4_intents or not ONOS4_intents\ |
| 652 | or "Error" in ONOS5_intents or not ONOS5_intents\ |
| 653 | or "Error" in ONOS6_intents or not ONOS6_intents\ |
| 654 | or "Error" in ONOS7_intents or not ONOS7_intents: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 655 | main.log.report( "Error in getting ONOS intents" ) |
| 656 | main.log.warn( "ONOS1 intents response: " + repr( ONOS1_intents ) ) |
| 657 | main.log.warn( "ONOS2 intents response: " + repr( ONOS2_intents ) ) |
| 658 | main.log.warn( "ONOS3 intents response: " + repr( ONOS3_intents ) ) |
| 659 | main.log.warn( "ONOS4 intents response: " + repr( ONOS4_intents ) ) |
| 660 | main.log.warn( "ONOS5 intents response: " + repr( ONOS5_intents ) ) |
| 661 | main.log.warn( "ONOS6 intents response: " + repr( ONOS6_intents ) ) |
| 662 | main.log.warn( "ONOS7 intents response: " + repr( ONOS7_intents ) ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 663 | elif ONOS1_intents == ONOS2_intents\ |
| 664 | and ONOS1_intents == ONOS3_intents\ |
| 665 | and ONOS1_intents == ONOS4_intents\ |
| 666 | and ONOS1_intents == ONOS5_intents\ |
| 667 | and ONOS1_intents == ONOS6_intents\ |
| 668 | and ONOS1_intents == ONOS7_intents: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 669 | intent_state = ONOS1_intents |
| 670 | intent_check = main.TRUE |
| 671 | main.log.report( "Intents are consistent across all ONOS nodes" ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 672 | else: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 673 | main.log.warn( |
| 674 | "ONOS1 intents: ", |
| 675 | json.dumps( |
| 676 | json.loads( ONOS1_intents ), |
| 677 | sort_keys=True, |
| 678 | indent=4, |
| 679 | separators=( |
| 680 | ',', |
| 681 | ': ' ) ) ) |
| 682 | main.log.warn( |
| 683 | "ONOS2 intents: ", |
| 684 | json.dumps( |
| 685 | json.loads( ONOS2_intents ), |
| 686 | sort_keys=True, |
| 687 | indent=4, |
| 688 | separators=( |
| 689 | ',', |
| 690 | ': ' ) ) ) |
| 691 | main.log.warn( |
| 692 | "ONOS3 intents: ", |
| 693 | json.dumps( |
| 694 | json.loads( ONOS3_intents ), |
| 695 | sort_keys=True, |
| 696 | indent=4, |
| 697 | separators=( |
| 698 | ',', |
| 699 | ': ' ) ) ) |
| 700 | main.log.warn( |
| 701 | "ONOS4 intents: ", |
| 702 | json.dumps( |
| 703 | json.loads( ONOS4_intents ), |
| 704 | sort_keys=True, |
| 705 | indent=4, |
| 706 | separators=( |
| 707 | ',', |
| 708 | ': ' ) ) ) |
| 709 | main.log.warn( |
| 710 | "ONOS5 intents: ", |
| 711 | json.dumps( |
| 712 | json.loads( ONOS5_intents ), |
| 713 | sort_keys=True, |
| 714 | indent=4, |
| 715 | separators=( |
| 716 | ',', |
| 717 | ': ' ) ) ) |
| 718 | main.log.warn( |
| 719 | "ONOS6 intents: ", |
| 720 | json.dumps( |
| 721 | json.loads( ONOS6_intents ), |
| 722 | sort_keys=True, |
| 723 | indent=4, |
| 724 | separators=( |
| 725 | ',', |
| 726 | ': ' ) ) ) |
| 727 | main.log.warn( |
| 728 | "ONOS7 intents: ", |
| 729 | json.dumps( |
| 730 | json.loads( ONOS7_intents ), |
| 731 | sort_keys=True, |
| 732 | indent=4, |
| 733 | separators=( |
| 734 | ',', |
| 735 | ': ' ) ) ) |
| 736 | utilities.assert_equals( |
| 737 | expect=main.TRUE, |
| 738 | actual=intent_check, |
| 739 | onpass="Intents are consistent across all ONOS nodes", |
| 740 | onfail="ONOS nodes have different views of intents" ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 741 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 742 | main.step( "Get the flows from each controller" ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 743 | global flow_state |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 744 | flow_state = [] |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 745 | ONOS1_flows = main.ONOScli1.flows( json_format=True ) |
| 746 | ONOS2_flows = main.ONOScli2.flows( json_format=True ) |
| 747 | ONOS3_flows = main.ONOScli3.flows( json_format=True ) |
| 748 | ONOS4_flows = main.ONOScli4.flows( json_format=True ) |
| 749 | ONOS5_flows = main.ONOScli5.flows( json_format=True ) |
| 750 | ONOS6_flows = main.ONOScli6.flows( json_format=True ) |
| 751 | ONOS7_flows = main.ONOScli7.flows( json_format=True ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 752 | ONOS1_flows_json = json.loads( ONOS1_flows ) |
| 753 | ONOS2_flows_json = json.loads( ONOS2_flows ) |
| 754 | ONOS3_flows_json = json.loads( ONOS3_flows ) |
| 755 | ONOS4_flows_json = json.loads( ONOS4_flows ) |
| 756 | ONOS5_flows_json = json.loads( ONOS5_flows ) |
| 757 | ONOS6_flows_json = json.loads( ONOS6_flows ) |
| 758 | ONOS7_flows_json = json.loads( ONOS7_flows ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 759 | flow_check = main.FALSE |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 760 | if "Error" in ONOS1_flows or not ONOS1_flows\ |
| 761 | or "Error" in ONOS2_flows or not ONOS2_flows\ |
| 762 | or "Error" in ONOS3_flows or not ONOS3_flows\ |
| 763 | or "Error" in ONOS4_flows or not ONOS4_flows\ |
| 764 | or "Error" in ONOS5_flows or not ONOS5_flows\ |
| 765 | or "Error" in ONOS6_flows or not ONOS6_flows\ |
| 766 | or "Error" in ONOS7_flows or not ONOS7_flows: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 767 | main.log.report( "Error in getting ONOS intents" ) |
| 768 | main.log.warn( "ONOS1 flows repsponse: " + ONOS1_flows ) |
| 769 | main.log.warn( "ONOS2 flows repsponse: " + ONOS2_flows ) |
| 770 | main.log.warn( "ONOS3 flows repsponse: " + ONOS3_flows ) |
| 771 | main.log.warn( "ONOS4 flows repsponse: " + ONOS4_flows ) |
| 772 | main.log.warn( "ONOS5 flows repsponse: " + ONOS5_flows ) |
| 773 | main.log.warn( "ONOS6 flows repsponse: " + ONOS6_flows ) |
| 774 | main.log.warn( "ONOS7 flows repsponse: " + ONOS7_flows ) |
| 775 | elif len( ONOS1_flows_json ) == len( ONOS2_flows_json )\ |
| 776 | and len( ONOS1_flows_json ) == len( ONOS3_flows_json )\ |
| 777 | and len( ONOS1_flows_json ) == len( ONOS4_flows_json )\ |
| 778 | and len( ONOS1_flows_json ) == len( ONOS5_flows_json )\ |
| 779 | and len( ONOS1_flows_json ) == len( ONOS6_flows_json )\ |
| 780 | and len( ONOS1_flows_json ) == len( ONOS7_flows_json ): |
| 781 | # TODO: Do a better check, maybe compare flows on switches? |
| 782 | flow_state = ONOS1_flows |
| 783 | flow_check = main.TRUE |
| 784 | main.log.report( "Flow count is consistent across all ONOS nodes" ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 785 | else: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 786 | main.log.warn( "ONOS1 flows: " + |
| 787 | json.dumps( ONOS1_flows_json, sort_keys=True, |
| 788 | indent=4, separators=( ',', ': ' ) ) ) |
| 789 | main.log.warn( "ONOS2 flows: " + |
| 790 | json.dumps( ONOS2_flows_json, sort_keys=True, |
| 791 | indent=4, separators=( ',', ': ' ) ) ) |
| 792 | main.log.warn( "ONOS3 flows: " + |
| 793 | json.dumps( ONOS3_flows_json, sort_keys=True, |
| 794 | indent=4, separators=( ',', ': ' ) ) ) |
| 795 | main.log.warn( "ONOS4 flows: " + |
| 796 | json.dumps( ONOS4_flows_json, sort_keys=True, |
| 797 | indent=4, separators=( ',', ': ' ) ) ) |
| 798 | main.log.warn( "ONOS5 flows: " + |
| 799 | json.dumps( ONOS5_flows_json, sort_keys=True, |
| 800 | indent=4, separators=( ',', ': ' ) ) ) |
| 801 | main.log.warn( "ONOS6 flows: " + |
| 802 | json.dumps( ONOS6_flows_json, sort_keys=True, |
| 803 | indent=4, separators=( ',', ': ' ) ) ) |
| 804 | main.log.warn( "ONOS7 flows: " + |
| 805 | json.dumps( ONOS7_flows_json, sort_keys=True, |
| 806 | indent=4, separators=( ',', ': ' ) ) ) |
| 807 | utilities.assert_equals( |
| 808 | expect=main.TRUE, |
| 809 | actual=flow_check, |
| 810 | onpass="The flow count is consistent across all ONOS nodes", |
| 811 | onfail="ONOS nodes have different flow counts" ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 812 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 813 | main.step( "Get the OF Table entries" ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 814 | global flows |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 815 | flows = [] |
| 816 | for i in range( 1, 29 ): |
| 817 | flows.append( main.Mininet2.get_flowTable( 1.3, "s" + str( i ) ) ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 818 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 819 | # TODO: Compare switch flow tables with ONOS flow tables |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 820 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 821 | main.step( "Start continuous pings" ) |
| 822 | main.Mininet2.pingLong( |
| 823 | src=main.params[ 'PING' ][ 'source1' ], |
| 824 | target=main.params[ 'PING' ][ 'target1' ], |
| 825 | pingTime=500 ) |
| 826 | main.Mininet2.pingLong( |
| 827 | src=main.params[ 'PING' ][ 'source2' ], |
| 828 | target=main.params[ 'PING' ][ 'target2' ], |
| 829 | pingTime=500 ) |
| 830 | main.Mininet2.pingLong( |
| 831 | src=main.params[ 'PING' ][ 'source3' ], |
| 832 | target=main.params[ 'PING' ][ 'target3' ], |
| 833 | pingTime=500 ) |
| 834 | main.Mininet2.pingLong( |
| 835 | src=main.params[ 'PING' ][ 'source4' ], |
| 836 | target=main.params[ 'PING' ][ 'target4' ], |
| 837 | pingTime=500 ) |
| 838 | main.Mininet2.pingLong( |
| 839 | src=main.params[ 'PING' ][ 'source5' ], |
| 840 | target=main.params[ 'PING' ][ 'target5' ], |
| 841 | pingTime=500 ) |
| 842 | main.Mininet2.pingLong( |
| 843 | src=main.params[ 'PING' ][ 'source6' ], |
| 844 | target=main.params[ 'PING' ][ 'target6' ], |
| 845 | pingTime=500 ) |
| 846 | main.Mininet2.pingLong( |
| 847 | src=main.params[ 'PING' ][ 'source7' ], |
| 848 | target=main.params[ 'PING' ][ 'target7' ], |
| 849 | pingTime=500 ) |
| 850 | main.Mininet2.pingLong( |
| 851 | src=main.params[ 'PING' ][ 'source8' ], |
| 852 | target=main.params[ 'PING' ][ 'target8' ], |
| 853 | pingTime=500 ) |
| 854 | main.Mininet2.pingLong( |
| 855 | src=main.params[ 'PING' ][ 'source9' ], |
| 856 | target=main.params[ 'PING' ][ 'target9' ], |
| 857 | pingTime=500 ) |
| 858 | main.Mininet2.pingLong( |
| 859 | src=main.params[ 'PING' ][ 'source10' ], |
| 860 | target=main.params[ 'PING' ][ 'target10' ], |
| 861 | pingTime=500 ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 862 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 863 | main.step( "Create TestONTopology object" ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 864 | ctrls = [] |
| 865 | count = 1 |
| 866 | while True: |
| 867 | temp = () |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 868 | if ( 'ip' + str( count ) ) in main.params[ 'CTRL' ]: |
| 869 | temp = temp + ( getattr( main, ( 'ONOS' + str( count ) ) ), ) |
| 870 | temp = temp + ( "ONOS" + str( count ), ) |
| 871 | temp = temp + ( main.params[ 'CTRL' ][ 'ip' + str( count ) ], ) |
| 872 | temp = temp + \ |
| 873 | ( eval( main.params[ 'CTRL' ][ 'port' + str( count ) ] ), ) |
| 874 | ctrls.append( temp ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 875 | count = count + 1 |
| 876 | else: |
| 877 | break |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 878 | MNTopo = TestONTopology( |
| 879 | main.Mininet1, |
| 880 | ctrls ) # can also add Intent API info for intent operations |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 881 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 882 | main.step( "Collecting topology information from ONOS" ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 883 | devices = [] |
| 884 | devices.append( main.ONOScli1.devices() ) |
| 885 | devices.append( main.ONOScli2.devices() ) |
| 886 | devices.append( main.ONOScli3.devices() ) |
| 887 | devices.append( main.ONOScli4.devices() ) |
| 888 | devices.append( main.ONOScli5.devices() ) |
| 889 | devices.append( main.ONOScli6.devices() ) |
| 890 | devices.append( main.ONOScli7.devices() ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 891 | hosts = [] |
| 892 | hosts.append( main.ONOScli1.hosts() ) |
| 893 | hosts.append( main.ONOScli2.hosts() ) |
| 894 | hosts.append( main.ONOScli3.hosts() ) |
| 895 | hosts.append( main.ONOScli4.hosts() ) |
| 896 | hosts.append( main.ONOScli5.hosts() ) |
| 897 | hosts.append( main.ONOScli6.hosts() ) |
| 898 | hosts.append( main.ONOScli7.hosts() ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 899 | ports = [] |
| 900 | ports.append( main.ONOScli1.ports() ) |
| 901 | ports.append( main.ONOScli2.ports() ) |
| 902 | ports.append( main.ONOScli3.ports() ) |
| 903 | ports.append( main.ONOScli4.ports() ) |
| 904 | ports.append( main.ONOScli5.ports() ) |
| 905 | ports.append( main.ONOScli6.ports() ) |
| 906 | ports.append( main.ONOScli7.ports() ) |
| 907 | links = [] |
| 908 | links.append( main.ONOScli1.links() ) |
| 909 | links.append( main.ONOScli2.links() ) |
| 910 | links.append( main.ONOScli3.links() ) |
| 911 | links.append( main.ONOScli4.links() ) |
| 912 | links.append( main.ONOScli5.links() ) |
| 913 | links.append( main.ONOScli6.links() ) |
| 914 | links.append( main.ONOScli7.links() ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 915 | clusters = [] |
| 916 | clusters.append( main.ONOScli1.clusters() ) |
| 917 | clusters.append( main.ONOScli2.clusters() ) |
| 918 | clusters.append( main.ONOScli3.clusters() ) |
| 919 | clusters.append( main.ONOScli4.clusters() ) |
| 920 | clusters.append( main.ONOScli5.clusters() ) |
| 921 | clusters.append( main.ONOScli6.clusters() ) |
| 922 | clusters.append( main.ONOScli7.clusters() ) |
| 923 | paths = [] |
| 924 | temp_topo = main.ONOSbench.get_topology( main.ONOScli1.topology() ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 925 | paths.append( temp_topo.get( 'paths', False ) ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 926 | temp_topo = main.ONOSbench.get_topology( main.ONOScli2.topology() ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 927 | paths.append( temp_topo.get( 'paths', False ) ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 928 | temp_topo = main.ONOSbench.get_topology( main.ONOScli3.topology() ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 929 | paths.append( temp_topo.get( 'paths', False ) ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 930 | temp_topo = main.ONOSbench.get_topology( main.ONOScli4.topology() ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 931 | paths.append( temp_topo.get( 'paths', False ) ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 932 | temp_topo = main.ONOSbench.get_topology( main.ONOScli5.topology() ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 933 | paths.append( temp_topo.get( 'paths', False ) ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 934 | temp_topo = main.ONOSbench.get_topology( main.ONOScli6.topology() ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 935 | paths.append( temp_topo.get( 'paths', False ) ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 936 | temp_topo = main.ONOSbench.get_topology( main.ONOScli7.topology() ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 937 | paths.append( temp_topo.get( 'paths', False ) ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 938 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 939 | # Compare json objects for hosts, dataplane clusters and paths |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 940 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 941 | # hosts |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 942 | consistent_hosts_result = main.TRUE |
| 943 | for controller in range( len( hosts ) ): |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 944 | controller_str = str( controller + 1 ) |
| 945 | if "Error" not in hosts[ controller ]: |
| 946 | if hosts[ controller ] == hosts[ 0 ]: |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 947 | continue |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 948 | else: # hosts not consistent |
| 949 | main.log.report( "hosts from ONOS" + |
| 950 | controller_str + |
| 951 | " is inconsistent with ONOS1" ) |
| 952 | main.log.warn( repr( hosts[ controller ] ) ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 953 | consistent_hosts_result = main.FALSE |
| 954 | |
| 955 | else: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 956 | main.log.report( "Error in getting ONOS hosts from ONOS" + |
| 957 | controller_str ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 958 | consistent_hosts_result = main.FALSE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 959 | main.log.warn( "ONOS" + controller_str + |
| 960 | " hosts response: " + |
| 961 | repr( hosts[ controller ] ) ) |
| 962 | utilities.assert_equals( |
| 963 | expect=main.TRUE, |
| 964 | actual=consistent_hosts_result, |
| 965 | onpass="Hosts view is consistent across all ONOS nodes", |
| 966 | onfail="ONOS nodes have different views of hosts" ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 967 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 968 | # Strongly connected clusters of devices |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 969 | consistent_clusters_result = main.TRUE |
| 970 | for controller in range( len( clusters ) ): |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 971 | if "Error" not in clusters[ controller ]: |
| 972 | if clusters[ controller ] == clusters[ 0 ]: |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 973 | continue |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 974 | else: # clusters not consistent |
| 975 | main.log.report( "clusters from ONOS" + |
| 976 | controller_str + |
| 977 | " is inconsistent with ONOS1" ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 978 | consistent_clusters_result = main.FALSE |
| 979 | |
| 980 | else: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 981 | main.log.report( "Error in getting dataplane clusters " + |
| 982 | "from ONOS" + controller_str ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 983 | consistent_clusters_result = main.FALSE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 984 | main.log.warn( "ONOS" + controller_str + |
| 985 | " clusters response: " + |
| 986 | repr( clusters[ controller ] ) ) |
| 987 | utilities.assert_equals( |
| 988 | expect=main.TRUE, |
| 989 | actual=consistent_clusters_result, |
| 990 | onpass="Clusters view is consistent across all ONOS nodes", |
| 991 | onfail="ONOS nodes have different views of clusters" ) |
| 992 | # there should always only be one cluster |
| 993 | num_clusters = len( json.loads( clusters[ 0 ] ) ) |
| 994 | utilities.assert_equals( |
| 995 | expect=1, |
| 996 | actual=num_clusters, |
| 997 | onpass="ONOS shows 1 SCC", |
| 998 | onfail="ONOS shows " + |
| 999 | str( num_clusters ) + |
| 1000 | " SCCs" ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1001 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1002 | # paths |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1003 | consistent_paths_result = main.TRUE |
| 1004 | for controller in range( len( paths ) ): |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1005 | controller_str = str( controller + 1 ) |
| 1006 | if "Error" not in paths[ controller ]: |
| 1007 | if paths[ controller ] == paths[ 0 ]: |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1008 | continue |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1009 | else: # paths not consistent |
| 1010 | main.log.report( "paths from ONOS" + controller_str + |
| 1011 | " is inconsistent with ONOS1" ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1012 | consistent_paths_result = main.FALSE |
| 1013 | |
| 1014 | else: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1015 | main.log.report( "Error in getting paths from ONOS" + |
| 1016 | controller_str ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1017 | consistent_paths_result = main.FALSE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1018 | main.log.warn( "ONOS" + controller_str + " paths response: " + |
| 1019 | repr( paths[ controller ] ) ) |
| 1020 | utilities.assert_equals( |
| 1021 | expect=main.TRUE, |
| 1022 | actual=consistent_paths_result, |
| 1023 | onpass="Paths count is consistent across all ONOS nodes", |
| 1024 | onfail="ONOS nodes have different counts of paths" ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1025 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1026 | main.step( "Comparing ONOS topology to MN" ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1027 | devices_results = main.TRUE |
| 1028 | ports_results = main.TRUE |
| 1029 | links_results = main.TRUE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1030 | for controller in range( num_controllers ): |
| 1031 | controller_str = str( controller + 1 ) |
| 1032 | if devices[ controller ] or "Error" not in devices[ controller ]: |
| 1033 | current_devices_result = main.Mininet1.compare_switches( |
| 1034 | MNTopo, |
| 1035 | json.loads( |
| 1036 | devices[ controller ] ) ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1037 | else: |
| 1038 | current_devices_result = main.FALSE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1039 | utilities.assert_equals( expect=main.TRUE, |
| 1040 | actual=current_devices_result, |
| 1041 | onpass="ONOS" + controller_str + |
| 1042 | " Switches view is correct", |
| 1043 | onfail="ONOS" + controller_str + |
| 1044 | " Switches view is incorrect" ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1045 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1046 | if ports[ controller ] or "Error" not in ports[ controller ]: |
| 1047 | current_ports_result = main.Mininet1.compare_ports( |
| 1048 | MNTopo, |
| 1049 | json.loads( |
| 1050 | ports[ controller ] ) ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1051 | else: |
| 1052 | current_ports_result = main.FALSE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1053 | utilities.assert_equals( expect=main.TRUE, |
| 1054 | actual=current_ports_result, |
| 1055 | onpass="ONOS" + controller_str + |
| 1056 | " ports view is correct", |
| 1057 | onfail="ONOS" + controller_str + |
| 1058 | " ports view is incorrect" ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1059 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1060 | if links[ controller ] or "Error" not in links[ controller ]: |
| 1061 | current_links_result = main.Mininet1.compare_links( |
| 1062 | MNTopo, |
| 1063 | json.loads( |
| 1064 | links[ controller ] ) ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1065 | else: |
| 1066 | current_links_result = main.FALSE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1067 | utilities.assert_equals( expect=main.TRUE, |
| 1068 | actual=current_links_result, |
| 1069 | onpass="ONOS" + controller_str + |
| 1070 | " links view is correct", |
| 1071 | onfail="ONOS" + controller_str + |
| 1072 | " links view is incorrect" ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1073 | |
| 1074 | devices_results = devices_results and current_devices_result |
| 1075 | ports_results = ports_results and current_ports_result |
| 1076 | links_results = links_results and current_links_result |
| 1077 | |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1078 | topo_result = devices_results and ports_results and links_results\ |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1079 | and consistent_hosts_result and consistent_clusters_result\ |
| 1080 | and consistent_paths_result |
| 1081 | utilities.assert_equals( expect=main.TRUE, actual=topo_result, |
| 1082 | onpass="Topology Check Test successful", |
| 1083 | onfail="Topology Check Test NOT successful" ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1084 | |
| 1085 | final_assert = main.TRUE |
| 1086 | final_assert = final_assert and topo_result and flow_check \ |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1087 | and intent_check and consistent_mastership and roles_not_null |
| 1088 | utilities.assert_equals( expect=main.TRUE, actual=final_assert, |
| 1089 | onpass="State check successful", |
| 1090 | onfail="State check NOT successful" ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1091 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1092 | def CASE6( self, main ): |
| 1093 | """ |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1094 | The Failure case. Since this is the Sanity test, we do nothing. |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1095 | """ |
Jon Hall | 368769f | 2014-11-19 15:43:35 -0800 | [diff] [blame] | 1096 | import time |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1097 | main.log.report( "Wait 60 seconds instead of inducing a failure" ) |
| 1098 | time.sleep( 60 ) |
| 1099 | utilities.assert_equals( |
| 1100 | expect=main.TRUE, |
| 1101 | actual=main.TRUE, |
| 1102 | onpass="Sleeping 60 seconds", |
| 1103 | onfail="Something is terribly wrong with my math" ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1104 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1105 | def CASE7( self, main ): |
| 1106 | """ |
Jon Hall | 368769f | 2014-11-19 15:43:35 -0800 | [diff] [blame] | 1107 | Check state after ONOS failure |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1108 | """ |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1109 | import json |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1110 | main.case( "Running ONOS Constant State Tests" ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1111 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1112 | # Assert that each device has a master |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1113 | ONOS1_master_not_null = main.ONOScli1.roles_not_null() |
| 1114 | ONOS2_master_not_null = main.ONOScli2.roles_not_null() |
| 1115 | ONOS3_master_not_null = main.ONOScli3.roles_not_null() |
| 1116 | ONOS4_master_not_null = main.ONOScli4.roles_not_null() |
| 1117 | ONOS5_master_not_null = main.ONOScli5.roles_not_null() |
| 1118 | ONOS6_master_not_null = main.ONOScli6.roles_not_null() |
| 1119 | ONOS7_master_not_null = main.ONOScli7.roles_not_null() |
| 1120 | roles_not_null = ONOS1_master_not_null and ONOS2_master_not_null and\ |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1121 | ONOS3_master_not_null and ONOS4_master_not_null and\ |
| 1122 | ONOS5_master_not_null and ONOS6_master_not_null and\ |
| 1123 | ONOS7_master_not_null |
| 1124 | utilities.assert_equals( |
| 1125 | expect=main.TRUE, |
| 1126 | actual=roles_not_null, |
| 1127 | onpass="Each device has a master", |
| 1128 | onfail="Some devices don't have a master assigned" ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1129 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1130 | main.step( "Check if switch roles are consistent across all nodes" ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1131 | ONOS1_mastership = main.ONOScli1.roles() |
| 1132 | ONOS2_mastership = main.ONOScli2.roles() |
| 1133 | ONOS3_mastership = main.ONOScli3.roles() |
| 1134 | ONOS4_mastership = main.ONOScli4.roles() |
| 1135 | ONOS5_mastership = main.ONOScli5.roles() |
| 1136 | ONOS6_mastership = main.ONOScli6.roles() |
| 1137 | ONOS7_mastership = main.ONOScli7.roles() |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1138 | # print json.dumps( json.loads( ONOS1_mastership ), sort_keys=True, |
| 1139 | # indent=4, separators=( ',', ': ' ) ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1140 | if "Error" in ONOS1_mastership or not ONOS1_mastership\ |
| 1141 | or "Error" in ONOS2_mastership or not ONOS2_mastership\ |
| 1142 | or "Error" in ONOS3_mastership or not ONOS3_mastership\ |
| 1143 | or "Error" in ONOS4_mastership or not ONOS4_mastership\ |
| 1144 | or "Error" in ONOS5_mastership or not ONOS5_mastership\ |
| 1145 | or "Error" in ONOS6_mastership or not ONOS6_mastership\ |
| 1146 | or "Error" in ONOS7_mastership or not ONOS7_mastership: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1147 | main.log.error( "Error in getting ONOS mastership" ) |
| 1148 | main.log.warn( "ONOS1 mastership response: " + |
| 1149 | repr( ONOS1_mastership ) ) |
| 1150 | main.log.warn( "ONOS2 mastership response: " + |
| 1151 | repr( ONOS2_mastership ) ) |
| 1152 | main.log.warn( "ONOS3 mastership response: " + |
| 1153 | repr( ONOS3_mastership ) ) |
| 1154 | main.log.warn( "ONOS4 mastership response: " + |
| 1155 | repr( ONOS4_mastership ) ) |
| 1156 | main.log.warn( "ONOS5 mastership response: " + |
| 1157 | repr( ONOS5_mastership ) ) |
| 1158 | main.log.warn( "ONOS6 mastership response: " + |
| 1159 | repr( ONOS6_mastership ) ) |
| 1160 | main.log.warn( "ONOS7 mastership response: " + |
| 1161 | repr( ONOS7_mastership ) ) |
| 1162 | consistent_mastership = main.FALSE |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1163 | elif ONOS1_mastership == ONOS2_mastership\ |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1164 | and ONOS1_mastership == ONOS3_mastership\ |
| 1165 | and ONOS1_mastership == ONOS4_mastership\ |
| 1166 | and ONOS1_mastership == ONOS5_mastership\ |
| 1167 | and ONOS1_mastership == ONOS6_mastership\ |
| 1168 | and ONOS1_mastership == ONOS7_mastership: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1169 | consistent_mastership = main.TRUE |
| 1170 | main.log.report( |
| 1171 | "Switch roles are consistent across all ONOS nodes" ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1172 | else: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1173 | main.log.warn( "ONOS1 roles: ", json.dumps( |
| 1174 | json.loads( ONOS1_mastership ), sort_keys=True, indent=4, |
| 1175 | separators=( ',', ': ' ) ) ) |
| 1176 | main.log.warn( "ONOS2 roles: ", json.dumps( |
| 1177 | json.loads( ONOS2_mastership ), sort_keys=True, indent=4, |
| 1178 | separators=( ',', ': ' ) ) ) |
| 1179 | main.log.warn( "ONOS3 roles: ", json.dumps( |
| 1180 | json.loads( ONOS3_mastership ), sort_keys=True, indent=4, |
| 1181 | separators=( ',', ': ' ) ) ) |
| 1182 | main.log.warn( "ONOS4 roles: ", json.dumps( |
| 1183 | json.loads( ONOS4_mastership ), sort_keys=True, indent=4, |
| 1184 | separators=( ',', ': ' ) ) ) |
| 1185 | main.log.warn( "ONOS5 roles: ", json.dumps( |
| 1186 | json.loads( ONOS5_mastership ), sort_keys=True, indent=4, |
| 1187 | separators=( ',', ': ' ) ) ) |
| 1188 | main.log.warn( "ONOS6 roles: ", json.dumps( |
| 1189 | json.loads( ONOS6_mastership ), sort_keys=True, indent=4, |
| 1190 | separators=( ',', ': ' ) ) ) |
| 1191 | main.log.warn( "ONOS7 roles: ", json.dumps( |
| 1192 | json.loads( ONOS7_mastership ), sort_keys=True, indent=4, |
| 1193 | separators=( ',', ': ' ) ) ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1194 | consistent_mastership = main.FALSE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1195 | utilities.assert_equals( |
| 1196 | expect=main.TRUE, |
| 1197 | actual=consistent_mastership, |
| 1198 | onpass="Switch roles are consistent across all ONOS nodes", |
| 1199 | onfail="ONOS nodes have different views of switch roles" ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1200 | |
| 1201 | description2 = "Compare switch roles from before failure" |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1202 | main.step( description2 ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1203 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1204 | current_json = json.loads( ONOS1_mastership ) |
| 1205 | old_json = json.loads( mastership_state ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1206 | mastership_check = main.TRUE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1207 | for i in range( 1, 29 ): |
| 1208 | switchDPID = str( |
| 1209 | main.Mininet1.getSwitchDPID( |
| 1210 | switch="s" + |
| 1211 | str( i ) ) ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1212 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1213 | current = [ switch[ 'master' ] for switch in current_json |
| 1214 | if switchDPID in switch[ 'id' ] ] |
| 1215 | old = [ switch[ 'master' ] for switch in old_json |
| 1216 | if switchDPID in switch[ 'id' ] ] |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1217 | if current == old: |
| 1218 | mastership_check = mastership_check and main.TRUE |
| 1219 | else: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1220 | main.log.warn( "Mastership of switch %s changed" % switchDPID ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1221 | mastership_check = main.FALSE |
| 1222 | if mastership_check == main.TRUE: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1223 | main.log.report( "Mastership of Switches was not changed" ) |
| 1224 | utilities.assert_equals( |
| 1225 | expect=main.TRUE, |
| 1226 | actual=mastership_check, |
| 1227 | onpass="Mastership of Switches was not changed", |
| 1228 | onfail="Mastership of some switches changed" ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1229 | mastership_check = mastership_check and consistent_mastership |
| 1230 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1231 | main.step( "Get the intents and compare across all nodes" ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1232 | ONOS1_intents = main.ONOScli1.intents( json_format=True ) |
| 1233 | ONOS2_intents = main.ONOScli2.intents( json_format=True ) |
| 1234 | ONOS3_intents = main.ONOScli3.intents( json_format=True ) |
| 1235 | ONOS4_intents = main.ONOScli4.intents( json_format=True ) |
| 1236 | ONOS5_intents = main.ONOScli5.intents( json_format=True ) |
| 1237 | ONOS6_intents = main.ONOScli6.intents( json_format=True ) |
| 1238 | ONOS7_intents = main.ONOScli7.intents( json_format=True ) |
| 1239 | intent_check = main.FALSE |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1240 | if "Error" in ONOS1_intents or not ONOS1_intents\ |
| 1241 | or "Error" in ONOS2_intents or not ONOS2_intents\ |
| 1242 | or "Error" in ONOS3_intents or not ONOS3_intents\ |
| 1243 | or "Error" in ONOS4_intents or not ONOS4_intents\ |
| 1244 | or "Error" in ONOS5_intents or not ONOS5_intents\ |
| 1245 | or "Error" in ONOS6_intents or not ONOS6_intents\ |
| 1246 | or "Error" in ONOS7_intents or not ONOS7_intents: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1247 | main.log.report( "Error in getting ONOS intents" ) |
| 1248 | main.log.warn( "ONOS1 intents response: " + repr( ONOS1_intents ) ) |
| 1249 | main.log.warn( "ONOS2 intents response: " + repr( ONOS2_intents ) ) |
| 1250 | main.log.warn( "ONOS3 intents response: " + repr( ONOS3_intents ) ) |
| 1251 | main.log.warn( "ONOS4 intents response: " + repr( ONOS4_intents ) ) |
| 1252 | main.log.warn( "ONOS5 intents response: " + repr( ONOS5_intents ) ) |
| 1253 | main.log.warn( "ONOS6 intents response: " + repr( ONOS6_intents ) ) |
| 1254 | main.log.warn( "ONOS7 intents response: " + repr( ONOS7_intents ) ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1255 | elif ONOS1_intents == ONOS2_intents\ |
| 1256 | and ONOS1_intents == ONOS3_intents\ |
| 1257 | and ONOS1_intents == ONOS4_intents\ |
| 1258 | and ONOS1_intents == ONOS5_intents\ |
| 1259 | and ONOS1_intents == ONOS6_intents\ |
| 1260 | and ONOS1_intents == ONOS7_intents: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1261 | intent_check = main.TRUE |
| 1262 | main.log.report( "Intents are consistent across all ONOS nodes" ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1263 | else: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1264 | main.log.warn( "ONOS1 intents: " ) |
| 1265 | print json.dumps( json.loads( ONOS1_intents ), sort_keys=True, |
| 1266 | indent=4, separators=( ',', ': ' ) ) |
| 1267 | main.log.warn( "ONOS2 intents: " ) |
| 1268 | print json.dumps( json.loads( ONOS2_intents ), sort_keys=True, |
| 1269 | indent=4, separators=( ',', ': ' ) ) |
| 1270 | main.log.warn( "ONOS3 intents: " ) |
| 1271 | print json.dumps( json.loads( ONOS3_intents ), sort_keys=True, |
| 1272 | indent=4, separators=( ',', ': ' ) ) |
| 1273 | main.log.warn( "ONOS4 intents: " ) |
| 1274 | print json.dumps( json.loads( ONOS4_intents ), sort_keys=True, |
| 1275 | indent=4, separators=( ',', ': ' ) ) |
| 1276 | main.log.warn( "ONOS5 intents: " ) |
| 1277 | print json.dumps( json.loads( ONOS5_intents ), sort_keys=True, |
| 1278 | indent=4, separators=( ',', ': ' ) ) |
| 1279 | main.log.warn( "ONOS6 intents: " ) |
| 1280 | print json.dumps( json.loads( ONOS6_intents ), sort_keys=True, |
| 1281 | indent=4, separators=( ',', ': ' ) ) |
| 1282 | main.log.warn( "ONOS7 intents: " ) |
| 1283 | print json.dumps( json.loads( ONOS7_intents ), sort_keys=True, |
| 1284 | indent=4, separators=( ',', ': ' ) ) |
| 1285 | utilities.assert_equals( |
| 1286 | expect=main.TRUE, |
| 1287 | actual=intent_check, |
| 1288 | onpass="Intents are consistent across all ONOS nodes", |
| 1289 | onfail="ONOS nodes have different views of intents" ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1290 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1291 | # NOTE: Hazelcast has no durability, so intents are lost across system |
| 1292 | # restarts |
| 1293 | main.step( "Compare current intents with intents before the failure" ) |
| 1294 | # NOTE: this requires case 5 to pass for intent_state to be set. |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1295 | # maybe we should stop the test if that fails? |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1296 | if intent_state == ONOS1_intents: |
| 1297 | same_intents = main.TRUE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1298 | main.log.report( "Intents are consistent with before failure" ) |
| 1299 | # TODO: possibly the states have changed? we may need to figure out |
| 1300 | # what the aceptable states are |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1301 | else: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1302 | try: |
| 1303 | main.log.warn( "ONOS1 intents: " ) |
| 1304 | print json.dumps( json.loads( ONOS1_intents ), |
| 1305 | sort_keys=True, indent=4, |
| 1306 | separators=( ',', ': ' ) ) |
| 1307 | except: |
| 1308 | pass |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1309 | same_intents = main.FALSE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1310 | utilities.assert_equals( |
| 1311 | expect=main.TRUE, |
| 1312 | actual=same_intents, |
| 1313 | onpass="Intents are consistent with before failure", |
| 1314 | onfail="The Intents changed during failure" ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1315 | intent_check = intent_check and same_intents |
| 1316 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1317 | main.step( "Get the OF Table entries and compare to before " + |
| 1318 | "component failure" ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1319 | Flow_Tables = main.TRUE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1320 | flows2 = [] |
| 1321 | for i in range( 28 ): |
| 1322 | main.log.info( "Checking flow table on s" + str( i + 1 ) ) |
| 1323 | tmp_flows = main.Mininet2.get_flowTable( 1.3, "s" + str( i + 1 ) ) |
| 1324 | flows2.append( tmp_flows ) |
| 1325 | temp_result = main.Mininet2.flow_comp( |
| 1326 | flow1=flows[ i ], |
| 1327 | flow2=tmp_flows ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1328 | Flow_Tables = Flow_Tables and temp_result |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1329 | if Flow_Tables == main.FALSE: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1330 | main.log.info( "Differences in flow table for switch: s" + |
| 1331 | str( i + 1 ) ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1332 | if Flow_Tables == main.TRUE: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1333 | main.log.report( "No changes were found in the flow tables" ) |
| 1334 | utilities.assert_equals( |
| 1335 | expect=main.TRUE, |
| 1336 | actual=Flow_Tables, |
| 1337 | onpass="No changes were found in the flow tables", |
| 1338 | onfail="Changes were found in the flow tables" ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1339 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1340 | main.step( "Check the continuous pings to ensure that no packets " + |
| 1341 | "were dropped during component failure" ) |
| 1342 | # FIXME: This check is always failing. Investigate cause |
| 1343 | # NOTE: this may be something to do with file permsissions |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1344 | # or slight change in format |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1345 | main.Mininet2.pingKill( |
| 1346 | main.params[ 'TESTONUSER' ], |
| 1347 | main.params[ 'TESTONIP' ] ) |
| 1348 | Loss_In_Pings = main.FALSE |
| 1349 | # NOTE: checkForLoss returns main.FALSE with 0% packet loss |
| 1350 | for i in range( 8, 18 ): |
| 1351 | main.log.info( |
| 1352 | "Checking for a loss in pings along flow from s" + |
| 1353 | str( i ) ) |
| 1354 | Loss_In_Pings = main.Mininet2.checkForLoss( |
| 1355 | "/tmp/ping.h" + |
| 1356 | str( i ) ) or Loss_In_Pings |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1357 | if Loss_In_Pings == main.TRUE: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1358 | main.log.info( "Loss in ping detected" ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1359 | elif Loss_In_Pings == main.ERROR: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1360 | main.log.info( "There are multiple mininet process running" ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1361 | elif Loss_In_Pings == main.FALSE: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1362 | main.log.info( "No Loss in the pings" ) |
| 1363 | main.log.report( "No loss of dataplane connectivity" ) |
| 1364 | utilities.assert_equals( |
| 1365 | expect=main.FALSE, |
| 1366 | actual=Loss_In_Pings, |
| 1367 | onpass="No Loss of connectivity", |
| 1368 | onfail="Loss of dataplane connectivity detected" ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1369 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1370 | # Test of LeadershipElection |
| 1371 | # NOTE: this only works for the sanity test. In case of failures, |
| 1372 | # leader will likely change |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 1373 | leader = ONOS1_ip |
| 1374 | leader_result = main.TRUE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1375 | for controller in range( 1, num_controllers + 1 ): |
| 1376 | # loop through ONOScli handlers |
| 1377 | node = getattr( main, ( 'ONOScli' + str( controller ) ) ) |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 1378 | leaderN = node.election_test_leader() |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1379 | # verify leader is ONOS1 |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 1380 | if leaderN == leader: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1381 | # all is well |
| 1382 | # NOTE: In failure scenario, this could be a new node, maybe |
| 1383 | # check != ONOS1 |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 1384 | pass |
| 1385 | elif leaderN == main.FALSE: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1386 | # error in response |
| 1387 | main.log.report( "Something is wrong with " + |
| 1388 | "election_test_leader function," + |
| 1389 | " check the error logs" ) |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 1390 | leader_result = main.FALSE |
| 1391 | elif leader != leaderN: |
| 1392 | leader_result = main.FALSE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1393 | main.log.report( "ONOS" + str( controller ) + " sees " + |
| 1394 | str( leaderN ) + |
| 1395 | " as the leader of the election app. " + |
| 1396 | "Leader should be " + str( leader ) ) |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 1397 | if leader_result: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1398 | main.log.report( "Leadership election tests passed(consistent " + |
| 1399 | "view of leader across listeners and a new " + |
| 1400 | "leader was re-elected if applicable)" ) |
| 1401 | utilities.assert_equals( |
| 1402 | expect=main.TRUE, |
| 1403 | actual=leader_result, |
| 1404 | onpass="Leadership election passed", |
| 1405 | onfail="Something went wrong with Leadership election" ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1406 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1407 | result = mastership_check and intent_check and Flow_Tables and\ |
| 1408 | ( not Loss_In_Pings ) and roles_not_null and leader_result |
| 1409 | result = int( result ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1410 | if result == main.TRUE: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1411 | main.log.report( "Constant State Tests Passed" ) |
| 1412 | utilities.assert_equals( expect=main.TRUE, actual=result, |
| 1413 | onpass="Constant State Tests Passed", |
| 1414 | onfail="Constant state tests failed" ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1415 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1416 | def CASE8( self, main ): |
| 1417 | """ |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1418 | Compare topo |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1419 | """ |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1420 | import sys |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1421 | # FIXME add this path to params |
| 1422 | sys.path.append( "/home/admin/sts" ) |
| 1423 | # assumes that sts is already in you PYTHONPATH |
| 1424 | from sts.topology.teston_topology import TestONTopology |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1425 | import json |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1426 | import time |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1427 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1428 | description = "Compare ONOS Topology view to Mininet topology" |
| 1429 | main.case( description ) |
| 1430 | main.log.report( description ) |
| 1431 | main.step( "Create TestONTopology object" ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1432 | ctrls = [] |
| 1433 | count = 1 |
| 1434 | while True: |
| 1435 | temp = () |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1436 | if ( 'ip' + str( count ) ) in main.params[ 'CTRL' ]: |
| 1437 | temp = temp + ( getattr( main, ( 'ONOS' + str( count ) ) ), ) |
| 1438 | temp = temp + ( "ONOS" + str( count ), ) |
| 1439 | temp = temp + ( main.params[ 'CTRL' ][ 'ip' + str( count ) ], ) |
| 1440 | temp = temp + \ |
| 1441 | ( eval( main.params[ 'CTRL' ][ 'port' + str( count ) ] ), ) |
| 1442 | ctrls.append( temp ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1443 | count = count + 1 |
| 1444 | else: |
| 1445 | break |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1446 | MNTopo = TestONTopology( |
| 1447 | main.Mininet1, |
| 1448 | ctrls ) # can also add Intent API info for intent operations |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1449 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1450 | main.step( "Comparing ONOS topology to MN" ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1451 | devices_results = main.TRUE |
| 1452 | ports_results = main.TRUE |
| 1453 | links_results = main.TRUE |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1454 | topo_result = main.FALSE |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1455 | elapsed = 0 |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 1456 | count = 0 |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1457 | main.step( "Collecting topology information from ONOS" ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1458 | start_time = time.time() |
| 1459 | while topo_result == main.FALSE and elapsed < 60: |
Jon Hall | ffb386d | 2014-11-21 13:43:38 -0800 | [diff] [blame] | 1460 | count = count + 1 |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1461 | if count > 1: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1462 | # TODO: Depricate STS usage |
| 1463 | MNTopo = TestONTopology( |
| 1464 | main.Mininet1, |
| 1465 | ctrls ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1466 | cli_start = time.time() |
| 1467 | devices = [] |
| 1468 | devices.append( main.ONOScli1.devices() ) |
| 1469 | devices.append( main.ONOScli2.devices() ) |
| 1470 | devices.append( main.ONOScli3.devices() ) |
| 1471 | devices.append( main.ONOScli4.devices() ) |
| 1472 | devices.append( main.ONOScli5.devices() ) |
| 1473 | devices.append( main.ONOScli6.devices() ) |
| 1474 | devices.append( main.ONOScli7.devices() ) |
| 1475 | hosts = [] |
| 1476 | hosts.append( main.ONOScli1.hosts() ) |
| 1477 | hosts.append( main.ONOScli2.hosts() ) |
| 1478 | hosts.append( main.ONOScli3.hosts() ) |
| 1479 | hosts.append( main.ONOScli4.hosts() ) |
| 1480 | hosts.append( main.ONOScli5.hosts() ) |
| 1481 | hosts.append( main.ONOScli6.hosts() ) |
| 1482 | hosts.append( main.ONOScli7.hosts() ) |
| 1483 | ports = [] |
| 1484 | ports.append( main.ONOScli1.ports() ) |
| 1485 | ports.append( main.ONOScli2.ports() ) |
| 1486 | ports.append( main.ONOScli3.ports() ) |
| 1487 | ports.append( main.ONOScli4.ports() ) |
| 1488 | ports.append( main.ONOScli5.ports() ) |
| 1489 | ports.append( main.ONOScli6.ports() ) |
| 1490 | ports.append( main.ONOScli7.ports() ) |
| 1491 | links = [] |
| 1492 | links.append( main.ONOScli1.links() ) |
| 1493 | links.append( main.ONOScli2.links() ) |
| 1494 | links.append( main.ONOScli3.links() ) |
| 1495 | links.append( main.ONOScli4.links() ) |
| 1496 | links.append( main.ONOScli5.links() ) |
| 1497 | links.append( main.ONOScli6.links() ) |
| 1498 | links.append( main.ONOScli7.links() ) |
| 1499 | clusters = [] |
| 1500 | clusters.append( main.ONOScli1.clusters() ) |
| 1501 | clusters.append( main.ONOScli2.clusters() ) |
| 1502 | clusters.append( main.ONOScli3.clusters() ) |
| 1503 | clusters.append( main.ONOScli4.clusters() ) |
| 1504 | clusters.append( main.ONOScli5.clusters() ) |
| 1505 | clusters.append( main.ONOScli6.clusters() ) |
| 1506 | clusters.append( main.ONOScli7.clusters() ) |
| 1507 | paths = [] |
| 1508 | temp_topo = main.ONOSbench.get_topology( main.ONOScli1.topology() ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1509 | paths.append( temp_topo.get( 'paths', False ) ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1510 | temp_topo = main.ONOSbench.get_topology( main.ONOScli2.topology() ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1511 | paths.append( temp_topo.get( 'paths', False ) ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1512 | temp_topo = main.ONOSbench.get_topology( main.ONOScli3.topology() ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1513 | paths.append( temp_topo.get( 'paths', False ) ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1514 | temp_topo = main.ONOSbench.get_topology( main.ONOScli4.topology() ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1515 | paths.append( temp_topo.get( 'paths', False ) ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1516 | temp_topo = main.ONOSbench.get_topology( main.ONOScli5.topology() ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1517 | paths.append( temp_topo.get( 'paths', False ) ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1518 | temp_topo = main.ONOSbench.get_topology( main.ONOScli6.topology() ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1519 | paths.append( temp_topo.get( 'paths', False ) ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1520 | temp_topo = main.ONOSbench.get_topology( main.ONOScli7.topology() ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1521 | paths.append( temp_topo.get( 'paths', False ) ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1522 | |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1523 | elapsed = time.time() - start_time |
| 1524 | cli_time = time.time() - cli_start |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1525 | print "CLI time: " + str( cli_time ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1526 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1527 | for controller in range( num_controllers ): |
| 1528 | controller_str = str( controller + 1 ) |
| 1529 | if devices[ controller ] or "Error" not in devices[ |
| 1530 | controller ]: |
| 1531 | current_devices_result = main.Mininet1.compare_switches( |
| 1532 | MNTopo, |
| 1533 | json.loads( |
| 1534 | devices[ controller ] ) ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1535 | else: |
| 1536 | current_devices_result = main.FALSE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1537 | utilities.assert_equals( expect=main.TRUE, |
| 1538 | actual=current_devices_result, |
| 1539 | onpass="ONOS" + controller_str + |
| 1540 | " Switches view is correct", |
| 1541 | onfail="ONOS" + controller_str + |
| 1542 | " Switches view is incorrect" ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1543 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1544 | if ports[ controller ] or "Error" not in ports[ controller ]: |
| 1545 | current_ports_result = main.Mininet1.compare_ports( |
| 1546 | MNTopo, |
| 1547 | json.loads( |
| 1548 | ports[ controller ] ) ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1549 | else: |
| 1550 | current_ports_result = main.FALSE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1551 | utilities.assert_equals( expect=main.TRUE, |
| 1552 | actual=current_ports_result, |
| 1553 | onpass="ONOS" + controller_str + |
| 1554 | " ports view is correct", |
| 1555 | onfail="ONOS" + controller_str + |
| 1556 | " ports view is incorrect" ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1557 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1558 | if links[ controller ] or "Error" not in links[ controller ]: |
| 1559 | current_links_result = main.Mininet1.compare_links( |
| 1560 | MNTopo, |
| 1561 | json.loads( |
| 1562 | links[ controller ] ) ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1563 | else: |
| 1564 | current_links_result = main.FALSE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1565 | utilities.assert_equals( expect=main.TRUE, |
| 1566 | actual=current_links_result, |
| 1567 | onpass="ONOS" + controller_str + |
| 1568 | " links view is correct", |
| 1569 | onfail="ONOS" + controller_str + |
| 1570 | " links view is incorrect" ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1571 | devices_results = devices_results and current_devices_result |
| 1572 | ports_results = ports_results and current_ports_result |
| 1573 | links_results = links_results and current_links_result |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1574 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1575 | # Compare json objects for hosts, dataplane clusters and paths |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1576 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1577 | # hosts |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1578 | consistent_hosts_result = main.TRUE |
| 1579 | for controller in range( len( hosts ) ): |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1580 | controller_str = str( controller + 1 ) |
| 1581 | if "Error" not in hosts[ controller ]: |
| 1582 | if hosts[ controller ] == hosts[ 0 ]: |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1583 | continue |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1584 | else: # hosts not consistent |
| 1585 | main.log.report( "hosts from ONOS" + controller_str + |
| 1586 | " is inconsistent with ONOS1" ) |
| 1587 | main.log.warn( repr( hosts[ controller ] ) ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1588 | consistent_hosts_result = main.FALSE |
| 1589 | |
| 1590 | else: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1591 | main.log.report( "Error in getting ONOS hosts from ONOS" + |
| 1592 | controller_str ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1593 | consistent_hosts_result = main.FALSE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1594 | main.log.warn( "ONOS" + controller_str + |
| 1595 | " hosts response: " + |
| 1596 | repr( hosts[ controller ] ) ) |
| 1597 | utilities.assert_equals( |
| 1598 | expect=main.TRUE, |
| 1599 | actual=consistent_hosts_result, |
| 1600 | onpass="Hosts view is consistent across all ONOS nodes", |
| 1601 | onfail="ONOS nodes have different views of hosts" ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1602 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1603 | # Strongly connected clusters of devices |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1604 | consistent_clusters_result = main.TRUE |
| 1605 | for controller in range( len( clusters ) ): |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1606 | controller_str = str( controller + 1 ) |
| 1607 | if "Error" not in clusters[ controller ]: |
| 1608 | if clusters[ controller ] == clusters[ 0 ]: |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1609 | continue |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1610 | else: # clusters not consistent |
| 1611 | main.log.report( "clusters from ONOS" + |
| 1612 | controller_str + |
| 1613 | " is inconsistent with ONOS1" ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1614 | consistent_clusters_result = main.FALSE |
| 1615 | |
| 1616 | else: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1617 | main.log.report( "Error in getting dataplane clusters " + |
| 1618 | "from ONOS" + controller_str ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1619 | consistent_clusters_result = main.FALSE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1620 | main.log.warn( "ONOS" + controller_str + |
| 1621 | " clusters response: " + |
| 1622 | repr( clusters[ controller ] ) ) |
| 1623 | utilities.assert_equals( |
| 1624 | expect=main.TRUE, |
| 1625 | actual=consistent_clusters_result, |
| 1626 | onpass="Clusters view is consistent across all ONOS nodes", |
| 1627 | onfail="ONOS nodes have different views of clusters" ) |
| 1628 | # there should always only be one cluster |
| 1629 | num_clusters = len( json.loads( clusters[ 0 ] ) ) |
| 1630 | utilities.assert_equals( |
| 1631 | expect=1, |
| 1632 | actual=num_clusters, |
| 1633 | onpass="ONOS shows 1 SCC", |
| 1634 | onfail="ONOS shows " + |
| 1635 | str( num_clusters ) + |
| 1636 | " SCCs" ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1637 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1638 | # paths |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1639 | consistent_paths_result = main.TRUE |
| 1640 | for controller in range( len( paths ) ): |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1641 | controller_str = str( controller + 1 ) |
| 1642 | if "Error" not in paths[ controller ]: |
| 1643 | if paths[ controller ] == paths[ 0 ]: |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1644 | continue |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1645 | else: # paths not consistent |
| 1646 | main.log.report( "paths from ONOS" + controller_str + |
| 1647 | " is inconsistent with ONOS1" ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1648 | consistent_paths_result = main.FALSE |
| 1649 | |
| 1650 | else: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1651 | main.log.report( "Error in getting paths from ONOS" + |
| 1652 | controller_str ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1653 | consistent_paths_result = main.FALSE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1654 | main.log.warn( "ONOS" + controller_str + |
| 1655 | " paths response: " + |
| 1656 | repr( paths[ controller ] ) ) |
| 1657 | utilities.assert_equals( |
| 1658 | expect=main.TRUE, |
| 1659 | actual=consistent_paths_result, |
| 1660 | onpass="Paths count is consistent across all ONOS nodes", |
| 1661 | onfail="ONOS nodes have different counts of paths" ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1662 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1663 | topo_result = ( devices_results and ports_results and links_results |
| 1664 | and consistent_hosts_result |
| 1665 | and consistent_clusters_result |
| 1666 | and consistent_paths_result ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1667 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1668 | topo_result = topo_result and int( count <= 2 ) |
| 1669 | note = "note it takes about " + str( int( cli_time ) ) + \ |
| 1670 | " seconds for the test to make all the cli calls to fetch " +\ |
| 1671 | "the topology from each ONOS instance" |
| 1672 | main.log.report( |
| 1673 | "Very crass estimate for topology discovery/convergence(" + |
| 1674 | str( note ) + "): " + str( elapsed ) + " seconds, " + |
| 1675 | str( count ) + " tries" ) |
| 1676 | utilities.assert_equals( expect=main.TRUE, actual=topo_result, |
| 1677 | onpass="Topology Check Test successful", |
| 1678 | onfail="Topology Check Test NOT successful" ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1679 | if topo_result == main.TRUE: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1680 | main.log.report( "ONOS topology view matches Mininet topology" ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1681 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1682 | def CASE9( self, main ): |
| 1683 | """ |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1684 | Link s3-s28 down |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1685 | """ |
| 1686 | import time |
| 1687 | # NOTE: You should probably run a topology check after this |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1688 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1689 | link_sleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1690 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1691 | description = "Turn off a link to ensure that Link Discovery " +\ |
| 1692 | "is working properly" |
| 1693 | main.log.report( description ) |
| 1694 | main.case( description ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1695 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1696 | main.step( "Kill Link between s3 and s28" ) |
| 1697 | Link_Down = main.Mininet1.link( END1="s3", END2="s28", OPTION="down" ) |
| 1698 | main.log.info( |
| 1699 | "Waiting " + |
| 1700 | str( link_sleep ) + |
| 1701 | " seconds for link down to be discovered" ) |
| 1702 | time.sleep( link_sleep ) |
| 1703 | utilities.assert_equals( expect=main.TRUE, actual=Link_Down, |
| 1704 | onpass="Link down succesful", |
| 1705 | onfail="Failed to bring link down" ) |
| 1706 | # TODO do some sort of check here |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1707 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1708 | def CASE10( self, main ): |
| 1709 | """ |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1710 | Link s3-s28 up |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1711 | """ |
| 1712 | import time |
| 1713 | # NOTE: You should probably run a topology check after this |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1714 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1715 | link_sleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1716 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1717 | description = "Restore a link to ensure that Link Discovery is " + \ |
| 1718 | "working properly" |
| 1719 | main.log.report( description ) |
| 1720 | main.case( description ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1721 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1722 | main.step( "Bring link between s3 and s28 back up" ) |
| 1723 | Link_Up = main.Mininet1.link( END1="s3", END2="s28", OPTION="up" ) |
| 1724 | main.log.info( |
| 1725 | "Waiting " + |
| 1726 | str( link_sleep ) + |
| 1727 | " seconds for link up to be discovered" ) |
| 1728 | time.sleep( link_sleep ) |
| 1729 | utilities.assert_equals( expect=main.TRUE, actual=Link_Up, |
| 1730 | onpass="Link up succesful", |
| 1731 | onfail="Failed to bring link up" ) |
| 1732 | # TODO do some sort of check here |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1733 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1734 | def CASE11( self, main ): |
| 1735 | """ |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1736 | Switch Down |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1737 | """ |
| 1738 | # NOTE: You should probably run a topology check after this |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1739 | import time |
| 1740 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1741 | switch_sleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1742 | |
| 1743 | description = "Killing a switch to ensure it is discovered correctly" |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1744 | main.log.report( description ) |
| 1745 | main.case( description ) |
| 1746 | switch = main.params[ 'kill' ][ 'switch' ] |
| 1747 | switchDPID = main.params[ 'kill' ][ 'dpid' ] |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1748 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1749 | # TODO: Make this switch parameterizable |
| 1750 | main.step( "Kill " + switch ) |
| 1751 | main.log.report( "Deleting " + switch ) |
| 1752 | main.Mininet1.del_switch( switch ) |
| 1753 | main.log.info( "Waiting " + str( switch_sleep ) + |
| 1754 | " seconds for switch down to be discovered" ) |
| 1755 | time.sleep( switch_sleep ) |
| 1756 | device = main.ONOScli1.get_device( dpid=switchDPID ) |
| 1757 | # Peek at the deleted switch |
| 1758 | main.log.warn( str( device ) ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1759 | result = main.FALSE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1760 | if device and device[ 'available' ] is False: |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1761 | result = main.TRUE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1762 | utilities.assert_equals( expect=main.TRUE, actual=result, |
| 1763 | onpass="Kill switch succesful", |
| 1764 | onfail="Failed to kill switch?" ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1765 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1766 | def CASE12( self, main ): |
| 1767 | """ |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1768 | Switch Up |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1769 | """ |
| 1770 | # NOTE: You should probably run a topology check after this |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1771 | import time |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 1772 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1773 | switch_sleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] ) |
| 1774 | switch = main.params[ 'kill' ][ 'switch' ] |
| 1775 | switchDPID = main.params[ 'kill' ][ 'dpid' ] |
| 1776 | links = main.params[ 'kill' ][ 'links' ].split() |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1777 | description = "Adding a switch to ensure it is discovered correctly" |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1778 | main.log.report( description ) |
| 1779 | main.case( description ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1780 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1781 | main.step( "Add back " + switch ) |
| 1782 | main.log.report( "Adding back " + switch ) |
| 1783 | main.Mininet1.add_switch( switch, dpid=switchDPID ) |
| 1784 | # TODO: New dpid or same? Ask Thomas? |
| 1785 | for peer in links: |
| 1786 | main.Mininet1.add_link( switch, peer ) |
| 1787 | main.Mininet1.assign_sw_controller( |
| 1788 | sw=switch.split( 's' )[ 1 ], |
| 1789 | count=num_controllers, |
| 1790 | ip1=ONOS1_ip, |
| 1791 | port1=ONOS1_port, |
| 1792 | ip2=ONOS2_ip, |
| 1793 | port2=ONOS2_port, |
| 1794 | ip3=ONOS3_ip, |
| 1795 | port3=ONOS3_port, |
| 1796 | ip4=ONOS4_ip, |
| 1797 | port4=ONOS4_port, |
| 1798 | ip5=ONOS5_ip, |
| 1799 | port5=ONOS5_port, |
| 1800 | ip6=ONOS6_ip, |
| 1801 | port6=ONOS6_port, |
| 1802 | ip7=ONOS7_ip, |
| 1803 | port7=ONOS7_port ) |
| 1804 | main.log.info( |
| 1805 | "Waiting " + |
| 1806 | str( switch_sleep ) + |
| 1807 | " seconds for switch up to be discovered" ) |
| 1808 | time.sleep( switch_sleep ) |
| 1809 | device = main.ONOScli1.get_device( dpid=switchDPID ) |
| 1810 | # Peek at the deleted switch |
| 1811 | main.log.warn( str( device ) ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1812 | result = main.FALSE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1813 | if device and device[ 'available' ]: |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1814 | result = main.TRUE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1815 | utilities.assert_equals( expect=main.TRUE, actual=result, |
| 1816 | onpass="add switch succesful", |
| 1817 | onfail="Failed to add switch?" ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1818 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1819 | def CASE13( self, main ): |
| 1820 | """ |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1821 | Clean up |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1822 | """ |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1823 | import os |
| 1824 | import time |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1825 | # TODO: make use of this elsewhere |
| 1826 | ips = [] |
| 1827 | ips.append(ONOS1_ip) |
| 1828 | ips.append(ONOS2_ip) |
| 1829 | ips.append(ONOS3_ip) |
| 1830 | ips.append(ONOS4_ip) |
| 1831 | ips.append(ONOS5_ip) |
| 1832 | ips.append(ONOS6_ip) |
| 1833 | ips.append(ONOS7_ip) |
| 1834 | |
| 1835 | # printing colors to terminal |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 1836 | colors = {} |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1837 | colors[ 'cyan' ] = '\033[96m' |
| 1838 | colors[ 'purple' ] = '\033[95m' |
| 1839 | colors[ 'blue' ] = '\033[94m' |
| 1840 | colors[ 'green' ] = '\033[92m' |
| 1841 | colors[ 'yellow' ] = '\033[93m' |
| 1842 | colors[ 'red' ] = '\033[91m' |
| 1843 | colors[ 'end' ] = '\033[0m' |
Jon Hall | 368769f | 2014-11-19 15:43:35 -0800 | [diff] [blame] | 1844 | description = "Test Cleanup" |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1845 | main.log.report( description ) |
| 1846 | main.case( description ) |
| 1847 | main.step( "Killing tcpdumps" ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1848 | main.Mininet2.stop_tcpdump() |
| 1849 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1850 | main.step( "Checking ONOS Logs for errors" ) |
| 1851 | for i in range(7): |
| 1852 | print colors[ 'purple' ] + "Checking logs for errors on " + \ |
| 1853 | "ONOS" + str( i + 1 ) + ":" + colors[ 'end' ] |
| 1854 | print main.ONOSbench.check_logs( ips[i] ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1855 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1856 | main.step( "Copying MN pcap and ONOS log files to test station" ) |
Jon Hall | b1290e8 | 2014-11-18 16:17:48 -0500 | [diff] [blame] | 1857 | testname = main.TEST |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1858 | teststation_user = main.params[ 'TESTONUSER' ] |
| 1859 | teststation_IP = main.params[ 'TESTONIP' ] |
| 1860 | # NOTE: MN Pcap file is being saved to ~/packet_captures |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1861 | # scp this file as MN and TestON aren't necessarily the same vm |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1862 | # FIXME: scp |
| 1863 | # mn files |
| 1864 | # TODO: Load these from params |
| 1865 | # NOTE: must end in / |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1866 | log_folder = "/opt/onos/log/" |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1867 | log_files = [ "karaf.log", "karaf.log.1" ] |
| 1868 | # NOTE: must end in / |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1869 | dst_dir = "~/packet_captures/" |
| 1870 | for f in log_files: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1871 | for i in range(7): |
| 1872 | main.ONOSbench.handle.sendline( "scp sdn@" + ips[i] + ":" + |
| 1873 | log_folder + f + " " + |
| 1874 | teststation_user + "@" + |
| 1875 | teststation_IP + ":" + |
| 1876 | dst_dir + str( testname ) + |
| 1877 | "-ONOS" + str( i + 1 ) + "-" + |
| 1878 | f ) |
| 1879 | # std*.log's |
| 1880 | # NOTE: must end in / |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1881 | log_folder = "/opt/onos/var/" |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1882 | log_files = [ "stderr.log", "stdout.log" ] |
| 1883 | # NOTE: must end in / |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1884 | dst_dir = "~/packet_captures/" |
| 1885 | for f in log_files: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1886 | for i in range(7): |
| 1887 | main.ONOSbench.handle.sendline( "scp sdn@" + ips[i] + ":" + |
| 1888 | log_folder + f + " " + |
| 1889 | teststation_user + "@" + |
| 1890 | teststation_IP + ":" + |
| 1891 | dst_dir + str( testname ) + |
| 1892 | "-ONOS" + str( i + 1 ) + "-" + |
| 1893 | f ) |
| 1894 | # sleep so scp can finish |
| 1895 | time.sleep( 10 ) |
| 1896 | main.step( "Packing and rotating pcap archives" ) |
| 1897 | os.system( "~/TestON/dependencies/rotate.sh " + str( testname ) ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1898 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1899 | # TODO: actually check something here |
| 1900 | utilities.assert_equals( expect=main.TRUE, actual=main.TRUE, |
| 1901 | onpass="Test cleanup successful", |
| 1902 | onfail="Test cleanup NOT successful" ) |
Jon Hall | 73cf9cc | 2014-11-20 22:28:38 -0800 | [diff] [blame] | 1903 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1904 | def CASE14( self, main ): |
| 1905 | """ |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1906 | start election app on all onos nodes |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1907 | """ |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 1908 | leader_result = main.TRUE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1909 | # install app on onos 1 |
| 1910 | main.log.info( "Install leadership election app" ) |
| 1911 | main.ONOScli1.feature_install( "onos-app-election" ) |
| 1912 | # wait for election |
| 1913 | # check for leader |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 1914 | leader = main.ONOScli1.election_test_leader() |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1915 | # verify leader is ONOS1 |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 1916 | if leader == ONOS1_ip: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1917 | # all is well |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 1918 | pass |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1919 | elif leader is None: |
| 1920 | # No leader elected |
| 1921 | main.log.report( "No leader was elected" ) |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 1922 | leader_result = main.FALSE |
| 1923 | elif leader == main.FALSE: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1924 | # error in response |
| 1925 | # TODO: add check for "Command not found:" in the driver, this |
| 1926 | # means the app isn't loaded |
| 1927 | main.log.report( "Something is wrong with election_test_leader" + |
| 1928 | " function, check the error logs" ) |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 1929 | leader_result = main.FALSE |
| 1930 | else: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1931 | # error in response |
| 1932 | main.log.report( |
| 1933 | "Unexpected response from election_test_leader function:'" + |
| 1934 | str(leader) + |
| 1935 | "'" ) |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 1936 | leader_result = main.FALSE |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1937 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1938 | # install on other nodes and check for leader. |
| 1939 | # Should be onos1 and each app should show the same leader |
| 1940 | for controller in range( 2, num_controllers + 1 ): |
| 1941 | # loop through ONOScli handlers |
| 1942 | node = getattr( main, ( 'ONOScli' + str( controller ) ) ) |
| 1943 | node.feature_install( "onos-app-election" ) |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 1944 | leaderN = node.election_test_leader() |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1945 | # verify leader is ONOS1 |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 1946 | if leaderN == ONOS1_ip: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1947 | # all is well |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 1948 | pass |
| 1949 | elif leaderN == main.FALSE: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1950 | # error in response |
| 1951 | # TODO: add check for "Command not found:" in the driver, this |
| 1952 | # means the app isn't loaded |
| 1953 | main.log.report( "Something is wrong with " + |
| 1954 | "election_test_leader function, check the" + |
| 1955 | " error logs" ) |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 1956 | leader_result = main.FALSE |
| 1957 | elif leader != leaderN: |
| 1958 | leader_result = main.FALSE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1959 | main.log.report( "ONOS" + str( controller ) + " sees " + |
| 1960 | str( leaderN ) + |
| 1961 | " as the leader of the election app. Leader" + |
| 1962 | " should be " + |
| 1963 | str( leader ) ) |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 1964 | if leader_result: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1965 | main.log.report( "Leadership election tests passed( consistent " + |
| 1966 | "view of leader across listeners and a leader " + |
| 1967 | "was elected)" ) |
| 1968 | utilities.assert_equals( |
| 1969 | expect=main.TRUE, |
| 1970 | actual=leader_result, |
| 1971 | onpass="Leadership election passed", |
| 1972 | onfail="Something went wrong with Leadership election" ) |
Jon Hall | 94fd047 | 2014-12-08 11:52:42 -0800 | [diff] [blame] | 1973 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1974 | def CASE15( self, main ): |
| 1975 | """ |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 1976 | Check that Leadership Election is still functional |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1977 | """ |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 1978 | leader_result = main.TRUE |
| 1979 | description = "Check that Leadership Election is still functional" |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1980 | main.log.report( description ) |
| 1981 | main.case( description ) |
| 1982 | main.step( "Find current leader and withdraw" ) |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 1983 | leader = main.ONOScli1.election_test_leader() |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 1984 | # TODO: do some sanity checking on leader before using it |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 1985 | withdraw_result = main.FALSE |
| 1986 | if leader == ONOS1_ip: |
| 1987 | old_leader = getattr( main, "ONOScli1" ) |
| 1988 | elif leader == ONOS2_ip: |
| 1989 | old_leader = getattr( main, "ONOScli2" ) |
| 1990 | elif leader == ONOS3_ip: |
| 1991 | old_leader = getattr( main, "ONOScli3" ) |
| 1992 | elif leader == ONOS4_ip: |
| 1993 | old_leader = getattr( main, "ONOScli4" ) |
| 1994 | elif leader == ONOS5_ip: |
| 1995 | old_leader = getattr( main, "ONOScli5" ) |
| 1996 | elif leader == ONOS6_ip: |
| 1997 | old_leader = getattr( main, "ONOScli6" ) |
| 1998 | elif leader == ONOS7_ip: |
| 1999 | old_leader = getattr( main, "ONOScli7" ) |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2000 | elif leader is None or leader == main.FALSE: |
| 2001 | main.log.report( |
| 2002 | "Leader for the election app should be an ONOS node," + |
| 2003 | "instead got '" + |
| 2004 | str(leader) + |
| 2005 | "'" ) |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 2006 | leader_result = main.FALSE |
| 2007 | withdraw_result = old_leader.election_test_withdraw() |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2008 | utilities.assert_equals( |
| 2009 | expect=main.TRUE, |
| 2010 | actual=withdraw_result, |
| 2011 | onpass="App was withdrawn from election", |
| 2012 | onfail="App was not withdrawn from election" ) |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 2013 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2014 | main.step( "Make sure new leader is elected" ) |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 2015 | leader_list = [] |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2016 | for controller in range( 1, num_controllers + 1 ): |
| 2017 | # loop through ONOScli handlers |
| 2018 | node = getattr( main, ( 'ONOScli' + str( controller ) ) ) |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 2019 | leader_list.append( node.election_test_leader() ) |
| 2020 | for leaderN in leader_list: |
| 2021 | if leaderN == leader: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2022 | main.log.report( |
| 2023 | "ONOS" + |
| 2024 | str( controller ) + |
| 2025 | " still sees " + |
| 2026 | str( leader ) + |
| 2027 | " as leader after they withdrew" ) |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 2028 | leader_result = main.FALSE |
| 2029 | elif leaderN == main.FALSE: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2030 | # error in response |
| 2031 | # TODO: add check for "Command not found:" in the driver, this |
| 2032 | # means the app isn't loaded |
| 2033 | main.log.report( "Something is wrong with " + |
| 2034 | "election_test_leader function, " + |
| 2035 | "check the error logs" ) |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 2036 | leader_result = main.FALSE |
| 2037 | consistent_leader = main.FALSE |
| 2038 | if len( set( leader_list ) ) == 1: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2039 | main.log.info( "Each Election-app sees '" + |
| 2040 | str(leader_list[0]) + |
| 2041 | "' as the leader" ) |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 2042 | consistent_leader = main.TRUE |
| 2043 | else: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2044 | main.log.report( |
| 2045 | "Inconsistent responses for leader of Election-app:" ) |
| 2046 | for n in range( len( leader_list ) ): |
| 2047 | main.log.report( "ONOS" + str( n + 1 ) + " response: " + |
| 2048 | str( leader_list[ n ] ) ) |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 2049 | if leader_result: |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2050 | main.log.report( "Leadership election tests passed(consistent " + |
| 2051 | "view of leader across listeners and a new " + |
| 2052 | "leader was elected when the old leader " + |
| 2053 | "resigned)" ) |
| 2054 | utilities.assert_equals( |
| 2055 | expect=main.TRUE, |
| 2056 | actual=leader_result, |
| 2057 | onpass="Leadership election passed", |
| 2058 | onfail="Something went wrong with Leadership election" ) |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 2059 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2060 | main.step( |
| 2061 | "Run for election on old leader(just so everyone is in the hat)" ) |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 2062 | run_result = old_leader.election_test_run() |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2063 | utilities.assert_equals( |
| 2064 | expect=main.TRUE, |
| 2065 | actual=run_result, |
| 2066 | onpass="App re-ran for election", |
| 2067 | onfail="App failed to run for election" ) |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 2068 | if consistent_leader == main.TRUE: |
| 2069 | after_run = main.ONOScli1.election_test_leader() |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2070 | # verify leader didn't just change |
| 2071 | if after_run == leader_list[ 0 ]: |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 2072 | leader_result = main.TRUE |
| 2073 | else: |
| 2074 | leader_result = main.FALSE |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2075 | # TODO: assert on run and withdraw results? |
Jon Hall | 669173b | 2014-12-17 11:36:30 -0800 | [diff] [blame] | 2076 | |
Jon Hall | 6aec96b | 2015-01-19 14:49:31 -0800 | [diff] [blame] | 2077 | utilities.assert_equals( |
| 2078 | expect=main.TRUE, |
| 2079 | actual=leader_result, |
| 2080 | onpass="Leadership election passed", |
| 2081 | onfail="Something went wrong with Leadership election after " + |
| 2082 | "the old leader re-ran for election" ) |