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

Generated by: LCOV version 1.14