00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef _ANNOUNCE_H_
00018 #define _ANNOUNCE_H_
00019
00020 #include <oasys/debug/Log.h>
00021 #include <oasys/thread/Timer.h>
00022 #include <string>
00023 #include "naming/EndpointID.h"
00024 #include "conv_layers/ConvergenceLayer.h"
00025
00026 #ifndef FOUR_BYTE_ALIGN
00027 #define FOUR_BYTE_ALIGN(x) (((x) % 4) != 0) ? ((x) + (4 - ((x) % 4))) : (x)
00028 #endif
00029
00030 namespace dtn {
00031
00042 class Announce : public oasys::Logger
00043 {
00044 public:
00045
00049 const std::string& name() { return name_; }
00050
00054 const std::string& type() { return type_; }
00055
00060 const std::string& local_addr() { return local_; }
00061
00066 virtual void handle_neighbor_discovered(const std::string& cl_addr,
00067 const EndpointID& remote_eid) = 0;
00068
00072 virtual size_t format_advertisement(u_char* buf, size_t len) = 0;
00073
00074 virtual ~Announce() {}
00075
00080 u_int interval_remaining()
00081 {
00082 struct timeval now;
00083 ::gettimeofday(&now,0);
00084 u_int timediff = TIMEVAL_DIFF_MSEC(now,data_sent_);
00085 if (timediff > interval_)
00086 return 0;
00087
00088 return (interval_ - timediff);
00089 }
00090
00094 static Announce* create_announce(const std::string& name,
00095 ConvergenceLayer* cl,
00096 int argc, const char* argv[]);
00097
00101 u_int interval() { return interval_; }
00102
00103 protected:
00104 Announce(const char* logpath = "/dtn/discovery/announce")
00105 : oasys::Logger("Announce",logpath),
00106 cl_(NULL), interval_(0)
00107 {
00108 ::gettimeofday(&data_sent_,0);
00109 }
00110
00111 virtual bool configure(const std::string& name,
00112 ConvergenceLayer* cl,
00113 int argc, const char* argv[]) = 0;
00114
00115 ConvergenceLayer* cl_;
00116 std::string local_;
00117 std::string name_;
00118 std::string type_;
00119 u_int interval_;
00120
00121 struct timeval data_sent_;
00122 private:
00123 Announce(const Announce&)
00124 : oasys::Logger("Announce","/dtn/discovery/beacon") {}
00125 };
00126
00127 }
00128
00129 #endif // _ANNOUNCE_H_