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