Search in sources :

Example 31 with Route

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);
}
Also used : ResolvedRoute(org.onosproject.routeservice.ResolvedRoute) Route(org.onosproject.routeservice.Route) ResolvedRoute(org.onosproject.routeservice.ResolvedRoute) Test(org.junit.Test)

Example 32 with Route

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;
}
Also used : Route(org.onosproject.routeservice.Route) RouteService(org.onosproject.routeservice.RouteService) Collection(java.util.Collection) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Command(org.apache.karaf.shell.api.action.Command) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) Objects(java.util.Objects) AbstractShellCommand(org.onosproject.cli.AbstractShellCommand) Service(org.apache.karaf.shell.api.action.lifecycle.Service) RouteInfo(org.onosproject.routeservice.RouteInfo) Optional(java.util.Optional) JsonNode(com.fasterxml.jackson.databind.JsonNode) RouteTableId(org.onosproject.routeservice.RouteTableId) ResolvedRoute(org.onosproject.routeservice.ResolvedRoute) Comparator(java.util.Comparator) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 33 with Route

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();
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) RouteAdminService(org.onosproject.routeservice.RouteAdminService) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) IOException(java.io.IOException) Route(org.onosproject.routeservice.Route) ResolvedRoute(org.onosproject.routeservice.ResolvedRoute) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 34 with Route

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;
        });
    });
}
Also used : IpPrefix(org.onlab.packet.IpPrefix) NodeId(org.onosproject.cluster.NodeId) Route(org.onosproject.routeservice.Route)

Aggregations

Route (org.onosproject.routeservice.Route)34 IpAddress (org.onlab.packet.IpAddress)16 ResolvedRoute (org.onosproject.routeservice.ResolvedRoute)13 IpPrefix (org.onlab.packet.IpPrefix)12 Host (org.onosproject.net.Host)11 MacAddress (org.onlab.packet.MacAddress)9 DhcpRecord (org.onosproject.dhcprelay.store.DhcpRecord)9 VlanId (org.onlab.packet.VlanId)8 HostId (org.onosproject.net.HostId)8 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)6 Collection (java.util.Collection)6 Optional (java.util.Optional)6 Set (java.util.Set)6 DHCP6 (org.onlab.packet.DHCP6)6 HostLocation (org.onosproject.net.HostLocation)6 RouteAdminService (org.onosproject.routeservice.RouteAdminService)6 ImmutableSet (com.google.common.collect.ImmutableSet)5 ArrayList (java.util.ArrayList)4 Dhcp6ClientIdOption (org.onlab.packet.dhcp.Dhcp6ClientIdOption)4 DefaultHostDescription (org.onosproject.net.host.DefaultHostDescription)4