OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
agent_xmpp_init.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
3  */
4 
5 #include "base/logging.h"
6 #include "base/contrail_ports.h"
7 #include "base/address_util.h"
8 #include "xmpp/xmpp_init.h"
9 #include "pugixml/pugixml.hpp"
10 #include "cmn/dns.h"
11 #include "agent/agent_xmpp_init.h"
13 #include "base/logging.h"
14 
15 using namespace boost::asio;
16 using namespace boost::asio::ip;
17 using boost::system::error_code;
18 
19 bool DnsAgentXmppManager::Init(bool xmpp_auth_enabled,
20  const std::string &xmpp_server_cert,
21  const std::string &xmpp_server_key,
22  const std::string &xmpp_ca_cert) {
23  uint32_t port = Dns::GetXmppServerPort();
24  if (!port)
25  port = ContrailPorts::DnsXmpp();
26 
27  // XmppChannel Configuration
28  XmppChannelConfig xmpp_cfg(false);
30  xmpp_cfg.endpoint.port(port);
31  xmpp_cfg.auth_enabled = xmpp_auth_enabled;
32  if (xmpp_cfg.auth_enabled) {
33  xmpp_cfg.path_to_server_cert = xmpp_server_cert;
34  xmpp_cfg.path_to_server_priv_key = xmpp_server_key;
35  xmpp_cfg.path_to_ca_cert = xmpp_ca_cert;
36  }
37 
38  error_code ec;
39  IpAddress xmpp_ip_address = AddressFromString(Dns::GetSelfIp(), &ec);
40  if (ec) {
41  LOG(ERROR, "Xmpp IP Address:" << Dns::GetSelfIp() <<
42  " conversion error:" << ec.message());
43  exit(1);
44  }
45 
46  // Create XmppServer
48  Dns::GetHostName(), &xmpp_cfg);
49  if (!server->Initialize(port, false, xmpp_ip_address)) {
50  return false;
51  }
52  Dns::SetXmppServer(server);
53 
54  DnsAgentXmppChannelManager *agent_xmpp_mgr =
55  new DnsAgentXmppChannelManager(server);
56  Dns::SetAgentXmppChannelManager(agent_xmpp_mgr);
57  return true;
58 }
59 
61  XmppServer *server;
62  if ((server = Dns::GetXmppServer()) != NULL) {
63  Dns::SetXmppServer(NULL);
64  server->Shutdown();
65  delete server;
66  }
67 }
boost::asio::ip::tcp::endpoint endpoint
Definition: xmpp_config.h:24
static const std::string & GetHostName()
Definition: dns.h:53
virtual bool Initialize(short port)
Definition: xmpp_server.cc:300
boost::asio::ip::address IpAddress
Definition: address.h:13
static const uint32_t GetXmppServerPort()
Definition: dns.h:43
static void Shutdown()
static void SetXmppServer(XmppServer *server)
Definition: dns.h:41
static std::string GetSelfIp()
Definition: dns.h:63
void Shutdown()
Definition: xmpp_server.cc:339
std::string path_to_ca_cert
Definition: xmpp_config.h:30
std::string FromAddr
Definition: xmpp_config.h:21
std::string path_to_server_cert
Definition: xmpp_config.h:28
IpAddress AddressFromString(const std::string &ip_address_str, boost::system::error_code *ec)
static const char * kDnsNodeJID
Definition: xmpp_init.h:19
#define LOG(_Level, _Msg)
Definition: logging.h:33
static XmppServer * GetXmppServer()
Definition: dns.h:40
static EventManager * GetEventManager()
Definition: dns.h:31
static void SetAgentXmppChannelManager(DnsAgentXmppChannelManager *mgr)
Definition: dns.h:49
static const uint16_t DnsXmpp()
std::string path_to_server_priv_key
Definition: xmpp_config.h:29
static bool Init(bool xmpp_auth_enabled, const std::string &xmpp_server_cert, const std::string &xmpp_server_key, const std::string &xmpp_ca_cert)