Line data Source code
1 : /* 2 : * Copyright (c) 2017 Juniper Networks, Inc. All rights reserved. 3 : */ 4 : #ifndef SRC_VNSW_AGENT_MAC_LEARNING_MAC_LEARNING_DB_CLIENT_H_ 5 : #define SRC_VNSW_AGENT_MAC_LEARNING_MAC_LEARNING_DB_CLIENT_H_ 6 : #include "cmn/agent.h" 7 : #include <oper/vn.h> 8 : #include <oper/vm.h> 9 : #include <oper/interface_common.h> 10 : #include <oper/nexthop.h> 11 : #include <oper/route_common.h> 12 : #include <oper/sg.h> 13 : #include <oper/vrf.h> 14 : #include <filter/acl.h> 15 : #include <oper/health_check.h> 16 : 17 : //Mac learning mgmt DB client module listens for all notification from 18 : //DB table and triggers change on the dependent MAC entries. 19 : //Add or Change of DB entry: 20 : // Request to revaluate DB entries is enqueued to MAC mgmt module 21 : // which in turn RESYNC's all the mac entries 22 : // 23 : //Delete of DB entry: 24 : // Request to delete DB Entry gets queued to MAC mgmt table, 25 : // which in turn deletes all the mac entries dependent on this 26 : // DB entry. 27 : // 28 : //Free of DB State: 29 : // DB state should be release till the depedent mac entries 30 : // have been deleted. Hence once the mac entries are deleted 31 : // request to free DB state gets enqued from mac mgmt module 32 : // to learning module, so that it happens in exclusion to DB. 33 : // 34 : class MacLearningDBClient { 35 : public: 36 : struct MacLearningDBState : public DBState { 37 87 : MacLearningDBState(): deleted_(false){} 38 : bool deleted_; 39 : uint32_t gen_id_; 40 : }; 41 : 42 : struct MacLearningIntfState: public MacLearningDBState { 43 : uint32_t l2_label_; 44 : VmInterface::SecurityGroupEntryList sg_l_; 45 : bool learning_enabled_; 46 : bool policy_enabled_; 47 : bool l2_active_; 48 : bool mac_ip_learning_enable_; 49 : }; 50 : 51 : struct MacLearningVrfState : public MacLearningDBState { 52 12 : MacLearningVrfState(): deleted_(false) {} 53 : void Register(MacLearningDBClient *client, VrfEntry *vrf); 54 : void Unregister(VrfEntry *vrf); 55 : bool deleted_; 56 : bool learning_enabled_; 57 : uint32_t isid_; 58 : DBTableBase::ListenerId bridge_listener_id_; 59 : DBTableBase::ListenerId evpn_listener_id_; 60 : }; 61 : struct MacLearningVnState : public MacLearningDBState { 62 12 : MacLearningVnState(): deleted_(false), mac_ip_learning_enabled_(false), 63 6 : hc_uuid_() {} 64 : bool deleted_; 65 : bool mac_ip_learning_enabled_; 66 : boost::uuids::uuid hc_uuid_; 67 : }; 68 : struct MacLearningHealthCheckState : public MacLearningDBState { 69 0 : MacLearningHealthCheckState(): deleted_(false) {} 70 : bool deleted_; 71 : uint32_t delay_; 72 : uint64_t delay_usecs_; 73 : uint32_t timeout_; 74 : uint64_t timeout_usecs_; 75 : uint32_t max_retries_; 76 : bool is_hc_enable_all_target_ips; 77 : std::set<IpAddress> hc_target_ip_list_; 78 : }; 79 : 80 : struct MacLearningRouteState : public MacLearningDBState { 81 : }; 82 : 83 : MacLearningDBClient(Agent *agent); 84 : virtual ~MacLearningDBClient(); 85 : void Init(); 86 : void Shutdown(); 87 : void FreeDBState(const DBEntry *db_entry, uint32_t gen_id); 88 : private: 89 : void AddEvent(const DBEntry *entry, MacLearningDBState *state); 90 : void DeleteEvent(const DBEntry *entry, MacLearningDBState *state); 91 : void DeleteNoOpEvent(const DBEntry *entry, MacLearningDBState *state); 92 : void ChangeEvent(const DBEntry *entry, MacLearningDBState *state); 93 : void ReleaseToken(const DBEntry *entry); 94 : void DeleteAllMac(const DBEntry *entry, MacLearningDBState *state); 95 : void InterfaceNotify(DBTablePartBase *part, DBEntryBase *e); 96 : void VrfNotify(DBTablePartBase *part, DBEntryBase *e); 97 : void RouteNotify(MacLearningVrfState *state, 98 : Agent::RouteTableType type, 99 : DBTablePartBase *partition, 100 : DBEntryBase *e); 101 : void EvpnRouteNotify(MacLearningVrfState *state, 102 : Agent::RouteTableType type, 103 : DBTablePartBase *partition, 104 : DBEntryBase *e); 105 : void VnNotify(DBTablePartBase *part, DBEntryBase *e); 106 : void HealthCheckNotify(DBTablePartBase *part, DBEntryBase *e); 107 : void FreeRouteState(const DBEntry *e, uint32_t gen_id); 108 : void EnqueueAgingTableDelete(const VrfEntry *vrf); 109 : Agent *agent_; 110 : DBTableBase::ListenerId interface_listener_id_; 111 : DBTableBase::ListenerId vrf_listener_id_; 112 : DBTableBase::ListenerId vn_listener_id_; 113 : DBTableBase::ListenerId hc_listener_id_; 114 : DISALLOW_COPY_AND_ASSIGN(MacLearningDBClient); 115 : }; 116 : #endif