use of nl.uva.cs.lobcder.rest.wrappers.NetworkEntity in project lobcder by skoulouzis.
the class SDNSweep method pushFlowIntoOnePort.
private void pushFlowIntoOnePort() throws IOException, ParserConfigurationException, SAXException {
// get(0).dpid;
String s1 = getAllSwitches().iterator().next().dpid;
// get(1).dpid;
String s2 = getAllSwitches().iterator().next().dpid;
Number s1ToS2Port = 0;
Number s2ToS1Port = 0;
for (Link l : getAllSwitchLinks()) {
if (l.srcSwitch.equals(s1)) {
s1ToS2Port = l.srcPort;
s2ToS1Port = l.dstPort;
break;
} else if (l.srcSwitch.equals(s2)) {
s1ToS2Port = l.dstPort;
s2ToS1Port = l.srcPort;
break;
}
}
List<String> s1Hosts = new ArrayList<>();
List<String> s2Hosts = new ArrayList<>();
for (NetworkEntity ne : getAllNetworkEntites()) {
if (ne.getAttachmentPoint().get(0).getSwitchDPID().equals(s1)) {
s1Hosts.add(ne.getIpv4().get(0));
} else if (ne.getAttachmentPoint().get(0).getSwitchDPID().equals(s2)) {
s2Hosts.add(ne.getIpv4().get(0));
}
}
List<String> rules = new ArrayList<>();
// s1 to s2
for (String h1 : s1Hosts) {
for (String h2 : s2Hosts) {
String rule1To2 = "{\"switch\": \"" + s1 + "\", \"name\":\"" + h1 + "To" + h2 + "\", \"cookie\":\"0\", \"priority\":\"10\", " + "\"src-mac\":\"" + getNetworkEntitesCache().get(h1).getMac().get(0) + "\", \"ingress-port\":\"" + getNetworkEntitesCache().get(h1).getAttachmentPoint().get(0).getPort() + "\", " + "\"dst-mac\": \"" + getNetworkEntitesCache().get(h2).getMac().get(0) + "\", \"active\":\"true\"," + "\"actions\":\"output=" + s1ToS2Port + "\"}";
rules.add(rule1To2);
// Logger.getLogger(SDNSweep.class.getName()).log(Level.INFO, rule1To2);
}
}
// s2 to s1
for (String h1 : s2Hosts) {
for (String h2 : s1Hosts) {
String rule2To1 = "{\"switch\": \"" + s2 + "\", \"name\":\"" + h1 + "To" + h2 + "\", \"cookie\":\"0\", \"priority\":\"10\", " + "\"src-mac\":\"" + getNetworkEntitesCache().get(h1).getMac().get(0) + "\", \"ingress-port\":\"" + getNetworkEntitesCache().get(h1).getAttachmentPoint().get(0).getPort() + "\", " + "\"dst-mac\": \"" + getNetworkEntitesCache().get(h2).getMac().get(0) + "\", \"active\":\"true\"," + "\"actions\":\"output=" + s2ToS1Port + "\"}";
rules.add(rule2To1);
// Logger.getLogger(SDNSweep.class.getName()).log(Level.INFO, rule2To1);
}
}
pushFlows(rules);
flowPushed = true;
}
Aggregations