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