Search in sources :

Example 11 with FlowRuleBatchEntry

use of org.onosproject.net.flow.oldbatch.FlowRuleBatchEntry 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 12 with FlowRuleBatchEntry

use of org.onosproject.net.flow.oldbatch.FlowRuleBatchEntry in project onos by opennetworkinglab.

the class ECFlowRuleStore method storeBatchInternal.

private void storeBatchInternal(FlowRuleBatchOperation operation) {
    final DeviceId did = operation.deviceId();
    // final Collection<FlowEntry> ft = flowTable.getFlowEntries(did);
    Set<FlowRuleBatchEntry> currentOps = updateStoreInternal(operation);
    if (currentOps.isEmpty()) {
        batchOperationComplete(FlowRuleBatchEvent.completed(new FlowRuleBatchRequest(operation.id(), Collections.emptySet()), new CompletedBatchOperation(true, Collections.emptySet(), did)));
        return;
    }
    notifyDelegate(FlowRuleBatchEvent.requested(new FlowRuleBatchRequest(operation.id(), currentOps), operation.deviceId()));
}
Also used : DeviceId(org.onosproject.net.DeviceId) FlowRuleBatchEntry(org.onosproject.net.flow.oldbatch.FlowRuleBatchEntry) CompletedBatchOperation(org.onosproject.net.flow.CompletedBatchOperation) FlowRuleBatchRequest(org.onosproject.net.flow.oldbatch.FlowRuleBatchRequest)

Example 13 with FlowRuleBatchEntry

use of org.onosproject.net.flow.oldbatch.FlowRuleBatchEntry in project onos by opennetworkinglab.

the class NullFlowRuleProvider method executeBatch.

@Override
public void executeBatch(FlowRuleBatchOperation batch) {
    // TODO: consider checking mastership
    Set<FlowEntry> entries = flowTable.getOrDefault(batch.deviceId(), Sets.newConcurrentHashSet());
    for (FlowRuleBatchEntry fbe : batch.getOperations()) {
        switch(fbe.operator()) {
            case ADD:
                entries.add(new DefaultFlowEntry(fbe.target()));
                break;
            case REMOVE:
                entries.remove(new DefaultFlowEntry(fbe.target()));
                break;
            case MODIFY:
                FlowEntry entry = new DefaultFlowEntry(fbe.target());
                entries.remove(entry);
                entries.add(entry);
                break;
            default:
                log.error("Unknown flow operation: {}", fbe);
        }
    }
    flowTable.put(batch.deviceId(), entries);
    CompletedBatchOperation op = new CompletedBatchOperation(true, Collections.emptySet(), batch.deviceId());
    providerService.batchOperationCompleted(batch.id(), op);
}
Also used : DefaultFlowEntry(org.onosproject.net.flow.DefaultFlowEntry) FlowRuleBatchEntry(org.onosproject.net.flow.oldbatch.FlowRuleBatchEntry) DefaultFlowEntry(org.onosproject.net.flow.DefaultFlowEntry) FlowEntry(org.onosproject.net.flow.FlowEntry) CompletedBatchOperation(org.onosproject.net.flow.CompletedBatchOperation)

Example 14 with FlowRuleBatchEntry

use of org.onosproject.net.flow.oldbatch.FlowRuleBatchEntry in project onos by opennetworkinglab.

the class SimpleVirtualFlowRuleStore method storeBatch.

@Override
public void storeBatch(NetworkId networkId, FlowRuleBatchOperation batchOperation) {
    List<FlowRuleBatchEntry> toAdd = new ArrayList<>();
    List<FlowRuleBatchEntry> toRemove = new ArrayList<>();
    for (FlowRuleBatchEntry entry : batchOperation.getOperations()) {
        final FlowRule flowRule = entry.target();
        if (entry.operator().equals(FlowRuleBatchEntry.FlowRuleOperation.ADD)) {
            if (!getFlowEntries(networkId, flowRule.deviceId(), flowRule.id()).contains(flowRule)) {
                storeFlowRule(networkId, flowRule);
                toAdd.add(entry);
            }
        } else if (entry.operator().equals(FlowRuleBatchEntry.FlowRuleOperation.REMOVE)) {
            if (getFlowEntries(networkId, flowRule.deviceId(), flowRule.id()).contains(flowRule)) {
                deleteFlowRule(networkId, flowRule);
                toRemove.add(entry);
            }
        } else {
            throw new UnsupportedOperationException("Unsupported operation type");
        }
    }
    if (toAdd.isEmpty() && toRemove.isEmpty()) {
        notifyDelegate(networkId, FlowRuleBatchEvent.completed(new FlowRuleBatchRequest(batchOperation.id(), Collections.emptySet()), new CompletedBatchOperation(true, Collections.emptySet(), batchOperation.deviceId())));
        return;
    }
    SettableFuture<CompletedBatchOperation> r = SettableFuture.create();
    final long futureId = localBatchIdGen.incrementAndGet();
    pendingFutures.put(futureId, r);
    toAdd.addAll(toRemove);
    notifyDelegate(networkId, FlowRuleBatchEvent.requested(new FlowRuleBatchRequest(batchOperation.id(), Sets.newHashSet(toAdd)), batchOperation.deviceId()));
}
Also used : FlowRuleBatchEntry(org.onosproject.net.flow.oldbatch.FlowRuleBatchEntry) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) FlowRule(org.onosproject.net.flow.FlowRule) CompletedBatchOperation(org.onosproject.net.flow.CompletedBatchOperation) FlowRuleBatchRequest(org.onosproject.net.flow.oldbatch.FlowRuleBatchRequest)

Aggregations

FlowRuleBatchEntry (org.onosproject.net.flow.oldbatch.FlowRuleBatchEntry)14 CompletedBatchOperation (org.onosproject.net.flow.CompletedBatchOperation)8 FlowRule (org.onosproject.net.flow.FlowRule)6 Test (org.junit.Test)5 DeviceId (org.onosproject.net.DeviceId)5 FlowRuleBatchOperation (org.onosproject.net.flow.oldbatch.FlowRuleBatchOperation)5 FlowRuleBatchRequest (org.onosproject.net.flow.oldbatch.FlowRuleBatchRequest)5 DefaultFlowEntry (org.onosproject.net.flow.DefaultFlowEntry)4 FlowEntry (org.onosproject.net.flow.FlowEntry)4 DefaultFlowRule (org.onosproject.net.flow.DefaultFlowRule)3 ArrayList (java.util.ArrayList)2 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)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 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableSet (com.google.common.collect.ImmutableSet)1