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