Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 1 | package net.onrc.onos.ofcontroller.flowmanager; |
| 2 | |
| 3 | import static org.junit.Assert.*; |
| 4 | import static org.easymock.EasyMock.expect; |
| 5 | import static org.easymock.EasyMock.cmpEq; |
| 6 | import static org.powermock.api.easymock.PowerMock.*; |
| 7 | |
| 8 | import java.util.*; |
| 9 | import java.util.concurrent.Executors; |
| 10 | import java.util.concurrent.ScheduledExecutorService; |
| 11 | import java.util.concurrent.TimeUnit; |
| 12 | |
| 13 | import net.floodlightcontroller.core.IFloodlightProviderService; |
Toshio Koide | ca7abe0 | 2013-06-27 17:30:17 -0700 | [diff] [blame] | 14 | import net.floodlightcontroller.core.IOFSwitch; |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 15 | import net.floodlightcontroller.core.module.FloodlightModuleContext; |
| 16 | import net.floodlightcontroller.core.module.IFloodlightService; |
| 17 | import net.floodlightcontroller.restserver.IRestApiService; |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame^] | 18 | import net.onrc.onos.datagrid.IDatagridService; |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 19 | import net.onrc.onos.graph.GraphDBOperation; |
| 20 | import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IFlowEntry; |
| 21 | import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IFlowPath; |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 22 | import net.onrc.onos.ofcontroller.flowmanager.web.FlowWebRoutable; |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame^] | 23 | import net.onrc.onos.ofcontroller.topology.ITopologyNetService; |
Pavlin Radoslavov | e1b37bc | 2013-10-16 03:57:06 -0700 | [diff] [blame] | 24 | import net.onrc.onos.ofcontroller.topology.TopologyManager; |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 25 | import net.onrc.onos.ofcontroller.util.*; |
| 26 | |
| 27 | import org.easymock.EasyMock; |
| 28 | import org.easymock.IAnswer; |
| 29 | import org.junit.After; |
| 30 | import org.junit.Before; |
Toshio Koide | ca7abe0 | 2013-06-27 17:30:17 -0700 | [diff] [blame] | 31 | import org.junit.Ignore; |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 32 | import org.junit.Test; |
| 33 | import org.junit.runner.RunWith; |
Toshio Koide | ca7abe0 | 2013-06-27 17:30:17 -0700 | [diff] [blame] | 34 | import org.openflow.protocol.OFFlowMod; |
| 35 | import org.openflow.protocol.OFType; |
| 36 | import org.openflow.protocol.factory.BasicFactory; |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 37 | import org.powermock.core.classloader.annotations.PrepareForTest; |
| 38 | import org.powermock.modules.junit4.PowerMockRunner; |
| 39 | |
| 40 | /** |
| 41 | * @author Toshio Koide |
| 42 | */ |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame^] | 43 | @Ignore |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 44 | @RunWith(PowerMockRunner.class) |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame^] | 45 | @PrepareForTest({FlowManager.class, FlowDatabaseOperation.class, GraphDBOperation.class, System.class, Executors.class}) |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 46 | public class FlowManagerTest { |
| 47 | private static FloodlightModuleContext context; |
| 48 | private static IFloodlightProviderService floodlightProvider; |
Pavlin Radoslavov | e1b37bc | 2013-10-16 03:57:06 -0700 | [diff] [blame] | 49 | private static TopologyManager topologyManager; |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame^] | 50 | private static IDatagridService datagridService; |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 51 | private static IRestApiService restApi; |
| 52 | private static GraphDBOperation op; |
| 53 | |
| 54 | /** |
| 55 | * @throws java.lang.Exception |
| 56 | */ |
| 57 | @Before |
| 58 | public void setUp() throws Exception { |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * @throws java.lang.Exception |
| 63 | */ |
| 64 | @After |
| 65 | public void tearDown() throws Exception { |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * @throws java.lang.Exception |
| 70 | */ |
| 71 | private void expectInitWithContext() throws Exception { |
| 72 | // create mock objects |
| 73 | context = createMock(FloodlightModuleContext.class); |
| 74 | floodlightProvider = createMock(IFloodlightProviderService.class); |
Pavlin Radoslavov | e1b37bc | 2013-10-16 03:57:06 -0700 | [diff] [blame] | 75 | topologyManager = createMock(TopologyManager.class); |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame^] | 76 | datagridService = createMock(IDatagridService.class); |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 77 | restApi = createMock(IRestApiService.class); |
| 78 | op = createMock(GraphDBOperation.class); |
| 79 | |
| 80 | // setup expectations |
| 81 | expect(context.getServiceImpl(IFloodlightProviderService.class)).andReturn(floodlightProvider); |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame^] | 82 | expect(context.getServiceImpl(ITopologyNetService.class)).andReturn(topologyManager); |
| 83 | expect(context.getServiceImpl(IDatagridService.class)).andReturn(datagridService); |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 84 | expect(context.getServiceImpl(IRestApiService.class)).andReturn(restApi); |
| 85 | expectNew(GraphDBOperation.class, new Class<?>[] {String.class}, EasyMock.isA(String.class)).andReturn(op); |
Pavlin Radoslavov | e1b37bc | 2013-10-16 03:57:06 -0700 | [diff] [blame] | 86 | expectNew(TopologyManager.class, new Class<?>[] {String.class}, EasyMock.isA(String.class)).andReturn(topologyManager); |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | private IFlowPath createIFlowPathMock(long flowId, String installerID, |
Pavlin Radoslavov | 204b286 | 2013-07-12 14:15:36 -0700 | [diff] [blame] | 90 | long flowPathFlags, |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 91 | long srcDpid, int srcPort, long dstDpid, int dstPort) { |
| 92 | IFlowPath iFlowPath = createNiceMock(IFlowPath.class); |
| 93 | expect(iFlowPath.getFlowId()).andReturn(new FlowId(flowId).toString()).anyTimes(); |
| 94 | expect(iFlowPath.getInstallerId()).andReturn(installerID).anyTimes(); |
Pavlin Radoslavov | 204b286 | 2013-07-12 14:15:36 -0700 | [diff] [blame] | 95 | expect(iFlowPath.getFlowPathFlags()).andReturn(new Long(flowPathFlags)).anyTimes(); |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 96 | expect(iFlowPath.getSrcSwitch()).andReturn(new Dpid(srcDpid).toString()).anyTimes(); |
| 97 | expect(iFlowPath.getSrcPort()).andReturn(new Short((short)srcPort)).anyTimes(); |
| 98 | expect(iFlowPath.getDstSwitch()).andReturn(new Dpid(dstDpid).toString()).anyTimes(); |
| 99 | expect(iFlowPath.getDstPort()).andReturn(new Short((short)dstPort)).anyTimes(); |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 100 | return iFlowPath; |
| 101 | } |
| 102 | |
Toshio Koide | ca7abe0 | 2013-06-27 17:30:17 -0700 | [diff] [blame] | 103 | private FlowPath createTestFlowPath(long flowId, String installerId, |
Pavlin Radoslavov | 204b286 | 2013-07-12 14:15:36 -0700 | [diff] [blame] | 104 | final long flowPathFlags, |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 105 | final long srcDpid, final int srcPort, |
| 106 | final long dstDpid, final int dstPort |
| 107 | ) { |
| 108 | FlowPath flowPath = new FlowPath(); |
| 109 | flowPath.setFlowId(new FlowId(flowId)); |
| 110 | flowPath.setInstallerId(new CallerId(installerId)); |
Pavlin Radoslavov | 204b286 | 2013-07-12 14:15:36 -0700 | [diff] [blame] | 111 | flowPath.setFlowPathFlags(new FlowPathFlags(flowPathFlags)); |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 112 | flowPath.setDataPath(new DataPath() {{ |
| 113 | setSrcPort(new SwitchPort(new Dpid(srcDpid), new Port((short)srcPort))); |
| 114 | setDstPort(new SwitchPort(new Dpid(dstDpid), new Port((short)dstPort))); |
| 115 | }}); |
| 116 | flowPath.setFlowEntryMatch(new FlowEntryMatch()); |
| 117 | return flowPath; |
| 118 | } |
| 119 | |
| 120 | private ArrayList<FlowPath> createTestFlowPaths() { |
Pavlin Radoslavov | 204b286 | 2013-07-12 14:15:36 -0700 | [diff] [blame] | 121 | FlowPath flowPath1 = createTestFlowPath(1, "foo caller id", 0, 1, 1, 2, 2); |
| 122 | FlowPath flowPath2 = createTestFlowPath(2, "caller id", 0, 1, 1, 2, 2); |
| 123 | FlowPath flowPath3 = createTestFlowPath(3, "caller id", 0, 1, 5, 2, 2); |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 124 | |
| 125 | ArrayList<FlowPath> flowPaths = new ArrayList<FlowPath>(); |
| 126 | flowPaths.add(flowPath1); |
| 127 | flowPaths.add(flowPath2); |
| 128 | flowPaths.add(flowPath3); |
| 129 | |
| 130 | return flowPaths; |
| 131 | } |
| 132 | |
| 133 | |
| 134 | // IFlowService methods |
| 135 | |
| 136 | |
| 137 | /** |
| 138 | * Test method for {@link FlowManager#addFlow(FlowPath, FlowId, String)}. |
| 139 | * @throws Exception |
| 140 | */ |
| 141 | @Test |
| 142 | public final void testAddFlowFailGraphCreatesNoFlow() throws Exception { |
| 143 | // instantiate required objects |
| 144 | FlowId flowId = new FlowId(123); |
| 145 | FlowPath flowPath = new FlowPath(); |
| 146 | flowPath.setFlowId(flowId); |
Toshio Koide | ca7abe0 | 2013-06-27 17:30:17 -0700 | [diff] [blame] | 147 | FlowManager fm = new FlowManager(); |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 148 | |
| 149 | // setup expectations |
| 150 | expectInitWithContext(); |
| 151 | expect(op.searchFlowPath(flowId)).andReturn(null); |
| 152 | expect(op.newFlowPath()).andReturn(null); |
| 153 | op.rollback(); |
| 154 | |
| 155 | // start the test |
| 156 | replayAll(); |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 157 | |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 158 | fm.init(context); |
| 159 | Boolean result = fm.addFlow(flowPath, flowId, ""); |
| 160 | |
| 161 | // verify the test |
| 162 | verifyAll(); |
| 163 | assertFalse(result); |
| 164 | } |
| 165 | |
| 166 | /** |
| 167 | * Test method for {@link FlowManager#addFlow(FlowPath, FlowId, String)}. |
| 168 | * @throws Exception |
| 169 | */ |
| 170 | @Test |
| 171 | public final void testAddFlowSuccessNormally() throws Exception { |
| 172 | final String addFlowEntry = "addFlowEntry"; |
| 173 | // create mock objects |
| 174 | IFlowPath createdFlowPath = createNiceMock(IFlowPath.class); |
| 175 | IFlowEntry createdFlowEntry1 = createNiceMock(IFlowEntry.class); |
| 176 | IFlowEntry createdFlowEntry2 = createNiceMock(IFlowEntry.class); |
| 177 | FlowManager fm = createPartialMockAndInvokeDefaultConstructor(FlowManager.class, addFlowEntry); |
| 178 | |
| 179 | // instantiate required objects |
| 180 | final FlowEntry flowEntry1 = new FlowEntry(); |
| 181 | final FlowEntry flowEntry2 = new FlowEntry(); |
| 182 | ArrayList<FlowEntry> flowEntries = new ArrayList<FlowEntry>(); |
| 183 | flowEntries.add(flowEntry1); |
| 184 | flowEntries.add(flowEntry2); |
| 185 | |
| 186 | DataPath dataPath = new DataPath(); |
| 187 | dataPath.setSrcPort(new SwitchPort(new Dpid(0x1234), new Port((short)1))); |
| 188 | dataPath.setDstPort(new SwitchPort(new Dpid(0x5678), new Port((short)2))); |
| 189 | dataPath.setFlowEntries(flowEntries); |
| 190 | |
| 191 | FlowEntryMatch match = new FlowEntryMatch(); |
| 192 | |
| 193 | FlowPath flowPath = new FlowPath(); |
| 194 | flowPath.setFlowId(new FlowId(0x100)); |
| 195 | flowPath.setInstallerId(new CallerId("installer id")); |
Pavlin Radoslavov | 204b286 | 2013-07-12 14:15:36 -0700 | [diff] [blame] | 196 | flowPath.setFlowPathFlags(new FlowPathFlags(0)); |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 197 | flowPath.setDataPath(dataPath); |
| 198 | flowPath.setFlowEntryMatch(match); |
| 199 | |
| 200 | // setup expectations |
| 201 | expectInitWithContext(); |
| 202 | expect(op.searchFlowPath(cmpEq(new FlowId(0x100)))).andReturn(null); |
| 203 | expect(op.newFlowPath()).andReturn(createdFlowPath); |
| 204 | createdFlowPath.setFlowId("0x100"); |
| 205 | createdFlowPath.setType("flow"); |
| 206 | createdFlowPath.setInstallerId("installer id"); |
Pavlin Radoslavov | 204b286 | 2013-07-12 14:15:36 -0700 | [diff] [blame] | 207 | createdFlowPath.setFlowPathFlags(new Long((long)0)); |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 208 | createdFlowPath.setSrcSwitch("00:00:00:00:00:00:12:34"); |
| 209 | createdFlowPath.setSrcPort(new Short((short)1)); |
| 210 | createdFlowPath.setDstSwitch("00:00:00:00:00:00:56:78"); |
| 211 | createdFlowPath.setDstPort(new Short((short)2)); |
| 212 | createdFlowPath.setDataPathSummary("data path summary"); |
| 213 | createdFlowPath.setUserState("FE_USER_ADD"); |
| 214 | |
| 215 | expectPrivate(fm, addFlowEntry, createdFlowPath, flowEntry1) |
| 216 | .andReturn(createdFlowEntry1); |
| 217 | expectPrivate(fm, addFlowEntry, createdFlowPath, flowEntry2) |
| 218 | .andReturn(createdFlowEntry2); |
| 219 | |
| 220 | op.commit(); |
| 221 | |
| 222 | // start the test |
| 223 | replayAll(); |
| 224 | |
| 225 | fm.init(context); |
| 226 | Boolean result = fm.addFlow(flowPath, new FlowId(0x100), "data path summary"); |
| 227 | |
| 228 | // verify the test |
| 229 | verifyAll(); |
| 230 | assertTrue(result); |
| 231 | } |
| 232 | |
| 233 | /** |
| 234 | * Test method for {@link FlowManager#deleteAllFlows()}. |
| 235 | * @throws Exception |
| 236 | */ |
| 237 | @Test |
| 238 | public final void testDeleteAllFlowsSuccessNormally() throws Exception { |
| 239 | // create mock objects |
| 240 | IFlowPath flowPath1 = createNiceMock(IFlowPath.class); |
| 241 | IFlowPath flowPath2 = createNiceMock(IFlowPath.class); |
| 242 | |
| 243 | // instantiate required objects |
| 244 | ArrayList<IFlowPath> flowPaths = new ArrayList<IFlowPath>(); |
| 245 | flowPaths.add(flowPath1); |
| 246 | flowPaths.add(flowPath2); |
Toshio Koide | ca7abe0 | 2013-06-27 17:30:17 -0700 | [diff] [blame] | 247 | FlowManager fm = new FlowManager(); |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 248 | |
| 249 | // setup expectations |
| 250 | expectInitWithContext(); |
| 251 | expect(op.getAllFlowPaths()).andReturn(flowPaths); |
| 252 | |
| 253 | expect(flowPath1.getFlowId()).andReturn("1").anyTimes(); |
| 254 | expect(op.searchFlowPath(cmpEq(new FlowId(1)))).andReturn(flowPath1); |
| 255 | expect(flowPath1.getFlowEntries()).andReturn(new ArrayList<IFlowEntry>()); |
| 256 | op.removeFlowPath(flowPath1); |
| 257 | |
| 258 | expect(flowPath2.getFlowId()).andReturn("2").anyTimes(); |
| 259 | expect(op.searchFlowPath(cmpEq(new FlowId(2)))).andReturn(flowPath2); |
| 260 | expect(flowPath2.getFlowEntries()).andReturn(new ArrayList<IFlowEntry>()); |
| 261 | op.removeFlowPath(flowPath2); |
| 262 | |
| 263 | op.commit(); |
| 264 | expectLastCall().anyTimes(); |
| 265 | |
| 266 | // start the test |
| 267 | replayAll(); |
| 268 | |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 269 | fm.init(context); |
| 270 | Boolean result = fm.deleteAllFlows(); |
| 271 | |
| 272 | // verify the test |
| 273 | verifyAll(); |
| 274 | assertTrue(result); |
| 275 | } |
| 276 | |
| 277 | /** |
| 278 | * Test method for {@link FlowManager#deleteFlow(FlowId)}. |
| 279 | * @throws Exception |
| 280 | */ |
| 281 | @Test |
| 282 | public final void testDeleteFlowSuccessEmptyFlowPath() throws Exception { |
Toshio Koide | ca7abe0 | 2013-06-27 17:30:17 -0700 | [diff] [blame] | 283 | // instantiate required objects |
| 284 | FlowManager fm = new FlowManager(); |
| 285 | |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 286 | // create mock objects |
| 287 | IFlowPath flowObj = createNiceMock(IFlowPath.class); |
| 288 | |
| 289 | // setup expectations |
| 290 | expectInitWithContext(); |
| 291 | expect(op.searchFlowPath(cmpEq(new FlowId(1)))).andReturn(flowObj); |
| 292 | expect(flowObj.getFlowEntries()).andReturn(new ArrayList<IFlowEntry>()); |
| 293 | op.removeFlowPath(flowObj); |
| 294 | op.commit(); |
| 295 | expectLastCall().anyTimes(); |
| 296 | |
| 297 | // start the test |
| 298 | replayAll(); |
| 299 | |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 300 | fm.init(context); |
| 301 | Boolean result = fm.deleteFlow(new FlowId(1)); |
| 302 | |
| 303 | // verify the test |
| 304 | verifyAll(); |
| 305 | assertTrue(result); |
| 306 | } |
| 307 | |
| 308 | /** |
| 309 | * Test method for {@link FlowManager#clearAllFlows()}. |
| 310 | * @throws Exception |
| 311 | */ |
| 312 | @Test |
| 313 | public final void testClearAllFlowsSuccessNormally() throws Exception { |
| 314 | // create mock objects |
| 315 | IFlowPath flowPath1 = createNiceMock(IFlowPath.class); |
| 316 | IFlowPath flowPath2 = createNiceMock(IFlowPath.class); |
| 317 | IFlowPath flowPath3 = createNiceMock(IFlowPath.class); |
| 318 | FlowManager fm = createPartialMockAndInvokeDefaultConstructor(FlowManager.class, "clearFlow"); |
| 319 | |
| 320 | // instantiate required objects |
| 321 | ArrayList<IFlowPath> flowPaths = new ArrayList<IFlowPath>(); |
| 322 | flowPaths.add(flowPath1); |
| 323 | flowPaths.add(flowPath2); |
| 324 | flowPaths.add(null); |
| 325 | flowPaths.add(flowPath3); |
| 326 | |
| 327 | // setup expectations |
| 328 | expectInitWithContext(); |
| 329 | expect(op.getAllFlowPaths()).andReturn(flowPaths); |
| 330 | expect(flowPath1.getFlowId()).andReturn(new FlowId(1).toString()); |
| 331 | expect(flowPath2.getFlowId()).andReturn(null); |
| 332 | expect(flowPath3.getFlowId()).andReturn(new FlowId(3).toString()); |
| 333 | expect(fm.clearFlow(cmpEq(new FlowId(1)))).andReturn(true); |
| 334 | expect(fm.clearFlow(cmpEq(new FlowId(3)))).andReturn(true); |
| 335 | |
| 336 | // start the test |
| 337 | replayAll(); |
| 338 | |
| 339 | fm.init(context); |
| 340 | Boolean result = fm.clearAllFlows(); |
| 341 | |
| 342 | //verify the test |
| 343 | verifyAll(); |
| 344 | assertTrue(result); |
| 345 | } |
| 346 | |
| 347 | /** |
| 348 | * Test method for {@link FlowManager#getFlow()}. |
| 349 | * @throws Exception |
| 350 | */ |
| 351 | @Test |
| 352 | public final void testGetFlowSuccessNormally() throws Exception { |
| 353 | // instantiate required objects |
| 354 | FlowManager fm = new FlowManager(); |
Pavlin Radoslavov | 204b286 | 2013-07-12 14:15:36 -0700 | [diff] [blame] | 355 | IFlowPath iFlowPath = createIFlowPathMock(1, "caller id", 0, 1, 1, 2, 2); |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 356 | |
| 357 | // setup expectations |
| 358 | expectInitWithContext(); |
Toshio Koide | ca7abe0 | 2013-06-27 17:30:17 -0700 | [diff] [blame] | 359 | expect(op.searchFlowPath(cmpEq(new FlowId(1)))).andReturn(iFlowPath); |
| 360 | expect(iFlowPath.getFlowEntries()).andReturn(new ArrayList<IFlowEntry>()).anyTimes(); |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 361 | op.commit(); |
| 362 | |
| 363 | // start the test |
| 364 | replayAll(); |
| 365 | |
| 366 | fm.init(context); |
Pavlin Radoslavov | 204b286 | 2013-07-12 14:15:36 -0700 | [diff] [blame] | 367 | FlowPath flowPath = fm.getFlow(new FlowId(1)); |
| 368 | String installerId = flowPath.installerId().toString(); |
| 369 | long flowPathFlags = flowPath.flowPathFlags().flags(); |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 370 | |
| 371 | //verify the test |
| 372 | verifyAll(); |
Pavlin Radoslavov | 204b286 | 2013-07-12 14:15:36 -0700 | [diff] [blame] | 373 | assertEquals("caller id", installerId); |
| 374 | assertEquals(0L, flowPathFlags); |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 375 | } |
| 376 | |
| 377 | /** |
| 378 | * Test method for {@link FlowManager#getAllFlows(CallerId, DataPathEndpoints)}. |
| 379 | * @throws Exception |
| 380 | */ |
| 381 | @Test |
| 382 | public final void testGetAllFlowsWithCallerIdAndDataPathEndpointsSuccessNormally() throws Exception { |
| 383 | final String getAllFlows = "getAllFlows"; |
| 384 | // create mock objects |
| 385 | FlowManager fm = createPartialMock(FlowManager.class, getAllFlows, |
| 386 | new Class<?>[]{}, new Object[]{}); |
| 387 | |
| 388 | // instantiate required objects |
| 389 | DataPathEndpoints dataPathEndpoints = new DataPathEndpoints( |
| 390 | new SwitchPort(new Dpid(1), new Port((short)1)), |
| 391 | new SwitchPort(new Dpid(2), new Port((short)2))); |
| 392 | |
| 393 | ArrayList<FlowPath> obtainedAllFlows = createTestFlowPaths(); |
| 394 | |
| 395 | //setup expectations |
| 396 | expectInitWithContext(); |
| 397 | expectPrivate(fm, getAllFlows).andReturn(obtainedAllFlows); |
| 398 | |
| 399 | //start the test |
| 400 | replayAll(); |
| 401 | |
| 402 | fm.init(context); |
| 403 | ArrayList<FlowPath> flows = fm.getAllFlows(new CallerId("caller id"), dataPathEndpoints); |
| 404 | |
| 405 | // verify the test |
| 406 | verifyAll(); |
| 407 | assertEquals(1, flows.size()); |
| 408 | assertEquals(obtainedAllFlows.get(1), flows.get(0)); |
| 409 | } |
| 410 | |
| 411 | /** |
| 412 | * Test method for {@link FlowManager#getAllFlows(DataPathEndpoints)}. |
| 413 | * @throws Exception |
| 414 | */ |
| 415 | @Test |
| 416 | public final void testGetAllFlowsWithDataPathEndpointsSuccessNormally() throws Exception { |
| 417 | final String getAllFlows = "getAllFlows"; |
| 418 | // create mock objects |
| 419 | FlowManager fm = createPartialMock(FlowManager.class, getAllFlows, |
| 420 | new Class<?>[]{}, new Object[]{}); |
| 421 | |
| 422 | // instantiate required objects |
| 423 | DataPathEndpoints dataPathEndpoints = new DataPathEndpoints( |
| 424 | new SwitchPort(new Dpid(1), new Port((short)1)), |
| 425 | new SwitchPort(new Dpid(2), new Port((short)2))); |
| 426 | |
| 427 | ArrayList<FlowPath> obtainedAllFlows = createTestFlowPaths(); |
| 428 | |
| 429 | //setup expectations |
| 430 | expectInitWithContext(); |
| 431 | expectPrivate(fm, getAllFlows).andReturn(obtainedAllFlows); |
| 432 | |
| 433 | //start the test |
| 434 | replayAll(); |
| 435 | |
| 436 | fm.init(context); |
| 437 | ArrayList<FlowPath> flows = fm.getAllFlows(dataPathEndpoints); |
| 438 | |
| 439 | // verify the test |
| 440 | verifyAll(); |
| 441 | assertEquals(2, flows.size()); |
| 442 | assertEquals(obtainedAllFlows.get(0), flows.get(0)); |
| 443 | assertEquals(obtainedAllFlows.get(1), flows.get(1)); |
| 444 | // TODO: ignore the order of flows in the list |
| 445 | } |
| 446 | |
| 447 | /** |
| 448 | * Test method for {@link FlowManager#getAllFlowsSummary(FlowId, int)}. |
| 449 | * @throws Exception |
| 450 | */ |
| 451 | @Test |
| 452 | public final void testGetAllFlowsSummarySuccessNormally() throws Exception { |
| 453 | final String getAllFlowsWithoutFlowEntries = "getAllFlowsWithoutFlowEntries"; |
| 454 | // create mock objects |
| 455 | FlowManager fm = createPartialMockAndInvokeDefaultConstructor(FlowManager.class, getAllFlowsWithoutFlowEntries); |
Pavlin Radoslavov | 204b286 | 2013-07-12 14:15:36 -0700 | [diff] [blame] | 456 | IFlowPath flowPath1 = createIFlowPathMock(1, "", 0, 1, 2, 3, 4); |
| 457 | IFlowPath flowPath2 = createIFlowPathMock(5, "", 0, 2, 3, 4, 5); |
| 458 | IFlowPath flowPath3 = createIFlowPathMock(10, "", 0, 3, 4, 5, 6); |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 459 | |
| 460 | // instantiate required objects |
| 461 | ArrayList<IFlowPath> flows = new ArrayList<IFlowPath>(); |
| 462 | flows.add(flowPath3); |
| 463 | flows.add(flowPath1); |
| 464 | flows.add(flowPath2); |
| 465 | |
| 466 | // setup expectations |
| 467 | expectInitWithContext(); |
| 468 | expectPrivate(fm, getAllFlowsWithoutFlowEntries).andReturn(flows); |
| 469 | |
| 470 | // start the test |
| 471 | replayAll(); |
| 472 | |
| 473 | fm.init(context); |
| 474 | ArrayList<IFlowPath> returnedFlows = fm.getAllFlowsSummary(null, 0); |
| 475 | |
| 476 | // verify the test |
| 477 | verifyAll(); |
| 478 | assertEquals(3, returnedFlows.size()); |
| 479 | assertEquals(1, new FlowId(returnedFlows.get(0).getFlowId()).value()); |
| 480 | assertEquals(5, new FlowId(returnedFlows.get(1).getFlowId()).value()); |
| 481 | assertEquals(10, new FlowId(returnedFlows.get(2).getFlowId()).value()); |
| 482 | } |
| 483 | |
| 484 | /** |
| 485 | * Test method for {@link FlowManager#getAllFlows()}. |
| 486 | * @throws Exception |
| 487 | */ |
| 488 | @Test |
| 489 | public final void testGetAllFlowsSuccessNormally() throws Exception { |
Toshio Koide | ca7abe0 | 2013-06-27 17:30:17 -0700 | [diff] [blame] | 490 | // create mock objects |
Pavlin Radoslavov | 204b286 | 2013-07-12 14:15:36 -0700 | [diff] [blame] | 491 | IFlowPath iFlowPath1 = createIFlowPathMock(1, "caller id", 0, 1, 1, 2, 2); |
| 492 | IFlowPath iFlowPath2 = createIFlowPathMock(2, "caller id", 0, 2, 5, 3, 5); |
Toshio Koide | ca7abe0 | 2013-06-27 17:30:17 -0700 | [diff] [blame] | 493 | |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 494 | // instantiate required objects |
| 495 | ArrayList<IFlowPath> flowPaths = new ArrayList<IFlowPath>(); |
Toshio Koide | ca7abe0 | 2013-06-27 17:30:17 -0700 | [diff] [blame] | 496 | flowPaths.add(iFlowPath1); |
| 497 | flowPaths.add(iFlowPath2); |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 498 | FlowManager fm = new FlowManager(); |
| 499 | |
| 500 | // setup expectations |
| 501 | expectInitWithContext(); |
| 502 | expect(op.getAllFlowPaths()).andReturn(flowPaths); |
Toshio Koide | ca7abe0 | 2013-06-27 17:30:17 -0700 | [diff] [blame] | 503 | expect(iFlowPath1.getFlowEntries()).andReturn(new ArrayList<IFlowEntry>()).anyTimes(); |
| 504 | expect(iFlowPath2.getFlowEntries()).andReturn(new ArrayList<IFlowEntry>()).anyTimes(); |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 505 | op.commit(); |
| 506 | |
| 507 | // start the test |
| 508 | replayAll(); |
| 509 | |
| 510 | fm.init(context); |
| 511 | ArrayList<FlowPath> flows = fm.getAllFlows(); |
| 512 | |
| 513 | // verify the test |
| 514 | verifyAll(); |
| 515 | assertEquals(2, flows.size()); |
| 516 | assertEquals(new SwitchPort(new Dpid(1), new Port((short)1)).toString(), |
| 517 | flows.get(0).dataPath().srcPort().toString()); |
| 518 | assertEquals(new SwitchPort(new Dpid(2), new Port((short)5)).toString(), |
| 519 | flows.get(1).dataPath().srcPort().toString()); |
| 520 | // TODO: more asserts |
| 521 | // TODO: ignore seq. of the list |
| 522 | } |
| 523 | |
| 524 | /** |
| 525 | * Test method for {@link FlowManager#addAndMaintainShortestPathFlow(FlowPath)}. |
| 526 | * @throws Exception |
| 527 | */ |
| 528 | @Test |
| 529 | public final void testAddAndMaintainShortestPathFlowSuccessNormally() throws Exception { |
| 530 | final String addFlow = "addFlow"; |
| 531 | |
| 532 | // create mock objects |
| 533 | FlowManager fm = createPartialMockAndInvokeDefaultConstructor(FlowManager.class, addFlow); |
| 534 | |
| 535 | // instantiate required objects |
| 536 | DataPath dataPath = new DataPath(); |
| 537 | dataPath.setSrcPort(new SwitchPort(new Dpid(1), new Port((short)3))); |
| 538 | dataPath.setDstPort(new SwitchPort(new Dpid(2), new Port((short)4))); |
| 539 | FlowEntryMatch match = new FlowEntryMatch(); |
| 540 | FlowPath paramFlow = new FlowPath(); |
| 541 | paramFlow.setFlowId(new FlowId(100)); |
| 542 | paramFlow.setInstallerId(new CallerId("installer id")); |
Pavlin Radoslavov | 204b286 | 2013-07-12 14:15:36 -0700 | [diff] [blame] | 543 | paramFlow.setFlowPathFlags(new FlowPathFlags(0)); |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 544 | paramFlow.setDataPath(dataPath); |
| 545 | paramFlow.setFlowEntryMatch(match); |
| 546 | |
| 547 | // setup expectations |
| 548 | expectInitWithContext(); |
| 549 | expectPrivate(fm, addFlow, |
| 550 | EasyMock.anyObject(FlowPath.class), |
| 551 | EasyMock.anyObject(FlowId.class), |
| 552 | EasyMock.anyObject(String.class) |
| 553 | ).andAnswer(new IAnswer<Object>() { |
| 554 | public Object answer() throws Exception { |
| 555 | FlowPath flowPath = (FlowPath)EasyMock.getCurrentArguments()[0]; |
| 556 | assertEquals(flowPath.flowId().value(), 100); |
| 557 | assertEquals(flowPath.installerId().toString(), "installer id"); |
Pavlin Radoslavov | 204b286 | 2013-07-12 14:15:36 -0700 | [diff] [blame] | 558 | assertEquals(flowPath.flowPathFlags().flags(), 0); |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 559 | assertEquals(flowPath.dataPath().srcPort().toString(), |
| 560 | new SwitchPort(new Dpid(1), new Port((short)3)).toString()); |
| 561 | |
| 562 | String dataPathSummary = (String)EasyMock.getCurrentArguments()[2]; |
| 563 | assertEquals(dataPathSummary, "X"); |
| 564 | |
| 565 | return true; |
| 566 | } |
| 567 | }); |
| 568 | |
| 569 | // start the test |
| 570 | replayAll(); |
| 571 | |
| 572 | fm.init(context); |
| 573 | FlowPath resultFlow = fm.addAndMaintainShortestPathFlow(paramFlow); |
| 574 | |
| 575 | // verify the test |
| 576 | verifyAll(); |
| 577 | assertEquals(paramFlow.flowId().value(), resultFlow.flowId().value()); |
| 578 | assertEquals(paramFlow.installerId().toString(), resultFlow.installerId().toString()); |
Pavlin Radoslavov | 204b286 | 2013-07-12 14:15:36 -0700 | [diff] [blame] | 579 | assertEquals(paramFlow.flowPathFlags().flags(), resultFlow.flowPathFlags().flags()); |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 580 | assertEquals(paramFlow.dataPath().toString(), resultFlow.dataPath().toString()); |
| 581 | assertEquals(paramFlow.flowEntryMatch().toString(), resultFlow.flowEntryMatch().toString()); |
| 582 | } |
| 583 | |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 584 | // INetMapStorage methods |
| 585 | |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 586 | /** |
| 587 | * Test method for {@link FlowManager#init(String)}. |
| 588 | * @throws Exception |
| 589 | */ |
| 590 | @Test |
| 591 | public final void testInitSuccessNormally() throws Exception { |
Toshio Koide | ca7abe0 | 2013-06-27 17:30:17 -0700 | [diff] [blame] | 592 | // instantiate required objects |
| 593 | FlowManager fm = new FlowManager(); |
| 594 | |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 595 | // create mock objects |
| 596 | op = createMock(GraphDBOperation.class); |
| 597 | |
| 598 | // setup expectations |
| 599 | expectNew(GraphDBOperation.class, "/dummy/path").andReturn(op); |
| 600 | |
| 601 | // start the test |
| 602 | replayAll(); |
| 603 | |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 604 | fm.init("/dummy/path"); |
| 605 | |
| 606 | // verify the test |
| 607 | verifyAll(); |
| 608 | } |
| 609 | |
| 610 | /** |
| 611 | * Test method for {@link FlowManager#close()}. |
| 612 | * @throws Exception |
| 613 | */ |
| 614 | @Test |
| 615 | public final void testCloseSuccessNormally() throws Exception { |
| 616 | // instantiate required objects |
| 617 | FlowManager fm = new FlowManager(); |
| 618 | |
| 619 | // setup expectations |
| 620 | expectInitWithContext(); |
| 621 | op.close(); |
| 622 | |
| 623 | // start the test |
| 624 | replayAll(); |
| 625 | |
| 626 | fm.init(context); |
| 627 | fm.close(); |
| 628 | |
| 629 | // verify the test |
| 630 | verifyAll(); |
| 631 | } |
| 632 | |
| 633 | |
| 634 | // IFloodlightModule methods |
| 635 | |
| 636 | |
| 637 | /** |
| 638 | * Test method for {@link FlowManager#getModuleServices()}. |
| 639 | * @throws Exception |
| 640 | */ |
| 641 | @Test |
| 642 | public final void testGetModuleServicesSuccessNormally() throws Exception { |
| 643 | // instantiate required objects |
| 644 | FlowManager fm = new FlowManager(); |
| 645 | |
| 646 | // setup expectations |
| 647 | expectInitWithContext(); |
| 648 | |
| 649 | // start the test |
| 650 | replayAll(); |
| 651 | |
| 652 | fm.init(context); |
| 653 | Collection<Class<? extends IFloodlightService>> l = fm.getModuleServices(); |
| 654 | |
| 655 | // verify the test |
| 656 | verifyAll(); |
| 657 | assertEquals(1, l.size()); |
| 658 | assertEquals(IFlowService.class, l.iterator().next()); |
| 659 | } |
| 660 | |
| 661 | /** |
| 662 | * Test method for {@link FlowManager#getServiceImpls()}. |
| 663 | * @throws Exception |
| 664 | */ |
| 665 | @Test |
| 666 | public final void testGetServiceImplsSuccessNormally() throws Exception { |
| 667 | // instantiate required objects |
| 668 | FlowManager fm = new FlowManager(); |
| 669 | |
| 670 | // setup expectations |
| 671 | expectInitWithContext(); |
| 672 | |
| 673 | // start the test |
| 674 | replayAll(); |
| 675 | |
| 676 | fm.init(context); |
| 677 | Map<Class<? extends IFloodlightService>, IFloodlightService> si = fm.getServiceImpls(); |
| 678 | |
| 679 | // verify the test |
| 680 | verifyAll(); |
| 681 | assertEquals(1, si.size()); |
| 682 | assertTrue(si.containsKey(IFlowService.class)); |
| 683 | assertEquals(fm, si.get(IFlowService.class)); |
| 684 | } |
| 685 | |
| 686 | /** |
| 687 | * Test method for {@link FlowManager#getModuleDependencies()}. |
| 688 | * @throws Exception |
| 689 | */ |
| 690 | @Test |
| 691 | public final void testGetModuleDependenciesSuccessNormally() throws Exception { |
| 692 | // instantiate required objects |
| 693 | FlowManager fm = new FlowManager(); |
| 694 | |
| 695 | // setup expectations |
| 696 | expectInitWithContext(); |
| 697 | |
| 698 | // start the test |
| 699 | replayAll(); |
| 700 | |
| 701 | fm.init(context); |
| 702 | Collection<Class<? extends IFloodlightService>> md = fm.getModuleDependencies(); |
| 703 | |
| 704 | // verify the test |
| 705 | verifyAll(); |
Pavlin Radoslavov | 0537827 | 2013-10-19 23:23:05 -0700 | [diff] [blame] | 706 | assertEquals(4, md.size()); |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 707 | assertTrue(md.contains(IFloodlightProviderService.class)); |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 708 | assertTrue(md.contains(IRestApiService.class)); |
| 709 | } |
| 710 | |
| 711 | /** |
| 712 | * Test method for {@link FlowManager#init(FloodlightModuleContext)}. |
| 713 | * @throws Exception |
| 714 | */ |
| 715 | @Test |
| 716 | public final void testInitWithFloodlightModuleContextSuccessNormally() throws Exception { |
| 717 | // instantiate required objects |
| 718 | FlowManager fm = new FlowManager(); |
| 719 | |
| 720 | // setup expectations |
| 721 | expectInitWithContext(); |
| 722 | |
| 723 | // start the test |
| 724 | replayAll(); |
| 725 | |
| 726 | fm.init(context); |
| 727 | |
| 728 | // verify the test |
| 729 | verifyAll(); |
| 730 | } |
| 731 | |
| 732 | /** |
| 733 | * Test method for {@link FlowManager#startUp(FloodlightModuleContext)}. |
| 734 | * @throws Exception |
| 735 | */ |
| 736 | @Test |
| 737 | public final void testStartupSuccessNormally() throws Exception { |
| 738 | // create mock objects |
| 739 | mockStaticPartial(Executors.class, "newScheduledThreadPool"); |
| 740 | ScheduledExecutorService scheduler = createMock(ScheduledExecutorService.class); |
| 741 | |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 742 | // instantiate required objects |
| 743 | FlowManager fm = new FlowManager(); |
| 744 | |
| 745 | // setup expectations |
| 746 | expectInitWithContext(); |
| 747 | expect(Executors.newScheduledThreadPool(1)).andReturn(scheduler); |
| 748 | expect(Executors.newScheduledThreadPool(1)).andReturn(scheduler); |
| 749 | expect(scheduler.scheduleAtFixedRate( |
| 750 | EasyMock.anyObject(Runnable.class), |
| 751 | EasyMock.anyLong(), |
| 752 | EasyMock.anyLong(), |
| 753 | EasyMock.anyObject(TimeUnit.class))).andReturn(null).times(2); |
| 754 | restApi.addRestletRoutable(EasyMock.anyObject(FlowWebRoutable.class)); |
| 755 | |
| 756 | // start the test |
| 757 | replayAll(); |
| 758 | |
| 759 | fm.init(context); |
| 760 | fm.startUp(context); |
| 761 | |
| 762 | // verify the test |
| 763 | verifyAll(); |
| 764 | } |
Toshio Koide | ca7abe0 | 2013-06-27 17:30:17 -0700 | [diff] [blame] | 765 | |
| 766 | |
| 767 | // other methods |
| 768 | |
| 769 | |
| 770 | /** |
| 771 | * Test method for {@link FlowManager#clearFlow(FlowId)}. |
| 772 | * @throws Exception |
| 773 | */ |
| 774 | @Test |
| 775 | public final void testClearFlowSuccessNormally() throws Exception { |
| 776 | // create mock objects |
Pavlin Radoslavov | 204b286 | 2013-07-12 14:15:36 -0700 | [diff] [blame] | 777 | IFlowPath flowPath = createIFlowPathMock(123, "id", 0, 1, 2, 3, 4); |
Toshio Koide | ca7abe0 | 2013-06-27 17:30:17 -0700 | [diff] [blame] | 778 | IFlowEntry flowEntry1 = createMock(IFlowEntry.class); |
| 779 | IFlowEntry flowEntry2 = createMock(IFlowEntry.class); |
| 780 | IFlowEntry flowEntry3 = createMock(IFlowEntry.class); |
| 781 | |
| 782 | // instantiate required objects |
| 783 | FlowManager fm = new FlowManager(); |
| 784 | FlowId flowId = new FlowId(123); |
| 785 | ArrayList<IFlowEntry> flowEntries = new ArrayList<IFlowEntry>(); |
| 786 | flowEntries.add(flowEntry1); |
| 787 | flowEntries.add(flowEntry2); |
| 788 | flowEntries.add(flowEntry3); |
| 789 | |
| 790 | // setup expectations |
| 791 | expectInitWithContext(); |
| 792 | expect(op.searchFlowPath(cmpEq(flowId))).andReturn(flowPath); |
| 793 | expect(flowPath.getFlowEntries()).andReturn(flowEntries); |
| 794 | flowPath.removeFlowEntry(flowEntry1); |
| 795 | flowPath.removeFlowEntry(flowEntry2); |
| 796 | flowPath.removeFlowEntry(flowEntry3); |
| 797 | op.removeFlowEntry(flowEntry1); |
| 798 | op.removeFlowEntry(flowEntry2); |
| 799 | op.removeFlowEntry(flowEntry3); |
| 800 | op.removeFlowPath(flowPath); |
| 801 | op.commit(); |
| 802 | |
| 803 | // start the test |
| 804 | replayAll(); |
| 805 | |
| 806 | fm.init(context); |
| 807 | fm.clearFlow(flowId); |
| 808 | |
| 809 | // verify the test |
| 810 | verifyAll(); |
| 811 | } |
| 812 | |
| 813 | /** |
| 814 | * Test method for {@link FlowManager#getAllFlowsWithoutFlowEntries()}. |
| 815 | * @throws Exception |
| 816 | */ |
| 817 | @Test |
| 818 | public final void testGetAllFlowsWithoutFlowEntriesSuccessNormally() throws Exception { |
| 819 | // create mock objects |
Pavlin Radoslavov | 204b286 | 2013-07-12 14:15:36 -0700 | [diff] [blame] | 820 | IFlowPath iFlowPath1 = createIFlowPathMock(1, "caller id", 0, 1, 1, 2, 2); |
| 821 | IFlowPath iFlowPath2 = createIFlowPathMock(2, "caller id", 0, 2, 5, 3, 5); |
Toshio Koide | ca7abe0 | 2013-06-27 17:30:17 -0700 | [diff] [blame] | 822 | |
| 823 | // instantiate required objects |
| 824 | ArrayList<IFlowPath> flowPaths = new ArrayList<IFlowPath>(); |
| 825 | flowPaths.add(iFlowPath1); |
| 826 | flowPaths.add(iFlowPath2); |
| 827 | FlowManager fm = new FlowManager(); |
| 828 | |
| 829 | // setup expectations |
| 830 | expectInitWithContext(); |
| 831 | op.commit(); |
| 832 | expect(op.getAllFlowPaths()).andReturn(flowPaths); |
| 833 | |
| 834 | // start the test |
| 835 | replayAll(); |
| 836 | |
| 837 | fm.init(context); |
| 838 | ArrayList<IFlowPath> result = fm.getAllFlowsWithoutFlowEntries(); |
| 839 | |
| 840 | // verify the test |
| 841 | verifyAll(); |
| 842 | assertEquals(iFlowPath1, result.get(0)); |
| 843 | assertEquals(iFlowPath2, result.get(1)); |
| 844 | |
| 845 | // TODO: does this method just return the replica of the flow paths? |
| 846 | } |
| 847 | |
| 848 | /** |
| 849 | * Test method for {@link FlowManager#reconcileFlow(IFlowPath, DataPath)}. |
| 850 | * @throws Exception |
| 851 | */ |
| 852 | @Test |
| 853 | public final void testReconcileFlowWithFlowPathAndDataPathSuccessNormally() throws Exception { |
| 854 | final String addFlowEntry = "addFlowEntry"; |
| 855 | |
| 856 | // create mock objects |
Pavlin Radoslavov | 204b286 | 2013-07-12 14:15:36 -0700 | [diff] [blame] | 857 | IFlowPath iFlowPath1 = createIFlowPathMock(1, "caller id", 0, 1, 1, 2, 2); |
Toshio Koide | ca7abe0 | 2013-06-27 17:30:17 -0700 | [diff] [blame] | 858 | IFlowEntry iFlowEntry1 = createMock(IFlowEntry.class); |
| 859 | IFlowEntry iFlowEntry2 = createMock(IFlowEntry.class); |
| 860 | FlowManager fm = createPartialMockAndInvokeDefaultConstructor(FlowManager.class, addFlowEntry); |
| 861 | |
| 862 | // instantiate required objects |
| 863 | FlowEntry flowEntry1 = new FlowEntry(); |
| 864 | flowEntry1.setDpid(new Dpid(1)); |
| 865 | flowEntry1.setFlowId(new FlowId(1)); |
| 866 | flowEntry1.setInPort(new Port((short) 1)); |
| 867 | flowEntry1.setOutPort(new Port((short) 11)); |
| 868 | flowEntry1.setFlowEntryId(new FlowEntryId(1)); |
| 869 | flowEntry1.setFlowEntryMatch(new FlowEntryMatch()); |
Pavlin Radoslavov | 1bc2c47 | 2013-07-17 18:11:37 -0700 | [diff] [blame] | 870 | flowEntry1.setFlowEntryActions(new FlowEntryActions()); |
Toshio Koide | ca7abe0 | 2013-06-27 17:30:17 -0700 | [diff] [blame] | 871 | flowEntry1.setFlowEntryErrorState(new FlowEntryErrorState()); |
| 872 | |
| 873 | FlowEntry flowEntry2 = new FlowEntry(); |
| 874 | flowEntry2.setDpid(new Dpid(2)); |
| 875 | flowEntry2.setFlowId(new FlowId(2)); |
| 876 | flowEntry2.setInPort(new Port((short) 22)); |
| 877 | flowEntry2.setOutPort(new Port((short) 2)); |
| 878 | flowEntry2.setFlowEntryId(new FlowEntryId(2)); |
| 879 | flowEntry2.setFlowEntryMatch(new FlowEntryMatch()); |
Pavlin Radoslavov | 1bc2c47 | 2013-07-17 18:11:37 -0700 | [diff] [blame] | 880 | flowEntry2.setFlowEntryActions(new FlowEntryActions()); |
Toshio Koide | ca7abe0 | 2013-06-27 17:30:17 -0700 | [diff] [blame] | 881 | flowEntry2.setFlowEntryErrorState(new FlowEntryErrorState()); |
| 882 | |
| 883 | DataPath dataPath = new DataPath(); |
| 884 | ArrayList<FlowEntry> flowEntries = new ArrayList<FlowEntry>(); |
| 885 | flowEntries.add(flowEntry1); |
| 886 | flowEntries.add(flowEntry2); |
| 887 | dataPath.setFlowEntries(flowEntries); |
| 888 | |
| 889 | ArrayList<IFlowEntry> oldFlowEntries = new ArrayList<IFlowEntry>(); |
| 890 | oldFlowEntries.add(iFlowEntry1); |
| 891 | oldFlowEntries.add(iFlowEntry2); |
| 892 | |
| 893 | // setup expectations |
| 894 | expectInitWithContext(); |
Toshio Koide | ca7abe0 | 2013-06-27 17:30:17 -0700 | [diff] [blame] | 895 | expect(iFlowPath1.getFlowEntries()).andReturn(oldFlowEntries); |
| 896 | iFlowEntry1.setUserState("FE_USER_DELETE"); |
| 897 | iFlowEntry1.setSwitchState("FE_SWITCH_NOT_UPDATED"); |
| 898 | iFlowEntry2.setUserState("FE_USER_DELETE"); |
| 899 | iFlowEntry2.setSwitchState("FE_SWITCH_NOT_UPDATED"); |
| 900 | expectPrivate(fm, addFlowEntry, iFlowPath1, flowEntry1).andReturn(null); |
| 901 | expectPrivate(fm, addFlowEntry, iFlowPath1, flowEntry2).andReturn(null); |
| 902 | |
| 903 | // start the test |
| 904 | replayAll(); |
| 905 | |
| 906 | fm.init(context); |
| 907 | Boolean result = fm.reconcileFlow(iFlowPath1, dataPath); |
| 908 | |
| 909 | // verify the test |
| 910 | verifyAll(); |
| 911 | assertTrue(result); |
| 912 | // TODO: write more asserts |
| 913 | } |
| 914 | |
| 915 | /** |
| 916 | * Test method for {@link FlowManager#installFlowEntry(net.floodlightcontroller.core.IOFSwitch, IFlowPath, IFlowEntry)}. |
| 917 | * @throws Exception |
| 918 | */ |
| 919 | @Test |
| 920 | public final void testInstallFlowEntryWithIFlowPathSuccessNormally() throws Exception { |
| 921 | // create mock object |
| 922 | IOFSwitch iofSwitch = createNiceMock(IOFSwitch.class); |
Pavlin Radoslavov | 204b286 | 2013-07-12 14:15:36 -0700 | [diff] [blame] | 923 | IFlowPath iFlowPath = createIFlowPathMock(1, "id", 0, 1, 2, 3, 4); |
Toshio Koide | ca7abe0 | 2013-06-27 17:30:17 -0700 | [diff] [blame] | 924 | IFlowEntry iFlowEntry = createMock(IFlowEntry.class); |
| 925 | BasicFactory basicFactory = createMock(BasicFactory.class); |
| 926 | |
| 927 | // instantiate required objects |
| 928 | FlowManager fm = new FlowManager(); |
| 929 | |
Pavlin Radoslavov | 1bc2c47 | 2013-07-17 18:11:37 -0700 | [diff] [blame] | 930 | FlowEntryAction action = new FlowEntryAction(); |
| 931 | action.setActionOutput(new Port((short)2)); |
| 932 | FlowEntryActions actions = new FlowEntryActions(); |
| 933 | actions.addAction(action); |
| 934 | |
Toshio Koide | ca7abe0 | 2013-06-27 17:30:17 -0700 | [diff] [blame] | 935 | // setup expectations |
| 936 | expectInitWithContext(); |
| 937 | expect(iFlowEntry.getFlowEntryId()).andReturn(new FlowEntryId(123).toString()); |
| 938 | expect(iFlowEntry.getUserState()).andReturn("FE_USER_ADD"); |
| 939 | iFlowEntry.setSwitchState("FE_SWITCH_UPDATED"); |
| 940 | expect(iFlowEntry.getMatchInPort()).andReturn(new Short((short) 1)); |
Toshio Koide | ca7abe0 | 2013-06-27 17:30:17 -0700 | [diff] [blame] | 941 | expect(iFlowEntry.getMatchSrcMac()).andReturn("01:23:45:67:89:01"); |
| 942 | expect(iFlowEntry.getMatchDstMac()).andReturn("01:23:45:67:89:02"); |
Pavlin Radoslavov | ad3a1e6 | 2013-07-09 13:30:16 -0700 | [diff] [blame] | 943 | expect(iFlowEntry.getMatchEthernetFrameType()).andReturn(new Short((short)0x0800)); |
| 944 | expect(iFlowEntry.getMatchVlanId()).andReturn(new Short((short)0x1234)); |
| 945 | expect(iFlowEntry.getMatchVlanPriority()).andReturn(new Byte((byte)0x10)); |
| 946 | expect(iFlowEntry.getMatchSrcIPv4Net()).andReturn("192.168.0.1"); |
| 947 | expect(iFlowEntry.getMatchDstIPv4Net()).andReturn("192.168.0.2"); |
| 948 | expect(iFlowEntry.getMatchIpProto()).andReturn(new Byte((byte)0x20)); |
| 949 | expect(iFlowEntry.getMatchIpToS()).andReturn(new Byte((byte)0x3)); |
| 950 | expect(iFlowEntry.getMatchSrcTcpUdpPort()).andReturn(new Short((short)40000)); |
| 951 | expect(iFlowEntry.getMatchDstTcpUdpPort()).andReturn(new Short((short)80)); |
Pavlin Radoslavov | 1bc2c47 | 2013-07-17 18:11:37 -0700 | [diff] [blame] | 952 | expect(iFlowEntry.getActions()).andReturn(actions.toString()); |
Toshio Koide | ca7abe0 | 2013-06-27 17:30:17 -0700 | [diff] [blame] | 953 | expect(floodlightProvider.getOFMessageFactory()).andReturn(basicFactory); |
| 954 | expect(basicFactory.getMessage(OFType.FLOW_MOD)).andReturn(new OFFlowMod()); |
| 955 | expect(iofSwitch.getStringId()).andReturn(new Dpid(100).toString()); |
| 956 | |
| 957 | // start the test |
| 958 | replayAll(); |
| 959 | |
| 960 | fm.init(context); |
| 961 | Boolean result = fm.installFlowEntry(iofSwitch, iFlowPath, iFlowEntry); |
| 962 | |
| 963 | // verify the test |
| 964 | verifyAll(); |
| 965 | assertTrue(result); |
| 966 | // TODO: write more asserts |
| 967 | } |
| 968 | |
| 969 | /** |
| 970 | * Test method for {@link FlowManager#installFlowEntry(net.floodlightcontroller.core.IOFSwitch, FlowPath, FlowEntry)}. |
| 971 | * The method seems to be not used for now. |
| 972 | */ |
| 973 | @Ignore @Test |
| 974 | public final void testInstallFlowEntryWithFlowPathSuccessNormally() { |
| 975 | fail("not yet implemented"); |
| 976 | } |
| 977 | |
| 978 | /** |
| 979 | * Test method for {@link FlowManager#removeFlowEntry(net.floodlightcontroller.core.IOFSwitch, FlowPath, FlowEntry)}. |
| 980 | * The method seems to be not implemented and not used for now. |
| 981 | */ |
| 982 | @Ignore @Test |
| 983 | public final void testRemoveFlowEntrySuccessNormally() { |
| 984 | fail("not yet implemented"); |
| 985 | } |
Pavlin Radoslavov | ddd01ba | 2013-07-03 15:40:44 -0700 | [diff] [blame] | 986 | } |