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

message.hh

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 
00030 #ifndef QOLYESTER_DAEMON_MSG_MESSAGE_HH
00031 # define QOLYESTER_DAEMON_MSG_MESSAGE_HH 1
00032 
00033 // The idea behind the message hierarchy is to make messages
00034 // independent of the packets and allow messages to be aggregated into
00035 // a single packet.
00036 
00037 // When a message is created in the local node, no data is prepared
00038 // until the actual dump of the message into a packet.  Messages that
00039 // support partial generation can thus be generated differently
00040 // depending on the space left in the current packet.  To avoid a
00041 // total mess, non-local messages are forwarded unfragmented.
00042 
00043 # include <list>
00044 
00045 # include "net/ipaddress.hh"
00046 # include "utl/data.hh"
00047 # include "utl/seqnum.hh"
00048 # include "utl/timeval.hh"
00049 
00050 namespace olsr {
00051 
00052   namespace msg {
00053 
00054     // The abstract message class
00055 
00060 
00061     class Message {
00062     public:
00063       struct header;
00067       virtual ~Message() {}
00068 
00069       // The dump method.  Returns true if the message was partial and
00070       // immediate additional generation is required to avoid validity
00071       // timer expiration.
00072 
00077       virtual bool      dump(utl::Data&, const address_t&) const = 0;
00078 
00087       virtual void      inc_seqnum() { ++seqnum; }
00088 
00089       // Parsing routine.
00100       static void       parse(utl::Data d, const address_t& sender,
00101                               const address_t& receiver,
00102                               const seqnum_t& pseqnum);
00103 
00104       // Default forward routine.
00113       static void       forward(utl::Data& d, const header& mh);
00114 
00115       // Convenience data structure of the message header.
00122       struct raw {
00123         u_int8_t                type;
00124         u_int8_t                vtime;
00125         u_int16_t               size;
00126         u_int8_t                addr[ADDRESS_SIZE];
00127         u_int8_t                ttl;
00128         u_int8_t                hopcount;
00129         u_int16_t               seqnum;
00130         u_int8_t                data[0];
00131       };
00132 
00133       struct header {
00134         header(const address_t& s, const address_t& r, const address_t& o,
00135                const timeval_t& v, const seqnum_t& ps, const seqnum_t& ms,
00136                const unsigned& hopcount)
00137           : sender(s),
00138             receiver(r),
00139             originator(o),
00140             validity(v),
00141             pseqnum(ps),
00142             mseqnum(ms),
00143             hopcount(hopcount)
00144         {}
00145         const address_t&        sender;
00146         const address_t&        receiver;
00147         const address_t&        originator;
00148         const timeval_t&        validity;
00149         const seqnum_t&         pseqnum;
00150         const seqnum_t&         mseqnum;
00151         const unsigned&         hopcount;
00152       };
00153 
00154       static const ::size_t             min_length = sizeof (raw); 
00155 
00156     protected:
00157       static utl::Seqnum<u_int16_t>     seqnum; 
00158     };
00159 
00160     // Special message class of unknown or lost message type.  A known
00161     // message type is lost after the message has been
00162     // parsed/processed and is queued for forwarding.
00171     class UnknownMessage : public Message {
00172     public:
00177       UnknownMessage(utl::Data& d);
00178 
00182       virtual ~UnknownMessage() {}
00183 
00189       virtual bool dump(utl::Data& d, const address_t&) const;
00190 
00194       virtual void      inc_seqnum() {}
00195 
00196     private:
00197       utl::Data _data; 
00198     };
00199 
00200   } // namespace msg
00201 
00202   typedef std::list<const msg::Message*>        pending_t;
00203 
00208   pending_t                                     pending_messages;
00209 
00210 } // namespace olsr
00211 
00212 # ifndef QOLYESTER_DONTINCLUDE_HXX
00213 #  include "message.hxx"
00214 # endif
00215 
00216 #endif // ! QOLYESTER_DAEMON_MSG_MESSAGE_HH

Generated on Thu Jul 28 21:21:47 2005 for Qolyester daemon by  doxygen 1.4.1