Search in sources :

Example 11 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 12 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 13 with DefaultFlowEntry

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

the class CzechLightFlowRuleProgrammable method getFlowEntries.

@Override
public Collection<FlowEntry> getFlowEntries() {
    if (deviceType() == CzechLightDiscovery.DeviceType.INLINE_AMP || deviceType() == CzechLightDiscovery.DeviceType.COHERENT_ADD_DROP) {
        final var data = getConnectionCache().get(data().deviceId());
        if (data == null) {
            return new ArrayList<>();
        }
        return data.stream().map(rule -> new DefaultFlowEntry(rule)).collect(Collectors.toList());
    }
    HierarchicalConfiguration xml;
    try {
        xml = doGetSubtree(CzechLightDiscovery.CHANNEL_DEFS_FILTER + CzechLightDiscovery.MC_ROUTING_FILTER);
    } catch (NetconfException e) {
        log.error("Cannot read data from NETCONF: {}", e);
        return new ArrayList<>();
    }
    final var allChannels = MediaChannelDefinition.parseChannelDefinitions(xml);
    Collection<FlowEntry> list = new ArrayList<>();
    final var allMCs = xml.configurationsAt("data.media-channels");
    allMCs.stream().map(cfg -> confToMCRouting(ELEMENT_ADD, allChannels, cfg)).filter(Objects::nonNull).forEach(flow -> {
        log.debug("{}: found ADD: {}", data().deviceId(), flow.toString());
        list.add(new DefaultFlowEntry(asFlowRule(Direction.ADD, flow), FlowEntry.FlowEntryState.ADDED));
    });
    allMCs.stream().map(cfg -> confToMCRouting(ELEMENT_DROP, allChannels, cfg)).filter(Objects::nonNull).forEach(flow -> {
        log.debug("{}: found DROP: {}", data().deviceId(), flow.toString());
        list.add(new DefaultFlowEntry(asFlowRule(Direction.DROP, flow), FlowEntry.FlowEntryState.ADDED));
    });
    return list;
}
Also used : NetconfException(org.onosproject.netconf.NetconfException) GridType(org.onosproject.net.GridType) FlowRuleProgrammable(org.onosproject.net.flow.FlowRuleProgrammable) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) CoreService(org.onosproject.core.CoreService) PortNumber(org.onosproject.net.PortNumber) DeviceService(org.onosproject.net.device.DeviceService) LoggerFactory(org.slf4j.LoggerFactory) FlowEntry(org.onosproject.net.flow.FlowEntry) Spectrum(org.onlab.util.Spectrum) PortCriterion(org.onosproject.net.flow.criteria.PortCriterion) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) NetconfSession(org.onosproject.netconf.NetconfSession) AbstractHandlerBehaviour(org.onosproject.net.driver.AbstractHandlerBehaviour) OchSignalCriterion(org.onosproject.net.flow.criteria.OchSignalCriterion) ArrayList(java.util.ArrayList) FlowRuleService(org.onosproject.net.flow.FlowRuleService) TrafficSelector(org.onosproject.net.flow.TrafficSelector) NetconfController(org.onosproject.netconf.NetconfController) L0ModificationInstruction(org.onosproject.net.flow.instructions.L0ModificationInstruction) Map(java.util.Map) Criteria(org.onosproject.net.flow.criteria.Criteria) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) OchSignalType(org.onosproject.net.OchSignalType) DefaultFlowEntry(org.onosproject.net.flow.DefaultFlowEntry) Instructions(org.onosproject.net.flow.instructions.Instructions) Logger(org.slf4j.Logger) Collection(java.util.Collection) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) HierarchicalConfiguration(org.apache.commons.configuration.HierarchicalConfiguration) Lambda(org.onosproject.net.Lambda) Collectors(java.util.stream.Collectors) DeviceConnectionCache(org.onosproject.drivers.odtn.impl.DeviceConnectionCache) OchSignal(org.onosproject.net.OchSignal) Objects(java.util.Objects) DatastoreId(org.onosproject.netconf.DatastoreId) TreeMap(java.util.TreeMap) FlowRule(org.onosproject.net.flow.FlowRule) ChannelSpacing(org.onosproject.net.ChannelSpacing) DefaultFlowEntry(org.onosproject.net.flow.DefaultFlowEntry) NetconfException(org.onosproject.netconf.NetconfException) ArrayList(java.util.ArrayList) HierarchicalConfiguration(org.apache.commons.configuration.HierarchicalConfiguration) FlowEntry(org.onosproject.net.flow.FlowEntry) DefaultFlowEntry(org.onosproject.net.flow.DefaultFlowEntry)

Example 14 with DefaultFlowEntry

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

the class FlowRuleManagerTest method flowMetrics.

@Test
public void flowMetrics() {
    FlowRule f1 = flowRule(1, 1);
    FlowRule f2 = flowRule(2, 2);
    FlowRule f3 = flowRule(3, 3);
    mgr.applyFlowRules(f1, f2, f3);
    FlowEntry fe1 = new DefaultFlowEntry(f1);
    FlowEntry fe2 = new DefaultFlowEntry(f2);
    // FlowRule updatedF1 = flowRule(f1, FlowRuleState.ADDED);
    // FlowRule updatedF2 = flowRule(f2, FlowRuleState.ADDED);
    providerService.pushFlowMetrics(DID, Lists.newArrayList(fe1, fe2));
    assertTrue("Entries should be added.", validateState(ImmutableMap.of(f1, FlowEntryState.ADDED, f2, FlowEntryState.ADDED, f3, FlowEntryState.PENDING_ADD)));
    validateEvents(RULE_ADD_REQUESTED, RULE_ADD_REQUESTED, RULE_ADD_REQUESTED, RULE_ADDED, RULE_ADDED, RULE_ADD_REQUESTED);
}
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 15 with DefaultFlowEntry

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

the class FlowRuleManagerTest 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());
    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.purgeFlowRules(DID);
    assertEquals("0 rule should exist", 0, 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)

Aggregations

DefaultFlowEntry (org.onosproject.net.flow.DefaultFlowEntry)44 FlowEntry (org.onosproject.net.flow.FlowEntry)38 FlowRule (org.onosproject.net.flow.FlowRule)31 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)7 Collectors (java.util.stream.Collectors)6 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 Set (java.util.Set)3