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