use of org.jgrapht.graph.DefaultWeightedEdge in project lobcder by skoulouzis.
the class WebDataFileResource method getLowestCostWorker.
private String getLowestCostWorker(String reqSource) throws IOException, URISyntaxException, InterruptedException {
if (sdnClient == null) {
String uri = PropertiesHelper.getSDNControllerURL();
sdnClient = new SDNControllerClient(uri);
}
List<DefaultWeightedEdge> shortestPath = sdnClient.getShortestPath(reqSource, workersMap.keySet());
Logger.getLogger(WebDataFileResource.class.getName()).log(Level.FINEST, "getShortestPath: {0}", shortestPath);
if (PropertiesHelper.pushFlow()) {
sdnClient.pushFlow(shortestPath);
}
DefaultWeightedEdge e = shortestPath.get(0);
String[] workerSwitch = e.toString().split(" : ");
String workerIP = workerSwitch[0].substring(1);
String worker = workersMap.get(workerIP);
String w = worker + "/" + getLogicalData().getUid();
String token = UUID.randomUUID().toString();
AuthLobcderComponents.setTicket(worker, token);
// w = "http://localhost:8080/lobcder-worker/"+getLogicalData().getUid();
return w + "/" + token;
}
use of org.jgrapht.graph.DefaultWeightedEdge in project lobcder by skoulouzis.
the class SDNService method setStats.
@Path("optimizeFlow")
@PUT
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public void setStats(JAXBElement<Endpoints> jbEndpoints) throws IOException, InterruptedException {
MyPrincipal mp = (MyPrincipal) request.getAttribute("myprincipal");
if (mp.getRoles().contains("worker") || mp.isAdmin()) {
Endpoints endpoints = jbEndpoints.getValue();
if (sdnClient == null) {
String uri = PropertiesHelper.getSDNControllerURL();
sdnClient = new SDNControllerClient(uri);
}
Set<String> sources = new HashSet<>();
sources.add(endpoints.source);
List<DefaultWeightedEdge> shortestPath = sdnClient.getShortestPath(endpoints.destination, sources);
sdnClient.pushFlow(shortestPath);
}
}
use of org.jgrapht.graph.DefaultWeightedEdge in project lobcder by skoulouzis.
the class SDNControllerClient method exportGraph.
// private SDNSweep.FloodlightStats[] getFloodlightPortStats(String dpi, int getPort()) throws IOException, InterruptedException {
// SDNSweep.FloodlightStats stats1 = null;
// SDNSweep.FloodlightStats stats2 = null;
// // List<FloodlightStats> stats1 = getFloodlightPortStats(dpi);
// // Thread.sleep((long) interval);
// // List<FloodlightStats> stats2 = getFloodlightPortStats(dpi);
// Map<String, SDNSweep.StatsHolder> map = SDNSweep.getStatsMap();
// if (map != null) {
// SDNSweep.StatsHolder h = map.get(dpi+"-"+getPort());
// if (h != null) {
// stats1 = h.getStats1();
// stats2 = h.getStats2();
// }
// }
// SDNSweep.FloodlightStats stat1 = null;
// for (SDNSweep.FloodlightStats s : stats1) {
// if (s.portNumber == getPort()) {
// stat1 = s;
// break;
// }
// }
//
// SDNSweep.FloodlightStats stat2 = null;
// for (SDNSweep.FloodlightStats s : stats2) {
// if (s.portNumber == getPort()) {
// stat2 = s;
// break;
// }
// }
// return new SDNSweep.FloodlightStats[]{stats1, stats2};
// }
// private String[] getsFlowPort(String v1, String v2) {
// String[] tuple = new String[2];
// if (sFlowHostPortMap == null) {
// sFlowHostPortMap = new HashMap<>();
// }
// if (v1.contains(":") && v2.contains(":")) {
// String switch1IP = getSwitchIPFromDPI(v1);
// // String switch2IP = getSwitchIPFromDPI(v2);
// if (!sFlowHostPortMap.containsKey(switch1IP)) {
// List<Flow> flows = getAgentFlows(switch1IP);
// for (Flow f : flows) {
// String[] keys = f.flowKeys.split(",");
// String from = keys[0];
// String to = keys[1];
// if (!isAttached(from, v1) && isAttached(to, v1)) {
// // Logger.getLogger(SDNControllerClient.class.getName()).log(Level.INFO, "Switch: " + switch1IP + " -> " + f.dataSource);
// sFlowHostPortMap.put(switch1IP, f.dataSource);
// break;
// }
// }
// }
// // Logger.getLogger(SDNControllerClient.class.getName()).log(Level.INFO, "Host: " + switch1IP + " getPort(): " + sFlowHostPortMap.get(switch1IP));
// tuple[0] = switch1IP;
// tuple[1] = String.valueOf(sFlowHostPortMap.get(switch1IP));
// return tuple;
// } else {
// String switchIP = null;
// String hostIP = null;
// if (v1.contains(".")) {
// switchIP = getSwitchIPFromHostIP(v1);
// hostIP = v1;
// } else {
// switchIP = getSwitchIPFromHostIP(v2);
// hostIP = v2;
// }
//
// if (!sFlowHostPortMap.containsKey(hostIP)) {
// List<Flow> flows = getAgentFlows(switchIP);
// for (Flow f : flows) {
// String[] keys = f.flowKeys.split(",");
// if (keys[0].equals(hostIP)) {
// sFlowHostPortMap.put(hostIP, f.dataSource);
// break;
// }
// }
// }
// Logger.getLogger(SDNControllerClient.class.getName()).log(Level.INFO, "Host: " + hostIP + " is attached to: " + switchIP + " getPort(): " + sFlowHostPortMap.get(hostIP));
// tuple[0] = switchIP;
// tuple[1] = String.valueOf(sFlowHostPortMap.get(hostIP));
// return tuple;
// }
// }
//
// private Map<String, Integer> getifNameOpenFlowPortNumberMap(String dpi) {
// HashMap<String, Integer> ifNamePortMap = new HashMap<>();
// List<Switch> switches = getSwitches();
// for (Switch s : switches) {
// if (s.dpid.equals(dpi)) {
// List<Port> ports = s.ports;
// for (Port p : ports) {
// ifNamePortMap.put(p.name, p.portNumber);
// }
// break;
// }
// }
// return ifNamePortMap;
// }
//
// private String getSwitchIPFromDPI(String dpi) {
// for (Switch s : getSwitches()) {
// if (s.dpid.equals(dpi)) {
// return s.inetAddress.split(":")[0].substring(1);
// }
// }
// return null;
// }
//
// private boolean isAttached(String from, String dpi) {
// for (NetworkEntity ne : getNetworkEntity(from)) {
// for (AttachmentPoint ap : ne.getAttachmentPoint()) {
// if (ap.getSwitchDPID().equals(dpi)) {
// return true;
// }
// }
// }
// return false;
// }
// private List<NetworkEntity> getNetworkEntity(String address) {
// if (networkEntityCache == null) {
// networkEntityCache = new HashMap();
// }
// if (!networkEntityCache.containsKey(address)) {
// WebResource webResource = client.resource(uri + ":" + floodlightPort);
// WebResource res = null;
// if (address.contains(".")) {
// // http://145.100.133.131:8080/wm/device/?getIpv4()=192.168.100.1
// res = webResource.path("wm").path("device/").queryParam("getIpv4()", address);
// } else {
// // http://145.100.133.131:8080/wm/device/?getMac()=fe:16:3e:00:26:b1
// res = webResource.path("wm").path("device/").queryParam("getMac()", address);
// }
// List<NetworkEntity> ne = res.get(new GenericType<List<NetworkEntity>>() {
// });
// networkEntityCache.put(address, ne);
// }
// return networkEntityCache.get(address);
// }
//
// private List<NetworkEntity> getNetworkEntity(Set<String> sources) {
// List<NetworkEntity> entities = new ArrayList<>();
// for (String e : sources) {
// entities.addAll(getNetworkEntity(e));
// }
// return entities;
// }
//
// private List<Link> getSwitchLinks() {
// if (linkCache == null) {
// linkCache = new ArrayList<>();
// }
// if (linkCache.isEmpty()) {
// WebResource webResource = client.resource(uri + ":" + floodlightPort);
// WebResource res = webResource.path("wm").path("topology").path("links").path("json");
// linkCache = res.get(new GenericType<List<Link>>() {
// });
// }
//
// return linkCache;
// }
//
// private List<Switch> getSwitches() {
// if (switches == null) {
// WebResource webResource = client.resource(uri + ":" + floodlightPort);
// WebResource res = webResource.path("wm").path("core").path("controller").path("switches").path("json");
// switches = res.get(new GenericType<List<Switch>>() {
// });
// }
// return switches;
// }
//
// private String getSwitchIPFromHostIP(String address) {
// if (networkEntitySwitchMap == null) {
// networkEntitySwitchMap = new HashMap<>();
// }
// if (!networkEntitySwitchMap.containsKey(address)) {
// List<NetworkEntity> ne = getNetworkEntity(address);
// String dpi = ne.get(0).getAttachmentPoint().get(0).getSwitchDPID();
// for (Switch switches : getSwitches()) {
// if (switches.dpid.equals(dpi)) {
// String ip = switches.inetAddress.split(":")[0].substring(1);
// networkEntitySwitchMap.put(address, ip);
// break;
// }
// }
// }
//
// return networkEntitySwitchMap.get(address);
// }
//
// private List<Flow> getAgentFlows(String switchIP) {
// List<Flow> agentFlows = new ArrayList<>();
// for (Flow f : getAllFlows()) {
// if (f.agent.equals(switchIP)) {
// agentFlows.add(f);
// }
// }
// return agentFlows;
// }
//
// private List<Flow> getAllFlows() {
// WebResource webResource = client.resource(uri + ":" + sflowRTPrt);
// WebResource res = webResource.path("flows").path("json");
// return res.get(new GenericType<List<Flow>>() {
// });
// }
//
// private List<Ifpkts> getifoutpktsMetric(String agent, int getPort()) {
// WebResource webResource = client.resource(uri + ":" + sflowRTPrt);
// WebResource res = webResource.path("metric").path(agent).path(getPort() + ".ifoutpkts").path("json");
// return res.get(new GenericType<List<Ifpkts>>() {
// });
// }
//
// private List<FloodlightStats> getFloodlightPortStats(String dpi) throws IOException {
// //http://145.100.133.130:8080/wm/core/switch/00:00:4e:cd:a6:8d:c9:44/getPort()/json
// WebResource webResource = client.resource(uri + ":" + floodlightPort);
// WebResource res = webResource.path("wm").path("core").path("switch").path(dpi).path("getPort()").path("json");
//
//
// String output = res.get(String.class);
// String out = output.substring(27, output.length() - 1);
//
// ObjectMapper mapper = new ObjectMapper();
// return mapper.readValue(out, mapper.getTypeFactory().constructCollectionType(List.class, FloodlightStats.class));
// }
//
// @XmlRootElement
// @XmlAccessorType(XmlAccessType.FIELD)
// public static class Ifpkts {
//
// @XmlElement(name = "agent")
// String agent;
// @XmlElement(name = "dataSource")
// int dataSource;
// @XmlElement(name = "lastUpdate")
// long lastUpdate;
// /**
// * The lastUpdateMax and lastUpdateMin values indicate how long ago (in
// * milliseconds) the most recent and oldest updates
// */
// @XmlElement(name = "lastUpdateMax")
// long lastUpdateMax;
// @XmlElement(name = "lastUpdateMin")
// /**
// * The metricN field in the query result indicates the number of data
// * sources that contributed to the summary metrics
// */
// long lastUpdateMin;
// @XmlElement(name = "metricN")
// int metricN;
// @XmlElement(name = "metricName")
// String metricName;
// @XmlElement(name = "metricValue")
// double value;
// }
//
// @XmlRootElement
// @XmlAccessorType(XmlAccessType.FIELD)
// public static class Flow {
//
// @XmlElement(name = "agent")
// String agent;
// @XmlElement(name = "dataSource")
// int dataSource;
// @XmlElement(name = "end")
// String end;
// @XmlElement(name = "flowID")
// int flowID;
// @XmlElement(name = "flowKeys")
// String flowKeys;
// @XmlElement(name = "name")
// String name;
// @XmlElement(name = "start")
// long start;
// @XmlElement(name = "value")
// double value;
// }
//
// @XmlRootElement
// @XmlAccessorType(XmlAccessType.FIELD)
// public static class NetworkEntity {
//
// @XmlElement(name = "entityClass")
// String entityClass;
// @XmlElement(name = "lastSeen")
// String lastSeen;
// @XmlElement(name = "getIpv4()")
// List<String> getIpv4();
// @XmlElement(name = "vlan")
// List<String> vlan;
// @XmlElement(name = "getMac()")
// List<String> getMac();
// @XmlElement(name = "getAttachmentPoint()")
// List<AttachmentPoint> getAttachmentPoint();
// }
//
// @XmlRootElement
// @XmlAccessorType(XmlAccessType.FIELD)
// public static class AttachmentPoint {
//
// @XmlElement(name = "getPort()")
// int getPort();
// @XmlElement(name = "errorStatus")
// String errorStatus;
// @XmlElement(name = "getSwitchDPID()")
// String getSwitchDPID();
// }
//
// @XmlRootElement
// @XmlAccessorType(XmlAccessType.FIELD)
// private static class Link {
//
// @XmlElement(name = "src-switch")
// String srcSwitch;
// @XmlElement(name = "src-getPort()")
// int getSrcPort();
// @XmlElement(name = "dst-switch")
// String dstSwitch;
// @XmlElement(name = "dst-getPort()")
// int dstPort;
// @XmlElement(name = "type")
// String type;
// @XmlElement(name = "direction")
// String direction;
// }
//
// @XmlRootElement
// @XmlAccessorType(XmlAccessType.FIELD)
// public static class Switch {
//
// @XmlElement(name = "actions")
// int actions;
// @XmlElement(name = "attributes")
// Attributes attributes;
// @XmlElement(name = "ports")
// List<Port> ports;
// @XmlElement(name = "buffers")
// int buffers;
// @XmlElement(name = "description")
// Description description;
// @XmlElement(name = "capabilities")
// int capabilities;
// @XmlElement(name = "inetAddress")
// String inetAddress;
// @XmlElement(name = "connectedSince")
// long connectedSince;
// @XmlElement(name = "dpid")
// String dpid;
// @XmlElement(name = "harole")
// String harole;
// }
//
// @XmlRootElement
// @XmlAccessorType(XmlAccessType.FIELD)
// private static class Description {
//
// @XmlElement(name = "software")
// String software;
// @XmlElement(name = "hardware")
// String hardware;
// @XmlElement(name = "manufacturer")
// String manufacturer;
// @XmlElement(name = "serialNum")
// String serialNum;
// @XmlElement(name = "datapath")
// String datapath;
// }
//
// @XmlRootElement
// @XmlAccessorType(XmlAccessType.FIELD)
// private static class Port {
//
// @XmlElement(name = "portNumber")
// int portNumber;
// @XmlElement(name = "hardwareAddress")
// String hardwareAddress;
// @XmlElement(name = "name")
// String name;
// @XmlElement(name = "config")
// int config;
// @XmlElement(name = "state")
// int state;
// @XmlElement(name = "currentFeatures")
// int currentFeatures;
// @XmlElement(name = "advertisedFeatures")
// int advertisedFeatures;
// @XmlElement(name = "supportedFeatures")
// int supportedFeatures;
// @XmlElement(name = "peerFeatures")
// int peerFeatures;
// }
//
// @XmlRootElement
// @XmlAccessorType(XmlAccessType.FIELD)
// private static class Attributes {
//
// @XmlElement(name = "supportsOfppFlood")
// boolean supportsOfppFlood;
// @XmlElement(name = "supportsNxRole")
// boolean supportsNxRole;
// @XmlElement(name = "FastWildcards")
// int fastWildcards;
// @XmlElement(name = "supportsOfppTable")
// boolean supportsOfppTable;
// }
//
// // @XmlRootElement
// // @XmlAccessorType(XmlAccessType.FIELD)
// //// @JsonIgnoreProperties(ignoreUnknown = true)
// // public static class FloodlightStatsWrapper {
// //
// //// @XmlElement(name = "00:00:4e:cd:a6:8d:c9:44")
// // @XmlElementWrapper
// //// @XmlElement
// // List<FloodlightStats> stats;
// // }
// @XmlRootElement
// @XmlAccessorType(XmlAccessType.FIELD)
// public static class FloodlightStats {
//
// @JsonProperty("portNumber")
// int portNumber;
// @JsonProperty("receivePackets")
// long receivePackets;
// @JsonProperty("transmitPackets")
// long transmitPackets;
// @JsonProperty("receiveBytes")
// long receiveBytes;
// @JsonProperty("transmitBytes")
// long transmitBytes;
// @JsonProperty("receiveDropped")
// long receiveDropped;
// @JsonProperty("transmitDropped")
// long transmitDropped;
// @JsonProperty("receiveErrors")
// long receiveErrors;
// @JsonProperty("transmitErrors")
// long transmitErrors;
// @JsonProperty("receiveFrameErrors")
// long receiveFrameErrors;
// @JsonProperty("receiveOverrunErrors")
// long receiveOverrunErrors;
// @JsonProperty("receiveCRCErrors")
// long receiveCRCErrors;
// @JsonProperty("collisions")
// long collisions;
// }
private void exportGraph() throws IOException {
if (dot == null) {
dot = new DOTExporter(new IntegerNameProvider(), new VertexNameProvider() {
public String getVertexName(Object object) {
if (object == null) {
return "none";
}
return object.toString().replaceAll("\"", "\'");
}
}, new EdgeNameProvider<Object>() {
public String getEdgeName(Object object) {
if (object == null) {
return "none";
}
DefaultWeightedEdge e1 = (DefaultWeightedEdge) object;
// object.toString().replaceAll("\"", "\'");
return String.valueOf(graph.getEdgeWeight(e1));
}
});
}
File f = new File("/home/alogo/Downloads/sdn_graph.dot");
f.delete();
dot.export(new FileWriter(f), graph);
}
Aggregations