blob: 5c73bfcaccf0e8b7b044c2acda7f6cc0bc950289 [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"
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -080033#include "ns3/packet.h"
Ilya Moiseenko3e15eff2011-08-30 13:33:09 -070034
Ilya Moiseenkoa828e9f2011-08-31 11:04:00 -070035#include <iostream>
36#include <fstream>
37#include <sstream>
38
Ilya Moiseenko3e15eff2011-08-30 13:33:09 -070039using namespace ns3;
Ilya Moiseenkoa828e9f2011-08-31 11:04:00 -070040using namespace std;
Ilya Moiseenko3e15eff2011-08-30 13:33:09 -070041
42NS_LOG_COMPONENT_DEFINE ("InterestHeaderSerializationTest");
43
44class InterestHeaderSerializationTest : public TestCase
45{
46public:
Ilya Moiseenko3e15eff2011-08-30 13:33:09 -070047 InterestHeaderSerializationTest ();
48 virtual ~InterestHeaderSerializationTest ();
49
Ilya Moiseenko3e15eff2011-08-30 13:33:09 -070050private:
51 virtual void DoRun (void);
52};
53
54InterestHeaderSerializationTest::InterestHeaderSerializationTest ()
55: TestCase ("Interest Header Serialization Test")
56{
57}
58
59InterestHeaderSerializationTest::~InterestHeaderSerializationTest ()
60{
61}
62
63void
64InterestHeaderSerializationTest::DoRun(void)
65{
Ilya Moiseenko08723712011-09-01 17:42:12 -070066 Packet packet (0);
Ilya Moiseenkoa828e9f2011-08-31 11:04:00 -070067
Ilya Moiseenko3e15eff2011-08-30 13:33:09 -070068 uint32_t randomNonce = UniformVariable().GetInteger(1, std::numeric_limits<uint32_t>::max ());
69 Ptr<CcnxNameComponents> testname = Create<CcnxNameComponents> ();
70 (*testname) ("test") ("test2");
71
72 Ptr<CcnxNameComponents> exclude = Create<CcnxNameComponents> ();
Ilya Moiseenkoa828e9f2011-08-31 11:04:00 -070073 (*exclude) ("exclude") ("exclude2");
Ilya Moiseenko3e15eff2011-08-30 13:33:09 -070074
75 Time lifetime = Seconds(4.0);
76 bool child = true;
77
78 uint32_t maxSuffixComponents = 40;
79 uint32_t minSuffixComponents = 20;
80
81 CcnxInterestHeader interestHeader;
82 interestHeader.SetNonce(randomNonce);
83 interestHeader.SetName(testname);
84 interestHeader.SetInterestLifetime(lifetime);
85 interestHeader.SetChildSelector(child);
86 interestHeader.SetExclude(exclude);
87 interestHeader.SetMaxSuffixComponents(maxSuffixComponents);
88 interestHeader.SetMinSuffixComponents(minSuffixComponents);
89
Ilya Moiseenko08723712011-09-01 17:42:12 -070090 //serialization
91 packet.AddHeader (interestHeader);
92
93 //deserialization
Ilya Moiseenko3e15eff2011-08-30 13:33:09 -070094 CcnxInterestHeader target;
Ilya Moiseenko08723712011-09-01 17:42:12 -070095 packet.RemoveHeader (target);
96
Ilya Moiseenko3e15eff2011-08-30 13:33:09 -070097
Ilya Moiseenko3e15eff2011-08-30 13:33:09 -070098 NS_TEST_ASSERT_MSG_EQ (target.GetNonce(), randomNonce, "Interest Header nonce deserialization failed");
99
Ilya Moiseenkoa828e9f2011-08-31 11:04:00 -0700100 NS_TEST_ASSERT_MSG_EQ (target.GetName(), *testname, "Interest Header name deserialization failed");
Ilya Moiseenko3e15eff2011-08-30 13:33:09 -0700101
102 NS_TEST_ASSERT_MSG_EQ (target.GetInterestLifetime(), lifetime, "Interest Header lifetime deserialization failed");
103
Ilya Moiseenkoa828e9f2011-08-31 11:04:00 -0700104 NS_TEST_ASSERT_MSG_EQ (target.IsEnabledChildSelector(), child, "Interest Header childselector deserialization failed");
Ilya Moiseenko3e15eff2011-08-30 13:33:09 -0700105
Ilya Moiseenkoa828e9f2011-08-31 11:04:00 -0700106 NS_TEST_ASSERT_MSG_EQ (target.GetExclude(), *exclude, "Interest Header exclude deserialization failed");
Ilya Moiseenko3e15eff2011-08-30 13:33:09 -0700107
108 NS_TEST_ASSERT_MSG_EQ (target.GetMaxSuffixComponents(), (int)maxSuffixComponents, "Interest Header maxSuffixComponents deserialization failed");
109
110 NS_TEST_ASSERT_MSG_EQ (target.GetMinSuffixComponents(), (int)minSuffixComponents, "Interest Header minSuffixComponents deserialization failed");
111}
112
113class InterestHeaderSerializationTestSuite : public TestSuite
114{
115public:
116 InterestHeaderSerializationTestSuite ();
117};
118
119InterestHeaderSerializationTestSuite::InterestHeaderSerializationTestSuite ()
120: TestSuite ("interest-header-serialization-test-suite", UNIT)
121{
Ilya Moiseenkoa828e9f2011-08-31 11:04:00 -0700122 SetDataDir (NS_TEST_SOURCEDIR);
Ilya Moiseenko3e15eff2011-08-30 13:33:09 -0700123 AddTestCase (new InterestHeaderSerializationTest);
124}
125
126static InterestHeaderSerializationTestSuite suite;