IBR-DTN  1.0.0
DatagramService.h
Go to the documentation of this file.
1 /*
2  * DatagramService.h
3  *
4  * Created on: 09.11.2012
5  * Author: morgenro
6  */
7 
8 #ifndef DATAGRAMSERVICE_H_
9 #define DATAGRAMSERVICE_H_
10 
11 #include "core/Node.h"
12 #include <ibrcommon/net/vinterface.h>
13 #include <string>
14 
15 namespace dtn
16 {
17  namespace net
18  {
19  class DatagramException : public ibrcommon::Exception
20  {
21  public:
22  DatagramException(const std::string &what) : ibrcommon::Exception(what)
23  {};
24 
25  virtual ~DatagramException() throw() {};
26  };
27 
29  {
30  public:
31  WrongSeqNoException(size_t exp_seqno)
32  : DatagramException("Wrong sequence number received"), expected_seqno(exp_seqno)
33  {};
34 
35  virtual ~WrongSeqNoException() throw() {};
36 
37  const size_t expected_seqno;
38  };
39 
41  {
42  public:
44  {
45  FLOW_NONE = 0,
48  };
49 
51  {
52  SEGMENT_FIRST = 0x02,
53  SEGMENT_LAST = 0x01,
56  };
57 
58  class Parameter
59  {
60  public:
61  // default constructor
64  initial_timeout(50), retry_limit(5) { }
65 
66  // destructor
67  virtual ~Parameter() { }
68 
70  unsigned int max_seq_numbers;
73  size_t retry_limit;
74  };
75 
76  virtual ~DatagramService() = 0;
77 
82  virtual void bind() throw (DatagramException) = 0;
83 
87  virtual void shutdown() = 0;
88 
96  virtual void send(const char &type, const char &flags, const unsigned int &seqno, const std::string &address, const char *buf, size_t length) throw (DatagramException) = 0;
97 
104  virtual void send(const char &type, const char &flags, const unsigned int &seqno, const char *buf, size_t length) throw (DatagramException) = 0;
105 
114  virtual size_t recvfrom(char *buf, size_t length, char &type, char &flags, unsigned int &seqno, std::string &address) throw (DatagramException) = 0;
115 
120  virtual const std::string getServiceTag() const;
121 
127  virtual const std::string getServiceDescription() const = 0;
128 
133  virtual const ibrcommon::vinterface& getInterface() const = 0;
134 
139  virtual dtn::core::Node::Protocol getProtocol() const = 0;
140 
145  virtual const Parameter& getParameter() const = 0;
146  };
147  }
148 }
149 
150 #endif /* DATAGRAMSERVICE_H_ */
virtual const ibrcommon::vinterface & getInterface() const =0
virtual void bind()=0
virtual const Parameter & getParameter() const =0
WrongSeqNoException(size_t exp_seqno)
virtual void send(const char &type, const char &flags, const unsigned int &seqno, const std::string &address, const char *buf, size_t length)=0
virtual const std::string getServiceTag() const
DatagramException(const std::string &what)
virtual void shutdown()=0
virtual size_t recvfrom(char *buf, size_t length, char &type, char &flags, unsigned int &seqno, std::string &address)=0
virtual dtn::core::Node::Protocol getProtocol() const =0
virtual const std::string getServiceDescription() const =0