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

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       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       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       bool      add_message(const msg::Message& m);
00054 
00055       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 void parse(utl::Data, const address_t&, const address_t&);
00062     protected:  
00063 
00064       // Convenience data structure of the packet header
00065       struct raw {
00066         u_int16_t       length;
00067         u_int16_t       seqnum;
00068         u_int8_t        data[0];
00069       };
00070     public:
00071       static const ::size_t     min_length = sizeof (raw);
00072     private:
00073       ::size_t          _size;
00074       address_t         _sender;
00075       utl::Data         _data;
00076       raw*              _raw;
00077     protected:
00078       static std::map<address_t, utl::Seqnum<u_int16_t> >       seqnum_map;
00079     };
00080 
00081   } // namespace pkt
00082 
00083 } // namespace olsr
00084 
00085 # ifndef QOLYESTER_DONTINCLUDE_HXX
00086 #  include "packet.hxx"
00087 # endif
00088 
00089 #endif // ! QOLYESTER_DAEMON_PKT_PACKET_HH

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