Move BGP listen port configuration to BgpSessionManager component
Change-Id: I445bff180740fededacaa59441fc53332cc3d482
Showing
9 changed files
with
71 additions
and
52 deletions
| ... | @@ -24,9 +24,8 @@ public interface BgpService { | ... | @@ -24,9 +24,8 @@ public interface BgpService { |
| 24 | * Starts the BGP service. | 24 | * Starts the BGP service. |
| 25 | * | 25 | * |
| 26 | * @param routeListener listener to send route updates to | 26 | * @param routeListener listener to send route updates to |
| 27 | - * @param bgpPort port number to listen on | ||
| 28 | */ | 27 | */ |
| 29 | - void start(RouteListener routeListener, int bgpPort); | 28 | + void start(RouteListener routeListener); |
| 30 | 29 | ||
| 31 | /** | 30 | /** |
| 32 | * Stops the BGP service. | 31 | * Stops the BGP service. | ... | ... |
| ... | @@ -55,6 +55,11 @@ | ... | @@ -55,6 +55,11 @@ |
| 55 | </dependency> | 55 | </dependency> |
| 56 | 56 | ||
| 57 | <dependency> | 57 | <dependency> |
| 58 | + <groupId>org.osgi</groupId> | ||
| 59 | + <artifactId>org.osgi.compendium</artifactId> | ||
| 60 | + </dependency> | ||
| 61 | + | ||
| 62 | + <dependency> | ||
| 58 | <groupId>org.apache.karaf.shell</groupId> | 63 | <groupId>org.apache.karaf.shell</groupId> |
| 59 | <artifactId>org.apache.karaf.shell.console</artifactId> | 64 | <artifactId>org.apache.karaf.shell.console</artifactId> |
| 60 | </dependency> | 65 | </dependency> | ... | ... |
| ... | @@ -124,7 +124,7 @@ public class Router implements RoutingService { | ... | @@ -124,7 +124,7 @@ public class Router implements RoutingService { |
| 124 | this.fibComponent = checkNotNull(listener); | 124 | this.fibComponent = checkNotNull(listener); |
| 125 | this.hostService.addListener(hostListener); | 125 | this.hostService.addListener(hostListener); |
| 126 | 126 | ||
| 127 | - bgpService.start(new InternalRouteListener(), 2000); | 127 | + bgpService.start(new InternalRouteListener()); |
| 128 | 128 | ||
| 129 | bgpUpdatesExecutor.execute(new Runnable() { | 129 | bgpUpdatesExecutor.execute(new Runnable() { |
| 130 | @Override | 130 | @Override | ... | ... |
| ... | @@ -15,7 +15,11 @@ | ... | @@ -15,7 +15,11 @@ |
| 15 | */ | 15 | */ |
| 16 | package org.onosproject.routing.bgp; | 16 | package org.onosproject.routing.bgp; |
| 17 | 17 | ||
| 18 | +import org.osgi.service.component.ComponentContext; | ||
| 19 | +import org.apache.felix.scr.annotations.Activate; | ||
| 18 | import org.apache.felix.scr.annotations.Component; | 20 | import org.apache.felix.scr.annotations.Component; |
| 21 | +import org.apache.felix.scr.annotations.Deactivate; | ||
| 22 | +import org.apache.felix.scr.annotations.Modified; | ||
| 19 | import org.apache.felix.scr.annotations.Service; | 23 | import org.apache.felix.scr.annotations.Service; |
| 20 | import org.jboss.netty.bootstrap.ServerBootstrap; | 24 | import org.jboss.netty.bootstrap.ServerBootstrap; |
| 21 | import org.jboss.netty.channel.Channel; | 25 | import org.jboss.netty.channel.Channel; |
| ... | @@ -40,6 +44,7 @@ import java.net.InetAddress; | ... | @@ -40,6 +44,7 @@ import java.net.InetAddress; |
| 40 | import java.net.InetSocketAddress; | 44 | import java.net.InetSocketAddress; |
| 41 | import java.net.SocketAddress; | 45 | import java.net.SocketAddress; |
| 42 | import java.util.Collection; | 46 | import java.util.Collection; |
| 47 | +import java.util.Dictionary; | ||
| 43 | import java.util.concurrent.ConcurrentHashMap; | 48 | import java.util.concurrent.ConcurrentHashMap; |
| 44 | import java.util.concurrent.ConcurrentMap; | 49 | import java.util.concurrent.ConcurrentMap; |
| 45 | 50 | ||
| ... | @@ -72,6 +77,47 @@ public class BgpSessionManager implements BgpInfoService, BgpService { | ... | @@ -72,6 +77,47 @@ public class BgpSessionManager implements BgpInfoService, BgpService { |
| 72 | 77 | ||
| 73 | private RouteListener routeListener; | 78 | private RouteListener routeListener; |
| 74 | 79 | ||
| 80 | + private static final int DEFAULT_BGP_PORT = 2000; | ||
| 81 | + private int bgpPort; | ||
| 82 | + | ||
| 83 | + @Activate | ||
| 84 | + protected void activate(ComponentContext context) { | ||
| 85 | + readComponentConfiguration(context); | ||
| 86 | + log.info("BgpSessionManager started"); | ||
| 87 | + } | ||
| 88 | + | ||
| 89 | + @Deactivate | ||
| 90 | + protected void deactivate() { | ||
| 91 | + log.info("BgpSessionManager stopped"); | ||
| 92 | + } | ||
| 93 | + | ||
| 94 | + /** | ||
| 95 | + * Extracts properties from the component configuration context. | ||
| 96 | + * | ||
| 97 | + * @param context the component context | ||
| 98 | + */ | ||
| 99 | + private void readComponentConfiguration(ComponentContext context) { | ||
| 100 | + Dictionary<?, ?> properties = context.getProperties(); | ||
| 101 | + try { | ||
| 102 | + String strPort = (String) properties.get("bgpPort"); | ||
| 103 | + if (strPort != null) { | ||
| 104 | + bgpPort = Integer.parseInt(strPort); | ||
| 105 | + } else { | ||
| 106 | + bgpPort = DEFAULT_BGP_PORT; | ||
| 107 | + } | ||
| 108 | + } catch (Exception e) { | ||
| 109 | + bgpPort = DEFAULT_BGP_PORT; | ||
| 110 | + } | ||
| 111 | + log.debug("BGP port is set to {}", bgpPort); | ||
| 112 | + } | ||
| 113 | + | ||
| 114 | + @Modified | ||
| 115 | + public void modified(ComponentContext context) { | ||
| 116 | + // Blank @Modified method to catch modifications to the context. | ||
| 117 | + // If no @Modified method exists, it seems @Activate is called again | ||
| 118 | + // when the context is modified. | ||
| 119 | + } | ||
| 120 | + | ||
| 75 | /** | 121 | /** |
| 76 | * Checks whether the BGP Session Manager is shutdown. | 122 | * Checks whether the BGP Session Manager is shutdown. |
| 77 | * | 123 | * |
| ... | @@ -245,7 +291,7 @@ public class BgpSessionManager implements BgpInfoService, BgpService { | ... | @@ -245,7 +291,7 @@ public class BgpSessionManager implements BgpInfoService, BgpService { |
| 245 | } | 291 | } |
| 246 | 292 | ||
| 247 | @Override | 293 | @Override |
| 248 | - public void start(RouteListener routeListener, int listenPortNumber) { | 294 | + public void start(RouteListener routeListener) { |
| 249 | log.debug("BGP Session Manager start."); | 295 | log.debug("BGP Session Manager start."); |
| 250 | isShutdown = false; | 296 | isShutdown = false; |
| 251 | 297 | ||
| ... | @@ -271,7 +317,7 @@ public class BgpSessionManager implements BgpInfoService, BgpService { | ... | @@ -271,7 +317,7 @@ public class BgpSessionManager implements BgpInfoService, BgpService { |
| 271 | } | 317 | } |
| 272 | }; | 318 | }; |
| 273 | InetSocketAddress listenAddress = | 319 | InetSocketAddress listenAddress = |
| 274 | - new InetSocketAddress(listenPortNumber); | 320 | + new InetSocketAddress(bgpPort); |
| 275 | 321 | ||
| 276 | serverBootstrap = new ServerBootstrap(channelFactory); | 322 | serverBootstrap = new ServerBootstrap(channelFactory); |
| 277 | // serverBootstrap.setOptions("reuseAddr", true); | 323 | // serverBootstrap.setOptions("reuseAddr", true); | ... | ... |
| ... | @@ -78,7 +78,7 @@ public class RouterAsyncArpTest { | ... | @@ -78,7 +78,7 @@ public class RouterAsyncArpTest { |
| 78 | hostService = createMock(HostService.class); | 78 | hostService = createMock(HostService.class); |
| 79 | 79 | ||
| 80 | BgpService bgpService = createMock(BgpService.class); | 80 | BgpService bgpService = createMock(BgpService.class); |
| 81 | - bgpService.start(anyObject(RouteListener.class), anyInt()); | 81 | + bgpService.start(anyObject(RouteListener.class)); |
| 82 | bgpService.stop(); | 82 | bgpService.stop(); |
| 83 | replay(bgpService); | 83 | replay(bgpService); |
| 84 | 84 | ... | ... |
| ... | @@ -84,7 +84,7 @@ public class RouterTest { | ... | @@ -84,7 +84,7 @@ public class RouterTest { |
| 84 | setUpHostService(); | 84 | setUpHostService(); |
| 85 | 85 | ||
| 86 | BgpService bgpService = createMock(BgpService.class); | 86 | BgpService bgpService = createMock(BgpService.class); |
| 87 | - bgpService.start(anyObject(RouteListener.class), anyInt()); | 87 | + bgpService.start(anyObject(RouteListener.class)); |
| 88 | bgpService.stop(); | 88 | bgpService.stop(); |
| 89 | replay(bgpService); | 89 | replay(bgpService); |
| 90 | 90 | ... | ... |
| ... | @@ -35,16 +35,21 @@ import org.onlab.packet.Ip4Address; | ... | @@ -35,16 +35,21 @@ import org.onlab.packet.Ip4Address; |
| 35 | import org.onlab.packet.Ip4Prefix; | 35 | import org.onlab.packet.Ip4Prefix; |
| 36 | import org.onosproject.routingapi.RouteListener; | 36 | import org.onosproject.routingapi.RouteListener; |
| 37 | import org.onosproject.routingapi.RouteUpdate; | 37 | import org.onosproject.routingapi.RouteUpdate; |
| 38 | +import org.osgi.service.component.ComponentContext; | ||
| 38 | 39 | ||
| 39 | import java.net.InetAddress; | 40 | import java.net.InetAddress; |
| 40 | import java.net.InetSocketAddress; | 41 | import java.net.InetSocketAddress; |
| 41 | import java.net.SocketAddress; | 42 | import java.net.SocketAddress; |
| 42 | import java.util.ArrayList; | 43 | import java.util.ArrayList; |
| 43 | import java.util.Collection; | 44 | import java.util.Collection; |
| 45 | +import java.util.Dictionary; | ||
| 44 | import java.util.LinkedList; | 46 | import java.util.LinkedList; |
| 45 | import java.util.concurrent.Executors; | 47 | import java.util.concurrent.Executors; |
| 46 | import java.util.concurrent.TimeUnit; | 48 | import java.util.concurrent.TimeUnit; |
| 47 | 49 | ||
| 50 | +import static org.easymock.EasyMock.createMock; | ||
| 51 | +import static org.easymock.EasyMock.expect; | ||
| 52 | +import static org.easymock.EasyMock.replay; | ||
| 48 | import static org.hamcrest.Matchers.hasSize; | 53 | import static org.hamcrest.Matchers.hasSize; |
| 49 | import static org.hamcrest.Matchers.is; | 54 | import static org.hamcrest.Matchers.is; |
| 50 | import static org.hamcrest.Matchers.notNullValue; | 55 | import static org.hamcrest.Matchers.notNullValue; |
| ... | @@ -252,7 +257,14 @@ public class BgpSessionManagerTest { | ... | @@ -252,7 +257,14 @@ public class BgpSessionManagerTest { |
| 252 | // | 257 | // |
| 253 | bgpSessionManager = new BgpSessionManager(); | 258 | bgpSessionManager = new BgpSessionManager(); |
| 254 | // NOTE: We use port 0 to bind on any available port | 259 | // NOTE: We use port 0 to bind on any available port |
| 255 | - bgpSessionManager.start(dummyRouteListener, 0); | 260 | + ComponentContext componentContext = createMock(ComponentContext.class); |
| 261 | + Dictionary<String, String> dictionary = createMock(Dictionary.class); | ||
| 262 | + expect(dictionary.get("bgpPort")).andReturn("0"); | ||
| 263 | + replay(dictionary); | ||
| 264 | + expect(componentContext.getProperties()).andReturn(dictionary); | ||
| 265 | + replay(componentContext); | ||
| 266 | + bgpSessionManager.activate(componentContext); | ||
| 267 | + bgpSessionManager.start(dummyRouteListener); | ||
| 256 | 268 | ||
| 257 | // Get the port number the BGP Session Manager is listening on | 269 | // Get the port number the BGP Session Manager is listening on |
| 258 | Channel serverChannel = TestUtils.getField(bgpSessionManager, | 270 | Channel serverChannel = TestUtils.getField(bgpSessionManager, | ... | ... |
| ... | @@ -55,11 +55,6 @@ | ... | @@ -55,11 +55,6 @@ |
| 55 | </dependency> | 55 | </dependency> |
| 56 | 56 | ||
| 57 | <dependency> | 57 | <dependency> |
| 58 | - <groupId>org.osgi</groupId> | ||
| 59 | - <artifactId>org.osgi.compendium</artifactId> | ||
| 60 | - </dependency> | ||
| 61 | - | ||
| 62 | - <dependency> | ||
| 63 | <groupId>org.onosproject</groupId> | 58 | <groupId>org.onosproject</groupId> |
| 64 | <artifactId>onlab-misc</artifactId> | 59 | <artifactId>onlab-misc</artifactId> |
| 65 | </dependency> | 60 | </dependency> | ... | ... |
| ... | @@ -18,7 +18,6 @@ package org.onosproject.sdnip; | ... | @@ -18,7 +18,6 @@ package org.onosproject.sdnip; |
| 18 | import org.apache.felix.scr.annotations.Activate; | 18 | 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; | ||
| 22 | import org.apache.felix.scr.annotations.Reference; | 21 | import org.apache.felix.scr.annotations.Reference; |
| 23 | import org.apache.felix.scr.annotations.ReferenceCardinality; | 22 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
| 24 | import org.apache.felix.scr.annotations.Service; | 23 | import org.apache.felix.scr.annotations.Service; |
| ... | @@ -34,11 +33,8 @@ import org.onosproject.net.host.HostService; | ... | @@ -34,11 +33,8 @@ import org.onosproject.net.host.HostService; |
| 34 | import org.onosproject.net.intent.IntentService; | 33 | import org.onosproject.net.intent.IntentService; |
| 35 | import org.onosproject.routingapi.RoutingService; | 34 | import org.onosproject.routingapi.RoutingService; |
| 36 | import org.onosproject.sdnip.config.SdnIpConfigurationReader; | 35 | import org.onosproject.sdnip.config.SdnIpConfigurationReader; |
| 37 | -import org.osgi.service.component.ComponentContext; | ||
| 38 | import org.slf4j.Logger; | 36 | import org.slf4j.Logger; |
| 39 | 37 | ||
| 40 | -import java.util.Dictionary; | ||
| 41 | - | ||
| 42 | import static org.slf4j.LoggerFactory.getLogger; | 38 | import static org.slf4j.LoggerFactory.getLogger; |
| 43 | 39 | ||
| 44 | /** | 40 | /** |
| ... | @@ -77,9 +73,6 @@ public class SdnIp implements SdnIpService { | ... | @@ -77,9 +73,6 @@ public class SdnIp implements SdnIpService { |
| 77 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 73 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 78 | protected NetworkConfigService networkConfigService; | 74 | protected NetworkConfigService networkConfigService; |
| 79 | 75 | ||
| 80 | - private static final int DEFAULT_BGP_PORT = 2000; | ||
| 81 | - private int bgpPort; | ||
| 82 | - | ||
| 83 | private IntentSynchronizer intentSynchronizer; | 76 | private IntentSynchronizer intentSynchronizer; |
| 84 | private SdnIpConfigurationReader config; | 77 | private SdnIpConfigurationReader config; |
| 85 | private PeerConnectivityManager peerConnectivity; | 78 | private PeerConnectivityManager peerConnectivity; |
| ... | @@ -90,9 +83,8 @@ public class SdnIp implements SdnIpService { | ... | @@ -90,9 +83,8 @@ public class SdnIp implements SdnIpService { |
| 90 | private ControllerNode localControllerNode; | 83 | private ControllerNode localControllerNode; |
| 91 | 84 | ||
| 92 | @Activate | 85 | @Activate |
| 93 | - protected void activate(ComponentContext context) { | 86 | + protected void activate() { |
| 94 | log.info("SDN-IP started"); | 87 | log.info("SDN-IP started"); |
| 95 | - readComponentConfiguration(context); | ||
| 96 | 88 | ||
| 97 | appId = coreService.registerApplication(SDN_IP_APP); | 89 | appId = coreService.registerApplication(SDN_IP_APP); |
| 98 | config = new SdnIpConfigurationReader(); | 90 | config = new SdnIpConfigurationReader(); |
| ... | @@ -117,9 +109,6 @@ public class SdnIp implements SdnIpService { | ... | @@ -117,9 +109,6 @@ public class SdnIp implements SdnIpService { |
| 117 | 109 | ||
| 118 | leadershipService.addListener(leadershipEventListener); | 110 | leadershipService.addListener(leadershipEventListener); |
| 119 | leadershipService.runForLeadership(appId.name()); | 111 | leadershipService.runForLeadership(appId.name()); |
| 120 | - | ||
| 121 | - log.info("Starting BGP with port {}", bgpPort); | ||
| 122 | - // TODO feed port information through to the BgpService | ||
| 123 | } | 112 | } |
| 124 | 113 | ||
| 125 | @Deactivate | 114 | @Deactivate |
| ... | @@ -134,33 +123,6 @@ public class SdnIp implements SdnIpService { | ... | @@ -134,33 +123,6 @@ public class SdnIp implements SdnIpService { |
| 134 | log.info("SDN-IP Stopped"); | 123 | log.info("SDN-IP Stopped"); |
| 135 | } | 124 | } |
| 136 | 125 | ||
| 137 | - /** | ||
| 138 | - * Extracts properties from the component configuration context. | ||
| 139 | - * | ||
| 140 | - * @param context the component context | ||
| 141 | - */ | ||
| 142 | - private void readComponentConfiguration(ComponentContext context) { | ||
| 143 | - Dictionary<?, ?> properties = context.getProperties(); | ||
| 144 | - try { | ||
| 145 | - String strPort = (String) properties.get("bgpPort"); | ||
| 146 | - if (strPort != null) { | ||
| 147 | - bgpPort = Integer.parseInt(strPort); | ||
| 148 | - } else { | ||
| 149 | - bgpPort = DEFAULT_BGP_PORT; | ||
| 150 | - } | ||
| 151 | - } catch (Exception e) { | ||
| 152 | - bgpPort = DEFAULT_BGP_PORT; | ||
| 153 | - } | ||
| 154 | - log.debug("BGP port is set to {}", bgpPort); | ||
| 155 | - } | ||
| 156 | - | ||
| 157 | - @Modified | ||
| 158 | - public void modified(ComponentContext context) { | ||
| 159 | - // Blank @Modified method to catch modifications to the context. | ||
| 160 | - // If no @Modified method exists, it seems @Activate is called again | ||
| 161 | - // when the context is modified. | ||
| 162 | - } | ||
| 163 | - | ||
| 164 | @Override | 126 | @Override |
| 165 | public void modifyPrimary(boolean isPrimary) { | 127 | public void modifyPrimary(boolean isPrimary) { |
| 166 | intentSynchronizer.leaderChanged(isPrimary); | 128 | intentSynchronizer.leaderChanged(isPrimary); | ... | ... |
-
Please register or login to post a comment