Sophie

Sophie

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

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: ProphetTLV.cc 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>ProphetTLV.cc</h1><a href="ProphetTLV_8cc.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">#include &lt;arpa/inet.h&gt;</span> <span class="comment">// for hton[ls] and ntoh[ls]</span>
<a name="l00018"></a>00018 
<a name="l00019"></a>00019 <span class="preprocessor">#include "<a class="code" href="ProphetTLV_8h.html">ProphetTLV.h</a>"</span>
<a name="l00020"></a>00020 <span class="preprocessor">#include "<a class="code" href="HelloTLV_8h.html">HelloTLV.h</a>"</span>
<a name="l00021"></a>00021 <span class="preprocessor">#include "<a class="code" href="RIBDTLV_8h.html">RIBDTLV.h</a>"</span>
<a name="l00022"></a>00022 <span class="preprocessor">#include "<a class="code" href="RIBTLV_8h.html">RIBTLV.h</a>"</span>
<a name="l00023"></a>00023 <span class="preprocessor">#include "<a class="code" href="OfferTLV_8h.html">OfferTLV.h</a>"</span>
<a name="l00024"></a>00024 <span class="preprocessor">#include "<a class="code" href="ResponseTLV_8h.html">ResponseTLV.h</a>"</span>
<a name="l00025"></a>00025 <span class="preprocessor">#include "<a class="code" href="Params_8h.html">Params.h</a>"</span>
<a name="l00026"></a>00026 
<a name="l00027"></a>00027 <span class="keyword">namespace </span>prophet
<a name="l00028"></a>00028 {
<a name="l00029"></a>00029 
<a name="l00030"></a><a class="code" href="classprophet_1_1ProphetTLV.html#f4bc4ce27f0db6efac6f4c6e6dd569d9">00030</a> <a class="code" href="classprophet_1_1ProphetTLV.html#f4bc4ce27f0db6efac6f4c6e6dd569d9">ProphetTLV::ProphetTLV</a>()
<a name="l00031"></a>00031     : result_(UnknownResult), sender_instance_(0), receiver_instance_(0),
<a name="l00032"></a>00032       tid_(0), length_(ProphetHeaderSize)
<a name="l00033"></a>00033 {
<a name="l00034"></a>00034 }
<a name="l00035"></a>00035 
<a name="l00036"></a><a class="code" href="classprophet_1_1ProphetTLV.html#84bc3ce650a356af8f782852928ae067">00036</a> <a class="code" href="classprophet_1_1ProphetTLV.html#f4bc4ce27f0db6efac6f4c6e6dd569d9">ProphetTLV::ProphetTLV</a>(<span class="keyword">const</span> std::string&amp; <a class="code" href="dtnmoteproxy_8c.html#e1ade0f5a1b32f6c8be72f31a99e2a18">src</a>, <span class="keyword">const</span> std::string&amp; dst, 
<a name="l00037"></a>00037                        <a class="code" href="classprophet_1_1ProphetTLV.html#8612aff33b50bae0e7005ef59d14c274" title="Legal values for ProphetHeader.result field p.">header_result_t</a> result, u_int16_t local_instance,
<a name="l00038"></a>00038                        u_int16_t remote_instance, u_int32_t tid)
<a name="l00039"></a>00039     : src_(src), dst_(dst), result_(result),
<a name="l00040"></a>00040       sender_instance_(local_instance), 
<a name="l00041"></a>00041       receiver_instance_(remote_instance), tid_(tid),
<a name="l00042"></a>00042       length_(ProphetHeaderSize)
<a name="l00043"></a>00043 {
<a name="l00044"></a>00044 }
<a name="l00045"></a>00045 
<a name="l00046"></a><a class="code" href="classprophet_1_1ProphetTLV.html#4c2b108aa8da108f35c4f4b2fbf24172">00046</a> <a class="code" href="classprophet_1_1ProphetTLV.html#f4bc4ce27f0db6efac6f4c6e6dd569d9">ProphetTLV::ProphetTLV</a>(<span class="keyword">const</span> <a class="code" href="classprophet_1_1ProphetTLV.html">ProphetTLV</a>&amp; p)
<a name="l00047"></a>00047     : src_(p.src_), dst_(p.dst_), result_(p.result_),
<a name="l00048"></a>00048       sender_instance_(p.sender_instance_),
<a name="l00049"></a>00049       receiver_instance_(p.receiver_instance_),
<a name="l00050"></a>00050       tid_(p.tid_), length_(p.length_)
<a name="l00051"></a>00051 {
<a name="l00052"></a>00052     <a class="code" href="classprophet_1_1ProphetTLV.html#4a730ffc2e7ddd7639445d05c78f7a9d" title="Linked list of TLVs embedded in this Prophet TLV.">list_</a>.assign(p.<a class="code" href="classprophet_1_1ProphetTLV.html#4a730ffc2e7ddd7639445d05c78f7a9d" title="Linked list of TLVs embedded in this Prophet TLV.">list_</a>.begin(),p.<a class="code" href="classprophet_1_1ProphetTLV.html#4a730ffc2e7ddd7639445d05c78f7a9d" title="Linked list of TLVs embedded in this Prophet TLV.">list_</a>.end());
<a name="l00053"></a>00053 }
<a name="l00054"></a>00054 
<a name="l00055"></a><a class="code" href="classprophet_1_1ProphetTLV.html#cf13c3a9cc9321a621e76dea681ae2cc">00055</a> <a class="code" href="classprophet_1_1ProphetTLV.html#cf13c3a9cc9321a621e76dea681ae2cc" title="Destructor.">ProphetTLV::~ProphetTLV</a>()
<a name="l00056"></a>00056 {
<a name="l00057"></a>00057     <span class="keywordflow">for</span> (<a class="code" href="classprophet_1_1ProphetTLV.html#f9d02d9a43c726344e5fd4454b10248f">iterator</a> i = <a class="code" href="classprophet_1_1ProphetTLV.html#4a730ffc2e7ddd7639445d05c78f7a9d" title="Linked list of TLVs embedded in this Prophet TLV.">list_</a>.begin(); i != <a class="code" href="classprophet_1_1ProphetTLV.html#4a730ffc2e7ddd7639445d05c78f7a9d" title="Linked list of TLVs embedded in this Prophet TLV.">list_</a>.end(); i++)
<a name="l00058"></a>00058         <span class="keyword">delete</span> *i;
<a name="l00059"></a>00059 }
<a name="l00060"></a>00060 
<a name="l00061"></a>00061 <span class="keywordtype">size_t</span>
<a name="l00062"></a><a class="code" href="classprophet_1_1ProphetTLV.html#e6ac3c3c15db1d7e12c98a9f96a29b7e">00062</a> <a class="code" href="classprophet_1_1ProphetTLV.html#e6ac3c3c15db1d7e12c98a9f96a29b7e" title="Write ProphetTLV out to no more than len bytes of buffer; return bytes written.">ProphetTLV::serialize</a>(u_char* bp, <span class="keywordtype">size_t</span> <a class="code" href="num2sdnv_8c.html#fed088663f8704004425cdae2120b9b3">len</a>)<span class="keyword"> const</span>
<a name="l00063"></a>00063 <span class="keyword"></span>{
<a name="l00064"></a>00064     <span class="comment">// weed out the oddball</span>
<a name="l00065"></a>00065     <span class="keywordflow">if</span> (bp == NULL) <span class="keywordflow">return</span> 0;
<a name="l00066"></a>00066 
<a name="l00067"></a>00067     <span class="comment">// check that lengths match up</span>
<a name="l00068"></a>00068     <span class="keywordflow">if</span> (<a class="code" href="classprophet_1_1ProphetTLV.html#3a8d9c3d3763364ffe7ab755fabf522f">ProphetHeaderSize</a> &gt; len) <span class="keywordflow">return</span> 0;
<a name="l00069"></a>00069 
<a name="l00070"></a>00070     <span class="comment">// initialize some accounting</span>
<a name="l00071"></a>00071     <a class="code" href="classprophet_1_1ProphetTLV.html#47f93a2a8a1b1fe7615ce69c438cdcdf" title="Serialized length of this TLV.">length_</a> = 0;
<a name="l00072"></a>00072 
<a name="l00073"></a>00073     <span class="comment">// save pointer to header</span>
<a name="l00074"></a>00074     <a class="code" href="structprophet_1_1ProphetTLV_1_1ProphetHeader.html" title="Header Definition p.">ProphetHeader</a>* hdr = (<a class="code" href="structprophet_1_1ProphetTLV_1_1ProphetHeader.html" title="Header Definition p.">ProphetHeader</a>*) bp;
<a name="l00075"></a>00075     memset(hdr,0,<a class="code" href="classprophet_1_1ProphetTLV.html#3a8d9c3d3763364ffe7ab755fabf522f">ProphetHeaderSize</a>);
<a name="l00076"></a>00076 
<a name="l00077"></a>00077     <span class="comment">// skip past header for now</span>
<a name="l00078"></a>00078     bp += <a class="code" href="classprophet_1_1ProphetTLV.html#3a8d9c3d3763364ffe7ab755fabf522f">ProphetHeaderSize</a>;
<a name="l00079"></a>00079 
<a name="l00080"></a>00080     <span class="comment">// write out each TLV to buffer</span>
<a name="l00081"></a>00081     <span class="keywordflow">for</span> (<a class="code" href="classprophet_1_1ProphetTLV.html#8f32d86d9a6895255507bc316687330e">const_iterator</a> i = <a class="code" href="classprophet_1_1ProphetTLV.html#4a730ffc2e7ddd7639445d05c78f7a9d" title="Linked list of TLVs embedded in this Prophet TLV.">list_</a>.begin(); i != <a class="code" href="classprophet_1_1ProphetTLV.html#4a730ffc2e7ddd7639445d05c78f7a9d" title="Linked list of TLVs embedded in this Prophet TLV.">list_</a>.end(); i++)
<a name="l00082"></a>00082     {
<a name="l00083"></a>00083         <a class="code" href="classprophet_1_1BaseTLV.html" title="The Prophet I-D (March 2006) dictates five bytecodes for router state exchange messages...">BaseTLV</a>* tlv = *i;
<a name="l00084"></a>00084         <span class="keywordtype">size_t</span> bytes_written = tlv-&gt;<a class="code" href="classprophet_1_1BaseTLV.html#18534e5841ee8447ca2c51cf299becd0" title="Write out TLV from in-memory representation into provided buffer, using no more than...">serialize</a>(bp,len);
<a name="l00085"></a>00085         <span class="keywordflow">if</span> (bytes_written != tlv-&gt;<a class="code" href="classprophet_1_1BaseTLV.html#5d6ab71b768b416bc457090d1189b291" title="Accessors.">length</a>())
<a name="l00086"></a>00086             <span class="keywordflow">break</span>;
<a name="l00087"></a>00087 
<a name="l00088"></a>00088         <a class="code" href="classprophet_1_1ProphetTLV.html#47f93a2a8a1b1fe7615ce69c438cdcdf" title="Serialized length of this TLV.">length_</a> += bytes_written;
<a name="l00089"></a>00089         len     -= bytes_written;
<a name="l00090"></a>00090         bp      += bytes_written;
<a name="l00091"></a>00091     }
<a name="l00092"></a>00092 
<a name="l00093"></a>00093     <span class="comment">// if all went well, the math should line up</span>
<a name="l00094"></a>00094     <span class="keywordflow">if</span> (<a class="code" href="classprophet_1_1ProphetTLV.html#3a8d9c3d3763364ffe7ab755fabf522f">ProphetHeaderSize</a> &gt; len) <span class="keywordflow">return</span> 0;
<a name="l00095"></a>00095 
<a name="l00096"></a>00096     <span class="comment">// now write out the header</span>
<a name="l00097"></a>00097     <a class="code" href="classprophet_1_1ProphetTLV.html#47f93a2a8a1b1fe7615ce69c438cdcdf" title="Serialized length of this TLV.">length_</a> += <a class="code" href="classprophet_1_1ProphetTLV.html#3a8d9c3d3763364ffe7ab755fabf522f">ProphetHeaderSize</a>;
<a name="l00098"></a>00098     len     -= <a class="code" href="classprophet_1_1ProphetTLV.html#3a8d9c3d3763364ffe7ab755fabf522f">ProphetHeaderSize</a>;
<a name="l00099"></a>00099 
<a name="l00100"></a>00100     hdr-&gt;<a class="code" href="structprophet_1_1ProphetTLV_1_1ProphetHeader.html#78926b93e6ea4e360ffdab8cf46c24dd" title="This version of the PRoPHET Protocol = 1.">version</a>           = <a class="code" href="classprophet_1_1ProphetParams.html#a03c1f2abfb829093d93fdc489ed56cd" title="Current version of the protocol.">ProphetParams::PROPHET_VERSION</a>;
<a name="l00101"></a>00101     hdr-&gt;<a class="code" href="structprophet_1_1ProphetTLV_1_1ProphetHeader.html#a176e0483e0d2787a8f511fe3c3a8ec1" title="TBD.">flags</a>             = 0;
<a name="l00102"></a>00102     hdr-&gt;<a class="code" href="structprophet_1_1ProphetTLV_1_1ProphetHeader.html#4fb75a06d41e250c589f15da9d6a5e79" title="Field that is used to indicate whether a response is required to the request message...">result</a>            = <a class="code" href="classprophet_1_1ProphetTLV.html#70c7e729beb6adfadcdfeba0c0d66e48" title="Disposition of this Prophet TLV.">result_</a>;
<a name="l00103"></a>00103     hdr-&gt;<a class="code" href="structprophet_1_1ProphetTLV_1_1ProphetHeader.html#54bd2a3d93895cccc3bd6defae1099cc" title="Field gives further information concerning the result in a response message.">code</a>              = 0;
<a name="l00104"></a>00104     hdr-&gt;<a class="code" href="structprophet_1_1ProphetTLV_1_1ProphetHeader.html#83b7b89d87997fb770fa04eddabec350" title="For messages during the Hello phase with the Hello SYN, Hello SYNACK, and Hello ACK...">sender_instance</a>   = htons(<a class="code" href="classprophet_1_1ProphetTLV.html#a5c646fb585272d478dde3b33459412c" title="Local node&amp;#39;s index for this encounter.">sender_instance_</a>);
<a name="l00105"></a>00105     hdr-&gt;<a class="code" href="structprophet_1_1ProphetTLV_1_1ProphetHeader.html#acff2ef85ea793081b0e853e658ac438" title="For messages during the Hello phase with the Hello SYN, Hello SYNACK, and Hello ACK...">receiver_instance</a> = htons(<a class="code" href="classprophet_1_1ProphetTLV.html#753213cd2699f81fafb1b611660257b1" title="Peer&amp;#39;s index for this encounter.">receiver_instance_</a>);
<a name="l00106"></a>00106     hdr-&gt;<a class="code" href="structprophet_1_1ProphetTLV_1_1ProphetHeader.html#d5bc7f1caa6386e1ff19c5e1c3c55135" title="Used to associate a message with its response message.">transaction_id</a>    = htonl(<a class="code" href="classprophet_1_1ProphetTLV.html#4a89f5a792bb50f1b24980058245d3e8" title="Transaction ID for this TLV.">tid_</a>);
<a name="l00107"></a>00107     hdr-&gt;<a class="code" href="structprophet_1_1ProphetTLV_1_1ProphetHeader.html#866e230b9ea5df8e61d98dd791b833e1" title="Length in octets of this message including headers and message body.">length</a>            = htons(<a class="code" href="classprophet_1_1ProphetTLV.html#47f93a2a8a1b1fe7615ce69c438cdcdf" title="Serialized length of this TLV.">length_</a>);
<a name="l00108"></a>00108 
<a name="l00109"></a>00109     <span class="keywordflow">return</span> <a class="code" href="classprophet_1_1ProphetTLV.html#47f93a2a8a1b1fe7615ce69c438cdcdf" title="Serialized length of this TLV.">length_</a>;
<a name="l00110"></a>00110 }
<a name="l00111"></a>00111 
<a name="l00112"></a>00112 <a class="code" href="classprophet_1_1ProphetTLV.html">ProphetTLV</a>*
<a name="l00113"></a><a class="code" href="classprophet_1_1ProphetTLV.html#dd264b57f9575d3af5a5c7e1e3414bcf">00113</a> <a class="code" href="classprophet_1_1ProphetTLV.html#dd264b57f9575d3af5a5c7e1e3414bcf" title="Read ProphetTLV in from no more than len bytes of buffer; return bytes read.">ProphetTLV::deserialize</a>(<span class="keyword">const</span> std::string&amp; <a class="code" href="dtnmoteproxy_8c.html#e1ade0f5a1b32f6c8be72f31a99e2a18">src</a>,
<a name="l00114"></a>00114                         <span class="keyword">const</span> std::string&amp; dst,
<a name="l00115"></a>00115                         <span class="keyword">const</span> u_char* bp, <span class="keywordtype">size_t</span> <a class="code" href="num2sdnv_8c.html#fed088663f8704004425cdae2120b9b3">len</a>)
<a name="l00116"></a>00116 {
<a name="l00117"></a>00117     <span class="comment">// weed out the oddball</span>
<a name="l00118"></a>00118     <span class="keywordflow">if</span> (bp == NULL) <span class="keywordflow">return</span> NULL;
<a name="l00119"></a>00119 
<a name="l00120"></a>00120     <span class="comment">// check that lengths match up</span>
<a name="l00121"></a>00121     <span class="keywordflow">if</span> (<a class="code" href="classprophet_1_1ProphetTLV.html#3a8d9c3d3763364ffe7ab755fabf522f">ProphetHeaderSize</a> &gt; len) <span class="keywordflow">return</span> NULL;
<a name="l00122"></a>00122 
<a name="l00123"></a>00123     <span class="comment">// start reading and validating header from buffer</span>
<a name="l00124"></a>00124     <a class="code" href="structprophet_1_1ProphetTLV_1_1ProphetHeader.html" title="Header Definition p.">ProphetHeader</a>* hdr = (<a class="code" href="structprophet_1_1ProphetTLV_1_1ProphetHeader.html" title="Header Definition p.">ProphetHeader</a>*) bp; 
<a name="l00125"></a>00125     <span class="keywordflow">if</span> (hdr-&gt;<a class="code" href="structprophet_1_1ProphetTLV_1_1ProphetHeader.html#78926b93e6ea4e360ffdab8cf46c24dd" title="This version of the PRoPHET Protocol = 1.">version</a> != <a class="code" href="classprophet_1_1ProphetParams.html#a03c1f2abfb829093d93fdc489ed56cd" title="Current version of the protocol.">ProphetParams::PROPHET_VERSION</a>) <span class="keywordflow">return</span> NULL;
<a name="l00126"></a>00126     <span class="keywordflow">if</span> (hdr-&gt;<a class="code" href="structprophet_1_1ProphetTLV_1_1ProphetHeader.html#a176e0483e0d2787a8f511fe3c3a8ec1" title="TBD.">flags</a> != 0) <span class="keywordflow">return</span> NULL;
<a name="l00127"></a>00127     <span class="keywordflow">if</span> (hdr-&gt;<a class="code" href="structprophet_1_1ProphetTLV_1_1ProphetHeader.html#54bd2a3d93895cccc3bd6defae1099cc" title="Field gives further information concerning the result in a response message.">code</a> != 0) <span class="keywordflow">return</span> NULL;
<a name="l00128"></a>00128     <span class="keywordflow">if</span> (static_cast&lt;size_t&gt;(ntohs(hdr-&gt;<a class="code" href="structprophet_1_1ProphetTLV_1_1ProphetHeader.html#866e230b9ea5df8e61d98dd791b833e1" title="Length in octets of this message including headers and message body.">length</a>)) &gt; len) <span class="keywordflow">return</span> NULL;
<a name="l00129"></a>00129 
<a name="l00130"></a>00130     <span class="comment">// Create object and begin copying in from buffer</span>
<a name="l00131"></a>00131     <a class="code" href="classprophet_1_1ProphetTLV.html">ProphetTLV</a>* p = <span class="keyword">new</span> <a class="code" href="classprophet_1_1ProphetTLV.html#f4bc4ce27f0db6efac6f4c6e6dd569d9">ProphetTLV</a>();
<a name="l00132"></a>00132     p-&gt;<a class="code" href="classprophet_1_1ProphetTLV.html#e6b7fa9fb743044e2f09366cbbfb4199" title="destination id for TLV source (from Bundle metadata)">src_</a>               = src;
<a name="l00133"></a>00133     p-&gt;<a class="code" href="classprophet_1_1ProphetTLV.html#e40801aa7f49ddab1ad25c37701f9f47" title="destination id for TLV destination (from Bundle &amp;quot;)">dst_</a>               = dst;
<a name="l00134"></a>00134     p-&gt;<a class="code" href="classprophet_1_1ProphetTLV.html#70c7e729beb6adfadcdfeba0c0d66e48" title="Disposition of this Prophet TLV.">result_</a>            = (<a class="code" href="classprophet_1_1ProphetTLV.html#8612aff33b50bae0e7005ef59d14c274" title="Legal values for ProphetHeader.result field p.">header_result_t</a>) hdr-&gt;<a class="code" href="structprophet_1_1ProphetTLV_1_1ProphetHeader.html#4fb75a06d41e250c589f15da9d6a5e79" title="Field that is used to indicate whether a response is required to the request message...">result</a>;
<a name="l00135"></a>00135     p-&gt;<a class="code" href="classprophet_1_1ProphetTLV.html#a5c646fb585272d478dde3b33459412c" title="Local node&amp;#39;s index for this encounter.">sender_instance_</a>   = ntohs(hdr-&gt;<a class="code" href="structprophet_1_1ProphetTLV_1_1ProphetHeader.html#83b7b89d87997fb770fa04eddabec350" title="For messages during the Hello phase with the Hello SYN, Hello SYNACK, and Hello ACK...">sender_instance</a>);
<a name="l00136"></a>00136     p-&gt;<a class="code" href="classprophet_1_1ProphetTLV.html#753213cd2699f81fafb1b611660257b1" title="Peer&amp;#39;s index for this encounter.">receiver_instance_</a> = ntohs(hdr-&gt;<a class="code" href="structprophet_1_1ProphetTLV_1_1ProphetHeader.html#acff2ef85ea793081b0e853e658ac438" title="For messages during the Hello phase with the Hello SYN, Hello SYNACK, and Hello ACK...">receiver_instance</a>);
<a name="l00137"></a>00137     p-&gt;<a class="code" href="classprophet_1_1ProphetTLV.html#4a89f5a792bb50f1b24980058245d3e8" title="Transaction ID for this TLV.">tid_</a>               = ntohl(hdr-&gt;<a class="code" href="structprophet_1_1ProphetTLV_1_1ProphetHeader.html#d5bc7f1caa6386e1ff19c5e1c3c55135" title="Used to associate a message with its response message.">transaction_id</a>);
<a name="l00138"></a>00138     <span class="keywordtype">bool</span> submessage_flag = (hdr-&gt;<a class="code" href="structprophet_1_1ProphetTLV_1_1ProphetHeader.html#ec5c0c81380555747fd6fd2855ef0a64" title="If S is set then the SubMessage Number field indicates the total number of SubMessage...">submessage_flag</a> == 0x1);
<a name="l00139"></a>00139     u_int16_t submessage_num = ntohs(hdr-&gt;<a class="code" href="structprophet_1_1ProphetTLV_1_1ProphetHeader.html#c247cbd2076e7c0d5036a6154ab0f41a" title="When a message is segmented because it exceeds the MTU of the link layer, each segment...">submessage_num</a>);
<a name="l00140"></a>00140 
<a name="l00141"></a>00141     <span class="comment">// prophet tlv fragmentation is not supported by this implementation</span>
<a name="l00142"></a>00142     <span class="keywordflow">if</span> (submessage_flag == <span class="keyword">true</span> || submessage_num != 0)
<a name="l00143"></a>00143     {
<a name="l00144"></a>00144         <span class="keyword">delete</span> p;
<a name="l00145"></a>00145         <span class="keywordflow">return</span> NULL;
<a name="l00146"></a>00146     }
<a name="l00147"></a>00147 
<a name="l00148"></a>00148     <span class="comment">// move past header</span>
<a name="l00149"></a>00149     p-&gt;<a class="code" href="classprophet_1_1ProphetTLV.html#47f93a2a8a1b1fe7615ce69c438cdcdf" title="Serialized length of this TLV.">length_</a>  = <a class="code" href="classprophet_1_1ProphetTLV.html#3a8d9c3d3763364ffe7ab755fabf522f">ProphetHeaderSize</a>;
<a name="l00150"></a>00150     len        -= <a class="code" href="classprophet_1_1ProphetTLV.html#3a8d9c3d3763364ffe7ab755fabf522f">ProphetHeaderSize</a>;
<a name="l00151"></a>00151     bp         += <a class="code" href="classprophet_1_1ProphetTLV.html#3a8d9c3d3763364ffe7ab755fabf522f">ProphetHeaderSize</a>;
<a name="l00152"></a>00152 
<a name="l00153"></a>00153     <span class="comment">// begin reading TLVs in from buffer</span>
<a name="l00154"></a>00154     <a class="code" href="classprophet_1_1BaseTLV.html#37c3690d6040c870b40fa0436b67b09d" title="Byte codes for TLV types.">BaseTLV::prophet_tlv_t</a> typecode = <a class="code" href="classprophet_1_1BaseTLV.html#37c3690d6040c870b40fa0436b67b09d7058a0458dcadab12100c4813118e7db">BaseTLV::UNKNOWN_TLV</a>;
<a name="l00155"></a>00155     <a class="code" href="classprophet_1_1BaseTLV.html" title="The Prophet I-D (March 2006) dictates five bytecodes for router state exchange messages...">BaseTLV</a>* tlv = NULL;
<a name="l00156"></a>00156     <span class="keywordflow">while</span> (len &gt; 0)
<a name="l00157"></a>00157     {
<a name="l00158"></a>00158         typecode = (<a class="code" href="classprophet_1_1BaseTLV.html#37c3690d6040c870b40fa0436b67b09d" title="Byte codes for TLV types.">BaseTLV::prophet_tlv_t</a>)*bp;
<a name="l00159"></a>00159         <span class="keywordflow">switch</span> (typecode)
<a name="l00160"></a>00160         {
<a name="l00161"></a>00161             <span class="keywordflow">case</span> <a class="code" href="classprophet_1_1BaseTLV.html#37c3690d6040c870b40fa0436b67b09d4dcc990715f37355c47fb7f197fb5a3c">BaseTLV::HELLO_TLV</a>:
<a name="l00162"></a>00162                 tlv = <a class="code" href="classprophet_1_1ProphetTLV.html#dd264b57f9575d3af5a5c7e1e3414bcf" title="Read ProphetTLV in from no more than len bytes of buffer; return bytes read.">TLVFactory&lt;HelloTLV&gt;::deserialize</a>(bp,len);
<a name="l00163"></a>00163                 <span class="keywordflow">break</span>;
<a name="l00164"></a>00164             <span class="keywordflow">case</span> <a class="code" href="classprophet_1_1BaseTLV.html#37c3690d6040c870b40fa0436b67b09de5615891dad0b40891a124fcff00f562">BaseTLV::RIBD_TLV</a>:
<a name="l00165"></a>00165                 tlv = <a class="code" href="classprophet_1_1ProphetTLV.html#dd264b57f9575d3af5a5c7e1e3414bcf" title="Read ProphetTLV in from no more than len bytes of buffer; return bytes read.">TLVFactory&lt;RIBDTLV&gt;::deserialize</a>(bp,len);
<a name="l00166"></a>00166                 <span class="keywordflow">break</span>;
<a name="l00167"></a>00167             <span class="keywordflow">case</span> <a class="code" href="classprophet_1_1BaseTLV.html#37c3690d6040c870b40fa0436b67b09d1a1e57bb574af687605a82fe9f8b7f3e">BaseTLV::RIB_TLV</a>:
<a name="l00168"></a>00168                 tlv = <a class="code" href="classprophet_1_1ProphetTLV.html#dd264b57f9575d3af5a5c7e1e3414bcf" title="Read ProphetTLV in from no more than len bytes of buffer; return bytes read.">TLVFactory&lt;RIBTLV&gt;::deserialize</a>(bp,len);
<a name="l00169"></a>00169                 <span class="keywordflow">break</span>;
<a name="l00170"></a>00170             <span class="keywordflow">case</span> <a class="code" href="classprophet_1_1BaseTLV.html#37c3690d6040c870b40fa0436b67b09d4678012b183261a4608ea83babc8c315">BaseTLV::OFFER_TLV</a>:
<a name="l00171"></a>00171                 tlv = <a class="code" href="classprophet_1_1ProphetTLV.html#dd264b57f9575d3af5a5c7e1e3414bcf" title="Read ProphetTLV in from no more than len bytes of buffer; return bytes read.">TLVFactory&lt;OfferTLV&gt;::deserialize</a>(bp,len);
<a name="l00172"></a>00172                 <span class="keywordflow">break</span>;
<a name="l00173"></a>00173             <span class="keywordflow">case</span> <a class="code" href="classprophet_1_1BaseTLV.html#37c3690d6040c870b40fa0436b67b09d41b6935bfc9badb7cc041dada67836e5">BaseTLV::RESPONSE_TLV</a>:
<a name="l00174"></a>00174                 tlv = <a class="code" href="classprophet_1_1ProphetTLV.html#dd264b57f9575d3af5a5c7e1e3414bcf" title="Read ProphetTLV in from no more than len bytes of buffer; return bytes read.">TLVFactory&lt;ResponseTLV&gt;::deserialize</a>(bp,len);
<a name="l00175"></a>00175                 <span class="keywordflow">break</span>;
<a name="l00176"></a>00176             <span class="keywordflow">default</span>:
<a name="l00177"></a>00177                 tlv = NULL;
<a name="l00178"></a>00178                 <span class="keywordflow">break</span>;
<a name="l00179"></a>00179         }
<a name="l00180"></a>00180         <span class="keywordflow">if</span> (tlv == NULL) <span class="keywordflow">break</span>;
<a name="l00181"></a>00181         <span class="comment">// increments length_ by tlv-&gt;length()</span>
<a name="l00182"></a>00182         p-&gt;<a class="code" href="classprophet_1_1ProphetTLV.html#b77f5471a0a55f685d1bfbfd8f57c78f" title="Place TLV on list for serialization into next outbound ProphetTLV.">add_tlv</a>(tlv);
<a name="l00183"></a>00183         <span class="comment">// move pointer past the parsed TLV</span>
<a name="l00184"></a>00184         bp  += tlv-&gt;<a class="code" href="classprophet_1_1BaseTLV.html#5d6ab71b768b416bc457090d1189b291" title="Accessors.">length</a>();
<a name="l00185"></a>00185         len -= tlv-&gt;<a class="code" href="classprophet_1_1BaseTLV.html#5d6ab71b768b416bc457090d1189b291" title="Accessors.">length</a>();
<a name="l00186"></a>00186     }
<a name="l00187"></a>00187     <span class="keywordflow">return</span> p;
<a name="l00188"></a>00188 }
<a name="l00189"></a>00189 
<a name="l00190"></a>00190 <a class="code" href="classprophet_1_1BaseTLV.html" title="The Prophet I-D (March 2006) dictates five bytecodes for router state exchange messages...">BaseTLV</a>*
<a name="l00191"></a><a class="code" href="classprophet_1_1ProphetTLV.html#65e794043a4ff3a74906b901e7b6dabf">00191</a> <a class="code" href="classprophet_1_1ProphetTLV.html#65e794043a4ff3a74906b901e7b6dabf" title="Remove next TLV from list.">ProphetTLV::get_tlv</a>()
<a name="l00192"></a>00192 {
<a name="l00193"></a>00193     <span class="keywordflow">if</span> (<a class="code" href="classprophet_1_1ProphetTLV.html#4a730ffc2e7ddd7639445d05c78f7a9d" title="Linked list of TLVs embedded in this Prophet TLV.">list_</a>.empty())
<a name="l00194"></a>00194         <span class="keywordflow">return</span> NULL;
<a name="l00195"></a>00195     <a class="code" href="classprophet_1_1BaseTLV.html" title="The Prophet I-D (March 2006) dictates five bytecodes for router state exchange messages...">BaseTLV</a>* t = <a class="code" href="classprophet_1_1ProphetTLV.html#4a730ffc2e7ddd7639445d05c78f7a9d" title="Linked list of TLVs embedded in this Prophet TLV.">list_</a>.front();
<a name="l00196"></a>00196     <a class="code" href="classprophet_1_1ProphetTLV.html#4a730ffc2e7ddd7639445d05c78f7a9d" title="Linked list of TLVs embedded in this Prophet TLV.">list_</a>.pop_front();
<a name="l00197"></a>00197     <span class="keywordflow">return</span> t;
<a name="l00198"></a>00198 }
<a name="l00199"></a>00199 
<a name="l00200"></a>00200 <span class="keywordtype">bool</span>
<a name="l00201"></a><a class="code" href="classprophet_1_1ProphetTLV.html#b77f5471a0a55f685d1bfbfd8f57c78f">00201</a> <a class="code" href="classprophet_1_1ProphetTLV.html#b77f5471a0a55f685d1bfbfd8f57c78f" title="Place TLV on list for serialization into next outbound ProphetTLV.">ProphetTLV::add_tlv</a>(<a class="code" href="classprophet_1_1BaseTLV.html" title="The Prophet I-D (March 2006) dictates five bytecodes for router state exchange messages...">BaseTLV</a>* tlv)
<a name="l00202"></a>00202 {
<a name="l00203"></a>00203     <span class="comment">// weed out the oddball</span>
<a name="l00204"></a>00204     <span class="keywordflow">if</span> (tlv == NULL) <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00205"></a>00205 
<a name="l00206"></a>00206     <a class="code" href="classprophet_1_1ProphetTLV.html#47f93a2a8a1b1fe7615ce69c438cdcdf" title="Serialized length of this TLV.">length_</a> += tlv-&gt;<a class="code" href="classprophet_1_1BaseTLV.html#5d6ab71b768b416bc457090d1189b291" title="Accessors.">length</a>();
<a name="l00207"></a>00207     <a class="code" href="classprophet_1_1ProphetTLV.html#4a730ffc2e7ddd7639445d05c78f7a9d" title="Linked list of TLVs embedded in this Prophet TLV.">list_</a>.push_back(tlv);
<a name="l00208"></a>00208     <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00209"></a>00209 }
<a name="l00210"></a>00210 
<a name="l00211"></a>00211 }; <span class="comment">// namespace prophet</span>
</pre></div></div>
<hr size="1"><address style="text-align: right;"><small>Generated on Fri Jan 30 09:26:57 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>