00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #ifndef _ETH_CONVERGENCE_LAYER_H_
00039 #define _ETH_CONVERGENCE_LAYER_H_
00040
00041
00042 #ifdef __linux__
00043
00044 #include <sys/types.h>
00045 #include <netinet/in.h>
00046 #include <linux/if.h>
00047
00048 #include <oasys/thread/Thread.h>
00049 #include <oasys/thread/Timer.h>
00050
00051 #include "ConvergenceLayer.h"
00052 #include "naming/EthernetScheme.h"
00053
00069 namespace dtn {
00070
00071 class EthConvergenceLayer : public ConvergenceLayer {
00072
00073 public:
00074 class BeaconTimer;
00075
00079 static const u_int8_t ETHCL_VERSION = 0x01;
00080 static const u_int16_t ETHERTYPE_DTN = 0xd710;
00081
00082 static const u_int8_t ETHCL_BEACON = 0x01;
00083 static const u_int8_t ETHCL_BUNDLE = 0x02;
00084
00085 static const u_int32_t ETHCL_BEACON_TIMEOUT_INTERVAL = 2500;
00086
00087 static const u_int16_t MAX_ETHER_PACKET = 1518;
00088
00092 static const u_int MAX_BUNDLE_LEN = 65507;
00093
00097 struct EthCLHeader {
00098 u_int8_t version;
00099 u_int8_t type;
00100 u_int16_t _padding2;
00101 u_int32_t bundle_id;
00102 } __attribute__((packed));
00103
00108 class EthCLInfo : public CLInfo {
00109 public:
00110 EthCLInfo(char* if_name) {
00111 memset(if_name_,0,IFNAMSIZ);
00112 strcpy(if_name_,if_name);
00113 timer = NULL;
00114 }
00115
00116 ~EthCLInfo() {
00117 if(timer)
00118 delete timer;
00119 }
00120
00121
00122 char if_name_[IFNAMSIZ];
00123
00124 BeaconTimer* timer;
00125 };
00126
00130 EthConvergenceLayer();
00131
00135 bool interface_up(Interface* iface, int argc, const char* argv[]);
00136
00140 bool interface_down(Interface* iface);
00141
00146 bool open_contact(const ContactRef& contact);
00147
00151 bool close_contact(const ContactRef& contact);
00152
00156 void send_bundle(const ContactRef& contact, Bundle* bundle);
00157
00167 class Params : public CLInfo {
00168 public:
00169 u_int32_t beacon_interval_;
00170 };
00171
00175 static Params defaults_;
00176
00181 class Receiver : public CLInfo,
00182 public oasys::Logger,
00183 public oasys::Thread
00184 {
00185 public:
00189 Receiver(const char *if_name, EthConvergenceLayer::Params* params);
00190
00194 virtual ~Receiver() {}
00195
00205 void run();
00206
00207 protected:
00211 void process_data(u_char* bp, size_t len);
00212 char if_name_[IFNAMSIZ];
00213 };
00214
00215
00216
00226 class Sender : public CLInfo,
00227 public oasys::Logger
00228 {
00229 public:
00233 Sender(char* if_name, const ContactRef& contact);
00234
00238 virtual ~Sender() {}
00239
00240 protected:
00241 friend class EthConvergenceLayer;
00242
00246 bool send_bundle(Bundle* bundle);
00247
00249 ContactRef contact_;
00250
00252 int sock_;
00253
00255 eth_addr_t src_hw_addr_;
00256 eth_addr_t dst_hw_addr_;
00257
00259 char if_name_[IFNAMSIZ];
00260
00261 char canary_[7];
00262
00268 u_char buf_[EthConvergenceLayer::MAX_BUNDLE_LEN];
00269 };
00270
00275 class Beacon : public oasys::Logger,
00276 public oasys::Thread
00277 {
00278 public:
00279 Beacon(const char* if_name, unsigned int beacon_interval);
00280
00281 virtual ~Beacon() {};
00282
00283 private:
00284 virtual void run();
00285 char if_name_[IFNAMSIZ];
00286 unsigned int beacon_interval_;
00287 };
00288
00289 class BeaconTimer : public oasys::Logger, public oasys::Timer, public CLInfo {
00290 public:
00291 char * next_hop_;
00292
00293 BeaconTimer(char * next_hop);
00294 ~BeaconTimer();
00295
00296 void timeout(const struct timeval& now);
00297
00298 Timer* copy();
00299 };
00300
00301 protected:
00305 bool parse_params(Params* params, int argc, const char** argv,
00306 const char** invalidp);
00307
00308 private:
00309 Beacon *if_beacon_;
00310 };
00311
00312
00313 }
00314
00315 #endif // __linux
00316
00317 #endif