Search in sources :

Example 6 with PortDescription

use of org.onosproject.net.device.PortDescription 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 7 with PortDescription

use of org.onosproject.net.device.PortDescription in project onos by opennetworkinglab.

the class PolatisDeviceDescription method discoverPortDetails.

/**
 * Discovers port details, for Polatis Snmp device.
 *
 * @return port list
 */
@Override
public List<PortDescription> discoverPortDetails() {
    List<PortDescription> ports = Lists.newArrayList();
    List<TableEvent> events;
    DeviceId deviceId = handler().data().deviceId();
    try {
        OID[] columnOIDs = { new OID(PORT_CURRENT_STATE_OID) };
        events = getTable(handler(), columnOIDs);
    } catch (IOException e) {
        log.error("Error reading ports table for device {} exception {}", deviceId, e);
        return ports;
    }
    if (events == null) {
        log.error("Error reading ports table for device {}", deviceId);
        return ports;
    }
    for (TableEvent event : events) {
        if (event == null) {
            log.error("Error reading event for device {}", deviceId);
            continue;
        }
        VariableBinding[] columns = event.getColumns();
        if (columns == null) {
            log.error("Error reading columns for device {} event {}", deviceId, event);
            continue;
        }
        VariableBinding portColumn = columns[0];
        if (portColumn == null) {
            continue;
        }
        int port = event.getIndex().last();
        boolean enabled = (portColumn.getVariable().toInt() == 1);
        PortNumber portNumber = PortNumber.portNumber(port);
        DefaultAnnotations annotations = DefaultAnnotations.builder().build();
        double opticalBand = Spectrum.O_BAND_MIN.asGHz() - Spectrum.L_BAND_MAX.asGHz();
        Frequency opticalGrid = Frequency.ofGHz(opticalBand / POLATIS_NUM_OF_WAVELENGTHS);
        PortDescription p = omsPortDescription(portNumber, enabled, Spectrum.O_BAND_MIN, Spectrum.L_BAND_MAX, opticalGrid, annotations);
        ports.add(p);
    }
    return ports;
}
Also used : DefaultAnnotations(org.onosproject.net.DefaultAnnotations) DeviceId(org.onosproject.net.DeviceId) OmsPortHelper.omsPortDescription(org.onosproject.net.optical.device.OmsPortHelper.omsPortDescription) PortDescription(org.onosproject.net.device.PortDescription) OID(org.snmp4j.smi.OID) IOException(java.io.IOException) TableEvent(org.snmp4j.util.TableEvent) Frequency(org.onlab.util.Frequency) PortNumber(org.onosproject.net.PortNumber) VariableBinding(org.snmp4j.smi.VariableBinding)

Example 8 with PortDescription

use of org.onosproject.net.device.PortDescription in project onos by opennetworkinglab.

the class PolatisUtility method parsePorts.

/**
 * Returns a list of PortDescriptions from parsing the content of the reply to a get[-config] call to a
 * Polatis switch.
 *
 * @param content        XML to be parsed as string
 * @param numInputPorts  Number of input ports
 * @param numOutputPorts Number of output ports
 * @return               List of ports as PortDescription objects
 */
public static List<PortDescription> parsePorts(String content, int numInputPorts, int numOutputPorts) {
    List<HierarchicalConfiguration> subtrees = configsAt(content, KEY_DATA_PORTCONFIG);
    List<PortDescription> portDescriptions = new ArrayList<PortDescription>();
    for (HierarchicalConfiguration portConfig : subtrees) {
        PortDescription parsedPort = parsePort(portConfig, numInputPorts, numOutputPorts == 0 ? true : false);
        portDescriptions.add(parsedPort);
    }
    return portDescriptions;
}
Also used : ArrayList(java.util.ArrayList) OmsPortHelper.omsPortDescription(org.onosproject.net.optical.device.OmsPortHelper.omsPortDescription) PortDescription(org.onosproject.net.device.PortDescription) HierarchicalConfiguration(org.apache.commons.configuration.HierarchicalConfiguration)

Example 9 with PortDescription

use of org.onosproject.net.device.PortDescription in project onos by opennetworkinglab.

the class DeviceInjectionConfigMonitor method injectDevice.

private void injectDevice(DeviceId did) {
    Optional<BasicDeviceConfig> basic = Optional.ofNullable(netcfgService.getConfig(did, BasicDeviceConfig.class));
    Optional<DeviceDescriptionDiscovery> discovery = basic.map(BasicDeviceConfig::driver).map(driverService::getDriver).filter(drvr -> drvr.hasBehaviour(DeviceDescriptionDiscovery.class)).map(drvr -> drvr.createBehaviour(new DefaultDriverHandler(new DefaultDriverData(drvr, did)), DeviceDescriptionDiscovery.class));
    if (discovery.isPresent()) {
        providerService.deviceConnected(did, discovery.get().discoverDeviceDetails());
        providerService.updatePorts(did, discovery.get().discoverPortDetails());
    } else {
        String unk = "UNKNOWN";
        DefaultDeviceDescription desc = new DefaultDeviceDescription(did.uri(), basic.map(BasicDeviceConfig::type).orElse(Type.SWITCH), basic.map(BasicDeviceConfig::manufacturer).orElse(unk), basic.map(BasicDeviceConfig::hwVersion).orElse(unk), basic.map(BasicDeviceConfig::swVersion).orElse(unk), basic.map(BasicDeviceConfig::serial).orElse(unk), new ChassisId(), true);
        providerService.deviceConnected(did, desc);
        Optional<DeviceInjectionConfig> inject = Optional.ofNullable(netcfgService.getConfig(did, DeviceInjectionConfig.class));
        String ports = inject.map(DeviceInjectionConfig::ports).orElse("0");
        int numPorts = Integer.parseInt(ports);
        List<PortDescription> portDescs = new ArrayList<>(numPorts);
        for (int i = 1; i <= numPorts; ++i) {
            // TODO inject port details if something like BasicPortConfig was created
            PortNumber number = portNumber(i);
            boolean isEnabled = true;
            portDescs.add(DefaultPortDescription.builder().withPortNumber(number).isEnabled(isEnabled).build());
        }
        providerService.updatePorts(did, portDescs);
    }
}
Also used : NetworkConfigService(org.onosproject.net.config.NetworkConfigService) NetworkConfigRegistry(org.onosproject.net.config.NetworkConfigRegistry) BasicDeviceConfig(org.onosproject.net.config.basics.BasicDeviceConfig) PortNumber.portNumber(org.onosproject.net.PortNumber.portNumber) PortNumber(org.onosproject.net.PortNumber) NetworkConfigEvent(org.onosproject.net.config.NetworkConfigEvent) DeviceService(org.onosproject.net.device.DeviceService) Tools.groupedThreads(org.onlab.util.Tools.groupedThreads) DeviceProviderRegistry(org.onosproject.net.device.DeviceProviderRegistry) DefaultDriverData(org.onosproject.net.driver.DefaultDriverData) DriverService(org.onosproject.net.driver.DriverService) ArrayList(java.util.ArrayList) Component(org.osgi.service.component.annotations.Component) ImmutableList(com.google.common.collect.ImmutableList) DEVICE_SUBJECT_FACTORY(org.onosproject.net.config.basics.SubjectFactories.DEVICE_SUBJECT_FACTORY) DefaultDriverHandler(org.onosproject.net.driver.DefaultDriverHandler) DeviceProvider(org.onosproject.net.device.DeviceProvider) PortDescription(org.onosproject.net.device.PortDescription) DeviceProviderService(org.onosproject.net.device.DeviceProviderService) Activate(org.osgi.service.component.annotations.Activate) DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription) EnumSet(java.util.EnumSet) ExecutorService(java.util.concurrent.ExecutorService) Type(org.onosproject.net.Device.Type) ImmutableSet(com.google.common.collect.ImmutableSet) Logger(org.slf4j.Logger) MastershipRole(org.onosproject.net.MastershipRole) Deactivate(org.osgi.service.component.annotations.Deactivate) DeviceDescriptionDiscovery(org.onosproject.net.device.DeviceDescriptionDiscovery) Set(java.util.Set) ProviderId(org.onosproject.net.provider.ProviderId) Executors.newSingleThreadExecutor(java.util.concurrent.Executors.newSingleThreadExecutor) Beta(com.google.common.annotations.Beta) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) TimeUnit(java.util.concurrent.TimeUnit) ConfigFactory(org.onosproject.net.config.ConfigFactory) DeviceInjectionConfig(org.onosproject.net.config.inject.DeviceInjectionConfig) DefaultPortDescription(org.onosproject.net.device.DefaultPortDescription) List(java.util.List) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) Optional(java.util.Optional) DeviceId(org.onosproject.net.DeviceId) Reference(org.osgi.service.component.annotations.Reference) NetworkConfigListener(org.onosproject.net.config.NetworkConfigListener) ChassisId(org.onlab.packet.ChassisId) ChassisId(org.onlab.packet.ChassisId) DefaultDriverHandler(org.onosproject.net.driver.DefaultDriverHandler) ArrayList(java.util.ArrayList) DeviceInjectionConfig(org.onosproject.net.config.inject.DeviceInjectionConfig) PortDescription(org.onosproject.net.device.PortDescription) DefaultPortDescription(org.onosproject.net.device.DefaultPortDescription) BasicDeviceConfig(org.onosproject.net.config.basics.BasicDeviceConfig) DeviceDescriptionDiscovery(org.onosproject.net.device.DeviceDescriptionDiscovery) DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription) PortNumber(org.onosproject.net.PortNumber) DefaultDriverData(org.onosproject.net.driver.DefaultDriverData)

Example 10 with PortDescription

use of org.onosproject.net.device.PortDescription in project onos by opennetworkinglab.

the class FujitsuT100DeviceDescription method discoverPortDetails.

@Override
public List<PortDescription> discoverPortDetails() {
    NetconfController controller = checkNotNull(handler().get(NetconfController.class));
    NetconfSession session = controller.getDevicesMap().get(handler().data().deviceId()).getSession();
    String reply;
    try {
        reply = session.get(requestBuilder());
    } catch (NetconfException e) {
        log.error("Failed to retrieve port details for device {}", handler().data().deviceId());
        return ImmutableList.of();
    }
    List<PortDescription> descriptions = parseFujitsuT100Ports(XmlConfigParser.loadXml(new ByteArrayInputStream(reply.getBytes())));
    return ImmutableList.copyOf(descriptions);
}
Also used : NetconfSession(org.onosproject.netconf.NetconfSession) NetconfException(org.onosproject.netconf.NetconfException) ByteArrayInputStream(java.io.ByteArrayInputStream) OchPortHelper.ochPortDescription(org.onosproject.net.optical.device.OchPortHelper.ochPortDescription) PortDescription(org.onosproject.net.device.PortDescription) OduCltPortHelper.oduCltPortDescription(org.onosproject.net.optical.device.OduCltPortHelper.oduCltPortDescription) NetconfController(org.onosproject.netconf.NetconfController)

Aggregations

PortDescription (org.onosproject.net.device.PortDescription)81 DefaultPortDescription (org.onosproject.net.device.DefaultPortDescription)41 Test (org.junit.Test)25 DefaultAnnotations (org.onosproject.net.DefaultAnnotations)25 PortNumber (org.onosproject.net.PortNumber)24 DeviceId (org.onosproject.net.DeviceId)23 ArrayList (java.util.ArrayList)22 Port (org.onosproject.net.Port)22 DeviceEvent (org.onosproject.net.device.DeviceEvent)14 ProviderId (org.onosproject.net.provider.ProviderId)13 Device (org.onosproject.net.Device)12 HierarchicalConfiguration (org.apache.commons.configuration.HierarchicalConfiguration)11 DefaultPort (org.onosproject.net.DefaultPort)9 DeviceService (org.onosproject.net.device.DeviceService)9 NetconfSession (org.onosproject.netconf.NetconfSession)8 IOException (java.io.IOException)7 HashMap (java.util.HashMap)7 OduCltPortHelper.oduCltPortDescription (org.onosproject.net.optical.device.OduCltPortHelper.oduCltPortDescription)7 OmsPortHelper.omsPortDescription (org.onosproject.net.optical.device.OmsPortHelper.omsPortDescription)7 OchPortHelper.ochPortDescription (org.onosproject.net.optical.device.OchPortHelper.ochPortDescription)6