mirror of
https://github.com/opennetworkinglab/onos.git
synced 2025-10-14 17:01:02 +02:00
Move BGP listen port configuration to BgpSessionManager component
Change-Id: I445bff180740fededacaa59441fc53332cc3d482
This commit is contained in:
parent
41349e9b46
commit
d24fafbc7c
@ -24,9 +24,8 @@ public interface BgpService {
|
|||||||
* Starts the BGP service.
|
* Starts the BGP service.
|
||||||
*
|
*
|
||||||
* @param routeListener listener to send route updates to
|
* @param routeListener listener to send route updates to
|
||||||
* @param bgpPort port number to listen on
|
|
||||||
*/
|
*/
|
||||||
void start(RouteListener routeListener, int bgpPort);
|
void start(RouteListener routeListener);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stops the BGP service.
|
* Stops the BGP service.
|
||||||
|
@ -54,6 +54,11 @@
|
|||||||
<artifactId>guava</artifactId>
|
<artifactId>guava</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.osgi</groupId>
|
||||||
|
<artifactId>org.osgi.compendium</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.karaf.shell</groupId>
|
<groupId>org.apache.karaf.shell</groupId>
|
||||||
<artifactId>org.apache.karaf.shell.console</artifactId>
|
<artifactId>org.apache.karaf.shell.console</artifactId>
|
||||||
|
@ -124,7 +124,7 @@ public class Router implements RoutingService {
|
|||||||
this.fibComponent = checkNotNull(listener);
|
this.fibComponent = checkNotNull(listener);
|
||||||
this.hostService.addListener(hostListener);
|
this.hostService.addListener(hostListener);
|
||||||
|
|
||||||
bgpService.start(new InternalRouteListener(), 2000);
|
bgpService.start(new InternalRouteListener());
|
||||||
|
|
||||||
bgpUpdatesExecutor.execute(new Runnable() {
|
bgpUpdatesExecutor.execute(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -15,7 +15,11 @@
|
|||||||
*/
|
*/
|
||||||
package org.onosproject.routing.bgp;
|
package org.onosproject.routing.bgp;
|
||||||
|
|
||||||
|
import org.osgi.service.component.ComponentContext;
|
||||||
|
import org.apache.felix.scr.annotations.Activate;
|
||||||
import org.apache.felix.scr.annotations.Component;
|
import org.apache.felix.scr.annotations.Component;
|
||||||
|
import org.apache.felix.scr.annotations.Deactivate;
|
||||||
|
import org.apache.felix.scr.annotations.Modified;
|
||||||
import org.apache.felix.scr.annotations.Service;
|
import org.apache.felix.scr.annotations.Service;
|
||||||
import org.jboss.netty.bootstrap.ServerBootstrap;
|
import org.jboss.netty.bootstrap.ServerBootstrap;
|
||||||
import org.jboss.netty.channel.Channel;
|
import org.jboss.netty.channel.Channel;
|
||||||
@ -40,6 +44,7 @@ import java.net.InetAddress;
|
|||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.net.SocketAddress;
|
import java.net.SocketAddress;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.Dictionary;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.ConcurrentMap;
|
import java.util.concurrent.ConcurrentMap;
|
||||||
|
|
||||||
@ -72,6 +77,47 @@ public class BgpSessionManager implements BgpInfoService, BgpService {
|
|||||||
|
|
||||||
private RouteListener routeListener;
|
private RouteListener routeListener;
|
||||||
|
|
||||||
|
private static final int DEFAULT_BGP_PORT = 2000;
|
||||||
|
private int bgpPort;
|
||||||
|
|
||||||
|
@Activate
|
||||||
|
protected void activate(ComponentContext context) {
|
||||||
|
readComponentConfiguration(context);
|
||||||
|
log.info("BgpSessionManager started");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deactivate
|
||||||
|
protected void deactivate() {
|
||||||
|
log.info("BgpSessionManager stopped");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extracts properties from the component configuration context.
|
||||||
|
*
|
||||||
|
* @param context the component context
|
||||||
|
*/
|
||||||
|
private void readComponentConfiguration(ComponentContext context) {
|
||||||
|
Dictionary<?, ?> properties = context.getProperties();
|
||||||
|
try {
|
||||||
|
String strPort = (String) properties.get("bgpPort");
|
||||||
|
if (strPort != null) {
|
||||||
|
bgpPort = Integer.parseInt(strPort);
|
||||||
|
} else {
|
||||||
|
bgpPort = DEFAULT_BGP_PORT;
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
bgpPort = DEFAULT_BGP_PORT;
|
||||||
|
}
|
||||||
|
log.debug("BGP port is set to {}", bgpPort);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Modified
|
||||||
|
public void modified(ComponentContext context) {
|
||||||
|
// Blank @Modified method to catch modifications to the context.
|
||||||
|
// If no @Modified method exists, it seems @Activate is called again
|
||||||
|
// when the context is modified.
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks whether the BGP Session Manager is shutdown.
|
* Checks whether the BGP Session Manager is shutdown.
|
||||||
*
|
*
|
||||||
@ -245,7 +291,7 @@ public class BgpSessionManager implements BgpInfoService, BgpService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void start(RouteListener routeListener, int listenPortNumber) {
|
public void start(RouteListener routeListener) {
|
||||||
log.debug("BGP Session Manager start.");
|
log.debug("BGP Session Manager start.");
|
||||||
isShutdown = false;
|
isShutdown = false;
|
||||||
|
|
||||||
@ -271,7 +317,7 @@ public class BgpSessionManager implements BgpInfoService, BgpService {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
InetSocketAddress listenAddress =
|
InetSocketAddress listenAddress =
|
||||||
new InetSocketAddress(listenPortNumber);
|
new InetSocketAddress(bgpPort);
|
||||||
|
|
||||||
serverBootstrap = new ServerBootstrap(channelFactory);
|
serverBootstrap = new ServerBootstrap(channelFactory);
|
||||||
// serverBootstrap.setOptions("reuseAddr", true);
|
// serverBootstrap.setOptions("reuseAddr", true);
|
||||||
|
@ -78,7 +78,7 @@ public class RouterAsyncArpTest {
|
|||||||
hostService = createMock(HostService.class);
|
hostService = createMock(HostService.class);
|
||||||
|
|
||||||
BgpService bgpService = createMock(BgpService.class);
|
BgpService bgpService = createMock(BgpService.class);
|
||||||
bgpService.start(anyObject(RouteListener.class), anyInt());
|
bgpService.start(anyObject(RouteListener.class));
|
||||||
bgpService.stop();
|
bgpService.stop();
|
||||||
replay(bgpService);
|
replay(bgpService);
|
||||||
|
|
||||||
|
@ -84,7 +84,7 @@ public class RouterTest {
|
|||||||
setUpHostService();
|
setUpHostService();
|
||||||
|
|
||||||
BgpService bgpService = createMock(BgpService.class);
|
BgpService bgpService = createMock(BgpService.class);
|
||||||
bgpService.start(anyObject(RouteListener.class), anyInt());
|
bgpService.start(anyObject(RouteListener.class));
|
||||||
bgpService.stop();
|
bgpService.stop();
|
||||||
replay(bgpService);
|
replay(bgpService);
|
||||||
|
|
||||||
|
@ -35,16 +35,21 @@ import org.onlab.packet.Ip4Address;
|
|||||||
import org.onlab.packet.Ip4Prefix;
|
import org.onlab.packet.Ip4Prefix;
|
||||||
import org.onosproject.routingapi.RouteListener;
|
import org.onosproject.routingapi.RouteListener;
|
||||||
import org.onosproject.routingapi.RouteUpdate;
|
import org.onosproject.routingapi.RouteUpdate;
|
||||||
|
import org.osgi.service.component.ComponentContext;
|
||||||
|
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.net.SocketAddress;
|
import java.net.SocketAddress;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.Dictionary;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import static org.easymock.EasyMock.createMock;
|
||||||
|
import static org.easymock.EasyMock.expect;
|
||||||
|
import static org.easymock.EasyMock.replay;
|
||||||
import static org.hamcrest.Matchers.hasSize;
|
import static org.hamcrest.Matchers.hasSize;
|
||||||
import static org.hamcrest.Matchers.is;
|
import static org.hamcrest.Matchers.is;
|
||||||
import static org.hamcrest.Matchers.notNullValue;
|
import static org.hamcrest.Matchers.notNullValue;
|
||||||
@ -252,7 +257,14 @@ public class BgpSessionManagerTest {
|
|||||||
//
|
//
|
||||||
bgpSessionManager = new BgpSessionManager();
|
bgpSessionManager = new BgpSessionManager();
|
||||||
// NOTE: We use port 0 to bind on any available port
|
// NOTE: We use port 0 to bind on any available port
|
||||||
bgpSessionManager.start(dummyRouteListener, 0);
|
ComponentContext componentContext = createMock(ComponentContext.class);
|
||||||
|
Dictionary<String, String> dictionary = createMock(Dictionary.class);
|
||||||
|
expect(dictionary.get("bgpPort")).andReturn("0");
|
||||||
|
replay(dictionary);
|
||||||
|
expect(componentContext.getProperties()).andReturn(dictionary);
|
||||||
|
replay(componentContext);
|
||||||
|
bgpSessionManager.activate(componentContext);
|
||||||
|
bgpSessionManager.start(dummyRouteListener);
|
||||||
|
|
||||||
// Get the port number the BGP Session Manager is listening on
|
// Get the port number the BGP Session Manager is listening on
|
||||||
Channel serverChannel = TestUtils.getField(bgpSessionManager,
|
Channel serverChannel = TestUtils.getField(bgpSessionManager,
|
||||||
|
@ -54,11 +54,6 @@
|
|||||||
<version>4.0</version>
|
<version>4.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.osgi</groupId>
|
|
||||||
<artifactId>org.osgi.compendium</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.onosproject</groupId>
|
<groupId>org.onosproject</groupId>
|
||||||
<artifactId>onlab-misc</artifactId>
|
<artifactId>onlab-misc</artifactId>
|
||||||
|
@ -18,7 +18,6 @@ package org.onosproject.sdnip;
|
|||||||
import org.apache.felix.scr.annotations.Activate;
|
import org.apache.felix.scr.annotations.Activate;
|
||||||
import org.apache.felix.scr.annotations.Component;
|
import org.apache.felix.scr.annotations.Component;
|
||||||
import org.apache.felix.scr.annotations.Deactivate;
|
import org.apache.felix.scr.annotations.Deactivate;
|
||||||
import org.apache.felix.scr.annotations.Modified;
|
|
||||||
import org.apache.felix.scr.annotations.Reference;
|
import org.apache.felix.scr.annotations.Reference;
|
||||||
import org.apache.felix.scr.annotations.ReferenceCardinality;
|
import org.apache.felix.scr.annotations.ReferenceCardinality;
|
||||||
import org.apache.felix.scr.annotations.Service;
|
import org.apache.felix.scr.annotations.Service;
|
||||||
@ -34,11 +33,8 @@ import org.onosproject.net.host.HostService;
|
|||||||
import org.onosproject.net.intent.IntentService;
|
import org.onosproject.net.intent.IntentService;
|
||||||
import org.onosproject.routingapi.RoutingService;
|
import org.onosproject.routingapi.RoutingService;
|
||||||
import org.onosproject.sdnip.config.SdnIpConfigurationReader;
|
import org.onosproject.sdnip.config.SdnIpConfigurationReader;
|
||||||
import org.osgi.service.component.ComponentContext;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
|
||||||
import java.util.Dictionary;
|
|
||||||
|
|
||||||
import static org.slf4j.LoggerFactory.getLogger;
|
import static org.slf4j.LoggerFactory.getLogger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -77,9 +73,6 @@ public class SdnIp implements SdnIpService {
|
|||||||
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
|
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
|
||||||
protected NetworkConfigService networkConfigService;
|
protected NetworkConfigService networkConfigService;
|
||||||
|
|
||||||
private static final int DEFAULT_BGP_PORT = 2000;
|
|
||||||
private int bgpPort;
|
|
||||||
|
|
||||||
private IntentSynchronizer intentSynchronizer;
|
private IntentSynchronizer intentSynchronizer;
|
||||||
private SdnIpConfigurationReader config;
|
private SdnIpConfigurationReader config;
|
||||||
private PeerConnectivityManager peerConnectivity;
|
private PeerConnectivityManager peerConnectivity;
|
||||||
@ -90,9 +83,8 @@ public class SdnIp implements SdnIpService {
|
|||||||
private ControllerNode localControllerNode;
|
private ControllerNode localControllerNode;
|
||||||
|
|
||||||
@Activate
|
@Activate
|
||||||
protected void activate(ComponentContext context) {
|
protected void activate() {
|
||||||
log.info("SDN-IP started");
|
log.info("SDN-IP started");
|
||||||
readComponentConfiguration(context);
|
|
||||||
|
|
||||||
appId = coreService.registerApplication(SDN_IP_APP);
|
appId = coreService.registerApplication(SDN_IP_APP);
|
||||||
config = new SdnIpConfigurationReader();
|
config = new SdnIpConfigurationReader();
|
||||||
@ -117,9 +109,6 @@ public class SdnIp implements SdnIpService {
|
|||||||
|
|
||||||
leadershipService.addListener(leadershipEventListener);
|
leadershipService.addListener(leadershipEventListener);
|
||||||
leadershipService.runForLeadership(appId.name());
|
leadershipService.runForLeadership(appId.name());
|
||||||
|
|
||||||
log.info("Starting BGP with port {}", bgpPort);
|
|
||||||
// TODO feed port information through to the BgpService
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deactivate
|
@Deactivate
|
||||||
@ -134,33 +123,6 @@ public class SdnIp implements SdnIpService {
|
|||||||
log.info("SDN-IP Stopped");
|
log.info("SDN-IP Stopped");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Extracts properties from the component configuration context.
|
|
||||||
*
|
|
||||||
* @param context the component context
|
|
||||||
*/
|
|
||||||
private void readComponentConfiguration(ComponentContext context) {
|
|
||||||
Dictionary<?, ?> properties = context.getProperties();
|
|
||||||
try {
|
|
||||||
String strPort = (String) properties.get("bgpPort");
|
|
||||||
if (strPort != null) {
|
|
||||||
bgpPort = Integer.parseInt(strPort);
|
|
||||||
} else {
|
|
||||||
bgpPort = DEFAULT_BGP_PORT;
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
bgpPort = DEFAULT_BGP_PORT;
|
|
||||||
}
|
|
||||||
log.debug("BGP port is set to {}", bgpPort);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Modified
|
|
||||||
public void modified(ComponentContext context) {
|
|
||||||
// Blank @Modified method to catch modifications to the context.
|
|
||||||
// If no @Modified method exists, it seems @Activate is called again
|
|
||||||
// when the context is modified.
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void modifyPrimary(boolean isPrimary) {
|
public void modifyPrimary(boolean isPrimary) {
|
||||||
intentSynchronizer.leaderChanged(isPrimary);
|
intentSynchronizer.leaderChanged(isPrimary);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user