00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "config.hh"
00020
00021 #ifdef QOLYESTER_ENABLE_VIRTUAL
00022
00023 # ifndef QOLYESTER_DAEMON_NET_VIRTUALINTERFACE_HXX
00024 # define QOLYESTER_DAEMON_NET_VIRTUALINTERFACE_HXX 1
00025
00026 # include "virtualinterface.hh"
00027
00028 namespace olsr {
00029
00030 namespace net {
00031
00032 VirtualInterface::VirtualInterface()
00033 : info_(),
00034 addr_(info_.addr()),
00035 prefix_(0),
00036 events_()
00037 {}
00038
00039 VirtualInterface::VirtualInterface(const sys::VirtualInterfaceInfo& info)
00040 : info_(info),
00041 addr_(info_.addr()),
00042 prefix_(info_.prefix()),
00043 events_()
00044 {}
00045
00046 VirtualInterface::VirtualInterface(const This& other)
00047 : Super(other),
00048 info_(other.info_),
00049 addr_(info_.addr()),
00050 prefix_(info_.prefix()),
00051 events_()
00052 {}
00053
00054 VirtualInterface::~VirtualInterface() {
00055 debug << "Destroying interface instance {\n";
00056 for (events_t::iterator i = events_.begin(); i != events_.end();
00057 ) {
00058 debug << " Destroying " << (*i)->name() << "\n";
00059 events_t::iterator tmp = i++;
00060 scheduler.destroy(*tmp);
00061 }
00062 debug << "}" << std::endl;
00063 }
00064
00065 unsigned
00066 VirtualInterface::mtu() const {
00067 return info_.mtu();
00068 }
00069
00070 sch::IOEvent::p_t
00071 VirtualInterface::recv_p() const {
00072 return info_.socket().read_p();
00073 }
00074
00075 sch::IOEvent::p_t
00076 VirtualInterface::send_p() const {
00077 return info_.socket().write_p();
00078 }
00079
00080 void
00081 VirtualInterface::insert_event(sch::IOEvent* e) {
00082 debug << "Inserting " << e->name() << " into interface" << std::endl;
00083 events_.insert(e);
00084 }
00085
00086 void
00087 VirtualInterface::erase_event(sch::IOEvent* e) {
00088 debug << "Erasing " << e->name() << " from interface" << std::endl;
00089 events_.erase(e);
00090 }
00091
00092 void
00093 VirtualInterface::destroy_all_events() {
00094 while (!events_.empty()) {
00095 sch::IOEvent* e = *events_.begin();
00096 events_.erase(events_.begin());
00097 scheduler.destroy(e);
00098 }
00099 }
00100
00101 pkt::Packet
00102 VirtualInterface::receive() const {
00103
00104
00105 try {
00106 utl::Data d = info_.socket().receive();
00107 address_t froma(d.raw(), address_t::address_size);
00108 d += address_t::address_size;
00109 debug << up << "paquet received from switch: ip=" << froma
00110 << std::endl;
00111
00112 return pkt::Packet(froma, d);
00113 } catch (sys::UnixClosedConnection&) {
00114 terminate_now.set_mark();
00115 throw std::runtime_error("VirtualInterface::receive(): "
00116 "closed connection");
00117 }
00118 }
00119
00120 void
00121 VirtualInterface::send(const pkt::Packet& p) const {
00122 try {
00123 info_.socket().send(p.data());
00124 } catch (sys::UnixClosedConnection&) {
00125 terminate_now.set_mark();
00126 throw std::runtime_error("VirtualInterface::send(): "
00127 "closed connection");
00128 }
00129 address_t froma = p.sender();
00130 debug << up << "paquet sent from " << froma << std::endl;
00131
00132 }
00133
00134 bool
00135 VirtualInterface::operator<(const This& rhs) const {
00136 return addr_ < rhs.addr_;
00137 }
00138
00139 VirtualInterface&
00140 VirtualInterface::make_key(const address_t& a) {
00141 const_cast<address_t&>(dummy_for_find_.addr_) = a;
00142 return dummy_for_find_;
00143 }
00144
00145 }
00146
00147 }
00148
00149 # endif // ! QOLYESTER_DAEMON_NET_VIRTUALINTERFACE_HXX
00150
00151 #endif // QOLYESTER_ENABLE_VIRTUAL