Menu

VarHeaderLength.h

Go to the documentation of this file.
00001 /*******************************************************************************
00002  *
00003  * Copyright (c) 2010 Philipp Werner <philipp.werner@st.ovgu.de>
00004  * All rights reserved.
00005  *
00006  *    Redistribution and use in source and binary forms, with or without
00007  *    modification, are permitted provided that the following conditions
00008  *    are met:
00009  *
00010  *    * Redistributions of source code must retain the above copyright
00011  *      notice, this list of conditions and the following disclaimer.
00012  *
00013  *    * Redistributions in binary form must reproduce the above copyright
00014  *      notice, this list of conditions and the following disclaimer in
00015  *      the documentation and/or other materials provided with the
00016  *      distribution.
00017  *
00018  *    * Neither the name of the copyright holders nor the names of
00019  *      contributors may be used to endorse or promote products derived
00020  *      from this software without specific prior written permission.
00021  *
00022  *
00023  *    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
00024  *    IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
00025  *    TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
00026  *    PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
00027  *    OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00028  *    SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00029  *    LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00030  *    DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00031  *    THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00032  *    (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00033  *    OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00034  *
00035  *
00036  * $Id$
00037  *
00038  ******************************************************************************/
00039 
00040 #ifndef __VARHEADERLENGTH_H_FB8B6AC493785D__
00041 #define __VARHEADERLENGTH_H_FB8B6AC493785D__
00042 
00043 
00044 #include "debug.h"
00045 #include "config/type_traits/ExpandedRangeTypeSelector.h"
00046 
00047 
00048 namespace famouso {
00049     namespace mw {
00050         namespace afp {
00051             namespace defrag {
00052                 namespace detail {
00053 
00054 
00055                     template <class DCP>
00056                     class VarHeaderLength {
00057 
00058                             typedef typename DCP::SizeProp::elen_t elen_t;
00059                             typedef typename DCP::SizeProp::flen_t flen_t;
00060                             typedef typename DCP::SizeProp::fcount_t fcount_t;
00061 
00062                         public:
00063 
00065                             typedef typename ExpandedRangeTypeSelector<elen_t>::type eelen_t;
00066 
00077                             static eelen_t get_payload(fcount_t frag_count, flen_t no_ext_mtu) {
00078                                 eelen_t p = 0;          // payload
00079                                 flen_t h = 1;           // header length
00080                                 fcount_t c_h = 32;      // max. fragment count for header length = h
00081                                 fcount_t c_max = 32;    // max. fragment count for header length <= h
00082 
00083                                 while (frag_count > c_h) {
00084                                     frag_count -= c_h;
00085                                     p += c_h * (no_ext_mtu - h);
00086 
00087                                     h++;
00088                                     FAMOUSO_ASSERT(h < no_ext_mtu);
00089                                     c_h = 127 * c_max;
00090                                     c_max = 128 * c_max;
00091                                 }
00092                                 p += frag_count * (no_ext_mtu - h);
00093                                 return p;
00094                             }
00095 
00096 
00105                             static flen_t get_basic_header_len(fcount_t fseq) {
00106                                 flen_t hl = 1;
00107                                 while (fseq >= 32) {
00108                                     hl++;
00109                                     fseq >>= 7;
00110                                 }
00111                                 return hl;
00112                             }
00113                     };
00114 
00115 
00116                 } // namespace detail
00117             } // namespace defrag
00118         } // namespace afp
00119     } // namespace mw
00120 } // namespace famouso
00121 
00122 
00123 #endif // __VARHEADERLENGTH_H_FB8B6AC493785D__
00124