Sophie

Sophie

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

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: RIBTLV.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>RIBTLV.cc</h1><a href="RIBTLV_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 <span class="preprocessor">#include &lt;string.h&gt;</span> <span class="comment">// for memset</span>
<a name="l00019"></a>00019 <span class="preprocessor">#include "<a class="code" href="Util_8h.html">Util.h</a>"</span>
<a name="l00020"></a>00020 <span class="preprocessor">#include "<a class="code" href="RIBTLV_8h.html">RIBTLV.h</a>"</span>
<a name="l00021"></a>00021 
<a name="l00022"></a>00022 <span class="keyword">namespace </span>prophet
<a name="l00023"></a>00023 {
<a name="l00024"></a>00024 
<a name="l00025"></a><a class="code" href="classprophet_1_1RIBTLV.html#dce5afcecb193e604f78d01711740b45">00025</a> <a class="code" href="classprophet_1_1RIBTLV.html#8bbe4d6a0baf33591fee36cf282191a7" title="Constructor.">RIBTLV::RIBTLV</a>(<span class="keyword">const</span> <a class="code" href="classprophet_1_1PointerList.html">RIBNodeList</a>&amp; nodes,
<a name="l00026"></a>00026                <span class="keywordtype">bool</span> relay, <span class="keywordtype">bool</span> <a class="code" href="dtncat_8c.html#160881851a33309c0106503ac4d14d96">custody</a>,
<a name="l00027"></a>00027                <span class="keywordtype">bool</span> internet)
<a name="l00028"></a>00028     : <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 class="code" href="classprophet_1_1BaseTLV.html" title="The Prophet I-D (March 2006) dictates five bytecodes for router state exchange messages...">BaseTLV</a>::RIB_TLV), nodes_(nodes),
<a name="l00029"></a>00029       relay_(relay), custody_(custody), internet_(internet)
<a name="l00030"></a>00030 {
<a name="l00031"></a>00031     <a class="code" href="classprophet_1_1BaseTLV.html#4c0a7b24b795bafb52c16b24a6188823" title="serialized length of TLV, mutable so it can be assigned by serialize() const">length_</a>  = <a class="code" href="classprophet_1_1RIBTLV.html#c8cc286d0b6f4322a5c1e4beff758d72">RIBTLVHeaderSize</a>;
<a name="l00032"></a>00032     <a class="code" href="classprophet_1_1BaseTLV.html#4c0a7b24b795bafb52c16b24a6188823" title="serialized length of TLV, mutable so it can be assigned by serialize() const">length_</a> += <a class="code" href="classprophet_1_1RIBTLV.html#c7119b733e1ac4b3cf22a1ce5a7f0062">RIBEntrySize</a> * <a class="code" href="classprophet_1_1RIBTLV.html#7f42b25b00f4418988b449e5b7ad0609" title="List of RIB entries.">nodes_</a>.size();
<a name="l00033"></a>00033 }
<a name="l00034"></a>00034 
<a name="l00035"></a><a class="code" href="classprophet_1_1RIBTLV.html#8bbe4d6a0baf33591fee36cf282191a7">00035</a> <a class="code" href="classprophet_1_1RIBTLV.html#8bbe4d6a0baf33591fee36cf282191a7" title="Constructor.">RIBTLV::RIBTLV</a>()
<a name="l00036"></a>00036     : <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 class="code" href="classprophet_1_1BaseTLV.html" title="The Prophet I-D (March 2006) dictates five bytecodes for router state exchange messages...">BaseTLV</a>::RIB_TLV), nodes_(),
<a name="l00037"></a>00037       relay_(false), custody_(false), internet_(false) {}
<a name="l00038"></a>00038 
<a name="l00039"></a>00039 <span class="keywordtype">size_t</span>
<a name="l00040"></a><a class="code" href="classprophet_1_1RIBTLV.html#ce56f1f66c8a973d7a59b0c2bfa4812c">00040</a> <a class="code" href="classprophet_1_1RIBTLV.html#ce56f1f66c8a973d7a59b0c2bfa4812c" title="Virtual from BaseTLV.">RIBTLV::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="l00041"></a>00041 <span class="keyword"></span>{
<a name="l00042"></a>00042     <span class="comment">// weed out the oddball</span>
<a name="l00043"></a>00043     <span class="keywordflow">if</span> (bp == NULL || <a class="code" href="classprophet_1_1BaseTLV.html#88263c57b5c2760ece631ce8943c6249" title="typecode for this TLV">typecode_</a> != <a class="code" href="classprophet_1_1BaseTLV.html#37c3690d6040c870b40fa0436b67b09d1a1e57bb574af687605a82fe9f8b7f3e">BaseTLV::RIB_TLV</a>) <span class="keywordflow">return</span> 0;
<a name="l00044"></a>00044 
<a name="l00045"></a>00045     <span class="comment">// check for adequate buffer length</span>
<a name="l00046"></a>00046     <span class="keywordflow">if</span> (<a class="code" href="classprophet_1_1RIBTLV.html#c8cc286d0b6f4322a5c1e4beff758d72">RIBTLVHeaderSize</a> + <a class="code" href="classprophet_1_1RIBTLV.html#c7119b733e1ac4b3cf22a1ce5a7f0062">RIBEntrySize</a> * <a class="code" href="classprophet_1_1RIBTLV.html#7f42b25b00f4418988b449e5b7ad0609" title="List of RIB entries.">nodes_</a>.size() &gt; len) <span class="keywordflow">return</span> 0;
<a name="l00047"></a>00047 
<a name="l00048"></a>00048     <span class="comment">// initialize accounting</span>
<a name="l00049"></a>00049     <a class="code" href="classprophet_1_1BaseTLV.html#4c0a7b24b795bafb52c16b24a6188823" title="serialized length of TLV, mutable so it can be assigned by serialize() const">length_</a> = 0;
<a name="l00050"></a>00050     <span class="keywordtype">size_t</span> rib_entry_count = 0;
<a name="l00051"></a>00051     <a class="code" href="structprophet_1_1RIBTLV_1_1RIBTLVHeader.html" title="Routing Information Base TLV   p.">RIBTLVHeader</a>* hdr = (<a class="code" href="structprophet_1_1RIBTLV_1_1RIBTLVHeader.html" title="Routing Information Base TLV   p.">RIBTLVHeader</a>*) bp;
<a name="l00052"></a>00052 
<a name="l00053"></a>00053     <span class="comment">// start writing RIB entries out to buffer, skipping header for now</span>
<a name="l00054"></a>00054     bp      += <a class="code" href="classprophet_1_1RIBTLV.html#c8cc286d0b6f4322a5c1e4beff758d72">RIBTLVHeaderSize</a>;
<a name="l00055"></a>00055     <a class="code" href="classprophet_1_1BaseTLV.html#4c0a7b24b795bafb52c16b24a6188823" title="serialized length of TLV, mutable so it can be assigned by serialize() const">length_</a> += <a class="code" href="classprophet_1_1RIBTLV.html#c8cc286d0b6f4322a5c1e4beff758d72">RIBTLVHeaderSize</a>;
<a name="l00056"></a>00056     <a class="code" href="classprophet_1_1RIBNode.html" title="RIBNode provides a convenience wrapper around Node for tracking endpoint ID to string...">RIBNode</a>* node = NULL;
<a name="l00057"></a>00057     <span class="keywordflow">for</span> (<a class="code" href="classprophet_1_1RIBTLV.html#5f6c403eb1a75ab229ebb8214ebbacfd">const_iterator</a> i = <a class="code" href="classprophet_1_1RIBTLV.html#7f42b25b00f4418988b449e5b7ad0609" title="List of RIB entries.">nodes_</a>.begin(); i != <a class="code" href="classprophet_1_1RIBTLV.html#7f42b25b00f4418988b449e5b7ad0609" title="List of RIB entries.">nodes_</a>.end(); i++)
<a name="l00058"></a>00058     {
<a name="l00059"></a>00059         node = (*i);
<a name="l00060"></a>00060 
<a name="l00061"></a>00061         <span class="keywordtype">size_t</span> bytes_written = 0;
<a name="l00062"></a>00062         <span class="keywordflow">if</span> ((bytes_written =
<a name="l00063"></a>00063                     <a class="code" href="classprophet_1_1RIBTLV.html#89c4ff6df76ed8241a3fd7d0745f3b2d" title="Serialize routing information base entry out to no more than len bytes of buffer...">write_rib_entry</a>(node-&gt;<a class="code" href="classprophet_1_1RIBNode.html#8cfc39e5a10c38c054d51c88fea5916d" title="String identifier used by RIB TLV.">sid_</a>, node-&gt;<a class="code" href="classprophet_1_1Node.html#97b1dbf4d60d48b5ffc8d7022a3708b7" title="Accessors.">p_value</a>(),
<a name="l00064"></a>00064                                     node-&gt;<a class="code" href="classprophet_1_1Node.html#0c4ef32bed5fa9595df25d24d4090ffc" title="Accessors.">relay</a>(), node-&gt;<a class="code" href="classprophet_1_1Node.html#30c2f606e0860b283bea16d79e1d5747" title="Accessors.">custody</a>(),
<a name="l00065"></a>00065                                     node-&gt;<a class="code" href="classprophet_1_1Node.html#f960607d5799557a90155780683e5be3" title="Accessors.">internet_gw</a>(), bp, len)) == 0)
<a name="l00066"></a>00066             <span class="keywordflow">break</span>;
<a name="l00067"></a>00067         
<a name="l00068"></a>00068         bp      += bytes_written;
<a name="l00069"></a>00069         len     -= bytes_written;
<a name="l00070"></a>00070         <a class="code" href="classprophet_1_1BaseTLV.html#4c0a7b24b795bafb52c16b24a6188823" title="serialized length of TLV, mutable so it can be assigned by serialize() const">length_</a> += bytes_written;
<a name="l00071"></a>00071 
<a name="l00072"></a>00072         rib_entry_count++;
<a name="l00073"></a>00073 
<a name="l00074"></a>00074         node = NULL;
<a name="l00075"></a>00075     }
<a name="l00076"></a>00076 
<a name="l00077"></a>00077     <span class="comment">// fill out the header with how many entries successfully written</span>
<a name="l00078"></a>00078     hdr-&gt;<a class="code" href="structprophet_1_1RIBTLV_1_1RIBTLVHeader.html#db7a7beb67758dda3c48d61f040cdb79" title="defined as 0xA1">type</a>             = <a class="code" href="classprophet_1_1BaseTLV.html#88263c57b5c2760ece631ce8943c6249" title="typecode for this TLV">typecode_</a>;
<a name="l00079"></a>00079     hdr-&gt;<a class="code" href="structprophet_1_1RIBTLV_1_1RIBTLVHeader.html#ec1efe4a9c808953b0cc107b42cc40d9" title="Length of the TLV in octets, including the TLV header and any nested TLVs.">length</a>           = htons(<a class="code" href="classprophet_1_1BaseTLV.html#4c0a7b24b795bafb52c16b24a6188823" title="serialized length of TLV, mutable so it can be assigned by serialize() const">length_</a>);
<a name="l00080"></a>00080     hdr-&gt;<a class="code" href="structprophet_1_1RIBTLV_1_1RIBTLVHeader.html#48ebbee6e355aa41e417f3b585518ee7" title="Number of routing entries in the TLV.">rib_string_count</a> = htons(rib_entry_count);
<a name="l00081"></a>00081     hdr-&gt;<a class="code" href="structprophet_1_1RIBTLV_1_1RIBTLVHeader.html#6ee7de8ff9df37d5db6823e41c7ece69" title="The encoding of the Header flag field relates to the capabilities of the Source node...">flags</a>            = 0;
<a name="l00082"></a>00082 
<a name="l00083"></a>00083     <span class="keywordflow">if</span> (<a class="code" href="classprophet_1_1RIBTLV.html#c4f10f023f5ca5f98644576888cf178d" title="Whether this node accepts bundles for relay to other nodes.">relay_</a>)    hdr-&gt;<a class="code" href="structprophet_1_1RIBTLV_1_1RIBTLVHeader.html#6ee7de8ff9df37d5db6823e41c7ece69" title="The encoding of the Header flag field relates to the capabilities of the Source node...">flags</a> |= <a class="code" href="classprophet_1_1RIBTLV.html#b822f9c4c9f1bbfde21215cc137b2ce907986bd40834cfcf54f8a40aa6ce3b79">RELAY_NODE</a>;
<a name="l00084"></a>00084     <span class="keywordflow">if</span> (<a class="code" href="classprophet_1_1RIBTLV.html#66d56083be8dfcb832ad1016ed2ee95b" title="Whether this node accepts custody transfers.">custody_</a>)  hdr-&gt;<a class="code" href="structprophet_1_1RIBTLV_1_1RIBTLVHeader.html#6ee7de8ff9df37d5db6823e41c7ece69" title="The encoding of the Header flag field relates to the capabilities of the Source node...">flags</a> |= <a class="code" href="classprophet_1_1RIBTLV.html#b822f9c4c9f1bbfde21215cc137b2ce99fac89806e29c2fa236bbac89fa5483d">CUSTODY_NODE</a>;
<a name="l00085"></a>00085     <span class="keywordflow">if</span> (<a class="code" href="classprophet_1_1RIBTLV.html#a77ff503c9891ef67c02cb09fabd4aed" title="Whether this node bridges to the Internet.">internet_</a>) hdr-&gt;<a class="code" href="structprophet_1_1RIBTLV_1_1RIBTLVHeader.html#6ee7de8ff9df37d5db6823e41c7ece69" title="The encoding of the Header flag field relates to the capabilities of the Source node...">flags</a> |= <a class="code" href="classprophet_1_1RIBTLV.html#b822f9c4c9f1bbfde21215cc137b2ce95f74aeab69c1736cea20e0fc9e18b48e">INTERNET_GW_NODE</a>;
<a name="l00086"></a>00086 
<a name="l00087"></a>00087     <span class="keywordflow">return</span> <a class="code" href="classprophet_1_1BaseTLV.html#4c0a7b24b795bafb52c16b24a6188823" title="serialized length of TLV, mutable so it can be assigned by serialize() const">length_</a>;
<a name="l00088"></a>00088 }
<a name="l00089"></a>00089 
<a name="l00090"></a>00090 <span class="keywordtype">void</span>
<a name="l00091"></a><a class="code" href="classprophet_1_1RIBTLV.html#be1b38891666e6c09f5cf4df07287e88">00091</a> <a class="code" href="classprophet_1_1RIBTLV.html#be1b38891666e6c09f5cf4df07287e88" title="Utility function for decoding RIB header flags.">RIBTLV::decode_flags</a>(u_int8_t flags, <span class="keywordtype">bool</span>* relay,
<a name="l00092"></a>00092                      <span class="keywordtype">bool</span>* <a class="code" href="dtncat_8c.html#160881851a33309c0106503ac4d14d96">custody</a>, <span class="keywordtype">bool</span>* internet)
<a name="l00093"></a>00093 {
<a name="l00094"></a>00094     <span class="comment">// weed out the oddball</span>
<a name="l00095"></a>00095     <span class="keywordflow">if</span> (relay == NULL || custody == NULL || internet == NULL) <span class="keywordflow">return</span>;
<a name="l00096"></a>00096 
<a name="l00097"></a>00097     <span class="comment">//XXX/wilson CUSTODY_NODE doesn't make much sense when !RELAY_NODE but</span>
<a name="l00098"></a>00098     <span class="comment">//           how's the best way to enforce that?</span>
<a name="l00099"></a>00099     *relay    = ((flags &amp; <a class="code" href="classprophet_1_1RIBTLV.html#b822f9c4c9f1bbfde21215cc137b2ce907986bd40834cfcf54f8a40aa6ce3b79">RELAY_NODE</a>)       == <a class="code" href="classprophet_1_1RIBTLV.html#b822f9c4c9f1bbfde21215cc137b2ce907986bd40834cfcf54f8a40aa6ce3b79">RELAY_NODE</a>);
<a name="l00100"></a>00100     *custody  = ((flags &amp; <a class="code" href="classprophet_1_1RIBTLV.html#b822f9c4c9f1bbfde21215cc137b2ce99fac89806e29c2fa236bbac89fa5483d">CUSTODY_NODE</a>)     == <a class="code" href="classprophet_1_1RIBTLV.html#b822f9c4c9f1bbfde21215cc137b2ce99fac89806e29c2fa236bbac89fa5483d">CUSTODY_NODE</a>);
<a name="l00101"></a>00101     *internet = ((flags &amp; <a class="code" href="classprophet_1_1RIBTLV.html#b822f9c4c9f1bbfde21215cc137b2ce95f74aeab69c1736cea20e0fc9e18b48e">INTERNET_GW_NODE</a>) == <a class="code" href="classprophet_1_1RIBTLV.html#b822f9c4c9f1bbfde21215cc137b2ce95f74aeab69c1736cea20e0fc9e18b48e">INTERNET_GW_NODE</a>);
<a name="l00102"></a>00102 }
<a name="l00103"></a>00103 
<a name="l00104"></a>00104 <span class="keywordtype">size_t</span>
<a name="l00105"></a><a class="code" href="classprophet_1_1RIBTLV.html#89c4ff6df76ed8241a3fd7d0745f3b2d">00105</a> <a class="code" href="classprophet_1_1RIBTLV.html#89c4ff6df76ed8241a3fd7d0745f3b2d" title="Serialize routing information base entry out to no more than len bytes of buffer...">RIBTLV::write_rib_entry</a>(u_int16_t sid, <span class="keywordtype">double</span> pvalue, <span class="keywordtype">bool</span> relay,
<a name="l00106"></a>00106                         <span class="keywordtype">bool</span> <a class="code" href="dtncat_8c.html#160881851a33309c0106503ac4d14d96">custody</a>, <span class="keywordtype">bool</span> internet, u_char* bp,
<a name="l00107"></a>00107                         <span class="keywordtype">size_t</span> <a class="code" href="num2sdnv_8c.html#fed088663f8704004425cdae2120b9b3">len</a>)<span class="keyword"> const</span>
<a name="l00108"></a>00108 <span class="keyword"></span>{
<a name="l00109"></a>00109     <span class="comment">// weed out the oddball</span>
<a name="l00110"></a>00110     <span class="keywordflow">if</span> (bp == NULL) <span class="keywordflow">return</span> 0;
<a name="l00111"></a>00111 
<a name="l00112"></a>00112     <span class="comment">// check the length of incoming buffer</span>
<a name="l00113"></a>00113     <span class="keywordflow">if</span> (<a class="code" href="classprophet_1_1RIBTLV.html#c7119b733e1ac4b3cf22a1ce5a7f0062">RIBEntrySize</a> &gt; len) <span class="keywordflow">return</span> 0;
<a name="l00114"></a>00114 
<a name="l00115"></a>00115     <span class="comment">// cast buffer pointer to RIB, zero, and start writing</span>
<a name="l00116"></a>00116     <a class="code" href="structprophet_1_1RIBTLV_1_1RIBEntry.html" title="Routing Information Base entry p.">RIBEntry</a>* rib = (<a class="code" href="structprophet_1_1RIBTLV_1_1RIBEntry.html" title="Routing Information Base entry p.">RIBEntry</a>*) bp;
<a name="l00117"></a>00117     memset(rib,0,<a class="code" href="classprophet_1_1RIBTLV.html#c7119b733e1ac4b3cf22a1ce5a7f0062">RIBEntrySize</a>);
<a name="l00118"></a>00118     rib-&gt;<a class="code" href="structprophet_1_1RIBTLV_1_1RIBEntry.html#1ce76a60ed33e980a54bd7571e2ca97e" title="ID string as predefined in the dictionary TLV.">string_id</a> = htons(sid);
<a name="l00119"></a>00119     <span class="comment">// scale double to 8 bits</span>
<a name="l00120"></a>00120     rib-&gt;<a class="code" href="structprophet_1_1RIBTLV_1_1RIBEntry.html#2039f77099dbe998c1289694eeb5136b" title="Delivery predictability for the destination of this entry as calculated according...">pvalue</a> = (u_int8_t) ( (<span class="keywordtype">int</span>) (pvalue * (255.0)) ) &amp; 0xff;
<a name="l00121"></a>00121     rib-&gt;<a class="code" href="structprophet_1_1RIBTLV_1_1RIBEntry.html#ceff2d13cb03114648c39cbbcf2d23bf" title="The encoding of the RIB flag field is    Flag 0: Relay Node 0b1   Flag 1: Custody...">flags</a>  = 0;
<a name="l00122"></a>00122     <span class="keywordflow">if</span> (relay)    rib-&gt;<a class="code" href="structprophet_1_1RIBTLV_1_1RIBEntry.html#ceff2d13cb03114648c39cbbcf2d23bf" title="The encoding of the RIB flag field is    Flag 0: Relay Node 0b1   Flag 1: Custody...">flags</a> |= <a class="code" href="classprophet_1_1RIBTLV.html#b822f9c4c9f1bbfde21215cc137b2ce907986bd40834cfcf54f8a40aa6ce3b79">RELAY_NODE</a>;
<a name="l00123"></a>00123     <span class="keywordflow">if</span> (custody)  rib-&gt;<a class="code" href="structprophet_1_1RIBTLV_1_1RIBEntry.html#ceff2d13cb03114648c39cbbcf2d23bf" title="The encoding of the RIB flag field is    Flag 0: Relay Node 0b1   Flag 1: Custody...">flags</a> |= <a class="code" href="classprophet_1_1RIBTLV.html#b822f9c4c9f1bbfde21215cc137b2ce99fac89806e29c2fa236bbac89fa5483d">CUSTODY_NODE</a>;
<a name="l00124"></a>00124     <span class="keywordflow">if</span> (internet) rib-&gt;<a class="code" href="structprophet_1_1RIBTLV_1_1RIBEntry.html#ceff2d13cb03114648c39cbbcf2d23bf" title="The encoding of the RIB flag field is    Flag 0: Relay Node 0b1   Flag 1: Custody...">flags</a> |= <a class="code" href="classprophet_1_1RIBTLV.html#b822f9c4c9f1bbfde21215cc137b2ce95f74aeab69c1736cea20e0fc9e18b48e">INTERNET_GW_NODE</a>;
<a name="l00125"></a>00125 
<a name="l00126"></a>00126     <span class="keywordflow">return</span> <a class="code" href="classprophet_1_1RIBTLV.html#c7119b733e1ac4b3cf22a1ce5a7f0062">RIBEntrySize</a>;
<a name="l00127"></a>00127 }
<a name="l00128"></a>00128 
<a name="l00129"></a>00129 <span class="keywordtype">size_t</span>
<a name="l00130"></a><a class="code" href="classprophet_1_1RIBTLV.html#27007d75c45d2e5cb300fabe19d0de5c">00130</a> <a class="code" href="classprophet_1_1RIBTLV.html#27007d75c45d2e5cb300fabe19d0de5c" title="Deserialize RIBEntry struct from transport into memory, reading no more than len...">RIBTLV::read_rib_entry</a>(u_int16_t* sid, <span class="keywordtype">double</span>* pvalue,
<a name="l00131"></a>00131                        <span class="keywordtype">bool</span>* relay, <span class="keywordtype">bool</span>* <a class="code" href="dtncat_8c.html#160881851a33309c0106503ac4d14d96">custody</a>, <span class="keywordtype">bool</span>* internet,
<a name="l00132"></a>00132                        <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="l00133"></a>00133 {
<a name="l00134"></a>00134     <span class="comment">// weed out the oddball, check for adequate length</span>
<a name="l00135"></a>00135     <span class="keywordflow">if</span> (<a class="code" href="classprophet_1_1RIBTLV.html#c7119b733e1ac4b3cf22a1ce5a7f0062">RIBEntrySize</a> &gt; len ||
<a name="l00136"></a>00136         sid == NULL        ||
<a name="l00137"></a>00137         pvalue == NULL     ||
<a name="l00138"></a>00138         relay == NULL      ||
<a name="l00139"></a>00139         custody == NULL    ||
<a name="l00140"></a>00140         internet == NULL   ||
<a name="l00141"></a>00141         bp == NULL)           <span class="keywordflow">return</span> 0;
<a name="l00142"></a>00142 
<a name="l00143"></a>00143     <span class="comment">// start reading in from buffer</span>
<a name="l00144"></a>00144     <a class="code" href="structprophet_1_1RIBTLV_1_1RIBEntry.html" title="Routing Information Base entry p.">RIBEntry</a>* rib = (<a class="code" href="structprophet_1_1RIBTLV_1_1RIBEntry.html" title="Routing Information Base entry p.">RIBEntry</a>*) bp;
<a name="l00145"></a>00145     *sid = ntohs(rib-&gt;<a class="code" href="structprophet_1_1RIBTLV_1_1RIBEntry.html#1ce76a60ed33e980a54bd7571e2ca97e" title="ID string as predefined in the dictionary TLV.">string_id</a>);
<a name="l00146"></a>00146     <span class="comment">// scale 8 bits to double, use 0xff as denominator</span>
<a name="l00147"></a>00147     *pvalue = ((rib-&gt;<a class="code" href="structprophet_1_1RIBTLV_1_1RIBEntry.html#2039f77099dbe998c1289694eeb5136b" title="Delivery predictability for the destination of this entry as calculated according...">pvalue</a> &amp; 0xff) + 0.0) / (255.0);
<a name="l00148"></a>00148     <a class="code" href="classprophet_1_1RIBTLV.html#be1b38891666e6c09f5cf4df07287e88" title="Utility function for decoding RIB header flags.">decode_flags</a>(rib-&gt;<a class="code" href="structprophet_1_1RIBTLV_1_1RIBEntry.html#ceff2d13cb03114648c39cbbcf2d23bf" title="The encoding of the RIB flag field is    Flag 0: Relay Node 0b1   Flag 1: Custody...">flags</a>, relay, custody, internet);
<a name="l00149"></a>00149     <span class="keywordflow">return</span> <a class="code" href="classprophet_1_1RIBTLV.html#c7119b733e1ac4b3cf22a1ce5a7f0062">RIBEntrySize</a>;
<a name="l00150"></a>00150 }
<a name="l00151"></a>00151 
<a name="l00152"></a>00152 <span class="keywordtype">bool</span>
<a name="l00153"></a><a class="code" href="classprophet_1_1RIBTLV.html#2ef063b460e46038ff251775cb621a9c">00153</a> <a class="code" href="classprophet_1_1RIBTLV.html#2ef063b460e46038ff251775cb621a9c" title="Virtual from BaseTLV.">RIBTLV::deserialize</a>(<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="l00154"></a>00154 {
<a name="l00155"></a>00155     <span class="comment">// weed out the oddball</span>
<a name="l00156"></a>00156     <span class="keywordflow">if</span> (bp == NULL || <a class="code" href="classprophet_1_1BaseTLV.html#88263c57b5c2760ece631ce8943c6249" title="typecode for this TLV">typecode_</a> != <a class="code" href="classprophet_1_1BaseTLV.html#37c3690d6040c870b40fa0436b67b09d1a1e57bb574af687605a82fe9f8b7f3e">BaseTLV::RIB_TLV</a>) <span class="keywordflow">return</span> 0;
<a name="l00157"></a>00157 
<a name="l00158"></a>00158     <span class="comment">// check for adequate length</span>
<a name="l00159"></a>00159     <span class="keywordflow">if</span> (<a class="code" href="classprophet_1_1RIBTLV.html#c8cc286d0b6f4322a5c1e4beff758d72">RIBTLVHeaderSize</a> &gt; len) <span class="keywordflow">return</span> 0;
<a name="l00160"></a>00160 
<a name="l00161"></a>00161     <a class="code" href="structprophet_1_1RIBTLV_1_1RIBTLVHeader.html" title="Routing Information Base TLV   p.">RIBTLVHeader</a>* hdr = (<a class="code" href="structprophet_1_1RIBTLV_1_1RIBTLVHeader.html" title="Routing Information Base TLV   p.">RIBTLVHeader</a>*) bp;
<a name="l00162"></a>00162 
<a name="l00163"></a>00163     <span class="comment">// enforce typecode expectation</span>
<a name="l00164"></a>00164     <span class="keywordflow">if</span> (hdr-&gt;<a class="code" href="structprophet_1_1RIBTLV_1_1RIBTLVHeader.html#db7a7beb67758dda3c48d61f040cdb79" title="defined as 0xA1">type</a> != <a class="code" href="classprophet_1_1BaseTLV.html#37c3690d6040c870b40fa0436b67b09d1a1e57bb574af687605a82fe9f8b7f3e">BaseTLV::RIB_TLV</a> || <a class="code" href="classprophet_1_1BaseTLV.html#88263c57b5c2760ece631ce8943c6249" title="typecode for this TLV">typecode_</a> != <a class="code" href="classprophet_1_1BaseTLV.html#37c3690d6040c870b40fa0436b67b09d1a1e57bb574af687605a82fe9f8b7f3e">BaseTLV::RIB_TLV</a>)
<a name="l00165"></a>00165         <span class="keywordflow">return</span> 0;
<a name="l00166"></a>00166 
<a name="l00167"></a>00167     <span class="comment">// check incoming header for length</span>
<a name="l00168"></a>00168     <a class="code" href="classprophet_1_1BaseTLV.html#4c0a7b24b795bafb52c16b24a6188823" title="serialized length of TLV, mutable so it can be assigned by serialize() const">length_</a> = ntohs(hdr-&gt;<a class="code" href="structprophet_1_1RIBTLV_1_1RIBTLVHeader.html#ec1efe4a9c808953b0cc107b42cc40d9" title="Length of the TLV in octets, including the TLV header and any nested TLVs.">length</a>);
<a name="l00169"></a>00169     <span class="keywordflow">if</span> (<a class="code" href="classprophet_1_1BaseTLV.html#4c0a7b24b795bafb52c16b24a6188823" title="serialized length of TLV, mutable so it can be assigned by serialize() const">length_</a> &gt; len) <span class="keywordflow">return</span> 0;
<a name="l00170"></a>00170 
<a name="l00171"></a>00171     <span class="comment">// read information from the header</span>
<a name="l00172"></a>00172     <a class="code" href="classprophet_1_1BaseTLV.html#31f1ebbf538b5b28c42e49e1eef6a34e" title="TLV-specific flags.">flags_</a> = hdr-&gt;<a class="code" href="structprophet_1_1RIBTLV_1_1RIBTLVHeader.html#6ee7de8ff9df37d5db6823e41c7ece69" title="The encoding of the Header flag field relates to the capabilities of the Source node...">flags</a>;
<a name="l00173"></a>00173     <a class="code" href="classprophet_1_1RIBTLV.html#be1b38891666e6c09f5cf4df07287e88" title="Utility function for decoding RIB header flags.">decode_flags</a>(<a class="code" href="classprophet_1_1BaseTLV.html#31f1ebbf538b5b28c42e49e1eef6a34e" title="TLV-specific flags.">flags_</a>,&amp;<a class="code" href="classprophet_1_1RIBTLV.html#c4f10f023f5ca5f98644576888cf178d" title="Whether this node accepts bundles for relay to other nodes.">relay_</a>,&amp;<a class="code" href="classprophet_1_1RIBTLV.html#66d56083be8dfcb832ad1016ed2ee95b" title="Whether this node accepts custody transfers.">custody_</a>,&amp;<a class="code" href="classprophet_1_1RIBTLV.html#a77ff503c9891ef67c02cb09fabd4aed" title="Whether this node bridges to the Internet.">internet_</a>);
<a name="l00174"></a>00174     <span class="keywordtype">size_t</span> rib_entry_count = ntohs(hdr-&gt;<a class="code" href="structprophet_1_1RIBTLV_1_1RIBTLVHeader.html#48ebbee6e355aa41e417f3b585518ee7" title="Number of routing entries in the TLV.">rib_string_count</a>);
<a name="l00175"></a>00175 
<a name="l00176"></a>00176     <span class="comment">// skip past the header, account for how much has been read so far</span>
<a name="l00177"></a>00177     bp              += <a class="code" href="classprophet_1_1RIBTLV.html#c8cc286d0b6f4322a5c1e4beff758d72">RIBTLVHeaderSize</a>;
<a name="l00178"></a>00178     len             -= <a class="code" href="classprophet_1_1RIBTLV.html#c8cc286d0b6f4322a5c1e4beff758d72">RIBTLVHeaderSize</a>;
<a name="l00179"></a>00179     <span class="keywordtype">size_t</span> amt_read  = <a class="code" href="classprophet_1_1RIBTLV.html#c8cc286d0b6f4322a5c1e4beff758d72">RIBTLVHeaderSize</a>;
<a name="l00180"></a>00180 
<a name="l00181"></a>00181     <span class="comment">// read in each RIB entry</span>
<a name="l00182"></a>00182     <span class="keywordflow">while</span> (rib_entry_count-- &gt; 0)
<a name="l00183"></a>00183     {
<a name="l00184"></a>00184         <a class="code" href="classprophet_1_1RIBNode.html" title="RIBNode provides a convenience wrapper around Node for tracking endpoint ID to string...">RIBNode</a> remote;
<a name="l00185"></a>00185         u_int16_t sid = 0;
<a name="l00186"></a>00186         <span class="keywordtype">double</span> pvalue = 0.0;
<a name="l00187"></a>00187         <span class="keywordtype">bool</span> <a class="code" href="classprophet_1_1RIBTLV.html#fd92d49a23da8ee5a9ef1349b1f85bfa" title="Accessors.">relay</a>    = <span class="keyword">false</span>;
<a name="l00188"></a>00188         <span class="keywordtype">bool</span> <a class="code" href="classprophet_1_1RIBTLV.html#3c4a5b5a78ca2cd299952914f540f3e8" title="Accessors.">custody</a>  = <span class="keyword">false</span>;
<a name="l00189"></a>00189         <span class="keywordtype">bool</span> <a class="code" href="classprophet_1_1RIBTLV.html#25507e2237efebdcccd2f2800464cb8d" title="Accessors.">internet</a> = <span class="keyword">false</span>;
<a name="l00190"></a>00190 
<a name="l00191"></a>00191         <span class="keywordtype">size_t</span> bytes_read = 
<a name="l00192"></a>00192             <a class="code" href="classprophet_1_1RIBTLV.html#27007d75c45d2e5cb300fabe19d0de5c" title="Deserialize RIBEntry struct from transport into memory, reading no more than len...">read_rib_entry</a>(&amp;sid,&amp;pvalue,&amp;relay,&amp;custody,&amp;internet,bp,len);
<a name="l00193"></a>00193 
<a name="l00194"></a>00194         <span class="keywordflow">if</span> (bytes_read != <a class="code" href="classprophet_1_1RIBTLV.html#c7119b733e1ac4b3cf22a1ce5a7f0062">RIBEntrySize</a>) <span class="keywordflow">break</span>;
<a name="l00195"></a>00195 
<a name="l00196"></a>00196         remote.<a class="code" href="classprophet_1_1Node.html#9782bc47ae71e19c461aeb8077d0bede" title="Mutators, protected for use by friend classes only.">set_pvalue</a>(pvalue);
<a name="l00197"></a>00197         remote.<a class="code" href="classprophet_1_1Node.html#3000d74e49497db616a5273a1a9c8b05" title="}">set_relay</a>(relay);
<a name="l00198"></a>00198         remote.<a class="code" href="classprophet_1_1Node.html#8fe7de524be35146a9453473138b9c0f" title="}">set_custody</a>(custody);
<a name="l00199"></a>00199         remote.<a class="code" href="classprophet_1_1Node.html#aded851dec9a724734930e46589113a2" title="}">set_internet_gw</a>(internet);
<a name="l00200"></a>00200         remote.<a class="code" href="classprophet_1_1RIBNode.html#8cfc39e5a10c38c054d51c88fea5916d" title="String identifier used by RIB TLV.">sid_</a> = sid;
<a name="l00201"></a>00201 
<a name="l00202"></a>00202         <span class="comment">// store this RIB entry</span>
<a name="l00203"></a>00203         <a class="code" href="classprophet_1_1RIBTLV.html#7f42b25b00f4418988b449e5b7ad0609" title="List of RIB entries.">nodes_</a>.push_back(<span class="keyword">new</span> <a class="code" href="classprophet_1_1RIBNode.html" title="RIBNode provides a convenience wrapper around Node for tracking endpoint ID to string...">RIBNode</a>(remote));
<a name="l00204"></a>00204 
<a name="l00205"></a>00205         <span class="comment">// account for bytes read</span>
<a name="l00206"></a>00206         bp       += bytes_read;
<a name="l00207"></a>00207         len      -= bytes_read;
<a name="l00208"></a>00208         amt_read += bytes_read;
<a name="l00209"></a>00209     }
<a name="l00210"></a>00210 
<a name="l00211"></a>00211     <span class="keywordflow">return</span> (amt_read == <a class="code" href="classprophet_1_1BaseTLV.html#4c0a7b24b795bafb52c16b24a6188823" title="serialized length of TLV, mutable so it can be assigned by serialize() const">length_</a>);
<a name="l00212"></a>00212 }
<a name="l00213"></a>00213 
<a name="l00214"></a>00214 }; <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>