Search in sources :

Example 36 with FlowEntry

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

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

the class TelemetryVflowListCommand method doExecute.

@Override
protected void doExecute() {
    CoreService coreService = get(CoreService.class);
    FlowRuleService flowService = get(FlowRuleService.class);
    ApplicationId appId = coreService.getAppId(OPENSTACK_TELEMETRY_APP_ID);
    List<FlowEntry> flows = Lists.newArrayList(flowService.getFlowEntriesById(appId));
    print(FORMAT, "SrcIp", "SrcPort", "DstIp", "DstPort", "Protocol");
    for (FlowEntry entry : flows) {
        TrafficSelector selector = entry.selector();
        IpPrefix srcIp = ((IPCriterion) selector.getCriterion(IPV4_SRC)).ip();
        IpPrefix dstIp = ((IPCriterion) selector.getCriterion(IPV4_DST)).ip();
        TpPort srcPort = TpPort.tpPort(0);
        TpPort dstPort = TpPort.tpPort(0);
        String protocolStr = "ANY";
        Criterion ipProtocolCriterion = selector.getCriterion(IP_PROTO);
        if (ipProtocolCriterion != null) {
            short protocol = ((IPProtocolCriterion) selector.getCriterion(IP_PROTO)).protocol();
            if (protocol == PROTOCOL_TCP) {
                srcPort = ((TcpPortCriterion) selector.getCriterion(TCP_SRC)).tcpPort();
                dstPort = ((TcpPortCriterion) selector.getCriterion(TCP_DST)).tcpPort();
                protocolStr = TCP;
            }
            if (protocol == PROTOCOL_UDP) {
                srcPort = ((UdpPortCriterion) selector.getCriterion(UDP_SRC)).udpPort();
                dstPort = ((UdpPortCriterion) selector.getCriterion(UDP_SRC)).udpPort();
                protocolStr = UDP;
            }
        }
        print(FORMAT, srcIp.toString(), srcPort.toString(), dstIp.toString(), dstPort.toString(), protocolStr);
    }
}
Also used : IPCriterion(org.onosproject.net.flow.criteria.IPCriterion) CoreService(org.onosproject.core.CoreService) IpPrefix(org.onlab.packet.IpPrefix) IPProtocolCriterion(org.onosproject.net.flow.criteria.IPProtocolCriterion) TcpPortCriterion(org.onosproject.net.flow.criteria.TcpPortCriterion) IPCriterion(org.onosproject.net.flow.criteria.IPCriterion) Criterion(org.onosproject.net.flow.criteria.Criterion) UdpPortCriterion(org.onosproject.net.flow.criteria.UdpPortCriterion) IPProtocolCriterion(org.onosproject.net.flow.criteria.IPProtocolCriterion) TrafficSelector(org.onosproject.net.flow.TrafficSelector) TpPort(org.onlab.packet.TpPort) FlowRuleService(org.onosproject.net.flow.FlowRuleService) ApplicationId(org.onosproject.core.ApplicationId) FlowEntry(org.onosproject.net.flow.FlowEntry)

Example 38 with FlowEntry

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

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

Example 40 with FlowEntry

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

the class FlowRuleManagerTest method flowMissingRemove.

/*
     * Tests whether a rule that was marked for removal but no flowRemoved was received
     * is indeed removed at the next stats update.
     */
@Test
public void flowMissingRemove() {
    FlowRule f1 = flowRule(1, 1);
    FlowRule f2 = flowRule(2, 2);
    FlowRule f3 = flowRule(3, 3);
    // FlowRule updatedF1 = flowRule(f1, FlowRuleState.ADDED);
    // FlowRule updatedF2 = flowRule(f2, FlowRuleState.ADDED);
    FlowEntry fe1 = new DefaultFlowEntry(f1);
    FlowEntry fe2 = new DefaultFlowEntry(f2);
    mgr.applyFlowRules(f1, f2, f3);
    mgr.removeFlowRules(f3);
    providerService.pushFlowMetrics(DID, Lists.newArrayList(fe1, fe2));
    validateEvents(RULE_ADD_REQUESTED, RULE_ADD_REQUESTED, RULE_ADD_REQUESTED, RULE_REMOVE_REQUESTED, RULE_ADDED, RULE_ADDED, RULE_REMOVED);
}
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

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