src/applications/model/udp-echo-client.cc
author Mohit Goyal <mohit.bits2011@gmail.com>
Fri, 27 Mar 2015 07:17:37 -0700
changeset 11240 5b6a7efcf062
parent 11085 6e4d08656d7c
permissions -rw-r--r--
SetGroupName for applications module
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1496
0ad4c18b475c start of udp echo applications
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
0ad4c18b475c start of udp echo applications
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     2
/*
0ad4c18b475c start of udp echo applications
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     3
 * Copyright 2007 University of Washington
0ad4c18b475c start of udp echo applications
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     4
 * 
0ad4c18b475c start of udp echo applications
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
0ad4c18b475c start of udp echo applications
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License version 2 as
0ad4c18b475c start of udp echo applications
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     7
 * published by the Free Software Foundation;
0ad4c18b475c start of udp echo applications
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     8
 *
0ad4c18b475c start of udp echo applications
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
0ad4c18b475c start of udp echo applications
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
0ad4c18b475c start of udp echo applications
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0ad4c18b475c start of udp echo applications
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    12
 * GNU General Public License for more details.
0ad4c18b475c start of udp echo applications
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    13
 *
0ad4c18b475c start of udp echo applications
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
0ad4c18b475c start of udp echo applications
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
0ad4c18b475c start of udp echo applications
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
0ad4c18b475c start of udp echo applications
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    17
 */
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1500
diff changeset
    18
#include "ns3/log.h"
1496
0ad4c18b475c start of udp echo applications
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    19
#include "ns3/ipv4-address.h"
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7256
diff changeset
    20
#include "ns3/ipv6-address.h"
1496
0ad4c18b475c start of udp echo applications
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    21
#include "ns3/nstime.h"
0ad4c18b475c start of udp echo applications
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    22
#include "ns3/inet-socket-address.h"
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7256
diff changeset
    23
#include "ns3/inet6-socket-address.h"
1496
0ad4c18b475c start of udp echo applications
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    24
#include "ns3/socket.h"
0ad4c18b475c start of udp echo applications
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    25
#include "ns3/simulator.h"
0ad4c18b475c start of udp echo applications
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    26
#include "ns3/socket-factory.h"
0ad4c18b475c start of udp echo applications
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    27
#include "ns3/packet.h"
2494
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    28
#include "ns3/uinteger.h"
4710
e56da5fd6697 bug 638: add missing tx trace source
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 4577
diff changeset
    29
#include "ns3/trace-source-accessor.h"
1496
0ad4c18b475c start of udp echo applications
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    30
#include "udp-echo-client.h"
0ad4c18b475c start of udp echo applications
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    31
10968
2d29fee2b7b8 [Bug 1551] Redux: NS_LOG_COMPONENT_DEFINE inside or outside of ns3 namespace?
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10967
diff changeset
    32
namespace ns3 {
10967
597a9ec89e60 [Bug 1551] NS_LOG_COMPONENT_DEFINE inside or outside of ns3 namespace?
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10652
diff changeset
    33
10968
2d29fee2b7b8 [Bug 1551] Redux: NS_LOG_COMPONENT_DEFINE inside or outside of ns3 namespace?
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10967
diff changeset
    34
NS_LOG_COMPONENT_DEFINE ("UdpEchoClientApplication");
1496
0ad4c18b475c start of udp echo applications
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    35
10652
dc18deba4502 [doxygen] Revert r10410, r10411, r10412
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10453
diff changeset
    36
NS_OBJECT_ENSURE_REGISTERED (UdpEchoClient);
1496
0ad4c18b475c start of udp echo applications
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    37
2494
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    38
TypeId
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    39
UdpEchoClient::GetTypeId (void)
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    40
{
2602
d9262bff6df2 add back support for introspected doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2494
diff changeset
    41
  static TypeId tid = TypeId ("ns3::UdpEchoClient")
2494
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    42
    .SetParent<Application> ()
11240
5b6a7efcf062 SetGroupName for applications module
Mohit Goyal <mohit.bits2011@gmail.com>
parents: 11085
diff changeset
    43
    .SetGroupName("Applications")
2494
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    44
    .AddConstructor<UdpEchoClient> ()
3257
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3145
diff changeset
    45
    .AddAttribute ("MaxPackets", 
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3145
diff changeset
    46
                   "The maximum number of packets the application will send",
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2766
diff changeset
    47
                   UintegerValue (100),
2494
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    48
                   MakeUintegerAccessor (&UdpEchoClient::m_count),
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    49
                   MakeUintegerChecker<uint32_t> ())
3257
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3145
diff changeset
    50
    .AddAttribute ("Interval", 
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3145
diff changeset
    51
                   "The time to wait between packets",
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2766
diff changeset
    52
                   TimeValue (Seconds (1.0)),
2494
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    53
                   MakeTimeAccessor (&UdpEchoClient::m_interval),
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    54
                   MakeTimeChecker ())
3382
d5f8e5fae1c6 fix bug 234 which changes required methods on helpers to constructor parameters. Update tutorial content to reflect. Change RemoteIpv4 attribute to RemoteAddress.
Craig Dowell <craigdo@ee.washington.edu>
parents: 3271
diff changeset
    55
    .AddAttribute ("RemoteAddress", 
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7256
diff changeset
    56
                   "The destination Address of the outbound packets",
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7256
diff changeset
    57
                   AddressValue (),
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7256
diff changeset
    58
                   MakeAddressAccessor (&UdpEchoClient::m_peerAddress),
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7256
diff changeset
    59
                   MakeAddressChecker ())
3257
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3145
diff changeset
    60
    .AddAttribute ("RemotePort", 
ba198dad54a2 CSMA Cleanup, XXX in echo apps, clarification of point-to-point data rates in dox
Craig Dowell <craigdo@ee.washington.edu>
parents: 3145
diff changeset
    61
                   "The destination port of the outbound packets",
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2766
diff changeset
    62
                   UintegerValue (0),
2494
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    63
                   MakeUintegerAccessor (&UdpEchoClient::m_peerPort),
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    64
                   MakeUintegerChecker<uint16_t> ())
4577
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
    65
    .AddAttribute ("PacketSize", "Size of echo data in outbound packets",
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2766
diff changeset
    66
                   UintegerValue (100),
4577
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
    67
                   MakeUintegerAccessor (&UdpEchoClient::SetDataSize,
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
    68
                                         &UdpEchoClient::GetDataSize),
2494
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    69
                   MakeUintegerChecker<uint32_t> ())
4710
e56da5fd6697 bug 638: add missing tx trace source
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 4577
diff changeset
    70
    .AddTraceSource ("Tx", "A new packet is created and is sent",
11085
6e4d08656d7c TracedCallback function signatures, the simple ones.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10968
diff changeset
    71
                     MakeTraceSourceAccessor (&UdpEchoClient::m_txTrace),
6e4d08656d7c TracedCallback function signatures, the simple ones.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10968
diff changeset
    72
                     "ns3::Packet::TracedCallback")
7166
2ea56ac66361 applications coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6847
diff changeset
    73
  ;
2494
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    74
  return tid;
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    75
}
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    76
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    77
UdpEchoClient::UdpEchoClient ()
1496
0ad4c18b475c start of udp echo applications
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    78
{
9133
bcf7cef191c1 Clean up function logging of applications module.
Vedran Miletić <rivanvx@gmail.com>
parents: 7820
diff changeset
    79
  NS_LOG_FUNCTION (this);
2494
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    80
  m_sent = 0;
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    81
  m_socket = 0;
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    82
  m_sendEvent = EventId ();
4577
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
    83
  m_data = 0;
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
    84
  m_dataSize = 0;
1496
0ad4c18b475c start of udp echo applications
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    85
}
0ad4c18b475c start of udp echo applications
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    86
0ad4c18b475c start of udp echo applications
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    87
UdpEchoClient::~UdpEchoClient()
0ad4c18b475c start of udp echo applications
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    88
{
9133
bcf7cef191c1 Clean up function logging of applications module.
Vedran Miletić <rivanvx@gmail.com>
parents: 7820
diff changeset
    89
  NS_LOG_FUNCTION (this);
4410
59e19500509d Add explicit socket close to udp echo for consistency
Craig Dowell <craigdo@ee.washington.edu>
parents: 3382
diff changeset
    90
  m_socket = 0;
4577
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
    91
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
    92
  delete [] m_data;
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
    93
  m_data = 0;
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
    94
  m_dataSize = 0;
1496
0ad4c18b475c start of udp echo applications
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    95
}
0ad4c18b475c start of udp echo applications
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    96
2766
9b1b0cc12042 add UdpEchoClient::SetRemote
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2602
diff changeset
    97
void 
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7256
diff changeset
    98
UdpEchoClient::SetRemote (Address ip, uint16_t port)
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7256
diff changeset
    99
{
9133
bcf7cef191c1 Clean up function logging of applications module.
Vedran Miletić <rivanvx@gmail.com>
parents: 7820
diff changeset
   100
  NS_LOG_FUNCTION (this << ip << port);
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7256
diff changeset
   101
  m_peerAddress = ip;
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7256
diff changeset
   102
  m_peerPort = port;
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7256
diff changeset
   103
}
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7256
diff changeset
   104
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7256
diff changeset
   105
void 
2766
9b1b0cc12042 add UdpEchoClient::SetRemote
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2602
diff changeset
   106
UdpEchoClient::SetRemote (Ipv4Address ip, uint16_t port)
9b1b0cc12042 add UdpEchoClient::SetRemote
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2602
diff changeset
   107
{
9133
bcf7cef191c1 Clean up function logging of applications module.
Vedran Miletić <rivanvx@gmail.com>
parents: 7820
diff changeset
   108
  NS_LOG_FUNCTION (this << ip << port);
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7256
diff changeset
   109
  m_peerAddress = Address (ip);
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7256
diff changeset
   110
  m_peerPort = port;
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7256
diff changeset
   111
}
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7256
diff changeset
   112
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7256
diff changeset
   113
void 
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7256
diff changeset
   114
UdpEchoClient::SetRemote (Ipv6Address ip, uint16_t port)
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7256
diff changeset
   115
{
9133
bcf7cef191c1 Clean up function logging of applications module.
Vedran Miletić <rivanvx@gmail.com>
parents: 7820
diff changeset
   116
  NS_LOG_FUNCTION (this << ip << port);
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7256
diff changeset
   117
  m_peerAddress = Address (ip);
2766
9b1b0cc12042 add UdpEchoClient::SetRemote
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2602
diff changeset
   118
  m_peerPort = port;
9b1b0cc12042 add UdpEchoClient::SetRemote
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2602
diff changeset
   119
}
9b1b0cc12042 add UdpEchoClient::SetRemote
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2602
diff changeset
   120
1496
0ad4c18b475c start of udp echo applications
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   121
void
0ad4c18b475c start of udp echo applications
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   122
UdpEchoClient::DoDispose (void)
0ad4c18b475c start of udp echo applications
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   123
{
9133
bcf7cef191c1 Clean up function logging of applications module.
Vedran Miletić <rivanvx@gmail.com>
parents: 7820
diff changeset
   124
  NS_LOG_FUNCTION (this);
1496
0ad4c18b475c start of udp echo applications
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   125
  Application::DoDispose ();
0ad4c18b475c start of udp echo applications
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   126
}
0ad4c18b475c start of udp echo applications
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   127
0ad4c18b475c start of udp echo applications
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   128
void 
0ad4c18b475c start of udp echo applications
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   129
UdpEchoClient::StartApplication (void)
0ad4c18b475c start of udp echo applications
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   130
{
9133
bcf7cef191c1 Clean up function logging of applications module.
Vedran Miletić <rivanvx@gmail.com>
parents: 7820
diff changeset
   131
  NS_LOG_FUNCTION (this);
1496
0ad4c18b475c start of udp echo applications
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   132
3025
d93423ef5ef2 fix bug 180
Craig Dowell <craigdo@ee.washington.edu>
parents: 2989
diff changeset
   133
  if (m_socket == 0)
1496
0ad4c18b475c start of udp echo applications
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   134
    {
3125
d2d8a36cfd23 s/ns3::Udp/ns3::UdpSocketFactory
Tom Henderson <tomh@tomh.org>
parents: 3116
diff changeset
   135
      TypeId tid = TypeId::LookupByName ("ns3::UdpSocketFactory");
7256
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7225
diff changeset
   136
      m_socket = Socket::CreateSocket (GetNode (), tid);
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7256
diff changeset
   137
      if (Ipv4Address::IsMatchingType(m_peerAddress) == true)
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7256
diff changeset
   138
        {
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7256
diff changeset
   139
          m_socket->Bind();
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7256
diff changeset
   140
          m_socket->Connect (InetSocketAddress (Ipv4Address::ConvertFrom(m_peerAddress), m_peerPort));
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7256
diff changeset
   141
        }
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7256
diff changeset
   142
      else if (Ipv6Address::IsMatchingType(m_peerAddress) == true)
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7256
diff changeset
   143
        {
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7256
diff changeset
   144
          m_socket->Bind6();
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7256
diff changeset
   145
          m_socket->Connect (Inet6SocketAddress (Ipv6Address::ConvertFrom(m_peerAddress), m_peerPort));
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7256
diff changeset
   146
        }
1496
0ad4c18b475c start of udp echo applications
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   147
    }
0ad4c18b475c start of udp echo applications
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   148
7256
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7225
diff changeset
   149
  m_socket->SetRecvCallback (MakeCallback (&UdpEchoClient::HandleRead, this));
1500
895ed42278d3 finish up basic echo apps
Craig Dowell <craigdo@ee.washington.edu>
parents: 1499
diff changeset
   150
7256
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7225
diff changeset
   151
  ScheduleTransmit (Seconds (0.));
1496
0ad4c18b475c start of udp echo applications
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   152
}
0ad4c18b475c start of udp echo applications
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   153
0ad4c18b475c start of udp echo applications
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   154
void 
0ad4c18b475c start of udp echo applications
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   155
UdpEchoClient::StopApplication ()
0ad4c18b475c start of udp echo applications
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   156
{
9133
bcf7cef191c1 Clean up function logging of applications module.
Vedran Miletić <rivanvx@gmail.com>
parents: 7820
diff changeset
   157
  NS_LOG_FUNCTION (this);
1500
895ed42278d3 finish up basic echo apps
Craig Dowell <craigdo@ee.washington.edu>
parents: 1499
diff changeset
   158
3025
d93423ef5ef2 fix bug 180
Craig Dowell <craigdo@ee.washington.edu>
parents: 2989
diff changeset
   159
  if (m_socket != 0) 
1500
895ed42278d3 finish up basic echo apps
Craig Dowell <craigdo@ee.washington.edu>
parents: 1499
diff changeset
   160
    {
4410
59e19500509d Add explicit socket close to udp echo for consistency
Craig Dowell <craigdo@ee.washington.edu>
parents: 3382
diff changeset
   161
      m_socket->Close ();
7256
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7225
diff changeset
   162
      m_socket->SetRecvCallback (MakeNullCallback<void, Ptr<Socket> > ());
5288
93b77f8fb697 Bug 682: UdpEchoClient does not reset socket on StopApplication
Josh Pelkey <jpelkey@gatech.edu>
parents: 5152
diff changeset
   163
      m_socket = 0;
1500
895ed42278d3 finish up basic echo apps
Craig Dowell <craigdo@ee.washington.edu>
parents: 1499
diff changeset
   164
    }
895ed42278d3 finish up basic echo apps
Craig Dowell <craigdo@ee.washington.edu>
parents: 1499
diff changeset
   165
7256
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7225
diff changeset
   166
  Simulator::Cancel (m_sendEvent);
1496
0ad4c18b475c start of udp echo applications
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   167
}
0ad4c18b475c start of udp echo applications
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   168
0ad4c18b475c start of udp echo applications
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   169
void 
4577
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   170
UdpEchoClient::SetDataSize (uint32_t dataSize)
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   171
{
9133
bcf7cef191c1 Clean up function logging of applications module.
Vedran Miletić <rivanvx@gmail.com>
parents: 7820
diff changeset
   172
  NS_LOG_FUNCTION (this << dataSize);
4577
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   173
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   174
  //
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   175
  // If the client is setting the echo packet data size this way, we infer
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   176
  // that she doesn't care about the contents of the packet at all, so 
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   177
  // neither will we.
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   178
  //
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   179
  delete [] m_data;
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   180
  m_data = 0;
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   181
  m_dataSize = 0;
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   182
  m_size = dataSize;
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   183
}
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   184
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   185
uint32_t 
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   186
UdpEchoClient::GetDataSize (void) const
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   187
{
9133
bcf7cef191c1 Clean up function logging of applications module.
Vedran Miletić <rivanvx@gmail.com>
parents: 7820
diff changeset
   188
  NS_LOG_FUNCTION (this);
4577
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   189
  return m_size;
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   190
}
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   191
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   192
void 
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   193
UdpEchoClient::SetFill (std::string fill)
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   194
{
9133
bcf7cef191c1 Clean up function logging of applications module.
Vedran Miletić <rivanvx@gmail.com>
parents: 7820
diff changeset
   195
  NS_LOG_FUNCTION (this << fill);
4577
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   196
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   197
  uint32_t dataSize = fill.size () + 1;
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   198
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   199
  if (dataSize != m_dataSize)
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   200
    {
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   201
      delete [] m_data;
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   202
      m_data = new uint8_t [dataSize];
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   203
      m_dataSize = dataSize;
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   204
    }
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   205
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   206
  memcpy (m_data, fill.c_str (), dataSize);
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   207
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   208
  //
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   209
  // Overwrite packet size attribute.
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   210
  //
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   211
  m_size = dataSize;
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   212
}
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   213
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   214
void 
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   215
UdpEchoClient::SetFill (uint8_t fill, uint32_t dataSize)
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   216
{
9133
bcf7cef191c1 Clean up function logging of applications module.
Vedran Miletić <rivanvx@gmail.com>
parents: 7820
diff changeset
   217
  NS_LOG_FUNCTION (this << fill << dataSize);
4577
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   218
  if (dataSize != m_dataSize)
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   219
    {
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   220
      delete [] m_data;
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   221
      m_data = new uint8_t [dataSize];
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   222
      m_dataSize = dataSize;
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   223
    }
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   224
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   225
  memset (m_data, fill, dataSize);
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   226
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   227
  //
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   228
  // Overwrite packet size attribute.
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   229
  //
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   230
  m_size = dataSize;
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   231
}
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   232
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   233
void 
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   234
UdpEchoClient::SetFill (uint8_t *fill, uint32_t fillSize, uint32_t dataSize)
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   235
{
9133
bcf7cef191c1 Clean up function logging of applications module.
Vedran Miletić <rivanvx@gmail.com>
parents: 7820
diff changeset
   236
  NS_LOG_FUNCTION (this << fill << fillSize << dataSize);
4577
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   237
  if (dataSize != m_dataSize)
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   238
    {
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   239
      delete [] m_data;
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   240
      m_data = new uint8_t [dataSize];
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   241
      m_dataSize = dataSize;
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   242
    }
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   243
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   244
  if (fillSize >= dataSize)
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   245
    {
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   246
      memcpy (m_data, fill, dataSize);
7749
7458a10a17d1 Fix bug 1378 (UdpEchoClient::SetFill() does not set packet size correctly) (fix from jesse1013000@gmail.com)
Tom Henderson <tomh@tomh.org>
parents: 7717
diff changeset
   247
      m_size = dataSize;
4577
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   248
      return;
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   249
    }
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   250
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   251
  //
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   252
  // Do all but the final fill.
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   253
  //
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   254
  uint32_t filled = 0;
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   255
  while (filled + fillSize < dataSize)
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   256
    {
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   257
      memcpy (&m_data[filled], fill, fillSize);
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   258
      filled += fillSize;
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   259
    }
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   260
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   261
  //
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   262
  // Last fill may be partial
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   263
  //
7256
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7225
diff changeset
   264
  memcpy (&m_data[filled], fill, dataSize - filled);
4577
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   265
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   266
  //
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   267
  // Overwrite packet size attribute.
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   268
  //
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   269
  m_size = dataSize;
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   270
}
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   271
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   272
void 
1496
0ad4c18b475c start of udp echo applications
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   273
UdpEchoClient::ScheduleTransmit (Time dt)
0ad4c18b475c start of udp echo applications
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   274
{
9133
bcf7cef191c1 Clean up function logging of applications module.
Vedran Miletić <rivanvx@gmail.com>
parents: 7820
diff changeset
   275
  NS_LOG_FUNCTION (this << dt);
7256
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7225
diff changeset
   276
  m_sendEvent = Simulator::Schedule (dt, &UdpEchoClient::Send, this);
1496
0ad4c18b475c start of udp echo applications
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   277
}
0ad4c18b475c start of udp echo applications
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   278
0ad4c18b475c start of udp echo applications
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   279
void 
0ad4c18b475c start of udp echo applications
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   280
UdpEchoClient::Send (void)
0ad4c18b475c start of udp echo applications
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   281
{
9133
bcf7cef191c1 Clean up function logging of applications module.
Vedran Miletić <rivanvx@gmail.com>
parents: 7820
diff changeset
   282
  NS_LOG_FUNCTION (this);
1496
0ad4c18b475c start of udp echo applications
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   283
0ad4c18b475c start of udp echo applications
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   284
  NS_ASSERT (m_sendEvent.IsExpired ());
0ad4c18b475c start of udp echo applications
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   285
4710
e56da5fd6697 bug 638: add missing tx trace source
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 4577
diff changeset
   286
  Ptr<Packet> p;
4577
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   287
  if (m_dataSize)
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   288
    {
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   289
      //
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   290
      // If m_dataSize is non-zero, we have a data buffer of the same size that we
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   291
      // are expected to copy and send.  This state of affairs is created if one of
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   292
      // the Fill functions is called.  In this case, m_size must have been set
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   293
      // to agree with m_dataSize
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   294
      //
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   295
      NS_ASSERT_MSG (m_dataSize == m_size, "UdpEchoClient::Send(): m_size and m_dataSize inconsistent");
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   296
      NS_ASSERT_MSG (m_data, "UdpEchoClient::Send(): m_dataSize but no m_data");
4710
e56da5fd6697 bug 638: add missing tx trace source
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 4577
diff changeset
   297
      p = Create<Packet> (m_data, m_dataSize);
4577
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   298
    }
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   299
  else
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   300
    {
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   301
      //
10453
ab7eaf3e1af0 Bug 938 - missing Doxygen in ns-3 (applications model + helper)
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10411
diff changeset
   302
      // If m_dataSize is zero, the client has indicated that it doesn't care
4577
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   303
      // about the data itself either by specifying the data size by setting
10453
ab7eaf3e1af0 Bug 938 - missing Doxygen in ns-3 (applications model + helper)
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10411
diff changeset
   304
      // the corresponding attribute or by not calling a SetFill function.  In
4577
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   305
      // this case, we don't worry about it either.  But we do allow m_size
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   306
      // to have a value different from the (zero) m_dataSize.
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   307
      //
4710
e56da5fd6697 bug 638: add missing tx trace source
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 4577
diff changeset
   308
      p = Create<Packet> (m_size);
4577
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   309
    }
4710
e56da5fd6697 bug 638: add missing tx trace source
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 4577
diff changeset
   310
  // call to the trace sinks before the packet is actually sent,
e56da5fd6697 bug 638: add missing tx trace source
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 4577
diff changeset
   311
  // so that tags added to the packet can be sent as well
e56da5fd6697 bug 638: add missing tx trace source
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 4577
diff changeset
   312
  m_txTrace (p);
e56da5fd6697 bug 638: add missing tx trace source
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 4577
diff changeset
   313
  m_socket->Send (p);
4577
84c133267507 Allow UDP echo client to specify packet contents
Craig Dowell <craigdo@ee.washington.edu>
parents: 4410
diff changeset
   314
1496
0ad4c18b475c start of udp echo applications
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   315
  ++m_sent;
0ad4c18b475c start of udp echo applications
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   316
7807
21c50515e50a UdpEcho NS_LOG_INFO bugfix (wrong address type) and cosmetic changes to log output
Vedran Miletić <rivanvx@gmail.com>
parents: 7760
diff changeset
   317
  if (Ipv4Address::IsMatchingType (m_peerAddress))
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7256
diff changeset
   318
    {
7820
9ebf12703683 Add time to UdpEchoClient and UdpEchoServer NS_LOG_INFO output.
Vedran Miletić <rivanvx@gmail.com>
parents: 7807
diff changeset
   319
      NS_LOG_INFO ("At time " << Simulator::Now ().GetSeconds () << "s client sent " << m_size << " bytes to " <<
7807
21c50515e50a UdpEcho NS_LOG_INFO bugfix (wrong address type) and cosmetic changes to log output
Vedran Miletić <rivanvx@gmail.com>
parents: 7760
diff changeset
   320
                   Ipv4Address::ConvertFrom (m_peerAddress) << " port " << m_peerPort);
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7256
diff changeset
   321
    }
7807
21c50515e50a UdpEcho NS_LOG_INFO bugfix (wrong address type) and cosmetic changes to log output
Vedran Miletić <rivanvx@gmail.com>
parents: 7760
diff changeset
   322
  else if (Ipv6Address::IsMatchingType (m_peerAddress))
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7256
diff changeset
   323
    {
7820
9ebf12703683 Add time to UdpEchoClient and UdpEchoServer NS_LOG_INFO output.
Vedran Miletić <rivanvx@gmail.com>
parents: 7807
diff changeset
   324
      NS_LOG_INFO ("At time " << Simulator::Now ().GetSeconds () << "s client sent " << m_size << " bytes to " <<
7807
21c50515e50a UdpEcho NS_LOG_INFO bugfix (wrong address type) and cosmetic changes to log output
Vedran Miletić <rivanvx@gmail.com>
parents: 7760
diff changeset
   325
                   Ipv6Address::ConvertFrom (m_peerAddress) << " port " << m_peerPort);
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7256
diff changeset
   326
    }
1499
93d51d757afa working one way echo app
Craig Dowell <craigdo@ee.washington.edu>
parents: 1496
diff changeset
   327
1496
0ad4c18b475c start of udp echo applications
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   328
  if (m_sent < m_count) 
0ad4c18b475c start of udp echo applications
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   329
    {
0ad4c18b475c start of udp echo applications
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   330
      ScheduleTransmit (m_interval);
0ad4c18b475c start of udp echo applications
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   331
    }
0ad4c18b475c start of udp echo applications
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   332
}
0ad4c18b475c start of udp echo applications
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   333
1500
895ed42278d3 finish up basic echo apps
Craig Dowell <craigdo@ee.washington.edu>
parents: 1499
diff changeset
   334
void
3098
d384d52f8f6e Cut over UDP applications to use the new receive API
Tom Henderson <tomh@tomh.org>
parents: 2989
diff changeset
   335
UdpEchoClient::HandleRead (Ptr<Socket> socket)
1500
895ed42278d3 finish up basic echo apps
Craig Dowell <craigdo@ee.washington.edu>
parents: 1499
diff changeset
   336
{
3098
d384d52f8f6e Cut over UDP applications to use the new receive API
Tom Henderson <tomh@tomh.org>
parents: 2989
diff changeset
   337
  NS_LOG_FUNCTION (this << socket);
d384d52f8f6e Cut over UDP applications to use the new receive API
Tom Henderson <tomh@tomh.org>
parents: 2989
diff changeset
   338
  Ptr<Packet> packet;
3271
023417b3bc5a Move other applications to RecvFrom ()
Tom Henderson <tomh@tomh.org>
parents: 3269
diff changeset
   339
  Address from;
7760
e98d9c028d7f Bug 1372: condition without parentheses patch
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents: 7749
diff changeset
   340
  while ((packet = socket->RecvFrom (from)))
1500
895ed42278d3 finish up basic echo apps
Craig Dowell <craigdo@ee.washington.edu>
parents: 1499
diff changeset
   341
    {
3098
d384d52f8f6e Cut over UDP applications to use the new receive API
Tom Henderson <tomh@tomh.org>
parents: 2989
diff changeset
   342
      if (InetSocketAddress::IsMatchingType (from))
d384d52f8f6e Cut over UDP applications to use the new receive API
Tom Henderson <tomh@tomh.org>
parents: 2989
diff changeset
   343
        {
7820
9ebf12703683 Add time to UdpEchoClient and UdpEchoServer NS_LOG_INFO output.
Vedran Miletić <rivanvx@gmail.com>
parents: 7807
diff changeset
   344
          NS_LOG_INFO ("At time " << Simulator::Now ().GetSeconds () << "s client received " << packet->GetSize () << " bytes from " <<
7807
21c50515e50a UdpEcho NS_LOG_INFO bugfix (wrong address type) and cosmetic changes to log output
Vedran Miletić <rivanvx@gmail.com>
parents: 7760
diff changeset
   345
                       InetSocketAddress::ConvertFrom (from).GetIpv4 () << " port " <<
21c50515e50a UdpEcho NS_LOG_INFO bugfix (wrong address type) and cosmetic changes to log output
Vedran Miletić <rivanvx@gmail.com>
parents: 7760
diff changeset
   346
                       InetSocketAddress::ConvertFrom (from).GetPort ());
3098
d384d52f8f6e Cut over UDP applications to use the new receive API
Tom Henderson <tomh@tomh.org>
parents: 2989
diff changeset
   347
        }
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7256
diff changeset
   348
      else if (Inet6SocketAddress::IsMatchingType (from))
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7256
diff changeset
   349
        {
7820
9ebf12703683 Add time to UdpEchoClient and UdpEchoServer NS_LOG_INFO output.
Vedran Miletić <rivanvx@gmail.com>
parents: 7807
diff changeset
   350
          NS_LOG_INFO ("At time " << Simulator::Now ().GetSeconds () << "s client received " << packet->GetSize () << " bytes from " <<
7807
21c50515e50a UdpEcho NS_LOG_INFO bugfix (wrong address type) and cosmetic changes to log output
Vedran Miletić <rivanvx@gmail.com>
parents: 7760
diff changeset
   351
                       Inet6SocketAddress::ConvertFrom (from).GetIpv6 () << " port " <<
21c50515e50a UdpEcho NS_LOG_INFO bugfix (wrong address type) and cosmetic changes to log output
Vedran Miletić <rivanvx@gmail.com>
parents: 7760
diff changeset
   352
                       Inet6SocketAddress::ConvertFrom (from).GetPort ());
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7256
diff changeset
   353
        }
1500
895ed42278d3 finish up basic echo apps
Craig Dowell <craigdo@ee.washington.edu>
parents: 1499
diff changeset
   354
    }
895ed42278d3 finish up basic echo apps
Craig Dowell <craigdo@ee.washington.edu>
parents: 1499
diff changeset
   355
}
895ed42278d3 finish up basic echo apps
Craig Dowell <craigdo@ee.washington.edu>
parents: 1499
diff changeset
   356
1496
0ad4c18b475c start of udp echo applications
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   357
} // Namespace ns3