00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef _ETH_CONVERGENCE_LAYER_H_
00018 #define _ETH_CONVERGENCE_LAYER_H_
00019
00020
00021 #ifdef __linux__
00022
00023 #include <sys/types.h>
00024 #include <netinet/in.h>
00025 #include <linux/if.h>
00026
00027 #include <oasys/thread/Thread.h>
00028 #include <oasys/thread/Timer.h>
00029
00030 #include "ConvergenceLayer.h"
00031 #include "naming/EthernetScheme.h"
00032
00048 namespace dtn {
00049
00050 class EthConvergenceLayer : public ConvergenceLayer {
00051
00052 public:
00053 class BeaconTimer;
00054
00058 static const u_int8_t ETHCL_VERSION = 0x01;
00059 static const u_int16_t ETHERTYPE_DTN = 0xd710;
00060
00061 static const u_int8_t ETHCL_BEACON = 0x01;
00062 static const u_int8_t ETHCL_BUNDLE = 0x02;
00063
00064 static const u_int32_t ETHCL_BEACON_TIMEOUT_INTERVAL = 2500;
00065
00066 static const u_int16_t MAX_ETHER_PACKET = 1518;
00067
00071 static const u_int MAX_BUNDLE_LEN = 65507;
00072
00076 struct EthCLHeader {
00077 u_int8_t version;
00078 u_int8_t type;
00079 u_int16_t _padding2;
00080 u_int32_t bundle_id;
00081 } __attribute__((packed));
00082
00087 class EthCLInfo : public CLInfo {
00088 public:
00089 EthCLInfo(char* if_name) {
00090 memset(if_name_,0,IFNAMSIZ);
00091 strcpy(if_name_,if_name);
00092 timer = NULL;
00093 }
00094
00095 ~EthCLInfo() {
00096 if(timer)
00097 delete timer;
00098 }
00099
00100
00101 char if_name_[IFNAMSIZ];
00102
00103 BeaconTimer* timer;
00104 };
00105
00109 EthConvergenceLayer();
00110
00114 bool interface_up(Interface* iface, int argc, const char* argv[]);
00115
00119 bool interface_down(Interface* iface);
00120
00125 bool open_contact(const ContactRef& contact);
00126
00130 bool close_contact(const ContactRef& contact);
00131
00135 void delete_link(const LinkRef& link);
00136
00140 void bundle_queued(const LinkRef& link, const BundleRef& bundle);
00141
00145 bool is_queued(const LinkRef& contact, Bundle* bundle);
00146
00156 class Params : public CLInfo {
00157 public:
00158 u_int32_t beacon_interval_;
00159 };
00160
00164 static Params defaults_;
00165
00170 class Receiver : public CLInfo,
00171 public oasys::Logger,
00172 public oasys::Thread
00173 {
00174 public:
00178 Receiver(const char *if_name, EthConvergenceLayer::Params* params);
00179
00183 virtual ~Receiver() {}
00184
00194 void run();
00195
00196 protected:
00200 void process_data(u_char* bp, size_t len);
00201 char if_name_[IFNAMSIZ];
00202 };
00203
00204
00205
00215 class Sender : public CLInfo,
00216 public oasys::Logger
00217 {
00218 public:
00222 Sender(char* if_name, const ContactRef& contact);
00223
00227 virtual ~Sender() {}
00228
00229 protected:
00230 friend class EthConvergenceLayer;
00231
00235 bool send_bundle(const BundleRef& bundle);
00236
00238 ContactRef contact_;
00239
00241 int sock_;
00242
00244 eth_addr_t src_hw_addr_;
00245 eth_addr_t dst_hw_addr_;
00246
00248 char if_name_[IFNAMSIZ];
00249
00250 char canary_[7];
00251
00257 u_char buf_[EthConvergenceLayer::MAX_BUNDLE_LEN];
00258 };
00259
00264 class Beacon : public oasys::Logger,
00265 public oasys::Thread
00266 {
00267 public:
00268 Beacon(const char* if_name, unsigned int beacon_interval);
00269
00270 virtual ~Beacon() {};
00271
00272 private:
00273 virtual void run();
00274 char if_name_[IFNAMSIZ];
00275 unsigned int beacon_interval_;
00276 };
00277
00278 class BeaconTimer : public oasys::Logger, public oasys::Timer, public CLInfo {
00279 public:
00280 char * next_hop_;
00281
00282 BeaconTimer(char * next_hop);
00283 ~BeaconTimer();
00284
00285 void timeout(const struct timeval& now);
00286
00287 Timer* copy();
00288 };
00289
00290 protected:
00294 bool parse_params(Params* params, int argc, const char** argv,
00295 const char** invalidp);
00296
00297 private:
00298 Beacon *if_beacon_;
00299 };
00300
00301
00302 }
00303
00304 #endif // __linux
00305
00306 #endif