author | Craig Dowell <craigdo@ee.washington.edu> |
Mon, 29 Oct 2007 12:48:01 -0700 | |
changeset 1867 | 16deaedc0380 |
parent 1535 | e08f62e85340 |
parent 1866 | e7dbcc4df546 |
child 2182 | 13c8ebd1a19e |
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" |
|
28 |
#include "packet-sink.h" |
|
29 |
||
30 |
using namespace std; |
|
31 |
||
32 |
namespace ns3 { |
|
33 |
||
1504
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1496
diff
changeset
|
34 |
NS_LOG_COMPONENT_DEFINE ("PacketSinkApplication"); |
1427
736fb30be782
Use NS_DEBUG instead of NS_DEBUG_UNCOND in PacketSink code.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
1319
diff
changeset
|
35 |
|
1319 | 36 |
// Constructors |
37 |
||
38 |
PacketSink::PacketSink (Ptr<Node> n, |
|
39 |
const Address &local, |
|
1456
7372ff049e61
Remove m_quiet variable, fix copyright
Tom Henderson <tomh@tomh.org>
parents:
1427
diff
changeset
|
40 |
std::string iid) |
1319 | 41 |
: Application(n) |
42 |
{ |
|
1456
7372ff049e61
Remove m_quiet variable, fix copyright
Tom Henderson <tomh@tomh.org>
parents:
1427
diff
changeset
|
43 |
Construct (n, local, iid); |
1319 | 44 |
} |
45 |
||
46 |
void |
|
47 |
PacketSink::Construct (Ptr<Node> n, |
|
48 |
const Address &local, |
|
1456
7372ff049e61
Remove m_quiet variable, fix copyright
Tom Henderson <tomh@tomh.org>
parents:
1427
diff
changeset
|
49 |
std::string iid) |
1319 | 50 |
{ |
51 |
m_socket = 0; |
|
52 |
m_local = local; |
|
53 |
m_iid = iid; |
|
54 |
} |
|
55 |
||
56 |
PacketSink::~PacketSink() |
|
57 |
{} |
|
58 |
||
59 |
void |
|
60 |
PacketSink::DoDispose (void) |
|
61 |
{ |
|
62 |
m_socket = 0; |
|
63 |
||
64 |
// chain up |
|
65 |
Application::DoDispose (); |
|
66 |
} |
|
67 |
||
68 |
||
69 |
// Application Methods |
|
70 |
void PacketSink::StartApplication() // Called at time specified by Start |
|
71 |
{ |
|
72 |
// Create the socket if not already |
|
73 |
if (!m_socket) |
|
74 |
{ |
|
75 |
InterfaceId iid = InterfaceId::LookupByName (m_iid); |
|
76 |
Ptr<SocketFactory> socketFactory = |
|
77 |
GetNode ()->QueryInterface<SocketFactory> (iid); |
|
78 |
m_socket = socketFactory->CreateSocket (); |
|
79 |
m_socket->Bind (m_local); |
|
80 |
} |
|
1867 | 81 |
|
1535
e08f62e85340
Fix callbacks in packet-sink
Tom Henderson <tomh@tomh.org>
parents:
1504
diff
changeset
|
82 |
m_socket->SetRecvCallback (MakeCallback(&PacketSink::Receive, this)); |
1319 | 83 |
} |
84 |
||
85 |
void PacketSink::StopApplication() // Called at time specified by Stop |
|
86 |
{ |
|
87 |
if (!m_socket) |
|
88 |
{ |
|
1535
e08f62e85340
Fix callbacks in packet-sink
Tom Henderson <tomh@tomh.org>
parents:
1504
diff
changeset
|
89 |
m_socket->SetRecvCallback (MakeNullCallback<void, Ptr<Socket>, |
1867 | 90 |
Ptr<Packet>, const Address &> ()); |
1319 | 91 |
} |
92 |
} |
|
93 |
||
1456
7372ff049e61
Remove m_quiet variable, fix copyright
Tom Henderson <tomh@tomh.org>
parents:
1427
diff
changeset
|
94 |
// This LOG output inspired by the application on Joseph Kopena's wiki |
1866
e7dbcc4df546
do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1504
diff
changeset
|
95 |
void PacketSink::Receive(Ptr<Socket> socket, Ptr<Packet> packet, |
1319 | 96 |
const Address &from) |
97 |
{ |
|
1456
7372ff049e61
Remove m_quiet variable, fix copyright
Tom Henderson <tomh@tomh.org>
parents:
1427
diff
changeset
|
98 |
if (InetSocketAddress::IsMatchingType (from)) |
1319 | 99 |
{ |
1456
7372ff049e61
Remove m_quiet variable, fix copyright
Tom Henderson <tomh@tomh.org>
parents:
1427
diff
changeset
|
100 |
InetSocketAddress address = InetSocketAddress::ConvertFrom (from); |
1866
e7dbcc4df546
do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1504
diff
changeset
|
101 |
NS_LOG_INFO ("Received " << packet->GetSize() << " bytes from " << |
1504
36ecc970ba96
checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents:
1496
diff
changeset
|
102 |
address.GetIpv4() << " [" << address << "]---'" << |
1866
e7dbcc4df546
do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1504
diff
changeset
|
103 |
packet->PeekData() << "'"); |
1456
7372ff049e61
Remove m_quiet variable, fix copyright
Tom Henderson <tomh@tomh.org>
parents:
1427
diff
changeset
|
104 |
// TODO: Add a tracing source here |
1319 | 105 |
} |
106 |
} |
|
107 |
||
108 |
} // Namespace ns3 |