Skip to content

Commit c4e3e54

Browse files
author
Shuotian Cheng
authored
[policerorch]: Add PolicerOrch to bundle with mirror session (#889)
Now that we could create a policer for the mirror session to throttle the mirroring traffic. configuration: POLICER|NAME: meter_type:packets|bytes mode:sr_tcm|tr_tcm|storm_control cir|DIGITS cbs|DIGITS pir|DIGITS pbs|DIGITS corlor_source:aware|blind red_action:drop yellow_action:drop green_action:drop MIRROR_SESSION|NAME: policer:policer_name Signed-off-by: Shu0T1an ChenG <[email protected]>
1 parent f437f9f commit c4e3e54

9 files changed

+588
-11
lines changed

orchagent/Makefile.am

+2-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ orchagent_SOURCES = \
4949
vnetorch.cpp \
5050
dtelorch.cpp \
5151
flexcounterorch.cpp \
52-
watermarkorch.cpp
52+
watermarkorch.cpp \
53+
policerorch.cpp
5354

5455
orchagent_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI)
5556
orchagent_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI)

orchagent/copporch.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,23 @@ extern sai_switch_api_t* sai_switch_api;
1717
extern sai_object_id_t gSwitchId;
1818
extern PortsOrch* gPortsOrch;
1919

20-
map<string, sai_meter_type_t> policer_meter_map = {
20+
static map<string, sai_meter_type_t> policer_meter_map = {
2121
{"packets", SAI_METER_TYPE_PACKETS},
2222
{"bytes", SAI_METER_TYPE_BYTES}
2323
};
2424

25-
map<string, sai_policer_mode_t> policer_mode_map = {
25+
static map<string, sai_policer_mode_t> policer_mode_map = {
2626
{"sr_tcm", SAI_POLICER_MODE_SR_TCM},
2727
{"tr_tcm", SAI_POLICER_MODE_TR_TCM},
2828
{"storm", SAI_POLICER_MODE_STORM_CONTROL}
2929
};
3030

31-
map<string, sai_policer_color_source_t> policer_color_aware_map = {
31+
static map<string, sai_policer_color_source_t> policer_color_aware_map = {
3232
{"aware", SAI_POLICER_COLOR_SOURCE_AWARE},
3333
{"blind", SAI_POLICER_COLOR_SOURCE_BLIND}
3434
};
3535

36-
map<string, sai_hostif_trap_type_t> trap_id_map = {
36+
static map<string, sai_hostif_trap_type_t> trap_id_map = {
3737
{"stp", SAI_HOSTIF_TRAP_TYPE_STP},
3838
{"lacp", SAI_HOSTIF_TRAP_TYPE_LACP},
3939
{"eapol", SAI_HOSTIF_TRAP_TYPE_EAPOL},
@@ -71,7 +71,7 @@ map<string, sai_hostif_trap_type_t> trap_id_map = {
7171
{"udld", SAI_HOSTIF_TRAP_TYPE_UDLD}
7272
};
7373

74-
map<string, sai_packet_action_t> packet_action_map = {
74+
static map<string, sai_packet_action_t> packet_action_map = {
7575
{"drop", SAI_PACKET_ACTION_DROP},
7676
{"forward", SAI_PACKET_ACTION_FORWARD},
7777
{"copy", SAI_PACKET_ACTION_COPY},

orchagent/mirrororch.cpp

+36-2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#define MIRROR_SESSION_MONITOR_PORT "monitor_port"
2525
#define MIRROR_SESSION_ROUTE_PREFIX "route_prefix"
2626
#define MIRROR_SESSION_VLAN_HEADER_VALID "vlan_header_valid"
27+
#define MIRROR_SESSION_POLICER "policer"
2728

2829
#define MIRROR_SESSION_DEFAULT_VLAN_PRI 0
2930
#define MIRROR_SESSION_DEFAULT_VLAN_CFI 0
@@ -60,12 +61,13 @@ MirrorEntry::MirrorEntry(const string& platform) :
6061
}
6162

6263
MirrorOrch::MirrorOrch(TableConnector stateDbConnector, TableConnector confDbConnector,
63-
PortsOrch *portOrch, RouteOrch *routeOrch, NeighOrch *neighOrch, FdbOrch *fdbOrch) :
64+
PortsOrch *portOrch, RouteOrch *routeOrch, NeighOrch *neighOrch, FdbOrch *fdbOrch, PolicerOrch *policerOrch) :
6465
Orch(confDbConnector.first, confDbConnector.second),
6566
m_portsOrch(portOrch),
6667
m_routeOrch(routeOrch),
6768
m_neighOrch(neighOrch),
6869
m_fdbOrch(fdbOrch),
70+
m_policerOrch(policerOrch),
6971
m_mirrorTable(stateDbConnector.first, stateDbConnector.second)
7072
{
7173
m_portsOrch->attach(this);
@@ -239,6 +241,18 @@ void MirrorOrch::createEntry(const string& key, const vector<FieldValueTuple>& d
239241
{
240242
entry.queue = to_uint<uint8_t>(fvValue(i));
241243
}
244+
else if (fvField(i) == MIRROR_SESSION_POLICER)
245+
{
246+
if (!m_policerOrch->policerExists(fvValue(i)))
247+
{
248+
SWSS_LOG_ERROR("Failed to get policer %s",
249+
fvValue(i).c_str());
250+
return;
251+
}
252+
253+
m_policerOrch->increaseRefCount(fvValue(i));
254+
entry.policer = fvValue(i);
255+
}
242256
else
243257
{
244258
SWSS_LOG_ERROR("Failed to parse session %s configuration. Unknown attribute %s.\n", key.c_str(), fvField(i).c_str());
@@ -292,6 +306,11 @@ void MirrorOrch::deleteEntry(const string& name)
292306
deactivateSession(name, session);
293307
}
294308

309+
if (!session.policer.empty())
310+
{
311+
m_policerOrch->decreaseRefCount(session.policer);
312+
}
313+
295314
m_syncdMirrors.erase(sessionIter);
296315

297316
SWSS_LOG_NOTICE("Removed mirror session %s", name.c_str());
@@ -387,7 +406,8 @@ bool MirrorOrch::getNeighborInfo(const string& name, MirrorEntry& session)
387406
}
388407
case Port::VLAN:
389408
{
390-
SWSS_LOG_NOTICE("vlan id is %d", session.neighborInfo.port.m_vlan_info.vlan_id);
409+
SWSS_LOG_NOTICE("Get mirror session destination IP neighbor VLAN %d",
410+
session.neighborInfo.port.m_vlan_info.vlan_id);
391411
Port member;
392412
if (!m_fdbOrch->getPort(session.neighborInfo.mac, session.neighborInfo.port.m_vlan_info.vlan_id, member))
393413
{
@@ -550,6 +570,20 @@ bool MirrorOrch::activateSession(const string& name, MirrorEntry& session)
550570
attr.value.u16 = session.greType;
551571
attrs.push_back(attr);
552572

573+
if (!session.policer.empty())
574+
{
575+
sai_object_id_t oid = SAI_NULL_OBJECT_ID;
576+
if (!m_policerOrch->getPolicerOid(session.policer, oid))
577+
{
578+
SWSS_LOG_ERROR("Faield to get policer %s", session.policer.c_str());
579+
return false;
580+
}
581+
582+
attr.id = SAI_MIRROR_SESSION_ATTR_POLICER;
583+
attr.value.oid = oid;
584+
attrs.push_back(attr);
585+
}
586+
553587
status = sai_mirror_api->
554588
create_mirror_session(&session.sessionId, gSwitchId, (uint32_t)attrs.size(), attrs.data());
555589
if (status != SAI_STATUS_SUCCESS)

orchagent/mirrororch.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "neighorch.h"
88
#include "routeorch.h"
99
#include "fdborch.h"
10+
#include "policerorch.h"
1011

1112
#include "ipaddress.h"
1213
#include "ipaddresses.h"
@@ -30,6 +31,7 @@ struct MirrorEntry
3031
uint8_t dscp;
3132
uint8_t ttl;
3233
uint8_t queue;
34+
string policer;
3335

3436
struct
3537
{
@@ -65,7 +67,7 @@ class MirrorOrch : public Orch, public Observer, public Subject
6567
{
6668
public:
6769
MirrorOrch(TableConnector appDbConnector, TableConnector confDbConnector,
68-
PortsOrch *portOrch, RouteOrch *routeOrch, NeighOrch *neighOrch, FdbOrch *fdbOrch);
70+
PortsOrch *portOrch, RouteOrch *routeOrch, NeighOrch *neighOrch, FdbOrch *fdbOrch, PolicerOrch *policerOrch);
6971

7072
void update(SubjectType, void *);
7173
bool sessionExists(const string&);
@@ -79,6 +81,7 @@ class MirrorOrch : public Orch, public Observer, public Subject
7981
RouteOrch *m_routeOrch;
8082
NeighOrch *m_neighOrch;
8183
FdbOrch *m_fdbOrch;
84+
PolicerOrch *m_policerOrch;
8285

8386
Table m_mirrorTable;
8487

orchagent/orchdaemon.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,11 @@ bool OrchDaemon::init()
128128
};
129129
gBufferOrch = new BufferOrch(m_configDb, buffer_tables);
130130

131+
PolicerOrch *policer_orch = new PolicerOrch(m_configDb, "POLICER");
132+
131133
TableConnector stateDbMirrorSession(m_stateDb, APP_MIRROR_SESSION_TABLE_NAME);
132134
TableConnector confDbMirrorSession(m_configDb, CFG_MIRROR_SESSION_TABLE_NAME);
133-
MirrorOrch *mirror_orch = new MirrorOrch(stateDbMirrorSession, confDbMirrorSession, gPortsOrch, gRouteOrch, gNeighOrch, gFdbOrch);
135+
MirrorOrch *mirror_orch = new MirrorOrch(stateDbMirrorSession, confDbMirrorSession, gPortsOrch, gRouteOrch, gNeighOrch, gFdbOrch, policer_orch);
134136

135137
TableConnector confDbAclTable(m_configDb, CFG_ACL_TABLE_NAME);
136138
TableConnector confDbAclRuleTable(m_configDb, CFG_ACL_RULE_TABLE_NAME);
@@ -163,7 +165,7 @@ bool OrchDaemon::init()
163165
* when iterating ConsumerMap.
164166
* That is ensured implicitly by the order of map key, "LAG_TABLE" is smaller than "VLAN_TABLE" in lexicographic order.
165167
*/
166-
m_orchList = { gSwitchOrch, gCrmOrch, gBufferOrch, gPortsOrch, gIntfsOrch, gNeighOrch, gRouteOrch, copp_orch, tunnel_decap_orch, qos_orch, wm_orch };
168+
m_orchList = { gSwitchOrch, gCrmOrch, gBufferOrch, gPortsOrch, gIntfsOrch, gNeighOrch, gRouteOrch, copp_orch, tunnel_decap_orch, qos_orch, wm_orch, policer_orch };
167169

168170

169171
bool initialize_dtel = false;

orchagent/orchdaemon.h

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "countercheckorch.h"
2727
#include "flexcounterorch.h"
2828
#include "watermarkorch.h"
29+
#include "policerorch.h"
2930
#include "directory.h"
3031

3132
using namespace swss;

0 commit comments

Comments
 (0)