Search in sources :

Example 1 with LinkWeigher

use of org.onosproject.net.topology.LinkWeigher in project onos by opennetworkinglab.

the class VirtualNetworkTopologyManagerTest method testGetDisjointPaths.

/**
 * Test getDisjointPaths() methods.
 */
@Test
public void testGetDisjointPaths() {
    VirtualNetwork virtualNetwork = setupVirtualNetworkTopology();
    TopologyService topologyService = manager.get(virtualNetwork.id(), TopologyService.class);
    Topology topology = topologyService.currentTopology();
    VirtualDevice srcVirtualDevice = getVirtualDevice(virtualNetwork.id(), DID1);
    VirtualDevice dstVirtualDevice = getVirtualDevice(virtualNetwork.id(), DID2);
    // test the getDisjointPaths() method.
    Set<DisjointPath> paths = topologyService.getDisjointPaths(topology, srcVirtualDevice.id(), dstVirtualDevice.id());
    assertNotNull("The paths should not be null.", paths);
    assertEquals("The paths size did not match.", 1, paths.size());
    // test the getDisjointPaths() method using a weight.
    LinkWeigher weight = new LinkWeigherAdapter(1.0);
    Set<DisjointPath> paths1 = topologyService.getDisjointPaths(topology, srcVirtualDevice.id(), dstVirtualDevice.id(), weight);
    assertNotNull("The paths should not be null.", paths1);
    assertEquals("The paths size did not match.", 1, paths1.size());
}
Also used : VirtualNetwork(org.onosproject.incubator.net.virtual.VirtualNetwork) LinkWeigherAdapter(org.onosproject.net.topology.LinkWeigherAdapter) LinkWeigher(org.onosproject.net.topology.LinkWeigher) VirtualDevice(org.onosproject.incubator.net.virtual.VirtualDevice) Topology(org.onosproject.net.topology.Topology) DisjointPath(org.onosproject.net.DisjointPath) TopologyService(org.onosproject.net.topology.TopologyService) Test(org.junit.Test)

Example 2 with LinkWeigher

use of org.onosproject.net.topology.LinkWeigher in project onos by opennetworkinglab.

the class OpticalConnectivityIntentCompiler method getOpticalPaths.

/**
 * Calculates optical paths in WDM topology.
 *
 * @param intent optical connectivity intent
 * @return set of paths in WDM topology
 */
private Stream<Path> getOpticalPaths(OpticalConnectivityIntent intent) {
    // Route in WDM topology
    Topology topology = topologyService.currentTopology();
    // TODO: refactor with LinkWeigher class Implementation
    LinkWeigher weight = new LinkWeigher() {

        @Override
        public Weight getInitialWeight() {
            return ScalarWeight.toWeight(0.0);
        }

        @Override
        public Weight getNonViableWeight() {
            return ScalarWeight.NON_VIABLE_WEIGHT;
        }

        /**
         * @param edge edge to be weighed
         * @return the metric retrieved from the annotations otherwise 1
         */
        @Override
        public Weight weight(TopologyEdge edge) {
            log.debug("Link {} metric {}", edge.link(), edge.link().annotations().value("metric"));
            // Disregard inactive or non-optical links
            if (edge.link().state() == Link.State.INACTIVE) {
                return ScalarWeight.toWeight(-1);
            }
            if (edge.link().type() != Link.Type.OPTICAL) {
                return ScalarWeight.toWeight(-1);
            }
            // Adhere to static port mappings
            DeviceId srcDeviceId = edge.link().src().deviceId();
            if (srcDeviceId.equals(intent.getSrc().deviceId())) {
                ConnectPoint srcStaticPort = staticPort(intent.getSrc());
                if (srcStaticPort != null) {
                    return ScalarWeight.toWeight(srcStaticPort.equals(edge.link().src()) ? 1 : -1);
                }
            }
            DeviceId dstDeviceId = edge.link().dst().deviceId();
            if (dstDeviceId.equals(intent.getDst().deviceId())) {
                ConnectPoint dstStaticPort = staticPort(intent.getDst());
                if (dstStaticPort != null) {
                    return ScalarWeight.toWeight(dstStaticPort.equals(edge.link().dst()) ? 1 : -1);
                }
            }
            Annotations annotations = edge.link().annotations();
            if (annotations != null && annotations.value("metric") != null && !annotations.value("metric").isEmpty()) {
                double metric = Double.parseDouble(annotations.value("metric"));
                return ScalarWeight.toWeight(metric);
            } else {
                return ScalarWeight.toWeight(1);
            }
        }
    };
    ConnectPoint start = intent.getSrc();
    ConnectPoint end = intent.getDst();
    // 0 hop case
    if (start.deviceId().equals(end.deviceId())) {
        log.debug("install optical intent for 0 hop i.e srcDeviceId=dstDeviceId");
        DefaultLink defaultLink = DefaultLink.builder().providerId(PROVIDER_ID).src(start).dst(end).state(Link.State.ACTIVE).type(Link.Type.DIRECT).isExpected(true).build();
        List<Link> links = ImmutableList.<Link>builder().add(defaultLink).build();
        Annotations annotations = DefaultAnnotations.builder().build();
        DefaultPath defaultPath = new DefaultPath(PROVIDER_ID, links, null, annotations);
        return ImmutableList.<Path>builder().add(defaultPath).build().stream();
    }
    // head link's src port should be same as intent src port and tail link dst port
    // should be same as intent dst port in the path.
    Stream<Path> paths = topologyService.getKShortestPaths(topology, start.deviceId(), end.deviceId(), weight).filter(p -> p.links().get(0).src().port().equals(start.port()) && p.links().get(p.links().size() - 1).dst().port().equals(end.port()));
    if (log.isDebugEnabled()) {
        return paths.map(path -> {
            // no-op map stage to add debug logging
            log.debug("Candidate path: {}", path.links().stream().map(lk -> lk.src() + "-" + lk.dst()).collect(Collectors.toList()));
            return path;
        });
    }
    return paths;
}
Also used : Path(org.onosproject.net.Path) DefaultPath(org.onosproject.net.DefaultPath) DefaultLink(org.onosproject.net.DefaultLink) DeviceId(org.onosproject.net.DeviceId) Topology(org.onosproject.net.topology.Topology) TopologyEdge(org.onosproject.net.topology.TopologyEdge) ConnectPoint(org.onosproject.net.ConnectPoint) Annotations(org.onosproject.net.Annotations) DefaultAnnotations(org.onosproject.net.DefaultAnnotations) LinkWeigher(org.onosproject.net.topology.LinkWeigher) DefaultPath(org.onosproject.net.DefaultPath) Link(org.onosproject.net.Link) DefaultLink(org.onosproject.net.DefaultLink)

Example 3 with LinkWeigher

use of org.onosproject.net.topology.LinkWeigher in project onos by opennetworkinglab.

the class OpticalOduIntentCompiler method getOpticalPaths.

/**
 * Calculates optical paths in OTU topology.
 *
 * @param intent optical ODU intent
 * @return set of paths in OTU topology
 */
private Set<Path> getOpticalPaths(OpticalOduIntent intent) {
    // Route in OTU topology
    Topology topology = topologyService.currentTopology();
    class Weigher implements LinkWeigher {

        @Override
        public Weight weight(TopologyEdge edge) {
            if (edge.link().state() == Link.State.INACTIVE) {
                return ScalarWeight.toWeight(-1);
            }
            if (edge.link().type() != Link.Type.OPTICAL) {
                return ScalarWeight.toWeight(-1);
            }
            // Find path with available TributarySlots resources
            if (!isAvailableTributarySlots(intent, edge.link())) {
                return ScalarWeight.toWeight(-1);
            }
            return ScalarWeight.toWeight(1);
        }

        @Override
        public Weight getInitialWeight() {
            return null;
        }

        @Override
        public Weight getNonViableWeight() {
            return null;
        }
    }
    LinkWeigher weigher = new Weigher();
    ConnectPoint start = intent.getSrc();
    ConnectPoint end = intent.getDst();
    return topologyService.getPaths(topology, start.deviceId(), end.deviceId(), weigher);
}
Also used : LinkWeigher(org.onosproject.net.topology.LinkWeigher) LinkWeigher(org.onosproject.net.topology.LinkWeigher) Topology(org.onosproject.net.topology.Topology) TopologyEdge(org.onosproject.net.topology.TopologyEdge) ConnectPoint(org.onosproject.net.ConnectPoint)

Example 4 with LinkWeigher

use of org.onosproject.net.topology.LinkWeigher in project onos by opennetworkinglab.

the class VirtualNetworkPathManagerTest method testGetPathsOnNonEmptyVnet.

/**
 * Tests getPaths(), getDisjointPaths()
 * on a non-empty virtual network.
 */
@Test
public void testGetPathsOnNonEmptyVnet() {
    VirtualNetwork vnet = setupVnet();
    PathService pathService = manager.get(vnet.id(), PathService.class);
    // src and dest are in vnet and are connected by a virtual link
    Set<Path> paths = pathService.getPaths(DID1, DID3);
    validatePaths(paths, 1, 1, DID1, DID3, 1.0);
    LinkWeigher linkWeight = new LinkWeigherAdapter(2.0);
    paths = pathService.getPaths(DID1, DID3, linkWeight);
    validatePaths(paths, 1, 1, DID1, DID3, 2.0);
    Set<DisjointPath> disjointPaths = pathService.getDisjointPaths(DID1, DID3);
    validatePaths(disjointPaths, 1, 1, DID1, DID3, 1.0);
    disjointPaths = pathService.getDisjointPaths(DID1, DID3, linkWeight);
    validatePaths(disjointPaths, 1, 1, DID1, DID3, 2.0);
    // src and dest are in vnet but are not connected
    paths = pathService.getPaths(DID4, DID3);
    assertEquals("incorrect path count", 0, paths.size());
    disjointPaths = pathService.getDisjointPaths(DID4, DID3);
    assertEquals("incorrect path count", 0, disjointPaths.size());
    // src is in vnet, but dest is not in vnet.
    DeviceId nonExistentDeviceId = DeviceId.deviceId("nonExistentDevice");
    paths = pathService.getPaths(DID2, nonExistentDeviceId);
    assertEquals("incorrect path count", 0, paths.size());
    disjointPaths = pathService.getDisjointPaths(DID2, nonExistentDeviceId);
    assertEquals("incorrect path count", 0, disjointPaths.size());
}
Also used : VirtualNetwork(org.onosproject.incubator.net.virtual.VirtualNetwork) Path(org.onosproject.net.Path) DisjointPath(org.onosproject.net.DisjointPath) LinkWeigherAdapter(org.onosproject.net.topology.LinkWeigherAdapter) PathService(org.onosproject.net.topology.PathService) LinkWeigher(org.onosproject.net.topology.LinkWeigher) DeviceId(org.onosproject.net.DeviceId) DisjointPath(org.onosproject.net.DisjointPath) Test(org.junit.Test)

Example 5 with LinkWeigher

use of org.onosproject.net.topology.LinkWeigher in project onos by opennetworkinglab.

the class VirtualNetworkTopologyManagerTest method testGetPaths.

/**
 * Test getPaths() and getPaths() by weight methods.
 */
@Test
public void testGetPaths() {
    VirtualNetwork virtualNetwork = setupVirtualNetworkTopology();
    TopologyService topologyService = manager.get(virtualNetwork.id(), TopologyService.class);
    Topology topology = topologyService.currentTopology();
    VirtualDevice srcVirtualDevice = getVirtualDevice(virtualNetwork.id(), DID1);
    VirtualDevice dstVirtualDevice = getVirtualDevice(virtualNetwork.id(), DID2);
    // test the getPaths() method.
    Set<Path> paths = topologyService.getPaths(topology, srcVirtualDevice.id(), dstVirtualDevice.id());
    assertNotNull("The paths should not be null.", paths);
    assertEquals("The paths size did not match.", 1, paths.size());
    // test the getPaths() by weight method.
    LinkWeigher weight = new LinkWeigherAdapter(1.0);
    Set<Path> paths1 = topologyService.getPaths(topology, srcVirtualDevice.id(), dstVirtualDevice.id(), weight);
    assertNotNull("The paths should not be null.", paths1);
    assertEquals("The paths size did not match.", 1, paths1.size());
    Path path = paths1.iterator().next();
    assertEquals("wrong path length", 1, path.links().size());
    assertEquals("wrong path cost", ScalarWeight.toWeight(1.0), path.weight());
}
Also used : VirtualNetwork(org.onosproject.incubator.net.virtual.VirtualNetwork) Path(org.onosproject.net.Path) DisjointPath(org.onosproject.net.DisjointPath) LinkWeigherAdapter(org.onosproject.net.topology.LinkWeigherAdapter) LinkWeigher(org.onosproject.net.topology.LinkWeigher) VirtualDevice(org.onosproject.incubator.net.virtual.VirtualDevice) Topology(org.onosproject.net.topology.Topology) TopologyService(org.onosproject.net.topology.TopologyService) Test(org.junit.Test)

Aggregations

LinkWeigher (org.onosproject.net.topology.LinkWeigher)7 Topology (org.onosproject.net.topology.Topology)5 Test (org.junit.Test)4 Path (org.onosproject.net.Path)4 LinkWeigherAdapter (org.onosproject.net.topology.LinkWeigherAdapter)4 VirtualNetwork (org.onosproject.incubator.net.virtual.VirtualNetwork)3 DisjointPath (org.onosproject.net.DisjointPath)3 VirtualDevice (org.onosproject.incubator.net.virtual.VirtualDevice)2 ConnectPoint (org.onosproject.net.ConnectPoint)2 DeviceId (org.onosproject.net.DeviceId)2 TopologyEdge (org.onosproject.net.topology.TopologyEdge)2 TopologyService (org.onosproject.net.topology.TopologyService)2 Annotations (org.onosproject.net.Annotations)1 DefaultAnnotations (org.onosproject.net.DefaultAnnotations)1 DefaultLink (org.onosproject.net.DefaultLink)1 DefaultPath (org.onosproject.net.DefaultPath)1 Link (org.onosproject.net.Link)1 GeoDistanceLinkWeight (org.onosproject.net.topology.GeoDistanceLinkWeight)1 MetricLinkWeight (org.onosproject.net.topology.MetricLinkWeight)1 PathService (org.onosproject.net.topology.PathService)1