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; |
| 7 | import net.onrc.onos.intent.PathIntent; |
| 8 | import net.onrc.onos.intent.PathIntents; |
| 9 | import net.onrc.onos.intent.ShortestPathIntent; |
| 10 | import net.onrc.onos.ofcontroller.networkgraph.*; |
| 11 | |
| 12 | import org.junit.After; |
| 13 | import org.junit.Before; |
| 14 | import org.junit.Test; |
| 15 | |
| 16 | /** |
| 17 | * @author Toshio Koide (t-koide@onlab.us) |
| 18 | */ |
| 19 | public class UseCaseTest { |
| 20 | public class MutableNetworkGraph extends AbstractNetworkGraph { |
| 21 | public Switch addSwitch(Long switchId) { |
| 22 | SwitchImpl sw = new SwitchImpl(this, switchId); |
| 23 | switches.put(sw.getDpid(), sw); |
| 24 | return sw; |
| 25 | |
| 26 | } |
| 27 | |
| 28 | public Link addLink(Long srcDpid, Long srcPortNo, Long dstDpid, Long dstPortNo) { |
| 29 | return new LinkImpl( |
| 30 | this, |
| 31 | getSwitch(srcDpid).getPort(srcPortNo), |
| 32 | getSwitch(dstDpid).getPort(dstPortNo)); |
| 33 | } |
| 34 | |
| 35 | public Link[] addBidirectionalLinks(Long srcDpid, Long srcPortNo, Long dstDpid, Long dstPortNo) { |
| 36 | Link[] links = new Link[2]; |
| 37 | links[0] = addLink(srcDpid, srcPortNo, dstDpid, dstPortNo); |
| 38 | links[1] = addLink(dstDpid, dstPortNo, srcDpid, srcPortNo); |
| 39 | |
| 40 | return links; |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | NetworkGraph g; |
| 45 | |
| 46 | @Before |
| 47 | public void setUp() { |
| 48 | MutableNetworkGraph g = new MutableNetworkGraph(); |
| 49 | |
| 50 | // add 10 switches (24 ports switch) |
| 51 | for (Long dpid=1L; dpid<10L; dpid++) { |
| 52 | SwitchImpl sw = (SwitchImpl) g.addSwitch(dpid); |
| 53 | for (Long j=1L; j<=24L; j++) { |
| 54 | sw.addPort(j); |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | // add loop path |
| 59 | g.addBidirectionalLinks(1L, 1L, 2L, 2L); |
| 60 | g.addBidirectionalLinks(2L, 1L, 3L, 2L); |
| 61 | g.addBidirectionalLinks(3L, 1L, 4L, 2L); |
| 62 | g.addBidirectionalLinks(4L, 1L, 5L, 2L); |
| 63 | g.addBidirectionalLinks(5L, 1L, 6L, 2L); |
| 64 | g.addBidirectionalLinks(6L, 1L, 7L, 2L); |
| 65 | g.addBidirectionalLinks(7L, 1L, 8L, 2L); |
| 66 | g.addBidirectionalLinks(8L, 1L, 9L, 2L); |
| 67 | g.addBidirectionalLinks(9L, 1L, 1L, 2L); |
| 68 | |
| 69 | // add other links |
| 70 | g.addBidirectionalLinks(1L, 3L, 5L, 3L); |
| 71 | g.addBidirectionalLinks(2L, 4L, 5L, 4L); |
| 72 | g.addBidirectionalLinks(2L, 5L, 7L, 5L); |
| 73 | g.addBidirectionalLinks(3L, 6L, 7L, 6L); |
| 74 | g.addBidirectionalLinks(3L, 7L, 8L, 7L); |
| 75 | g.addBidirectionalLinks(3L, 8L, 9L, 8L); |
| 76 | g.addBidirectionalLinks(4L, 9l, 9L, 9L); |
| 77 | |
| 78 | // set capacity of all links to 1000Mbps |
| 79 | for (Link link: g.getLinks()) { |
| 80 | ((LinkImpl)link).setCapacity(1000.0); |
| 81 | } |
| 82 | |
| 83 | /* |
| 84 | // add Devices |
| 85 | for (Long l=1L; l<=9L; l++) { |
| 86 | DeviceImpl d = new DeviceImpl(g, MACAddress.valueOf(l)); |
| 87 | d.addAttachmentPoint(g.getSwitch(l).getPort(20L)); |
| 88 | g.addDevice(d); |
| 89 | } |
| 90 | */ |
| 91 | |
| 92 | this.g = g; |
| 93 | } |
| 94 | |
| 95 | @After |
| 96 | public void tearDown() { |
| 97 | } |
| 98 | |
| 99 | private void showResult(PathIntents intents) { |
| 100 | for (PathIntent pathIntent: intents.getIntents()) { |
| 101 | System.out.println("Parent intent: " + pathIntent.getParentIntent().toString()); |
| 102 | System.out.println("Path:"); |
| 103 | for (Link link: pathIntent.getPath()) { |
| 104 | System.out.printf("%s --(%f/%f)--> %s\n", |
| 105 | link.getSourcePort(), |
| 106 | link.getCapacity() - intents.getAvailableBandwidth(link), |
| 107 | link.getCapacity(), |
| 108 | link.getDestinationPort()); |
| 109 | } |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | @Test |
| 114 | public void useCase1() { |
| 115 | // create shortest path intents |
| 116 | LinkedList<Intent> intents = new LinkedList<Intent>(); |
Toshio Koide | 13986d1 | 2014-02-11 20:25:32 -0800 | [diff] [blame^] | 117 | intents.add(new ShortestPathIntent(g, "1", 1L, 20L, 1L, 4L, 20L, 4L)); |
| 118 | intents.add(new ShortestPathIntent(g, "2", 2L, 20L, 2L, 6L, 20L, 5L)); |
| 119 | intents.add(new ShortestPathIntent(g, "3", 4L, 20L, 3L, 8L, 20L, 6L)); |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 120 | |
| 121 | // compile high-level intents into low-level intents (calculate paths) |
| 122 | PathCalcRuntime runtime1 = new PathCalcRuntime(g); |
| 123 | runtime1.addInputIntents(intents); |
| 124 | |
| 125 | // show results |
| 126 | showResult(runtime1.getOutputIntents()); |
| 127 | } |
| 128 | |
| 129 | @Test |
| 130 | public void useCase2() { |
| 131 | // create constrained shortest path intents |
| 132 | LinkedList<Intent> intents = new LinkedList<Intent>(); |
Toshio Koide | 13986d1 | 2014-02-11 20:25:32 -0800 | [diff] [blame^] | 133 | intents.add(new ConstrainedShortestPathIntent(g, "1", 1L, 20L, 1L, 4L, 20L, 17L, 400.0)); |
| 134 | intents.add(new ConstrainedShortestPathIntent(g, "2", 2L, 20L, 2L, 6L, 20L, 18L, 400.0)); |
| 135 | intents.add(new ConstrainedShortestPathIntent(g, "3", 4L, 20L, 3L, 8L, 20L, 19L, 400.0)); |
| 136 | intents.add(new ConstrainedShortestPathIntent(g, "4", 3L, 20L, 4L, 8L, 20L, 20L, 400.0)); |
| 137 | intents.add(new ConstrainedShortestPathIntent(g, "5", 4L, 20L, 5L, 8L, 20L, 21L, 400.0)); |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 138 | |
| 139 | // compile high-level intents into low-level intents (calculate paths) |
| 140 | PathCalcRuntime runtime1 = new PathCalcRuntime(g); |
| 141 | runtime1.addInputIntents(intents); |
| 142 | |
| 143 | // show results |
| 144 | showResult(runtime1.getOutputIntents()); |
| 145 | } |
| 146 | |
| 147 | @Test |
| 148 | public void useCase3() { |
| 149 | // create constrained & not best effort shortest path intents |
| 150 | LinkedList<Intent> intents = new LinkedList<Intent>(); |
Toshio Koide | 13986d1 | 2014-02-11 20:25:32 -0800 | [diff] [blame^] | 151 | intents.add(new ConstrainedShortestPathIntent(g, "1", 1L, 20L, 1L, 4L, 20L, 6L, 600.0)); |
| 152 | intents.add(new ConstrainedShortestPathIntent(g, "2", 2L, 20L, 2L, 6L, 20L, 7L, 600.0)); |
| 153 | intents.add(new ShortestPathIntent(g, "3", 4L, 20L, 3L, 8L, 20L, 8L)); |
| 154 | intents.add(new ShortestPathIntent(g, "4", 4L, 20L, 4L, 8L, 20L, 9L)); |
| 155 | intents.add(new ConstrainedShortestPathIntent(g, "5", 4L, 20L, 5L, 8L, 20L, 10L, 600.0)); |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 156 | |
| 157 | // compile high-level intents into low-level intents (calculate paths) |
| 158 | PathCalcRuntime runtime1 = new PathCalcRuntime(g); |
| 159 | runtime1.addInputIntents(intents); |
| 160 | |
| 161 | // show results |
| 162 | showResult(runtime1.getOutputIntents()); |
| 163 | } |
| 164 | } |