Search in sources :

Example 26 with ConnectPoint

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

the class RouteHandler method processRouteRemovedInternal.

private void processRouteRemovedInternal(Collection<ResolvedRoute> routes) {
    if (!isReady()) {
        log.info("System is not ready. Skip removing route for {}", routes);
        return;
    }
    log.info("processRouteRemovedInternal. routes={}", routes);
    Set<IpPrefix> allPrefixes = Sets.newHashSet();
    routes.forEach(route -> {
        allPrefixes.add(route.prefix());
    });
    log.debug("RouteRemoved. revokeSubnet {}", allPrefixes);
    // FIXME remove routes more precisely by memorizing the old locations
    srManager.defaultRoutingHandler.revokeSubnet(allPrefixes, null);
    routes.forEach(route -> {
        IpPrefix prefix = route.prefix();
        MacAddress nextHopMac = route.nextHopMac();
        VlanId nextHopVlan = route.nextHopVlan();
        Set<ConnectPoint> locations = srManager.nextHopLocations(route);
        locations.forEach(location -> {
            log.debug("RouteRemoved. removeSubnet {}, {}", location, prefix);
            srManager.deviceConfiguration.removeSubnet(location, prefix);
        // We don't need to call revokeRoute again since revokeSubnet will remove the prefix
        // from all devices, including the ones that next hop attaches to.
        // revokeSubnet will also remove flow on the pair device (if exist) pointing to current location.
        });
    });
}
Also used : IpPrefix(org.onlab.packet.IpPrefix) MacAddress(org.onlab.packet.MacAddress) ConnectPoint(org.onosproject.net.ConnectPoint) VlanId(org.onlab.packet.VlanId)

Example 27 with ConnectPoint

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

the class RouteHandler method processHostMovedEvent.

void processHostMovedEvent(HostEvent event) {
    log.info("processHostMovedEvent {}", event);
    MacAddress hostMac = event.subject().mac();
    VlanId hostVlanId = event.subject().vlan();
    Set<ConnectPoint> prevLocations = event.prevSubject().locations().stream().map(h -> (ConnectPoint) h).collect(Collectors.toSet());
    Set<ConnectPoint> newLocations = event.subject().locations().stream().map(h -> (ConnectPoint) h).collect(Collectors.toSet());
    List<Set<IpPrefix>> batchedSubnets = srManager.deviceConfiguration.getBatchedSubnets(event.subject().id());
    Set<DeviceId> newDeviceIds = newLocations.stream().map(ConnectPoint::deviceId).collect(Collectors.toSet());
    // Set of deviceIDs of the previous locations where the host was connected
    // Used to determine if host moved to different connect points
    // on same device or moved to a different device altogether
    Set<DeviceId> oldDeviceIds = prevLocations.stream().map(ConnectPoint::deviceId).collect(Collectors.toSet());
    // and only when the no. of routes with the host as next-hop is not zero
    if (!batchedSubnets.isEmpty()) {
        // For each new location, if NextObj exists for the host, update with new location ..
        Sets.difference(newLocations, prevLocations).forEach(newLocation -> {
            // NOTE: that we use the nexthop vlanId to retrieve the nextId
            // while the vlanId used to program the L3 unicast chain
            // is derived from the port configuration. In case of
            // a tagged interface we use host vlanId. Host vlan should
            // be part of the tags configured for that port. See the
            // code in DefaultGroupHandler.updateL3UcastGroupBucket
            int nextId = srManager.getMacVlanNextObjectiveId(newLocation.deviceId(), hostMac, hostVlanId, null, false);
            if (nextId != -1) {
                // Update the nextId group bucket
                log.debug("HostMoved. NextId exists, update L3 Ucast Group Bucket {}, {}, {} --> {}", newLocation, hostMac, hostVlanId, nextId);
                srManager.updateMacVlanTreatment(newLocation.deviceId(), hostMac, hostVlanId, newLocation.port(), nextId);
            } else {
                log.debug("HostMoved. NextId does not exist for this location {}, host {}/{}", newLocation, hostMac, hostVlanId);
            }
        });
    }
    batchedSubnets.forEach(subnets -> {
        log.debug("HostMoved. populateSubnet {}, {}", newLocations, subnets);
        srManager.defaultRoutingHandler.populateSubnet(newLocations, subnets);
        subnets.forEach(prefix -> {
            // For each old location
            Sets.difference(prevLocations, newLocations).forEach(prevLocation -> {
                // Otherwise, do not remove and let the adding part update the old flow
                if (newDeviceIds.contains(prevLocation.deviceId())) {
                    return;
                }
                log.debug("HostMoved. removeSubnet {}, {}", prevLocation, prefix);
                srManager.deviceConfiguration.removeSubnet(prevLocation, prefix);
                // Do not remove flow from a device if the route is still reachable via its pair device.
                // If spine exists,
                // populateSubnet above will update the flow to point to its pair device via spine.
                // If spine does not exist,
                // processSingleLeafPair below will update the flow to point to its pair device via pair port.
                DeviceId pairDeviceId = srManager.getPairDeviceId(prevLocation.deviceId()).orElse(null);
                if (newLocations.stream().anyMatch(n -> n.deviceId().equals(pairDeviceId))) {
                    return;
                }
                log.debug("HostMoved. revokeRoute {}, {}, {}, {}", prevLocation, prefix, hostMac, hostVlanId);
                srManager.defaultRoutingHandler.revokeRoute(prevLocation.deviceId(), prefix, hostMac, hostVlanId, prevLocation.port(), false);
            });
            // For each new location, add all new IPs.
            Sets.difference(newLocations, prevLocations).forEach(newLocation -> {
                log.debug("HostMoved. addSubnet {}, {}", newLocation, prefix);
                srManager.deviceConfiguration.addSubnet(newLocation, prefix);
                // its a new connect point, not a move from an existing device, populateRoute
                if (!oldDeviceIds.contains(newLocation.deviceId())) {
                    log.debug("HostMoved. populateRoute {}, {}, {}, {}", newLocation, prefix, hostMac, hostVlanId);
                    srManager.defaultRoutingHandler.populateRoute(newLocation.deviceId(), prefix, hostMac, hostVlanId, newLocation.port(), false);
                }
            });
            newLocations.forEach(location -> {
                processSingleLeafPairIfNeeded(newLocations, location, prefix, hostVlanId);
            });
        });
    });
}
Also used : DeviceConfigNotFoundException(org.onosproject.segmentrouting.config.DeviceConfigNotFoundException) Logger(org.slf4j.Logger) Host(org.onosproject.net.Host) Collection(java.util.Collection) VlanId(org.onlab.packet.VlanId) PortNumber(org.onosproject.net.PortNumber) LoggerFactory(org.slf4j.LoggerFactory) RouteEvent(org.onosproject.routeservice.RouteEvent) Set(java.util.Set) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) ConnectPoint(org.onosproject.net.ConnectPoint) Objects(java.util.Objects) List(java.util.List) RouteInfo(org.onosproject.routeservice.RouteInfo) Optional(java.util.Optional) MacAddress(org.onlab.packet.MacAddress) HostEvent(org.onosproject.net.host.HostEvent) ResolvedRoute(org.onosproject.routeservice.ResolvedRoute) DeviceId(org.onosproject.net.DeviceId) IpPrefix(org.onlab.packet.IpPrefix) Set(java.util.Set) DeviceId(org.onosproject.net.DeviceId) MacAddress(org.onlab.packet.MacAddress) ConnectPoint(org.onosproject.net.ConnectPoint) VlanId(org.onlab.packet.VlanId) ConnectPoint(org.onosproject.net.ConnectPoint)

Example 28 with ConnectPoint

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

the class RouteHandler method processRouteAddedInternal.

/**
 * Internal logic that handles route addition.
 *
 * @param routes collection of routes to be processed
 * @param populateRouteOnly true if we only want to populateRoute but not populateSubnet.
 *                          Set it to true when initializing a device coming up.
 *                          populateSubnet will be done when link comes up later so it is redundant.
 *                          populateRoute still needs to be done for statically configured next hop hosts.
 */
private void processRouteAddedInternal(Collection<ResolvedRoute> routes, boolean populateRouteOnly) {
    if (!isReady()) {
        log.info("System is not ready. Skip adding route for {}", routes);
        return;
    }
    log.info("processRouteAddedInternal. routes={}", routes);
    if (routes.size() > 2) {
        log.info("Route {} has more than two next hops. Do not process route change", routes);
        return;
    }
    if (routes.isEmpty()) {
        log.warn("No resolved route found. Abort processRouteAddedInternal");
        return;
    }
    Set<ConnectPoint> allLocations = Sets.newHashSet();
    Set<IpPrefix> allPrefixes = Sets.newHashSet();
    routes.forEach(route -> {
        allLocations.addAll(srManager.nextHopLocations(route));
        allPrefixes.add(route.prefix());
    });
    log.debug("RouteAdded. populateSubnet {}, {}", allLocations, allPrefixes);
    srManager.defaultRoutingHandler.populateSubnet(allLocations, allPrefixes);
    routes.forEach(route -> {
        IpPrefix prefix = route.prefix();
        MacAddress nextHopMac = route.nextHopMac();
        VlanId nextHopVlan = route.nextHopVlan();
        Set<ConnectPoint> locations = srManager.nextHopLocations(route);
        locations.forEach(location -> {
            log.debug("RouteAdded. addSubnet {}, {}", location, prefix);
            srManager.deviceConfiguration.addSubnet(location, prefix);
            log.debug("RouteAdded populateRoute {}, {}, {}, {}", location, prefix, nextHopMac, nextHopVlan);
            srManager.defaultRoutingHandler.populateRoute(location.deviceId(), prefix, nextHopMac, nextHopVlan, location.port(), false);
            processSingleLeafPairIfNeeded(locations, location, prefix, nextHopVlan);
        });
    });
}
Also used : IpPrefix(org.onlab.packet.IpPrefix) MacAddress(org.onlab.packet.MacAddress) ConnectPoint(org.onosproject.net.ConnectPoint) VlanId(org.onlab.packet.VlanId)

Example 29 with ConnectPoint

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

the class McastRoleListCommand method doExecute.

@Override
protected void doExecute() {
    // Verify mcast group
    IpAddress mcastGroup = null;
    // We want to use source cp only for a specific group
    ConnectPoint sourcecp = null;
    if (!isNullOrEmpty(gAddr)) {
        mcastGroup = IpAddress.valueOf(gAddr);
        if (!isNullOrEmpty(source)) {
            sourcecp = ConnectPoint.deviceConnectPoint(source);
        }
    }
    // Get SR service, the roles and the groups
    SegmentRoutingService srService = get(SegmentRoutingService.class);
    Map<McastRoleStoreKey, McastRole> keyToRole = srService.getMcastRoles(mcastGroup, sourcecp);
    Set<IpAddress> mcastGroups = keyToRole.keySet().stream().map(McastRoleStoreKey::mcastIp).collect(Collectors.toSet());
    // Print the trees for each group
    mcastGroups.forEach(group -> {
        // Create a new map for the group
        Map<ConnectPoint, Multimap<McastRole, DeviceId>> roleDeviceIdMap = Maps.newHashMap();
        keyToRole.entrySet().stream().filter(entry -> entry.getKey().mcastIp().equals(group)).forEach(entry -> roleDeviceIdMap.compute(entry.getKey().source(), (gsource, map) -> {
            map = map == null ? ArrayListMultimap.create() : map;
            map.put(entry.getValue(), entry.getKey().deviceId());
            return map;
        }));
        roleDeviceIdMap.forEach((gsource, map) -> {
            // Print the map
            printMcastRole(group, gsource, map.get(McastRole.INGRESS), map.get(McastRole.TRANSIT), map.get(McastRole.EGRESS));
        });
    });
}
Also used : SegmentRoutingService(org.onosproject.segmentrouting.SegmentRoutingService) ArrayListMultimap(com.google.common.collect.ArrayListMultimap) McastRoleStoreKey(org.onosproject.segmentrouting.mcast.McastRoleStoreKey) McastGroupCompleter(org.onosproject.mcast.cli.McastGroupCompleter) Collection(java.util.Collection) Set(java.util.Set) Strings.isNullOrEmpty(com.google.common.base.Strings.isNullOrEmpty) Multimap(com.google.common.collect.Multimap) Maps(com.google.common.collect.Maps) Collectors(java.util.stream.Collectors) Command(org.apache.karaf.shell.api.action.Command) ConnectPoint(org.onosproject.net.ConnectPoint) AbstractShellCommand(org.onosproject.cli.AbstractShellCommand) SegmentRoutingService(org.onosproject.segmentrouting.SegmentRoutingService) ConnectPointCompleter(org.onosproject.cli.net.ConnectPointCompleter) Map(java.util.Map) Service(org.apache.karaf.shell.api.action.lifecycle.Service) Completion(org.apache.karaf.shell.api.action.Completion) Option(org.apache.karaf.shell.api.action.Option) DeviceId(org.onosproject.net.DeviceId) IpAddress(org.onlab.packet.IpAddress) McastRole(org.onosproject.segmentrouting.mcast.McastRole) ArrayListMultimap(com.google.common.collect.ArrayListMultimap) Multimap(com.google.common.collect.Multimap) McastRoleStoreKey(org.onosproject.segmentrouting.mcast.McastRoleStoreKey) IpAddress(org.onlab.packet.IpAddress) ConnectPoint(org.onosproject.net.ConnectPoint) McastRole(org.onosproject.segmentrouting.mcast.McastRole)

Example 30 with ConnectPoint

use of org.onosproject.net.ConnectPoint 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)

Aggregations

ConnectPoint (org.onosproject.net.ConnectPoint)536 Test (org.junit.Test)149 DeviceId (org.onosproject.net.DeviceId)125 FilteredConnectPoint (org.onosproject.net.FilteredConnectPoint)91 Link (org.onosproject.net.Link)88 Set (java.util.Set)86 PortNumber (org.onosproject.net.PortNumber)86 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)83 VlanId (org.onlab.packet.VlanId)78 TrafficSelector (org.onosproject.net.flow.TrafficSelector)75 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)72 Logger (org.slf4j.Logger)71 Port (org.onosproject.net.Port)70 List (java.util.List)69 Ethernet (org.onlab.packet.Ethernet)69 DeviceService (org.onosproject.net.device.DeviceService)67 Collectors (java.util.stream.Collectors)66 MacAddress (org.onlab.packet.MacAddress)64 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)64 Intent (org.onosproject.net.intent.Intent)62