Jonathan Hart
Committed by Gerrit Code Review

Modified BGP and FPM route sources to push to new route service.

Also created an adapter to adapt the new interface to the old one for
backwards compatibilty with existing FIB components.

Change-Id: If8eb2220d9e4e69af135a8f9469ffda567ed4448
...@@ -18,6 +18,7 @@ package org.onosproject.routing; ...@@ -18,6 +18,7 @@ package org.onosproject.routing;
18 /** 18 /**
19 * A source of route updates. 19 * A source of route updates.
20 */ 20 */
21 +@Deprecated
21 public interface RouteSourceService { 22 public interface RouteSourceService {
22 23
23 /** 24 /**
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
16 package org.onosproject.routing.bgp; 16 package org.onosproject.routing.bgp;
17 17
18 import org.onlab.packet.IpPrefix; 18 import org.onlab.packet.IpPrefix;
19 +import org.onosproject.incubator.net.routing.Route;
19 import org.onosproject.routing.RouteUpdate; 20 import org.onosproject.routing.RouteUpdate;
20 import org.slf4j.Logger; 21 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory; 22 import org.slf4j.LoggerFactory;
...@@ -45,15 +46,16 @@ class BgpRouteSelector { ...@@ -45,15 +46,16 @@ class BgpRouteSelector {
45 * Processes route entry updates: added/updated and deleted route 46 * Processes route entry updates: added/updated and deleted route
46 * entries. 47 * entries.
47 * 48 *
48 - * @param bgpSession the BGP session the route entry updates were
49 - * received on
50 * @param addedBgpRouteEntries the added/updated route entries to process 49 * @param addedBgpRouteEntries the added/updated route entries to process
51 * @param deletedBgpRouteEntries the deleted route entries to process 50 * @param deletedBgpRouteEntries the deleted route entries to process
52 */ 51 */
53 - synchronized void routeUpdates(BgpSession bgpSession, 52 + synchronized void routeUpdates(
54 Collection<BgpRouteEntry> addedBgpRouteEntries, 53 Collection<BgpRouteEntry> addedBgpRouteEntries,
55 Collection<BgpRouteEntry> deletedBgpRouteEntries) { 54 Collection<BgpRouteEntry> deletedBgpRouteEntries) {
56 - Collection<RouteUpdate> routeUpdates = new LinkedList<>(); 55 +
56 + Collection<Route> updates = new LinkedList<>();
57 + Collection<Route> withdraws = new LinkedList<>();
58 +
57 RouteUpdate routeUpdate; 59 RouteUpdate routeUpdate;
58 60
59 if (bgpSessionManager.isShutdown()) { 61 if (bgpSessionManager.isShutdown()) {
...@@ -61,32 +63,42 @@ class BgpRouteSelector { ...@@ -61,32 +63,42 @@ class BgpRouteSelector {
61 } 63 }
62 // Process the deleted route entries 64 // Process the deleted route entries
63 for (BgpRouteEntry bgpRouteEntry : deletedBgpRouteEntries) { 65 for (BgpRouteEntry bgpRouteEntry : deletedBgpRouteEntries) {
64 - routeUpdate = processDeletedRoute(bgpSession, bgpRouteEntry); 66 + routeUpdate = processDeletedRoute(bgpRouteEntry);
65 - if (routeUpdate != null) { 67 + convertRouteUpdateToRoute(routeUpdate, updates, withdraws);
66 - routeUpdates.add(routeUpdate);
67 - }
68 } 68 }
69 69
70 // Process the added/updated route entries 70 // Process the added/updated route entries
71 for (BgpRouteEntry bgpRouteEntry : addedBgpRouteEntries) { 71 for (BgpRouteEntry bgpRouteEntry : addedBgpRouteEntries) {
72 - routeUpdate = processAddedRoute(bgpSession, bgpRouteEntry); 72 + routeUpdate = processAddedRoute(bgpRouteEntry);
73 - if (routeUpdate != null) { 73 + convertRouteUpdateToRoute(routeUpdate, updates, withdraws);
74 - routeUpdates.add(routeUpdate); 74 + }
75 +
76 + bgpSessionManager.withdraw(withdraws);
77 + bgpSessionManager.update(updates);
78 + }
79 +
80 + private void convertRouteUpdateToRoute(RouteUpdate routeUpdate,
81 + Collection<Route> updates,
82 + Collection<Route> withdraws) {
83 + if (routeUpdate != null) {
84 + Route route = new Route(Route.Source.BGP, routeUpdate.routeEntry().prefix(),
85 + routeUpdate.routeEntry().nextHop());
86 + if (routeUpdate.type().equals(RouteUpdate.Type.UPDATE)) {
87 + updates.add(route);
88 + } else if (routeUpdate.type().equals(RouteUpdate.Type.DELETE)) {
89 + withdraws.add(route);
75 } 90 }
76 } 91 }
77 - bgpSessionManager.getRouteListener().update(routeUpdates);
78 } 92 }
79 93
80 /** 94 /**
81 * Processes an added/updated route entry. 95 * Processes an added/updated route entry.
82 * 96 *
83 - * @param bgpSession the BGP session the route entry update was received on
84 * @param bgpRouteEntry the added/updated route entry 97 * @param bgpRouteEntry the added/updated route entry
85 * @return the result route update that should be forwarded to the 98 * @return the result route update that should be forwarded to the
86 * Route Listener, or null if no route update should be forwarded 99 * Route Listener, or null if no route update should be forwarded
87 */ 100 */
88 - private RouteUpdate processAddedRoute(BgpSession bgpSession, 101 + private RouteUpdate processAddedRoute(BgpRouteEntry bgpRouteEntry) {
89 - BgpRouteEntry bgpRouteEntry) {
90 RouteUpdate routeUpdate; 102 RouteUpdate routeUpdate;
91 BgpRouteEntry bestBgpRouteEntry = 103 BgpRouteEntry bestBgpRouteEntry =
92 bgpSessionManager.findBgpRoute(bgpRouteEntry.prefix()); 104 bgpSessionManager.findBgpRoute(bgpRouteEntry.prefix());
...@@ -136,13 +148,11 @@ class BgpRouteSelector { ...@@ -136,13 +148,11 @@ class BgpRouteSelector {
136 /** 148 /**
137 * Processes a deleted route entry. 149 * Processes a deleted route entry.
138 * 150 *
139 - * @param bgpSession the BGP session the route entry update was received on
140 * @param bgpRouteEntry the deleted route entry 151 * @param bgpRouteEntry the deleted route entry
141 * @return the result route update that should be forwarded to the 152 * @return the result route update that should be forwarded to the
142 * Route Listener, or null if no route update should be forwarded 153 * Route Listener, or null if no route update should be forwarded
143 */ 154 */
144 - private RouteUpdate processDeletedRoute(BgpSession bgpSession, 155 + private RouteUpdate processDeletedRoute(BgpRouteEntry bgpRouteEntry) {
145 - BgpRouteEntry bgpRouteEntry) {
146 RouteUpdate routeUpdate; 156 RouteUpdate routeUpdate;
147 BgpRouteEntry bestBgpRouteEntry = 157 BgpRouteEntry bestBgpRouteEntry =
148 bgpSessionManager.findBgpRoute(bgpRouteEntry.prefix()); 158 bgpSessionManager.findBgpRoute(bgpRouteEntry.prefix());
......
...@@ -327,6 +327,7 @@ public class BgpSession extends SimpleChannelHandler { ...@@ -327,6 +327,7 @@ public class BgpSession extends SimpleChannelHandler {
327 ctx.getChannel().getRemoteAddress(), 327 ctx.getChannel().getRemoteAddress(),
328 ctx.getChannel().getLocalAddress(), 328 ctx.getChannel().getLocalAddress(),
329 e); 329 e);
330 + log.debug("Exception:", e.getCause());
330 processChannelDisconnected(); 331 processChannelDisconnected();
331 } 332 }
332 333
...@@ -350,8 +351,8 @@ public class BgpSession extends SimpleChannelHandler { ...@@ -350,8 +351,8 @@ public class BgpSession extends SimpleChannelHandler {
350 BgpRouteSelector bgpRouteSelector = 351 BgpRouteSelector bgpRouteSelector =
351 bgpSessionManager.getBgpRouteSelector(); 352 bgpSessionManager.getBgpRouteSelector();
352 Collection<BgpRouteEntry> addedRoutes = Collections.emptyList(); 353 Collection<BgpRouteEntry> addedRoutes = Collections.emptyList();
353 - bgpRouteSelector.routeUpdates(this, addedRoutes, deletedRoutes4); 354 + bgpRouteSelector.routeUpdates(addedRoutes, deletedRoutes4);
354 - bgpRouteSelector.routeUpdates(this, addedRoutes, deletedRoutes6); 355 + bgpRouteSelector.routeUpdates(addedRoutes, deletedRoutes6);
355 356
356 bgpSessionManager.peerDisconnected(this); 357 bgpSessionManager.peerDisconnected(this);
357 } 358 }
......
...@@ -19,6 +19,8 @@ import org.apache.felix.scr.annotations.Activate; ...@@ -19,6 +19,8 @@ import org.apache.felix.scr.annotations.Activate;
19 import org.apache.felix.scr.annotations.Component; 19 import org.apache.felix.scr.annotations.Component;
20 import org.apache.felix.scr.annotations.Deactivate; 20 import org.apache.felix.scr.annotations.Deactivate;
21 import org.apache.felix.scr.annotations.Modified; 21 import org.apache.felix.scr.annotations.Modified;
22 +import org.apache.felix.scr.annotations.Reference;
23 +import org.apache.felix.scr.annotations.ReferenceCardinality;
22 import org.apache.felix.scr.annotations.Service; 24 import org.apache.felix.scr.annotations.Service;
23 import org.jboss.netty.bootstrap.ServerBootstrap; 25 import org.jboss.netty.bootstrap.ServerBootstrap;
24 import org.jboss.netty.channel.Channel; 26 import org.jboss.netty.channel.Channel;
...@@ -34,8 +36,8 @@ import org.onlab.packet.Ip4Address; ...@@ -34,8 +36,8 @@ import org.onlab.packet.Ip4Address;
34 import org.onlab.packet.Ip4Prefix; 36 import org.onlab.packet.Ip4Prefix;
35 import org.onlab.packet.Ip6Prefix; 37 import org.onlab.packet.Ip6Prefix;
36 import org.onlab.packet.IpPrefix; 38 import org.onlab.packet.IpPrefix;
37 -import org.onosproject.routing.RouteSourceService; 39 +import org.onosproject.incubator.net.routing.Route;
38 -import org.onosproject.routing.RouteListener; 40 +import org.onosproject.incubator.net.routing.RouteAdminService;
39 import org.osgi.service.component.ComponentContext; 41 import org.osgi.service.component.ComponentContext;
40 import org.slf4j.Logger; 42 import org.slf4j.Logger;
41 import org.slf4j.LoggerFactory; 43 import org.slf4j.LoggerFactory;
...@@ -48,7 +50,6 @@ import java.util.Dictionary; ...@@ -48,7 +50,6 @@ import java.util.Dictionary;
48 import java.util.concurrent.ConcurrentHashMap; 50 import java.util.concurrent.ConcurrentHashMap;
49 import java.util.concurrent.ConcurrentMap; 51 import java.util.concurrent.ConcurrentMap;
50 52
51 -import static com.google.common.base.Preconditions.checkNotNull;
52 import static java.util.concurrent.Executors.newCachedThreadPool; 53 import static java.util.concurrent.Executors.newCachedThreadPool;
53 import static org.onlab.util.Tools.groupedThreads; 54 import static org.onlab.util.Tools.groupedThreads;
54 55
...@@ -57,10 +58,13 @@ import static org.onlab.util.Tools.groupedThreads; ...@@ -57,10 +58,13 @@ import static org.onlab.util.Tools.groupedThreads;
57 */ 58 */
58 @Component(immediate = true, enabled = false) 59 @Component(immediate = true, enabled = false)
59 @Service 60 @Service
60 -public class BgpSessionManager implements BgpInfoService, RouteSourceService { 61 +public class BgpSessionManager implements BgpInfoService {
61 private static final Logger log = 62 private static final Logger log =
62 LoggerFactory.getLogger(BgpSessionManager.class); 63 LoggerFactory.getLogger(BgpSessionManager.class);
63 64
65 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
66 + protected RouteAdminService routeService;
67 +
64 boolean isShutdown = true; 68 boolean isShutdown = true;
65 private Channel serverChannel; // Listener for incoming BGP connections 69 private Channel serverChannel; // Listener for incoming BGP connections
66 private ServerBootstrap serverBootstrap; 70 private ServerBootstrap serverBootstrap;
...@@ -75,19 +79,19 @@ public class BgpSessionManager implements BgpInfoService, RouteSourceService { ...@@ -75,19 +79,19 @@ public class BgpSessionManager implements BgpInfoService, RouteSourceService {
75 private ConcurrentMap<Ip6Prefix, BgpRouteEntry> bgpRoutes6 = 79 private ConcurrentMap<Ip6Prefix, BgpRouteEntry> bgpRoutes6 =
76 new ConcurrentHashMap<>(); 80 new ConcurrentHashMap<>();
77 81
78 - private RouteListener routeListener;
79 -
80 private static final int DEFAULT_BGP_PORT = 2000; 82 private static final int DEFAULT_BGP_PORT = 2000;
81 private int bgpPort; 83 private int bgpPort;
82 84
83 @Activate 85 @Activate
84 protected void activate(ComponentContext context) { 86 protected void activate(ComponentContext context) {
85 readComponentConfiguration(context); 87 readComponentConfiguration(context);
88 + start();
86 log.info("BgpSessionManager started"); 89 log.info("BgpSessionManager started");
87 } 90 }
88 91
89 @Deactivate 92 @Deactivate
90 protected void deactivate() { 93 protected void deactivate() {
94 + stop();
91 log.info("BgpSessionManager stopped"); 95 log.info("BgpSessionManager stopped");
92 } 96 }
93 97
...@@ -128,15 +132,6 @@ public class BgpSessionManager implements BgpInfoService, RouteSourceService { ...@@ -128,15 +132,6 @@ public class BgpSessionManager implements BgpInfoService, RouteSourceService {
128 } 132 }
129 133
130 /** 134 /**
131 - * Gets the route listener.
132 - *
133 - * @return the route listener to use
134 - */
135 - RouteListener getRouteListener() {
136 - return routeListener;
137 - }
138 -
139 - /**
140 * Gets the BGP sessions. 135 * Gets the BGP sessions.
141 * 136 *
142 * @return the BGP sessions 137 * @return the BGP sessions
...@@ -290,13 +285,29 @@ public class BgpSessionManager implements BgpInfoService, RouteSourceService { ...@@ -290,13 +285,29 @@ public class BgpSessionManager implements BgpInfoService, RouteSourceService {
290 return bgpRouteSelector; 285 return bgpRouteSelector;
291 } 286 }
292 287
293 - @Override 288 + /**
294 - public void start(RouteListener routeListener) { 289 + * Sends updates routes to the route service.
290 + *
291 + * @param updates routes to update
292 + */
293 + void update(Collection<Route> updates) {
294 + routeService.update(updates);
295 + }
296 +
297 + /**
298 + * Sends withdrawn routes to the routes service.
299 + *
300 + * @param withdraws routes to withdraw
301 + */
302 + void withdraw(Collection<Route> withdraws) {
303 + routeService.withdraw(withdraws);
304 + }
305 +
306 +
307 + public void start() {
295 log.debug("BGP Session Manager start."); 308 log.debug("BGP Session Manager start.");
296 isShutdown = false; 309 isShutdown = false;
297 310
298 - this.routeListener = checkNotNull(routeListener);
299 -
300 ChannelFactory channelFactory = new NioServerSocketChannelFactory( 311 ChannelFactory channelFactory = new NioServerSocketChannelFactory(
301 newCachedThreadPool(groupedThreads("onos/bgp", "sm-boss-%d")), 312 newCachedThreadPool(groupedThreads("onos/bgp", "sm-boss-%d")),
302 newCachedThreadPool(groupedThreads("onos/bgp", "sm-worker-%d"))); 313 newCachedThreadPool(groupedThreads("onos/bgp", "sm-worker-%d")));
...@@ -330,7 +341,6 @@ public class BgpSessionManager implements BgpInfoService, RouteSourceService { ...@@ -330,7 +341,6 @@ public class BgpSessionManager implements BgpInfoService, RouteSourceService {
330 } 341 }
331 } 342 }
332 343
333 - @Override
334 public void stop() { 344 public void stop() {
335 isShutdown = true; 345 isShutdown = true;
336 allChannels.close().awaitUninterruptibly(); 346 allChannels.close().awaitUninterruptibly();
......
...@@ -154,10 +154,10 @@ final class BgpUpdate { ...@@ -154,10 +154,10 @@ final class BgpUpdate {
154 // 154 //
155 BgpRouteSelector bgpRouteSelector = 155 BgpRouteSelector bgpRouteSelector =
156 bgpSession.getBgpSessionManager().getBgpRouteSelector(); 156 bgpSession.getBgpSessionManager().getBgpRouteSelector();
157 - bgpRouteSelector.routeUpdates(bgpSession, 157 + bgpRouteSelector.routeUpdates(
158 decodedBgpRoutes.addedUnicastRoutes4.values(), 158 decodedBgpRoutes.addedUnicastRoutes4.values(),
159 decodedBgpRoutes.deletedUnicastRoutes4.values()); 159 decodedBgpRoutes.deletedUnicastRoutes4.values());
160 - bgpRouteSelector.routeUpdates(bgpSession, 160 + bgpRouteSelector.routeUpdates(
161 decodedBgpRoutes.addedUnicastRoutes6.values(), 161 decodedBgpRoutes.addedUnicastRoutes6.values(),
162 decodedBgpRoutes.deletedUnicastRoutes6.values()); 162 decodedBgpRoutes.deletedUnicastRoutes6.values());
163 163
......
...@@ -15,18 +15,10 @@ ...@@ -15,18 +15,10 @@
15 */ 15 */
16 package org.onosproject.routing.config.impl; 16 package org.onosproject.routing.config.impl;
17 17
18 -import static org.onosproject.routing.RouteEntry.createBinaryString;
19 -
20 import com.google.common.collect.ImmutableSet; 18 import com.google.common.collect.ImmutableSet;
21 import com.googlecode.concurrenttrees.radix.node.concrete.DefaultByteArrayNodeFactory; 19 import com.googlecode.concurrenttrees.radix.node.concrete.DefaultByteArrayNodeFactory;
22 import com.googlecode.concurrenttrees.radixinverted.ConcurrentInvertedRadixTree; 20 import com.googlecode.concurrenttrees.radixinverted.ConcurrentInvertedRadixTree;
23 import com.googlecode.concurrenttrees.radixinverted.InvertedRadixTree; 21 import com.googlecode.concurrenttrees.radixinverted.InvertedRadixTree;
24 -
25 -import java.util.HashSet;
26 -import java.util.Objects;
27 -import java.util.Set;
28 -import java.util.stream.Collectors;
29 -
30 import org.apache.felix.scr.annotations.Activate; 22 import org.apache.felix.scr.annotations.Activate;
31 import org.apache.felix.scr.annotations.Component; 23 import org.apache.felix.scr.annotations.Component;
32 import org.apache.felix.scr.annotations.Deactivate; 24 import org.apache.felix.scr.annotations.Deactivate;
...@@ -48,15 +40,22 @@ import org.onosproject.net.config.NetworkConfigListener; ...@@ -48,15 +40,22 @@ import org.onosproject.net.config.NetworkConfigListener;
48 import org.onosproject.net.config.NetworkConfigRegistry; 40 import org.onosproject.net.config.NetworkConfigRegistry;
49 import org.onosproject.net.config.NetworkConfigService; 41 import org.onosproject.net.config.NetworkConfigService;
50 import org.onosproject.net.config.basics.SubjectFactories; 42 import org.onosproject.net.config.basics.SubjectFactories;
43 +import org.onosproject.routing.RoutingService;
51 import org.onosproject.routing.config.BgpConfig; 44 import org.onosproject.routing.config.BgpConfig;
52 import org.onosproject.routing.config.LocalIpPrefixEntry; 45 import org.onosproject.routing.config.LocalIpPrefixEntry;
53 import org.onosproject.routing.config.ReactiveRoutingConfig; 46 import org.onosproject.routing.config.ReactiveRoutingConfig;
54 import org.onosproject.routing.config.RouterConfig; 47 import org.onosproject.routing.config.RouterConfig;
55 import org.onosproject.routing.config.RoutingConfigurationService; 48 import org.onosproject.routing.config.RoutingConfigurationService;
56 -import org.onosproject.routing.impl.Router;
57 import org.slf4j.Logger; 49 import org.slf4j.Logger;
58 import org.slf4j.LoggerFactory; 50 import org.slf4j.LoggerFactory;
59 51
52 +import java.util.HashSet;
53 +import java.util.Objects;
54 +import java.util.Set;
55 +import java.util.stream.Collectors;
56 +
57 +import static org.onosproject.routing.RouteEntry.createBinaryString;
58 +
60 /** 59 /**
61 * Implementation of RoutingConfigurationService which reads routing 60 * Implementation of RoutingConfigurationService which reads routing
62 * configuration from a file. 61 * configuration from a file.
...@@ -165,7 +164,7 @@ public class RoutingConfigurationImpl implements RoutingConfigurationService { ...@@ -165,7 +164,7 @@ public class RoutingConfigurationImpl implements RoutingConfigurationService {
165 virtualGatewayMacAddress = config.virtualGatewayMacAddress(); 164 virtualGatewayMacAddress = config.virtualGatewayMacAddress();
166 165
167 // Setup BGP peer connect points 166 // Setup BGP peer connect points
168 - ApplicationId routerAppId = coreService.getAppId(Router.ROUTER_APP_ID); 167 + ApplicationId routerAppId = coreService.getAppId(RoutingService.ROUTER_APP_ID);
169 if (routerAppId == null) { 168 if (routerAppId == null) {
170 log.info("Router application ID is null!"); 169 log.info("Router application ID is null!");
171 return; 170 return;
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
15 */ 15 */
16 package org.onosproject.routing.fpm; 16 package org.onosproject.routing.fpm;
17 17
18 +import com.google.common.collect.ImmutableList;
18 import com.google.common.collect.ImmutableMap; 19 import com.google.common.collect.ImmutableMap;
19 import org.apache.felix.scr.annotations.Activate; 20 import org.apache.felix.scr.annotations.Activate;
20 import org.apache.felix.scr.annotations.Component; 21 import org.apache.felix.scr.annotations.Component;
...@@ -38,10 +39,8 @@ import org.onlab.packet.IpAddress; ...@@ -38,10 +39,8 @@ import org.onlab.packet.IpAddress;
38 import org.onlab.packet.IpPrefix; 39 import org.onlab.packet.IpPrefix;
39 import org.onlab.util.Tools; 40 import org.onlab.util.Tools;
40 import org.onosproject.cfg.ComponentConfigService; 41 import org.onosproject.cfg.ComponentConfigService;
41 -import org.onosproject.routing.RouteEntry; 42 +import org.onosproject.incubator.net.routing.Route;
42 -import org.onosproject.routing.RouteListener; 43 +import org.onosproject.incubator.net.routing.RouteAdminService;
43 -import org.onosproject.routing.RouteSourceService;
44 -import org.onosproject.routing.RouteUpdate;
45 import org.onosproject.routing.fpm.protocol.FpmHeader; 44 import org.onosproject.routing.fpm.protocol.FpmHeader;
46 import org.onosproject.routing.fpm.protocol.Netlink; 45 import org.onosproject.routing.fpm.protocol.Netlink;
47 import org.onosproject.routing.fpm.protocol.RouteAttribute; 46 import org.onosproject.routing.fpm.protocol.RouteAttribute;
...@@ -55,12 +54,11 @@ import org.slf4j.LoggerFactory; ...@@ -55,12 +54,11 @@ import org.slf4j.LoggerFactory;
55 54
56 import java.net.InetSocketAddress; 55 import java.net.InetSocketAddress;
57 import java.net.SocketAddress; 56 import java.net.SocketAddress;
58 -import java.util.Collections;
59 import java.util.Dictionary; 57 import java.util.Dictionary;
58 +import java.util.LinkedList;
60 import java.util.List; 59 import java.util.List;
61 import java.util.Map; 60 import java.util.Map;
62 import java.util.concurrent.ConcurrentHashMap; 61 import java.util.concurrent.ConcurrentHashMap;
63 -import java.util.stream.Collectors;
64 62
65 import static java.util.concurrent.Executors.newCachedThreadPool; 63 import static java.util.concurrent.Executors.newCachedThreadPool;
66 import static org.onlab.util.Tools.groupedThreads; 64 import static org.onlab.util.Tools.groupedThreads;
...@@ -70,7 +68,7 @@ import static org.onlab.util.Tools.groupedThreads; ...@@ -70,7 +68,7 @@ import static org.onlab.util.Tools.groupedThreads;
70 */ 68 */
71 @Service 69 @Service
72 @Component(immediate = true, enabled = false) 70 @Component(immediate = true, enabled = false)
73 -public class FpmManager implements RouteSourceService, FpmInfoService { 71 +public class FpmManager implements FpmInfoService {
74 private final Logger log = LoggerFactory.getLogger(getClass()); 72 private final Logger log = LoggerFactory.getLogger(getClass());
75 73
76 private static final int FPM_PORT = 2620; 74 private static final int FPM_PORT = 2620;
...@@ -78,15 +76,16 @@ public class FpmManager implements RouteSourceService, FpmInfoService { ...@@ -78,15 +76,16 @@ public class FpmManager implements RouteSourceService, FpmInfoService {
78 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 76 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
79 protected ComponentConfigService componentConfigService; 77 protected ComponentConfigService componentConfigService;
80 78
79 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
80 + protected RouteAdminService routeService;
81 +
81 private ServerBootstrap serverBootstrap; 82 private ServerBootstrap serverBootstrap;
82 private Channel serverChannel; 83 private Channel serverChannel;
83 private ChannelGroup allChannels = new DefaultChannelGroup(); 84 private ChannelGroup allChannels = new DefaultChannelGroup();
84 85
85 private Map<SocketAddress, Long> peers = new ConcurrentHashMap<>(); 86 private Map<SocketAddress, Long> peers = new ConcurrentHashMap<>();
86 87
87 - private Map<IpPrefix, RouteEntry> fpmRoutes = new ConcurrentHashMap<>(); 88 + private Map<IpPrefix, Route> fpmRoutes = new ConcurrentHashMap<>();
88 -
89 - private RouteListener routeListener;
90 89
91 @Property(name = "clearRoutes", boolValue = true, 90 @Property(name = "clearRoutes", boolValue = true,
92 label = "Whether to clear routes when the FPM connection goes down") 91 label = "Whether to clear routes when the FPM connection goes down")
...@@ -96,12 +95,14 @@ public class FpmManager implements RouteSourceService, FpmInfoService { ...@@ -96,12 +95,14 @@ public class FpmManager implements RouteSourceService, FpmInfoService {
96 protected void activate(ComponentContext context) { 95 protected void activate(ComponentContext context) {
97 componentConfigService.registerProperties(getClass()); 96 componentConfigService.registerProperties(getClass());
98 modified(context); 97 modified(context);
98 + startServer();
99 log.info("Started"); 99 log.info("Started");
100 } 100 }
101 101
102 @Deactivate 102 @Deactivate
103 protected void deactivate() { 103 protected void deactivate() {
104 stopServer(); 104 stopServer();
105 + fpmRoutes.clear();
105 componentConfigService.unregisterProperties(getClass(), false); 106 componentConfigService.unregisterProperties(getClass(), false);
106 log.info("Stopped"); 107 log.info("Stopped");
107 } 108 }
...@@ -165,19 +166,6 @@ public class FpmManager implements RouteSourceService, FpmInfoService { ...@@ -165,19 +166,6 @@ public class FpmManager implements RouteSourceService, FpmInfoService {
165 } 166 }
166 } 167 }
167 168
168 - @Override
169 - public void start(RouteListener routeListener) {
170 - this.routeListener = routeListener;
171 -
172 - startServer();
173 - }
174 -
175 - @Override
176 - public void stop() {
177 - fpmRoutes.clear();
178 - stopServer();
179 - }
180 -
181 private void fpmMessage(FpmHeader fpmMessage) { 169 private void fpmMessage(FpmHeader fpmMessage) {
182 Netlink netlink = fpmMessage.netlink(); 170 Netlink netlink = fpmMessage.netlink();
183 RtNetlink rtNetlink = netlink.rtNetlink(); 171 RtNetlink rtNetlink = netlink.rtNetlink();
...@@ -212,51 +200,46 @@ public class FpmManager implements RouteSourceService, FpmInfoService { ...@@ -212,51 +200,46 @@ public class FpmManager implements RouteSourceService, FpmInfoService {
212 200
213 IpPrefix prefix = IpPrefix.valueOf(dstAddress, rtNetlink.dstLength()); 201 IpPrefix prefix = IpPrefix.valueOf(dstAddress, rtNetlink.dstLength());
214 202
215 - RouteUpdate routeUpdate = null; 203 + List<Route> updates = new LinkedList<>();
216 - RouteEntry entry; 204 + List<Route> withdraws = new LinkedList<>();
205 +
206 + Route route;
217 switch (netlink.type()) { 207 switch (netlink.type()) {
218 case RTM_NEWROUTE: 208 case RTM_NEWROUTE:
219 if (gateway == null) { 209 if (gateway == null) {
220 // We ignore interface routes with no gateway for now. 210 // We ignore interface routes with no gateway for now.
221 return; 211 return;
222 } 212 }
223 - entry = new RouteEntry(prefix, gateway); 213 + route = new Route(Route.Source.FPM, prefix, gateway);
224 214
225 - fpmRoutes.put(entry.prefix(), entry); 215 + fpmRoutes.put(prefix, route);
226 216
227 - routeUpdate = new RouteUpdate(RouteUpdate.Type.UPDATE, entry); 217 + updates.add(route);
228 break; 218 break;
229 case RTM_DELROUTE: 219 case RTM_DELROUTE:
230 - RouteEntry existing = fpmRoutes.remove(prefix); 220 + Route existing = fpmRoutes.remove(prefix);
231 if (existing == null) { 221 if (existing == null) {
232 log.warn("Got delete for non-existent prefix"); 222 log.warn("Got delete for non-existent prefix");
233 return; 223 return;
234 } 224 }
235 225
236 - entry = new RouteEntry(prefix, existing.nextHop()); 226 + route = new Route(Route.Source.FPM, prefix, existing.nextHop());
237 227
238 - routeUpdate = new RouteUpdate(RouteUpdate.Type.DELETE, entry); 228 + withdraws.add(route);
239 break; 229 break;
240 case RTM_GETROUTE: 230 case RTM_GETROUTE:
241 default: 231 default:
242 break; 232 break;
243 } 233 }
244 234
245 - if (routeUpdate == null) { 235 + routeService.withdraw(withdraws);
246 - log.warn("Unsupported FPM message: {}", fpmMessage); 236 + routeService.update(updates);
247 - return;
248 - }
249 -
250 - routeListener.update(Collections.singletonList(routeUpdate));
251 } 237 }
252 238
253 239
254 private void clearRoutes() { 240 private void clearRoutes() {
255 log.info("Clearing all routes"); 241 log.info("Clearing all routes");
256 - List<RouteUpdate> routeUpdates = fpmRoutes.values().stream() 242 + routeService.withdraw(ImmutableList.copyOf(fpmRoutes.values()));
257 - .map(routeEntry -> new RouteUpdate(RouteUpdate.Type.DELETE, routeEntry))
258 - .collect(Collectors.toList());
259 - routeListener.update(routeUpdates);
260 } 243 }
261 244
262 @Override 245 @Override
......
...@@ -33,8 +33,7 @@ import org.onlab.junit.TestUtils; ...@@ -33,8 +33,7 @@ import org.onlab.junit.TestUtils;
33 import org.onlab.junit.TestUtils.TestUtilsException; 33 import org.onlab.junit.TestUtils.TestUtilsException;
34 import org.onlab.packet.Ip4Address; 34 import org.onlab.packet.Ip4Address;
35 import org.onlab.packet.Ip4Prefix; 35 import org.onlab.packet.Ip4Prefix;
36 -import org.onosproject.routing.RouteListener; 36 +import org.onosproject.incubator.net.routing.RouteAdminService;
37 -import org.onosproject.routing.RouteUpdate;
38 import org.osgi.service.component.ComponentContext; 37 import org.osgi.service.component.ComponentContext;
39 38
40 import java.net.InetAddress; 39 import java.net.InetAddress;
...@@ -48,6 +47,7 @@ import java.util.concurrent.Executors; ...@@ -48,6 +47,7 @@ import java.util.concurrent.Executors;
48 import java.util.concurrent.TimeUnit; 47 import java.util.concurrent.TimeUnit;
49 48
50 import static org.easymock.EasyMock.createMock; 49 import static org.easymock.EasyMock.createMock;
50 +import static org.easymock.EasyMock.createNiceMock;
51 import static org.easymock.EasyMock.expect; 51 import static org.easymock.EasyMock.expect;
52 import static org.easymock.EasyMock.replay; 52 import static org.easymock.EasyMock.replay;
53 import static org.hamcrest.Matchers.hasSize; 53 import static org.hamcrest.Matchers.hasSize;
...@@ -85,6 +85,8 @@ public class BgpSessionManagerTest { ...@@ -85,6 +85,8 @@ public class BgpSessionManagerTest {
85 // Timeout waiting for a message to be received 85 // Timeout waiting for a message to be received
86 private static final int MESSAGE_TIMEOUT_MS = 5000; // 5s 86 private static final int MESSAGE_TIMEOUT_MS = 5000; // 5s
87 87
88 + private RouteAdminService routeService;
89 +
88 // The BGP Session Manager to test 90 // The BGP Session Manager to test
89 private BgpSessionManager bgpSessionManager; 91 private BgpSessionManager bgpSessionManager;
90 92
...@@ -102,19 +104,6 @@ public class BgpSessionManagerTest { ...@@ -102,19 +104,6 @@ public class BgpSessionManagerTest {
102 // The socket that the remote peers should connect to 104 // The socket that the remote peers should connect to
103 private InetSocketAddress connectToSocket; 105 private InetSocketAddress connectToSocket;
104 106
105 - private final DummyRouteListener dummyRouteListener =
106 - new DummyRouteListener();
107 -
108 - /**
109 - * Dummy implementation for the RouteListener interface.
110 - */
111 - private class DummyRouteListener implements RouteListener {
112 - @Override
113 - public void update(Collection<RouteUpdate> routeUpdate) {
114 - // Nothing to do
115 - }
116 - }
117 -
118 /** 107 /**
119 * A class to capture the state for a BGP peer. 108 * A class to capture the state for a BGP peer.
120 */ 109 */
...@@ -238,13 +227,11 @@ public class BgpSessionManagerTest { ...@@ -238,13 +227,11 @@ public class BgpSessionManagerTest {
238 } 227 }
239 228
240 @SuppressWarnings("unchecked") 229 @SuppressWarnings("unchecked")
241 - private Dictionary 230 + private void getDictionaryMock(ComponentContext componentContext) {
242 - getDictionaryMock(ComponentContext componentContext) {
243 Dictionary dictionary = createMock(Dictionary.class); 231 Dictionary dictionary = createMock(Dictionary.class);
244 expect(dictionary.get("bgpPort")).andReturn("0"); 232 expect(dictionary.get("bgpPort")).andReturn("0");
245 replay(dictionary); 233 replay(dictionary);
246 expect(componentContext.getProperties()).andReturn(dictionary); 234 expect(componentContext.getProperties()).andReturn(dictionary);
247 - return dictionary;
248 } 235 }
249 236
250 @Before 237 @Before
...@@ -262,12 +249,16 @@ public class BgpSessionManagerTest { ...@@ -262,12 +249,16 @@ public class BgpSessionManagerTest {
262 // connections. 249 // connections.
263 // 250 //
264 bgpSessionManager = new BgpSessionManager(); 251 bgpSessionManager = new BgpSessionManager();
252 +
253 + routeService = createNiceMock(RouteAdminService.class);
254 + replay(routeService);
255 + bgpSessionManager.routeService = routeService;
256 +
265 // NOTE: We use port 0 to bind on any available port 257 // NOTE: We use port 0 to bind on any available port
266 ComponentContext componentContext = createMock(ComponentContext.class); 258 ComponentContext componentContext = createMock(ComponentContext.class);
267 - Dictionary dictionary = getDictionaryMock(componentContext); 259 + getDictionaryMock(componentContext);
268 replay(componentContext); 260 replay(componentContext);
269 bgpSessionManager.activate(componentContext); 261 bgpSessionManager.activate(componentContext);
270 - bgpSessionManager.start(dummyRouteListener);
271 262
272 // Get the port number the BGP Session Manager is listening on 263 // Get the port number the BGP Session Manager is listening on
273 Channel serverChannel = TestUtils.getField(bgpSessionManager, 264 Channel serverChannel = TestUtils.getField(bgpSessionManager,
...@@ -547,6 +538,7 @@ public class BgpSessionManagerTest { ...@@ -547,6 +538,7 @@ public class BgpSessionManagerTest {
547 withdrawnRoutes.add(Ip4Prefix.valueOf("70.0.0.0/16")); 538 withdrawnRoutes.add(Ip4Prefix.valueOf("70.0.0.0/16"));
548 withdrawnRoutes.add(Ip4Prefix.valueOf("80.0.0.0/24")); 539 withdrawnRoutes.add(Ip4Prefix.valueOf("80.0.0.0/24"));
549 withdrawnRoutes.add(Ip4Prefix.valueOf("90.0.0.0/32")); 540 withdrawnRoutes.add(Ip4Prefix.valueOf("90.0.0.0/32"));
541 +
550 // Write the routes 542 // Write the routes
551 message = peer1.peerChannelHandler.prepareBgpUpdate( 543 message = peer1.peerChannelHandler.prepareBgpUpdate(
552 NEXT_HOP1_ROUTER, 544 NEXT_HOP1_ROUTER,
......
...@@ -39,7 +39,7 @@ import org.onosproject.net.host.HostListener; ...@@ -39,7 +39,7 @@ import org.onosproject.net.host.HostListener;
39 import org.onosproject.net.host.HostService; 39 import org.onosproject.net.host.HostService;
40 import org.onosproject.net.provider.ProviderId; 40 import org.onosproject.net.provider.ProviderId;
41 import org.onosproject.routing.config.RoutingConfigurationService; 41 import org.onosproject.routing.config.RoutingConfigurationService;
42 -import org.onosproject.routing.impl.Router.InternalHostListener; 42 +import org.onosproject.routing.impl.DefaultRouter.InternalHostListener;
43 import org.onosproject.routing.RouteSourceService; 43 import org.onosproject.routing.RouteSourceService;
44 import org.onosproject.routing.FibEntry; 44 import org.onosproject.routing.FibEntry;
45 import org.onosproject.routing.FibListener; 45 import org.onosproject.routing.FibListener;
...@@ -74,7 +74,7 @@ public class RouterAsyncArpTest { ...@@ -74,7 +74,7 @@ public class RouterAsyncArpTest {
74 DeviceId.deviceId("of:0000000000000003"), 74 DeviceId.deviceId("of:0000000000000003"),
75 PortNumber.portNumber(1)); 75 PortNumber.portNumber(1));
76 76
77 - private Router router; 77 + private DefaultRouter router;
78 private InternalHostListener internalHostListener; 78 private InternalHostListener internalHostListener;
79 79
80 @Before 80 @Before
...@@ -90,7 +90,7 @@ public class RouterAsyncArpTest { ...@@ -90,7 +90,7 @@ public class RouterAsyncArpTest {
90 90
91 fibListener = createMock(FibListener.class); 91 fibListener = createMock(FibListener.class);
92 92
93 - router = new Router(); 93 + router = new DefaultRouter();
94 router.coreService = createNiceMock(CoreService.class); 94 router.coreService = createNiceMock(CoreService.class);
95 router.hostService = hostService; 95 router.hostService = hostService;
96 router.routingConfigurationService = routingConfigurationService; 96 router.routingConfigurationService = routingConfigurationService;
......
...@@ -90,7 +90,7 @@ public class RouterTest { ...@@ -90,7 +90,7 @@ public class RouterTest {
90 private static final ConnectPoint SW6_ETH1 = new ConnectPoint( 90 private static final ConnectPoint SW6_ETH1 = new ConnectPoint(
91 DeviceId.deviceId("of:0000000000000006"), 91 DeviceId.deviceId("of:0000000000000006"),
92 PortNumber.portNumber(1)); 92 PortNumber.portNumber(1));
93 - private Router router; 93 + private DefaultRouter router;
94 94
95 @Before 95 @Before
96 public void setUp() throws Exception { 96 public void setUp() throws Exception {
...@@ -105,7 +105,7 @@ public class RouterTest { ...@@ -105,7 +105,7 @@ public class RouterTest {
105 105
106 fibListener = createMock(FibListener.class); 106 fibListener = createMock(FibListener.class);
107 107
108 - router = new Router(); 108 + router = new DefaultRouter();
109 router.coreService = createNiceMock(CoreService.class); 109 router.coreService = createNiceMock(CoreService.class);
110 router.hostService = hostService; 110 router.hostService = hostService;
111 router.routingConfigurationService = routingConfigurationService; 111 router.routingConfigurationService = routingConfigurationService;
......
1 +/*
2 + * Copyright 2016-present Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +
17 +package org.onosproject.incubator.net.routing;
18 +
19 +import org.onlab.packet.IpAddress;
20 +
21 +import java.util.Collection;
22 +import java.util.Map;
23 +import java.util.Set;
24 +
25 +/**
26 + * Adapter class for the route service.
27 + */
28 +public class RouteServiceAdapter implements RouteAdminService {
29 + @Override
30 + public void update(Collection<Route> routes) {
31 +
32 + }
33 +
34 + @Override
35 + public void withdraw(Collection<Route> routes) {
36 +
37 + }
38 +
39 + @Override
40 + public Map<RouteTableId, Collection<Route>> getAllRoutes() {
41 + return null;
42 + }
43 +
44 + @Override
45 + public Route longestPrefixMatch(IpAddress ip) {
46 + return null;
47 + }
48 +
49 + @Override
50 + public Collection<Route> getRoutesForNextHop(IpAddress nextHop) {
51 + return null;
52 + }
53 +
54 + @Override
55 + public Set<NextHop> getNextHops() {
56 + return null;
57 + }
58 +
59 + @Override
60 + public void addListener(RouteListener listener) {
61 +
62 + }
63 +
64 + @Override
65 + public void removeListener(RouteListener listener) {
66 +
67 + }
68 +}