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 | |
Pavlin Radoslavov | 1308dc6 | 2013-10-25 15:54:31 -0700 | [diff] [blame] | 8 | import java.lang.reflect.Method; |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 9 | import java.util.*; |
| 10 | import java.util.concurrent.Executors; |
| 11 | import java.util.concurrent.ScheduledExecutorService; |
| 12 | import java.util.concurrent.TimeUnit; |
| 13 | |
| 14 | import net.floodlightcontroller.core.IFloodlightProviderService; |
Toshio Koide | ca7abe0 | 2013-06-27 17:30:17 -0700 | [diff] [blame] | 15 | import net.floodlightcontroller.core.IOFSwitch; |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 16 | import net.floodlightcontroller.core.module.FloodlightModuleContext; |
| 17 | import net.floodlightcontroller.core.module.IFloodlightService; |
| 18 | import net.floodlightcontroller.restserver.IRestApiService; |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 19 | import net.onrc.onos.datagrid.IDatagridService; |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 20 | import net.onrc.onos.graph.GraphDBOperation; |
| 21 | import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IFlowEntry; |
| 22 | import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IFlowPath; |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 23 | import net.onrc.onos.ofcontroller.flowmanager.web.FlowWebRoutable; |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 24 | import net.onrc.onos.ofcontroller.topology.ITopologyNetService; |
Pavlin Radoslavov | e1b37bc | 2013-10-16 03:57:06 -0700 | [diff] [blame] | 25 | import net.onrc.onos.ofcontroller.topology.TopologyManager; |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 26 | import net.onrc.onos.ofcontroller.util.*; |
| 27 | |
| 28 | import org.easymock.EasyMock; |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 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 | 7d4a40e | 2013-10-27 23:39:40 -0700 | [diff] [blame] | 90 | String flowPathType, String flowPathUserState, |
| 91 | long flowPathFlags, long srcDpid, int srcPort, |
| 92 | long dstDpid, int dstPort) { |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 93 | IFlowPath iFlowPath = createNiceMock(IFlowPath.class); |
| 94 | expect(iFlowPath.getFlowId()).andReturn(new FlowId(flowId).toString()).anyTimes(); |
| 95 | expect(iFlowPath.getInstallerId()).andReturn(installerID).anyTimes(); |
Pavlin Radoslavov | d28cf7c | 2013-10-26 11:27:43 -0700 | [diff] [blame] | 96 | expect(iFlowPath.getFlowPathType()).andReturn(flowPathType).anyTimes(); |
Pavlin Radoslavov | 7d4a40e | 2013-10-27 23:39:40 -0700 | [diff] [blame] | 97 | expect(iFlowPath.getFlowPathUserState()).andReturn(flowPathUserState).anyTimes(); |
Pavlin Radoslavov | 204b286 | 2013-07-12 14:15:36 -0700 | [diff] [blame] | 98 | expect(iFlowPath.getFlowPathFlags()).andReturn(new Long(flowPathFlags)).anyTimes(); |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 99 | expect(iFlowPath.getSrcSwitch()).andReturn(new Dpid(srcDpid).toString()).anyTimes(); |
| 100 | expect(iFlowPath.getSrcPort()).andReturn(new Short((short)srcPort)).anyTimes(); |
| 101 | expect(iFlowPath.getDstSwitch()).andReturn(new Dpid(dstDpid).toString()).anyTimes(); |
| 102 | expect(iFlowPath.getDstPort()).andReturn(new Short((short)dstPort)).anyTimes(); |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 103 | return iFlowPath; |
| 104 | } |
| 105 | |
Toshio Koide | ca7abe0 | 2013-06-27 17:30:17 -0700 | [diff] [blame] | 106 | private FlowPath createTestFlowPath(long flowId, String installerId, |
Pavlin Radoslavov | 7d4a40e | 2013-10-27 23:39:40 -0700 | [diff] [blame] | 107 | String flowPathType, String flowPathUserState, |
| 108 | final long flowPathFlags, |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 109 | final long srcDpid, final int srcPort, |
Pavlin Radoslavov | d28cf7c | 2013-10-26 11:27:43 -0700 | [diff] [blame] | 110 | final long dstDpid, final int dstPort |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 111 | ) { |
| 112 | FlowPath flowPath = new FlowPath(); |
| 113 | flowPath.setFlowId(new FlowId(flowId)); |
| 114 | flowPath.setInstallerId(new CallerId(installerId)); |
Pavlin Radoslavov | d28cf7c | 2013-10-26 11:27:43 -0700 | [diff] [blame] | 115 | flowPath.setFlowPathType(FlowPathType.valueOf(flowPathType)); |
Pavlin Radoslavov | 7d4a40e | 2013-10-27 23:39:40 -0700 | [diff] [blame] | 116 | flowPath.setFlowPathUserState(FlowPathUserState.valueOf(flowPathUserState)); |
Pavlin Radoslavov | 204b286 | 2013-07-12 14:15:36 -0700 | [diff] [blame] | 117 | flowPath.setFlowPathFlags(new FlowPathFlags(flowPathFlags)); |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 118 | flowPath.setDataPath(new DataPath() {{ |
| 119 | setSrcPort(new SwitchPort(new Dpid(srcDpid), new Port((short)srcPort))); |
| 120 | setDstPort(new SwitchPort(new Dpid(dstDpid), new Port((short)dstPort))); |
| 121 | }}); |
| 122 | flowPath.setFlowEntryMatch(new FlowEntryMatch()); |
| 123 | return flowPath; |
| 124 | } |
| 125 | |
Naoki Shiota | 991093a | 2013-12-10 14:47:18 -0800 | [diff] [blame^] | 126 | /* |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 127 | private ArrayList<FlowPath> createTestFlowPaths() { |
Pavlin Radoslavov | 7d4a40e | 2013-10-27 23:39:40 -0700 | [diff] [blame] | 128 | FlowPath flowPath1 = createTestFlowPath(1, "foo caller id", "FP_TYPE_SHORTEST_PATH", "FP_USER_ADD", 0, 1, 1, 2, 2); |
| 129 | FlowPath flowPath2 = createTestFlowPath(2, "caller id", "FP_TYPE_SHORTEST_PATH", "FP_USER_ADD", 0, 1, 1, 2, 2); |
| 130 | FlowPath flowPath3 = createTestFlowPath(3, "caller id", "FP_TYPE_SHORTEST_PATH", "FP_USER_ADD", 0, 1, 5, 2, 2); |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 131 | |
| 132 | ArrayList<FlowPath> flowPaths = new ArrayList<FlowPath>(); |
| 133 | flowPaths.add(flowPath1); |
| 134 | flowPaths.add(flowPath2); |
| 135 | flowPaths.add(flowPath3); |
| 136 | |
| 137 | return flowPaths; |
| 138 | } |
Naoki Shiota | 991093a | 2013-12-10 14:47:18 -0800 | [diff] [blame^] | 139 | */ |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 140 | |
| 141 | |
| 142 | // IFlowService methods |
| 143 | |
| 144 | |
| 145 | /** |
Pavlin Radoslavov | 051abb4 | 2013-12-05 17:24:50 -0800 | [diff] [blame] | 146 | * Test method for {@link FlowManager#addFlow(FlowPath)}. |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 147 | * @throws Exception |
| 148 | */ |
| 149 | @Test |
| 150 | public final void testAddFlowFailGraphCreatesNoFlow() throws Exception { |
| 151 | // instantiate required objects |
| 152 | FlowId flowId = new FlowId(123); |
| 153 | FlowPath flowPath = new FlowPath(); |
| 154 | flowPath.setFlowId(flowId); |
Toshio Koide | ca7abe0 | 2013-06-27 17:30:17 -0700 | [diff] [blame] | 155 | FlowManager fm = new FlowManager(); |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 156 | |
| 157 | // setup expectations |
| 158 | expectInitWithContext(); |
| 159 | expect(op.searchFlowPath(flowId)).andReturn(null); |
| 160 | expect(op.newFlowPath()).andReturn(null); |
| 161 | op.rollback(); |
| 162 | |
| 163 | // start the test |
| 164 | replayAll(); |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 165 | |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 166 | fm.init(context); |
Pavlin Radoslavov | 051abb4 | 2013-12-05 17:24:50 -0800 | [diff] [blame] | 167 | FlowId result = fm.addFlow(flowPath); |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 168 | |
| 169 | // verify the test |
| 170 | verifyAll(); |
Pavlin Radoslavov | 051abb4 | 2013-12-05 17:24:50 -0800 | [diff] [blame] | 171 | assertNotNull(result); |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | /** |
Pavlin Radoslavov | 051abb4 | 2013-12-05 17:24:50 -0800 | [diff] [blame] | 175 | * Test method for {@link FlowManager#addFlow(FlowPath)}. |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 176 | * @throws Exception |
| 177 | */ |
| 178 | @Test |
| 179 | public final void testAddFlowSuccessNormally() throws Exception { |
| 180 | final String addFlowEntry = "addFlowEntry"; |
| 181 | // create mock objects |
| 182 | IFlowPath createdFlowPath = createNiceMock(IFlowPath.class); |
| 183 | IFlowEntry createdFlowEntry1 = createNiceMock(IFlowEntry.class); |
| 184 | IFlowEntry createdFlowEntry2 = createNiceMock(IFlowEntry.class); |
| 185 | FlowManager fm = createPartialMockAndInvokeDefaultConstructor(FlowManager.class, addFlowEntry); |
| 186 | |
| 187 | // instantiate required objects |
| 188 | final FlowEntry flowEntry1 = new FlowEntry(); |
| 189 | final FlowEntry flowEntry2 = new FlowEntry(); |
| 190 | ArrayList<FlowEntry> flowEntries = new ArrayList<FlowEntry>(); |
| 191 | flowEntries.add(flowEntry1); |
| 192 | flowEntries.add(flowEntry2); |
| 193 | |
| 194 | DataPath dataPath = new DataPath(); |
| 195 | dataPath.setSrcPort(new SwitchPort(new Dpid(0x1234), new Port((short)1))); |
| 196 | dataPath.setDstPort(new SwitchPort(new Dpid(0x5678), new Port((short)2))); |
| 197 | dataPath.setFlowEntries(flowEntries); |
| 198 | |
| 199 | FlowEntryMatch match = new FlowEntryMatch(); |
| 200 | |
| 201 | FlowPath flowPath = new FlowPath(); |
| 202 | flowPath.setFlowId(new FlowId(0x100)); |
| 203 | flowPath.setInstallerId(new CallerId("installer id")); |
Pavlin Radoslavov | d28cf7c | 2013-10-26 11:27:43 -0700 | [diff] [blame] | 204 | flowPath.setFlowPathType(FlowPathType.valueOf("FP_TYPE_SHORTEST_PATH")); |
Pavlin Radoslavov | 7d4a40e | 2013-10-27 23:39:40 -0700 | [diff] [blame] | 205 | flowPath.setFlowPathUserState(FlowPathUserState.valueOf("FP_USER_ADD")); |
Pavlin Radoslavov | 204b286 | 2013-07-12 14:15:36 -0700 | [diff] [blame] | 206 | flowPath.setFlowPathFlags(new FlowPathFlags(0)); |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 207 | flowPath.setDataPath(dataPath); |
| 208 | flowPath.setFlowEntryMatch(match); |
| 209 | |
| 210 | // setup expectations |
| 211 | expectInitWithContext(); |
| 212 | expect(op.searchFlowPath(cmpEq(new FlowId(0x100)))).andReturn(null); |
| 213 | expect(op.newFlowPath()).andReturn(createdFlowPath); |
| 214 | createdFlowPath.setFlowId("0x100"); |
| 215 | createdFlowPath.setType("flow"); |
| 216 | createdFlowPath.setInstallerId("installer id"); |
Pavlin Radoslavov | d28cf7c | 2013-10-26 11:27:43 -0700 | [diff] [blame] | 217 | createdFlowPath.setFlowPathType("FP_TYPE_SHORTEST_PATH"); |
Pavlin Radoslavov | 7d4a40e | 2013-10-27 23:39:40 -0700 | [diff] [blame] | 218 | createdFlowPath.setFlowPathUserState("FP_USER_ADD"); |
Pavlin Radoslavov | 204b286 | 2013-07-12 14:15:36 -0700 | [diff] [blame] | 219 | createdFlowPath.setFlowPathFlags(new Long((long)0)); |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 220 | createdFlowPath.setSrcSwitch("00:00:00:00:00:00:12:34"); |
| 221 | createdFlowPath.setSrcPort(new Short((short)1)); |
| 222 | createdFlowPath.setDstSwitch("00:00:00:00:00:00:56:78"); |
| 223 | createdFlowPath.setDstPort(new Short((short)2)); |
| 224 | createdFlowPath.setDataPathSummary("data path summary"); |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 225 | |
| 226 | expectPrivate(fm, addFlowEntry, createdFlowPath, flowEntry1) |
| 227 | .andReturn(createdFlowEntry1); |
| 228 | expectPrivate(fm, addFlowEntry, createdFlowPath, flowEntry2) |
| 229 | .andReturn(createdFlowEntry2); |
| 230 | |
| 231 | op.commit(); |
| 232 | |
| 233 | // start the test |
| 234 | replayAll(); |
| 235 | |
| 236 | fm.init(context); |
Pavlin Radoslavov | 051abb4 | 2013-12-05 17:24:50 -0800 | [diff] [blame] | 237 | FlowId result = fm.addFlow(flowPath); |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 238 | |
| 239 | // verify the test |
| 240 | verifyAll(); |
Pavlin Radoslavov | 051abb4 | 2013-12-05 17:24:50 -0800 | [diff] [blame] | 241 | assertNotNull(result); |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 242 | } |
Pavlin Radoslavov | f2a5265 | 2013-11-22 12:35:42 -0800 | [diff] [blame] | 243 | |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 244 | /** |
Pavlin Radoslavov | f2a5265 | 2013-11-22 12:35:42 -0800 | [diff] [blame] | 245 | * Test method for {@link FlowManager#deleteFlow(FlowId)}. |
| 246 | * @throws Exception |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 247 | */ |
| 248 | @Test |
Pavlin Radoslavov | f2a5265 | 2013-11-22 12:35:42 -0800 | [diff] [blame] | 249 | public final void testDeleteFlowSuccessNormally() throws Exception { |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 250 | // create mock objects |
Pavlin Radoslavov | f2a5265 | 2013-11-22 12:35:42 -0800 | [diff] [blame] | 251 | IFlowPath flowPath = createIFlowPathMock(123, "id", "FP_TYPE_SHORTEST_PATH", "FP_USER_ADD", 0, 1, 2, 3, 4); |
| 252 | IFlowEntry flowEntry1 = createMock(IFlowEntry.class); |
| 253 | IFlowEntry flowEntry2 = createMock(IFlowEntry.class); |
| 254 | IFlowEntry flowEntry3 = createMock(IFlowEntry.class); |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 255 | |
| 256 | // instantiate required objects |
Toshio Koide | ca7abe0 | 2013-06-27 17:30:17 -0700 | [diff] [blame] | 257 | FlowManager fm = new FlowManager(); |
Pavlin Radoslavov | f2a5265 | 2013-11-22 12:35:42 -0800 | [diff] [blame] | 258 | FlowId flowId = new FlowId(123); |
| 259 | ArrayList<IFlowEntry> flowEntries = new ArrayList<IFlowEntry>(); |
| 260 | flowEntries.add(flowEntry1); |
| 261 | flowEntries.add(flowEntry2); |
| 262 | flowEntries.add(flowEntry3); |
| 263 | |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 264 | // setup expectations |
| 265 | expectInitWithContext(); |
Pavlin Radoslavov | f2a5265 | 2013-11-22 12:35:42 -0800 | [diff] [blame] | 266 | expect(op.searchFlowPath(cmpEq(flowId))).andReturn(flowPath); |
| 267 | expect(flowPath.getFlowEntries()).andReturn(flowEntries); |
| 268 | flowPath.removeFlowEntry(flowEntry1); |
| 269 | flowPath.removeFlowEntry(flowEntry2); |
| 270 | flowPath.removeFlowEntry(flowEntry3); |
| 271 | op.removeFlowEntry(flowEntry1); |
| 272 | op.removeFlowEntry(flowEntry2); |
| 273 | op.removeFlowEntry(flowEntry3); |
| 274 | op.removeFlowPath(flowPath); |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 275 | op.commit(); |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 276 | |
| 277 | // start the test |
| 278 | replayAll(); |
| 279 | |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 280 | fm.init(context); |
Pavlin Radoslavov | f2a5265 | 2013-11-22 12:35:42 -0800 | [diff] [blame] | 281 | fm.deleteFlow(flowId); |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 282 | |
| 283 | // verify the test |
| 284 | verifyAll(); |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 285 | } |
| 286 | |
| 287 | /** |
| 288 | * Test method for {@link FlowManager#deleteFlow(FlowId)}. |
| 289 | * @throws Exception |
| 290 | */ |
| 291 | @Test |
| 292 | public final void testDeleteFlowSuccessEmptyFlowPath() throws Exception { |
Toshio Koide | ca7abe0 | 2013-06-27 17:30:17 -0700 | [diff] [blame] | 293 | // instantiate required objects |
| 294 | FlowManager fm = new FlowManager(); |
| 295 | |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 296 | // create mock objects |
| 297 | IFlowPath flowObj = createNiceMock(IFlowPath.class); |
| 298 | |
| 299 | // setup expectations |
| 300 | expectInitWithContext(); |
| 301 | expect(op.searchFlowPath(cmpEq(new FlowId(1)))).andReturn(flowObj); |
| 302 | expect(flowObj.getFlowEntries()).andReturn(new ArrayList<IFlowEntry>()); |
| 303 | op.removeFlowPath(flowObj); |
| 304 | op.commit(); |
| 305 | expectLastCall().anyTimes(); |
| 306 | |
| 307 | // start the test |
| 308 | replayAll(); |
| 309 | |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 310 | fm.init(context); |
| 311 | Boolean result = fm.deleteFlow(new FlowId(1)); |
| 312 | |
| 313 | // verify the test |
| 314 | verifyAll(); |
| 315 | assertTrue(result); |
| 316 | } |
| 317 | |
| 318 | /** |
Pavlin Radoslavov | f2a5265 | 2013-11-22 12:35:42 -0800 | [diff] [blame] | 319 | * Test method for {@link FlowManager#deleteAllFlows()}. |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 320 | * @throws Exception |
| 321 | */ |
| 322 | @Test |
Pavlin Radoslavov | f2a5265 | 2013-11-22 12:35:42 -0800 | [diff] [blame] | 323 | public final void testDeleteAllFlowsSuccessNormally() throws Exception { |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 324 | // create mock objects |
| 325 | IFlowPath flowPath1 = createNiceMock(IFlowPath.class); |
| 326 | IFlowPath flowPath2 = createNiceMock(IFlowPath.class); |
| 327 | IFlowPath flowPath3 = createNiceMock(IFlowPath.class); |
Pavlin Radoslavov | f2a5265 | 2013-11-22 12:35:42 -0800 | [diff] [blame] | 328 | FlowManager fm = createPartialMockAndInvokeDefaultConstructor(FlowManager.class, "deleteFlow"); |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 329 | |
| 330 | // instantiate required objects |
| 331 | ArrayList<IFlowPath> flowPaths = new ArrayList<IFlowPath>(); |
| 332 | flowPaths.add(flowPath1); |
| 333 | flowPaths.add(flowPath2); |
| 334 | flowPaths.add(null); |
| 335 | flowPaths.add(flowPath3); |
| 336 | |
| 337 | // setup expectations |
| 338 | expectInitWithContext(); |
| 339 | expect(op.getAllFlowPaths()).andReturn(flowPaths); |
| 340 | expect(flowPath1.getFlowId()).andReturn(new FlowId(1).toString()); |
| 341 | expect(flowPath2.getFlowId()).andReturn(null); |
| 342 | expect(flowPath3.getFlowId()).andReturn(new FlowId(3).toString()); |
Pavlin Radoslavov | f2a5265 | 2013-11-22 12:35:42 -0800 | [diff] [blame] | 343 | expect(fm.deleteFlow(cmpEq(new FlowId(1)))).andReturn(true); |
| 344 | expect(fm.deleteFlow(cmpEq(new FlowId(3)))).andReturn(true); |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 345 | |
| 346 | // start the test |
| 347 | replayAll(); |
| 348 | |
| 349 | fm.init(context); |
Pavlin Radoslavov | f2a5265 | 2013-11-22 12:35:42 -0800 | [diff] [blame] | 350 | Boolean result = fm.deleteAllFlows(); |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 351 | |
Pavlin Radoslavov | f2a5265 | 2013-11-22 12:35:42 -0800 | [diff] [blame] | 352 | // verify the test |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 353 | verifyAll(); |
| 354 | assertTrue(result); |
| 355 | } |
| 356 | |
| 357 | /** |
| 358 | * Test method for {@link FlowManager#getFlow()}. |
| 359 | * @throws Exception |
| 360 | */ |
| 361 | @Test |
| 362 | public final void testGetFlowSuccessNormally() throws Exception { |
| 363 | // instantiate required objects |
| 364 | FlowManager fm = new FlowManager(); |
Pavlin Radoslavov | 7d4a40e | 2013-10-27 23:39:40 -0700 | [diff] [blame] | 365 | IFlowPath iFlowPath = createIFlowPathMock(1, "caller id", "FP_TYPE_SHORTEST_PATH", "FP_USER_ADD", 0, 1, 1, 2, 2); |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 366 | |
| 367 | // setup expectations |
| 368 | expectInitWithContext(); |
Toshio Koide | ca7abe0 | 2013-06-27 17:30:17 -0700 | [diff] [blame] | 369 | expect(op.searchFlowPath(cmpEq(new FlowId(1)))).andReturn(iFlowPath); |
| 370 | expect(iFlowPath.getFlowEntries()).andReturn(new ArrayList<IFlowEntry>()).anyTimes(); |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 371 | op.commit(); |
| 372 | |
| 373 | // start the test |
| 374 | replayAll(); |
| 375 | |
| 376 | fm.init(context); |
Pavlin Radoslavov | 204b286 | 2013-07-12 14:15:36 -0700 | [diff] [blame] | 377 | FlowPath flowPath = fm.getFlow(new FlowId(1)); |
| 378 | String installerId = flowPath.installerId().toString(); |
Pavlin Radoslavov | d28cf7c | 2013-10-26 11:27:43 -0700 | [diff] [blame] | 379 | String flowPathType = flowPath.flowPathType().toString(); |
Pavlin Radoslavov | 7d4a40e | 2013-10-27 23:39:40 -0700 | [diff] [blame] | 380 | String flowPathUserState = flowPath.flowPathUserState().toString(); |
Pavlin Radoslavov | 204b286 | 2013-07-12 14:15:36 -0700 | [diff] [blame] | 381 | long flowPathFlags = flowPath.flowPathFlags().flags(); |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 382 | |
| 383 | //verify the test |
| 384 | verifyAll(); |
Pavlin Radoslavov | 204b286 | 2013-07-12 14:15:36 -0700 | [diff] [blame] | 385 | assertEquals("caller id", installerId); |
Pavlin Radoslavov | d28cf7c | 2013-10-26 11:27:43 -0700 | [diff] [blame] | 386 | assertEquals("FP_TYPE_SHORTEST_PATH", flowPathType); |
Pavlin Radoslavov | 7d4a40e | 2013-10-27 23:39:40 -0700 | [diff] [blame] | 387 | assertEquals("FP_USER_ADD", flowPathUserState); |
Pavlin Radoslavov | 204b286 | 2013-07-12 14:15:36 -0700 | [diff] [blame] | 388 | assertEquals(0L, flowPathFlags); |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 389 | } |
| 390 | |
| 391 | /** |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 392 | * Test method for {@link FlowManager#getAllFlowsSummary(FlowId, int)}. |
| 393 | * @throws Exception |
| 394 | */ |
| 395 | @Test |
| 396 | public final void testGetAllFlowsSummarySuccessNormally() throws Exception { |
Pavlin Radoslavov | 4ef6ba2 | 2013-11-22 19:32:58 -0800 | [diff] [blame] | 397 | final String getAllFlowsWithDataPathSummary = "getAllFlowsWithDataPathSummary"; |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 398 | // create mock objects |
Pavlin Radoslavov | 4ef6ba2 | 2013-11-22 19:32:58 -0800 | [diff] [blame] | 399 | FlowManager fm = createPartialMockAndInvokeDefaultConstructor(FlowManager.class, getAllFlowsWithDataPathSummary); |
| 400 | FlowPath flowPath1 = createTestFlowPath(1, "", "FP_TYPE_SHORTEST_PATH", "FP_USER_ADD", 0, 1, 2, 3, 4); |
| 401 | FlowPath flowPath2 = createTestFlowPath(5, "", "FP_TYPE_SHORTEST_PATH", "FP_USER_ADD", 0, 2, 3, 4, 5); |
| 402 | FlowPath flowPath3 = createTestFlowPath(10, "", "FP_TYPE_SHORTEST_PATH", "FP_USER_ADD", 0, 3, 4, 5, 6); |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 403 | |
| 404 | // instantiate required objects |
Pavlin Radoslavov | 4ef6ba2 | 2013-11-22 19:32:58 -0800 | [diff] [blame] | 405 | ArrayList<FlowPath> flows = new ArrayList<FlowPath>(); |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 406 | flows.add(flowPath3); |
| 407 | flows.add(flowPath1); |
| 408 | flows.add(flowPath2); |
| 409 | |
| 410 | // setup expectations |
| 411 | expectInitWithContext(); |
Pavlin Radoslavov | 4ef6ba2 | 2013-11-22 19:32:58 -0800 | [diff] [blame] | 412 | expectPrivate(fm, getAllFlowsWithDataPathSummary).andReturn(flows); |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 413 | |
| 414 | // start the test |
| 415 | replayAll(); |
| 416 | |
| 417 | fm.init(context); |
Pavlin Radoslavov | 4ef6ba2 | 2013-11-22 19:32:58 -0800 | [diff] [blame] | 418 | ArrayList<FlowPath> returnedFlows = fm.getAllFlowsSummary(null, 0); |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 419 | |
| 420 | // verify the test |
| 421 | verifyAll(); |
| 422 | assertEquals(3, returnedFlows.size()); |
Pavlin Radoslavov | 4ef6ba2 | 2013-11-22 19:32:58 -0800 | [diff] [blame] | 423 | assertEquals(1, new FlowId(returnedFlows.get(0).flowId().value()).value()); |
| 424 | assertEquals(5, new FlowId(returnedFlows.get(1).flowId().value()).value()); |
| 425 | assertEquals(10, new FlowId(returnedFlows.get(2).flowId().value()).value()); |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 426 | } |
| 427 | |
| 428 | /** |
| 429 | * Test method for {@link FlowManager#getAllFlows()}. |
| 430 | * @throws Exception |
| 431 | */ |
| 432 | @Test |
| 433 | public final void testGetAllFlowsSuccessNormally() throws Exception { |
Toshio Koide | ca7abe0 | 2013-06-27 17:30:17 -0700 | [diff] [blame] | 434 | // create mock objects |
Pavlin Radoslavov | 7d4a40e | 2013-10-27 23:39:40 -0700 | [diff] [blame] | 435 | IFlowPath iFlowPath1 = createIFlowPathMock(1, "caller id", "FP_TYPE_SHORTEST_PATH", "FP_USER_ADD", 0, 1, 1, 2, 2); |
| 436 | IFlowPath iFlowPath2 = createIFlowPathMock(2, "caller id", "FP_TYPE_SHORTEST_PATH", "FP_USER_ADD", 0, 2, 5, 3, 5); |
Toshio Koide | ca7abe0 | 2013-06-27 17:30:17 -0700 | [diff] [blame] | 437 | |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 438 | // instantiate required objects |
| 439 | ArrayList<IFlowPath> flowPaths = new ArrayList<IFlowPath>(); |
Toshio Koide | ca7abe0 | 2013-06-27 17:30:17 -0700 | [diff] [blame] | 440 | flowPaths.add(iFlowPath1); |
| 441 | flowPaths.add(iFlowPath2); |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 442 | FlowManager fm = new FlowManager(); |
| 443 | |
| 444 | // setup expectations |
| 445 | expectInitWithContext(); |
| 446 | expect(op.getAllFlowPaths()).andReturn(flowPaths); |
Toshio Koide | ca7abe0 | 2013-06-27 17:30:17 -0700 | [diff] [blame] | 447 | expect(iFlowPath1.getFlowEntries()).andReturn(new ArrayList<IFlowEntry>()).anyTimes(); |
| 448 | expect(iFlowPath2.getFlowEntries()).andReturn(new ArrayList<IFlowEntry>()).anyTimes(); |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 449 | op.commit(); |
| 450 | |
| 451 | // start the test |
| 452 | replayAll(); |
| 453 | |
| 454 | fm.init(context); |
| 455 | ArrayList<FlowPath> flows = fm.getAllFlows(); |
| 456 | |
| 457 | // verify the test |
| 458 | verifyAll(); |
| 459 | assertEquals(2, flows.size()); |
| 460 | assertEquals(new SwitchPort(new Dpid(1), new Port((short)1)).toString(), |
| 461 | flows.get(0).dataPath().srcPort().toString()); |
| 462 | assertEquals(new SwitchPort(new Dpid(2), new Port((short)5)).toString(), |
| 463 | flows.get(1).dataPath().srcPort().toString()); |
| 464 | // TODO: more asserts |
| 465 | // TODO: ignore seq. of the list |
| 466 | } |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 467 | |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 468 | // INetMapStorage methods |
| 469 | |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 470 | /** |
| 471 | * Test method for {@link FlowManager#init(String)}. |
| 472 | * @throws Exception |
| 473 | */ |
| 474 | @Test |
| 475 | public final void testInitSuccessNormally() throws Exception { |
Toshio Koide | ca7abe0 | 2013-06-27 17:30:17 -0700 | [diff] [blame] | 476 | // instantiate required objects |
| 477 | FlowManager fm = new FlowManager(); |
| 478 | |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 479 | // create mock objects |
| 480 | op = createMock(GraphDBOperation.class); |
| 481 | |
| 482 | // setup expectations |
| 483 | expectNew(GraphDBOperation.class, "/dummy/path").andReturn(op); |
| 484 | |
| 485 | // start the test |
| 486 | replayAll(); |
| 487 | |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 488 | fm.init("/dummy/path"); |
| 489 | |
| 490 | // verify the test |
| 491 | verifyAll(); |
| 492 | } |
| 493 | |
| 494 | /** |
| 495 | * Test method for {@link FlowManager#close()}. |
| 496 | * @throws Exception |
| 497 | */ |
| 498 | @Test |
| 499 | public final void testCloseSuccessNormally() throws Exception { |
| 500 | // instantiate required objects |
| 501 | FlowManager fm = new FlowManager(); |
| 502 | |
| 503 | // setup expectations |
| 504 | expectInitWithContext(); |
| 505 | op.close(); |
| 506 | |
| 507 | // start the test |
| 508 | replayAll(); |
| 509 | |
| 510 | fm.init(context); |
| 511 | fm.close(); |
| 512 | |
| 513 | // verify the test |
| 514 | verifyAll(); |
| 515 | } |
| 516 | |
| 517 | |
| 518 | // IFloodlightModule methods |
| 519 | |
| 520 | |
| 521 | /** |
| 522 | * Test method for {@link FlowManager#getModuleServices()}. |
| 523 | * @throws Exception |
| 524 | */ |
| 525 | @Test |
| 526 | public final void testGetModuleServicesSuccessNormally() throws Exception { |
| 527 | // instantiate required objects |
| 528 | FlowManager fm = new FlowManager(); |
| 529 | |
| 530 | // setup expectations |
| 531 | expectInitWithContext(); |
| 532 | |
| 533 | // start the test |
| 534 | replayAll(); |
| 535 | |
| 536 | fm.init(context); |
| 537 | Collection<Class<? extends IFloodlightService>> l = fm.getModuleServices(); |
| 538 | |
| 539 | // verify the test |
| 540 | verifyAll(); |
| 541 | assertEquals(1, l.size()); |
| 542 | assertEquals(IFlowService.class, l.iterator().next()); |
| 543 | } |
| 544 | |
| 545 | /** |
| 546 | * Test method for {@link FlowManager#getServiceImpls()}. |
| 547 | * @throws Exception |
| 548 | */ |
| 549 | @Test |
| 550 | public final void testGetServiceImplsSuccessNormally() throws Exception { |
| 551 | // instantiate required objects |
| 552 | FlowManager fm = new FlowManager(); |
| 553 | |
| 554 | // setup expectations |
| 555 | expectInitWithContext(); |
| 556 | |
| 557 | // start the test |
| 558 | replayAll(); |
| 559 | |
| 560 | fm.init(context); |
| 561 | Map<Class<? extends IFloodlightService>, IFloodlightService> si = fm.getServiceImpls(); |
| 562 | |
| 563 | // verify the test |
| 564 | verifyAll(); |
| 565 | assertEquals(1, si.size()); |
| 566 | assertTrue(si.containsKey(IFlowService.class)); |
| 567 | assertEquals(fm, si.get(IFlowService.class)); |
| 568 | } |
| 569 | |
| 570 | /** |
| 571 | * Test method for {@link FlowManager#getModuleDependencies()}. |
| 572 | * @throws Exception |
| 573 | */ |
| 574 | @Test |
| 575 | public final void testGetModuleDependenciesSuccessNormally() throws Exception { |
| 576 | // instantiate required objects |
| 577 | FlowManager fm = new FlowManager(); |
| 578 | |
| 579 | // setup expectations |
| 580 | expectInitWithContext(); |
| 581 | |
| 582 | // start the test |
| 583 | replayAll(); |
| 584 | |
| 585 | fm.init(context); |
| 586 | Collection<Class<? extends IFloodlightService>> md = fm.getModuleDependencies(); |
| 587 | |
| 588 | // verify the test |
| 589 | verifyAll(); |
Pavlin Radoslavov | 0537827 | 2013-10-19 23:23:05 -0700 | [diff] [blame] | 590 | assertEquals(4, md.size()); |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 591 | assertTrue(md.contains(IFloodlightProviderService.class)); |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 592 | assertTrue(md.contains(IRestApiService.class)); |
| 593 | } |
| 594 | |
| 595 | /** |
| 596 | * Test method for {@link FlowManager#init(FloodlightModuleContext)}. |
| 597 | * @throws Exception |
| 598 | */ |
| 599 | @Test |
| 600 | public final void testInitWithFloodlightModuleContextSuccessNormally() throws Exception { |
| 601 | // instantiate required objects |
| 602 | FlowManager fm = new FlowManager(); |
| 603 | |
| 604 | // setup expectations |
| 605 | expectInitWithContext(); |
| 606 | |
| 607 | // start the test |
| 608 | replayAll(); |
| 609 | |
| 610 | fm.init(context); |
| 611 | |
| 612 | // verify the test |
| 613 | verifyAll(); |
| 614 | } |
| 615 | |
| 616 | /** |
| 617 | * Test method for {@link FlowManager#startUp(FloodlightModuleContext)}. |
| 618 | * @throws Exception |
| 619 | */ |
| 620 | @Test |
| 621 | public final void testStartupSuccessNormally() throws Exception { |
| 622 | // create mock objects |
| 623 | mockStaticPartial(Executors.class, "newScheduledThreadPool"); |
| 624 | ScheduledExecutorService scheduler = createMock(ScheduledExecutorService.class); |
| 625 | |
Toshio Koide | fe2625e | 2013-06-26 13:59:53 -0700 | [diff] [blame] | 626 | // instantiate required objects |
| 627 | FlowManager fm = new FlowManager(); |
| 628 | |
| 629 | // setup expectations |
| 630 | expectInitWithContext(); |
| 631 | expect(Executors.newScheduledThreadPool(1)).andReturn(scheduler); |
| 632 | expect(Executors.newScheduledThreadPool(1)).andReturn(scheduler); |
| 633 | expect(scheduler.scheduleAtFixedRate( |
| 634 | EasyMock.anyObject(Runnable.class), |
| 635 | EasyMock.anyLong(), |
| 636 | EasyMock.anyLong(), |
| 637 | EasyMock.anyObject(TimeUnit.class))).andReturn(null).times(2); |
| 638 | restApi.addRestletRoutable(EasyMock.anyObject(FlowWebRoutable.class)); |
| 639 | |
| 640 | // start the test |
| 641 | replayAll(); |
| 642 | |
| 643 | fm.init(context); |
| 644 | fm.startUp(context); |
| 645 | |
| 646 | // verify the test |
| 647 | verifyAll(); |
| 648 | } |
Toshio Koide | ca7abe0 | 2013-06-27 17:30:17 -0700 | [diff] [blame] | 649 | |
| 650 | |
| 651 | // other methods |
| 652 | |
Toshio Koide | ca7abe0 | 2013-06-27 17:30:17 -0700 | [diff] [blame] | 653 | /** |
Toshio Koide | ca7abe0 | 2013-06-27 17:30:17 -0700 | [diff] [blame] | 654 | * Test method for {@link FlowManager#reconcileFlow(IFlowPath, DataPath)}. |
| 655 | * @throws Exception |
| 656 | */ |
| 657 | @Test |
| 658 | public final void testReconcileFlowWithFlowPathAndDataPathSuccessNormally() throws Exception { |
| 659 | final String addFlowEntry = "addFlowEntry"; |
| 660 | |
| 661 | // create mock objects |
Pavlin Radoslavov | 7d4a40e | 2013-10-27 23:39:40 -0700 | [diff] [blame] | 662 | IFlowPath iFlowPath1 = createIFlowPathMock(1, "caller id", "FP_TYPE_SHORTEST_PATH", "FP_USER_ADD", 0, 1, 1, 2, 2); |
Toshio Koide | ca7abe0 | 2013-06-27 17:30:17 -0700 | [diff] [blame] | 663 | IFlowEntry iFlowEntry1 = createMock(IFlowEntry.class); |
| 664 | IFlowEntry iFlowEntry2 = createMock(IFlowEntry.class); |
| 665 | FlowManager fm = createPartialMockAndInvokeDefaultConstructor(FlowManager.class, addFlowEntry); |
| 666 | |
| 667 | // instantiate required objects |
| 668 | FlowEntry flowEntry1 = new FlowEntry(); |
| 669 | flowEntry1.setDpid(new Dpid(1)); |
| 670 | flowEntry1.setFlowId(new FlowId(1)); |
| 671 | flowEntry1.setInPort(new Port((short) 1)); |
| 672 | flowEntry1.setOutPort(new Port((short) 11)); |
| 673 | flowEntry1.setFlowEntryId(new FlowEntryId(1)); |
| 674 | flowEntry1.setFlowEntryMatch(new FlowEntryMatch()); |
Pavlin Radoslavov | 1bc2c47 | 2013-07-17 18:11:37 -0700 | [diff] [blame] | 675 | flowEntry1.setFlowEntryActions(new FlowEntryActions()); |
Toshio Koide | ca7abe0 | 2013-06-27 17:30:17 -0700 | [diff] [blame] | 676 | flowEntry1.setFlowEntryErrorState(new FlowEntryErrorState()); |
| 677 | |
| 678 | FlowEntry flowEntry2 = new FlowEntry(); |
| 679 | flowEntry2.setDpid(new Dpid(2)); |
| 680 | flowEntry2.setFlowId(new FlowId(2)); |
| 681 | flowEntry2.setInPort(new Port((short) 22)); |
| 682 | flowEntry2.setOutPort(new Port((short) 2)); |
| 683 | flowEntry2.setFlowEntryId(new FlowEntryId(2)); |
| 684 | flowEntry2.setFlowEntryMatch(new FlowEntryMatch()); |
Pavlin Radoslavov | 1bc2c47 | 2013-07-17 18:11:37 -0700 | [diff] [blame] | 685 | flowEntry2.setFlowEntryActions(new FlowEntryActions()); |
Toshio Koide | ca7abe0 | 2013-06-27 17:30:17 -0700 | [diff] [blame] | 686 | flowEntry2.setFlowEntryErrorState(new FlowEntryErrorState()); |
| 687 | |
| 688 | DataPath dataPath = new DataPath(); |
| 689 | ArrayList<FlowEntry> flowEntries = new ArrayList<FlowEntry>(); |
| 690 | flowEntries.add(flowEntry1); |
| 691 | flowEntries.add(flowEntry2); |
| 692 | dataPath.setFlowEntries(flowEntries); |
| 693 | |
| 694 | ArrayList<IFlowEntry> oldFlowEntries = new ArrayList<IFlowEntry>(); |
| 695 | oldFlowEntries.add(iFlowEntry1); |
| 696 | oldFlowEntries.add(iFlowEntry2); |
| 697 | |
| 698 | // setup expectations |
| 699 | expectInitWithContext(); |
Toshio Koide | ca7abe0 | 2013-06-27 17:30:17 -0700 | [diff] [blame] | 700 | expect(iFlowPath1.getFlowEntries()).andReturn(oldFlowEntries); |
| 701 | iFlowEntry1.setUserState("FE_USER_DELETE"); |
| 702 | iFlowEntry1.setSwitchState("FE_SWITCH_NOT_UPDATED"); |
| 703 | iFlowEntry2.setUserState("FE_USER_DELETE"); |
| 704 | iFlowEntry2.setSwitchState("FE_SWITCH_NOT_UPDATED"); |
| 705 | expectPrivate(fm, addFlowEntry, iFlowPath1, flowEntry1).andReturn(null); |
| 706 | expectPrivate(fm, addFlowEntry, iFlowPath1, flowEntry2).andReturn(null); |
| 707 | |
| 708 | // start the test |
| 709 | replayAll(); |
| 710 | |
| 711 | fm.init(context); |
Pavlin Radoslavov | 1308dc6 | 2013-10-25 15:54:31 -0700 | [diff] [blame] | 712 | // Use reflection to test the private method |
| 713 | // Boolean result = fm.reconcileFlow(iFlowPath1, dataPath); |
Naoki Shiota | 991093a | 2013-12-10 14:47:18 -0800 | [diff] [blame^] | 714 | Class<?> fmClass = FlowManager.class; |
Pavlin Radoslavov | 1308dc6 | 2013-10-25 15:54:31 -0700 | [diff] [blame] | 715 | Method method = fmClass.getDeclaredMethod( |
| 716 | "reconcileFlow", |
| 717 | new Class[] { IFlowPath.class, DataPath.class }); |
| 718 | method.setAccessible(true); |
| 719 | Boolean result = (Boolean)method.invoke(fm, |
| 720 | new Object[] { iFlowPath1, dataPath }); |
Toshio Koide | ca7abe0 | 2013-06-27 17:30:17 -0700 | [diff] [blame] | 721 | |
| 722 | // verify the test |
| 723 | verifyAll(); |
| 724 | assertTrue(result); |
| 725 | // TODO: write more asserts |
| 726 | } |
| 727 | |
| 728 | /** |
| 729 | * Test method for {@link FlowManager#installFlowEntry(net.floodlightcontroller.core.IOFSwitch, IFlowPath, IFlowEntry)}. |
| 730 | * @throws Exception |
| 731 | */ |
| 732 | @Test |
| 733 | public final void testInstallFlowEntryWithIFlowPathSuccessNormally() throws Exception { |
| 734 | // create mock object |
| 735 | IOFSwitch iofSwitch = createNiceMock(IOFSwitch.class); |
Pavlin Radoslavov | 7d4a40e | 2013-10-27 23:39:40 -0700 | [diff] [blame] | 736 | IFlowPath iFlowPath = createIFlowPathMock(1, "id", "FP_TYPE_SHORTEST_PATH", "FP_USER_ADD", 0, 1, 2, 3, 4); |
Toshio Koide | ca7abe0 | 2013-06-27 17:30:17 -0700 | [diff] [blame] | 737 | IFlowEntry iFlowEntry = createMock(IFlowEntry.class); |
| 738 | BasicFactory basicFactory = createMock(BasicFactory.class); |
| 739 | |
| 740 | // instantiate required objects |
| 741 | FlowManager fm = new FlowManager(); |
| 742 | |
Pavlin Radoslavov | 1bc2c47 | 2013-07-17 18:11:37 -0700 | [diff] [blame] | 743 | FlowEntryAction action = new FlowEntryAction(); |
| 744 | action.setActionOutput(new Port((short)2)); |
| 745 | FlowEntryActions actions = new FlowEntryActions(); |
| 746 | actions.addAction(action); |
| 747 | |
Toshio Koide | ca7abe0 | 2013-06-27 17:30:17 -0700 | [diff] [blame] | 748 | // setup expectations |
| 749 | expectInitWithContext(); |
| 750 | expect(iFlowEntry.getFlowEntryId()).andReturn(new FlowEntryId(123).toString()); |
| 751 | expect(iFlowEntry.getUserState()).andReturn("FE_USER_ADD"); |
| 752 | iFlowEntry.setSwitchState("FE_SWITCH_UPDATED"); |
| 753 | expect(iFlowEntry.getMatchInPort()).andReturn(new Short((short) 1)); |
Toshio Koide | ca7abe0 | 2013-06-27 17:30:17 -0700 | [diff] [blame] | 754 | expect(iFlowEntry.getMatchSrcMac()).andReturn("01:23:45:67:89:01"); |
| 755 | expect(iFlowEntry.getMatchDstMac()).andReturn("01:23:45:67:89:02"); |
Pavlin Radoslavov | ad3a1e6 | 2013-07-09 13:30:16 -0700 | [diff] [blame] | 756 | expect(iFlowEntry.getMatchEthernetFrameType()).andReturn(new Short((short)0x0800)); |
| 757 | expect(iFlowEntry.getMatchVlanId()).andReturn(new Short((short)0x1234)); |
| 758 | expect(iFlowEntry.getMatchVlanPriority()).andReturn(new Byte((byte)0x10)); |
| 759 | expect(iFlowEntry.getMatchSrcIPv4Net()).andReturn("192.168.0.1"); |
| 760 | expect(iFlowEntry.getMatchDstIPv4Net()).andReturn("192.168.0.2"); |
| 761 | expect(iFlowEntry.getMatchIpProto()).andReturn(new Byte((byte)0x20)); |
| 762 | expect(iFlowEntry.getMatchIpToS()).andReturn(new Byte((byte)0x3)); |
| 763 | expect(iFlowEntry.getMatchSrcTcpUdpPort()).andReturn(new Short((short)40000)); |
| 764 | expect(iFlowEntry.getMatchDstTcpUdpPort()).andReturn(new Short((short)80)); |
Pavlin Radoslavov | 1bc2c47 | 2013-07-17 18:11:37 -0700 | [diff] [blame] | 765 | expect(iFlowEntry.getActions()).andReturn(actions.toString()); |
Toshio Koide | ca7abe0 | 2013-06-27 17:30:17 -0700 | [diff] [blame] | 766 | expect(floodlightProvider.getOFMessageFactory()).andReturn(basicFactory); |
| 767 | expect(basicFactory.getMessage(OFType.FLOW_MOD)).andReturn(new OFFlowMod()); |
| 768 | expect(iofSwitch.getStringId()).andReturn(new Dpid(100).toString()); |
| 769 | |
| 770 | // start the test |
| 771 | replayAll(); |
| 772 | |
| 773 | fm.init(context); |
Pavlin Radoslavov | 1308dc6 | 2013-10-25 15:54:31 -0700 | [diff] [blame] | 774 | // Use reflection to test the private method |
| 775 | // Boolean result = fm.installFlowEntry(iofSwitch, iFlowPath, iFlowEntry); |
Naoki Shiota | 991093a | 2013-12-10 14:47:18 -0800 | [diff] [blame^] | 776 | Class<?> fmClass = FlowManager.class; |
Pavlin Radoslavov | 1308dc6 | 2013-10-25 15:54:31 -0700 | [diff] [blame] | 777 | Method method = fmClass.getDeclaredMethod( |
| 778 | "installFlowEntry", |
| 779 | new Class[] { IOFSwitch.class, IFlowPath.class, IFlowEntry.class }); |
| 780 | method.setAccessible(true); |
| 781 | Boolean result = (Boolean)method.invoke(fm, |
| 782 | new Object[] { iofSwitch, iFlowPath, iFlowEntry }); |
| 783 | |
Toshio Koide | ca7abe0 | 2013-06-27 17:30:17 -0700 | [diff] [blame] | 784 | |
| 785 | // verify the test |
| 786 | verifyAll(); |
| 787 | assertTrue(result); |
| 788 | // TODO: write more asserts |
| 789 | } |
| 790 | |
| 791 | /** |
| 792 | * Test method for {@link FlowManager#installFlowEntry(net.floodlightcontroller.core.IOFSwitch, FlowPath, FlowEntry)}. |
| 793 | * The method seems to be not used for now. |
| 794 | */ |
| 795 | @Ignore @Test |
| 796 | public final void testInstallFlowEntryWithFlowPathSuccessNormally() { |
| 797 | fail("not yet implemented"); |
| 798 | } |
| 799 | |
| 800 | /** |
| 801 | * Test method for {@link FlowManager#removeFlowEntry(net.floodlightcontroller.core.IOFSwitch, FlowPath, FlowEntry)}. |
| 802 | * The method seems to be not implemented and not used for now. |
| 803 | */ |
| 804 | @Ignore @Test |
| 805 | public final void testRemoveFlowEntrySuccessNormally() { |
| 806 | fail("not yet implemented"); |
| 807 | } |
Pavlin Radoslavov | ddd01ba | 2013-07-03 15:40:44 -0700 | [diff] [blame] | 808 | } |