Line data Source code
1 : /* 2 : * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved. 3 : */ 4 : 5 : #ifndef __ctrlplane__ifmap_update_queue__ 6 : #define __ctrlplane__ifmap_update_queue__ 7 : 8 : #include <map> 9 : #include "ifmap/ifmap_update.h" 10 : 11 : class IFMapServer; 12 : 13 : class IFMapUpdateQueue { 14 : public: 15 : typedef boost::intrusive::member_hook< 16 : IFMapListEntry, 17 : boost::intrusive::list_member_hook<>, 18 : &IFMapListEntry::node 19 : > MemberHook; 20 : typedef boost::intrusive::list<IFMapListEntry, MemberHook> List; 21 : 22 : typedef std::map<int, IFMapMarker *> MarkerMap; 23 : 24 : explicit IFMapUpdateQueue(IFMapServer *server); 25 : 26 : ~IFMapUpdateQueue(); 27 : 28 : // Called from the Exporter to add a new update at the tail of the queue. 29 : // Returns true if the tail_marker was the last element in the queue. 30 : bool Enqueue(IFMapUpdate *update); 31 : 32 : // Called from the Exporter to remove an update (because it is going to 33 : // be superceeded) or by the Sender when the update advertise mask is 34 : // empty. 35 : void Dequeue(IFMapUpdate *update); 36 : 37 : // Called by the Sender to iterate through the update queue. Current can 38 : // be a marker or the previous update. 39 : IFMapListEntry *Next(IFMapListEntry *current); 40 : 41 : // Returns the element before current or NULL if current is the first 42 : // element in the list. 43 : IFMapListEntry *Previous(IFMapListEntry *current); 44 : 45 : // Returns the last element in the list or NULL if the list is empty. 46 : IFMapListEntry *GetLast(); 47 : 48 : // Moves the marker from its previous position to the position immediately 49 : // 'before' the current node. Used when the Sender stops sending updates or 50 : // is blocked. 51 : void MoveMarkerBefore(IFMapMarker *marker, IFMapListEntry *current); 52 : 53 : // Moves the marker from its previous position to the position immediately 54 : // 'after' the current node. Used when the Sender stops sending updates or 55 : // is blocked. 56 : void MoveMarkerAfter(IFMapMarker *marker, IFMapListEntry *current); 57 : 58 : // Removes a set of members from marker, creates a new marker with this set 59 : // and inserts it 'before' current. Returns the new marker. 60 : IFMapMarker* MarkerSplitBefore(IFMapMarker *marker, IFMapListEntry *current, 61 : const BitSet &msplit); 62 : 63 : // Removes a set of members from marker, creates a new marker with this set 64 : // and inserts it 'after' current. Returns the new marker. 65 : IFMapMarker *MarkerSplitAfter(IFMapMarker *marker, IFMapListEntry *current, 66 : const BitSet &msplit); 67 : 68 : // Moves the specified 'mmove' set from 'src' to 'dst'. If 'src' becomes 69 : // empty it is deleted. 70 : void MarkerMerge(IFMapMarker *dst, IFMapMarker *src, const BitSet &mmove); 71 : 72 : // When a new client is established, adds it to the tail marker in order 73 : // to receive new updates. 74 : void Join(int bit); 75 : 76 : // When a client session terminate, removes its bit from all the queue 77 : // entries (marker or otherwise). 78 : void Leave(int bit); 79 : 80 : // Retrieves the marker corresponding to the client that has the specified 81 : // index. 82 : IFMapMarker *GetMarker(int bit); 83 : 84 : // Returns true if the queue is empty. 85 : bool empty() const; 86 : 87 1624 : IFMapMarker *tail_marker() { return &tail_marker_; } 88 : 89 : int size() const; 90 : 91 : void PrintQueue(); 92 : 93 : private: 94 : friend class ShowIFMapUpdateQueue; 95 : static const uint64_t NULL_SEQUENCE = 0; 96 : List list_; 97 : MarkerMap marker_map_; 98 : IFMapMarker tail_marker_; 99 : IFMapServer *server_; 100 : uint64_t sequence_; 101 : 102 : void SetSequence(IFMapListEntry *item); 103 : void PushbackIntoList(IFMapListEntry *item); 104 : void InsertIntoListBefore(IFMapListEntry *ptr, IFMapListEntry *item); 105 : void InsertIntoListAfter(IFMapListEntry *ptr, IFMapListEntry *item); 106 : void EraseFromList(IFMapListEntry *item); 107 : void ClearAndDisposeList(); 108 : IFMapMarker* MarkerSplit(IFMapMarker *marker, IFMapListEntry *current, 109 : const BitSet &msplit, bool before); 110 : }; 111 : 112 : #endif /* defined(__ctrlplane__ifmap_update_queue__) */