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; |
| 18 | import net.onrc.onos.graph.GraphDBOperation; |
| 19 | import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IFlowEntry; |
| 20 | import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IFlowPath; |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 21 | import net.onrc.onos.ofcontroller.flowmanager.web.FlowWebRoutable; |
Pavlin Radoslavov | e1b37bc | 2013-10-16 03:57:06 -0700 | [diff] [blame] | 22 | import net.onrc.onos.ofcontroller.topology.TopologyManager; |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 23 | import net.onrc.onos.ofcontroller.util.*; |
| 24 | |
| 25 | import org.easymock.EasyMock; |
| 26 | import org.easymock.IAnswer; |
| 27 | import org.junit.After; |
| 28 | import org.junit.Before; |
Toshio Koide | ca7abe0 | 2013-06-27 17:30:17 -0700 | [diff] [blame] | 29 | import org.junit.Ignore; |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 30 | import org.junit.Test; |
| 31 | import org.junit.runner.RunWith; |
Toshio Koide | ca7abe0 | 2013-06-27 17:30:17 -0700 | [diff] [blame] | 32 | import org.openflow.protocol.OFFlowMod; |
| 33 | import org.openflow.protocol.OFType; |
| 34 | import org.openflow.protocol.factory.BasicFactory; |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 35 | import org.powermock.core.classloader.annotations.PrepareForTest; |
| 36 | import 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}) |
| 43 | public class FlowManagerTest { |
| 44 | private static FloodlightModuleContext context; |
| 45 | private static IFloodlightProviderService floodlightProvider; |
Pavlin Radoslavov | e1b37bc | 2013-10-16 03:57:06 -0700 | [diff] [blame] | 46 | private static TopologyManager topologyManager; |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 47 | 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 Radoslavov | e1b37bc | 2013-10-16 03:57:06 -0700 | [diff] [blame] | 71 | topologyManager = createMock(TopologyManager.class); |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 72 | restApi = createMock(IRestApiService.class); |
| 73 | op = createMock(GraphDBOperation.class); |
| 74 | |
| 75 | // setup expectations |
| 76 | expect(context.getServiceImpl(IFloodlightProviderService.class)).andReturn(floodlightProvider); |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 77 | expect(context.getServiceImpl(IRestApiService.class)).andReturn(restApi); |
| 78 | 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] | 79 | 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] | 80 | } |
| 81 | |
| 82 | private IFlowPath createIFlowPathMock(long flowId, String installerID, |
Pavlin Radoslavov | 204b286 | 2013-07-12 14:15:36 -0700 | [diff] [blame] | 83 | long flowPathFlags, |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 84 | 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 Radoslavov | 204b286 | 2013-07-12 14:15:36 -0700 | [diff] [blame] | 88 | expect(iFlowPath.getFlowPathFlags()).andReturn(new Long(flowPathFlags)).anyTimes(); |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 89 | 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 Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 93 | return iFlowPath; |
| 94 | } |
| 95 | |
Toshio Koide | ca7abe0 | 2013-06-27 17:30:17 -0700 | [diff] [blame] | 96 | private FlowPath createTestFlowPath(long flowId, String installerId, |
Pavlin Radoslavov | 204b286 | 2013-07-12 14:15:36 -0700 | [diff] [blame] | 97 | final long flowPathFlags, |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 98 | 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 Radoslavov | 204b286 | 2013-07-12 14:15:36 -0700 | [diff] [blame] | 104 | flowPath.setFlowPathFlags(new FlowPathFlags(flowPathFlags)); |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 105 | 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 Radoslavov | 204b286 | 2013-07-12 14:15:36 -0700 | [diff] [blame] | 114 | 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 Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 117 | |
| 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 Koide | ca7abe0 | 2013-06-27 17:30:17 -0700 | [diff] [blame] | 140 | FlowManager fm = new FlowManager(); |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 141 | |
| 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 Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 150 | |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 151 | 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 Radoslavov | 204b286 | 2013-07-12 14:15:36 -0700 | [diff] [blame] | 189 | flowPath.setFlowPathFlags(new FlowPathFlags(0)); |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 190 | 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 Radoslavov | 204b286 | 2013-07-12 14:15:36 -0700 | [diff] [blame] | 200 | createdFlowPath.setFlowPathFlags(new Long((long)0)); |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 201 | 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 Koide | ca7abe0 | 2013-06-27 17:30:17 -0700 | [diff] [blame] | 240 | FlowManager fm = new FlowManager(); |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 241 | |
| 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 Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 262 | 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 Koide | ca7abe0 | 2013-06-27 17:30:17 -0700 | [diff] [blame] | 276 | // instantiate required objects |
| 277 | FlowManager fm = new FlowManager(); |
| 278 | |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 279 | // 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 Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 293 | 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 Radoslavov | 204b286 | 2013-07-12 14:15:36 -0700 | [diff] [blame] | 348 | IFlowPath iFlowPath = createIFlowPathMock(1, "caller id", 0, 1, 1, 2, 2); |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 349 | |
| 350 | // setup expectations |
| 351 | expectInitWithContext(); |
Toshio Koide | ca7abe0 | 2013-06-27 17:30:17 -0700 | [diff] [blame] | 352 | expect(op.searchFlowPath(cmpEq(new FlowId(1)))).andReturn(iFlowPath); |
| 353 | expect(iFlowPath.getFlowEntries()).andReturn(new ArrayList<IFlowEntry>()).anyTimes(); |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 354 | op.commit(); |
| 355 | |
| 356 | // start the test |
| 357 | replayAll(); |
| 358 | |
| 359 | fm.init(context); |
Pavlin Radoslavov | 204b286 | 2013-07-12 14:15:36 -0700 | [diff] [blame] | 360 | FlowPath flowPath = fm.getFlow(new FlowId(1)); |
| 361 | String installerId = flowPath.installerId().toString(); |
| 362 | long flowPathFlags = flowPath.flowPathFlags().flags(); |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 363 | |
| 364 | //verify the test |
| 365 | verifyAll(); |
Pavlin Radoslavov | 204b286 | 2013-07-12 14:15:36 -0700 | [diff] [blame] | 366 | assertEquals("caller id", installerId); |
| 367 | assertEquals(0L, flowPathFlags); |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 368 | } |
| 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 Radoslavov | 204b286 | 2013-07-12 14:15:36 -0700 | [diff] [blame] | 449 | 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 Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 452 | |
| 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 Koide | ca7abe0 | 2013-06-27 17:30:17 -0700 | [diff] [blame] | 483 | // create mock objects |
Pavlin Radoslavov | 204b286 | 2013-07-12 14:15:36 -0700 | [diff] [blame] | 484 | IFlowPath iFlowPath1 = createIFlowPathMock(1, "caller id", 0, 1, 1, 2, 2); |
| 485 | IFlowPath iFlowPath2 = createIFlowPathMock(2, "caller id", 0, 2, 5, 3, 5); |
Toshio Koide | ca7abe0 | 2013-06-27 17:30:17 -0700 | [diff] [blame] | 486 | |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 487 | // instantiate required objects |
| 488 | ArrayList<IFlowPath> flowPaths = new ArrayList<IFlowPath>(); |
Toshio Koide | ca7abe0 | 2013-06-27 17:30:17 -0700 | [diff] [blame] | 489 | flowPaths.add(iFlowPath1); |
| 490 | flowPaths.add(iFlowPath2); |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 491 | FlowManager fm = new FlowManager(); |
| 492 | |
| 493 | // setup expectations |
| 494 | expectInitWithContext(); |
| 495 | expect(op.getAllFlowPaths()).andReturn(flowPaths); |
Toshio Koide | ca7abe0 | 2013-06-27 17:30:17 -0700 | [diff] [blame] | 496 | expect(iFlowPath1.getFlowEntries()).andReturn(new ArrayList<IFlowEntry>()).anyTimes(); |
| 497 | expect(iFlowPath2.getFlowEntries()).andReturn(new ArrayList<IFlowEntry>()).anyTimes(); |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 498 | 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 Radoslavov | 204b286 | 2013-07-12 14:15:36 -0700 | [diff] [blame] | 536 | paramFlow.setFlowPathFlags(new FlowPathFlags(0)); |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 537 | 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 Radoslavov | 204b286 | 2013-07-12 14:15:36 -0700 | [diff] [blame] | 551 | assertEquals(flowPath.flowPathFlags().flags(), 0); |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 552 | 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 Radoslavov | 204b286 | 2013-07-12 14:15:36 -0700 | [diff] [blame] | 572 | assertEquals(paramFlow.flowPathFlags().flags(), resultFlow.flowPathFlags().flags()); |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 573 | assertEquals(paramFlow.dataPath().toString(), resultFlow.dataPath().toString()); |
| 574 | assertEquals(paramFlow.flowEntryMatch().toString(), resultFlow.flowEntryMatch().toString()); |
| 575 | } |
| 576 | |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 577 | // INetMapStorage methods |
| 578 | |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 579 | /** |
| 580 | * Test method for {@link FlowManager#init(String)}. |
| 581 | * @throws Exception |
| 582 | */ |
| 583 | @Test |
| 584 | public final void testInitSuccessNormally() throws Exception { |
Toshio Koide | ca7abe0 | 2013-06-27 17:30:17 -0700 | [diff] [blame] | 585 | // instantiate required objects |
| 586 | FlowManager fm = new FlowManager(); |
| 587 | |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 588 | // create mock objects |
| 589 | op = createMock(GraphDBOperation.class); |
| 590 | |
| 591 | // setup expectations |
| 592 | expectNew(GraphDBOperation.class, "/dummy/path").andReturn(op); |
| 593 | |
| 594 | // start the test |
| 595 | replayAll(); |
| 596 | |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 597 | fm.init("/dummy/path"); |
| 598 | |
| 599 | // verify the test |
| 600 | verifyAll(); |
| 601 | } |
| 602 | |
| 603 | /** |
| 604 | * Test method for {@link FlowManager#close()}. |
| 605 | * @throws Exception |
| 606 | */ |
| 607 | @Test |
| 608 | public final void testCloseSuccessNormally() throws Exception { |
| 609 | // instantiate required objects |
| 610 | FlowManager fm = new FlowManager(); |
| 611 | |
| 612 | // setup expectations |
| 613 | expectInitWithContext(); |
| 614 | op.close(); |
| 615 | |
| 616 | // start the test |
| 617 | replayAll(); |
| 618 | |
| 619 | fm.init(context); |
| 620 | fm.close(); |
| 621 | |
| 622 | // verify the test |
| 623 | verifyAll(); |
| 624 | } |
| 625 | |
| 626 | |
| 627 | // IFloodlightModule methods |
| 628 | |
| 629 | |
| 630 | /** |
| 631 | * Test method for {@link FlowManager#getModuleServices()}. |
| 632 | * @throws Exception |
| 633 | */ |
| 634 | @Test |
| 635 | public final void testGetModuleServicesSuccessNormally() throws Exception { |
| 636 | // instantiate required objects |
| 637 | FlowManager fm = new FlowManager(); |
| 638 | |
| 639 | // setup expectations |
| 640 | expectInitWithContext(); |
| 641 | |
| 642 | // start the test |
| 643 | replayAll(); |
| 644 | |
| 645 | fm.init(context); |
| 646 | Collection<Class<? extends IFloodlightService>> l = fm.getModuleServices(); |
| 647 | |
| 648 | // verify the test |
| 649 | verifyAll(); |
| 650 | assertEquals(1, l.size()); |
| 651 | assertEquals(IFlowService.class, l.iterator().next()); |
| 652 | } |
| 653 | |
| 654 | /** |
| 655 | * Test method for {@link FlowManager#getServiceImpls()}. |
| 656 | * @throws Exception |
| 657 | */ |
| 658 | @Test |
| 659 | public final void testGetServiceImplsSuccessNormally() throws Exception { |
| 660 | // instantiate required objects |
| 661 | FlowManager fm = new FlowManager(); |
| 662 | |
| 663 | // setup expectations |
| 664 | expectInitWithContext(); |
| 665 | |
| 666 | // start the test |
| 667 | replayAll(); |
| 668 | |
| 669 | fm.init(context); |
| 670 | Map<Class<? extends IFloodlightService>, IFloodlightService> si = fm.getServiceImpls(); |
| 671 | |
| 672 | // verify the test |
| 673 | verifyAll(); |
| 674 | assertEquals(1, si.size()); |
| 675 | assertTrue(si.containsKey(IFlowService.class)); |
| 676 | assertEquals(fm, si.get(IFlowService.class)); |
| 677 | } |
| 678 | |
| 679 | /** |
| 680 | * Test method for {@link FlowManager#getModuleDependencies()}. |
| 681 | * @throws Exception |
| 682 | */ |
| 683 | @Test |
| 684 | public final void testGetModuleDependenciesSuccessNormally() throws Exception { |
| 685 | // instantiate required objects |
| 686 | FlowManager fm = new FlowManager(); |
| 687 | |
| 688 | // setup expectations |
| 689 | expectInitWithContext(); |
| 690 | |
| 691 | // start the test |
| 692 | replayAll(); |
| 693 | |
| 694 | fm.init(context); |
| 695 | Collection<Class<? extends IFloodlightService>> md = fm.getModuleDependencies(); |
| 696 | |
| 697 | // verify the test |
| 698 | verifyAll(); |
Pavlin Radoslavov | 0537827 | 2013-10-19 23:23:05 -0700 | [diff] [blame^] | 699 | assertEquals(4, md.size()); |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 700 | assertTrue(md.contains(IFloodlightProviderService.class)); |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 701 | assertTrue(md.contains(IRestApiService.class)); |
| 702 | } |
| 703 | |
| 704 | /** |
| 705 | * Test method for {@link FlowManager#init(FloodlightModuleContext)}. |
| 706 | * @throws Exception |
| 707 | */ |
| 708 | @Test |
| 709 | public final void testInitWithFloodlightModuleContextSuccessNormally() throws Exception { |
| 710 | // instantiate required objects |
| 711 | FlowManager fm = new FlowManager(); |
| 712 | |
| 713 | // setup expectations |
| 714 | expectInitWithContext(); |
| 715 | |
| 716 | // start the test |
| 717 | replayAll(); |
| 718 | |
| 719 | fm.init(context); |
| 720 | |
| 721 | // verify the test |
| 722 | verifyAll(); |
| 723 | } |
| 724 | |
| 725 | /** |
| 726 | * Test method for {@link FlowManager#startUp(FloodlightModuleContext)}. |
| 727 | * @throws Exception |
| 728 | */ |
| 729 | @Test |
| 730 | public final void testStartupSuccessNormally() throws Exception { |
| 731 | // create mock objects |
| 732 | mockStaticPartial(Executors.class, "newScheduledThreadPool"); |
| 733 | ScheduledExecutorService scheduler = createMock(ScheduledExecutorService.class); |
| 734 | |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 735 | // instantiate required objects |
| 736 | FlowManager fm = new FlowManager(); |
| 737 | |
| 738 | // setup expectations |
| 739 | expectInitWithContext(); |
| 740 | expect(Executors.newScheduledThreadPool(1)).andReturn(scheduler); |
| 741 | expect(Executors.newScheduledThreadPool(1)).andReturn(scheduler); |
| 742 | expect(scheduler.scheduleAtFixedRate( |
| 743 | EasyMock.anyObject(Runnable.class), |
| 744 | EasyMock.anyLong(), |
| 745 | EasyMock.anyLong(), |
| 746 | EasyMock.anyObject(TimeUnit.class))).andReturn(null).times(2); |
| 747 | restApi.addRestletRoutable(EasyMock.anyObject(FlowWebRoutable.class)); |
| 748 | |
| 749 | // start the test |
| 750 | replayAll(); |
| 751 | |
| 752 | fm.init(context); |
| 753 | fm.startUp(context); |
| 754 | |
| 755 | // verify the test |
| 756 | verifyAll(); |
| 757 | } |
Toshio Koide | ca7abe0 | 2013-06-27 17:30:17 -0700 | [diff] [blame] | 758 | |
| 759 | |
| 760 | // other methods |
| 761 | |
| 762 | |
| 763 | /** |
| 764 | * Test method for {@link FlowManager#clearFlow(FlowId)}. |
| 765 | * @throws Exception |
| 766 | */ |
| 767 | @Test |
| 768 | public final void testClearFlowSuccessNormally() throws Exception { |
| 769 | // create mock objects |
Pavlin Radoslavov | 204b286 | 2013-07-12 14:15:36 -0700 | [diff] [blame] | 770 | IFlowPath flowPath = createIFlowPathMock(123, "id", 0, 1, 2, 3, 4); |
Toshio Koide | ca7abe0 | 2013-06-27 17:30:17 -0700 | [diff] [blame] | 771 | IFlowEntry flowEntry1 = createMock(IFlowEntry.class); |
| 772 | IFlowEntry flowEntry2 = createMock(IFlowEntry.class); |
| 773 | IFlowEntry flowEntry3 = createMock(IFlowEntry.class); |
| 774 | |
| 775 | // instantiate required objects |
| 776 | FlowManager fm = new FlowManager(); |
| 777 | FlowId flowId = new FlowId(123); |
| 778 | ArrayList<IFlowEntry> flowEntries = new ArrayList<IFlowEntry>(); |
| 779 | flowEntries.add(flowEntry1); |
| 780 | flowEntries.add(flowEntry2); |
| 781 | flowEntries.add(flowEntry3); |
| 782 | |
| 783 | // setup expectations |
| 784 | expectInitWithContext(); |
| 785 | expect(op.searchFlowPath(cmpEq(flowId))).andReturn(flowPath); |
| 786 | expect(flowPath.getFlowEntries()).andReturn(flowEntries); |
| 787 | flowPath.removeFlowEntry(flowEntry1); |
| 788 | flowPath.removeFlowEntry(flowEntry2); |
| 789 | flowPath.removeFlowEntry(flowEntry3); |
| 790 | op.removeFlowEntry(flowEntry1); |
| 791 | op.removeFlowEntry(flowEntry2); |
| 792 | op.removeFlowEntry(flowEntry3); |
| 793 | op.removeFlowPath(flowPath); |
| 794 | op.commit(); |
| 795 | |
| 796 | // start the test |
| 797 | replayAll(); |
| 798 | |
| 799 | fm.init(context); |
| 800 | fm.clearFlow(flowId); |
| 801 | |
| 802 | // verify the test |
| 803 | verifyAll(); |
| 804 | } |
| 805 | |
| 806 | /** |
| 807 | * Test method for {@link FlowManager#getAllFlowsWithoutFlowEntries()}. |
| 808 | * @throws Exception |
| 809 | */ |
| 810 | @Test |
| 811 | public final void testGetAllFlowsWithoutFlowEntriesSuccessNormally() throws Exception { |
| 812 | // create mock objects |
Pavlin Radoslavov | 204b286 | 2013-07-12 14:15:36 -0700 | [diff] [blame] | 813 | IFlowPath iFlowPath1 = createIFlowPathMock(1, "caller id", 0, 1, 1, 2, 2); |
| 814 | IFlowPath iFlowPath2 = createIFlowPathMock(2, "caller id", 0, 2, 5, 3, 5); |
Toshio Koide | ca7abe0 | 2013-06-27 17:30:17 -0700 | [diff] [blame] | 815 | |
| 816 | // instantiate required objects |
| 817 | ArrayList<IFlowPath> flowPaths = new ArrayList<IFlowPath>(); |
| 818 | flowPaths.add(iFlowPath1); |
| 819 | flowPaths.add(iFlowPath2); |
| 820 | FlowManager fm = new FlowManager(); |
| 821 | |
| 822 | // setup expectations |
| 823 | expectInitWithContext(); |
| 824 | op.commit(); |
| 825 | expect(op.getAllFlowPaths()).andReturn(flowPaths); |
| 826 | |
| 827 | // start the test |
| 828 | replayAll(); |
| 829 | |
| 830 | fm.init(context); |
| 831 | ArrayList<IFlowPath> result = fm.getAllFlowsWithoutFlowEntries(); |
| 832 | |
| 833 | // verify the test |
| 834 | verifyAll(); |
| 835 | assertEquals(iFlowPath1, result.get(0)); |
| 836 | assertEquals(iFlowPath2, result.get(1)); |
| 837 | |
| 838 | // TODO: does this method just return the replica of the flow paths? |
| 839 | } |
| 840 | |
| 841 | /** |
| 842 | * Test method for {@link FlowManager#reconcileFlow(IFlowPath, DataPath)}. |
| 843 | * @throws Exception |
| 844 | */ |
| 845 | @Test |
| 846 | public final void testReconcileFlowWithFlowPathAndDataPathSuccessNormally() throws Exception { |
| 847 | final String addFlowEntry = "addFlowEntry"; |
| 848 | |
| 849 | // create mock objects |
Pavlin Radoslavov | 204b286 | 2013-07-12 14:15:36 -0700 | [diff] [blame] | 850 | IFlowPath iFlowPath1 = createIFlowPathMock(1, "caller id", 0, 1, 1, 2, 2); |
Toshio Koide | ca7abe0 | 2013-06-27 17:30:17 -0700 | [diff] [blame] | 851 | IFlowEntry iFlowEntry1 = createMock(IFlowEntry.class); |
| 852 | IFlowEntry iFlowEntry2 = createMock(IFlowEntry.class); |
| 853 | FlowManager fm = createPartialMockAndInvokeDefaultConstructor(FlowManager.class, addFlowEntry); |
| 854 | |
| 855 | // instantiate required objects |
| 856 | FlowEntry flowEntry1 = new FlowEntry(); |
| 857 | flowEntry1.setDpid(new Dpid(1)); |
| 858 | flowEntry1.setFlowId(new FlowId(1)); |
| 859 | flowEntry1.setInPort(new Port((short) 1)); |
| 860 | flowEntry1.setOutPort(new Port((short) 11)); |
| 861 | flowEntry1.setFlowEntryId(new FlowEntryId(1)); |
| 862 | flowEntry1.setFlowEntryMatch(new FlowEntryMatch()); |
Pavlin Radoslavov | 1bc2c47 | 2013-07-17 18:11:37 -0700 | [diff] [blame] | 863 | flowEntry1.setFlowEntryActions(new FlowEntryActions()); |
Toshio Koide | ca7abe0 | 2013-06-27 17:30:17 -0700 | [diff] [blame] | 864 | flowEntry1.setFlowEntryErrorState(new FlowEntryErrorState()); |
| 865 | |
| 866 | FlowEntry flowEntry2 = new FlowEntry(); |
| 867 | flowEntry2.setDpid(new Dpid(2)); |
| 868 | flowEntry2.setFlowId(new FlowId(2)); |
| 869 | flowEntry2.setInPort(new Port((short) 22)); |
| 870 | flowEntry2.setOutPort(new Port((short) 2)); |
| 871 | flowEntry2.setFlowEntryId(new FlowEntryId(2)); |
| 872 | flowEntry2.setFlowEntryMatch(new FlowEntryMatch()); |
Pavlin Radoslavov | 1bc2c47 | 2013-07-17 18:11:37 -0700 | [diff] [blame] | 873 | flowEntry2.setFlowEntryActions(new FlowEntryActions()); |
Toshio Koide | ca7abe0 | 2013-06-27 17:30:17 -0700 | [diff] [blame] | 874 | flowEntry2.setFlowEntryErrorState(new FlowEntryErrorState()); |
| 875 | |
| 876 | DataPath dataPath = new DataPath(); |
| 877 | ArrayList<FlowEntry> flowEntries = new ArrayList<FlowEntry>(); |
| 878 | flowEntries.add(flowEntry1); |
| 879 | flowEntries.add(flowEntry2); |
| 880 | dataPath.setFlowEntries(flowEntries); |
| 881 | |
| 882 | ArrayList<IFlowEntry> oldFlowEntries = new ArrayList<IFlowEntry>(); |
| 883 | oldFlowEntries.add(iFlowEntry1); |
| 884 | oldFlowEntries.add(iFlowEntry2); |
| 885 | |
| 886 | // setup expectations |
| 887 | expectInitWithContext(); |
Toshio Koide | ca7abe0 | 2013-06-27 17:30:17 -0700 | [diff] [blame] | 888 | expect(iFlowPath1.getFlowEntries()).andReturn(oldFlowEntries); |
| 889 | iFlowEntry1.setUserState("FE_USER_DELETE"); |
| 890 | iFlowEntry1.setSwitchState("FE_SWITCH_NOT_UPDATED"); |
| 891 | iFlowEntry2.setUserState("FE_USER_DELETE"); |
| 892 | iFlowEntry2.setSwitchState("FE_SWITCH_NOT_UPDATED"); |
| 893 | expectPrivate(fm, addFlowEntry, iFlowPath1, flowEntry1).andReturn(null); |
| 894 | expectPrivate(fm, addFlowEntry, iFlowPath1, flowEntry2).andReturn(null); |
| 895 | |
| 896 | // start the test |
| 897 | replayAll(); |
| 898 | |
| 899 | fm.init(context); |
| 900 | Boolean result = fm.reconcileFlow(iFlowPath1, dataPath); |
| 901 | |
| 902 | // verify the test |
| 903 | verifyAll(); |
| 904 | assertTrue(result); |
| 905 | // TODO: write more asserts |
| 906 | } |
| 907 | |
| 908 | /** |
| 909 | * Test method for {@link FlowManager#installFlowEntry(net.floodlightcontroller.core.IOFSwitch, IFlowPath, IFlowEntry)}. |
| 910 | * @throws Exception |
| 911 | */ |
| 912 | @Test |
| 913 | public final void testInstallFlowEntryWithIFlowPathSuccessNormally() throws Exception { |
| 914 | // create mock object |
| 915 | IOFSwitch iofSwitch = createNiceMock(IOFSwitch.class); |
Pavlin Radoslavov | 204b286 | 2013-07-12 14:15:36 -0700 | [diff] [blame] | 916 | IFlowPath iFlowPath = createIFlowPathMock(1, "id", 0, 1, 2, 3, 4); |
Toshio Koide | ca7abe0 | 2013-06-27 17:30:17 -0700 | [diff] [blame] | 917 | IFlowEntry iFlowEntry = createMock(IFlowEntry.class); |
| 918 | BasicFactory basicFactory = createMock(BasicFactory.class); |
| 919 | |
| 920 | // instantiate required objects |
| 921 | FlowManager fm = new FlowManager(); |
| 922 | |
Pavlin Radoslavov | 1bc2c47 | 2013-07-17 18:11:37 -0700 | [diff] [blame] | 923 | FlowEntryAction action = new FlowEntryAction(); |
| 924 | action.setActionOutput(new Port((short)2)); |
| 925 | FlowEntryActions actions = new FlowEntryActions(); |
| 926 | actions.addAction(action); |
| 927 | |
Toshio Koide | ca7abe0 | 2013-06-27 17:30:17 -0700 | [diff] [blame] | 928 | // setup expectations |
| 929 | expectInitWithContext(); |
| 930 | expect(iFlowEntry.getFlowEntryId()).andReturn(new FlowEntryId(123).toString()); |
| 931 | expect(iFlowEntry.getUserState()).andReturn("FE_USER_ADD"); |
| 932 | iFlowEntry.setSwitchState("FE_SWITCH_UPDATED"); |
| 933 | expect(iFlowEntry.getMatchInPort()).andReturn(new Short((short) 1)); |
Toshio Koide | ca7abe0 | 2013-06-27 17:30:17 -0700 | [diff] [blame] | 934 | expect(iFlowEntry.getMatchSrcMac()).andReturn("01:23:45:67:89:01"); |
| 935 | expect(iFlowEntry.getMatchDstMac()).andReturn("01:23:45:67:89:02"); |
Pavlin Radoslavov | ad3a1e6 | 2013-07-09 13:30:16 -0700 | [diff] [blame] | 936 | expect(iFlowEntry.getMatchEthernetFrameType()).andReturn(new Short((short)0x0800)); |
| 937 | expect(iFlowEntry.getMatchVlanId()).andReturn(new Short((short)0x1234)); |
| 938 | expect(iFlowEntry.getMatchVlanPriority()).andReturn(new Byte((byte)0x10)); |
| 939 | expect(iFlowEntry.getMatchSrcIPv4Net()).andReturn("192.168.0.1"); |
| 940 | expect(iFlowEntry.getMatchDstIPv4Net()).andReturn("192.168.0.2"); |
| 941 | expect(iFlowEntry.getMatchIpProto()).andReturn(new Byte((byte)0x20)); |
| 942 | expect(iFlowEntry.getMatchIpToS()).andReturn(new Byte((byte)0x3)); |
| 943 | expect(iFlowEntry.getMatchSrcTcpUdpPort()).andReturn(new Short((short)40000)); |
| 944 | expect(iFlowEntry.getMatchDstTcpUdpPort()).andReturn(new Short((short)80)); |
Pavlin Radoslavov | 1bc2c47 | 2013-07-17 18:11:37 -0700 | [diff] [blame] | 945 | expect(iFlowEntry.getActions()).andReturn(actions.toString()); |
Toshio Koide | ca7abe0 | 2013-06-27 17:30:17 -0700 | [diff] [blame] | 946 | expect(floodlightProvider.getOFMessageFactory()).andReturn(basicFactory); |
| 947 | expect(basicFactory.getMessage(OFType.FLOW_MOD)).andReturn(new OFFlowMod()); |
| 948 | expect(iofSwitch.getStringId()).andReturn(new Dpid(100).toString()); |
| 949 | |
| 950 | // start the test |
| 951 | replayAll(); |
| 952 | |
| 953 | fm.init(context); |
| 954 | Boolean result = fm.installFlowEntry(iofSwitch, iFlowPath, iFlowEntry); |
| 955 | |
| 956 | // verify the test |
| 957 | verifyAll(); |
| 958 | assertTrue(result); |
| 959 | // TODO: write more asserts |
| 960 | } |
| 961 | |
| 962 | /** |
| 963 | * Test method for {@link FlowManager#installFlowEntry(net.floodlightcontroller.core.IOFSwitch, FlowPath, FlowEntry)}. |
| 964 | * The method seems to be not used for now. |
| 965 | */ |
| 966 | @Ignore @Test |
| 967 | public final void testInstallFlowEntryWithFlowPathSuccessNormally() { |
| 968 | fail("not yet implemented"); |
| 969 | } |
| 970 | |
| 971 | /** |
| 972 | * Test method for {@link FlowManager#removeFlowEntry(net.floodlightcontroller.core.IOFSwitch, FlowPath, FlowEntry)}. |
| 973 | * The method seems to be not implemented and not used for now. |
| 974 | */ |
| 975 | @Ignore @Test |
| 976 | public final void testRemoveFlowEntrySuccessNormally() { |
| 977 | fail("not yet implemented"); |
| 978 | } |
| 979 | |
| 980 | /** |
| 981 | * Test method for {@link FlowManager#installRemoteFlowEntry(FlowPath, FlowEntry)}. |
| 982 | * The method seems to be not implemented and not used for now. |
| 983 | */ |
| 984 | @Ignore @Test |
| 985 | public final void testInstallRemoteFlowEntrySuccessNormally() { |
| 986 | fail("not yet implemented"); |
| 987 | } |
| 988 | |
| 989 | /** |
| 990 | * Test method for {@link FlowManager#removeRemoteFlowEntry(FlowPath, FlowEntry)}. |
| 991 | * The method seems to be not implemented and not used for now. |
| 992 | */ |
| 993 | @Ignore @Test |
| 994 | public final void testRemoveRemoteFlowEntrySuccessNormally() { |
| 995 | fail("not yet implemented"); |
| 996 | } |
Pavlin Radoslavov | ddd01ba | 2013-07-03 15:40:44 -0700 | [diff] [blame] | 997 | } |