Search in sources :

Example 96 with FlowEntry

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

the class FlowRuleManagerTest method removeFlowRules.

@Test
public void removeFlowRules() {
    FlowRule f1 = addFlowRule(1);
    FlowRule f2 = addFlowRule(2);
    FlowRule f3 = addFlowRule(3);
    assertEquals("3 rules should exist", 3, flowCount());
    FlowEntry fe1 = new DefaultFlowEntry(f1);
    FlowEntry fe2 = new DefaultFlowEntry(f2);
    FlowEntry fe3 = new DefaultFlowEntry(f3);
    providerService.pushFlowMetrics(DID, ImmutableList.of(fe1, fe2, fe3));
    validateEvents(RULE_ADD_REQUESTED, RULE_ADD_REQUESTED, RULE_ADD_REQUESTED, RULE_ADDED, RULE_ADDED, RULE_ADDED);
    mgr.removeFlowRules(f1, f2);
    // removing from north, so no events generated
    validateEvents(RULE_REMOVE_REQUESTED, RULE_REMOVE_REQUESTED);
    assertEquals("3 rule should exist", 3, flowCount());
    assertTrue("Entries should be pending remove.", validateState(ImmutableMap.of(f1, FlowEntryState.PENDING_REMOVE, f2, FlowEntryState.PENDING_REMOVE, f3, FlowEntryState.ADDED)));
    mgr.removeFlowRules(f1);
    assertEquals("3 rule should still exist", 3, flowCount());
}
Also used : 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 97 with FlowEntry

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

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

the class DistributedStatisticStore method removeFromStatistics.

@Override
public synchronized void removeFromStatistics(FlowRule rule) {
    ConnectPoint cp = buildConnectPoint(rule);
    if (cp == null) {
        return;
    }
    InternalStatisticRepresentation rep = representations.get(cp);
    if (rep != null && rep.remove(rule)) {
        updatePublishedStats(cp, Collections.emptySet());
    }
    Set<FlowEntry> values = current.get(cp);
    if (values != null) {
        values.remove(rule);
    }
    values = previous.get(cp);
    if (values != null) {
        values.remove(rule);
    }
}
Also used : ConnectPoint(org.onosproject.net.ConnectPoint) FlowEntry(org.onosproject.net.flow.FlowEntry)

Example 99 with FlowEntry

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

the class ECFlowRuleStoreTest method testPurgeFlow.

/**
 * Tests purge flow for a device.
 */
@Test
public void testPurgeFlow() {
    FlowEntry flowEntry = new DefaultFlowEntry(flowRule);
    flowStoreImpl.addOrUpdateFlowRule(flowEntry);
    FlowEntry flowEntry1 = new DefaultFlowEntry(flowRule1);
    flowStoreImpl.addOrUpdateFlowRule(flowEntry1);
    assertFlowsOnDevice(deviceId, 2);
    flowStoreImpl.purgeFlowRule(deviceId);
    assertFlowsOnDevice(deviceId, 0);
}
Also used : DefaultFlowEntry(org.onosproject.net.flow.DefaultFlowEntry) FlowEntry(org.onosproject.net.flow.FlowEntry) DefaultFlowEntry(org.onosproject.net.flow.DefaultFlowEntry) Test(org.junit.Test)

Example 100 with FlowEntry

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

the class ECFlowRuleStoreTest method testAddFlow.

/**
 * Tests adding a flowrule.
 */
@Test
public void testAddFlow() {
    FlowEntry flowEntry = new DefaultFlowEntry(flowRule);
    FlowRuleOperation op = new FlowRuleOperation(flowRule, FlowRuleOperation.Type.ADD);
    Multimap<DeviceId, FlowRuleBatchEntry> perDeviceBatches = ArrayListMultimap.create();
    perDeviceBatches.put(op.rule().deviceId(), new FlowRuleBatchEntry(FlowRuleBatchEntry.FlowRuleOperation.ADD, op.rule()));
    FlowRuleBatchOperation b = new FlowRuleBatchOperation(perDeviceBatches.get(deviceId), deviceId, 1);
    flowStoreImpl.storeBatch(b);
    FlowEntry flowEntry1 = flowStoreImpl.getFlowEntry(flowRule);
    assertEquals("PENDING_ADD", flowEntry1.state().toString());
    flowStoreImpl.addOrUpdateFlowRule(flowEntry);
    assertFlowsOnDevice(deviceId, 1);
    FlowEntry flowEntry2 = flowStoreImpl.getFlowEntry(flowRule);
    assertEquals("ADDED", flowEntry2.state().toString());
    assertThat(flowStoreImpl.getTableStatistics(deviceId), notNullValue());
}
Also used : FlowRuleBatchOperation(org.onosproject.net.flow.oldbatch.FlowRuleBatchOperation) DefaultFlowEntry(org.onosproject.net.flow.DefaultFlowEntry) DeviceId(org.onosproject.net.DeviceId) FlowRuleBatchEntry(org.onosproject.net.flow.oldbatch.FlowRuleBatchEntry) FlowEntry(org.onosproject.net.flow.FlowEntry) DefaultFlowEntry(org.onosproject.net.flow.DefaultFlowEntry) FlowRuleOperation(org.onosproject.net.flow.FlowRuleOperation) Test(org.junit.Test)

Aggregations

FlowEntry (org.onosproject.net.flow.FlowEntry)119 DefaultFlowEntry (org.onosproject.net.flow.DefaultFlowEntry)58 FlowRule (org.onosproject.net.flow.FlowRule)48 Test (org.junit.Test)28 DefaultFlowRule (org.onosproject.net.flow.DefaultFlowRule)28 FlowRuleService (org.onosproject.net.flow.FlowRuleService)25 ArrayList (java.util.ArrayList)24 StoredFlowEntry (org.onosproject.net.flow.StoredFlowEntry)23 Device (org.onosproject.net.Device)19 DeviceId (org.onosproject.net.DeviceId)19 PortNumber (org.onosproject.net.PortNumber)16 Instruction (org.onosproject.net.flow.instructions.Instruction)16 DeviceService (org.onosproject.net.device.DeviceService)14 TrafficSelector (org.onosproject.net.flow.TrafficSelector)14 List (java.util.List)13 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)12 HashSet (java.util.HashSet)12 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)12 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)12 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)11