Skip to content

Commit

Permalink
Merge branch 'pr2' into add-p4orch
Browse files Browse the repository at this point in the history
  • Loading branch information
donNewtonAlpha committed Nov 2, 2021
2 parents 07831eb + 988c7ff commit 97383d3
Show file tree
Hide file tree
Showing 4 changed files with 204 additions and 74 deletions.
15 changes: 12 additions & 3 deletions orchagent/orch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "orch.h"

#include "subscriberstatetable.h"
#include "converter.h"
#include "portsorch.h"
#include "tokenize.h"
#include "logger.h"
Expand Down Expand Up @@ -44,7 +45,7 @@ Orch::Orch(DBConnector *db, const vector<table_name_with_pri_t> &tableNames_with
}
}

Orch::Orch(const vector<TableConnector>& tables)
Orch::Orch(const vect
{
for (auto it : tables)
{
Expand Down Expand Up @@ -878,7 +879,15 @@ void Orch2::doTask(Consumer &consumer)
while (it != consumer.m_toSync.end())
{
bool erase_from_queue = true;
bool sync_mode = false;
ReturnCode rc;
for (const auto &kv : kfvFieldsValues(it->second))
{
if (to_upper(fvField(kv)) == "SYNC_MODE" && to_upper(fvValue(kv)) == "TRUE")
{
sync_mode = true;
}
}
try
{
request_.parse(it->second);
Expand Down Expand Up @@ -929,13 +938,13 @@ void Orch2::doTask(Consumer &consumer)
SWSS_LOG_ERROR("%s", rc.message().c_str());
}
request_.clear();
if (!rc.ok())
if (!rc.ok() && sync_mode)
{
m_publisher.publish(consumer.getTableName(), kfvKey(it->second),
kfvFieldsValues(it->second), rc);
}

if (erase_from_queue)
if (erase_from_queue || sync_mode)
{
it = consumer.m_toSync.erase(it);
}
Expand Down
168 changes: 128 additions & 40 deletions orchagent/vrforch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ bool VRFOrch::addOperation(const Request& request)
SWSS_LOG_ENTER();
uint32_t vni = 0;
bool error = true;
bool sync_mode = false;
bool sync_mode_config = false;

sai_attribute_t attr;
vector<sai_attribute_t> attrs;
Expand Down Expand Up @@ -75,6 +77,12 @@ bool VRFOrch::addOperation(const Request& request)
SWSS_LOG_INFO("MGMT VRF field: %s ignored", name.c_str());
continue;
}
else if (name == "sync_mode")
{
sync_mode_config = true;
sync_mode = request.getAttrBool("sync_mode");
continue;
}
else
{
SWSS_LOG_ERROR("Logic error: Unknown attribute: %s", name.c_str());
Expand All @@ -95,27 +103,46 @@ bool VRFOrch::addOperation(const Request& request)
attrs.data());
if (status != SAI_STATUS_SUCCESS)
{
ReturnCode rc = ReturnCode(status)
<< "Failed to create virtual router name: "
<< vrf_name << ", rv: " << sai_serialize_status(status);
SWSS_LOG_ERROR("%s", rc.message().c_str());
m_publisher.publish(request.getTableName(), request.getFullKey(),
request.getFullAttrFields(), rc);
handleSaiCreateStatus(SAI_API_VIRTUAL_ROUTER, status);
// Remove from orchagent queue when there is SAI error
return true;
SWSS_LOG_ERROR("Failed to create virtual router name: %s, rv: %d", vrf_name.c_str(), status);
task_process_status handle_status = handleSaiCreateStatus(SAI_API_VIRTUAL_ROUTER, status);
if (sync_mode)
{
ReturnCode rc = ReturnCode(status)
<< "Failed to create virtual router name: "
<< vrf_name << ", rv: " << sai_serialize_status(status);
m_publisher.publish(request.getTableName(), request.getFullKey(),
request.getFullAttrFields(), rc);
return true;
}
else if (handle_status != task_success)
{
return parseHandleSaiStatusFailure(handle_status);
}
}

vrf_table_[vrf_name].vrf_id = router_id;
vrf_table_[vrf_name].ref_count = 0;
vrf_table_[vrf_name].sync_mode = sync_mode;
vrf_id_table_[router_id] = vrf_name;
if (vni != 0)
{
SWSS_LOG_INFO("VRF '%s' vni %d add", vrf_name.c_str(), vni);
error = updateVrfVNIMap(vrf_name, vni);
if (error == false)
{
return false;
if (sync_mode)
{
ReturnCode rc = ReturnCode(StatusCode::SWSS_RC_INVALID_PARAM)
<< "Failed to update VRF vni map.";
SWSS_LOG_ERROR("%s", rc.message().c_str());
m_publisher.publish(request.getTableName(), request.getFullKey(),
request.getFullAttrFields(), rc);
return true;
}
else
{
return false;
}
}
}
m_stateVrfObjectTable.hset(vrf_name, "state", "ok");
Expand All @@ -125,37 +152,65 @@ bool VRFOrch::addOperation(const Request& request)
{
// Update an existing vrf

if (sync_mode_config)
{
vrf_table_[vrf_name].sync_mode = sync_mode;
}

sai_object_id_t router_id = it->second.vrf_id;

for (const auto& attr: attrs)
{
sai_status_t status = sai_virtual_router_api->set_virtual_router_attribute(router_id, &attr);
if (status != SAI_STATUS_SUCCESS)
{
ReturnCode rc = ReturnCode(status)
<< "Failed to update virtual router attribute. vrf name: "
<< vrf_name << ", rv: " << sai_serialize_status(status);
SWSS_LOG_ERROR("%s", rc.message().c_str());
m_publisher.publish(request.getTableName(), request.getFullKey(),
request.getFullAttrFields(), rc);
handleSaiSetStatus(SAI_API_VIRTUAL_ROUTER, status);
// Remove from orchagent queue when there is SAI error
return true;
SWSS_LOG_ERROR("Failed to update virtual router attribute. vrf name: %s, rv: %d", vrf_name.c_str(), status);
task_process_status handle_status = handleSaiSetStatus(SAI_API_VIRTUAL_ROUTER, status);
if (sync_mode)
{
ReturnCode rc = ReturnCode(status)
<< "Failed to update virtual router attribute. vrf name: "
<< vrf_name << ", rv: " << sai_serialize_status(status);
m_publisher.publish(request.getTableName(), request.getFullKey(),
request.getFullAttrFields(), rc);
return true;
}
else if (handle_status != task_success)
{
return parseHandleSaiStatusFailure(handle_status);
}

}
}

SWSS_LOG_INFO("VRF '%s' vni %d modify", vrf_name.c_str(), vni);
error = updateVrfVNIMap(vrf_name, vni);
if (error == false)
{
return false;
if (sync_mode)
{
ReturnCode rc = ReturnCode(StatusCode::SWSS_RC_INVALID_PARAM)
<< "Failed to update VRF vni map.";
SWSS_LOG_ERROR("%s", rc.message().c_str());
m_publisher.publish(request.getTableName(), request.getFullKey(),
request.getFullAttrFields(), rc);
return true;
}
else
{
return false;
}
}

SWSS_LOG_NOTICE("VRF '%s' was updated", vrf_name.c_str());
}

if (sync_mode)
 {
 m_publisher.publish(request.getTableName(), request.getFullKey(),
 request.getFullAttrFields(), ReturnCode());
 }

m_publisher.publish(request.getTableName(), request.getFullKey(),
request.getFullAttrFields(), ReturnCode());
return true;
}

Expand All @@ -167,45 +222,78 @@ bool VRFOrch::delOperation(const Request& request)
const std::string& vrf_name = request.getKeyString(0);
if (vrf_table_.find(vrf_name) == std::end(vrf_table_))
{
ReturnCode rc = ReturnCode(StatusCode::SWSS_RC_NOT_FOUND)
<< "VRF '" << vrf_name << "' doesn't exist";
SWSS_LOG_ERROR("%s", rc.message().c_str());
m_publisher.publish(request.getTableName(), request.getFullKey(),
request.getFullAttrFields(), rc);
SWSS_LOG_ERROR("VRF '%s' doesn't exist", vrf_name.c_str());
return true;
}

bool sync_mode = vrf_table_[vrf_name].sync_mode;
if (vrf_table_[vrf_name].ref_count)
return false;
{
if (sync_mode)
 {
 ReturnCode rc = ReturnCode(StatusCode::SWSS_RC_INVALID_PARAM)
 << "Failed to delete VRF " << vrf_name
 << ": reference count is not zero.";
SWSS_LOG_ERROR("%s", rc.message().c_str());
 m_publisher.publish(request.getTableName(), request.getFullKey(),
 request.getFullAttrFields(), rc);
return true;
 }
else
 {
return false;
 }
 }

sai_object_id_t router_id = vrf_table_[vrf_name].vrf_id;
sai_status_t status = sai_virtual_router_api->remove_virtual_router(router_id);
if (status != SAI_STATUS_SUCCESS)
{
ReturnCode rc = ReturnCode(status)
<< "Failed to remove virtual router name: "
<< vrf_name << ", rv:" << sai_serialize_status(status);
SWSS_LOG_ERROR("%s", rc.message().c_str());
m_publisher.publish(request.getTableName(), request.getFullKey(),
request.getFullAttrFields(), rc);
handleSaiRemoveStatus(SAI_API_VIRTUAL_ROUTER, status);
// Remove from orchagent queue when there is SAI error
return true;
SWSS_LOG_ERROR("Failed to remove virtual router name: %s, rv:%d", vrf_name.c_str(), status);
task_process_status handle_status = handleSaiRemoveStatus(SAI_API_VIRTUAL_ROUTER, status);
if (sync_mode)
{
ReturnCode rc = ReturnCode(status)
<< "Failed to remove virtual router name: "
<< vrf_name << ", rv:" << sai_serialize_status(status);
m_publisher.publish(request.getTableName(), request.getFullKey(),
request.getFullAttrFields(), rc);
return true;
}
else if (handle_status != task_success)
{
return parseHandleSaiStatusFailure(handle_status);
}
}

vrf_table_.erase(vrf_name);
vrf_id_table_.erase(router_id);
error = delVrfVNIMap(vrf_name, 0);
if (error == false)
{
return false;
if (sync_mode)
 {
 ReturnCode rc = ReturnCode(StatusCode::SWSS_RC_INVALID_PARAM)
 << "Failed to delete VRF vni map.";
SWSS_LOG_ERROR("%s", rc.message().c_str());
 m_publisher.publish(request.getTableName(), request.getFullKey(),
 request.getFullAttrFields(), rc);
return true;
 }
else
 {
return false;
 }
}
m_stateVrfObjectTable.del(vrf_name);

SWSS_LOG_NOTICE("VRF '%s' was removed", vrf_name.c_str());

m_publisher.publish(request.getTableName(), request.getFullKey(),
request.getFullAttrFields(), ReturnCode());
if (sync_mode)
 {
 m_publisher.publish(request.getTableName(), request.getFullKey(),
 request.getFullAttrFields(), ReturnCode());
 }
return true;
}

Expand Down
4 changes: 3 additions & 1 deletion orchagent/vrforch.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ struct VrfEntry
{
sai_object_id_t vrf_id;
int ref_count;
bool sync_mode;
};

struct VNIEntry
Expand All @@ -34,7 +35,8 @@ const request_description_t request_description = {
{ "fallback", REQ_T_BOOL },
{ "vni", REQ_T_UINT },
{ "mgmtVrfEnabled", REQ_T_BOOL },
{ "in_band_mgmt_enabled", REQ_T_BOOL }
{ "in_band_mgmt_enabled", REQ_T_BOOL },
{ "sync_mode", REQ_T_BOOL }
},
{ } // no mandatory attributes
};
Expand Down
Loading

0 comments on commit 97383d3

Please sign in to comment.