blob: 73eee6b17966195194e96865a3707bf4909fc7d7 [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:");
38 for (Link link: pathIntent.getPath()) {
39 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 Koide13986d12014-02-11 20:25:32 -080052 intents.add(new ShortestPathIntent(g, "1", 1L, 20L, 1L, 4L, 20L, 4L));
53 intents.add(new ShortestPathIntent(g, "2", 2L, 20L, 2L, 6L, 20L, 5L));
54 intents.add(new ShortestPathIntent(g, "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);
59
60 // show results
61 showResult(runtime1.getOutputIntents());
62 }
63
64 @Test
65 public void useCase2() {
66 // create constrained shortest path intents
67 LinkedList<Intent> intents = new LinkedList<Intent>();
Toshio Koide13986d12014-02-11 20:25:32 -080068 intents.add(new ConstrainedShortestPathIntent(g, "1", 1L, 20L, 1L, 4L, 20L, 17L, 400.0));
69 intents.add(new ConstrainedShortestPathIntent(g, "2", 2L, 20L, 2L, 6L, 20L, 18L, 400.0));
70 intents.add(new ConstrainedShortestPathIntent(g, "3", 4L, 20L, 3L, 8L, 20L, 19L, 400.0));
71 intents.add(new ConstrainedShortestPathIntent(g, "4", 3L, 20L, 4L, 8L, 20L, 20L, 400.0));
72 intents.add(new ConstrainedShortestPathIntent(g, "5", 4L, 20L, 5L, 8L, 20L, 21L, 400.0));
Toshio Koidec87810e2014-02-11 13:03:21 -080073
74 // compile high-level intents into low-level intents (calculate paths)
75 PathCalcRuntime runtime1 = new PathCalcRuntime(g);
76 runtime1.addInputIntents(intents);
77
78 // show results
79 showResult(runtime1.getOutputIntents());
80 }
81
82 @Test
83 public void useCase3() {
84 // create constrained & not best effort shortest path intents
85 LinkedList<Intent> intents = new LinkedList<Intent>();
Toshio Koide13986d12014-02-11 20:25:32 -080086 intents.add(new ConstrainedShortestPathIntent(g, "1", 1L, 20L, 1L, 4L, 20L, 6L, 600.0));
87 intents.add(new ConstrainedShortestPathIntent(g, "2", 2L, 20L, 2L, 6L, 20L, 7L, 600.0));
88 intents.add(new ShortestPathIntent(g, "3", 4L, 20L, 3L, 8L, 20L, 8L));
89 intents.add(new ShortestPathIntent(g, "4", 4L, 20L, 4L, 8L, 20L, 9L));
90 intents.add(new ConstrainedShortestPathIntent(g, "5", 4L, 20L, 5L, 8L, 20L, 10L, 600.0));
Toshio Koidec87810e2014-02-11 13:03:21 -080091
92 // compile high-level intents into low-level intents (calculate paths)
93 PathCalcRuntime runtime1 = new PathCalcRuntime(g);
94 runtime1.addInputIntents(intents);
95
96 // show results
97 showResult(runtime1.getOutputIntents());
98 }
99}