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

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) 2014 Juniper Networks, Inc. All rights reserved.
       3             :  * Copyright Contributors to the OpenSDN project
       4             :  */
       5             : 
       6             : #ifndef __VNSW_CONTROLLER_CLEANUP_TIMER_HPP__
       7             : #define __VNSW_CONTROLLER_CLEANUP_TIMER_HPP__
       8             : 
       9             : #include <sandesh/sandesh_trace.h>
      10             : #include <boost/scoped_ptr.hpp>
      11             : #include <boost/shared_ptr.hpp>
      12             : 
      13             : class AgentXmppChannel;
      14             : 
      15             : /*
      16             :  * Controller Timer - abstract class.
      17             :  * Used to manage timers required for removing stale entries for config and
      18             :  * routes received from control nodes and end of config
      19             :  * Functionalities provided are - start, cancel,
      20             :  *
      21             :  */
      22             : struct ControllerTimer {
      23             :     ControllerTimer(Agent *agent, const std::string &timer_name,
      24             :                     uint32_t timer_interval);
      25             :     virtual ~ControllerTimer();
      26             : 
      27             :     virtual void Start(AgentXmppChannel *agent_xmpp_channel);
      28           0 :     virtual bool TimerExpirationDone() {return false;}
      29             :     virtual uint32_t GetTimerInterval() const = 0;
      30           0 :     virtual uint32_t timer_interval() {
      31           0 :         return timer_interval_;
      32             :     }
      33           0 :     virtual void set_timer_interval(uint32_t timer_interval) {
      34           0 :         timer_interval_ = timer_interval;
      35           0 :     }
      36             : 
      37             :     bool Cancel();
      38             :     void Fire();
      39             :     bool TimerExpiredCallback();
      40         120 :     const std::string& timer_name() const {return timer_name_;}
      41             :     bool running() const;
      42             : 
      43             :     Agent *agent_;
      44             :     // Timer
      45             :     Timer *controller_timer_;
      46             :     // Last time when timer was started
      47             :     uint64_t last_restart_time_;
      48             :     std::string xmpp_server_;
      49             :     std::string timer_name_;
      50             :     uint32_t timer_interval_;
      51             : };
      52             : 
      53             : /*
      54             :  * ConfigCleanupTimer
      55             :  *
      56             :  * Using the sequence number clean all stale configs(All config with lesser
      57             :  * sequence number are deleted)
      58             :  * Timer is started when end of config is determined.
      59             :  * sequence_number_ - picked from agent ifmap xmpp channel.
      60             :  */
      61             : struct ConfigCleanupTimer : public ControllerTimer {
      62             :     ConfigCleanupTimer(Agent *agent);
      63           4 :     virtual ~ConfigCleanupTimer() { }
      64             : 
      65             :     virtual void Start(AgentXmppChannel *agent_xmpp_channel);
      66             :     virtual uint32_t GetTimerInterval() const;
      67             :     virtual bool TimerExpirationDone();
      68             : 
      69             :     uint64_t sequence_number_;
      70             : };
      71             : 
      72             : /*
      73             :  * EndOfConfigTimer
      74             :  *
      75             :  * On config channel becoming ready, this timer is started.
      76             :  * Its determined by identifying inactivity(not receiving config) on config channel.
      77             :  * Fallback time - If config is continuously being received or no config is
      78             :  * sent, then there is a fallback for identifying end of config.
      79             :  *
      80             :  * On end of config start end of rib tx timer, walker to notify routes and
      81             :  * config cleanup.
      82             :  */
      83             : struct EndOfConfigTimer : public ControllerTimer {
      84             :     EndOfConfigTimer(Agent *agent, AgentIfMapXmppChannel *channel);
      85           4 :     virtual ~EndOfConfigTimer() { }
      86             : 
      87             :     virtual void Start(AgentXmppChannel *agent_xmpp_channel);
      88             :     virtual uint32_t GetTimerInterval() const;
      89             :     virtual bool TimerExpirationDone();
      90             : 
      91             :     uint32_t GetFallbackInterval() const;
      92             :     uint32_t GetInactivityInterval() const;
      93             :     void Reset();
      94             :     void GresEnabled(bool enable);
      95             : 
      96             :     AgentIfMapXmppChannel *config_channel_;
      97             :     uint64_t last_config_receive_time_;
      98             :     uint64_t inactivity_detected_time_;
      99             :     uint64_t end_of_config_processed_time_;
     100             :     bool fallback_;
     101             :     uint64_t config_inactivity_time_;
     102             :     uint64_t fallback_interval_;
     103             : };
     104             : 
     105             : /*
     106             :  * EndOfRibTxTimer
     107             :  *
     108             :  * Started on identifying end of config.
     109             :  * End of config starts a walk which will export routes. Each export is time
     110             :  * stamped so that inactivity of route export can be determined. If there is no
     111             :  * export seen for end-of-rib-tx time then end-of-rib-tx is concluded.
     112             :  * Fallback is also present in case route updates never stop for some reason.
     113             :  *
     114             :  * At the end of rib walk EOR is sent to control node.
     115             :  */
     116             : struct EndOfRibTxTimer : public ControllerTimer {
     117             :     EndOfRibTxTimer(Agent *agent);
     118          42 :     virtual ~EndOfRibTxTimer() { }
     119             : 
     120             :     virtual void Start(AgentXmppChannel *agent_xmpp_channel);
     121             :     virtual uint32_t GetTimerInterval() const;
     122             :     virtual bool TimerExpirationDone();
     123             : 
     124             :     uint32_t GetFallbackInterval() const;
     125             :     uint32_t GetInactivityInterval() const;
     126             :     void Reset();
     127             :     void GresEnabled(bool enable);
     128             : 
     129             :     AgentXmppChannel *agent_xmpp_channel_;
     130             :     uint64_t end_of_rib_tx_time_;
     131             :     uint64_t last_route_published_time_;
     132             :     bool fallback_;
     133             :     uint64_t fallback_interval_;
     134             : };
     135             : 
     136             : /*
     137             :  * EndOfRibRxTimer
     138             :  *
     139             :  * This timer is used as fallback only.
     140             :  * It observes for EOR from control node. In case it is not seen then on
     141             :  * fallback assume that EOR is received. If EOR is received from CN then this
     142             :  * timer is cancelled.
     143             :  * On expiration stale walk to remove stale route paths for this parent peer.
     144             :  */
     145             : struct EndOfRibRxTimer : public ControllerTimer {
     146             :     EndOfRibRxTimer(Agent *agent);
     147          42 :     virtual ~EndOfRibRxTimer() { }
     148             : 
     149             :     virtual void Start(AgentXmppChannel *agent_xmpp_channel);
     150             :     virtual uint32_t GetTimerInterval() const;
     151             :     virtual bool TimerExpirationDone();
     152             :     void Reset();
     153             :     void GresEnabled(bool enable);
     154             : 
     155             :     AgentXmppChannel *agent_xmpp_channel_;
     156             :     uint64_t end_of_rib_rx_time_;
     157             :     uint64_t end_of_rib_rx_fallback_time_;
     158             :     bool fallback_;
     159             : };
     160             : 
     161             : /*
     162             :  * LlgrStaleTimer
     163             :  *
     164             :  * When CN is down and this timer expires then stales will be cleaned.
     165             :  * It is the maximum time for which stale will be retained after CN is not
     166             :  * ready. This timer has no meaning when CN is ready as end-of-rib rx timer is
     167             :  * responsible for flushing out routes.
     168             :  */
     169             : struct LlgrStaleTimer : public ControllerTimer {
     170             :     LlgrStaleTimer(Agent *agent);
     171          42 :     virtual ~LlgrStaleTimer() { }
     172             : 
     173             :     virtual void Start(AgentXmppChannel *agent_xmpp_channel);
     174             :     virtual uint32_t GetTimerInterval() const;
     175             :     virtual bool TimerExpirationDone();
     176             :     void Reset();
     177             :     void GresEnabled(bool enable);
     178             : 
     179             :     AgentXmppChannel *agent_xmpp_channel_;
     180             :     uint64_t llgr_stale_time_;
     181             : };
     182             : #endif

Generated by: LCOV version 1.14