Skip to content

Commit

Permalink
Copp sflow changes
Browse files Browse the repository at this point in the history
undoing revert

indentation

Code review fixes

Addressing code review comments

Latest copp changes based on headers
  • Loading branch information
dgsudharsan committed Aug 28, 2019
1 parent cadc5bd commit c98babb
Show file tree
Hide file tree
Showing 3 changed files with 194 additions and 0 deletions.
164 changes: 164 additions & 0 deletions orchagent/copporch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,41 @@ bool CoppOrch::applyAttributesToTrapIds(sai_object_id_t trap_group_id,
return false;
}
m_syncdTrapIds[trap_id] = trap_group_id;

auto hostTbl_entry = m_trapId_hostTblEntry_map.find(trap_id);

if (hostTbl_entry == m_trapId_hostTblEntry_map.end())
{
auto hostif_map = m_trap_group_hostif_map.find(trap_group_id);
if (hostif_map != m_trap_group_hostif_map.end())
{
sai_object_id_t hostif_table_entry = SAI_NULL_OBJECT_ID;
sai_attribute_t sai_host_table_attr[4];

sai_host_table_attr[0].id = SAI_HOSTIF_TABLE_ENTRY_ATTR_TYPE;
sai_host_table_attr[0].value.s32 = SAI_HOSTIF_TABLE_ENTRY_TYPE_TRAP_ID;

sai_host_table_attr[1].id = SAI_HOSTIF_TABLE_ENTRY_ATTR_TRAP_ID;
sai_host_table_attr[1].value.oid = hostif_trap_id;

sai_host_table_attr[2].id = SAI_HOSTIF_TABLE_ENTRY_ATTR_CHANNEL_TYPE;
sai_host_table_attr[2].value.s32 = SAI_HOSTIF_TABLE_ENTRY_CHANNEL_TYPE_GENETLINK;

sai_host_table_attr[3].id = SAI_HOSTIF_TABLE_ENTRY_ATTR_HOST_IF;
sai_host_table_attr[3].value.oid = hostif_map->second;

sai_status_t status = sai_hostif_api->create_hostif_table_entry(&hostif_table_entry,
gSwitchId, 4,
sai_host_table_attr);

if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_ERROR("Failed to create hostif table entry failed, rv %d", status);
return false;
}
m_trapId_hostTblEntry_map[trap_id] = hostif_table_entry;
}
}
}

return true;
Expand Down Expand Up @@ -319,6 +354,69 @@ bool CoppOrch::createPolicer(string trap_group_name, vector<sai_attribute_t> &po
return true;
}

bool CoppOrch::createGenetlinkHostIf(string trap_group_name, vector<sai_attribute_t> &genetlink_attribs)
{
SWSS_LOG_ENTER();

sai_object_id_t hostif_id;
sai_status_t sai_status;

sai_status = sai_hostif_api->create_hostif(&hostif_id, gSwitchId,
(uint32_t)genetlink_attribs.size(),
genetlink_attribs.data());
if (sai_status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_ERROR("Failed to create genetlink hostif for trap group %s, rc=%d",
trap_group_name.c_str(), sai_status);
return false;
}

m_trap_group_hostif_map[m_trap_group_map[trap_group_name]] = hostif_id;
return true;
}

bool CoppOrch::removeGenetlinkHostIf(string trap_group_name)
{
SWSS_LOG_ENTER();

sai_status_t sai_status;

for (auto it : m_syncdTrapIds)
{
if (it.second == m_trap_group_map[trap_group_name])
{
auto hostTableEntry = m_trapId_hostTblEntry_map.find(it.first);
if (hostTableEntry != m_trapId_hostTblEntry_map.end())
{
sai_status = sai_hostif_api->remove_hostif_table_entry(hostTableEntry->second);
if(sai_status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_ERROR("Failed to delete hostif table entry %ld \
on trap group %s. rc=%d", hostTableEntry->second,
trap_group_name.c_str(), sai_status);
return false;
}
m_trapId_hostTblEntry_map.erase(it.first);
}
}
}

auto hostInfo = m_trap_group_hostif_map.find(m_trap_group_map[trap_group_name]);
if(hostInfo != m_trap_group_hostif_map.end())
{
sai_status = sai_hostif_api->remove_hostif(hostInfo->second);
if(sai_status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_ERROR("Failed to delete host info %ld on trap group %s. rc=%d",
hostInfo->second, trap_group_name.c_str(), sai_status);
return false;
}
m_trap_group_hostif_map.erase(m_trap_group_map[trap_group_name]);
}

return true;
}

task_process_status CoppOrch::processCoppRule(Consumer& consumer)
{
SWSS_LOG_ENTER();
Expand All @@ -334,6 +432,7 @@ task_process_status CoppOrch::processCoppRule(Consumer& consumer)
vector<sai_attribute_t> trap_gr_attribs;
vector<sai_attribute_t> trap_id_attribs;
vector<sai_attribute_t> policer_attribs;
vector<sai_attribute_t> genetlink_attribs;

if (op == SET_COMMAND)
{
Expand Down Expand Up @@ -441,6 +540,25 @@ task_process_status CoppOrch::processCoppRule(Consumer& consumer)
attr.value.s32 = policer_action;
policer_attribs.push_back(attr);
}
else if (fvField(*i) == copp_genetlink_name)
{
attr.id = SAI_HOSTIF_ATTR_TYPE;
attr.value.s32 = SAI_HOSTIF_TYPE_GENETLINK;
genetlink_attribs.push_back(attr);

attr.id = SAI_HOSTIF_ATTR_NAME;
strncpy(attr.value.chardata, fvValue(*i).c_str(),
sizeof(attr.value.chardata));
genetlink_attribs.push_back(attr);

}
else if (fvField(*i) == copp_genetlink_mcgrp_name)
{
attr.id = SAI_HOSTIF_ATTR_GENETLINK_MCGRP_NAME;
strncpy(attr.value.chardata, fvValue(*i).c_str(),
sizeof(attr.value.chardata));
genetlink_attribs.push_back(attr);
}
else
{
SWSS_LOG_ERROR("Unknown copp field specified:%s\n", fvField(*i).c_str());
Expand Down Expand Up @@ -480,6 +598,38 @@ task_process_status CoppOrch::processCoppRule(Consumer& consumer)
}
}
}
if (!genetlink_attribs.empty())
{
auto hostif_map = m_trap_group_hostif_map.find(m_trap_group_map[trap_group_name]);

if (hostif_map != m_trap_group_hostif_map.end())
{
for(sai_uint32_t idx = 0; idx < genetlink_attribs.size(); idx++)
{
auto hostif_attr = genetlink_attribs[idx];
sai_status = sai_hostif_api->set_hostif_attribute(hostif_map->second,
&hostif_attr);
if(sai_status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_ERROR("Failed to apply attribute[%d].id=%d to hostif for \
trap group %s, error:%d", idx, hostif_attr.id,
trap_group_name.c_str(), sai_status);

return task_process_status::task_failed;
}
}
}
else
{
if (!genetlink_attribs.empty())
{
if (!createGenetlinkHostIf(trap_group_name, genetlink_attribs))
{
return task_process_status::task_failed;
}
}
}
}

for (sai_uint32_t ind = 0; ind < trap_gr_attribs.size(); ind++)
{
Expand Down Expand Up @@ -517,6 +667,14 @@ task_process_status CoppOrch::processCoppRule(Consumer& consumer)
return task_process_status::task_failed;
}
}

if (!genetlink_attribs.empty())
{
if (!createGenetlinkHostIf(trap_group_name, genetlink_attribs))
{
return task_process_status::task_failed;
}
}
}

/* Apply traps to trap group */
Expand All @@ -534,6 +692,12 @@ task_process_status CoppOrch::processCoppRule(Consumer& consumer)
return task_process_status::task_failed;
}

if (!removeGenetlinkHostIf(trap_group_name))
{
SWSS_LOG_ERROR("Failed to remove hostif from trap group %s", trap_group_name.c_str());
return task_process_status::task_failed;
}

/* Do not remove default trap group */
if (trap_group_name == default_trap_group)
{
Expand Down
14 changes: 14 additions & 0 deletions orchagent/copporch.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,18 @@ const string copp_policer_action_green_field = "green_action";
const string copp_policer_action_red_field = "red_action";
const string copp_policer_action_yellow_field = "yellow_action";

// genetlink fields
const string copp_genetlink_name = "genetlink_name";
const string copp_genetlink_mcgrp_name = "genetlink_mcgrp_name";

/* TrapGroupPolicerTable: trap group ID, policer ID */
typedef map<sai_object_id_t, sai_object_id_t> TrapGroupPolicerTable;
/* TrapIdTrapGroupTable: trap ID, trap group ID */
typedef map<sai_hostif_trap_type_t, sai_object_id_t> TrapIdTrapGroupTable;
/* TrapGroupHostIfMap: trap group ID to host interface ID */
typedef map<sai_object_id_t, sai_object_id_t> TrapGroupHostIfMap;
/* TrapGroupHostIfMap: trap type to host table entry */
typedef map<sai_hostif_trap_type_t, sai_object_id_t> TrapHostTblEntryMap;

class CoppOrch : public Orch
{
Expand All @@ -39,6 +47,9 @@ class CoppOrch : public Orch
TrapGroupPolicerTable m_trap_group_policer_map;
TrapIdTrapGroupTable m_syncdTrapIds;

TrapGroupHostIfMap m_trap_group_hostif_map;
TrapHostTblEntryMap m_trapId_hostTblEntry_map;

void initDefaultHostIntfTable();
void initDefaultTrapGroup();
void initDefaultTrapIds();
Expand All @@ -54,6 +65,9 @@ class CoppOrch : public Orch

sai_object_id_t getPolicer(string trap_group_name);

bool createGenetlinkHostIf(string trap_group_name, vector<sai_attribute_t> &hostif_attribs);
bool removeGenetlinkHostIf(string trap_group_name);

virtual void doTask(Consumer& consumer);
};
#endif /* SWSS_COPPORCH_H */
Expand Down
16 changes: 16 additions & 0 deletions swssconfig/sample/00-copp.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,21 @@
"red_action":"drop"
},
"OP": "SET"
},
{
"COPP_TABLE:trap.group.sflow": {
"trap_ids": "sample_packet",
"trap_action":"trap",
"trap_priority":"1",
"queue": "2",
"meter_type":"packets",
"mode":"sr_tcm",
"cir":"1000",
"cbs":"1000",
"red_action":"drop",
"genetlink_name":"psample",
"genetlink_mcgrp_name":"packets"
},
"OP": "SET"
}
]

0 comments on commit c98babb

Please sign in to comment.