Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed Orchagent crashed when add and delete route at same time(#3436) #3438

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion orchagent/routeorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -975,6 +975,7 @@ void RouteOrch::doTask(Consumer& consumer)
// Go through the bulker results
auto it_prev = consumer.m_toSync.begin();
m_bulkNhgReducedRefCnt.clear();
m_bulkNhReducedRefCnt.clear();
while (it_prev != it)
{
KeyOpFieldsValuesTuple t = it_prev->second;
Expand Down Expand Up @@ -1070,6 +1071,13 @@ void RouteOrch::doTask(Consumer& consumer)
removeNextHopGroup(it_nhg.first);
}
}
for (auto& it_nh : m_bulkNhReducedRefCnt)
{
if (it_nh.isMplsNextHop() && (m_neighOrch->getNextHopRefCount(it_nh) == 0))
{
m_neighOrch->removeMplsNextHop(it_nh);
}
}
}
}

Expand Down Expand Up @@ -2608,7 +2616,7 @@ bool RouteOrch::removeRoutePost(const RouteBulkContext& ctx)
if (nexthop.isMplsNextHop() &&
(m_neighOrch->getNextHopRefCount(nexthop) == 0))
{
m_neighOrch->removeMplsNextHop(nexthop);
m_bulkNhReducedRefCnt.push_back(nexthop);
}
else if (nexthop.isSrv6NextHop() &&
(m_neighOrch->getNextHopRefCount(nexthop) == 0))
Expand Down
2 changes: 2 additions & 0 deletions orchagent/routeorch.h
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,8 @@ class RouteOrch : public Orch, public Subject
std::set<std::pair<NextHopGroupKey, sai_object_id_t>> m_bulkNhgReducedRefCnt;
/* m_bulkNhgReducedRefCnt: nexthop, vrf_id */

std::vector<NextHopKey> m_bulkNhReducedRefCnt;

std::set<IpPrefix> m_SubnetDecapTermsCreated;
ProducerStateTable m_appTunnelDecapTermProducer;

Expand Down
113 changes: 113 additions & 0 deletions tests/mock_tests/routeorch_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,119 @@ namespace routeorch_test
ASSERT_EQ(current_remove_count + 1, remove_route_count);
ASSERT_EQ(current_set_count, set_route_count);
}

TEST_F(RouteOrchTest, RouteOrchTestDelSetSameVrf)
{
std::deque<KeyOpFieldsValuesTuple> entries;

// Create Vrf1
entries.push_back({"Vrf1", "SET", { {"v4", "true"} }});
auto vrf_consumer = dynamic_cast<Consumer *>(gVrfOrch->getExecutor(APP_VRF_TABLE_NAME));
vrf_consumer->addToSync(entries);
static_cast<Orch *>(gVrfOrch)->doTask();
entries.clear();

// Add route to Vrf1
entries.push_back({"Vrf1:1.1.1.0/24", "SET", { {"ifname", "Ethernet0"},
{"nexthop", "10.0.0.3"},
{"mpls_nh", "push16/80"}}});
auto consumer = dynamic_cast<Consumer *>(gRouteOrch->getExecutor(APP_ROUTE_TABLE_NAME));
consumer->addToSync(entries);
auto current_create_count = create_route_count;
auto current_remove_count = remove_route_count;
auto current_set_count = set_route_count;

static_cast<Orch *>(gRouteOrch)->doTask();
ASSERT_EQ(current_create_count + 1, create_route_count);
ASSERT_EQ(current_remove_count, remove_route_count);
ASSERT_EQ(current_set_count, set_route_count);
entries.clear();

//Del route form vrf1
entries.push_back({"Vrf1:1.1.1.0/24", "DEL", { {} }});
consumer = dynamic_cast<Consumer *>(gRouteOrch->getExecutor(APP_ROUTE_TABLE_NAME));
consumer->addToSync(entries);
current_create_count = create_route_count;
current_remove_count = remove_route_count;
current_set_count = set_route_count;

static_cast<Orch *>(gRouteOrch)->doTask();
ASSERT_EQ(current_create_count, create_route_count);
ASSERT_EQ(current_remove_count + 1, remove_route_count);
ASSERT_EQ(current_set_count, set_route_count);
entries.clear();

// Deleting VRF
entries.push_back({"Vrf1", "DEL", { {"v4", "true"} }});
vrf_consumer->addToSync(entries);
static_cast<Orch *>(gVrfOrch)->doTask();
}

TEST_F(RouteOrchTest, RouteOrchTestDelSetDiffVrf)
{
std::deque<KeyOpFieldsValuesTuple> entries;

// Create Vrf1 and Vrf2
entries.push_back({"Vrf1", "SET", { {"v4", "true"} }});
entries.push_back({"Vrf2", "SET", { {"v4", "true"} }});
auto vrf_consumer = dynamic_cast<Consumer *>(gVrfOrch->getExecutor(APP_VRF_TABLE_NAME));
vrf_consumer->addToSync(entries);
static_cast<Orch *>(gVrfOrch)->doTask();
entries.clear();

// Add route to Vrf1
entries.push_back({"Vrf1:1.1.1.0/24", "SET", { {"ifname", "Ethernet0"},
{"nexthop", "10.0.0.3"},
{"mpls_nh", "push16/80"}}});
auto consumer = dynamic_cast<Consumer *>(gRouteOrch->getExecutor(APP_ROUTE_TABLE_NAME));
consumer->addToSync(entries);
auto current_create_count = create_route_count;
auto current_remove_count = remove_route_count;
auto current_set_count = set_route_count;

static_cast<Orch *>(gRouteOrch)->doTask();
ASSERT_EQ(current_create_count + 1, create_route_count);
ASSERT_EQ(current_remove_count, remove_route_count);
ASSERT_EQ(current_set_count, set_route_count);
entries.clear();

//Del route form vrf1 and add to Vrf2
entries.push_back({"Vrf1:1.1.1.0/24", "DEL", { {} }});
entries.push_back({"Vrf2:1.1.1.0/24", "SET", { {"ifname", "Ethernet0"},
{"nexthop", "10.0.0.3"},
{"mpls_nh", "push16/80"}}});
consumer = dynamic_cast<Consumer *>(gRouteOrch->getExecutor(APP_ROUTE_TABLE_NAME));
consumer->addToSync(entries);
current_create_count = create_route_count;
current_remove_count = remove_route_count;
current_set_count = set_route_count;

static_cast<Orch *>(gRouteOrch)->doTask();
ASSERT_EQ(current_create_count + 1, create_route_count);
ASSERT_EQ(current_remove_count + 1, remove_route_count);
ASSERT_EQ(current_set_count, set_route_count);
entries.clear();

//Del route form vrf2
entries.push_back({"Vrf2:1.1.1.0/24", "DEL", { {} }});
consumer = dynamic_cast<Consumer *>(gRouteOrch->getExecutor(APP_ROUTE_TABLE_NAME));
consumer->addToSync(entries);
current_create_count = create_route_count;
current_remove_count = remove_route_count;
current_set_count = set_route_count;

static_cast<Orch *>(gRouteOrch)->doTask();
ASSERT_EQ(current_create_count, create_route_count);
ASSERT_EQ(current_remove_count + 1, remove_route_count);
ASSERT_EQ(current_set_count, set_route_count);
entries.clear();

// Deleting VRF
entries.push_back({"Vrf1", "DEL", { {"v4", "true"} }});
entries.push_back({"Vrf2", "DEL", { {"v4", "true"} }});
vrf_consumer->addToSync(entries);
static_cast<Orch *>(gVrfOrch)->doTask();
}

TEST_F(RouteOrchTest, RouteOrchTestDelSetDefaultRoute)
{
Expand Down
Loading