From 3468494c82e16ed7bae6a6c009ddcb16033443ed Mon Sep 17 00:00:00 2001 From: Prabhjot Singh Sethi Date: Fri, 8 May 2015 15:46:11 +0530 Subject: [PATCH] Adding Connection UVE for ToR connection This will help reporting connection state for ToR. Change-Id: I5d9f0d80eba5305309e9a01eb0b792c3a1763a16 Closes-Bug: 1430745 --- src/base/sandesh/process_info.sandesh | 4 +- .../ovs_tor_agent/ovsdb_client/SConscript | 1 + .../ovsdb_client/ovsdb_client.cc | 10 ++ .../ovs_tor_agent/ovsdb_client/ovsdb_client.h | 4 + .../ovsdb_client_connection_state.cc | 130 ++++++++++++++++++ .../ovsdb_client_connection_state.h | 70 ++++++++++ .../ovsdb_client/ovsdb_client_idl.cc | 14 ++ .../ovsdb_client/ovsdb_client_idl.h | 5 + .../ovsdb_client/ovsdb_client_session.cc | 2 + .../ovsdb_client/ovsdb_client_session.h | 4 +- .../ovsdb_client/ovsdb_client_ssl.cc | 14 +- .../ovsdb_client/ovsdb_client_ssl.h | 4 +- .../ovsdb_client/ovsdb_client_tcp.cc | 14 +- .../ovsdb_client/ovsdb_client_tcp.h | 4 +- .../ovsdb_client/physical_switch_ovsdb.cc | 13 ++ .../ovsdb_client/physical_switch_ovsdb.h | 2 + src/vnsw/agent/uve/agent_uve_base.cc | 38 ++--- 17 files changed, 311 insertions(+), 22 deletions(-) create mode 100644 src/vnsw/agent/ovs_tor_agent/ovsdb_client/ovsdb_client_connection_state.cc create mode 100644 src/vnsw/agent/ovs_tor_agent/ovsdb_client/ovsdb_client_connection_state.h diff --git a/src/base/sandesh/process_info.sandesh b/src/base/sandesh/process_info.sandesh index 37568f983e7..a324c531329 100644 --- a/src/base/sandesh/process_info.sandesh +++ b/src/base/sandesh/process_info.sandesh @@ -14,6 +14,7 @@ enum ConnectionType { ZOOKEEPER, DISCOVERY, APISERVER, + TOR, } const map ConnectionTypeNames = { @@ -25,7 +26,8 @@ const map ConnectionTypeNames = { ConnectionType.REDIS : "Redis", ConnectionType.ZOOKEEPER : "Zookeeper", ConnectionType.DISCOVERY : "Discovery", - ConnectionType.APISERVER : "ApiServer" + ConnectionType.APISERVER : "ApiServer", + ConnectionType.TOR : "ToR" } enum ConnectionStatus { diff --git a/src/vnsw/agent/ovs_tor_agent/ovsdb_client/SConscript b/src/vnsw/agent/ovs_tor_agent/ovsdb_client/SConscript index 250b13c261b..b14986fcc89 100644 --- a/src/vnsw/agent/ovs_tor_agent/ovsdb_client/SConscript +++ b/src/vnsw/agent/ovs_tor_agent/ovsdb_client/SConscript @@ -25,6 +25,7 @@ libovsdbclient = env.Library('ovsdbclient', 'logical_switch_ovsdb.cc', 'multicast_mac_local_ovsdb.cc', 'ovsdb_client.cc', + 'ovsdb_client_connection_state.cc', 'ovsdb_client_idl.cc', 'ovsdb_client_session.cc', 'ovsdb_client_ssl.cc', diff --git a/src/vnsw/agent/ovs_tor_agent/ovsdb_client/ovsdb_client.cc b/src/vnsw/agent/ovs_tor_agent/ovsdb_client/ovsdb_client.cc index 6ab126d34a8..eab73cbcdc2 100644 --- a/src/vnsw/agent/ovs_tor_agent/ovsdb_client/ovsdb_client.cc +++ b/src/vnsw/agent/ovs_tor_agent/ovsdb_client/ovsdb_client.cc @@ -8,10 +8,12 @@ #include #include #include +#include #include #include using OVSDB::OvsdbClient; +using OVSDB::ConnectionStateTable; OvsdbClient::OvsdbClient(OvsPeerManager *manager, int keepalive_interval) : peer_manager_(manager), ksync_obj_manager_(KSyncObjectManager::Init()), @@ -21,6 +23,14 @@ OvsdbClient::OvsdbClient(OvsPeerManager *manager, int keepalive_interval) : OvsdbClient::~OvsdbClient() { } +void OvsdbClient::RegisterConnectionTable(Agent *agent) { + connection_table_.reset(new ConnectionStateTable(agent)); +} + +ConnectionStateTable *OvsdbClient::connection_table() { + return connection_table_.get(); +} + KSyncObjectManager *OvsdbClient::ksync_obj_manager() { return ksync_obj_manager_; } diff --git a/src/vnsw/agent/ovs_tor_agent/ovsdb_client/ovsdb_client.h b/src/vnsw/agent/ovs_tor_agent/ovsdb_client/ovsdb_client.h index e550283c9c7..850642523ea 100644 --- a/src/vnsw/agent/ovs_tor_agent/ovsdb_client/ovsdb_client.h +++ b/src/vnsw/agent/ovs_tor_agent/ovsdb_client/ovsdb_client.h @@ -13,6 +13,7 @@ class KSyncObjectManager; namespace OVSDB { class OvsdbClientSession; +class ConnectionStateTable; class OvsdbClient { public: OvsdbClient(OvsPeerManager *manager, int keepalive_interval); @@ -33,6 +34,8 @@ class OvsdbClient { virtual void AddSessionInfo(SandeshOvsdbClient &client) = 0; virtual void shutdown() = 0; + void RegisterConnectionTable(Agent *agent); + ConnectionStateTable *connection_table(); KSyncObjectManager *ksync_obj_manager(); int keepalive_interval() const; void Init(); @@ -42,6 +45,7 @@ class OvsdbClient { protected: OvsPeerManager *peer_manager_; private: + boost::scoped_ptr connection_table_; KSyncObjectManager *ksync_obj_manager_; int keepalive_interval_; DISALLOW_COPY_AND_ASSIGN(OvsdbClient); diff --git a/src/vnsw/agent/ovs_tor_agent/ovsdb_client/ovsdb_client_connection_state.cc b/src/vnsw/agent/ovs_tor_agent/ovsdb_client/ovsdb_client_connection_state.cc new file mode 100644 index 00000000000..c95576857f3 --- /dev/null +++ b/src/vnsw/agent/ovs_tor_agent/ovsdb_client/ovsdb_client_connection_state.cc @@ -0,0 +1,130 @@ +/* + * Copyright (c) 2015 Juniper Networks, Inc. All rights reserved. + */ + +#include +#include "ovsdb_client_connection_state.h" + +using namespace OVSDB; +using namespace process; +using namespace std; + +ConnectionStateEntry::ConnectionStateEntry(const std::string &device_name) : + device_name_(device_name), device_entry_(NULL) { +} + +ConnectionStateEntry::~ConnectionStateEntry() { +} + +ConnectionStateTable::ConnectionStateTable(Agent *agent) + : agent_(agent), table_(agent->physical_device_table()) { + id_ = table_->Register( + boost::bind(&ConnectionStateTable::PhysicalDeviceNotify, + this, _1, _2)); +} + +ConnectionStateTable::~ConnectionStateTable() { + table_->Unregister(id_); +} + +void ConnectionStateTable::AddIdlToConnectionState(const std::string &dev_name, + OvsdbClientIdl *idl) { + ConnectionStateEntry *state = new ConnectionStateEntry(dev_name); + pair ret; + ret = entry_map_.insert(pair(dev_name, + state)); + if (ret.second == false) { + // entry already existed, delete allocated memory + delete state; + } + ret.first->second->idl_list_.insert(idl); + UpdateConnectionInfo(ret.first->second, false); +} + +void ConnectionStateTable::DelIdlToConnectionState(const std::string &dev_name, + OvsdbClientIdl *idl) { + EntryMap::iterator it = entry_map_.find(dev_name); + if (it == entry_map_.end()) { + return; + } + it->second->idl_list_.erase(idl); + if (it->second->idl_list_.empty()) { + if (it->second->device_entry_ == NULL) { + UpdateConnectionInfo(it->second, true); + delete it->second; + entry_map_.erase(it); + } else { + UpdateConnectionInfo(it->second, false); + } + } +} + +void ConnectionStateTable::PhysicalDeviceNotify(DBTablePartBase *part, + DBEntryBase *e) { + PhysicalDevice *dev = static_cast(e); + ConnectionStateEntry *state = + static_cast(dev->GetState(table_, id_)); + if (dev->IsDeleted()) { + if (state) { + state->device_entry_ = NULL; + if (state->idl_list_.empty()) { + UpdateConnectionInfo(state, true); + entry_map_.erase(state->device_name_); + delete state; + } else { + UpdateConnectionInfo(state, false); + } + dev->ClearState(table_, id_); + } + return; + } + if (!state) { + state = new ConnectionStateEntry(dev->name()); + pair ret; + ret = entry_map_.insert(pair(dev->name(), + state)); + if (ret.second == false) { + // entry already existed, delete allocated memory + delete state; + } + ret.first->second->device_entry_ = dev; + dev->SetState(table_, id_, ret.first->second); + UpdateConnectionInfo(ret.first->second, false); + } +} + +void ConnectionStateTable::UpdateConnectionInfo(ConnectionStateEntry *entry, + bool deleted) { + if (agent_->connection_state() == NULL) + return; + + if (deleted) { + agent_->connection_state()->Delete(ConnectionType::TOR, + entry->device_name_); + } else { + ConnectionStatus::type status = ConnectionStatus::UP; + string message; + boost::asio::ip::tcp::endpoint ep; + if (!entry->idl_list_.empty()) { + ConnectionStateEntry::IdlList::iterator it = + entry->idl_list_.begin(); + ep.address((*it)->remote_ip()); + ep.port((*it)->remote_port()); + } + + if (entry->device_entry_ == NULL) { + status = ConnectionStatus::DOWN; + message = "Config Not Available"; + } else if (entry->idl_list_.empty()) { + status = ConnectionStatus::DOWN; + message = "ToR Not Available"; + } else { + message = "Active sessions = " + + integerToString(entry->idl_list_.size()); + } + agent_->connection_state()->Update(ConnectionType::TOR, + entry->device_name_, status, + ep, message); + } +} + diff --git a/src/vnsw/agent/ovs_tor_agent/ovsdb_client/ovsdb_client_connection_state.h b/src/vnsw/agent/ovs_tor_agent/ovsdb_client/ovsdb_client_connection_state.h new file mode 100644 index 00000000000..969391f21ad --- /dev/null +++ b/src/vnsw/agent/ovs_tor_agent/ovsdb_client/ovsdb_client_connection_state.h @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2015 Juniper Networks, Inc. All rights reserved. + */ + +#ifndef SRC_VNSW_AGENT_OVS_TOR_AGENT_OVSDB_CLIENT_CONNECTION_STATE_H_ +#define SRC_VNSW_AGENT_OVS_TOR_AGENT_OVSDB_CLIENT_CONNECTION_STATE_H_ + +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "ovsdb_client_idl.h" + +namespace OVSDB { +class ConnectionStateEntry; + +// Table to maintain Connection State for Physical Switches/Devices +class ConnectionStateTable { +public: + typedef std::map EntryMap; + explicit ConnectionStateTable(Agent *agent); + virtual ~ConnectionStateTable(); + + // Adding first IDL to ConnectionState Entry marks session Up + void AddIdlToConnectionState(const std::string &device_name, + OvsdbClientIdl *idl); + + // Deleting last IDL from ConnectionState Entry marks session Down + void DelIdlToConnectionState(const std::string &device_name, + OvsdbClientIdl *idl); + +private: + void PhysicalDeviceNotify(DBTablePartBase *part, DBEntryBase *e); + + // API to update connection info state + void UpdateConnectionInfo(ConnectionStateEntry *entry, bool deleted); + + Agent *agent_; + DBTableBase *table_; + DBTableBase::ListenerId id_; + EntryMap entry_map_; + DISALLOW_COPY_AND_ASSIGN(ConnectionStateTable); +}; + +// Connection State Entry represent a physical router, reports connection +// state Up as long as config and idl for Physical Switch exists +class ConnectionStateEntry : public DBState { +public: + typedef std::set IdlList; + explicit ConnectionStateEntry(const std::string &device_name); + virtual ~ConnectionStateEntry(); + +private: + friend class ConnectionStateTable; + std::string device_name_; + PhysicalDevice *device_entry_; + IdlList idl_list_; + DISALLOW_COPY_AND_ASSIGN(ConnectionStateEntry); +}; + +}; + +#endif //SRC_VNSW_AGENT_OVS_TOR_AGENT_OVSDB_CLIENT_CONNECTION_STATE_H_ + diff --git a/src/vnsw/agent/ovs_tor_agent/ovsdb_client/ovsdb_client_idl.cc b/src/vnsw/agent/ovs_tor_agent/ovsdb_client/ovsdb_client_idl.cc index da351469cba..ad21fc62785 100644 --- a/src/vnsw/agent/ovs_tor_agent/ovsdb_client/ovsdb_client_idl.cc +++ b/src/vnsw/agent/ovs_tor_agent/ovsdb_client/ovsdb_client_idl.cc @@ -12,6 +12,7 @@ extern "C" { }; #include #include +#include #include #include #include @@ -48,6 +49,7 @@ using OVSDB::UnicastMacLocalOvsdb; using OVSDB::MulticastMacLocalOvsdb; using OVSDB::VrfOvsdbObject; using OVSDB::VnOvsdbObject; +using OVSDB::ConnectionStateTable; namespace OVSDB { void ovsdb_wrapper_idl_callback(void *idl_base, int op, @@ -282,6 +284,18 @@ void OvsdbClientIdl::MessageProcess(struct jsonrpc_msg *msg) { receive_queue_->Enqueue(ovs_msg); } +Ip4Address OvsdbClientIdl::remote_ip() const { + return session_->remote_ip(); +} + +uint16_t OvsdbClientIdl::remote_port() const { + return session_->remote_port(); +} + +ConnectionStateTable *OvsdbClientIdl::connection_table() { + return session_->connection_table(); +} + KSyncObjectManager *OvsdbClientIdl::ksync_obj_manager() { return session_->ksync_obj_manager(); } diff --git a/src/vnsw/agent/ovs_tor_agent/ovsdb_client/ovsdb_client_idl.h b/src/vnsw/agent/ovs_tor_agent/ovsdb_client/ovsdb_client_idl.h index e9ff26d6ea5..472ddd152c2 100644 --- a/src/vnsw/agent/ovs_tor_agent/ovsdb_client/ovsdb_client_idl.h +++ b/src/vnsw/agent/ovs_tor_agent/ovsdb_client/ovsdb_client_idl.h @@ -46,6 +46,7 @@ class MulticastMacLocalOvsdb; class VrfOvsdbObject; class VnOvsdbObject; class OvsdbEntryBase; +class ConnectionStateTable; class OvsdbClientIdl; typedef boost::intrusive_ptr OvsdbClientIdlPtr; @@ -130,6 +131,10 @@ class OvsdbClientIdl { // Process jsonrpc_msg for IDL, takes ownership of jsonrpc_msg void MessageProcess(struct jsonrpc_msg *msg); + Ip4Address remote_ip() const; + uint16_t remote_port() const; + + ConnectionStateTable *connection_table(); KSyncObjectManager *ksync_obj_manager(); OvsPeer *route_peer(); bool deleted() { return deleted_; } diff --git a/src/vnsw/agent/ovs_tor_agent/ovsdb_client/ovsdb_client_session.cc b/src/vnsw/agent/ovs_tor_agent/ovsdb_client/ovsdb_client_session.cc index a4d01d0e3da..bed1a6d5c87 100644 --- a/src/vnsw/agent/ovs_tor_agent/ovsdb_client/ovsdb_client_session.cc +++ b/src/vnsw/agent/ovs_tor_agent/ovsdb_client/ovsdb_client_session.cc @@ -10,6 +10,7 @@ extern "C" { #include #include +#include #include #include #include @@ -18,6 +19,7 @@ extern "C" { using OVSDB::OvsdbClientIdl; using OVSDB::OvsdbClientSession; +using OVSDB::ConnectionStateTable; int OvsdbClientSession::ovsdb_io_task_id_ = -1; diff --git a/src/vnsw/agent/ovs_tor_agent/ovsdb_client/ovsdb_client_session.h b/src/vnsw/agent/ovs_tor_agent/ovsdb_client/ovsdb_client_session.h index 072ff51276b..1485d6c025b 100644 --- a/src/vnsw/agent/ovs_tor_agent/ovsdb_client/ovsdb_client_session.h +++ b/src/vnsw/agent/ovs_tor_agent/ovsdb_client/ovsdb_client_session.h @@ -35,8 +35,10 @@ class OvsdbClientSession { virtual int keepalive_interval() = 0; + virtual ConnectionStateTable *connection_table() = 0; virtual KSyncObjectManager *ksync_obj_manager() = 0; - virtual Ip4Address remote_ip() { return Ip4Address(); } + virtual Ip4Address remote_ip() const { return Ip4Address(); } + virtual uint16_t remote_port() const { return 0; } virtual Ip4Address tsn_ip() = 0; virtual void SendMsg(u_int8_t *buf, std::size_t len) = 0; void MessageProcess(const u_int8_t *buf, std::size_t len); diff --git a/src/vnsw/agent/ovs_tor_agent/ovsdb_client/ovsdb_client_ssl.cc b/src/vnsw/agent/ovs_tor_agent/ovsdb_client/ovsdb_client_ssl.cc index 425f4b1967a..5d945810a3e 100644 --- a/src/vnsw/agent/ovs_tor_agent/ovsdb_client/ovsdb_client_ssl.cc +++ b/src/vnsw/agent/ovs_tor_agent/ovsdb_client/ovsdb_client_ssl.cc @@ -8,6 +8,7 @@ #include #include #include +#include #include @@ -15,6 +16,7 @@ using OVSDB::OvsdbClientSession; using OVSDB::OvsdbClientSsl; using OVSDB::OvsdbClientSslSession; using OVSDB::OvsdbClientTcpSessionReader; +using OVSDB::ConnectionStateTable; OvsdbClientSsl::OvsdbClientSsl(Agent *agent, TorAgentParam *params, OvsPeerManager *manager) : @@ -58,6 +60,7 @@ OvsdbClientSsl::~OvsdbClientSsl() { } void OvsdbClientSsl::RegisterClients() { + RegisterConnectionTable(agent_); Initialize(ssl_server_port_); } @@ -199,6 +202,11 @@ int OvsdbClientSslSession::keepalive_interval() { return ovs_server->keepalive_interval(); } +ConnectionStateTable *OvsdbClientSslSession::connection_table() { + OvsdbClientSsl *ovs_server = static_cast(server()); + return ovs_server->connection_table(); +} + KSyncObjectManager *OvsdbClientSslSession::ksync_obj_manager() { OvsdbClientSsl *ovs_server = static_cast(server()); return ovs_server->ksync_obj_manager(); @@ -223,10 +231,14 @@ void OvsdbClientSslSession::TriggerClose() { EnqueueEvent(TcpSession::CLOSE); } -Ip4Address OvsdbClientSslSession::remote_ip() { +Ip4Address OvsdbClientSslSession::remote_ip() const { return remote_endpoint().address().to_v4(); } +uint16_t OvsdbClientSslSession::remote_port() const { + return remote_endpoint().port(); +} + bool OvsdbClientSslSession::ProcessSessionEvent(OvsdbSessionEvent ovs_event) { boost::system::error_code ec; switch (ovs_event.event) { diff --git a/src/vnsw/agent/ovs_tor_agent/ovsdb_client/ovsdb_client_ssl.h b/src/vnsw/agent/ovs_tor_agent/ovsdb_client/ovsdb_client_ssl.h index 2e2970ac6a5..78a9da195fb 100644 --- a/src/vnsw/agent/ovs_tor_agent/ovsdb_client/ovsdb_client_ssl.h +++ b/src/vnsw/agent/ovs_tor_agent/ovsdb_client/ovsdb_client_ssl.h @@ -33,6 +33,7 @@ class OvsdbClientSslSession : public OvsdbClientSession, public SslSession { int keepalive_interval(); + ConnectionStateTable *connection_table(); KSyncObjectManager *ksync_obj_manager(); Ip4Address tsn_ip(); @@ -45,7 +46,8 @@ class OvsdbClientSslSession : public OvsdbClientSession, public SslSession { void TriggerClose(); // method to return ip address of remoter endpoint - virtual Ip4Address remote_ip(); + virtual Ip4Address remote_ip() const; + virtual uint16_t remote_port() const; // Dequeue event from workqueue for processing bool ProcessSessionEvent(OvsdbSessionEvent event); diff --git a/src/vnsw/agent/ovs_tor_agent/ovsdb_client/ovsdb_client_tcp.cc b/src/vnsw/agent/ovs_tor_agent/ovsdb_client/ovsdb_client_tcp.cc index 48a4f1bde8e..c0edd8abe9d 100644 --- a/src/vnsw/agent/ovs_tor_agent/ovsdb_client/ovsdb_client_tcp.cc +++ b/src/vnsw/agent/ovs_tor_agent/ovsdb_client/ovsdb_client_tcp.cc @@ -7,11 +7,13 @@ #include #include #include +#include using OVSDB::OvsdbClientSession; using OVSDB::OvsdbClientTcp; using OVSDB::OvsdbClientTcpSession; using OVSDB::OvsdbClientTcpSessionReader; +using OVSDB::ConnectionStateTable; OvsdbClientTcp::OvsdbClientTcp(Agent *agent, IpAddress tor_ip, int tor_port, IpAddress tsn_ip, int keepalive_interval, OvsPeerManager *manager) : @@ -24,6 +26,7 @@ OvsdbClientTcp::~OvsdbClientTcp() { } void OvsdbClientTcp::RegisterClients() { + RegisterConnectionTable(agent_); session_ = CreateSession(); Connect(session_, server_ep_); } @@ -149,6 +152,11 @@ int OvsdbClientTcpSession::keepalive_interval() { return ovs_server->keepalive_interval(); } +ConnectionStateTable *OvsdbClientTcpSession::connection_table() { + OvsdbClientTcp *ovs_server = static_cast(server()); + return ovs_server->connection_table(); +} + KSyncObjectManager *OvsdbClientTcpSession::ksync_obj_manager() { OvsdbClientTcp *ovs_server = static_cast(server()); return ovs_server->ksync_obj_manager(); @@ -175,10 +183,14 @@ void OvsdbClientTcpSession::TriggerClose() { session_event_queue_->Enqueue(ovs_event); } -Ip4Address OvsdbClientTcpSession::remote_ip() { +Ip4Address OvsdbClientTcpSession::remote_ip() const { return remote_endpoint().address().to_v4(); } +uint16_t OvsdbClientTcpSession::remote_port() const { + return remote_endpoint().port(); +} + bool OvsdbClientTcpSession::ProcessSessionEvent(OvsdbSessionEvent ovs_event) { boost::system::error_code ec; switch (ovs_event.event) { diff --git a/src/vnsw/agent/ovs_tor_agent/ovsdb_client/ovsdb_client_tcp.h b/src/vnsw/agent/ovs_tor_agent/ovsdb_client/ovsdb_client_tcp.h index 36934f3afd8..c74b8f3187d 100644 --- a/src/vnsw/agent/ovs_tor_agent/ovsdb_client/ovsdb_client_tcp.h +++ b/src/vnsw/agent/ovs_tor_agent/ovsdb_client/ovsdb_client_tcp.h @@ -55,6 +55,7 @@ class OvsdbClientTcpSession : public OvsdbClientSession, public TcpSession { int keepalive_interval(); + ConnectionStateTable *connection_table(); KSyncObjectManager *ksync_obj_manager(); Ip4Address tsn_ip(); @@ -67,7 +68,8 @@ class OvsdbClientTcpSession : public OvsdbClientSession, public TcpSession { void TriggerClose(); // method to return ip address of remoter endpoint - virtual Ip4Address remote_ip(); + virtual Ip4Address remote_ip() const; + virtual uint16_t remote_port() const; // Dequeue event from workqueue for processing bool ProcessSessionEvent(OvsdbSessionEvent event); diff --git a/src/vnsw/agent/ovs_tor_agent/ovsdb_client/physical_switch_ovsdb.cc b/src/vnsw/agent/ovs_tor_agent/ovsdb_client/physical_switch_ovsdb.cc index f42e008ec8e..7f2c9ed9556 100644 --- a/src/vnsw/agent/ovs_tor_agent/ovsdb_client/physical_switch_ovsdb.cc +++ b/src/vnsw/agent/ovs_tor_agent/ovsdb_client/physical_switch_ovsdb.cc @@ -12,6 +12,7 @@ extern "C" { #include #include #include +#include #include #include #include @@ -30,6 +31,18 @@ PhysicalSwitchEntry::PhysicalSwitchEntry(PhysicalSwitchTable *table, PhysicalSwitchEntry::~PhysicalSwitchEntry() { } +bool PhysicalSwitchEntry::Add() { + table_->client_idl()->connection_table()->AddIdlToConnectionState( + name_, table_->client_idl()); + return true; +} + +bool PhysicalSwitchEntry::Delete() { + table_->client_idl()->connection_table()->DelIdlToConnectionState( + name_, table_->client_idl()); + return true; +} + Ip4Address &PhysicalSwitchEntry::tunnel_ip() { return tunnel_ip_; } diff --git a/src/vnsw/agent/ovs_tor_agent/ovsdb_client/physical_switch_ovsdb.h b/src/vnsw/agent/ovs_tor_agent/ovsdb_client/physical_switch_ovsdb.h index 633395f4cfe..ca3cc1f6632 100644 --- a/src/vnsw/agent/ovs_tor_agent/ovsdb_client/physical_switch_ovsdb.h +++ b/src/vnsw/agent/ovs_tor_agent/ovsdb_client/physical_switch_ovsdb.h @@ -32,6 +32,8 @@ class PhysicalSwitchEntry : public OvsdbEntry { PhysicalSwitchEntry(PhysicalSwitchTable *table, const std::string &name); ~PhysicalSwitchEntry(); + bool Add(); + bool Delete(); Ip4Address &tunnel_ip(); const std::string &name(); void set_tunnel_ip(std::string ip); diff --git a/src/vnsw/agent/uve/agent_uve_base.cc b/src/vnsw/agent/uve/agent_uve_base.cc index 4baf90377cd..b57fc8c1a61 100644 --- a/src/vnsw/agent/uve/agent_uve_base.cc +++ b/src/vnsw/agent/uve/agent_uve_base.cc @@ -19,6 +19,7 @@ #include using process::ConnectionInfo; +using process::ConnectionType; using process::ProcessState; using process::ConnectionStatus; using process::ConnectionState; @@ -117,6 +118,12 @@ uint8_t AgentUveBase::ExpectedConnections(uint8_t &num_control_nodes, cfg->collector_server_list().size() != 0) { count++; } + + // for TOR agent add physical device count to the count + if (agent_->tor_agent_enabled()) { + count += agent_->physical_device_table()->Size(); + } + return count; } @@ -144,28 +151,24 @@ void AgentUveBase::VrouterAgentProcessState std::string cup(g_process_info_constants.ConnectionStatusNames. find(ConnectionStatus::UP)->second); bool is_cup = true; + bool is_tor_cup = true; + string tor_type(g_process_info_constants.ConnectionTypeNames. + find(ConnectionType::TOR)->second); // Iterate to determine process connectivity status for (std::vector::const_iterator it = cinfos.begin(); it != cinfos.end(); it++) { const ConnectionInfo &cinfo(*it); const std::string &conn_status(cinfo.get_status()); if (conn_status != cup) { + if (cinfo.get_type() == tor_type) { + is_tor_cup = false; + } if (cinfo.get_name().compare(0, 13, agent_->xmpp_control_node_prefix()) == 0) { down_control_nodes++; - is_cup = false; - UpdateMessage(cinfo, message); - continue; - } else if (cinfo.get_name().compare(0, 11, - agent_->xmpp_dns_server_prefix()) == 0) { - is_cup = false; - UpdateMessage(cinfo, message); - continue; - } else { - is_cup = false; - UpdateMessage(cinfo, message); - continue; } + is_cup = false; + UpdateMessage(cinfo, message); } } if ((num_control_nodes == 0) || (num_control_nodes == down_control_nodes)) { @@ -173,17 +176,20 @@ void AgentUveBase::VrouterAgentProcessState if ((num_control_nodes == 0) && message.empty()) { message = "No control-nodes configured"; } + } else if (!is_tor_cup) { + // waiting for TOR to connect + pstate = ProcessState::NON_FUNCTIONAL; } else { pstate = ProcessState::FUNCTIONAL; } + if (!is_cup) { + message += " connection down"; + } if (num_conns != expected_conns) { - message = "Number of connections:" + integerToString(num_conns) + + message += " Number of connections:" + integerToString(num_conns) + ", Expected: " + integerToString(expected_conns); return; } - if (!is_cup) { - message += " connection down"; - } return; }