Line data Source code
1 : /* 2 : * Copyright (c) 2017 Juniper Networks, Inc. All rights reserved. 3 : */ 4 : #include <boost/asio.hpp> 5 : #include <boost/bind/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 : using namespace boost::placeholders; 23 : 24 19 : Client::Client(Connection *cm, ClientId id) : id_(id), cm_(cm) { 25 19 : } 26 : 27 20 : Client::~Client() { 28 : // DeleteClientSessions(); 29 20 : } 30 : 31 0 : void Client::DeleteClientSessions() { 32 0 : cm_->GetServer()->DeleteClientSessions(); 33 0 : } 34 : 35 10636 : Session *Client::GetSession(const SessionKey &key) const { 36 10636 : return cm_->GetServer()->SessionByKey(key); 37 : } 38 : 39 10636 : bool Client::Up(const SessionKey &key) const { 40 10636 : Session *session = GetSession(key); 41 10636 : return session && session->Up(); 42 : } 43 : 44 28 : void Client::AddSession(const SessionKey &key, const SessionConfig &config) { 45 28 : cm_->GetServer()->AddSession(key, config, bind(&Client::Notify, this, _1, 46 : _2)); 47 28 : } 48 : 49 25 : void Client::DeleteSession(const SessionKey &key) { 50 25 : cm_->GetServer()->DeleteSession(key); 51 25 : } 52 : 53 75 : void Client::Notify(const SessionKey &key, const BFD::BFDState &new_state) { 54 75 : cm_->NotifyStateChange(key, new_state == kUp); 55 75 : }