|
| 1 | +#include <map> |
| 2 | + |
| 3 | +#include "switchorch.h" |
| 4 | + |
| 5 | +using namespace std; |
| 6 | +using namespace swss; |
| 7 | + |
| 8 | +extern sai_object_id_t gSwitchId; |
| 9 | +extern sai_switch_api_t *sai_switch_api; |
| 10 | + |
| 11 | +const map<string, sai_switch_attr_t> switch_attribute_map = |
| 12 | +{ |
| 13 | + {"fdb_unicast_miss_packet_action", SAI_SWITCH_ATTR_FDB_UNICAST_MISS_PACKET_ACTION}, |
| 14 | + {"fdb_broadcast_miss_packet_action", SAI_SWITCH_ATTR_FDB_BROADCAST_MISS_PACKET_ACTION}, |
| 15 | + {"fdb_multicast_miss_packet_action", SAI_SWITCH_ATTR_FDB_MULTICAST_MISS_PACKET_ACTION} |
| 16 | +}; |
| 17 | + |
| 18 | +const map<string, sai_packet_action_t> packet_action_map = |
| 19 | +{ |
| 20 | + {"drop", SAI_PACKET_ACTION_DROP}, |
| 21 | + {"forward", SAI_PACKET_ACTION_FORWARD}, |
| 22 | + {"trap", SAI_PACKET_ACTION_TRAP} |
| 23 | +}; |
| 24 | + |
| 25 | +SwitchOrch::SwitchOrch(DBConnector *db, string tableName) : |
| 26 | + Orch(db, tableName) |
| 27 | +{ |
| 28 | +} |
| 29 | + |
| 30 | +void SwitchOrch::doTask(Consumer &consumer) |
| 31 | +{ |
| 32 | + SWSS_LOG_ENTER(); |
| 33 | + |
| 34 | + auto it = consumer.m_toSync.begin(); |
| 35 | + while (it != consumer.m_toSync.end()) |
| 36 | + { |
| 37 | + auto t = it->second; |
| 38 | + |
| 39 | + auto op = kfvOp(t); |
| 40 | + |
| 41 | + if (op == SET_COMMAND) |
| 42 | + { |
| 43 | + for (auto i : kfvFieldsValues(t)) |
| 44 | + { |
| 45 | + auto attribute = fvField(i); |
| 46 | + |
| 47 | + if (switch_attribute_map.find(attribute) == switch_attribute_map.end()) |
| 48 | + { |
| 49 | + SWSS_LOG_ERROR("Unsupported switch attribute %s", attribute.c_str()); |
| 50 | + it = consumer.m_toSync.erase(it); |
| 51 | + continue; |
| 52 | + } |
| 53 | + |
| 54 | + auto value = fvValue(i); |
| 55 | + if (packet_action_map.find(value) == packet_action_map.end()) |
| 56 | + { |
| 57 | + SWSS_LOG_ERROR("Unsupported packet action %s", value.c_str()); |
| 58 | + it = consumer.m_toSync.erase(it); |
| 59 | + continue; |
| 60 | + } |
| 61 | + |
| 62 | + sai_attribute_t attr; |
| 63 | + attr.id = switch_attribute_map.at(attribute); |
| 64 | + attr.value.s32 = packet_action_map.at(value); |
| 65 | + |
| 66 | + sai_status_t status = sai_switch_api->set_switch_attribute(gSwitchId, &attr); |
| 67 | + if (status != SAI_STATUS_SUCCESS) |
| 68 | + { |
| 69 | + SWSS_LOG_ERROR("Failed to set switch attribute %s to %s, rv:%d", |
| 70 | + attribute.c_str(), value.c_str(), status); |
| 71 | + it++; |
| 72 | + continue; |
| 73 | + } |
| 74 | + |
| 75 | + SWSS_LOG_NOTICE("Set switch attribute %s to %s", attribute.c_str(), value.c_str()); |
| 76 | + it = consumer.m_toSync.erase(it); |
| 77 | + } |
| 78 | + } |
| 79 | + else |
| 80 | + { |
| 81 | + SWSS_LOG_WARN("Unsupported operation"); |
| 82 | + it = consumer.m_toSync.erase(it); |
| 83 | + } |
| 84 | + } |
| 85 | +} |
0 commit comments