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