@@ -720,8 +720,11 @@ VNetRouteOrch::VNetRouteOrch(DBConnector *db, vector<string> &tableNames, VNetOr
720
720
handler_map_.insert (handler_pair (APP_VNET_RT_TUNNEL_TABLE_NAME, &VNetRouteOrch::handleTunnel));
721
721
722
722
state_db_ = shared_ptr<DBConnector>(new DBConnector (" STATE_DB" , 0 ));
723
+ app_db_ = shared_ptr<DBConnector>(new DBConnector (" APPL_DB" , 0 ));
724
+
723
725
state_vnet_rt_tunnel_table_ = unique_ptr<Table>(new Table (state_db_.get (), STATE_VNET_RT_TUNNEL_TABLE_NAME));
724
726
state_vnet_rt_adv_table_ = unique_ptr<Table>(new Table (state_db_.get (), STATE_ADVERTISE_NETWORK_TABLE_NAME));
727
+ monitor_session_producer_ = unique_ptr<Table>(new Table (app_db_.get (), APP_VNET_MONITOR_TABLE_NAME));
725
728
726
729
gBfdOrch ->attach (this );
727
730
}
@@ -900,6 +903,7 @@ bool VNetRouteOrch::removeNextHopGroup(const string& vnet, const NextHopGroupKey
900
903
template <>
901
904
bool VNetRouteOrch::doRouteTask<VNetVrfObject>(const string& vnet, IpPrefix& ipPrefix,
902
905
NextHopGroupKey& nexthops, string& op, string& profile,
906
+ const string& monitoring,
903
907
const map<NextHopKey, IpAddress>& monitors)
904
908
{
905
909
SWSS_LOG_ENTER ();
@@ -940,7 +944,7 @@ bool VNetRouteOrch::doRouteTask<VNetVrfObject>(const string& vnet, IpPrefix& ipP
940
944
sai_object_id_t nh_id;
941
945
if (!hasNextHopGroup (vnet, nexthops))
942
946
{
943
- setEndpointMonitor (vnet, monitors, nexthops);
947
+ setEndpointMonitor (vnet, monitors, nexthops, monitoring, ipPrefix );
944
948
if (nexthops.getSize () == 1 )
945
949
{
946
950
NextHopKey nexthop (nexthops.to_string (), true );
@@ -957,7 +961,7 @@ bool VNetRouteOrch::doRouteTask<VNetVrfObject>(const string& vnet, IpPrefix& ipP
957
961
{
958
962
if (!addNextHopGroup (vnet, nexthops, vrf_obj))
959
963
{
960
- delEndpointMonitor (vnet, nexthops);
964
+ delEndpointMonitor (vnet, nexthops, ipPrefix );
961
965
SWSS_LOG_ERROR (" Failed to create next hop group %s" , nexthops.to_string ().c_str ());
962
966
return false ;
963
967
}
@@ -1031,7 +1035,7 @@ bool VNetRouteOrch::doRouteTask<VNetVrfObject>(const string& vnet, IpPrefix& ipP
1031
1035
NextHopKey nexthop (nhg.to_string (), true );
1032
1036
vrf_obj->removeTunnelNextHop (nexthop);
1033
1037
}
1034
- delEndpointMonitor (vnet, nhg);
1038
+ delEndpointMonitor (vnet, nhg, ipPrefix );
1035
1039
}
1036
1040
else
1037
1041
{
@@ -1091,7 +1095,7 @@ bool VNetRouteOrch::doRouteTask<VNetVrfObject>(const string& vnet, IpPrefix& ipP
1091
1095
NextHopKey nexthop (nhg.to_string (), true );
1092
1096
vrf_obj->removeTunnelNextHop (nexthop);
1093
1097
}
1094
- delEndpointMonitor (vnet, nhg);
1098
+ delEndpointMonitor (vnet, nhg, ipPrefix );
1095
1099
}
1096
1100
else
1097
1101
{
@@ -1609,39 +1613,118 @@ void VNetRouteOrch::removeBfdSession(const string& vnet, const NextHopKey& endpo
1609
1613
bfd_sessions_.erase (monitor_addr);
1610
1614
}
1611
1615
1612
- void VNetRouteOrch::setEndpointMonitor (const string& vnet, const map<NextHopKey, IpAddress>& monitors, NextHopGroupKey& nexthops)
1616
+ void VNetRouteOrch::createMonitoringSession (const string& vnet, const NextHopKey& endpoint, const IpAddress& monitor_addr, IpPrefix& ipPrefix)
1617
+ {
1618
+ SWSS_LOG_ENTER ();
1619
+
1620
+ IpAddress endpoint_addr = endpoint.ip_address ;
1621
+ if (monitor_info_[vnet].find (ipPrefix) != monitor_info_[vnet].end () &&
1622
+ monitor_info_[vnet][ipPrefix].find (endpoint) != monitor_info_[vnet][ipPrefix].end ())
1623
+ {
1624
+ SWSS_LOG_NOTICE (" Monitoring session for prefix %s endpoint %s already exist" , ipPrefix.to_string ().c_str (), endpoint_addr.to_string ().c_str ());
1625
+ return ;
1626
+ }
1627
+ else
1628
+ {
1629
+ vector<FieldValueTuple> data;
1630
+ auto *vnet_obj = vnet_orch_->getTypePtr <VNetVrfObject>(vnet);
1631
+
1632
+ auto overlay_dmac = vnet_obj->getOverlayDMac ();
1633
+ string key = ipPrefix.to_string () + " :" + monitor_addr.to_string ();
1634
+ FieldValueTuple fvTuple1 (" packet_type" , " vxlan" );
1635
+ data.push_back (fvTuple1);
1636
+
1637
+ FieldValueTuple fvTuple3 (" overlay_dmac" , overlay_dmac.to_string ());
1638
+ data.push_back (fvTuple3);
1639
+
1640
+ monitor_session_producer_->set (key, data);
1641
+
1642
+ MonitorSessionInfo& info = monitor_info_[vnet][ipPrefix][endpoint];
1643
+ info.monitor = monitor_addr;
1644
+ info.state = MONITOR_SESSION_STATE::MONITOR_SESSION_STATE_DOWN;
1645
+ }
1646
+ }
1647
+
1648
+ void VNetRouteOrch::removeMonitoringSession (const string& vnet, const NextHopKey& endpoint, const IpAddress& monitor_addr, IpPrefix& ipPrefix)
1649
+ {
1650
+ SWSS_LOG_ENTER ();
1651
+
1652
+ IpAddress endpoint_addr = endpoint.ip_address ;
1653
+ if (monitor_info_[vnet].find (ipPrefix) == monitor_info_[vnet].end () ||
1654
+ monitor_info_[vnet][ipPrefix].find (endpoint) == monitor_info_[vnet][ipPrefix].end ())
1655
+ {
1656
+ SWSS_LOG_NOTICE (" Monitor session for prefix %s endpoint %s does not exist" , ipPrefix.to_string ().c_str (), endpoint_addr.to_string ().c_str ());
1657
+ }
1658
+
1659
+ string key = ipPrefix.to_string () + " :" + monitor_addr.to_string ();
1660
+ monitor_session_producer_->del (key);
1661
+ monitor_info_[vnet][ipPrefix].erase (endpoint);
1662
+ }
1663
+
1664
+ void VNetRouteOrch::setEndpointMonitor (const string& vnet, const map<NextHopKey, IpAddress>& monitors, NextHopGroupKey& nexthops, const string& monitoring, IpPrefix& ipPrefix)
1613
1665
{
1614
1666
SWSS_LOG_ENTER ();
1615
1667
1616
1668
for (auto monitor : monitors)
1617
1669
{
1618
1670
NextHopKey nh = monitor.first ;
1619
1671
IpAddress monitor_ip = monitor.second ;
1620
- if (nexthop_info_[vnet]. find (nh. ip_address ) == nexthop_info_[vnet]. end () )
1672
+ if (monitoring == " custom " )
1621
1673
{
1622
- createBfdSession (vnet, nh, monitor_ip);
1674
+ if (monitor_info_[vnet].find (ipPrefix) == monitor_info_[vnet].end () ||
1675
+ monitor_info_[vnet][ipPrefix].find (nh) == monitor_info_[vnet][ipPrefix].end ())
1676
+ {
1677
+ createMonitoringSession (vnet, nh, monitor_ip, ipPrefix);
1678
+ }
1679
+ }
1680
+ else
1681
+ {
1682
+ if (nexthop_info_[vnet].find (nh.ip_address ) == nexthop_info_[vnet].end ())
1683
+ {
1684
+ createBfdSession (vnet, nh, monitor_ip);
1685
+ }
1686
+ nexthop_info_[vnet][nh.ip_address ].ref_count ++;
1623
1687
}
1624
-
1625
- nexthop_info_[vnet][nh.ip_address ].ref_count ++;
1626
1688
}
1627
1689
}
1628
1690
1629
- void VNetRouteOrch::delEndpointMonitor (const string& vnet, NextHopGroupKey& nexthops)
1691
+ void VNetRouteOrch::delEndpointMonitor (const string& vnet, NextHopGroupKey& nexthops, IpPrefix& ipPrefix )
1630
1692
{
1631
1693
SWSS_LOG_ENTER ();
1632
1694
1633
1695
std::set<NextHopKey> nhks = nexthops.getNextHops ();
1696
+ bool is_custom_monitoring = false ;
1697
+ if (monitor_info_[vnet].find (ipPrefix) != monitor_info_[vnet].end ())
1698
+ {
1699
+ is_custom_monitoring = true ;
1700
+ }
1634
1701
for (auto nhk: nhks)
1635
1702
{
1636
1703
IpAddress ip = nhk.ip_address ;
1637
- if (nexthop_info_[vnet].find (ip) != nexthop_info_[vnet].end ()) {
1638
- if (--nexthop_info_[vnet][ip].ref_count == 0 )
1704
+ if (is_custom_monitoring)
1705
+ {
1706
+ if ( monitor_info_[vnet][ipPrefix].find (nhk) != monitor_info_[vnet][ipPrefix].end ())
1639
1707
{
1640
- IpAddress monitor_addr = nexthop_info_[vnet][ip].monitor_addr ;
1641
- removeBfdSession (vnet, nhk, monitor_addr);
1708
+ removeMonitoringSession (vnet, nhk, monitor_info_[vnet][ipPrefix][nhk].monitor , ipPrefix);
1709
+ }
1710
+ }
1711
+ else
1712
+ {
1713
+ if (nexthop_info_[vnet].find (ip) != nexthop_info_[vnet].end ()) {
1714
+ if (--nexthop_info_[vnet][ip].ref_count == 0 )
1715
+ {
1716
+ IpAddress monitor_addr = nexthop_info_[vnet][ip].monitor_addr ;
1717
+ {
1718
+ removeBfdSession (vnet, nhk, monitor_addr);
1719
+ }
1720
+ }
1642
1721
}
1643
1722
}
1644
1723
}
1724
+ if (is_custom_monitoring)
1725
+ {
1726
+ monitor_info_[vnet].erase (ipPrefix);
1727
+ }
1645
1728
}
1646
1729
1647
1730
void VNetRouteOrch::postRouteState (const string& vnet, IpPrefix& ipPrefix, NextHopGroupKey& nexthops, string& profile)
@@ -2024,7 +2107,7 @@ bool VNetRouteOrch::handleTunnel(const Request& request)
2024
2107
2025
2108
if (vnet_orch_->isVnetExecVrf ())
2026
2109
{
2027
- return doRouteTask<VNetVrfObject>(vnet_name, ip_pfx, nhg, op, profile, monitors);
2110
+ return doRouteTask<VNetVrfObject>(vnet_name, ip_pfx, nhg, op, profile, monitoring, monitors);
2028
2111
}
2029
2112
2030
2113
return true ;
0 commit comments