Sophie

Sophie

distrib > Mandriva > 2010.0 > i586 > media > contrib-release > by-pkgid > 29c369053a983cc5d8c880dc6e0a2237 > files > 702

libdtn-devel-2.6.0-2mdv2009.1.i586.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>DTN Reference Implementation: TLVCreator.h Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css">
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.5.8 -->
<div class="navigation" id="top">
  <div class="tabs">
    <ul>
      <li><a href="main.html"><span>Main&nbsp;Page</span></a></li>
      <li><a href="namespaces.html"><span>Namespaces</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
  <div class="tabs">
    <ul>
      <li><a href="files.html"><span>File&nbsp;List</span></a></li>
      <li><a href="globals.html"><span>File&nbsp;Members</span></a></li>
    </ul>
  </div>
<h1>TLVCreator.h</h1><a href="TLVCreator_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
<a name="l00002"></a>00002 <span class="comment"> *    Copyright 2007 Baylor University</span>
<a name="l00003"></a>00003 <span class="comment"> *</span>
<a name="l00004"></a>00004 <span class="comment"> *    Licensed under the Apache License, Version 2.0 (the "License");</span>
<a name="l00005"></a>00005 <span class="comment"> *    you may not use this file except in compliance with the License.</span>
<a name="l00006"></a>00006 <span class="comment"> *    You may obtain a copy of the License at</span>
<a name="l00007"></a>00007 <span class="comment"> *</span>
<a name="l00008"></a>00008 <span class="comment"> *        http://www.apache.org/licenses/LICENSE-2.0</span>
<a name="l00009"></a>00009 <span class="comment"> *</span>
<a name="l00010"></a>00010 <span class="comment"> *    Unless required by applicable law or agreed to in writing, software</span>
<a name="l00011"></a>00011 <span class="comment"> *    distributed under the License is distributed on an "AS IS" BASIS,</span>
<a name="l00012"></a>00012 <span class="comment"> *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.</span>
<a name="l00013"></a>00013 <span class="comment"> *    See the License for the specific language governing permissions and</span>
<a name="l00014"></a>00014 <span class="comment"> *    limitations under the License.</span>
<a name="l00015"></a>00015 <span class="comment"> */</span>
<a name="l00016"></a>00016 
<a name="l00017"></a>00017 <span class="preprocessor">#ifndef _PROPHET_TLV_CREATOR_H_</span>
<a name="l00018"></a>00018 <span class="preprocessor"></span><span class="preprocessor">#define _PROPHET_TLV_CREATOR_H_</span>
<a name="l00019"></a>00019 <span class="preprocessor"></span>
<a name="l00020"></a>00020 <span class="preprocessor">#include "<a class="code" href="Table_8h.html">Table.h</a>"</span>
<a name="l00021"></a>00021 <span class="preprocessor">#include "<a class="code" href="BundleCore_8h.html">BundleCore.h</a>"</span>
<a name="l00022"></a>00022 <span class="preprocessor">#include "BundleList.h"</span>
<a name="l00023"></a>00023 <span class="preprocessor">#include "Dictionary.h"</span>
<a name="l00024"></a>00024 <span class="preprocessor">#include "<a class="code" href="RIBDTLV_8h.html">RIBDTLV.h</a>"</span>
<a name="l00025"></a>00025 <span class="preprocessor">#include "<a class="code" href="RIBTLV_8h.html">RIBTLV.h</a>"</span>
<a name="l00026"></a>00026 <span class="preprocessor">#include "<a class="code" href="OfferTLV_8h.html">OfferTLV.h</a>"</span>
<a name="l00027"></a>00027 <span class="preprocessor">#include "<a class="code" href="BundleTLVEntryList_8h.html">BundleTLVEntryList.h</a>"</span>
<a name="l00028"></a>00028 <span class="preprocessor">#include "<a class="code" href="BundleOffer_8h.html">BundleOffer.h</a>"</span>
<a name="l00029"></a>00029 <span class="preprocessor">#include "<a class="code" href="Oracle_8h.html">Oracle.h</a>"</span>
<a name="l00030"></a>00030 <span class="preprocessor">#include &lt;string&gt;</span>
<a name="l00031"></a>00031 
<a name="l00032"></a>00032 <span class="keyword">namespace </span>prophet
<a name="l00033"></a>00033 {
<a name="l00034"></a>00034 
<a name="l00035"></a>00035 <span class="keyword">struct </span>TLVCreator
<a name="l00036"></a>00036 {
<a name="l00037"></a>00037     <span class="keyword">static</span> RIBDTLV* ribd(BundleCore* core,
<a name="l00038"></a>00038                          <span class="keyword">const</span> Table* nodes,
<a name="l00039"></a>00039                          <span class="keyword">const</span> std::string&amp; sender,
<a name="l00040"></a>00040                          <span class="keyword">const</span> std::string&amp; receiver)
<a name="l00041"></a>00041     {
<a name="l00042"></a>00042         <span class="comment">// reject the oddball</span>
<a name="l00043"></a>00043         <span class="keywordflow">if</span> (core == NULL || nodes == NULL) <span class="keywordflow">return</span> NULL;
<a name="l00044"></a>00044 
<a name="l00045"></a>00045         Dictionary ribd(sender,receiver);
<a name="l00046"></a>00046         <span class="keywordflow">for</span> (<a class="code" href="classprophet_1_1Table.html#a2f4bc33f615e318215dc60b48447a5d">Table::const_iterator</a> i = nodes-&gt;begin(); i != nodes-&gt;end(); i++)
<a name="l00047"></a>00047         {
<a name="l00048"></a>00048             <span class="comment">// grab the route from the iterator</span>
<a name="l00049"></a>00049             std::string dest = i-&gt;first;
<a name="l00050"></a>00050             std::string eid = core-&gt;get_route(dest);
<a name="l00051"></a>00051             <span class="comment">// attempt to insert, fail out if unsuccessful</span>
<a name="l00052"></a>00052             <span class="keywordflow">if</span> (ribd.insert(eid) == <a class="code" href="classprophet_1_1Dictionary.html#bb335d818c777bf393a25cbbd0661679" title="Reserve 0xffff for in-band error signal.">Dictionary::INVALID_SID</a> &amp;&amp;
<a name="l00053"></a>00053                 ribd.find(eid) == <a class="code" href="classprophet_1_1Dictionary.html#bb335d818c777bf393a25cbbd0661679" title="Reserve 0xffff for in-band error signal.">Dictionary::INVALID_SID</a>) <span class="keywordflow">return</span> NULL;
<a name="l00054"></a>00054         }
<a name="l00055"></a>00055 
<a name="l00056"></a>00056         ribd.dump(core,__FILE__,__LINE__);
<a name="l00057"></a>00057         <span class="keywordflow">return</span> <span class="keyword">new</span> RIBDTLV(ribd);
<a name="l00058"></a>00058     }
<a name="l00059"></a>00059 
<a name="l00060"></a>00060     <span class="keyword">static</span> RIBTLV* rib(Oracle* oracle,
<a name="l00061"></a>00061                        <span class="keyword">const</span> Dictionary&amp; ribd,
<a name="l00062"></a>00062                        <span class="keywordtype">bool</span> relay_node,
<a name="l00063"></a>00063                        <span class="keywordtype">bool</span> accept_custody,
<a name="l00064"></a>00064                        <span class="keywordtype">bool</span> internet_gw = <span class="keyword">false</span>)
<a name="l00065"></a>00065     {
<a name="l00066"></a>00066         <span class="comment">// reject the oddball</span>
<a name="l00067"></a>00067         <span class="keywordflow">if</span> (oracle == NULL) <span class="keywordflow">return</span> NULL;
<a name="l00068"></a>00068 
<a name="l00069"></a>00069         <span class="keyword">const</span> Table* nodes = oracle-&gt;nodes();
<a name="l00070"></a>00070         std::string sender = ribd.find(0);
<a name="l00071"></a>00071         std::string receiver = ribd.find(1);
<a name="l00072"></a>00072 
<a name="l00073"></a>00073         <a class="code" href="namespaceprophet.html#85efb86d8e405350d5ac3236c15e4be5">RIBNodeList</a> list;
<a name="l00074"></a>00074         <span class="keywordflow">for</span> (<a class="code" href="classprophet_1_1Table.html#a2f4bc33f615e318215dc60b48447a5d">Table::const_iterator</a> i = nodes-&gt;begin(); i != nodes-&gt;end(); i++)
<a name="l00075"></a>00075         {
<a name="l00076"></a>00076             <span class="keyword">const</span> std::string eid = i-&gt;first;
<a name="l00077"></a>00077             <span class="keywordflow">if</span> (eid == sender || eid == receiver) <span class="keywordflow">continue</span>;
<a name="l00078"></a>00078             <span class="keyword">const</span> Node* n = i-&gt;second;
<a name="l00079"></a>00079             u_int16_t sid = ribd.find(eid);
<a name="l00080"></a>00080             <span class="keywordflow">if</span> (sid == <a class="code" href="classprophet_1_1Dictionary.html#bb335d818c777bf393a25cbbd0661679" title="Reserve 0xffff for in-band error signal.">Dictionary::INVALID_SID</a>)
<a name="l00081"></a>00081                 <span class="keywordflow">return</span> NULL; <span class="comment">// log error?</span>
<a name="l00082"></a>00082             oracle-&gt;core()-&gt;print_log(<span class="stringliteral">"rib"</span>,<a class="code" href="classprophet_1_1BundleCore.html#494b3a7c2b761b5b79873ea016ab8cc8" title="Log level.">BundleCore::LOG_DEBUG</a>,
<a name="l00083"></a>00083                     <span class="stringliteral">"%s (%u) -&gt; %.2f"</span>,eid.c_str(),sid,n-&gt;p_value());
<a name="l00084"></a>00084             list.push_back(<span class="keyword">new</span> RIBNode(n,sid));
<a name="l00085"></a>00085         }
<a name="l00086"></a>00086 
<a name="l00087"></a>00087         ribd.dump(oracle-&gt;core(),__FILE__,__LINE__);
<a name="l00088"></a>00088         <span class="keywordflow">return</span> <span class="keyword">new</span> RIBTLV(list,relay_node,accept_custody,internet_gw);
<a name="l00089"></a>00089     }
<a name="l00090"></a>00090 
<a name="l00091"></a>00091     <span class="keyword">static</span> OfferTLV* offer(Oracle* oracle,
<a name="l00092"></a>00092                            <span class="keyword">const</span> Link* nexthop,
<a name="l00093"></a>00093                            <span class="keyword">const</span> Dictionary&amp; ribd,
<a name="l00094"></a>00094                            <span class="keyword">const</span> Table&amp; remote)
<a name="l00095"></a>00095     {
<a name="l00096"></a>00096         <span class="comment">// reject the oddball</span>
<a name="l00097"></a>00097         <span class="keywordflow">if</span> (oracle == NULL) <span class="keywordflow">return</span> NULL;
<a name="l00098"></a>00098 
<a name="l00099"></a>00099         <span class="comment">// create comp</span>
<a name="l00100"></a>00100         FwdStrategyComp* comp = <a class="code" href="structprophet_1_1FwdStrategy.html#923e75aec806ac8dfdb97904e222ae7a" title="Factory method to create instance of appropriate type of comparator.">FwdStrategy::strategy</a>(
<a name="l00101"></a>00101                 oracle-&gt;params()-&gt;fs(),
<a name="l00102"></a>00102                 oracle-&gt;nodes(),
<a name="l00103"></a>00103                 &amp;remote);
<a name="l00104"></a>00104 
<a name="l00105"></a>00105         <span class="comment">// create decider</span>
<a name="l00106"></a>00106         Decider* d = Decider::decider(
<a name="l00107"></a>00107                 oracle-&gt;params()-&gt;fs(),
<a name="l00108"></a>00108                 nexthop,
<a name="l00109"></a>00109                 oracle-&gt;core(),
<a name="l00110"></a>00110                 oracle-&gt;nodes(),
<a name="l00111"></a>00111                 &amp;remote,
<a name="l00112"></a>00112                 oracle-&gt;stats(),
<a name="l00113"></a>00113                 oracle-&gt;params()-&gt;max_forward(),
<a name="l00114"></a>00114                 oracle-&gt;params()-&gt;relay_node());
<a name="l00115"></a>00115 
<a name="l00116"></a>00116         <span class="comment">// offer's destructor will clean up comp and d</span>
<a name="l00117"></a>00117         BundleOffer offer(oracle-&gt;core(),oracle-&gt;core()-&gt;bundles(),comp,d);
<a name="l00118"></a>00118 
<a name="l00119"></a>00119         <span class="comment">// Create a reduced list of ACKs by only tacking on those that </span>
<a name="l00120"></a>00120         <span class="comment">// haven't already been sent</span>
<a name="l00121"></a>00121 
<a name="l00122"></a>00122         PointerList&lt;Ack&gt; acklist; <span class="comment">// list of clones from oracle's ACKs</span>
<a name="l00123"></a>00123         AckList acks; <span class="comment">// reduced list to send to get_bundle_offer</span>
<a name="l00124"></a>00124         AckList* link_acks = <span class="keyword">const_cast&lt;</span>Link*<span class="keyword">&gt;</span>(nexthop)-&gt;acks();
<a name="l00125"></a>00125 
<a name="l00126"></a>00126         oracle-&gt;acks()-&gt;clone(acklist);
<a name="l00127"></a>00127         <span class="keywordflow">for</span>(PointerList&lt;Ack&gt;::iterator i = acklist.begin();
<a name="l00128"></a>00128                 i != acklist.end(); i++)
<a name="l00129"></a>00129         {
<a name="l00130"></a>00130             <span class="comment">// returns false if already exists in list (meaning, already sent)</span>
<a name="l00131"></a>00131             <span class="keywordflow">if</span> (link_acks-&gt;insert(*i))
<a name="l00132"></a>00132                 acks.insert(*i);
<a name="l00133"></a>00133         }
<a name="l00134"></a>00134 
<a name="l00135"></a>00135         BundleOfferList list = offer.get_bundle_offer(ribd,&amp;acks);
<a name="l00136"></a>00136         
<a name="l00137"></a>00137         <span class="keywordflow">if</span> (list.empty())
<a name="l00138"></a>00138             oracle-&gt;core()-&gt;print_log(<span class="stringliteral">"offer"</span>,<a class="code" href="classprophet_1_1BundleCore.html#494b3a7c2b761b5b79873ea016ab8cc8" title="Log level.">BundleCore::LOG_DEBUG</a>,
<a name="l00139"></a>00139                     <span class="stringliteral">"empty bundle offer"</span>);
<a name="l00140"></a>00140         <span class="keywordflow">else</span>
<a name="l00141"></a>00141         {
<a name="l00142"></a>00142             <span class="keywordflow">for</span> (<a class="code" href="classprophet_1_1BundleEntryList.html#3332c2306c20626dd5e0b9767ac2c378">BundleOfferList::const_iterator</a> i = list.begin(); 
<a name="l00143"></a>00143                     i != list.end(); i++)
<a name="l00144"></a>00144             {
<a name="l00145"></a>00145                 oracle-&gt;core()-&gt;print_log(<span class="stringliteral">"offer"</span>,<a class="code" href="classprophet_1_1BundleCore.html#494b3a7c2b761b5b79873ea016ab8cc8" title="Log level.">BundleCore::LOG_DEBUG</a>,
<a name="l00146"></a>00146                         <span class="stringliteral">"%u %u %u %s%s%s"</span>,
<a name="l00147"></a>00147                         (*i)-&gt;creation_ts(),
<a name="l00148"></a>00148                         (*i)-&gt;seqno(),
<a name="l00149"></a>00149                         (*i)-&gt;sid(),
<a name="l00150"></a>00150                         (*i)-&gt;custody() ? <span class="stringliteral">"C"</span> : <span class="stringliteral">"-"</span>,
<a name="l00151"></a>00151                         (*i)-&gt;accept() ? <span class="stringliteral">"A"</span> : <span class="stringliteral">"-"</span>,
<a name="l00152"></a>00152                         (*i)-&gt;ack() ? <span class="stringliteral">"K"</span> : <span class="stringliteral">"-"</span>);
<a name="l00153"></a>00153             }
<a name="l00154"></a>00154         }
<a name="l00155"></a>00155 
<a name="l00156"></a>00156         <span class="keywordflow">return</span> <span class="keyword">new</span> OfferTLV(list);
<a name="l00157"></a>00157     }
<a name="l00158"></a>00158 
<a name="l00159"></a>00159     <span class="keyword">static</span> ResponseTLV* response(Oracle* oracle,
<a name="l00160"></a>00160                                  <span class="keyword">const</span> BundleOfferList&amp; offers,
<a name="l00161"></a>00161                                  BundleResponseList&amp; list,
<a name="l00162"></a>00162                                  <span class="keyword">const</span> Dictionary&amp; ribd)
<a name="l00163"></a>00163     {
<a name="l00164"></a>00164         <span class="comment">// reject the oddball</span>
<a name="l00165"></a>00165         <span class="keywordflow">if</span> (oracle == NULL) <span class="keywordflow">return</span> NULL;
<a name="l00166"></a>00166 
<a name="l00167"></a>00167         ribd.dump(oracle-&gt;core(),__FILE__,__LINE__);
<a name="l00168"></a>00168 
<a name="l00169"></a>00169         <span class="keywordflow">for</span> (<a class="code" href="classprophet_1_1BundleEntryList.html#3332c2306c20626dd5e0b9767ac2c378">BundleOfferList::const_iterator</a> i = offers.begin();
<a name="l00170"></a>00170                 i != offers.end(); i++)
<a name="l00171"></a>00171         {
<a name="l00172"></a>00172             <span class="comment">// pull out the three-way tuple that uniquely identifies bundles</span>
<a name="l00173"></a>00173             u_int32_t cts = (*i)-&gt;creation_ts();
<a name="l00174"></a>00174             u_int32_t seq = (*i)-&gt;seqno();
<a name="l00175"></a>00175             u_int16_t sid = (*i)-&gt;sid();
<a name="l00176"></a>00176             std::string eid = ribd.find(sid);
<a name="l00177"></a>00177 
<a name="l00178"></a>00178             <span class="comment">// First delete any ACK'd bundles, and store the ACK</span>
<a name="l00179"></a>00179             <span class="keyword">const</span> Bundle* b = oracle-&gt;core()-&gt;find(
<a name="l00180"></a>00180                     oracle-&gt;core()-&gt;bundles(),eid,cts,seq);
<a name="l00181"></a>00181             <span class="keywordflow">if</span> ((*i)-&gt;ack())
<a name="l00182"></a>00182             {
<a name="l00183"></a>00183                 oracle-&gt;core()-&gt;print_log(<span class="stringliteral">"response"</span>,<a class="code" href="classprophet_1_1BundleCore.html#494b3a7c2b761b5b79873ea016ab8cc8" title="Log level.">BundleCore::LOG_DEBUG</a>,
<a name="l00184"></a>00184                         <span class="stringliteral">"ACK %s %u:%u"</span>,eid.c_str(),cts,seq);
<a name="l00185"></a>00185 
<a name="l00186"></a>00186                 <span class="keywordflow">if</span> (b != NULL)
<a name="l00187"></a>00187                     oracle-&gt;ack(b);
<a name="l00188"></a>00188                 <span class="keywordflow">else</span>
<a name="l00189"></a>00189                     oracle-&gt;acks()-&gt;insert(eid,cts,seq);
<a name="l00190"></a>00190 
<a name="l00191"></a>00191                 <span class="comment">// also remember that it came from this link, so as not </span>
<a name="l00192"></a>00192                 <span class="comment">// to propagate this ACK over this link again</span>
<a name="l00193"></a>00193 
<a name="l00194"></a>00194             }
<a name="l00195"></a>00195             <span class="keywordflow">else</span>
<a name="l00196"></a>00196             <span class="comment">// only request the bundle if not already present in host storage</span>
<a name="l00197"></a>00197             <span class="comment">// and if no ACK exists for the bundle</span>
<a name="l00198"></a>00198             <span class="keywordflow">if</span> (b == NULL)
<a name="l00199"></a>00199             {
<a name="l00200"></a>00200                 <span class="comment">// no need to request bundles that have already been delivered</span>
<a name="l00201"></a>00201                 <span class="keywordflow">if</span> (oracle-&gt;acks()-&gt;is_ackd(eid,cts,seq))
<a name="l00202"></a>00202                 {
<a name="l00203"></a>00203                     oracle-&gt;core()-&gt;print_log(<span class="stringliteral">"response"</span>,<a class="code" href="classprophet_1_1BundleCore.html#494b3a7c2b761b5b79873ea016ab8cc8" title="Log level.">BundleCore::LOG_DEBUG</a>,
<a name="l00204"></a>00204                         <span class="stringliteral">"not requesting ACK'd bundle: %s %u %u"</span>,
<a name="l00205"></a>00205                         eid.c_str(),cts,seq);
<a name="l00206"></a>00206                     <span class="keywordflow">continue</span>;
<a name="l00207"></a>00207                 }
<a name="l00208"></a>00208 
<a name="l00209"></a>00209                 <span class="comment">// Logically AND local settings for custody accept with</span>
<a name="l00210"></a>00210                 <span class="comment">// remote's request for custody transfer</span>
<a name="l00211"></a>00211                 <span class="keywordtype">bool</span> <a class="code" href="dtncat_8c.html#160881851a33309c0106503ac4d14d96">custody</a> = (*i)-&gt;custody() &amp;&amp;
<a name="l00212"></a>00212                                oracle-&gt;core()-&gt;custody_accepted();
<a name="l00213"></a>00213                 <span class="keywordflow">if</span> (list.add_response(cts,seq,sid,custody))
<a name="l00214"></a>00214                 {
<a name="l00215"></a>00215                     <span class="keyword">const</span> BundleResponseEntry* bre = list.back();
<a name="l00216"></a>00216                     oracle-&gt;core()-&gt;print_log(<span class="stringliteral">"response"</span>,<a class="code" href="classprophet_1_1BundleCore.html#494b3a7c2b761b5b79873ea016ab8cc8" title="Log level.">BundleCore::LOG_DEBUG</a>,
<a name="l00217"></a>00217                         <span class="stringliteral">"%s (%u) %u %u"</span>,eid.c_str(),bre-&gt;sid(),
<a name="l00218"></a>00218                         bre-&gt;creation_ts(),bre-&gt;seqno());
<a name="l00219"></a>00219                 }
<a name="l00220"></a>00220             }
<a name="l00221"></a>00221         }
<a name="l00222"></a>00222 
<a name="l00223"></a>00223         <span class="keywordflow">return</span> <span class="keyword">new</span> ResponseTLV(list);
<a name="l00224"></a>00224     }
<a name="l00225"></a>00225 
<a name="l00226"></a>00226 }; <span class="comment">// struct TLVCreator</span>
<a name="l00227"></a>00227 
<a name="l00228"></a>00228 }; <span class="comment">// namespace prophet</span>
<a name="l00229"></a>00229 
<a name="l00230"></a>00230 <span class="preprocessor">#endif // _PROPHET_TLV_CREATOR_H_</span>
</pre></div></div>
<hr size="1"><address style="text-align: right;"><small>Generated on Fri Jan 30 09:26:58 2009 for DTN Reference Implementation by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.8 </small></address>
</body>
</html>