Search in sources :

Example 6 with FlowRuleEvent

use of org.onosproject.net.flow.FlowRuleEvent 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)

Example 7 with FlowRuleEvent

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

the class FlowRuleManagerTest method validateEvents.

private void validateEvents(FlowRuleEvent.Type... events) {
    if (events == null) {
        assertTrue("events generated", listener.events.isEmpty());
    }
    int i = 0;
    System.err.println("events :" + listener.events);
    for (FlowRuleEvent e : listener.events) {
        assertEquals("unexpected event", events[i], e.type());
        i++;
    }
    assertEquals("mispredicted number of events", events.length, listener.events.size());
    listener.events.clear();
}
Also used : FlowRuleEvent(org.onosproject.net.flow.FlowRuleEvent)

Example 8 with FlowRuleEvent

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

the class DistributedVirtualFlowRuleStore method removeFlowRuleInternal.

private FlowRuleEvent removeFlowRuleInternal(VirtualFlowEntry rule) {
    final DeviceId deviceId = rule.flowEntry().deviceId();
    // This is where one could mark a rule as removed and still keep it in the store.
    final FlowEntry removed = flowTable.remove(rule.networkId(), deviceId, rule.flowEntry());
    // rule may be partial rule that is missing treatment, we should use rule from store instead
    return removed != null ? new FlowRuleEvent(RULE_REMOVED, removed) : null;
}
Also used : FlowRuleEvent(org.onosproject.net.flow.FlowRuleEvent) VirtualDeviceId(org.onosproject.incubator.net.virtual.store.impl.primitives.VirtualDeviceId) DeviceId(org.onosproject.net.DeviceId) FlowEntry(org.onosproject.net.flow.FlowEntry) StoredFlowEntry(org.onosproject.net.flow.StoredFlowEntry) DefaultFlowEntry(org.onosproject.net.flow.DefaultFlowEntry) VirtualFlowEntry(org.onosproject.incubator.net.virtual.store.impl.primitives.VirtualFlowEntry)

Example 9 with FlowRuleEvent

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

the class DistributedVirtualFlowRuleStore method addOrUpdateFlowRuleInternal.

private FlowRuleEvent addOrUpdateFlowRuleInternal(NetworkId networkId, FlowEntry rule) {
    // check if this new rule is an update to an existing entry
    StoredFlowEntry stored = flowTable.getFlowEntry(networkId, rule);
    if (stored != null) {
        // FIXME modification of "stored" flow entry outside of flow table
        stored.setBytes(rule.bytes());
        stored.setLife(rule.life(TimeUnit.NANOSECONDS), TimeUnit.NANOSECONDS);
        stored.setLiveType(rule.liveType());
        stored.setPackets(rule.packets());
        stored.setLastSeen();
        if (stored.state() == FlowEntry.FlowEntryState.PENDING_ADD) {
            stored.setState(FlowEntry.FlowEntryState.ADDED);
            return new FlowRuleEvent(FlowRuleEvent.Type.RULE_ADDED, rule);
        }
        return new FlowRuleEvent(FlowRuleEvent.Type.RULE_UPDATED, rule);
    }
    // TODO: Confirm if this behavior is correct. See SimpleFlowRuleStore
    // TODO: also update backup if the behavior is correct.
    flowTable.add(networkId, rule);
    return null;
}
Also used : StoredFlowEntry(org.onosproject.net.flow.StoredFlowEntry) FlowRuleEvent(org.onosproject.net.flow.FlowRuleEvent)

Example 10 with FlowRuleEvent

use of org.onosproject.net.flow.FlowRuleEvent 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)

Aggregations

FlowRuleEvent (org.onosproject.net.flow.FlowRuleEvent)10 StoredFlowEntry (org.onosproject.net.flow.StoredFlowEntry)7 DeviceId (org.onosproject.net.DeviceId)3 DefaultFlowEntry (org.onosproject.net.flow.DefaultFlowEntry)2 FlowEntry (org.onosproject.net.flow.FlowEntry)2 VirtualDeviceId (org.onosproject.incubator.net.virtual.store.impl.primitives.VirtualDeviceId)1 VirtualFlowEntry (org.onosproject.incubator.net.virtual.store.impl.primitives.VirtualFlowEntry)1