26 #include "ns3/simulator.h" 27 #include "ns3/simple-channel.h" 28 #include "ns3/simple-net-device.h" 29 #include "ns3/socket.h" 30 #include "ns3/boolean.h" 31 #include "ns3/double.h" 32 #include "ns3/string.h" 33 #include "ns3/config.h" 34 #include "ns3/data-rate.h" 35 #include "ns3/uinteger.h" 37 #include "ns3/names.h" 40 #include "ns3/inet-socket-address.h" 41 #include "ns3/random-variable-stream.h" 43 #include "ns3/ipv4-l3-protocol.h" 44 #include "ns3/ipv4-static-routing.h" 45 #include "ns3/udp-socket-factory.h" 46 #include "ns3/udp-socket.h" 47 #include "ns3/packet-sink.h" 49 #include "ns3/internet-stack-helper.h" 50 #include "ns3/ipv4-list-routing-helper.h" 51 #include "ns3/ipv4-static-routing-helper.h" 52 #include "ns3/ipv4-address-helper.h" 53 #include "ns3/simple-net-device-helper.h" 54 #include "ns3/packet-sink-helper.h" 55 #include "ns3/on-off-helper.h" 56 #include "ns3/trace-helper.h" 58 #include "ns3/traffic-control-layer.h" 79 main (
int argc,
char *argv[])
82 const std::string targetAddr =
"239.192.100.1";
111 listRouting.Add (staticRouting, 0);
120 ipv4address.
SetBase (
"10.0.0.0",
"255.255.255.0");
124 for (
auto diter =
devices.Begin (); diter !=
devices.End (); ++diter)
141 routing->AddHostRouteTo (targetAddr.c_str (), ipv4->GetInterfaceForDevice (*diter), 0);
153 simplechannel->
BlackList (Names::Find <SimpleNetDevice> (
"A/dev"), Names::Find <SimpleNetDevice> (
"D/dev"));
154 simplechannel->BlackList (Names::Find <SimpleNetDevice> (
"D/dev"), Names::Find <SimpleNetDevice> (
"A/dev"));
156 simplechannel->BlackList (Names::Find <SimpleNetDevice> (
"A/dev"), Names::Find <SimpleNetDevice> (
"E/dev"));
157 simplechannel->BlackList (Names::Find <SimpleNetDevice> (
"E/dev"), Names::Find <SimpleNetDevice> (
"A/dev"));
159 simplechannel->BlackList (Names::Find <SimpleNetDevice> (
"B/dev"), Names::Find <SimpleNetDevice> (
"E/dev"));
160 simplechannel->BlackList (Names::Find <SimpleNetDevice> (
"E/dev"), Names::Find <SimpleNetDevice> (
"B/dev"));
162 simplechannel->BlackList (Names::Find <SimpleNetDevice> (
"C/dev"), Names::Find <SimpleNetDevice> (
"E/dev"));
163 simplechannel->BlackList (Names::Find <SimpleNetDevice> (
"E/dev"), Names::Find <SimpleNetDevice> (
"C/dev"));
169 auto sinks = sinkHelper.Install (
"B");
170 sinks.Add (sinkHelper.Install (
"C"));
171 sinks.Add (sinkHelper.Install (
"D"));
172 sinks.Add (sinkHelper.Install (
"E"));
178 onoffHelper.SetAttribute (
"MaxBytes",
UintegerValue (10 * 1024));
179 auto source = onoffHelper.Install (
"A");
183 for (
auto end =
nodes.End (),
184 iter =
nodes.Begin (); iter != end; ++iter)
186 internet.
EnablePcapIpv4 (
"smf-trace", (*iter)->GetId (), 1,
false);
192 std::cout <<
"Node A sent " << 10 * 1024 <<
" bytes" << std::endl;
193 for (
auto end = sinks.End (),
194 iter = sinks.Begin (); iter != end; ++iter)
196 auto node = (*iter)->GetNode ();
static Ipv4Address GetAny(void)
AttributeValue implementation for Boolean.
NS_ASSERT_MSG(false, "Ipv4AddressGenerator::MaskToIndex(): Impossible")
void SetIpv4ArpJitter(bool enable)
Enable/disable IPv4 ARP Jitter.
void EnablePcapIpv4(std::string prefix, Ptr< Ipv4 > ipv4, uint32_t interface, bool explicitFilename=false)
Enable pcap output the indicated Ipv4 and interface pair.
uint64_t GetTotalRx() const
static void Run(void)
Run the simulation.
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
aggregate IP/TCP/UDP functionality to existing Nodes.
A helper to make it easier to instantiate an ns3::PacketSinkApplication on a set of nodes...
A helper to make it easier to instantiate an ns3::OnOffApplication on a set of nodes.
static void Add(std::string name, Ptr< Object > object)
Add the association between the string "name" and the Ptr<Object> obj.
void AddMulticastRoute(Ptr< Node > n, Ipv4Address source, Ipv4Address group, Ptr< NetDevice > input, NetDeviceContainer output)
Add a multicast route to a node and net device using explicit Ptr<Node> and Ptr<NetDevice> ...
Class for representing data rates.
static void Clear(void)
Clear the list of objects associated with names.
AttributeValue implementation for Time.
Hold an unsigned integer type.
holds a vector of ns3::NetDevice pointers
static void Destroy(void)
Execute the events scheduled with ScheduleDestroy().
Access to the IPv4 forwarding table, interfaces, and configuration.
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
keep track of a set of node pointers.
void Install(std::string nodeName) const
Aggregate implementations of the ns3::Ipv4, ns3::Ipv6, ns3::Udp, and ns3::Tcp classes onto the provid...
Ipv4InterfaceContainer Assign(const NetDeviceContainer &c)
Assign IP addresses to the net devices specified in the container based on the current network prefix...
Helper class that adds ns3::Ipv4StaticRouting objects.
AttributeValue implementation for DataRate.
A simple channel, for simple things and testing.
Time Seconds(double value)
Construct a Time in the indicated unit.
void SetDefault(std::string name, const AttributeValue &value)
static std::string FindName(Ptr< Object > object)
Given a pointer to an object, look to see if that object has a name associated with it and...
Helper class that adds ns3::Ipv4ListRouting objects.
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
build a set of SimpleNetDevice objects
Receive and consume traffic generated to an IP address and port.
void SetRoutingHelper(const Ipv4RoutingHelper &routing)
virtual void BlackList(Ptr< SimpleNetDevice > from, Ptr< SimpleNetDevice > to)
Blocks the communications from a NetDevice to another NetDevice.
void SetIpv6StackInstall(bool enable)
Enable/disable IPv6 stack install.
Ptr< Ipv4StaticRouting > GetStaticRouting(Ptr< Ipv4 > ipv4) const
Try and find the static routing protocol as either the main routing protocol or in the list of routin...
void SetBase(Ipv4Address network, Ipv4Mask mask, Ipv4Address base="0.0.0.1")
Set the base network number, network mask and base address.