merged ns-3-dev
This commit is contained in:
@@ -23,49 +23,52 @@
|
||||
# - DropTail queues
|
||||
# - Tracing of queues and packet receptions to file "udp-echo.tr"
|
||||
|
||||
import ns3
|
||||
|
||||
import ns.applications
|
||||
import ns.core
|
||||
import ns.csma
|
||||
import ns.internet
|
||||
import ns.network
|
||||
|
||||
def main(argv):
|
||||
#
|
||||
# Allow the user to override any of the defaults and the above Bind() at
|
||||
# run-time, via command-line arguments
|
||||
#
|
||||
cmd = ns3.CommandLine()
|
||||
cmd = ns.core.CommandLine()
|
||||
cmd.Parse(argv)
|
||||
|
||||
#
|
||||
# But since this is a realtime script, don't allow the user to mess with
|
||||
# that.
|
||||
#
|
||||
ns3.GlobalValue.Bind("SimulatorImplementationType", ns3.StringValue("ns3::RealtimeSimulatorImpl"))
|
||||
ns.core.GlobalValue.Bind("SimulatorImplementationType", ns.core.StringValue("ns3::RealtimeSimulatorImpl"))
|
||||
|
||||
#
|
||||
# Explicitly create the nodes required by the topology (shown above).
|
||||
#
|
||||
print "Create nodes."
|
||||
n = ns3.NodeContainer()
|
||||
n = ns.network.NodeContainer()
|
||||
n.Create(4)
|
||||
|
||||
internet = ns3.InternetStackHelper()
|
||||
internet = ns.internet.InternetStackHelper()
|
||||
internet.Install(n)
|
||||
|
||||
#
|
||||
# Explicitly create the channels required by the topology (shown above).
|
||||
#
|
||||
print ("Create channels.")
|
||||
csma = ns3.CsmaHelper()
|
||||
csma.SetChannelAttribute("DataRate", ns3.DataRateValue(ns3.DataRate(5000000)))
|
||||
csma.SetChannelAttribute("Delay", ns3.TimeValue(ns3.MilliSeconds(2)));
|
||||
csma.SetDeviceAttribute("Mtu", ns3.UintegerValue(1400))
|
||||
csma = ns.csma.CsmaHelper()
|
||||
csma.SetChannelAttribute("DataRate", ns.network.DataRateValue(ns.network.DataRate(5000000)))
|
||||
csma.SetChannelAttribute("Delay", ns.core.TimeValue(ns.core.MilliSeconds(2)));
|
||||
csma.SetDeviceAttribute("Mtu", ns.core.UintegerValue(1400))
|
||||
d = csma.Install(n)
|
||||
|
||||
#
|
||||
# We've got the "hardware" in place. Now we need to add IP addresses.
|
||||
#
|
||||
print ("Assign IP Addresses.")
|
||||
ipv4 = ns3.Ipv4AddressHelper()
|
||||
ipv4.SetBase(ns3.Ipv4Address("10.1.1.0"), ns3.Ipv4Mask("255.255.255.0"))
|
||||
ipv4 = ns.internet.Ipv4AddressHelper()
|
||||
ipv4.SetBase(ns.network.Ipv4Address("10.1.1.0"), ns.network.Ipv4Mask("255.255.255.0"))
|
||||
i = ipv4.Assign(d)
|
||||
|
||||
print ("Create Applications.")
|
||||
@@ -74,10 +77,10 @@ def main(argv):
|
||||
# Create a UdpEchoServer application on node one.
|
||||
#
|
||||
port = 9 # well-known echo port number
|
||||
server = ns3.UdpEchoServerHelper(port)
|
||||
server = ns.applications.UdpEchoServerHelper(port)
|
||||
apps = server.Install(n.Get(1))
|
||||
apps.Start(ns3.Seconds(1.0))
|
||||
apps.Stop(ns3.Seconds(10.0))
|
||||
apps.Start(ns.core.Seconds(1.0))
|
||||
apps.Stop(ns.core.Seconds(10.0))
|
||||
|
||||
#
|
||||
# Create a UdpEchoClient application to send UDP datagrams from node zero to
|
||||
@@ -85,16 +88,16 @@ def main(argv):
|
||||
#
|
||||
packetSize = 1024
|
||||
maxPacketCount = 500
|
||||
interPacketInterval = ns3.Seconds(0.01)
|
||||
client = ns3.UdpEchoClientHelper(i.GetAddress (1), port)
|
||||
client.SetAttribute("MaxPackets", ns3.UintegerValue(maxPacketCount))
|
||||
client.SetAttribute("Interval", ns3.TimeValue(interPacketInterval))
|
||||
client.SetAttribute("PacketSize", ns3.UintegerValue(packetSize))
|
||||
interPacketInterval = ns.core.Seconds(0.01)
|
||||
client = ns.applications.UdpEchoClientHelper(i.GetAddress (1), port)
|
||||
client.SetAttribute("MaxPackets", ns.core.UintegerValue(maxPacketCount))
|
||||
client.SetAttribute("Interval", ns.core.TimeValue(interPacketInterval))
|
||||
client.SetAttribute("PacketSize", ns.core.UintegerValue(packetSize))
|
||||
apps = client.Install(n.Get(0))
|
||||
apps.Start(ns3.Seconds(2.0))
|
||||
apps.Stop(ns3.Seconds(10.0))
|
||||
apps.Start(ns.core.Seconds(2.0))
|
||||
apps.Stop(ns.core.Seconds(10.0))
|
||||
|
||||
ascii = ns3.AsciiTraceHelper()
|
||||
ascii = ns.network.AsciiTraceHelper()
|
||||
csma.EnableAsciiAll(ascii.CreateFileStream("realtime-udp-echo.tr"))
|
||||
csma.EnablePcapAll("realtime-udp-echo", False)
|
||||
|
||||
@@ -102,8 +105,8 @@ def main(argv):
|
||||
# Now, do the actual simulation.
|
||||
#
|
||||
print ("Run Simulation.")
|
||||
ns3.Simulator.Run()
|
||||
ns3.Simulator.Destroy()
|
||||
ns.core.Simulator.Run()
|
||||
ns.core.Simulator.Destroy()
|
||||
print ("Done.")
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
@@ -3,3 +3,5 @@
|
||||
def build(bld):
|
||||
obj = bld.create_ns3_program('realtime-udp-echo', ['csma', 'internet'])
|
||||
obj.source = 'realtime-udp-echo.cc'
|
||||
|
||||
bld.register_ns3_script('realtime-udp-echo.py', ['csma', 'internet', 'applications'])
|
||||
|
||||
@@ -105,7 +105,8 @@ RttEstimator::RttEstimator () : next (1), history (),
|
||||
|
||||
RttEstimator::RttEstimator(const RttEstimator& c)
|
||||
: Object (c), next(c.next), history(c.history),
|
||||
m_maxMultiplier (c.m_maxMultiplier), est(c.est), nSamples(c.nSamples),
|
||||
m_maxMultiplier (c.m_maxMultiplier), est(c.est),
|
||||
minrto(c.minrto), nSamples(c.nSamples),
|
||||
multiplier(c.multiplier)
|
||||
{}
|
||||
|
||||
|
||||
152
src/spectrum/test/spectrum-test.h
Normal file
152
src/spectrum/test/spectrum-test.h
Normal file
@@ -0,0 +1,152 @@
|
||||
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2009 University of Washington
|
||||
* Copyright (c) 2011 CTTC
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* Author: Nicola Baldo <nbaldo@cttc.es>
|
||||
* part of the code copied from test.h
|
||||
*/
|
||||
|
||||
#include <ns3/test.h>
|
||||
#include <ns3/spectrum-value.h>
|
||||
|
||||
|
||||
/**
|
||||
* \brief Test if two SpectrumModel instances are equal within a given tolerance.
|
||||
*
|
||||
* This test compares component-by-component the two SpectrumModel
|
||||
* instances; if any pair of components differs by more than the given
|
||||
* tolerance, the test fails.
|
||||
*
|
||||
* \param actual the actual value obtained by the simulator
|
||||
* \param expected the expected value obtained by off-line calculations
|
||||
* \param tol the tolerance
|
||||
* \param msg the message to print if the test fails
|
||||
*
|
||||
*/
|
||||
#define NS_TEST_ASSERT_MSG_SPECTRUM_MODEL_EQ_TOL(actual, expected, tol, msg) \
|
||||
NS_TEST_ASSERT_MSG_SPECTRUM_MODEL_EQ_TOL_INTERNAL(actual, expected, tol, msg, __FILE__, __LINE__)
|
||||
|
||||
|
||||
/**
|
||||
* \internal
|
||||
*/
|
||||
#define NS_TEST_ASSERT_MSG_SPECTRUM_MODEL_EQ_TOL_INTERNAL(actual, expected, tol, msg, file, line) \
|
||||
do \
|
||||
{ \
|
||||
Bands::const_iterator i = (actual).Begin (); \
|
||||
Bands::const_iterator j = (expected).Begin (); \
|
||||
uint32_t k = 0; \
|
||||
while (i != (actual).End () && j != (expected).End ()) \
|
||||
{ \
|
||||
if ((i->fl > j->fl + (tol)) || (i->fl < j->fl - (tol)) || \
|
||||
(i->fc > j->fc + (tol)) || (i->fc < j->fc - (tol)) || \
|
||||
(i->fh > j->fh + (tol)) || (i->fh < j->fh - (tol))) \
|
||||
{ \
|
||||
if (gBreakOnFailure) {*(int *)0 = 0;} \
|
||||
std::ostringstream indexStream; \
|
||||
indexStream << "[" << k << "]"; \
|
||||
std::ostringstream msgStream; \
|
||||
msgStream << (msg); \
|
||||
std::ostringstream actualStream; \
|
||||
actualStream << i->fl << " <-- " << i->fc << " --> " << i->fh; \
|
||||
std::ostringstream expectedStream; \
|
||||
expectedStream << j->fl << " <-- " << j->fc << " --> " << j->fh; \
|
||||
ReportTestFailure (std::string (#actual) + indexStream.str () + " == " + std::string (#expected) + indexStream.str (), \
|
||||
actualStream.str (), expectedStream.str (), msgStream.str (), (file), (line)); \
|
||||
} \
|
||||
++i; \
|
||||
++j; \
|
||||
++k; \
|
||||
} \
|
||||
if (i != (actual).End () || j != (expected).End ()) \
|
||||
{ \
|
||||
std::ostringstream msgStream; \
|
||||
msgStream << (msg); \
|
||||
std::ostringstream actualStream; \
|
||||
actualStream << (i != (actual).End ()); \
|
||||
std::ostringstream expectedStream; \
|
||||
expectedStream << (j != (expected).End ()); \
|
||||
ReportTestFailure ("Bands::iterator == End ()" , \
|
||||
actualStream.str (), expectedStream.str (), msgStream.str (), (file), (line)); \
|
||||
} \
|
||||
} \
|
||||
while (false); \
|
||||
|
||||
|
||||
/**
|
||||
* \brief Test if two SpectrumValue instances are equal within a given tolerance.
|
||||
*
|
||||
* This test compares component-by-component the two SpectrumValue
|
||||
* instances; if any pair of components differs by more than the given
|
||||
* tolerance, the test fails.
|
||||
*
|
||||
* \param actual the actual value obtained by the simulator
|
||||
* \param expected the expected value obtained by off-line calculations
|
||||
* \param tol the tolerance
|
||||
* \param msg the message to print if the test fails
|
||||
*
|
||||
*/
|
||||
#define NS_TEST_ASSERT_MSG_SPECTRUM_VALUE_EQ_TOL(actual, expected, tol, msg) \
|
||||
NS_TEST_ASSERT_MSG_SPECTRUM_VALUE_EQ_TOL_INTERNAL(actual, expected, tol, msg, __FILE__, __LINE__)
|
||||
|
||||
|
||||
/**
|
||||
* \internal
|
||||
*/
|
||||
#define NS_TEST_ASSERT_MSG_SPECTRUM_VALUE_EQ_TOL_INTERNAL(actual, expected, tol, msg, file, line) \
|
||||
do \
|
||||
{ \
|
||||
Values::const_iterator i = (actual).ConstValuesBegin (); \
|
||||
Values::const_iterator j = (expected).ConstValuesBegin (); \
|
||||
uint32_t k = 0; \
|
||||
while (i != (actual).ConstValuesEnd () && j != (expected).ConstValuesEnd ()) \
|
||||
{ \
|
||||
if ((*i) > (*j) + (tol) || (*i) < (*j) - (tol)) \
|
||||
{ \
|
||||
if (gBreakOnFailure) {*(int *)0 = 0;} \
|
||||
std::ostringstream indexStream; \
|
||||
indexStream << "[" << k << "]"; \
|
||||
std::ostringstream msgStream; \
|
||||
msgStream << msg; \
|
||||
std::ostringstream actualStream; \
|
||||
actualStream << actual; \
|
||||
std::ostringstream expectedStream; \
|
||||
expectedStream << expected; \
|
||||
ReportTestFailure (std::string (#actual) + indexStream.str () + " == " + std::string (#expected) + indexStream.str (), \
|
||||
actualStream.str (), expectedStream.str (), msgStream.str (), file, line); \
|
||||
} \
|
||||
++i; \
|
||||
++j; \
|
||||
++k; \
|
||||
} \
|
||||
if (i != (actual).ConstValuesEnd () || j != (expected).ConstValuesEnd ()) \
|
||||
{ \
|
||||
std::ostringstream msgStream; \
|
||||
msgStream << (msg); \
|
||||
std::ostringstream actualStream; \
|
||||
actualStream << (i != (actual).ConstValuesEnd ()); \
|
||||
std::ostringstream expectedStream; \
|
||||
expectedStream << (j != (expected).ConstValuesEnd ()); \
|
||||
ReportTestFailure ("Values::const_iterator == ConstValuesEnd ()" , \
|
||||
actualStream.str (), expectedStream.str (), msgStream.str (), (file), (line)); \
|
||||
} \
|
||||
} \
|
||||
while (false); \
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
#include <iostream>
|
||||
#include <math.h>
|
||||
|
||||
#include "spectrum-value-test.h"
|
||||
#include "spectrum-test.h"
|
||||
|
||||
// NS_LOG_COMPONENT_DEFINE ("SpectrumValueTest");
|
||||
|
||||
@@ -72,6 +72,7 @@ SpectrumValueTestCase::MoreOrLessEqual (SpectrumValue x, SpectrumValue y)
|
||||
void
|
||||
SpectrumValueTestCase::DoRun (void)
|
||||
{
|
||||
NS_TEST_ASSERT_MSG_SPECTRUM_MODEL_EQ_TOL (*m_a.GetSpectrumModel (), *m_b.GetSpectrumModel (), TOLERANCE, GetName ());
|
||||
NS_TEST_ASSERT_MSG_SPECTRUM_VALUE_EQ_TOL (m_a, m_b, TOLERANCE, GetName ());
|
||||
}
|
||||
|
||||
|
||||
@@ -1,77 +0,0 @@
|
||||
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2009 University of Washington
|
||||
* Copyright (c) 2011 CTTC
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* Author: Nicola Baldo <nbaldo@cttc.es>
|
||||
* part of the code copied from test.h
|
||||
*/
|
||||
|
||||
#include <ns3/test.h>
|
||||
#include <ns3/spectrum-value.h>
|
||||
|
||||
/**
|
||||
* \brief Test if two SpectrumValue instances are equal within a given tolerance.
|
||||
*
|
||||
* This test compares component-by-component the two SpectrumValue
|
||||
* instances; if any pair of components differs by more than the given
|
||||
* tolerance, the test fails.
|
||||
*
|
||||
* \param actual the actual value obtained by the simulator
|
||||
* \param expected the expected value obtained by off-line calculations
|
||||
* \param tol the tolerance
|
||||
* \param msg the message to print if the test fails
|
||||
*
|
||||
*/
|
||||
#define NS_TEST_ASSERT_MSG_SPECTRUM_VALUE_EQ_TOL(actual, expected, tol, msg) \
|
||||
NS_TEST_ASSERT_MSG_SPECTRUM_VALUE_EQ_TOL_INTERNAL(actual, expected, tol, msg, __FILE__, __LINE__)
|
||||
|
||||
|
||||
/**
|
||||
* \internal
|
||||
*/
|
||||
#define NS_TEST_ASSERT_MSG_SPECTRUM_VALUE_EQ_TOL_INTERNAL(actual, expected, tol, msg, file, line) \
|
||||
do \
|
||||
{ \
|
||||
Values::const_iterator i = actual.ConstValuesBegin (); \
|
||||
Values::const_iterator j = expected.ConstValuesBegin (); \
|
||||
uint32_t k = 0; \
|
||||
while (i != actual.ConstValuesEnd () && j != expected.ConstValuesEnd ()) \
|
||||
{ \
|
||||
if ((*i) > (*j) + (tol) || (*i) < (*j) - (tol)) \
|
||||
{ \
|
||||
if (gBreakOnFailure) {*(int *)0 = 0;} \
|
||||
std::ostringstream indexStream; \
|
||||
indexStream << "[" << k << "]"; \
|
||||
std::ostringstream msgStream; \
|
||||
msgStream << msg; \
|
||||
std::ostringstream actualStream; \
|
||||
actualStream << actual; \
|
||||
std::ostringstream expectedStream; \
|
||||
expectedStream << expected; \
|
||||
ReportTestFailure (std::string (#actual) + indexStream.str () + " == " + std::string (#expected) + indexStream.str (), \
|
||||
actualStream.str (), expectedStream.str (), msgStream.str (), file, line); \
|
||||
} \
|
||||
++i; \
|
||||
++j; \
|
||||
++k; \
|
||||
} \
|
||||
} \
|
||||
while (false); \
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -67,7 +67,7 @@ def build(bld):
|
||||
'helper/adhoc-aloha-noack-ideal-phy-helper.h',
|
||||
'helper/waveform-generator-helper.h',
|
||||
'helper/spectrum-analyzer-helper.h',
|
||||
'test/spectrum-value-test.h',
|
||||
'test/spectrum-test.h',
|
||||
]
|
||||
|
||||
if (bld.env['ENABLE_EXAMPLES']):
|
||||
|
||||
@@ -17,7 +17,12 @@
|
||||
#
|
||||
|
||||
import sys
|
||||
import ns3
|
||||
|
||||
import ns.core
|
||||
import ns.csma
|
||||
import ns.internet
|
||||
import ns.network
|
||||
import ns.tap_bridge
|
||||
|
||||
def main(argv):
|
||||
#
|
||||
@@ -25,15 +30,15 @@ def main(argv):
|
||||
# interact in real-time and therefore we have to use the real-time simulator
|
||||
# and take the time to calculate checksums.
|
||||
#
|
||||
ns3.GlobalValue.Bind("SimulatorImplementationType", ns3.StringValue("ns3::RealtimeSimulatorImpl"))
|
||||
ns3.GlobalValue.Bind("ChecksumEnabled", ns3.BooleanValue("true"))
|
||||
ns.core.GlobalValue.Bind("SimulatorImplementationType", ns.core.StringValue("ns3::RealtimeSimulatorImpl"))
|
||||
ns.core.GlobalValue.Bind("ChecksumEnabled", ns.core.BooleanValue("true"))
|
||||
|
||||
#
|
||||
# Create two ghost nodes. The first will represent the virtual machine host
|
||||
# on the left side of the network; and the second will represent the VM on
|
||||
# the right side.
|
||||
#
|
||||
nodes = ns3.NodeContainer()
|
||||
nodes = ns.network.NodeContainer()
|
||||
nodes.Create (2)
|
||||
|
||||
#
|
||||
@@ -41,7 +46,7 @@ def main(argv):
|
||||
# devices installed on both of the nodes. The data rate and delay for the
|
||||
# channel can be set through the command-line parser.
|
||||
#
|
||||
csma = ns3.CsmaHelper()
|
||||
csma = ns.csma.CsmaHelper()
|
||||
devices = csma.Install(nodes)
|
||||
|
||||
#
|
||||
@@ -52,24 +57,24 @@ def main(argv):
|
||||
# only see traffic from one other device on that bridge. That is the case
|
||||
# for this configuration.
|
||||
#
|
||||
tapBridge = ns3.TapBridgeHelper()
|
||||
tapBridge.SetAttribute ("Mode", ns3.StringValue ("UseLocal"))
|
||||
tapBridge.SetAttribute ("DeviceName", ns3.StringValue ("tap-left"))
|
||||
tapBridge = ns.tap_bridge.TapBridgeHelper()
|
||||
tapBridge.SetAttribute ("Mode", ns.core.StringValue ("UseLocal"))
|
||||
tapBridge.SetAttribute ("DeviceName", ns.core.StringValue ("tap-left"))
|
||||
tapBridge.Install (nodes.Get (0), devices.Get (0))
|
||||
|
||||
#
|
||||
# Connect the right side tap to the right side wifi device on the right-side
|
||||
# ghost node.
|
||||
#
|
||||
tapBridge.SetAttribute ("DeviceName", ns3.StringValue ("tap-right"))
|
||||
tapBridge.SetAttribute ("DeviceName", ns.core.StringValue ("tap-right"))
|
||||
tapBridge.Install (nodes.Get (1), devices.Get (1))
|
||||
|
||||
#
|
||||
# Run the simulation for ten minutes to give the user time to play around
|
||||
#
|
||||
ns3.Simulator.Stop (ns3.Seconds (600))
|
||||
ns3.Simulator.Run(signal_check_frequency = -1)
|
||||
ns3.Simulator.Destroy()
|
||||
ns.core.Simulator.Stop (ns.core.Seconds (600))
|
||||
ns.core.Simulator.Run(signal_check_frequency = -1)
|
||||
ns.core.Simulator.Destroy()
|
||||
return 0
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
@@ -17,7 +17,12 @@
|
||||
#
|
||||
|
||||
import sys
|
||||
import ns3
|
||||
import ns.core
|
||||
import ns.internet
|
||||
import ns.mobility
|
||||
import ns.network
|
||||
import ns.tap_bridge
|
||||
import ns.wifi
|
||||
|
||||
def main(argv):
|
||||
#
|
||||
@@ -25,35 +30,35 @@ def main(argv):
|
||||
# interact in real-time and therefore we have to use the real-time simulator
|
||||
# and take the time to calculate checksums.
|
||||
#
|
||||
ns3.GlobalValue.Bind("SimulatorImplementationType", ns3.StringValue("ns3::RealtimeSimulatorImpl"))
|
||||
ns3.GlobalValue.Bind("ChecksumEnabled", ns3.BooleanValue("true"))
|
||||
ns.core.GlobalValue.Bind("SimulatorImplementationType", ns.core.StringValue("ns3::RealtimeSimulatorImpl"))
|
||||
ns.core.GlobalValue.Bind("ChecksumEnabled", ns.core.BooleanValue("true"))
|
||||
|
||||
#
|
||||
# Create two ghost nodes. The first will represent the virtual machine host
|
||||
# on the left side of the network; and the second will represent the VM on
|
||||
# the right side.
|
||||
#
|
||||
nodes = ns3.NodeContainer()
|
||||
nodes = ns.network.NodeContainer()
|
||||
nodes.Create (2);
|
||||
|
||||
#
|
||||
# We're going to use 802.11 A so set up a wifi helper to reflect that.
|
||||
#
|
||||
wifi = ns3.WifiHelper.Default()
|
||||
wifi.SetStandard (ns3.WIFI_PHY_STANDARD_80211a);
|
||||
wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager", "DataMode", ns3.StringValue ("OfdmRate54Mbps"));
|
||||
wifi = ns.wifi.WifiHelper.Default()
|
||||
wifi.SetStandard (ns.wifi.WIFI_PHY_STANDARD_80211a);
|
||||
wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager", "DataMode", ns.core.StringValue ("OfdmRate54Mbps"));
|
||||
|
||||
#
|
||||
# No reason for pesky access points, so we'll use an ad-hoc network.
|
||||
#
|
||||
wifiMac = ns3.NqosWifiMacHelper.Default()
|
||||
wifiMac = ns.wifi.NqosWifiMacHelper.Default()
|
||||
wifiMac.SetType ("ns3::AdhocWifiMac");
|
||||
|
||||
#
|
||||
# Configure the physcial layer.
|
||||
#
|
||||
wifiChannel = ns3.YansWifiChannelHelper.Default()
|
||||
wifiPhy = ns3.YansWifiPhyHelper.Default()
|
||||
wifiChannel = ns.wifi.YansWifiChannelHelper.Default()
|
||||
wifiPhy = ns.wifi.YansWifiPhyHelper.Default()
|
||||
wifiPhy.SetChannel(wifiChannel.Create())
|
||||
|
||||
#
|
||||
@@ -65,10 +70,10 @@ def main(argv):
|
||||
# We need location information since we are talking about wifi, so add a
|
||||
# constant position to the ghost nodes.
|
||||
#
|
||||
mobility = ns3.MobilityHelper()
|
||||
positionAlloc = ns3.ListPositionAllocator()
|
||||
positionAlloc.Add(ns3.Vector(0.0, 0.0, 0.0))
|
||||
positionAlloc.Add(ns3.Vector(5.0, 0.0, 0.0))
|
||||
mobility = ns.mobility.MobilityHelper()
|
||||
positionAlloc = ns.mobility.ListPositionAllocator()
|
||||
positionAlloc.Add(ns.core.Vector(0.0, 0.0, 0.0))
|
||||
positionAlloc.Add(ns.core.Vector(5.0, 0.0, 0.0))
|
||||
mobility.SetPositionAllocator(positionAlloc)
|
||||
mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel")
|
||||
mobility.Install(nodes)
|
||||
@@ -81,24 +86,24 @@ def main(argv):
|
||||
# only see traffic from one other device on that bridge. That is the case
|
||||
# for this configuration.
|
||||
#
|
||||
tapBridge = ns3.TapBridgeHelper()
|
||||
tapBridge.SetAttribute ("Mode", ns3.StringValue ("UseLocal"));
|
||||
tapBridge.SetAttribute ("DeviceName", ns3.StringValue ("tap-left"));
|
||||
tapBridge = ns.tap_bridge.TapBridgeHelper()
|
||||
tapBridge.SetAttribute ("Mode", ns.core.StringValue ("UseLocal"));
|
||||
tapBridge.SetAttribute ("DeviceName", ns.core.StringValue ("tap-left"));
|
||||
tapBridge.Install (nodes.Get (0), devices.Get (0));
|
||||
|
||||
#
|
||||
# Connect the right side tap to the right side wifi device on the right-side
|
||||
# ghost node.
|
||||
#
|
||||
tapBridge.SetAttribute ("DeviceName", ns3.StringValue ("tap-right"));
|
||||
tapBridge.SetAttribute ("DeviceName", ns.core.StringValue ("tap-right"));
|
||||
tapBridge.Install (nodes.Get (1), devices.Get (1));
|
||||
|
||||
#
|
||||
# Run the simulation for ten minutes to give the user time to play around
|
||||
#
|
||||
ns3.Simulator.Stop (ns3.Seconds (600));
|
||||
ns3.Simulator.Run(signal_check_frequency = -1)
|
||||
ns3.Simulator.Destroy()
|
||||
ns.core.Simulator.Stop (ns.core.Seconds (600));
|
||||
ns.core.Simulator.Run(signal_check_frequency = -1)
|
||||
ns.core.Simulator.Destroy()
|
||||
return 0
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
@@ -156,6 +156,7 @@ class Node(PyVizObject):
|
||||
try:
|
||||
ns3_node = ns3.NodeList.GetNode(self.node_index)
|
||||
ipv4 = ns3_node.GetObject(ns3.Ipv4.GetTypeId())
|
||||
ipv6 = ns3_node.GetObject(ns3.Ipv6.GetTypeId())
|
||||
lines = ['<b><u>Node %i</u></b>' % self.node_index]
|
||||
lines.append('')
|
||||
|
||||
@@ -174,6 +175,7 @@ class Node(PyVizObject):
|
||||
lines.append(' <b>Name:</b> %s' % name)
|
||||
devname = dev.GetInstanceTypeId().GetName()
|
||||
lines.append(' <b>Type:</b> %s' % devname)
|
||||
|
||||
if ipv4 is not None:
|
||||
ipv4_idx = ipv4.GetInterfaceForDevice(dev)
|
||||
if ipv4_idx != -1:
|
||||
@@ -182,6 +184,15 @@ class Node(PyVizObject):
|
||||
ipv4.GetAddress(ipv4_idx, i).GetMask())
|
||||
for i in range(ipv4.GetNAddresses(ipv4_idx))]
|
||||
lines.append(' <b>IPv4 Addresses:</b> %s' % '; '.join(addresses))
|
||||
|
||||
if ipv6 is not None:
|
||||
ipv6_idx = ipv6.GetInterfaceForDevice(dev)
|
||||
if ipv6_idx != -1:
|
||||
addresses = [
|
||||
'%s/%s' % (ipv6.GetAddress(ipv6_idx, i).GetAddress(),
|
||||
ipv6.GetAddress(ipv6_idx, i).GetPrefix())
|
||||
for i in range(ipv6.GetNAddresses(ipv4_idx))]
|
||||
lines.append(' <b>IPv6 Addresses:</b> %s' % '; '.join(addresses))
|
||||
|
||||
lines.append(' <b>MAC Address:</b> %s' % (dev.GetAddress(),))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user