LCOV - code coverage report
Current view: top level - vnsw/agent/controller - controller_init.cc (source / functions) Hit Total Coverage
Test: OpenSDN C/C++ coverage (all TARGET_SET jobs) Lines: 296 621 47.7 %
Date: 2026-06-08 02:02:55 Functions: 25 50 50.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
       3             :  */
       4             : 
       5             : #include <algorithm>
       6             : #include <base/string_util.h>
       7             : #include <base/logging.h>
       8             : #include <base/timer.h>
       9             : #include <base/contrail_ports.h>
      10             : #include <base/connection_info.h>
      11             : #include <base/address_util.h>
      12             : #include <net/tunnel_encap_type.h>
      13             : #include <sandesh/sandesh_trace.h>
      14             : #include <cmn/agent_cmn.h>
      15             : #include <cmn/xmpp_server_address_parser.h>
      16             : #include <xmpp/xmpp_init.h>
      17             : #include <pugixml/pugixml.hpp>
      18             : #include <oper/global_qos_config.h>
      19             : #include <oper/global_system_config.h>
      20             : #include <oper/vrf.h>
      21             : #include <oper/peer.h>
      22             : #include <oper/mirror_table.h>
      23             : #include <oper/multicast.h>
      24             : #include <controller/controller_types.h>
      25             : #include <controller/controller_init.h>
      26             : #include <controller/controller_timer.h>
      27             : #include <controller/controller_peer.h>
      28             : #include <controller/controller_ifmap.h>
      29             : #include <controller/controller_dns.h>
      30             : #include <controller/controller_export.h>
      31             : 
      32             : using namespace boost::asio;
      33             : 
      34             : SandeshTraceBufferPtr ControllerConnectionsTraceBuf(SandeshTraceBufferCreate(
      35             :     "ControllerConnections", 5000));
      36             : SandeshTraceBufferPtr ControllerInfoTraceBuf(SandeshTraceBufferCreate(
      37             :     "ControllerInfo", 5000));
      38             : SandeshTraceBufferPtr ControllerTxConfigTraceBuf1(SandeshTraceBufferCreate(
      39             :     "ControllerTxConfig_1", 5000));
      40             : SandeshTraceBufferPtr ControllerTxConfigTraceBuf2(SandeshTraceBufferCreate(
      41             :     "ControllerTxConfig_2", 5000));
      42             : SandeshTraceBufferPtr ControllerRouteWalkerTraceBuf(SandeshTraceBufferCreate(
      43             :     "ControllerRouteWalker", 5000));
      44             : SandeshTraceBufferPtr ControllerTraceBuf(SandeshTraceBufferCreate(
      45             :     "Controller", 5000));
      46             : SandeshTraceBufferPtr ControllerRxRouteMessageTraceBuf1(SandeshTraceBufferCreate(
      47             :     "ControllerRxRouteXmppMessage1", 5000));
      48             : SandeshTraceBufferPtr ControllerRxConfigMessageTraceBuf1(SandeshTraceBufferCreate(
      49             :     "ControllerRxConfigXmppMessage1", 5000));
      50             : SandeshTraceBufferPtr ControllerRxRouteMessageTraceBuf2(SandeshTraceBufferCreate(
      51             :     "ControllerRxRouteXmppMessage2", 5000));
      52             : SandeshTraceBufferPtr ControllerRxConfigMessageTraceBuf2(SandeshTraceBufferCreate(
      53             :     "ControllerRxConfigXmppMessage2", 5000));
      54             : SandeshTraceBufferPtr ControllerTxMessageTraceBuf1(SandeshTraceBufferCreate(
      55             :     "ControllerTxXmppMessage_1", 5000));
      56             : SandeshTraceBufferPtr ControllerTxMessageTraceBuf2(SandeshTraceBufferCreate(
      57             :     "ControllerTxXmppMessage_2", 5000));
      58             : 
      59           0 : ControllerReConfigData::ControllerReConfigData(std::string service_name,
      60           0 :                                                std::vector<string>server_list) :
      61           0 :     ControllerWorkQueueData(), service_name_(service_name),
      62           0 :     server_list_(server_list) {
      63           0 : }
      64             : 
      65           2 : ControllerDelPeerData::ControllerDelPeerData(AgentXmppChannel *channel) :
      66           2 :     ControllerWorkQueueData(), channel_(channel) {
      67           2 : }
      68             : 
      69           1 : VNController::VNController(Agent *agent)
      70           1 :     : agent_(agent), multicast_sequence_number_(0),
      71           1 :     work_queue_(agent->task_scheduler()->GetTaskId("Agent::ControllerXmpp"), 0,
      72             :                 boost::bind(&VNController::ControllerWorkQueueProcess, this,
      73             :                             _1)),
      74           3 :     fabric_multicast_label_range_(), xmpp_channel_down_cb_(),
      75           4 :     disconnect_(false) {
      76           1 :     work_queue_.set_name("Controller Queue");
      77           3 :     for (uint8_t count = 0; count < MAX_XMPP_SERVERS; count++) {
      78           2 :         timed_out_channels_[count].clear();
      79             :     }
      80           1 :     delpeer_walks_.clear();
      81           1 :     work_queue_.set_disable(true);
      82           1 : }
      83             : 
      84           7 : VNController::~VNController() {
      85           1 :     work_queue_.Shutdown();
      86          10 : }
      87             : 
      88           2 : void VNController::FillMcastLabelRange(uint32_t *start_idx,
      89             :                                        uint32_t *end_idx,
      90             :                                        uint8_t idx) const {
      91             :     // Multicast labels required by both control nodes
      92           2 :     uint32_t max_mc_labels = 2 * (agent_->vrouter_max_vrfs());
      93             :     // Multicast label count per control node
      94           2 :     uint32_t mc_label_count = 0;
      95           2 :     uint32_t vrouter_max_labels = agent_->vrouter_max_labels();
      96             : 
      97           2 :     if (max_mc_labels + MIN_UNICAST_LABEL_RANGE < vrouter_max_labels) {
      98           2 :         mc_label_count = agent_->vrouter_max_vrfs();
      99             :     } else {
     100           0 :         mc_label_count = (vrouter_max_labels - MIN_UNICAST_LABEL_RANGE)/2;
     101             :     }
     102             : 
     103           2 :     *start_idx = vrouter_max_labels - ((idx + 1) * mc_label_count);
     104           2 :     *end_idx = (vrouter_max_labels - ((idx) * mc_label_count) - 1);
     105           2 : }
     106             : 
     107           2 : void VNController::SetAgentMcastLabelRange(uint8_t idx) {
     108           2 :     uint32_t start = 0;
     109           2 :     uint32_t end = 0;
     110           2 :     std::stringstream str;
     111             : 
     112             :     //Logic for multicast label allocation
     113             :     //  1> Reserve minimum 4k label for unicast
     114             :     //  2> In the remaining label space
     115             :     //       * Try allocating labels equal to no. of VN
     116             :     //         for each control node
     117             :     //       * If label space is not huge enough
     118             :     //         split remaining unicast label for both control
     119             :     //         node
     120             :     //  Remaining label would be used for unicast mpls label
     121           2 :     if (agent_->vrouter_max_labels() <=  MIN_UNICAST_LABEL_RANGE) {
     122           0 :         str << 0 << "-" << 0;
     123           0 :         fabric_multicast_label_range_[idx].start = 0;
     124           0 :         fabric_multicast_label_range_[idx].end = 0;
     125           0 :         fabric_multicast_label_range_[idx].fabric_multicast_label_range_str =
     126           0 :             str.str();
     127           0 :         return;
     128             :     }
     129             : 
     130           2 :     FillMcastLabelRange(&start, &end, idx);
     131           2 :     str << start << "-" << end;
     132             : 
     133           2 :     agent_->mpls_table()->ReserveMulticastLabel(start, end, idx);
     134           2 :     fabric_multicast_label_range_[idx].start = start;
     135           2 :     fabric_multicast_label_range_[idx].end = end;
     136           2 :     fabric_multicast_label_range_[idx].fabric_multicast_label_range_str =
     137           2 :         str.str();
     138           2 : }
     139             : 
     140           2 : void VNController::SetDscpConfig(XmppChannelConfig *xmpp_cfg) const {
     141           2 :     GlobalQosConfig* qos = NULL;
     142           2 :     if (agent_->oper_db()) {
     143           2 :         qos = agent_->oper_db()->global_qos_config();
     144             :     }
     145           2 :     if (qos && qos->control_dscp() != GlobalQosConfig::kInvalidDscp) {
     146           2 :         xmpp_cfg->dscp_value = qos->control_dscp();
     147             :     } else {
     148           0 :         xmpp_cfg->dscp_value = 0;
     149             :     }
     150           2 : }
     151             : 
     152           1 : void VNController::XmppServerConnect() {
     153             : 
     154           1 :     uint8_t count = 0;
     155             : 
     156           1 :     if (agent_->is_vhost_interface_up() == false) {
     157             :         // Sleep 100 msec to avoid cpu hogging.
     158           0 :         usleep(100000);
     159             :         ControllerConnectRetryDataType data(
     160           0 :             new ControllerConnectRetryData(true, false));
     161             :         ControllerWorkQueueDataType base_data =
     162           0 :             boost::static_pointer_cast<ControllerWorkQueueData>(data);
     163           0 :         work_queue_.Enqueue(base_data);
     164           0 :         return;
     165           0 :     }
     166             : 
     167           3 :     while (count < MAX_XMPP_SERVERS) {
     168           2 :         SetAgentMcastLabelRange(count);
     169           2 :         if (!agent_->controller_ifmap_xmpp_server(count).empty()) {
     170             : 
     171           1 :             AgentXmppChannel *ch = agent_->controller_xmpp_channel(count);
     172           1 :             if (ch) {
     173             :                 // Channel is created, do not disturb
     174           0 :                 CONTROLLER_CONNECTIONS_TRACE(DiscoveryConnection,
     175             :                     "XMPP Server is already present, ignore reconfig response",
     176             :                     count, ch->GetXmppServer(), "");
     177           0 :                 count++;
     178           0 :                 continue;
     179             :             }
     180             : 
     181           1 :             boost::system::error_code ec;
     182           1 :             XmppChannelConfig *xmpp_cfg = new XmppChannelConfig(true);
     183           1 :             xmpp_cfg->ToAddr = XmppInit::kControlNodeJID;
     184           1 :             xmpp_cfg->FromAddr = agent_->agent_name();
     185           1 :             xmpp_cfg->NodeAddr = XmppInit::kPubSubNS;
     186             :             FastConvergenceParameters fc_params =
     187           1 :                 agent_->oper_db()->global_system_config()->fc_params();
     188           1 :             if (fc_params.enable) {
     189           0 :                 xmpp_cfg->xmpp_hold_time = fc_params.xmpp_hold_time;
     190             :             }
     191             :             /*
     192             :              * Since TcpServer asserts in bind failure,
     193             :              * dont need to assert in failure.
     194             :              * Also TorAgent can be run anywhere. so vhost0
     195             :              * ip binding should not be done for TorAgent.
     196             :              */
     197           1 :             Ip4Address local_endpoint;
     198           1 :             if (!agent_->tor_agent_enabled() && !agent_->isMockMode()) {
     199           1 :                 local_endpoint = agent_->compute_node_ip();
     200           1 :                 xmpp_cfg->local_endpoint.address(AddressFromString(
     201           2 :                     local_endpoint.to_string(), &ec));
     202             :             }
     203           1 :             if (agent_->test_mode()) {
     204           1 :                 local_endpoint = Ip4Address::from_string("127.0.0.1", ec);
     205           1 :                 xmpp_cfg->local_endpoint.address(AddressFromString(
     206           2 :                     local_endpoint.to_string(), &ec));
     207             :             }
     208           1 :             xmpp_cfg->endpoint.address(AddressFromString(
     209           1 :                 agent_->controller_ifmap_xmpp_server(count), &ec));
     210           1 :             assert(ec.value() == 0);
     211           1 :             xmpp_cfg->auth_enabled = agent_->xmpp_auth_enabled();
     212           1 :             if (xmpp_cfg->auth_enabled) {
     213           0 :                 xmpp_cfg->path_to_server_cert =  agent_->xmpp_server_cert();
     214           0 :                 xmpp_cfg->path_to_server_priv_key =  agent_->xmpp_server_key();
     215           0 :                 xmpp_cfg->path_to_ca_cert =  agent_->xmpp_ca_cert();
     216             :             }
     217           1 :             uint16_t port = agent_->controller_ifmap_xmpp_port(count);
     218           1 :             xmpp_cfg->endpoint.port(port);
     219           1 :             SetDscpConfig(xmpp_cfg);
     220           1 :             xmpp_cfg->xmlns = agent_->subcluster_name();
     221             : 
     222             :             // Create Xmpp Client
     223           1 :             XmppClient *client = new XmppClient(agent_->event_manager(), xmpp_cfg);
     224             : 
     225           1 :             XmppInit *xmpp = new XmppInit();
     226           1 :             xmpp->AddXmppChannelConfig(xmpp_cfg);
     227             :             // create bgp peer
     228             :             AgentXmppChannel *bgp_peer = new AgentXmppChannel(agent_,
     229           1 :                               agent_->controller_ifmap_xmpp_server(count),
     230           1 :                               fabric_multicast_label_range(count).
     231           1 :                                                fabric_multicast_label_range_str,
     232           1 :                               count);
     233           1 :             client->RegisterConnectionEvent(xmps::BGP,
     234             :                boost::bind(&AgentXmppChannel::XmppClientChannelEvent,
     235             :                            bgp_peer, _2));
     236           1 :             xmpp->InitClient(client);
     237             : 
     238             :             XmppChannel *channel = client->
     239           1 :                 FindChannel(XmppInit::kControlNodeJID);
     240           1 :             assert(channel);
     241           1 :             channel->RegisterRxMessageTraceCallback(
     242             :                              boost::bind(&VNController::RxXmppMessageTrace,
     243           1 :                                          this, bgp_peer->GetXmppServerIdx(),
     244             :                                          _1, _2, _3, _4, _5));
     245           1 :             channel->RegisterTxMessageTraceCallback(
     246             :                              boost::bind(&VNController::TxXmppMessageTrace,
     247           1 :                                          this, bgp_peer->GetXmppServerIdx(),
     248             :                                          _1, _2, _3, _4, _5));
     249           1 :             bgp_peer->RegisterXmppChannel(channel);
     250             : 
     251           1 :             bgp_peer->UpdateConnectionInfo(channel->GetPeerState());
     252             : 
     253             :             // create ifmap peer
     254             :             AgentIfMapXmppChannel *ifmap_peer =
     255           1 :                 new AgentIfMapXmppChannel(agent_, channel, count);
     256             : 
     257           1 :             agent_->set_controller_xmpp_channel(bgp_peer, count);
     258           1 :             agent_->set_ifmap_xmpp_channel(ifmap_peer, count);
     259           1 :             agent_->set_controller_ifmap_xmpp_client(client, count);
     260           1 :             agent_->set_controller_ifmap_xmpp_init(xmpp, count);
     261             :         }
     262           2 :         count++;
     263             :     }
     264             : }
     265             : 
     266           1 : void VNController::DnsXmppServerConnect() {
     267             : 
     268           1 :     if (agent_->GetDnsProto() == NULL) {
     269           0 :         return;
     270             :     }
     271             : 
     272           1 :     if (agent_->is_vhost_interface_up() == false) {
     273             :         // Sleep 100 msec to avoid cpu hogging.
     274           0 :         usleep(100000);
     275             :         ControllerConnectRetryDataType data(
     276           0 :             new ControllerConnectRetryData(false, true));
     277             :         ControllerWorkQueueDataType base_data =
     278           0 :             boost::static_pointer_cast<ControllerWorkQueueData>(data);
     279           0 :         work_queue_.Enqueue(base_data);
     280           0 :         return;
     281           0 :     }
     282             : 
     283           1 :     uint8_t count = 0;
     284           3 :     while (count < MAX_XMPP_SERVERS) {
     285           2 :         if (!agent_->dns_server(count).empty()) {
     286             : 
     287           1 :             AgentDnsXmppChannel *ch = agent_->dns_xmpp_channel(count);
     288           1 :             if (ch) {
     289             :                 // Channel is up and running, do not disturb
     290           0 :                 CONTROLLER_CONNECTIONS_TRACE(DiscoveryConnection,
     291             :                     "DNS Server is already present, ignore reconfig response",
     292             :                     count, ch->GetXmppServer(), "");
     293           0 :                 count++;
     294           0 :                 continue;
     295             :             }
     296             : 
     297             :             // XmppChannel Configuration
     298           1 :             boost::system::error_code ec;
     299           1 :             XmppChannelConfig *xmpp_cfg_dns = new XmppChannelConfig(true);
     300           1 :             xmpp_cfg_dns->ToAddr = XmppInit::kDnsNodeJID;
     301           1 :             xmpp_cfg_dns->FromAddr = agent_->agent_name() + "/dns";
     302           1 :             xmpp_cfg_dns->NodeAddr = "";
     303             :             /*
     304             :              * Since TcpServer asserts in bind failure,
     305             :              * dont need to assert in failure.
     306             :              * Also TorAgent can be run anywhere. so vhost0
     307             :              * ip binding should not be done for TorAgent.
     308             :              */
     309           1 :             Ip4Address local_endpoint;
     310           1 :             if (!agent_->tor_agent_enabled() && !agent_->isMockMode()) {
     311           1 :                 local_endpoint = agent_->compute_node_ip();
     312           1 :                 xmpp_cfg_dns->local_endpoint.address(AddressFromString(
     313           2 :                     local_endpoint.to_string(), &ec));
     314             :             }
     315           1 :             if (agent_->test_mode()) {
     316           1 :                 local_endpoint = Ip4Address::from_string("127.0.0.1", ec);
     317           1 :                 xmpp_cfg_dns->local_endpoint.address(AddressFromString(
     318           2 :                     local_endpoint.to_string(), &ec));
     319             :             }
     320           1 :             xmpp_cfg_dns->endpoint.address(AddressFromString(
     321           1 :                 agent_->dns_server(count), &ec));
     322           1 :             assert(ec.value() == 0);
     323           1 :             if (agent_->xmpp_dns_test_mode()) {
     324           0 :                 xmpp_cfg_dns->endpoint.port(agent_->dns_server_port(count));
     325             :             } else {
     326           1 :                 xmpp_cfg_dns->endpoint.port(ContrailPorts::DnsXmpp());
     327             :             }
     328           1 :             xmpp_cfg_dns->auth_enabled = agent_->dns_auth_enabled();
     329           1 :             if (xmpp_cfg_dns->auth_enabled) {
     330           0 :                 xmpp_cfg_dns->path_to_server_cert = agent_->xmpp_server_cert();
     331           0 :                 xmpp_cfg_dns->path_to_server_priv_key =  agent_->xmpp_server_key();
     332           0 :                 xmpp_cfg_dns->path_to_ca_cert =  agent_->xmpp_ca_cert();
     333             :             }
     334           1 :             SetDscpConfig(xmpp_cfg_dns);
     335             : 
     336             :             // Create Xmpp Client
     337           1 :             XmppClient *client_dns = new XmppClient(agent_->event_manager(),
     338           1 :                                                     xmpp_cfg_dns);
     339             : 
     340           1 :             XmppInit *xmpp_dns = new XmppInit();
     341             :             // create dns peer
     342             :             AgentDnsXmppChannel *dns_peer = new AgentDnsXmppChannel(agent_,
     343           1 :                                                 agent_->dns_server(count),
     344           1 :                                                 count);
     345           1 :             client_dns->RegisterConnectionEvent(xmps::DNS,
     346             :                 boost::bind(&AgentDnsXmppChannel::XmppClientChannelEvent,
     347             :                             dns_peer, _2));
     348             : 
     349           1 :             xmpp_dns->AddXmppChannelConfig(xmpp_cfg_dns);
     350           1 :             xmpp_dns->InitClient(client_dns);
     351             : 
     352           1 :             XmppChannel *channel_dns = client_dns->FindChannel(
     353             :                                                    XmppInit::kDnsNodeJID);
     354           1 :             assert(channel_dns);
     355           1 :             dns_peer->RegisterXmppChannel(channel_dns);
     356             : 
     357             : 
     358           1 :             dns_peer->UpdateConnectionInfo(channel_dns->GetPeerState());
     359           1 :             agent_->set_dns_xmpp_client(client_dns, count);
     360           1 :             agent_->set_dns_xmpp_channel(dns_peer, count);
     361           1 :             agent_->set_dns_xmpp_init(xmpp_dns, count);
     362             :         }
     363           2 :         count++;
     364             :     }
     365             : }
     366             : 
     367           1 : void VNController::Connect() {
     368             :     /* Connect to Control-Node Xmpp Server */
     369           1 :     controller_list_chksum_ = Agent::GetInstance()->GetControllerlistChksum();
     370           1 :     XmppServerConnect();
     371             : 
     372             :     /* Connect to DNS Xmpp Server */
     373           1 :     dns_list_chksum_ = Agent::GetInstance()->GetDnslistChksum();
     374           1 :     DnsXmppServerConnect();
     375             : 
     376             :     /* Inits */
     377           1 :     agent_->controller()->increment_multicast_sequence_number();
     378           1 :     agent_->set_cn_mcast_builder(NULL);
     379           1 :     agent_ifmap_vm_export_.reset(new AgentIfMapVmExport(agent_));
     380           1 :     agent_->oper_db()->global_system_config()->gres_parameters().
     381           1 :         Register(boost::bind(&VNController::GracefulRestartConfigListener,
     382             :                              this));
     383           1 : }
     384             : 
     385             : // Disconnect on agent shutdown.
     386           1 : void VNController::XmppServerDisConnect() {
     387             :     XmppClient *cl;
     388           1 :     uint8_t count = 0;
     389           1 :     disconnect_ = true;
     390           3 :     while (count < MAX_XMPP_SERVERS) {
     391           2 :         if ((cl = agent_->controller_ifmap_xmpp_client(count)) != NULL) {
     392           0 :             cl->Shutdown();
     393             :         }
     394             :         // Delpeer walk for channel slot = count
     395           2 :         StartDelPeerWalk(agent_->controller_xmpp_channel_ref(count));
     396             :         // Delpeer walk done for timedout channels which used to represent this
     397             :         // slot.
     398           2 :         FlushTimedOutChannels(count);
     399           2 :         count ++;
     400             :     }
     401           1 : }
     402             : 
     403             : // Test-only code to verify that xmpp timeout has been updated correctly.
     404           0 : bool VNController::VerifyXmppServerTimeout(uint32_t to) {
     405             :     XmppClient *cl;
     406           0 :     uint8_t count = 0;
     407           0 :     while (count < MAX_XMPP_SERVERS) {
     408           0 :         if ((cl = agent_->controller_ifmap_xmpp_client(count)) != NULL) {
     409           0 :             if (to != cl->XmppTimeOut(XmppInit::kControlNodeJID))
     410           0 :                 return false;
     411             :         }
     412           0 :         count++;
     413             :     }
     414           0 :     return true;
     415             : }
     416             : 
     417             : // Update agent-controller xmpp connection witth new timeout value.
     418           0 : void VNController::XmppServerUpdate(uint8_t xmpp_hold_time) {
     419             :     XmppClient *cl;
     420           0 :     uint8_t count = 0;
     421           0 :     while (count < MAX_XMPP_SERVERS) {
     422           0 :         if ((cl = agent_->controller_ifmap_xmpp_client(count)) != NULL) {
     423           0 :             cl->UpdateTimeOut(xmpp_hold_time, XmppInit::kControlNodeJID);
     424             :         }
     425           0 :         count ++;
     426             :     }
     427           0 : }
     428             : 
     429           1 : void VNController::DnsXmppServerDisConnect() {
     430             :     XmppClient *cl;
     431           1 :     uint8_t count = 0;
     432           3 :     while (count < MAX_XMPP_SERVERS) {
     433           2 :         if ((cl = agent_->dns_xmpp_client(count)) != NULL) {
     434           0 :             cl->Shutdown();
     435             :         }
     436           2 :         count ++;
     437             :     }
     438           1 : }
     439             : 
     440           4 : void VNController::StartDelPeerWalk(AgentXmppChannelPtr ptr) {
     441           4 :     if (!ptr.get())
     442           2 :         return;
     443             : 
     444           2 :     ptr.get()->bgp_peer_id()->DelPeerRoutes(
     445             :         boost::bind(&VNController::DelPeerWalkDone, this, ptr.get()),
     446             :         ptr.get()->sequence_number());
     447           2 :     delpeer_walks_.push_back(ptr);
     448             : }
     449             : 
     450             : //During delete of xmpp channel, check if BGP peer is deleted.
     451             : //If not agent never got a channel down state and is being removed
     452             : //as it is not part of discovery list.
     453             : //Artificially inject NOT_READY in agent xmpp channel.
     454           2 : void VNController::DeleteAgentXmppChannel(uint8_t idx) {
     455           2 :     AgentXmppChannel *channel = agent_->controller_xmpp_channel(idx);
     456           2 :     if (!channel)
     457           0 :         return;
     458             : 
     459           2 :     BgpPeer *bgp_peer = channel->bgp_peer_id();
     460           2 :     if (bgp_peer != NULL) {
     461             :         //Defer delete of channel till delete walk of bgp peer is over.
     462             :         //Till walk is over, unregister as table listener is not done and there
     463             :         //may be notifications(which will be ignored though, but valid pointer is
     464             :         //needed). BgpPeer destructor will handle deletion of channel.
     465           2 :         AgentXmppChannel::HandleAgentXmppClientChannelEvent(channel,
     466             :                                                             xmps::NOT_READY);
     467           2 :         channel->Unregister();
     468             :     }
     469             :     //Every delete of channel should delete flow of bgp-as-a-service,
     470             :     //which is using this CN.
     471           2 :     if (xmpp_channel_down_cb_.empty() == false) {
     472           2 :         xmpp_channel_down_cb_(idx);
     473             :     }
     474             : }
     475             : 
     476             : //Trigger shutdown and cleanup of routes for the client
     477           1 : void VNController::DisConnect() {
     478           1 :     XmppServerDisConnect();
     479           1 :     DnsXmppServerDisConnect();
     480           1 : }
     481             : 
     482           2 : void VNController::Cleanup() {
     483           2 :     uint8_t count = 0;
     484             :     XmppClient *cl;
     485           6 :     while (count < MAX_XMPP_SERVERS) {
     486           4 :         if ((cl = agent_->controller_ifmap_xmpp_client(count)) != NULL) {
     487           1 :             DisConnectControllerIfmapServer(count);
     488             :         }
     489           4 :         if ((cl = agent_->dns_xmpp_client(count)) != NULL) {
     490           1 :             DisConnectDnsServer(count);
     491             :         }
     492           4 :         count++;
     493             :     }
     494             : 
     495           2 :     agent_->controller()->increment_multicast_sequence_number();
     496           2 :     agent_->set_cn_mcast_builder(NULL);
     497           2 :     agent_ifmap_vm_export_.reset();
     498           2 : }
     499             : 
     500             : 
     501           0 : AgentXmppChannel *VNController::FindAgentXmppChannel(
     502             :                                 const std::string &server_ip) {
     503             : 
     504           0 :     uint8_t count = 0;
     505           0 :     while (count < MAX_XMPP_SERVERS) {
     506           0 :         AgentXmppChannel *ch = agent_->controller_xmpp_channel(count);
     507           0 :         if (ch && (ch->GetXmppServer().compare(server_ip) == 0)) {
     508           0 :             return ch;
     509             :         }
     510           0 :         count++;
     511             :     }
     512             : 
     513           0 :     return NULL;
     514             : }
     515             : 
     516           2 : const string VNController::MakeConnectionPrefix(bool is_dns) const {
     517           2 :     string name_prefix;
     518           2 :     if (is_dns) {
     519           1 :         name_prefix = agent_->xmpp_dns_server_prefix();
     520             :     } else {
     521           1 :         name_prefix = agent_->xmpp_control_node_prefix();
     522             :     }
     523           2 :     return name_prefix;
     524           0 : }
     525             : 
     526           2 : void VNController::DeleteConnectionInfo(const std::string &addr, bool is_dns)
     527             :                                         const {
     528           2 :     boost::asio::ip::tcp::endpoint ep;
     529           2 :     boost::system::error_code ec;
     530           2 :     ep.address(AddressFromString(addr, &ec));
     531           2 :     const string name =  ep.address().to_string();
     532           2 :     const string &name_prefix = MakeConnectionPrefix(is_dns);
     533           4 :     agent_->connection_state()->Delete(process::ConnectionType::XMPP,
     534           4 :                                            name_prefix + name);
     535           2 : }
     536             : 
     537           2 : void VNController::DelPeerWalkDone(AgentXmppChannel* ptr) {
     538           2 :     ControllerDelPeerDataType data(new ControllerDelPeerData(ptr));
     539             :     ControllerWorkQueueDataType base_data =
     540           2 :         boost::static_pointer_cast<ControllerWorkQueueData>(data);
     541           2 :     work_queue_.Enqueue(base_data);
     542           2 : }
     543             : 
     544           2 : void VNController::DelPeerWalkDoneProcess(AgentXmppChannel *channel) {
     545           2 :     DynamicPeer::ProcessDelete(channel->bgp_peer_id());
     546           2 :     for (AgentXmppChannelListIter it = delpeer_walks_.begin();
     547           2 :          it != delpeer_walks_.end(); it++) {
     548           2 :         if ((*it).get() == channel) {
     549           2 :             delpeer_walks_.erase(it);
     550           2 :             break;
     551             :         }
     552             :     }
     553             :     //delete channel;
     554           2 :     if (disconnect_ & delpeer_walks_.empty())
     555           1 :         Cleanup();
     556           2 : }
     557             : 
     558           6 : void VNController::FlushTimedOutChannels(uint8_t idx) {
     559           6 :     for (AgentXmppChannelListIter it = timed_out_channels_[idx].begin();
     560           8 :          it != timed_out_channels_[idx].end(); it++) {
     561           2 :         StartDelPeerWalk((*it));
     562             :     }
     563           6 :     timed_out_channels_[idx].clear();
     564           6 : }
     565             : 
     566           2 : void VNController::DisConnectControllerIfmapServer(uint8_t idx) {
     567             : 
     568             :     // Managed Delete of XmppClient object, which deletes the
     569             :     // dependent XmppClientConnection object and
     570             :     // scoped XmppChannel object
     571           2 :     XmppClient *xc = agent_->controller_ifmap_xmpp_client(idx);
     572             :     //In case of UT xc can be NULL
     573           2 :     if (!agent_->test_mode() || xc) {
     574           1 :         xc->UnRegisterConnectionEvent(xmps::BGP);
     575           1 :         xc->Shutdown(); // ManagedDelete
     576             :     }
     577           2 :     agent_->set_controller_ifmap_xmpp_client(NULL, idx);
     578             : 
     579             :     //cleanup AgentXmppChannel
     580           2 :     DeleteAgentXmppChannel(idx);
     581             :     //Trigger removal from service inuse list for discovery
     582             :     //cleanup AgentIfmapXmppChannel
     583           2 :     timed_out_channels_[idx].push_back(agent_->controller_xmpp_channel_ref(idx));
     584           2 :     agent_->controller_xmpp_channel(idx)->UpdateConnectionInfo(xmps::TIMEDOUT);
     585           2 :     agent_->reset_controller_xmpp_channel(idx);
     586             : 
     587           2 :     delete agent_->ifmap_xmpp_channel(idx);
     588           2 :     agent_->set_ifmap_xmpp_channel(NULL, idx);
     589             : 
     590           2 :     if (!agent_->test_mode() || xc) {
     591           1 :         agent_->controller_ifmap_xmpp_init(idx)->Reset();
     592           1 :         delete agent_->controller_ifmap_xmpp_init(idx);
     593           1 :         agent_->set_controller_ifmap_xmpp_init(NULL, idx);
     594           1 :         DeleteConnectionInfo(agent_->controller_ifmap_xmpp_server(idx), false);
     595             :     }
     596             : 
     597           2 :     agent_->reset_controller_ifmap_xmpp_server(idx);
     598           2 : }
     599             : 
     600           0 : bool VNController::AgentReConfigXmppServerConnectedExists(
     601             :                                  const std::string &server_ip,
     602             :                                  std::vector<std::string> resp) {
     603             : 
     604           0 :     std::vector<std::string>::iterator iter;
     605           0 :     int8_t count = -1;
     606           0 :     int8_t min_iter = std::min(static_cast<int>(resp.size()), MAX_XMPP_SERVERS);
     607           0 :     for (iter = resp.begin(); ++count < min_iter; iter++) {
     608           0 :         std::vector<string> servers;
     609           0 :         boost::split(servers, *iter, boost::is_any_of(":"));
     610           0 :         if (servers[0].compare(server_ip) == 0) {
     611           0 :             return true;
     612             :         }
     613           0 :     }
     614           0 :     return false;
     615             : }
     616             : 
     617             : 
     618           0 : void VNController::ReConnectXmppServer() {
     619             : 
     620             :     std::vector<string> controller_list =
     621           0 :         Agent::GetInstance()->GetControllerlist();
     622             : 
     623             :     ControllerReConfigDataType data(new ControllerReConfigData(
     624             :         g_vns_constants.XMPP_SERVER_DISCOVERY_SERVICE_NAME,
     625           0 :         controller_list));
     626             :     ControllerWorkQueueDataType base_data =
     627           0 :         boost::static_pointer_cast<ControllerWorkQueueData>(data);
     628           0 :     work_queue_.Enqueue(base_data);
     629           0 : }
     630             : 
     631           0 : void VNController::ReConnectDnsServer() {
     632             : 
     633             :     std::vector<string> dns_list =
     634           0 :         Agent::GetInstance()->GetDnslist();
     635             : 
     636             :     ControllerReConfigDataType data(new ControllerReConfigData(
     637             :         g_vns_constants.DNS_SERVER_DISCOVERY_SERVICE_NAME,
     638           0 :         dns_list));
     639             :     ControllerWorkQueueDataType base_data =
     640           0 :         boost::static_pointer_cast<ControllerWorkQueueData>(data);
     641           0 :     work_queue_.Enqueue(base_data);
     642           0 : }
     643             : 
     644           0 : void VNController::ReConnect() {
     645             : 
     646           0 :     if (controller_list_chksum_ !=
     647           0 :         Agent::GetInstance()->GetControllerlistChksum()) {
     648             : 
     649           0 :         controller_list_chksum_ =
     650           0 :             Agent::GetInstance()->GetControllerlistChksum();
     651             : 
     652           0 :         ReConnectXmppServer();
     653             :     }
     654             : 
     655           0 :     if (dns_list_chksum_ !=
     656           0 :         Agent::GetInstance()->GetDnslistChksum()) {
     657             : 
     658           0 :         dns_list_chksum_ =
     659           0 :             Agent::GetInstance()->GetDnslistChksum();
     660             : 
     661           0 :         ReConnectDnsServer();
     662             :     }
     663           0 : }
     664             : 
     665           0 : bool VNController::ApplyControllerReConfigInternal(std::vector<string> resp) {
     666           0 :     XmppServerAddressParser addressParser(XMPP_SERVER_PORT, MAX_XMPP_SERVERS);
     667           0 :     std::vector<string>::iterator iter;
     668           0 :     int8_t count = -1;
     669             : 
     670             :     /* Apply only MAX_XMPP_SERVERS from list as the list is ordered */
     671           0 :     int8_t min_iter = std::min(static_cast<int>(resp.size()), MAX_XMPP_SERVERS);
     672           0 :     for (iter = resp.begin(); ++count < min_iter; iter++) {
     673           0 :         std::string server_ip;
     674             :         uint16_t server_port;
     675           0 :         addressParser.ParseAddress(*iter, &server_ip, &server_port);
     676           0 :         std::string str_port = integerToString(server_port);
     677             : 
     678           0 :         CONTROLLER_CONNECTIONS_TRACE(DiscoveryConnection, "XMPP ReConfig Apply Server Ip",
     679             :             count, server_ip, str_port);
     680             : 
     681           0 :         AgentXmppChannel *chnl = FindAgentXmppChannel(server_ip);
     682           0 :         if (chnl) {
     683           0 :             if (chnl->GetXmppChannel() &&
     684           0 :                 chnl->GetXmppChannel()->GetPeerState() == xmps::READY) {
     685           0 :                 CONTROLLER_CONNECTIONS_TRACE(DiscoveryConnection,
     686             :                     " XMPP ReConfig Server is READY and running, ignore", count,
     687             :                     chnl->GetXmppServer(), "");
     688           0 :                 continue;
     689             :             } else {
     690           0 :                 CONTROLLER_CONNECTIONS_TRACE(DiscoveryConnection,
     691             :                     " XMPP ReConfig Server is NOT_READY, ignore", count,
     692             :                     chnl->GetXmppServer(), "");
     693           0 :                 continue;
     694             :             }
     695             : 
     696             :         } else {
     697             : 
     698           0 :             for (uint8_t xs_idx = 0; xs_idx < MAX_XMPP_SERVERS; xs_idx++) {
     699             : 
     700           0 :                 if (agent_->controller_ifmap_xmpp_server(xs_idx).empty()) {
     701             : 
     702           0 :                     CONTROLLER_CONNECTIONS_TRACE(DiscoveryConnection,
     703             :                         "Set Xmpp ReConfig Channel",
     704             :                         xs_idx, server_ip, str_port);
     705             : 
     706           0 :                     agent_->set_controller_ifmap_xmpp_server(server_ip, xs_idx);
     707           0 :                     agent_->set_controller_ifmap_xmpp_port(server_port, xs_idx);
     708           0 :                     break;
     709             : 
     710           0 :                 } else if (agent_->controller_xmpp_channel(xs_idx)) {
     711             : 
     712           0 :                     if (AgentReConfigXmppServerConnectedExists(
     713           0 :                         agent_->controller_ifmap_xmpp_server(xs_idx), resp)) {
     714             : 
     715           0 :                         CONTROLLER_CONNECTIONS_TRACE(DiscoveryConnection,
     716             :                             "Retain Xmpp ReConfig Channel ", xs_idx,
     717             :                              agent_->controller_ifmap_xmpp_server(xs_idx), "");
     718           0 :                         continue;
     719             :                     }
     720             : 
     721           0 :                     CONTROLLER_CONNECTIONS_TRACE(DiscoveryConnection,
     722             :                         "ReSet Xmpp ReConfig Channel ", xs_idx,
     723             :                         agent_->controller_ifmap_xmpp_server(xs_idx),
     724             :                         server_ip);
     725             : 
     726           0 :                     DisConnectControllerIfmapServer(xs_idx);
     727           0 :                     agent_->set_controller_ifmap_xmpp_server(server_ip, xs_idx);
     728           0 :                     agent_->set_controller_ifmap_xmpp_port(server_port, xs_idx);
     729           0 :                     break;
     730             :                 }
     731             :             }
     732             :         }
     733           0 :     }
     734             : 
     735           0 :     XmppServerConnect();
     736           0 :     return true;
     737             : }
     738             : 
     739           0 : AgentDnsXmppChannel *VNController::FindAgentDnsXmppChannel(
     740             :                                    const std::string &server_ip) {
     741             : 
     742           0 :     uint8_t count = 0;
     743           0 :     while (count < MAX_XMPP_SERVERS) {
     744           0 :         AgentDnsXmppChannel *ch = agent_->dns_xmpp_channel(count);
     745           0 :         if (ch && (ch->GetXmppServer().compare(server_ip) == 0)) {
     746           0 :             return ch;
     747             :         }
     748           0 :         count++;
     749             :     }
     750             : 
     751           0 :     return NULL;
     752             : }
     753             : 
     754           1 : void VNController::DisConnectDnsServer(uint8_t idx) {
     755             : 
     756             :     // Managed Delete of XmppClient object, which deletes the
     757             :     // dependent XmppClientConnection object and
     758             :     // scoped_ptr XmppChannel
     759           1 :     XmppClient *xc = agent_->dns_xmpp_client(idx);
     760           1 :     xc->UnRegisterConnectionEvent(xmps::DNS);
     761           1 :     xc->Shutdown();
     762           1 :     agent_->set_dns_xmpp_client(NULL, idx);
     763             : 
     764             :     //cleanup AgentDnsXmppChannel
     765           1 :     delete agent_->dns_xmpp_channel(idx);
     766           1 :     agent_->set_dns_xmpp_channel(NULL, idx);
     767             : 
     768           1 :     agent_->dns_xmpp_init(idx)->Reset();
     769           1 :     delete agent_->dns_xmpp_init(idx);
     770           1 :     agent_->set_dns_xmpp_init(NULL, idx);
     771             : 
     772           1 :     DeleteConnectionInfo(agent_->dns_server(idx), true);
     773           1 :     agent_->reset_dns_server(idx);
     774           1 : }
     775             : 
     776           0 : bool VNController::ApplyDnsReConfigInternal(std::vector<string> resp) {
     777           0 :     XmppServerAddressParser addressParser(XMPP_DNS_SERVER_PORT, MAX_XMPP_SERVERS);
     778           0 :     std::vector<string>::iterator iter;
     779           0 :     int8_t count = -1;
     780             : 
     781             :     /* Apply only MAX_XMPP_SERVERS from list as the list is ordered */
     782           0 :     int8_t min_iter = std::min(static_cast<int>(resp.size()), MAX_XMPP_SERVERS);
     783           0 :     for (iter = resp.begin(); ++count < min_iter; iter++) {
     784           0 :         std::string server_ip;
     785             :         uint16_t server_port;
     786           0 :         addressParser.ParseAddress(*iter, &server_ip, &server_port);
     787           0 :         std::string str_port = integerToString(server_port);
     788             : 
     789           0 :         CONTROLLER_CONNECTIONS_TRACE(DiscoveryConnection,
     790             :             "DNS Server ReConfig Apply Server Ip",
     791             :             count, server_ip, str_port);
     792             : 
     793           0 :         AgentDnsXmppChannel *chnl = FindAgentDnsXmppChannel(server_ip);
     794           0 :         if (chnl) {
     795           0 :             if (chnl->GetXmppChannel() &&
     796           0 :                 chnl->GetXmppChannel()->GetPeerState() == xmps::READY) {
     797           0 :                 CONTROLLER_CONNECTIONS_TRACE(DiscoveryConnection,
     798             :                     "DNS Server is READY and running, ignore", count,
     799             :                     chnl->GetXmppServer(), "");
     800           0 :                 continue;
     801             :             } else {
     802           0 :                 CONTROLLER_CONNECTIONS_TRACE(DiscoveryConnection,
     803             :                     "DNS Server is NOT_READY, ignore", count,
     804             :                     chnl->GetXmppServer(), "");
     805           0 :                 continue;
     806             :             }
     807             :         } else {
     808             : 
     809           0 :             for (uint8_t xs_idx = 0; xs_idx < MAX_XMPP_SERVERS; xs_idx++) {
     810             : 
     811           0 :                 if (agent_->dns_server(xs_idx).empty()) {
     812             : 
     813           0 :                     CONTROLLER_CONNECTIONS_TRACE(DiscoveryConnection,
     814             :                         "Set Dns Xmpp Channel ",
     815             :                         xs_idx, server_ip, str_port);
     816             : 
     817           0 :                     agent_->set_dns_server(server_ip, xs_idx);
     818           0 :                     agent_->set_dns_server_port(server_port, xs_idx);
     819           0 :                     break;
     820             : 
     821           0 :                 } else if (agent_->dns_xmpp_channel(xs_idx)) {
     822             : 
     823           0 :                     if (AgentReConfigXmppServerConnectedExists(
     824           0 :                         agent_->dns_server(xs_idx), resp)) {
     825             : 
     826           0 :                         CONTROLLER_CONNECTIONS_TRACE(DiscoveryConnection,
     827             :                             "Retain Dns Xmpp Channel ", xs_idx,
     828             :                             agent_->dns_server(xs_idx), "");
     829           0 :                         continue;
     830             :                     }
     831             : 
     832           0 :                     CONTROLLER_CONNECTIONS_TRACE(DiscoveryConnection,
     833             :                         "ReSet Dns ReConfigChannel ", xs_idx,
     834             :                         agent_->dns_server(xs_idx), server_ip);
     835             : 
     836           0 :                     DisConnectDnsServer(xs_idx);
     837           0 :                     agent_->set_dns_server(server_ip, xs_idx);
     838           0 :                     agent_->set_dns_server_port(server_port, xs_idx);
     839           0 :                     break;
     840             :                }
     841             :            }
     842             :         }
     843           0 :     }
     844             : 
     845           0 :     DnsXmppServerConnect();
     846           0 :     return true;
     847             : }
     848             : 
     849             : /*
     850             :  * Returns the number of active agentxmppchannel.
     851             :  * AgentXmppChannel is identified as active if it has a BGP peer
     852             :  * attached to it.
     853             :  */
     854           0 : uint8_t VNController::ActiveXmppConnectionCount() {
     855           0 :     uint8_t active_xmpps = 0;
     856           0 :     for (uint8_t count = 0; count < MAX_XMPP_SERVERS; count++) {
     857           0 :         AgentXmppChannel *xc = agent_->controller_xmpp_channel(count);
     858           0 :        if (xc) {
     859             :            // Check if AgentXmppChannel has BGP peer
     860           0 :            if (xc->bgp_peer_id() != NULL)
     861           0 :                active_xmpps++;
     862             :        }
     863             :     }
     864             : 
     865           0 :     return active_xmpps;
     866             : }
     867             : 
     868           0 : AgentXmppChannel *VNController::GetActiveXmppChannel() {
     869           0 :     for (uint8_t count = 0; count < MAX_XMPP_SERVERS; count++) {
     870           0 :         AgentXmppChannel *xc = agent_->controller_xmpp_channel(count);
     871           0 :        if (xc) {
     872             :            // Check if AgentXmppChannel has BGP peer
     873           0 :            if (xc->bgp_peer_id() != NULL)
     874           0 :                return xc;
     875             :        }
     876             :     }
     877             : 
     878           0 :     return NULL;
     879             : }
     880             : 
     881           0 : void VNController::StartEndOfRibTxTimer() {
     882           0 :     uint8_t count = 0;
     883           0 :     while (count < MAX_XMPP_SERVERS) {
     884           0 :         if (agent_->controller_xmpp_channel(count))
     885           0 :             agent_->controller_xmpp_channel(count)->end_of_rib_tx_timer()->
     886           0 :                 Start(agent_->controller_xmpp_channel(count));
     887           0 :         count++;
     888             :     }
     889           0 : }
     890             : 
     891           0 : void VNController::StopEndOfRibTx() {
     892           0 :     uint8_t count = 0;
     893           0 :     while (count < MAX_XMPP_SERVERS) {
     894           0 :         if (agent_->controller_xmpp_channel(count)) {
     895           0 :             agent_->controller_xmpp_channel(count)->
     896           0 :                 end_of_rib_tx_timer()->Cancel();
     897           0 :             agent_->controller_xmpp_channel(count)->StopEndOfRibTxWalker();
     898             :         }
     899           0 :         count++;
     900             :     }
     901           0 : }
     902             : 
     903          27 : bool VNController::ControllerWorkQueueProcess(ControllerWorkQueueDataType data) {
     904             : 
     905             :     //DOM processing
     906             :     ControllerXmppDataType derived_xmpp_data =
     907          27 :         boost::dynamic_pointer_cast<ControllerXmppData>(data);
     908          27 :     if (derived_xmpp_data) {
     909           0 :         return XmppMessageProcess(derived_xmpp_data);
     910             :     }
     911             : 
     912             :     // VM Subscription message
     913             :     ControllerVmiSubscribeData *subscribe_data =
     914          27 :         boost::dynamic_pointer_cast<ControllerVmiSubscribeData>(data.get());
     915          27 :     if (subscribe_data && agent_ifmap_vm_export_.get()) {
     916          24 :         agent_ifmap_vm_export_->VmiEvent(subscribe_data);
     917          24 :         return true;
     918             :     }
     919             : 
     920             :     //ReConfig
     921             :     ControllerReConfigDataType reconfig_data =
     922           3 :         boost::dynamic_pointer_cast<ControllerReConfigData>(data);
     923           3 :     if (reconfig_data) {
     924           0 :         if (reconfig_data->service_name_.compare(
     925           0 :             g_vns_constants.XMPP_SERVER_DISCOVERY_SERVICE_NAME) == 0) {
     926           0 :             return ApplyControllerReConfigInternal(reconfig_data->server_list_);
     927           0 :         } else if (reconfig_data->service_name_.compare(
     928           0 :             g_vns_constants.DNS_SERVER_DISCOVERY_SERVICE_NAME) == 0) {
     929           0 :             return ApplyDnsReConfigInternal(reconfig_data->server_list_);
     930             :         } else {
     931           0 :             LOG(ERROR, "Unknown Service Name %s" << reconfig_data->service_name_);
     932           0 :             return true;
     933             :         }
     934             :     }
     935             : 
     936             :     ControllerDelPeerDataType del_peer_data =
     937           3 :         boost::dynamic_pointer_cast<ControllerDelPeerData>(data);
     938           3 :     if (del_peer_data) {
     939           2 :         DelPeerWalkDoneProcess(del_peer_data.get()->channel());
     940           2 :         return true;
     941             :     }
     942             : 
     943             :     AgentIfMapXmppChannel::EndOfConfigDataPtr end_of_config_data =
     944           1 :         boost::dynamic_pointer_cast<EndOfConfigData>(data);
     945           2 :     if (end_of_config_data &&
     946           1 :         (agent_->ifmap_xmpp_channel(agent_->ifmap_active_xmpp_server_index()) ==
     947           2 :          end_of_config_data->channel())) {
     948           0 :         end_of_config_data->channel()->ProcessEndOfConfig();
     949           0 :         return true;
     950             :     }
     951             : 
     952             :     //Connection retry for servers
     953             :     ControllerConnectRetryDataType connect_retry_data =
     954           1 :         boost::dynamic_pointer_cast<ControllerConnectRetryData>(data);
     955           1 :     if (connect_retry_data) {
     956           0 :         if (connect_retry_data->connect_xmpp_server()) {
     957           0 :             XmppServerConnect();
     958           0 :             return true;
     959             :         }
     960           0 :         if (connect_retry_data->connect_dns_xmpp_server()) {
     961           0 :             DnsXmppServerConnect();
     962           0 :             return true;
     963             :         }
     964             :     }
     965             : 
     966           1 :     return true;
     967          27 : }
     968             : 
     969           0 : bool VNController::XmppMessageProcess(ControllerXmppDataType data) {
     970           0 :     if (data->peer_id() == xmps::BGP) {
     971           0 :         if (data->config()) {
     972             :             AgentXmppChannel *peer =
     973           0 :                 agent_->controller_xmpp_channel(data->channel_id());
     974           0 :             if (peer) {
     975           0 :                 peer->ReceiveBgpMessage(data->dom());
     976             :             }
     977             :         } else {
     978             :             AgentXmppChannel *peer =
     979           0 :                 agent_->controller_xmpp_channel(data->channel_id());
     980           0 :             if (peer) {
     981           0 :                 AgentXmppChannel::HandleAgentXmppClientChannelEvent(peer,
     982             :                                                                     data->peer_state());
     983             :             }
     984             :         }
     985           0 :     } else if (data->peer_id() == xmps::CONFIG) {
     986             :         AgentIfMapXmppChannel *peer =
     987           0 :             agent_->ifmap_xmpp_channel(data->channel_id());
     988           0 :         if (peer) {
     989           0 :             peer->ReceiveConfigMessage(data->dom());
     990             :         }
     991           0 :     } else if (data->peer_id() == xmps::DNS) {
     992             :         AgentDnsXmppChannel *peer =
     993           0 :             agent_->dns_xmpp_channel(data->channel_id());
     994           0 :         if (data->config()) {
     995           0 :             if (peer) {
     996           0 :                 peer->ReceiveDnsMessage(data->dom());
     997             :             }
     998             :         } else {
     999           0 :             if (peer) {
    1000           0 :                 AgentDnsXmppChannel::HandleXmppClientChannelEvent(peer,
    1001             :                                                                   data->peer_state());
    1002             :             }
    1003             :         }
    1004             :     }
    1005             : 
    1006           0 :     return true;
    1007             : }
    1008             : 
    1009          25 : void VNController::Enqueue(ControllerWorkQueueDataType data) {
    1010          25 :     work_queue_.Enqueue(data);
    1011          25 : }
    1012             : 
    1013           0 : bool VNController::RxXmppMessageTrace(uint8_t peer_index,
    1014             :                                       const std::string &to_address,
    1015             :                                       int port, int size,
    1016             :                                       const std::string &msg,
    1017             :                                       const XmppStanza::XmppMessage *xmppmsg) {
    1018           0 :     const std::string &to = xmppmsg->to;
    1019           0 :     if (to.find(XmppInit::kBgpPeer) != string::npos) {
    1020           0 :         CONTROLLER_RX_ROUTE_MESSAGE_TRACE(Message, peer_index, to_address,
    1021             :                                            port, size, msg);
    1022           0 :         return true;
    1023           0 :     } else if (to.find(XmppInit::kConfigPeer) != string::npos) {
    1024           0 :         CONTROLLER_RX_CONFIG_MESSAGE_TRACE(Message, peer_index, to_address,
    1025             :                                            port, size, msg);
    1026           0 :         return true;
    1027             :     }
    1028           0 :     return false;
    1029             : }
    1030             : 
    1031           0 : bool VNController::TxXmppMessageTrace(uint8_t peer_index,
    1032             :                                       const std::string &to_address,
    1033             :                                       int port, int size,
    1034             :                                       const std::string &msg,
    1035             :                                       const XmppStanza::XmppMessage *xmppmsg) {
    1036           0 :     CONTROLLER_TX_MESSAGE_TRACE(Message, peer_index, to_address,
    1037             :                                 port, size, msg);
    1038           0 :     return true;
    1039             : }
    1040             : 
    1041           0 : bool VNController::IsWorkQueueEmpty() const {
    1042           0 :     return (work_queue_.IsQueueEmpty() == 0);
    1043             : }
    1044             : 
    1045           0 : MacAddress VNController::GetTunnelMac(const autogen::EnetNextHopType &nh) {
    1046           0 :     return MacAddress(nh.mac);
    1047             : }
    1048             : 
    1049           0 : MacAddress VNController::GetTunnelMac(const autogen::NextHopType &nh) {
    1050           0 :     return MacAddress();
    1051             : }
    1052             : 
    1053           0 : TunnelType::TypeBmap VNController::GetTypeBitmap
    1054             : (const autogen::EnetTunnelEncapsulationListType &encap) {
    1055           0 :     TunnelType::TypeBmap bmap = 0;
    1056           0 :     for (autogen::EnetTunnelEncapsulationListType::const_iterator iter =
    1057           0 :          encap.begin(); iter != encap.end(); iter++) {
    1058             :         TunnelEncapType::Encap encap =
    1059           0 :             TunnelEncapType::TunnelEncapFromString(*iter);
    1060           0 :         if ((encap == TunnelEncapType::GRE) ||
    1061             :             (encap == TunnelEncapType::MPLS_O_GRE))
    1062           0 :             bmap |= (1 << TunnelType::MPLS_GRE);
    1063           0 :         if (encap == TunnelEncapType::MPLS_O_UDP)
    1064           0 :             bmap |= (1 << TunnelType::MPLS_UDP);
    1065           0 :         if (encap == TunnelEncapType::VXLAN)
    1066           0 :             bmap |= (1 << TunnelType::VXLAN);
    1067           0 :         if (encap == TunnelEncapType::NATIVE)
    1068           0 :             bmap |= (1 << TunnelType::NATIVE);
    1069           0 :         if (encap == TunnelEncapType::MPLS)
    1070           0 :             bmap |= (1 << TunnelType::MPLS_OVER_MPLS);
    1071             :     }
    1072           0 :     return bmap;
    1073             : }
    1074             : 
    1075           0 : TunnelType::TypeBmap VNController::GetTypeBitmap
    1076             : (const autogen::TunnelEncapsulationListType &encap) {
    1077           0 :     TunnelType::TypeBmap bmap = 0;
    1078           0 :     for (autogen::TunnelEncapsulationListType::const_iterator iter =
    1079           0 :          encap.begin(); iter != encap.end(); iter++) {
    1080             :         TunnelEncapType::Encap encap =
    1081           0 :             TunnelEncapType::TunnelEncapFromString(*iter);
    1082           0 :         if ((encap == TunnelEncapType::GRE) ||
    1083             :             (encap == TunnelEncapType::MPLS_O_GRE))
    1084           0 :             bmap |= (1 << TunnelType::MPLS_GRE);
    1085           0 :         if (encap == TunnelEncapType::MPLS_O_UDP)
    1086           0 :             bmap |= (1 << TunnelType::MPLS_UDP);
    1087           0 :         if (encap == TunnelEncapType::NATIVE)
    1088           0 :             bmap |= (1 << TunnelType::NATIVE);
    1089           0 :         if (encap == TunnelEncapType::MPLS)
    1090           0 :             bmap |= (1 << TunnelType::MPLS_OVER_MPLS);
    1091             :     }
    1092           0 :     return bmap;
    1093             : }
    1094             : 
    1095           0 : TunnelType::TypeBmap VNController::GetTypeBitmap
    1096             : (const autogen::McastTunnelEncapsulationListType &encap) {
    1097           0 :     TunnelType::TypeBmap bmap = 0;
    1098           0 :     for (autogen::McastTunnelEncapsulationListType::const_iterator iter =
    1099           0 :          encap.begin(); iter != encap.end(); iter++) {
    1100             :         TunnelEncapType::Encap encap =
    1101           0 :             TunnelEncapType::TunnelEncapFromString(*iter);
    1102           0 :         if ((encap == TunnelEncapType::GRE) ||
    1103             :             (encap == TunnelEncapType::MPLS_O_GRE))
    1104           0 :             bmap |= (1 << TunnelType::MPLS_GRE);
    1105           0 :         if (encap == TunnelEncapType::MPLS_O_UDP)
    1106           0 :             bmap |= (1 << TunnelType::MPLS_UDP);
    1107             :     }
    1108           0 :     return bmap;
    1109             : }
    1110             : 
    1111           0 : void VNController::GracefulRestartConfigListener() {
    1112           0 :     bool enable = agent_->oper_db()->global_system_config()->
    1113           0 :         gres_parameters().IsEnabled();
    1114             : 
    1115           0 :     for (uint8_t i = 0; i < MAX_XMPP_SERVERS; i++) {
    1116           0 :         if (agent_->ifmap_xmpp_channel(i)) {
    1117           0 :             agent_->ifmap_xmpp_channel(i)->end_of_config_timer()->
    1118           0 :                 GresEnabled(enable);
    1119             :         }
    1120           0 :         if (agent_->controller_xmpp_channel(i)) {
    1121           0 :             agent_->controller_xmpp_channel(i)->end_of_rib_tx_timer()->
    1122           0 :                 GresEnabled(enable);
    1123           0 :             agent_->controller_xmpp_channel(i)->end_of_rib_rx_timer()->
    1124           0 :                 GresEnabled(enable);
    1125             :         }
    1126             :     }
    1127           0 : }

Generated by: LCOV version 1.14