Alexander Afanasyev | fd0c41c | 2012-06-11 22:15:49 -0700 | [diff] [blame] | 1 | /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /* |
| 3 | * Copyright (c) 2012 University of California, Los Angeles |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License version 2 as |
| 7 | * published by the Free Software Foundation; |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 17 | * |
| 18 | * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu> |
| 19 | */ |
| 20 | |
| 21 | #include "ns3/core-module.h" |
| 22 | #include "ns3/ndnSIM-module.h" |
Alexander Afanasyev | 674c876 | 2012-11-21 23:50:33 -0800 | [diff] [blame] | 23 | |
| 24 | #include "ndnSIM-trie.h" |
| 25 | |
Alexander Afanasyev | 1a2df6a | 2012-08-17 13:21:51 -0700 | [diff] [blame] | 26 | #include "../utils/trie/trie-with-policy.h" |
| 27 | #include "../utils/trie/lru-policy.h" |
| 28 | #include "../utils/trie/random-policy.h" |
| 29 | #include "../utils/trie/fifo-policy.h" |
| 30 | #include "../utils/trie/multi-policy.h" |
Alexander Afanasyev | fd0c41c | 2012-06-11 22:15:49 -0700 | [diff] [blame] | 31 | |
Alexander Afanasyev | 44bb6ea | 2012-07-09 08:44:41 -0700 | [diff] [blame] | 32 | #include <boost/lexical_cast.hpp> |
| 33 | |
| 34 | using namespace std; |
Alexander Afanasyev | fd0c41c | 2012-06-11 22:15:49 -0700 | [diff] [blame] | 35 | using namespace ns3; |
Alexander Afanasyev | cf6dc92 | 2012-08-10 16:55:27 -0700 | [diff] [blame] | 36 | using namespace ndn::ndnSIM; |
Alexander Afanasyev | 30cb117 | 2012-07-06 10:47:39 -0700 | [diff] [blame] | 37 | using namespace boost; |
Alexander Afanasyev | fd0c41c | 2012-06-11 22:15:49 -0700 | [diff] [blame] | 38 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 39 | NS_LOG_COMPONENT_DEFINE ("ndn.Trie"); |
Alexander Afanasyev | fd0c41c | 2012-06-11 22:15:49 -0700 | [diff] [blame] | 40 | |
Alexander Afanasyev | 36b4577 | 2012-07-10 16:57:42 -0700 | [diff] [blame] | 41 | // class Integer : public ns3::SimpleRefCount<Integer> |
| 42 | // { |
| 43 | // public: |
| 44 | // ::Integer (int value) : value_ (value) {} |
Alexander Afanasyev | 89fb535 | 2012-06-12 22:43:16 -0700 | [diff] [blame] | 45 | |
Alexander Afanasyev | 36b4577 | 2012-07-10 16:57:42 -0700 | [diff] [blame] | 46 | // operator int () const { return value_; } |
| 47 | // private: |
| 48 | // int value_; |
| 49 | // }; |
Alexander Afanasyev | fd0c41c | 2012-06-11 22:15:49 -0700 | [diff] [blame] | 50 | |
Alexander Afanasyev | 36b4577 | 2012-07-10 16:57:42 -0700 | [diff] [blame] | 51 | // std::ostream & |
| 52 | // operator << (std::ostream &os, const ::Integer &i) |
| 53 | // { |
| 54 | // os << (int)i; |
| 55 | // return os; |
| 56 | // } |
Alexander Afanasyev | 89fb535 | 2012-06-12 22:43:16 -0700 | [diff] [blame] | 57 | |
Alexander Afanasyev | 674c876 | 2012-11-21 23:50:33 -0800 | [diff] [blame] | 58 | void |
| 59 | TrieTest::DoRun () |
Alexander Afanasyev | fd0c41c | 2012-06-11 22:15:49 -0700 | [diff] [blame] | 60 | { |
Alexander Afanasyev | 674c876 | 2012-11-21 23:50:33 -0800 | [diff] [blame] | 61 | cerr << "TrieTest is temporarily broken" << endl; |
Alexander Afanasyev | 44bb6ea | 2012-07-09 08:44:41 -0700 | [diff] [blame] | 62 | // typedef trie_with_policy< |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 63 | // ns3::NdnNameComponents, |
Alexander Afanasyev | 44bb6ea | 2012-07-09 08:44:41 -0700 | [diff] [blame] | 64 | // smart_pointer_payload_traits<Integer>, |
| 65 | // multi_policy_traits< |
| 66 | // mpl::vector2<lru_policy_traits,random_policy_traits> |
| 67 | // > > trie; |
Alexander Afanasyev | 9e96e36 | 2012-07-02 23:04:39 -0700 | [diff] [blame] | 68 | |
Alexander Afanasyev | 44bb6ea | 2012-07-09 08:44:41 -0700 | [diff] [blame] | 69 | // trie x; |
| 70 | // x.getPolicy ().get<0> ().set_max_size (100); |
| 71 | // x.getPolicy ().get<1> ().set_max_size (3); |
| 72 | // // // x.getPolicy ().get<1> ().set_max_size (3); |
| 73 | // // // // x.getPolicy ().get1 ().set_max_size (10); |
| 74 | // // // // x.getPolicy ().get2 ().set_max_size (3); |
Alexander Afanasyev | 89fb535 | 2012-06-12 22:43:16 -0700 | [diff] [blame] | 75 | |
Alexander Afanasyev | 44bb6ea | 2012-07-09 08:44:41 -0700 | [diff] [blame] | 76 | // // // // x.getTrie ().PrintStat (std::cout); |
Alexander Afanasyev | 89fb535 | 2012-06-12 22:43:16 -0700 | [diff] [blame] | 77 | |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 78 | // ns3::NdnNameComponents n1,n2,n3,n4; |
Alexander Afanasyev | 44bb6ea | 2012-07-09 08:44:41 -0700 | [diff] [blame] | 79 | // // // // n1("a")("b")("c"); |
| 80 | // // // // n2("a")("b")("d"); |
| 81 | // // // // n3("a")("b")("f"); |
| 82 | // // // // n4("a")("b"); |
Alexander Afanasyev | fd0c41c | 2012-06-11 22:15:49 -0700 | [diff] [blame] | 83 | |
Alexander Afanasyev | 44bb6ea | 2012-07-09 08:44:41 -0700 | [diff] [blame] | 84 | // n1("a"); |
| 85 | // n2("b"); |
| 86 | // n3("c"); |
| 87 | // n4("d"); |
Alexander Afanasyev | 89fb535 | 2012-06-12 22:43:16 -0700 | [diff] [blame] | 88 | |
Alexander Afanasyev | 44bb6ea | 2012-07-09 08:44:41 -0700 | [diff] [blame] | 89 | // x.insert (n1, ns3::Create<Integer> (1)); |
| 90 | // x.insert (n2, ns3::Create<Integer> (2)); |
| 91 | // // // // x.longest_prefix_match (n1); |
| 92 | // x.insert (n3, ns3::Create<Integer> (3)); |
| 93 | // x.insert (n4, ns3::Create<Integer> (4)); |
| 94 | // x.insert (n4, ns3::Create<Integer> (4)); |
Alexander Afanasyev | 89fb535 | 2012-06-12 22:43:16 -0700 | [diff] [blame] | 95 | |
Alexander Afanasyev | 44bb6ea | 2012-07-09 08:44:41 -0700 | [diff] [blame] | 96 | // std::cout << "digraph trie {\n"; |
| 97 | // std::cout << x.getTrie (); |
| 98 | // std::cout << "}\n"; |
Alexander Afanasyev | 9a98970 | 2012-06-29 17:44:00 -0700 | [diff] [blame] | 99 | |
Alexander Afanasyev | 674c876 | 2012-11-21 23:50:33 -0800 | [diff] [blame] | 100 | // Ptr<Node> node = CreateObject<Node> (); |
| 101 | // Names::Add ("TestNode", node); |
| 102 | // Ptr<ndn::App> app = CreateObject<ndn::App> (); |
| 103 | // node->AddApplication (app); |
Alexander Afanasyev | 44bb6ea | 2012-07-09 08:44:41 -0700 | [diff] [blame] | 104 | |
Alexander Afanasyev | 674c876 | 2012-11-21 23:50:33 -0800 | [diff] [blame] | 105 | // ObjectFactory factory ("ns3::ndn::fib::Default"); |
Alexander Afanasyev | 44bb6ea | 2012-07-09 08:44:41 -0700 | [diff] [blame] | 106 | |
Alexander Afanasyev | 674c876 | 2012-11-21 23:50:33 -0800 | [diff] [blame] | 107 | // Ptr<ndn::Fib> fib = factory.Create<ndn::Fib> (); |
| 108 | // node->AggregateObject (fib); |
| 109 | // Ptr<ndn::Face> face = CreateObject<ndn::AppFace> (app); |
Alexander Afanasyev | 44bb6ea | 2012-07-09 08:44:41 -0700 | [diff] [blame] | 110 | |
Alexander Afanasyev | 674c876 | 2012-11-21 23:50:33 -0800 | [diff] [blame] | 111 | // fib->Add (lexical_cast<ndn::NameComponents> ("/bla"), face, 1); |
| 112 | // fib->Add (lexical_cast<ndn::NameComponents> ("/bla/1"), face, 1); |
| 113 | // fib->Add (lexical_cast<ndn::NameComponents> ("/bla/2"), face, 1); |
| 114 | // fib->Add (lexical_cast<ndn::NameComponents> ("/bla/3"), face, 1); |
| 115 | // fib->Add (lexical_cast<ndn::NameComponents> ("/bla/1/1"), face, 1); |
| 116 | // fib->Add (lexical_cast<ndn::NameComponents> ("/bla/1/2"), face, 1); |
Alexander Afanasyev | 44bb6ea | 2012-07-09 08:44:41 -0700 | [diff] [blame] | 117 | |
Alexander Afanasyev | 674c876 | 2012-11-21 23:50:33 -0800 | [diff] [blame] | 118 | // cout << *fib << endl; |
Alexander Afanasyev | 44bb6ea | 2012-07-09 08:44:41 -0700 | [diff] [blame] | 119 | |
Alexander Afanasyev | 674c876 | 2012-11-21 23:50:33 -0800 | [diff] [blame] | 120 | // fib->RemoveFromAll (face); |
Alexander Afanasyev | 44bb6ea | 2012-07-09 08:44:41 -0700 | [diff] [blame] | 121 | |
Alexander Afanasyev | 674c876 | 2012-11-21 23:50:33 -0800 | [diff] [blame] | 122 | // cout << *fib << endl; |
Alexander Afanasyev | 9a98970 | 2012-06-29 17:44:00 -0700 | [diff] [blame] | 123 | // BOOST_FOREACH (const trie::parent_trie &item, x.getPolicy ()) |
| 124 | // { |
| 125 | // std::cout << *item.payload () << " " << std::endl; |
| 126 | // } |
Alexander Afanasyev | 89fb535 | 2012-06-12 22:43:16 -0700 | [diff] [blame] | 127 | |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 128 | // ns3::NdnNameComponents n4; |
Alexander Afanasyev | 89fb535 | 2012-06-12 22:43:16 -0700 | [diff] [blame] | 129 | // n4("a")("c"); |
Alexander Afanasyev | fd0c41c | 2012-06-11 22:15:49 -0700 | [diff] [blame] | 130 | |
Alexander Afanasyev | 89fb535 | 2012-06-12 22:43:16 -0700 | [diff] [blame] | 131 | // // std::cout << *x->find (n4).get<0> (); |
Alexander Afanasyev | fd0c41c | 2012-06-11 22:15:49 -0700 | [diff] [blame] | 132 | |
Alexander Afanasyev | 89fb535 | 2012-06-12 22:43:16 -0700 | [diff] [blame] | 133 | // x->prune (); |
| 134 | // // x->find (n5).get<0> ()->erase (); |
| 135 | // x->find (n1).get<0> ()->erase (); |
Alexander Afanasyev | fd0c41c | 2012-06-11 22:15:49 -0700 | [diff] [blame] | 136 | |
Alexander Afanasyev | 89fb535 | 2012-06-12 22:43:16 -0700 | [diff] [blame] | 137 | // std::cout << "digraph trie {\n"; |
| 138 | // std::cout << *x; |
| 139 | // std::cout << "}\n"; |
Alexander Afanasyev | fd0c41c | 2012-06-11 22:15:49 -0700 | [diff] [blame] | 140 | |
Alexander Afanasyev | 89fb535 | 2012-06-12 22:43:16 -0700 | [diff] [blame] | 141 | // x->PrintStat (std::cout); |
| 142 | |
| 143 | // delete x; |
Alexander Afanasyev | fd0c41c | 2012-06-11 22:15:49 -0700 | [diff] [blame] | 144 | } |
| 145 | |