Open Kilda Java Documentation
PathComputerTest.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.provider;
17 
29 
30 import org.junit.After;
31 import org.junit.AfterClass;
32 import org.junit.Assert;
33 import org.junit.BeforeClass;
34 import org.junit.Ignore;
35 import org.junit.Test;
36 import org.neo4j.driver.v1.AuthTokens;
37 import org.neo4j.driver.v1.Driver;
38 import org.neo4j.driver.v1.GraphDatabase;
39 import org.neo4j.graphdb.GraphDatabaseService;
40 import org.neo4j.graphdb.Label;
41 import org.neo4j.graphdb.Node;
42 import org.neo4j.graphdb.Relationship;
43 import org.neo4j.graphdb.RelationshipType;
44 import org.neo4j.graphdb.Transaction;
45 import org.neo4j.graphdb.factory.GraphDatabaseFactory;
46 import org.neo4j.io.fs.FileUtils;
47 import org.neo4j.kernel.configuration.BoltConnector;
48 
49 import java.io.File;
50 import java.util.Arrays;
51 import java.util.LinkedList;
52 import java.util.List;
53 
58 public class PathComputerTest {
59 
60  private static GraphDatabaseService graphDb;
61 
62  private static final File databaseDirectory = new File("target/neo4j-test-db");
63  private static Driver driver;
64  private static NeoDriver nd;
65 
66  @BeforeClass
67  public static void setUpOnce() throws Exception {
68  FileUtils.deleteRecursively(databaseDirectory); // delete neo db file
69 
70  // This next area enables Kilda to connect to the local db
71  BoltConnector bolt = new BoltConnector("0");
72  graphDb = new GraphDatabaseFactory()
73  .newEmbeddedDatabaseBuilder(databaseDirectory)
74  .setConfig(bolt.type, "BOLT")
75  .setConfig(bolt.enabled, "true")
76  .setConfig(bolt.listen_address, "localhost:7878")
77  .newGraphDatabase();
78 
79  driver = GraphDatabase.driver("bolt://localhost:7878", AuthTokens.basic("neo4j", "password"));
80  nd = new NeoDriver(driver);
81 
82  }
83 
84  @AfterClass
85  public static void teatDownOnce() {
86  driver.close();
87  graphDb.shutdown();
88  }
89 
90  @After
91  public void cleanUp() {
92  try (Transaction tx = graphDb.beginTx()) {
93  graphDb.execute("MATCH (n) DETACH DELETE n");
94  tx.success();
95  }
96  }
97 
98  @Test
99  public void testGetFlowInfo() {
100  try (Transaction tx = graphDb.beginTx()) {
101  Node node1;
102  node1 = graphDb.createNode(Label.label("switch"));
103  node1.setProperty("name", "00:03");
104  Node node2;
105  node2 = graphDb.createNode(Label.label("switch"));
106  node2.setProperty("name", "00:04");
107  Relationship rel1 = node1.createRelationshipTo(node2, RelationshipType.withName("flow"));
108  rel1.setProperty("flowid", "f1");
109  rel1.setProperty("cookie", 3);
110  rel1.setProperty("meter_id", 2);
111  rel1.setProperty("transit_vlan", 1);
112  rel1.setProperty("src_switch", "00:03");
113  tx.success();
114  }
115 
116  List<FlowInfo> fi = nd.getFlowInfo();
117  Assert.assertEquals(fi.get(0).getFlowId(), "f1");
118  Assert.assertEquals(fi.get(0).getCookie(), 3);
119  Assert.assertEquals(fi.get(0).getMeterId(), 2);
120  Assert.assertEquals(fi.get(0).getTransitVlanId(), 1);
121  Assert.assertEquals(fi.get(0).getSrcSwitchId(), "00:03");
122  }
123 
124  private Node createNode(String name) {
125  Node n = graphDb.createNode(Label.label("switch"));
126  n.setProperty("name", name);
127  n.setProperty("state", "active");
128  return n;
129  }
130 
131  private Relationship addRel(Node n1, Node n2, String status, String actual, int cost, long bw, int port) {
132  Relationship rel;
133  rel = n1.createRelationshipTo(n2, RelationshipType.withName("isl"));
134  rel.setProperty("status", status);
135  rel.setProperty("actual", actual);
136  if (cost >= 0) {
137  rel.setProperty("cost", cost);
138  }
139  rel.setProperty("available_bandwidth", bw);
140  rel.setProperty("latency", 5);
141  rel.setProperty("src_port", port);
142  rel.setProperty("dst_port", port);
143  rel.setProperty("src_switch", n1.getProperty("name"));
144  rel.setProperty("dst_switch", n2.getProperty("name"));
145  return rel;
146  }
147 
148  private Relationship addRelAsString(Node n1, Node n2, String status, String actual, String cost, int bw, int port) {
149  Relationship rel;
150  rel = n1.createRelationshipTo(n2, RelationshipType.withName("isl"));
151  rel.setProperty("status", status);
152  rel.setProperty("actual", actual);
153  if (cost != null && !cost.isEmpty()) {
154  rel.setProperty("cost", cost);
155  }
156  rel.setProperty("available_bandwidth", bw);
157  rel.setProperty("latency", 5);
158  rel.setProperty("src_port", port);
159  rel.setProperty("dst_port", port);
160  rel.setProperty("src_switch", n1.getProperty("name"));
161  rel.setProperty("dst_switch", n2.getProperty("name"));
162  return rel;
163  }
164 
168  private void createDiamondAsString(String pathBstatus, String pathCstatus, String pathBcost, String pathCcost,
169  String switchStart, int startIndex) {
170  try (Transaction tx = graphDb.beginTx()) {
171  // A - B - D
172  // + C +
173  int index = startIndex;
174  Node nodeA = createNode(switchStart + String.format("%02X", index++));
175  Node nodeB = createNode(switchStart + String.format("%02X", index++));
176  Node nodeC = createNode(switchStart + String.format("%02X", index++));
177  Node nodeD = createNode(switchStart + String.format("%02X", index++));
178  String actual = (pathBstatus.equals("active") && pathCstatus.equals("active")) ? "active" : "inactive";
179  addRelAsString(nodeA, nodeB, pathBstatus, actual, pathBcost, 1000, 5);
180  addRelAsString(nodeA, nodeC, pathCstatus, actual, pathCcost, 1000, 6);
181  addRelAsString(nodeB, nodeD, pathBstatus, actual, pathBcost, 1000, 6);
182  addRelAsString(nodeC, nodeD, pathCstatus, actual, pathCcost, 1000, 5);
183  addRelAsString(nodeB, nodeA, pathBstatus, actual, pathBcost, 1000, 5);
184  addRelAsString(nodeC, nodeA, pathCstatus, actual, pathCcost, 1000, 6);
185  addRelAsString(nodeD, nodeB, pathBstatus, actual, pathBcost, 1000, 6);
186  addRelAsString(nodeD, nodeC, pathCstatus, actual, pathCcost, 1000, 5);
187  tx.success();
188  }
189  }
190 
191  private void createDiamond(String pathBstatus, String pathCstatus, int pathBcost, int pathCcost) {
192  createDiamond(pathBstatus, pathCstatus, pathBcost, pathCcost, "00:", 1);
193  }
194 
195  private void createDiamond(String pathBstatus, String pathCstatus, int pathBcost, int pathCcost,
196  String switchStart, int startIndex) {
197  try (Transaction tx = graphDb.beginTx()) {
198  // A - B - D
199  // + C +
200  int index = startIndex;
201  Node nodeA = createNode(switchStart + String.format("%02X", index++));
202  Node nodeB = createNode(switchStart + String.format("%02X", index++));
203  Node nodeC = createNode(switchStart + String.format("%02X", index++));
204  Node nodeD = createNode(switchStart + String.format("%02X", index++));
205  String actual = (pathBstatus.equals("active") && pathCstatus.equals("active")) ? "active" : "inactive";
206  addRel(nodeA, nodeB, pathBstatus, actual, pathBcost, 1000, 5);
207  addRel(nodeA, nodeC, pathCstatus, actual, pathCcost, 1000, 6);
208  addRel(nodeB, nodeD, pathBstatus, actual, pathBcost, 1000, 6);
209  addRel(nodeC, nodeD, pathCstatus, actual, pathCcost, 1000, 5);
210  addRel(nodeB, nodeA, pathBstatus, actual, pathBcost, 1000, 5);
211  addRel(nodeC, nodeA, pathCstatus, actual, pathCcost, 1000, 6);
212  addRel(nodeD, nodeB, pathBstatus, actual, pathBcost, 1000, 6);
213  addRel(nodeD, nodeC, pathCstatus, actual, pathCcost, 1000, 5);
214  tx.success();
215  }
216  }
217 
218  private void connectDiamonds(SwitchId switchA, SwitchId switchB, String status, int cost, int port) {
219  try (Transaction tx = graphDb.beginTx()) {
220  // A - B - D
221  // + C +
222  Node nodeA = graphDb.findNode(Label.label("switch"), "name", switchA);
223  Node nodeB = graphDb.findNode(Label.label("switch"), "name", switchB);
224  addRel(nodeA, nodeB, status, status, cost, 1000, port);
225  addRel(nodeB, nodeA, status, status, cost, 1000, port);
226  tx.success();
227  }
228  }
229 
230  private void createTriangleTopo(String pathABstatus, int pathABcost, int pathCcost) {
231  createTriangleTopo(pathABstatus, pathABcost, pathCcost, "00:", 1);
232  }
233 
234  private void createTriangleTopo(String pathABstatus, int pathABcost, int pathCcost,
235  String switchStart, int startIndex) {
236  try (Transaction tx = graphDb.beginTx()) {
237  // A - B
238  // + C +
239  int index = startIndex;
240 
241  Node nodeA = createNode(switchStart + String.format("%02X", index++));
242  Node nodeB = createNode(switchStart + String.format("%02X", index++));
243  Node nodeC = createNode(switchStart + String.format("%02X", index++));
244 
245  addRel(nodeA, nodeB, pathABstatus, pathABstatus, pathABcost, 1000, 5);
246  addRel(nodeB, nodeA, pathABstatus, pathABstatus, pathABcost, 1000, 5);
247  addRel(nodeA, nodeC, "active", "active", pathCcost, 1000, 6);
248  addRel(nodeC, nodeA, "active", "active", pathCcost, 1000, 6);
249  addRel(nodeC, nodeB, "active", "active", pathCcost, 1000, 7);
250  addRel(nodeB, nodeC, "active", "active", pathCcost, 1000, 7);
251  tx.success();
252  }
253  }
254 
255  @Test
257  /*
258  * simple happy path test .. everything has cost
259  */
260  createDiamond("active", "active", 10, 20);
261  Flow f = new Flow();
262  f.setSourceSwitch(new SwitchId("00:01"));
263  f.setDestinationSwitch(new SwitchId("00:04"));
264  f.setBandwidth(100);
266  //System.out.println("path = " + path);
267  Assert.assertNotNull(path);
268  Assert.assertEquals(4, path.left.getPath().size());
269  Assert.assertEquals(new SwitchId("00:02"), path.left.getPath().get(1).getSwitchId()); // chooses path B
270  }
271 
272 
273  @Test
275  /*
276  * simple happy path test .. everything has cost
277  */
278  createDiamondAsString("active", "active", "10", "20", "FF:", 1);
279  Flow f = new Flow();
280  f.setSourceSwitch(new SwitchId("FF:01"));
281  f.setDestinationSwitch(new SwitchId("FF:04"));
282  f.setBandwidth(100);
284  //System.out.println("path = " + path);
285  Assert.assertNotNull(path);
286  Assert.assertEquals(4, path.left.getPath().size());
287  Assert.assertEquals(new SwitchId("FF:02"), path.left.getPath().get(1).getSwitchId()); // chooses path B
288  }
289 
290 
291  @Test
293  /*
294  * verifies that iSL in both directions needs to be active
295  */
296  createDiamond("inactive", "active", 10, 20, "01:", 1);
297  Flow f = new Flow();
298  f.setSourceSwitch(new SwitchId("01:01"));
299  f.setDestinationSwitch(new SwitchId("01:04"));
300  f.setBandwidth(100);
301 
303 
304  Assert.assertNotNull(path);
305  Assert.assertEquals(4, path.left.getPath().size());
306  // ====> only difference is it should now have C as first hop .. since B is inactive
307  Assert.assertEquals(new SwitchId("01:03"), path.left.getPath().get(1).getSwitchId()); // chooses path B
308  }
309 
310  @Test
312  /*
313  * simple happy path test .. but lowest path is inactive
314  */
315  createTriangleTopo("inactive", 5, 20, "02:", 1);
316  Flow f = new Flow();
317  f.setSourceSwitch(new SwitchId("02:01"));
318  f.setDestinationSwitch(new SwitchId("02:02"));
319  f.setBandwidth(100);
320 
321  AvailableNetwork network = nd.getAvailableNetwork(false, 100);
323  System.out.println("path = " + path);
324  Assert.assertNotNull(path);
325  Assert.assertEquals(4, path.left.getPath().size());
326  // ====> only difference is it should now have C as first hop .. since B is inactive
327  Assert.assertEquals(new SwitchId("02:03"), path.left.getPath().get(1).getSwitchId()); // chooses path B
328  }
329 
330  @Test
332  /*
333  * simple happy path test .. but pathB has no cost .. but still cheaper than pathC (test the default)
334  */
335  createDiamond("active", "active", -1, 2000, "03:", 1);
336  Flow f = new Flow();
337  f.setSourceSwitch(new SwitchId("03:01"));
338  f.setDestinationSwitch(new SwitchId("03:04"));
339  f.setBandwidth(100);
340 
341  AvailableNetwork network = nd.getAvailableNetwork(false, 100);
343  // System.out.println("path = " + path);
344  Assert.assertNotNull(path);
345  Assert.assertEquals(4, path.left.getPath().size());
346  // ====> Should choose B .. because default cost (700) cheaper than 2000
347  Assert.assertEquals(new SwitchId("03:02"), path.left.getPath().get(1).getSwitchId()); // chooses path B
348  }
349 
350 
351  @Test(expected = UnroutablePathException.class)
353  /*
354  * simple happy path test .. but pathB has no cost .. but still cheaper than pathC (test the default)
355  */
356  createDiamond("inactive", "inactive", 10, 30, "04:", 1);
357  Flow f = new Flow();
358  f.setSourceSwitch(new SwitchId("04:01"));
359  f.setDestinationSwitch(new SwitchId("04:04"));
360  f.setBandwidth(100);
362  }
363 
364 
368  @Test
369  public void getPathTest_InitState() {
370  createDiamond("active", "active", 10, 20, "05:", 1);
371  boolean ignoreBw = false;
372 
373  long time = System.currentTimeMillis();
374  System.out.println("start = " + time);
375  AvailableNetwork network = nd.getAvailableNetwork(ignoreBw, 0);
376  System.out.println("\nNETWORK = " + network);
377 
378  System.out.println("AvailableNetwork = " + (System.currentTimeMillis() - time));
379  System.out.println("network.getCounts() = " + network.getCounts());
380 
381  time = System.currentTimeMillis();
382  network.removeSelfLoops().reduceByCost();
383  System.out.println("network.getCounts() = " + network.getCounts());
384  System.out.println("After Counts = " + (System.currentTimeMillis() - time));
385 
386  time = System.currentTimeMillis();
387  network = nd.getAvailableNetwork(ignoreBw, 0);
388  System.out.println("2nd AvailableNetwork = " + (System.currentTimeMillis() - time));
389  SimpleSwitch[] switches = new SimpleSwitch[network.getSwitches().values().size()];
390  Arrays.sort(network.getSwitches().values().toArray(switches));
391  Assert.assertEquals(4, switches.length);
392  Assert.assertEquals(new SwitchId("05:01"), switches[0].dpid);
393  Assert.assertEquals(new SwitchId("05:04"), switches[3].dpid);
394  Assert.assertEquals(2, switches[0].outbound.size());
395  Assert.assertEquals(1, switches[0].outbound.get(new SwitchId("05:02")).size());
396  Assert.assertEquals(10, switches[0].outbound.get(new SwitchId("05:02")).iterator().next().getCost());
397  Assert.assertEquals(1, switches[0].outbound.get(new SwitchId("05:03")).size());
398  Assert.assertEquals(20, switches[0].outbound.get(new SwitchId("05:03")).iterator().next().getCost());
399 
400  time = System.currentTimeMillis();
401  SimpleGetShortestPath sgsp = new SimpleGetShortestPath(network, new SwitchId("05:01"),
402  new SwitchId("05:03"), 35);
403  LinkedList<SimpleIsl> result = sgsp.getPath();
404  System.out.println("TIME: SimpleGetShortestPath.getPath -> " + (System.currentTimeMillis() - time));
405  System.out.println("result = " + result);
406 
407  time = System.currentTimeMillis();
408  sgsp = new SimpleGetShortestPath(network, new SwitchId("05:01"), new SwitchId("05:04"), 35);
409  result = sgsp.getPath();
410  System.out.println("TIME: SimpleGetShortestPath.getPath -> " + (System.currentTimeMillis() - time));
411  System.out.println("result = " + result);
412  }
413 
418  @Test
419  public void getPathTest_Islands() {
420  createDiamond("active", "active", 10, 20, "06:", 1);
421  createDiamond("active", "active", 10, 20, "07:", 1);
422  boolean ignoreBw = false;
423 
424  AvailableNetwork network = nd.getAvailableNetwork(ignoreBw, 0);
425  network.removeSelfLoops().reduceByCost();
426 
427  // THIS ONE SHOULD WORK
428  long time = System.currentTimeMillis();
429  SimpleGetShortestPath sgsp = new SimpleGetShortestPath(network, new SwitchId("06:01"),
430  new SwitchId("06:03"), 35);
431  LinkedList<SimpleIsl> result = sgsp.getPath();
432  System.out.println("TIME: SimpleGetShortestPath.getPath -> " + (System.currentTimeMillis() - time));
433  System.out.println("result = " + result);
434 
435  // THIS ONE SHOULD FAIL
436  time = System.currentTimeMillis();
437  sgsp = new SimpleGetShortestPath(network, new SwitchId("06:01"), new SwitchId("07:04"), 35);
438  result = sgsp.getPath();
439  System.out.println("TIME: SimpleGetShortestPath.getPath -> " + (System.currentTimeMillis() - time));
440  System.out.println("result = " + result);
441  }
442 
447  @Ignore
448  @Test
449  public void getPathTest_Large() {
450  createDiamond("active", "active", 10, 20, "08:", 1);
451 
452  for (int i = 0; i < 50; i++) {
453  createDiamond("active", "active", 10, 20, "10:", 4 * i + 1);
454  createDiamond("active", "active", 10, 20, "11:", 4 * i + 1);
455  createDiamond("active", "active", 10, 20, "12:", 4 * i + 1);
456  createDiamond("active", "active", 10, 20, "13:", 4 * i + 1);
457  }
458  for (int i = 0; i < 49; i++) {
459  String prev = String.format("%02X", 4 * i + 4);
460  String next = String.format("%02X", 4 * i + 5);
461  connectDiamonds(new SwitchId("10:" + prev), new SwitchId("10:" + next), "active", 20, 50);
462  connectDiamonds(new SwitchId("11:" + prev), new SwitchId("11:" + next), "active", 20, 50);
463  connectDiamonds(new SwitchId("12:" + prev), new SwitchId("12:" + next), "active", 20, 50);
464  connectDiamonds(new SwitchId("13:" + prev), new SwitchId("13:" + next), "active", 20, 50);
465  }
466  connectDiamonds(new SwitchId("10:99"), new SwitchId("11:22"), "active", 20, 50);
467  connectDiamonds(new SwitchId("11:99"), new SwitchId("12:22"), "active", 20, 50);
468  connectDiamonds(new SwitchId("12:99"), new SwitchId("13:22"), "active", 20, 50);
469  connectDiamonds(new SwitchId("13:99"), new SwitchId("10:22"), "active", 20, 50);
470 
471  boolean ignoreBw = false;
472 
473  AvailableNetwork network = nd.getAvailableNetwork(ignoreBw, 0);
474  network.removeSelfLoops().reduceByCost();
475  System.out.println("network.getCounts() = " + network.getCounts());
476 
477  // THIS ONE SHOULD WORK
478  long time = System.currentTimeMillis();
479  SimpleGetShortestPath sgsp = new SimpleGetShortestPath(network, new SwitchId("10:01"),
480  new SwitchId("11:03"), 200);
481  LinkedList<SimpleIsl> result = sgsp.getPath();
482  System.out.println("TIME: SimpleGetShortestPath.getPath -> " + (System.currentTimeMillis() - time));
483  System.out.println("Path Length = " + result.size());
484 
485  // THIS ONE SHOULD FAIL
486  time = System.currentTimeMillis();
487  sgsp = new SimpleGetShortestPath(network, new SwitchId("08:01"), new SwitchId("11:04"), 100);
488  result = sgsp.getPath();
489  System.out.println("TIME: SimpleGetShortestPath.getPath -> " + (System.currentTimeMillis() - time));
490  System.out.println("Path Length = " + result.size());
491  }
492 
493 
498  @Test
500  createDiamond("active", "active", 10, 20, "09:", 1);
501  Flow flow = new Flow();
502  SwitchId start = new SwitchId("09:01");
503  SwitchId end = new SwitchId("09:04");
504  flow.setSourceSwitch(start); // getPath will find an isl port
505  flow.setDestinationSwitch(end);
506  flow.setIgnoreBandwidth(false);
507  flow.setBandwidth(10);
509  // ensure start/end switches match
510  List<PathNode> left = result.left.getPath();
511  Assert.assertEquals(start, left.get(0).getSwitchId());
512  Assert.assertEquals(end, left.get(left.size() - 1).getSwitchId());
513  List<PathNode> right = result.right.getPath();
514  Assert.assertEquals(end, right.get(0).getSwitchId());
515  Assert.assertEquals(start, right.get(right.size() - 1).getSwitchId());
516  }
517 
521  @Test
522  public void shouldAlwaysFindPathForExistedFlow() throws Exception {
523  int flowBandwidth = 1000;
524 
525  Flow flow = new Flow();
526  flow.setBandwidth(flowBandwidth);
527  flow.setSourceSwitch(new SwitchId("A1:01")); // getPath will find an isl port
528  flow.setDestinationSwitch(new SwitchId("A1:03"));
529  flow.setIgnoreBandwidth(false);
530  flow.setFlowId("flow-A1:01-A1:03");
531 
532  long availableBandwidth = 0L;
533  createLinearTopoWithFlowSegments(10, "A1:", 1, availableBandwidth, flow.getFlowId(), flow.getBandwidth());
534  AvailableNetwork network = nd.getAvailableNetwork(flow.isIgnoreBandwidth(), flow.getBandwidth());
535  network.addIslsOccupiedByFlow(flow.getFlowId(), flow.isIgnoreBandwidth(), flow.getBandwidth());
537 
538  Assert.assertEquals(4, result.getLeft().getPath().size());
539  Assert.assertEquals(4, result.getRight().getPath().size());
540  }
541 
545  @Test(expected = UnroutablePathException.class)
547  long originFlowBandwidth = 1000L;
548 
549  Flow flow = new Flow();
550  flow.setBandwidth(originFlowBandwidth);
551  flow.setSourceSwitch(new SwitchId("A1:01"));
552  flow.setDestinationSwitch(new SwitchId("A1:03"));
553  flow.setIgnoreBandwidth(false);
554  flow.setFlowId("flow-A1:01-A1:03");
555 
556  // create network, all links have available bandwidth 0
557  long availableBandwidth = 0L;
558  createLinearTopoWithFlowSegments(10, "A1:", 1, availableBandwidth, flow.getFlowId(), flow.getBandwidth());
559 
560  long updatedFlowBandwidth = originFlowBandwidth + 1;
561  AvailableNetwork network = nd.getAvailableNetwork(flow.isIgnoreBandwidth(), updatedFlowBandwidth);
562 
563  network.addIslsOccupiedByFlow(flow.getFlowId(), flow.isIgnoreBandwidth(), updatedFlowBandwidth);
564  nd.getPath(flow, network, Strategy.COST);
565  }
566 
567  private void createLinearTopoWithFlowSegments(int cost, String switchStart, int startIndex, long linkBw,
568  String flowId, long flowBandwidth) {
569  try (Transaction tx = graphDb.beginTx()) {
570  int index = startIndex;
571  // A - B - C
572  Node nodeA = createNode(switchStart + String.format("%02X", index++));
573  Node nodeB = createNode(switchStart + String.format("%02X", index++));
574  Node nodeC = createNode(switchStart + String.format("%02X", index));
575  addRel(nodeA, nodeB, "active", "active", cost, linkBw, 5);
576  addRel(nodeB, nodeC, "active", "active", cost, linkBw, 6);
577  addRel(nodeC, nodeB, "active", "active", cost, linkBw, 6);
578  addRel(nodeB, nodeA, "active", "active", cost, linkBw, 5);
579 
580  addFlowSegment(flowId, flowBandwidth, nodeA, nodeB, 5, 5);
581  addFlowSegment(flowId, flowBandwidth, nodeB, nodeA, 5, 5);
582  addFlowSegment(flowId, flowBandwidth, nodeB, nodeC, 6, 6);
583  addFlowSegment(flowId, flowBandwidth, nodeC, nodeB, 6, 6);
584  tx.success();
585  }
586  }
587 
588  private void addFlowSegment(String flowId, long flowBandwidth, Node src, Node dst, int srcPort, int dstPort) {
589  Relationship rel;
590  rel = src.createRelationshipTo(dst, RelationshipType.withName("flow_segment"));
591  rel.setProperty("src_switch", src.getProperty("name"));
592  rel.setProperty("dst_switch", dst.getProperty("name"));
593  rel.setProperty("src_port", srcPort);
594  rel.setProperty("dst_port", dstPort);
595  rel.setProperty("flowid", flowId);
596  rel.setProperty("bandwidth", flowBandwidth);
597  }
598 
599 }
void setIgnoreBandwidth(Boolean ignoreBandwidth)
Definition: Flow.java:267
Map< SwitchId, SimpleSwitch > getSwitches()
ImmutablePair< PathInfoData, PathInfoData > getPath(Flow flow, Strategy strategy)
Definition: NeoDriver.java:66
name
Definition: setup.py:24
def status()
Definition: rest.py:593
list result
Definition: plan-d.py:72
AvailableNetwork getAvailableNetwork(boolean ignoreBandwidth, long requestedBandwidth)
Definition: NeoDriver.java:319
def index()
Definition: login.py:30
void addIslsOccupiedByFlow(String flowId, boolean ignoreBandwidth, long flowBandwidth)