|
14 | 14 | #include "return_code.h"
|
15 | 15 | #include "vrforch.h"
|
16 | 16 |
|
17 |
| -extern "C" { |
| 17 | +extern "C" |
| 18 | +{ |
18 | 19 | #include "sai.h"
|
19 | 20 | }
|
20 | 21 |
|
21 |
| -namespace p4orch { |
22 |
| -namespace test { |
| 22 | +namespace p4orch |
| 23 | +{ |
| 24 | +namespace test |
| 25 | +{ |
23 | 26 | class AclManagerTest;
|
24 |
| -} // namespace test |
25 |
| - |
26 |
| -class AclRuleManager : public ObjectManagerInterface { |
27 |
| - public: |
28 |
| - explicit AclRuleManager(P4OidMapper* p4oidMapper, VRFOrch* vrfOrch, |
29 |
| - CoppOrch* coppOrch, |
30 |
| - ResponsePublisherInterface* publisher) |
31 |
| - : m_p4OidMapper(p4oidMapper), |
32 |
| - m_vrfOrch(vrfOrch), |
33 |
| - m_publisher(publisher), |
34 |
| - m_coppOrch(coppOrch), |
35 |
| - m_countersDb(std::make_unique<swss::DBConnector>("COUNTERS_DB", 0)), |
36 |
| - m_countersTable(std::make_unique<swss::Table>( |
37 |
| - m_countersDb.get(), std::string(COUNTERS_TABLE) + |
38 |
| - DEFAULT_KEY_SEPARATOR + |
39 |
| - APP_P4RT_TABLE_NAME)) { |
40 |
| - SWSS_LOG_ENTER(); |
41 |
| - assert(m_p4OidMapper != nullptr); |
42 |
| - } |
43 |
| - virtual ~AclRuleManager() = default; |
44 |
| - |
45 |
| - void enqueue(const swss::KeyOpFieldsValuesTuple& entry) override; |
46 |
| - void drain() override; |
47 |
| - |
48 |
| - // Update counters stats for every rule in each ACL table in COUNTERS_DB, if |
49 |
| - // counters are enabled in rules. |
50 |
| - void doAclCounterStatsTask(); |
51 |
| - |
52 |
| - private: |
53 |
| - // Deserializes an entry in a dynamically created ACL table. |
54 |
| - ReturnCodeOr<P4AclRuleAppDbEntry> deserializeAclRuleAppDbEntry( |
55 |
| - const std::string& acl_table_name, const std::string& key, |
56 |
| - const std::vector<swss::FieldValueTuple>& attributes); |
57 |
| - |
58 |
| - // Validate an ACL rule APP_DB entry. |
59 |
| - ReturnCode validateAclRuleAppDbEntry(const P4AclRuleAppDbEntry& app_db_entry); |
60 |
| - |
61 |
| - // Get ACL rule by table name and rule key. Return nullptr if not found. |
62 |
| - P4AclRule* getAclRule(const std::string& acl_table_name, |
63 |
| - const std::string& acl_rule_key); |
64 |
| - |
65 |
| - // Processes add operation for an ACL rule. |
66 |
| - ReturnCode processAddRuleRequest(const std::string& acl_rule_key, |
67 |
| - const P4AclRuleAppDbEntry& app_db_entry); |
68 |
| - |
69 |
| - // Processes delete operation for an ACL rule. |
70 |
| - ReturnCode processDeleteRuleRequest(const std::string& acl_table_name, |
71 |
| - const std::string& acl_rule_key); |
72 |
| - |
73 |
| - // Processes update operation for an ACL rule. |
74 |
| - ReturnCode processUpdateRuleRequest(const P4AclRuleAppDbEntry& app_db_entry, |
75 |
| - const P4AclRule& old_acl_rule); |
76 |
| - |
77 |
| - // Set counters stats for an ACL rule in COUNTERS_DB. |
78 |
| - ReturnCode setAclRuleCounterStats(const P4AclRule& acl_rule); |
79 |
| - |
80 |
| - // Create an ACL rule. |
81 |
| - ReturnCode createAclRule(P4AclRule& acl_rule); |
82 |
| - |
83 |
| - // Create an ACL counter. |
84 |
| - ReturnCode createAclCounter(const std::string& acl_table_name, |
85 |
| - const std::string& counter_key, |
86 |
| - const P4AclCounter& p4_acl_counter, |
87 |
| - sai_object_id_t* counter_oid); |
88 |
| - |
89 |
| - // Create an ACL meter. |
90 |
| - ReturnCode createAclMeter(const P4AclMeter& p4_acl_meter, |
91 |
| - const std::string& meter_key, |
92 |
| - sai_object_id_t* meter_oid); |
93 |
| - |
94 |
| - // Remove an ACL counter. |
95 |
| - ReturnCode removeAclCounter(const std::string& acl_table_name, |
96 |
| - const std::string& counter_key); |
97 |
| - |
98 |
| - // Update ACL meter. |
99 |
| - ReturnCode updateAclMeter(const P4AclMeter& new_acl_meter, |
100 |
| - const P4AclMeter& old_acl_meter); |
101 |
| - |
102 |
| - // Update ACL rule. |
103 |
| - ReturnCode updateAclRule(const P4AclRule& new_acl_rule, |
104 |
| - const P4AclRule& old_acl_rule, |
105 |
| - std::vector<sai_attribute_t>& acl_entry_attrs, |
106 |
| - std::vector<sai_attribute_t>& rollback_attrs); |
107 |
| - |
108 |
| - // Remove an ACL meter. |
109 |
| - ReturnCode removeAclMeter(const std::string& meter_key); |
110 |
| - |
111 |
| - // Remove the ACL rule by key in the given ACL table. |
112 |
| - ReturnCode removeAclRule(const std::string& acl_table_name, |
113 |
| - const std::string& acl_rule_key); |
114 |
| - |
115 |
| - // Set Meter value in ACL rule. |
116 |
| - ReturnCode setMeterValue(const P4AclTableDefinition* acl_table, |
117 |
| - const P4AclRuleAppDbEntry& app_db_entry, |
118 |
| - P4AclMeter& acl_meter); |
119 |
| - |
120 |
| - // Validate and set all match attributes in an ACL rule. |
121 |
| - ReturnCode setAllMatchFieldValues(const P4AclRuleAppDbEntry& app_db_entry, |
122 |
| - const P4AclTableDefinition* acl_table, |
123 |
| - P4AclRule& acl_rules); |
124 |
| - |
125 |
| - // Validate and set all action attributes in an ACL rule. |
126 |
| - ReturnCode setAllActionFieldValues(const P4AclRuleAppDbEntry& app_db_entry, |
127 |
| - const P4AclTableDefinition* acl_table, |
128 |
| - P4AclRule& acl_rule); |
129 |
| - |
130 |
| - // Validate and set a match attribute in an ACL rule. |
131 |
| - ReturnCode setMatchValue(const acl_entry_attr_union_t attr_name, |
132 |
| - const std::string& attr_value, |
133 |
| - sai_attribute_value_t* value, P4AclRule* acl_rule, |
134 |
| - const std::string& ip_type_bit_type = EMPTY_STRING); |
135 |
| - |
136 |
| - // Validate and set an action attribute in an ACL rule. |
137 |
| - ReturnCode setActionValue(const acl_entry_attr_union_t attr_name, |
138 |
| - const std::string& attr_value, |
139 |
| - sai_attribute_value_t* value, P4AclRule* acl_rule); |
140 |
| - |
141 |
| - // Get port object id by name for redirect action. |
142 |
| - ReturnCode getRedirectActionPortOid(const std::string& target, |
143 |
| - sai_object_id_t* rediect_oid); |
144 |
| - |
145 |
| - // Get next hop object id by name for redirect action. |
146 |
| - ReturnCode getRedirectActionNextHopOid(const std::string& target, |
147 |
| - sai_object_id_t* rediect_oid); |
148 |
| - |
149 |
| - // Create user defined trap for each cpu queue/trap group and program user |
150 |
| - // defined traps in hostif. Save the user defined trap oids in m_p4OidMapper |
151 |
| - // and default ref count is 1. |
152 |
| - ReturnCode setUpUserDefinedTraps(); |
153 |
| - |
154 |
| - // Clean up user defined traps created for cpu queues. Callers need to make |
155 |
| - // sure ref count on user defined traps in m_userDefinedTraps are ones before |
156 |
| - // clean up. |
157 |
| - ReturnCode cleanUpUserDefinedTraps(); |
158 |
| - |
159 |
| - P4OidMapper* m_p4OidMapper; |
160 |
| - ResponsePublisherInterface* m_publisher; |
161 |
| - P4AclRuleTables m_aclRuleTables; |
162 |
| - VRFOrch* m_vrfOrch; |
163 |
| - CoppOrch* m_coppOrch; |
164 |
| - std::deque<swss::KeyOpFieldsValuesTuple> m_entries; |
165 |
| - std::unique_ptr<swss::DBConnector> m_countersDb; |
166 |
| - std::unique_ptr<swss::Table> m_countersTable; |
167 |
| - std::vector<P4UserDefinedTrapHostifTableEntry> m_userDefinedTraps; |
168 |
| - |
169 |
| - friend class AclTableManager; |
170 |
| - friend class p4orch::test::AclManagerTest; |
| 27 | +} // namespace test |
| 28 | + |
| 29 | +class AclRuleManager : public ObjectManagerInterface |
| 30 | +{ |
| 31 | + public: |
| 32 | + explicit AclRuleManager(P4OidMapper *p4oidMapper, VRFOrch *vrfOrch, CoppOrch *coppOrch, |
| 33 | + ResponsePublisherInterface *publisher) |
| 34 | + : m_p4OidMapper(p4oidMapper), m_vrfOrch(vrfOrch), m_publisher(publisher), m_coppOrch(coppOrch), |
| 35 | + m_countersDb(std::make_unique<swss::DBConnector>("COUNTERS_DB", 0)), |
| 36 | + m_countersTable(std::make_unique<swss::Table>( |
| 37 | + m_countersDb.get(), std::string(COUNTERS_TABLE) + DEFAULT_KEY_SEPARATOR + APP_P4RT_TABLE_NAME)) |
| 38 | + { |
| 39 | + SWSS_LOG_ENTER(); |
| 40 | + assert(m_p4OidMapper != nullptr); |
| 41 | + } |
| 42 | + virtual ~AclRuleManager() = default; |
| 43 | + |
| 44 | + void enqueue(const swss::KeyOpFieldsValuesTuple &entry) override; |
| 45 | + void drain() override; |
| 46 | + |
| 47 | + // Update counters stats for every rule in each ACL table in COUNTERS_DB, if |
| 48 | + // counters are enabled in rules. |
| 49 | + void doAclCounterStatsTask(); |
| 50 | + |
| 51 | + private: |
| 52 | + // Deserializes an entry in a dynamically created ACL table. |
| 53 | + ReturnCodeOr<P4AclRuleAppDbEntry> deserializeAclRuleAppDbEntry( |
| 54 | + const std::string &acl_table_name, const std::string &key, |
| 55 | + const std::vector<swss::FieldValueTuple> &attributes); |
| 56 | + |
| 57 | + // Validate an ACL rule APP_DB entry. |
| 58 | + ReturnCode validateAclRuleAppDbEntry(const P4AclRuleAppDbEntry &app_db_entry); |
| 59 | + |
| 60 | + // Get ACL rule by table name and rule key. Return nullptr if not found. |
| 61 | + P4AclRule *getAclRule(const std::string &acl_table_name, const std::string &acl_rule_key); |
| 62 | + |
| 63 | + // Processes add operation for an ACL rule. |
| 64 | + ReturnCode processAddRuleRequest(const std::string &acl_rule_key, const P4AclRuleAppDbEntry &app_db_entry); |
| 65 | + |
| 66 | + // Processes delete operation for an ACL rule. |
| 67 | + ReturnCode processDeleteRuleRequest(const std::string &acl_table_name, const std::string &acl_rule_key); |
| 68 | + |
| 69 | + // Processes update operation for an ACL rule. |
| 70 | + ReturnCode processUpdateRuleRequest(const P4AclRuleAppDbEntry &app_db_entry, const P4AclRule &old_acl_rule); |
| 71 | + |
| 72 | + // Set counters stats for an ACL rule in COUNTERS_DB. |
| 73 | + ReturnCode setAclRuleCounterStats(const P4AclRule &acl_rule); |
| 74 | + |
| 75 | + // Create an ACL rule. |
| 76 | + ReturnCode createAclRule(P4AclRule &acl_rule); |
| 77 | + |
| 78 | + // Create an ACL counter. |
| 79 | + ReturnCode createAclCounter(const std::string &acl_table_name, const std::string &counter_key, |
| 80 | + const P4AclCounter &p4_acl_counter, sai_object_id_t *counter_oid); |
| 81 | + |
| 82 | + // Create an ACL meter. |
| 83 | + ReturnCode createAclMeter(const P4AclMeter &p4_acl_meter, const std::string &meter_key, sai_object_id_t *meter_oid); |
| 84 | + |
| 85 | + // Remove an ACL counter. |
| 86 | + ReturnCode removeAclCounter(const std::string &acl_table_name, const std::string &counter_key); |
| 87 | + |
| 88 | + // Update ACL meter. |
| 89 | + ReturnCode updateAclMeter(const P4AclMeter &new_acl_meter, const P4AclMeter &old_acl_meter); |
| 90 | + |
| 91 | + // Update ACL rule. |
| 92 | + ReturnCode updateAclRule(const P4AclRule &new_acl_rule, const P4AclRule &old_acl_rule, |
| 93 | + std::vector<sai_attribute_t> &acl_entry_attrs, |
| 94 | + std::vector<sai_attribute_t> &rollback_attrs); |
| 95 | + |
| 96 | + // Remove an ACL meter. |
| 97 | + ReturnCode removeAclMeter(const std::string &meter_key); |
| 98 | + |
| 99 | + // Remove the ACL rule by key in the given ACL table. |
| 100 | + ReturnCode removeAclRule(const std::string &acl_table_name, const std::string &acl_rule_key); |
| 101 | + |
| 102 | + // Set Meter value in ACL rule. |
| 103 | + ReturnCode setMeterValue(const P4AclTableDefinition *acl_table, const P4AclRuleAppDbEntry &app_db_entry, |
| 104 | + P4AclMeter &acl_meter); |
| 105 | + |
| 106 | + // Validate and set all match attributes in an ACL rule. |
| 107 | + ReturnCode setAllMatchFieldValues(const P4AclRuleAppDbEntry &app_db_entry, const P4AclTableDefinition *acl_table, |
| 108 | + P4AclRule &acl_rules); |
| 109 | + |
| 110 | + // Validate and set all action attributes in an ACL rule. |
| 111 | + ReturnCode setAllActionFieldValues(const P4AclRuleAppDbEntry &app_db_entry, const P4AclTableDefinition *acl_table, |
| 112 | + P4AclRule &acl_rule); |
| 113 | + |
| 114 | + // Validate and set a match attribute in an ACL rule. |
| 115 | + ReturnCode setMatchValue(const acl_entry_attr_union_t attr_name, const std::string &attr_value, |
| 116 | + sai_attribute_value_t *value, P4AclRule *acl_rule, |
| 117 | + const std::string &ip_type_bit_type = EMPTY_STRING); |
| 118 | + |
| 119 | + // Validate and set an action attribute in an ACL rule. |
| 120 | + ReturnCode setActionValue(const acl_entry_attr_union_t attr_name, const std::string &attr_value, |
| 121 | + sai_attribute_value_t *value, P4AclRule *acl_rule); |
| 122 | + |
| 123 | + // Get port object id by name for redirect action. |
| 124 | + ReturnCode getRedirectActionPortOid(const std::string &target, sai_object_id_t *rediect_oid); |
| 125 | + |
| 126 | + // Get next hop object id by name for redirect action. |
| 127 | + ReturnCode getRedirectActionNextHopOid(const std::string &target, sai_object_id_t *rediect_oid); |
| 128 | + |
| 129 | + // Create user defined trap for each cpu queue/trap group and program user |
| 130 | + // defined traps in hostif. Save the user defined trap oids in m_p4OidMapper |
| 131 | + // and default ref count is 1. |
| 132 | + ReturnCode setUpUserDefinedTraps(); |
| 133 | + |
| 134 | + // Clean up user defined traps created for cpu queues. Callers need to make |
| 135 | + // sure ref count on user defined traps in m_userDefinedTraps are ones before |
| 136 | + // clean up. |
| 137 | + ReturnCode cleanUpUserDefinedTraps(); |
| 138 | + |
| 139 | + P4OidMapper *m_p4OidMapper; |
| 140 | + ResponsePublisherInterface *m_publisher; |
| 141 | + P4AclRuleTables m_aclRuleTables; |
| 142 | + VRFOrch *m_vrfOrch; |
| 143 | + CoppOrch *m_coppOrch; |
| 144 | + std::deque<swss::KeyOpFieldsValuesTuple> m_entries; |
| 145 | + std::unique_ptr<swss::DBConnector> m_countersDb; |
| 146 | + std::unique_ptr<swss::Table> m_countersTable; |
| 147 | + std::vector<P4UserDefinedTrapHostifTableEntry> m_userDefinedTraps; |
| 148 | + |
| 149 | + friend class AclTableManager; |
| 150 | + friend class p4orch::test::AclManagerTest; |
171 | 151 | };
|
172 | 152 |
|
173 |
| -} // namespace p4orch |
| 153 | +} // namespace p4orch |
0 commit comments