use of org.onosproject.net.Port.Type in project onos by opennetworkinglab.
the class TextBlockParserCisco method findPortInfo.
/**
* Creates the port information object.
* @param interfaceTree the interfaces as plain text
* @return the Port description object
*/
private static DefaultPortDescription findPortInfo(String interfaceTree) {
String[] textStr = interfaceTree.split(NEWLINE_SPLITTER);
String[] firstLine = textStr[0].split(SPACE);
String firstWord = firstLine[0];
Type type = getPortType(textStr);
boolean isEnabled = getIsEnabled(textStr);
String port = getPort(textStr);
long portSpeed = getPortSpeed(textStr);
DefaultAnnotations.Builder annotations = DefaultAnnotations.builder().set(AnnotationKeys.PORT_NAME, firstWord);
return "-1".equals(port) ? null : DefaultPortDescription.builder().withPortNumber(PortNumber.portNumber(port)).isEnabled(isEnabled).type(type).portSpeed(portSpeed).annotations(annotations.build()).build();
}
use of org.onosproject.net.Port.Type in project onos by opennetworkinglab.
the class PortCodec method decode.
/**
* {@inheritDoc}
*
* Note: Result of {@link Port#element()} returned Port object,
* is not a full Device object.
* Only it's DeviceId can be used.
*/
@Override
public Port decode(ObjectNode json, CodecContext context) {
if (json == null || !json.isObject()) {
return null;
}
DeviceId did = DeviceId.deviceId(json.get(ELEMENT).asText());
Device device = new DummyDevice(did);
PortNumber number = portNumber(json.get(PORT_NAME).asText());
boolean isEnabled = json.get(IS_ENABLED).asBoolean();
Type type = Type.valueOf(json.get(TYPE).asText().toUpperCase());
long portSpeed = json.get(PORT_SPEED).asLong();
Annotations annotations = extractAnnotations(json, context);
return new DefaultPort(device, number, isEnabled, type, portSpeed, annotations);
}
use of org.onosproject.net.Port.Type in project onos by opennetworkinglab.
the class JuniperUtils method parsePhysicalInterface.
/**
* Parses {@literal physical-interface} tree.
*
* @param portDescriptions list to populate Ports found parsing configuration
* @param phyIntf physical-interface
*/
private static void parsePhysicalInterface(List<PortDescription> portDescriptions, HierarchicalConfiguration phyIntf) {
Builder annotations = DefaultAnnotations.builder();
PortNumber portNumber = portNumber(phyIntf.getString(SNMP_INDEX));
String phyPortName = phyIntf.getString(NAME);
if (portNumber == null) {
log.debug("Skipping physical-interface {}, no PortNumer", phyPortName);
log.trace(" {}", phyIntf);
return;
}
setIfNonNull(annotations, AnnotationKeys.PORT_NAME, phyPortName);
setIfNonNull(annotations, AnnotationKeys.PORT_MAC, phyIntf.getString("current-physical-address"));
setIfNonNull(annotations, AK_IF_TYPE, phyIntf.getString(IF_TYPE));
setIfNonNull(annotations, AK_DESCRIPTION, phyIntf.getString("description"));
boolean opUp = phyIntf.getString("oper-status", "down").equals("up");
annotations.set(AK_OPER_STATUS, toUpDown(opUp));
boolean admUp = phyIntf.getString("admin-status", "down").equals("up");
annotations.set(AK_ADMIN_STATUS, toUpDown(admUp));
long portSpeed = toMbps(phyIntf.getString(SPEED));
Type portType = phyIntf.getString(IF_MEDIA_TYPE, COPPER).equalsIgnoreCase(FIBER) ? Type.FIBER : Type.COPPER;
portDescriptions.add(DefaultPortDescription.builder().withPortNumber(portNumber).isEnabled(admUp && opUp).type(portType).portSpeed(portSpeed).annotations(annotations.build()).build());
// parse each logical Interface
for (HierarchicalConfiguration logIntf : phyIntf.configurationsAt("logical-interface")) {
if (logIntf == null) {
continue;
}
PortNumber lPortNumber = safePortNumber(logIntf.getString(SNMP_INDEX));
if (lPortNumber == null) {
log.debug("Skipping logical-interface {} under {}, no PortNumer", logIntf.getString(NAME), phyPortName);
log.trace(" {}", logIntf);
continue;
}
Builder lannotations = DefaultAnnotations.builder();
setIfNonNull(lannotations, AnnotationKeys.PORT_NAME, logIntf.getString(NAME));
setIfNonNull(lannotations, AK_PHYSICAL_PORT_NAME, phyPortName);
String afName = logIntf.getString("address-family.address-family-name");
String address = logIntf.getString("address-family.interface-address.ifa-local");
if (afName != null && address != null) {
// e.g., inet : IPV4, inet6 : IPV6
setIfNonNull(lannotations, afName, address);
}
// preserving former behavior
setIfNonNull(lannotations, AK_IP, logIntf.getString("address-family.interface-address.ifa-local"));
setIfNonNull(lannotations, AK_ENCAPSULATION, logIntf.getString("encapsulation"));
// TODO confirm if this is correct.
// Looking at sample data,
// it seemed all logical loop-back interfaces were down
boolean lEnabled = logIntf.getString("if-config-flags.iff-up") != null;
portDescriptions.add(DefaultPortDescription.builder().withPortNumber(lPortNumber).isEnabled(admUp && opUp && lEnabled).type(portType).portSpeed(portSpeed).annotations(lannotations.build()).build());
}
}
use of org.onosproject.net.Port.Type 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