Line data Source code
1 : /* 2 : * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved. 3 : */ 4 : 5 : #ifndef vnsw_agent_nh_ksync_h 6 : #define vnsw_agent_nh_ksync_h 7 : 8 : #include <boost/asio.hpp> 9 : #include <boost/bind/bind.hpp> 10 : 11 : #include <db/db_entry.h> 12 : #include <db/db_table.h> 13 : #include <db/db_table_partition.h> 14 : #include <ksync/ksync_entry.h> 15 : #include <ksync/ksync_object.h> 16 : #include <ksync/ksync_netlink.h> 17 : #include <vrouter/ksync/interface_ksync.h> 18 : #include "oper/nexthop.h" 19 : 20 : #include "vr_nexthop.h" 21 : 22 : using namespace boost::placeholders; 23 : 24 : class NHKSyncObject; 25 : typedef std::vector<InterfaceKSyncEntry> InterfaceKSyncEntryList; 26 : 27 : class NHKSyncEntry : public KSyncNetlinkDBEntry { 28 : public: 29 : static const int kDefaultNhMsgSize = 4096; 30 : static const int MAX_VR_PHY_INTF = 3; 31 : NHKSyncEntry(NHKSyncObject *obj, const NHKSyncEntry *entry, 32 : uint32_t index); 33 : NHKSyncEntry(NHKSyncObject *obj, const NextHop *nh); 34 : virtual ~NHKSyncEntry(); 35 : 36 : const NextHop *nh() { return nh_; } 37 1109 : NextHop::Type type() const {return type_;} 38 4413 : InterfaceKSyncEntry *interface() const { 39 4413 : return static_cast<InterfaceKSyncEntry *>(interface_.get()); 40 : } 41 160 : std::vector<KSyncEntryPtr> interface_list() const { 42 160 : return interface_list_; 43 : } 44 160 : std::vector<int32_t> encap_valid_list() const { 45 160 : return encap_valid_list_; 46 : } 47 342 : InterfaceKSyncEntry *crypt_interface() const { 48 342 : return static_cast<InterfaceKSyncEntry *>(crypt_interface_.get()); 49 : } 50 : KSyncDBObject *GetObject() const; 51 : 52 : virtual bool IsLess(const KSyncEntry &rhs) const; 53 : virtual std::string ToString() const; 54 : virtual KSyncEntry *UnresolvedReference(); 55 : virtual bool Sync(DBEntry *e); 56 : virtual int AddMsg(char *buf, int buf_len); 57 : virtual int ChangeMsg(char *buf, int buf_len); 58 : virtual int DeleteMsg(char *buf, int buf_len); 59 : void FillObjectLog(sandesh_op::type op, KSyncNhInfo &info) const; 60 5175 : uint32_t nh_id() const { return nh_id_;} 61 : void SetEncap(InterfaceKSyncEntry *if_ksync, std::vector<int8_t> &encap, 62 : const int32_t index=-1); 63 99 : bool is_bridge() const { return is_bridge_; } 64 : bool is_vxlan_routing() const { return is_vxlan_routing_; } 65 : 66 320 : int MsgLen() { 67 : // for larger component NH lists, increase message length 68 320 : return kDefaultNhMsgSize * ((component_nh_list_.size() / 128) + 1); 69 : } 70 : uint8_t SetEcmpFieldsToUse(); 71 : bool KSyncEntrySandesh(Sandesh *resp); 72 35 : COMPOSITETYPE CompositeType() const { return comp_type_;} 73 : private: 74 : void SetKSyncNhListSandeshData(KSyncNhListSandeshData *data) const; 75 : class KSyncComponentNH { 76 : public: 77 368 : KSyncComponentNH(uint32_t label, KSyncEntry *entry) : 78 368 : label_(label), nh_(entry) { 79 368 : } 80 : 81 2718 : NHKSyncEntry *nh() const { 82 2718 : return static_cast<NHKSyncEntry *>(nh_.get()); 83 : } 84 : 85 177 : uint32_t label() const { 86 177 : return label_; 87 : } 88 : private: 89 : uint32_t label_; 90 : KSyncEntryPtr nh_; 91 : }; 92 : 93 : typedef std::vector<KSyncComponentNH> KSyncComponentNHList; 94 : 95 : int Encode(sandesh_op::type op, char *buf, int buf_len); 96 : NHKSyncObject *ksync_obj_; 97 : NextHop::Type type_; 98 : uint32_t vrf_id_; 99 : uint32_t label_; 100 : KSyncEntryPtr interface_; 101 : IpAddress sip_; 102 : IpAddress dip_; 103 : uint16_t sport_; 104 : uint16_t dport_; 105 : MacAddress smac_; 106 : MacAddress dmac_; 107 : MacAddress rewrite_dmac_; 108 : bool valid_; 109 : bool policy_; 110 : bool is_mcast_nh_; 111 : bool defer_; 112 : KSyncComponentNHList component_nh_list_; 113 : const NextHop *nh_; 114 : uint16_t vlan_tag_; 115 : bool is_local_ecmp_nh_; 116 : bool is_bridge_; 117 : bool is_vxlan_routing_; 118 : COMPOSITETYPE comp_type_; 119 : bool validate_mcast_src_; 120 : TunnelType tunnel_type_; 121 : uint8_t prefix_len_; 122 : uint32_t nh_id_; 123 : ComponentNHKeyList component_nh_key_list_; 124 : bool bridge_nh_; 125 : bool flood_unknown_unicast_; 126 : EcmpHashFields ecmp_hash_fieds_; 127 : KSyncEntryPtr pbb_child_nh_; 128 : uint32_t isid_; 129 : uint32_t pbb_label_; 130 : bool learning_enabled_; 131 : bool need_pbb_tunnel_; 132 : bool etree_leaf_; 133 : bool layer2_control_word_; 134 : bool crypt_; 135 : bool crypt_path_available_; 136 : KSyncEntryPtr crypt_interface_; 137 : TunnelType::Type transport_tunnel_type_; 138 : std::vector<KSyncEntryPtr> interface_list_; 139 : std::vector<int32_t> encap_valid_list_; 140 : std::vector<MacAddress> dmac_list_; 141 : DISALLOW_COPY_AND_ASSIGN(NHKSyncEntry); 142 : }; 143 : 144 : class NHKSyncObject : public KSyncDBObject { 145 : public: 146 : static const int kNHIndexCount = NH_TABLE_ENTRIES; 147 : NHKSyncObject(KSync *ksync); 148 : virtual ~NHKSyncObject(); 149 : 150 1462 : KSync *ksync() const { return ksync_; } 151 : 152 : virtual KSyncEntry *Alloc(const KSyncEntry *entry, uint32_t index); 153 : virtual KSyncEntry *DBToKSyncEntry(const DBEntry *e); 154 : void RegisterDBClients(); 155 : private: 156 : KSync *ksync_; 157 : DISALLOW_COPY_AND_ASSIGN(NHKSyncObject); 158 : }; 159 : 160 : #endif // vnsw_agent_nh_ksync_h