Search in sources :

Example 6 with Builder

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());
}
Also used : Builder(org.onosproject.net.DefaultAnnotations.Builder) HostAnnotationConfig(org.onosproject.net.config.basics.HostAnnotationConfig)

Example 7 with Builder

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();
}
Also used : PortAnnotationConfig(org.onosproject.net.config.basics.PortAnnotationConfig) HashMap(java.util.HashMap) Builder(org.onosproject.net.DefaultAnnotations.Builder)

Example 8 with Builder

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());
    }
}
Also used : Type(org.onosproject.net.Port.Type) Builder(org.onosproject.net.DefaultAnnotations.Builder) HashCodeBuilder(org.apache.commons.lang3.builder.HashCodeBuilder) EqualsBuilder(org.apache.commons.lang3.builder.EqualsBuilder) XmlConfigParser.loadXmlString(org.onosproject.drivers.utilities.XmlConfigParser.loadXmlString) PortNumber(org.onosproject.net.PortNumber) HierarchicalConfiguration(org.apache.commons.configuration.HierarchicalConfiguration)

Example 9 with Builder

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();
}
Also used : Builder(org.onosproject.net.DefaultAnnotations.Builder)

Example 10 with Builder

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();
}
Also used : Builder(org.onosproject.net.DefaultAnnotations.Builder)

Aggregations

Builder (org.onosproject.net.DefaultAnnotations.Builder)11 DefaultAnnotations (org.onosproject.net.DefaultAnnotations)2 PortAnnotationConfig (org.onosproject.net.config.basics.PortAnnotationConfig)2 HashMap (java.util.HashMap)1 HierarchicalConfiguration (org.apache.commons.configuration.HierarchicalConfiguration)1 EqualsBuilder (org.apache.commons.lang3.builder.EqualsBuilder)1 HashCodeBuilder (org.apache.commons.lang3.builder.HashCodeBuilder)1 XmlConfigParser.loadXmlString (org.onosproject.drivers.utilities.XmlConfigParser.loadXmlString)1 Type (org.onosproject.net.Port.Type)1 PortNumber (org.onosproject.net.PortNumber)1 DeviceAnnotationConfig (org.onosproject.net.config.basics.DeviceAnnotationConfig)1 HostAnnotationConfig (org.onosproject.net.config.basics.HostAnnotationConfig)1 DefaultPortStatistics (org.onosproject.net.device.DefaultPortStatistics)1 PortStatistics (org.onosproject.net.device.PortStatistics)1 Dpid (org.onosproject.openflow.controller.Dpid)1 OpenFlowSwitch (org.onosproject.openflow.controller.OpenFlowSwitch)1 OFPortDesc (org.projectfloodlight.openflow.protocol.OFPortDesc)1 OFPortDescProp (org.projectfloodlight.openflow.protocol.OFPortDescProp)1 OFPortDescPropOptical (org.projectfloodlight.openflow.protocol.OFPortDescPropOptical)1 OFPortStatsEntry (org.projectfloodlight.openflow.protocol.OFPortStatsEntry)1