Search in sources :

Example 16 with LinkService

use of org.onosproject.net.link.LinkService in project onos by opennetworkinglab.

the class VirtualNetworkLinkManagerTest method testGetDeviceIngressLinksByNullId.

/**
 * Tests querying for device ingress links using a null device identifier.
 */
@Test(expected = NullPointerException.class)
public void testGetDeviceIngressLinksByNullId() {
    manager.registerTenantId(TenantId.tenantId(tenantIdValue1));
    VirtualNetwork virtualNetwork = manager.createVirtualNetwork(TenantId.tenantId(tenantIdValue1));
    LinkService linkService = manager.get(virtualNetwork.id(), LinkService.class);
    // test the getDeviceIngressLinks() method with a null device identifier.
    linkService.getDeviceIngressLinks(null);
}
Also used : VirtualNetwork(org.onosproject.incubator.net.virtual.VirtualNetwork) LinkService(org.onosproject.net.link.LinkService) Test(org.junit.Test)

Example 17 with LinkService

use of org.onosproject.net.link.LinkService in project onos by opennetworkinglab.

the class VirtualNetworkLinkManagerTest method testGetEgressLinksByNullId.

/**
 * Tests querying for egress links using a null connect point.
 */
@Test(expected = NullPointerException.class)
public void testGetEgressLinksByNullId() {
    manager.registerTenantId(TenantId.tenantId(tenantIdValue1));
    VirtualNetwork virtualNetwork = manager.createVirtualNetwork(TenantId.tenantId(tenantIdValue1));
    LinkService linkService = manager.get(virtualNetwork.id(), LinkService.class);
    // test the getEgressLinks() method with a null connect point.
    linkService.getEgressLinks(null);
}
Also used : VirtualNetwork(org.onosproject.incubator.net.virtual.VirtualNetwork) LinkService(org.onosproject.net.link.LinkService) Test(org.junit.Test)

Example 18 with LinkService

use of org.onosproject.net.link.LinkService in project onos by opennetworkinglab.

the class VirtualNetworkLinkManagerTest method testGetLinks.

/**
 * Tests the getLinks(), getActiveLinks(), getLinkCount(), getLink(),
 * getLinks(ConnectPoint), getDeviceLinks(), getDeviceEgressLinks(), getDeviceIngressLinks(),
 * getEgressLinks(), getIngressLinks() methods.
 */
@Test
public void testGetLinks() {
    manager.registerTenantId(TenantId.tenantId(tenantIdValue1));
    VirtualNetwork virtualNetwork = manager.createVirtualNetwork(TenantId.tenantId(tenantIdValue1));
    VirtualDevice srcVirtualDevice = manager.createVirtualDevice(virtualNetwork.id(), DID1);
    VirtualDevice dstVirtualDevice = manager.createVirtualDevice(virtualNetwork.id(), DID2);
    ConnectPoint src = new ConnectPoint(srcVirtualDevice.id(), PortNumber.portNumber(1));
    manager.createVirtualPort(virtualNetwork.id(), src.deviceId(), src.port(), new ConnectPoint(srcVirtualDevice.id(), src.port()));
    ConnectPoint dst = new ConnectPoint(dstVirtualDevice.id(), PortNumber.portNumber(2));
    manager.createVirtualPort(virtualNetwork.id(), dst.deviceId(), dst.port(), new ConnectPoint(dstVirtualDevice.id(), dst.port()));
    VirtualLink link1 = manager.createVirtualLink(virtualNetwork.id(), src, dst);
    VirtualLink link2 = manager.createVirtualLink(virtualNetwork.id(), dst, src);
    LinkService linkService = manager.get(virtualNetwork.id(), LinkService.class);
    // test the getLinks() method
    Iterator<Link> it = linkService.getLinks().iterator();
    assertEquals("The link set size did not match.", 2, Iterators.size(it));
    // test the getActiveLinks() method where all links are INACTIVE
    Iterator<Link> it2 = linkService.getActiveLinks().iterator();
    assertEquals("The link set size did not match.", 0, Iterators.size(it2));
    // test the getActiveLinks() method where one link is ACTIVE
    virtualNetworkManagerStore.updateLink(link1, link1.tunnelId(), Link.State.ACTIVE);
    Iterator<Link> it3 = linkService.getActiveLinks().iterator();
    assertEquals("The link set size did not match.", 1, Iterators.size(it3));
    // test the getLinkCount() method
    assertEquals("The link set size did not match.", 2, linkService.getLinkCount());
    // test the getLink() method
    assertEquals("The expect link did not match.", link1, linkService.getLink(src, dst));
    assertEquals("The expect link did not match.", link2, linkService.getLink(dst, src));
    assertNotEquals("The expect link should not have matched.", link1, linkService.getLink(dst, src));
    // test the getLinks(ConnectPoint) method
    assertEquals("The link set size did not match.", 2, linkService.getLinks(src).size());
    assertEquals("The link set size did not match.", 2, linkService.getLinks(dst).size());
    ConnectPoint connectPoint = new ConnectPoint(dstVirtualDevice.id(), PortNumber.portNumber(3));
    assertEquals("The link set size did not match.", 0, linkService.getLinks(connectPoint).size());
    // test the getDeviceLinks() method
    assertEquals("The link set size did not match.", 2, linkService.getDeviceLinks(DID1).size());
    assertEquals("The link set size did not match.", 2, linkService.getDeviceLinks(DID2).size());
    assertEquals("The link set size did not match.", 0, linkService.getDeviceLinks(DID3).size());
    // test the getDeviceEgressLinks() method
    assertEquals("The link set size did not match.", 1, linkService.getDeviceEgressLinks(DID1).size());
    assertEquals("The link set size did not match.", 1, linkService.getDeviceEgressLinks(DID2).size());
    assertEquals("The link set size did not match.", 0, linkService.getDeviceEgressLinks(DID3).size());
    // test the getDeviceIngressLinks() method
    assertEquals("The link set size did not match.", 1, linkService.getDeviceIngressLinks(DID1).size());
    assertEquals("The link set size did not match.", 1, linkService.getDeviceIngressLinks(DID2).size());
    assertEquals("The link set size did not match.", 0, linkService.getDeviceIngressLinks(DID3).size());
    // test the getEgressLinks() method
    assertEquals("The link set size did not match.", 1, linkService.getEgressLinks(src).size());
    assertEquals("The link set size did not match.", 1, linkService.getEgressLinks(dst).size());
    assertEquals("The link set size did not match.", 0, linkService.getEgressLinks(connectPoint).size());
    // test the getIngressLinks() method
    assertEquals("The link set size did not match.", 1, linkService.getIngressLinks(src).size());
    assertEquals("The link set size did not match.", 1, linkService.getIngressLinks(dst).size());
    assertEquals("The link set size did not match.", 0, linkService.getIngressLinks(connectPoint).size());
}
Also used : VirtualNetwork(org.onosproject.incubator.net.virtual.VirtualNetwork) VirtualDevice(org.onosproject.incubator.net.virtual.VirtualDevice) ConnectPoint(org.onosproject.net.ConnectPoint) LinkService(org.onosproject.net.link.LinkService) Link(org.onosproject.net.Link) VirtualLink(org.onosproject.incubator.net.virtual.VirtualLink) VirtualLink(org.onosproject.incubator.net.virtual.VirtualLink) Test(org.junit.Test)

Example 19 with LinkService

use of org.onosproject.net.link.LinkService in project onos by opennetworkinglab.

the class LinksWebResource method getLinks.

/**
 * Gets infrastructure links.
 * Returns array of all links, or links for the specified device or port.
 * @onos.rsModel LinksGet
 * @param deviceId  (optional) device identifier
 * @param port      (optional) port number
 * @param direction (optional) direction qualifier
 * @return 200 OK with array of all links, or links for the specified device or port
 */
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response getLinks(@QueryParam("device") String deviceId, @QueryParam("port") String port, @QueryParam("direction") String direction) {
    LinkService service = get(LinkService.class);
    Iterable<Link> links;
    if (deviceId != null && port != null) {
        links = getConnectPointLinks(new ConnectPoint(deviceId(deviceId), portNumber(port)), direction, service);
    } else if (deviceId != null) {
        links = getDeviceLinks(deviceId(deviceId), direction, service);
    } else {
        links = service.getLinks();
    }
    return ok(encodeArray(Link.class, "links", links)).build();
}
Also used : LinkService(org.onosproject.net.link.LinkService) ConnectPoint(org.onosproject.net.ConnectPoint) Link(org.onosproject.net.Link) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 20 with LinkService

use of org.onosproject.net.link.LinkService in project onos by opennetworkinglab.

the class LinkDstCompleter method complete.

@Override
public int complete(Session session, CommandLine commandLine, List<String> candidates) {
    // Delegate string completer
    StringsCompleter delegate = new StringsCompleter();
    // Fetch our service and feed it's offerings to the string completer
    LinkService service = AbstractShellCommand.get(LinkService.class);
    // Link source the previous argument.
    String srcArg = commandLine.getArguments()[commandLine.getCursorArgumentIndex() - 1];
    // Generate the device ID/port number identifiers
    SortedSet<String> strings = delegate.getStrings();
    try {
        ConnectPoint src = ConnectPoint.deviceConnectPoint(srcArg);
        service.getEgressLinks(src).forEach(link -> strings.add(link.dst().elementId().toString() + "/" + link.dst().port()));
    } catch (NumberFormatException e) {
        System.err.println("Invalid connect-point");
    }
    // Now let the completer do the work for figuring out what to offer.
    return delegate.complete(session, commandLine, candidates);
}
Also used : StringsCompleter(org.apache.karaf.shell.support.completers.StringsCompleter) LinkService(org.onosproject.net.link.LinkService) ConnectPoint(org.onosproject.net.ConnectPoint)

Aggregations

LinkService (org.onosproject.net.link.LinkService)22 ConnectPoint (org.onosproject.net.ConnectPoint)12 Test (org.junit.Test)9 VirtualNetwork (org.onosproject.incubator.net.virtual.VirtualNetwork)9 Link (org.onosproject.net.Link)9 DeviceService (org.onosproject.net.device.DeviceService)5 Collectors (java.util.stream.Collectors)4 Collections (java.util.Collections)3 List (java.util.List)3 Set (java.util.Set)3 VirtualDevice (org.onosproject.incubator.net.virtual.VirtualDevice)3 DeviceId (org.onosproject.net.DeviceId)3 ImmutableList (com.google.common.collect.ImmutableList)2 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2 Optional (java.util.Optional)2 StringsCompleter (org.apache.karaf.shell.support.completers.StringsCompleter)2 ConnectPoint.deviceConnectPoint (org.onosproject.net.ConnectPoint.deviceConnectPoint)2