use of org.onosproject.net.SparseAnnotations in project onos by opennetworkinglab.
the class BasicDeviceOperator method combine.
/**
* Generates a DeviceDescription containing fields from a DeviceDescription and
* a DeviceConfig.
*
* @param cfg the device config entity from network config
* @param descr a DeviceDescription
* @return DeviceDescription based on both sources
*/
public static DeviceDescription combine(BasicDeviceConfig cfg, DeviceDescription descr) {
if (cfg == null || descr == null) {
return descr;
}
Device.Type type = descr.type();
if (cfg.type() != null && cfg.type() != type) {
type = cfg.type();
}
String manufacturer = descr.manufacturer();
if (cfg.manufacturer() != null && !cfg.manufacturer().equals(manufacturer)) {
manufacturer = cfg.manufacturer();
}
String hwVersion = descr.hwVersion();
if (cfg.hwVersion() != null && !cfg.hwVersion().equals(hwVersion)) {
hwVersion = cfg.hwVersion();
}
String swVersion = descr.swVersion();
if (cfg.swVersion() != null && !cfg.swVersion().equals(swVersion)) {
swVersion = cfg.swVersion();
}
String serial = descr.serialNumber();
if (cfg.serial() != null && !cfg.serial().equals(serial)) {
serial = cfg.serial();
}
SparseAnnotations sa = combine(cfg, descr.annotations());
return new DefaultDeviceDescription(descr.deviceUri(), type, manufacturer, hwVersion, swVersion, serial, descr.chassisId(), descr.isDefaultAvailable(), sa);
}
use of org.onosproject.net.SparseAnnotations in project onos by opennetworkinglab.
the class BasicLinkOperator method combine.
/**
* Generates a LinkDescription containing fields from a LinkDescription and
* a LinkConfig.
*
* @param cfg the link config entity from network config
* @param descr a LinkDescription
* @return LinkDescription based on both sources
*/
public static LinkDescription combine(BasicLinkConfig cfg, LinkDescription descr) {
if (cfg == null) {
return descr;
}
Link.Type type = descr.type();
if (cfg.isTypeConfigured()) {
if (cfg.type() != type) {
type = cfg.type();
}
}
SparseAnnotations sa = combine(cfg, descr.annotations());
return new DefaultLinkDescription(descr.src(), descr.dst(), type, sa);
}
use of org.onosproject.net.SparseAnnotations in project onos by opennetworkinglab.
the class PortProtoTranslator method translate.
/**
* Translates gRPC PortDescription message to {@link PortDescription}.
*
* @param portDescription gRPC message
* @return {@link PortDescription}
*/
public static PortDescription translate(PortDescriptionProto portDescription) {
PortNumber number = PortNumber.fromString(portDescription.getPortNumber());
boolean isEnabled = portDescription.getIsEnabled();
Port.Type type = translate(portDescription.getType()).get();
long portSpeed = portDescription.getPortSpeed();
SparseAnnotations annotations = AnnotationsTranslator.asAnnotations(portDescription.getAnnotationsMap());
// TODO How to deal with more specific Port...
return DefaultPortDescription.builder().withPortNumber(number).isEnabled(isEnabled).type(type).portSpeed(portSpeed).annotations(annotations).build();
}
use of org.onosproject.net.SparseAnnotations in project onos by opennetworkinglab.
the class KryoSerializerTest method testAnnotations.
@Test
public void testAnnotations() {
// Annotations does not have equals defined, manually test equality
final byte[] a1Bytes = serializer.encode(A1);
SparseAnnotations copiedA1 = serializer.decode(a1Bytes);
assertAnnotationsEquals(copiedA1, A1);
final byte[] a12Bytes = serializer.encode(A1_2);
SparseAnnotations copiedA12 = serializer.decode(a12Bytes);
assertAnnotationsEquals(copiedA12, A1_2);
}
use of org.onosproject.net.SparseAnnotations in project onos by opennetworkinglab.
the class DeviceDescriptionDiscoveryAristaImpl method discoverPortDetails.
@Override
public List<PortDescription> discoverPortDetails() {
Map<String, MacAddress> macAddressMap = getMacAddressesByInterface();
List<PortDescription> ports = Lists.newArrayList();
DeviceId deviceId = checkNotNull(handler().data().deviceId());
try {
Optional<JsonNode> result = AristaUtils.retrieveCommandResult(handler(), SHOW_INTERFACES_STATUS);
if (!result.isPresent()) {
log.warn("{} Device unable to get interfaces status information.", deviceId);
return ports;
}
JsonNode jsonNode = result.get().findValue(INTERFACE_STATUSES);
jsonNode.fieldNames().forEachRemaining(name -> {
JsonNode interfaceNode = jsonNode.get(name);
Long bandwidth = interfaceNode.path(BANDWIDTH).asLong() / MBPS;
String macAddress = macAddressMap.containsKey(name) ? macAddressMap.get(name).toString() : "";
SparseAnnotations annotations = DefaultAnnotations.builder().set(AnnotationKeys.BANDWIDTH, bandwidth.toString()).set(AnnotationKeys.NAME, name).set(AnnotationKeys.PORT_NAME, name).set(AnnotationKeys.PORT_MAC, macAddress).set(LINK_STATUS, interfaceNode.path(LINK_STATUS).asText()).set(LINE_PROTOCOL_STATUS, interfaceNode.path(LINE_PROTOCOL_STATUS).asText()).set(INTERFACE_TYPE, interfaceNode.path(INTERFACE_TYPE).asText()).build();
int portNumber;
try {
portNumber = getPortNumber(name);
} catch (Exception e) {
log.debug("Interface does not have port number: {}", name);
return;
}
PortDescription portDescription = DefaultPortDescription.builder().withPortNumber(PortNumber.portNumber(portNumber)).isEnabled(true).type(Port.Type.FIBER).portSpeed(bandwidth).annotations(annotations).build();
ports.add(portDescription);
});
} catch (Exception e) {
log.error("Exception occurred because of {}, trace: {}", e, e.getStackTrace());
}
return ports;
}
Aggregations