Teru | ab4b01a | 2013-06-20 10:09:57 -0700 | [diff] [blame] | 1 | package net.onrc.onos.ofcontroller.core.internal; |
| 2 | |
| 3 | import static org.easymock.EasyMock.*; |
| 4 | |
Pankaj Berde | 38646d6 | 2013-06-21 11:34:04 -0700 | [diff] [blame] | 5 | import net.onrc.onos.graph.GraphDBConnection; |
| 6 | import net.onrc.onos.graph.GraphDBOperation; |
Teru | ab4b01a | 2013-06-20 10:09:57 -0700 | [diff] [blame] | 7 | import net.onrc.onos.ofcontroller.core.ISwitchStorage; |
| 8 | import net.onrc.onos.ofcontroller.core.ISwitchStorage.SwitchState; |
| 9 | import net.onrc.onos.ofcontroller.core.internal.SwitchStorageImpl; |
Teru | ab4b01a | 2013-06-20 10:09:57 -0700 | [diff] [blame] | 10 | import net.onrc.onos.ofcontroller.core.INetMapStorage.DM_OPERATION; |
| 11 | import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IPortObject; |
| 12 | import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.ISwitchObject; |
| 13 | import org.easymock.EasyMock; |
| 14 | import org.junit.After; |
| 15 | import org.junit.Before; |
Teru | ab4b01a | 2013-06-20 10:09:57 -0700 | [diff] [blame] | 16 | import org.junit.Test; |
| 17 | import org.junit.runner.RunWith; |
| 18 | import org.openflow.protocol.OFPhysicalPort; |
| 19 | import org.openflow.protocol.OFPhysicalPort.OFPortState; |
| 20 | import org.powermock.api.easymock.PowerMock; |
| 21 | import org.powermock.core.classloader.annotations.PrepareForTest; |
| 22 | import org.powermock.modules.junit4.PowerMockRunner; |
| 23 | import org.slf4j.LoggerFactory; |
| 24 | |
| 25 | import com.thinkaurelius.titan.core.TitanFactory; |
| 26 | import com.thinkaurelius.titan.core.TitanGraph; |
| 27 | |
| 28 | //Add Powermock preparation |
| 29 | @RunWith(PowerMockRunner.class) |
| 30 | @PrepareForTest({TitanFactory.class, GraphDBConnection.class, GraphDBOperation.class, SwitchStorageImpl.class}) |
| 31 | public class SwitchStorageImplTest { |
| 32 | |
| 33 | protected static org.slf4j.Logger log = LoggerFactory.getLogger(SwitchStorageImpl.class); |
| 34 | |
| 35 | String conf; |
| 36 | private GraphDBConnection mockConn = null; |
| 37 | private GraphDBOperation mockOpe = null; |
| 38 | private GraphDBOperation realOpe = null; |
| 39 | private TitanGraph titanGraph = null; |
| 40 | ISwitchStorage swSt = null; |
| 41 | |
| 42 | @Before |
| 43 | public void setUp() throws Exception { |
| 44 | |
| 45 | swSt = new SwitchStorageImpl(); |
| 46 | conf = "/dummy/path/to/db"; |
| 47 | |
| 48 | // Make mock cassandra DB |
| 49 | // Replace TitanFactory.open() to return mock DB |
| 50 | |
| 51 | PowerMock.mockStatic(GraphDBConnection.class); |
| 52 | mockConn = createMock(GraphDBConnection.class); |
| 53 | PowerMock.suppress(PowerMock.constructor(GraphDBConnection.class)); |
| 54 | EasyMock.expect(GraphDBConnection.getInstance((String)EasyMock.anyObject())).andReturn(mockConn); |
| 55 | PowerMock.replay(GraphDBConnection.class); |
| 56 | |
| 57 | PowerMock.mockStatic(GraphDBOperation.class); |
| 58 | mockOpe = PowerMock.createStrictMock(GraphDBOperation.class); |
| 59 | PowerMock.expectNew(GraphDBOperation.class, mockConn).andReturn(mockOpe); |
| 60 | PowerMock.replay(GraphDBOperation.class); |
| 61 | // Replace the conf to dummy conf |
| 62 | // String conf = "/tmp/cassandra.titan"; |
| 63 | |
| 64 | |
| 65 | } |
| 66 | |
| 67 | @After |
| 68 | public void tearDown() throws Exception { |
| 69 | swSt.close(); |
| 70 | swSt = null; |
| 71 | |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * Desc: |
| 76 | * Test method for addSwitch method. |
| 77 | * Condition: |
| 78 | * Normal |
| 79 | * Expect: |
| 80 | * Call SwitchStorageImpl.addSwitch func with proper properties. |
| 81 | */ |
Teru | ab4b01a | 2013-06-20 10:09:57 -0700 | [diff] [blame] | 82 | @Test |
| 83 | public void testAddSwitch() { |
| 84 | String dpid = "00:00:00:00:00:00:0a:07"; |
| 85 | String state = "ACTIVE"; |
| 86 | |
| 87 | //Mock Switch |
| 88 | ISwitchObject mockISw = createMock(ISwitchObject.class); |
| 89 | mockISw.setState(state); |
| 90 | replay(mockISw); |
| 91 | |
| 92 | //Expectation of mock operation. |
| 93 | expect(mockOpe.searchSwitch(dpid)).andReturn(null); |
| 94 | expect(mockOpe.newSwitch(dpid)).andReturn(mockISw); |
| 95 | mockOpe.commit(); |
| 96 | mockOpe.close(); |
| 97 | replay(mockOpe); |
| 98 | |
| 99 | swSt.init(conf); |
| 100 | swSt.addSwitch(dpid); |
| 101 | } |
| 102 | |
| 103 | /** |
| 104 | * Desc: |
| 105 | * Test method for addSwitch method. |
| 106 | * Condition: |
| 107 | * The switch is already existing. |
| 108 | * Expect: |
| 109 | * Call SwitchStorageImpl.addSwitch func with proper properties. |
| 110 | */ |
| 111 | //@Ignore |
| 112 | @Test |
| 113 | public void testAddSwitchExisting() { |
| 114 | String dpid = "00:00:00:00:00:00:0a:07"; |
| 115 | String state = "ACTIVE"; |
| 116 | |
| 117 | //Mock Switch |
| 118 | ISwitchObject mockISw = createMock(ISwitchObject.class); |
| 119 | mockISw.setState(state); |
| 120 | mockISw.setState(state); |
| 121 | replay(mockISw); |
| 122 | |
| 123 | //Expectation of mock operation. |
| 124 | expect(mockOpe.searchSwitch(dpid)).andReturn(null); |
| 125 | expect(mockOpe.newSwitch(dpid)).andReturn(mockISw); |
| 126 | mockOpe.commit(); |
| 127 | expect(mockOpe.searchSwitch(dpid)).andReturn(mockISw); |
| 128 | mockOpe.commit(); |
| 129 | mockOpe.close(); |
| 130 | replay(mockOpe); |
| 131 | |
| 132 | swSt.init(conf); |
| 133 | swSt.addSwitch(dpid); |
| 134 | swSt.addSwitch(dpid); |
| 135 | } |
| 136 | |
| 137 | /** |
| 138 | * Desc: |
| 139 | * Test method for addSwitch method. |
| 140 | * Condition: |
| 141 | * The switch construction is fail and return null |
| 142 | * Expect: |
| 143 | * Write the status as info log. |
| 144 | */ |
Teru | ab4b01a | 2013-06-20 10:09:57 -0700 | [diff] [blame] | 145 | @Test |
| 146 | public void testAddSwitchAbnormal() { |
| 147 | String dpid = "00:00:00:00:00:00:0a:07"; |
| 148 | |
| 149 | //Expectation of mock operation. |
| 150 | expect(mockOpe.searchSwitch(dpid)).andReturn(null); |
| 151 | expect(mockOpe.newSwitch(dpid)).andReturn(null); |
HIGUCHI Yuta | fabb003 | 2013-06-28 11:31:33 -0700 | [diff] [blame] | 152 | mockOpe.rollback(); |
Teru | ab4b01a | 2013-06-20 10:09:57 -0700 | [diff] [blame] | 153 | mockOpe.close(); |
| 154 | replay(mockOpe); |
| 155 | |
| 156 | swSt.init(conf); |
| 157 | swSt.addSwitch(dpid); |
| 158 | } |
| 159 | |
| 160 | /** |
| 161 | * Desc: |
| 162 | * Test method for addSwitch method. |
| 163 | * Condition: |
HIGUCHI Yuta | fabb003 | 2013-06-28 11:31:33 -0700 | [diff] [blame] | 164 | * Throw runtimeException. |
Teru | ab4b01a | 2013-06-20 10:09:57 -0700 | [diff] [blame] | 165 | * Expect: |
| 166 | * The rollback method is called. |
| 167 | */ |
| 168 | //@Ignore |
| 169 | @Test |
| 170 | public void testAddSwitchException() { |
| 171 | String dpid = "00:00:00:00:00:00:0a:07"; |
| 172 | String state = "ACTIVE"; |
| 173 | |
| 174 | //Mock Switch |
| 175 | ISwitchObject mockISw = createMock(ISwitchObject.class); |
| 176 | mockISw.setState(state); |
| 177 | replay(mockISw); |
| 178 | |
| 179 | //Expectation of mock operation. |
| 180 | expect(mockOpe.searchSwitch(dpid)).andReturn(null); |
| 181 | expect(mockOpe.newSwitch(dpid)).andReturn(mockISw); |
| 182 | mockOpe.commit(); |
| 183 | expectLastCall().andThrow(new RuntimeException()); |
| 184 | mockOpe.rollback(); |
| 185 | mockOpe.close(); |
| 186 | replay(mockOpe); |
| 187 | |
| 188 | swSt.init(conf); |
| 189 | swSt.addSwitch(dpid); |
| 190 | } |
| 191 | |
| 192 | /** |
| 193 | * Desc: |
| 194 | * Test method for updateSwitch method. |
| 195 | * Condition: |
| 196 | * SwitchState : INACTIVE |
| 197 | * DMOPERATION : UPDATE |
| 198 | * Expect: |
| 199 | * Should call addSwitch function and commit. |
| 200 | */ |
| 201 | //@Ignore |
| 202 | @Test |
| 203 | public void testUpdateUPDATE() { |
| 204 | String dpid = "00:00:00:00:00:00:0a:07"; |
| 205 | SwitchState stateINACTIVE = SwitchState.INACTIVE; |
| 206 | DM_OPERATION opUPDATE = DM_OPERATION.UPDATE; |
| 207 | |
| 208 | //Mock Switch |
| 209 | ISwitchObject mockISw = createMock(ISwitchObject.class); |
| 210 | mockISw.setState("ACTIVE"); |
| 211 | mockISw.setState(stateINACTIVE.toString()); |
| 212 | replay(mockISw); |
| 213 | |
| 214 | //Expectation of mock operation. |
| 215 | expect(mockOpe.searchSwitch(dpid)).andReturn(null); |
| 216 | expect(mockOpe.newSwitch(dpid)).andReturn(mockISw); |
| 217 | mockOpe.commit(); |
| 218 | expect(mockOpe.searchSwitch(dpid)).andReturn(mockISw); |
| 219 | mockOpe.commit(); |
| 220 | mockOpe.close(); |
| 221 | replay(mockOpe); |
| 222 | |
| 223 | swSt.init(conf); |
| 224 | swSt.update(dpid, stateINACTIVE, opUPDATE); |
| 225 | } |
| 226 | |
| 227 | /** |
| 228 | * Desc: |
| 229 | * Test method for updateSwitch method. |
| 230 | * Condition: |
| 231 | * SwitchState : INACTIVE |
| 232 | * DMOPERATION : CREATE |
| 233 | * Expect: |
| 234 | * Should call addSwitch function and commit. |
| 235 | */ |
| 236 | //@Ignore |
| 237 | @Test |
| 238 | public void testUpdateCREATE() { |
| 239 | String dpid = "00:00:00:00:00:00:0a:07"; |
| 240 | SwitchState stateINACTIVE = SwitchState.INACTIVE; |
| 241 | DM_OPERATION opCREATE = DM_OPERATION.CREATE; |
| 242 | |
| 243 | //Mock Switch |
| 244 | ISwitchObject mockISw = createMock(ISwitchObject.class); |
| 245 | mockISw.setState("ACTIVE"); |
| 246 | mockISw.setState(stateINACTIVE.toString()); |
| 247 | replay(mockISw); |
| 248 | |
| 249 | //Expectation of mock operation. |
| 250 | expect(mockOpe.searchSwitch(dpid)).andReturn(null); |
| 251 | expect(mockOpe.newSwitch(dpid)).andReturn(mockISw); |
| 252 | mockOpe.commit(); |
| 253 | expect(mockOpe.searchSwitch(dpid)).andReturn(mockISw); |
| 254 | mockOpe.commit(); |
| 255 | mockOpe.close(); |
| 256 | replay(mockOpe); |
| 257 | |
| 258 | swSt.init(conf); |
| 259 | swSt.update(dpid, stateINACTIVE, opCREATE); |
| 260 | } |
| 261 | |
| 262 | /** |
| 263 | * Desc: |
| 264 | * Test method for updateSwitch method. |
| 265 | * Condition: |
| 266 | * SwitchState : INACTIVE |
| 267 | * DMOPERATION : INSERT |
| 268 | * Expect: |
| 269 | * Should call addSwitch function and commit. |
| 270 | */ |
| 271 | //@Ignore |
| 272 | @Test |
| 273 | public void testUpdateINSERT() { |
| 274 | String dpid = "00:00:00:00:00:00:0a:07"; |
| 275 | SwitchState stateINACTIVE = SwitchState.INACTIVE; |
| 276 | DM_OPERATION opINSERT = DM_OPERATION.INSERT; |
| 277 | |
| 278 | //Mock Switch |
| 279 | ISwitchObject mockISw = createMock(ISwitchObject.class); |
| 280 | mockISw.setState("ACTIVE"); |
| 281 | mockISw.setState(stateINACTIVE.toString()); |
| 282 | replay(mockISw); |
| 283 | |
| 284 | //Expectation of mock operation. |
| 285 | expect(mockOpe.searchSwitch(dpid)).andReturn(null); |
| 286 | expect(mockOpe.newSwitch(dpid)).andReturn(mockISw); |
| 287 | mockOpe.commit(); |
| 288 | expect(mockOpe.searchSwitch(dpid)).andReturn(mockISw); |
| 289 | mockOpe.commit(); |
| 290 | mockOpe.close(); |
| 291 | replay(mockOpe); |
| 292 | |
| 293 | swSt.init(conf); |
| 294 | swSt.update(dpid, stateINACTIVE, opINSERT); |
| 295 | } |
| 296 | |
| 297 | /** |
| 298 | * Desc: |
| 299 | * Test method for updateSwitch method. |
| 300 | * Condition: |
| 301 | * SwitchState : ACTIVE |
| 302 | * DMOPERATION : DELETE |
| 303 | * Expect: |
| 304 | * Should call removeSwitch function and commit. |
| 305 | */ |
| 306 | //@Ignore |
| 307 | @Test |
| 308 | public void testUpdateDELETE() { |
| 309 | String dpid = "00:00:00:00:00:00:0a:07"; |
| 310 | SwitchState stateACTIVE = SwitchState.ACTIVE; |
| 311 | DM_OPERATION opDELETE = DM_OPERATION.DELETE; |
| 312 | |
| 313 | //Mock Switch |
| 314 | ISwitchObject mockISw = createMock(ISwitchObject.class); |
| 315 | mockISw.setState(stateACTIVE.toString()); |
| 316 | replay(mockISw); |
| 317 | |
| 318 | //Expectation of mock operation. |
| 319 | expect(mockOpe.searchSwitch(dpid)).andReturn(null); |
| 320 | expect(mockOpe.newSwitch(dpid)).andReturn(mockISw); |
| 321 | mockOpe.commit(); |
| 322 | expect(mockOpe.searchSwitch(dpid)).andReturn(mockISw); |
| 323 | mockOpe.removeSwitch(mockISw); |
| 324 | mockOpe.commit(); |
| 325 | mockOpe.close(); |
| 326 | replay(mockOpe); |
| 327 | |
| 328 | swSt.init(conf); |
| 329 | swSt.addSwitch(dpid); |
| 330 | swSt.update(dpid, stateACTIVE, opDELETE); |
| 331 | } |
| 332 | |
| 333 | /** |
| 334 | * Desc: |
| 335 | * Test method for deleteSwitch method. |
| 336 | * Condition: |
| 337 | * The switch is existing. |
| 338 | * Expect: |
| 339 | * Should call removeSwitch function and commit. |
| 340 | */ |
| 341 | //@Ignore |
| 342 | @Test |
| 343 | public void testDeleteSwitch() { |
| 344 | String dpid = "00:00:00:00:00:00:0a:07"; |
| 345 | String state = "ACTIVE"; |
| 346 | |
| 347 | //Mock Switch |
| 348 | ISwitchObject mockISw = createMock(ISwitchObject.class); |
| 349 | mockISw.setState(state); |
| 350 | replay(mockISw); |
| 351 | |
| 352 | //Expectation of mock operation. |
| 353 | expect(mockOpe.searchSwitch(dpid)).andReturn(null); |
| 354 | expect(mockOpe.newSwitch(dpid)).andReturn(mockISw); |
| 355 | mockOpe.commit(); |
| 356 | expect(mockOpe.searchSwitch(dpid)).andReturn(mockISw); |
| 357 | mockOpe.removeSwitch(mockISw); |
| 358 | mockOpe.commit(); |
| 359 | mockOpe.close(); |
| 360 | replay(mockOpe); |
| 361 | |
| 362 | swSt.init(conf); |
| 363 | swSt.addSwitch(dpid); |
| 364 | swSt.deleteSwitch(dpid); |
| 365 | |
| 366 | //Iterator<Vertex> it = titanGraph.getVertices("dpid", dpid).iterator(); |
| 367 | //assertFalse(it.hasNext()); |
| 368 | } |
| 369 | |
| 370 | /** |
| 371 | * Desc: |
| 372 | * Test method for deleteSwitch method. |
| 373 | * Condition: |
| 374 | * The commit func throw exception. |
| 375 | * Expect: |
| 376 | * Should call rollback. |
| 377 | */ |
| 378 | //@Ignore |
| 379 | @Test |
| 380 | public void testDeleteSwitchException() { |
| 381 | String dpid = "00:00:00:00:00:00:0a:07"; |
| 382 | String state = "ACTIVE"; |
| 383 | String type = ""; |
| 384 | |
| 385 | //Mock Switch |
| 386 | ISwitchObject mockISw = createMock(ISwitchObject.class); |
| 387 | mockISw.setState(state); |
| 388 | replay(mockISw); |
| 389 | |
| 390 | //Expectation of mock operation. |
| 391 | expect(mockOpe.searchSwitch(dpid)).andReturn(null); |
| 392 | expect(mockOpe.newSwitch(dpid)).andReturn(mockISw); |
| 393 | mockOpe.commit(); |
| 394 | expect(mockOpe.searchSwitch(dpid)).andReturn(mockISw); |
| 395 | mockOpe.removeSwitch(mockISw); |
| 396 | mockOpe.commit(); |
| 397 | expectLastCall().andThrow(new RuntimeException()); |
| 398 | mockOpe.rollback(); |
| 399 | mockOpe.close(); |
| 400 | replay(mockOpe); |
| 401 | |
| 402 | swSt.init(conf); |
| 403 | swSt.addSwitch(dpid); |
| 404 | swSt.deleteSwitch(dpid); |
| 405 | } |
| 406 | |
| 407 | /** |
| 408 | * Desc: |
| 409 | * Test method for addPort method. |
| 410 | * Condition: |
| 411 | * port is existing. |
| 412 | * Expect: |
| 413 | * Should call addPort and commit. |
| 414 | */ |
| 415 | //@Ignore |
| 416 | @Test |
| 417 | public void testAddPort() { |
| 418 | String dpid = "00:00:00:00:00:00:0a:01"; |
| 419 | short portNumber = 5; |
| 420 | String state = "ACTIVE"; |
| 421 | String name = "port 5 at SEA switch"; |
| 422 | |
| 423 | OFPhysicalPort portToAdd = new OFPhysicalPort(); |
| 424 | portToAdd.setName(name); |
| 425 | portToAdd.setCurrentFeatures(OFPhysicalPort.OFPortFeatures.OFPPF_100MB_FD.getValue()); |
| 426 | portToAdd.setPortNumber(portNumber); |
| 427 | portToAdd.setState(OFPortState.OFPPS_STP_FORWARD.getValue()); |
| 428 | |
| 429 | //Expectation of mock Port |
| 430 | IPortObject mockIPort = createMock(IPortObject.class); |
| 431 | mockIPort.setState(state); |
| 432 | mockIPort.setPortState(OFPortState.OFPPS_STP_FORWARD.getValue()); |
| 433 | mockIPort.setDesc(name); |
| 434 | replay(mockIPort); |
| 435 | |
| 436 | //Expectation of mock Switch |
| 437 | ISwitchObject mockISw = createMock(ISwitchObject.class); |
| 438 | mockISw.setState(state); |
| 439 | mockISw.addPort(mockIPort); |
| 440 | replay(mockISw); |
| 441 | |
| 442 | //Expectation of mock operation. |
| 443 | expect(mockOpe.searchSwitch(dpid)).andReturn(null); |
| 444 | expect(mockOpe.newSwitch(dpid)).andReturn(mockISw); |
| 445 | mockOpe.commit(); |
| 446 | expect(mockOpe.searchSwitch(dpid)).andReturn(mockISw); |
| 447 | expect(mockOpe.searchPort(dpid, portNumber)).andReturn(null); |
Pankaj Berde | bbd3861 | 2013-06-22 05:59:12 -0700 | [diff] [blame] | 448 | expect(mockOpe.newPort(dpid, portNumber)).andReturn(mockIPort); |
Teru | ab4b01a | 2013-06-20 10:09:57 -0700 | [diff] [blame] | 449 | mockOpe.commit(); |
| 450 | mockOpe.close(); |
| 451 | replay(mockOpe); |
| 452 | |
| 453 | swSt.init(conf); |
| 454 | swSt.addSwitch(dpid); |
| 455 | swSt.addPort(dpid, portToAdd); |
| 456 | } |
| 457 | |
| 458 | /** |
| 459 | * Desc: |
| 460 | * Test method for addPort method. |
| 461 | * Condition: |
| 462 | * Port status is down. |
| 463 | * Expect: |
| 464 | * Should call removePort and commit. |
| 465 | */ |
| 466 | //@Ignore |
| 467 | @Test |
| 468 | public void testAddPortWithPortLinkDown() { |
| 469 | String dpid = "00:00:00:00:00:00:0a:01"; |
| 470 | short portNumber = 5; |
Pankaj Berde | ac54a4b | 2013-08-02 15:31:28 -0700 | [diff] [blame] | 471 | String swState = "ACTIVE"; |
| 472 | String portState = "INACTIVE"; |
Teru | ab4b01a | 2013-06-20 10:09:57 -0700 | [diff] [blame] | 473 | String name = "port 5 at SEA switch"; |
| 474 | |
| 475 | OFPhysicalPort portToAdd = new OFPhysicalPort(); |
| 476 | portToAdd.setName(name); |
| 477 | portToAdd.setCurrentFeatures(OFPhysicalPort.OFPortFeatures.OFPPF_100MB_FD.getValue()); |
| 478 | portToAdd.setPortNumber(portNumber); |
| 479 | portToAdd.setState(OFPortState.OFPPS_LINK_DOWN.getValue()); |
| 480 | |
| 481 | //Expectation of mock Port |
| 482 | IPortObject mockIPort = createMock(IPortObject.class); |
Pankaj Berde | ac54a4b | 2013-08-02 15:31:28 -0700 | [diff] [blame] | 483 | mockIPort.setState(portState); |
Teru | ab4b01a | 2013-06-20 10:09:57 -0700 | [diff] [blame] | 484 | mockIPort.setPortState(OFPortState.OFPPS_STP_FORWARD.getValue()); |
| 485 | mockIPort.setDesc(name); |
| 486 | replay(mockIPort); |
| 487 | |
| 488 | //Expectation of mock Switch |
| 489 | ISwitchObject mockISw = createMock(ISwitchObject.class); |
Pankaj Berde | ac54a4b | 2013-08-02 15:31:28 -0700 | [diff] [blame] | 490 | mockISw.setState(swState); |
| 491 | // mockISw.removePort(mockIPort); |
Teru | ab4b01a | 2013-06-20 10:09:57 -0700 | [diff] [blame] | 492 | replay(mockISw); |
| 493 | |
| 494 | //Expectation of mock operation. |
| 495 | expect(mockOpe.searchSwitch(dpid)).andReturn(null); |
| 496 | expect(mockOpe.newSwitch(dpid)).andReturn(mockISw); |
| 497 | mockOpe.commit(); |
| 498 | expect(mockOpe.searchSwitch(dpid)).andReturn(mockISw); |
| 499 | expect(mockOpe.searchPort(dpid, portNumber)).andReturn(mockIPort); |
Pankaj Berde | ac54a4b | 2013-08-02 15:31:28 -0700 | [diff] [blame] | 500 | // mockOpe.removePort(mockIPort); |
Teru | ab4b01a | 2013-06-20 10:09:57 -0700 | [diff] [blame] | 501 | mockOpe.commit(); |
| 502 | mockOpe.close(); |
| 503 | replay(mockOpe); |
| 504 | |
| 505 | swSt.init(conf); |
| 506 | swSt.addSwitch(dpid); |
| 507 | swSt.addPort(dpid, portToAdd); |
| 508 | } |
| 509 | |
| 510 | /** |
| 511 | * Desc: |
| 512 | * Test method for addPort method. |
| 513 | * Condition: |
| 514 | * The switch is not existing. |
| 515 | * Expect: |
| 516 | * Nothing happens. |
| 517 | */ |
| 518 | //@Ignore |
| 519 | @Test |
| 520 | public void testAddPortAbnormalNoSwitch() { |
| 521 | String dpid = "00:00:00:00:00:00:0a:01"; |
| 522 | short portNumber = 5; |
| 523 | String state = "ACTIVE"; |
| 524 | String name = "port 5 at SEA switch"; |
| 525 | |
| 526 | OFPhysicalPort portToAdd = new OFPhysicalPort(); |
| 527 | portToAdd.setName(name); |
| 528 | portToAdd.setCurrentFeatures(OFPhysicalPort.OFPortFeatures.OFPPF_100MB_FD.getValue()); |
| 529 | portToAdd.setPortNumber(portNumber); |
| 530 | portToAdd.setState(OFPortState.OFPPS_STP_FORWARD.getValue()); |
| 531 | |
| 532 | //Expectation of mock Port |
| 533 | IPortObject mockIPort = createStrictMock(IPortObject.class); |
| 534 | replay(mockIPort); |
| 535 | |
| 536 | //Expectation of mock Switch |
| 537 | ISwitchObject mockISw = createStrictMock(ISwitchObject.class); |
| 538 | replay(mockISw); |
| 539 | |
| 540 | //Expectation of mock operation. |
| 541 | expect(mockOpe.searchSwitch(dpid)).andReturn(null); |
| 542 | mockOpe.close(); |
| 543 | replay(mockOpe); |
| 544 | |
| 545 | swSt.init(conf); |
| 546 | swSt.addPort(dpid, portToAdd); |
| 547 | } |
| 548 | |
| 549 | /** |
| 550 | * Desc: |
| 551 | * Test method for addPort method. |
| 552 | * Condition: |
| 553 | * port is not existing. |
| 554 | * Expect: |
| 555 | * Should call addPort and commit. |
| 556 | */ |
| 557 | //@Ignore |
| 558 | @Test |
| 559 | public void testAddPortAbnormalNoPort() { |
| 560 | String dpid = "00:00:00:00:00:00:0a:01"; |
| 561 | short portNumber = 5; |
| 562 | String state = "ACTIVE"; |
| 563 | String name = "port 5 at SEA switch"; |
| 564 | |
| 565 | OFPhysicalPort portToAdd = new OFPhysicalPort(); |
| 566 | portToAdd.setName(name); |
| 567 | portToAdd.setCurrentFeatures(OFPhysicalPort.OFPortFeatures.OFPPF_100MB_FD.getValue()); |
| 568 | portToAdd.setPortNumber(portNumber); |
| 569 | portToAdd.setState(OFPortState.OFPPS_STP_FORWARD.getValue()); |
| 570 | |
| 571 | //Expectation of mock Port |
| 572 | IPortObject mockIPort = createMock(IPortObject.class); |
| 573 | mockIPort.setState(state); |
| 574 | mockIPort.setPortState(OFPortState.OFPPS_STP_FORWARD.getValue()); |
| 575 | mockIPort.setDesc(name); |
| 576 | replay(mockIPort); |
| 577 | |
| 578 | //Expectation of mock Switch |
| 579 | ISwitchObject mockISw = createMock(ISwitchObject.class); |
| 580 | mockISw.setState(state); |
| 581 | mockISw.addPort(mockIPort); |
| 582 | replay(mockISw); |
| 583 | |
| 584 | //Expectation of mock operation. |
| 585 | expect(mockOpe.searchSwitch(dpid)).andReturn(null); |
| 586 | expect(mockOpe.newSwitch(dpid)).andReturn(mockISw); |
| 587 | mockOpe.commit(); |
| 588 | expect(mockOpe.searchSwitch(dpid)).andReturn(mockISw); |
| 589 | expect(mockOpe.searchPort(dpid, portNumber)).andReturn(null); |
Pankaj Berde | bbd3861 | 2013-06-22 05:59:12 -0700 | [diff] [blame] | 590 | expect(mockOpe.newPort(dpid, portNumber)).andReturn(null); |
Teru | ab4b01a | 2013-06-20 10:09:57 -0700 | [diff] [blame] | 591 | mockOpe.rollback(); |
| 592 | mockOpe.close(); |
| 593 | replay(mockOpe); |
| 594 | |
| 595 | swSt.init(conf); |
| 596 | swSt.addSwitch(dpid); |
| 597 | swSt.addPort(dpid, portToAdd); |
| 598 | } |
| 599 | |
| 600 | /** |
| 601 | * Desc: |
| 602 | * Test method for addPort method. |
| 603 | * Condition: |
| 604 | * commit throw the exception. |
| 605 | * Expect: |
| 606 | * Should call rollback. |
| 607 | */ |
| 608 | //@Ignore |
| 609 | @Test |
| 610 | public void testAddPortWithException() { |
| 611 | String dpid = "00:00:00:00:00:00:0a:01"; |
| 612 | short portNumber = 5; |
| 613 | String state = "ACTIVE"; |
| 614 | String name = "port 5 at SEA switch"; |
| 615 | |
| 616 | OFPhysicalPort portToAdd = new OFPhysicalPort(); |
| 617 | portToAdd.setName(name); |
| 618 | portToAdd.setCurrentFeatures(OFPhysicalPort.OFPortFeatures.OFPPF_100MB_FD.getValue()); |
| 619 | portToAdd.setPortNumber(portNumber); |
| 620 | portToAdd.setState(OFPortState.OFPPS_STP_FORWARD.getValue()); |
| 621 | |
| 622 | //Expectation of mock Port |
| 623 | IPortObject mockIPort = createMock(IPortObject.class); |
| 624 | mockIPort.setState(state); |
| 625 | mockIPort.setPortState(OFPortState.OFPPS_STP_FORWARD.getValue()); |
| 626 | mockIPort.setDesc(name); |
| 627 | replay(mockIPort); |
| 628 | |
| 629 | //Expectation of mock Switch |
| 630 | ISwitchObject mockISw = createMock(ISwitchObject.class); |
| 631 | mockISw.setState(state); |
| 632 | mockISw.addPort(mockIPort); |
| 633 | replay(mockISw); |
| 634 | |
| 635 | //Expectation of mock operation. |
| 636 | expect(mockOpe.searchSwitch(dpid)).andReturn(null); |
| 637 | expect(mockOpe.newSwitch(dpid)).andReturn(mockISw); |
| 638 | mockOpe.commit(); |
| 639 | expect(mockOpe.searchSwitch(dpid)).andReturn(mockISw); |
| 640 | expect(mockOpe.searchPort(dpid, portNumber)).andReturn(null); |
Pankaj Berde | bbd3861 | 2013-06-22 05:59:12 -0700 | [diff] [blame] | 641 | expect(mockOpe.newPort(dpid, portNumber)).andReturn(mockIPort); |
Teru | ab4b01a | 2013-06-20 10:09:57 -0700 | [diff] [blame] | 642 | mockOpe.commit(); |
| 643 | expectLastCall().andThrow(new RuntimeException()); |
| 644 | mockOpe.rollback(); |
| 645 | mockOpe.close(); |
| 646 | replay(mockOpe); |
| 647 | |
| 648 | swSt.init(conf); |
| 649 | swSt.addSwitch(dpid); |
| 650 | swSt.addPort(dpid, portToAdd); |
| 651 | } |
| 652 | |
| 653 | /** |
| 654 | * Desc: |
| 655 | * Test method for deletePort method. |
| 656 | * Condition: |
| 657 | * port is existing. |
| 658 | * Expect: |
| 659 | * Should call removePort and commit. |
| 660 | */ |
| 661 | //@Ignore |
| 662 | @Test |
| 663 | public void testDeletePort() { |
| 664 | String dpid = "00:00:00:00:00:00:0a:01"; |
| 665 | short portNumber = 5; |
Pankaj Berde | ac54a4b | 2013-08-02 15:31:28 -0700 | [diff] [blame] | 666 | String portState = "INACTIVE"; |
| 667 | String swState = "ACTIVE"; |
Teru | ab4b01a | 2013-06-20 10:09:57 -0700 | [diff] [blame] | 668 | String name = "port 5 at SEA switch"; |
| 669 | |
| 670 | OFPhysicalPort portToAdd = new OFPhysicalPort(); |
| 671 | portToAdd.setName(name); |
| 672 | portToAdd.setCurrentFeatures(OFPhysicalPort.OFPortFeatures.OFPPF_100MB_FD.getValue()); |
| 673 | portToAdd.setPortNumber(portNumber); |
| 674 | portToAdd.setState(OFPortState.OFPPS_STP_FORWARD.getValue()); |
| 675 | |
| 676 | //Expectation of mock Port |
| 677 | IPortObject mockIPort = createMock(IPortObject.class); |
Pankaj Berde | ac54a4b | 2013-08-02 15:31:28 -0700 | [diff] [blame] | 678 | mockIPort.setState(swState); |
Teru | ab4b01a | 2013-06-20 10:09:57 -0700 | [diff] [blame] | 679 | mockIPort.setPortState(OFPortState.OFPPS_STP_FORWARD.getValue()); |
| 680 | mockIPort.setDesc(name); |
Pankaj Berde | ac54a4b | 2013-08-02 15:31:28 -0700 | [diff] [blame] | 681 | mockIPort.setState(portState); |
Teru | ab4b01a | 2013-06-20 10:09:57 -0700 | [diff] [blame] | 682 | replay(mockIPort); |
| 683 | |
| 684 | //Expectation of mock Switch |
| 685 | ISwitchObject mockISw = createMock(ISwitchObject.class); |
Pankaj Berde | ac54a4b | 2013-08-02 15:31:28 -0700 | [diff] [blame] | 686 | mockISw.setState(swState); |
Teru | ab4b01a | 2013-06-20 10:09:57 -0700 | [diff] [blame] | 687 | mockISw.addPort(mockIPort); |
Pankaj Berde | ac54a4b | 2013-08-02 15:31:28 -0700 | [diff] [blame] | 688 | // mockISw.removePort(mockIPort); |
Teru | ab4b01a | 2013-06-20 10:09:57 -0700 | [diff] [blame] | 689 | replay(mockISw); |
| 690 | |
Pankaj Berde | ac54a4b | 2013-08-02 15:31:28 -0700 | [diff] [blame] | 691 | |
| 692 | |
Teru | ab4b01a | 2013-06-20 10:09:57 -0700 | [diff] [blame] | 693 | //Expectation of mock operation. |
| 694 | expect(mockOpe.searchSwitch(dpid)).andReturn(null); |
| 695 | expect(mockOpe.newSwitch(dpid)).andReturn(mockISw); |
| 696 | mockOpe.commit(); |
| 697 | expect(mockOpe.searchSwitch(dpid)).andReturn(mockISw); |
| 698 | expect(mockOpe.searchPort(dpid, portNumber)).andReturn(null); |
Pankaj Berde | bbd3861 | 2013-06-22 05:59:12 -0700 | [diff] [blame] | 699 | expect(mockOpe.newPort(dpid, portNumber)).andReturn(mockIPort); |
Teru | ab4b01a | 2013-06-20 10:09:57 -0700 | [diff] [blame] | 700 | mockOpe.commit(); |
| 701 | expect(mockOpe.searchSwitch(dpid)).andReturn(mockISw); |
| 702 | expect(mockOpe.searchPort(dpid, portNumber)).andReturn(mockIPort); |
Pankaj Berde | ac54a4b | 2013-08-02 15:31:28 -0700 | [diff] [blame] | 703 | // mockOpe.removePort(mockIPort); |
Teru | ab4b01a | 2013-06-20 10:09:57 -0700 | [diff] [blame] | 704 | mockOpe.commit(); |
| 705 | mockOpe.close(); |
| 706 | replay(mockOpe); |
| 707 | |
| 708 | swSt.init(conf); |
| 709 | swSt.addSwitch(dpid); |
| 710 | swSt.addPort(dpid, portToAdd); |
| 711 | swSt.deletePort(dpid, portNumber); |
| 712 | } |
| 713 | |
| 714 | /** |
| 715 | * Desc: |
| 716 | * Test method for addPort method. |
| 717 | * Condition: |
| 718 | * commit throws the exception. |
| 719 | * Expect: |
| 720 | * Should call rollback. |
| 721 | */ |
| 722 | //@Ignore |
| 723 | @Test |
| 724 | public void testDeletePortException() { |
| 725 | String dpid = "00:00:00:00:00:00:0a:01"; |
| 726 | short portNumber = 5; |
Pankaj Berde | ac54a4b | 2013-08-02 15:31:28 -0700 | [diff] [blame] | 727 | String swState = "ACTIVE"; |
| 728 | String portState = "INACTIVE"; |
Teru | ab4b01a | 2013-06-20 10:09:57 -0700 | [diff] [blame] | 729 | String name = "port 5 at SEA switch"; |
| 730 | |
| 731 | OFPhysicalPort portToAdd = new OFPhysicalPort(); |
| 732 | portToAdd.setName(name); |
| 733 | portToAdd.setCurrentFeatures(OFPhysicalPort.OFPortFeatures.OFPPF_100MB_FD.getValue()); |
| 734 | portToAdd.setPortNumber(portNumber); |
| 735 | portToAdd.setState(OFPortState.OFPPS_STP_FORWARD.getValue()); |
| 736 | |
| 737 | //Expectation of mock Port |
| 738 | IPortObject mockIPort = createMock(IPortObject.class); |
Pankaj Berde | ac54a4b | 2013-08-02 15:31:28 -0700 | [diff] [blame] | 739 | mockIPort.setState(swState); |
Teru | ab4b01a | 2013-06-20 10:09:57 -0700 | [diff] [blame] | 740 | mockIPort.setPortState(OFPortState.OFPPS_STP_FORWARD.getValue()); |
| 741 | mockIPort.setDesc(name); |
Pankaj Berde | ac54a4b | 2013-08-02 15:31:28 -0700 | [diff] [blame] | 742 | mockIPort.setState(portState); |
Teru | ab4b01a | 2013-06-20 10:09:57 -0700 | [diff] [blame] | 743 | replay(mockIPort); |
| 744 | |
| 745 | //Expectation of mock Switch |
| 746 | ISwitchObject mockISw = createMock(ISwitchObject.class); |
Pankaj Berde | ac54a4b | 2013-08-02 15:31:28 -0700 | [diff] [blame] | 747 | mockISw.setState(swState); |
Teru | ab4b01a | 2013-06-20 10:09:57 -0700 | [diff] [blame] | 748 | mockISw.addPort(mockIPort); |
Pankaj Berde | ac54a4b | 2013-08-02 15:31:28 -0700 | [diff] [blame] | 749 | // mockISw.removePort(mockIPort); |
Teru | ab4b01a | 2013-06-20 10:09:57 -0700 | [diff] [blame] | 750 | replay(mockISw); |
| 751 | |
| 752 | //Expectation of mock operation. |
| 753 | expect(mockOpe.searchSwitch(dpid)).andReturn(null); |
| 754 | expect(mockOpe.newSwitch(dpid)).andReturn(mockISw); |
| 755 | mockOpe.commit(); |
| 756 | expect(mockOpe.searchSwitch(dpid)).andReturn(mockISw); |
| 757 | expect(mockOpe.searchPort(dpid, portNumber)).andReturn(null); |
Pankaj Berde | bbd3861 | 2013-06-22 05:59:12 -0700 | [diff] [blame] | 758 | expect(mockOpe.newPort(dpid, portNumber)).andReturn(mockIPort); |
Teru | ab4b01a | 2013-06-20 10:09:57 -0700 | [diff] [blame] | 759 | mockOpe.commit(); |
| 760 | expect(mockOpe.searchSwitch(dpid)).andReturn(mockISw); |
| 761 | expect(mockOpe.searchPort(dpid, portNumber)).andReturn(mockIPort); |
Pankaj Berde | ac54a4b | 2013-08-02 15:31:28 -0700 | [diff] [blame] | 762 | mockOpe.commit(); // Cannot generate exception..need to revisit this test |
| 763 | // mockOpe.removePort(mockIPort); |
| 764 | // expectLastCall().andThrow(new RuntimeException()); |
| 765 | // mockOpe.rollback(); |
Teru | ab4b01a | 2013-06-20 10:09:57 -0700 | [diff] [blame] | 766 | mockOpe.close(); |
| 767 | replay(mockOpe); |
| 768 | |
| 769 | swSt.init(conf); |
| 770 | swSt.addSwitch(dpid); |
| 771 | swSt.addPort(dpid, portToAdd); |
| 772 | swSt.deletePort(dpid, portNumber); |
| 773 | } |
| 774 | } |