Open Kilda Java Documentation
SimpleGetShortestPathTest.java
Go to the documentation of this file.
1 /* Copyright 2018 Telstra Open Source
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 package org.openkilda.pce.algo;
17 
21 
22 import org.junit.Test;
23 
24 import java.util.LinkedList;
25 
27 
32  AvailableNetwork network = new AvailableNetwork(null);
33  network.addLink(new SwitchId("00:00:00:22:3d:5a:04:87"), new SwitchId("00:00:b0:d2:f5:00:5a:b8"),
34  7, 60, 0, 3);
35  network.addLink(new SwitchId("00:00:00:22:3d:5a:04:87"), new SwitchId("00:00:70:72:cf:d2:48:6c"),
36  5, 32, 10, 18);
37  network.addLink(new SwitchId("00:00:00:22:3d:5a:04:87"), new SwitchId("00:00:00:22:3d:6b:00:04"),
38  2, 2, 10, 2);
39  network.addLink(new SwitchId("00:00:00:22:3d:5a:04:87"), new SwitchId("00:00:70:72:cf:d2:47:a6"),
40  6, 16, 10, 15);
41  network.addLink(new SwitchId("00:00:00:22:3d:5a:04:87"), new SwitchId("00:00:00:22:3d:6c:00:b8"),
42  1, 3, 40, 4);
43  network.addLink(new SwitchId("00:00:00:22:3d:6b:00:04"), new SwitchId("00:00:00:22:3d:6c:00:b8"),
44  1, 1, 100, 7);
45  network.addLink(new SwitchId("00:00:00:22:3d:6b:00:04"), new SwitchId("00:00:00:22:3d:5a:04:87"),
46  2, 2, 10, 1);
47  network.addLink(new SwitchId("00:00:00:22:3d:6c:00:b8"), new SwitchId("00:00:b0:d2:f5:00:5a:b8"),
48  6, 19, 10, 3);
49  network.addLink(new SwitchId("00:00:00:22:3d:6c:00:b8"), new SwitchId("00:00:00:22:3d:6b:00:04"),
50  1, 1, 100, 2);
51  network.addLink(new SwitchId("00:00:00:22:3d:6c:00:b8"), new SwitchId("00:00:00:22:3d:5a:04:87"),
52  3, 1, 100, 2);
53  network.addLink(new SwitchId("00:00:70:72:cf:d2:47:a6"), new SwitchId("00:00:70:72:cf:d2:48:6c"),
54  52, 52, 10, 381);
55  network.addLink(new SwitchId("00:00:70:72:cf:d2:47:a6"), new SwitchId("00:00:00:22:3d:5a:04:87"),
56  16, 6, 10, 18);
57  network.addLink(new SwitchId("00:00:70:72:cf:d2:48:6c"), new SwitchId("00:00:b0:d2:f5:00:5a:b8"),
58  48, 49, 10, 97);
59  network.addLink(new SwitchId("00:00:70:72:cf:d2:48:6c"), new SwitchId("00:00:70:72:cf:d2:47:a6"),
60  52, 52, 10, 1021);
61  network.addLink(new SwitchId("00:00:70:72:cf:d2:48:6c"), new SwitchId("00:00:00:22:3d:5a:04:87"),
62  32, 5, 10, 16);
63  network.addLink(new SwitchId("00:00:b0:d2:f5:00:5a:b8"), new SwitchId("00:00:70:72:cf:d2:48:6c"),
64  49, 48, 10, 0);
65  network.addLink(new SwitchId("00:00:b0:d2:f5:00:5a:b8"), new SwitchId("00:00:00:22:3d:6c:00:b8"),
66  19, 6, 10, 3);
67  network.addLink(new SwitchId("00:00:b0:d2:f5:00:5a:b8"), new SwitchId("00:00:00:22:3d:5a:04:87"),
68  50, 7, 0, 3);
69  return network;
70  }
71 
72 
73  @Test
74  public void getPath() {
75 
76  AvailableNetwork network = buildNetwork1();
77  network.removeSelfLoops().reduceByCost();
78  SimpleGetShortestPath forward = new SimpleGetShortestPath(network, new SwitchId("00:00:70:72:cf:d2:47:a6"),
79  new SwitchId("00:00:b0:d2:f5:00:5a:b8"), 35);
80 
81  LinkedList<SimpleIsl> fpath = forward.getPath();
82  System.out.println("forward.getPath() = " + fpath);
83  SimpleGetShortestPath reverse = new SimpleGetShortestPath(network, new SwitchId("00:00:b0:d2:f5:00:5a:b8"),
84  new SwitchId("00:00:70:72:cf:d2:47:a6"), 35);
85  LinkedList<SimpleIsl> rpath = reverse.getPath(fpath);
86  System.out.println("reverse.getPath() = " + rpath);
87 
88 
89  }
90 }
AvailableNetwork addLink(SwitchId srcDpid, SwitchId dstDpid, int srcPort, int dstPort, int cost, int latency)