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