/
agent_path.cc
1397 lines (1190 loc) · 43 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
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* 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 <init/agent_param.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/ecmp_load_balance.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_list_(),
sync_(false), force_policy_(false), sg_list_(),
tunnel_dest_(0), tunnel_bmap_(TunnelType::AllType()),
tunnel_type_(TunnelType::ComputeType(TunnelType::AllType())),
vrf_name_(""), gw_ip_(), unresolved_(true), is_stale_(false),
is_subnet_discard_(false), dependant_rt_(rt), path_preference_(),
local_ecmp_mpls_label_(rt), composite_nh_key_(NULL), subnet_service_ip_(),
arp_mac_(), arp_interface_(NULL), arp_valid_(false),
ecmp_suppressed_(false), is_local_(false) {
}
AgentPath::~AgentPath() {
clear_sg_list();
}
uint32_t AgentPath::GetTunnelBmap() const {
TunnelType::Type type = TunnelType::ComputeType(tunnel_bmap_);
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_;
}
}
NextHop* AgentPath::nexthop() const {
return nh_.get();
}
const NextHop* AgentPath::ComputeNextHop(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
bool ret = false;
if (nh == NULL) {
nh = agent->nexthop_table()->discard_nh();
}
if (nh_ != nh) {
nh_ = nh;
if (nh && nh->GetType() == NextHop::TUNNEL) {
TunnelNH *tunnel_nh = static_cast<TunnelNH *>(nh);
tunnel_dest_ = *tunnel_nh->GetDip();
}
ret = true;
}
if (peer_ && (peer_->GetType() == Peer::MULTICAST_PEER) &&
(label_ != MplsTable::kInvalidLabel)) {
MplsLabelKey key(MplsLabel::MCAST_NH, label_);
MplsLabel *mpls = static_cast<MplsLabel *>(agent->mpls_table()->
FindActiveEntry(&key));
if (agent->mpls_table()->ChangeNH(mpls, nh))
ret = true;
if (mpls) {
//Send notify of change
mpls->get_table_partition()->Notify(mpls);
}
}
return ret;
}
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(),
intf_nh->GetDMac());
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) {
//Return if there is no change in tunnel type for non Composite NH.
//For composite NH component needs to be traversed.
if ((tunnel_type_ == TunnelType::ComputeType(tunnel_bmap_)) &&
(nh_.get() && nh_.get()->GetType() != NextHop::COMPOSITE)) {
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);
const TunnelNH *tunnel_nh = static_cast<const TunnelNH*>(nh_.get());
TunnelNHKey *tnh_key =
new TunnelNHKey(agent->fabric_vrf_name(), *(tunnel_nh->GetSip()),
tunnel_dest_, 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(), *(tunnel_nh->GetSip()),
tunnel_dest_, 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 &&
local_ecmp_mpls_label_.get() != NULL) {
boost::scoped_ptr<CompositeNHKey> composite_nh_key(composite_nh_key_->Clone());
bool comp_nh_policy = false;
if (ReorderCompositeNH(agent, composite_nh_key.get(), comp_nh_policy)) {
composite_nh_key->SetPolicy(comp_nh_policy);
if (ChangeCompositeNH(agent, composite_nh_key.get())) {
ret = true;
}
}
}
if (nh_ && nh_->GetType() == NextHop::ARP) {
if (CopyArpData()) {
ret = true;
}
}
if (vrf_name_ == Agent::NullString()) {
return ret;
}
InetUnicastAgentRouteTable *table = NULL;
InetUnicastRouteEntry *rt = NULL;
table = sync_route->vrf()->GetInetUnicastRouteTable(gw_ip_);
rt = table ? table->FindRoute(gw_ip_) : NULL;
if (rt == sync_route) {
rt = NULL;
}
if (rt == NULL || rt->plen() == 0) {
if (agent->params()->subnet_hosts_resolvable() == false &&
agent->fabric_vrf_name() == vrf_name_) {
unresolved = false;
assert(gw_ip_.is_v4());
table->AddArpReq(vrf_name_, gw_ip_.to_v4(), vrf_name_,
agent->vhost_interface(), false,
dest_vn_list_, sg_list_);
} else {
unresolved = true;
}
} else if (rt->GetActiveNextHop()->GetType() == NextHop::RESOLVE) {
const ResolveNH *nh =
static_cast<const ResolveNH *>(rt->GetActiveNextHop());
assert(gw_ip_.is_v4());
table->AddArpReq(vrf_name_, gw_ip_.to_v4(), nh->interface()->vrf()->GetName(),
nh->interface(), nh->PolicyEnabled(), dest_vn_list_,
sg_list_);
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() == 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());
}
const AgentPath *AgentPath::UsablePath() const {
return this;
}
void AgentPath::set_nexthop(NextHop *nh) {
nh_ = nh;
}
bool AgentPath::CopyArpData() {
bool ret = false;
if (nh_ && nh_->GetType() == NextHop::ARP) {
const ArpNH *arp_nh = static_cast<const ArpNH *>(nh_.get());
if (arp_mac() != arp_nh->GetMac()) {
set_arp_mac(arp_nh->GetMac());
ret = true;
}
if (arp_interface() != arp_nh->GetInterface()) {
set_arp_interface(arp_nh->GetInterface());
ret = true;
}
if (arp_valid() != arp_nh->IsValid()) {
set_arp_valid(arp_nh->IsValid());
ret = true;
}
}
return ret;
}
EvpnDerivedPath::EvpnDerivedPath(const EvpnPeer *evpn_peer,
const IpAddress &ip_addr,
uint32_t ethernet_tag,
const std::string &parent) :
AgentPath(evpn_peer, NULL),
ip_addr_(ip_addr), ethernet_tag_(ethernet_tag),
parent_(parent){
}
bool EvpnDerivedPath::IsLess(const AgentPath &r_path) const {
const EvpnDerivedPath *r_evpn_path =
dynamic_cast<const EvpnDerivedPath *>(&r_path);
if (r_evpn_path != NULL) {
if (r_evpn_path->ip_addr() != ip_addr_) {
return (ip_addr_ < r_evpn_path->ip_addr());
}
}
return peer()->IsLess(r_path.peer());
}
const NextHop *EvpnDerivedPath::ComputeNextHop(Agent *agent) const {
return nexthop();
}
EvpnDerivedPathData::EvpnDerivedPathData(const EvpnRouteEntry *evpn_rt) :
AgentRouteData(false), ethernet_tag_(evpn_rt->ethernet_tag()),
ip_addr_(evpn_rt->ip_addr()), reference_path_(evpn_rt->GetActivePath()),
ecmp_suppressed_(false) {
// For debuging add peer of active path in parent as well
std::stringstream s;
s << evpn_rt->ToString();
s << " ";
if (reference_path_ && reference_path_->peer())
s << reference_path_->peer()->GetName();
parent_ = s.str();
}
AgentPath *EvpnDerivedPathData::CreateAgentPath(const Peer *peer,
AgentRoute *rt) const {
const EvpnPeer *evpn_peer = dynamic_cast<const EvpnPeer *>(peer);
assert(evpn_peer != NULL);
return (new EvpnDerivedPath(evpn_peer, ip_addr_, ethernet_tag_,
parent_));
}
bool EvpnDerivedPathData::AddChangePath(Agent *agent, AgentPath *path,
const AgentRoute *rt) {
bool ret = false;
EvpnDerivedPath *evpn_path = dynamic_cast<EvpnDerivedPath *>(path);
assert(evpn_path != NULL);
evpn_path->set_tunnel_dest(reference_path_->tunnel_dest());
uint32_t label = reference_path_->label();
if (evpn_path->label() != label) {
evpn_path->set_label(label);
ret = true;
}
uint32_t vxlan_id = reference_path_->vxlan_id();
if (evpn_path->vxlan_id() != vxlan_id) {
evpn_path->set_vxlan_id(vxlan_id);
ret = true;
}
uint32_t tunnel_bmap = reference_path_->tunnel_bmap();
if (evpn_path->tunnel_bmap() != tunnel_bmap) {
evpn_path->set_tunnel_bmap(tunnel_bmap);
ret = true;
}
TunnelType::Type tunnel_type = reference_path_->tunnel_type();
if (evpn_path->tunnel_type() != tunnel_type) {
evpn_path->set_tunnel_type(tunnel_type);
ret = true;
}
PathPreference pref = reference_path_->path_preference();
if (evpn_path->path_preference() != pref) {
// Take path preference from parent path
evpn_path->set_path_preference(pref);
ret = true;
}
if (evpn_path->nexthop() !=
reference_path_->nexthop()) {
evpn_path->set_nexthop(reference_path_->nexthop());
ret = true;
}
const SecurityGroupList &sg_list = reference_path_->sg_list();
if (evpn_path->sg_list() != sg_list) {
evpn_path->set_sg_list(sg_list);
ret = true;
}
const VnListType &dest_vn_list = reference_path_->dest_vn_list();
if (evpn_path->dest_vn_list() != dest_vn_list) {
evpn_path->set_dest_vn_list(dest_vn_list);
ret = true;
}
if (evpn_path->ecmp_suppressed() != ecmp_suppressed_) {
evpn_path->set_ecmp_suppressed(ecmp_suppressed_);
ret = true;
}
return ret;
}
bool HostRoute::AddChangePath(Agent *agent, AgentPath *path,
const AgentRoute *rt) {
bool ret = false;
NextHop *nh = NULL;
InterfaceNHKey key(intf_.Clone(), false, InterfaceNHFlags::INET4,
agent->pkt_interface_mac());
nh = static_cast<NextHop *>(agent->nexthop_table()->FindActiveEntry(&key));
VnListType dest_vn_list;
dest_vn_list.insert(dest_vn_name_);
if (path->dest_vn_list() != dest_vn_list) {
path->set_dest_vn_list(dest_vn_list);
ret = true;
}
path->set_unresolved(false);
if (path->ChangeNH(agent, nh) == true)
ret = true;
return ret;
}
bool HostRoute::UpdateRoute(AgentRoute *rt) {
bool ret = false;
InetUnicastRouteEntry *uc_rt =
static_cast<InetUnicastRouteEntry *>(rt);
AgentRouteTable *table = static_cast<AgentRouteTable *>(rt->get_table());
if ((table->GetTableType() != Agent::INET4_UNICAST) &&
(table->GetTableType() != Agent::INET6_UNICAST))
return ret;
if (uc_rt->proxy_arp() != true) {
uc_rt->set_proxy_arp(true);
ret = true;
}
return ret;
}
bool L2ReceiveRoute::AddChangePath(Agent *agent, AgentPath *path,
const AgentRoute *rt) {
bool ret = false;
path->set_unresolved(false);
VnListType dest_vn_list;
dest_vn_list.insert(dest_vn_name_);
if (path->dest_vn_list() != dest_vn_list) {
path->set_dest_vn_list(dest_vn_list);
ret = true;
}
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->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;
}
}
if (path->ChangeNH(agent, agent->nexthop_table()->l2_receive_nh()) == true)
ret = true;
return ret;
}
bool InetInterfaceRoute::UpdateRoute(AgentRoute *rt) {
bool ret = false;
AgentRouteTable *table = static_cast<AgentRouteTable *>(rt->get_table());
if ((table->GetTableType() != Agent::INET4_UNICAST) &&
(table->GetTableType() != Agent::INET6_UNICAST))
return ret;
InetUnicastRouteEntry *uc_rt =
static_cast<InetUnicastRouteEntry *>(rt);
if (uc_rt->proxy_arp() != true) {
uc_rt->set_proxy_arp(true);
ret = true;
}
if (uc_rt->ipam_subnet_route() == true) {
uc_rt->set_ipam_subnet_route(false);
ret = true;
}
return ret;
}
bool InetInterfaceRoute::AddChangePath(Agent *agent, AgentPath *path,
const AgentRoute *rt) {
bool ret = false;
NextHop *nh = NULL;
InterfaceNHKey key(intf_.Clone(), false, InterfaceNHFlags::INET4,
agent->pkt_interface_mac());
nh = static_cast<NextHop *>(agent->nexthop_table()->FindActiveEntry(&key));
if (path->dest_vn_list() != dest_vn_list_) {
path->set_dest_vn_list(dest_vn_list_);
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,
const AgentRoute *rt) {
bool ret = false;
VnListType dest_vn_list;
dest_vn_list.insert(vn_);
if (path->dest_vn_list() != dest_vn_list) {
path->set_dest_vn_list(dest_vn_list);
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,
const AgentRoute *rt) {
bool ret = false;
NextHop *nh = NULL;
SecurityGroupList path_sg_list;
CommunityList path_communities;
//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;
if (vm_port) {
// Use policy based NH if policy enabled on interface
if (vm_port->policy_enabled()) {
policy = true;
ret = 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;
}
MacAddress mac = MacAddress::ZeroMac();
if (vm_port) {
mac = vm_port->vm_mac();
const InetUnicastRouteEntry *ip_rt =
dynamic_cast<const InetUnicastRouteEntry *>(rt);
if (ip_rt) {
mac = vm_port->GetIpMac(ip_rt->addr(), ip_rt->plen());
}
}
InterfaceNHKey key(intf_.Clone(), policy, flags_, mac);
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_list() != dest_vn_list_) {
path->set_dest_vn_list(dest_vn_list_);
ret = true;
}
path_sg_list = path->sg_list();
if (path_sg_list != sg_list_) {
path->set_sg_list(sg_list_);
ret = true;
}
path_communities = path->communities();
if (path_communities != communities_) {
path->set_communities(communities_);
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->ComputeNextHop(agent) && path->ComputeNextHop(agent)->PolicyEnabled())
old_policy = true;
if (nh && nh->PolicyEnabled())
new_policy = true;
if (old_policy != new_policy) {
sync_route_ = true;
}
if (path->subnet_service_ip() != subnet_service_ip_) {
path->set_subnet_service_ip(subnet_service_ip_);
ret = true;
}
path->set_unresolved(false);
path->SyncRoute(sync_route_);
if (ecmp_load_balance_ != path->ecmp_load_balance()) {
path->set_ecmp_load_balance(ecmp_load_balance_);
ret = true;
}
if (path->ChangeNH(agent, nh) == true)
ret = true;
if (is_local_ != path->is_local()) {
path->set_is_local(is_local_);
ret = true;
}
return ret;
}
bool VlanNhRoute::AddChangePath(Agent *agent, AgentPath *path,
const AgentRoute *rt) {
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_list() != dest_vn_list_) {
path->set_dest_vn_list(dest_vn_list_);
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().ConfigChanged(path_preference_)) {
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,
const AgentRoute *rt) {
bool ret = false;
NextHop *nh = NULL;
ResolveNHKey key(intf_key_.get(), policy_);
nh = static_cast<NextHop *>(agent->nexthop_table()->FindActiveEntry(&key));
path->set_unresolved(false);
VnListType dest_vn_list;
dest_vn_list.insert(dest_vn_name_);
if (path->dest_vn_list() != dest_vn_list) {
path->set_dest_vn_list(dest_vn_list);
ret = true;
}
if (path->label() != label_) {
path->set_label(label_);
ret = true;
}
if (path->sg_list() != path_sg_list_) {
path->set_sg_list(path_sg_list_);
ret = true;
}
//By default resolve route on gateway interface
//is supported with MPLSoGRE or MplsoUdp port
path->set_tunnel_bmap(TunnelType::MplsType());
TunnelType::Type new_tunnel_type =
TunnelType::ComputeType(TunnelType::MplsType());
if (path->tunnel_type() != new_tunnel_type) {
path->set_tunnel_type(new_tunnel_type);
}
if (path->ChangeNH(agent, nh) == true)
ret = true;
return ret;
}
bool ReceiveRoute::AddChangePath(Agent *agent, AgentPath *path,
const AgentRoute *rt) {
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);
VnListType dest_vn_list;
dest_vn_list.insert(vn_);
if (path->dest_vn_list() != dest_vn_list) {
path->set_dest_vn_list(dest_vn_list);
ret = true;
}
if (path->label() != label_) {
path->set_label(label_);
ret = true;
}
if (path->ChangeNH(agent, nh) == true)
ret = true;
return ret;
}
bool ReceiveRoute::UpdateRoute(AgentRoute *rt) {
bool ret = false;
AgentRouteTable *table = static_cast<AgentRouteTable *>(rt->get_table());
if ((table->GetTableType() != Agent::INET4_UNICAST) &&
(table->GetTableType() != Agent::INET6_UNICAST))
return ret;
InetUnicastRouteEntry *uc_rt =
static_cast<InetUnicastRouteEntry *>(rt);
if (uc_rt->proxy_arp() != proxy_arp_) {
uc_rt->set_proxy_arp(proxy_arp_);
ret = true;
}
return ret;
}
bool MulticastRoute::AddChangePath(Agent *agent, AgentPath *path,
const AgentRoute *rt) {
bool ret = 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);
ret = MulticastRoute::CopyPathParameters(agent,
path,
vn_name_,
false,
vxlan_id_,
label_,
tunnel_type_,
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,
NextHop *nh) {
VnListType dest_vn_list;
dest_vn_list.insert(vn_name);
path->set_dest_vn_list(dest_vn_list);
path->set_unresolved(unresolved);
path->set_vxlan_id(vxlan_id);
if ((path->peer() != agent->local_vm_peer()) &&
(path->peer() != agent->local_peer()))
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(tunnel_type);
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->ChangeNH(agent, nh);
return true;
}
bool PathPreferenceData::AddChangePath(Agent *agent, AgentPath *path,
const AgentRoute *rt) {
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());
path_preference_.set_dependent_ip(path->path_preference().dependent_ip());
if (path &&
path->path_preference() != path_preference_) {
path->set_path_preference(path_preference_);
ret = true;
}
return ret;
}
// Subnet Route route data
IpamSubnetRoute::IpamSubnetRoute(DBRequest &nh_req,
const std::string &dest_vn_name) :
AgentRouteData(false), dest_vn_name_(dest_vn_name) {
nh_req_.Swap(&nh_req);
}
bool IpamSubnetRoute::AddChangePath(Agent *agent, AgentPath *path,
const AgentRoute *rt) {
agent->nexthop_table()->Process(nh_req_);
NextHop *nh = static_cast<NextHop *>(agent->nexthop_table()->
FindActiveEntry(nh_req_.key.get()));
assert(nh);
bool ret = false;
if (path->ChangeNH(agent, nh) == true) {
ret = true;