blob: 7ec0c4012140a57104715c2da10dba8fc886279d [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 Afanasyev9a989702012-06-29 17:44:00 -070023#include "../utils/trie-with-policy.h"
Alexander Afanasyev9e96e362012-07-02 23:04:39 -070024#include "../utils/lru-policy.h"
25#include "../utils/random-policy.h"
26#include "../utils/fifo-policy.h"
Alexander Afanasyev30cb1172012-07-06 10:47:39 -070027#include "../utils/multi-policy.h"
Alexander Afanasyevfd0c41c2012-06-11 22:15:49 -070028
Alexander Afanasyev44bb6ea2012-07-09 08:44:41 -070029#include <boost/lexical_cast.hpp>
30
31using namespace std;
Alexander Afanasyevfd0c41c2012-06-11 22:15:49 -070032using namespace ns3;
Alexander Afanasyev30cb1172012-07-06 10:47:39 -070033using namespace ndnSIM;
34using namespace boost;
Alexander Afanasyevfd0c41c2012-06-11 22:15:49 -070035
36NS_LOG_COMPONENT_DEFINE ("Trie");
37
38class Integer : public ns3::SimpleRefCount<Integer>
39{
40public:
41 Integer (int value) : value_ (value) {}
Alexander Afanasyev89fb5352012-06-12 22:43:16 -070042
43 operator int () const { return value_; }
Alexander Afanasyevfd0c41c2012-06-11 22:15:49 -070044private:
45 int value_;
46};
47
Alexander Afanasyev89fb5352012-06-12 22:43:16 -070048std::ostream &
49operator << (std::ostream &os, const Integer &i)
50{
51 os << (int)i;
52 return os;
53}
54
Alexander Afanasyevfd0c41c2012-06-11 22:15:49 -070055int
56main (int argc, char *argv[])
57{
Alexander Afanasyev9e96e362012-07-02 23:04:39 -070058 CommandLine args;
59 args.Parse (argc, argv);
Alexander Afanasyev903062f2012-07-04 18:25:26 -070060
Alexander Afanasyev44bb6ea2012-07-09 08:44:41 -070061 // typedef trie_with_policy<
62 // ns3::CcnxNameComponents,
63 // smart_pointer_payload_traits<Integer>,
64 // multi_policy_traits<
65 // mpl::vector2<lru_policy_traits,random_policy_traits>
66 // > > trie;
Alexander Afanasyev9e96e362012-07-02 23:04:39 -070067
Alexander Afanasyev44bb6ea2012-07-09 08:44:41 -070068 // 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 Afanasyev89fb5352012-06-12 22:43:16 -070074
Alexander Afanasyev44bb6ea2012-07-09 08:44:41 -070075 // // // // x.getTrie ().PrintStat (std::cout);
Alexander Afanasyev89fb5352012-06-12 22:43:16 -070076
Alexander Afanasyev44bb6ea2012-07-09 08:44:41 -070077 // ns3::CcnxNameComponents n1,n2,n3,n4;
78 // // // // n1("a")("b")("c");
79 // // // // n2("a")("b")("d");
80 // // // // n3("a")("b")("f");
81 // // // // n4("a")("b");
Alexander Afanasyevfd0c41c2012-06-11 22:15:49 -070082
Alexander Afanasyev44bb6ea2012-07-09 08:44:41 -070083 // n1("a");
84 // n2("b");
85 // n3("c");
86 // n4("d");
Alexander Afanasyev89fb5352012-06-12 22:43:16 -070087
Alexander Afanasyev44bb6ea2012-07-09 08:44:41 -070088 // 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 Afanasyev89fb5352012-06-12 22:43:16 -070094
Alexander Afanasyev44bb6ea2012-07-09 08:44:41 -070095 // std::cout << "digraph trie {\n";
96 // std::cout << x.getTrie ();
97 // std::cout << "}\n";
Alexander Afanasyev9a989702012-06-29 17:44:00 -070098
Alexander Afanasyev44bb6ea2012-07-09 08:44:41 -070099 Ptr<Node> node = CreateObject<Node> ();
100 Names::Add ("TestNode", node);
101 Ptr<CcnxApp> app = CreateObject<CcnxApp> ();
102 node->AddApplication (app);
103
104 ObjectFactory factory ("ns3::CcnxFib");
105
106 Ptr<CcnxFib> fib = factory.Create<CcnxFib> ();
107 node->AggregateObject (fib);
108 Ptr<CcnxFace> face = CreateObject<CcnxAppFace> (app);
109
110 fib->Add (lexical_cast<CcnxNameComponents> ("/bla"), face, 1);
111 fib->Add (lexical_cast<CcnxNameComponents> ("/bla/1"), face, 1);
112 fib->Add (lexical_cast<CcnxNameComponents> ("/bla/2"), face, 1);
113 fib->Add (lexical_cast<CcnxNameComponents> ("/bla/3"), face, 1);
114 fib->Add (lexical_cast<CcnxNameComponents> ("/bla/1/1"), face, 1);
115 fib->Add (lexical_cast<CcnxNameComponents> ("/bla/1/2"), face, 1);
116
117 cout << *fib << endl;
118
119 fib->RemoveFromAll (face);
120
121 cout << *fib << endl;
Alexander Afanasyev9a989702012-06-29 17:44:00 -0700122 // BOOST_FOREACH (const trie::parent_trie &item, x.getPolicy ())
123 // {
124 // std::cout << *item.payload () << " " << std::endl;
125 // }
Alexander Afanasyev89fb5352012-06-12 22:43:16 -0700126
127 // ns3::CcnxNameComponents n4;
128 // n4("a")("c");
Alexander Afanasyevfd0c41c2012-06-11 22:15:49 -0700129
Alexander Afanasyev89fb5352012-06-12 22:43:16 -0700130 // // std::cout << *x->find (n4).get<0> ();
Alexander Afanasyevfd0c41c2012-06-11 22:15:49 -0700131
Alexander Afanasyev89fb5352012-06-12 22:43:16 -0700132 // x->prune ();
133 // // x->find (n5).get<0> ()->erase ();
134 // x->find (n1).get<0> ()->erase ();
Alexander Afanasyevfd0c41c2012-06-11 22:15:49 -0700135
Alexander Afanasyev89fb5352012-06-12 22:43:16 -0700136 // std::cout << "digraph trie {\n";
137 // std::cout << *x;
138 // std::cout << "}\n";
Alexander Afanasyevfd0c41c2012-06-11 22:15:49 -0700139
Alexander Afanasyev89fb5352012-06-12 22:43:16 -0700140 // x->PrintStat (std::cout);
141
142 // delete x;
Alexander Afanasyevfd0c41c2012-06-11 22:15:49 -0700143
144 return 0;
145}
146