View | Details | Raw Unified | Return to bug 73
Collapse All | Expand All

(-)a/examples/simple-global-routing.cc (+19 lines)
 Lines 65-70    Link Here 
65
#include "ns3/ipv4-route.h"
65
#include "ns3/ipv4-route.h"
66
#include "ns3/point-to-point-topology.h"
66
#include "ns3/point-to-point-topology.h"
67
#include "ns3/onoff-application.h"
67
#include "ns3/onoff-application.h"
68
#include "ns3/packet-sink.h"
68
#include "ns3/global-route-manager.h"
69
#include "ns3/global-route-manager.h"
69
70
70
using namespace ns3;
71
using namespace ns3;
 Lines 151-156   int main (int argc, char *argv[]) Link Here 
151
  ooff->Start (Seconds (1.0));
152
  ooff->Start (Seconds (1.0));
152
  ooff->Stop (Seconds (10.0));
153
  ooff->Stop (Seconds (10.0));
153
154
155
  // Create a packet sink to receive these packets
156
  Ptr<PacketSink> sink = Create<PacketSink> (
157
    n3, 
158
    InetSocketAddress (Ipv4Address::GetAny (), 80), 
159
    "Udp");
160
  // Start the sink
161
  sink->Start (Seconds (1.0));
162
  sink->Stop (Seconds (10.0));
163
154
  // Create a similar flow from n3 to n1, starting at time 1.1 seconds
164
  // Create a similar flow from n3 to n1, starting at time 1.1 seconds
155
  ooff = Create<OnOffApplication> (
165
  ooff = Create<OnOffApplication> (
156
    n3, 
166
    n3, 
 Lines 162-167   int main (int argc, char *argv[]) Link Here 
162
  ooff->Start (Seconds (1.1));
172
  ooff->Start (Seconds (1.1));
163
  ooff->Stop (Seconds (10.0));
173
  ooff->Stop (Seconds (10.0));
164
174
175
  // Create a packet sink to receive these packets
176
  sink = Create<PacketSink> (
177
    n1, 
178
    InetSocketAddress (Ipv4Address::GetAny (), 80), 
179
    "Udp");
180
  // Start the sink
181
  sink->Start (Seconds (1.1));
182
  sink->Stop (Seconds (10.0));
183
165
  // Configure tracing of all enqueue, dequeue, and NetDevice receive events
184
  // Configure tracing of all enqueue, dequeue, and NetDevice receive events
166
  // Trace output will be sent to the simple-global-routing.tr file
185
  // Trace output will be sent to the simple-global-routing.tr file
167
  AsciiTrace asciitrace ("simple-global-routing.tr");
186
  AsciiTrace asciitrace ("simple-global-routing.tr");
(-)4c8b5cc01547 (+100 lines)
Added Link Here 
1
/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2
//
3
// Copyright (c) 2006 Georgia Tech Research Corporation
4
//
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
7
// published by the Free Software Foundation;
8
//
9
// This program is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
// GNU General Public License for more details.
13
//
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
16
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
//
18
#include "ns3/address.h"
19
#include "ns3/inet-socket-address.h"
20
#include "ns3/node.h"
21
#include "ns3/socket.h"
22
#include "ns3/simulator.h"
23
#include "ns3/socket-factory.h"
24
#include "ns3/packet.h"
25
#include "packet-sink.h"
26
27
using namespace std;
28
29
namespace ns3 {
30
31
// Constructors
32
33
PacketSink::PacketSink (Ptr<Node> n, 
34
                        const Address &local,
35
                        std::string iid)
36
  :  Application(n)
37
{
38
  Construct (n, local, iid);
39
}
40
41
void
42
PacketSink::Construct (Ptr<Node> n, 
43
                             const Address &local,
44
                             std::string iid)
45
{
46
  m_socket = 0;
47
  m_local = local;
48
  m_iid = iid;
49
}
50
51
PacketSink::~PacketSink()
52
{}
53
54
void
55
PacketSink::DoDispose (void)
56
{
57
  m_socket = 0;
58
59
  // chain up
60
  Application::DoDispose ();
61
}
62
63
64
// Application Methods
65
void PacketSink::StartApplication()    // Called at time specified by Start
66
{
67
  // Create the socket if not already
68
  if (!m_socket)
69
    {
70
      InterfaceId iid = InterfaceId::LookupByName (m_iid);
71
      Ptr<SocketFactory> socketFactory = 
72
        GetNode ()->QueryInterface<SocketFactory> (iid);
73
      m_socket = socketFactory->CreateSocket ();
74
      m_socket->Bind (m_local);
75
    }
76
  m_socket->SetRecvCallback((Callback<void, Ptr<Socket>, const Packet &,
77
    const Address &>) MakeCallback(&PacketSink::Receive, this));
78
}
79
80
void PacketSink::StopApplication()     // Called at time specified by Stop
81
{
82
  if (!m_socket) 
83
    {
84
      m_socket->SetRecvCallback((Callback<void, Ptr<Socket>, const Packet &,
85
                               const Address &>) NULL);
86
 
87
    }
88
}
89
90
// This callback body suggested by Joe Kopena's wiki
91
void PacketSink::Receive(Ptr<Socket> socket, const Packet &packet,
92
                       const Address &from) 
93
{
94
  InetSocketAddress address = InetSocketAddress::ConvertFrom (from);
95
  cout << __PRETTY_FUNCTION__ << ": Received " << packet.GetSize() <<
96
    " bytes from " << address.GetIpv4() << " [" << address << "]---'" <<
97
    packet.PeekData() << "'" << endl;
98
}
99
100
} // Namespace ns3
(-)4c8b5cc01547 (+71 lines)
Added Link Here 
1
/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2
//
3
// Copyright (c) 2006 Georgia Tech Research Corporation
4
//
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
7
// published by the Free Software Foundation;
8
//
9
// This program is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
// GNU General Public License for more details.
13
//
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
16
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
//
18
//
19
20
#ifndef __packet_sink_h__
21
#define __packet_sink_h__
22
23
#include "ns3/application.h"
24
#include "ns3/event-id.h"
25
#include "ns3/ptr.h"
26
27
namespace ns3 {
28
29
class Address;
30
class Socket;
31
class Packet;
32
33
class PacketSink : public Application 
34
{
35
public:
36
  /**
37
   * \param n node associated to this application
38
   * \param local local ip address
39
   * \param iid
40
   * \param ontime on time random variable
41
   * \param offtime off time random variable
42
   */
43
  PacketSink (Ptr<Node> n,
44
              const Address &local,
45
              std::string iid);
46
47
  virtual ~PacketSink ();
48
49
protected:
50
  virtual void DoDispose (void);
51
private:
52
  // inherited from Application base class.
53
  virtual void StartApplication (void);    // Called at time specified by Start
54
  virtual void StopApplication (void);     // Called at time specified by Stop
55
56
  void Construct (Ptr<Node> n,
57
                  const Address &local,
58
                  std::string iid);
59
60
  void Receive (Ptr<Socket> socket, const Packet& packet, const Address& from);
61
62
  Ptr<Socket>     m_socket;       // Associated socket
63
  Address         m_local;        // Local address to bind to
64
  std::string     m_iid;          // Protocol name (e.g., "Udp")
65
  
66
};
67
68
} // namespace ns3
69
70
#endif
71
(-)a/src/applications/wscript (+2 lines)
 Lines 4-12   def build(bld): Link Here 
4
    obj = bld.create_ns3_module('applications', ['node'])
4
    obj = bld.create_ns3_module('applications', ['node'])
5
    obj.source = [
5
    obj.source = [
6
        'onoff-application.cc',
6
        'onoff-application.cc',
7
        'packet-sink.cc',
7
        ]
8
        ]
8
9
9
    headers = bld.create_obj('ns3header')
10
    headers = bld.create_obj('ns3header')
10
    headers.source = [
11
    headers.source = [
11
        'onoff-application.h',
12
        'onoff-application.h',
13
        'packet-sink.h',
12
        ]
14
        ]
(-)a/src/node/ipv4-address.h (+12 lines)
 Lines 135-142   public: Link Here 
135
  static Ipv4Address ConvertFrom (const Address &address);
135
  static Ipv4Address ConvertFrom (const Address &address);
136
136
137
  static Ipv4Address GetZero (void);
137
  static Ipv4Address GetZero (void);
138
  /**
139
   * \brief Get Ipv4Address corresponding to INADDR_ANY constant
140
   *        (0.0.0.0)
141
   */
138
  static Ipv4Address GetAny (void);
142
  static Ipv4Address GetAny (void);
143
  /**
144
   * \brief Get Ipv4Address corresponding to INADDR_BROADCAST constant
145
   *        (255.255.255.255)
146
   */
139
  static Ipv4Address GetBroadcast (void);
147
  static Ipv4Address GetBroadcast (void);
148
  /**
149
   * \brief Get Ipv4Address corresponding to INADDR_LOOPBACK constant
150
   *        (127.0.0.1)
151
   */
140
  static Ipv4Address GetLoopback (void);
152
  static Ipv4Address GetLoopback (void);
141
private:
153
private:
142
  Address ConvertTo (void) const;
154
  Address ConvertTo (void) const;

Return to bug 73