IBR-DTNSuite
0.8
|
00001 /* 00002 * UDPDatagramService.h 00003 * 00004 * Created on: 22.11.2011 00005 * Author: morgenro 00006 */ 00007 00008 #ifndef UDPDATAGRAMSERVICE_H_ 00009 #define UDPDATAGRAMSERVICE_H_ 00010 00011 #include "net/DatagramConvergenceLayer.h" 00012 #include "net/DatagramConnectionParameter.h" 00013 #include <ibrcommon/net/udpsocket.h> 00014 #include <ibrcommon/net/vinterface.h> 00015 00016 namespace dtn 00017 { 00018 namespace net 00019 { 00020 class UDPDatagramService : public dtn::net::DatagramService, protected ibrcommon::udpsocket 00021 { 00022 public: 00023 UDPDatagramService(const ibrcommon::vinterface &iface, int port, size_t mtu = 1280); 00024 virtual ~UDPDatagramService(); 00025 00030 virtual void bind() throw (DatagramException); 00031 00035 virtual void shutdown(); 00036 00043 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); 00044 00050 virtual void send(const char &type, const char &flags, const unsigned int &seqno, const char *buf, size_t length) throw (DatagramException); 00051 00060 virtual size_t recvfrom(char *buf, size_t length, char &type, char &flags, unsigned int &seqno, std::string &address) throw (DatagramException); 00061 00066 virtual const std::string getServiceTag() const; 00067 00073 virtual const std::string getServiceDescription() const; 00074 00079 virtual const ibrcommon::vinterface& getInterface() const; 00080 00085 virtual dtn::core::Node::Protocol getProtocol() const; 00086 00091 virtual const DatagramConnectionParameter& getParameter() const; 00092 00093 private: 00094 static const std::string encode(const ibrcommon::vaddress &address, const unsigned int &port); 00095 static void decode(const std::string &identifier, std::string &address, unsigned int &port); 00096 00097 00098 const static int BROADCAST_PORT = 5551; 00099 const ibrcommon::vinterface _iface; 00100 const int _bind_port; 00101 00102 DatagramConnectionParameter _params; 00103 }; 00104 00105 } /* namespace net */ 00106 } /* namespace dtn */ 00107 #endif /* UDPDATAGRAMSERVICE_H_ */