Search in sources :

Example 46 with DefaultDeviceDescription

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

the class SimpleDeviceStoreTest method testEvents.

// If Delegates should be called only on remote events,
// then Simple* should never call them, thus not test required.
// TODO add test for Port events when we have them
@Ignore("Ignore until Delegate spec. is clear.")
@Test
public final void testEvents() throws InterruptedException {
    final CountDownLatch addLatch = new CountDownLatch(1);
    DeviceStoreDelegate checkAdd = event -> {
        assertEquals(DEVICE_ADDED, event.type());
        assertDevice(DID1, SW1, event.subject());
        addLatch.countDown();
    };
    final CountDownLatch updateLatch = new CountDownLatch(1);
    DeviceStoreDelegate checkUpdate = event -> {
        assertEquals(DEVICE_UPDATED, event.type());
        assertDevice(DID1, SW2, event.subject());
        updateLatch.countDown();
    };
    final CountDownLatch removeLatch = new CountDownLatch(1);
    DeviceStoreDelegate checkRemove = event -> {
        assertEquals(DEVICE_REMOVED, event.type());
        assertDevice(DID1, SW2, event.subject());
        removeLatch.countDown();
    };
    DeviceDescription description = new DefaultDeviceDescription(DID1.uri(), SWITCH, MFR, HW, SW1, SN, CID);
    deviceStore.setDelegate(checkAdd);
    deviceStore.createOrUpdateDevice(PID, DID1, description);
    assertTrue("Add event fired", addLatch.await(1, TimeUnit.SECONDS));
    DeviceDescription description2 = new DefaultDeviceDescription(DID1.uri(), SWITCH, MFR, HW, SW2, SN, CID);
    deviceStore.unsetDelegate(checkAdd);
    deviceStore.setDelegate(checkUpdate);
    deviceStore.createOrUpdateDevice(PID, DID1, description2);
    assertTrue("Update event fired", updateLatch.await(1, TimeUnit.SECONDS));
    deviceStore.unsetDelegate(checkUpdate);
    deviceStore.setDelegate(checkRemove);
    deviceStore.removeDevice(DID1);
    assertTrue("Remove event fired", removeLatch.await(1, TimeUnit.SECONDS));
}
Also used : Arrays(java.util.Arrays) Iterables(com.google.common.collect.Iterables) BeforeClass(org.junit.BeforeClass) PortNumber(org.onosproject.net.PortNumber) HashMap(java.util.HashMap) DeviceStore(org.onosproject.net.device.DeviceStore) NetTestTools.assertAnnotationsEquals(org.onosproject.net.NetTestTools.assertAnnotationsEquals) Port(org.onosproject.net.Port) Map(java.util.Map) After(org.junit.After) SWITCH(org.onosproject.net.Device.Type.SWITCH) PortDescription(org.onosproject.net.device.PortDescription) DeviceId.deviceId(org.onosproject.net.DeviceId.deviceId) DeviceStoreDelegate(org.onosproject.net.device.DeviceStoreDelegate) DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription) Before(org.junit.Before) DeviceDescription(org.onosproject.net.device.DeviceDescription) AfterClass(org.junit.AfterClass) Device(org.onosproject.net.Device) Set(java.util.Set) Test(org.junit.Test) ProviderId(org.onosproject.net.provider.ProviderId) Type(org.onosproject.net.device.DeviceEvent.Type) Sets(com.google.common.collect.Sets) TimeUnit(java.util.concurrent.TimeUnit) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) DefaultAnnotations(org.onosproject.net.DefaultAnnotations) DefaultPortDescription(org.onosproject.net.device.DefaultPortDescription) Ignore(org.junit.Ignore) SparseAnnotations(org.onosproject.net.SparseAnnotations) DeviceEvent(org.onosproject.net.device.DeviceEvent) Assert(org.junit.Assert) DeviceId(org.onosproject.net.DeviceId) ChassisId(org.onlab.packet.ChassisId) DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription) DeviceDescription(org.onosproject.net.device.DeviceDescription) DeviceStoreDelegate(org.onosproject.net.device.DeviceStoreDelegate) DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription) CountDownLatch(java.util.concurrent.CountDownLatch) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 47 with DefaultDeviceDescription

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

the class PolatisDeviceDescription method discoverDeviceDetails.

/**
 * Discovers device details, for Polatis Snmp device by getting the system
 * information.
 *
 * @return device description
 */
@Override
public DeviceDescription discoverDeviceDetails() {
    DeviceService deviceService = checkNotNull(handler().get(DeviceService.class));
    DeviceId deviceId = handler().data().deviceId();
    Device device = deviceService.getDevice(deviceId);
    if (device == null) {
        return new DefaultDeviceDescription(deviceId.uri(), Device.Type.FIBER_SWITCH, DEFAULT_MANUFACTURER, DEFAULT_DESCRIPTION_DATA, DEFAULT_DESCRIPTION_DATA, DEFAULT_DESCRIPTION_DATA, new ChassisId());
    }
    String hardwareVersion = DEFAULT_DESCRIPTION_DATA;
    try {
        hardwareVersion = hardwareVersion();
    } catch (IOException e) {
        log.error("Error reading hardware version for device {} exception ", deviceId, e);
    }
    String softwareVersion = DEFAULT_DESCRIPTION_DATA;
    try {
        softwareVersion = softwareVersion();
    } catch (IOException e) {
        log.error("Error reading software version for device {} exception {}", deviceId, e);
    }
    String serialNumber = DEFAULT_DESCRIPTION_DATA;
    try {
        serialNumber = serialNumber();
    } catch (IOException e) {
        log.error("Error reading serial number for device {} exception {}", deviceId, e);
    }
    return new DefaultDeviceDescription(deviceId.uri(), Device.Type.FIBER_SWITCH, DEFAULT_MANUFACTURER, hardwareVersion, softwareVersion, serialNumber, device.chassisId(), (SparseAnnotations) device.annotations());
}
Also used : 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) IOException(java.io.IOException)

Example 48 with DefaultDeviceDescription

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

the class StratumDeviceDescriptionDiscovery method discoverDeviceDetails.

@Override
public DeviceDescription discoverDeviceDetails() {
    final DeviceDescription p4Descr = p4runtime.discoverDeviceDetails();
    final DeviceDescription gnoiDescr = gnoi.discoverDeviceDetails();
    final DeviceDescription gnmiDescr = gnmi.discoverDeviceDetails();
    return new DefaultDeviceDescription(data().deviceId().uri(), Device.Type.SWITCH, data().driver().manufacturer(), data().driver().hwVersion(), data().driver().swVersion(), UNKNOWN, p4Descr.chassisId(), // Availability is mandated by P4Runtime.
    p4Descr.isDefaultAvailable(), DefaultAnnotations.builder().putAll(p4Descr.annotations()).putAll(gnmiDescr.annotations()).putAll(gnoiDescr.annotations()).set(AnnotationKeys.PROTOCOL, format("%s, %s, %s", p4Descr.annotations().value(AnnotationKeys.PROTOCOL), gnmiDescr.annotations().value(AnnotationKeys.PROTOCOL), gnoiDescr.annotations().value(AnnotationKeys.PROTOCOL))).build());
}
Also used : DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription) DeviceDescription(org.onosproject.net.device.DeviceDescription) DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription)

Example 49 with DefaultDeviceDescription

use of org.onosproject.net.device.DefaultDeviceDescription 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)

Example 50 with DefaultDeviceDescription

use of org.onosproject.net.device.DefaultDeviceDescription 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)

Aggregations

DefaultDeviceDescription (org.onosproject.net.device.DefaultDeviceDescription)52 ChassisId (org.onlab.packet.ChassisId)33 DeviceDescription (org.onosproject.net.device.DeviceDescription)26 DeviceId (org.onosproject.net.DeviceId)24 Device (org.onosproject.net.Device)20 SparseAnnotations (org.onosproject.net.SparseAnnotations)14 DeviceService (org.onosproject.net.device.DeviceService)11 NetconfException (org.onosproject.netconf.NetconfException)11 NetconfSession (org.onosproject.netconf.NetconfSession)11 Test (org.junit.Test)9 DefaultAnnotations (org.onosproject.net.DefaultAnnotations)8 XMLConfiguration (org.apache.commons.configuration.XMLConfiguration)6 DeviceDescriptionDiscovery (org.onosproject.net.device.DeviceDescriptionDiscovery)6 DeviceEvent (org.onosproject.net.device.DeviceEvent)6 HierarchicalConfiguration (org.apache.commons.configuration.HierarchicalConfiguration)5 NetconfDevice (org.onosproject.netconf.NetconfDevice)5 List (java.util.List)4 BiFunction (java.util.function.BiFunction)4 Function (java.util.function.Function)4 XPath (javax.xml.xpath.XPath)4