Sophie

Sophie

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

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: RouteTable.h Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css">
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.5.8 -->
<div class="navigation" id="top">
  <div class="tabs">
    <ul>
      <li><a href="main.html"><span>Main&nbsp;Page</span></a></li>
      <li><a href="namespaces.html"><span>Namespaces</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
  <div class="tabs">
    <ul>
      <li><a href="files.html"><span>File&nbsp;List</span></a></li>
      <li><a href="globals.html"><span>File&nbsp;Members</span></a></li>
    </ul>
  </div>
<h1>RouteTable.h</h1><a href="RouteTable_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
<a name="l00002"></a>00002 <span class="comment"> *    Copyright 2004-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">#ifndef _BUNDLE_ROUTETABLE_H_</span>
<a name="l00018"></a>00018 <span class="preprocessor"></span><span class="preprocessor">#define _BUNDLE_ROUTETABLE_H_</span>
<a name="l00019"></a>00019 <span class="preprocessor"></span>
<a name="l00020"></a>00020 <span class="preprocessor">#include &lt;set&gt;</span>
<a name="l00021"></a>00021 <span class="preprocessor">#include &lt;oasys/debug/Log.h&gt;</span>
<a name="l00022"></a>00022 <span class="preprocessor">#include &lt;oasys/util/StringBuffer.h&gt;</span>
<a name="l00023"></a>00023 <span class="preprocessor">#include &lt;oasys/util/StringUtils.h&gt;</span>
<a name="l00024"></a>00024 <span class="preprocessor">#include &lt;oasys/serialize/Serialize.h&gt;</span>
<a name="l00025"></a>00025 
<a name="l00026"></a>00026 <span class="preprocessor">#include "<a class="code" href="RouteEntry_8h.html">RouteEntry.h</a>"</span>
<a name="l00027"></a>00027 
<a name="l00028"></a>00028 <span class="keyword">namespace </span>dtn {
<a name="l00029"></a>00029 
<a name="l00034"></a><a class="code" href="classdtn_1_1RouteTable.html">00034</a> <span class="keyword">class </span><a class="code" href="classdtn_1_1RouteTable.html" title="Class that implements the routing table, implemented with an stl vector.">RouteTable</a> : <span class="keyword">public</span> oasys::<a class="code" href="classoasys_1_1Logger.html">Logger</a> {
<a name="l00035"></a>00035 <span class="keyword">public</span>:
<a name="l00039"></a>00039     <a class="code" href="classdtn_1_1RouteTable.html#bfe323c89a1d44bc552c8a37fee578ac" title="Constructor.">RouteTable</a>(<span class="keyword">const</span> std::string&amp; router_name);
<a name="l00040"></a>00040 
<a name="l00044"></a>00044     <span class="keyword">virtual</span> <a class="code" href="classdtn_1_1RouteTable.html#6dae4138a767df9fb3bb94e752a1ab5d" title="Destructor.">~RouteTable</a>();
<a name="l00045"></a>00045 
<a name="l00049"></a>00049     <span class="keywordtype">bool</span> <a class="code" href="classdtn_1_1RouteTable.html#f4563da3a4e78c4784a72e790a831469" title="Add a route entry.">add_entry</a>(<a class="code" href="classdtn_1_1RouteEntry.html" title="Class to represent route table entry.">RouteEntry</a>* entry);
<a name="l00050"></a>00050     
<a name="l00054"></a>00054     <span class="keywordtype">bool</span> <a class="code" href="classdtn_1_1RouteTable.html#6116a1b3c21e46d1689e3ce010ecfe8e" title="Remove a route entry.">del_entry</a>(<span class="keyword">const</span> <a class="code" href="classdtn_1_1EndpointIDPattern.html" title="A Distinct class for endpoint patterns (i.e.">EndpointIDPattern</a>&amp; dest, <span class="keyword">const</span> <a class="code" href="namespacedtn.html#6efb37e503f8062c537b022eb755b94e" title="Typedef for a reference on a link.">LinkRef</a>&amp; next_hop);
<a name="l00055"></a>00055 
<a name="l00059"></a>00059     <span class="keyword">template</span>&lt;<span class="keyword">typename</span> Predicate&gt;
<a name="l00060"></a>00060     <span class="keywordtype">size_t</span> <a class="code" href="classdtn_1_1RouteTable.html#737932d31320acd50d7c58f61128baaa" title="Remove entries that match the given predicate.">del_matching_entries</a>(Predicate test);
<a name="l00061"></a>00061     
<a name="l00067"></a>00067     <span class="keywordtype">size_t</span> <a class="code" href="classdtn_1_1RouteTable.html#f58eb380fc5a9cd31745d353d3f8baea" title="Remove all entries to the given endpoint id pattern.">del_entries</a>(<span class="keyword">const</span> <a class="code" href="classdtn_1_1EndpointIDPattern.html" title="A Distinct class for endpoint patterns (i.e.">EndpointIDPattern</a>&amp; dest);
<a name="l00068"></a>00068 
<a name="l00074"></a>00074     <span class="keywordtype">size_t</span> <a class="code" href="classdtn_1_1RouteTable.html#db642a8b6ce784847ba7fa7e633e9cc9" title="Remove all entries that rely on the given next_hop link.">del_entries_for_nexthop</a>(<span class="keyword">const</span> <a class="code" href="namespacedtn.html#6efb37e503f8062c537b022eb755b94e" title="Typedef for a reference on a link.">LinkRef</a>&amp; next_hop);
<a name="l00075"></a>00075 
<a name="l00079"></a>00079     <span class="keywordtype">void</span> <a class="code" href="classdtn_1_1RouteTable.html#bec0465af4dbd62a1b8878e3437f7350" title="Clear the whole route table.">clear</a>();
<a name="l00080"></a>00080 
<a name="l00088"></a>00088     <span class="keywordtype">size_t</span> <a class="code" href="classdtn_1_1RouteTable.html#dceb882f843c17db3afd73521bc78c6d" title="Fill in the entry_vec with the list of all entries whose patterns match the given...">get_matching</a>(<span class="keyword">const</span> <a class="code" href="classdtn_1_1EndpointID.html">EndpointID</a>&amp; eid, <span class="keyword">const</span> <a class="code" href="namespacedtn.html#6efb37e503f8062c537b022eb755b94e" title="Typedef for a reference on a link.">LinkRef</a>&amp; next_hop,
<a name="l00089"></a>00089                         <a class="code" href="classdtn_1_1RouteEntryVec.html" title="Class for a vector of route entries.">RouteEntryVec</a>* entry_vec) <span class="keyword">const</span>;
<a name="l00090"></a>00090     
<a name="l00096"></a><a class="code" href="classdtn_1_1RouteTable.html#af2c1c26503c7b62e489ffc579b3565f">00096</a>     <span class="keywordtype">size_t</span> <a class="code" href="classdtn_1_1RouteTable.html#dceb882f843c17db3afd73521bc78c6d" title="Fill in the entry_vec with the list of all entries whose patterns match the given...">get_matching</a>(<span class="keyword">const</span> <a class="code" href="classdtn_1_1EndpointID.html">EndpointID</a>&amp; eid,
<a name="l00097"></a>00097                         <a class="code" href="classdtn_1_1RouteEntryVec.html" title="Class for a vector of route entries.">RouteEntryVec</a>* entry_vec)<span class="keyword"> const</span>
<a name="l00098"></a>00098 <span class="keyword">    </span>{
<a name="l00099"></a>00099         <a class="code" href="namespacedtn.html#6efb37e503f8062c537b022eb755b94e" title="Typedef for a reference on a link.">LinkRef</a> link(<span class="stringliteral">"RouteTable::get_matching: null"</span>);
<a name="l00100"></a>00100         <span class="keywordflow">return</span> <a class="code" href="classdtn_1_1RouteTable.html#dceb882f843c17db3afd73521bc78c6d" title="Fill in the entry_vec with the list of all entries whose patterns match the given...">get_matching</a>(eid, link, entry_vec);
<a name="l00101"></a>00101     }
<a name="l00102"></a>00102 
<a name="l00106"></a>00106     <span class="keywordtype">void</span> <a class="code" href="classdtn_1_1RouteTable.html#410e143edbfa9e818b64e005b1aa5169" title="Dump a string representation of the routing table.">dump</a>(oasys::StringBuffer* <a class="code" href="num2sdnv_8c.html#a81cdcc7ff6987bc85c073253e32715f">buf</a>) <span class="keyword">const</span>;
<a name="l00107"></a>00107 
<a name="l00111"></a><a class="code" href="classdtn_1_1RouteTable.html#0ea24556a080751daef79301ab04c906">00111</a>     <span class="keywordtype">int</span> <a class="code" href="classdtn_1_1RouteTable.html#0ea24556a080751daef79301ab04c906" title="Return the size of the table.">size</a>() { <span class="keywordflow">return</span> <a class="code" href="classdtn_1_1RouteTable.html#c6d778ec7a30cfcdf2047fde6a4de87b" title="The routing table itself.">route_table_</a>.size(); }
<a name="l00112"></a>00112 
<a name="l00117"></a>00117     <span class="keyword">const</span> <a class="code" href="classdtn_1_1RouteEntryVec.html" title="Class for a vector of route entries.">RouteEntryVec</a> *<a class="code" href="classdtn_1_1RouteTable.html#581c0578208d828885d211e0ab8381fd" title="Return the routing table.">route_table</a>();
<a name="l00118"></a>00118 
<a name="l00122"></a><a class="code" href="classdtn_1_1RouteTable.html#af649a3531d46d38066fefa3ec9fdc14">00122</a>     oasys::Lock* <a class="code" href="classdtn_1_1RouteTable.html#af649a3531d46d38066fefa3ec9fdc14" title="Accessor for the RouteTable internal lock.">lock</a>() { <span class="keywordflow">return</span> &amp;<a class="code" href="classdtn_1_1RouteTable.html#6ce91b3d9a32bd3f60910d942129c84c" title="Lock to protect internal data structures.">lock_</a>; }
<a name="l00123"></a>00123 
<a name="l00124"></a>00124 <span class="keyword">protected</span>:
<a name="l00126"></a>00126     <span class="keywordtype">size_t</span> <a class="code" href="classdtn_1_1RouteTable.html#e537332547b15d6675f877b0658cc6ec" title="Helper function for get_matching.">get_matching_helper</a>(<span class="keyword">const</span> <a class="code" href="classdtn_1_1EndpointID.html">EndpointID</a>&amp; eid,
<a name="l00127"></a>00127                                <span class="keyword">const</span> <a class="code" href="namespacedtn.html#6efb37e503f8062c537b022eb755b94e" title="Typedef for a reference on a link.">LinkRef</a>&amp;    next_hop,
<a name="l00128"></a>00128                                <a class="code" href="classdtn_1_1RouteEntryVec.html" title="Class for a vector of route entries.">RouteEntryVec</a>*    entry_vec,
<a name="l00129"></a>00129                                <span class="keywordtype">bool</span>*             loop,
<a name="l00130"></a>00130                                <span class="keywordtype">int</span>               level) <span class="keyword">const</span>;
<a name="l00131"></a>00131     
<a name="l00133"></a><a class="code" href="classdtn_1_1RouteTable.html#c6d778ec7a30cfcdf2047fde6a4de87b">00133</a>     <a class="code" href="classdtn_1_1RouteEntryVec.html" title="Class for a vector of route entries.">RouteEntryVec</a> <a class="code" href="classdtn_1_1RouteTable.html#c6d778ec7a30cfcdf2047fde6a4de87b" title="The routing table itself.">route_table_</a>;
<a name="l00134"></a>00134 
<a name="l00138"></a><a class="code" href="classdtn_1_1RouteTable.html#6ce91b3d9a32bd3f60910d942129c84c">00138</a>     <span class="keyword">mutable</span> oasys::SpinLock <a class="code" href="classdtn_1_1RouteTable.html#6ce91b3d9a32bd3f60910d942129c84c" title="Lock to protect internal data structures.">lock_</a>;
<a name="l00139"></a>00139 };
<a name="l00140"></a>00140 
<a name="l00141"></a>00141 <span class="comment">//----------------------------------------------------------------------</span>
<a name="l00142"></a>00142 <span class="keyword">template</span> &lt;<span class="keyword">typename</span> Predicate&gt;
<a name="l00143"></a>00143 <span class="keyword">inline</span> <span class="keywordtype">size_t</span>
<a name="l00144"></a><a class="code" href="classdtn_1_1RouteTable.html#737932d31320acd50d7c58f61128baaa">00144</a> <a class="code" href="classdtn_1_1RouteTable.html#737932d31320acd50d7c58f61128baaa" title="Remove entries that match the given predicate.">RouteTable::del_matching_entries</a>(Predicate pred)
<a name="l00145"></a>00145 {
<a name="l00146"></a>00146     oasys::ScopeLock l(&amp;<a class="code" href="classdtn_1_1RouteTable.html#6ce91b3d9a32bd3f60910d942129c84c" title="Lock to protect internal data structures.">lock_</a>, <span class="stringliteral">"RouteTable::del_matching_entries"</span>);
<a name="l00147"></a>00147 
<a name="l00148"></a>00148     <span class="comment">// XXX/demmer there should be a way to avoid having to go through</span>
<a name="l00149"></a>00149     <span class="comment">// twice but i can't figure it out...</span>
<a name="l00150"></a>00150     <span class="keywordtype">bool</span> found = <span class="keyword">false</span>;
<a name="l00151"></a>00151     <span class="keywordflow">for</span> (RouteEntryVec::iterator iter = <a class="code" href="classdtn_1_1RouteTable.html#c6d778ec7a30cfcdf2047fde6a4de87b" title="The routing table itself.">route_table_</a>.begin();
<a name="l00152"></a>00152          iter != <a class="code" href="classdtn_1_1RouteTable.html#c6d778ec7a30cfcdf2047fde6a4de87b" title="The routing table itself.">route_table_</a>.end(); ++iter)
<a name="l00153"></a>00153     {
<a name="l00154"></a>00154         <span class="keywordflow">if</span> (pred(*iter)) {
<a name="l00155"></a>00155             found = <span class="keyword">true</span>;
<a name="l00156"></a>00156             <span class="keyword">delete</span> *iter;
<a name="l00157"></a>00157             *iter = NULL;
<a name="l00158"></a>00158         }
<a name="l00159"></a>00159     }
<a name="l00160"></a>00160 
<a name="l00161"></a>00161     <span class="comment">// short circuit if nothing was deleted</span>
<a name="l00162"></a>00162     <span class="keywordflow">if</span> (!found) 
<a name="l00163"></a>00163         <span class="keywordflow">return</span> 0;
<a name="l00164"></a>00164 
<a name="l00165"></a>00165     <span class="keywordtype">size_t</span> old_size = <a class="code" href="classdtn_1_1RouteTable.html#c6d778ec7a30cfcdf2047fde6a4de87b" title="The routing table itself.">route_table_</a>.size();
<a name="l00166"></a>00166 
<a name="l00167"></a>00167     <span class="comment">// this stl ugliness first sorts the vector so all the null</span>
<a name="l00168"></a>00168     <span class="comment">// entries are at the end, then cleans them out with erase()</span>
<a name="l00169"></a>00169     RouteEntryVec::iterator new_end =
<a name="l00170"></a>00170         std::remove_if(<a class="code" href="classdtn_1_1RouteTable.html#c6d778ec7a30cfcdf2047fde6a4de87b" title="The routing table itself.">route_table_</a>.begin(), <a class="code" href="classdtn_1_1RouteTable.html#c6d778ec7a30cfcdf2047fde6a4de87b" title="The routing table itself.">route_table_</a>.end(),
<a name="l00171"></a>00171                        std::bind2nd(std::equal_to&lt;RouteEntry*&gt;(), 0));
<a name="l00172"></a>00172     <a class="code" href="classdtn_1_1RouteTable.html#c6d778ec7a30cfcdf2047fde6a4de87b" title="The routing table itself.">route_table_</a>.erase(new_end, <a class="code" href="classdtn_1_1RouteTable.html#c6d778ec7a30cfcdf2047fde6a4de87b" title="The routing table itself.">route_table_</a>.end());
<a name="l00173"></a>00173     
<a name="l00174"></a>00174     <span class="keywordflow">return</span> old_size - <a class="code" href="classdtn_1_1RouteTable.html#c6d778ec7a30cfcdf2047fde6a4de87b" title="The routing table itself.">route_table_</a>.size();
<a name="l00175"></a>00175 }
<a name="l00176"></a>00176 
<a name="l00177"></a>00177 } <span class="comment">// namespace dtn</span>
<a name="l00178"></a>00178 
<a name="l00179"></a>00179 <span class="preprocessor">#endif </span><span class="comment">/* _BUNDLE_ROUTETABLE_H_ */</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>