24 #include "ns3/arp-l3-protocol.h"
25 #include "ns3/assert.h"
26 #include "ns3/callback.h"
27 #include "ns3/config.h"
28 #include "ns3/core-config.h"
29 #include "ns3/ipv4-click-routing.h"
30 #include "ns3/ipv4-l3-click-protocol.h"
33 #include "ns3/names.h"
34 #include "ns3/net-device.h"
36 #include "ns3/object.h"
37 #include "ns3/packet-socket-factory.h"
38 #include "ns3/simulator.h"
39 #include "ns3/string.h"
40 #include "ns3/trace-helper.h"
50 #define INTERFACE_CONTEXT
82 NS_LOG_INFO(
"Ignoring packet to/from interface " << interface);
117 NS_LOG_INFO(
"Ignoring packet to/from interface " << interface);
155 NS_LOG_INFO(
"Ignoring packet to/from interface " << interface);
161 #ifdef INTERFACE_CONTEXT
163 <<
interface << ") " << *p << std::endl;
171 : m_ipv4Enabled(true)
210 for (
auto i = c.
Begin(); i != c.
End(); ++i)
225 for (
auto i = c.
Begin(); i != c.
End(); ++i)
240 for (
auto i = c.
Begin(); i != c.
End(); ++i)
255 for (
auto i = c.
Begin(); i != c.
End(); ++i)
269 const std::string typeId)
284 NS_FATAL_ERROR(
"ClickInternetStackHelper::Install (): Aggregating "
285 "an InternetStack to a node with an existing Ipv4 object");
303 ipv4Routing->SetClickFile(it->second);
309 ipv4Routing->SetDefines(definesIt->second);
315 ipv4Routing->SetClickRoutingTableElement(it->second);
317 ipv4->SetRoutingProtocol(ipv4Routing);
325 Ptr<Node> node = Names::Find<Node>(nodeName);
334 if ((*i).first.first ==
ipv4)
346 bool explicitFilename)
352 NS_LOG_INFO(
"Call to enable Ipv4 pcap tracing but Ipv4 not enabled");
362 std::string filename;
363 if (explicitFilename)
386 "ClickInternetStackHelper::EnablePcapIpv4Internal(): "
387 "m_ipv4Enabled and ipv4L3Protocol inconsistent");
392 "ClickInternetStackHelper::EnablePcapIpv4Internal(): "
393 "Unable to connect ipv4L3Protocol \"Tx\"");
398 "ClickInternetStackHelper::EnablePcapIpv4Internal(): "
399 "Unable to connect ipv4L3Protocol \"Rx\"");
410 if ((*i).first.first ==
ipv4)
423 bool explicitFilename)
427 NS_LOG_INFO(
"Call to enable Ipv4 ascii tracing but Ipv4 not enabled");
456 std::string filename;
457 if (explicitFilename)
495 "ClickInternetStackHelper::EnableAsciiIpv4Internal(): "
496 "Unable to connect ipv4L3Protocol \"Drop\"");
518 std::ostringstream oss;
526 oss <<
"/NodeList/" << node->
GetId() <<
"/$ns3::ArpL3Protocol/Drop";
535 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.
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.
Ptr< T > GetObject() const
Get a pointer to the requested aggregated Object.
void AggregateObject(Ptr< Object > other)
Aggregate two Objects together.
std::ostream * GetStream()
Return a pointer to an ostream previously set in the wrapper.
void AddHeader(const Header &header)
Add header to this packet.
Ptr< Packet > Copy() const
performs a COW copy of the packet.
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.
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.
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.