author | Josh Pelkey <jpelkey@gatech.edu> |
Fri, 13 May 2011 14:51:11 -0400 | |
changeset 7166 | 2ea56ac66361 |
parent 6847 | 138f00c56381 |
child 7225 | 3b4d401c4a5b |
permissions | -rw-r--r-- |
4576
96811f76c3e2
remind v4ping.cc that echo data is variable length
Craig Dowell <craigdo@ee.washington.edu>
parents:
4521
diff
changeset
|
1 |
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
96811f76c3e2
remind v4ping.cc that echo data is variable length
Craig Dowell <craigdo@ee.washington.edu>
parents:
4521
diff
changeset
|
2 |
/* |
96811f76c3e2
remind v4ping.cc that echo data is variable length
Craig Dowell <craigdo@ee.washington.edu>
parents:
4521
diff
changeset
|
3 |
* This program is free software; you can redistribute it and/or modify |
96811f76c3e2
remind v4ping.cc that echo data is variable length
Craig Dowell <craigdo@ee.washington.edu>
parents:
4521
diff
changeset
|
4 |
* it under the terms of the GNU General Public License version 2 as |
96811f76c3e2
remind v4ping.cc that echo data is variable length
Craig Dowell <craigdo@ee.washington.edu>
parents:
4521
diff
changeset
|
5 |
* published by the Free Software Foundation; |
96811f76c3e2
remind v4ping.cc that echo data is variable length
Craig Dowell <craigdo@ee.washington.edu>
parents:
4521
diff
changeset
|
6 |
* |
96811f76c3e2
remind v4ping.cc that echo data is variable length
Craig Dowell <craigdo@ee.washington.edu>
parents:
4521
diff
changeset
|
7 |
* This program is distributed in the hope that it will be useful, |
96811f76c3e2
remind v4ping.cc that echo data is variable length
Craig Dowell <craigdo@ee.washington.edu>
parents:
4521
diff
changeset
|
8 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
96811f76c3e2
remind v4ping.cc that echo data is variable length
Craig Dowell <craigdo@ee.washington.edu>
parents:
4521
diff
changeset
|
9 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
96811f76c3e2
remind v4ping.cc that echo data is variable length
Craig Dowell <craigdo@ee.washington.edu>
parents:
4521
diff
changeset
|
10 |
* GNU General Public License for more details. |
96811f76c3e2
remind v4ping.cc that echo data is variable length
Craig Dowell <craigdo@ee.washington.edu>
parents:
4521
diff
changeset
|
11 |
* |
96811f76c3e2
remind v4ping.cc that echo data is variable length
Craig Dowell <craigdo@ee.washington.edu>
parents:
4521
diff
changeset
|
12 |
* You should have received a copy of the GNU General Public License |
96811f76c3e2
remind v4ping.cc that echo data is variable length
Craig Dowell <craigdo@ee.washington.edu>
parents:
4521
diff
changeset
|
13 |
* along with this program; if not, write to the Free Software |
96811f76c3e2
remind v4ping.cc that echo data is variable length
Craig Dowell <craigdo@ee.washington.edu>
parents:
4521
diff
changeset
|
14 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
96811f76c3e2
remind v4ping.cc that echo data is variable length
Craig Dowell <craigdo@ee.washington.edu>
parents:
4521
diff
changeset
|
15 |
*/ |
3821
9ea825f066a2
Apply icmp-application patch frm lacage
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
16 |
#include "v4ping.h" |
9ea825f066a2
Apply icmp-application patch frm lacage
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
17 |
#include "ns3/icmpv4.h" |
9ea825f066a2
Apply icmp-application patch frm lacage
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
18 |
#include "ns3/assert.h" |
9ea825f066a2
Apply icmp-application patch frm lacage
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
19 |
#include "ns3/log.h" |
9ea825f066a2
Apply icmp-application patch frm lacage
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
20 |
#include "ns3/ipv4-address.h" |
9ea825f066a2
Apply icmp-application patch frm lacage
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
21 |
#include "ns3/socket.h" |
9ea825f066a2
Apply icmp-application patch frm lacage
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
22 |
#include "ns3/uinteger.h" |
5568
6e159c6c34bb
Use ping in AODV example + multiple V4Ping enhancements to produce pingish output
Pavel Boyko <boyko@iitp.ru>
parents:
4576
diff
changeset
|
23 |
#include "ns3/boolean.h" |
3821
9ea825f066a2
Apply icmp-application patch frm lacage
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
24 |
#include "ns3/inet-socket-address.h" |
9ea825f066a2
Apply icmp-application patch frm lacage
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
25 |
#include "ns3/packet.h" |
9ea825f066a2
Apply icmp-application patch frm lacage
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
26 |
#include "ns3/trace-source-accessor.h" |
9ea825f066a2
Apply icmp-application patch frm lacage
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
27 |
|
9ea825f066a2
Apply icmp-application patch frm lacage
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
28 |
namespace ns3 { |
9ea825f066a2
Apply icmp-application patch frm lacage
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
29 |
|
9ea825f066a2
Apply icmp-application patch frm lacage
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
30 |
NS_LOG_COMPONENT_DEFINE ("V4Ping"); |
9ea825f066a2
Apply icmp-application patch frm lacage
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
31 |
NS_OBJECT_ENSURE_REGISTERED (V4Ping); |
9ea825f066a2
Apply icmp-application patch frm lacage
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
32 |
|
9ea825f066a2
Apply icmp-application patch frm lacage
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
33 |
TypeId |
9ea825f066a2
Apply icmp-application patch frm lacage
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
34 |
V4Ping::GetTypeId (void) |
9ea825f066a2
Apply icmp-application patch frm lacage
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
35 |
{ |
9ea825f066a2
Apply icmp-application patch frm lacage
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
36 |
static TypeId tid = TypeId ("ns3::V4Ping") |
9ea825f066a2
Apply icmp-application patch frm lacage
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
37 |
.SetParent<Application> () |
9ea825f066a2
Apply icmp-application patch frm lacage
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
38 |
.AddConstructor<V4Ping> () |
9ea825f066a2
Apply icmp-application patch frm lacage
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
39 |
.AddAttribute ("Remote", |
7166
2ea56ac66361
applications coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6847
diff
changeset
|
40 |
"The address of the machine we want to ping.", |
2ea56ac66361
applications coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6847
diff
changeset
|
41 |
Ipv4AddressValue (), |
2ea56ac66361
applications coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6847
diff
changeset
|
42 |
MakeIpv4AddressAccessor (&V4Ping::m_remote), |
2ea56ac66361
applications coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6847
diff
changeset
|
43 |
MakeIpv4AddressChecker ()) |
5568
6e159c6c34bb
Use ping in AODV example + multiple V4Ping enhancements to produce pingish output
Pavel Boyko <boyko@iitp.ru>
parents:
4576
diff
changeset
|
44 |
.AddAttribute ("Verbose", |
6e159c6c34bb
Use ping in AODV example + multiple V4Ping enhancements to produce pingish output
Pavel Boyko <boyko@iitp.ru>
parents:
4576
diff
changeset
|
45 |
"Produce usual output.", |
6e159c6c34bb
Use ping in AODV example + multiple V4Ping enhancements to produce pingish output
Pavel Boyko <boyko@iitp.ru>
parents:
4576
diff
changeset
|
46 |
BooleanValue (false), |
6e159c6c34bb
Use ping in AODV example + multiple V4Ping enhancements to produce pingish output
Pavel Boyko <boyko@iitp.ru>
parents:
4576
diff
changeset
|
47 |
MakeBooleanAccessor (&V4Ping::m_verbose), |
6e159c6c34bb
Use ping in AODV example + multiple V4Ping enhancements to produce pingish output
Pavel Boyko <boyko@iitp.ru>
parents:
4576
diff
changeset
|
48 |
MakeBooleanChecker ()) |
6e159c6c34bb
Use ping in AODV example + multiple V4Ping enhancements to produce pingish output
Pavel Boyko <boyko@iitp.ru>
parents:
4576
diff
changeset
|
49 |
.AddAttribute ("Interval", "Wait interval seconds between sending each packet.", |
6e159c6c34bb
Use ping in AODV example + multiple V4Ping enhancements to produce pingish output
Pavel Boyko <boyko@iitp.ru>
parents:
4576
diff
changeset
|
50 |
TimeValue (Seconds (1)), |
6e159c6c34bb
Use ping in AODV example + multiple V4Ping enhancements to produce pingish output
Pavel Boyko <boyko@iitp.ru>
parents:
4576
diff
changeset
|
51 |
MakeTimeAccessor (&V4Ping::m_interval), |
6e159c6c34bb
Use ping in AODV example + multiple V4Ping enhancements to produce pingish output
Pavel Boyko <boyko@iitp.ru>
parents:
4576
diff
changeset
|
52 |
MakeTimeChecker ()) |
6e159c6c34bb
Use ping in AODV example + multiple V4Ping enhancements to produce pingish output
Pavel Boyko <boyko@iitp.ru>
parents:
4576
diff
changeset
|
53 |
.AddAttribute ("Size", "The number of data bytes to be sent, real packet will be 8 (ICMP) + 20 (IP) bytes longer.", |
6e159c6c34bb
Use ping in AODV example + multiple V4Ping enhancements to produce pingish output
Pavel Boyko <boyko@iitp.ru>
parents:
4576
diff
changeset
|
54 |
UintegerValue (56), |
6e159c6c34bb
Use ping in AODV example + multiple V4Ping enhancements to produce pingish output
Pavel Boyko <boyko@iitp.ru>
parents:
4576
diff
changeset
|
55 |
MakeUintegerAccessor (&V4Ping::m_size), |
6e159c6c34bb
Use ping in AODV example + multiple V4Ping enhancements to produce pingish output
Pavel Boyko <boyko@iitp.ru>
parents:
4576
diff
changeset
|
56 |
MakeUintegerChecker<uint32_t> (16)) |
3821
9ea825f066a2
Apply icmp-application patch frm lacage
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
57 |
.AddTraceSource ("Rtt", |
7166
2ea56ac66361
applications coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6847
diff
changeset
|
58 |
"The rtt calculated by the ping.", |
2ea56ac66361
applications coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6847
diff
changeset
|
59 |
MakeTraceSourceAccessor (&V4Ping::m_traceRtt)); |
2ea56ac66361
applications coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6847
diff
changeset
|
60 |
; |
3821
9ea825f066a2
Apply icmp-application patch frm lacage
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
61 |
return tid; |
9ea825f066a2
Apply icmp-application patch frm lacage
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
62 |
} |
9ea825f066a2
Apply icmp-application patch frm lacage
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
63 |
|
9ea825f066a2
Apply icmp-application patch frm lacage
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
64 |
V4Ping::V4Ping () |
5568
6e159c6c34bb
Use ping in AODV example + multiple V4Ping enhancements to produce pingish output
Pavel Boyko <boyko@iitp.ru>
parents:
4576
diff
changeset
|
65 |
: m_interval (Seconds (1)), |
6e159c6c34bb
Use ping in AODV example + multiple V4Ping enhancements to produce pingish output
Pavel Boyko <boyko@iitp.ru>
parents:
4576
diff
changeset
|
66 |
m_size (56), |
6e159c6c34bb
Use ping in AODV example + multiple V4Ping enhancements to produce pingish output
Pavel Boyko <boyko@iitp.ru>
parents:
4576
diff
changeset
|
67 |
m_socket (0), |
6e159c6c34bb
Use ping in AODV example + multiple V4Ping enhancements to produce pingish output
Pavel Boyko <boyko@iitp.ru>
parents:
4576
diff
changeset
|
68 |
m_seq (0), |
6e159c6c34bb
Use ping in AODV example + multiple V4Ping enhancements to produce pingish output
Pavel Boyko <boyko@iitp.ru>
parents:
4576
diff
changeset
|
69 |
m_verbose (false), |
6e159c6c34bb
Use ping in AODV example + multiple V4Ping enhancements to produce pingish output
Pavel Boyko <boyko@iitp.ru>
parents:
4576
diff
changeset
|
70 |
m_recv (0) |
6e159c6c34bb
Use ping in AODV example + multiple V4Ping enhancements to produce pingish output
Pavel Boyko <boyko@iitp.ru>
parents:
4576
diff
changeset
|
71 |
{ |
6e159c6c34bb
Use ping in AODV example + multiple V4Ping enhancements to produce pingish output
Pavel Boyko <boyko@iitp.ru>
parents:
4576
diff
changeset
|
72 |
} |
3821
9ea825f066a2
Apply icmp-application patch frm lacage
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
73 |
V4Ping::~V4Ping () |
7166
2ea56ac66361
applications coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6847
diff
changeset
|
74 |
{ |
2ea56ac66361
applications coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6847
diff
changeset
|
75 |
} |
3821
9ea825f066a2
Apply icmp-application patch frm lacage
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
76 |
|
9ea825f066a2
Apply icmp-application patch frm lacage
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
77 |
void |
9ea825f066a2
Apply icmp-application patch frm lacage
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
78 |
V4Ping::DoDispose (void) |
9ea825f066a2
Apply icmp-application patch frm lacage
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
79 |
{ |
9ea825f066a2
Apply icmp-application patch frm lacage
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
80 |
NS_LOG_FUNCTION (this); |
9ea825f066a2
Apply icmp-application patch frm lacage
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
81 |
m_socket = 0; |
9ea825f066a2
Apply icmp-application patch frm lacage
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
82 |
Application::DoDispose (); |
9ea825f066a2
Apply icmp-application patch frm lacage
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
83 |
} |
9ea825f066a2
Apply icmp-application patch frm lacage
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
84 |
|
9ea825f066a2
Apply icmp-application patch frm lacage
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
85 |
uint32_t |
9ea825f066a2
Apply icmp-application patch frm lacage
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
86 |
V4Ping::GetApplicationId (void) const |
9ea825f066a2
Apply icmp-application patch frm lacage
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
87 |
{ |
9ea825f066a2
Apply icmp-application patch frm lacage
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
88 |
Ptr<Node> node = GetNode (); |
9ea825f066a2
Apply icmp-application patch frm lacage
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
89 |
for (uint32_t i = 0; i < node->GetNApplications (); ++i) |
9ea825f066a2
Apply icmp-application patch frm lacage
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
90 |
{ |
9ea825f066a2
Apply icmp-application patch frm lacage
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
91 |
if (node->GetApplication (i) == this) |
7166
2ea56ac66361
applications coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6847
diff
changeset
|
92 |
{ |
2ea56ac66361
applications coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6847
diff
changeset
|
93 |
return i; |
2ea56ac66361
applications coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6847
diff
changeset
|
94 |
} |
3821
9ea825f066a2
Apply icmp-application patch frm lacage
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
95 |
} |
9ea825f066a2
Apply icmp-application patch frm lacage
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
96 |
NS_ASSERT_MSG (false, "forgot to add application to node"); |
9ea825f066a2
Apply icmp-application patch frm lacage
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
97 |
return 0; // quiet compiler |
9ea825f066a2
Apply icmp-application patch frm lacage
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
98 |
} |
9ea825f066a2
Apply icmp-application patch frm lacage
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
99 |
|
9ea825f066a2
Apply icmp-application patch frm lacage
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
100 |
void |
9ea825f066a2
Apply icmp-application patch frm lacage
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
101 |
V4Ping::Receive (Ptr<Socket> socket) |
9ea825f066a2
Apply icmp-application patch frm lacage
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
102 |
{ |
9ea825f066a2
Apply icmp-application patch frm lacage
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
103 |
NS_LOG_FUNCTION (this << socket); |
9ea825f066a2
Apply icmp-application patch frm lacage
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
104 |
while (m_socket->GetRxAvailable () > 0) |
9ea825f066a2
Apply icmp-application patch frm lacage
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
105 |
{ |
9ea825f066a2
Apply icmp-application patch frm lacage
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
106 |
Address from; |
9ea825f066a2
Apply icmp-application patch frm lacage
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
107 |
Ptr<Packet> p = m_socket->RecvFrom (0xffffffff, 0, from); |
9ea825f066a2
Apply icmp-application patch frm lacage
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
108 |
NS_LOG_DEBUG ("recv " << p->GetSize () << " bytes"); |
9ea825f066a2
Apply icmp-application patch frm lacage
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
109 |
NS_ASSERT (InetSocketAddress::IsMatchingType (from)); |
9ea825f066a2
Apply icmp-application patch frm lacage
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
110 |
InetSocketAddress realFrom = InetSocketAddress::ConvertFrom (from); |
9ea825f066a2
Apply icmp-application patch frm lacage
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
111 |
NS_ASSERT (realFrom.GetPort () == 1); // protocol should be icmp. |
9ea825f066a2
Apply icmp-application patch frm lacage
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
112 |
Ipv4Header ipv4; |
9ea825f066a2
Apply icmp-application patch frm lacage
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
113 |
p->RemoveHeader (ipv4); |
5568
6e159c6c34bb
Use ping in AODV example + multiple V4Ping enhancements to produce pingish output
Pavel Boyko <boyko@iitp.ru>
parents:
4576
diff
changeset
|
114 |
uint32_t recvSize = p->GetSize (); |
3821
9ea825f066a2
Apply icmp-application patch frm lacage
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
115 |
NS_ASSERT (ipv4.GetProtocol () == 1); // protocol should be icmp. |
9ea825f066a2
Apply icmp-application patch frm lacage
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
116 |
Icmpv4Header icmp; |
9ea825f066a2
Apply icmp-application patch frm lacage
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
117 |
p->RemoveHeader (icmp); |
9ea825f066a2
Apply icmp-application patch frm lacage
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
118 |
if (icmp.GetType () == Icmpv4Header::ECHO_REPLY) |
7166
2ea56ac66361
applications coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6847
diff
changeset
|
119 |
{ |
2ea56ac66361
applications coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6847
diff
changeset
|
120 |
Icmpv4Echo echo; |
2ea56ac66361
applications coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6847
diff
changeset
|
121 |
p->RemoveHeader (echo); |
2ea56ac66361
applications coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6847
diff
changeset
|
122 |
std::map<uint16_t, Time>::iterator i = m_sent.find(echo.GetSequenceNumber()); |
6088 | 123 |
|
7166
2ea56ac66361
applications coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6847
diff
changeset
|
124 |
if (i != m_sent.end () && echo.GetIdentifier () == 0) |
2ea56ac66361
applications coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6847
diff
changeset
|
125 |
{ |
5568
6e159c6c34bb
Use ping in AODV example + multiple V4Ping enhancements to produce pingish output
Pavel Boyko <boyko@iitp.ru>
parents:
4576
diff
changeset
|
126 |
uint32_t buf[m_size / 4]; |
7166
2ea56ac66361
applications coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6847
diff
changeset
|
127 |
uint32_t dataSize = echo.GetDataSize (); |
6737
623189bc65be
bug 1029: fix endian issue in v4ping.cc
Tom Henderson <tomh@tomh.org>
parents:
6467
diff
changeset
|
128 |
uint32_t nodeId; |
623189bc65be
bug 1029: fix endian issue in v4ping.cc
Tom Henderson <tomh@tomh.org>
parents:
6467
diff
changeset
|
129 |
uint32_t appId; |
7166
2ea56ac66361
applications coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6847
diff
changeset
|
130 |
if (dataSize == sizeof(buf)) |
2ea56ac66361
applications coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6847
diff
changeset
|
131 |
{ |
4576
96811f76c3e2
remind v4ping.cc that echo data is variable length
Craig Dowell <craigdo@ee.washington.edu>
parents:
4521
diff
changeset
|
132 |
echo.GetData ((uint8_t *)buf); |
6737
623189bc65be
bug 1029: fix endian issue in v4ping.cc
Tom Henderson <tomh@tomh.org>
parents:
6467
diff
changeset
|
133 |
Read32 ((const uint8_t *) &buf[0], nodeId); |
623189bc65be
bug 1029: fix endian issue in v4ping.cc
Tom Henderson <tomh@tomh.org>
parents:
6467
diff
changeset
|
134 |
Read32 ((const uint8_t *) &buf[1], appId); |
4576
96811f76c3e2
remind v4ping.cc that echo data is variable length
Craig Dowell <craigdo@ee.washington.edu>
parents:
4521
diff
changeset
|
135 |
|
7166
2ea56ac66361
applications coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6847
diff
changeset
|
136 |
if (nodeId == GetNode ()->GetId () && |
2ea56ac66361
applications coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6847
diff
changeset
|
137 |
appId == GetApplicationId ()) |
2ea56ac66361
applications coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6847
diff
changeset
|
138 |
{ |
2ea56ac66361
applications coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6847
diff
changeset
|
139 |
Time sendTime = i->second; |
2ea56ac66361
applications coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6847
diff
changeset
|
140 |
NS_ASSERT (Simulator::Now () >= sendTime); |
2ea56ac66361
applications coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6847
diff
changeset
|
141 |
Time delta = Simulator::Now () - sendTime; |
2ea56ac66361
applications coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6847
diff
changeset
|
142 |
|
2ea56ac66361
applications coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6847
diff
changeset
|
143 |
m_sent.erase (i); |
2ea56ac66361
applications coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6847
diff
changeset
|
144 |
m_avgRtt.Update (delta.GetMilliSeconds()); |
2ea56ac66361
applications coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6847
diff
changeset
|
145 |
m_recv++; |
2ea56ac66361
applications coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6847
diff
changeset
|
146 |
m_traceRtt (delta); |
2ea56ac66361
applications coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6847
diff
changeset
|
147 |
|
2ea56ac66361
applications coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6847
diff
changeset
|
148 |
if (m_verbose) |
2ea56ac66361
applications coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6847
diff
changeset
|
149 |
{ |
2ea56ac66361
applications coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6847
diff
changeset
|
150 |
std::cout << recvSize << " bytes from " << realFrom.GetIpv4() << ":" |
5568
6e159c6c34bb
Use ping in AODV example + multiple V4Ping enhancements to produce pingish output
Pavel Boyko <boyko@iitp.ru>
parents:
4576
diff
changeset
|
151 |
<< " icmp_seq=" << echo.GetSequenceNumber () |
6e159c6c34bb
Use ping in AODV example + multiple V4Ping enhancements to produce pingish output
Pavel Boyko <boyko@iitp.ru>
parents:
4576
diff
changeset
|
152 |
<< " ttl=" << (unsigned)ipv4.GetTtl () |
6e159c6c34bb
Use ping in AODV example + multiple V4Ping enhancements to produce pingish output
Pavel Boyko <boyko@iitp.ru>
parents:
4576
diff
changeset
|
153 |
<< " time=" << delta.GetMilliSeconds() << " ms\n"; |
7166
2ea56ac66361
applications coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6847
diff
changeset
|
154 |
} |
2ea56ac66361
applications coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6847
diff
changeset
|
155 |
} |
2ea56ac66361
applications coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6847
diff
changeset
|
156 |
} |
2ea56ac66361
applications coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6847
diff
changeset
|
157 |
} |
2ea56ac66361
applications coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6847
diff
changeset
|
158 |
} |
3821
9ea825f066a2
Apply icmp-application patch frm lacage
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
159 |
} |
9ea825f066a2
Apply icmp-application patch frm lacage
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
160 |
} |
9ea825f066a2
Apply icmp-application patch frm lacage
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
161 |
|
6737
623189bc65be
bug 1029: fix endian issue in v4ping.cc
Tom Henderson <tomh@tomh.org>
parents:
6467
diff
changeset
|
162 |
// Writes data to buffer in little-endian format; least significant byte |
623189bc65be
bug 1029: fix endian issue in v4ping.cc
Tom Henderson <tomh@tomh.org>
parents:
6467
diff
changeset
|
163 |
// of data is at lowest buffer address |
4026
58ae52c5845f
bug 448: V4Ping Application Sends uint32_t Data in Host Order
Craig Dowell <craigdo@ee.washington.edu>
parents:
3932
diff
changeset
|
164 |
void |
6737
623189bc65be
bug 1029: fix endian issue in v4ping.cc
Tom Henderson <tomh@tomh.org>
parents:
6467
diff
changeset
|
165 |
V4Ping::Write32 (uint8_t *buffer, const uint32_t data) |
4026
58ae52c5845f
bug 448: V4Ping Application Sends uint32_t Data in Host Order
Craig Dowell <craigdo@ee.washington.edu>
parents:
3932
diff
changeset
|
166 |
{ |
58ae52c5845f
bug 448: V4Ping Application Sends uint32_t Data in Host Order
Craig Dowell <craigdo@ee.washington.edu>
parents:
3932
diff
changeset
|
167 |
buffer[0] = (data >> 0) & 0xff; |
58ae52c5845f
bug 448: V4Ping Application Sends uint32_t Data in Host Order
Craig Dowell <craigdo@ee.washington.edu>
parents:
3932
diff
changeset
|
168 |
buffer[1] = (data >> 8) & 0xff; |
58ae52c5845f
bug 448: V4Ping Application Sends uint32_t Data in Host Order
Craig Dowell <craigdo@ee.washington.edu>
parents:
3932
diff
changeset
|
169 |
buffer[2] = (data >> 16) & 0xff; |
58ae52c5845f
bug 448: V4Ping Application Sends uint32_t Data in Host Order
Craig Dowell <craigdo@ee.washington.edu>
parents:
3932
diff
changeset
|
170 |
buffer[3] = (data >> 24) & 0xff; |
58ae52c5845f
bug 448: V4Ping Application Sends uint32_t Data in Host Order
Craig Dowell <craigdo@ee.washington.edu>
parents:
3932
diff
changeset
|
171 |
} |
58ae52c5845f
bug 448: V4Ping Application Sends uint32_t Data in Host Order
Craig Dowell <craigdo@ee.washington.edu>
parents:
3932
diff
changeset
|
172 |
|
6737
623189bc65be
bug 1029: fix endian issue in v4ping.cc
Tom Henderson <tomh@tomh.org>
parents:
6467
diff
changeset
|
173 |
// Writes data from a little-endian formatted buffer to data |
623189bc65be
bug 1029: fix endian issue in v4ping.cc
Tom Henderson <tomh@tomh.org>
parents:
6467
diff
changeset
|
174 |
void |
623189bc65be
bug 1029: fix endian issue in v4ping.cc
Tom Henderson <tomh@tomh.org>
parents:
6467
diff
changeset
|
175 |
V4Ping::Read32 (const uint8_t *buffer, uint32_t &data) |
623189bc65be
bug 1029: fix endian issue in v4ping.cc
Tom Henderson <tomh@tomh.org>
parents:
6467
diff
changeset
|
176 |
{ |
623189bc65be
bug 1029: fix endian issue in v4ping.cc
Tom Henderson <tomh@tomh.org>
parents:
6467
diff
changeset
|
177 |
data = (buffer[3] << 24) + (buffer[2] << 16) + (buffer[1] << 8) + buffer[0]; |
623189bc65be
bug 1029: fix endian issue in v4ping.cc
Tom Henderson <tomh@tomh.org>
parents:
6467
diff
changeset
|
178 |
} |
623189bc65be
bug 1029: fix endian issue in v4ping.cc
Tom Henderson <tomh@tomh.org>
parents:
6467
diff
changeset
|
179 |
|
3821
9ea825f066a2
Apply icmp-application patch frm lacage
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
180 |
void |
5568
6e159c6c34bb
Use ping in AODV example + multiple V4Ping enhancements to produce pingish output
Pavel Boyko <boyko@iitp.ru>
parents:
4576
diff
changeset
|
181 |
V4Ping::Send () |
3821
9ea825f066a2
Apply icmp-application patch frm lacage
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
182 |
{ |
6088 | 183 |
NS_LOG_FUNCTION (m_seq); |
3821
9ea825f066a2
Apply icmp-application patch frm lacage
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
184 |
Ptr<Packet> p = Create<Packet> (); |
9ea825f066a2
Apply icmp-application patch frm lacage
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
185 |
Icmpv4Echo echo; |
9ea825f066a2
Apply icmp-application patch frm lacage
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
186 |
echo.SetSequenceNumber (m_seq); |
9ea825f066a2
Apply icmp-application patch frm lacage
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
187 |
m_seq++; |
9ea825f066a2
Apply icmp-application patch frm lacage
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
188 |
echo.SetIdentifier (0); |
4026
58ae52c5845f
bug 448: V4Ping Application Sends uint32_t Data in Host Order
Craig Dowell <craigdo@ee.washington.edu>
parents:
3932
diff
changeset
|
189 |
|
58ae52c5845f
bug 448: V4Ping Application Sends uint32_t Data in Host Order
Craig Dowell <craigdo@ee.washington.edu>
parents:
3932
diff
changeset
|
190 |
// |
58ae52c5845f
bug 448: V4Ping Application Sends uint32_t Data in Host Order
Craig Dowell <craigdo@ee.washington.edu>
parents:
3932
diff
changeset
|
191 |
// We must write quantities out in some form of network order. Since there |
58ae52c5845f
bug 448: V4Ping Application Sends uint32_t Data in Host Order
Craig Dowell <craigdo@ee.washington.edu>
parents:
3932
diff
changeset
|
192 |
// isn't an htonl to work with we just follow the convention in pcap traces |
58ae52c5845f
bug 448: V4Ping Application Sends uint32_t Data in Host Order
Craig Dowell <craigdo@ee.washington.edu>
parents:
3932
diff
changeset
|
193 |
// (where any difference would show up anyway) and borrow that code. Don't |
58ae52c5845f
bug 448: V4Ping Application Sends uint32_t Data in Host Order
Craig Dowell <craigdo@ee.washington.edu>
parents:
3932
diff
changeset
|
194 |
// be too surprised when you see that this is a little endian convention. |
58ae52c5845f
bug 448: V4Ping Application Sends uint32_t Data in Host Order
Craig Dowell <craigdo@ee.washington.edu>
parents:
3932
diff
changeset
|
195 |
// |
5568
6e159c6c34bb
Use ping in AODV example + multiple V4Ping enhancements to produce pingish output
Pavel Boyko <boyko@iitp.ru>
parents:
4576
diff
changeset
|
196 |
uint8_t data[m_size]; |
6e159c6c34bb
Use ping in AODV example + multiple V4Ping enhancements to produce pingish output
Pavel Boyko <boyko@iitp.ru>
parents:
4576
diff
changeset
|
197 |
for (uint32_t i = 0; i < m_size; ++i) data[i] = 0; |
6e159c6c34bb
Use ping in AODV example + multiple V4Ping enhancements to produce pingish output
Pavel Boyko <boyko@iitp.ru>
parents:
4576
diff
changeset
|
198 |
NS_ASSERT (m_size >= 16); |
7166
2ea56ac66361
applications coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6847
diff
changeset
|
199 |
|
4026
58ae52c5845f
bug 448: V4Ping Application Sends uint32_t Data in Host Order
Craig Dowell <craigdo@ee.washington.edu>
parents:
3932
diff
changeset
|
200 |
uint32_t tmp = GetNode ()->GetId (); |
58ae52c5845f
bug 448: V4Ping Application Sends uint32_t Data in Host Order
Craig Dowell <craigdo@ee.washington.edu>
parents:
3932
diff
changeset
|
201 |
Write32 (&data[0 * sizeof(uint32_t)], tmp); |
58ae52c5845f
bug 448: V4Ping Application Sends uint32_t Data in Host Order
Craig Dowell <craigdo@ee.washington.edu>
parents:
3932
diff
changeset
|
202 |
|
58ae52c5845f
bug 448: V4Ping Application Sends uint32_t Data in Host Order
Craig Dowell <craigdo@ee.washington.edu>
parents:
3932
diff
changeset
|
203 |
tmp = GetApplicationId (); |
58ae52c5845f
bug 448: V4Ping Application Sends uint32_t Data in Host Order
Craig Dowell <craigdo@ee.washington.edu>
parents:
3932
diff
changeset
|
204 |
Write32 (&data[1 * sizeof(uint32_t)], tmp); |
58ae52c5845f
bug 448: V4Ping Application Sends uint32_t Data in Host Order
Craig Dowell <craigdo@ee.washington.edu>
parents:
3932
diff
changeset
|
205 |
|
5568
6e159c6c34bb
Use ping in AODV example + multiple V4Ping enhancements to produce pingish output
Pavel Boyko <boyko@iitp.ru>
parents:
4576
diff
changeset
|
206 |
Ptr<Packet> dataPacket = Create<Packet> ((uint8_t *) &data, m_size); |
3821
9ea825f066a2
Apply icmp-application patch frm lacage
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
207 |
echo.SetData (dataPacket); |
9ea825f066a2
Apply icmp-application patch frm lacage
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
208 |
p->AddHeader (echo); |
9ea825f066a2
Apply icmp-application patch frm lacage
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
209 |
Icmpv4Header header; |
9ea825f066a2
Apply icmp-application patch frm lacage
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
210 |
header.SetType (Icmpv4Header::ECHO); |
9ea825f066a2
Apply icmp-application patch frm lacage
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
211 |
header.SetCode (0); |
6467
58ea957f5dd3
[Bug 960] V4Ping does not generate checksum
Fernando Pereira <ferdonfeup@gmail.com>
parents:
6088
diff
changeset
|
212 |
if (Node::ChecksumEnabled ()) |
58ea957f5dd3
[Bug 960] V4Ping does not generate checksum
Fernando Pereira <ferdonfeup@gmail.com>
parents:
6088
diff
changeset
|
213 |
{ |
58ea957f5dd3
[Bug 960] V4Ping does not generate checksum
Fernando Pereira <ferdonfeup@gmail.com>
parents:
6088
diff
changeset
|
214 |
header.EnableChecksum (); |
58ea957f5dd3
[Bug 960] V4Ping does not generate checksum
Fernando Pereira <ferdonfeup@gmail.com>
parents:
6088
diff
changeset
|
215 |
} |
3821
9ea825f066a2
Apply icmp-application patch frm lacage
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
216 |
p->AddHeader (header); |
6088 | 217 |
m_sent.insert (std::make_pair (m_seq - 1, Simulator::Now())); |
3821
9ea825f066a2
Apply icmp-application patch frm lacage
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
218 |
m_socket->Send (p, 0); |
7166
2ea56ac66361
applications coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6847
diff
changeset
|
219 |
m_next = Simulator::Schedule (m_interval, &V4Ping::Send, this); |
5568
6e159c6c34bb
Use ping in AODV example + multiple V4Ping enhancements to produce pingish output
Pavel Boyko <boyko@iitp.ru>
parents:
4576
diff
changeset
|
220 |
} |
6e159c6c34bb
Use ping in AODV example + multiple V4Ping enhancements to produce pingish output
Pavel Boyko <boyko@iitp.ru>
parents:
4576
diff
changeset
|
221 |
|
6e159c6c34bb
Use ping in AODV example + multiple V4Ping enhancements to produce pingish output
Pavel Boyko <boyko@iitp.ru>
parents:
4576
diff
changeset
|
222 |
void |
6e159c6c34bb
Use ping in AODV example + multiple V4Ping enhancements to produce pingish output
Pavel Boyko <boyko@iitp.ru>
parents:
4576
diff
changeset
|
223 |
V4Ping::StartApplication (void) |
6e159c6c34bb
Use ping in AODV example + multiple V4Ping enhancements to produce pingish output
Pavel Boyko <boyko@iitp.ru>
parents:
4576
diff
changeset
|
224 |
{ |
6e159c6c34bb
Use ping in AODV example + multiple V4Ping enhancements to produce pingish output
Pavel Boyko <boyko@iitp.ru>
parents:
4576
diff
changeset
|
225 |
NS_LOG_FUNCTION (this); |
7166
2ea56ac66361
applications coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6847
diff
changeset
|
226 |
|
5568
6e159c6c34bb
Use ping in AODV example + multiple V4Ping enhancements to produce pingish output
Pavel Boyko <boyko@iitp.ru>
parents:
4576
diff
changeset
|
227 |
m_started = Simulator::Now (); |
6e159c6c34bb
Use ping in AODV example + multiple V4Ping enhancements to produce pingish output
Pavel Boyko <boyko@iitp.ru>
parents:
4576
diff
changeset
|
228 |
if (m_verbose) |
6e159c6c34bb
Use ping in AODV example + multiple V4Ping enhancements to produce pingish output
Pavel Boyko <boyko@iitp.ru>
parents:
4576
diff
changeset
|
229 |
{ |
6e159c6c34bb
Use ping in AODV example + multiple V4Ping enhancements to produce pingish output
Pavel Boyko <boyko@iitp.ru>
parents:
4576
diff
changeset
|
230 |
std::cout << "PING " << m_remote << " 56(84) bytes of data.\n"; |
6e159c6c34bb
Use ping in AODV example + multiple V4Ping enhancements to produce pingish output
Pavel Boyko <boyko@iitp.ru>
parents:
4576
diff
changeset
|
231 |
} |
7166
2ea56ac66361
applications coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6847
diff
changeset
|
232 |
|
5568
6e159c6c34bb
Use ping in AODV example + multiple V4Ping enhancements to produce pingish output
Pavel Boyko <boyko@iitp.ru>
parents:
4576
diff
changeset
|
233 |
m_socket = Socket::CreateSocket (GetNode (), TypeId::LookupByName ("ns3::Ipv4RawSocketFactory")); |
6e159c6c34bb
Use ping in AODV example + multiple V4Ping enhancements to produce pingish output
Pavel Boyko <boyko@iitp.ru>
parents:
4576
diff
changeset
|
234 |
NS_ASSERT (m_socket != 0); |
6e159c6c34bb
Use ping in AODV example + multiple V4Ping enhancements to produce pingish output
Pavel Boyko <boyko@iitp.ru>
parents:
4576
diff
changeset
|
235 |
m_socket->SetAttribute ("Protocol", UintegerValue (1)); // icmp |
6e159c6c34bb
Use ping in AODV example + multiple V4Ping enhancements to produce pingish output
Pavel Boyko <boyko@iitp.ru>
parents:
4576
diff
changeset
|
236 |
m_socket->SetRecvCallback (MakeCallback (&V4Ping::Receive, this)); |
6e159c6c34bb
Use ping in AODV example + multiple V4Ping enhancements to produce pingish output
Pavel Boyko <boyko@iitp.ru>
parents:
4576
diff
changeset
|
237 |
InetSocketAddress src = InetSocketAddress (Ipv4Address::GetAny (), 0); |
6e159c6c34bb
Use ping in AODV example + multiple V4Ping enhancements to produce pingish output
Pavel Boyko <boyko@iitp.ru>
parents:
4576
diff
changeset
|
238 |
int status; |
6e159c6c34bb
Use ping in AODV example + multiple V4Ping enhancements to produce pingish output
Pavel Boyko <boyko@iitp.ru>
parents:
4576
diff
changeset
|
239 |
status = m_socket->Bind (src); |
6e159c6c34bb
Use ping in AODV example + multiple V4Ping enhancements to produce pingish output
Pavel Boyko <boyko@iitp.ru>
parents:
4576
diff
changeset
|
240 |
NS_ASSERT (status != -1); |
6e159c6c34bb
Use ping in AODV example + multiple V4Ping enhancements to produce pingish output
Pavel Boyko <boyko@iitp.ru>
parents:
4576
diff
changeset
|
241 |
InetSocketAddress dst = InetSocketAddress (m_remote, 0); |
6e159c6c34bb
Use ping in AODV example + multiple V4Ping enhancements to produce pingish output
Pavel Boyko <boyko@iitp.ru>
parents:
4576
diff
changeset
|
242 |
status = m_socket->Connect (dst); |
6e159c6c34bb
Use ping in AODV example + multiple V4Ping enhancements to produce pingish output
Pavel Boyko <boyko@iitp.ru>
parents:
4576
diff
changeset
|
243 |
NS_ASSERT (status != -1); |
7166
2ea56ac66361
applications coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6847
diff
changeset
|
244 |
|
5568
6e159c6c34bb
Use ping in AODV example + multiple V4Ping enhancements to produce pingish output
Pavel Boyko <boyko@iitp.ru>
parents:
4576
diff
changeset
|
245 |
Send (); |
3821
9ea825f066a2
Apply icmp-application patch frm lacage
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
246 |
} |
9ea825f066a2
Apply icmp-application patch frm lacage
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
247 |
void |
9ea825f066a2
Apply icmp-application patch frm lacage
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
248 |
V4Ping::StopApplication (void) |
9ea825f066a2
Apply icmp-application patch frm lacage
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
249 |
{ |
9ea825f066a2
Apply icmp-application patch frm lacage
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
250 |
NS_LOG_FUNCTION (this); |
5568
6e159c6c34bb
Use ping in AODV example + multiple V4Ping enhancements to produce pingish output
Pavel Boyko <boyko@iitp.ru>
parents:
4576
diff
changeset
|
251 |
m_next.Cancel(); |
3932
76fabfcfd757
bug 421: memory leak in csma-ping
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3821
diff
changeset
|
252 |
m_socket->Close (); |
7166
2ea56ac66361
applications coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6847
diff
changeset
|
253 |
|
5568
6e159c6c34bb
Use ping in AODV example + multiple V4Ping enhancements to produce pingish output
Pavel Boyko <boyko@iitp.ru>
parents:
4576
diff
changeset
|
254 |
if (m_verbose) |
6e159c6c34bb
Use ping in AODV example + multiple V4Ping enhancements to produce pingish output
Pavel Boyko <boyko@iitp.ru>
parents:
4576
diff
changeset
|
255 |
{ |
6e159c6c34bb
Use ping in AODV example + multiple V4Ping enhancements to produce pingish output
Pavel Boyko <boyko@iitp.ru>
parents:
4576
diff
changeset
|
256 |
std::ostringstream os; |
6e159c6c34bb
Use ping in AODV example + multiple V4Ping enhancements to produce pingish output
Pavel Boyko <boyko@iitp.ru>
parents:
4576
diff
changeset
|
257 |
os.precision (4); |
6e159c6c34bb
Use ping in AODV example + multiple V4Ping enhancements to produce pingish output
Pavel Boyko <boyko@iitp.ru>
parents:
4576
diff
changeset
|
258 |
os << "--- " << m_remote << " ping statistics ---\n" |
7166
2ea56ac66361
applications coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6847
diff
changeset
|
259 |
<< m_seq << " packets transmitted, " << m_recv << " received, " |
2ea56ac66361
applications coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6847
diff
changeset
|
260 |
<< ((m_seq - m_recv) * 100 / m_seq) << "% packet loss, " |
2ea56ac66361
applications coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6847
diff
changeset
|
261 |
<< "time " << (Simulator::Now () - m_started).GetMilliSeconds () << "ms\n"; |
2ea56ac66361
applications coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6847
diff
changeset
|
262 |
|
5568
6e159c6c34bb
Use ping in AODV example + multiple V4Ping enhancements to produce pingish output
Pavel Boyko <boyko@iitp.ru>
parents:
4576
diff
changeset
|
263 |
if (m_avgRtt.Count () > 0) |
6e159c6c34bb
Use ping in AODV example + multiple V4Ping enhancements to produce pingish output
Pavel Boyko <boyko@iitp.ru>
parents:
4576
diff
changeset
|
264 |
os << "rtt min/avg/max/mdev = " << m_avgRtt.Min() << "/" << m_avgRtt.Avg() << "/" |
7166
2ea56ac66361
applications coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6847
diff
changeset
|
265 |
<< m_avgRtt.Max() << "/" << m_avgRtt.Stddev() |
2ea56ac66361
applications coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6847
diff
changeset
|
266 |
<< " ms\n"; |
5568
6e159c6c34bb
Use ping in AODV example + multiple V4Ping enhancements to produce pingish output
Pavel Boyko <boyko@iitp.ru>
parents:
4576
diff
changeset
|
267 |
std::cout << os.str(); |
6e159c6c34bb
Use ping in AODV example + multiple V4Ping enhancements to produce pingish output
Pavel Boyko <boyko@iitp.ru>
parents:
4576
diff
changeset
|
268 |
} |
3821
9ea825f066a2
Apply icmp-application patch frm lacage
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
269 |
} |
9ea825f066a2
Apply icmp-application patch frm lacage
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
270 |
|
9ea825f066a2
Apply icmp-application patch frm lacage
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
271 |
|
9ea825f066a2
Apply icmp-application patch frm lacage
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
272 |
} // namespace ns3 |