OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ifmap_link.h
Go to the documentation of this file.
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  explicit LinkOriginInfo() :
21  }
22  explicit LinkOriginInfo(IFMapOrigin origin, uint64_t seq_num) :
23  origin(origin), sequence_number(seq_num) {
24  }
26  uint64_t sequence_number;
27  };
28 
29  IFMapLink(const std::string &name);
30  const std::string &link_name() const { return link_name_; }
31  virtual const std::string &name() const { return metadata_; }
32 
33  // Initialize the link.
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  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  IFMapNode *left() { return left_node_; }
62  const IFMapNode *left() const { return left_node_; }
63  IFMapNode *right() { return right_node_; }
64  const IFMapNode *right() const { return right_node_; }
65  bool link_revival() const { return link_revival_; }
66 
67  const IFMapNode::Descriptor &left_id() const { return left_id_; }
68  const IFMapNode::Descriptor &right_id() const { return right_id_; }
69 
70  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  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
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_;
93  std::vector<LinkOriginInfo> origin_info_;
96 };
97 
98 #endif /* defined(__ctrlplane__ifmap_link__) */
std::unique_ptr< DBRequestKey > KeyPtr
Definition: db_entry.h:25
Definition: db.h:24
std::pair< std::string, std::string > Descriptor
Definition: ifmap_node.h:22