Search in sources :

Example 41 with PortCriterion

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

the class FlowRuleCodecTest method codecCriteriaFlowTest.

/**
 * Checks that a rule with one of each kind of criterion decodes properly.
 *
 * @throws IOException if the resource cannot be processed
 */
@Test
public void codecCriteriaFlowTest() throws Exception {
    FlowRule rule = getRule("criteria-flow.json");
    checkCommonData(rule);
    assertThat(rule.selector().criteria().size(), is(35));
    rule.selector().criteria().forEach(criterion -> criteria.put(criterion.type().name(), criterion));
    Criterion criterion;
    criterion = getCriterion(Criterion.Type.ETH_TYPE);
    assertThat(((EthTypeCriterion) criterion).ethType(), is(new EthType(2054)));
    criterion = getCriterion(Criterion.Type.ETH_DST);
    assertThat(((EthCriterion) criterion).mac(), is(MacAddress.valueOf("00:11:22:33:44:55")));
    criterion = getCriterion(Criterion.Type.ETH_SRC);
    assertThat(((EthCriterion) criterion).mac(), is(MacAddress.valueOf("00:11:22:33:44:55")));
    criterion = getCriterion(Criterion.Type.IN_PORT);
    assertThat(((PortCriterion) criterion).port(), is(PortNumber.portNumber(23)));
    criterion = getCriterion(Criterion.Type.IN_PHY_PORT);
    assertThat(((PortCriterion) criterion).port(), is(PortNumber.portNumber(44)));
    criterion = getCriterion(Criterion.Type.VLAN_VID);
    assertThat(((VlanIdCriterion) criterion).vlanId(), is(VlanId.vlanId((short) 777)));
    criterion = getCriterion(Criterion.Type.VLAN_PCP);
    assertThat(((VlanPcpCriterion) criterion).priority(), is(((byte) 3)));
    criterion = getCriterion(Criterion.Type.IP_DSCP);
    assertThat(((IPDscpCriterion) criterion).ipDscp(), is(((byte) 2)));
    criterion = getCriterion(Criterion.Type.IP_ECN);
    assertThat(((IPEcnCriterion) criterion).ipEcn(), is(((byte) 1)));
    criterion = getCriterion(Criterion.Type.IP_PROTO);
    assertThat(((IPProtocolCriterion) criterion).protocol(), is(((short) 4)));
    criterion = getCriterion(Criterion.Type.IPV4_SRC);
    assertThat(((IPCriterion) criterion).ip(), is((IpPrefix.valueOf("1.2.0.0/32"))));
    criterion = getCriterion(Criterion.Type.IPV4_DST);
    assertThat(((IPCriterion) criterion).ip(), is((IpPrefix.valueOf("2.2.0.0/32"))));
    criterion = getCriterion(Criterion.Type.IPV6_SRC);
    assertThat(((IPCriterion) criterion).ip(), is((IpPrefix.valueOf("3.2.0.0/32"))));
    criterion = getCriterion(Criterion.Type.IPV6_DST);
    assertThat(((IPCriterion) criterion).ip(), is((IpPrefix.valueOf("4.2.0.0/32"))));
    criterion = getCriterion(Criterion.Type.TCP_SRC);
    assertThat(((TcpPortCriterion) criterion).tcpPort().toInt(), is(80));
    criterion = getCriterion(Criterion.Type.TCP_DST);
    assertThat(((TcpPortCriterion) criterion).tcpPort().toInt(), is(443));
    criterion = getCriterion(Criterion.Type.UDP_SRC);
    assertThat(((UdpPortCriterion) criterion).udpPort().toInt(), is(180));
    criterion = getCriterion(Criterion.Type.UDP_DST);
    assertThat(((UdpPortCriterion) criterion).udpPort().toInt(), is(1443));
    criterion = getCriterion(Criterion.Type.SCTP_SRC);
    assertThat(((SctpPortCriterion) criterion).sctpPort().toInt(), is(280));
    criterion = getCriterion(Criterion.Type.SCTP_DST);
    assertThat(((SctpPortCriterion) criterion).sctpPort().toInt(), is(2443));
    criterion = getCriterion(Criterion.Type.ICMPV4_TYPE);
    assertThat(((IcmpTypeCriterion) criterion).icmpType(), is((short) 24));
    criterion = getCriterion(Criterion.Type.ICMPV4_CODE);
    assertThat(((IcmpCodeCriterion) criterion).icmpCode(), is((short) 16));
    criterion = getCriterion(Criterion.Type.ICMPV6_TYPE);
    assertThat(((Icmpv6TypeCriterion) criterion).icmpv6Type(), is((short) 14));
    criterion = getCriterion(Criterion.Type.ICMPV6_CODE);
    assertThat(((Icmpv6CodeCriterion) criterion).icmpv6Code(), is((short) 6));
    criterion = getCriterion(Criterion.Type.IPV6_FLABEL);
    assertThat(((IPv6FlowLabelCriterion) criterion).flowLabel(), is(8));
    criterion = getCriterion(Criterion.Type.IPV6_ND_TARGET);
    assertThat(((IPv6NDTargetAddressCriterion) criterion).targetAddress().toString(), is("1111:2222:3333:4444:5555:6666:7777:8888"));
    criterion = getCriterion(Criterion.Type.IPV6_ND_SLL);
    assertThat(((IPv6NDLinkLayerAddressCriterion) criterion).mac(), is(MacAddress.valueOf("00:11:22:33:44:56")));
    criterion = getCriterion(Criterion.Type.IPV6_ND_TLL);
    assertThat(((IPv6NDLinkLayerAddressCriterion) criterion).mac(), is(MacAddress.valueOf("00:11:22:33:44:57")));
    criterion = getCriterion(Criterion.Type.MPLS_LABEL);
    assertThat(((MplsCriterion) criterion).label(), is(MplsLabel.mplsLabel(123)));
    criterion = getCriterion(Criterion.Type.IPV6_EXTHDR);
    assertThat(((IPv6ExthdrFlagsCriterion) criterion).exthdrFlags(), is(99));
    criterion = getCriterion(Criterion.Type.TUNNEL_ID);
    assertThat(((TunnelIdCriterion) criterion).tunnelId(), is(100L));
    criterion = getCriterion(Criterion.Type.OCH_SIGTYPE);
    assertThat(((OchSignalTypeCriterion) criterion).signalType(), is(OchSignalType.FIXED_GRID));
    criterion = getCriterion(Criterion.Type.ODU_SIGTYPE);
    assertThat(((OduSignalTypeCriterion) criterion).signalType(), is(OduSignalType.ODU4));
    criterion = getCriterion(Criterion.Type.ODU_SIGID);
    assertThat(((OduSignalIdCriterion) criterion).oduSignalId().tributaryPortNumber(), is(1));
    assertThat(((OduSignalIdCriterion) criterion).oduSignalId().tributarySlotLength(), is(80));
    assertThat(((OduSignalIdCriterion) criterion).oduSignalId().tributarySlotBitmap(), is(new byte[] { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }));
}
Also used : EthType(org.onlab.packet.EthType) IPDscpCriterion(org.onosproject.net.flow.criteria.IPDscpCriterion) VlanPcpCriterion(org.onosproject.net.flow.criteria.VlanPcpCriterion) IPProtocolCriterion(org.onosproject.net.flow.criteria.IPProtocolCriterion) PortCriterion(org.onosproject.net.flow.criteria.PortCriterion) IcmpTypeCriterion(org.onosproject.net.flow.criteria.IcmpTypeCriterion) OchSignalCriterion(org.onosproject.net.flow.criteria.OchSignalCriterion) IPCriterion(org.onosproject.net.flow.criteria.IPCriterion) IcmpCodeCriterion(org.onosproject.net.flow.criteria.IcmpCodeCriterion) IPv6NDTargetAddressCriterion(org.onosproject.net.flow.criteria.IPv6NDTargetAddressCriterion) Icmpv6TypeCriterion(org.onosproject.net.flow.criteria.Icmpv6TypeCriterion) SctpPortCriterion(org.onosproject.net.flow.criteria.SctpPortCriterion) TunnelIdCriterion(org.onosproject.net.flow.criteria.TunnelIdCriterion) MplsCriterion(org.onosproject.net.flow.criteria.MplsCriterion) IPv6NDLinkLayerAddressCriterion(org.onosproject.net.flow.criteria.IPv6NDLinkLayerAddressCriterion) EthCriterion(org.onosproject.net.flow.criteria.EthCriterion) IPEcnCriterion(org.onosproject.net.flow.criteria.IPEcnCriterion) OduSignalTypeCriterion(org.onosproject.net.flow.criteria.OduSignalTypeCriterion) TcpPortCriterion(org.onosproject.net.flow.criteria.TcpPortCriterion) Criterion(org.onosproject.net.flow.criteria.Criterion) EthTypeCriterion(org.onosproject.net.flow.criteria.EthTypeCriterion) OduSignalIdCriterion(org.onosproject.net.flow.criteria.OduSignalIdCriterion) UdpPortCriterion(org.onosproject.net.flow.criteria.UdpPortCriterion) Icmpv6CodeCriterion(org.onosproject.net.flow.criteria.Icmpv6CodeCriterion) OchSignalTypeCriterion(org.onosproject.net.flow.criteria.OchSignalTypeCriterion) IPv6FlowLabelCriterion(org.onosproject.net.flow.criteria.IPv6FlowLabelCriterion) IPv6ExthdrFlagsCriterion(org.onosproject.net.flow.criteria.IPv6ExthdrFlagsCriterion) VlanIdCriterion(org.onosproject.net.flow.criteria.VlanIdCriterion) TcpPortCriterion(org.onosproject.net.flow.criteria.TcpPortCriterion) IPv6NDTargetAddressCriterion(org.onosproject.net.flow.criteria.IPv6NDTargetAddressCriterion) UdpPortCriterion(org.onosproject.net.flow.criteria.UdpPortCriterion) OduSignalIdCriterion(org.onosproject.net.flow.criteria.OduSignalIdCriterion) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) SctpPortCriterion(org.onosproject.net.flow.criteria.SctpPortCriterion) Test(org.junit.Test)

Example 42 with PortCriterion

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

the class Ofdpa3Pipeline method processDoubleTaggedFilter.

/**
 * Configure filtering rules of outer and inner VLAN IDs, and a MAC address.
 * Filtering happens in three tables (VLAN_TABLE, VLAN_1_TABLE, TMAC_TABLE).
 *
 * @param filteringObjective the filtering objective
 * @param install            true to add, false to remove
 * @param applicationId      for application programming this filter
 */
private void processDoubleTaggedFilter(FilteringObjective filteringObjective, boolean install, ApplicationId applicationId) {
    PortCriterion portCriterion = null;
    EthCriterion ethCriterion = null;
    VlanIdCriterion innervidCriterion = null;
    VlanIdCriterion outerVidCriterion = null;
    boolean popVlan = false;
    boolean removeDoubleTagged = true;
    if (filteringObjective.meta().writeMetadata() != null) {
        removeDoubleTagged = shouldRemoveDoubleTagged(filteringObjective.meta().writeMetadata());
    }
    log.info("HERE , removeDoubleTagged {}", removeDoubleTagged);
    TrafficTreatment meta = filteringObjective.meta();
    if (!filteringObjective.key().equals(Criteria.dummy()) && filteringObjective.key().type() == Criterion.Type.IN_PORT) {
        portCriterion = (PortCriterion) filteringObjective.key();
    }
    if (portCriterion == null) {
        log.warn("No IN_PORT defined in filtering objective from app: {}" + "Failed to program VLAN tables.", applicationId);
        return;
    } else {
        log.debug("Received filtering objective for dev/port: {}/{}", deviceId, portCriterion.port());
    }
    // meta should have only one instruction, popVlan.
    if (meta != null && meta.allInstructions().size() == 1) {
        L2ModificationInstruction l2Inst = (L2ModificationInstruction) meta.allInstructions().get(0);
        if (l2Inst.subtype().equals(L2SubType.VLAN_POP)) {
            popVlan = true;
        } else {
            log.warn("Filtering objective can have only VLAN_POP instruction.");
            return;
        }
    } else {
        log.warn("Filtering objective should have one instruction.");
        return;
    }
    FlowRuleOperations.Builder ops = FlowRuleOperations.builder();
    for (Criterion criterion : filteringObjective.conditions()) {
        switch(criterion.type()) {
            case ETH_DST:
            case ETH_DST_MASKED:
                ethCriterion = (EthCriterion) criterion;
                break;
            case VLAN_VID:
                outerVidCriterion = (VlanIdCriterion) criterion;
                break;
            case INNER_VLAN_VID:
                innervidCriterion = (VlanIdCriterion) criterion;
                break;
            default:
                log.warn("Unsupported filter {}", criterion);
                fail(filteringObjective, ObjectiveError.UNSUPPORTED);
                return;
        }
    }
    if (innervidCriterion == null || outerVidCriterion == null) {
        log.warn("filtering objective should have two vidCriterion.");
        return;
    }
    if (ethCriterion == null || ethCriterion.mac().equals(NONE)) {
        // NOTE: it is possible that a filtering objective only has vidCriterion
        log.warn("filtering objective missing dstMac, cannot program TMAC table");
        return;
    } else {
        MacAddress unicastMac = readEthDstFromTreatment(filteringObjective.meta());
        List<List<FlowRule>> allStages = processEthDstFilter(portCriterion, ethCriterion, innervidCriterion, innervidCriterion.vlanId(), unicastMac, applicationId);
        for (List<FlowRule> flowRules : allStages) {
            log.trace("Starting a new flow rule stage for TMAC table flow");
            ops.newStage();
            for (FlowRule flowRule : flowRules) {
                log.trace("{} flow rules in TMAC table: {} for dev: {}", (install) ? "adding" : "removing", flowRules, deviceId);
                if (install) {
                    ops = ops.add(flowRule);
                } else {
                    // same VLAN on this device if TMAC doesn't support matching on in_port.
                    if (matchInPortTmacTable() || (filteringObjective.meta() != null && filteringObjective.meta().clearedDeferred())) {
                        // if metadata instruction not null and not removeDoubleTagged move on.
                        if ((filteringObjective.meta().writeMetadata() != null) && (!removeDoubleTagged)) {
                            log.info("Skipping removal of tmac rule for device {}", deviceId);
                            continue;
                        } else {
                            ops = ops.remove(flowRule);
                        }
                    } else {
                        log.debug("Abort TMAC flow removal on {}. Some other ports still share this TMAC flow");
                    }
                }
            }
        }
    }
    List<FlowRule> rules;
    rules = processDoubleVlanIdFilter(portCriterion, innervidCriterion, outerVidCriterion, popVlan, applicationId);
    for (FlowRule flowRule : rules) {
        log.trace("{} flow rule in VLAN table: {} for dev: {}", (install) ? "adding" : "removing", flowRule, deviceId);
        // if context is remove, table is vlan_1 and removeDoubleTagged is false, continue.
        if (flowRule.table().equals(IndexTableId.of(VLAN_TABLE)) && !removeDoubleTagged && !install) {
            log.info("Skipping removal of vlan table rule for now!");
            continue;
        }
        ops = install ? ops.add(flowRule) : ops.remove(flowRule);
    }
    // apply filtering flow rules
    flowRuleService.apply(ops.build(new FlowRuleOperationsContext() {

        @Override
        public void onSuccess(FlowRuleOperations ops) {
            log.debug("Applied {} filtering rules in device {}", ops.stages().get(0).size(), deviceId);
            pass(filteringObjective);
        }

        @Override
        public void onError(FlowRuleOperations ops) {
            log.info("Failed to apply all filtering rules in dev {}", deviceId);
            fail(filteringObjective, ObjectiveError.FLOWINSTALLATIONFAILED);
        }
    }));
}
Also used : FlowRuleOperations(org.onosproject.net.flow.FlowRuleOperations) EthCriterion(org.onosproject.net.flow.criteria.EthCriterion) L2ModificationInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction) PortCriterion(org.onosproject.net.flow.criteria.PortCriterion) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) MacAddress(org.onlab.packet.MacAddress) PortCriterion(org.onosproject.net.flow.criteria.PortCriterion) TunnelIdCriterion(org.onosproject.net.flow.criteria.TunnelIdCriterion) EthCriterion(org.onosproject.net.flow.criteria.EthCriterion) Criterion(org.onosproject.net.flow.criteria.Criterion) VlanIdCriterion(org.onosproject.net.flow.criteria.VlanIdCriterion) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) FlowRuleOperationsContext(org.onosproject.net.flow.FlowRuleOperationsContext) VlanIdCriterion(org.onosproject.net.flow.criteria.VlanIdCriterion)

Example 43 with PortCriterion

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

the class SpringOpenTTP method processVlanIdFilter.

protected List<FlowRule> processVlanIdFilter(VlanIdCriterion vlanIdCriterion, FilteringObjective filt, VlanId assignedVlan, VlanId explicitlyAssignedVlan, VlanId pushedVlan, boolean pushVlan, boolean popVlan, ApplicationId applicationId) {
    List<FlowRule> rules = new ArrayList<>();
    log.debug("adding rule for VLAN: {}", vlanIdCriterion.vlanId());
    TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
    TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();
    PortCriterion p = (PortCriterion) filt.key();
    if (vlanIdCriterion.vlanId() != VlanId.NONE) {
        selector.matchVlanId(vlanIdCriterion.vlanId());
        selector.matchInPort(p.port());
        if (popVlan) {
            // Pop outer tag
            treatment.immediate().popVlan();
        }
        if (explicitlyAssignedVlan != null && (!popVlan || !vlanIdCriterion.vlanId().equals(assignedVlan))) {
            // Modify VLAN ID on single tagged packet or modify remaining tag after popping
            // In the first case, do not set VLAN ID again to the already existing value
            treatment.immediate().setVlanId(explicitlyAssignedVlan);
        }
        if (pushVlan) {
            // Push new tag
            treatment.immediate().pushVlan().setVlanId(pushedVlan);
        }
    } else {
        selector.matchInPort(p.port());
        treatment.immediate().pushVlan().setVlanId(assignedVlan);
    }
    treatment.transition(tmacTableId);
    FlowRule rule = DefaultFlowRule.builder().forDevice(deviceId).withSelector(selector.build()).withTreatment(treatment.build()).withPriority(filt.priority()).fromApp(applicationId).makePermanent().forTable(vlanTableId).build();
    rules.add(rule);
    return rules;
}
Also used : ArrayList(java.util.ArrayList) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) PortCriterion(org.onosproject.net.flow.criteria.PortCriterion) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment)

Example 44 with PortCriterion

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

the class CentecV350Pipeline method processFilter.

private void processFilter(FilteringObjective filt, boolean install, ApplicationId applicationId) {
    PortCriterion p;
    if (!filt.key().equals(Criteria.dummy()) && filt.key().type() == Criterion.Type.IN_PORT) {
        p = (PortCriterion) filt.key();
    } else {
        log.warn("No key defined in filtering objective from app: {}. Not" + "processing filtering objective", applicationId);
        fail(filt, ObjectiveError.UNKNOWN);
        return;
    }
    // Convert filtering conditions for switch-intfs into flow rules.
    FlowRuleOperations.Builder ops = FlowRuleOperations.builder();
    for (Criterion c : filt.conditions()) {
        // Here we do a trick to install 2 flow rules to MAC_TABLE and ROUTE_TABLE.
        if (c.type() == Criterion.Type.ETH_DST) {
            EthCriterion e = (EthCriterion) c;
            // Install TMAC flow rule.
            log.debug("adding rule for Termination MAC in Filter Table: {}", e.mac());
            TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
            TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();
            selector.matchEthDst(e.mac());
            // Add IPv4 matching explicitly since we will redirect it to ROUTE Table
            // through MAC table.
            selector.matchEthType(Ethernet.TYPE_IPV4);
            treatment.transition(MAC_TABLE);
            FlowRule rule = DefaultFlowRule.builder().forDevice(deviceId).withSelector(selector.build()).withTreatment(treatment.build()).withPriority(FILTER_TABLE_TMAC_PRIORITY).fromApp(applicationId).makePermanent().forTable(FILTER_TABLE).build();
            ops = install ? ops.add(rule) : ops.remove(rule);
            // Must install another rule to direct the IPv4 packets that hit TMAC to
            // Route table.
            log.debug("adding rule for Termination MAC in MAC Table: {}", e.mac());
            selector = DefaultTrafficSelector.builder();
            treatment = DefaultTrafficTreatment.builder();
            selector.matchEthDst(e.mac());
            // MAC_Table must have metadata matching configured, use the default metadata.
            selector.matchMetadata(DEFAULT_METADATA);
            treatment.transition(ROUTE_TABLE);
            rule = DefaultFlowRule.builder().forDevice(deviceId).withSelector(selector.build()).withTreatment(treatment.build()).withPriority(MAC_TABLE_PRIORITY).fromApp(applicationId).makePermanent().forTable(MAC_TABLE).build();
            ops = install ? ops.add(rule) : ops.remove(rule);
        } else if (c.type() == Criterion.Type.VLAN_VID) {
            VlanIdCriterion v = (VlanIdCriterion) c;
            log.debug("adding rule for VLAN: {}", v.vlanId());
            TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
            TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();
            selector.matchVlanId(v.vlanId());
            selector.matchInPort(p.port());
            // Although the accepted packets will be sent to filter table, we must
            // explicitly set goto_table instruction here.
            treatment.writeMetadata(DEFAULT_METADATA, DEFAULT_METADATA_MASK);
            // set default metadata written by PORT_VLAN Table.
            treatment.transition(FILTER_TABLE);
            // We do not support strip vlan here, treatment.deferred().popVlan();
            // PORT_VLAN table only accept 0xffff priority since it does exact match only.
            FlowRule rule = DefaultFlowRule.builder().forDevice(deviceId).withSelector(selector.build()).withTreatment(treatment.build()).withPriority(PORT_VLAN_TABLE_PRIORITY).fromApp(applicationId).makePermanent().forTable(PORT_VLAN_TABLE).build();
            ops = install ? ops.add(rule) : ops.remove(rule);
        } else if (c.type() == Criterion.Type.IPV4_DST) {
            IPCriterion ipaddr = (IPCriterion) c;
            log.debug("adding IP filtering rules in FILTER table: {}", ipaddr.ip());
            TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
            TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();
            selector.matchEthType(Ethernet.TYPE_IPV4);
            // router IPs to the controller
            selector.matchIPDst(ipaddr.ip());
            treatment.setOutput(PortNumber.CONTROLLER);
            FlowRule rule = DefaultFlowRule.builder().forDevice(deviceId).withSelector(selector.build()).withTreatment(treatment.build()).withPriority(FILTER_TABLE_CONTROLLER_PRIORITY).fromApp(applicationId).makePermanent().forTable(FILTER_TABLE).build();
            ops = install ? ops.add(rule) : ops.remove(rule);
        } else {
            log.warn("Driver does not currently process filtering condition" + " of type: {}", c.type());
            fail(filt, ObjectiveError.UNSUPPORTED);
        }
    }
    // apply filtering flow rules
    flowRuleService.apply(ops.build(new FlowRuleOperationsContext() {

        @Override
        public void onSuccess(FlowRuleOperations ops) {
            pass(filt);
            log.info("Applied filtering rules");
        }

        @Override
        public void onError(FlowRuleOperations ops) {
            fail(filt, ObjectiveError.FLOWINSTALLATIONFAILED);
            log.info("Failed to apply filtering rules");
        }
    }));
}
Also used : FlowRuleOperations(org.onosproject.net.flow.FlowRuleOperations) EthCriterion(org.onosproject.net.flow.criteria.EthCriterion) IPCriterion(org.onosproject.net.flow.criteria.IPCriterion) CacheBuilder(com.google.common.cache.CacheBuilder) PortCriterion(org.onosproject.net.flow.criteria.PortCriterion) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) PortCriterion(org.onosproject.net.flow.criteria.PortCriterion) IPCriterion(org.onosproject.net.flow.criteria.IPCriterion) EthCriterion(org.onosproject.net.flow.criteria.EthCriterion) Criterion(org.onosproject.net.flow.criteria.Criterion) EthTypeCriterion(org.onosproject.net.flow.criteria.EthTypeCriterion) VlanIdCriterion(org.onosproject.net.flow.criteria.VlanIdCriterion) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) FlowRuleOperationsContext(org.onosproject.net.flow.FlowRuleOperationsContext) VlanIdCriterion(org.onosproject.net.flow.criteria.VlanIdCriterion)

Example 45 with PortCriterion

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

the class PolatisInternalConnectivity method getOutputPorts.

/**
 * Returns a set of possible output PortNumbers to which a given input port can be internally connected
 * on a given device.
 * <p>
 * This is a callback method required by the InternalConnectivity behaviour.
 * @param inputPortNum Input port number on device
 * @return             List of possible output ports
 */
@Override
public Set<PortNumber> getOutputPorts(PortNumber inputPortNum) {
    // NOTE: in this implementation, inputPortNum is the supplied port number and
    // can be an "input" port OR an "output" port
    // This reflects the fact that reverse propagation is possible through a Polatis switch
    // (output port -> input port)
    Set<PortNumber> ports = new HashSet<PortNumber>();
    Set<PortNumber> enabledPorts = new HashSet<PortNumber>();
    Collection<FlowEntry> flowEntries = parseConnections(this);
    // e.g. one selector (IN_PORT) and one action (set output port)
    if (flowEntries.stream().map(flow -> ((PortCriterion) flow.selector().getCriterion(Criterion.Type.IN_PORT)).port()).collect(Collectors.toSet()).contains(inputPortNum) || flowEntries.stream().map(flow -> ((OutputInstruction) flow.treatment().allInstructions().get(0)).port()).collect(Collectors.toSet()).contains(inputPortNum)) {
        log.warn("Queried port {} is already used in a cross-connect", inputPortNum);
        return ports;
    } else {
        DeviceId deviceID = handler().data().deviceId();
        DeviceService deviceService = checkNotNull(this.handler().get(DeviceService.class));
        Port inputPort = deviceService.getPort(new ConnectPoint(deviceID, inputPortNum));
        if (inputPort.annotations().value(KEY_PORTDIR).equals(VALUE_CC)) {
            ports = deviceService.getPorts(deviceID).stream().filter(p -> !p.equals(inputPortNum)).map(p -> p.number()).collect(Collectors.toSet());
        } else {
            ports = deviceService.getPorts(deviceID).stream().filter((p) -> {
                Port port = deviceService.getPort(new ConnectPoint(deviceID, p.number()));
                return !port.annotations().value(KEY_PORTDIR).equals(inputPort.annotations().value(KEY_PORTDIR));
            }).map(p -> p.number()).collect(Collectors.toSet());
        }
        // Remove disabled ports
        enabledPorts = ports.stream().filter(p -> deviceService.getPort(new ConnectPoint(deviceID, p)).isEnabled()).collect(Collectors.toSet());
    }
    log.debug("Ports before filtering out used and disabled ones: " + ports);
    return filterUsedPorts(enabledPorts, flowEntries);
}
Also used : OutputInstruction(org.onosproject.net.flow.instructions.Instructions.OutputInstruction) Logger(org.slf4j.Logger) KEY_PORTDIR(org.onosproject.drivers.polatis.netconf.PolatisNetconfUtility.KEY_PORTDIR) InternalConnectivity(org.onosproject.net.behaviour.InternalConnectivity) Collection(java.util.Collection) PortNumber(org.onosproject.net.PortNumber) DeviceService(org.onosproject.net.device.DeviceService) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) FlowEntry(org.onosproject.net.flow.FlowEntry) Set(java.util.Set) PortCriterion(org.onosproject.net.flow.criteria.PortCriterion) Collectors(java.util.stream.Collectors) ConnectPoint(org.onosproject.net.ConnectPoint) AbstractHandlerBehaviour(org.onosproject.net.driver.AbstractHandlerBehaviour) HashSet(java.util.HashSet) Port(org.onosproject.net.Port) PolatisUtility(org.onosproject.drivers.polatis.netconf.PolatisUtility) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) DeviceId(org.onosproject.net.DeviceId) Criterion(org.onosproject.net.flow.criteria.Criterion) OutputInstruction(org.onosproject.net.flow.instructions.Instructions.OutputInstruction) DeviceId(org.onosproject.net.DeviceId) Port(org.onosproject.net.Port) DeviceService(org.onosproject.net.device.DeviceService) PortCriterion(org.onosproject.net.flow.criteria.PortCriterion) PortNumber(org.onosproject.net.PortNumber) FlowEntry(org.onosproject.net.flow.FlowEntry) ConnectPoint(org.onosproject.net.ConnectPoint) HashSet(java.util.HashSet)

Aggregations

PortCriterion (org.onosproject.net.flow.criteria.PortCriterion)55 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)34 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)32 FlowRule (org.onosproject.net.flow.FlowRule)32 VlanIdCriterion (org.onosproject.net.flow.criteria.VlanIdCriterion)28 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)26 TrafficSelector (org.onosproject.net.flow.TrafficSelector)25 List (java.util.List)24 Criterion (org.onosproject.net.flow.criteria.Criterion)24 Test (org.junit.Test)22 Intent (org.onosproject.net.intent.Intent)21 CoreService (org.onosproject.core.CoreService)20 FilteredConnectPoint (org.onosproject.net.FilteredConnectPoint)20 PortNumber (org.onosproject.net.PortNumber)20 LinkCollectionIntent (org.onosproject.net.intent.LinkCollectionIntent)20 DeviceId (org.onosproject.net.DeviceId)18 DefaultFlowRule (org.onosproject.net.flow.DefaultFlowRule)18 MplsCriterion (org.onosproject.net.flow.criteria.MplsCriterion)18 Collection (java.util.Collection)16 Collectors (java.util.stream.Collectors)16