Line data Source code
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 17 : class XmppChannelConfig { 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; 28 : bool auth_enabled; 29 : std::string path_to_server_cert; 30 : std::string path_to_server_priv_key; 31 : std::string path_to_ca_cert; 32 : int tcp_hold_time; 33 : bool gr_helper_disable; 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 46424 : bool ClientOnly() const { return isClient_; } 44 : 45 : private: 46 : bool isClient_; 47 : }; 48 : 49 : class XmppConfigData { 50 : public: 51 : typedef boost::ptr_map<boost::asio::ip::tcp::endpoint, XmppChannelConfig> 52 : XmppChannelConfigMap; 53 : 54 10040 : XmppConfigData() { 55 10040 : } 56 : 57 4993 : void AddXmppChannelConfig(XmppChannelConfig *channel) { 58 4993 : neighbors_.insert(channel->endpoint, channel); 59 4993 : } 60 : 61 : XmppChannelConfig &GetXmppChannelConfig(const boost::asio::ip::tcp::endpoint ep) { 62 : return neighbors_[ep]; 63 : } 64 : 65 10004 : const XmppChannelConfigMap &neighbors() const { return neighbors_; } 66 : 67 : void Clear() { 68 : neighbors_.clear(); 69 : } 70 : 71 : private: 72 : XmppChannelConfigMap neighbors_; 73 : DISALLOW_COPY_AND_ASSIGN(XmppConfigData); 74 : }; 75 : 76 : class XmppConfigManager { 77 : public: 78 : enum DiffType { 79 : DF_NONE, 80 : DF_ADD, 81 : DF_CHANGE, 82 : DF_DELETE 83 : }; 84 : 85 : XmppConfigManager(); 86 : 87 : typedef boost::function<void(DiffType, const XmppChannelConfig *, 88 : const XmppChannelConfig *)> PeerDiffObserver; 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_; 107 : DISALLOW_COPY_AND_ASSIGN(XmppConfigManager); 108 : }; 109 : 110 : #endif