blob: e068febaaaf0a9f6b1ac5982917f463fc5711ed0 [file] [log] [blame]
Alexander Afanasyev795f9b52011-11-21 11:47:35 -08001/* -*- 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 */
Ilya Moiseenko74077042011-08-30 16:04:22 -070019#include "ns3/test.h"
20#include "ns3/annotated-topology-reader.h"
21#include "ns3/ccnx-interest-header.h"
22#include "ns3/uinteger.h"
23#include "ns3/random-variable.h"
24#include <limits>
25#include "ns3/ccnx-header-helper.h"
26#include "ns3/header.h"
27#include "ns3/ccnx-name-components.h"
28#include "ns3/nstime.h"
29#include "ns3/buffer.h"
30#include "ns3/log.h"
Alexander Afanasyev8633d5d2011-12-12 18:02:31 -080031#include "ns3/packet.h"
Ilya Moiseenko74077042011-08-30 16:04:22 -070032
33using namespace ns3;
Alexander Afanasyev85a3bca2011-08-31 16:51:03 -070034#include <fstream>
Ilya Moiseenko74077042011-08-30 16:04:22 -070035
36NS_LOG_COMPONENT_DEFINE ("InterestHeaderExample");
37
38int
39main (int argc, char *argv[])
40{
Alexander Afanasyev795f9b52011-11-21 11:47:35 -080041 // LogComponentEnable ("InterestHeaderExample", LOG_ALL);
42 // LogComponentEnable ("Packet", LOG_ALL);
Alexander Afanasyev85a3bca2011-08-31 16:51:03 -070043
Alexander Afanasyev795f9b52011-11-21 11:47:35 -080044 NS_LOG_INFO ("Test started");
Alexander Afanasyev85a3bca2011-08-31 16:51:03 -070045
Alexander Afanasyev795f9b52011-11-21 11:47:35 -080046 Packet::EnablePrinting ();
47 Packet::EnableChecking ();
48 Packet packet (0);
Alexander Afanasyeve91ab752011-08-31 19:13:40 -070049
Alexander Afanasyev795f9b52011-11-21 11:47:35 -080050 CcnxInterestHeader interestHeader;
Alexander Afanasyev85a3bca2011-08-31 16:51:03 -070051
Alexander Afanasyev795f9b52011-11-21 11:47:35 -080052 Ptr<CcnxNameComponents> testname = Create<CcnxNameComponents> ();
53 (*testname) ("first") ("second");
54 interestHeader.SetName(testname);
Alexander Afanasyev85a3bca2011-08-31 16:51:03 -070055
Alexander Afanasyev795f9b52011-11-21 11:47:35 -080056 uint32_t minSuffixComponents = 20;
57 interestHeader.SetMinSuffixComponents(minSuffixComponents);
Alexander Afanasyev85a3bca2011-08-31 16:51:03 -070058
Alexander Afanasyev795f9b52011-11-21 11:47:35 -080059 uint32_t maxSuffixComponents = 40;
60 interestHeader.SetMaxSuffixComponents(maxSuffixComponents);
Alexander Afanasyev85a3bca2011-08-31 16:51:03 -070061
Alexander Afanasyev795f9b52011-11-21 11:47:35 -080062 Time lifetime = Seconds(661777) + MicroSeconds(1234);
63 interestHeader.SetInterestLifetime(lifetime);
Alexander Afanasyev85a3bca2011-08-31 16:51:03 -070064
Alexander Afanasyev795f9b52011-11-21 11:47:35 -080065 bool child = true;
66 interestHeader.SetChildSelector(child);
Alexander Afanasyev85a3bca2011-08-31 16:51:03 -070067
Alexander Afanasyev795f9b52011-11-21 11:47:35 -080068 Ptr<CcnxNameComponents> exclude = Create<CcnxNameComponents> ();
69 (*exclude) ("exclude1") ("exclude2");
70 interestHeader.SetExclude(exclude);
Alexander Afanasyev85a3bca2011-08-31 16:51:03 -070071
Alexander Afanasyev795f9b52011-11-21 11:47:35 -080072 UniformVariable random(1, std::numeric_limits<uint32_t>::max ());
73 uint32_t randomNonce = static_cast<uint32_t> (random.GetValue());
74 interestHeader.SetNonce(randomNonce);
Ilya Moiseenko19dbcf32011-11-16 14:32:14 -080075
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080076 interestHeader.SetNack(CcnxInterestHeader::NACK_CONGESTION);
Alexander Afanasyev795f9b52011-11-21 11:47:35 -080077 NS_LOG_INFO ("Source: \n" << interestHeader);
Ilya Moiseenko74077042011-08-30 16:04:22 -070078
Alexander Afanasyev795f9b52011-11-21 11:47:35 -080079 packet.AddHeader (interestHeader);
80 NS_LOG_INFO ("Deserialized packet: " << packet);
Alexander Afanasyev85a3bca2011-08-31 16:51:03 -070081
Alexander Afanasyev795f9b52011-11-21 11:47:35 -080082 NS_LOG_INFO ("Removing and deserializing individual headers");
Alexander Afanasyev85a3bca2011-08-31 16:51:03 -070083
Alexander Afanasyev795f9b52011-11-21 11:47:35 -080084 CcnxInterestHeader target;
85 packet.RemoveHeader (target);
Alexander Afanasyeve91ab752011-08-31 19:13:40 -070086
Alexander Afanasyev795f9b52011-11-21 11:47:35 -080087 // NS_LOG_INFO ("Target: \n" << target);
Alexander Afanasyeve91ab752011-08-31 19:13:40 -070088
Alexander Afanasyev795f9b52011-11-21 11:47:35 -080089 return 0;
Alexander Afanasyev85a3bca2011-08-31 16:51:03 -070090}