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