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