Line data Source code
1 : /* 2 : * Copyright (c) 2017 Juniper Networks, Inc. All rights reserved. 3 : * Copyright Contributors to the OpenSDN project 4 : */ 5 : 6 : #ifndef SRC_VNSW_AGENT_MAC_LEARNING_MAC_LEARNING_EVENT_H_ 7 : #define SRC_VNSW_AGENT_MAC_LEARNING_MAC_LEARNING_EVENT_H_ 8 : 9 : #include "cmn/agent.h" 10 : #include "mac_learning_key.h" 11 : #include "mac_learning_base.h" 12 : 13 : class MacLearningPartition; 14 : class MacIpLearningTable; 15 : 16 : class MacLearningEntryRequest { 17 : public: 18 : enum Event { 19 : INVALID, 20 : VROUTER_MSG, 21 : ADD_MAC, 22 : RESYNC_MAC, 23 : DELETE_MAC, 24 : FREE_DB_ENTRY, 25 : DELETE_VRF, 26 : REMOTE_MAC_IP, 27 : MAC_IP_UNREACHABLE 28 : 29 : }; 30 : 31 0 : MacLearningEntryRequest(Event event, PktInfoPtr pkt): 32 0 : event_(event), pkt_info_(pkt) {} 33 3576 : MacLearningEntryRequest(Event event, MacLearningEntryPtr ptr): 34 3576 : event_(event), mac_learning_entry_(ptr) { 35 3578 : } 36 : 37 74 : MacLearningEntryRequest(Event event, uint32_t vrf_id): 38 74 : event_(event), vrf_id_(vrf_id) { 39 74 : } 40 6 : MacLearningEntryRequest(Event event, uint32_t vrf_id, 41 6 : IpAddress &ip, MacAddress &mac): 42 6 : event_(event), vrf_id_(vrf_id), ip_(ip), mac_(mac) { 43 6 : } 44 : 45 736 : MacLearningEntryRequest(Event event, const DBEntry *entry, 46 736 : uint32_t gen_id): 47 736 : event_(event), db_entry_(entry), gen_id_(gen_id) {} 48 : 49 0 : MacLearningEntryPtr mac_learning_entry() { 50 0 : return mac_learning_entry_; 51 : } 52 : 53 1552 : Event event() { 54 1552 : return event_; 55 : } 56 : 57 736 : const DBEntry *db_entry() { 58 736 : return db_entry_; 59 : } 60 : 61 0 : PktInfoPtr pkt_info() { 62 0 : return pkt_info_; 63 : } 64 : 65 80 : uint32_t vrf_id() { 66 80 : return vrf_id_; 67 : } 68 : 69 736 : uint32_t gen_id() { 70 736 : return gen_id_; 71 : } 72 6 : IpAddress ip() { 73 6 : return ip_; 74 : } 75 0 : MacAddress mac() { 76 0 : return mac_; 77 : } 78 : 79 : private: 80 : Event event_; 81 : MacLearningEntryPtr mac_learning_entry_; 82 : PktInfoPtr pkt_info_; 83 : uint32_t vrf_id_; 84 : const DBEntry *db_entry_; 85 : uint32_t gen_id_; 86 : IpAddress ip_; 87 : MacAddress mac_; 88 : }; 89 : //typedef boost::shared_ptr<MacLearningEntryRequest> MacLearningEntryRequestPtr; 90 : 91 : class MacLearningRequestQueue { 92 : public: 93 : typedef WorkQueue<MacLearningEntryRequestPtr> Queue; 94 : MacLearningRequestQueue(MacLearningPartition *partition, 95 : TokenPool *pool); 96 6 : ~MacLearningRequestQueue() {} 97 : void Shutdown() {} 98 : virtual bool HandleEvent(MacLearningEntryRequestPtr ptr); 99 : virtual bool TokenCheck(); 100 : 101 736 : void Enqueue(MacLearningEntryRequestPtr ptr) { 102 736 : queue_.Enqueue(ptr); 103 736 : } 104 : 105 0 : void MayBeStartRunner() { 106 0 : queue_.MayBeStartRunner(); 107 0 : } 108 : 109 2 : void SetQueueDisable(bool disable) { 110 2 : queue_.set_disable(disable); 111 2 : } 112 : 113 : private: 114 : MacLearningPartition *partition_; 115 : TokenPool *pool_; 116 : Queue queue_; 117 : DISALLOW_COPY_AND_ASSIGN(MacLearningRequestQueue); 118 : }; 119 : class MacIpLearningRequestQueue { 120 : public: 121 : typedef WorkQueue<MacLearningEntryRequestPtr> Queue; 122 : MacIpLearningRequestQueue(MacIpLearningTable *table); 123 2 : ~MacIpLearningRequestQueue() {} 124 : void Shutdown() {} 125 : bool HandleEvent(MacLearningEntryRequestPtr ptr); 126 : 127 6 : void Enqueue(MacLearningEntryRequestPtr ptr) { 128 6 : queue_.Enqueue(ptr); 129 6 : } 130 : 131 : void MayBeStartRunner() { 132 : queue_.MayBeStartRunner(); 133 : } 134 : 135 2 : void SetQueueDisable(bool disable) { 136 2 : queue_.set_disable(disable); 137 2 : } 138 : 139 : private: 140 : MacIpLearningTable *table_; 141 : Queue queue_; 142 : DISALLOW_COPY_AND_ASSIGN(MacIpLearningRequestQueue); 143 : }; 144 : #endif