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