Skip to content

Commit

Permalink
Holding the UUID from ID_PERMS in config DBState in DB Add and using it
Browse files Browse the repository at this point in the history
for Config Delete
closes-bug: #1420209

Change-Id: I3b3f591b3730605660bcdef9c5c07503c55cc09b
  • Loading branch information
divakardhar committed Feb 19, 2015
1 parent 54e50e1 commit 6a9b4be
Show file tree
Hide file tree
Showing 34 changed files with 553 additions and 152 deletions.
35 changes: 31 additions & 4 deletions src/vnsw/agent/cfg/cfg_filter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -66,23 +66,50 @@ bool CfgFilter::CheckProperty(DBTable *table, IFMapNode *node, DBRequest *req,

void CfgFilter::Init() {
agent_cfg_->cfg_vm_table()->RegisterPreFilter
(boost::bind(&CfgFilter::CheckProperty, this, _1, _2, _3,
(boost::bind(&CfgFilter::CheckProperty, this, _1, _2, _3,
VirtualMachine::ID_PERMS));

agent_cfg_->cfg_vn_table()->RegisterPreFilter
(boost::bind(&CfgFilter::CheckProperty, this, _1, _2, _3,
(boost::bind(&CfgFilter::CheckProperty, this, _1, _2, _3,
VirtualNetwork::ID_PERMS));

agent_cfg_->cfg_vm_interface_table()->RegisterPreFilter
(boost::bind(&CfgFilter::CheckProperty, this, _1, _2, _3,
(boost::bind(&CfgFilter::CheckProperty, this, _1, _2, _3,
VirtualMachineInterface::ID_PERMS));

agent_cfg_->cfg_acl_table()->RegisterPreFilter
(boost::bind(&CfgFilter::CheckProperty, this, _1, _2, _3,
(boost::bind(&CfgFilter::CheckProperty, this, _1, _2, _3,
AccessControlList::ID_PERMS));

agent_cfg_->cfg_loadbalancer_table()->RegisterPreFilter
(boost::bind(&CfgFilter::CheckProperty, this, _1, _2, _3,
LoadbalancerPool::ID_PERMS));

agent_cfg_->cfg_service_instance_table()->RegisterPreFilter
(boost::bind(&CfgFilter::CheckProperty, this, _1, _2, _3,
ServiceInstance::ID_PERMS));

agent_cfg_->cfg_security_group_table()->RegisterPreFilter
(boost::bind(&CfgFilter::CheckProperty, this, _1, _2, _3,
SecurityGroup::ID_PERMS));

agent_cfg_->cfg_logical_port_table()->RegisterPreFilter
(boost::bind(&CfgFilter::CheckProperty, this, _1, _2, _3,
LogicalInterface::ID_PERMS));

agent_cfg_->cfg_physical_device_table()->RegisterPreFilter
(boost::bind(&CfgFilter::CheckProperty, this, _1, _2, _3,
PhysicalRouter::ID_PERMS));
}

void CfgFilter::Shutdown() {
agent_cfg_->cfg_vm_table()->RegisterPreFilter(NULL);
agent_cfg_->cfg_vn_table()->RegisterPreFilter(NULL);
agent_cfg_->cfg_vm_interface_table()->RegisterPreFilter(NULL);
agent_cfg_->cfg_acl_table()->RegisterPreFilter(NULL);
agent_cfg_->cfg_loadbalancer_table()->RegisterPreFilter(NULL);
agent_cfg_->cfg_service_instance_table()->RegisterPreFilter(NULL);
agent_cfg_->cfg_security_group_table()->RegisterPreFilter(NULL);
agent_cfg_->cfg_logical_port_table()->RegisterPreFilter(NULL);
agent_cfg_->cfg_physical_device_table()->RegisterPreFilter(NULL);
}
27 changes: 24 additions & 3 deletions src/vnsw/agent/cfg/cfg_init.cc
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,9 @@ void AgentConfig::RegisterDBClients(DB *db) {
cfg_listener_->Register("virtual-network-network-ipam",
boost::bind(&VnTable::IpamVnSync, _1), -1);
cfg_listener_->Register("network-ipam", boost::bind(&DomainConfig::IpamSync,
agent_->domain_config_table(), _1), NetworkIpam::ID_PERMS);
agent_->domain_config_table(), _1), -1);
cfg_listener_->Register("virtual-DNS", boost::bind(&DomainConfig::VDnsSync,
agent_->domain_config_table(), _1), VirtualDns::ID_PERMS);
agent_->domain_config_table(), _1), -1);
cfg_listener_->Register
("virtual-machine-interface-routing-instance",
boost::bind(&InterfaceTable::VmInterfaceVrfSync,
Expand Down Expand Up @@ -214,10 +214,25 @@ void AgentConfig::RegisterDBClients(DB *db) {
assert(cfg_vm_port_vrf_table_);

cfg_route_table_ = (static_cast<IFMapAgentTable *>
(IFMapTable::FindTable(agent_->db(),
(IFMapTable::FindTable(agent_->db(),
"interface-route-table")));
assert(cfg_route_table_);

cfg_loadbalancer_table_ = (static_cast<IFMapAgentTable *>
(IFMapTable::FindTable(agent_->db(),
"loadbalancer_pool")));
assert(cfg_loadbalancer_table_);

cfg_service_instance_table_ = (static_cast<IFMapAgentTable *>
(IFMapTable::FindTable(agent_->db(),
"service_instance")));
assert(cfg_service_instance_table_);

cfg_security_group_table_ = (static_cast<IFMapAgentTable *>
(IFMapTable::FindTable(agent_->db(),
"security_group")));
assert(cfg_security_group_table_);

cfg_subnet_table_ = (static_cast<IFMapAgentTable *>
(IFMapTable::FindTable(agent_->db(),
"subnet")));
Expand All @@ -228,6 +243,12 @@ void AgentConfig::RegisterDBClients(DB *db) {
"logical-interface")));
assert(cfg_logical_port_table_);

cfg_physical_device_table_ = (static_cast<IFMapAgentTable *>
(IFMapTable::FindTable(agent_->db(),
"physical-router")));
assert(cfg_physical_device_table_);


cfg_interface_client_->Init();
}

Expand Down
20 changes: 20 additions & 0 deletions src/vnsw/agent/cfg/cfg_init.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,22 @@ class AgentConfig {
return cfg_logical_port_table_;
}

IFMapAgentTable *cfg_loadbalancer_table() const {
return cfg_loadbalancer_table_;
}

IFMapAgentTable *cfg_service_instance_table() const {
return cfg_service_instance_table_;
}

IFMapAgentTable *cfg_security_group_table() const {
return cfg_security_group_table_;
}

IFMapAgentTable *cfg_physical_device_table() const {
return cfg_physical_device_table_;
}

Agent *agent() const { return agent_; }
CfgFilter *cfg_filter() const { return cfg_filter_.get(); }
CfgListener *cfg_listener() const { return cfg_listener_.get(); }
Expand Down Expand Up @@ -118,6 +134,10 @@ class AgentConfig {
IFMapAgentTable *cfg_service_template_table_;
IFMapAgentTable *cfg_subnet_table_;
IFMapAgentTable *cfg_logical_port_table_;
IFMapAgentTable *cfg_loadbalancer_table_;
IFMapAgentTable *cfg_service_instance_table_;
IFMapAgentTable *cfg_security_group_table_;
IFMapAgentTable *cfg_physical_device_table_;

DISALLOW_COPY_AND_ASSIGN(AgentConfig);
};
Expand Down
23 changes: 23 additions & 0 deletions src/vnsw/agent/cfg/cfg_listener.cc
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ void CfgListener::Shutdown() {
cfg_listener_id_map_.clear();
}


// Get CfgDBState set for an IFNode
CfgDBState *CfgListener::GetCfgDBState(IFMapTable *table, DBEntryBase *dbe,
DBTableBase::ListenerId &id) {
Expand All @@ -78,6 +79,19 @@ CfgDBState *CfgListener::GetCfgDBState(IFMapTable *table, DBEntryBase *dbe,
return static_cast<CfgDBState *>(dbe->GetState(table, id));
}


bool CfgListener::GetCfgDBStateUuid(IFMapNode *node, boost::uuids::uuid &id) {

DBEntryBase *dbe = static_cast <DBEntryBase *> (node);
DBTableBase::ListenerId lid = 0;
CfgDBState *state = GetCfgDBState(node->table(), dbe, lid);
if (!state || (state->uuid_ == boost::uuids::nil_uuid()))
return false;

id = state->uuid_;
return true;
}

// When traversing graph, check if an IFMapNode can be used. Conditions are,
// - The node is not in deleted state
// - The node was notified earlier
Expand Down Expand Up @@ -144,6 +158,11 @@ AgentDBTable* CfgListener::GetOperDBTable(IFMapNode *node) {
return NULL;
}
const CfgTableListenerInfo *info = &loc->second;

// IF delete operation lets not bother about mandatory fields
if (node->IsDeleted())
return info->table_;

// Check for presence of ID_PERMS if configured
if (info->need_property_id_ >= 0) {
const IFMapObject *obj = node->GetObject();
Expand Down Expand Up @@ -308,6 +327,10 @@ void CfgListener::NodeNotify(AgentDBTable *oper_table, IFMapNode *node) {
if (node->IsDeleted()) {
req.oper = DBRequest::DB_ENTRY_DELETE;
} else {
DBEntryBase *dbe = static_cast <DBEntryBase *>(node);
DBTableBase::ListenerId lid = 0;
CfgDBState *state = GetCfgDBState(node->table(), dbe, lid);
oper_table->IFNodeToUuid(node, state->uuid_);
req.oper = DBRequest::DB_ENTRY_ADD_CHANGE;
}

Expand Down
7 changes: 5 additions & 2 deletions src/vnsw/agent/cfg/cfg_listener.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ class DB;

class CfgDBState : public DBState {
public:
CfgDBState() : notify_count_(0) { };
uint32_t notify_count_;
CfgDBState() : notify_count_(0), uuid_(boost::uuids::nil_uuid()) { };
bool notify_count_;
boost::uuids::uuid uuid_;
};

class CfgListener {
Expand Down Expand Up @@ -67,6 +68,8 @@ class CfgListener {
bool SkipNode(IFMapNode *node);
bool SkipNode(IFMapNode *node, IFMapAgentTable *table);

bool GetCfgDBStateUuid(IFMapNode *node, boost::uuids::uuid &id);

// Callback invoked for each IFMap neighbor node
typedef boost::function<void(const Agent *agent, const char *name,
IFMapNode *node, AgentKey *key,
Expand Down
4 changes: 4 additions & 0 deletions src/vnsw/agent/cmn/agent_db.cc
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ void AgentDBTablePartition::Remove(DBEntryBase *entry) {
DBTablePartition::Remove(entry);
}

bool AgentDBTable::IFNodeToUuid(IFMapNode *node, boost::uuids::uuid &id) {
return false;
}

void AgentDBTable::Input(DBTablePartition *partition, DBClient *client,
DBRequest *req) {
AgentKey *key = static_cast<AgentKey *>(req->key.get());
Expand Down
2 changes: 2 additions & 0 deletions src/vnsw/agent/cmn/agent_db.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ class AgentDBTable : public DBTable {
assert(0);
return false;
}
virtual bool IFNodeToUuid(IFMapNode *node, boost::uuids::uuid &id);

virtual DBTablePartition *AllocPartition(int index) {
return new AgentDBTablePartition(this, index);
};
Expand Down
13 changes: 11 additions & 2 deletions src/vnsw/agent/filter/acl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <agent_types.h>

#include <cfg/cfg_init.h>
#include <cfg/cfg_listener.h>

#include <filter/traffic_action.h>
#include <filter/acl_entry_match.h>
Expand Down Expand Up @@ -313,11 +314,19 @@ static void AclObjectTrace(AgentLogEvent::type event, AclSpec &acl_spec)
}
}

bool AclTable::IFNodeToReq(IFMapNode *node, DBRequest &req) {
bool AclTable::IFNodeToUuid(IFMapNode *node, boost::uuids::uuid &u) {
AccessControlList *cfg_acl = static_cast <AccessControlList *> (node->GetObject());
autogen::IdPermsType id_perms = cfg_acl->id_perms();
boost::uuids::uuid u;
CfgUuidSet(id_perms.uuid.uuid_mslong, id_perms.uuid.uuid_lslong, u);
return true;
}

bool AclTable::IFNodeToReq(IFMapNode *node, DBRequest &req) {

AccessControlList *cfg_acl = static_cast <AccessControlList *> (node->GetObject());
uuid u;
if (agent()->cfg_listener()->GetCfgDBStateUuid(node, u) == false)
return false;

// Delete ACL
if (req.oper == DBRequest::DB_ENTRY_DELETE) {
Expand Down
1 change: 1 addition & 0 deletions src/vnsw/agent/filter/acl.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ class AclTable : public AgentDBTable {
virtual bool Delete(DBEntry *entry, const DBRequest *req);

virtual bool IFNodeToReq(IFMapNode *node, DBRequest &req);
virtual bool IFNodeToUuid(IFMapNode *node, boost::uuids::uuid &u);

static DBTableBase *CreateTable(DB *db, const std::string &name);
TrafficAction::Action ConvertActionString(std::string action) const;
Expand Down
2 changes: 0 additions & 2 deletions src/vnsw/agent/kstate/test/test_kstate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,6 @@ class KStateTest : public ::testing::Test {
};

bool KStateTest::ksync_init_;

TEST_F(KStateTest, IfDumpTest) {
int if_count = 0;
TestIfKState::Init();
Expand Down Expand Up @@ -267,7 +266,6 @@ TEST_F(KStateTest, NHDumpTest) {

DeletePorts(max_ports);
}

TEST_F(KStateTest, NHGetTest) {
int nh_count = 0;
TestNHKState::Init();
Expand Down

0 comments on commit 6a9b4be

Please sign in to comment.