Search in sources :

Example 1 with FlowRuleEvent

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

the class SimpleVirtualFlowRuleStore method addOrUpdateFlowRule.

@Override
public FlowRuleEvent addOrUpdateFlowRule(NetworkId networkId, FlowEntry rule) {
    // check if this new rule is an update to an existing entry
    List<StoredFlowEntry> entries = getFlowEntries(networkId, 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() == FlowEntry.FlowEntryState.PENDING_ADD) {
                        stored.setState(FlowEntry.FlowEntryState.ADDED);
                        // TODO: Do we need to change `rule` state?
                        return new FlowRuleEvent(FlowRuleEvent.Type.RULE_ADDED, rule);
                    }
                    return new FlowRuleEvent(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);
    return null;
}
Also used : StoredFlowEntry(org.onosproject.net.flow.StoredFlowEntry) FlowRuleEvent(org.onosproject.net.flow.FlowRuleEvent)

Example 2 with FlowRuleEvent

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

the class VirtualNetworkFlowRuleManagerTest method validateEvents.

private void validateEvents(TestFlowRuleListener listener, 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 3 with FlowRuleEvent

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

the class SimpleFlowRuleStore method removeFlowRule.

@Override
public FlowRuleEvent removeFlowRule(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(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 4 with FlowRuleEvent

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

the class ECFlowRuleStore method addOrUpdateFlowRuleInternal.

private FlowRuleEvent addOrUpdateFlowRuleInternal(FlowEntry rule) {
    FlowRuleEvent event = flowTable.update(rule, stored -> {
        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() == FlowEntryState.PENDING_ADD) {
            stored.setState(FlowEntryState.ADDED);
            return new FlowRuleEvent(Type.RULE_ADDED, rule);
        }
        return new FlowRuleEvent(Type.RULE_UPDATED, rule);
    });
    if (event != null) {
        return event;
    }
    // TODO: Confirm if this behavior is correct. See SimpleFlowRuleStore
    // TODO: also update backup if the behavior is correct.
    flowTable.add(rule);
    return null;
}
Also used : FlowRuleEvent(org.onosproject.net.flow.FlowRuleEvent)

Example 5 with FlowRuleEvent

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

the class ECFlowRuleStore method removeFlowRuleInternal.

private FlowRuleEvent removeFlowRuleInternal(FlowEntry rule) {
    // This is where one could mark a rule as removed and still keep it in the store.
    final FlowEntry removed = flowTable.remove(rule);
    log.debug("Removed flow rule: {}", removed);
    // 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) FlowEntry(org.onosproject.net.flow.FlowEntry) StoredFlowEntry(org.onosproject.net.flow.StoredFlowEntry) DefaultFlowEntry(org.onosproject.net.flow.DefaultFlowEntry)

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