use of org.onosproject.routeservice.Route in project onos by opennetworkinglab.
the class RouteManagerTest method testRouteUpdate.
/**
* Tests updating routes in the route manager.
*/
@Test
public void testRouteUpdate() {
Route route = new Route(Route.Source.STATIC, V4_PREFIX1, V4_NEXT_HOP1);
Route updatedRoute = new Route(Route.Source.STATIC, V4_PREFIX1, V4_NEXT_HOP2);
ResolvedRoute resolvedRoute = new ResolvedRoute(route, MAC1);
ResolvedRoute updatedResolvedRoute = new ResolvedRoute(updatedRoute, MAC2);
verifyRouteUpdated(route, updatedRoute, resolvedRoute, updatedResolvedRoute);
// Different prefix pointing to the same next hop.
// In this case we expect to receive a ROUTE_UPDATED event.
route = new Route(Route.Source.STATIC, V4_PREFIX2, V4_NEXT_HOP1);
updatedRoute = new Route(Route.Source.STATIC, V4_PREFIX2, V4_NEXT_HOP2);
resolvedRoute = new ResolvedRoute(route, MAC1);
updatedResolvedRoute = new ResolvedRoute(updatedRoute, MAC2);
verifyRouteUpdated(route, updatedRoute, resolvedRoute, updatedResolvedRoute);
route = new Route(Route.Source.STATIC, V6_PREFIX1, V6_NEXT_HOP1);
updatedRoute = new Route(Route.Source.STATIC, V6_PREFIX1, V6_NEXT_HOP2);
resolvedRoute = new ResolvedRoute(route, MAC3);
updatedResolvedRoute = new ResolvedRoute(updatedRoute, MAC4);
verifyRouteUpdated(route, updatedRoute, resolvedRoute, updatedResolvedRoute);
}
use of org.onosproject.routeservice.Route in project onos by opennetworkinglab.
the class RoutesListCommand method json.
/**
* Produces a JSON array of routes.
*
* @param routes the routes with the data
* @return JSON array with the routes
*/
private JsonNode json(Collection<RouteInfo> routes) {
ObjectMapper mapper = new ObjectMapper();
ArrayNode result = mapper.createArrayNode();
routes.stream().flatMap(ri -> ri.allRoutes().stream()).forEach(r -> {
// use RouteCodec to encode the Route object inside ResolvedRoute
ObjectNode routeNode = jsonForEntity(r.route(), Route.class);
if (r.nextHopMac() != null) {
routeNode.put("nextHopMac", r.nextHopMac().toString());
}
if (r.nextHopVlan() != null) {
routeNode.put("nextHopVlan", r.nextHopVlan().toString());
}
result.add(routeNode);
});
return result;
}
use of org.onosproject.routeservice.Route in project onos by opennetworkinglab.
the class RouteServiceWebResource method createRoutes.
/**
* Creates new unicast routes.
* Creates a new route in the unicast RIB. Source field is kept optional.
* Without Source field routes are created as STATIC routes. Otherwise as per the mentioned Source
*
* @param routesStream unicast routes JSON array
* @return status of the request - CREATED if the JSON is correct,
* BAD_REQUEST if the JSON is invalid, NO_CONTENT otherwise
* @onos.rsModel RoutesTypePost
*/
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("/bulk")
public Response createRoutes(InputStream routesStream) {
RouteAdminService service = get(RouteAdminService.class);
try {
ObjectNode jsonTree = readTreeFromStream(mapper(), routesStream);
ArrayNode routesArray = nullIsIllegal((ArrayNode) jsonTree.get(ROUTES), ROUTES_KEY_ERROR);
List<Route> routes = codec(Route.class).decode(routesArray, this);
service.update(routes);
} catch (IOException ex) {
throw new IllegalArgumentException(ex);
}
return Response.noContent().build();
}
use of org.onosproject.routeservice.Route in project onos by opennetworkinglab.
the class FpmManager method updateAcceptRouteFlag.
@Override
public void updateAcceptRouteFlag(Collection<FpmPeerAcceptRoutes> modifiedPeers) {
modifiedPeers.forEach(modifiedPeer -> {
log.debug("FPM connection to {} is disabled", modifiedPeer);
NodeId localNode = clusterService.getLocalNode().id();
log.debug("Peer Flag {}", modifiedPeer.isAcceptRoutes());
peers.compute(modifiedPeer.peer(), (p, infos) -> {
if (infos == null) {
return null;
}
Iterator<FpmConnectionInfo> iterator = infos.iterator();
if (iterator.hasNext()) {
FpmConnectionInfo connectionInfo = iterator.next();
if (connectionInfo.isAcceptRoutes() == modifiedPeer.isAcceptRoutes()) {
return null;
}
localPeers.remove(modifiedPeer.peer());
infos.remove(connectionInfo);
infos.add(new FpmConnectionInfo(localNode, modifiedPeer.peer(), System.currentTimeMillis(), modifiedPeer.isAcceptRoutes()));
localPeers.put(modifiedPeer.peer(), infos);
}
Map<IpPrefix, Route> routes = fpmRoutes.get(modifiedPeer.peer());
if (routes != null && !modifiedPeer.isAcceptRoutes()) {
updateRouteStore(Lists.newArrayList(), routes.values());
} else {
updateRouteStore(routes.values(), Lists.newArrayList());
}
return infos;
});
});
}
Aggregations