Alexander Afanasyev | f1e013f | 2012-07-11 17:59:40 -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 | * |
Alexander Afanasyev | cf6dc92 | 2012-08-10 16:55:27 -0700 | [diff] [blame] | 18 | * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu> |
| 19 | * Ilya Moiseenko <iliamo@cs.ucla.edu> |
Alexander Afanasyev | f1e013f | 2012-07-11 17:59:40 -0700 | [diff] [blame] | 20 | */ |
| 21 | |
| 22 | #include "ns3/core-module.h" |
| 23 | #include "ns3/ndnSIM-module.h" |
| 24 | #include "ndnSIM-serialization.h" |
| 25 | |
| 26 | #include <boost/lexical_cast.hpp> |
| 27 | |
| 28 | using namespace std; |
| 29 | |
Alexander Afanasyev | cf6dc92 | 2012-08-10 16:55:27 -0700 | [diff] [blame] | 30 | namespace ns3 { |
| 31 | |
| 32 | using namespace ndn; |
Alexander Afanasyev | f1e013f | 2012-07-11 17:59:40 -0700 | [diff] [blame] | 33 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 34 | NS_LOG_COMPONENT_DEFINE ("ndn.Serialization"); |
Alexander Afanasyev | f1e013f | 2012-07-11 17:59:40 -0700 | [diff] [blame] | 35 | |
| 36 | void |
| 37 | InterestSerializationTest::DoRun () |
| 38 | { |
Alexander Afanasyev | cf6dc92 | 2012-08-10 16:55:27 -0700 | [diff] [blame] | 39 | InterestHeader source; |
Alexander Afanasyev | bd9c18e | 2012-11-19 15:23:41 -0800 | [diff] [blame] | 40 | |
| 41 | source.SetName (Create<NameComponents> (boost::lexical_cast<NameComponents> ("/test/test2"))); |
Alexander Afanasyev | cf6dc92 | 2012-08-10 16:55:27 -0700 | [diff] [blame] | 42 | NS_TEST_ASSERT_MSG_EQ (source.GetName (), boost::lexical_cast<NameComponents> ("/test/test2"), "set/get name failed"); |
Alexander Afanasyev | f1e013f | 2012-07-11 17:59:40 -0700 | [diff] [blame] | 43 | |
Alexander Afanasyev | f1e013f | 2012-07-11 17:59:40 -0700 | [diff] [blame] | 44 | source.SetScope (2); |
| 45 | NS_TEST_ASSERT_MSG_EQ (source.GetScope (), 2, "set/get scope failed"); |
| 46 | |
| 47 | source.SetInterestLifetime (Seconds (100)); |
| 48 | NS_TEST_ASSERT_MSG_EQ (source.GetInterestLifetime (), Seconds (100), "set/get interest lifetime failed"); |
| 49 | |
| 50 | source.SetNonce (200); |
| 51 | NS_TEST_ASSERT_MSG_EQ (source.GetNonce (), 200, "set/get nonce failed"); |
| 52 | |
| 53 | source.SetNack (10); |
| 54 | NS_TEST_ASSERT_MSG_EQ (source.GetNack (), 10, "set/get NACK failed"); |
| 55 | |
| 56 | Packet packet (0); |
| 57 | //serialization |
| 58 | packet.AddHeader (source); |
| 59 | |
| 60 | //deserialization |
Alexander Afanasyev | cf6dc92 | 2012-08-10 16:55:27 -0700 | [diff] [blame] | 61 | InterestHeader target; |
Alexander Afanasyev | f1e013f | 2012-07-11 17:59:40 -0700 | [diff] [blame] | 62 | packet.RemoveHeader (target); |
| 63 | |
Alexander Afanasyev | bd9c18e | 2012-11-19 15:23:41 -0800 | [diff] [blame] | 64 | NS_TEST_ASSERT_MSG_EQ (source.GetName () , target.GetName () , "source/target name failed"); |
| 65 | NS_TEST_ASSERT_MSG_EQ (source.GetScope () , target.GetScope () , "source/target scope failed"); |
| 66 | NS_TEST_ASSERT_MSG_EQ (source.GetInterestLifetime (), target.GetInterestLifetime (), "source/target interest lifetime failed"); |
| 67 | NS_TEST_ASSERT_MSG_EQ (source.GetNonce () , target.GetNonce () , "source/target nonce failed"); |
| 68 | NS_TEST_ASSERT_MSG_EQ (source.GetNack () , target.GetNack () , "source/target NACK failed"); |
Alexander Afanasyev | f1e013f | 2012-07-11 17:59:40 -0700 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | void |
| 72 | ContentObjectSerializationTest::DoRun () |
| 73 | { |
Alexander Afanasyev | 11fdadd | 2012-11-19 15:43:17 -0800 | [diff] [blame] | 74 | ContentObjectHeader source; |
| 75 | |
| 76 | source.SetName (Create<NameComponents> (boost::lexical_cast<NameComponents> ("/test/test2/1"))); |
| 77 | NS_TEST_ASSERT_MSG_EQ (source.GetName (), boost::lexical_cast<NameComponents> ("/test/test2/1"), "set/get name failed"); |
| 78 | |
| 79 | source.SetFreshness (Seconds (10)); |
| 80 | NS_TEST_ASSERT_MSG_EQ (source.GetFreshness (), Seconds (10), "set/get freshness failed"); |
| 81 | |
| 82 | source.SetTimestamp (Seconds (100)); |
| 83 | NS_TEST_ASSERT_MSG_EQ (source.GetTimestamp (), Seconds (100), "set/get timestamp failed"); |
| 84 | |
| 85 | Packet packet (0); |
| 86 | //serialization |
| 87 | packet.AddHeader (source); |
| 88 | |
| 89 | //deserialization |
| 90 | ContentObjectHeader target; |
| 91 | packet.RemoveHeader (target); |
| 92 | |
| 93 | NS_TEST_ASSERT_MSG_EQ (source.GetName () , target.GetName () , "source/target name failed"); |
| 94 | NS_TEST_ASSERT_MSG_EQ (source.GetFreshness (), target.GetFreshness (), "source/target freshness failed"); |
| 95 | NS_TEST_ASSERT_MSG_EQ (source.GetTimestamp (), target.GetTimestamp (), "source/target timestamp failed"); |
Alexander Afanasyev | f1e013f | 2012-07-11 17:59:40 -0700 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | } |