OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
nexthop_manager.cc
Go to the documentation of this file.
1 /*
2  * Implementation of NexthopManager class. It does the following:
3  * - instantiates NexthopServer object so that interested clients can
4  * register for nexthop notification.
5  * - registers with the vrouter-agent nexthopDB for "db.nexthop.0"
6  * table to get nexthop updates. The nexthops are actually stored
7  * in the NexthopServer object.
8  */
9 #include "db/db.h"
10 #include "cmn/agent_signal.h"
11 #include "io/event_manager.h"
12 #include "nexthop_manager.h"
13 #include "oper/tunnel_nh.h"
14 #include <sys/wait.h>
15 
16 NexthopManager::NexthopManager(EventManager *evm, const std::string &endpoint)
17  : evm_(evm), nh_table_(NULL), nh_listener_(DBTableBase::kInvalidId),
18  nh_server_(new NexthopDBServer(*(evm->io_service()), endpoint))
19 {
20 }
21 
23 {
24 }
25 
26 void
28 {
29  nh_table_ = database->FindTable("db.nexthop.0");
30  assert(nh_table_);
31  nh_listener_ =
33  _1, _2));
34 }
35 
36 void
38 {
40 }
41 
42 void
44 {
45  NextHop *nh = static_cast <NextHop *>(entry);
46  if (nh->GetType () == NextHop::TUNNEL) {
47  TunnelNH *tnh = (TunnelNH *) nh;
48  if (nh->IsDeleted()) {
49  nh_server_->FindAndRemoveNexthop(tnh->GetDip()->to_string());
50  } else {
51  nh_server_->FindOrCreateNexthop(tnh->GetDip()->to_string());
52  }
53  }
54 }
void EventObserver(DBTablePartBase *db_part, DBEntryBase *entry)
NexthopManager(EventManager *evm, const std::string &endpoint)
bool IsDeleted() const
Definition: db_entry.h:49
const Ip4Address * GetDip() const
Definition: tunnel_nh.h:37
boost::scoped_ptr< NexthopDBServer > nh_server_
Type GetType() const
Definition: nexthop.h:405
void Unregister(ListenerId listener)
Definition: db_table.cc:186
ListenerId Register(ChangeCallback callback, const std::string &name="unspecified")
Definition: db_table.cc:181
Definition: db.h:24
void Initialize(DB *database)
DBTableBase::ListenerId nh_listener_
DBTableBase * nh_table_
DBTableBase * FindTable(const std::string &name)
Definition: db.cc:68
static EventManager evm