|
2 | 2 | #include <inttypes.h>
|
3 | 3 |
|
4 | 4 | #include "switchorch.h"
|
| 5 | +#include "crmorch.h" |
5 | 6 | #include "converter.h"
|
6 | 7 | #include "notifier.h"
|
7 | 8 | #include "notificationproducer.h"
|
8 | 9 | #include "macaddress.h"
|
| 10 | +#include "return_code.h" |
9 | 11 |
|
10 | 12 | using namespace std;
|
11 | 13 | using namespace swss;
|
12 | 14 |
|
13 | 15 | extern sai_object_id_t gSwitchId;
|
14 | 16 | extern sai_switch_api_t *sai_switch_api;
|
| 17 | +extern sai_acl_api_t *sai_acl_api; |
15 | 18 | extern MacAddress gVxlanMacAddress;
|
| 19 | +extern CrmOrch *gCrmOrch; |
16 | 20 |
|
17 | 21 | const map<string, sai_switch_attr_t> switch_attribute_map =
|
18 | 22 | {
|
@@ -57,6 +61,92 @@ SwitchOrch::SwitchOrch(DBConnector *db, vector<TableConnector>& connectors, Tabl
|
57 | 61 | Orch::addExecutor(executorT);
|
58 | 62 | }
|
59 | 63 |
|
| 64 | +void SwitchOrch::initAclGroupsBindToSwitch() |
| 65 | +{ |
| 66 | + // Create an ACL group per stage, INGRESS, EGRESS and PRE_INGRESS |
| 67 | + for (auto stage_it : aclStageLookup) |
| 68 | + { |
| 69 | + sai_object_id_t group_oid; |
| 70 | + auto status = createAclGroup(fvValue(stage_it), &group_oid); |
| 71 | + if (!status.ok()) |
| 72 | + { |
| 73 | + status.prepend("Failed to create ACL group for stage " + fvField(stage_it) + ": "); |
| 74 | + SWSS_LOG_THROW("%s", status.message().c_str()); |
| 75 | + } |
| 76 | + SWSS_LOG_NOTICE("Created ACL group for stage %s", fvField(stage_it).c_str()); |
| 77 | + m_aclGroups[fvValue(stage_it)] = group_oid; |
| 78 | + status = bindAclGroupToSwitch(fvValue(stage_it), group_oid); |
| 79 | + if (!status.ok()) |
| 80 | + { |
| 81 | + status.prepend("Failed to bind ACL group to stage " + fvField(stage_it) + ": "); |
| 82 | + SWSS_LOG_THROW("%s", status.message().c_str()); |
| 83 | + } |
| 84 | + } |
| 85 | +} |
| 86 | + |
| 87 | +const std::map<sai_acl_stage_t, sai_object_id_t> &SwitchOrch::getAclGroupOidsBindingToSwitch() |
| 88 | +{ |
| 89 | + return m_aclGroups; |
| 90 | +} |
| 91 | + |
| 92 | +ReturnCode SwitchOrch::createAclGroup(const sai_acl_stage_t &group_stage, sai_object_id_t *acl_grp_oid) |
| 93 | +{ |
| 94 | + SWSS_LOG_ENTER(); |
| 95 | + |
| 96 | + std::vector<sai_attribute_t> acl_grp_attrs; |
| 97 | + sai_attribute_t acl_grp_attr; |
| 98 | + acl_grp_attr.id = SAI_ACL_TABLE_GROUP_ATTR_ACL_STAGE; |
| 99 | + acl_grp_attr.value.s32 = group_stage; |
| 100 | + acl_grp_attrs.push_back(acl_grp_attr); |
| 101 | + |
| 102 | + acl_grp_attr.id = SAI_ACL_TABLE_GROUP_ATTR_TYPE; |
| 103 | + acl_grp_attr.value.s32 = SAI_ACL_TABLE_GROUP_TYPE_PARALLEL; |
| 104 | + acl_grp_attrs.push_back(acl_grp_attr); |
| 105 | + |
| 106 | + acl_grp_attr.id = SAI_ACL_TABLE_ATTR_ACL_BIND_POINT_TYPE_LIST; |
| 107 | + std::vector<int32_t> bpoint_list; |
| 108 | + bpoint_list.push_back(SAI_ACL_BIND_POINT_TYPE_SWITCH); |
| 109 | + acl_grp_attr.value.s32list.count = (uint32_t)bpoint_list.size(); |
| 110 | + acl_grp_attr.value.s32list.list = bpoint_list.data(); |
| 111 | + acl_grp_attrs.push_back(acl_grp_attr); |
| 112 | + |
| 113 | + CHECK_ERROR_AND_LOG_AND_RETURN(sai_acl_api->create_acl_table_group( |
| 114 | + acl_grp_oid, gSwitchId, (uint32_t)acl_grp_attrs.size(), acl_grp_attrs.data()), |
| 115 | + "Failed to create ACL group for stage " << group_stage); |
| 116 | + if (group_stage == SAI_ACL_STAGE_INGRESS || group_stage == SAI_ACL_STAGE_PRE_INGRESS || |
| 117 | + group_stage == SAI_ACL_STAGE_EGRESS) |
| 118 | + { |
| 119 | + gCrmOrch->incCrmAclUsedCounter(CrmResourceType::CRM_ACL_GROUP, (sai_acl_stage_t)group_stage, |
| 120 | + SAI_ACL_BIND_POINT_TYPE_SWITCH); |
| 121 | + } |
| 122 | + SWSS_LOG_INFO("Suceeded to create ACL group %s in stage %d ", sai_serialize_object_id(*acl_grp_oid).c_str(), |
| 123 | + group_stage); |
| 124 | + return ReturnCode(); |
| 125 | +} |
| 126 | + |
| 127 | +ReturnCode SwitchOrch::bindAclGroupToSwitch(const sai_acl_stage_t &group_stage, const sai_object_id_t &acl_grp_oid) |
| 128 | +{ |
| 129 | + SWSS_LOG_ENTER(); |
| 130 | + |
| 131 | + auto switch_attr_it = aclStageToSwitchAttrLookup.find(group_stage); |
| 132 | + if (switch_attr_it == aclStageToSwitchAttrLookup.end()) |
| 133 | + { |
| 134 | + LOG_ERROR_AND_RETURN(ReturnCode(StatusCode::SWSS_RC_INVALID_PARAM) |
| 135 | + << "Failed to set ACL group(" << acl_grp_oid << ") to the SWITCH bind point at stage " |
| 136 | + << group_stage); |
| 137 | + } |
| 138 | + sai_attribute_t attr; |
| 139 | + attr.id = switch_attr_it->second; |
| 140 | + attr.value.oid = acl_grp_oid; |
| 141 | + auto sai_status = sai_switch_api->set_switch_attribute(gSwitchId, &attr); |
| 142 | + if (sai_status != SAI_STATUS_SUCCESS) |
| 143 | + { |
| 144 | + LOG_ERROR_AND_RETURN(ReturnCode(sai_status) << "[SAI] Failed to set_switch_attribute with attribute.id=" |
| 145 | + << attr.id << " and acl group oid=" << acl_grp_oid); |
| 146 | + } |
| 147 | + return ReturnCode(); |
| 148 | +} |
| 149 | + |
60 | 150 | void SwitchOrch::doCfgSensorsTableTask(Consumer &consumer)
|
61 | 151 | {
|
62 | 152 | SWSS_LOG_ENTER();
|
|
0 commit comments