Java Code Examples for org.onosproject.net.flowobjective.FilteringObjective#Builder

The following examples show how to use org.onosproject.net.flowobjective.FilteringObjective#Builder . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FibInstaller.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Installs or removes unicast filtering objectives relating to an interface.
 *
 * @param routerIntf interface to update objectives for
 * @param install true to install the objectives, false to remove them
 */
private void updateFilteringObjective(InterfaceProvisionRequest routerIntf, boolean install) {
    Interface intf = routerIntf.intf();
    VlanId assignedVlan = (egressVlan().equals(VlanId.NONE)) ?
            VlanId.vlanId(ASSIGNED_VLAN) :
            egressVlan();

    FilteringObjective.Builder fob = DefaultFilteringObjective.builder();
    // first add filter for the interface
    fob.withKey(Criteria.matchInPort(intf.connectPoint().port()))
        .addCondition(Criteria.matchEthDst(intf.mac()))
        .addCondition(Criteria.matchVlanId(intf.vlan()));
    fob.withPriority(PRIORITY_OFFSET);
    if (intf.vlan() == VlanId.NONE) {
        TrafficTreatment tt = DefaultTrafficTreatment.builder()
                .pushVlan().setVlanId(assignedVlan).build();
        fob.withMeta(tt);
    }
    fob.permit().fromApp(fibAppId);
    sendFilteringObjective(install, fob, intf);

    // then add the same mac/vlan filters for control-plane connect point
    fob.withKey(Criteria.matchInPort(routerIntf.controlPlaneConnectPoint().port()));
    sendFilteringObjective(install, fob, intf);
}
 
Example 2
Source File: FibInstaller.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Installs or removes multicast filtering objectives relating to an interface.
 *
 * @param routerIntf interface to update objectives for
 * @param install true to install the objectives, false to remove them
 */
private void updateMcastFilteringObjective(InterfaceProvisionRequest routerIntf, boolean install) {
    Interface intf = routerIntf.intf();
    VlanId assignedVlan = (egressVlan().equals(VlanId.NONE)) ?
            VlanId.vlanId(ASSIGNED_VLAN) :
            egressVlan();

    FilteringObjective.Builder fob = DefaultFilteringObjective.builder();
    // first add filter for the interface
    fob.withKey(Criteria.matchInPort(intf.connectPoint().port()))
            .addCondition(Criteria.matchEthDstMasked(MacAddress.IPV4_MULTICAST,
                    MacAddress.IPV4_MULTICAST_MASK))
            .addCondition(Criteria.matchVlanId(ingressVlan()));
    fob.withPriority(PRIORITY_OFFSET);
    TrafficTreatment tt = DefaultTrafficTreatment.builder()
            .pushVlan().setVlanId(assignedVlan).build();
    fob.withMeta(tt);

    fob.permit().fromApp(fibAppId);
    sendFilteringObjective(install, fob, intf);
}
 
Example 3
Source File: RoutingRulePopulator.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Creates or removes filtering objectives for a double-tagged host on a port.
 *
 * @param deviceId device identifier
 * @param portNum  port identifier for port to be filtered
 * @param outerVlan outer VLAN ID
 * @param innerVlan inner VLAN ID
 * @param install true to install the filtering objective, false to remove
 */
void processDoubleTaggedFilter(DeviceId deviceId, PortNumber portNum, VlanId outerVlan,
                               VlanId innerVlan, boolean install) {
    // We should trigger the removal of double tagged rules only when removing
    // the filtering objective and no other hosts are connected to the same device port.
    boolean cleanupDoubleTaggedRules = !anyDoubleTaggedHost(deviceId, portNum) && !install;
    FilteringObjective.Builder fob = buildDoubleTaggedFilteringObj(deviceId, portNum,
                                                                   outerVlan, innerVlan,
                                                                   cleanupDoubleTaggedRules);
    if (fob == null) {
        // error encountered during build
        return;
    }
    log.debug("{} double-tagged filtering objectives for dev/port: {}/{}",
              install ? "Installing" : "Removing", deviceId, portNum);
    ObjectiveContext context = new DefaultObjectiveContext(
            (objective) -> log.debug("Filter for {}/{} {}", deviceId, portNum,
                                     install ? "installed" : "removed"),
            (objective, error) -> log.warn("Failed to {} filter for {}/{}: {}",
                                           install ? "install" : "remove", deviceId, portNum, error));
    if (install) {
        srManager.flowObjectiveService.filter(deviceId, fob.add(context));
    } else {
        srManager.flowObjectiveService.filter(deviceId, fob.remove(context));
    }
}
 
Example 4
Source File: McastUtils.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Adds filtering objective for given device and port.
 *
 * @param deviceId device ID
 * @param port ingress port number
 * @param assignedVlan assigned VLAN ID
 * @param mcastIp the group address
 * @param mcastRole the role of the device
 * @param matchOnMac match or not on macaddress
 */
void addFilterToDevice(DeviceId deviceId, PortNumber port, VlanId assignedVlan,
                       IpAddress mcastIp, McastRole mcastRole, boolean matchOnMac) {
    if (!srManager.deviceConfiguration().isConfigured(deviceId)) {
        log.debug("skip update of fitering objective for unconfigured device: {}", deviceId);
        return;
    }
    MacAddress routerMac = getRouterMac(deviceId, port);

    if (MacAddress.NONE.equals(routerMac)) {
        return;
    }
    FilteringObjective.Builder filtObjBuilder = filterObjBuilder(port, assignedVlan, mcastIp,
                                                                 routerMac, mcastRole, matchOnMac);
    ObjectiveContext context = new DefaultObjectiveContext(
            (objective) -> log.debug("Successfully add filter on {}/{}, vlan {}",
                                     deviceId, port.toLong(), assignedVlan),
            (objective, error) ->
                    log.warn("Failed to add filter on {}/{}, vlan {}: {}",
                             deviceId, port.toLong(), assignedVlan, error));
    srManager.flowObjectiveService.filter(deviceId, filtObjBuilder.add(context));
}
 
Example 5
Source File: McastUtils.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Removes filtering objective for given device and port.
 *
 * @param deviceId device ID
 * @param port ingress port number
 * @param assignedVlan assigned VLAN ID
 * @param mcastIp multicast IP address
 * @param mcastRole the multicast role of the device
 */
void removeFilterToDevice(DeviceId deviceId, PortNumber port, VlanId assignedVlan,
                          IpAddress mcastIp, McastRole mcastRole) {
    if (!srManager.deviceConfiguration().isConfigured(deviceId)) {
        log.debug("skip update of fitering objective for unconfigured device: {}", deviceId);
        return;
    }
    MacAddress routerMac = getRouterMac(deviceId, port);

    if (MacAddress.NONE.equals(routerMac)) {
        return;
    }
    FilteringObjective.Builder filtObjBuilder =
            filterObjBuilder(port, assignedVlan, mcastIp, routerMac, mcastRole, false);
    ObjectiveContext context = new DefaultObjectiveContext(
            (objective) -> log.debug("Successfully removed filter on {}/{}, vlan {}",
                                     deviceId, port.toLong(), assignedVlan),
            (objective, error) ->
                    log.warn("Failed to remove filter on {}/{}, vlan {}: {}",
                             deviceId, port.toLong(), assignedVlan, error));
    srManager.flowObjectiveService.filter(deviceId, filtObjBuilder.remove(context));
}
 
Example 6
Source File: DemoInstaller.java    From onos with Apache License 2.0 6 votes vote down vote up
private Set<FilteringObjective.Builder> createFilter(int flowObjPerDevice) {
    Set<FilteringObjective.Builder> filterObjSet = new HashSet<>();
    for (int i = 0; i < flowObjPerDevice; i++) {
        TrafficTreatment.Builder tbuilder = DefaultTrafficTreatment.builder();
        tbuilder.add(Instructions.createOutput(PortNumber.portNumber(2)));
        TrafficSelector.Builder sbuilder = DefaultTrafficSelector.builder();
        sbuilder.matchInPort(PortNumber.portNumber(i + 3L));
        sbuilder.matchEthDst(MacAddress.valueOf("12:00:00:00:00:10"));

        FilteringObjective.Builder fobBuilder = DefaultFilteringObjective.builder();
        fobBuilder.fromApp(appId)
                  .withKey(sbuilder.build().getCriterion(Criterion.Type.IN_PORT))
                  .addCondition(sbuilder.build().getCriterion(Criterion.Type.ETH_DST))
                  .withMeta(tbuilder.build())
                  .permit()
                  .withPriority(i + 1)
                  .makePermanent();

        filterObjSet.add(fobBuilder);
    }

    return filterObjSet;
}
 
Example 7
Source File: InOrderFlowObjectiveManagerTest.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Creates filtering objective builder with a serial number encoded in MPLS label.
 * The serial number is used to identify same objective that occurs multiple times.
 *
 * @param portnum Port number
 * @param vlanId VLAN Id
 * @param mac MAC address
 * @param serial Serial number
 * @return Filtering objective builder
 */
private static FilteringObjective.Builder buildFilteringObjective(PortNumber portnum, VlanId vlanId,
                                                                  MacAddress mac, int serial) {
    FilteringObjective.Builder fob = DefaultFilteringObjective.builder();
    fob.withKey(Criteria.matchInPort(portnum))
            .addCondition(Criteria.matchEthDst(mac))
            .addCondition(Criteria.matchVlanId(VlanId.NONE))
            .addCondition(Criteria.matchMplsLabel(MplsLabel.mplsLabel(serial)))
            .withPriority(PRIORITY);

    TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
    tBuilder.pushVlan().setVlanId(vlanId);
    fob.withMeta(tBuilder.build());

    fob.permit().fromApp(APP_ID);
    return fob;
}
 
Example 8
Source File: FibInstaller.java    From onos with Apache License 2.0 5 votes vote down vote up
private void sendFilteringObjective(boolean install, FilteringObjective.Builder fob,
                                    Interface intf) {

    ObjectiveContext context = new DefaultObjectiveContext(
            (objective) -> log.info("Installed filter for interface {}", intf),
            (objective, error) ->
                    log.error("Failed to install filter for interface {}: {}", intf, error));

    FilteringObjective filter = install ? fob.add(context) : fob.remove(context);

    flowObjectiveService.filter(deviceId, filter);
}
 
Example 9
Source File: DefaultL2TunnelHandler.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Creates the filtering objective according to a given policy.
 *
 * @param inPort   the in port
 * @param innerTag the inner vlan tag
 * @param outerTag the outer vlan tag
 * @return the filtering objective
 */
private FilteringObjective.Builder createFiltObjective(PortNumber inPort, VlanId innerTag, VlanId outerTag) {

    log.debug("Creating connection point filtering objective for vlans {} / {}", outerTag, innerTag);
    return DefaultFilteringObjective
            .builder()
            .withKey(Criteria.matchInPort(inPort))
            .addCondition(Criteria.matchInnerVlanId(innerTag))
            .addCondition(Criteria.matchVlanId(outerTag))
            .withPriority(SegmentRoutingService.DEFAULT_PRIORITY)
            .permit()
            .fromApp(srManager.appId());
}
 
Example 10
Source File: RoutingRulePopulator.java    From onos with Apache License 2.0 5 votes vote down vote up
private boolean processSinglePortFiltersInternal(DeviceId deviceId, PortNumber portnum,
                                                  boolean pushVlan, VlanId vlanId, boolean install) {
    boolean doTMAC = true;

    if (!pushVlan) {
        // Skip the tagged vlans belonging to an interface without an IP address
        Set<Interface> ifaces = srManager.interfaceService
                .getInterfacesByPort(new ConnectPoint(deviceId, portnum))
                .stream()
                .filter(intf -> intf.vlanTagged().contains(vlanId) && intf.ipAddressesList().isEmpty())
                .collect(Collectors.toSet());
        if (!ifaces.isEmpty()) {
            log.debug("processSinglePortFiltersInternal: skipping TMAC for vlan {} at {}/{} - no IP",
                      vlanId, deviceId, portnum);
            doTMAC = false;
        }
    }

    FilteringObjective.Builder fob = buildFilteringObjective(deviceId, portnum, pushVlan, vlanId, doTMAC);
    if (fob == null) {
        // error encountered during build
        return false;
    }
    log.debug("{} filtering objectives for dev/port: {}/{}",
             install ? "Installing" : "Removing", deviceId, portnum);
    ObjectiveContext context = new DefaultObjectiveContext(
            (objective) -> log.debug("Filter for {}/{} {}", deviceId, portnum,
                    install ? "installed" : "removed"),
            (objective, error) -> log.warn("Failed to {} filter for {}/{}: {}",
                    install ? "install" : "remove", deviceId, portnum, error));
    if (install) {
        srManager.flowObjectiveService.filter(deviceId, fob.add(context));
    } else {
        srManager.flowObjectiveService.filter(deviceId, fob.remove(context));
    }
    return true;
}
 
Example 11
Source File: McastUtils.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a filtering objective builder for multicast.
 *
 * @param ingressPort ingress port of the multicast stream
 * @param assignedVlan assigned VLAN ID
 * @param mcastIp the group address
 * @param routerMac router MAC. This is carried in metadata and used from some switches that
 *                  need to put unicast entry before multicast entry in TMAC table.
 * @param mcastRole the Multicast role
 * @param matchOnMac match or not on macaddress
 * @return filtering objective builder
 */
private FilteringObjective.Builder filterObjBuilder(PortNumber ingressPort, VlanId assignedVlan,
                                                    IpAddress mcastIp, MacAddress routerMac, McastRole mcastRole,
                                                    boolean matchOnMac) {
    FilteringObjective.Builder filtBuilder = DefaultFilteringObjective.builder();
    // Let's add the in port matching and the priority
    filtBuilder.withKey(Criteria.matchInPort(ingressPort))
            .withPriority(SegmentRoutingService.DEFAULT_PRIORITY);
    // According to the mcast role we match on the proper vlan
    // If the role is null we are on the transit or on the egress
    if (mcastRole == null) {
        filtBuilder.addCondition(Criteria.matchVlanId(egressVlan()));
    } else {
        filtBuilder.addCondition(Criteria.matchVlanId(ingressVlan()));
    }
    // Add vlan info to the treatment builder
    TrafficTreatment.Builder ttb = DefaultTrafficTreatment.builder()
            .pushVlan().setVlanId(assignedVlan);
    // Additionally match on mac address and augment the treatment
    if (matchOnMac) {
        // According to the IP type we set the proper match on the mac address
        if (mcastIp.isIp4()) {
            filtBuilder.addCondition(Criteria.matchEthDstMasked(MacAddress.IPV4_MULTICAST,
                    MacAddress.IPV4_MULTICAST_MASK));
        } else {
            filtBuilder.addCondition(Criteria.matchEthDstMasked(MacAddress.IPV6_MULTICAST,
                    MacAddress.IPV6_MULTICAST_MASK));
        }
        // We set mac address to the treatment
        if (routerMac != null && !routerMac.equals(MacAddress.NONE)) {
            ttb.setEthDst(routerMac);
        }
    }
    // We finally build the meta treatment
    TrafficTreatment tt = ttb.build();
    filtBuilder.withMeta(tt);
    // Done, we return a permit filtering objective
    return filtBuilder.permit().fromApp(srManager.appId());
}
 
Example 12
Source File: AppConfigHandler.java    From onos with Apache License 2.0 5 votes vote down vote up
private Set<FilteringObjective.Builder> getVRouterFlowObjBuilders(Set<MacAddress> macAddresses) {
    ImmutableSet.Builder<FilteringObjective.Builder> setBuilder = ImmutableSet.builder();
    macAddresses.forEach(macAddress -> {
        FilteringObjective.Builder fobuilder = DefaultFilteringObjective.builder();
        fobuilder.withKey(Criteria.matchInPort(PortNumber.ANY))
                .addCondition(Criteria.matchEthDst(macAddress))
                .permit()
                .withPriority(SegmentRoutingService.DEFAULT_PRIORITY)
                .fromApp(srManager.appId);
        setBuilder.add(fobuilder);
    });
    return setBuilder.build();
}
 
Example 13
Source File: XconnectManager.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a filtering objective builder for XConnect.
 *
 * @param key  XConnect key
 * @param port XConnect ports
 * @param filtered true if this is a filtered port
 * @return next objective builder
 */
private FilteringObjective.Builder filterObjBuilder(XconnectKey key, PortNumber port, boolean filtered) {
    FilteringObjective.Builder fob = DefaultFilteringObjective.builder();
    fob.withKey(Criteria.matchInPort(port))
            .addCondition(Criteria.matchEthDst(MacAddress.NONE))
            .withPriority(XCONNECT_PRIORITY);
    if (filtered) {
        fob.addCondition(Criteria.matchVlanId(key.vlanId()));
    } else {
        fob.addCondition(Criteria.matchVlanId(VlanId.ANY));
    }
    return fob.permit().fromApp(appId);
}
 
Example 14
Source File: RoutingRulePopulator.java    From onos with Apache License 2.0 4 votes vote down vote up
private FilteringObjective.Builder buildFilteringObjective(DeviceId deviceId, PortNumber portnum,
                                                           boolean pushVlan, VlanId vlanId, boolean doTMAC) {
    MacAddress deviceMac;
    try {
        deviceMac = config.getDeviceMac(deviceId);
    } catch (DeviceConfigNotFoundException e) {
        log.warn(e.getMessage() + " Processing SinglePortFilters aborted");
        return null;
    }
    FilteringObjective.Builder fob = DefaultFilteringObjective.builder();

    if (doTMAC) {
        fob.withKey(Criteria.matchInPort(portnum))
                .addCondition(Criteria.matchEthDst(deviceMac))
                .withPriority(SegmentRoutingService.DEFAULT_PRIORITY);
    } else {
        fob.withKey(Criteria.matchInPort(portnum))
                .withPriority(SegmentRoutingService.DEFAULT_PRIORITY);
    }

    TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();

    if (pushVlan) {
        fob.addCondition(Criteria.matchVlanId(VlanId.NONE));
        tBuilder.pushVlan().setVlanId(vlanId);
    } else {
        fob.addCondition(Criteria.matchVlanId(vlanId));
    }

    // NOTE: Some switch hardware share the same filtering flow among different ports.
    //       We use this metadata to let the driver know that there is no more enabled port
    //       within the same VLAN on this device.
    if (noMoreEnabledPort(deviceId, vlanId)) {
        tBuilder.wipeDeferred();
    }

    fob.withMeta(tBuilder.build());

    fob.permit().fromApp(srManager.appId);
    return fob;
}
 
Example 15
Source File: RoutingRulePopulator.java    From onos with Apache License 2.0 4 votes vote down vote up
private FilteringObjective.Builder buildDoubleTaggedFilteringObj(DeviceId deviceId, PortNumber portNum,
                                                                 VlanId outerVlan, VlanId innerVlan,
                                                                 boolean cleanupDoubleTaggedRules) {
    MacAddress deviceMac;
    try {
        deviceMac = config.getDeviceMac(deviceId);
    } catch (DeviceConfigNotFoundException e) {
        log.warn(e.getMessage() + " Processing DoubleTaggedFilters aborted");
        return null;
    }
    FilteringObjective.Builder fob = DefaultFilteringObjective.builder();
    // Outer vlan id match should be appeared before inner vlan id match.
    fob.withKey(Criteria.matchInPort(portNum))
            .addCondition(Criteria.matchEthDst(deviceMac))
            .addCondition(Criteria.matchVlanId(outerVlan))
            .addCondition(Criteria.matchInnerVlanId(innerVlan))
            .withPriority(SegmentRoutingService.DEFAULT_PRIORITY);

    TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
    // Pop outer vlan
    tBuilder.popVlan();

    // special metadata for driver
    if (cleanupDoubleTaggedRules) {
        tBuilder.writeMetadata(CLEANUP_DOUBLE_TAGGED_HOST_ENTRIES, DOUBLE_TAGGED_METADATA_MASK);
    } else {
        tBuilder.writeMetadata(0, DOUBLE_TAGGED_METADATA_MASK);
    }

    // NOTE: Some switch hardware share the same filtering flow among different ports.
    //       We use this metadata to let the driver know that there is no more enabled port
    //       within the same VLAN on this device.
    if (noMoreEnabledPort(deviceId, outerVlan)) {
        tBuilder.wipeDeferred();
    }

    fob.withMeta(tBuilder.build());

    fob.permit().fromApp(srManager.appId);
    return fob;
}
 
Example 16
Source File: LinkCollectionIntentFlowObjectiveCompiler.java    From onos with Apache License 2.0 4 votes vote down vote up
private FilteringObjective buildFilteringObjective(LinkCollectionIntent intent,
                                                   TrafficSelector selector,
                                                   DeviceId deviceId,
                                                   PortNumber inPort) {
    FilteringObjective.Builder builder = DefaultFilteringObjective.builder();
    builder.fromApp(appId)
            .permit()
            .makePermanent()
            .withPriority(intent.priority());
    Criterion inPortCriterion = selector.getCriterion(Criterion.Type.IN_PORT);
    if (inPortCriterion != null) {
        builder.withKey(inPortCriterion);
    }

    FilteredConnectPoint ingressPoint = intent.filteredIngressPoints().stream()
            .filter(fcp -> fcp.connectPoint().equals(new ConnectPoint(deviceId, inPort)))
            .filter(fcp -> selector.criteria().containsAll(fcp.trafficSelector().criteria()))
            .findFirst()
            .orElse(null);

    AtomicBoolean emptyCondition = new AtomicBoolean(true);
    if (ingressPoint != null) {
        // ingress point, use criterion of it
        ingressPoint.trafficSelector().criteria().forEach(criterion -> {
            builder.addCondition(criterion);
            emptyCondition.set(false);
        });
        if (emptyCondition.get()) {
            return null;
        }
        return builder.add();
    }
    Optional<EncapsulationConstraint> encapConstraint = this.getIntentEncapConstraint(intent);
    if (encapConstraint.isPresent() &&
            !encapConstraint.get().encapType().equals(EncapsulationType.NONE)) {
        // encapsulation enabled, use encapsulation label and tag.
        EncapsulationConstraint encap = encapConstraint.get();
        switch (encap.encapType()) {
            case VLAN:
                builder.addCondition(selector.getCriterion(Criterion.Type.VLAN_VID));
                emptyCondition.set(false);
                break;
            case MPLS:
                builder.addCondition(selector.getCriterion(Criterion.Type.MPLS_LABEL));
                emptyCondition.set(false);
                break;
            default:
                log.warn("No filtering rule found because of unknown encapsulation type.");
                break;
        }
    } else {
        // encapsulation not enabled, check if the treatment applied to the ingress or not
        if (intent.applyTreatmentOnEgress()) {
            // filtering criterion will be changed on egress point, use
            // criterion of ingress point
            ingressPoint = intent.filteredIngressPoints().stream()
                    .findFirst()
                    .orElse(null);
            if (ingressPoint == null) {
                log.warn("No filtering rule found because no ingress point in the Intent");
            } else {
                ingressPoint.trafficSelector().criteria().stream()
                        .filter(criterion -> !criterion.type().equals(Criterion.Type.IN_PORT))
                        .forEach(criterion -> {
                            builder.addCondition(criterion);
                            emptyCondition.set(false);
                        });
            }
        } else {
            // filtering criterion will be changed on ingress point, use
            // criterion of egress point
            FilteredConnectPoint egressPoint = intent.filteredEgressPoints().stream()
                    .findFirst()
                    .orElse(null);
            if (egressPoint == null) {
                log.warn("No filtering rule found because no egress point in the Intent");
            } else {
                egressPoint.trafficSelector().criteria().stream()
                        .filter(criterion -> !criterion.type().equals(Criterion.Type.IN_PORT))
                        .forEach(criterion -> {
                            builder.addCondition(criterion);
                            emptyCondition.set(false);
                        });
            }
        }
    }
    if (emptyCondition.get()) {
        return null;
    }
    return builder.add();
}