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 | 9a98970 | 2012-06-29 17:44:00 -0700 | [diff] [blame] | 23 | #include "../utils/trie-with-policy.h" |
Alexander Afanasyev | 9e96e36 | 2012-07-02 23:04:39 -0700 | [diff] [blame] | 24 | #include "../utils/lru-policy.h" |
| 25 | #include "../utils/random-policy.h" |
| 26 | #include "../utils/fifo-policy.h" |
Alexander Afanasyev | 30cb117 | 2012-07-06 10:47:39 -0700 | [diff] [blame] | 27 | #include "../utils/multi-policy.h" |
Alexander Afanasyev | fd0c41c | 2012-06-11 22:15:49 -0700 | [diff] [blame] | 28 | |
Alexander Afanasyev | 44bb6ea | 2012-07-09 08:44:41 -0700 | [diff] [blame] | 29 | #include <boost/lexical_cast.hpp> |
| 30 | |
| 31 | using namespace std; |
Alexander Afanasyev | fd0c41c | 2012-06-11 22:15:49 -0700 | [diff] [blame] | 32 | using namespace ns3; |
Alexander Afanasyev | 30cb117 | 2012-07-06 10:47:39 -0700 | [diff] [blame] | 33 | using namespace ndnSIM; |
| 34 | using namespace boost; |
Alexander Afanasyev | fd0c41c | 2012-06-11 22:15:49 -0700 | [diff] [blame] | 35 | |
| 36 | NS_LOG_COMPONENT_DEFINE ("Trie"); |
| 37 | |
Alexander Afanasyev | 36b4577 | 2012-07-10 16:57:42 -0700 | [diff] [blame] | 38 | // class Integer : public ns3::SimpleRefCount<Integer> |
| 39 | // { |
| 40 | // public: |
| 41 | // ::Integer (int value) : value_ (value) {} |
Alexander Afanasyev | 89fb535 | 2012-06-12 22:43:16 -0700 | [diff] [blame] | 42 | |
Alexander Afanasyev | 36b4577 | 2012-07-10 16:57:42 -0700 | [diff] [blame] | 43 | // operator int () const { return value_; } |
| 44 | // private: |
| 45 | // int value_; |
| 46 | // }; |
Alexander Afanasyev | fd0c41c | 2012-06-11 22:15:49 -0700 | [diff] [blame] | 47 | |
Alexander Afanasyev | 36b4577 | 2012-07-10 16:57:42 -0700 | [diff] [blame] | 48 | // std::ostream & |
| 49 | // operator << (std::ostream &os, const ::Integer &i) |
| 50 | // { |
| 51 | // os << (int)i; |
| 52 | // return os; |
| 53 | // } |
Alexander Afanasyev | 89fb535 | 2012-06-12 22:43:16 -0700 | [diff] [blame] | 54 | |
Alexander Afanasyev | fd0c41c | 2012-06-11 22:15:49 -0700 | [diff] [blame] | 55 | int |
| 56 | main (int argc, char *argv[]) |
| 57 | { |
Alexander Afanasyev | 9e96e36 | 2012-07-02 23:04:39 -0700 | [diff] [blame] | 58 | CommandLine args; |
| 59 | args.Parse (argc, argv); |
Alexander Afanasyev | 903062f | 2012-07-04 18:25:26 -0700 | [diff] [blame] | 60 | |
Alexander Afanasyev | 44bb6ea | 2012-07-09 08:44:41 -0700 | [diff] [blame] | 61 | // typedef trie_with_policy< |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 62 | // ns3::NdnNameComponents, |
Alexander Afanasyev | 44bb6ea | 2012-07-09 08:44:41 -0700 | [diff] [blame] | 63 | // smart_pointer_payload_traits<Integer>, |
| 64 | // multi_policy_traits< |
| 65 | // mpl::vector2<lru_policy_traits,random_policy_traits> |
| 66 | // > > trie; |
Alexander Afanasyev | 9e96e36 | 2012-07-02 23:04:39 -0700 | [diff] [blame] | 67 | |
Alexander Afanasyev | 44bb6ea | 2012-07-09 08:44:41 -0700 | [diff] [blame] | 68 | // trie x; |
| 69 | // x.getPolicy ().get<0> ().set_max_size (100); |
| 70 | // x.getPolicy ().get<1> ().set_max_size (3); |
| 71 | // // // x.getPolicy ().get<1> ().set_max_size (3); |
| 72 | // // // // x.getPolicy ().get1 ().set_max_size (10); |
| 73 | // // // // x.getPolicy ().get2 ().set_max_size (3); |
Alexander Afanasyev | 89fb535 | 2012-06-12 22:43:16 -0700 | [diff] [blame] | 74 | |
Alexander Afanasyev | 44bb6ea | 2012-07-09 08:44:41 -0700 | [diff] [blame] | 75 | // // // // x.getTrie ().PrintStat (std::cout); |
Alexander Afanasyev | 89fb535 | 2012-06-12 22:43:16 -0700 | [diff] [blame] | 76 | |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 77 | // ns3::NdnNameComponents n1,n2,n3,n4; |
Alexander Afanasyev | 44bb6ea | 2012-07-09 08:44:41 -0700 | [diff] [blame] | 78 | // // // // n1("a")("b")("c"); |
| 79 | // // // // n2("a")("b")("d"); |
| 80 | // // // // n3("a")("b")("f"); |
| 81 | // // // // n4("a")("b"); |
Alexander Afanasyev | fd0c41c | 2012-06-11 22:15:49 -0700 | [diff] [blame] | 82 | |
Alexander Afanasyev | 44bb6ea | 2012-07-09 08:44:41 -0700 | [diff] [blame] | 83 | // n1("a"); |
| 84 | // n2("b"); |
| 85 | // n3("c"); |
| 86 | // n4("d"); |
Alexander Afanasyev | 89fb535 | 2012-06-12 22:43:16 -0700 | [diff] [blame] | 87 | |
Alexander Afanasyev | 44bb6ea | 2012-07-09 08:44:41 -0700 | [diff] [blame] | 88 | // x.insert (n1, ns3::Create<Integer> (1)); |
| 89 | // x.insert (n2, ns3::Create<Integer> (2)); |
| 90 | // // // // x.longest_prefix_match (n1); |
| 91 | // x.insert (n3, ns3::Create<Integer> (3)); |
| 92 | // x.insert (n4, ns3::Create<Integer> (4)); |
| 93 | // x.insert (n4, ns3::Create<Integer> (4)); |
Alexander Afanasyev | 89fb535 | 2012-06-12 22:43:16 -0700 | [diff] [blame] | 94 | |
Alexander Afanasyev | 44bb6ea | 2012-07-09 08:44:41 -0700 | [diff] [blame] | 95 | // std::cout << "digraph trie {\n"; |
| 96 | // std::cout << x.getTrie (); |
| 97 | // std::cout << "}\n"; |
Alexander Afanasyev | 9a98970 | 2012-06-29 17:44:00 -0700 | [diff] [blame] | 98 | |
Alexander Afanasyev | 44bb6ea | 2012-07-09 08:44:41 -0700 | [diff] [blame] | 99 | Ptr<Node> node = CreateObject<Node> (); |
| 100 | Names::Add ("TestNode", node); |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 101 | Ptr<NdnApp> app = CreateObject<NdnApp> (); |
Alexander Afanasyev | 44bb6ea | 2012-07-09 08:44:41 -0700 | [diff] [blame] | 102 | node->AddApplication (app); |
| 103 | |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 104 | ObjectFactory factory ("ns3::NdnFib"); |
Alexander Afanasyev | 44bb6ea | 2012-07-09 08:44:41 -0700 | [diff] [blame] | 105 | |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 106 | Ptr<NdnFib> fib = factory.Create<NdnFib> (); |
Alexander Afanasyev | 44bb6ea | 2012-07-09 08:44:41 -0700 | [diff] [blame] | 107 | node->AggregateObject (fib); |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 108 | Ptr<NdnFace> face = CreateObject<NdnAppFace> (app); |
Alexander Afanasyev | 44bb6ea | 2012-07-09 08:44:41 -0700 | [diff] [blame] | 109 | |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 110 | fib->Add (lexical_cast<NdnNameComponents> ("/bla"), face, 1); |
| 111 | fib->Add (lexical_cast<NdnNameComponents> ("/bla/1"), face, 1); |
| 112 | fib->Add (lexical_cast<NdnNameComponents> ("/bla/2"), face, 1); |
| 113 | fib->Add (lexical_cast<NdnNameComponents> ("/bla/3"), face, 1); |
| 114 | fib->Add (lexical_cast<NdnNameComponents> ("/bla/1/1"), face, 1); |
| 115 | fib->Add (lexical_cast<NdnNameComponents> ("/bla/1/2"), face, 1); |
Alexander Afanasyev | 44bb6ea | 2012-07-09 08:44:41 -0700 | [diff] [blame] | 116 | |
| 117 | cout << *fib << endl; |
| 118 | |
| 119 | fib->RemoveFromAll (face); |
| 120 | |
| 121 | cout << *fib << endl; |
Alexander Afanasyev | 9a98970 | 2012-06-29 17:44:00 -0700 | [diff] [blame] | 122 | // BOOST_FOREACH (const trie::parent_trie &item, x.getPolicy ()) |
| 123 | // { |
| 124 | // std::cout << *item.payload () << " " << std::endl; |
| 125 | // } |
Alexander Afanasyev | 89fb535 | 2012-06-12 22:43:16 -0700 | [diff] [blame] | 126 | |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 127 | // ns3::NdnNameComponents n4; |
Alexander Afanasyev | 89fb535 | 2012-06-12 22:43:16 -0700 | [diff] [blame] | 128 | // n4("a")("c"); |
Alexander Afanasyev | fd0c41c | 2012-06-11 22:15:49 -0700 | [diff] [blame] | 129 | |
Alexander Afanasyev | 89fb535 | 2012-06-12 22:43:16 -0700 | [diff] [blame] | 130 | // // std::cout << *x->find (n4).get<0> (); |
Alexander Afanasyev | fd0c41c | 2012-06-11 22:15:49 -0700 | [diff] [blame] | 131 | |
Alexander Afanasyev | 89fb535 | 2012-06-12 22:43:16 -0700 | [diff] [blame] | 132 | // x->prune (); |
| 133 | // // x->find (n5).get<0> ()->erase (); |
| 134 | // x->find (n1).get<0> ()->erase (); |
Alexander Afanasyev | fd0c41c | 2012-06-11 22:15:49 -0700 | [diff] [blame] | 135 | |
Alexander Afanasyev | 89fb535 | 2012-06-12 22:43:16 -0700 | [diff] [blame] | 136 | // std::cout << "digraph trie {\n"; |
| 137 | // std::cout << *x; |
| 138 | // std::cout << "}\n"; |
Alexander Afanasyev | fd0c41c | 2012-06-11 22:15:49 -0700 | [diff] [blame] | 139 | |
Alexander Afanasyev | 89fb535 | 2012-06-12 22:43:16 -0700 | [diff] [blame] | 140 | // x->PrintStat (std::cout); |
| 141 | |
| 142 | // delete x; |
Alexander Afanasyev | fd0c41c | 2012-06-11 22:15:49 -0700 | [diff] [blame] | 143 | |
| 144 | return 0; |
| 145 | } |
| 146 | |