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

Generated by: LCOV version 1.14