Search in sources :

Example 16 with OpenFlowSwitch

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

Example 17 with OpenFlowSwitch

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

the class OpenFlowRuleProvider method applyRule.

private void applyRule(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)).buildFlowAdd());
    recordEvent(dpid);
}
Also used : Dpid(org.onosproject.openflow.controller.Dpid) OpenFlowSwitch(org.onosproject.openflow.controller.OpenFlowSwitch)

Example 18 with OpenFlowSwitch

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

the class OpenFlowControllerImpl method processPacket.

@Override
public void processPacket(Dpid dpid, OFMessage msg) {
    OpenFlowSwitch sw = this.getSwitch(dpid);
    if (log.isTraceEnabled()) {
        log.trace("Processing message from switch {} via openflow: {}", dpid, msg);
    }
    // Check if someone is waiting for this message
    ConcurrentMap<Long, CompletableFuture<OFMessage>> xids = responses.get(dpid);
    if (xids != null) {
        CompletableFuture<OFMessage> future = xids.remove(msg.getXid());
        if (future != null) {
            future.complete(msg);
        }
    }
    switch(msg.getType()) {
        case PORT_STATUS:
            for (OpenFlowSwitchListener l : ofSwitchListener) {
                l.portChanged(dpid, (OFPortStatus) msg);
            }
            break;
        case FEATURES_REPLY:
            for (OpenFlowSwitchListener l : ofSwitchListener) {
                l.switchChanged(dpid);
            }
            break;
        case PACKET_IN:
            if (sw == null) {
                log.error("Ignoring PACKET_IN, switch {} is not found", dpid);
                break;
            }
            OpenFlowPacketContext pktCtx = DefaultOpenFlowPacketContext.packetContextFromPacketIn(sw, (OFPacketIn) msg);
            for (PacketListener p : ofPacketListener.values()) {
                p.handlePacket(pktCtx);
            }
            break;
        // ie. Back to back error could cause us to starve.
        case FLOW_REMOVED:
            executorMsgs.execute(new OFMessageHandler(dpid, msg));
            break;
        case ERROR:
            log.debug("Received error message from {}: {}", dpid, msg);
            errorMsgs.putIfAbsent(msg.getXid(), true);
            executorErrorMsgs.execute(new OFMessageHandler(dpid, msg));
            break;
        case STATS_REPLY:
            processStatsReply(dpid, (OFStatsReply) msg);
            break;
        case BARRIER_REPLY:
            if (errorMsgs.containsKey(msg.getXid())) {
                // To make oferror msg handling and corresponding barrier reply serialized,
                // executorErrorMsgs is used for both transaction
                errorMsgs.remove(msg.getXid());
                executorErrorMsgs.execute(new OFMessageHandler(dpid, msg));
            } else {
                executorBarrier.execute(new OFMessageHandler(dpid, msg));
            }
            break;
        case EXPERIMENTER:
            if (sw == null) {
                log.error("Switch {} is not found", dpid);
                break;
            }
            long experimenter = ((OFExperimenter) msg).getExperimenter();
            if (experimenter == 0x748771) {
                // LINC-OE port stats
                OFCircuitPortStatus circuitPortStatus = (OFCircuitPortStatus) msg;
                OFPortStatus.Builder portStatus = sw.factory().buildPortStatus();
                OFPortDesc.Builder portDesc = sw.factory().buildPortDesc();
                portDesc.setPortNo(circuitPortStatus.getPortNo()).setHwAddr(circuitPortStatus.getHwAddr()).setName(circuitPortStatus.getName()).setConfig(circuitPortStatus.getConfig()).setState(circuitPortStatus.getState());
                portStatus.setReason(circuitPortStatus.getReason()).setDesc(portDesc.build());
                for (OpenFlowSwitchListener l : ofSwitchListener) {
                    l.portChanged(dpid, portStatus.build());
                }
            } else {
                log.warn("Handling experimenter type {} not yet implemented", ((OFExperimenter) msg).getExperimenter(), msg);
            }
            break;
        default:
            log.warn("Handling message type {} not yet implemented {}", msg.getType(), msg);
    }
}
Also used : OpenFlowSwitchListener(org.onosproject.openflow.controller.OpenFlowSwitchListener) OFCircuitPortStatus(org.projectfloodlight.openflow.protocol.OFCircuitPortStatus) OFMessage(org.projectfloodlight.openflow.protocol.OFMessage) PacketListener(org.onosproject.openflow.controller.PacketListener) OFPortStatus(org.projectfloodlight.openflow.protocol.OFPortStatus) OpenFlowPacketContext(org.onosproject.openflow.controller.OpenFlowPacketContext) DefaultOpenFlowPacketContext(org.onosproject.openflow.controller.DefaultOpenFlowPacketContext) CompletableFuture(java.util.concurrent.CompletableFuture) OFExperimenter(org.projectfloodlight.openflow.protocol.OFExperimenter) OFPortDesc(org.projectfloodlight.openflow.protocol.OFPortDesc) OpenFlowSwitch(org.onosproject.openflow.controller.OpenFlowSwitch)

Example 19 with OpenFlowSwitch

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

the class OpenFlowRuleProvider method executeBatch.

@Override
public void executeBatch(FlowRuleBatchOperation batch) {
    checkNotNull(batch);
    Dpid dpid = Dpid.dpid(batch.deviceId().uri());
    OpenFlowSwitch sw = controller.getSwitch(dpid);
    // If switch no longer exists, simply return.
    if (sw == null) {
        Set<FlowRule> failures = ImmutableSet.copyOf(Lists.transform(batch.getOperations(), e -> e.target()));
        providerService.batchOperationCompleted(batch.id(), new CompletedBatchOperation(false, failures, batch.deviceId()));
        return;
    }
    pendingBatches.put(batch.id(), new InternalCacheEntry(batch));
    // Build a batch of flow mods - to reduce the number i/o asked to the SO
    Set<OFFlowMod> mods = Sets.newHashSet();
    OFFlowMod mod;
    for (FlowRuleBatchEntry fbe : batch.getOperations()) {
        FlowModBuilder builder = FlowModBuilder.builder(fbe.target(), sw.factory(), Optional.of(batch.id()), Optional.of(driverService));
        switch(fbe.operator()) {
            case ADD:
                mod = builder.buildFlowAdd();
                break;
            case REMOVE:
                mod = builder.buildFlowDel();
                break;
            case MODIFY:
                mod = builder.buildFlowMod();
                break;
            default:
                log.error("Unsupported batch operation {}; skipping flowmod {}", fbe.operator(), fbe);
                continue;
        }
        mods.add(mod);
    }
    // Build a list to mantain the order
    List<OFMessage> modsTosend = Lists.newArrayList(mods);
    OFBarrierRequest.Builder builder = sw.factory().buildBarrierRequest().setXid(batch.id());
    // Adds finally the barrier request
    modsTosend.add(builder.build());
    sw.sendMsg(modsTosend);
    // Take into account also the barrier request
    recordEvents(dpid, (batch.getOperations().size() + 1));
}
Also used : FlowRuleBatchOperation(org.onosproject.net.flow.oldbatch.FlowRuleBatchOperation) CompletedBatchOperation(org.onosproject.net.flow.CompletedBatchOperation) U64(org.projectfloodlight.openflow.types.U64) OFStatsReply(org.projectfloodlight.openflow.protocol.OFStatsReply) DefaultTableStatisticsEntry(org.onosproject.net.flow.DefaultTableStatisticsEntry) Tools.groupedThreads(org.onlab.util.Tools.groupedThreads) FlowEntry(org.onosproject.net.flow.FlowEntry) DefaultLoad(org.onosproject.net.statistic.DefaultLoad) TableStatisticsEntry(org.onosproject.net.flow.TableStatisticsEntry) DefaultDriverData(org.onosproject.net.driver.DefaultDriverData) DriverService(org.onosproject.net.driver.DriverService) POLL_FREQUENCY_DEFAULT(org.onosproject.provider.of.flow.impl.OsgiPropertyConstants.POLL_FREQUENCY_DEFAULT) Unpooled(io.netty.buffer.Unpooled) FlowRuleProviderRegistry(org.onosproject.net.flow.FlowRuleProviderRegistry) Executors.newScheduledThreadPool(java.util.concurrent.Executors.newScheduledThreadPool) DefaultDriverHandler(org.onosproject.net.driver.DefaultDriverHandler) Map(java.util.Map) OFMessage(org.projectfloodlight.openflow.protocol.OFMessage) POLL_FREQUENCY(org.onosproject.provider.of.flow.impl.OsgiPropertyConstants.POLL_FREQUENCY) Driver(org.onosproject.net.driver.Driver) Dpid(org.onosproject.openflow.controller.Dpid) ADAPTIVE_FLOW_SAMPLING_DEFAULT(org.onosproject.provider.of.flow.impl.OsgiPropertyConstants.ADAPTIVE_FLOW_SAMPLING_DEFAULT) Tools.get(org.onlab.util.Tools.get) ImmutableSet(com.google.common.collect.ImmutableSet) IndexTableId(org.onosproject.net.flow.IndexTableId) Deactivate(org.osgi.service.component.annotations.Deactivate) Set(java.util.Set) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) OFBadRequestCode(org.projectfloodlight.openflow.protocol.OFBadRequestCode) FlowEntryBuilder(org.onosproject.provider.of.flow.util.FlowEntryBuilder) OFBadMatchErrorMsg(org.projectfloodlight.openflow.protocol.errormsg.OFBadMatchErrorMsg) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) OpenFlowEventListener(org.onosproject.openflow.controller.OpenFlowEventListener) OFBadRequestErrorMsg(org.projectfloodlight.openflow.protocol.errormsg.OFBadRequestErrorMsg) OFFlowModFailedErrorMsg(org.projectfloodlight.openflow.protocol.errormsg.OFFlowModFailedErrorMsg) FlowRuleBatchEntry(org.onosproject.net.flow.oldbatch.FlowRuleBatchEntry) ADAPTIVE_FLOW_SAMPLING(org.onosproject.provider.of.flow.impl.OsgiPropertyConstants.ADAPTIVE_FLOW_SAMPLING) Objects(java.util.Objects) List(java.util.List) FlowRuleProvider(org.onosproject.net.flow.FlowRuleProvider) FlowRule(org.onosproject.net.flow.FlowRule) Optional(java.util.Optional) CacheBuilder(com.google.common.cache.CacheBuilder) DeviceId(org.onosproject.net.DeviceId) OFType(org.projectfloodlight.openflow.protocol.OFType) Dictionary(java.util.Dictionary) OFVersion(org.projectfloodlight.openflow.protocol.OFVersion) OFPortStatus(org.projectfloodlight.openflow.protocol.OFPortStatus) OpenFlowSwitchListener(org.onosproject.openflow.controller.OpenFlowSwitchListener) ComponentContext(org.osgi.service.component.ComponentContext) Strings.isNullOrEmpty(com.google.common.base.Strings.isNullOrEmpty) OFFlowLightweightStatsReply(org.projectfloodlight.openflow.protocol.OFFlowLightweightStatsReply) POLL_STATS_PERIODICALLY_DEFAULT(org.onosproject.provider.of.flow.impl.OsgiPropertyConstants.POLL_STATS_PERIODICALLY_DEFAULT) Component(org.osgi.service.component.annotations.Component) Lists(com.google.common.collect.Lists) ByteBuf(io.netty.buffer.ByteBuf) OFFlowRemoved(org.projectfloodlight.openflow.protocol.OFFlowRemoved) OFCapabilities(org.projectfloodlight.openflow.protocol.OFCapabilities) OFTableStatsReply(org.projectfloodlight.openflow.protocol.OFTableStatsReply) OFFlowStatsReply(org.projectfloodlight.openflow.protocol.OFFlowStatsReply) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Activate(org.osgi.service.component.annotations.Activate) OFErrorMsg(org.projectfloodlight.openflow.protocol.OFErrorMsg) OFBarrierRequest(org.projectfloodlight.openflow.protocol.OFBarrierRequest) OFBadActionErrorMsg(org.projectfloodlight.openflow.protocol.errormsg.OFBadActionErrorMsg) OFBadInstructionErrorMsg(org.projectfloodlight.openflow.protocol.errormsg.OFBadInstructionErrorMsg) ComponentConfigService(org.onosproject.cfg.ComponentConfigService) AbstractProvider(org.onosproject.net.provider.AbstractProvider) RemovalNotification(com.google.common.cache.RemovalNotification) Logger(org.slf4j.Logger) OFStatsType(org.projectfloodlight.openflow.protocol.OFStatsType) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) RoleState(org.onosproject.openflow.controller.RoleState) ProviderId(org.onosproject.net.provider.ProviderId) Maps(com.google.common.collect.Maps) OpenFlowController(org.onosproject.openflow.controller.OpenFlowController) OpenFlowSwitch(org.onosproject.openflow.controller.OpenFlowSwitch) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) TimeUnit(java.util.concurrent.TimeUnit) DriverHandler(org.onosproject.net.driver.DriverHandler) POLL_STATS_PERIODICALLY(org.onosproject.provider.of.flow.impl.OsgiPropertyConstants.POLL_STATS_PERIODICALLY) RemovalCause(com.google.common.cache.RemovalCause) OFFlowMod(org.projectfloodlight.openflow.protocol.OFFlowMod) Modified(org.osgi.service.component.annotations.Modified) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) OFTableStatsEntry(org.projectfloodlight.openflow.protocol.OFTableStatsEntry) FlowRuleProviderService(org.onosproject.net.flow.FlowRuleProviderService) U16(org.projectfloodlight.openflow.types.U16) Cache(com.google.common.cache.Cache) Reference(org.osgi.service.component.annotations.Reference) Collections(java.util.Collections) OFMessage(org.projectfloodlight.openflow.protocol.OFMessage) Dpid(org.onosproject.openflow.controller.Dpid) FlowRuleBatchEntry(org.onosproject.net.flow.oldbatch.FlowRuleBatchEntry) CompletedBatchOperation(org.onosproject.net.flow.CompletedBatchOperation) OpenFlowSwitch(org.onosproject.openflow.controller.OpenFlowSwitch) OFBarrierRequest(org.projectfloodlight.openflow.protocol.OFBarrierRequest) FlowRule(org.onosproject.net.flow.FlowRule) OFFlowMod(org.projectfloodlight.openflow.protocol.OFFlowMod)

Example 20 with OpenFlowSwitch

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

the class OpenFlowRuleProvider method triggerStatsCollection.

private void triggerStatsCollection(Dpid dpid) {
    OpenFlowSwitch sw = controller.getSwitch(dpid);
    if (sw == null) {
        return;
    }
    SwitchDataCollector sdc = adaptiveFlowSampling ? afsCollectors.get(dpid) : simpleCollectors.get(dpid);
    if (sdc == null) {
        if (adaptiveFlowSampling) {
            sdc = new NewAdaptiveFlowStatsCollector(driverService, sw, -1);
            afsCollectors.put(dpid, (NewAdaptiveFlowStatsCollector) sdc);
        } else {
            sdc = new FlowStatsCollector(executorService, sw, -1);
            simpleCollectors.put(dpid, (FlowStatsCollector) sdc);
        }
    }
    sdc.start();
    TableStatisticsCollector tsc = tableStatsCollectors.get(dpid);
    if (tsc == null) {
        tsc = new TableStatisticsCollector(executorService, sw, -1);
        tableStatsCollectors.put(dpid, tsc);
    }
    tsc.start();
}
Also used : OpenFlowSwitch(org.onosproject.openflow.controller.OpenFlowSwitch)

Aggregations

OpenFlowSwitch (org.onosproject.openflow.controller.OpenFlowSwitch)29 Dpid (org.onosproject.openflow.controller.Dpid)17 OpenFlowController (org.onosproject.openflow.controller.OpenFlowController)5 DeviceId (org.onosproject.net.DeviceId)4 OFPortDesc (org.projectfloodlight.openflow.protocol.OFPortDesc)4 Test (org.junit.Test)3 OpenFlowSwitchListener (org.onosproject.openflow.controller.OpenFlowSwitchListener)3 ArrayList (java.util.ArrayList)2 Type (org.onosproject.net.Device.Type)2 ExtensionTreatmentType (org.onosproject.net.flow.instructions.ExtensionTreatmentType)2 PortDescPropertyType (org.onosproject.openflow.controller.PortDescPropertyType)2 OFFlowLightweightStatsReply (org.projectfloodlight.openflow.protocol.OFFlowLightweightStatsReply)2 OFFlowStatsReply (org.projectfloodlight.openflow.protocol.OFFlowStatsReply)2 OFTableStatsEntry (org.projectfloodlight.openflow.protocol.OFTableStatsEntry)2 OFTableStatsReply (org.projectfloodlight.openflow.protocol.OFTableStatsReply)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