Search in sources :

Example 56 with DeviceService

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()));
    }
}
Also used : Tools(org.onlab.util.Tools) Supplier(com.google.common.base.Supplier) PortNumber(org.onosproject.net.PortNumber) DeviceService(org.onosproject.net.device.DeviceService) AnnotationKeys(org.onosproject.net.AnnotationKeys) DefaultLinkDescription(org.onosproject.net.link.DefaultLinkDescription) Link(org.onosproject.net.Link) ConnectPoint(org.onosproject.net.ConnectPoint) AbstractHandlerBehaviour(org.onosproject.net.driver.AbstractHandlerBehaviour) Port(org.onosproject.net.Port) Map(java.util.Map) JsonNode(com.fasterxml.jackson.databind.JsonNode) StreamSupport(java.util.stream.StreamSupport) LinkDescription(org.onosproject.net.link.LinkDescription) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) DefaultPort(org.onosproject.net.DefaultPort) Device(org.onosproject.net.Device) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) Set(java.util.Set) Sets(com.google.common.collect.Sets) LinkDiscovery(org.onosproject.net.behaviour.LinkDiscovery) Objects(java.util.Objects) DefaultAnnotations(org.onosproject.net.DefaultAnnotations) List(java.util.List) DriverHandler(org.onosproject.net.driver.DriverHandler) Stream(java.util.stream.Stream) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) Optional(java.util.Optional) MacAddress(org.onlab.packet.MacAddress) DeviceId(org.onosproject.net.DeviceId) DefaultAnnotations(org.onosproject.net.DefaultAnnotations) Port(org.onosproject.net.Port) DefaultPort(org.onosproject.net.DefaultPort) ConnectPoint(org.onosproject.net.ConnectPoint) DefaultPort(org.onosproject.net.DefaultPort)

Example 57 with DeviceService

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;
}
Also used : DeviceId(org.onosproject.net.DeviceId) Port(org.onosproject.net.Port) DeviceService(org.onosproject.net.device.DeviceService) JsonNode(com.fasterxml.jackson.databind.JsonNode) PortStatistics(org.onosproject.net.device.PortStatistics) DefaultPortStatistics(org.onosproject.net.device.DefaultPortStatistics) Map(java.util.Map)

Example 58 with DeviceService

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();
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DeviceService(org.onosproject.net.device.DeviceService)

Example 59 with DeviceService

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);
}
Also used : VirtualNetwork(org.onosproject.incubator.net.virtual.VirtualNetwork) DeviceService(org.onosproject.net.device.DeviceService) Test(org.junit.Test)

Example 60 with DeviceService

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());
}
Also used : VirtualNetwork(org.onosproject.incubator.net.virtual.VirtualNetwork) VirtualDevice(org.onosproject.incubator.net.virtual.VirtualDevice) DeviceService(org.onosproject.net.device.DeviceService) Test(org.junit.Test)

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