LCOV - code coverage report
Current view: top level - ifmap - ifmap_link.h (source / functions) Hit Total Coverage
Test: OpenSDN C/C++ coverage (all TARGET_SET jobs) Lines: 13 16 81.2 %
Date: 2026-06-18 01:51:13 Functions: 11 12 91.7 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
       3             :  */
       4             : 
       5             : #ifndef __ctrlplane__ifmap_link__
       6             : #define __ctrlplane__ifmap_link__
       7             : 
       8             : #include "db/db_graph_edge.h"
       9             : #include "db/db_table.h"
      10             : #include "ifmap/ifmap_node.h"
      11             : #include "ifmap/ifmap_origin.h"
      12             : 
      13             : // An IFMapLink represents an edge in the ifmap configuration graph.
      14             : // When links are deleted, the cached left and right node_ members are
      15             : // cleared.
      16             : class IFMapLink : public DBGraphEdge {
      17             : public:
      18             :     struct LinkOriginInfo {
      19           0 :         explicit LinkOriginInfo() :
      20           0 :             origin(IFMapOrigin::UNKNOWN), sequence_number(0) {
      21           0 :         }
      22      190622 :         explicit LinkOriginInfo(IFMapOrigin origin, uint64_t seq_num) :
      23      190622 :             origin(origin), sequence_number(seq_num) {
      24      190622 :         }
      25             :         IFMapOrigin origin;
      26             :         uint64_t sequence_number;
      27             :     };
      28             : 
      29             :     IFMapLink(const std::string &name);
      30    10356996 :     const std::string &link_name() const { return link_name_; }
      31      191051 :     virtual const std::string &name() const { return metadata_; }
      32             : 
      33             :     // Initialize the link.
      34             :     void SetProperties(IFMapNode *left, IFMapNode *right,
      35             :                        const std::string &metadata, uint64_t sequence_number,
      36             :                        const IFMapOrigin &origin);
      37             :     // Update some fields
      38             :     void UpdateProperties(const IFMapOrigin &in_origin,
      39             :                           uint64_t sequence_number);
      40             :     // Called by IFMapLinkTable when the node is deleted.
      41             :     void ClearNodes();
      42             : 
      43             :     virtual KeyPtr GetDBRequestKey() const;
      44             :     virtual void SetKey(const DBRequestKey *genkey);
      45             :     virtual std::string ToString() const;
      46             :     virtual bool IsLess(const DBEntry &rgen) const;
      47           8 :     void SetLinkRevival(bool lr) { link_revival_ = lr; };
      48             : 
      49             :     // Return the left node. If the link is deleted, the node is retrieved
      50             :     // by doing a database table lookup iff db in non-NULL. If db is NULL,
      51             :     // the method returns NULL. The actual node may have already been deleted.
      52             :     IFMapNode *LeftNode(DB *db);
      53             :     const IFMapNode *LeftNode(DB *db) const;
      54             : 
      55             :     // Return the right node. As with the corresponding Left methods these
      56             :     // return the cached value if the node is not deleted and perform a DB
      57             :     // lookup (when the parameter db is non-NULL) when the node is deleted.
      58             :     IFMapNode *RightNode(DB *db);
      59             :     const IFMapNode *RightNode(DB *db) const;
      60             : 
      61       13481 :     IFMapNode *left() { return left_node_; }
      62             :     const IFMapNode *left() const { return left_node_; }
      63       10848 :     IFMapNode *right() { return right_node_; }
      64             :     const IFMapNode *right() const { return right_node_; }
      65         721 :     bool link_revival() const { return link_revival_; }
      66             : 
      67         468 :     const IFMapNode::Descriptor &left_id() const { return left_id_; }
      68         468 :     const IFMapNode::Descriptor &right_id() const { return right_id_; }
      69             : 
      70     1009177 :     const std::string &metadata() const { return metadata_; }
      71             : 
      72             :     void AddOriginInfo(const IFMapOrigin &in_origin, uint64_t seq_num);
      73             :     void RemoveOriginInfo(IFMapOrigin::Origin in_origin);
      74             :     bool HasOrigin(IFMapOrigin::Origin in_origin);
      75       33252 :     bool is_origin_empty() { return origin_info_.empty(); }
      76             :     void EncodeLinkInfo(pugi::xml_node *parent) const;
      77             : 
      78             :     // if exists is true, return value will have relevant entry
      79             :     IFMapLink::LinkOriginInfo GetOriginInfo(IFMapOrigin::Origin in_origin,
      80             :                                             bool *exists);
      81             :     // if exists is true, return value will have relevant sequence number
      82             :     uint64_t sequence_number(IFMapOrigin::Origin in_origin, bool *exists);
      83             : 
      84             : private:
      85             :     friend class ShowIFMapLinkTable;
      86             : 
      87             :     std::string link_name_;
      88             :     std::string metadata_;
      89             :     IFMapNode::Descriptor left_id_;
      90             :     IFMapNode::Descriptor right_id_;
      91             :     IFMapNode *left_node_;
      92             :     IFMapNode *right_node_;
      93             :     std::vector<LinkOriginInfo> origin_info_;
      94             :     bool link_revival_;
      95             :     DISALLOW_COPY_AND_ASSIGN(IFMapLink);
      96             : };
      97             : 
      98             : #endif /* defined(__ctrlplane__ifmap_link__) */

Generated by: LCOV version 1.14