Skip to content

Commit

Permalink
Add SAI TAM Event extension attributes
Browse files Browse the repository at this point in the history
Summary:
Add attributes required for Mirror on Drop on J3:
- SAI_TAM_EVENT_ATTR_EXTENSIONS_COLLECTOR_LIST
- SAI_TAM_EVENT_ATTR_PACKET_DROP_TYPE_MMU
- SAI_TAM_EVENT_ATTR_AGING_GROUP

Reviewed By: nivinl

Differential Revision: D64201667

fbshipit-source-id: f73c57436f37656120f4c6d617a49b50383d4cfa
  • Loading branch information
maxwindiff authored and facebook-github-bot committed Oct 17, 2024
1 parent c4f6f8b commit 7af70f7
Show file tree
Hide file tree
Showing 11 changed files with 325 additions and 43 deletions.
34 changes: 32 additions & 2 deletions fboss/agent/hw/sai/api/TamApi.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,25 +153,55 @@ struct SaiTamEventTraits {
using SwitchEventType = SaiExtensionAttribute<
std::vector<sai_int32_t>,
AttributeSwitchEventType>;

struct AttributeDeviceId {
std::optional<sai_attr_id_t> operator()();
};
using DeviceId = SaiExtensionAttribute<sai_uint32_t, AttributeDeviceId>;
struct AttributeEventId {
std::optional<sai_attr_id_t> operator()();
};
using SwitchEventId = SaiExtensionAttribute<sai_uint32_t, AttributeEventId>;
struct AttributeExtensionsCollectorList {
std::optional<sai_attr_id_t> operator()();
};
using ExtensionsCollectorList = SaiExtensionAttribute<
std::vector<sai_object_id_t>,
AttributeExtensionsCollectorList>;
struct AttributePacketDropTypeMmu {
std::optional<sai_attr_id_t> operator()();
};
using PacketDropTypeMmu = SaiExtensionAttribute<
std::vector<sai_int32_t>,
AttributePacketDropTypeMmu>;
struct AttributeAgingGroup {
std::optional<sai_attr_id_t> operator()();
};
using AgingGroup =
SaiExtensionAttribute<sai_object_id_t, AttributeAgingGroup>;
};
using AdapterKey = TamEventSaiId;
using AdapterHostKey = std::tuple<
Attributes::Type,
Attributes::ActionList,
Attributes::CollectorList,
Attributes::SwitchEventType>;
Attributes::SwitchEventType,
std::optional<Attributes::DeviceId>,
std::optional<Attributes::SwitchEventId>,
std::optional<Attributes::ExtensionsCollectorList>,
std::optional<Attributes::PacketDropTypeMmu>,
std::optional<Attributes::AgingGroup>>;
using CreateAttributes = AdapterHostKey;
};

SAI_ATTRIBUTE_NAME(TamEvent, Type)
SAI_ATTRIBUTE_NAME(TamEvent, ActionList)
SAI_ATTRIBUTE_NAME(TamEvent, CollectorList)
SAI_ATTRIBUTE_NAME(TamEvent, SwitchEventType)
SAI_ATTRIBUTE_NAME(TamEvent, DeviceId)
SAI_ATTRIBUTE_NAME(TamEvent, SwitchEventId)
SAI_ATTRIBUTE_NAME(TamEvent, ExtensionsCollectorList)
SAI_ATTRIBUTE_NAME(TamEvent, PacketDropTypeMmu)
SAI_ATTRIBUTE_NAME(TamEvent, AgingGroup)

struct SaiTamTraits {
static constexpr sai_object_type_t ObjectType = SAI_OBJECT_TYPE_TAM;
Expand Down
35 changes: 35 additions & 0 deletions fboss/agent/hw/sai/api/bcm/TamApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,43 @@ SaiTamEventTraits::Attributes::AttributeSwitchEventType::operator()() {
return std::nullopt;
}

std::optional<sai_attr_id_t>
SaiTamEventTraits::Attributes::AttributeDeviceId::operator()() {
#if defined(SAI_VERSION_11_3_0_0_DNX_ODP)
return SAI_TAM_EVENT_ATTR_DEVICE_ID;
#endif
return std::nullopt;
}

std::optional<sai_attr_id_t>
SaiTamEventTraits::Attributes::AttributeEventId::operator()() {
#if defined(SAI_VERSION_11_3_0_0_DNX_ODP)
return SAI_TAM_EVENT_ATTR_EVENT_ID;
#endif
return std::nullopt;
}

std::optional<sai_attr_id_t>
SaiTamEventTraits::Attributes::AttributeExtensionsCollectorList::operator()() {
#if defined(SAI_VERSION_11_3_0_0_DNX_ODP)
return SAI_TAM_EVENT_ATTR_EXTENSIONS_COLLECTOR_LIST;
#endif
return std::nullopt;
}

std::optional<sai_attr_id_t>
SaiTamEventTraits::Attributes::AttributePacketDropTypeMmu::operator()() {
#if defined(SAI_VERSION_11_3_0_0_DNX_ODP)
return SAI_TAM_EVENT_ATTR_PACKET_DROP_TYPE_MMU;
#endif
return std::nullopt;
}

std::optional<sai_attr_id_t>
SaiTamEventTraits::Attributes::AttributeAgingGroup::operator()() {
#if defined(SAI_VERSION_11_3_0_0_DNX_ODP)
return SAI_TAM_EVENT_ATTR_AGING_GROUP;
#endif
return std::nullopt;
}

Expand Down
20 changes: 20 additions & 0 deletions fboss/agent/hw/sai/api/fake/FakeSaiExtensions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,31 @@ SaiTamEventTraits::Attributes::AttributeSwitchEventType::operator()() {
return SAI_TAM_EVENT_ATTR_FAKE_SWITCH_EVENT_TYPE;
}

std::optional<sai_attr_id_t>
SaiTamEventTraits::Attributes::AttributeDeviceId::operator()() {
return SAI_TAM_EVENT_ATTR_FAKE_DEVICE_ID;
}

std::optional<sai_attr_id_t>
SaiTamEventTraits::Attributes::AttributeEventId::operator()() {
return SAI_TAM_EVENT_ATTR_FAKE_SWITCH_EVENT_ID;
}

std::optional<sai_attr_id_t>
SaiTamEventTraits::Attributes::AttributeExtensionsCollectorList::operator()() {
return SAI_TAM_EVENT_ATTR_FAKE_EXTENSIONS_COLLECTOR_LIST;
}

std::optional<sai_attr_id_t>
SaiTamEventTraits::Attributes::AttributePacketDropTypeMmu::operator()() {
return SAI_TAM_EVENT_ATTR_FAKE_PACKET_DROP_TYPE_MMU;
}

std::optional<sai_attr_id_t>
SaiTamEventTraits::Attributes::AttributeAgingGroup::operator()() {
return SAI_TAM_EVENT_ATTR_FAKE_AGING_GROUP;
}

std::optional<sai_attr_id_t>
SaiTamTransportTraits::Attributes::AttributeSrcMacAddress::operator()() {
return SAI_TAM_TRANSPORT_ATTR_FAKE_SRC_MAC_ADDRESS;
Expand Down
4 changes: 4 additions & 0 deletions fboss/agent/hw/sai/api/fake/saifakeextensions.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,11 @@ typedef enum _sai_switch_extensions_attr_t {

typedef enum _sai_tam_event_extensions_attr_t {
SAI_TAM_EVENT_ATTR_FAKE_SWITCH_EVENT_TYPE = SAI_TAM_EVENT_ATTR_END,
SAI_TAM_EVENT_ATTR_FAKE_DEVICE_ID,
SAI_TAM_EVENT_ATTR_FAKE_SWITCH_EVENT_ID,
SAI_TAM_EVENT_ATTR_FAKE_EXTENSIONS_COLLECTOR_LIST,
SAI_TAM_EVENT_ATTR_FAKE_PACKET_DROP_TYPE_MMU,
SAI_TAM_EVENT_ATTR_FAKE_AGING_GROUP,
SAI_TAM_TRANSPORT_ATTR_FAKE_SRC_MAC_ADDRESS = SAI_TAM_TRANSPORT_ATTR_END,
SAI_TAM_TRANSPORT_ATTR_FAKE_DST_MAC_ADDRESS,
} sai_tam_event_extensions_attr_t;
Expand Down
20 changes: 20 additions & 0 deletions fboss/agent/hw/sai/api/oss/TamApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,31 @@ SaiTamEventTraits::Attributes::AttributeSwitchEventType::operator()() {
return std::nullopt;
}

std::optional<sai_attr_id_t>
SaiTamEventTraits::Attributes::AttributeDeviceId::operator()() {
return std::nullopt;
}

std::optional<sai_attr_id_t>
SaiTamEventTraits::Attributes::AttributeEventId::operator()() {
return std::nullopt;
}

std::optional<sai_attr_id_t>
SaiTamEventTraits::Attributes::AttributeExtensionsCollectorList::operator()() {
return std::nullopt;
}

std::optional<sai_attr_id_t>
SaiTamEventTraits::Attributes::AttributePacketDropTypeMmu::operator()() {
return std::nullopt;
}

std::optional<sai_attr_id_t>
SaiTamEventTraits::Attributes::AttributeAgingGroup::operator()() {
return std::nullopt;
}

std::optional<sai_attr_id_t>
SaiTamTransportTraits::Attributes::AttributeSrcMacAddress::operator()() {
return std::nullopt;
Expand Down
20 changes: 20 additions & 0 deletions fboss/agent/hw/sai/api/tajo/TamApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,31 @@ SaiTamEventTraits::Attributes::AttributeSwitchEventType::operator()() {
return SAI_TAM_EVENT_ATTR_SWITCH_EVENT_TYPE;
}

std::optional<sai_attr_id_t>
SaiTamEventTraits::Attributes::AttributeDeviceId::operator()() {
return std::nullopt;
}

std::optional<sai_attr_id_t>
SaiTamEventTraits::Attributes::AttributeEventId::operator()() {
return std::nullopt;
}

std::optional<sai_attr_id_t>
SaiTamEventTraits::Attributes::AttributeExtensionsCollectorList::operator()() {
return std::nullopt;
}

std::optional<sai_attr_id_t>
SaiTamEventTraits::Attributes::AttributePacketDropTypeMmu::operator()() {
return std::nullopt;
}

std::optional<sai_attr_id_t>
SaiTamEventTraits::Attributes::AttributeAgingGroup::operator()() {
return std::nullopt;
}

std::optional<sai_attr_id_t>
SaiTamTransportTraits::Attributes::AttributeSrcMacAddress::operator()() {
return std::nullopt;
Expand Down
17 changes: 17 additions & 0 deletions fboss/agent/hw/sai/api/tests/TamApiTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,12 @@ TEST_F(TamApiTest, TamEvent) {
std::vector<sai_object_id_t> eventCollectors{SAI_NULL_OBJECT_ID};
std::vector<sai_int32_t> eventTypes{1, 2, 3, 4}; // parity error e.g.

sai_int32_t deviceId = 0;
sai_int32_t eventId = 1;
std::vector<sai_object_id_t> extensionsCollectorList{10};
std::vector<sai_int32_t> packetDropTypeMmu = {3, 4};
sai_object_id_t agingGroup = 20;

SaiTamEventTraits::CreateAttributes eventAttr;
std::get<SaiTamEventTraits::Attributes::Type>(eventAttr) =
SAI_TAM_EVENT_TYPE_PACKET_DROP; // type of Event
Expand All @@ -150,6 +156,17 @@ TEST_F(TamApiTest, TamEvent) {
eventCollectors;
std::get<SaiTamEventTraits::Attributes::SwitchEventType>(eventAttr) =
eventTypes;
std::get<std::optional<SaiTamEventTraits::Attributes::DeviceId>>(eventAttr) =
deviceId;
std::get<std::optional<SaiTamEventTraits::Attributes::SwitchEventId>>(
eventAttr) = eventId;
std::get<
std::optional<SaiTamEventTraits::Attributes::ExtensionsCollectorList>>(
eventAttr) = extensionsCollectorList;
std::get<std::optional<SaiTamEventTraits::Attributes::PacketDropTypeMmu>>(
eventAttr) = packetDropTypeMmu;
std::get<std::optional<SaiTamEventTraits::Attributes::AgingGroup>>(
eventAttr) = agingGroup;

auto eventSaiId = tamApi->create<SaiTamEventTraits>(eventAttr, switchId);
EXPECT_EQ(
Expand Down
Loading

0 comments on commit 7af70f7

Please sign in to comment.