Search in sources :

Example 91 with Port

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

the class PolatisLinkDiscovery method checkPeer.

private boolean checkPeer(ConnectPoint nearEndCP, ConnectPoint peerCP, DriverHandler handler, boolean direct) {
    // check peerCP exists and is available (either via device service or direct from device)
    DeviceId peerDeviceID = peerCP.deviceId();
    boolean result = false;
    DeviceService deviceService = checkNotNull(handler.get(DeviceService.class));
    if (deviceService.isAvailable(peerDeviceID)) {
        log.trace("Peer device {} exists", peerDeviceID.toString());
        Device device = deviceService.getDevice(peerDeviceID);
        int numInputPorts = Integer.parseInt(device.annotations().value(KEY_INPUTPORTS));
        int numOutputPorts = Integer.parseInt(device.annotations().value(KEY_OUTPUTPORTS));
        List<Port> ports = deviceService.getPorts(peerDeviceID);
        PortNumber farEndPortNum = peerCP.port();
        Port port = deviceService.getPort(peerCP);
        if (port != null) {
            if (port.isEnabled()) {
                log.trace("Peer port {} exists", port.number().toLong());
                // check far end peer-port entry (use device service or retrieve direct from switch)
                Port peerPort = deviceService.getPort(peerDeviceID, farEndPortNum);
                String farEndPortPeerportData = peerPort.annotations().value(KEY_PORTPEER);
                if (direct) {
                    log.trace("Checking device {} DIRECT", handler.data().deviceId());
                    // A bit of a cludge it seems but temporarily open a new NETCONF session to far-end device
                    NetconfController controller = checkNotNull(handler.get(NetconfController.class));
                    NetconfSession farEndDeviceSession = controller.getDevicesMap().get(peerDeviceID).getSession();
                    String reply = netconfGet(farEndDeviceSession, getPortFilter(farEndPortNum));
                    PortDescription peerPortDescDirect = parsePorts(reply, numInputPorts, numOutputPorts).get(0);
                    log.trace("peerPortDesc from device: " + peerPortDescDirect.toString());
                    String farEndPortPeerportDataDirect = peerPortDescDirect.annotations().value(KEY_PORTPEER);
                    farEndPortPeerportData = farEndPortPeerportDataDirect;
                }
                if (!farEndPortPeerportData.equals("")) {
                    if (farEndPortPeerportData.charAt(0) == '{') {
                        log.trace("Far-end peer-port value:" + farEndPortPeerportData);
                        ObjectMapper mapper = new ObjectMapper();
                        ConnectPoint checkNearEndCP = null;
                        try {
                            checkNearEndCP = parsePeerportDataForCP(mapper.readTree(farEndPortPeerportData));
                        } catch (JsonProcessingException jpe) {
                            log.trace("Error processing peer-port JSON: {}", jpe.toString());
                        }
                        if (nearEndCP.equals(checkNearEndCP)) {
                            log.trace("Reciprocal peer port entries match: nearEnd={}, farEnd={}", nearEndCP, checkNearEndCP);
                            result = true;
                        } else {
                            log.trace("Peer-port entry for far-end port ({}) does not match near-end " + "port number ({})", checkNearEndCP, nearEndCP);
                        }
                    }
                } else {
                    log.trace("Null peer-port entry for far-end port ({})", peerCP);
                }
            } else {
                log.trace("Peer port {} is DISABLED", port);
            }
        } else {
            log.trace("Peer port {} does not exist", port);
        }
    } else {
        log.trace("Far end device does not exist or is not available");
    }
    return result;
}
Also used : NetconfSession(org.onosproject.netconf.NetconfSession) DeviceId(org.onosproject.net.DeviceId) Device(org.onosproject.net.Device) Port(org.onosproject.net.Port) DeviceService(org.onosproject.net.device.DeviceService) PortDescription(org.onosproject.net.device.PortDescription) ConnectPoint(org.onosproject.net.ConnectPoint) ConnectPoint(org.onosproject.net.ConnectPoint) NetconfController(org.onosproject.netconf.NetconfController) PortNumber(org.onosproject.net.PortNumber) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 92 with Port

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

the class PortStatsDriver method updatePorts.

public void updatePorts(Device device) {
    Set<PortStatistics> portStats = new HashSet<>();
    for (Port port : deviceService.getPorts(device.id())) {
        portStats.add(DefaultPortStatistics.builder().setBytesReceived(Math.abs(random.nextInt())).setBytesSent(Math.abs(random.nextInt())).setPacketsReceived(Math.abs(random.nextInt())).setPacketsSent(Math.abs(random.nextInt())).setDurationSec(2).setDeviceId(device.id()).setPort(port.number()).build());
    }
    deviceProviderService.updatePortStatistics(device.id(), portStats);
}
Also used : Port(org.onosproject.net.Port) PortStatistics(org.onosproject.net.device.PortStatistics) DefaultPortStatistics(org.onosproject.net.device.DefaultPortStatistics) HashSet(java.util.HashSet)

Example 93 with Port

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

the class ZtePortStatisticsDiscovery method discoverPortStatistics.

@Override
public Collection<PortStatistics> discoverPortStatistics() {
    DeviceId deviceId = handler().data().deviceId();
    LOG.debug("Discovering ZTE PortStatistics for device {}", deviceId);
    NetconfController controller = handler().get(NetconfController.class);
    if (null == controller) {
        LOG.error("Cannot find NetconfController");
        return null;
    }
    NetconfSession session = controller.getDevicesMap().get(deviceId).getSession();
    if (null == session) {
        LOG.error("No session available for device {}", deviceId);
        return null;
    }
    DeviceService deviceService = this.handler().get(DeviceService.class);
    List<Port> ports = deviceService.getPorts(deviceId);
    Collection<PortStatistics> portStatistics = Lists.newArrayList();
    ports.stream().filter(Port::isEnabled).filter(this::isClientPort).forEach(port -> portStatistics.add(discoverSpecifiedPortStatistics(session, deviceId, port)));
    return portStatistics;
}
Also used : NetconfSession(org.onosproject.netconf.NetconfSession) DeviceId(org.onosproject.net.DeviceId) Port(org.onosproject.net.Port) DeviceService(org.onosproject.net.device.DeviceService) NetconfController(org.onosproject.netconf.NetconfController) PortStatistics(org.onosproject.net.device.PortStatistics) DefaultPortStatistics(org.onosproject.net.device.DefaultPortStatistics)

Example 94 with Port

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

the class ZteTransceiver method enable.

@Override
public List<CharSequence> enable(PortNumber client, PortNumber line, boolean enable) {
    DeviceId deviceId = handler().data().deviceId();
    log.info("Discovering ZTE device {}", deviceId);
    Port clientPort = handler().get(DeviceService.class).getPort(deviceId, client);
    if (clientPort == null) {
        log.warn("{} does not exist on {}", client, deviceId);
        return Collections.emptyList();
    }
    String clientName = clientPort.annotations().value(OC_NAME);
    if (Strings.isNullOrEmpty(clientName)) {
        log.warn("{} annotations not exist on {}@{}", OC_NAME, client, deviceId);
        return Collections.emptyList();
    }
    Port linePort = handler().get(DeviceService.class).getPort(deviceId, line);
    if (linePort == null) {
        log.warn("{} does not exist on {}", line, deviceId);
        return Collections.emptyList();
    }
    String lineName = linePort.annotations().value(OC_NAME);
    if (Strings.isNullOrEmpty(lineName)) {
        log.warn("{} annotations not exist on {}@{}", OC_NAME, line, deviceId);
        return Collections.emptyList();
    }
    int clientIndex, lineIndex;
    try {
        clientIndex = getPortIndex(clientName);
        lineIndex = getPortIndex(lineName);
    } catch (IllegalArgumentException e) {
        return Collections.emptyList();
    }
    // create <terminal-device xmlns="http://openconfig.net/yang/terminal-device">
    // </terminal-device>
    OpenConfigTerminalDeviceHandler terminalDevice = new OpenConfigTerminalDeviceHandler();
    // add <logical-channels></logical-channels>
    OpenConfigLogicalChannelsHandler logicalChannels = new OpenConfigLogicalChannelsHandler(terminalDevice);
    // add <channel><index>"clientIndex"</index></channel>
    OpenConfigChannelHandler channel = new OpenConfigChannelHandler(clientIndex, logicalChannels);
    // add <channel xc:operation="merge/delete">
    if (enable) {
        channel.addAnnotation(ANOTATION_NAME, Operation.MERGE.value());
    } else {
        channel.addAnnotation(ANOTATION_NAME, Operation.DELETE.value());
    }
    // add <config><index>"clientIndex"</index></config>
    OpenConfigConfigOfChannelHandler configOfChannel = new OpenConfigConfigOfChannelHandler(channel);
    configOfChannel.addIndex(clientIndex);
    // add <logical-channel-assignments></logical-channel-assignments>
    OpenConfigLogicalChannelAssignmentsHandler logicalChannelAssignments = new OpenConfigLogicalChannelAssignmentsHandler(channel);
    // add <assignment><index>1</index></assignment>
    OpenConfigAssignmentHandler assignment = new OpenConfigAssignmentHandler(1, logicalChannelAssignments);
    // add <config><assignment-type>LOGICAL_CHANNEL</assignment-type>
    // <logical-channel>"lineIndex"</logical-channel>
    // </config>
    OpenConfigConfigOfAssignmentHandler configOfAssignment = new OpenConfigConfigOfAssignmentHandler(assignment);
    configOfAssignment.addAssignmentType(AssignmentTypeEnum.LOGICAL_CHANNEL);
    configOfAssignment.addLogicalChannel("" + lineIndex);
    return terminalDevice.getListCharSequence();
}
Also used : OpenConfigConfigOfChannelHandler(org.onosproject.odtn.utils.openconfig.OpenConfigConfigOfChannelHandler) OpenConfigConfigOfAssignmentHandler(org.onosproject.odtn.utils.openconfig.OpenConfigConfigOfAssignmentHandler) DeviceId(org.onosproject.net.DeviceId) Port(org.onosproject.net.Port) DeviceService(org.onosproject.net.device.DeviceService) OpenConfigAssignmentHandler(org.onosproject.odtn.utils.openconfig.OpenConfigAssignmentHandler) OpenConfigTerminalDeviceHandler(org.onosproject.odtn.utils.openconfig.OpenConfigTerminalDeviceHandler) OpenConfigLogicalChannelAssignmentsHandler(org.onosproject.odtn.utils.openconfig.OpenConfigLogicalChannelAssignmentsHandler) OpenConfigChannelHandler(org.onosproject.odtn.utils.openconfig.OpenConfigChannelHandler) OpenConfigLogicalChannelsHandler(org.onosproject.odtn.utils.openconfig.OpenConfigLogicalChannelsHandler)

Example 95 with Port

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

the class LldpLinkProviderTest method portSuppressedByPortBlacklist.

@Test
public void portSuppressedByPortBlacklist() {
    // add device in stub DeviceService without suppression configured
    deviceService.putDevice(device(DID3));
    deviceListener.event(deviceEvent(DeviceEvent.Type.DEVICE_ADDED, DID3));
    final long portno3 = 3L;
    final Port port3 = port(DID3, portno3, true);
    final ConnectPoint cpDid3no3 = new ConnectPoint(DID3, PortNumber.portNumber(portno3));
    portBlacklist.add(cpDid3no3);
    // suppressed port added to non-suppressed device
    deviceService.putPorts(DID3, port3);
    deviceListener.event(portEvent(DeviceEvent.Type.PORT_ADDED, DID3, port3));
    configListener.event(new NetworkConfigEvent(Type.CONFIG_ADDED, cpDid3no3, LinkDiscoveryFromPort.class));
    // discovery helper should be there turned on
    assertFalse("Discoverer is expected to start", provider.discoverers.get(DID3).isStopped());
    // but port is not a discovery target
    assertFalse("Discoverer should not contain the port there", provider.discoverers.get(DID3).containsPort(portno3));
}
Also used : NetworkConfigEvent(org.onosproject.net.config.NetworkConfigEvent) Port(org.onosproject.net.Port) DefaultPort(org.onosproject.net.DefaultPort) ConnectPoint(org.onosproject.net.ConnectPoint) Test(org.junit.Test)

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