Search in sources :

Example 26 with DefaultAnnotations

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

the class SimpleDeviceStore method composePort.

/**
 * Returns a Port, merging description given from multiple Providers.
 *
 * @param device   device the port is on
 * @param number   port number
 * @param descsMap Collection of Descriptions from multiple providers
 * @return Port instance
 */
private Port composePort(Device device, PortNumber number, Map<ProviderId, DeviceDescriptions> descsMap) {
    ProviderId primary = pickPrimaryPid(descsMap);
    DeviceDescriptions primDescs = descsMap.get(primary);
    // if no primary, assume not enabled
    // TODO: revisit this default port enabled/disabled behavior
    boolean isEnabled = false;
    DefaultAnnotations annotations = DefaultAnnotations.builder().build();
    final PortDescription portDesc = primDescs.getPortDesc(number);
    if (portDesc != null) {
        isEnabled = portDesc.isEnabled();
        annotations = merge(annotations, portDesc.annotations());
    }
    for (Entry<ProviderId, DeviceDescriptions> e : descsMap.entrySet()) {
        if (e.getKey().equals(primary)) {
            continue;
        }
        // TODO: should keep track of Description timestamp
        // and only merge conflicting keys when timestamp is newer
        // Currently assuming there will never be a key conflict between
        // providers
        // annotation merging. not so efficient, should revisit later
        final PortDescription otherPortDesc = e.getValue().getPortDesc(number);
        if (otherPortDesc != null) {
            annotations = merge(annotations, otherPortDesc.annotations());
        }
    }
    return portDesc == null ? new DefaultPort(device, number, false, annotations) : new DefaultPort(device, number, isEnabled, portDesc.type(), portDesc.portSpeed(), annotations);
}
Also used : ProviderId(org.onosproject.net.provider.ProviderId) DefaultAnnotations(org.onosproject.net.DefaultAnnotations) PortDescription(org.onosproject.net.device.PortDescription) DefaultPortDescription(org.onosproject.net.device.DefaultPortDescription) DefaultPort(org.onosproject.net.DefaultPort)

Example 27 with DefaultAnnotations

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

the class SimpleDeviceStore method composeDevice.

/**
 * Returns a Device, merging description given from multiple Providers.
 *
 * @param deviceId      device identifier
 * @param providerDescs Collection of Descriptions from multiple providers
 * @return Device instance
 */
private Device composeDevice(DeviceId deviceId, Map<ProviderId, DeviceDescriptions> providerDescs) {
    checkArgument(!providerDescs.isEmpty(), "No Device descriptions supplied");
    ProviderId primary = pickPrimaryPid(providerDescs);
    DeviceDescriptions desc = providerDescs.get(primary);
    final DeviceDescription base = desc.getDeviceDesc();
    Type type = base.type();
    String manufacturer = base.manufacturer();
    String hwVersion = base.hwVersion();
    String swVersion = base.swVersion();
    String serialNumber = base.serialNumber();
    ChassisId chassisId = base.chassisId();
    DefaultAnnotations annotations = DefaultAnnotations.builder().build();
    annotations = merge(annotations, base.annotations());
    for (Entry<ProviderId, DeviceDescriptions> e : providerDescs.entrySet()) {
        if (e.getKey().equals(primary)) {
            continue;
        }
        // TODO: should keep track of Description timestamp
        // and only merge conflicting keys when timestamp is newer
        // Currently assuming there will never be a key conflict between
        // providers
        // annotation merging. not so efficient, should revisit later
        annotations = merge(annotations, e.getValue().getDeviceDesc().annotations());
    }
    return new DefaultDevice(primary, deviceId, type, manufacturer, hwVersion, swVersion, serialNumber, chassisId, annotations);
}
Also used : ProviderId(org.onosproject.net.provider.ProviderId) DeviceDescription(org.onosproject.net.device.DeviceDescription) DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription) Type(org.onosproject.net.Device.Type) ChassisId(org.onlab.packet.ChassisId) DefaultAnnotations(org.onosproject.net.DefaultAnnotations) DefaultDevice(org.onosproject.net.DefaultDevice)

Example 28 with DefaultAnnotations

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

the class PolatisLinkDiscovery method getLinks.

/**
 * Returns the set of LinkDescriptions originating from a Polatis switch.
 * <p>
 * This is the callback required by the LinkDiscovery behaviour.
 * @return Set of outbound unidirectional links as LinkDescriptions
 */
@Override
public Set<LinkDescription> getLinks() {
    Set<LinkDescription> links = new HashSet<>();
    DeviceId deviceID = handler().data().deviceId();
    log.debug("*** Checking peer-port fields on device {}", deviceID.toString());
    NetconfController controller = checkNotNull(handler().get(NetconfController.class));
    if (controller == null || controller.getDevicesMap() == null || controller.getDevicesMap().get(deviceID) == null) {
        log.warn("NETCONF session to device {} not yet established, will try again...", deviceID);
        return links;
    }
    DeviceService deviceService = checkNotNull(handler().get(DeviceService.class));
    Device device = deviceService.getDevice(deviceID);
    int numInputPorts = Integer.parseInt(device.annotations().value(KEY_INPUTPORTS));
    int numOutputPorts = Integer.parseInt(device.annotations().value(KEY_OUTPUTPORTS));
    log.trace("Talking to device " + handler().data().deviceId().toString());
    String reply = netconfGet(handler(), getPortsFilter());
    // Get port details from switch as PortDescription objects
    List<PortDescription> ports = parsePorts(reply, numInputPorts, numOutputPorts);
    int numPeerPortEntries = 0;
    int numPortsScanned = 0;
    ObjectMapper mapper = new ObjectMapper();
    for (PortDescription port : ports) {
        numPortsScanned++;
        if (deviceService.getPort(new ConnectPoint(deviceID, port.portNumber())).isEnabled()) {
            String peerPortData = port.annotations().value(KEY_PORTPEER);
            if (!peerPortData.equals("")) {
                numPeerPortEntries++;
                if (peerPortData.charAt(0) == '{') {
                    ConnectPoint nearEndCP = new ConnectPoint(deviceID, port.portNumber());
                    ConnectPoint farEndCP = null;
                    try {
                        farEndCP = parsePeerportDataForCP(mapper.readTree(peerPortData));
                    } catch (JsonProcessingException jpe) {
                        log.debug("Error processing peer-port JSON: {}", jpe.toString());
                    }
                    if (farEndCP != null) {
                        log.trace("Found ref on port {} to peer ConnectPoint: {}", port.portNumber(), farEndCP.toString());
                        if (checkPeer(nearEndCP, farEndCP, this.handler(), true)) {
                            log.trace("Peer {} checks out", farEndCP.toString());
                            // now add link to Set<LinkDescription>
                            DefaultAnnotations annotations = DefaultAnnotations.builder().set(KEY_LINKBIDIR, VALUE_FALSE).set(KEY_LINKALLOWED, VALUE_TRUE).build();
                            ConnectPoint aEndCP = nearEndCP;
                            ConnectPoint bEndCP = farEndCP;
                            // reverse direction of unidirectional link if near-end port is INPUT
                            if (port.annotations().value(KEY_PORTDIR).equals(VALUE_INPUT)) {
                                aEndCP = farEndCP;
                                bEndCP = nearEndCP;
                            }
                            LinkDescription newLinkDesc = new DefaultLinkDescription(aEndCP, bEndCP, Link.Type.OPTICAL, true, annotations);
                            links.add(newLinkDesc);
                            log.debug("Adding link {}", newLinkDesc);
                        }
                    }
                }
            }
        }
    }
    log.debug("Scanned {} ports, {} had peer-port entries, {} {} valid", numPortsScanned, numPeerPortEntries, links.size(), links.size() == 1 ? "is" : "are");
    log.trace("Links found on this iteration: {}", links);
    return links;
}
Also used : DefaultAnnotations(org.onosproject.net.DefaultAnnotations) DefaultLinkDescription(org.onosproject.net.link.DefaultLinkDescription) LinkDescription(org.onosproject.net.link.LinkDescription) DeviceId(org.onosproject.net.DeviceId) Device(org.onosproject.net.Device) DeviceService(org.onosproject.net.device.DeviceService) PortDescription(org.onosproject.net.device.PortDescription) ConnectPoint(org.onosproject.net.ConnectPoint) NetconfController(org.onosproject.netconf.NetconfController) ConnectPoint(org.onosproject.net.ConnectPoint) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) HashSet(java.util.HashSet) DefaultLinkDescription(org.onosproject.net.link.DefaultLinkDescription)

Example 29 with DefaultAnnotations

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

the class PolatisUtility method parsePort.

/**
 * Returns a single PortDescription from parsing a HierarchicalConfiguration object containing a Polatis switch
 * port config.
 *
 * @param cfg            Single port as HierarchicalConfiguration object
 * @param numInputPorts  Number of input ports
 * @param isConfigurable Switch is CC
 * @return               Single port as PortDescription object
 */
public static PortDescription parsePort(HierarchicalConfiguration cfg, int numInputPorts, boolean isConfigurable) {
    PortNumber portNumber = PortNumber.portNumber(cfg.getLong(KEY_PORTID));
    String portType = VALUE_UNKNOWN;
    if (isConfigurable) {
        portType = VALUE_CC;
    } else {
        portType = portNumber.toLong() > numInputPorts ? VALUE_OUTPUT : VALUE_INPUT;
    }
    String peerPort = cfg.getString(KEY_PEERPORT);
    DefaultAnnotations annotations = DefaultAnnotations.builder().set(AnnotationKeys.PORT_NAME, cfg.getString(KEY_PORTLABEL)).set(KEY_PORTPEER, cfg.getString(KEY_PEERPORT)).set(KEY_PORTDIR, portType).build();
    return omsPortDescription(portNumber, cfg.getString(KEY_PORTSTATUS).equals(PORT_ENABLED), Spectrum.U_BAND_MIN, Spectrum.O_BAND_MAX, Frequency.ofGHz(6_25), annotations);
}
Also used : DefaultAnnotations(org.onosproject.net.DefaultAnnotations) PortNumber(org.onosproject.net.PortNumber)

Example 30 with DefaultAnnotations

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

the class PolatisDeviceDescription method parseProductInformation.

private DeviceDescription parseProductInformation() {
    DeviceService devsvc = checkNotNull(handler().get(DeviceService.class));
    DeviceId devID = handler().data().deviceId();
    String reply = netconfGet(handler(), getProdInfoFilter());
    subscribe(handler());
    HierarchicalConfiguration cfg = configAt(reply, KEY_DATA_PRODINF);
    String hw = cfg.getString(KEY_HWVERSION);
    String numInputPorts = "0";
    String numOutputPorts = "0";
    if (!hw.equals("")) {
        Pattern patternSize = Pattern.compile("\\d+x[\\dC]+");
        Matcher matcher = patternSize.matcher(hw);
        if (matcher.find()) {
            String switchSize = matcher.group();
            log.debug("Got switch size: " + switchSize);
            Pattern patternNumber = Pattern.compile("[\\dC]+");
            matcher = patternNumber.matcher(switchSize);
            if (matcher.find()) {
                numInputPorts = matcher.group();
                log.debug("numInputPorts=" + numInputPorts);
                if (matcher.find()) {
                    if (!matcher.group().equals("CC")) {
                        numOutputPorts = matcher.group();
                    }
                }
                log.debug("numOutputPorts=" + numOutputPorts);
            }
        }
    } else {
        log.warn("Unable to determine type of Polatis switch " + devID.toString());
    }
    DefaultAnnotations annotations = DefaultAnnotations.builder().set(KEY_INPUTPORTS, numInputPorts).set(KEY_OUTPUTPORTS, numOutputPorts).build();
    return new DefaultDeviceDescription(devID.uri(), FIBER_SWITCH, cfg.getString(KEY_MANUFACTURER), cfg.getString(KEY_HWVERSION), cfg.getString(KEY_SWVERSION), cfg.getString(KEY_SERIALNUMBER), new ChassisId(cfg.getString(KEY_SERIALNUMBER)), true, annotations);
}
Also used : Pattern(java.util.regex.Pattern) ChassisId(org.onlab.packet.ChassisId) DefaultAnnotations(org.onosproject.net.DefaultAnnotations) Matcher(java.util.regex.Matcher) DeviceId(org.onosproject.net.DeviceId) DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription) DeviceService(org.onosproject.net.device.DeviceService) HierarchicalConfiguration(org.apache.commons.configuration.HierarchicalConfiguration)

Aggregations

DefaultAnnotations (org.onosproject.net.DefaultAnnotations)33 ConnectPoint (org.onosproject.net.ConnectPoint)9 PortDescription (org.onosproject.net.device.PortDescription)9 DefaultLinkDescription (org.onosproject.net.link.DefaultLinkDescription)8 DeviceId (org.onosproject.net.DeviceId)7 PortNumber (org.onosproject.net.PortNumber)7 ProviderId (org.onosproject.net.provider.ProviderId)7 DefaultPortDescription (org.onosproject.net.device.DefaultPortDescription)6 LinkDescription (org.onosproject.net.link.LinkDescription)6 HierarchicalConfiguration (org.apache.commons.configuration.HierarchicalConfiguration)4 Device (org.onosproject.net.Device)4 DeviceDescription (org.onosproject.net.device.DeviceDescription)4 ArrayList (java.util.ArrayList)3 ChassisId (org.onlab.packet.ChassisId)3 DefaultDevice (org.onosproject.net.DefaultDevice)3 DefaultDeviceDescription (org.onosproject.net.device.DefaultDeviceDescription)3 DeviceService (org.onosproject.net.device.DeviceService)3 XPath (javax.xml.xpath.XPath)2 XPathExpressionException (javax.xml.xpath.XPathExpressionException)2 Test (org.junit.Test)2