Search in sources :

Example 21 with Path

use of org.onosproject.net.Path in project onos by opennetworkinglab.

the class PathListCommand method doExecute.

@Override
protected void doExecute() {
    init();
    DeviceService deviceService = get(DeviceService.class);
    DeviceId srcDid = deviceId(src);
    if (deviceService.getDevice(srcDid) == null) {
        print("Unknown device %s", src);
        return;
    }
    DeviceId dstDid = deviceId(dst);
    if (deviceService.getDevice(dstDid) == null) {
        print("Unknown device %s", dst);
        return;
    }
    Set<? extends Path> paths;
    if (disjoint) {
        paths = service.getDisjointPaths(topology, srcDid, dstDid);
    } else {
        paths = service.getPaths(topology, srcDid, dstDid);
    }
    if (outputJson()) {
        print("%s", json(this, paths));
    } else {
        for (Path path : paths) {
            print(pathString(path));
            if (path instanceof DisjointPath) {
                // print backup right after primary
                print(pathString(((DisjointPath) path).backup()));
            }
        }
    }
}
Also used : Path(org.onosproject.net.Path) DisjointPath(org.onosproject.net.DisjointPath) DeviceId(org.onosproject.net.DeviceId) DeviceService(org.onosproject.net.device.DeviceService) DisjointPath(org.onosproject.net.DisjointPath)

Example 22 with Path

use of org.onosproject.net.Path in project onos by opennetworkinglab.

the class PathListCommand method json.

/**
 * Produces a JSON array containing the specified paths.
 *
 * @param context context to use for looking up codecs
 * @param paths collection of paths
 * @return JSON array
 */
public static JsonNode json(AbstractShellCommand context, Iterable<? extends Path> paths) {
    ObjectMapper mapper = context.mapper();
    ArrayNode result = mapper.createArrayNode();
    for (Path path : paths) {
        result.add(LinksListCommand.json(context, path).put("cost", path.cost()).set("links", LinksListCommand.json(context, path.links())));
        if (path instanceof DisjointPath) {
            // [ (primay), (backup), ...]
            DisjointPath backup = (DisjointPath) path;
            result.add(LinksListCommand.json(context, backup.backup()).put("cost", backup.cost()).set("links", LinksListCommand.json(context, backup.links())));
        }
    }
    return result;
}
Also used : Path(org.onosproject.net.Path) DisjointPath(org.onosproject.net.DisjointPath) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DisjointPath(org.onosproject.net.DisjointPath)

Example 23 with Path

use of org.onosproject.net.Path in project onos by opennetworkinglab.

the class ReactiveForwarding method fixBlackhole.

private void fixBlackhole(ConnectPoint egress) {
    Set<FlowEntry> rules = getFlowRulesFrom(egress);
    Set<SrcDstPair> pairs = findSrcDstPairs(rules);
    Map<DeviceId, Set<Path>> srcPaths = new HashMap<>();
    for (SrcDstPair sd : pairs) {
        // get the edge deviceID for the src host
        Host srcHost = hostService.getHost(HostId.hostId(sd.src));
        Host dstHost = hostService.getHost(HostId.hostId(sd.dst));
        if (srcHost != null && dstHost != null) {
            DeviceId srcId = srcHost.location().deviceId();
            DeviceId dstId = dstHost.location().deviceId();
            log.trace("SRC ID is {}, DST ID is {}", srcId, dstId);
            cleanFlowRules(sd, egress.deviceId());
            Set<Path> shortestPaths = srcPaths.get(srcId);
            if (shortestPaths == null) {
                shortestPaths = topologyService.getPaths(topologyService.currentTopology(), egress.deviceId(), srcId);
                srcPaths.put(srcId, shortestPaths);
            }
            backTrackBadNodes(shortestPaths, dstId, sd);
        }
    }
}
Also used : Path(org.onosproject.net.Path) Set(java.util.Set) ImmutableSet(com.google.common.collect.ImmutableSet) HashMap(java.util.HashMap) DeviceId(org.onosproject.net.DeviceId) Host(org.onosproject.net.Host) FlowEntry(org.onosproject.net.flow.FlowEntry)

Example 24 with Path

use of org.onosproject.net.Path in project onos by opennetworkinglab.

the class OpticalPathProvisioner method setupConnectivity.

/*
     * Request packet-layer connectivity between specified ports,
     * over packet-optical multi-layer infrastructure.
     *
     * Functionality-wise this is effectively submitting Packet-Optical
     * multi-layer P2P Intent.
     *
     * It computes multi-layer path meeting specified constraint,
     * and calls setupPath.
     */
@Override
public OpticalConnectivityId setupConnectivity(ConnectPoint ingress, ConnectPoint egress, Bandwidth bandwidth, Duration latency) {
    checkNotNull(ingress);
    checkNotNull(egress);
    log.info("setupConnectivity({}, {}, {}, {})", ingress, egress, bandwidth, latency);
    Bandwidth bw = (bandwidth == null) ? NO_BW_REQUIREMENT : bandwidth;
    Stream<Path> paths = topologyService.getKShortestPaths(topologyService.currentTopology(), ingress.deviceId(), egress.deviceId(), new BandwidthLinkWeight(bandwidth));
    // Path service calculates from node to node, we're only interested in port to port
    Optional<OpticalConnectivityId> id = paths.filter(p -> p.src().equals(ingress) && p.dst().equals(egress)).limit(maxPaths).map(p -> setupPath(p, bw, latency)).filter(Objects::nonNull).findFirst();
    if (id.isPresent()) {
        log.info("Assigned OpticalConnectivityId: {}", id);
    } else {
        log.error("setupConnectivity({}, {}, {}, {}) failed.", ingress, egress, bandwidth, latency);
    }
    return id.orElse(null);
}
Also used : Path(org.onosproject.net.Path) OpticalConnectivityId(org.onosproject.newoptical.api.OpticalConnectivityId) Bandwidth(org.onlab.util.Bandwidth)

Example 25 with Path

use of org.onosproject.net.Path in project onos by opennetworkinglab.

the class GnpyManager method obtainConnectivity.

@Override
public Pair<IntentId, Double> obtainConnectivity(ConnectPoint ingress, ConnectPoint egress, boolean bidirectional) {
    ByteArrayOutputStream connectivityRequest = createGnpyRequest(ingress, egress, bidirectional);
    String response = gnpyHttpUtil.post(null, "/gnpy-experimental", new ByteArrayInputStream(connectivityRequest.toByteArray()), MediaType.APPLICATION_JSON_TYPE, String.class);
    ObjectMapper om = new ObjectMapper();
    final ObjectReader reader = om.reader();
    JsonNode jsonNode;
    try {
        jsonNode = reader.readTree(response);
        if (jsonNode == null) {
            log.error("JsonNode is null for response {}", response);
            return null;
        }
        log.info("Response {}", response);
        String bestPath;
        try {
            bestPath = getBestOsnrPathKey(jsonNode);
        } catch (IllegalStateException e) {
            log.error("Exception while contacting GNPy", e);
            return null;
        }
        OchSignal ochSignal = createOchSignal(jsonNode);
        Map<DeviceId, Double> deviceAtoBPowerMap = new HashMap<>();
        Map<DeviceId, Double> deviceBtoAPowerMap = new HashMap<>();
        // TODO this list is currently only populated in the forward direction
        List<DeviceId> deviceIds = getDeviceAndPopulatePowerMap(jsonNode, deviceAtoBPowerMap, deviceBtoAPowerMap, bestPath);
        Path suggestedPath = createSuggestedPath(deviceIds);
        log.info("Suggested path {}", suggestedPath);
        Intent intent = createOpticalIntent(ingress, egress, deviceService, null, appId, bidirectional, ochSignal, suggestedPath);
        intentsPowerMap.put(intent.id(), new GnpyPowerInfo(deviceAtoBPowerMap, deviceBtoAPowerMap, getLaunchPower(jsonNode), suggestedPath.links(), ingress, egress, ochSignal));
        intentService.submit(intent);
        return Pair.of(intent.id(), getOsnr(jsonNode, bestPath));
    } catch (IOException e) {
        log.error("Exception while reading response {}", response, e);
        return null;
    }
}
Also used : Path(org.onosproject.net.Path) DefaultPath(org.onosproject.net.DefaultPath) HashMap(java.util.HashMap) DeviceId(org.onosproject.net.DeviceId) OchSignal(org.onosproject.net.OchSignal) JsonNode(com.fasterxml.jackson.databind.JsonNode) OpticalIntentUtility.createOpticalIntent(org.onosproject.net.optical.util.OpticalIntentUtility.createOpticalIntent) Intent(org.onosproject.net.intent.Intent) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) ByteArrayInputStream(java.io.ByteArrayInputStream) ObjectReader(com.fasterxml.jackson.databind.ObjectReader) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

Path (org.onosproject.net.Path)60 DeviceId (org.onosproject.net.DeviceId)27 DefaultPath (org.onosproject.net.DefaultPath)24 Link (org.onosproject.net.Link)23 DisjointPath (org.onosproject.net.DisjointPath)22 ConnectPoint (org.onosproject.net.ConnectPoint)18 Test (org.junit.Test)16 ImmutableSet (com.google.common.collect.ImmutableSet)12 ArrayList (java.util.ArrayList)11 List (java.util.List)11 Set (java.util.Set)11 Collectors (java.util.stream.Collectors)10 DefaultLink (org.onosproject.net.DefaultLink)10 Intent (org.onosproject.net.intent.Intent)10 Collections (java.util.Collections)9 Topology (org.onosproject.net.topology.Topology)8 Logger (org.slf4j.Logger)8 Stream (java.util.stream.Stream)7 ScalarWeight (org.onlab.graph.ScalarWeight)7 HostId (org.onosproject.net.HostId)7