/
bridge_route.cc
780 lines (695 loc) · 30.6 KB
/
bridge_route.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
/*
* Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
*/
#include <boost/uuid/uuid_io.hpp>
#include <cmn/agent_cmn.h>
#include <route/route.h>
#include <oper/route_common.h>
#include <oper/vrf.h>
#include <oper/tunnel_nh.h>
#include <oper/mpls.h>
#include <oper/mirror_table.h>
#include <controller/controller_export.h>
#include <controller/controller_peer.h>
#include <oper/agent_sandesh.h>
using namespace std;
using namespace boost::asio;
/////////////////////////////////////////////////////////////////////////////
// Utility functions
/////////////////////////////////////////////////////////////////////////////
static void BridgeTableEnqueue(Agent *agent, DBRequest *req) {
AgentRouteTable *table = agent->fabric_l2_unicast_table();
if (table) {
table->Enqueue(req);
}
}
static void BridgeTableProcess(Agent *agent, const string &vrf_name,
DBRequest &req) {
AgentRouteTable *table =
agent->vrf_table()->GetBridgeRouteTable(vrf_name);
if (table) {
table->Process(req);
}
}
/////////////////////////////////////////////////////////////////////////////
// BridgeRouteKey methods
/////////////////////////////////////////////////////////////////////////////
string BridgeRouteKey::ToString() const {
return dmac_.ToString();
}
BridgeRouteKey *BridgeRouteKey::Clone() const {
return new BridgeRouteKey(peer_, vrf_name_, dmac_);
}
AgentRoute *
BridgeRouteKey::AllocRouteEntry(VrfEntry *vrf, bool is_multicast) const
{
BridgeRouteEntry *entry = new BridgeRouteEntry(vrf, dmac_,
peer()->GetType(),
is_multicast);
return static_cast<AgentRoute *>(entry);
}
/////////////////////////////////////////////////////////////////////////////
// BridgeAgentRouteTable methods
/////////////////////////////////////////////////////////////////////////////
DBTableBase *BridgeAgentRouteTable::CreateTable(DB *db,
const std::string &name) {
AgentRouteTable *table = new BridgeAgentRouteTable(db, name);
table->Init();
return table;
}
BridgeRouteEntry *BridgeAgentRouteTable::FindRoute(const MacAddress &mac) {
BridgeRouteKey key(agent()->local_vm_peer(), vrf_name(), mac, 0);
BridgeRouteEntry *route =
static_cast<BridgeRouteEntry *>(FindActiveEntry(&key));
return route;
}
/////////////////////////////////////////////////////////////////////////////
// BridgeAgentRouteTable utility methods to add/delete routes
/////////////////////////////////////////////////////////////////////////////
void BridgeAgentRouteTable::AddBridgeReceiveRoute(const Peer *peer,
const string &vrf_name,
const MacAddress &mac,
const string &vn_name,
const string &interface,
bool policy) {
Agent *agent = Agent::GetInstance();
DBRequest req(DBRequest::DB_ENTRY_ADD_CHANGE);
req.key.reset(new BridgeRouteKey(peer, vrf_name, mac, 0));
PacketInterfaceKey intf_key(nil_uuid(), agent->pkt_interface_name());
req.data.reset(new HostRoute(intf_key, vn_name));
BridgeTableEnqueue(agent, &req);
}
void BridgeAgentRouteTable::AddBridgeReceiveRouteReq(const Peer *peer,
const string &vrf_name,
uint32_t vxlan_id,
const MacAddress &mac,
const string &vn_name) {
DBRequest req(DBRequest::DB_ENTRY_ADD_CHANGE);
req.key.reset(new BridgeRouteKey(peer, vrf_name, mac, vxlan_id));
req.data.reset(new L2ReceiveRoute(vn_name, vxlan_id, 0));
Enqueue(&req);
}
void BridgeAgentRouteTable::AddBridgeReceiveRoute(const Peer *peer,
const string &vrf_name,
uint32_t vxlan_id,
const MacAddress &mac,
const string &vn_name) {
DBRequest req(DBRequest::DB_ENTRY_ADD_CHANGE);
req.key.reset(new BridgeRouteKey(peer, vrf_name, mac, vxlan_id));
req.data.reset(new L2ReceiveRoute(vn_name, vxlan_id, 0));
Process(req);
}
void BridgeAgentRouteTable::AddBridgeRoute(const AgentRoute *rt) {
const EvpnRouteEntry *evpn_rt =
static_cast<const EvpnRouteEntry *>(rt);
DBRequest req(DBRequest::DB_ENTRY_ADD_CHANGE);
req.key.reset(new BridgeRouteKey(agent()->evpn_peer(),
evpn_rt->vrf()->GetName(),
evpn_rt->mac(), 0));
req.data.reset(new EvpnDerivedPathData(evpn_rt));
BridgeTableProcess(agent(), vrf_name(), req);
}
void BridgeAgentRouteTable::AddOvsPeerMulticastRoute(const Peer *peer,
uint32_t vxlan_id,
const std::string &vn_name,
Ip4Address tsn,
Ip4Address tor_ip) {
const VrfEntry *vrf = vrf_entry();
DBRequest nh_req(DBRequest::DB_ENTRY_ADD_CHANGE);
nh_req.key.reset(new TunnelNHKey(vrf->GetName(), tsn, tor_ip,
false, TunnelType::VXLAN));
nh_req.data.reset(new TunnelNHData());
DBRequest req(DBRequest::DB_ENTRY_ADD_CHANGE);
req.key.reset(new BridgeRouteKey(peer,
vrf->GetName(),
MacAddress::BroadcastMac(),
vxlan_id));
req.data.reset(new MulticastRoute(vn_name, 0, vxlan_id,
TunnelType::VxlanType(),
nh_req, Composite::L2COMP));
BridgeTableProcess(agent(), vrf_name(), req);
}
void BridgeAgentRouteTable::AddMacVmBindingRoute(const Peer *peer,
const std::string &vrf_name,
const MacAddress &mac,
const VmInterface *vm_intf) {
DBRequest req(DBRequest::DB_ENTRY_ADD_CHANGE);
req.key.reset(new BridgeRouteKey(peer, vrf_name, mac, 0));
req.data.reset(new MacVmBindingPathData(vm_intf));
BridgeTableProcess(agent(), vrf_name, req);
}
void BridgeAgentRouteTable::DeleteMacVmBindingRoute(const Peer *peer,
const std::string &vrf_name,
const MacAddress &mac,
const VmInterface *vm_intf) {
DBRequest req(DBRequest::DB_ENTRY_DELETE);
req.key.reset(new BridgeRouteKey(peer, vrf_name, mac, 0));
req.data.reset(new MacVmBindingPathData(vm_intf));
BridgeTableProcess(agent(), vrf_name, req);
}
void BridgeAgentRouteTable::DeleteBridgeRoute(const AgentRoute *rt) {
const EvpnRouteEntry *evpn_rt =
static_cast<const EvpnRouteEntry *>(rt);
DBRequest req(DBRequest::DB_ENTRY_DELETE);
req.key.reset(new BridgeRouteKey(agent()->evpn_peer(),
evpn_rt->vrf()->GetName(),
evpn_rt->mac(), 0));
req.data.reset(new EvpnDerivedPathData(evpn_rt));
BridgeTableProcess(Agent::GetInstance(), evpn_rt->vrf()->GetName(), req);
}
void BridgeAgentRouteTable::DeleteReq(const Peer *peer, const string &vrf_name,
const MacAddress &mac,
uint32_t ethernet_tag) {
DBRequest req(DBRequest::DB_ENTRY_DELETE);
req.key.reset(new BridgeRouteKey(peer, vrf_name, mac, ethernet_tag));
req.data.reset(NULL);
BridgeTableEnqueue(Agent::GetInstance(), &req);
}
void BridgeAgentRouteTable::Delete(const Peer *peer, const string &vrf_name,
const MacAddress &mac,
uint32_t ethernet_tag) {
DBRequest req(DBRequest::DB_ENTRY_DELETE);
req.key.reset(new BridgeRouteKey(peer, vrf_name, mac, ethernet_tag));
req.data.reset(NULL);
BridgeTableProcess(Agent::GetInstance(), vrf_name, req);
}
void BridgeAgentRouteTable::DeleteOvsPeerMulticastRoute(const Peer *peer,
uint32_t vxlan_id) {
const VrfEntry *vrf = vrf_entry();
DBRequest req(DBRequest::DB_ENTRY_DELETE);
req.key.reset(new BridgeRouteKey(peer,
vrf->GetName(),
MacAddress::BroadcastMac(),
vxlan_id));
req.data.reset(NULL);
BridgeTableProcess(agent(), vrf->GetName(), req);
}
void BridgeAgentRouteTable::AddBridgeBroadcastRoute(const Peer *peer,
const string &vrf_name,
const string &vn_name,
uint32_t label,
int vxlan_id,
uint32_t ethernet_tag,
uint32_t tunnel_type,
COMPOSITETYPE type,
ComponentNHKeyList
&component_nh_key_list) {
DBRequest nh_req(DBRequest::DB_ENTRY_ADD_CHANGE);
nh_req.key.reset(new CompositeNHKey(type, false, component_nh_key_list,
vrf_name));
nh_req.data.reset(new CompositeNHData());
DBRequest req(DBRequest::DB_ENTRY_ADD_CHANGE);
req.key.reset(new BridgeRouteKey(peer, vrf_name,
MacAddress::BroadcastMac(), ethernet_tag));
req.data.reset(new MulticastRoute(vn_name, label,
((peer->GetType() == Peer::BGP_PEER) ?
ethernet_tag : vxlan_id), tunnel_type,
nh_req, type));
BridgeTableEnqueue(Agent::GetInstance(), &req);
}
void BridgeAgentRouteTable::DeleteBroadcastReq(const Peer *peer,
const string &vrf_name,
uint32_t ethernet_tag,
COMPOSITETYPE type) {
DBRequest req(DBRequest::DB_ENTRY_DELETE);
req.key.reset(new BridgeRouteKey(peer, vrf_name,
MacAddress::BroadcastMac(), ethernet_tag));
DBRequest nh_req;
//For same BGP peer type comp type helps in identifying if its a delete
//for TOR or EVPN path.
//Only ethernet tag is required, rest are dummy.
req.data.reset(new MulticastRoute("", 0, ethernet_tag,
TunnelType::AllType(),
nh_req, type));
BridgeTableEnqueue(Agent::GetInstance(), &req);
}
const VmInterface *BridgeAgentRouteTable::FindVmFromDhcpBinding
(const MacAddress &mac) {
const BridgeRouteEntry *l2_rt = FindRoute(mac);
if (l2_rt == NULL)
return NULL;
const MacVmBindingPath *dhcp_path = dynamic_cast<const MacVmBindingPath *>
(l2_rt->FindMacVmBindingPath());
if (dhcp_path == NULL)
return NULL;
return dhcp_path->vm_interface();
}
/////////////////////////////////////////////////////////////////////////////
// BridgeRouteEntry methods
/////////////////////////////////////////////////////////////////////////////
const std::string BridgeRouteEntry::GetAddressString() const {
//For multicast use the same tree as of 255.255.255.255
if (is_multicast()) {
return "255.255.255.255";
}
return ToString();
}
string BridgeRouteEntry::ToString() const {
return mac_.ToString();
}
int BridgeRouteEntry::CompareTo(const Route &rhs) const {
const BridgeRouteEntry &a = static_cast<const BridgeRouteEntry &>(rhs);
return mac_.CompareTo(a.mac_);
}
DBEntryBase::KeyPtr BridgeRouteEntry::GetDBRequestKey() const {
BridgeRouteKey *key =
new BridgeRouteKey(Agent::GetInstance()->local_vm_peer(),
vrf()->GetName(), mac_);
return DBEntryBase::KeyPtr(key);
}
void BridgeRouteEntry::SetKey(const DBRequestKey *key) {
const BridgeRouteKey *k = static_cast<const BridgeRouteKey *>(key);
SetVrf(Agent::GetInstance()->vrf_table()->FindVrfFromName(k->vrf_name()));
mac_ = k->GetMac();
}
uint32_t BridgeRouteEntry::GetActiveLabel() const {
uint32_t label = 0;
if (is_multicast()) {
if (TunnelType::ComputeType(TunnelType::AllType()) ==
(1 << TunnelType::VXLAN)) {
label = GetActivePath()->vxlan_id();
} else {
label = GetActivePath()->label();
}
} else {
label = GetActivePath()->GetActiveLabel();
}
return label;
}
AgentPath *BridgeRouteEntry::FindPathUsingKeyData
(const AgentRouteKey *key, const AgentRouteData *data) const {
const Peer *peer = key->peer();
if (is_multicast())
return FindMulticastPathUsingKeyData(key, data);
const EvpnPeer *evpn_peer = dynamic_cast<const EvpnPeer*>(peer);
if (evpn_peer != NULL)
return FindEvpnPathUsingKeyData(key, data);
return FindPath(peer);
}
AgentPath *BridgeRouteEntry::FindMulticastPathUsingKeyData
(const AgentRouteKey *key, const AgentRouteData *data) const {
assert(is_multicast());
Route::PathList::const_iterator it;
for (it = GetPathList().begin(); it != GetPathList().end();
it++) {
const AgentPath *path = static_cast<const AgentPath *>(it.operator->());
if (path->peer() != key->peer())
continue;
//Handle multicast peer matching,
//In case of BGP peer also match VXLAN id.
if (path->peer()->GetType() != Peer::BGP_PEER)
return const_cast<AgentPath *>(path);
const MulticastRoute *multicast_data =
dynamic_cast<const MulticastRoute *>(data);
assert(multicast_data != NULL);
if (multicast_data->vxlan_id() != path->vxlan_id())
continue;
//In multicast from same peer, TOR and EVPN comp can
//come. These should not overlap and be installed as
//different path.
const CompositeNH *cnh = dynamic_cast<CompositeNH *>(path->nexthop());
if ((cnh != NULL) &&
(multicast_data->comp_nh_type() != cnh->composite_nh_type()))
continue;
return const_cast<AgentPath *>(path);
}
return NULL;
}
AgentPath *BridgeRouteEntry::FindEvpnPathUsingKeyData
(const AgentRouteKey *key, const AgentRouteData *data) const {
const Peer *peer = key->peer();
const EvpnPeer *evpn_peer = dynamic_cast<const EvpnPeer*>(peer);
assert(evpn_peer != NULL);
Route::PathList::const_iterator it;
for (it = GetPathList().begin(); it != GetPathList().end(); it++) {
const AgentPath *path = static_cast<const AgentPath *>(it.operator->());
if (path->peer() != key->peer())
continue;
//Handle mac route added via evpn route.
const EvpnDerivedPath *evpn_path =
dynamic_cast<const EvpnDerivedPath *>(path);
const EvpnDerivedPathData *evpn_data =
dynamic_cast<const EvpnDerivedPathData *>(data);
assert(evpn_path != NULL);
assert(evpn_data != NULL);
if (evpn_path->ethernet_tag() != evpn_data->ethernet_tag())
continue;
if (evpn_path->ip_addr() != evpn_data->ip_addr())
continue;
return const_cast<AgentPath *>(path);
}
return NULL;
}
void BridgeRouteEntry::DeletePathUsingKeyData(const AgentRouteKey *key,
const AgentRouteData *data,
bool force_delete) {
Route::PathList::iterator it;
for (it = GetPathList().begin(); it != GetPathList().end();
it++) {
AgentPath *path = static_cast<AgentPath *>(it.operator->());
bool delete_path = false;
if (key->peer() == path->peer()) {
if ((path->peer()->GetType() != Peer::BGP_PEER) &&
(path->peer()->GetType() != Peer::EVPN_PEER)) {
delete_path = true;
} else {
//There are two ways to receive delete of BGP peer path in
//l2 route.
//First is via withdraw meesage from control node in which
//force_delete will be false and vxlan_id will be matched to
//decide.
//Second can be via route walkers where on peer going down or
//vrf delete, paths from BGP peer should be deleted irrespective
//of vxlan_id.
if (force_delete && (path->peer()->GetType() ==
Peer::BGP_PEER)) {
delete_path = true;
} else if (is_multicast()) {
assert(path->peer()->GetType() == Peer::BGP_PEER);
const MulticastRoute *multicast_data =
dynamic_cast<const MulticastRoute *>(data);
assert(multicast_data != NULL);
if (multicast_data->vxlan_id() != path->vxlan_id())
continue;
delete_path = true;
} else if (path->peer()->GetType() == Peer::EVPN_PEER) {
const EvpnDerivedPath *evpn_path =
dynamic_cast<const EvpnDerivedPath *>(path);
const EvpnDerivedPathData *evpn_data =
dynamic_cast<const EvpnDerivedPathData *>(data);
assert(evpn_path != NULL);
assert(evpn_data != NULL);
if (evpn_path->ethernet_tag() != evpn_data->ethernet_tag())
continue;
if (evpn_path->ip_addr() != evpn_data->ip_addr())
continue;
delete_path = true;
}
}
if (delete_path) {
DeletePathInternal(path);
return;
}
}
}
}
const AgentPath *BridgeRouteEntry::FindMacVmBindingPath() const {
Agent *agent = (static_cast<AgentRouteTable *> (get_table()))->agent();
return FindPath(agent->mac_vm_binding_peer());
}
const AgentPath *BridgeRouteEntry::FindOvsPath() const {
for(Route::PathList::const_iterator it = GetPathList().begin();
it != GetPathList().end(); it++) {
const AgentPath *path = static_cast<const AgentPath *>(it.operator->());
if (path->peer()->GetType() == Peer::OVS_PEER) {
return const_cast<AgentPath *>(path);
}
}
return NULL;
}
bool BridgeRouteEntry::ReComputePathAdd(AgentPath *path) {
if (is_multicast()) {
//evaluate add of path
return ReComputeMulticastPaths(path, false);
}
return false;
}
bool BridgeRouteEntry::ReComputePathDeletion(AgentPath *path) {
if (is_multicast()) {
//evaluate delete of path
return ReComputeMulticastPaths(path, true);
}
return false;
}
bool BridgeRouteEntry::ReComputeMulticastPaths(AgentPath *path, bool del) {
if (path->peer() == NULL) {
return false;
}
//HACK: subnet route uses multicast NH. During IPAM delete
//subnet discard is deleted. Consider this as delete of all
//paths. Though this can be handled via multicast module
//which can also issue delete of all peers, however
//this is a temporary code as subnet route will not use
//multicast NH.
bool delete_all = false;
if (path->is_subnet_discard() && del) {
delete_all = true;
}
Agent *agent = (static_cast<AgentRouteTable *> (get_table()))->agent();
if (del && (path->peer() == agent->multicast_peer()))
return false;
//Possible paths:
//EVPN path - can be from multiple peers.
//Fabric path - from multicast builder
//Multicast peer
AgentPath *multicast_peer_path = NULL;
AgentPath *local_peer_path = NULL;
AgentPath *evpn_peer_path = NULL;
AgentPath *fabric_peer_path = NULL;
AgentPath *tor_peer_path = NULL;
//Delete path label
if (del) {
MplsLabel::DeleteReq(agent, path->label());
}
for (Route::PathList::iterator it = GetPathList().begin();
it != GetPathList().end(); it++) {
AgentPath *it_path =
static_cast<AgentPath *>(it.operator->());
if (delete_all && (it_path->peer() != agent->multicast_peer()))
continue;
//Handle deletions
if (del && (path->peer() == it_path->peer())) {
if (path->peer()->GetType() != Peer::BGP_PEER)
continue;
//Dive into comp NH type for BGP peer
const CompositeNH *it_path_comp_nh =
static_cast<const CompositeNH *>(it_path->nexthop());
const CompositeNH *comp_nh =
static_cast<const CompositeNH *>(path->nexthop());
if (it_path_comp_nh->composite_nh_type() ==
comp_nh->composite_nh_type())
continue;
}
//Handle Add/Changes
if (it_path->peer() == agent->local_vm_peer()) {
local_peer_path = it_path;
} else if (it_path->peer()->GetType() == Peer::BGP_PEER) {
const CompositeNH *bgp_comp_nh =
static_cast<const CompositeNH *>(it_path->nexthop());
//Its a TOR NH
if (bgp_comp_nh && (bgp_comp_nh->composite_nh_type() ==
Composite::TOR)) {
if (tor_peer_path == NULL)
tor_peer_path = it_path;
}
//Pick up the first peer.
if (bgp_comp_nh && (bgp_comp_nh->composite_nh_type() ==
Composite::EVPN)) {
if (evpn_peer_path == NULL)
evpn_peer_path = it_path;
}
} else if (it_path->peer()->GetType() ==
Peer::MULTICAST_FABRIC_TREE_BUILDER) {
fabric_peer_path = it_path;
} else if (it_path->peer() == agent->multicast_peer()) {
multicast_peer_path = it_path;
}
}
//all paths are gone so delete multicast_peer path as well
if ((local_peer_path == NULL) &&
(tor_peer_path == NULL) &&
(evpn_peer_path == NULL) &&
(fabric_peer_path == NULL)) {
if (multicast_peer_path != NULL)
RemovePath(multicast_peer_path);
return true;
}
uint32_t old_fabric_mpls_label = 0;
if (multicast_peer_path == NULL) {
multicast_peer_path = new AgentPath(agent->multicast_peer(), NULL);
InsertPath(multicast_peer_path);
} else {
old_fabric_mpls_label = multicast_peer_path->label();
}
ComponentNHKeyList component_nh_list;
if (tor_peer_path) {
NextHopKey *tor_peer_key =
static_cast<NextHopKey *>((tor_peer_path->
ComputeNextHop(agent)->GetDBRequestKey()).release());
std::auto_ptr<const NextHopKey> key4(tor_peer_key);
ComponentNHKeyPtr component_nh_data4(new ComponentNHKey(0, key4));
component_nh_list.push_back(component_nh_data4);
}
if (evpn_peer_path) {
NextHopKey *evpn_peer_key =
static_cast<NextHopKey *>((evpn_peer_path->
ComputeNextHop(agent)->GetDBRequestKey()).release());
std::auto_ptr<const NextHopKey> key2(evpn_peer_key);
ComponentNHKeyPtr component_nh_data2(new ComponentNHKey(0, key2));
component_nh_list.push_back(component_nh_data2);
}
if (fabric_peer_path) {
NextHopKey *fabric_peer_key =
static_cast<NextHopKey *>((fabric_peer_path->
ComputeNextHop(agent)->GetDBRequestKey()).release());
std::auto_ptr<const NextHopKey> key3(fabric_peer_key);
ComponentNHKeyPtr component_nh_data3(new ComponentNHKey(0, key3));
component_nh_list.push_back(component_nh_data3);
}
if (local_peer_path) {
NextHopKey *local_peer_key =
static_cast<NextHopKey *>((local_peer_path->
ComputeNextHop(agent)->GetDBRequestKey()).release());
std::auto_ptr<const NextHopKey> key1(local_peer_key);
ComponentNHKeyPtr component_nh_data1(new ComponentNHKey(0, key1));
component_nh_list.push_back(component_nh_data1);
}
DBRequest nh_req(DBRequest::DB_ENTRY_ADD_CHANGE);
nh_req.key.reset(new CompositeNHKey(Composite::L2COMP,
false,
component_nh_list,
vrf()->GetName()));
nh_req.data.reset(new CompositeNHData());
agent->nexthop_table()->Process(nh_req);
NextHop *nh = static_cast<NextHop *>(agent->nexthop_table()->
FindActiveEntry(nh_req.key.get()));
//NH may not get added if VRF is marked for delete. Route may be in
//transition of getting deleted, skip NH modification.
if (!nh) {
return false;
}
bool ret = false;
//Identify parameters to be passed to populate multicast_peer path and
//based on peer priorites for each attribute.
std::string dest_vn_name = "";
bool unresolved = false;
uint32_t vxlan_id = 0;
uint32_t label = 0;
uint32_t evpn_label = 0;
uint32_t tunnel_bmap = TunnelType::AllType();
//Select based on priority of path peer.
if (local_peer_path) {
dest_vn_name = local_peer_path->dest_vn_name();
unresolved = local_peer_path->unresolved();
vxlan_id = local_peer_path->vxlan_id();
tunnel_bmap = TunnelType::AllType();
label = local_peer_path->label();
evpn_label = label;
} else if (tor_peer_path) {
dest_vn_name = tor_peer_path->dest_vn_name();
unresolved = tor_peer_path->unresolved();
vxlan_id = tor_peer_path->vxlan_id();
tunnel_bmap = TunnelType::VxlanType();
label = tor_peer_path->label();
evpn_label = label;
} else if (fabric_peer_path) {
dest_vn_name = fabric_peer_path->dest_vn_name();
unresolved = fabric_peer_path->unresolved();
vxlan_id = fabric_peer_path->vxlan_id();
tunnel_bmap = TunnelType::MplsType();
label = fabric_peer_path->label();
} else if (evpn_peer_path) {
dest_vn_name = evpn_peer_path->dest_vn_name();
unresolved = evpn_peer_path->unresolved();
vxlan_id = evpn_peer_path->vxlan_id();
tunnel_bmap = TunnelType::VxlanType();
label = evpn_peer_path->label();
evpn_label = label;
}
//Mpls label selection needs to be overridden by fabric label
//if fabric peer is present
if (fabric_peer_path) {
label = fabric_peer_path->label();
}
ret = MulticastRoute::CopyPathParameters(agent,
multicast_peer_path,
dest_vn_name,
unresolved,
vxlan_id,
label,
tunnel_bmap,
nh);
//Bake all MPLS label
if (fabric_peer_path) {
//Add new label
MplsLabel::CreateMcastLabelReq(agent,
fabric_peer_path->label(),
Composite::L2COMP,
component_nh_list,
vrf()->GetName());
//Delete Old label, in case label has changed for same peer.
if (old_fabric_mpls_label != fabric_peer_path->label()) {
MplsLabel::DeleteReq(agent, old_fabric_mpls_label);
}
}
if (evpn_label != 0) {
MplsLabel::CreateMcastLabelReq(agent,
evpn_label,
Composite::L2COMP,
component_nh_list,
vrf()->GetName());
}
return ret;
}
/////////////////////////////////////////////////////////////////////////////
// Sandesh related methods
/////////////////////////////////////////////////////////////////////////////
void BridgeRouteReq::HandleRequest() const {
VrfEntry *vrf =
Agent::GetInstance()->vrf_table()->FindVrfFromId(get_vrf_index());
if (!vrf) {
ErrorResp *resp = new ErrorResp();
resp->set_context(context());
resp->Response();
return;
}
AgentSandeshPtr sand(new AgentBridgeRtSandesh(vrf, context(), "",
get_stale()));
sand->DoSandesh(sand);
}
AgentSandeshPtr BridgeAgentRouteTable::GetAgentSandesh
(const AgentSandeshArguments *args, const std::string &context) {
return AgentSandeshPtr(new AgentBridgeRtSandesh(vrf_entry(), context, "",
true));
}
bool BridgeRouteEntry::DBEntrySandesh(Sandesh *sresp, bool stale) const {
BridgeRouteResp *resp = static_cast<BridgeRouteResp *>(sresp);
RouteL2SandeshData data;
data.set_mac(ToString());
for (Route::PathList::const_iterator it = GetPathList().begin();
it != GetPathList().end(); it++) {
const AgentPath *path = static_cast<const AgentPath *>(it.operator->());
if (path) {
if (stale && !path->is_stale())
continue;
PathSandeshData pdata;
path->SetSandeshData(pdata);
if (is_multicast()) {
pdata.set_vxlan_id(path->vxlan_id());
}
const EvpnDerivedPath *evpn_path = dynamic_cast<const EvpnDerivedPath *>(path);
if (evpn_path) {
pdata.set_info(evpn_path->parent());
}
data.path_list.push_back(pdata);
}
}
std::vector<RouteL2SandeshData> &list =
const_cast<std::vector<RouteL2SandeshData>&>(resp->get_route_list());
list.push_back(data);
return true;
}
//Supporting deprecated layer2 requests
void Layer2RouteReq::HandleRequest() const {
VrfEntry *vrf =
Agent::GetInstance()->vrf_table()->FindVrfFromId(get_vrf_index());
if (!vrf) {
ErrorResp *resp = new ErrorResp();
resp->set_context(context());
resp->Response();
return;
}
AgentSandeshPtr sand(new AgentLayer2RtSandesh(vrf, context(), "",
get_stale()));
sand->DoSandesh(sand);
}