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

(-)a/examples/matrix-topology/wscript (-1 / +1 lines)
 Lines 2-6    Link Here 
2
2
3
def build(bld):
3
def build(bld):
4
    obj = bld.create_ns3_program('matrix-topology',
4
    obj = bld.create_ns3_program('matrix-topology',
5
                                 ['network', 'internet', 'netanim', 'mobility', 'applications'])
5
                                 ['network', 'internet', 'netanim', 'point-to-point', 'mobility', 'applications'])
6
    obj.source = 'matrix-topology.cc'
6
    obj.source = 'matrix-topology.cc'
(-)a/examples/naming/object-names.cc (+1 lines)
 Lines 25-30    Link Here 
25
#include "ns3/core-module.h"
25
#include "ns3/core-module.h"
26
#include "ns3/csma-module.h"
26
#include "ns3/csma-module.h"
27
#include "ns3/applications-module.h"
27
#include "ns3/applications-module.h"
28
#include "ns3/internet-module.h"
28
29
29
using namespace ns3;
30
using namespace ns3;
30
31
(-)a/examples/realtime/realtime-udp-echo.cc (+1 lines)
 Lines 29-34    Link Here 
29
#include "ns3/core-module.h"
29
#include "ns3/core-module.h"
30
#include "ns3/csma-module.h"
30
#include "ns3/csma-module.h"
31
#include "ns3/applications-module.h"
31
#include "ns3/applications-module.h"
32
#include "ns3/internet-module.h"
32
33
33
using namespace ns3;
34
using namespace ns3;
34
35
(-)a/examples/routing/mixed-global-routing.cc (-1 / +1 lines)
 Lines 41-47    Link Here 
41
#include "ns3/point-to-point-module.h"
41
#include "ns3/point-to-point-module.h"
42
#include "ns3/csma-module.h"
42
#include "ns3/csma-module.h"
43
#include "ns3/applications-module.h"
43
#include "ns3/applications-module.h"
44
#include "ns3/ipv4-global-routing-helper.h"
44
#include "ns3/internet-module.h"
45
45
46
using namespace ns3;
46
using namespace ns3;
47
47
(-)a/examples/socket/wscript (-2 / +2 lines)
 Lines 1-8    Link Here 
1
## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
1
## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
2
2
3
def build(bld):
3
def build(bld):
4
    obj = bld.create_ns3_program('socket-bound-static-routing', ['network', 'csma', 'internet'])
4
    obj = bld.create_ns3_program('socket-bound-static-routing', ['network', 'csma', 'point-to-point', 'internet'])
5
    obj.source = 'socket-bound-static-routing.cc'
5
    obj.source = 'socket-bound-static-routing.cc'
6
6
7
    obj = bld.create_ns3_program('socket-bound-tcp-static-routing', ['network', 'csma', 'internet'])
7
    obj = bld.create_ns3_program('socket-bound-tcp-static-routing', ['network', 'csma', 'point-to-point', 'internet'])
8
    obj.source = 'socket-bound-tcp-static-routing.cc'
8
    obj.source = 'socket-bound-tcp-static-routing.cc'
(-)a/examples/tcp/star.cc (-1 / +1 lines)
 Lines 21-27    Link Here 
21
#include "ns3/internet-module.h"
21
#include "ns3/internet-module.h"
22
#include "ns3/point-to-point-module.h"
22
#include "ns3/point-to-point-module.h"
23
#include "ns3/applications-module.h"
23
#include "ns3/applications-module.h"
24
#include "ns3/ipv4-global-routing-helper.h"
24
#include "ns3/point-to-point-layout-module.h"
25
25
26
// Network topology (default)
26
// Network topology (default)
27
//
27
//
(-)a/examples/tcp/tcp-nsc-zoo.cc (-1 / +1 lines)
 Lines 34-40    Link Here 
34
#include "ns3/applications-module.h"
34
#include "ns3/applications-module.h"
35
#include "ns3/network-module.h"
35
#include "ns3/network-module.h"
36
#include "ns3/csma-module.h"
36
#include "ns3/csma-module.h"
37
#include "ns3/ipv4-global-routing-helper.h"
37
#include "ns3/internet-module.h"
38
38
39
using namespace ns3;
39
using namespace ns3;
40
40
(-)a/examples/tcp/wscript (-1 / +1 lines)
 Lines 18-24    Link Here 
18
    obj.source = 'tcp-star-server.cc'
18
    obj.source = 'tcp-star-server.cc'
19
19
20
    obj = bld.create_ns3_program('star',
20
    obj = bld.create_ns3_program('star',
21
                                 ['netanim', 'point-to-point', 'applications', 'internet'])
21
                                 ['netanim', 'point-to-point', 'point-to-point-layout', 'applications', 'internet'])
22
    obj.source = 'star.cc'
22
    obj.source = 'star.cc'
23
23
24
    obj = bld.create_ns3_program('tcp-bulk-send',
24
    obj = bld.create_ns3_program('tcp-bulk-send',
(-)a/examples/tutorial/third.cc (-1 / +1 lines)
 Lines 21-27    Link Here 
21
#include "ns3/wifi-module.h"
21
#include "ns3/wifi-module.h"
22
#include "ns3/mobility-module.h"
22
#include "ns3/mobility-module.h"
23
#include "ns3/csma-module.h"
23
#include "ns3/csma-module.h"
24
#include "ns3/ipv4-global-routing-helper.h"
24
#include "ns3/internet-module.h"
25
25
26
// Default Network Topology
26
// Default Network Topology
27
//
27
//
(-)a/examples/udp-client-server/udp-client-server.cc (+1 lines)
 Lines 28-33    Link Here 
28
#include "ns3/core-module.h"
28
#include "ns3/core-module.h"
29
#include "ns3/csma-module.h"
29
#include "ns3/csma-module.h"
30
#include "ns3/applications-module.h"
30
#include "ns3/applications-module.h"
31
#include "ns3/internet-module.h"
31
32
32
using namespace ns3;
33
using namespace ns3;
33
34
(-)a/examples/udp-client-server/udp-trace-client-server.cc (+1 lines)
 Lines 27-32    Link Here 
27
#include "ns3/core-module.h"
27
#include "ns3/core-module.h"
28
#include "ns3/csma-module.h"
28
#include "ns3/csma-module.h"
29
#include "ns3/applications-module.h"
29
#include "ns3/applications-module.h"
30
#include "ns3/internet-module.h"
30
31
31
using namespace ns3;
32
using namespace ns3;
32
33
(-)a/examples/udp/udp-echo.cc (+1 lines)
 Lines 29-34    Link Here 
29
#include "ns3/core-module.h"
29
#include "ns3/core-module.h"
30
#include "ns3/csma-module.h"
30
#include "ns3/csma-module.h"
31
#include "ns3/applications-module.h"
31
#include "ns3/applications-module.h"
32
#include "ns3/internet-module.h"
32
33
33
using namespace ns3;
34
using namespace ns3;
34
35
(-)a/examples/wireless/mixed-wireless.cc (-1 / +1 lines)
 Lines 68-74    Link Here 
68
#include "ns3/wifi-module.h"
68
#include "ns3/wifi-module.h"
69
#include "ns3/csma-module.h"
69
#include "ns3/csma-module.h"
70
#include "ns3/olsr-helper.h"
70
#include "ns3/olsr-helper.h"
71
#include "ns3/ipv4-global-routing-helper.h"
71
#include "ns3/internet-module.h"
72
72
73
using namespace ns3;
73
using namespace ns3;
74
74
(-)a/examples/wireless/wifi-wired-bridging.cc (+1 lines)
 Lines 49-54    Link Here 
49
#include "ns3/wifi-module.h"
49
#include "ns3/wifi-module.h"
50
#include "ns3/network-module.h"
50
#include "ns3/network-module.h"
51
#include "ns3/csma-module.h"
51
#include "ns3/csma-module.h"
52
#include "ns3/internet-module.h"
52
#include "ns3/bridge-helper.h"
53
#include "ns3/bridge-helper.h"
53
#include <vector>
54
#include <vector>
54
#include <stdint.h>
55
#include <stdint.h>
(-)a/src/bridge/examples/csma-bridge-one-hop.cc (-1 / +1 lines)
 Lines 74-80    Link Here 
74
#include "ns3/applications-module.h"
74
#include "ns3/applications-module.h"
75
#include "ns3/bridge-module.h"
75
#include "ns3/bridge-module.h"
76
#include "ns3/csma-module.h"
76
#include "ns3/csma-module.h"
77
#include "ns3/ipv4-global-routing-helper.h"
77
#include "ns3/internet-module.h"
78
78
79
using namespace ns3;
79
using namespace ns3;
80
80
(-)a/src/bridge/examples/csma-bridge.cc (+1 lines)
 Lines 37-42    Link Here 
37
#include "ns3/applications-module.h"
37
#include "ns3/applications-module.h"
38
#include "ns3/bridge-module.h"
38
#include "ns3/bridge-module.h"
39
#include "ns3/csma-module.h"
39
#include "ns3/csma-module.h"
40
#include "ns3/internet-module.h"
40
41
41
using namespace ns3;
42
using namespace ns3;
42
43
(-)e9ca5b2838e7 (+195 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
 */
17
18
#include "ns3/core-module.h"
19
#include "ns3/network-module.h"
20
#include "ns3/csma-module.h"
21
#include "ns3/csma-star-helper.h"
22
#include "ns3/applications-module.h"
23
#include "ns3/csma-module.h"
24
#include "ns3/internet-module.h"
25
26
// Network topology (default)
27
//
28
//            n2     +          +     n3          .
29
//             | ... |\        /| ... |           .
30
//             ======= \      / =======           .
31
//              CSMA    \    /   CSMA             .
32
//                       \  /                     .
33
//            n1     +--- n0 ---+     n4          .
34
//             | ... |   /  \   | ... |           .
35
//             =======  /    \  =======           .
36
//              CSMA   /      \  CSMA             .
37
//                    /        \                  .
38
//            n6     +          +     n5          .
39
//             | ... |          | ... |           .
40
//             =======          =======           .
41
//              CSMA             CSMA             .
42
//
43
44
using namespace ns3;
45
46
NS_LOG_COMPONENT_DEFINE ("CsmaStar");
47
48
int 
49
main (int argc, char *argv[])
50
{
51
52
  //
53
  // Set up some default values for the simulation.
54
  //
55
  Config::SetDefault ("ns3::OnOffApplication::PacketSize", UintegerValue (137));
56
57
  // ??? try and stick 15kb/s into the data rate
58
  Config::SetDefault ("ns3::OnOffApplication::DataRate", StringValue ("14kb/s"));
59
60
  //
61
  // Default number of nodes in the star.  Overridable by command line argument.
62
  //
63
  uint32_t nSpokes = 7;
64
65
  CommandLine cmd;
66
  cmd.AddValue("nSpokes", "Number of spoke nodes to place in the star", nSpokes);
67
  cmd.Parse (argc, argv);
68
69
  NS_LOG_INFO ("Build star topology.");
70
  CsmaHelper csma;
71
  csma.SetChannelAttribute ("DataRate", StringValue ("100Mbps"));
72
  csma.SetChannelAttribute ("Delay", StringValue ("1ms"));
73
  CsmaStarHelper star (nSpokes, csma);
74
75
  NodeContainer fillNodes;
76
77
  //
78
  // Just to be nasy, hang some more nodes off of the CSMA channel for each
79
  // spoke, so that there are a total of 16 nodes on each channel.  Stash
80
  // all of these new devices into a container.
81
  //
82
  NetDeviceContainer fillDevices;
83
84
  uint32_t nFill = 14;
85
  for (uint32_t i = 0; i < star.GetSpokeDevices ().GetN (); ++i)
86
    {
87
      Ptr<Channel> channel = star.GetSpokeDevices ().Get (i)->GetChannel ();
88
      Ptr<CsmaChannel> csmaChannel = channel->GetObject<CsmaChannel> ();
89
      NodeContainer newNodes;
90
      newNodes.Create (nFill);
91
      fillNodes.Add (newNodes);
92
      fillDevices.Add (csma.Install (newNodes, csmaChannel));
93
    }
94
95
  NS_LOG_INFO ("Install internet stack on all nodes.");
96
  InternetStackHelper internet;
97
  star.InstallStack (internet);
98
  internet.Install (fillNodes);
99
100
  NS_LOG_INFO ("Assign IP Addresses.");
101
  star.AssignIpv4Addresses (Ipv4AddressHelper ("10.1.0.0", "255.255.255.0"));
102
103
  //
104
  // We assigned addresses to the logical hub and the first "drop" of the 
105
  // CSMA network that acts as the spoke, but we also have a number of fill
106
  // devices (nFill) also hanging off the CSMA network.  We have got to 
107
  // assign addresses to them as well.  We put all of the fill devices into
108
  // a single device container, so the first nFill devices are associated
109
  // with the channel connected to spokeDevices.Get (0), the second nFill
110
  // devices afe associated with the channel connected to spokeDevices.Get (1)
111
  // etc.
112
  //
113
  Ipv4AddressHelper address;
114
  for(uint32_t i = 0; i < star.SpokeCount (); ++i)
115
  {
116
    std::ostringstream subnet;
117
    subnet << "10.1." << i << ".0";
118
    NS_LOG_INFO ("Assign IP Addresses for CSMA subnet " << subnet.str ());
119
    address.SetBase (subnet.str ().c_str (), "255.255.255.0", "0.0.0.3");
120
121
    for (uint32_t j = 0; j < nFill; ++j)
122
      {
123
        address.Assign (fillDevices.Get (i * nFill + j));
124
      }
125
  }
126
127
  NS_LOG_INFO ("Create applications.");
128
  //
129
  // Create a packet sink on the star "hub" to receive packets.  
130
  // 
131
  uint16_t port = 50000;
132
  Address hubLocalAddress (InetSocketAddress (Ipv4Address::GetAny (), port));
133
  PacketSinkHelper packetSinkHelper ("ns3::TcpSocketFactory", hubLocalAddress);
134
  ApplicationContainer hubApp = packetSinkHelper.Install (star.GetHub ());
135
  hubApp.Start (Seconds (1.0));
136
  hubApp.Stop (Seconds (10.0));
137
138
  //
139
  // Create OnOff applications to send TCP to the hub, one on each spoke node.
140
  //
141
  OnOffHelper onOffHelper ("ns3::TcpSocketFactory", Address ());
142
  onOffHelper.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1)));
143
  onOffHelper.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0)));
144
145
  ApplicationContainer spokeApps;
146
147
  for (uint32_t i = 0; i < star.SpokeCount (); ++i)
148
    {
149
      AddressValue remoteAddress (InetSocketAddress (star.GetHubIpv4Address (i), port));
150
      onOffHelper.SetAttribute ("Remote", remoteAddress);
151
      spokeApps.Add (onOffHelper.Install (star.GetSpokeNode (i)));
152
    }
153
154
  spokeApps.Start (Seconds (1.0));
155
  spokeApps.Stop (Seconds (10.0));
156
157
  //
158
  // Because we are evil, we also add OnOff applications to send TCP to the hub 
159
  // from the fill devices on each CSMA link.  The first nFill nodes in the 
160
  // fillNodes container are on the CSMA network talking to the zeroth device
161
  // on the hub node.  The next nFill nodes are on the CSMA network talking to
162
  // the first device on the hub node, etc.  So the ith fillNode is associated
163
  // with the hub address found on the (i / nFill)th device on the hub node.
164
  //
165
  ApplicationContainer fillApps;
166
167
  for (uint32_t i = 0; i < fillNodes.GetN (); ++i)
168
    {
169
      AddressValue remoteAddress (InetSocketAddress (star.GetHubIpv4Address (i / nFill), port));
170
      onOffHelper.SetAttribute ("Remote", remoteAddress);
171
      fillApps.Add (onOffHelper.Install (fillNodes.Get (i)));
172
    }
173
174
  fillApps.Start (Seconds (1.0));
175
  fillApps.Stop (Seconds (10.0));
176
177
  NS_LOG_INFO ("Enable static global routing.");
178
  //
179
  // Turn on global static routing so we can actually be routed across the star.
180
  //
181
  Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
182
183
  NS_LOG_INFO ("Enable pcap tracing.");
184
  //
185
  // Do pcap tracing on all devices on all nodes.
186
  //
187
  csma.EnablePcapAll ("csma-star", false);
188
189
  NS_LOG_INFO ("Run Simulation.");
190
  Simulator::Run ();
191
  Simulator::Destroy ();
192
  NS_LOG_INFO ("Done.");
193
194
  return 0;
195
}
(-)e9ca5b2838e7 (+1 lines)
Added Link Here 
1
exec "`dirname "$0"`"/../../waf "$@"
(-)e9ca5b2838e7 (+5 lines)
Added Link Here 
1
## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
2
3
def build(bld):
4
    obj = bld.create_ns3_program('csma-star', ['csma', 'csma-layout', 'internet', 'applications'])
5
    obj.source = 'csma-star.cc'
(-)e9ca5b2838e7 (+109 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
17
#include <iostream>
18
#include <sstream>
19
20
// ns3 includes
21
#include "ns3/animation-interface.h"
22
#include "ns3/csma-star-helper.h"
23
#include "ns3/node-list.h"
24
#include "ns3/point-to-point-net-device.h"
25
#include "ns3/vector.h"
26
27
NS_LOG_COMPONENT_DEFINE("CsmaStarHelper");
28
29
namespace ns3 {
30
  
31
CsmaStarHelper::CsmaStarHelper (uint32_t numSpokes,
32
                                CsmaHelper csmaHelper)
33
{
34
  m_hub.Create (1);
35
  m_spokes.Create (numSpokes);
36
37
  for (uint32_t i = 0; i < m_spokes.GetN (); ++i)
38
    {
39
      NodeContainer nodes (m_hub.Get (0), m_spokes.Get (i));
40
      NetDeviceContainer nd = csmaHelper.Install (nodes);
41
      m_hubDevices.Add (nd.Get (0));
42
      m_spokeDevices.Add (nd.Get (1));
43
    }
44
}
45
46
CsmaStarHelper::~CsmaStarHelper ()
47
{}
48
49
Ptr<Node> 
50
CsmaStarHelper::GetHub () const
51
{
52
  return m_hub.Get (0);
53
}
54
55
Ptr<Node> 
56
CsmaStarHelper::GetSpokeNode (uint32_t i) const
57
{
58
  return m_spokes.Get (i);
59
}
60
61
NetDeviceContainer
62
CsmaStarHelper::GetHubDevices () const
63
{
64
  return m_spokeDevices;
65
}
66
67
NetDeviceContainer
68
CsmaStarHelper::GetSpokeDevices () const
69
{
70
  return m_spokeDevices;
71
}
72
73
Ipv4Address 
74
CsmaStarHelper::GetHubIpv4Address (uint32_t i) const
75
{
76
  return m_hubInterfaces.GetAddress (i);
77
}
78
79
Ipv4Address 
80
CsmaStarHelper::GetSpokeIpv4Address (uint32_t i) const
81
{
82
  return m_spokeInterfaces.GetAddress (i);
83
}
84
85
uint32_t  
86
CsmaStarHelper::SpokeCount () const
87
{
88
  return m_spokes.GetN ();
89
}
90
91
void 
92
CsmaStarHelper::InstallStack (InternetStackHelper stack)
93
{
94
  stack.Install (m_hub);
95
  stack.Install (m_spokes);
96
}
97
98
void 
99
CsmaStarHelper::AssignIpv4Addresses (Ipv4AddressHelper address)
100
{
101
  for (uint32_t i = 0; i < m_spokes.GetN (); ++i)
102
    {
103
      m_hubInterfaces.Add (address.Assign (m_hubDevices.Get (i)));
104
      m_spokeInterfaces.Add (address.Assign (m_spokeDevices.Get (i)));
105
      address.NewNetwork ();
106
    }
107
}
108
109
} // namespace ns3
(-)e9ca5b2838e7 (+123 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
17
// Define an object to create a dumbbell topology.
18
19
#ifndef CSMA_STAR_HELPER_H
20
#define CSMA_STAR_HELPER_H
21
22
#include <string>
23
24
#include "csma-helper.h"
25
#include "ipv4-address-helper.h"
26
#include "internet-stack-helper.h"
27
#include "ipv4-interface-container.h"
28
29
namespace ns3 {
30
  
31
/**
32
 * \brief A helper to make it easier to create a star topology
33
 * with Csma links
34
 */
35
class CsmaStarHelper
36
{
37
public:
38
  /**
39
   * Create a CsmaStarHelper in order to easily create
40
   * star topologies using Csma links
41
   *
42
   * \param numSpokes the number of links attached to 
43
   *        the hub node, creating a total of 
44
   *        numSpokes + 1 nodes
45
   *
46
   * \param csmaHelper the link helper for Csma links, 
47
   *        used to link nodes together
48
   */
49
  CsmaStarHelper (uint32_t numSpokes, 
50
                  CsmaHelper csmaHelper);
51
52
  ~CsmaStarHelper ();
53
54
public:
55
  /**
56
   * \returns a node pointer to the hub node in the
57
   *          star, i.e., the center node
58
   */
59
  Ptr<Node> GetHub () const;
60
61
  /**
62
   * \param i an index into the spokes of the star
63
   *
64
   * \returns a node pointer to the node at the indexed spoke
65
   */
66
  Ptr<Node> GetSpokeNode (uint32_t i) const;
67
68
  /**
69
   * \returns the net-device container which contains all of 
70
   *          the devices on the hub node
71
   */
72
  NetDeviceContainer GetHubDevices () const;
73
74
  /**
75
   * \returns the net-device container which contains all of 
76
   *          the spoke node devices
77
   */
78
  NetDeviceContainer GetSpokeDevices () const;
79
80
  /**
81
   * \param i index into the hub interfaces
82
   *
83
   * \returns Ipv4Address according to indexed hub interface
84
   */
85
  Ipv4Address GetHubIpv4Address (uint32_t i) const;
86
87
  /**
88
   * \param i index into the spoke interfaces
89
   *
90
   * \returns Ipv4Address according to indexed spoke interface
91
   */
92
  Ipv4Address GetSpokeIpv4Address (uint32_t i) const;
93
94
  /**
95
   * \returns the total number of spokes in the star
96
   */
97
  uint32_t SpokeCount () const;
98
99
  /**
100
   * \param stack an InternetStackHelper which is used to install 
101
   *              on every node in the star
102
   */
103
  void InstallStack (InternetStackHelper stack);
104
105
  /**
106
   * \param address an Ipv4AddressHelper which is used to install 
107
   *                Ipv4 addresses on all the node interfaces in 
108
   *                the star
109
   */
110
  void AssignIpv4Addresses (Ipv4AddressHelper address);
111
112
private:
113
  NodeContainer m_hub;
114
  NetDeviceContainer m_hubDevices;
115
  NodeContainer m_spokes;
116
  NetDeviceContainer m_spokeDevices;
117
  Ipv4InterfaceContainer m_hubInterfaces;
118
  Ipv4InterfaceContainer m_spokeInterfaces;
119
};
120
121
} // namespace ns3
122
123
#endif /* CSMA_STAR_HELPER_H */
(-)e9ca5b2838e7 (+1 lines)
Added Link Here 
1
exec "`dirname "$0"`"/../../waf "$@"
(-)e9ca5b2838e7 (+18 lines)
Added Link Here 
1
## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
2
3
def build(bld):
4
    obj = bld.create_ns3_module('csma-layout', ['csma', 'network', 'applications'])
5
    obj.source = [
6
        'model/csma-star-helper.cc',
7
        ]
8
    headers = bld.new_task_gen('ns3header')
9
    headers.module = 'csma-layout'
10
    headers.source = [
11
        'model/csma-star-helper.h',
12
        ]
13
14
    if bld.env['ENABLE_EXAMPLES']:
15
        bld.add_subdirs('examples')
16
17
    #bld.ns3_python_bindings()
18
(-)a/src/csma/examples/csma-broadcast.cc (+1 lines)
 Lines 36-41    Link Here 
36
#include "ns3/network-module.h"
36
#include "ns3/network-module.h"
37
#include "ns3/csma-module.h"
37
#include "ns3/csma-module.h"
38
#include "ns3/applications-module.h"
38
#include "ns3/applications-module.h"
39
#include "ns3/internet-module.h"
39
40
40
using namespace ns3;
41
using namespace ns3;
41
42
(-)a/src/csma/examples/csma-multicast.cc (-2 / +1 lines)
 Lines 36-43    Link Here 
36
#include "ns3/network-module.h"
36
#include "ns3/network-module.h"
37
#include "ns3/csma-module.h"
37
#include "ns3/csma-module.h"
38
#include "ns3/applications-module.h"
38
#include "ns3/applications-module.h"
39
#include "ns3/ipv4-static-routing-helper.h"
39
#include "ns3/internet-module.h"
40
#include "ns3/ipv4-list-routing-helper.h"
41
40
42
using namespace ns3;
41
using namespace ns3;
43
42
(-)a/src/csma/examples/csma-one-subnet.cc (+1 lines)
 Lines 32-37    Link Here 
32
#include "ns3/network-module.h"
32
#include "ns3/network-module.h"
33
#include "ns3/csma-module.h"
33
#include "ns3/csma-module.h"
34
#include "ns3/applications-module.h"
34
#include "ns3/applications-module.h"
35
#include "ns3/internet-module.h"
35
36
36
using namespace ns3;
37
using namespace ns3;
37
38
(-)a/src/csma/examples/csma-ping.cc (+1 lines)
 Lines 32-37    Link Here 
32
#include "ns3/network-module.h"
32
#include "ns3/network-module.h"
33
#include "ns3/csma-module.h"
33
#include "ns3/csma-module.h"
34
#include "ns3/applications-module.h"
34
#include "ns3/applications-module.h"
35
#include "ns3/internet-module.h"
35
36
36
using namespace ns3;
37
using namespace ns3;
37
38
(-)a/src/csma/examples/csma-raw-ip-socket.cc (+1 lines)
 Lines 35-40    Link Here 
35
#include "ns3/network-module.h"
35
#include "ns3/network-module.h"
36
#include "ns3/csma-module.h"
36
#include "ns3/csma-module.h"
37
#include "ns3/applications-module.h"
37
#include "ns3/applications-module.h"
38
#include "ns3/internet-module.h"
38
39
39
using namespace ns3;
40
using namespace ns3;
40
41
(-)a/src/csma/examples/wscript (-3 lines)
 Lines 13-21    Link Here 
13
    obj = bld.create_ns3_program('csma-multicast', ['csma', 'internet'])
13
    obj = bld.create_ns3_program('csma-multicast', ['csma', 'internet'])
14
    obj.source = 'csma-multicast.cc'
14
    obj.source = 'csma-multicast.cc'
15
15
16
    obj = bld.create_ns3_program('csma-star', ['csma', 'internet'])
17
    obj.source = 'csma-star.cc'
18
19
    obj = bld.create_ns3_program('csma-raw-ip-socket', ['csma', 'internet'])
16
    obj = bld.create_ns3_program('csma-raw-ip-socket', ['csma', 'internet'])
20
    obj.source = 'csma-raw-ip-socket.cc'
17
    obj.source = 'csma-raw-ip-socket.cc'
21
18
(-)a/src/csma/wscript (-3 / +1 lines)
 Lines 1-13    Link Here 
1
## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
1
## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
2
2
3
def build(bld):
3
def build(bld):
4
    obj = bld.create_ns3_module('csma', ['network', 'point-to-point', 'applications', 'netanim'])
4
    obj = bld.create_ns3_module('csma', ['network', 'applications'])
5
    obj.source = [
5
    obj.source = [
6
        'model/backoff.cc',
6
        'model/backoff.cc',
7
        'model/csma-net-device.cc',
7
        'model/csma-net-device.cc',
8
        'model/csma-channel.cc',
8
        'model/csma-channel.cc',
9
        'helper/csma-helper.cc',
9
        'helper/csma-helper.cc',
10
        'helper/csma-star-helper.cc',
11
        ]
10
        ]
12
    headers = bld.new_task_gen('ns3header')
11
    headers = bld.new_task_gen('ns3header')
13
    headers.module = 'csma'
12
    headers.module = 'csma'
 Lines 16-22    Link Here 
16
        'model/csma-net-device.h',
15
        'model/csma-net-device.h',
17
        'model/csma-channel.h',
16
        'model/csma-channel.h',
18
        'helper/csma-helper.h',
17
        'helper/csma-helper.h',
19
        'helper/csma-star-helper.h',
20
        ]
18
        ]
21
19
22
    if bld.env['ENABLE_EXAMPLES']:
20
    if bld.env['ENABLE_EXAMPLES']:
(-)a/src/netanim/examples/dumbbell-animation.cc (-1 / +1 lines)
 Lines 24-30    Link Here 
24
#include "ns3/point-to-point-module.h"
24
#include "ns3/point-to-point-module.h"
25
#include "ns3/netanim-module.h"
25
#include "ns3/netanim-module.h"
26
#include "ns3/applications-module.h"
26
#include "ns3/applications-module.h"
27
#include "ns3/ipv4-global-routing-helper.h"
27
#include "ns3/point-to-point-layout-module.h"
28
28
29
using namespace ns3;
29
using namespace ns3;
30
30
(-)a/src/netanim/examples/grid-animation.cc (-1 / +1 lines)
 Lines 24-30    Link Here 
24
#include "ns3/point-to-point-module.h"
24
#include "ns3/point-to-point-module.h"
25
#include "ns3/netanim-module.h"
25
#include "ns3/netanim-module.h"
26
#include "ns3/applications-module.h"
26
#include "ns3/applications-module.h"
27
#include "ns3/ipv4-global-routing-helper.h"
27
#include "ns3/point-to-point-layout-module.h"
28
28
29
using namespace ns3;
29
using namespace ns3;
30
30
(-)a/src/netanim/examples/star-animation.cc (-1 / +1 lines)
 Lines 21-27    Link Here 
21
#include "ns3/internet-module.h"
21
#include "ns3/internet-module.h"
22
#include "ns3/point-to-point-module.h"
22
#include "ns3/point-to-point-module.h"
23
#include "ns3/applications-module.h"
23
#include "ns3/applications-module.h"
24
#include "ns3/ipv4-global-routing-helper.h"
24
#include "ns3/point-to-point-layout-module.h"
25
25
26
// Network topology (default)
26
// Network topology (default)
27
//
27
//
(-)a/src/netanim/examples/wscript (-3 / +3 lines)
 Lines 2-14    Link Here 
2
2
3
def build(bld):
3
def build(bld):
4
    obj = bld.create_ns3_program('dumbbell-animation',
4
    obj = bld.create_ns3_program('dumbbell-animation',
5
                                 ['netanim', 'applications'])
5
                                 ['netanim', 'applications', 'point-to-point-layout'])
6
    obj.source = 'dumbbell-animation.cc'
6
    obj.source = 'dumbbell-animation.cc'
7
7
8
    obj = bld.create_ns3_program('grid-animation',
8
    obj = bld.create_ns3_program('grid-animation',
9
                                 ['netanim', 'applications'])
9
                                 ['netanim', 'applications', 'point-to-point-layout'])
10
    obj.source = 'grid-animation.cc'
10
    obj.source = 'grid-animation.cc'
11
11
12
    obj = bld.create_ns3_program('star-animation',
12
    obj = bld.create_ns3_program('star-animation',
13
                                 ['netanim', 'applications'])
13
                                 ['netanim', 'applications', 'point-to-point-layout'])
14
    obj.source = 'star-animation.cc'
14
    obj.source = 'star-animation.cc'
(-)a/src/netanim/helper/point-to-point-dumbbell-helper.cc (-267 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
 * Author: George F. Riley<riley@ece.gatech.edu>
17
 */
18
19
// Implement an object to create a dumbbell topology.
20
21
#include <iostream>
22
#include <sstream>
23
24
// ns3 includes
25
#include "ns3/animation-interface.h"
26
#include "ns3/point-to-point-dumbbell-helper.h"
27
#include "ns3/constant-position-mobility-model.h"
28
29
#include "ns3/node-list.h"
30
#include "ns3/point-to-point-net-device.h"
31
#include "ns3/vector.h"
32
33
NS_LOG_COMPONENT_DEFINE("PointToPointDumbbellHelper");
34
35
namespace ns3 {
36
  
37
PointToPointDumbbellHelper::PointToPointDumbbellHelper (uint32_t nLeftLeaf,
38
                   PointToPointHelper leftHelper,
39
                   uint32_t nRightLeaf,
40
                   PointToPointHelper rightHelper,
41
                   PointToPointHelper bottleneckHelper)
42
{
43
  // Create the bottleneck routers
44
  m_routers.Create (2);
45
  // Create the leaf nodes
46
  m_leftLeaf.Create (nLeftLeaf);
47
  m_rightLeaf.Create (nRightLeaf);
48
49
  // Add the link connecting routers
50
  m_routerDevices = bottleneckHelper.Install (m_routers);
51
  // Add the left side links
52
  for (uint32_t i = 0; i < nLeftLeaf; ++i)
53
    {
54
      NetDeviceContainer c = leftHelper.Install (m_routers.Get (0),
55
                                                m_leftLeaf.Get (i));
56
      m_leftRouterDevices.Add (c.Get (0));
57
      m_leftLeafDevices.Add (c.Get(1));
58
    }
59
  // Add the right side links
60
  for (uint32_t i = 0; i < nRightLeaf; ++i)
61
    {
62
      NetDeviceContainer c = rightHelper.Install (m_routers.Get (1),
63
                                                m_rightLeaf.Get (i));
64
      m_rightRouterDevices.Add (c.Get (0));
65
      m_rightLeafDevices.Add (c.Get (1));
66
    }
67
}
68
69
PointToPointDumbbellHelper::~PointToPointDumbbellHelper ()
70
{}
71
72
Ptr<Node> PointToPointDumbbellHelper::GetLeft () const
73
{ // Get the left side bottleneck router
74
  return m_routers.Get (0);
75
}
76
77
Ptr<Node> PointToPointDumbbellHelper::GetLeft (uint32_t i) const
78
{ // Get the i'th left side leaf
79
  return m_leftLeaf.Get (i);
80
}
81
82
Ptr<Node> PointToPointDumbbellHelper::GetRight () const
83
{ // Get the right side bottleneck router
84
  return m_routers.Get (1);
85
}
86
87
Ptr<Node> PointToPointDumbbellHelper::GetRight (uint32_t i) const
88
{ // Get the i'th right side leaf
89
  return m_rightLeaf.Get (i);
90
}
91
92
Ipv4Address PointToPointDumbbellHelper::GetLeftIpv4Address (uint32_t i) const
93
{
94
  return m_leftLeafInterfaces.GetAddress (i);
95
}
96
97
Ipv4Address PointToPointDumbbellHelper::GetRightIpv4Address (uint32_t i) const
98
{
99
  return m_rightLeafInterfaces.GetAddress (i);
100
}
101
102
uint32_t  PointToPointDumbbellHelper::LeftCount () const
103
{ // Number of left side nodes
104
  return m_leftLeaf.GetN ();
105
}
106
107
uint32_t  PointToPointDumbbellHelper::RightCount () const
108
{ // Number of right side nodes
109
  return m_rightLeaf.GetN ();
110
}
111
112
void PointToPointDumbbellHelper::InstallStack (InternetStackHelper stack)
113
{
114
  stack.Install (m_routers);
115
  stack.Install (m_leftLeaf);
116
  stack.Install (m_rightLeaf);
117
}
118
119
void PointToPointDumbbellHelper::AssignIpv4Addresses (Ipv4AddressHelper leftIp,
120
                               Ipv4AddressHelper rightIp,
121
                               Ipv4AddressHelper routerIp)
122
{
123
  // Assign the router network
124
  m_routerInterfaces = routerIp.Assign (m_routerDevices);
125
  // Assign to left side 
126
  for (uint32_t i = 0; i < LeftCount (); ++i)
127
    {
128
      NetDeviceContainer ndc;
129
      ndc.Add (m_leftLeafDevices.Get (i));
130
      ndc.Add (m_leftRouterDevices.Get (i));
131
      Ipv4InterfaceContainer ifc = leftIp.Assign(ndc);
132
      m_leftLeafInterfaces.Add (ifc.Get (0));
133
      m_leftRouterInterfaces.Add (ifc.Get (1));
134
      leftIp.NewNetwork ();
135
    }
136
  // Assign to right side
137
  for (uint32_t i = 0; i < RightCount (); ++i)
138
    {
139
      NetDeviceContainer ndc;
140
      ndc.Add (m_rightLeafDevices.Get (i));
141
      ndc.Add (m_rightRouterDevices.Get (i));
142
      Ipv4InterfaceContainer ifc = rightIp.Assign (ndc);
143
      m_rightLeafInterfaces.Add (ifc.Get (0));
144
      m_rightRouterInterfaces.Add (ifc.Get (1));
145
      rightIp.NewNetwork ();
146
    }
147
}
148
149
150
void PointToPointDumbbellHelper::BoundingBox (double ulx, double uly, // Upper left x/y
151
                           double lrx, double lry) // Lower right y
152
{
153
  double xDist;
154
  double yDist;
155
  if (lrx > ulx)
156
    {
157
      xDist = lrx - ulx;
158
    }
159
  else
160
    {
161
      xDist = ulx - lrx;
162
    }
163
  if (lry > uly)
164
    {
165
      yDist = lry - uly;
166
    }
167
  else
168
    {
169
      yDist = uly - lry;
170
    }
171
172
  double xAdder = xDist / 3.0;
173
  double  thetaL = M_PI / (LeftCount () + 1.0);
174
  double  thetaR = M_PI / (RightCount () + 1.0);
175
176
  // Place the left router
177
  Ptr<Node> lr = GetLeft ();
178
  Ptr<ConstantPositionMobilityModel> loc = lr->GetObject<ConstantPositionMobilityModel> ();
179
  if (loc == 0)
180
    {
181
      loc = CreateObject<ConstantPositionMobilityModel> ();
182
      lr->AggregateObject (loc);
183
    }
184
  Vector lrl (ulx + xAdder, uly + yDist/2.0, 0);
185
  loc->SetPosition (lrl);
186
  
187
  // Place the right router
188
  Ptr<Node> rr = GetRight ();
189
  loc = rr->GetObject<ConstantPositionMobilityModel> ();
190
  if (loc == 0)
191
    {
192
      loc = CreateObject<ConstantPositionMobilityModel> ();
193
      rr->AggregateObject (loc);
194
    }
195
  Vector rrl (ulx + xAdder * 2, uly + yDist/2.0, 0); // Right router location
196
  loc->SetPosition (rrl);
197
198
  // Place the left leaf nodes
199
  double theta = -M_PI_2 + thetaL;
200
  for (uint32_t l = 0; l < LeftCount (); ++l)
201
    {
202
      // Make them in a circular pattern to make all line lengths the same
203
      // Special case when theta = 0, to be sure we get a straight line
204
      if ((LeftCount () % 2) == 1)
205
        { // Count is odd, see if we are in middle
206
          if (l == (LeftCount () / 2))
207
            {
208
              theta = 0.0;
209
            }
210
        }
211
      Ptr<Node> ln = GetLeft (l);
212
      loc = ln->GetObject<ConstantPositionMobilityModel> ();
213
      if (loc == 0)
214
        {
215
          loc = CreateObject<ConstantPositionMobilityModel> ();
216
          ln->AggregateObject (loc);
217
        }
218
      Vector lnl (lrl.x - cos (theta) * xAdder,
219
                   lrl.y + sin (theta) * xAdder, 0);  // Left Node Location
220
      // Insure did not exceed bounding box
221
      if (lnl.y < uly) 
222
        {
223
          lnl.y = uly; // Set to upper right y
224
        }
225
      if (lnl.y > lry) 
226
        {
227
          lnl.y = lry; // Set to lower right y
228
        }
229
      loc->SetPosition (lnl);
230
      theta += thetaL;
231
    }
232
  // Place the right nodes
233
  theta = -M_PI_2 + thetaR;
234
  for (uint32_t r = 0; r < RightCount (); ++r)
235
    {
236
      // Special case when theta = 0, to be sure we get a straight line
237
      if ((RightCount () % 2) == 1)
238
        { // Count is odd, see if we are in middle
239
          if (r == (RightCount () / 2))
240
            {
241
              theta = 0.0;
242
            }
243
        }
244
      Ptr<Node> rn = GetRight (r);
245
      loc = rn->GetObject<ConstantPositionMobilityModel> ();
246
      if (loc == 0)
247
        {
248
          loc = CreateObject<ConstantPositionMobilityModel> ();
249
          rn->AggregateObject (loc);
250
        }
251
      Vector rnl (rrl.x + cos (theta) * xAdder, // Right node location
252
                   rrl.y + sin (theta) * xAdder, 0);
253
      // Insure did not exceed bounding box
254
      if (rnl.y < uly) 
255
        {
256
          rnl.y = uly; // Set to upper right y
257
        }
258
      if (rnl.y > lry) 
259
        {
260
          rnl.y = lry; // Set to lower right y
261
        }
262
      loc->SetPosition (rnl);
263
      theta += thetaR;
264
    }
265
}
266
  
267
} // namespace ns3
(-)a/src/netanim/helper/point-to-point-dumbbell-helper.h (-160 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
 * Author: George F. Riley<riley@ece.gatech.edu>
17
 */
18
19
// Define an object to create a dumbbell topology.
20
21
#ifndef POINT_TO_POINT_DUMBBELL_HELPER_H
22
#define POINT_TO_POINT_DUMBBELL_HELPER_H
23
24
#include <string>
25
26
#include "point-to-point-helper.h"
27
#include "ipv4-address-helper.h"
28
#include "internet-stack-helper.h"
29
#include "ipv4-interface-container.h"
30
31
namespace ns3 {
32
  
33
/**
34
 * \brief A helper to make it easier to create a dumbbell topology
35
 * with p2p links
36
 */
37
class PointToPointDumbbellHelper
38
{
39
public:
40
  /**
41
   * Create a PointToPointDumbbellHelper in order to easily create
42
   * dumbbell topologies using p2p links
43
   *
44
   * \param nLeftLeaf number of left side leaf nodes in the dumbbell
45
   *
46
   * \param leftHelper PointToPointHelper used to install the links 
47
   *                   between the left leaf nodes and the left-most 
48
   *                   router
49
   *
50
   * \param nRightLeaf number of right side leaf nodes in the dumbbell
51
   *
52
   * \param rightHelper PointToPointHelper used to install the links 
53
   *                    between the right leaf nodes and the right-most 
54
   *                    router
55
   *
56
   * \param bottleneckHelper PointToPointHelper used to install the link 
57
   *                         between the inner-routers, usually known as 
58
   *                         the bottleneck link
59
   */
60
  PointToPointDumbbellHelper (uint32_t nLeftLeaf,
61
                              PointToPointHelper leftHelper,
62
                              uint32_t nRightLeaf,
63
                              PointToPointHelper rightHelper,
64
                              PointToPointHelper bottleneckHelper);
65
66
  ~PointToPointDumbbellHelper ();
67
68
public:
69
  /**
70
   * \returns pointer to the node of the left side bottleneck
71
   *          router
72
   */
73
  Ptr<Node> GetLeft () const;
74
  
75
  /**
76
   * \returns pointer to the i'th left side leaf node
77
   */
78
  Ptr<Node> GetLeft (uint32_t i) const;
79
80
  /**
81
   * \returns pointer to the node of the right side bottleneck
82
   *          router
83
   */
84
  Ptr<Node> GetRight () const;
85
86
  /**
87
   * \returns pointer to the i'th left side leaf node
88
   */
89
  Ptr<Node> GetRight (uint32_t i) const;
90
91
  /**
92
   * \returns an Ipv4Address of the i'th left leaf
93
   */
94
  Ipv4Address GetLeftIpv4Address (uint32_t i ) const; // Get left leaf address
95
96
  /**
97
   * \returns an Ipv4Address of the i'th right leaf
98
   */
99
  Ipv4Address GetRightIpv4Address (uint32_t i) const; // Get right leaf address
100
101
  /**
102
   * \returns total number of left side leaf nodes
103
   */
104
  uint32_t  LeftCount () const;
105
106
  /**
107
   * \returns total number of right side leaf nodes
108
   */
109
  uint32_t  RightCount () const;
110
111
  /**
112
   * \param stack an InternetStackHelper which is used to install 
113
   *              on every node in the dumbbell
114
   */
115
  void      InstallStack (InternetStackHelper stack);
116
117
  /**
118
   * \param leftIp Ipv4AddressHelper to assign Ipv4 addresses to the
119
   *               interfaces on the left side of the dumbbell
120
   *
121
   * \param rightIp Ipv4AddressHelper to assign Ipv4 addresses to the
122
   *                interfaces on the right side of the dumbbell
123
   *
124
   * \param routerIp Ipv4AddressHelper to assign Ipv4 addresses to the 
125
   *                 interfaces on the bottleneck link
126
   */
127
  void      AssignIpv4Addresses (Ipv4AddressHelper leftIp,
128
                                 Ipv4AddressHelper rightIp,
129
                                 Ipv4AddressHelper routerIp);
130
131
  /**
132
   * Sets up the node canvas locations for every node in the dumbbell.
133
   * This is needed for use with the animation interface
134
   *
135
   * \param ulx upper left x value
136
   * \param uly upper left y value
137
   * \param lrx lower right x value
138
   * \param lry lower right y value
139
   */
140
  void      BoundingBox (double ulx, double uly, double lrx, double lry);
141
  
142
private:
143
  NodeContainer          m_leftLeaf;
144
  NetDeviceContainer     m_leftLeafDevices;
145
  NodeContainer          m_rightLeaf;
146
  NetDeviceContainer     m_rightLeafDevices;
147
  NodeContainer          m_routers;
148
  NetDeviceContainer     m_routerDevices; // just two connecting the routers
149
  NetDeviceContainer     m_leftRouterDevices;
150
  NetDeviceContainer     m_rightRouterDevices;
151
  Ipv4InterfaceContainer m_leftLeafInterfaces;
152
  Ipv4InterfaceContainer m_leftRouterInterfaces;
153
  Ipv4InterfaceContainer m_rightLeafInterfaces;
154
  Ipv4InterfaceContainer m_rightRouterInterfaces;
155
  Ipv4InterfaceContainer m_routerInterfaces;
156
};
157
158
} // namespace ns3
159
160
#endif /* POINT_TO_POINT_DUMBBELL_HELPER_H */
(-)a/src/netanim/helper/point-to-point-grid-helper.cc (-216 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
 * Author: Josh Pelkey <jpelkey@gatech.edu>
17
 */
18
19
#include "ns3/point-to-point-grid-helper.h"
20
#include "ns3/animation-interface.h"
21
#include "ns3/internet-stack-helper.h"
22
#include "ns3/point-to-point-helper.h"
23
#include "ns3/constant-position-mobility-model.h"
24
#include "ns3/string.h"
25
#include "ns3/vector.h"
26
#include "ns3/log.h"
27
28
NS_LOG_COMPONENT_DEFINE("PointToPointGridHelper");
29
30
namespace ns3 {
31
  
32
PointToPointGridHelper::PointToPointGridHelper (uint32_t nRows, 
33
                                                uint32_t nCols, 
34
                                                PointToPointHelper pointToPoint)
35
  : m_xSize (nCols), m_ySize (nRows)
36
{
37
  // Bounds check
38
  if (m_xSize < 1 || m_ySize < 1 || (m_xSize < 2 && m_ySize < 2))
39
    {
40
      NS_FATAL_ERROR ("Need more nodes for grid.");
41
    }
42
43
  InternetStackHelper stack;
44
45
  for (uint32_t y = 0; y < nRows; ++y)
46
  {
47
    NodeContainer rowNodes;
48
    NetDeviceContainer rowDevices;
49
    NetDeviceContainer colDevices;
50
51
    for (uint32_t x = 0; x < nCols; ++x)
52
    {
53
      rowNodes.Create (1);
54
55
      // install p2p links across the row
56
      if (x > 0)
57
      {
58
        rowDevices.Add (pointToPoint.
59
            Install (rowNodes.Get (x-1), rowNodes.Get (x)));
60
      }
61
62
      // install vertical p2p links
63
      if (y > 0)
64
      {
65
        colDevices.Add(pointToPoint.
66
                      Install ((m_nodes.at (y-1)).Get (x), rowNodes.Get (x)));
67
      }
68
    }
69
70
    m_nodes.push_back (rowNodes);
71
    m_rowDevices.push_back (rowDevices);
72
73
    if (y > 0)
74
      m_colDevices.push_back (colDevices);
75
  }
76
}
77
78
PointToPointGridHelper::~PointToPointGridHelper ()
79
{}
80
81
void
82
PointToPointGridHelper::InstallStack (InternetStackHelper stack)
83
{
84
  for (uint32_t i = 0; i < m_nodes.size (); ++i)
85
    {
86
      NodeContainer rowNodes = m_nodes[i];
87
      for (uint32_t j = 0; j < rowNodes.GetN (); ++j)
88
        {
89
          stack.Install (rowNodes.Get (j));
90
        }
91
    }
92
}
93
94
void
95
PointToPointGridHelper::AssignIpv4Addresses (Ipv4AddressHelper rowIp, Ipv4AddressHelper colIp)
96
{
97
  // Assign addresses to all row devices in the grid.
98
  // These devices are stored in a vector.  Each row 
99
  // of the grid has all the row devices in one entry 
100
  // of the vector.  These entries come in pairs.
101
  for (uint32_t i = 0; i < m_rowDevices.size (); ++i)
102
    {
103
      Ipv4InterfaceContainer rowInterfaces; 
104
      NetDeviceContainer rowContainer = m_rowDevices[i];
105
      for (uint32_t j = 0; j < rowContainer.GetN (); j+=2)
106
        {
107
          rowInterfaces.Add (rowIp.Assign (rowContainer.Get (j))); 
108
          rowInterfaces.Add (rowIp.Assign (rowContainer.Get (j+1)));
109
          rowIp.NewNetwork ();
110
        }
111
      m_rowInterfaces.push_back (rowInterfaces);
112
    }
113
114
  // Assign addresses to all col devices in the grid.
115
  // These devices are stored in a vector.  Each col 
116
  // of the grid has all the col devices in one entry 
117
  // of the vector.  These entries come in pairs.
118
  for (uint32_t i = 0; i < m_colDevices.size (); ++i)
119
    {
120
      Ipv4InterfaceContainer colInterfaces; 
121
      NetDeviceContainer colContainer = m_colDevices[i];
122
      for (uint32_t j = 0; j < colContainer.GetN (); j+=2)
123
        {
124
          colInterfaces.Add (colIp.Assign (colContainer.Get (j))); 
125
          colInterfaces.Add (colIp.Assign (colContainer.Get (j+1)));
126
          colIp.NewNetwork ();
127
        }
128
      m_colInterfaces.push_back (colInterfaces);
129
    }
130
}
131
132
void
133
PointToPointGridHelper::BoundingBox (double ulx, double uly,
134
                         double lrx, double lry)
135
{
136
  double xDist; 
137
  double yDist; 
138
  if (lrx > ulx)
139
    {
140
      xDist = lrx - ulx;
141
    }
142
  else
143
    {
144
      xDist = ulx - lrx;
145
    }
146
  if (lry > uly)
147
    {
148
      yDist = lry - uly;
149
    }
150
  else
151
    {
152
      yDist = uly - lry;
153
    }
154
  double xAdder = xDist / m_xSize;
155
  double yAdder = yDist / m_ySize;
156
  double yLoc = yDist / 2;
157
  for (uint32_t i = 0; i < m_ySize; ++i)
158
  {
159
    double xLoc = xDist / 2;
160
    for (uint32_t j = 0; j < m_xSize; ++j)
161
    {
162
      Ptr<Node> node = GetNode (i, j);
163
      Ptr<ConstantPositionMobilityModel> loc = node->GetObject<ConstantPositionMobilityModel> ();
164
      if (loc ==0)
165
      {
166
        loc = CreateObject<ConstantPositionMobilityModel> ();
167
        node->AggregateObject (loc);
168
      }
169
      Vector locVec (xLoc, yLoc, 0);
170
      loc->SetPosition (locVec);
171
172
      xLoc += xAdder;
173
    }
174
    yLoc += yAdder;
175
  }
176
}
177
178
Ptr<Node> 
179
PointToPointGridHelper::GetNode (uint32_t row, uint32_t col)
180
{
181
  if (row > m_nodes.size () - 1 || 
182
      col > m_nodes.at (row).GetN () - 1) 
183
    {
184
       NS_FATAL_ERROR ("Index out of bounds in PointToPointGridHelper::GetNode.");
185
    }
186
187
  return (m_nodes.at (row)).Get (col);
188
}
189
190
Ipv4Address
191
PointToPointGridHelper::GetIpv4Address (uint32_t row, uint32_t col)
192
{
193
  if (row > m_nodes.size () - 1 || 
194
      col > m_nodes.at (row).GetN () - 1) 
195
    {
196
       NS_FATAL_ERROR ("Index out of bounds in PointToPointGridHelper::GetIpv4Address.");
197
    }
198
199
  // Right now this just gets one of the addresses of the
200
  // specified node.  The exact device can't be specified.
201
  // If you picture the grid, the address returned is the 
202
  // address of the left (row) device of all nodes, with 
203
  // the exception of the left-most nodes in the grid; 
204
  // in which case the right (row) device address is 
205
  // returned
206
  if (col == 0)
207
  {
208
    return (m_rowInterfaces.at (row)).GetAddress (0);
209
  }
210
  else
211
  {
212
    return (m_rowInterfaces.at (row)).GetAddress ((2*col)-1);
213
  }
214
}
215
216
} // namespace ns3
(-)a/src/netanim/helper/point-to-point-grid-helper.h (-125 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
 * Author: Josh Pelkey <jpelkey@gatech.edu>
17
 */
18
19
#ifndef POINT_TO_POINT_GRID_HELPER_H
20
#define POINT_TO_POINT_GRID_HELPER_H
21
22
#include <vector>
23
24
#include "internet-stack-helper.h"
25
#include "point-to-point-helper.h"
26
#include "ipv4-address-helper.h"
27
#include "ipv4-interface-container.h"
28
#include "net-device-container.h"
29
30
namespace ns3 {
31
  
32
/**
33
 * \brief A helper to make it easier to create a grid topology
34
 * with p2p links
35
 */
36
class PointToPointGridHelper 
37
{
38
public: 
39
  /**
40
   * Create a PointToPointGridHelper in order to easily create
41
   * grid topologies using p2p links
42
   *
43
   * \param nRows total number of rows in the grid
44
   *
45
   * \param nCols total number of colums in the grid
46
   *
47
   * \param pointToPoint the PointToPointHelper which is used 
48
   *                     to connect all of the nodes together 
49
   *                     in the grid
50
   */
51
  PointToPointGridHelper (uint32_t nRows, 
52
                          uint32_t nCols, 
53
                          PointToPointHelper pointToPoint);
54
55
  ~PointToPointGridHelper ();
56
57
  /**
58
   * \param row the row address of the node desired
59
   *
60
   * \param col the column address of the node desired
61
   *
62
   * \returns a pointer to the node specified by the 
63
   *          (row, col) address
64
   */
65
  Ptr<Node> GetNode (uint32_t row, uint32_t col);
66
67
  /**
68
   * This returns an Ipv4 address at the node specified by 
69
   * the (row, col) address.  Technically, a node will have 
70
   * multiple interfaces in the grid; therefore, it also has 
71
   * multiple Ipv4 addresses.  This method only returns one of 
72
   * the addresses. If you picture the grid, the address returned 
73
   * is the left row device of all the nodes, except the left-most 
74
   * grid nodes, which returns the right row device.
75
   *
76
   * \param row the row address of the node desired
77
   *
78
   * \param col the column address of the node desired
79
   *
80
   * \returns Ipv4Address of one of the interfaces of the node 
81
   *          specified by the (row, col) address
82
   */
83
  Ipv4Address GetIpv4Address (uint32_t row, uint32_t col);
84
85
  /**
86
   * \param stack an InternetStackHelper which is used to install 
87
   *              on every node in the grid
88
   */
89
  void InstallStack (InternetStackHelper stack);
90
91
  /**
92
   * Assigns Ipv4 addresses to all the row and column interfaces
93
   *
94
   * \param rowIp the Ipv4AddressHelper used to assign Ipv4 addresses 
95
   *              to all of the row interfaces in the grid
96
   *
97
   * \param colIp the Ipv4AddressHelper used to assign Ipv4 addresses 
98
   *              to all of the row interfaces in the grid
99
   */
100
  void AssignIpv4Addresses (Ipv4AddressHelper rowIp, Ipv4AddressHelper colIp);
101
102
  /**
103
   * Sets up the node canvas locations for every node in the grid.
104
   * This is needed for use with the animation interface
105
   *
106
   * \param ulx upper left x value
107
   * \param uly upper left y value
108
   * \param lrx lower right x value
109
   * \param lry lower right y value
110
   */
111
  void BoundingBox (double ulx, double uly, double lrx, double lry);
112
113
private:
114
  uint32_t m_xSize;
115
  uint32_t m_ySize;
116
  std::vector<NetDeviceContainer> m_rowDevices;
117
  std::vector<NetDeviceContainer> m_colDevices;
118
  std::vector<Ipv4InterfaceContainer> m_rowInterfaces;
119
  std::vector<Ipv4InterfaceContainer> m_colInterfaces;
120
  std::vector<NodeContainer> m_nodes;
121
};
122
123
} // namespace ns3
124
      
125
#endif /* POINT_TO_POINT_GRID_HELPER_H */
(-)a/src/netanim/helper/point-to-point-star-helper.cc (-159 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
17
#include <iostream>
18
#include <sstream>
19
20
// ns3 includes
21
#include "ns3/animation-interface.h"
22
#include "ns3/point-to-point-star-helper.h"
23
#include "ns3/constant-position-mobility-model.h"
24
25
#include "ns3/node-list.h"
26
#include "ns3/point-to-point-net-device.h"
27
#include "ns3/vector.h"
28
29
NS_LOG_COMPONENT_DEFINE("PointToPointStarHelper");
30
31
namespace ns3 {
32
  
33
PointToPointStarHelper::PointToPointStarHelper (uint32_t numSpokes,
34
                   PointToPointHelper p2pHelper)
35
{
36
  m_hub.Create (1);
37
  m_spokes.Create (numSpokes);
38
39
  for (uint32_t i = 0; i < m_spokes.GetN (); ++i)
40
    {
41
      NetDeviceContainer nd = p2pHelper.Install (m_hub.Get (0), m_spokes.Get (i));
42
      m_hubDevices.Add (nd.Get (0));
43
      m_spokeDevices.Add (nd.Get (1));
44
    }
45
}
46
47
PointToPointStarHelper::~PointToPointStarHelper ()
48
{}
49
50
Ptr<Node> 
51
PointToPointStarHelper::GetHub () const
52
{
53
  return m_hub.Get (0);
54
}
55
56
Ptr<Node> 
57
PointToPointStarHelper::GetSpokeNode (uint32_t i) const
58
{
59
  return m_spokes.Get (i);
60
}
61
62
Ipv4Address 
63
PointToPointStarHelper::GetHubIpv4Address (uint32_t i) const
64
{
65
  return m_hubInterfaces.GetAddress (i);
66
}
67
68
Ipv4Address 
69
PointToPointStarHelper::GetSpokeIpv4Address (uint32_t i) const
70
{
71
  return m_spokeInterfaces.GetAddress (i);
72
}
73
74
uint32_t  
75
PointToPointStarHelper::SpokeCount () const
76
{
77
  return m_spokes.GetN ();
78
}
79
80
void 
81
PointToPointStarHelper::InstallStack (InternetStackHelper stack)
82
{
83
  stack.Install (m_hub);
84
  stack.Install (m_spokes);
85
}
86
87
void 
88
PointToPointStarHelper::AssignIpv4Addresses (Ipv4AddressHelper address)
89
{
90
  for (uint32_t i = 0; i < m_spokes.GetN (); ++i)
91
    {
92
      m_hubInterfaces.Add (address.Assign (m_hubDevices.Get (i)));
93
      m_spokeInterfaces.Add (address.Assign (m_spokeDevices.Get (i)));
94
      address.NewNetwork ();
95
    }
96
}
97
98
void 
99
PointToPointStarHelper::BoundingBox (double ulx, double uly,
100
                                     double lrx, double lry)
101
{
102
  double xDist;
103
  double yDist;
104
  if (lrx > ulx)
105
    {
106
      xDist = lrx - ulx;
107
    }
108
  else
109
    {
110
      xDist = ulx - lrx;
111
    }
112
  if (lry > uly)
113
    {
114
      yDist = lry - uly;
115
    }
116
  else
117
    {
118
      yDist = uly - lry;
119
    }
120
121
  // Place the hub
122
  Ptr<Node> hub = m_hub.Get (0);
123
  Ptr<ConstantPositionMobilityModel> hubLoc =  hub->GetObject<ConstantPositionMobilityModel> ();
124
  if (hubLoc == 0)
125
    {
126
      hubLoc = CreateObject<ConstantPositionMobilityModel> ();
127
      hub->AggregateObject (hubLoc);
128
    }
129
  Vector hubVec (ulx + xDist/2.0, uly + yDist/2.0, 0);
130
  hubLoc->SetPosition (hubVec);
131
132
  double spokeDist;
133
  if (xDist > yDist)
134
    {
135
      spokeDist = yDist/4.0;
136
    }
137
  else
138
    {
139
      spokeDist = xDist/4.0;
140
    }
141
142
  double theta = 2*M_PI/m_spokes.GetN ();
143
  for (uint32_t i = 0; i < m_spokes.GetN (); ++i)
144
    {
145
      Ptr<Node> spokeNode = m_spokes.Get (i);
146
      Ptr<ConstantPositionMobilityModel> spokeLoc = spokeNode->GetObject<ConstantPositionMobilityModel> ();
147
      if (spokeLoc == 0)
148
        {
149
          spokeLoc = CreateObject<ConstantPositionMobilityModel> ();
150
          spokeNode->AggregateObject (spokeLoc);
151
        }
152
        Vector spokeVec (hubVec.x + cos (theta*i) * spokeDist, 
153
                         hubVec.y + sin (theta*i) * spokeDist,
154
                         0);
155
        spokeLoc->SetPosition (spokeVec);
156
    }
157
}
158
159
} // namespace ns3
(-)a/src/netanim/helper/point-to-point-star-helper.h (-122 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
17
// Define an object to create a dumbbell topology.
18
19
#ifndef POINT_TO_POINT_STAR_HELPER_H
20
#define POINT_TO_POINT_STAR_HELPER_H
21
22
#include <string>
23
24
#include "point-to-point-helper.h"
25
#include "ipv4-address-helper.h"
26
#include "internet-stack-helper.h"
27
#include "ipv4-interface-container.h"
28
29
namespace ns3 {
30
  
31
/**
32
 * \brief A helper to make it easier to create a star topology
33
 * with PointToPoint links
34
 */
35
class PointToPointStarHelper
36
{
37
public:
38
  /**
39
   * Create a PointToPointStarHelper in order to easily create
40
   * star topologies using p2p links
41
   *
42
   * \param numSpokes the number of links attached to 
43
   *        the hub node, creating a total of 
44
   *        numSpokes + 1 nodes
45
   *
46
   * \param p2pHelper the link helper for p2p links, 
47
   *        used to link nodes together
48
   */
49
  PointToPointStarHelper (uint32_t numSpokes, 
50
                          PointToPointHelper p2pHelper);
51
52
  ~PointToPointStarHelper ();
53
54
public:
55
  /**
56
   * \returns a node pointer to the hub node in the
57
   *          star, i.e., the center node
58
   */
59
  Ptr<Node> GetHub () const;
60
61
  /**
62
   * \param i an index into the spokes of the star
63
   *
64
   * \returns a node pointer to the node at the indexed spoke
65
   */
66
  Ptr<Node> GetSpokeNode (uint32_t i) const;
67
68
  /**
69
   * \param i index into the hub interfaces
70
   *
71
   * \returns Ipv4Address according to indexed hub interface
72
   */
73
  Ipv4Address GetHubIpv4Address (uint32_t i) const;
74
75
  /**
76
   * \param i index into the spoke interfaces
77
   *
78
   * \returns Ipv4Address according to indexed spoke interface
79
   */
80
  Ipv4Address GetSpokeIpv4Address (uint32_t i) const;
81
82
  /**
83
   * \returns the total number of spokes in the star
84
   */
85
  uint32_t SpokeCount () const;
86
87
  /**
88
   * \param stack an InternetStackHelper which is used to install 
89
   *              on every node in the star
90
   */
91
  void InstallStack (InternetStackHelper stack);
92
93
  /**
94
   * \param address an Ipv4AddressHelper which is used to install 
95
   *                Ipv4 addresses on all the node interfaces in 
96
   *                the star
97
   */
98
  void AssignIpv4Addresses (Ipv4AddressHelper address);
99
100
  /**
101
   * Sets up the node canvas locations for every node in the star. 
102
   * This is needed for use with the animation interface
103
   *
104
   * \param ulx upper left x value
105
   * \param uly upper left y value
106
   * \param lrx lower right x value
107
   * \param lry lower right y value
108
   */
109
  void BoundingBox (double ulx, double uly, double lrx, double lry);
110
111
private:
112
  NodeContainer m_hub;
113
  NetDeviceContainer m_hubDevices;
114
  NodeContainer m_spokes;
115
  NetDeviceContainer m_spokeDevices;
116
  Ipv4InterfaceContainer m_hubInterfaces;
117
  Ipv4InterfaceContainer m_spokeInterfaces;
118
};
119
120
} // namespace ns3
121
122
#endif /* POINT_TO_POINT_STAR_HELPER_H */
(-)a/src/netanim/model/animation-interface.cc (-2 lines)
 Lines 21-28    Link Here 
21
#include <stdio.h>
21
#include <stdio.h>
22
#include <sstream>
22
#include <sstream>
23
23
24
#include "ns3/netanim-config.h"
25
26
// Socket related includes
24
// Socket related includes
27
#if defined(HAVE_SYS_SOCKET_H) && defined(HAVE_NETINET_IN_H)
25
#if defined(HAVE_SYS_SOCKET_H) && defined(HAVE_NETINET_IN_H)
28
#include <sys/socket.h>
26
#include <sys/socket.h>
(-)a/src/netanim/wscript (-8 / +1 lines)
 Lines 1-22    Link Here 
1
## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
1
## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
2
2
3
def build(bld):
3
def build(bld):
4
    module = bld.create_ns3_module('netanim', ['internet', 'point-to-point', 'mobility'])
4
    module = bld.create_ns3_module('netanim', ['internet', 'mobility'])
5
    module.includes = '.'
5
    module.includes = '.'
6
    module.source = [
6
    module.source = [
7
        'model/animation-interface.cc',
7
        'model/animation-interface.cc',
8
        'helper/point-to-point-dumbbell-helper.cc',
9
        'helper/point-to-point-grid-helper.cc',
10
        'helper/point-to-point-star-helper.cc',
11
        ]
8
        ]
12
9
13
    headers = bld.new_task_gen('ns3header')
10
    headers = bld.new_task_gen('ns3header')
14
    headers.module = 'netanim'
11
    headers.module = 'netanim'
15
    headers.source = [
12
    headers.source = [
16
        'model/animation-interface.h',
13
        'model/animation-interface.h',
17
        'helper/point-to-point-dumbbell-helper.h',
18
        'helper/point-to-point-grid-helper.h',
19
        'helper/point-to-point-star-helper.h',
20
        ]
14
        ]
21
15
22
    if (bld.env['ENABLE_EXAMPLES']):
16
    if (bld.env['ENABLE_EXAMPLES']):
 Lines 28-32    Link Here 
28
def configure(conf):
22
def configure(conf):
29
    conf.check(header_name='sys/socket.h', define_name='HAVE_SYS_SOCKET_H')
23
    conf.check(header_name='sys/socket.h', define_name='HAVE_SYS_SOCKET_H')
30
    conf.check(header_name='netinet/in.h', define_name='HAVE_NETINET_IN_H')
24
    conf.check(header_name='netinet/in.h', define_name='HAVE_NETINET_IN_H')
31
    conf.write_config_header('ns3/netanim-config.h', top=True)
32
25
(-)a/src/olsr/examples/olsr-hna.cc (-3 / +1 lines)
 Lines 56-66    Link Here 
56
#include "ns3/config-store-module.h"
56
#include "ns3/config-store-module.h"
57
#include "ns3/wifi-module.h"
57
#include "ns3/wifi-module.h"
58
#include "ns3/csma-module.h"
58
#include "ns3/csma-module.h"
59
#include "ns3/ipv4-list-routing.h"
59
#include "ns3/internet-module.h"
60
#include "ns3/olsr-routing-protocol.h"
60
#include "ns3/olsr-routing-protocol.h"
61
#include "ns3/olsr-helper.h"
61
#include "ns3/olsr-helper.h"
62
#include "ns3/ipv4-static-routing-helper.h"
63
#include "ns3/ipv4-list-routing-helper.h"
64
62
65
#include <iostream>
63
#include <iostream>
66
#include <fstream>
64
#include <fstream>
(-)e9ca5b2838e7 (+267 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
 * Author: George F. Riley<riley@ece.gatech.edu>
17
 */
18
19
// Implement an object to create a dumbbell topology.
20
21
#include <iostream>
22
#include <sstream>
23
24
// ns3 includes
25
#include "ns3/animation-interface.h"
26
#include "ns3/point-to-point-dumbbell.h"
27
#include "ns3/constant-position-mobility-model.h"
28
29
#include "ns3/node-list.h"
30
#include "ns3/point-to-point-net-device.h"
31
#include "ns3/vector.h"
32
33
NS_LOG_COMPONENT_DEFINE("PointToPointDumbbellHelper");
34
35
namespace ns3 {
36
  
37
PointToPointDumbbellHelper::PointToPointDumbbellHelper (uint32_t nLeftLeaf,
38
                   PointToPointHelper leftHelper,
39
                   uint32_t nRightLeaf,
40
                   PointToPointHelper rightHelper,
41
                   PointToPointHelper bottleneckHelper)
42
{
43
  // Create the bottleneck routers
44
  m_routers.Create (2);
45
  // Create the leaf nodes
46
  m_leftLeaf.Create (nLeftLeaf);
47
  m_rightLeaf.Create (nRightLeaf);
48
49
  // Add the link connecting routers
50
  m_routerDevices = bottleneckHelper.Install (m_routers);
51
  // Add the left side links
52
  for (uint32_t i = 0; i < nLeftLeaf; ++i)
53
    {
54
      NetDeviceContainer c = leftHelper.Install (m_routers.Get (0),
55
                                                m_leftLeaf.Get (i));
56
      m_leftRouterDevices.Add (c.Get (0));
57
      m_leftLeafDevices.Add (c.Get(1));
58
    }
59
  // Add the right side links
60
  for (uint32_t i = 0; i < nRightLeaf; ++i)
61
    {
62
      NetDeviceContainer c = rightHelper.Install (m_routers.Get (1),
63
                                                m_rightLeaf.Get (i));
64
      m_rightRouterDevices.Add (c.Get (0));
65
      m_rightLeafDevices.Add (c.Get (1));
66
    }
67
}
68
69
PointToPointDumbbellHelper::~PointToPointDumbbellHelper ()
70
{}
71
72
Ptr<Node> PointToPointDumbbellHelper::GetLeft () const
73
{ // Get the left side bottleneck router
74
  return m_routers.Get (0);
75
}
76
77
Ptr<Node> PointToPointDumbbellHelper::GetLeft (uint32_t i) const
78
{ // Get the i'th left side leaf
79
  return m_leftLeaf.Get (i);
80
}
81
82
Ptr<Node> PointToPointDumbbellHelper::GetRight () const
83
{ // Get the right side bottleneck router
84
  return m_routers.Get (1);
85
}
86
87
Ptr<Node> PointToPointDumbbellHelper::GetRight (uint32_t i) const
88
{ // Get the i'th right side leaf
89
  return m_rightLeaf.Get (i);
90
}
91
92
Ipv4Address PointToPointDumbbellHelper::GetLeftIpv4Address (uint32_t i) const
93
{
94
  return m_leftLeafInterfaces.GetAddress (i);
95
}
96
97
Ipv4Address PointToPointDumbbellHelper::GetRightIpv4Address (uint32_t i) const
98
{
99
  return m_rightLeafInterfaces.GetAddress (i);
100
}
101
102
uint32_t  PointToPointDumbbellHelper::LeftCount () const
103
{ // Number of left side nodes
104
  return m_leftLeaf.GetN ();
105
}
106
107
uint32_t  PointToPointDumbbellHelper::RightCount () const
108
{ // Number of right side nodes
109
  return m_rightLeaf.GetN ();
110
}
111
112
void PointToPointDumbbellHelper::InstallStack (InternetStackHelper stack)
113
{
114
  stack.Install (m_routers);
115
  stack.Install (m_leftLeaf);
116
  stack.Install (m_rightLeaf);
117
}
118
119
void PointToPointDumbbellHelper::AssignIpv4Addresses (Ipv4AddressHelper leftIp,
120
                               Ipv4AddressHelper rightIp,
121
                               Ipv4AddressHelper routerIp)
122
{
123
  // Assign the router network
124
  m_routerInterfaces = routerIp.Assign (m_routerDevices);
125
  // Assign to left side 
126
  for (uint32_t i = 0; i < LeftCount (); ++i)
127
    {
128
      NetDeviceContainer ndc;
129
      ndc.Add (m_leftLeafDevices.Get (i));
130
      ndc.Add (m_leftRouterDevices.Get (i));
131
      Ipv4InterfaceContainer ifc = leftIp.Assign(ndc);
132
      m_leftLeafInterfaces.Add (ifc.Get (0));
133
      m_leftRouterInterfaces.Add (ifc.Get (1));
134
      leftIp.NewNetwork ();
135
    }
136
  // Assign to right side
137
  for (uint32_t i = 0; i < RightCount (); ++i)
138
    {
139
      NetDeviceContainer ndc;
140
      ndc.Add (m_rightLeafDevices.Get (i));
141
      ndc.Add (m_rightRouterDevices.Get (i));
142
      Ipv4InterfaceContainer ifc = rightIp.Assign (ndc);
143
      m_rightLeafInterfaces.Add (ifc.Get (0));
144
      m_rightRouterInterfaces.Add (ifc.Get (1));
145
      rightIp.NewNetwork ();
146
    }
147
}
148
149
150
void PointToPointDumbbellHelper::BoundingBox (double ulx, double uly, // Upper left x/y
151
                           double lrx, double lry) // Lower right y
152
{
153
  double xDist;
154
  double yDist;
155
  if (lrx > ulx)
156
    {
157
      xDist = lrx - ulx;
158
    }
159
  else
160
    {
161
      xDist = ulx - lrx;
162
    }
163
  if (lry > uly)
164
    {
165
      yDist = lry - uly;
166
    }
167
  else
168
    {
169
      yDist = uly - lry;
170
    }
171
172
  double xAdder = xDist / 3.0;
173
  double  thetaL = M_PI / (LeftCount () + 1.0);
174
  double  thetaR = M_PI / (RightCount () + 1.0);
175
176
  // Place the left router
177
  Ptr<Node> lr = GetLeft ();
178
  Ptr<ConstantPositionMobilityModel> loc = lr->GetObject<ConstantPositionMobilityModel> ();
179
  if (loc == 0)
180
    {
181
      loc = CreateObject<ConstantPositionMobilityModel> ();
182
      lr->AggregateObject (loc);
183
    }
184
  Vector lrl (ulx + xAdder, uly + yDist/2.0, 0);
185
  loc->SetPosition (lrl);
186
  
187
  // Place the right router
188
  Ptr<Node> rr = GetRight ();
189
  loc = rr->GetObject<ConstantPositionMobilityModel> ();
190
  if (loc == 0)
191
    {
192
      loc = CreateObject<ConstantPositionMobilityModel> ();
193
      rr->AggregateObject (loc);
194
    }
195
  Vector rrl (ulx + xAdder * 2, uly + yDist/2.0, 0); // Right router location
196
  loc->SetPosition (rrl);
197
198
  // Place the left leaf nodes
199
  double theta = -M_PI_2 + thetaL;
200
  for (uint32_t l = 0; l < LeftCount (); ++l)
201
    {
202
      // Make them in a circular pattern to make all line lengths the same
203
      // Special case when theta = 0, to be sure we get a straight line
204
      if ((LeftCount () % 2) == 1)
205
        { // Count is odd, see if we are in middle
206
          if (l == (LeftCount () / 2))
207
            {
208
              theta = 0.0;
209
            }
210
        }
211
      Ptr<Node> ln = GetLeft (l);
212
      loc = ln->GetObject<ConstantPositionMobilityModel> ();
213
      if (loc == 0)
214
        {
215
          loc = CreateObject<ConstantPositionMobilityModel> ();
216
          ln->AggregateObject (loc);
217
        }
218
      Vector lnl (lrl.x - cos (theta) * xAdder,
219
                   lrl.y + sin (theta) * xAdder, 0);  // Left Node Location
220
      // Insure did not exceed bounding box
221
      if (lnl.y < uly) 
222
        {
223
          lnl.y = uly; // Set to upper right y
224
        }
225
      if (lnl.y > lry) 
226
        {
227
          lnl.y = lry; // Set to lower right y
228
        }
229
      loc->SetPosition (lnl);
230
      theta += thetaL;
231
    }
232
  // Place the right nodes
233
  theta = -M_PI_2 + thetaR;
234
  for (uint32_t r = 0; r < RightCount (); ++r)
235
    {
236
      // Special case when theta = 0, to be sure we get a straight line
237
      if ((RightCount () % 2) == 1)
238
        { // Count is odd, see if we are in middle
239
          if (r == (RightCount () / 2))
240
            {
241
              theta = 0.0;
242
            }
243
        }
244
      Ptr<Node> rn = GetRight (r);
245
      loc = rn->GetObject<ConstantPositionMobilityModel> ();
246
      if (loc == 0)
247
        {
248
          loc = CreateObject<ConstantPositionMobilityModel> ();
249
          rn->AggregateObject (loc);
250
        }
251
      Vector rnl (rrl.x + cos (theta) * xAdder, // Right node location
252
                   rrl.y + sin (theta) * xAdder, 0);
253
      // Insure did not exceed bounding box
254
      if (rnl.y < uly) 
255
        {
256
          rnl.y = uly; // Set to upper right y
257
        }
258
      if (rnl.y > lry) 
259
        {
260
          rnl.y = lry; // Set to lower right y
261
        }
262
      loc->SetPosition (rnl);
263
      theta += thetaR;
264
    }
265
}
266
  
267
} // namespace ns3
(-)e9ca5b2838e7 (+160 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
 * Author: George F. Riley<riley@ece.gatech.edu>
17
 */
18
19
// Define an object to create a dumbbell topology.
20
21
#ifndef POINT_TO_POINT_DUMBBELL_HELPER_H
22
#define POINT_TO_POINT_DUMBBELL_HELPER_H
23
24
#include <string>
25
26
#include "point-to-point-helper.h"
27
#include "ipv4-address-helper.h"
28
#include "internet-stack-helper.h"
29
#include "ipv4-interface-container.h"
30
31
namespace ns3 {
32
  
33
/**
34
 * \brief A helper to make it easier to create a dumbbell topology
35
 * with p2p links
36
 */
37
class PointToPointDumbbellHelper
38
{
39
public:
40
  /**
41
   * Create a PointToPointDumbbellHelper in order to easily create
42
   * dumbbell topologies using p2p links
43
   *
44
   * \param nLeftLeaf number of left side leaf nodes in the dumbbell
45
   *
46
   * \param leftHelper PointToPointHelper used to install the links 
47
   *                   between the left leaf nodes and the left-most 
48
   *                   router
49
   *
50
   * \param nRightLeaf number of right side leaf nodes in the dumbbell
51
   *
52
   * \param rightHelper PointToPointHelper used to install the links 
53
   *                    between the right leaf nodes and the right-most 
54
   *                    router
55
   *
56
   * \param bottleneckHelper PointToPointHelper used to install the link 
57
   *                         between the inner-routers, usually known as 
58
   *                         the bottleneck link
59
   */
60
  PointToPointDumbbellHelper (uint32_t nLeftLeaf,
61
                              PointToPointHelper leftHelper,
62
                              uint32_t nRightLeaf,
63
                              PointToPointHelper rightHelper,
64
                              PointToPointHelper bottleneckHelper);
65
66
  ~PointToPointDumbbellHelper ();
67
68
public:
69
  /**
70
   * \returns pointer to the node of the left side bottleneck
71
   *          router
72
   */
73
  Ptr<Node> GetLeft () const;
74
  
75
  /**
76
   * \returns pointer to the i'th left side leaf node
77
   */
78
  Ptr<Node> GetLeft (uint32_t i) const;
79
80
  /**
81
   * \returns pointer to the node of the right side bottleneck
82
   *          router
83
   */
84
  Ptr<Node> GetRight () const;
85
86
  /**
87
   * \returns pointer to the i'th left side leaf node
88
   */
89
  Ptr<Node> GetRight (uint32_t i) const;
90
91
  /**
92
   * \returns an Ipv4Address of the i'th left leaf
93
   */
94
  Ipv4Address GetLeftIpv4Address (uint32_t i ) const; // Get left leaf address
95
96
  /**
97
   * \returns an Ipv4Address of the i'th right leaf
98
   */
99
  Ipv4Address GetRightIpv4Address (uint32_t i) const; // Get right leaf address
100
101
  /**
102
   * \returns total number of left side leaf nodes
103
   */
104
  uint32_t  LeftCount () const;
105
106
  /**
107
   * \returns total number of right side leaf nodes
108
   */
109
  uint32_t  RightCount () const;
110
111
  /**
112
   * \param stack an InternetStackHelper which is used to install 
113
   *              on every node in the dumbbell
114
   */
115
  void      InstallStack (InternetStackHelper stack);
116
117
  /**
118
   * \param leftIp Ipv4AddressHelper to assign Ipv4 addresses to the
119
   *               interfaces on the left side of the dumbbell
120
   *
121
   * \param rightIp Ipv4AddressHelper to assign Ipv4 addresses to the
122
   *                interfaces on the right side of the dumbbell
123
   *
124
   * \param routerIp Ipv4AddressHelper to assign Ipv4 addresses to the 
125
   *                 interfaces on the bottleneck link
126
   */
127
  void      AssignIpv4Addresses (Ipv4AddressHelper leftIp,
128
                                 Ipv4AddressHelper rightIp,
129
                                 Ipv4AddressHelper routerIp);
130
131
  /**
132
   * Sets up the node canvas locations for every node in the dumbbell.
133
   * This is needed for use with the animation interface
134
   *
135
   * \param ulx upper left x value
136
   * \param uly upper left y value
137
   * \param lrx lower right x value
138
   * \param lry lower right y value
139
   */
140
  void      BoundingBox (double ulx, double uly, double lrx, double lry);
141
  
142
private:
143
  NodeContainer          m_leftLeaf;
144
  NetDeviceContainer     m_leftLeafDevices;
145
  NodeContainer          m_rightLeaf;
146
  NetDeviceContainer     m_rightLeafDevices;
147
  NodeContainer          m_routers;
148
  NetDeviceContainer     m_routerDevices; // just two connecting the routers
149
  NetDeviceContainer     m_leftRouterDevices;
150
  NetDeviceContainer     m_rightRouterDevices;
151
  Ipv4InterfaceContainer m_leftLeafInterfaces;
152
  Ipv4InterfaceContainer m_leftRouterInterfaces;
153
  Ipv4InterfaceContainer m_rightLeafInterfaces;
154
  Ipv4InterfaceContainer m_rightRouterInterfaces;
155
  Ipv4InterfaceContainer m_routerInterfaces;
156
};
157
158
} // namespace ns3
159
160
#endif /* POINT_TO_POINT_DUMBBELL_HELPER_H */
(-)e9ca5b2838e7 (+216 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
 * Author: Josh Pelkey <jpelkey@gatech.edu>
17
 */
18
19
#include "ns3/point-to-point-grid.h"
20
#include "ns3/animation-interface.h"
21
#include "ns3/internet-stack-helper.h"
22
#include "ns3/point-to-point-helper.h"
23
#include "ns3/constant-position-mobility-model.h"
24
#include "ns3/string.h"
25
#include "ns3/vector.h"
26
#include "ns3/log.h"
27
28
NS_LOG_COMPONENT_DEFINE("PointToPointGridHelper");
29
30
namespace ns3 {
31
  
32
PointToPointGridHelper::PointToPointGridHelper (uint32_t nRows, 
33
                                                uint32_t nCols, 
34
                                                PointToPointHelper pointToPoint)
35
  : m_xSize (nCols), m_ySize (nRows)
36
{
37
  // Bounds check
38
  if (m_xSize < 1 || m_ySize < 1 || (m_xSize < 2 && m_ySize < 2))
39
    {
40
      NS_FATAL_ERROR ("Need more nodes for grid.");
41
    }
42
43
  InternetStackHelper stack;
44
45
  for (uint32_t y = 0; y < nRows; ++y)
46
  {
47
    NodeContainer rowNodes;
48
    NetDeviceContainer rowDevices;
49
    NetDeviceContainer colDevices;
50
51
    for (uint32_t x = 0; x < nCols; ++x)
52
    {
53
      rowNodes.Create (1);
54
55
      // install p2p links across the row
56
      if (x > 0)
57
      {
58
        rowDevices.Add (pointToPoint.
59
            Install (rowNodes.Get (x-1), rowNodes.Get (x)));
60
      }
61
62
      // install vertical p2p links
63
      if (y > 0)
64
      {
65
        colDevices.Add(pointToPoint.
66
                      Install ((m_nodes.at (y-1)).Get (x), rowNodes.Get (x)));
67
      }
68
    }
69
70
    m_nodes.push_back (rowNodes);
71
    m_rowDevices.push_back (rowDevices);
72
73
    if (y > 0)
74
      m_colDevices.push_back (colDevices);
75
  }
76
}
77
78
PointToPointGridHelper::~PointToPointGridHelper ()
79
{}
80
81
void
82
PointToPointGridHelper::InstallStack (InternetStackHelper stack)
83
{
84
  for (uint32_t i = 0; i < m_nodes.size (); ++i)
85
    {
86
      NodeContainer rowNodes = m_nodes[i];
87
      for (uint32_t j = 0; j < rowNodes.GetN (); ++j)
88
        {
89
          stack.Install (rowNodes.Get (j));
90
        }
91
    }
92
}
93
94
void
95
PointToPointGridHelper::AssignIpv4Addresses (Ipv4AddressHelper rowIp, Ipv4AddressHelper colIp)
96
{
97
  // Assign addresses to all row devices in the grid.
98
  // These devices are stored in a vector.  Each row 
99
  // of the grid has all the row devices in one entry 
100
  // of the vector.  These entries come in pairs.
101
  for (uint32_t i = 0; i < m_rowDevices.size (); ++i)
102
    {
103
      Ipv4InterfaceContainer rowInterfaces; 
104
      NetDeviceContainer rowContainer = m_rowDevices[i];
105
      for (uint32_t j = 0; j < rowContainer.GetN (); j+=2)
106
        {
107
          rowInterfaces.Add (rowIp.Assign (rowContainer.Get (j))); 
108
          rowInterfaces.Add (rowIp.Assign (rowContainer.Get (j+1)));
109
          rowIp.NewNetwork ();
110
        }
111
      m_rowInterfaces.push_back (rowInterfaces);
112
    }
113
114
  // Assign addresses to all col devices in the grid.
115
  // These devices are stored in a vector.  Each col 
116
  // of the grid has all the col devices in one entry 
117
  // of the vector.  These entries come in pairs.
118
  for (uint32_t i = 0; i < m_colDevices.size (); ++i)
119
    {
120
      Ipv4InterfaceContainer colInterfaces; 
121
      NetDeviceContainer colContainer = m_colDevices[i];
122
      for (uint32_t j = 0; j < colContainer.GetN (); j+=2)
123
        {
124
          colInterfaces.Add (colIp.Assign (colContainer.Get (j))); 
125
          colInterfaces.Add (colIp.Assign (colContainer.Get (j+1)));
126
          colIp.NewNetwork ();
127
        }
128
      m_colInterfaces.push_back (colInterfaces);
129
    }
130
}
131
132
void
133
PointToPointGridHelper::BoundingBox (double ulx, double uly,
134
                         double lrx, double lry)
135
{
136
  double xDist; 
137
  double yDist; 
138
  if (lrx > ulx)
139
    {
140
      xDist = lrx - ulx;
141
    }
142
  else
143
    {
144
      xDist = ulx - lrx;
145
    }
146
  if (lry > uly)
147
    {
148
      yDist = lry - uly;
149
    }
150
  else
151
    {
152
      yDist = uly - lry;
153
    }
154
  double xAdder = xDist / m_xSize;
155
  double yAdder = yDist / m_ySize;
156
  double yLoc = yDist / 2;
157
  for (uint32_t i = 0; i < m_ySize; ++i)
158
  {
159
    double xLoc = xDist / 2;
160
    for (uint32_t j = 0; j < m_xSize; ++j)
161
    {
162
      Ptr<Node> node = GetNode (i, j);
163
      Ptr<ConstantPositionMobilityModel> loc = node->GetObject<ConstantPositionMobilityModel> ();
164
      if (loc ==0)
165
      {
166
        loc = CreateObject<ConstantPositionMobilityModel> ();
167
        node->AggregateObject (loc);
168
      }
169
      Vector locVec (xLoc, yLoc, 0);
170
      loc->SetPosition (locVec);
171
172
      xLoc += xAdder;
173
    }
174
    yLoc += yAdder;
175
  }
176
}
177
178
Ptr<Node> 
179
PointToPointGridHelper::GetNode (uint32_t row, uint32_t col)
180
{
181
  if (row > m_nodes.size () - 1 || 
182
      col > m_nodes.at (row).GetN () - 1) 
183
    {
184
       NS_FATAL_ERROR ("Index out of bounds in PointToPointGridHelper::GetNode.");
185
    }
186
187
  return (m_nodes.at (row)).Get (col);
188
}
189
190
Ipv4Address
191
PointToPointGridHelper::GetIpv4Address (uint32_t row, uint32_t col)
192
{
193
  if (row > m_nodes.size () - 1 || 
194
      col > m_nodes.at (row).GetN () - 1) 
195
    {
196
       NS_FATAL_ERROR ("Index out of bounds in PointToPointGridHelper::GetIpv4Address.");
197
    }
198
199
  // Right now this just gets one of the addresses of the
200
  // specified node.  The exact device can't be specified.
201
  // If you picture the grid, the address returned is the 
202
  // address of the left (row) device of all nodes, with 
203
  // the exception of the left-most nodes in the grid; 
204
  // in which case the right (row) device address is 
205
  // returned
206
  if (col == 0)
207
  {
208
    return (m_rowInterfaces.at (row)).GetAddress (0);
209
  }
210
  else
211
  {
212
    return (m_rowInterfaces.at (row)).GetAddress ((2*col)-1);
213
  }
214
}
215
216
} // namespace ns3
(-)e9ca5b2838e7 (+125 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
 * Author: Josh Pelkey <jpelkey@gatech.edu>
17
 */
18
19
#ifndef POINT_TO_POINT_GRID_HELPER_H
20
#define POINT_TO_POINT_GRID_HELPER_H
21
22
#include <vector>
23
24
#include "internet-stack-helper.h"
25
#include "point-to-point-helper.h"
26
#include "ipv4-address-helper.h"
27
#include "ipv4-interface-container.h"
28
#include "net-device-container.h"
29
30
namespace ns3 {
31
  
32
/**
33
 * \brief A helper to make it easier to create a grid topology
34
 * with p2p links
35
 */
36
class PointToPointGridHelper 
37
{
38
public: 
39
  /**
40
   * Create a PointToPointGridHelper in order to easily create
41
   * grid topologies using p2p links
42
   *
43
   * \param nRows total number of rows in the grid
44
   *
45
   * \param nCols total number of colums in the grid
46
   *
47
   * \param pointToPoint the PointToPointHelper which is used 
48
   *                     to connect all of the nodes together 
49
   *                     in the grid
50
   */
51
  PointToPointGridHelper (uint32_t nRows, 
52
                          uint32_t nCols, 
53
                          PointToPointHelper pointToPoint);
54
55
  ~PointToPointGridHelper ();
56
57
  /**
58
   * \param row the row address of the node desired
59
   *
60
   * \param col the column address of the node desired
61
   *
62
   * \returns a pointer to the node specified by the 
63
   *          (row, col) address
64
   */
65
  Ptr<Node> GetNode (uint32_t row, uint32_t col);
66
67
  /**
68
   * This returns an Ipv4 address at the node specified by 
69
   * the (row, col) address.  Technically, a node will have 
70
   * multiple interfaces in the grid; therefore, it also has 
71
   * multiple Ipv4 addresses.  This method only returns one of 
72
   * the addresses. If you picture the grid, the address returned 
73
   * is the left row device of all the nodes, except the left-most 
74
   * grid nodes, which returns the right row device.
75
   *
76
   * \param row the row address of the node desired
77
   *
78
   * \param col the column address of the node desired
79
   *
80
   * \returns Ipv4Address of one of the interfaces of the node 
81
   *          specified by the (row, col) address
82
   */
83
  Ipv4Address GetIpv4Address (uint32_t row, uint32_t col);
84
85
  /**
86
   * \param stack an InternetStackHelper which is used to install 
87
   *              on every node in the grid
88
   */
89
  void InstallStack (InternetStackHelper stack);
90
91
  /**
92
   * Assigns Ipv4 addresses to all the row and column interfaces
93
   *
94
   * \param rowIp the Ipv4AddressHelper used to assign Ipv4 addresses 
95
   *              to all of the row interfaces in the grid
96
   *
97
   * \param colIp the Ipv4AddressHelper used to assign Ipv4 addresses 
98
   *              to all of the row interfaces in the grid
99
   */
100
  void AssignIpv4Addresses (Ipv4AddressHelper rowIp, Ipv4AddressHelper colIp);
101
102
  /**
103
   * Sets up the node canvas locations for every node in the grid.
104
   * This is needed for use with the animation interface
105
   *
106
   * \param ulx upper left x value
107
   * \param uly upper left y value
108
   * \param lrx lower right x value
109
   * \param lry lower right y value
110
   */
111
  void BoundingBox (double ulx, double uly, double lrx, double lry);
112
113
private:
114
  uint32_t m_xSize;
115
  uint32_t m_ySize;
116
  std::vector<NetDeviceContainer> m_rowDevices;
117
  std::vector<NetDeviceContainer> m_colDevices;
118
  std::vector<Ipv4InterfaceContainer> m_rowInterfaces;
119
  std::vector<Ipv4InterfaceContainer> m_colInterfaces;
120
  std::vector<NodeContainer> m_nodes;
121
};
122
123
} // namespace ns3
124
      
125
#endif /* POINT_TO_POINT_GRID_HELPER_H */
(-)e9ca5b2838e7 (+159 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
17
#include <iostream>
18
#include <sstream>
19
20
// ns3 includes
21
#include "ns3/animation-interface.h"
22
#include "ns3/point-to-point-star.h"
23
#include "ns3/constant-position-mobility-model.h"
24
25
#include "ns3/node-list.h"
26
#include "ns3/point-to-point-net-device.h"
27
#include "ns3/vector.h"
28
29
NS_LOG_COMPONENT_DEFINE("PointToPointStarHelper");
30
31
namespace ns3 {
32
  
33
PointToPointStarHelper::PointToPointStarHelper (uint32_t numSpokes,
34
                   PointToPointHelper p2pHelper)
35
{
36
  m_hub.Create (1);
37
  m_spokes.Create (numSpokes);
38
39
  for (uint32_t i = 0; i < m_spokes.GetN (); ++i)
40
    {
41
      NetDeviceContainer nd = p2pHelper.Install (m_hub.Get (0), m_spokes.Get (i));
42
      m_hubDevices.Add (nd.Get (0));
43
      m_spokeDevices.Add (nd.Get (1));
44
    }
45
}
46
47
PointToPointStarHelper::~PointToPointStarHelper ()
48
{}
49
50
Ptr<Node> 
51
PointToPointStarHelper::GetHub () const
52
{
53
  return m_hub.Get (0);
54
}
55
56
Ptr<Node> 
57
PointToPointStarHelper::GetSpokeNode (uint32_t i) const
58
{
59
  return m_spokes.Get (i);
60
}
61
62
Ipv4Address 
63
PointToPointStarHelper::GetHubIpv4Address (uint32_t i) const
64
{
65
  return m_hubInterfaces.GetAddress (i);
66
}
67
68
Ipv4Address 
69
PointToPointStarHelper::GetSpokeIpv4Address (uint32_t i) const
70
{
71
  return m_spokeInterfaces.GetAddress (i);
72
}
73
74
uint32_t  
75
PointToPointStarHelper::SpokeCount () const
76
{
77
  return m_spokes.GetN ();
78
}
79
80
void 
81
PointToPointStarHelper::InstallStack (InternetStackHelper stack)
82
{
83
  stack.Install (m_hub);
84
  stack.Install (m_spokes);
85
}
86
87
void 
88
PointToPointStarHelper::AssignIpv4Addresses (Ipv4AddressHelper address)
89
{
90
  for (uint32_t i = 0; i < m_spokes.GetN (); ++i)
91
    {
92
      m_hubInterfaces.Add (address.Assign (m_hubDevices.Get (i)));
93
      m_spokeInterfaces.Add (address.Assign (m_spokeDevices.Get (i)));
94
      address.NewNetwork ();
95
    }
96
}
97
98
void 
99
PointToPointStarHelper::BoundingBox (double ulx, double uly,
100
                                     double lrx, double lry)
101
{
102
  double xDist;
103
  double yDist;
104
  if (lrx > ulx)
105
    {
106
      xDist = lrx - ulx;
107
    }
108
  else
109
    {
110
      xDist = ulx - lrx;
111
    }
112
  if (lry > uly)
113
    {
114
      yDist = lry - uly;
115
    }
116
  else
117
    {
118
      yDist = uly - lry;
119
    }
120
121
  // Place the hub
122
  Ptr<Node> hub = m_hub.Get (0);
123
  Ptr<ConstantPositionMobilityModel> hubLoc =  hub->GetObject<ConstantPositionMobilityModel> ();
124
  if (hubLoc == 0)
125
    {
126
      hubLoc = CreateObject<ConstantPositionMobilityModel> ();
127
      hub->AggregateObject (hubLoc);
128
    }
129
  Vector hubVec (ulx + xDist/2.0, uly + yDist/2.0, 0);
130
  hubLoc->SetPosition (hubVec);
131
132
  double spokeDist;
133
  if (xDist > yDist)
134
    {
135
      spokeDist = yDist/4.0;
136
    }
137
  else
138
    {
139
      spokeDist = xDist/4.0;
140
    }
141
142
  double theta = 2*M_PI/m_spokes.GetN ();
143
  for (uint32_t i = 0; i < m_spokes.GetN (); ++i)
144
    {
145
      Ptr<Node> spokeNode = m_spokes.Get (i);
146
      Ptr<ConstantPositionMobilityModel> spokeLoc = spokeNode->GetObject<ConstantPositionMobilityModel> ();
147
      if (spokeLoc == 0)
148
        {
149
          spokeLoc = CreateObject<ConstantPositionMobilityModel> ();
150
          spokeNode->AggregateObject (spokeLoc);
151
        }
152
        Vector spokeVec (hubVec.x + cos (theta*i) * spokeDist, 
153
                         hubVec.y + sin (theta*i) * spokeDist,
154
                         0);
155
        spokeLoc->SetPosition (spokeVec);
156
    }
157
}
158
159
} // namespace ns3
(-)e9ca5b2838e7 (+122 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
17
// Define an object to create a dumbbell topology.
18
19
#ifndef POINT_TO_POINT_STAR_HELPER_H
20
#define POINT_TO_POINT_STAR_HELPER_H
21
22
#include <string>
23
24
#include "point-to-point-helper.h"
25
#include "ipv4-address-helper.h"
26
#include "internet-stack-helper.h"
27
#include "ipv4-interface-container.h"
28
29
namespace ns3 {
30
  
31
/**
32
 * \brief A helper to make it easier to create a star topology
33
 * with PointToPoint links
34
 */
35
class PointToPointStarHelper
36
{
37
public:
38
  /**
39
   * Create a PointToPointStarHelper in order to easily create
40
   * star topologies using p2p links
41
   *
42
   * \param numSpokes the number of links attached to 
43
   *        the hub node, creating a total of 
44
   *        numSpokes + 1 nodes
45
   *
46
   * \param p2pHelper the link helper for p2p links, 
47
   *        used to link nodes together
48
   */
49
  PointToPointStarHelper (uint32_t numSpokes, 
50
                          PointToPointHelper p2pHelper);
51
52
  ~PointToPointStarHelper ();
53
54
public:
55
  /**
56
   * \returns a node pointer to the hub node in the
57
   *          star, i.e., the center node
58
   */
59
  Ptr<Node> GetHub () const;
60
61
  /**
62
   * \param i an index into the spokes of the star
63
   *
64
   * \returns a node pointer to the node at the indexed spoke
65
   */
66
  Ptr<Node> GetSpokeNode (uint32_t i) const;
67
68
  /**
69
   * \param i index into the hub interfaces
70
   *
71
   * \returns Ipv4Address according to indexed hub interface
72
   */
73
  Ipv4Address GetHubIpv4Address (uint32_t i) const;
74
75
  /**
76
   * \param i index into the spoke interfaces
77
   *
78
   * \returns Ipv4Address according to indexed spoke interface
79
   */
80
  Ipv4Address GetSpokeIpv4Address (uint32_t i) const;
81
82
  /**
83
   * \returns the total number of spokes in the star
84
   */
85
  uint32_t SpokeCount () const;
86
87
  /**
88
   * \param stack an InternetStackHelper which is used to install 
89
   *              on every node in the star
90
   */
91
  void InstallStack (InternetStackHelper stack);
92
93
  /**
94
   * \param address an Ipv4AddressHelper which is used to install 
95
   *                Ipv4 addresses on all the node interfaces in 
96
   *                the star
97
   */
98
  void AssignIpv4Addresses (Ipv4AddressHelper address);
99
100
  /**
101
   * Sets up the node canvas locations for every node in the star. 
102
   * This is needed for use with the animation interface
103
   *
104
   * \param ulx upper left x value
105
   * \param uly upper left y value
106
   * \param lrx lower right x value
107
   * \param lry lower right y value
108
   */
109
  void BoundingBox (double ulx, double uly, double lrx, double lry);
110
111
private:
112
  NodeContainer m_hub;
113
  NetDeviceContainer m_hubDevices;
114
  NodeContainer m_spokes;
115
  NetDeviceContainer m_spokeDevices;
116
  Ipv4InterfaceContainer m_hubInterfaces;
117
  Ipv4InterfaceContainer m_spokeInterfaces;
118
};
119
120
} // namespace ns3
121
122
#endif /* POINT_TO_POINT_STAR_HELPER_H */
(-)e9ca5b2838e7 (+1 lines)
Added Link Here 
1
exec "`dirname "$0"`"/../../waf "$@"
(-)e9ca5b2838e7 (+23 lines)
Added Link Here 
1
## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
2
3
def build(bld):
4
    module = bld.create_ns3_module('point-to-point-layout', ['internet', 'point-to-point', 'mobility'])
5
    module.includes = '.'
6
    module.source = [
7
        'model/point-to-point-dumbbell.cc',
8
        'model/point-to-point-grid.cc',
9
        'model/point-to-point-star.cc',
10
        ]
11
12
    headers = bld.new_task_gen('ns3header')
13
    headers.module = 'point-to-point-layout'
14
    headers.source = [
15
        'model/point-to-point-dumbbell.h',
16
        'model/point-to-point-grid.h',
17
        'model/point-to-point-star.h',
18
        ]
19
20
    bld.ns3_python_bindings()
21
22
23
(-)a/src/wimax/examples/wimax-multicast.cc (-5 / +2 lines)
 Lines 59-69    Link Here 
59
#include "ns3/csma-module.h"
59
#include "ns3/csma-module.h"
60
#include <iostream>
60
#include <iostream>
61
#include "ns3/global-route-manager.h"
61
#include "ns3/global-route-manager.h"
62
#include "ns3/constant-position-mobility-model.h"
62
#include "ns3/mobility-module.h"
63
#include "ns3/random-waypoint-mobility-model.h"
63
#include "ns3/internet-module.h"
64
#include "ns3/ipv4-static-routing-helper.h"
65
#include "ns3/ipv4-list-routing-helper.h"
66
67
#include "ns3/vector.h"
64
#include "ns3/vector.h"
68
65
69
NS_LOG_COMPONENT_DEFINE ("WimaxMulticastSimulation");
66
NS_LOG_COMPONENT_DEFINE ("WimaxMulticastSimulation");
(-)a/src/wscript (+2 lines)
 Lines 57-62    Link Here 
57
    'energy',
57
    'energy',
58
    'tools',
58
    'tools',
59
    'visualizer',
59
    'visualizer',
60
    'point-to-point-layout',
61
    'csma-layout',
60
    )
62
    )
61
63
62
def set_options(opt):
64
def set_options(opt):

Return to bug 1105