OpenSDN source code
agent_xmpp_init.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 "base/logging.h"
7 #include "base/contrail_ports.h"
8 #include "base/address_util.h"
9 #include "xmpp/xmpp_init.h"
10 #include "pugixml/pugixml.hpp"
11 #include "cmn/dns.h"
12 #include "agent/agent_xmpp_init.h"
14 #include "base/logging.h"
15 
16 using namespace boost::asio;
17 using namespace boost::asio::ip;
18 using boost::system::error_code;
19 
20 bool DnsAgentXmppManager::Init(bool xmpp_auth_enabled,
21  const std::string &xmpp_server_cert,
22  const std::string &xmpp_server_key,
23  const std::string &xmpp_ca_cert) {
24  uint32_t port = Dns::GetXmppServerPort();
25  if (!port)
26  port = ContrailPorts::DnsXmpp();
27 
28  // XmppChannel Configuration
29  XmppChannelConfig xmpp_cfg(false);
31  xmpp_cfg.endpoint.port(port);
32  xmpp_cfg.auth_enabled = xmpp_auth_enabled;
33  if (xmpp_cfg.auth_enabled) {
34  xmpp_cfg.path_to_server_cert = xmpp_server_cert;
35  xmpp_cfg.path_to_server_priv_key = xmpp_server_key;
36  xmpp_cfg.path_to_ca_cert = xmpp_ca_cert;
37  }
38 
39  error_code ec;
40  IpAddress xmpp_ip_address = AddressFromString(Dns::GetSelfIp(), &ec);
41  if (ec) {
42  LOG(ERROR, "Xmpp IP Address:" << Dns::GetSelfIp() <<
43  " conversion error:" << ec.message());
44  exit(1);
45  }
46 
47  // Create XmppServer
49  Dns::GetHostName(), &xmpp_cfg);
50  if (!server->Initialize(port, false, xmpp_ip_address)) {
51  return false;
52  }
53  Dns::SetXmppServer(server);
54 
55  DnsAgentXmppChannelManager *agent_xmpp_mgr =
56  new DnsAgentXmppChannelManager(server);
57  Dns::SetAgentXmppChannelManager(agent_xmpp_mgr);
58  return true;
59 }
60 
62  XmppServer *server;
63  if ((server = Dns::GetXmppServer()) != NULL) {
64  Dns::SetXmppServer(NULL);
65  server->Shutdown();
66  delete server;
67  }
68 }
boost::asio::ip::address IpAddress
Definition: address.h:14
IpAddress AddressFromString(const std::string &ip_address_str, boost::system::error_code *ec)
static const uint16_t DnsXmpp()
static void Shutdown()
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)
static std::string GetSelfIp()
Definition: dns.h:66
static EventManager * GetEventManager()
Definition: dns.h:34
static const std::string & GetHostName()
Definition: dns.h:56
static const uint32_t GetXmppServerPort()
Definition: dns.h:46
static void SetAgentXmppChannelManager(DnsAgentXmppChannelManager *mgr)
Definition: dns.h:52
static void SetXmppServer(XmppServer *server)
Definition: dns.h:44
static XmppServer * GetXmppServer()
Definition: dns.h:43
std::string FromAddr
Definition: xmpp_config.h:22
boost::asio::ip::tcp::endpoint endpoint
Definition: xmpp_config.h:25
std::string path_to_ca_cert
Definition: xmpp_config.h:31
std::string path_to_server_cert
Definition: xmpp_config.h:29
std::string path_to_server_priv_key
Definition: xmpp_config.h:30
static const char * kDnsNodeJID
Definition: xmpp_init.h:20
void Shutdown()
Definition: xmpp_server.cc:340
virtual bool Initialize(short port)
Definition: xmpp_server.cc:301
#define LOG(_Level, _Msg)
Definition: logging.h:35