OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ifmap_update_queue.h
Go to the documentation of this file.
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 
14 public:
15  typedef boost::intrusive::member_hook<
17  boost::intrusive::list_member_hook<>,
20  typedef boost::intrusive::list<IFMapListEntry, MemberHook> List;
21 
22  typedef std::map<int, IFMapMarker *> MarkerMap;
23 
24  explicit IFMapUpdateQueue(IFMapServer *server);
25 
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.
40 
41  // Returns the element before current or NULL if current is the first
42  // element in the list.
44 
45  // Returns the last element in the list or NULL if the list is empty.
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.
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.
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 
88 
89  int size() const;
90 
91  void PrintQueue();
92 
93 private:
94  friend class ShowIFMapUpdateQueue;
95  static const uint64_t NULL_SEQUENCE = 0;
100  uint64_t sequence_;
101 
102  void SetSequence(IFMapListEntry *item);
103  void PushbackIntoList(IFMapListEntry *item);
106  void EraseFromList(IFMapListEntry *item);
107  void ClearAndDisposeList();
109  const BitSet &msplit, bool before);
110 };
111 
112 #endif /* defined(__ctrlplane__ifmap_update_queue__) */
boost::intrusive::list< IFMapListEntry, MemberHook > List
boost::intrusive::list_member_hook node
Definition: ifmap_update.h:56
IFMapMarker * MarkerSplit(IFMapMarker *marker, IFMapListEntry *current, const BitSet &msplit, bool before)
void MoveMarkerBefore(IFMapMarker *marker, IFMapListEntry *current)
void MoveMarkerAfter(IFMapMarker *marker, IFMapListEntry *current)
IFMapMarker * tail_marker()
void SetSequence(IFMapListEntry *item)
IFMapListEntry * GetLast()
static const uint64_t NULL_SEQUENCE
std::map< int, IFMapMarker * > MarkerMap
IFMapMarker * GetMarker(int bit)
void Dequeue(IFMapUpdate *update)
IFMapMarker * MarkerSplitAfter(IFMapMarker *marker, IFMapListEntry *current, const BitSet &msplit)
IFMapMarker * MarkerSplitBefore(IFMapMarker *marker, IFMapListEntry *current, const BitSet &msplit)
Definition: bitset.h:17
void EraseFromList(IFMapListEntry *item)
IFMapListEntry * Previous(IFMapListEntry *current)
void MarkerMerge(IFMapMarker *dst, IFMapMarker *src, const BitSet &mmove)
IFMapServer * server_
boost::intrusive::member_hook< IFMapListEntry, boost::intrusive::list_member_hook<>,&IFMapListEntry::node > MemberHook
void InsertIntoListBefore(IFMapListEntry *ptr, IFMapListEntry *item)
IFMapMarker tail_marker_
void PushbackIntoList(IFMapListEntry *item)
IFMapUpdateQueue(IFMapServer *server)
void InsertIntoListAfter(IFMapListEntry *ptr, IFMapListEntry *item)
IFMapListEntry * Next(IFMapListEntry *current)
bool Enqueue(IFMapUpdate *update)