Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 1 | package net.onrc.onos.intent.runtime; |
| 2 | |
| 3 | import java.util.LinkedList; |
| 4 | |
| 5 | import net.onrc.onos.intent.ConstrainedShortestPathIntent; |
| 6 | import net.onrc.onos.intent.Intent; |
Toshio Koide | ebdbb62 | 2014-02-12 20:28:38 -0800 | [diff] [blame] | 7 | import net.onrc.onos.intent.MockNetworkGraph; |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 8 | import net.onrc.onos.intent.PathIntent; |
Toshio Koide | 4f30873 | 2014-02-18 15:19:48 -0800 | [diff] [blame] | 9 | import net.onrc.onos.intent.PathIntentMap; |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 10 | import net.onrc.onos.intent.ShortestPathIntent; |
| 11 | import net.onrc.onos.ofcontroller.networkgraph.*; |
| 12 | |
| 13 | import org.junit.After; |
| 14 | import org.junit.Before; |
| 15 | import org.junit.Test; |
| 16 | |
| 17 | /** |
| 18 | * @author Toshio Koide (t-koide@onlab.us) |
| 19 | */ |
| 20 | public class UseCaseTest { |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 21 | NetworkGraph g; |
| 22 | |
| 23 | @Before |
| 24 | public void setUp() { |
Toshio Koide | ebdbb62 | 2014-02-12 20:28:38 -0800 | [diff] [blame] | 25 | MockNetworkGraph graph = new MockNetworkGraph(); |
| 26 | graph.createSampleTopology(); |
| 27 | g = graph; |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 28 | } |
| 29 | |
| 30 | @After |
| 31 | public void tearDown() { |
| 32 | } |
| 33 | |
Toshio Koide | 4f30873 | 2014-02-18 15:19:48 -0800 | [diff] [blame] | 34 | private void showResult(PathIntentMap intents) { |
| 35 | for (Intent intent: intents.getAllIntents()) { |
| 36 | PathIntent pathIntent = (PathIntent)intent; |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 37 | System.out.println("Parent intent: " + pathIntent.getParentIntent().toString()); |
| 38 | System.out.println("Path:"); |
Toshio Koide | c406e79 | 2014-02-14 16:52:42 -0800 | [diff] [blame] | 39 | for (Link link: pathIntent.getPath(g)) { |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 40 | System.out.printf("%s --(%f/%f)--> %s\n", |
| 41 | link.getSourcePort(), |
| 42 | link.getCapacity() - intents.getAvailableBandwidth(link), |
| 43 | link.getCapacity(), |
| 44 | link.getDestinationPort()); |
| 45 | } |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | @Test |
| 50 | public void useCase1() { |
| 51 | // create shortest path intents |
| 52 | LinkedList<Intent> intents = new LinkedList<Intent>(); |
Toshio Koide | 0e4d8d2 | 2014-02-14 10:56:10 -0800 | [diff] [blame] | 53 | intents.add(new ShortestPathIntent("1", 1L, 20L, 1L, 4L, 20L, 4L)); |
| 54 | intents.add(new ShortestPathIntent("2", 2L, 20L, 2L, 6L, 20L, 5L)); |
| 55 | intents.add(new ShortestPathIntent("3", 4L, 20L, 3L, 8L, 20L, 6L)); |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 56 | |
| 57 | // compile high-level intents into low-level intents (calculate paths) |
| 58 | PathCalcRuntime runtime1 = new PathCalcRuntime(g); |
Toshio Koide | 4f30873 | 2014-02-18 15:19:48 -0800 | [diff] [blame] | 59 | PathIntentMap pathIntents = runtime1.calcPathIntents(intents, new PathIntentMap(g)); |
Brian O'Connor | 7f8e301 | 2014-02-15 23:59:29 -0800 | [diff] [blame] | 60 | |
| 61 | // compile low-level intents into flow entry installation plan |
| 62 | PlanCalcRuntime runtime2 = new PlanCalcRuntime(g); |
Toshio Koide | 4f30873 | 2014-02-18 15:19:48 -0800 | [diff] [blame] | 63 | runtime2.addIntents(pathIntents); |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 64 | |
| 65 | // show results |
Toshio Koide | 4f30873 | 2014-02-18 15:19:48 -0800 | [diff] [blame] | 66 | showResult(pathIntents); |
Brian O'Connor | 7f8e301 | 2014-02-15 23:59:29 -0800 | [diff] [blame] | 67 | System.out.println(runtime2.getPlan()); |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | @Test |
| 71 | public void useCase2() { |
| 72 | // create constrained shortest path intents |
| 73 | LinkedList<Intent> intents = new LinkedList<Intent>(); |
Toshio Koide | 0e4d8d2 | 2014-02-14 10:56:10 -0800 | [diff] [blame] | 74 | intents.add(new ConstrainedShortestPathIntent("1", 1L, 20L, 1L, 4L, 20L, 17L, 400.0)); |
| 75 | intents.add(new ConstrainedShortestPathIntent("2", 2L, 20L, 2L, 6L, 20L, 18L, 400.0)); |
| 76 | intents.add(new ConstrainedShortestPathIntent("3", 4L, 20L, 3L, 8L, 20L, 19L, 400.0)); |
| 77 | intents.add(new ConstrainedShortestPathIntent("4", 3L, 20L, 4L, 8L, 20L, 20L, 400.0)); |
| 78 | intents.add(new ConstrainedShortestPathIntent("5", 4L, 20L, 5L, 8L, 20L, 21L, 400.0)); |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 79 | |
| 80 | // compile high-level intents into low-level intents (calculate paths) |
| 81 | PathCalcRuntime runtime1 = new PathCalcRuntime(g); |
Toshio Koide | 4f30873 | 2014-02-18 15:19:48 -0800 | [diff] [blame] | 82 | PathIntentMap pathIntents = runtime1.calcPathIntents(intents, new PathIntentMap(g)); |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 83 | |
Brian O'Connor | 7f8e301 | 2014-02-15 23:59:29 -0800 | [diff] [blame] | 84 | // compile low-level intents into flow entry installation plan |
| 85 | PlanCalcRuntime runtime2 = new PlanCalcRuntime(g); |
Toshio Koide | 4f30873 | 2014-02-18 15:19:48 -0800 | [diff] [blame] | 86 | runtime2.addIntents(pathIntents); |
Brian O'Connor | 7f8e301 | 2014-02-15 23:59:29 -0800 | [diff] [blame] | 87 | |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 88 | // show results |
Toshio Koide | 4f30873 | 2014-02-18 15:19:48 -0800 | [diff] [blame] | 89 | showResult(pathIntents); |
Brian O'Connor | 7f8e301 | 2014-02-15 23:59:29 -0800 | [diff] [blame] | 90 | System.out.println(runtime2.getPlan()); |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | @Test |
| 94 | public void useCase3() { |
| 95 | // create constrained & not best effort shortest path intents |
| 96 | LinkedList<Intent> intents = new LinkedList<Intent>(); |
Toshio Koide | 0e4d8d2 | 2014-02-14 10:56:10 -0800 | [diff] [blame] | 97 | intents.add(new ConstrainedShortestPathIntent("1", 1L, 20L, 1L, 4L, 20L, 6L, 600.0)); |
| 98 | intents.add(new ConstrainedShortestPathIntent("2", 2L, 20L, 2L, 6L, 20L, 7L, 600.0)); |
| 99 | intents.add(new ShortestPathIntent("3", 4L, 20L, 3L, 8L, 20L, 8L)); |
| 100 | intents.add(new ShortestPathIntent("4", 4L, 20L, 4L, 8L, 20L, 9L)); |
| 101 | intents.add(new ConstrainedShortestPathIntent("5", 4L, 20L, 5L, 8L, 20L, 10L, 600.0)); |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 102 | |
| 103 | // compile high-level intents into low-level intents (calculate paths) |
| 104 | PathCalcRuntime runtime1 = new PathCalcRuntime(g); |
Toshio Koide | 4f30873 | 2014-02-18 15:19:48 -0800 | [diff] [blame] | 105 | PathIntentMap pathIntents = runtime1.calcPathIntents(intents, new PathIntentMap(g)); |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 106 | |
Brian O'Connor | 7f8e301 | 2014-02-15 23:59:29 -0800 | [diff] [blame] | 107 | // compile low-level intents into flow entry installation plan |
| 108 | PlanCalcRuntime runtime2 = new PlanCalcRuntime(g); |
Toshio Koide | 4f30873 | 2014-02-18 15:19:48 -0800 | [diff] [blame] | 109 | runtime2.addIntents(pathIntents); |
Brian O'Connor | 7f8e301 | 2014-02-15 23:59:29 -0800 | [diff] [blame] | 110 | |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 111 | // show results |
Toshio Koide | 4f30873 | 2014-02-18 15:19:48 -0800 | [diff] [blame] | 112 | showResult(pathIntents); |
Brian O'Connor | 7f8e301 | 2014-02-15 23:59:29 -0800 | [diff] [blame] | 113 | System.out.println(runtime2.getPlan()); |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 114 | } |
| 115 | } |