Search in sources :

Example 16 with DeviceConfigNotFoundException

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

the class LinkHandler method updateHostPorts.

/**
 * Administratively enables or disables edge ports if the link that was
 * added or removed was the only uplink port from an edge device. Edge ports
 * that belong to dual-homed hosts are always processed. In addition,
 * single-homed host ports are optionally processed depending on the
 * singleHomedDown property.
 *
 * @param link the link to be processed
 * @param added true if link was added, false if link was removed
 */
private void updateHostPorts(Link link, boolean added) {
    // Topology has only a single pair of leaves
    if (srManager.getInfraDeviceIds().isEmpty()) {
        log.debug("No spine configured. Not updating edge port for {} {}", link, added ? "add" : "remove");
        return;
    }
    DeviceConfiguration devConfig = srManager.deviceConfiguration;
    if (added) {
        try {
            if (!devConfig.isEdgeDevice(link.src().deviceId()) || devConfig.isEdgeDevice(link.dst().deviceId())) {
                return;
            }
        } catch (DeviceConfigNotFoundException e) {
            log.warn("Unable to determine if link is a valid uplink" + e.getMessage());
        }
        // re-enable previously disabled ports on this edge-device if any
        Set<PortNumber> p = downedPortStore.remove(link.src().deviceId());
        if (p != null) {
            log.warn("Link src {} --> dst {} added is an edge-device uplink, " + "enabling dual homed ports if any: {}", link.src().deviceId(), link.dst().deviceId(), (p.isEmpty()) ? "no ports" : p);
            p.forEach(pnum -> srManager.deviceAdminService.changePortState(link.src().deviceId(), pnum, true));
        }
    } else {
        // If the device does not have a pair device - skip
        DeviceId dev = link.src().deviceId();
        if (getPairDeviceIdOrNull(dev) == null) {
            log.info("Device {} does not have pair device " + "not disabling access port", dev);
            return;
        }
        // Verify if last uplink
        if (!lastUplink(link)) {
            return;
        }
        // find dual homed hosts on this dev to disable
        Set<PortNumber> dp = srManager.hostHandler.getDualHomedHostPorts(dev);
        log.warn("Link src {} --> dst {} removed was the last uplink, " + "disabling  dual homed ports:  {}", dev, link.dst().deviceId(), (dp.isEmpty()) ? "no ports" : dp);
        dp.forEach(pnum -> srManager.deviceAdminService.changePortState(dev, pnum, false));
        if (srManager.singleHomedDown) {
            // get all configured ports and down them if they haven't already
            // been downed
            srManager.deviceService.getPorts(dev).stream().filter(p -> p.isEnabled() && !dp.contains(p.number())).filter(p -> srManager.interfaceService.isConfigured(new ConnectPoint(dev, p.number()))).filter(p -> !srManager.deviceConfiguration.isPairLocalPort(dev, p.number())).forEach(p -> {
                log.warn("Last uplink gone src {} -> dst {} .. removing " + "configured port {}", p.number());
                srManager.deviceAdminService.changePortState(dev, p.number(), false);
                dp.add(p.number());
            });
        }
        if (!dp.isEmpty()) {
            // update global store
            Set<PortNumber> p = downedPortStore.get(dev);
            if (p == null) {
                p = dp;
            } else {
                p.addAll(dp);
            }
            downedPortStore.put(link.src().deviceId(), p);
        }
    }
}
Also used : DeviceConfigNotFoundException(org.onosproject.segmentrouting.config.DeviceConfigNotFoundException) Logger(org.slf4j.Logger) HostLocation(org.onosproject.net.HostLocation) Device(org.onosproject.net.Device) ImmutableMap(com.google.common.collect.ImmutableMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) PortNumber(org.onosproject.net.PortNumber) LoggerFactory(org.slf4j.LoggerFactory) Set(java.util.Set) EventuallyConsistentMapBuilder(org.onosproject.store.service.EventuallyConsistentMapBuilder) WallClockTimestamp(org.onosproject.store.service.WallClockTimestamp) Collectors(java.util.stream.Collectors) Link(org.onosproject.net.Link) Sets(com.google.common.collect.Sets) ConnectPoint(org.onosproject.net.ConnectPoint) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) DefaultGroupHandler(org.onosproject.segmentrouting.grouphandler.DefaultGroupHandler) Map(java.util.Map) Entry(java.util.Map.Entry) LinkService(org.onosproject.net.link.LinkService) EventuallyConsistentMap(org.onosproject.store.service.EventuallyConsistentMap) DeviceId(org.onosproject.net.DeviceId) DeviceId(org.onosproject.net.DeviceId) PortNumber(org.onosproject.net.PortNumber) ConnectPoint(org.onosproject.net.ConnectPoint) DeviceConfigNotFoundException(org.onosproject.segmentrouting.config.DeviceConfigNotFoundException)

Example 17 with DeviceConfigNotFoundException

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

the class LinkHandler method avoidLink.

/**
 * Determines if the given link should be avoided in routing calculations by
 * policy or design.
 *
 * @param link the infrastructure link being queried
 * @return true if link should be avoided
 */
boolean avoidLink(Link link) {
    // XXX currently only avoids all pair-links. In the future can be
    // extended to avoid any generic link
    DeviceId src = link.src().deviceId();
    PortNumber srcPort = link.src().port();
    DeviceConfiguration devConfig = srManager.deviceConfiguration;
    if (devConfig == null || !devConfig.isConfigured(src)) {
        log.warn("Device {} not configured..cannot avoid link {}", src, link);
        return false;
    }
    DeviceId pairDev;
    PortNumber pairLocalPort, pairRemotePort = null;
    try {
        pairDev = devConfig.getPairDeviceId(src);
        pairLocalPort = devConfig.getPairLocalPort(src);
        if (pairDev != null) {
            pairRemotePort = devConfig.getPairLocalPort(pairDev);
        }
    } catch (DeviceConfigNotFoundException e) {
        log.warn("Pair dev for dev {} not configured..cannot avoid link {}", src, link);
        return false;
    }
    return srcPort.equals(pairLocalPort) && link.dst().deviceId().equals(pairDev) && link.dst().port().equals(pairRemotePort);
}
Also used : DeviceId(org.onosproject.net.DeviceId) PortNumber(org.onosproject.net.PortNumber) DeviceConfigNotFoundException(org.onosproject.segmentrouting.config.DeviceConfigNotFoundException)

Example 18 with DeviceConfigNotFoundException

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

the class RouteHandler method processSingleLeafPairIfNeeded.

protected boolean processSingleLeafPairIfNeeded(Set<ConnectPoint> locations, ConnectPoint location, IpPrefix prefix, VlanId nextHopVlan) {
    // Special handling for single leaf pair
    if (!srManager.getInfraDeviceIds().isEmpty()) {
        log.debug("Spine found. Skip single leaf pair handling");
        return false;
    }
    Optional<DeviceId> pairDeviceId = srManager.getPairDeviceId(location.deviceId());
    if (pairDeviceId.isEmpty()) {
        log.debug("Pair device of {} not found", location.deviceId());
        return false;
    }
    if (locations.stream().anyMatch(l -> l.deviceId().equals(pairDeviceId.get()))) {
        log.debug("Pair device has a next hop available. Leave it as is.");
        return false;
    }
    Optional<PortNumber> pairRemotePort = srManager.getPairLocalPort(pairDeviceId.get());
    if (pairRemotePort.isEmpty()) {
        log.debug("Pair remote port of {} not found", pairDeviceId.get());
        return false;
    }
    // Use routerMac of the pair device as the next hop
    MacAddress effectiveMac;
    try {
        effectiveMac = srManager.getDeviceMacAddress(location.deviceId());
    } catch (DeviceConfigNotFoundException e) {
        log.warn("Abort populateRoute on pair device {}. routerMac not found", pairDeviceId);
        return false;
    }
    // Since the pairLocalPort is trunk port, use assigned vlan of original port
    // when the host is untagged
    VlanId effectiveVlan = Optional.ofNullable(srManager.getInternalVlanId(location)).orElse(nextHopVlan);
    log.debug("Single leaf pair. populateRoute {}/{}, {}, {}, {}", pairDeviceId, pairRemotePort, prefix, effectiveMac, effectiveVlan);
    srManager.defaultRoutingHandler.populateRoute(pairDeviceId.get(), prefix, effectiveMac, effectiveVlan, pairRemotePort.get(), false);
    return true;
}
Also used : DeviceId(org.onosproject.net.DeviceId) PortNumber(org.onosproject.net.PortNumber) MacAddress(org.onlab.packet.MacAddress) DeviceConfigNotFoundException(org.onosproject.segmentrouting.config.DeviceConfigNotFoundException) VlanId(org.onlab.packet.VlanId)

Example 19 with DeviceConfigNotFoundException

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

the class McastUtils method getRouterMac.

/**
 * Get router mac using application config and the connect point.
 *
 * @param deviceId the device id
 * @param port the port number
 * @return the router mac if the port is configured, otherwise null
 */
private MacAddress getRouterMac(DeviceId deviceId, PortNumber port) {
    // Do nothing if the port is configured as suppressed
    ConnectPoint connectPoint = new ConnectPoint(deviceId, port);
    SegmentRoutingAppConfig appConfig = srManager.cfgService.getConfig(srManager.appId(), SegmentRoutingAppConfig.class);
    if (appConfig != null && appConfig.suppressSubnet().contains(connectPoint)) {
        log.info("Ignore suppressed port {}", connectPoint);
        return MacAddress.NONE;
    }
    // Get the router mac using the device configuration
    MacAddress routerMac;
    try {
        routerMac = srManager.deviceConfiguration().getDeviceMac(deviceId);
    } catch (DeviceConfigNotFoundException dcnfe) {
        log.warn("Failed to get device MAC since the device {} is not configured", deviceId);
        return null;
    }
    return routerMac;
}
Also used : SegmentRoutingAppConfig(org.onosproject.segmentrouting.config.SegmentRoutingAppConfig) MacAddress(org.onlab.packet.MacAddress) ConnectPoint(org.onosproject.net.ConnectPoint) DeviceConfigNotFoundException(org.onosproject.segmentrouting.config.DeviceConfigNotFoundException)

Example 20 with DeviceConfigNotFoundException

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

the class PolicyManager method redirectPolicyNextObjective.

private NextObjective.Builder redirectPolicyNextObjective(DeviceId srcDevice, RedirectPolicy redirectPolicy) {
    Set<Link> egressLinks = linkService.getDeviceEgressLinks(srcDevice);
    Map<ConnectPoint, DeviceId> egressPortsToEnforce = Maps.newHashMap();
    List<DeviceId> edgeDevices = getEdgeDeviceIds();
    egressLinks.stream().filter(link -> redirectPolicy.spinesToEnforce().contains(link.dst().deviceId()) && !edgeDevices.contains(link.dst().deviceId())).forEach(link -> egressPortsToEnforce.put(link.src(), link.dst().deviceId()));
    // No ports no friend
    if (egressPortsToEnforce.isEmpty()) {
        log.warn("There are no port available for the REDIRECT policy {}", redirectPolicy.policyId());
        return null;
    }
    // We need to add a treatment for each valid egress port. The treatment
    // requires to set src and dst mac address and set the egress port. We are
    // deliberately not providing the metadata to prevent the programming of
    // some tables which are already controlled by SegmentRouting or are unnecessary
    int nextId = flowObjectiveService.allocateNextId();
    DefaultNextObjective.Builder builder = DefaultNextObjective.builder().withId(nextId).withType(NextObjective.Type.HASHED).fromApp(appId);
    MacAddress srcDeviceMac;
    try {
        srcDeviceMac = getDeviceMacAddress(srcDevice);
    } catch (DeviceConfigNotFoundException e) {
        log.warn(e.getMessage() + " Aborting installation REDIRECT policy {}", redirectPolicy.policyId());
        return null;
    }
    MacAddress neigborDeviceMac;
    TrafficTreatment.Builder tBuilder;
    for (Map.Entry<ConnectPoint, DeviceId> entry : egressPortsToEnforce.entrySet()) {
        try {
            neigborDeviceMac = getDeviceMacAddress(entry.getValue());
        } catch (DeviceConfigNotFoundException e) {
            log.warn(e.getMessage() + " Aborting installation REDIRECT policy {}", redirectPolicy.policyId());
            return null;
        }
        tBuilder = DefaultTrafficTreatment.builder().setEthSrc(srcDeviceMac).setEthDst(neigborDeviceMac).setOutput(entry.getKey().port());
        builder.addTreatment(tBuilder.build());
    }
    return builder;
}
Also used : DeviceConfigNotFoundException(org.onosproject.segmentrouting.config.DeviceConfigNotFoundException) ConsistentMap(org.onosproject.store.service.ConsistentMap) NetworkConfigRegistry(org.onosproject.net.config.NetworkConfigRegistry) PredictableExecutor(org.onlab.util.PredictableExecutor) CoreService(org.onosproject.core.CoreService) DeviceService(org.onosproject.net.device.DeviceService) Tools.groupedThreads(org.onlab.util.Tools.groupedThreads) DefaultNextObjective(org.onosproject.net.flowobjective.DefaultNextObjective) DropPolicy(org.onosproject.segmentrouting.policy.api.DropPolicy) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) Link(org.onosproject.net.Link) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) ConnectPoint(org.onosproject.net.ConnectPoint) Sets(org.glassfish.jersey.internal.guava.Sets) StorageService(org.onosproject.store.service.StorageService) Map(java.util.Map) ApplicationId(org.onosproject.core.ApplicationId) NextObjective(org.onosproject.net.flowobjective.NextObjective) KryoNamespaces(org.onosproject.store.serializers.KryoNamespaces) EDGE_PORT(org.onosproject.segmentrouting.metadata.SRObjectiveMetadata.EDGE_PORT) WorkPartitionService(org.onosproject.net.intent.WorkPartitionService) NodeId(org.onosproject.cluster.NodeId) Serializer(org.onosproject.store.service.Serializer) ImmutableSet(com.google.common.collect.ImmutableSet) Deactivate(org.osgi.service.component.annotations.Deactivate) Set(java.util.Set) DefaultForwardingObjective(org.onosproject.net.flowobjective.DefaultForwardingObjective) Collectors(java.util.stream.Collectors) TrafficMatchData(org.onosproject.segmentrouting.policy.api.TrafficMatchData) PolicyType(org.onosproject.segmentrouting.policy.api.Policy.PolicyType) Executors(java.util.concurrent.Executors) Versioned(org.onosproject.store.service.Versioned) List(java.util.List) ObjectiveContext(org.onosproject.net.flowobjective.ObjectiveContext) Policy(org.onosproject.segmentrouting.policy.api.Policy) TrafficMatchState(org.onosproject.segmentrouting.policy.api.TrafficMatchState) RedirectPolicy(org.onosproject.segmentrouting.policy.api.RedirectPolicy) LinkService(org.onosproject.net.link.LinkService) Optional(java.util.Optional) ClusterService(org.onosproject.cluster.ClusterService) HashFunction(com.google.common.hash.HashFunction) DeviceId(org.onosproject.net.DeviceId) PolicyService(org.onosproject.segmentrouting.policy.api.PolicyService) StorageException(org.onosproject.store.service.StorageException) NetworkConfigEvent(org.onosproject.net.config.NetworkConfigEvent) Hashing(com.google.common.hash.Hashing) SegmentRoutingDeviceConfig(org.onosproject.segmentrouting.config.SegmentRoutingDeviceConfig) CompletableFuture(java.util.concurrent.CompletableFuture) PolicyState(org.onosproject.segmentrouting.policy.api.PolicyState) KryoNamespace(org.onlab.util.KryoNamespace) MapEventListener(org.onosproject.store.service.MapEventListener) ArrayList(java.util.ArrayList) FlowObjectiveService(org.onosproject.net.flowobjective.FlowObjectiveService) TrafficMatch(org.onosproject.segmentrouting.policy.api.TrafficMatch) Component(org.osgi.service.component.annotations.Component) Lists(com.google.common.collect.Lists) TrafficSelector(org.onosproject.net.flow.TrafficSelector) Activate(org.osgi.service.component.annotations.Activate) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultObjectiveContext(org.onosproject.net.flowobjective.DefaultObjectiveContext) ExecutorService(java.util.concurrent.ExecutorService) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) Logger(org.slf4j.Logger) TrafficMatchPriority(org.onosproject.segmentrouting.policy.api.TrafficMatchPriority) Maps(com.google.common.collect.Maps) CodecService(org.onosproject.codec.CodecService) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) PolicyId(org.onosproject.segmentrouting.policy.api.PolicyId) TrafficMatchId(org.onosproject.segmentrouting.policy.api.TrafficMatchId) MapEvent(org.onosproject.store.service.MapEvent) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) Objective(org.onosproject.net.flowobjective.Objective) MacAddress(org.onlab.packet.MacAddress) Reference(org.osgi.service.component.annotations.Reference) NetworkConfigListener(org.onosproject.net.config.NetworkConfigListener) PolicyData(org.onosproject.segmentrouting.policy.api.PolicyData) DeviceId(org.onosproject.net.DeviceId) MacAddress(org.onlab.packet.MacAddress) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) ConnectPoint(org.onosproject.net.ConnectPoint) ConnectPoint(org.onosproject.net.ConnectPoint) DeviceConfigNotFoundException(org.onosproject.segmentrouting.config.DeviceConfigNotFoundException) DefaultNextObjective(org.onosproject.net.flowobjective.DefaultNextObjective) ConsistentMap(org.onosproject.store.service.ConsistentMap) Map(java.util.Map) Link(org.onosproject.net.Link)

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