Search in sources :

Example 66 with Port

use of org.onosproject.net.Port in project onos by opennetworkinglab.

the class PortWaveLengthCommand method createOchSignalFromWavelength.

private OchSignal createOchSignalFromWavelength(DeviceService deviceService, ConnectPoint cp) {
    long wavelength = Long.parseLong(parameter);
    if (wavelength == 0L) {
        return null;
    }
    Port port = deviceService.getPort(cp);
    Optional<OchPort> ochPortOpt = OchPortHelper.asOchPort(port);
    if (ochPortOpt.isPresent()) {
        OchPort ochPort = ochPortOpt.get();
        GridType gridType = ochPort.lambda().gridType();
        ChannelSpacing channelSpacing = ochPort.lambda().channelSpacing();
        int slotGranularity = ochPort.lambda().slotGranularity();
        int multiplier = getMultplier(wavelength, gridType, channelSpacing);
        return new OchSignal(gridType, channelSpacing, multiplier, slotGranularity);
    } else {
        print("[ERROR] connect point %s is not OChPort", cp);
        return null;
    }
}
Also used : ChannelSpacing(org.onosproject.net.ChannelSpacing) Port(org.onosproject.net.Port) OchPort(org.onosproject.net.optical.OchPort) OchSignal(org.onosproject.net.OchSignal) OchPort(org.onosproject.net.optical.OchPort) ConnectPoint(org.onosproject.net.ConnectPoint) GridType(org.onosproject.net.GridType)

Example 67 with Port

use of org.onosproject.net.Port in project onos by opennetworkinglab.

the class LinkDiscoveryAristaImpl method findRemoteDeviceByChassisId.

private Optional<Device> findRemoteDeviceByChassisId(DeviceService deviceService, String remoteChassisIdString) {
    String forMacTmp = remoteChassisIdString.replace(".", "").replaceAll("(.{2})", "$1:").trim().substring(0, 17);
    MacAddress mac = MacAddress.valueOf(forMacTmp);
    Supplier<Stream<Device>> deviceStream = () -> StreamSupport.stream(deviceService.getAvailableDevices().spliterator(), false);
    Optional<Device> remoteDeviceOptional = deviceStream.get().filter(device -> device.chassisId() != null && MacAddress.valueOf(device.chassisId().value()).equals(mac)).findAny();
    if (remoteDeviceOptional.isPresent()) {
        log.debug("remoteDevice found by chassis id: {}", forMacTmp);
        return remoteDeviceOptional;
    } else {
        remoteDeviceOptional = deviceStream.get().filter(device -> Tools.stream(deviceService.getPorts(device.id())).anyMatch(port -> port.annotations().keys().contains(AnnotationKeys.PORT_MAC) && MacAddress.valueOf(port.annotations().value(AnnotationKeys.PORT_MAC)).equals(mac))).findAny();
        if (remoteDeviceOptional.isPresent()) {
            log.debug("remoteDevice found by port mac: {}", forMacTmp);
            return remoteDeviceOptional;
        } else {
            return Optional.empty();
        }
    }
}
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) Device(org.onosproject.net.Device) Stream(java.util.stream.Stream) MacAddress(org.onlab.packet.MacAddress)

Example 68 with Port

use of org.onosproject.net.Port 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 69 with Port

use of org.onosproject.net.Port 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 70 with Port

use of org.onosproject.net.Port in project onos by opennetworkinglab.

the class VirtualNetworkIntentManagerTest method setupVirtualNetworkTopology.

/**
 * Method to create the virtual network for further testing.
 *
 * @return virtual network
 */
private VirtualNetwork setupVirtualNetworkTopology() {
    manager.registerTenantId(TenantId.tenantId(tenantIdValue1));
    VirtualNetwork virtualNetwork = manager.createVirtualNetwork(TenantId.tenantId(tenantIdValue1));
    VirtualDevice virtualDevice1 = manager.createVirtualDevice(virtualNetwork.id(), DID1);
    VirtualDevice virtualDevice2 = manager.createVirtualDevice(virtualNetwork.id(), DID2);
    VirtualDevice virtualDevice3 = manager.createVirtualDevice(virtualNetwork.id(), DID3);
    VirtualDevice virtualDevice4 = manager.createVirtualDevice(virtualNetwork.id(), DID4);
    Port port1 = new DefaultPort(virtualDevice1, PortNumber.portNumber(1), true);
    cp1 = new ConnectPoint(virtualDevice1.id(), port1.number());
    manager.createVirtualPort(virtualNetwork.id(), virtualDevice1.id(), port1.number(), cp1);
    Port port2 = new DefaultPort(virtualDevice1, PortNumber.portNumber(2), true);
    cp2 = new ConnectPoint(virtualDevice1.id(), port2.number());
    manager.createVirtualPort(virtualNetwork.id(), virtualDevice1.id(), port2.number(), cp2);
    Port port3 = new DefaultPort(virtualDevice2, PortNumber.portNumber(3), true);
    cp3 = new ConnectPoint(virtualDevice2.id(), port3.number());
    manager.createVirtualPort(virtualNetwork.id(), virtualDevice2.id(), port3.number(), cp3);
    Port port4 = new DefaultPort(virtualDevice2, PortNumber.portNumber(4), true);
    cp4 = new ConnectPoint(virtualDevice2.id(), port4.number());
    manager.createVirtualPort(virtualNetwork.id(), virtualDevice2.id(), port4.number(), cp4);
    Port port5 = new DefaultPort(virtualDevice3, PortNumber.portNumber(5), true);
    cp5 = new ConnectPoint(virtualDevice3.id(), port5.number());
    manager.createVirtualPort(virtualNetwork.id(), virtualDevice3.id(), port5.number(), cp5);
    Port port6 = new DefaultPort(virtualDevice3, PortNumber.portNumber(6), true);
    cp6 = new ConnectPoint(virtualDevice3.id(), port6.number());
    manager.createVirtualPort(virtualNetwork.id(), virtualDevice3.id(), port6.number(), cp6);
    link1 = manager.createVirtualLink(virtualNetwork.id(), cp1, cp3);
    virtualNetworkManagerStore.updateLink(link1, link1.tunnelId(), Link.State.ACTIVE);
    link2 = manager.createVirtualLink(virtualNetwork.id(), cp3, cp1);
    virtualNetworkManagerStore.updateLink(link2, link2.tunnelId(), Link.State.ACTIVE);
    link3 = manager.createVirtualLink(virtualNetwork.id(), cp4, cp5);
    virtualNetworkManagerStore.updateLink(link3, link3.tunnelId(), Link.State.ACTIVE);
    link4 = manager.createVirtualLink(virtualNetwork.id(), cp5, cp4);
    virtualNetworkManagerStore.updateLink(link4, link4.tunnelId(), Link.State.ACTIVE);
    vnetIntentService = new VirtualNetworkIntentManager(manager, virtualNetwork.id());
    vnetIntentService.intentStore = intentStore;
    return virtualNetwork;
}
Also used : VirtualNetwork(org.onosproject.incubator.net.virtual.VirtualNetwork) Port(org.onosproject.net.Port) DefaultPort(org.onosproject.net.DefaultPort) VirtualDevice(org.onosproject.incubator.net.virtual.VirtualDevice) ConnectPoint(org.onosproject.net.ConnectPoint) DefaultPort(org.onosproject.net.DefaultPort)

Aggregations

Port (org.onosproject.net.Port)200 DeviceService (org.onosproject.net.device.DeviceService)92 PortNumber (org.onosproject.net.PortNumber)85 ConnectPoint (org.onosproject.net.ConnectPoint)78 DeviceId (org.onosproject.net.DeviceId)76 Device (org.onosproject.net.Device)63 List (java.util.List)51 Set (java.util.Set)47 Optional (java.util.Optional)43 DefaultPort (org.onosproject.net.DefaultPort)38 Logger (org.slf4j.Logger)38 ArrayList (java.util.ArrayList)36 Collectors (java.util.stream.Collectors)35 Collections (java.util.Collections)34 Collection (java.util.Collection)33 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)33 Test (org.junit.Test)31 Ethernet (org.onlab.packet.Ethernet)31 Map (java.util.Map)29 Sets (com.google.common.collect.Sets)28