blob: 62d83a46d69ac858a0e41b02d31204047c94bf12 [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:
Ilya Moiseenko3e15eff2011-08-30 13:33:09 -070046 InterestHeaderSerializationTest ();
47 virtual ~InterestHeaderSerializationTest ();
48
Ilya Moiseenko3e15eff2011-08-30 13:33:09 -070049private:
50 virtual void DoRun (void);
51};
52
53InterestHeaderSerializationTest::InterestHeaderSerializationTest ()
54: TestCase ("Interest Header Serialization Test")
55{
56}
57
58InterestHeaderSerializationTest::~InterestHeaderSerializationTest ()
59{
60}
61
62void
63InterestHeaderSerializationTest::DoRun(void)
64{
Ilya Moiseenko08723712011-09-01 17:42:12 -070065 Packet packet (0);
Ilya Moiseenkoa828e9f2011-08-31 11:04:00 -070066
Ilya Moiseenko3e15eff2011-08-30 13:33:09 -070067 uint32_t randomNonce = UniformVariable().GetInteger(1, std::numeric_limits<uint32_t>::max ());
68 Ptr<CcnxNameComponents> testname = Create<CcnxNameComponents> ();
69 (*testname) ("test") ("test2");
70
71 Ptr<CcnxNameComponents> exclude = Create<CcnxNameComponents> ();
Ilya Moiseenkoa828e9f2011-08-31 11:04:00 -070072 (*exclude) ("exclude") ("exclude2");
Ilya Moiseenko3e15eff2011-08-30 13:33:09 -070073
74 Time lifetime = Seconds(4.0);
75 bool child = true;
76
77 uint32_t maxSuffixComponents = 40;
78 uint32_t minSuffixComponents = 20;
79
80 CcnxInterestHeader interestHeader;
81 interestHeader.SetNonce(randomNonce);
82 interestHeader.SetName(testname);
83 interestHeader.SetInterestLifetime(lifetime);
84 interestHeader.SetChildSelector(child);
85 interestHeader.SetExclude(exclude);
86 interestHeader.SetMaxSuffixComponents(maxSuffixComponents);
87 interestHeader.SetMinSuffixComponents(minSuffixComponents);
88
Ilya Moiseenko08723712011-09-01 17:42:12 -070089 //serialization
90 packet.AddHeader (interestHeader);
91
92 //deserialization
Ilya Moiseenko3e15eff2011-08-30 13:33:09 -070093 CcnxInterestHeader target;
Ilya Moiseenko08723712011-09-01 17:42:12 -070094 packet.RemoveHeader (target);
95
Ilya Moiseenko3e15eff2011-08-30 13:33:09 -070096
Ilya Moiseenko3e15eff2011-08-30 13:33:09 -070097 NS_TEST_ASSERT_MSG_EQ (target.GetNonce(), randomNonce, "Interest Header nonce deserialization failed");
98
Ilya Moiseenkoa828e9f2011-08-31 11:04:00 -070099 NS_TEST_ASSERT_MSG_EQ (target.GetName(), *testname, "Interest Header name deserialization failed");
Ilya Moiseenko3e15eff2011-08-30 13:33:09 -0700100
101 NS_TEST_ASSERT_MSG_EQ (target.GetInterestLifetime(), lifetime, "Interest Header lifetime deserialization failed");
102
Ilya Moiseenkoa828e9f2011-08-31 11:04:00 -0700103 NS_TEST_ASSERT_MSG_EQ (target.IsEnabledChildSelector(), child, "Interest Header childselector deserialization failed");
Ilya Moiseenko3e15eff2011-08-30 13:33:09 -0700104
Ilya Moiseenkoa828e9f2011-08-31 11:04:00 -0700105 NS_TEST_ASSERT_MSG_EQ (target.GetExclude(), *exclude, "Interest Header exclude deserialization failed");
Ilya Moiseenko3e15eff2011-08-30 13:33:09 -0700106
107 NS_TEST_ASSERT_MSG_EQ (target.GetMaxSuffixComponents(), (int)maxSuffixComponents, "Interest Header maxSuffixComponents deserialization failed");
108
109 NS_TEST_ASSERT_MSG_EQ (target.GetMinSuffixComponents(), (int)minSuffixComponents, "Interest Header minSuffixComponents deserialization failed");
110}
111
112class InterestHeaderSerializationTestSuite : public TestSuite
113{
114public:
115 InterestHeaderSerializationTestSuite ();
116};
117
118InterestHeaderSerializationTestSuite::InterestHeaderSerializationTestSuite ()
119: TestSuite ("interest-header-serialization-test-suite", UNIT)
120{
Ilya Moiseenkoa828e9f2011-08-31 11:04:00 -0700121 SetDataDir (NS_TEST_SOURCEDIR);
Ilya Moiseenko3e15eff2011-08-30 13:33:09 -0700122 AddTestCase (new InterestHeaderSerializationTest);
123}
124
125static InterestHeaderSerializationTestSuite suite;