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 send_bundle(const ContactRef& contact, Bundle* bundle);
00136
00146 class Params : public CLInfo {
00147 public:
00148 u_int32_t beacon_interval_;
00149 };
00150
00154 static Params defaults_;
00155
00160 class Receiver : public CLInfo,
00161 public oasys::Logger,
00162 public oasys::Thread
00163 {
00164 public:
00168 Receiver(const char *if_name, EthConvergenceLayer::Params* params);
00169
00173 virtual ~Receiver() {}
00174
00184 void run();
00185
00186 protected:
00190 void process_data(u_char* bp, size_t len);
00191 char if_name_[IFNAMSIZ];
00192 };
00193
00194
00195
00205 class Sender : public CLInfo,
00206 public oasys::Logger
00207 {
00208 public:
00212 Sender(char* if_name, const ContactRef& contact);
00213
00217 virtual ~Sender() {}
00218
00219 protected:
00220 friend class EthConvergenceLayer;
00221
00225 bool send_bundle(Bundle* bundle);
00226
00228 ContactRef contact_;
00229
00231 int sock_;
00232
00234 eth_addr_t src_hw_addr_;
00235 eth_addr_t dst_hw_addr_;
00236
00238 char if_name_[IFNAMSIZ];
00239
00240 char canary_[7];
00241
00247 u_char buf_[EthConvergenceLayer::MAX_BUNDLE_LEN];
00248 };
00249
00254 class Beacon : public oasys::Logger,
00255 public oasys::Thread
00256 {
00257 public:
00258 Beacon(const char* if_name, unsigned int beacon_interval);
00259
00260 virtual ~Beacon() {};
00261
00262 private:
00263 virtual void run();
00264 char if_name_[IFNAMSIZ];
00265 unsigned int beacon_interval_;
00266 };
00267
00268 class BeaconTimer : public oasys::Logger, public oasys::Timer, public CLInfo {
00269 public:
00270 char * next_hop_;
00271
00272 BeaconTimer(char * next_hop);
00273 ~BeaconTimer();
00274
00275 void timeout(const struct timeval& now);
00276
00277 Timer* copy();
00278 };
00279
00280 protected:
00284 bool parse_params(Params* params, int argc, const char** argv,
00285 const char** invalidp);
00286
00287 private:
00288 Beacon *if_beacon_;
00289 };
00290
00291
00292 }
00293
00294 #endif // __linux
00295
00296 #endif