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; |
Jonathan Hart | 6df9017 | 2014-04-03 10:13:11 -0700 | [diff] [blame] | 18 | import net.onrc.onos.core.datagrid.IDatagridService; |
| 19 | import net.onrc.onos.core.datagrid.IEventChannel; |
| 20 | import net.onrc.onos.core.datagrid.IEventChannelListener; |
Jonathan Hart | aa38097 | 2014-04-03 10:24:46 -0700 | [diff] [blame] | 21 | import net.onrc.onos.core.intent.ConstrainedShortestPathIntent; |
| 22 | import net.onrc.onos.core.intent.FlowEntry; |
| 23 | import net.onrc.onos.core.intent.Intent; |
Jonathan Hart | a88fd24 | 2014-04-03 11:24:54 -0700 | [diff] [blame] | 24 | import net.onrc.onos.core.intent.Intent.IntentState; |
| 25 | import net.onrc.onos.core.intent.IntentOperation.Operator; |
Jonathan Hart | aa38097 | 2014-04-03 10:24:46 -0700 | [diff] [blame] | 26 | import net.onrc.onos.core.intent.IntentOperationList; |
Jonathan Hart | aa38097 | 2014-04-03 10:24:46 -0700 | [diff] [blame] | 27 | import net.onrc.onos.core.intent.PathIntent; |
| 28 | import net.onrc.onos.core.intent.PathIntentMap; |
| 29 | import net.onrc.onos.core.intent.ShortestPathIntent; |
Pavlin Radoslavov | 1366905 | 2014-05-13 10:33:39 -0700 | [diff] [blame] | 30 | import net.onrc.onos.core.intent.runtime.web.IntentWebRoutable; |
Jonathan Hart | deda0ba | 2014-04-03 11:14:12 -0700 | [diff] [blame] | 31 | import net.onrc.onos.core.registry.IControllerRegistryService; |
Jonathan Hart | 472062d | 2014-04-03 10:56:48 -0700 | [diff] [blame] | 32 | import net.onrc.onos.core.topology.DeviceEvent; |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 33 | import net.onrc.onos.core.topology.ITopologyListener; |
| 34 | import net.onrc.onos.core.topology.ITopologyService; |
Jonathan Hart | 472062d | 2014-04-03 10:56:48 -0700 | [diff] [blame] | 35 | import net.onrc.onos.core.topology.LinkEvent; |
TeruU | 5d2c939 | 2014-06-09 20:02:02 -0700 | [diff] [blame] | 36 | import net.onrc.onos.core.topology.MockTopology; |
Jonathan Hart | 472062d | 2014-04-03 10:56:48 -0700 | [diff] [blame] | 37 | import net.onrc.onos.core.topology.PortEvent; |
| 38 | import net.onrc.onos.core.topology.SwitchEvent; |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 39 | import net.onrc.onos.core.topology.Topology; |
Pavlin Radoslavov | 4eaab99 | 2014-07-03 18:39:42 -0700 | [diff] [blame] | 40 | import net.onrc.onos.core.topology.TopologyEvents; |
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.) |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 54 | */ |
Nick Karanatsios | 8abe717 | 2014-02-19 20:31:48 -0800 | [diff] [blame] | 55 | @RunWith(PowerMockRunner.class) |
| 56 | @PrepareForTest(PathCalcRuntimeModule.class) |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 57 | public class UseCaseTest { |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 58 | private Topology topology; |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 59 | private FloodlightModuleContext modContext; |
| 60 | private IDatagridService datagridService; |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 61 | private ITopologyService topologyService; |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 62 | private IControllerRegistryService controllerRegistryService; |
| 63 | private PersistIntent persistIntent; |
Pavlin Radoslavov | 1366905 | 2014-05-13 10:33:39 -0700 | [diff] [blame] | 64 | private IRestApiService restApi; |
Toshio Koide | e04a9df | 2014-05-01 15:49:28 -0700 | [diff] [blame] | 65 | private IEventChannel<Long, IntentOperationList> intentOperationChannel; |
| 66 | private IEventChannel<Long, IntentStateList> intentStateChannel; |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 67 | |
Yuta HIGUCHI | 44a0b35 | 2014-05-14 21:32:48 -0700 | [diff] [blame] | 68 | private static final Long LOCAL_PORT = 0xFFFEL; |
Toshio Koide | fe1d5d9 | 2014-02-26 20:09:48 -0800 | [diff] [blame] | 69 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 70 | @SuppressWarnings("unchecked") |
| 71 | @Before |
| 72 | public void setUp() throws Exception { |
Yuta HIGUCHI | 44a0b35 | 2014-05-14 21:32:48 -0700 | [diff] [blame] | 73 | MockTopology mockTopology = new MockTopology(); |
| 74 | mockTopology.createSampleTopology1(); |
| 75 | this.topology = mockTopology; |
Toshio Koide | 27ffd41 | 2014-02-18 19:15:27 -0800 | [diff] [blame] | 76 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 77 | datagridService = createMock(IDatagridService.class); |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 78 | topologyService = createMock(ITopologyService.class); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 79 | controllerRegistryService = createMock(IControllerRegistryService.class); |
| 80 | modContext = createMock(FloodlightModuleContext.class); |
Toshio Koide | e04a9df | 2014-05-01 15:49:28 -0700 | [diff] [blame] | 81 | intentOperationChannel = createMock(IEventChannel.class); |
| 82 | intentStateChannel = createMock(IEventChannel.class); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 83 | persistIntent = PowerMock.createMock(PersistIntent.class); |
Pavlin Radoslavov | 1366905 | 2014-05-13 10:33:39 -0700 | [diff] [blame] | 84 | restApi = createMock(IRestApiService.class); |
Toshio Koide | 798bc1b | 2014-02-20 14:02:40 -0800 | [diff] [blame] | 85 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 86 | PowerMock.expectNew(PersistIntent.class, |
Pavlin Radoslavov | 0294e05 | 2014-04-10 13:36:45 -0700 | [diff] [blame] | 87 | anyObject(IControllerRegistryService.class)).andReturn(persistIntent); |
Toshio Koide | 27ffd41 | 2014-02-18 19:15:27 -0800 | [diff] [blame] | 88 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 89 | expect(modContext.getServiceImpl(IDatagridService.class)) |
| 90 | .andReturn(datagridService).once(); |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 91 | expect(modContext.getServiceImpl(ITopologyService.class)) |
| 92 | .andReturn(topologyService).once(); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 93 | expect(modContext.getServiceImpl(IControllerRegistryService.class)) |
| 94 | .andReturn(controllerRegistryService).once(); |
| 95 | expect(persistIntent.getKey()).andReturn(1L).anyTimes(); |
| 96 | expect(persistIntent.persistIfLeader(eq(1L), |
| 97 | anyObject(IntentOperationList.class))).andReturn(true).anyTimes(); |
Pavlin Radoslavov | 1366905 | 2014-05-13 10:33:39 -0700 | [diff] [blame] | 98 | expect(modContext.getServiceImpl(IRestApiService.class)) |
| 99 | .andReturn(restApi).once(); |
Toshio Koide | 0c9106d | 2014-02-19 15:26:38 -0800 | [diff] [blame] | 100 | |
Yuta HIGUCHI | 44a0b35 | 2014-05-14 21:32:48 -0700 | [diff] [blame] | 101 | expect(topologyService.getTopology()).andReturn(mockTopology).anyTimes(); |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 102 | topologyService.registerTopologyListener(anyObject(ITopologyListener.class)); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 103 | expectLastCall(); |
Toshio Koide | 0c9106d | 2014-02-19 15:26:38 -0800 | [diff] [blame] | 104 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 105 | expect(datagridService.createChannel("onos.pathintent", Long.class, IntentOperationList.class)) |
Toshio Koide | e04a9df | 2014-05-01 15:49:28 -0700 | [diff] [blame] | 106 | .andReturn(intentOperationChannel).once(); |
Toshio Koide | 27ffd41 | 2014-02-18 19:15:27 -0800 | [diff] [blame] | 107 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 108 | expect(datagridService.addListener( |
| 109 | eq("onos.pathintent_state"), |
| 110 | anyObject(IEventChannelListener.class), |
| 111 | eq(Long.class), |
| 112 | eq(IntentStateList.class))) |
Toshio Koide | e04a9df | 2014-05-01 15:49:28 -0700 | [diff] [blame] | 113 | .andReturn(intentStateChannel).once(); |
Pavlin Radoslavov | 1366905 | 2014-05-13 10:33:39 -0700 | [diff] [blame] | 114 | restApi.addRestletRoutable(anyObject(IntentWebRoutable.class)); |
Toshio Koide | 066506e | 2014-02-20 19:52:09 -0800 | [diff] [blame] | 115 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 116 | replay(datagridService); |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 117 | replay(topologyService); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 118 | replay(modContext); |
| 119 | replay(controllerRegistryService); |
| 120 | PowerMock.replay(persistIntent, PersistIntent.class); |
Pavlin Radoslavov | 1366905 | 2014-05-13 10:33:39 -0700 | [diff] [blame] | 121 | replay(restApi); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 122 | } |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 123 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 124 | @After |
| 125 | public void tearDown() { |
| 126 | verify(datagridService); |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 127 | verify(topologyService); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 128 | verify(modContext); |
| 129 | verify(controllerRegistryService); |
| 130 | PowerMock.verify(persistIntent, PersistIntent.class); |
Pavlin Radoslavov | 1366905 | 2014-05-13 10:33:39 -0700 | [diff] [blame] | 131 | verify(restApi); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 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 | private void showResult(PathIntentMap intents) { |
| 135 | for (Intent intent : intents.getAllIntents()) { |
| 136 | PathIntent pathIntent = (PathIntent) intent; |
| 137 | System.out.println("Path intent:" + pathIntent); |
| 138 | System.out.println("Parent intent: " + pathIntent.getParentIntent().toString()); |
| 139 | } |
| 140 | } |
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 | @Test |
| 143 | public void createShortestPaths() throws FloodlightModuleException { |
| 144 | // create shortest path intents |
| 145 | IntentOperationList opList = new IntentOperationList(); |
| 146 | opList.add(Operator.ADD, new ShortestPathIntent("1", 1L, 12L, LOCAL_PORT, 2L, 21L, LOCAL_PORT)); |
| 147 | opList.add(Operator.ADD, new ShortestPathIntent("2", 1L, 14L, LOCAL_PORT, 4L, 41L, LOCAL_PORT)); |
| 148 | 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] | 149 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 150 | // compile high-level intent operations into low-level intent operations (calculate paths) |
| 151 | PathCalcRuntimeModule runtime1 = new PathCalcRuntimeModule(); |
| 152 | runtime1.init(modContext); |
| 153 | runtime1.startUp(modContext); |
| 154 | IntentOperationList pathIntentOpList = runtime1.executeIntentOperations(opList); |
Toshio Koide | 27ffd41 | 2014-02-18 19:15:27 -0800 | [diff] [blame] | 155 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 156 | // compile low-level intents into flow entry installation plan |
| 157 | PlanCalcRuntime runtime2 = new PlanCalcRuntime(); |
| 158 | List<Set<FlowEntry>> plan = runtime2.computePlan(pathIntentOpList); |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 159 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 160 | // show results |
| 161 | showResult((PathIntentMap) runtime1.getPathIntents()); |
| 162 | System.out.println(plan); |
| 163 | } |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 164 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 165 | @Test |
| 166 | public void createConstrainedShortestPaths() throws FloodlightModuleException { |
| 167 | // create constrained shortest path intents |
| 168 | IntentOperationList opList = new IntentOperationList(); |
Yuta HIGUCHI | 91a8f50 | 2014-06-17 10:15:29 -0700 | [diff] [blame] | 169 | opList.add(Operator.ADD, new ConstrainedShortestPathIntent("1", 1L, 12L, |
| 170 | LOCAL_PORT, 2L, 21L, LOCAL_PORT, 400.0)); |
| 171 | opList.add(Operator.ADD, new ConstrainedShortestPathIntent("2", 1L, 14L, |
| 172 | LOCAL_PORT, 4L, 41L, LOCAL_PORT, 400.0)); |
| 173 | opList.add(Operator.ADD, new ConstrainedShortestPathIntent("3", 2L, 24L, |
| 174 | LOCAL_PORT, 4L, 42L, LOCAL_PORT, 400.0)); |
| 175 | opList.add(Operator.ADD, new ConstrainedShortestPathIntent("4", 2L, 23L, |
| 176 | LOCAL_PORT, 3L, 32L, LOCAL_PORT, 400.0)); |
| 177 | opList.add(Operator.ADD, new ConstrainedShortestPathIntent("5", 3L, 34L, |
| 178 | LOCAL_PORT, 4L, 43L, LOCAL_PORT, 400.0)); |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 179 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 180 | // compile high-level intent operations into low-level intent operations (calculate paths) |
| 181 | PathCalcRuntimeModule runtime1 = new PathCalcRuntimeModule(); |
| 182 | runtime1.init(modContext); |
| 183 | runtime1.startUp(modContext); |
| 184 | IntentOperationList pathIntentOpList = runtime1.executeIntentOperations(opList); |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 185 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 186 | // compile low-level intents into flow entry installation plan |
| 187 | PlanCalcRuntime runtime2 = new PlanCalcRuntime(); |
| 188 | List<Set<FlowEntry>> plan = runtime2.computePlan(pathIntentOpList); |
Brian O'Connor | 7f8e301 | 2014-02-15 23:59:29 -0800 | [diff] [blame] | 189 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 190 | // show results |
| 191 | showResult((PathIntentMap) runtime1.getPathIntents()); |
| 192 | System.out.println(plan); |
| 193 | } |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 194 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 195 | @Test |
| 196 | public void createMixedShortestPaths() throws FloodlightModuleException { |
| 197 | // create constrained & best effort shortest path intents |
| 198 | IntentOperationList opList = new IntentOperationList(); |
Yuta HIGUCHI | 91a8f50 | 2014-06-17 10:15:29 -0700 | [diff] [blame] | 199 | opList.add(Operator.ADD, new ConstrainedShortestPathIntent("1", 1L, 12L, |
| 200 | LOCAL_PORT, 2L, 21L, LOCAL_PORT, 400.0)); |
| 201 | opList.add(Operator.ADD, new ConstrainedShortestPathIntent("2", 1L, 14L, |
| 202 | LOCAL_PORT, 4L, 41L, LOCAL_PORT, 400.0)); |
| 203 | opList.add(Operator.ADD, new ShortestPathIntent("3", 2L, 24L, LOCAL_PORT, 4L, |
| 204 | 42L, LOCAL_PORT)); |
| 205 | opList.add(Operator.ADD, new ShortestPathIntent("4", 2L, 23L, LOCAL_PORT, 3L, |
| 206 | 32L, LOCAL_PORT)); |
| 207 | opList.add(Operator.ADD, new ConstrainedShortestPathIntent("5", 3L, 34L, |
| 208 | LOCAL_PORT, 4L, 43L, LOCAL_PORT, 400.0)); |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 209 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 210 | // compile high-level intent operations into low-level intent operations (calculate paths) |
| 211 | PathCalcRuntimeModule runtime1 = new PathCalcRuntimeModule(); |
| 212 | runtime1.init(modContext); |
| 213 | runtime1.startUp(modContext); |
| 214 | IntentOperationList pathIntentOpList = runtime1.executeIntentOperations(opList); |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 215 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 216 | // compile low-level intents into flow entry installation plan |
| 217 | PlanCalcRuntime runtime2 = new PlanCalcRuntime(); |
| 218 | List<Set<FlowEntry>> plan = runtime2.computePlan(pathIntentOpList); |
Brian O'Connor | 7f8e301 | 2014-02-15 23:59:29 -0800 | [diff] [blame] | 219 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 220 | // show results |
| 221 | showResult((PathIntentMap) runtime1.getPathIntents()); |
| 222 | System.out.println(plan); |
| 223 | } |
Toshio Koide | d9fa2a8 | 2014-02-19 17:35:18 -0800 | [diff] [blame] | 224 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 225 | @Test |
| 226 | public void rerouteShortestPaths() throws FloodlightModuleException { |
| 227 | List<SwitchEvent> addedSwitchEvents = new LinkedList<>(); |
| 228 | List<SwitchEvent> removedSwitchEvents = new LinkedList<>(); |
| 229 | List<PortEvent> addedPortEvents = new LinkedList<>(); |
| 230 | List<PortEvent> removedPortEvents = new LinkedList<>(); |
| 231 | List<LinkEvent> addedLinkEvents = new LinkedList<>(); |
| 232 | List<LinkEvent> removedLinkEvents = new LinkedList<>(); |
| 233 | List<DeviceEvent> addedDeviceEvents = new LinkedList<>(); |
| 234 | List<DeviceEvent> removedDeviceEvents = new LinkedList<>(); |
Pavlin Radoslavov | 4eaab99 | 2014-07-03 18:39:42 -0700 | [diff] [blame] | 235 | TopologyEvents topologyEvents; |
Pavlin Radoslavov | 74986ce | 2014-02-20 13:17:20 -0800 | [diff] [blame] | 236 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 237 | // create shortest path intents |
| 238 | IntentOperationList opList = new IntentOperationList(); |
| 239 | opList.add(Operator.ADD, new ShortestPathIntent("1", 1L, 12L, LOCAL_PORT, 2L, 21L, LOCAL_PORT)); |
| 240 | opList.add(Operator.ADD, new ShortestPathIntent("2", 1L, 14L, LOCAL_PORT, 4L, 41L, LOCAL_PORT)); |
| 241 | 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] | 242 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 243 | // compile high-level intent operations into low-level intent operations (calculate paths) |
| 244 | PathCalcRuntimeModule runtime1 = new PathCalcRuntimeModule(); |
| 245 | runtime1.init(modContext); |
| 246 | runtime1.startUp(modContext); |
| 247 | IntentOperationList pathIntentOpList = runtime1.executeIntentOperations(opList); |
Toshio Koide | 0c9106d | 2014-02-19 15:26:38 -0800 | [diff] [blame] | 248 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 249 | // compile low-level intents into flow entry installation plan |
| 250 | PlanCalcRuntime runtime2 = new PlanCalcRuntime(); |
| 251 | List<Set<FlowEntry>> plan = runtime2.computePlan(pathIntentOpList); |
Toshio Koide | 0c9106d | 2014-02-19 15:26:38 -0800 | [diff] [blame] | 252 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 253 | // show results step1 |
| 254 | showResult((PathIntentMap) runtime1.getPathIntents()); |
| 255 | System.out.println(plan); |
Toshio Koide | 0c9106d | 2014-02-19 15:26:38 -0800 | [diff] [blame] | 256 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 257 | // TODO this state changes should be triggered by notification of plan module |
| 258 | IntentStateList states = new IntentStateList(); |
| 259 | states.put("1", IntentState.INST_ACK); |
| 260 | states.put("2", IntentState.INST_ACK); |
| 261 | states.put("3", IntentState.INST_ACK); |
| 262 | runtime1.getHighLevelIntents().changeStates(states); |
| 263 | states.clear(); |
| 264 | states.put("1___0", IntentState.INST_ACK); |
| 265 | states.put("2___0", IntentState.INST_ACK); |
| 266 | states.put("3___0", IntentState.INST_ACK); |
| 267 | runtime1.getPathIntents().changeStates(states); |
Toshio Koide | a10c037 | 2014-02-20 17:28:10 -0800 | [diff] [blame] | 268 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 269 | // link down |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 270 | ((MockTopology) topology).removeLink(1L, 12L, 2L, 21L); // This link is used by the intent "1" |
| 271 | ((MockTopology) topology).removeLink(2L, 21L, 1L, 12L); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 272 | LinkEvent linkEvent1 = new LinkEvent(1L, 12L, 2L, 21L); |
| 273 | LinkEvent linkEvent2 = new LinkEvent(2L, 21L, 1L, 12L); |
| 274 | removedLinkEvents.clear(); |
| 275 | removedLinkEvents.add(linkEvent1); |
| 276 | removedLinkEvents.add(linkEvent2); |
Pavlin Radoslavov | 4eaab99 | 2014-07-03 18:39:42 -0700 | [diff] [blame] | 277 | |
| 278 | topologyEvents = new TopologyEvents(0, |
| 279 | addedSwitchEvents, |
| 280 | removedSwitchEvents, |
| 281 | addedPortEvents, |
| 282 | removedPortEvents, |
| 283 | addedLinkEvents, |
| 284 | removedLinkEvents, |
| 285 | addedDeviceEvents, |
| 286 | removedDeviceEvents); |
| 287 | |
| 288 | runtime1.topologyEvents(topologyEvents); |
Toshio Koide | 7d3cee0 | 2014-06-05 18:56:19 -0700 | [diff] [blame] | 289 | System.out.println("*** Link goes down. ***"); |
| 290 | |
| 291 | // send notification |
| 292 | IntentStateList isl = new IntentStateList(); |
| 293 | isl.put("1___0", IntentState.DEL_ACK); |
| 294 | isl.put("1___1", IntentState.INST_ACK); |
| 295 | isl.domainSwitchDpids.add(1L); |
| 296 | isl.domainSwitchDpids.add(2L); |
| 297 | isl.domainSwitchDpids.add(4L); |
| 298 | runtime1.entryUpdated(isl); |
Toshio Koide | 0c9106d | 2014-02-19 15:26:38 -0800 | [diff] [blame] | 299 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 300 | // show results step2 |
| 301 | showResult((PathIntentMap) runtime1.getPathIntents()); |
Toshio Koide | 7d3cee0 | 2014-06-05 18:56:19 -0700 | [diff] [blame] | 302 | |
| 303 | // link up |
| 304 | ((MockTopology) topology).addBidirectionalLinks(1L, 12L, 2L, 21L); |
| 305 | linkEvent1 = new LinkEvent(1L, 12L, 2L, 21L); |
| 306 | linkEvent2 = new LinkEvent(2L, 21L, 1L, 12L); |
| 307 | removedLinkEvents.clear(); |
| 308 | addedLinkEvents.clear(); |
| 309 | addedLinkEvents.add(linkEvent1); |
| 310 | addedLinkEvents.add(linkEvent2); |
Pavlin Radoslavov | 4eaab99 | 2014-07-03 18:39:42 -0700 | [diff] [blame] | 311 | |
| 312 | topologyEvents = new TopologyEvents(0, |
| 313 | addedSwitchEvents, |
| 314 | removedSwitchEvents, |
| 315 | addedPortEvents, |
| 316 | removedPortEvents, |
| 317 | addedLinkEvents, |
| 318 | removedLinkEvents, |
| 319 | addedDeviceEvents, |
| 320 | removedDeviceEvents); |
| 321 | |
| 322 | runtime1.topologyEvents(topologyEvents); |
Toshio Koide | 7d3cee0 | 2014-06-05 18:56:19 -0700 | [diff] [blame] | 323 | System.out.println("*** Link goes up. ***"); |
| 324 | |
| 325 | // send notification |
| 326 | isl = new IntentStateList(); |
| 327 | isl.put("1___1", IntentState.DEL_ACK); |
| 328 | isl.put("1___2", IntentState.INST_ACK); |
| 329 | isl.domainSwitchDpids.add(1L); |
| 330 | isl.domainSwitchDpids.add(2L); |
| 331 | isl.domainSwitchDpids.add(4L); |
| 332 | runtime1.entryUpdated(isl); |
| 333 | |
| 334 | // show results step3 |
| 335 | showResult((PathIntentMap) runtime1.getPathIntents()); |
| 336 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 337 | // TODO: show results of plan computation |
| 338 | } |
Toshio Koide | fa735a1 | 2014-03-28 10:49:07 -0700 | [diff] [blame] | 339 | |
| 340 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 341 | @Test |
| 342 | public void createAndRemoveShortestPaths() throws FloodlightModuleException { |
| 343 | // create shortest path intents |
| 344 | IntentOperationList opList = new IntentOperationList(); |
| 345 | opList.add(Operator.ADD, new ShortestPathIntent("1", 1L, 12L, LOCAL_PORT, 2L, 21L, LOCAL_PORT)); |
| 346 | opList.add(Operator.ADD, new ShortestPathIntent("2", 1L, 14L, LOCAL_PORT, 4L, 41L, LOCAL_PORT)); |
| 347 | 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] | 348 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 349 | // compile high-level intent operations into low-level intent operations (calculate paths) |
| 350 | PathCalcRuntimeModule runtime1 = new PathCalcRuntimeModule(); |
| 351 | runtime1.init(modContext); |
| 352 | runtime1.startUp(modContext); |
| 353 | IntentOperationList pathIntentOpList = runtime1.executeIntentOperations(opList); |
Toshio Koide | fa735a1 | 2014-03-28 10:49:07 -0700 | [diff] [blame] | 354 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 355 | // compile low-level intents into flow entry installation plan |
| 356 | PlanCalcRuntime runtime2 = new PlanCalcRuntime(); |
| 357 | List<Set<FlowEntry>> plan = runtime2.computePlan(pathIntentOpList); |
Toshio Koide | fa735a1 | 2014-03-28 10:49:07 -0700 | [diff] [blame] | 358 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 359 | // show results |
| 360 | showResult((PathIntentMap) runtime1.getPathIntents()); |
| 361 | System.out.println(plan); |
Toshio Koide | fa735a1 | 2014-03-28 10:49:07 -0700 | [diff] [blame] | 362 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 363 | // create remove operations |
| 364 | opList.clear(); |
| 365 | opList.add(Operator.REMOVE, new Intent("1")); |
| 366 | opList.add(Operator.REMOVE, new Intent("2")); |
Toshio Koide | fa735a1 | 2014-03-28 10:49:07 -0700 | [diff] [blame] | 367 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 368 | // compile |
| 369 | runtime1.executeIntentOperations(opList); |
Toshio Koide | fa735a1 | 2014-03-28 10:49:07 -0700 | [diff] [blame] | 370 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 371 | // show results |
| 372 | showResult((PathIntentMap) runtime1.getPathIntents()); |
| 373 | System.out.println(plan); |
| 374 | } |
Toshio Koide | fa735a1 | 2014-03-28 10:49:07 -0700 | [diff] [blame] | 375 | |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 376 | } |