Teru | 68076a4 | 2013-06-27 14:57:49 -0700 | [diff] [blame] | 1 | package net.onrc.onos.ofcontroller.core; |
| 2 | |
| 3 | import static org.junit.Assert.*; |
| 4 | |
| 5 | import net.onrc.onos.graph.GraphDBConnection; |
| 6 | import net.onrc.onos.graph.GraphDBOperation; |
| 7 | import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IFlowEntry; |
| 8 | import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IFlowPath; |
| 9 | import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IPortObject; |
| 10 | import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.ISwitchObject; |
| 11 | import net.onrc.onos.ofcontroller.core.internal.SwitchStorageImpl; |
| 12 | import net.onrc.onos.ofcontroller.core.internal.TestDatabaseManager; |
| 13 | import org.easymock.EasyMock; |
| 14 | import org.junit.After; |
| 15 | import org.junit.Before; |
| 16 | import org.junit.Test; |
| 17 | import org.junit.runner.RunWith; |
| 18 | import org.powermock.api.easymock.PowerMock; |
| 19 | import org.powermock.core.classloader.annotations.PrepareForTest; |
| 20 | import org.slf4j.LoggerFactory; |
| 21 | import org.powermock.modules.junit4.PowerMockRunner; |
| 22 | |
| 23 | import com.thinkaurelius.titan.core.TitanFactory; |
| 24 | import com.thinkaurelius.titan.core.TitanGraph; |
| 25 | |
| 26 | //Add Powermock preparation |
| 27 | @RunWith(PowerMockRunner.class) |
| 28 | @PrepareForTest({TitanFactory.class, GraphDBConnection.class, GraphDBOperation.class, SwitchStorageImpl.class}) |
| 29 | public class INetMapTopologyObjectsIFlowEntryTest { |
| 30 | |
| 31 | //The test network is ./titan/schema/test-network.xml |
| 32 | |
| 33 | protected static org.slf4j.Logger log = LoggerFactory.getLogger(SwitchStorageImpl.class); |
| 34 | |
| 35 | String conf; |
| 36 | private GraphDBConnection conn = null; |
| 37 | private GraphDBOperation ope = null; |
| 38 | private TitanGraph titanGraph = null; |
| 39 | private IFlowEntry flowEntry = null; |
| 40 | |
| 41 | @Before |
| 42 | public void setUp() throws Exception { |
| 43 | conf = "/dummy/path/to/db"; |
| 44 | |
| 45 | // Make mock cassandra DB |
| 46 | // Replace TitanFactory.open() to return mock DB |
| 47 | TestDatabaseManager.deleteTestDatabase(); |
| 48 | titanGraph = TestDatabaseManager.getTestDatabase(); |
| 49 | //TestDatabaseManager.populateTestData(titanGraph); |
| 50 | PowerMock.mockStatic(TitanFactory.class); |
| 51 | EasyMock.expect(TitanFactory.open((String)EasyMock.anyObject())).andReturn(titanGraph); |
| 52 | PowerMock.replay(TitanFactory.class); |
| 53 | |
| 54 | conn = GraphDBConnection.getInstance(conf); |
| 55 | ope = new GraphDBOperation(conn); |
| 56 | |
| 57 | flowEntry = ope.newFlowEntry(); |
| 58 | } |
| 59 | |
| 60 | @After |
| 61 | public void tearDown() throws Exception { |
| 62 | titanGraph.shutdown(); |
| 63 | TestDatabaseManager.deleteTestDatabase(); |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * Desc: |
| 68 | * Test method for set and get FlowEntryId. |
| 69 | * Condition: |
| 70 | * N/A |
| 71 | * Expect: |
| 72 | * 1. Should set FlowEntryId. |
| 73 | * 2. Should get FlowEntryId. |
| 74 | */ |
| 75 | @Test |
| 76 | public void testSetGetFlowEntryId() { |
| 77 | String flowEntryId = "xx"; |
| 78 | flowEntry.setFlowEntryId(flowEntryId); |
| 79 | assertEquals(flowEntry.getFlowEntryId(), flowEntryId); |
| 80 | } |
Pavlin Radoslavov | 5139c0b | 2013-12-09 18:04:53 -0800 | [diff] [blame] | 81 | |
| 82 | /** |
| 83 | * Desc: |
| 84 | * Test method for set and get Idle Timeout. |
| 85 | * Condition: |
| 86 | * N/A |
| 87 | * Expect: |
| 88 | * 1. Should set Idle Timeout. |
| 89 | * 2. Should get Idle Timeout. |
| 90 | */ |
| 91 | @Test |
| 92 | public void testSetGetIdleTimeout() { |
| 93 | Integer idleTimeout = 5; |
| 94 | flowEntry.setIdleTimeout(idleTimeout); |
| 95 | assertEquals(flowEntry.getIdleTimeout(), idleTimeout); |
| 96 | } |
| 97 | |
| 98 | /** |
| 99 | * Desc: |
| 100 | * Test method for set and get Hard Timeout. |
| 101 | * Condition: |
| 102 | * N/A |
| 103 | * Expect: |
| 104 | * 1. Should set Hard Timeout. |
| 105 | * 2. Should get Hard Timeout. |
| 106 | */ |
| 107 | @Test |
| 108 | public void testSetGetHardTimeout() { |
| 109 | Integer hardTimeout = 5; |
| 110 | flowEntry.setHardTimeout(hardTimeout); |
| 111 | assertEquals(flowEntry.getHardTimeout(), hardTimeout); |
| 112 | } |
Teru | 68076a4 | 2013-06-27 14:57:49 -0700 | [diff] [blame] | 113 | |
| 114 | /** |
| 115 | * Desc: |
| 116 | * Test method for set and get SwitchDpid. |
| 117 | * Condition: |
| 118 | * N/A |
| 119 | * Expect: |
| 120 | * 1. Should set SwitchDpid. |
| 121 | * 2. Should get SwitchDpid. |
| 122 | */ |
| 123 | @Test |
| 124 | public void testSetGetSwitchDpid() { |
| 125 | String switchDpid = "00:00:00:00:00:11"; |
| 126 | flowEntry.setSwitchDpid(switchDpid); |
| 127 | assertEquals(flowEntry.getSwitchDpid(), switchDpid); |
| 128 | } |
| 129 | |
| 130 | /** |
| 131 | * Desc: |
| 132 | * Test method for set and get UserState. |
| 133 | * Condition: |
| 134 | * N/A |
| 135 | * Expect: |
| 136 | * 1. Should set UserState. |
| 137 | * 2. Should get UserState. |
| 138 | */ |
| 139 | @Test |
| 140 | public void testSetGetUserState() { |
| 141 | String userStete = "good"; |
| 142 | flowEntry.setUserState(userStete); |
| 143 | assertEquals(flowEntry.getUserState(), userStete); |
| 144 | } |
| 145 | |
| 146 | /** |
| 147 | * Desc: |
| 148 | * Test method for set and get SwitchState. |
| 149 | * Condition: |
| 150 | * N/A |
| 151 | * Expect: |
| 152 | * 1. Should set SwitchState. |
| 153 | * 2. Should get SwitchState. |
| 154 | */ |
| 155 | @Test |
| 156 | public void testSetGetSwitchState() { |
| 157 | String switchStete = "ACTIVE"; |
| 158 | flowEntry.setSwitchState(switchStete); |
| 159 | assertEquals(flowEntry.getSwitchState(), switchStete); |
| 160 | } |
| 161 | |
| 162 | /** |
| 163 | * Desc: |
| 164 | * Test method for set and get ErrorStateType. |
| 165 | * Condition: |
| 166 | * N/A |
| 167 | * Expect: |
| 168 | * 1. Should set ErrorStateType. |
| 169 | * 2. Should get ErrorStateType. |
| 170 | */ |
| 171 | @Test |
| 172 | public void testSetGetErrorStateType() { |
| 173 | String errorSteteType = "error"; |
| 174 | flowEntry.setErrorStateType(errorSteteType); |
| 175 | assertEquals(flowEntry.getErrorStateType(), errorSteteType); |
| 176 | } |
| 177 | |
| 178 | /** |
| 179 | * Desc: |
| 180 | * Test method for set and get ErrorStateCode. |
| 181 | * Condition: |
| 182 | * N/A |
| 183 | * Expect: |
| 184 | * 1. Should set ErrorStateCode. |
| 185 | * 2. Should get ErrorStateCode. |
| 186 | */ |
| 187 | @Test |
| 188 | public void testSetGetErrorStateCode() { |
| 189 | String errorSteteCode = "error"; |
| 190 | flowEntry.setErrorStateCode(errorSteteCode); |
| 191 | assertEquals(flowEntry.getErrorStateCode(), errorSteteCode); |
| 192 | } |
| 193 | |
| 194 | /** |
| 195 | * Desc: |
| 196 | * Test method for set and get MatchInPort. |
| 197 | * Condition: |
| 198 | * N/A |
| 199 | * Expect: |
| 200 | * 1. Should set MatchInPort. |
| 201 | * 2. Should get MatchInPort. |
| 202 | */ |
| 203 | @Test |
| 204 | public void testSetGetMatchInPort() { |
| 205 | Short inPort = 1; |
| 206 | flowEntry.setMatchInPort(inPort); |
| 207 | assertEquals(flowEntry.getMatchInPort(), inPort); |
| 208 | } |
| 209 | |
| 210 | /** |
| 211 | * Desc: |
Teru | 68076a4 | 2013-06-27 14:57:49 -0700 | [diff] [blame] | 212 | * Test method for set and get MatchSrcMac. |
| 213 | * Condition: |
| 214 | * N/A |
| 215 | * Expect: |
| 216 | * 1. Should set MatchSrcMac. |
| 217 | * 2. Should get MatchSrcMac. |
| 218 | */ |
| 219 | @Test |
| 220 | public void testSetGetMatchSrcMac() { |
| 221 | String matchSrcMac = "00:00:00:00:00:11"; |
| 222 | flowEntry.setMatchSrcMac(matchSrcMac); |
| 223 | assertEquals(flowEntry.getMatchSrcMac(), matchSrcMac); |
| 224 | } |
| 225 | |
| 226 | /** |
| 227 | * Desc: |
| 228 | * Test method for set and get MatchDstMac. |
| 229 | * Condition: |
| 230 | * N/A |
| 231 | * Expect: |
| 232 | * 1. Should set MatchDstMac. |
| 233 | * 2. Should get MatchDstMac. |
| 234 | */ |
| 235 | @Test |
| 236 | public void testSetGetMatchDstMac() { |
| 237 | String matchDstMac = "00:00:00:00:00:11"; |
| 238 | flowEntry.setMatchDstMac(matchDstMac); |
| 239 | assertEquals(flowEntry.getMatchDstMac(), matchDstMac); |
| 240 | } |
Pavlin Radoslavov | ad3a1e6 | 2013-07-09 13:30:16 -0700 | [diff] [blame] | 241 | |
| 242 | /** |
| 243 | * Desc: |
| 244 | * Test method for set and get MatchEthernetFrameType. |
| 245 | * Condition: |
| 246 | * N/A |
| 247 | * Expect: |
| 248 | * 1. Should set MatchEthernetFrameType. |
| 249 | * 2. Should get MatchEthernetFrameType. |
| 250 | */ |
| 251 | @Test |
| 252 | public void testSetGetMatchEthernetFrameType() { |
| 253 | Short matchEthernetFrameType = 1; |
| 254 | flowEntry.setMatchEthernetFrameType(matchEthernetFrameType); |
| 255 | assertEquals(flowEntry.getMatchEthernetFrameType(), matchEthernetFrameType); |
| 256 | } |
| 257 | |
| 258 | /** |
| 259 | * Desc: |
| 260 | * Test method for set and get MatchVlanId. |
| 261 | * Condition: |
| 262 | * N/A |
| 263 | * Expect: |
| 264 | * 1. Should set MatchVlanId. |
| 265 | * 2. Should get MatchVlanId. |
| 266 | */ |
| 267 | @Test |
| 268 | public void testSetGetMatchVlanId() { |
| 269 | Short matchVlanId = 10; |
| 270 | flowEntry.setMatchVlanId(matchVlanId); |
| 271 | assertEquals(flowEntry.getMatchVlanId(), matchVlanId); |
| 272 | } |
| 273 | |
| 274 | /** |
| 275 | * Desc: |
| 276 | * Test method for set and get MatchVlanPriority. |
| 277 | * Condition: |
| 278 | * N/A |
| 279 | * Expect: |
| 280 | * 1. Should set MatchVlanPriority. |
| 281 | * 2. Should get MatchVlanPriority. |
| 282 | */ |
| 283 | @Test |
| 284 | public void testSetGetMatchVlanPriority() { |
| 285 | Byte matchVlanPriority = 10; |
| 286 | flowEntry.setMatchVlanPriority(matchVlanPriority); |
| 287 | assertEquals(flowEntry.getMatchVlanPriority(), matchVlanPriority); |
| 288 | } |
Teru | 68076a4 | 2013-06-27 14:57:49 -0700 | [diff] [blame] | 289 | |
| 290 | /** |
| 291 | * Desc: |
| 292 | * Test method for set and get SrcIPv4Net. |
| 293 | * Condition: |
| 294 | * N/A |
| 295 | * Expect: |
| 296 | * 1. Should set SrcIPv4Net. |
| 297 | * 2. Should get SrcIPv4Net. |
| 298 | */ |
| 299 | @Test |
| 300 | public void testSetGetMatchSrcIPv4Net() { |
| 301 | String srcIPv4Net = "192.168.0.1"; |
| 302 | flowEntry.setMatchSrcIPv4Net(srcIPv4Net); |
| 303 | assertEquals(flowEntry.getMatchSrcIPv4Net(), srcIPv4Net); |
| 304 | } |
| 305 | |
| 306 | /** |
| 307 | * Desc: |
| 308 | * Test method for set and get MatchDstIPv4Net. |
| 309 | * Condition: |
| 310 | * N/A |
| 311 | * Expect: |
| 312 | * 1. Should set MatchDstIPv4Net. |
| 313 | * 2. Should get MatchDstIPv4Net. |
| 314 | */ |
| 315 | @Test |
| 316 | public void testSetGetMatchDstIPv4Net() { |
| 317 | String dstIPv4Net = "192.168.0.1"; |
| 318 | flowEntry.setMatchDstIPv4Net(dstIPv4Net); |
| 319 | assertEquals(flowEntry.getMatchDstIPv4Net(), dstIPv4Net); |
| 320 | } |
Pavlin Radoslavov | ad3a1e6 | 2013-07-09 13:30:16 -0700 | [diff] [blame] | 321 | |
| 322 | /** |
| 323 | * Desc: |
| 324 | * Test method for set and get MatchIpProto. |
| 325 | * Condition: |
| 326 | * N/A |
| 327 | * Expect: |
| 328 | * 1. Should set MatchIpProto. |
| 329 | * 2. Should get MatchIpProto. |
| 330 | */ |
| 331 | @Test |
| 332 | public void testSetGetMatchIpProto() { |
| 333 | Byte matchIpProto = 20; |
| 334 | flowEntry.setMatchIpProto(matchIpProto); |
| 335 | assertEquals(flowEntry.getMatchIpProto(), matchIpProto); |
| 336 | } |
| 337 | |
| 338 | /** |
| 339 | * Desc: |
| 340 | * Test method for set and get MatchIpToS. |
| 341 | * Condition: |
| 342 | * N/A |
| 343 | * Expect: |
| 344 | * 1. Should set MatchIpToS. |
| 345 | * 2. Should get MatchIpToS. |
| 346 | */ |
| 347 | @Test |
| 348 | public void testSetGetMatchIpToS() { |
| 349 | Byte matchIpToS = 20; |
| 350 | flowEntry.setMatchIpToS(matchIpToS); |
| 351 | assertEquals(flowEntry.getMatchIpToS(), matchIpToS); |
| 352 | } |
| 353 | |
| 354 | /** |
| 355 | * Desc: |
| 356 | * Test method for set and get MatchSrcTcpUdpPort. |
| 357 | * Condition: |
| 358 | * N/A |
| 359 | * Expect: |
| 360 | * 1. Should set MatchSrcTcpUdpPort. |
| 361 | * 2. Should get MatchSrcTcpUdpPort. |
| 362 | */ |
| 363 | @Test |
| 364 | public void testSetGetMatchSrcTcpUdpPort() { |
| 365 | Short srcTcpUdpPort = (short)65535; |
| 366 | flowEntry.setMatchSrcTcpUdpPort(srcTcpUdpPort); |
| 367 | assertEquals(flowEntry.getMatchSrcTcpUdpPort(), srcTcpUdpPort); |
| 368 | } |
| 369 | |
| 370 | /** |
| 371 | * Desc: |
| 372 | * Test method for set and get MatchDstTcpUdpPort. |
| 373 | * Condition: |
| 374 | * N/A |
| 375 | * Expect: |
| 376 | * 1. Should set MatchDstTcpUdpPort. |
| 377 | * 2. Should get MatchDstTcpUdpPort. |
| 378 | */ |
| 379 | @Test |
| 380 | public void testSetGetMatchDstTcpUdpPort() { |
| 381 | Short dstTcpUdpPort = (short)65535; |
| 382 | flowEntry.setMatchDstTcpUdpPort(dstTcpUdpPort); |
| 383 | assertEquals(flowEntry.getMatchDstTcpUdpPort(), dstTcpUdpPort); |
| 384 | } |
Teru | 68076a4 | 2013-06-27 14:57:49 -0700 | [diff] [blame] | 385 | |
| 386 | /** |
| 387 | * Desc: |
Pavlin Radoslavov | c1bafd1 | 2013-07-12 17:00:35 -0700 | [diff] [blame] | 388 | * Test method for set and get ActionOutputPort. |
Teru | 68076a4 | 2013-06-27 14:57:49 -0700 | [diff] [blame] | 389 | * Condition: |
| 390 | * N/A |
| 391 | * Expect: |
Pavlin Radoslavov | c1bafd1 | 2013-07-12 17:00:35 -0700 | [diff] [blame] | 392 | * 1. Should set ActionOutputPort. |
| 393 | * 2. Should get ActionOutputPort. |
Teru | 68076a4 | 2013-06-27 14:57:49 -0700 | [diff] [blame] | 394 | */ |
| 395 | @Test |
Pavlin Radoslavov | c1bafd1 | 2013-07-12 17:00:35 -0700 | [diff] [blame] | 396 | public void testSetGetActionOutputPort() { |
| 397 | Short actionOutputPort = 1; |
| 398 | flowEntry.setActionOutputPort(actionOutputPort); |
| 399 | assertEquals(flowEntry.getActionOutputPort(), actionOutputPort); |
Teru | 68076a4 | 2013-06-27 14:57:49 -0700 | [diff] [blame] | 400 | } |
| 401 | |
| 402 | /** |
| 403 | * Desc: |
| 404 | * Test method for set and get FlowPath. |
| 405 | * Condition: |
| 406 | * N/A |
| 407 | * Expect: |
| 408 | * 1. Should set FlowPath. |
| 409 | * 2. Should get FlowPath. |
| 410 | */ |
| 411 | @Test |
| 412 | public void testSetGetFlowPath() { |
| 413 | IFlowPath fp = ope.newFlowPath(); |
| 414 | String flowId = "xx"; |
| 415 | fp.setFlowId(flowId); |
| 416 | flowEntry.setFlow(fp); |
| 417 | IFlowPath fp2 = flowEntry.getFlow(); |
| 418 | assertEquals(fp2.getFlowId(), flowId); |
| 419 | } |
| 420 | |
| 421 | /** |
| 422 | * Desc: |
| 423 | * Test method for set and get Switch. |
| 424 | * Condition: |
| 425 | * N/A |
| 426 | * Expect: |
| 427 | * 1. Should set Switch. |
| 428 | * 2. Should get Switch. |
| 429 | */ |
| 430 | @Test |
| 431 | public void testSetGetSwitch() { |
| 432 | String dpid = "00:00:00:00:00:22"; |
| 433 | ISwitchObject sw1 = ope.newSwitch(dpid); |
| 434 | flowEntry.setSwitch(sw1); |
| 435 | ISwitchObject sw2 = flowEntry.getSwitch(); |
| 436 | assertEquals(sw2, sw1); |
| 437 | } |
| 438 | |
| 439 | /** |
| 440 | * Desc: |
| 441 | * Test method for set and get InPort. |
| 442 | * Condition: |
| 443 | * N/A |
| 444 | * Expect: |
| 445 | * 1. Should set InPort. |
| 446 | * 2. Should get InPort. |
| 447 | */ |
| 448 | @Test |
| 449 | public void testSetGetInPort() { |
| 450 | String dpid = "00:00:00:00:00:22"; |
| 451 | Short portNum = 4; |
| 452 | IPortObject port1 = ope.newPort(dpid, portNum); |
| 453 | flowEntry.setInPort(port1); |
| 454 | IPortObject port2 = flowEntry.getInPort(); |
| 455 | assertEquals(port2, port1); |
| 456 | } |
| 457 | |
| 458 | /** |
| 459 | * Desc: |
| 460 | * Test method for set and get OutPort. |
| 461 | * Condition: |
| 462 | * N/A |
| 463 | * Expect: |
| 464 | * 1. Should set OutPort. |
| 465 | * 2. Should get OutPort. |
| 466 | */ |
| 467 | @Test |
| 468 | public void testSetGetOutPort() { |
| 469 | String dpid = "00:00:00:00:00:22"; |
| 470 | Short portNum = 4; |
| 471 | IPortObject port1 = ope.newPort(dpid, portNum); |
| 472 | flowEntry.setOutPort(port1); |
| 473 | IPortObject port2 = flowEntry.getOutPort(); |
| 474 | assertEquals(port2, port1); |
| 475 | } |
| 476 | } |