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