Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 1 | package net.onrc.onos.intent.runtime; |
| 2 | |
Toshio Koide | 27ffd41 | 2014-02-18 19:15:27 -0800 | [diff] [blame] | 3 | import net.floodlightcontroller.core.module.FloodlightModuleContext; |
| 4 | import net.floodlightcontroller.core.module.FloodlightModuleException; |
| 5 | import net.onrc.onos.datagrid.IDatagridService; |
| 6 | import net.onrc.onos.datagrid.IEventChannel; |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 7 | import net.onrc.onos.intent.ConstrainedShortestPathIntent; |
| 8 | import net.onrc.onos.intent.Intent; |
Toshio Koide | 27ffd41 | 2014-02-18 19:15:27 -0800 | [diff] [blame] | 9 | import net.onrc.onos.intent.IntentOperation.Operator; |
| 10 | import net.onrc.onos.intent.IntentOperationList; |
Toshio Koide | ebdbb62 | 2014-02-12 20:28:38 -0800 | [diff] [blame] | 11 | import net.onrc.onos.intent.MockNetworkGraph; |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 12 | import net.onrc.onos.intent.PathIntent; |
Toshio Koide | 4f30873 | 2014-02-18 15:19:48 -0800 | [diff] [blame] | 13 | import net.onrc.onos.intent.PathIntentMap; |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 14 | import net.onrc.onos.intent.ShortestPathIntent; |
Toshio Koide | 27ffd41 | 2014-02-18 19:15:27 -0800 | [diff] [blame] | 15 | import net.onrc.onos.ofcontroller.networkgraph.INetworkGraphService; |
| 16 | import net.onrc.onos.ofcontroller.networkgraph.Link; |
| 17 | import net.onrc.onos.ofcontroller.networkgraph.NetworkGraph; |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 18 | |
Toshio Koide | 27ffd41 | 2014-02-18 19:15:27 -0800 | [diff] [blame] | 19 | import org.easymock.EasyMock; |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 20 | import org.junit.After; |
| 21 | import org.junit.Before; |
| 22 | import org.junit.Test; |
| 23 | |
| 24 | /** |
| 25 | * @author Toshio Koide (t-koide@onlab.us) |
| 26 | */ |
| 27 | public class UseCaseTest { |
Toshio Koide | 27ffd41 | 2014-02-18 19:15:27 -0800 | [diff] [blame] | 28 | private NetworkGraph g; |
| 29 | private FloodlightModuleContext modContext; |
| 30 | private IDatagridService datagridService; |
| 31 | private INetworkGraphService networkGraphService; |
| 32 | @SuppressWarnings("rawtypes") |
| 33 | private IEventChannel eventChannel; |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 34 | |
Toshio Koide | 27ffd41 | 2014-02-18 19:15:27 -0800 | [diff] [blame] | 35 | @SuppressWarnings("unchecked") |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 36 | @Before |
| 37 | public void setUp() { |
Toshio Koide | ebdbb62 | 2014-02-12 20:28:38 -0800 | [diff] [blame] | 38 | MockNetworkGraph graph = new MockNetworkGraph(); |
| 39 | graph.createSampleTopology(); |
| 40 | g = graph; |
Toshio Koide | 27ffd41 | 2014-02-18 19:15:27 -0800 | [diff] [blame] | 41 | |
| 42 | datagridService = EasyMock.createMock(IDatagridService.class); |
| 43 | networkGraphService = EasyMock.createMock(INetworkGraphService.class); |
| 44 | modContext = EasyMock.createMock(FloodlightModuleContext.class); |
| 45 | eventChannel = EasyMock.createMock(IEventChannel.class); |
| 46 | |
| 47 | EasyMock.expect(modContext.getServiceImpl(EasyMock.eq(IDatagridService.class))) |
| 48 | .andReturn(datagridService).once(); |
| 49 | EasyMock.expect(modContext.getServiceImpl(EasyMock.eq(INetworkGraphService.class))) |
| 50 | .andReturn(networkGraphService).once(); |
| 51 | |
| 52 | networkGraphService.getNetworkGraph(); |
| 53 | EasyMock.expectLastCall().andReturn(g).anyTimes(); |
| 54 | |
| 55 | EasyMock.expect(datagridService.createChannel("onos.pathintent", byte[].class, IntentOperationList.class)) |
| 56 | .andReturn(eventChannel).once(); |
| 57 | |
| 58 | EasyMock.replay(datagridService); |
| 59 | EasyMock.replay(networkGraphService); |
| 60 | EasyMock.replay(modContext); |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | @After |
| 64 | public void tearDown() { |
Toshio Koide | 27ffd41 | 2014-02-18 19:15:27 -0800 | [diff] [blame] | 65 | EasyMock.verify(datagridService); |
| 66 | EasyMock.verify(networkGraphService); |
| 67 | EasyMock.verify(modContext); |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 68 | } |
| 69 | |
Toshio Koide | 4f30873 | 2014-02-18 15:19:48 -0800 | [diff] [blame] | 70 | private void showResult(PathIntentMap intents) { |
| 71 | for (Intent intent: intents.getAllIntents()) { |
| 72 | PathIntent pathIntent = (PathIntent)intent; |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 73 | System.out.println("Parent intent: " + pathIntent.getParentIntent().toString()); |
| 74 | System.out.println("Path:"); |
Toshio Koide | c406e79 | 2014-02-14 16:52:42 -0800 | [diff] [blame] | 75 | for (Link link: pathIntent.getPath(g)) { |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 76 | System.out.printf("%s --(%f/%f)--> %s\n", |
| 77 | link.getSourcePort(), |
| 78 | link.getCapacity() - intents.getAvailableBandwidth(link), |
| 79 | link.getCapacity(), |
| 80 | link.getDestinationPort()); |
| 81 | } |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | @Test |
Toshio Koide | 27ffd41 | 2014-02-18 19:15:27 -0800 | [diff] [blame] | 86 | public void useCase1() throws FloodlightModuleException { |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 87 | // create shortest path intents |
Toshio Koide | 27ffd41 | 2014-02-18 19:15:27 -0800 | [diff] [blame] | 88 | IntentOperationList opList = new IntentOperationList(); |
| 89 | opList.add(Operator.ADD, new ShortestPathIntent("1", 1L, 20L, 1L, 4L, 20L, 4L)); |
| 90 | opList.add(Operator.ADD, new ShortestPathIntent("2", 2L, 20L, 2L, 6L, 20L, 5L)); |
| 91 | opList.add(Operator.ADD, new ShortestPathIntent("3", 4L, 20L, 3L, 8L, 20L, 6L)); |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 92 | |
Toshio Koide | 27ffd41 | 2014-02-18 19:15:27 -0800 | [diff] [blame] | 93 | // compile high-level intent operations into low-level intent operations (calculate paths) |
| 94 | PathCalcRuntimeModule runtime1 = new PathCalcRuntimeModule(); |
| 95 | runtime1.init(modContext); |
| 96 | runtime1.startUp(modContext); |
| 97 | IntentOperationList pathIntentOpList = runtime1.executeIntentOperations(opList); |
| 98 | |
Brian O'Connor | 7f8e301 | 2014-02-15 23:59:29 -0800 | [diff] [blame] | 99 | // compile low-level intents into flow entry installation plan |
| 100 | PlanCalcRuntime runtime2 = new PlanCalcRuntime(g); |
Toshio Koide | 103ccb2 | 2014-02-18 21:51:25 -0800 | [diff] [blame] | 101 | runtime2.addIntents(pathIntentOpList); |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 102 | |
| 103 | // show results |
Toshio Koide | 27ffd41 | 2014-02-18 19:15:27 -0800 | [diff] [blame] | 104 | showResult((PathIntentMap) runtime1.getPathIntents()); |
Brian O'Connor | 7f8e301 | 2014-02-15 23:59:29 -0800 | [diff] [blame] | 105 | System.out.println(runtime2.getPlan()); |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | @Test |
Toshio Koide | 27ffd41 | 2014-02-18 19:15:27 -0800 | [diff] [blame] | 109 | public void useCase2() throws FloodlightModuleException { |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 110 | // create constrained shortest path intents |
Toshio Koide | 27ffd41 | 2014-02-18 19:15:27 -0800 | [diff] [blame] | 111 | IntentOperationList opList = new IntentOperationList(); |
| 112 | opList.add(Operator.ADD, new ConstrainedShortestPathIntent("1", 1L, 20L, 1L, 4L, 20L, 17L, 400.0)); |
| 113 | opList.add(Operator.ADD, new ConstrainedShortestPathIntent("2", 2L, 20L, 2L, 6L, 20L, 18L, 400.0)); |
| 114 | opList.add(Operator.ADD, new ConstrainedShortestPathIntent("3", 4L, 20L, 3L, 8L, 20L, 19L, 400.0)); |
| 115 | opList.add(Operator.ADD, new ConstrainedShortestPathIntent("4", 3L, 20L, 4L, 8L, 20L, 20L, 400.0)); |
| 116 | opList.add(Operator.ADD, new ConstrainedShortestPathIntent("5", 4L, 20L, 5L, 8L, 20L, 21L, 400.0)); |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 117 | |
Toshio Koide | 27ffd41 | 2014-02-18 19:15:27 -0800 | [diff] [blame] | 118 | // compile high-level intent operations into low-level intent operations (calculate paths) |
| 119 | PathCalcRuntimeModule runtime1 = new PathCalcRuntimeModule(); |
| 120 | runtime1.init(modContext); |
| 121 | runtime1.startUp(modContext); |
| 122 | IntentOperationList pathIntentOpList = runtime1.executeIntentOperations(opList); |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 123 | |
Brian O'Connor | 7f8e301 | 2014-02-15 23:59:29 -0800 | [diff] [blame] | 124 | // compile low-level intents into flow entry installation plan |
| 125 | PlanCalcRuntime runtime2 = new PlanCalcRuntime(g); |
Toshio Koide | 103ccb2 | 2014-02-18 21:51:25 -0800 | [diff] [blame] | 126 | runtime2.addIntents(pathIntentOpList); |
Brian O'Connor | 7f8e301 | 2014-02-15 23:59:29 -0800 | [diff] [blame] | 127 | |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 128 | // show results |
Toshio Koide | 27ffd41 | 2014-02-18 19:15:27 -0800 | [diff] [blame] | 129 | showResult((PathIntentMap) runtime1.getPathIntents()); |
Brian O'Connor | 7f8e301 | 2014-02-15 23:59:29 -0800 | [diff] [blame] | 130 | System.out.println(runtime2.getPlan()); |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | @Test |
Toshio Koide | 27ffd41 | 2014-02-18 19:15:27 -0800 | [diff] [blame] | 134 | public void useCase3() throws FloodlightModuleException { |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 135 | // create constrained & not best effort shortest path intents |
Toshio Koide | 27ffd41 | 2014-02-18 19:15:27 -0800 | [diff] [blame] | 136 | IntentOperationList opList = new IntentOperationList(); |
| 137 | opList.add(Operator.ADD, new ConstrainedShortestPathIntent("1", 1L, 20L, 1L, 4L, 20L, 6L, 600.0)); |
| 138 | opList.add(Operator.ADD, new ConstrainedShortestPathIntent("2", 2L, 20L, 2L, 6L, 20L, 7L, 600.0)); |
| 139 | opList.add(Operator.ADD, new ShortestPathIntent("3", 4L, 20L, 3L, 8L, 20L, 8L)); |
| 140 | opList.add(Operator.ADD, new ShortestPathIntent("4", 4L, 20L, 4L, 8L, 20L, 9L)); |
| 141 | opList.add(Operator.ADD, new ConstrainedShortestPathIntent("5", 4L, 20L, 5L, 8L, 20L, 10L, 600.0)); |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 142 | |
Toshio Koide | 27ffd41 | 2014-02-18 19:15:27 -0800 | [diff] [blame] | 143 | // compile high-level intent operations into low-level intent operations (calculate paths) |
| 144 | PathCalcRuntimeModule runtime1 = new PathCalcRuntimeModule(); |
| 145 | runtime1.init(modContext); |
| 146 | runtime1.startUp(modContext); |
| 147 | IntentOperationList pathIntentOpList = runtime1.executeIntentOperations(opList); |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 148 | |
Brian O'Connor | 7f8e301 | 2014-02-15 23:59:29 -0800 | [diff] [blame] | 149 | // compile low-level intents into flow entry installation plan |
| 150 | PlanCalcRuntime runtime2 = new PlanCalcRuntime(g); |
Toshio Koide | 103ccb2 | 2014-02-18 21:51:25 -0800 | [diff] [blame] | 151 | runtime2.addIntents(pathIntentOpList); |
Brian O'Connor | 7f8e301 | 2014-02-15 23:59:29 -0800 | [diff] [blame] | 152 | |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 153 | // show results |
Toshio Koide | 27ffd41 | 2014-02-18 19:15:27 -0800 | [diff] [blame] | 154 | showResult((PathIntentMap) runtime1.getPathIntents()); |
Brian O'Connor | 7f8e301 | 2014-02-15 23:59:29 -0800 | [diff] [blame] | 155 | System.out.println(runtime2.getPlan()); |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 156 | } |
| 157 | } |