Search in sources :

Example 86 with DeviceService

use of org.onosproject.net.device.DeviceService in project onos by opennetworkinglab.

the class StatisticsWebResource method getPortDeltaStatistics.

/**
 * Gets port delta statistics of all devices.
 * @onos.rsModel StatisticsPorts
 * @return 200 OK with JSON encoded array of port delta statistics
 */
@GET
@Path("delta/ports")
@Produces(MediaType.APPLICATION_JSON)
public Response getPortDeltaStatistics() {
    final DeviceService service = get(DeviceService.class);
    final Iterable<Device> devices = service.getDevices();
    final ObjectNode root = mapper().createObjectNode();
    final ArrayNode rootArrayNode = root.putArray("statistics");
    for (final Device device : devices) {
        final ObjectNode deviceStatsNode = mapper().createObjectNode();
        deviceStatsNode.put("device", device.id().toString());
        final ArrayNode statisticsNode = deviceStatsNode.putArray("ports");
        final Iterable<PortStatistics> portStatsEntries = service.getPortDeltaStatistics(device.id());
        if (portStatsEntries != null) {
            for (final PortStatistics entry : portStatsEntries) {
                statisticsNode.add(codec(PortStatistics.class).encode(entry, this));
            }
        }
        rootArrayNode.add(deviceStatsNode);
    }
    return ok(root).build();
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Device(org.onosproject.net.Device) DeviceService(org.onosproject.net.device.DeviceService) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) PortStatistics(org.onosproject.net.device.PortStatistics) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 87 with DeviceService

use of org.onosproject.net.device.DeviceService in project onos by opennetworkinglab.

the class StatisticsWebResource method getPortDeltaStatisticsByDeviceIdAndPort.

/**
 * Gets port delta statistics of a specified device and port.
 * @onos.rsModel StatisticsPorts
 * @param deviceId device ID
 * @param port port
 * @return 200 OK with JSON encoded array of port delta statistics for the specified port
 */
@GET
@Path("delta/ports/{deviceId}/{port}")
@Produces(MediaType.APPLICATION_JSON)
public Response getPortDeltaStatisticsByDeviceIdAndPort(@PathParam("deviceId") String deviceId, @PathParam("port") String port) {
    final DeviceService service = get(DeviceService.class);
    final PortNumber portNumber = portNumber(port);
    final PortStatistics portStatsEntry = service.getDeltaStatisticsForPort(DeviceId.deviceId(deviceId), portNumber);
    final ObjectNode root = mapper().createObjectNode();
    final ArrayNode rootArrayNode = root.putArray("statistics");
    final ObjectNode deviceStatsNode = mapper().createObjectNode();
    deviceStatsNode.put("device", deviceId);
    final ArrayNode statisticsNode = deviceStatsNode.putArray("ports");
    if (portStatsEntry != null) {
        statisticsNode.add(codec(PortStatistics.class).encode(portStatsEntry, this));
    }
    rootArrayNode.add(deviceStatsNode);
    return ok(root).build();
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) DeviceService(org.onosproject.net.device.DeviceService) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) PortNumber(org.onosproject.net.PortNumber) PortStatistics(org.onosproject.net.device.PortStatistics) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 88 with DeviceService

use of org.onosproject.net.device.DeviceService in project onos by opennetworkinglab.

the class StatisticsWebResource method getPortStatisticsByDeviceIdAndPort.

/**
 * Gets port statistics of a specified device and port.
 * @onos.rsModel StatisticsPorts
 * @param deviceId device ID
 * @param port port
 * @return 200 OK with JSON encoded array of port statistics for the specified port
 */
@GET
@Path("ports/{deviceId}/{port}")
@Produces(MediaType.APPLICATION_JSON)
public Response getPortStatisticsByDeviceIdAndPort(@PathParam("deviceId") String deviceId, @PathParam("port") String port) {
    final DeviceService service = get(DeviceService.class);
    final PortNumber portNumber = portNumber(port);
    final PortStatistics portStatsEntry = service.getStatisticsForPort(DeviceId.deviceId(deviceId), portNumber);
    final ObjectNode root = mapper().createObjectNode();
    final ArrayNode rootArrayNode = root.putArray("statistics");
    final ObjectNode deviceStatsNode = mapper().createObjectNode();
    deviceStatsNode.put("device", deviceId);
    final ArrayNode statisticsNode = deviceStatsNode.putArray("ports");
    if (portStatsEntry != null) {
        statisticsNode.add(codec(PortStatistics.class).encode(portStatsEntry, this));
    }
    rootArrayNode.add(deviceStatsNode);
    return ok(root).build();
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) DeviceService(org.onosproject.net.device.DeviceService) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) PortNumber(org.onosproject.net.PortNumber) PortStatistics(org.onosproject.net.device.PortStatistics) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 89 with DeviceService

use of org.onosproject.net.device.DeviceService in project onos by opennetworkinglab.

the class TopologyResourceTest method setUpTest.

/**
 * Initializes the test harness.
 */
@Before
public void setUpTest() {
    TopologyService topologyService = new MockTopologyService();
    DeviceService mockDeviceService = new MockDeviceService();
    CodecManager codecService = new CodecManager();
    codecService.activate();
    ServiceDirectory testDirectory = new TestServiceDirectory().add(DeviceService.class, mockDeviceService).add(TopologyService.class, topologyService).add(CodecService.class, codecService);
    setServiceDirectory(testDirectory);
}
Also used : ServiceDirectory(org.onlab.osgi.ServiceDirectory) TestServiceDirectory(org.onlab.osgi.TestServiceDirectory) DeviceService(org.onosproject.net.device.DeviceService) TestServiceDirectory(org.onlab.osgi.TestServiceDirectory) CodecManager(org.onosproject.codec.impl.CodecManager) TopologyService(org.onosproject.net.topology.TopologyService) Before(org.junit.Before)

Example 90 with DeviceService

use of org.onosproject.net.device.DeviceService in project onos by opennetworkinglab.

the class PolatisInternalConnectivity method testConnectivity.

/**
 * Returns boolean in response to test of whether 2 ports on a given device can be internally connected.
 * <p>
 * This is a callback method required by the InternalConnectivity behaviour.
 * @param  inputPortNum  Input port number on device
 * @param  outputPortNum Output port number on device
 * @return               Indication whether internal connection can be made
 */
@Override
public boolean testConnectivity(PortNumber inputPortNum, PortNumber outputPortNum) {
    // is possible through a Polatis switch
    if (inputPortNum.equals(outputPortNum)) {
        log.debug("Input and output ports cannot be one and the same");
        return false;
    }
    DeviceId deviceID = handler().data().deviceId();
    DeviceService deviceService = checkNotNull(this.handler().get(DeviceService.class));
    Port inputPort = deviceService.getPort(new ConnectPoint(deviceID, inputPortNum));
    Port outputPort = deviceService.getPort(new ConnectPoint(deviceID, outputPortNum));
    if (!inputPort.isEnabled()) {
        log.debug("Input port is DISABLED");
        return false;
    }
    if (!outputPort.isEnabled()) {
        log.debug("Output port is DISABLED");
        return false;
    }
    if (!inputPort.annotations().value(KEY_PORTDIR).equals(VALUE_CC)) {
        if (inputPort.annotations().value(KEY_PORTDIR).equals(outputPort.annotations().value(KEY_PORTDIR))) {
            log.debug("Dual sided switch and provided input & output ports on same side");
            return false;
        }
    }
    // Check if either port is used in an active cross-connect
    Set<PortNumber> usedPorts = getUsedPorts();
    if (usedPorts.contains(inputPortNum)) {
        log.debug("Input port {} is used in an active cross-connect", inputPortNum);
        return false;
    }
    if (usedPorts.contains(outputPortNum)) {
        log.debug("Output port {} is used in an active cross-connect", outputPortNum);
        return false;
    }
    return true;
}
Also used : DeviceId(org.onosproject.net.DeviceId) Port(org.onosproject.net.Port) DeviceService(org.onosproject.net.device.DeviceService) PortNumber(org.onosproject.net.PortNumber) ConnectPoint(org.onosproject.net.ConnectPoint)

Aggregations

DeviceService (org.onosproject.net.device.DeviceService)187 Device (org.onosproject.net.Device)75 DeviceId (org.onosproject.net.DeviceId)73 Port (org.onosproject.net.Port)59 ConnectPoint (org.onosproject.net.ConnectPoint)42 PortNumber (org.onosproject.net.PortNumber)40 List (java.util.List)30 Collectors (java.util.stream.Collectors)24 Set (java.util.Set)23 AbstractHandlerBehaviour (org.onosproject.net.driver.AbstractHandlerBehaviour)19 Logger (org.slf4j.Logger)19 ArrayList (java.util.ArrayList)18 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)17 Optional (java.util.Optional)17 Test (org.junit.Test)16 JsonNode (com.fasterxml.jackson.databind.JsonNode)15 Collections (java.util.Collections)15 VirtualNetwork (org.onosproject.incubator.net.virtual.VirtualNetwork)15 DriverHandler (org.onosproject.net.driver.DriverHandler)15 Collection (java.util.Collection)14