Search in sources :

Example 1 with TopologyProcessingException

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);
    }
}
Also used : Response(javax.ws.rs.core.Response) TopologyProcessingException(org.openkilda.topo.exceptions.TopologyProcessingException) IOException(java.io.IOException) Client(javax.ws.rs.client.Client) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 2 with TopologyProcessingException

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);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Topology(org.openkilda.topo.Topology) Switch(org.openkilda.topo.Switch) TopologyProcessingException(org.openkilda.topo.exceptions.TopologyProcessingException) LinkEndpoint(org.openkilda.topo.LinkEndpoint) HashMap(java.util.HashMap) Map(java.util.Map) Link(org.openkilda.topo.Link) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 3 with TopologyProcessingException

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);
    }
}
Also used : Response(javax.ws.rs.core.Response) TopologyProcessingException(org.openkilda.topo.exceptions.TopologyProcessingException) List(java.util.List) IOException(java.io.IOException) Client(javax.ws.rs.client.Client) ClientConfig(org.glassfish.jersey.client.ClientConfig) SwitchInfoData(org.openkilda.messaging.info.event.SwitchInfoData) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 4 with TopologyProcessingException

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);
    }
}
Also used : Response(javax.ws.rs.core.Response) TopologyProcessingException(org.openkilda.topo.exceptions.TopologyProcessingException) ArrayList(java.util.ArrayList) List(java.util.List) IOException(java.io.IOException) Client(javax.ws.rs.client.Client) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Flow(org.openkilda.messaging.model.Flow)

Example 5 with TopologyProcessingException

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;
}
Also used : TopologyProcessingException(org.openkilda.topo.exceptions.TopologyProcessingException) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)8 TopologyProcessingException (org.openkilda.topo.exceptions.TopologyProcessingException)8 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)6 Client (javax.ws.rs.client.Client)4 Response (javax.ws.rs.core.Response)4 List (java.util.List)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 ClientConfig (org.glassfish.jersey.client.ClientConfig)2 Link (org.openkilda.topo.Link)2 LinkEndpoint (org.openkilda.topo.LinkEndpoint)2 Switch (org.openkilda.topo.Switch)2 Topology (org.openkilda.topo.Topology)2 Given (cucumber.api.java.en.Given)1 File (java.io.File)1 Map (java.util.Map)1 IslInfoData (org.openkilda.messaging.info.event.IslInfoData)1 SwitchInfoData (org.openkilda.messaging.info.event.SwitchInfoData)1 Flow (org.openkilda.messaging.model.Flow)1 NodeDto (org.openkilda.topo.builders.TeTopologyParser.TopologyDto.NodeDto)1