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 java.util.ArrayList; |
| 6 | import java.util.HashMap; |
| 7 | |
| 8 | import net.onrc.onos.graph.GraphDBConnection; |
| 9 | import net.onrc.onos.graph.GraphDBOperation; |
| 10 | import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IFlowEntry; |
| 11 | import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IFlowPath; |
| 12 | import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.ISwitchObject; |
| 13 | import net.onrc.onos.ofcontroller.core.internal.SwitchStorageImpl; |
| 14 | import net.onrc.onos.ofcontroller.core.internal.TestDatabaseManager; |
| 15 | import org.easymock.EasyMock; |
| 16 | import org.junit.After; |
| 17 | import org.junit.Before; |
| 18 | import org.junit.Test; |
| 19 | import org.junit.runner.RunWith; |
| 20 | import org.powermock.api.easymock.PowerMock; |
| 21 | import org.powermock.core.classloader.annotations.PrepareForTest; |
| 22 | import org.slf4j.LoggerFactory; |
| 23 | import org.powermock.modules.junit4.PowerMockRunner; |
| 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 INetMapTopologyObjectsIFlowPathTest { |
| 32 | |
| 33 | //The test network is ./titan/schema/test-network.xml |
| 34 | |
| 35 | protected static org.slf4j.Logger log = LoggerFactory.getLogger(SwitchStorageImpl.class); |
| 36 | |
| 37 | String conf; |
| 38 | private GraphDBConnection conn = null; |
| 39 | private GraphDBOperation ope = null; |
| 40 | private TitanGraph titanGraph = null; |
| 41 | private IFlowPath flowPath = null; |
| 42 | private IFlowEntry flowEntry = null; |
| 43 | |
| 44 | @Before |
| 45 | public void setUp() throws Exception { |
| 46 | conf = "/dummy/path/to/db"; |
| 47 | |
| 48 | // Make mock cassandra DB |
| 49 | // Replace TitanFactory.open() to return mock DB |
| 50 | TestDatabaseManager.deleteTestDatabase(); |
| 51 | titanGraph = TestDatabaseManager.getTestDatabase(); |
| 52 | //TestDatabaseManager.populateTestData(titanGraph); |
| 53 | PowerMock.mockStatic(TitanFactory.class); |
| 54 | EasyMock.expect(TitanFactory.open((String)EasyMock.anyObject())).andReturn(titanGraph); |
| 55 | PowerMock.replay(TitanFactory.class); |
| 56 | |
| 57 | conn = GraphDBConnection.getInstance(conf); |
| 58 | ope = new GraphDBOperation(conn); |
| 59 | |
| 60 | flowPath = ope.newFlowPath(); |
| 61 | flowEntry = ope.newFlowEntry(); |
| 62 | flowEntry.setState("zz"); |
| 63 | } |
| 64 | |
| 65 | @After |
| 66 | public void tearDown() throws Exception { |
| 67 | titanGraph.shutdown(); |
| 68 | TestDatabaseManager.deleteTestDatabase(); |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * Desc: |
| 73 | * Test method for get and set FlowId method. |
| 74 | * Condition: |
| 75 | * N/A |
| 76 | * Expect: |
| 77 | * 1. Should set the flow id. |
| 78 | * 2. Should get the flow id. |
| 79 | */ |
| 80 | @Test |
| 81 | public void testSetGetFlowId() { |
| 82 | String flowId = "xx"; |
| 83 | flowPath.setFlowId(flowId); |
| 84 | assertEquals(flowPath.getFlowId(), flowId); |
| 85 | } |
| 86 | |
| 87 | /** |
| 88 | * Desc: |
| 89 | * Test method for get and set InstallerId method. |
| 90 | * Condition: |
| 91 | * N/A |
| 92 | * Expect: |
| 93 | * 1. Should set the installer id. |
| 94 | * 2. Should get the installer id. |
| 95 | */ |
| 96 | @Test |
| 97 | public void testSetGetInstallerId() { |
| 98 | String flowId = "xx"; |
| 99 | String installerId = "yy"; |
| 100 | flowPath.setFlowId(flowId); |
| 101 | flowPath.setInstallerId(installerId); |
| 102 | assertEquals(flowPath.getInstallerId(), installerId); |
| 103 | } |
| 104 | |
| 105 | /** |
| 106 | * Desc: |
Pavlin Radoslavov | d28cf7c | 2013-10-26 11:27:43 -0700 | [diff] [blame] | 107 | * Test method for get and set FlowPathType method. |
| 108 | * Condition: |
| 109 | * N/A |
| 110 | * Expect: |
| 111 | * 1. Should set the Flow Path Type. |
| 112 | * 2. Should get the Flow Path Type. |
| 113 | */ |
| 114 | @Test |
| 115 | public void testSetGetFlowPathType() { |
| 116 | String flowId = "xx"; |
| 117 | String flowPathType = "FP_TYPE_SHORTEST_PATH"; |
| 118 | flowPath.setFlowId(flowId); |
| 119 | flowPath.setFlowPathType(flowPathType); |
| 120 | assertEquals(flowPath.getFlowPathType(), flowPathType); |
| 121 | } |
| 122 | |
| 123 | /** |
| 124 | * Desc: |
Pavlin Radoslavov | 7d4a40e | 2013-10-27 23:39:40 -0700 | [diff] [blame] | 125 | * Test method for get and set FlowPathUserState method. |
| 126 | * Condition: |
| 127 | * N/A |
| 128 | * Expect: |
| 129 | * 1. Should set the Flow Path User State. |
| 130 | * 2. Should get the Flow Path User State. |
| 131 | */ |
| 132 | @Test |
| 133 | public void testSetGetFlowPathUserState() { |
| 134 | String flowId = "xx"; |
| 135 | String flowPathUserState = "FP_USER_ADD"; |
| 136 | flowPath.setFlowId(flowId); |
| 137 | flowPath.setFlowPathUserState(flowPathUserState); |
| 138 | assertEquals(flowPath.getFlowPathUserState(), flowPathUserState); |
| 139 | } |
| 140 | |
| 141 | /** |
| 142 | * Desc: |
Pavlin Radoslavov | 204b286 | 2013-07-12 14:15:36 -0700 | [diff] [blame] | 143 | * Test method for get and set FlowPathFlags method. |
| 144 | * Condition: |
| 145 | * N/A |
| 146 | * Expect: |
| 147 | * 1. Should set the Flow Path Flags. |
| 148 | * 2. Should get the Flow Path Flags. |
| 149 | */ |
| 150 | @Test |
| 151 | public void testSetGetFlowPathFlags() { |
| 152 | String flowId = "xx"; |
| 153 | Long flowPathFlags = new Long(0x3); |
| 154 | flowPath.setFlowId(flowId); |
| 155 | flowPath.setFlowPathFlags(flowPathFlags); |
| 156 | assertEquals(flowPath.getFlowPathFlags(), flowPathFlags); |
| 157 | } |
| 158 | |
| 159 | /** |
| 160 | * Desc: |
Teru | 68076a4 | 2013-06-27 14:57:49 -0700 | [diff] [blame] | 161 | * Test method for get and set SourceSwitch method. |
| 162 | * Condition: |
| 163 | * N/A |
| 164 | * Expect: |
| 165 | * 1. Should set the source switch. |
| 166 | * 2. Should get the source switch. |
| 167 | */ |
| 168 | @Test |
| 169 | public void testSetGetSourceSwitch() { |
| 170 | String flowId = "xx"; |
| 171 | String sourceSwitch = "aa"; |
| 172 | flowPath.setFlowId(flowId); |
| 173 | flowPath.setSrcSwitch(sourceSwitch); |
| 174 | assertEquals(flowPath.getSrcSwitch(), sourceSwitch); |
| 175 | } |
| 176 | |
| 177 | /** |
| 178 | * Desc: |
| 179 | * Test method for get and set SourcePort method. |
| 180 | * Condition: |
| 181 | * N/A |
| 182 | * Expect: |
| 183 | * 1. Should set the source port. |
| 184 | * 2. Should get the source port. |
| 185 | */ |
| 186 | @Test |
| 187 | public void testSetGetSourcePort() { |
| 188 | String flowId = "xx"; |
| 189 | Short sourcePort = 1; |
| 190 | flowPath.setFlowId(flowId); |
| 191 | flowPath.setSrcPort(sourcePort); |
| 192 | assertEquals(flowPath.getSrcPort(), sourcePort); |
| 193 | } |
| 194 | |
| 195 | /** |
| 196 | * Desc: |
| 197 | * Test method for get and set DestSwitch method. |
| 198 | * Condition: |
| 199 | * N/A |
| 200 | * Expect: |
| 201 | * 1. Should set the dest switch. |
| 202 | * 2. Should get the dest switch. |
| 203 | */ |
| 204 | @Test |
| 205 | public void testSetGetDestSwitch() { |
| 206 | String flowId = "xx"; |
| 207 | String destSwitch = "bb"; |
| 208 | flowPath.setFlowId(flowId); |
| 209 | flowPath.setDstSwitch(destSwitch); |
| 210 | assertEquals(flowPath.getDstSwitch(), destSwitch); |
| 211 | } |
| 212 | |
| 213 | /** |
| 214 | * Desc: |
| 215 | * Test method for get and set DestPort method. |
| 216 | * Condition: |
| 217 | * N/A |
| 218 | * Expect: |
| 219 | * 1. Should set the source dest port. |
| 220 | * 2. Should get the source dest port. |
| 221 | */ |
| 222 | @Test |
| 223 | public void testSetGetDstPort() { |
| 224 | String flowId = "xx"; |
| 225 | Short dstPort = 2; |
| 226 | flowPath.setFlowId(flowId); |
| 227 | flowPath.setDstPort(dstPort); |
| 228 | assertEquals(flowPath.getDstPort(), dstPort); |
| 229 | } |
| 230 | |
| 231 | /** |
| 232 | * Desc: |
| 233 | * Test method for get and set DataPathSummary method. |
| 234 | * Condition: |
| 235 | * N/A |
| 236 | * Expect: |
| 237 | * 1. Should set the data path summary. |
| 238 | * 2. Should get the data path summary. |
| 239 | */ |
| 240 | @Test |
| 241 | public void testSetGetDataPathSummary() { |
| 242 | String flowId = "xx"; |
| 243 | String dataPathSummary = "yy"; |
| 244 | flowPath.setFlowId(flowId); |
| 245 | flowPath.setInstallerId(dataPathSummary); |
| 246 | assertEquals(flowPath.getInstallerId(), dataPathSummary); |
| 247 | } |
| 248 | |
| 249 | public boolean testIFlowEntry(IFlowPath fp, IFlowEntry fe) |
| 250 | { |
| 251 | ArrayList<IFlowEntry> flowEntryList = new ArrayList<IFlowEntry>(); |
| 252 | for(IFlowEntry inFlowEntry : fp.getFlowEntries()) |
| 253 | { |
| 254 | flowEntryList.add(inFlowEntry); |
| 255 | } |
| 256 | return flowEntryList.contains(fe); |
| 257 | } |
| 258 | |
| 259 | /** |
| 260 | * Desc: |
| 261 | * Test method for addFlowEntry and getFlorEntries method. |
| 262 | * Condition: |
| 263 | * N/A |
| 264 | * Expect: |
| 265 | * 1. Should add the FlowEntry. |
| 266 | * 2. Should get the FlowEntries. It is tested in the testIFlowEntry method. |
| 267 | */ |
| 268 | @Test |
| 269 | public void testAddFlowEntryAndGetFlowEntries() { |
| 270 | String flowId = "xx"; |
| 271 | flowPath.setFlowId(flowId); |
| 272 | flowPath.addFlowEntry(flowEntry); |
| 273 | IFlowEntry flowEntry2 = ope.newFlowEntry(); |
| 274 | flowPath.addFlowEntry(flowEntry2); |
| 275 | assertTrue(testIFlowEntry(flowPath, flowEntry)); |
| 276 | assertTrue(testIFlowEntry(flowPath, flowEntry2)); |
| 277 | } |
| 278 | |
| 279 | /** |
| 280 | * Desc: |
| 281 | * Test method for remove FlowEntry. |
| 282 | * Condition: |
| 283 | * N/A |
| 284 | * Expect: |
| 285 | * 1. Should remove FlowEntry. |
| 286 | */ |
| 287 | @Test |
| 288 | public void testRemoveFlowEntry() { |
| 289 | String flowId = "xx"; |
| 290 | flowPath.setFlowId(flowId); |
| 291 | flowPath.addFlowEntry(flowEntry); |
| 292 | flowPath.removeFlowEntry(flowEntry); |
| 293 | assertTrue(!testIFlowEntry(flowPath, flowEntry)); |
| 294 | } |
| 295 | |
| 296 | /** |
| 297 | * Desc: |
Teru | 68076a4 | 2013-06-27 14:57:49 -0700 | [diff] [blame] | 298 | * Test method for set and get MatchSrcMac |
| 299 | * Condition: |
| 300 | * N/A |
| 301 | * Expect: |
| 302 | * 1. Should set MatchSrcMac. |
| 303 | * 2. Should get MatchSrcMac. |
| 304 | */ |
| 305 | @Test |
| 306 | public void testSetGetMatchSrcMac() { |
| 307 | String flowId = "xx"; |
| 308 | String matchSrcMac = "00:00:00:00:00:11"; |
| 309 | flowPath.setFlowId(flowId); |
| 310 | flowPath.setMatchSrcMac(matchSrcMac); |
| 311 | assertEquals(flowPath.getMatchSrcMac(), matchSrcMac); |
| 312 | } |
| 313 | |
| 314 | /** |
| 315 | * Desc: |
| 316 | * Test method for set and get MatchDstMac. |
| 317 | * Condition: |
| 318 | * N/A |
| 319 | * Expect: |
| 320 | * 1. Should set MatchDstMac. |
| 321 | * 2. Should get MatchDstMac. |
| 322 | */ |
| 323 | @Test |
| 324 | public void testSetGetMatchDstMac() { |
| 325 | String flowId = "xx"; |
| 326 | String matchDstMac = "00:00:00:00:00:11"; |
| 327 | flowPath.setFlowId(flowId); |
| 328 | flowPath.setMatchDstMac(matchDstMac); |
| 329 | assertEquals(flowPath.getMatchDstMac(), matchDstMac); |
| 330 | } |
Pavlin Radoslavov | ad3a1e6 | 2013-07-09 13:30:16 -0700 | [diff] [blame] | 331 | |
Teru | 68076a4 | 2013-06-27 14:57:49 -0700 | [diff] [blame] | 332 | /** |
| 333 | * Desc: |
Pavlin Radoslavov | ad3a1e6 | 2013-07-09 13:30:16 -0700 | [diff] [blame] | 334 | * Test method for set and get MatchEthernetFrameType |
Teru | 68076a4 | 2013-06-27 14:57:49 -0700 | [diff] [blame] | 335 | * Condition: |
| 336 | * N/A |
| 337 | * Expect: |
Pavlin Radoslavov | ad3a1e6 | 2013-07-09 13:30:16 -0700 | [diff] [blame] | 338 | * 1. Should set MatchEthernetFrameType. |
| 339 | * 2. Should get MatchEthernetFrameType. |
| 340 | */ |
| 341 | @Test |
| 342 | public void testSetGetMatchEthernetFrameType() { |
| 343 | String flowId = "xx"; |
| 344 | Short matchEthernetFrameType = 1; |
| 345 | flowPath.setFlowId(flowId); |
| 346 | flowPath.setMatchEthernetFrameType(matchEthernetFrameType); |
| 347 | assertEquals(flowPath.getMatchEthernetFrameType(), matchEthernetFrameType); |
| 348 | } |
| 349 | |
| 350 | /** |
| 351 | * Desc: |
| 352 | * Test method for set and get MatchVlanId |
| 353 | * Condition: |
| 354 | * N/A |
| 355 | * Expect: |
| 356 | * 1. Should set MatchVlanId. |
| 357 | * 2. Should get MatchVlanId. |
| 358 | */ |
| 359 | @Test |
| 360 | public void testSetGetMatchVlanId() { |
| 361 | String flowId = "xx"; |
| 362 | Short matchVlanId = 10; |
| 363 | flowPath.setFlowId(flowId); |
| 364 | flowPath.setMatchVlanId(matchVlanId); |
| 365 | assertEquals(flowPath.getMatchVlanId(), matchVlanId); |
| 366 | } |
| 367 | |
| 368 | /** |
| 369 | * Desc: |
| 370 | * Test method for set and get MatchVlanPriority |
| 371 | * Condition: |
| 372 | * N/A |
| 373 | * Expect: |
| 374 | * 1. Should set MatchVlanPriority. |
| 375 | * 2. Should get MatchVlanPriority. |
| 376 | */ |
| 377 | @Test |
| 378 | public void testSetGetMatchVlanPriority() { |
| 379 | String flowId = "xx"; |
| 380 | Byte matchVlanPriority = 20; |
| 381 | flowPath.setFlowId(flowId); |
| 382 | flowPath.setMatchVlanPriority(matchVlanPriority); |
| 383 | assertEquals(flowPath.getMatchVlanPriority(), matchVlanPriority); |
| 384 | } |
| 385 | |
| 386 | /** |
| 387 | * Desc: |
| 388 | * Test method for set and get MatchSrcIPv4Net. |
| 389 | * Condition: |
| 390 | * N/A |
| 391 | * Expect: |
| 392 | * 1. Should set MatchSrcIPv4Net. |
| 393 | * 2. Should get MatchSrcIPv4Net. |
Teru | 68076a4 | 2013-06-27 14:57:49 -0700 | [diff] [blame] | 394 | */ |
| 395 | @Test |
| 396 | public void testSetGetMatchSrcIPv4Net() { |
| 397 | String flowId = "xx"; |
| 398 | String ip = "192.168.0.1"; |
| 399 | flowPath.setFlowId(flowId); |
| 400 | flowPath.setMatchSrcIPv4Net(ip); |
| 401 | assertEquals(flowPath.getMatchSrcIPv4Net(), ip); |
| 402 | } |
| 403 | |
| 404 | /** |
| 405 | * Desc: |
Pavlin Radoslavov | ad3a1e6 | 2013-07-09 13:30:16 -0700 | [diff] [blame] | 406 | * Test method for set and get MatchDstIPv4Net. |
Teru | 68076a4 | 2013-06-27 14:57:49 -0700 | [diff] [blame] | 407 | * Condition: |
| 408 | * N/A |
| 409 | * Expect: |
Pavlin Radoslavov | ad3a1e6 | 2013-07-09 13:30:16 -0700 | [diff] [blame] | 410 | * 1. Should set MatchDstIPv4Net. |
| 411 | * 2. Should get MatchDstIPv4Net. |
Teru | 68076a4 | 2013-06-27 14:57:49 -0700 | [diff] [blame] | 412 | */ |
| 413 | @Test |
| 414 | public void testSetGetMatchDstIPv4Net() { |
| 415 | String flowId = "xx"; |
| 416 | String ip = "192.168.0.1"; |
| 417 | flowPath.setFlowId(flowId); |
| 418 | flowPath.setMatchDstIPv4Net(ip); |
| 419 | assertEquals(flowPath.getMatchDstIPv4Net(), ip); |
| 420 | } |
Pavlin Radoslavov | ad3a1e6 | 2013-07-09 13:30:16 -0700 | [diff] [blame] | 421 | |
| 422 | /** |
| 423 | * Desc: |
| 424 | * Test method for set and get MatchIpProto |
| 425 | * Condition: |
| 426 | * N/A |
| 427 | * Expect: |
| 428 | * 1. Should set MatchIpProto. |
| 429 | * 2. Should get MatchIpProto. |
| 430 | */ |
| 431 | @Test |
| 432 | public void testSetGetMatchIpProto() { |
| 433 | String flowId = "xx"; |
| 434 | Byte matchIpProto = 20; |
| 435 | flowPath.setFlowId(flowId); |
| 436 | flowPath.setMatchIpProto(matchIpProto); |
| 437 | assertEquals(flowPath.getMatchIpProto(), matchIpProto); |
| 438 | } |
| 439 | |
| 440 | /** |
| 441 | * Desc: |
| 442 | * Test method for set and get MatchIpToS |
| 443 | * Condition: |
| 444 | * N/A |
| 445 | * Expect: |
| 446 | * 1. Should set MatchIpToS. |
| 447 | * 2. Should get MatchIpToS. |
| 448 | */ |
| 449 | @Test |
| 450 | public void testSetGetMatchIpToS() { |
| 451 | String flowId = "xx"; |
| 452 | Byte matchIpToS = 20; |
| 453 | flowPath.setFlowId(flowId); |
| 454 | flowPath.setMatchIpToS(matchIpToS); |
| 455 | assertEquals(flowPath.getMatchIpToS(), matchIpToS); |
| 456 | } |
| 457 | |
| 458 | /** |
| 459 | * Desc: |
| 460 | * Test method for set and get MatchSrcTcpUdpPort. |
| 461 | * Condition: |
| 462 | * N/A |
| 463 | * Expect: |
| 464 | * 1. Should set MatchSrcTcpUdpPort. |
| 465 | * 2. Should get MatchSrcTcpUdpPort. |
| 466 | */ |
| 467 | @Test |
| 468 | public void testSetGetMatchSrcTcpUdpPort() { |
| 469 | String flowId = "xx"; |
| 470 | Short srcTcpUdpPort = (short)65535; |
| 471 | flowPath.setFlowId(flowId); |
| 472 | flowPath.setMatchSrcTcpUdpPort(srcTcpUdpPort); |
| 473 | assertEquals(flowPath.getMatchSrcTcpUdpPort(), srcTcpUdpPort); |
| 474 | } |
| 475 | |
| 476 | /** |
| 477 | * Desc: |
| 478 | * Test method for set and get MatchDstTcpUdpPort. |
| 479 | * Condition: |
| 480 | * N/A |
| 481 | * Expect: |
| 482 | * 1. Should set MatchDstTcpUdpPort. |
| 483 | * 2. Should get MatchDstTcpUdpPort. |
| 484 | */ |
| 485 | @Test |
| 486 | public void testSetGetMatchDstTcpUdpPort() { |
| 487 | String flowId = "xx"; |
| 488 | Short dstTcpUdpPort = (short)65535; |
| 489 | flowPath.setFlowId(flowId); |
| 490 | flowPath.setMatchDstTcpUdpPort(dstTcpUdpPort); |
| 491 | assertEquals(flowPath.getMatchDstTcpUdpPort(), dstTcpUdpPort); |
| 492 | } |
| 493 | |
Teru | 68076a4 | 2013-06-27 14:57:49 -0700 | [diff] [blame] | 494 | /** |
| 495 | * Desc: |
Teru | 68076a4 | 2013-06-27 14:57:49 -0700 | [diff] [blame] | 496 | * Test method for get Switches. |
| 497 | * Condition: |
| 498 | * N/A |
| 499 | * Expect: |
| 500 | * 1. Should get switches. |
| 501 | */ |
| 502 | @Test |
| 503 | public void testGetSwitches() { |
| 504 | String flowId = "xx"; |
| 505 | String dpid = "1"; |
| 506 | flowPath.setFlowId(flowId); |
| 507 | ISwitchObject sw = ope.newSwitch(dpid); |
| 508 | flowEntry.setSwitch(sw); |
| 509 | flowPath.addFlowEntry(flowEntry); |
| 510 | |
| 511 | HashMap<String, ISwitchObject> swList = new HashMap<String, ISwitchObject>(); |
| 512 | for(ISwitchObject insw : flowPath.getSwitches()){ |
| 513 | swList.put(sw.getDPID(), insw); |
| 514 | } |
| 515 | |
| 516 | assertTrue(swList.containsKey(dpid)); |
| 517 | } |
| 518 | |
| 519 | //TODO Dont know how to set the state property. |
| 520 | @Test |
| 521 | public void testGetState() { |
| 522 | String status = null; |
| 523 | assertEquals(flowPath.getState(), status); |
| 524 | } |
| 525 | |
| 526 | |
| 527 | } |