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

The following examples show how to use org.onosproject.net.flowobjective.ForwardingObjective#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: XconnectManager.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Creates an ACL forwarding objective builder for XConnect.
 *
 * @param vlanId cross connect VLAN id
 * @return forwarding objective builder
 */
private ForwardingObjective.Builder aclObjBuilder(VlanId vlanId) {
    TrafficSelector.Builder sbuilder = DefaultTrafficSelector.builder();
    sbuilder.matchVlanId(vlanId);

    TrafficTreatment.Builder tbuilder = DefaultTrafficTreatment.builder();

    ForwardingObjective.Builder fob = DefaultForwardingObjective.builder();
    fob.withFlag(ForwardingObjective.Flag.VERSATILE)
            .withSelector(sbuilder.build())
            .withTreatment(tbuilder.build())
            .withPriority(XCONNECT_ACL_PRIORITY)
            .fromApp(appId)
            .makePermanent();
    return fob;
}
 
Example 2
Source File: L2ForwardServiceImpl.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public void programExternalOut(DeviceId deviceId,
                            SegmentationId segmentationId,
                            PortNumber outPort, MacAddress sourceMac,
                            Objective.Operation type) {
    TrafficSelector selector = DefaultTrafficSelector.builder()
            .matchTunnelId(Long.parseLong(segmentationId.toString()))
            .matchEthSrc(sourceMac).build();
    TrafficTreatment treatment = DefaultTrafficTreatment.builder()
            .setOutput(outPort).build();
    ForwardingObjective.Builder objective = DefaultForwardingObjective
            .builder().withTreatment(treatment).withSelector(selector)
            .fromApp(appId).withFlag(Flag.SPECIFIC)
            .withPriority(MAC_PRIORITY);
    if (type.equals(Objective.Operation.ADD)) {
        flowObjectiveService.forward(deviceId, objective.add());
    } else {
        flowObjectiveService.forward(deviceId, objective.remove());
    }

}
 
Example 3
Source File: DefaultL2TunnelHandler.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Creates the forwarding objective for the initiation.
 *
 * @param tunnelId the tunnel id
 * @param inPort   the input port
 * @param nextId   the next step
 * @return the forwarding objective to support the initiation.
 */
private ForwardingObjective.Builder createInitFwdObjective(long tunnelId, PortNumber inPort, int nextId) {

    log.debug("Creating forwarding objective for tunnel {} : Port {} , nextId {}", tunnelId, inPort, nextId);
    TrafficSelector.Builder trafficSelector = DefaultTrafficSelector.builder();

    // The flow has to match on the mpls logical
    // port and the tunnel id.
    trafficSelector.matchTunnelId(tunnelId);
    trafficSelector.matchInPort(inPort);

    return DefaultForwardingObjective
            .builder()
            .fromApp(srManager.appId())
            .makePermanent()
            .nextStep(nextId)
            .withPriority(SegmentRoutingService.DEFAULT_PRIORITY)
            .withSelector(trafficSelector.build())
            .withFlag(VERSATILE);

}
 
Example 4
Source File: RoutingRulePopulator.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Revokes IP flow rules for the router IP address from given device.
 *
 * @param targetSw target switch from which the ipPrefix need to be removed
 * @param ipPrefix the IP address of the destination router
 * @return true if all rules are removed successfully, false otherwise
 */
private boolean revokeIpRuleForRouter(DeviceId targetSw, IpPrefix ipPrefix) {
    TrafficSelector.Builder sbuilder = buildIpSelectorFromIpPrefix(ipPrefix);
    TrafficSelector selector = sbuilder.build();
    TrafficTreatment dummyTreatment = DefaultTrafficTreatment.builder().build();

    ForwardingObjective.Builder fwdBuilder = DefaultForwardingObjective
            .builder()
            .fromApp(srManager.appId)
            .makePermanent()
            .withSelector(selector)
            .withTreatment(dummyTreatment)
            .withPriority(getPriorityFromPrefix(ipPrefix))
            .withFlag(ForwardingObjective.Flag.SPECIFIC);

    ObjectiveContext context = new DefaultObjectiveContext(
            (objective) -> log.debug("IP rule for router {} revoked from {}", ipPrefix, targetSw),
            (objective, error) -> log.warn("Failed to revoke IP rule for router {} from {}: {}",
                    ipPrefix, targetSw, error));
    srManager.flowObjectiveService.forward(targetSw, fwdBuilder.remove(context));

    return true;
}
 
Example 5
Source File: ClassifierServiceImpl.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public void programExportPortArpClassifierRules(Port exportPort,
                                                DeviceId deviceId,
                                                Operation type) {
    TrafficSelector selector = DefaultTrafficSelector.builder()
            .matchEthType(EtherType.ARP.ethType().toShort())
            .matchInPort(exportPort.number()).build();
    TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();
    treatment.add(Instructions.createOutput(PortNumber.CONTROLLER));
    ForwardingObjective.Builder objective = DefaultForwardingObjective
            .builder().withTreatment(treatment.build())
            .withSelector(selector).fromApp(appId).withFlag(Flag.SPECIFIC)
            .withPriority(L3_CLASSIFIER_PRIORITY);
    if (type.equals(Objective.Operation.ADD)) {
        flowObjectiveService.forward(deviceId, objective.add());
    } else {
        flowObjectiveService.forward(deviceId, objective.remove());
    }
}
 
Example 6
Source File: FibInstaller.java    From onos with Apache License 2.0 6 votes vote down vote up
private ForwardingObjective.Builder generateRibForwardingObj(IpPrefix prefix,
                                                             Integer nextId) {
    TrafficSelector selector = buildIpSelectorFromIpPrefix(prefix).build();
    int priority = prefix.prefixLength() * PRIORITY_MULTIPLIER + PRIORITY_OFFSET;

    ForwardingObjective.Builder fwdBuilder = DefaultForwardingObjective.builder()
            .fromApp(fibAppId)
            .makePermanent()
            .withSelector(selector)
            .withPriority(priority)
            .withFlag(ForwardingObjective.Flag.SPECIFIC);

    if (nextId == null) {
        // Route withdraws are not specified with next hops. Generating
        // dummy treatment as there is no equivalent nextId info.
        fwdBuilder.withTreatment(DefaultTrafficTreatment.builder().build());
    } else {
        fwdBuilder.nextStep(nextId);
    }
    return fwdBuilder;
}
 
Example 7
Source File: RoutingRulePopulator.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a forwarding objective builder for egress forwarding rules.
 * <p>
 * The forwarding objective installs flow rules to egress pipeline to push
 * two vlan headers with given inner, outer vlan ids and outer tpid.
 *
 * @param portNumber port where the next hop attaches to
 * @param dummyVlanId vlan ID of the packet to match
 * @param innerVlan inner vlan ID of the next hop
 * @param outerVlan outer vlan ID of the next hop
 * @param outerTpid outer TPID of the next hop
 * @return forwarding objective builder
 */
private ForwardingObjective.Builder egressFwdObjBuilder(PortNumber portNumber, VlanId dummyVlanId,
                                                        VlanId innerVlan, VlanId outerVlan, EthType outerTpid) {
    TrafficSelector.Builder sbuilder = DefaultTrafficSelector.builder();
    sbuilder.matchVlanId(dummyVlanId);
    TrafficTreatment.Builder tbuilder = DefaultTrafficTreatment.builder();
    tbuilder.setOutput(portNumber).setVlanId(innerVlan);

    if (outerTpid.equals(EthType.EtherType.QINQ.ethType())) {
        tbuilder.pushVlan(outerTpid);
    } else {
        tbuilder.pushVlan();
    }

    tbuilder.setVlanId(outerVlan);
    return DefaultForwardingObjective.builder()
            .withSelector(sbuilder.build())
            .withTreatment(tbuilder.build())
            .fromApp(srManager.appId)
            .makePermanent()
            .withPriority(DEFAULT_PRIORITY)
            .withFlag(ForwardingObjective.Flag.EGRESS);
}
 
Example 8
Source File: SnatServiceImpl.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public void programSnatSameSegmentUploadControllerRules(DeviceId deviceId,
                                                        SegmentationId matchVni,
                                                        IpAddress srcIP,
                                                        IpAddress dstIP,
                                                        IpPrefix prefix,
                                                        Operation type) {

    TrafficSelector selector = DefaultTrafficSelector.builder()
            .matchEthType(Ethernet.TYPE_IPV4)
            .matchTunnelId(Long.parseLong(matchVni.segmentationId()))
            .matchIPSrc(IpPrefix.valueOf(srcIP, PREFIC_LENGTH))
            .matchIPDst(IpPrefix.valueOf(dstIP, prefix.prefixLength()))
            .build();
    TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();
    treatment.add(Instructions.createOutput(PortNumber.CONTROLLER));
    ForwardingObjective.Builder objective = DefaultForwardingObjective
            .builder().withTreatment(treatment.build())
            .withSelector(selector).fromApp(appId).withFlag(Flag.SPECIFIC)
            .withPriority(SNAT_SAME_SEG_CON_PRIORITY);
    if (type.equals(Objective.Operation.ADD)) {
        flowObjectiveService.forward(deviceId, objective.add());
    } else {
        flowObjectiveService.forward(deviceId, objective.remove());
    }
}
 
Example 9
Source File: RoutingRulePopulator.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Populate a bridging rule on given deviceId that matches given mac, given vlan and
 * output to given port.
 *
 * @param deviceId device ID
 * @param port port
 * @param mac mac address
 * @param vlanId VLAN ID
 * @return future that carries the flow objective if succeeded, null if otherwise
 */
CompletableFuture<Objective> populateBridging(DeviceId deviceId, PortNumber port, MacAddress mac, VlanId vlanId) {
    ForwardingObjective.Builder fob = bridgingFwdObjBuilder(deviceId, mac, vlanId, port, false);
    if (fob == null) {
        log.warn("Fail to build fwd obj for host {}/{}. Abort.", mac, vlanId);
        return CompletableFuture.completedFuture(null);
    }

    CompletableFuture<Objective> future = new CompletableFuture<>();
    ObjectiveContext context = new DefaultObjectiveContext(
            (objective) -> {
                log.debug("Brigding rule for {}/{} populated", mac, vlanId);
                future.complete(objective);
            },
            (objective, error) -> {
                log.warn("Failed to populate bridging rule for {}/{}: {}", mac, vlanId, error);
                future.complete(null);
            });
    srManager.flowObjectiveService.forward(deviceId, fob.add(context));
    return future;
}
 
Example 10
Source File: CorsaL2OverlayPipeline.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public void forward(ForwardingObjective fwd) {
    // The Corsa devices don't support the clear deferred actions
    // so for now we have to filter this instruction for the fwd
    // objectives sent by the Packet Manager before to create the
    // flow rule
    if (fwd.flag() == VERSATILE && fwd.treatment().clearedDeferred()) {
        // First we create a new treatment without the unsupported action
        TrafficTreatment.Builder noClearTreatment = DefaultTrafficTreatment.builder();
        fwd.treatment().allInstructions().forEach(noClearTreatment::add);
        // Then we create a new forwarding objective without the unsupported action
        ForwardingObjective.Builder noClearFwd = DefaultForwardingObjective.builder(fwd);
        noClearFwd.withTreatment(noClearTreatment.build());
        // According to the operation we substitute fwd with the correct objective
        switch (fwd.op()) {
            case ADD:
                fwd = noClearFwd.add(fwd.context().orElse(null));
                break;
            case REMOVE:
                fwd = noClearFwd.remove(fwd.context().orElse(null));
                break;
            default:
                log.warn("Unknown operation {}", fwd.op());
                return;
        }
    }
    // Finally we send to the DefaultSingleTablePipeline for the real processing
    super.forward(fwd);
}
 
Example 11
Source File: DefaultL2TunnelHandler.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Creates the forwarding objective for the termination.
 *
 * @param pwLabel    the pseudo wire label
 * @param tunnelId   the tunnel id
 * @param egressPort the egress port
 * @param nextId     the next step
 * @return the forwarding objective to support the termination
 */
private ForwardingObjective.Builder createTermFwdObjective(MplsLabel pwLabel, long tunnelId,
                                                           PortNumber egressPort, int nextId) {

    log.debug("Creating forwarding objective for termination for tunnel {} : pwLabel {}, egressPort {}, nextId {}",
             tunnelId, pwLabel, egressPort, nextId);
    TrafficSelector.Builder trafficSelector = DefaultTrafficSelector.builder();
    TrafficTreatment.Builder trafficTreatment = DefaultTrafficTreatment.builder();
    // The flow has to match on the pw label and bos
    trafficSelector.matchEthType(Ethernet.MPLS_UNICAST);
    trafficSelector.matchMplsLabel(pwLabel);
    trafficSelector.matchMplsBos(true);
    // The flow has to decrement ttl, restore ttl in
    // pop mpls, set tunnel id and port.
    trafficTreatment.decMplsTtl();
    trafficTreatment.copyTtlIn();
    trafficTreatment.popMpls();
    trafficTreatment.setTunnelId(tunnelId);
    trafficTreatment.setOutput(egressPort);

    return DefaultForwardingObjective
            .builder()
            .fromApp(srManager.appId())
            .makePermanent()
            .nextStep(nextId)
            .withPriority(SegmentRoutingService.DEFAULT_PRIORITY)
            .withSelector(trafficSelector.build())
            .withTreatment(trafficTreatment.build())
            .withFlag(VERSATILE);
}
 
Example 12
Source File: SnatServiceImpl.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public void removeSnatRules(DeviceId deviceId, TrafficSelector selector,
                            TrafficTreatment treatment, int priority,
                            Objective.Operation type) {
    ForwardingObjective.Builder objective = DefaultForwardingObjective
            .builder().withTreatment(treatment).withSelector(selector)
            .fromApp(appId).withFlag(Flag.SPECIFIC).withPriority(priority);
    if (type.equals(Objective.Operation.ADD)) {
        flowObjectiveService.forward(deviceId, objective.add());
    } else {
        flowObjectiveService.forward(deviceId, objective.remove());
    }
}
 
Example 13
Source File: RoutingRulePopulator.java    From onos with Apache License 2.0 5 votes vote down vote up
private ForwardingObjective.Builder fwdObjBuilder(TrafficSelector selector,
                                                  TrafficTreatment treatment, int priority) {
    return DefaultForwardingObjective.builder()
            .withPriority(priority)
            .withSelector(selector)
            .fromApp(srManager.appId)
            .withFlag(ForwardingObjective.Flag.VERSATILE)
            .withTreatment(treatment)
            .makePermanent();
}
 
Example 14
Source File: InOrderFlowObjectiveManagerTest.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Creates forwarding objective builder.
 *
 * @param selector Traffic selector
 * @param nextId next ID
 * @return Forwarding objective builder
 */
private static ForwardingObjective.Builder buildFwdObjective(TrafficSelector selector, int nextId) {
    return DefaultForwardingObjective.builder()
            .makePermanent()
            .withSelector(selector)
            .nextStep(nextId)
            .fromApp(APP_ID)
            .withPriority(PRIORITY)
            .withFlag(ForwardingObjective.Flag.SPECIFIC);
}
 
Example 15
Source File: XconnectManager.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Populates ACL forwarding objectives for given XConnect.
 *
 * @param key XConnect store key
 */
private void populateAcl(XconnectKey key) {
    ForwardingObjective.Builder aclObjBuilder = aclObjBuilder(key.vlanId());
    ObjectiveContext aclContext = new DefaultObjectiveContext(
            (objective) -> log.debug("XConnect AclObj for {} populated", key),
            (objective, error) ->
                    log.warn("Failed to populate XConnect AclObj for {}: {}", key, error));
    flowObjectiveService.forward(key.deviceId(), aclObjBuilder.add(aclContext));
}
 
Example 16
Source File: XconnectManager.java    From onos with Apache License 2.0 4 votes vote down vote up
/**
 * Populate L2 multicast rule on given deviceId that matches given mac, given vlan and
 * output to given port's L2 mulitcast group.
 *
 * @param deviceId    Device ID
 * @param pairPort    Pair port number
 * @param vlanId      VLAN ID
 * @param accessPorts List of access ports to be added into L2 multicast group
 */
private void populateL2Multicast(DeviceId deviceId, PortNumber pairPort,
                                 VlanId vlanId, List<PortNumber> accessPorts) {
    // Ensure enough rights to program pair device
    if (!srService.shouldProgram(deviceId)) {
        log.debug("Abort populate L2Multicast {}-{}: {}", deviceId, vlanId, ERROR_NOT_LEADER);
        return;
    }

    boolean multicastGroupExists = true;
    int vlanMulticastNextId;
    VlanNextObjectiveStoreKey key = new VlanNextObjectiveStoreKey(deviceId, vlanId);

    // Step 1 : Populate single homed access ports into vlan's L2 multicast group
    NextObjective.Builder vlanMulticastNextObjBuilder = DefaultNextObjective
            .builder()
            .withType(NextObjective.Type.BROADCAST)
            .fromApp(srService.appId())
        .withMeta(DefaultTrafficSelector.builder().matchVlanId(vlanId)
                      .matchEthDst(MacAddress.IPV4_MULTICAST).build());
    vlanMulticastNextId = getMulticastGroupNextObjectiveId(key);
    if (vlanMulticastNextId == -1) {
        // Vlan's L2 multicast group doesn't exist; create it, update store and add pair port as sub-group
        multicastGroupExists = false;
        vlanMulticastNextId = flowObjectiveService.allocateNextId();
        addMulticastGroupNextObjectiveId(key, vlanMulticastNextId);
        vlanMulticastNextObjBuilder.addTreatment(
                DefaultTrafficTreatment.builder().setOutput(pairPort).build()
        );
    }
    vlanMulticastNextObjBuilder.withId(vlanMulticastNextId);
    int nextId = vlanMulticastNextId;
    accessPorts.forEach(p -> {
        TrafficTreatment.Builder egressAction = DefaultTrafficTreatment.builder();
        // Do vlan popup action based on interface configuration
        if (interfaceService.getInterfacesByPort(new ConnectPoint(deviceId, p))
                .stream().noneMatch(i -> i.vlanTagged().contains(vlanId))) {
            egressAction.popVlan();
        }
        egressAction.setOutput(p);
        vlanMulticastNextObjBuilder.addTreatment(egressAction.build());
        addMulticastGroupPort(key, p);
    });
    ObjectiveContext context = new DefaultObjectiveContext(
            (objective) ->
                    log.debug("L2 multicast group installed/updated. "
                                      + "NextObject Id {} on {} for subnet {} ",
                              nextId, deviceId, vlanId),
            (objective, error) ->
                    log.warn("L2 multicast group failed to install/update. "
                                     + " NextObject Id {} on {} for subnet {} : {}",
                             nextId, deviceId, vlanId, error)
    );
    if (!multicastGroupExists) {
        flowObjectiveService.next(deviceId, vlanMulticastNextObjBuilder.add(context));

        // Step 2 : Populate ACL rule; selector = vlan + pair-port, output = vlan L2 multicast group
        TrafficSelector.Builder multicastSelector = DefaultTrafficSelector.builder();
        multicastSelector.matchEthType(Ethernet.TYPE_VLAN);
        multicastSelector.matchInPort(pairPort);
        multicastSelector.matchVlanId(vlanId);
        ForwardingObjective.Builder vlanMulticastForwardingObj = DefaultForwardingObjective.builder()
                .withFlag(ForwardingObjective.Flag.VERSATILE)
                .nextStep(vlanMulticastNextId)
                .withSelector(multicastSelector.build())
                .withPriority(100)
                .fromApp(srService.appId())
                .makePermanent();
        context = new DefaultObjectiveContext(
                (objective) -> log.debug("L2 multicasting versatile rule for device {}, port/vlan {}/{} populated",
                                         deviceId,
                                         pairPort,
                                         vlanId),
                (objective, error) -> log.warn("Failed to populate L2 multicasting versatile rule for device {}, " +
                                                       "ports/vlan {}/{}: {}", deviceId, pairPort, vlanId, error));
        flowObjectiveService.forward(deviceId, vlanMulticastForwardingObj.add(context));
    } else {
        // L2_MULTICAST & BROADCAST are similar structure in subgroups; so going with BROADCAST type.
        vlanMulticastNextObjBuilder.withType(NextObjective.Type.BROADCAST);
        flowObjectiveService.next(deviceId, vlanMulticastNextObjBuilder.addToExisting(context));
    }
}
 
Example 17
Source File: RoutingRulePopulator.java    From onos with Apache License 2.0 4 votes vote down vote up
/**
 * Returns a Forwarding Objective builder for the MPLS rule that references
 * the desired Next Objective. Creates a DestinationSet that allows the
 * groupHandler to create or find the required next objective.
 *
 * @param targetSw the target sw
 * @param nextHops the set of next hops
 * @param phpRequired true if penultimate-hop-popping is required
 * @param isBos true if matched label is bottom-of-stack
 * @param meta metadata for creating next objective
 * @param routerIp the router ip representing the destination switch
 * @param destSw the destination sw
 * @return the mpls forwarding objective builder
 */
private ForwardingObjective.Builder getMplsForwardingObjective(
                                         DeviceId targetSw,
                                         Set<DeviceId> nextHops,
                                         boolean phpRequired,
                                         boolean isBos,
                                         TrafficSelector meta,
                                         IpAddress routerIp,
                                         int segmentId,
                                         DeviceId destSw) {

    ForwardingObjective.Builder fwdBuilder = DefaultForwardingObjective
            .builder().withFlag(ForwardingObjective.Flag.SPECIFIC);

    TrafficTreatment.Builder tbuilder = DefaultTrafficTreatment.builder();
    DestinationSet ds = null;
    DestinationSet.DestinationSetType dstType = null;
    boolean simple = false;
    if (phpRequired) {
        // php case - pop should always be flow-action
        log.debug("getMplsForwardingObjective: php required");
        tbuilder.deferred().copyTtlIn();
        if (isBos) {
            if (routerIp.isIp4()) {
                tbuilder.deferred().popMpls(EthType.EtherType.IPV4.ethType());
            } else {
                tbuilder.deferred().popMpls(EthType.EtherType.IPV6.ethType());
            }
            tbuilder.decNwTtl();
            // standard case -> BoS == True; pop results in IP packet and forwarding
            // is via an ECMP group
            ds = DestinationSet.createTypePopBos(destSw);
        } else {
            tbuilder.deferred().popMpls(EthType.EtherType.MPLS_UNICAST.ethType())
                .decMplsTtl();
            // double-label case -> BoS == False, pop results in MPLS packet
            // depending on configuration we can ECMP this packet or choose one output
            ds = DestinationSet.createTypePopNotBos(destSw);
            if (!srManager.getMplsEcmp()) {
               simple = true;
            }
        }
    } else {
        // swap with self case - SR CONTINUE
        log.debug("getMplsForwardingObjective: swap with self");
        tbuilder.deferred().decMplsTtl();
        // swap results in MPLS packet with same BoS bit regardless of bit value
        // depending on configuration we can ECMP this packet or choose one output
        // differentiate here between swap with not bos or swap with bos
        ds = isBos ? DestinationSet.createTypeSwapBos(segmentId, destSw) :
                DestinationSet.createTypeSwapNotBos(segmentId, destSw);
        if (!srManager.getMplsEcmp()) {
            simple = true;
        }
    }

    fwdBuilder.withTreatment(tbuilder.build());
    log.debug("Trying to get a nextObjId for mpls rule on device:{} to ds:{}",
              targetSw, ds);
    DefaultGroupHandler gh = srManager.getGroupHandler(targetSw);
    if (gh == null) {
        log.warn("getNextObjectiveId query - groupHandler for device {} "
                + "not found", targetSw);
        return null;
    }

    Map<DeviceId, Set<DeviceId>> dstNextHops = new HashMap<>();
    dstNextHops.put(destSw, nextHops);
    int nextId = gh.getNextObjectiveId(ds, dstNextHops, meta, simple);
    if (nextId <= 0) {
        log.warn("No next objective in {} for ds: {}", targetSw, ds);
        return null;
    } else {
        log.debug("nextObjId found:{} for mpls rule on device:{} to ds:{}",
                  nextId, targetSw, ds);
    }

    fwdBuilder.nextStep(nextId);
    return fwdBuilder;
}
 
Example 18
Source File: RoutingRulePopulator.java    From onos with Apache License 2.0 4 votes vote down vote up
/**
 * Generates a forwarding objective builder for bridging rules.
 * <p>
 * The forwarding objective bridges packets destined to a given MAC to
 * given port on given device.
 *
 * @param deviceId Device that host attaches to
 * @param mac MAC address of the host
 * @param hostVlanId VLAN ID of the host
 * @param outport Port that host attaches to
 * @param revoke true if forwarding objective is meant to revoke forwarding rule
 * @return Forwarding objective builder
 */
private ForwardingObjective.Builder bridgingFwdObjBuilder(
        DeviceId deviceId, MacAddress mac, VlanId hostVlanId, PortNumber outport, boolean revoke) {
    ConnectPoint connectPoint = new ConnectPoint(deviceId, outport);
    VlanId untaggedVlan = srManager.interfaceService.getUntaggedVlanId(connectPoint);
    Set<VlanId> taggedVlans = srManager.interfaceService.getTaggedVlanId(connectPoint);
    VlanId nativeVlan = srManager.interfaceService.getNativeVlanId(connectPoint);

    // Create host selector
    TrafficSelector.Builder sbuilder = DefaultTrafficSelector.builder();
    sbuilder.matchEthDst(mac);

    // Create host treatment
    TrafficTreatment.Builder tbuilder = DefaultTrafficTreatment.builder();
    tbuilder.immediate().setOutput(outport);

    // Create host meta
    TrafficSelector.Builder mbuilder = DefaultTrafficSelector.builder();

    // Adjust the selector, treatment and meta according to VLAN configuration
    if (taggedVlans.contains(hostVlanId)) {
        sbuilder.matchVlanId(hostVlanId);
        mbuilder.matchVlanId(hostVlanId);
    } else if (hostVlanId.equals(VlanId.NONE)) {
        if (untaggedVlan != null) {
            sbuilder.matchVlanId(untaggedVlan);
            mbuilder.matchVlanId(untaggedVlan);
            tbuilder.immediate().popVlan();
        } else if (nativeVlan != null) {
            sbuilder.matchVlanId(nativeVlan);
            mbuilder.matchVlanId(nativeVlan);
            tbuilder.immediate().popVlan();
        } else {
            log.warn("Untagged host {}/{} is not allowed on {} without untagged or native" +
                    "vlan config", mac, hostVlanId, connectPoint);
            return null;
        }
    } else {
        log.warn("Tagged host {}/{} is not allowed on {} without VLAN listed in tagged vlan",
                mac, hostVlanId, connectPoint);
        return null;
    }

    // All forwarding is via Groups. Drivers can re-purpose to flow-actions if needed.
    // If the objective is to revoke an existing rule, and for some reason
    // the next-objective does not exist, then a new one should not be created
    int portNextObjId = srManager.getPortNextObjectiveId(deviceId, outport,
            tbuilder.build(), mbuilder.build(), !revoke);
    if (portNextObjId == -1) {
        // Warning log will come from getPortNextObjective method
        return null;
    }

    return DefaultForwardingObjective.builder()
            .withFlag(ForwardingObjective.Flag.SPECIFIC)
            .withSelector(sbuilder.build())
            .nextStep(portNextObjId)
            .withPriority(100)
            .fromApp(srManager.appId)
            .makePermanent();
}
 
Example 19
Source File: EvpnManager.java    From onos with Apache License 2.0 4 votes vote down vote up
private void setFlows(DeviceId deviceId, Host host, Label label,
                      List<VpnRouteTarget> rtImport,
                      Operation type) {
    log.info("Set the flows to OVS");
    ForwardingObjective.Builder objective = getMplsInBuilder(deviceId,
                                                             host,
                                                             label);
    if (type.equals(Objective.Operation.ADD)) {
        flowObjectiveService.forward(deviceId, objective.add());
    } else {
        flowObjectiveService.forward(deviceId, objective.remove());
    }

    // download remote flows if and only routes are present.
    evpnRouteStore.getRouteTables().forEach(routeTableId -> {
        Collection<EvpnRouteSet> routes
                = evpnRouteStore.getRoutes(routeTableId);
        if (routes != null) {
            routes.forEach(route -> {
                Collection<EvpnRoute> evpnRoutes = route.routes();
                for (EvpnRoute evpnRoute : evpnRoutes) {
                    EvpnRoute evpnRouteTem = evpnRoute;
                    Set<Host> hostByMac = hostService
                            .getHostsByMac(evpnRouteTem
                                                   .prefixMac());

                    if (!hostByMac.isEmpty()
                            || (!(compareLists(rtImport, evpnRouteTem
                            .exportRouteTarget())))) {
                        log.info("Route target import/export is not matched");
                        continue;
                    }
                    log.info("Set the ARP flows");
                    addArpFlows(deviceId, evpnRouteTem, type, host);
                    ForwardingObjective.Builder build = getMplsOutBuilder(deviceId,
                                                                          evpnRouteTem,
                                                                          host);
                    log.info("Set the MPLS  flows");
                    if (type.equals(Objective.Operation.ADD)) {
                        flowObjectiveService.forward(deviceId, build.add());
                    } else {
                        flowObjectiveService.forward(deviceId, build.remove());
                    }
                }
            });
        }
    });
}
 
Example 20
Source File: RoutingRulePopulator.java    From onos with Apache License 2.0 4 votes vote down vote up
/**
 * Populate or revoke a bridging rule on given deviceId that matches given vlanId,
 * and hostMAC connected to given port, and output to given port only when
 * vlan information is valid.
 *
 * @param deviceId device ID that host attaches to
 * @param portNum port number that host attaches to
 * @param hostMac mac address of the host connected to the switch port
 * @param vlanId Vlan ID configured on the switch port
 * @param popVlan true to pop Vlan tag at TrafficTreatment, false otherwise
 * @param install true to populate the objective, false to revoke
 */
// TODO Refactor. There are a lot of duplications between this method, populateBridging,
//      revokeBridging and bridgingFwdObjBuilder.
void updateBridging(DeviceId deviceId, PortNumber portNum, MacAddress hostMac,
                    VlanId vlanId, boolean popVlan, boolean install) {
    // Create host selector
    TrafficSelector.Builder sbuilder = DefaultTrafficSelector.builder();
    sbuilder.matchEthDst(hostMac);

    // Create host meta
    TrafficSelector.Builder mbuilder = DefaultTrafficSelector.builder();

    sbuilder.matchVlanId(vlanId);
    mbuilder.matchVlanId(vlanId);

    // Create host treatment
    TrafficTreatment.Builder tbuilder = DefaultTrafficTreatment.builder();
    tbuilder.immediate().setOutput(portNum);

    if (popVlan) {
        tbuilder.immediate().popVlan();
    }

    int portNextObjId = srManager.getPortNextObjectiveId(deviceId, portNum,
            tbuilder.build(), mbuilder.build(), install);
    if (portNextObjId != -1) {
        ForwardingObjective.Builder fob = DefaultForwardingObjective.builder()
                .withFlag(ForwardingObjective.Flag.SPECIFIC)
                .withSelector(sbuilder.build())
                .nextStep(portNextObjId)
                .withPriority(100)
                .fromApp(srManager.appId)
                .makePermanent();

        ObjectiveContext context = new DefaultObjectiveContext(
                (objective) -> log.debug("Brigding rule for {}/{} {}", hostMac, vlanId,
                        install ? "populated" : "revoked"),
                (objective, error) -> log.warn("Failed to {} bridging rule for {}/{}: {}",
                        install ? "populate" : "revoke", hostMac, vlanId, error));
        srManager.flowObjectiveService.forward(deviceId, install ? fob.add(context) : fob.remove(context));
    } else {
        log.warn("Failed to retrieve next objective for {}/{}", hostMac, vlanId);
    }
}