blob: 81b7972430151981b7ba4004a703f0c9035b70ce [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"
Ilya Moiseenko3e15eff2011-08-30 13:33:09 -070022#include "ns3/ccnx-interest-header.h"
23#include "ns3/uinteger.h"
24#include "ns3/random-variable.h"
25#include <limits>
26#include "ns3/ccnx-header-helper.h"
27#include "ns3/header.h"
28#include "ns3/ccnx-name-components.h"
29#include "ns3/nstime.h"
30#include "ns3/buffer.h"
31#include "ns3/log.h"
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -080032#include "ns3/packet.h"
Ilya Moiseenko3e15eff2011-08-30 13:33:09 -070033
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:
Alexander Afanasyev864522f2012-05-31 13:33:57 -070046 InterestHeaderSerializationTest ();
47 virtual ~InterestHeaderSerializationTest ();
Ilya Moiseenko3e15eff2011-08-30 13:33:09 -070048
Ilya Moiseenko3e15eff2011-08-30 13:33:09 -070049private:
Alexander Afanasyev864522f2012-05-31 13:33:57 -070050 virtual void DoRun (void);
Ilya Moiseenko3e15eff2011-08-30 13:33:09 -070051};
52
53InterestHeaderSerializationTest::InterestHeaderSerializationTest ()
Alexander Afanasyev864522f2012-05-31 13:33:57 -070054 : TestCase ("Interest Header Serialization Test")
Ilya Moiseenko3e15eff2011-08-30 13:33:09 -070055{
56}
57
58InterestHeaderSerializationTest::~InterestHeaderSerializationTest ()
59{
60}
61
62void
63InterestHeaderSerializationTest::DoRun(void)
64{
Alexander Afanasyev864522f2012-05-31 13:33:57 -070065 Packet packet (0);
Ilya Moiseenkoa828e9f2011-08-31 11:04:00 -070066
Alexander Afanasyev864522f2012-05-31 13:33:57 -070067 uint32_t randomNonce = UniformVariable().GetInteger(1, std::numeric_limits<uint32_t>::max ());
68 Ptr<CcnxNameComponents> testname = Create<CcnxNameComponents> ();
69 (*testname) ("test") ("test2");
Ilya Moiseenko3e15eff2011-08-30 13:33:09 -070070
Alexander Afanasyev864522f2012-05-31 13:33:57 -070071 Ptr<CcnxNameComponents> exclude = Create<CcnxNameComponents> ();
72 (*exclude) ("exclude") ("exclude2");
Ilya Moiseenko3e15eff2011-08-30 13:33:09 -070073
Alexander Afanasyev864522f2012-05-31 13:33:57 -070074 Time lifetime = Seconds(4.0);
75 bool child = true;
Ilya Moiseenko3e15eff2011-08-30 13:33:09 -070076
Alexander Afanasyev864522f2012-05-31 13:33:57 -070077 uint32_t maxSuffixComponents = 40;
78 uint32_t minSuffixComponents = 20;
Ilya Moiseenko3e15eff2011-08-30 13:33:09 -070079
Alexander Afanasyev864522f2012-05-31 13:33:57 -070080 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);
Ilya Moiseenko3e15eff2011-08-30 13:33:09 -070088
Alexander Afanasyev864522f2012-05-31 13:33:57 -070089 //serialization
90 packet.AddHeader (interestHeader);
Ilya Moiseenko08723712011-09-01 17:42:12 -070091
Alexander Afanasyev864522f2012-05-31 13:33:57 -070092 //deserialization
93 CcnxInterestHeader target;
94 packet.RemoveHeader (target);
Ilya Moiseenko08723712011-09-01 17:42:12 -070095
Ilya Moiseenko3e15eff2011-08-30 13:33:09 -070096
Alexander Afanasyev864522f2012-05-31 13:33:57 -070097 NS_TEST_ASSERT_MSG_EQ (target.GetNonce(), randomNonce, "Interest Header nonce deserialization failed");
Ilya Moiseenko3e15eff2011-08-30 13:33:09 -070098
Alexander Afanasyev864522f2012-05-31 13:33:57 -070099 NS_TEST_ASSERT_MSG_EQ (target.GetName(), *testname, "Interest Header name deserialization failed");
Ilya Moiseenko3e15eff2011-08-30 13:33:09 -0700100
Alexander Afanasyev864522f2012-05-31 13:33:57 -0700101 NS_TEST_ASSERT_MSG_EQ (target.GetInterestLifetime(), lifetime, "Interest Header lifetime deserialization failed");
Ilya Moiseenko3e15eff2011-08-30 13:33:09 -0700102
Alexander Afanasyev864522f2012-05-31 13:33:57 -0700103 NS_TEST_ASSERT_MSG_EQ (target.IsEnabledChildSelector(), child, "Interest Header childselector deserialization failed");
Ilya Moiseenko3e15eff2011-08-30 13:33:09 -0700104
Alexander Afanasyev864522f2012-05-31 13:33:57 -0700105 NS_TEST_ASSERT_MSG_EQ (target.GetExclude(), *exclude, "Interest Header exclude deserialization failed");
Ilya Moiseenko3e15eff2011-08-30 13:33:09 -0700106
Alexander Afanasyev864522f2012-05-31 13:33:57 -0700107 NS_TEST_ASSERT_MSG_EQ (target.GetMaxSuffixComponents(), (int)maxSuffixComponents, "Interest Header maxSuffixComponents deserialization failed");
Ilya Moiseenko3e15eff2011-08-30 13:33:09 -0700108
Alexander Afanasyev864522f2012-05-31 13:33:57 -0700109 NS_TEST_ASSERT_MSG_EQ (target.GetMinSuffixComponents(), (int)minSuffixComponents, "Interest Header minSuffixComponents deserialization failed");
Ilya Moiseenko3e15eff2011-08-30 13:33:09 -0700110}
111
112class InterestHeaderSerializationTestSuite : public TestSuite
113{
114public:
Alexander Afanasyev864522f2012-05-31 13:33:57 -0700115 InterestHeaderSerializationTestSuite ();
Ilya Moiseenko3e15eff2011-08-30 13:33:09 -0700116};
117
118InterestHeaderSerializationTestSuite::InterestHeaderSerializationTestSuite ()
Alexander Afanasyev864522f2012-05-31 13:33:57 -0700119 : TestSuite ("interest-header-serialization-test-suite", UNIT)
Ilya Moiseenko3e15eff2011-08-30 13:33:09 -0700120{
Alexander Afanasyev864522f2012-05-31 13:33:57 -0700121 SetDataDir (NS_TEST_SOURCEDIR);
122 AddTestCase (new InterestHeaderSerializationTest);
Ilya Moiseenko3e15eff2011-08-30 13:33:09 -0700123}
124
125static InterestHeaderSerializationTestSuite suite;