|
xorp
|
00001 // -*- c-basic-offset: 4; tab-width: 8; indent-tabs-mode: t -*- 00002 // vim:set sts=4 ts=8 sw=4: 00003 00004 // Copyright (c) 2001-2009 XORP, Inc. 00005 // 00006 // This program is free software; you can redistribute it and/or modify 00007 // it under the terms of the GNU General Public License, Version 2, June 00008 // 1991 as published by the Free Software Foundation. Redistribution 00009 // and/or modification of this program under the terms of any other 00010 // version of the GNU General Public License is not permitted. 00011 // 00012 // This program is distributed in the hope that it will be useful, but 00013 // WITHOUT ANY WARRANTY; without even the implied warranty of 00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For more details, 00015 // see the GNU General Public License, Version 2, a copy of which can be 00016 // found in the XORP LICENSE.gpl file. 00017 // 00018 // XORP Inc, 2953 Bunker Hill Lane, Suite 204, Santa Clara, CA 95054, USA; 00019 // http://xorp.net 00020 00021 // $XORP: xorp/contrib/olsr/emulate_net.hh,v 1.3 2008/10/02 21:56:34 bms Exp $ 00022 00023 #ifndef __OLSR_EMULATE_NET_HH__ 00024 #define __OLSR_EMULATE_NET_HH__ 00025 00026 #include <deque> 00027 00032 class EmulateSubnet { 00033 public: 00034 EmulateSubnet(TestInfo& info, EventLoop& eventloop); 00035 virtual ~EmulateSubnet(); 00036 00047 void 00048 receive_frames(const string& interface, const string& vif, 00049 IPv4 dst, uint16_t dport, IPv4 src, uint16_t sport, 00050 uint8_t* data, uint32_t len, const string instance); 00051 00055 virtual void 00056 bind_interface(const string& instance, 00057 const string& interface, const string& vif, 00058 const IPv4& listen_addr, const uint16_t listen_port, 00059 DebugIO& io); 00060 00064 void 00065 unbind_interface(const string& instance, 00066 const string& interface, const string& vif, 00067 const IPv4& listen_addr, const uint16_t listen_port, 00068 DebugIO& io); 00069 00070 inline void set_all_nodes_addr(IPv4 all_nodes_addr) { 00071 _all_nodes_addr = all_nodes_addr; 00072 } 00073 00074 protected: 00075 class Multiplex { 00076 public: 00077 Multiplex(const string& instance, 00078 const string& interface, const string& vif, 00079 IPv4 listen_addr, uint16_t listen_port); 00080 inline bool operator <(const Multiplex& him) const { 00081 return him._instance < _instance; 00082 } 00083 const string _instance; 00084 const string _interface; 00085 const string _vif; 00086 const IPv4 _listen_addr; 00087 const uint16_t _listen_port; 00088 }; 00089 00090 class Frame { 00091 public: 00092 Frame(const string& interface, const string& vif, 00093 IPv4 dst, uint16_t dport, 00094 IPv4 src, uint16_t sport, 00095 uint8_t* data, uint32_t len, 00096 string instance); 00097 00098 // for use by EmulateSubnetHops 00099 inline vector<uint8_t>& get_buffer() { return _pkt; } 00100 00101 string _interface; // uniquely identifies link 00102 string _vif; 00103 IPv4 _dst; // IP header fields 00104 uint16_t _dport; 00105 IPv4 _src; 00106 uint16_t _sport; 00107 vector<uint8_t> _pkt; // payload 00108 string _instance; 00109 }; 00110 00111 protected: 00112 void next(); 00113 virtual void forward(Frame frame); 00114 00115 protected: 00116 TestInfo& _info; 00117 EventLoop& _eventloop; 00118 00119 map<const Multiplex, DebugIO *> _ios; 00120 00121 XorpTimer _timer; 00122 deque<Frame> _queue[2]; 00123 int _queue_add; 00124 int _queue_remove; 00125 IPv4 _all_nodes_addr; 00126 }; 00127 00137 class EmulateSubnetHops : public EmulateSubnet { 00138 public: 00139 EmulateSubnetHops(TestInfo& info, EventLoop& eventloop, 00140 uint8_t hopdelta = 1, uint8_t maxlinks = 2); 00141 00142 virtual ~EmulateSubnetHops(); 00143 00144 inline uint8_t hopdelta() const { return _hopdelta; } 00145 inline size_t empty_pkt_drops() const { return _empty_pkt_drops; } 00146 inline size_t ttl_msg_drops() const { return _ttl_msg_drops; } 00147 00152 void 00153 bind_interface(const string& instance, 00154 const string& interface, const string& vif, 00155 const IPv4& listen_addr, const uint16_t listen_port, 00156 DebugIO& io); 00157 00158 protected: 00165 void forward(Frame frame); 00166 00167 private: 00168 MessageDecoder _md; 00169 uint8_t _hopdelta; 00170 uint8_t _maxlinks; 00171 size_t _empty_pkt_drops; 00172 size_t _ttl_msg_drops; 00173 }; 00174 00175 #endif // __OLSR_EMULATE_NET_HH__