Jonathan Hart | aa38097 | 2014-04-03 10:24:46 -0700 | [diff] [blame] | 1 | package net.onrc.onos.core.intent.runtime; |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 2 | |
Jonathan Hart | a88fd24 | 2014-04-03 11:24:54 -0700 | [diff] [blame] | 3 | import static org.easymock.EasyMock.anyObject; |
| 4 | import static org.easymock.EasyMock.createMock; |
| 5 | import static org.easymock.EasyMock.eq; |
| 6 | import static org.easymock.EasyMock.expect; |
| 7 | import static org.easymock.EasyMock.expectLastCall; |
| 8 | import static org.easymock.EasyMock.replay; |
| 9 | import static org.easymock.EasyMock.verify; |
Toshio Koide | 066506e | 2014-02-20 19:52:09 -0800 | [diff] [blame] | 10 | |
Pavlin Radoslavov | 74986ce | 2014-02-20 13:17:20 -0800 | [diff] [blame] | 11 | import java.util.LinkedList; |
Brian O'Connor | 12861f7 | 2014-02-19 20:40:32 -0800 | [diff] [blame] | 12 | import java.util.List; |
| 13 | import java.util.Set; |
| 14 | |
Toshio Koide | 27ffd41 | 2014-02-18 19:15:27 -0800 | [diff] [blame] | 15 | import net.floodlightcontroller.core.module.FloodlightModuleContext; |
| 16 | import net.floodlightcontroller.core.module.FloodlightModuleException; |
Pavlin Radoslavov | 1366905 | 2014-05-13 10:33:39 -0700 | [diff] [blame] | 17 | import net.floodlightcontroller.restserver.IRestApiService; |
| 18 | |
Jonathan Hart | 6df9017 | 2014-04-03 10:13:11 -0700 | [diff] [blame] | 19 | import net.onrc.onos.core.datagrid.IDatagridService; |
| 20 | import net.onrc.onos.core.datagrid.IEventChannel; |
| 21 | import net.onrc.onos.core.datagrid.IEventChannelListener; |
Jonathan Hart | aa38097 | 2014-04-03 10:24:46 -0700 | [diff] [blame] | 22 | import net.onrc.onos.core.intent.ConstrainedShortestPathIntent; |
| 23 | import net.onrc.onos.core.intent.FlowEntry; |
| 24 | import net.onrc.onos.core.intent.Intent; |
Jonathan Hart | a88fd24 | 2014-04-03 11:24:54 -0700 | [diff] [blame] | 25 | import net.onrc.onos.core.intent.Intent.IntentState; |
| 26 | import net.onrc.onos.core.intent.IntentOperation.Operator; |
Jonathan Hart | aa38097 | 2014-04-03 10:24:46 -0700 | [diff] [blame] | 27 | import net.onrc.onos.core.intent.IntentOperationList; |
| 28 | import net.onrc.onos.core.intent.MockNetworkGraph; |
| 29 | import net.onrc.onos.core.intent.PathIntent; |
| 30 | import net.onrc.onos.core.intent.PathIntentMap; |
| 31 | import net.onrc.onos.core.intent.ShortestPathIntent; |
Pavlin Radoslavov | 1366905 | 2014-05-13 10:33:39 -0700 | [diff] [blame] | 32 | import net.onrc.onos.core.intent.runtime.web.IntentWebRoutable; |
Jonathan Hart | deda0ba | 2014-04-03 11:14:12 -0700 | [diff] [blame] | 33 | import net.onrc.onos.core.registry.IControllerRegistryService; |
Jonathan Hart | 472062d | 2014-04-03 10:56:48 -0700 | [diff] [blame] | 34 | import net.onrc.onos.core.topology.DeviceEvent; |
| 35 | import net.onrc.onos.core.topology.INetworkGraphListener; |
| 36 | import net.onrc.onos.core.topology.INetworkGraphService; |
| 37 | import net.onrc.onos.core.topology.LinkEvent; |
| 38 | import net.onrc.onos.core.topology.NetworkGraph; |
| 39 | import net.onrc.onos.core.topology.PortEvent; |
| 40 | import net.onrc.onos.core.topology.SwitchEvent; |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 41 | |
| 42 | import org.junit.After; |
| 43 | import org.junit.Before; |
| 44 | import org.junit.Test; |
Nick Karanatsios | 8abe717 | 2014-02-19 20:31:48 -0800 | [diff] [blame] | 45 | import org.junit.runner.RunWith; |
| 46 | import org.powermock.api.easymock.PowerMock; |
| 47 | import org.powermock.core.classloader.annotations.PrepareForTest; |
| 48 | import org.powermock.modules.junit4.PowerMockRunner; |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 49 | |
| 50 | /** |
Toshio Koide | e04a9df | 2014-05-01 15:49:28 -0700 | [diff] [blame] | 51 | * Temporary test cases for the ONS2014 demo. |
| 52 | * These test cases should be modified and be moved to appropriate classes |
| 53 | * (ex. PathCalcRuntimeModuleTest, PlanInstallModuleTest, etc.) |
| 54 | * |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 55 | * @author Toshio Koide (t-koide@onlab.us) |
| 56 | */ |
Nick Karanatsios | 8abe717 | 2014-02-19 20:31:48 -0800 | [diff] [blame] | 57 | @RunWith(PowerMockRunner.class) |
| 58 | @PrepareForTest(PathCalcRuntimeModule.class) |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 59 | public class UseCaseTest { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 60 | private NetworkGraph g; |
| 61 | private FloodlightModuleContext modContext; |
| 62 | private IDatagridService datagridService; |
| 63 | private INetworkGraphService networkGraphService; |
| 64 | private IControllerRegistryService controllerRegistryService; |
| 65 | private PersistIntent persistIntent; |
Pavlin Radoslavov | 1366905 | 2014-05-13 10:33:39 -0700 | [diff] [blame] | 66 | private IRestApiService restApi; |
Toshio Koide | e04a9df | 2014-05-01 15:49:28 -0700 | [diff] [blame] | 67 | private IEventChannel<Long, IntentOperationList> intentOperationChannel; |
| 68 | private IEventChannel<Long, IntentStateList> intentStateChannel; |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 69 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 70 | private static Long LOCAL_PORT = 0xFFFEL; |
Toshio Koide | fe1d5d9 | 2014-02-26 20:09:48 -0800 | [diff] [blame] | 71 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 72 | @SuppressWarnings("unchecked") |
| 73 | @Before |
| 74 | public void setUp() throws Exception { |
| 75 | MockNetworkGraph graph = new MockNetworkGraph(); |
| 76 | graph.createSampleTopology1(); |
| 77 | g = graph; |
Toshio Koide | 27ffd41 | 2014-02-18 19:15:27 -0800 | [diff] [blame] | 78 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 79 | datagridService = createMock(IDatagridService.class); |
| 80 | networkGraphService = createMock(INetworkGraphService.class); |
| 81 | controllerRegistryService = createMock(IControllerRegistryService.class); |
| 82 | modContext = createMock(FloodlightModuleContext.class); |
Toshio Koide | e04a9df | 2014-05-01 15:49:28 -0700 | [diff] [blame] | 83 | intentOperationChannel = createMock(IEventChannel.class); |
| 84 | intentStateChannel = createMock(IEventChannel.class); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 85 | persistIntent = PowerMock.createMock(PersistIntent.class); |
Pavlin Radoslavov | 1366905 | 2014-05-13 10:33:39 -0700 | [diff] [blame] | 86 | restApi = createMock(IRestApiService.class); |
Toshio Koide | 798bc1b | 2014-02-20 14:02:40 -0800 | [diff] [blame] | 87 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 88 | PowerMock.expectNew(PersistIntent.class, |
Pavlin Radoslavov | 0294e05 | 2014-04-10 13:36:45 -0700 | [diff] [blame] | 89 | anyObject(IControllerRegistryService.class)).andReturn(persistIntent); |
Toshio Koide | 27ffd41 | 2014-02-18 19:15:27 -0800 | [diff] [blame] | 90 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 91 | expect(modContext.getServiceImpl(IDatagridService.class)) |
| 92 | .andReturn(datagridService).once(); |
| 93 | expect(modContext.getServiceImpl(INetworkGraphService.class)) |
| 94 | .andReturn(networkGraphService).once(); |
| 95 | expect(modContext.getServiceImpl(IControllerRegistryService.class)) |
| 96 | .andReturn(controllerRegistryService).once(); |
| 97 | expect(persistIntent.getKey()).andReturn(1L).anyTimes(); |
| 98 | expect(persistIntent.persistIfLeader(eq(1L), |
| 99 | anyObject(IntentOperationList.class))).andReturn(true).anyTimes(); |
Pavlin Radoslavov | 1366905 | 2014-05-13 10:33:39 -0700 | [diff] [blame] | 100 | expect(modContext.getServiceImpl(IRestApiService.class)) |
| 101 | .andReturn(restApi).once(); |
Toshio Koide | 0c9106d | 2014-02-19 15:26:38 -0800 | [diff] [blame] | 102 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 103 | expect(networkGraphService.getNetworkGraph()).andReturn(g).anyTimes(); |
| 104 | networkGraphService.registerNetworkGraphListener(anyObject(INetworkGraphListener.class)); |
| 105 | expectLastCall(); |
Toshio Koide | 0c9106d | 2014-02-19 15:26:38 -0800 | [diff] [blame] | 106 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 107 | expect(datagridService.createChannel("onos.pathintent", Long.class, IntentOperationList.class)) |
Toshio Koide | e04a9df | 2014-05-01 15:49:28 -0700 | [diff] [blame] | 108 | .andReturn(intentOperationChannel).once(); |
Toshio Koide | 27ffd41 | 2014-02-18 19:15:27 -0800 | [diff] [blame] | 109 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 110 | expect(datagridService.addListener( |
| 111 | eq("onos.pathintent_state"), |
| 112 | anyObject(IEventChannelListener.class), |
| 113 | eq(Long.class), |
| 114 | eq(IntentStateList.class))) |
Toshio Koide | e04a9df | 2014-05-01 15:49:28 -0700 | [diff] [blame] | 115 | .andReturn(intentStateChannel).once(); |
Pavlin Radoslavov | 1366905 | 2014-05-13 10:33:39 -0700 | [diff] [blame] | 116 | restApi.addRestletRoutable(anyObject(IntentWebRoutable.class)); |
Toshio Koide | 066506e | 2014-02-20 19:52:09 -0800 | [diff] [blame] | 117 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 118 | replay(datagridService); |
| 119 | replay(networkGraphService); |
| 120 | replay(modContext); |
| 121 | replay(controllerRegistryService); |
| 122 | PowerMock.replay(persistIntent, PersistIntent.class); |
Pavlin Radoslavov | 1366905 | 2014-05-13 10:33:39 -0700 | [diff] [blame] | 123 | replay(restApi); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 124 | } |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 125 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 126 | @After |
| 127 | public void tearDown() { |
| 128 | verify(datagridService); |
| 129 | verify(networkGraphService); |
| 130 | verify(modContext); |
| 131 | verify(controllerRegistryService); |
| 132 | PowerMock.verify(persistIntent, PersistIntent.class); |
Pavlin Radoslavov | 1366905 | 2014-05-13 10:33:39 -0700 | [diff] [blame] | 133 | verify(restApi); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 134 | } |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 135 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 136 | private void showResult(PathIntentMap intents) { |
| 137 | for (Intent intent : intents.getAllIntents()) { |
| 138 | PathIntent pathIntent = (PathIntent) intent; |
| 139 | System.out.println("Path intent:" + pathIntent); |
| 140 | System.out.println("Parent intent: " + pathIntent.getParentIntent().toString()); |
| 141 | } |
| 142 | } |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 143 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 144 | @Test |
| 145 | public void createShortestPaths() throws FloodlightModuleException { |
| 146 | // create shortest path intents |
| 147 | IntentOperationList opList = new IntentOperationList(); |
| 148 | opList.add(Operator.ADD, new ShortestPathIntent("1", 1L, 12L, LOCAL_PORT, 2L, 21L, LOCAL_PORT)); |
| 149 | opList.add(Operator.ADD, new ShortestPathIntent("2", 1L, 14L, LOCAL_PORT, 4L, 41L, LOCAL_PORT)); |
| 150 | opList.add(Operator.ADD, new ShortestPathIntent("3", 2L, 23L, LOCAL_PORT, 3L, 32L, LOCAL_PORT)); |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 151 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 152 | // compile high-level intent operations into low-level intent operations (calculate paths) |
| 153 | PathCalcRuntimeModule runtime1 = new PathCalcRuntimeModule(); |
| 154 | runtime1.init(modContext); |
| 155 | runtime1.startUp(modContext); |
| 156 | IntentOperationList pathIntentOpList = runtime1.executeIntentOperations(opList); |
Toshio Koide | 27ffd41 | 2014-02-18 19:15:27 -0800 | [diff] [blame] | 157 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 158 | // compile low-level intents into flow entry installation plan |
| 159 | PlanCalcRuntime runtime2 = new PlanCalcRuntime(); |
| 160 | List<Set<FlowEntry>> plan = runtime2.computePlan(pathIntentOpList); |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 161 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 162 | // show results |
| 163 | showResult((PathIntentMap) runtime1.getPathIntents()); |
| 164 | System.out.println(plan); |
| 165 | } |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 166 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 167 | @Test |
| 168 | public void createConstrainedShortestPaths() throws FloodlightModuleException { |
| 169 | // create constrained shortest path intents |
| 170 | IntentOperationList opList = new IntentOperationList(); |
| 171 | opList.add(Operator.ADD, new ConstrainedShortestPathIntent("1", 1L, 12L, LOCAL_PORT, 2L, 21L, LOCAL_PORT, 400.0)); |
| 172 | opList.add(Operator.ADD, new ConstrainedShortestPathIntent("2", 1L, 14L, LOCAL_PORT, 4L, 41L, LOCAL_PORT, 400.0)); |
| 173 | opList.add(Operator.ADD, new ConstrainedShortestPathIntent("3", 2L, 24L, LOCAL_PORT, 4L, 42L, LOCAL_PORT, 400.0)); |
| 174 | opList.add(Operator.ADD, new ConstrainedShortestPathIntent("4", 2L, 23L, LOCAL_PORT, 3L, 32L, LOCAL_PORT, 400.0)); |
| 175 | opList.add(Operator.ADD, new ConstrainedShortestPathIntent("5", 3L, 34L, LOCAL_PORT, 4L, 43L, LOCAL_PORT, 400.0)); |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 176 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 177 | // compile high-level intent operations into low-level intent operations (calculate paths) |
| 178 | PathCalcRuntimeModule runtime1 = new PathCalcRuntimeModule(); |
| 179 | runtime1.init(modContext); |
| 180 | runtime1.startUp(modContext); |
| 181 | IntentOperationList pathIntentOpList = runtime1.executeIntentOperations(opList); |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 182 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 183 | // compile low-level intents into flow entry installation plan |
| 184 | PlanCalcRuntime runtime2 = new PlanCalcRuntime(); |
| 185 | List<Set<FlowEntry>> plan = runtime2.computePlan(pathIntentOpList); |
Brian O'Connor | 7f8e301 | 2014-02-15 23:59:29 -0800 | [diff] [blame] | 186 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 187 | // show results |
| 188 | showResult((PathIntentMap) runtime1.getPathIntents()); |
| 189 | System.out.println(plan); |
| 190 | } |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 191 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 192 | @Test |
| 193 | public void createMixedShortestPaths() throws FloodlightModuleException { |
| 194 | // create constrained & best effort shortest path intents |
| 195 | IntentOperationList opList = new IntentOperationList(); |
| 196 | opList.add(Operator.ADD, new ConstrainedShortestPathIntent("1", 1L, 12L, LOCAL_PORT, 2L, 21L, LOCAL_PORT, 400.0)); |
| 197 | opList.add(Operator.ADD, new ConstrainedShortestPathIntent("2", 1L, 14L, LOCAL_PORT, 4L, 41L, LOCAL_PORT, 400.0)); |
| 198 | opList.add(Operator.ADD, new ShortestPathIntent("3", 2L, 24L, LOCAL_PORT, 4L, 42L, LOCAL_PORT)); |
| 199 | opList.add(Operator.ADD, new ShortestPathIntent("4", 2L, 23L, LOCAL_PORT, 3L, 32L, LOCAL_PORT)); |
| 200 | opList.add(Operator.ADD, new ConstrainedShortestPathIntent("5", 3L, 34L, LOCAL_PORT, 4L, 43L, LOCAL_PORT, 400.0)); |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 201 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 202 | // compile high-level intent operations into low-level intent operations (calculate paths) |
| 203 | PathCalcRuntimeModule runtime1 = new PathCalcRuntimeModule(); |
| 204 | runtime1.init(modContext); |
| 205 | runtime1.startUp(modContext); |
| 206 | IntentOperationList pathIntentOpList = runtime1.executeIntentOperations(opList); |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 207 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 208 | // compile low-level intents into flow entry installation plan |
| 209 | PlanCalcRuntime runtime2 = new PlanCalcRuntime(); |
| 210 | List<Set<FlowEntry>> plan = runtime2.computePlan(pathIntentOpList); |
Brian O'Connor | 7f8e301 | 2014-02-15 23:59:29 -0800 | [diff] [blame] | 211 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 212 | // show results |
| 213 | showResult((PathIntentMap) runtime1.getPathIntents()); |
| 214 | System.out.println(plan); |
| 215 | } |
Toshio Koide | d9fa2a8 | 2014-02-19 17:35:18 -0800 | [diff] [blame] | 216 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 217 | @Test |
| 218 | public void rerouteShortestPaths() throws FloodlightModuleException { |
| 219 | List<SwitchEvent> addedSwitchEvents = new LinkedList<>(); |
| 220 | List<SwitchEvent> removedSwitchEvents = new LinkedList<>(); |
| 221 | List<PortEvent> addedPortEvents = new LinkedList<>(); |
| 222 | List<PortEvent> removedPortEvents = new LinkedList<>(); |
| 223 | List<LinkEvent> addedLinkEvents = new LinkedList<>(); |
| 224 | List<LinkEvent> removedLinkEvents = new LinkedList<>(); |
| 225 | List<DeviceEvent> addedDeviceEvents = new LinkedList<>(); |
| 226 | List<DeviceEvent> removedDeviceEvents = new LinkedList<>(); |
Pavlin Radoslavov | 74986ce | 2014-02-20 13:17:20 -0800 | [diff] [blame] | 227 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 228 | // create shortest path intents |
| 229 | IntentOperationList opList = new IntentOperationList(); |
| 230 | opList.add(Operator.ADD, new ShortestPathIntent("1", 1L, 12L, LOCAL_PORT, 2L, 21L, LOCAL_PORT)); |
| 231 | opList.add(Operator.ADD, new ShortestPathIntent("2", 1L, 14L, LOCAL_PORT, 4L, 41L, LOCAL_PORT)); |
| 232 | opList.add(Operator.ADD, new ShortestPathIntent("3", 2L, 23L, LOCAL_PORT, 3L, 32L, LOCAL_PORT)); |
Toshio Koide | 0c9106d | 2014-02-19 15:26:38 -0800 | [diff] [blame] | 233 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 234 | // compile high-level intent operations into low-level intent operations (calculate paths) |
| 235 | PathCalcRuntimeModule runtime1 = new PathCalcRuntimeModule(); |
| 236 | runtime1.init(modContext); |
| 237 | runtime1.startUp(modContext); |
| 238 | IntentOperationList pathIntentOpList = runtime1.executeIntentOperations(opList); |
Toshio Koide | 0c9106d | 2014-02-19 15:26:38 -0800 | [diff] [blame] | 239 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 240 | // compile low-level intents into flow entry installation plan |
| 241 | PlanCalcRuntime runtime2 = new PlanCalcRuntime(); |
| 242 | List<Set<FlowEntry>> plan = runtime2.computePlan(pathIntentOpList); |
Toshio Koide | 0c9106d | 2014-02-19 15:26:38 -0800 | [diff] [blame] | 243 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 244 | // show results step1 |
| 245 | showResult((PathIntentMap) runtime1.getPathIntents()); |
| 246 | System.out.println(plan); |
Toshio Koide | 0c9106d | 2014-02-19 15:26:38 -0800 | [diff] [blame] | 247 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 248 | // TODO this state changes should be triggered by notification of plan module |
| 249 | IntentStateList states = new IntentStateList(); |
| 250 | states.put("1", IntentState.INST_ACK); |
| 251 | states.put("2", IntentState.INST_ACK); |
| 252 | states.put("3", IntentState.INST_ACK); |
| 253 | runtime1.getHighLevelIntents().changeStates(states); |
| 254 | states.clear(); |
| 255 | states.put("1___0", IntentState.INST_ACK); |
| 256 | states.put("2___0", IntentState.INST_ACK); |
| 257 | states.put("3___0", IntentState.INST_ACK); |
| 258 | runtime1.getPathIntents().changeStates(states); |
Toshio Koide | a10c037 | 2014-02-20 17:28:10 -0800 | [diff] [blame] | 259 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 260 | // link down |
| 261 | ((MockNetworkGraph) g).removeLink(1L, 12L, 2L, 21L); // This link is used by the intent "1" |
| 262 | ((MockNetworkGraph) g).removeLink(2L, 21L, 1L, 12L); |
| 263 | LinkEvent linkEvent1 = new LinkEvent(1L, 12L, 2L, 21L); |
| 264 | LinkEvent linkEvent2 = new LinkEvent(2L, 21L, 1L, 12L); |
| 265 | removedLinkEvents.clear(); |
| 266 | removedLinkEvents.add(linkEvent1); |
| 267 | removedLinkEvents.add(linkEvent2); |
| 268 | runtime1.networkGraphEvents( |
| 269 | addedSwitchEvents, |
| 270 | removedSwitchEvents, |
| 271 | addedPortEvents, |
| 272 | removedPortEvents, |
| 273 | addedLinkEvents, |
| 274 | removedLinkEvents, |
| 275 | addedDeviceEvents, |
| 276 | removedDeviceEvents); |
| 277 | System.out.println("Link goes down."); |
Toshio Koide | 0c9106d | 2014-02-19 15:26:38 -0800 | [diff] [blame] | 278 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 279 | // show results step2 |
| 280 | showResult((PathIntentMap) runtime1.getPathIntents()); |
| 281 | // TODO: show results of plan computation |
| 282 | } |
Toshio Koide | fa735a1 | 2014-03-28 10:49:07 -0700 | [diff] [blame] | 283 | |
| 284 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 285 | @Test |
| 286 | public void createAndRemoveShortestPaths() throws FloodlightModuleException { |
| 287 | // create shortest path intents |
| 288 | IntentOperationList opList = new IntentOperationList(); |
| 289 | opList.add(Operator.ADD, new ShortestPathIntent("1", 1L, 12L, LOCAL_PORT, 2L, 21L, LOCAL_PORT)); |
| 290 | opList.add(Operator.ADD, new ShortestPathIntent("2", 1L, 14L, LOCAL_PORT, 4L, 41L, LOCAL_PORT)); |
| 291 | opList.add(Operator.ADD, new ShortestPathIntent("3", 2L, 23L, LOCAL_PORT, 3L, 32L, LOCAL_PORT)); |
Toshio Koide | fa735a1 | 2014-03-28 10:49:07 -0700 | [diff] [blame] | 292 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 293 | // compile high-level intent operations into low-level intent operations (calculate paths) |
| 294 | PathCalcRuntimeModule runtime1 = new PathCalcRuntimeModule(); |
| 295 | runtime1.init(modContext); |
| 296 | runtime1.startUp(modContext); |
| 297 | IntentOperationList pathIntentOpList = runtime1.executeIntentOperations(opList); |
Toshio Koide | fa735a1 | 2014-03-28 10:49:07 -0700 | [diff] [blame] | 298 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 299 | // compile low-level intents into flow entry installation plan |
| 300 | PlanCalcRuntime runtime2 = new PlanCalcRuntime(); |
| 301 | List<Set<FlowEntry>> plan = runtime2.computePlan(pathIntentOpList); |
Toshio Koide | fa735a1 | 2014-03-28 10:49:07 -0700 | [diff] [blame] | 302 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 303 | // show results |
| 304 | showResult((PathIntentMap) runtime1.getPathIntents()); |
| 305 | System.out.println(plan); |
Toshio Koide | fa735a1 | 2014-03-28 10:49:07 -0700 | [diff] [blame] | 306 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 307 | // create remove operations |
| 308 | opList.clear(); |
| 309 | opList.add(Operator.REMOVE, new Intent("1")); |
| 310 | opList.add(Operator.REMOVE, new Intent("2")); |
Toshio Koide | fa735a1 | 2014-03-28 10:49:07 -0700 | [diff] [blame] | 311 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 312 | // compile |
| 313 | runtime1.executeIntentOperations(opList); |
Toshio Koide | fa735a1 | 2014-03-28 10:49:07 -0700 | [diff] [blame] | 314 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 315 | // show results |
| 316 | showResult((PathIntentMap) runtime1.getPathIntents()); |
| 317 | System.out.println(plan); |
| 318 | } |
Toshio Koide | fa735a1 | 2014-03-28 10:49:07 -0700 | [diff] [blame] | 319 | |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 320 | } |