OpenSDN source code
xmpp_config.h
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 #ifndef __XMPP_CONFIG_H__
7 #define __XMPP_CONFIG_H__
8 
9 #include <boost/asio/ip/tcp.hpp>
10 #include <boost/function.hpp>
11 #include <boost/property_tree/ptree.hpp>
12 #include <boost/ptr_container/ptr_map.hpp>
13 
14 #include "base/util.h"
15 
16 // Internal representation of Peer configuration
18 public:
19  explicit XmppChannelConfig(bool isClient = false);
20 
21  std::string ToAddr;
22  std::string FromAddr;
23  std::string NodeAddr; // pubsub node
24  std::string name;
25  boost::asio::ip::tcp::endpoint endpoint;
26  boost::asio::ip::tcp::endpoint local_endpoint;
27  bool logUVE;
29  std::string path_to_server_cert;
31  std::string path_to_ca_cert;
34  int xmpp_hold_time; // was uint8_t, but int everywhere
35  uint8_t dscp_value;
36  std::string xmlns;
37 
38  int CompareTo(const XmppChannelConfig &rhs) const;
39  static int const default_client_port = 5269;
40  static int const default_server_port = 5222;
41  static int const kTcpHoldTime = 30; //in secs
42 
43  bool ClientOnly() const { return isClient_; }
44 
45 private:
46  bool isClient_;
47 };
48 
50 public:
51  typedef boost::ptr_map<boost::asio::ip::tcp::endpoint, XmppChannelConfig>
53 
55  }
56 
58  neighbors_.insert(channel->endpoint, channel);
59  }
60 
61  XmppChannelConfig &GetXmppChannelConfig(const boost::asio::ip::tcp::endpoint ep) {
62  return neighbors_[ep];
63  }
64 
65  const XmppChannelConfigMap &neighbors() const { return neighbors_; }
66 
67  void Clear() {
68  neighbors_.clear();
69  }
70 
71 private:
74 };
75 
77 public:
78  enum DiffType {
82  DF_DELETE
83  };
84 
86 
87  typedef boost::function<void(DiffType, const XmppChannelConfig *,
89 
90  // stage 1: build the future internal representation
91  bool ParseConfig(const std::string &config, XmppConfigData *);
92 
93  // stage 2: generate a delta
94  void PeerConfigDiff(PeerDiffObserver obs) const;
95 
96  // stage 3: commit
97  void AcceptFuture();
98 
99  // testing API -- begin --
100  void SetFuture(const XmppConfigData *future);
101  // testing API -- end --
102 
103  void Terminate();
104 private:
105  std::unique_ptr<const XmppConfigData> current_;
106  std::unique_ptr<const XmppConfigData> future_;
108 };
109 
110 #endif
std::string FromAddr
Definition: xmpp_config.h:22
int CompareTo(const XmppChannelConfig &rhs) const
Definition: xmpp_config.cc:22
std::string name
Definition: xmpp_config.h:24
bool ClientOnly() const
Definition: xmpp_config.h:43
std::string xmlns
Definition: xmpp_config.h:36
std::string NodeAddr
Definition: xmpp_config.h:23
boost::asio::ip::tcp::endpoint local_endpoint
Definition: xmpp_config.h:26
static int const default_client_port
Definition: xmpp_config.h:39
boost::asio::ip::tcp::endpoint endpoint
Definition: xmpp_config.h:25
std::string path_to_ca_cert
Definition: xmpp_config.h:31
XmppChannelConfig(bool isClient=false)
Definition: xmpp_config.cc:15
static int const kTcpHoldTime
Definition: xmpp_config.h:41
static int const default_server_port
Definition: xmpp_config.h:40
uint8_t dscp_value
Definition: xmpp_config.h:35
std::string path_to_server_cert
Definition: xmpp_config.h:29
std::string path_to_server_priv_key
Definition: xmpp_config.h:30
std::string ToAddr
Definition: xmpp_config.h:21
const XmppChannelConfigMap & neighbors() const
Definition: xmpp_config.h:65
DISALLOW_COPY_AND_ASSIGN(XmppConfigData)
boost::ptr_map< boost::asio::ip::tcp::endpoint, XmppChannelConfig > XmppChannelConfigMap
Definition: xmpp_config.h:52
XmppChannelConfig & GetXmppChannelConfig(const boost::asio::ip::tcp::endpoint ep)
Definition: xmpp_config.h:61
XmppChannelConfigMap neighbors_
Definition: xmpp_config.h:72
void AddXmppChannelConfig(XmppChannelConfig *channel)
Definition: xmpp_config.h:57
bool ParseConfig(const std::string &config, XmppConfigData *)
boost::function< void(DiffType, const XmppChannelConfig *, const XmppChannelConfig *)> PeerDiffObserver
Definition: xmpp_config.h:88
std::unique_ptr< const XmppConfigData > future_
Definition: xmpp_config.h:106
void PeerConfigDiff(PeerDiffObserver obs) const
Definition: xmpp_config.cc:33
void SetFuture(const XmppConfigData *future)
Definition: xmpp_config.cc:70
std::unique_ptr< const XmppConfigData > current_
Definition: xmpp_config.h:105
DISALLOW_COPY_AND_ASSIGN(XmppConfigManager)