Search in sources :

Example 11 with ObjectiveContext

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

the class RoutingRulePopulator method revokeIpRuleForRouter.

/**
 * 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;
}
Also used : 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) Builder(org.onosproject.net.flowobjective.ForwardingObjective.Builder) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) DefaultForwardingObjective(org.onosproject.net.flowobjective.DefaultForwardingObjective) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment)

Example 12 with ObjectiveContext

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

the class RoutingRulePopulator method revokeBridging.

/**
 * Revoke 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> revokeBridging(DeviceId deviceId, PortNumber port, MacAddress mac, VlanId vlanId) {
    ForwardingObjective.Builder fob = bridgingFwdObjBuilder(deviceId, mac, vlanId, port, true);
    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 {}/{} revoked", mac, vlanId);
        future.complete(objective);
    }, (objective, error) -> {
        log.warn("Failed to revoke bridging rule for {}/{}: {}", mac, vlanId, error);
        future.complete(null);
    });
    srManager.flowObjectiveService.forward(deviceId, fob.remove(context));
    return future;
}
Also used : ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) DefaultFilteringObjective(org.onosproject.net.flowobjective.DefaultFilteringObjective) FilteringObjective(org.onosproject.net.flowobjective.FilteringObjective) DefaultForwardingObjective(org.onosproject.net.flowobjective.DefaultForwardingObjective) 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) Builder(org.onosproject.net.flowobjective.ForwardingObjective.Builder) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) DefaultForwardingObjective(org.onosproject.net.flowobjective.DefaultForwardingObjective)

Example 13 with ObjectiveContext

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

the class RoutingRulePopulator method populateRoute.

/**
 * Populates IP rules for a route that has direct connection to the switch.
 * This method should not be invoked directly without going through DefaultRoutingHandler.
 *
 * @param deviceId device ID of the device that next hop attaches to
 * @param prefix IP prefix of the route
 * @param hostMac MAC address of the next hop
 * @param hostVlanId Vlan ID of the nexthop
 * @param outPort port where the next hop attaches to
 * @param directHost host is of type direct or indirect
 * @return future that carries the flow objective if succeeded, null if otherwise
 */
CompletableFuture<Objective> populateRoute(DeviceId deviceId, IpPrefix prefix, MacAddress hostMac, VlanId hostVlanId, PortNumber outPort, boolean directHost) {
    log.debug("Populate direct routing entry for route {} at {}:{}", prefix, deviceId, outPort);
    ForwardingObjective.Builder fwdBuilder;
    try {
        fwdBuilder = routingFwdObjBuilder(deviceId, prefix, hostMac, hostVlanId, outPort, null, null, directHost, false);
    } catch (DeviceConfigNotFoundException e) {
        log.warn(e.getMessage() + " Aborting direct populateRoute");
        return CompletableFuture.completedFuture(null);
    }
    if (fwdBuilder == null) {
        log.warn("Aborting host routing table entry due " + "to error for dev:{} route:{}", deviceId, prefix);
        return CompletableFuture.completedFuture(null);
    }
    int nextId = fwdBuilder.add().nextId();
    CompletableFuture<Objective> future = new CompletableFuture<>();
    ObjectiveContext context = new DefaultObjectiveContext((objective) -> {
        log.debug("Direct routing rule for route {} populated. nextId={}", prefix, nextId);
        future.complete(objective);
    }, (objective, error) -> {
        log.warn("Failed to populate direct routing rule for route {}: {}", prefix, error);
        future.complete(null);
    });
    srManager.flowObjectiveService.forward(deviceId, fwdBuilder.add(context));
    rulePopulationCounter.incrementAndGet();
    return future;
}
Also used : ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) DefaultFilteringObjective(org.onosproject.net.flowobjective.DefaultFilteringObjective) FilteringObjective(org.onosproject.net.flowobjective.FilteringObjective) DefaultForwardingObjective(org.onosproject.net.flowobjective.DefaultForwardingObjective) 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) Builder(org.onosproject.net.flowobjective.ForwardingObjective.Builder) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) DefaultForwardingObjective(org.onosproject.net.flowobjective.DefaultForwardingObjective) DeviceConfigNotFoundException(org.onosproject.segmentrouting.config.DeviceConfigNotFoundException) ConnectPoint(org.onosproject.net.ConnectPoint)

Example 14 with ObjectiveContext

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

the class RoutingRulePopulator method processDoubleTaggedFilter.

/**
 * 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));
    }
}
Also used : DefaultObjectiveContext(org.onosproject.net.flowobjective.DefaultObjectiveContext) ObjectiveContext(org.onosproject.net.flowobjective.ObjectiveContext) DefaultObjectiveContext(org.onosproject.net.flowobjective.DefaultObjectiveContext) DefaultFilteringObjective(org.onosproject.net.flowobjective.DefaultFilteringObjective) FilteringObjective(org.onosproject.net.flowobjective.FilteringObjective)

Example 15 with ObjectiveContext

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

the class McastHandler method removePortFromDevice.

/**
 * Removes a port from given multicast group on given device.
 * This involves the update of L3 multicast group and multicast routing
 * table entry.
 *
 * @param deviceId device ID
 * @param port port to be added
 * @param mcastIp multicast group
 * @param assignedVlan assigned VLAN ID
 * @return true if this is the last sink on this device
 */
private boolean removePortFromDevice(DeviceId deviceId, PortNumber port, IpAddress mcastIp, VlanId assignedVlan) {
    // TODO trace
    log.info("Removing {} on {}/{} and vlan {}", mcastIp, deviceId, port, assignedVlan);
    McastStoreKey mcastStoreKey = new McastStoreKey(mcastIp, deviceId, assignedVlan);
    // This device is not serving this multicast group
    if (!mcastNextObjStore.containsKey(mcastStoreKey)) {
        return true;
    }
    NextObjective nextObj = mcastNextObjStore.get(mcastStoreKey).value();
    Set<PortNumber> existingPorts = mcastUtils.getPorts(nextObj.next());
    // This port does not serve this multicast group
    if (!existingPorts.contains(port)) {
        if (!existingPorts.isEmpty()) {
            log.debug("{} is not serving {} on port {}. Abort.", deviceId, mcastIp, port);
            return false;
        }
        return true;
    }
    // Copy and modify the ImmutableSet
    existingPorts = Sets.newHashSet(existingPorts);
    existingPorts.remove(port);
    NextObjective newNextObj;
    ObjectiveContext context;
    ForwardingObjective fwdObj;
    if (existingPorts.isEmpty()) {
        context = new DefaultObjectiveContext((objective) -> log.debug("Successfully remove {} on {}/{}, vlan {}", mcastIp, deviceId, port.toLong(), assignedVlan), (objective, error) -> log.warn("Failed to remove {} on {}/{}, vlan {}: {}", mcastIp, deviceId, port.toLong(), assignedVlan, error));
        fwdObj = mcastUtils.fwdObjBuilder(mcastIp, assignedVlan, nextObj.id()).remove(context);
        if (!srManager.deviceConfiguration().isConfigured(deviceId)) {
            log.debug("skip forward flowobjective removal for device: {}", deviceId);
        } else {
            srManager.flowObjectiveService.forward(deviceId, fwdObj);
        }
        mcastNextObjStore.remove(mcastStoreKey);
    } else {
        // Here we store the next objective with the remaining port
        newNextObj = mcastUtils.nextObjBuilder(mcastIp, assignedVlan, existingPorts, nextObj.id()).removeFromExisting();
        mcastNextObjStore.put(mcastStoreKey, newNextObj);
        // Let's modify the next objective removing the bucket
        newNextObj = mcastUtils.nextObjBuilder(mcastIp, assignedVlan, ImmutableSet.of(port), nextObj.id()).removeFromExisting();
        if (!srManager.deviceConfiguration().isConfigured(deviceId)) {
            log.debug("skip next flowobjective update for device: {}", deviceId);
        } else {
            // no need to update the flow here since we have updated the next objective + group
            // the existing flow will keep pointing to the updated nextobj
            srManager.flowObjectiveService.next(deviceId, newNextObj);
        }
    }
    return existingPorts.isEmpty();
}
Also used : NextObjective(org.onosproject.net.flowobjective.NextObjective) ConsistentMap(org.onosproject.store.service.ConsistentMap) CoreService(org.onosproject.core.CoreService) PortNumber(org.onosproject.net.PortNumber) LoggerFactory(org.slf4j.LoggerFactory) Tools.groupedThreads(org.onlab.util.Tools.groupedThreads) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) ConsistentMultimap(org.onosproject.store.service.ConsistentMultimap) Link(org.onosproject.net.Link) SINKS_REMOVED(org.onosproject.mcast.api.McastEvent.Type.SINKS_REMOVED) ConnectPoint(org.onosproject.net.ConnectPoint) HashMultimap(com.google.common.collect.HashMultimap) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Executors.newScheduledThreadPool(java.util.concurrent.Executors.newScheduledThreadPool) McastEvent(org.onosproject.mcast.api.McastEvent) Port(org.onosproject.net.Port) Map(java.util.Map) ApplicationId(org.onosproject.core.ApplicationId) NextObjective(org.onosproject.net.flowobjective.NextObjective) SOURCES_ADDED(org.onosproject.mcast.api.McastEvent.Type.SOURCES_ADDED) INGRESS(org.onosproject.segmentrouting.mcast.McastRole.INGRESS) KryoNamespaces(org.onosproject.store.serializers.KryoNamespaces) SOURCES_REMOVED(org.onosproject.mcast.api.McastEvent.Type.SOURCES_REMOVED) Objects(com.google.common.base.Objects) ROUTE_ADDED(org.onosproject.mcast.api.McastEvent.Type.ROUTE_ADDED) NodeId(org.onosproject.cluster.NodeId) Serializer(org.onosproject.store.service.Serializer) ImmutableSet(com.google.common.collect.ImmutableSet) Device(org.onosproject.net.Device) Collection(java.util.Collection) Set(java.util.Set) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) SINKS_ADDED(org.onosproject.mcast.api.McastEvent.Type.SINKS_ADDED) Versioned(org.onosproject.store.service.Versioned) List(java.util.List) ObjectiveContext(org.onosproject.net.flowobjective.ObjectiveContext) Entry(java.util.Map.Entry) Optional(java.util.Optional) Path(org.onosproject.net.Path) DeviceId(org.onosproject.net.DeviceId) McastRouteUpdate(org.onosproject.mcast.api.McastRouteUpdate) ROUTE_REMOVED(org.onosproject.mcast.api.McastEvent.Type.ROUTE_REMOVED) Multimap(com.google.common.collect.Multimap) KryoNamespace(org.onlab.util.KryoNamespace) AtomicReference(java.util.concurrent.atomic.AtomicReference) Lists(com.google.common.collect.Lists) TRANSIT(org.onosproject.segmentrouting.mcast.McastRole.TRANSIT) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) HostId(org.onosproject.net.HostId) DefaultObjectiveContext(org.onosproject.net.flowobjective.DefaultObjectiveContext) IpAddress(org.onlab.packet.IpAddress) SegmentRoutingManager(org.onosproject.segmentrouting.SegmentRoutingManager) McastRouteData(org.onosproject.mcast.api.McastRouteData) Logger(org.slf4j.Logger) EGRESS(org.onosproject.segmentrouting.mcast.McastRole.EGRESS) Iterator(java.util.Iterator) VlanId(org.onlab.packet.VlanId) Maps(com.google.common.collect.Maps) McastRoute(org.onosproject.mcast.api.McastRoute) TimeUnit(java.util.concurrent.TimeUnit) DistributedSet(org.onosproject.store.service.DistributedSet) Comparator(java.util.Comparator) Collections(java.util.Collections) DefaultObjectiveContext(org.onosproject.net.flowobjective.DefaultObjectiveContext) ObjectiveContext(org.onosproject.net.flowobjective.ObjectiveContext) DefaultObjectiveContext(org.onosproject.net.flowobjective.DefaultObjectiveContext) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) PortNumber(org.onosproject.net.PortNumber)

Aggregations

ObjectiveContext (org.onosproject.net.flowobjective.ObjectiveContext)69 DefaultObjectiveContext (org.onosproject.net.flowobjective.DefaultObjectiveContext)57 ForwardingObjective (org.onosproject.net.flowobjective.ForwardingObjective)45 DefaultForwardingObjective (org.onosproject.net.flowobjective.DefaultForwardingObjective)41 NextObjective (org.onosproject.net.flowobjective.NextObjective)41 DefaultNextObjective (org.onosproject.net.flowobjective.DefaultNextObjective)37 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)35 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)35 TrafficSelector (org.onosproject.net.flow.TrafficSelector)35 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)35 Objective (org.onosproject.net.flowobjective.Objective)34 ConnectPoint (org.onosproject.net.ConnectPoint)33 FilteringObjective (org.onosproject.net.flowobjective.FilteringObjective)27 DefaultFilteringObjective (org.onosproject.net.flowobjective.DefaultFilteringObjective)26 CompletableFuture (java.util.concurrent.CompletableFuture)21 MacAddress (org.onlab.packet.MacAddress)19 ObjectiveError (org.onosproject.net.flowobjective.ObjectiveError)19 DeviceId (org.onosproject.net.DeviceId)17 Set (java.util.Set)16 Lists (com.google.common.collect.Lists)15