/
vm_interface.h
1225 lines (1103 loc) · 48.8 KB
/
vm_interface.h
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.
*/
#ifndef vnsw_agent_vm_interface_hpp
#define vnsw_agent_vm_interface_hpp
#include <oper/oper_dhcp_options.h>
#include <oper/audit_list.h>
#include <oper/ecmp_load_balance.h>
/////////////////////////////////////////////////////////////////////////////
// Implementation of VM Port interfaces
/////////////////////////////////////////////////////////////////////////////
typedef std::vector<boost::uuids::uuid> SgUuidList;
typedef std::vector<SgEntryRef> SgList;
struct VmInterfaceData;
struct VmInterfaceConfigData;
struct VmInterfaceNovaData;
struct VmInterfaceIpAddressData;
struct VmInterfaceOsOperStateData;
struct VmInterfaceMirrorData;
class OperDhcpOptions;
class PathPreference;
class MetaDataIp;
class HealthCheckInstance;
class LocalVmPortPeer;
/////////////////////////////////////////////////////////////////////////////
// Definition for VmInterface
// Agent supports multiple type of VMInterfaces
// - VMI for a virtual-machine spawned on KVM compute node. It will have a TAP
// interface associated with it. Agent also expects a INSTANCE_MSG from
// nova-compute/equivalent to add this port
// DeviceType = VM_ON_TAP, VmiType = INSTANCE
// - VMI for a virtual-machine spawned on VMware ESXi. All virtual-machines
// are connected on a physical-port and VLAN is used to distinguish them
// DeviceType = VM_PHYSICAL_VLAN, VmiType = INTANCE, agent->hypervisor_mode = ESXi
// - VMI for a virtual-machine spawned on VMWare VCenter . All virtual-machines
// are connected on a physical-port and they are classified by the smac
// DeviceType = VM_PHYSICAL_MAC, VmiType = INTANCE and
// agent hypervisor mode = VCenter
// - VMI for service-chain virtual-machines
// - VMI for service-chain virtual-machine spawned on KVM compute node.
// It will have a TAP interface associated with it. Agent also expects a
// INSTANCE_MSG from interface associated with it.
// DeviceType = VM_ON_TAP, VmiType = SERVICE_CHAIN
// - VMI for service-instances spawned by agent itself.
// It will have a TAP interface associated with it. Agent also expects a
// INSTANCE_MSG from interface associated with it.
// DeviceType = VM, VmiType = SERVICE_INTANCE
//
/////////////////////////////////////////////////////////////////////////////
class VmInterface : public Interface {
public:
static const uint32_t kInvalidVlanId = 0xFFFF;
static const uint32_t kInvalidPmdId = 0xFFFF;
enum Configurer {
INSTANCE_MSG,
CONFIG
};
// Type of VMI Port
enum DeviceType {
DEVICE_TYPE_INVALID,
VM_ON_TAP, // VMI on TAP/physial port interface
// VMI is created based on the INSTANCE_MSG
VM_VLAN_ON_VMI, // VMI on TAP port with VLAN as classifier
// VMI is created based on config message
VM_PHYSICAL_VLAN, // VMI classified with VLAN on a physical-port
// (used in VMWare ESXi)
// VMI is created based on the INSTANCE_MSG
VM_PHYSICAL_MAC, // VMI classified with MAC on a physical-port
// (used in VMWare VCenter)
// VMI is created based on the INSTANCE_MSG
TOR, // Baremetal connected to ToR
LOCAL_DEVICE, // VMI on a local port. Used in GATEWAY
REMOTE_VM_VLAN_ON_VMI, // VMI on a local phy-port with VLAN as classifier
VM_SRIOV // VMI on an SRIOV VM
};
// Type of VM on the VMI
enum VmiType {
VMI_TYPE_INVALID,
INSTANCE,
SERVICE_CHAIN,
SERVICE_INSTANCE,
BAREMETAL,
GATEWAY,
REMOTE_VM,
SRIOV
};
enum ProxyArpMode {
PROXY_ARP_NONE,
PROXY_ARP_UNRESTRICTED,
PROXY_ARP_INVALID
};
struct ListEntry {
ListEntry() : installed_(false), del_pending_(false) { }
ListEntry(bool installed, bool del_pending) :
installed_(installed), del_pending_(del_pending) { }
virtual ~ListEntry() {}
bool installed() const { return installed_; }
bool del_pending() const { return del_pending_; }
void set_installed(bool val) const { installed_ = val; }
void set_del_pending(bool val) const { del_pending_ = val; }
mutable bool installed_;
mutable bool del_pending_;
};
// A unified structure for storing FloatingIp information for both
// operational and config elements
struct FloatingIp : public ListEntry {
FloatingIp();
FloatingIp(const FloatingIp &rhs);
FloatingIp(const IpAddress &addr, const std::string &vrf,
const boost::uuids::uuid &vn_uuid, const IpAddress &ip);
virtual ~FloatingIp();
bool operator() (const FloatingIp &lhs, const FloatingIp &rhs) const;
bool IsLess(const FloatingIp *rhs) const;
void L3Activate(VmInterface *interface, bool force_update) const;
void L3DeActivate(VmInterface *interface) const;
void L2Activate(VmInterface *interface, bool force_update,
uint32_t old_ethernet_tag) const;
void L2DeActivate(VmInterface *interface,
uint32_t ethernet_tag) const;
void DeActivate(VmInterface *interface, bool l2,
uint32_t old_ethernet_tag) const;
void Activate(VmInterface *interface, bool force_update,
bool l2, uint32_t old_ethernet_tag) const;
const IpAddress GetFixedIp(const VmInterface *) const;
IpAddress floating_ip_;
mutable VnEntryRef vn_;
mutable VrfEntryRef vrf_;
std::string vrf_name_;
boost::uuids::uuid vn_uuid_;
mutable bool l2_installed_;
mutable IpAddress fixed_ip_;
mutable bool force_l3_update_;
mutable bool force_l2_update_;
};
typedef std::set<FloatingIp, FloatingIp> FloatingIpSet;
typedef std::map<Ip4Address, MetaDataIp*> MetaDataIpMap;
typedef std::set<HealthCheckInstance *> HealthCheckInstanceSet;
struct FloatingIpList {
FloatingIpList() : v4_count_(0), v6_count_(0), list_() { }
~FloatingIpList() { }
void Insert(const FloatingIp *rhs);
void Update(const FloatingIp *lhs, const FloatingIp *rhs);
void Remove(FloatingIpSet::iterator &it);
uint16_t v4_count_;
uint16_t v6_count_;
FloatingIpSet list_;
};
// A unified structure for storing AliasIp information for both
// operational and config elements
struct AliasIp : public ListEntry {
AliasIp();
AliasIp(const AliasIp &rhs);
AliasIp(const IpAddress &addr, const std::string &vrf,
const boost::uuids::uuid &vn_uuid);
virtual ~AliasIp();
bool operator() (const AliasIp &lhs, const AliasIp &rhs) const;
bool IsLess(const AliasIp *rhs) const;
void Activate(VmInterface *interface, bool force_update) const;
void DeActivate(VmInterface *interface) const;
IpAddress alias_ip_;
mutable VnEntryRef vn_;
mutable VrfEntryRef vrf_;
std::string vrf_name_;
boost::uuids::uuid vn_uuid_;
mutable bool force_update_;
};
typedef std::set<AliasIp, AliasIp> AliasIpSet;
struct AliasIpList {
AliasIpList() : v4_count_(0), v6_count_(0), list_() { }
~AliasIpList() { }
void Insert(const AliasIp *rhs);
void Update(const AliasIp *lhs, const AliasIp *rhs);
void Remove(AliasIpSet::iterator &it);
uint16_t v4_count_;
uint16_t v6_count_;
AliasIpSet list_;
};
struct ServiceVlan : ListEntry {
ServiceVlan();
ServiceVlan(const ServiceVlan &rhs);
ServiceVlan(uint16_t tag, const std::string &vrf_name,
const Ip4Address &addr, const Ip6Address &addr6,
const MacAddress &smac, const MacAddress &dmac);
virtual ~ServiceVlan();
bool operator() (const ServiceVlan &lhs, const ServiceVlan &rhs) const;
bool IsLess(const ServiceVlan *rhs) const;
void Activate(VmInterface *interface, bool force_change,
bool old_ipv4_active, bool old_ipv6_active) const;
void DeActivate(VmInterface *interface) const;
void V4RouteDelete(const Peer *peer) const;
void V6RouteDelete(const Peer *peer) const;
uint16_t tag_;
std::string vrf_name_;
Ip4Address addr_;
Ip6Address addr6_;
MacAddress smac_;
MacAddress dmac_;
mutable VrfEntryRef vrf_;
mutable uint32_t label_;
mutable bool v4_rt_installed_;
mutable bool v6_rt_installed_;
};
typedef std::set<ServiceVlan, ServiceVlan> ServiceVlanSet;
struct ServiceVlanList {
ServiceVlanList() : list_() { }
~ServiceVlanList() { }
void Insert(const ServiceVlan *rhs);
void Update(const ServiceVlan *lhs, const ServiceVlan *rhs);
void Remove(ServiceVlanSet::iterator &it);
ServiceVlanSet list_;
};
struct StaticRoute : ListEntry {
StaticRoute();
StaticRoute(const StaticRoute &rhs);
StaticRoute(const std::string &vrf, const IpAddress &addr,
uint32_t plen, const IpAddress &gw,
const CommunityList &communities);
virtual ~StaticRoute();
bool operator() (const StaticRoute &lhs, const StaticRoute &rhs) const;
bool IsLess(const StaticRoute *rhs) const;
void Activate(VmInterface *interface, bool force_update) const;
void DeActivate(VmInterface *interface) const;
mutable std::string vrf_;
IpAddress addr_;
uint32_t plen_;
IpAddress gw_;
CommunityList communities_;
};
typedef std::set<StaticRoute, StaticRoute> StaticRouteSet;
struct StaticRouteList {
StaticRouteList() : list_() { }
~StaticRouteList() { }
void Insert(const StaticRoute *rhs);
void Update(const StaticRoute *lhs, const StaticRoute *rhs);
void Remove(StaticRouteSet::iterator &it);
StaticRouteSet list_;
};
struct AllowedAddressPair : ListEntry {
AllowedAddressPair();
AllowedAddressPair(const AllowedAddressPair &rhs);
AllowedAddressPair(const std::string &vrf, const IpAddress &addr,
uint32_t plen, bool ecmp, const MacAddress &mac);
virtual ~AllowedAddressPair();
bool operator() (const AllowedAddressPair &lhs,
const AllowedAddressPair &rhs) const;
bool IsLess(const AllowedAddressPair *rhs) const;
void Activate(VmInterface *interface, bool force_update,
bool policy_change) const;
void DeActivate(VmInterface *interface) const;
void L2Activate(VmInterface *interface, bool force_update,
bool policy_change, bool old_layer2_forwarding,
bool old_layer3_forwarding) const;
void L2DeActivate(VmInterface *interface) const;
void CreateLabelAndNH(Agent *agent, VmInterface *interface,
bool policy_change) const;
mutable std::string vrf_;
IpAddress addr_;
uint32_t plen_;
mutable bool ecmp_;
MacAddress mac_;
mutable bool l2_entry_installed_;
mutable bool l3_ecmp_config_changed_;
mutable bool l2_ecmp_config_changed_;
mutable uint32_t ethernet_tag_;
mutable VrfEntryRef vrf_ref_;
mutable IpAddress service_ip_;
mutable uint32_t label_;
mutable NextHopRef policy_enabled_nh_;
mutable NextHopRef policy_disabled_nh_;
};
typedef std::set<AllowedAddressPair, AllowedAddressPair>
AllowedAddressPairSet;
struct AllowedAddressPairList {
AllowedAddressPairList() : list_() { }
~AllowedAddressPairList() { }
void Insert(const AllowedAddressPair *rhs);
void Update(const AllowedAddressPair *lhs,
const AllowedAddressPair *rhs);
void Remove(AllowedAddressPairSet::iterator &it);
AllowedAddressPairSet list_;
};
struct SecurityGroupEntry : ListEntry {
SecurityGroupEntry();
SecurityGroupEntry(const SecurityGroupEntry &rhs);
SecurityGroupEntry(const boost::uuids::uuid &uuid);
virtual ~SecurityGroupEntry();
bool operator == (const SecurityGroupEntry &rhs) const;
bool operator() (const SecurityGroupEntry &lhs,
const SecurityGroupEntry &rhs) const;
bool IsLess(const SecurityGroupEntry *rhs) const;
void Activate(VmInterface *interface) const;
void DeActivate(VmInterface *interface) const;
mutable SgEntryRef sg_;
boost::uuids::uuid uuid_;
};
typedef std::set<SecurityGroupEntry, SecurityGroupEntry>
SecurityGroupEntrySet;
typedef std::vector<boost::uuids::uuid> SecurityGroupUuidList;
struct SecurityGroupEntryList {
SecurityGroupEntryList() : list_() { }
~SecurityGroupEntryList() { }
void Insert(const SecurityGroupEntry *rhs);
void Update(const SecurityGroupEntry *lhs,
const SecurityGroupEntry *rhs);
void Remove(SecurityGroupEntrySet::iterator &it);
SecurityGroupEntrySet list_;
};
struct VrfAssignRule : ListEntry {
VrfAssignRule();
VrfAssignRule(const VrfAssignRule &rhs);
VrfAssignRule(uint32_t id,
const autogen::MatchConditionType &match_condition_,
const std::string &vrf_name, bool ignore_acl);
~VrfAssignRule();
bool operator == (const VrfAssignRule &rhs) const;
bool operator() (const VrfAssignRule &lhs,
const VrfAssignRule &rhs) const;
bool IsLess(const VrfAssignRule *rhs) const;
const uint32_t id_;
mutable std::string vrf_name_;
mutable bool ignore_acl_;
mutable autogen::MatchConditionType match_condition_;
};
typedef std::set<VrfAssignRule, VrfAssignRule> VrfAssignRuleSet;
struct VrfAssignRuleList {
VrfAssignRuleList() : list_() { }
~VrfAssignRuleList() { };
void Insert(const VrfAssignRule *rhs);
void Update(const VrfAssignRule *lhs, const VrfAssignRule *rhs);
void Remove(VrfAssignRuleSet::iterator &it);
VrfAssignRuleSet list_;
};
struct InstanceIp : ListEntry {
InstanceIp();
InstanceIp(const InstanceIp &rhs);
InstanceIp(const IpAddress &ip, uint8_t plen, bool ecmp,
bool is_primary, bool is_service_health_check_ip,
bool is_local, const IpAddress &tracking_ip);
~InstanceIp();
bool operator == (const InstanceIp &rhs) const;
bool operator() (const InstanceIp &lhs,
const InstanceIp &rhs) const;
bool IsLess(const InstanceIp *rhs) const;
void L3Activate(VmInterface *interface, bool force_update) const;
void L3DeActivate(VmInterface *interface, VrfEntry *old_vrf) const;
void L2Activate(VmInterface *interface, bool force_update,
uint32_t old_ethernet_tag) const;
void L2DeActivate(VmInterface *interface, VrfEntry *old_vrf,
uint32_t old_ethernet_tag) const;
void DeActivate(VmInterface *interface, bool l2,
VrfEntry *old_vrf, uint32_t old_ethernet_tag) const;
void Activate(VmInterface *interface, bool force_update, bool l2,
int old_ethernet_tag) const;
void SetPrefixForAllocUnitIpam(VmInterface *interface) const;
bool installed() const {
if (l2_installed_ || installed_) {
return true;
}
return false;
}
bool is_force_policy() const {
return is_service_health_check_ip_;
}
bool IsL3Only() const {
return is_service_health_check_ip_;
}
const IpAddress ip_;
mutable uint8_t plen_;
mutable bool ecmp_;
mutable bool l2_installed_;
mutable bool is_primary_;
mutable bool is_service_health_check_ip_;
mutable bool is_local_;
mutable IpAddress old_tracking_ip_;
mutable IpAddress tracking_ip_;
mutable bool l3_ecmp_mode_changed_;
mutable bool l2_ecmp_mode_changed_;
};
typedef std::set<InstanceIp, InstanceIp> InstanceIpSet;
struct InstanceIpList {
InstanceIpList() : list_() { }
~InstanceIpList() { };
void Insert(const InstanceIp *rhs);
void Update(const InstanceIp *lhs, const InstanceIp *rhs);
void Remove(InstanceIpSet::iterator &it);
InstanceIpSet list_;
};
struct FatFlowEntry : ListEntry {
FatFlowEntry(): protocol(0), port(0) {}
FatFlowEntry(const FatFlowEntry &rhs):
protocol(rhs.protocol), port(rhs.port) {}
FatFlowEntry(const uint8_t proto, const uint16_t p):
protocol(proto), port(p) {}
virtual ~FatFlowEntry(){}
bool operator == (const FatFlowEntry &rhs) const {
return (rhs.protocol == protocol && rhs.port == port);
}
bool operator() (const FatFlowEntry &lhs,
const FatFlowEntry &rhs) const {
return lhs.IsLess(&rhs);
}
bool IsLess(const FatFlowEntry *rhs) const {
if (protocol != rhs->protocol) {
return protocol < rhs->protocol;
}
return port < rhs->port;
}
uint8_t protocol;
uint16_t port;
};
typedef std::set<FatFlowEntry, FatFlowEntry> FatFlowEntrySet;
struct FatFlowList {
FatFlowList(): list_() {}
~FatFlowList() {}
void Insert(const FatFlowEntry *rhs);
void Update(const FatFlowEntry *lhs, const FatFlowEntry *rhs);
void Remove(FatFlowEntrySet::iterator &it);
FatFlowEntrySet list_;
};
enum Trace {
ADD,
DELETE,
ACTIVATED_IPV4,
ACTIVATED_IPV6,
ACTIVATED_L2,
DEACTIVATED_IPV4,
DEACTIVATED_IPV6,
DEACTIVATED_L2,
FLOATING_IP_CHANGE,
SERVICE_CHANGE,
};
enum Preference {
INVALID = 0,
LOW = 100,
HIGH = 200
};
VmInterface(const boost::uuids::uuid &uuid);
VmInterface(const boost::uuids::uuid &uuid, const std::string &name,
const Ip4Address &addr, const MacAddress &mac,
const std::string &vm_name,
const boost::uuids::uuid &vm_project_uuid, uint16_t tx_vlan_id,
uint16_t rx_vlan_id, Interface *parent,
const Ip6Address &addr6, DeviceType dev_type, VmiType vmi_type);
virtual ~VmInterface();
virtual bool CmpInterface(const DBEntry &rhs) const;
virtual void GetOsParams(Agent *agent);
void SendTrace(const AgentDBTable *table, Trace event) const;
// DBEntry vectors
KeyPtr GetDBRequestKey() const;
std::string ToString() const;
bool Resync(const InterfaceTable *table, const VmInterfaceData *data);
bool OnChange(VmInterfaceData *data);
void PostAdd();
// Accessor functions
const VmEntry *vm() const { return vm_.get(); }
const VnEntry *vn() const { return vn_.get(); }
const MirrorEntry *mirror_entry() const { return mirror_entry_.get(); }
const Ip4Address &primary_ip_addr() const { return primary_ip_addr_; }
bool policy_enabled() const { return policy_enabled_; }
const Ip4Address &subnet_bcast_addr() const { return subnet_bcast_addr_; }
const Ip6Address &primary_ip6_addr() const { return primary_ip6_addr_; }
const MacAddress &vm_mac() const { return vm_mac_; }
bool fabric_port() const { return fabric_port_; }
bool need_linklocal_ip() const { return need_linklocal_ip_; }
bool drop_new_flows() const { return drop_new_flows_; }
bool dhcp_enable_config() const { return dhcp_enable_; }
void set_dhcp_enable_config(bool dhcp_enable) {
dhcp_enable_= dhcp_enable;
}
bool do_dhcp_relay() const { return do_dhcp_relay_; }
ProxyArpMode proxy_arp_mode() const { return proxy_arp_mode_; }
bool IsUnrestrictedProxyArp() const {
return proxy_arp_mode_ == PROXY_ARP_UNRESTRICTED;
}
int vxlan_id() const { return vxlan_id_; }
bool bridging() const { return bridging_; }
bool layer3_forwarding() const { return layer3_forwarding_; }
const std::string &vm_name() const { return vm_name_; }
const boost::uuids::uuid &vm_project_uuid() const { return vm_project_uuid_; }
const std::string &cfg_name() const { return cfg_name_; }
Preference local_preference() const { return local_preference_; }
uint16_t tx_vlan_id() const { return tx_vlan_id_; }
uint16_t rx_vlan_id() const { return rx_vlan_id_; }
const Interface *parent() const { return parent_.get(); }
bool ecmp() const { return ecmp_;}
bool ecmp6() const { return ecmp6_;}
Ip4Address service_ip() { return service_ip_;}
bool service_ip_ecmp() const { return service_ip_ecmp_;}
Ip6Address service_ip6() { return service_ip6_;}
bool service_ip_ecmp6() const { return service_ip_ecmp6_;}
const OperDhcpOptions &oper_dhcp_options() const { return oper_dhcp_options_; }
uint8_t configurer() const {return configurer_;}
bool IsConfigurerSet(VmInterface::Configurer type);
void SetConfigurer(VmInterface::Configurer type);
void ResetConfigurer(VmInterface::Configurer type);
bool CanBeDeleted() const {return (configurer_ == 0);}
const Ip4Address& subnet() const { return subnet_;}
const uint8_t subnet_plen() const { return subnet_plen_;}
const MacAddress& GetVifMac(const Agent*) const;
const boost::uuids::uuid &logical_interface() const {
return logical_interface_;
}
bool flood_unknown_unicast() const {
return flood_unknown_unicast_;
}
Interface::MirrorDirection mirror_direction() const {
return mirror_direction_;
}
const FloatingIpList &floating_ip_list() const {
return floating_ip_list_;
}
const AliasIpList &alias_ip_list() const {
return alias_ip_list_;
}
const ServiceVlanList &service_vlan_list() const {
return service_vlan_list_;
}
const StaticRouteList &static_route_list() const {
return static_route_list_;
}
const SecurityGroupEntryList &sg_list() const {
return sg_list_;
}
const VrfAssignRuleList &vrf_assign_rule_list() const {
return vrf_assign_rule_list_;
}
const AllowedAddressPairList &allowed_address_pair_list() const {
return allowed_address_pair_list_;
}
const InstanceIpList &instance_ipv4_list() const {
return instance_ipv4_list_;
}
const InstanceIpList &instance_ipv6_list() const {
return instance_ipv6_list_;
}
const FatFlowList &fat_flow_list() const {
return fat_flow_list_;
}
bool IsFatFlow(uint8_t protocol, uint16_t port) const;
void set_vxlan_id(int vxlan_id) { vxlan_id_ = vxlan_id; }
void set_subnet_bcast_addr(const Ip4Address &addr) {
subnet_bcast_addr_ = addr;
}
void set_mirror_entry (MirrorEntry *mirror_entry) {
mirror_entry_ = mirror_entry;
}
void set_mirror_direction(Interface::MirrorDirection mirror_direction) {
mirror_direction_ = mirror_direction;
}
void set_primary_ip_addr(const Ip4Address &addr) { primary_ip_addr_ = addr; }
const std::string GetAnalyzer() const;
void SetPathPreference(PathPreference *pref, bool ecmp,
const IpAddress &dependent_ip) const;
void SetServiceVlanPathPreference(PathPreference *pref,
const IpAddress &service_ip) const;
void CopySgIdList(SecurityGroupList *sg_id_list) const;
bool NeedMplsLabel() const;
bool IsVxlanMode() const;
bool SgExists(const boost::uuids::uuid &id, const SgList &sg_l);
bool IsMirrorEnabled() const { return mirror_entry_.get() != NULL; }
bool HasFloatingIp(Address::Family family) const;
bool HasFloatingIp() const;
bool IsFloatingIp(const IpAddress &ip) const;
VrfEntry *GetAliasIpVrf(const IpAddress &ip) const;
Ip4Address mdata_ip_addr() const;
MetaDataIp *GetMetaDataIp(const Ip4Address &ip) const;
const MacAddress& GetIpMac(const IpAddress &,
const uint8_t plen) const;
void InsertMetaDataIpInfo(MetaDataIp *mip);
void DeleteMetaDataIpInfo(MetaDataIp *mip);
void UpdateMetaDataIpInfo();
void InsertHealthCheckInstance(HealthCheckInstance *hc_inst);
void DeleteHealthCheckInstance(HealthCheckInstance *hc_inst);
const HealthCheckInstanceSet &hc_instance_set() const;
size_t GetFloatingIpCount() const { return floating_ip_list_.list_.size(); }
size_t GetAliasIpCount() const { return alias_ip_list_.list_.size(); }
bool HasServiceVlan() const { return service_vlan_list_.list_.size() != 0; }
uint32_t GetServiceVlanLabel(const VrfEntry *vrf) const;
uint32_t GetServiceVlanTag(const VrfEntry *vrf) const;
const VrfEntry* GetServiceVlanVrf(uint16_t vlan_tag) const;
bool Delete(const DBRequest *req);
void Add();
bool OnResyncServiceVlan(VmInterfaceConfigData *data);
void UpdateAllRoutes();
bool IsL2Active() const;
bool IsIpv6Active() const;
bool NeedDevice() const;
VmInterface::DeviceType device_type() const {return device_type_;}
VmInterface::VmiType vmi_type() const {return vmi_type_;}
// Add a vm-interface
static void NovaAdd(InterfaceTable *table,
const boost::uuids::uuid &intf_uuid,
const std::string &os_name, const Ip4Address &addr,
const std::string &mac, const std::string &vn_name,
const boost::uuids::uuid &vm_project_uuid,
uint16_t tx_vlan_id, uint16_t rx_vlan_id,
const std::string &parent, const Ip6Address &ipv6,
Interface::Transport transport);
// Del a vm-interface
static void Delete(InterfaceTable *table,
const boost::uuids::uuid &intf_uuid,
VmInterface::Configurer configurer);
void AllocL2MplsLabel(bool force_update, bool policy_change);
void DeleteL2MplsLabel();
const AclDBEntry* vrf_assign_acl() const { return vrf_assign_acl_.get();}
bool WaitForTraffic() const;
bool GetInterfaceDhcpOptions(
std::vector<autogen::DhcpOptionType> *options) const;
bool GetSubnetDhcpOptions(
std::vector<autogen::DhcpOptionType> *options, bool ipv6) const;
bool GetIpamDhcpOptions(
std::vector<autogen::DhcpOptionType> *options, bool ipv6) const;
const Peer *peer() const;
IpAddress GetServiceIp(const IpAddress &ip) const;
void UpdateL2InterfaceRoute(bool old_bridging, bool force_update,
VrfEntry *vrf,
const Ip4Address &old_addr,
const Ip6Address &old_v6_addr,
int ethernet_tag,
bool old_layer3_forwarding,
bool policy_change,
const Ip4Address &new_addr,
const Ip6Address &new_v6_addr,
const MacAddress &mac,
const IpAddress &dependent_ip,
bool ecmp) const;
uint32_t ethernet_tag() const {return ethernet_tag_;}
IpAddress service_health_check_ip() const { return service_health_check_ip_; }
void UpdateVxLan();
bool IsActive() const;
const VmiEcmpLoadBalance &ecmp_load_balance() const {return ecmp_load_balance_;}
bool InstallBridgeRoutes() const;
Agent *agent() const {
return (static_cast<InterfaceTable *>(get_table()))->agent();
}
bool is_vn_qos_config() const {
return is_vn_qos_config_;
}
const NextHop* l3_interface_nh_no_policy() const {
return l3_interface_nh_no_policy_.get();
}
private:
friend struct VmInterfaceConfigData;
friend struct VmInterfaceNovaData;
friend struct VmInterfaceIpAddressData;
friend struct VmInterfaceOsOperStateData;
friend struct VmInterfaceMirrorData;
friend struct VmInterfaceGlobalVrouterData;
friend struct VmInterfaceHealthCheckData;
friend struct VmInterfaceNewFlowDropData;
bool IsMetaDataL2Active() const;
bool IsMetaDataIPActive() const;
bool IsIpv4Active() const;
bool PolicyEnabled() const;
void AddRoute(const std::string &vrf_name, const IpAddress &ip,
uint32_t plen, const std::string &vn_name, bool force_policy,
bool ecmp, bool is_local, bool proxy_arp,
const IpAddress &service_ip, const IpAddress &dependent_ip,
const CommunityList &communties, uint32_t label);
void DeleteRoute(const std::string &vrf_name, const IpAddress &ip,
uint32_t plen);
void ResolveRoute(const std::string &vrf_name, const Ip4Address &addr,
uint32_t plen, const std::string &dest_vn, bool policy);
void ServiceVlanAdd(ServiceVlan &entry);
void ServiceVlanDel(ServiceVlan &entry);
void ServiceVlanRouteAdd(const ServiceVlan &entry, bool force_update);
void ServiceVlanRouteDel(const ServiceVlan &entry);
bool OnResyncSecurityGroupList(VmInterfaceConfigData *data,
bool new_ipv4_active);
bool OnResyncStaticRoute(VmInterfaceConfigData *data, bool new_ipv4_active);
bool ResyncIpAddress(const VmInterfaceIpAddressData *data);
bool ResyncOsOperState(const VmInterfaceOsOperStateData *data);
bool ResyncConfig(VmInterfaceConfigData *data);
bool CopyIpAddress(Ip4Address &addr);
bool CopyIp6Address(const Ip6Address &addr);
void ApplyMacVmBindingConfig(const VrfEntry *old_vrf,
bool old_l2_active,
bool old_dhcp_enable);
void ApplyConfigCommon(const VrfEntry *old_vrf,
bool old_l2_active,
bool old_dhcp_enable);
bool CopyConfig(const InterfaceTable *table,
const VmInterfaceConfigData *data, bool *sg_changed,
bool *ecmp_changed, bool *local_pref_changed,
bool *ecmp_load_balance_changed,
bool *static_route_config_changed);
void ApplyConfig(bool old_ipv4_active,bool old_l2_active, bool old_policy,
VrfEntry *old_vrf, const Ip4Address &old_addr,
int old_ethernet_tag, bool old_need_linklocal_ip,
bool old_ipv6_active, const Ip6Address &old_v6_addr,
const Ip4Address &old_subnet, const uint8_t old_subnet_plen,
bool old_dhcp_enable, bool old_layer3_forwarding,
bool force_update, const Ip4Address &old_dhcp_addr,
bool old_metadata_ip_active, bool old_bridging);
void UpdateL3MetadataIp(VrfEntry *old_vrf, bool force_update,
bool policy_change, bool old_metadata_ip_active);
void DeleteL3MetadataIp(VrfEntry *old_vrf, bool force_update,
bool policy_change, bool old_metadata_ip_active,
bool old_need_linklocal_ip);
void UpdateL3(bool old_ipv4_active, VrfEntry *old_vrf,
const Ip4Address &old_addr, int old_ethernet_tag,
bool force_update, bool policy_change,
bool old_ipv6_active, const Ip6Address &old_v6_addr,
const Ip4Address &subnet, const uint8_t old_subnet_plen,
const Ip4Address &old_dhcp_addr);
void DeleteL3(bool old_ipv4_active, VrfEntry *old_vrf,
const Ip4Address &old_addr, bool old_need_linklocal_ip,
bool old_ipv6_active, const Ip6Address &old_v6_addr,
const Ip4Address &old_subnet, const uint8_t old_subnet_plen,
int old_ethernet_tag, const Ip4Address &old_dhcp_addr,
bool force_update);
void UpdateBridgeRoutes(bool old_bridging, VrfEntry *old_vrf,
int old_ethernet_tag, bool force_update,
bool policy_change, const Ip4Address &old_addr,
const Ip6Address &old_v6_addr,
bool old_layer3_forwarding);
void DeleteBridgeRoutes(bool old_bridging, VrfEntry *old_vrf,
int old_ethernet_tag, const Ip4Address &old_addr,
const Ip6Address &old_v6_addr,
bool old_layer3_forwarding, bool force_update);
void UpdateL2(bool old_l2_active, bool policy_change);
void DeleteL2(bool old_l2_active);
void AllocL3MplsLabel(bool force_update, bool policy_change,
uint32_t new_label);
void DeleteL3MplsLabel();
void UpdateL3TunnelId(bool force_update, bool policy_change);
void DeleteL3TunnelId();
void UpdateMacVmBinding();
void UpdateL3NextHop();
void DeleteL3NextHop();
void UpdateL2NextHop();
void UpdateFlowKeyNextHop();
void DeleteL2NextHop();
void DeleteMacVmBinding(const VrfEntry *old_vrf);
bool L2Activated(bool old_l2_active);
bool BridgingActivated(bool old_bridging);
bool Ipv4Activated(bool old_ipv4_active);
bool Ipv6Activated(bool old_ipv6_active);
bool L2Deactivated(bool old_l2_active);
bool BridgingDeactivated(bool old_bridging);
bool Ipv4Deactivated(bool old_ipv4_active);
bool Ipv6Deactivated(bool old_ipv6_active);
void UpdateIpv4InterfaceRoute(bool old_ipv4_active, bool force_update,
VrfEntry * old_vrf,
const Ip4Address &old_addr);
void DeleteIpv4InterfaceRoute(VrfEntry *old_vrf,
const Ip4Address &old_addr);
void UpdateResolveRoute(bool old_ipv4_active, bool force_update,
bool policy_change, VrfEntry * old_vrf,
const Ip4Address &old_addr, uint8_t old_plen);
void DeleteResolveRoute(VrfEntry *old_vrf,
const Ip4Address &old_addr, const uint8_t old_plen);
void DeleteInterfaceNH();
void UpdateMetadataRoute(bool old_ipv4_active, VrfEntry *old_vrf);
void DeleteMetadataRoute(bool old_ipv4_active, VrfEntry *old_vrf,
bool old_need_linklocal_ip);
void CleanupFloatingIpList();
void UpdateFloatingIp(bool force_update, bool policy_change, bool l2,
uint32_t old_ethernet_tag);
void DeleteFloatingIp(bool l2, uint32_t old_ethernet_tag);
void CleanupAliasIpList();
void UpdateAliasIp(bool force_update, bool policy_change);
void DeleteAliasIp();
void UpdateServiceVlan(bool force_update, bool policy_change,
bool old_ipv4_active, bool old_ipv6_active);
void DeleteServiceVlan();
void UpdateStaticRoute(bool force_update);
void DeleteStaticRoute();
void UpdateAllowedAddressPair(bool force_update, bool policy_change,
bool l2, bool old_l2_forwarding,
bool old_l3_forwarding);
void DeleteAllowedAddressPair(bool l2);
void UpdateSecurityGroup();
void DeleteSecurityGroup();
void UpdateFatFlow();
void DeleteFatFlow();
void UpdateL2TunnelId(bool force_update, bool policy_change);
void DeleteL2TunnelId();
void DeleteL2InterfaceRoute(bool old_bridging, VrfEntry *old_vrf,
const Ip4Address &old_v4_addr,
const Ip6Address &old_v6_addr,
int old_ethernet_tag,
const MacAddress &mac) const;
void UpdateVrfAssignRule();
void DeleteVrfAssignRule();
void UpdateIpv4InstanceIp(bool force_update, bool policy_change,
bool l2, uint32_t old_ethernet_tag,
VrfEntry *old_vrf);
void DeleteIpv4InstanceIp(bool l2, uint32_t old_ethernet_tag,
VrfEntry *old_vrf, bool force_update);
void UpdateIpv6InstanceIp(bool force_update, bool policy_change,
bool l2, uint32_t old_ethernet_tag);
void DeleteIpv6InstanceIp(bool l2, uint32_t old_ethernet_tag,
VrfEntry *old_vrf, bool force_update);
void AddL2ReceiveRoute(bool old_bridging);
void DeleteL2ReceiveRoute(const VrfEntry *old_vrf, bool old_briding);
bool UpdateIsHealthCheckActive();
void CopyEcmpLoadBalance(EcmpLoadBalance &ecmp_load_balance);
void UpdateCommonNextHop();
void DeleteCommonNextHop();
VmEntryBackRef vm_;
VnEntryRef vn_;
Ip4Address primary_ip_addr_;
std::auto_ptr<MetaDataIp> mdata_ip_;
Ip4Address subnet_bcast_addr_;
Ip6Address primary_ip6_addr_;
MacAddress vm_mac_;
bool policy_enabled_;
MirrorEntryRef mirror_entry_;
Interface::MirrorDirection mirror_direction_;
std::string cfg_name_;
bool fabric_port_;
bool need_linklocal_ip_;
bool drop_new_flows_;
// DHCP flag - set according to the dhcp option in the ifmap subnet object.
// It controls whether the vrouter sends the DHCP requests from VM interface
// to agent or if it would flood the request in the VN.
bool dhcp_enable_;
// true if IP is to be obtained from DHCP Relay and not learnt from fabric
bool do_dhcp_relay_;
// Proxy ARP mode for interface
ProxyArpMode proxy_arp_mode_;
// VM-Name. Used by DNS
std::string vm_name_;
// project uuid of the vm to which the interface belongs
boost::uuids::uuid vm_project_uuid_;
int vxlan_id_;
bool bridging_;
bool layer3_forwarding_;
bool flood_unknown_unicast_;
bool mac_set_;
bool ecmp_;
bool ecmp6_;
Ip4Address service_ip_;
bool service_ip_ecmp_;
Ip6Address service_ip6_;
bool service_ip_ecmp6_;
// disable-policy configuration on VMI. When this is configured, policy
// dependent features like flows, floating-IP and SG will not work on this
// VMI. However metadata-services will work because metadata route will
// still point to policy enabled NH.
bool disable_policy_;
// VLAN Tag and the parent interface when VLAN is enabled
uint16_t tx_vlan_id_;
uint16_t rx_vlan_id_;
InterfaceRef parent_;
Preference local_preference_;
// DHCP options defined for the interface
OperDhcpOptions oper_dhcp_options_;
// Lists
SecurityGroupEntryList sg_list_;
FloatingIpList floating_ip_list_;
AliasIpList alias_ip_list_;
ServiceVlanList service_vlan_list_;
StaticRouteList static_route_list_;
AllowedAddressPairList allowed_address_pair_list_;
InstanceIpList instance_ipv4_list_;
InstanceIpList instance_ipv6_list_;
FatFlowList fat_flow_list_;
// Peer for interface routes
std::auto_ptr<LocalVmPortPeer> peer_;
VrfAssignRuleList vrf_assign_rule_list_;
AclDBEntryRef vrf_assign_acl_;
Ip4Address vm_ip_service_addr_;
VmInterface::DeviceType device_type_;
VmInterface::VmiType vmi_type_;
uint8_t configurer_;
Ip4Address subnet_;
uint8_t subnet_plen_;
int ethernet_tag_;
// Logical interface uuid to which the interface belongs
boost::uuids::uuid logical_interface_;
Ip4Address nova_ip_addr_;
Ip6Address nova_ip6_addr_;
Ip4Address dhcp_addr_;
MetaDataIpMap metadata_ip_map_;
HealthCheckInstanceSet hc_instance_set_;
VmiEcmpLoadBalance ecmp_load_balance_;
IpAddress service_health_check_ip_;
NextHopRef l3_interface_nh_policy_;
NextHopRef l2_interface_nh_policy_;
NextHopRef l3_interface_nh_no_policy_;
NextHopRef l2_interface_nh_no_policy_;
bool is_vn_qos_config_;
DISALLOW_COPY_AND_ASSIGN(VmInterface);
};
/////////////////////////////////////////////////////////////////////////////
// Key for VM Interfaces
/////////////////////////////////////////////////////////////////////////////
struct VmInterfaceKey : public InterfaceKey {
VmInterfaceKey(AgentKey::DBSubOperation sub_op,
const boost::uuids::uuid &uuid, const std::string &name);
virtual ~VmInterfaceKey() { }
Interface *AllocEntry(const InterfaceTable *table) const;
Interface *AllocEntry(const InterfaceTable *table,
const InterfaceData *data) const;
InterfaceKey *Clone() const;