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