Line data Source code
1 : /*
2 : * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
3 : */
4 :
5 : #ifndef vnsw_agent_sandesh_h_
6 : #define vnsw_agent_sandesh_h_
7 :
8 : #include <cmn/agent_cmn.h>
9 :
10 : /////////////////////////////////////////////////////////////////////////////
11 : // Header file defining infra to implement introspect for DB-Tables
12 : /////////////////////////////////////////////////////////////////////////////
13 :
14 : class VrfEntry;
15 : class DBEntryBase;
16 : class PageReqData;
17 :
18 : /////////////////////////////////////////////////////////////////////////////
19 : // Class to encode/decode the arguments used in pagination links
20 : // Stores arguments in form of <key, value> pair in a map
21 : /////////////////////////////////////////////////////////////////////////////
22 : class AgentSandeshArguments {
23 : public:
24 : typedef std::map<std::string, std::string> ArgumentMap;
25 :
26 0 : AgentSandeshArguments() { }
27 0 : ~AgentSandeshArguments() { }
28 :
29 : bool Add(const std::string &key, const std::string &val);
30 : bool Add(const std::string &key, int val);
31 : bool Del(const std::string &key);
32 : bool Get(const std::string &key, std::string *val) const;
33 : std::string GetString(const std::string &key) const;
34 : bool Get(const std::string &key, int *val) const;
35 : int GetInt(const std::string &key) const;
36 :
37 : int Encode(std::string *str);
38 : int Decode(const std::string &str);
39 : private:
40 : ArgumentMap arguments_;
41 : DISALLOW_COPY_AND_ASSIGN(AgentSandeshArguments);
42 : };
43 :
44 : /////////////////////////////////////////////////////////////////////////////
45 : // Manager class for AgentSandesh.
46 : // Agent gets Paging requests in Sandesh task context. Agent needs to iterate
47 : // thru the DBTable. So, we need to move the request to a task in DBTable
48 : // context. A work-queue is defined for this reason
49 : /////////////////////////////////////////////////////////////////////////////
50 : class AgentSandeshManager {
51 : public:
52 : struct PageRequest {
53 2 : PageRequest() : key_(""), context_("") { }
54 0 : PageRequest(const std::string &key, const std::string &context) :
55 0 : key_(key), context_(context) {
56 0 : }
57 0 : PageRequest(const PageRequest &req) :
58 0 : key_(req.key_), context_(req.context_) {
59 0 : }
60 2 : ~PageRequest() { }
61 :
62 : std::string key_;
63 : std::string context_;
64 : };
65 :
66 : AgentSandeshManager(Agent *agent);
67 : ~AgentSandeshManager();
68 :
69 : void Init();
70 : void Shutdown();
71 : void AddPageRequest(const std::string &key, const std::string &context);
72 : bool Run(PageRequest req);
73 : private:
74 : Agent *agent_;
75 : WorkQueue<PageRequest> page_request_queue_;
76 : DISALLOW_COPY_AND_ASSIGN(AgentSandeshManager);
77 : };
78 :
79 : /////////////////////////////////////////////////////////////////////////////
80 : // A common base class to handle introspect requests for DBTables. Provides
81 : // support for common features such as,
82 : //
83 : // - Support for pagination. Including links for prev, next and first pages
84 : // - Supports query of complete table
85 : /////////////////////////////////////////////////////////////////////////////
86 : class AgentSandesh;
87 : typedef class boost::shared_ptr<AgentSandesh> AgentSandeshPtr;
88 : class AgentSandesh {
89 : public:
90 : static const uint8_t entries_per_sandesh = 100;
91 : static const uint16_t kEntriesPerPage = 100;
92 0 : AgentSandesh(const std::string &context, const std::string &name) :
93 0 : name_(name), resp_(NULL), count_(0), total_entries_(0),
94 0 : context_(context), walkid_(DBTableWalker::kInvalidWalkerId) {
95 0 : }
96 : AgentSandesh(const std::string &context) :
97 : name_(""), resp_(NULL), count_(0), context_(context),
98 : walkid_(DBTableWalker::kInvalidWalkerId) {
99 : }
100 :
101 0 : virtual ~AgentSandesh() {}
102 :
103 : // Check if a DBEntry passes filter
104 0 : virtual bool Filter(const DBEntryBase *entry) { return true; }
105 : // Convert from filter to arguments. Arguments will be converted to string
106 : // and passed in next/prev pagination links
107 0 : virtual bool FilterToArgs(AgentSandeshArguments *args) {
108 0 : args->Add("name", name_);
109 0 : return true;
110 : }
111 : std::string context() const { return context_; }
112 :
113 : void DoSandeshInternal(AgentSandeshPtr sandesh, int start, int count);
114 : static void DoSandesh(AgentSandeshPtr sandesh, int start, int count);
115 : static void DoSandesh(AgentSandeshPtr sandesh);
116 : void MakeSandeshPageReq(PageReqData *req, DBTable *table, int first,
117 : int last, int end, int count, int page_size);
118 :
119 : protected:
120 : std::string name_; // name coming in the sandesh request
121 : SandeshResponse *resp_;
122 : private:
123 : bool EntrySandesh(DBEntryBase *entry, int first, int last);
124 : void SandeshDone(AgentSandeshPtr ptr, int first, int page_size,
125 : DBTable::DBTableWalkRef walk_ref,
126 : DBTableBase *partition);
127 : void SetResp();
128 : virtual DBTable *AgentGetTable() = 0;
129 : virtual void Alloc() = 0;
130 : virtual bool UpdateResp(DBEntryBase *entry);
131 :
132 : int count_;
133 : int total_entries_;
134 : std::string context_;
135 : DBTableWalker::WalkId walkid_;
136 : DISALLOW_COPY_AND_ASSIGN(AgentSandesh);
137 : };
138 :
139 : /////////////////////////////////////////////////////////////////////////////
140 : // AgentSandesh class implementation for different OperDB Tables
141 : /////////////////////////////////////////////////////////////////////////////
142 : class AgentVnSandesh : public AgentSandesh {
143 : public:
144 : AgentVnSandesh(const std::string &context, const std::string &name,
145 : const std::string &u, const std::string &vxlan_id,
146 : const std::string &ipam_name);
147 0 : ~AgentVnSandesh() {}
148 : virtual bool Filter(const DBEntryBase *entry);
149 : virtual bool FilterToArgs(AgentSandeshArguments *args);
150 :
151 : private:
152 : friend class VnListReq;
153 : DBTable *AgentGetTable();
154 : void Alloc();
155 : std::string name_;
156 : std::string uuid_str_;
157 : std::string vxlan_id_;
158 : std::string ipam_name_;
159 :
160 : boost::uuids::uuid uuid_;
161 :
162 : };
163 :
164 : class AgentSgSandesh : public AgentSandesh {
165 : public:
166 0 : AgentSgSandesh(std::string context, std::string name)
167 0 : : AgentSandesh(context, name) {}
168 :
169 : private:
170 : DBTable *AgentGetTable();
171 : void Alloc();
172 : };
173 :
174 : class AgentVmSandesh : public AgentSandesh {
175 : public:
176 0 : AgentVmSandesh(std::string context, std::string uuid)
177 0 : : AgentSandesh(context, uuid) {}
178 :
179 : private:
180 : DBTable *AgentGetTable();
181 : void Alloc();
182 : };
183 :
184 : class AgentIntfSandesh : public AgentSandesh {
185 : public:
186 : AgentIntfSandesh(const std::string &context, const std::string &type,
187 : const std::string &name, const std::string &u,
188 : const std::string &vn, const std::string &mac,
189 : const std::string &v4, const std::string &v6,
190 : const std::string &parent, const std::string &ip_active,
191 : const std::string &ip6_active,
192 : const std::string &l2_active);
193 0 : ~AgentIntfSandesh() { }
194 : virtual bool Filter(const DBEntryBase *entry);
195 : virtual bool FilterToArgs(AgentSandeshArguments *args);
196 :
197 : private:
198 : friend class ItfReq;
199 : DBTable *AgentGetTable();
200 : void Alloc();
201 :
202 : // Filters
203 : std::string type_;
204 : std::string name_;
205 : std::string uuid_str_;
206 : std::string vn_;
207 : std::string mac_str_;
208 : std::string v4_str_;
209 : std::string v6_str_;
210 : std::string parent_uuid_str_;
211 : std::string ip_active_str_;
212 : std::string ip6_active_str_;
213 : std::string l2_active_str_;
214 :
215 : boost::uuids::uuid uuid_;
216 : MacAddress mac_;
217 : Ip4Address v4_;
218 : Ip6Address v6_;
219 : boost::uuids::uuid parent_uuid_;
220 : };
221 :
222 : class AgentNhSandesh : public AgentSandesh {
223 : public:
224 : AgentNhSandesh(const std::string &context, const std::string &type,
225 : const std::string &nh_index, const std::string &policy_enabled);
226 0 : ~AgentNhSandesh() { }
227 : virtual bool Filter(const DBEntryBase *entry);
228 : virtual bool FilterToArgs(AgentSandeshArguments *args);
229 :
230 : private:
231 : friend class NhListReq;
232 : DBTable *AgentGetTable();
233 : void Alloc();
234 :
235 : // Filters
236 : std::string type_;
237 : std::string nh_index_;
238 : std::string policy_enabled_;
239 : };
240 :
241 : class AgentMplsSandesh : public AgentSandesh {
242 : public:
243 : AgentMplsSandesh(const std::string &context, const std::string &type,
244 : const std::string &label);
245 0 : ~AgentMplsSandesh() { }
246 : virtual bool Filter(const DBEntryBase *entry);
247 : virtual bool FilterToArgs(AgentSandeshArguments *args);
248 :
249 : private:
250 : friend class MplsReq;
251 : DBTable *AgentGetTable();
252 : void Alloc();
253 :
254 : // Filters
255 : std::string type_;
256 : std::string label_;
257 :
258 : };
259 :
260 : class AgentVrfSandesh : public AgentSandesh {
261 : public:
262 0 : AgentVrfSandesh(std::string context, std::string name)
263 0 : : AgentSandesh(context, name) {}
264 :
265 : private:
266 : DBTable *AgentGetTable();
267 : void Alloc();
268 : };
269 :
270 : class AgentInet4UcRtSandesh : public AgentSandesh {
271 : public:
272 0 : AgentInet4UcRtSandesh(VrfEntry *vrf, std::string context, bool stale)
273 0 : : AgentSandesh(context, ""), vrf_(vrf), stale_(stale) {
274 0 : dump_table_ = true;
275 0 : }
276 0 : AgentInet4UcRtSandesh(VrfEntry *vrf, std::string context,
277 : Ip4Address addr, uint8_t plen, bool stale)
278 0 : : AgentSandesh(context, ""), vrf_(vrf), addr_(addr), plen_(plen),
279 0 : stale_(stale) {
280 0 : dump_table_ = false;
281 0 : }
282 :
283 : private:
284 : DBTable *AgentGetTable();
285 : void Alloc();
286 : bool UpdateResp(DBEntryBase *entry);
287 :
288 : VrfEntry *vrf_;
289 : Ip4Address addr_;
290 : uint8_t plen_;
291 : bool stale_;
292 : bool dump_table_;
293 : };
294 :
295 : class AgentInet4MplsUcRtSandesh : public AgentSandesh {
296 : public:
297 0 : AgentInet4MplsUcRtSandesh(VrfEntry *vrf, std::string context, bool stale)
298 0 : : AgentSandesh(context, ""), vrf_(vrf), stale_(stale) {
299 0 : dump_table_ = true;
300 0 : }
301 0 : AgentInet4MplsUcRtSandesh(VrfEntry *vrf, std::string context,
302 : Ip4Address addr, uint8_t plen, bool stale)
303 0 : : AgentSandesh(context, ""), vrf_(vrf), addr_(addr), plen_(plen),
304 0 : stale_(stale) {
305 0 : dump_table_ = false;
306 0 : }
307 :
308 : private:
309 : DBTable *AgentGetTable();
310 : void Alloc();
311 : bool UpdateResp(DBEntryBase *entry);
312 :
313 : VrfEntry *vrf_;
314 : Ip4Address addr_;
315 : uint8_t plen_;
316 : bool stale_;
317 : bool dump_table_;
318 : };
319 :
320 : class AgentInet4McRtSandesh : public AgentSandesh {
321 : public:
322 0 : AgentInet4McRtSandesh(VrfEntry *vrf, std::string context, std::string name,
323 : bool stale)
324 0 : : AgentSandesh(context, name), vrf_(vrf), stale_(stale) {
325 0 : dump_table_ = true;
326 0 : }
327 0 : AgentInet4McRtSandesh(VrfEntry *vrf, std::string context, std::string name,
328 : Ip4Address src_addr, Ip4Address grp_addr,
329 : bool stale)
330 0 : : AgentSandesh(context, name), vrf_(vrf), src_addr_(src_addr),
331 0 : grp_addr_(grp_addr), stale_(stale) {
332 0 : dump_table_ = false;
333 0 : }
334 :
335 : private:
336 : DBTable *AgentGetTable();
337 : void Alloc();
338 : bool UpdateResp(DBEntryBase *entry);
339 :
340 : VrfEntry *vrf_;
341 : Ip4Address src_addr_;
342 : Ip4Address grp_addr_;
343 : bool stale_;
344 : bool dump_table_;
345 : };
346 :
347 : class AgentLayer2RtSandesh : public AgentSandesh {
348 : public:
349 0 : AgentLayer2RtSandesh(VrfEntry *vrf, std::string context, std::string name,
350 : bool stale)
351 0 : : AgentSandesh(context, name), vrf_(vrf), stale_(stale) {}
352 :
353 : private:
354 : DBTable *AgentGetTable();
355 : void Alloc();
356 : bool UpdateResp(DBEntryBase *entry);
357 :
358 : VrfEntry *vrf_;
359 : bool stale_;
360 : };
361 :
362 : class AgentBridgeRtSandesh : public AgentSandesh {
363 : public:
364 0 : AgentBridgeRtSandesh(VrfEntry *vrf, std::string context, std::string name,
365 : bool stale, std::string mac)
366 0 : : AgentSandesh(context, name), vrf_(vrf), stale_(stale), mac_(mac) {}
367 :
368 : private:
369 : DBTable *AgentGetTable();
370 : void Alloc();
371 : bool UpdateResp(DBEntryBase *entry);
372 :
373 : VrfEntry *vrf_;
374 : bool stale_;
375 : std::string mac_;
376 : };
377 :
378 : class AgentEvpnRtSandesh : public AgentSandesh {
379 : public:
380 0 : AgentEvpnRtSandesh(VrfEntry *vrf, std::string context, std::string name,
381 : bool stale)
382 0 : : AgentSandesh(context, name), vrf_(vrf), stale_(stale) {}
383 :
384 : private:
385 : DBTable *AgentGetTable();
386 : void Alloc();
387 : bool UpdateResp(DBEntryBase *entry);
388 :
389 : VrfEntry *vrf_;
390 : bool stale_;
391 : };
392 :
393 : class AgentInet6UcRtSandesh : public AgentSandesh {
394 : public:
395 0 : AgentInet6UcRtSandesh(VrfEntry *vrf, std::string context, bool stale) :
396 0 : AgentSandesh(context, ""), vrf_(vrf), stale_(stale) {
397 0 : dump_table_ = true;
398 0 : }
399 0 : AgentInet6UcRtSandesh(VrfEntry *vrf, std::string context,
400 0 : Ip6Address addr, uint8_t plen, bool stale) :
401 0 : AgentSandesh(context, ""), vrf_(vrf), addr_(addr), plen_(plen),
402 0 : stale_(stale) {
403 0 : dump_table_ = false;
404 0 : }
405 :
406 : private:
407 : DBTable *AgentGetTable();
408 : void Alloc();
409 : bool UpdateResp(DBEntryBase *entry);
410 :
411 : VrfEntry *vrf_;
412 : Ip6Address addr_;
413 : uint8_t plen_;
414 : bool stale_;
415 : bool dump_table_;
416 : };
417 :
418 : class AgentAclSandesh : public AgentSandesh {
419 : public:
420 0 : AgentAclSandesh(std::string context, std::string name)
421 0 : : AgentSandesh(context, name) {}
422 :
423 : private:
424 : DBTable *AgentGetTable();
425 : void Alloc();
426 : bool UpdateResp(DBEntryBase *entry);
427 : };
428 :
429 : class AgentMirrorSandesh : public AgentSandesh {
430 : public:
431 : AgentMirrorSandesh(const std::string &context, const std::string &analyzer_name);
432 0 : ~AgentMirrorSandesh() { }
433 : virtual bool Filter(const DBEntryBase *entry);
434 : virtual bool FilterToArgs(AgentSandeshArguments *args);
435 :
436 : private:
437 : friend class MirrorEntryReq;
438 : DBTable *AgentGetTable();
439 : void Alloc();
440 :
441 : //Filters
442 : std::string analyzer_name_;
443 : };
444 :
445 : class AgentVrfAssignSandesh : public AgentSandesh {
446 : public:
447 0 : AgentVrfAssignSandesh(std::string context, std::string uuid)
448 0 : : AgentSandesh(context, uuid) {}
449 :
450 : private:
451 : DBTable *AgentGetTable();
452 : void Alloc();
453 : };
454 :
455 : class AgentVxLanSandesh : public AgentSandesh {
456 : public:
457 : AgentVxLanSandesh(const std::string &context, const std::string &vxlan_id);
458 0 : ~AgentVxLanSandesh() { }
459 : virtual bool Filter(const DBEntryBase *entry);
460 : virtual bool FilterToArgs(AgentSandeshArguments *args);
461 :
462 : private:
463 : friend class VxLanReq;
464 : DBTable *AgentGetTable();
465 : void Alloc();
466 :
467 : //Filters
468 : std::string vxlan_id_;
469 : };
470 :
471 : class AgentServiceInstanceSandesh : public AgentSandesh {
472 : public:
473 0 : AgentServiceInstanceSandesh(std::string context, std::string uuid)
474 0 : : AgentSandesh(context, uuid) {}
475 :
476 : private:
477 : DBTable *AgentGetTable();
478 : void Alloc();
479 : };
480 :
481 : class AgentLoadBalancerSandesh : public AgentSandesh {
482 : public:
483 : AgentLoadBalancerSandesh(std::string context, std::string uuid)
484 : : AgentSandesh(context, uuid) {}
485 :
486 : private:
487 : DBTable *AgentGetTable();
488 : void Alloc();
489 : };
490 :
491 : class AgentLoadBalancerV2Sandesh : public AgentSandesh {
492 : public:
493 : AgentLoadBalancerV2Sandesh(std::string context, std::string uuid)
494 : : AgentSandesh(context, uuid) {}
495 :
496 : private:
497 : DBTable *AgentGetTable();
498 : void Alloc();
499 : };
500 :
501 : class AgentHealthCheckSandesh : public AgentSandesh {
502 : public:
503 : AgentHealthCheckSandesh(const std::string &context, const std::string &u);
504 0 : ~AgentHealthCheckSandesh() {}
505 : virtual bool Filter(const DBEntryBase *entry);
506 : virtual bool FilterToArgs(AgentSandeshArguments *args);
507 :
508 : private:
509 : friend class VnListReq;
510 : DBTable *AgentGetTable();
511 : void Alloc();
512 : std::string uuid_str_;
513 :
514 : boost::uuids::uuid uuid_;
515 :
516 : };
517 :
518 : class AgentQosConfigSandesh : public AgentSandesh {
519 : public:
520 : AgentQosConfigSandesh(const std::string &context, const std::string &u,
521 : const std::string &name, const std::string &id);
522 0 : ~AgentQosConfigSandesh() {}
523 : virtual bool Filter(const DBEntryBase *entry);
524 : virtual bool FilterToArgs(AgentSandeshArguments *args);
525 :
526 : private:
527 : DBTable *AgentGetTable();
528 : void Alloc();
529 : std::string uuid_;
530 : std::string name_;
531 : std::string id_;
532 : };
533 :
534 : class ForwardingClassSandesh : public AgentSandesh {
535 : public:
536 : ForwardingClassSandesh(const std::string &context, const std::string &u,
537 : const std::string &name, const std::string &idx);
538 0 : ~ForwardingClassSandesh() {}
539 : virtual bool Filter(const DBEntryBase *entry);
540 : virtual bool FilterToArgs(AgentSandeshArguments *args);
541 :
542 : private:
543 : DBTable *AgentGetTable();
544 : void Alloc();
545 : std::string uuid_;
546 : std::string name_;
547 : std::string id_;
548 : };
549 :
550 : class QosQueueSandesh : public AgentSandesh {
551 : public:
552 : QosQueueSandesh(const std::string &context, const std::string &u,
553 : const std::string &name, const std::string &id);
554 0 : ~QosQueueSandesh() {}
555 : virtual bool Filter(const DBEntryBase *entry);
556 : virtual bool FilterToArgs(AgentSandeshArguments *args);
557 :
558 : private:
559 : DBTable *AgentGetTable();
560 : void Alloc();
561 : std::string uuid_;
562 : std::string name_;
563 : std::string id_;
564 : };
565 :
566 : class BridgeDomainSandesh : public AgentSandesh {
567 : public:
568 : BridgeDomainSandesh(const std::string &context, const std::string &u,
569 : const std::string &name);
570 0 : ~BridgeDomainSandesh() {}
571 : virtual bool Filter(const DBEntryBase *entry);
572 : virtual bool FilterToArgs(AgentSandeshArguments *args);
573 :
574 : private:
575 : DBTable *AgentGetTable();
576 : void Alloc();
577 : std::string uuid_str_;
578 : std::string name_;
579 : boost::uuids::uuid uuid_;
580 : };
581 :
582 : class AgentPolicySetSandesh : public AgentSandesh {
583 : public:
584 : AgentPolicySetSandesh(const std::string &context, const std::string &uuid,
585 : const std::string &name);
586 : virtual bool Filter(const DBEntryBase *entry);
587 : virtual bool FilterToArgs(AgentSandeshArguments *args);
588 :
589 : private:
590 : DBTable *AgentGetTable();
591 : std::string uuid_str_;
592 : std::string name_;
593 : boost::uuids::uuid uuid_;
594 : void Alloc();
595 : bool UpdateResp(DBEntryBase *entry);
596 : };
597 :
598 : class TagSandesh : public AgentSandesh {
599 : public:
600 : TagSandesh(const std::string &context, const std::string &u,
601 : const std::string &name);
602 0 : ~TagSandesh() {}
603 : virtual bool Filter(const DBEntryBase *entry);
604 : virtual bool FilterToArgs(AgentSandeshArguments *args);
605 :
606 : private:
607 : DBTable *AgentGetTable();
608 : void Alloc();
609 : std::string uuid_str_;
610 : std::string name_;
611 : boost::uuids::uuid uuid_;
612 : };
613 :
614 : class AgentSecurityLoggingObjectSandesh : public AgentSandesh {
615 : public:
616 0 : AgentSecurityLoggingObjectSandesh(const std::string &context,
617 : const std::string &uuid)
618 0 : : AgentSandesh(context, uuid) {}
619 :
620 : private:
621 : DBTable *AgentGetTable();
622 : void Alloc();
623 : };
624 :
625 : class AgentCryptTunnelSandesh : public AgentSandesh {
626 : public:
627 : AgentCryptTunnelSandesh(const std::string &context, const std::string &name);
628 : virtual bool Filter(const DBEntryBase *entry);
629 : virtual bool FilterToArgs(AgentSandeshArguments *args);
630 : private:
631 : DBTable *AgentGetTable();
632 : void Alloc();
633 : bool UpdateResp(DBEntryBase *entry);
634 : std::string remote_ip_;
635 : };
636 :
637 : class AgentMulticastPolicySandesh : public AgentSandesh {
638 : public:
639 0 : AgentMulticastPolicySandesh(const std::string &context,
640 : const std::string &uuid)
641 0 : : AgentSandesh(context, uuid) {}
642 :
643 : private:
644 : DBTable *AgentGetTable();
645 : void Alloc();
646 : bool UpdateResp(DBEntryBase *entry);
647 : };
648 :
649 : #endif // vnsw_agent_sandesh_h_
|