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();
}
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();
}
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);
}
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);
}
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);
}
Aggregations