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

(-)a/doc/release_steps.txt (-1 / +1 lines)
 Lines 9-15   3. add current version of waf script fro Link Here 
9
   - svn checkout http://waf.googlecode.com/svn/tags/ns3/ waf
9
   - svn checkout http://waf.googlecode.com/svn/tags/ns3/ waf
10
   - build waf script and put it into top of ns-3-dev
10
   - build waf script and put it into top of ns-3-dev
11
4. cd ns-3-dev; ./waf configure; ./waf dist
11
4. cd ns-3-dev; ./waf configure; ./waf dist
12
5. test tarball on release platforms (run-tests and simple-p2p)
12
5. test tarball on release platforms (run-tests and simple-point-to-point)
13
6. tag ns-3-dev with "release ns-3.0.X"
13
6. tag ns-3-dev with "release ns-3.0.X"
14
  - hg tag "release ns-3.0.x"
14
  - hg tag "release ns-3.0.x"
15
  - hg push 
15
  - hg push 
(-)a/examples/simple-p2p.cc (-191 lines)
Removed Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * This program is free software; you can redistribute it and/or modify
4
 * it under the terms of the GNU General Public License version 2 as
5
 * published by the Free Software Foundation;
6
 *
7
 * This program is distributed in the hope that it will be useful,
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 * GNU General Public License for more details.
11
 *
12
 * You should have received a copy of the GNU General Public License
13
 * along with this program; if not, write to the Free Software
14
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
15
 *
16
 * ns-2 simple.tcl script (ported from ns-2)
17
 * Originally authored by Steve McCanne, 12/19/1996
18
 */
19
20
// Port of ns-2/tcl/ex/simple.tcl to ns-3
21
//
22
// Network topology
23
//
24
//  n0
25
//     \ 5 Mb/s, 2ms
26
//      \          1.5Mb/s, 10ms
27
//       n2 -------------------------n3
28
//      /
29
//     / 5 Mb/s, 2ms
30
//   n1
31
//
32
// - all links are p2p links with indicated one-way BW/delay
33
// - CBR/UDP flows from n0 to n3, and from n3 to n1
34
// - FTP/TCP flow from n0 to n3, starting at time 1.2 to time 1.35 sec.
35
// - UDP packet size of 210 bytes, with per-packet interval 0.00375 sec.
36
//   (i.e., DataRate of 448,000 bps)
37
// - DropTail queues 
38
// - Tracing of queues and packet receptions to file "simple-p2p.tr"
39
40
#include <iostream>
41
#include <fstream>
42
#include <string>
43
#include <cassert>
44
45
#include "ns3/command-line.h"
46
#include "ns3/default-value.h"
47
#include "ns3/ptr.h"
48
#include "ns3/random-variable.h"
49
50
#include "ns3/simulator.h"
51
#include "ns3/nstime.h"
52
#include "ns3/data-rate.h"
53
54
#include "ns3/ascii-trace.h"
55
#include "ns3/pcap-trace.h"
56
#include "ns3/internet-node.h"
57
#include "ns3/p2p-channel.h"
58
#include "ns3/p2p-net-device.h"
59
#include "ns3/mac-address.h"
60
#include "ns3/ipv4-address.h"
61
#include "ns3/ipv4.h"
62
#include "ns3/socket.h"
63
#include "ns3/ipv4-route.h"
64
#include "ns3/p2p-topology.h"
65
#include "ns3/onoff-application.h"
66
67
using namespace ns3;
68
69
int main (int argc, char *argv[])
70
{
71
72
  // Users may find it convenient to turn on explicit debugging
73
  // for selected modules; the below lines suggest how to do this
74
#if 0 
75
  DebugComponentEnable("Object");
76
  DebugComponentEnable("Queue");
77
  DebugComponentEnable("DropTailQueue");
78
  DebugComponentEnable("Channel");
79
  DebugComponentEnable("PointToPointChannel");
80
  DebugComponentEnable("PointToPointNetDevice");
81
#endif
82
83
  // Set up some default values for the simulation.  Use the Bind()
84
  // technique to tell the system what subclass of Queue to use,
85
  // and what the queue limit is
86
87
  // The below Bind command tells the queue factory which class to
88
  // instantiate, when the queue factory is invoked in the topology code
89
  Bind ("Queue", "DropTailQueue");
90
91
  Bind ("OnOffApplicationPacketSize", "210");
92
  Bind ("OnOffApplicationDataRate", "448kb/s");
93
94
  //Bind ("DropTailQueue::m_maxPackets", 30);   
95
96
  // Allow the user to override any of the defaults and the above
97
  // Bind()s at run-time, via command-line arguments
98
  CommandLine::Parse (argc, argv);
99
100
  // Here, we will explicitly create four nodes.  In more sophisticated
101
  // topologies, we could configure a node factory.
102
  Ptr<Node> n0 = Create<InternetNode> ();
103
  Ptr<Node> n1 = Create<InternetNode> (); 
104
  Ptr<Node> n2 = Create<InternetNode> (); 
105
  Ptr<Node> n3 = Create<InternetNode> ();
106
107
  // We create the channels first without any IP addressing information
108
  Ptr<PointToPointChannel> channel0 = 
109
    PointToPointTopology::AddPointToPointLink (
110
      n0, n2, DataRate(5000000), MilliSeconds(2));
111
112
  Ptr<PointToPointChannel> channel1 = 
113
    PointToPointTopology::AddPointToPointLink (
114
      n1, n2, DataRate(5000000), MilliSeconds(2));
115
  
116
  Ptr<PointToPointChannel> channel2 = 
117
    PointToPointTopology::AddPointToPointLink (
118
      n2, n3, DataRate(1500000), MilliSeconds(10));
119
  
120
  // Later, we add IP addresses.  
121
  PointToPointTopology::AddIpv4Addresses (
122
      channel0, n0, Ipv4Address("10.1.1.1"),
123
      n2, Ipv4Address("10.1.1.2"));
124
  
125
  PointToPointTopology::AddIpv4Addresses (
126
      channel1, n1, Ipv4Address("10.1.2.1"),
127
      n2, Ipv4Address("10.1.2.2"));
128
  
129
  PointToPointTopology::AddIpv4Addresses (
130
      channel2, n2, Ipv4Address("10.1.3.1"),
131
      n3, Ipv4Address("10.1.3.2"));
132
133
  // Finally, we add static routes.  These three steps (Channel and
134
  // NetDevice creation, IP Address assignment, and routing) are 
135
  // separated because there may be a need to postpone IP Address
136
  // assignment (emulation) or modify to use dynamic routing
137
  PointToPointTopology::AddIpv4Routes(n0, n2, channel0);
138
  PointToPointTopology::AddIpv4Routes(n1, n2, channel1);
139
  PointToPointTopology::AddIpv4Routes(n2, n3, channel2);
140
141
142
  // Create the OnOff application to send UDP datagrams of size
143
  // 210 bytes at a rate of 448 Kb/s
144
  Ptr<OnOffApplication> ooff = Create<OnOffApplication> (
145
    n0, 
146
    Ipv4Address("10.1.3.2"), 
147
    80, 
148
    "Udp",
149
    ConstantVariable(1), 
150
    ConstantVariable(0));
151
  // Start the application
152
  ooff->Start(Seconds(1.0));
153
  ooff->Stop (Seconds(10.0));
154
155
  // Create a similar flow from n3 to n1, starting at time 1.1 seconds
156
  ooff = Create<OnOffApplication> (
157
    n3, 
158
    Ipv4Address("10.1.2.1"), 
159
    80, 
160
    "Udp",
161
    ConstantVariable(1), 
162
    ConstantVariable(0));
163
  // Start the application
164
  ooff->Start(Seconds(1.1));
165
  ooff->Stop (Seconds(10.0));
166
167
  // Here, finish off packet routing configuration
168
  // This will likely set by some global StaticRouting object in the future
169
  Ptr<Ipv4> ipv4;
170
  ipv4 = n0->QueryInterface<Ipv4> (Ipv4::iid);
171
  ipv4->SetDefaultRoute (Ipv4Address ("10.1.1.2"), 1);
172
  ipv4 = n3->QueryInterface<Ipv4> (Ipv4::iid);
173
  ipv4->SetDefaultRoute (Ipv4Address ("10.1.3.1"), 1);
174
  
175
  // Configure tracing of all enqueue, dequeue, and NetDevice receive events
176
  // Trace output will be sent to the simple-p2p.tr file
177
  AsciiTrace asciitrace ("simple-p2p.tr");
178
  asciitrace.TraceAllQueues ();
179
  asciitrace.TraceAllNetDeviceRx ();
180
181
  // Also configure some tcpdump traces; each interface will be traced
182
  // The output files will be named simple-p2p.pcap-<nodeId>-<interfaceId>
183
  // and can be read by the "tcpdump -r" command (use "-tt" option to
184
  // display timestamps correctly)
185
  PcapTrace pcaptrace ("simple-p2p.pcap");
186
  pcaptrace.TraceAllIp ();
187
188
  Simulator::Run ();
189
    
190
  Simulator::Destroy ();
191
}
(-)7a81f1ef8c74 (+192 lines)
Added Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * This program is free software; you can redistribute it and/or modify
4
 * it under the terms of the GNU General Public License version 2 as
5
 * published by the Free Software Foundation;
6
 *
7
 * This program is distributed in the hope that it will be useful,
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 * GNU General Public License for more details.
11
 *
12
 * You should have received a copy of the GNU General Public License
13
 * along with this program; if not, write to the Free Software
14
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
15
 *
16
 * ns-2 simple.tcl script (ported from ns-2)
17
 * Originally authored by Steve McCanne, 12/19/1996
18
 */
19
20
// Port of ns-2/tcl/ex/simple.tcl to ns-3
21
//
22
// Network topology
23
//
24
//  n0
25
//     \ 5 Mb/s, 2ms
26
//      \          1.5Mb/s, 10ms
27
//       n2 -------------------------n3
28
//      /
29
//     / 5 Mb/s, 2ms
30
//   n1
31
//
32
// - all links are point-to-point links with indicated one-way BW/delay
33
// - CBR/UDP flows from n0 to n3, and from n3 to n1
34
// - FTP/TCP flow from n0 to n3, starting at time 1.2 to time 1.35 sec.
35
// - UDP packet size of 210 bytes, with per-packet interval 0.00375 sec.
36
//   (i.e., DataRate of 448,000 bps)
37
// - DropTail queues 
38
// - Tracing of queues and packet receptions to file "simple-point-to-point.tr"
39
40
#include <iostream>
41
#include <fstream>
42
#include <string>
43
#include <cassert>
44
45
#include "ns3/command-line.h"
46
#include "ns3/default-value.h"
47
#include "ns3/ptr.h"
48
#include "ns3/random-variable.h"
49
50
#include "ns3/simulator.h"
51
#include "ns3/nstime.h"
52
#include "ns3/data-rate.h"
53
54
#include "ns3/ascii-trace.h"
55
#include "ns3/pcap-trace.h"
56
#include "ns3/internet-node.h"
57
#include "ns3/point-to-point-channel.h"
58
#include "ns3/point-to-point-net-device.h"
59
#include "ns3/mac-address.h"
60
#include "ns3/ipv4-address.h"
61
#include "ns3/ipv4.h"
62
#include "ns3/socket.h"
63
#include "ns3/ipv4-route.h"
64
#include "ns3/point-to-point-topology.h"
65
#include "ns3/onoff-application.h"
66
67
using namespace ns3;
68
69
int main (int argc, char *argv[])
70
{
71
72
  // Users may find it convenient to turn on explicit debugging
73
  // for selected modules; the below lines suggest how to do this
74
#if 0 
75
  DebugComponentEnable("Object");
76
  DebugComponentEnable("Queue");
77
  DebugComponentEnable("DropTailQueue");
78
  DebugComponentEnable("Channel");
79
  DebugComponentEnable("PointToPointChannel");
80
  DebugComponentEnable("PointToPointNetDevice");
81
#endif
82
83
  // Set up some default values for the simulation.  Use the Bind()
84
  // technique to tell the system what subclass of Queue to use,
85
  // and what the queue limit is
86
87
  // The below Bind command tells the queue factory which class to
88
  // instantiate, when the queue factory is invoked in the topology code
89
  Bind ("Queue", "DropTailQueue");
90
91
  Bind ("OnOffApplicationPacketSize", "210");
92
  Bind ("OnOffApplicationDataRate", "448kb/s");
93
94
  //Bind ("DropTailQueue::m_maxPackets", 30);   
95
96
  // Allow the user to override any of the defaults and the above
97
  // Bind()s at run-time, via command-line arguments
98
  CommandLine::Parse (argc, argv);
99
100
  // Here, we will explicitly create four nodes.  In more sophisticated
101
  // topologies, we could configure a node factory.
102
  Ptr<Node> n0 = Create<InternetNode> ();
103
  Ptr<Node> n1 = Create<InternetNode> (); 
104
  Ptr<Node> n2 = Create<InternetNode> (); 
105
  Ptr<Node> n3 = Create<InternetNode> ();
106
107
  // We create the channels first without any IP addressing information
108
  Ptr<PointToPointChannel> channel0 = 
109
    PointToPointTopology::AddPointToPointLink (
110
      n0, n2, DataRate(5000000), MilliSeconds(2));
111
112
  Ptr<PointToPointChannel> channel1 = 
113
    PointToPointTopology::AddPointToPointLink (
114
      n1, n2, DataRate(5000000), MilliSeconds(2));
115
  
116
  Ptr<PointToPointChannel> channel2 = 
117
    PointToPointTopology::AddPointToPointLink (
118
      n2, n3, DataRate(1500000), MilliSeconds(10));
119
  
120
  // Later, we add IP addresses.  
121
  PointToPointTopology::AddIpv4Addresses (
122
      channel0, n0, Ipv4Address("10.1.1.1"),
123
      n2, Ipv4Address("10.1.1.2"));
124
  
125
  PointToPointTopology::AddIpv4Addresses (
126
      channel1, n1, Ipv4Address("10.1.2.1"),
127
      n2, Ipv4Address("10.1.2.2"));
128
  
129
  PointToPointTopology::AddIpv4Addresses (
130
      channel2, n2, Ipv4Address("10.1.3.1"),
131
      n3, Ipv4Address("10.1.3.2"));
132
133
  // Finally, we add static routes.  These three steps (Channel and
134
  // NetDevice creation, IP Address assignment, and routing) are 
135
  // separated because there may be a need to postpone IP Address
136
  // assignment (emulation) or modify to use dynamic routing
137
  PointToPointTopology::AddIpv4Routes(n0, n2, channel0);
138
  PointToPointTopology::AddIpv4Routes(n1, n2, channel1);
139
  PointToPointTopology::AddIpv4Routes(n2, n3, channel2);
140
141
142
  // Create the OnOff application to send UDP datagrams of size
143
  // 210 bytes at a rate of 448 Kb/s
144
  Ptr<OnOffApplication> ooff = Create<OnOffApplication> (
145
    n0, 
146
    Ipv4Address("10.1.3.2"), 
147
    80, 
148
    "Udp",
149
    ConstantVariable(1), 
150
    ConstantVariable(0));
151
  // Start the application
152
  ooff->Start(Seconds(1.0));
153
  ooff->Stop (Seconds(10.0));
154
155
  // Create a similar flow from n3 to n1, starting at time 1.1 seconds
156
  ooff = Create<OnOffApplication> (
157
    n3, 
158
    Ipv4Address("10.1.2.1"), 
159
    80, 
160
    "Udp",
161
    ConstantVariable(1), 
162
    ConstantVariable(0));
163
  // Start the application
164
  ooff->Start(Seconds(1.1));
165
  ooff->Stop (Seconds(10.0));
166
167
  // Here, finish off packet routing configuration
168
  // This will likely set by some global StaticRouting object in the future
169
  Ptr<Ipv4> ipv4;
170
  ipv4 = n0->QueryInterface<Ipv4> (Ipv4::iid);
171
  ipv4->SetDefaultRoute (Ipv4Address ("10.1.1.2"), 1);
172
  ipv4 = n3->QueryInterface<Ipv4> (Ipv4::iid);
173
  ipv4->SetDefaultRoute (Ipv4Address ("10.1.3.1"), 1);
174
  
175
  // Configure tracing of all enqueue, dequeue, and NetDevice receive events
176
  // Trace output will be sent to the simple-point-to-point.tr file
177
  AsciiTrace asciitrace ("simple-point-to-point.tr");
178
  asciitrace.TraceAllQueues ();
179
  asciitrace.TraceAllNetDeviceRx ();
180
181
  // Also configure some tcpdump traces; each interface will be traced
182
  // The output files will be named 
183
  // simple-point-to-point.pcap-<nodeId>-<interfaceId>
184
  // and can be read by the "tcpdump -r" command (use "-tt" option to
185
  // display timestamps correctly)
186
  PcapTrace pcaptrace ("simple-point-to-point.pcap");
187
  pcaptrace.TraceAllIp ();
188
189
  Simulator::Run ();
190
    
191
  Simulator::Destroy ();
192
}
(-)a/examples/wscript (-1 / +1 lines)
 Lines 9-13   def build(bld): Link Here 
9
        obj.source = source
9
        obj.source = source
10
        return obj
10
        return obj
11
        
11
        
12
    obj = create_ns_prog('simple-p2p', 'simple-p2p.cc', deps=['p2p', 'internet-node'])
12
    obj = create_ns_prog('simple-point-to-point', 'simple-point-to-point.cc', deps=['point-to-point', 'internet-node'])
13
13
(-)a/samples/wscript (-2 / +1 lines)
 Lines 18-24   def build(bld): Link Here 
18
    obj = create_ns_prog('main-test', 'main-test.cc')
18
    obj = create_ns_prog('main-test', 'main-test.cc')
19
    obj = create_ns_prog('main-simple', 'main-simple.cc',
19
    obj = create_ns_prog('main-simple', 'main-simple.cc',
20
                         deps=['node', 'internet-node', 'applications'])
20
                         deps=['node', 'internet-node', 'applications'])
21
    #obj = create_ns_prog('main-simple-p2p', 'main-simple-p2p.cc', deps=['node', 'p2p'])
22
    obj = create_ns_prog('main-default-value', 'main-default-value.cc',
21
    obj = create_ns_prog('main-default-value', 'main-default-value.cc',
23
                         deps=['core', 'simulator', 'node', 'p2p'])
22
                         deps=['core', 'simulator', 'node'])
24
23
(-)a/src/devices/p2p/p2p-channel.cc (-142 lines)
Removed Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * Copyright (c) 2007 University of Washington
4
 * All rights reserved.
5
 *
6
 * This program is free software; you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License version 2 as
8
 * published by the Free Software Foundation;
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
 *
19
 * Author: Craig Dowell <craigdo@ee.washington.edu>
20
 */
21
22
#include "p2p-channel.h"
23
#include "p2p-net-device.h"
24
#include "ns3/packet.h"
25
#include "ns3/simulator.h"
26
#include "ns3/debug.h"
27
28
NS_DEBUG_COMPONENT_DEFINE ("PointToPointChannel");
29
30
namespace ns3 {
31
32
//
33
// By default, you get a channel with the name "PointToPoint Channel" that 
34
// has an "infitely" fast transmission speed and zero delay.
35
PointToPointChannel::PointToPointChannel()
36
: 
37
  Channel ("PointToPoint Channel"), 
38
  m_bps (DataRate(0xffffffff)),
39
  m_delay (Seconds(0)),
40
  m_nDevices(0)
41
{
42
  NS_DEBUG("PointToPointChannel::PointToPointChannel ()");
43
}
44
45
PointToPointChannel::PointToPointChannel(
46
  const DataRate& bps, 
47
  const Time& delay)
48
: 
49
  Channel ("PointToPoint Channel"), 
50
  m_bps (bps),
51
  m_delay (delay),
52
  m_nDevices(0)
53
{
54
  NS_DEBUG("PointToPointChannel::PointToPointChannel (" << Channel::GetName() 
55
    << ", " << bps.GetBitRate() << ", " << delay << ")");
56
}
57
58
PointToPointChannel::PointToPointChannel(
59
  const std::string& name,
60
  const DataRate& bps, 
61
  const Time& delay)
62
: 
63
  Channel (name),
64
  m_bps (bps), 
65
  m_delay (delay),
66
  m_nDevices(0)
67
{
68
  NS_DEBUG("PointToPointChannel::PointToPointChannel (" << name << ", " << 
69
    bps.GetBitRate() << ", " << delay << ")");
70
}
71
72
  void
73
PointToPointChannel::Attach(Ptr<PointToPointNetDevice> device)
74
{
75
  NS_DEBUG("PointToPointChannel::Attach (" << device << ")");
76
  NS_ASSERT(m_nDevices < N_DEVICES && "Only two devices permitted");
77
  NS_ASSERT(device != 0);
78
79
  m_link[m_nDevices++].m_src = device;
80
//
81
// If we have both devices connected to the channel, then finish introducing
82
// the two halves and set the links to IDLE.
83
//
84
  if (m_nDevices == N_DEVICES)
85
    {
86
      m_link[0].m_dst = m_link[1].m_src;
87
      m_link[1].m_dst = m_link[0].m_src;
88
      m_link[0].m_state = IDLE;
89
      m_link[1].m_state = IDLE;
90
    }
91
}
92
93
bool PointToPointChannel::TransmitStart(Packet& p,
94
                                        Ptr<PointToPointNetDevice> src,
95
                                        const Time& txTime)
96
{
97
  NS_DEBUG ("PointToPointChannel::TransmitStart (" << &p << ", " << src << 
98
            ")");
99
  NS_DEBUG ("PointToPointChannel::TransmitStart (): UID is " << 
100
            p.GetUid () << ")");
101
102
  NS_ASSERT(m_link[0].m_state != INITIALIZING);
103
  NS_ASSERT(m_link[1].m_state != INITIALIZING);
104
105
  uint32_t wire = src == m_link[0].m_src ? 0 : 1;
106
107
  // Here we schedule the packet receive event at the receiver,
108
  // which simplifies this model quite a bit.  The channel just
109
  // adds the propagation delay time
110
  Simulator::Schedule (txTime + m_delay,
111
                       &PointToPointNetDevice::Receive,
112
                       m_link[wire].m_dst, p);
113
  return true;
114
}
115
116
uint32_t 
117
PointToPointChannel::GetNDevices (void) const
118
{
119
  return m_nDevices;
120
}
121
122
Ptr<NetDevice>
123
PointToPointChannel::GetDevice (uint32_t i) const
124
{
125
  NS_ASSERT(i < 2);
126
  return m_link[i].m_src;
127
}
128
129
const DataRate&
130
PointToPointChannel::GetDataRate (void)
131
{
132
  return m_bps;
133
}
134
135
const Time&
136
PointToPointChannel::GetDelay (void)
137
{
138
  return m_delay;
139
}
140
141
142
} // namespace ns3
(-)a/src/devices/p2p/p2p-channel.h (-127 lines)
Removed Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * Copyright (c) 2007 University of Washington
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
#ifndef POINT_TO_POINT_CHANNEL_H
20
#define POINT_TO_POINT_CHANNEL_H
21
22
#include <list>
23
#include "ns3/channel.h"
24
#include "ns3/ptr.h"
25
#include "ns3/packet.h"
26
#include "ns3/nstime.h"
27
#include "ns3/data-rate.h"
28
29
namespace ns3 {
30
31
class PointToPointNetDevice;
32
33
/**
34
 * \brief Simple Point To Point Channel.
35
 *
36
 * This class represents a very simple point to point channel.  Think full
37
 * duplex RS-232 or RS-422 with null modem and no handshaking.  There is no
38
 * multi-drop capability on this channel -- there can be a maximum of two 
39
 * point-to-point net devices connected.  Once we start talking about multi-
40
 * drop, or CSMA, or some other sharing mechanism, things begin getting 
41
 * complicated quickly.  Rather than invent some ad-hoc mechanism, we just
42
 * Keep It Simple everywhere.
43
 *
44
 * When the channel is instaniated, the constructor takes parameters for
45
 * a single speed, in bits per second, and a speed-of-light delay time as a
46
 * Time object.  Both directions use the same speed and delay time.
47
 *
48
 * There are two "wires" in the channel.  The first device connected gets the
49
 * [0] wire to transmit on.  The second device gets the [1] wire.  There is a
50
 * state (IDLE, TRANSMITTING) associated with each wire.
51
 */
52
class PointToPointChannel : public Channel {
53
public:
54
// Each point to point link has exactly two net devices
55
  static const int N_DEVICES = 2;
56
  /**
57
   * \brief Create a PointToPointChannel
58
   *
59
   * By default, you get a channel with the name "PointToPoint Channel" that
60
   * has an "infitely" fast transmission speed and zero delay.
61
   */
62
  PointToPointChannel ();
63
  
64
  /**
65
   * \brief Create a PointToPointChannel
66
   *
67
   * \param bps The maximum bitrate of the channel
68
   * \param delay Transmission delay through the channel
69
   */  
70
  PointToPointChannel (const DataRate& bps, const Time& delay);
71
  
72
  /**
73
   * \brief Create a PointToPointChannel
74
   *
75
   * \param name the name of the channel for identification purposes
76
   * \param bps The maximum bitrate of the channel
77
   * \param delay Transmission delay through the channel
78
   */
79
  PointToPointChannel (const std::string& name,
80
                 const DataRate& bps, const Time& delay);
81
82
  /**
83
   * \brief Attach a given netdevice to this channel
84
   * \param device pointer to the netdevice to attach to the channel
85
   */
86
  void Attach (Ptr<PointToPointNetDevice> device);
87
  bool TransmitStart (Packet& p, Ptr<PointToPointNetDevice> src,
88
                      const Time& txTime);
89
  // Below two not needed
90
  //bool TransmitEnd (Packet &p, Ptr<PointToPointNetDevice> src);
91
  //void PropagationCompleteEvent(Packet p, Ptr<PointToPointNetDevice> src);
92
93
94
  virtual uint32_t GetNDevices (void) const;
95
  virtual Ptr<NetDevice> GetDevice (uint32_t i) const;
96
97
  virtual const DataRate& GetDataRate (void);
98
  virtual const Time&     GetDelay (void);
99
100
private:
101
  DataRate      m_bps;
102
  Time          m_delay;
103
  int32_t       m_nDevices;
104
105
  enum WireState
106
    {
107
      INITIALIZING,
108
      IDLE,
109
      TRANSMITTING,
110
      PROPAGATING
111
    };
112
113
  class Link
114
  {
115
  public:
116
    Link() : m_state (INITIALIZING), m_src (0), m_dst (0) {}
117
    WireState              m_state;
118
    Ptr<PointToPointNetDevice> m_src;
119
    Ptr<PointToPointNetDevice> m_dst;
120
  };
121
    
122
  Link    m_link[N_DEVICES];
123
};
124
125
} // namespace ns3
126
127
#endif /* POINT_TO_POINT_CHANNEL_H */
(-)a/src/devices/p2p/p2p-net-device.cc (-275 lines)
Removed Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * Copyright (c) 2005,2006 INRIA
4
 * All rights reserved.
5
 *
6
 * This program is free software; you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License version 2 as
8
 * published by the Free Software Foundation;
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
 *
19
 * Author:  Craig Dowell <craigdo@ee.washington.edu>
20
 * Revised: George Riley <riley@ece.gatech.edu>
21
 */
22
23
#include <iostream>
24
#include <cassert>
25
#include "ns3/debug.h"
26
#include "ns3/queue.h"
27
#include "ns3/simulator.h"
28
#include "ns3/composite-trace-resolver.h"
29
#include "p2p-net-device.h"
30
#include "p2p-channel.h"
31
32
NS_DEBUG_COMPONENT_DEFINE ("PointToPointNetDevice");
33
34
namespace ns3 {
35
36
DataRateDefaultValue PointToPointNetDevice::g_defaultRate(
37
           "PointToPointLinkDataRate", 
38
           "The default data rate for point to point links",
39
           DataRate ("10Mb/s"));
40
41
  PointToPointNetDevice::PointToPointNetDevice (Ptr<Node> node,
42
                                                const DataRate& rate) 
43
: 
44
  NetDevice(node, MacAddress (6)), 
45
  m_txMachineState (READY),
46
  m_bps (rate),
47
  m_tInterframeGap (Seconds(0)),
48
  m_channel (0), 
49
  m_queue (0),
50
  m_rxTrace ()
51
{
52
  NS_DEBUG ("PointToPointNetDevice::PointToPointNetDevice (" << node << ")");
53
54
  // BUGBUG FIXME
55
  //
56
  // You _must_ support broadcast to get any sort of packet from the ARP layer.
57
  EnableBroadcast (MacAddress ("ff:ff:ff:ff:ff:ff"));
58
  EnableMulticast();
59
  EnablePointToPoint();
60
}
61
62
PointToPointNetDevice::~PointToPointNetDevice()
63
{
64
  NS_DEBUG ("PointToPointNetDevice::~PointToPointNetDevice ()");
65
  m_queue = 0;
66
}
67
68
//
69
// Copy constructor for PointToPointNetDevice.
70
//
71
// We use the underlying NetDevice copy constructor to get the base class
72
// copied.  These just remain as is (e.g. you get the same name, the same
73
// MAC address).  If you need to fix them up, YOU, the copier need to do 
74
// that.
75
// 
76
// The things we need to be careful of are the channel, the queue and the
77
// trace callback.  If the channel pointer is non-zero, we copy the pointer 
78
// and add a reference.  If the queue is non-zero, we copy it using the queue
79
// assignment operator.  We don't mess with the trace -- we just reset it.
80
// We're assuming that the tracing will be set up after the topology creation
81
// phase and this won't actually matter.
82
//
83
// GFR Comments.  Don't see where the "copy the pointer and add reference"
84
// stated above is done. Can original author please comment and/or fix.
85
// Shouldn't the queue pointer also bump the refcount?
86
PointToPointNetDevice::PointToPointNetDevice (const PointToPointNetDevice& nd)
87
: 
88
  NetDevice(nd), 
89
  m_txMachineState(READY),
90
  m_bps (nd.m_bps),
91
  m_tInterframeGap (nd.m_tInterframeGap),
92
  m_channel(nd.m_channel), 
93
  m_queue(0),
94
  m_rxTrace ()
95
{
96
  NS_DEBUG ("PointToPointNetDevice::PointToPointNetDevice (" << &nd << ")");
97
98
  if (nd.m_queue)
99
    {
100
      m_queue = nd.m_queue;
101
    }
102
    
103
}
104
105
  // GFR COmments...shouldn't this decrement the refcount instead
106
  // of just nil-ing out the pointer?  Don't understand this.
107
void PointToPointNetDevice::DoDispose()
108
{
109
  m_channel = 0;
110
  NetDevice::DoDispose ();
111
}
112
113
//
114
// Assignment operator for PointToPointNetDevice.
115
//
116
//
117
PointToPointNetDevice&
118
PointToPointNetDevice::operator= (const PointToPointNetDevice& nd)
119
{
120
  NS_DEBUG ("PointToPointNetDevice::operator= (" << &nd << ")");
121
  // FIXME.  Not sure what to do here
122
  // GFR Note.  I would suggest dis-allowing netdevice assignment,
123
  // as well as pass-by-value (ie. copy constructor).
124
  // This resolves some of the questions above about copy constructors.
125
  // Why should we ever copy or assign a net device?
126
  return *this;
127
}
128
129
void PointToPointNetDevice::SetDataRate(const DataRate& bps)
130
{
131
  m_bps = bps;
132
}
133
134
void PointToPointNetDevice::SetInterframeGap(const Time& t)
135
{
136
  m_tInterframeGap = t;
137
}
138
139
bool PointToPointNetDevice::SendTo (Packet& p, const MacAddress& dest)
140
{
141
  NS_DEBUG ("PointToPointNetDevice::SendTo (" << &p << ", " << &dest << ")");
142
  NS_DEBUG ("PointToPointNetDevice::SendTo (): UID is " << p.GetUid () << ")");
143
144
  // GFR Comment. Why is this an assertion? Can't a link legitimately
145
  // "go down" during the simulation?  Shouldn't we just wait for it
146
  // to come back up?
147
  NS_ASSERT (IsLinkUp ());
148
149
//
150
// This class simulates a point to point device.  In the case of a serial
151
// link, this means that we're simulating something like a UART.
152
//
153
//
154
// If there's a transmission in progress, we enque the packet for later
155
// trnsmission; otherwise we send it now.
156
    if (m_txMachineState == READY) 
157
      {
158
        return TransmitStart (p);
159
      }
160
    else
161
      {
162
        return m_queue->Enqueue(p);
163
      }
164
}
165
166
  bool
167
PointToPointNetDevice::TransmitStart (Packet &p)
168
{
169
  NS_DEBUG ("PointToPointNetDevice::TransmitStart (" << &p << ")");
170
  NS_DEBUG (
171
    "PointToPointNetDevice::TransmitStart (): UID is " << p.GetUid () << ")");
172
//
173
// This function is called to start the process of transmitting a packet.
174
// We need to tell the channel that we've started wiggling the wire and
175
// schedule an event that will be executed when the transmission is complete.
176
//
177
  NS_ASSERT_MSG(m_txMachineState == READY, "Must be READY to transmit");
178
  m_txMachineState = BUSY;
179
  Time txTime = Seconds (m_bps.CalculateTxTime(p.GetSize()));
180
  Time txCompleteTime = txTime + m_tInterframeGap;
181
182
  NS_DEBUG ("PointToPointNetDevice::TransmitStart (): " <<
183
    "Schedule TransmitCompleteEvent in " << 
184
    txCompleteTime.GetSeconds () << "sec");
185
  // Schedule the tx complete event
186
  Simulator::Schedule (txCompleteTime, 
187
                       &PointToPointNetDevice::TransmitComplete, 
188
                       this);
189
  return m_channel->TransmitStart(p, this, txTime); 
190
}
191
192
void PointToPointNetDevice::TransmitComplete (void)
193
{
194
  NS_DEBUG ("PointToPointNetDevice::TransmitCompleteEvent ()");
195
//
196
// This function is called to finish the  process of transmitting a packet.
197
// We need to tell the channel that we've stopped wiggling the wire and
198
// get the next packet from the queue.  If the queue is empty, we are
199
// done, otherwise transmit the next packet.
200
//
201
  NS_ASSERT_MSG(m_txMachineState == BUSY, "Must be BUSY if transmitting");
202
  m_txMachineState = READY;
203
  Packet p;
204
  if (!m_queue->Dequeue(p)) return; // Nothing to do at this point
205
  TransmitStart(p);
206
}
207
208
TraceResolver* PointToPointNetDevice::DoCreateTraceResolver (
209
                                      TraceContext const &context)
210
{
211
  CompositeTraceResolver *resolver = new CompositeTraceResolver (context);
212
  resolver->Add ("queue", 
213
                 MakeCallback (&Queue::CreateTraceResolver, PeekPointer (m_queue)),
214
                 PointToPointNetDevice::QUEUE);
215
  resolver->Add ("rx",
216
                 m_rxTrace,
217
                 PointToPointNetDevice::RX);
218
  return resolver;
219
}
220
221
bool PointToPointNetDevice::Attach (Ptr<PointToPointChannel> ch)
222
{
223
  NS_DEBUG ("PointToPointNetDevice::Attach (" << &ch << ")");
224
225
  m_channel = ch;
226
227
  m_channel->Attach(this);
228
  m_bps = m_channel->GetDataRate ();
229
  // GFR Comment.  Below is definitely wrong.  Interframe gap
230
  // is unrelated to channel delay.
231
  //m_tInterframeGap = m_channel->GetDelay ();
232
233
  /* 
234
   * For now, this device is up whenever a channel is attached to it.
235
   * In fact, it should become up only when the second device
236
   * is attached to the channel. So, there should be a way for
237
   * a PointToPointChannel to notify both of its attached devices
238
   * that the channel is 'complete', hence that the devices are
239
   * up, hence that they can call NotifyLinkUp. 
240
   */
241
  NotifyLinkUp ();
242
  return true;
243
}
244
245
void PointToPointNetDevice::AddQueue (Ptr<Queue> q)
246
{
247
  NS_DEBUG ("PointToPointNetDevice::AddQueue (" << q << ")");
248
249
  m_queue = q;
250
}
251
252
void PointToPointNetDevice::Receive (Packet& p)
253
{
254
  NS_DEBUG ("PointToPointNetDevice::Receive (" << &p << ")");
255
256
  m_rxTrace (p);
257
  ForwardUp (p);
258
}
259
260
Ptr<Queue> PointToPointNetDevice::GetQueue(void) const 
261
{ 
262
    return m_queue;
263
}
264
265
Ptr<Channel> PointToPointNetDevice::DoGetChannel(void) const 
266
{ 
267
    return m_channel;
268
}
269
270
bool PointToPointNetDevice::DoNeedsArp (void) const
271
{
272
  return false;
273
}
274
275
} // namespace ns3
(-)a/src/devices/p2p/p2p-net-device.h (-310 lines)
Removed Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * Copyright (c) 2007 University of Washington
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
 * Author: Craig Dowell <craigdo@ee.washington.edu>
19
 */
20
21
#ifndef POINT_TO_POINT_NET_DEVICE_H
22
#define POINT_TO_POINT_NET_DEVICE_H
23
24
#include <string.h>
25
#include "ns3/mac-address.h"
26
#include "ns3/node.h"
27
#include "ns3/net-device.h"
28
#include "ns3/callback.h"
29
#include "ns3/packet.h"
30
#include "ns3/callback-trace-source.h"
31
#include "ns3/nstime.h"
32
#include "ns3/data-rate.h"
33
#include "ns3/default-value.h"
34
#include "ns3/ptr.h"
35
36
namespace ns3 {
37
38
class Queue;
39
class PointToPointChannel;
40
41
/**
42
 * \class PointToPointNetDevice
43
 * \brief A Device for a Point to Point Network Link.
44
 *
45
 * Ns-3 takes a four-layer view of a protocol stack.  This is the same model
46
 * that TCP uses.  In this view, layers 5-7 of the OSI reference model are
47
 * grouped together into an application layer; layer four (transport / TCP) is
48
 * broken out; layer three (network / IP) is broken out; and layers 1-2 are
49
 * grouped together.  We call this grouping of layers one and two a NetDevice
50
 * and represent it as a class in the system.
51
 *
52
 * The NetDevice class is specialized according to the needs of the specific
53
 * kind of network link.  In this case, the link is a PointToPoint link.  The
54
 * PointToPoint link is a family of classes that includes this class, the
55
 * PointToPointNetDevice, a PointToPointChannel class that represents the 
56
 * actual medium across which bits are sent, a PointToPointIpv4Interface class
57
 * that provides the hook to tie a general purpose node to this specific
58
 * link, and finally, a PointToPointTopology object that is responsible for
59
 * putting all of the pieces together.
60
 *
61
 * This is the PointToPointNetDevice class that represents, essentially, the
62
 * PC card that is used to connect to the PointToPoint network.
63
 */
64
class PointToPointNetDevice : public NetDevice {
65
public:
66
  /**
67
   * Enumeration of the types of traces supported in the class.
68
   *
69
   */
70
  enum TraceType {
71
    QUEUE, /**< Trace queue events on the attached queue */
72
    RX,    /**< Trace packet reception events (from the channel) */
73
  };
74
  /**
75
   * Construct a PointToPointNetDevice
76
   *
77
   * This is the constructor for the PointToPointNetDevice.  It takes as a
78
   * parameter the Node to which this device is connected.  Ownership of the
79
   * Node pointer is not implied and the node must not be deleded.
80
   *
81
   * @see PointToPointTopology::AddPointToPointLink ()
82
   * @param node the Node to which this device is connected.
83
   */
84
  PointToPointNetDevice (Ptr<Node> node,
85
                         const DataRate& = g_defaultRate.GetValue());
86
  /**
87
   * Copy Construct a PointToPointNetDevice
88
   *
89
   * This is the copy constructor for the PointToPointNetDevice.  This is
90
   * primarily used in topology creation.
91
   *
92
   * @see PointToPointTopology::AddPointToPointLink ()
93
   * @param nd the object to be copied
94
   */
95
  PointToPointNetDevice (const PointToPointNetDevice& nd);
96
  /**
97
   * Destroy a PointToPointNetDevice
98
   *
99
   * This is the destructor for the PointToPointNetDevice.
100
   */
101
  virtual ~PointToPointNetDevice();
102
  /**
103
   * Assignment Operator for a PointToPointNetDevice
104
   *
105
   * This is the assignment operator for the PointToPointNetDevice.  This is
106
   * to allow
107
   *
108
   * @param nd the object to be copied
109
   */
110
  PointToPointNetDevice& operator= (const PointToPointNetDevice& nd);
111
  /**
112
   * Set the Data Rate used for transmission of packets.  The data rate is
113
   * set in the Attach () method from the corresponding field in the channel
114
   * to which the device is attached.  It can be overridden using this method.
115
   *
116
   * @see Attach ()
117
   * @param bps the data rate at which this object operates
118
   */
119
  void SetDataRate(const DataRate& bps);
120
  /**
121
   * Set the inteframe gap used to separate packets.  The interframe gap
122
   * defines the minimum space required between packets sent by this device.
123
   * It is usually set in the Attach () method based on the speed of light
124
   * delay of the channel to which the device is attached.  It can be 
125
   * overridden using this method if desired.
126
   *
127
   * @see Attach ()
128
   * @param t the interframe gap time
129
   */
130
  void SetInterframeGap(const Time& t);
131
  /**
132
   * Attach the device to a channel.
133
   *
134
   * The PointToPointTopology object creates a PointToPointChannel and two
135
   * PointtoPointNetDevices.  In order to introduce these components to each
136
   * other, the topology object calls Attach () on each PointToPointNetDevice.
137
   * Inside this method, the Net Device calls out to the PointToPointChannel
138
   * to introduce itself.
139
   *
140
   * @see PointToPointTopology::AddPointToPointLink ()
141
   * @see SetDataRate ()
142
   * @see SetInterframeGap ()
143
   * @param ch a pointer to the channel to which this object is being attached.
144
   */
145
  bool Attach(Ptr<PointToPointChannel> ch);
146
  /**
147
   * Attach a queue to the PointToPointNetDevice.
148
   *
149
   * The PointToPointNetDevice "owns" a queue.  This queue is created by the
150
   * PointToPointTopology object and implements a queueing method such as
151
   * DropTail or RED.  The PointToPointNetDevice assumes ownership of this
152
   * queue and must delete it when the device is destroyed.
153
   *
154
   * @see PointToPointTopology::AddPointToPointLink ()
155
   * @see Queue
156
   * @see DropTailQueue
157
   * @param queue a pointer to the queue for which object is assuming
158
   *        ownership.
159
   */
160
  void AddQueue(Ptr<Queue> queue);
161
  /**
162
   * Receive a packet from a connected PointToPointChannel.
163
   *
164
   * The PointToPointNetDevice receives packets from its connected channel
165
   * and forwards them up the protocol stack.  This is the public method
166
   * used by the channel to indicate that the last bit of a packet has 
167
   * arrived at the device.
168
   *
169
   * @see PointToPointChannel
170
   * @param p a reference to the received packet
171
   */
172
  void Receive (Packet& p);
173
protected:
174
  virtual void DoDispose (void);
175
  /**
176
   * Get a copy of the attached Queue.
177
   *
178
   * This method is provided for any derived class that may need to get
179
   * direct access to the underlying queue.
180
   *
181
   * @see PointToPointTopology
182
   * @returns a pointer to the queue.
183
   */
184
  Ptr<Queue> GetQueue(void) const; 
185
  /**
186
   * Get a copy of the attached Channel
187
   *
188
   * This method is provided for any derived class that may need to get
189
   * direct access to the connected channel
190
   *
191
   * @see PointToPointChannel
192
   * @returns a pointer to the channel
193
   */
194
  virtual Ptr<Channel> DoGetChannel(void) const;
195
  /**
196
   * Set a new default data rate
197
   * @param Data rate to set for new default
198
   */
199
  static void SetDefaultRate(const DataRate&);
200
201
  /** 
202
   * Get the current default rate.
203
   * @returns a const reference to current default
204
   */
205
206
  static const DataRate& GetDefaultRate();
207
208
private:
209
  /**
210
   * Send a Packet Down the Wire.
211
   *
212
   * The SendTo method is defined as the standard way that the level three
213
   * protocol uses to tell a NetDevice to send a packet.  SendTo is declared
214
   * as abstract in the NetDevice class and we declare it here.
215
   *
216
   * @see NetDevice
217
   * @param p a reference to the packet to send
218
   * @param dest a reference to the MacAddress of the destination device
219
   * @returns true if success, false on failure
220
   */
221
  virtual bool SendTo (Packet& p, const MacAddress& dest);
222
  /**
223
   * Start Sending a Packet Down the Wire.
224
   *
225
   * The TransmitStart method is the method that is used internally in the
226
   * PointToPointNetDevice to begin the process of sending a packet out on
227
   * the channel.  The corresponding method is called on the channel to let
228
   * it know that the physical device this class represents has virually
229
   * started sending signals.  An event is scheduled for the time at which
230
   * the bits have been completely transmitted.
231
   *
232
   * @see PointToPointChannel::TransmitStart ()
233
   * @see TransmitCompleteEvent ()
234
   * @param p a reference to the packet to send
235
   * @returns true if success, false on failure
236
   */
237
  bool TransmitStart (Packet &p);
238
  /**
239
   * Stop Sending a Packet Down the Wire and Begin the Interframe Gap.
240
   *
241
   * The TransmitComplete method is used internally to finish the process
242
   * of sending a packet out on the channel.
243
   *
244
   */
245
  void TransmitComplete(void);
246
  /**
247
   * Create a Trace Resolver for events in the net device.
248
   *
249
   * @see class TraceResolver
250
   */
251
  virtual TraceResolver* DoCreateTraceResolver (TraceContext const &context);
252
  virtual bool DoNeedsArp (void) const;
253
  /**
254
   * Enumeration of the states of the transmit machine of the net device.
255
   */
256
  enum TxMachineState
257
    {
258
      READY, /**< The transmitter is ready to begin transmission of a packet */
259
      BUSY   /**< The transmitter is busy transmitting a packet */
260
    };
261
  /**
262
   * The state of the Net Device transmit state machine.
263
   * @see TxMachineState
264
   */
265
  TxMachineState m_txMachineState;
266
  /**
267
   * The data rate that the Net Device uses to simulate packet transmission
268
   * timing.
269
   * @see class DataRate
270
   */
271
  DataRate       m_bps;
272
  /**
273
   * The interframe gap that the Net Device uses to throttle packet
274
   * transmission
275
   * @see class Time
276
   */
277
  Time           m_tInterframeGap;
278
  /**
279
   * The PointToPointChannel to which this PointToPointNetDevice has been
280
   * attached.
281
   * @see class PointToPointChannel
282
   */
283
  Ptr<PointToPointChannel> m_channel;
284
  /**
285
   * The Queue which this PointToPointNetDevice uses as a packet source.
286
   * Management of this Queue has been delegated to the PointToPointNetDevice
287
   * and it has the responsibility for deletion.
288
   * @see class Queue
289
   * @see class DropTailQueue
290
   */
291
  Ptr<Queue> m_queue;
292
  /**
293
   * The trace source for the packet reception events that the device can
294
   * fire.
295
   *
296
   * @see class CallBackTraceSource
297
   * @see class TraceResolver
298
   */
299
  CallbackTraceSource<Packet &> m_rxTrace;
300
  /** 
301
   * Default data rate.  Used for all newly created p2p net devices
302
   */
303
   static DataRateDefaultValue g_defaultRate;
304
305
};
306
307
}; // namespace ns3
308
309
#endif // POINT_TO_POINT_NET_DEVICE_H
310
(-)a/src/devices/p2p/p2p-topology.cc (-172 lines)
Removed 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
// Author: George F. Riley<riley@ece.gatech.edu>
19
//
20
21
//
22
// Topology helper for ns3.
23
// George F. Riley, Georgia Tech, Spring 2007
24
25
#include <algorithm>
26
#include "ns3/assert.h"
27
#include "ns3/debug.h"
28
#include "ns3/fatal-error.h"
29
#include "ns3/nstime.h"
30
#include "ns3/internet-node.h"
31
#include "ns3/ipv4-address.h"
32
#include "ns3/ipv4.h"
33
#include "ns3/queue.h"
34
35
#include "p2p-channel.h"
36
#include "p2p-net-device.h"
37
#include "p2p-topology.h"
38
39
namespace ns3 {
40
41
Ptr<PointToPointChannel>
42
PointToPointTopology::AddPointToPointLink(
43
  Ptr<Node> n1,
44
  Ptr<Node> n2,
45
  const DataRate& bps,
46
  const Time& delay)
47
{
48
  Ptr<PointToPointChannel> channel = Create<PointToPointChannel> (bps, delay);
49
50
  Ptr<PointToPointNetDevice> net1 = Create<PointToPointNetDevice> (n1);
51
52
  Ptr<Queue> q = Queue::CreateDefault ();
53
  net1->AddQueue(q);
54
  net1->Attach (channel);
55
  
56
  Ptr<PointToPointNetDevice> net2 = Create<PointToPointNetDevice> (n2);
57
58
  q = Queue::CreateDefault ();
59
  net2->AddQueue(q);
60
  net2->Attach (channel);
61
62
  return channel;
63
}
64
65
void
66
PointToPointTopology::AddIpv4Addresses(
67
  Ptr<const PointToPointChannel> chan,
68
  Ptr<Node> n1, const Ipv4Address& addr1,
69
  Ptr<Node> n2, const Ipv4Address& addr2)
70
{
71
72
  // Duplex link is assumed to be subnetted as a /30
73
  // May run this unnumbered in the future?
74
  Ipv4Mask netmask("255.255.255.252");
75
  NS_ASSERT (netmask.IsMatch(addr1,addr2));
76
77
  // The PointToPoint channel is used to find the relevant NetDevices
78
  NS_ASSERT (chan->GetNDevices () == 2);
79
  Ptr<NetDevice> nd1 = chan->GetDevice (0);
80
  Ptr<NetDevice> nd2 = chan->GetDevice (1);
81
  // Make sure that nd1 belongs to n1 and nd2 to n2
82
  if ( (nd1->GetNode ()->GetId () == n2->GetId () ) && 
83
       (nd2->GetNode ()->GetId () == n1->GetId () ) )
84
    {
85
      std::swap(nd1, nd2);
86
    }
87
  NS_ASSERT (nd1->GetNode ()->GetId () == n1->GetId ());
88
  NS_ASSERT (nd2->GetNode ()->GetId () == n2->GetId ());
89
  
90
  Ptr<Ipv4> ip1 = n1->QueryInterface<Ipv4> (Ipv4::iid);
91
  uint32_t index1 = ip1->AddInterface (nd1);
92
93
  ip1->SetAddress (index1, addr1);
94
  ip1->SetNetworkMask (index1, netmask);
95
  ip1->SetUp (index1);
96
97
  Ptr<Ipv4> ip2 = n2->QueryInterface<Ipv4> (Ipv4::iid);
98
  uint32_t index2 = ip2->AddInterface (nd2);
99
100
  ip2->SetAddress (index2, addr2);
101
  ip2->SetNetworkMask (index2, netmask);
102
  ip2->SetUp (index2);
103
  
104
}
105
106
void
107
PointToPointTopology::AddIpv4Routes (
108
  Ptr<Node> n1, Ptr<Node> n2, Ptr<const PointToPointChannel> chan)
109
{ 
110
  // The PointToPoint channel is used to find the relevant NetDevices
111
  NS_ASSERT (chan->GetNDevices () == 2);
112
  Ptr<NetDevice> nd1 = chan->GetDevice (0);
113
  Ptr<NetDevice> nd2 = chan->GetDevice (1);
114
115
  // Assert that n1 is the Node owning one of the two NetDevices
116
  // and make sure that nd1 corresponds to it
117
  if (nd1->GetNode ()->GetId () == n1->GetId ())
118
    {
119
      ; // Do nothing
120
    }
121
  else if (nd2->GetNode ()->GetId () == n1->GetId ())
122
    {
123
      std::swap(nd1, nd2);
124
    }
125
  else
126
    {
127
      NS_FATAL_ERROR("P2PTopo: Node does not contain an interface on Channel");
128
    }
129
130
   // Assert that n2 is the Node owning one of the two NetDevices
131
   // and make sure that nd2 corresponds to it
132
  if (nd2->GetNode ()->GetId () != n2->GetId ())
133
    {
134
      NS_FATAL_ERROR("P2PTopo: Node does not contain an interface on Channel");
135
    }
136
137
  // Assert that both are Ipv4 nodes
138
  Ptr<Ipv4> ip1 = nd1->GetNode ()->QueryInterface<Ipv4> (Ipv4::iid);
139
  Ptr<Ipv4> ip2 = nd2->GetNode ()->QueryInterface<Ipv4> (Ipv4::iid);
140
  NS_ASSERT(ip1 != 0 && ip2 != 0);
141
142
  // Get interface indexes for both nodes corresponding to the right channel
143
  uint32_t index1 = 0;
144
  bool found = false;
145
  for (uint32_t i = 0; i < ip1->GetNInterfaces (); i++)
146
    {
147
      if (ip1 ->GetNetDevice (i) == nd1)
148
        {
149
          index1 = i;
150
          found = true;
151
        }
152
    }
153
  NS_ASSERT(found);
154
155
  uint32_t index2 = 0;
156
  found = false;
157
  for (uint32_t i = 0; i < ip2->GetNInterfaces (); i++)
158
    {
159
      if (ip2 ->GetNetDevice (i) == nd2)
160
        {
161
          index2 = i;
162
          found = true;
163
        }
164
    }
165
  NS_ASSERT(found);
166
167
  ip1->AddHostRouteTo (ip2-> GetAddress (index2), index1);
168
  ip2->AddHostRouteTo (ip1-> GetAddress (index1), index2); 
169
}
170
171
} // namespace ns3
172
 
(-)a/src/devices/p2p/p2p-topology.h (-87 lines)
Removed 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
// Author: George F. Riley<riley@ece.gatech.edu>
19
//
20
// Topology helper for ns3.
21
// George F. Riley, Georgia Tech, Spring 2007
22
#ifndef __POINT_TO_POINT_TOPOLOGY_H__
23
#define __POINT_TO_POINT_TOPOLOGY_H__
24
25
#include "ns3/ptr.h"
26
27
// The topology class consists of only static methods thar are used to
28
// create the topology and data flows for an ns3 simulation
29
30
namespace ns3 {
31
32
class PointToPointChannel;
33
class Node;
34
class IPAddr;
35
class DataRate;
36
class Queue;
37
38
/**
39
 * \brief A helper class to create Topologies based on the 
40
 * ns3::PointToPointNetDevice and  ns3::PointToPointChannel objects.
41
 */
42
class PointToPointTopology {
43
public:
44
  /** 
45
   * \param n1 Node
46
   * \param n2 Node
47
   * \param dataRate Maximum transmission link rate 
48
   * \param delay one-way propagation delay 
49
   * \return Pointer to the underlying PointToPointChannel
50
   * 
51
   * Add a full-duplex point-to-point link between two nodes
52
   * and attach PointToPointNetDevices to the resulting
53
   * PointToPointChannel.  
54
   */
55
  static Ptr<PointToPointChannel> AddPointToPointLink(
56
    Ptr<Node> n1, Ptr<Node> n2, const DataRate& dataRate, const Time& delay);
57
58
  /** 
59
   * \param chan PointToPointChannel to use
60
   * \param n1 Node
61
   * \param addr1 Ipv4 Address for n1
62
   * \param n2 Node
63
   * \param addr2 Ipv4 Address for n2
64
   * 
65
   * Add Ipv4Addresses to the Ipv4 interfaces associated with the 
66
   * two PointToPointNetDevices on the provided PointToPointChannel
67
   */
68
  static void AddIpv4Addresses(
69
    Ptr<const PointToPointChannel> chan,
70
    Ptr<Node> n1, const Ipv4Address& addr1,
71
    Ptr<Node> n2, const Ipv4Address& addr2);
72
73
  /**
74
   * \param channel PointToPointChannel to use
75
   * \param n1 Node
76
   * \param n2 Node
77
   * 
78
   * For the given PointToPointChannel, for each Node, add an 
79
   * IPv4 host route to the IPv4 address of the peer node.  
80
   */
81
  static void AddIpv4Routes (Ptr<Node> n1, Ptr<Node> n2, Ptr<const PointToPointChannel> channel);
82
};
83
84
} // namespace ns3
85
86
#endif
87
(-)a/src/devices/p2p/wscript (-20 lines)
Removed Link Here 
1
## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
2
3
4
def build(bld):
5
    p2p = bld.create_obj('cpp', 'shlib')
6
    p2p.name = 'ns3-p2p'
7
    p2p.target = p2p.name
8
    p2p.uselib_local = ['ns3-node']
9
    p2p.source = [
10
        'p2p-net-device.cc',
11
        'p2p-channel.cc',
12
        'p2p-topology.cc',
13
        ]
14
    headers = bld.create_obj('ns3header')
15
    headers.source = [
16
        'p2p-net-device.h',
17
        'p2p-channel.h',
18
        'p2p-topology.h',
19
        ]
20
(-)7a81f1ef8c74 (+142 lines)
Added Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * Copyright (c) 2007 University of Washington
4
 * All rights reserved.
5
 *
6
 * This program is free software; you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License version 2 as
8
 * published by the Free Software Foundation;
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
 *
19
 * Author: Craig Dowell <craigdo@ee.washington.edu>
20
 */
21
22
#include "p2p-channel.h"
23
#include "p2p-net-device.h"
24
#include "ns3/packet.h"
25
#include "ns3/simulator.h"
26
#include "ns3/debug.h"
27
28
NS_DEBUG_COMPONENT_DEFINE ("PointToPointChannel");
29
30
namespace ns3 {
31
32
//
33
// By default, you get a channel with the name "PointToPoint Channel" that 
34
// has an "infitely" fast transmission speed and zero delay.
35
PointToPointChannel::PointToPointChannel()
36
: 
37
  Channel ("PointToPoint Channel"), 
38
  m_bps (DataRate(0xffffffff)),
39
  m_delay (Seconds(0)),
40
  m_nDevices(0)
41
{
42
  NS_DEBUG("PointToPointChannel::PointToPointChannel ()");
43
}
44
45
PointToPointChannel::PointToPointChannel(
46
  const DataRate& bps, 
47
  const Time& delay)
48
: 
49
  Channel ("PointToPoint Channel"), 
50
  m_bps (bps),
51
  m_delay (delay),
52
  m_nDevices(0)
53
{
54
  NS_DEBUG("PointToPointChannel::PointToPointChannel (" << Channel::GetName() 
55
    << ", " << bps.GetBitRate() << ", " << delay << ")");
56
}
57
58
PointToPointChannel::PointToPointChannel(
59
  const std::string& name,
60
  const DataRate& bps, 
61
  const Time& delay)
62
: 
63
  Channel (name),
64
  m_bps (bps), 
65
  m_delay (delay),
66
  m_nDevices(0)
67
{
68
  NS_DEBUG("PointToPointChannel::PointToPointChannel (" << name << ", " << 
69
    bps.GetBitRate() << ", " << delay << ")");
70
}
71
72
  void
73
PointToPointChannel::Attach(Ptr<PointToPointNetDevice> device)
74
{
75
  NS_DEBUG("PointToPointChannel::Attach (" << device << ")");
76
  NS_ASSERT(m_nDevices < N_DEVICES && "Only two devices permitted");
77
  NS_ASSERT(device != 0);
78
79
  m_link[m_nDevices++].m_src = device;
80
//
81
// If we have both devices connected to the channel, then finish introducing
82
// the two halves and set the links to IDLE.
83
//
84
  if (m_nDevices == N_DEVICES)
85
    {
86
      m_link[0].m_dst = m_link[1].m_src;
87
      m_link[1].m_dst = m_link[0].m_src;
88
      m_link[0].m_state = IDLE;
89
      m_link[1].m_state = IDLE;
90
    }
91
}
92
93
bool PointToPointChannel::TransmitStart(Packet& p,
94
                                        Ptr<PointToPointNetDevice> src,
95
                                        const Time& txTime)
96
{
97
  NS_DEBUG ("PointToPointChannel::TransmitStart (" << &p << ", " << src << 
98
            ")");
99
  NS_DEBUG ("PointToPointChannel::TransmitStart (): UID is " << 
100
            p.GetUid () << ")");
101
102
  NS_ASSERT(m_link[0].m_state != INITIALIZING);
103
  NS_ASSERT(m_link[1].m_state != INITIALIZING);
104
105
  uint32_t wire = src == m_link[0].m_src ? 0 : 1;
106
107
  // Here we schedule the packet receive event at the receiver,
108
  // which simplifies this model quite a bit.  The channel just
109
  // adds the propagation delay time
110
  Simulator::Schedule (txTime + m_delay,
111
                       &PointToPointNetDevice::Receive,
112
                       m_link[wire].m_dst, p);
113
  return true;
114
}
115
116
uint32_t 
117
PointToPointChannel::GetNDevices (void) const
118
{
119
  return m_nDevices;
120
}
121
122
Ptr<NetDevice>
123
PointToPointChannel::GetDevice (uint32_t i) const
124
{
125
  NS_ASSERT(i < 2);
126
  return m_link[i].m_src;
127
}
128
129
const DataRate&
130
PointToPointChannel::GetDataRate (void)
131
{
132
  return m_bps;
133
}
134
135
const Time&
136
PointToPointChannel::GetDelay (void)
137
{
138
  return m_delay;
139
}
140
141
142
} // namespace ns3
(-)7a81f1ef8c74 (+127 lines)
Added Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * Copyright (c) 2007 University of Washington
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
#ifndef POINT_TO_POINT_CHANNEL_H
20
#define POINT_TO_POINT_CHANNEL_H
21
22
#include <list>
23
#include "ns3/channel.h"
24
#include "ns3/ptr.h"
25
#include "ns3/packet.h"
26
#include "ns3/nstime.h"
27
#include "ns3/data-rate.h"
28
29
namespace ns3 {
30
31
class PointToPointNetDevice;
32
33
/**
34
 * \brief Simple Point To Point Channel.
35
 *
36
 * This class represents a very simple point to point channel.  Think full
37
 * duplex RS-232 or RS-422 with null modem and no handshaking.  There is no
38
 * multi-drop capability on this channel -- there can be a maximum of two 
39
 * point-to-point net devices connected.  Once we start talking about multi-
40
 * drop, or CSMA, or some other sharing mechanism, things begin getting 
41
 * complicated quickly.  Rather than invent some ad-hoc mechanism, we just
42
 * Keep It Simple everywhere.
43
 *
44
 * When the channel is instaniated, the constructor takes parameters for
45
 * a single speed, in bits per second, and a speed-of-light delay time as a
46
 * Time object.  Both directions use the same speed and delay time.
47
 *
48
 * There are two "wires" in the channel.  The first device connected gets the
49
 * [0] wire to transmit on.  The second device gets the [1] wire.  There is a
50
 * state (IDLE, TRANSMITTING) associated with each wire.
51
 */
52
class PointToPointChannel : public Channel {
53
public:
54
// Each point to point link has exactly two net devices
55
  static const int N_DEVICES = 2;
56
  /**
57
   * \brief Create a PointToPointChannel
58
   *
59
   * By default, you get a channel with the name "PointToPoint Channel" that
60
   * has an "infitely" fast transmission speed and zero delay.
61
   */
62
  PointToPointChannel ();
63
  
64
  /**
65
   * \brief Create a PointToPointChannel
66
   *
67
   * \param bps The maximum bitrate of the channel
68
   * \param delay Transmission delay through the channel
69
   */  
70
  PointToPointChannel (const DataRate& bps, const Time& delay);
71
  
72
  /**
73
   * \brief Create a PointToPointChannel
74
   *
75
   * \param name the name of the channel for identification purposes
76
   * \param bps The maximum bitrate of the channel
77
   * \param delay Transmission delay through the channel
78
   */
79
  PointToPointChannel (const std::string& name,
80
                 const DataRate& bps, const Time& delay);
81
82
  /**
83
   * \brief Attach a given netdevice to this channel
84
   * \param device pointer to the netdevice to attach to the channel
85
   */
86
  void Attach (Ptr<PointToPointNetDevice> device);
87
  bool TransmitStart (Packet& p, Ptr<PointToPointNetDevice> src,
88
                      const Time& txTime);
89
  // Below two not needed
90
  //bool TransmitEnd (Packet &p, Ptr<PointToPointNetDevice> src);
91
  //void PropagationCompleteEvent(Packet p, Ptr<PointToPointNetDevice> src);
92
93
94
  virtual uint32_t GetNDevices (void) const;
95
  virtual Ptr<NetDevice> GetDevice (uint32_t i) const;
96
97
  virtual const DataRate& GetDataRate (void);
98
  virtual const Time&     GetDelay (void);
99
100
private:
101
  DataRate      m_bps;
102
  Time          m_delay;
103
  int32_t       m_nDevices;
104
105
  enum WireState
106
    {
107
      INITIALIZING,
108
      IDLE,
109
      TRANSMITTING,
110
      PROPAGATING
111
    };
112
113
  class Link
114
  {
115
  public:
116
    Link() : m_state (INITIALIZING), m_src (0), m_dst (0) {}
117
    WireState              m_state;
118
    Ptr<PointToPointNetDevice> m_src;
119
    Ptr<PointToPointNetDevice> m_dst;
120
  };
121
    
122
  Link    m_link[N_DEVICES];
123
};
124
125
} // namespace ns3
126
127
#endif /* POINT_TO_POINT_CHANNEL_H */
(-)7a81f1ef8c74 (+275 lines)
Added Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * Copyright (c) 2005,2006 INRIA
4
 * All rights reserved.
5
 *
6
 * This program is free software; you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License version 2 as
8
 * published by the Free Software Foundation;
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
 *
19
 * Author:  Craig Dowell <craigdo@ee.washington.edu>
20
 * Revised: George Riley <riley@ece.gatech.edu>
21
 */
22
23
#include <iostream>
24
#include <cassert>
25
#include "ns3/debug.h"
26
#include "ns3/queue.h"
27
#include "ns3/simulator.h"
28
#include "ns3/composite-trace-resolver.h"
29
#include "p2p-net-device.h"
30
#include "p2p-channel.h"
31
32
NS_DEBUG_COMPONENT_DEFINE ("PointToPointNetDevice");
33
34
namespace ns3 {
35
36
DataRateDefaultValue PointToPointNetDevice::g_defaultRate(
37
           "PointToPointLinkDataRate", 
38
           "The default data rate for point to point links",
39
           DataRate ("10Mb/s"));
40
41
  PointToPointNetDevice::PointToPointNetDevice (Ptr<Node> node,
42
                                                const DataRate& rate) 
43
: 
44
  NetDevice(node, MacAddress (6)), 
45
  m_txMachineState (READY),
46
  m_bps (rate),
47
  m_tInterframeGap (Seconds(0)),
48
  m_channel (0), 
49
  m_queue (0),
50
  m_rxTrace ()
51
{
52
  NS_DEBUG ("PointToPointNetDevice::PointToPointNetDevice (" << node << ")");
53
54
  // BUGBUG FIXME
55
  //
56
  // You _must_ support broadcast to get any sort of packet from the ARP layer.
57
  EnableBroadcast (MacAddress ("ff:ff:ff:ff:ff:ff"));
58
  EnableMulticast();
59
  EnablePointToPoint();
60
}
61
62
PointToPointNetDevice::~PointToPointNetDevice()
63
{
64
  NS_DEBUG ("PointToPointNetDevice::~PointToPointNetDevice ()");
65
  m_queue = 0;
66
}
67
68
//
69
// Copy constructor for PointToPointNetDevice.
70
//
71
// We use the underlying NetDevice copy constructor to get the base class
72
// copied.  These just remain as is (e.g. you get the same name, the same
73
// MAC address).  If you need to fix them up, YOU, the copier need to do 
74
// that.
75
// 
76
// The things we need to be careful of are the channel, the queue and the
77
// trace callback.  If the channel pointer is non-zero, we copy the pointer 
78
// and add a reference.  If the queue is non-zero, we copy it using the queue
79
// assignment operator.  We don't mess with the trace -- we just reset it.
80
// We're assuming that the tracing will be set up after the topology creation
81
// phase and this won't actually matter.
82
//
83
// GFR Comments.  Don't see where the "copy the pointer and add reference"
84
// stated above is done. Can original author please comment and/or fix.
85
// Shouldn't the queue pointer also bump the refcount?
86
PointToPointNetDevice::PointToPointNetDevice (const PointToPointNetDevice& nd)
87
: 
88
  NetDevice(nd), 
89
  m_txMachineState(READY),
90
  m_bps (nd.m_bps),
91
  m_tInterframeGap (nd.m_tInterframeGap),
92
  m_channel(nd.m_channel), 
93
  m_queue(0),
94
  m_rxTrace ()
95
{
96
  NS_DEBUG ("PointToPointNetDevice::PointToPointNetDevice (" << &nd << ")");
97
98
  if (nd.m_queue)
99
    {
100
      m_queue = nd.m_queue;
101
    }
102
    
103
}
104
105
  // GFR COmments...shouldn't this decrement the refcount instead
106
  // of just nil-ing out the pointer?  Don't understand this.
107
void PointToPointNetDevice::DoDispose()
108
{
109
  m_channel = 0;
110
  NetDevice::DoDispose ();
111
}
112
113
//
114
// Assignment operator for PointToPointNetDevice.
115
//
116
//
117
PointToPointNetDevice&
118
PointToPointNetDevice::operator= (const PointToPointNetDevice& nd)
119
{
120
  NS_DEBUG ("PointToPointNetDevice::operator= (" << &nd << ")");
121
  // FIXME.  Not sure what to do here
122
  // GFR Note.  I would suggest dis-allowing netdevice assignment,
123
  // as well as pass-by-value (ie. copy constructor).
124
  // This resolves some of the questions above about copy constructors.
125
  // Why should we ever copy or assign a net device?
126
  return *this;
127
}
128
129
void PointToPointNetDevice::SetDataRate(const DataRate& bps)
130
{
131
  m_bps = bps;
132
}
133
134
void PointToPointNetDevice::SetInterframeGap(const Time& t)
135
{
136
  m_tInterframeGap = t;
137
}
138
139
bool PointToPointNetDevice::SendTo (Packet& p, const MacAddress& dest)
140
{
141
  NS_DEBUG ("PointToPointNetDevice::SendTo (" << &p << ", " << &dest << ")");
142
  NS_DEBUG ("PointToPointNetDevice::SendTo (): UID is " << p.GetUid () << ")");
143
144
  // GFR Comment. Why is this an assertion? Can't a link legitimately
145
  // "go down" during the simulation?  Shouldn't we just wait for it
146
  // to come back up?
147
  NS_ASSERT (IsLinkUp ());
148
149
//
150
// This class simulates a point to point device.  In the case of a serial
151
// link, this means that we're simulating something like a UART.
152
//
153
//
154
// If there's a transmission in progress, we enque the packet for later
155
// trnsmission; otherwise we send it now.
156
    if (m_txMachineState == READY) 
157
      {
158
        return TransmitStart (p);
159
      }
160
    else
161
      {
162
        return m_queue->Enqueue(p);
163
      }
164
}
165
166
  bool
167
PointToPointNetDevice::TransmitStart (Packet &p)
168
{
169
  NS_DEBUG ("PointToPointNetDevice::TransmitStart (" << &p << ")");
170
  NS_DEBUG (
171
    "PointToPointNetDevice::TransmitStart (): UID is " << p.GetUid () << ")");
172
//
173
// This function is called to start the process of transmitting a packet.
174
// We need to tell the channel that we've started wiggling the wire and
175
// schedule an event that will be executed when the transmission is complete.
176
//
177
  NS_ASSERT_MSG(m_txMachineState == READY, "Must be READY to transmit");
178
  m_txMachineState = BUSY;
179
  Time txTime = Seconds (m_bps.CalculateTxTime(p.GetSize()));
180
  Time txCompleteTime = txTime + m_tInterframeGap;
181
182
  NS_DEBUG ("PointToPointNetDevice::TransmitStart (): " <<
183
    "Schedule TransmitCompleteEvent in " << 
184
    txCompleteTime.GetSeconds () << "sec");
185
  // Schedule the tx complete event
186
  Simulator::Schedule (txCompleteTime, 
187
                       &PointToPointNetDevice::TransmitComplete, 
188
                       this);
189
  return m_channel->TransmitStart(p, this, txTime); 
190
}
191
192
void PointToPointNetDevice::TransmitComplete (void)
193
{
194
  NS_DEBUG ("PointToPointNetDevice::TransmitCompleteEvent ()");
195
//
196
// This function is called to finish the  process of transmitting a packet.
197
// We need to tell the channel that we've stopped wiggling the wire and
198
// get the next packet from the queue.  If the queue is empty, we are
199
// done, otherwise transmit the next packet.
200
//
201
  NS_ASSERT_MSG(m_txMachineState == BUSY, "Must be BUSY if transmitting");
202
  m_txMachineState = READY;
203
  Packet p;
204
  if (!m_queue->Dequeue(p)) return; // Nothing to do at this point
205
  TransmitStart(p);
206
}
207
208
TraceResolver* PointToPointNetDevice::DoCreateTraceResolver (
209
                                      TraceContext const &context)
210
{
211
  CompositeTraceResolver *resolver = new CompositeTraceResolver (context);
212
  resolver->Add ("queue", 
213
                 MakeCallback (&Queue::CreateTraceResolver, PeekPointer (m_queue)),
214
                 PointToPointNetDevice::QUEUE);
215
  resolver->Add ("rx",
216
                 m_rxTrace,
217
                 PointToPointNetDevice::RX);
218
  return resolver;
219
}
220
221
bool PointToPointNetDevice::Attach (Ptr<PointToPointChannel> ch)
222
{
223
  NS_DEBUG ("PointToPointNetDevice::Attach (" << &ch << ")");
224
225
  m_channel = ch;
226
227
  m_channel->Attach(this);
228
  m_bps = m_channel->GetDataRate ();
229
  // GFR Comment.  Below is definitely wrong.  Interframe gap
230
  // is unrelated to channel delay.
231
  //m_tInterframeGap = m_channel->GetDelay ();
232
233
  /* 
234
   * For now, this device is up whenever a channel is attached to it.
235
   * In fact, it should become up only when the second device
236
   * is attached to the channel. So, there should be a way for
237
   * a PointToPointChannel to notify both of its attached devices
238
   * that the channel is 'complete', hence that the devices are
239
   * up, hence that they can call NotifyLinkUp. 
240
   */
241
  NotifyLinkUp ();
242
  return true;
243
}
244
245
void PointToPointNetDevice::AddQueue (Ptr<Queue> q)
246
{
247
  NS_DEBUG ("PointToPointNetDevice::AddQueue (" << q << ")");
248
249
  m_queue = q;
250
}
251
252
void PointToPointNetDevice::Receive (Packet& p)
253
{
254
  NS_DEBUG ("PointToPointNetDevice::Receive (" << &p << ")");
255
256
  m_rxTrace (p);
257
  ForwardUp (p);
258
}
259
260
Ptr<Queue> PointToPointNetDevice::GetQueue(void) const 
261
{ 
262
    return m_queue;
263
}
264
265
Ptr<Channel> PointToPointNetDevice::DoGetChannel(void) const 
266
{ 
267
    return m_channel;
268
}
269
270
bool PointToPointNetDevice::DoNeedsArp (void) const
271
{
272
  return false;
273
}
274
275
} // namespace ns3
(-)7a81f1ef8c74 (+310 lines)
Added Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * Copyright (c) 2007 University of Washington
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
 * Author: Craig Dowell <craigdo@ee.washington.edu>
19
 */
20
21
#ifndef POINT_TO_POINT_NET_DEVICE_H
22
#define POINT_TO_POINT_NET_DEVICE_H
23
24
#include <string.h>
25
#include "ns3/mac-address.h"
26
#include "ns3/node.h"
27
#include "ns3/net-device.h"
28
#include "ns3/callback.h"
29
#include "ns3/packet.h"
30
#include "ns3/callback-trace-source.h"
31
#include "ns3/nstime.h"
32
#include "ns3/data-rate.h"
33
#include "ns3/default-value.h"
34
#include "ns3/ptr.h"
35
36
namespace ns3 {
37
38
class Queue;
39
class PointToPointChannel;
40
41
/**
42
 * \class PointToPointNetDevice
43
 * \brief A Device for a Point to Point Network Link.
44
 *
45
 * Ns-3 takes a four-layer view of a protocol stack.  This is the same model
46
 * that TCP uses.  In this view, layers 5-7 of the OSI reference model are
47
 * grouped together into an application layer; layer four (transport / TCP) is
48
 * broken out; layer three (network / IP) is broken out; and layers 1-2 are
49
 * grouped together.  We call this grouping of layers one and two a NetDevice
50
 * and represent it as a class in the system.
51
 *
52
 * The NetDevice class is specialized according to the needs of the specific
53
 * kind of network link.  In this case, the link is a PointToPoint link.  The
54
 * PointToPoint link is a family of classes that includes this class, the
55
 * PointToPointNetDevice, a PointToPointChannel class that represents the 
56
 * actual medium across which bits are sent, a PointToPointIpv4Interface class
57
 * that provides the hook to tie a general purpose node to this specific
58
 * link, and finally, a PointToPointTopology object that is responsible for
59
 * putting all of the pieces together.
60
 *
61
 * This is the PointToPointNetDevice class that represents, essentially, the
62
 * PC card that is used to connect to the PointToPoint network.
63
 */
64
class PointToPointNetDevice : public NetDevice {
65
public:
66
  /**
67
   * Enumeration of the types of traces supported in the class.
68
   *
69
   */
70
  enum TraceType {
71
    QUEUE, /**< Trace queue events on the attached queue */
72
    RX,    /**< Trace packet reception events (from the channel) */
73
  };
74
  /**
75
   * Construct a PointToPointNetDevice
76
   *
77
   * This is the constructor for the PointToPointNetDevice.  It takes as a
78
   * parameter the Node to which this device is connected.  Ownership of the
79
   * Node pointer is not implied and the node must not be deleded.
80
   *
81
   * @see PointToPointTopology::AddPointToPointLink ()
82
   * @param node the Node to which this device is connected.
83
   */
84
  PointToPointNetDevice (Ptr<Node> node,
85
                         const DataRate& = g_defaultRate.GetValue());
86
  /**
87
   * Copy Construct a PointToPointNetDevice
88
   *
89
   * This is the copy constructor for the PointToPointNetDevice.  This is
90
   * primarily used in topology creation.
91
   *
92
   * @see PointToPointTopology::AddPointToPointLink ()
93
   * @param nd the object to be copied
94
   */
95
  PointToPointNetDevice (const PointToPointNetDevice& nd);
96
  /**
97
   * Destroy a PointToPointNetDevice
98
   *
99
   * This is the destructor for the PointToPointNetDevice.
100
   */
101
  virtual ~PointToPointNetDevice();
102
  /**
103
   * Assignment Operator for a PointToPointNetDevice
104
   *
105
   * This is the assignment operator for the PointToPointNetDevice.  This is
106
   * to allow
107
   *
108
   * @param nd the object to be copied
109
   */
110
  PointToPointNetDevice& operator= (const PointToPointNetDevice& nd);
111
  /**
112
   * Set the Data Rate used for transmission of packets.  The data rate is
113
   * set in the Attach () method from the corresponding field in the channel
114
   * to which the device is attached.  It can be overridden using this method.
115
   *
116
   * @see Attach ()
117
   * @param bps the data rate at which this object operates
118
   */
119
  void SetDataRate(const DataRate& bps);
120
  /**
121
   * Set the inteframe gap used to separate packets.  The interframe gap
122
   * defines the minimum space required between packets sent by this device.
123
   * It is usually set in the Attach () method based on the speed of light
124
   * delay of the channel to which the device is attached.  It can be 
125
   * overridden using this method if desired.
126
   *
127
   * @see Attach ()
128
   * @param t the interframe gap time
129
   */
130
  void SetInterframeGap(const Time& t);
131
  /**
132
   * Attach the device to a channel.
133
   *
134
   * The PointToPointTopology object creates a PointToPointChannel and two
135
   * PointtoPointNetDevices.  In order to introduce these components to each
136
   * other, the topology object calls Attach () on each PointToPointNetDevice.
137
   * Inside this method, the Net Device calls out to the PointToPointChannel
138
   * to introduce itself.
139
   *
140
   * @see PointToPointTopology::AddPointToPointLink ()
141
   * @see SetDataRate ()
142
   * @see SetInterframeGap ()
143
   * @param ch a pointer to the channel to which this object is being attached.
144
   */
145
  bool Attach(Ptr<PointToPointChannel> ch);
146
  /**
147
   * Attach a queue to the PointToPointNetDevice.
148
   *
149
   * The PointToPointNetDevice "owns" a queue.  This queue is created by the
150
   * PointToPointTopology object and implements a queueing method such as
151
   * DropTail or RED.  The PointToPointNetDevice assumes ownership of this
152
   * queue and must delete it when the device is destroyed.
153
   *
154
   * @see PointToPointTopology::AddPointToPointLink ()
155
   * @see Queue
156
   * @see DropTailQueue
157
   * @param queue a pointer to the queue for which object is assuming
158
   *        ownership.
159
   */
160
  void AddQueue(Ptr<Queue> queue);
161
  /**
162
   * Receive a packet from a connected PointToPointChannel.
163
   *
164
   * The PointToPointNetDevice receives packets from its connected channel
165
   * and forwards them up the protocol stack.  This is the public method
166
   * used by the channel to indicate that the last bit of a packet has 
167
   * arrived at the device.
168
   *
169
   * @see PointToPointChannel
170
   * @param p a reference to the received packet
171
   */
172
  void Receive (Packet& p);
173
protected:
174
  virtual void DoDispose (void);
175
  /**
176
   * Get a copy of the attached Queue.
177
   *
178
   * This method is provided for any derived class that may need to get
179
   * direct access to the underlying queue.
180
   *
181
   * @see PointToPointTopology
182
   * @returns a pointer to the queue.
183
   */
184
  Ptr<Queue> GetQueue(void) const; 
185
  /**
186
   * Get a copy of the attached Channel
187
   *
188
   * This method is provided for any derived class that may need to get
189
   * direct access to the connected channel
190
   *
191
   * @see PointToPointChannel
192
   * @returns a pointer to the channel
193
   */
194
  virtual Ptr<Channel> DoGetChannel(void) const;
195
  /**
196
   * Set a new default data rate
197
   * @param Data rate to set for new default
198
   */
199
  static void SetDefaultRate(const DataRate&);
200
201
  /** 
202
   * Get the current default rate.
203
   * @returns a const reference to current default
204
   */
205
206
  static const DataRate& GetDefaultRate();
207
208
private:
209
  /**
210
   * Send a Packet Down the Wire.
211
   *
212
   * The SendTo method is defined as the standard way that the level three
213
   * protocol uses to tell a NetDevice to send a packet.  SendTo is declared
214
   * as abstract in the NetDevice class and we declare it here.
215
   *
216
   * @see NetDevice
217
   * @param p a reference to the packet to send
218
   * @param dest a reference to the MacAddress of the destination device
219
   * @returns true if success, false on failure
220
   */
221
  virtual bool SendTo (Packet& p, const MacAddress& dest);
222
  /**
223
   * Start Sending a Packet Down the Wire.
224
   *
225
   * The TransmitStart method is the method that is used internally in the
226
   * PointToPointNetDevice to begin the process of sending a packet out on
227
   * the channel.  The corresponding method is called on the channel to let
228
   * it know that the physical device this class represents has virually
229
   * started sending signals.  An event is scheduled for the time at which
230
   * the bits have been completely transmitted.
231
   *
232
   * @see PointToPointChannel::TransmitStart ()
233
   * @see TransmitCompleteEvent ()
234
   * @param p a reference to the packet to send
235
   * @returns true if success, false on failure
236
   */
237
  bool TransmitStart (Packet &p);
238
  /**
239
   * Stop Sending a Packet Down the Wire and Begin the Interframe Gap.
240
   *
241
   * The TransmitComplete method is used internally to finish the process
242
   * of sending a packet out on the channel.
243
   *
244
   */
245
  void TransmitComplete(void);
246
  /**
247
   * Create a Trace Resolver for events in the net device.
248
   *
249
   * @see class TraceResolver
250
   */
251
  virtual TraceResolver* DoCreateTraceResolver (TraceContext const &context);
252
  virtual bool DoNeedsArp (void) const;
253
  /**
254
   * Enumeration of the states of the transmit machine of the net device.
255
   */
256
  enum TxMachineState
257
    {
258
      READY, /**< The transmitter is ready to begin transmission of a packet */
259
      BUSY   /**< The transmitter is busy transmitting a packet */
260
    };
261
  /**
262
   * The state of the Net Device transmit state machine.
263
   * @see TxMachineState
264
   */
265
  TxMachineState m_txMachineState;
266
  /**
267
   * The data rate that the Net Device uses to simulate packet transmission
268
   * timing.
269
   * @see class DataRate
270
   */
271
  DataRate       m_bps;
272
  /**
273
   * The interframe gap that the Net Device uses to throttle packet
274
   * transmission
275
   * @see class Time
276
   */
277
  Time           m_tInterframeGap;
278
  /**
279
   * The PointToPointChannel to which this PointToPointNetDevice has been
280
   * attached.
281
   * @see class PointToPointChannel
282
   */
283
  Ptr<PointToPointChannel> m_channel;
284
  /**
285
   * The Queue which this PointToPointNetDevice uses as a packet source.
286
   * Management of this Queue has been delegated to the PointToPointNetDevice
287
   * and it has the responsibility for deletion.
288
   * @see class Queue
289
   * @see class DropTailQueue
290
   */
291
  Ptr<Queue> m_queue;
292
  /**
293
   * The trace source for the packet reception events that the device can
294
   * fire.
295
   *
296
   * @see class CallBackTraceSource
297
   * @see class TraceResolver
298
   */
299
  CallbackTraceSource<Packet &> m_rxTrace;
300
  /** 
301
   * Default data rate.  Used for all newly created p2p net devices
302
   */
303
   static DataRateDefaultValue g_defaultRate;
304
305
};
306
307
}; // namespace ns3
308
309
#endif // POINT_TO_POINT_NET_DEVICE_H
310
(-)7a81f1ef8c74 (+172 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
// Author: George F. Riley<riley@ece.gatech.edu>
19
//
20
21
//
22
// Topology helper for ns3.
23
// George F. Riley, Georgia Tech, Spring 2007
24
25
#include <algorithm>
26
#include "ns3/assert.h"
27
#include "ns3/debug.h"
28
#include "ns3/fatal-error.h"
29
#include "ns3/nstime.h"
30
#include "ns3/internet-node.h"
31
#include "ns3/ipv4-address.h"
32
#include "ns3/ipv4.h"
33
#include "ns3/queue.h"
34
35
#include "p2p-channel.h"
36
#include "p2p-net-device.h"
37
#include "p2p-topology.h"
38
39
namespace ns3 {
40
41
Ptr<PointToPointChannel>
42
PointToPointTopology::AddPointToPointLink(
43
  Ptr<Node> n1,
44
  Ptr<Node> n2,
45
  const DataRate& bps,
46
  const Time& delay)
47
{
48
  Ptr<PointToPointChannel> channel = Create<PointToPointChannel> (bps, delay);
49
50
  Ptr<PointToPointNetDevice> net1 = Create<PointToPointNetDevice> (n1);
51
52
  Ptr<Queue> q = Queue::CreateDefault ();
53
  net1->AddQueue(q);
54
  net1->Attach (channel);
55
  
56
  Ptr<PointToPointNetDevice> net2 = Create<PointToPointNetDevice> (n2);
57
58
  q = Queue::CreateDefault ();
59
  net2->AddQueue(q);
60
  net2->Attach (channel);
61
62
  return channel;
63
}
64
65
void
66
PointToPointTopology::AddIpv4Addresses(
67
  Ptr<const PointToPointChannel> chan,
68
  Ptr<Node> n1, const Ipv4Address& addr1,
69
  Ptr<Node> n2, const Ipv4Address& addr2)
70
{
71
72
  // Duplex link is assumed to be subnetted as a /30
73
  // May run this unnumbered in the future?
74
  Ipv4Mask netmask("255.255.255.252");
75
  NS_ASSERT (netmask.IsMatch(addr1,addr2));
76
77
  // The PointToPoint channel is used to find the relevant NetDevices
78
  NS_ASSERT (chan->GetNDevices () == 2);
79
  Ptr<NetDevice> nd1 = chan->GetDevice (0);
80
  Ptr<NetDevice> nd2 = chan->GetDevice (1);
81
  // Make sure that nd1 belongs to n1 and nd2 to n2
82
  if ( (nd1->GetNode ()->GetId () == n2->GetId () ) && 
83
       (nd2->GetNode ()->GetId () == n1->GetId () ) )
84
    {
85
      std::swap(nd1, nd2);
86
    }
87
  NS_ASSERT (nd1->GetNode ()->GetId () == n1->GetId ());
88
  NS_ASSERT (nd2->GetNode ()->GetId () == n2->GetId ());
89
  
90
  Ptr<Ipv4> ip1 = n1->QueryInterface<Ipv4> (Ipv4::iid);
91
  uint32_t index1 = ip1->AddInterface (nd1);
92
93
  ip1->SetAddress (index1, addr1);
94
  ip1->SetNetworkMask (index1, netmask);
95
  ip1->SetUp (index1);
96
97
  Ptr<Ipv4> ip2 = n2->QueryInterface<Ipv4> (Ipv4::iid);
98
  uint32_t index2 = ip2->AddInterface (nd2);
99
100
  ip2->SetAddress (index2, addr2);
101
  ip2->SetNetworkMask (index2, netmask);
102
  ip2->SetUp (index2);
103
  
104
}
105
106
void
107
PointToPointTopology::AddIpv4Routes (
108
  Ptr<Node> n1, Ptr<Node> n2, Ptr<const PointToPointChannel> chan)
109
{ 
110
  // The PointToPoint channel is used to find the relevant NetDevices
111
  NS_ASSERT (chan->GetNDevices () == 2);
112
  Ptr<NetDevice> nd1 = chan->GetDevice (0);
113
  Ptr<NetDevice> nd2 = chan->GetDevice (1);
114
115
  // Assert that n1 is the Node owning one of the two NetDevices
116
  // and make sure that nd1 corresponds to it
117
  if (nd1->GetNode ()->GetId () == n1->GetId ())
118
    {
119
      ; // Do nothing
120
    }
121
  else if (nd2->GetNode ()->GetId () == n1->GetId ())
122
    {
123
      std::swap(nd1, nd2);
124
    }
125
  else
126
    {
127
      NS_FATAL_ERROR("P2PTopo: Node does not contain an interface on Channel");
128
    }
129
130
   // Assert that n2 is the Node owning one of the two NetDevices
131
   // and make sure that nd2 corresponds to it
132
  if (nd2->GetNode ()->GetId () != n2->GetId ())
133
    {
134
      NS_FATAL_ERROR("P2PTopo: Node does not contain an interface on Channel");
135
    }
136
137
  // Assert that both are Ipv4 nodes
138
  Ptr<Ipv4> ip1 = nd1->GetNode ()->QueryInterface<Ipv4> (Ipv4::iid);
139
  Ptr<Ipv4> ip2 = nd2->GetNode ()->QueryInterface<Ipv4> (Ipv4::iid);
140
  NS_ASSERT(ip1 != 0 && ip2 != 0);
141
142
  // Get interface indexes for both nodes corresponding to the right channel
143
  uint32_t index1 = 0;
144
  bool found = false;
145
  for (uint32_t i = 0; i < ip1->GetNInterfaces (); i++)
146
    {
147
      if (ip1 ->GetNetDevice (i) == nd1)
148
        {
149
          index1 = i;
150
          found = true;
151
        }
152
    }
153
  NS_ASSERT(found);
154
155
  uint32_t index2 = 0;
156
  found = false;
157
  for (uint32_t i = 0; i < ip2->GetNInterfaces (); i++)
158
    {
159
      if (ip2 ->GetNetDevice (i) == nd2)
160
        {
161
          index2 = i;
162
          found = true;
163
        }
164
    }
165
  NS_ASSERT(found);
166
167
  ip1->AddHostRouteTo (ip2-> GetAddress (index2), index1);
168
  ip2->AddHostRouteTo (ip1-> GetAddress (index1), index2); 
169
}
170
171
} // namespace ns3
172
 
(-)7a81f1ef8c74 (+87 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
// Author: George F. Riley<riley@ece.gatech.edu>
19
//
20
// Topology helper for ns3.
21
// George F. Riley, Georgia Tech, Spring 2007
22
#ifndef __POINT_TO_POINT_TOPOLOGY_H__
23
#define __POINT_TO_POINT_TOPOLOGY_H__
24
25
#include "ns3/ptr.h"
26
27
// The topology class consists of only static methods thar are used to
28
// create the topology and data flows for an ns3 simulation
29
30
namespace ns3 {
31
32
class PointToPointChannel;
33
class Node;
34
class IPAddr;
35
class DataRate;
36
class Queue;
37
38
/**
39
 * \brief A helper class to create Topologies based on the 
40
 * ns3::PointToPointNetDevice and  ns3::PointToPointChannel objects.
41
 */
42
class PointToPointTopology {
43
public:
44
  /** 
45
   * \param n1 Node
46
   * \param n2 Node
47
   * \param dataRate Maximum transmission link rate 
48
   * \param delay one-way propagation delay 
49
   * \return Pointer to the underlying PointToPointChannel
50
   * 
51
   * Add a full-duplex point-to-point link between two nodes
52
   * and attach PointToPointNetDevices to the resulting
53
   * PointToPointChannel.  
54
   */
55
  static Ptr<PointToPointChannel> AddPointToPointLink(
56
    Ptr<Node> n1, Ptr<Node> n2, const DataRate& dataRate, const Time& delay);
57
58
  /** 
59
   * \param chan PointToPointChannel to use
60
   * \param n1 Node
61
   * \param addr1 Ipv4 Address for n1
62
   * \param n2 Node
63
   * \param addr2 Ipv4 Address for n2
64
   * 
65
   * Add Ipv4Addresses to the Ipv4 interfaces associated with the 
66
   * two PointToPointNetDevices on the provided PointToPointChannel
67
   */
68
  static void AddIpv4Addresses(
69
    Ptr<const PointToPointChannel> chan,
70
    Ptr<Node> n1, const Ipv4Address& addr1,
71
    Ptr<Node> n2, const Ipv4Address& addr2);
72
73
  /**
74
   * \param channel PointToPointChannel to use
75
   * \param n1 Node
76
   * \param n2 Node
77
   * 
78
   * For the given PointToPointChannel, for each Node, add an 
79
   * IPv4 host route to the IPv4 address of the peer node.  
80
   */
81
  static void AddIpv4Routes (Ptr<Node> n1, Ptr<Node> n2, Ptr<const PointToPointChannel> channel);
82
};
83
84
} // namespace ns3
85
86
#endif
87
(-)7a81f1ef8c74 (+20 lines)
Added Link Here 
1
## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
2
3
4
def build(bld):
5
    pointtopoint = bld.create_obj('cpp', 'shlib')
6
    pointtopoint.name = 'ns3-point-to-point'
7
    pointtopoint.target = pointtopoint.name
8
    pointtopoint.uselib_local = ['ns3-node']
9
    pointtopoint.source = [
10
        'point-to-point-net-device.cc',
11
        'point-to-point-channel.cc',
12
        'point-to-point-topology.cc',
13
        ]
14
    headers = bld.create_obj('ns3header')
15
    headers.source = [
16
        'point-to-point-net-device.h',
17
        'point-to-point-channel.h',
18
        'point-to-point-topology.h',
19
        ]
20
(-)a/src/wscript (-1 / +1 lines)
 Lines 15-21   all_modules = [ Link Here 
15
    'simulator',
15
    'simulator',
16
    'node',
16
    'node',
17
    'internet-node',
17
    'internet-node',
18
    'devices/p2p',
18
    'devices/point-to-point',
19
    'applications',
19
    'applications',
20
    ]
20
    ]
21
21

Return to bug 56