-
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 10 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,66 @@ 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); | ||
//shutdown_bfd_during_tsa parameter is used by the BFD session creator to ensure that the the | ||
//specified session gets removed when the device goes into TSA state. | ||
//if this parameter is not specified or set to false for a session, the | ||
// corrosponding BFD session would be maintained even in TSA state. | ||
if (fvField(i) == "shutdown_bfd_during_tsa" && value == "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. @arlakshm , fyi (This param can control the individual BFD session state during TSA) |
||
{ | ||
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 +356,12 @@ bool BfdOrch::create_bfd_session(const string& key, const vector<FieldValueTuple | |
{ | ||
tos = to_uint<uint8_t>(value); | ||
} | ||
else if (fvField(i) == "shutdown_bfd_during_tsa") | ||
{ | ||
//since we are handling shutdown_bfd_during_tsa in the caller function, we need to ignore it here. | ||
//failure to ignore this parameter would cause error log. | ||
continue; | ||
} | ||
else | ||
SWSS_LOG_ERROR("Unsupported BFD attribute %s\n", fvField(i).c_str()); | ||
} | ||
|
@@ -551,3 +615,116 @@ 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. |
||
tsa_enabled = tsaState; | ||
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; | ||
if (tsa_enabled != state) | ||
siqbal1986 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
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); | ||
} | ||
} | ||
|
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