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  */
4 
5 #ifndef vnsw_agent_resource_sandesh_map_hpp
6 #define vnsw_agent_resource_sandesh_map_hpp
7 #include "resource_manager/resource_manager_types.h"
8 
9 class Timer;
10 class ResourceManager;
12 // Backup Resource Table maintains all the Sandesh data to
13 // resource index in a map. Timer is maintained per Backup Resource table.
14 // will be used to trigger Write to file based on idle time out logic.
15 // Trigger will be intiated Only when we don't see any frequent Changes
16 // in the Data modifications with in the idle time out period otherwise
17 // Write to file will happens upon fallback.
19 public:
20  static const uint8_t kFallBackCount = 6;
22  const std::string &name,
23  const std::string& file_name);
24  virtual ~BackUpResourceTable();
25 
26  virtual bool WriteToFile() = 0;
27  virtual void ReadFromFile() = 0;
28  virtual void RestoreResource() = 0;
29  bool TimerExpiry();
30  void StartTimer();
32  return backup_manager_;
33  }
34  Agent *agent() {return agent_;}
35  void TriggerBackup();
36  bool UpdateRequired();
39  const std::string & backup_dir() {return backup_dir_;}
40  static const std::string FindFile(const std::string &root,
41  const std::string & file_ext);
42  static bool CalculateHashSum(const std::string &file_name,
43  uint32_t *hashsum);
44  const std::string& file_name_str() {return file_name_str_;}
45  const std::string& file_name_prefix() {return file_name_prefix_;}
46 protected:
47  template <typename T1, typename T2>
48  bool WriteMapToFile(T1* sandesh_data, const T2& index_map);
49  template <typename T>
50  void ReadMapFromFile(T* sandesh_data, const std::string &root);
51  std::string backup_dir_;
52 
53 private:
56  std::string name_;
61  std::string file_name_str_;
62  std::string file_name_prefix_;
64 };
65 
66 // Vrf backup resource table to maintains Sandesh encoded data VrfMpls info
68 public:
69  typedef std::map<uint32_t, VrfMplsResource> Map;
70  typedef Map::iterator MapIter;
73 
74  bool WriteToFile();
75  void ReadFromFile();
76  void RestoreResource();
77  Map& map() {return map_;}
78 private:
80 };
81 
82 // Vlan backup resource table to maintains Sandesh encoded data VlanMpls info
84 public:
85  typedef std::map<uint32_t, VlanMplsResource> Map;
86  typedef Map::iterator MapIter;
89 
90  bool WriteToFile();
91  void ReadFromFile();
92  void RestoreResource();
93  Map& map() {return map_;}
94 private:
96 };
97 
98 // Interface backup resource table to maintains sandesh encode data for
99 // interfaceMpls info
101 public:
102  typedef std::map<uint32_t, InterfaceIndexResource> Map;
103  typedef Map::iterator MapIter;
106 
107  bool WriteToFile();
108  void ReadFromFile();
109  void RestoreResource();
110  Map& map() {return map_;}
111 private:
113 };
114 
115 // Route backup resource table to maintains sandesh encoded data for route info
117 public:
118  typedef std::map<uint32_t, RouteMplsResource> Map;
119  typedef Map::iterator MapIter;
122 
123  bool WriteToFile();
124  void ReadFromFile();
125  void RestoreResource();
126  Map& map() {return map_;}
127 private:
129 };
130 
131 // interface backup resource table to maintains sandesh encoded data for route info
133 public:
134  typedef std::map<uint32_t, VmInterfaceIndexResource> Map;
135  typedef Map::iterator MapIter;
138 
139  bool WriteToFile();
140  void ReadFromFile();
141  void RestoreResource();
142  Map& map() {return map_;}
143 private:
145 };
146 
147 // vrf backup resource table to maintains sandesh encoded data for vrf info
149 public:
150  typedef std::map<uint32_t, VrfIndexResource> Map;
151  typedef Map::iterator MapIter;
153  virtual ~VrfBackUpResourceTable();
154 
155  bool WriteToFile();
156  void ReadFromFile();
157  void RestoreResource();
158  Map& map() {return map_;}
159 private:
161 };
162 
163 // Qos backup resource table to maintains sandesh encoded data for qos info
165 public:
166  typedef std::map<uint32_t, QosIndexResource> Map;
167  typedef Map::iterator MapIter;
169  virtual ~QosBackUpResourceTable();
170 
171  bool WriteToFile();
172  void ReadFromFile();
173  void RestoreResource();
174  Map& map() {return map_;}
175 private:
177 };
178 
179 // bgp as a service backup resource table to maintains
180 // sandesh encoded data for bgp info
182 public:
183  typedef std::map<uint32_t, BgpAsServiceIndexResource> Map;
184  typedef Map::iterator MapIter;
187 
188  bool WriteToFile();
189  void ReadFromFile();
190  void RestoreResource();
191  Map& map() {return map_;}
192 private:
194 };
195 
196 // mirro backup resource table to maintains sandesh encoded data for mirro info
198 public:
199  typedef std::map<uint32_t, MirrorIndexResource> Map;
200  typedef Map::iterator MapIter;
202  virtual ~MirrorBackUpResourceTable();
203 
204  bool WriteToFile();
205  void ReadFromFile();
206  void RestoreResource();
207  Map& map() {return map_;}
208 private:
210 };
211 
212 // Maintians all the Sandesh encoded structures
214 public:
215  typedef pair<uint32_t, VrfMplsResource> VrfMplsResourcePair;
216  typedef pair<uint32_t, VlanMplsResource> VlanMplsResourcePair;
217  typedef pair<uint32_t, InterfaceIndexResource>
219  typedef pair<uint32_t, RouteMplsResource> RouteMplsResourcePair;
220  typedef pair<uint32_t, VmInterfaceIndexResource>
222  typedef pair<uint32_t, VrfIndexResource> VrfIndexResourcePair;
223  typedef pair<uint32_t, QosIndexResource> QosIndexResourcePair;
224  typedef pair<uint32_t, BgpAsServiceIndexResource>
226  typedef pair<uint32_t, MirrorIndexResource> MirrorIndexResourcePair;
228  virtual ~ResourceSandeshMaps();
229  void ReadFromFile();
230  void RestoreResource();
231  void EndOfBackup();
232  void AddInterfaceMplsResourceEntry(uint32_t index,
233  InterfaceIndexResource data );
234  void DeleteInterfaceMplsResourceEntry(uint32_t index);
235  void AddVrfMplsResourceEntry(uint32_t index,
236  VrfMplsResource data);
237  void DeleteVrfMplsResourceEntry(uint32_t index);
238  void AddVlanMplsResourceEntry(uint32_t index,
239  VlanMplsResource data);
240  void DeleteVlanMplsResourceEntry(uint32_t index);
241  void AddRouteMplsResourceEntry(uint32_t index,
242  RouteMplsResource data);
243  void DeleteRouteMplsResourceEntry(uint32_t index);
244 
245  void AddVmInterfaceResourceEntry(uint32_t index,
246  VmInterfaceIndexResource data);
247  void DeleteVmInterfaceResourceEntry(uint32_t index);
248 
249  void AddVrfResourceEntry(uint32_t index,
250  VrfIndexResource data);
251  void DeleteVrfResourceEntry(uint32_t index);
252 
253  void AddQosResourceEntry(uint32_t index,
254  QosIndexResource data);
255  void DeleteQosResourceEntry(uint32_t index);
256 
257  void AddBgpAsServiceResourceEntry(uint32_t index,
258  BgpAsServiceIndexResource data);
259  void DeleteBgpAsServiceResourceEntry(uint32_t index);
260 
261  void AddMirrorResourceEntry(uint32_t index,
262  MirrorIndexResource data);
263  void DeleteMirrorResourceEntry(uint32_t index);
264 
267  }
268 
270  return vrf_mpls_index_table_;
271  }
272 
274  return vlan_mpls_index_table_;
275  }
276 
279  }
280 
283  }
284 
286  return vrf_index_table_;
287  }
288 
290  return qos_index_table_;
291  }
292 
295  }
296 
298  return mirror_index_table_;
299  }
300 
301 private:
314 };
315 #endif
Definition: agent.h:360
bool WriteMapToFile(T1 *sandesh_data, const T2 &index_map)
Definition: sandesh_map.cc:158
const std::string & file_name_str()
Definition: sandesh_map.h:44
DISALLOW_COPY_AND_ASSIGN(BackUpResourceTable)
virtual void ReadFromFile()=0
virtual bool WriteToFile()=0
std::string name_
Definition: sandesh_map.h:56
static const std::string FindFile(const std::string &root, const std::string &file_ext)
Definition: sandesh_map.cc:198
virtual ~BackUpResourceTable()
Definition: sandesh_map.cc:56
uint32_t backup_idle_timeout_
Definition: sandesh_map.h:58
uint64_t last_modified_time_
Definition: sandesh_map.h:59
void ReadMapFromFile(T *sandesh_data, const std::string &root)
Definition: sandesh_map.cc:244
std::string file_name_prefix_
Definition: sandesh_map.h:62
void EnqueueRestore(ResourceManager::KeyPtr key, ResourceManager::DataPtr data)
Definition: sandesh_map.cc:100
const std::string & backup_dir()
Definition: sandesh_map.h:39
std::string file_name_str_
Definition: sandesh_map.h:61
static const uint8_t kFallBackCount
Definition: sandesh_map.h:20
std::string backup_dir_
Definition: sandesh_map.h:51
static bool CalculateHashSum(const std::string &file_name, uint32_t *hashsum)
Definition: sandesh_map.cc:139
ResourceBackupManager * backup_manager_
Definition: sandesh_map.h:54
BackUpResourceTable(ResourceBackupManager *manager, const std::string &name, const std::string &file_name)
Definition: sandesh_map.cc:29
uint8_t fall_back_count_
Definition: sandesh_map.h:60
ResourceBackupManager * backup_manager()
Definition: sandesh_map.h:31
virtual void RestoreResource()=0
const std::string & file_name_prefix()
Definition: sandesh_map.h:45
BgpAsServiceBackUpResourceTable(ResourceBackupManager *manager)
Definition: sandesh_map.cc:558
std::map< uint32_t, BgpAsServiceIndexResource > Map
Definition: sandesh_map.h:183
std::map< uint32_t, InterfaceIndexResource > Map
Definition: sandesh_map.h:102
InterfaceMplsBackUpResourceTable(ResourceBackupManager *manager)
Definition: sandesh_map.cc:393
MirrorBackUpResourceTable(ResourceBackupManager *manager)
Definition: sandesh_map.cc:596
std::map< uint32_t, MirrorIndexResource > Map
Definition: sandesh_map.h:199
virtual ~MirrorBackUpResourceTable()
Definition: sandesh_map.cc:601
std::map< uint32_t, QosIndexResource > Map
Definition: sandesh_map.h:166
virtual ~QosBackUpResourceTable()
Definition: sandesh_map.cc:525
QosBackUpResourceTable(ResourceBackupManager *manager)
Definition: sandesh_map.cc:520
Map::iterator MapIter
Definition: sandesh_map.h:167
boost::shared_ptr< ResourceKey > KeyPtr
boost::shared_ptr< ResourceData > DataPtr
void DeleteBgpAsServiceResourceEntry(uint32_t index)
Definition: sandesh_map.cc:780
void DeleteVrfResourceEntry(uint32_t index)
Definition: sandesh_map.cc:761
pair< uint32_t, VlanMplsResource > VlanMplsResourcePair
Definition: sandesh_map.h:216
void AddRouteMplsResourceEntry(uint32_t index, RouteMplsResource data)
Definition: sandesh_map.cc:738
pair< uint32_t, RouteMplsResource > RouteMplsResourcePair
Definition: sandesh_map.h:219
MirrorBackUpResourceTable & mirror_index_table()
Definition: sandesh_map.h:297
VmInterfaceBackUpResourceTable & vm_interface_index_table()
Definition: sandesh_map.h:281
pair< uint32_t, InterfaceIndexResource > InterfaceMplsResourcePair
Definition: sandesh_map.h:218
BgpAsServiceBackUpResourceTable bgp_as_service_index_table_
Definition: sandesh_map.h:311
QosBackUpResourceTable qos_index_table_
Definition: sandesh_map.h:310
void AddVlanMplsResourceEntry(uint32_t index, VlanMplsResource data)
Definition: sandesh_map.cc:729
virtual ~ResourceSandeshMaps()
Definition: sandesh_map.cc:641
pair< uint32_t, BgpAsServiceIndexResource > BgpAsServiceIndexResourcePair
Definition: sandesh_map.h:225
void DeleteVrfMplsResourceEntry(uint32_t index)
Definition: sandesh_map.cc:725
void DeleteQosResourceEntry(uint32_t index)
Definition: sandesh_map.cc:770
BgpAsServiceBackUpResourceTable & bgp_as_service_index_table()
Definition: sandesh_map.h:293
void AddVrfMplsResourceEntry(uint32_t index, VrfMplsResource data)
Definition: sandesh_map.cc:720
void AddMirrorResourceEntry(uint32_t index, MirrorIndexResource data)
Definition: sandesh_map.cc:784
VrfBackUpResourceTable & vrf_index_table()
Definition: sandesh_map.h:285
void AddBgpAsServiceResourceEntry(uint32_t index, BgpAsServiceIndexResource data)
Definition: sandesh_map.cc:775
VrfBackUpResourceTable vrf_index_table_
Definition: sandesh_map.h:309
pair< uint32_t, VmInterfaceIndexResource > VmInterfaceIndexResourcePair
Definition: sandesh_map.h:221
QosBackUpResourceTable & qos_index_table()
Definition: sandesh_map.h:289
InterfaceMplsBackUpResourceTable & interface_mpls_index_table()
Definition: sandesh_map.h:265
VrfMplsBackUpResourceTable vrf_mpls_index_table_
Definition: sandesh_map.h:305
pair< uint32_t, VrfMplsResource > VrfMplsResourcePair
Definition: sandesh_map.h:215
void AddInterfaceMplsResourceEntry(uint32_t index, InterfaceIndexResource data)
Definition: sandesh_map.cc:711
VlanMplsBackUpResourceTable & vlan_mpls_index_table()
Definition: sandesh_map.h:273
VmInterfaceBackUpResourceTable vm_interface_index_table_
Definition: sandesh_map.h:308
VlanMplsBackUpResourceTable vlan_mpls_index_table_
Definition: sandesh_map.h:306
MirrorBackUpResourceTable mirror_index_table_
Definition: sandesh_map.h:312
void DeleteMirrorResourceEntry(uint32_t index)
Definition: sandesh_map.cc:790
VrfMplsBackUpResourceTable & vrf_mpls_index_table()
Definition: sandesh_map.h:269
RouteMplsBackUpResourceTable route_mpls_index_table_
Definition: sandesh_map.h:307
DISALLOW_COPY_AND_ASSIGN(ResourceSandeshMaps)
void AddVmInterfaceResourceEntry(uint32_t index, VmInterfaceIndexResource data)
Definition: sandesh_map.cc:747
void DeleteVlanMplsResourceEntry(uint32_t index)
Definition: sandesh_map.cc:734
InterfaceMplsBackUpResourceTable interface_mpls_index_table_
Definition: sandesh_map.h:304
void DeleteInterfaceMplsResourceEntry(uint32_t index)
Definition: sandesh_map.cc:716
void AddVrfResourceEntry(uint32_t index, VrfIndexResource data)
Definition: sandesh_map.cc:756
RouteMplsBackUpResourceTable & route_mpls_index_table()
Definition: sandesh_map.h:277
pair< uint32_t, QosIndexResource > QosIndexResourcePair
Definition: sandesh_map.h:223
ResourceSandeshMaps(ResourceBackupManager *manager)
Definition: sandesh_map.cc:632
pair< uint32_t, VrfIndexResource > VrfIndexResourcePair
Definition: sandesh_map.h:222
void DeleteRouteMplsResourceEntry(uint32_t index)
Definition: sandesh_map.cc:743
ResourceBackupManager * backup_manager_
Definition: sandesh_map.h:302
pair< uint32_t, MirrorIndexResource > MirrorIndexResourcePair
Definition: sandesh_map.h:226
void DeleteVmInterfaceResourceEntry(uint32_t index)
Definition: sandesh_map.cc:752
void AddQosResourceEntry(uint32_t index, QosIndexResource data)
Definition: sandesh_map.cc:765
RouteMplsBackUpResourceTable(ResourceBackupManager *manager)
Definition: sandesh_map.cc:358
std::map< uint32_t, RouteMplsResource > Map
Definition: sandesh_map.h:118
Definition: timer.h:54
VlanMplsBackUpResourceTable(ResourceBackupManager *manager)
Definition: sandesh_map.cc:319
std::map< uint32_t, VlanMplsResource > Map
Definition: sandesh_map.h:85
virtual ~VlanMplsBackUpResourceTable()
Definition: sandesh_map.cc:324
VmInterfaceBackUpResourceTable(ResourceBackupManager *manager)
Definition: sandesh_map.cc:444
std::map< uint32_t, VmInterfaceIndexResource > Map
Definition: sandesh_map.h:134
std::map< uint32_t, VrfIndexResource > Map
Definition: sandesh_map.h:150
virtual ~VrfBackUpResourceTable()
Definition: sandesh_map.cc:487
Map::iterator MapIter
Definition: sandesh_map.h:151
VrfBackUpResourceTable(ResourceBackupManager *manager)
Definition: sandesh_map.cc:482
std::map< uint32_t, VrfMplsResource > Map
Definition: sandesh_map.h:69
VrfMplsBackUpResourceTable(ResourceBackupManager *manager)
Definition: sandesh_map.cc:282
virtual ~VrfMplsBackUpResourceTable()
Definition: sandesh_map.cc:287