Search in sources :

Example 6 with DeviceId

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

the class DefaultRoutingHandler method revokeSubnet.

/**
 * Revoke rules of given subnet in all edge switches. Use the
 * destination switch (if it is provided) to provide coordination
 * among the instances. Otherwise, only the leader of the target
 * switch can remove this subnet.
 *
 * @param subnets subnet being removed
 * @param destSw destination switch. It is null when it is called from RouteHandler,
 *               in this context we don't have a way to remember the old locations.
 * @return true if succeed
 */
protected boolean revokeSubnet(Set<IpPrefix> subnets, DeviceId destSw) {
    DeviceId targetSw;
    List<Future<Boolean>> futures = Lists.newArrayList();
    for (Device sw : srManager.deviceService.getAvailableDevices()) {
        targetSw = sw.id();
        // In some calls, we dont know anymore the destination switch
        if ((destSw != null && shouldProgram(destSw)) || shouldProgram(targetSw)) {
            futures.add(routePopulators.submit(new RevokeSubnet(targetSw, subnets)));
        } else {
            futures.add(CompletableFuture.completedFuture(true));
        }
    }
    // check the execution of each job
    return checkJobs(futures);
}
Also used : DeviceId(org.onosproject.net.DeviceId) Device(org.onosproject.net.Device) Future(java.util.concurrent.Future) CompletableFuture(java.util.concurrent.CompletableFuture)

Example 7 with DeviceId

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

the class DefaultRoutingHandler method compareGraphs.

/**
 * For the root switch, searches all the target nodes reachable in the base
 * graph, and compares paths to the ones in the comp graph.
 *
 * @param base the graph that is indexed for all reachable target nodes
 *             from the root node
 * @param comp the graph that the base graph is compared to
 * @param rootSw  both ecmp graphs are calculated for the root node
 * @return all the routes that have changed in the base graph
 */
private Set<ArrayList<DeviceId>> compareGraphs(EcmpShortestPathGraph base, EcmpShortestPathGraph comp, DeviceId rootSw) {
    ImmutableSet.Builder<ArrayList<DeviceId>> changedRoutesBuilder = ImmutableSet.builder();
    HashMap<Integer, HashMap<DeviceId, ArrayList<ArrayList<DeviceId>>>> baseMap = base.getAllLearnedSwitchesAndVia();
    HashMap<Integer, HashMap<DeviceId, ArrayList<ArrayList<DeviceId>>>> compMap = comp.getAllLearnedSwitchesAndVia();
    for (Integer itrIdx : baseMap.keySet()) {
        HashMap<DeviceId, ArrayList<ArrayList<DeviceId>>> baseViaMap = baseMap.get(itrIdx);
        for (DeviceId targetSw : baseViaMap.keySet()) {
            ArrayList<ArrayList<DeviceId>> basePath = baseViaMap.get(targetSw);
            ArrayList<ArrayList<DeviceId>> compPath = getVia(compMap, targetSw);
            if ((compPath == null) || !basePath.equals(compPath)) {
                log.trace("Impacted route:{} -> {}", targetSw, rootSw);
                ArrayList<DeviceId> route = new ArrayList<>();
                // switch with rules to populate
                route.add(targetSw);
                // towards this destination
                route.add(rootSw);
                changedRoutesBuilder.add(route);
            }
        }
    }
    return changedRoutesBuilder.build();
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) HashMap(java.util.HashMap) DeviceId(org.onosproject.net.DeviceId) ArrayList(java.util.ArrayList)

Example 8 with DeviceId

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

the class DeviceConfiguration method updateConfig.

public void updateConfig() {
    // Read config from device subject, excluding gatewayIps and subnets.
    Set<DeviceId> deviceSubjects = srManager.cfgService.getSubjects(DeviceId.class, SegmentRoutingDeviceConfig.class);
    deviceSubjects.forEach(subject -> {
        SegmentRoutingDeviceConfig config = srManager.cfgService.getConfig(subject, SegmentRoutingDeviceConfig.class);
        SegmentRouterInfo info = new SegmentRouterInfo();
        info.deviceId = subject;
        info.ipv4NodeSid = config.nodeSidIPv4();
        info.ipv6NodeSid = config.nodeSidIPv6();
        info.ipv4Loopback = config.routerIpv4();
        info.ipv6Loopback = config.routerIpv6();
        info.mac = config.routerMac();
        info.isEdge = config.isEdgeRouter();
        info.adjacencySids = config.adjacencySids();
        info.pairDeviceId = config.pairDeviceId();
        info.pairLocalPort = config.pairLocalPort();
        info.pwRoutingLabel = info.ipv4NodeSid + 1000;
        deviceConfigMap.put(info.deviceId, info);
        log.debug("Read device config for device: {}", info.deviceId);
        // IPv6 sid is not inserted. this part of the code is not used for now.
        allSegmentIds.add(info.ipv4NodeSid);
        // Block host with routerMac and untagged VLAN
        blockHost(info.mac, VlanId.NONE);
    });
    // Read gatewayIps and subnets from port subject. Ignore suppressed ports.
    Set<ConnectPoint> portSubjects = srManager.cfgService.getSubjects(ConnectPoint.class, InterfaceConfig.class);
    portSubjects.stream().filter(subject -> deviceConfigMap.containsKey(subject.deviceId())).filter(subject -> !isSuppressedPort(subject)).forEach(subject -> {
        InterfaceConfig config = srManager.cfgService.getConfig(subject, InterfaceConfig.class);
        Set<Interface> networkInterfaces;
        try {
            networkInterfaces = config.getInterfaces();
        } catch (ConfigException e) {
            log.error("Error loading port configuration");
            return;
        }
        networkInterfaces.forEach(networkInterface -> {
            VlanId vlanId = networkInterface.vlan();
            ConnectPoint connectPoint = networkInterface.connectPoint();
            DeviceId dpid = connectPoint.deviceId();
            PortNumber port = connectPoint.port();
            MacAddress mac = networkInterface.mac();
            SegmentRouterInfo info = deviceConfigMap.get(dpid);
            // skip if there is no corresponding device for this ConnectPoint
            if (info != null) {
                // Extract subnet information
                List<InterfaceIpAddress> interfaceAddresses = networkInterface.ipAddressesList();
                interfaceAddresses.forEach(interfaceAddress -> {
                    // Do not add /0, /32 and /128 to gateway IP list
                    int prefixLength = interfaceAddress.subnetAddress().prefixLength();
                    IpPrefix ipPrefix = interfaceAddress.subnetAddress();
                    if (ipPrefix.isIp4()) {
                        if (prefixLength != 0 && prefixLength != IpPrefix.MAX_INET_MASK_LENGTH) {
                            info.gatewayIps.put(port, interfaceAddress.ipAddress());
                        }
                        info.subnets.put(port, interfaceAddress.subnetAddress());
                    } else {
                        if (prefixLength != 0 && prefixLength != IpPrefix.MAX_INET6_MASK_LENGTH) {
                            info.gatewayIps.put(port, interfaceAddress.ipAddress());
                        }
                        info.subnets.put(port, interfaceAddress.subnetAddress());
                    }
                });
                // Override interface mac with router mac
                if (!mac.equals(info.mac)) {
                    ArrayNode array = (ArrayNode) config.node();
                    for (JsonNode intfNode : array) {
                        ObjectNode objNode = (ObjectNode) intfNode;
                        objNode.put(InterfaceConfig.MAC, info.mac.toString());
                    }
                    srManager.cfgService.applyConfig(connectPoint, InterfaceConfig.class, array);
                }
                // Block host with routerMac and taggedVlan
                networkInterface.vlanTagged().forEach(taggedVlan -> {
                    blockHost(info.mac, taggedVlan);
                });
            }
        });
        // We register the connect point with the NRS.
        srManager.registerConnectPoint(subject);
    });
}
Also used : DeviceConfigNotFoundException(org.onosproject.segmentrouting.config.DeviceConfigNotFoundException) Route(org.onosproject.routeservice.Route) Interface(org.onosproject.net.intf.Interface) PortNumber(org.onosproject.net.PortNumber) InterfaceConfig(org.onosproject.net.config.basics.InterfaceConfig) LoggerFactory(org.slf4j.LoggerFactory) SegmentRoutingDeviceConfig(org.onosproject.segmentrouting.config.SegmentRoutingDeviceConfig) HashMap(java.util.HashMap) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Multimaps(com.google.common.collect.Multimaps) ConnectPoint(org.onosproject.net.ConnectPoint) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) SegmentRoutingAppConfig(org.onosproject.segmentrouting.config.SegmentRoutingAppConfig) HashMultimap(com.google.common.collect.HashMultimap) Lists(com.google.common.collect.Lists) Map(java.util.Map) BasicHostConfig(org.onosproject.net.config.basics.BasicHostConfig) JsonNode(com.fasterxml.jackson.databind.JsonNode) HostId(org.onosproject.net.HostId) IpAddress(org.onlab.packet.IpAddress) Ip6Address(org.onlab.packet.Ip6Address) ImmutableSet(com.google.common.collect.ImmutableSet) Ip4Address(org.onlab.packet.Ip4Address) Logger(org.slf4j.Logger) Collection(java.util.Collection) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) VlanId(org.onlab.packet.VlanId) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) Set(java.util.Set) InterfaceIpAddress(org.onosproject.net.host.InterfaceIpAddress) Collectors(java.util.stream.Collectors) SetMultimap(com.google.common.collect.SetMultimap) Sets(com.google.common.collect.Sets) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) Objects(java.util.Objects) List(java.util.List) Stream(java.util.stream.Stream) MacAddress(org.onlab.packet.MacAddress) DeviceProperties(org.onosproject.segmentrouting.config.DeviceProperties) DeviceId(org.onosproject.net.DeviceId) ConfigException(org.onosproject.net.config.ConfigException) Collections(java.util.Collections) IpPrefix(org.onlab.packet.IpPrefix) SegmentRoutingDeviceConfig(org.onosproject.segmentrouting.config.SegmentRoutingDeviceConfig) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) DeviceId(org.onosproject.net.DeviceId) ConfigException(org.onosproject.net.config.ConfigException) JsonNode(com.fasterxml.jackson.databind.JsonNode) MacAddress(org.onlab.packet.MacAddress) ConnectPoint(org.onosproject.net.ConnectPoint) ConnectPoint(org.onosproject.net.ConnectPoint) IpPrefix(org.onlab.packet.IpPrefix) InterfaceConfig(org.onosproject.net.config.basics.InterfaceConfig) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) PortNumber(org.onosproject.net.PortNumber) Interface(org.onosproject.net.intf.Interface) VlanId(org.onlab.packet.VlanId) InterfaceIpAddress(org.onosproject.net.host.InterfaceIpAddress)

Example 9 with DeviceId

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

the class EcmpShortestPathGraph method calcECMPShortestPathGraph.

/**
 * Calculates the BFS tree.
 */
private void calcECMPShortestPathGraph() {
    deviceQueue.add(rootDevice);
    int currDistance = 0;
    distanceQueue.add(currDistance);
    deviceSearched.put(rootDevice, currDistance);
    while (!deviceQueue.isEmpty()) {
        DeviceId sw = deviceQueue.poll();
        Set<DeviceId> prevSw = Sets.newHashSet();
        currDistance = distanceQueue.poll();
        for (Link link : srManager.linkHandler.getDeviceEgressLinks(sw)) {
            if (srManager.linkHandler.avoidLink(link)) {
                continue;
            }
            DeviceId reachedDevice = link.dst().deviceId();
            if (prevSw.contains(reachedDevice)) {
                // Ignore LAG links between the same set of Devices
                continue;
            } else {
                prevSw.add(reachedDevice);
            }
            Integer distance = deviceSearched.get(reachedDevice);
            if ((distance != null) && (distance < (currDistance + 1))) {
                continue;
            }
            if (distance == null) {
                // First time visiting this Device node
                deviceQueue.add(reachedDevice);
                distanceQueue.add(currDistance + 1);
                deviceSearched.put(reachedDevice, currDistance + 1);
                ArrayList<DeviceId> distanceSwArray = distanceDeviceMap.get(currDistance + 1);
                if (distanceSwArray == null) {
                    distanceSwArray = new ArrayList<>();
                    distanceSwArray.add(reachedDevice);
                    distanceDeviceMap.put(currDistance + 1, distanceSwArray);
                } else {
                    distanceSwArray.add(reachedDevice);
                }
            }
            ArrayList<Link> upstreamLinkArray = upstreamLinks.get(reachedDevice);
            if (upstreamLinkArray == null) {
                upstreamLinkArray = new ArrayList<>();
                upstreamLinkArray.add(copyDefaultLink(link));
                // upstreamLinkArray.add(link);
                upstreamLinks.put(reachedDevice, upstreamLinkArray);
            } else {
                // ECMP links
                upstreamLinkArray.add(copyDefaultLink(link));
            }
        }
    }
}
Also used : DeviceId(org.onosproject.net.DeviceId) DefaultLink(org.onosproject.net.DefaultLink) Link(org.onosproject.net.Link)

Example 10 with DeviceId

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

the class EcmpShortestPathGraph method getECMPPaths.

/**
 * Return the computed ECMP paths from the root Device to a given Device in
 * the network.
 *
 * @param targetDevice the target Device
 * @return the list of ECMP Paths from the root Device to the target Device
 */
public ArrayList<Path> getECMPPaths(DeviceId targetDevice) {
    ArrayList<Path> pathArray = paths.get(targetDevice);
    if (pathArray == null && deviceSearched.containsKey(targetDevice)) {
        pathArray = new ArrayList<>();
        DeviceId sw = targetDevice;
        getDFSPaths(sw, null, pathArray);
        paths.put(targetDevice, pathArray);
    }
    return pathArray;
}
Also used : DefaultPath(org.onosproject.net.DefaultPath) Path(org.onosproject.net.Path) DeviceId(org.onosproject.net.DeviceId)

Aggregations

DeviceId (org.onosproject.net.DeviceId)782 List (java.util.List)178 PortNumber (org.onosproject.net.PortNumber)170 Collectors (java.util.stream.Collectors)152 ConnectPoint (org.onosproject.net.ConnectPoint)152 Set (java.util.Set)138 DeviceService (org.onosproject.net.device.DeviceService)122 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)118 ArrayList (java.util.ArrayList)115 VlanId (org.onlab.packet.VlanId)115 Logger (org.slf4j.Logger)114 Collections (java.util.Collections)109 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)109 Device (org.onosproject.net.Device)107 Collection (java.util.Collection)106 Test (org.junit.Test)104 CoreService (org.onosproject.core.CoreService)103 FlowRule (org.onosproject.net.flow.FlowRule)101 ImmutableSet (com.google.common.collect.ImmutableSet)99 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)96