Search in sources :

Example 26 with DeviceConfigNotFoundException

use of org.onosproject.segmentrouting.config.DeviceConfigNotFoundException in project trellis-control by opennetworkinglab.

the class RoutingRulePopulator method buildDoubleTaggedFilteringObj.

private FilteringObjective.Builder buildDoubleTaggedFilteringObj(DeviceId deviceId, PortNumber portNum, VlanId outerVlan, VlanId innerVlan, boolean cleanupDoubleTaggedRules) {
    MacAddress deviceMac;
    long metadata = 0;
    boolean isPairPort;
    try {
        deviceMac = config.getDeviceMac(deviceId);
        isPairPort = portNum.equals(config.getPairLocalPort(deviceId));
    } catch (DeviceConfigNotFoundException e) {
        log.warn(e.getMessage() + " Processing DoubleTaggedFilters aborted");
        return null;
    }
    FilteringObjective.Builder fob = DefaultFilteringObjective.builder();
    // Outer vlan id match should be appeared before inner vlan id match.
    fob.withKey(Criteria.matchInPort(portNum)).addCondition(Criteria.matchEthDst(deviceMac)).addCondition(Criteria.matchVlanId(outerVlan)).addCondition(Criteria.matchInnerVlanId(innerVlan)).withPriority(SegmentRoutingService.DEFAULT_PRIORITY);
    TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
    // Pop outer vlan
    tBuilder.popVlan();
    // NOTE: Special metadata for driver to signal when clean up double tagged entries
    if (cleanupDoubleTaggedRules) {
        metadata = metadata | CLEANUP_DOUBLE_TAGGED_HOST_ENTRIES;
    }
    // NOTE: Metadata to signal the port type to the driver
    metadata = metadata | portType(innerVlan, outerVlan, isPairPort);
    // NOTE: metadata equals 0 is rejected by the driver
    if (metadata > 0) {
        tBuilder.writeMetadata(metadata, METADATA_MASK);
    }
    // within the same VLAN on this device.
    if (noMoreEnabledPort(deviceId, outerVlan)) {
        tBuilder.wipeDeferred();
    }
    fob.withMeta(tBuilder.build());
    fob.permit().fromApp(srManager.appId);
    return fob;
}
Also used : DefaultFilteringObjective(org.onosproject.net.flowobjective.DefaultFilteringObjective) FilteringObjective(org.onosproject.net.flowobjective.FilteringObjective) MacAddress(org.onlab.packet.MacAddress) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) DeviceConfigNotFoundException(org.onosproject.segmentrouting.config.DeviceConfigNotFoundException)

Example 27 with DeviceConfigNotFoundException

use of org.onosproject.segmentrouting.config.DeviceConfigNotFoundException in project trellis-control by opennetworkinglab.

the class RoutingRulePopulator method buildFilteringObjective.

private FilteringObjective.Builder buildFilteringObjective(DeviceId deviceId, PortNumber portnum, boolean pushVlan, VlanId vlanId, boolean doTMAC, boolean update) {
    MacAddress deviceMac;
    long metadata = 0;
    boolean isPairPort;
    try {
        deviceMac = config.getDeviceMac(deviceId);
        isPairPort = portnum.equals(config.getPairLocalPort(deviceId));
    } catch (DeviceConfigNotFoundException e) {
        log.warn(e.getMessage() + " Processing SinglePortFilters aborted");
        return null;
    }
    FilteringObjective.Builder fob = DefaultFilteringObjective.builder();
    if (doTMAC) {
        fob.withKey(Criteria.matchInPort(portnum)).addCondition(Criteria.matchEthDst(deviceMac)).withPriority(SegmentRoutingService.DEFAULT_PRIORITY);
    } else {
        fob.withKey(Criteria.matchInPort(portnum)).withPriority(SegmentRoutingService.DEFAULT_PRIORITY);
    }
    TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
    if (pushVlan) {
        fob.addCondition(Criteria.matchVlanId(VlanId.NONE));
        tBuilder.pushVlan().setVlanId(vlanId);
    } else {
        fob.addCondition(Criteria.matchVlanId(vlanId));
    }
    // within the same VLAN on this device.
    if (noMoreEnabledPort(deviceId, vlanId)) {
        tBuilder.wipeDeferred();
    }
    // configuration associated to that port
    if (update) {
        metadata = metadata | INTERFACE_CONFIG_UPDATE;
    }
    // NOTE: Metadata to signal the driver the port type
    metadata = metadata | portType(VlanId.NONE, vlanId, isPairPort);
    // NOTE: metadata equals 0 is rejected by the driver
    if (metadata > 0) {
        tBuilder.writeMetadata(metadata, METADATA_MASK);
    }
    fob.withMeta(tBuilder.build());
    fob.permit().fromApp(srManager.appId);
    return fob;
}
Also used : DefaultFilteringObjective(org.onosproject.net.flowobjective.DefaultFilteringObjective) FilteringObjective(org.onosproject.net.flowobjective.FilteringObjective) MacAddress(org.onlab.packet.MacAddress) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) DeviceConfigNotFoundException(org.onosproject.segmentrouting.config.DeviceConfigNotFoundException)

Example 28 with DeviceConfigNotFoundException

use of org.onosproject.segmentrouting.config.DeviceConfigNotFoundException in project trellis-control by opennetworkinglab.

the class RoutingRulePopulator method populateDoubleTaggedRoute.

/**
 * Populates IP rules for a route that has double-tagged next hop.
 *
 * @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 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
 * @param outPort port where the next hop attaches to
 */
void populateDoubleTaggedRoute(DeviceId deviceId, IpPrefix prefix, MacAddress hostMac, VlanId innerVlan, VlanId outerVlan, EthType outerTpid, PortNumber outPort) {
    ForwardingObjective.Builder fwdBuilder;
    log.debug("Populate direct routing entry for double-tagged host route {} at {}:{}", prefix, deviceId, outPort);
    try {
        fwdBuilder = routingFwdObjBuilder(deviceId, prefix, hostMac, outerVlan, outPort, innerVlan, outerTpid, true, false);
    } catch (DeviceConfigNotFoundException e) {
        log.error(e.getMessage() + " Aborting populateDoubleTaggedRoute");
        return;
    }
    if (fwdBuilder == null) {
        log.error("Aborting double-tagged host routing table entry due to error for dev:{} route:{}", deviceId, prefix);
        return;
    }
    int nextId = fwdBuilder.add().nextId();
    DefaultObjectiveContext context = new DefaultObjectiveContext(objective -> {
        log.debug("Direct routing rule for double-tagged host route {} populated. nextId={}", prefix, nextId);
    }, (objective, error) -> log.warn("Failed to populate direct routing rule for double-tagged host route {}: {}", prefix, error));
    srManager.flowObjectiveService.forward(deviceId, fwdBuilder.add(context));
    rulePopulationCounter.incrementAndGet();
}
Also used : 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 29 with DeviceConfigNotFoundException

use of org.onosproject.segmentrouting.config.DeviceConfigNotFoundException in project trellis-control by opennetworkinglab.

the class RoutingRulePopulator method revokeDoubleTaggedRoute.

/**
 * Revokes IP rules for a route that has double-tagged next hop.
 *
 * @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 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
 * @param outPort port where the next hop attaches to
 */
void revokeDoubleTaggedRoute(DeviceId deviceId, IpPrefix prefix, MacAddress hostMac, VlanId innerVlan, VlanId outerVlan, EthType outerTpid, PortNumber outPort) {
    ForwardingObjective.Builder fwdBuilder;
    log.debug("Revoking direct routing entry for double-tagged host route {} at {}:{}", prefix, deviceId, outPort);
    try {
        fwdBuilder = routingFwdObjBuilder(deviceId, prefix, hostMac, outerVlan, outPort, innerVlan, outerTpid, true, true);
    } catch (DeviceConfigNotFoundException e) {
        log.error(e.getMessage() + " Aborting revokeDoubleTaggedRoute");
        return;
    }
    if (fwdBuilder == null) {
        log.error("Aborting double-tagged host routing table entry due to error for dev:{} route:{}", deviceId, prefix);
        return;
    }
    int nextId = fwdBuilder.remove().nextId();
    DefaultObjectiveContext context = new DefaultObjectiveContext(objective -> {
        log.debug("Direct routing rule for double-tagged host route {} revoked. nextId={}", prefix, nextId);
        // Try to remove next objective as well
        ImmutablePair<TrafficTreatment, TrafficSelector> treatmentAndMeta;
        try {
            treatmentAndMeta = getTreatmentAndMeta(deviceId, hostMac, outerVlan, outPort, innerVlan, outerTpid);
        } catch (DeviceConfigNotFoundException e) {
            log.error(e.getMessage() + " Aborting revokeDoubleTaggedRoute");
            return;
        }
        if (treatmentAndMeta == null) {
            // Warning log will come from getTreatmentAndMeta method
            return;
        }
        DefaultGroupHandler groupHandler = srManager.getGroupHandler(deviceId);
        if (groupHandler == null) {
            log.warn("Failed to revoke direct routing rule for double-tagged host route {}: " + "group handler not found for {}", prefix, deviceId);
            return;
        }
        groupHandler.removeGroupFromPort(outPort, treatmentAndMeta.getLeft(), treatmentAndMeta.getRight());
    }, (objective, error) -> log.warn("Failed to revoke direct routing rule for double-tagged host route {}: {}", prefix, error));
    srManager.flowObjectiveService.forward(deviceId, fwdBuilder.remove(context));
}
Also used : DefaultGroupHandler(org.onosproject.segmentrouting.grouphandler.DefaultGroupHandler) 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) DeviceConfigNotFoundException(org.onosproject.segmentrouting.config.DeviceConfigNotFoundException) ConnectPoint(org.onosproject.net.ConnectPoint)

Example 30 with DeviceConfigNotFoundException

use of org.onosproject.segmentrouting.config.DeviceConfigNotFoundException in project trellis-control by opennetworkinglab.

the class RoutingRulePopulator method updateFwdObj.

/**
 * Update Forwarding objective for each host and IP address connected to given port.
 * And create corresponding Simple Next objective if it does not exist.
 * Applied only when populating Forwarding objective
 * @param deviceId switch ID to set the rule
 * @param portNumber port number
 * @param prefix IP prefix of the route
 * @param hostMac MAC address of the next hop
 * @param vlanId Vlan ID of the port
 * @param popVlan true to pop vlan tag in TrafficTreatment
 * @param install true to populate the forwarding objective, false to revoke
 * @return a completable future that completes when the fwdobj completes. In case of removal,
 * the completable future completes when also the nextobj completes.
 */
CompletableFuture<Objective> updateFwdObj(DeviceId deviceId, PortNumber portNumber, IpPrefix prefix, MacAddress hostMac, VlanId vlanId, boolean popVlan, boolean install) {
    ForwardingObjective.Builder fob;
    TrafficSelector.Builder sbuilder = buildIpSelectorFromIpPrefix(prefix);
    MacAddress deviceMac;
    try {
        deviceMac = config.getDeviceMac(deviceId);
    } catch (DeviceConfigNotFoundException e) {
        log.warn(e.getMessage() + " Aborting updateFwdObj.");
        return CompletableFuture.completedFuture(null);
    }
    TrafficTreatment.Builder tbuilder = DefaultTrafficTreatment.builder();
    tbuilder.deferred().setEthDst(hostMac).setEthSrc(deviceMac).setOutput(portNumber);
    TrafficSelector.Builder mbuilder = DefaultTrafficSelector.builder();
    if (!popVlan) {
        mbuilder.matchVlanId(vlanId);
        tbuilder.setVlanId(vlanId);
    } else {
        mbuilder.matchVlanId(vlanId);
        tbuilder.popVlan();
    }
    // 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, portNumber, tbuilder.build(), mbuilder.build(), install);
    CompletableFuture<Objective> future = new CompletableFuture<>();
    if (portNextObjId == -1) {
        // Warning log will come from getPortNextObjective method
        return CompletableFuture.completedFuture(null);
    }
    fob = DefaultForwardingObjective.builder().withSelector(sbuilder.build()).nextStep(portNextObjId).fromApp(srManager.appId).makePermanent().withPriority(getPriorityFromPrefix(prefix)).withFlag(ForwardingObjective.Flag.SPECIFIC);
    ObjectiveContext context = new DefaultObjectiveContext((objective) -> {
        log.debug("IP rule for route {} {}", prefix, install ? "installed" : "revoked");
        future.complete(objective);
    }, (objective, error) -> {
        log.warn("Failed to {} IP rule for route {}: {}", install ? "install" : "revoke", prefix, error);
        future.complete(null);
    });
    srManager.flowObjectiveService.forward(deviceId, install ? fob.add(context) : fob.remove(context));
    if (!install) {
        if (!srManager.getVlanPortMap(deviceId).containsKey(vlanId) || !srManager.getVlanPortMap(deviceId).get(vlanId).contains(portNumber)) {
            DefaultGroupHandler grpHandler = srManager.getGroupHandler(deviceId);
            if (grpHandler == null) {
                log.warn("updateFwdObj: groupHandler for device {} not found", deviceId);
            } else {
                // Before moving forward we have to be sure flow has been removed;
                try {
                    future.get();
                } catch (InterruptedException | ExecutionException e) {
                    log.warn("Exception caught when executing IP rule removal for route {}", prefix);
                }
                // Flow future has been already consumed (normally or exceptionally)
                return grpHandler.removeGroupFromPort(portNumber, tbuilder.build(), mbuilder.build());
            }
        }
    }
    return future;
}
Also used : Builder(org.onosproject.net.flowobjective.ForwardingObjective.Builder) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) DefaultForwardingObjective(org.onosproject.net.flowobjective.DefaultForwardingObjective) MacAddress(org.onlab.packet.MacAddress) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) DeviceConfigNotFoundException(org.onosproject.segmentrouting.config.DeviceConfigNotFoundException) ConnectPoint(org.onosproject.net.ConnectPoint) 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) DefaultGroupHandler(org.onosproject.segmentrouting.grouphandler.DefaultGroupHandler) 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) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

DeviceConfigNotFoundException (org.onosproject.segmentrouting.config.DeviceConfigNotFoundException)48 DeviceId (org.onosproject.net.DeviceId)24 ConnectPoint (org.onosproject.net.ConnectPoint)22 MacAddress (org.onlab.packet.MacAddress)18 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)18 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)18 PortNumber (org.onosproject.net.PortNumber)11 DefaultObjectiveContext (org.onosproject.net.flowobjective.DefaultObjectiveContext)11 Set (java.util.Set)10 IpAddress (org.onlab.packet.IpAddress)9 VlanId (org.onlab.packet.VlanId)9 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)9 TrafficSelector (org.onosproject.net.flow.TrafficSelector)9 DefaultForwardingObjective (org.onosproject.net.flowobjective.DefaultForwardingObjective)9 ForwardingObjective (org.onosproject.net.flowobjective.ForwardingObjective)9 Ip4Address (org.onlab.packet.Ip4Address)8 Ip6Address (org.onlab.packet.Ip6Address)8 Logger (org.slf4j.Logger)8 ArrayList (java.util.ArrayList)7 HashSet (java.util.HashSet)7