Search in sources :

Example 1 with ResolvedRoute

use of org.onosproject.routeservice.ResolvedRoute in project onos by opennetworkinglab.

the class RouteServiceWebResource method getRoutesCountByType.

/**
 * Get count of all types routes .
 * Returns count of all known route types.
 *
 * @return 200 OK with count of all route types
 * @onos.rsModel RoutesGetTypeCount
 */
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/routes/types/count")
public Response getRoutesCountByType() {
    RouteService service = get(RouteService.class);
    ObjectNode root = mapper().createObjectNode();
    service.getRouteTables().forEach(table -> {
        List<Route> staticRoutes = new ArrayList<>();
        List<Route> fpmRoutes = new ArrayList<>();
        List<Route> ripRoutes = new ArrayList<>();
        List<Route> dhcpRoutes = new ArrayList<>();
        List<Route> dhcpLQRoutes = new ArrayList<>();
        List<Route> bgpRoutes = new ArrayList<>();
        List<Route> routes = service.getRoutes(table).stream().flatMap(ri -> ri.allRoutes().stream()).map(ResolvedRoute::route).collect(Collectors.toList());
        routes.forEach(route -> {
            if (route.source() == Route.Source.STATIC) {
                staticRoutes.add(route);
            }
            if (route.source() == Route.Source.FPM) {
                fpmRoutes.add(route);
            }
            if (route.source() == Route.Source.RIP) {
                ripRoutes.add(route);
            }
            if (route.source() == Route.Source.DHCP) {
                dhcpRoutes.add(route);
            }
            if (route.source() == Route.Source.DHCPLQ) {
                dhcpLQRoutes.add(route);
            }
            if (route.source() == Route.Source.BGP) {
                bgpRoutes.add(route);
            }
        });
        root.put(table.name() + "StaticRouteCount", staticRoutes.size());
        root.put(table.name() + "FpmRouteCount", fpmRoutes.size());
        root.put(table.name() + "RipRouteCount", ripRoutes.size());
        root.put(table.name() + "DhcpRouteCount", dhcpRoutes.size());
        root.put(table.name() + "DhcpLQRouteCount", dhcpLQRoutes.size());
        root.put(table.name() + "BgpRouteCount", bgpRoutes.size());
        root.put(table.name() + "TotalRouteCount", routes.stream().count());
    });
    return ok(root).build();
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayList(java.util.ArrayList) RouteService(org.onosproject.routeservice.RouteService) Route(org.onosproject.routeservice.Route) ResolvedRoute(org.onosproject.routeservice.ResolvedRoute) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 2 with ResolvedRoute

use of org.onosproject.routeservice.ResolvedRoute in project onos by opennetworkinglab.

the class RouteServiceWebResource method getRoutes.

/**
 * Get all unicast routes.
 * Returns array of all known unicast routes.
 *
 * @return 200 OK with array of all known unicast routes
 * @onos.rsModel RoutesGet
 */
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response getRoutes() {
    RouteService service = get(RouteService.class);
    ObjectNode root = mapper().createObjectNode();
    service.getRouteTables().forEach(table -> {
        List<Route> routes = service.getRoutes(table).stream().flatMap(ri -> ri.allRoutes().stream()).map(ResolvedRoute::route).collect(Collectors.toList());
        root.put(table.name(), codec(Route.class).encode(routes, this));
    });
    return ok(root).build();
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) RouteService(org.onosproject.routeservice.RouteService) Route(org.onosproject.routeservice.Route) ResolvedRoute(org.onosproject.routeservice.ResolvedRoute) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 3 with ResolvedRoute

use of org.onosproject.routeservice.ResolvedRoute in project onos by opennetworkinglab.

the class RouteManagerTest method testRouteDelete.

/**
 * Tests deleting routes from the route manager.
 */
@Test
public void testRouteDelete() {
    Route route = new Route(Route.Source.STATIC, V4_PREFIX1, V4_NEXT_HOP1);
    ResolvedRoute removedResolvedRoute = new ResolvedRoute(route, MAC1);
    verifyDelete(route, removedResolvedRoute);
    route = new Route(Route.Source.STATIC, V6_PREFIX1, V6_NEXT_HOP1);
    removedResolvedRoute = new ResolvedRoute(route, MAC3);
    verifyDelete(route, removedResolvedRoute);
}
Also used : ResolvedRoute(org.onosproject.routeservice.ResolvedRoute) Route(org.onosproject.routeservice.Route) ResolvedRoute(org.onosproject.routeservice.ResolvedRoute) Test(org.junit.Test)

Example 4 with ResolvedRoute

use of org.onosproject.routeservice.ResolvedRoute in project onos by opennetworkinglab.

the class RouteManagerTest method testAsyncRouteAdd.

/**
 * Tests adding a route entry where the HostService does not immediately
 * know the MAC address of the next hop, but this is learnt later.
 */
@Test
public void testAsyncRouteAdd() {
    Route route = new Route(Route.Source.STATIC, V4_PREFIX1, V4_NEXT_HOP1);
    // 2nd route for the same nexthop
    Route route2 = new Route(Route.Source.STATIC, V4_PREFIX2, V4_NEXT_HOP2);
    // 3rd route with no valid nexthop
    Route route3 = new Route(Route.Source.STATIC, V6_PREFIX1, V6_NEXT_HOP1);
    // Host service will reply with no hosts when asked
    reset(hostService);
    expect(hostService.getHostsByIp(anyObject(IpAddress.class))).andReturn(Collections.emptySet()).anyTimes();
    hostService.startMonitoringIp(V4_NEXT_HOP1);
    hostService.startMonitoringIp(V4_NEXT_HOP2);
    hostService.startMonitoringIp(V6_NEXT_HOP1);
    expectLastCall().anyTimes();
    replay(hostService);
    // Initially when we add the route, no route event will be sent because
    // the host is not known
    replay(routeListener);
    routeManager.update(Lists.newArrayList(route, route2, route3));
    verify(routeListener);
    // Now when we send the event, we expect the FIB update to be sent
    reset(routeListener);
    ResolvedRoute resolvedRoute = new ResolvedRoute(route, MAC1);
    routeListener.event(event(RouteEvent.Type.ROUTE_ADDED, resolvedRoute, null, Sets.newHashSet(resolvedRoute), null));
    ResolvedRoute resolvedRoute2 = new ResolvedRoute(route2, MAC1);
    routeListener.event(event(RouteEvent.Type.ROUTE_ADDED, resolvedRoute2, null, Sets.newHashSet(resolvedRoute2), null));
    replay(routeListener);
    Host host = createHost(MAC1, Lists.newArrayList(V4_NEXT_HOP1, V4_NEXT_HOP2));
    // Set up the host service with a host
    reset(hostService);
    expect(hostService.getHostsByIp(V4_NEXT_HOP1)).andReturn(Collections.singleton(host)).anyTimes();
    hostService.startMonitoringIp(V4_NEXT_HOP1);
    expect(hostService.getHostsByIp(V4_NEXT_HOP2)).andReturn(Collections.singleton(host)).anyTimes();
    hostService.startMonitoringIp(V4_NEXT_HOP2);
    expectLastCall().anyTimes();
    replay(hostService);
    // Send in the host event
    hostListener.event(new HostEvent(HostEvent.Type.HOST_ADDED, host));
    verify(routeListener);
}
Also used : HostEvent(org.onosproject.net.host.HostEvent) Host(org.onosproject.net.Host) DefaultHost(org.onosproject.net.DefaultHost) ResolvedRoute(org.onosproject.routeservice.ResolvedRoute) Route(org.onosproject.routeservice.Route) ResolvedRoute(org.onosproject.routeservice.ResolvedRoute) Test(org.junit.Test)

Example 5 with ResolvedRoute

use of org.onosproject.routeservice.ResolvedRoute in project onos by opennetworkinglab.

the class FibInstallerTest method testRouteUpdate.

/**
 * Tests updating a route.
 *
 * We verify that the flowObjectiveService records the correct state and that the
 * correct flow is submitted to the flowObjectiveService.
 */
@Test
public void testRouteUpdate() {
    // Firstly add a route
    testRouteAdd();
    reset(flowObjectiveService);
    ResolvedRoute oldRoute = createRoute(PREFIX1, NEXT_HOP1, MAC1);
    ResolvedRoute route = createRoute(PREFIX1, NEXT_HOP2, MAC2);
    // Create the next objective
    NextObjective nextObjective = createNextObjective(MAC2, MAC2, SW1_ETH2.port(), VLAN1, true);
    flowObjectiveService.next(DEVICE_ID, nextObjective);
    // Create the flow objective
    ForwardingObjective fwd = createForwardingObjective(PREFIX1, true);
    flowObjectiveService.forward(DEVICE_ID, fwd);
    EasyMock.expectLastCall().once();
    setUpFlowObjectiveService();
    // Send in the update event
    routeListener.event(new RouteEvent(RouteEvent.Type.ROUTE_UPDATED, route, oldRoute));
    verify(flowObjectiveService);
}
Also used : DefaultNextObjective(org.onosproject.net.flowobjective.DefaultNextObjective) NextObjective(org.onosproject.net.flowobjective.NextObjective) RouteEvent(org.onosproject.routeservice.RouteEvent) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) DefaultForwardingObjective(org.onosproject.net.flowobjective.DefaultForwardingObjective) ResolvedRoute(org.onosproject.routeservice.ResolvedRoute) Test(org.junit.Test)

Aggregations

ResolvedRoute (org.onosproject.routeservice.ResolvedRoute)16 Test (org.junit.Test)13 RouteEvent (org.onosproject.routeservice.RouteEvent)9 Route (org.onosproject.routeservice.Route)7 AbstractIntentTest (org.onosproject.net.intent.AbstractIntentTest)5 MultiPointToSinglePointIntent (org.onosproject.net.intent.MultiPointToSinglePointIntent)5 DefaultForwardingObjective (org.onosproject.net.flowobjective.DefaultForwardingObjective)4 ForwardingObjective (org.onosproject.net.flowobjective.ForwardingObjective)4 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3 DefaultNextObjective (org.onosproject.net.flowobjective.DefaultNextObjective)3 NextObjective (org.onosproject.net.flowobjective.NextObjective)3 RouteService (org.onosproject.routeservice.RouteService)3 GET (javax.ws.rs.GET)2 Produces (javax.ws.rs.Produces)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Comparator (java.util.Comparator)1