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();
}
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();
}
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();
}
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);
}
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;
}
Aggregations