00001 // 00002 // Copyright (C) 2005 Andras Varga 00003 // 00004 // This program is free software; you can redistribute it and/or 00005 // modify it under the terms of the GNU Lesser General Public License 00006 // as published by the Free Software Foundation; either version 2 00007 // of the License, or (at your option) any later version. 00008 // 00009 // This program is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 // GNU Lesser General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU Lesser General Public License 00015 // along with this program; if not, see <http://www.gnu.org/licenses/>. 00016 // 00017 00018 #ifndef __IPv6FRAGBUF_H__ 00019 #define __IPv6FRAGBUF_H__ 00020 00021 #include <map> 00022 #include <vector> 00023 #include "INETDefs.h" 00024 #include "ReassemblyBuffer.h" 00025 #include "IPv6Address.h" 00026 00027 class ICMPv6; 00028 class IPv6Datagram; 00029 class IPv6FragmentHeader; 00030 00034 class INET_API IPv6FragBuf 00035 { 00036 protected: 00037 // 00038 // Key for finding the reassembly buffer for a datagram. 00039 // 00040 struct Key 00041 { 00042 uint32 id; 00043 IPv6Address src; 00044 IPv6Address dest; 00045 00046 inline bool operator<(const Key& b) const { 00047 return (id!=b.id) ? (id<b.id) : (src!=b.src) ? (src<b.src) : (dest<b.dest); 00048 } 00049 }; 00050 00051 // 00052 // Reassembly buffer for the datagram 00053 // 00054 struct DatagramBuffer 00055 { 00056 ReassemblyBuffer buf; // reassembly buffer 00057 IPv6Datagram *datagram; // the actual datagram 00058 simtime_t lastupdate; // last time a new fragment arrived 00059 }; 00060 00061 // we use std::map for fast lookup by datagram Id 00062 typedef std::map<Key,DatagramBuffer> Buffers; 00063 00064 // the reassembly buffers 00065 Buffers bufs; 00066 00067 // needed for TIME_EXCEEDED errors 00068 ICMPv6 *icmpModule; 00069 00070 public: 00074 IPv6FragBuf(); 00075 00079 ~IPv6FragBuf(); 00080 00085 void init(ICMPv6 *icmp); 00086 00092 IPv6Datagram *addFragment(IPv6Datagram *datagram, IPv6FragmentHeader *fh, simtime_t now); 00093 00103 void purgeStaleFragments(simtime_t lastupdate); 00104 }; 00105 00106 #endif 00107