OpenSDN source code
sandesh_map.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016 Juniper Networks, Inc. All rights reserved.
3  * Copyright Contributors to the OpenSDN project
4  */
5 
6 #ifndef vnsw_agent_resource_sandesh_map_hpp
7 #define vnsw_agent_resource_sandesh_map_hpp
8 #include "resource_manager/resource_manager_types.h"
9 
10 class Timer;
11 class ResourceManager;
13 // Backup Resource Table maintains all the Sandesh data to
14 // resource index in a map. Timer is maintained per Backup Resource table.
15 // will be used to trigger Write to file based on idle time out logic.
16 // Trigger will be intiated Only when we don't see any frequent Changes
17 // in the Data modifications with in the idle time out period otherwise
18 // Write to file will happens upon fallback.
20 public:
21  static const uint8_t kFallBackCount = 6;
23  const std::string &name,
24  const std::string& file_name);
25  virtual ~BackUpResourceTable();
26 
27  virtual bool WriteToFile() = 0;
28  virtual void ReadFromFile() = 0;
29  virtual void RestoreResource() = 0;
30  bool TimerExpiry();
31  void StartTimer();
33  return backup_manager_;
34  }
35  Agent *agent() {return agent_;}
36  void TriggerBackup();
37  bool UpdateRequired();
40  const std::string & backup_dir() {return backup_dir_;}
41  static const std::string FindFile(const std::string &root,
42  const std::string & file_ext);
43  static bool CalculateHashSum(const std::string &file_name,
44  uint32_t *hashsum);
45  const std::string& file_name_str() {return file_name_str_;}
46  const std::string& file_name_prefix() {return file_name_prefix_;}
47 protected:
48  template <typename T1, typename T2>
49  bool WriteMapToFile(T1* sandesh_data, const T2& index_map);
50  template <typename T>
51  void ReadMapFromFile(T* sandesh_data, const std::string &root);
52  std::string backup_dir_;
53 
54 private:
57  std::string name_;
62  std::string file_name_str_;
63  std::string file_name_prefix_;
65 };
66 
67 // Vrf backup resource table to maintains Sandesh encoded data VrfMpls info
69 public:
70  typedef std::map<uint32_t, VrfMplsResource> Map;
71  typedef Map::iterator MapIter;
74 
75  bool WriteToFile();
76  void ReadFromFile();
77  void RestoreResource();
78  Map& map() {return map_;}
79 private:
81 };
82 
83 // Vlan backup resource table to maintains Sandesh encoded data VlanMpls info
85 public:
86  typedef std::map<uint32_t, VlanMplsResource> Map;
87  typedef Map::iterator MapIter;
90 
91  bool WriteToFile();
92  void ReadFromFile();
93  void RestoreResource();
94  Map& map() {return map_;}
95 private:
97 };
98 
99 // Interface backup resource table to maintains sandesh encode data for
100 // interfaceMpls info
102 public:
103  typedef std::map<uint32_t, InterfaceIndexResource> Map;
104  typedef Map::iterator MapIter;
107 
108  bool WriteToFile();
109  void ReadFromFile();
110  void RestoreResource();
111  Map& map() {return map_;}
112 private:
114 };
115 
116 // Route backup resource table to maintains sandesh encoded data for route info
118 public:
119  typedef std::map<uint32_t, RouteMplsResource> Map;
120  typedef Map::iterator MapIter;
123 
124  bool WriteToFile();
125  void ReadFromFile();
126  void RestoreResource();
127  Map& map() {return map_;}
128 private:
130 };
131 
132 // interface backup resource table to maintains sandesh encoded data for route info
134 public:
135  typedef std::map<uint32_t, VmInterfaceIndexResource> Map;
136  typedef Map::iterator MapIter;
139 
140  bool WriteToFile();
141  void ReadFromFile();
142  void RestoreResource();
143  Map& map() {return map_;}
144 private:
146 };
147 
148 // vrf backup resource table to maintains sandesh encoded data for vrf info
150 public:
151  typedef std::map<uint32_t, VrfIndexResource> Map;
152  typedef Map::iterator MapIter;
154  virtual ~VrfBackUpResourceTable();
155 
156  bool WriteToFile();
157  void ReadFromFile();
158  void RestoreResource();
159  Map& map() {return map_;}
160 private:
162 };
163 
164 // Qos backup resource table to maintains sandesh encoded data for qos info
166 public:
167  typedef std::map<uint32_t, QosIndexResource> Map;
168  typedef Map::iterator MapIter;
170  virtual ~QosBackUpResourceTable();
171 
172  bool WriteToFile();
173  void ReadFromFile();
174  void RestoreResource();
175  Map& map() {return map_;}
176 private:
178 };
179 
180 // bgp as a service backup resource table to maintains
181 // sandesh encoded data for bgp info
183 public:
184  typedef std::map<uint32_t, BgpAsServiceIndexResource> Map;
185  typedef Map::iterator MapIter;
188 
189  bool WriteToFile();
190  void ReadFromFile();
191  void RestoreResource();
192  Map& map() {return map_;}
193 private:
195 };
196 
197 // mirro backup resource table to maintains sandesh encoded data for mirro info
199 public:
200  typedef std::map<uint32_t, MirrorIndexResource> Map;
201  typedef Map::iterator MapIter;
203  virtual ~MirrorBackUpResourceTable();
204 
205  bool WriteToFile();
206  void ReadFromFile();
207  void RestoreResource();
208  Map& map() {return map_;}
209 private:
211 };
212 
213 // Maintians all the Sandesh encoded structures
215 public:
216  typedef pair<uint32_t, VrfMplsResource> VrfMplsResourcePair;
217  typedef pair<uint32_t, VlanMplsResource> VlanMplsResourcePair;
218  typedef pair<uint32_t, InterfaceIndexResource>
220  typedef pair<uint32_t, RouteMplsResource> RouteMplsResourcePair;
221  typedef pair<uint32_t, VmInterfaceIndexResource>
223  typedef pair<uint32_t, VrfIndexResource> VrfIndexResourcePair;
224  typedef pair<uint32_t, QosIndexResource> QosIndexResourcePair;
225  typedef pair<uint32_t, BgpAsServiceIndexResource>
227  typedef pair<uint32_t, MirrorIndexResource> MirrorIndexResourcePair;
229  virtual ~ResourceSandeshMaps();
230  void ReadFromFile();
231  void RestoreResource();
232  void EndOfBackup();
233  void AddInterfaceMplsResourceEntry(uint32_t index,
234  InterfaceIndexResource data );
235  void DeleteInterfaceMplsResourceEntry(uint32_t index);
236  void AddVrfMplsResourceEntry(uint32_t index,
237  VrfMplsResource data);
238  void DeleteVrfMplsResourceEntry(uint32_t index);
239  void AddVlanMplsResourceEntry(uint32_t index,
240  VlanMplsResource data);
241  void DeleteVlanMplsResourceEntry(uint32_t index);
242  void AddRouteMplsResourceEntry(uint32_t index,
243  RouteMplsResource data);
244  void DeleteRouteMplsResourceEntry(uint32_t index);
245 
246  void AddVmInterfaceResourceEntry(uint32_t index,
247  VmInterfaceIndexResource data);
248  void DeleteVmInterfaceResourceEntry(uint32_t index);
249 
250  void AddVrfResourceEntry(uint32_t index,
251  VrfIndexResource data);
252  void DeleteVrfResourceEntry(uint32_t index);
253 
254  void AddQosResourceEntry(uint32_t index,
255  QosIndexResource data);
256  void DeleteQosResourceEntry(uint32_t index);
257 
258  void AddBgpAsServiceResourceEntry(uint32_t index,
259  BgpAsServiceIndexResource data);
260  void DeleteBgpAsServiceResourceEntry(uint32_t index);
261 
262  void AddMirrorResourceEntry(uint32_t index,
263  MirrorIndexResource data);
264  void DeleteMirrorResourceEntry(uint32_t index);
265 
268  }
269 
271  return vrf_mpls_index_table_;
272  }
273 
275  return vlan_mpls_index_table_;
276  }
277 
280  }
281 
284  }
285 
287  return vrf_index_table_;
288  }
289 
291  return qos_index_table_;
292  }
293 
296  }
297 
299  return mirror_index_table_;
300  }
301 
302 private:
315 };
316 #endif
Definition: agent.h:361
bool WriteMapToFile(T1 *sandesh_data, const T2 &index_map)
Definition: sandesh_map.cc:159
const std::string & file_name_str()
Definition: sandesh_map.h:45
DISALLOW_COPY_AND_ASSIGN(BackUpResourceTable)
virtual void ReadFromFile()=0
virtual bool WriteToFile()=0
std::string name_
Definition: sandesh_map.h:57
static const std::string FindFile(const std::string &root, const std::string &file_ext)
Definition: sandesh_map.cc:199
virtual ~BackUpResourceTable()
Definition: sandesh_map.cc:57
uint32_t backup_idle_timeout_
Definition: sandesh_map.h:59
uint64_t last_modified_time_
Definition: sandesh_map.h:60
void ReadMapFromFile(T *sandesh_data, const std::string &root)
Definition: sandesh_map.cc:245
std::string file_name_prefix_
Definition: sandesh_map.h:63
void EnqueueRestore(ResourceManager::KeyPtr key, ResourceManager::DataPtr data)
Definition: sandesh_map.cc:101
const std::string & backup_dir()
Definition: sandesh_map.h:40
std::string file_name_str_
Definition: sandesh_map.h:62
static const uint8_t kFallBackCount
Definition: sandesh_map.h:21
std::string backup_dir_
Definition: sandesh_map.h:52
static bool CalculateHashSum(const std::string &file_name, uint32_t *hashsum)
Definition: sandesh_map.cc:140
ResourceBackupManager * backup_manager_
Definition: sandesh_map.h:55
BackUpResourceTable(ResourceBackupManager *manager, const std::string &name, const std::string &file_name)
Definition: sandesh_map.cc:30
uint8_t fall_back_count_
Definition: sandesh_map.h:61
ResourceBackupManager * backup_manager()
Definition: sandesh_map.h:32
virtual void RestoreResource()=0
const std::string & file_name_prefix()
Definition: sandesh_map.h:46
BgpAsServiceBackUpResourceTable(ResourceBackupManager *manager)
Definition: sandesh_map.cc:559
std::map< uint32_t, BgpAsServiceIndexResource > Map
Definition: sandesh_map.h:184
std::map< uint32_t, InterfaceIndexResource > Map
Definition: sandesh_map.h:103
InterfaceMplsBackUpResourceTable(ResourceBackupManager *manager)
Definition: sandesh_map.cc:394
MirrorBackUpResourceTable(ResourceBackupManager *manager)
Definition: sandesh_map.cc:597
std::map< uint32_t, MirrorIndexResource > Map
Definition: sandesh_map.h:200
virtual ~MirrorBackUpResourceTable()
Definition: sandesh_map.cc:602
std::map< uint32_t, QosIndexResource > Map
Definition: sandesh_map.h:167
virtual ~QosBackUpResourceTable()
Definition: sandesh_map.cc:526
QosBackUpResourceTable(ResourceBackupManager *manager)
Definition: sandesh_map.cc:521
Map::iterator MapIter
Definition: sandesh_map.h:168
boost::shared_ptr< ResourceKey > KeyPtr
boost::shared_ptr< ResourceData > DataPtr
void DeleteBgpAsServiceResourceEntry(uint32_t index)
Definition: sandesh_map.cc:781
void DeleteVrfResourceEntry(uint32_t index)
Definition: sandesh_map.cc:762
pair< uint32_t, VlanMplsResource > VlanMplsResourcePair
Definition: sandesh_map.h:217
void AddRouteMplsResourceEntry(uint32_t index, RouteMplsResource data)
Definition: sandesh_map.cc:739
pair< uint32_t, RouteMplsResource > RouteMplsResourcePair
Definition: sandesh_map.h:220
MirrorBackUpResourceTable & mirror_index_table()
Definition: sandesh_map.h:298
VmInterfaceBackUpResourceTable & vm_interface_index_table()
Definition: sandesh_map.h:282
pair< uint32_t, InterfaceIndexResource > InterfaceMplsResourcePair
Definition: sandesh_map.h:219
BgpAsServiceBackUpResourceTable bgp_as_service_index_table_
Definition: sandesh_map.h:312
QosBackUpResourceTable qos_index_table_
Definition: sandesh_map.h:311
void AddVlanMplsResourceEntry(uint32_t index, VlanMplsResource data)
Definition: sandesh_map.cc:730
virtual ~ResourceSandeshMaps()
Definition: sandesh_map.cc:642
pair< uint32_t, BgpAsServiceIndexResource > BgpAsServiceIndexResourcePair
Definition: sandesh_map.h:226
void DeleteVrfMplsResourceEntry(uint32_t index)
Definition: sandesh_map.cc:726
void DeleteQosResourceEntry(uint32_t index)
Definition: sandesh_map.cc:771
BgpAsServiceBackUpResourceTable & bgp_as_service_index_table()
Definition: sandesh_map.h:294
void AddVrfMplsResourceEntry(uint32_t index, VrfMplsResource data)
Definition: sandesh_map.cc:721
void AddMirrorResourceEntry(uint32_t index, MirrorIndexResource data)
Definition: sandesh_map.cc:785
VrfBackUpResourceTable & vrf_index_table()
Definition: sandesh_map.h:286
void AddBgpAsServiceResourceEntry(uint32_t index, BgpAsServiceIndexResource data)
Definition: sandesh_map.cc:776
VrfBackUpResourceTable vrf_index_table_
Definition: sandesh_map.h:310
pair< uint32_t, VmInterfaceIndexResource > VmInterfaceIndexResourcePair
Definition: sandesh_map.h:222
QosBackUpResourceTable & qos_index_table()
Definition: sandesh_map.h:290
InterfaceMplsBackUpResourceTable & interface_mpls_index_table()
Definition: sandesh_map.h:266
VrfMplsBackUpResourceTable vrf_mpls_index_table_
Definition: sandesh_map.h:306
pair< uint32_t, VrfMplsResource > VrfMplsResourcePair
Definition: sandesh_map.h:216
void AddInterfaceMplsResourceEntry(uint32_t index, InterfaceIndexResource data)
Definition: sandesh_map.cc:712
VlanMplsBackUpResourceTable & vlan_mpls_index_table()
Definition: sandesh_map.h:274
VmInterfaceBackUpResourceTable vm_interface_index_table_
Definition: sandesh_map.h:309
VlanMplsBackUpResourceTable vlan_mpls_index_table_
Definition: sandesh_map.h:307
MirrorBackUpResourceTable mirror_index_table_
Definition: sandesh_map.h:313
void DeleteMirrorResourceEntry(uint32_t index)
Definition: sandesh_map.cc:791
VrfMplsBackUpResourceTable & vrf_mpls_index_table()
Definition: sandesh_map.h:270
RouteMplsBackUpResourceTable route_mpls_index_table_
Definition: sandesh_map.h:308
DISALLOW_COPY_AND_ASSIGN(ResourceSandeshMaps)
void AddVmInterfaceResourceEntry(uint32_t index, VmInterfaceIndexResource data)
Definition: sandesh_map.cc:748
void DeleteVlanMplsResourceEntry(uint32_t index)
Definition: sandesh_map.cc:735
InterfaceMplsBackUpResourceTable interface_mpls_index_table_
Definition: sandesh_map.h:305
void DeleteInterfaceMplsResourceEntry(uint32_t index)
Definition: sandesh_map.cc:717
void AddVrfResourceEntry(uint32_t index, VrfIndexResource data)
Definition: sandesh_map.cc:757
RouteMplsBackUpResourceTable & route_mpls_index_table()
Definition: sandesh_map.h:278
pair< uint32_t, QosIndexResource > QosIndexResourcePair
Definition: sandesh_map.h:224
ResourceSandeshMaps(ResourceBackupManager *manager)
Definition: sandesh_map.cc:633
pair< uint32_t, VrfIndexResource > VrfIndexResourcePair
Definition: sandesh_map.h:223
void DeleteRouteMplsResourceEntry(uint32_t index)
Definition: sandesh_map.cc:744
ResourceBackupManager * backup_manager_
Definition: sandesh_map.h:303
pair< uint32_t, MirrorIndexResource > MirrorIndexResourcePair
Definition: sandesh_map.h:227
void DeleteVmInterfaceResourceEntry(uint32_t index)
Definition: sandesh_map.cc:753
void AddQosResourceEntry(uint32_t index, QosIndexResource data)
Definition: sandesh_map.cc:766
RouteMplsBackUpResourceTable(ResourceBackupManager *manager)
Definition: sandesh_map.cc:359
std::map< uint32_t, RouteMplsResource > Map
Definition: sandesh_map.h:119
Definition: timer.h:58
VlanMplsBackUpResourceTable(ResourceBackupManager *manager)
Definition: sandesh_map.cc:320
std::map< uint32_t, VlanMplsResource > Map
Definition: sandesh_map.h:86
virtual ~VlanMplsBackUpResourceTable()
Definition: sandesh_map.cc:325
VmInterfaceBackUpResourceTable(ResourceBackupManager *manager)
Definition: sandesh_map.cc:445
std::map< uint32_t, VmInterfaceIndexResource > Map
Definition: sandesh_map.h:135
std::map< uint32_t, VrfIndexResource > Map
Definition: sandesh_map.h:151
virtual ~VrfBackUpResourceTable()
Definition: sandesh_map.cc:488
Map::iterator MapIter
Definition: sandesh_map.h:152
VrfBackUpResourceTable(ResourceBackupManager *manager)
Definition: sandesh_map.cc:483
std::map< uint32_t, VrfMplsResource > Map
Definition: sandesh_map.h:70
VrfMplsBackUpResourceTable(ResourceBackupManager *manager)
Definition: sandesh_map.cc:283
virtual ~VrfMplsBackUpResourceTable()
Definition: sandesh_map.cc:288