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