Search in sources :

Example 1 with Builder

use of org.onosproject.net.DefaultAnnotations.Builder in project onos by opennetworkinglab.

the class DeviceAnnotationOperator method combine.

@Override
public DeviceDescription combine(DeviceId deviceId, DeviceDescription descr, Optional<Config> prevConfig) {
    DeviceAnnotationConfig cfg = lookupConfig(deviceId);
    if (cfg == null) {
        return descr;
    }
    Map<String, String> annotations = cfg.annotations();
    Builder builder = DefaultAnnotations.builder();
    builder.putAll(descr.annotations());
    if (prevConfig.isPresent()) {
        DeviceAnnotationConfig prevDeviceAnnotationConfig = (DeviceAnnotationConfig) prevConfig.get();
        for (String key : prevDeviceAnnotationConfig.annotations().keySet()) {
            if (!annotations.containsKey(key)) {
                builder.remove(key);
            }
        }
    }
    builder.putAll(annotations);
    return DefaultDeviceDescription.copyReplacingAnnotation(descr, builder.build());
}
Also used : Builder(org.onosproject.net.DefaultAnnotations.Builder) DeviceAnnotationConfig(org.onosproject.net.config.basics.DeviceAnnotationConfig)

Example 2 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) {
    PortAnnotationConfig cfg = lookupConfig(cp);
    if (cfg == null) {
        return descr;
    }
    Map<String, String> annotations = cfg.annotations();
    if (annotations.isEmpty()) {
        return descr;
    }
    Builder builder = DefaultAnnotations.builder();
    builder.putAll(descr.annotations());
    builder.putAll(annotations);
    return DefaultPortDescription.builder(descr).annotations(builder.build()).build();
}
Also used : PortAnnotationConfig(org.onosproject.net.config.basics.PortAnnotationConfig) Builder(org.onosproject.net.DefaultAnnotations.Builder)

Example 3 with Builder

use of org.onosproject.net.DefaultAnnotations.Builder in project onos by opennetworkinglab.

the class OchPortHelper method ochPortDescription.

/**
 * Creates OCh port DefaultPortDescription based on the supplied information.
 *
 * @param number      port number
 * @param isEnabled   port enabled state
 * @param signalType  ODU signal type
 * @param isTunable   tunable wavelength capability
 * @param lambda      OCh signal
 * @param annotationsIn key/value annotations map
 * @return OCh port DefaultPortDescription with OCh annotations
 */
public static PortDescription ochPortDescription(PortNumber number, boolean isEnabled, OduSignalType signalType, boolean isTunable, OchSignal lambda, SparseAnnotations annotationsIn) {
    Builder builder = DefaultAnnotations.builder();
    builder.putAll(annotationsIn);
    builder.set(TUNABLE, String.valueOf(isTunable));
    builder.set(LAMBDA, OchSignalCodec.encode(lambda).toString());
    builder.set(SIGNAL_TYPE, signalType.toString());
    DefaultAnnotations annotations = builder.build();
    long portSpeed = signalType.bitRate();
    return DefaultPortDescription.builder().withPortNumber(number).isEnabled(isEnabled).type(Port.Type.OCH).portSpeed(portSpeed).annotations(annotations).build();
}
Also used : DefaultAnnotations(org.onosproject.net.DefaultAnnotations) Builder(org.onosproject.net.DefaultAnnotations.Builder)

Example 4 with Builder

use of org.onosproject.net.DefaultAnnotations.Builder in project onos by opennetworkinglab.

the class OduCltPortHelper method oduCltPortDescription.

/**
 * Creates ODU client port description based on the supplied information.
 *
 * @param number        port number
 * @param isEnabled     port enabled state
 * @param signalType    ODU client signal type
 * @param annotations   key/value annotations map
 * @return              port description
 */
public static PortDescription oduCltPortDescription(PortNumber number, boolean isEnabled, CltSignalType signalType, SparseAnnotations annotations) {
    Builder builder = DefaultAnnotations.builder();
    builder.putAll(annotations);
    builder.set(SIGNAL_TYPE, signalType.toString());
    long portSpeed = signalType.bitRate();
    return DefaultPortDescription.builder().withPortNumber(number).isEnabled(isEnabled).type(Port.Type.ODUCLT).portSpeed(portSpeed).annotations(builder.build()).build();
}
Also used : Builder(org.onosproject.net.DefaultAnnotations.Builder)

Example 5 with Builder

use of org.onosproject.net.DefaultAnnotations.Builder in project onos by opennetworkinglab.

the class OpenFlowDeviceProvider method buildPortStatistics.

private Collection<PortStatistics> buildPortStatistics(DeviceId deviceId, List<OFPortStatsEntry> entries) {
    HashSet<PortStatistics> stats = Sets.newHashSet();
    final Dpid dpid = dpid(deviceId.uri());
    OpenFlowSwitch sw = controller.getSwitch(dpid);
    for (OFPortStatsEntry entry : entries) {
        try {
            if (entry == null || entry.getPortNo() == null || entry.getPortNo().getPortNumber() < 0) {
                continue;
            }
            DefaultAnnotations.Builder annotations = DefaultAnnotations.builder();
            boolean propSupported = entry.getVersion().getWireVersion() >= OFVersion.OF_14.getWireVersion();
            Optional<OFPortStatsPropOptical> optical = propSupported ? entry.getProperties().stream().filter(OFPortStatsPropOptical.class::isInstance).map(OFPortStatsPropOptical.class::cast).findAny() : Optional.empty();
            if (optical.isPresent()) {
                long flags = optical.get().getFlags();
                boolean useFreq = false;
                for (OFPortDesc pd : sw.getPorts()) {
                    if (pd.getPortNo().equals(entry.getPortNo())) {
                        for (OFPortDescProp prop : pd.getProperties()) {
                            if (prop instanceof OFPortDescPropOptical) {
                                OFPortDescPropOptical oprop = (OFPortDescPropOptical) prop;
                                long supported = oprop.getSupported();
                                int useFreqVal = OFOpticalPortFeaturesSerializerVer14.USE_FREQ_VAL;
                                if ((supported & useFreqVal) != 0) {
                                    useFreq = true;
                                    break;
                                }
                            }
                        }
                    }
                }
                int txTune = OFPortStatsOpticalFlagsSerializerVer14.TX_TUNE_VAL;
                long txFreq = optical.get().getTxFreqLmda();
                long txOffset = optical.get().getTxOffset();
                long txGridSpan = optical.get().getTxGridSpan();
                annotations.set(AK_TX_TUNE_FEATURE, ((flags & txTune) != 0) ? "enabled" : "disabled");
                annotations.set(propertyFrequency ? AK_TX_FREQ_HZ : AK_TX_LMDA_NM, freqLmdaToAnnotation(txFreq, useFreq));
                annotations.set(propertyFrequency ? AK_TX_OFFSET_HZ : AK_TX_OFFSET_LMDA_NM, freqLmdaToAnnotation(txOffset, useFreq));
                annotations.set(propertyFrequency ? AK_TX_GRID_SPAN_HZ : AK_TX_GRID_SPAN_LMDA_NM, freqLmdaToAnnotation(txGridSpan, useFreq));
                int rxTune = OFPortStatsOpticalFlagsSerializerVer14.RX_TUNE_VAL;
                long rxFreq = optical.get().getRxFreqLmda();
                long rxOffset = optical.get().getRxOffset();
                long rxGridSpan = optical.get().getRxGridSpan();
                annotations.set(AK_RX_TUNE_FEATURE, ((flags & rxTune) != 0) ? "enabled" : "disabled");
                annotations.set(propertyFrequency ? AK_RX_FREQ_HZ : AK_RX_LMDA_NM, freqLmdaToAnnotation(rxFreq, useFreq));
                annotations.set(propertyFrequency ? AK_RX_OFFSET_HZ : AK_RX_OFFSET_LMDA_NM, freqLmdaToAnnotation(rxOffset, useFreq));
                annotations.set(propertyFrequency ? AK_RX_GRID_SPAN_HZ : AK_RX_GRID_SPAN_LMDA_NM, freqLmdaToAnnotation(rxGridSpan, useFreq));
                int txPwrVal = OFPortStatsOpticalFlagsSerializerVer14.TX_PWR_VAL;
                int txPwr = optical.get().getTxPwr();
                annotations.set(AK_TX_PWR_FEATURE, ((flags & txPwrVal) != 0) ? "enabled" : "disabled");
                annotations.set(AK_TX_PWR, Integer.toString(txPwr));
                int rxPwrVal = OFPortStatsOpticalFlagsSerializerVer14.RX_PWR_VAL;
                int rxPwr = optical.get().getRxPwr();
                annotations.set(AK_RX_PWR_FEATURE, ((flags & rxPwrVal) != 0) ? "enabled" : "disabled");
                annotations.set(AK_RX_PWR, Integer.toString(rxPwr));
                int txBias = OFPortStatsOpticalFlagsSerializerVer14.TX_BIAS_VAL;
                int biasCurrent = optical.get().getBiasCurrent();
                annotations.set(AK_TX_BIAS_FEATURE, ((flags & txBias) != 0) ? "enabled" : "disabled");
                annotations.set(AK_BIAS_CURRENT, Integer.toString(biasCurrent));
                int txTemp = OFPortStatsOpticalFlagsSerializerVer14.TX_TEMP_VAL;
                int temperature = optical.get().getTemperature();
                annotations.set(AK_TX_TEMP_FEATURE, ((flags & txTemp) != 0) ? "enabled" : "disabled");
                annotations.set(AK_TEMPERATURE, Integer.toString(temperature));
            }
            DefaultPortStatistics.Builder builder = DefaultPortStatistics.builder();
            DefaultPortStatistics stat = builder.setDeviceId(deviceId).setPort(PortNumber.portNumber(entry.getPortNo().getPortNumber())).setPacketsReceived(entry.getRxPackets().getValue()).setPacketsSent(entry.getTxPackets().getValue()).setBytesReceived(entry.getRxBytes().getValue()).setBytesSent(entry.getTxBytes().getValue()).setPacketsRxDropped(entry.getRxDropped().getValue()).setPacketsTxDropped(entry.getTxDropped().getValue()).setPacketsRxErrors(entry.getRxErrors().getValue()).setPacketsTxErrors(entry.getTxErrors().getValue()).setDurationSec(entry.getVersion() == OFVersion.OF_10 ? 0 : entry.getDurationSec()).setDurationNano(entry.getVersion() == OFVersion.OF_10 ? 0 : entry.getDurationNsec()).setAnnotations(annotations.build()).build();
            stats.add(stat);
        } catch (Exception e) {
            LOG.warn("Unable to process port stats", e);
        }
    }
    return Collections.unmodifiableSet(stats);
}
Also used : DefaultAnnotations(org.onosproject.net.DefaultAnnotations) DefaultPortStatistics(org.onosproject.net.device.DefaultPortStatistics) Builder(org.onosproject.net.DefaultAnnotations.Builder) Dpid(org.onosproject.openflow.controller.Dpid) OFPortDescProp(org.projectfloodlight.openflow.protocol.OFPortDescProp) OFPortStatsPropOptical(org.projectfloodlight.openflow.protocol.OFPortStatsPropOptical) DefaultPortStatistics(org.onosproject.net.device.DefaultPortStatistics) PortStatistics(org.onosproject.net.device.PortStatistics) OFPortDescPropOptical(org.projectfloodlight.openflow.protocol.OFPortDescPropOptical) OFPortDesc(org.projectfloodlight.openflow.protocol.OFPortDesc) OpenFlowSwitch(org.onosproject.openflow.controller.OpenFlowSwitch) OFPortStatsEntry(org.projectfloodlight.openflow.protocol.OFPortStatsEntry)

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