14#include "ns3/arp-l3-protocol.h"
15#include "ns3/ethernet-header.h"
16#include "ns3/icmpv4-l4-protocol.h"
17#include "ns3/ip-l4-protocol.h"
18#include "ns3/ipv4-raw-socket-impl.h"
19#include "ns3/llc-snap-header.h"
20#include "ns3/loopback-net-device.h"
21#include "ns3/net-device.h"
23#include "ns3/object-vector.h"
24#include "ns3/socket.h"
25#include "ns3/uinteger.h"
40 TypeId(
"ns3::Ipv4L3ClickProtocol")
42 .AddConstructor<Ipv4L3ClickProtocol>()
43 .SetGroupName(
"Click")
46 "The TTL value set by default on all outgoing packets generated on this node.",
50 .AddAttribute(
"InterfaceList",
51 "The set of Ipv4 interfaces associated to this Ipv4 stack.",
146 for (
uint32_t j = 0; j < (*i)->GetNAddresses(); j++)
148 if ((*i)->GetAddress(j).GetLocal() == address)
166 for (
uint32_t j = 0; j < (*i)->GetNAddresses(); j++)
168 if ((*i)->GetAddress(j).GetLocal().CombineMask(mask) == address.CombineMask(mask))
186 return (*iter).second;
203 NS_LOG_LOGIC(
"For me (destination " << address <<
" match)");
213 if (address.IsMulticast())
216 if (MulticastCheckGroup(iif, address))
224 if (address.IsBroadcast())
244 <<
" match) on another interface");
250 NS_LOG_LOGIC(
"For me (interface broadcast address on another interface)");
266 (*i)->SetForwarding(forward);
334 interface->SetDevice(device);
335 interface->SetNode(
m_node);
338 interface->AddAddress(ifaceAddr);
388 bool retVal = interface->AddAddress(address);
389 if (m_routingProtocol)
391 m_routingProtocol->NotifyAddAddress(i, address);
401 return interface->GetAddress(addressIndex);
409 return iface->GetNAddresses();
420 if (m_routingProtocol)
422 m_routingProtocol->NotifyRemoveAddress(i, address);
443 if (m_routingProtocol)
445 m_routingProtocol->NotifyRemoveAddress(i, ifAddr);
470 if (!
test.IsSecondary())
472 return test.GetLocal();
536 NS_LOG_WARN(
"Could not find source address for " << dst <<
" and scope " << scope
546 interface->SetMetric(metric);
554 return interface->GetMetric();
562 return interface->GetDevice()->GetMtu();
570 return interface->IsUp();
580 if (m_routingProtocol)
582 m_routingProtocol->NotifyInterfaceUp(i);
591 interface->SetDown();
593 if (m_routingProtocol)
595 m_routingProtocol->NotifyInterfaceDown(ifaceIndex);
604 NS_LOG_LOGIC(
"Forwarding state: " << interface->IsForwarding());
605 return interface->IsForwarding();
613 interface->SetForwarding(val);
644 interface->SetDevice(device);
666 uint16_t payloadSize,
707 bool mayFragment =
true;
710 bool found = packet->RemovePacketTag(tag);
716 ipHeader =
BuildHeader(source, destination, protocol, packet->GetSize(), ttl, mayFragment);
722 packet->AddHeader(ipHeader);
723 click->Send(packet->Copy(), source, destination);
736 packet->AddHeader(ipHeader);
753 p->RemoveHeader(header);
760 p->RemoveHeader(llc);
789 int32_t interface = GetInterfaceForDevice(device);
791 "Received a packet from an interface that is not known to IPv4");
793 if (!ipv4Interface->IsUp())
795 NS_LOG_LOGIC(
"Dropping received packet -- interface is down");
800 if (Node::ChecksumEnabled())
804 packetForRawSocket->RemoveHeader(ipHeader);
806 for (
auto i = m_sockets.begin(); i != m_sockets.end(); ++i)
810 socket->ForwardUp(packetForRawSocket, ipHeader, ipv4Interface);
822 packet->AddHeader(hdr);
825 click->Receive(packet->Copy(),
859 bool subnetDirected =
false;
867 subnetDirected =
true;
872 GetIcmp()->SendDestUnreachPort(ip, copy);
896 L4ListKey_t key = std::make_pair(protocol->GetProtocolNumber(), -1);
899 NS_LOG_WARN(
"Overwriting default protocol " <<
int(protocol->GetProtocolNumber()));
909 L4ListKey_t key = std::make_pair(protocol->GetProtocolNumber(), interfaceIndex);
912 NS_LOG_WARN(
"Overwriting protocol " <<
int(protocol->GetProtocolNumber())
913 <<
" on interface " <<
int(interfaceIndex));
923 L4ListKey_t key = std::make_pair(protocol->GetProtocolNumber(), -1);
927 NS_LOG_WARN(
"Trying to remove an non-existent default protocol "
928 <<
int(protocol->GetProtocolNumber()));
941 L4ListKey_t key = std::make_pair(protocol->GetProtocolNumber(), interfaceIndex);
945 NS_LOG_WARN(
"Trying to remove an non-existent protocol "
946 <<
int(protocol->GetProtocolNumber()) <<
" on interface "
947 <<
int(interfaceIndex));
969 if (interfaceIndex >= 0)
972 key = std::make_pair(protocolNumber, interfaceIndex);
980 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.
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.
void SetStrongEndSystemModel(bool model) override
Set or unset the Strong End System Model.
~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
bool m_strongEndSystemModel
Whether to use Strong End System Model.
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
bool GetStrongEndSystemModel() const override
Get the Strong End System Model status.
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.
Ptr< T > GetObject() const
Get a pointer to the requested aggregated Object.
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...
#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.
Ptr< const AttributeChecker > MakeUintegerChecker()
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...
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Ptr< const AttributeChecker > MakeObjectVectorChecker()
ObjectPtrContainerValue ObjectVectorValue
ObjectVectorValue is an alias for ObjectPtrContainerValue.
Ptr< const AttributeAccessor > MakeObjectVectorAccessor(U T::*memberVariable)
MakeAccessorHelper implementation for ObjectVector.
Ptr< T1 > DynamicCast(const Ptr< T2 > &p)
Cast a Ptr.
-ns3 Test suite for the ns3 wrapper script