LCOV - code coverage report
Current view: top level - vnsw/agent/oper - remote_physical_interface.cc (source / functions) Hit Total Coverage
Test: OpenSDN C/C++ coverage (all TARGET_SET jobs) Lines: 13 110 11.8 %
Date: 2026-08-03 02:19:58 Functions: 6 25 24.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) 2014 Juniper Networks, Inc. All rights reserved.
       3             :  */
       4             : 
       5             : #include <boost/uuid/uuid_io.hpp>
       6             : #include <vnc_cfg_types.h>
       7             : #include <cmn/agent_cmn.h>
       8             : 
       9             : #include <ifmap/ifmap_node.h>
      10             : #include <cfg/cfg_init.h>
      11             : #include <oper/agent_sandesh.h>
      12             : #include <oper/ifmap_dependency_manager.h>
      13             : #include <oper/interface_common.h>
      14             : #include <oper/physical_device.h>
      15             : #include <oper/nexthop.h>
      16             : #include <oper/config_manager.h>
      17             : 
      18             : #include <vector>
      19             : #include <string>
      20             : 
      21             : using std::string;
      22             : using boost::uuids::uuid;
      23             : 
      24             : /////////////////////////////////////////////////////////////////////////////
      25             : // RemotePhysicalInterface routines
      26             : /////////////////////////////////////////////////////////////////////////////
      27           1 : RemotePhysicalInterface::RemotePhysicalInterface(const std::string &name) :
      28           1 :     Interface(Interface::REMOTE_PHYSICAL, boost::uuids::nil_uuid(), name,
      29           0 :               NULL, true, boost::uuids::nil_uuid()),
      30           2 :     display_name_(), physical_device_(NULL) {
      31           1 : }
      32             : 
      33           2 : RemotePhysicalInterface::~RemotePhysicalInterface() {
      34           2 : }
      35             : 
      36           0 : string RemotePhysicalInterface::ToString() const {
      37           0 :     return "Remote-PORT <" + name() + ">";
      38             : }
      39             : 
      40           0 : bool RemotePhysicalInterface::CmpInterface(const DBEntry &rhs) const {
      41           0 :     const RemotePhysicalInterface &a =
      42             :         static_cast<const RemotePhysicalInterface &>(rhs);
      43           0 :     return name() < a.name();
      44             : }
      45             : 
      46           0 : void RemotePhysicalInterface::GetOsParams(Agent *agent) {
      47           0 :     os_params_.os_index_ = Interface::kInvalidIndex;
      48           0 :     os_params_.mac_.Zero();
      49           0 :     os_params_.os_oper_state_ = true;
      50           0 : }
      51             : 
      52           0 : DBEntryBase::KeyPtr RemotePhysicalInterface::GetDBRequestKey() const {
      53           0 :     InterfaceKey *key = new RemotePhysicalInterfaceKey(name());
      54           0 :     return DBEntryBase::KeyPtr(key);
      55             : }
      56             : 
      57           0 : bool RemotePhysicalInterface::OnChange(const InterfaceTable *table,
      58             :                                        const RemotePhysicalInterfaceData *data){
      59           0 :     bool ret = false;
      60             : 
      61             :     // Handle VRF Change
      62           0 :     VrfKey key(data->vrf_name_);
      63           0 :     VrfEntry *new_vrf = static_cast<VrfEntry *>
      64           0 :         (table->agent()->vrf_table()->FindActiveEntry(&key));
      65           0 :     if (new_vrf != vrf_.get()) {
      66           0 :         vrf_.reset(new_vrf);
      67           0 :         ret = true;
      68             :     }
      69             : 
      70             :     PhysicalDevice *dev =
      71           0 :         table->agent()->physical_device_table()->Find(data->device_uuid_);
      72           0 :     if (dev != physical_device_.get()) {
      73           0 :         physical_device_.reset(dev);
      74           0 :         ret = true;
      75             :     }
      76             : 
      77           0 :     if (display_name_ != data->display_name_) {
      78           0 :         display_name_ = data->display_name_;
      79           0 :         ret = true;
      80             :     }
      81             : 
      82           0 :     return ret;
      83           0 : }
      84             : 
      85             : /////////////////////////////////////////////////////////////////////////////
      86             : // RemotePhysicalInterfaceKey routines
      87             : /////////////////////////////////////////////////////////////////////////////
      88           1 : RemotePhysicalInterfaceKey::RemotePhysicalInterfaceKey(const std::string &name):
      89             :     InterfaceKey(AgentKey::ADD_DEL_CHANGE, Interface::REMOTE_PHYSICAL,
      90           1 :                  boost::uuids::nil_uuid(), name, false) {
      91           1 : }
      92             : 
      93           1 : RemotePhysicalInterfaceKey::~RemotePhysicalInterfaceKey() {
      94           1 : }
      95             : 
      96           1 : Interface *RemotePhysicalInterfaceKey::AllocEntry(const InterfaceTable *table)
      97             :     const {
      98           1 :     return new RemotePhysicalInterface(name_);
      99             : }
     100             : 
     101           0 : Interface *RemotePhysicalInterfaceKey::AllocEntry(const InterfaceTable *table,
     102             :                                                   const InterfaceData *data)
     103             :     const {
     104           0 :     RemotePhysicalInterface *intf = new RemotePhysicalInterface(name_);
     105             : 
     106           0 :     const RemotePhysicalInterfaceData *phy_data =
     107             :         static_cast<const RemotePhysicalInterfaceData *>(data);
     108             : 
     109           0 :     intf->OnChange(table, phy_data);
     110           0 :     return intf;
     111             : }
     112             : 
     113           0 : InterfaceKey *RemotePhysicalInterfaceKey::Clone() const {
     114           0 :     return new RemotePhysicalInterfaceKey(name_);
     115             : }
     116             : 
     117             : /////////////////////////////////////////////////////////////////////////////
     118             : // RemotePhysicalInterfaceData routines
     119             : /////////////////////////////////////////////////////////////////////////////
     120           0 : RemotePhysicalInterfaceData::RemotePhysicalInterfaceData
     121             :     (Agent *agent, IFMapNode *node, const string &display_name,
     122           0 :      const string &vrf_name, const uuid &device_uuid) :
     123             :     InterfaceData(agent, node, Interface::TRANSPORT_INVALID),
     124           0 :     display_name_(display_name),
     125           0 :     device_uuid_(device_uuid) {
     126           0 :     RemotePhysicalPortInit(vrf_name);
     127           0 : }
     128             : 
     129           0 : RemotePhysicalInterfaceData::~RemotePhysicalInterfaceData() {
     130           0 : }
     131             : 
     132             : /////////////////////////////////////////////////////////////////////////////
     133             : // Config handling routines
     134             : /////////////////////////////////////////////////////////////////////////////
     135           0 : static RemotePhysicalInterfaceKey *BuildKey(IFMapNode *node) {
     136           0 :     return new RemotePhysicalInterfaceKey(node->name());
     137             : }
     138             : 
     139           0 : static RemotePhysicalInterfaceData *BuildData
     140             : (Agent *agent, IFMapNode *node, const autogen::PhysicalInterface *port) {
     141           0 :     boost::uuids::uuid dev_uuid = boost::uuids::nil_uuid();
     142             :     // Find link with physical-router adjacency
     143           0 :     IFMapNode *adj_node = NULL;
     144           0 :     adj_node = agent->config_manager()->FindAdjacentIFMapNode(node,
     145             :                                                             "physical-router");
     146           0 :     if (adj_node) {
     147             :         autogen::PhysicalRouter *router =
     148           0 :             static_cast<autogen::PhysicalRouter *>(adj_node->GetObject());
     149           0 :         autogen::IdPermsType id_perms = router->id_perms();
     150           0 :         CfgUuidSet(id_perms.uuid.uuid_mslong, id_perms.uuid.uuid_lslong,
     151             :                    dev_uuid);
     152           0 :     }
     153             : 
     154           0 :     return new RemotePhysicalInterfaceData(agent, node, port->display_name(),
     155           0 :                                            agent->fabric_vrf_name(), dev_uuid);
     156             : }
     157             : 
     158           0 : bool InterfaceTable::RemotePhysicalInterfaceIFNodeToReq(IFMapNode *node,
     159             :                                                   DBRequest &req,
     160             :                                                   const boost::uuids::uuid &u) {
     161             :     autogen::PhysicalInterface *port =
     162           0 :         static_cast <autogen::PhysicalInterface *>(node->GetObject());
     163           0 :     assert(port);
     164             : 
     165           0 :     req.key.reset(BuildKey(node));
     166           0 :     if (req.oper == DBRequest::DB_ENTRY_DELETE || node->IsDeleted()) {
     167           0 :         req.oper = DBRequest::DB_ENTRY_DELETE;
     168           0 :         return true;
     169             :     }
     170             : 
     171           0 :     req.oper = DBRequest::DB_ENTRY_ADD_CHANGE;
     172           0 :     req.data.reset(BuildData(agent(), node, port));
     173           0 :     pi_ifnode_to_req_++;
     174           0 :     return true;
     175             : }
     176             : 
     177             : /////////////////////////////////////////////////////////////////////////////
     178             : // Utility methods
     179             : /////////////////////////////////////////////////////////////////////////////
     180           0 : static void SetReq(DBRequest *req, const string &fqdn,
     181             :                    const string &display_name, const string &vrf_name,
     182             :                    const uuid &device_uuid) {
     183           0 :     req->key.reset(new RemotePhysicalInterfaceKey(fqdn));
     184           0 :     req->data.reset(new RemotePhysicalInterfaceData(NULL, NULL, display_name,
     185           0 :                                                     vrf_name, device_uuid));
     186           0 : }
     187             : 
     188           0 : void RemotePhysicalInterface::CreateReq(InterfaceTable *table,
     189             :                                         const string &fqdn,
     190             :                                         const string &display_name,
     191             :                                         const string &vrf_name,
     192             :                                         const uuid &device_uuid) {
     193           0 :     DBRequest req(DBRequest::DB_ENTRY_ADD_CHANGE);
     194           0 :     SetReq(&req, fqdn, display_name, vrf_name, device_uuid);
     195           0 :     table->Enqueue(&req);
     196           0 : }
     197             : 
     198           0 : void RemotePhysicalInterface::Create(InterfaceTable *table, const string &fqdn,
     199             :                                      const string &display_name,
     200             :                                      const string &vrf_name,
     201             :                                      const uuid &device_uuid) {
     202           0 :     DBRequest req(DBRequest::DB_ENTRY_ADD_CHANGE);
     203           0 :     SetReq(&req, fqdn, display_name, vrf_name, device_uuid);
     204           0 :     table->Process(req);
     205           0 : }
     206             : 
     207             : // Enqueue DBRequest to delete a Host Interface
     208           0 : void RemotePhysicalInterface::DeleteReq(InterfaceTable *table,
     209             :                                         const string &fqdn) {
     210           0 :     DBRequest req(DBRequest::DB_ENTRY_DELETE);
     211           0 :     req.key.reset(new RemotePhysicalInterfaceKey(fqdn));
     212           0 :     req.data.reset(NULL);
     213           0 :     table->Enqueue(&req);
     214           0 : }
     215             : 
     216           0 : void RemotePhysicalInterface::Delete(InterfaceTable *table,
     217             :                                      const string &fqdn) {
     218           0 :     DBRequest req(DBRequest::DB_ENTRY_DELETE);
     219           0 :     req.key.reset(new RemotePhysicalInterfaceKey(fqdn));
     220           0 :     req.data.reset(NULL);
     221           0 :     table->Process(req);
     222           0 : }

Generated by: LCOV version 1.14