Search in sources :

Example 16 with ResolvedRoute

use of org.onosproject.routeservice.ResolvedRoute 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 17 with ResolvedRoute

use of org.onosproject.routeservice.ResolvedRoute in project trellis-control by opennetworkinglab.

the class HostHandlerTest method testHostRemovedWithRouteRemoved.

@Test
public void testHostRemovedWithRouteRemoved() {
    Host subject = new DefaultHost(PROVIDER_ID, HOST_ID_UNTAGGED, HOST_MAC, HOST_VLAN_UNTAGGED, Sets.newHashSet(HOST_LOC11), Sets.newHashSet(HOST_IP11), false);
    // Add a host
    // Expect: add one routing rule and one bridging rule
    hostHandler.processHostAddedEvent(new HostEvent(HostEvent.Type.HOST_ADDED, subject));
    assertEquals(1, ROUTING_TABLE.size());
    assertNotNull(ROUTING_TABLE.get(new MockRoutingTableKey(DEV1, HOST_IP11.toIpPrefix())));
    assertEquals(1, BRIDGING_TABLE.size());
    assertNotNull(BRIDGING_TABLE.get(new MockBridgingTableKey(DEV1, HOST_MAC, INTF_VLAN_UNTAGGED)));
    IpPrefix prefix = IpPrefix.valueOf("55.55.55.0/24");
    // Setting up mock route service
    RouteService routeService = hostHandler.srManager.routeService;
    reset(routeService);
    IpAddress nextHopIp2 = IpAddress.valueOf("20.0.0.1");
    MacAddress nextHopMac2 = MacAddress.valueOf("00:22:33:44:55:66");
    VlanId nextHopVlan2 = VlanId.NONE;
    Route r1 = new Route(Route.Source.STATIC, prefix, HOST_IP11);
    ResolvedRoute rr1 = new ResolvedRoute(r1, HOST_MAC, VlanId.NONE);
    Route r2 = new Route(Route.Source.STATIC, prefix, nextHopIp2);
    ResolvedRoute rr2 = new ResolvedRoute(r2, nextHopMac2, nextHopVlan2);
    RouteInfo routeInfo = new RouteInfo(prefix, rr1, Sets.newHashSet(rr1, rr2));
    RouteTableId routeTableId = new RouteTableId("ipv4");
    expect(routeService.getRouteTables()).andReturn(Sets.newHashSet(routeTableId));
    expect(routeService.getRoutes(routeTableId)).andReturn(Sets.newHashSet(routeInfo));
    replay(routeService);
    // Setting up mock device configuration
    hostHandler.srManager.deviceConfiguration = EasyMock.createNiceMock(DeviceConfiguration.class);
    DeviceConfiguration deviceConfiguration = hostHandler.srManager.deviceConfiguration;
    expect(deviceConfiguration.inSameSubnet(CP11, HOST_IP11)).andReturn(true);
    deviceConfiguration.removeSubnet(CP11, prefix);
    expectLastCall();
    replay(deviceConfiguration);
    // Remove the host
    // Expect: add the routing rule and the bridging rule
    hostHandler.processHostRemovedEvent(new HostEvent(HostEvent.Type.HOST_REMOVED, subject));
    assertEquals(0, ROUTING_TABLE.size());
    assertEquals(0, BRIDGING_TABLE.size());
    // Expect: subnet is removed from device config
    verify(deviceConfiguration);
}
Also used : RouteTableId(org.onosproject.routeservice.RouteTableId) Host(org.onosproject.net.Host) DefaultHost(org.onosproject.net.DefaultHost) MacAddress(org.onlab.packet.MacAddress) ResolvedRoute(org.onosproject.routeservice.ResolvedRoute) IpPrefix(org.onlab.packet.IpPrefix) DefaultHost(org.onosproject.net.DefaultHost) HostEvent(org.onosproject.net.host.HostEvent) RouteService(org.onosproject.routeservice.RouteService) InterfaceIpAddress(org.onosproject.net.host.InterfaceIpAddress) IpAddress(org.onlab.packet.IpAddress) RouteInfo(org.onosproject.routeservice.RouteInfo) VlanId(org.onlab.packet.VlanId) Route(org.onosproject.routeservice.Route) ResolvedRoute(org.onosproject.routeservice.ResolvedRoute) Test(org.junit.Test)

Example 18 with ResolvedRoute

use of org.onosproject.routeservice.ResolvedRoute in project trellis-control by opennetworkinglab.

the class RouteHandler method processRouteUpdatedInternal.

private void processRouteUpdatedInternal(Set<ResolvedRoute> routes, Set<ResolvedRoute> oldRoutes) {
    if (!isReady()) {
        log.info("System is not ready. Skip updating route for {} -> {}", oldRoutes, routes);
        return;
    }
    log.info("processRouteUpdatedInternal. routes={}, oldRoutes={}", routes, oldRoutes);
    if (routes.size() > 2) {
        log.info("Route {} has more than two next hops. Do not process route change", routes);
        return;
    }
    Set<ConnectPoint> allLocations = Sets.newHashSet();
    Set<IpPrefix> allPrefixes = Sets.newHashSet();
    routes.forEach(route -> {
        allLocations.addAll(srManager.nextHopLocations(route));
        allPrefixes.add(route.prefix());
    });
    // Revoke subnet from all locations and reset oldRoutes such that system will be reprogrammed from scratch
    if (oldRoutes.size() > 2) {
        log.info("Revoke subnet {} and reset oldRoutes");
        // FIXME remove routes more precisely by memorizing the old locations
        srManager.defaultRoutingHandler.revokeSubnet(allPrefixes, null);
        oldRoutes = Sets.newHashSet();
    }
    log.debug("RouteUpdated. populateSubnet {}, {}", allLocations, allPrefixes);
    srManager.defaultRoutingHandler.populateSubnet(allLocations, allPrefixes);
    Set<ResolvedRoute> toBeRemoved = Sets.difference(oldRoutes, routes).immutableCopy();
    Set<ResolvedRoute> toBeAdded = Sets.difference(routes, oldRoutes).immutableCopy();
    toBeRemoved.forEach(route -> {
        srManager.nextHopLocations(route).forEach(oldLocation -> {
            if (toBeAdded.stream().map(srManager::nextHopLocations).flatMap(Set::stream).map(ConnectPoint::deviceId).noneMatch(deviceId -> deviceId.equals(oldLocation.deviceId()))) {
                IpPrefix prefix = route.prefix();
                log.debug("RouteUpdated. removeSubnet {}, {}", oldLocation, prefix);
                srManager.deviceConfiguration.removeSubnet(oldLocation, prefix);
            // We don't remove the flow on the old location in occasion of two next hops becoming one
            // since the populateSubnet will point the old location to the new location via spine.
            }
        });
    });
    toBeAdded.forEach(route -> {
        IpPrefix prefix = route.prefix();
        MacAddress nextHopMac = route.nextHopMac();
        VlanId nextHopVlan = route.nextHopVlan();
        Set<ConnectPoint> locations = srManager.nextHopLocations(route);
        locations.forEach(location -> {
            log.debug("RouteUpdated. addSubnet {}, {}", location, prefix);
            srManager.deviceConfiguration.addSubnet(location, prefix);
            log.debug("RouteUpdated. populateRoute {}, {}, {}, {}", location, prefix, nextHopMac, nextHopVlan);
            srManager.defaultRoutingHandler.populateRoute(location.deviceId(), prefix, nextHopMac, nextHopVlan, location.port(), false);
            processSingleLeafPairIfNeeded(locations, location, prefix, nextHopVlan);
        });
    });
}
Also used : IpPrefix(org.onlab.packet.IpPrefix) Set(java.util.Set) ResolvedRoute(org.onosproject.routeservice.ResolvedRoute) MacAddress(org.onlab.packet.MacAddress) ConnectPoint(org.onosproject.net.ConnectPoint) VlanId(org.onlab.packet.VlanId)

Aggregations

ResolvedRoute (org.onosproject.routeservice.ResolvedRoute)18 Test (org.junit.Test)14 RouteEvent (org.onosproject.routeservice.RouteEvent)9 Route (org.onosproject.routeservice.Route)8 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 RouteService (org.onosproject.routeservice.RouteService)4 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3 DefaultNextObjective (org.onosproject.net.flowobjective.DefaultNextObjective)3 NextObjective (org.onosproject.net.flowobjective.NextObjective)3 GET (javax.ws.rs.GET)2 Produces (javax.ws.rs.Produces)2 IpPrefix (org.onlab.packet.IpPrefix)2 MacAddress (org.onlab.packet.MacAddress)2 VlanId (org.onlab.packet.VlanId)2 DefaultHost (org.onosproject.net.DefaultHost)2 Host (org.onosproject.net.Host)2 HostEvent (org.onosproject.net.host.HostEvent)2