Line data Source code
1 : /* 2 : * Copyright (c) 2020 Juniper Networks, Inc. All rights reserved. 3 : */ 4 : 5 : #ifndef SRC_VNSW_AGENT_MAC_IP_LEARNING_MAC_LEARNING_H_ 6 : #define SRC_VNSW_AGENT_MAC_IP_LEARNING_MAC_LEARNING_H_ 7 : 8 : #include <mutex> 9 : 10 : #include "cmn/agent.h" 11 : #include "mac_ip_learning_key.h" 12 : #include "mac_learning_base.h" 13 : #include "mac_learning_event.h" 14 : #include "pkt/flow_token.h" 15 : #include "health_check.h" 16 : 17 : class MacIpLearningTable; 18 : class MacIpLearningRequestQueue; 19 : class MacIpLearningEntry : public MacLearningEntry { 20 : public: 21 : MacIpLearningEntry(MacIpLearningTable *table, uint32_t vrf_id_, 22 : const IpAddress &ip, const MacAddress &mac, 23 : InterfaceConstRef intf); 24 0 : virtual ~MacIpLearningEntry() {} 25 : bool Add(); 26 : void Delete(); 27 : void Resync(); 28 0 : uint32_t vrf_id() { 29 0 : return key_.vrf_id_; 30 : } 31 0 : const Interface* intf() { 32 0 : return intf_.get(); 33 : } 34 0 : const VnEntry* Vn() { 35 0 : return vn_.get(); 36 : } 37 372 : const HealthCheckService* HcService() { 38 372 : return hc_service_; 39 : } 40 33 : const HealthCheckInstanceBase* HcInstance() { 41 33 : return hc_instance_; 42 : } 43 : MacIpLearningTable *mac_ip_learning_table() const { 44 : return mac_ip_learning_table_; 45 : } 46 0 : const MacIpLearningKey& key() const { 47 0 : return key_; 48 : } 49 0 : IpAddress& IpAddr() { 50 0 : return ip_; 51 : } 52 0 : MacAddress& Mac() { 53 0 : return mac_; 54 : } 55 : void EnqueueToTable(MacLearningEntryRequestPtr req); 56 : void AddHealthCheckService(HealthCheckService *service); 57 : void UpdateHealthCheckService(); 58 : HealthCheckService* GetHealthCheckService(const VnEntry *vn); 59 : 60 : private: 61 : MacIpLearningTable *mac_ip_learning_table_; 62 : MacIpLearningKey key_; 63 : IpAddress ip_; 64 : MacAddress mac_; 65 : InterfaceConstRef intf_; 66 : VnEntryConstRef vn_; 67 : HealthCheckService *hc_service_; 68 : HealthCheckInstanceBase *hc_instance_; 69 : DISALLOW_COPY_AND_ASSIGN(MacIpLearningEntry); 70 : }; 71 : 72 : class MacIpLearningTable { 73 : public: 74 : typedef std::pair<MacIpLearningKey, 75 : MacLearningEntryPtr> MacIpLearningEntryPair; 76 : typedef std::map<MacIpLearningKey, 77 : MacLearningEntryPtr, 78 : MacIpLearningKeyCmp> MacIpLearningEntryMap; 79 : 80 : MacIpLearningTable(Agent *agent, MacLearningProto *proto); 81 6 : virtual ~MacIpLearningTable() {} 82 : void Add(MacLearningEntryPtr ptr); 83 : void Resync(MacLearningEntryPtr ptr); 84 : void Delete(MacLearningEntryPtr ptr); 85 : void DetectIpMove(MacLearningEntryRequestPtr ptr); 86 : void MacIpEntryUnreachable(MacLearningEntryRequestPtr ptr); 87 : void MacIpEntryUnreachable(uint32_t vrf_id, IpAddress &ip, MacAddress &mac); 88 : void MacIpEntryHcNotify(const HealthCheckInstanceService *instance_service); 89 : MacIpLearningEntry* Find(const MacIpLearningKey &key); 90 : MacAddress GetPairedMacAddress(uint32_t vrf_id, const IpAddress &ip); 91 : //To be used in test cases only 92 : //MacLearningEntryPtr TestGet(const MacLearningKey &key); 93 : bool RequestHandler(MacLearningEntryRequestPtr ptr); 94 : 95 3 : Agent* agent() { 96 3 : return agent_; 97 : } 98 : 99 2 : void SetQueueDisable(bool disable) { 100 2 : work_queue_.SetQueueDisable(disable); 101 2 : } 102 : 103 : void Enqueue(MacLearningEntryRequestPtr req); 104 : void EnqueueMgmtReq(MacLearningEntryPtr ptr, bool add); 105 : 106 : private: 107 : Agent *agent_; 108 : MacIpLearningEntryMap mac_ip_learning_entry_map_; 109 : MacIpLearningRequestQueue work_queue_; 110 : std::mutex macip_map_mutex_; 111 : DISALLOW_COPY_AND_ASSIGN(MacIpLearningTable); 112 : }; 113 : #endif