Skip to content

Commit

Permalink
[AETHER-72] Refactoring RouteService
Browse files Browse the repository at this point in the history
- to use bulk updates interface
- to use new getRoutesForNextHops API
- to use multi-thread resolver
- to use multi-thread hostexec
- to use a concurrent hashmap instead of synchronized
- to use a non-blocking resolved store

Additionally updates unit tests

Change-Id: Id960abd0f2a1b03066ce34b6a2f72b76566bb58c
  • Loading branch information
pierventre committed Apr 6, 2021
1 parent ec2b318 commit e91c87f
Show file tree
Hide file tree
Showing 12 changed files with 502 additions and 131 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,27 @@ public interface RouteStore extends Store<InternalRouteEvent, RouteStoreDelegate
*/
void updateRoute(Route route);

/**
* Adds or updates the given routes in the store.
*
* @param routes routes to add or update
*/
void updateRoutes(Collection<Route> routes);

/**
* Removes the given route from the store.
*
* @param route route to remove
*/
void removeRoute(Route route);

/**
* Removes the given routes from the store.
*
* @param routes routes to remove
*/
void removeRoutes(Collection<Route> routes);

/**
* Replaces the all the routes for a prefix
* with the given route.
Expand Down Expand Up @@ -78,6 +92,14 @@ default void replaceRoute(Route route) {
// TODO think about including route table info
Collection<Route> getRoutesForNextHop(IpAddress ip);

/**
* Returns all routes that point to any of the given next hops IP addresses.
*
* @param nextHops next hops IP addresses
* @return collection of routes sets
*/
Collection<RouteSet> getRoutesForNextHops(Collection<IpAddress> nextHops);

/**
* Returns the set of routes in the default route table for the given prefix.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,21 @@ public void updateRoute(Route route) {

}

@Override
public void updateRoutes(Collection<Route> routes) {

}

@Override
public void removeRoute(Route route) {

}

@Override
public void removeRoutes(Collection<Route> routes) {

}

@Override
public void replaceRoute(Route route) {

Expand All @@ -55,6 +65,11 @@ public Collection<Route> getRoutesForNextHop(IpAddress ip) {
return null;
}

@Override
public Collection<RouteSet> getRoutesForNextHops(Collection<IpAddress> nextHops) {
return null;
}

@Override
public RouteSet getRoutes(IpPrefix prefix) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package org.onosproject.routeservice.impl;

import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Maps;
import com.googlecode.concurrenttrees.common.KeyValuePair;
import com.googlecode.concurrenttrees.radix.node.concrete.DefaultByteArrayNodeFactory;
import com.googlecode.concurrenttrees.radixinverted.ConcurrentInvertedRadixTree;
Expand Down Expand Up @@ -121,7 +120,7 @@ public RouteTable() {
routeTable = new ConcurrentInvertedRadixTree<>(
new DefaultByteArrayNodeFactory());

alternativeRoutes = Maps.newHashMap();
alternativeRoutes = new ConcurrentHashMap<>();
}

/**
Expand All @@ -133,7 +132,6 @@ public RouteTable() {
public RouteEvent update(ResolvedRoute route, Set<ResolvedRoute> alternatives) {
Set<ResolvedRoute> immutableAlternatives = checkAlternatives(route, alternatives);

synchronized (this) {
ResolvedRoute oldRoute = routeTable.put(createBinaryString(route.prefix()), route);
Set<ResolvedRoute> oldRoutes = alternativeRoutes.put(route.prefix(), immutableAlternatives);

Expand All @@ -153,7 +151,6 @@ public RouteEvent update(ResolvedRoute route, Set<ResolvedRoute> alternatives) {
}

return null;
}
}

/**
Expand Down Expand Up @@ -181,18 +178,16 @@ private Set<ResolvedRoute> checkAlternatives(ResolvedRoute route, Set<ResolvedRo
* @param prefix prefix to remove
*/
public RouteEvent remove(IpPrefix prefix) {
synchronized (this) {
String key = createBinaryString(prefix);
String key = createBinaryString(prefix);

ResolvedRoute route = routeTable.getValueForExactKey(key);
Set<ResolvedRoute> alternatives = alternativeRoutes.remove(prefix);
ResolvedRoute route = routeTable.getValueForExactKey(key);
Set<ResolvedRoute> alternatives = alternativeRoutes.remove(prefix);

if (route != null) {
routeTable.remove(key);
return new RouteEvent(RouteEvent.Type.ROUTE_REMOVED, route, alternatives);
}
return null;
if (route != null) {
routeTable.remove(key);
return new RouteEvent(RouteEvent.Type.ROUTE_REMOVED, route, alternatives);
}
return null;
}

/**
Expand Down
Loading

0 comments on commit e91c87f

Please sign in to comment.