Thomas Vachuska
Committed by Gerrit Code Review

Fixing a defect in simulated topology to make sure to use unique ports.

Change-Id: I6ae266e9347470722e4df31aed18e3141e3e84a4
......@@ -42,8 +42,10 @@ public class LinearTopologySimulator extends TopologySimulator {
@Override
protected void createLinks() {
int portOffset = 1;
for (int i = 0, n = deviceCount - 1; i < n; i++) {
createLink(i, i + 1);
createLink(i, i + 1, portOffset, 1);
portOffset = 2;
}
}
......
......@@ -25,7 +25,7 @@ public class RerouteTopologySimulator extends LinearTopologySimulator {
@Override
protected void processTopoShape(String shape) {
super.processTopoShape(shape);
infrastructurePorts = 3;
infrastructurePorts = 5;
deviceCount = (topoShape.length == 1) ? deviceCount : Integer.parseInt(topoShape[1]);
}
......@@ -37,13 +37,15 @@ public class RerouteTopologySimulator extends LinearTopologySimulator {
@Override
protected void createLinks() {
int portOffset = 1;
for (int i = 0, n = deviceCount - 2; i < n; i++) {
createLink(i, i + 1);
createLink(i, i + 1, portOffset, 1);
portOffset = 2;
}
int middle = (deviceCount - 1) / 2;
int alternate = deviceCount - 1;
createLink(middle - 1, alternate);
createLink(middle, alternate);
createLink(middle - 1, alternate, 3, 1);
createLink(middle, alternate, 3, 2);
}
@Override
......
......@@ -187,15 +187,27 @@ public abstract class TopologySimulator {
deviceIds.add(id);
}
// /**
// * Creates simulated link between two devices on port 1 and port 2.
// *
// * @param i index of one simulated device
// * @param j index of another simulated device
// */
// protected void createLink(int i, int j) {
// createLink(i, j, 1, 2);
// }
/**
* Creates simulated link between two devices.
*
* @param i index of one simulated device
* @param j index of another simulated device
* @param i index of one simulated device
* @param j index of another simulated device
* @param pi port number of i-th device
* @param pj port number of j-th device
*/
protected void createLink(int i, int j) {
ConnectPoint one = new ConnectPoint(deviceIds.get(i), PortNumber.portNumber(1));
ConnectPoint two = new ConnectPoint(deviceIds.get(j), PortNumber.portNumber(2));
protected void createLink(int i, int j, int pi, int pj) {
ConnectPoint one = new ConnectPoint(deviceIds.get(i), PortNumber.portNumber(pi));
ConnectPoint two = new ConnectPoint(deviceIds.get(j), PortNumber.portNumber(pj));
linkProviderService.linkDetected(new DefaultLinkDescription(one, two, DIRECT));
linkProviderService.linkDetected(new DefaultLinkDescription(two, one, DIRECT));
}
......
......@@ -55,14 +55,16 @@ public class TreeTopologySimulator extends TopologySimulator {
@Override
protected void createLinks() {
int portOffset = 1;
for (int t = 1; t < tierOffset.length; t++) {
int child = tierOffset[t];
for (int parent = tierOffset[t - 1]; parent < tierOffset[t]; parent++) {
for (int i = 0; i < tierMultiplier[t]; i++) {
createLink(parent, child);
createLink(parent, child, i + portOffset, 1);
child++;
}
}
portOffset = 2; // beyond first tier, allow for up-links
}
}
......