blob: d31b9b654eb1301f973ec44a6f405faa964afcf7 [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;
9import net.onrc.onos.intent.PathIntents;
10import 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
34 private void showResult(PathIntents intents) {
35 for (PathIntent pathIntent: intents.getIntents()) {
36 System.out.println("Parent intent: " + pathIntent.getParentIntent().toString());
37 System.out.println("Path:");
Toshio Koidec406e792014-02-14 16:52:42 -080038 for (Link link: pathIntent.getPath(g)) {
Toshio Koidec87810e2014-02-11 13:03:21 -080039 System.out.printf("%s --(%f/%f)--> %s\n",
40 link.getSourcePort(),
41 link.getCapacity() - intents.getAvailableBandwidth(link),
42 link.getCapacity(),
43 link.getDestinationPort());
44 }
45 }
46 }
47
48 @Test
49 public void useCase1() {
50 // create shortest path intents
51 LinkedList<Intent> intents = new LinkedList<Intent>();
Toshio Koide0e4d8d22014-02-14 10:56:10 -080052 intents.add(new ShortestPathIntent("1", 1L, 20L, 1L, 4L, 20L, 4L));
53 intents.add(new ShortestPathIntent("2", 2L, 20L, 2L, 6L, 20L, 5L));
54 intents.add(new ShortestPathIntent("3", 4L, 20L, 3L, 8L, 20L, 6L));
Toshio Koidec87810e2014-02-11 13:03:21 -080055
56 // compile high-level intents into low-level intents (calculate paths)
57 PathCalcRuntime runtime1 = new PathCalcRuntime(g);
58 runtime1.addInputIntents(intents);
Brian O'Connor7f8e3012014-02-15 23:59:29 -080059
60 // compile low-level intents into flow entry installation plan
61 PlanCalcRuntime runtime2 = new PlanCalcRuntime(g);
62 runtime2.addIntents(runtime1.getOutputIntents());
Toshio Koidec87810e2014-02-11 13:03:21 -080063
64 // show results
65 showResult(runtime1.getOutputIntents());
Brian O'Connor7f8e3012014-02-15 23:59:29 -080066 System.out.println(runtime2.getPlan());
Toshio Koidec87810e2014-02-11 13:03:21 -080067 }
68
69 @Test
70 public void useCase2() {
71 // create constrained shortest path intents
72 LinkedList<Intent> intents = new LinkedList<Intent>();
Toshio Koide0e4d8d22014-02-14 10:56:10 -080073 intents.add(new ConstrainedShortestPathIntent("1", 1L, 20L, 1L, 4L, 20L, 17L, 400.0));
74 intents.add(new ConstrainedShortestPathIntent("2", 2L, 20L, 2L, 6L, 20L, 18L, 400.0));
75 intents.add(new ConstrainedShortestPathIntent("3", 4L, 20L, 3L, 8L, 20L, 19L, 400.0));
76 intents.add(new ConstrainedShortestPathIntent("4", 3L, 20L, 4L, 8L, 20L, 20L, 400.0));
77 intents.add(new ConstrainedShortestPathIntent("5", 4L, 20L, 5L, 8L, 20L, 21L, 400.0));
Toshio Koidec87810e2014-02-11 13:03:21 -080078
79 // compile high-level intents into low-level intents (calculate paths)
80 PathCalcRuntime runtime1 = new PathCalcRuntime(g);
81 runtime1.addInputIntents(intents);
82
Brian O'Connor7f8e3012014-02-15 23:59:29 -080083 // compile low-level intents into flow entry installation plan
84 PlanCalcRuntime runtime2 = new PlanCalcRuntime(g);
85 runtime2.addIntents(runtime1.getOutputIntents());
86
Toshio Koidec87810e2014-02-11 13:03:21 -080087 // show results
88 showResult(runtime1.getOutputIntents());
Brian O'Connor7f8e3012014-02-15 23:59:29 -080089 System.out.println(runtime2.getPlan());
Toshio Koidec87810e2014-02-11 13:03:21 -080090 }
91
92 @Test
93 public void useCase3() {
94 // create constrained & not best effort shortest path intents
95 LinkedList<Intent> intents = new LinkedList<Intent>();
Toshio Koide0e4d8d22014-02-14 10:56:10 -080096 intents.add(new ConstrainedShortestPathIntent("1", 1L, 20L, 1L, 4L, 20L, 6L, 600.0));
97 intents.add(new ConstrainedShortestPathIntent("2", 2L, 20L, 2L, 6L, 20L, 7L, 600.0));
98 intents.add(new ShortestPathIntent("3", 4L, 20L, 3L, 8L, 20L, 8L));
99 intents.add(new ShortestPathIntent("4", 4L, 20L, 4L, 8L, 20L, 9L));
100 intents.add(new ConstrainedShortestPathIntent("5", 4L, 20L, 5L, 8L, 20L, 10L, 600.0));
Toshio Koidec87810e2014-02-11 13:03:21 -0800101
102 // compile high-level intents into low-level intents (calculate paths)
103 PathCalcRuntime runtime1 = new PathCalcRuntime(g);
104 runtime1.addInputIntents(intents);
105
Brian O'Connor7f8e3012014-02-15 23:59:29 -0800106 // compile low-level intents into flow entry installation plan
107 PlanCalcRuntime runtime2 = new PlanCalcRuntime(g);
108 runtime2.addIntents(runtime1.getOutputIntents());
109
Toshio Koidec87810e2014-02-11 13:03:21 -0800110 // show results
111 showResult(runtime1.getOutputIntents());
Brian O'Connor7f8e3012014-02-15 23:59:29 -0800112 System.out.println(runtime2.getPlan());
Toshio Koidec87810e2014-02-11 13:03:21 -0800113 }
114}