Skip to content

Commit

Permalink
NAT bulking and SAI NAT aging notification
Browse files Browse the repository at this point in the history
  • Loading branch information
arvbb committed Dec 27, 2021
1 parent a4c80c3 commit 1a4f67b
Show file tree
Hide file tree
Showing 6 changed files with 461 additions and 252 deletions.
63 changes: 63 additions & 0 deletions orchagent/bulker.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,24 @@ static inline bool operator==(const sai_route_entry_t& a, const sai_route_entry_
;
}

static inline bool operator==(const sai_nat_entry_t& a, const sai_nat_entry_t& b)
{
return a.switch_id == b.switch_id
&& a.vr_id == b.vr_id
&& a.nat_type == b.nat_type
&& a.data.key.src_ip == b.data.key.src_ip
&& a.data.key.dst_ip == b.data.key.dst_ip
&& a.data.key.proto == b.data.key.proto
&& a.data.key.l4_src_port == b.data.key.l4_src_port
&& a.data.key.l4_dst_port == b.data.key.l4_dst_port
&& a.data.mask.src_ip == b.data.mask.src_ip
&& a.data.mask.dst_ip == b.data.mask.dst_ip
&& a.data.mask.proto == b.data.mask.proto
&& a.data.mask.l4_src_port == b.data.mask.l4_src_port
&& a.data.mask.l4_dst_port == b.data.mask.l4_dst_port
;
}

static inline bool operator==(const sai_inseg_entry_t& a, const sai_inseg_entry_t& b)
{
return a.switch_id == b.switch_id
Expand Down Expand Up @@ -80,6 +98,29 @@ namespace std
}
};

template <>
struct hash<sai_nat_entry_t>
{
size_t operator()(const sai_nat_entry_t& a) const noexcept
{
size_t seed = 0;
boost::hash_combine(seed, a.switch_id);
boost::hash_combine(seed, a.vr_id);
boost::hash_combine(seed, a.nat_type);
boost::hash_combine(seed, a.data.key.src_ip);
boost::hash_combine(seed, a.data.key.dst_ip);
boost::hash_combine(seed, a.data.key.proto);
boost::hash_combine(seed, a.data.key.l4_src_port);
boost::hash_combine(seed, a.data.key.l4_dst_port);
boost::hash_combine(seed, a.data.mask.src_ip);
boost::hash_combine(seed, a.data.mask.dst_ip);
boost::hash_combine(seed, a.data.mask.proto);
boost::hash_combine(seed, a.data.mask.l4_src_port);
boost::hash_combine(seed, a.data.mask.l4_dst_port);
return seed;
}
};

template <>
struct hash<sai_fdb_entry_t>
{
Expand Down Expand Up @@ -143,6 +184,19 @@ struct SaiBulkerTraits<sai_route_api_t>
using bulk_set_entry_attribute_fn = sai_bulk_set_route_entry_attribute_fn;
};

template<>
struct SaiBulkerTraits<sai_nat_api_t>
{
using entry_t = sai_nat_entry_t;
using api_t = sai_nat_api_t;
using create_entry_fn = sai_create_nat_entry_fn;
using remove_entry_fn = sai_remove_nat_entry_fn;
using set_entry_attribute_fn = sai_set_nat_entry_attribute_fn;
using bulk_create_entry_fn = sai_bulk_create_nat_entry_fn;
using bulk_remove_entry_fn = sai_bulk_remove_nat_entry_fn;
using bulk_set_entry_attribute_fn = sai_bulk_set_nat_entry_attribute_fn;
};

template<>
struct SaiBulkerTraits<sai_fdb_api_t>
{
Expand Down Expand Up @@ -574,6 +628,15 @@ inline EntityBulker<sai_route_api_t>::EntityBulker(sai_route_api_t *api, size_t
set_entries_attribute = api->set_route_entries_attribute;
}

template <>
inline EntityBulker<sai_nat_api_t>::EntityBulker(sai_nat_api_t *api, size_t max_bulk_size) :
max_bulk_size(max_bulk_size)
{
create_entries = api->create_nat_entries;
remove_entries = api->remove_nat_entries;
set_entries_attribute = api->set_nat_entries_attribute;
}

template <>
inline EntityBulker<sai_fdb_api_t>::EntityBulker(sai_fdb_api_t *api, size_t max_bulk_size) :
max_bulk_size(max_bulk_size)
Expand Down
3 changes: 3 additions & 0 deletions orchagent/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,9 @@ int main(int argc, char **argv)
attr.id = SAI_SWITCH_ATTR_FDB_EVENT_NOTIFY;
attr.value.ptr = (void *)on_fdb_event;
attrs.push_back(attr);
attr.id = SAI_SWITCH_ATTR_NAT_EVENT_NOTIFY;
attr.value.ptr = (void *)on_nat_event;
attrs.push_back(attr);

// Initialize recording parameters.
gSairedisRecord =
Expand Down
Loading

0 comments on commit 1a4f67b

Please sign in to comment.