Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding Connection UVE for ToR connection
This will help reporting connection state for ToR. Change-Id: I5d9f0d80eba5305309e9a01eb0b792c3a1763a16 Closes-Bug: 1430745
- Loading branch information
Prabhjot Singh Sethi
committed
May 11, 2015
1 parent
081ca34
commit 3468494
Showing
17 changed files
with
311 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
130 changes: 130 additions & 0 deletions
130
src/vnsw/agent/ovs_tor_agent/ovsdb_client/ovsdb_client_connection_state.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
/* | ||
* Copyright (c) 2015 Juniper Networks, Inc. All rights reserved. | ||
*/ | ||
|
||
#include <base/string_util.h> | ||
#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<EntryMap::iterator, bool> ret; | ||
ret = entry_map_.insert(pair<string, ConnectionStateEntry*>(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<PhysicalDevice *>(e); | ||
ConnectionStateEntry *state = | ||
static_cast<ConnectionStateEntry *>(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<EntryMap::iterator, bool> ret; | ||
ret = entry_map_.insert(pair<string, ConnectionStateEntry*>(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); | ||
} | ||
} | ||
|
70 changes: 70 additions & 0 deletions
70
src/vnsw/agent/ovs_tor_agent/ovsdb_client/ovsdb_client_connection_state.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <tbb/atomic.h> | ||
#include <base/connection_info.h> | ||
#include <db/db.h> | ||
#include <db/db_entry.h> | ||
#include <db/db_table.h> | ||
#include <db/db_table_partition.h> | ||
|
||
#include <cmn/agent.h> | ||
#include <oper/physical_device.h> | ||
|
||
#include "ovsdb_client_idl.h" | ||
|
||
namespace OVSDB { | ||
class ConnectionStateEntry; | ||
|
||
// Table to maintain Connection State for Physical Switches/Devices | ||
class ConnectionStateTable { | ||
public: | ||
typedef std::map<std::string, ConnectionStateEntry *> 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<OvsdbClientIdl *> 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_ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.