@@ -41,18 +41,22 @@ namespace
4141
4242ReturnCode validateAppDbEntry (const P4NextHopAppDbEntry &app_db_entry)
4343{
44+ // TODO(b/225242372): remove kSetNexthop action after P4RT and Orion update
45+ // naming
4446 if (app_db_entry.action_str != p4orch::kSetIpNexthop && app_db_entry.action_str != p4orch::kSetNexthop &&
4547 app_db_entry.action_str != p4orch::kSetTunnelNexthop )
4648 {
4749 return ReturnCode (StatusCode::SWSS_RC_INVALID_PARAM)
4850 << " Invalid action " << QuotedVar (app_db_entry.action_str ) << " of Nexthop App DB entry" ;
4951 }
50- if (app_db_entry.neighbor_id .isZero ())
52+ if (app_db_entry.action_str == p4orch:: kSetIpNexthop && app_db_entry. neighbor_id .isZero ())
5153 {
5254 return ReturnCode (StatusCode::SWSS_RC_INVALID_PARAM)
5355 << " Missing field " << QuotedVar (prependParamField (p4orch::kNeighborId )) << " for action "
5456 << QuotedVar (p4orch::kSetIpNexthop ) << " in table entry" ;
5557 }
58+ // TODO(b/225242372): remove kSetNexthop action after P4RT and Orion update
59+ // naming
5660 if (app_db_entry.action_str == p4orch::kSetIpNexthop || app_db_entry.action_str == p4orch::kSetNexthop )
5761 {
5862 if (!app_db_entry.gre_tunnel_id .empty ())
@@ -321,23 +325,27 @@ ReturnCode NextHopManager::createNextHop(P4NextHopEntry &next_hop_entry)
321325 << " already exists in centralized mapper" );
322326 }
323327
324- std::string router_interface_id = next_hop_entry.router_interface_id ;
325328 if (!next_hop_entry.gre_tunnel_id .empty ())
326329 {
327- auto underlay_if_or = gP4Orch ->getGreTunnelManager ()->getUnderlayIfFromGreTunnelEntry (
330+ auto gre_tunnel_or = gP4Orch ->getGreTunnelManager ()->getConstGreTunnelEntry (
328331 KeyGenerator::generateTunnelKey (next_hop_entry.gre_tunnel_id ));
329- if (!underlay_if_or .ok ())
332+ if (!gre_tunnel_or .ok ())
330333 {
331334 LOG_ERROR_AND_RETURN (ReturnCode (StatusCode::SWSS_RC_NOT_FOUND)
332335 << " GRE Tunnel " << QuotedVar (next_hop_entry.gre_tunnel_id )
333336 << " does not exist in GRE Tunnel Manager" );
334337 }
335- router_interface_id = *underlay_if_or;
338+ next_hop_entry.router_interface_id = (*gre_tunnel_or).router_interface_id ;
339+ // BRCM requires neighbor object to be created before GRE tunnel, referring
340+ // to the one in GRE tunnel object when creating next_hop_entry_with
341+ // setTunnelAction
342+ next_hop_entry.neighbor_id = (*gre_tunnel_or).neighbor_id ;
336343 }
337344
338345 // Neighbor doesn't have OID and the IP addr needed in next hop creation is
339346 // neighbor_id, so only check neighbor existence in centralized mapper.
340- const auto neighbor_key = KeyGenerator::generateNeighborKey (router_interface_id, next_hop_entry.neighbor_id );
347+ const auto neighbor_key =
348+ KeyGenerator::generateNeighborKey (next_hop_entry.router_interface_id , next_hop_entry.neighbor_id );
341349 if (!m_p4OidMapper->existsOID (SAI_OBJECT_TYPE_NEIGHBOR_ENTRY, neighbor_key))
342350 {
343351 LOG_ERROR_AND_RETURN (ReturnCode (StatusCode::SWSS_RC_NOT_FOUND)
@@ -456,15 +464,15 @@ ReturnCode NextHopManager::removeNextHop(const std::string &next_hop_key)
456464 std::string router_interface_id = next_hop_entry->router_interface_id ;
457465 if (!next_hop_entry->gre_tunnel_id .empty ())
458466 {
459- auto underlay_if_or = gP4Orch ->getGreTunnelManager ()->getUnderlayIfFromGreTunnelEntry (
467+ auto gre_tunnel_or = gP4Orch ->getGreTunnelManager ()->getConstGreTunnelEntry (
460468 KeyGenerator::generateTunnelKey (next_hop_entry->gre_tunnel_id ));
461- if (!underlay_if_or .ok ())
469+ if (!gre_tunnel_or .ok ())
462470 {
463471 LOG_ERROR_AND_RETURN (ReturnCode (StatusCode::SWSS_RC_NOT_FOUND)
464472 << " GRE Tunnel " << QuotedVar (next_hop_entry->gre_tunnel_id )
465473 << " does not exist in GRE Tunnel Manager" );
466474 }
467- router_interface_id = *underlay_if_or ;
475+ router_interface_id = (*gre_tunnel_or). router_interface_id ;
468476 }
469477 m_p4OidMapper->decreaseRefCount (
470478 SAI_OBJECT_TYPE_NEIGHBOR_ENTRY,
@@ -560,15 +568,17 @@ std::string NextHopManager::verifyStateCache(const P4NextHopAppDbEntry &app_db_e
560568 << QuotedVar (next_hop_entry->next_hop_id ) << " in nexthop manager." ;
561569 return msg.str ();
562570 }
563- if (next_hop_entry->router_interface_id != app_db_entry.router_interface_id )
571+ if (app_db_entry.action_str == p4orch::kSetIpNexthop &&
572+ next_hop_entry->router_interface_id != app_db_entry.router_interface_id )
564573 {
565574 std::stringstream msg;
566575 msg << " Nexthop " << QuotedVar (app_db_entry.next_hop_id ) << " with ritf ID "
567576 << QuotedVar (app_db_entry.router_interface_id ) << " does not match internal cache "
568577 << QuotedVar (next_hop_entry->router_interface_id ) << " in nexthop manager." ;
569578 return msg.str ();
570579 }
571- if (next_hop_entry->neighbor_id .to_string () != app_db_entry.neighbor_id .to_string ())
580+ if (app_db_entry.action_str == p4orch::kSetIpNexthop &&
581+ next_hop_entry->neighbor_id .to_string () != app_db_entry.neighbor_id .to_string ())
572582 {
573583 std::stringstream msg;
574584 msg << " Nexthop " << QuotedVar (app_db_entry.next_hop_id ) << " with neighbor ID "
@@ -577,14 +587,45 @@ std::string NextHopManager::verifyStateCache(const P4NextHopAppDbEntry &app_db_e
577587 return msg.str ();
578588 }
579589
580- if (next_hop_entry->gre_tunnel_id != app_db_entry.gre_tunnel_id )
590+ if (app_db_entry.action_str == p4orch::kSetTunnelNexthop &&
591+ next_hop_entry->gre_tunnel_id != app_db_entry.gre_tunnel_id )
581592 {
582593 std::stringstream msg;
583594 msg << " Nexthop " << QuotedVar (app_db_entry.next_hop_id ) << " with GRE tunnel ID "
584595 << QuotedVar (app_db_entry.gre_tunnel_id ) << " does not match internal cache "
585596 << QuotedVar (next_hop_entry->gre_tunnel_id ) << " in nexthop manager." ;
586597 return msg.str ();
587598 }
599+ if (!next_hop_entry->gre_tunnel_id .empty ())
600+ {
601+ auto gre_tunnel_or = gP4Orch ->getGreTunnelManager ()->getConstGreTunnelEntry (
602+ KeyGenerator::generateTunnelKey (next_hop_entry->gre_tunnel_id ));
603+ if (!gre_tunnel_or.ok ())
604+ {
605+ std::stringstream msg;
606+ msg << " GRE Tunnel " << QuotedVar (next_hop_entry->gre_tunnel_id ) << " does not exist in GRE Tunnel Manager" ;
607+ return msg.str ();
608+ }
609+ P4GreTunnelEntry gre_tunnel = *gre_tunnel_or;
610+ if (gre_tunnel.neighbor_id .to_string () != next_hop_entry->neighbor_id .to_string ())
611+ {
612+ std::stringstream msg;
613+ msg << " Nexthop " << QuotedVar (next_hop_entry->next_hop_id ) << " with neighbor ID "
614+ << QuotedVar (next_hop_entry->neighbor_id .to_string ())
615+ << " in nexthop manager does not match internal cache " << QuotedVar (gre_tunnel.neighbor_id .to_string ())
616+ << " with tunnel ID " << QuotedVar (gre_tunnel.tunnel_id ) << " in GRE tunnel manager." ;
617+ return msg.str ();
618+ }
619+ if (gre_tunnel.router_interface_id != next_hop_entry->router_interface_id )
620+ {
621+ std::stringstream msg;
622+ msg << " Nexthop " << QuotedVar (next_hop_entry->next_hop_id ) << " with rif ID "
623+ << QuotedVar (next_hop_entry->router_interface_id )
624+ << " in nexthop manager does not match internal cache " << QuotedVar (gre_tunnel.router_interface_id )
625+ << " with tunnel ID " << QuotedVar (gre_tunnel.tunnel_id ) << " in GRE tunnel manager." ;
626+ return msg.str ();
627+ }
628+ }
588629
589630 return m_p4OidMapper->verifyOIDMapping (SAI_OBJECT_TYPE_NEXT_HOP, next_hop_entry->next_hop_key ,
590631 next_hop_entry->next_hop_oid );
0 commit comments