Search in sources :

Example 11 with StoredFlowEntry

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

the class FlowBucket method remove.

/**
 * Removes the given flow rule from the bucket.
 *
 * @param rule  the rule to remove
 * @param term  the term in which the change occurred
 * @param clock the logical clock
 * @return the removed flow entry
 */
public FlowEntry remove(FlowEntry rule, long term, LogicalClock clock) {
    final AtomicReference<FlowEntry> removedRule = new AtomicReference<>();
    flowBucket.computeIfPresent(rule.id(), (flowId, flowEntries) -> {
        flowEntries.computeIfPresent((StoredFlowEntry) rule, (k, stored) -> {
            if (rule instanceof DefaultFlowEntry) {
                DefaultFlowEntry toRemove = (DefaultFlowEntry) rule;
                if (stored instanceof DefaultFlowEntry) {
                    DefaultFlowEntry storedEntry = (DefaultFlowEntry) stored;
                    if (toRemove.created() < storedEntry.created()) {
                        LOGGER.debug("Trying to remove more recent flow entry {} (stored: {})", toRemove, stored);
                        // the key is not updated, removedRule remains null
                        return stored;
                    }
                }
            }
            removedRule.set(stored);
            return null;
        });
        return flowEntries.isEmpty() ? null : flowEntries;
    });
    if (removedRule.get() != null) {
        recordUpdate(term, clock.getTimestamp());
        return removedRule.get();
    } else {
        return null;
    }
}
Also used : DefaultFlowEntry(org.onosproject.net.flow.DefaultFlowEntry) AtomicReference(java.util.concurrent.atomic.AtomicReference) DefaultFlowEntry(org.onosproject.net.flow.DefaultFlowEntry) FlowEntry(org.onosproject.net.flow.FlowEntry) StoredFlowEntry(org.onosproject.net.flow.StoredFlowEntry)

Example 12 with StoredFlowEntry

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

the class FlowRuleManagerTest method flowRemoved.

@Test
public void flowRemoved() {
    FlowRule f1 = addFlowRule(1);
    FlowRule f2 = addFlowRule(2);
    StoredFlowEntry fe1 = new DefaultFlowEntry(f1);
    FlowEntry fe2 = new DefaultFlowEntry(f2);
    providerService.pushFlowMetrics(DID, ImmutableList.of(fe1, fe2));
    service.removeFlowRules(f1);
    // FIXME modification of "stored" flow entry outside of store
    fe1.setState(FlowEntryState.REMOVED);
    providerService.flowRemoved(fe1);
    validateEvents(RULE_ADD_REQUESTED, RULE_ADD_REQUESTED, RULE_ADDED, RULE_ADDED, RULE_REMOVE_REQUESTED, RULE_REMOVED);
    providerService.flowRemoved(fe1);
    validateEvents();
    FlowRule f3 = flowRule(3, 3);
    FlowEntry fe3 = new DefaultFlowEntry(f3);
    service.applyFlowRules(f3);
    providerService.pushFlowMetrics(DID, Collections.singletonList(fe3));
    validateEvents(RULE_ADD_REQUESTED, RULE_ADDED, RULE_UPDATED);
    providerService.flowRemoved(fe3);
    validateEvents();
}
Also used : StoredFlowEntry(org.onosproject.net.flow.StoredFlowEntry) DefaultFlowEntry(org.onosproject.net.flow.DefaultFlowEntry) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) FlowEntry(org.onosproject.net.flow.FlowEntry) StoredFlowEntry(org.onosproject.net.flow.StoredFlowEntry) DefaultFlowEntry(org.onosproject.net.flow.DefaultFlowEntry) Test(org.junit.Test)

Example 13 with StoredFlowEntry

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

the class FlowEntryWithLoadTest method testConstructionDEfaultLoad.

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

Example 14 with StoredFlowEntry

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

the class VirtualNetworkFlowRuleManagerTest method flowRemoved.

@Test
public void flowRemoved() {
    FlowRule f1 = addFlowRule(1);
    FlowRule f2 = addFlowRule(2);
    StoredFlowEntry fe1 = new DefaultFlowEntry(f1);
    FlowEntry fe2 = new DefaultFlowEntry(f2);
    providerService1.pushFlowMetrics(VDID1, ImmutableList.of(fe1, fe2));
    vnetFlowRuleService1.removeFlowRules(f1);
    // FIXME modification of "stored" flow entry outside of store
    fe1.setState(FlowEntry.FlowEntryState.REMOVED);
    providerService1.flowRemoved(fe1);
    validateEvents(listener1, RULE_ADD_REQUESTED, RULE_ADD_REQUESTED, RULE_ADDED, RULE_ADDED, RULE_REMOVE_REQUESTED, RULE_REMOVED);
    providerService1.flowRemoved(fe1);
    validateEvents(listener1);
    FlowRule f3 = flowRule(3, 3);
    FlowEntry fe3 = new DefaultFlowEntry(f3);
    vnetFlowRuleService1.applyFlowRules(f3);
    providerService1.pushFlowMetrics(VDID1, Collections.singletonList(fe3));
    validateEvents(listener1, RULE_ADD_REQUESTED, RULE_ADDED, RULE_UPDATED);
    providerService1.flowRemoved(fe3);
    validateEvents(listener1);
}
Also used : StoredFlowEntry(org.onosproject.net.flow.StoredFlowEntry) DefaultFlowEntry(org.onosproject.net.flow.DefaultFlowEntry) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) FlowEntry(org.onosproject.net.flow.FlowEntry) StoredFlowEntry(org.onosproject.net.flow.StoredFlowEntry) DefaultFlowEntry(org.onosproject.net.flow.DefaultFlowEntry) Test(org.junit.Test)

Example 15 with StoredFlowEntry

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

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