use of org.openkilda.topo.exceptions.TopologyProcessingException in project open-kilda by telstra.
the class FlowUtils method getLinkBandwidth.
/**
* Returns link available bandwidth through Topology-Engine-Rest service.
*
* @return The JSON document of all flows
*/
public static Integer getLinkBandwidth(final String src_switch, final String src_port) {
System.out.println("\n==> Topology-Engine Link Bandwidth");
long current = System.currentTimeMillis();
Client client = clientFactory();
Response response = client.target(topologyEndpoint).path("/api/v1/topology/links/bandwidth/").path("{src_switch}").path("{src_port}").resolveTemplate("src_switch", src_switch).resolveTemplate("src_port", src_port).request().header(HttpHeaders.AUTHORIZATION, authHeaderValue).get();
System.out.println(format("===> Response = %s", response.toString()));
System.out.println(format("===> Topology-Engine Link Bandwidth Time: %,.3f", getTimeDuration(current)));
try {
Integer bandwidth = new ObjectMapper().readValue(response.readEntity(String.class), Integer.class);
System.out.println(format("====> Link switch=%s port=%s bandwidth=%d", src_switch, src_port, bandwidth));
return bandwidth;
} catch (IOException ex) {
throw new TopologyProcessingException(format("Unable to parse the links '%s'.", response.toString()), ex);
}
}
use of org.openkilda.topo.exceptions.TopologyProcessingException in project open-kilda by telstra.
the class TestTopologyBuilder method buildTopoFromTestJson.
/**
* This implements the ability to translate a test topology into a Topology object
*
* @param jsonDoc A JSON doc that matches the syntax of the json files in test/resources/topology
* @return The topology represented in the text file.
*/
@SuppressWarnings("unchecked")
public static final Topology buildTopoFromTestJson(String jsonDoc) {
Map<String, Switch> switches = new HashMap<>();
Map<String, Switch> altSwitchId = new HashMap<>();
Map<String, Link> links = new HashMap<>();
ObjectMapper mapper = new ObjectMapper();
Map<String, ArrayList<Map<String, String>>> root;
try {
root = mapper.readValue(jsonDoc, Map.class);
} catch (IOException ex) {
throw new TopologyProcessingException(format("Unable to parse the topology '%s'.", jsonDoc), ex);
}
// populate switches first
ArrayList<Map<String, String>> jsonSwitches = root.get("switches");
for (Map<String, String> s : jsonSwitches) {
String id = normalSwitchID(s.get("dpid"));
Switch newSwitch = new Switch(id);
switches.put(id, newSwitch);
if (s.get("name") != null)
altSwitchId.put(s.get("name"), newSwitch);
}
// now populate links
ArrayList<Map<String, String>> jsonLinks = root.get("links");
for (Map<String, String> l : jsonLinks) {
String srcId = l.get("node1");
String dstId = l.get("node2");
Switch src = switches.get(srcId);
if (src == null)
src = altSwitchId.get(srcId);
Switch dst = switches.get(dstId);
if (dst == null)
dst = altSwitchId.get(dstId);
Link link = new Link(new LinkEndpoint(src, null, null), new LinkEndpoint(dst, null, null));
links.put(link.getShortSlug(), link);
}
return new Topology(switches, links);
}
use of org.openkilda.topo.exceptions.TopologyProcessingException in project open-kilda by telstra.
the class SwitchesUtils method dumpSwitches.
/**
* Returns Switches through Topology-Engine-Rest service.
*
* @return The JSON document of all flows
*/
public static List<SwitchInfoData> dumpSwitches() {
System.out.println("\n==> Topology-Engine Dump Switches");
Client client = ClientBuilder.newClient(new ClientConfig());
Response response = client.target(topologyEndpoint).path("/api/v1/topology/switches").request().header(HttpHeaders.AUTHORIZATION, authHeaderValue).get();
System.out.println(format("===> Response = %s", response.toString()));
try {
List<SwitchInfoData> switches = new ObjectMapper().readValue(response.readEntity(String.class), new TypeReference<List<SwitchInfoData>>() {
});
return switches;
} catch (IOException ex) {
throw new TopologyProcessingException(format("Unable to parse the switches '%s'.", response.toString()), ex);
}
}
use of org.openkilda.topo.exceptions.TopologyProcessingException in project open-kilda by telstra.
the class FlowUtils method dumpFlows.
/**
* Returns flows through Topology-Engine-Rest service.
*
* @return The JSON document of all flows
*/
public static List<Flow> dumpFlows() {
System.out.println("\n==> Topology-Engine Dump Flows");
long current = System.currentTimeMillis();
Client client = clientFactory();
Response response = client.target(topologyEndpoint).path("/api/v1/topology/flows").request().header(HttpHeaders.AUTHORIZATION, authHeaderValue).get();
System.out.println(format("===> Response = %s", response.toString()));
System.out.println(format("===> Topology-Engine Dump Flows Time: %,.3f", getTimeDuration(current)));
try {
List<Flow> flows = new ObjectMapper().readValue(response.readEntity(String.class), new TypeReference<List<Flow>>() {
});
System.out.println(format("====> Topology-Engine Dump Flows = %d", flows.size()));
return flows;
} catch (IOException ex) {
throw new TopologyProcessingException(format("Unable to parse the flows '%s'.", response.toString()), ex);
}
}
use of org.openkilda.topo.exceptions.TopologyProcessingException in project open-kilda by telstra.
the class TestUtils method createMininetTopoFromFile.
public static String createMininetTopoFromFile(URL url) {
String doc;
try {
doc = Resources.toString(url, Charsets.UTF_8);
} catch (IOException ex) {
throw new TopologyProcessingException(format("Unable to read the topology file '%s'.", url), ex);
}
// remove any SW characters
doc = doc.replaceAll("\"dpid\": \"SW", "\"dpid\": \"");
// remove ':' in id
doc = doc.replaceAll("([0-9A-Fa-f]{2}):", "$1");
TopologyHelp.CreateMininetTopology(doc);
return doc;
}
Aggregations