Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

virtualinterface.hxx

Go to the documentation of this file.
00001 // Copyright (C) 2003, 2004, 2005 Laboratoire de Recherche en Informatique
00002 
00003 // This file is part of Qolyester.
00004 
00005 // Qolyester is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU General Public License
00007 // as published by the Free Software Foundation; either version 2
00008 // of the License, or (at your option) any later version.
00009 
00010 // Qolyester is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 
00015 // You should have received a copy of the GNU General Public License
00016 // along with this program; if not, write to the Free Software
00017 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
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 "sch/events.hh"
00027 #  include "virtualinterface.hh"
00028 
00029 namespace olsr {
00030 
00031   namespace net {
00032 
00033     VirtualInterface::VirtualInterface()
00034       : info_(),
00035         addr_(info_.addr()),
00036         prefix_(0),
00037         events_(),
00038         sender_(0),
00039         queue_size_(cst::queue_size)
00040     {}
00041 
00042     VirtualInterface::VirtualInterface(const sys::VirtualInterfaceInfo& info)
00043       : info_(info),
00044         addr_(info_.addr()),
00045         prefix_(info_.prefix()),
00046         events_(),
00047         sender_(0),
00048         queue_size_(cst::queue_size)
00049     {}
00050 
00051     VirtualInterface::VirtualInterface(const This& other)
00052       : Super(other),
00053         info_(other.info_),
00054         addr_(info_.addr()),
00055         prefix_(info_.prefix()),
00056         events_(),
00057         sender_(0),
00058         queue_size_(other.queue_size_)
00059     {}
00060 
00061     VirtualInterface::~VirtualInterface() {
00062       debug << "Destroying interface instance {\n";
00063       for (events_t::iterator i = events_.begin(); i != events_.end();
00064            /* ++i elsewhere */) {
00065         debug << "  Destroying " << (*i)->name() << "\n";
00066         events_t::iterator tmp = i++;
00067         scheduler.destroy(*tmp);
00068       }
00069       debug << "}" << std::endl;
00070     }
00071 
00072     unsigned
00073     VirtualInterface::mtu() const {
00074       return info_.mtu();
00075     }
00076 
00077     sch::IOEvent::p_t
00078     VirtualInterface::recv_p() const {
00079       return info_.socket().read_p();
00080     }
00081 
00082     sch::IOEvent::p_t
00083     VirtualInterface::send_p() const {
00084       return info_.socket().write_p();
00085     }
00086 
00087     void
00088     VirtualInterface::insert_event(sch::IOEvent* e) {
00089       debug << "Inserting " << e->name() << " into interface" << std::endl;
00090       events_.insert(e);
00091     }
00092 
00093     void
00094     VirtualInterface::erase_event(sch::IOEvent* e) {
00095       debug << "Erasing " << e->name() << " from interface" << std::endl;
00096       if (e == sender_)
00097         sender_ = 0;
00098       events_.erase(e);
00099     }
00100 
00101     void
00102     VirtualInterface::destroy_all_events() {
00103       while (!events_.empty()) {
00104         sch::IOEvent*   e = *events_.begin();
00105         events_.erase(events_.begin());
00106         scheduler.destroy(e);
00107       }
00108     }
00109 
00110     pkt::Packet
00111     VirtualInterface::receive() const {
00112 //      std::string             fromf;
00113 //         utl::Data            d = info_.socket().receive(fromf);
00114       try {
00115         utl::Data               d = info_.socket().receive();
00116         address_t               froma(d.raw(), address_t::address_size);
00117         d += address_t::address_size;
00118         debug << up << "paquet received from switch: ip=" << froma
00119               << std::endl;
00120 
00121         return pkt::Packet(froma, d);
00122       } catch (sys::UnixClosedConnection&) {
00123         terminate_now.set_mark();
00124         throw std::runtime_error("VirtualInterface::receive(): "
00125                                  "closed connection");
00126       }
00127     }
00128 
00129     void
00130     VirtualInterface::send(const pkt::Packet& p) const {
00131       try {
00132         info_.socket().send(p.data());
00133       } catch (sys::UnixClosedConnection&) {
00134         terminate_now.set_mark();
00135         throw std::runtime_error("VirtualInterface::send(): "
00136                                  "closed connection");
00137       }
00138       address_t froma = p.sender();
00139       debug << up << "paquet sent from " << froma << std::endl;
00140 
00141     }
00142 
00143     void
00144     VirtualInterface::shipout(const pkt::Packet& p) {
00145       debug << up << "Shipping out packet of " << p.size()
00146             << " bytes through " << info_.name() << std::endl;
00147       if (sender_ == 0) {
00148         sender_ = new sch::PacketSender(this, p);
00149         scheduler.insert(sender_);
00150       } else {
00151         sender_->push_packet(p);
00152       }
00153     }
00154 
00155     bool
00156     VirtualInterface::operator<(const This& rhs) const {
00157       return addr_ < rhs.addr_;
00158     }
00159 
00160     VirtualInterface&
00161     VirtualInterface::make_key(const address_t& a) {
00162       const_cast<address_t&>(dummy_for_find_.addr_) = a;
00163       return dummy_for_find_;
00164     }
00165 
00166   } // namespace net
00167 
00168 } // namespace olsr
00169 
00170 # endif // ! QOLYESTER_DAEMON_NET_VIRTUALINTERFACE_HXX
00171 
00172 #endif // QOLYESTER_ENABLE_VIRTUAL

Generated on Thu Dec 8 01:24:38 2005 for Qolyester daemon by  doxygen 1.4.3-20050530