blob: ed8356e0968f6710831b57a2981a3139829f1512 [file] [log] [blame]
Alexander Afanasyevfd0c41c2012-06-11 22:15:49 -07001/* -*- 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 Afanasyev674c8762012-11-21 23:50:33 -080023
24#include "ndnSIM-trie.h"
25
Alexander Afanasyev1a2df6a2012-08-17 13:21:51 -070026#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 Afanasyevfd0c41c2012-06-11 22:15:49 -070031
Alexander Afanasyev44bb6ea2012-07-09 08:44:41 -070032#include <boost/lexical_cast.hpp>
33
34using namespace std;
Alexander Afanasyevfd0c41c2012-06-11 22:15:49 -070035using namespace ns3;
Alexander Afanasyevcf6dc922012-08-10 16:55:27 -070036using namespace ndn::ndnSIM;
Alexander Afanasyev30cb1172012-07-06 10:47:39 -070037using namespace boost;
Alexander Afanasyevfd0c41c2012-06-11 22:15:49 -070038
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070039NS_LOG_COMPONENT_DEFINE ("ndn.Trie");
Alexander Afanasyevfd0c41c2012-06-11 22:15:49 -070040
Alexander Afanasyev36b45772012-07-10 16:57:42 -070041// class Integer : public ns3::SimpleRefCount<Integer>
42// {
43// public:
44// ::Integer (int value) : value_ (value) {}
Alexander Afanasyev89fb5352012-06-12 22:43:16 -070045
Alexander Afanasyev36b45772012-07-10 16:57:42 -070046// operator int () const { return value_; }
47// private:
48// int value_;
49// };
Alexander Afanasyevfd0c41c2012-06-11 22:15:49 -070050
Alexander Afanasyev36b45772012-07-10 16:57:42 -070051// std::ostream &
52// operator << (std::ostream &os, const ::Integer &i)
53// {
54// os << (int)i;
55// return os;
56// }
Alexander Afanasyev89fb5352012-06-12 22:43:16 -070057
Alexander Afanasyev674c8762012-11-21 23:50:33 -080058void
59TrieTest::DoRun ()
Alexander Afanasyevfd0c41c2012-06-11 22:15:49 -070060{
Alexander Afanasyev674c8762012-11-21 23:50:33 -080061 cerr << "TrieTest is temporarily broken" << endl;
Alexander Afanasyev44bb6ea2012-07-09 08:44:41 -070062 // typedef trie_with_policy<
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070063 // ns3::NdnNameComponents,
Alexander Afanasyev44bb6ea2012-07-09 08:44:41 -070064 // smart_pointer_payload_traits<Integer>,
65 // multi_policy_traits<
66 // mpl::vector2<lru_policy_traits,random_policy_traits>
67 // > > trie;
Alexander Afanasyev9e96e362012-07-02 23:04:39 -070068
Alexander Afanasyev44bb6ea2012-07-09 08:44:41 -070069 // 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 Afanasyev89fb5352012-06-12 22:43:16 -070075
Alexander Afanasyev44bb6ea2012-07-09 08:44:41 -070076 // // // // x.getTrie ().PrintStat (std::cout);
Alexander Afanasyev89fb5352012-06-12 22:43:16 -070077
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070078 // ns3::NdnNameComponents n1,n2,n3,n4;
Alexander Afanasyev44bb6ea2012-07-09 08:44:41 -070079 // // // // n1("a")("b")("c");
80 // // // // n2("a")("b")("d");
81 // // // // n3("a")("b")("f");
82 // // // // n4("a")("b");
Alexander Afanasyevfd0c41c2012-06-11 22:15:49 -070083
Alexander Afanasyev44bb6ea2012-07-09 08:44:41 -070084 // n1("a");
85 // n2("b");
86 // n3("c");
87 // n4("d");
Alexander Afanasyev89fb5352012-06-12 22:43:16 -070088
Alexander Afanasyev44bb6ea2012-07-09 08:44:41 -070089 // 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 Afanasyev89fb5352012-06-12 22:43:16 -070095
Alexander Afanasyev44bb6ea2012-07-09 08:44:41 -070096 // std::cout << "digraph trie {\n";
97 // std::cout << x.getTrie ();
98 // std::cout << "}\n";
Alexander Afanasyev9a989702012-06-29 17:44:00 -070099
Alexander Afanasyev674c8762012-11-21 23:50:33 -0800100 // Ptr<Node> node = CreateObject<Node> ();
101 // Names::Add ("TestNode", node);
102 // Ptr<ndn::App> app = CreateObject<ndn::App> ();
103 // node->AddApplication (app);
Alexander Afanasyev44bb6ea2012-07-09 08:44:41 -0700104
Alexander Afanasyev674c8762012-11-21 23:50:33 -0800105 // ObjectFactory factory ("ns3::ndn::fib::Default");
Alexander Afanasyev44bb6ea2012-07-09 08:44:41 -0700106
Alexander Afanasyev674c8762012-11-21 23:50:33 -0800107 // Ptr<ndn::Fib> fib = factory.Create<ndn::Fib> ();
108 // node->AggregateObject (fib);
109 // Ptr<ndn::Face> face = CreateObject<ndn::AppFace> (app);
Alexander Afanasyev44bb6ea2012-07-09 08:44:41 -0700110
Alexander Afanasyev674c8762012-11-21 23:50:33 -0800111 // 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 Afanasyev44bb6ea2012-07-09 08:44:41 -0700117
Alexander Afanasyev674c8762012-11-21 23:50:33 -0800118 // cout << *fib << endl;
Alexander Afanasyev44bb6ea2012-07-09 08:44:41 -0700119
Alexander Afanasyev674c8762012-11-21 23:50:33 -0800120 // fib->RemoveFromAll (face);
Alexander Afanasyev44bb6ea2012-07-09 08:44:41 -0700121
Alexander Afanasyev674c8762012-11-21 23:50:33 -0800122 // cout << *fib << endl;
Alexander Afanasyev9a989702012-06-29 17:44:00 -0700123 // BOOST_FOREACH (const trie::parent_trie &item, x.getPolicy ())
124 // {
125 // std::cout << *item.payload () << " " << std::endl;
126 // }
Alexander Afanasyev89fb5352012-06-12 22:43:16 -0700127
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700128 // ns3::NdnNameComponents n4;
Alexander Afanasyev89fb5352012-06-12 22:43:16 -0700129 // n4("a")("c");
Alexander Afanasyevfd0c41c2012-06-11 22:15:49 -0700130
Alexander Afanasyev89fb5352012-06-12 22:43:16 -0700131 // // std::cout << *x->find (n4).get<0> ();
Alexander Afanasyevfd0c41c2012-06-11 22:15:49 -0700132
Alexander Afanasyev89fb5352012-06-12 22:43:16 -0700133 // x->prune ();
134 // // x->find (n5).get<0> ()->erase ();
135 // x->find (n1).get<0> ()->erase ();
Alexander Afanasyevfd0c41c2012-06-11 22:15:49 -0700136
Alexander Afanasyev89fb5352012-06-12 22:43:16 -0700137 // std::cout << "digraph trie {\n";
138 // std::cout << *x;
139 // std::cout << "}\n";
Alexander Afanasyevfd0c41c2012-06-11 22:15:49 -0700140
Alexander Afanasyev89fb5352012-06-12 22:43:16 -0700141 // x->PrintStat (std::cout);
142
143 // delete x;
Alexander Afanasyevfd0c41c2012-06-11 22:15:49 -0700144}
145