Sophie

Sophie

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

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: DTLSR.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>DTLSR.cc</h1><a href="DTLSR_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 Intel Corporation</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">#ifdef HAVE_CONFIG_H</span>
<a name="l00018"></a>00018 <span class="preprocessor"></span><span class="preprocessor">#include &lt;<a class="code" href="dtn-config_8h.html">dtn-config.h</a>&gt;</span>
<a name="l00019"></a>00019 <span class="preprocessor">#endif</span>
<a name="l00020"></a>00020 <span class="preprocessor"></span>
<a name="l00021"></a>00021 <span class="preprocessor">#include &lt;oasys/serialize/MarshalSerialize.h&gt;</span>
<a name="l00022"></a>00022 <span class="preprocessor">#include &lt;oasys/util/ScratchBuffer.h&gt;</span>
<a name="l00023"></a>00023 
<a name="l00024"></a>00024 <span class="preprocessor">#include "<a class="code" href="DTLSR_8h.html">DTLSR.h</a>"</span>
<a name="l00025"></a>00025 <span class="preprocessor">#include "<a class="code" href="bundling_2Bundle_8h.html">bundling/Bundle.h</a>"</span>
<a name="l00026"></a>00026 
<a name="l00027"></a>00027 <span class="keyword">namespace </span>dtn {
<a name="l00028"></a>00028 
<a name="l00029"></a>00029 <span class="comment">//----------------------------------------------------------------------</span>
<a name="l00030"></a>00030 <span class="keywordtype">void</span>
<a name="l00031"></a><a class="code" href="classdtn_1_1DTLSR_1_1LinkParams.html#ca6613a54de7c6dcf811a2fd689aa346">00031</a> <a class="code" href="classdtn_1_1DTLSR_1_1LinkParams.html#ca6613a54de7c6dcf811a2fd689aa346">DTLSR::LinkParams::serialize</a>(oasys::SerializeAction* a)
<a name="l00032"></a>00032 {
<a name="l00033"></a>00033     a-&gt;process(<span class="stringliteral">"state"</span>, &amp;<a class="code" href="classdtn_1_1DTLSR_1_1LinkParams.html#c0657e477eb6777479b0407d9219a057" title="LINK_UP or LINK_DOWN.">state_</a>);
<a name="l00034"></a>00034     a-&gt;process(<span class="stringliteral">"cost"</span>,  &amp;<a class="code" href="classdtn_1_1DTLSR_1_1LinkParams.html#17b3e69006f09ca7592b8cb85d0326b6" title="configured link cost">cost_</a>);
<a name="l00035"></a>00035     a-&gt;process(<span class="stringliteral">"delay"</span>, &amp;<a class="code" href="classdtn_1_1DTLSR_1_1LinkParams.html#19d5dedc6ba528e2462d492946df7887" title="estimated link delay">delay_</a>);
<a name="l00036"></a>00036     a-&gt;process(<span class="stringliteral">"bw"</span>,    &amp;<a class="code" href="classdtn_1_1DTLSR_1_1LinkParams.html#9982fc31a8aa8b9e7a155850423dbf66" title="estimated link bandwidth">bw_</a>);
<a name="l00037"></a>00037     a-&gt;process(<span class="stringliteral">"qcount"</span>,&amp;<a class="code" href="classdtn_1_1DTLSR_1_1LinkParams.html#756797e40e97b6f9db310ed7e0b43de1" title="number of bundles in queue">qcount_</a>);
<a name="l00038"></a>00038     a-&gt;process(<span class="stringliteral">"qsize"</span>, &amp;<a class="code" href="classdtn_1_1DTLSR_1_1LinkParams.html#612721595d71d68276c969a6ad798743" title="total size of bundles in queue">qsize_</a>);
<a name="l00039"></a>00039 }
<a name="l00040"></a>00040 
<a name="l00041"></a>00041 <span class="comment">//----------------------------------------------------------------------</span>
<a name="l00042"></a>00042 <span class="keywordtype">void</span>
<a name="l00043"></a><a class="code" href="classdtn_1_1DTLSR_1_1LinkState.html#bcce846f6403c17ccb4ef7d9fd7e2ef0">00043</a> <a class="code" href="classdtn_1_1DTLSR_1_1LinkState.html#bcce846f6403c17ccb4ef7d9fd7e2ef0">DTLSR::LinkState::serialize</a>(oasys::SerializeAction* a)
<a name="l00044"></a>00044 {
<a name="l00045"></a>00045     a-&gt;process(<span class="stringliteral">"dest"</span>,    &amp;<a class="code" href="classdtn_1_1DTLSR_1_1LinkState.html#7b36417a371fe42c1689567f0d149404" title="Destination node.">dest_</a>);
<a name="l00046"></a>00046     a-&gt;process(<span class="stringliteral">"id"</span>,      &amp;<a class="code" href="classdtn_1_1DTLSR_1_1LinkState.html#9bab6de7a7a5c103cc942c81b2e63d71" title="Link name.">id_</a>);
<a name="l00047"></a>00047     a-&gt;process(<span class="stringliteral">"elapsed"</span>, &amp;<a class="code" href="classdtn_1_1DTLSR_1_1LinkState.html#dac733d6fcb356d154edd8dabe2d3f1d" title="Time since last state change for this link.">elapsed_</a>);
<a name="l00048"></a>00048     a-&gt;process(<span class="stringliteral">"params"</span>,  &amp;<a class="code" href="classdtn_1_1DTLSR_1_1LinkState.html#46d69f66f7f84d855c09af8e91f49917" title="Parameters of the link.">params_</a>);
<a name="l00049"></a>00049 }
<a name="l00050"></a>00050 
<a name="l00051"></a>00051 <span class="comment">//----------------------------------------------------------------------</span>
<a name="l00052"></a>00052 <span class="keywordtype">void</span>
<a name="l00053"></a><a class="code" href="classdtn_1_1DTLSR_1_1LSA.html#fd0d47939ef14f73ed0374c82186975a">00053</a> <a class="code" href="classdtn_1_1DTLSR_1_1LSA.html#fd0d47939ef14f73ed0374c82186975a">DTLSR::LSA::serialize</a>(oasys::SerializeAction* a)
<a name="l00054"></a>00054 {
<a name="l00055"></a>00055     a-&gt;process(<span class="stringliteral">"seqno"</span>,   &amp;<a class="code" href="classdtn_1_1DTLSR_1_1LSA.html#8f22ba59fb3771fb73d89f7f13e3c80b" title="Strictly increasing sequence number for this source.">seqno_</a>);
<a name="l00056"></a>00056     a-&gt;process(<span class="stringliteral">"links"</span>,   &amp;<a class="code" href="classdtn_1_1DTLSR_1_1LSA.html#8d58017622a5224c316abc5893b2d894" title="Vector of link states.">links_</a>);
<a name="l00057"></a>00057 }
<a name="l00058"></a>00058 
<a name="l00059"></a>00059 <span class="comment">//----------------------------------------------------------------------</span>
<a name="l00060"></a>00060 <span class="keywordtype">void</span>
<a name="l00061"></a><a class="code" href="classdtn_1_1DTLSR.html#699d051e60ee419630bffd22bdd2a739">00061</a> <a class="code" href="classdtn_1_1DTLSR.html#699d051e60ee419630bffd22bdd2a739" title="Format the LSA into the given bundle&amp;#39;s payload.">DTLSR::format_lsa_bundle</a>(<a class="code" href="classdtn_1_1Bundle.html" title="The internal representation of a bundle.">Bundle</a>* bundle, <span class="keyword">const</span> <a class="code" href="classdtn_1_1DTLSR_1_1LSA.html" title="The LSA that&amp;#39;s sent over the network.">LSA</a>* lsa)
<a name="l00062"></a>00062 {
<a name="l00063"></a>00063     oasys::MarshalSize ms(oasys::Serialize::CONTEXT_NETWORK);
<a name="l00064"></a>00064     <span class="keywordflow">if</span> (ms.action(lsa) != 0) {
<a name="l00065"></a>00065         log_crit_p(<span class="stringliteral">"/dtn/route/dtlsr"</span>, <span class="stringliteral">"error sizing lsa"</span>);
<a name="l00066"></a>00066         <span class="keywordflow">return</span>;
<a name="l00067"></a>00067     }
<a name="l00068"></a>00068     <span class="keywordtype">size_t</span> <a class="code" href="num2sdnv_8c.html#fed088663f8704004425cdae2120b9b3">len</a> = ms.size();
<a name="l00069"></a>00069 
<a name="l00070"></a>00070     <span class="comment">// XXX/demmer should define a new serialization class that</span>
<a name="l00071"></a>00071     <span class="comment">// overrides the Marshal::process for strings and uses an SDNV</span>
<a name="l00072"></a>00072     <span class="comment">// length instead. Could also send the params in a packed struct</span>
<a name="l00073"></a>00073     <span class="comment">// for convenience</span>
<a name="l00074"></a>00074 
<a name="l00075"></a>00075     oasys::ScratchBuffer&lt;u_char*, 256&gt; <a class="code" href="num2sdnv_8c.html#a81cdcc7ff6987bc85c073253e32715f">buf</a>;
<a name="l00076"></a>00076     
<a name="l00077"></a>00077     oasys::Marshal m(oasys::Serialize::CONTEXT_NETWORK, &amp;buf);
<a name="l00078"></a>00078     <span class="keywordflow">if</span> (m.action(lsa) != 0) {
<a name="l00079"></a>00079         log_crit_p(<span class="stringliteral">"/dtn/route/dtlsr"</span>, <span class="stringliteral">"error marshalling lsa"</span>);
<a name="l00080"></a>00080         <span class="keywordflow">return</span>;
<a name="l00081"></a>00081     }
<a name="l00082"></a>00082 
<a name="l00083"></a>00083     bundle-&gt;<a class="code" href="classdtn_1_1Bundle.html#857079bad68497626f75c2985b69052f" title="Setters and mutable accessors.">mutable_payload</a>()-&gt;<a class="code" href="classdtn_1_1BundlePayload.html#af1ede6096a6d625fb83c001a9d490d6" title="Set the payload length in preparation for filling in with data.">set_length</a>(1 + len);
<a name="l00084"></a>00084 
<a name="l00085"></a>00085     u_char type = <a class="code" href="classdtn_1_1DTLSR.html#d0a6df53eaef2a9ef1d3576e3ac0005cbed7dff6b128f3fa540411dfa25d6ec5">MSG_LSA</a>;
<a name="l00086"></a>00086     bundle-&gt;<a class="code" href="classdtn_1_1Bundle.html#857079bad68497626f75c2985b69052f" title="Setters and mutable accessors.">mutable_payload</a>()-&gt;<a class="code" href="classdtn_1_1BundlePayload.html#7f5185039b03f0c875a12136b6b24862" title="Write a chunk of payload data at the specified offset.">write_data</a>(&amp;type,     0, 1);
<a name="l00087"></a>00087     bundle-&gt;<a class="code" href="classdtn_1_1Bundle.html#857079bad68497626f75c2985b69052f" title="Setters and mutable accessors.">mutable_payload</a>()-&gt;<a class="code" href="classdtn_1_1BundlePayload.html#7f5185039b03f0c875a12136b6b24862" title="Write a chunk of payload data at the specified offset.">write_data</a>(buf.buf(), 1, len);
<a name="l00088"></a>00088 }
<a name="l00089"></a>00089 
<a name="l00090"></a>00090 <span class="comment">//----------------------------------------------------------------------</span>
<a name="l00091"></a>00091 <span class="keywordtype">bool</span>
<a name="l00092"></a><a class="code" href="classdtn_1_1DTLSR.html#09838e294dee8194df4ee5069c91584a">00092</a> <a class="code" href="classdtn_1_1DTLSR.html#09838e294dee8194df4ee5069c91584a" title="Parse an LSA bundle.">DTLSR::parse_lsa_bundle</a>(<span class="keyword">const</span> <a class="code" href="classdtn_1_1Bundle.html" title="The internal representation of a bundle.">Bundle</a>* bundle, <a class="code" href="classdtn_1_1DTLSR_1_1LSA.html" title="The LSA that&amp;#39;s sent over the network.">LSA</a>* lsa)
<a name="l00093"></a>00093 {
<a name="l00094"></a>00094     oasys::ScratchBuffer&lt;u_char*, 256&gt; <a class="code" href="num2sdnv_8c.html#a81cdcc7ff6987bc85c073253e32715f">buf</a>;
<a name="l00095"></a>00095     <span class="keywordtype">size_t</span> <a class="code" href="num2sdnv_8c.html#fed088663f8704004425cdae2120b9b3">len</a> = bundle-&gt;<a class="code" href="classdtn_1_1Bundle.html#3bc0b88b547620b4029eba4809a73447" title="Accessors.">payload</a>().<a class="code" href="classdtn_1_1BundlePayload.html#56b3851ad789c4dbf019a32d557b7453" title="The payload length.">length</a>();
<a name="l00096"></a>00096     bundle-&gt;<a class="code" href="classdtn_1_1Bundle.html#3bc0b88b547620b4029eba4809a73447" title="Accessors.">payload</a>().<a class="code" href="classdtn_1_1BundlePayload.html#c4ce25f2d2d7ad54a9306ea2599731b4" title="Copy out a chunk of payload data into the supplied buffer.">read_data</a>(0, len, buf.buf(len));
<a name="l00097"></a>00097 
<a name="l00098"></a>00098     <span class="keywordflow">if</span> (buf.buf()[0] != <a class="code" href="classdtn_1_1DTLSR.html#d0a6df53eaef2a9ef1d3576e3ac0005cbed7dff6b128f3fa540411dfa25d6ec5">MSG_LSA</a>) {
<a name="l00099"></a>00099         log_warn_p(<span class="stringliteral">"/dtn/route/dtlsr"</span>,
<a name="l00100"></a>00100                    <span class="stringliteral">"parse_lsa_bundle: typecode byte %u != MSG_LSA"</span>,
<a name="l00101"></a>00101                    buf.buf()[0]);
<a name="l00102"></a>00102         <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00103"></a>00103     }
<a name="l00104"></a>00104     
<a name="l00105"></a>00105     oasys::Unmarshal um(oasys::Serialize::CONTEXT_NETWORK,
<a name="l00106"></a>00106                         buf.buf() + 1, len - 1);
<a name="l00107"></a>00107     <span class="keywordflow">if</span> (um.action(lsa) != 0) {
<a name="l00108"></a>00108         log_warn_p(<span class="stringliteral">"/dtn/route/dtlsr"</span>,
<a name="l00109"></a>00109                    <span class="stringliteral">"error unmarshalling lsa vector"</span>);
<a name="l00110"></a>00110         <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00111"></a>00111     }
<a name="l00112"></a>00112 
<a name="l00113"></a>00113     <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00114"></a>00114 }
<a name="l00115"></a>00115 
<a name="l00116"></a>00116 } <span class="comment">// namespace dtn</span>
</pre></div></div>
<hr size="1"><address style="text-align: right;"><small>Generated on Fri Jan 30 09:26:53 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>