Search in sources :

Example 16 with StoredFlowEntry

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

the class DistributedVirtualFlowRuleStore method updateStoreInternal.

private Set<FlowRuleBatchEntry> updateStoreInternal(NetworkId networkId, FlowRuleBatchOperation operation) {
    return operation.getOperations().stream().map(op -> {
        StoredFlowEntry entry;
        switch(op.operator()) {
            case ADD:
                entry = new DefaultFlowEntry(op.target());
                // always add requested FlowRule
                // Note: 2 equal FlowEntry may have different treatment
                flowTable.remove(networkId, entry.deviceId(), entry);
                flowTable.add(networkId, entry);
                return op;
            case REMOVE:
                entry = flowTable.getFlowEntry(networkId, op.target());
                if (entry != null) {
                    // FIXME modification of "stored" flow entry outside of flow table
                    entry.setState(FlowEntry.FlowEntryState.PENDING_REMOVE);
                    log.debug("Setting state of rule to pending remove: {}", entry);
                    return op;
                }
                break;
            case MODIFY:
                // TODO: figure this out at some point
                break;
            default:
                log.warn("Unknown flow operation operator: {}", op.operator());
        }
        return null;
    }).filter(Objects::nonNull).collect(Collectors.toSet());
}
Also used : StoredFlowEntry(org.onosproject.net.flow.StoredFlowEntry) DefaultFlowEntry(org.onosproject.net.flow.DefaultFlowEntry)

Example 17 with StoredFlowEntry

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

the class SimpleVirtualFlowRuleStore method removeFlowRule.

@Override
public FlowRuleEvent removeFlowRule(NetworkId networkId, FlowEntry rule) {
    // This is where one could mark a rule as removed and still keep it in the store.
    final DeviceId did = rule.deviceId();
    List<StoredFlowEntry> entries = getFlowEntries(networkId, did, rule.id());
    synchronized (entries) {
        if (entries.remove(rule)) {
            return new FlowRuleEvent(RULE_REMOVED, rule);
        }
    }
    return null;
}
Also used : StoredFlowEntry(org.onosproject.net.flow.StoredFlowEntry) FlowRuleEvent(org.onosproject.net.flow.FlowRuleEvent) DeviceId(org.onosproject.net.DeviceId)

Example 18 with StoredFlowEntry

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

the class SimpleFlowRuleStore method addOrUpdateFlowRule.

@Override
public FlowRuleEvent addOrUpdateFlowRule(FlowEntry rule) {
    // check if this new rule is an update to an existing entry
    List<StoredFlowEntry> entries = getFlowEntries(rule.deviceId(), rule.id());
    synchronized (entries) {
        for (StoredFlowEntry stored : entries) {
            if (stored.equals(rule)) {
                synchronized (stored) {
                    // FIXME modification of "stored" flow entry outside of flow table
                    stored.setBytes(rule.bytes());
                    stored.setLife(rule.life());
                    stored.setPackets(rule.packets());
                    if (stored.state() == FlowEntryState.PENDING_ADD) {
                        stored.setState(FlowEntryState.ADDED);
                        // TODO: Do we need to change `rule` state?
                        return new FlowRuleEvent(Type.RULE_ADDED, rule);
                    }
                    return new FlowRuleEvent(Type.RULE_UPDATED, rule);
                }
            }
        }
    }
    // should not reach here
    // storeFlowRule was expected to be called
    log.error("FlowRule was not found in store {} to update", rule);
    // flowEntries.put(did, rule);
    return null;
}
Also used : StoredFlowEntry(org.onosproject.net.flow.StoredFlowEntry) FlowRuleEvent(org.onosproject.net.flow.FlowRuleEvent)

Aggregations

StoredFlowEntry (org.onosproject.net.flow.StoredFlowEntry)18 DefaultFlowEntry (org.onosproject.net.flow.DefaultFlowEntry)9 FlowEntry (org.onosproject.net.flow.FlowEntry)5 FlowRuleEvent (org.onosproject.net.flow.FlowRuleEvent)5 Test (org.junit.Test)4 DeviceId (org.onosproject.net.DeviceId)4 FlowId (org.onosproject.net.flow.FlowId)4 FlowRule (org.onosproject.net.flow.FlowRule)4 AtomicReference (java.util.concurrent.atomic.AtomicReference)3 DefaultFlowRule (org.onosproject.net.flow.DefaultFlowRule)3 Maps (com.google.common.collect.Maps)2 Map (java.util.Map)2 Function (java.util.function.Function)2 Collectors (java.util.stream.Collectors)2 ApplicationId (org.onosproject.core.ApplicationId)2 ConnectPoint (org.onosproject.net.ConnectPoint)2 LogicalTimestamp (org.onosproject.store.LogicalTimestamp)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 ArrayList (java.util.ArrayList)1