blob: 39e4955f0e931bd11c8cc55954866d69004c48d9 [file] [log] [blame]
Teru68076a42013-06-27 14:57:49 -07001package net.onrc.onos.ofcontroller.core;
2
3import static org.junit.Assert.*;
4
5import java.util.ArrayList;
6import java.util.HashMap;
7
8import net.onrc.onos.graph.GraphDBConnection;
9import net.onrc.onos.graph.GraphDBOperation;
10import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IFlowEntry;
11import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IFlowPath;
12import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.ISwitchObject;
13import net.onrc.onos.ofcontroller.core.internal.SwitchStorageImpl;
14import net.onrc.onos.ofcontroller.core.internal.TestDatabaseManager;
15import org.easymock.EasyMock;
16import org.junit.After;
17import org.junit.Before;
18import org.junit.Test;
19import org.junit.runner.RunWith;
20import org.powermock.api.easymock.PowerMock;
21import org.powermock.core.classloader.annotations.PrepareForTest;
22import org.slf4j.LoggerFactory;
23import org.powermock.modules.junit4.PowerMockRunner;
24
25import com.thinkaurelius.titan.core.TitanFactory;
26import com.thinkaurelius.titan.core.TitanGraph;
27
28//Add Powermock preparation
29@RunWith(PowerMockRunner.class)
30@PrepareForTest({TitanFactory.class, GraphDBConnection.class, GraphDBOperation.class, SwitchStorageImpl.class})
31public 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 Radoslavovd28cf7c2013-10-26 11:27:43 -0700107 * 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 Radoslavov7d4a40e2013-10-27 23:39:40 -0700125 * 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 Radoslavov204b2862013-07-12 14:15:36 -0700143 * 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:
Pavlin Radoslavov5139c0b2013-12-09 18:04:53 -0800161 * Test method for get and set Idle Timeout method.
162 * Condition:
163 * N/A
164 * Expect:
165 * 1. Should set the Idle Timeout.
166 * 2. Should get the Idle Timeout.
167 */
168 @Test
169 public void testSetGetIdleTimeout() {
170 String flowId = "xx";
171 Integer idleTimeout = 5;
172 flowPath.setFlowId(flowId);
173 flowPath.setIdleTimeout(idleTimeout);
174 assertEquals(flowPath.getIdleTimeout(), idleTimeout);
175 }
176
177 /**
178 * Desc:
179 * Test method for get and set Hard Timeout method.
180 * Condition:
181 * N/A
182 * Expect:
183 * 1. Should set the Hard Timeout.
184 * 2. Should get the Hard Timeout.
185 */
186 @Test
187 public void testSetGetHardTimeout() {
188 String flowId = "xx";
189 Integer hardTimeout = 5;
190 flowPath.setFlowId(flowId);
191 flowPath.setHardTimeout(hardTimeout);
192 assertEquals(flowPath.getHardTimeout(), hardTimeout);
193 }
194
195 /**
196 * Desc:
Teru68076a42013-06-27 14:57:49 -0700197 * Test method for get and set SourceSwitch method.
198 * Condition:
199 * N/A
200 * Expect:
201 * 1. Should set the source switch.
202 * 2. Should get the source switch.
203 */
204 @Test
205 public void testSetGetSourceSwitch() {
206 String flowId = "xx";
207 String sourceSwitch = "aa";
208 flowPath.setFlowId(flowId);
209 flowPath.setSrcSwitch(sourceSwitch);
210 assertEquals(flowPath.getSrcSwitch(), sourceSwitch);
211 }
212
213 /**
214 * Desc:
215 * Test method for get and set SourcePort method.
216 * Condition:
217 * N/A
218 * Expect:
219 * 1. Should set the source port.
220 * 2. Should get the source port.
221 */
222 @Test
223 public void testSetGetSourcePort() {
224 String flowId = "xx";
225 Short sourcePort = 1;
226 flowPath.setFlowId(flowId);
227 flowPath.setSrcPort(sourcePort);
228 assertEquals(flowPath.getSrcPort(), sourcePort);
229 }
230
231 /**
232 * Desc:
233 * Test method for get and set DestSwitch method.
234 * Condition:
235 * N/A
236 * Expect:
237 * 1. Should set the dest switch.
238 * 2. Should get the dest switch.
239 */
240 @Test
241 public void testSetGetDestSwitch() {
242 String flowId = "xx";
243 String destSwitch = "bb";
244 flowPath.setFlowId(flowId);
245 flowPath.setDstSwitch(destSwitch);
246 assertEquals(flowPath.getDstSwitch(), destSwitch);
247 }
248
249 /**
250 * Desc:
251 * Test method for get and set DestPort method.
252 * Condition:
253 * N/A
254 * Expect:
255 * 1. Should set the source dest port.
256 * 2. Should get the source dest port.
257 */
258 @Test
259 public void testSetGetDstPort() {
260 String flowId = "xx";
261 Short dstPort = 2;
262 flowPath.setFlowId(flowId);
263 flowPath.setDstPort(dstPort);
264 assertEquals(flowPath.getDstPort(), dstPort);
265 }
266
267 /**
268 * Desc:
269 * Test method for get and set DataPathSummary method.
270 * Condition:
271 * N/A
272 * Expect:
273 * 1. Should set the data path summary.
274 * 2. Should get the data path summary.
275 */
276 @Test
277 public void testSetGetDataPathSummary() {
278 String flowId = "xx";
279 String dataPathSummary = "yy";
280 flowPath.setFlowId(flowId);
281 flowPath.setInstallerId(dataPathSummary);
282 assertEquals(flowPath.getInstallerId(), dataPathSummary);
283 }
284
285 public boolean testIFlowEntry(IFlowPath fp, IFlowEntry fe)
286 {
287 ArrayList<IFlowEntry> flowEntryList = new ArrayList<IFlowEntry>();
288 for(IFlowEntry inFlowEntry : fp.getFlowEntries())
289 {
290 flowEntryList.add(inFlowEntry);
291 }
292 return flowEntryList.contains(fe);
293 }
294
295 /**
296 * Desc:
297 * Test method for addFlowEntry and getFlorEntries method.
298 * Condition:
299 * N/A
300 * Expect:
301 * 1. Should add the FlowEntry.
302 * 2. Should get the FlowEntries. It is tested in the testIFlowEntry method.
303 */
304 @Test
305 public void testAddFlowEntryAndGetFlowEntries() {
306 String flowId = "xx";
307 flowPath.setFlowId(flowId);
308 flowPath.addFlowEntry(flowEntry);
309 IFlowEntry flowEntry2 = ope.newFlowEntry();
310 flowPath.addFlowEntry(flowEntry2);
311 assertTrue(testIFlowEntry(flowPath, flowEntry));
312 assertTrue(testIFlowEntry(flowPath, flowEntry2));
313 }
314
315 /**
316 * Desc:
317 * Test method for remove FlowEntry.
318 * Condition:
319 * N/A
320 * Expect:
321 * 1. Should remove FlowEntry.
322 */
323 @Test
324 public void testRemoveFlowEntry() {
325 String flowId = "xx";
326 flowPath.setFlowId(flowId);
327 flowPath.addFlowEntry(flowEntry);
328 flowPath.removeFlowEntry(flowEntry);
329 assertTrue(!testIFlowEntry(flowPath, flowEntry));
330 }
331
332 /**
333 * Desc:
Teru68076a42013-06-27 14:57:49 -0700334 * Test method for set and get MatchSrcMac
335 * Condition:
336 * N/A
337 * Expect:
338 * 1. Should set MatchSrcMac.
339 * 2. Should get MatchSrcMac.
340 */
341 @Test
342 public void testSetGetMatchSrcMac() {
343 String flowId = "xx";
344 String matchSrcMac = "00:00:00:00:00:11";
345 flowPath.setFlowId(flowId);
346 flowPath.setMatchSrcMac(matchSrcMac);
347 assertEquals(flowPath.getMatchSrcMac(), matchSrcMac);
348 }
349
350 /**
351 * Desc:
352 * Test method for set and get MatchDstMac.
353 * Condition:
354 * N/A
355 * Expect:
356 * 1. Should set MatchDstMac.
357 * 2. Should get MatchDstMac.
358 */
359 @Test
360 public void testSetGetMatchDstMac() {
361 String flowId = "xx";
362 String matchDstMac = "00:00:00:00:00:11";
363 flowPath.setFlowId(flowId);
364 flowPath.setMatchDstMac(matchDstMac);
365 assertEquals(flowPath.getMatchDstMac(), matchDstMac);
366 }
Pavlin Radoslavovad3a1e62013-07-09 13:30:16 -0700367
Teru68076a42013-06-27 14:57:49 -0700368 /**
369 * Desc:
Pavlin Radoslavovad3a1e62013-07-09 13:30:16 -0700370 * Test method for set and get MatchEthernetFrameType
Teru68076a42013-06-27 14:57:49 -0700371 * Condition:
372 * N/A
373 * Expect:
Pavlin Radoslavovad3a1e62013-07-09 13:30:16 -0700374 * 1. Should set MatchEthernetFrameType.
375 * 2. Should get MatchEthernetFrameType.
376 */
377 @Test
378 public void testSetGetMatchEthernetFrameType() {
379 String flowId = "xx";
380 Short matchEthernetFrameType = 1;
381 flowPath.setFlowId(flowId);
382 flowPath.setMatchEthernetFrameType(matchEthernetFrameType);
383 assertEquals(flowPath.getMatchEthernetFrameType(), matchEthernetFrameType);
384 }
385
386 /**
387 * Desc:
388 * Test method for set and get MatchVlanId
389 * Condition:
390 * N/A
391 * Expect:
392 * 1. Should set MatchVlanId.
393 * 2. Should get MatchVlanId.
394 */
395 @Test
396 public void testSetGetMatchVlanId() {
397 String flowId = "xx";
398 Short matchVlanId = 10;
399 flowPath.setFlowId(flowId);
400 flowPath.setMatchVlanId(matchVlanId);
401 assertEquals(flowPath.getMatchVlanId(), matchVlanId);
402 }
403
404 /**
405 * Desc:
406 * Test method for set and get MatchVlanPriority
407 * Condition:
408 * N/A
409 * Expect:
410 * 1. Should set MatchVlanPriority.
411 * 2. Should get MatchVlanPriority.
412 */
413 @Test
414 public void testSetGetMatchVlanPriority() {
415 String flowId = "xx";
416 Byte matchVlanPriority = 20;
417 flowPath.setFlowId(flowId);
418 flowPath.setMatchVlanPriority(matchVlanPriority);
419 assertEquals(flowPath.getMatchVlanPriority(), matchVlanPriority);
420 }
421
422 /**
423 * Desc:
424 * Test method for set and get MatchSrcIPv4Net.
425 * Condition:
426 * N/A
427 * Expect:
428 * 1. Should set MatchSrcIPv4Net.
429 * 2. Should get MatchSrcIPv4Net.
Teru68076a42013-06-27 14:57:49 -0700430 */
431 @Test
432 public void testSetGetMatchSrcIPv4Net() {
433 String flowId = "xx";
434 String ip = "192.168.0.1";
435 flowPath.setFlowId(flowId);
436 flowPath.setMatchSrcIPv4Net(ip);
437 assertEquals(flowPath.getMatchSrcIPv4Net(), ip);
438 }
439
440 /**
441 * Desc:
Pavlin Radoslavovad3a1e62013-07-09 13:30:16 -0700442 * Test method for set and get MatchDstIPv4Net.
Teru68076a42013-06-27 14:57:49 -0700443 * Condition:
444 * N/A
445 * Expect:
Pavlin Radoslavovad3a1e62013-07-09 13:30:16 -0700446 * 1. Should set MatchDstIPv4Net.
447 * 2. Should get MatchDstIPv4Net.
Teru68076a42013-06-27 14:57:49 -0700448 */
449 @Test
450 public void testSetGetMatchDstIPv4Net() {
451 String flowId = "xx";
452 String ip = "192.168.0.1";
453 flowPath.setFlowId(flowId);
454 flowPath.setMatchDstIPv4Net(ip);
455 assertEquals(flowPath.getMatchDstIPv4Net(), ip);
456 }
Pavlin Radoslavovad3a1e62013-07-09 13:30:16 -0700457
458 /**
459 * Desc:
460 * Test method for set and get MatchIpProto
461 * Condition:
462 * N/A
463 * Expect:
464 * 1. Should set MatchIpProto.
465 * 2. Should get MatchIpProto.
466 */
467 @Test
468 public void testSetGetMatchIpProto() {
469 String flowId = "xx";
470 Byte matchIpProto = 20;
471 flowPath.setFlowId(flowId);
472 flowPath.setMatchIpProto(matchIpProto);
473 assertEquals(flowPath.getMatchIpProto(), matchIpProto);
474 }
475
476 /**
477 * Desc:
478 * Test method for set and get MatchIpToS
479 * Condition:
480 * N/A
481 * Expect:
482 * 1. Should set MatchIpToS.
483 * 2. Should get MatchIpToS.
484 */
485 @Test
486 public void testSetGetMatchIpToS() {
487 String flowId = "xx";
488 Byte matchIpToS = 20;
489 flowPath.setFlowId(flowId);
490 flowPath.setMatchIpToS(matchIpToS);
491 assertEquals(flowPath.getMatchIpToS(), matchIpToS);
492 }
493
494 /**
495 * Desc:
496 * Test method for set and get MatchSrcTcpUdpPort.
497 * Condition:
498 * N/A
499 * Expect:
500 * 1. Should set MatchSrcTcpUdpPort.
501 * 2. Should get MatchSrcTcpUdpPort.
502 */
503 @Test
504 public void testSetGetMatchSrcTcpUdpPort() {
505 String flowId = "xx";
506 Short srcTcpUdpPort = (short)65535;
507 flowPath.setFlowId(flowId);
508 flowPath.setMatchSrcTcpUdpPort(srcTcpUdpPort);
509 assertEquals(flowPath.getMatchSrcTcpUdpPort(), srcTcpUdpPort);
510 }
511
512 /**
513 * Desc:
514 * Test method for set and get MatchDstTcpUdpPort.
515 * Condition:
516 * N/A
517 * Expect:
518 * 1. Should set MatchDstTcpUdpPort.
519 * 2. Should get MatchDstTcpUdpPort.
520 */
521 @Test
522 public void testSetGetMatchDstTcpUdpPort() {
523 String flowId = "xx";
524 Short dstTcpUdpPort = (short)65535;
525 flowPath.setFlowId(flowId);
526 flowPath.setMatchDstTcpUdpPort(dstTcpUdpPort);
527 assertEquals(flowPath.getMatchDstTcpUdpPort(), dstTcpUdpPort);
528 }
529
Teru68076a42013-06-27 14:57:49 -0700530 /**
531 * Desc:
Teru68076a42013-06-27 14:57:49 -0700532 * Test method for get Switches.
533 * Condition:
534 * N/A
535 * Expect:
536 * 1. Should get switches.
537 */
538 @Test
539 public void testGetSwitches() {
540 String flowId = "xx";
541 String dpid = "1";
542 flowPath.setFlowId(flowId);
543 ISwitchObject sw = ope.newSwitch(dpid);
544 flowEntry.setSwitch(sw);
545 flowPath.addFlowEntry(flowEntry);
546
547 HashMap<String, ISwitchObject> swList = new HashMap<String, ISwitchObject>();
548 for(ISwitchObject insw : flowPath.getSwitches()){
549 swList.put(sw.getDPID(), insw);
550 }
551
552 assertTrue(swList.containsKey(dpid));
553 }
554
555 //TODO Dont know how to set the state property.
556 @Test
557 public void testGetState() {
558 String status = null;
559 assertEquals(flowPath.getState(), status);
560 }
561
562
563}