/
ifmap_manager.cc
97 lines (77 loc) · 3.12 KB
/
ifmap_manager.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*
* Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
*/
#include "ifmap_manager.h"
#include "ifmap_state_machine.h"
#include "ifmap/ifmap_server.h"
#include "peer_server_finder.h"
#include <sandesh/sandesh_types.h>
#include <sandesh/sandesh.h>
#include "ifmap/ifmap_server_show_types.h"
#include <boost/function.hpp>
#include <boost/asio/io_service.hpp>
IFMapManager::IFMapManager(IFMapServer *ifmap_server, const std::string& url,
const std::string& user, const std::string& passwd,
const std::string& certstore, PollReadCb readcb,
boost::asio::io_service *io_service,
DiscoveryServiceClient *ds_client)
: pollreadcb_(readcb), io_service_(io_service),
channel_(new IFMapChannel(this, user, passwd, certstore)),
state_machine_(new IFMapStateMachine(this)),
peer_finder_(new PeerIFMapServerFinder(this, ds_client, url)),
ifmap_server_(ifmap_server) {
ifmap_server->set_ifmap_manager(this);
}
IFMapManager::IFMapManager(IFMapServer *ifmap_server, const std::string& url,
const std::string& user, const std::string& passwd,
const std::string& certstore, PollReadCb readcb,
boost::asio::io_service *io_service)
: pollreadcb_(readcb), io_service_(io_service),
channel_(new IFMapChannel(this, user, passwd, certstore)),
state_machine_(new IFMapStateMachine(this)), peer_finder_(NULL),
ifmap_server_(ifmap_server) {
ifmap_server->set_ifmap_manager(this);
}
IFMapManager::IFMapManager()
: pollreadcb_(NULL), io_service_(NULL), channel_(NULL),
state_machine_(NULL), peer_finder_(NULL), ifmap_server_(NULL) {
}
IFMapManager::~IFMapManager() {
}
void IFMapManager::Start(const std::string &host, const std::string &port) {
channel_->SetHostPort(host, port);
channel_->set_sm(state_machine_.get());
state_machine_->set_channel(channel_.get());
state_machine_->Start();
}
void IFMapManager::SetChannel(IFMapChannel *channel) {
channel_.reset(channel);
}
uint64_t IFMapManager::GetChannelSequenceNumber() {
return channel_->get_sequence_number();
}
void IFMapManager::SetStartStaleEntriesCleanup(bool value) {
channel_->set_start_stale_entries_cleanup(value);
}
void IFMapManager::GetPeerServerInfo(IFMapPeerServerInfoUI &server_info) {
server_info.set_url(get_host_port());
server_info.set_connection_status(channel_->get_connection_status());
server_info.set_connection_status_change_at(
channel_->get_connection_status_change_at());
}
void IFMapManager::GetAllDSPeerInfo(IFMapDSPeerInfo *ds_peer_info) {
peer_finder_->GetAllDSPeerInfo(ds_peer_info);
}
void IFMapManager::ResetConnection(const std::string &host,
const std::string &port) {
state_machine_->ResetConnectionReqEnqueue(host, port);
}
bool IFMapManager::PeerDown() {
return peer_finder_->PeerDown();
}
std::string IFMapManager::get_url() {
return peer_finder_->get_url();
}
bool IFMapManager::get_init_done() {
return peer_finder_->get_init_done();
}