Search in sources :

Example 26 with SparseAnnotations

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

the class DeviceDescriptionDiscoveryAristaImpl method discoverDeviceDetails.

@Override
public DeviceDescription discoverDeviceDetails() {
    try {
        Optional<JsonNode> result = AristaUtils.retrieveCommandResult(handler(), SHOW_VERSION);
        if (!result.isPresent()) {
            return null;
        }
        JsonNode jsonNode = result.get().get(AristaUtils.RESULT_START_INDEX);
        String hwVer = jsonNode.get(MODEL_NAME).asText(UNKNOWN);
        String swVer = jsonNode.get(SW_VERSION).asText(UNKNOWN);
        String serialNum = jsonNode.get(SERIAL_NUMBER).asText(UNKNOWN);
        String systemMacAddress = jsonNode.get(SYSTEM_MAC_ADDRESS).asText("").replace(":", "");
        DeviceId deviceId = checkNotNull(handler().data().deviceId());
        DeviceService deviceService = checkNotNull(handler().get(DeviceService.class));
        Device device = deviceService.getDevice(deviceId);
        ChassisId chassisId = systemMacAddress.isEmpty() ? new ChassisId() : new ChassisId(systemMacAddress);
        log.debug("systemMacAddress: {}", systemMacAddress);
        SparseAnnotations annotations = device == null ? DefaultAnnotations.builder().build() : (SparseAnnotations) device.annotations();
        return new DefaultDeviceDescription(deviceId.uri(), Device.Type.SWITCH, MANUFACTURER, hwVer, swVer, serialNum, chassisId, annotations);
    } catch (Exception e) {
        log.error("Exception occurred because of {}, trace: {}", e, e.getStackTrace());
        return null;
    }
}
Also used : SparseAnnotations(org.onosproject.net.SparseAnnotations) ChassisId(org.onlab.packet.ChassisId) DeviceId(org.onosproject.net.DeviceId) Device(org.onosproject.net.Device) DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription) DeviceService(org.onosproject.net.device.DeviceService) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 27 with SparseAnnotations

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

the class SimpleLinkStore method createOrUpdateLinkDescription.

// Guarded by linkDescs value (=locking each Link)
private LinkDescription createOrUpdateLinkDescription(Map<ProviderId, LinkDescription> descs, ProviderId providerId, LinkDescription linkDescription) {
    // merge existing attributes and merge
    LinkDescription oldDesc = descs.get(providerId);
    LinkDescription newDesc = linkDescription;
    if (oldDesc != null) {
        // we only allow transition from INDIRECT -> DIRECT
        final Type newType;
        if (oldDesc.type() == DIRECT) {
            newType = DIRECT;
        } else {
            newType = linkDescription.type();
        }
        SparseAnnotations merged = union(oldDesc.annotations(), linkDescription.annotations());
        newDesc = new DefaultLinkDescription(linkDescription.src(), linkDescription.dst(), newType, merged);
    }
    return descs.put(providerId, newDesc);
}
Also used : SparseAnnotations(org.onosproject.net.SparseAnnotations) Type(org.onosproject.net.Link.Type) DefaultLinkDescription(org.onosproject.net.link.DefaultLinkDescription) LinkDescription(org.onosproject.net.link.LinkDescription) DefaultLinkDescription(org.onosproject.net.link.DefaultLinkDescription)

Example 28 with SparseAnnotations

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

the class CienaWaveserverAiDeviceDescription method discoverDeviceDetails.

@Override
public DeviceDescription discoverDeviceDetails() {
    log.debug("Adding description for Waveserver Ai device");
    NetconfSession session = getNetconfSession();
    Device device = getDevice(handler().data().deviceId());
    try {
        XPath xp = XPathFactory.newInstance().newXPath();
        Node node = TEMPLATE_MANAGER.doRequest(session, "discoverDeviceDetails");
        String chassisId = xp.evaluate("waveserver-chassis/mac-addresses/chassis/base/text()", node);
        chassisId = chassisId.replace(":", "");
        SparseAnnotations annotationDevice = DefaultAnnotations.builder().set("name", xp.evaluate("waveserver-system/host-name/current-host-name/text()", node)).build();
        return new DefaultDeviceDescription(device.id().uri(), Device.Type.OTN, "Ciena", "WaverserverAi", xp.evaluate("waveserver-software/status/active-version/text()", node), xp.evaluate("waveserver-chassis/identification/serial-number/text()", node), new ChassisId(Long.valueOf(chassisId, 16)), (SparseAnnotations) annotationDevice);
    } catch (NetconfException | XPathExpressionException e) {
        log.error("Unable to retrieve device information for device {}, {}", device.chassisId(), e);
    }
    return new DefaultDeviceDescription(device.id().uri(), Device.Type.OTN, "Ciena", "WaverserverAi", "unknown", "unknown", device.chassisId());
}
Also used : NetconfSession(org.onosproject.netconf.NetconfSession) XPath(javax.xml.xpath.XPath) SparseAnnotations(org.onosproject.net.SparseAnnotations) ChassisId(org.onlab.packet.ChassisId) NetconfException(org.onosproject.netconf.NetconfException) Device(org.onosproject.net.Device) NetconfDevice(org.onosproject.netconf.NetconfDevice) XPathExpressionException(javax.xml.xpath.XPathExpressionException) Node(org.w3c.dom.Node) DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription)

Example 29 with SparseAnnotations

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

the class CienaWaveserverAiDeviceDescriptionTest method testDiscoverDeviceDetails.

@Test
public void testDiscoverDeviceDetails() {
    XPath xp = XPathFactory.newInstance().newXPath();
    SparseAnnotations expectAnnotation = DefaultAnnotations.builder().set("hostname", "hostnameWaveServer").build();
    DefaultDeviceDescription expectResult = new DefaultDeviceDescription(mockDeviceId.uri(), Device.Type.OTN, "Ciena", "WaverserverAi", "waveserver-1.1.0.302", "M000", new ChassisId(0L), expectAnnotation);
    try {
        Node node = doRequest("/response/discoverDeviceDetails.xml", "/rpc-reply/data");
        SparseAnnotations annotationDevice = DefaultAnnotations.builder().set("hostname", xp.evaluate("waveserver-system/host-name/current-host-name/text()", node)).build();
        DefaultDeviceDescription result = new DefaultDeviceDescription(mockDeviceId.uri(), Device.Type.OTN, "Ciena", "WaverserverAi", xp.evaluate("waveserver-software/status/active-version/text()", node), xp.evaluate("waveserver-chassis/identification/serial-number/text()", node), new ChassisId(0L), annotationDevice);
        assertEquals(expectResult, result);
    } catch (XPathExpressionException e) {
        e.printStackTrace();
    }
}
Also used : XPath(javax.xml.xpath.XPath) SparseAnnotations(org.onosproject.net.SparseAnnotations) ChassisId(org.onlab.packet.ChassisId) XPathExpressionException(javax.xml.xpath.XPathExpressionException) DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription) Node(org.w3c.dom.Node) Test(org.junit.Test)

Example 30 with SparseAnnotations

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

the class OpticalPortOperator method combine.

/**
 * Generates a PortDescription containing fields from a PortDescription and
 * an OpticalPortConfig.
 *
 * @param cp {@link ConnectPoint} representing the port.
 * @param descr input {@link PortDescription}
 * @return Combined {@link PortDescription}
 */
@Override
public PortDescription combine(ConnectPoint cp, PortDescription descr) {
    checkNotNull(cp);
    // must be removed if we need type override
    if (descr != null && !optical.contains(descr.type())) {
        return descr;
    }
    OpticalPortConfig opc = lookupConfig(cp);
    if (descr == null || opc == null) {
        return descr;
    }
    PortNumber number = descr.portNumber();
    // handle PortNumber "name" portion
    if (!opc.name().isEmpty()) {
        number = PortNumber.portNumber(descr.portNumber().toLong(), opc.name());
    }
    // handle additional annotations
    SparseAnnotations annotations = combine(opc, descr.annotations());
    // (Future work) handle type overwrite?
    Type type = firstNonNull(opc.type(), descr.type());
    if (type != descr.type()) {
        // TODO: Do we need to be able to overwrite Port.Type?
        log.warn("Port type overwrite requested for {}. Ignoring.", cp);
    }
    return updateDescription(number, annotations, descr);
}
Also used : SparseAnnotations(org.onosproject.net.SparseAnnotations) Type(org.onosproject.net.Port.Type) PortNumber(org.onosproject.net.PortNumber)

Aggregations

SparseAnnotations (org.onosproject.net.SparseAnnotations)30 DefaultDeviceDescription (org.onosproject.net.device.DefaultDeviceDescription)12 ChassisId (org.onlab.packet.ChassisId)10 DeviceId (org.onosproject.net.DeviceId)8 Device (org.onosproject.net.Device)6 Test (org.junit.Test)5 DefaultTunnelDescription (org.onosproject.incubator.net.tunnel.DefaultTunnelDescription)4 TunnelDescription (org.onosproject.incubator.net.tunnel.TunnelDescription)4 DeviceDescription (org.onosproject.net.device.DeviceDescription)4 PortDescription (org.onosproject.net.device.PortDescription)4 NetconfException (org.onosproject.netconf.NetconfException)4 NetconfSession (org.onosproject.netconf.NetconfSession)4 XMLConfiguration (org.apache.commons.configuration.XMLConfiguration)3 GroupId (org.onosproject.core.GroupId)3 IpTunnelEndPoint (org.onosproject.incubator.net.tunnel.IpTunnelEndPoint)3 TunnelEndPoint (org.onosproject.incubator.net.tunnel.TunnelEndPoint)3 TunnelId (org.onosproject.incubator.net.tunnel.TunnelId)3 Link (org.onosproject.net.Link)3 PortNumber (org.onosproject.net.PortNumber)3 NetconfDevice (org.onosproject.netconf.NetconfDevice)3