Search in sources :

Example 66 with NextObjective

use of org.onosproject.net.flowobjective.NextObjective in project onos by opennetworkinglab.

the class FibInstaller method addNextHop.

private synchronized void addNextHop(ResolvedRoute route) {
    prefixToNextHop.put(route.prefix(), route.nextHop());
    if (nextHopsCount.count(route.nextHop()) == 0) {
        // There was no next hop in the multiset
        Interface egressIntf = interfaceService.getMatchingInterface(route.nextHop());
        if (egressIntf == null) {
            log.warn("no egress interface found for {}", route);
            return;
        }
        NextHopGroupKey groupKey = new NextHopGroupKey(route.nextHop());
        NextHop nextHop = new NextHop(route.nextHop(), route.nextHopMac(), groupKey);
        TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder().setEthSrc(egressIntf.mac()).setEthDst(nextHop.mac());
        TrafficSelector.Builder metabuilder = null;
        if (!egressIntf.vlan().equals(VlanId.NONE)) {
            treatment.pushVlan().setVlanId(egressIntf.vlan()).setVlanPcp((byte) 0);
        } else {
            // untagged outgoing port may require internal vlan in some pipelines
            metabuilder = DefaultTrafficSelector.builder();
            metabuilder.matchVlanId(VlanId.vlanId(ASSIGNED_VLAN));
        }
        treatment.setOutput(egressIntf.connectPoint().port());
        int nextId = flowObjectiveService.allocateNextId();
        NextObjective.Builder nextBuilder = DefaultNextObjective.builder().withId(nextId).addTreatment(treatment.build()).withType(NextObjective.Type.SIMPLE).fromApp(fibAppId);
        if (metabuilder != null) {
            nextBuilder.withMeta(metabuilder.build());
        }
        // TODO add callbacks
        NextObjective nextObjective = nextBuilder.add();
        flowObjectiveService.next(deviceId, nextObjective);
        nextHops.put(nextHop.ip(), nextId);
        if (routeToNextHop) {
            // Install route to next hop
            ForwardingObjective fob = generateRibForwardingObj(IpPrefix.valueOf(route.nextHop(), 32), nextId).add();
            flowObjectiveService.forward(deviceId, fob);
        }
    }
    nextHopsCount.add(route.nextHop());
}
Also used : DefaultNextObjective(org.onosproject.net.flowobjective.DefaultNextObjective) NextObjective(org.onosproject.net.flowobjective.NextObjective) NextHop(org.onosproject.routing.NextHop) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) DefaultForwardingObjective(org.onosproject.net.flowobjective.DefaultForwardingObjective) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) Interface(org.onosproject.net.intf.Interface) NextHopGroupKey(org.onosproject.routing.NextHopGroupKey)

Example 67 with NextObjective

use of org.onosproject.net.flowobjective.NextObjective in project onos by opennetworkinglab.

the class FibInstallerTest method testRouteAddWithVlan.

/**
 * Tests adding a route with to a next hop in a VLAN.
 *
 * We verify that the flowObjectiveService records the correct state and that the
 * correct flowObjectiveService is submitted to the flowObjectiveService.
 */
@Test
public void testRouteAddWithVlan() {
    ResolvedRoute route = createRoute(PREFIX1, NEXT_HOP2, MAC2);
    // Create the next objective
    NextObjective nextObjective = createNextObjective(MAC2, MAC2, SW1_ETH2.port(), VLAN1, true);
    flowObjectiveService.next(DEVICE_ID, nextObjective);
    // Create the flow objective
    ForwardingObjective fwd = createForwardingObjective(PREFIX1, true);
    flowObjectiveService.forward(DEVICE_ID, fwd);
    EasyMock.expectLastCall().once();
    setUpFlowObjectiveService();
    // Send in the add event
    routeListener.event(new RouteEvent(RouteEvent.Type.ROUTE_ADDED, route));
    verify(flowObjectiveService);
}
Also used : DefaultNextObjective(org.onosproject.net.flowobjective.DefaultNextObjective) NextObjective(org.onosproject.net.flowobjective.NextObjective) RouteEvent(org.onosproject.routeservice.RouteEvent) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) DefaultForwardingObjective(org.onosproject.net.flowobjective.DefaultForwardingObjective) ResolvedRoute(org.onosproject.routeservice.ResolvedRoute) Test(org.junit.Test)

Example 68 with NextObjective

use of org.onosproject.net.flowobjective.NextObjective in project onos by opennetworkinglab.

the class FibInstallerTest method testRouteAdd.

/**
 * Tests adding a route.
 *
 * We verify that the flowObjectiveService records the correct state and that the
 * correct flow is submitted to the flowObjectiveService.
 */
@Test
public void testRouteAdd() {
    ResolvedRoute resolvedRoute = createRoute(PREFIX1, NEXT_HOP1, MAC1);
    // Create the next objective
    NextObjective nextObjective = createNextObjective(MAC1, MAC1, SW1_ETH1.port(), VlanId.NONE, true);
    flowObjectiveService.next(DEVICE_ID, nextObjective);
    // Create the flow objective
    ForwardingObjective fwd = createForwardingObjective(PREFIX1, true);
    flowObjectiveService.forward(DEVICE_ID, fwd);
    EasyMock.expectLastCall().once();
    setUpFlowObjectiveService();
    // Send in the add event
    RouteEvent routeEvent = new RouteEvent(RouteEvent.Type.ROUTE_ADDED, resolvedRoute);
    routeListener.event(routeEvent);
    verify(flowObjectiveService);
}
Also used : DefaultNextObjective(org.onosproject.net.flowobjective.DefaultNextObjective) NextObjective(org.onosproject.net.flowobjective.NextObjective) RouteEvent(org.onosproject.routeservice.RouteEvent) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) DefaultForwardingObjective(org.onosproject.net.flowobjective.DefaultForwardingObjective) ResolvedRoute(org.onosproject.routeservice.ResolvedRoute) Test(org.junit.Test)

Example 69 with NextObjective

use of org.onosproject.net.flowobjective.NextObjective in project trellis-control by opennetworkinglab.

the class DefaultGroupHandler method processEdgePort.

/**
 * Adds or removes a port that has been configured with a vlan to a broadcast group
 * for bridging. Should only be called by the instance leading the programming
 * for this device.
 *
 * @param port the port on this device that needs to be added/removed to a bcast group
 * @param vlanId the vlan id corresponding to the broadcast domain/group
 * @param popVlan indicates if packets should be sent out untagged or not out
 *                of the port. If true, indicates an access (untagged) or native vlan
 *                configuration. If false, indicates a trunk (tagged) vlan config.
 * @param portUp true if port is enabled, false if disabled
 */
public void processEdgePort(PortNumber port, VlanId vlanId, boolean popVlan, boolean portUp) {
    // get the next id for the subnet and edit it.
    Integer nextId = getVlanNextObjectiveId(vlanId);
    if (nextId == -1) {
        if (portUp) {
            log.debug("**Creating flooding group for first port enabled in" + " vlan {} on dev {} port {}", vlanId, deviceId, port);
            createBcastGroupFromVlan(vlanId, Collections.singleton(port));
        } else {
            log.warn("Could not find flooding group for subnet {} on dev:{} when" + " removing port:{}", vlanId, deviceId, port);
        }
        return;
    }
    log.info("**port{} in device {}: {} Bucket with Port {} to" + " next-id {}", (portUp) ? "UP" : "DOWN", deviceId, (portUp) ? "Adding" : "Removing", port, nextId);
    // Create the bucket to be added or removed
    TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
    if (popVlan) {
        tBuilder.popVlan();
    }
    tBuilder.setOutput(port);
    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 {} NextObj {} on {}", port, (portUp) ? "addedTo" : "removedFrom", nextId, deviceId), (objective, error) -> {
        log.warn("port {} failed to {} NextObj {} on {}: {}", port, (portUp) ? "addTo" : "removeFrom", nextId, deviceId, error);
        srManager.invalidateNextObj(objective.id());
    });
    NextObjective nextObj = (portUp) ? nextObjBuilder.addToExisting(context) : nextObjBuilder.removeFromExisting(context);
    log.debug("edgePort processed: Submited next objective {} in device {}", nextId, deviceId);
    flowObjectiveService.next(deviceId, nextObj);
}
Also used : DefaultNextObjective(org.onosproject.net.flowobjective.DefaultNextObjective) NextObjective(org.onosproject.net.flowobjective.NextObjective) DefaultObjectiveContext(org.onosproject.net.flowobjective.DefaultObjectiveContext) ObjectiveContext(org.onosproject.net.flowobjective.ObjectiveContext) DefaultObjectiveContext(org.onosproject.net.flowobjective.DefaultObjectiveContext) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment)

Example 70 with NextObjective

use of org.onosproject.net.flowobjective.NextObjective in project trellis-control by opennetworkinglab.

the class DefaultGroupHandler method removeGroupFromPort.

/**
 * 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
 * @return a completable future that completes when the port has been removed
 */
public CompletableFuture<Objective> removeGroupFromPort(PortNumber portNum, TrafficTreatment treatment, TrafficSelector meta) {
    PortNextObjectiveStoreKey key = new PortNextObjectiveStoreKey(deviceId, portNum, treatment, meta);
    Integer nextId = portNextObjStore.get(key);
    CompletableFuture<Objective> future = new CompletableFuture<>();
    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 done " + "NextObj {} on {}", nextId, deviceId);
        future.complete(objective);
    }, (objective, error) -> {
        log.warn("removeGroupFromPort failed to install NextObj {} on {}: {}", nextId, deviceId, error);
        srManager.invalidateNextObj(objective.id());
        future.complete(null);
    });
    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);
    return future;
}
Also used : PortNextObjectiveStoreKey(org.onosproject.segmentrouting.storekey.PortNextObjectiveStoreKey) DefaultNextObjective(org.onosproject.net.flowobjective.DefaultNextObjective) NextObjective(org.onosproject.net.flowobjective.NextObjective) DefaultNextObjective(org.onosproject.net.flowobjective.DefaultNextObjective) NextObjective(org.onosproject.net.flowobjective.NextObjective) Objective(org.onosproject.net.flowobjective.Objective) CompletableFuture(java.util.concurrent.CompletableFuture) DefaultObjectiveContext(org.onosproject.net.flowobjective.DefaultObjectiveContext) ObjectiveContext(org.onosproject.net.flowobjective.ObjectiveContext) DefaultObjectiveContext(org.onosproject.net.flowobjective.DefaultObjectiveContext)

Aggregations

NextObjective (org.onosproject.net.flowobjective.NextObjective)83 DefaultNextObjective (org.onosproject.net.flowobjective.DefaultNextObjective)57 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)56 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)55 TrafficSelector (org.onosproject.net.flow.TrafficSelector)51 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)47 ForwardingObjective (org.onosproject.net.flowobjective.ForwardingObjective)36 Objective (org.onosproject.net.flowobjective.Objective)31 ObjectiveContext (org.onosproject.net.flowobjective.ObjectiveContext)30 DeviceId (org.onosproject.net.DeviceId)29 PortNumber (org.onosproject.net.PortNumber)24 FilteringObjective (org.onosproject.net.flowobjective.FilteringObjective)24 DefaultObjectiveContext (org.onosproject.net.flowobjective.DefaultObjectiveContext)23 Set (java.util.Set)22 Test (org.junit.Test)22 List (java.util.List)21 Collectors (java.util.stream.Collectors)20 GroupBucket (org.onosproject.net.group.GroupBucket)19 GroupBuckets (org.onosproject.net.group.GroupBuckets)19 Lists (com.google.common.collect.Lists)18