Search in sources :

Example 6 with StoredFlowEntry

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

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

the class FlowEntryWithLoadTest method testConstructionCpFeLoad.

@Test
public void testConstructionCpFeLoad() {
    ConnectPoint cp = NetTestTools.connectPoint("id1", 1);
    StoredFlowEntry fe = new MockFlowEntry(FlowEntry.FlowLiveType.IMMEDIATE);
    Load load = new DefaultLoad();
    FlowEntryWithLoad underTest = new FlowEntryWithLoad(cp, fe, load);
    assertThat(underTest.connectPoint(), is(cp));
    assertThat(underTest.load(), is(load));
    assertThat(underTest.storedFlowEntry(), is(fe));
}
Also used : StoredFlowEntry(org.onosproject.net.flow.StoredFlowEntry) ConnectPoint(org.onosproject.net.ConnectPoint) Test(org.junit.Test)

Example 8 with StoredFlowEntry

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

the class FlowStatisticManager method toFlowEntryWithLoad.

private List<TypedFlowEntryWithLoad> toFlowEntryWithLoad(List<FlowEntryWithLoad> loadList) {
    // convert FlowEntryWithLoad list to TypedFlowEntryWithLoad list
    List<TypedFlowEntryWithLoad> tfelList = new ArrayList<>();
    loadList.forEach(fel -> {
        StoredFlowEntry sfe = fel.storedFlowEntry();
        TypedStoredFlowEntry.FlowLiveType liveType = toTypedStoredFlowEntryLiveType(sfe.liveType());
        TypedStoredFlowEntry tfe = new DefaultTypedFlowEntry(sfe, liveType);
        TypedFlowEntryWithLoad tfel = new TypedFlowEntryWithLoad(fel.connectPoint(), tfe, fel.load());
        tfelList.add(tfel);
    });
    return tfelList;
}
Also used : TypedStoredFlowEntry(org.onosproject.net.flow.TypedStoredFlowEntry) TypedStoredFlowEntry(org.onosproject.net.flow.TypedStoredFlowEntry) StoredFlowEntry(org.onosproject.net.flow.StoredFlowEntry) TypedFlowEntryWithLoad(org.onosproject.net.statistic.TypedFlowEntryWithLoad) DefaultTypedFlowEntry(org.onosproject.net.flow.DefaultTypedFlowEntry) ArrayList(java.util.ArrayList)

Example 9 with StoredFlowEntry

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

the class SimpleFlowRuleStore method storeFlowRuleInternal.

private void storeFlowRuleInternal(FlowRule rule) {
    StoredFlowEntry f = new DefaultFlowEntry(rule);
    final DeviceId did = f.deviceId();
    final FlowId fid = f.id();
    List<StoredFlowEntry> existing = getFlowEntries(did, fid);
    synchronized (existing) {
        for (StoredFlowEntry fe : existing) {
            if (fe.equals(rule)) {
                // was already there? ignore
                return;
            }
        }
        // new flow rule added
        existing.add(f);
    }
}
Also used : FlowId(org.onosproject.net.flow.FlowId) StoredFlowEntry(org.onosproject.net.flow.StoredFlowEntry) DefaultFlowEntry(org.onosproject.net.flow.DefaultFlowEntry) DeviceId(org.onosproject.net.DeviceId)

Example 10 with StoredFlowEntry

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

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