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"
58 .AddConstructor<UdpL4Protocol> ()
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);
204 NS_LOG_FUNCTION (
this << localAddress << localPort << peerAddress << peerPort);
206 peerAddress, peerPort);
247 NS_LOG_FUNCTION (
this << localAddress << localPort << peerAddress << peerPort);
249 peerAddress, peerPort);
261 uint8_t icmpType, uint8_t icmpCode, uint32_t icmpInfo,
263 const uint8_t payload[8])
265 NS_LOG_FUNCTION (
this << icmpSource << icmpTtl << icmpType << icmpCode << icmpInfo
266 << payloadSource << payloadDestination);
268 src = payload[0] << 8;
270 dst = payload[2] << 8;
276 endPoint->
ForwardIcmp (icmpSource, icmpTtl, icmpType, icmpCode, icmpInfo);
280 NS_LOG_DEBUG (
"no endpoint found source=" << payloadSource <<
281 ", destination="<<payloadDestination<<
282 ", src=" << src <<
", dst=" << dst);
288 uint8_t icmpType, uint8_t icmpCode, uint32_t icmpInfo,
290 const uint8_t payload[8])
292 NS_LOG_FUNCTION (
this << icmpSource << icmpTtl << icmpType << icmpCode << icmpInfo
293 << payloadSource << payloadDestination);
295 src = payload[0] << 8;
297 dst = payload[2] << 8;
303 endPoint->
ForwardIcmp (icmpSource, icmpTtl, icmpType, icmpCode, icmpInfo);
307 NS_LOG_DEBUG (
"no endpoint found source=" << payloadSource <<
308 ", destination="<<payloadDestination<<
309 ", src=" << src <<
", dst=" << dst);
344 if (endPoints.empty ())
346 if (this->GetObject<Ipv6L3Protocol> () != 0)
348 NS_LOG_LOGIC (
" No Ipv4 endpoints matched on UdpL4Protocol, trying Ipv6 "<<
this);
355 return (this->
Receive (packet, ipv6Header, fakeInterface));
364 endPoint != endPoints.end (); endPoint++)
398 if (endPoints.empty ())
404 endPoint != endPoints.end (); endPoint++)
406 (*endPoint)->ForwardUp (packet->
Copy (), header, udpHeader.GetSourcePort (), interface);
414 uint16_t sport, uint16_t dport)
439 NS_LOG_FUNCTION (
this << packet << saddr << daddr << sport << dport << route);
460 uint16_t sport, uint16_t dport)
485 NS_LOG_FUNCTION (
this << packet << saddr << daddr << sport << dport << route);
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
Ptr< const AttributeAccessor > MakeObjectVectorAccessor(U T::*memberContainer)
Ptr< Socket > CreateSocket(void)
#define NS_LOG_FUNCTION(parameters)
virtual void DoDispose(void)
This method is called by Object::Dispose or by the object's destructor, whichever comes first...
std::list< Ipv6EndPoint * > EndPoints
Container of the IPv6 endpoints.
void Send(Ptr< Packet > packet, Ipv6Address source, Ipv6Address destination, uint8_t protocol, Ptr< Ipv6Route > route)
Higher-level layers call this method to send a packet down the stack to the MAC and PHY layers...
IPv6 layer implementation.
EndPoints Lookup(Ipv6Address dst, uint16_t dport, Ipv6Address src, uint16_t sport, Ptr< Ipv6Interface > incomingInterface)
lookup for a match with all the parameters.
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...
static bool ChecksumEnabled(void)
bool IsNull(void) const
Check for null implementation.
NS_OBJECT_ENSURE_REGISTERED(NullMessageSimulatorImpl)
virtual void DoDispose(void)
This method is called by Object::Dispose or by the object's destructor, whichever comes first...
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
std::list< Ipv6EndPoint * >::iterator EndPointsI
Iterator to the container of the IPv6 endpoints.
Ptr< Node > m_node
the node this stack is associated with
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.
Demultiplexes packets to various transport layer endpoints.
virtual int GetProtocolNumber(void) const
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.
Ipv6EndPoint * Allocate(void)
Allocate a Ipv6EndPoint.
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
void AggregateObject(Ptr< Object > other)
#define NS_LOG_LOGIC(msg)
static TypeId GetTypeId(void)
Get the type ID.
void DeAllocate(Ipv6EndPoint *endPoint)
Remove a end point.
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 void NotifyNewAggregate(void)
This method is invoked whenever two sets of objects are aggregated together.
Ptr< Packet > Copy(void) const
uint32_t PeekHeader(Header &header) const
Deserialize but does not remove the header from the internal buffer.
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.
Ipv6EndPointDemux * m_endPoints6
A list of IPv6 end points.
void ForwardIcmp(Ipv4Address icmpSource, uint8_t icmpTtl, uint8_t icmpType, uint8_t icmpCode, uint32_t icmpInfo)
Forward the ICMP packet to the upper level.
Ipv6EndPoint * SimpleLookup(Ipv6Address dst, uint16_t dport, Ipv6Address src, uint16_t sport)
Simple lookup for a four-tuple match.
virtual void Send(Ptr< Packet > packet, Ipv4Address source, Ipv4Address destination, uint8_t protocol, Ptr< Ipv4Route > route)=0
Ipv4EndPoint * SimpleLookup(Ipv4Address daddr, uint16_t dport, Ipv4Address saddr, uint16_t sport)
simple lookup for a match with all the parameters.
L4 Protocol abstract base class.
void DeAllocate(Ipv4EndPoint *endPoint)
Remove an IPv4 Endpoint.
IpL4Protocol::DownTargetCallback6 m_downTarget6
Callback to send packets over IPv6.
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...
EndPoints Lookup(Ipv4Address daddr, uint16_t dport, Ipv4Address saddr, uint16_t sport, Ptr< Ipv4Interface > incomingInterface)
lookup for a match with all the parameters.
NS_LOG_COMPONENT_DEFINE("UdpL4Protocol")
Describes an IPv6 address.
Ipv4 addresses are stored in host order in this class.
std::list< Ipv4EndPoint * > EndPoints
Container of the IPv4 endpoints.
IpL4Protocol::DownTargetCallback m_downTarget
Callback to send packets over IPv4.
virtual void NotifyNewAggregate()
This method is invoked whenever two sets of objects are aggregated together.
Demultiplexor for end points.
#define NS_LOG_DEBUG(msg)
std::vector< Ptr< UdpSocketImpl > > m_sockets
list of sockets
A representation of an internet IPv6 endpoint/connection.
Ipv4EndPointDemux * m_endPoints
A list of IPv4 end points.
void Send(Ptr< Packet > packet, Ipv4Address saddr, Ipv4Address daddr, uint16_t sport, uint16_t dport)
Send a packet via UDP (IPv4)
void Nullify(void)
Discard the implementation, set it to null.
Ipv6EndPoint * Allocate6(void)
Allocate an IPv6 Endpoint.
void ForwardIcmp(Ipv6Address src, uint8_t ttl, uint8_t type, uint8_t code, uint32_t info)
Forward the ICMP packet to the upper level.
std::list< Ipv4EndPoint * >::iterator EndPointsI
Iterator to the container of the IPv4 endpoints.
contain a set of ns3::Object pointers.
void DeAllocate(Ipv4EndPoint *endPoint)
Remove a end point.
static Ipv6Address MakeIpv4MappedAddress(Ipv4Address addr)
Make the Ipv4-mapped IPv6 address.
Ptr< T > GetObject(void) const
bool IsIpv4MappedAddress() const
If the address is an IPv4-mapped address.
a unique identifier for an interface.
static const uint8_t PROT_NUMBER
protocol number (0x11)
TypeId SetParent(TypeId tid)
void AddHeader(const Header &header)
Add header to this packet.
A representation of an internet endpoint/connection.
Ipv4EndPoint * Allocate(void)
Allocate a Ipv4EndPoint.