Skip to content

Commit

Permalink
[policerorch]: Add PolicerOrch to bundle with mirror session (#889)
Browse files Browse the repository at this point in the history
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 <shuche@microsoft.com>
  • Loading branch information
Shuotian Cheng committed May 23, 2019
1 parent f437f9f commit c4e3e54
Show file tree
Hide file tree
Showing 9 changed files with 588 additions and 11 deletions.
3 changes: 2 additions & 1 deletion orchagent/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ orchagent_SOURCES = \
vnetorch.cpp \
dtelorch.cpp \
flexcounterorch.cpp \
watermarkorch.cpp
watermarkorch.cpp \
policerorch.cpp

orchagent_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI)
orchagent_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI)
Expand Down
10 changes: 5 additions & 5 deletions orchagent/copporch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,23 @@ extern sai_switch_api_t* sai_switch_api;
extern sai_object_id_t gSwitchId;
extern PortsOrch* gPortsOrch;

map<string, sai_meter_type_t> policer_meter_map = {
static map<string, sai_meter_type_t> policer_meter_map = {
{"packets", SAI_METER_TYPE_PACKETS},
{"bytes", SAI_METER_TYPE_BYTES}
};

map<string, sai_policer_mode_t> policer_mode_map = {
static map<string, sai_policer_mode_t> policer_mode_map = {
{"sr_tcm", SAI_POLICER_MODE_SR_TCM},
{"tr_tcm", SAI_POLICER_MODE_TR_TCM},
{"storm", SAI_POLICER_MODE_STORM_CONTROL}
};

map<string, sai_policer_color_source_t> policer_color_aware_map = {
static map<string, sai_policer_color_source_t> policer_color_aware_map = {
{"aware", SAI_POLICER_COLOR_SOURCE_AWARE},
{"blind", SAI_POLICER_COLOR_SOURCE_BLIND}
};

map<string, sai_hostif_trap_type_t> trap_id_map = {
static map<string, sai_hostif_trap_type_t> trap_id_map = {
{"stp", SAI_HOSTIF_TRAP_TYPE_STP},
{"lacp", SAI_HOSTIF_TRAP_TYPE_LACP},
{"eapol", SAI_HOSTIF_TRAP_TYPE_EAPOL},
Expand Down Expand Up @@ -71,7 +71,7 @@ map<string, sai_hostif_trap_type_t> trap_id_map = {
{"udld", SAI_HOSTIF_TRAP_TYPE_UDLD}
};

map<string, sai_packet_action_t> packet_action_map = {
static map<string, sai_packet_action_t> packet_action_map = {
{"drop", SAI_PACKET_ACTION_DROP},
{"forward", SAI_PACKET_ACTION_FORWARD},
{"copy", SAI_PACKET_ACTION_COPY},
Expand Down
38 changes: 36 additions & 2 deletions orchagent/mirrororch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#define MIRROR_SESSION_MONITOR_PORT "monitor_port"
#define MIRROR_SESSION_ROUTE_PREFIX "route_prefix"
#define MIRROR_SESSION_VLAN_HEADER_VALID "vlan_header_valid"
#define MIRROR_SESSION_POLICER "policer"

#define MIRROR_SESSION_DEFAULT_VLAN_PRI 0
#define MIRROR_SESSION_DEFAULT_VLAN_CFI 0
Expand Down Expand Up @@ -60,12 +61,13 @@ MirrorEntry::MirrorEntry(const string& platform) :
}

MirrorOrch::MirrorOrch(TableConnector stateDbConnector, TableConnector confDbConnector,
PortsOrch *portOrch, RouteOrch *routeOrch, NeighOrch *neighOrch, FdbOrch *fdbOrch) :
PortsOrch *portOrch, RouteOrch *routeOrch, NeighOrch *neighOrch, FdbOrch *fdbOrch, PolicerOrch *policerOrch) :
Orch(confDbConnector.first, confDbConnector.second),
m_portsOrch(portOrch),
m_routeOrch(routeOrch),
m_neighOrch(neighOrch),
m_fdbOrch(fdbOrch),
m_policerOrch(policerOrch),
m_mirrorTable(stateDbConnector.first, stateDbConnector.second)
{
m_portsOrch->attach(this);
Expand Down Expand Up @@ -239,6 +241,18 @@ void MirrorOrch::createEntry(const string& key, const vector<FieldValueTuple>& d
{
entry.queue = to_uint<uint8_t>(fvValue(i));
}
else if (fvField(i) == MIRROR_SESSION_POLICER)
{
if (!m_policerOrch->policerExists(fvValue(i)))
{
SWSS_LOG_ERROR("Failed to get policer %s",
fvValue(i).c_str());
return;
}

m_policerOrch->increaseRefCount(fvValue(i));
entry.policer = fvValue(i);
}
else
{
SWSS_LOG_ERROR("Failed to parse session %s configuration. Unknown attribute %s.\n", key.c_str(), fvField(i).c_str());
Expand Down Expand Up @@ -292,6 +306,11 @@ void MirrorOrch::deleteEntry(const string& name)
deactivateSession(name, session);
}

if (!session.policer.empty())
{
m_policerOrch->decreaseRefCount(session.policer);
}

m_syncdMirrors.erase(sessionIter);

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

if (!session.policer.empty())
{
sai_object_id_t oid = SAI_NULL_OBJECT_ID;
if (!m_policerOrch->getPolicerOid(session.policer, oid))
{
SWSS_LOG_ERROR("Faield to get policer %s", session.policer.c_str());
return false;
}

attr.id = SAI_MIRROR_SESSION_ATTR_POLICER;
attr.value.oid = oid;
attrs.push_back(attr);
}

status = sai_mirror_api->
create_mirror_session(&session.sessionId, gSwitchId, (uint32_t)attrs.size(), attrs.data());
if (status != SAI_STATUS_SUCCESS)
Expand Down
5 changes: 4 additions & 1 deletion orchagent/mirrororch.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "neighorch.h"
#include "routeorch.h"
#include "fdborch.h"
#include "policerorch.h"

#include "ipaddress.h"
#include "ipaddresses.h"
Expand All @@ -30,6 +31,7 @@ struct MirrorEntry
uint8_t dscp;
uint8_t ttl;
uint8_t queue;
string policer;

struct
{
Expand Down Expand Up @@ -65,7 +67,7 @@ class MirrorOrch : public Orch, public Observer, public Subject
{
public:
MirrorOrch(TableConnector appDbConnector, TableConnector confDbConnector,
PortsOrch *portOrch, RouteOrch *routeOrch, NeighOrch *neighOrch, FdbOrch *fdbOrch);
PortsOrch *portOrch, RouteOrch *routeOrch, NeighOrch *neighOrch, FdbOrch *fdbOrch, PolicerOrch *policerOrch);

void update(SubjectType, void *);
bool sessionExists(const string&);
Expand All @@ -79,6 +81,7 @@ class MirrorOrch : public Orch, public Observer, public Subject
RouteOrch *m_routeOrch;
NeighOrch *m_neighOrch;
FdbOrch *m_fdbOrch;
PolicerOrch *m_policerOrch;

Table m_mirrorTable;

Expand Down
6 changes: 4 additions & 2 deletions orchagent/orchdaemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,11 @@ bool OrchDaemon::init()
};
gBufferOrch = new BufferOrch(m_configDb, buffer_tables);

PolicerOrch *policer_orch = new PolicerOrch(m_configDb, "POLICER");

TableConnector stateDbMirrorSession(m_stateDb, APP_MIRROR_SESSION_TABLE_NAME);
TableConnector confDbMirrorSession(m_configDb, CFG_MIRROR_SESSION_TABLE_NAME);
MirrorOrch *mirror_orch = new MirrorOrch(stateDbMirrorSession, confDbMirrorSession, gPortsOrch, gRouteOrch, gNeighOrch, gFdbOrch);
MirrorOrch *mirror_orch = new MirrorOrch(stateDbMirrorSession, confDbMirrorSession, gPortsOrch, gRouteOrch, gNeighOrch, gFdbOrch, policer_orch);

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


bool initialize_dtel = false;
Expand Down
1 change: 1 addition & 0 deletions orchagent/orchdaemon.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "countercheckorch.h"
#include "flexcounterorch.h"
#include "watermarkorch.h"
#include "policerorch.h"
#include "directory.h"

using namespace swss;
Expand Down
Loading

0 comments on commit c4e3e54

Please sign in to comment.