packet.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 
00019 # include "msg/message.hh"
00020 
00021 #ifndef QOLYESTER_DAEMON_PKT_PACKET_HH
00022 # define QOLYESTER_DAEMON_PKT_PACKET_HH 1
00023 
00024 # include <sys/types.h>
00025 # include <map>
00026 
00027 # include "net/ipaddress.hh"
00028 # include "utl/data.hh"
00029 # include "utl/seqnum.hh"
00030 
00031 namespace olsr {
00032 
00033   namespace pkt {
00034 
00035     // The packet class.
00036 
00037     class Packet {
00038     public:
00039       // There are two ways to create a packet:
00040       // * create a new one for local generation.
00041       inline Packet(const ::size_t mtu, const address_t& addr);
00042       // * pack received data into a packet to include network-layer
00043       //   information (source address, destination address).
00044       inline Packet(const address_t& addr, const utl::Data& d);
00045 
00046       // Accessors
00047       ::size_t          size()   const { return _size; }
00048       const utl::Data&  data()   const { return _data;   }
00049       const address_t&  sender() const { return _sender; }
00050 
00051       // Modifiers
00052       // Add a single message.
00053       inline bool       add_message(const msg::Message& m);
00054 
00055       inline void       close(const address_t& i);
00056 
00057 //       // Add as much messages from pm as possible.
00058 //       void   fill(pending_t& pm, pending_t& spm);
00059 
00060       // Forward declaration of parsing static method
00061       static inline void        parse(utl::Data,
00062                                       const address_t& sender,
00063                                       const address_t& receiver);
00064     protected:
00065 
00066       // Convenience data structure of the packet header
00067       struct raw {
00068         u_int16_t       length;
00069         u_int16_t       seqnum;
00070         u_int8_t        data[0];
00071       };
00072     public:
00073       static const ::size_t     min_length = sizeof (raw);
00074     private:
00075       ::size_t          _size;
00076       address_t         _sender;
00077       utl::Data         _data;
00078       raw*              _raw;
00079     protected:
00080       static std::map<address_t, utl::Seqnum<u_int16_t> >       seqnum_map;
00081     };
00082 
00083   } // namespace pkt
00084 
00085 } // namespace olsr
00086 
00087 # include "packet.hxx"
00088 
00089 #endif // ! QOLYESTER_DAEMON_PKT_PACKET_HH

Generated on Mon Sep 10 17:02:12 2007 for Qolyester daemon by  doxygen 1.5.1