OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
controller_timer.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014 Juniper Networks, Inc. All rights reserved.
3  */
4 
5 #include "base/logging.h"
6 #include "base/timer.h"
7 #include <sandesh/sandesh_trace.h>
8 #include "cmn/agent_cmn.h"
9 #include "init/agent_param.h"
10 #include "xmpp/xmpp_init.h"
11 #include "pugixml/pugixml.hpp"
13 #include "oper/vrf.h"
14 #include "oper/peer.h"
15 #include "oper/mirror_table.h"
16 #include "oper/multicast.h"
17 #include "oper/operdb_init.h"
18 #include "oper/instance_manager.h"
19 #include "controller/controller_types.h"
24 
25 #define SECS_TO_USECS(t) t * 1000 * 1000
26 #define SECS_TO_MSECS(t) t * 1000
27 
28 // Creates new timer
30  const std::string &timer_name,
31  uint32_t timer_interval)
32  : agent_(agent), last_restart_time_(0),
33  xmpp_server_(""), timer_name_(timer_name),
34  timer_interval_(timer_interval) {
37  io_service()), timer_name,
39  GetTaskId("Agent::ControllerXmpp"), 0);
40 }
41 
43  //Delete timer
44  if (controller_timer_) {
46  }
47 }
48 
51 }
52 
54  CONTROLLER_TRACE(Timer, "ControllerTimer", timer_name(), "");
56  xmpp_server_.clear();
57 
58  if (controller_timer_ == NULL) {
59  CONTROLLER_TRACE(Timer, "No controller timer", timer_name(), "");
60  return true;
61  }
62 
63  return controller_timer_->Cancel();
64 }
65 
66 // Set the last_restart_time and update the owner of the timer with XmppServer
67 void ControllerTimer::Start(AgentXmppChannel *agent_xmpp_channel) {
68  if (controller_timer_->running()) {
69  if (controller_timer_->Cancel() == false) {
70  CONTROLLER_TRACE(Timer, "Cancel during restart of timer failed",
71  timer_name(), agent_xmpp_channel->GetXmppServer());
72  }
73  }
74 
75  // Start the timer fresh
77  boost::bind(&ControllerTimer::TimerExpiredCallback, this));
78  CONTROLLER_TRACE(Timer, "Start", timer_name(),
79  agent_xmpp_channel->GetXmppServer());
80 
82  xmpp_server_ = agent_xmpp_channel->GetXmppServer();
83 }
84 
86  return controller_timer_->running();
87 }
88 
89 // Start the timer again if extension interval is not zero.
90 // If extension interval is not present then execute the expiration
91 // handler.
93 
94  bool ret = TimerExpirationDone();
95  CONTROLLER_TRACE(Timer, "Called Timer Expiration Routine", timer_name(),
96  xmpp_server_);
97 
98  //Reset all parameters
99  xmpp_server_.clear();
100  return ret;
101 }
102 
104  ControllerTimer(agent, "Agent Config Stale cleanup timer",
105  SECS_TO_MSECS(agent->params()->
106  llgr_params().stale_config_cleanup_time())),
107  sequence_number_(0) {
108 }
109 
113  GetSeqNumber();
114 
115  ControllerTimer::Start(channel);
116 }
117 
121  return false;
122 }
123 
125  return SECS_TO_MSECS(agent_->params()->
126  llgr_params().stale_config_cleanup_time());
127 }
128 
130  AgentIfMapXmppChannel *config_channel) :
131  ControllerTimer(agent, "End of config identification timer",
132  SECS_TO_MSECS(agent->params()->
133  llgr_params().config_poll_time())),
134  config_channel_(config_channel) {
135  Reset();
136 }
137 
143  fallback_interval_ = 0;
144  fallback_ = false;
146  gres_parameters().IsEnabled());
147 }
148 
149 void EndOfConfigTimer::Start(AgentXmppChannel *agent_xmpp_channel) {
150  Reset();
152  ControllerTimer::Start(agent_xmpp_channel);
153 }
154 
155 //Identify silence of 30 seconds on config channel
157  uint64_t current_time = UTCTimestampUsec();
158  //Config has been seen within inactivity time
159  bool config_seen = false;
160 
161  if (last_config_receive_time_ != 0) {
162  if ((current_time - last_config_receive_time_) <
164  config_seen = true;
165  }
166  }
167 
168  //When config is regularly seen on channel, put stale timeout to worst.
169  if ((current_time - last_restart_time_) >= GetFallbackInterval()) {
170  fallback_ = true;
171  }
172 
173  // End of config is enqueued in VNController work queue for processing.
174  if (fallback_ || !config_seen) {
177  return false;
178  }
179  return true;
180 }
181 
183  return SECS_TO_MSECS(agent_->params()->
184  llgr_params().config_poll_time());
185 }
186 
188  return fallback_interval_;
189 }
190 
193 }
194 
195 void EndOfConfigTimer::GresEnabled(bool enable) {
196  if (enable) {
198  llgr_params().config_inactivity_time());
200  llgr_params().config_fallback_time());
201  } else {
203  fallback_interval_ = 0;
204  }
205 }
206 
208  ControllerTimer(agent, "End of rib Tx identification timer",
209  SECS_TO_MSECS(agent->params()->
210  llgr_params().end_of_rib_tx_poll_time())),
211  agent_xmpp_channel_(NULL) {
212  Reset();
213 }
214 
218  fallback_ = false;
219  fallback_interval_ = 0;
221  gres_parameters().IsEnabled());
222 }
223 
224 void EndOfRibTxTimer::Start(AgentXmppChannel *agent_xmpp_channel) {
225  Reset();
226  agent_xmpp_channel_ = agent_xmpp_channel;
227  ControllerTimer::Start(agent_xmpp_channel);
228 }
229 
231  uint64_t current_time = UTCTimestampUsec();
232  uint8_t index = agent_xmpp_channel_->GetXmppServerIdx();
233  bool end_of_rib = false;
234 
235  // Check for fallback
236  if (last_route_published_time_ == 0) {
237  if ((current_time - agent_->controller_xmpp_channel_setup_time(index)) >
239  end_of_rib = true;
240  } else {
241  return true;
242  }
243  }
244 
245  // Check for inactivity
246  if ((current_time - last_route_published_time_) > GetInactivityInterval()) {
247  end_of_rib = true;
248  }
249 
250  if (end_of_rib) {
251  // Start walk to delete stale routes.
253  //Notify
256  return false;
257  }
258 
259  return true;
260 }
261 
263  return SECS_TO_MSECS(agent_->params()->
264  llgr_params().end_of_rib_tx_poll_time());
265 }
266 
268  return fallback_interval_;
269 }
270 
272  return end_of_rib_tx_time_;
273 }
274 
275 void EndOfRibTxTimer::GresEnabled(bool enable) {
276  if (enable) {
278  llgr_params().end_of_rib_tx_inactivity_time());
280  llgr_params().end_of_rib_tx_fallback_time());
281  } else {
283  fallback_interval_ = 0;
284  }
285 }
286 
288  ControllerTimer(agent, "End of rib Rx path timer",
289  SECS_TO_MSECS(agent->params()->
290  llgr_params().end_of_rib_rx_fallback_time())),
291  agent_xmpp_channel_(NULL) {
292  Reset();
293 }
294 
295 void EndOfRibRxTimer::Start(AgentXmppChannel *agent_xmpp_channel) {
296  agent_xmpp_channel_ = agent_xmpp_channel;
297  ControllerTimer::Start(agent_xmpp_channel);
298 }
299 
302  fallback_ = true;
304  return false;
305 }
306 
310  fallback_ = false;
312  gres_parameters().IsEnabled());
313 }
314 
317 }
318 
319 void EndOfRibRxTimer::GresEnabled(bool enable) {
320  if (enable) {
322  global_system_config()->gres_parameters().end_of_rib_time();
323  if (end_of_rib_rx_fallback_time_ == 0) {
325  llgr_params().end_of_rib_rx_fallback_time());
326  }
327  } else {
329  }
330 }
331 
333  ControllerTimer(agent, "Llgr stale timer",
334  SECS_TO_MSECS(agent->oper_db()->global_system_config()->
335  gres_parameters().llgr_stale_time())),
336  agent_xmpp_channel_(NULL) {
337  Reset();
338 }
339 
340 void LlgrStaleTimer::Start(AgentXmppChannel *agent_xmpp_channel) {
341  Reset();
342  agent_xmpp_channel_ = agent_xmpp_channel;
343  ControllerTimer::Start(agent_xmpp_channel);
344 }
345 
348  return false;
349 }
350 
352  llgr_stale_time_ = 0;
354  gres_parameters().IsEnabled());
355 }
356 
358  return llgr_stale_time_;
359 }
360 
361 void LlgrStaleTimer::GresEnabled(bool enable) {
362  if (enable) {
364  global_system_config()->gres_parameters().llgr_stale_time());
365  if (llgr_stale_time_ == 0) {
367  llgr_params().llgr_stale_time());
368  }
369  } else {
370  llgr_stale_time_ = 0;
371  }
372 }
virtual void Start(AgentXmppChannel *agent_xmpp_channel)
ConfigCleanupTimer(Agent *agent)
virtual bool TimerExpirationDone()
EndOfRibTxTimer(Agent *agent)
bool running() const
uint64_t end_of_rib_tx_time_
ControllerTimer(Agent *agent, const std::string &timer_name, uint32_t timer_interval)
virtual bool TimerExpirationDone()
uint64_t last_route_published_time_
void GresEnabled(bool enable)
virtual void Start(AgentXmppChannel *agent_xmpp_channel)
void Fire()
Definition: timer.h:118
uint32_t GetInactivityInterval() const
Timer * controller_timer_
virtual uint32_t GetTimerInterval() const =0
AgentIfMapXmppChannel * config_channel_
virtual uint32_t GetTimerInterval() const
virtual void Start(AgentXmppChannel *agent_xmpp_channel)
uint64_t config_inactivity_time_
OperDB * oper_db() const
Definition: agent.cc:1013
void GresEnabled(bool enable)
AgentIfMapXmppChannel * ifmap_xmpp_channel(uint8_t idx) const
Definition: agent.h:792
virtual void Start(AgentXmppChannel *agent_xmpp_channel)
EventNotifier * event_notifier() const
Definition: agent.cc:893
InstanceManager * instance_manager()
Definition: operdb_init.h:64
virtual ~ControllerTimer()
Definition: agent.h:358
uint64_t last_restart_time_
virtual uint32_t GetTimerInterval() const
static TaskScheduler * GetInstance()
Definition: task.cc:547
#define SECS_TO_MSECS(t)
void GresEnabled(bool enable)
virtual bool TimerExpirationDone()
AgentXmppChannel * agent_xmpp_channel_
uint64_t fallback_interval_
VNController * controller() const
Definition: agent.cc:981
EventManager * event_manager() const
Definition: agent.h:1103
virtual void Start(AgentXmppChannel *agent_xmpp_channel)
uint32_t GetFallbackInterval() const
std::string xmpp_server_
AgentXmppChannel * agent_xmpp_channel_
uint8_t GetXmppServerIdx()
EndOfRibRxTimer(Agent *agent)
AgentParam * params() const
Definition: agent.h:1218
static Timer * CreateTimer(boost::asio::io_context &service, const std::string &name, int task_id=Timer::GetTimerTaskId(), int task_instance=Timer::GetTimerInstanceId(), bool delete_on_completion=false)
Definition: timer.cc:201
IFMapAgentStaleCleaner * ifmap_stale_cleaner() const
Definition: agent.h:1177
AgentXmppChannel * agent_xmpp_channel_
bool Cancel()
Definition: timer.cc:150
virtual void Start(AgentXmppChannel *agent_xmpp_channel)
virtual uint32_t GetTimerInterval() const
std::string GetXmppServer()
uint64_t inactivity_detected_time_
uint64_t end_of_config_processed_time_
virtual bool TimerExpirationDone()
virtual uint32_t GetTimerInterval() const
uint32_t GetInactivityInterval() const
EndOfConfigTimer(Agent *agent, AgentIfMapXmppChannel *channel)
static uint64_t UTCTimestampUsec()
Definition: time_util.h:13
uint64_t end_of_rib_rx_time_
uint64_t llgr_stale_time_
bool Start(int time, Handler handler, ErrorHandler error_handler=NULL)
Definition: timer.cc:108
const std::string & timer_name() const
#define SECS_TO_USECS(t)
uint64_t last_config_receive_time_
uint64_t end_of_rib_rx_fallback_time_
bool running() const
Definition: timer.h:86
void GresEnabled(bool enable)
virtual bool TimerExpirationDone()
const uint64_t controller_xmpp_channel_setup_time(uint8_t idx) const
Definition: agent.h:801
Definition: timer.h:54
uint32_t GetFallbackInterval() const
LlgrStaleTimer(Agent *agent)
virtual uint32_t GetTimerInterval() const
GlobalSystemConfig * global_system_config() const
Definition: operdb_init.h:85
#define CONTROLLER_TRACE(obj,...)
virtual bool TimerExpirationDone()
uint64_t fallback_interval_
const int8_t & ifmap_active_xmpp_server_index() const
Definition: agent.h:780
static bool DeleteTimer(Timer *Timer)
Definition: timer.cc:222