OpenSDN source code
nexthop_server.h
Go to the documentation of this file.
1 /*
2  * NexthopDBServer class: represents the master server interface that
3  * has a Nexthop DB store and a list of clients.
4  */
5 #ifndef _AGENT_NHS_NEXTHOP_SERVER_H_
6 #define _AGENT_NHS_NEXTHOP_SERVER_H_
7 
8 #include <cstdio>
9 #include <iostream>
10 #include <mutex>
11 
12 #include <boost/array.hpp>
13 #include <boost/asio.hpp>
14 #include <boost/asio/signal_set.hpp>
15 #include <boost/bind/bind.hpp>
16 #include <boost/enable_shared_from_this.hpp>
17 #include <boost/scoped_ptr.hpp>
18 #include <boost/shared_ptr.hpp>
19 #include "io/usock_server.h"
20 #include "nexthop_client.h"
21 #include "nexthop_entry.h"
22 
23 using namespace boost::placeholders;
24 
25 /*
26  * The main server object for serving nexthops to connected clients.
27  */
29 {
30  public:
31 
32  typedef std::map <uint64_t, NexthopDBClient::ClientPtr> ClientDB;
33  typedef std::map <uint64_t, NexthopDBClient::ClientPtr>::iterator
35  typedef std::map <std::string, NexthopDBEntry::NexthopPtr> NexthopDB;
36  typedef std::map <std::string, NexthopDBEntry::NexthopPtr>::iterator
38 
39  NexthopDBServer(boost::asio::io_context &io, const std::string &path);
40 
41  NexthopDBEntry::NexthopPtr FindOrCreateNexthop(const std::string &str);
42  void FindAndRemoveNexthop(const std::string &str);
43  void Run();
44  void EventHandler(UnixDomainSocketServer *, UnixDomainSocketSession *,
46  void RemoveClient(uint64_t);
47 
48  private:
49  void AddClient(NexthopDBClient::ClientPtr cl);
50  void TriggerClients();
51  void AddNexthop(NexthopDBEntry::NexthopPtr nh);
52  void RemoveNexthop(NexthopDBEntry::NexthopPtr nh);
53 
54  boost::asio::io_context &io_service_;
55  std::string endpoint_path_;
56  boost::scoped_ptr<UnixDomainSocketServer> io_server_;
59  std::mutex mutex_;
60 };
61 
62 #endif
boost::shared_ptr< NexthopDBClient > ClientPtr
boost::shared_ptr< NexthopDBEntry > NexthopPtr
Definition: nexthop_entry.h:26
boost::scoped_ptr< UnixDomainSocketServer > io_server_
NexthopDB nexthop_table_
ClientDB client_table_
std::map< uint64_t, NexthopDBClient::ClientPtr >::iterator ClientIterator
boost::asio::io_context & io_service_
std::string endpoint_path_
std::mutex mutex_
std::map< std::string, NexthopDBEntry::NexthopPtr >::iterator NexthopIterator
std::map< uint64_t, NexthopDBClient::ClientPtr > ClientDB
std::map< std::string, NexthopDBEntry::NexthopPtr > NexthopDB
Event
Definition: http_client.h:29
Definition: io_utils.cc:11