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

[BFD]Retry create BFD with different source UDP port on failure #2225

Merged
merged 5 commits into from
Apr 7, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
35 changes: 34 additions & 1 deletion orchagent/bfdorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ using namespace swss;
#define BFD_SESSION_MILLISECOND_TO_MICROSECOND 1000
#define BFD_SRCPORTINIT 49152
#define BFD_SRCPORTMAX 65536
#define NUM_BFD_SRCPORT_RETRIES 3

extern sai_bfd_api_t* sai_bfd_api;
extern sai_object_id_t gSwitchId;
Expand Down Expand Up @@ -239,6 +240,8 @@ bool BfdOrch::create_bfd_session(const string& key, const vector<FieldValueTuple
sai_attribute_t attr;
vector<sai_attribute_t> attrs;
vector<FieldValueTuple> fvVector;
uint32_t attr_idx = 0;
uint32_t src_port_attr_idx = 0;

for (auto i : data)
{
Expand Down Expand Up @@ -292,57 +295,70 @@ bool BfdOrch::create_bfd_session(const string& key, const vector<FieldValueTuple
attr.id = SAI_BFD_SESSION_ATTR_TYPE;
attr.value.s32 = bfd_session_type;
attrs.emplace_back(attr);
attr_idx++;
fvVector.emplace_back("type", session_type_lookup.at(bfd_session_type));

attr.id = SAI_BFD_SESSION_ATTR_LOCAL_DISCRIMINATOR;
attr.value.u32 = bfd_gen_id();
attrs.emplace_back(attr);
attr_idx++;

attr.id = SAI_BFD_SESSION_ATTR_UDP_SRC_PORT;
attr.value.u32 = bfd_src_port();
attrs.emplace_back(attr);
src_port_attr_idx = attr_idx;
attr_idx++;

attr.id = SAI_BFD_SESSION_ATTR_REMOTE_DISCRIMINATOR;
attr.value.u32 = 0;
attrs.emplace_back(attr);
attr_idx++;

attr.id = SAI_BFD_SESSION_ATTR_BFD_ENCAPSULATION_TYPE;
attr.value.s32 = encapsulation_type;
attrs.emplace_back(attr);
attr_idx++;

attr.id = SAI_BFD_SESSION_ATTR_IPHDR_VERSION;
attr.value.u8 = src_ip.isV4() ? 4 : 6;
attrs.emplace_back(attr);
attr_idx++;

attr.id = SAI_BFD_SESSION_ATTR_SRC_IP_ADDRESS;
copy(attr.value.ipaddr, src_ip);
attrs.emplace_back(attr);
attr_idx++;
fvVector.emplace_back("local_addr", src_ip.to_string());

attr.id = SAI_BFD_SESSION_ATTR_DST_IP_ADDRESS;
copy(attr.value.ipaddr, peer_address);
attrs.emplace_back(attr);
attr_idx++;

attr.id = SAI_BFD_SESSION_ATTR_MIN_TX;
attr.value.u32 = tx_interval * BFD_SESSION_MILLISECOND_TO_MICROSECOND;
attrs.emplace_back(attr);
attr_idx++;
fvVector.emplace_back("tx_interval", to_string(tx_interval));

attr.id = SAI_BFD_SESSION_ATTR_MIN_RX;
attr.value.u32 = rx_interval * BFD_SESSION_MILLISECOND_TO_MICROSECOND;
attrs.emplace_back(attr);
attr_idx++;
fvVector.emplace_back("rx_interval", to_string(rx_interval));

attr.id = SAI_BFD_SESSION_ATTR_MULTIPLIER;
attr.value.u8 = multiplier;
attrs.emplace_back(attr);
attr_idx++;
fvVector.emplace_back("multiplier", to_string(multiplier));

if (multihop)
{
attr.id = SAI_BFD_SESSION_ATTR_MULTIHOP;
attr.value.booldata = true;
attrs.emplace_back(attr);
attr_idx++;
fvVector.emplace_back("multihop", "true");
}
else
Expand Down Expand Up @@ -376,18 +392,22 @@ bool BfdOrch::create_bfd_session(const string& key, const vector<FieldValueTuple
attr.id = SAI_BFD_SESSION_ATTR_HW_LOOKUP_VALID;
attr.value.booldata = false;
attrs.emplace_back(attr);
attr_idx++;

attr.id = SAI_BFD_SESSION_ATTR_PORT;
attr.value.oid = port.m_port_id;
attrs.emplace_back(attr);
attr_idx++;

attr.id = SAI_BFD_SESSION_ATTR_SRC_MAC_ADDRESS;
memcpy(attr.value.mac, port.m_mac.getMac(), sizeof(sai_mac_t));
attrs.emplace_back(attr);
attr_idx++;

attr.id = SAI_BFD_SESSION_ATTR_DST_MAC_ADDRESS;
memcpy(attr.value.mac, dst_mac.getMac(), sizeof(sai_mac_t));
attrs.emplace_back(attr);
attr_idx++;
}
else
{
Expand All @@ -410,12 +430,24 @@ bool BfdOrch::create_bfd_session(const string& key, const vector<FieldValueTuple
}

attrs.emplace_back(attr);
attr_idx++;
}

fvVector.emplace_back("state", session_state_lookup.at(SAI_BFD_SESSION_STATE_DOWN));

sai_object_id_t bfd_session_id = SAI_NULL_OBJECT_ID;
sai_status_t status = sai_bfd_api->create_bfd_session(&bfd_session_id, gSwitchId, (uint32_t)attrs.size(), attrs.data());
sai_status_t status = sai_bfd_api->create_bfd_session(&bfd_session_id, gSwitchId, attr_idx, attrs.data());

for (int retry = 0; (status != SAI_STATUS_SUCCESS) && (retry < NUM_BFD_SRCPORT_RETRIES); retry++)
dgsudharsan marked this conversation as resolved.
Show resolved Hide resolved
{
auto old_num = attrs[src_port_attr_idx].value.u32;
attrs[src_port_attr_idx].value.u32 = bfd_src_port();
SWSS_LOG_WARN("BFD create using port number %d failed. Retrying with port number %d",
old_num, attrs[src_port_attr_idx].value.u32);
status = sai_bfd_api->create_bfd_session(&bfd_session_id, gSwitchId,
attr_idx, attrs.data());
}

if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_ERROR("Failed to create bfd session %s, rv:%d", key.c_str(), status);
Expand Down Expand Up @@ -487,3 +519,4 @@ uint32_t BfdOrch::bfd_src_port(void)

return (port++);
}

1 change: 1 addition & 0 deletions orchagent/bfdorch.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class BfdOrch: public Orch, public Subject

uint32_t bfd_gen_id(void);
uint32_t bfd_src_port(void);
void update_port_number(std::vector<sai_attribute_t> &attrs);

bool register_bfd_state_change_notification(void);

Expand Down