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));
}
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());
}
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());
}
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);
}
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());
}
Aggregations