Line data Source code
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 20 : Client::Client(Connection *cm, ClientId id) : id_(id), cm_(cm) { 26 20 : } 27 : 28 22 : Client::~Client() { 29 : // DeleteClientSessions(); 30 22 : } 31 : 32 0 : void Client::DeleteClientSessions() { 33 0 : cm_->GetServer()->DeleteClientSessions(); 34 0 : } 35 : 36 10706 : Session *Client::GetSession(const SessionKey &key) const { 37 10706 : return cm_->GetServer()->SessionByKey(key); 38 : } 39 : 40 10706 : bool Client::Up(const SessionKey &key) const { 41 10706 : Session *session = GetSession(key); 42 10706 : return session && session->Up(); 43 : } 44 : 45 28 : void Client::AddSession(const SessionKey &key, const SessionConfig &config) { 46 28 : cm_->GetServer()->AddSession(key, config, bind(&Client::Notify, this, _1, 47 : _2)); 48 28 : } 49 : 50 25 : void Client::DeleteSession(const SessionKey &key) { 51 25 : cm_->GetServer()->DeleteSession(key); 52 25 : } 53 : 54 75 : void Client::Notify(const SessionKey &key, const BFD::BFDState &new_state) { 55 75 : cm_->NotifyStateChange(key, new_state == kUp); 56 75 : }