Skip to content

Commit

Permalink
Merge "Assure Paths deleted before Peer" into R2.21.x
Browse files Browse the repository at this point in the history
  • Loading branch information
Zuul authored and opencontrail-ci-admin committed May 9, 2016
2 parents d6416a6 + 3f63d9d commit 418b910
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 22 deletions.
13 changes: 6 additions & 7 deletions src/vnsw/agent/controller/controller_route_walker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,12 @@ bool ControllerRouteWalker::VrfDelPeer(DBTablePartBase *partition,
DBEntryBase *entry) {
VrfEntry *vrf = static_cast<VrfEntry *>(entry);
if (peer_->GetType() == Peer::BGP_PEER) {
BgpPeer *bgp_peer = static_cast<BgpPeer *>(peer_);
VrfExport::State *vrf_state = static_cast<VrfExport::State *>
(bgp_peer->GetVrfExportState(partition, entry));
// If there is no state for this peer for vrf sent, then ignore
// walk for same and continue for next entry.
if (!vrf_state) return true;

// skip starting walk on route tables if all the the route tables
// are already delete, this also safe-gaurds that StartRouteWalk
// will not be the first reference on the deleted VRF which will
// end up taking reference and setting refcount state on deleted
// VRF which can cause Bug - 1495824
if (vrf->AllRouteTableDeleted()) return true;
// Register Callback for deletion of VRF state on completion of route
// walks
RouteWalkDoneForVrfCallback(boost::bind(
Expand Down
2 changes: 1 addition & 1 deletion src/vnsw/agent/oper/agent_route.cc
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ auto_ptr<DBEntry> AgentRouteTable::AllocEntry(const DBRequestKey *k) const {
// Delete all paths from BGP Peer. Delete route if no path left
bool AgentRouteTable::DeleteAllBgpPath(DBTablePartBase *part,
DBEntryBase *entry) {
AgentRoute *route = static_cast<InetUnicastRouteEntry *>(entry);
AgentRoute *route = static_cast<AgentRoute *>(entry);
if (route && !route->IsDeleted()) {
std::list<AgentPath *> to_be_deleted_path_list;
for(Route::PathList::iterator it = route->GetPathList().begin();
Expand Down
40 changes: 26 additions & 14 deletions src/vnsw/agent/test/test_l2route.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ static void ValidateSandeshResponse(Sandesh *sandesh, vector<int> &result) {
//Validate the response by the expectation
}

class TestL2RouteState : public DBState {
public:
int id_;
};

void TestL2RouteVrfNotify(DBTablePartBase *partition, DBEntryBase *e) {
}

class RouteTest : public ::testing::Test {
public:
static void SetTunnelType(TunnelType::Type type) {
Expand Down Expand Up @@ -1260,24 +1268,28 @@ TEST_F(RouteTest, deleted_peer_walk_on_deleted_vrf) {
client->WaitForIdle();

VrfEntry *vrf1 = VrfGet("vrf1");
//Add a peer and keep a reference of same.
BgpPeer *bgp_peer_ptr = CreateBgpPeer(Ip4Address(1), "BGP Peer1");
boost::shared_ptr<BgpPeer> bgp_peer =
bgp_peer_ptr->GetBgpXmppPeer()->bgp_peer_id_ref();
//Add a peer
BgpPeer *bgp_peer = CreateBgpPeer(Ip4Address(1), "BGP Peer1");

//Take VRF reference and delete VRF.
VrfEntry *vrf2 = new VrfEntry("vrf2", 0, agent_);
vrf2->MarkDelete();
vrf2->set_table_partition(vrf1->get_table_partition());
DBTableBase *table = Agent::GetInstance()->vrf_table();
DBTableBase::ListenerId l_id =
table->Register(boost::bind(&TestL2RouteVrfNotify, _1, _2));

TestL2RouteState tmp_state;
// Hold VRF by Adding a state to it, this makes sure that refcount
// on this VRF drops to zero but it is still held by state
// so that VRF Walk Notify can walk through deleted VRF
vrf1->SetState(table, l_id, &tmp_state);

bgp_peer_ptr->route_walker()->set_type(ControllerRouteWalker::DELPEER);
bgp_peer_ptr->route_walker()->VrfWalkNotify(vrf1->get_table_partition(), vrf2);
DeleteBgpPeer(bgp_peer.get());
client->WaitForIdle();
DeleteVmportEnv(input, 1, true);
client->WaitForIdle();
bgp_peer.reset();
delete vrf2;

bgp_peer->route_walker()->set_type(ControllerRouteWalker::DELPEER);
bgp_peer->route_walker()->VrfWalkNotify(vrf1->get_table_partition(), vrf1);
DeleteBgpPeer(bgp_peer);
vrf1->ClearState(table, l_id);
table->Unregister(l_id);
client->WaitForIdle();
}

// Bug# 1508894
Expand Down

0 comments on commit 418b910

Please sign in to comment.