blob: 8a727d3b9bc238c184f968cf815ad7c1f63dc298 [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
Pavlin Radoslavov1308dc62013-10-25 15:54:31 -07008import java.lang.reflect.Method;
Toshio Koidefe2625e2013-06-26 13:59:53 -07009import java.util.*;
10import java.util.concurrent.Executors;
11import java.util.concurrent.ScheduledExecutorService;
12import java.util.concurrent.TimeUnit;
13
14import net.floodlightcontroller.core.IFloodlightProviderService;
Toshio Koideca7abe02013-06-27 17:30:17 -070015import net.floodlightcontroller.core.IOFSwitch;
Toshio Koidefe2625e2013-06-26 13:59:53 -070016import net.floodlightcontroller.core.module.FloodlightModuleContext;
17import net.floodlightcontroller.core.module.IFloodlightService;
18import net.floodlightcontroller.restserver.IRestApiService;
Pavlin Radoslavov661c86f2013-10-21 12:40:40 -070019import net.onrc.onos.datagrid.IDatagridService;
Toshio Koidefe2625e2013-06-26 13:59:53 -070020import net.onrc.onos.graph.GraphDBOperation;
21import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IFlowEntry;
22import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IFlowPath;
Toshio Koidefe2625e2013-06-26 13:59:53 -070023import net.onrc.onos.ofcontroller.flowmanager.web.FlowWebRoutable;
Pavlin Radoslavov661c86f2013-10-21 12:40:40 -070024import net.onrc.onos.ofcontroller.topology.ITopologyNetService;
Pavlin Radoslavove1b37bc2013-10-16 03:57:06 -070025import net.onrc.onos.ofcontroller.topology.TopologyManager;
Toshio Koidefe2625e2013-06-26 13:59:53 -070026import net.onrc.onos.ofcontroller.util.*;
27
28import org.easymock.EasyMock;
29import org.easymock.IAnswer;
30import org.junit.After;
31import org.junit.Before;
Toshio Koideca7abe02013-06-27 17:30:17 -070032import org.junit.Ignore;
Toshio Koidefe2625e2013-06-26 13:59:53 -070033import org.junit.Test;
34import org.junit.runner.RunWith;
Toshio Koideca7abe02013-06-27 17:30:17 -070035import org.openflow.protocol.OFFlowMod;
36import org.openflow.protocol.OFType;
37import org.openflow.protocol.factory.BasicFactory;
Toshio Koidefe2625e2013-06-26 13:59:53 -070038import org.powermock.core.classloader.annotations.PrepareForTest;
39import org.powermock.modules.junit4.PowerMockRunner;
40
41/**
42 * @author Toshio Koide
43 */
Pavlin Radoslavov661c86f2013-10-21 12:40:40 -070044@Ignore
Toshio Koidefe2625e2013-06-26 13:59:53 -070045@RunWith(PowerMockRunner.class)
Pavlin Radoslavov661c86f2013-10-21 12:40:40 -070046@PrepareForTest({FlowManager.class, FlowDatabaseOperation.class, GraphDBOperation.class, System.class, Executors.class})
Toshio Koidefe2625e2013-06-26 13:59:53 -070047public class FlowManagerTest {
48 private static FloodlightModuleContext context;
49 private static IFloodlightProviderService floodlightProvider;
Pavlin Radoslavove1b37bc2013-10-16 03:57:06 -070050 private static TopologyManager topologyManager;
Pavlin Radoslavov661c86f2013-10-21 12:40:40 -070051 private static IDatagridService datagridService;
Toshio Koidefe2625e2013-06-26 13:59:53 -070052 private static IRestApiService restApi;
53 private static GraphDBOperation op;
54
55 /**
56 * @throws java.lang.Exception
57 */
58 @Before
59 public void setUp() throws Exception {
60 }
61
62 /**
63 * @throws java.lang.Exception
64 */
65 @After
66 public void tearDown() throws Exception {
67 }
68
69 /**
70 * @throws java.lang.Exception
71 */
72 private void expectInitWithContext() throws Exception {
73 // create mock objects
74 context = createMock(FloodlightModuleContext.class);
75 floodlightProvider = createMock(IFloodlightProviderService.class);
Pavlin Radoslavove1b37bc2013-10-16 03:57:06 -070076 topologyManager = createMock(TopologyManager.class);
Pavlin Radoslavov661c86f2013-10-21 12:40:40 -070077 datagridService = createMock(IDatagridService.class);
Toshio Koidefe2625e2013-06-26 13:59:53 -070078 restApi = createMock(IRestApiService.class);
79 op = createMock(GraphDBOperation.class);
80
81 // setup expectations
82 expect(context.getServiceImpl(IFloodlightProviderService.class)).andReturn(floodlightProvider);
Pavlin Radoslavov661c86f2013-10-21 12:40:40 -070083 expect(context.getServiceImpl(ITopologyNetService.class)).andReturn(topologyManager);
84 expect(context.getServiceImpl(IDatagridService.class)).andReturn(datagridService);
Toshio Koidefe2625e2013-06-26 13:59:53 -070085 expect(context.getServiceImpl(IRestApiService.class)).andReturn(restApi);
86 expectNew(GraphDBOperation.class, new Class<?>[] {String.class}, EasyMock.isA(String.class)).andReturn(op);
Pavlin Radoslavove1b37bc2013-10-16 03:57:06 -070087 expectNew(TopologyManager.class, new Class<?>[] {String.class}, EasyMock.isA(String.class)).andReturn(topologyManager);
Toshio Koidefe2625e2013-06-26 13:59:53 -070088 }
89
90 private IFlowPath createIFlowPathMock(long flowId, String installerID,
Pavlin Radoslavov7d4a40e2013-10-27 23:39:40 -070091 String flowPathType, String flowPathUserState,
92 long flowPathFlags, long srcDpid, int srcPort,
93 long dstDpid, int dstPort) {
Toshio Koidefe2625e2013-06-26 13:59:53 -070094 IFlowPath iFlowPath = createNiceMock(IFlowPath.class);
95 expect(iFlowPath.getFlowId()).andReturn(new FlowId(flowId).toString()).anyTimes();
96 expect(iFlowPath.getInstallerId()).andReturn(installerID).anyTimes();
Pavlin Radoslavovd28cf7c2013-10-26 11:27:43 -070097 expect(iFlowPath.getFlowPathType()).andReturn(flowPathType).anyTimes();
Pavlin Radoslavov7d4a40e2013-10-27 23:39:40 -070098 expect(iFlowPath.getFlowPathUserState()).andReturn(flowPathUserState).anyTimes();
Pavlin Radoslavov204b2862013-07-12 14:15:36 -070099 expect(iFlowPath.getFlowPathFlags()).andReturn(new Long(flowPathFlags)).anyTimes();
Toshio Koidefe2625e2013-06-26 13:59:53 -0700100 expect(iFlowPath.getSrcSwitch()).andReturn(new Dpid(srcDpid).toString()).anyTimes();
101 expect(iFlowPath.getSrcPort()).andReturn(new Short((short)srcPort)).anyTimes();
102 expect(iFlowPath.getDstSwitch()).andReturn(new Dpid(dstDpid).toString()).anyTimes();
103 expect(iFlowPath.getDstPort()).andReturn(new Short((short)dstPort)).anyTimes();
Toshio Koidefe2625e2013-06-26 13:59:53 -0700104 return iFlowPath;
105 }
106
Toshio Koideca7abe02013-06-27 17:30:17 -0700107 private FlowPath createTestFlowPath(long flowId, String installerId,
Pavlin Radoslavov7d4a40e2013-10-27 23:39:40 -0700108 String flowPathType, String flowPathUserState,
109 final long flowPathFlags,
Toshio Koidefe2625e2013-06-26 13:59:53 -0700110 final long srcDpid, final int srcPort,
Pavlin Radoslavovd28cf7c2013-10-26 11:27:43 -0700111 final long dstDpid, final int dstPort
Toshio Koidefe2625e2013-06-26 13:59:53 -0700112 ) {
113 FlowPath flowPath = new FlowPath();
114 flowPath.setFlowId(new FlowId(flowId));
115 flowPath.setInstallerId(new CallerId(installerId));
Pavlin Radoslavovd28cf7c2013-10-26 11:27:43 -0700116 flowPath.setFlowPathType(FlowPathType.valueOf(flowPathType));
Pavlin Radoslavov7d4a40e2013-10-27 23:39:40 -0700117 flowPath.setFlowPathUserState(FlowPathUserState.valueOf(flowPathUserState));
Pavlin Radoslavov204b2862013-07-12 14:15:36 -0700118 flowPath.setFlowPathFlags(new FlowPathFlags(flowPathFlags));
Toshio Koidefe2625e2013-06-26 13:59:53 -0700119 flowPath.setDataPath(new DataPath() {{
120 setSrcPort(new SwitchPort(new Dpid(srcDpid), new Port((short)srcPort)));
121 setDstPort(new SwitchPort(new Dpid(dstDpid), new Port((short)dstPort)));
122 }});
123 flowPath.setFlowEntryMatch(new FlowEntryMatch());
124 return flowPath;
125 }
126
127 private ArrayList<FlowPath> createTestFlowPaths() {
Pavlin Radoslavov7d4a40e2013-10-27 23:39:40 -0700128 FlowPath flowPath1 = createTestFlowPath(1, "foo caller id", "FP_TYPE_SHORTEST_PATH", "FP_USER_ADD", 0, 1, 1, 2, 2);
129 FlowPath flowPath2 = createTestFlowPath(2, "caller id", "FP_TYPE_SHORTEST_PATH", "FP_USER_ADD", 0, 1, 1, 2, 2);
130 FlowPath flowPath3 = createTestFlowPath(3, "caller id", "FP_TYPE_SHORTEST_PATH", "FP_USER_ADD", 0, 1, 5, 2, 2);
Toshio Koidefe2625e2013-06-26 13:59:53 -0700131
132 ArrayList<FlowPath> flowPaths = new ArrayList<FlowPath>();
133 flowPaths.add(flowPath1);
134 flowPaths.add(flowPath2);
135 flowPaths.add(flowPath3);
136
137 return flowPaths;
138 }
139
140
141 // IFlowService methods
142
143
144 /**
145 * Test method for {@link FlowManager#addFlow(FlowPath, FlowId, String)}.
146 * @throws Exception
147 */
148 @Test
149 public final void testAddFlowFailGraphCreatesNoFlow() throws Exception {
150 // instantiate required objects
151 FlowId flowId = new FlowId(123);
152 FlowPath flowPath = new FlowPath();
153 flowPath.setFlowId(flowId);
Toshio Koideca7abe02013-06-27 17:30:17 -0700154 FlowManager fm = new FlowManager();
Toshio Koidefe2625e2013-06-26 13:59:53 -0700155
156 // setup expectations
157 expectInitWithContext();
158 expect(op.searchFlowPath(flowId)).andReturn(null);
159 expect(op.newFlowPath()).andReturn(null);
160 op.rollback();
161
162 // start the test
163 replayAll();
Toshio Koidefe2625e2013-06-26 13:59:53 -0700164
Toshio Koidefe2625e2013-06-26 13:59:53 -0700165 fm.init(context);
Pavlin Radoslavovbcc86ef2013-10-26 12:06:25 -0700166 Boolean result = fm.addFlow(flowPath, flowId);
Toshio Koidefe2625e2013-06-26 13:59:53 -0700167
168 // verify the test
169 verifyAll();
170 assertFalse(result);
171 }
172
173 /**
Pavlin Radoslavovbcc86ef2013-10-26 12:06:25 -0700174 * Test method for {@link FlowManager#addFlow(FlowPath, FlowId)}.
Toshio Koidefe2625e2013-06-26 13:59:53 -0700175 * @throws Exception
176 */
177 @Test
178 public final void testAddFlowSuccessNormally() throws Exception {
179 final String addFlowEntry = "addFlowEntry";
180 // create mock objects
181 IFlowPath createdFlowPath = createNiceMock(IFlowPath.class);
182 IFlowEntry createdFlowEntry1 = createNiceMock(IFlowEntry.class);
183 IFlowEntry createdFlowEntry2 = createNiceMock(IFlowEntry.class);
184 FlowManager fm = createPartialMockAndInvokeDefaultConstructor(FlowManager.class, addFlowEntry);
185
186 // instantiate required objects
187 final FlowEntry flowEntry1 = new FlowEntry();
188 final FlowEntry flowEntry2 = new FlowEntry();
189 ArrayList<FlowEntry> flowEntries = new ArrayList<FlowEntry>();
190 flowEntries.add(flowEntry1);
191 flowEntries.add(flowEntry2);
192
193 DataPath dataPath = new DataPath();
194 dataPath.setSrcPort(new SwitchPort(new Dpid(0x1234), new Port((short)1)));
195 dataPath.setDstPort(new SwitchPort(new Dpid(0x5678), new Port((short)2)));
196 dataPath.setFlowEntries(flowEntries);
197
198 FlowEntryMatch match = new FlowEntryMatch();
199
200 FlowPath flowPath = new FlowPath();
201 flowPath.setFlowId(new FlowId(0x100));
202 flowPath.setInstallerId(new CallerId("installer id"));
Pavlin Radoslavovd28cf7c2013-10-26 11:27:43 -0700203 flowPath.setFlowPathType(FlowPathType.valueOf("FP_TYPE_SHORTEST_PATH"));
Pavlin Radoslavov7d4a40e2013-10-27 23:39:40 -0700204 flowPath.setFlowPathUserState(FlowPathUserState.valueOf("FP_USER_ADD"));
Pavlin Radoslavov204b2862013-07-12 14:15:36 -0700205 flowPath.setFlowPathFlags(new FlowPathFlags(0));
Toshio Koidefe2625e2013-06-26 13:59:53 -0700206 flowPath.setDataPath(dataPath);
207 flowPath.setFlowEntryMatch(match);
208
209 // setup expectations
210 expectInitWithContext();
211 expect(op.searchFlowPath(cmpEq(new FlowId(0x100)))).andReturn(null);
212 expect(op.newFlowPath()).andReturn(createdFlowPath);
213 createdFlowPath.setFlowId("0x100");
214 createdFlowPath.setType("flow");
215 createdFlowPath.setInstallerId("installer id");
Pavlin Radoslavovd28cf7c2013-10-26 11:27:43 -0700216 createdFlowPath.setFlowPathType("FP_TYPE_SHORTEST_PATH");
Pavlin Radoslavov7d4a40e2013-10-27 23:39:40 -0700217 createdFlowPath.setFlowPathUserState("FP_USER_ADD");
Pavlin Radoslavov204b2862013-07-12 14:15:36 -0700218 createdFlowPath.setFlowPathFlags(new Long((long)0));
Toshio Koidefe2625e2013-06-26 13:59:53 -0700219 createdFlowPath.setSrcSwitch("00:00:00:00:00:00:12:34");
220 createdFlowPath.setSrcPort(new Short((short)1));
221 createdFlowPath.setDstSwitch("00:00:00:00:00:00:56:78");
222 createdFlowPath.setDstPort(new Short((short)2));
223 createdFlowPath.setDataPathSummary("data path summary");
Toshio Koidefe2625e2013-06-26 13:59:53 -0700224
225 expectPrivate(fm, addFlowEntry, createdFlowPath, flowEntry1)
226 .andReturn(createdFlowEntry1);
227 expectPrivate(fm, addFlowEntry, createdFlowPath, flowEntry2)
228 .andReturn(createdFlowEntry2);
229
230 op.commit();
231
232 // start the test
233 replayAll();
234
235 fm.init(context);
Pavlin Radoslavovbcc86ef2013-10-26 12:06:25 -0700236 Boolean result = fm.addFlow(flowPath, new FlowId(0x100));
Toshio Koidefe2625e2013-06-26 13:59:53 -0700237
238 // verify the test
239 verifyAll();
240 assertTrue(result);
241 }
Pavlin Radoslavovf2a52652013-11-22 12:35:42 -0800242
Toshio Koidefe2625e2013-06-26 13:59:53 -0700243 /**
Pavlin Radoslavovf2a52652013-11-22 12:35:42 -0800244 * Test method for {@link FlowManager#deleteFlow(FlowId)}.
245 * @throws Exception
Toshio Koidefe2625e2013-06-26 13:59:53 -0700246 */
247 @Test
Pavlin Radoslavovf2a52652013-11-22 12:35:42 -0800248 public final void testDeleteFlowSuccessNormally() throws Exception {
Toshio Koidefe2625e2013-06-26 13:59:53 -0700249 // create mock objects
Pavlin Radoslavovf2a52652013-11-22 12:35:42 -0800250 IFlowPath flowPath = createIFlowPathMock(123, "id", "FP_TYPE_SHORTEST_PATH", "FP_USER_ADD", 0, 1, 2, 3, 4);
251 IFlowEntry flowEntry1 = createMock(IFlowEntry.class);
252 IFlowEntry flowEntry2 = createMock(IFlowEntry.class);
253 IFlowEntry flowEntry3 = createMock(IFlowEntry.class);
Toshio Koidefe2625e2013-06-26 13:59:53 -0700254
255 // instantiate required objects
Toshio Koideca7abe02013-06-27 17:30:17 -0700256 FlowManager fm = new FlowManager();
Pavlin Radoslavovf2a52652013-11-22 12:35:42 -0800257 FlowId flowId = new FlowId(123);
258 ArrayList<IFlowEntry> flowEntries = new ArrayList<IFlowEntry>();
259 flowEntries.add(flowEntry1);
260 flowEntries.add(flowEntry2);
261 flowEntries.add(flowEntry3);
262
Toshio Koidefe2625e2013-06-26 13:59:53 -0700263 // setup expectations
264 expectInitWithContext();
Pavlin Radoslavovf2a52652013-11-22 12:35:42 -0800265 expect(op.searchFlowPath(cmpEq(flowId))).andReturn(flowPath);
266 expect(flowPath.getFlowEntries()).andReturn(flowEntries);
267 flowPath.removeFlowEntry(flowEntry1);
268 flowPath.removeFlowEntry(flowEntry2);
269 flowPath.removeFlowEntry(flowEntry3);
270 op.removeFlowEntry(flowEntry1);
271 op.removeFlowEntry(flowEntry2);
272 op.removeFlowEntry(flowEntry3);
273 op.removeFlowPath(flowPath);
Toshio Koidefe2625e2013-06-26 13:59:53 -0700274 op.commit();
Toshio Koidefe2625e2013-06-26 13:59:53 -0700275
276 // start the test
277 replayAll();
278
Toshio Koidefe2625e2013-06-26 13:59:53 -0700279 fm.init(context);
Pavlin Radoslavovf2a52652013-11-22 12:35:42 -0800280 fm.deleteFlow(flowId);
Toshio Koidefe2625e2013-06-26 13:59:53 -0700281
282 // verify the test
283 verifyAll();
Toshio Koidefe2625e2013-06-26 13:59:53 -0700284 }
285
286 /**
287 * Test method for {@link FlowManager#deleteFlow(FlowId)}.
288 * @throws Exception
289 */
290 @Test
291 public final void testDeleteFlowSuccessEmptyFlowPath() throws Exception {
Toshio Koideca7abe02013-06-27 17:30:17 -0700292 // instantiate required objects
293 FlowManager fm = new FlowManager();
294
Toshio Koidefe2625e2013-06-26 13:59:53 -0700295 // create mock objects
296 IFlowPath flowObj = createNiceMock(IFlowPath.class);
297
298 // setup expectations
299 expectInitWithContext();
300 expect(op.searchFlowPath(cmpEq(new FlowId(1)))).andReturn(flowObj);
301 expect(flowObj.getFlowEntries()).andReturn(new ArrayList<IFlowEntry>());
302 op.removeFlowPath(flowObj);
303 op.commit();
304 expectLastCall().anyTimes();
305
306 // start the test
307 replayAll();
308
Toshio Koidefe2625e2013-06-26 13:59:53 -0700309 fm.init(context);
310 Boolean result = fm.deleteFlow(new FlowId(1));
311
312 // verify the test
313 verifyAll();
314 assertTrue(result);
315 }
316
317 /**
Pavlin Radoslavovf2a52652013-11-22 12:35:42 -0800318 * Test method for {@link FlowManager#deleteAllFlows()}.
Toshio Koidefe2625e2013-06-26 13:59:53 -0700319 * @throws Exception
320 */
321 @Test
Pavlin Radoslavovf2a52652013-11-22 12:35:42 -0800322 public final void testDeleteAllFlowsSuccessNormally() throws Exception {
Toshio Koidefe2625e2013-06-26 13:59:53 -0700323 // create mock objects
324 IFlowPath flowPath1 = createNiceMock(IFlowPath.class);
325 IFlowPath flowPath2 = createNiceMock(IFlowPath.class);
326 IFlowPath flowPath3 = createNiceMock(IFlowPath.class);
Pavlin Radoslavovf2a52652013-11-22 12:35:42 -0800327 FlowManager fm = createPartialMockAndInvokeDefaultConstructor(FlowManager.class, "deleteFlow");
Toshio Koidefe2625e2013-06-26 13:59:53 -0700328
329 // instantiate required objects
330 ArrayList<IFlowPath> flowPaths = new ArrayList<IFlowPath>();
331 flowPaths.add(flowPath1);
332 flowPaths.add(flowPath2);
333 flowPaths.add(null);
334 flowPaths.add(flowPath3);
335
336 // setup expectations
337 expectInitWithContext();
338 expect(op.getAllFlowPaths()).andReturn(flowPaths);
339 expect(flowPath1.getFlowId()).andReturn(new FlowId(1).toString());
340 expect(flowPath2.getFlowId()).andReturn(null);
341 expect(flowPath3.getFlowId()).andReturn(new FlowId(3).toString());
Pavlin Radoslavovf2a52652013-11-22 12:35:42 -0800342 expect(fm.deleteFlow(cmpEq(new FlowId(1)))).andReturn(true);
343 expect(fm.deleteFlow(cmpEq(new FlowId(3)))).andReturn(true);
Toshio Koidefe2625e2013-06-26 13:59:53 -0700344
345 // start the test
346 replayAll();
347
348 fm.init(context);
Pavlin Radoslavovf2a52652013-11-22 12:35:42 -0800349 Boolean result = fm.deleteAllFlows();
Toshio Koidefe2625e2013-06-26 13:59:53 -0700350
Pavlin Radoslavovf2a52652013-11-22 12:35:42 -0800351 // verify the test
Toshio Koidefe2625e2013-06-26 13:59:53 -0700352 verifyAll();
353 assertTrue(result);
354 }
355
356 /**
357 * Test method for {@link FlowManager#getFlow()}.
358 * @throws Exception
359 */
360 @Test
361 public final void testGetFlowSuccessNormally() throws Exception {
362 // instantiate required objects
363 FlowManager fm = new FlowManager();
Pavlin Radoslavov7d4a40e2013-10-27 23:39:40 -0700364 IFlowPath iFlowPath = createIFlowPathMock(1, "caller id", "FP_TYPE_SHORTEST_PATH", "FP_USER_ADD", 0, 1, 1, 2, 2);
Toshio Koidefe2625e2013-06-26 13:59:53 -0700365
366 // setup expectations
367 expectInitWithContext();
Toshio Koideca7abe02013-06-27 17:30:17 -0700368 expect(op.searchFlowPath(cmpEq(new FlowId(1)))).andReturn(iFlowPath);
369 expect(iFlowPath.getFlowEntries()).andReturn(new ArrayList<IFlowEntry>()).anyTimes();
Toshio Koidefe2625e2013-06-26 13:59:53 -0700370 op.commit();
371
372 // start the test
373 replayAll();
374
375 fm.init(context);
Pavlin Radoslavov204b2862013-07-12 14:15:36 -0700376 FlowPath flowPath = fm.getFlow(new FlowId(1));
377 String installerId = flowPath.installerId().toString();
Pavlin Radoslavovd28cf7c2013-10-26 11:27:43 -0700378 String flowPathType = flowPath.flowPathType().toString();
Pavlin Radoslavov7d4a40e2013-10-27 23:39:40 -0700379 String flowPathUserState = flowPath.flowPathUserState().toString();
Pavlin Radoslavov204b2862013-07-12 14:15:36 -0700380 long flowPathFlags = flowPath.flowPathFlags().flags();
Toshio Koidefe2625e2013-06-26 13:59:53 -0700381
382 //verify the test
383 verifyAll();
Pavlin Radoslavov204b2862013-07-12 14:15:36 -0700384 assertEquals("caller id", installerId);
Pavlin Radoslavovd28cf7c2013-10-26 11:27:43 -0700385 assertEquals("FP_TYPE_SHORTEST_PATH", flowPathType);
Pavlin Radoslavov7d4a40e2013-10-27 23:39:40 -0700386 assertEquals("FP_USER_ADD", flowPathUserState);
Pavlin Radoslavov204b2862013-07-12 14:15:36 -0700387 assertEquals(0L, flowPathFlags);
Toshio Koidefe2625e2013-06-26 13:59:53 -0700388 }
389
390 /**
391 * Test method for {@link FlowManager#getAllFlows(CallerId, DataPathEndpoints)}.
392 * @throws Exception
393 */
394 @Test
395 public final void testGetAllFlowsWithCallerIdAndDataPathEndpointsSuccessNormally() throws Exception {
396 final String getAllFlows = "getAllFlows";
397 // create mock objects
398 FlowManager fm = createPartialMock(FlowManager.class, getAllFlows,
399 new Class<?>[]{}, new Object[]{});
400
401 // instantiate required objects
402 DataPathEndpoints dataPathEndpoints = new DataPathEndpoints(
403 new SwitchPort(new Dpid(1), new Port((short)1)),
404 new SwitchPort(new Dpid(2), new Port((short)2)));
405
406 ArrayList<FlowPath> obtainedAllFlows = createTestFlowPaths();
407
408 //setup expectations
409 expectInitWithContext();
410 expectPrivate(fm, getAllFlows).andReturn(obtainedAllFlows);
411
412 //start the test
413 replayAll();
414
415 fm.init(context);
416 ArrayList<FlowPath> flows = fm.getAllFlows(new CallerId("caller id"), dataPathEndpoints);
417
418 // verify the test
419 verifyAll();
420 assertEquals(1, flows.size());
421 assertEquals(obtainedAllFlows.get(1), flows.get(0));
422 }
423
424 /**
425 * Test method for {@link FlowManager#getAllFlows(DataPathEndpoints)}.
426 * @throws Exception
427 */
428 @Test
429 public final void testGetAllFlowsWithDataPathEndpointsSuccessNormally() throws Exception {
430 final String getAllFlows = "getAllFlows";
431 // create mock objects
432 FlowManager fm = createPartialMock(FlowManager.class, getAllFlows,
433 new Class<?>[]{}, new Object[]{});
434
435 // instantiate required objects
436 DataPathEndpoints dataPathEndpoints = new DataPathEndpoints(
437 new SwitchPort(new Dpid(1), new Port((short)1)),
438 new SwitchPort(new Dpid(2), new Port((short)2)));
439
440 ArrayList<FlowPath> obtainedAllFlows = createTestFlowPaths();
441
442 //setup expectations
443 expectInitWithContext();
444 expectPrivate(fm, getAllFlows).andReturn(obtainedAllFlows);
445
446 //start the test
447 replayAll();
448
449 fm.init(context);
450 ArrayList<FlowPath> flows = fm.getAllFlows(dataPathEndpoints);
451
452 // verify the test
453 verifyAll();
454 assertEquals(2, flows.size());
455 assertEquals(obtainedAllFlows.get(0), flows.get(0));
456 assertEquals(obtainedAllFlows.get(1), flows.get(1));
457 // TODO: ignore the order of flows in the list
458 }
459
460 /**
461 * Test method for {@link FlowManager#getAllFlowsSummary(FlowId, int)}.
462 * @throws Exception
463 */
464 @Test
465 public final void testGetAllFlowsSummarySuccessNormally() throws Exception {
Pavlin Radoslavov4ef6ba22013-11-22 19:32:58 -0800466 final String getAllFlowsWithDataPathSummary = "getAllFlowsWithDataPathSummary";
Toshio Koidefe2625e2013-06-26 13:59:53 -0700467 // create mock objects
Pavlin Radoslavov4ef6ba22013-11-22 19:32:58 -0800468 FlowManager fm = createPartialMockAndInvokeDefaultConstructor(FlowManager.class, getAllFlowsWithDataPathSummary);
469 FlowPath flowPath1 = createTestFlowPath(1, "", "FP_TYPE_SHORTEST_PATH", "FP_USER_ADD", 0, 1, 2, 3, 4);
470 FlowPath flowPath2 = createTestFlowPath(5, "", "FP_TYPE_SHORTEST_PATH", "FP_USER_ADD", 0, 2, 3, 4, 5);
471 FlowPath flowPath3 = createTestFlowPath(10, "", "FP_TYPE_SHORTEST_PATH", "FP_USER_ADD", 0, 3, 4, 5, 6);
Toshio Koidefe2625e2013-06-26 13:59:53 -0700472
473 // instantiate required objects
Pavlin Radoslavov4ef6ba22013-11-22 19:32:58 -0800474 ArrayList<FlowPath> flows = new ArrayList<FlowPath>();
Toshio Koidefe2625e2013-06-26 13:59:53 -0700475 flows.add(flowPath3);
476 flows.add(flowPath1);
477 flows.add(flowPath2);
478
479 // setup expectations
480 expectInitWithContext();
Pavlin Radoslavov4ef6ba22013-11-22 19:32:58 -0800481 expectPrivate(fm, getAllFlowsWithDataPathSummary).andReturn(flows);
Toshio Koidefe2625e2013-06-26 13:59:53 -0700482
483 // start the test
484 replayAll();
485
486 fm.init(context);
Pavlin Radoslavov4ef6ba22013-11-22 19:32:58 -0800487 ArrayList<FlowPath> returnedFlows = fm.getAllFlowsSummary(null, 0);
Toshio Koidefe2625e2013-06-26 13:59:53 -0700488
489 // verify the test
490 verifyAll();
491 assertEquals(3, returnedFlows.size());
Pavlin Radoslavov4ef6ba22013-11-22 19:32:58 -0800492 assertEquals(1, new FlowId(returnedFlows.get(0).flowId().value()).value());
493 assertEquals(5, new FlowId(returnedFlows.get(1).flowId().value()).value());
494 assertEquals(10, new FlowId(returnedFlows.get(2).flowId().value()).value());
Toshio Koidefe2625e2013-06-26 13:59:53 -0700495 }
496
497 /**
498 * Test method for {@link FlowManager#getAllFlows()}.
499 * @throws Exception
500 */
501 @Test
502 public final void testGetAllFlowsSuccessNormally() throws Exception {
Toshio Koideca7abe02013-06-27 17:30:17 -0700503 // create mock objects
Pavlin Radoslavov7d4a40e2013-10-27 23:39:40 -0700504 IFlowPath iFlowPath1 = createIFlowPathMock(1, "caller id", "FP_TYPE_SHORTEST_PATH", "FP_USER_ADD", 0, 1, 1, 2, 2);
505 IFlowPath iFlowPath2 = createIFlowPathMock(2, "caller id", "FP_TYPE_SHORTEST_PATH", "FP_USER_ADD", 0, 2, 5, 3, 5);
Toshio Koideca7abe02013-06-27 17:30:17 -0700506
Toshio Koidefe2625e2013-06-26 13:59:53 -0700507 // instantiate required objects
508 ArrayList<IFlowPath> flowPaths = new ArrayList<IFlowPath>();
Toshio Koideca7abe02013-06-27 17:30:17 -0700509 flowPaths.add(iFlowPath1);
510 flowPaths.add(iFlowPath2);
Toshio Koidefe2625e2013-06-26 13:59:53 -0700511 FlowManager fm = new FlowManager();
512
513 // setup expectations
514 expectInitWithContext();
515 expect(op.getAllFlowPaths()).andReturn(flowPaths);
Toshio Koideca7abe02013-06-27 17:30:17 -0700516 expect(iFlowPath1.getFlowEntries()).andReturn(new ArrayList<IFlowEntry>()).anyTimes();
517 expect(iFlowPath2.getFlowEntries()).andReturn(new ArrayList<IFlowEntry>()).anyTimes();
Toshio Koidefe2625e2013-06-26 13:59:53 -0700518 op.commit();
519
520 // start the test
521 replayAll();
522
523 fm.init(context);
524 ArrayList<FlowPath> flows = fm.getAllFlows();
525
526 // verify the test
527 verifyAll();
528 assertEquals(2, flows.size());
529 assertEquals(new SwitchPort(new Dpid(1), new Port((short)1)).toString(),
530 flows.get(0).dataPath().srcPort().toString());
531 assertEquals(new SwitchPort(new Dpid(2), new Port((short)5)).toString(),
532 flows.get(1).dataPath().srcPort().toString());
533 // TODO: more asserts
534 // TODO: ignore seq. of the list
535 }
536
537 /**
538 * Test method for {@link FlowManager#addAndMaintainShortestPathFlow(FlowPath)}.
539 * @throws Exception
540 */
541 @Test
542 public final void testAddAndMaintainShortestPathFlowSuccessNormally() throws Exception {
543 final String addFlow = "addFlow";
544
545 // create mock objects
546 FlowManager fm = createPartialMockAndInvokeDefaultConstructor(FlowManager.class, addFlow);
547
548 // instantiate required objects
549 DataPath dataPath = new DataPath();
550 dataPath.setSrcPort(new SwitchPort(new Dpid(1), new Port((short)3)));
551 dataPath.setDstPort(new SwitchPort(new Dpid(2), new Port((short)4)));
552 FlowEntryMatch match = new FlowEntryMatch();
553 FlowPath paramFlow = new FlowPath();
554 paramFlow.setFlowId(new FlowId(100));
555 paramFlow.setInstallerId(new CallerId("installer id"));
Pavlin Radoslavovd28cf7c2013-10-26 11:27:43 -0700556 paramFlow.setFlowPathType(FlowPathType.valueOf("FP_TYPE_SHORTEST_PATH"));
Pavlin Radoslavov7d4a40e2013-10-27 23:39:40 -0700557 paramFlow.setFlowPathUserState(FlowPathUserState.valueOf("FP_USER_ADD"));
Pavlin Radoslavov204b2862013-07-12 14:15:36 -0700558 paramFlow.setFlowPathFlags(new FlowPathFlags(0));
Toshio Koidefe2625e2013-06-26 13:59:53 -0700559 paramFlow.setDataPath(dataPath);
560 paramFlow.setFlowEntryMatch(match);
561
562 // setup expectations
563 expectInitWithContext();
564 expectPrivate(fm, addFlow,
565 EasyMock.anyObject(FlowPath.class),
566 EasyMock.anyObject(FlowId.class),
567 EasyMock.anyObject(String.class)
568 ).andAnswer(new IAnswer<Object>() {
569 public Object answer() throws Exception {
570 FlowPath flowPath = (FlowPath)EasyMock.getCurrentArguments()[0];
571 assertEquals(flowPath.flowId().value(), 100);
572 assertEquals(flowPath.installerId().toString(), "installer id");
Pavlin Radoslavovd28cf7c2013-10-26 11:27:43 -0700573 assertEquals(flowPath.flowPathType().toString(), "PF_TYPE_SHORTEST_PATH");
Pavlin Radoslavov7d4a40e2013-10-27 23:39:40 -0700574 assertEquals(flowPath.flowPathUserState().toString(), "PF_USER_STATE");
Pavlin Radoslavov204b2862013-07-12 14:15:36 -0700575 assertEquals(flowPath.flowPathFlags().flags(), 0);
Toshio Koidefe2625e2013-06-26 13:59:53 -0700576 assertEquals(flowPath.dataPath().srcPort().toString(),
577 new SwitchPort(new Dpid(1), new Port((short)3)).toString());
578
579 String dataPathSummary = (String)EasyMock.getCurrentArguments()[2];
580 assertEquals(dataPathSummary, "X");
581
582 return true;
583 }
584 });
585
586 // start the test
587 replayAll();
588
589 fm.init(context);
590 FlowPath resultFlow = fm.addAndMaintainShortestPathFlow(paramFlow);
591
592 // verify the test
593 verifyAll();
594 assertEquals(paramFlow.flowId().value(), resultFlow.flowId().value());
595 assertEquals(paramFlow.installerId().toString(), resultFlow.installerId().toString());
Pavlin Radoslavovd28cf7c2013-10-26 11:27:43 -0700596 assertEquals(paramFlow.flowPathType().toString(), resultFlow.flowPathType().toString());
Pavlin Radoslavov7d4a40e2013-10-27 23:39:40 -0700597 assertEquals(paramFlow.flowPathUserState().toString(), resultFlow.flowPathUserState().toString());
Pavlin Radoslavov204b2862013-07-12 14:15:36 -0700598 assertEquals(paramFlow.flowPathFlags().flags(), resultFlow.flowPathFlags().flags());
Toshio Koidefe2625e2013-06-26 13:59:53 -0700599 assertEquals(paramFlow.dataPath().toString(), resultFlow.dataPath().toString());
600 assertEquals(paramFlow.flowEntryMatch().toString(), resultFlow.flowEntryMatch().toString());
601 }
602
Toshio Koidefe2625e2013-06-26 13:59:53 -0700603 // INetMapStorage methods
604
Toshio Koidefe2625e2013-06-26 13:59:53 -0700605 /**
606 * Test method for {@link FlowManager#init(String)}.
607 * @throws Exception
608 */
609 @Test
610 public final void testInitSuccessNormally() throws Exception {
Toshio Koideca7abe02013-06-27 17:30:17 -0700611 // instantiate required objects
612 FlowManager fm = new FlowManager();
613
Toshio Koidefe2625e2013-06-26 13:59:53 -0700614 // create mock objects
615 op = createMock(GraphDBOperation.class);
616
617 // setup expectations
618 expectNew(GraphDBOperation.class, "/dummy/path").andReturn(op);
619
620 // start the test
621 replayAll();
622
Toshio Koidefe2625e2013-06-26 13:59:53 -0700623 fm.init("/dummy/path");
624
625 // verify the test
626 verifyAll();
627 }
628
629 /**
630 * Test method for {@link FlowManager#close()}.
631 * @throws Exception
632 */
633 @Test
634 public final void testCloseSuccessNormally() throws Exception {
635 // instantiate required objects
636 FlowManager fm = new FlowManager();
637
638 // setup expectations
639 expectInitWithContext();
640 op.close();
641
642 // start the test
643 replayAll();
644
645 fm.init(context);
646 fm.close();
647
648 // verify the test
649 verifyAll();
650 }
651
652
653 // IFloodlightModule methods
654
655
656 /**
657 * Test method for {@link FlowManager#getModuleServices()}.
658 * @throws Exception
659 */
660 @Test
661 public final void testGetModuleServicesSuccessNormally() throws Exception {
662 // instantiate required objects
663 FlowManager fm = new FlowManager();
664
665 // setup expectations
666 expectInitWithContext();
667
668 // start the test
669 replayAll();
670
671 fm.init(context);
672 Collection<Class<? extends IFloodlightService>> l = fm.getModuleServices();
673
674 // verify the test
675 verifyAll();
676 assertEquals(1, l.size());
677 assertEquals(IFlowService.class, l.iterator().next());
678 }
679
680 /**
681 * Test method for {@link FlowManager#getServiceImpls()}.
682 * @throws Exception
683 */
684 @Test
685 public final void testGetServiceImplsSuccessNormally() throws Exception {
686 // instantiate required objects
687 FlowManager fm = new FlowManager();
688
689 // setup expectations
690 expectInitWithContext();
691
692 // start the test
693 replayAll();
694
695 fm.init(context);
696 Map<Class<? extends IFloodlightService>, IFloodlightService> si = fm.getServiceImpls();
697
698 // verify the test
699 verifyAll();
700 assertEquals(1, si.size());
701 assertTrue(si.containsKey(IFlowService.class));
702 assertEquals(fm, si.get(IFlowService.class));
703 }
704
705 /**
706 * Test method for {@link FlowManager#getModuleDependencies()}.
707 * @throws Exception
708 */
709 @Test
710 public final void testGetModuleDependenciesSuccessNormally() throws Exception {
711 // instantiate required objects
712 FlowManager fm = new FlowManager();
713
714 // setup expectations
715 expectInitWithContext();
716
717 // start the test
718 replayAll();
719
720 fm.init(context);
721 Collection<Class<? extends IFloodlightService>> md = fm.getModuleDependencies();
722
723 // verify the test
724 verifyAll();
Pavlin Radoslavov05378272013-10-19 23:23:05 -0700725 assertEquals(4, md.size());
Toshio Koidefe2625e2013-06-26 13:59:53 -0700726 assertTrue(md.contains(IFloodlightProviderService.class));
Toshio Koidefe2625e2013-06-26 13:59:53 -0700727 assertTrue(md.contains(IRestApiService.class));
728 }
729
730 /**
731 * Test method for {@link FlowManager#init(FloodlightModuleContext)}.
732 * @throws Exception
733 */
734 @Test
735 public final void testInitWithFloodlightModuleContextSuccessNormally() throws Exception {
736 // instantiate required objects
737 FlowManager fm = new FlowManager();
738
739 // setup expectations
740 expectInitWithContext();
741
742 // start the test
743 replayAll();
744
745 fm.init(context);
746
747 // verify the test
748 verifyAll();
749 }
750
751 /**
752 * Test method for {@link FlowManager#startUp(FloodlightModuleContext)}.
753 * @throws Exception
754 */
755 @Test
756 public final void testStartupSuccessNormally() throws Exception {
757 // create mock objects
758 mockStaticPartial(Executors.class, "newScheduledThreadPool");
759 ScheduledExecutorService scheduler = createMock(ScheduledExecutorService.class);
760
Toshio Koidefe2625e2013-06-26 13:59:53 -0700761 // instantiate required objects
762 FlowManager fm = new FlowManager();
763
764 // setup expectations
765 expectInitWithContext();
766 expect(Executors.newScheduledThreadPool(1)).andReturn(scheduler);
767 expect(Executors.newScheduledThreadPool(1)).andReturn(scheduler);
768 expect(scheduler.scheduleAtFixedRate(
769 EasyMock.anyObject(Runnable.class),
770 EasyMock.anyLong(),
771 EasyMock.anyLong(),
772 EasyMock.anyObject(TimeUnit.class))).andReturn(null).times(2);
773 restApi.addRestletRoutable(EasyMock.anyObject(FlowWebRoutable.class));
774
775 // start the test
776 replayAll();
777
778 fm.init(context);
779 fm.startUp(context);
780
781 // verify the test
782 verifyAll();
783 }
Toshio Koideca7abe02013-06-27 17:30:17 -0700784
785
786 // other methods
787
Toshio Koideca7abe02013-06-27 17:30:17 -0700788 /**
Toshio Koideca7abe02013-06-27 17:30:17 -0700789 * Test method for {@link FlowManager#reconcileFlow(IFlowPath, DataPath)}.
790 * @throws Exception
791 */
792 @Test
793 public final void testReconcileFlowWithFlowPathAndDataPathSuccessNormally() throws Exception {
794 final String addFlowEntry = "addFlowEntry";
795
796 // create mock objects
Pavlin Radoslavov7d4a40e2013-10-27 23:39:40 -0700797 IFlowPath iFlowPath1 = createIFlowPathMock(1, "caller id", "FP_TYPE_SHORTEST_PATH", "FP_USER_ADD", 0, 1, 1, 2, 2);
Toshio Koideca7abe02013-06-27 17:30:17 -0700798 IFlowEntry iFlowEntry1 = createMock(IFlowEntry.class);
799 IFlowEntry iFlowEntry2 = createMock(IFlowEntry.class);
800 FlowManager fm = createPartialMockAndInvokeDefaultConstructor(FlowManager.class, addFlowEntry);
801
802 // instantiate required objects
803 FlowEntry flowEntry1 = new FlowEntry();
804 flowEntry1.setDpid(new Dpid(1));
805 flowEntry1.setFlowId(new FlowId(1));
806 flowEntry1.setInPort(new Port((short) 1));
807 flowEntry1.setOutPort(new Port((short) 11));
808 flowEntry1.setFlowEntryId(new FlowEntryId(1));
809 flowEntry1.setFlowEntryMatch(new FlowEntryMatch());
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700810 flowEntry1.setFlowEntryActions(new FlowEntryActions());
Toshio Koideca7abe02013-06-27 17:30:17 -0700811 flowEntry1.setFlowEntryErrorState(new FlowEntryErrorState());
812
813 FlowEntry flowEntry2 = new FlowEntry();
814 flowEntry2.setDpid(new Dpid(2));
815 flowEntry2.setFlowId(new FlowId(2));
816 flowEntry2.setInPort(new Port((short) 22));
817 flowEntry2.setOutPort(new Port((short) 2));
818 flowEntry2.setFlowEntryId(new FlowEntryId(2));
819 flowEntry2.setFlowEntryMatch(new FlowEntryMatch());
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700820 flowEntry2.setFlowEntryActions(new FlowEntryActions());
Toshio Koideca7abe02013-06-27 17:30:17 -0700821 flowEntry2.setFlowEntryErrorState(new FlowEntryErrorState());
822
823 DataPath dataPath = new DataPath();
824 ArrayList<FlowEntry> flowEntries = new ArrayList<FlowEntry>();
825 flowEntries.add(flowEntry1);
826 flowEntries.add(flowEntry2);
827 dataPath.setFlowEntries(flowEntries);
828
829 ArrayList<IFlowEntry> oldFlowEntries = new ArrayList<IFlowEntry>();
830 oldFlowEntries.add(iFlowEntry1);
831 oldFlowEntries.add(iFlowEntry2);
832
833 // setup expectations
834 expectInitWithContext();
Toshio Koideca7abe02013-06-27 17:30:17 -0700835 expect(iFlowPath1.getFlowEntries()).andReturn(oldFlowEntries);
836 iFlowEntry1.setUserState("FE_USER_DELETE");
837 iFlowEntry1.setSwitchState("FE_SWITCH_NOT_UPDATED");
838 iFlowEntry2.setUserState("FE_USER_DELETE");
839 iFlowEntry2.setSwitchState("FE_SWITCH_NOT_UPDATED");
840 expectPrivate(fm, addFlowEntry, iFlowPath1, flowEntry1).andReturn(null);
841 expectPrivate(fm, addFlowEntry, iFlowPath1, flowEntry2).andReturn(null);
842
843 // start the test
844 replayAll();
845
846 fm.init(context);
Pavlin Radoslavov1308dc62013-10-25 15:54:31 -0700847 // Use reflection to test the private method
848 // Boolean result = fm.reconcileFlow(iFlowPath1, dataPath);
849 Class fmClass = FlowManager.class;
850 Method method = fmClass.getDeclaredMethod(
851 "reconcileFlow",
852 new Class[] { IFlowPath.class, DataPath.class });
853 method.setAccessible(true);
854 Boolean result = (Boolean)method.invoke(fm,
855 new Object[] { iFlowPath1, dataPath });
Toshio Koideca7abe02013-06-27 17:30:17 -0700856
857 // verify the test
858 verifyAll();
859 assertTrue(result);
860 // TODO: write more asserts
861 }
862
863 /**
864 * Test method for {@link FlowManager#installFlowEntry(net.floodlightcontroller.core.IOFSwitch, IFlowPath, IFlowEntry)}.
865 * @throws Exception
866 */
867 @Test
868 public final void testInstallFlowEntryWithIFlowPathSuccessNormally() throws Exception {
869 // create mock object
870 IOFSwitch iofSwitch = createNiceMock(IOFSwitch.class);
Pavlin Radoslavov7d4a40e2013-10-27 23:39:40 -0700871 IFlowPath iFlowPath = createIFlowPathMock(1, "id", "FP_TYPE_SHORTEST_PATH", "FP_USER_ADD", 0, 1, 2, 3, 4);
Toshio Koideca7abe02013-06-27 17:30:17 -0700872 IFlowEntry iFlowEntry = createMock(IFlowEntry.class);
873 BasicFactory basicFactory = createMock(BasicFactory.class);
874
875 // instantiate required objects
876 FlowManager fm = new FlowManager();
877
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700878 FlowEntryAction action = new FlowEntryAction();
879 action.setActionOutput(new Port((short)2));
880 FlowEntryActions actions = new FlowEntryActions();
881 actions.addAction(action);
882
Toshio Koideca7abe02013-06-27 17:30:17 -0700883 // setup expectations
884 expectInitWithContext();
885 expect(iFlowEntry.getFlowEntryId()).andReturn(new FlowEntryId(123).toString());
886 expect(iFlowEntry.getUserState()).andReturn("FE_USER_ADD");
887 iFlowEntry.setSwitchState("FE_SWITCH_UPDATED");
888 expect(iFlowEntry.getMatchInPort()).andReturn(new Short((short) 1));
Toshio Koideca7abe02013-06-27 17:30:17 -0700889 expect(iFlowEntry.getMatchSrcMac()).andReturn("01:23:45:67:89:01");
890 expect(iFlowEntry.getMatchDstMac()).andReturn("01:23:45:67:89:02");
Pavlin Radoslavovad3a1e62013-07-09 13:30:16 -0700891 expect(iFlowEntry.getMatchEthernetFrameType()).andReturn(new Short((short)0x0800));
892 expect(iFlowEntry.getMatchVlanId()).andReturn(new Short((short)0x1234));
893 expect(iFlowEntry.getMatchVlanPriority()).andReturn(new Byte((byte)0x10));
894 expect(iFlowEntry.getMatchSrcIPv4Net()).andReturn("192.168.0.1");
895 expect(iFlowEntry.getMatchDstIPv4Net()).andReturn("192.168.0.2");
896 expect(iFlowEntry.getMatchIpProto()).andReturn(new Byte((byte)0x20));
897 expect(iFlowEntry.getMatchIpToS()).andReturn(new Byte((byte)0x3));
898 expect(iFlowEntry.getMatchSrcTcpUdpPort()).andReturn(new Short((short)40000));
899 expect(iFlowEntry.getMatchDstTcpUdpPort()).andReturn(new Short((short)80));
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700900 expect(iFlowEntry.getActions()).andReturn(actions.toString());
Toshio Koideca7abe02013-06-27 17:30:17 -0700901 expect(floodlightProvider.getOFMessageFactory()).andReturn(basicFactory);
902 expect(basicFactory.getMessage(OFType.FLOW_MOD)).andReturn(new OFFlowMod());
903 expect(iofSwitch.getStringId()).andReturn(new Dpid(100).toString());
904
905 // start the test
906 replayAll();
907
908 fm.init(context);
Pavlin Radoslavov1308dc62013-10-25 15:54:31 -0700909 // Use reflection to test the private method
910 // Boolean result = fm.installFlowEntry(iofSwitch, iFlowPath, iFlowEntry);
911 Class fmClass = FlowManager.class;
912 Method method = fmClass.getDeclaredMethod(
913 "installFlowEntry",
914 new Class[] { IOFSwitch.class, IFlowPath.class, IFlowEntry.class });
915 method.setAccessible(true);
916 Boolean result = (Boolean)method.invoke(fm,
917 new Object[] { iofSwitch, iFlowPath, iFlowEntry });
918
Toshio Koideca7abe02013-06-27 17:30:17 -0700919
920 // verify the test
921 verifyAll();
922 assertTrue(result);
923 // TODO: write more asserts
924 }
925
926 /**
927 * Test method for {@link FlowManager#installFlowEntry(net.floodlightcontroller.core.IOFSwitch, FlowPath, FlowEntry)}.
928 * The method seems to be not used for now.
929 */
930 @Ignore @Test
931 public final void testInstallFlowEntryWithFlowPathSuccessNormally() {
932 fail("not yet implemented");
933 }
934
935 /**
936 * Test method for {@link FlowManager#removeFlowEntry(net.floodlightcontroller.core.IOFSwitch, FlowPath, FlowEntry)}.
937 * The method seems to be not implemented and not used for now.
938 */
939 @Ignore @Test
940 public final void testRemoveFlowEntrySuccessNormally() {
941 fail("not yet implemented");
942 }
Pavlin Radoslavovddd01ba2013-07-03 15:40:44 -0700943}