LEFT | RIGHT |
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ | 1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
2 /* | 2 /* |
3 * Copyright (c) 2014 Universita' di Firenze | 3 * Copyright (c) 2014 Universita' di Firenze |
4 * | 4 * |
5 * This program is free software; you can redistribute it and/or modify | 5 * This program is free software; you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License version 2 as | 6 * it under the terms of the GNU General Public License version 2 as |
7 * published by the Free Software Foundation; | 7 * published by the Free Software Foundation; |
8 * | 8 * |
9 * This program is distributed in the hope that it will be useful, | 9 * This program is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 27 matching lines...) Expand all Loading... |
38 NS_LOG_COMPONENT_DEFINE ("PacketSocketClient"); | 38 NS_LOG_COMPONENT_DEFINE ("PacketSocketClient"); |
39 NS_OBJECT_ENSURE_REGISTERED (PacketSocketClient); | 39 NS_OBJECT_ENSURE_REGISTERED (PacketSocketClient); |
40 | 40 |
41 TypeId | 41 TypeId |
42 PacketSocketClient::GetTypeId (void) | 42 PacketSocketClient::GetTypeId (void) |
43 { | 43 { |
44 static TypeId tid = TypeId ("ns3::PacketSocketClient") | 44 static TypeId tid = TypeId ("ns3::PacketSocketClient") |
45 .SetParent<Application> () | 45 .SetParent<Application> () |
46 .AddConstructor<PacketSocketClient> () | 46 .AddConstructor<PacketSocketClient> () |
47 .AddAttribute ("MaxPackets", | 47 .AddAttribute ("MaxPackets", |
48 "The maximum number of packets the application will send", | 48 "The maximum number of packets the application will send (zer
o means infinite)", |
49 UintegerValue (100), | 49 UintegerValue (100), |
50 MakeUintegerAccessor (&PacketSocketClient::m_maxPackets), | 50 MakeUintegerAccessor (&PacketSocketClient::m_maxPackets), |
51 MakeUintegerChecker<uint32_t> ()) | 51 MakeUintegerChecker<uint32_t> ()) |
52 .AddAttribute ("Interval", | 52 .AddAttribute ("Interval", |
53 "The time to wait between packets", TimeValue (Seconds (1.0))
, | 53 "The time to wait between packets", TimeValue (Seconds (1.0))
, |
54 MakeTimeAccessor (&PacketSocketClient::m_interval), | 54 MakeTimeAccessor (&PacketSocketClient::m_interval), |
55 MakeTimeChecker ()) | 55 MakeTimeChecker ()) |
56 .AddAttribute ("PacketSize", | 56 .AddAttribute ("PacketSize", |
57 "Size of packets generated (bytes).", | 57 "Size of packets generated (bytes).", |
58 UintegerValue (1024), | 58 UintegerValue (1024), |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 PacketSocketClient::DoDispose (void) | 90 PacketSocketClient::DoDispose (void) |
91 { | 91 { |
92 NS_LOG_FUNCTION (this); | 92 NS_LOG_FUNCTION (this); |
93 Application::DoDispose (); | 93 Application::DoDispose (); |
94 } | 94 } |
95 | 95 |
96 void | 96 void |
97 PacketSocketClient::StartApplication (void) | 97 PacketSocketClient::StartApplication (void) |
98 { | 98 { |
99 NS_LOG_FUNCTION (this); | 99 NS_LOG_FUNCTION (this); |
100 NS_ASSERT_MSG (m_peerAddressSet, "Local address not set"); | 100 NS_ASSERT_MSG (m_peerAddressSet, "Local address not set"); |
101 | 101 |
102 if (m_socket == 0) | 102 if (m_socket == 0) |
103 { | 103 { |
104 TypeId tid = TypeId::LookupByName ("ns3::PacketSocketFactory"); | 104 TypeId tid = TypeId::LookupByName ("ns3::PacketSocketFactory"); |
105 m_socket = Socket::CreateSocket (GetNode (), tid); | 105 m_socket = Socket::CreateSocket (GetNode (), tid); |
106 | 106 |
107 m_socket->Bind (m_peerAddress); | 107 m_socket->Bind (m_peerAddress); |
108 m_socket->Connect (m_peerAddress); | 108 m_socket->Connect (m_peerAddress); |
109 } | 109 } |
110 | 110 |
(...skipping 27 matching lines...) Expand all Loading... |
138 << p->GetUid () << " Time: " | 138 << p->GetUid () << " Time: " |
139 << (Simulator::Now ()).GetSeconds ()); | 139 << (Simulator::Now ()).GetSeconds ()); |
140 } | 140 } |
141 else | 141 else |
142 { | 142 { |
143 NS_LOG_INFO ("Error while sending " << m_size << " bytes to " | 143 NS_LOG_INFO ("Error while sending " << m_size << " bytes to " |
144 << peerAddressStringStream.str ()); | 144 << peerAddressStringStream.str ()); |
145 } | 145 } |
146 m_sent++; | 146 m_sent++; |
147 | 147 |
148 if (m_sent < m_maxPackets) | 148 if ((m_sent < m_maxPackets) || (m_maxPackets == 0)) |
149 { | 149 { |
150 m_txTrace (p, m_peerAddress); | 150 m_txTrace (p, m_peerAddress); |
151 m_sendEvent = Simulator::Schedule (m_interval, &PacketSocketClient::Send,
this); | 151 m_sendEvent = Simulator::Schedule (m_interval, &PacketSocketClient::Send,
this); |
152 } | 152 } |
153 } | 153 } |
154 | 154 |
155 } // Namespace ns3 | 155 } // Namespace ns3 |
LEFT | RIGHT |