-
Notifications
You must be signed in to change notification settings - Fork 492
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
Bfd support for TSA state. #2926
Changes from 8 commits
02288e5
e41fa6d
08dfd64
dc6b875
633ee13
fad54cf
0fb802f
227e0d4
560d927
dd11002
6cceac7
a1d2889
fddfc5f
5363ed3
b673871
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,6 +74,16 @@ BfdOrch::BfdOrch(DBConnector *db, string tableName, TableConnector stateDbBfdSes | |
|
||
Orch::addExecutor(bfdStateNotificatier); | ||
register_state_change_notif = false; | ||
BgpGlobalStateOrch* bgp_global_state_orch = gDirectory.get<BgpGlobalStateOrch*>(); | ||
if (bgp_global_state_orch) | ||
{ | ||
tsa_enabled = bgp_global_state_orch->getTsaState(); | ||
} | ||
else | ||
{ | ||
tsa_enabled = false; | ||
} | ||
|
||
} | ||
|
||
BfdOrch::~BfdOrch(void) | ||
|
@@ -96,18 +106,62 @@ void BfdOrch::doTask(Consumer &consumer) | |
|
||
if (op == SET_COMMAND) | ||
{ | ||
if (!create_bfd_session(key, data)) | ||
bool tsa_shutdown_enabled = false; | ||
for (auto i : data) | ||
{ | ||
it++; | ||
continue; | ||
auto value = fvValue(i); | ||
if (fvField(i) == "tsa_shutdown" && value == "true" ) | ||
{ | ||
tsa_shutdown_enabled = true; | ||
break; | ||
} | ||
} | ||
if (tsa_shutdown_enabled) | ||
{ | ||
bfd_session_cache[key] = data; | ||
if (!tsa_enabled) | ||
{ | ||
if (!create_bfd_session(key, data)) | ||
{ | ||
it++; | ||
continue; | ||
} | ||
} | ||
else | ||
{ | ||
notify_session_state_down(key); | ||
} | ||
} | ||
else | ||
{ | ||
if (!create_bfd_session(key, data)) | ||
{ | ||
it++; | ||
continue; | ||
} | ||
} | ||
} | ||
else if (op == DEL_COMMAND) | ||
{ | ||
if (!remove_bfd_session(key)) | ||
if (bfd_session_cache.find(key) != bfd_session_cache.end() ) | ||
{ | ||
it++; | ||
continue; | ||
bfd_session_cache.erase(key); | ||
if (!tsa_enabled) | ||
{ | ||
if (!remove_bfd_session(key)) | ||
{ | ||
it++; | ||
continue; | ||
} | ||
} | ||
} | ||
else | ||
{ | ||
if (!remove_bfd_session(key)) | ||
{ | ||
it++; | ||
continue; | ||
} | ||
} | ||
} | ||
else | ||
|
@@ -298,6 +352,10 @@ bool BfdOrch::create_bfd_session(const string& key, const vector<FieldValueTuple | |
{ | ||
tos = to_uint<uint8_t>(value); | ||
} | ||
else if (fvField(i) == "tsa_shutdown") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what is the purpose of this section? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have added a comment in the code and I have changed the name of the field to shutdown_bfd_during_tsa. The BFD tsa shutdown is handled by the bfd cache in the caller function. This block is added to avoid getting the unknown parameter syslog. |
||
{ | ||
continue; | ||
} | ||
else | ||
SWSS_LOG_ERROR("Unsupported BFD attribute %s\n", fvField(i).c_str()); | ||
} | ||
|
@@ -551,3 +609,113 @@ uint32_t BfdOrch::bfd_src_port(void) | |
return (port++); | ||
} | ||
|
||
void BfdOrch::notify_session_state_down(const string& key) | ||
siqbal1986 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
size_t found_vrf = key.find(delimiter); | ||
if (found_vrf == string::npos) | ||
{ | ||
SWSS_LOG_ERROR("Failed to parse key %s, no vrf is given", key.c_str()); | ||
return; | ||
} | ||
|
||
size_t found_ifname = key.find(delimiter, found_vrf + 1); | ||
if (found_ifname == string::npos) | ||
{ | ||
SWSS_LOG_ERROR("Failed to parse key %s, no ifname is given", key.c_str()); | ||
return; | ||
} | ||
string vrf_name = key.substr(0, found_vrf); | ||
string alias = key.substr(found_vrf + 1, found_ifname - found_vrf - 1); | ||
IpAddress peer_address(key.substr(found_ifname + 1)); | ||
BfdUpdate update; | ||
update.peer = get_state_db_key(vrf_name, alias, peer_address); | ||
update.state = SAI_BFD_SESSION_STATE_DOWN; | ||
notify(SUBJECT_TYPE_BFD_SESSION_STATE_CHANGE, static_cast<void *>(&update)); | ||
return; | ||
siqbal1986 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
void BfdOrch::handleTsaStateChange(bool tsaState) | ||
{ | ||
SWSS_LOG_INFO("BfdOrch TSA state Changed to %d.\n", int(tsaState)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you please change this to NOTICE? , also log the existing state There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done. now log is in the caller function. |
||
for (auto it : bfd_session_cache) | ||
{ | ||
if (tsaState == true) | ||
siqbal1986 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
siqbal1986 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
notify_session_state_down(it.first); | ||
if (!remove_bfd_session(it.first)) | ||
{ | ||
SWSS_LOG_ERROR("Failed to remove BFD session %s\n", it.first.c_str()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please remove the error log as its handled in the remove function already There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
} | ||
} else | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
{ | ||
if (!create_bfd_session(it.first, it.second)) | ||
{ | ||
SWSS_LOG_ERROR("Failed to create BFD session %s\n", it.first.c_str()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please remove the error log There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
} | ||
} | ||
} | ||
} | ||
|
||
BgpGlobalStateOrch::BgpGlobalStateOrch(DBConnector *db, string tableName): | ||
Orch(db, tableName) | ||
{ | ||
SWSS_LOG_ENTER(); | ||
tsa_enabled = false; | ||
SWSS_LOG_ERROR("BgpGlobalStateOrch init complete\n"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is this ERROR log, please remove There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
} | ||
|
||
BgpGlobalStateOrch::~BgpGlobalStateOrch(void) | ||
{ | ||
SWSS_LOG_ENTER(); | ||
} | ||
|
||
bool BgpGlobalStateOrch::getTsaState() | ||
{ | ||
SWSS_LOG_ENTER(); | ||
return tsa_enabled; | ||
} | ||
void BgpGlobalStateOrch::doTask(Consumer &consumer) | ||
{ | ||
SWSS_LOG_ENTER(); | ||
|
||
auto it = consumer.m_toSync.begin(); | ||
while (it != consumer.m_toSync.end()) | ||
{ | ||
KeyOpFieldsValuesTuple t = it->second; | ||
|
||
string key = kfvKey(t); | ||
string op = kfvOp(t); | ||
auto data = kfvFieldsValues(t); | ||
|
||
if (op == SET_COMMAND) | ||
{ | ||
for (auto i : data) | ||
{ | ||
auto value = fvValue(i); | ||
auto type = fvField(i); | ||
SWSS_LOG_INFO("SET on key %s, data T %s, V %s\n", key.c_str(), type.c_str(), value.c_str()); | ||
if (type == "tsa_enabled") | ||
{ | ||
bool state = true ? value == "true" : false; | ||
tsa_enabled = state; | ||
BfdOrch* bfd_orch = gDirectory.get<BfdOrch*>(); | ||
|
||
if (bfd_orch) | ||
{ | ||
bfd_orch->handleTsaStateChange(state); | ||
} | ||
} | ||
} | ||
} | ||
else if (op == DEL_COMMAND) | ||
{ | ||
SWSS_LOG_ERROR("DEL on key %s is not expected.\n", key.c_str()); | ||
} | ||
else | ||
{ | ||
SWSS_LOG_ERROR("Unknown operation type %s\n", op.c_str()); | ||
} | ||
it = consumer.m_toSync.erase(it); | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1817,6 +1817,7 @@ void VNetRouteOrch::createBfdSession(const string& vnet, const NextHopKey& endpo | |
FieldValueTuple fvTuple("local_addr", src_ip.to_string()); | ||
data.push_back(fvTuple); | ||
data.emplace_back("multihop", "true"); | ||
data.emplace_back("tsa_shutdown", "true"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not clear of the meaning of this variable - 'tsa_shutdown' ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. renamed it already and added comments. |
||
bfd_session_producer_.set(key, data); | ||
bfd_sessions_[monitor_addr].bfd_state = SAI_BFD_SESSION_STATE_DOWN; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you don't need this section. Just initialize
tsa_enabled
to false in class and handle TSA change in the normal update path.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed