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