13#include "ns3/arp-l3-protocol.h"
14#include "ns3/assert.h"
15#include "ns3/callback.h"
16#include "ns3/config.h"
17#include "ns3/core-config.h"
18#include "ns3/ipv4-click-routing.h"
19#include "ns3/ipv4-l3-click-protocol.h"
23#include "ns3/net-device.h"
25#include "ns3/object.h"
26#include "ns3/packet-socket-factory.h"
27#include "ns3/simulator.h"
28#include "ns3/string.h"
29#include "ns3/trace-helper.h"
39#define INTERFACE_CONTEXT
71 NS_LOG_INFO(
"Ignoring packet to/from interface " << interface);
106 NS_LOG_INFO(
"Ignoring packet to/from interface " << interface);
111 p->AddHeader(header);
144 NS_LOG_INFO(
"Ignoring packet to/from interface " << interface);
149 p->AddHeader(header);
150#ifdef INTERFACE_CONTEXT
152 <<
interface << ") " << *p << std::endl;
160 : m_ipv4Enabled(true)
199 for (
auto i = c.
Begin(); i != c.
End(); ++i)
214 for (
auto i = c.
Begin(); i != c.
End(); ++i)
229 for (
auto i = c.
Begin(); i != c.
End(); ++i)
244 for (
auto i = c.
Begin(); i != c.
End(); ++i)
258 const std::string typeId)
263 node->AggregateObject(protocol);
271 if (node->GetObject<
Ipv4>())
273 NS_FATAL_ERROR(
"ClickInternetStackHelper::Install (): Aggregating "
274 "an InternetStack to a node with an existing Ipv4 object");
284 node->AggregateObject(factory);
292 ipv4Routing->SetClickFile(it->second);
298 ipv4Routing->SetDefines(definesIt->second);
304 ipv4Routing->SetClickRoutingTableElement(it->second);
306 ipv4->SetRoutingProtocol(ipv4Routing);
307 node->AggregateObject(ipv4Routing);
323 if ((*i).first.first == ipv4)
335 bool explicitFilename)
341 NS_LOG_INFO(
"Call to enable Ipv4 pcap tracing but Ipv4 not enabled");
351 std::string filename;
352 if (explicitFilename)
375 "ClickInternetStackHelper::EnablePcapIpv4Internal(): "
376 "m_ipv4Enabled and ipv4L3Protocol inconsistent");
381 "ClickInternetStackHelper::EnablePcapIpv4Internal(): "
382 "Unable to connect ipv4L3Protocol \"Tx\"");
387 "ClickInternetStackHelper::EnablePcapIpv4Internal(): "
388 "Unable to connect ipv4L3Protocol \"Rx\"");
399 if ((*i).first.first == ipv4)
412 bool explicitFilename)
416 NS_LOG_INFO(
"Call to enable Ipv4 ascii tracing but Ipv4 not enabled");
445 std::string filename;
446 if (explicitFilename)
484 "ClickInternetStackHelper::EnableAsciiIpv4Internal(): "
485 "Unable to connect ipv4L3Protocol \"Drop\"");
507 std::ostringstream oss;
515 oss <<
"/NodeList/" << node->GetId() <<
"/$ns3::ArpL3Protocol/Drop";
524 oss <<
"/NodeList/" << node->GetId() <<
"/$ns3::Ipv4L3Protocol/Drop";
An implementation of the ARP protocol.
Manage ASCII trace files for device models.
void HookDefaultDropSinkWithoutContext(Ptr< T > object, std::string traceName, Ptr< OutputStreamWrapper > stream)
Hook a trace source to the default drop operation trace sink that does not accept nor log a trace con...
static void DefaultDropSinkWithContext(Ptr< OutputStreamWrapper > file, std::string context, Ptr< const Packet > p)
Basic Drop default trace sink.
std::string GetFilenameFromInterfacePair(std::string prefix, Ptr< Object > object, uint32_t interface, bool useObjectNames=true)
Let the ascii trace helper figure out a reasonable filename to use for an ascii trace file associated...
Ptr< OutputStreamWrapper > CreateFileStream(std::string filename, std::ios::openmode filemode=std::ios::out)
Create and initialize an output stream object we'll use to write the traced bits.
aggregate Click/IP/TCP/UDP functionality to existing Nodes.
std::map< Ptr< Node >, std::string > m_nodeToClickFileMap
Node to Click file mapping.
~ClickInternetStackHelper() override
Destroy the ClickInternetStackHelper.
ClickInternetStackHelper & operator=(const ClickInternetStackHelper &o)
Assignment operator.
bool PcapHooked(Ptr< Ipv4 > ipv4)
Check if PCAP is hooked.
void SetDefines(NodeContainer c, std::map< std::string, std::string > defines)
Set defines to be used for a group of nodes.
static void CreateAndAggregateObjectFromTypeId(Ptr< Node > node, const std::string typeId)
Create and aggregate object from type ID.
std::map< Ptr< Node >, std::string > m_nodeToRoutingTableElementMap
Node to Routing Table Element mapping.
void Initialize()
Initialize stack helper.
bool m_ipv4Enabled
IPv4 install state (enabled/disabled) ?
void SetClickFile(NodeContainer c, std::string clickfile)
Set a Click file to be used for a group of nodes.
bool AsciiHooked(Ptr< Ipv4 > ipv4)
Check if ASCII is hooked.
ClickInternetStackHelper()
Create a new ClickInternetStackHelper which uses Ipv4ClickRouting for routing.
void SetRoutingTableElement(NodeContainer c, std::string rt)
Set a Click routing table element for a group of nodes.
void InstallAll() const
Aggregate IPv4, UDP, and TCP stacks to all nodes in the simulation.
void Install(std::string nodeName) const
Aggregate implementations of the ns3::Ipv4L3ClickProtocol, ns3::ArpL3Protocol, ns3::Udp,...
void EnablePcapIpv4Internal(std::string prefix, Ptr< Ipv4 > ipv4, uint32_t interface, bool explicitFilename) override
Enable pcap output the indicated Ipv4 and interface pair.
void Reset()
Return helper internal state to that of a newly constructed one.
std::map< Ptr< Node >, std::map< std::string, std::string > > m_nodeToDefinesMap
Node to Click defines mapping.
void EnableAsciiIpv4Internal(Ptr< OutputStreamWrapper > stream, std::string prefix, Ptr< Ipv4 > ipv4, uint32_t interface, bool explicitFilename) override
Enable ascii trace output on the indicated Ipv4 and interface pair.
Access to the IPv4 forwarding table, interfaces, and configuration.
Implement the IPv4 layer.
DropReason
Reason why a packet has been dropped.
static Ptr< T > Find(std::string path)
Given a name path string, look to see if there's an object in the system with that associated to it.
keep track of a set of node pointers.
Iterator End() const
Get an iterator which indicates past-the-last Node in the container.
static NodeContainer GetGlobal()
Create a NodeContainer that contains a list of all nodes created through NodeContainer::Create() and ...
Iterator Begin() const
Get an iterator which refers to the first Node in the container.
bool TraceConnectWithoutContext(std::string name, const CallbackBase &cb)
Connect a TraceSource to a Callback without a context.
Instantiate subclasses of ns3::Object.
Ptr< Object > Create() const
Create an Object instance of the configured TypeId.
void SetTypeId(TypeId tid)
Set the TypeId of the Objects to be created by this factory.
A base class which provides memory management and object aggregation.
static void EnablePrinting()
Enable printing packets metadata.
Manage pcap files for device models.
Ptr< PcapFileWrapper > CreateFile(std::string filename, std::ios::openmode filemode, DataLinkType dataLinkType, uint32_t snapLen=std::numeric_limits< uint32_t >::max(), int32_t tzCorrection=0)
Create and initialize a pcap file.
std::string GetFilenameFromInterfacePair(std::string prefix, Ptr< Object > object, uint32_t interface, bool useObjectNames=true)
Let the pcap helper figure out a reasonable filename to use for the pcap file associated with a node.
Smart pointer class similar to boost::intrusive_ptr.
static Time Now()
Return the current simulation virtual time.
double GetSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
void Connect(std::string path, const CallbackBase &cb)
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
auto MakeBoundCallback(R(*fnPtr)(Args...), BArgs &&... bargs)
Make Callbacks with varying number of bound arguments.
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
std::pair< Ptr< Ipv4 >, uint32_t > InterfacePairIpv4
Ipv4/interface pair.
std::map< InterfacePairIpv4, Ptr< OutputStreamWrapper > > InterfaceStreamMapIpv4
Ipv4/interface and output stream container.
static void Ipv4L3ProtocolDropSinkWithContext(Ptr< OutputStreamWrapper > stream, std::string context, const Ipv4Header &header, Ptr< const Packet > packet, Ipv4L3Protocol::DropReason reason, Ptr< Ipv4 > ipv4, uint32_t interface)
Packet dropped callback with context.
Callback< R, Args... > MakeCallback(R(T::*memPtr)(Args...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
std::map< InterfacePairIpv4, Ptr< PcapFileWrapper > > InterfaceFileMapIpv4
Ipv4/interface and Pcap file wrapper container.
static void Ipv4L3ProtocolRxTxSink(Ptr< const Packet > p, Ptr< Ipv4 > ipv4, uint32_t interface)
IPv4 Rx / Tx packet callback.
static InterfaceFileMapIpv4 g_interfaceFileMapIpv4
A mapping of Ipv4/interface pairs to pcap files.
static InterfaceStreamMapIpv4 g_interfaceStreamMapIpv4
A mapping of Ipv4/interface pairs to ascii streams.
static void Ipv4L3ProtocolDropSinkWithoutContext(Ptr< OutputStreamWrapper > stream, const Ipv4Header &header, Ptr< const Packet > packet, Ipv4L3Protocol::DropReason reason, Ptr< Ipv4 > ipv4, uint32_t interface)
Packet dropped callback without context.