Ilya Moiseenko | 7407704 | 2011-08-30 16:04:22 -0700 | [diff] [blame] | 1 | #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 | |
| 14 | using namespace ns3; |
Alexander Afanasyev | 85a3bca | 2011-08-31 16:51:03 -0700 | [diff] [blame] | 15 | #include <fstream> |
Ilya Moiseenko | 7407704 | 2011-08-30 16:04:22 -0700 | [diff] [blame] | 16 | |
| 17 | NS_LOG_COMPONENT_DEFINE ("InterestHeaderExample"); |
| 18 | |
| 19 | int |
| 20 | main (int argc, char *argv[]) |
| 21 | { |
Alexander Afanasyev | 85a3bca | 2011-08-31 16:51:03 -0700 | [diff] [blame] | 22 | LogComponentEnable ("InterestHeaderExample", LOG_ALL); |
Alexander Afanasyev | e91ab75 | 2011-08-31 19:13:40 -0700 | [diff] [blame] | 23 | LogComponentEnable ("Packet", LOG_ALL); |
Alexander Afanasyev | 85a3bca | 2011-08-31 16:51:03 -0700 | [diff] [blame] | 24 | |
Ilya Moiseenko | 7407704 | 2011-08-30 16:04:22 -0700 | [diff] [blame] | 25 | NS_LOG_INFO ("Test started"); |
Alexander Afanasyev | 85a3bca | 2011-08-31 16:51:03 -0700 | [diff] [blame] | 26 | |
Alexander Afanasyev | e91ab75 | 2011-08-31 19:13:40 -0700 | [diff] [blame] | 27 | Packet::EnablePrinting (); |
| 28 | Packet::EnableChecking (); |
| 29 | Packet packet (0); |
| 30 | |
Ilya Moiseenko | 7407704 | 2011-08-30 16:04:22 -0700 | [diff] [blame] | 31 | CcnxInterestHeader interestHeader; |
Alexander Afanasyev | 85a3bca | 2011-08-31 16:51:03 -0700 | [diff] [blame] | 32 | |
| 33 | Ptr<CcnxNameComponents> testname = Create<CcnxNameComponents> (); |
| 34 | (*testname) ("first") ("second"); |
Ilya Moiseenko | 7407704 | 2011-08-30 16:04:22 -0700 | [diff] [blame] | 35 | interestHeader.SetName(testname); |
Alexander Afanasyev | 85a3bca | 2011-08-31 16:51:03 -0700 | [diff] [blame] | 36 | |
| 37 | uint32_t minSuffixComponents = 20; |
Ilya Moiseenko | 7407704 | 2011-08-30 16:04:22 -0700 | [diff] [blame] | 38 | interestHeader.SetMinSuffixComponents(minSuffixComponents); |
Alexander Afanasyev | 85a3bca | 2011-08-31 16:51:03 -0700 | [diff] [blame] | 39 | |
| 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 Afanasyev | e91ab75 | 2011-08-31 19:13:40 -0700 | [diff] [blame] | 56 | NS_LOG_INFO ("Source: \n" << interestHeader); |
Ilya Moiseenko | 7407704 | 2011-08-30 16:04:22 -0700 | [diff] [blame] | 57 | |
Alexander Afanasyev | e91ab75 | 2011-08-31 19:13:40 -0700 | [diff] [blame] | 58 | packet.AddHeader (interestHeader); |
| 59 | NS_LOG_INFO ("Deserialized packet: " << packet); |
Alexander Afanasyev | 85a3bca | 2011-08-31 16:51:03 -0700 | [diff] [blame] | 60 | |
Alexander Afanasyev | e91ab75 | 2011-08-31 19:13:40 -0700 | [diff] [blame] | 61 | NS_LOG_INFO ("Removing and deserializing individual headers"); |
Alexander Afanasyev | 85a3bca | 2011-08-31 16:51:03 -0700 | [diff] [blame] | 62 | |
Ilya Moiseenko | 7407704 | 2011-08-30 16:04:22 -0700 | [diff] [blame] | 63 | CcnxInterestHeader target; |
Alexander Afanasyev | e91ab75 | 2011-08-31 19:13:40 -0700 | [diff] [blame] | 64 | packet.RemoveHeader (target); |
| 65 | |
Alexander Afanasyev | 85a3bca | 2011-08-31 16:51:03 -0700 | [diff] [blame] | 66 | NS_LOG_INFO ("Target: \n" << target); |
Alexander Afanasyev | e91ab75 | 2011-08-31 19:13:40 -0700 | [diff] [blame] | 67 | |
| 68 | return 0; |
Alexander Afanasyev | 85a3bca | 2011-08-31 16:51:03 -0700 | [diff] [blame] | 69 | } |