<!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: CLConnection.cc Source File</title> <link href="doxygen.css" rel="stylesheet" type="text/css"> <link href="tabs.css" rel="stylesheet" type="text/css"> </head><body> <!-- Generated by Doxygen 1.5.6 --> <div class="navigation" id="top"> <div class="tabs"> <ul> <li><a href="main.html"><span>Main 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> <h1>CLConnection.cc</h1><a href="CLConnection_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 2006 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 <<a class="code" href="dtn-config_8h.html">dtn-config.h</a>></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 <oasys/util/OptParser.h></span> <a name="l00022"></a>00022 <span class="preprocessor">#include <oasys/util/Time.h></span> <a name="l00023"></a>00023 <a name="l00024"></a>00024 <span class="preprocessor">#include "<a class="code" href="CLConnection_8h.html">CLConnection.h</a>"</span> <a name="l00025"></a>00025 <span class="preprocessor">#include "<a class="code" href="BundleDaemon_8h.html">bundling/BundleDaemon.h</a>"</span> <a name="l00026"></a>00026 <span class="preprocessor">#include "<a class="code" href="BundlePayload_8h.html">bundling/BundlePayload.h</a>"</span> <a name="l00027"></a>00027 <span class="preprocessor">#include "<a class="code" href="ContactManager_8h.html">contacts/ContactManager.h</a>"</span> <a name="l00028"></a>00028 <a name="l00029"></a>00029 <span class="keyword">namespace </span>dtn { <a name="l00030"></a>00030 <a name="l00031"></a>00031 <span class="comment">//----------------------------------------------------------------------</span> <a name="l00032"></a><a class="code" href="classdtn_1_1CLConnection.html#ecdbc7977153da5766537d58c7b86640">00032</a> <a class="code" href="classdtn_1_1CLConnection.html#ecdbc7977153da5766537d58c7b86640" title="Constructor.">CLConnection::CLConnection</a>(<span class="keyword">const</span> <span class="keywordtype">char</span>* classname, <a name="l00033"></a>00033 <span class="keyword">const</span> <span class="keywordtype">char</span>* logpath, <a name="l00034"></a>00034 <a class="code" href="classdtn_1_1ConnectionConvergenceLayer.html" title="All convergence layers that maintain a connection (i.e.">ConnectionConvergenceLayer</a>* cl, <a name="l00035"></a>00035 <a class="code" href="classdtn_1_1ConnectionConvergenceLayer_1_1LinkParams.html" title="Tunable parameter structure stored in each Link&#39;s CLInfo slot.">LinkParams</a>* params, <a name="l00036"></a>00036 <span class="keywordtype">bool</span> active_connector) <a name="l00037"></a>00037 : Thread(classname), <a name="l00038"></a>00038 <a class="code" href="classoasys_1_1Logger.html">Logger</a>(classname, logpath), <a name="l00039"></a>00039 contact_(classname), <a name="l00040"></a>00040 contact_up_(false), <a name="l00041"></a>00041 cmdqueue_lock_(), <a name="l00042"></a>00042 cmdqueue_(logpath, &cmdqueue_lock_, false), <a name="l00043"></a>00043 cl_(cl), <a name="l00044"></a>00044 params_(params), <a name="l00045"></a>00045 active_connector_(active_connector), <a name="l00046"></a>00046 num_pollfds_(0), <a name="l00047"></a>00047 poll_timeout_(-1), <a name="l00048"></a>00048 contact_broken_(false) <a name="l00049"></a>00049 { <a name="l00050"></a>00050 <a class="code" href="classdtn_1_1CLConnection.html#95f89064268605c6183fa4c436a12071" title="Buffer for outgoing data.">sendbuf_</a>.reserve(<a class="code" href="classdtn_1_1CLConnection.html#e3408a135a49d68ab36fd8de5805b1fe" title="Pointer to Link parameters, or to defaults until Link is bound.">params_</a>-><a class="code" href="classdtn_1_1ConnectionConvergenceLayer_1_1LinkParams.html#c5ca778da8a9f0fda86d83057ccda6aa" title="Buffer size for sending data.">sendbuf_len_</a>); <a name="l00051"></a>00051 <a class="code" href="classdtn_1_1CLConnection.html#483ff0dd2871a812491c16aa8d3f9124" title="Buffer for incoming data.">recvbuf_</a>.reserve(<a class="code" href="classdtn_1_1CLConnection.html#e3408a135a49d68ab36fd8de5805b1fe" title="Pointer to Link parameters, or to defaults until Link is bound.">params_</a>-><a class="code" href="classdtn_1_1ConnectionConvergenceLayer_1_1LinkParams.html#2ad6f369e6bdf7e153ddebc606ecb4fd" title="Buffer size for receiving data.">recvbuf_len_</a>); <a name="l00052"></a>00052 } <a name="l00053"></a>00053 <a name="l00054"></a>00054 <span class="comment">//----------------------------------------------------------------------</span> <a name="l00055"></a><a class="code" href="classdtn_1_1CLConnection.html#0a721370a299527ee06f7945d218d320">00055</a> CLConnection::~CLConnection() <a name="l00056"></a>00056 { <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_1CLConnection.html#851229a5aa77ceed90311a41db937c18">00061</a> <a class="code" href="classdtn_1_1CLConnection.html#851229a5aa77ceed90311a41db937c18" title="Main run loop.">CLConnection::run</a>() <a name="l00062"></a>00062 { <a name="l00063"></a>00063 <span class="keyword">struct </span>pollfd* cmdqueue_poll; <a name="l00064"></a>00064 <a name="l00065"></a>00065 <a class="code" href="classdtn_1_1CLConnection.html#4eafc63965ee312f521b46d4a16e5621" title="Fill in the pollfds array with any file descriptors that should be waited on for...">initialize_pollfds</a>(); <a name="l00066"></a>00066 <span class="keywordflow">if</span> (<a class="code" href="classdtn_1_1CLConnection.html#a61b296b02812f04b3df0c8fb09919b8" title="Contact has been broken.">contact_broken_</a>) { <a name="l00067"></a>00067 log_debug(<span class="stringliteral">"contact_broken set during initialization"</span>); <a name="l00068"></a>00068 <span class="keywordflow">return</span>; <a name="l00069"></a>00069 } <a name="l00070"></a>00070 <a name="l00071"></a>00071 cmdqueue_poll = &<a class="code" href="classdtn_1_1CLConnection.html#9b530df82d1a6b8ca6717fd225c30b5b" title="Array of pollfds.">pollfds_</a>[<a class="code" href="classdtn_1_1CLConnection.html#9acc4a1e846c1a93ca38be02296b9ee0" title="Number of pollfds in use.">num_pollfds_</a>]; <a name="l00072"></a>00072 cmdqueue_poll->fd = <a class="code" href="classdtn_1_1CLConnection.html#1701c536c9f5cd3d276c4b91a38ed2cf" title="Daemon/CLConnection command queue.">cmdqueue_</a>.read_fd(); <a name="l00073"></a>00073 cmdqueue_poll->events = POLLIN; <a name="l00074"></a>00074 <a name="l00075"></a>00075 <span class="comment">// based on the parameter passed to the constructor, we either</span> <a name="l00076"></a>00076 <span class="comment">// initiate a connection or accept one, then move on to the main</span> <a name="l00077"></a>00077 <span class="comment">// run() loop. it is the responsibility of the underlying CL to</span> <a name="l00078"></a>00078 <span class="comment">// make sure that a contact_ structure is found / created</span> <a name="l00079"></a>00079 <span class="keywordflow">if</span> (<a class="code" href="classdtn_1_1CLConnection.html#cbb28c68b3122186db85d5978f97ad42" title="Should we connect() or accept().">active_connector_</a>) { <a name="l00080"></a>00080 <a class="code" href="classdtn_1_1CLConnection.html#1a74612d4da690a4719bfc1b3a37ded1" title="Initiate a connection to the remote side.">connect</a>(); <a name="l00081"></a>00081 } <span class="keywordflow">else</span> { <a name="l00082"></a>00082 <a class="code" href="classdtn_1_1CLConnection.html#e57d6885f1053d64c54403ec6d263f6a" title="Accept a connection from the remote side.">accept</a>(); <a name="l00083"></a>00083 } <a name="l00084"></a>00084 <a name="l00085"></a>00085 oasys::Time next_write(0,0); <a name="l00086"></a>00086 <a name="l00087"></a>00087 <span class="keywordflow">while</span> (<span class="keyword">true</span>) { <a name="l00088"></a>00088 <span class="keywordflow">if</span> (<a class="code" href="classdtn_1_1CLConnection.html#a61b296b02812f04b3df0c8fb09919b8" title="Contact has been broken.">contact_broken_</a>) { <a name="l00089"></a>00089 log_debug(<span class="stringliteral">"contact_broken set, exiting main loop"</span>); <a name="l00090"></a>00090 <span class="keywordflow">return</span>; <a name="l00091"></a>00091 } <a name="l00092"></a>00092 <a name="l00093"></a>00093 <span class="comment">// check the comand queue coming in from the bundle daemon</span> <a name="l00094"></a>00094 <span class="comment">// if any arrive, we continue to the top of the loop to check</span> <a name="l00095"></a>00095 <span class="comment">// contact_broken and then process any other commands before</span> <a name="l00096"></a>00096 <span class="comment">// checking for data to/from the remote side</span> <a name="l00097"></a>00097 <span class="keywordflow">if</span> (<a class="code" href="classdtn_1_1CLConnection.html#1701c536c9f5cd3d276c4b91a38ed2cf" title="Daemon/CLConnection command queue.">cmdqueue_</a>.size() != 0) { <a name="l00098"></a>00098 <a class="code" href="classdtn_1_1CLConnection.html#3980220ff1677d1e68a4738e690ef3a4">process_command</a>(); <a name="l00099"></a>00099 <span class="keywordflow">continue</span>; <a name="l00100"></a>00100 } <a name="l00101"></a>00101 <a name="l00102"></a>00102 oasys::Time now = oasys::Time::now(); <a name="l00103"></a>00103 <a name="l00104"></a>00104 <span class="keywordtype">int</span> timeout; <a name="l00105"></a>00105 <span class="keywordflow">if</span> (<a class="code" href="classdtn_1_1CLConnection.html#e3408a135a49d68ab36fd8de5805b1fe" title="Pointer to Link parameters, or to defaults until Link is bound.">params_</a>-><a class="code" href="classdtn_1_1ConnectionConvergenceLayer_1_1LinkParams.html#afc9760cfe60df3967cf328878f32f33" title="Msecs to sleep between write calls.">test_write_delay_</a> == 0) <a name="l00106"></a>00106 { <a name="l00107"></a>00107 <span class="comment">// send any data there is to send. if something was sent</span> <a name="l00108"></a>00108 <span class="comment">// out and there's still more to go, we'll call poll() with a</span> <a name="l00109"></a>00109 <span class="comment">// zero timeout so we can read any data there is to</span> <a name="l00110"></a>00110 <span class="comment">// consume, then return to send another chunk.</span> <a name="l00111"></a>00111 <span class="keywordtype">bool</span> more_to_send = <a class="code" href="classdtn_1_1CLConnection.html#ec0e51344116123883bafeafb0db4839" title="Start or continue transmission of bundle data or cl acks.">send_pending_data</a>(); <a name="l00112"></a>00112 timeout = more_to_send ? 0 : <a class="code" href="classdtn_1_1CLConnection.html#b9b601dae1312020426d0d57daca19da" title="Timeout to wait for poll data.">poll_timeout_</a>; <a name="l00113"></a>00113 } <a name="l00114"></a>00114 <span class="keywordflow">else</span> <a name="l00115"></a>00115 { <a name="l00116"></a>00116 <span class="comment">// to implement the test_write_delay we need to track the</span> <a name="l00117"></a>00117 <span class="comment">// time to call write again</span> <a name="l00118"></a>00118 <span class="keywordflow">if</span> (now >= next_write) { <a name="l00119"></a>00119 <span class="keywordtype">bool</span> more_to_send = <a class="code" href="classdtn_1_1CLConnection.html#ec0e51344116123883bafeafb0db4839" title="Start or continue transmission of bundle data or cl acks.">send_pending_data</a>(); <a name="l00120"></a>00120 <span class="keywordflow">if</span> (more_to_send) { <a name="l00121"></a>00121 next_write = now; <a name="l00122"></a>00122 next_write.add_milliseconds(<a class="code" href="classdtn_1_1CLConnection.html#e3408a135a49d68ab36fd8de5805b1fe" title="Pointer to Link parameters, or to defaults until Link is bound.">params_</a>-><a class="code" href="classdtn_1_1ConnectionConvergenceLayer_1_1LinkParams.html#afc9760cfe60df3967cf328878f32f33" title="Msecs to sleep between write calls.">test_write_delay_</a>); <a name="l00123"></a>00123 } <span class="keywordflow">else</span> { <a name="l00124"></a>00124 next_write.sec_ = 0; <a name="l00125"></a>00125 next_write.usec_ = 0; <a name="l00126"></a>00126 } <a name="l00127"></a>00127 } <a name="l00128"></a>00128 <a name="l00129"></a>00129 <span class="comment">// if next_write is non-zero, then there's more to send.</span> <a name="l00130"></a>00130 <span class="keywordflow">if</span> (next_write.sec_ != 0) { <a name="l00131"></a>00131 timeout = std::min((u_int32_t)<a class="code" href="classdtn_1_1CLConnection.html#b9b601dae1312020426d0d57daca19da" title="Timeout to wait for poll data.">poll_timeout_</a>, <a name="l00132"></a>00132 (next_write - now).in_milliseconds()); <a name="l00133"></a>00133 } <span class="keywordflow">else</span> { <a name="l00134"></a>00134 timeout = <a class="code" href="classdtn_1_1CLConnection.html#b9b601dae1312020426d0d57daca19da" title="Timeout to wait for poll data.">poll_timeout_</a>; <a name="l00135"></a>00135 } <a name="l00136"></a>00136 <a name="l00137"></a>00137 log_debug(<span class="stringliteral">"timeout is %u: next_write %u.%u (%u ms from now), poll_timeout %d"</span>, <a name="l00138"></a>00138 timeout, next_write.sec_, next_write.usec_, <a name="l00139"></a>00139 next_write.sec_ == 0 ? 0 : (next_write - now).in_milliseconds(), <a class="code" href="classdtn_1_1CLConnection.html#b9b601dae1312020426d0d57daca19da" title="Timeout to wait for poll data.">poll_timeout_</a>); <a name="l00140"></a>00140 <a name="l00141"></a>00141 } <a name="l00142"></a>00142 <a name="l00143"></a>00143 <span class="comment">// check again here for contact broken since we don't want to</span> <a name="l00144"></a>00144 <span class="comment">// poll if the socket's been closed</span> <a name="l00145"></a>00145 <span class="keywordflow">if</span> (<a class="code" href="classdtn_1_1CLConnection.html#a61b296b02812f04b3df0c8fb09919b8" title="Contact has been broken.">contact_broken_</a>) { <a name="l00146"></a>00146 log_debug(<span class="stringliteral">"contact_broken set, exiting main loop"</span>); <a name="l00147"></a>00147 <span class="keywordflow">return</span>; <a name="l00148"></a>00148 } <a name="l00149"></a>00149 <a name="l00150"></a>00150 <span class="comment">// now we poll() to wait for a new command (indicated by the</span> <a name="l00151"></a>00151 <span class="comment">// notifier on the command queue), data arriving from the</span> <a name="l00152"></a>00152 <span class="comment">// remote side, or write-readiness on the socket indicating</span> <a name="l00153"></a>00153 <span class="comment">// that we can send more data.</span> <a name="l00154"></a>00154 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i < <a class="code" href="classdtn_1_1CLConnection.html#9acc4a1e846c1a93ca38be02296b9ee0" title="Number of pollfds in use.">num_pollfds_</a> + 1; ++i) { <a name="l00155"></a>00155 <a class="code" href="classdtn_1_1CLConnection.html#9b530df82d1a6b8ca6717fd225c30b5b" title="Array of pollfds.">pollfds_</a>[i].revents = 0; <a name="l00156"></a>00156 } <a name="l00157"></a>00157 <a name="l00158"></a>00158 log_debug(<span class="stringliteral">"calling poll on %d fds with timeout %d"</span>, <a name="l00159"></a>00159 num_pollfds_ + 1, timeout); <a name="l00160"></a>00160 <a name="l00161"></a>00161 <span class="keywordtype">int</span> cc = oasys::IO::poll_multiple(<a class="code" href="classdtn_1_1CLConnection.html#9b530df82d1a6b8ca6717fd225c30b5b" title="Array of pollfds.">pollfds_</a>, num_pollfds_ + 1, <a name="l00162"></a>00162 timeout, NULL, logpath_); <a name="l00163"></a>00163 <a name="l00164"></a>00164 <span class="comment">// check again here for contact broken since we don't want to</span> <a name="l00165"></a>00165 <span class="comment">// act on the poll result if the contact is broken</span> <a name="l00166"></a>00166 <span class="keywordflow">if</span> (<a class="code" href="classdtn_1_1CLConnection.html#a61b296b02812f04b3df0c8fb09919b8" title="Contact has been broken.">contact_broken_</a>) { <a name="l00167"></a>00167 log_debug(<span class="stringliteral">"contact_broken set, exiting main loop"</span>); <a name="l00168"></a>00168 <span class="keywordflow">return</span>; <a name="l00169"></a>00169 } <a name="l00170"></a>00170 <a name="l00171"></a>00171 <span class="keywordflow">if</span> (cc == oasys::IOTIMEOUT) <a name="l00172"></a>00172 { <a name="l00173"></a>00173 <a class="code" href="classdtn_1_1CLConnection.html#7abfc7041499dd4cd5244a59843742a2" title="Handle network activity from the remote side.">handle_poll_timeout</a>(); <a name="l00174"></a>00174 } <a name="l00175"></a>00175 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (cc > 0) <a name="l00176"></a>00176 { <a name="l00177"></a>00177 <span class="keywordflow">if</span> (cc == 1 && cmdqueue_poll->revents != 0) { <a name="l00178"></a>00178 <span class="keywordflow">continue</span>; <span class="comment">// activity on the command queue only</span> <a name="l00179"></a>00179 } <a name="l00180"></a>00180 <a class="code" href="classdtn_1_1CLConnection.html#bd706e4a2d9c0ba04327347008a7affc" title="Handle network activity from the remote side.">handle_poll_activity</a>(); <a name="l00181"></a>00181 } <a name="l00182"></a>00182 <span class="keywordflow">else</span> <a name="l00183"></a>00183 { <a name="l00184"></a>00184 log_err(<span class="stringliteral">"unexpected return from poll_multiple: %d"</span>, cc); <a name="l00185"></a>00185 <a class="code" href="classdtn_1_1CLConnection.html#4b0859bd97cd3e0d6d4dba4ba070c8cb">break_contact</a>(<a class="code" href="classdtn_1_1ContactEvent.html#e20f7357509a2bcca3d8e6c8daf552f7f0c1475c056a0f72e11b5ba8466a27f7" title="Unexpected session interruption.">ContactEvent::BROKEN</a>); <a name="l00186"></a>00186 <span class="keywordflow">return</span>; <a name="l00187"></a>00187 } <a name="l00188"></a>00188 } <a name="l00189"></a>00189 } <a name="l00190"></a>00190 <a name="l00191"></a>00191 <span class="comment">//----------------------------------------------------------------------</span> <a name="l00192"></a>00192 <span class="keywordtype">void</span> <a name="l00193"></a><a class="code" href="classdtn_1_1CLConnection.html#3980220ff1677d1e68a4738e690ef3a4">00193</a> <a class="code" href="classdtn_1_1CLConnection.html#3980220ff1677d1e68a4738e690ef3a4">CLConnection::process_command</a>() <a name="l00194"></a>00194 { <a name="l00195"></a>00195 <a class="code" href="structdtn_1_1CLConnection_1_1CLMsg.html" title="struct used for messages going from the daemon thread to the connection thread.">CLMsg</a> msg; <a name="l00196"></a>00196 <span class="keywordtype">bool</span> ok = <a class="code" href="classdtn_1_1CLConnection.html#1701c536c9f5cd3d276c4b91a38ed2cf" title="Daemon/CLConnection command queue.">cmdqueue_</a>.try_pop(&msg); <a name="l00197"></a>00197 <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(ok); <span class="comment">// shouldn't be called if the queue is empty</span> <a name="l00198"></a>00198 <a name="l00199"></a>00199 <span class="keywordflow">switch</span>(msg.<a class="code" href="structdtn_1_1CLConnection_1_1CLMsg.html#38c046d3a8e719f70c30d50a577031d5">type_</a>) { <a name="l00200"></a>00200 <span class="keywordflow">case</span> <a class="code" href="classdtn_1_1CLConnection.html#63574e52407c97761d234ee70673d6682a3cb1958e000ece0c3b1ec62b6a6a28">CLMSG_BUNDLES_QUEUED</a>: <a name="l00201"></a>00201 log_debug(<span class="stringliteral">"processing CLMSG_BUNDLES_QUEUED"</span>); <a name="l00202"></a>00202 <a class="code" href="classdtn_1_1CLConnection.html#3130269f207546f88bac4834a477accd" title="Handle notification that bundle(s) may be queued on the link.">handle_bundles_queued</a>(); <a name="l00203"></a>00203 <span class="keywordflow">break</span>; <a name="l00204"></a>00204 <a name="l00205"></a>00205 <span class="keywordflow">case</span> <a class="code" href="classdtn_1_1CLConnection.html#63574e52407c97761d234ee70673d6687956f18d39bad128e8ec2e0b4015dd4b">CLMSG_CANCEL_BUNDLE</a>: <a name="l00206"></a>00206 log_debug(<span class="stringliteral">"processing CLMSG_CANCEL_BUNDLE"</span>); <a name="l00207"></a>00207 <a class="code" href="classdtn_1_1CLConnection.html#2aa5e13fd12c89035b952a7b4e19cb93" title="Handle a cancel bundle request.">handle_cancel_bundle</a>(msg.<a class="code" href="structdtn_1_1CLConnection_1_1CLMsg.html#2dc186bbe7dc21e9ac357078529c0038">bundle_</a>.object()); <a name="l00208"></a>00208 <span class="keywordflow">break</span>; <a name="l00209"></a>00209 <a name="l00210"></a>00210 <span class="keywordflow">case</span> <a class="code" href="classdtn_1_1CLConnection.html#63574e52407c97761d234ee70673d6682a906c20963b066daaca910e2e6b5ffe">CLMSG_BREAK_CONTACT</a>: <a name="l00211"></a>00211 log_debug(<span class="stringliteral">"processing CLMSG_BREAK_CONTACT"</span>); <a name="l00212"></a>00212 <a class="code" href="classdtn_1_1CLConnection.html#4b0859bd97cd3e0d6d4dba4ba070c8cb">break_contact</a>(<a class="code" href="classdtn_1_1ContactEvent.html#e20f7357509a2bcca3d8e6c8daf552f72e449a76cefd484940a3f3bfc07d188e" title="User action (i.e. console / config).">ContactEvent::USER</a>); <a name="l00213"></a>00213 <span class="keywordflow">break</span>; <a name="l00214"></a>00214 <span class="keywordflow">default</span>: <a name="l00215"></a>00215 PANIC(<span class="stringliteral">"invalid CLMsg typecode %d"</span>, msg.<a class="code" href="structdtn_1_1CLConnection_1_1CLMsg.html#38c046d3a8e719f70c30d50a577031d5">type_</a>); <a name="l00216"></a>00216 } <a name="l00217"></a>00217 } <a name="l00218"></a>00218 <a name="l00219"></a>00219 <span class="comment">//----------------------------------------------------------------------</span> <a name="l00220"></a>00220 <span class="keywordtype">void</span> <a name="l00221"></a><a class="code" href="classdtn_1_1CLConnection.html#1214075456352961d8a70f82f69be0bf">00221</a> <a class="code" href="classdtn_1_1CLConnection.html#1214075456352961d8a70f82f69be0bf">CLConnection::contact_up</a>() <a name="l00222"></a>00222 { <a name="l00223"></a>00223 log_debug(<span class="stringliteral">"contact_up"</span>); <a name="l00224"></a>00224 <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(<a class="code" href="classdtn_1_1CLConnection.html#29c0707d21c5347919186a8e14728ed0" title="Ref to the Contact.">contact_</a> != NULL); <a name="l00225"></a>00225 <a name="l00226"></a>00226 <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(!<a class="code" href="classdtn_1_1CLConnection.html#5712e80e8d3608ae67709fd8adf53bbe" title="Has contact_up been called.">contact_up_</a>); <a name="l00227"></a>00227 <a class="code" href="classdtn_1_1CLConnection.html#5712e80e8d3608ae67709fd8adf53bbe" title="Has contact_up been called.">contact_up_</a> = <span class="keyword">true</span>; <a name="l00228"></a>00228 <a name="l00229"></a>00229 <a class="code" href="classdtn_1_1BundleDaemon.html#370a80f7dd9fd9297e76d7f830d737a8" title="Queues the event at the tail of the queue for processing by the daemon thread.">BundleDaemon::post</a>(<span class="keyword">new</span> <a class="code" href="classdtn_1_1ContactUpEvent.html" title="Event class for contact up events.">ContactUpEvent</a>(<a class="code" href="classdtn_1_1CLConnection.html#29c0707d21c5347919186a8e14728ed0" title="Ref to the Contact.">contact_</a>)); <a name="l00230"></a>00230 } <a name="l00231"></a>00231 <a name="l00232"></a>00232 <span class="comment">//----------------------------------------------------------------------</span> <a name="l00233"></a>00233 <span class="keywordtype">void</span> <a name="l00234"></a><a class="code" href="classdtn_1_1CLConnection.html#4b0859bd97cd3e0d6d4dba4ba070c8cb">00234</a> <a class="code" href="classdtn_1_1CLConnection.html#4b0859bd97cd3e0d6d4dba4ba070c8cb">CLConnection::break_contact</a>(<a class="code" href="classdtn_1_1ContactEvent.html#e20f7357509a2bcca3d8e6c8daf552f7" title="Reason codes for contact state operations.">ContactEvent::reason_t</a> reason) <a name="l00235"></a>00235 { <a name="l00236"></a>00236 <a class="code" href="classdtn_1_1CLConnection.html#a61b296b02812f04b3df0c8fb09919b8" title="Contact has been broken.">contact_broken_</a> = <span class="keyword">true</span>; <a name="l00237"></a>00237 <a name="l00238"></a>00238 log_debug(<span class="stringliteral">"break_contact: %s"</span>, <a class="code" href="classdtn_1_1ContactEvent.html#9ce1fd3e3d0a1c675a90423eefac8a6e" title="Reason to string conversion.">ContactEvent::reason_to_str</a>(reason)); <a name="l00239"></a>00239 <a name="l00240"></a>00240 <span class="keywordflow">if</span> (reason != <a class="code" href="classdtn_1_1ContactEvent.html#e20f7357509a2bcca3d8e6c8daf552f7f0c1475c056a0f72e11b5ba8466a27f7" title="Unexpected session interruption.">ContactEvent::BROKEN</a>) { <a name="l00241"></a>00241 <a class="code" href="classdtn_1_1CLConnection.html#29174c5754484629bfb63c59ffb5ad46" title="Shut down the connection.">disconnect</a>(); <a name="l00242"></a>00242 } <a name="l00243"></a>00243 <a name="l00244"></a>00244 <span class="comment">// if the connection isn't being closed by the user, we need to</span> <a name="l00245"></a>00245 <span class="comment">// notify the daemon that either the contact ended or the link</span> <a name="l00246"></a>00246 <span class="comment">// became unavailable before a contact began.</span> <a name="l00247"></a>00247 <span class="comment">//</span> <a name="l00248"></a>00248 <span class="comment">// we need to check that there is in fact a contact, since a</span> <a name="l00249"></a>00249 <span class="comment">// connection may be accepted and then break before establishing a</span> <a name="l00250"></a>00250 <span class="comment">// contact</span> <a name="l00251"></a>00251 <span class="keywordflow">if</span> ((reason != <a class="code" href="classdtn_1_1ContactEvent.html#e20f7357509a2bcca3d8e6c8daf552f72e449a76cefd484940a3f3bfc07d188e" title="User action (i.e. console / config).">ContactEvent::USER</a>) && (<a class="code" href="classdtn_1_1CLConnection.html#29c0707d21c5347919186a8e14728ed0" title="Ref to the Contact.">contact_</a> != NULL)) { <a name="l00252"></a>00252 <a class="code" href="classdtn_1_1BundleDaemon.html#370a80f7dd9fd9297e76d7f830d737a8" title="Queues the event at the tail of the queue for processing by the daemon thread.">BundleDaemon::post</a>( <a name="l00253"></a>00253 <span class="keyword">new</span> <a class="code" href="classdtn_1_1LinkStateChangeRequest.html" title="Request class for link state change requests that are sent to the daemon thread for...">LinkStateChangeRequest</a>(<a class="code" href="classdtn_1_1CLConnection.html#29c0707d21c5347919186a8e14728ed0" title="Ref to the Contact.">contact_</a>->link(), <a name="l00254"></a>00254 <a class="code" href="classdtn_1_1Link.html#1bf2479a21276737f73204a3c46508a32e48e0c707487f143c54dd1cd5185323" title="Bogus state that&#39;s never actually used in the Link state_ variable, but is used...">Link::CLOSED</a>, <a name="l00255"></a>00255 reason)); <a name="l00256"></a>00256 } <a name="l00257"></a>00257 } <a name="l00258"></a>00258 <a name="l00259"></a>00259 <span class="comment">//----------------------------------------------------------------------</span> <a name="l00260"></a>00260 <span class="keywordtype">bool</span> <a name="l00261"></a><a class="code" href="classdtn_1_1CLConnection.html#46186272ffc0c76aedd5e2035e8865b7">00261</a> <a class="code" href="classdtn_1_1CLConnection.html#46186272ffc0c76aedd5e2035e8865b7">CLConnection::find_contact</a>(<span class="keyword">const</span> <a class="code" href="classdtn_1_1EndpointID.html">EndpointID</a>& peer_eid) <a name="l00262"></a>00262 { <a name="l00263"></a>00263 <span class="keywordflow">if</span> (<a class="code" href="classdtn_1_1CLConnection.html#29c0707d21c5347919186a8e14728ed0" title="Ref to the Contact.">contact_</a> != NULL) { <a name="l00264"></a>00264 log_debug(<span class="stringliteral">"CLConnection::find_contact: contact already exists"</span>); <a name="l00265"></a>00265 <span class="keywordflow">return</span> <span class="keyword">true</span>; <a name="l00266"></a>00266 } <a name="l00267"></a>00267 <a name="l00268"></a>00268 <span class="comment">/*</span> <a name="l00269"></a>00269 <span class="comment"> * Now we may need to find or create an appropriate opportunistic</span> <a name="l00270"></a>00270 <span class="comment"> * link for the connection.</span> <a name="l00271"></a>00271 <span class="comment"> *</span> <a name="l00272"></a>00272 <span class="comment"> * First, we check if there's an idle (i.e. UNAVAILABLE) link to</span> <a name="l00273"></a>00273 <span class="comment"> * the remote eid. We explicitly ignore the nexthop address, since</span> <a name="l00274"></a>00274 <span class="comment"> * that can change (due to things like TCP/UDP port number</span> <a name="l00275"></a>00275 <span class="comment"> * assignment), but we pass in the remote eid to match for a link.</span> <a name="l00276"></a>00276 <span class="comment"> *</span> <a name="l00277"></a>00277 <span class="comment"> * If we can't find one, then we create a new opportunistic link</span> <a name="l00278"></a>00278 <span class="comment"> * for the connection.</span> <a name="l00279"></a>00279 <span class="comment"> */</span> <a name="l00280"></a>00280 <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(<a class="code" href="classdtn_1_1CLConnection.html#04d6a5a9a07c68cd62756a5706ff58d1" title="Nexthop identifier set by CL.">nexthop_</a> != <span class="stringliteral">""</span>); <span class="comment">// the derived class must have set the</span> <a name="l00281"></a>00281 <span class="comment">// nexthop in the constructor</span> <a name="l00282"></a>00282 <a name="l00283"></a>00283 <a class="code" href="classdtn_1_1ContactManager.html" title="A contact manager class.">ContactManager</a>* cm = BundleDaemon::instance()->contactmgr(); <a name="l00284"></a>00284 oasys::ScopeLock l(cm-><a class="code" href="classdtn_1_1ContactManager.html#6edebce9cf6080f854039f8df593cfec" title="Accessor for the ContactManager internal lock.">lock</a>(), <span class="stringliteral">"CLConnection::find_contact"</span>); <a name="l00285"></a>00285 <a name="l00286"></a>00286 <span class="keywordtype">bool</span> new_link = <span class="keyword">false</span>; <a name="l00287"></a>00287 <a class="code" href="namespacedtn.html#6efb37e503f8062c537b022eb755b94e" title="Typedef for a reference on a link.">LinkRef</a> link = cm-><a class="code" href="classdtn_1_1ContactManager.html#d6123f2dcfbba11d95100eb3cfb714bf" title="Helper routine to find a link based on criteria:.">find_link_to</a>(<a class="code" href="classdtn_1_1CLConnection.html#99b84b09e39381998c5a918579853a30" title="Pointer to the CL.">cl_</a>, <span class="stringliteral">""</span>, peer_eid, <a name="l00288"></a>00288 <a class="code" href="classdtn_1_1Link.html#a93653796d33692c67c415afd1edf61e692792332b57aa903a769cb33e3d366b" title="The link may or may not be available, based on uncontrollable factors.">Link::OPPORTUNISTIC</a>, <a name="l00289"></a>00289 <a class="code" href="classdtn_1_1Link.html#1bf2479a21276737f73204a3c46508a36a3d11409342e7987b0ffe9c532d6e51" title="The link is closed but is able to be opened, either because it is an on demand link...">Link::AVAILABLE</a> | <a class="code" href="classdtn_1_1Link.html#1bf2479a21276737f73204a3c46508a3fcb80aea04644bdc565b13fa371b2e1e" title="The link is closed and not able to be opened currently.">Link::UNAVAILABLE</a>); <a name="l00290"></a>00290 <a name="l00291"></a>00291 <span class="keywordflow">if</span> (link == NULL || (link != NULL && link->contact() != NULL)) { <a name="l00292"></a>00292 <span class="keywordflow">if</span> (link != NULL) { <a name="l00293"></a>00293 log_warn(<span class="stringliteral">"CLConnection::find_contact: "</span> <a name="l00294"></a>00294 <span class="stringliteral">"in-use opportunistic link *%p"</span>, link.object()); <a name="l00295"></a>00295 } <a name="l00296"></a>00296 <a name="l00297"></a>00297 link = cm-><a class="code" href="classdtn_1_1ContactManager.html#a0e0738c54cc947fb03f765f3afcb03c" title="Notification from a convergence layer that a new opportunistic link has come knocking...">new_opportunistic_link</a>(<a class="code" href="classdtn_1_1CLConnection.html#99b84b09e39381998c5a918579853a30" title="Pointer to the CL.">cl_</a>, <a class="code" href="classdtn_1_1CLConnection.html#04d6a5a9a07c68cd62756a5706ff58d1" title="Nexthop identifier set by CL.">nexthop_</a>.c_str(), peer_eid); <a name="l00298"></a>00298 <span class="keywordflow">if</span> (link == NULL) { <a name="l00299"></a>00299 log_debug(<span class="stringliteral">"CLConnection::find_contact: "</span> <a name="l00300"></a>00300 <span class="stringliteral">"failed to create opportunistic link"</span>); <a name="l00301"></a>00301 <span class="keywordflow">return</span> <span class="keyword">false</span>; <a name="l00302"></a>00302 } <a name="l00303"></a>00303 <a name="l00304"></a>00304 new_link = <span class="keyword">true</span>; <a name="l00305"></a>00305 log_debug(<span class="stringliteral">"CLConnection::find_contact: "</span> <a name="l00306"></a>00306 <span class="stringliteral">"created new opportunistic link *%p"</span>, link.object()); <a name="l00307"></a>00307 } <a name="l00308"></a>00308 <a name="l00309"></a>00309 <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(link != NULL); <a name="l00310"></a>00310 oasys::ScopeLock link_lock(link->lock(), <span class="stringliteral">"CLConnection::find_contact"</span>); <a name="l00311"></a>00311 <a name="l00312"></a>00312 <span class="comment">// XXX/demmer remove check for no contact</span> <a name="l00313"></a>00313 <span class="keywordflow">if</span> (!new_link) { <a name="l00314"></a>00314 <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(link->contact() == NULL); <a name="l00315"></a>00315 link->set_nexthop(<a class="code" href="classdtn_1_1CLConnection.html#04d6a5a9a07c68cd62756a5706ff58d1" title="Nexthop identifier set by CL.">nexthop_</a>); <a name="l00316"></a>00316 log_debug(<span class="stringliteral">"CLConnection::find_contact: "</span> <a name="l00317"></a>00317 <span class="stringliteral">"found idle opportunistic link *%p"</span>, link.object()); <a name="l00318"></a>00318 } <a name="l00319"></a>00319 <a name="l00320"></a>00320 <span class="comment">// The link should not be marked for deletion because the</span> <a name="l00321"></a>00321 <span class="comment">// ContactManager is locked.</span> <a name="l00322"></a>00322 <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(!link->isdeleted()); <a name="l00323"></a>00323 <a name="l00324"></a>00324 <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(link->cl_info() != NULL); <a name="l00325"></a>00325 <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(!link->isopen()); <a name="l00326"></a>00326 <a name="l00327"></a>00327 <a class="code" href="classdtn_1_1CLConnection.html#29c0707d21c5347919186a8e14728ed0" title="Ref to the Contact.">contact_</a> = <span class="keyword">new</span> <a class="code" href="classdtn_1_1Contact.html" title="Encapsulation of an active connection to a next-hop DTN contact.">Contact</a>(link); <a name="l00328"></a>00328 contact_->set_cl_info(<span class="keyword">this</span>); <a name="l00329"></a>00329 link->set_contact(contact_.object()); <a name="l00330"></a>00330 <a name="l00331"></a>00331 <span class="comment">/*</span> <a name="l00332"></a>00332 <span class="comment"> * Now that the connection is established, we swing the</span> <a name="l00333"></a>00333 <span class="comment"> * params_ pointer to those of the link, since there's a</span> <a name="l00334"></a>00334 <span class="comment"> * chance they've been modified by the user in the past.</span> <a name="l00335"></a>00335 <span class="comment"> */</span> <a name="l00336"></a>00336 <a class="code" href="classdtn_1_1ConnectionConvergenceLayer_1_1LinkParams.html" title="Tunable parameter structure stored in each Link&#39;s CLInfo slot.">LinkParams</a>* lparams = <span class="keyword">dynamic_cast<</span><a class="code" href="classdtn_1_1ConnectionConvergenceLayer_1_1LinkParams.html" title="Tunable parameter structure stored in each Link&#39;s CLInfo slot.">LinkParams</a>*<span class="keyword">></span>(link->cl_info()); <a name="l00337"></a>00337 <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(lparams != NULL); <a name="l00338"></a>00338 <a class="code" href="classdtn_1_1CLConnection.html#e3408a135a49d68ab36fd8de5805b1fe" title="Pointer to Link parameters, or to defaults until Link is bound.">params_</a> = lparams; <a name="l00339"></a>00339 <a name="l00340"></a>00340 <span class="keywordflow">return</span> <span class="keyword">true</span>; <a name="l00341"></a>00341 } <a name="l00342"></a>00342 <a name="l00343"></a>00343 <a name="l00344"></a>00344 } <span class="comment">// namespace dtn</span> </pre></div></div> <hr size="1"><address style="text-align: right;"><small>Generated on Mon Jul 21 14:09:38 2008 for DTN Reference Implementation by <a href="http://www.doxygen.org/index.html"> <img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.6 </small></address> </body> </html>