Search in sources :

Example 1 with Topology

use of org.openkilda.topology.model.Topology in project open-kilda by telstra.

the class TopologyServiceImplTest method clear.

@Test
public void clear() throws Exception {
    Topology topology = topologyService.clear(DEFAULT_CORRELATION_ID);
    assertEquals(new Topology(new ArrayList<>()), topology);
    System.out.println(topology.toString());
}
Also used : ArrayList(java.util.ArrayList) Topology(org.openkilda.topology.model.Topology) Test(org.junit.Test)

Example 2 with Topology

use of org.openkilda.topology.model.Topology in project open-kilda by telstra.

the class TopologyServiceImplTest method network.

@Test
public void network() throws Exception {
    List<Node> nodes = Arrays.asList(new Node(srcSwitchId, Collections.singletonList(firstTransitSwitchId)), new Node(firstTransitSwitchId, Arrays.asList(srcSwitchId, secondTransitSwitchId)), new Node(secondTransitSwitchId, Arrays.asList(firstTransitSwitchId, dstSwitchId)), new Node(dstSwitchId, Collections.singletonList(secondTransitSwitchId)));
    Topology topology = topologyService.network(DEFAULT_CORRELATION_ID);
    assertEquals(new Topology(nodes), topology);
    System.out.println(topology.toString());
}
Also used : Node(org.openkilda.topology.model.Node) Topology(org.openkilda.topology.model.Topology) Test(org.junit.Test)

Example 3 with Topology

use of org.openkilda.topology.model.Topology in project open-kilda by telstra.

the class TopologyController method network.

/**
 * Dumps topology.
 *
 * @param correlationId correlation ID header value
 * @return network topology
 */
@RequestMapping(value = "/network", method = RequestMethod.GET, produces = APPLICATION_JSON_UTF8_VALUE)
public ResponseEntity<Topology> network(@RequestHeader(value = CORRELATION_ID, defaultValue = DEFAULT_CORRELATION_ID) String correlationId) {
    logger.debug("Get topology: {}={}", CORRELATION_ID, correlationId);
    Topology topology = topologyService.network(correlationId);
    return new ResponseEntity<>(topology, new HttpHeaders(), HttpStatus.OK);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ResponseEntity(org.springframework.http.ResponseEntity) Topology(org.openkilda.topology.model.Topology) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with Topology

use of org.openkilda.topology.model.Topology in project open-kilda by telstra.

the class TopologyController method clear.

/**
 * Cleans topology.
 *
 * @param correlationId correlation ID header value
 * @return network topology
 */
@RequestMapping(value = "/clear", method = RequestMethod.GET, produces = APPLICATION_JSON_UTF8_VALUE)
public ResponseEntity<Topology> clear(@RequestHeader(value = CORRELATION_ID, defaultValue = DEFAULT_CORRELATION_ID) String correlationId) {
    logger.debug("Clear topology: {}={}", CORRELATION_ID, correlationId);
    Topology topology = topologyService.clear(correlationId);
    return new ResponseEntity<>(topology, new HttpHeaders(), HttpStatus.OK);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ResponseEntity(org.springframework.http.ResponseEntity) Topology(org.openkilda.topology.model.Topology) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with Topology

use of org.openkilda.topology.model.Topology in project open-kilda by telstra.

the class TopologyServiceImpl method network.

/**
 * {@inheritDoc}
 */
@Override
public Topology network(String correlationId) {
    logger.debug("Dumping topology: {}={}", CORRELATION_ID, correlationId);
    List<Isl> isls = islRepository.getAllIsl();
    logger.debug("Found isls: {}={}, {}", CORRELATION_ID, correlationId, isls);
    Iterable<Switch> switches = switchRepository.findAll();
    List<Node> nodes = new ArrayList<>();
    for (Switch sw : switches) {
        List<String> relationships = new ArrayList<>();
        for (Isl isl : isls) {
            if (isl.getSourceSwitch().equals(sw.getName())) {
                relationships.add(isl.getDestinationSwitch());
            }
        }
        nodes.add(new Node(sw.getName(), relationships));
    }
    return new Topology(nodes);
}
Also used : Isl(org.openkilda.topology.domain.Isl) Switch(org.openkilda.topology.domain.Switch) Node(org.openkilda.topology.model.Node) ArrayList(java.util.ArrayList) Topology(org.openkilda.topology.model.Topology)

Aggregations

Topology (org.openkilda.topology.model.Topology)5 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 Node (org.openkilda.topology.model.Node)2 HttpHeaders (org.springframework.http.HttpHeaders)2 ResponseEntity (org.springframework.http.ResponseEntity)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 Isl (org.openkilda.topology.domain.Isl)1 Switch (org.openkilda.topology.domain.Switch)1