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