OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
mirror_table.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
3  */
4 
5 #include <boost/bind.hpp>
6 #include <base/logging.h>
7 #include <db/db.h>
8 #include <db/db_entry.h>
9 #include <db/db_table.h>
10 
11 #include <cmn/agent_cmn.h>
12 #include <init/agent_param.h>
13 #include "oper/route_common.h"
14 #include "oper/nexthop.h"
15 #include "oper/tunnel_nh.h"
16 #include "oper/vrf.h"
17 #include "oper/mirror_table.h"
18 #include "oper/agent_sandesh.h"
20 using namespace std;
21 using namespace boost::asio;
23 
25  boost::system::error_code err;
26  if (udp_sock_.get()) {
27  udp_sock_->close(err);
28  }
29 }
30 
31 bool MirrorEntry::IsLess(const DBEntry &rhs) const {
32  const MirrorEntry &a = static_cast<const MirrorEntry &>(rhs);
33  return (analyzer_name_ < a.GetAnalyzerName());
34 }
35 
37  MirrorEntryKey *key = new MirrorEntryKey(analyzer_name_);
38  return DBEntryBase::KeyPtr(key);
39 }
40 
42  const MirrorEntryKey *key = static_cast<const MirrorEntryKey *>(k);
43  analyzer_name_ = key->analyzer_name_;
44 }
45 
46 std::unique_ptr<DBEntry> MirrorTable::AllocEntry(const DBRequestKey *k) const {
47  const MirrorEntryKey *key = static_cast<const MirrorEntryKey *>(k);
48  MirrorEntry *mirror_entry = new MirrorEntry(key->analyzer_name_);
49  return std::unique_ptr<DBEntry>(static_cast<DBEntry *>(mirror_entry));
50 }
51 
53  const MirrorEntryKey *key = static_cast<const MirrorEntryKey *>(req->key.get());
54  MirrorEntry *mirror_entry = new MirrorEntry(key->analyzer_name_);
56  (agent()->resource_manager(),
57  key->analyzer_name_));
58  uint32_t index = static_cast<IndexResourceData *>
59  (agent()->resource_manager()->Allocate(rkey).get())->index();
60  mirror_entry->set_mirror_index(index);
61  //Get Mirror NH
62  OnChange(mirror_entry, req);
63  return mirror_entry;
64 }
65 
66 bool MirrorTable::OnChange(MirrorEntry *mirror_entry) {
67  bool ret = false;
68  NextHop *nh = NULL;
69  bool valid_nh = false;
70  if (mirror_entry->mirror_flags_ ==
72  VrfEntry *vrf = agent()->vrf_table()->FindVrfFromName(mirror_entry->vrf_name_);
73  // mirror vrf should have been created
74  if(vrf != NULL) {
75  BridgeRouteKey key(agent()->evpn_peer(), mirror_entry->vrf_name_,
76  mirror_entry->mac_);
77  BridgeRouteEntry *rt = static_cast<BridgeRouteEntry *>
78  (static_cast<BridgeAgentRouteTable *>
79  (vrf->GetBridgeRouteTable())->FindActiveEntry(&key));
80 
81  // if route entry is preset assign the active nexthop to mirror entry
82  // if route entry & active apath is not preset create discard nh
83  // and add it unresolved entry
84  if (rt != NULL) {
85  const AgentPath *path = rt->GetActivePath();
86  nh = path->nexthop();
87  if (nh != NULL) {
88  mirror_entry->vni_ = rt->GetActiveLabel();
89  AddResolvedVrfMirrorEntry(mirror_entry);
90  valid_nh = true;
91  }
92  }
93  }
94  } else { //StaticNH Without Juniper Hdr
96  agent()->fabric_inet4_unicast_table()->FindLPM(mirror_entry->dip_);
97  //if route entry is preset add the active next hop else add discard nh
98  if (rt != NULL) {
99  DBRequest nh_req;
101  // Do this only for v4, until we add support for v6
102  // Typecast on v6 would cause an exception and would
103  // assert in task.cc.
104  if (mirror_entry->sip_.is_v4() && mirror_entry->dip_.is_v4()) {
105  TunnelNHKey *nh_key =
106  new TunnelNHKey(agent()->fabric_vrf_name(),
107  mirror_entry->sip_.to_v4(),
108  mirror_entry->dip_.to_v4(),
109  false, TunnelType::VXLAN);
110  nh_req.key.reset(nh_key);
111  nh_req.data.reset(NULL);
112  agent()->nexthop_table()->Process(nh_req);
113  nh = static_cast<NextHop *>
114  (agent()->nexthop_table()->FindActiveEntry(nh_key));
115  if (nh != NULL) {
116  valid_nh = true;
117  AddResolvedVrfMirrorEntry(mirror_entry);
118  }
119  }
120  }
121  }
122 
123  // if there is no Valid nh point it to discard nh
124  if (!valid_nh) {
125  DiscardNH key;
126  nh = static_cast<NextHop *>
127  (agent()->nexthop_table()->FindActiveEntry(&key));
128  AddUnresolved(mirror_entry);
129  }
130 
131  if (mirror_entry->nh_ != nh) {
132  ret = true;
133  mirror_entry->nh_ = nh;
134  }
135  return ret;
136 }
137 
138 bool MirrorTable::OnChange(DBEntry *entry, const DBRequest *req) {
139  bool ret = false;
140  bool vrf_changed = false;
141  MirrorEntry *mirror_entry = static_cast<MirrorEntry *>(entry);
142  MirrorEntryData *data = static_cast<MirrorEntryData *>(req->data.get());
143 
144  // Check for nic assisted supported ignore creating NH.
145  // if there is any change from non nic to nic assited mirroring.
146  // delete if there are any previously allocated resources for mirror entry.
147  if (data->nic_assisted_mirroring_ !=
148  mirror_entry->nic_assisted_mirroring_) {
149  if (!mirror_entry->nic_assisted_mirroring_) {
150  DeleteMirrorVrf(mirror_entry, true);
151  mirror_entry->nh_ = NULL;
152  mirror_entry->vrf_ = NULL;
153  }
154  mirror_entry->nic_assisted_mirroring_ =
156  mirror_entry->nic_assisted_mirroring_vlan_ =
158  if (mirror_entry->nic_assisted_mirroring_)
159  return true;
160  } else if (data->nic_assisted_mirroring_){
161  mirror_entry->nic_assisted_mirroring_vlan_ =
163  return true;
164  }
165 
166  if (mirror_entry->vrf_name_ != data->vrf_name_) {
167  vrf_changed = true;
168  }
169  if (vrf_changed || (mirror_entry->mirror_flags_ != data->mirror_flags_)) {
170  DeleteMirrorVrf(mirror_entry, vrf_changed);
171  mirror_entry->vrf_name_ = data->vrf_name_;
172  }
173 
174  mirror_entry->sip_ = data->sip_;
175  mirror_entry->sport_ = data->sport_;
176  mirror_entry->dip_ = data->dip_;
177  mirror_entry->dport_ = data->dport_;
178  mirror_entry->mirror_flags_ = data->mirror_flags_;
179  // Check for any Vxlan changes.
180  if (mirror_entry->vni_ != data->vni_) {
181  mirror_entry->vni_ = data->vni_;
182  ret = true;
183  }
184  mirror_entry->mac_ = data->mac_;
185  if (!mirror_entry->createdvrf_) {
186  mirror_entry->createdvrf_ = data->createdvrf_;
187  }
190  {
191  ret |= OnChange(mirror_entry);
192  return ret;
193  }
194 
195  DBRequest nh_req;
197  MirrorNHKey *nh_key = new MirrorNHKey(data->vrf_name_, data->sip_,
198  data->sport_, data->dip_, data->dport_);
199  nh_req.key.reset(nh_key);
200  nh_req.data.reset(NULL);
201  agent()->nexthop_table()->Process(nh_req);
202 
203  /* For service-chain based mirroring, vrf will always be empty. In this
204  * case we should create MirrorNH even when VRF is NULL */
205  bool check_for_vrf = false;
206  VrfEntry *vrf = NULL;
207  if (!data->vrf_name_.empty()) {
208  VrfKey key(data->vrf_name_);
209  vrf = static_cast<VrfEntry *>(agent()->vrf_table()->
210  FindActiveEntry(&key));
211  check_for_vrf = true;
212  }
213 
214  NextHop *nh = static_cast<NextHop *>
215  (agent()->nexthop_table()->FindActiveEntry(nh_key));
216  if (nh == NULL || (check_for_vrf && vrf == NULL)) {
217  //Make the mirror NH point to discard
218  //and change the nexthop once the VRF is
219  //available
220  AddUnresolved(mirror_entry);
221  DiscardNH key;
222  nh = static_cast<NextHop *>
223  (agent()->nexthop_table()->FindActiveEntry(&key));
224  } else {
225  AddResolvedVrfMirrorEntry(mirror_entry);
226  }
227 
228  if (mirror_entry->nh_ != nh) {
229  mirror_entry->nh_ = nh;
230  mirror_entry->vrf_ =
231  agent()->vrf_table()->FindVrfFromName(data->vrf_name_);
232  ret = true;
233  }
234  return ret;
235 }
236 
237 bool MirrorTable::Delete(DBEntry *entry, const DBRequest *request) {
238  MirrorEntry *mirror_entry = static_cast<MirrorEntry *>(entry);
239  agent()->resource_manager()->Release(Resource::MIRROR_INDEX,
240  mirror_entry->mirror_index());
241  DeleteMirrorVrf(mirror_entry, true);
242  return true;
243 }
244 
245 void MirrorTable::DeleteMirrorVrf(MirrorEntry *entry, bool del_from_vrf_list) {
246  if (del_from_vrf_list) {
247  RemoveUnresolved(entry);
248  DeleteResolvedVrfMirrorEntry(entry);
249  }
251  VrfEntry *vrf =
252  agent()->vrf_table()->FindVrfFromName(entry->vrf_name_);
253  if (vrf) {
254  bool confvrf = vrf->flags() & VrfData::ConfigVrf;
255  bool gwvrf = vrf->flags() & VrfData::GwVrf;
256  if (entry->createdvrf_ && !confvrf && !gwvrf)
257  agent()->vrf_table()->DeleteVrfReq(entry->vrf_name_,
259  }
260  }
261 }
262 
263 void MirrorTable::Add(VrfMirrorEntryList &vrf_entry_map, MirrorEntry *entry) {
264  VrfMirrorEntryList::iterator it = vrf_entry_map.find(entry->vrf_name_);
265 
266  if (it != vrf_entry_map.end()) {
267  MirrorEntryList::const_iterator list_it = it->second.begin();
268  for (; list_it != it->second.end(); list_it++) {
269  if (*list_it == entry) {
270  //Entry already present
271  return;
272  }
273  }
274  it->second.push_back(entry);
275  return;
276  }
277 
278  MirrorEntryList list;
279  list.push_back(entry);
280  vrf_entry_map.insert(VrfMirrorEntry(entry->vrf_name_, list));
281 }
282 
284  VrfMirrorEntryList::iterator it = list.find(entry->vrf_name_);
285  if (it == list.end()) {
286  return;
287  }
288 
289  MirrorEntryList::iterator list_it = it->second.begin();
290  for(;list_it != it->second.end(); list_it++) {
291  if (*list_it == entry) {
292  it->second.erase(list_it);
293  break;
294  }
295  }
296 }
297 
299  const VrfEntry *vrf) {
300  VrfMirrorEntryList::iterator it = list.find(vrf->GetName());
301  if (it == list.end()) {
302  return;
303  }
304 
305  MirrorEntryList::iterator list_it = it->second.begin();
306  for(;list_it != it->second.end(); list_it++) {
307  DBRequest req;
309 
310  MirrorEntryKey *key = new MirrorEntryKey((*list_it)->GetAnalyzerName());
311  key->sub_op_ = AgentKey::RESYNC;
312  MirrorEntryData *data = new MirrorEntryData((*list_it)->vrf_name(),
313  *((*list_it)->GetSip()),
314  (*list_it)->GetSPort(),
315  *((*list_it)->GetDip()),
316  (*list_it)->GetDPort(), (*list_it)->GetMirrorFlag(),
317  (*list_it)->GetVni(), *((*list_it)->GetMac()),
318  (*list_it)->GetCreatedVrf());
319  req.key.reset(key);
320  req.data.reset(data);
321  Enqueue(&req);
322  }
323  list.erase(it);
324 }
325 
327  Add(unresolved_entry_list_, entry);
328 }
329 
331  Delete(unresolved_entry_list_, entry);
332 }
333 
335  Add(resolved_entry_list_, entry);
336 }
337 
339  Delete(resolved_entry_list_, entry);
340 }
341 
343  ResyncMirrorEntry(resolved_entry_list_, vrf);
344 }
345 
347  ResyncMirrorEntry(unresolved_entry_list_, vrf);
348 }
349 
350 
351 void MirrorTable::AddMirrorEntry(const std::string &analyzer_name,
352  const std::string &vrf_name,
353  const IpAddress &sip, uint16_t sport,
354  const IpAddress &dip, uint16_t dport,
355  uint32_t vni, uint8_t mirror_flag,
356  const MacAddress &mac) {
357  Agent *agent = Agent::GetInstance();
358  bool createdvrf = false;
359  DBRequest req;
360 
361  if (dip.is_v6() && vrf_name == mirror_table_->agent()->fabric_vrf_name()) {
362  LOG(ERROR, "Ipv6 as destination not supported on Fabric VRF: " <<
363  dip.to_string());
364  return;
365  }
366  // if Mirror VRF is not preset create the vrf.
367  // creatation of VRF ensures all the routes will be dowloaded from control node.
369  VrfEntry *vrf = agent->vrf_table()->FindVrfFromName(vrf_name);
370  if (vrf == NULL) {
371  agent->vrf_table()->CreateVrfReq(vrf_name, VrfData::MirrorVrf);
372  createdvrf = true;
373  }
374  }
375  MirrorEntryKey *key = new MirrorEntryKey(analyzer_name);
376  MirrorEntryData *data = new MirrorEntryData(vrf_name, sip, sport, dip,
377  dport, mirror_flag, vni, mac,
378  createdvrf);
380  req.key.reset(key);
381  req.data.reset(data);
382  mirror_table_->Enqueue(&req);
383 }
384 
385 void MirrorTable::AddMirrorEntry(const std::string &analyzer_name,
386  const std::string &vrf_name,
387  const IpAddress &sip, uint16_t sport,
388  const IpAddress &dip, uint16_t dport) {
389 
390  DBRequest req;
391 
392  if (dip.is_v6() && vrf_name == mirror_table_->agent()->fabric_vrf_name()) {
393  LOG(ERROR, "Ipv6 as destination not supported on Fabric VRF: " <<
394  dip.to_string());
395  return;
396  }
397  // First enqueue request to add Mirror NH
399 
400  MirrorNHKey *nh_key = new MirrorNHKey(vrf_name, sip, sport, dip, dport);
401  req.key.reset(nh_key);
402  req.data.reset(NULL);
403  mirror_table_->agent()->nexthop_table()->Enqueue(&req);
404 
406  MirrorEntryKey *key = new MirrorEntryKey(analyzer_name);
407  MirrorEntryData *data = new MirrorEntryData(vrf_name, sip,
408  sport, dip, dport, 1, 0 ,
409  MacAddress::ZeroMac(), false);
410  req.key.reset(key);
411  req.data.reset(data);
412  mirror_table_->Enqueue(&req);
413 }
414 
415 void MirrorTable::AddMirrorEntry(const std::string &analyzer_name,
416  uint32_t nic_assisted_mirroring_vlan) {
417  DBRequest req;
419  MirrorEntryKey *key = new MirrorEntryKey(analyzer_name);
420  MirrorEntryData *data = new MirrorEntryData(true, nic_assisted_mirroring_vlan);
421  req.key.reset(key);
422  req.data.reset(data);
423  mirror_table_->Enqueue(&req);
424 }
425 
426 
427 void MirrorTable::DelMirrorEntry(const std::string &analyzer_name) {
428  DBRequest req;
430  MirrorEntryKey *key = new MirrorEntryKey(analyzer_name);
431  req.key.reset(key);
432  req.data.reset(NULL);
433  mirror_table_->Enqueue(&req);
434 }
435 
437  const MirrorEntry *mirr_entry = static_cast<const MirrorEntry *>(e);
438  DelMirrorEntry(mirr_entry->GetAnalyzerName());
439 }
440 
441 DBTableBase *MirrorTable::CreateTable(DB *db, const std::string &name) {
442  mirror_table_ = new MirrorTable(db, name);
443  mirror_table_->Init();
444  return mirror_table_;
445 };
446 
448  VrfListenerInit();
449 }
450 
452  vrf_listener_id_ = agent()->vrf_table()->
453  Register(boost::bind(&MirrorTable::VrfNotify,
454  this, _1, _2));
455 }
456 
458  VrfEntry *vrf = static_cast<VrfEntry *>(entry);
459  MirrorVrfState *state = static_cast<MirrorVrfState *>
460  (vrf->GetState(base->parent(), vrf_listener_id_));
461  if (vrf->IsDeleted()) {
462  if (state) {
463  UnRegisterBridgeRouteTableListener(vrf, state);
464  vrf->ClearState(base->parent(), vrf_listener_id_);
465  delete state;
466  }
467  //VRF is getting deleted remove all the mirror nexthop
468  ResyncResolvedMirrorEntry(vrf);
469  return;
470  }
471 
472  // This will be for dynamic witout juniper header, to resolve the
473  // bridge entry lookup
474  bool miror_vrf = UnresolvedMirrorVrf(vrf, unresolved_entry_list_);
475  if (state == NULL && miror_vrf) {
476  state = new MirrorVrfState();
477  state->seen_ = true;
478  vrf->SetState(base->parent(), vrf_listener_id_, state);
480  BridgeAgentRouteTable *bridge_table =
481  static_cast<BridgeAgentRouteTable *>
482  (vrf->GetBridgeRouteTable());
484  bridge_table->Register(boost::bind(&MirrorTable::BridgeRouteTableNotify,
485  this, _1, _2));
486  }
487  }
488  ResyncUnresolvedMirrorEntry(vrf);
489 }
490 
492  VrfMirrorEntryList &list){
493  VrfMirrorEntryList::iterator it = list.find(vrf->GetName());
494  if (it == list.end()) {
495  return false;
496  }
497  // Need to check if there are any entries with DynamicNH_Without_JuniperHdr
498  MirrorEntryList::iterator list_it = it->second.begin();
499  for(;list_it != it->second.end(); list_it++) {
500  if ((*list_it)->GetMirrorFlag() ==
502  return true;
503  }
504  }
505  return false;
506 }
507 // if the Unresolved remote mac is present it will return the entry
510  VrfMirrorEntryList &list) {
511  VrfMirrorEntryList::iterator it = list.find(vrf->GetName());
512  if (it == list.end()) {
513  return NULL;
514  }
515  MirrorEntryList::iterator list_it = it->second.begin();
516  for(;list_it != it->second.end(); list_it++) {
517  const MacAddress &remote_vm_mac = *((*list_it)->GetMac());
518  if (remote_vm_mac == mac) {
519  return (*list_it);
520  }
521  }
522  return NULL;
523 }
524 
525 
527  DBEntryBase *entry) {
528  const BridgeRouteEntry *bridge_rt = static_cast<const BridgeRouteEntry *>(entry);
529  if (bridge_rt->IsDeleted()) {
530  ResyncResolvedMirrorEntry(bridge_rt->vrf());
531  } else {
532  MirrorEntry *unresolved_mirror_entry = GetMirrorEntry(bridge_rt->vrf(),
533  bridge_rt->prefix_address(),
534  unresolved_entry_list_);
535  MirrorEntry *resolved_mirror_entry = GetMirrorEntry(bridge_rt->vrf(),
536  bridge_rt->prefix_address(),
537  resolved_entry_list_);
538  // Check for Both resolved and unresolved list for Change in route
539  if (unresolved_mirror_entry &&
540  unresolved_mirror_entry->mirror_flags_ ==
542  ResyncUnresolvedMirrorEntry(bridge_rt->vrf());
543  } else if (resolved_mirror_entry &&
544  ((resolved_mirror_entry->vni_ != bridge_rt->GetActiveLabel()) ||
545  (resolved_mirror_entry->nh_ !=
546  bridge_rt->GetActivePath()->nexthop()))) {
547  ResyncResolvedMirrorEntry(bridge_rt->vrf());
548  }
549  }
550 }
551 
553  MirrorVrfState *state) {
555  return;
556  BridgeAgentRouteTable *bridge_table = static_cast<BridgeAgentRouteTable *>
557  (vrf->GetBridgeRouteTable());
558  bridge_table->Unregister(state->bridge_rt_table_listener_id_);
560 }
561 
562 void MirrorTable::ReadHandler(const boost::system::error_code &ec,
563  size_t bytes_transferred) {
564 
565  if (ec) {
566  LOG(ERROR, "Error reading from Mirror sock. Error : " <<
567  boost::system::system_error(ec).what());
568  return;
569  }
570 
571  udp_sock_->async_receive(boost::asio::buffer(rx_buff_, sizeof(rx_buff_)),
572  boost::bind(&MirrorTable::ReadHandler, this,
573  boost::asio::placeholders::error,
574  boost::asio::placeholders::bytes_transferred));
575 }
576 
578  EventManager *event_mgr;
579 
580  event_mgr = agent()->event_manager();
581  boost::asio::io_service &io = *event_mgr->io_service();
582  ip::udp::endpoint ep(ip::udp::v4(),
583  agent()->params()->mirror_client_port());
584 
585  udp_sock_.reset(new ip::udp::socket(io));
586 
587  boost::system::error_code ec;
588  udp_sock_->open(ip::udp::v4(), ec);
589  assert(ec.value() == 0);
590 
591  udp_sock_->bind(ep, ec);
592  if (ec.value() != 0) {
593  ep.port(0);
594  udp_sock_->bind(ep, ec);
595  assert(ec.value() == 0);
596  }
597 
598  ip::udp::endpoint sock_ep = udp_sock_->local_endpoint(ec);
599  assert(ec.value() == 0);
600  agent()->set_mirror_port(sock_ep.port());
601 
602  udp_sock_->async_receive(boost::asio::buffer(rx_buff_, sizeof(rx_buff_)),
603  boost::bind(&MirrorTable::ReadHandler, this,
604  boost::asio::placeholders::error,
605  boost::asio::placeholders::bytes_transferred));
606 }
607 
608 VrfEntry *MirrorTable::FindVrfEntry(const string &vrf_name) const {
609  return agent()->vrf_table()->FindVrfFromName(vrf_name);
610 }
611 
613  agent()->vrf_table()->Unregister(vrf_listener_id_);
614 }
615 
617  VrfMirrorEntryList::iterator it;
618  for (it = resolved_entry_list_.begin(); it != resolved_entry_list_.end(); ++it) {
619  if (it->second.size() > 0) {
620  return true;
621  }
622  }
623  return false;
624 }
625 
626 uint32_t MirrorEntry::vrf_id() const {
627  return vrf_ ? vrf_->vrf_id() : uint32_t(-1);
628 }
629 
631  return vrf_ ? vrf_.get() : NULL;
632 }
633 
634 void MirrorEntry::set_mirror_entrySandeshData(MirrorEntrySandeshData &data) const {
635  data.set_analyzer_name(GetAnalyzerName());
636  data.set_sip(GetSip()->to_string());
637  data.set_dip(GetDip()->to_string());
638  data.set_vrf(GetVrf() ? GetVrf()->GetName() : "");
639  data.set_sport(GetSPort());
640  data.set_dport(GetDPort());
641  data.set_ref_count(GetRefCount());
642  if (nh_) {
643  nh_->SetNHSandeshData(data.nh);
644  }
645 }
646 
647 bool MirrorEntry::DBEntrySandesh(Sandesh *sresp, std::string &name) const {
648  MirrorEntryResp *resp = static_cast<MirrorEntryResp *>(sresp);
649 
650  MirrorEntrySandeshData data;
651  set_mirror_entrySandeshData(data);
652  std::vector<MirrorEntrySandeshData> &list =
653  const_cast<std::vector<MirrorEntrySandeshData>&>
654  (resp->get_mirror_entry_list());
655  list.push_back(data);
656 
657  return true;
658 }
659 
660 void MirrorEntryReq::HandleRequest() const {
661  AgentSandeshPtr sand(new AgentMirrorSandesh(context(), get_analyzer_name()));
662  sand->DoSandesh(sand);
663 }
664 
666  const std::string &context) {
667  return AgentSandeshPtr(new AgentMirrorSandesh(context,
668  args->GetString("analyzer_name")));
669 }
670 
672 MirrorTable::DecodeMirrorFlag (const std::string &nh_mode, bool juniper_header) {
673  std::string str = "static";
674  if (juniper_header) {
675  if (boost::iequals(nh_mode, str))
678  } else {
679  if (boost::iequals(nh_mode, str))
682  }
683 }
static const MacAddress & ZeroMac()
Definition: mac_address.h:158
virtual std::unique_ptr< DBEntry > AllocEntry(const DBRequestKey *k) const
Definition: mirror_table.cc:46
void CreateVrfReq(const string &name, uint32_t flags=VrfData::ConfigVrf)
Definition: vrf.cc:939
static Agent * GetInstance()
Definition: agent.h:436
Definition: vrf.h:86
MacAddress mac_
Definition: mirror_table.h:106
DBState * GetState(DBTableBase *tbl_base, ListenerId listener) const
Definition: db_entry.cc:37
IpAddress dip_
Definition: mirror_table.h:46
std::string GetString(const std::string &key) const
VrfEntry * FindVrfFromName(const string &name)
Definition: vrf.cc:873
void ReadHandler(const boost::system::error_code &error, size_t bytes)
uint32_t vni_
Definition: mirror_table.h:105
IpAddress sip_
Definition: mirror_table.h:44
bool createdvrf_
Definition: mirror_table.h:109
VrfEntryRef vrf_
Definition: mirror_table.h:97
bool nic_assisted_mirroring_
Definition: mirror_table.h:52
bool IsConfigured()
bool IsDeleted() const
Definition: db_entry.h:49
void SetState(DBTableBase *tbl_base, ListenerId listener, DBState *state)
Definition: db_entry.cc:22
boost::asio::ip::address IpAddress
Definition: address.h:13
uint8_t sub_op_
Definition: agent_db.h:106
uint16_t sport_
Definition: mirror_table.h:99
void DeleteResolvedVrfMirrorEntry(MirrorEntry *entry)
std::unique_ptr< DBRequestData > data
Definition: db_table.h:49
boost::shared_ptr< ResourceKey > KeyPtr
uint32_t vrf_id() const
boost::asio::io_context * io_service()
Definition: event_manager.h:42
void ResyncResolvedMirrorEntry(const VrfEntry *vrf)
DBTableBase * parent()
std::map< std::string, MirrorEntryList > VrfMirrorEntryList
Definition: mirror_table.h:121
const string & GetName() const
Definition: vrf.h:100
std::unique_ptr< DBRequestKey > KeyPtr
Definition: db_entry.h:25
void BridgeRouteTableNotify(DBTablePartBase *partition, DBEntryBase *e)
void AddResolvedVrfMirrorEntry(MirrorEntry *entry)
void Unregister(ListenerId listener)
Definition: db_table.cc:186
uint16_t nic_assisted_mirroring_vlan_
Definition: mirror_table.h:111
void MirrorSockInit(void)
virtual void OnZeroRefcount(AgentDBEntry *e)
ListenerId Register(ChangeCallback callback, const std::string &name="unspecified")
Definition: db_table.cc:181
Definition: db.h:24
const AgentPath * GetActivePath() const
Definition: agent_route.cc:876
NextHop * nexthop() const
Definition: agent_path.cc:87
DBTableBase::ListenerId bridge_rt_table_listener_id_
Definition: mirror_table.h:177
Definition: agent.h:358
Definition: vrf.h:22
void Initialize()
const VrfEntry * GetVrf() const
std::pair< std::string, MirrorEntryList > VrfMirrorEntry
Definition: mirror_table.h:122
std::unique_ptr< DBRequestKey > key
Definition: db_table.h:48
virtual ~MirrorTable()
Definition: mirror_table.cc:24
DBOperation oper
Definition: db_table.h:42
AgentRouteTable * GetBridgeRouteTable() const
Definition: vrf.cc:334
uint8_t mirror_flags_
Definition: mirror_table.h:104
class boost::shared_ptr< AgentSandesh > AgentSandeshPtr
Definition: agent_db.h:18
static MirrorEntryData::MirrorEntryFlags DecodeMirrorFlag(const std::string &nh_mode, bool juniper_header)
void DeleteMirrorVrf(MirrorEntry *entry, bool del_from_vrf_list)
void VrfListenerInit()
virtual bool IsLess(const DBEntry &rhs) const
Definition: mirror_table.cc:31
IpAddress sip_
Definition: mirror_table.h:98
void ClearState(DBTableBase *tbl_base, ListenerId listener)
Definition: db_entry.cc:73
MacAddress mac_
Definition: mirror_table.h:50
VrfEntry * FindVrfEntry(const std::string &vrf_name) const
virtual AgentSandeshPtr GetAgentSandesh(const AgentSandeshArguments *args, const std::string &context)
static void DelMirrorEntry(const std::string &analyzer_name)
virtual const PrefixType & prefix_address() const
Returns the value of a stored prefix address (IPv4, IPv6 or MAC address)
Definition: agent_route.h:375
uint16_t dport_
Definition: mirror_table.h:47
static void AddMirrorEntry(const std::string &analyzer_name, const std::string &vrf_name, const IpAddress &sip, uint16_t sport, const IpAddress &dip, uint16_t dport)
VrfTable * vrf_table() const
Definition: agent.h:485
void set_mirror_entrySandeshData(MirrorEntrySandeshData &data) const
virtual DBEntry * Add(const DBRequest *req)
Definition: mirror_table.cc:52
uint32_t mirror_index() const
Definition: mirror_table.h:94
bool nic_assisted_mirroring_
Definition: mirror_table.h:110
void RemoveUnresolved(MirrorEntry *entry)
void ResyncUnresolvedMirrorEntry(const VrfEntry *vrf)
uint8_t mirror_flags_
Definition: mirror_table.h:48
std::vector< MirrorEntry * > MirrorEntryList
Definition: mirror_table.h:120
bool UnresolvedMirrorVrf(const VrfEntry *vrf, VrfMirrorEntryList &list)
static const int kInvalidId
Definition: db_table.h:64
std::string vrf_name_
Definition: mirror_table.h:103
bool DBEntrySandesh(Sandesh *sresp, std::string &name) const
void VrfNotify(DBTablePartBase *root, DBEntryBase *entry)
#define LOG(_Level, _Msg)
Definition: logging.h:33
VrfEntry * vrf() const
Definition: agent_route.h:275
virtual bool Delete(DBEntry *entry, const DBRequest *request)
const std::string GetAnalyzerName() const
Definition: mirror_table.h:77
static DBTableBase * CreateTable(DB *db, const std::string &name)
void AddUnresolved(MirrorEntry *entry)
void set_mirror_index(uint32_t index)
Definition: mirror_table.h:93
uint16_t sport_
Definition: mirror_table.h:45
void UnRegisterBridgeRouteTableListener(const VrfEntry *entry, MirrorVrfState *state)
static MirrorTable * mirror_table_
Definition: mirror_table.h:191
uint32_t flags() const
Definition: vrf.h:108
virtual KeyPtr GetDBRequestKey() const
Definition: mirror_table.cc:36
virtual bool OnChange(DBEntry *entry, const DBRequest *req)
std::string analyzer_name_
Definition: mirror_table.h:16
void ResyncMirrorEntry(VrfMirrorEntryList &list, const VrfEntry *vrf)
IpAddress dip_
Definition: mirror_table.h:100
void Shutdown()
virtual void SetKey(const DBRequestKey *key)
Definition: mirror_table.cc:41
uint16_t nic_assisted_mirroring_vlan_
Definition: mirror_table.h:53
MirrorEntry * GetMirrorEntry(VrfEntry *vrf, const MacAddress &mac, VrfMirrorEntryList &list)
uint16_t dport_
Definition: mirror_table.h:101
std::string vrf_name_
Definition: mirror_table.h:43
NextHopRef nh_
Definition: mirror_table.h:102
virtual uint32_t GetActiveLabel() const