2 * Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.bgpmanager.thrift.server;
13 import org.apache.thrift.server.TServer;
14 import org.apache.thrift.server.TServer.Args;
15 import org.apache.thrift.server.TSimpleServer;
16 import org.apache.thrift.transport.TServerSocket;
17 import org.apache.thrift.transport.TServerTransport;
18 import org.opendaylight.bgpmanager.BgpManager;
19 import org.opendaylight.bgpmanager.BgpConfigurationManager;
20 import org.opendaylight.bgpmanager.FibDSWriter;
21 import org.opendaylight.bgpmanager.thrift.gen.BgpUpdater;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.fibmanager.rev150330.fibentries.VrfTables;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
26 public class BgpThriftService {
28 BgpManager bgpManager;
29 FibDSWriter fibDSWriter;
31 // to store copy fo FIB-VRF tables on QBGP restart.
32 public List<VrfTables> stale_vrfTables;
34 private static final Logger LOGGER =
35 LoggerFactory.getLogger(BgpThriftService.class);
37 public BgpThriftService(int ourPort, BgpManager bm) {
38 this.ourPort = ourPort;
40 fibDSWriter = bm.getFibWriter();
43 public class BgpUpdateServer implements Runnable, BgpUpdater.Iface {
45 public void BgpUpdateServer() {
50 BgpUpdater.Processor processor = new BgpUpdater.Processor(this);
51 TServerTransport transport = new TServerSocket(ourPort);
52 server = new TSimpleServer(new Args(transport).processor(processor));
54 } catch (Exception e) {
55 LOGGER.error("Exception in BGP Updater server"+e);
59 public void onUpdatePushRoute(String rd, String prefix, int plen,
60 String nexthop, int label) {
62 BgpConfigurationManager.onUpdatePushRoute(rd, prefix, plen, nexthop, label);
63 } catch (Throwable e) {
64 LOGGER.error("failed to handle update route " ,e);
68 public void onUpdateWithdrawRoute(String rd, String prefix, int plen) {
69 LOGGER.debug("Route del ** {} ** {}/{} ", rd, prefix, plen);
71 fibDSWriter.removeFibEntryFromDS(rd, prefix + "/" + plen);
72 } catch (Throwable e) {
73 LOGGER.error("failed to handle withdraw route " ,e);
77 public void onStartConfigResyncNotification() {
78 LOGGER.info("BGP (re)started");
80 bgpManager.bgpRestarted();
81 } catch (Throwable e) {
82 LOGGER.error("failed to handle onStartConfigResyncNotification " ,e);
86 public void onNotificationSendEvent(String prefix, byte errCode,
89 int subCode = errSubcode;
90 bgpManager.sendNotificationEvent(prefix, errCode, errSubcode);
98 thread = new Thread(new BgpUpdateServer());