use of nl.uva.cs.lobcder.catalogue.SDNSweep in project lobcder by skoulouzis.
the class SDNControllerClient method pushFlow.
// private double getCost(String v1, String v2) throws InterruptedException, IOException {
// // String[] agentPort = getsFlowPort(v1, v2);
// // double tpp = getTimePerPacket(agentPort[0], Integer.valueOf(agentPort[1]));
// String dpi;
// if (v1.contains(":")) {
// dpi = v1;
// } else {
// dpi = v2;
// }
//
// // SDNSweep.FloodlightStats[] stats = getFloodlightPortStats(dpi, getPort());
// Double rpps = SDNSweep.getReceivePacketsMap().get(dpi);
// Double tpps = SDNSweep.getTransmitPacketsMap().get(dpi);
// if (rpps == null) {
// rpps = Double.valueOf(1);
// }
// if (tpps == null) {
// tpps = Double.valueOf(1);
// }
// // double rrrt = (interval / rpps);
// // double trrt = (interval / tpps);
//
// double tpp = (rpps > tpps) ? rpps : tpps;
// if (tpp <= 0) {
// tpp = 1;
// }
// Double rbytes = SDNSweep.getReceiveBytesMap().get(dpi);
// if (rbytes == null) {
// rbytes = Double.valueOf(1);
// }
// Double tbytes = SDNSweep.getTransmitBytesMap().get(dpi);
// if (tbytes == null) {
// tbytes = Double.valueOf(1);
// }
// double rbps = rbytes / SDNSweep.interval;
// double tbps = tbytes / SDNSweep.interval;
// double cost = 1.0 / ((rbps + tbps) / 2.0);
//
//
// if (rbytes <= 0) {
// rbytes = Double.valueOf(1);
// }
// if (tbytes <= 0) {
// tbytes = Double.valueOf(1);
// }
//
// double rMTU = rbytes / rpps * 1.0;
// double tMTU = tbytes / tpps * 1.0;
// double mtu = (rMTU > tMTU) ? rMTU : tMTU;
// // if (mtu <= 500) {
// // mtu = 1500;
// // }
//
// //TT=TpP * NoP
// //NoP = {MTU}/{FS}
// //TpP =[({MTU} / {bps}) + RTT] // is the time it takes to transmit one packet or time per packet
// //TT = [({MTU} / {bps}) + RTT] * [ {MTU}/{FS}]
// double nop = mtu / 1024.0;
// double mtt = tpp * nop;
//
// // SDNSweep.OFlow f = SDNSweep.getOFlowsMap().get(dpi);
// // double bps = -1;
// // if (f != null) {
// // bps = f.byteCount / f.durationSeconds * 1.0;
// // double tmp = f.packetCount / f.durationSeconds * 1.0;
// // if (tpp <= 1 && tmp > tpp) {
// // mtt = tmp * nop;
// // }
// // }
// // Double averageLinkUsage = SDNSweep.getAverageLinkUsageMap().get(dpi);
// // if (averageLinkUsage != null) {
// //
// // if (factor > -1) {
// // mtt += averageLinkUsage * factor;
// // }
// //// For each sec of usage how much extra time we get ?
// //// We asume a liner ralationship
// //// The longer the usage it means either more transfers per flow or larger files or both
// //
// //// Logger.getLogger(SDNControllerClient.class.getName()).log(Level.INFO, "dpi: " + dpi + " averageLinkUsage: " + averageLinkUsage);
// // } else {
// // mtt-=factor;
// // }
//
// // Logger.getLogger(SDNControllerClient.class.getName()).log(Level.INFO, "From: {0} to: {1} tt: {2}", new Object[]{v1, v2, mtt});
// return (mtt > 0) ? mtt : 1.2;
// }
public void pushFlow(final List<DefaultWeightedEdge> shortestPath) throws IOException {
if (shortestPath != null && !shortestPath.isEmpty()) {
Thread thread = new Thread() {
public void run() {
try {
DefaultWeightedEdge e = shortestPath.get(0);
String pair = e.toString().substring(1, e.toString().length() - 1);
String[] workerSwitch = pair.toString().split(" : ");
String srcIP = workerSwitch[0];
String srcMac = SDNSweep.getNetworkEntity(srcIP).getMac().get(0);
String srcSwitchAndPort = workerSwitch[1];
String srcSwitch = srcSwitchAndPort.split("-")[0];
String srcIngressPort = String.valueOf(SDNSweep.getNetworkEntity(srcIP).getAttachmentPoint().get(0).getPort());
String srcOutput;
e = shortestPath.get(1);
pair = e.toString().substring(1, e.toString().length() - 1);
workerSwitch = pair.split(" : ");
if (workerSwitch[0].equals(srcSwitch + "-" + srcIngressPort)) {
srcOutput = workerSwitch[1].split("-")[1];
} else {
srcOutput = workerSwitch[0].split("-")[1];
}
e = shortestPath.get(shortestPath.size() - 1);
pair = e.toString().substring(1, e.toString().length() - 1);
workerSwitch = pair.toString().split(" : ");
String dstIP = workerSwitch[0];
String dstMac = SDNSweep.getNetworkEntity(dstIP).getMac().get(0);
String dstSwitchAndPort = workerSwitch[1];
String dstSwitch = dstSwitchAndPort.split("-")[0];
String dstOutput = String.valueOf(SDNSweep.getNetworkEntity(dstIP).getAttachmentPoint().get(0).getPort());
e = shortestPath.get(shortestPath.size() - 2);
pair = e.toString().substring(1, e.toString().length() - 1);
workerSwitch = pair.toString().split(" : ");
String node1 = workerSwitch[0];
String node2 = workerSwitch[1];
String dstIngressPort = "";
if (node1.equals(dstSwitch + "-" + dstOutput)) {
dstIngressPort = node2.split("-")[1];
} else {
dstIngressPort = node1.split("-")[1];
}
// String rulesrcToSw = "{\"switch\": \"" + srcSwitch + "\", \"name\":\"tmp\", \"cookie\":\"0\", \"priority\":\"5\", "
// + "\"src-ip\":\"" + srcIP + "\", \"ingress-getPort()\":\"" + srcIngressPort + "\", "
// + "\"dst-ip\": \"" + dstIP + "\", \"active\":\"true\",\"ether-type\":\"0x0800\", "
// + "\"actions\":\"output=" + srcOutput + "\"}";
//
//
// String ruleSwTodst = "{\"switch\": \"" + dstSwitch + "\", \"name\":\"tmp\", \"cookie\":\"0\", \"priority\":\"5\", "
// + "\"src-ip\":\"" + srcIP + "\", \"ingress-getPort()\":\"" + dstIngressPort + "\", "
// + "\"dst-ip\": \"" + dstIP + "\", \"active\":\"true\",\"ether-type\":\"0x0800\", "
// + "\"actions\":\"output=" + dstOutput + "\"}";
String rule11 = "{\"switch\": \"" + srcSwitch + "\", \"name\":\"tmp1-1\", \"cookie\":\"0\", \"priority\":\"5\", " + "\"src-mac\":\"" + srcMac + "\", \"ingress-getPort()\":\"" + srcIngressPort + "\", " + "\"dst-mac\": \"" + dstMac + "\", \"active\":\"true\",\"vlan-id\":\"-1\", " + "\"actions\":\"output=" + srcOutput + "\"}";
String rule12 = "{\"switch\": \"" + srcSwitch + "\", \"name\":\"tmp1-2\", \"cookie\":\"0\", \"priority\":\"5\", " + "\"src-mac\":\"" + dstMac + "\", \"ingress-getPort()\":\"" + srcOutput + "\", " + "\"dst-mac\": \"" + srcMac + "\", \"active\":\"true\",\"vlan-id\":\"-1\", " + "\"actions\":\"output=" + srcIngressPort + "\"}";
String rule21 = "{\"switch\": \"" + dstSwitch + "\", \"name\":\"tmp2-1\", \"cookie\":\"0\", \"priority\":\"5\", " + "\"src-mac\":\"" + srcMac + "\", \"ingress-getPort()\":\"" + dstIngressPort + "\", " + "\"dst-mac\": \"" + dstMac + "\", \"active\":\"true\",\"vlan-id\":\"-1\", " + "\"actions\":\"output=" + dstOutput + "\"}";
String rule22 = "{\"switch\": \"" + dstSwitch + "\", \"name\":\"tmp2-2\", \"cookie\":\"0\", \"priority\":\"5\", " + "\"src-mac\":\"" + dstMac + "\", \"ingress-getPort()\":\"" + dstOutput + "\", " + "\"dst-mac\": \"" + srcMac + "\", \"active\":\"true\",\"vlan-id\":\"-1\", " + "\"actions\":\"output=" + dstIngressPort + "\"}";
List<String> rules = new ArrayList<>();
rules.add(rule11);
rules.add(rule12);
rules.add(rule21);
rules.add(rule22);
try {
new SDNSweep(null).pushFlows(rules);
} catch (IOException ex) {
Logger.getLogger(SDNControllerClient.class.getName()).log(Level.SEVERE, null, ex);
} catch (ParserConfigurationException ex) {
Logger.getLogger(SDNControllerClient.class.getName()).log(Level.SEVERE, null, ex);
} catch (SAXException ex) {
Logger.getLogger(SDNControllerClient.class.getName()).log(Level.SEVERE, null, ex);
}
} catch (IOException ex) {
Logger.getLogger(SDNControllerClient.class.getName()).log(Level.SEVERE, null, ex);
}
}
};
thread.start();
}
}
Aggregations