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