OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ifmap_uuid_mapper.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
3  */
4 
5 #ifndef __IFMAP_UUID_MAPPER_H__
6 #define __IFMAP_UUID_MAPPER_H__
7 
8 #include <boost/bind.hpp>
9 #include <boost/uuid/uuid.hpp>
10 #include <boost/uuid/uuid_io.hpp>
11 
12 #include "db/db_table.h"
13 
14 #include <map>
15 #include <set>
16 #include <string>
17 
18 class DB;
19 class IFMapNode;
20 class IFMapServer;
21 class IFMapServerTable;
22 
23 // Maintains a mapping of [uuid, node]
25 public:
26  typedef std::map<std::string, IFMapNode *> UuidNodeMap;
27  typedef UuidNodeMap::size_type Sz_t;
28 
29  std::string Add(uint64_t ms_long, uint64_t ls_long, IFMapNode *node);
30  void Delete(const std::string &uuid_str);
31  IFMapNode *Find(const std::string &uuid_str);
32  bool Exists(const std::string &uuid_str);
33  void PrintAllMappedEntries();
34  Sz_t Size() { return uuid_node_map_.size(); }
35 
36 private:
38 
39  void SetUuid(uint64_t ms_long, uint64_t ls_long, boost::uuids::uuid &uu_id);
40  std::string UuidToString(const boost::uuids::uuid &id);
41 
43 };
44 
46 public:
47  // Store [vm-uuid, vr-name] from the vm-reg request
48  // ADD: vm-reg-request, DELETE: vm-node add/xmpp-not-ready
49  typedef std::map<std::string, std::string> PendingVmRegMap;
50  // Store [vm-node, vm-uuid]. Used to clean-up uuid_mapper_'s 'vm-uuid'
51  // entry when the vm-node becomes InFeasible. The objects would be gone by
52  // then and the uuid would not be available from the node.
53  // ADD: config vm-node add, DELETE: config vm-node delete
54  typedef std::map<IFMapNode *, std::string> NodeUuidMap;
55 
58 
59  void Initialize();
60  void Shutdown();
62  return uuid_mapper_.Size();
63  }
64 
66  DB *db() { return db_; }
68  bool is_registered() { return registered; }
69 
70  void VmNodeProcess(DBTablePartBase *partition, DBEntryBase *entry);
71  IFMapNode *GetVmNodeByUuid(const std::string &vm_uuid);
72  bool VmNodeExists(const std::string &vm_uuid);
74 
75  void ProcessVmRegAsPending(std::string vm_uuid, std::string vr_name,
76  bool subscribe);
77  bool PendingVmRegExists(const std::string &vm_uuid, std::string *vr_name);
78  PendingVmRegMap::size_type PendingVmRegCount() {
79  return pending_vmreg_map_.size();
80  }
81  void CleanupPendingVmRegEntry(const std::string &vm_uuid) {
82  pending_vmreg_map_.erase(vm_uuid);
83  }
85 
86  bool NodeToUuid(IFMapNode *vm_node, std::string *vm_uuid);
87  bool NodeProcessed(IFMapNode *node);
88  NodeUuidMap::size_type NodeUuidMapCount() {
89  return node_uuid_map_.size();
90  }
92 
93 private:
94  friend class IFMapVmUuidMapperTest;
95  friend class ShowIFMapPendingVmReg;
98 
99  DB *db_;
104  // ADD: config vm-node add, DELETE: config vm-node delete
108 
109  // TODO: consider moving the common parts inside IFMapNode
110  bool IsFeasible(IFMapNode *node);
111 };
112 
113 #endif /* __IFMAP_UUID_MAPPER_H__ */
void ProcessVmRegAsPending(std::string vm_uuid, std::string vr_name, bool subscribe)
DBTable::ListenerId vm_listener_id()
UuidNodeMap::size_type Sz_t
UuidNodeMap uuid_node_map_
std::map< std::string, IFMapNode * > UuidNodeMap
NodeUuidMap::size_type NodeUuidMapCount()
std::string UuidToString(const boost::uuids::uuid &id)
NodeUuidMap node_uuid_map_
DBTable::ListenerId vm_lid_
int ListenerId
Definition: db_table.h:62
IFMapNode * GetVmNodeByUuid(const std::string &vm_uuid)
IFMapServer * server()
boost::uuids::uuid uuid
bool VmNodeExists(const std::string &vm_uuid)
IFMapVmUuidMapper(DB *db, IFMapServer *server)
PendingVmRegMap::size_type PendingVmRegCount()
void PrintAllNodeUuidMappedEntries()
void SetUuid(uint64_t ms_long, uint64_t ls_long, boost::uuids::uuid &uu_id)
IFMapUuidMapper::Sz_t UuidMapperCount()
Definition: db.h:24
bool PendingVmRegExists(const std::string &vm_uuid, std::string *vr_name)
bool NodeToUuid(IFMapNode *vm_node, std::string *vm_uuid)
PendingVmRegMap pending_vmreg_map_
friend class IFMapVmUuidMapperTest
bool IsFeasible(IFMapNode *node)
void CleanupPendingVmRegEntry(const std::string &vm_uuid)
IFMapServerTable * vm_table_
std::string Add(uint64_t ms_long, uint64_t ls_long, IFMapNode *node)
bool NodeProcessed(IFMapNode *node)
bool Exists(const std::string &uuid_str)
IFMapNode * Find(const std::string &uuid_str)
void VmNodeProcess(DBTablePartBase *partition, DBEntryBase *entry)
IFMapUuidMapper uuid_mapper_
std::map< IFMapNode *, std::string > NodeUuidMap
std::map< std::string, std::string > PendingVmRegMap
IFMapServer * ifmap_server_
void Delete(const std::string &uuid_str)