Search in sources :

Example 26 with FlowEntry

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

the class ECFlowRuleStoreTest method testRemoveFlow.

/**
 * Tests flow removal.
 */
@Test
public void testRemoveFlow() {
    Iterable<FlowEntry> flows1 = flowStoreImpl.getFlowEntries(deviceId);
    for (FlowEntry flow : flows1) {
        flowStoreImpl.removeFlowRule(flow);
    }
    assertFlowsOnDevice(deviceId, 0);
}
Also used : FlowEntry(org.onosproject.net.flow.FlowEntry) DefaultFlowEntry(org.onosproject.net.flow.DefaultFlowEntry) Test(org.junit.Test)

Example 27 with FlowEntry

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

the class ECFlowRuleStoreTest method testStoreBatch.

/**
 * Tests initial state of flowrule.
 */
@Test
public void testStoreBatch() {
    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());
}
Also used : FlowRuleBatchOperation(org.onosproject.net.flow.oldbatch.FlowRuleBatchOperation) 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)

Example 28 with FlowEntry

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

the class ECFlowRuleStoreTest method testPurgeFlowAppId.

/**
 * Tests purge flow for a device and an application.
 */
@Test
public void testPurgeFlowAppId() {
    FlowEntry flowEntry1 = new DefaultFlowEntry(flowRule1);
    flowStoreImpl.addOrUpdateFlowRule(flowEntry1);
    FlowEntry flowEntry2 = new DefaultFlowEntry(flowRule2);
    flowStoreImpl.addOrUpdateFlowRule(flowEntry2);
    FlowEntry flowEntry3 = new DefaultFlowEntry(flowRule3);
    flowStoreImpl.addOrUpdateFlowRule(flowEntry3);
    assertFlowsOnDevice(deviceId, 2);
    assertFlowsOnDevice(deviceId2, 1);
    flowStoreImpl.purgeFlowRules(deviceId, APP_ID_2);
    assertFlowsOnDevice(deviceId, 1);
    assertFlowsOnDevice(deviceId2, 1);
}
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 29 with FlowEntry

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

the class ECFlowRuleStoreTest method assertFlowsOnDevice.

private void assertFlowsOnDevice(DeviceId deviceId, int nFlows) {
    Iterable<FlowEntry> flows1 = flowStoreImpl.getFlowEntries(deviceId);
    int sum1 = 0;
    for (FlowEntry flowEntry : flows1) {
        sum1++;
    }
    assertThat(sum1, is(nFlows));
}
Also used : FlowEntry(org.onosproject.net.flow.FlowEntry) DefaultFlowEntry(org.onosproject.net.flow.DefaultFlowEntry)

Example 30 with FlowEntry

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

the class DistributedFlowStatisticStore method updateFlowStatistic.

@Override
public synchronized void updateFlowStatistic(FlowEntry rule) {
    ConnectPoint cp = buildConnectPoint(rule);
    if (cp == null) {
        return;
    }
    Set<FlowEntry> curr = current.get(cp);
    if (curr == null) {
        addFlowStatistic(rule);
    } else {
        Optional<FlowEntry> f = curr.stream().filter(c -> rule.equals(c)).findAny();
        if (f.isPresent() && rule.bytes() < f.get().bytes()) {
            log.debug("DistributedFlowStatisticStore:updateFlowStatistic():" + " Invalid Flow Update! Will be removed!!" + " curr flowId=" + Long.toHexString(rule.id().value()) + ", prev flowId=" + Long.toHexString(f.get().id().value()) + ", curr bytes=" + rule.bytes() + ", prev bytes=" + f.get().bytes() + ", curr life=" + rule.life() + ", prev life=" + f.get().life() + ", curr lastSeen=" + rule.lastSeen() + ", prev lastSeen=" + f.get().lastSeen());
            // something is wrong! invalid flow entry, so delete it
            removeFlowStatistic(rule);
            return;
        }
        Set<FlowEntry> prev = previous.get(cp);
        if (prev == null) {
            prev = new HashSet<>();
            previous.put(cp, prev);
        }
        // previous one is exist
        if (f.isPresent()) {
            // remove old one and add new one
            prev.remove(rule);
            if (!prev.add(f.get())) {
                log.debug("DistributedFlowStatisticStore:updateFlowStatistic():" + " flowId={}, add failed into previous.", Long.toHexString(rule.id().value()));
            }
        }
        // remove old one and add new one
        curr.remove(rule);
        if (!curr.add(rule)) {
            log.debug("DistributedFlowStatisticStore:updateFlowStatistic():" + " flowId={}, add failed into current.", Long.toHexString(rule.id().value()));
        }
    }
}
Also used : DFS_MESSAGE_HANDLER_THREAD_POOL_SIZE(org.onosproject.store.OsgiPropertyConstants.DFS_MESSAGE_HANDLER_THREAD_POOL_SIZE) Tools(org.onlab.util.Tools) PortNumber(org.onosproject.net.PortNumber) ComponentContext(org.osgi.service.component.ComponentContext) Tools.groupedThreads(org.onlab.util.Tools.groupedThreads) FlowEntry(org.onosproject.net.flow.FlowEntry) Strings.isNullOrEmpty(com.google.common.base.Strings.isNullOrEmpty) ConnectPoint(org.onosproject.net.ConnectPoint) DFS_MESSAGE_HANDLER_THREAD_POOL_SIZE_DEFAULT(org.onosproject.store.OsgiPropertyConstants.DFS_MESSAGE_HANDLER_THREAD_POOL_SIZE_DEFAULT) HashSet(java.util.HashSet) Component(org.osgi.service.component.annotations.Component) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) Map(java.util.Map) MessageSubject(org.onosproject.store.cluster.messaging.MessageSubject) Activate(org.osgi.service.component.annotations.Activate) KryoNamespaces(org.onosproject.store.serializers.KryoNamespaces) Objects(com.google.common.base.Objects) MastershipService(org.onosproject.mastership.MastershipService) ExecutorService(java.util.concurrent.ExecutorService) ComponentConfigService(org.onosproject.cfg.ComponentConfigService) NodeId(org.onosproject.cluster.NodeId) Serializer(org.onosproject.store.service.Serializer) Instructions(org.onosproject.net.flow.instructions.Instructions) Tools.get(org.onlab.util.Tools.get) Logger(org.slf4j.Logger) Properties(java.util.Properties) Deactivate(org.osgi.service.component.annotations.Deactivate) Instruction(org.onosproject.net.flow.instructions.Instruction) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) Executors(java.util.concurrent.Executors) Executors.newFixedThreadPool(java.util.concurrent.Executors.newFixedThreadPool) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) TimeUnit(java.util.concurrent.TimeUnit) FlowStatisticStore(org.onosproject.net.statistic.FlowStatisticStore) FlowRule(org.onosproject.net.flow.FlowRule) Modified(org.osgi.service.component.annotations.Modified) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) ClusterCommunicationService(org.onosproject.store.cluster.messaging.ClusterCommunicationService) Optional(java.util.Optional) ClusterService(org.onosproject.cluster.ClusterService) DeviceId(org.onosproject.net.DeviceId) Reference(org.osgi.service.component.annotations.Reference) Collections(java.util.Collections) Dictionary(java.util.Dictionary) ConnectPoint(org.onosproject.net.ConnectPoint) FlowEntry(org.onosproject.net.flow.FlowEntry)

Aggregations

FlowEntry (org.onosproject.net.flow.FlowEntry)123 DefaultFlowEntry (org.onosproject.net.flow.DefaultFlowEntry)61 FlowRule (org.onosproject.net.flow.FlowRule)51 Test (org.junit.Test)31 DefaultFlowRule (org.onosproject.net.flow.DefaultFlowRule)31 FlowRuleService (org.onosproject.net.flow.FlowRuleService)27 ArrayList (java.util.ArrayList)24 StoredFlowEntry (org.onosproject.net.flow.StoredFlowEntry)23 DeviceId (org.onosproject.net.DeviceId)20 Device (org.onosproject.net.Device)19 PortNumber (org.onosproject.net.PortNumber)17 TrafficSelector (org.onosproject.net.flow.TrafficSelector)16 Instruction (org.onosproject.net.flow.instructions.Instruction)16 DeviceService (org.onosproject.net.device.DeviceService)15 List (java.util.List)14 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)13 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)13 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)12 HashSet (java.util.HashSet)12 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)11