Alexander Afanasyev | 795f9b5 | 2011-11-21 11:47:35 -0800 | [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 | * |
| 18 | */ |
Ilya Moiseenko | 7407704 | 2011-08-30 16:04:22 -0700 | [diff] [blame] | 19 | #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 | |
| 32 | using namespace ns3; |
Alexander Afanasyev | 85a3bca | 2011-08-31 16:51:03 -0700 | [diff] [blame] | 33 | #include <fstream> |
Ilya Moiseenko | 7407704 | 2011-08-30 16:04:22 -0700 | [diff] [blame] | 34 | |
| 35 | NS_LOG_COMPONENT_DEFINE ("InterestHeaderExample"); |
| 36 | |
| 37 | int |
| 38 | main (int argc, char *argv[]) |
| 39 | { |
Alexander Afanasyev | 795f9b5 | 2011-11-21 11:47:35 -0800 | [diff] [blame] | 40 | // LogComponentEnable ("InterestHeaderExample", LOG_ALL); |
| 41 | // LogComponentEnable ("Packet", LOG_ALL); |
Alexander Afanasyev | 85a3bca | 2011-08-31 16:51:03 -0700 | [diff] [blame] | 42 | |
Alexander Afanasyev | 795f9b5 | 2011-11-21 11:47:35 -0800 | [diff] [blame] | 43 | NS_LOG_INFO ("Test started"); |
Alexander Afanasyev | 85a3bca | 2011-08-31 16:51:03 -0700 | [diff] [blame] | 44 | |
Alexander Afanasyev | 795f9b5 | 2011-11-21 11:47:35 -0800 | [diff] [blame] | 45 | Packet::EnablePrinting (); |
| 46 | Packet::EnableChecking (); |
| 47 | Packet packet (0); |
Alexander Afanasyev | e91ab75 | 2011-08-31 19:13:40 -0700 | [diff] [blame] | 48 | |
Alexander Afanasyev | 795f9b5 | 2011-11-21 11:47:35 -0800 | [diff] [blame] | 49 | CcnxInterestHeader interestHeader; |
Alexander Afanasyev | 85a3bca | 2011-08-31 16:51:03 -0700 | [diff] [blame] | 50 | |
Alexander Afanasyev | 795f9b5 | 2011-11-21 11:47:35 -0800 | [diff] [blame] | 51 | Ptr<CcnxNameComponents> testname = Create<CcnxNameComponents> (); |
| 52 | (*testname) ("first") ("second"); |
| 53 | interestHeader.SetName(testname); |
Alexander Afanasyev | 85a3bca | 2011-08-31 16:51:03 -0700 | [diff] [blame] | 54 | |
Alexander Afanasyev | 795f9b5 | 2011-11-21 11:47:35 -0800 | [diff] [blame] | 55 | uint32_t minSuffixComponents = 20; |
| 56 | interestHeader.SetMinSuffixComponents(minSuffixComponents); |
Alexander Afanasyev | 85a3bca | 2011-08-31 16:51:03 -0700 | [diff] [blame] | 57 | |
Alexander Afanasyev | 795f9b5 | 2011-11-21 11:47:35 -0800 | [diff] [blame] | 58 | uint32_t maxSuffixComponents = 40; |
| 59 | interestHeader.SetMaxSuffixComponents(maxSuffixComponents); |
Alexander Afanasyev | 85a3bca | 2011-08-31 16:51:03 -0700 | [diff] [blame] | 60 | |
Alexander Afanasyev | 795f9b5 | 2011-11-21 11:47:35 -0800 | [diff] [blame] | 61 | Time lifetime = Seconds(661777) + MicroSeconds(1234); |
| 62 | interestHeader.SetInterestLifetime(lifetime); |
Alexander Afanasyev | 85a3bca | 2011-08-31 16:51:03 -0700 | [diff] [blame] | 63 | |
Alexander Afanasyev | 795f9b5 | 2011-11-21 11:47:35 -0800 | [diff] [blame] | 64 | bool child = true; |
| 65 | interestHeader.SetChildSelector(child); |
Alexander Afanasyev | 85a3bca | 2011-08-31 16:51:03 -0700 | [diff] [blame] | 66 | |
Alexander Afanasyev | 795f9b5 | 2011-11-21 11:47:35 -0800 | [diff] [blame] | 67 | Ptr<CcnxNameComponents> exclude = Create<CcnxNameComponents> (); |
| 68 | (*exclude) ("exclude1") ("exclude2"); |
| 69 | interestHeader.SetExclude(exclude); |
Alexander Afanasyev | 85a3bca | 2011-08-31 16:51:03 -0700 | [diff] [blame] | 70 | |
Alexander Afanasyev | 795f9b5 | 2011-11-21 11:47:35 -0800 | [diff] [blame] | 71 | UniformVariable random(1, std::numeric_limits<uint32_t>::max ()); |
| 72 | uint32_t randomNonce = static_cast<uint32_t> (random.GetValue()); |
| 73 | interestHeader.SetNonce(randomNonce); |
Ilya Moiseenko | 19dbcf3 | 2011-11-16 14:32:14 -0800 | [diff] [blame] | 74 | |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame] | 75 | interestHeader.SetNack(CcnxInterestHeader::NACK_CONGESTION); |
Alexander Afanasyev | 795f9b5 | 2011-11-21 11:47:35 -0800 | [diff] [blame] | 76 | NS_LOG_INFO ("Source: \n" << interestHeader); |
Ilya Moiseenko | 7407704 | 2011-08-30 16:04:22 -0700 | [diff] [blame] | 77 | |
Alexander Afanasyev | 795f9b5 | 2011-11-21 11:47:35 -0800 | [diff] [blame] | 78 | packet.AddHeader (interestHeader); |
| 79 | NS_LOG_INFO ("Deserialized packet: " << packet); |
Alexander Afanasyev | 85a3bca | 2011-08-31 16:51:03 -0700 | [diff] [blame] | 80 | |
Alexander Afanasyev | 795f9b5 | 2011-11-21 11:47:35 -0800 | [diff] [blame] | 81 | NS_LOG_INFO ("Removing and deserializing individual headers"); |
Alexander Afanasyev | 85a3bca | 2011-08-31 16:51:03 -0700 | [diff] [blame] | 82 | |
Alexander Afanasyev | 795f9b5 | 2011-11-21 11:47:35 -0800 | [diff] [blame] | 83 | CcnxInterestHeader target; |
| 84 | packet.RemoveHeader (target); |
Alexander Afanasyev | e91ab75 | 2011-08-31 19:13:40 -0700 | [diff] [blame] | 85 | |
Alexander Afanasyev | 795f9b5 | 2011-11-21 11:47:35 -0800 | [diff] [blame] | 86 | // NS_LOG_INFO ("Target: \n" << target); |
Alexander Afanasyev | e91ab75 | 2011-08-31 19:13:40 -0700 | [diff] [blame] | 87 | |
Alexander Afanasyev | 795f9b5 | 2011-11-21 11:47:35 -0800 | [diff] [blame] | 88 | return 0; |
Alexander Afanasyev | 85a3bca | 2011-08-31 16:51:03 -0700 | [diff] [blame] | 89 | } |