libbgp  0.6
A C++ BGP Library.
bgp-sink.h
Go to the documentation of this file.
1 
11 #ifndef BGP_SINK_H_
12 #define BGP_SINK_H_
13 #include <mutex>
14 #include <stdint.h>
15 #include <unistd.h>
16 #include "bgp-packet.h"
17 #include "bgp-log-handler.h"
18 
19 namespace libbgp {
20 
29 class BgpSink {
30 public:
31  // create a new sink
32  BgpSink(bool use_4b_asn);
33 
34  // feed stream of packets into sink
35  ssize_t fill(const uint8_t *buffer, size_t len);
36 
37  // get a pointer to next packet from sink (might chane if fill())
38  //BufferPtr pourPtr();
39 
40  // get a pointer to datas in sink (might chane if fill())
41  //BufferPtr pourPtrAll();
42 
43  // get and remove a single BGP packet from sink (max size = 4096)
44  //ssize_t pour(uint8_t *buffer, size_t len);
45 
46  // get a packet from sink and remove that packet from sink. if no packet
47  // currently avaliable, 0 will be returned. if error, -2 will be returned,
48  // if error happend during parse but the packet object has already been
49  // created, -1 will be returned.
50  // otherwise, pkt is set to point to the new packet, and bytes drained is
51  // returned. (> 0)
52  ssize_t pour(BgpPacket **pkt);
53 
54  // get and remove all packets from sink (max size = sink buffer size)
55  //ssize_t pourAll(uint8_t *buffer, size_t len);
56 
57  // get number of bytes currently in sink
58  size_t getBytesInSink() const;
59 
60  // discard packets in sink
61  void drain();
62 
63  void setLogger(BgpLogHandler *logger);
64 
65  ~BgpSink();
66 
67 private:
68  // settle the sink
69  void settle();
70 
71  // exapnd the sink
72  void expand();
73 
74  uint8_t *buffer;
75  size_t buffer_size;
76  size_t offset_start;
77  size_t offset_end;
78  bool use_4b_asn;
79  std::recursive_mutex mutex;
80  BgpLogHandler *logger;
81 };
82 
83 }
84 
85 #endif // BGP_SINK_H_
ssize_t pour(BgpPacket **pkt)
Pour BGP packet out from sink.
Definition: bgp-sink.cc:86
The BgpSink class.
Definition: bgp-sink.h:29
void setLogger(BgpLogHandler *logger)
Set the logger to use. If NULL or not set, nothing will be logger.
Definition: bgp-sink.cc:164
~BgpSink()
Destroy the Bgp Sink:: Bgp Sink object.
Definition: bgp-sink.cc:36
void drain()
Drain the sink. (Remove all data from sink buffer)
Definition: bgp-sink.cc:145
Top level deserialization/serialization entry point for BGP messages.
Definition: bgp-afi.h:14
The BgpLogHandler class.
BGP log handler.
size_t getBytesInSink() const
Get amount to data in sink.
Definition: bgp-sink.cc:155
The BgpPacket class.
Definition: bgp-packet.h:26
ssize_t fill(const uint8_t *buffer, size_t len)
Fill the sink with data.
Definition: bgp-sink.cc:50
BgpSink(bool use_4b_asn)
Construct a new Bgp Sink:: Bgp Sink object.
Definition: bgp-sink.cc:24