merge with HEAD

This commit is contained in:
Mathieu Lacage
2008-11-28 08:56:47 +01:00
30 changed files with 1451 additions and 308 deletions

View File

@@ -106,6 +106,14 @@ assignment of /32 addresses.
</li>
</ul>
<li>17-11-2008; changeset
<a href="http://code.nsnam.org/ns-3-dev/rev/756887a9bbea">756887a9bbea</a></li>
<ul>
<li>
Global routing supports bridge devices.
</li>
</ul>
<hr>
<h1>changes from ns-3.1 to ns-3.2</h1>

View File

@@ -0,0 +1,246 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation;
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
// Network topology
//
// bridge1 The node named bridge1 (node 5 in the nodelist)
// ------------------ has three CMSA net devices that are bridged
// CSMA CSMA CSMA together using a BridgeNetDevice.
// | | |
// | | | The bridge node talks over three CSMA channels
// | | |
// CSMA CSMA CSMA to three other CSMA net devices
// ---- ---- ----
// n0 n1 n2 Node two acts as a router and talks to another
// ---- bridge that connects the remaining nodes.
// CSMA
// |
// n3 n4 |
// ---- ---- |
// CSMA CSMA |
// | | |
// | | |
// | | |
// CSMA CSMA CSMA The node named bridge2 (node 6 in the nodelist)
// ------------------ has three CMSA net devices that are bridged
// bridge2 together using a BridgeNetDevice.
//
// Or, more abstractly, recognizing that bridge 1 and bridge 2 are nodes
// with three net devices:
//
// n0 n1 (n0 = 10.1.1.2)
// | | (n1 = 10.1.1.3) Note odd addressing
// ----------- (n2 = 10.1.1.1)
// | bridge1 | <- n5
// -----------
// |
// router <- n2
// |
// -----------
// | bridge2 | <- n6
// ----------- (n2 = 10.1.2.1)
// | | (n3 = 10.1.2.2)
// n3 n4 (n4 = 10.1.2.3)
//
// So, this example shows two broadcast domains, each interconnected by a bridge
// with a router node (n2) interconnecting the layer-2 broadcast domains
//
// It is meant to mirror somewhat the csma-bridge example but adds another
// bridged link separated by a router.
//
// - CBR/UDP flows from n0 (10.1.1.2) to n1 (10.1.1.3) and from n3 (10.1.2.2) to n0 (10.1.1.3)
// - DropTail queues
// - Global static routing
// - Tracing of queues and packet receptions to file "csma-bridge-one-hop.tr"
#include <iostream>
#include <fstream>
#include "ns3/simulator-module.h"
#include "ns3/node-module.h"
#include "ns3/core-module.h"
#include "ns3/helper-module.h"
#include "ns3/bridge-module.h"
#include "ns3/global-route-manager.h"
using namespace ns3;
NS_LOG_COMPONENT_DEFINE ("CsmaBridgeOneHopExample");
int
main (int argc, char *argv[])
{
//
// Users may find it convenient to turn on explicit debugging
// for selected modules; the below lines suggest how to do this
//
#if 0
LogComponentEnable ("CsmaBridgeOneHopExample", LOG_LEVEL_INFO);
#endif
//
// Make the random number generators generate reproducible results.
//
RandomVariable::UseGlobalSeed (1, 1, 2, 3, 5, 8);
//
// Allow the user to override any of the defaults and the above Bind() at
// run-time, via command-line arguments
//
CommandLine cmd;
cmd.Parse (argc, argv);
//
// Explicitly create the nodes required by the topology (shown above).
//
NS_LOG_INFO ("Create nodes.");
Ptr<Node> n0 = CreateObject<Node> ();
Ptr<Node> n1 = CreateObject<Node> ();
Ptr<Node> n2 = CreateObject<Node> ();
Ptr<Node> n3 = CreateObject<Node> ();
Ptr<Node> n4 = CreateObject<Node> ();
Ptr<Node> bridge1 = CreateObject<Node> ();
Ptr<Node> bridge2 = CreateObject<Node> ();
NS_LOG_INFO ("Build Topology");
CsmaHelper csma;
csma.SetChannelAttribute ("DataRate", DataRateValue (5000000));
csma.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (2)));
// Create the csma links, from each terminal to the bridge
// This will create six network devices; we'll keep track separately
// of the devices on and off the bridge respectively, for later configuration
NetDeviceContainer topLanDevices;
NetDeviceContainer topBridgeDevices;
// It is easier to iterate the nodes in C++ if we put them into a container
NodeContainer topLan (n2, n0, n1);
for (int i = 0; i < 3; i++)
{
// install a csma channel between the ith toplan node and the bridge node
NetDeviceContainer link = csma.Install (NodeContainer (topLan.Get (i), bridge1));
topLanDevices.Add (link.Get (0));
topBridgeDevices.Add (link.Get (1));
}
//
// Now, Create the bridge netdevice, which will do the packet switching. The
// bridge lives on the node bridge1 and bridges together the topBridgeDevices
// which are the three CSMA net devices on the node in the diagram above.
//
BridgeHelper bridge;
bridge.Install (bridge1, topBridgeDevices);
// Add internet stack to the topLan nodes
InternetStackHelper internet;
internet.Install (topLan);
// Repeat for bottom bridged LAN
NetDeviceContainer bottomLanDevices;
NetDeviceContainer bottomBridgeDevices;
NodeContainer bottomLan (n2, n3, n4);
for (int i = 0; i < 3; i++)
{
NetDeviceContainer link = csma.Install (NodeContainer (bottomLan.Get (i), bridge2));
bottomLanDevices.Add (link.Get (0));
bottomBridgeDevices.Add (link.Get (1));
}
bridge.Install (bridge2, bottomBridgeDevices);
// Add internet stack to the bottomLan nodes
internet.Install (NodeContainer (n3, n4));
// We've got the "hardware" in place. Now we need to add IP addresses.
NS_LOG_INFO ("Assign IP Addresses.");
Ipv4AddressHelper ipv4;
ipv4.SetBase ("10.1.1.0", "255.255.255.0");
ipv4.Assign (topLanDevices);
ipv4.SetBase ("10.1.2.0", "255.255.255.0");
ipv4.Assign (bottomLanDevices);
//
// Create router nodes, initialize routing database and set up the routing
// tables in the nodes. We excuse the bridge nodes from having to serve as
// routers, since they don't even have internet stacks on them.
//
NodeContainer routerNodes (n0, n1, n2, n3, n4);
GlobalRouteManager::PopulateRoutingTables (routerNodes);
//
// Create an OnOff application to send UDP datagrams from node zero to node 1.
//
NS_LOG_INFO ("Create Applications.");
uint16_t port = 9; // Discard port (RFC 863)
OnOffHelper onoff ("ns3::UdpSocketFactory",
Address (InetSocketAddress (Ipv4Address ("10.1.1.3"), port)));
onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1)));
onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0)));
ApplicationContainer app = onoff.Install (n0);
// Start the application
app.Start (Seconds (1.0));
app.Stop (Seconds (10.0));
// Create an optional packet sink to receive these packets
PacketSinkHelper sink ("ns3::UdpSocketFactory",
Address (InetSocketAddress (Ipv4Address::GetAny (), port)));
ApplicationContainer sink1 = sink.Install (n1);
sink1.Start (Seconds (1.0));
sink1.Stop (Seconds (10.0));
//
// Create a similar flow from n3 to n0, starting at time 1.1 seconds
//
onoff.SetAttribute ("Remote",
AddressValue (InetSocketAddress (Ipv4Address ("10.1.1.2"), port)));
ApplicationContainer app2 = onoff.Install (n3);
app2.Start (Seconds (1.1));
app2.Stop (Seconds (10.0));
ApplicationContainer sink2 = sink.Install (n0);
sink2.Start (Seconds (1.1));
sink2.Stop (Seconds (10.0));
//
// Configure tracing of all enqueue, dequeue, and NetDevice receive events.
// Trace output will be sent to the file "csma-bridge-one-hop.tr"
//
NS_LOG_INFO ("Configure Tracing.");
std::ofstream ascii;
ascii.open ("csma-bridge-one-hop.tr");
CsmaHelper::EnableAsciiAll (ascii);
//
// Also configure some tcpdump traces; each interface will be traced.
// The output files will be named:
// csma-bridge.pcap-<nodeId>-<interfaceId>
// and can be read by the "tcpdump -r" command (use "-tt" option to
// display timestamps correctly)
//
CsmaHelper::EnablePcapAll ("csma-bridge-one-hop");
//
// Now, do the actual simulation.
//
NS_LOG_INFO ("Run Simulation.");
Simulator::Run ();
Simulator::Destroy ();
NS_LOG_INFO ("Done.");
}

View File

@@ -1,4 +1,46 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation;
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
// Default network topology includes some number of AP nodes specified by
// the variable nWifis (defaults to two). Off of each AP node, there are some
// number of STA nodes specified by the variable nStas (defaults to two).
// Each AP talks to its associated STA nodes. There are bridge net devices
// on each AP node that bridge the whole thing into one network.
//
// +-----+ +-----+ +-----+ +-----+
// | STA | | STA | | STA | | STA |
// +-----+ +-----+ +-----+ +-----+
// 192.168.0.3 192.168.0.4 192.168.0.5 192.168.0.6
// -------- -------- -------- --------
// WIFI STA WIFI STA WIFI STA WIFI STA
// -------- -------- -------- --------
// ((*)) ((*)) | ((*)) ((*))
// |
// ((*)) | ((*))
// ------- -------
// WIFI AP CSMA ========= CSMA WIFI AP
// ------- ---- ---- -------
// ############## ##############
// BRIDGE BRIDGE
// ############## ##############
// 192.168.0.1 192.168.0.2
// +---------+ +---------+
// | AP Node | | AP Node |
// +---------+ +---------+
//
#include "ns3/core-module.h"
#include "ns3/simulator-module.h"
@@ -46,7 +88,6 @@ int main (int argc, char *argv[])
stack.Install (backboneNodes);
backboneDevices = csma.Install (backboneNodes);
backboneInterfaces = ip.Assign (backboneDevices);
double wifiX = 0.0;
for (uint32_t i = 0; i < nWifis; ++i)
@@ -69,7 +110,6 @@ int main (int argc, char *argv[])
wifiPhy.SetChannel (wifiChannel.Create ());
sta.Create (nStas);
ip.NewNetwork ();
mobility.SetPositionAllocator ("ns3::GridPositionAllocator",
"MinX", DoubleValue (wifiX),
"MinY", DoubleValue (0.0),
@@ -87,8 +127,12 @@ int main (int argc, char *argv[])
"BeaconGeneration", BooleanValue (true),
"BeaconInterval", TimeValue (Seconds (2.5)));
apDev = wifi.Install (wifiPhy, backboneNodes.Get (i));
apInterface = ip.Assign (apDev);
bridge.Install (backboneNodes.Get (i), NetDeviceContainer (apDev, backboneDevices.Get (i)));
NetDeviceContainer bridgeDev;
bridgeDev = bridge.Install (backboneNodes.Get (i), NetDeviceContainer (apDev, backboneDevices.Get (i)));
// assign AP IP address to bridge, not wifi
apInterface = ip.Assign (bridgeDev);
// setup the STAs
stack.Install (sta);

View File

@@ -28,6 +28,10 @@ def build(bld):
['bridge', 'csma', 'internet-stack'])
obj.source = 'csma-bridge.cc'
obj = bld.create_ns3_program('csma-bridge-one-hop',
['bridge', 'csma', 'internet-stack'])
obj.source = 'csma-bridge-one-hop.cc'
obj = bld.create_ns3_program('udp-echo',
['csma', 'internet-stack'])
obj.source = 'udp-echo.cc'

View File

@@ -149,6 +149,7 @@ void
V4Ping::StopApplication (void)
{
NS_LOG_FUNCTION (this);
m_socket->Close ();
}

View File

@@ -21,6 +21,16 @@
#include "fatal-error.h"
#define NS_ABORT_MSG(msg) \
do { \
std::cerr << "file=" << __FILE__ << \
", line=" << __LINE__ << ", abort, msg=\"" << \
msg << "\"" << std::endl; \
int *a = 0; \
*a = 0; \
} while (false)
#define NS_ABORT_IF(cond) \
do { \
if (cond) \

View File

@@ -57,6 +57,7 @@ BridgeNetDevice::BridgeNetDevice ()
m_ifIndex (0),
m_mtu (0xffff)
{
NS_LOG_FUNCTION_NOARGS ();
m_channel = CreateObject<BridgeChannel> ();
}
@@ -100,6 +101,7 @@ void
BridgeNetDevice::ForwardUnicast (Ptr<NetDevice> incomingPort, Ptr<const Packet> packet,
uint16_t protocol, Mac48Address src, Mac48Address dst)
{
NS_LOG_FUNCTION_NOARGS ();
NS_LOG_DEBUG ("LearningBridgeForward (incomingPort=" << incomingPort->GetName ()
<< ", packet=" << packet << ", protocol="<<protocol
<< ", src=" << src << ", dst=" << dst << ")");
@@ -133,6 +135,7 @@ void
BridgeNetDevice::ForwardBroadcast (Ptr<NetDevice> incomingPort, Ptr<const Packet> packet,
uint16_t protocol, Mac48Address src, Mac48Address dst)
{
NS_LOG_FUNCTION_NOARGS ();
NS_LOG_DEBUG ("LearningBridgeForward (incomingPort=" << incomingPort->GetName ()
<< ", packet=" << packet << ", protocol="<<protocol
<< ", src=" << src << ", dst=" << dst << ")");
@@ -154,6 +157,7 @@ BridgeNetDevice::ForwardBroadcast (Ptr<NetDevice> incomingPort, Ptr<const Packet
void BridgeNetDevice::Learn (Mac48Address source, Ptr<NetDevice> port)
{
NS_LOG_FUNCTION_NOARGS ();
if (m_enableLearning)
{
LearnedState &state = m_learnState[source];
@@ -164,6 +168,7 @@ void BridgeNetDevice::Learn (Mac48Address source, Ptr<NetDevice> port)
Ptr<NetDevice> BridgeNetDevice::GetLearnedState (Mac48Address source)
{
NS_LOG_FUNCTION_NOARGS ();
if (m_enableLearning)
{
Time now = Simulator::Now ();
@@ -185,9 +190,25 @@ Ptr<NetDevice> BridgeNetDevice::GetLearnedState (Mac48Address source)
return NULL;
}
uint32_t
BridgeNetDevice::GetNBridgePorts (void) const
{
NS_LOG_FUNCTION_NOARGS ();
return m_ports.size ();
}
Ptr<NetDevice>
BridgeNetDevice::GetBridgePort (uint32_t n) const
{
NS_LOG_FUNCTION_NOARGS ();
return m_ports[n];
}
void
BridgeNetDevice::AddBridgePort (Ptr<NetDevice> bridgePort)
{
NS_LOG_FUNCTION_NOARGS ();
NS_ASSERT (bridgePort != this);
if (!Mac48Address::IsMatchingType (bridgePort->GetAddress ()))
{
@@ -212,42 +233,49 @@ BridgeNetDevice::AddBridgePort (Ptr<NetDevice> bridgePort)
void
BridgeNetDevice::SetName(const std::string name)
{
NS_LOG_FUNCTION_NOARGS ();
m_name = name;
}
std::string
BridgeNetDevice::GetName(void) const
{
NS_LOG_FUNCTION_NOARGS ();
return m_name;
}
void
BridgeNetDevice::SetIfIndex(const uint32_t index)
{
NS_LOG_FUNCTION_NOARGS ();
m_ifIndex = index;
}
uint32_t
BridgeNetDevice::GetIfIndex(void) const
{
NS_LOG_FUNCTION_NOARGS ();
return m_ifIndex;
}
Ptr<Channel>
BridgeNetDevice::GetChannel (void) const
{
NS_LOG_FUNCTION_NOARGS ();
return m_channel;
}
Address
BridgeNetDevice::GetAddress (void) const
{
NS_LOG_FUNCTION_NOARGS ();
return m_address;
}
bool
BridgeNetDevice::SetMtu (const uint16_t mtu)
{
NS_LOG_FUNCTION_NOARGS ();
m_mtu = mtu;
return true;
}
@@ -255,6 +283,7 @@ BridgeNetDevice::SetMtu (const uint16_t mtu)
uint16_t
BridgeNetDevice::GetMtu (void) const
{
NS_LOG_FUNCTION_NOARGS ();
return m_mtu;
}
@@ -262,6 +291,7 @@ BridgeNetDevice::GetMtu (void) const
bool
BridgeNetDevice::IsLinkUp (void) const
{
NS_LOG_FUNCTION_NOARGS ();
return true;
}
@@ -274,6 +304,7 @@ BridgeNetDevice::SetLinkChangeCallback (Callback<void> callback)
bool
BridgeNetDevice::IsBroadcast (void) const
{
NS_LOG_FUNCTION_NOARGS ();
return true;
}
@@ -281,12 +312,14 @@ BridgeNetDevice::IsBroadcast (void) const
Address
BridgeNetDevice::GetBroadcast (void) const
{
NS_LOG_FUNCTION_NOARGS ();
return Mac48Address ("ff:ff:ff:ff:ff:ff");
}
bool
BridgeNetDevice::IsMulticast (void) const
{
NS_LOG_FUNCTION_NOARGS ();
return true;
}
@@ -302,13 +335,22 @@ BridgeNetDevice::GetMulticast (Ipv4Address multicastGroup) const
bool
BridgeNetDevice::IsPointToPoint (void) const
{
NS_LOG_FUNCTION_NOARGS ();
return false;
}
bool
BridgeNetDevice::IsBridge (void) const
{
NS_LOG_FUNCTION_NOARGS ();
return true;
}
bool
BridgeNetDevice::Send (Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber)
{
NS_LOG_FUNCTION_NOARGS ();
for (std::vector< Ptr<NetDevice> >::iterator iter = m_ports.begin ();
iter != m_ports.end (); iter++)
{
@@ -322,6 +364,7 @@ BridgeNetDevice::Send (Ptr<Packet> packet, const Address& dest, uint16_t protoco
bool
BridgeNetDevice::SendFrom (Ptr<Packet> packet, const Address& src, const Address& dest, uint16_t protocolNumber)
{
NS_LOG_FUNCTION_NOARGS ();
for (std::vector< Ptr<NetDevice> >::iterator iter = m_ports.begin ();
iter != m_ports.end (); iter++)
{
@@ -336,6 +379,7 @@ BridgeNetDevice::SendFrom (Ptr<Packet> packet, const Address& src, const Address
Ptr<Node>
BridgeNetDevice::GetNode (void) const
{
NS_LOG_FUNCTION_NOARGS ();
return m_node;
}
@@ -343,6 +387,7 @@ BridgeNetDevice::GetNode (void) const
void
BridgeNetDevice::SetNode (Ptr<Node> node)
{
NS_LOG_FUNCTION_NOARGS ();
m_node = node;
}
@@ -350,6 +395,7 @@ BridgeNetDevice::SetNode (Ptr<Node> node)
bool
BridgeNetDevice::NeedsArp (void) const
{
NS_LOG_FUNCTION_NOARGS ();
return true;
}
@@ -357,25 +403,28 @@ BridgeNetDevice::NeedsArp (void) const
void
BridgeNetDevice::SetReceiveCallback (NetDevice::ReceiveCallback cb)
{
NS_LOG_FUNCTION_NOARGS ();
m_rxCallback = cb;
}
void
BridgeNetDevice::SetPromiscReceiveCallback (NetDevice::PromiscReceiveCallback cb)
{
NS_LOG_FUNCTION_NOARGS ();
m_promiscRxCallback = cb;
}
bool
BridgeNetDevice::SupportsSendFrom () const
{
NS_LOG_FUNCTION_NOARGS ();
return true;
}
void
BridgeNetDevice::DoDispose (void)
{
NS_LOG_FUNCTION_NOARGS ();
m_node = 0;
NetDevice::DoDispose ();
}

View File

@@ -82,6 +82,10 @@ public:
*/
void AddBridgePort (Ptr<NetDevice> bridgePort);
uint32_t GetNBridgePorts (void) const;
Ptr<NetDevice> GetBridgePort (uint32_t n) const;
// inherited from NetDevice base class.
virtual void SetName(const std::string name);
virtual std::string GetName(void) const;
@@ -98,6 +102,7 @@ public:
virtual bool IsMulticast (void) const;
virtual Address GetMulticast (Ipv4Address multicastGroup) const;
virtual bool IsPointToPoint (void) const;
virtual bool IsBridge (void) const;
virtual bool Send (Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber);
virtual bool SendFrom (Ptr<Packet> packet, const Address& source, const Address& dest, uint16_t protocolNumber);
virtual Ptr<Node> GetNode (void) const;

View File

@@ -832,6 +832,13 @@ CsmaNetDevice::GetMulticast (Ipv4Address multicastGroup) const
bool
CsmaNetDevice::IsPointToPoint (void) const
{
NS_LOG_FUNCTION_NOARGS ();
return false;
}
bool
CsmaNetDevice::IsBridge (void) const
{
NS_LOG_FUNCTION_NOARGS ();
return false;

View File

@@ -350,6 +350,12 @@ public:
*/
virtual bool IsPointToPoint (void) const;
/**
* Is this a bridge?
* \returns false.
*/
virtual bool IsBridge (void) const;
/**
* Start sending a packet down the channel.
*/

View File

@@ -882,6 +882,12 @@ EmuNetDevice::IsPointToPoint (void) const
return false;
}
bool
EmuNetDevice::IsBridge (void) const
{
return false;
}
void
EmuNetDevice::SetPromiscReceiveCallback (PromiscReceiveCallback cb)
{

View File

@@ -165,6 +165,12 @@ public:
*/
virtual bool IsPointToPoint (void) const;
/**
* Is this a bridge?
* \returns false.
*/
virtual bool IsBridge (void) const;
virtual bool Send(Ptr<Packet> packet, const Address &dest, uint16_t protocolNumber);
virtual bool SendFrom(Ptr<Packet> packet, const Address& source, const Address& dest, uint16_t protocolNumber);

View File

@@ -391,6 +391,12 @@ PointToPointNetDevice::IsPointToPoint (void) const
return true;
}
bool
PointToPointNetDevice::IsBridge (void) const
{
return false;
}
bool
PointToPointNetDevice::Send(
Ptr<Packet> packet,

View File

@@ -252,6 +252,7 @@ public:
virtual Address GetMulticast (Ipv4Address multicastGroup) const;
virtual bool IsPointToPoint (void) const;
virtual bool IsBridge (void) const;
virtual bool Send(Ptr<Packet> packet, const Address &dest, uint16_t protocolNumber);
virtual bool SendFrom(Ptr<Packet> packet, const Address& source, const Address& dest, uint16_t protocolNumber);

View File

@@ -238,6 +238,11 @@ WifiNetDevice::IsPointToPoint (void) const
return false;
}
bool
WifiNetDevice::IsBridge (void) const
{
return false;
}
bool
WifiNetDevice::Send(Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber)
{
NS_ASSERT (Mac48Address::IsMatchingType (dest));

View File

@@ -90,6 +90,7 @@ public:
virtual bool IsMulticast (void) const;
virtual Address GetMulticast (Ipv4Address multicastGroup) const;
virtual bool IsPointToPoint (void) const;
virtual bool IsBridge (void) const;
virtual bool Send(Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber);
virtual Ptr<Node> GetNode (void) const;
virtual void SetNode (Ptr<Node> node);

View File

@@ -1,24 +1,49 @@
#include "bridge-helper.h"
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation;
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "bridge-helper.h"
#include "ns3/log.h"
#include "ns3/bridge-net-device.h"
#include "ns3/node.h"
NS_LOG_COMPONENT_DEFINE ("BridgeHelper");
namespace ns3 {
BridgeHelper::BridgeHelper ()
{
NS_LOG_FUNCTION_NOARGS ();
m_deviceFactory.SetTypeId ("ns3::BridgeNetDevice");
}
void
BridgeHelper::SetDeviceAttribute (std::string n1, const AttributeValue &v1)
{
NS_LOG_FUNCTION_NOARGS ();
m_deviceFactory.Set (n1, v1);
}
NetDeviceContainer
BridgeHelper::Install (Ptr<Node> node, NetDeviceContainer c)
{
NS_LOG_FUNCTION_NOARGS ();
NS_LOG_LOGIC ("**** Install bridge device on node " << node->GetId ());
NetDeviceContainer devs;
Ptr<BridgeNetDevice> dev = m_deviceFactory.Create<BridgeNetDevice> ();
devs.Add (dev);
@@ -26,6 +51,7 @@ BridgeHelper::Install (Ptr<Node> node, NetDeviceContainer c)
for (NetDeviceContainer::Iterator i = c.Begin (); i != c.End (); ++i)
{
NS_LOG_LOGIC ("**** Add BridgePort "<< *i);
dev->AddBridgePort (*i);
}
return devs;

View File

@@ -50,6 +50,17 @@ NodeContainer::NodeContainer (const NodeContainer &a, const NodeContainer &b,
Add (d);
}
NodeContainer::NodeContainer (const NodeContainer &a, const NodeContainer &b,
const NodeContainer &c, const NodeContainer &d,
const NodeContainer &e)
{
Add (a);
Add (b);
Add (c);
Add (d);
Add (e);
}
NodeContainer::Iterator
NodeContainer::Begin (void) const
{

View File

@@ -64,6 +64,8 @@ public:
NodeContainer (const NodeContainer &a, const NodeContainer &b, const NodeContainer &c);
NodeContainer (const NodeContainer &a, const NodeContainer &b, const NodeContainer &c, const NodeContainer &d);
NodeContainer (const NodeContainer &a, const NodeContainer &b, const NodeContainer &c, const NodeContainer &d,
const NodeContainer &e);
/**
* \returns an iterator to the start of the vector of node pointers.

View File

@@ -184,6 +184,15 @@ public:
virtual Address GetMulticast (Ipv6Address addr) const = 0;
/**
* \brief Return true if the net device is acting as a bridge.
*
* \return value of m_isBridge flag
*/
virtual bool IsBridge (void) const = 0;
/**
* \brief Return true if the net device is on a point-to-point link.
*
* \return value of m_isPointToPoint flag
*/
virtual bool IsPointToPoint (void) const = 0;

View File

@@ -163,6 +163,13 @@ SimpleNetDevice::IsPointToPoint (void) const
{
return false;
}
bool
SimpleNetDevice::IsBridge (void) const
{
return false;
}
bool
SimpleNetDevice::Send(Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber)
{

View File

@@ -61,6 +61,7 @@ public:
virtual bool IsMulticast (void) const;
virtual Address GetMulticast (Ipv4Address multicastGroup) const;
virtual bool IsPointToPoint (void) const;
virtual bool IsBridge (void) const;
virtual bool Send(Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber);
virtual bool SendFrom(Ptr<Packet> packet, const Address& source, const Address& dest, uint16_t protocolNumber);
virtual Ptr<Node> GetNode (void) const;

View File

@@ -97,7 +97,7 @@ SPFVertex::~SPFVertex ()
void
SPFVertex::SetVertexType (SPFVertex::VertexType type)
{
NS_LOG_FUNCTION_NOARGS ();
NS_LOG_FUNCTION (type);
m_vertexType = type;
}
@@ -111,7 +111,7 @@ SPFVertex::GetVertexType (void) const
void
SPFVertex::SetVertexId (Ipv4Address id)
{
NS_LOG_FUNCTION_NOARGS ();
NS_LOG_FUNCTION (id);
m_vertexId = id;
}
@@ -125,7 +125,7 @@ SPFVertex::GetVertexId (void) const
void
SPFVertex::SetLSA (GlobalRoutingLSA* lsa)
{
NS_LOG_FUNCTION_NOARGS ();
NS_LOG_FUNCTION (lsa);
m_lsa = lsa;
}
@@ -139,7 +139,7 @@ SPFVertex::GetLSA (void) const
void
SPFVertex::SetDistanceFromRoot (uint32_t distance)
{
NS_LOG_FUNCTION_NOARGS ();
NS_LOG_FUNCTION (distance);
m_distanceFromRoot = distance;
}
@@ -153,7 +153,7 @@ SPFVertex::GetDistanceFromRoot (void) const
void
SPFVertex::SetOutgoingTypeId (uint32_t id)
{
NS_LOG_FUNCTION_NOARGS ();
NS_LOG_FUNCTION (id);
m_rootOif = id;
}
@@ -167,7 +167,7 @@ SPFVertex::GetOutgoingTypeId (void) const
void
SPFVertex::SetNextHop (Ipv4Address nextHop)
{
NS_LOG_FUNCTION_NOARGS ();
NS_LOG_FUNCTION (nextHop);
m_nextHop = nextHop;
}
@@ -181,7 +181,7 @@ SPFVertex::GetNextHop (void) const
void
SPFVertex::SetParent (SPFVertex* parent)
{
NS_LOG_FUNCTION_NOARGS ();
NS_LOG_FUNCTION (parent);
m_parent = parent;
}
@@ -202,7 +202,7 @@ SPFVertex::GetNChildren (void) const
SPFVertex*
SPFVertex::GetChild (uint32_t n) const
{
NS_LOG_FUNCTION_NOARGS ();
NS_LOG_FUNCTION (n);
uint32_t j = 0;
for ( ListOfSPFVertex_t::const_iterator i = m_children.begin ();
@@ -214,14 +214,14 @@ SPFVertex::GetChild (uint32_t n) const
return *i;
}
}
NS_ASSERT_MSG(false, "Index <n> out of range.");
NS_ASSERT_MSG (false, "Index <n> out of range.");
return 0;
}
uint32_t
SPFVertex::AddChild (SPFVertex* child)
{
NS_LOG_FUNCTION_NOARGS ();
NS_LOG_FUNCTION (child);
m_children.push_back (child);
return m_children.size ();
}
@@ -268,14 +268,14 @@ GlobalRouteManagerLSDB::Initialize ()
void
GlobalRouteManagerLSDB::Insert (Ipv4Address addr, GlobalRoutingLSA* lsa)
{
NS_LOG_FUNCTION_NOARGS ();
NS_LOG_FUNCTION (addr << lsa);
m_database.insert (LSDBPair_t (addr, lsa));
}
GlobalRoutingLSA*
GlobalRouteManagerLSDB::GetLSA (Ipv4Address addr) const
{
NS_LOG_FUNCTION_NOARGS ();
NS_LOG_FUNCTION (addr);
//
// Look up an LSA by its address.
//
@@ -293,7 +293,7 @@ GlobalRouteManagerLSDB::GetLSA (Ipv4Address addr) const
GlobalRoutingLSA*
GlobalRouteManagerLSDB::GetLSAByLinkData (Ipv4Address addr) const
{
NS_LOG_FUNCTION_NOARGS ();
NS_LOG_FUNCTION (addr);
//
// Look up an LSA by its address.
//
@@ -341,7 +341,7 @@ GlobalRouteManagerImpl::~GlobalRouteManagerImpl ()
void
GlobalRouteManagerImpl::DebugUseLsdb (GlobalRouteManagerLSDB* lsdb)
{
NS_LOG_FUNCTION_NOARGS ();
NS_LOG_FUNCTION (lsdb);
if (m_lsdb)
{
delete m_lsdb;
@@ -351,8 +351,7 @@ GlobalRouteManagerImpl::DebugUseLsdb (GlobalRouteManagerLSDB* lsdb)
//
// In order to build the routing database, we need at least one of the nodes
// to participate as a router. Eventually we expect to provide a mechanism
// for selecting a subset of the nodes to participate; for now, we just make
// to participate as a router. This is a convenience function that makes
// all nodes routers. We do this by walking the list of nodes in the system
// and aggregating a Global Router Interface to each of the nodes.
//
@@ -371,6 +370,21 @@ GlobalRouteManagerImpl::SelectRouterNodes ()
}
}
void
GlobalRouteManagerImpl::SelectRouterNodes (NodeContainer c)
{
NS_LOG_FUNCTION (&c);
for (NodeContainer::Iterator i = c.Begin (); i != c.End (); i++)
{
Ptr<Node> node = *i;
NS_LOG_LOGIC ("Adding GlobalRouter interface to node " <<
node->GetId ());
Ptr<GlobalRouter> globalRouter = CreateObject<GlobalRouter> ();
node->AggregateObject (globalRouter);
}
}
//
// In order to build the routing database, we need to walk the list of nodes
// in the system and look for those that support the GlobalRouter interface.
@@ -385,14 +399,14 @@ GlobalRouteManagerImpl::BuildGlobalRoutingDatabase ()
{
NS_LOG_FUNCTION_NOARGS ();
//
// Walk the list of nodes looking for the GlobalRouter Interface.
// Walk the list of nodes looking for the GlobalRouter Interface. Nodes with
// global router interfaces are, not too surprisingly, our routers.
//
for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); i++)
{
Ptr<Node> node = *i;
Ptr<GlobalRouter> rtr =
node->GetObject<GlobalRouter> ();
Ptr<GlobalRouter> rtr = node->GetObject<GlobalRouter> ();
//
// Ignore nodes that aren't participating in routing.
//
@@ -504,7 +518,7 @@ GlobalRouteManagerImpl::InitializeRoutes ()
void
GlobalRouteManagerImpl::SPFNext (SPFVertex* v, CandidateQueue& candidate)
{
NS_LOG_FUNCTION_NOARGS ();
NS_LOG_FUNCTION (v << &candidate);
SPFVertex* w = 0;
GlobalRoutingLSA* w_lsa = 0;
@@ -706,13 +720,13 @@ GlobalRouteManagerImpl::SPFNexthopCalculation (
GlobalRoutingLinkRecord* l,
uint32_t distance)
{
NS_LOG_FUNCTION_NOARGS ();
NS_LOG_FUNCTION (v << w << l << distance);
//
// If w is a NetworkVertex, l should be null
/*
if (w->GetVertexType () == SPFVertex::VertexNetwork && l)
{
NS_ASSERT_MSG(0, "Error: SPFNexthopCalculation parameter problem");
NS_ASSERT_MSG (0, "Error: SPFNexthopCalculation parameter problem");
}
*/
@@ -764,7 +778,7 @@ GlobalRouteManagerImpl::SPFNexthopCalculation (
// return the link record describing the link from <w> to <v>. Think of it as
// SPFGetLink.
//
NS_ASSERT(l);
NS_ASSERT (l);
GlobalRoutingLinkRecord *linkRemote = 0;
linkRemote = SPFGetNextLink (w, v, linkRemote);
//
@@ -778,7 +792,7 @@ GlobalRouteManagerImpl::SPFNexthopCalculation (
// from the root node to the host represented by vertex <w>, you have to send
// the packet to the next hop address specified in w->m_nextHop.
//
w->SetNextHop(linkRemote->GetLinkData ());
w->SetNextHop (linkRemote->GetLinkData ());
//
// Now find the outgoing interface corresponding to the point to point link
// from the perspective of <v> -- remember that <l> is the link "from"
@@ -832,7 +846,7 @@ GlobalRouteManagerImpl::SPFNexthopCalculation (
* use can then be derived from the next hop IP address (or
* it can be inherited from the parent network).
*/
w->SetNextHop(linkRemote->GetLinkData ());
w->SetNextHop (linkRemote->GetLinkData ());
w->SetOutgoingTypeId (v->GetOutgoingTypeId ());
NS_LOG_LOGIC ("Next hop from " <<
v->GetVertexId () << " to " << w->GetVertexId () <<
@@ -891,7 +905,7 @@ GlobalRouteManagerImpl::SPFGetNextLink (
SPFVertex* w,
GlobalRoutingLinkRecord* prev_link)
{
NS_LOG_FUNCTION_NOARGS ();
NS_LOG_FUNCTION (v << w << prev_link);
bool skip = true;
bool found_prev_link = false;
@@ -966,7 +980,7 @@ GlobalRouteManagerImpl::SPFGetNextLink (
void
GlobalRouteManagerImpl::DebugSPFCalculate (Ipv4Address root)
{
NS_LOG_FUNCTION_NOARGS ();
NS_LOG_FUNCTION (root);
SPFCalculate (root);
}
@@ -987,7 +1001,7 @@ GlobalRouteManagerImpl::SPFCalculate (Ipv4Address root)
// of the tree. Initially, this queue is empty.
//
CandidateQueue candidate;
NS_ASSERT(candidate.Size () == 0);
NS_ASSERT (candidate.Size () == 0);
//
// Initialize the shortest-path tree to only contain the router doing the
// calculation. Each router (and corresponding network) is a vertex in the
@@ -1094,7 +1108,7 @@ GlobalRouteManagerImpl::SPFCalculate (Ipv4Address root)
}
else
{
NS_ASSERT_MSG(0, "illegal SPFVertex type");
NS_ASSERT_MSG (0, "illegal SPFVertex type");
}
//
// RFC2328 16.1. (5).
@@ -1123,7 +1137,7 @@ GlobalRouteManagerImpl::SPFCalculate (Ipv4Address root)
uint32_t
GlobalRouteManagerImpl::FindOutgoingTypeId (Ipv4Address a, Ipv4Mask amask)
{
NS_LOG_FUNCTION_NOARGS ();
NS_LOG_FUNCTION (a << amask);
//
// We have an IP address <a> and a vertex ID of the root of the SPF tree.
// The question is what interface index does this address correspond to.
@@ -1199,7 +1213,7 @@ GlobalRouteManagerImpl::FindOutgoingTypeId (Ipv4Address a, Ipv4Mask amask)
void
GlobalRouteManagerImpl::SPFIntraAddRouter (SPFVertex* v)
{
NS_LOG_FUNCTION_NOARGS ();
NS_LOG_FUNCTION (v);
NS_ASSERT_MSG (m_spfroot,
"GlobalRouteManagerImpl::SPFIntraAddRouter (): Root pointer not set");
@@ -1316,7 +1330,7 @@ GlobalRouteManagerImpl::SPFIntraAddRouter (SPFVertex* v)
void
GlobalRouteManagerImpl::SPFIntraAddTransit (SPFVertex* v)
{
NS_LOG_FUNCTION_NOARGS ();
NS_LOG_FUNCTION (v);
NS_ASSERT_MSG (m_spfroot,
"GlobalRouteManagerImpl::SPFIntraAddTransit (): Root pointer not set");
@@ -1409,7 +1423,7 @@ GlobalRouteManagerImpl::SPFIntraAddTransit (SPFVertex* v)
void
GlobalRouteManagerImpl::SPFVertexAddParent (SPFVertex* v)
{
NS_LOG_FUNCTION_NOARGS ();
NS_LOG_FUNCTION (v);
v->GetParent ()->AddChild (v);
}

View File

@@ -29,6 +29,7 @@
#include "ns3/object.h"
#include "ns3/ptr.h"
#include "ns3/ipv4-address.h"
#include "ns3/node-container.h"
#include "global-router-interface.h"
namespace ns3 {
@@ -707,6 +708,14 @@ public:
*/
virtual void SelectRouterNodes ();
/**
* @brief Select which nodes in the system are to be router nodes and
* aggregate the appropriate interfaces onto those nodes.
* @internal
*
*/
virtual void SelectRouterNodes (NodeContainer c);
/**
* @brief Build the routing database by gathering Link State Advertisements
* from each node exporting a GlobalRouter interface.

View File

@@ -21,6 +21,7 @@
#include "ns3/assert.h"
#include "ns3/log.h"
#include "ns3/simulation-singleton.h"
#include "ns3/node-container.h"
#include "global-route-manager.h"
#include "global-route-manager-impl.h"
@@ -33,7 +34,7 @@ namespace ns3 {
// ---------------------------------------------------------------------------
void
GlobalRouteManager::PopulateRoutingTables ()
GlobalRouteManager::PopulateRoutingTables (void)
{
SelectRouterNodes ();
BuildGlobalRoutingDatabase ();
@@ -41,28 +42,43 @@ GlobalRouteManager::PopulateRoutingTables ()
}
void
GlobalRouteManager::SelectRouterNodes ()
GlobalRouteManager::PopulateRoutingTables (NodeContainer c)
{
SelectRouterNodes (c);
BuildGlobalRoutingDatabase ();
InitializeRoutes ();
}
void
GlobalRouteManager::SelectRouterNodes (void)
{
SimulationSingleton<GlobalRouteManagerImpl>::Get ()->
SelectRouterNodes ();
}
void
GlobalRouteManager::BuildGlobalRoutingDatabase ()
GlobalRouteManager::SelectRouterNodes (NodeContainer c)
{
SimulationSingleton<GlobalRouteManagerImpl>::Get ()->
SelectRouterNodes (c);
}
void
GlobalRouteManager::BuildGlobalRoutingDatabase (void)
{
SimulationSingleton<GlobalRouteManagerImpl>::Get ()->
BuildGlobalRoutingDatabase ();
}
void
GlobalRouteManager::InitializeRoutes ()
GlobalRouteManager::InitializeRoutes (void)
{
SimulationSingleton<GlobalRouteManagerImpl>::Get ()->
InitializeRoutes ();
}
uint32_t
GlobalRouteManager::AllocateRouterId ()
GlobalRouteManager::AllocateRouterId (void)
{
static uint32_t routerId = 0;
return routerId++;

View File

@@ -22,6 +22,8 @@
#ifndef GLOBAL_ROUTE_MANAGER_H
#define GLOBAL_ROUTE_MANAGER_H
#include "ns3/node-container.h"
namespace ns3 {
/**
@@ -40,7 +42,8 @@ class GlobalRouteManager
public:
/**
* @brief Build a routing database and initialize the routing tables of
* the nodes in the simulation.
* the nodes in the simulation. Makes all nodes in the simulation into
* routers.
*
* All this function does is call BuildGlobalRoutingDatabase () and
* InitializeRoutes ().
@@ -50,6 +53,19 @@ public:
*/
static void PopulateRoutingTables ();
/**
* @brief Build a routing database and initialize the routing tables of
* the nodes in the simulation. Makes the nodes in the provided container
* into routers.
*
* All this function does is call BuildGlobalRoutingDatabase () and
* InitializeRoutes ().
*
* @see BuildGlobalRoutingDatabase ();
* @see InitializeRoutes ();
*/
static void PopulateRoutingTables (NodeContainer c);
/**
* @brief Allocate a 32-bit router ID from monotonically increasing counter.
*/
@@ -64,6 +80,14 @@ private:
*/
static void SelectRouterNodes ();
/**
* @brief Select which nodes in the system are to be router nodes and
* aggregate the appropriate interfaces onto those nodes.
* @internal
*
*/
static void SelectRouterNodes (NodeContainer c);
/**
* @brief Build the routing database by gathering Link State Advertisements
* from each node exporting a GlobalRouter interface.

File diff suppressed because it is too large Load Diff

View File

@@ -29,10 +29,14 @@
#include "ns3/node.h"
#include "ns3/channel.h"
#include "ns3/ipv4-address.h"
#include "ns3/net-device-container.h"
#include "ns3/bridge-net-device.h"
#include "ns3/global-route-manager.h"
namespace ns3 {
class GlobalRouter;
/**
* @brief A single link record for a link state advertisement.
*
@@ -43,6 +47,7 @@ namespace ns3 {
class GlobalRoutingLinkRecord
{
public:
friend class GlobalRoutingLSA;
/**
* @enum LinkType
* @brief Enumeration of the possible types of Global Routing Link Records.
@@ -639,9 +644,17 @@ private:
void ClearLSAs (void);
Ptr<NetDevice> GetAdjacent(Ptr<NetDevice> nd, Ptr<Channel> ch) const;
uint32_t FindIfIndexForDevice(Ptr<Node> node, Ptr<NetDevice> nd) const;
Ipv4Address FindDesignatedRouterForLink (Ptr<Node> node,
Ptr<NetDevice> ndLocal) const;
bool FindIfIndexForDevice(Ptr<Node> node, Ptr<NetDevice> nd, uint32_t &index) const;
Ipv4Address FindDesignatedRouterForLink (Ptr<NetDevice> ndLocal, bool allowRecursion) const;
bool AnotherRouterOnLink (Ptr<NetDevice> nd, bool allowRecursion) const;
void ProcessBroadcastLink (Ptr<NetDevice> nd, GlobalRoutingLSA *pLSA, NetDeviceContainer &c);
void ProcessSingleBroadcastLink (Ptr<NetDevice> nd, GlobalRoutingLSA *pLSA, NetDeviceContainer &c);
void ProcessBridgedBroadcastLink (Ptr<NetDevice> nd, GlobalRoutingLSA *pLSA, NetDeviceContainer &c);
void ProcessPointToPointLink (Ptr<NetDevice> ndLocal, GlobalRoutingLSA *pLSA);
void BuildNetworkLSAs (NetDeviceContainer c);
Ptr<BridgeNetDevice> NetDeviceIsBridged (Ptr<NetDevice> nd) const;
typedef std::list<GlobalRoutingLSA*> ListOfLSAs_t;
ListOfLSAs_t m_LSAs;

View File

@@ -447,16 +447,13 @@ def build(bld):
if Params.g_options.run:
# Check that the requested program name is valid
try:
wutils.find_program(Params.g_options.run, env)
except ValueError, ex:
Params.fatal(str(ex))
program_name, dummy_program_argv = wutils.get_run_program(Params.g_options.run, get_command_template())
# When --run'ing a program, tell WAF to only build that program,
# nothing more; this greatly speeds up compilation when all you
# want to do is run a test program.
if not Params.g_options.compile_targets:
Params.g_options.compile_targets = Params.g_options.run
Params.g_options.compile_targets = program_name

View File

@@ -94,13 +94,12 @@ def run_argv(argv, os_env=None):
Params.fatal("Command %s exited with code %i" % (argv, retval))
return retval
def run_program(program_string, command_template=None):
def get_run_program(program_string, command_template=None):
"""
if command_template is not None, then program_string == program
name and argv is given by command_template with %s replaced by the
full path to the program. Else, program_string is interpreted as
a shell command with first name being the program name.
Return the program name and argv of the process that would be executed by
run_program(program_string, command_template).
"""
#print "get_run_program_argv(program_string=%r, command_template=%r)" % (program_string, command_template)
env = Params.g_build.env_of_name('default')
if command_template in (None, '%s'):
@@ -132,7 +131,16 @@ def run_program(program_string, command_template=None):
Params.fatal("%s does not appear to be a program" % (program_name,))
execvec = shlex.split(command_template % (program_node.abspath(env),))
return program_name, execvec
def run_program(program_string, command_template=None):
"""
if command_template is not None, then program_string == program
name and argv is given by command_template with %s replaced by the
full path to the program. Else, program_string is interpreted as
a shell command with first name being the program name.
"""
dummy_program_name, execvec = get_run_program(program_string, command_template)
former_cwd = os.getcwd()
if (Params.g_options.cwd_launch):
os.chdir(Params.g_options.cwd_launch)