blob: 041cac60fac0a8e80c40861a47651cfd9f463be7 [file] [log] [blame]
Alexander Afanasyevc39f0b42011-11-28 12:51:12 -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 * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
19 */
20
21#include "ns3/core-module.h"
22#include "ns3/ccnx-content-object-header.h"
23#include "ns3/ccnx-interest-header.h"
24#include "ns3/ccnx-header-helper.h"
25#include "ns3/header.h"
26#include "ns3/ccnx-name-components.h"
27#include "ns3/nstime.h"
28#include "ns3/string.h"
29#include "ns3/buffer.h"
30#include "ns3/packet.h"
31#include "ns3/log.h"
32
33using namespace ns3;
34#include <fstream>
35
36NS_LOG_COMPONENT_DEFINE ("PacketSizes");
37
38int
39main (int argc, char *argv[])
40{
41 NS_LOG_INFO ("Test started");
42
43 uint32_t size = 1024;
44 std::string namePrefixStr = "/1";
45 uint32_t start=0, end=100;
46
47 CommandLine cmd;
48 cmd.AddValue ("size", "ContentObject payload size", size);
49 cmd.AddValue ("name", "Prefix", namePrefixStr);
50 cmd.AddValue ("start", "Range start", start);
51 cmd.AddValue ("end", "Range end", end);
52 cmd.Parse (argc, argv);
53
54 CcnxNameComponents namePrefixValue;
55 std::istringstream is (namePrefixStr);
56 is >> namePrefixValue;
57
58 Packet::EnablePrinting ();
59 Packet::EnableChecking ();
60
61 double interestSize = 0.0;
62 double nackSize = 0.0;
63 double contentObjectSize = 0.0;
64
65 double progress = start;
66 double step = (end-start)/100.0;
67
68 progress += step;
69
70 NS_LOG_INFO (progress << ", " << step);
71
72 for (uint32_t currentSize = start; currentSize < end; currentSize++)
73 {
74 Ptr<CcnxNameComponents> namePrefix = Create<CcnxNameComponents> (namePrefixValue);
75 namePrefix->Add (currentSize);
76
77 NS_LOG_LOGIC (boost::cref (*namePrefix));
78
79 // Interest Packet (doesn't have a payload)
80 CcnxInterestHeader interestHeader;
81
82 interestHeader.SetName (namePrefix);
83 interestHeader.SetInterestLifetime (Seconds (4.0));
84 interestHeader.SetNonce (10101010);
85
86 Ptr<Packet> interestPacket = Create<Packet> (0);
87 interestPacket->AddHeader (interestHeader);
88
89 interestSize = interestSize + (1.0*interestPacket->GetSize () - interestSize) / (currentSize - start + 1);
90
91
92
93 // NACK
94 interestHeader.SetNack (CcnxInterestHeader::NACK_GIVEUP_PIT);
95
96 Ptr<Packet> nackPacket = Create<Packet> (0);
97 nackPacket->AddHeader (interestHeader);
98
99 nackSize = nackSize + (1.0*nackPacket->GetSize () - nackSize) / (currentSize - start + 1);
100
101 // ContentObject
102 CcnxContentObjectHeader coHeader;
103 CcnxContentObjectTail coTrailer;
104
105 coHeader.SetName (namePrefix);
106
107 Ptr<Packet> contentObject = Create<Packet> (size);
108
109 contentObject->AddHeader (coHeader);
110 contentObject->AddTrailer (coTrailer);
111
112 contentObjectSize = contentObjectSize + (1.0*contentObject->GetSize () - contentObjectSize ) / (currentSize - start + 1);
113
114 NS_LOG_DEBUG (interestSize << ", " << nackSize << ", " << contentObjectSize);
115
116 if (currentSize >= progress)
117 {
118 NS_LOG_INFO ("Current: " << currentSize << "/" << end);
119 progress += step;
120 }
121 }
122
123 NS_LOG_INFO ("Avg interest: " << interestSize << ", avg nack: " << nackSize << ", avg contentObject: " << contentObjectSize);
124
125 return 0;
126}