blob: dbdf0c3eacb898f78ff098f6927239c4a5c5fcc2 [file] [log] [blame]
Ilya Moiseenkoa828e9f2011-08-31 11:04:00 -07001/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2011 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: Ilya Moiseenko <iliamo@cs.ucla.edu>
19 */
20
Ilya Moiseenko3e15eff2011-08-30 13:33:09 -070021#include "ns3/test.h"
22#include "ns3/annotated-topology-reader.h"
23#include "ns3/ccnx-interest-header.h"
24#include "ns3/uinteger.h"
25#include "ns3/random-variable.h"
26#include <limits>
27#include "ns3/ccnx-header-helper.h"
28#include "ns3/header.h"
29#include "ns3/ccnx-name-components.h"
30#include "ns3/nstime.h"
31#include "ns3/buffer.h"
32#include "ns3/log.h"
33
Ilya Moiseenkoa828e9f2011-08-31 11:04:00 -070034#include <iostream>
35#include <fstream>
36#include <sstream>
37
Ilya Moiseenko3e15eff2011-08-30 13:33:09 -070038using namespace ns3;
Ilya Moiseenkoa828e9f2011-08-31 11:04:00 -070039using namespace std;
Ilya Moiseenko3e15eff2011-08-30 13:33:09 -070040
41NS_LOG_COMPONENT_DEFINE ("InterestHeaderSerializationTest");
42
43class InterestHeaderSerializationTest : public TestCase
44{
45public:
46 //static const uint32_t N_RUNS = 5;
47 //static const uint32_t N_BINS = 50;
48 //static const uint32_t N_MEASUREMENTS = 1000000;
49
50 InterestHeaderSerializationTest ();
51 virtual ~InterestHeaderSerializationTest ();
52
53 //double ChiSquaredTest (UniformVariable &u);
54
55private:
56 virtual void DoRun (void);
57};
58
59InterestHeaderSerializationTest::InterestHeaderSerializationTest ()
60: TestCase ("Interest Header Serialization Test")
61{
62}
63
64InterestHeaderSerializationTest::~InterestHeaderSerializationTest ()
65{
66}
67
68void
69InterestHeaderSerializationTest::DoRun(void)
70{
71 //ReportStart();
72 //SetVerbose(true);
Ilya Moiseenkoa828e9f2011-08-31 11:04:00 -070073 std::ostringstream msgStream;
74 msgStream << "Preved!";
75
76 //NS_TEST_EXPECT_MSG_NE (true,false, "DIRECTORY = " <<NS_TEST_SOURCEDIR);
77
78 /*ReportTestFailure ("DIRECTORY = ", NS_TEST_SOURCEDIR,
79 "", "",
80 "", 0);*/
81 string str = NS_TEST_SOURCEDIR;
82 //str += "/hahaha";
83 //CreateDataDirFilename(str);
Ilya Moiseenko3e15eff2011-08-30 13:33:09 -070084 NS_LOG_INFO ("Test started");
85 uint32_t randomNonce = UniformVariable().GetInteger(1, std::numeric_limits<uint32_t>::max ());
86 Ptr<CcnxNameComponents> testname = Create<CcnxNameComponents> ();
87 (*testname) ("test") ("test2");
88
89 Ptr<CcnxNameComponents> exclude = Create<CcnxNameComponents> ();
Ilya Moiseenkoa828e9f2011-08-31 11:04:00 -070090 (*exclude) ("exclude") ("exclude2");
Ilya Moiseenko3e15eff2011-08-30 13:33:09 -070091
92 Time lifetime = Seconds(4.0);
93 bool child = true;
94
95 uint32_t maxSuffixComponents = 40;
96 uint32_t minSuffixComponents = 20;
97
98 CcnxInterestHeader interestHeader;
99 interestHeader.SetNonce(randomNonce);
100 interestHeader.SetName(testname);
101 interestHeader.SetInterestLifetime(lifetime);
102 interestHeader.SetChildSelector(child);
103 interestHeader.SetExclude(exclude);
104 interestHeader.SetMaxSuffixComponents(maxSuffixComponents);
105 interestHeader.SetMinSuffixComponents(minSuffixComponents);
106
107 uint32_t size = interestHeader.GetSerializedSize();
108 //uint32_t size = 5;
109 NS_TEST_ASSERT_MSG_EQ (false, true, "GetSize = " << size);
110 Buffer buf(size);
111 Buffer::Iterator iter = buf.Begin ();
112 //interestHeader.
Ilya Moiseenkoa828e9f2011-08-31 11:04:00 -0700113 interestHeader.Serialize(iter);
Ilya Moiseenko3e15eff2011-08-30 13:33:09 -0700114
115 iter = buf.Begin ();
116 CcnxInterestHeader target;
Ilya Moiseenkoa828e9f2011-08-31 11:04:00 -0700117 target.Deserialize(iter);
Ilya Moiseenko3e15eff2011-08-30 13:33:09 -0700118
119 /*if(target.GetNonce() == randomNonce)
120 {
121
122 ReportCaseFailure();
123 }*/
124 NS_TEST_ASSERT_MSG_EQ (target.GetNonce(), randomNonce, "Interest Header nonce deserialization failed");
125
Ilya Moiseenkoa828e9f2011-08-31 11:04:00 -0700126 NS_TEST_ASSERT_MSG_EQ (target.GetName(), *testname, "Interest Header name deserialization failed");
Ilya Moiseenko3e15eff2011-08-30 13:33:09 -0700127
128 NS_TEST_ASSERT_MSG_EQ (target.GetInterestLifetime(), lifetime, "Interest Header lifetime deserialization failed");
129
Ilya Moiseenkoa828e9f2011-08-31 11:04:00 -0700130 NS_TEST_ASSERT_MSG_EQ (target.IsEnabledChildSelector(), child, "Interest Header childselector deserialization failed");
Ilya Moiseenko3e15eff2011-08-30 13:33:09 -0700131
Ilya Moiseenkoa828e9f2011-08-31 11:04:00 -0700132 NS_TEST_ASSERT_MSG_EQ (target.GetExclude(), *exclude, "Interest Header exclude deserialization failed");
Ilya Moiseenko3e15eff2011-08-30 13:33:09 -0700133
134 NS_TEST_ASSERT_MSG_EQ (target.GetMaxSuffixComponents(), (int)maxSuffixComponents, "Interest Header maxSuffixComponents deserialization failed");
135
136 NS_TEST_ASSERT_MSG_EQ (target.GetMinSuffixComponents(), (int)minSuffixComponents, "Interest Header minSuffixComponents deserialization failed");
137}
138
139class InterestHeaderSerializationTestSuite : public TestSuite
140{
141public:
142 InterestHeaderSerializationTestSuite ();
143};
144
145InterestHeaderSerializationTestSuite::InterestHeaderSerializationTestSuite ()
146: TestSuite ("interest-header-serialization-test-suite", UNIT)
147{
Ilya Moiseenkoa828e9f2011-08-31 11:04:00 -0700148 SetDataDir (NS_TEST_SOURCEDIR);
Ilya Moiseenko3e15eff2011-08-30 13:33:09 -0700149 AddTestCase (new InterestHeaderSerializationTest);
150}
151
152static InterestHeaderSerializationTestSuite suite;