/
agent_path.cc
885 lines (755 loc) · 26.6 KB
/
agent_path.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
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
/*
* Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
*/
#include <boost/uuid/uuid_io.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/foreach.hpp>
#include <cmn/agent_cmn.h>
#include <route/route.h>
#include <vnc_cfg_types.h>
#include <agent_types.h>
#include <filter/acl.h>
#include <oper/peer.h>
#include <oper/vrf.h>
#include <oper/interface_common.h>
#include <oper/nexthop.h>
#include <oper/tunnel_nh.h>
#include <oper/vn.h>
#include <oper/mirror_table.h>
#include <oper/vxlan.h>
#include <oper/mpls.h>
#include <oper/route_common.h>
#include <oper/agent_sandesh.h>
using namespace std;
using namespace boost::asio;
AgentPath::AgentPath(const Peer *peer, AgentRoute *rt):
Path(), peer_(peer), nh_(NULL), label_(MplsTable::kInvalidLabel),
vxlan_id_(VxLanTable::kInvalidvxlan_id), dest_vn_name_(""),
sync_(false), proxy_arp_(false), force_policy_(false), sg_list_(),
server_ip_(0), tunnel_bmap_(TunnelType::AllType()),
tunnel_type_(TunnelType::ComputeType(TunnelType::AllType())),
vrf_name_(""), gw_ip_(0), unresolved_(true), is_stale_(false),
is_subnet_discard_(false), dependant_rt_(rt), path_preference_(),
local_ecmp_mpls_label_(rt), composite_nh_key_(NULL), subnet_gw_ip_() {
}
AgentPath::~AgentPath() {
clear_sg_list();
}
uint32_t AgentPath::GetTunnelBmap() const {
TunnelType::Type type = TunnelType::ComputeType(TunnelType::AllType());
if ((type == (1 << TunnelType::VXLAN)) && (vxlan_id_ != 0)) {
return (1 << TunnelType::VXLAN);
} else {
return tunnel_bmap_;
}
}
uint32_t AgentPath::GetActiveLabel() const {
if (tunnel_type_ == TunnelType::VXLAN) {
return vxlan_id_;
} else {
return label_;
}
}
const NextHop* AgentPath::nexthop(Agent *agent) const {
if (nh_) {
return nh_.get();
}
if (unresolved_ == true) {
DiscardNH key;
return static_cast<NextHop *>
(agent->nexthop_table()->FindActiveEntry(&key));
}
//Indirect route's path, get direct route's NH
const NextHop *nh = dependant_rt_.get()->GetActiveNextHop();
if (nh == NULL) {
assert(0);
}
return nh;
}
bool AgentPath::ChangeNH(Agent *agent, NextHop *nh) {
// If NH is not found, point route to discard NH
if (nh == NULL) {
nh = agent->nexthop_table()->discard_nh();
}
if (nh_ != nh) {
nh_ = nh;
return true;
}
return false;
}
bool AgentPath::RebakeAllTunnelNHinCompositeNH(const AgentRoute *sync_route) {
if (nh_->GetType() != NextHop::COMPOSITE){
return false;
}
Agent *agent =
static_cast<AgentRouteTable *>(sync_route->get_table())->agent();
CompositeNH *cnh = static_cast<CompositeNH *>(nh_.get());
//Compute new tunnel type
TunnelType::Type new_tunnel_type;
//Only MPLS types are supported for multicast
if ((sync_route->is_multicast()) && (peer_->GetType() ==
Peer::MULTICAST_FABRIC_TREE_BUILDER)) {
new_tunnel_type = TunnelType::ComputeType(TunnelType::MplsType());
if (new_tunnel_type == TunnelType::VXLAN) {
new_tunnel_type = TunnelType::MPLS_GRE;
}
} else {
new_tunnel_type = TunnelType::ComputeType(tunnel_bmap_);
}
CompositeNH *new_composite_nh = NULL;
new_composite_nh = cnh->ChangeTunnelType(agent, new_tunnel_type);
if (ChangeNH(agent, new_composite_nh)) {
//Update composite NH key list to reflect new type
if (composite_nh_key_)
composite_nh_key_->ChangeTunnelType(new_tunnel_type);
return true;
}
return false;
}
bool AgentPath::UpdateNHPolicy(Agent *agent) {
bool ret = false;
if (nh_.get() == NULL || nh_->GetType() != NextHop::INTERFACE) {
return ret;
}
const InterfaceNH *intf_nh = static_cast<const InterfaceNH *>(nh_.get());
if (intf_nh->GetInterface()->type() != Interface::VM_INTERFACE) {
return ret;
}
const VmInterface *vm_port =
static_cast<const VmInterface *>(intf_nh->GetInterface());
bool policy = vm_port->policy_enabled();
if (force_policy_) {
policy = true;
}
NextHop *nh = NULL;
if (intf_nh->PolicyEnabled() != policy) {
//Make path point to policy enabled interface
InterfaceNHKey key(new VmInterfaceKey(AgentKey::ADD_DEL_CHANGE,
vm_port->GetUuid(), ""),
policy, intf_nh->GetFlags());
nh = static_cast<NextHop *>
(agent->nexthop_table()->FindActiveEntry(&key));
// If NH is not found, point route to discard NH
if (nh == NULL) {
LOG(DEBUG, "Interface NH for <"
<< boost::lexical_cast<std::string>(vm_port->GetUuid())
<< " : policy = " << policy);
nh = agent->nexthop_table()->discard_nh();
}
if (ChangeNH(agent, nh) == true) {
ret = true;
}
}
return ret;
}
bool AgentPath::UpdateTunnelType(Agent *agent, const AgentRoute *sync_route) {
if (tunnel_type_ == TunnelType::ComputeType(tunnel_bmap_)) {
return false;
}
tunnel_type_ = TunnelType::ComputeType(tunnel_bmap_);
if (tunnel_type_ == TunnelType::VXLAN &&
vxlan_id_ == VxLanTable::kInvalidvxlan_id) {
tunnel_type_ = TunnelType::ComputeType(TunnelType::MplsType());
}
if (nh_.get() && nh_->GetType() == NextHop::TUNNEL) {
DBRequest nh_req(DBRequest::DB_ENTRY_ADD_CHANGE);
TunnelNHKey *tnh_key =
new TunnelNHKey(agent->fabric_vrf_name(), agent->router_id(),
server_ip_, false, tunnel_type_);
nh_req.key.reset(tnh_key);
nh_req.data.reset(new TunnelNHData());
agent->nexthop_table()->Process(nh_req);
TunnelNHKey nh_key(agent->fabric_vrf_name(), agent->router_id(),
server_ip_, false, tunnel_type_);
NextHop *nh = static_cast<NextHop *>
(agent->nexthop_table()->FindActiveEntry(&nh_key));
ChangeNH(agent, nh);
}
if (nh_.get() && nh_->GetType() == NextHop::COMPOSITE) {
RebakeAllTunnelNHinCompositeNH(sync_route);
}
return true;
}
bool AgentPath::Sync(AgentRoute *sync_route) {
bool ret = false;
bool unresolved = false;
Agent *agent = static_cast<AgentRouteTable *>
(sync_route->get_table())->agent();
// Check if there is change in policy on the interface
// If yes update the path to point to policy enabled NH
if (UpdateNHPolicy(agent)) {
ret = true;
}
//Handle tunnel type change
if (UpdateTunnelType(agent, sync_route)) {
ret = true;
}
//Check if there was a change in local ecmp composite nexthop
if (nh_ && nh_->GetType() == NextHop::COMPOSITE &&
composite_nh_key_.get() != NULL) {
boost::scoped_ptr<CompositeNHKey> composite_nh_key(composite_nh_key_->Clone());
if (ReorderCompositeNH(agent, composite_nh_key.get())) {
if (ChangeCompositeNH(agent, composite_nh_key.get())) {
ret = true;
}
}
}
if (vrf_name_ == Agent::NullString()) {
return ret;
}
InetUnicastAgentRouteTable *table = NULL;
InetUnicastRouteEntry *rt = NULL;
table = agent->vrf_table()->GetInet4UnicastRouteTable(vrf_name_);
if (table)
rt = table->FindRoute(gw_ip_);
if (rt == sync_route) {
rt = NULL;
}
if (rt == NULL || rt->plen() == 0) {
unresolved = true;
} else if (rt->GetActiveNextHop()->GetType() == NextHop::RESOLVE) {
table->AddArpReq(vrf_name_, gw_ip_);
unresolved = true;
} else {
unresolved = false;
}
if (unresolved_ != unresolved) {
unresolved_ = unresolved;
ret = true;
}
// Reset to new gateway route, no nexthop for indirect route
if (dependant_rt_.get() != rt) {
dependant_rt_.reset(rt);
ret = true;
}
return ret;
}
bool AgentPath::IsLess(const AgentPath &r_path) const {
if (peer()->GetType() == Peer::LOCAL_VM_PORT_PEER &&
peer()->GetType() == r_path.peer()->GetType()) {
if (path_preference() != r_path.path_preference()) {
//If right path has lesser preference, then
//it should be after the current entry
//Hence the reverse check
return (r_path.path_preference() < path_preference());
}
}
return peer()->IsLess(r_path.peer());
}
bool HostRoute::AddChangePath(Agent *agent, AgentPath *path) {
bool ret = false;
NextHop *nh = NULL;
InterfaceNHKey key(intf_.Clone(), false, InterfaceNHFlags::INET4);
nh = static_cast<NextHop *>(agent->nexthop_table()->FindActiveEntry(&key));
if (path->dest_vn_name() != dest_vn_name_) {
path->set_dest_vn_name(dest_vn_name_);
ret = true;
}
if (path->proxy_arp() != proxy_arp_) {
path->set_proxy_arp(proxy_arp_);
ret = true;
}
path->set_proxy_arp(true);
path->set_unresolved(false);
if (path->ChangeNH(agent, nh) == true)
ret = true;
return ret;
}
bool InetInterfaceRoute::AddChangePath(Agent *agent, AgentPath *path) {
bool ret = false;
NextHop *nh = NULL;
InterfaceNHKey key(intf_.Clone(), false, InterfaceNHFlags::INET4);
nh = static_cast<NextHop *>(agent->nexthop_table()->FindActiveEntry(&key));
if (path->dest_vn_name() != dest_vn_name_) {
path->set_dest_vn_name(dest_vn_name_);
ret = true;
}
if (path->label() != label_) {
path->set_label(label_);
ret = true;
}
path->set_tunnel_bmap(tunnel_bmap_);
TunnelType::Type tunnel_type = TunnelType::ComputeType(tunnel_bmap_);
if (tunnel_type != path->tunnel_type()) {
path->set_tunnel_type(tunnel_type);
ret = true;
}
path->set_unresolved(false);
if (path->ChangeNH(agent, nh) == true)
ret = true;
return ret;
}
bool DropRoute::AddChangePath(Agent *agent, AgentPath *path) {
bool ret = false;
if (path->dest_vn_name() != vn_) {
path->set_dest_vn_name(vn_);
ret = true;
}
NextHop *nh = agent->nexthop_table()->discard_nh();
path->set_unresolved(false);
if (path->ChangeNH(agent, nh) == true) {
ret = true;
}
return ret;
}
bool LocalVmRoute::AddChangePath(Agent *agent, AgentPath *path) {
bool ret = false;
NextHop *nh = NULL;
SecurityGroupList path_sg_list;
//TODO Based on key table type pick up interface
VmInterfaceKey intf_key(AgentKey::ADD_DEL_CHANGE, intf_.uuid_, "");
VmInterface *vm_port = static_cast<VmInterface *>
(agent->interface_table()->FindActiveEntry(&intf_key));
bool policy = false;
// Use policy based NH if policy enabled on interface
if (vm_port && vm_port->policy_enabled()) {
policy = true;
}
path->set_tunnel_bmap(tunnel_bmap_);
TunnelType::Type new_tunnel_type = TunnelType::ComputeType(tunnel_bmap_);
if (new_tunnel_type == TunnelType::VXLAN &&
vxlan_id_ == VxLanTable::kInvalidvxlan_id) {
new_tunnel_type = TunnelType::ComputeType(TunnelType::MplsType());
}
if (path->tunnel_type() != new_tunnel_type) {
path->set_tunnel_type(new_tunnel_type);
ret = true;
}
// If policy force-enabled in request, enable policy
path->set_force_policy(force_policy_);
if (force_policy_) {
policy = true;
}
InterfaceNHKey key(intf_.Clone(), policy, flags_);
nh = static_cast<NextHop *>(agent->nexthop_table()->FindActiveEntry(&key));
if (path->label() != mpls_label_) {
path->set_label(mpls_label_);
ret = true;
}
if (path->vxlan_id() != vxlan_id_) {
path->set_vxlan_id(vxlan_id_);
ret = true;
}
if (path->dest_vn_name() != dest_vn_name_) {
path->set_dest_vn_name(dest_vn_name_);
ret = true;
}
if (path->proxy_arp() != proxy_arp_) {
path->set_proxy_arp(proxy_arp_);
ret = true;
}
path_sg_list = path->sg_list();
if (path_sg_list != sg_list_) {
path->set_sg_list(sg_list_);
ret = true;
}
//Priority and sequence no of path are updated from path
//preference state machine
//Path preference value enqueued here would be copied
//only if
//1> ecmp field is set to true, meaning path would be
// active-active
//2> static preference is set, meaning external entity
// would specify the preference of this path(ex LBaaS)
//3> Change in priority when static preference is set
if (path->path_preference().ConfigChanged(path_preference_)) {
path->set_path_preference(path_preference_);
ret = true;
}
if (path->peer() && path->peer()->GetType() == Peer::BGP_PEER) {
//Copy entire path preference for BGP peer path,
//since allowed-address pair config doesn't modify
//preference on BGP path
if (path->path_preference() != path_preference_) {
path->set_path_preference(path_preference_);
ret = true;
}
}
// When BGP path was added, the policy flag in BGP path was based on
// interface config at that instance. If the policy flag changes in
// path for "Local Peer", we should change policy flag on BGP peer
// also. Check if policy has changed and enable SYNC of all path in
// this case
// Ideally his is needed only for LocalPath. But, having code for all
// paths does not have any problem
bool old_policy = false;
bool new_policy = false;
if (path->nexthop(agent) && path->nexthop(agent)->PolicyEnabled())
old_policy = true;
if (nh && nh->PolicyEnabled())
new_policy = true;
if (old_policy != new_policy) {
sync_route_ = true;
}
if (path->subnet_gw_ip() != subnet_gw_ip_) {
path->set_subnet_gw_ip(subnet_gw_ip_);
ret = true;
}
path->set_unresolved(false);
path->SyncRoute(sync_route_);
if (path->ChangeNH(agent, nh) == true)
ret = true;
return ret;
}
bool VlanNhRoute::AddChangePath(Agent *agent, AgentPath *path) {
bool ret = false;
NextHop *nh = NULL;
SecurityGroupList path_sg_list;
assert(intf_.type_ == Interface::VM_INTERFACE);
VlanNHKey key(intf_.uuid_, tag_);
nh = static_cast<NextHop *>(agent->nexthop_table()->FindActiveEntry(&key));
if (nh) {
assert(nh->GetType() == NextHop::VLAN);
}
if (path->label() != label_) {
path->set_label(label_);
ret = true;
}
if (path->dest_vn_name() != dest_vn_name_) {
path->set_dest_vn_name(dest_vn_name_);
ret = true;
}
path_sg_list = path->sg_list();
if (path_sg_list != sg_list_) {
path->set_sg_list(sg_list_);
ret = true;
}
//Copy over entire path preference structure, whenever there is a
//transition from active-active to active-backup struture
if (path->path_preference().ecmp() != path_preference_.ecmp()) {
path->set_path_preference(path_preference_);
ret = true;
}
path->set_tunnel_bmap(tunnel_bmap_);
TunnelType::Type tunnel_type = TunnelType::ComputeType(tunnel_bmap_);
if (tunnel_type != path->tunnel_type()) {
path->set_tunnel_type(tunnel_type);
ret = true;
}
path->set_unresolved(false);
if (path->ChangeNH(agent, nh) == true) {
ret = true;
}
return ret;
}
bool ResolveRoute::AddChangePath(Agent *agent, AgentPath *path) {
bool ret = false;
NextHop *nh = NULL;
ResolveNHKey key;
nh = static_cast<NextHop *>(agent->nexthop_table()->FindActiveEntry(&key));
path->set_unresolved(false);
if (path->dest_vn_name() != agent->fabric_vn_name()) {
path->set_dest_vn_name(agent->fabric_vn_name());
ret = true;
}
if (path->ChangeNH(agent, nh) == true)
ret = true;
return ret;
}
bool ReceiveRoute::AddChangePath(Agent *agent, AgentPath *path) {
bool ret = false;
NextHop *nh = NULL;
//TODO check if it needs to know table type
ReceiveNHKey key(intf_.Clone(), policy_);
nh = static_cast<NextHop *>(agent->nexthop_table()->FindActiveEntry(&key));
path->set_unresolved(false);
if (path->dest_vn_name() != vn_) {
path->set_dest_vn_name(vn_);
ret = true;
}
if (path->proxy_arp() != proxy_arp_) {
path->set_proxy_arp(proxy_arp_);
ret = true;
}
if (path->label() != label_) {
path->set_label(label_);
ret = true;
}
if (path->ChangeNH(agent, nh) == true)
ret = true;
return ret;
}
bool MulticastRoute::AddChangePath(Agent *agent, AgentPath *path) {
bool ret = false;
bool is_subnet_discard = false;
NextHop *nh = NULL;
agent->nexthop_table()->Process(composite_nh_req_);
nh = static_cast<NextHop *>(agent->nexthop_table()->
FindActiveEntry(composite_nh_req_.key.get()));
assert(nh);
if (nh) {
if (nh->GetType() == NextHop::DISCARD) {
is_subnet_discard = true;
}
}
ret = MulticastRoute::CopyPathParameters(agent,
path,
vn_name_,
false,
vxlan_id_,
label_,
TunnelType::AllType(),
is_subnet_discard,
nh);
return ret;
}
bool MulticastRoute::CopyPathParameters(Agent *agent,
AgentPath *path,
const std::string &vn_name,
bool unresolved,
uint32_t vxlan_id,
uint32_t label,
uint32_t tunnel_type,
bool is_subnet_discard,
NextHop *nh) {
path->set_dest_vn_name(vn_name);
path->set_unresolved(unresolved);
path->set_vxlan_id(vxlan_id);
path->set_label(label);
//Setting of tunnel is only for simulated TOR.
path->set_tunnel_bmap(tunnel_type);
TunnelType::Type new_tunnel_type =
TunnelType::ComputeType(TunnelType::AllType());
if (new_tunnel_type == TunnelType::VXLAN &&
vxlan_id == VxLanTable::kInvalidvxlan_id) {
new_tunnel_type = TunnelType::ComputeType(TunnelType::MplsType());
}
if (path->tunnel_type() != new_tunnel_type) {
path->set_tunnel_type(new_tunnel_type);
}
path->set_is_subnet_discard(is_subnet_discard);
path->ChangeNH(agent, nh);
return true;
}
bool PathPreferenceData::AddChangePath(Agent *agent, AgentPath *path) {
bool ret = false;
//ECMP flag will not be changed by path preference module,
//hence retain value in path
if (!path) {
return ret;
}
path_preference_.set_ecmp(path->path_preference().ecmp());
if (path &&
path->path_preference() != path_preference_) {
path->set_path_preference(path_preference_);
ret = true;
}
return ret;
}
// Subnet Route route data
SubnetRoute::SubnetRoute(const string &vn_name,
uint32_t vxlan_id, DBRequest &nh_req) :
MulticastRoute(vn_name, 0, vxlan_id, nh_req) {
is_multicast_ = false;
}
///////////////////////////////////////////////
// Sandesh routines below (route_sandesh.cc)
//////////////////////////////////////////////
//TODO make it generic
void UnresolvedNH::HandleRequest() const {
VrfEntry *vrf = Agent::GetInstance()->vrf_table()->FindVrfFromId(0);
if (!vrf) {
ErrorResp *resp = new ErrorResp();
resp->set_context(context());
resp->Response();
return;
}
int count = 0;
std::string empty("");
AgentRouteTable *rt_table = static_cast<AgentRouteTable *>
(vrf->GetInet4UnicastRouteTable());
NhListResp *resp = new NhListResp();
//TODO - Convert inet4ucroutetable to agentroutetable
AgentRouteTable::UnresolvedNHTree::const_iterator it;
it = rt_table->unresolved_nh_begin();
for (;it != rt_table->unresolved_nh_end(); it++) {
count++;
const NextHop *nh = *it;
nh->DBEntrySandesh(resp, empty);
if (count == 1) {
resp->set_context(context()+"$");
resp->Response();
count = 0;
resp = new NhListResp();
}
}
resp->set_context(context());
resp->Response();
return;
}
//TODO IMplement filltrace in path class
void AgentRoute::FillTrace(RouteInfo &rt_info, Trace event,
const AgentPath *path) {
Agent *agent = static_cast<AgentRouteTable *>(get_table())->agent();
rt_info.set_ip(ToString());
rt_info.set_vrf(vrf()->GetName());
switch(event) {
case ADD:{
rt_info.set_op("ADD");
break;
}
case DELETE: {
rt_info.set_op("DELETE");
break;
}
case ADD_PATH:
case DELETE_PATH:
case STALE_PATH:
case CHANGE_PATH: {
if (event == ADD_PATH) {
rt_info.set_op("PATH ADD");
} else if (event == CHANGE_PATH) {
rt_info.set_op("PATH CHANGE");
} else if (event == DELETE_PATH) {
rt_info.set_op("PATH DELETE");
} else if (event == STALE_PATH) {
rt_info.set_op("PATH STALE");
}
if (path == NULL) {
rt_info.set_nh_type("<NULL>");
break;
}
if (path->peer()) {
rt_info.set_peer(path->peer()->GetName());
}
rt_info.set_ecmp(path->path_preference().ecmp());
const NextHop *nh = path->nexthop(agent);
if (nh == NULL) {
rt_info.set_nh_type("<NULL>");
break;
}
switch (nh->GetType()) {
case NextHop::TUNNEL: {
const TunnelNH *tun = static_cast<const TunnelNH *>(nh);
rt_info.set_nh_type("TUNNEL");
rt_info.set_dest_server(tun->GetDip()->to_string());
rt_info.set_dest_server_vrf(tun->GetVrf()->GetName());
break;
}
case NextHop::ARP:{
rt_info.set_nh_type("DIRECT");
break;
}
case NextHop::INTERFACE: {
const InterfaceNH *intf_nh = static_cast<const InterfaceNH *>(nh);
rt_info.set_nh_type("INTERFACE");
rt_info.set_intf(intf_nh->GetInterface()->name());
break;
}
case NextHop::RECEIVE: {
const ReceiveNH *rcv_nh = static_cast<const ReceiveNH *>(nh);
rt_info.set_nh_type("RECEIVE");
rt_info.set_intf(rcv_nh->GetInterface()->name());
break;
}
case NextHop::DISCARD: {
rt_info.set_nh_type("DISCARD");
break;
}
case NextHop::VLAN: {
rt_info.set_nh_type("VLAN");
break;
}
case NextHop::RESOLVE: {
rt_info.set_nh_type("RESOLVE");
break;
}
case NextHop::COMPOSITE: {
rt_info.set_nh_type("COMPOSITE");
break;
}
default:
assert(0);
break;
}
break;
}
}
}
void AgentPath::SetSandeshData(PathSandeshData &pdata) const {
if (nh_.get() != NULL) {
nh_->SetNHSandeshData(pdata.nh);
}
pdata.set_peer(const_cast<Peer *>(peer())->GetName());
pdata.set_dest_vn(dest_vn_name());
pdata.set_unresolved(unresolved() ? "true" : "false");
if (!gw_ip().is_unspecified()) {
pdata.set_gw_ip(gw_ip().to_string());
pdata.set_vrf(vrf_name());
}
if (proxy_arp()) {
pdata.set_proxy_arp("ProxyArp");
}
pdata.set_sg_list(sg_list());
pdata.set_vxlan_id(vxlan_id());
pdata.set_label(label());
pdata.set_active_tunnel_type(
TunnelType(tunnel_type()).ToString());
pdata.set_supported_tunnel_type(
TunnelType::GetString(tunnel_bmap()));
pdata.set_stale(is_stale());
PathPreferenceSandeshData path_preference_data;
path_preference_data.set_sequence(path_preference_.sequence());
path_preference_data.set_preference(path_preference_.preference());
path_preference_data.set_ecmp(path_preference_.ecmp());
path_preference_data.set_wait_for_traffic(
path_preference_.wait_for_traffic());
pdata.set_path_preference_data(path_preference_data);
}
void AgentPath::set_local_ecmp_mpls_label(MplsLabel *mpls) {
local_ecmp_mpls_label_.reset(mpls);
}
const MplsLabel* AgentPath::local_ecmp_mpls_label() const {
return local_ecmp_mpls_label_.get();
}
bool AgentPath::ReorderCompositeNH(Agent *agent,
CompositeNHKey *composite_nh_key) {
//Find local composite mpls label, if present
//This has to be done, before expanding component NH
BOOST_FOREACH(ComponentNHKeyPtr component_nh_key,
composite_nh_key->component_nh_key_list()) {
if (component_nh_key.get() == NULL ||
component_nh_key->nh_key()->GetType() != NextHop::COMPOSITE) {
continue;
}
//Get mpls label allocated for this composite NH
MplsLabel *mpls = agent->mpls_table()->
FindMplsLabel(component_nh_key->label());
if (!mpls) {
//If a mpls label is deleted,
//wait for bgp to update latest list
local_ecmp_mpls_label_.reset(mpls);
return false;
}
local_ecmp_mpls_label_.reset(mpls);
break;
}
//Make a copy of composite NH, so that aggregarate mpls
//label allocated for local composite ecmp is maintained
//as data in path
CompositeNHKey *comp_key = composite_nh_key->Clone();
//Reorder the keys so that, existing component NH maintain
//there previous position
//For example take a composite NH with members A, B, C
//in that exact order,If B gets deleted,
//the new composite NH created should be A <NULL> C in that order,
//irrespective of the order user passed it in
composite_nh_key->Reorder(agent, label_, nexthop(agent));
//Copy the unchanged component NH list to path data
set_composite_nh_key(comp_key);
return true;
}
bool AgentPath::ChangeCompositeNH(Agent *agent,
CompositeNHKey *composite_nh_key) {
DBRequest nh_req(DBRequest::DB_ENTRY_ADD_CHANGE);
nh_req.key.reset(composite_nh_key->Clone());
nh_req.data.reset(new CompositeNHData());
agent->nexthop_table()->Process(nh_req);
NextHop *nh = static_cast<NextHop *>(agent->nexthop_table()->
FindActiveEntry(composite_nh_key));
assert(nh);
if (ChangeNH(agent, nh) == true) {
return true;
}
return false;
}