Line data Source code
1 : /* 2 : * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved. 3 : */ 4 : 5 : #ifndef vnsw_agent_interface_ksync_h 6 : #define vnsw_agent_interface_ksync_h 7 : 8 : #include <net/ethernet.h> 9 : 10 : #include <boost/asio.hpp> 11 : #include <boost/bind/bind.hpp> 12 : 13 : #include <db/db_entry.h> 14 : #include <db/db_table.h> 15 : #include <db/db_table_partition.h> 16 : #include <ksync/ksync_entry.h> 17 : #include <ksync/ksync_object.h> 18 : #include <ksync/ksync_netlink.h> 19 : #include <ksync/ksync_sock.h> 20 : #include "oper/interface_common.h" 21 : #include "vrouter/ksync/agent_ksync_types.h" 22 : #include "vr_types.h" 23 : 24 : using namespace boost::placeholders; 25 : 26 : void KSyncInterfaceCreate(Interface::Type type, const char *if_name, 27 : uint32_t vrf_id, uint32_t &ifindex, uint32_t &fd, 28 : MacAddress &mac); 29 : void KSyncInterfaceDelete(Interface::Type type, const char *if_name, 30 : uint32_t vrf_id, uint32_t ifindex, uint32_t fd); 31 : void GetPhyMac(const char *ifname, char *mac); 32 : 33 : class Timer; 34 : class InterfaceKSyncObject; 35 : 36 : class InterfaceKSyncEntry : public KSyncNetlinkDBEntry { 37 : public: 38 : static const int kDefaultInterfaceMsgSize = KSYNC_DEFAULT_MSG_SIZE; 39 : 40 : InterfaceKSyncEntry(InterfaceKSyncObject *obj, 41 : const InterfaceKSyncEntry *entry, uint32_t index); 42 : InterfaceKSyncEntry(InterfaceKSyncObject *obj, const Interface *intf); 43 : virtual ~InterfaceKSyncEntry(); 44 : 45 312 : const MacAddress &mac() const { 46 312 : if (parent_.get() == NULL) { 47 283 : return mac_; 48 : } else { 49 : const InterfaceKSyncEntry *parent = 50 29 : static_cast<const InterfaceKSyncEntry *>(parent_.get()); 51 29 : return parent->mac(); 52 : } 53 : } 54 0 : const MacAddress &smac() const {return smac_;} 55 : 56 288 : uint32_t interface_id() const {return interface_id_;} 57 192 : const string &interface_name() const {return interface_name_;} 58 0 : bool has_service_vlan() const {return has_service_vlan_;} 59 127 : bool no_arp() const { return no_arp_; } 60 214 : PhysicalInterface::EncapType encap_type() const { return encap_type_; } 61 : 62 : KSyncDBObject *GetObject() const; 63 : virtual bool Sync(DBEntry *e); 64 : virtual bool IsLess(const KSyncEntry &rhs) const; 65 : virtual std::string ToString() const; 66 : virtual int AddMsg(char *buf, int buf_len); 67 : virtual int ChangeMsg(char *buf, int buf_len); 68 : virtual int DeleteMsg(char *buf, int buf_len); 69 : virtual KSyncEntry *UnresolvedReference(); 70 : void FillObjectLog(sandesh_op::type op, KSyncIntfInfo &info) const; 71 : bool drop_new_flows() const {return drop_new_flows_;} 72 108 : bool dhcp_enable() const {return dhcp_enable_;} 73 : bool dhcp_enable_v6() const {return dhcp_enable_v6_;} 74 : bool layer3_forwarding() const {return layer3_forwarding_;} 75 : bool bridging() const {return bridging_;} 76 3 : bool pbb_interface() const {return pbb_interface_;} 77 2 : const MacAddress &pbb_mac() const { return pbb_mac_; } 78 : 79 73 : int MsgLen() { return kDefaultInterfaceMsgSize; } 80 : bool KSyncEntrySandesh(Sandesh *resp); 81 : 82 : private: 83 : friend class InterfaceKSyncObject; 84 : int Encode(sandesh_op::type op, char *buf, int buf_len); 85 : void SetKsyncItfSandeshData(KSyncItfSandeshData *data) const; 86 : 87 : string analyzer_name_; 88 : bool drop_new_flows_; 89 : bool dhcp_enable_; 90 : bool dhcp_enable_v6_; 91 : uint32_t fd_; // FD opened for this 92 : uint32_t flow_key_nh_id_; 93 : bool has_service_vlan_; 94 : uint32_t interface_id_; 95 : string interface_name_; // Key 96 : uint32_t ip_; 97 : Ip6Address primary_ip6_; 98 : bool hc_active_; 99 : bool ipv4_active_; 100 : bool layer3_forwarding_; 101 : InterfaceKSyncObject *ksync_obj_; 102 : bool l2_active_; 103 : bool metadata_l2_active_; 104 : bool metadata_ip_active_; 105 : bool bridging_; 106 : VmInterface::ProxyArpMode proxy_arp_mode_; 107 : MacAddress mac_; 108 : MacAddress smac_; 109 : Interface::MirrorDirection mirror_direction_; 110 : int network_id_; 111 : size_t os_index_; 112 : KSyncEntryPtr parent_; 113 : bool policy_enabled_; 114 : InetInterface::SubType sub_type_; 115 : VmInterface::DeviceType vmi_device_type_; 116 : VmInterface::VmiType vmi_type_; 117 : VmInterface::HbsIntfType hbs_intf_type_; 118 : Interface::Type type_; 119 : uint16_t rx_vlan_id_; 120 : uint16_t tx_vlan_id_; 121 : uint32_t vrf_id_; 122 : uint32_t multicast_vrf_id_; 123 : bool persistent_; 124 : PhysicalInterface::SubType subtype_; 125 : KSyncEntryPtr xconnect_; 126 : bool no_arp_; 127 : PhysicalInterface::EncapType encap_type_; 128 : std::string display_name_; 129 : Interface::Transport transport_; 130 : bool flood_unknown_unicast_; 131 : VmInterface::FatFlowList fat_flow_list_; 132 : VmInterface::FatFlowExcludeList fat_flow_exclude_list_; 133 : std::set<MacAddress> aap_mac_list_; 134 : KSyncEntryPtr qos_config_; 135 : bool learning_enabled_; 136 : uint32_t isid_; 137 : uint32_t pbb_cmac_vrf_; 138 : MacAddress pbb_mac_; 139 : bool etree_leaf_; 140 : bool pbb_interface_; 141 : uint8_t vhostuser_mode_; 142 : bool igmp_enable_; 143 : bool mac_ip_learning_enable_; 144 : boost::optional<InterfaceOsParams::IfGuid> os_guid_; 145 : std::vector<KSyncEntryPtr> xconnect_list_; 146 : DISALLOW_COPY_AND_ASSIGN(InterfaceKSyncEntry); 147 : }; 148 : 149 : class InterfaceKSyncObject : public KSyncDBObject { 150 : public: 151 : InterfaceKSyncObject(KSync *parent); 152 : virtual ~InterfaceKSyncObject(); 153 : 154 2727 : KSync *ksync() const { return ksync_; } 155 : 156 : void Init(); 157 : void InitTest(); 158 : virtual KSyncEntry *Alloc(const KSyncEntry *entry, uint32_t index); 159 : virtual KSyncEntry *DBToKSyncEntry(const DBEntry *e); 160 : void RegisterDBClients(); 161 : DBFilterResp DBEntryFilter(const DBEntry *e, const KSyncDBEntry *k); 162 : 163 : private: 164 : KSync *ksync_; 165 : DISALLOW_COPY_AND_ASSIGN(InterfaceKSyncObject); 166 : }; 167 : 168 : #endif // vnsw_agent_interface_ksync_h