blob: 750bfbaf7b7c06fe9f5708069960a4d3268a8dd8 [file] [log] [blame]
Toshio Koidefe2625e2013-06-26 13:59:53 -07001package net.onrc.onos.ofcontroller.flowmanager;
2
3import static org.junit.Assert.*;
4import static org.easymock.EasyMock.expect;
5import static org.easymock.EasyMock.cmpEq;
6import static org.powermock.api.easymock.PowerMock.*;
7
8import java.util.*;
9import java.util.concurrent.Executors;
10import java.util.concurrent.ScheduledExecutorService;
11import java.util.concurrent.TimeUnit;
12
13import net.floodlightcontroller.core.IFloodlightProviderService;
Toshio Koideca7abe02013-06-27 17:30:17 -070014import net.floodlightcontroller.core.IOFSwitch;
Toshio Koidefe2625e2013-06-26 13:59:53 -070015import net.floodlightcontroller.core.module.FloodlightModuleContext;
16import net.floodlightcontroller.core.module.IFloodlightService;
17import net.floodlightcontroller.restserver.IRestApiService;
18import net.onrc.onos.graph.GraphDBOperation;
19import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IFlowEntry;
20import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IFlowPath;
Toshio Koidefe2625e2013-06-26 13:59:53 -070021import net.onrc.onos.ofcontroller.flowmanager.web.FlowWebRoutable;
Pavlin Radoslavovddd01ba2013-07-03 15:40:44 -070022import net.onrc.onos.ofcontroller.routing.TopoRouteService;
Toshio Koidefe2625e2013-06-26 13:59:53 -070023import net.onrc.onos.ofcontroller.util.*;
24
25import org.easymock.EasyMock;
26import org.easymock.IAnswer;
27import org.junit.After;
28import org.junit.Before;
Toshio Koideca7abe02013-06-27 17:30:17 -070029import org.junit.Ignore;
Toshio Koidefe2625e2013-06-26 13:59:53 -070030import org.junit.Test;
31import org.junit.runner.RunWith;
Toshio Koideca7abe02013-06-27 17:30:17 -070032import org.openflow.protocol.OFFlowMod;
33import org.openflow.protocol.OFType;
34import org.openflow.protocol.factory.BasicFactory;
Toshio Koidefe2625e2013-06-26 13:59:53 -070035import org.powermock.core.classloader.annotations.PrepareForTest;
36import org.powermock.modules.junit4.PowerMockRunner;
37
38/**
39 * @author Toshio Koide
40 */
41@RunWith(PowerMockRunner.class)
42@PrepareForTest({FlowManager.class, GraphDBOperation.class, System.class, Executors.class})
43public class FlowManagerTest {
44 private static FloodlightModuleContext context;
45 private static IFloodlightProviderService floodlightProvider;
Pavlin Radoslavovddd01ba2013-07-03 15:40:44 -070046 private static TopoRouteService topoRouteService;
Toshio Koidefe2625e2013-06-26 13:59:53 -070047 private static IRestApiService restApi;
48 private static GraphDBOperation op;
49
50 /**
51 * @throws java.lang.Exception
52 */
53 @Before
54 public void setUp() throws Exception {
55 }
56
57 /**
58 * @throws java.lang.Exception
59 */
60 @After
61 public void tearDown() throws Exception {
62 }
63
64 /**
65 * @throws java.lang.Exception
66 */
67 private void expectInitWithContext() throws Exception {
68 // create mock objects
69 context = createMock(FloodlightModuleContext.class);
70 floodlightProvider = createMock(IFloodlightProviderService.class);
Pavlin Radoslavovddd01ba2013-07-03 15:40:44 -070071 topoRouteService = createMock(TopoRouteService.class);
Toshio Koidefe2625e2013-06-26 13:59:53 -070072 restApi = createMock(IRestApiService.class);
73 op = createMock(GraphDBOperation.class);
74
75 // setup expectations
76 expect(context.getServiceImpl(IFloodlightProviderService.class)).andReturn(floodlightProvider);
Toshio Koidefe2625e2013-06-26 13:59:53 -070077 expect(context.getServiceImpl(IRestApiService.class)).andReturn(restApi);
78 expectNew(GraphDBOperation.class, new Class<?>[] {String.class}, EasyMock.isA(String.class)).andReturn(op);
Pavlin Radoslavovddd01ba2013-07-03 15:40:44 -070079 expectNew(TopoRouteService.class, new Class<?>[] {String.class}, EasyMock.isA(String.class)).andReturn(topoRouteService);
Toshio Koidefe2625e2013-06-26 13:59:53 -070080 }
81
82 private IFlowPath createIFlowPathMock(long flowId, String installerID,
83 long srcDpid, int srcPort, long dstDpid, int dstPort) {
84 IFlowPath iFlowPath = createNiceMock(IFlowPath.class);
85 expect(iFlowPath.getFlowId()).andReturn(new FlowId(flowId).toString()).anyTimes();
86 expect(iFlowPath.getInstallerId()).andReturn(installerID).anyTimes();
87 expect(iFlowPath.getSrcSwitch()).andReturn(new Dpid(srcDpid).toString()).anyTimes();
88 expect(iFlowPath.getSrcPort()).andReturn(new Short((short)srcPort)).anyTimes();
89 expect(iFlowPath.getDstSwitch()).andReturn(new Dpid(dstDpid).toString()).anyTimes();
90 expect(iFlowPath.getDstPort()).andReturn(new Short((short)dstPort)).anyTimes();
Toshio Koidefe2625e2013-06-26 13:59:53 -070091 return iFlowPath;
92 }
93
Toshio Koideca7abe02013-06-27 17:30:17 -070094 private FlowPath createTestFlowPath(long flowId, String installerId,
Toshio Koidefe2625e2013-06-26 13:59:53 -070095 final long srcDpid, final int srcPort,
96 final long dstDpid, final int dstPort
97 ) {
98 FlowPath flowPath = new FlowPath();
99 flowPath.setFlowId(new FlowId(flowId));
100 flowPath.setInstallerId(new CallerId(installerId));
101 flowPath.setDataPath(new DataPath() {{
102 setSrcPort(new SwitchPort(new Dpid(srcDpid), new Port((short)srcPort)));
103 setDstPort(new SwitchPort(new Dpid(dstDpid), new Port((short)dstPort)));
104 }});
105 flowPath.setFlowEntryMatch(new FlowEntryMatch());
106 return flowPath;
107 }
108
109 private ArrayList<FlowPath> createTestFlowPaths() {
110 FlowPath flowPath1 = createTestFlowPath(1, "foo caller id", 1, 1, 2, 2);
111 FlowPath flowPath2 = createTestFlowPath(2, "caller id", 1, 1, 2, 2);
112 FlowPath flowPath3 = createTestFlowPath(3, "caller id", 1, 5, 2, 2);
113
114 ArrayList<FlowPath> flowPaths = new ArrayList<FlowPath>();
115 flowPaths.add(flowPath1);
116 flowPaths.add(flowPath2);
117 flowPaths.add(flowPath3);
118
119 return flowPaths;
120 }
121
122
123 // IFlowService methods
124
125
126 /**
127 * Test method for {@link FlowManager#addFlow(FlowPath, FlowId, String)}.
128 * @throws Exception
129 */
130 @Test
131 public final void testAddFlowFailGraphCreatesNoFlow() throws Exception {
132 // instantiate required objects
133 FlowId flowId = new FlowId(123);
134 FlowPath flowPath = new FlowPath();
135 flowPath.setFlowId(flowId);
Toshio Koideca7abe02013-06-27 17:30:17 -0700136 FlowManager fm = new FlowManager();
Toshio Koidefe2625e2013-06-26 13:59:53 -0700137
138 // setup expectations
139 expectInitWithContext();
140 expect(op.searchFlowPath(flowId)).andReturn(null);
141 expect(op.newFlowPath()).andReturn(null);
142 op.rollback();
143
144 // start the test
145 replayAll();
Toshio Koidefe2625e2013-06-26 13:59:53 -0700146
Toshio Koidefe2625e2013-06-26 13:59:53 -0700147 fm.init(context);
148 Boolean result = fm.addFlow(flowPath, flowId, "");
149
150 // verify the test
151 verifyAll();
152 assertFalse(result);
153 }
154
155 /**
156 * Test method for {@link FlowManager#addFlow(FlowPath, FlowId, String)}.
157 * @throws Exception
158 */
159 @Test
160 public final void testAddFlowSuccessNormally() throws Exception {
161 final String addFlowEntry = "addFlowEntry";
162 // create mock objects
163 IFlowPath createdFlowPath = createNiceMock(IFlowPath.class);
164 IFlowEntry createdFlowEntry1 = createNiceMock(IFlowEntry.class);
165 IFlowEntry createdFlowEntry2 = createNiceMock(IFlowEntry.class);
166 FlowManager fm = createPartialMockAndInvokeDefaultConstructor(FlowManager.class, addFlowEntry);
167
168 // instantiate required objects
169 final FlowEntry flowEntry1 = new FlowEntry();
170 final FlowEntry flowEntry2 = new FlowEntry();
171 ArrayList<FlowEntry> flowEntries = new ArrayList<FlowEntry>();
172 flowEntries.add(flowEntry1);
173 flowEntries.add(flowEntry2);
174
175 DataPath dataPath = new DataPath();
176 dataPath.setSrcPort(new SwitchPort(new Dpid(0x1234), new Port((short)1)));
177 dataPath.setDstPort(new SwitchPort(new Dpid(0x5678), new Port((short)2)));
178 dataPath.setFlowEntries(flowEntries);
179
180 FlowEntryMatch match = new FlowEntryMatch();
181
182 FlowPath flowPath = new FlowPath();
183 flowPath.setFlowId(new FlowId(0x100));
184 flowPath.setInstallerId(new CallerId("installer id"));
185 flowPath.setDataPath(dataPath);
186 flowPath.setFlowEntryMatch(match);
187
188 // setup expectations
189 expectInitWithContext();
190 expect(op.searchFlowPath(cmpEq(new FlowId(0x100)))).andReturn(null);
191 expect(op.newFlowPath()).andReturn(createdFlowPath);
192 createdFlowPath.setFlowId("0x100");
193 createdFlowPath.setType("flow");
194 createdFlowPath.setInstallerId("installer id");
195 createdFlowPath.setSrcSwitch("00:00:00:00:00:00:12:34");
196 createdFlowPath.setSrcPort(new Short((short)1));
197 createdFlowPath.setDstSwitch("00:00:00:00:00:00:56:78");
198 createdFlowPath.setDstPort(new Short((short)2));
199 createdFlowPath.setDataPathSummary("data path summary");
200 createdFlowPath.setUserState("FE_USER_ADD");
201
202 expectPrivate(fm, addFlowEntry, createdFlowPath, flowEntry1)
203 .andReturn(createdFlowEntry1);
204 expectPrivate(fm, addFlowEntry, createdFlowPath, flowEntry2)
205 .andReturn(createdFlowEntry2);
206
207 op.commit();
208
209 // start the test
210 replayAll();
211
212 fm.init(context);
213 Boolean result = fm.addFlow(flowPath, new FlowId(0x100), "data path summary");
214
215 // verify the test
216 verifyAll();
217 assertTrue(result);
218 }
219
220 /**
221 * Test method for {@link FlowManager#deleteAllFlows()}.
222 * @throws Exception
223 */
224 @Test
225 public final void testDeleteAllFlowsSuccessNormally() throws Exception {
226 // create mock objects
227 IFlowPath flowPath1 = createNiceMock(IFlowPath.class);
228 IFlowPath flowPath2 = createNiceMock(IFlowPath.class);
229
230 // instantiate required objects
231 ArrayList<IFlowPath> flowPaths = new ArrayList<IFlowPath>();
232 flowPaths.add(flowPath1);
233 flowPaths.add(flowPath2);
Toshio Koideca7abe02013-06-27 17:30:17 -0700234 FlowManager fm = new FlowManager();
Toshio Koidefe2625e2013-06-26 13:59:53 -0700235
236 // setup expectations
237 expectInitWithContext();
238 expect(op.getAllFlowPaths()).andReturn(flowPaths);
239
240 expect(flowPath1.getFlowId()).andReturn("1").anyTimes();
241 expect(op.searchFlowPath(cmpEq(new FlowId(1)))).andReturn(flowPath1);
242 expect(flowPath1.getFlowEntries()).andReturn(new ArrayList<IFlowEntry>());
243 op.removeFlowPath(flowPath1);
244
245 expect(flowPath2.getFlowId()).andReturn("2").anyTimes();
246 expect(op.searchFlowPath(cmpEq(new FlowId(2)))).andReturn(flowPath2);
247 expect(flowPath2.getFlowEntries()).andReturn(new ArrayList<IFlowEntry>());
248 op.removeFlowPath(flowPath2);
249
250 op.commit();
251 expectLastCall().anyTimes();
252
253 // start the test
254 replayAll();
255
Toshio Koidefe2625e2013-06-26 13:59:53 -0700256 fm.init(context);
257 Boolean result = fm.deleteAllFlows();
258
259 // verify the test
260 verifyAll();
261 assertTrue(result);
262 }
263
264 /**
265 * Test method for {@link FlowManager#deleteFlow(FlowId)}.
266 * @throws Exception
267 */
268 @Test
269 public final void testDeleteFlowSuccessEmptyFlowPath() throws Exception {
Toshio Koideca7abe02013-06-27 17:30:17 -0700270 // instantiate required objects
271 FlowManager fm = new FlowManager();
272
Toshio Koidefe2625e2013-06-26 13:59:53 -0700273 // create mock objects
274 IFlowPath flowObj = createNiceMock(IFlowPath.class);
275
276 // setup expectations
277 expectInitWithContext();
278 expect(op.searchFlowPath(cmpEq(new FlowId(1)))).andReturn(flowObj);
279 expect(flowObj.getFlowEntries()).andReturn(new ArrayList<IFlowEntry>());
280 op.removeFlowPath(flowObj);
281 op.commit();
282 expectLastCall().anyTimes();
283
284 // start the test
285 replayAll();
286
Toshio Koidefe2625e2013-06-26 13:59:53 -0700287 fm.init(context);
288 Boolean result = fm.deleteFlow(new FlowId(1));
289
290 // verify the test
291 verifyAll();
292 assertTrue(result);
293 }
294
295 /**
296 * Test method for {@link FlowManager#clearAllFlows()}.
297 * @throws Exception
298 */
299 @Test
300 public final void testClearAllFlowsSuccessNormally() throws Exception {
301 // create mock objects
302 IFlowPath flowPath1 = createNiceMock(IFlowPath.class);
303 IFlowPath flowPath2 = createNiceMock(IFlowPath.class);
304 IFlowPath flowPath3 = createNiceMock(IFlowPath.class);
305 FlowManager fm = createPartialMockAndInvokeDefaultConstructor(FlowManager.class, "clearFlow");
306
307 // instantiate required objects
308 ArrayList<IFlowPath> flowPaths = new ArrayList<IFlowPath>();
309 flowPaths.add(flowPath1);
310 flowPaths.add(flowPath2);
311 flowPaths.add(null);
312 flowPaths.add(flowPath3);
313
314 // setup expectations
315 expectInitWithContext();
316 expect(op.getAllFlowPaths()).andReturn(flowPaths);
317 expect(flowPath1.getFlowId()).andReturn(new FlowId(1).toString());
318 expect(flowPath2.getFlowId()).andReturn(null);
319 expect(flowPath3.getFlowId()).andReturn(new FlowId(3).toString());
320 expect(fm.clearFlow(cmpEq(new FlowId(1)))).andReturn(true);
321 expect(fm.clearFlow(cmpEq(new FlowId(3)))).andReturn(true);
322
323 // start the test
324 replayAll();
325
326 fm.init(context);
327 Boolean result = fm.clearAllFlows();
328
329 //verify the test
330 verifyAll();
331 assertTrue(result);
332 }
333
334 /**
335 * Test method for {@link FlowManager#getFlow()}.
336 * @throws Exception
337 */
338 @Test
339 public final void testGetFlowSuccessNormally() throws Exception {
340 // instantiate required objects
341 FlowManager fm = new FlowManager();
Toshio Koideca7abe02013-06-27 17:30:17 -0700342 IFlowPath iFlowPath = createIFlowPathMock(1, "caller id", 1, 1, 2, 2);
Toshio Koidefe2625e2013-06-26 13:59:53 -0700343
344 // setup expectations
345 expectInitWithContext();
Toshio Koideca7abe02013-06-27 17:30:17 -0700346 expect(op.searchFlowPath(cmpEq(new FlowId(1)))).andReturn(iFlowPath);
347 expect(iFlowPath.getFlowEntries()).andReturn(new ArrayList<IFlowEntry>()).anyTimes();
Toshio Koidefe2625e2013-06-26 13:59:53 -0700348 op.commit();
349
350 // start the test
351 replayAll();
352
353 fm.init(context);
354 String result = fm.getFlow(new FlowId(1)).installerId().toString();
355
356 //verify the test
357 verifyAll();
358 assertEquals("caller id", result);
359 }
360
361 /**
362 * Test method for {@link FlowManager#getAllFlows(CallerId, DataPathEndpoints)}.
363 * @throws Exception
364 */
365 @Test
366 public final void testGetAllFlowsWithCallerIdAndDataPathEndpointsSuccessNormally() throws Exception {
367 final String getAllFlows = "getAllFlows";
368 // create mock objects
369 FlowManager fm = createPartialMock(FlowManager.class, getAllFlows,
370 new Class<?>[]{}, new Object[]{});
371
372 // instantiate required objects
373 DataPathEndpoints dataPathEndpoints = new DataPathEndpoints(
374 new SwitchPort(new Dpid(1), new Port((short)1)),
375 new SwitchPort(new Dpid(2), new Port((short)2)));
376
377 ArrayList<FlowPath> obtainedAllFlows = createTestFlowPaths();
378
379 //setup expectations
380 expectInitWithContext();
381 expectPrivate(fm, getAllFlows).andReturn(obtainedAllFlows);
382
383 //start the test
384 replayAll();
385
386 fm.init(context);
387 ArrayList<FlowPath> flows = fm.getAllFlows(new CallerId("caller id"), dataPathEndpoints);
388
389 // verify the test
390 verifyAll();
391 assertEquals(1, flows.size());
392 assertEquals(obtainedAllFlows.get(1), flows.get(0));
393 }
394
395 /**
396 * Test method for {@link FlowManager#getAllFlows(DataPathEndpoints)}.
397 * @throws Exception
398 */
399 @Test
400 public final void testGetAllFlowsWithDataPathEndpointsSuccessNormally() throws Exception {
401 final String getAllFlows = "getAllFlows";
402 // create mock objects
403 FlowManager fm = createPartialMock(FlowManager.class, getAllFlows,
404 new Class<?>[]{}, new Object[]{});
405
406 // instantiate required objects
407 DataPathEndpoints dataPathEndpoints = new DataPathEndpoints(
408 new SwitchPort(new Dpid(1), new Port((short)1)),
409 new SwitchPort(new Dpid(2), new Port((short)2)));
410
411 ArrayList<FlowPath> obtainedAllFlows = createTestFlowPaths();
412
413 //setup expectations
414 expectInitWithContext();
415 expectPrivate(fm, getAllFlows).andReturn(obtainedAllFlows);
416
417 //start the test
418 replayAll();
419
420 fm.init(context);
421 ArrayList<FlowPath> flows = fm.getAllFlows(dataPathEndpoints);
422
423 // verify the test
424 verifyAll();
425 assertEquals(2, flows.size());
426 assertEquals(obtainedAllFlows.get(0), flows.get(0));
427 assertEquals(obtainedAllFlows.get(1), flows.get(1));
428 // TODO: ignore the order of flows in the list
429 }
430
431 /**
432 * Test method for {@link FlowManager#getAllFlowsSummary(FlowId, int)}.
433 * @throws Exception
434 */
435 @Test
436 public final void testGetAllFlowsSummarySuccessNormally() throws Exception {
437 final String getAllFlowsWithoutFlowEntries = "getAllFlowsWithoutFlowEntries";
438 // create mock objects
439 FlowManager fm = createPartialMockAndInvokeDefaultConstructor(FlowManager.class, getAllFlowsWithoutFlowEntries);
440 IFlowPath flowPath1 = createIFlowPathMock(1, "", 1, 2, 3, 4);
441 IFlowPath flowPath2 = createIFlowPathMock(5, "", 2, 3, 4, 5);
442 IFlowPath flowPath3 = createIFlowPathMock(10, "", 3, 4, 5, 6);
443
444 // instantiate required objects
445 ArrayList<IFlowPath> flows = new ArrayList<IFlowPath>();
446 flows.add(flowPath3);
447 flows.add(flowPath1);
448 flows.add(flowPath2);
449
450 // setup expectations
451 expectInitWithContext();
452 expectPrivate(fm, getAllFlowsWithoutFlowEntries).andReturn(flows);
453
454 // start the test
455 replayAll();
456
457 fm.init(context);
458 ArrayList<IFlowPath> returnedFlows = fm.getAllFlowsSummary(null, 0);
459
460 // verify the test
461 verifyAll();
462 assertEquals(3, returnedFlows.size());
463 assertEquals(1, new FlowId(returnedFlows.get(0).getFlowId()).value());
464 assertEquals(5, new FlowId(returnedFlows.get(1).getFlowId()).value());
465 assertEquals(10, new FlowId(returnedFlows.get(2).getFlowId()).value());
466 }
467
468 /**
469 * Test method for {@link FlowManager#getAllFlows()}.
470 * @throws Exception
471 */
472 @Test
473 public final void testGetAllFlowsSuccessNormally() throws Exception {
Toshio Koideca7abe02013-06-27 17:30:17 -0700474 // create mock objects
475 IFlowPath iFlowPath1 = createIFlowPathMock(1, "caller id", 1, 1, 2, 2);
476 IFlowPath iFlowPath2 = createIFlowPathMock(2, "caller id", 2, 5, 3, 5);
477
Toshio Koidefe2625e2013-06-26 13:59:53 -0700478 // instantiate required objects
479 ArrayList<IFlowPath> flowPaths = new ArrayList<IFlowPath>();
Toshio Koideca7abe02013-06-27 17:30:17 -0700480 flowPaths.add(iFlowPath1);
481 flowPaths.add(iFlowPath2);
Toshio Koidefe2625e2013-06-26 13:59:53 -0700482 FlowManager fm = new FlowManager();
483
484 // setup expectations
485 expectInitWithContext();
486 expect(op.getAllFlowPaths()).andReturn(flowPaths);
Toshio Koideca7abe02013-06-27 17:30:17 -0700487 expect(iFlowPath1.getFlowEntries()).andReturn(new ArrayList<IFlowEntry>()).anyTimes();
488 expect(iFlowPath2.getFlowEntries()).andReturn(new ArrayList<IFlowEntry>()).anyTimes();
Toshio Koidefe2625e2013-06-26 13:59:53 -0700489 op.commit();
490
491 // start the test
492 replayAll();
493
494 fm.init(context);
495 ArrayList<FlowPath> flows = fm.getAllFlows();
496
497 // verify the test
498 verifyAll();
499 assertEquals(2, flows.size());
500 assertEquals(new SwitchPort(new Dpid(1), new Port((short)1)).toString(),
501 flows.get(0).dataPath().srcPort().toString());
502 assertEquals(new SwitchPort(new Dpid(2), new Port((short)5)).toString(),
503 flows.get(1).dataPath().srcPort().toString());
504 // TODO: more asserts
505 // TODO: ignore seq. of the list
506 }
507
508 /**
509 * Test method for {@link FlowManager#addAndMaintainShortestPathFlow(FlowPath)}.
510 * @throws Exception
511 */
512 @Test
513 public final void testAddAndMaintainShortestPathFlowSuccessNormally() throws Exception {
514 final String addFlow = "addFlow";
515
516 // create mock objects
517 FlowManager fm = createPartialMockAndInvokeDefaultConstructor(FlowManager.class, addFlow);
518
519 // instantiate required objects
520 DataPath dataPath = new DataPath();
521 dataPath.setSrcPort(new SwitchPort(new Dpid(1), new Port((short)3)));
522 dataPath.setDstPort(new SwitchPort(new Dpid(2), new Port((short)4)));
523 FlowEntryMatch match = new FlowEntryMatch();
524 FlowPath paramFlow = new FlowPath();
525 paramFlow.setFlowId(new FlowId(100));
526 paramFlow.setInstallerId(new CallerId("installer id"));
527 paramFlow.setDataPath(dataPath);
528 paramFlow.setFlowEntryMatch(match);
529
530 // setup expectations
531 expectInitWithContext();
532 expectPrivate(fm, addFlow,
533 EasyMock.anyObject(FlowPath.class),
534 EasyMock.anyObject(FlowId.class),
535 EasyMock.anyObject(String.class)
536 ).andAnswer(new IAnswer<Object>() {
537 public Object answer() throws Exception {
538 FlowPath flowPath = (FlowPath)EasyMock.getCurrentArguments()[0];
539 assertEquals(flowPath.flowId().value(), 100);
540 assertEquals(flowPath.installerId().toString(), "installer id");
541 assertEquals(flowPath.dataPath().srcPort().toString(),
542 new SwitchPort(new Dpid(1), new Port((short)3)).toString());
543
544 String dataPathSummary = (String)EasyMock.getCurrentArguments()[2];
545 assertEquals(dataPathSummary, "X");
546
547 return true;
548 }
549 });
550
551 // start the test
552 replayAll();
553
554 fm.init(context);
555 FlowPath resultFlow = fm.addAndMaintainShortestPathFlow(paramFlow);
556
557 // verify the test
558 verifyAll();
559 assertEquals(paramFlow.flowId().value(), resultFlow.flowId().value());
560 assertEquals(paramFlow.installerId().toString(), resultFlow.installerId().toString());
561 assertEquals(paramFlow.dataPath().toString(), resultFlow.dataPath().toString());
562 assertEquals(paramFlow.flowEntryMatch().toString(), resultFlow.flowEntryMatch().toString());
563 }
564
565 /**
566 * Test method for {@link FlowManager#measurementStorePathFlow(FlowPath)}.
567 * @throws Exception
568 */
569 @Test
570 public final void testMeasurementStorePathFlowSuccessNormally() throws Exception {
571 // instantiate required objects
572 FlowPath paramFlow = createTestFlowPath(100, "installer id", 1, 3, 2, 4);
573 Map<Long, Object> shortestPathMap = new HashMap<Long, Object>();
574 FlowManager fm = new FlowManager();
575
576 // setup expectations
577 expectInitWithContext();
578 expect((Map<Long,Object>)topoRouteService.prepareShortestPathTopo()
579 ).andReturn(shortestPathMap);
580 expect(topoRouteService.getTopoShortestPath(
581 shortestPathMap,
582 paramFlow.dataPath().srcPort(),
583 paramFlow.dataPath().dstPort())).andReturn(null);
584
585 // start the test
586 replayAll();
587
588 fm.init(context);
589 FlowPath resultFlowPath = fm.measurementStorePathFlow(paramFlow);
590
591 // verify the test
592 verifyAll();
593 assertEquals(paramFlow.flowId().value(), resultFlowPath.flowId().value());
594 assertEquals(paramFlow.installerId().toString(), resultFlowPath.installerId().toString());
595 assertEquals(paramFlow.dataPath().toString(), resultFlowPath.dataPath().toString());
596 assertEquals(paramFlow.flowEntryMatch().toString(), resultFlowPath.flowEntryMatch().toString());
597 }
598
599 /**
600 * Test method for {@link FlowManager#measurementInstallPaths(Integer)}.
601 * @throws Exception
602 */
603 @Test
604 public final void testMeasurementInstallPathsSuccessNormally() throws Exception {
605 final String addFlow = "addFlow";
606
607 // create mock objects
608 FlowManager fm = createPartialMockAndInvokeDefaultConstructor(FlowManager.class, addFlow);
609
610 // instantiate required objects
611 FlowPath flow1 = createTestFlowPath(1, "installer id", 1, 2, 3, 4);
612 FlowPath flow2 = createTestFlowPath(2, "installer id", 2, 3, 4, 5);
613 FlowPath flow3 = createTestFlowPath(3, "installer id", 3, 4, 5, 6);
614 Map<Long, Object> shortestPathMap = new HashMap<Long, Object>();
615
616 // setup expectations
617 expectInitWithContext();
618 expect((Map<Long,Object>)topoRouteService.prepareShortestPathTopo()
619 ).andReturn(shortestPathMap);
620
621 expect(topoRouteService.getTopoShortestPath(
622 shortestPathMap,
623 flow1.dataPath().srcPort(),
624 flow1.dataPath().dstPort())).andReturn(null);
625
626 expect(topoRouteService.getTopoShortestPath(
627 shortestPathMap,
628 flow2.dataPath().srcPort(),
629 flow2.dataPath().dstPort())).andReturn(null);
630
631 expect(topoRouteService.getTopoShortestPath(
632 shortestPathMap,
633 flow3.dataPath().srcPort(),
634 flow3.dataPath().dstPort())).andReturn(null);
635
636 expectPrivate(fm, addFlow,
637 EasyMock.cmpEq(flow1),
638 EasyMock.anyObject(FlowId.class),
639 EasyMock.anyObject(String.class)).andReturn(true);
640
641 expectPrivate(fm, addFlow,
642 EasyMock.cmpEq(flow2),
643 EasyMock.anyObject(FlowId.class),
644 EasyMock.anyObject(String.class)).andReturn(true);
645
646 expectPrivate(fm, addFlow,
647 EasyMock.cmpEq(flow3),
648 EasyMock.anyObject(FlowId.class),
649 EasyMock.anyObject(String.class)).andReturn(true);
650
651 // start the test
652 replayAll();
653
654 fm.init(context);
655 fm.measurementStorePathFlow(flow1);
656 fm.measurementStorePathFlow(flow2);
657 fm.measurementStorePathFlow(flow3);
658 Boolean result = fm.measurementInstallPaths(3);
659
660 // verify the test
661 verifyAll();
662 assertTrue(result);
663 }
664
665 /**
666 * Test method for {@link FlowManager#measurementGetInstallPathsTimeNsec()}.
667 * @throws Exception
668 */
669 @Test
670 public final void testMeasurementGetInstallPathsTimeNsecSuccessNormally() throws Exception {
671 final String addFlow = "addFlow";
672
673 // create mock objects
674 FlowManager fm = createPartialMockAndInvokeDefaultConstructor(FlowManager.class, addFlow);
675 mockStaticPartial(System.class, "nanoTime");
676
677 // instantiate required objects
678 FlowPath flow1 = createTestFlowPath(1, "installer id", 1, 2, 3, 4);
679 Map<Long, Object> shortestPathMap = new HashMap<Long, Object>();
680
681 // setup expectations
682 expectInitWithContext();
683 expect(System.nanoTime()).andReturn(new Long(100000));
684 expect(System.nanoTime()).andReturn(new Long(110000));
685 expect((Map<Long,Object>)topoRouteService.prepareShortestPathTopo()
686 ).andReturn(shortestPathMap);
687 expect(topoRouteService.getTopoShortestPath(
688 shortestPathMap,
689 flow1.dataPath().srcPort(),
690 flow1.dataPath().dstPort())).andReturn(null);
691 expectPrivate(fm, addFlow,
692 EasyMock.cmpEq(flow1),
693 EasyMock.anyObject(FlowId.class),
694 EasyMock.anyObject(String.class)).andReturn(true);
695
696 // start the test
697 replayAll();
698
699 fm.init(context);
700 fm.measurementStorePathFlow(flow1).toString();
701 fm.measurementInstallPaths(1);
702 Long result = fm.measurementGetInstallPathsTimeNsec();
703
704 // verify the test
705 verifyAll();
706 assertEquals(new Long(10000), result);
707 }
708
709 /**
710 * Test method for {@link FlowManager#measurementGetPerFlowInstallTime()}.
711 * @throws Exception
712 */
713 @Test
714 public final void testMeasurementGetPerFlowInstallTimeSuccessNormally() throws Exception {
715 final String addFlow = "addFlow";
716
717 // create mock objects
718 FlowManager fm = createPartialMockAndInvokeDefaultConstructor(FlowManager.class, addFlow);
719
720 // instantiate required objects
721 FlowPath flow1 = createTestFlowPath(1, "installer id", 1, 2, 3, 4);
722 Map<Long, Object> shortestPathMap = new HashMap<Long, Object>();
723
724 // setup expectations
725 expectInitWithContext();
726 expect((Map<Long,Object>)topoRouteService.prepareShortestPathTopo()
727 ).andReturn(shortestPathMap);
728
729 expect(topoRouteService.getTopoShortestPath(
730 shortestPathMap,
731 flow1.dataPath().srcPort(),
732 flow1.dataPath().dstPort())).andReturn(null);
733
734 expectPrivate(fm, addFlow,
735 EasyMock.cmpEq(flow1),
736 EasyMock.anyObject(FlowId.class),
737 EasyMock.anyObject(String.class)).andReturn(true);
738
739
740 // start the test
741 replayAll();
742
743 fm.init(context);
744 fm.measurementStorePathFlow(flow1);
745 fm.measurementInstallPaths(10);
746 String result = fm.measurementGetPerFlowInstallTime();
747
748 // verify the test
749 verifyAll();
750 assertTrue(result.startsWith("ThreadAndTimePerFlow"));
751 }
752
753 /**
754 * Test method for {@link FlowManager#measurementClearAllPaths()}.
755 * @throws Exception
756 */
757 @Test
758 public final void testMeasurementClearAllPathsSuccessNormally() throws Exception {
759 // instantiate required objects
760 FlowPath paramFlow = createTestFlowPath(100, "installer id", 1, 3, 2, 4);
761 Map<Long, Object> shortestPathMap = new HashMap<Long, Object>();
Toshio Koideca7abe02013-06-27 17:30:17 -0700762 FlowManager fm = new FlowManager();
Toshio Koidefe2625e2013-06-26 13:59:53 -0700763
764 // setup expectations
765 expectInitWithContext();
766 expect((Map<Long,Object>)topoRouteService.prepareShortestPathTopo()
767 ).andReturn(shortestPathMap);
768 expect(topoRouteService.getTopoShortestPath(
769 shortestPathMap,
770 paramFlow.dataPath().srcPort(),
771 paramFlow.dataPath().dstPort())).andReturn(null);
772 topoRouteService.dropShortestPathTopo(shortestPathMap);
773
774 // start the test
775 replayAll();
776
Toshio Koidefe2625e2013-06-26 13:59:53 -0700777 fm.init(context);
778 fm.measurementStorePathFlow(paramFlow);
779 Boolean result = fm.measurementClearAllPaths();
780
781 // verify the test
782 verifyAll();
783 assertTrue(result);
784 assertEquals(new Long(0), fm.measurementGetInstallPathsTimeNsec());
785 assertEquals("", fm.measurementGetPerFlowInstallTime());
786 }
787
788
789 // INetMapStorage methods
790
791
792 /**
793 * Test method for {@link FlowManager#init(String)}.
794 * @throws Exception
795 */
796 @Test
797 public final void testInitSuccessNormally() throws Exception {
Toshio Koideca7abe02013-06-27 17:30:17 -0700798 // instantiate required objects
799 FlowManager fm = new FlowManager();
800
Toshio Koidefe2625e2013-06-26 13:59:53 -0700801 // create mock objects
802 op = createMock(GraphDBOperation.class);
803
804 // setup expectations
805 expectNew(GraphDBOperation.class, "/dummy/path").andReturn(op);
806
807 // start the test
808 replayAll();
809
Toshio Koidefe2625e2013-06-26 13:59:53 -0700810 fm.init("/dummy/path");
811
812 // verify the test
813 verifyAll();
814 }
815
816 /**
817 * Test method for {@link FlowManager#close()}.
818 * @throws Exception
819 */
820 @Test
821 public final void testCloseSuccessNormally() throws Exception {
822 // instantiate required objects
823 FlowManager fm = new FlowManager();
824
825 // setup expectations
826 expectInitWithContext();
827 op.close();
828
829 // start the test
830 replayAll();
831
832 fm.init(context);
833 fm.close();
834
835 // verify the test
836 verifyAll();
837 }
838
839
840 // IFloodlightModule methods
841
842
843 /**
844 * Test method for {@link FlowManager#getModuleServices()}.
845 * @throws Exception
846 */
847 @Test
848 public final void testGetModuleServicesSuccessNormally() throws Exception {
849 // instantiate required objects
850 FlowManager fm = new FlowManager();
851
852 // setup expectations
853 expectInitWithContext();
854
855 // start the test
856 replayAll();
857
858 fm.init(context);
859 Collection<Class<? extends IFloodlightService>> l = fm.getModuleServices();
860
861 // verify the test
862 verifyAll();
863 assertEquals(1, l.size());
864 assertEquals(IFlowService.class, l.iterator().next());
865 }
866
867 /**
868 * Test method for {@link FlowManager#getServiceImpls()}.
869 * @throws Exception
870 */
871 @Test
872 public final void testGetServiceImplsSuccessNormally() throws Exception {
873 // instantiate required objects
874 FlowManager fm = new FlowManager();
875
876 // setup expectations
877 expectInitWithContext();
878
879 // start the test
880 replayAll();
881
882 fm.init(context);
883 Map<Class<? extends IFloodlightService>, IFloodlightService> si = fm.getServiceImpls();
884
885 // verify the test
886 verifyAll();
887 assertEquals(1, si.size());
888 assertTrue(si.containsKey(IFlowService.class));
889 assertEquals(fm, si.get(IFlowService.class));
890 }
891
892 /**
893 * Test method for {@link FlowManager#getModuleDependencies()}.
894 * @throws Exception
895 */
896 @Test
897 public final void testGetModuleDependenciesSuccessNormally() throws Exception {
898 // instantiate required objects
899 FlowManager fm = new FlowManager();
900
901 // setup expectations
902 expectInitWithContext();
903
904 // start the test
905 replayAll();
906
907 fm.init(context);
908 Collection<Class<? extends IFloodlightService>> md = fm.getModuleDependencies();
909
910 // verify the test
911 verifyAll();
Pavlin Radoslavovddd01ba2013-07-03 15:40:44 -0700912 assertEquals(2, md.size());
Toshio Koidefe2625e2013-06-26 13:59:53 -0700913 assertTrue(md.contains(IFloodlightProviderService.class));
Toshio Koidefe2625e2013-06-26 13:59:53 -0700914 assertTrue(md.contains(IRestApiService.class));
915 }
916
917 /**
918 * Test method for {@link FlowManager#init(FloodlightModuleContext)}.
919 * @throws Exception
920 */
921 @Test
922 public final void testInitWithFloodlightModuleContextSuccessNormally() throws Exception {
923 // instantiate required objects
924 FlowManager fm = new FlowManager();
925
926 // setup expectations
927 expectInitWithContext();
928
929 // start the test
930 replayAll();
931
932 fm.init(context);
933
934 // verify the test
935 verifyAll();
936 }
937
938 /**
939 * Test method for {@link FlowManager#startUp(FloodlightModuleContext)}.
940 * @throws Exception
941 */
942 @Test
943 public final void testStartupSuccessNormally() throws Exception {
944 // create mock objects
945 mockStaticPartial(Executors.class, "newScheduledThreadPool");
946 ScheduledExecutorService scheduler = createMock(ScheduledExecutorService.class);
947
Toshio Koidefe2625e2013-06-26 13:59:53 -0700948 // instantiate required objects
949 FlowManager fm = new FlowManager();
950
951 // setup expectations
952 expectInitWithContext();
953 expect(Executors.newScheduledThreadPool(1)).andReturn(scheduler);
954 expect(Executors.newScheduledThreadPool(1)).andReturn(scheduler);
955 expect(scheduler.scheduleAtFixedRate(
956 EasyMock.anyObject(Runnable.class),
957 EasyMock.anyLong(),
958 EasyMock.anyLong(),
959 EasyMock.anyObject(TimeUnit.class))).andReturn(null).times(2);
960 restApi.addRestletRoutable(EasyMock.anyObject(FlowWebRoutable.class));
961
962 // start the test
963 replayAll();
964
965 fm.init(context);
966 fm.startUp(context);
967
968 // verify the test
969 verifyAll();
970 }
Toshio Koideca7abe02013-06-27 17:30:17 -0700971
972
973 // other methods
974
975
976 /**
977 * Test method for {@link FlowManager#clearFlow(FlowId)}.
978 * @throws Exception
979 */
980 @Test
981 public final void testClearFlowSuccessNormally() throws Exception {
982 // create mock objects
983 IFlowPath flowPath = createIFlowPathMock(123, "id", 1, 2, 3, 4);
984 IFlowEntry flowEntry1 = createMock(IFlowEntry.class);
985 IFlowEntry flowEntry2 = createMock(IFlowEntry.class);
986 IFlowEntry flowEntry3 = createMock(IFlowEntry.class);
987
988 // instantiate required objects
989 FlowManager fm = new FlowManager();
990 FlowId flowId = new FlowId(123);
991 ArrayList<IFlowEntry> flowEntries = new ArrayList<IFlowEntry>();
992 flowEntries.add(flowEntry1);
993 flowEntries.add(flowEntry2);
994 flowEntries.add(flowEntry3);
995
996 // setup expectations
997 expectInitWithContext();
998 expect(op.searchFlowPath(cmpEq(flowId))).andReturn(flowPath);
999 expect(flowPath.getFlowEntries()).andReturn(flowEntries);
1000 flowPath.removeFlowEntry(flowEntry1);
1001 flowPath.removeFlowEntry(flowEntry2);
1002 flowPath.removeFlowEntry(flowEntry3);
1003 op.removeFlowEntry(flowEntry1);
1004 op.removeFlowEntry(flowEntry2);
1005 op.removeFlowEntry(flowEntry3);
1006 op.removeFlowPath(flowPath);
1007 op.commit();
1008
1009 // start the test
1010 replayAll();
1011
1012 fm.init(context);
1013 fm.clearFlow(flowId);
1014
1015 // verify the test
1016 verifyAll();
1017 }
1018
1019 /**
1020 * Test method for {@link FlowManager#getAllFlowsWithoutFlowEntries()}.
1021 * @throws Exception
1022 */
1023 @Test
1024 public final void testGetAllFlowsWithoutFlowEntriesSuccessNormally() throws Exception {
1025 // create mock objects
1026 IFlowPath iFlowPath1 = createIFlowPathMock(1, "caller id", 1, 1, 2, 2);
1027 IFlowPath iFlowPath2 = createIFlowPathMock(2, "caller id", 2, 5, 3, 5);
1028
1029 // instantiate required objects
1030 ArrayList<IFlowPath> flowPaths = new ArrayList<IFlowPath>();
1031 flowPaths.add(iFlowPath1);
1032 flowPaths.add(iFlowPath2);
1033 FlowManager fm = new FlowManager();
1034
1035 // setup expectations
1036 expectInitWithContext();
1037 op.commit();
1038 expect(op.getAllFlowPaths()).andReturn(flowPaths);
1039
1040 // start the test
1041 replayAll();
1042
1043 fm.init(context);
1044 ArrayList<IFlowPath> result = fm.getAllFlowsWithoutFlowEntries();
1045
1046 // verify the test
1047 verifyAll();
1048 assertEquals(iFlowPath1, result.get(0));
1049 assertEquals(iFlowPath2, result.get(1));
1050
1051 // TODO: does this method just return the replica of the flow paths?
1052 }
1053
1054 /**
1055 * Test method for {@link FlowManager#reconcileFlow(IFlowPath, DataPath)}.
1056 * @throws Exception
1057 */
1058 @Test
1059 public final void testReconcileFlowWithFlowPathAndDataPathSuccessNormally() throws Exception {
1060 final String addFlowEntry = "addFlowEntry";
1061
1062 // create mock objects
1063 IFlowPath iFlowPath1 = createIFlowPathMock(1, "caller id", 1, 1, 2, 2);
1064 IFlowEntry iFlowEntry1 = createMock(IFlowEntry.class);
1065 IFlowEntry iFlowEntry2 = createMock(IFlowEntry.class);
1066 FlowManager fm = createPartialMockAndInvokeDefaultConstructor(FlowManager.class, addFlowEntry);
1067
1068 // instantiate required objects
1069 FlowEntry flowEntry1 = new FlowEntry();
1070 flowEntry1.setDpid(new Dpid(1));
1071 flowEntry1.setFlowId(new FlowId(1));
1072 flowEntry1.setInPort(new Port((short) 1));
1073 flowEntry1.setOutPort(new Port((short) 11));
1074 flowEntry1.setFlowEntryId(new FlowEntryId(1));
1075 flowEntry1.setFlowEntryMatch(new FlowEntryMatch());
1076 flowEntry1.setFlowEntryActions(new ArrayList<FlowEntryAction>());
1077 flowEntry1.setFlowEntryErrorState(new FlowEntryErrorState());
1078
1079 FlowEntry flowEntry2 = new FlowEntry();
1080 flowEntry2.setDpid(new Dpid(2));
1081 flowEntry2.setFlowId(new FlowId(2));
1082 flowEntry2.setInPort(new Port((short) 22));
1083 flowEntry2.setOutPort(new Port((short) 2));
1084 flowEntry2.setFlowEntryId(new FlowEntryId(2));
1085 flowEntry2.setFlowEntryMatch(new FlowEntryMatch());
1086 flowEntry2.setFlowEntryActions(new ArrayList<FlowEntryAction>());
1087 flowEntry2.setFlowEntryErrorState(new FlowEntryErrorState());
1088
1089 DataPath dataPath = new DataPath();
1090 ArrayList<FlowEntry> flowEntries = new ArrayList<FlowEntry>();
1091 flowEntries.add(flowEntry1);
1092 flowEntries.add(flowEntry2);
1093 dataPath.setFlowEntries(flowEntries);
1094
1095 ArrayList<IFlowEntry> oldFlowEntries = new ArrayList<IFlowEntry>();
1096 oldFlowEntries.add(iFlowEntry1);
1097 oldFlowEntries.add(iFlowEntry2);
1098
1099 // setup expectations
1100 expectInitWithContext();
1101 expect(floodlightProvider.getSwitches()).andReturn(null); // TODO: why is this needed?
1102 expect(iFlowPath1.getFlowEntries()).andReturn(oldFlowEntries);
1103 iFlowEntry1.setUserState("FE_USER_DELETE");
1104 iFlowEntry1.setSwitchState("FE_SWITCH_NOT_UPDATED");
1105 iFlowEntry2.setUserState("FE_USER_DELETE");
1106 iFlowEntry2.setSwitchState("FE_SWITCH_NOT_UPDATED");
1107 expectPrivate(fm, addFlowEntry, iFlowPath1, flowEntry1).andReturn(null);
1108 expectPrivate(fm, addFlowEntry, iFlowPath1, flowEntry2).andReturn(null);
1109
1110 // start the test
1111 replayAll();
1112
1113 fm.init(context);
1114 Boolean result = fm.reconcileFlow(iFlowPath1, dataPath);
1115
1116 // verify the test
1117 verifyAll();
1118 assertTrue(result);
1119 // TODO: write more asserts
1120 }
1121
1122 /**
1123 * Test method for {@link FlowManager#installFlowEntry(net.floodlightcontroller.core.IOFSwitch, IFlowPath, IFlowEntry)}.
1124 * @throws Exception
1125 */
1126 @Test
1127 public final void testInstallFlowEntryWithIFlowPathSuccessNormally() throws Exception {
1128 // create mock object
1129 IOFSwitch iofSwitch = createNiceMock(IOFSwitch.class);
1130 IFlowPath iFlowPath = createIFlowPathMock(1, "id", 1, 2, 3, 4);
1131 IFlowEntry iFlowEntry = createMock(IFlowEntry.class);
1132 BasicFactory basicFactory = createMock(BasicFactory.class);
1133
1134 // instantiate required objects
1135 FlowManager fm = new FlowManager();
1136
1137 // setup expectations
1138 expectInitWithContext();
1139 expect(iFlowEntry.getFlowEntryId()).andReturn(new FlowEntryId(123).toString());
1140 expect(iFlowEntry.getUserState()).andReturn("FE_USER_ADD");
1141 iFlowEntry.setSwitchState("FE_SWITCH_UPDATED");
1142 expect(iFlowEntry.getMatchInPort()).andReturn(new Short((short) 1));
Toshio Koideca7abe02013-06-27 17:30:17 -07001143 expect(iFlowEntry.getMatchSrcMac()).andReturn("01:23:45:67:89:01");
1144 expect(iFlowEntry.getMatchDstMac()).andReturn("01:23:45:67:89:02");
Pavlin Radoslavovad3a1e62013-07-09 13:30:16 -07001145 expect(iFlowEntry.getMatchEthernetFrameType()).andReturn(new Short((short)0x0800));
1146 expect(iFlowEntry.getMatchVlanId()).andReturn(new Short((short)0x1234));
1147 expect(iFlowEntry.getMatchVlanPriority()).andReturn(new Byte((byte)0x10));
1148 expect(iFlowEntry.getMatchSrcIPv4Net()).andReturn("192.168.0.1");
1149 expect(iFlowEntry.getMatchDstIPv4Net()).andReturn("192.168.0.2");
1150 expect(iFlowEntry.getMatchIpProto()).andReturn(new Byte((byte)0x20));
1151 expect(iFlowEntry.getMatchIpToS()).andReturn(new Byte((byte)0x3));
1152 expect(iFlowEntry.getMatchSrcTcpUdpPort()).andReturn(new Short((short)40000));
1153 expect(iFlowEntry.getMatchDstTcpUdpPort()).andReturn(new Short((short)80));
Toshio Koideca7abe02013-06-27 17:30:17 -07001154 expect(iFlowEntry.getActionOutput()).andReturn(new Short((short) 2));
1155 expect(floodlightProvider.getOFMessageFactory()).andReturn(basicFactory);
1156 expect(basicFactory.getMessage(OFType.FLOW_MOD)).andReturn(new OFFlowMod());
1157 expect(iofSwitch.getStringId()).andReturn(new Dpid(100).toString());
1158
1159 // start the test
1160 replayAll();
1161
1162 fm.init(context);
1163 Boolean result = fm.installFlowEntry(iofSwitch, iFlowPath, iFlowEntry);
1164
1165 // verify the test
1166 verifyAll();
1167 assertTrue(result);
1168 // TODO: write more asserts
1169 }
1170
1171 /**
1172 * Test method for {@link FlowManager#installFlowEntry(net.floodlightcontroller.core.IOFSwitch, FlowPath, FlowEntry)}.
1173 * The method seems to be not used for now.
1174 */
1175 @Ignore @Test
1176 public final void testInstallFlowEntryWithFlowPathSuccessNormally() {
1177 fail("not yet implemented");
1178 }
1179
1180 /**
1181 * Test method for {@link FlowManager#removeFlowEntry(net.floodlightcontroller.core.IOFSwitch, FlowPath, FlowEntry)}.
1182 * The method seems to be not implemented and not used for now.
1183 */
1184 @Ignore @Test
1185 public final void testRemoveFlowEntrySuccessNormally() {
1186 fail("not yet implemented");
1187 }
1188
1189 /**
1190 * Test method for {@link FlowManager#installRemoteFlowEntry(FlowPath, FlowEntry)}.
1191 * The method seems to be not implemented and not used for now.
1192 */
1193 @Ignore @Test
1194 public final void testInstallRemoteFlowEntrySuccessNormally() {
1195 fail("not yet implemented");
1196 }
1197
1198 /**
1199 * Test method for {@link FlowManager#removeRemoteFlowEntry(FlowPath, FlowEntry)}.
1200 * The method seems to be not implemented and not used for now.
1201 */
1202 @Ignore @Test
1203 public final void testRemoveRemoteFlowEntrySuccessNormally() {
1204 fail("not yet implemented");
1205 }
Pavlin Radoslavovddd01ba2013-07-03 15:40:44 -07001206}