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 index a2590527c0e..4ee2bf3ea73 100644 --- 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 @@ -11,9 +11,10 @@ using namespace process; using namespace std; ConnectionStateEntry::ConnectionStateEntry(ConnectionStateTable *table, - const std::string &device_name) : - table_(table), device_name_(device_name), device_entry_(NULL), - ha_stale_dev_vn_table_(NULL) { + const std::string &device_name, + const boost::uuids::uuid &u) : + table_(table), device_name_(device_name), device_uuid_(u), + device_entry_(NULL), ha_stale_dev_vn_table_(NULL) { refcount_ = 0; } @@ -71,7 +72,8 @@ ConnectionStateTable::~ConnectionStateTable() { void ConnectionStateTable::AddIdlToConnectionState(const std::string &dev_name, OvsdbClientIdl *idl) { - ConnectionStateEntry *state = new ConnectionStateEntry(this, dev_name); + ConnectionStateEntry *state = new ConnectionStateEntry(this, dev_name, + boost::uuids::nil_uuid()); pair ret; ret = entry_map_.insert(pair(dev_name, state)); @@ -137,7 +139,7 @@ void ConnectionStateTable::PhysicalDeviceNotify(DBTablePartBase *part, if (dev->name().empty()) return; - state = new ConnectionStateEntry(this, dev->name()); + state = new ConnectionStateEntry(this, dev->name(), dev->uuid()); pair ret; ret = entry_map_.insert(pair(dev->name(), state)); @@ -146,6 +148,7 @@ void ConnectionStateTable::PhysicalDeviceNotify(DBTablePartBase *part, delete state; } state = ret.first->second; + ret.first->second->device_uuid_ = dev->uuid(); ret.first->second->device_entry_ = dev; dev->SetState(table_, id_, ret.first->second); UpdateConnectionInfo(ret.first->second, false); @@ -160,6 +163,7 @@ void ConnectionStateTable::PhysicalDeviceNotify(DBTablePartBase *part, void ConnectionStateTable::UpdateConnectionInfo(ConnectionStateEntry *entry, bool deleted) { + NotifyUve(entry, deleted); if (agent_->connection_state() == NULL) return; @@ -193,3 +197,25 @@ void ConnectionStateTable::UpdateConnectionInfo(ConnectionStateEntry *entry, } } +void ConnectionStateTable::NotifyUve(ConnectionStateEntry *entry, + bool deleted) { + /* If device uuid is not available we cannot notify Uve Module */ + if (entry->device_uuid_ == boost::uuids::nil_uuid()) + return; + + if (agent_->uve() == NULL || agent_->uve()->prouter_uve_table() == NULL) + return; + + ProuterUveTable *ptable = agent_->uve()->prouter_uve_table(); + if (deleted) { + ptable->UpdateMastership(entry->device_uuid_, false); + } else { + bool mastership = true; + if (entry->device_entry_ == NULL) { + mastership = false; + } else if (entry->idl_list_.empty()) { + mastership = false; + } + ptable->UpdateMastership(entry->device_uuid_, mastership); + } +} 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 index 382d9622f61..f2e44a416b8 100644 --- 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 @@ -15,6 +15,7 @@ #include #include +#include #include "ovsdb_client_idl.h" @@ -47,6 +48,7 @@ class ConnectionStateTable { // API to update connection info state void UpdateConnectionInfo(ConnectionStateEntry *entry, bool deleted); + void NotifyUve(ConnectionStateEntry *entry, bool deleted); Agent *agent_; DBTableBase *table_; @@ -62,7 +64,8 @@ class ConnectionStateEntry : public DBState { public: typedef std::set IdlList; ConnectionStateEntry(ConnectionStateTable *table, - const std::string &device_name); + const std::string &device_name, + const boost::uuids::uuid &u); virtual ~ConnectionStateEntry(); bool IsConnectionActive(); @@ -78,6 +81,7 @@ class ConnectionStateEntry : public DBState { ConnectionStateTable *table_; std::string device_name_; + boost::uuids::uuid device_uuid_; PhysicalDevice *device_entry_; IdlList idl_list_; // Ha Stale Dev VN table for the device, which listens to physical diff --git a/src/vnsw/agent/uve/prouter.sandesh b/src/vnsw/agent/uve/prouter.sandesh index f28cc89b1d6..81e1219f3f8 100644 --- a/src/vnsw/agent/uve/prouter.sandesh +++ b/src/vnsw/agent/uve/prouter.sandesh @@ -16,6 +16,11 @@ struct ProuterData { 4: optional list physical_interface_list 5: optional list logical_interface_list 6: optional string agent_name + /* The following list can atmost have one element. It is defined as list + to support aggregation. Backup agent will send empty list for the + following field while master agent will send its name as the only + element in the list */ + 7: optional list connected_agent_list (aggtype="union") } /** diff --git a/src/vnsw/agent/uve/prouter_uve_table.cc b/src/vnsw/agent/uve/prouter_uve_table.cc index 454dedbe718..15affdb013a 100644 --- a/src/vnsw/agent/uve/prouter_uve_table.cc +++ b/src/vnsw/agent/uve/prouter_uve_table.cc @@ -203,7 +203,7 @@ void ProuterUveTable::PhyInterfaceUveEntry::Update(const Interface *pintf) { ProuterUveTable::ProuterUveEntry::ProuterUveEntry(const PhysicalDevice *p) : name_(p->name()), uuid_(p->uuid()), physical_interface_set_(), - changed_(true), deleted_(false), renewed_(false) { + changed_(true), deleted_(false), renewed_(false), mastership_(p->master()) { } ProuterUveTable::LogicalInterfaceUveEntry::LogicalInterfaceUveEntry @@ -349,6 +349,7 @@ void ProuterUveTable::FrameProuterMsg(ProuterUveEntry *entry, ProuterData *uve) const { vector phy_if_list; vector logical_list; + vector connected_agent_list; /* We are using hostname instead of fq-name because Prouter UVE sent by * other modules to send topology information uses hostname and we want * both these information to be seen in same UVE */ @@ -371,6 +372,13 @@ void ProuterUveTable::FrameProuterMsg(ProuterUveEntry *entry, ++lit; } uve->set_logical_interface_list(logical_list); + if (entry->mastership_) { + connected_agent_list.push_back(agent_->agent_name()); + uve->set_connected_agent_list(connected_agent_list); + } else { + /* Send Empty list */ + uve->set_connected_agent_list(connected_agent_list); + } } bool ProuterUveTable::SendProuterMsg(ProuterUveEntry *entry) { @@ -424,6 +432,7 @@ ProuterUveTable::ProuterUveEntry* ProuterUveTable::AddHandler UveProuterMap::iterator it = ret.first; ProuterUveEntry *entry = it->second.get(); entry->changed_ = true; + entry->mastership_ = p->master(); if (entry->deleted_) { entry->renewed_ = true; } @@ -560,6 +569,7 @@ void ProuterUveTable::PhysicalDeviceNotify(DBTablePartBase *partition, } else { /* For Change notifications send only the msg */ ProuterUveEntry *entry = PDEntryToProuterUveEntry(pr->uuid()); + entry->mastership_ = pr->master(); entry->changed_ = true; } } @@ -853,3 +863,15 @@ void ProuterUveTable::DispatchPhysicalInterfaceMsg (const UvePhysicalInterfaceAgent &uve) { UvePhysicalInterfaceAgentTrace::Send(uve); } + +void ProuterUveTable::UpdateMastership(const boost::uuids::uuid &u, bool value) +{ + ProuterUveEntry *entry = PDEntryToProuterUveEntry(u); + if (entry == NULL) { + return; + } + if (entry->mastership_ != value) { + entry->mastership_ = value; + entry->changed_ = true; + } +} diff --git a/src/vnsw/agent/uve/prouter_uve_table.h b/src/vnsw/agent/uve/prouter_uve_table.h index 264dac72db2..009c47290f4 100644 --- a/src/vnsw/agent/uve/prouter_uve_table.h +++ b/src/vnsw/agent/uve/prouter_uve_table.h @@ -79,6 +79,7 @@ class ProuterUveTable { bool changed_; bool deleted_; bool renewed_; + bool mastership_; }; typedef boost::shared_ptr ProuterUveEntryPtr; typedef std::map UveProuterMap; @@ -113,6 +114,7 @@ class ProuterUveTable { bool TimerExpiry(); bool PITimerExpiry(); bool LITimerExpiry(); + void UpdateMastership(const boost::uuids::uuid &u, bool value); protected: UveProuterMap uve_prouter_map_;