LCOV - code coverage report
Current view: top level - vnsw/agent/oper - agent_sandesh.cc (source / functions) Hit Total Coverage
Test: OpenSDN C/C++ coverage (all TARGET_SET jobs) Lines: 12 872 1.4 %
Date: 2026-11-09 02:10:49 Functions: 4 145 2.8 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
       3             :  * Copyright Contributors to the OpenSDN project
       4             :  */
       5             : 
       6             : #include <cmn/agent_cmn.h>
       7             : 
       8             : #include <vnc_cfg_types.h>
       9             : #include <agent_types.h>
      10             : 
      11             : #include <oper/peer.h>
      12             : #include <oper/vrf.h>
      13             : #include <oper/interface_common.h>
      14             : #include <oper/health_check.h>
      15             : #include <oper/nexthop.h>
      16             : #include <oper/vn.h>
      17             : #include <oper/vm.h>
      18             : #include <oper/mirror_table.h>
      19             : #include <oper/vxlan.h>
      20             : #include <oper/service_instance.h>
      21             : #include <filter/acl.h>
      22             : #include <oper/mpls.h>
      23             : #include <oper/route_common.h>
      24             : #include <oper/sg.h>
      25             : #include <oper/agent_sandesh.h>
      26             : #include <oper/vrf_assign.h>
      27             : #include <oper/forwarding_class.h>
      28             : #include <oper/qos_config.h>
      29             : #include <oper/qos_queue.h>
      30             : #include <oper/bridge_domain.h>
      31             : #include <oper/tag.h>
      32             : #include <oper/security_logging_object.h>
      33             : #include <filter/acl.h>
      34             : #include <filter/policy_set.h>
      35             : #include <oper/crypt_tunnel.h>
      36             : #include <oper/multicast_policy.h>
      37             : 
      38             : /////////////////////////////////////////////////////////////////////////////
      39             : // Utility routines
      40             : /////////////////////////////////////////////////////////////////////////////
      41           0 : static bool MatchSubString(const string &str, const string &sub_str) {
      42           0 :     if (sub_str.empty())
      43           0 :         return true;
      44             : 
      45           0 :     return (str.find(sub_str) != string::npos);
      46             : }
      47             : 
      48           0 : AgentVnSandesh::AgentVnSandesh(const std::string &context,
      49             :                                    const std::string &name,
      50             :                                    const std::string &u,
      51             :                                    const std::string &vxlan_id,
      52           0 :                                    const std::string &ipam_name) :
      53           0 :         AgentSandesh(context, ""), name_(name), uuid_str_(u),
      54           0 :         vxlan_id_(vxlan_id), ipam_name_(ipam_name) {
      55             : 
      56           0 :     boost::system::error_code ec;
      57           0 :     uuid_ = StringToUuid(u);
      58           0 : }
      59             : 
      60           0 : static bool MatchUuid(const string &uuid_str, const boost::uuids::uuid &u,
      61             :                       const boost::uuids::uuid val) {
      62           0 :     if (uuid_str.empty())
      63           0 :         return true;
      64           0 :     return u == val;
      65             : }
      66             : 
      67             : /////////////////////////////////////////////////////////////////////////////
      68             : // Sandesh routines per DBTable
      69             : /////////////////////////////////////////////////////////////////////////////
      70           0 : DBTable *AgentVnSandesh::AgentGetTable() {
      71           0 :     return static_cast<DBTable *>(Agent::GetInstance()->vn_table());
      72             : }
      73             : 
      74           0 : void AgentVnSandesh::Alloc() {
      75           0 :     resp_ = new VnListResp();
      76           0 : }
      77             : 
      78           0 : bool AgentVnSandesh::Filter(const DBEntryBase *entry) {
      79           0 :     const VnEntry *vn = dynamic_cast<const VnEntry *>(entry);
      80           0 :     assert(vn);
      81             : 
      82           0 :     if (MatchSubString(vn->GetName(), name_) == false)
      83           0 :         return false;
      84             : 
      85           0 :     if (MatchUuid(uuid_str_ , uuid_,  vn->GetUuid()) == false)
      86           0 :         return false;
      87             : 
      88           0 :     if (vxlan_id_.empty() == false) {
      89           0 :         if (((vn->GetVxLanId()) == boost::lexical_cast<int>(vxlan_id_)) == false) {
      90           0 :            return false;
      91             :        }
      92             :     }
      93             : 
      94           0 :     const std::vector<VnIpam> VnIpams = vn->GetVnIpam();
      95           0 :     std::vector<VnIpam>::const_iterator pos;
      96           0 :     bool ipam_flag = true;
      97           0 :     if (VnIpams.size() == 0) {
      98           0 :         ipam_flag = false;
      99             :     }
     100           0 :     for(pos=VnIpams.begin();pos < VnIpams.end();pos++) {
     101           0 :             if ((MatchSubString(pos->ipam_name , ipam_name_) == true)) {
     102           0 :                 ipam_flag = false;
     103             :             }
     104             :     }
     105           0 :     if (ipam_flag == true) {
     106           0 :        return false;
     107             :     }
     108             : 
     109           0 :     return true;
     110           0 : }
     111             : 
     112           0 : bool AgentVnSandesh::FilterToArgs(AgentSandeshArguments *args) {
     113           0 :     args->Add("name", name_);
     114           0 :     args->Add("uuid", uuid_str_);
     115           0 :     args->Add("vxlan_id", vxlan_id_);
     116           0 :     args->Add("ipam_name", ipam_name_);
     117             : 
     118           0 :     return true;
     119             : }
     120             : 
     121           0 : DBTable *AgentSgSandesh::AgentGetTable() {
     122           0 :     return static_cast<DBTable *>(Agent::GetInstance()->sg_table());
     123             : }
     124             : 
     125           0 : void AgentSgSandesh::Alloc() {
     126           0 :     resp_ = new SgListResp();
     127           0 : }
     128             : 
     129           0 : DBTable *AgentVmSandesh::AgentGetTable() {
     130           0 :     return static_cast<DBTable *>(Agent::GetInstance()->vm_table());
     131             : }
     132             : 
     133           0 : void AgentVmSandesh::Alloc() {
     134           0 :     resp_ = new VmListResp();
     135           0 : }
     136             : 
     137           0 : AgentIntfSandesh::AgentIntfSandesh(const std::string &context,
     138             :                                    const std::string &type,
     139             :                                    const std::string &name,
     140             :                                    const std::string &u,
     141             :                                    const std::string &vn,
     142             :                                    const std::string &mac,
     143             :                                    const std::string &v4,
     144             :                                    const std::string &v6,
     145             :                                    const std::string &parent,
     146             :                                    const std::string &ip_active,
     147             :                                    const std::string &ip6_active,
     148           0 :                                    const std::string &l2_active) :
     149           0 :         AgentSandesh(context, ""), type_(type), name_(name), uuid_str_(u),
     150           0 :         vn_(vn), mac_str_(mac), v4_str_(v4), v6_str_(v6),
     151           0 :         parent_uuid_str_(parent), ip_active_str_(ip_active),
     152           0 :         ip6_active_str_(ip6_active), l2_active_str_(l2_active) {
     153             : 
     154           0 :     boost::system::error_code ec;
     155           0 :     uuid_ = StringToUuid(u);
     156           0 :     v4_ = Ip4Address::from_string(v4, ec);
     157           0 :     v6_ = Ip6Address::from_string(v6, ec);
     158           0 :     parent_uuid_ = StringToUuid(parent);
     159           0 : }
     160             : 
     161           0 : DBTable *AgentIntfSandesh::AgentGetTable() {
     162           0 :     return static_cast<DBTable *>(Agent::GetInstance()->interface_table());
     163             : }
     164             : 
     165           0 : void AgentIntfSandesh::Alloc() {
     166           0 :     resp_ = new ItfResp();
     167           0 : }
     168             : 
     169           0 : bool AgentIntfSandesh::Filter(const DBEntryBase *entry) {
     170           0 :     const Interface *intf = dynamic_cast<const Interface *>(entry);
     171           0 :     assert(intf);
     172             : 
     173           0 :     if (MatchSubString(intf->name(), name_) == false)
     174           0 :         return false;
     175             : 
     176           0 :     if (type_.empty() == false) {
     177           0 :         if (type_ == "physical" &&
     178           0 :             (intf->type() != Interface::PHYSICAL &&
     179           0 :              intf->type() != Interface::REMOTE_PHYSICAL))
     180           0 :             return false;
     181           0 :         if (type_ == "logical" && intf->type() != Interface::LOGICAL)
     182           0 :             return false;
     183           0 :         if (type_ == "vmi" && intf->type() != Interface::VM_INTERFACE)
     184           0 :             return false;
     185           0 :         if (type_ == "inet" && intf->type() != Interface::INET)
     186           0 :             return false;
     187           0 :         if (type_ == "pkt" && intf->type() != Interface::PACKET)
     188           0 :             return false;
     189             :     }
     190             : 
     191           0 :     if (MatchUuid(uuid_str_, uuid_, intf->GetUuid()) == false)
     192           0 :         return false;
     193             : 
     194             :     // vn_, mac_str_, v4_str_ or v6_str_ set means get VM-Interfaces only
     195           0 :     if (vn_.empty() == false || mac_str_.empty() == false ||
     196           0 :         v4_str_.empty() == false || v6_str_.empty() == false) {
     197           0 :         if (intf->type() != Interface::VM_INTERFACE)
     198           0 :             return false;
     199             :     }
     200             : 
     201           0 :     if (ip_active_str_.empty() == false) {
     202           0 :         if (ip_active_str_ == "no" || ip_active_str_ == "inactive") {
     203           0 :             if (intf->ipv4_active())
     204           0 :                 return false;
     205             :         }
     206             :     }
     207             : 
     208           0 :     if (ip6_active_str_.empty() == false) {
     209           0 :         if (ip6_active_str_ == "no" || ip6_active_str_ == "inactive") {
     210           0 :             if (intf->ipv6_active())
     211           0 :                 return false;
     212             :         }
     213             :     }
     214             : 
     215           0 :     if (l2_active_str_.empty() == false) {
     216           0 :         if (l2_active_str_ == "no" || l2_active_str_ == "inactive") {
     217           0 :             if (intf->l2_active())
     218           0 :                 return false;
     219             :         }
     220             :     }
     221             : 
     222           0 :     const LogicalInterface *li = dynamic_cast<const LogicalInterface *>(entry);
     223           0 :     if (li) {
     224           0 :         if (parent_uuid_str_.empty() == false && parent_uuid_.is_nil() == false
     225           0 :             && li->physical_interface()) {
     226           0 :             if (li->physical_interface()->GetUuid() != parent_uuid_)
     227           0 :                 return false;
     228             :         }
     229             : 
     230           0 :         return true;
     231             :     }
     232             : 
     233           0 :     const VmInterface *vmi = dynamic_cast<const VmInterface *>(entry);
     234           0 :     if (vmi == NULL)
     235           0 :         return true;
     236             : 
     237           0 :     if (vn_.empty() == false && vmi->vn()) {
     238           0 :         if (MatchSubString(vmi->vn()->GetName(), vn_) == false)
     239           0 :             return false;
     240             :     }
     241             : 
     242           0 :     if (MatchSubString(vmi->vm_mac().ToString(), mac_str_) == false)
     243           0 :         return false;
     244             : 
     245           0 :     if (v4_str_.empty() == false) {
     246           0 :         if (v4_ != vmi->primary_ip_addr()) {
     247           0 :             return false;
     248             :         }
     249             :     }
     250             : 
     251           0 :     if (v6_str_.empty() == false) {
     252           0 :         if (v6_ != vmi->primary_ip6_addr()) {
     253           0 :             return false;
     254             :         }
     255             :     }
     256             : 
     257           0 :     return true;
     258             : }
     259             : 
     260           0 : bool AgentIntfSandesh::FilterToArgs(AgentSandeshArguments *args) {
     261           0 :     args->Add("type", type_);
     262           0 :     args->Add("name", name_);
     263           0 :     args->Add("uuid", uuid_str_);
     264           0 :     args->Add("vn", vn_);
     265           0 :     args->Add("mac", mac_str_);
     266           0 :     args->Add("ipv4", v4_str_);
     267           0 :     args->Add("ipv6", v6_str_);
     268           0 :     args->Add("parent", parent_uuid_str_);
     269           0 :     args->Add("ip-active", ip_active_str_);
     270           0 :     args->Add("ip6-active", ip6_active_str_);
     271           0 :     args->Add("l2-active", l2_active_str_);
     272           0 :     return true;
     273             : }
     274             : 
     275           0 : DBTable *AgentNhSandesh::AgentGetTable() {
     276           0 :     return static_cast<DBTable *>(Agent::GetInstance()->nexthop_table());
     277             : }
     278             : 
     279           0 : void AgentNhSandesh::Alloc() {
     280           0 :     resp_ = new NhListResp();
     281           0 : }
     282             : 
     283           0 : AgentNhSandesh::AgentNhSandesh(const std::string &context,
     284             :                                const std::string &type,
     285             :                                const std::string &nh_index,
     286           0 :                                const std::string &policy_enabled) :
     287           0 :         AgentSandesh(context, ""), type_(type), nh_index_(nh_index),
     288           0 :                                    policy_enabled_(policy_enabled) {
     289             : 
     290           0 : }
     291             : 
     292           0 : bool AgentNhSandesh::Filter(const DBEntryBase *entry) {
     293           0 :     const NextHop *nh = dynamic_cast<const NextHop *>(entry);
     294           0 :     assert(nh);
     295             : 
     296           0 :     if (type_.empty() == false) {
     297           0 :         NextHop::Type nh_type = nh->GetType();
     298           0 :         if (type_ == "invalid" &&
     299             :              (nh_type != NextHop::INVALID))
     300           0 :            return false;
     301           0 :         if (type_ == "discard" &&
     302             :              (nh_type != NextHop::DISCARD))
     303           0 :            return false;
     304           0 :         if (type_ == "l2-receive" &&
     305             :              (nh_type != NextHop::L2_RECEIVE))
     306           0 :            return false;
     307           0 :         if (type_ == "receive" &&
     308             :              (nh_type != NextHop::RECEIVE))
     309           0 :            return false;
     310           0 :         if (type_ == "resolve" &&
     311             :              (nh_type != NextHop::RESOLVE))
     312           0 :            return false;
     313           0 :         if (type_ == "arp" &&
     314             :              (nh_type != NextHop::ARP))
     315           0 :            return false;
     316           0 :         if (type_ == "vrf" &&
     317             :              (nh_type != NextHop::VRF))
     318           0 :            return false;
     319           0 :         if (type_ == "interface" &&
     320             :              (nh_type != NextHop::INTERFACE))
     321           0 :            return false;
     322           0 :         if (type_ == "tunnel" &&
     323             :              (nh_type != NextHop::TUNNEL))
     324           0 :            return false;
     325           0 :         if (type_ == "mirror" &&
     326             :              (nh_type != NextHop::MIRROR))
     327           0 :            return false;
     328           0 :         if (type_ == "composite" &&
     329             :              (nh_type != NextHop::COMPOSITE))
     330           0 :            return false;
     331           0 :         if (type_ == "vlan" &&
     332             :              (nh_type != NextHop::VLAN))
     333           0 :            return false;
     334             : 
     335             :     }
     336             : 
     337           0 :     if (policy_enabled_.empty() == false) {
     338           0 :         bool policy_flag = true;
     339           0 :         if (MatchSubString("enabled", policy_enabled_) == false) {
     340           0 :             policy_flag = false;
     341             :         }
     342           0 :         if (policy_flag != nh->PolicyEnabled()) {
     343           0 :            return false;
     344             :         }
     345             :     }
     346           0 :     if (nh_index_.empty() == false) {
     347           0 :         if (((nh->id()) == boost::lexical_cast<uint32_t>(nh_index_)) == false)
     348           0 :            return false;
     349             :     }
     350           0 :     return true;
     351             : 
     352             :     }
     353             : 
     354           0 : bool AgentNhSandesh::FilterToArgs(AgentSandeshArguments *args) {
     355           0 :     args->Add("type", type_);
     356           0 :     args->Add("nh_index", nh_index_);
     357           0 :     args->Add("policy_enabled", policy_enabled_);
     358           0 :     return true;
     359             : }
     360             : 
     361           0 : DBTable *AgentMplsSandesh::AgentGetTable() {
     362           0 :     return static_cast<DBTable *>(Agent::GetInstance()->mpls_table());
     363             : }
     364             : 
     365           0 : void AgentMplsSandesh::Alloc() {
     366           0 :     resp_ = new MplsResp();
     367           0 : }
     368             : 
     369           0 : AgentMplsSandesh::AgentMplsSandesh(const std::string &context,
     370             :                                const std::string &type,
     371           0 :                                const std::string &label) :
     372           0 :         AgentSandesh(context, ""), type_(type), label_(label) {
     373             : 
     374           0 : }
     375             : 
     376           0 : bool AgentMplsSandesh::Filter(const DBEntryBase *entry) {
     377           0 :     const MplsLabel *mplsl = dynamic_cast<const MplsLabel *>(entry);
     378           0 :     assert(mplsl);
     379             : 
     380           0 :     if (label_.empty() == false) {
     381           0 :         if (((mplsl->label()) == boost::lexical_cast<uint32_t>(label_)) == false)
     382           0 :            return false;
     383           0 :         NextHop::Type nh_type = mplsl->nexthop()->GetType();
     384           0 :         if (type_ == "invalid" &&
     385             :              (nh_type != NextHop::INVALID))
     386           0 :            return false;
     387           0 :         if (type_ == "interface" &&
     388             :              (nh_type != NextHop::INTERFACE))
     389           0 :            return false;
     390           0 :         if (type_ == "vlan" &&
     391             :              (nh_type != NextHop::VLAN))
     392           0 :            return false;
     393           0 :         if (type_ == "vrf" &&
     394             :              (nh_type != NextHop::VRF))
     395           0 :            return false;
     396           0 :         if (type_ == "composite" &&
     397             :              (nh_type != NextHop::COMPOSITE))
     398           0 :            return false;
     399             :     }
     400           0 :     return true;
     401             : }
     402             : 
     403           0 : bool AgentMplsSandesh::FilterToArgs(AgentSandeshArguments *args) {
     404           0 :     args->Add("type", type_);
     405           0 :     args->Add("label", label_);
     406           0 :     return true;
     407             : }
     408             : 
     409           0 : DBTable *AgentVrfSandesh::AgentGetTable() {
     410           0 :     return static_cast<DBTable *>(Agent::GetInstance()->vrf_table());
     411             : }
     412             : 
     413           0 : void AgentVrfSandesh::Alloc() {
     414           0 :     resp_ = new VrfListResp();
     415           0 : }
     416             : 
     417           0 : DBTable *AgentInet4UcRtSandesh::AgentGetTable() {
     418           0 :     return static_cast<DBTable *>(vrf_->GetInet4UnicastRouteTable());
     419             : }
     420             : 
     421           0 : void AgentInet4UcRtSandesh::Alloc() {
     422           0 :     resp_ = new Inet4UcRouteResp();
     423           0 : }
     424             : 
     425           0 : bool AgentInet4UcRtSandesh::UpdateResp(DBEntryBase *entry) {
     426           0 :     InetUnicastRouteEntry *rt = static_cast<InetUnicastRouteEntry *>(entry);
     427           0 :     if (dump_table_) {
     428           0 :         return rt->DBEntrySandesh(resp_, stale_);
     429             :     }
     430           0 :     return rt->DBEntrySandesh(resp_, addr_, plen_, stale_);
     431             : }
     432             : 
     433           0 : DBTable *AgentInet4MplsUcRtSandesh::AgentGetTable() {
     434           0 :     return static_cast<DBTable *>(vrf_->GetInet4MplsUnicastRouteTable());
     435             : }
     436             : 
     437           0 : void AgentInet4MplsUcRtSandesh::Alloc() {
     438           0 :     resp_ = new Inet4MplsUcRouteResp();
     439           0 : }
     440             : 
     441           0 : bool AgentInet4MplsUcRtSandesh::UpdateResp(DBEntryBase *entry) {
     442           0 :     InetUnicastRouteEntry *rt = static_cast<InetUnicastRouteEntry *>(entry);
     443           0 :     if (dump_table_) {
     444           0 :         return rt->DBEntrySandesh(resp_, stale_);
     445             :     }
     446           0 :     return rt->DBEntrySandesh(resp_, addr_, plen_, stale_);
     447             : }
     448             : 
     449           0 : DBTable *AgentInet6UcRtSandesh::AgentGetTable() {
     450           0 :     return static_cast<DBTable *>(vrf_->GetInet6UnicastRouteTable());
     451             : }
     452             : 
     453           0 : void AgentInet6UcRtSandesh::Alloc() {
     454           0 :     resp_ = new Inet6UcRouteResp();
     455           0 : }
     456             : 
     457           0 : bool AgentInet6UcRtSandesh::UpdateResp(DBEntryBase *entry) {
     458           0 :     InetUnicastRouteEntry *rt = static_cast<InetUnicastRouteEntry *>(entry);
     459           0 :     if (dump_table_) {
     460           0 :         return rt->DBEntrySandesh(resp_, stale_);
     461             :     }
     462           0 :     return rt->DBEntrySandesh(resp_, addr_, plen_, stale_);
     463             : }
     464             : 
     465           0 : DBTable *AgentInet4McRtSandesh::AgentGetTable() {
     466           0 :     return static_cast<DBTable *>(vrf_->GetInet4MulticastRouteTable());
     467             : }
     468             : 
     469           0 : void AgentInet4McRtSandesh::Alloc() {
     470           0 :     resp_ = new Inet4McRouteResp();
     471           0 : }
     472             : 
     473           0 : bool AgentInet4McRtSandesh::UpdateResp(DBEntryBase *entry) {
     474           0 :     Inet4MulticastRouteEntry *rt = static_cast<Inet4MulticastRouteEntry *>(entry);
     475           0 :     if (dump_table_) {
     476           0 :         return rt->DBEntrySandesh(resp_, stale_);
     477             :     }
     478           0 :     return rt->DBEntrySandesh(resp_, src_addr_, grp_addr_, stale_);
     479             : }
     480             : 
     481           0 : DBTable *AgentEvpnRtSandesh::AgentGetTable() {
     482           0 :     return static_cast<DBTable *>(vrf_->GetEvpnRouteTable());
     483             : }
     484             : 
     485           0 : void AgentEvpnRtSandesh::Alloc() {
     486           0 :     resp_ = new EvpnRouteResp();
     487           0 : }
     488             : 
     489           0 : bool AgentEvpnRtSandesh::UpdateResp(DBEntryBase *entry) {
     490           0 :     AgentRoute *rt = static_cast<AgentRoute *>(entry);
     491           0 :     return rt->DBEntrySandesh(resp_, stale_);
     492             : }
     493             : 
     494           0 : DBTable *AgentLayer2RtSandesh::AgentGetTable() {
     495           0 :     return static_cast<DBTable *>(vrf_->GetBridgeRouteTable());
     496             : }
     497             : 
     498           0 : void AgentLayer2RtSandesh::Alloc() {
     499           0 :     resp_ = new Layer2RouteResp();
     500           0 : }
     501             : 
     502           0 : bool AgentLayer2RtSandesh::UpdateResp(DBEntryBase *entry) {
     503           0 :     AgentRoute *rt = static_cast<AgentRoute *>(entry);
     504           0 :     return rt->DBEntrySandesh(resp_, stale_);
     505             : }
     506             : 
     507           0 : DBTable *AgentBridgeRtSandesh::AgentGetTable() {
     508           0 :     return static_cast<DBTable *>(vrf_->GetBridgeRouteTable());
     509             : }
     510             : 
     511           0 : void AgentBridgeRtSandesh::Alloc() {
     512           0 :     resp_ = new BridgeRouteResp();
     513           0 : }
     514             : 
     515           0 : bool AgentBridgeRtSandesh::UpdateResp(DBEntryBase *entry) {
     516           0 :     BridgeRouteEntry *rt = static_cast<BridgeRouteEntry *>(entry);
     517           0 :     assert(rt);
     518           0 :     if (MatchSubString(rt->prefix_address().ToString(), mac_) == false)
     519           0 :         return false;
     520             : 
     521           0 :     return rt->DBEntrySandesh(resp_, stale_);
     522             : }
     523             : 
     524           0 : DBTable *AgentAclSandesh::AgentGetTable() {
     525           0 :     return static_cast<DBTable *>(Agent::GetInstance()->acl_table());
     526             : }
     527             : 
     528           0 : void AgentAclSandesh::Alloc() {
     529           0 :     resp_ = new AclResp();
     530           0 : }
     531             : 
     532           0 : bool AgentAclSandesh::UpdateResp(DBEntryBase *entry) {
     533           0 :     AclDBEntry *ent = static_cast<AclDBEntry *>(entry);
     534           0 :     return ent->DBEntrySandesh(resp_, name_);
     535             : }
     536             : 
     537           0 : DBTable *AgentMirrorSandesh::AgentGetTable(){
     538           0 :     return static_cast<DBTable *>(Agent::GetInstance()->mirror_table());
     539             : }
     540             : 
     541           0 : void AgentMirrorSandesh::Alloc(){
     542           0 :     resp_ = new MirrorEntryResp();
     543           0 : }
     544             : 
     545           0 : AgentMirrorSandesh::AgentMirrorSandesh(const std::string &context,
     546           0 :                                const std::string &analyzer_name) :
     547           0 :         AgentSandesh(context, ""), analyzer_name_(analyzer_name) {
     548             : 
     549           0 : }
     550             : 
     551           0 : bool AgentMirrorSandesh::Filter(const DBEntryBase *entry) {
     552           0 :     const MirrorEntry *mrentry = dynamic_cast<const MirrorEntry *>(entry);
     553           0 :     assert(mrentry);
     554             : 
     555           0 :     if (MatchSubString(mrentry->GetAnalyzerName(), analyzer_name_) == false) {
     556           0 :         return false;
     557             :     }
     558             : 
     559           0 :     return true;
     560             : }
     561             : 
     562           0 : bool AgentMirrorSandesh::FilterToArgs(AgentSandeshArguments *args) {
     563           0 :     args->Add("analyzer_name", analyzer_name_);
     564             : 
     565           0 :     return true;
     566             : }
     567             : 
     568           0 : DBTable *AgentVrfAssignSandesh::AgentGetTable(){
     569           0 :     return static_cast<DBTable *>(Agent::GetInstance()->vrf_assign_table());
     570             : }
     571             : 
     572           0 : void AgentVrfAssignSandesh::Alloc(){
     573           0 :     resp_ = new VrfAssignResp();
     574           0 : }
     575             : 
     576           0 : DBTable *AgentVxLanSandesh::AgentGetTable() {
     577           0 :     return static_cast<DBTable *>(Agent::GetInstance()->vxlan_table());
     578             : }
     579             : 
     580           0 : void AgentVxLanSandesh::Alloc() {
     581           0 :     resp_ = new VxLanResp();
     582           0 : }
     583             : 
     584           0 : AgentVxLanSandesh::AgentVxLanSandesh(const std::string &context,
     585           0 :                              const std::string &vxlan_id):
     586           0 :        AgentSandesh(context, ""), vxlan_id_(vxlan_id) {
     587             : 
     588           0 : }
     589             : 
     590           0 : bool AgentVxLanSandesh::Filter(const DBEntryBase *entry) {
     591           0 :     const VxLanId *identry = dynamic_cast<const VxLanId *>(entry);
     592           0 :     assert(identry);
     593             : 
     594           0 :     if (vxlan_id_.empty() == false) {
     595           0 :         if (((identry->vxlan_id()) == boost::lexical_cast<uint32_t>(vxlan_id_)) == false) {
     596           0 :            return false;
     597             :        }
     598             :     }
     599             : 
     600           0 :     return true;
     601             : }
     602             : 
     603           0 : bool AgentVxLanSandesh::FilterToArgs(AgentSandeshArguments *args) {
     604           0 :     args->Add("vxlan_id", vxlan_id_);
     605             : 
     606           0 :     return true;
     607             : }
     608             : 
     609           0 : DBTable *AgentServiceInstanceSandesh::AgentGetTable() {
     610           0 :     return static_cast<DBTable *>(Agent::GetInstance()->service_instance_table());
     611             : }
     612             : 
     613           0 : void AgentServiceInstanceSandesh::Alloc() {
     614           0 :     resp_ = new ServiceInstanceResp();
     615           0 : }
     616             : 
     617             : /////////////////////////////////////////////////////////////////////////////
     618             : // Routines to manage arguments
     619             : /////////////////////////////////////////////////////////////////////////////
     620           0 : bool AgentSandeshArguments::Add(const std::string &key, const std::string &val){
     621           0 :     if (val.empty())
     622           0 :         return true;
     623           0 :     ArgumentMap::iterator it = arguments_.find(key);
     624           0 :     if (it != arguments_.end()) {
     625           0 :         it->second = val;
     626           0 :         return false;
     627             :     }
     628             : 
     629           0 :     arguments_.insert(make_pair(key, val));
     630           0 :     return true;
     631             : }
     632             : 
     633           0 : bool AgentSandeshArguments::Add(const std::string &key, int val) {
     634           0 :     std::stringstream ss;
     635           0 :     ss << val;
     636           0 :     ArgumentMap::iterator it = arguments_.find(key);
     637           0 :     if (it != arguments_.end()) {
     638           0 :         it->second = ss.str();
     639           0 :         return false;
     640             :     }
     641             : 
     642           0 :     arguments_.insert(make_pair(key, ss.str()));
     643           0 :     return true;
     644           0 : }
     645             : 
     646           0 : bool AgentSandeshArguments::Del(const std::string &key) {
     647           0 :     ArgumentMap::iterator it = arguments_.find(key);
     648           0 :     if (it != arguments_.end()) {
     649           0 :         arguments_.erase(it);
     650           0 :         return true;
     651             :     }
     652             : 
     653           0 :     return false;
     654             : }
     655             : 
     656           0 : bool AgentSandeshArguments::Get(const std::string &key, std::string *val) const{
     657           0 :     ArgumentMap::const_iterator it = arguments_.find(key);
     658           0 :     if (it == arguments_.end()) {
     659           0 :         *val = "INVALID";
     660           0 :         return false;
     661             :     }
     662           0 :     *val = it->second;
     663           0 :     return true;
     664             : }
     665             : 
     666           0 : string AgentSandeshArguments::GetString(const std::string &key) const {
     667           0 :     ArgumentMap::const_iterator it = arguments_.find(key);
     668           0 :     if (it == arguments_.end()) {
     669           0 :         return "";
     670             :     }
     671           0 :     return it->second;
     672             : }
     673             : 
     674           0 : bool AgentSandeshArguments::Get(const std::string &key, int *val) const {
     675           0 :     ArgumentMap::const_iterator it = arguments_.find(key);
     676           0 :     if (it == arguments_.end()) {
     677           0 :         *val = -1;
     678           0 :         return false;
     679             :     }
     680           0 :     *val = strtoul(it->second.c_str(), NULL, 0);
     681           0 :     return true;
     682             : }
     683             : 
     684           0 : int AgentSandeshArguments::GetInt(const std::string &key) const {
     685           0 :     ArgumentMap::const_iterator it = arguments_.find(key);
     686           0 :     if (it == arguments_.end()) {
     687           0 :         return -1;
     688             :     }
     689           0 :     return (strtoul(it->second.c_str(), NULL, 0));
     690             : }
     691             : 
     692           0 : int AgentSandeshArguments::Encode(std::string *str) {
     693           0 :     ArgumentMap::iterator it = arguments_.begin();
     694           0 :     while (it != arguments_.end()) {
     695           0 :         *str += it->first + ':' + it->second;
     696           0 :         it++;
     697           0 :         if (it != arguments_.end())
     698           0 :             *str += ",";
     699             :     }
     700           0 :     return arguments_.size();
     701             : }
     702             : 
     703           0 : static int Split(const string &s, char delim, vector<string> &tokens) {
     704           0 :     std::stringstream ss(s);
     705           0 :     string item;
     706           0 :     int count = 0;
     707           0 :     while(getline(ss, item, delim)) {
     708           0 :         tokens.push_back(item);
     709           0 :         count++;
     710             :     }
     711             : 
     712           0 :     return count;
     713           0 : }
     714             : 
     715           0 : int AgentSandeshArguments::Decode(const std::string &str) {
     716           0 :     vector<string> token_list;
     717           0 :     int count = Split(str, ',', token_list);
     718             : 
     719           0 :     for (vector<string>::iterator it = token_list.begin();
     720           0 :          it != token_list.end(); ++it) {
     721           0 :         vector<string> args;
     722           0 :         if (Split((*it), ':', args) < 2) {
     723           0 :             return 0;
     724             :         }
     725           0 :         string val = (*it).substr(args[0].length() + 1);
     726           0 :         Add(args[0], val);
     727           0 :     }
     728             : 
     729           0 :     return count;
     730           0 : }
     731             : 
     732             : ///////////////////////////////////////////////////////////////////////////
     733             : // AgentSandesh Utilities
     734             : ///////////////////////////////////////////////////////////////////////////
     735           0 : static int ComputeFirst(int first, int len) {
     736           0 :     if (first < 0 || first > len)
     737           0 :         return 0;
     738             : 
     739           0 :     return first;
     740             : }
     741             : 
     742           0 : static int ComputeLast(int first, int last, int len) {
     743           0 :     if (last < 0)
     744           0 :         return -1;
     745             : 
     746           0 :     if (last >= len)
     747           0 :         return first + AgentSandesh::kEntriesPerPage - 1;
     748             : 
     749           0 :     if (last < first)
     750           0 :         return first + AgentSandesh::kEntriesPerPage - 1;
     751             : 
     752           0 :     return last;
     753             : }
     754             : 
     755           0 : static int ComputePageSize(int first, int last) {
     756           0 :     if (first < 0 || last < 0)
     757           0 :         return AgentSandesh::kEntriesPerPage;
     758             : 
     759           0 :     if (last <= first)
     760           0 :         return AgentSandesh::kEntriesPerPage;
     761           0 :     return (last - first + 1);
     762             : }
     763             : 
     764           0 : void SandeshError(DBTable *table, const std::string &msg,
     765             :                   const std::string &context) {
     766           0 :     ErrorResp *resp = new ErrorResp();
     767             : 
     768           0 :     if (table) {
     769           0 :         std::stringstream s;
     770           0 :         s << table->name() << ":" << msg;
     771           0 :         resp->set_resp(s.str());
     772           0 :     } else {
     773           0 :         resp->set_resp(msg);
     774             :     }
     775           0 :     resp->set_context(context);
     776           0 :     resp->Response();
     777           0 :     return;
     778             : }
     779             : 
     780           0 : static void EncodeOne(string *s, DBTable *table, int begin, int end,
     781             :                       AgentSandeshArguments *filter) {
     782           0 :     *s = "";
     783           0 :     AgentSandeshArguments args;
     784           0 :     args.Add("table", table->name());
     785           0 :     args.Add("begin", begin);
     786           0 :     args.Add("end", end);
     787           0 :     args.Encode(s);
     788             : 
     789           0 :     if (filter) {
     790           0 :         *s += ",";
     791           0 :         filter->Del("table");
     792           0 :         filter->Del("begin");
     793           0 :         filter->Del("end");
     794           0 :         filter->Encode(s);
     795             :     }
     796           0 : }
     797             : 
     798           0 : void PageReq::HandleRequest() const {
     799           0 :     Agent *agent = Agent::GetInstance();
     800           0 :     agent->oper_db()->agent_sandesh_manager()->AddPageRequest(key, context());
     801           0 :     return;
     802             : }
     803             : 
     804             : ///////////////////////////////////////////////////////////////////////////
     805             : // AgentSandeshManager routines
     806             : ///////////////////////////////////////////////////////////////////////////
     807           2 : AgentSandeshManager::AgentSandeshManager(Agent *agent) :
     808           2 :     agent_(agent),
     809           2 :     page_request_queue_(TaskScheduler::GetInstance()->GetTaskId(AGENT_SANDESH_TASKNAME),
     810             :                         0, boost::bind(&AgentSandeshManager::Run, this, _1)) {
     811           2 :     page_request_queue_.set_name("Introspect page request");
     812           2 : }
     813             : 
     814           2 : AgentSandeshManager::~AgentSandeshManager() {
     815           2 : }
     816             : 
     817           2 : void AgentSandeshManager::Init() {
     818           2 : }
     819             : 
     820           2 : void AgentSandeshManager::Shutdown() {
     821           2 :     page_request_queue_.Shutdown();
     822           2 : }
     823             : 
     824           0 : void AgentSandeshManager::AddPageRequest(const string &key,
     825             :                                          const string &context) {
     826           0 :     page_request_queue_.Enqueue(PageRequest(key, context));
     827           0 : }
     828             : 
     829           0 : bool AgentSandeshManager::Run(PageRequest req) {
     830           0 :     AgentSandeshArguments args;
     831           0 :     args.Decode(req.key_);
     832             : 
     833           0 :     string table_name;
     834           0 :     int first = 0;
     835           0 :     int last = 0;
     836           0 :     if (args.Get("table", &table_name) == false ||
     837           0 :         args.Get("begin", &first) == false ||
     838           0 :         args.Get("end", &last) == false) {
     839           0 :         SandeshError(NULL, "Invalid request", req.context_);
     840           0 :         return true;
     841             :     }
     842             : 
     843             :     DBTable *table = static_cast<DBTable *>
     844           0 :         (Agent::GetInstance()->db()->FindTable(table_name));
     845           0 :     if (table == NULL) {
     846           0 :         SandeshError(NULL, "Invalid DBTable", req.context_);
     847           0 :         return true;
     848             :     }
     849             : 
     850           0 :     AgentDBTable *agent_table = dynamic_cast<AgentDBTable *>(table);
     851           0 :     if (agent_table) {
     852           0 :         AgentSandeshPtr sandesh = agent_table->GetAgentSandesh(&args,
     853           0 :                                                             req.context_);
     854           0 :         if (sandesh) {
     855           0 :             sandesh->DoSandesh(sandesh, first, last);
     856             :         } else {
     857           0 :             SandeshError(table, "Pagination not supported", req.context_);
     858             :         }
     859           0 :         return true;
     860           0 :     }
     861             : 
     862           0 :     AgentRouteTable *route_table = dynamic_cast<AgentRouteTable *>(table);
     863           0 :     if (route_table) {
     864           0 :         AgentSandeshPtr sandesh = route_table->GetAgentSandesh(&args,
     865           0 :                                                              req.context_);
     866           0 :         if (sandesh) {
     867           0 :             sandesh->DoSandesh(sandesh, first, last);
     868             :         } else {
     869           0 :             SandeshError(table, "Pagination not supported", req.context_);
     870             :         }
     871           0 :         return true;
     872           0 :     }
     873             : 
     874           0 :     SandeshError(table, "Pagination not supported", req.context_);
     875           0 :     return true;
     876           0 : }
     877             : 
     878             : ///////////////////////////////////////////////////////////////////////////
     879             : // AgentSandesh routines
     880             : ///////////////////////////////////////////////////////////////////////////
     881           0 : void AgentSandesh::MakeSandeshPageReq(PageReqData *req, DBTable *table,
     882             :                                       int first, int count, int match_count,
     883             :                                       int table_size, int page_size) {
     884           0 :     AgentSandeshArguments filter;
     885             : 
     886           0 :     FilterToArgs(&filter);
     887             : 
     888             :     // Set table-size
     889           0 :     int len = table->Size();
     890           0 :     req->set_table_size(len);
     891             : 
     892             :     // Set entries
     893           0 :     int last = first + count - 1;
     894           0 :     std::stringstream entries_ss;
     895           0 :     if (match_count >= 0) {
     896           0 :         if (count == 0) {
     897           0 :             entries_ss << " 0 / " << match_count;
     898             :         } else {
     899           0 :             entries_ss << first << "-" << last << "/" << match_count;
     900             :         }
     901             :     } else {
     902           0 :         entries_ss << first << "-" << last;
     903             :     }
     904           0 :     req->set_entries(entries_ss.str());
     905             : 
     906             :     // Next-Page link
     907           0 :     int next_page_first = last + 1;
     908           0 :     int next_page_last = next_page_first + page_size - 1;
     909           0 :     if (match_count >= 0 && next_page_last > match_count) {
     910           0 :         next_page_last = match_count - 1;
     911             :     }
     912             : 
     913           0 :     if (next_page_last >= table_size) {
     914           0 :         next_page_last = table_size - 1;
     915             :     }
     916             : 
     917           0 :     if ((match_count >= 0 && next_page_first < match_count) ||
     918           0 :         (match_count < 0 && next_page_first < table_size)) {
     919           0 :         string s;
     920           0 :         EncodeOne(&s, table, next_page_first, next_page_last, &filter);
     921           0 :         req->set_next_page(s);
     922           0 :     }
     923             : 
     924             :     // Prev-Page link
     925           0 :     if (first > 0) {
     926             :         int prev_page_first;
     927           0 :         if (page_size <  AgentSandesh::kEntriesPerPage) {
     928           0 :             prev_page_first = first - AgentSandesh::kEntriesPerPage;
     929             :         } else {
     930           0 :             prev_page_first = first - page_size;
     931             :         }
     932             : 
     933           0 :         if (prev_page_first < 0)
     934           0 :             prev_page_first = 0;
     935             : 
     936             :         int prev_page_last;
     937             : 
     938           0 :         if (page_size <  AgentSandesh::kEntriesPerPage) {
     939           0 :             prev_page_last = prev_page_first + AgentSandesh::kEntriesPerPage;
     940             :         } else {
     941           0 :             prev_page_last = prev_page_first + page_size;
     942             :         }
     943             : 
     944           0 :         if (prev_page_last >= first)
     945           0 :             prev_page_last = first - 1;
     946           0 :         string s;
     947           0 :         EncodeOne(&s, table, prev_page_first, prev_page_last, &filter);
     948           0 :         req->set_prev_page(s);
     949           0 :     }
     950             : 
     951             :     // First-Page link
     952           0 :     string s;
     953           0 :     if ((len - AgentSandesh::kEntriesPerPage) >= 0) {
     954           0 :         EncodeOne(&s, table, 0, (AgentSandesh::kEntriesPerPage - 1), &filter);
     955             :     } else {
     956           0 :         EncodeOne(&s, table, 0, (page_size - 1), &filter);
     957             :     }
     958             : 
     959           0 :     req->set_first_page(s);
     960             : 
     961             :     // All-Page link
     962           0 :     s = "";
     963           0 :     EncodeOne(&s, table, -1, -1, &filter);
     964           0 :     req->set_all(s);
     965           0 : }
     966             : 
     967           0 : void AgentSandesh::DoSandeshInternal(AgentSandeshPtr sandesh, int first,
     968             :                                      int last) {
     969           0 :     DBTable *table = AgentGetTable();
     970             :     DBTablePartition *part = static_cast<DBTablePartition *>
     971           0 :         (table->GetTablePartition(0));
     972             : 
     973           0 :     if (table == NULL || part == NULL) {
     974           0 :         SandeshError(table, "Invalid DBTable name", context_);
     975           0 :         return;
     976             :     }
     977             : 
     978           0 :     int len = (int)table->Size();
     979           0 :     int page_size = ComputePageSize(first, last);
     980           0 :     first = ComputeFirst(first, len);
     981           0 :     last = ComputeLast(first, last, len);
     982             : 
     983           0 :     SetResp();
     984             :     DBTable::DBTableWalkRef walk_ref = table->AllocWalker(
     985             :         boost::bind(&AgentSandesh::EntrySandesh, this, _2, first, last),
     986           0 :         boost::bind(&AgentSandesh::SandeshDone, this, sandesh, first,
     987           0 :                     page_size, _1, _2));
     988           0 :     table->WalkAgain(walk_ref);
     989           0 : }
     990             : 
     991           0 : void AgentSandesh::DoSandesh(AgentSandeshPtr sandesh, int first, int last) {
     992           0 :     sandesh->DoSandeshInternal(sandesh, first, last);
     993           0 : }
     994             : 
     995           0 : void AgentSandesh::DoSandesh(AgentSandeshPtr sandesh) {
     996           0 :     DoSandesh(sandesh, 0, (kEntriesPerPage - 1));
     997           0 : }
     998             : 
     999           0 : void AgentSandesh::SetResp() {
    1000           0 :     Alloc();
    1001           0 :     resp_->set_context(context_);
    1002           0 : }
    1003             : 
    1004           0 : bool AgentSandesh::UpdateResp(DBEntryBase *entry) {
    1005           0 :     AgentDBEntry *ent = static_cast<AgentDBEntry *>(entry);
    1006           0 :     return ent->DBEntrySandesh(resp_, name_);
    1007             : }
    1008             : 
    1009           0 : bool AgentSandesh::EntrySandesh(DBEntryBase *entry, int first, int last) {
    1010           0 :     if (Filter(entry) == false)
    1011           0 :         return true;
    1012             : 
    1013           0 :     if (total_entries_ >= first && ((last < 0) || (total_entries_ <= last))) {
    1014           0 :         if (!UpdateResp(entry)) {
    1015           0 :             return true;
    1016             :         }
    1017           0 :         count_++;
    1018             : 
    1019           0 :         if ((count_ % entries_per_sandesh) == 0) {
    1020             :             // send partial sandesh
    1021           0 :             resp_->set_more(true);
    1022           0 :             resp_->Response();
    1023           0 :             SetResp();
    1024             :         }
    1025             :     }
    1026           0 :     total_entries_++;
    1027             : 
    1028           0 :     return true;
    1029             : }
    1030             : 
    1031           0 : void AgentSandesh::SandeshDone(AgentSandeshPtr ptr, int first, int page_size,
    1032             :                                DBTable::DBTableWalkRef walk_ref,
    1033             :                                DBTableBase *partition) {
    1034           0 :     (static_cast<DBTable *>(partition))->ReleaseWalker(walk_ref);
    1035           0 :     resp_->set_more(true);
    1036           0 :     resp_->Response();
    1037             : 
    1038           0 :     Pagination *page = new Pagination();
    1039           0 :     resp_ = page;
    1040           0 :     resp_->set_context(context_);
    1041             : 
    1042           0 :     DBTable *table = AgentGetTable();
    1043           0 :     PageReqData req;
    1044           0 :     MakeSandeshPageReq(&req, table, first, count_, total_entries_,
    1045           0 :                        table->Size(), page_size);
    1046           0 :     page->set_req(req);
    1047           0 :     resp_->Response();
    1048           0 : }
    1049             : 
    1050           0 : void AgentInitStateReq::HandleRequest() const {
    1051           0 :     AgentInitState *resp = new AgentInitState();
    1052           0 :     resp->set_context(context());
    1053           0 :     Agent *agent = Agent::GetInstance();
    1054           0 :     if (agent->init_done()) {
    1055           0 :         resp->set_state("InitDone");
    1056             :     } else {
    1057           0 :         resp->set_state("InProgress");
    1058             :     }
    1059           0 :     resp->Response();
    1060           0 : }
    1061             : 
    1062           0 : void VrouterObjectLimitsReq::HandleRequest() const {
    1063           0 :    VrouterObjectLimitsResp *resp = new VrouterObjectLimitsResp();
    1064           0 :    resp->set_context(context());
    1065             : 
    1066           0 :    Agent *agent = Agent::GetInstance();
    1067             : 
    1068           0 :    VrouterObjectLimits vr_limits = agent->GetVrouterObjectLimits();
    1069           0 :    resp->set_vrouter_object_limit(vr_limits);
    1070           0 :    resp->Response();
    1071           0 : }
    1072             : 
    1073           0 : AgentHealthCheckSandesh::AgentHealthCheckSandesh(const std::string &context,
    1074           0 :                                                  const std::string &u) :
    1075           0 :         AgentSandesh(context, ""), uuid_str_(u) {
    1076           0 :     boost::system::error_code ec;
    1077           0 :     uuid_ = StringToUuid(u);
    1078           0 : }
    1079             : 
    1080           0 : DBTable *AgentHealthCheckSandesh::AgentGetTable() {
    1081           0 :     return static_cast<DBTable *>(Agent::GetInstance()->health_check_table());
    1082             : }
    1083             : 
    1084           0 : void AgentHealthCheckSandesh::Alloc() {
    1085           0 :     resp_ = new HealthCheckSandeshResp();
    1086           0 : }
    1087             : 
    1088           0 : bool AgentHealthCheckSandesh::Filter(const DBEntryBase *entry) {
    1089             :     const HealthCheckService *service =
    1090           0 :         dynamic_cast<const HealthCheckService *>(entry);
    1091           0 :     assert(service);
    1092             : 
    1093           0 :     if (MatchUuid(uuid_str_ , uuid_,  service->uuid()) == false)
    1094           0 :         return false;
    1095             : 
    1096           0 :     return true;
    1097             : }
    1098             : 
    1099           0 : bool AgentHealthCheckSandesh::FilterToArgs(AgentSandeshArguments *args) {
    1100           0 :     args->Add("uuid", uuid_str_);
    1101           0 :     return true;
    1102             : }
    1103             : 
    1104           0 : AgentQosConfigSandesh::AgentQosConfigSandesh(const std::string &context,
    1105             :                                              const std::string &u,
    1106             :                                              const std::string &name,
    1107           0 :                                              const std::string &id) :
    1108           0 :     AgentSandesh(context, ""), uuid_(u), name_(name), id_(id) {
    1109           0 : }
    1110             : 
    1111           0 : DBTable *AgentQosConfigSandesh::AgentGetTable() {
    1112           0 :     return static_cast<DBTable *>(Agent::GetInstance()->qos_config_table());
    1113             : }
    1114             : 
    1115           0 : void AgentQosConfigSandesh::Alloc() {
    1116           0 :     resp_ = new AgentQosConfigSandeshResp();
    1117           0 : }
    1118             : 
    1119           0 : bool AgentQosConfigSandesh::Filter(const DBEntryBase *entry) {
    1120             :     const AgentQosConfig *qos =
    1121           0 :         dynamic_cast<const AgentQosConfig *>(entry);
    1122           0 :     assert(qos);
    1123             : 
    1124           0 :     if (uuid_.empty() && name_.empty() && id_.empty()) {
    1125           0 :         return true;
    1126             :     }
    1127             : 
    1128           0 :     if (id_.empty() == false) {
    1129             :         uint32_t id;
    1130           0 :         stringToInteger(id_, id);
    1131           0 :         if (qos->id() != id) {
    1132           0 :             return false;
    1133             :         }
    1134             :     }
    1135             : 
    1136           0 :     if (name_.empty() == false &&
    1137           0 :         qos->name() != name_) {
    1138           0 :         return false;
    1139             :     }
    1140             : 
    1141           0 :     if (uuid_.empty() == false && qos->uuid() != StringToUuid(uuid_)) {
    1142           0 :         return false;
    1143             :     }
    1144             : 
    1145           0 :     return true;
    1146             : }
    1147             : 
    1148           0 : bool AgentQosConfigSandesh::FilterToArgs(AgentSandeshArguments *args) {
    1149           0 :     args->Add("uuid", uuid_);
    1150           0 :     args->Add("id", id_);
    1151           0 :     args->Add("name", name_);
    1152           0 :     return true;
    1153             : }
    1154             : 
    1155           0 : ForwardingClassSandesh::ForwardingClassSandesh(const std::string &context,
    1156             :                                                const std::string &u,
    1157             :                                                const std::string &name,
    1158           0 :                                                const std::string &id) :
    1159           0 :     AgentSandesh(context, ""), uuid_(u), name_(name), id_(id) {
    1160           0 : }
    1161             : 
    1162           0 : DBTable *ForwardingClassSandesh::AgentGetTable() {
    1163           0 :     return static_cast<DBTable *>(Agent::GetInstance()->forwarding_class_table());
    1164             : }
    1165             : 
    1166           0 : void ForwardingClassSandesh::Alloc() {
    1167           0 :     resp_ = new ForwardingClassSandeshResp();
    1168           0 : }
    1169             : 
    1170           0 : bool ForwardingClassSandesh::Filter(const DBEntryBase *entry) {
    1171             :     const ForwardingClass *fc =
    1172           0 :         dynamic_cast<const ForwardingClass *>(entry);
    1173           0 :     assert(fc);
    1174             : 
    1175           0 :     if (uuid_.empty() && name_.empty() && id_.empty()) {
    1176           0 :         return true;
    1177             :     }
    1178             : 
    1179           0 :     if (id_.empty() == false) {
    1180             :         uint32_t id;
    1181           0 :         stringToInteger(id_, id);
    1182           0 :         if (fc->id() != id) {
    1183           0 :             return false;
    1184             :         }
    1185             :     }
    1186             : 
    1187           0 :     if (name_.empty() == false &&
    1188           0 :         fc->name() != name_) {
    1189           0 :         return false;
    1190             :     }
    1191             : 
    1192           0 :     if (uuid_.empty() == false && fc->uuid() != StringToUuid(uuid_)) {
    1193           0 :         return false;
    1194             :     }
    1195             : 
    1196           0 :     return true;
    1197             : }
    1198             : 
    1199           0 : bool ForwardingClassSandesh::FilterToArgs(AgentSandeshArguments *args) {
    1200           0 :     args->Add("uuid", uuid_);
    1201           0 :     args->Add("id", id_);
    1202           0 :     args->Add("name", name_);
    1203           0 :     return true;
    1204             : }
    1205             : 
    1206           0 : QosQueueSandesh::QosQueueSandesh(const std::string &context,
    1207             :                                  const std::string &u,
    1208             :                                  const std::string &name,
    1209           0 :                                  const std::string &id) :
    1210           0 :     AgentSandesh(context, ""), uuid_(u), name_(name), id_(id) {
    1211           0 : }
    1212             : 
    1213           0 : DBTable *QosQueueSandesh::AgentGetTable() {
    1214           0 :     return static_cast<DBTable *>(Agent::GetInstance()->qos_queue_table());
    1215             : }
    1216             : 
    1217           0 : void QosQueueSandesh::Alloc() {
    1218           0 :     resp_ = new QosQueueSandeshResp();
    1219           0 : }
    1220             : 
    1221           0 : bool QosQueueSandesh::Filter(const DBEntryBase *entry) {
    1222           0 :     const QosQueue *qos_queue = dynamic_cast<const QosQueue *>(entry);
    1223           0 :     assert(qos_queue);
    1224             : 
    1225           0 :     if (uuid_.empty() && name_.empty() && id_.empty()) {
    1226           0 :         return true;
    1227             :     }
    1228             : 
    1229           0 :     if (id_.empty() == false) {
    1230             :         uint32_t id;
    1231           0 :         stringToInteger(id_, id);
    1232           0 :         if (qos_queue->id() != id) {
    1233           0 :             return false;
    1234             :         }
    1235             :     }
    1236             : 
    1237           0 :     if (name_.empty() == false &&
    1238           0 :         qos_queue->name() != name_) {
    1239           0 :         return false;
    1240             :     }
    1241             : 
    1242           0 :     if (uuid_.empty() == false && qos_queue->uuid() != StringToUuid(uuid_)) {
    1243           0 :         return false;
    1244             :     }
    1245             : 
    1246           0 :     return true;
    1247             : }
    1248             : 
    1249           0 : bool QosQueueSandesh::FilterToArgs(AgentSandeshArguments *args) {
    1250           0 :     args->Add("uuid", uuid_);
    1251           0 :     args->Add("name", name_);
    1252           0 :     args->Add("id", id_);
    1253           0 :     return true;
    1254             : }
    1255             : 
    1256           0 : BridgeDomainSandesh::BridgeDomainSandesh(const std::string &context,
    1257             :                                          const std::string &u,
    1258           0 :                                          const std::string &name) :
    1259           0 :     AgentSandesh(context, ""), uuid_str_(u), name_(name) {
    1260           0 :     boost::system::error_code ec;
    1261           0 :     uuid_ = StringToUuid(u);
    1262           0 : }
    1263             : 
    1264           0 : DBTable *BridgeDomainSandesh::AgentGetTable() {
    1265           0 :     return static_cast<DBTable *>(Agent::GetInstance()->bridge_domain_table());
    1266             : }
    1267             : 
    1268           0 : void BridgeDomainSandesh::Alloc() {
    1269           0 :     resp_ = new BridgeDomainSandeshResp();
    1270           0 : }
    1271             : 
    1272           0 : bool BridgeDomainSandesh::Filter(const DBEntryBase *entry) {
    1273             :     const BridgeDomainEntry *bd =
    1274           0 :         dynamic_cast<const BridgeDomainEntry *>(entry);
    1275           0 :     assert(bd);
    1276             : 
    1277           0 :     if (MatchUuid(uuid_str_ , uuid_,  bd->uuid()) == false)
    1278           0 :         return false;
    1279             : 
    1280           0 :     if (name_.empty() == false &&
    1281           0 :         bd->name() != name_) {
    1282           0 :         return false;
    1283             :     }
    1284             : 
    1285           0 :     return true;
    1286             : }
    1287             : 
    1288           0 : bool BridgeDomainSandesh::FilterToArgs(AgentSandeshArguments *args) {
    1289           0 :     args->Add("uuid", uuid_str_);
    1290           0 :     args->Add("name", name_);
    1291           0 :     return true;
    1292             : }
    1293             : 
    1294           0 : DBTable *AgentPolicySetSandesh::AgentGetTable() {
    1295           0 :     return static_cast<DBTable *>(Agent::GetInstance()->policy_set_table());
    1296             : }
    1297             : 
    1298           0 : AgentPolicySetSandesh::AgentPolicySetSandesh(const std::string &context,
    1299             :                                              const std::string &u,
    1300           0 :                                              const std::string &name) :
    1301           0 :     AgentSandesh(context, ""), uuid_str_(u), name_(name) {
    1302           0 :     boost::system::error_code ec;
    1303           0 :     uuid_ = StringToUuid(u);
    1304           0 : }
    1305             : 
    1306           0 : void AgentPolicySetSandesh::Alloc() {
    1307           0 :     resp_ = new ApplicationPolicySetResp();
    1308           0 : }
    1309             : 
    1310           0 : bool AgentPolicySetSandesh::UpdateResp(DBEntryBase *entry) {
    1311           0 :     PolicySet *ent = static_cast<PolicySet *>(entry);
    1312           0 :     return ent->DBEntrySandesh(resp_, name_);
    1313             : }
    1314             : 
    1315           0 : bool AgentPolicySetSandesh::FilterToArgs(AgentSandeshArguments *args) {
    1316           0 :     args->Add("uuid", uuid_str_);
    1317           0 :     args->Add("name", name_);
    1318           0 :     return true;
    1319             : }
    1320             : 
    1321           0 : bool AgentPolicySetSandesh::Filter(const DBEntryBase *entry) {
    1322             :     const PolicySet *ps =
    1323           0 :         dynamic_cast<const PolicySet *>(entry);
    1324           0 :     assert(ps);
    1325             : 
    1326           0 :     if (MatchUuid(uuid_str_ , uuid_,  ps->uuid()) == false) {
    1327           0 :         return false;
    1328             :     }
    1329             : 
    1330           0 :     if (name_.empty() == false &&
    1331           0 :             ps->name() != name_) {
    1332           0 :         return false;
    1333             :     }
    1334             : 
    1335           0 :     return true;
    1336             : }
    1337             : 
    1338           0 : TagSandesh::TagSandesh(const std::string &context,
    1339             :                                          const std::string &u,
    1340           0 :                                          const std::string &name) :
    1341           0 :     AgentSandesh(context, ""), uuid_str_(u), name_(name) {
    1342           0 :     boost::system::error_code ec;
    1343           0 :     uuid_ = StringToUuid(u);
    1344           0 : }
    1345             : 
    1346           0 : DBTable *TagSandesh::AgentGetTable() {
    1347           0 :     return static_cast<DBTable *>(Agent::GetInstance()->tag_table());
    1348             : }
    1349             : 
    1350           0 : void TagSandesh::Alloc() {
    1351           0 :     resp_ = new TagSandeshResp();
    1352           0 : }
    1353             : 
    1354           0 : bool TagSandesh::Filter(const DBEntryBase *entry) {
    1355             :     const TagEntry *tag =
    1356           0 :         dynamic_cast<const TagEntry *>(entry);
    1357           0 :     assert(tag);
    1358             : 
    1359           0 :     if (MatchUuid(uuid_str_ , uuid_,  tag->tag_uuid()) == false)
    1360           0 :         return false;
    1361             : 
    1362           0 :     if (name_.empty() == false &&
    1363           0 :         tag->name() != name_) {
    1364           0 :         return false;
    1365             :     }
    1366             : 
    1367           0 :     return true;
    1368             : }
    1369             : 
    1370           0 : bool TagSandesh::FilterToArgs(AgentSandeshArguments *args) {
    1371           0 :     args->Add("uuid", uuid_str_);
    1372           0 :     args->Add("name", name_);
    1373           0 :     return true;
    1374             : }
    1375             : 
    1376           0 : DBTable *AgentSecurityLoggingObjectSandesh::AgentGetTable() {
    1377           0 :     return static_cast<DBTable *>(Agent::GetInstance()->slo_table());
    1378             : }
    1379             : 
    1380           0 : void AgentSecurityLoggingObjectSandesh::Alloc() {
    1381           0 :     resp_ = new SLOListResp();
    1382           0 : }
    1383             : 
    1384           0 : DBTable *AgentCryptTunnelSandesh::AgentGetTable() {
    1385           0 :     return static_cast<DBTable *>(Agent::GetInstance()->crypt_tunnel_table());
    1386             : }
    1387             : 
    1388           0 : void AgentCryptTunnelSandesh::Alloc() {
    1389           0 :     resp_ = new CryptTunnelResp();
    1390           0 : }
    1391             : 
    1392           0 : AgentCryptTunnelSandesh::AgentCryptTunnelSandesh(const std::string &context,
    1393           0 :                                                  const std::string &remote_ip) :
    1394           0 :     AgentSandesh(context, ""), remote_ip_(remote_ip) {
    1395           0 : }
    1396             : 
    1397           0 : bool AgentCryptTunnelSandesh::UpdateResp(DBEntryBase *entry) {
    1398           0 :     CryptTunnelEntry *ent = static_cast<CryptTunnelEntry *>(entry);
    1399           0 :     return ent->DBEntrySandesh(resp_, remote_ip_);
    1400             : }
    1401             : 
    1402           0 : bool AgentCryptTunnelSandesh::FilterToArgs(AgentSandeshArguments *args) {
    1403           0 :     args->Add("remote", remote_ip_);
    1404           0 :     return true;
    1405             : }
    1406             : 
    1407           0 : bool AgentCryptTunnelSandesh::Filter(const DBEntryBase *entry) {
    1408             :     const CryptTunnelEntry *crypt_tunnel_entry =
    1409           0 :         dynamic_cast<const CryptTunnelEntry *>(entry);
    1410           0 :     assert(crypt_tunnel_entry);
    1411             : 
    1412           0 :     if (MatchSubString(crypt_tunnel_entry->ToString(), remote_ip_) == false)
    1413           0 :         return false;
    1414           0 :     return true;
    1415             : }
    1416             : 
    1417           0 : DBTable *AgentMulticastPolicySandesh::AgentGetTable() {
    1418           0 :     return static_cast<DBTable *>(Agent::GetInstance()->mp_table());
    1419             : }
    1420             : 
    1421           0 : void AgentMulticastPolicySandesh::Alloc() {
    1422           0 :     resp_ = new MulticastPolicyResp();
    1423           0 : }
    1424             : 
    1425           0 : bool AgentMulticastPolicySandesh::UpdateResp(DBEntryBase *entry) {
    1426           0 :     MulticastPolicyEntry *ent = static_cast<MulticastPolicyEntry *>(entry);
    1427           0 :     return ent->DBEntrySandesh(resp_, name_);
    1428             : }
    1429             : 

Generated by: LCOV version 1.14