Search in sources :

Example 11 with Dpid

use of org.onosproject.openflow.controller.Dpid in project onos by opennetworkinglab.

the class OplinkHandshakerUtil method getNeighbor.

private OplinkPortAdjacency getNeighbor(OFExpPortAdjacency ad) {
    // Check input parameter
    if (ad == null) {
        return null;
    }
    // Get adjacency properties
    for (OFExpPortAdjacencyId adid : ad.getProperties()) {
        List<OFExpExtAdId> otns = adid.getAdId();
        if (otns != null && otns.size() > 0) {
            OFExpPortAdidOtn otn = (OFExpPortAdidOtn) otns.get(0);
            // ITU-T G.7714 ETH MAC Format (in second 16 bytes of the following)
            // |---------------------------------------------------------------------------|
            // | Other format (16 bytes)                                                   |
            // |---------------------------------------------------------------------------|
            // | Header (2 bytes) | ID (4 BITS) | MAC (6 bytes) | Port (4 bytes) | Unused  |
            // |---------------------------------------------------------------------------|
            ByteBuf buffer = Unpooled.buffer(OPSPEC_BYTES);
            otn.getOpspec().write32Bytes(buffer);
            long mac = buffer.getLong(OPSPEC_MAC_POS) << OPSPEC_ID_BITS >>> OPSPEC_MAC_BIT_OFF;
            int port = (int) (buffer.getLong(OPSPEC_PORT_POS) << OPSPEC_ID_BITS >>> OPSPEC_PORT_BIT_OFF);
            // constructed from MAC address
            return new OplinkPortAdjacency(DeviceId.deviceId(Dpid.uri(new Dpid(mac))), PortNumber.portNumber(port));
        }
    }
    // Returns null if no properties found
    return null;
}
Also used : Dpid(org.onosproject.openflow.controller.Dpid) OFExpExtAdId(org.projectfloodlight.openflow.protocol.OFExpExtAdId) OFExpPortAdidOtn(org.projectfloodlight.openflow.protocol.OFExpPortAdidOtn) OFExpPortAdjacencyId(org.projectfloodlight.openflow.protocol.OFExpPortAdjacencyId) ByteBuf(io.netty.buffer.ByteBuf) ConnectPoint(org.onosproject.net.ConnectPoint)

Example 12 with Dpid

use of org.onosproject.openflow.controller.Dpid in project onos by opennetworkinglab.

the class OplinkPowerConfigUtil method getOpenFlowDevice.

/**
 * Returns current switch known to this OF controller.
 *
 * @return current switch
 */
private OpenFlowSwitch getOpenFlowDevice() {
    final DriverHandler handler = behaviour.handler();
    final OpenFlowController controller = handler.get(OpenFlowController.class);
    final Dpid dpid = Dpid.dpid(handler.data().deviceId().uri());
    OpenFlowSwitch sw = controller.getSwitch(dpid);
    if (sw == null || !sw.isConnected()) {
        log.warn("OpenFlow handshaker driver not found or device is not connected, dpid = {}", dpid);
        return null;
    }
    return sw;
}
Also used : Dpid(org.onosproject.openflow.controller.Dpid) OpenFlowSwitch(org.onosproject.openflow.controller.OpenFlowSwitch) DriverHandler(org.onosproject.net.driver.DriverHandler) OpenFlowController(org.onosproject.openflow.controller.OpenFlowController)

Example 13 with Dpid

use of org.onosproject.openflow.controller.Dpid in project onos by opennetworkinglab.

the class OpenFlowRuleProvider method removeRule.

private void removeRule(FlowRule flowRule) {
    Dpid dpid = Dpid.dpid(flowRule.deviceId().uri());
    OpenFlowSwitch sw = controller.getSwitch(dpid);
    if (sw == null) {
        return;
    }
    sw.sendMsg(FlowModBuilder.builder(flowRule, sw.factory(), Optional.empty(), Optional.of(driverService)).buildFlowDel());
    recordEvent(dpid);
}
Also used : Dpid(org.onosproject.openflow.controller.Dpid) OpenFlowSwitch(org.onosproject.openflow.controller.OpenFlowSwitch)

Example 14 with Dpid

use of org.onosproject.openflow.controller.Dpid 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)

Example 15 with Dpid

use of org.onosproject.openflow.controller.Dpid in project onos by opennetworkinglab.

the class OpenFlowDeviceProvider method triggerProbe.

@Override
public void triggerProbe(DeviceId deviceId) {
    LOG.debug("Triggering probe on device {}", deviceId);
    final Dpid dpid = dpid(deviceId.uri());
    OpenFlowSwitch sw = controller.getSwitch(dpid);
    if (sw == null || !sw.isConnected()) {
        LOG.error("Failed to probe device {} on sw={}", deviceId, sw);
        providerService.deviceDisconnected(deviceId);
        return;
    } else {
        LOG.trace("Confirmed device {} connection", deviceId);
    }
    // Prompt an update of port information. We can use any XID for this.
    OFFactory fact = sw.factory();
    switch(fact.getVersion()) {
        case OF_10:
            sw.sendMsg(fact.buildFeaturesRequest().setXid(0).build());
            break;
        case OF_13:
        case OF_14:
        case OF_15:
            sw.sendMsg(fact.buildPortDescStatsRequest().setXid(0).build());
            break;
        default:
            LOG.warn("Unhandled protocol version");
    }
}
Also used : Dpid(org.onosproject.openflow.controller.Dpid) OpenFlowSwitch(org.onosproject.openflow.controller.OpenFlowSwitch) OFFactory(org.projectfloodlight.openflow.protocol.OFFactory)

Aggregations

Dpid (org.onosproject.openflow.controller.Dpid)22 OpenFlowSwitch (org.onosproject.openflow.controller.OpenFlowSwitch)17 OpenFlowController (org.onosproject.openflow.controller.OpenFlowController)5 DeviceId (org.onosproject.net.DeviceId)4 GroupId (org.onosproject.core.GroupId)3 OFPortDesc (org.projectfloodlight.openflow.protocol.OFPortDesc)3 ByteBuf (io.netty.buffer.ByteBuf)2 DefaultDriverData (org.onosproject.net.driver.DefaultDriverData)2 DefaultDriverHandler (org.onosproject.net.driver.DefaultDriverHandler)2 Driver (org.onosproject.net.driver.Driver)2 DriverHandler (org.onosproject.net.driver.DriverHandler)2 GroupBuckets (org.onosproject.net.group.GroupBuckets)2 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 Strings.isNullOrEmpty (com.google.common.base.Strings.isNullOrEmpty)1 Cache (com.google.common.cache.Cache)1 CacheBuilder (com.google.common.cache.CacheBuilder)1 RemovalCause (com.google.common.cache.RemovalCause)1 RemovalNotification (com.google.common.cache.RemovalNotification)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Lists (com.google.common.collect.Lists)1