OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
controller_sandesh.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
3  */
4 
5 #include <cmn/agent_cmn.h>
6 #include <cmn/agent_db.h>
8 #include <controller/controller_types.h>
14 #include <xmpp/xmpp_connection.h>
15 #include <xmpp/xmpp_session.h>
16 
17 static uint8_t ChannelToDscp(XmppChannel *xc) {
18  const XmppConnection *conn = xc->connection();
19  if (conn) {
20  const XmppSession *sess = conn->session();
21  if (sess) {
22  return sess->GetDscpValue();
23  }
24  }
25  return 0;
26 }
27 
28 void AgentXmppConnectionStatusReq::HandleRequest() const {
29  Agent *agent = Agent::GetInstance();
30  uint8_t count = 0;
31  AgentXmppConnectionStatus *resp = new AgentXmppConnectionStatus();
32  while (count < MAX_XMPP_SERVERS) {
33  if (!agent->controller_ifmap_xmpp_server(count).empty()) {
34 
35  AgentXmppData data;
36  data.set_controller_ip(agent->controller_ifmap_xmpp_server(count));
37  AgentXmppChannel *ch = agent->controller_xmpp_channel(count);
38  AgentIfMapXmppChannel *ifmap_ch =agent->ifmap_xmpp_channel(count);
39 
40  if (ch) {
41  XmppChannel *xc = ch->GetXmppChannel();
42  if (xc->GetPeerState() == xmps::READY) {
43  data.set_state("Established");
44  } else {
45  data.set_state("Down");
46  }
47 
48  data.set_last_ready_time(
50  (agent->controller_xmpp_channel_setup_time(count))));
51 
52  //End of config
53  ConfigStats config_stats;
54  ControllerEndOfConfigStats eoc_stats = config_stats.end_of_config_stats;
55  if (ifmap_ch) {
56  EndOfConfigTimer *eoc_timer = ifmap_ch->end_of_config_timer();
57  eoc_stats.set_last_config_receive_time
59  (eoc_timer->last_config_receive_time_)));
60  eoc_stats.set_inactivity_detected_time
62  (eoc_timer->inactivity_detected_time_)));
63  eoc_stats.set_end_of_config_processed_time
65  (eoc_timer->end_of_config_processed_time_)));
66  if (eoc_timer->fallback_) {
67  eoc_stats.set_end_of_config_reason("fallback");
68  } else {
69  eoc_stats.set_end_of_config_reason("inactivity");
70  }
71  eoc_stats.set_last_start_time(
73  last_restart_time_)));
74  eoc_stats.set_running(eoc_timer->running());
75  } else {
76  eoc_stats.set_last_config_receive_time("");
77  eoc_stats.set_inactivity_detected_time("");
78  eoc_stats.set_end_of_config_processed_time("");
79  eoc_stats.set_end_of_config_reason("");
80  eoc_stats.set_last_start_time("");
81  eoc_stats.set_running(false);
82  }
83  config_stats.set_end_of_config_stats(eoc_stats);
84 
85  ConfigCleanupStats config_cleanup_stats =
86  config_stats.config_cleanup_stats;
87  if (ifmap_ch) {
88  ConfigCleanupTimer *cleanup_timer = ifmap_ch->
89  config_cleanup_timer();
90  config_cleanup_stats.set_last_start_time
92  (cleanup_timer->last_restart_time_)));
93  config_cleanup_stats.set_cleanup_sequence_number
94  (cleanup_timer->sequence_number_);
95  config_cleanup_stats.set_running(cleanup_timer->running());
96  } else {
97  config_cleanup_stats.set_last_start_time("");
98  config_cleanup_stats.set_cleanup_sequence_number(0);
99  config_cleanup_stats.set_running(false);
100  }
101  config_stats.set_config_cleanup_stats(config_cleanup_stats);
102  data.set_config_stats(config_stats);
103 
104  //End of rib
105  ControllerEndOfRibStats eor_stats;
106  ControllerEndOfRibTxStats eor_tx;
107  EndOfRibTxTimer *eor_tx_timer = ch->end_of_rib_tx_timer();
108  eor_tx.set_end_of_rib_tx_time
110  (eor_tx_timer->end_of_rib_tx_time_)));
111  eor_tx.set_last_route_published_time
113  (eor_tx_timer->last_route_published_time_)));
114  if (eor_tx_timer->fallback_) {
115  eor_tx.set_end_of_rib_reason("fallback");
116  } else {
117  eor_tx.set_end_of_rib_reason("inactivity");
118  }
119  eor_tx.set_last_start_time
121  (eor_tx_timer->last_restart_time_)));
122  eor_tx.set_running(eor_tx_timer->running());
123  eor_stats.set_tx(eor_tx);
124 
125  ControllerEndOfRibRxStats eor_rx;
126  EndOfRibRxTimer *eor_rx_timer = ch->end_of_rib_rx_timer();
127  eor_rx.set_end_of_rib_rx_time
129  (eor_rx_timer->end_of_rib_rx_time_)));
130  eor_rx.set_last_start_time
132  (eor_tx_timer->last_restart_time_)));
133  if (eor_rx_timer->fallback_) {
134  eor_rx.set_end_of_rib_reason("fallback");
135  } else {
136  eor_rx.set_end_of_rib_reason("inactivity");
137  }
138  eor_rx.set_running(eor_rx_timer->running());
139  eor_stats.set_rx(eor_rx);
140  data.set_end_of_rib_stats(eor_stats);
141 
142  data.set_sequence_number(ch->sequence_number());
143  data.set_peer_name(xc->ToString());
144  data.set_peer_address(xc->PeerAddress());
145  if (agent->mulitcast_builder() == ch) {
146  data.set_mcast_controller("Yes");
147  } else {
148  data.set_mcast_controller("No");
149  }
150 
151  if (agent->ifmap_active_xmpp_server().compare
152  (agent->controller_ifmap_xmpp_server(count)) == 0) {
153  data.set_cfg_controller("Yes");
154  } else {
155  data.set_cfg_controller("No");
156  }
157 
158  data.set_xmpp_auth_type(xc->AuthType());
159  data.set_last_state(xc->LastStateName());
160  data.set_last_event(xc->LastEvent());
161  data.set_last_state_at(xc->LastStateChangeAt());
162  data.set_flap_count(xc->FlapCount());
163  data.set_flap_time(xc->LastFlap());
164  data.set_dscp(ChannelToDscp(xc));
165 
166  ControllerProtoStats rx_proto_stats;
167  rx_proto_stats.open = xc->rx_open();
168  rx_proto_stats.keepalive = xc->rx_keepalive();
169  rx_proto_stats.update = xc->rx_update();
170  rx_proto_stats.close = xc->rx_close();
171 
172  ControllerProtoStats tx_proto_stats;
173  tx_proto_stats.open = xc->tx_open();
174  tx_proto_stats.keepalive = xc->tx_keepalive();
175  tx_proto_stats.update = xc->tx_update();
176  tx_proto_stats.close = xc->tx_close();
177 
178  data.set_rx_proto_stats(rx_proto_stats);
179  data.set_tx_proto_stats(tx_proto_stats);
180  }
181 
182  std::vector<AgentXmppData> &list =
183  const_cast<std::vector<AgentXmppData>&>(resp->get_peer());
184  list.push_back(data);
185  }
186  count++;
187  }
188  resp->set_context(context());
189  resp->set_more(false);
190  resp->Response();
191 }
192 
193 void AgentDnsXmppConnectionStatusReq::HandleRequest() const {
194  uint8_t dns_count = 0;
195  Agent *agent = Agent::GetInstance();
196 
197  AgentDnsXmppConnectionStatus *resp = new AgentDnsXmppConnectionStatus();
198  while (dns_count < MAX_XMPP_SERVERS) {
199  if (!agent->dns_server(dns_count).empty()) {
200 
201  AgentXmppDnsData data;
202  data.set_dns_controller_ip(agent->dns_server(dns_count));
203 
204  AgentDnsXmppChannel *ch = agent->dns_xmpp_channel(dns_count);
205  if (ch) {
206  XmppChannel *xc = ch->GetXmppChannel();
207  if (xc->GetPeerState() == xmps::READY) {
208  data.set_state("Established");
209  } else {
210  data.set_state("Down");
211  }
212 
213  data.set_peer_name(xc->ToString());
214  data.set_peer_address(xc->PeerAddress());
215  data.set_xmpp_auth_type(xc->AuthType());
216  data.set_last_state(xc->LastStateName());
217  data.set_last_event(xc->LastEvent());
218  data.set_last_state_at(xc->LastStateChangeAt());
219  data.set_flap_count(xc->FlapCount());
220  data.set_flap_time(xc->LastFlap());
221  data.set_dscp(ChannelToDscp(xc));
222 
223  ControllerProtoStats rx_proto_stats;
224  rx_proto_stats.open = xc->rx_open();
225  rx_proto_stats.keepalive = xc->rx_keepalive();
226  rx_proto_stats.update = xc->rx_update();
227  rx_proto_stats.close = xc->rx_close();
228 
229  ControllerProtoStats tx_proto_stats;
230  tx_proto_stats.open = xc->tx_open();
231  tx_proto_stats.keepalive = xc->tx_keepalive();
232  tx_proto_stats.update = xc->tx_update();
233  tx_proto_stats.close = xc->tx_close();
234 
235  data.set_rx_proto_stats(rx_proto_stats);
236  data.set_tx_proto_stats(tx_proto_stats);
237  }
238 
239  std::vector<AgentXmppDnsData> &list =
240  const_cast<std::vector<AgentXmppDnsData>&>(resp->get_peer());
241  list.push_back(data);
242  }
243  dns_count++;
244  }
245  resp->set_context(context());
246  resp->set_more(false);
247  resp->Response();
248 }
virtual const XmppConnection * connection() const =0
XmppChannel * GetXmppChannel()
static Agent * GetInstance()
Definition: agent.h:436
bool running() const
uint64_t end_of_rib_tx_time_
uint64_t last_route_published_time_
AgentXmppChannel * mulitcast_builder()
Definition: agent.h:895
const std::string & dns_server(uint8_t idx) const
Definition: agent.h:857
EndOfRibTxTimer * end_of_rib_tx_timer()
EndOfRibRxTimer * end_of_rib_rx_timer()
static uint8_t ChannelToDscp(XmppChannel *xc)
AgentXmppChannel * controller_xmpp_channel(uint8_t idx) const
Definition: agent.h:809
virtual xmps::PeerState GetPeerState() const =0
AgentIfMapXmppChannel * ifmap_xmpp_channel(uint8_t idx) const
Definition: agent.h:792
EndOfConfigTimer * end_of_config_timer()
virtual std::string AuthType() const =0
AgentDnsXmppChannel * dns_xmpp_channel(uint8_t idx) const
Definition: agent.h:844
virtual std::string LastStateChangeAt() const =0
virtual uint32_t rx_update() const =0
static const std::string integerToString(const NumberType &num)
Definition: string_util.h:19
Definition: agent.h:358
virtual uint32_t tx_keepalive() const =0
uint64_t last_restart_time_
uint64_t sequence_number() const
virtual std::string LastEvent() const =0
static boost::posix_time::ptime UTCUsecToPTime(uint64_t tusec)
Definition: time_util.h:38
virtual const std::string & ToString() const =0
virtual std::string LastStateName() const =0
const std::string & controller_ifmap_xmpp_server(uint8_t idx) const
Definition: agent.h:730
virtual uint32_t FlapCount() const =0
#define MAX_XMPP_SERVERS
Definition: agent.h:291
uint64_t inactivity_detected_time_
uint64_t end_of_config_processed_time_
uint64_t end_of_rib_rx_time_
uint64_t last_config_receive_time_
virtual uint32_t tx_close() const =0
virtual uint32_t rx_open() const =0
XmppChannel * GetXmppChannel()
const uint64_t controller_xmpp_channel_setup_time(uint8_t idx) const
Definition: agent.h:801
virtual uint32_t tx_update() const =0
const XmppSession * session() const
virtual std::string PeerAddress() const =0
uint8_t GetDscpValue() const
Definition: tcp_session.cc:573
virtual uint32_t tx_open() const =0
virtual uint32_t rx_close() const =0
virtual uint32_t rx_keepalive() const =0
const std::string & ifmap_active_xmpp_server() const
Definition: agent.h:781
virtual std::string LastFlap() const =0