OLD | NEW |
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) 2007,2008, 2009 INRIA, UDcast | 3 * Copyright (c) 2007,2008, 2009 INRIA, UDcast |
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 |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
15 * along with this program; if not, write to the Free Software | 15 * along with this program; if not, write to the Free Software |
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | 16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
17 * | 17 * |
18 * Author: Mohamed Amine Ismail <amine.ismail@sophia.inria.fr> | 18 * Author: Mohamed Amine Ismail <amine.ismail@sophia.inria.fr> |
19 * <amine.ismail@udcast.com> | 19 * <amine.ismail@udcast.com> |
20 */ | 20 */ |
21 #include "ns3/log.h" | 21 #include "ns3/log.h" |
22 #include "ns3/ipv4-address.h" | 22 #include "ns3/ipv4-address.h" |
23 #include "ns3/nstime.h" | 23 #include "ns3/nstime.h" |
24 #include "ns3/inet-socket-address.h" | 24 #include "ns3/inet-socket-address.h" |
| 25 #include "ns3/inet6-socket-address.h" |
25 #include "ns3/socket.h" | 26 #include "ns3/socket.h" |
26 #include "ns3/simulator.h" | 27 #include "ns3/simulator.h" |
27 #include "ns3/socket-factory.h" | 28 #include "ns3/socket-factory.h" |
28 #include "ns3/packet.h" | 29 #include "ns3/packet.h" |
29 #include "ns3/uinteger.h" | 30 #include "ns3/uinteger.h" |
30 #include "ns3/string.h" | 31 #include "ns3/string.h" |
31 #include "seq-ts-header.h" | 32 #include "seq-ts-header.h" |
32 #include "udp-trace-client.h" | 33 #include "udp-trace-client.h" |
33 #include <stdlib.h> | 34 #include <stdlib.h> |
34 #include <stdio.h> | 35 #include <stdio.h> |
(...skipping 17 matching lines...) Expand all Loading... |
52 { 320, 587, 'B'} | 53 { 320, 587, 'B'} |
53 }; | 54 }; |
54 | 55 |
55 TypeId | 56 TypeId |
56 UdpTraceClient::GetTypeId (void) | 57 UdpTraceClient::GetTypeId (void) |
57 { | 58 { |
58 static TypeId tid = TypeId ("ns3::UdpTraceClient") | 59 static TypeId tid = TypeId ("ns3::UdpTraceClient") |
59 .SetParent<Application> () | 60 .SetParent<Application> () |
60 .AddConstructor<UdpTraceClient> () | 61 .AddConstructor<UdpTraceClient> () |
61 .AddAttribute ("RemoteAddress", | 62 .AddAttribute ("RemoteAddress", |
62 "The destination Ipv4Address of the outbound packets", | 63 "The destination Address of the outbound packets", |
63 Ipv4AddressValue (), | 64 AddressValue (), |
64 MakeIpv4AddressAccessor (&UdpTraceClient::m_peerAddress), | 65 MakeAddressAccessor (&UdpTraceClient::m_peerAddress), |
65 MakeIpv4AddressChecker ()) | 66 MakeAddressChecker ()) |
66 .AddAttribute ("RemotePort", | 67 .AddAttribute ("RemotePort", |
67 "The destination port of the outbound packets", | 68 "The destination port of the outbound packets", |
68 UintegerValue (100), | 69 UintegerValue (100), |
69 MakeUintegerAccessor (&UdpTraceClient::m_peerPort), | 70 MakeUintegerAccessor (&UdpTraceClient::m_peerPort), |
70 MakeUintegerChecker<uint16_t> ()) | 71 MakeUintegerChecker<uint16_t> ()) |
71 .AddAttribute ("MaxPacketSize", | 72 .AddAttribute ("MaxPacketSize", |
72 "The maximum size of a packet.", | 73 "The maximum size of a packet.", |
73 UintegerValue (1024), | 74 UintegerValue (1024), |
74 MakeUintegerAccessor (&UdpTraceClient::m_maxPacketSize), | 75 MakeUintegerAccessor (&UdpTraceClient::m_maxPacketSize), |
75 MakeUintegerChecker<uint32_t> ()) | 76 MakeUintegerChecker<uint32_t> ()) |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 } | 110 } |
110 } | 111 } |
111 | 112 |
112 UdpTraceClient::~UdpTraceClient () | 113 UdpTraceClient::~UdpTraceClient () |
113 { | 114 { |
114 NS_LOG_FUNCTION (this); | 115 NS_LOG_FUNCTION (this); |
115 m_entries.clear (); | 116 m_entries.clear (); |
116 } | 117 } |
117 | 118 |
118 void | 119 void |
| 120 UdpTraceClient::SetRemote (Address ip, uint16_t port) |
| 121 { |
| 122 m_entries.clear (); |
| 123 m_peerAddress = ip; |
| 124 m_peerPort = port; |
| 125 } |
| 126 |
| 127 void |
119 UdpTraceClient::SetRemote (Ipv4Address ip, uint16_t port) | 128 UdpTraceClient::SetRemote (Ipv4Address ip, uint16_t port) |
120 { | 129 { |
121 m_entries.clear (); | 130 m_entries.clear (); |
122 m_peerAddress = ip; | 131 m_peerAddress = Address (ip); |
123 m_peerPort = port; | 132 m_peerPort = port; |
124 } | 133 } |
125 | 134 |
| 135 void |
| 136 UdpTraceClient::SetRemote (Ipv6Address ip, uint16_t port) |
| 137 { |
| 138 m_entries.clear (); |
| 139 m_peerAddress = Address (ip); |
| 140 m_peerPort = port; |
| 141 } |
| 142 |
126 void | 143 void |
127 UdpTraceClient::SetTraceFile (std::string traceFile) | 144 UdpTraceClient::SetTraceFile (std::string traceFile) |
128 { | 145 { |
129 if (traceFile == "") | 146 if (traceFile == "") |
130 { | 147 { |
131 LoadDefaultTrace (); | 148 LoadDefaultTrace (); |
132 } | 149 } |
133 else | 150 else |
134 { | 151 { |
135 LoadTrace (traceFile); | 152 LoadTrace (traceFile); |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 | 233 |
217 void | 234 void |
218 UdpTraceClient::StartApplication (void) | 235 UdpTraceClient::StartApplication (void) |
219 { | 236 { |
220 NS_LOG_FUNCTION (this); | 237 NS_LOG_FUNCTION (this); |
221 | 238 |
222 if (m_socket == 0) | 239 if (m_socket == 0) |
223 { | 240 { |
224 TypeId tid = TypeId::LookupByName ("ns3::UdpSocketFactory"); | 241 TypeId tid = TypeId::LookupByName ("ns3::UdpSocketFactory"); |
225 m_socket = Socket::CreateSocket (GetNode (), tid); | 242 m_socket = Socket::CreateSocket (GetNode (), tid); |
226 m_socket->Bind (); | 243 if (Ipv4Address::IsMatchingType(m_peerAddress) == true) |
227 m_socket->Connect (InetSocketAddress (m_peerAddress, m_peerPort)); | 244 { |
| 245 m_socket->Bind (); |
| 246 m_socket->Connect (InetSocketAddress (Ipv4Address::ConvertFrom (m_peer
Address), m_peerPort)); |
| 247 } |
| 248 else if (Ipv6Address::IsMatchingType(m_peerAddress) == true) |
| 249 { |
| 250 m_socket->Bind6 (); |
| 251 m_socket->Connect (Inet6SocketAddress (Ipv6Address::ConvertFrom (m_pee
rAddress), m_peerPort)); |
| 252 } |
228 } | 253 } |
229 m_socket->SetRecvCallback (MakeNullCallback<void, Ptr<Socket> > ()); | 254 m_socket->SetRecvCallback (MakeNullCallback<void, Ptr<Socket> > ()); |
230 m_sendEvent = Simulator::Schedule (Seconds (0.0), &UdpTraceClient::Send, this)
; | 255 m_sendEvent = Simulator::Schedule (Seconds (0.0), &UdpTraceClient::Send, this)
; |
231 } | 256 } |
232 | 257 |
233 void | 258 void |
234 UdpTraceClient::StopApplication () | 259 UdpTraceClient::StopApplication () |
235 { | 260 { |
236 NS_LOG_FUNCTION (this); | 261 NS_LOG_FUNCTION (this); |
237 Simulator::Cancel (m_sendEvent); | 262 Simulator::Cancel (m_sendEvent); |
(...skipping 10 matching lines...) Expand all Loading... |
248 packetSize = size - 12; // 12 is the size of the SeqTsHeader | 273 packetSize = size - 12; // 12 is the size of the SeqTsHeader |
249 } | 274 } |
250 else | 275 else |
251 { | 276 { |
252 packetSize = 0; | 277 packetSize = 0; |
253 } | 278 } |
254 p = Create<Packet> (packetSize); | 279 p = Create<Packet> (packetSize); |
255 SeqTsHeader seqTs; | 280 SeqTsHeader seqTs; |
256 seqTs.SetSeq (m_sent); | 281 seqTs.SetSeq (m_sent); |
257 p->AddHeader (seqTs); | 282 p->AddHeader (seqTs); |
| 283 |
| 284 std::stringstream addressString; |
| 285 if (Ipv4Address::IsMatchingType(m_peerAddress) == true) |
| 286 { |
| 287 addressString << Ipv4Address::ConvertFrom (m_peerAddress); |
| 288 } |
| 289 else if (Ipv6Address::IsMatchingType(m_peerAddress) == true) |
| 290 { |
| 291 addressString << Ipv6Address::ConvertFrom (m_peerAddress); |
| 292 } |
| 293 else |
| 294 { |
| 295 addressString << m_peerAddress; |
| 296 } |
| 297 |
258 if ((m_socket->Send (p)) >= 0) | 298 if ((m_socket->Send (p)) >= 0) |
259 { | 299 { |
260 ++m_sent; | 300 ++m_sent; |
261 NS_LOG_INFO ("Sent " << size << " bytes to " | 301 NS_LOG_INFO ("Sent " << size << " bytes to " |
262 << m_peerAddress); | 302 << addressString.str ()); |
263 } | 303 } |
264 else | 304 else |
265 { | 305 { |
266 NS_LOG_INFO ("Error while sending " << size << " bytes to " | 306 NS_LOG_INFO ("Error while sending " << size << " bytes to " |
267 << m_peerAddress); | 307 << addressString.str ()); |
268 } | 308 } |
269 } | 309 } |
270 | 310 |
271 void | 311 void |
272 UdpTraceClient::Send (void) | 312 UdpTraceClient::Send (void) |
273 { | 313 { |
274 NS_LOG_FUNCTION (this); | 314 NS_LOG_FUNCTION (this); |
275 | 315 |
276 NS_ASSERT (m_sendEvent.IsExpired ()); | 316 NS_ASSERT (m_sendEvent.IsExpired ()); |
277 Ptr<Packet> p; | 317 Ptr<Packet> p; |
(...skipping 10 matching lines...) Expand all Loading... |
288 | 328 |
289 m_currentEntry++; | 329 m_currentEntry++; |
290 m_currentEntry %= m_entries.size (); | 330 m_currentEntry %= m_entries.size (); |
291 entry = &m_entries[m_currentEntry]; | 331 entry = &m_entries[m_currentEntry]; |
292 } | 332 } |
293 while (entry->timeToSend == 0); | 333 while (entry->timeToSend == 0); |
294 m_sendEvent = Simulator::Schedule (MilliSeconds (entry->timeToSend), &UdpTrace
Client::Send, this); | 334 m_sendEvent = Simulator::Schedule (MilliSeconds (entry->timeToSend), &UdpTrace
Client::Send, this); |
295 } | 335 } |
296 | 336 |
297 } // Namespace ns3 | 337 } // Namespace ns3 |
OLD | NEW |