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 _dns_agent_xmpp_channel_h_ 7 : #define _dns_agent_xmpp_channel_h_ 8 : 9 : #include <map> 10 : #include <set> 11 : #include <string> 12 : #include <mutex> 13 : 14 : #include <boost/function.hpp> 15 : #include <boost/bind/bind.hpp> 16 : 17 : #include "xmpp/xmpp_channel.h" 18 : #include "bind/bind_util.h" 19 : 20 : using namespace boost::placeholders; 21 : 22 : class XmppServer; 23 : class DnsAgentXmppChannelManager; 24 : class AgentData; 25 : class AgentDnsData; 26 : class TaskTrigger; 27 : 28 : class DnsAgentXmppChannel { 29 : public: 30 : typedef std::set<DnsUpdateData *, DnsUpdateData::Compare> DataSet; 31 : 32 : DnsAgentXmppChannel(XmppChannel *channel, 33 : DnsAgentXmppChannelManager *mgr); 34 : virtual ~DnsAgentXmppChannel(); 35 : void Close(); 36 : void ReceiveReq(const XmppStanza::XmppMessage *msg); 37 : void GetAgentDnsData(AgentDnsData &data); 38 : void UpdateDnsRecords(BindUtil::Operation op); 39 : 40 : private: 41 : std::string GetDnsRecordName(std::string &vdns_name, const DnsItem &item); 42 : void HandleAgentUpdate(std::unique_ptr<DnsUpdateData> rcv_data); 43 : 44 : DataSet update_data_; 45 : XmppChannel *channel_; 46 : DnsAgentXmppChannelManager *mgr_; 47 : }; 48 : 49 : class DnsAgentXmppChannelManager { 50 : public: 51 : struct RecordRequest { 52 : BindUtil::Operation op; 53 : std::string record_name; 54 : std::string vdns_name; 55 : DnsItem item; 56 : 57 0 : RecordRequest(BindUtil::Operation o, const std::string &rec, 58 : const std::string &vdns, const DnsItem &it) 59 0 : : op(o), record_name(rec), vdns_name(vdns), item(it) {} 60 : }; 61 : typedef WorkQueue<boost::shared_ptr<RecordRequest> > RecordRequestWorkQueue; 62 : 63 : typedef std::map<const XmppChannel *, DnsAgentXmppChannel *> ChannelMap; 64 : 65 : DnsAgentXmppChannelManager(XmppServer *server); 66 : virtual ~DnsAgentXmppChannelManager(); 67 : void RemoveChannel(XmppChannel *ch); 68 : DnsAgentXmppChannel *FindChannel(const XmppChannel *ch); 69 : void HandleXmppChannelEvent(XmppChannel *channel, xmps::PeerState state); 70 : bool ProcessRecord(boost::shared_ptr<RecordRequest> req); 71 : void EnqueueRecord(boost::shared_ptr<RecordRequest> req); 72 : 73 : void GetAgentData(std::vector<AgentData> &list); 74 : void GetAgentDnsData(std::vector<AgentDnsData> &dt); 75 : 76 : private: 77 : uint8_t ChannelToDscp(const XmppChannel *xc) const; 78 : XmppServer *server_; 79 : ChannelMap channel_map_; 80 : std::mutex mutex_; 81 : RecordRequestWorkQueue work_queue_; 82 : }; 83 : 84 : #endif // _dns_agent_xmpp_channel_h_