blob: 6964440edc498fafae94d13df3e8e9ace4406091 [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"
31
32using namespace ns3;
Alexander Afanasyev85a3bca2011-08-31 16:51:03 -070033#include <fstream>
Ilya Moiseenko74077042011-08-30 16:04:22 -070034
35NS_LOG_COMPONENT_DEFINE ("InterestHeaderExample");
36
37int
38main (int argc, char *argv[])
39{
Alexander Afanasyev795f9b52011-11-21 11:47:35 -080040 // LogComponentEnable ("InterestHeaderExample", LOG_ALL);
41 // LogComponentEnable ("Packet", LOG_ALL);
Alexander Afanasyev85a3bca2011-08-31 16:51:03 -070042
Alexander Afanasyev795f9b52011-11-21 11:47:35 -080043 NS_LOG_INFO ("Test started");
Alexander Afanasyev85a3bca2011-08-31 16:51:03 -070044
Alexander Afanasyev795f9b52011-11-21 11:47:35 -080045 Packet::EnablePrinting ();
46 Packet::EnableChecking ();
47 Packet packet (0);
Alexander Afanasyeve91ab752011-08-31 19:13:40 -070048
Alexander Afanasyev795f9b52011-11-21 11:47:35 -080049 CcnxInterestHeader interestHeader;
Alexander Afanasyev85a3bca2011-08-31 16:51:03 -070050
Alexander Afanasyev795f9b52011-11-21 11:47:35 -080051 Ptr<CcnxNameComponents> testname = Create<CcnxNameComponents> ();
52 (*testname) ("first") ("second");
53 interestHeader.SetName(testname);
Alexander Afanasyev85a3bca2011-08-31 16:51:03 -070054
Alexander Afanasyev795f9b52011-11-21 11:47:35 -080055 uint32_t minSuffixComponents = 20;
56 interestHeader.SetMinSuffixComponents(minSuffixComponents);
Alexander Afanasyev85a3bca2011-08-31 16:51:03 -070057
Alexander Afanasyev795f9b52011-11-21 11:47:35 -080058 uint32_t maxSuffixComponents = 40;
59 interestHeader.SetMaxSuffixComponents(maxSuffixComponents);
Alexander Afanasyev85a3bca2011-08-31 16:51:03 -070060
Alexander Afanasyev795f9b52011-11-21 11:47:35 -080061 Time lifetime = Seconds(661777) + MicroSeconds(1234);
62 interestHeader.SetInterestLifetime(lifetime);
Alexander Afanasyev85a3bca2011-08-31 16:51:03 -070063
Alexander Afanasyev795f9b52011-11-21 11:47:35 -080064 bool child = true;
65 interestHeader.SetChildSelector(child);
Alexander Afanasyev85a3bca2011-08-31 16:51:03 -070066
Alexander Afanasyev795f9b52011-11-21 11:47:35 -080067 Ptr<CcnxNameComponents> exclude = Create<CcnxNameComponents> ();
68 (*exclude) ("exclude1") ("exclude2");
69 interestHeader.SetExclude(exclude);
Alexander Afanasyev85a3bca2011-08-31 16:51:03 -070070
Alexander Afanasyev795f9b52011-11-21 11:47:35 -080071 UniformVariable random(1, std::numeric_limits<uint32_t>::max ());
72 uint32_t randomNonce = static_cast<uint32_t> (random.GetValue());
73 interestHeader.SetNonce(randomNonce);
Ilya Moiseenko19dbcf32011-11-16 14:32:14 -080074
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080075 interestHeader.SetNack(CcnxInterestHeader::NACK_CONGESTION);
Alexander Afanasyev795f9b52011-11-21 11:47:35 -080076 NS_LOG_INFO ("Source: \n" << interestHeader);
Ilya Moiseenko74077042011-08-30 16:04:22 -070077
Alexander Afanasyev795f9b52011-11-21 11:47:35 -080078 packet.AddHeader (interestHeader);
79 NS_LOG_INFO ("Deserialized packet: " << packet);
Alexander Afanasyev85a3bca2011-08-31 16:51:03 -070080
Alexander Afanasyev795f9b52011-11-21 11:47:35 -080081 NS_LOG_INFO ("Removing and deserializing individual headers");
Alexander Afanasyev85a3bca2011-08-31 16:51:03 -070082
Alexander Afanasyev795f9b52011-11-21 11:47:35 -080083 CcnxInterestHeader target;
84 packet.RemoveHeader (target);
Alexander Afanasyeve91ab752011-08-31 19:13:40 -070085
Alexander Afanasyev795f9b52011-11-21 11:47:35 -080086 // NS_LOG_INFO ("Target: \n" << target);
Alexander Afanasyeve91ab752011-08-31 19:13:40 -070087
Alexander Afanasyev795f9b52011-11-21 11:47:35 -080088 return 0;
Alexander Afanasyev85a3bca2011-08-31 16:51:03 -070089}