use of org.onosproject.net.device.DeviceService in project onos by opennetworkinglab.
the class LinkDiscoveryAristaImpl method findDestinationPortByName.
private Optional<Port> findDestinationPortByName(String remotePortName, DeviceService deviceService, Device remoteDevice) {
Optional<Port> remotePort = deviceService.getPorts(remoteDevice.id()).stream().filter(port -> remotePortName.equals(port.annotations().value(AnnotationKeys.PORT_NAME))).findAny();
if (remotePort.isPresent()) {
return remotePort;
} else {
int portNumber = Integer.valueOf(remotePortName.replaceAll("\\D+", ""));
DefaultAnnotations.Builder annotations = DefaultAnnotations.builder().set(AnnotationKeys.PORT_NAME, remotePortName);
return Optional.of(new DefaultPort(remoteDevice, PortNumber.portNumber(portNumber, remotePortName), true, annotations.build()));
}
}
use of org.onosproject.net.device.DeviceService in project onos by opennetworkinglab.
the class PortStatisticsImpl method discoverPortStatistics.
@Override
public Collection<PortStatistics> discoverPortStatistics() {
Collection<PortStatistics> portStatistics = Lists.newArrayList();
try {
DeviceId deviceId = handler().data().deviceId();
DeviceService deviceService = this.handler().get(DeviceService.class);
List<Port> ports = deviceService.getPorts(deviceId);
Optional<JsonNode> result = AristaUtils.retrieveCommandResult(handler(), SHOW_INTERFACES);
if (!result.isPresent()) {
return portStatistics;
}
JsonNode interfaces = result.get().findValue(INTERFACES);
if (interfaces == null) {
return portStatistics;
}
Iterator<Map.Entry<String, JsonNode>> ifIterator = interfaces.fields();
while (ifIterator.hasNext()) {
Map.Entry<String, JsonNode> intf = ifIterator.next();
String ifName = intf.getKey();
JsonNode interfaceNode = intf.getValue();
JsonNode interfaceCounters = interfaceNode.get(INTERFACE_COUNTERS);
if (interfaceCounters == null) {
continue;
}
ports.stream().filter(Port::isEnabled).filter(port -> {
String portName = port.annotations().value(AnnotationKeys.PORT_NAME);
return portName != null && portName.equals(ifName);
}).findAny().ifPresent(port -> portStatistics.add(buildStatisticsForPort(interfaceCounters, port.number(), deviceId)));
}
} catch (Exception e) {
log.error("Exception occurred because of", e);
}
return portStatistics;
}
use of org.onosproject.net.device.DeviceService in project onos by opennetworkinglab.
the class DistributedVirtualFlowRuleStore method getFlowRuleCount.
@Override
public int getFlowRuleCount(NetworkId networkId) {
AtomicInteger sum = new AtomicInteger(0);
DeviceService deviceService = vnaService.get(networkId, DeviceService.class);
deviceService.getDevices().forEach(device -> sum.addAndGet(Iterables.size(getFlowEntries(networkId, device.id()))));
return sum.get();
}
use of org.onosproject.net.device.DeviceService in project onos by opennetworkinglab.
the class VirtualNetworkDeviceManagerTest method testIsAvailableByNullId.
/**
* Tests the isAvailable method using a null device identifier.
*/
@Test(expected = NullPointerException.class)
public void testIsAvailableByNullId() {
manager.registerTenantId(TenantId.tenantId(tenantIdValue1));
VirtualNetwork virtualNetwork = manager.createVirtualNetwork(TenantId.tenantId(tenantIdValue1));
DeviceService deviceService = manager.get(virtualNetwork.id(), DeviceService.class);
// test the isAvailable() method with null device id value.
deviceService.isAvailable(null);
}
use of org.onosproject.net.device.DeviceService in project onos by opennetworkinglab.
the class VirtualNetworkDeviceManagerTest method testGetPortStatistics.
/**
* Tests querying the port statistics of a device by device identifier.
*/
@Test
public void testGetPortStatistics() {
manager.registerTenantId(TenantId.tenantId(tenantIdValue1));
VirtualNetwork virtualNetwork = manager.createVirtualNetwork(TenantId.tenantId(tenantIdValue1));
VirtualDevice virtualDevice = manager.createVirtualDevice(virtualNetwork.id(), DID1);
manager.createVirtualDevice(virtualNetwork.id(), DID2);
DeviceService deviceService = manager.get(virtualNetwork.id(), DeviceService.class);
// test the getPortStatistics() method
assertEquals("The port statistics set size did not match.", 0, deviceService.getPortStatistics(DID1).size());
}
Aggregations