author | Craig Dowell <craigdo@ee.washington.edu> |
Tue, 24 Jun 2008 15:40:24 -0700 | |
changeset 3322 | 951296e9a277 |
parent 3276 | 8869a79a391f |
child 3379 | a2ef1eb4c16d |
permissions | -rw-r--r-- |
1456
7372ff049e61
Remove m_quiet variable, fix copyright
Tom Henderson <tomh@tomh.org>
parents:
1427
diff
changeset
|
1 |
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
7372ff049e61
Remove m_quiet variable, fix copyright
Tom Henderson <tomh@tomh.org>
parents:
1427
diff
changeset
|
2 |
/* |
7372ff049e61
Remove m_quiet variable, fix copyright
Tom Henderson <tomh@tomh.org>
parents:
1427
diff
changeset
|
3 |
* Copyright 2007 University of Washington |
7372ff049e61
Remove m_quiet variable, fix copyright
Tom Henderson <tomh@tomh.org>
parents:
1427
diff
changeset
|
4 |
* |
7372ff049e61
Remove m_quiet variable, fix copyright
Tom Henderson <tomh@tomh.org>
parents:
1427
diff
changeset
|
5 |
* This program is free software; you can redistribute it and/or modify |
7372ff049e61
Remove m_quiet variable, fix copyright
Tom Henderson <tomh@tomh.org>
parents:
1427
diff
changeset
|
6 |
* it under the terms of the GNU General Public License version 2 as |
7372ff049e61
Remove m_quiet variable, fix copyright
Tom Henderson <tomh@tomh.org>
parents:
1427
diff
changeset
|
7 |
* published by the Free Software Foundation; |
7372ff049e61
Remove m_quiet variable, fix copyright
Tom Henderson <tomh@tomh.org>
parents:
1427
diff
changeset
|
8 |
* |
7372ff049e61
Remove m_quiet variable, fix copyright
Tom Henderson <tomh@tomh.org>
parents:
1427
diff
changeset
|
9 |
* This program is distributed in the hope that it will be useful, |
7372ff049e61
Remove m_quiet variable, fix copyright
Tom Henderson <tomh@tomh.org>
parents:
1427
diff
changeset
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
7372ff049e61
Remove m_quiet variable, fix copyright
Tom Henderson <tomh@tomh.org>
parents:
1427
diff
changeset
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
7372ff049e61
Remove m_quiet variable, fix copyright
Tom Henderson <tomh@tomh.org>
parents:
1427
diff
changeset
|
12 |
* GNU General Public License for more details. |
7372ff049e61
Remove m_quiet variable, fix copyright
Tom Henderson <tomh@tomh.org>
parents:
1427
diff
changeset
|
13 |
* |
7372ff049e61
Remove m_quiet variable, fix copyright
Tom Henderson <tomh@tomh.org>
parents:
1427
diff
changeset
|
14 |
* You should have received a copy of the GNU General Public License |
7372ff049e61
Remove m_quiet variable, fix copyright
Tom Henderson <tomh@tomh.org>
parents:
1427
diff
changeset
|
15 |
* along with this program; if not, write to the Free Software |
7372ff049e61
Remove m_quiet variable, fix copyright
Tom Henderson <tomh@tomh.org>
parents:
1427
diff
changeset
|
16 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
7372ff049e61
Remove m_quiet variable, fix copyright
Tom Henderson <tomh@tomh.org>
parents:
1427
diff
changeset
|
17 |
* |
7372ff049e61
Remove m_quiet variable, fix copyright
Tom Henderson <tomh@tomh.org>
parents:
1427
diff
changeset
|
18 |
* Author: Tom Henderson (tomhend@u.washington.edu) |
7372ff049e61
Remove m_quiet variable, fix copyright
Tom Henderson <tomh@tomh.org>
parents:
1427
diff
changeset
|
19 |
*/ |
1319 | 20 |
#include "ns3/address.h" |
1504
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1496
diff
changeset
|
21 |
#include "ns3/log.h" |
1319 | 22 |
#include "ns3/inet-socket-address.h" |
23 |
#include "ns3/node.h" |
|
24 |
#include "ns3/socket.h" |
|
25 |
#include "ns3/simulator.h" |
|
26 |
#include "ns3/socket-factory.h" |
|
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/trace-source-accessor.h" |
3125
d2d8a36cfd23
s/ns3::Udp/ns3::UdpSocketFactory
Tom Henderson <tomh@tomh.org>
parents:
3116
diff
changeset
|
29 |
#include "ns3/udp-socket-factory.h" |
1319 | 30 |
#include "packet-sink.h" |
31 |
||
32 |
using namespace std; |
|
33 |
||
34 |
namespace ns3 { |
|
35 |
||
1504
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1496
diff
changeset
|
36 |
NS_LOG_COMPONENT_DEFINE ("PacketSinkApplication"); |
2494
1c69ea12779c
port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2257
diff
changeset
|
37 |
NS_OBJECT_ENSURE_REGISTERED (PacketSink); |
1319 | 38 |
|
2494
1c69ea12779c
port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2257
diff
changeset
|
39 |
TypeId |
1c69ea12779c
port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2257
diff
changeset
|
40 |
PacketSink::GetTypeId (void) |
1319 | 41 |
{ |
2602
d9262bff6df2
add back support for introspected doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2494
diff
changeset
|
42 |
static TypeId tid = TypeId ("ns3::PacketSink") |
2494
1c69ea12779c
port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2257
diff
changeset
|
43 |
.SetParent<Application> () |
2728
153993e8be6f
register constructor
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2602
diff
changeset
|
44 |
.AddConstructor<PacketSink> () |
2494
1c69ea12779c
port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2257
diff
changeset
|
45 |
.AddAttribute ("Local", "The Address on which to Bind the rx socket.", |
2965
4b28e9740e3b
get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2728
diff
changeset
|
46 |
AddressValue (), |
2494
1c69ea12779c
port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2257
diff
changeset
|
47 |
MakeAddressAccessor (&PacketSink::m_local), |
1c69ea12779c
port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2257
diff
changeset
|
48 |
MakeAddressChecker ()) |
1c69ea12779c
port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2257
diff
changeset
|
49 |
.AddAttribute ("Protocol", "The type id of the protocol to use for the rx socket.", |
3125
d2d8a36cfd23
s/ns3::Udp/ns3::UdpSocketFactory
Tom Henderson <tomh@tomh.org>
parents:
3116
diff
changeset
|
50 |
TypeIdValue (UdpSocketFactory::GetTypeId ()), |
2494
1c69ea12779c
port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2257
diff
changeset
|
51 |
MakeTypeIdAccessor (&PacketSink::m_tid), |
1c69ea12779c
port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2257
diff
changeset
|
52 |
MakeTypeIdChecker ()) |
1c69ea12779c
port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2257
diff
changeset
|
53 |
.AddTraceSource ("Rx", "A packet has been received", |
1c69ea12779c
port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2257
diff
changeset
|
54 |
MakeTraceSourceAccessor (&PacketSink::m_rxTrace)) |
1c69ea12779c
port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2257
diff
changeset
|
55 |
; |
1c69ea12779c
port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2257
diff
changeset
|
56 |
return tid; |
1319 | 57 |
} |
58 |
||
2494
1c69ea12779c
port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2257
diff
changeset
|
59 |
PacketSink::PacketSink () |
1319 | 60 |
{ |
61 |
m_socket = 0; |
|
62 |
} |
|
63 |
||
64 |
PacketSink::~PacketSink() |
|
65 |
{} |
|
66 |
||
67 |
void |
|
68 |
PacketSink::DoDispose (void) |
|
69 |
{ |
|
70 |
m_socket = 0; |
|
71 |
||
72 |
// chain up |
|
73 |
Application::DoDispose (); |
|
74 |
} |
|
75 |
||
76 |
||
77 |
// Application Methods |
|
78 |
void PacketSink::StartApplication() // Called at time specified by Start |
|
79 |
{ |
|
80 |
// Create the socket if not already |
|
81 |
if (!m_socket) |
|
82 |
{ |
|
3116
c33b6d2775b7
Move API for socket factory to a Socket::CreateSocket () factory method
Tom Henderson <tomh@tomh.org>
parents:
3103
diff
changeset
|
83 |
m_socket = Socket::CreateSocket (GetNode(), m_tid); |
1319 | 84 |
m_socket->Bind (m_local); |
2224
6f97d21a99c2
Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
2205
diff
changeset
|
85 |
m_socket->Listen (0); |
1319 | 86 |
} |
1867 | 87 |
|
3102 | 88 |
m_socket->SetRecvCallback (MakeCallback(&PacketSink::HandleRead, this)); |
2224
6f97d21a99c2
Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
2205
diff
changeset
|
89 |
m_socket->SetAcceptCallback ( |
6f97d21a99c2
Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
2205
diff
changeset
|
90 |
MakeNullCallback<bool, Ptr<Socket>, const Address &> (), |
3276
8869a79a391f
Changes for bug 205, unlisted FIN bug
Craig Dowell <craigdo@ee.washington.edu>
parents:
3271
diff
changeset
|
91 |
MakeNullCallback<void, Ptr<Socket>, const Address&> ()); |
1319 | 92 |
} |
93 |
||
94 |
void PacketSink::StopApplication() // Called at time specified by Stop |
|
95 |
{ |
|
2205 | 96 |
if (m_socket) |
1319 | 97 |
{ |
3102 | 98 |
m_socket->SetRecvCallback (MakeNullCallback<void, Ptr<Socket> > ()); |
1319 | 99 |
} |
100 |
} |
|
101 |
||
3097
1b1661bbfa33
Plumb in socket receive pull model, in parallel to existing Receive framework
Tom Henderson <tomh@tomh.org>
parents:
2965
diff
changeset
|
102 |
void PacketSink::HandleRead (Ptr<Socket> socket) |
1b1661bbfa33
Plumb in socket receive pull model, in parallel to existing Receive framework
Tom Henderson <tomh@tomh.org>
parents:
2965
diff
changeset
|
103 |
{ |
1b1661bbfa33
Plumb in socket receive pull model, in parallel to existing Receive framework
Tom Henderson <tomh@tomh.org>
parents:
2965
diff
changeset
|
104 |
Ptr<Packet> packet; |
3271
023417b3bc5a
Move other applications to RecvFrom ()
Tom Henderson <tomh@tomh.org>
parents:
3269
diff
changeset
|
105 |
Address from; |
023417b3bc5a
Move other applications to RecvFrom ()
Tom Henderson <tomh@tomh.org>
parents:
3269
diff
changeset
|
106 |
while (packet = socket->RecvFrom (from)) |
3097
1b1661bbfa33
Plumb in socket receive pull model, in parallel to existing Receive framework
Tom Henderson <tomh@tomh.org>
parents:
2965
diff
changeset
|
107 |
{ |
1b1661bbfa33
Plumb in socket receive pull model, in parallel to existing Receive framework
Tom Henderson <tomh@tomh.org>
parents:
2965
diff
changeset
|
108 |
if (InetSocketAddress::IsMatchingType (from)) |
1b1661bbfa33
Plumb in socket receive pull model, in parallel to existing Receive framework
Tom Henderson <tomh@tomh.org>
parents:
2965
diff
changeset
|
109 |
{ |
3101 | 110 |
InetSocketAddress address = InetSocketAddress::ConvertFrom (from); |
3097
1b1661bbfa33
Plumb in socket receive pull model, in parallel to existing Receive framework
Tom Henderson <tomh@tomh.org>
parents:
2965
diff
changeset
|
111 |
NS_LOG_INFO ("Received " << packet->GetSize() << " bytes from " << |
1b1661bbfa33
Plumb in socket receive pull model, in parallel to existing Receive framework
Tom Henderson <tomh@tomh.org>
parents:
2965
diff
changeset
|
112 |
address.GetIpv4() << " [" << address << "]---'" << |
1b1661bbfa33
Plumb in socket receive pull model, in parallel to existing Receive framework
Tom Henderson <tomh@tomh.org>
parents:
2965
diff
changeset
|
113 |
packet->PeekData() << "'"); |
1b1661bbfa33
Plumb in socket receive pull model, in parallel to existing Receive framework
Tom Henderson <tomh@tomh.org>
parents:
2965
diff
changeset
|
114 |
} |
1b1661bbfa33
Plumb in socket receive pull model, in parallel to existing Receive framework
Tom Henderson <tomh@tomh.org>
parents:
2965
diff
changeset
|
115 |
m_rxTrace (packet, from); |
1b1661bbfa33
Plumb in socket receive pull model, in parallel to existing Receive framework
Tom Henderson <tomh@tomh.org>
parents:
2965
diff
changeset
|
116 |
} |
1b1661bbfa33
Plumb in socket receive pull model, in parallel to existing Receive framework
Tom Henderson <tomh@tomh.org>
parents:
2965
diff
changeset
|
117 |
} |
1b1661bbfa33
Plumb in socket receive pull model, in parallel to existing Receive framework
Tom Henderson <tomh@tomh.org>
parents:
2965
diff
changeset
|
118 |
|
1319 | 119 |
} // Namespace ns3 |