21 #include "ns3/packet.h"
23 #include "ns3/callback.h"
24 #include "ns3/ipv4-address.h"
25 #include "ns3/ipv4-route.h"
27 #include "ns3/socket.h"
28 #include "ns3/net-device.h"
29 #include "ns3/uinteger.h"
30 #include "ns3/trace-source-accessor.h"
31 #include "ns3/object-vector.h"
32 #include "ns3/ipv4-header.h"
33 #include "ns3/boolean.h"
34 #include "ns3/ipv4-routing-table-entry.h"
36 #include "loopback-net-device.h"
37 #include "arp-l3-protocol.h"
38 #include "ipv4-l3-protocol.h"
39 #include "icmpv4-l4-protocol.h"
40 #include "ipv4-interface.h"
41 #include "ipv4-raw-socket-impl.h"
47 const uint16_t Ipv4L3Protocol::PROT_NUMBER = 0x0800;
49 NS_OBJECT_ENSURE_REGISTERED (Ipv4L3Protocol);
52 Ipv4L3Protocol::GetTypeId (
void)
54 static TypeId tid = TypeId (
"ns3::Ipv4L3Protocol")
56 .AddConstructor<Ipv4L3Protocol> ()
57 .AddAttribute (
"DefaultTos",
"The TOS value set by default on all outgoing packets generated on this node.",
59 MakeUintegerAccessor (&Ipv4L3Protocol::m_defaultTos),
60 MakeUintegerChecker<uint8_t> ())
61 .AddAttribute (
"DefaultTtl",
"The TTL value set by default on all outgoing packets generated on this node.",
63 MakeUintegerAccessor (&Ipv4L3Protocol::m_defaultTtl),
64 MakeUintegerChecker<uint8_t> ())
65 .AddAttribute (
"FragmentExpirationTimeout",
66 "When this timeout expires, the fragments will be cleared from the buffer.",
68 MakeTimeAccessor (&Ipv4L3Protocol::m_fragmentExpirationTimeout),
70 .AddTraceSource (
"Tx",
"Send ipv4 packet to outgoing interface.",
72 .AddTraceSource (
"Rx",
"Receive ipv4 packet from incoming interface.",
74 .AddTraceSource (
"Drop",
"Drop ipv4 packet",
76 .AddAttribute (
"InterfaceList",
"The set of Ipv4 interfaces associated to this Ipv4 stack.",
78 MakeObjectVectorAccessor (&Ipv4L3Protocol::m_interfaces),
79 MakeObjectVectorChecker<Ipv4Interface> ())
81 .AddTraceSource (
"SendOutgoing",
"A newly-generated packet by this node is about to be queued for transmission",
83 .AddTraceSource (
"UnicastForward",
"A unicast IPv4 packet was received by this node and is being forwarded to another node",
85 .AddTraceSource (
"LocalDeliver",
"An IPv4 packet was received by/for this node, and it is being forward up the stack",
92 Ipv4L3Protocol::Ipv4L3Protocol()
93 : m_identification (0)
99 Ipv4L3Protocol::~Ipv4L3Protocol ()
108 m_protocols.push_back (protocol);
114 for (L4List_t::const_iterator i = m_protocols.begin (); i != m_protocols.end (); ++i)
116 if ((*i)->GetProtocolNumber () == protocolNumber)
127 m_protocols.remove (protocol);
144 socket->SetNode (m_node);
145 m_sockets.push_back (socket);
152 for (SocketList::iterator i = m_sockets.begin (); i != m_sockets.end (); ++i)
177 this->SetNode (node);
187 m_routingProtocol = routingProtocol;
188 m_routingProtocol->SetIpv4 (
this);
196 return m_routingProtocol;
203 for (L4List_t::iterator i = m_protocols.begin (); i != m_protocols.end (); ++i)
207 m_protocols.clear ();
209 for (Ipv4InterfaceList::iterator i = m_interfaces.begin (); i != m_interfaces.end (); ++i)
213 m_interfaces.clear ();
216 m_routingProtocol = 0;
223 for (MapFragmentsTimers_t::iterator it = m_fragmentsTimers.begin (); it != m_fragmentsTimers.end (); it++)
225 if (it->second.IsRunning ())
227 it->second.Cancel ();
232 m_fragmentsTimers.clear ();
238 Ipv4L3Protocol::SetupLoopback (
void)
245 for (uint32_t i = 0; i < m_node->
GetNDevices (); i++)
247 if ((device = DynamicCast<LoopbackNetDevice> (m_node->
GetDevice (i))))
254 device = CreateObject<LoopbackNetDevice> ();
257 interface->SetDevice (device);
258 interface->SetNode (m_node);
260 interface->AddAddress (ifaceAddr);
261 uint32_t index = AddIpv4Interface (interface);
262 Ptr<Node> node = GetObject<Node> ();
264 Ipv4L3Protocol::PROT_NUMBER, device);
266 if (m_routingProtocol != 0)
268 m_routingProtocol->NotifyInterfaceUp (index);
286 Ipv4L3Protocol::PROT_NUMBER, device);
288 ArpL3Protocol::PROT_NUMBER, device);
291 interface->SetNode (m_node);
292 interface->SetDevice (device);
293 interface->SetForwarding (m_ipForward);
294 return AddIpv4Interface (interface);
301 uint32_t index = m_interfaces.size ();
302 m_interfaces.push_back (interface);
307 Ipv4L3Protocol::GetInterface (uint32_t index)
const
310 if (index < m_interfaces.size ())
312 return m_interfaces[index];
321 return m_interfaces.size ();
329 int32_t
interface = 0;
330 for (Ipv4InterfaceList::const_iterator i = m_interfaces.begin ();
331 i != m_interfaces.end ();
334 for (uint32_t j = 0; j < (*i)->GetNAddresses (); j++)
336 if ((*i)->GetAddress (j).GetLocal () == address)
352 int32_t
interface = 0;
353 for (Ipv4InterfaceList::const_iterator i = m_interfaces.begin ();
354 i != m_interfaces.end ();
357 for (uint32_t j = 0; j < (*i)->GetNAddresses (); j++)
359 if ((*i)->GetAddress (j).GetLocal ().CombineMask (mask) == address.
CombineMask (mask))
374 int32_t
interface = 0;
375 for (Ipv4InterfaceList::const_iterator i = m_interfaces.begin ();
376 i != m_interfaces.end ();
379 if ((*i)->GetDevice () == device)
396 if (address == iaddr.GetLocal ())
398 NS_LOG_LOGIC (
"For me (destination " << address <<
" match)");
401 if (address == iaddr.GetBroadcast ())
411 if (MulticastCheckGroup (iif, address ))
426 if (GetWeakEsModel ())
430 if (j == uint32_t (iif))
continue;
434 if (address == iaddr.GetLocal ())
436 NS_LOG_LOGIC (
"For me (destination " << address <<
" match) on another interface");
440 if (address == iaddr.GetBroadcast ())
442 NS_LOG_LOGIC (
"For me (interface broadcast address on another interface)");
455 NS_LOG_FUNCTION (
this << device << p << protocol << from << to << packetType);
457 NS_LOG_LOGIC (
"Packet from " << from <<
" received on node " <<
458 m_node->
GetId () <<
" on device: " << device->GetAddress());
460 uint32_t
interface = 0;
464 for (Ipv4InterfaceList::const_iterator i = m_interfaces.begin ();
465 i != m_interfaces.end ();
469 if (ipv4Interface->
GetDevice () == device)
471 if (ipv4Interface->
IsUp ())
478 NS_LOG_LOGIC (
"Dropping received packet -- interface is down");
480 packet->RemoveHeader (ipHeader);
492 packet->RemoveHeader (ipHeader);
497 packet->RemoveAtEnd (packet->GetSize () - ipHeader.
GetPayloadSize ());
502 NS_LOG_LOGIC (
"Dropping received packet -- checksum not ok");
507 for (SocketList::iterator i = m_sockets.begin (); i != m_sockets.end (); ++i)
511 socket->ForwardUp (packet, ipHeader, ipv4Interface);
514 NS_ASSERT_MSG (m_routingProtocol != 0,
"Need a routing protocol object to process packets");
515 if (!m_routingProtocol->RouteInput (packet, ipHeader, device,
517 MakeCallback (&Ipv4L3Protocol::IpMulticastForward,
this),
522 NS_LOG_WARN (
"No route found for forwarding packet. Drop.");
559 SendRealOut (route, packet, ipHeader);
569 NS_LOG_FUNCTION (
this << packet << source << destination << uint32_t (protocol) << route);
572 bool mayFragment =
true;
573 uint8_t ttl = m_defaultTtl;
581 uint8_t tos = m_defaultTos;
586 tos = ipTosTag.GetTos ();
599 NS_LOG_LOGIC (
"Ipv4L3Protocol::Send case 1: limited broadcast");
600 ipHeader = BuildHeader (source, destination, protocol, packet->
GetSize (), ttl, tos, mayFragment);
601 uint32_t ifaceIndex = 0;
602 for (Ipv4InterfaceList::iterator ifaceIter = m_interfaces.begin ();
603 ifaceIter != m_interfaces.end (); ifaceIter++, ifaceIndex++)
610 m_sendOutgoingTrace (ipHeader, packetCopy, ifaceIndex);
612 m_txTrace (packetCopy, m_node->
GetObject<
Ipv4> (), ifaceIndex);
613 outInterface->
Send (packetCopy, destination);
619 uint32_t ifaceIndex = 0;
620 for (Ipv4InterfaceList::iterator ifaceIter = m_interfaces.begin ();
621 ifaceIter != m_interfaces.end (); ifaceIter++, ifaceIndex++)
627 NS_LOG_LOGIC (
"Testing address " << ifAddr.GetLocal () <<
" with mask " << ifAddr.GetMask ());
631 NS_LOG_LOGIC (
"Ipv4L3Protocol::Send case 2: subnet directed bcast to " << ifAddr.GetLocal ());
632 ipHeader = BuildHeader (source, destination, protocol, packet->
GetSize (), ttl, tos, mayFragment);
634 m_sendOutgoingTrace (ipHeader, packetCopy, ifaceIndex);
635 packetCopy->AddHeader (ipHeader);
636 m_txTrace (packetCopy, m_node->
GetObject<
Ipv4> (), ifaceIndex);
637 outInterface->
Send (packetCopy, destination);
647 NS_LOG_LOGIC (
"Ipv4L3Protocol::Send case 3: passed in with route");
648 ipHeader = BuildHeader (source, destination, protocol, packet->
GetSize (), ttl, tos, mayFragment);
650 m_sendOutgoingTrace (ipHeader, packet, interface);
653 NS_LOG_LOGIC (
"Node[" << m_node->
GetId() <<
"] is sending to channel: " << cbt.GetChannel() <<
" on RX");
654 SendRealOut (route, packet->
Copy (), ipHeader);
664 NS_FATAL_ERROR (
"Ipv4L3Protocol::Send case 4: This case not yet implemented");
667 NS_LOG_LOGIC (
"Ipv4L3Protocol::Send case 5: passed in with no route " << destination);
668 Socket::SocketErrno errno_;
670 ipHeader = BuildHeader (source, destination, protocol, packet->
GetSize (), ttl, tos, mayFragment);
672 if (m_routingProtocol != 0)
674 newRoute = m_routingProtocol->RouteOutput (packet, ipHeader, oif, errno_);
678 NS_LOG_ERROR (
"Ipv4L3Protocol::Send: m_routingProtocol == 0");
683 m_sendOutgoingTrace (ipHeader, packet, interface);
684 SendRealOut (newRoute, packet->
Copy (), ipHeader);
697 Ipv4L3Protocol::BuildHeader (
701 uint16_t payloadSize,
706 NS_LOG_FUNCTION (
this << source << destination << (uint16_t)protocol << payloadSize << (uint16_t)ttl << (uint16_t)tos << mayFragment);
714 if (mayFragment ==
true)
735 Ipv4L3Protocol::SendRealOut (Ptr<Ipv4Route> route,
737 Ipv4Header
const &ipHeader)
746 packet->AddHeader (ipHeader);
747 Ptr<NetDevice> outDev = route->GetOutputDevice ();
748 int32_t
interface = GetInterfaceForDevice (outDev);
750 Ptr<Ipv4Interface> outInterface = GetInterface (interface);
751 NS_LOG_LOGIC (
"Send via NetDevice ifIndex " << outDev->GetIfIndex () <<
" ipv4InterfaceIndex " << interface);
753 if (!route->GetGateway ().IsEqual (Ipv4Address (
"0.0.0.0")))
755 if (outInterface->IsUp ())
757 NS_LOG_LOGIC (
"Send to gateway " << route->GetGateway ());
758 if ( packet->GetSize () > outInterface->GetDevice ()->GetMtu () )
760 std::list<Ptr<Packet> > listFragments;
761 DoFragmentation (packet, outInterface->GetDevice ()->GetMtu (), listFragments);
762 for ( std::list<Ptr<Packet> >::iterator it = listFragments.begin (); it != listFragments.end (); it++ )
764 m_txTrace (*it, m_node->GetObject<Ipv4> (), interface);
765 outInterface->Send (*it, route->GetGateway ());
770 m_txTrace (packet, m_node->GetObject<Ipv4> (), interface);
771 outInterface->Send (packet, route->GetGateway ());
776 NS_LOG_LOGIC (
"Dropping -- outgoing interface is down: " << route->GetGateway ());
778 packet->RemoveHeader (ipHeader);
779 m_dropTrace (ipHeader, packet,
DROP_INTERFACE_DOWN, m_node->GetObject<Ipv4> (), interface);
784 if (outInterface->IsUp ())
786 NS_LOG_LOGIC (
"Send to destination " << ipHeader.GetDestination ());
787 if ( packet->GetSize () > outInterface->GetDevice ()->GetMtu () )
789 std::list<Ptr<Packet> > listFragments;
790 DoFragmentation (packet, outInterface->GetDevice ()->GetMtu (), listFragments);
791 for ( std::list<Ptr<Packet> >::iterator it = listFragments.begin (); it != listFragments.end (); it++ )
794 m_txTrace (*it, m_node->GetObject<Ipv4> (), interface);
795 outInterface->Send (*it, ipHeader.GetDestination ());
800 m_txTrace (packet, m_node->GetObject<Ipv4> (), interface);
801 outInterface->Send (packet, ipHeader.GetDestination ());
806 NS_LOG_LOGIC (
"Dropping -- outgoing interface is down: " << ipHeader.GetDestination ());
808 packet->RemoveHeader (ipHeader);
809 m_dropTrace (ipHeader, packet,
DROP_INTERFACE_DOWN, m_node->GetObject<Ipv4> (), interface);
816 Ipv4L3Protocol::IpMulticastForward (Ptr<Ipv4MulticastRoute> mrtentry, Ptr<const Packet> p,
const Ipv4Header &header)
821 std::map<uint32_t, uint32_t> ttlMap = mrtentry->GetOutputTtlMap ();
822 std::map<uint32_t, uint32_t>::iterator mapIter;
824 for (mapIter = ttlMap.begin (); mapIter != ttlMap.end (); mapIter++)
826 uint32_t interfaceId = mapIter->first;
829 Ptr<Packet> packet = p->Copy ();
830 Ipv4Header h = header;
831 h.SetTtl (header.GetTtl () - 1);
832 if (h.GetTtl () == 0)
838 NS_LOG_LOGIC (
"Forward multicast via interface " << interfaceId);
839 Ptr<Ipv4Route> rtentry = Create<Ipv4Route> ();
840 rtentry->SetSource (h.GetSource ());
841 rtentry->SetDestination (h.GetDestination ());
844 SendRealOut (rtentry, packet, h);
851 Ipv4L3Protocol::IpForward (Ptr<Ipv4Route> rtentry, Ptr<const Packet> p,
const Ipv4Header &header)
856 Ipv4Header ipHeader = header;
857 Ptr<Packet> packet = p->Copy ();
859 ipHeader.SetTtl (ipHeader.GetTtl () - 1);
860 if (ipHeader.GetTtl () == 0)
863 if (ipHeader.GetProtocol () != Icmpv4L4Protocol::PROT_NUMBER &&
864 ipHeader.GetDestination ().IsBroadcast () ==
false &&
865 ipHeader.GetDestination ().IsMulticast () ==
false)
867 Ptr<Icmpv4L4Protocol> icmp =
GetIcmp ();
868 icmp->SendTimeExceededTtl (ipHeader, packet);
874 m_unicastForwardTrace (ipHeader, packet, interface);
875 SendRealOut (rtentry, packet, ipHeader);
879 Ipv4L3Protocol::LocalDeliver (Ptr<const Packet> packet, Ipv4Header
const&ip, uint32_t iif)
882 Ptr<Packet> p = packet->Copy ();
883 Ipv4Header ipHeader = ip;
885 if ( !ipHeader.IsLastFragment () || ipHeader.GetFragmentOffset () != 0 )
887 NS_LOG_LOGIC (
"Received a fragment, processing " << *p );
888 bool isPacketComplete;
890 if ( isPacketComplete ==
false)
894 NS_LOG_LOGIC (
"Got last fragment, Packet is complete " << *p );
897 m_localDeliverTrace (ip, packet, iif);
899 Ptr<IpL4Protocol> protocol =
GetProtocol (ip.GetProtocol ());
904 Ptr<Packet> copy = p->Copy ();
905 enum IpL4Protocol::RxStatus status =
906 protocol->
Receive (p, ip, GetInterface (iif));
908 case IpL4Protocol::RX_OK:
910 case IpL4Protocol::RX_ENDPOINT_CLOSED:
912 case IpL4Protocol::RX_CSUM_FAILED:
914 case IpL4Protocol::RX_ENDPOINT_UNREACH:
915 if (ip.GetDestination ().IsBroadcast () ==
true ||
916 ip.GetDestination ().IsMulticast () ==
true)
921 bool subnetDirected =
false;
924 Ipv4InterfaceAddress addr =
GetAddress (iif, i);
925 if (addr.GetLocal ().CombineMask (addr.GetMask ()) == ip.GetDestination ().CombineMask (addr.GetMask ()) &&
926 ip.GetDestination ().IsSubnetDirectedBroadcast (addr.GetMask ()))
928 subnetDirected =
true;
931 if (subnetDirected ==
false)
933 GetIcmp ()->SendDestUnreachPort (ip, copy);
944 bool retVal = interface->
AddAddress (address);
945 if (m_routingProtocol != 0)
947 m_routingProtocol->NotifyAddAddress (i, address);
976 if (m_routingProtocol != 0)
978 m_routingProtocol->NotifyRemoveAddress (i, address);
987 Ipv4Address dst, Ipv4InterfaceAddress::InterfaceAddressScope_e scope)
1001 if (iaddr.IsSecondary ())
continue;
1002 if (iaddr.GetScope () > scope)
continue;
1005 return iaddr.GetLocal ();
1009 addr = iaddr.GetLocal ();
1025 if (iaddr.IsSecondary ())
continue;
1026 if (iaddr.GetScope () != Ipv4InterfaceAddress::LINK
1027 && iaddr.GetScope () <= scope)
1029 return iaddr.GetLocal ();
1033 NS_LOG_WARN (
"Could not find source address for " << dst <<
" and scope "
1034 << scope <<
", returning 0");
1059 return interface->
GetDevice ()->GetMtu ();
1067 return interface->
IsUp ();
1075 interface->
SetUp ();
1077 if (m_routingProtocol != 0)
1079 m_routingProtocol->NotifyInterfaceUp (i);
1090 if (m_routingProtocol != 0)
1092 m_routingProtocol->NotifyInterfaceDown (ifaceIndex);
1121 Ipv4L3Protocol::SetIpForward (
bool forward)
1124 m_ipForward = forward;
1125 for (Ipv4InterfaceList::const_iterator i = m_interfaces.begin (); i != m_interfaces.end (); i++)
1127 (*i)->SetForwarding (forward);
1132 Ipv4L3Protocol::GetIpForward (
void)
const
1139 Ipv4L3Protocol::SetWeakEsModel (
bool model)
1142 m_weakEsModel = model;
1146 Ipv4L3Protocol::GetWeakEsModel (
void)
const
1149 return m_weakEsModel;
1153 Ipv4L3Protocol::RouteInputError (Ptr<const Packet> p,
const Ipv4Header & ipHeader, Socket::SocketErrno sockErrno)
1156 NS_LOG_LOGIC (
"Route input failure-- dropping packet to " << ipHeader <<
" with errno " << sockErrno);
1176 "IPv4 fragmentation implementation only works without option headers." );
1178 uint16_t offset = 0;
1179 bool moreFragment =
true;
1180 uint16_t originalOffset = 0;
1181 bool alreadyFragmented =
false;
1182 uint32_t currentFragmentablePartSize = 0;
1186 alreadyFragmented =
true;
1193 uint32_t fragmentSize = (outIfaceMtu - ipv4Header.
GetSerializedSize () ) & ~uint32_t (0x7);
1195 NS_LOG_LOGIC (
"Fragmenting - Target Size: " << fragmentSize );
1201 if (p->
GetSize () > offset + fragmentSize )
1203 moreFragment =
true;
1204 currentFragmentablePartSize = fragmentSize;
1209 moreFragment =
false;
1210 currentFragmentablePartSize = p->
GetSize () - offset;
1211 if (alreadyFragmented)
1221 NS_LOG_LOGIC (
"Fragment creation - " << offset <<
", " << currentFragmentablePartSize );
1235 NS_LOG_LOGIC (
"New fragment Header " << fragmentHeader);
1238 std::ostringstream oss;
1239 fragment->
Print (oss);
1243 listFragments.push_back (fragment);
1245 offset += currentFragmentablePartSize;
1248 while (moreFragment);
1260 std::pair<uint64_t, uint32_t> key;
1264 key.first = addressCombination;
1265 key.second = idProto;
1269 MapFragments_t::iterator it =
m_fragments.find (key);
1272 fragments = Create<Fragments> ();
1273 m_fragments.insert (std::make_pair (key, fragments));
1276 key, ipHeader, iif);
1280 fragments = it->second;
1292 if (m_fragmentsTimers[key].IsRunning ())
1295 m_fragmentsTimers[key].Cancel ();
1297 m_fragmentsTimers.erase (key);
1305 : m_moreFragment (0)
1320 std::list<std::pair<Ptr<Packet>, uint16_t> >::iterator it;
1324 if (it->second > fragmentOffset)
1332 m_moreFragment = moreFragment;
1343 bool ret = !m_moreFragment &&
m_fragments.size () > 0;
1347 uint16_t lastEndOffset = 0;
1352 NS_LOG_LOGIC (
"Checking overlaps " << lastEndOffset <<
" - " << it->second );
1354 if (lastEndOffset < it->second)
1360 uint16_t fragmentEnd = it->first->GetSize () + it->second;
1361 lastEndOffset = std::max ( lastEndOffset, fragmentEnd );
1373 std::list<std::pair<Ptr<Packet>, uint16_t> >::const_iterator it =
m_fragments.begin ();
1376 uint16_t lastEndOffset = 0;
1380 if ( lastEndOffset > it->second )
1386 uint32_t newStart = lastEndOffset - it->second;
1387 if ( it->first->GetSize () > newStart )
1389 uint32_t newSize = it->first->GetSize () - newStart;
1390 Ptr<Packet> tempFragment = it->first->CreateFragment (newStart, newSize);
1399 lastEndOffset = p->
GetSize ();
1410 std::list<std::pair<Ptr<Packet>, uint16_t> >::const_iterator it =
m_fragments.begin ();
1413 uint16_t lastEndOffset = 0;
1422 if ( lastEndOffset > it->second )
1424 uint32_t newStart = lastEndOffset - it->second;
1425 uint32_t newSize = it->first->GetSize () - newStart;
1426 Ptr<Packet> tempFragment = it->first->CreateFragment (newStart, newSize);
1429 else if ( lastEndOffset == it->second )
1434 lastEndOffset = p->
GetSize ();
1445 MapFragments_t::iterator it =
m_fragments.find (key);
1446 Ptr<Packet> packet = it->second->GetPartialPacket ();
1452 icmp->SendTimeExceededTtl (ipHeader, packet);
1460 m_fragmentsTimers.erase (key);
uint32_t RemoveHeader(Header &header)
void SetForwarding(bool val)
void SetDefaultTtl(uint8_t ttl)
void Receive(Ptr< NetDevice > device, Ptr< const Packet > p, uint16_t protocol, const Address &from, const Address &to, NetDevice::PacketType packetType)
Receive a packet.
Ptr< Packet > GetPacket() const
Get the entire packet.
static Ipv4Address GetAny(void)
#define NS_LOG_FUNCTION(parameters)
virtual void NotifyNewAggregate()
a class to represent an Ipv4 address mask
void Send(Ptr< Packet > p, Ipv4Address dest)
static bool ChecksumEnabled(void)
bool IsLocalMulticast(void) const
The IPv4 representation of a network interface.
#define NS_ASSERT(condition)
#define NS_LOG_COMPONENT_DEFINE(name)
uint32_t GetSize(void) const
bool IsMulticast(void) const
Ipv4Address CombineMask(Ipv4Mask const &mask) const
Combine this address with a network mask.
Ipv4InterfaceAddress RemoveAddress(uint32_t index)
virtual void DoDispose(void)
int32_t GetInterfaceForDevice(Ptr< const NetDevice > device) const
int32_t GetInterfaceForPrefix(Ipv4Address addr, Ipv4Mask mask) const
Return the interface number of first interface found that has an Ipv4 address within the prefix speci...
bool AddAddress(Ipv4InterfaceAddress address)
uint32_t AddInterface(Ptr< NetDevice > device)
static EventId Schedule(Time const &time, MEM mem_ptr, OBJ obj)
This class implements a tag that carries the socket-specific TTL of a packet to the IP layer...
void Print(std::ostream &os) const
#define NS_FATAL_ERROR(msg)
fatal error handling
a polymophic address class
Ipv4InterfaceAddress GetAddress(uint32_t interfaceIndex, uint32_t addressIndex) const
bool IsSubnetDirectedBroadcast(Ipv4Mask const &mask) const
Generate subnet-directed broadcast address corresponding to mask.
bool IsDestinationAddress(Ipv4Address address, uint32_t iif) const
Determine whether address and interface corresponding to received packet can be accepted for local de...
Ptr< Packet > GetPartialPacket() const
Get the complete part of the packet.
Ptr< Packet > CreateFragment(uint32_t start, uint32_t length) const
void AddAtEnd(Ptr< const Packet > packet)
bool PeekPacketTag(Tag &tag) const
Ptr< Icmpv4L4Protocol > GetIcmp(void) const
Get ICMPv4 protocol.
bool IsEntire() const
If all fragments have been added.
void SetMetric(uint32_t i, uint16_t metric)
virtual void DoDispose(void)
bool IsBroadcast(void) const
Ptr< NetDevice > GetDevice(uint32_t index) const
Ptr< Socket > CreateRawSocket(void)
Creates a raw socket.
virtual enum RxStatus Receive(Ptr< Packet > p, Ipv4Header const &header, Ptr< Ipv4Interface > incomingInterface)=0
void Send(Ptr< Packet > packet, Ipv4Address source, Ipv4Address destination, uint8_t protocol, Ptr< Ipv4Route > route)
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
bool IsUp(uint32_t i) const
MapFragments_t m_fragments
The hash of fragmented packets.
void SendWithHeader(Ptr< Packet > packet, Ipv4Header ipHeader, Ptr< Ipv4Route > route)
#define NS_LOG_LOGIC(msg)
Ipv4Address GetGateway(void) const
bool RemoveAddress(uint32_t interfaceIndex, uint32_t addressIndex)
void AddFragment(Ptr< Packet > fragment, uint16_t fragmentOffset, bool moreFragment)
Add a fragment.
Ipv4InterfaceAddress GetAddress(uint32_t index) const
virtual void NotifyNewAggregate(void)
Access to the Ipv4 forwarding table, interfaces, and configuration.
uint32_t GetNDevices(void) const
void SetForwarding(uint32_t i, bool val)
Ptr< Packet > Copy(void) const
int32_t GetInterfaceForAddress(Ipv4Address addr) const
Return the interface number of the interface that has been assigned the specified IP address...
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
void DoFragmentation(Ptr< Packet > packet, uint32_t outIfaceMtu, std::list< Ptr< Packet > > &listFragments)
Fragment a packet.
static Ipv4Address GetLoopback(void)
static Ipv4Mask GetLoopback(void)
void RegisterProtocolHandler(ProtocolHandler handler, uint16_t protocolType, Ptr< NetDevice > device, bool promiscuous=false)
Ptr< NetDevice > GetNetDevice(uint32_t i)
uint16_t GetMetric(void) const
#define NS_ASSERT_MSG(condition, message)
bool ProcessFragment(Ptr< Packet > &packet, Ipv4Header &ipHeader, uint32_t iif)
Process a packet fragment.
void Remove(Ptr< IpL4Protocol > protocol)
Ipv4 addresses are stored in host order in this class.
Time Seconds(double seconds)
create ns3::Time instances in units of seconds.
uint32_t AddDevice(Ptr< NetDevice > device)
uint32_t GetId(void) const
a class to store IPv4 address information on an interface
void DeleteRawSocket(Ptr< Socket > socket)
Deletes a particular raw socket.
bool AddAddress(uint32_t i, Ipv4InterfaceAddress address)
Ptr< NetDevice > GetDevice(void) const
void Insert(Ptr< IpL4Protocol > protocol)
bool RemovePacketTag(Tag &tag)
uint32_t GetNAddresses(uint32_t interface) const
uint16_t GetMtu(uint32_t i) const
void Receive(Ptr< NetDevice > device, Ptr< const Packet > p, uint16_t protocol, const Address &from, const Address &to, NetDevice::PacketType packetType)
uint32_t GetNInterfaces(void) const
Ptr< IpL4Protocol > GetProtocol(int protocolNumber) const
void SetMetric(uint16_t metric)
#define NS_LOG_ERROR(msg)
uint16_t GetMetric(uint32_t i) const
Ptr< Ipv4RoutingProtocol > GetRoutingProtocol(void) const
Get the routing protocol to be used by this Ipv4 stack.
Ptr< T > GetObject(void) const
uint32_t GetNAddresses(void) const
bool IsForwarding(void) const
void HandleFragmentsTimeout(std::pair< uint64_t, uint32_t > key, Ipv4Header &ipHeader, uint32_t iif)
Process the timeout for packet fragments.
void AddHeader(const Header &header)
bool IsForwarding(uint32_t i) const
Ipv4Address SelectSourceAddress(Ptr< const NetDevice > device, Ipv4Address dst, Ipv4InterfaceAddress::InterfaceAddressScope_e scope)
Return the first primary source address with scope less than or equal to the requested scope...
void SetRoutingProtocol(Ptr< Ipv4RoutingProtocol > routingProtocol)
Register a new routing protocol to be used by this Ipv4 stack.