use of org.onosproject.net.DefaultAnnotations.Builder in project onos by opennetworkinglab.
the class HostAnnotationOperator method combine.
@Override
public HostDescription combine(HostId hostId, HostDescription descr, Optional<Config> prevConfig) {
HostAnnotationConfig cfg = lookupConfig(hostId);
if (cfg == null) {
return descr;
}
Map<String, String> annotations = cfg.annotations();
Builder builder = DefaultAnnotations.builder();
builder.putAll(descr.annotations());
if (prevConfig.isPresent()) {
HostAnnotationConfig prevHostAnnotationConfig = (HostAnnotationConfig) prevConfig.get();
for (String key : prevHostAnnotationConfig.annotations().keySet()) {
if (!annotations.containsKey(key)) {
builder.remove(key);
}
}
}
builder.putAll(annotations);
return DefaultHostDescription.copyReplacingAnnotation(descr, builder.build());
}
use of org.onosproject.net.DefaultAnnotations.Builder in project onos by opennetworkinglab.
the class PortAnnotationOperator method combine.
@Override
public PortDescription combine(ConnectPoint cp, PortDescription descr, Optional<Config> prevConfig) {
PortAnnotationConfig cfg = lookupConfig(cp);
Map<String, String> annotations = new HashMap<>();
if (cfg != null) {
annotations.putAll(cfg.annotations());
}
Builder builder = DefaultAnnotations.builder();
builder.putAll(descr.annotations());
if (prevConfig.isPresent()) {
PortAnnotationConfig prevDeviceAnnotationConfig = (PortAnnotationConfig) prevConfig.get();
for (String key : prevDeviceAnnotationConfig.annotations().keySet()) {
if (!annotations.containsKey(key)) {
builder.remove(key);
}
}
}
builder.putAll(annotations);
return DefaultPortDescription.builder(descr).annotations(builder.build()).build();
}
use of org.onosproject.net.DefaultAnnotations.Builder 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.DefaultAnnotations.Builder in project onos by opennetworkinglab.
the class OmsPortHelper method omsPortDescription.
/**
* Creates OMS port description based on the supplied information.
*
* @param number port number
* @param isEnabled port enabled state
* @param minFrequency minimum frequency
* @param maxFrequency maximum frequency
* @param grid grid spacing frequency
* @param annotations key/value annotations map
* @return port description
*/
public static PortDescription omsPortDescription(PortNumber number, boolean isEnabled, Frequency minFrequency, Frequency maxFrequency, Frequency grid, SparseAnnotations annotations) {
Builder builder = DefaultAnnotations.builder();
builder.putAll(annotations);
builder.set(OpticalAnnotations.MIN_FREQ_HZ, String.valueOf(minFrequency.asHz()));
builder.set(OpticalAnnotations.MAX_FREQ_HZ, String.valueOf(maxFrequency.asHz()));
builder.set(OpticalAnnotations.GRID_HZ, String.valueOf(grid.asHz()));
long portSpeed = 0;
return DefaultPortDescription.builder().withPortNumber(number).isEnabled(isEnabled).type(Port.Type.OMS).portSpeed(portSpeed).annotations(builder.build()).build();
}
use of org.onosproject.net.DefaultAnnotations.Builder in project onos by opennetworkinglab.
the class OtuPortHelper method otuPortDescription.
/**
* Creates OTU port description based on the supplied information.
*
* @param number port number
* @param isEnabled port enabled state
* @param signalType OTU client signal type
* @param annotations key/value annotations map
* @return port description
*/
public static PortDescription otuPortDescription(PortNumber number, boolean isEnabled, OtuSignalType signalType, SparseAnnotations annotations) {
Builder builder = DefaultAnnotations.builder();
builder.putAll(annotations);
builder.set(SIGNAL_TYPE, signalType.toString());
// TODO specify appropriate value?
long portSpeed = 0;
return DefaultPortDescription.builder().withPortNumber(number).isEnabled(isEnabled).type(Port.Type.OTU).portSpeed(portSpeed).annotations(builder.build()).build();
}
Aggregations