use of nl.uva.cs.lobcder.rest.wrappers.AttachmentPoint in project lobcder by skoulouzis.
the class SDNSweep method getNetworkEntitiesForSwDPI.
private Collection<NetworkEntity> getNetworkEntitiesForSwDPI(String dpid) throws IOException, ParserConfigurationException, SAXException {
Iterator<NetworkEntity> iter = getAllNetworkEntites().iterator();
Collection<NetworkEntity> nes = new ArrayList<>();
while (iter.hasNext()) {
NetworkEntity ne = iter.next();
for (AttachmentPoint ap : ne.getAttachmentPoint()) {
if (ap.getSwitchDPID().equals(dpid)) {
nes.add(ne);
}
}
}
return nes;
}
use of nl.uva.cs.lobcder.rest.wrappers.AttachmentPoint in project lobcder by skoulouzis.
the class SDNSweep method getAllNetworkEntites.
private Collection<NetworkEntity> getAllNetworkEntites() throws IOException, ParserConfigurationException, SAXException {
if (getNetworkEntitesCache() == null) {
networkEntitesCache = new HashMap<>();
}
if (getNetworkEntitesCache().isEmpty() || getIterations() % 5 == 0) {
WebResource webResource = getClient().resource(getUri() + ":" + getFloodlightPort());
WebResource res = null;
// http://145.100.133.131:8080/wm/device/?getIpv4=192.168.100.1
res = webResource.path("wm").path("device/");
List<NetworkEntity> neList = res.get(new GenericType<List<NetworkEntity>>() {
});
String ipKey = null;
for (NetworkEntity ne : neList) {
if (!ne.getIpv4().isEmpty()) {
ipKey = ne.getIpv4().get(0);
for (String ip : ne.getIpv4()) {
if (!ip.startsWith("0")) {
ipKey = ip;
break;
}
}
}
String swIPFromFlukes = null;
if (!ne.getIpv4().isEmpty() && !networkEntitesCache.containsKey(ipKey)) {
if (getFlukesTopology() == null) {
initFlukesTopology();
}
if (getFlukesTopology() != null) {
swIPFromFlukes = findAttachedSwitch(ipKey);
// switches.get(swIPFromFlukes).dpid;
String swDPI = null;
Switch sw = getSwitches().get(swIPFromFlukes);
if (sw != null) {
swDPI = sw.dpid;
}
List<AttachmentPoint> ap = new ArrayList<>();
for (AttachmentPoint p : ne.getAttachmentPoint()) {
if (swDPI != null && p.getSwitchDPID().equals(swDPI)) {
ap.add(p);
break;
}
}
ne.setAttachmentPoint(ap);
}
getNetworkEntitesCache().put(ipKey, ne);
}
}
}
// }
return getNetworkEntitesCache().values();
}
use of nl.uva.cs.lobcder.rest.wrappers.AttachmentPoint in project lobcder by skoulouzis.
the class SDNSweep method pushARPFlow.
private void pushARPFlow() throws InterruptedException, IOException, ParserConfigurationException, SAXException {
Iterator<Switch> swIter = getAllSwitches().iterator();
List<String> arpFlows = new ArrayList<>();
while (swIter.hasNext()) {
Switch sw = swIter.next();
String flow = "{\"switch\":\"" + sw.dpid + "\", " + "\"name\":\"arp" + sw.dpid + "\", " + "\"ether-type\":\"0x0806\", " + "\"actions\":\"output=flood\"}";
arpFlows.add(flow);
Collection<NetworkEntity> nes = getNetworkEntitiesForSwDPI(sw.dpid);
Iterator<NetworkEntity> neIter = nes.iterator();
while (neIter.hasNext()) {
NetworkEntity ne = neIter.next();
for (String mac : ne.getMac()) {
for (AttachmentPoint ap : ne.getAttachmentPoint()) {
flow = "{\"switch\": \"" + sw.dpid + "\", " + "\"name\":\"flow-to-" + mac + "\", " + "\"cookie\":\"0\", " + "\"priority\":\"32768\", " + "\"dst-mac\":\"" + mac + "\"," + "\"active\":\"true\", " + "\"actions\":" + "\"output=" + ap.getPort() + "\"}";
arpFlows.add(flow);
}
}
}
}
List<Link> links = getAllSwitchLinks();
StringBuilder sb = new StringBuilder();
for (Link l : links) {
Collection<NetworkEntity> nes = getNetworkEntitiesForSwDPI(l.dstSwitch);
for (NetworkEntity neDst : nes) {
for (String mac : neDst.getMac()) {
sb.append("{\"switch\": \"").append(l.srcSwitch).append("\"," + "\"name\":\"").append(l.srcSwitch).append("-to-").append(mac).append("\", " + "\"cookie\":\"0\", " + "\"priority\":\"32768\", " + "\"dst-mac\":\"").append(mac).append("\"," + "\"active\":\"true\"," + "\"actions\":\"output=").append(l.srcPort).append("\"}\"");
arpFlows.add(sb.toString());
// Logger.getLogger(SDNSweep.class.getName()).log(Level.INFO, sb.toString());
sb.setLength(0);
}
}
nes = getNetworkEntitiesForSwDPI(l.srcSwitch);
for (NetworkEntity neDst : nes) {
for (String mac : neDst.getMac()) {
sb.append("{\"switch\": \"").append(l.dstSwitch).append("\"," + "\"name\":\"").append(l.dstSwitch).append("-to-").append(mac).append("\", " + "\"cookie\":\"0\", " + "\"priority\":\"32768\", " + "\"dst-mac\":\"").append(mac).append("\"," + "\"active\":\"true\"," + "\"actions\":\"output=").append(l.dstPort).append("\"}\"");
arpFlows.add(sb.toString());
// Logger.getLogger(SDNSweep.class.getName()).log(Level.INFO, sb.toString());
sb.setLength(0);
}
}
}
pushFlows(arpFlows);
}
use of nl.uva.cs.lobcder.rest.wrappers.AttachmentPoint in project lobcder by skoulouzis.
the class SDNSweep method fillInLinkGaps.
private ArrayList<Link> fillInLinkGaps(List<Link> switchLinks) throws IOException, ParserConfigurationException, SAXException {
ArrayList<Link> possibleLinks = new ArrayList<>();
for (Switch srcSW : getAllSwitches()) {
String srcSWIP = srcSW.inetAddress.replaceAll("/", "").substring(0, srcSW.inetAddress.indexOf(":") - 1);
int srcPort = 0;
for (NetworkEntity ne : getNetworkEntitiesForSwDPI(srcSW.dpid)) {
for (AttachmentPoint ap : ne.getAttachmentPoint()) {
for (Port p : srcSW.ports) {
for (Link existingLink : switchLinks) {
if (ap.getPort() != (Number) p.portNumber && p.portNumber != existingLink.srcPort && ap.getPort().intValue() <= 500 && p.portNumber <= 500) {
srcPort = p.portNumber;
break;
}
}
}
}
}
int dstPort;
Link l = null;
for (String dstSWIP : findConnectedSwitches(srcSWIP)) {
Switch dstSW = getSwitches().get(dstSWIP);
for (NetworkEntity ne : getNetworkEntitiesForSwDPI(dstSW.dpid)) {
for (AttachmentPoint ap : ne.getAttachmentPoint()) {
for (Port p : dstSW.ports) {
for (Link existingLink : switchLinks) {
if (ap.getPort() != (Number) p.portNumber && existingLink.dstPort != p.portNumber && ap.getPort().intValue() <= 500 && p.portNumber <= 500 && srcPort <= 500) {
dstPort = p.portNumber;
l = new Link();
l.srcSwitch = srcSW.dpid;
l.srcPort = srcPort;
l.dstSwitch = dstSW.dpid;
l.dstPort = dstPort;
possibleLinks.add(l);
break;
}
}
}
}
}
}
}
for (Link possible : possibleLinks) {
String possibleSRC = possible.srcSwitch + "-" + possible.srcPort;
String possibleDST = possible.dstSwitch + "-" + possible.dstPort;
for (Link existing : switchLinks) {
String existingSRC = existing.srcSwitch + "-" + existing.srcPort;
String existingDST = existing.dstSwitch + "-" + existing.dstPort;
if (!possibleSRC.equals(existingSRC) && !possibleDST.equals(existingDST) && !possibleSRC.equals(existingDST) && !possibleDST.equals(existingSRC)) {
Logger.getLogger(SDNSweep.class.getName()).log(Level.INFO, "{0}-{1} -> {2}-{3}", new Object[] { possible.srcSwitch, possible.srcPort, possible.dstSwitch, possible.dstPort });
}
}
}
ArrayList<Link> addedLinks = new ArrayList<>();
// }
return addedLinks;
}
use of nl.uva.cs.lobcder.rest.wrappers.AttachmentPoint in project lobcder by skoulouzis.
the class SDNControllerClient method getShortestPath.
public List<DefaultWeightedEdge> getShortestPath(String dest, Set<String> sources) throws InterruptedException, IOException {
if (graph == null) {
graph = new SimpleWeightedGraph<>(DefaultWeightedEdge.class);
}
Collection<SDNSweep.Switch> switchesColl = SDNSweep.getSwitches().values();
List<SDNSweep.Switch> switches;
if (switchesColl instanceof List) {
switches = (List) switchesColl;
} else {
switches = new ArrayList(switchesColl);
}
for (int i = 0; i < switches.size(); i++) {
List<Port> ports = switches.get(i).ports;
if (ports != null) {
for (int j = 0; j < ports.size(); j++) {
for (int k = 0; k < ports.size(); k++) {
if (ports.get(j).state == 0 && ports.get(k).state == 0 && j != k) {
String vertex1 = switches.get(i).dpid + "-" + ports.get(j).portNumber;
String vertex2 = switches.get(i).dpid + "-" + ports.get(k).portNumber;
// Logger.getLogger(SDNControllerClient.class.getName()).log(Level.INFO, "From: {0} to: {1}", new Object[]{vertex1, vertex2});
if (!graph.containsVertex(vertex1)) {
graph.addVertex(vertex1);
}
if (!graph.containsVertex(vertex2)) {
graph.addVertex(vertex2);
}
DefaultWeightedEdge e1;
if (!graph.containsEdge(vertex1, vertex2)) {
e1 = graph.addEdge(vertex1, vertex2);
} else {
e1 = graph.getEdge(vertex1, vertex2);
}
graph.setEdgeWeight(e1, 1);
}
}
}
}
}
// Logger.getLogger(SDNControllerClient.class.getName()).log(Level.INFO, "Destination: {0}", new Object[]{dest});
if (!graph.containsVertex(dest)) {
graph.addVertex(dest);
}
NetworkEntity destinationEntityArray = SDNSweep.getNetworkEntity(dest);
// for (SDNSweep.NetworkEntity ne : destinationEntityArray) {
if (destinationEntityArray != null) {
for (AttachmentPoint ap : destinationEntityArray.getAttachmentPoint()) {
String vertex = ap.getSwitchDPID() + "-" + ap.getPort();
// Logger.getLogger(SDNControllerClient.class.getName()).log(Level.INFO, "vertex: {0}", new Object[]{vertex});
if (!graph.containsVertex(vertex)) {
graph.addVertex(vertex);
}
DefaultWeightedEdge e1;
if (!graph.containsEdge(dest, vertex)) {
e1 = graph.addEdge(dest, vertex);
} else {
e1 = graph.getEdge(dest, vertex);
}
// Don't calculate the cost from the destination to the switch.
// There is nothing we can do about it so why waste cycles ?
// graph.setEdgeWeight(e1, 2);
graph.setEdgeWeight(e1, getCost(dest, vertex));
}
}
// List<NetworkEntity> sourceEntityArray = getNetworkEntity(sources);
for (String s : sources) {
NetworkEntity ne = SDNSweep.getNetworkEntity(s);
if (ne != null) {
for (String ip : ne.getIpv4()) {
if (!graph.containsVertex(ip)) {
graph.addVertex(ip);
}
for (AttachmentPoint ap : ne.getAttachmentPoint()) {
String vertex = ap.getSwitchDPID() + "-" + ap.getPort();
if (!graph.containsVertex(vertex)) {
graph.addVertex(vertex);
}
DefaultWeightedEdge e2;
if (!graph.containsEdge(ip, vertex)) {
e2 = graph.addEdge(ip, vertex);
} else {
e2 = graph.getEdge(ip, vertex);
}
graph.setEdgeWeight(e2, getCost(ip, vertex));
}
}
}
}
List<Link> links = SDNSweep.getSwitchLinks();
for (Link l : links) {
String srcVertex = l.srcSwitch + "-" + l.srcPort;
if (!graph.containsVertex(srcVertex)) {
graph.addVertex(srcVertex);
}
String dstVertex = l.dstSwitch + "-" + l.dstPort;
if (!graph.containsVertex(dstVertex)) {
graph.addVertex(dstVertex);
}
DefaultWeightedEdge e3;
if (!graph.containsEdge(srcVertex, dstVertex)) {
e3 = graph.addEdge(srcVertex, dstVertex);
} else {
e3 = graph.getEdge(srcVertex, dstVertex);
}
// Logger.getLogger(SDNControllerClient.class.getName()).log(Level.INFO, "dstVertex: {0}", new Object[]{dstVertex});
graph.setEdgeWeight(e3, getCost(srcVertex, dstVertex));
}
double cost = Double.MAX_VALUE;
List<DefaultWeightedEdge> shortestPath = null;
// exportGraph();
StringBuilder msg = new StringBuilder();
msg.append("\n");
for (String s : sources) {
if (graph.containsVertex(dest) && graph.containsVertex(s)) {
List<DefaultWeightedEdge> shorPath = null;
shorPath = DijkstraShortestPath.findPathBetween(graph, s, dest);
double w = 0;
if (shorPath != null) {
for (DefaultWeightedEdge e : shorPath) {
w += graph.getEdgeWeight(e);
}
DefaultWeightedEdge p = shorPath.get(0);
String e = graph.getEdgeSource(p);
msg.append("source: ").append(e).append(" cost: ").append(w).append("\n");
if (w <= cost) {
cost = w;
shortestPath = shorPath;
if (cost <= sources.size() + 1) {
break;
}
}
}
}
}
Logger.getLogger(SDNControllerClient.class.getName()).log(Level.INFO, msg.toString());
return shortestPath;
}
Aggregations