use of org.onosproject.net.device.DefaultPortDescription.Builder in project onos by opennetworkinglab.
the class CassiniTerminalDeviceDiscoveryOld method parseLogicalChannel.
/**
* Parses a component XML doc into a PortDescription.
*
* @param channel subtree to parse. It must be a component ot type PORT.
* case we need to check transceivers or optical channels.
*
* @return PortDescription or null if component does not have onos-index
*/
private PortDescription parseLogicalChannel(HierarchicalConfiguration channel) {
HierarchicalConfiguration config = channel.configurationAt("config");
String logicalChannelIndex = config.getString("index");
String description = config.getString("description");
String rateClass = config.getString("rate-class");
log.info("Parsing Component {} type {} rate {}", logicalChannelIndex, description, rateClass);
Map<String, String> annotations = new HashMap<>();
annotations.put(OdtnDeviceDescriptionDiscovery.OC_LOGICAL_CHANNEL, logicalChannelIndex);
annotations.put(OdtnDeviceDescriptionDiscovery.OC_NAME, description);
// Store all properties as port properties
// e.g. xe1/1
Pattern clientPattern = Pattern.compile("xe(\\d*)/1");
// e.g. oe1
Pattern linePattern = Pattern.compile("oe(\\d*)/(\\d*)");
Matcher clientMatch = clientPattern.matcher(description);
Matcher lineMatch = linePattern.matcher(description);
Pattern portSpeedPattern = Pattern.compile("TRIB_RATE_([0-9.]*)G");
Matcher portSpeedMatch = portSpeedPattern.matcher(rateClass);
Builder builder = DefaultPortDescription.builder();
if (portSpeedMatch.find()) {
Long speed = Long.parseLong(portSpeedMatch.group(1));
builder.portSpeed(speed * 1000);
}
if (clientMatch.find()) {
Long num = Long.parseLong(clientMatch.group(1));
Long portNum = 100 + num;
String connectionId = "connection:" + num.toString();
annotations.putIfAbsent(PORT_TYPE, OdtnPortType.CLIENT.value());
annotations.putIfAbsent(ONOS_PORT_INDEX, portNum.toString());
annotations.putIfAbsent(CONNECTION_ID, connectionId);
builder.withPortNumber(PortNumber.portNumber(portNum));
builder.type(Type.PACKET);
builder.annotations(DefaultAnnotations.builder().putAll(annotations).build());
return builder.build();
} else if (lineMatch.find()) {
Long num = (Long.parseLong(lineMatch.group(1)) - 1) * 2 + Long.parseLong(lineMatch.group(2));
Long portNum = 200 + num;
String connectionId = "connection:" + num.toString();
annotations.putIfAbsent(PORT_TYPE, OdtnPortType.LINE.value());
annotations.putIfAbsent(ONOS_PORT_INDEX, portNum.toString());
annotations.putIfAbsent(CONNECTION_ID, connectionId);
OchSignal signalId = OchSignal.newDwdmSlot(ChannelSpacing.CHL_50GHZ, 1);
return OchPortHelper.ochPortDescription(PortNumber.portNumber(portNum), true, // TODO Client signal to be discovered
OduSignalType.ODU4, true, signalId, DefaultAnnotations.builder().putAll(annotations).build());
} else {
log.warn("Unexpected component description: {}", description);
return null;
}
}
use of org.onosproject.net.device.DefaultPortDescription.Builder in project onos by opennetworkinglab.
the class AdvaTerminalDeviceDiscovery method parseLogicalChannel.
/**
* Parses a component XML doc into a PortDescription.
*
* @param channel subtree to parse. It must be a component ot type PORT.
* case we need to check transceivers or optical channels.
*
* @return PortDescription or null if component does not have onos-index
*/
private PortDescription parseLogicalChannel(HierarchicalConfiguration channel) {
HierarchicalConfiguration config = channel.configurationAt("config");
String logicalChannelIndex = config.getString("index");
String description = config.getString("description");
String rateClass = config.getString("rate-class");
log.info("Parsing Component {} type {} speed {}", logicalChannelIndex, description, rateClass);
Map<String, String> annotations = new HashMap<>();
annotations.put(OdtnDeviceDescriptionDiscovery.OC_LOGICAL_CHANNEL, logicalChannelIndex);
// Store all properties as port properties
// e.g. xe1/1
Pattern clientPattern = Pattern.compile("(\\d*)/(\\d*)/c(\\d)");
Pattern linePattern = Pattern.compile("(\\d*)/(\\d*)/n(\\d)");
Matcher clientMatch = clientPattern.matcher(description);
Matcher lineMatch = linePattern.matcher(description);
Pattern portSpeedPattern = Pattern.compile("TRIB_RATE_([0-9.]*)G");
Matcher portSpeedMatch = portSpeedPattern.matcher(rateClass);
Builder builder = DefaultPortDescription.builder();
if (portSpeedMatch.find()) {
Long speed = Long.parseLong(portSpeedMatch.group(1));
builder.portSpeed(speed * 1000);
}
if (clientMatch.find()) {
Long num = Long.parseLong(clientMatch.group(1));
Long portNum = 100 + num;
String connectionId = "connection:" + num.toString();
annotations.put(OdtnDeviceDescriptionDiscovery.OC_NAME, description);
annotations.putIfAbsent(PORT_TYPE, OdtnPortType.CLIENT.value());
annotations.putIfAbsent(ONOS_PORT_INDEX, portNum.toString());
annotations.putIfAbsent(CONNECTION_ID, connectionId);
builder.withPortNumber(PortNumber.portNumber(portNum));
builder.type(Type.PACKET);
builder.annotations(DefaultAnnotations.builder().putAll(annotations).build());
return builder.build();
} else if (lineMatch.find()) {
Long num = (Long.parseLong(lineMatch.group(1)) - 1) * 2 + Long.parseLong(lineMatch.group(2));
Long portNum = 200 + num;
String connectionId = "connection:" + num.toString();
description = description.substring(0, description.length() - 6);
annotations.putIfAbsent(PORT_TYPE, OdtnPortType.LINE.value());
annotations.putIfAbsent(ONOS_PORT_INDEX, portNum.toString());
annotations.putIfAbsent(CONNECTION_ID, connectionId);
annotations.put(OdtnDeviceDescriptionDiscovery.OC_NAME, "optch " + description);
OchSignal signalId = OchSignal.newDwdmSlot(ChannelSpacing.CHL_50GHZ, 1);
return OchPortHelper.ochPortDescription(PortNumber.portNumber(portNum), true, // TODO Client signal to be discovered
OduSignalType.ODU4, true, signalId, DefaultAnnotations.builder().putAll(annotations).build());
} else {
log.warn("Unexpected component description: {}", description);
return null;
}
}
use of org.onosproject.net.device.DefaultPortDescription.Builder in project onos by opennetworkinglab.
the class ZteDeviceDiscoveryImpl method toPortDescriptionInternal.
private PortDescription toPortDescriptionInternal(HierarchicalConfiguration component) {
Map<String, String> annotations = new HashMap<>();
String name = component.getString("name");
String type = component.getString("state/type");
annotations.put(OdtnDeviceDescriptionDiscovery.OC_NAME, name);
annotations.put(OdtnDeviceDescriptionDiscovery.OC_TYPE, type);
annotations.putIfAbsent(AnnotationKeys.PORT_NAME, name);
// PORT-1-4-C1
String[] textStr = name.split("-");
// use different value of portNumber on the same equipment
String portComponentIndex = textStr[textStr.length - 1];
int slotIndex = Integer.parseInt(textStr[2]);
int slotPortIndex = Integer.parseInt(portComponentIndex.substring(1));
int portNumber = slotIndex * 10 + slotPortIndex;
annotations.putIfAbsent(ONOS_PORT_INDEX, portComponentIndex);
annotations.putIfAbsent(CONNECTION_ID, "connection:" + Integer.parseInt(portComponentIndex.substring(1)));
if (portComponentIndex.charAt(0) == 'L') {
// line
annotations.putIfAbsent(PORT_TYPE, OdtnPortType.LINE.value());
OchSignal signalId = OchSignal.newDwdmSlot(ChannelSpacing.CHL_50GHZ, 1);
return OchPortHelper.ochPortDescription(PortNumber.portNumber(portNumber + 100L), true, OduSignalType.ODUC2, true, signalId, DefaultAnnotations.builder().putAll(annotations).build());
} else if (portComponentIndex.charAt(0) == 'C') {
// client
annotations.putIfAbsent(PORT_TYPE, OdtnPortType.CLIENT.value());
Builder builder = DefaultPortDescription.builder();
builder.withPortNumber(PortNumber.portNumber(portNumber)).isEnabled(true).portSpeed(100000L).type(Type.PACKET).annotations(DefaultAnnotations.builder().putAll(annotations).build());
return builder.build();
}
return null;
}
Aggregations