blob: cacedd2ae6e36c50a9a6da499ccb2b1e9c756e6d [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,
Pavlin Radoslavov204b2862013-07-12 14:15:36 -070083 long flowPathFlags,
Toshio Koidefe2625e2013-06-26 13:59:53 -070084 long srcDpid, int srcPort, long dstDpid, int dstPort) {
85 IFlowPath iFlowPath = createNiceMock(IFlowPath.class);
86 expect(iFlowPath.getFlowId()).andReturn(new FlowId(flowId).toString()).anyTimes();
87 expect(iFlowPath.getInstallerId()).andReturn(installerID).anyTimes();
Pavlin Radoslavov204b2862013-07-12 14:15:36 -070088 expect(iFlowPath.getFlowPathFlags()).andReturn(new Long(flowPathFlags)).anyTimes();
Toshio Koidefe2625e2013-06-26 13:59:53 -070089 expect(iFlowPath.getSrcSwitch()).andReturn(new Dpid(srcDpid).toString()).anyTimes();
90 expect(iFlowPath.getSrcPort()).andReturn(new Short((short)srcPort)).anyTimes();
91 expect(iFlowPath.getDstSwitch()).andReturn(new Dpid(dstDpid).toString()).anyTimes();
92 expect(iFlowPath.getDstPort()).andReturn(new Short((short)dstPort)).anyTimes();
Toshio Koidefe2625e2013-06-26 13:59:53 -070093 return iFlowPath;
94 }
95
Toshio Koideca7abe02013-06-27 17:30:17 -070096 private FlowPath createTestFlowPath(long flowId, String installerId,
Pavlin Radoslavov204b2862013-07-12 14:15:36 -070097 final long flowPathFlags,
Toshio Koidefe2625e2013-06-26 13:59:53 -070098 final long srcDpid, final int srcPort,
99 final long dstDpid, final int dstPort
100 ) {
101 FlowPath flowPath = new FlowPath();
102 flowPath.setFlowId(new FlowId(flowId));
103 flowPath.setInstallerId(new CallerId(installerId));
Pavlin Radoslavov204b2862013-07-12 14:15:36 -0700104 flowPath.setFlowPathFlags(new FlowPathFlags(flowPathFlags));
Toshio Koidefe2625e2013-06-26 13:59:53 -0700105 flowPath.setDataPath(new DataPath() {{
106 setSrcPort(new SwitchPort(new Dpid(srcDpid), new Port((short)srcPort)));
107 setDstPort(new SwitchPort(new Dpid(dstDpid), new Port((short)dstPort)));
108 }});
109 flowPath.setFlowEntryMatch(new FlowEntryMatch());
110 return flowPath;
111 }
112
113 private ArrayList<FlowPath> createTestFlowPaths() {
Pavlin Radoslavov204b2862013-07-12 14:15:36 -0700114 FlowPath flowPath1 = createTestFlowPath(1, "foo caller id", 0, 1, 1, 2, 2);
115 FlowPath flowPath2 = createTestFlowPath(2, "caller id", 0, 1, 1, 2, 2);
116 FlowPath flowPath3 = createTestFlowPath(3, "caller id", 0, 1, 5, 2, 2);
Toshio Koidefe2625e2013-06-26 13:59:53 -0700117
118 ArrayList<FlowPath> flowPaths = new ArrayList<FlowPath>();
119 flowPaths.add(flowPath1);
120 flowPaths.add(flowPath2);
121 flowPaths.add(flowPath3);
122
123 return flowPaths;
124 }
125
126
127 // IFlowService methods
128
129
130 /**
131 * Test method for {@link FlowManager#addFlow(FlowPath, FlowId, String)}.
132 * @throws Exception
133 */
134 @Test
135 public final void testAddFlowFailGraphCreatesNoFlow() throws Exception {
136 // instantiate required objects
137 FlowId flowId = new FlowId(123);
138 FlowPath flowPath = new FlowPath();
139 flowPath.setFlowId(flowId);
Toshio Koideca7abe02013-06-27 17:30:17 -0700140 FlowManager fm = new FlowManager();
Toshio Koidefe2625e2013-06-26 13:59:53 -0700141
142 // setup expectations
143 expectInitWithContext();
144 expect(op.searchFlowPath(flowId)).andReturn(null);
145 expect(op.newFlowPath()).andReturn(null);
146 op.rollback();
147
148 // start the test
149 replayAll();
Toshio Koidefe2625e2013-06-26 13:59:53 -0700150
Toshio Koidefe2625e2013-06-26 13:59:53 -0700151 fm.init(context);
152 Boolean result = fm.addFlow(flowPath, flowId, "");
153
154 // verify the test
155 verifyAll();
156 assertFalse(result);
157 }
158
159 /**
160 * Test method for {@link FlowManager#addFlow(FlowPath, FlowId, String)}.
161 * @throws Exception
162 */
163 @Test
164 public final void testAddFlowSuccessNormally() throws Exception {
165 final String addFlowEntry = "addFlowEntry";
166 // create mock objects
167 IFlowPath createdFlowPath = createNiceMock(IFlowPath.class);
168 IFlowEntry createdFlowEntry1 = createNiceMock(IFlowEntry.class);
169 IFlowEntry createdFlowEntry2 = createNiceMock(IFlowEntry.class);
170 FlowManager fm = createPartialMockAndInvokeDefaultConstructor(FlowManager.class, addFlowEntry);
171
172 // instantiate required objects
173 final FlowEntry flowEntry1 = new FlowEntry();
174 final FlowEntry flowEntry2 = new FlowEntry();
175 ArrayList<FlowEntry> flowEntries = new ArrayList<FlowEntry>();
176 flowEntries.add(flowEntry1);
177 flowEntries.add(flowEntry2);
178
179 DataPath dataPath = new DataPath();
180 dataPath.setSrcPort(new SwitchPort(new Dpid(0x1234), new Port((short)1)));
181 dataPath.setDstPort(new SwitchPort(new Dpid(0x5678), new Port((short)2)));
182 dataPath.setFlowEntries(flowEntries);
183
184 FlowEntryMatch match = new FlowEntryMatch();
185
186 FlowPath flowPath = new FlowPath();
187 flowPath.setFlowId(new FlowId(0x100));
188 flowPath.setInstallerId(new CallerId("installer id"));
Pavlin Radoslavov204b2862013-07-12 14:15:36 -0700189 flowPath.setFlowPathFlags(new FlowPathFlags(0));
Toshio Koidefe2625e2013-06-26 13:59:53 -0700190 flowPath.setDataPath(dataPath);
191 flowPath.setFlowEntryMatch(match);
192
193 // setup expectations
194 expectInitWithContext();
195 expect(op.searchFlowPath(cmpEq(new FlowId(0x100)))).andReturn(null);
196 expect(op.newFlowPath()).andReturn(createdFlowPath);
197 createdFlowPath.setFlowId("0x100");
198 createdFlowPath.setType("flow");
199 createdFlowPath.setInstallerId("installer id");
Pavlin Radoslavov204b2862013-07-12 14:15:36 -0700200 createdFlowPath.setFlowPathFlags(new Long((long)0));
Toshio Koidefe2625e2013-06-26 13:59:53 -0700201 createdFlowPath.setSrcSwitch("00:00:00:00:00:00:12:34");
202 createdFlowPath.setSrcPort(new Short((short)1));
203 createdFlowPath.setDstSwitch("00:00:00:00:00:00:56:78");
204 createdFlowPath.setDstPort(new Short((short)2));
205 createdFlowPath.setDataPathSummary("data path summary");
206 createdFlowPath.setUserState("FE_USER_ADD");
207
208 expectPrivate(fm, addFlowEntry, createdFlowPath, flowEntry1)
209 .andReturn(createdFlowEntry1);
210 expectPrivate(fm, addFlowEntry, createdFlowPath, flowEntry2)
211 .andReturn(createdFlowEntry2);
212
213 op.commit();
214
215 // start the test
216 replayAll();
217
218 fm.init(context);
219 Boolean result = fm.addFlow(flowPath, new FlowId(0x100), "data path summary");
220
221 // verify the test
222 verifyAll();
223 assertTrue(result);
224 }
225
226 /**
227 * Test method for {@link FlowManager#deleteAllFlows()}.
228 * @throws Exception
229 */
230 @Test
231 public final void testDeleteAllFlowsSuccessNormally() throws Exception {
232 // create mock objects
233 IFlowPath flowPath1 = createNiceMock(IFlowPath.class);
234 IFlowPath flowPath2 = createNiceMock(IFlowPath.class);
235
236 // instantiate required objects
237 ArrayList<IFlowPath> flowPaths = new ArrayList<IFlowPath>();
238 flowPaths.add(flowPath1);
239 flowPaths.add(flowPath2);
Toshio Koideca7abe02013-06-27 17:30:17 -0700240 FlowManager fm = new FlowManager();
Toshio Koidefe2625e2013-06-26 13:59:53 -0700241
242 // setup expectations
243 expectInitWithContext();
244 expect(op.getAllFlowPaths()).andReturn(flowPaths);
245
246 expect(flowPath1.getFlowId()).andReturn("1").anyTimes();
247 expect(op.searchFlowPath(cmpEq(new FlowId(1)))).andReturn(flowPath1);
248 expect(flowPath1.getFlowEntries()).andReturn(new ArrayList<IFlowEntry>());
249 op.removeFlowPath(flowPath1);
250
251 expect(flowPath2.getFlowId()).andReturn("2").anyTimes();
252 expect(op.searchFlowPath(cmpEq(new FlowId(2)))).andReturn(flowPath2);
253 expect(flowPath2.getFlowEntries()).andReturn(new ArrayList<IFlowEntry>());
254 op.removeFlowPath(flowPath2);
255
256 op.commit();
257 expectLastCall().anyTimes();
258
259 // start the test
260 replayAll();
261
Toshio Koidefe2625e2013-06-26 13:59:53 -0700262 fm.init(context);
263 Boolean result = fm.deleteAllFlows();
264
265 // verify the test
266 verifyAll();
267 assertTrue(result);
268 }
269
270 /**
271 * Test method for {@link FlowManager#deleteFlow(FlowId)}.
272 * @throws Exception
273 */
274 @Test
275 public final void testDeleteFlowSuccessEmptyFlowPath() throws Exception {
Toshio Koideca7abe02013-06-27 17:30:17 -0700276 // instantiate required objects
277 FlowManager fm = new FlowManager();
278
Toshio Koidefe2625e2013-06-26 13:59:53 -0700279 // create mock objects
280 IFlowPath flowObj = createNiceMock(IFlowPath.class);
281
282 // setup expectations
283 expectInitWithContext();
284 expect(op.searchFlowPath(cmpEq(new FlowId(1)))).andReturn(flowObj);
285 expect(flowObj.getFlowEntries()).andReturn(new ArrayList<IFlowEntry>());
286 op.removeFlowPath(flowObj);
287 op.commit();
288 expectLastCall().anyTimes();
289
290 // start the test
291 replayAll();
292
Toshio Koidefe2625e2013-06-26 13:59:53 -0700293 fm.init(context);
294 Boolean result = fm.deleteFlow(new FlowId(1));
295
296 // verify the test
297 verifyAll();
298 assertTrue(result);
299 }
300
301 /**
302 * Test method for {@link FlowManager#clearAllFlows()}.
303 * @throws Exception
304 */
305 @Test
306 public final void testClearAllFlowsSuccessNormally() throws Exception {
307 // create mock objects
308 IFlowPath flowPath1 = createNiceMock(IFlowPath.class);
309 IFlowPath flowPath2 = createNiceMock(IFlowPath.class);
310 IFlowPath flowPath3 = createNiceMock(IFlowPath.class);
311 FlowManager fm = createPartialMockAndInvokeDefaultConstructor(FlowManager.class, "clearFlow");
312
313 // instantiate required objects
314 ArrayList<IFlowPath> flowPaths = new ArrayList<IFlowPath>();
315 flowPaths.add(flowPath1);
316 flowPaths.add(flowPath2);
317 flowPaths.add(null);
318 flowPaths.add(flowPath3);
319
320 // setup expectations
321 expectInitWithContext();
322 expect(op.getAllFlowPaths()).andReturn(flowPaths);
323 expect(flowPath1.getFlowId()).andReturn(new FlowId(1).toString());
324 expect(flowPath2.getFlowId()).andReturn(null);
325 expect(flowPath3.getFlowId()).andReturn(new FlowId(3).toString());
326 expect(fm.clearFlow(cmpEq(new FlowId(1)))).andReturn(true);
327 expect(fm.clearFlow(cmpEq(new FlowId(3)))).andReturn(true);
328
329 // start the test
330 replayAll();
331
332 fm.init(context);
333 Boolean result = fm.clearAllFlows();
334
335 //verify the test
336 verifyAll();
337 assertTrue(result);
338 }
339
340 /**
341 * Test method for {@link FlowManager#getFlow()}.
342 * @throws Exception
343 */
344 @Test
345 public final void testGetFlowSuccessNormally() throws Exception {
346 // instantiate required objects
347 FlowManager fm = new FlowManager();
Pavlin Radoslavov204b2862013-07-12 14:15:36 -0700348 IFlowPath iFlowPath = createIFlowPathMock(1, "caller id", 0, 1, 1, 2, 2);
Toshio Koidefe2625e2013-06-26 13:59:53 -0700349
350 // setup expectations
351 expectInitWithContext();
Toshio Koideca7abe02013-06-27 17:30:17 -0700352 expect(op.searchFlowPath(cmpEq(new FlowId(1)))).andReturn(iFlowPath);
353 expect(iFlowPath.getFlowEntries()).andReturn(new ArrayList<IFlowEntry>()).anyTimes();
Toshio Koidefe2625e2013-06-26 13:59:53 -0700354 op.commit();
355
356 // start the test
357 replayAll();
358
359 fm.init(context);
Pavlin Radoslavov204b2862013-07-12 14:15:36 -0700360 FlowPath flowPath = fm.getFlow(new FlowId(1));
361 String installerId = flowPath.installerId().toString();
362 long flowPathFlags = flowPath.flowPathFlags().flags();
Toshio Koidefe2625e2013-06-26 13:59:53 -0700363
364 //verify the test
365 verifyAll();
Pavlin Radoslavov204b2862013-07-12 14:15:36 -0700366 assertEquals("caller id", installerId);
367 assertEquals(0L, flowPathFlags);
Toshio Koidefe2625e2013-06-26 13:59:53 -0700368 }
369
370 /**
371 * Test method for {@link FlowManager#getAllFlows(CallerId, DataPathEndpoints)}.
372 * @throws Exception
373 */
374 @Test
375 public final void testGetAllFlowsWithCallerIdAndDataPathEndpointsSuccessNormally() throws Exception {
376 final String getAllFlows = "getAllFlows";
377 // create mock objects
378 FlowManager fm = createPartialMock(FlowManager.class, getAllFlows,
379 new Class<?>[]{}, new Object[]{});
380
381 // instantiate required objects
382 DataPathEndpoints dataPathEndpoints = new DataPathEndpoints(
383 new SwitchPort(new Dpid(1), new Port((short)1)),
384 new SwitchPort(new Dpid(2), new Port((short)2)));
385
386 ArrayList<FlowPath> obtainedAllFlows = createTestFlowPaths();
387
388 //setup expectations
389 expectInitWithContext();
390 expectPrivate(fm, getAllFlows).andReturn(obtainedAllFlows);
391
392 //start the test
393 replayAll();
394
395 fm.init(context);
396 ArrayList<FlowPath> flows = fm.getAllFlows(new CallerId("caller id"), dataPathEndpoints);
397
398 // verify the test
399 verifyAll();
400 assertEquals(1, flows.size());
401 assertEquals(obtainedAllFlows.get(1), flows.get(0));
402 }
403
404 /**
405 * Test method for {@link FlowManager#getAllFlows(DataPathEndpoints)}.
406 * @throws Exception
407 */
408 @Test
409 public final void testGetAllFlowsWithDataPathEndpointsSuccessNormally() throws Exception {
410 final String getAllFlows = "getAllFlows";
411 // create mock objects
412 FlowManager fm = createPartialMock(FlowManager.class, getAllFlows,
413 new Class<?>[]{}, new Object[]{});
414
415 // instantiate required objects
416 DataPathEndpoints dataPathEndpoints = new DataPathEndpoints(
417 new SwitchPort(new Dpid(1), new Port((short)1)),
418 new SwitchPort(new Dpid(2), new Port((short)2)));
419
420 ArrayList<FlowPath> obtainedAllFlows = createTestFlowPaths();
421
422 //setup expectations
423 expectInitWithContext();
424 expectPrivate(fm, getAllFlows).andReturn(obtainedAllFlows);
425
426 //start the test
427 replayAll();
428
429 fm.init(context);
430 ArrayList<FlowPath> flows = fm.getAllFlows(dataPathEndpoints);
431
432 // verify the test
433 verifyAll();
434 assertEquals(2, flows.size());
435 assertEquals(obtainedAllFlows.get(0), flows.get(0));
436 assertEquals(obtainedAllFlows.get(1), flows.get(1));
437 // TODO: ignore the order of flows in the list
438 }
439
440 /**
441 * Test method for {@link FlowManager#getAllFlowsSummary(FlowId, int)}.
442 * @throws Exception
443 */
444 @Test
445 public final void testGetAllFlowsSummarySuccessNormally() throws Exception {
446 final String getAllFlowsWithoutFlowEntries = "getAllFlowsWithoutFlowEntries";
447 // create mock objects
448 FlowManager fm = createPartialMockAndInvokeDefaultConstructor(FlowManager.class, getAllFlowsWithoutFlowEntries);
Pavlin Radoslavov204b2862013-07-12 14:15:36 -0700449 IFlowPath flowPath1 = createIFlowPathMock(1, "", 0, 1, 2, 3, 4);
450 IFlowPath flowPath2 = createIFlowPathMock(5, "", 0, 2, 3, 4, 5);
451 IFlowPath flowPath3 = createIFlowPathMock(10, "", 0, 3, 4, 5, 6);
Toshio Koidefe2625e2013-06-26 13:59:53 -0700452
453 // instantiate required objects
454 ArrayList<IFlowPath> flows = new ArrayList<IFlowPath>();
455 flows.add(flowPath3);
456 flows.add(flowPath1);
457 flows.add(flowPath2);
458
459 // setup expectations
460 expectInitWithContext();
461 expectPrivate(fm, getAllFlowsWithoutFlowEntries).andReturn(flows);
462
463 // start the test
464 replayAll();
465
466 fm.init(context);
467 ArrayList<IFlowPath> returnedFlows = fm.getAllFlowsSummary(null, 0);
468
469 // verify the test
470 verifyAll();
471 assertEquals(3, returnedFlows.size());
472 assertEquals(1, new FlowId(returnedFlows.get(0).getFlowId()).value());
473 assertEquals(5, new FlowId(returnedFlows.get(1).getFlowId()).value());
474 assertEquals(10, new FlowId(returnedFlows.get(2).getFlowId()).value());
475 }
476
477 /**
478 * Test method for {@link FlowManager#getAllFlows()}.
479 * @throws Exception
480 */
481 @Test
482 public final void testGetAllFlowsSuccessNormally() throws Exception {
Toshio Koideca7abe02013-06-27 17:30:17 -0700483 // create mock objects
Pavlin Radoslavov204b2862013-07-12 14:15:36 -0700484 IFlowPath iFlowPath1 = createIFlowPathMock(1, "caller id", 0, 1, 1, 2, 2);
485 IFlowPath iFlowPath2 = createIFlowPathMock(2, "caller id", 0, 2, 5, 3, 5);
Toshio Koideca7abe02013-06-27 17:30:17 -0700486
Toshio Koidefe2625e2013-06-26 13:59:53 -0700487 // instantiate required objects
488 ArrayList<IFlowPath> flowPaths = new ArrayList<IFlowPath>();
Toshio Koideca7abe02013-06-27 17:30:17 -0700489 flowPaths.add(iFlowPath1);
490 flowPaths.add(iFlowPath2);
Toshio Koidefe2625e2013-06-26 13:59:53 -0700491 FlowManager fm = new FlowManager();
492
493 // setup expectations
494 expectInitWithContext();
495 expect(op.getAllFlowPaths()).andReturn(flowPaths);
Toshio Koideca7abe02013-06-27 17:30:17 -0700496 expect(iFlowPath1.getFlowEntries()).andReturn(new ArrayList<IFlowEntry>()).anyTimes();
497 expect(iFlowPath2.getFlowEntries()).andReturn(new ArrayList<IFlowEntry>()).anyTimes();
Toshio Koidefe2625e2013-06-26 13:59:53 -0700498 op.commit();
499
500 // start the test
501 replayAll();
502
503 fm.init(context);
504 ArrayList<FlowPath> flows = fm.getAllFlows();
505
506 // verify the test
507 verifyAll();
508 assertEquals(2, flows.size());
509 assertEquals(new SwitchPort(new Dpid(1), new Port((short)1)).toString(),
510 flows.get(0).dataPath().srcPort().toString());
511 assertEquals(new SwitchPort(new Dpid(2), new Port((short)5)).toString(),
512 flows.get(1).dataPath().srcPort().toString());
513 // TODO: more asserts
514 // TODO: ignore seq. of the list
515 }
516
517 /**
518 * Test method for {@link FlowManager#addAndMaintainShortestPathFlow(FlowPath)}.
519 * @throws Exception
520 */
521 @Test
522 public final void testAddAndMaintainShortestPathFlowSuccessNormally() throws Exception {
523 final String addFlow = "addFlow";
524
525 // create mock objects
526 FlowManager fm = createPartialMockAndInvokeDefaultConstructor(FlowManager.class, addFlow);
527
528 // instantiate required objects
529 DataPath dataPath = new DataPath();
530 dataPath.setSrcPort(new SwitchPort(new Dpid(1), new Port((short)3)));
531 dataPath.setDstPort(new SwitchPort(new Dpid(2), new Port((short)4)));
532 FlowEntryMatch match = new FlowEntryMatch();
533 FlowPath paramFlow = new FlowPath();
534 paramFlow.setFlowId(new FlowId(100));
535 paramFlow.setInstallerId(new CallerId("installer id"));
Pavlin Radoslavov204b2862013-07-12 14:15:36 -0700536 paramFlow.setFlowPathFlags(new FlowPathFlags(0));
Toshio Koidefe2625e2013-06-26 13:59:53 -0700537 paramFlow.setDataPath(dataPath);
538 paramFlow.setFlowEntryMatch(match);
539
540 // setup expectations
541 expectInitWithContext();
542 expectPrivate(fm, addFlow,
543 EasyMock.anyObject(FlowPath.class),
544 EasyMock.anyObject(FlowId.class),
545 EasyMock.anyObject(String.class)
546 ).andAnswer(new IAnswer<Object>() {
547 public Object answer() throws Exception {
548 FlowPath flowPath = (FlowPath)EasyMock.getCurrentArguments()[0];
549 assertEquals(flowPath.flowId().value(), 100);
550 assertEquals(flowPath.installerId().toString(), "installer id");
Pavlin Radoslavov204b2862013-07-12 14:15:36 -0700551 assertEquals(flowPath.flowPathFlags().flags(), 0);
Toshio Koidefe2625e2013-06-26 13:59:53 -0700552 assertEquals(flowPath.dataPath().srcPort().toString(),
553 new SwitchPort(new Dpid(1), new Port((short)3)).toString());
554
555 String dataPathSummary = (String)EasyMock.getCurrentArguments()[2];
556 assertEquals(dataPathSummary, "X");
557
558 return true;
559 }
560 });
561
562 // start the test
563 replayAll();
564
565 fm.init(context);
566 FlowPath resultFlow = fm.addAndMaintainShortestPathFlow(paramFlow);
567
568 // verify the test
569 verifyAll();
570 assertEquals(paramFlow.flowId().value(), resultFlow.flowId().value());
571 assertEquals(paramFlow.installerId().toString(), resultFlow.installerId().toString());
Pavlin Radoslavov204b2862013-07-12 14:15:36 -0700572 assertEquals(paramFlow.flowPathFlags().flags(), resultFlow.flowPathFlags().flags());
Toshio Koidefe2625e2013-06-26 13:59:53 -0700573 assertEquals(paramFlow.dataPath().toString(), resultFlow.dataPath().toString());
574 assertEquals(paramFlow.flowEntryMatch().toString(), resultFlow.flowEntryMatch().toString());
575 }
576
577 /**
578 * Test method for {@link FlowManager#measurementStorePathFlow(FlowPath)}.
579 * @throws Exception
580 */
581 @Test
582 public final void testMeasurementStorePathFlowSuccessNormally() throws Exception {
583 // instantiate required objects
Pavlin Radoslavov204b2862013-07-12 14:15:36 -0700584 FlowPath paramFlow = createTestFlowPath(100, "installer id", 0, 1, 3, 2, 4);
Toshio Koidefe2625e2013-06-26 13:59:53 -0700585 Map<Long, Object> shortestPathMap = new HashMap<Long, Object>();
586 FlowManager fm = new FlowManager();
587
588 // setup expectations
589 expectInitWithContext();
590 expect((Map<Long,Object>)topoRouteService.prepareShortestPathTopo()
591 ).andReturn(shortestPathMap);
592 expect(topoRouteService.getTopoShortestPath(
593 shortestPathMap,
594 paramFlow.dataPath().srcPort(),
595 paramFlow.dataPath().dstPort())).andReturn(null);
596
597 // start the test
598 replayAll();
599
600 fm.init(context);
601 FlowPath resultFlowPath = fm.measurementStorePathFlow(paramFlow);
602
603 // verify the test
604 verifyAll();
605 assertEquals(paramFlow.flowId().value(), resultFlowPath.flowId().value());
606 assertEquals(paramFlow.installerId().toString(), resultFlowPath.installerId().toString());
Pavlin Radoslavov204b2862013-07-12 14:15:36 -0700607 assertEquals(paramFlow.flowPathFlags().flags(), resultFlowPath.flowPathFlags().flags());
Toshio Koidefe2625e2013-06-26 13:59:53 -0700608 assertEquals(paramFlow.dataPath().toString(), resultFlowPath.dataPath().toString());
609 assertEquals(paramFlow.flowEntryMatch().toString(), resultFlowPath.flowEntryMatch().toString());
610 }
611
612 /**
613 * Test method for {@link FlowManager#measurementInstallPaths(Integer)}.
614 * @throws Exception
615 */
616 @Test
617 public final void testMeasurementInstallPathsSuccessNormally() throws Exception {
618 final String addFlow = "addFlow";
619
620 // create mock objects
621 FlowManager fm = createPartialMockAndInvokeDefaultConstructor(FlowManager.class, addFlow);
622
623 // instantiate required objects
Pavlin Radoslavov204b2862013-07-12 14:15:36 -0700624 FlowPath flow1 = createTestFlowPath(1, "installer id", 0, 1, 2, 3, 4);
625 FlowPath flow2 = createTestFlowPath(2, "installer id", 0, 2, 3, 4, 5);
626 FlowPath flow3 = createTestFlowPath(3, "installer id", 0, 3, 4, 5, 6);
Toshio Koidefe2625e2013-06-26 13:59:53 -0700627 Map<Long, Object> shortestPathMap = new HashMap<Long, Object>();
628
629 // setup expectations
630 expectInitWithContext();
631 expect((Map<Long,Object>)topoRouteService.prepareShortestPathTopo()
632 ).andReturn(shortestPathMap);
633
634 expect(topoRouteService.getTopoShortestPath(
635 shortestPathMap,
636 flow1.dataPath().srcPort(),
637 flow1.dataPath().dstPort())).andReturn(null);
638
639 expect(topoRouteService.getTopoShortestPath(
640 shortestPathMap,
641 flow2.dataPath().srcPort(),
642 flow2.dataPath().dstPort())).andReturn(null);
643
644 expect(topoRouteService.getTopoShortestPath(
645 shortestPathMap,
646 flow3.dataPath().srcPort(),
647 flow3.dataPath().dstPort())).andReturn(null);
648
649 expectPrivate(fm, addFlow,
650 EasyMock.cmpEq(flow1),
651 EasyMock.anyObject(FlowId.class),
652 EasyMock.anyObject(String.class)).andReturn(true);
653
654 expectPrivate(fm, addFlow,
655 EasyMock.cmpEq(flow2),
656 EasyMock.anyObject(FlowId.class),
657 EasyMock.anyObject(String.class)).andReturn(true);
658
659 expectPrivate(fm, addFlow,
660 EasyMock.cmpEq(flow3),
661 EasyMock.anyObject(FlowId.class),
662 EasyMock.anyObject(String.class)).andReturn(true);
663
664 // start the test
665 replayAll();
666
667 fm.init(context);
668 fm.measurementStorePathFlow(flow1);
669 fm.measurementStorePathFlow(flow2);
670 fm.measurementStorePathFlow(flow3);
671 Boolean result = fm.measurementInstallPaths(3);
672
673 // verify the test
674 verifyAll();
675 assertTrue(result);
676 }
677
678 /**
679 * Test method for {@link FlowManager#measurementGetInstallPathsTimeNsec()}.
680 * @throws Exception
681 */
682 @Test
683 public final void testMeasurementGetInstallPathsTimeNsecSuccessNormally() throws Exception {
684 final String addFlow = "addFlow";
685
686 // create mock objects
687 FlowManager fm = createPartialMockAndInvokeDefaultConstructor(FlowManager.class, addFlow);
688 mockStaticPartial(System.class, "nanoTime");
689
690 // instantiate required objects
Pavlin Radoslavov204b2862013-07-12 14:15:36 -0700691 FlowPath flow1 = createTestFlowPath(1, "installer id", 0, 1, 2, 3, 4);
Toshio Koidefe2625e2013-06-26 13:59:53 -0700692 Map<Long, Object> shortestPathMap = new HashMap<Long, Object>();
693
694 // setup expectations
695 expectInitWithContext();
696 expect(System.nanoTime()).andReturn(new Long(100000));
697 expect(System.nanoTime()).andReturn(new Long(110000));
698 expect((Map<Long,Object>)topoRouteService.prepareShortestPathTopo()
699 ).andReturn(shortestPathMap);
700 expect(topoRouteService.getTopoShortestPath(
701 shortestPathMap,
702 flow1.dataPath().srcPort(),
703 flow1.dataPath().dstPort())).andReturn(null);
704 expectPrivate(fm, addFlow,
705 EasyMock.cmpEq(flow1),
706 EasyMock.anyObject(FlowId.class),
707 EasyMock.anyObject(String.class)).andReturn(true);
708
709 // start the test
710 replayAll();
711
712 fm.init(context);
713 fm.measurementStorePathFlow(flow1).toString();
714 fm.measurementInstallPaths(1);
715 Long result = fm.measurementGetInstallPathsTimeNsec();
716
717 // verify the test
718 verifyAll();
719 assertEquals(new Long(10000), result);
720 }
721
722 /**
723 * Test method for {@link FlowManager#measurementGetPerFlowInstallTime()}.
724 * @throws Exception
725 */
726 @Test
727 public final void testMeasurementGetPerFlowInstallTimeSuccessNormally() throws Exception {
728 final String addFlow = "addFlow";
729
730 // create mock objects
731 FlowManager fm = createPartialMockAndInvokeDefaultConstructor(FlowManager.class, addFlow);
732
733 // instantiate required objects
Pavlin Radoslavov204b2862013-07-12 14:15:36 -0700734 FlowPath flow1 = createTestFlowPath(1, "installer id", 0, 1, 2, 3, 4);
Toshio Koidefe2625e2013-06-26 13:59:53 -0700735 Map<Long, Object> shortestPathMap = new HashMap<Long, Object>();
736
737 // setup expectations
738 expectInitWithContext();
739 expect((Map<Long,Object>)topoRouteService.prepareShortestPathTopo()
740 ).andReturn(shortestPathMap);
741
742 expect(topoRouteService.getTopoShortestPath(
743 shortestPathMap,
744 flow1.dataPath().srcPort(),
745 flow1.dataPath().dstPort())).andReturn(null);
746
747 expectPrivate(fm, addFlow,
748 EasyMock.cmpEq(flow1),
749 EasyMock.anyObject(FlowId.class),
750 EasyMock.anyObject(String.class)).andReturn(true);
751
752
753 // start the test
754 replayAll();
755
756 fm.init(context);
757 fm.measurementStorePathFlow(flow1);
758 fm.measurementInstallPaths(10);
759 String result = fm.measurementGetPerFlowInstallTime();
760
761 // verify the test
762 verifyAll();
763 assertTrue(result.startsWith("ThreadAndTimePerFlow"));
764 }
765
766 /**
767 * Test method for {@link FlowManager#measurementClearAllPaths()}.
768 * @throws Exception
769 */
770 @Test
771 public final void testMeasurementClearAllPathsSuccessNormally() throws Exception {
772 // instantiate required objects
Pavlin Radoslavov204b2862013-07-12 14:15:36 -0700773 FlowPath paramFlow = createTestFlowPath(100, "installer id", 0, 1, 3, 2, 4);
Toshio Koidefe2625e2013-06-26 13:59:53 -0700774 Map<Long, Object> shortestPathMap = new HashMap<Long, Object>();
Toshio Koideca7abe02013-06-27 17:30:17 -0700775 FlowManager fm = new FlowManager();
Toshio Koidefe2625e2013-06-26 13:59:53 -0700776
777 // setup expectations
778 expectInitWithContext();
779 expect((Map<Long,Object>)topoRouteService.prepareShortestPathTopo()
780 ).andReturn(shortestPathMap);
781 expect(topoRouteService.getTopoShortestPath(
782 shortestPathMap,
783 paramFlow.dataPath().srcPort(),
784 paramFlow.dataPath().dstPort())).andReturn(null);
785 topoRouteService.dropShortestPathTopo(shortestPathMap);
786
787 // start the test
788 replayAll();
789
Toshio Koidefe2625e2013-06-26 13:59:53 -0700790 fm.init(context);
791 fm.measurementStorePathFlow(paramFlow);
792 Boolean result = fm.measurementClearAllPaths();
793
794 // verify the test
795 verifyAll();
796 assertTrue(result);
797 assertEquals(new Long(0), fm.measurementGetInstallPathsTimeNsec());
798 assertEquals("", fm.measurementGetPerFlowInstallTime());
799 }
800
801
802 // INetMapStorage methods
803
804
805 /**
806 * Test method for {@link FlowManager#init(String)}.
807 * @throws Exception
808 */
809 @Test
810 public final void testInitSuccessNormally() throws Exception {
Toshio Koideca7abe02013-06-27 17:30:17 -0700811 // instantiate required objects
812 FlowManager fm = new FlowManager();
813
Toshio Koidefe2625e2013-06-26 13:59:53 -0700814 // create mock objects
815 op = createMock(GraphDBOperation.class);
816
817 // setup expectations
818 expectNew(GraphDBOperation.class, "/dummy/path").andReturn(op);
819
820 // start the test
821 replayAll();
822
Toshio Koidefe2625e2013-06-26 13:59:53 -0700823 fm.init("/dummy/path");
824
825 // verify the test
826 verifyAll();
827 }
828
829 /**
830 * Test method for {@link FlowManager#close()}.
831 * @throws Exception
832 */
833 @Test
834 public final void testCloseSuccessNormally() throws Exception {
835 // instantiate required objects
836 FlowManager fm = new FlowManager();
837
838 // setup expectations
839 expectInitWithContext();
840 op.close();
841
842 // start the test
843 replayAll();
844
845 fm.init(context);
846 fm.close();
847
848 // verify the test
849 verifyAll();
850 }
851
852
853 // IFloodlightModule methods
854
855
856 /**
857 * Test method for {@link FlowManager#getModuleServices()}.
858 * @throws Exception
859 */
860 @Test
861 public final void testGetModuleServicesSuccessNormally() throws Exception {
862 // instantiate required objects
863 FlowManager fm = new FlowManager();
864
865 // setup expectations
866 expectInitWithContext();
867
868 // start the test
869 replayAll();
870
871 fm.init(context);
872 Collection<Class<? extends IFloodlightService>> l = fm.getModuleServices();
873
874 // verify the test
875 verifyAll();
876 assertEquals(1, l.size());
877 assertEquals(IFlowService.class, l.iterator().next());
878 }
879
880 /**
881 * Test method for {@link FlowManager#getServiceImpls()}.
882 * @throws Exception
883 */
884 @Test
885 public final void testGetServiceImplsSuccessNormally() throws Exception {
886 // instantiate required objects
887 FlowManager fm = new FlowManager();
888
889 // setup expectations
890 expectInitWithContext();
891
892 // start the test
893 replayAll();
894
895 fm.init(context);
896 Map<Class<? extends IFloodlightService>, IFloodlightService> si = fm.getServiceImpls();
897
898 // verify the test
899 verifyAll();
900 assertEquals(1, si.size());
901 assertTrue(si.containsKey(IFlowService.class));
902 assertEquals(fm, si.get(IFlowService.class));
903 }
904
905 /**
906 * Test method for {@link FlowManager#getModuleDependencies()}.
907 * @throws Exception
908 */
909 @Test
910 public final void testGetModuleDependenciesSuccessNormally() throws Exception {
911 // instantiate required objects
912 FlowManager fm = new FlowManager();
913
914 // setup expectations
915 expectInitWithContext();
916
917 // start the test
918 replayAll();
919
920 fm.init(context);
921 Collection<Class<? extends IFloodlightService>> md = fm.getModuleDependencies();
922
923 // verify the test
924 verifyAll();
Pavlin Radoslavovddd01ba2013-07-03 15:40:44 -0700925 assertEquals(2, md.size());
Toshio Koidefe2625e2013-06-26 13:59:53 -0700926 assertTrue(md.contains(IFloodlightProviderService.class));
Toshio Koidefe2625e2013-06-26 13:59:53 -0700927 assertTrue(md.contains(IRestApiService.class));
928 }
929
930 /**
931 * Test method for {@link FlowManager#init(FloodlightModuleContext)}.
932 * @throws Exception
933 */
934 @Test
935 public final void testInitWithFloodlightModuleContextSuccessNormally() throws Exception {
936 // instantiate required objects
937 FlowManager fm = new FlowManager();
938
939 // setup expectations
940 expectInitWithContext();
941
942 // start the test
943 replayAll();
944
945 fm.init(context);
946
947 // verify the test
948 verifyAll();
949 }
950
951 /**
952 * Test method for {@link FlowManager#startUp(FloodlightModuleContext)}.
953 * @throws Exception
954 */
955 @Test
956 public final void testStartupSuccessNormally() throws Exception {
957 // create mock objects
958 mockStaticPartial(Executors.class, "newScheduledThreadPool");
959 ScheduledExecutorService scheduler = createMock(ScheduledExecutorService.class);
960
Toshio Koidefe2625e2013-06-26 13:59:53 -0700961 // instantiate required objects
962 FlowManager fm = new FlowManager();
963
964 // setup expectations
965 expectInitWithContext();
966 expect(Executors.newScheduledThreadPool(1)).andReturn(scheduler);
967 expect(Executors.newScheduledThreadPool(1)).andReturn(scheduler);
968 expect(scheduler.scheduleAtFixedRate(
969 EasyMock.anyObject(Runnable.class),
970 EasyMock.anyLong(),
971 EasyMock.anyLong(),
972 EasyMock.anyObject(TimeUnit.class))).andReturn(null).times(2);
973 restApi.addRestletRoutable(EasyMock.anyObject(FlowWebRoutable.class));
974
975 // start the test
976 replayAll();
977
978 fm.init(context);
979 fm.startUp(context);
980
981 // verify the test
982 verifyAll();
983 }
Toshio Koideca7abe02013-06-27 17:30:17 -0700984
985
986 // other methods
987
988
989 /**
990 * Test method for {@link FlowManager#clearFlow(FlowId)}.
991 * @throws Exception
992 */
993 @Test
994 public final void testClearFlowSuccessNormally() throws Exception {
995 // create mock objects
Pavlin Radoslavov204b2862013-07-12 14:15:36 -0700996 IFlowPath flowPath = createIFlowPathMock(123, "id", 0, 1, 2, 3, 4);
Toshio Koideca7abe02013-06-27 17:30:17 -0700997 IFlowEntry flowEntry1 = createMock(IFlowEntry.class);
998 IFlowEntry flowEntry2 = createMock(IFlowEntry.class);
999 IFlowEntry flowEntry3 = createMock(IFlowEntry.class);
1000
1001 // instantiate required objects
1002 FlowManager fm = new FlowManager();
1003 FlowId flowId = new FlowId(123);
1004 ArrayList<IFlowEntry> flowEntries = new ArrayList<IFlowEntry>();
1005 flowEntries.add(flowEntry1);
1006 flowEntries.add(flowEntry2);
1007 flowEntries.add(flowEntry3);
1008
1009 // setup expectations
1010 expectInitWithContext();
1011 expect(op.searchFlowPath(cmpEq(flowId))).andReturn(flowPath);
1012 expect(flowPath.getFlowEntries()).andReturn(flowEntries);
1013 flowPath.removeFlowEntry(flowEntry1);
1014 flowPath.removeFlowEntry(flowEntry2);
1015 flowPath.removeFlowEntry(flowEntry3);
1016 op.removeFlowEntry(flowEntry1);
1017 op.removeFlowEntry(flowEntry2);
1018 op.removeFlowEntry(flowEntry3);
1019 op.removeFlowPath(flowPath);
1020 op.commit();
1021
1022 // start the test
1023 replayAll();
1024
1025 fm.init(context);
1026 fm.clearFlow(flowId);
1027
1028 // verify the test
1029 verifyAll();
1030 }
1031
1032 /**
1033 * Test method for {@link FlowManager#getAllFlowsWithoutFlowEntries()}.
1034 * @throws Exception
1035 */
1036 @Test
1037 public final void testGetAllFlowsWithoutFlowEntriesSuccessNormally() throws Exception {
1038 // create mock objects
Pavlin Radoslavov204b2862013-07-12 14:15:36 -07001039 IFlowPath iFlowPath1 = createIFlowPathMock(1, "caller id", 0, 1, 1, 2, 2);
1040 IFlowPath iFlowPath2 = createIFlowPathMock(2, "caller id", 0, 2, 5, 3, 5);
Toshio Koideca7abe02013-06-27 17:30:17 -07001041
1042 // instantiate required objects
1043 ArrayList<IFlowPath> flowPaths = new ArrayList<IFlowPath>();
1044 flowPaths.add(iFlowPath1);
1045 flowPaths.add(iFlowPath2);
1046 FlowManager fm = new FlowManager();
1047
1048 // setup expectations
1049 expectInitWithContext();
1050 op.commit();
1051 expect(op.getAllFlowPaths()).andReturn(flowPaths);
1052
1053 // start the test
1054 replayAll();
1055
1056 fm.init(context);
1057 ArrayList<IFlowPath> result = fm.getAllFlowsWithoutFlowEntries();
1058
1059 // verify the test
1060 verifyAll();
1061 assertEquals(iFlowPath1, result.get(0));
1062 assertEquals(iFlowPath2, result.get(1));
1063
1064 // TODO: does this method just return the replica of the flow paths?
1065 }
1066
1067 /**
1068 * Test method for {@link FlowManager#reconcileFlow(IFlowPath, DataPath)}.
1069 * @throws Exception
1070 */
1071 @Test
1072 public final void testReconcileFlowWithFlowPathAndDataPathSuccessNormally() throws Exception {
1073 final String addFlowEntry = "addFlowEntry";
1074
1075 // create mock objects
Pavlin Radoslavov204b2862013-07-12 14:15:36 -07001076 IFlowPath iFlowPath1 = createIFlowPathMock(1, "caller id", 0, 1, 1, 2, 2);
Toshio Koideca7abe02013-06-27 17:30:17 -07001077 IFlowEntry iFlowEntry1 = createMock(IFlowEntry.class);
1078 IFlowEntry iFlowEntry2 = createMock(IFlowEntry.class);
1079 FlowManager fm = createPartialMockAndInvokeDefaultConstructor(FlowManager.class, addFlowEntry);
1080
1081 // instantiate required objects
1082 FlowEntry flowEntry1 = new FlowEntry();
1083 flowEntry1.setDpid(new Dpid(1));
1084 flowEntry1.setFlowId(new FlowId(1));
1085 flowEntry1.setInPort(new Port((short) 1));
1086 flowEntry1.setOutPort(new Port((short) 11));
1087 flowEntry1.setFlowEntryId(new FlowEntryId(1));
1088 flowEntry1.setFlowEntryMatch(new FlowEntryMatch());
1089 flowEntry1.setFlowEntryActions(new ArrayList<FlowEntryAction>());
1090 flowEntry1.setFlowEntryErrorState(new FlowEntryErrorState());
1091
1092 FlowEntry flowEntry2 = new FlowEntry();
1093 flowEntry2.setDpid(new Dpid(2));
1094 flowEntry2.setFlowId(new FlowId(2));
1095 flowEntry2.setInPort(new Port((short) 22));
1096 flowEntry2.setOutPort(new Port((short) 2));
1097 flowEntry2.setFlowEntryId(new FlowEntryId(2));
1098 flowEntry2.setFlowEntryMatch(new FlowEntryMatch());
1099 flowEntry2.setFlowEntryActions(new ArrayList<FlowEntryAction>());
1100 flowEntry2.setFlowEntryErrorState(new FlowEntryErrorState());
1101
1102 DataPath dataPath = new DataPath();
1103 ArrayList<FlowEntry> flowEntries = new ArrayList<FlowEntry>();
1104 flowEntries.add(flowEntry1);
1105 flowEntries.add(flowEntry2);
1106 dataPath.setFlowEntries(flowEntries);
1107
1108 ArrayList<IFlowEntry> oldFlowEntries = new ArrayList<IFlowEntry>();
1109 oldFlowEntries.add(iFlowEntry1);
1110 oldFlowEntries.add(iFlowEntry2);
1111
1112 // setup expectations
1113 expectInitWithContext();
1114 expect(floodlightProvider.getSwitches()).andReturn(null); // TODO: why is this needed?
1115 expect(iFlowPath1.getFlowEntries()).andReturn(oldFlowEntries);
1116 iFlowEntry1.setUserState("FE_USER_DELETE");
1117 iFlowEntry1.setSwitchState("FE_SWITCH_NOT_UPDATED");
1118 iFlowEntry2.setUserState("FE_USER_DELETE");
1119 iFlowEntry2.setSwitchState("FE_SWITCH_NOT_UPDATED");
1120 expectPrivate(fm, addFlowEntry, iFlowPath1, flowEntry1).andReturn(null);
1121 expectPrivate(fm, addFlowEntry, iFlowPath1, flowEntry2).andReturn(null);
1122
1123 // start the test
1124 replayAll();
1125
1126 fm.init(context);
1127 Boolean result = fm.reconcileFlow(iFlowPath1, dataPath);
1128
1129 // verify the test
1130 verifyAll();
1131 assertTrue(result);
1132 // TODO: write more asserts
1133 }
1134
1135 /**
1136 * Test method for {@link FlowManager#installFlowEntry(net.floodlightcontroller.core.IOFSwitch, IFlowPath, IFlowEntry)}.
1137 * @throws Exception
1138 */
1139 @Test
1140 public final void testInstallFlowEntryWithIFlowPathSuccessNormally() throws Exception {
1141 // create mock object
1142 IOFSwitch iofSwitch = createNiceMock(IOFSwitch.class);
Pavlin Radoslavov204b2862013-07-12 14:15:36 -07001143 IFlowPath iFlowPath = createIFlowPathMock(1, "id", 0, 1, 2, 3, 4);
Toshio Koideca7abe02013-06-27 17:30:17 -07001144 IFlowEntry iFlowEntry = createMock(IFlowEntry.class);
1145 BasicFactory basicFactory = createMock(BasicFactory.class);
1146
1147 // instantiate required objects
1148 FlowManager fm = new FlowManager();
1149
1150 // setup expectations
1151 expectInitWithContext();
1152 expect(iFlowEntry.getFlowEntryId()).andReturn(new FlowEntryId(123).toString());
1153 expect(iFlowEntry.getUserState()).andReturn("FE_USER_ADD");
1154 iFlowEntry.setSwitchState("FE_SWITCH_UPDATED");
1155 expect(iFlowEntry.getMatchInPort()).andReturn(new Short((short) 1));
Toshio Koideca7abe02013-06-27 17:30:17 -07001156 expect(iFlowEntry.getMatchSrcMac()).andReturn("01:23:45:67:89:01");
1157 expect(iFlowEntry.getMatchDstMac()).andReturn("01:23:45:67:89:02");
Pavlin Radoslavovad3a1e62013-07-09 13:30:16 -07001158 expect(iFlowEntry.getMatchEthernetFrameType()).andReturn(new Short((short)0x0800));
1159 expect(iFlowEntry.getMatchVlanId()).andReturn(new Short((short)0x1234));
1160 expect(iFlowEntry.getMatchVlanPriority()).andReturn(new Byte((byte)0x10));
1161 expect(iFlowEntry.getMatchSrcIPv4Net()).andReturn("192.168.0.1");
1162 expect(iFlowEntry.getMatchDstIPv4Net()).andReturn("192.168.0.2");
1163 expect(iFlowEntry.getMatchIpProto()).andReturn(new Byte((byte)0x20));
1164 expect(iFlowEntry.getMatchIpToS()).andReturn(new Byte((byte)0x3));
1165 expect(iFlowEntry.getMatchSrcTcpUdpPort()).andReturn(new Short((short)40000));
1166 expect(iFlowEntry.getMatchDstTcpUdpPort()).andReturn(new Short((short)80));
Toshio Koideca7abe02013-06-27 17:30:17 -07001167 expect(iFlowEntry.getActionOutput()).andReturn(new Short((short) 2));
1168 expect(floodlightProvider.getOFMessageFactory()).andReturn(basicFactory);
1169 expect(basicFactory.getMessage(OFType.FLOW_MOD)).andReturn(new OFFlowMod());
1170 expect(iofSwitch.getStringId()).andReturn(new Dpid(100).toString());
1171
1172 // start the test
1173 replayAll();
1174
1175 fm.init(context);
1176 Boolean result = fm.installFlowEntry(iofSwitch, iFlowPath, iFlowEntry);
1177
1178 // verify the test
1179 verifyAll();
1180 assertTrue(result);
1181 // TODO: write more asserts
1182 }
1183
1184 /**
1185 * Test method for {@link FlowManager#installFlowEntry(net.floodlightcontroller.core.IOFSwitch, FlowPath, FlowEntry)}.
1186 * The method seems to be not used for now.
1187 */
1188 @Ignore @Test
1189 public final void testInstallFlowEntryWithFlowPathSuccessNormally() {
1190 fail("not yet implemented");
1191 }
1192
1193 /**
1194 * Test method for {@link FlowManager#removeFlowEntry(net.floodlightcontroller.core.IOFSwitch, FlowPath, FlowEntry)}.
1195 * The method seems to be not implemented and not used for now.
1196 */
1197 @Ignore @Test
1198 public final void testRemoveFlowEntrySuccessNormally() {
1199 fail("not yet implemented");
1200 }
1201
1202 /**
1203 * Test method for {@link FlowManager#installRemoteFlowEntry(FlowPath, FlowEntry)}.
1204 * The method seems to be not implemented and not used for now.
1205 */
1206 @Ignore @Test
1207 public final void testInstallRemoteFlowEntrySuccessNormally() {
1208 fail("not yet implemented");
1209 }
1210
1211 /**
1212 * Test method for {@link FlowManager#removeRemoteFlowEntry(FlowPath, FlowEntry)}.
1213 * The method seems to be not implemented and not used for now.
1214 */
1215 @Ignore @Test
1216 public final void testRemoveRemoteFlowEntrySuccessNormally() {
1217 fail("not yet implemented");
1218 }
Pavlin Radoslavovddd01ba2013-07-03 15:40:44 -07001219}