22 #include "ns3/assert.h"
23 #include "ns3/packet.h"
25 #include "ns3/boolean.h"
26 #include "ns3/object-vector.h"
28 #include "ns3/ipv4-route.h"
29 #include "ns3/ipv6-route.h"
30 #include "ns3/ipv6-header.h"
57 .SetGroupName (
"Internet")
59 .AddAttribute (
"SocketList",
"The list of sockets associated to this protocol.",
62 MakeObjectVectorChecker<UdpSocketImpl> ())
93 Ptr<Node> node = this->GetObject<Node> ();
94 Ptr<Ipv4> ipv4 = this->GetObject<Ipv4> ();
99 if ((node != 0) && (ipv4 != 0 || ipv6 != 0))
103 udpFactory->SetUdp (
this);
168 socket->SetUdp (
this);
205 NS_LOG_FUNCTION (
this << boundNetDevice << localAddress << localPort << peerAddress << peerPort);
207 localAddress, localPort,
208 peerAddress, peerPort);
250 NS_LOG_FUNCTION (
this << boundNetDevice << localAddress << localPort << peerAddress << peerPort);
252 localAddress, localPort,
253 peerAddress, peerPort);
265 uint8_t icmpType, uint8_t icmpCode, uint32_t icmpInfo,
267 const uint8_t payload[8])
269 NS_LOG_FUNCTION (
this << icmpSource << icmpTtl << icmpType << icmpCode << icmpInfo
270 << payloadSource << payloadDestination);
272 src = payload[0] << 8;
274 dst = payload[2] << 8;
280 endPoint->
ForwardIcmp (icmpSource, icmpTtl, icmpType, icmpCode, icmpInfo);
284 NS_LOG_DEBUG (
"no endpoint found source=" << payloadSource <<
285 ", destination="<<payloadDestination<<
286 ", src=" << src <<
", dst=" << dst);
292 uint8_t icmpType, uint8_t icmpCode, uint32_t icmpInfo,
294 const uint8_t payload[8])
296 NS_LOG_FUNCTION (
this << icmpSource << icmpTtl << icmpType << icmpCode << icmpInfo
297 << payloadSource << payloadDestination);
299 src = payload[0] << 8;
301 dst = payload[2] << 8;
307 endPoint->
ForwardIcmp (icmpSource, icmpTtl, icmpType, icmpCode, icmpInfo);
311 NS_LOG_DEBUG (
"no endpoint found source=" << payloadSource <<
312 ", destination="<<payloadDestination<<
313 ", src=" << src <<
", dst=" << dst);
348 if (endPoints.empty ())
350 if (this->GetObject<Ipv6L3Protocol> () != 0)
352 NS_LOG_LOGIC (
" No Ipv4 endpoints matched on UdpL4Protocol, trying Ipv6 "<<
this);
353 Ptr<Ipv6Interface> fakeInterface;
354 Ipv6Header ipv6Header;
357 ipv6Header.SetSource (src);
358 ipv6Header.SetDestination (dst);
359 return (this->
Receive (packet, ipv6Header, fakeInterface));
368 endPoint != endPoints.end (); endPoint++)
378 Ipv6Header
const &header,
379 Ptr<Ipv6Interface> interface)
381 NS_LOG_FUNCTION (
this << packet << header.GetSource () << header.GetDestination ());
388 udpHeader.InitializeChecksum (header.GetSource (), header.GetDestination (),
PROT_NUMBER);
390 packet->RemoveHeader (udpHeader);
392 if(!udpHeader.IsChecksumOk () && !header.GetSource ().IsIpv4MappedAddress ())
398 NS_LOG_DEBUG (
"Looking up dst " << header.GetDestination () <<
" port " << udpHeader.GetDestinationPort ());
401 header.GetSource (), udpHeader.GetSourcePort (), interface);
402 if (endPoints.empty ())
408 endPoint != endPoints.end (); endPoint++)
410 (*endPoint)->ForwardUp (packet->Copy (), header, udpHeader.GetSourcePort (), interface);
418 uint16_t sport, uint16_t dport)
443 NS_LOG_FUNCTION (
this << packet << saddr << daddr << sport << dport << route);
464 uint16_t sport, uint16_t dport)
489 NS_LOG_FUNCTION (
this << packet << saddr << daddr << sport << dport << route);
bool IsNull(void) const
Check for null implementation.
void Nullify(void)
Discard the implementation, set it to null.
L4 Protocol abstract base class.
Ipv4 addresses are stored in host order in this class.
Demultiplexes packets to various transport layer endpoints.
std::list< Ipv4EndPoint * > EndPoints
Container of the IPv4 endpoints.
Ipv4EndPoint * SimpleLookup(Ipv4Address daddr, uint16_t dport, Ipv4Address saddr, uint16_t sport)
simple lookup for a match with all the parameters.
Ipv4EndPoint * Allocate(void)
Allocate a Ipv4EndPoint.
EndPoints Lookup(Ipv4Address daddr, uint16_t dport, Ipv4Address saddr, uint16_t sport, Ptr< Ipv4Interface > incomingInterface)
lookup for a match with all the parameters.
std::list< Ipv4EndPoint * >::iterator EndPointsI
Iterator to the container of the IPv4 endpoints.
void DeAllocate(Ipv4EndPoint *endPoint)
Remove a end point.
A representation of an internet endpoint/connection.
void ForwardIcmp(Ipv4Address icmpSource, uint8_t icmpTtl, uint8_t icmpType, uint8_t icmpCode, uint32_t icmpInfo)
Forward the ICMP packet to the upper level.
virtual void Send(Ptr< Packet > packet, Ipv4Address source, Ipv4Address destination, uint8_t protocol, Ptr< Ipv4Route > route)=0
Describes an IPv6 address.
static Ipv6Address MakeIpv4MappedAddress(Ipv4Address addr)
Make the Ipv4-mapped IPv6 address.
Demultiplexer for end points.
EndPoints Lookup(Ipv6Address dst, uint16_t dport, Ipv6Address src, uint16_t sport, Ptr< Ipv6Interface > incomingInterface)
lookup for a match with all the parameters.
std::list< Ipv6EndPoint * > EndPoints
Container of the IPv6 endpoints.
Ipv6EndPoint * Allocate(void)
Allocate a Ipv6EndPoint.
std::list< Ipv6EndPoint * >::iterator EndPointsI
Iterator to the container of the IPv6 endpoints.
Ipv6EndPoint * SimpleLookup(Ipv6Address dst, uint16_t dport, Ipv6Address src, uint16_t sport)
Simple lookup for a four-tuple match.
void DeAllocate(Ipv6EndPoint *endPoint)
Remove a end point.
A representation of an IPv6 endpoint/connection.
void ForwardIcmp(Ipv6Address src, uint8_t ttl, uint8_t type, uint8_t code, uint32_t info)
Forward the ICMP packet to the upper level.
Access to the IPv6 forwarding table, interfaces, and configuration.
virtual void Send(Ptr< Packet > packet, Ipv6Address source, Ipv6Address destination, uint8_t protocol, Ptr< Ipv6Route > route)=0
Higher-level layers call this method to send a packet down the stack to the MAC and PHY layers.
static bool ChecksumEnabled(void)
virtual void DoDispose(void)
Destructor implementation.
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
void AggregateObject(Ptr< Object > other)
Aggregate two Objects together.
virtual void NotifyNewAggregate(void)
Notify all Objects aggregated to this one of a new Object being aggregated.
Container for a set of ns3::Object pointers.
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
void AddHeader(const Header &header)
Add header to this packet.
uint32_t PeekHeader(Header &header) const
Deserialize but does not remove the header from the internal buffer.
Ptr< Packet > Copy(void) const
performs a COW copy of the packet.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Implementation of the UDP protocol.
void Send(Ptr< Packet > packet, Ipv4Address saddr, Ipv4Address daddr, uint16_t sport, uint16_t dport)
Send a packet via UDP (IPv4)
virtual int GetProtocolNumber(void) const
Returns the protocol number of this protocol.
Ipv6EndPointDemux * m_endPoints6
A list of IPv6 end points.
static TypeId GetTypeId(void)
Get the type ID.
virtual void ReceiveIcmp(Ipv4Address icmpSource, uint8_t icmpTtl, uint8_t icmpType, uint8_t icmpCode, uint32_t icmpInfo, Ipv4Address payloadSource, Ipv4Address payloadDestination, const uint8_t payload[8])
Called from lower-level layers to send the ICMP packet up in the stack.
Ptr< Node > m_node
the node this stack is associated with
Ipv4EndPointDemux * m_endPoints
A list of IPv4 end points.
virtual void SetDownTarget6(IpL4Protocol::DownTargetCallback6 cb)
This method allows a caller to set the current down target callback set for this L4 protocol (IPv6 ca...
void SetNode(Ptr< Node > node)
Set node associated with this stack.
virtual IpL4Protocol::DownTargetCallback6 GetDownTarget6(void) const
This method allows a caller to get the current down target callback set for this L4 protocol (IPv6 ca...
virtual enum IpL4Protocol::RxStatus Receive(Ptr< Packet > p, Ipv4Header const &header, Ptr< Ipv4Interface > interface)
Called from lower-level layers to send the packet up in the stack.
Ipv4EndPoint * Allocate(void)
Allocate an IPv4 Endpoint.
Ptr< Socket > CreateSocket(void)
virtual void SetDownTarget(IpL4Protocol::DownTargetCallback cb)
This method allows a caller to set the current down target callback set for this L4 protocol (IPv4 ca...
IpL4Protocol::DownTargetCallback m_downTarget
Callback to send packets over IPv4.
IpL4Protocol::DownTargetCallback6 m_downTarget6
Callback to send packets over IPv6.
std::vector< Ptr< UdpSocketImpl > > m_sockets
list of sockets
virtual void NotifyNewAggregate()
Notify all Objects aggregated to this one of a new Object being aggregated.
void DeAllocate(Ipv4EndPoint *endPoint)
Remove an IPv4 Endpoint.
Ipv6EndPoint * Allocate6(void)
Allocate an IPv6 Endpoint.
virtual void DoDispose(void)
Destructor implementation.
static const uint8_t PROT_NUMBER
protocol number (0x11)
virtual IpL4Protocol::DownTargetCallback GetDownTarget(void) const
This method allows a caller to get the current down target callback set for this L4 protocol (IPv4 ca...
Ptr< const AttributeAccessor > MakeObjectVectorAccessor(U T::*memberVariable)
MakeAccessorHelper implementation for ObjectVector.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
#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.
#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, Ts... > MakeCallback(R(T::*memPtr)(Ts...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...