Skip to content

Commit f53cc8c

Browse files
[DASH] Implement PL Redirect Map (#3731)
*[DASH] Implement PL Redirect Map (#3731) What I did Program SAI attributes for OUTBOUND_PORT_MAP and OUTBOUND_PORT_MAP_PORT_RANGE_ENTRY Why I did it As per sonic-net/SONiC#2015
1 parent c5c360e commit f53cc8c

16 files changed

+1096
-89
lines changed

orchagent/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ orchagent_SOURCES = \
123123
dash/dashtunnelorch.cpp \
124124
dash/pbutils.cpp \
125125
dash/dashhaorch.cpp \
126+
dash/dashportmaporch.cpp \
126127
twamporch.cpp \
127128
stporch.cpp
128129

orchagent/bulker.h

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@ typedef sai_status_t (*sai_bulk_set_inbound_routing_entry_attribute_fn) (
3939
_In_ sai_bulk_op_error_mode_t mode,
4040
_Out_ sai_status_t *object_statuses);
4141

42+
typedef sai_status_t (*sai_bulk_set_outbound_port_map_port_range_entry_attribute_fn) (
43+
_In_ uint32_t object_count,
44+
_In_ const sai_outbound_port_map_port_range_entry_t *entry,
45+
_In_ const sai_attribute_t *attr_list,
46+
_In_ sai_bulk_op_error_mode_t mode,
47+
_Out_ sai_status_t *object_statuses);
48+
4249
static inline bool operator==(const sai_ip_prefix_t& a, const sai_ip_prefix_t& b)
4350
{
4451
if (a.addr_family != b.addr_family) return false;
@@ -139,6 +146,15 @@ static inline bool operator==(const sai_outbound_routing_entry_t& a, const sai_o
139146
;
140147
}
141148

149+
static inline bool operator==(const sai_outbound_port_map_port_range_entry_t& a, const sai_outbound_port_map_port_range_entry_t& b)
150+
{
151+
return a.switch_id == b.switch_id
152+
&& a.outbound_port_map_id == b.outbound_port_map_id
153+
&& a.dst_port_range.min == b.dst_port_range.min
154+
&& a.dst_port_range.max == b.dst_port_range.max
155+
;
156+
}
157+
142158
static inline std::size_t hash_value(const sai_ip_prefix_t& a)
143159
{
144160
size_t seed = 0;
@@ -276,6 +292,20 @@ namespace std
276292
return seed;
277293
}
278294
};
295+
296+
template <>
297+
struct hash<sai_outbound_port_map_port_range_entry_t>
298+
{
299+
size_t operator()(const sai_outbound_port_map_port_range_entry_t& a) const noexcept
300+
{
301+
size_t seed = 0;
302+
boost::hash_combine(seed, a.switch_id);
303+
boost::hash_combine(seed, a.outbound_port_map_id);
304+
boost::hash_combine(seed, a.dst_port_range.min);
305+
boost::hash_combine(seed, a.dst_port_range.max);
306+
return seed;
307+
}
308+
};
279309
}
280310

281311
// SAI typedef which is not available in SAI 1.5
@@ -467,6 +497,19 @@ struct SaiBulkerTraits<sai_dash_tunnel_api_t>
467497
using bulk_remove_entry_fn = sai_bulk_object_remove_fn;
468498
};
469499

500+
template<>
501+
struct SaiBulkerTraits<sai_dash_outbound_port_map_api_t>
502+
{
503+
// Need to bulk port map objects and port map range entries from the same DASH API
504+
// entry_t, bulk_create/remove_entry_fn are only used by EntityBulker so we can use them for
505+
// port map port range bulking w/o affecting port map object bulking
506+
using api_t = sai_dash_outbound_port_map_api_t;
507+
using entry_t = sai_outbound_port_map_port_range_entry_t;
508+
using bulk_create_entry_fn = sai_bulk_create_outbound_port_map_port_range_entry_fn;
509+
using bulk_remove_entry_fn = sai_bulk_remove_outbound_port_map_port_range_entry_fn;
510+
using bulk_set_entry_attribute_fn = sai_bulk_set_outbound_port_map_port_range_entry_attribute_fn;
511+
};
512+
470513
template <typename T>
471514
class EntityBulker
472515
{
@@ -921,6 +964,14 @@ inline EntityBulker<sai_dash_outbound_routing_api_t>::EntityBulker(sai_dash_outb
921964
set_entries_attribute = nullptr;
922965
}
923966

967+
template <>
968+
inline EntityBulker<sai_dash_outbound_port_map_api_t>::EntityBulker(sai_dash_outbound_port_map_api_t *api, size_t max_bulk_size) : max_bulk_size(max_bulk_size)
969+
{
970+
create_entries = api->create_outbound_port_map_port_range_entries;
971+
remove_entries = api->remove_outbound_port_map_port_range_entries;
972+
set_entries_attribute = nullptr;
973+
}
974+
924975
template <typename T>
925976
class ObjectBulker
926977
{
@@ -1146,8 +1197,8 @@ class ObjectBulker
11461197
// object_id -> object_status
11471198
std::unordered_map<sai_object_id_t, sai_status_t *> removing_entries;
11481199

1149-
typename Ts::bulk_create_entry_fn create_entries;
1150-
typename Ts::bulk_remove_entry_fn remove_entries;
1200+
sai_bulk_object_create_fn create_entries;
1201+
sai_bulk_object_remove_fn remove_entries;
11511202
// TODO: wait until available in SAI
11521203
//typename Ts::bulk_set_entry_attribute_fn set_entries_attribute;
11531204

@@ -1321,3 +1372,12 @@ inline ObjectBulker<sai_dash_tunnel_api_t>::ObjectBulker(SaiBulkerTraits<sai_das
13211372
throw std::invalid_argument(ss.str());
13221373
}
13231374
}
1375+
1376+
template <>
1377+
inline ObjectBulker<sai_dash_outbound_port_map_api_t>::ObjectBulker(SaiBulkerTraits<sai_dash_outbound_port_map_api_t>::api_t *api, sai_object_id_t switch_id, size_t max_bulk_size) :
1378+
switch_id(switch_id),
1379+
max_bulk_size(max_bulk_size)
1380+
{
1381+
create_entries = api->create_outbound_port_maps;
1382+
remove_entries = api->remove_outbound_port_maps;
1383+
}

0 commit comments

Comments
 (0)