25#include "ns3/arp-l3-protocol.h"
26#include "ns3/ethernet-header.h"
27#include "ns3/icmpv4-l4-protocol.h"
28#include "ns3/ip-l4-protocol.h"
29#include "ns3/ipv4-raw-socket-impl.h"
30#include "ns3/llc-snap-header.h"
31#include "ns3/loopback-net-device.h"
32#include "ns3/net-device.h"
34#include "ns3/object-vector.h"
35#include "ns3/socket.h"
36#include "ns3/uinteger.h"
51 TypeId(
"ns3::Ipv4L3ClickProtocol")
53 .AddConstructor<Ipv4L3ClickProtocol>()
54 .SetGroupName(
"Click")
57 "The TTL value set by default on all outgoing packets generated on this node.",
60 MakeUintegerChecker<uint8_t>())
61 .AddAttribute(
"InterfaceList",
62 "The set of Ipv4 interfaces associated to this Ipv4 stack.",
65 MakeObjectVectorChecker<Ipv4Interface>());
106 Ptr<Node> node = this->GetObject<Node>();
157 for (
uint32_t j = 0; j < (*i)->GetNAddresses(); j++)
159 if ((*i)->GetAddress(j).GetLocal() == address)
177 for (
uint32_t j = 0; j < (*i)->GetNAddresses(); j++)
179 if ((*i)->GetAddress(j).GetLocal().CombineMask(mask) == address.CombineMask(mask))
197 return (*iter).second;
214 NS_LOG_LOGIC(
"For me (destination " << address <<
" match)");
224 if (address.IsMulticast())
227 if (MulticastCheckGroup(iif, address))
235 if (address.IsBroadcast())
255 <<
" match) on another interface");
261 NS_LOG_LOGIC(
"For me (interface broadcast address on another interface)");
277 (*i)->SetForwarding(forward);
330 device = CreateObject<LoopbackNetDevice>();
333 interface->SetDevice(device);
334 interface->SetNode(
m_node);
337 interface->AddAddress(ifaceAddr);
387 bool retVal = interface->AddAddress(address);
388 if (m_routingProtocol)
390 m_routingProtocol->NotifyAddAddress(i, address);
400 return interface->GetAddress(addressIndex);
408 return iface->GetNAddresses();
419 if (m_routingProtocol)
421 m_routingProtocol->NotifyRemoveAddress(i, address);
442 if (m_routingProtocol)
444 m_routingProtocol->NotifyRemoveAddress(i, ifAddr);
469 if (!
test.IsSecondary())
471 return test.GetLocal();
535 NS_LOG_WARN(
"Could not find source address for " << dst <<
" and scope " << scope
545 interface->SetMetric(metric);
553 return interface->GetMetric();
561 return interface->GetDevice()->GetMtu();
569 return interface->IsUp();
579 if (m_routingProtocol)
581 m_routingProtocol->NotifyInterfaceUp(i);
590 interface->SetDown();
592 if (m_routingProtocol)
594 m_routingProtocol->NotifyInterfaceDown(ifaceIndex);
603 NS_LOG_LOGIC(
"Forwarding state: " << interface->IsForwarding());
604 return interface->IsForwarding();
612 interface->SetForwarding(val);
643 interface->SetDevice(device);
665 uint16_t payloadSize,
706 bool mayFragment =
true;
709 bool found = packet->RemovePacketTag(tag);
715 ipHeader =
BuildHeader(source, destination, protocol, packet->GetSize(), ttl, mayFragment);
721 packet->AddHeader(ipHeader);
722 click->Send(packet->Copy(), source, destination);
735 packet->AddHeader(ipHeader);
752 p->RemoveHeader(header);
759 p->RemoveHeader(llc);
788 int32_t interface = GetInterfaceForDevice(device);
790 "Received a packet from an interface that is not known to IPv4");
792 if (!ipv4Interface->IsUp())
794 NS_LOG_LOGIC(
"Dropping received packet -- interface is down");
799 if (Node::ChecksumEnabled())
803 packetForRawSocket->RemoveHeader(ipHeader);
805 for (
auto i = m_sockets.begin(); i != m_sockets.end(); ++i)
809 socket->ForwardUp(packetForRawSocket, ipHeader, ipv4Interface);
821 packet->AddHeader(hdr);
824 click->Receive(packet->Copy(),
858 bool subnetDirected =
false;
866 subnetDirected =
true;
871 GetIcmp()->SendDestUnreachPort(ip, copy);
895 L4ListKey_t key = std::make_pair(protocol->GetProtocolNumber(), -1);
898 NS_LOG_WARN(
"Overwriting default protocol " <<
int(protocol->GetProtocolNumber()));
908 L4ListKey_t key = std::make_pair(protocol->GetProtocolNumber(), interfaceIndex);
911 NS_LOG_WARN(
"Overwriting protocol " <<
int(protocol->GetProtocolNumber())
912 <<
" on interface " <<
int(interfaceIndex));
922 L4ListKey_t key = std::make_pair(protocol->GetProtocolNumber(), -1);
926 NS_LOG_WARN(
"Trying to remove an non-existent default protocol "
927 <<
int(protocol->GetProtocolNumber()));
940 L4ListKey_t key = std::make_pair(protocol->GetProtocolNumber(), interfaceIndex);
944 NS_LOG_WARN(
"Trying to remove an non-existent protocol "
945 <<
int(protocol->GetProtocolNumber()) <<
" on interface "
946 <<
int(interfaceIndex));
968 if (interfaceIndex >= 0)
971 key = std::make_pair(protocolNumber, interfaceIndex);
979 key = std::make_pair(protocolNumber, -1);
a polymophic address class
static const uint16_t PROT_NUMBER
ARP protocol number (0x0806)
This is the implementation of the ICMP protocol as described in RFC 792.
static uint16_t GetStaticProtocolNumber()
Get the protocol number.
Ipv4 addresses are stored in host order in this class.
static Ipv4Address GetLoopback()
bool IsSubnetDirectedBroadcast(const Ipv4Mask &mask) const
Generate subnet-directed broadcast address corresponding to mask.
Ipv4Address CombineMask(const Ipv4Mask &mask) const
Combine this address with a network mask.
Access to the IPv4 forwarding table, interfaces, and configuration.
a class to store IPv4 address information on an interface
Ipv4Mask GetMask() const
Get the network mask.
InterfaceAddressScope_e
Address scope.
Ipv4InterfaceAddress::InterfaceAddressScope_e GetScope() const
Get address scope.
Ipv4Address GetLocal() const
Get the local address.
bool IsSecondary() const
Check if the address is a secondary address.
Ipv4Address GetBroadcast() const
Get the broadcast address.
The IPv4 representation of a network interface.
void SetNode(Ptr< Node > node)
Set node associated with interface.
Ptr< NetDevice > GetDevice() const
L4List_t m_protocols
List of IPv4 L4 protocols.
void SetPromisc(uint32_t i)
Sets an interface to run on promiscuous mode.
bool m_weakEsModel
Whether to use weak Es model.
uint32_t AddIpv4Interface(Ptr< Ipv4Interface > interface)
Adds an Ipv4Interface to the interfaces list.
Ipv4Header BuildHeader(Ipv4Address source, Ipv4Address destination, uint8_t protocol, uint16_t payloadSize, uint8_t ttl, bool mayFragment)
Build IPv4 header.
bool GetIpForward() const override
Get the IP forwarding state.
std::pair< int, int32_t > L4ListKey_t
Container of the IPv4 L4 keys: protocol number, interface index.
Ptr< Ipv4Interface > GetInterface(uint32_t i) const
Get a pointer to the i'th Ipv4Interface.
Ipv4InterfaceReverseContainer m_reverseInterfacesContainer
Container of NetDevice / Interface index associations.
TracedCallback< const Ipv4Header &, Ptr< const Packet >, uint32_t > m_localDeliverTrace
void LocalDeliver(Ptr< const Packet > p, const Ipv4Header &ip, uint32_t iif)
Ipv4ClickRouting calls this to locally deliver a packet.
bool RemoveAddress(uint32_t interfaceIndex, uint32_t addressIndex) override
Remove the address at addressIndex on named interface.
void Receive(Ptr< NetDevice > device, Ptr< const Packet > p, uint16_t protocol, const Address &from, const Address &to, NetDevice::PacketType packetType)
Lower layer calls this method to send a packet to Click.
SocketList m_sockets
List of sockets.
bool IsForwarding(uint32_t i) const override
uint32_t GetNAddresses(uint32_t interface) const override
uint16_t GetMtu(uint32_t i) const override
Ptr< Ipv4RoutingProtocol > m_routingProtocol
IPv4 routing protocol.
Ptr< Socket > CreateRawSocket() override
Creates a raw-socket.
static TypeId GetTypeId()
Get Type ID.
void Remove(Ptr< IpL4Protocol > protocol) override
int32_t GetInterfaceForDevice(Ptr< const NetDevice > device) const override
void SetIpForward(bool forward) override
Set or unset the IP forwarding state.
~Ipv4L3ClickProtocol() override
void SetUp(uint32_t i) override
Ptr< Ipv4RoutingProtocol > GetRoutingProtocol() const override
Get the routing protocol to be used by this Ipv4 stack.
void SetupLoopback()
Sets up a Loopback device.
void SetMetric(uint32_t i, uint16_t metric) override
Ipv4Address SourceAddressSelection(uint32_t interface, Ipv4Address dest) override
Choose the source address to use with destination address.
Ipv4InterfaceList m_interfaces
List of interfaces.
void NotifyNewAggregate() override
This function will notify other components connected to the node that a new stack member is now conne...
Ipv4InterfaceAddress GetAddress(uint32_t interfaceIndex, uint32_t addressIndex) const override
Because addresses can be removed, the addressIndex is not guaranteed to be static across calls to thi...
uint32_t GetNInterfaces() const override
void Send(Ptr< Packet > packet, Ipv4Address source, Ipv4Address destination, uint8_t protocol, Ptr< Ipv4Route > route) override
bool IsUp(uint32_t i) const override
Ptr< NetDevice > GetNetDevice(uint32_t i) override
int32_t GetInterfaceForAddress(Ipv4Address addr) const override
Return the interface number of the interface that has been assigned the specified IP address.
void Insert(Ptr< IpL4Protocol > protocol) override
void SetDown(uint32_t i) override
Ptr< IpL4Protocol > GetProtocol(int protocolNumber) const override
void SetWeakEsModel(bool model) override
Set or unset the Weak Es Model.
bool AddAddress(uint32_t i, Ipv4InterfaceAddress address) override
uint32_t AddInterface(Ptr< NetDevice > device) override
void SetNode(Ptr< Node > node)
Calls m_node = node and sets up Loopback if needed.
void DoDispose() override
Destructor implementation.
void DeleteRawSocket(Ptr< Socket > socket) override
Deletes a particular raw socket.
static const uint16_t PROT_NUMBER
Protocol number for Ipv4 L3 (0x0800).
uint16_t m_identification
Identification.
uint16_t GetMetric(uint32_t i) const override
bool IsDestinationAddress(Ipv4Address address, uint32_t iif) const override
Determine whether address and interface corresponding to received packet can be accepted for local de...
void SendDown(Ptr< Packet > packet, int ifid)
Ptr< Icmpv4L4Protocol > GetIcmp() const
Returns the Icmpv4L4Protocol for the node.
bool GetWeakEsModel() const override
Get the Weak Es Model status.
void SendWithHeader(Ptr< Packet > packet, Ipv4Header ipHeader, Ptr< Ipv4Route > route) override
void SetRoutingProtocol(Ptr< Ipv4RoutingProtocol > routingProtocol) override
Register a new routing protocol to be used by this Ipv4 stack.
bool m_ipForward
Whether IP forwarding is enabled.
uint8_t m_defaultTtl
Default TTL.
int32_t GetInterfaceForPrefix(Ipv4Address addr, Ipv4Mask mask) const override
Return the interface number of first interface found that has an Ipv4 address within the prefix speci...
void SetForwarding(uint32_t i, bool val) override
Ipv4Address SelectSourceAddress(Ptr< const NetDevice > device, Ipv4Address dst, Ipv4InterfaceAddress::InterfaceAddressScope_e scope) override
Return the first primary source address with scope less than or equal to the requested scope,...
void SetDefaultTtl(uint8_t ttl)
a class to represent an Ipv4 address mask
static Ipv4Mask GetLoopback()
static Mac48Address ConvertFrom(const Address &address)
PacketType
Packet types are used as they are in Linux.
uint32_t AddDevice(Ptr< NetDevice > device)
Associate a NetDevice to this node.
uint32_t GetNDevices() const
Ptr< NetDevice > GetDevice(uint32_t index) const
Retrieve the index-th NetDevice associated to this node.
static bool ChecksumEnabled()
virtual void NotifyNewAggregate()
Notify all Objects aggregated to this one of a new Object being aggregated.
virtual void DoDispose()
Destructor implementation.
Smart pointer class similar to boost::intrusive_ptr.
This class implements a tag that carries the socket-specific TTL of a packet to the IP layer.
uint8_t GetTtl() const
Get the tag's TTL.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Hold an unsigned integer type.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
ObjectPtrContainerValue ObjectVectorValue
ObjectVectorValue is an alias for ObjectPtrContainerValue.
Ptr< const AttributeAccessor > MakeObjectVectorAccessor(U T::*memberVariable)
MakeAccessorHelper implementation for ObjectVector.
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
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...
-ns3 Test suite for the ns3 wrapper script