- private BgpConfiguration bgpConfiguration = new BgpConfiguration();
- private BgpRouter bgpThriftClient;
- private BgpThriftService bgpThriftService;
- private boolean isBgpInitialized = false;
- private boolean hasBgpServiceStarted = false;
- private String bgpHost;
- private int bgpPort;
-
-
- private String getCustomConfig(String var, String def) {
- Bundle b = FrameworkUtil.getBundle(this.getClass());
- BundleContext context = null;
- if (b != null) {
- context = b.getBundleContext();
- }
- if (context != null)
- return context.getProperty(var);
- else
- return def;
-
- }
-
- private void initializeBGPCommunication() {
- //start our side of thrift server
- bgpThriftService = new BgpThriftService(this, fibDSWriter);
- bgpThriftService.start();
-
- //start bgp thrift client connection
- bgpThriftClient = new BgpRouter();
-
- bgpHost = getCustomConfig(BgpConstants.BGP_SPEAKER_HOST_NAME, BgpConstants.DEFAULT_BGP_HOST_NAME);
- bgpPort = BgpConstants.DEFAULT_BGP_THRIFT_PORT;
-
- configureBgpServer(bgpHost, bgpPort);
- try {
- connectToServer(bgpHost, bgpPort);
- } catch (Exception e) {
- return;
- }
-
- isBgpInitialized = true;
- //notify(); //notify all threads waiting for bgp init
-
- }
-
- public synchronized void waitForBgpInit() {
- if(!isBgpInitialized) {
- try {
- wait();
- } catch (InterruptedException e) {
- s_logger.error("InterruptedException while waiting for Bgp connection to initialize");
- return;
- }
- }
- }
-
- public void startBgpService() throws TException {
- if(bgpThriftClient == null) {
- s_logger.info("Start Bgp Service - bgpThriftClient is null. Unable to start BGP service.");
- return;
- }
-
- // Now try start bgp - if bgp is already Active, it will tell us, nothing to do then
- try {
- bgpThriftClient.startBgp((int)bgpConfiguration.getAsNum(), bgpConfiguration.getRouterId());
- s_logger.info("Started BGP with AS number " + (int)bgpConfiguration.getAsNum() + " and router id " + bgpConfiguration.getRouterId());
- } catch (BgpRouterException be) {
- if(be.getErrorCode() == BgpRouterException.BGP_ERR_ACTIVE) {
- s_logger.info("bgp server already active");
- return;
- }
- else if(be.getErrorCode() == BgpRouterException.BGP_ERR_NOT_INITED) {
- s_logger.error("bgp server connection not initialized.");
- reInitConn();
- return;
- }
- else {
- s_logger.error("application error while starting bgp server " + be.getErrorCode());
- return;
- }
-
- } catch (TException t) {
- s_logger.error("Could not set up thrift connection with bgp server");
- //s_logger.trace("Transport error while starting bgp server ", t);
- reInitConn();
- throw t;
- } catch (Exception e) {
- s_logger.error("Error while starting bgp server");
- //s_logger.trace("Bgp Service not started due to exception", e);
- return;
- }
-
- hasBgpServiceStarted = true;