Search in sources :

Example 1 with DefaultFlowEntry

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

the class SimpleVirtualFlowRuleStore method storeFlowRuleInternal.

private void storeFlowRuleInternal(NetworkId networkId, FlowRule rule) {
    StoredFlowEntry f = new DefaultFlowEntry(rule);
    final DeviceId did = f.deviceId();
    final FlowId fid = f.id();
    List<StoredFlowEntry> existing = getFlowEntries(networkId, 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 2 with DefaultFlowEntry

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

the class VirtualNetworkFlowRuleManagerTest method purgeFlowRules.

@Test
public void purgeFlowRules() {
    FlowRule f1 = addFlowRule(1);
    FlowRule f2 = addFlowRule(2);
    FlowRule f3 = addFlowRule(3);
    assertEquals("3 rules should exist", 3, flowCount(vnetFlowRuleService1));
    FlowEntry fe1 = new DefaultFlowEntry(f1);
    FlowEntry fe2 = new DefaultFlowEntry(f2);
    FlowEntry fe3 = new DefaultFlowEntry(f3);
    providerService1.pushFlowMetrics(VDID1, ImmutableList.of(fe1, fe2, fe3));
    validateEvents(listener1, RULE_ADD_REQUESTED, RULE_ADD_REQUESTED, RULE_ADD_REQUESTED, RULE_ADDED, RULE_ADDED, RULE_ADDED);
    vnetFlowRuleService1.purgeFlowRules(VDID1);
    assertEquals("0 rule should exist", 0, flowCount(vnetFlowRuleService1));
}
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 3 with DefaultFlowEntry

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

the class VirtualNetworkFlowRuleManagerTest method getFlowEntries.

@Test
public void getFlowEntries() {
    assertTrue("store should be empty", Sets.newHashSet(vnetFlowRuleService1.getFlowEntries(VDID1)).isEmpty());
    assertTrue("store should be empty", Sets.newHashSet(vnetFlowRuleService2.getFlowEntries(VDID1)).isEmpty());
    FlowRule f1 = addFlowRule(1);
    FlowRule f2 = addFlowRule(2);
    FlowEntry fe1 = new DefaultFlowEntry(f1);
    FlowEntry fe2 = new DefaultFlowEntry(f2);
    assertEquals("2 rules should exist", 2, flowCount(vnetFlowRuleService1));
    assertEquals("0 rules should exist", 0, flowCount(vnetFlowRuleService2));
    providerService1.pushFlowMetrics(VDID1, ImmutableList.of(fe1, fe2));
    validateEvents(listener1, RULE_ADD_REQUESTED, RULE_ADD_REQUESTED, RULE_ADDED, RULE_ADDED);
    addFlowRule(1);
    assertEquals("should still be 2 rules", 2, flowCount(vnetFlowRuleService1));
    System.err.println("events :" + listener1.events);
    assertEquals("0 rules should exist", 0, flowCount(vnetFlowRuleService2));
    providerService1.pushFlowMetrics(VDID1, ImmutableList.of(fe1));
    validateEvents(listener1, RULE_UPDATED, RULE_UPDATED);
}
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 4 with DefaultFlowEntry

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

the class FlowEntryCodec method decode.

@Override
public FlowEntry decode(ObjectNode json, CodecContext context) {
    checkNotNull(json, "JSON object cannot be null");
    // decode FlowRule-specific fields using the FlowRule codec
    FlowRule flowRule = context.codec(FlowRule.class).decode(json, context);
    JsonNode stateNode = json.get(STATE);
    FlowEntry.FlowEntryState state = (null == stateNode) ? FlowEntry.FlowEntryState.ADDED : FlowEntry.FlowEntryState.valueOf(stateNode.asText());
    JsonNode lifeNode = json.get(LIFE);
    long life = (null == lifeNode) ? 0 : lifeNode.asLong();
    JsonNode liveTypeNode = json.get(LIVE_TYPE);
    FlowEntry.FlowLiveType liveType = (null == liveTypeNode) ? FlowEntry.FlowLiveType.UNKNOWN : FlowEntry.FlowLiveType.valueOf(liveTypeNode.asText());
    JsonNode packetsNode = json.get(PACKETS);
    long packets = (null == packetsNode) ? 0 : packetsNode.asLong();
    JsonNode bytesNode = json.get(BYTES);
    long bytes = (null == bytesNode) ? 0 : bytesNode.asLong();
    return new DefaultFlowEntry(flowRule, state, life, liveType, packets, bytes);
}
Also used : DefaultFlowEntry(org.onosproject.net.flow.DefaultFlowEntry) JsonNode(com.fasterxml.jackson.databind.JsonNode) FlowRule(org.onosproject.net.flow.FlowRule) DefaultFlowEntry(org.onosproject.net.flow.DefaultFlowEntry) FlowEntry(org.onosproject.net.flow.FlowEntry)

Example 5 with DefaultFlowEntry

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

Aggregations

DefaultFlowEntry (org.onosproject.net.flow.DefaultFlowEntry)43 FlowEntry (org.onosproject.net.flow.FlowEntry)37 FlowRule (org.onosproject.net.flow.FlowRule)30 StoredFlowEntry (org.onosproject.net.flow.StoredFlowEntry)22 DefaultFlowRule (org.onosproject.net.flow.DefaultFlowRule)21 Test (org.junit.Test)20 ArrayList (java.util.ArrayList)8 DeviceId (org.onosproject.net.DeviceId)6 Collectors (java.util.stream.Collectors)5 Map (java.util.Map)4 HierarchicalConfiguration (org.apache.commons.configuration.HierarchicalConfiguration)4 DeviceConnectionCache (org.onosproject.drivers.odtn.impl.DeviceConnectionCache)4 PortNumber (org.onosproject.net.PortNumber)4 DeviceService (org.onosproject.net.device.DeviceService)4 FlowId (org.onosproject.net.flow.FlowId)4 Logger (org.slf4j.Logger)4 ImmutableList (com.google.common.collect.ImmutableList)3 IOException (java.io.IOException)3 Objects (java.util.Objects)3 AtomicReference (java.util.concurrent.atomic.AtomicReference)3