blob: 2b595b1c666ed68681d66534a6813a34c365ab98 [file] [log] [blame]
Ilya Moiseenko74077042011-08-30 16:04:22 -07001#include "ns3/test.h"
2#include "ns3/annotated-topology-reader.h"
3#include "ns3/ccnx-interest-header.h"
4#include "ns3/uinteger.h"
5#include "ns3/random-variable.h"
6#include <limits>
7#include "ns3/ccnx-header-helper.h"
8#include "ns3/header.h"
9#include "ns3/ccnx-name-components.h"
10#include "ns3/nstime.h"
11#include "ns3/buffer.h"
12#include "ns3/log.h"
13
14using namespace ns3;
Alexander Afanasyev85a3bca2011-08-31 16:51:03 -070015#include <fstream>
Ilya Moiseenko74077042011-08-30 16:04:22 -070016
17NS_LOG_COMPONENT_DEFINE ("InterestHeaderExample");
18
19int
20main (int argc, char *argv[])
21{
Alexander Afanasyev85a3bca2011-08-31 16:51:03 -070022 LogComponentEnable ("InterestHeaderExample", LOG_ALL);
Alexander Afanasyeve91ab752011-08-31 19:13:40 -070023 LogComponentEnable ("Packet", LOG_ALL);
Alexander Afanasyev85a3bca2011-08-31 16:51:03 -070024
Ilya Moiseenko74077042011-08-30 16:04:22 -070025 NS_LOG_INFO ("Test started");
Alexander Afanasyev85a3bca2011-08-31 16:51:03 -070026
Alexander Afanasyeve91ab752011-08-31 19:13:40 -070027 Packet::EnablePrinting ();
28 Packet::EnableChecking ();
29 Packet packet (0);
30
Ilya Moiseenko74077042011-08-30 16:04:22 -070031 CcnxInterestHeader interestHeader;
Alexander Afanasyev85a3bca2011-08-31 16:51:03 -070032
33 Ptr<CcnxNameComponents> testname = Create<CcnxNameComponents> ();
34 (*testname) ("first") ("second");
Ilya Moiseenko74077042011-08-30 16:04:22 -070035 interestHeader.SetName(testname);
Alexander Afanasyev85a3bca2011-08-31 16:51:03 -070036
37 uint32_t minSuffixComponents = 20;
Ilya Moiseenko74077042011-08-30 16:04:22 -070038 interestHeader.SetMinSuffixComponents(minSuffixComponents);
Alexander Afanasyev85a3bca2011-08-31 16:51:03 -070039
40 uint32_t maxSuffixComponents = 40;
41 interestHeader.SetMaxSuffixComponents(maxSuffixComponents);
42
43 Time lifetime = Seconds(661777) + MicroSeconds(1234);
44 interestHeader.SetInterestLifetime(lifetime);
45
46 bool child = true;
47 interestHeader.SetChildSelector(child);
48
49 Ptr<CcnxNameComponents> exclude = Create<CcnxNameComponents> ();
50 (*exclude) ("exclude1") ("exclude2");
51 interestHeader.SetExclude(exclude);
52
53 UniformVariable random(1, std::numeric_limits<uint32_t>::max ());
54 uint32_t randomNonce = static_cast<uint32_t> (random.GetValue());
55 interestHeader.SetNonce(randomNonce);
Alexander Afanasyeve91ab752011-08-31 19:13:40 -070056 NS_LOG_INFO ("Source: \n" << interestHeader);
Ilya Moiseenko74077042011-08-30 16:04:22 -070057
Alexander Afanasyeve91ab752011-08-31 19:13:40 -070058 packet.AddHeader (interestHeader);
59 NS_LOG_INFO ("Deserialized packet: " << packet);
Alexander Afanasyev85a3bca2011-08-31 16:51:03 -070060
Alexander Afanasyeve91ab752011-08-31 19:13:40 -070061 NS_LOG_INFO ("Removing and deserializing individual headers");
Alexander Afanasyev85a3bca2011-08-31 16:51:03 -070062
Ilya Moiseenko74077042011-08-30 16:04:22 -070063 CcnxInterestHeader target;
Alexander Afanasyeve91ab752011-08-31 19:13:40 -070064 packet.RemoveHeader (target);
65
Alexander Afanasyev85a3bca2011-08-31 16:51:03 -070066 NS_LOG_INFO ("Target: \n" << target);
Alexander Afanasyeve91ab752011-08-31 19:13:40 -070067
68 return 0;
Alexander Afanasyev85a3bca2011-08-31 16:51:03 -070069}