OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
bfd_client.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017 Juniper Networks, Inc. All rights reserved.
3  */
4 #include <boost/asio.hpp>
5 #include <boost/bind.hpp>
6 #include <boost/function.hpp>
7 #include <boost/scoped_ptr.hpp>
8 #include <boost/random.hpp>
9 #include <set>
10 
11 #include "base/logging.h"
12 #include "bfd/bfd_client.h"
13 #include "bfd/bfd_common.h"
14 #include "bfd/bfd_connection.h"
15 #include "bfd/bfd_server.h"
16 #include "bfd/bfd_session.h"
17 
18 using namespace BFD;
19 using boost::bind;
20 using std::make_pair;
21 using std::pair;
22 
23 Client::Client(Connection *cm, ClientId id) : id_(id), cm_(cm) {
24 }
25 
27  // DeleteClientSessions();
28 }
29 
32 }
33 
35  return cm_->GetServer()->SessionByKey(key);
36 }
37 
38 bool Client::Up(const SessionKey &key) const {
39  Session *session = GetSession(key);
40  return session && session->Up();
41 }
42 
43 void Client::AddSession(const SessionKey &key, const SessionConfig &config) {
44  cm_->GetServer()->AddSession(key, config, bind(&Client::Notify, this, _1,
45  _2));
46 }
47 
49  cm_->GetServer()->DeleteSession(key);
50 }
51 
52 void Client::Notify(const SessionKey &key, const BFD::BFDState &new_state) {
53  cm_->NotifyStateChange(key, new_state == kUp);
54 }
void AddSession(const SessionKey &key, const SessionConfig &config, ChangeCb cb)
Definition: bfd_server.cc:34
Client(Connection *cm, ClientId client_id=0)
Definition: bfd_client.cc:23
Connection * cm_
Definition: bfd_client.h:30
Session * SessionByKey(const boost::asio::ip::address &address, const SessionIndex &index=SessionIndex())
Definition: bfd_server.cc:165
virtual ~Client()
Definition: bfd_client.cc:26
uint32_t ClientId
Definition: bfd_common.h:19
bool Up(const SessionKey &key) const
Definition: bfd_client.cc:38
Session * GetSession(const SessionKey &key) const
Definition: bfd_client.cc:34
virtual void NotifyStateChange(const SessionKey &key, const bool &up)=0
void DeleteClientSessions()
Definition: bfd_client.cc:30
BFDState
Definition: bfd_common.h:21
void DeleteSession(const SessionKey &key)
Definition: bfd_client.cc:48
void DeleteSession(const SessionKey &key)
Definition: bfd_server.cc:51
void AddSession(const SessionKey &key, const SessionConfig &config)
Definition: bfd_client.cc:43
void Notify(const SessionKey &key, const BFD::BFDState &new_state)
Definition: bfd_client.cc:52
void DeleteClientSessions()
Definition: bfd_server.cc:66
bool Up() const
Definition: bfd_session.cc:324
virtual Server * GetServer() const =0