Toshio Koide | 5f26065 | 2014-01-30 14:41:12 -0800 | [diff] [blame^] | 1 | package net.onrc.onos.ofcontroller.app; |
| 2 | |
| 3 | import static org.junit.Assert.*; |
| 4 | |
| 5 | import net.onrc.onos.ofcontroller.app.Flow.FlowState; |
| 6 | |
| 7 | import org.junit.After; |
| 8 | import org.junit.Before; |
| 9 | import org.junit.Test; |
| 10 | |
| 11 | /** |
| 12 | * This code is valid for the architectural study purpose only. |
| 13 | * @author Toshio Koide (t-koide@onlab.us) |
| 14 | */ |
| 15 | public class SimpleTrafficEngineeringTest { |
| 16 | NetworkGraph g; |
| 17 | |
| 18 | @Before |
| 19 | public void setUp() { |
| 20 | g = new NetworkGraph(); |
| 21 | |
| 22 | // add 10 switches (24 ports switch) |
| 23 | for (Integer i=1; i<10; i++) { |
| 24 | Switch sw = g.addSwitch("v" + i.toString()); |
| 25 | for (Integer j=1; j<=24; j++) { |
| 26 | sw.addPort(j); |
| 27 | } |
| 28 | } |
| 29 | |
| 30 | // add loop path |
| 31 | g.addBidirectionalLinks("v1", 1, "v2", 2); |
| 32 | g.addBidirectionalLinks("v2", 1, "v3", 2); |
| 33 | g.addBidirectionalLinks("v3", 1, "v4", 2); |
| 34 | g.addBidirectionalLinks("v4", 1, "v5", 2); |
| 35 | g.addBidirectionalLinks("v5", 1, "v6", 2); |
| 36 | g.addBidirectionalLinks("v6", 1, "v7", 2); |
| 37 | g.addBidirectionalLinks("v7", 1, "v8", 2); |
| 38 | g.addBidirectionalLinks("v8", 1, "v9", 2); |
| 39 | g.addBidirectionalLinks("v9", 1, "v1", 2); |
| 40 | |
| 41 | // add other links |
| 42 | g.addBidirectionalLinks("v1", 3, "v2", 3); |
| 43 | g.addBidirectionalLinks("v2", 4, "v3", 4); |
| 44 | g.addBidirectionalLinks("v4", 5, "v3", 5); |
| 45 | g.addBidirectionalLinks("v5", 6, "v6", 6); |
| 46 | g.addBidirectionalLinks("v7", 7, "v6", 7); |
| 47 | g.addBidirectionalLinks("v8", 8, "v1", 8); |
| 48 | g.addBidirectionalLinks("v9", 9, "v1", 9); |
| 49 | |
| 50 | // set capacity of all links to 1000Mbps |
| 51 | for (Link link: g.getLinks()) { |
| 52 | link.setCapacity(1000.0); |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | @After |
| 57 | public void tearDown() { |
| 58 | } |
| 59 | |
| 60 | @Test |
| 61 | public void useCase1() { |
| 62 | // load TE algorithm |
| 63 | SimpleTrafficEngineering te = new SimpleTrafficEngineering(g); |
| 64 | |
| 65 | // get edge ports |
| 66 | SwitchPort srcPort = g.getSwitch("v1").getPort(20); |
| 67 | SwitchPort dstPort = g.getSwitch("v6").getPort(20); |
| 68 | |
| 69 | // specify bandwidth (Mbps) |
| 70 | double bandWidth = 1000.0; |
| 71 | |
| 72 | // allocate flow |
| 73 | ConstrainedFlow flow = te.allocate(srcPort, dstPort, bandWidth); |
| 74 | assertTrue(flow.isState(FlowState.PathInstalled)); |
| 75 | |
| 76 | // release flow |
| 77 | te.release(flow); |
| 78 | assertTrue(flow.isState(FlowState.PathRemoved)); |
| 79 | } |
| 80 | } |