blob: bdbc3284223269ae3b971df70afce870186a7ef8 [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
29using namespace ns3;
Alexander Afanasyev30cb1172012-07-06 10:47:39 -070030using namespace ndnSIM;
31using namespace boost;
Alexander Afanasyevfd0c41c2012-06-11 22:15:49 -070032
33NS_LOG_COMPONENT_DEFINE ("Trie");
34
35class Integer : public ns3::SimpleRefCount<Integer>
36{
37public:
38 Integer (int value) : value_ (value) {}
Alexander Afanasyev89fb5352012-06-12 22:43:16 -070039
40 operator int () const { return value_; }
Alexander Afanasyevfd0c41c2012-06-11 22:15:49 -070041private:
42 int value_;
43};
44
Alexander Afanasyev89fb5352012-06-12 22:43:16 -070045std::ostream &
46operator << (std::ostream &os, const Integer &i)
47{
48 os << (int)i;
49 return os;
50}
51
Alexander Afanasyevfd0c41c2012-06-11 22:15:49 -070052int
53main (int argc, char *argv[])
54{
Alexander Afanasyev9e96e362012-07-02 23:04:39 -070055 CommandLine args;
56 args.Parse (argc, argv);
Alexander Afanasyev903062f2012-07-04 18:25:26 -070057
Alexander Afanasyev9e96e362012-07-02 23:04:39 -070058 typedef trie_with_policy<
59 ns3::CcnxNameComponents,
60 smart_pointer_payload_traits<Integer>,
Alexander Afanasyev903062f2012-07-04 18:25:26 -070061 multi_policy_traits<
Alexander Afanasyev30cb1172012-07-06 10:47:39 -070062 mpl::vector2<lru_policy_traits,random_policy_traits>
Alexander Afanasyev903062f2012-07-04 18:25:26 -070063 > > trie;
Alexander Afanasyev9e96e362012-07-02 23:04:39 -070064
Alexander Afanasyev89fb5352012-06-12 22:43:16 -070065 trie x;
Alexander Afanasyev30cb1172012-07-06 10:47:39 -070066 x.getPolicy ().get<0> ().set_max_size (100);
67 x.getPolicy ().get<1> ().set_max_size (3);
Alexander Afanasyev903062f2012-07-04 18:25:26 -070068 // // x.getPolicy ().get<1> ().set_max_size (3);
69 // // // x.getPolicy ().get1 ().set_max_size (10);
70 // // // x.getPolicy ().get2 ().set_max_size (3);
Alexander Afanasyev89fb5352012-06-12 22:43:16 -070071
Alexander Afanasyev903062f2012-07-04 18:25:26 -070072 // // // x.getTrie ().PrintStat (std::cout);
Alexander Afanasyev89fb5352012-06-12 22:43:16 -070073
74 ns3::CcnxNameComponents n1,n2,n3,n4;
Alexander Afanasyev903062f2012-07-04 18:25:26 -070075 // // // n1("a")("b")("c");
76 // // // n2("a")("b")("d");
77 // // // n3("a")("b")("f");
78 // // // n4("a")("b");
Alexander Afanasyevfd0c41c2012-06-11 22:15:49 -070079
Alexander Afanasyev9e96e362012-07-02 23:04:39 -070080 n1("a");
81 n2("b");
82 n3("c");
83 n4("d");
Alexander Afanasyev89fb5352012-06-12 22:43:16 -070084
85 x.insert (n1, ns3::Create<Integer> (1));
Alexander Afanasyev9e96e362012-07-02 23:04:39 -070086 x.insert (n2, ns3::Create<Integer> (2));
Alexander Afanasyev903062f2012-07-04 18:25:26 -070087 // // // x.longest_prefix_match (n1);
Alexander Afanasyev9e96e362012-07-02 23:04:39 -070088 x.insert (n3, ns3::Create<Integer> (3));
Alexander Afanasyev89fb5352012-06-12 22:43:16 -070089 x.insert (n4, ns3::Create<Integer> (4));
Alexander Afanasyev903062f2012-07-04 18:25:26 -070090 x.insert (n4, ns3::Create<Integer> (4));
Alexander Afanasyev89fb5352012-06-12 22:43:16 -070091
Alexander Afanasyev9a989702012-06-29 17:44:00 -070092 std::cout << "digraph trie {\n";
93 std::cout << x.getTrie ();
94 std::cout << "}\n";
95
96 // BOOST_FOREACH (const trie::parent_trie &item, x.getPolicy ())
97 // {
98 // std::cout << *item.payload () << " " << std::endl;
99 // }
Alexander Afanasyev89fb5352012-06-12 22:43:16 -0700100
101 // ns3::CcnxNameComponents n4;
102 // n4("a")("c");
Alexander Afanasyevfd0c41c2012-06-11 22:15:49 -0700103
Alexander Afanasyev89fb5352012-06-12 22:43:16 -0700104 // // std::cout << *x->find (n4).get<0> ();
Alexander Afanasyevfd0c41c2012-06-11 22:15:49 -0700105
Alexander Afanasyev89fb5352012-06-12 22:43:16 -0700106 // x->prune ();
107 // // x->find (n5).get<0> ()->erase ();
108 // x->find (n1).get<0> ()->erase ();
Alexander Afanasyevfd0c41c2012-06-11 22:15:49 -0700109
Alexander Afanasyev89fb5352012-06-12 22:43:16 -0700110 // std::cout << "digraph trie {\n";
111 // std::cout << *x;
112 // std::cout << "}\n";
Alexander Afanasyevfd0c41c2012-06-11 22:15:49 -0700113
Alexander Afanasyev89fb5352012-06-12 22:43:16 -0700114 // x->PrintStat (std::cout);
115
116 // delete x;
Alexander Afanasyevfd0c41c2012-06-11 22:15:49 -0700117
118 return 0;
119}
120