LCOV - code coverage report
Current view: top level - vnsw/agent/controller - controller_init.h (source / functions) Hit Total Coverage
Test: OpenSDN C/C++ coverage (all TARGET_SET jobs) Lines: 21 39 53.8 %
Date: 2026-11-09 02:10:49 Functions: 16 32 50.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
       3             :  * Copyright Contributors to the OpenSDN project
       4             :  */
       5             : 
       6             : #ifndef __VNSW_CONTROLLER_INIT_HPP__
       7             : #define __VNSW_CONTROLLER_INIT_HPP__
       8             : 
       9             : #include <sandesh/sandesh_trace.h>
      10             : #include <boost/scoped_ptr.hpp>
      11             : #include <boost/shared_ptr.hpp>
      12             : #include <controller/controller_timer.h>
      13             : #include "xmpp/xmpp_channel.h"
      14             : #include <xmpp_enet_types.h>
      15             : #include <xmpp_unicast_types.h>
      16             : #include <xmpp_multicast_types.h>
      17             : #include <oper/route_common.h>
      18             : 
      19             : class AgentXmppChannel;
      20             : class AgentDnsXmppChannel;
      21             : class AgentIfMapVmExport;
      22             : class XmlBase;
      23             : class XmppChannelConfig;
      24             : 
      25             : class ControllerWorkQueueData {
      26             : public:
      27         370 :     ControllerWorkQueueData() {}
      28         370 :     virtual ~ControllerWorkQueueData() {}
      29             : 
      30             : private:
      31             :     DISALLOW_COPY_AND_ASSIGN(ControllerWorkQueueData);
      32             : };
      33             : 
      34             : class ControllerConnectRetryData : public ControllerWorkQueueData {
      35             : public:
      36           0 :     ControllerConnectRetryData(
      37           0 :         bool retry_xmpp_server, bool retry_dns_xmpp_server) :
      38             :         ControllerWorkQueueData(),
      39           0 :         retry_xmpp_server_(retry_xmpp_server),
      40           0 :         retry_dns_xmpp_server_(retry_dns_xmpp_server) {}
      41           0 :     virtual ~ControllerConnectRetryData() {}
      42             : 
      43           0 :     bool connect_xmpp_server() const {return retry_xmpp_server_;}
      44           0 :     bool connect_dns_xmpp_server() const {return retry_dns_xmpp_server_;}
      45             : 
      46             : private:
      47             :     bool retry_xmpp_server_;
      48             :     bool retry_dns_xmpp_server_;
      49             :     DISALLOW_COPY_AND_ASSIGN(ControllerConnectRetryData);
      50             : };
      51             : 
      52             : class ControllerXmppData : public ControllerWorkQueueData {
      53             : public:
      54           0 :     ControllerXmppData(xmps::PeerId peer_id, xmps::PeerState peer_state,
      55             :                        uint8_t channel_id, std::unique_ptr<XmlBase> dom,
      56           0 :                        bool config) :
      57             :         ControllerWorkQueueData(),
      58           0 :         peer_id_(peer_id), peer_state_(peer_state), channel_id_(channel_id),
      59           0 :         dom_(std::move(dom)), config_(config) { }
      60           0 :     virtual ~ControllerXmppData() { }
      61             : 
      62           0 :     xmps::PeerId peer_id() const {return peer_id_;}
      63           0 :     xmps::PeerState peer_state() const {return peer_state_;}
      64           0 :     uint8_t channel_id() const {return channel_id_;}
      65           0 :     std::unique_ptr<XmlBase> dom() {return std::move(dom_);}
      66           0 :     bool config() const {return config_;}
      67             : 
      68             : private:
      69             :     xmps::PeerId peer_id_;
      70             :     xmps::PeerState peer_state_;
      71             :     uint8_t channel_id_;
      72             :     std::unique_ptr<XmlBase> dom_;
      73             :     bool config_;
      74             :     DISALLOW_COPY_AND_ASSIGN(ControllerXmppData);
      75             : };
      76             : 
      77             : class ControllerVmiSubscribeData : public ControllerWorkQueueData {
      78             : public:
      79         330 :     ControllerVmiSubscribeData(bool del, const boost::uuids::uuid &vmi_uuid,
      80         330 :                                const boost::uuids::uuid &vm_uuid) :
      81         330 :         del_(del), vmi_uuid_(vmi_uuid), vm_uuid_(vm_uuid) { }
      82         660 :     virtual ~ControllerVmiSubscribeData() {}
      83             : 
      84             :     bool del_;
      85             :     boost::uuids::uuid vmi_uuid_;
      86             :     boost::uuids::uuid vm_uuid_;
      87             : };
      88             : 
      89             : class ControllerReConfigData : public ControllerWorkQueueData {
      90             : public:
      91             :     ControllerReConfigData(std::string service_name, std::vector<string> server_list);
      92           0 :     virtual ~ControllerReConfigData() {}
      93             : 
      94             :     std::string service_name_;
      95             :     std::vector<string> server_list_;
      96             :     DISALLOW_COPY_AND_ASSIGN(ControllerReConfigData);
      97             : };
      98             : 
      99             : class ControllerDelPeerData : public ControllerWorkQueueData {
     100             : public:
     101             :     ControllerDelPeerData(AgentXmppChannel *ch);
     102          42 :     virtual ~ControllerDelPeerData() {}
     103          21 :     AgentXmppChannel *channel() {
     104          21 :         return channel_;
     105             :     }
     106             : 
     107             : private:
     108             :     AgentXmppChannel *channel_;
     109             :     DISALLOW_COPY_AND_ASSIGN(ControllerDelPeerData);
     110             : };
     111             : 
     112             : class VNController {
     113             : public:
     114             :     typedef boost::function<void(uint8_t)> XmppChannelDownCb;
     115             :     typedef boost::shared_ptr<ControllerXmppData> ControllerXmppDataType;
     116             :     typedef boost::shared_ptr<ControllerConnectRetryData> ControllerConnectRetryDataType;
     117             :     typedef boost::shared_ptr<ControllerWorkQueueData> ControllerWorkQueueDataType;
     118             :     typedef boost::shared_ptr<ControllerReConfigData> ControllerReConfigDataType;
     119             :     typedef boost::shared_ptr<ControllerDelPeerData> ControllerDelPeerDataType;
     120             :     typedef std::list<PeerPtr> BgpPeerList;
     121             :     typedef BgpPeerList::const_iterator BgpPeerConstIterator;
     122             :     typedef std::list<PeerPtr>::iterator BgpPeerIterator;
     123             :     typedef boost::shared_ptr<AgentXmppChannel> AgentXmppChannelPtr;
     124             :     typedef std::vector<AgentXmppChannelPtr> AgentXmppChannelList;
     125             :     typedef AgentXmppChannelList::iterator AgentXmppChannelListIter;
     126             : 
     127             :     struct FabricMulticastLabelRange {
     128           4 :         FabricMulticastLabelRange() : start(), end(), fabric_multicast_label_range_str() {};
     129           4 :         ~FabricMulticastLabelRange() {};
     130             : 
     131             :         uint32_t start;
     132             :         uint32_t end;
     133             :         std::string fabric_multicast_label_range_str;
     134             :     };
     135             : 
     136             :     VNController(Agent *agent);
     137             :     virtual ~VNController();
     138             :     void Connect();
     139             :     void DisConnect();
     140             :     void ReConnect();
     141             :     void ReConnectXmppServer();
     142             :     void ReConnectDnsServer();
     143             : 
     144             :     void Cleanup();
     145             : 
     146             :     void XmppServerConnect();
     147             :     void DnsXmppServerConnect();
     148             : 
     149             :     void XmppServerDisConnect();
     150             :     void DnsXmppServerDisConnect();
     151             :     void XmppServerUpdate(uint8_t time_out);
     152             :     bool VerifyXmppServerTimeout(uint32_t to);
     153             : 
     154             :     void DisConnectControllerIfmapServer(uint8_t idx);
     155             :     void DisConnectDnsServer(uint8_t idx);
     156             : 
     157             :     //Multicast peer identifier
     158          44 :     void increment_multicast_sequence_number() {multicast_sequence_number_++;}
     159          19 :     uint64_t multicast_sequence_number() {return multicast_sequence_number_;}
     160             : 
     161             :     //Peer maintenace routines
     162             :     uint8_t ActiveXmppConnectionCount();
     163             :     AgentXmppChannel *GetActiveXmppChannel();
     164             : 
     165          19 :     AgentIfMapVmExport *agent_ifmap_vm_export() const {
     166          19 :         return agent_ifmap_vm_export_.get();
     167             :     }
     168             : 
     169             :     //Start/stop eor processors
     170             :     void StartEndOfRibTxTimer();
     171             :     void StopEndOfRibTx();
     172             : 
     173             :     bool ControllerWorkQueueProcess(ControllerWorkQueueDataType data);
     174             :     bool XmppMessageProcess(ControllerXmppDataType data);
     175             :     Agent *agent() {return agent_;}
     176             :     void Enqueue(ControllerWorkQueueDataType data);
     177             :     void DeleteAgentXmppChannel(uint8_t idx);
     178             :     void SetAgentMcastLabelRange(uint8_t idx);
     179             :     void FillMcastLabelRange(uint32_t *star_idx,
     180             :                              uint32_t *end_idx,
     181             :                              uint8_t idx) const;
     182           2 :     const FabricMulticastLabelRange &fabric_multicast_label_range(uint8_t idx) const {
     183           2 :         return fabric_multicast_label_range_[idx];
     184             :     }
     185           2 :     void RegisterControllerChangeCallback(XmppChannelDownCb xmpp_channel_down_cb) {
     186           2 :         xmpp_channel_down_cb_ = xmpp_channel_down_cb;
     187           2 :     }
     188             :     void FlushTimedOutChannels(uint8_t index);
     189             :     void DelPeerWalkDone(AgentXmppChannel *ch);
     190             :     void DelPeerWalkDoneProcess(AgentXmppChannel *ch);
     191             :     void StartDelPeerWalk(AgentXmppChannelPtr ch);
     192             :     bool RxXmppMessageTrace(uint8_t peer_index,
     193             :                             const std::string &to_address,
     194             :                             int port, int size,
     195             :                             const std::string &msg,
     196             :                             const XmppStanza::XmppMessage *xmpp_msg);
     197             :     bool TxXmppMessageTrace(uint8_t peer_index,
     198             :                             const std::string &to_address,
     199             :                             int port, int size,
     200             :                             const std::string &msg,
     201             :                             const XmppStanza::XmppMessage *xmpp_msg);
     202             :     //Tunnel type helpers
     203             :     TunnelType::TypeBmap GetTypeBitmap
     204             :         (const autogen::EnetTunnelEncapsulationListType &encap);
     205             :     TunnelType::TypeBmap GetTypeBitmap
     206             :         (const autogen::TunnelEncapsulationListType &encap);
     207             :     TunnelType::TypeBmap GetTypeBitmap
     208             :         (const autogen::McastTunnelEncapsulationListType &encap);
     209             :     //Tunnel Mac helpers
     210             :     MacAddress GetTunnelMac(const autogen::EnetNextHopType &nh);
     211             :     MacAddress GetTunnelMac(const autogen::NextHopType &nh);
     212             :     //Unit test helpers
     213             :     bool IsWorkQueueEmpty() const;
     214           2 :     void EnableWorkQueue() { work_queue_.set_disable(false); }
     215             :     void GracefulRestartConfigListener();
     216             : 
     217             : private:
     218             :     void SetDscpConfig(XmppChannelConfig *xmpp_cfg) const;
     219             :     AgentXmppChannel *FindAgentXmppChannel(const std::string &server_ip);
     220             :     AgentDnsXmppChannel *FindAgentDnsXmppChannel(const std::string &server_ip);
     221             :     void DeleteConnectionInfo(const std::string &addr, bool is_dns) const;
     222             :     const std::string MakeConnectionPrefix(bool is_dns) const;
     223             :     bool AgentReConfigXmppServerConnectedExists(const std::string &server_ip,
     224             :                                std::vector<std::string> resp);
     225             :     bool ApplyControllerReConfigInternal(std::vector<string>service_list);
     226             :     bool ApplyDnsReConfigInternal(std::vector<string>service_list);
     227             : 
     228             :     Agent *agent_;
     229             :     uint64_t multicast_sequence_number_;
     230             :     boost::scoped_ptr<AgentIfMapVmExport> agent_ifmap_vm_export_;
     231             :     WorkQueue<ControllerWorkQueueDataType> work_queue_;
     232             :     FabricMulticastLabelRange fabric_multicast_label_range_[MAX_XMPP_SERVERS];
     233             :     XmppChannelDownCb xmpp_channel_down_cb_;
     234             :     uint32_t controller_list_chksum_;
     235             :     uint32_t dns_list_chksum_;
     236             :     AgentXmppChannelList timed_out_channels_[MAX_XMPP_SERVERS];
     237             :     AgentXmppChannelList delpeer_walks_;
     238             :     bool disconnect_;
     239             : };
     240             : 
     241             : extern SandeshTraceBufferPtr ControllerInfoTraceBuf;
     242             : extern SandeshTraceBufferPtr ControllerTxConfigTraceBuf1;
     243             : extern SandeshTraceBufferPtr ControllerTxConfigTraceBuf2;
     244             : extern SandeshTraceBufferPtr ControllerRouteWalkerTraceBuf;
     245             : extern SandeshTraceBufferPtr ControllerTraceBuf;
     246             : extern SandeshTraceBufferPtr ControllerRxRouteMessageTraceBuf1;
     247             : extern SandeshTraceBufferPtr ControllerRxConfigMessageTraceBuf1;
     248             : extern SandeshTraceBufferPtr ControllerRxRouteMessageTraceBuf2;
     249             : extern SandeshTraceBufferPtr ControllerRxConfigMessageTraceBuf2;
     250             : extern SandeshTraceBufferPtr ControllerTxMessageTraceBuf1;
     251             : extern SandeshTraceBufferPtr ControllerTxMessageTraceBuf2;
     252             : 
     253             : #define CONTROLLER_RX_ROUTE_MESSAGE_TRACE(obj, index, ...)\
     254             : do {\
     255             :     if (index == 0) { \
     256             :         AgentXmpp##obj::TraceMsg(ControllerRxRouteMessageTraceBuf1, __FILE__, \
     257             :                                  __LINE__, __VA_ARGS__);\
     258             :     } else { \
     259             :         AgentXmpp##obj::TraceMsg(ControllerRxRouteMessageTraceBuf2, __FILE__, \
     260             :                                  __LINE__, __VA_ARGS__);\
     261             :     } \
     262             : } while (false)
     263             : 
     264             : #define CONTROLLER_RX_CONFIG_MESSAGE_TRACE(obj, index, ...)\
     265             : do {\
     266             :     if (index == 0) { \
     267             :         AgentXmpp##obj::TraceMsg(ControllerRxConfigMessageTraceBuf1, __FILE__, \
     268             :                                  __LINE__, __VA_ARGS__);\
     269             :     } else { \
     270             :         AgentXmpp##obj::TraceMsg(ControllerRxConfigMessageTraceBuf2, __FILE__, \
     271             :                                  __LINE__, __VA_ARGS__);\
     272             :     } \
     273             : } while (false)
     274             : 
     275             : #define CONTROLLER_INFO_TRACE(obj, ...)\
     276             : do {\
     277             :     AgentXmpp##obj::TraceMsg(ControllerInfoTraceBuf, __FILE__, __LINE__, __VA_ARGS__);\
     278             : } while (false)
     279             : 
     280             : #define CONTROLLER_TX_CONFIG_TRACE(obj, index, ...)\
     281             : do {\
     282             :     if (index == 0) { \
     283             :         AgentXmpp##obj::TraceMsg(ControllerTxConfigTraceBuf1, __FILE__, __LINE__, __VA_ARGS__);\
     284             :     } else { \
     285             :         AgentXmpp##obj::TraceMsg(ControllerTxConfigTraceBuf2, __FILE__, __LINE__, __VA_ARGS__);\
     286             :     } \
     287             : } while (false)
     288             : 
     289             : #define CONTROLLER_ROUTE_WALKER_TRACE(obj, ...)\
     290             : do {\
     291             :     AgentXmpp##obj::TraceMsg(ControllerRouteWalkerTraceBuf, __FILE__, __LINE__, __VA_ARGS__);\
     292             : } while (false)
     293             : 
     294             : #define CONTROLLER_CONNECTIONS_TRACE(obj, ...)\
     295             : do {\
     296             :     AgentXmpp##obj::TraceMsg(ControllerConnectionsTraceBuf, __FILE__, __LINE__, __VA_ARGS__);\
     297             : } while (false)
     298             : 
     299             : #define CONTROLLER_TRACE(obj, ...)\
     300             : do {\
     301             :     AgentXmpp##obj::TraceMsg(ControllerTraceBuf, __FILE__, __LINE__, __VA_ARGS__);\
     302             : } while (false)
     303             : 
     304             : #define CONTROLLER_TX_MESSAGE_TRACE(obj, index, ...)\
     305             : do {\
     306             :     if (index == 0) { \
     307             :         AgentXmpp##obj::TraceMsg(ControllerTxMessageTraceBuf1, __FILE__, \
     308             :                                  __LINE__, __VA_ARGS__);\
     309             :     } else { \
     310             :         AgentXmpp##obj::TraceMsg(ControllerTxMessageTraceBuf2, __FILE__, \
     311             :                                  __LINE__, __VA_ARGS__);\
     312             :     } \
     313             : } while (false)
     314             : 
     315             : #endif

Generated by: LCOV version 1.14