Skip to content

Commit 18b86b1

Browse files
Merge pull request #3883 from divyagayathri-hcl/mock_sai
[P4Orch] Add mocks for SAI bridge to p4orch.
2 parents 1b3f738 + 61e4463 commit 18b86b1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+3873
-1593
lines changed

orchagent/bulker.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -701,14 +701,23 @@ class EntityBulker
701701
std::vector<Te> rs;
702702
std::vector<sai_attribute_t> ts;
703703
std::vector<sai_status_t*> status_vector;
704+
// Use a set to keep track of the entries that have been processed.
705+
std::unordered_set<Te> entries;
704706

705707
for (auto const& entry : set_order)
706708
{
709+
// Skip the entry if it is alreay processed.
710+
// All attributes of an entry are processed in the first run.
711+
if (entries.count(entry) != 0)
712+
{
713+
continue;
714+
}
707715
auto i = setting_entries.find(entry);
708716
if (i == setting_entries.end())
709717
{
710718
continue;
711719
}
720+
entries.insert(entry);
712721
auto const& attrs = i->second;
713722
for (auto const& ia: attrs)
714723
{

orchagent/p4orch/acl_rule_manager.cpp

Lines changed: 73 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -176,75 +176,81 @@ void AclRuleManager::enqueue(const std::string &table_name, const swss::KeyOpFie
176176
m_entries.push_back(entry);
177177
}
178178

179-
void AclRuleManager::drain()
180-
{
181-
SWSS_LOG_ENTER();
182-
183-
for (const auto &key_op_fvs_tuple : m_entries)
184-
{
185-
std::string table_name;
186-
std::string db_key;
187-
parseP4RTKey(kfvKey(key_op_fvs_tuple), &table_name, &db_key);
188-
const auto &op = kfvOp(key_op_fvs_tuple);
189-
const std::vector<swss::FieldValueTuple> &attributes = kfvFieldsValues(key_op_fvs_tuple);
190-
191-
SWSS_LOG_NOTICE("OP: %s, RULE_KEY: %s", op.c_str(), QuotedVar(db_key).c_str());
192-
193-
ReturnCode status;
194-
auto app_db_entry_or = deserializeAclRuleAppDbEntry(table_name, db_key, attributes);
195-
if (!app_db_entry_or.ok())
196-
{
197-
status = app_db_entry_or.status();
198-
SWSS_LOG_ERROR("Unable to deserialize APP DB entry with key %s: %s",
199-
QuotedVar(table_name + ":" + db_key).c_str(), status.message().c_str());
200-
m_publisher->publish(APP_P4RT_TABLE_NAME, kfvKey(key_op_fvs_tuple), kfvFieldsValues(key_op_fvs_tuple),
201-
status,
202-
/*replace=*/true);
203-
continue;
204-
}
205-
auto &app_db_entry = *app_db_entry_or;
206-
207-
status = validateAclRuleAppDbEntry(app_db_entry);
208-
if (!status.ok())
209-
{
210-
SWSS_LOG_ERROR("Validation failed for ACL rule APP DB entry with key %s: %s",
211-
QuotedVar(table_name + ":" + db_key).c_str(), status.message().c_str());
212-
m_publisher->publish(APP_P4RT_TABLE_NAME, kfvKey(key_op_fvs_tuple), kfvFieldsValues(key_op_fvs_tuple),
213-
status,
214-
/*replace=*/true);
215-
continue;
216-
}
179+
void AclRuleManager::drainWithNotExecuted() {
180+
drainMgmtWithNotExecuted(m_entries, m_publisher);
181+
}
217182

218-
const auto &acl_table_name = app_db_entry.acl_table_name;
219-
const auto &acl_rule_key =
220-
KeyGenerator::generateAclRuleKey(app_db_entry.match_fvs, std::to_string(app_db_entry.priority));
183+
ReturnCode AclRuleManager::drain() {
184+
SWSS_LOG_ENTER();
221185

222-
const auto &operation = kfvOp(key_op_fvs_tuple);
223-
if (operation == SET_COMMAND)
224-
{
225-
auto *acl_rule = getAclRule(acl_table_name, acl_rule_key);
226-
if (acl_rule == nullptr)
227-
{
228-
status = processAddRuleRequest(acl_rule_key, app_db_entry);
229-
}
230-
else
231-
{
232-
status = processUpdateRuleRequest(app_db_entry, *acl_rule);
233-
}
234-
}
235-
else if (operation == DEL_COMMAND)
236-
{
237-
status = processDeleteRuleRequest(acl_table_name, acl_rule_key);
238-
}
239-
else
240-
{
241-
status = ReturnCode(StatusCode::SWSS_RC_INVALID_PARAM) << "Unknown operation type " << operation;
242-
SWSS_LOG_ERROR("%s", status.message().c_str());
243-
}
244-
m_publisher->publish(APP_P4RT_TABLE_NAME, kfvKey(key_op_fvs_tuple), kfvFieldsValues(key_op_fvs_tuple), status,
245-
/*replace=*/true);
246-
}
247-
m_entries.clear();
186+
ReturnCode status;
187+
while (!m_entries.empty()) {
188+
auto key_op_fvs_tuple = m_entries.front();
189+
m_entries.pop_front();
190+
std::string table_name;
191+
std::string db_key;
192+
parseP4RTKey(kfvKey(key_op_fvs_tuple), &table_name, &db_key);
193+
const auto& op = kfvOp(key_op_fvs_tuple);
194+
const std::vector<swss::FieldValueTuple>& attributes =
195+
kfvFieldsValues(key_op_fvs_tuple);
196+
197+
SWSS_LOG_NOTICE("OP: %s, RULE_KEY: %s", op.c_str(),
198+
QuotedVar(db_key).c_str());
199+
200+
auto app_db_entry_or =
201+
deserializeAclRuleAppDbEntry(table_name, db_key, attributes);
202+
if (!app_db_entry_or.ok()) {
203+
status = app_db_entry_or.status();
204+
SWSS_LOG_ERROR("Unable to deserialize APP DB entry with key %s: %s",
205+
QuotedVar(table_name + ":" + db_key).c_str(),
206+
status.message().c_str());
207+
m_publisher->publish(APP_P4RT_TABLE_NAME, kfvKey(key_op_fvs_tuple),
208+
kfvFieldsValues(key_op_fvs_tuple), status,
209+
/*replace=*/true);
210+
break;
211+
}
212+
auto& app_db_entry = *app_db_entry_or;
213+
214+
status = validateAclRuleAppDbEntry(app_db_entry);
215+
if (!status.ok()) {
216+
SWSS_LOG_ERROR(
217+
"Validation failed for ACL rule APP DB entry with key %s: %s",
218+
QuotedVar(table_name + ":" + db_key).c_str(),
219+
status.message().c_str());
220+
m_publisher->publish(APP_P4RT_TABLE_NAME, kfvKey(key_op_fvs_tuple),
221+
kfvFieldsValues(key_op_fvs_tuple), status,
222+
/*replace=*/true);
223+
break;
224+
}
225+
226+
const auto& acl_table_name = app_db_entry.acl_table_name;
227+
const auto& acl_rule_key = KeyGenerator::generateAclRuleKey(
228+
app_db_entry.match_fvs, std::to_string(app_db_entry.priority));
229+
230+
const auto& operation = kfvOp(key_op_fvs_tuple);
231+
if (operation == SET_COMMAND) {
232+
auto* acl_rule = getAclRule(acl_table_name, acl_rule_key);
233+
if (acl_rule == nullptr) {
234+
status = processAddRuleRequest(acl_rule_key, app_db_entry);
235+
} else {
236+
status = processUpdateRuleRequest(app_db_entry, *acl_rule);
237+
}
238+
} else if (operation == DEL_COMMAND) {
239+
status = processDeleteRuleRequest(acl_table_name, acl_rule_key);
240+
} else {
241+
status = ReturnCode(StatusCode::SWSS_RC_INVALID_PARAM)
242+
<< "Unknown operation type " << operation;
243+
SWSS_LOG_ERROR("%s", status.message().c_str());
244+
}
245+
m_publisher->publish(APP_P4RT_TABLE_NAME, kfvKey(key_op_fvs_tuple),
246+
kfvFieldsValues(key_op_fvs_tuple), status,
247+
/*replace=*/true);
248+
if (!status.ok()) {
249+
break;
250+
}
251+
}
252+
drainWithNotExecuted();
253+
return status;
248254
}
249255

250256
ReturnCode AclRuleManager::setUpUserDefinedTraps()

orchagent/p4orch/acl_rule_manager.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ class AclRuleManager : public ObjectManagerInterface
4242
virtual ~AclRuleManager() = default;
4343

4444
void enqueue(const std::string &table_name, const swss::KeyOpFieldsValuesTuple &entry) override;
45-
void drain() override;
45+
ReturnCode drain() override;
46+
void drainWithNotExecuted() override;
4647
std::string verifyState(const std::string &key, const std::vector<swss::FieldValueTuple> &tuple) override;
4748
ReturnCode getSaiObject(const std::string &json_key, sai_object_type_t &object_type,
4849
std::string &object_key) override;

orchagent/p4orch/acl_table_manager.cpp

Lines changed: 85 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -216,86 +216,94 @@ void AclTableManager::enqueue(const std::string &table_name, const swss::KeyOpFi
216216
m_entries.push_back(entry);
217217
}
218218

219-
void AclTableManager::drain()
220-
{
221-
SWSS_LOG_ENTER();
219+
void AclTableManager::drainWithNotExecuted() {
220+
drainMgmtWithNotExecuted(m_entries, m_publisher);
221+
}
222222

223-
for (const auto &key_op_fvs_tuple : m_entries)
224-
{
225-
std::string table_name;
226-
std::string db_key;
227-
parseP4RTKey(kfvKey(key_op_fvs_tuple), &table_name, &db_key);
228-
SWSS_LOG_NOTICE("P4AclTableManager drain tuple for table %s", QuotedVar(table_name).c_str());
229-
if (table_name != APP_P4RT_ACL_TABLE_DEFINITION_NAME)
230-
{
231-
ReturnCode status = ReturnCode(StatusCode::SWSS_RC_INVALID_PARAM)
232-
<< "Invalid table " << QuotedVar(table_name);
233-
SWSS_LOG_ERROR("%s", status.message().c_str());
234-
m_publisher->publish(APP_P4RT_TABLE_NAME, kfvKey(key_op_fvs_tuple), kfvFieldsValues(key_op_fvs_tuple),
235-
status,
236-
/*replace=*/true);
237-
continue;
238-
}
239-
const std::vector<swss::FieldValueTuple> &attributes = kfvFieldsValues(key_op_fvs_tuple);
223+
ReturnCode AclTableManager::drain() {
224+
SWSS_LOG_ENTER();
240225

241-
ReturnCode status;
242-
const std::string &operation = kfvOp(key_op_fvs_tuple);
243-
if (operation == SET_COMMAND)
244-
{
245-
auto app_db_entry_or = deserializeAclTableDefinitionAppDbEntry(db_key, attributes);
246-
if (!app_db_entry_or.ok())
247-
{
248-
status = app_db_entry_or.status();
249-
SWSS_LOG_ERROR("Unable to deserialize APP DB entry with key %s: %s",
250-
QuotedVar(table_name + ":" + db_key).c_str(), status.message().c_str());
251-
m_publisher->publish(APP_P4RT_TABLE_NAME, kfvKey(key_op_fvs_tuple), kfvFieldsValues(key_op_fvs_tuple),
252-
status,
253-
/*replace=*/true);
254-
continue;
255-
}
256-
auto &app_db_entry = *app_db_entry_or;
257-
258-
status = validateAclTableDefinitionAppDbEntry(app_db_entry);
259-
if (!status.ok())
260-
{
261-
SWSS_LOG_ERROR("Validation failed for ACL definition APP DB entry with key %s: %s",
262-
QuotedVar(table_name + ":" + db_key).c_str(), status.message().c_str());
263-
m_publisher->publish(APP_P4RT_TABLE_NAME, kfvKey(key_op_fvs_tuple), kfvFieldsValues(key_op_fvs_tuple),
264-
status,
265-
/*replace=*/true);
266-
continue;
267-
}
268-
auto *acl_table_definition = getAclTable(app_db_entry.acl_table_name);
269-
if (acl_table_definition == nullptr)
270-
{
271-
SWSS_LOG_NOTICE("ACL table SET %s", app_db_entry.acl_table_name.c_str());
272-
status = processAddTableRequest(app_db_entry);
273-
}
274-
else
275-
{
276-
// All attributes in sai_acl_table_attr_t are CREATE_ONLY.
277-
status = ReturnCode(StatusCode::SWSS_RC_UNIMPLEMENTED)
278-
<< "Unable to update ACL table definition in APP DB entry with key "
279-
<< QuotedVar(table_name + ":" + db_key)
280-
<< " : All attributes in sai_acl_table_attr_t are CREATE_ONLY.";
281-
}
282-
}
283-
else if (operation == DEL_COMMAND)
284-
{
285-
status = processDeleteTableRequest(db_key);
286-
}
287-
else
288-
{
289-
status = ReturnCode(StatusCode::SWSS_RC_INVALID_PARAM) << "Unknown operation type " << QuotedVar(operation);
290-
}
291-
if (!status.ok())
292-
{
293-
SWSS_LOG_ERROR("Processed DEFINITION entry status: %s", status.message().c_str());
294-
}
295-
m_publisher->publish(APP_P4RT_TABLE_NAME, kfvKey(key_op_fvs_tuple), kfvFieldsValues(key_op_fvs_tuple), status,
226+
ReturnCode status;
227+
while (!m_entries.empty()) {
228+
auto key_op_fvs_tuple = m_entries.front();
229+
m_entries.pop_front();
230+
std::string table_name;
231+
std::string db_key;
232+
233+
parseP4RTKey(kfvKey(key_op_fvs_tuple), &table_name, &db_key);
234+
SWSS_LOG_NOTICE("P4AclTableManager drain tuple for table %s",
235+
QuotedVar(table_name).c_str());
236+
if (table_name != APP_P4RT_ACL_TABLE_DEFINITION_NAME) {
237+
status = ReturnCode(StatusCode::SWSS_RC_INVALID_PARAM)
238+
<< "Invalid table " << QuotedVar(table_name);
239+
SWSS_LOG_ERROR("%s", status.message().c_str());
240+
m_publisher->publish(APP_P4RT_TABLE_NAME, kfvKey(key_op_fvs_tuple),
241+
kfvFieldsValues(key_op_fvs_tuple), status,
242+
/*replace=*/true);
243+
break;
244+
}
245+
const std::vector<swss::FieldValueTuple>& attributes =
246+
kfvFieldsValues(key_op_fvs_tuple);
247+
248+
const std::string& operation = kfvOp(key_op_fvs_tuple);
249+
if (operation == SET_COMMAND) {
250+
auto app_db_entry_or =
251+
deserializeAclTableDefinitionAppDbEntry(db_key, attributes);
252+
if (!app_db_entry_or.ok()) {
253+
status = app_db_entry_or.status();
254+
SWSS_LOG_ERROR("Unable to deserialize APP DB entry with key %s: %s",
255+
QuotedVar(table_name + ":" + db_key).c_str(),
256+
status.message().c_str());
257+
m_publisher->publish(APP_P4RT_TABLE_NAME, kfvKey(key_op_fvs_tuple),
258+
kfvFieldsValues(key_op_fvs_tuple), status,
296259
/*replace=*/true);
297-
}
298-
m_entries.clear();
260+
break;
261+
}
262+
auto& app_db_entry = *app_db_entry_or;
263+
264+
status = validateAclTableDefinitionAppDbEntry(app_db_entry);
265+
if (!status.ok()) {
266+
SWSS_LOG_ERROR(
267+
"Validation failed for ACL definition APP DB entry with key %s: %s",
268+
QuotedVar(table_name + ":" + db_key).c_str(),
269+
status.message().c_str());
270+
m_publisher->publish(APP_P4RT_TABLE_NAME, kfvKey(key_op_fvs_tuple),
271+
kfvFieldsValues(key_op_fvs_tuple), status,
272+
/*replace=*/true);
273+
break;
274+
}
275+
auto* acl_table_definition = getAclTable(app_db_entry.acl_table_name);
276+
if (acl_table_definition == nullptr) {
277+
SWSS_LOG_NOTICE("ACL table SET %s",
278+
app_db_entry.acl_table_name.c_str());
279+
status = processAddTableRequest(app_db_entry);
280+
} else {
281+
// All attributes in sai_acl_table_attr_t are CREATE_ONLY.
282+
status =
283+
ReturnCode(StatusCode::SWSS_RC_UNIMPLEMENTED)
284+
<< "Unable to update ACL table definition in APP DB entry with key "
285+
<< QuotedVar(table_name + ":" + db_key)
286+
<< " : All attributes in sai_acl_table_attr_t are CREATE_ONLY.";
287+
}
288+
} else if (operation == DEL_COMMAND) {
289+
status = processDeleteTableRequest(db_key);
290+
} else {
291+
status = ReturnCode(StatusCode::SWSS_RC_INVALID_PARAM)
292+
<< "Unknown operation type " << QuotedVar(operation);
293+
}
294+
if (!status.ok()) {
295+
SWSS_LOG_ERROR("Processed DEFINITION entry status: %s",
296+
status.message().c_str());
297+
}
298+
m_publisher->publish(APP_P4RT_TABLE_NAME, kfvKey(key_op_fvs_tuple),
299+
kfvFieldsValues(key_op_fvs_tuple), status,
300+
/*replace=*/true);
301+
if (!status.ok()) {
302+
break;
303+
}
304+
}
305+
drainWithNotExecuted();
306+
return status;
299307
}
300308

301309
ReturnCodeOr<P4AclTableDefinitionAppDbEntry> AclTableManager::deserializeAclTableDefinitionAppDbEntry(

orchagent/p4orch/acl_table_manager.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ class AclTableManager : public ObjectManagerInterface
3232
virtual ~AclTableManager();
3333

3434
void enqueue(const std::string &table_name, const swss::KeyOpFieldsValuesTuple &entry) override;
35-
void drain() override;
35+
ReturnCode drain() override;
36+
void drainWithNotExecuted() override;
3637
std::string verifyState(const std::string &key, const std::vector<swss::FieldValueTuple> &tuple) override;
3738
ReturnCode getSaiObject(const std::string &json_key, sai_object_type_t &object_type,
3839
std::string &object_key) override;

0 commit comments

Comments
 (0)