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

The following examples show how to use org.onosproject.net.flowobjective.NextObjective#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: ControlPlaneRedirectManagerTest.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Setup expectations on flowObjectiveService.next for NextObjective.
 *
 **/
private int modifyNextObjective(DeviceId deviceId, PortNumber portNumber, VlanId vlanId, boolean popVlan,
        boolean modifyFlag) {
    NextObjective.Builder nextObjBuilder = DefaultNextObjective.builder().withId(1)
            .withType(NextObjective.Type.SIMPLE).fromApp(APPID);

    TrafficTreatment.Builder ttBuilder = DefaultTrafficTreatment.builder();
    if (popVlan) {
        ttBuilder.popVlan();
    }
    ttBuilder.setOutput(portNumber);

    TrafficSelector.Builder metabuilder = DefaultTrafficSelector.builder();
    metabuilder.matchVlanId(vlanId);

    nextObjBuilder.withMeta(metabuilder.build());
    nextObjBuilder.addTreatment(ttBuilder.build());
    if (modifyFlag) {
        flowObjectiveService.next(deviceId, nextObjBuilder.add());
        expectLastCall().once();
    } else {
        flowObjectiveService.next(deviceId, nextObjBuilder.remove());
        expectLastCall().once();
    }
    return 1;
}
 
Example 2
Source File: InOrderFlowObjectiveManagerTest.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Creates next objective builder.
 *
 * @param nextId next ID
 * @param vlanId VLAN ID
 * @param ports Set of ports that is in the given VLAN ID
 *
 * @return Next objective builder
 */
private static NextObjective.Builder buildNextObjective(int nextId, VlanId vlanId, Collection<PortNumber> ports) {
    TrafficSelector metadata =
            DefaultTrafficSelector.builder().matchVlanId(vlanId).build();

    NextObjective.Builder nextObjBuilder = DefaultNextObjective
            .builder().withId(nextId)
            .withType(NextObjective.Type.BROADCAST).fromApp(APP_ID)
            .withMeta(metadata);

    ports.forEach(port -> {
        TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
        tBuilder.popVlan();
        tBuilder.setOutput(port);
        nextObjBuilder.addTreatment(tBuilder.build());
    });

    return nextObjBuilder;
}
 
Example 3
Source File: FibInstallerTest.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a next objective with the given parameters.
 *
 * @param srcMac source MAC address
 * @param dstMac destination MAC address
 * @param port port number
 * @param vlan vlan ID
 * @param add whether to create an add objective or remove objective
 * @return new next objective
 */
private NextObjective createNextObjective(MacAddress srcMac,
                                          MacAddress dstMac,
                                          PortNumber port,
                                          VlanId vlan,
                                          boolean add) {
    TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder()
            .setEthSrc(srcMac)
            .setEthDst(dstMac);
    TrafficSelector.Builder metabuilder = null;
    if (!vlan.equals(VlanId.NONE)) {
        treatment.pushVlan()
                 .setVlanId(vlan)
                 .setVlanPcp((byte) 0);
    } else {
        metabuilder = DefaultTrafficSelector.builder();
        metabuilder.matchVlanId(VlanId.vlanId(FibInstaller.ASSIGNED_VLAN));
    }

    treatment.setOutput(port);
    NextObjective.Builder nextBuilder = DefaultNextObjective.builder()
            .withId(NEXT_ID)
            .addTreatment(treatment.build())
            .withType(NextObjective.Type.SIMPLE)
            .fromApp(APPID);
    if (metabuilder != null) {
        nextBuilder.withMeta(metabuilder.build());
    }

    return add ? nextBuilder.add() : nextBuilder.remove();
}
 
Example 4
Source File: ControlPlaneRedirectManager.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a next objective for forwarding to a port. Handles metadata for
 * some pipelines that require vlan information for egress port.
 *
 * @param deviceId the device on which the next objective is being created
 * @param portNumber the egress port
 * @param vlanId vlan information for egress port
 * @param popVlan if vlan tag should be popped or not
 * @param install true to create an add next objective, false to create a remove
 *            next objective
 * @return nextId of the next objective created
 */
private int modifyNextObjective(DeviceId deviceId, PortNumber portNumber,
                                VlanId vlanId, boolean popVlan, boolean install) {
    int nextId = flowObjectiveService.allocateNextId();
    NextObjective.Builder nextObjBuilder = DefaultNextObjective
            .builder().withId(nextId)
            .withType(NextObjective.Type.SIMPLE)
            .fromApp(appId);

    TrafficTreatment.Builder ttBuilder = DefaultTrafficTreatment.builder();
    if (popVlan) {
        ttBuilder.popVlan();
    }
    ttBuilder.setOutput(portNumber);

    // setup metadata to pass to nextObjective - indicate the vlan on egress
    // if needed by the switch pipeline.
    TrafficSelector.Builder metabuilder = DefaultTrafficSelector.builder();
    metabuilder.matchVlanId(vlanId);

    nextObjBuilder.withMeta(metabuilder.build());
    nextObjBuilder.addTreatment(ttBuilder.build());
    log.debug("Submitted next objective {} in device {} for port/vlan {}/{}",
            nextId, deviceId, portNumber, vlanId);
    if (install) {
         flowObjectiveService.next(deviceId, nextObjBuilder.add());
    } else {
         flowObjectiveService.next(deviceId, nextObjBuilder.remove());
    }
    return nextId;
}
 
Example 5
Source File: DefaultGroupHandler.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Adds a single port to the L2FG or removes it from the L2FG.
 *
 * @param vlanId the vlan id corresponding to this port
 * @param portNum the port on this device to be updated
 * @param nextId the next objective ID for the given vlan id
 * @param install if true, adds the port to L2FG. If false, removes it from L2FG.
 */
public void updateGroupFromVlanConfiguration(VlanId vlanId, PortNumber portNum, int nextId, boolean install) {
    TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
    if (toPopVlan(portNum, vlanId)) {
        tBuilder.popVlan();
    }
    tBuilder.setOutput(portNum);

    TrafficSelector metadata =
            DefaultTrafficSelector.builder().matchVlanId(vlanId).build();

    NextObjective.Builder nextObjBuilder = DefaultNextObjective
            .builder().withId(nextId)
            .withType(NextObjective.Type.BROADCAST).fromApp(appId)
            .addTreatment(tBuilder.build())
            .withMeta(metadata);

    ObjectiveContext context = new DefaultObjectiveContext(
            (objective) -> log.debug("port {} successfully removedFrom NextObj {} on {}",
                                     portNum, nextId, deviceId),
            (objective, error) -> {
                log.warn("port {} failed to removedFrom NextObj {} on {}: {}", portNum, nextId, deviceId, error);
                srManager.invalidateNextObj(objective.id());
            });

    if (install) {
        flowObjectiveService.next(deviceId, nextObjBuilder.addToExisting(context));
    } else {
        flowObjectiveService.next(deviceId, nextObjBuilder.removeFromExisting(context));
    }
}
 
Example 6
Source File: DefaultGroupHandler.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Modifies L2IG bucket when the interface configuration is updated, especially
 * when the interface has same VLAN ID but the VLAN type is changed (e.g., from
 * vlan-tagged [10] to vlan-untagged 10), which requires changes on
 * TrafficTreatment in turn.
 *
 * @param portNumber the port on this device that needs to be updated
 * @param vlanId the vlan id corresponding to this port
 * @param pushVlan indicates if packets should be sent out untagged or not out
 *                 from the port. If true, updated TrafficTreatment involves
 *                 pop vlan tag action. If false, updated TrafficTreatment
 *                 does not involve pop vlan tag action.
 */
public void updateL2InterfaceGroupBucket(PortNumber portNumber, VlanId vlanId, boolean pushVlan) {
    TrafficTreatment.Builder oldTBuilder = DefaultTrafficTreatment.builder();
    TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
    tBuilder.setOutput(portNumber);
    oldTBuilder.setOutput(portNumber);
    if (pushVlan) {
        tBuilder.popVlan();
    } else {
        oldTBuilder.popVlan();
    }

    TrafficSelector metadata =
            DefaultTrafficSelector.builder().matchVlanId(vlanId).build();

    // Update portNextObjStore with new L2IG
    int nextId = getPortNextObjectiveId(portNumber, oldTBuilder.build(), metadata, false);
    portNextObjStore.remove(new PortNextObjectiveStoreKey(deviceId, portNumber, oldTBuilder.build(), metadata));
    portNextObjStore.put(new PortNextObjectiveStoreKey(deviceId, portNumber, tBuilder.build(), metadata), nextId);

    NextObjective.Builder nextObjBuilder = DefaultNextObjective
            .builder().withId(nextId)
            .withType(NextObjective.Type.SIMPLE).fromApp(appId)
            .addTreatment(tBuilder.build())
            .withMeta(metadata);

    ObjectiveContext context = new DefaultObjectiveContext(
            (objective) -> log.debug("port {} successfully updated NextObj {} on {}",
                                     portNumber, nextId, deviceId),
            (objective, error) -> {
                log.warn("port {} failed to updated NextObj {} on {}: {}", portNumber, nextId, deviceId, error);
                srManager.invalidateNextObj(objective.id());
            });

    flowObjectiveService.next(deviceId, nextObjBuilder.modify(context));
}
 
Example 7
Source File: DefaultGroupHandler.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Remove simple next objective for a single port. The treatments can include
 * all outgoing actions that need to happen on the packet.
 *
 * @param portNum  the outgoing port on the device
 * @param treatment the actions applied on the packets (should include outport)
 * @param meta optional data to pass to the driver
 */
public void removeGroupFromPort(PortNumber portNum, TrafficTreatment treatment,
                                TrafficSelector meta) {
    PortNextObjectiveStoreKey key = new PortNextObjectiveStoreKey(
            deviceId, portNum, treatment, meta);
    Integer nextId = portNextObjStore.get(key);

    NextObjective.Builder nextObjBuilder = DefaultNextObjective
            .builder().withId(nextId)
            .withType(NextObjective.Type.SIMPLE)
            .addTreatment(treatment)
            .fromApp(appId)
            .withMeta(meta);

    ObjectiveContext context = new DefaultObjectiveContext(
            (objective) ->
                    log.info("removeGroupFromPort installed "
                                      + "NextObj {} on {}", nextId, deviceId),
            (objective, error) -> {
                log.warn("removeGroupFromPort failed to install NextObj {} on {}: {}", nextId, deviceId, error);
                srManager.invalidateNextObj(objective.id());
            }
    );
    NextObjective nextObj = nextObjBuilder.remove(context);
    flowObjectiveService.next(deviceId, nextObj);
    log.info("removeGroupFromPort: Submitted next objective {} in device {} "
                      + "for port {}", nextId, deviceId, portNum);

    portNextObjStore.remove(key);
}
 
Example 8
Source File: DefaultGroupHandler.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Removes groups for the next objective ID given.
 *
 * @param objectiveId next objective ID to remove
 * @return true if succeeds, false otherwise
 */
public boolean removeGroup(int objectiveId) {
    for (Map.Entry<DestinationSetNextObjectiveStoreKey, NextNeighbors> e :
            dsNextObjStore.entrySet()) {
        if (e.getValue().nextId() != objectiveId) {
            continue;
        }
        // Right now it is just used in TunnelHandler
        // remember in future that PW transit groups could
        // be Indirect groups
        NextObjective.Builder nextObjBuilder = DefaultNextObjective
                .builder().withId(objectiveId)
                .withType(NextObjective.Type.HASHED).fromApp(appId);
        ObjectiveContext context = new DefaultObjectiveContext(
                (objective) -> log.debug("RemoveGroup removes NextObj {} on {}",
                        objectiveId, deviceId),
                (objective, error) -> {
                    log.warn("RemoveGroup failed to remove NextObj {} on {}: {}", objectiveId, deviceId, error);
                    srManager.invalidateNextObj(objective.id());
                });
        NextObjective nextObjective = nextObjBuilder.remove(context);
        log.info("**removeGroup: Submited "
                + "next objective {} in device {}",
                objectiveId, deviceId);
        flowObjectiveService.next(deviceId, nextObjective);

        dsNextObjStore.remove(e.getKey());
        return true;
    }

    return false;
}
 
Example 9
Source File: DefaultGroupHandler.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Removes simple next objective for a single port.
 *
 * @param deviceId device id that has the port to deal with
 * @param portNum the outgoing port on the device
 * @param vlanId vlan id associated with the port
 * @param popVlan true if POP_VLAN action is applied on the packets, false otherwise
 */
public void removePortNextObjective(DeviceId deviceId, PortNumber portNum, VlanId vlanId, boolean popVlan) {
    TrafficSelector.Builder mbuilder = DefaultTrafficSelector.builder();
    mbuilder.matchVlanId(vlanId);

    TrafficTreatment.Builder tbuilder = DefaultTrafficTreatment.builder();
    tbuilder.immediate().setOutput(portNum);
    if (popVlan) {
        tbuilder.immediate().popVlan();
    }

    int portNextObjId = srManager.getPortNextObjectiveId(deviceId, portNum,
                                                         tbuilder.build(), mbuilder.build(), false);

    PortNextObjectiveStoreKey key = new PortNextObjectiveStoreKey(
            deviceId, portNum, tbuilder.build(), mbuilder.build());
    if (portNextObjId != -1 && portNextObjStore.containsKey(key)) {
        NextObjective.Builder nextObjBuilder = DefaultNextObjective
                .builder().withId(portNextObjId)
                .withType(NextObjective.Type.SIMPLE).fromApp(appId);
        ObjectiveContext context = new DefaultObjectiveContext(
                (objective) -> log.debug("removePortNextObjective removes NextObj {} on {}",
                                         portNextObjId, deviceId),
                (objective, error) -> {
                    log.warn("removePortNextObjective failed to remove NextObj {} on {}: {}",
                            portNextObjId, deviceId, error);
                    srManager.invalidateNextObj(objective.id());
                });
        NextObjective nextObjective = nextObjBuilder.remove(context);
        log.info("**removePortNextObjective: Submitted "
                         + "next objective {} in device {}",
                 portNextObjId, deviceId);
        flowObjectiveService.next(deviceId, nextObjective);

        portNextObjStore.remove(key);
    }
}
 
Example 10
Source File: DefaultGroupHandler.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Create simple next objective for an indirect host mac/vlan. The treatments can include
 * all outgoing actions that need to happen on the packet.
 *
 * @param macAddr the mac address of the host
 * @param vlanId the vlan of the host
 * @param treatment the actions to apply on the packets (should include outport)
 * @param meta optional data to pass to the driver
 * @return next objective ID
 */
public int createGroupFromMacVlan(MacAddress macAddr, VlanId vlanId, TrafficTreatment treatment,
                                TrafficSelector meta) {
    int nextId = flowObjectiveService.allocateNextId();
    MacVlanNextObjectiveStoreKey key = new MacVlanNextObjectiveStoreKey(deviceId, macAddr, vlanId);

    NextObjective.Builder nextObjBuilder = DefaultNextObjective
            .builder().withId(nextId)
            .withType(NextObjective.Type.SIMPLE)
            .addTreatment(treatment)
            .fromApp(appId)
            .withMeta(meta);

    ObjectiveContext context = new DefaultObjectiveContext(
        (objective) ->
            log.debug("createGroupFromMacVlan installed "
                    + "NextObj {} on {}", nextId, deviceId),
        (objective, error) -> {
            log.warn("createGroupFromMacVlan failed to install NextObj {} on {}: {}", nextId, deviceId, error);
            srManager.invalidateNextObj(objective.id());
        });
    NextObjective nextObj = nextObjBuilder.add(context);
    flowObjectiveService.next(deviceId, nextObj);
    log.debug("createGroupFromMacVlan: Submited next objective {} in device {} "
            + "for host {}/{}", nextId, deviceId, macAddr, vlanId);

    macVlanNextObjStore.put(key, nextId);
    return nextId;
}
 
Example 11
Source File: DefaultGroupHandler.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Create simple next objective for a single port. The treatments can include
 * all outgoing actions that need to happen on the packet.
 *
 * @param portNum  the outgoing port on the device
 * @param treatment the actions to apply on the packets (should include outport)
 * @param meta optional data to pass to the driver
 */
public void createGroupFromPort(PortNumber portNum, TrafficTreatment treatment,
                                TrafficSelector meta) {
    int nextId = flowObjectiveService.allocateNextId();
    PortNextObjectiveStoreKey key = new PortNextObjectiveStoreKey(
                                            deviceId, portNum, treatment, meta);

    NextObjective.Builder nextObjBuilder = DefaultNextObjective
            .builder().withId(nextId)
            .withType(NextObjective.Type.SIMPLE)
            .addTreatment(treatment)
            .fromApp(appId)
            .withMeta(meta);

    ObjectiveContext context = new DefaultObjectiveContext(
        (objective) ->
            log.debug("createGroupFromPort installed "
                    + "NextObj {} on {}", nextId, deviceId),
        (objective, error) -> {
            log.warn("createGroupFromPort failed to install NextObj {} on {}: {}", nextId, deviceId, error);
            srManager.invalidateNextObj(objective.id());
        });
    NextObjective nextObj = nextObjBuilder.add(context);
    flowObjectiveService.next(deviceId, nextObj);
    log.debug("createGroupFromPort: Submited next objective {} in device {} "
            + "for port {}", nextId, deviceId, portNum);

    portNextObjStore.put(key, nextId);
}
 
Example 12
Source File: DefaultGroupHandler.java    From onos with Apache License 2.0 4 votes vote down vote up
@Override
public void run() {
    if (!srManager.mastershipService.isLocalMaster(deviceId)) {
        return;
    }
    DefaultRoutingHandler rh = srManager.getRoutingHandler();
    if (rh == null) {
        return;
    }
    if (!rh.isRoutingStable()) {
        return;
    }
    rh.acquireRoutingLock();
    try {
        log.trace("running bucket corrector for dev: {}", deviceId);
        Set<DestinationSetNextObjectiveStoreKey> dsKeySet = dsNextObjStore.entrySet()
                .stream()
                .filter(entry -> entry.getKey().deviceId().equals(deviceId))
                // Filter out PW transit groups or include them if MPLS ECMP is supported
                .filter(entry -> !entry.getKey().destinationSet().notBos() ||
                        (entry.getKey().destinationSet().notBos() && srManager.getMplsEcmp()))
                // Filter out simple SWAP groups or include them if MPLS ECMP is supported
                .filter(entry -> !entry.getKey().destinationSet().swap() ||
                        (entry.getKey().destinationSet().swap() && srManager.getMplsEcmp()))
                .map(entry -> entry.getKey())
                .collect(Collectors.toSet());
        for (DestinationSetNextObjectiveStoreKey dsKey : dsKeySet) {
            NextNeighbors next = dsNextObjStore.get(dsKey);
            if (next == null) {
                continue;
            }
            int nid = next.nextId();
            if (nextId != null && nextId != nid) {
                continue;
            }
            log.trace("bkt-corr: dsNextObjStore for device {}: {}",
                      deviceId, dsKey, next);
            TrafficSelector.Builder metabuilder = DefaultTrafficSelector.builder();
            metabuilder.matchVlanId(srManager.getDefaultInternalVlan());
            NextObjective.Builder nextObjBuilder = DefaultNextObjective.builder()
                    .withId(nid)
                    .withType(NextObjective.Type.HASHED)
                    .withMeta(metabuilder.build())
                    .fromApp(appId);

            next.dstNextHops().forEach((dstDev, nextHops) -> {
                int edgeLabel = dsKey.destinationSet().getEdgeLabel(dstDev);
                nextHops.forEach(neighbor -> {
                    MacAddress neighborMac;
                    try {
                        neighborMac = deviceConfig.getDeviceMac(neighbor);
                    } catch (DeviceConfigNotFoundException e) {
                        log.warn(e.getMessage() + " Aborting neighbor"
                                + neighbor);
                        return;
                    }
                    devicePortMap.get(neighbor).forEach(port -> {
                        log.trace("verify in device {} nextId {}: bucket with"
                                + " port/label {}/{} to dst {} via {}",
                                deviceId, nid, port, edgeLabel,
                                dstDev, neighbor);
                        nextObjBuilder
                            .addTreatment(treatmentBuilder(port,
                                                           neighborMac,
                                                           dsKey.destinationSet().swap(),
                                                           edgeLabel));
                    });
                });
            });

            NextObjective nextObjective = nextObjBuilder.verify();
            flowObjectiveService.next(deviceId, nextObjective);
        }
    } finally {
        rh.releaseRoutingLock();
    }

}
 
Example 13
Source File: DefaultGroupHandler.java    From onos with Apache License 2.0 4 votes vote down vote up
/**
 * Updates the next objective for the given nextId .
 *
 * @param hostMac mac of host for which Next obj is to be updated.
 * @param hostVlanId vlan of host for which Next obj is to be updated.
 * @param port port with which to update the Next Obj.
 * @param nextId of Next Obj which needs to be updated.
 */
public void updateL3UcastGroupBucket(MacAddress hostMac, VlanId hostVlanId, PortNumber port, int nextId) {

   MacAddress deviceMac;
    try {
        deviceMac = deviceConfig.getDeviceMac(deviceId);
    } catch (DeviceConfigNotFoundException e) {
        log.warn(e.getMessage() + " in updateL3UcastGroupBucket");
        return;
    }

    TrafficSelector metadata =
             DefaultTrafficSelector.builder().matchVlanId(hostVlanId).build();

    TrafficTreatment.Builder tbuilder = DefaultTrafficTreatment.builder();
    tbuilder.deferred()
            .setEthDst(hostMac)
            .setEthSrc(deviceMac)
            .setVlanId(hostVlanId)
            .setOutput(port);

    log.debug(" update L3Ucast : deviceMac {}, port {}, host {}/{}, nextid {}, Treatment {} Meta {}",
                                 deviceMac, port, hostMac, hostVlanId, nextId, tbuilder.build(), metadata);

    NextObjective.Builder nextObjBuilder = DefaultNextObjective
            .builder().withId(nextId)
            .withType(NextObjective.Type.SIMPLE).fromApp(appId)
            .addTreatment(tbuilder.build())
            .withMeta(metadata);

    ObjectiveContext context = new DefaultObjectiveContext(
            (objective) -> log.debug(" NextId {} successfully updated host {} vlan {} with port {}",
                                     nextId, hostMac, hostVlanId, port),
            (objective, error) -> {
                log.warn(" NextId {} failed to update host {} vlan {} with port {}, error : {}",
                                     nextId, hostMac, hostVlanId, port, error);
                srManager.invalidateNextObj(objective.id());
            });

    NextObjective nextObj = nextObjBuilder.modify(context);
    flowObjectiveService.next(deviceId, nextObj);

}
 
Example 14
Source File: DefaultGroupHandler.java    From onos with Apache License 2.0 4 votes vote down vote up
/**
 * Removes a single broadcast group from a given vlan id.
 * The group should be empty.
 * @param deviceId device Id to remove the group
 * @param portNum port number related to the group
 * @param vlanId vlan id of the broadcast group to remove
 * @param popVlan true if the TrafficTreatment involves pop vlan tag action
 */
public void removeBcastGroupFromVlan(DeviceId deviceId, PortNumber portNum,
                                     VlanId vlanId, boolean popVlan) {
    VlanNextObjectiveStoreKey key = new VlanNextObjectiveStoreKey(deviceId, vlanId);

    if (!vlanNextObjStore.containsKey(key)) {
        log.debug("Broadcast group for device {} and subnet {} does not exist",
                  deviceId, vlanId);
        return;
    }

    TrafficSelector metadata =
            DefaultTrafficSelector.builder().matchVlanId(vlanId).build();

    int nextId = vlanNextObjStore.get(key);

    NextObjective.Builder nextObjBuilder = DefaultNextObjective
            .builder().withId(nextId)
            .withType(NextObjective.Type.BROADCAST).fromApp(appId)
            .withMeta(metadata);

    TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
    if (popVlan) {
        tBuilder.popVlan();
    }
    tBuilder.setOutput(portNum);
    nextObjBuilder.addTreatment(tBuilder.build());

    ObjectiveContext context = new DefaultObjectiveContext(
            (objective) ->
                    log.debug("removeBroadcastGroupFromVlan removed "
                                      + "NextObj {} on {}", nextId, deviceId),
            (objective, error) -> {
                log.warn("removeBroadcastGroupFromVlan failed to remove NextObj {} on {}: {}",
                        nextId, deviceId, error);
                srManager.invalidateNextObj(objective.id());
            });
    NextObjective nextObj = nextObjBuilder.remove(context);
    flowObjectiveService.next(deviceId, nextObj);
    log.debug("removeBcastGroupFromVlan: Submited next objective {} in device {}",
              nextId, deviceId);

    vlanNextObjStore.remove(key, nextId);
}
 
Example 15
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 16
Source File: XconnectManager.java    From onos with Apache License 2.0 4 votes vote down vote up
/**
 * Updates L2 flooding groups; add pair link into L2 flooding group of given xconnect vlan.
 *
 * @param deviceId Device ID
 * @param port     Port details
 * @param vlanId   VLAN ID
 * @param install  Whether to add or revoke pair link addition to flooding group
 */
private void updateL2Flooding(DeviceId deviceId, PortNumber port, VlanId vlanId, boolean install) {
    XconnectKey key = new XconnectKey(deviceId, vlanId);
    // Ensure leadership on device
    if (!isLocalLeader(deviceId)) {
        log.debug("Abort updating L2Flood {}: {}", key, ERROR_NOT_LEADER);
        return;
    }

    // Locate L2 flooding group details for given xconnect vlan
    int nextId = Versioned.valueOrElse(xconnectNextObjStore.get(key), -1);
    if (nextId == -1) {
        log.debug("XConnect vlan {} broadcast group for device {} doesn't exists. " +
                          "Aborting pair group linking.", vlanId, deviceId);
        return;
    }

    // Add pairing-port group to flooding group
    TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();
    // treatment.popVlan();
    treatment.setOutput(port);
    ObjectiveContext context = new DefaultObjectiveContext(
            (objective) ->
                    log.debug("Pair port added/removed to vlan {} next objective {} on {}",
                              vlanId, nextId, deviceId),
            (objective, error) ->
                    log.warn("Failed adding/removing pair port to vlan {} next objective {} on {}." +
                                     "Error : {}", vlanId, nextId, deviceId, error)
    );
    NextObjective.Builder vlanNextObjectiveBuilder = DefaultNextObjective.builder()
            .withId(nextId)
            .withType(NextObjective.Type.BROADCAST)
            .fromApp(srService.appId())
            .withMeta(DefaultTrafficSelector.builder().matchVlanId(vlanId).build())
            .addTreatment(treatment.build());
    if (install) {
        flowObjectiveService.next(deviceId, vlanNextObjectiveBuilder.addToExisting(context));
    } else {
        flowObjectiveService.next(deviceId, vlanNextObjectiveBuilder.removeFromExisting(context));
    }
    log.debug("Submitted next objective {} for vlan: {} in device {}",
              nextId, vlanId, deviceId);
}
 
Example 17
Source File: DefaultGroupHandler.java    From onos with Apache License 2.0 4 votes vote down vote up
/**
 * Makes a call to the FlowObjective service to remove buckets from
 * a hash group. User must ensure that all the ports & labels are meant
 * same neighbor (ie. dstMac).
 *
 * @param portLabels a collection of port & label combinations to remove
 *                   from the hash group identified by the nextId
 * @param dstMac destination mac address of next-hop
 * @param nextId id for next-objective from which buckets will be removed
 */
private void removeFromHashedNextObjective(Collection<PortLabel> portLabels,
                                           MacAddress dstMac, Integer nextId) {
    TrafficSelector.Builder metabuilder = DefaultTrafficSelector.builder();
    metabuilder.matchVlanId(srManager.getDefaultInternalVlan());
    NextObjective.Builder nextObjBuilder = DefaultNextObjective
            .builder()
            .withType(NextObjective.Type.HASHED) //same as original
            .withMeta(metabuilder.build())
            .withId(nextId)
            .fromApp(appId);
    // Create the buckets to be removed
    portLabels.forEach(pl -> {
        TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
        tBuilder.setOutput(pl.port)
            .setEthDst(dstMac)
            .setEthSrc(nodeMacAddr);
        if (pl.popVlan) {
            tBuilder.popVlan();
        }
        if (pl.edgeLabel != DestinationSet.NO_EDGE_LABEL) {
            tBuilder.pushMpls()
                .copyTtlOut()
                .setMpls(MplsLabel.mplsLabel(pl.edgeLabel));
        }
        nextObjBuilder.addTreatment(tBuilder.build());
    });
    log.debug("removeFromHash in device {}: Removing Bucket with port/label"
            + " {} from nextId {}", deviceId, portLabels, nextId);

    ObjectiveContext context = new DefaultObjectiveContext(
            (objective) -> log.debug("port/label {} removedFrom NextObj"
                    + " {} on {}", portLabels, nextId, deviceId),
            (objective, error) -> {
                log.warn("port/label {} failed to removeFrom NextObj {} on {}: {}",
                        portLabels, nextId, deviceId, error);
                srManager.invalidateNextObj(objective.id());
            });
    NextObjective nextObjective = nextObjBuilder.removeFromExisting(context);
    flowObjectiveService.next(deviceId, nextObjective);
}
 
Example 18
Source File: DefaultGroupHandler.java    From onos with Apache License 2.0 4 votes vote down vote up
/**
 * Makes a call to the FlowObjective service to add buckets to
 * a hashed group. User must ensure that all the ports & labels are meant
 * same neighbor (ie. dstMac).
 *
 * @param portLabels a collection of port & label combinations to add
 *                   to the hash group identified by the nextId
 * @param dstMac destination mac address of next-hop
 * @param nextId id for next-objective to which buckets will be added
 *
 */
private void addToHashedNextObjective(Collection<PortLabel> portLabels,
                                      MacAddress dstMac, Integer nextId) {
    // setup metadata to pass to nextObjective - indicate the vlan on egress
    // if needed by the switch pipeline. Since hashed next-hops are always to
    // other neighboring routers, there is no subnet assigned on those ports.
    TrafficSelector.Builder metabuilder = DefaultTrafficSelector.builder();
    metabuilder.matchVlanId(srManager.getDefaultInternalVlan());
    NextObjective.Builder nextObjBuilder = DefaultNextObjective.builder()
            .withId(nextId)
            .withType(NextObjective.Type.HASHED)
            .withMeta(metabuilder.build())
            .fromApp(appId);
    // Create the new buckets to be updated
    portLabels.forEach(pl -> {
        TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
        tBuilder.setOutput(pl.port)
            .setEthDst(dstMac)
            .setEthSrc(nodeMacAddr);
        if (pl.popVlan) {
            tBuilder.popVlan();
        }
        if (pl.edgeLabel != DestinationSet.NO_EDGE_LABEL) {
            tBuilder.pushMpls()
                .copyTtlOut()
                .setMpls(MplsLabel.mplsLabel(pl.edgeLabel));
        }
        nextObjBuilder.addTreatment(tBuilder.build());
    });

    log.debug("addToHash in device {}: Adding Bucket with port/label {} "
            + "to nextId {}", deviceId, portLabels, nextId);

    ObjectiveContext context = new DefaultObjectiveContext(
            (objective) -> log.debug("addToHash port/label {} addedTo "
                    + "NextObj {} on {}", portLabels, nextId, deviceId),
            (objective, error) -> {
                log.warn("addToHash failed to add port/label {} to NextObj {} on {}: {}",
                        portLabels, nextId, deviceId, error);
                srManager.invalidateNextObj(objective.id());
            });
    NextObjective nextObjective = nextObjBuilder.addToExisting(context);
    flowObjectiveService.next(deviceId, nextObjective);
}
 
Example 19
Source File: DefaultL2TunnelHandler.java    From onos with Apache License 2.0 4 votes vote down vote up
/**
 * Handles the tunnel establishment which consists in
 * create the next objectives related to the initiation.
 *
 * @param l2Tunnel  the tunnel to deploy
 * @param ingress   the ingress connect point
 * @param egress    the egress connect point
 * @param direction the direction of the pw
 * @param nextHop next hop of the initiation point
 * @param oneHop if this pseudowire has only one link
 * @param termVlanId the termination vlan id
 * @return the result of the operation
 */
private Result deployPseudoWireInit(L2Tunnel l2Tunnel, ConnectPoint ingress,
                                    ConnectPoint egress, Direction direction,
                                    Link nextHop, boolean oneHop, VlanId termVlanId) {
    log.debug("Started deploying init next objectives for pseudowire {} for tunnel {} -> {}.",
              l2Tunnel.tunnelId(), ingress, egress);
    if (nextHop == null) {
        log.warn("No path between ingress and egress connection points for tunnel {}", l2Tunnel.tunnelId());
        return WRONG_PARAMETERS;
    }

    // We create the next objective without the metadata
    // context and id. We check if it already exists in the
    // store. If not we store as it is in the store.
    NextObjective.Builder nextObjectiveBuilder = createNextObjective(INITIATION,
                                                                     nextHop.src(),
                                                                     nextHop.dst(),
                                                                     l2Tunnel,
                                                                     egress.deviceId(),
                                                                     oneHop,
                                                                     termVlanId);

    if (nextObjectiveBuilder == null) {
        return INTERNAL_ERROR;
    }
    // We set the metadata. We will use this metadata
    // to inform the driver we are doing a l2 tunnel.
    TrafficSelector metadata = DefaultTrafficSelector
            .builder()
            .matchTunnelId(l2Tunnel.tunnelId())
            .build();
    nextObjectiveBuilder.withMeta(metadata);
    int nextId = srManager.flowObjectiveService.allocateNextId();
    if (nextId < 0) {
        log.warn("Not able to allocate a next id for initiation");
        return INTERNAL_ERROR;
    }
    nextObjectiveBuilder.withId(nextId);
    String key = generateKey(l2Tunnel.tunnelId(), direction);
    l2InitiationNextObjStore.put(key, nextObjectiveBuilder.add());
    ObjectiveContext context = new DefaultObjectiveContext(
            (objective) -> log.debug("Initiation l2 tunnel rule for {} populated", l2Tunnel.tunnelId()),
            (objective, error) -> {
                log.warn("Failed to populate Initiation l2 tunnel rule for {}: {}", l2Tunnel.tunnelId(), error);
                srManager.invalidateNextObj(objective.id());
            });
    NextObjective nextObjective = nextObjectiveBuilder.add(context);
    srManager.flowObjectiveService.next(ingress.deviceId(), nextObjective);
    log.debug("Initiation next objective for {} not found. Creating new NextObj with id={}",
              l2Tunnel.tunnelId(), nextObjective.id());
    Result result = SUCCESS;
    result.setNextId(nextObjective.id());
    return result;
}
 
Example 20
Source File: XconnectManager.java    From onos with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a next objective builder for XConnect.
 *
 * @param key       XConnect key
 * @param endpoints Xconnect endpoints
 * @return next objective builder
 */
private NextObjective.Builder nextObjBuilder(XconnectKey key, Set<XconnectEndpoint> endpoints) {
    int nextId = flowObjectiveService.allocateNextId();
    return nextObjBuilder(key, endpoints, nextId);
}