Ilya Moiseenko | a828e9f | 2011-08-31 11:04:00 -0700 | [diff] [blame] | 1 | /* -*- 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 Moiseenko | 3e15eff | 2011-08-30 13:33:09 -0700 | [diff] [blame] | 21 | #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 Afanasyev | e9c9d72 | 2012-01-19 16:59:30 -0800 | [diff] [blame] | 33 | #include "ns3/packet.h" |
Ilya Moiseenko | 3e15eff | 2011-08-30 13:33:09 -0700 | [diff] [blame] | 34 | |
Ilya Moiseenko | a828e9f | 2011-08-31 11:04:00 -0700 | [diff] [blame] | 35 | #include <iostream> |
| 36 | #include <fstream> |
| 37 | #include <sstream> |
| 38 | |
Ilya Moiseenko | 3e15eff | 2011-08-30 13:33:09 -0700 | [diff] [blame] | 39 | using namespace ns3; |
Ilya Moiseenko | a828e9f | 2011-08-31 11:04:00 -0700 | [diff] [blame] | 40 | using namespace std; |
Ilya Moiseenko | 3e15eff | 2011-08-30 13:33:09 -0700 | [diff] [blame] | 41 | |
| 42 | NS_LOG_COMPONENT_DEFINE ("InterestHeaderSerializationTest"); |
| 43 | |
| 44 | class InterestHeaderSerializationTest : public TestCase |
| 45 | { |
| 46 | public: |
Ilya Moiseenko | 3e15eff | 2011-08-30 13:33:09 -0700 | [diff] [blame] | 47 | InterestHeaderSerializationTest (); |
| 48 | virtual ~InterestHeaderSerializationTest (); |
| 49 | |
Ilya Moiseenko | 3e15eff | 2011-08-30 13:33:09 -0700 | [diff] [blame] | 50 | private: |
| 51 | virtual void DoRun (void); |
| 52 | }; |
| 53 | |
| 54 | InterestHeaderSerializationTest::InterestHeaderSerializationTest () |
| 55 | : TestCase ("Interest Header Serialization Test") |
| 56 | { |
| 57 | } |
| 58 | |
| 59 | InterestHeaderSerializationTest::~InterestHeaderSerializationTest () |
| 60 | { |
| 61 | } |
| 62 | |
| 63 | void |
| 64 | InterestHeaderSerializationTest::DoRun(void) |
| 65 | { |
Ilya Moiseenko | 0872371 | 2011-09-01 17:42:12 -0700 | [diff] [blame] | 66 | Packet packet (0); |
Ilya Moiseenko | a828e9f | 2011-08-31 11:04:00 -0700 | [diff] [blame] | 67 | |
Ilya Moiseenko | 3e15eff | 2011-08-30 13:33:09 -0700 | [diff] [blame] | 68 | 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 Moiseenko | a828e9f | 2011-08-31 11:04:00 -0700 | [diff] [blame] | 73 | (*exclude) ("exclude") ("exclude2"); |
Ilya Moiseenko | 3e15eff | 2011-08-30 13:33:09 -0700 | [diff] [blame] | 74 | |
| 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 Moiseenko | 0872371 | 2011-09-01 17:42:12 -0700 | [diff] [blame] | 90 | //serialization |
| 91 | packet.AddHeader (interestHeader); |
| 92 | |
| 93 | //deserialization |
Ilya Moiseenko | 3e15eff | 2011-08-30 13:33:09 -0700 | [diff] [blame] | 94 | CcnxInterestHeader target; |
Ilya Moiseenko | 0872371 | 2011-09-01 17:42:12 -0700 | [diff] [blame] | 95 | packet.RemoveHeader (target); |
| 96 | |
Ilya Moiseenko | 3e15eff | 2011-08-30 13:33:09 -0700 | [diff] [blame] | 97 | |
Ilya Moiseenko | 3e15eff | 2011-08-30 13:33:09 -0700 | [diff] [blame] | 98 | NS_TEST_ASSERT_MSG_EQ (target.GetNonce(), randomNonce, "Interest Header nonce deserialization failed"); |
| 99 | |
Ilya Moiseenko | a828e9f | 2011-08-31 11:04:00 -0700 | [diff] [blame] | 100 | NS_TEST_ASSERT_MSG_EQ (target.GetName(), *testname, "Interest Header name deserialization failed"); |
Ilya Moiseenko | 3e15eff | 2011-08-30 13:33:09 -0700 | [diff] [blame] | 101 | |
| 102 | NS_TEST_ASSERT_MSG_EQ (target.GetInterestLifetime(), lifetime, "Interest Header lifetime deserialization failed"); |
| 103 | |
Ilya Moiseenko | a828e9f | 2011-08-31 11:04:00 -0700 | [diff] [blame] | 104 | NS_TEST_ASSERT_MSG_EQ (target.IsEnabledChildSelector(), child, "Interest Header childselector deserialization failed"); |
Ilya Moiseenko | 3e15eff | 2011-08-30 13:33:09 -0700 | [diff] [blame] | 105 | |
Ilya Moiseenko | a828e9f | 2011-08-31 11:04:00 -0700 | [diff] [blame] | 106 | NS_TEST_ASSERT_MSG_EQ (target.GetExclude(), *exclude, "Interest Header exclude deserialization failed"); |
Ilya Moiseenko | 3e15eff | 2011-08-30 13:33:09 -0700 | [diff] [blame] | 107 | |
| 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 | |
| 113 | class InterestHeaderSerializationTestSuite : public TestSuite |
| 114 | { |
| 115 | public: |
| 116 | InterestHeaderSerializationTestSuite (); |
| 117 | }; |
| 118 | |
| 119 | InterestHeaderSerializationTestSuite::InterestHeaderSerializationTestSuite () |
| 120 | : TestSuite ("interest-header-serialization-test-suite", UNIT) |
| 121 | { |
Ilya Moiseenko | a828e9f | 2011-08-31 11:04:00 -0700 | [diff] [blame] | 122 | SetDataDir (NS_TEST_SOURCEDIR); |
Ilya Moiseenko | 3e15eff | 2011-08-30 13:33:09 -0700 | [diff] [blame] | 123 | AddTestCase (new InterestHeaderSerializationTest); |
| 124 | } |
| 125 | |
| 126 | static InterestHeaderSerializationTestSuite suite; |