Skip to content

Commit 793343d

Browse files
author
Shuotian Cheng
authored
[switchorch]: Add SwitchOrch to deal with switch attributes changes (sonic-net#314)
Right now, three switch attributes are supported: FDB unicast/multicast/ broadcast miss packet action. The attribute could be set to drop, forward, or trap. The current implementation adds switch configuration to the APPL_DB. In the future, it would be migrated to the CONF_DB.
1 parent 625d1d9 commit 793343d

File tree

5 files changed

+102
-2
lines changed

5 files changed

+102
-2
lines changed

orchagent/Makefile.am

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ else
1010
DBGFLAGS = -g -DNDEBUG
1111
endif
1212

13-
orchagent_SOURCES = main.cpp port.cpp orchdaemon.cpp orch.cpp notifications.cpp routeorch.cpp neighorch.cpp intfsorch.cpp portsorch.cpp copporch.cpp tunneldecaporch.cpp qosorch.cpp bufferorch.cpp mirrororch.cpp fdborch.cpp aclorch.cpp saihelper.cpp
13+
orchagent_SOURCES = main.cpp port.cpp orchdaemon.cpp orch.cpp notifications.cpp routeorch.cpp neighorch.cpp intfsorch.cpp portsorch.cpp copporch.cpp tunneldecaporch.cpp qosorch.cpp bufferorch.cpp mirrororch.cpp fdborch.cpp aclorch.cpp switchorch.cpp saihelper.cpp
1414

1515
orchagent_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI)
1616
orchagent_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI)

orchagent/orchdaemon.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ bool OrchDaemon::init()
3737
{
3838
SWSS_LOG_ENTER();
3939

40+
SwitchOrch *switch_orch = new SwitchOrch(m_applDb, APP_SWITCH_TABLE_NAME);
41+
4042
vector<string> ports_tables = {
4143
APP_PORT_TABLE_NAME,
4244
APP_VLAN_TABLE_NAME,
@@ -84,7 +86,7 @@ bool OrchDaemon::init()
8486
};
8587
AclOrch *acl_orch = new AclOrch(m_applDb, acl_tables, gPortsOrch, mirror_orch, neigh_orch, route_orch);
8688

87-
m_orchList = { gPortsOrch, intfs_orch, neigh_orch, route_orch, copp_orch, tunnel_decap_orch, qos_orch, buffer_orch, mirror_orch, acl_orch, gFdbOrch};
89+
m_orchList = { switch_orch, gPortsOrch, intfs_orch, neigh_orch, route_orch, copp_orch, tunnel_decap_orch, qos_orch, buffer_orch, mirror_orch, acl_orch, gFdbOrch};
8890
m_select = new Select();
8991

9092
return true;

orchagent/orchdaemon.h

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "mirrororch.h"
1818
#include "fdborch.h"
1919
#include "aclorch.h"
20+
#include "switchorch.h"
2021

2122
using namespace swss;
2223

orchagent/switchorch.cpp

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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+
}

orchagent/switchorch.h

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#pragma once
2+
3+
#include "orch.h"
4+
5+
class SwitchOrch : public Orch
6+
{
7+
public:
8+
SwitchOrch(DBConnector *db, string tableName);
9+
10+
private:
11+
void doTask(Consumer &consumer);
12+
};

0 commit comments

Comments
 (0)