Skip to content

Commit ef37109

Browse files
Merge pull request #4082 from divyagayathri-hcl/set_ip_nexthop_and_disable_rewrites
[P4Orch] Add support for action set_ip_nexthop_and_disable_rewrites in the next hop manager.
2 parents e108aec + c1f53c5 commit ef37109

6 files changed

Lines changed: 652 additions & 66 deletions

File tree

orchagent/p4orch/next_hop_manager.cpp

Lines changed: 128 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,46 +27,57 @@ extern sai_next_hop_api_t *sai_next_hop_api;
2727
extern CrmOrch *gCrmOrch;
2828
extern P4Orch *gP4Orch;
2929

30-
P4NextHopEntry::P4NextHopEntry(const std::string &next_hop_id, const std::string &router_interface_id,
31-
const std::string &gre_tunnel_id, const swss::IpAddress &neighbor_id)
32-
: next_hop_id(next_hop_id), router_interface_id(router_interface_id), gre_tunnel_id(gre_tunnel_id),
33-
neighbor_id(neighbor_id)
34-
{
35-
SWSS_LOG_ENTER();
36-
next_hop_key = KeyGenerator::generateNextHopKey(next_hop_id);
30+
P4NextHopEntry::P4NextHopEntry(
31+
const std::string& next_hop_id, const std::string& router_interface_id,
32+
const std::string& gre_tunnel_id, const swss::IpAddress& neighbor_id,
33+
bool disable_decrement_ttl, bool disable_src_mac_rewrite,
34+
bool disable_dst_mac_rewrite, bool disable_vlan_rewrite)
35+
: next_hop_id(next_hop_id),
36+
router_interface_id(router_interface_id),
37+
gre_tunnel_id(gre_tunnel_id),
38+
neighbor_id(neighbor_id),
39+
disable_decrement_ttl(disable_decrement_ttl),
40+
disable_src_mac_rewrite(disable_src_mac_rewrite),
41+
disable_dst_mac_rewrite(disable_dst_mac_rewrite),
42+
disable_vlan_rewrite(disable_vlan_rewrite) {
43+
SWSS_LOG_ENTER();
44+
next_hop_key = KeyGenerator::generateNextHopKey(next_hop_id);
3745
}
3846

3947
ReturnCode NextHopManager::validateAppDbEntry(
4048
const P4NextHopAppDbEntry& app_db_entry) {
4149
if (app_db_entry.action_str != p4orch::kSetIpNexthop &&
50+
app_db_entry.action_str != p4orch::kSetIpNexthopAndDisableRewrites &&
4251
app_db_entry.action_str != p4orch::kSetNexthop &&
4352
app_db_entry.action_str != p4orch::kSetTunnelNexthop) {
4453
return ReturnCode(StatusCode::SWSS_RC_INVALID_PARAM)
4554
<< "Invalid action " << QuotedVar(app_db_entry.action_str)
4655
<< " of Nexthop App DB entry";
4756
}
48-
if (app_db_entry.action_str == p4orch::kSetIpNexthop &&
57+
if ((app_db_entry.action_str == p4orch::kSetIpNexthop ||
58+
app_db_entry.action_str == p4orch::kSetIpNexthopAndDisableRewrites) &&
4959
app_db_entry.neighbor_id.isZero()) {
5060
return ReturnCode(StatusCode::SWSS_RC_INVALID_PARAM)
5161
<< "Missing field "
5262
<< QuotedVar(prependParamField(p4orch::kNeighborId))
53-
<< " for action " << QuotedVar(p4orch::kSetIpNexthop)
63+
<< " for action " << QuotedVar(app_db_entry.action_str)
5464
<< " in table entry";
5565
}
5666
if (app_db_entry.action_str == p4orch::kSetIpNexthop ||
67+
app_db_entry.action_str == p4orch::kSetIpNexthopAndDisableRewrites ||
5768
app_db_entry.action_str == p4orch::kSetNexthop) {
5869
if (!app_db_entry.gre_tunnel_id.empty()) {
5970
return ReturnCode(StatusCode::SWSS_RC_INVALID_PARAM)
6071
<< "Unexpected field "
6172
<< QuotedVar(prependParamField(p4orch::kTunnelId))
62-
<< " for action " << QuotedVar(p4orch::kSetIpNexthop)
73+
<< " for action " << QuotedVar(app_db_entry.action_str)
6374
<< " in table entry";
6475
}
6576
if (app_db_entry.router_interface_id.empty()) {
6677
return ReturnCode(StatusCode::SWSS_RC_INVALID_PARAM)
6778
<< "Missing field "
6879
<< QuotedVar(prependParamField(p4orch::kRouterInterfaceId))
69-
<< " for action " << QuotedVar(p4orch::kSetIpNexthop)
80+
<< " for action " << QuotedVar(app_db_entry.action_str)
7081
<< " in table entry";
7182
}
7283
}
@@ -187,6 +198,20 @@ ReturnCode NextHopManager::validateAppDbEntry(
187198
return ReturnCode();
188199
}
189200

201+
ReturnCodeOr<bool> parseFlag(std::string name, std::string value) {
202+
try {
203+
int flag = std::stoi(value);
204+
if (flag == 1)
205+
return true;
206+
else if (flag == 0)
207+
return false;
208+
} catch (std::exception& e) {
209+
// Nothing
210+
}
211+
return ReturnCode(StatusCode::SWSS_RC_INVALID_PARAM)
212+
<< "Invalid " << QuotedVar(name) << " value: " << QuotedVar(value);
213+
}
214+
190215
std::vector<sai_attribute_t> NextHopManager::getSaiAttrs(
191216
const P4NextHopEntry& next_hop_entry) {
192217
std::vector<sai_attribute_t> next_hop_attrs;
@@ -224,6 +249,22 @@ std::vector<sai_attribute_t> NextHopManager::getSaiAttrs(
224249
next_hop_attr.id = SAI_NEXT_HOP_ATTR_ROUTER_INTERFACE_ID;
225250
next_hop_attr.value.oid = rif_oid;
226251
next_hop_attrs.push_back(next_hop_attr);
252+
253+
next_hop_attr.id = SAI_NEXT_HOP_ATTR_DISABLE_DECREMENT_TTL;
254+
next_hop_attr.value.booldata = next_hop_entry.disable_decrement_ttl;
255+
next_hop_attrs.push_back(next_hop_attr);
256+
257+
next_hop_attr.id = SAI_NEXT_HOP_ATTR_DISABLE_SRC_MAC_REWRITE;
258+
next_hop_attr.value.booldata = next_hop_entry.disable_src_mac_rewrite;
259+
next_hop_attrs.push_back(next_hop_attr);
260+
261+
next_hop_attr.id = SAI_NEXT_HOP_ATTR_DISABLE_DST_MAC_REWRITE;
262+
next_hop_attr.value.booldata = next_hop_entry.disable_dst_mac_rewrite;
263+
next_hop_attrs.push_back(next_hop_attr);
264+
265+
next_hop_attr.id = SAI_NEXT_HOP_ATTR_DISABLE_VLAN_REWRITE;
266+
next_hop_attr.value.booldata = next_hop_entry.disable_vlan_rewrite;
267+
next_hop_attrs.push_back(next_hop_attr);
227268
}
228269

229270
next_hop_attr.id = SAI_NEXT_HOP_ATTR_IP;
@@ -426,14 +467,35 @@ ReturnCodeOr<P4NextHopAppDbEntry> NextHopManager::deserializeP4NextHopAppDbEntry
426467
{
427468
app_db_entry.gre_tunnel_id = value;
428469
}
470+
else if (field == prependParamField(p4orch::kDisableDecrementTtl))
471+
{
472+
ASSIGN_OR_RETURN(app_db_entry.disable_decrement_ttl,
473+
parseFlag(p4orch::kDisableDecrementTtl, value));
474+
}
475+
else if (field == prependParamField(p4orch::kDisableSrcMacRewrite))
476+
{
477+
ASSIGN_OR_RETURN(app_db_entry.disable_src_mac_rewrite,
478+
parseFlag(p4orch::kDisableSrcMacRewrite, value));
479+
}
480+
else if (field == prependParamField(p4orch::kDisableDstMacRewrite))
481+
{
482+
ASSIGN_OR_RETURN(app_db_entry.disable_dst_mac_rewrite,
483+
parseFlag(p4orch::kDisableDstMacRewrite, value));
484+
}
485+
else if (field == prependParamField(p4orch::kDisableVlanRewrite))
486+
{
487+
ASSIGN_OR_RETURN(app_db_entry.disable_vlan_rewrite,
488+
parseFlag(p4orch::kDisableVlanRewrite, value));
489+
}
429490
else if (field == p4orch::kAction)
430491
{
431492
app_db_entry.action_str = value;
432493
}
433494
else if (field != p4orch::kControllerMetadata)
434495
{
435496
return ReturnCode(StatusCode::SWSS_RC_INVALID_PARAM)
436-
<< "Unexpected field " << QuotedVar(field) << " in table entry";
497+
<< "Unexpected field " << QuotedVar(field)
498+
<< " in table entry";
437499
}
438500
}
439501

@@ -451,10 +513,14 @@ std::vector<ReturnCode> NextHopManager::createNextHops(
451513
std::vector<ReturnCode> statuses(next_hop_entries.size());
452514

453515
for (size_t i = 0; i < next_hop_entries.size(); ++i) {
454-
entries.push_back(P4NextHopEntry(next_hop_entries[i].next_hop_id,
455-
next_hop_entries[i].router_interface_id,
456-
next_hop_entries[i].gre_tunnel_id,
457-
next_hop_entries[i].neighbor_id));
516+
entries.push_back(P4NextHopEntry(
517+
next_hop_entries[i].next_hop_id,
518+
next_hop_entries[i].router_interface_id,
519+
next_hop_entries[i].gre_tunnel_id, next_hop_entries[i].neighbor_id,
520+
next_hop_entries[i].disable_decrement_ttl,
521+
next_hop_entries[i].disable_src_mac_rewrite,
522+
next_hop_entries[i].disable_dst_mac_rewrite,
523+
next_hop_entries[i].disable_vlan_rewrite));
458524
if (!entries[i].gre_tunnel_id.empty()) {
459525
auto gre_tunnel_or =
460526
gP4Orch->getGreTunnelManager()->getConstGreTunnelEntry(
@@ -730,6 +796,52 @@ std::string NextHopManager::verifyStateCache(const P4NextHopAppDbEntry &app_db_e
730796
<< QuotedVar(next_hop_entry->gre_tunnel_id) << " in nexthop manager.";
731797
return msg.str();
732798
}
799+
if (next_hop_entry->disable_decrement_ttl !=
800+
app_db_entry.disable_decrement_ttl) {
801+
std::stringstream msg;
802+
msg << "Nexthop " << QuotedVar(app_db_entry.next_hop_id)
803+
<< " with flag disable_decrement_ttl set to "
804+
<< QuotedVar(app_db_entry.disable_decrement_ttl ? "true" : "false")
805+
<< " does not match internal cache "
806+
<< QuotedVar(next_hop_entry->disable_decrement_ttl ? "true" : "false")
807+
<< " in nexthop manager.";
808+
return msg.str();
809+
}
810+
if (next_hop_entry->disable_src_mac_rewrite !=
811+
app_db_entry.disable_src_mac_rewrite) {
812+
std::stringstream msg;
813+
msg << "Nexthop " << QuotedVar(app_db_entry.next_hop_id)
814+
<< " with flag disable_src_mac_rewrite set to "
815+
<< QuotedVar(app_db_entry.disable_src_mac_rewrite ? "true" : "false")
816+
<< " does not match internal cache "
817+
<< QuotedVar(next_hop_entry->disable_src_mac_rewrite ? "true"
818+
: "false")
819+
<< " in nexthop manager.";
820+
return msg.str();
821+
}
822+
if (next_hop_entry->disable_dst_mac_rewrite !=
823+
app_db_entry.disable_dst_mac_rewrite) {
824+
std::stringstream msg;
825+
msg << "Nexthop " << QuotedVar(app_db_entry.next_hop_id)
826+
<< " with flag disable_dst_mac_rewrite set to "
827+
<< QuotedVar(app_db_entry.disable_dst_mac_rewrite ? "true" : "false")
828+
<< " does not match internal cache "
829+
<< QuotedVar(next_hop_entry->disable_dst_mac_rewrite ? "true"
830+
: "false")
831+
<< " in nexthop manager.";
832+
return msg.str();
833+
}
834+
if (next_hop_entry->disable_vlan_rewrite !=
835+
app_db_entry.disable_vlan_rewrite) {
836+
std::stringstream msg;
837+
msg << "Nexthop " << QuotedVar(app_db_entry.next_hop_id)
838+
<< " with flag disable_vlan_rewrite set to "
839+
<< QuotedVar(app_db_entry.disable_vlan_rewrite ? "true" : "false")
840+
<< " does not match internal cache "
841+
<< QuotedVar(next_hop_entry->disable_vlan_rewrite ? "true" : "false")
842+
<< " in nexthop manager.";
843+
return msg.str();
844+
}
733845
if (!next_hop_entry->gre_tunnel_id.empty())
734846
{
735847
auto gre_tunnel_or = gP4Orch->getGreTunnelManager()->getConstGreTunnelEntry(

orchagent/p4orch/next_hop_manager.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,22 @@ struct P4NextHopEntry
3232
std::string router_interface_id;
3333
std::string gre_tunnel_id;
3434
swss::IpAddress neighbor_id;
35+
bool disable_decrement_ttl = false;
36+
bool disable_src_mac_rewrite = false;
37+
bool disable_dst_mac_rewrite = false;
38+
bool disable_vlan_rewrite = false;
3539

3640
// SAI OID associated with this entry.
3741
sai_object_id_t next_hop_oid = SAI_NULL_OBJECT_ID;
3842

39-
P4NextHopEntry(const std::string &next_hop_id, const std::string &router_interface_id,
40-
const std::string &gre_tunnel_id, const swss::IpAddress &neighbor_id);
43+
P4NextHopEntry(const std::string& next_hop_id,
44+
const std::string& router_interface_id,
45+
const std::string& gre_tunnel_id,
46+
const swss::IpAddress& neighbor_id,
47+
bool disable_decrement_ttl = false,
48+
bool disable_src_mac_rewrite = false,
49+
bool disable_dst_mac_rewrite = false,
50+
bool disable_vlan_rewrite = false);
4151
};
4252

4353
// NextHopManager listens to changes in table APP_P4RT_NEXTHOP_TABLE_NAME and

orchagent/p4orch/p4orch_util.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ constexpr char *kSetWcmpGroupIdAndMetadata = "set_wcmp_group_id_and_metadata";
5656
constexpr char *kSetMetadataAndDrop = "set_metadata_and_drop";
5757
constexpr char *kSetNexthop = "set_nexthop";
5858
constexpr char *kSetIpNexthop = "set_ip_nexthop";
59+
constexpr char* kSetIpNexthopAndDisableRewrites =
60+
"set_ip_nexthop_and_disable_rewrites";
5961
constexpr char *kSetTunnelNexthop = "set_p2p_tunnel_encap_nexthop";
6062
constexpr char *kDrop = "drop";
6163
constexpr char *kTrap = "trap";
@@ -96,6 +98,10 @@ constexpr char *kTos = "tos";
9698
constexpr char *kMirrorAsIpv4Erspan = "mirror_as_ipv4_erspan";
9799
constexpr char *kL3AdmitAction = "admit_to_l3";
98100
constexpr char *kTunnelAction = "mark_for_p2p_tunnel_encap";
101+
constexpr char* kDisableDecrementTtl = "disable_decrement_ttl";
102+
constexpr char* kDisableSrcMacRewrite = "disable_src_mac_rewrite";
103+
constexpr char* kDisableDstMacRewrite = "disable_dst_mac_rewrite";
104+
constexpr char* kDisableVlanRewrite = "disable_vlan_rewrite";
99105

100106
// Field names in P4RT TABLE DEFINITION APP DB entry.
101107
constexpr char *kTables = "tables";
@@ -207,6 +213,10 @@ struct P4NextHopAppDbEntry
207213
std::string gre_tunnel_id;
208214
swss::IpAddress neighbor_id;
209215
std::string action_str;
216+
bool disable_decrement_ttl = false;
217+
bool disable_src_mac_rewrite = false;
218+
bool disable_dst_mac_rewrite = false;
219+
bool disable_vlan_rewrite = false;
210220
};
211221

212222
// P4L3AdmitAppDbEntry holds entry deserialized from table

0 commit comments

Comments
 (0)