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

Generated by: LCOV version 1.14