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