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