blob: e32da325359b4fb74f685f20045717dc0626d40f [file] [log] [blame]
Toshio Koidec87810e2014-02-11 13:03:21 -08001package net.onrc.onos.intent.runtime;
2
3import java.util.LinkedList;
4
5import net.onrc.onos.intent.ConstrainedShortestPathIntent;
6import net.onrc.onos.intent.Intent;
Toshio Koideebdbb622014-02-12 20:28:38 -08007import net.onrc.onos.intent.MockNetworkGraph;
Toshio Koidec87810e2014-02-11 13:03:21 -08008import net.onrc.onos.intent.PathIntent;
Toshio Koide4f308732014-02-18 15:19:48 -08009import net.onrc.onos.intent.PathIntentMap;
Toshio Koidec87810e2014-02-11 13:03:21 -080010import net.onrc.onos.intent.ShortestPathIntent;
11import net.onrc.onos.ofcontroller.networkgraph.*;
12
13import org.junit.After;
14import org.junit.Before;
15import org.junit.Test;
16
17/**
18 * @author Toshio Koide (t-koide@onlab.us)
19 */
20public class UseCaseTest {
Toshio Koidec87810e2014-02-11 13:03:21 -080021 NetworkGraph g;
22
23 @Before
24 public void setUp() {
Toshio Koideebdbb622014-02-12 20:28:38 -080025 MockNetworkGraph graph = new MockNetworkGraph();
26 graph.createSampleTopology();
27 g = graph;
Toshio Koidec87810e2014-02-11 13:03:21 -080028 }
29
30 @After
31 public void tearDown() {
32 }
33
Toshio Koide4f308732014-02-18 15:19:48 -080034 private void showResult(PathIntentMap intents) {
35 for (Intent intent: intents.getAllIntents()) {
36 PathIntent pathIntent = (PathIntent)intent;
Toshio Koidec87810e2014-02-11 13:03:21 -080037 System.out.println("Parent intent: " + pathIntent.getParentIntent().toString());
38 System.out.println("Path:");
Toshio Koidec406e792014-02-14 16:52:42 -080039 for (Link link: pathIntent.getPath(g)) {
Toshio Koidec87810e2014-02-11 13:03:21 -080040 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 Koide0e4d8d22014-02-14 10:56:10 -080053 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 Koidec87810e2014-02-11 13:03:21 -080056
57 // compile high-level intents into low-level intents (calculate paths)
58 PathCalcRuntime runtime1 = new PathCalcRuntime(g);
Toshio Koide4f308732014-02-18 15:19:48 -080059 PathIntentMap pathIntents = runtime1.calcPathIntents(intents, new PathIntentMap(g));
Brian O'Connor7f8e3012014-02-15 23:59:29 -080060
61 // compile low-level intents into flow entry installation plan
62 PlanCalcRuntime runtime2 = new PlanCalcRuntime(g);
Toshio Koide4f308732014-02-18 15:19:48 -080063 runtime2.addIntents(pathIntents);
Toshio Koidec87810e2014-02-11 13:03:21 -080064
65 // show results
Toshio Koide4f308732014-02-18 15:19:48 -080066 showResult(pathIntents);
Brian O'Connor7f8e3012014-02-15 23:59:29 -080067 System.out.println(runtime2.getPlan());
Toshio Koidec87810e2014-02-11 13:03:21 -080068 }
69
70 @Test
71 public void useCase2() {
72 // create constrained shortest path intents
73 LinkedList<Intent> intents = new LinkedList<Intent>();
Toshio Koide0e4d8d22014-02-14 10:56:10 -080074 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 Koidec87810e2014-02-11 13:03:21 -080079
80 // compile high-level intents into low-level intents (calculate paths)
81 PathCalcRuntime runtime1 = new PathCalcRuntime(g);
Toshio Koide4f308732014-02-18 15:19:48 -080082 PathIntentMap pathIntents = runtime1.calcPathIntents(intents, new PathIntentMap(g));
Toshio Koidec87810e2014-02-11 13:03:21 -080083
Brian O'Connor7f8e3012014-02-15 23:59:29 -080084 // compile low-level intents into flow entry installation plan
85 PlanCalcRuntime runtime2 = new PlanCalcRuntime(g);
Toshio Koide4f308732014-02-18 15:19:48 -080086 runtime2.addIntents(pathIntents);
Brian O'Connor7f8e3012014-02-15 23:59:29 -080087
Toshio Koidec87810e2014-02-11 13:03:21 -080088 // show results
Toshio Koide4f308732014-02-18 15:19:48 -080089 showResult(pathIntents);
Brian O'Connor7f8e3012014-02-15 23:59:29 -080090 System.out.println(runtime2.getPlan());
Toshio Koidec87810e2014-02-11 13:03:21 -080091 }
92
93 @Test
94 public void useCase3() {
95 // create constrained & not best effort shortest path intents
96 LinkedList<Intent> intents = new LinkedList<Intent>();
Toshio Koide0e4d8d22014-02-14 10:56:10 -080097 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 Koidec87810e2014-02-11 13:03:21 -0800102
103 // compile high-level intents into low-level intents (calculate paths)
104 PathCalcRuntime runtime1 = new PathCalcRuntime(g);
Toshio Koide4f308732014-02-18 15:19:48 -0800105 PathIntentMap pathIntents = runtime1.calcPathIntents(intents, new PathIntentMap(g));
Toshio Koidec87810e2014-02-11 13:03:21 -0800106
Brian O'Connor7f8e3012014-02-15 23:59:29 -0800107 // compile low-level intents into flow entry installation plan
108 PlanCalcRuntime runtime2 = new PlanCalcRuntime(g);
Toshio Koide4f308732014-02-18 15:19:48 -0800109 runtime2.addIntents(pathIntents);
Brian O'Connor7f8e3012014-02-15 23:59:29 -0800110
Toshio Koidec87810e2014-02-11 13:03:21 -0800111 // show results
Toshio Koide4f308732014-02-18 15:19:48 -0800112 showResult(pathIntents);
Brian O'Connor7f8e3012014-02-15 23:59:29 -0800113 System.out.println(runtime2.getPlan());
Toshio Koidec87810e2014-02-11 13:03:21 -0800114 }
115}