38 #include "ns3/assert.h"
39 #include "ns3/boolean.h"
40 #include "ns3/ipv4-route.h"
41 #include "ns3/ipv6-route.h"
44 #include "ns3/nstime.h"
45 #include "ns3/object-vector.h"
46 #include "ns3/packet.h"
47 #include "ns3/simulator.h"
62 #undef NS_LOG_APPEND_CONTEXT
63 #define NS_LOG_APPEND_CONTEXT \
66 std::clog << " [node " << m_node->GetId() << "] "; \
77 .SetGroupName(
"Internet")
79 .AddAttribute(
"RttEstimatorType",
80 "Type of RttEstimator objects.",
84 .AddAttribute(
"SocketType",
85 "Socket type of TCP objects.",
89 .AddAttribute(
"RecoveryType",
90 "Recovery type of TCP objects.",
94 .AddAttribute(
"SocketList",
95 "The list of sockets associated to this protocol.",
98 MakeObjectVectorChecker<TcpSocketBase>());
125 Ptr<Node> node = this->GetObject<Node>();
126 Ptr<Ipv4> ipv4 = this->GetObject<Ipv4>();
131 if (node && (ipv4 || ipv6))
135 tcpFactory->SetTcp(
this);
202 congestionAlgorithmFactory.
SetTypeId(congestionTypeId);
203 recoveryAlgorithmFactory.
SetTypeId(recoveryTypeId);
211 socket->SetTcp(
this);
213 socket->SetCongestionControlAlgorithm(algo);
214 socket->SetRecoveryAlgorithm(recovery);
261 NS_LOG_FUNCTION(
this << boundNetDevice << localAddress << localPort << peerAddress << peerPort);
262 return m_endPoints->
Allocate(boundNetDevice, localAddress, localPort, peerAddress, peerPort);
307 NS_LOG_FUNCTION(
this << boundNetDevice << localAddress << localPort << peerAddress << peerPort);
326 const uint8_t payload[8])
328 NS_LOG_FUNCTION(
this << icmpSource << (uint16_t)icmpTtl << (uint16_t)icmpType
329 << (uint16_t)icmpCode << icmpInfo << payloadSource << payloadDestination);
332 src = payload[0] << 8;
334 dst = payload[2] << 8;
338 if (endPoint !=
nullptr)
340 endPoint->
ForwardIcmp(icmpSource, icmpTtl, icmpType, icmpCode, icmpInfo);
344 NS_LOG_DEBUG(
"no endpoint found source=" << payloadSource
345 <<
", destination=" << payloadDestination
346 <<
", src=" << src <<
", dst=" << dst);
358 const uint8_t payload[8])
360 NS_LOG_FUNCTION(
this << icmpSource << (uint16_t)icmpTtl << (uint16_t)icmpType
361 << (uint16_t)icmpCode << icmpInfo << payloadSource << payloadDestination);
364 src = payload[0] << 8;
366 dst = payload[2] << 8;
371 if (endPoint !=
nullptr)
373 endPoint->
ForwardIcmp(icmpSource, icmpTtl, icmpType, icmpCode, icmpInfo);
377 NS_LOG_DEBUG(
"no endpoint found source=" << payloadSource
378 <<
", destination=" << payloadDestination
379 <<
", src=" << src <<
", dst=" << dst);
389 NS_LOG_FUNCTION(
this << packet << incomingTcpHeader << source << destination);
399 NS_LOG_LOGIC(
"TcpL4Protocol " <<
this <<
" receiving seq "
403 <<
" data size " << packet->
GetSize());
419 NS_LOG_FUNCTION(
this << incomingHeader << incomingSAddr << incomingDAddr);
447 SendPacket(rstPacket, outgoingTcpHeader, incomingDAddr, incomingSAddr);
456 NS_LOG_FUNCTION(
this << packet << incomingIpHeader << incomingInterface);
468 return checksumControl;
478 if (endPoints.empty())
480 if (this->GetObject<Ipv6L3Protocol>())
482 NS_LOG_LOGIC(
" No Ipv4 endpoints matched on TcpL4Protocol, trying Ipv6 " <<
this);
483 Ptr<Ipv6Interface> fakeInterface;
484 Ipv6Header ipv6Header;
490 ipv6Header.SetSource(src);
491 ipv6Header.SetDestination(dst);
492 return (this->
Receive(packet, ipv6Header, fakeInterface));
497 <<
" received a packet but"
498 " no endpoints matched."
501 <<
" source IP: " << incomingIpHeader.
GetSource()
511 NS_ASSERT_MSG(endPoints.size() == 1,
"Demux returned more than one endpoint");
513 <<
" received a packet and"
514 " now forwarding it up to endpoint/socket");
517 ->ForwardUp(packet, incomingIpHeader, incomingTcpHeader.
GetSourcePort(), incomingInterface);
524 const Ipv6Header& incomingIpHeader,
525 Ptr<Ipv6Interface> interface)
528 << incomingIpHeader.GetDestination());
530 TcpHeader incomingTcpHeader;
539 incomingIpHeader.GetSource(),
540 incomingIpHeader.GetDestination());
544 return checksumControl;
549 incomingTcpHeader.GetDestinationPort(),
550 incomingIpHeader.GetSource(),
551 incomingTcpHeader.GetSourcePort(),
553 if (endPoints.empty())
557 <<
" received a packet but"
558 " no endpoints matched."
559 <<
" destination IP: " << incomingIpHeader.GetDestination()
560 <<
" destination port: " << incomingTcpHeader.GetDestinationPort()
561 <<
" source IP: " << incomingIpHeader.GetSource()
562 <<
" source port: " << incomingTcpHeader.GetSourcePort());
565 incomingIpHeader.GetSource(),
566 incomingIpHeader.GetDestination());
571 NS_ASSERT_MSG(endPoints.size() == 1,
"Demux returned more than one endpoint");
573 <<
" received a packet and"
574 " now forwarding it up to endpoint/socket");
577 ->ForwardUp(packet, incomingIpHeader, incomingTcpHeader.GetSourcePort(), interface);
616 if (ipv4->GetRoutingProtocol())
618 route = ipv4->GetRoutingProtocol()->RouteOutput(packet, header, oif, errno_);
629 NS_FATAL_ERROR(
"Trying to use Tcp on a node without an Ipv4 interface");
675 if (ipv6->GetRoutingProtocol())
677 route = ipv6->GetRoutingProtocol()->RouteOutput(packet, header, oif, errno_);
688 NS_FATAL_ERROR(
"Trying to use Tcp on a node without an Ipv6 interface");
750 std::vector<Ptr<TcpSocketBase>>::iterator it =
m_sockets.begin();
769 std::vector<Ptr<TcpSocketBase>>::iterator it =
m_sockets.begin();
a polymophic address class
void Nullify()
Discard the implementation, set it to null.
bool IsNull() const
Check for null implementation.
static Inet6SocketAddress ConvertFrom(const Address &addr)
Convert the address to a InetSocketAddress.
static bool IsMatchingType(const Address &addr)
If the address match.
Ipv6Address GetIpv6() const
Get the IPv6 address.
static bool IsMatchingType(const Address &address)
Ipv4Address GetIpv4() const
static InetSocketAddress ConvertFrom(const Address &address)
Returns an InetSocketAddress which corresponds to the input Address.
L4 Protocol abstract base class.
Ipv4 addresses are stored in host order in this class.
static Ipv4Address ConvertFrom(const Address &address)
static bool IsMatchingType(const Address &address)
Demultiplexes packets to various transport layer endpoints.
Ipv4EndPoint * SimpleLookup(Ipv4Address daddr, uint16_t dport, Ipv4Address saddr, uint16_t sport)
simple lookup for a match with all the parameters.
EndPoints Lookup(Ipv4Address daddr, uint16_t dport, Ipv4Address saddr, uint16_t sport, Ptr< Ipv4Interface > incomingInterface)
lookup for a match with all the parameters.
void DeAllocate(Ipv4EndPoint *endPoint)
Remove a end point.
Ipv4EndPoint * Allocate()
Allocate a Ipv4EndPoint.
std::list< Ipv4EndPoint * > EndPoints
Container of the IPv4 endpoints.
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.
Access to the IPv4 forwarding table, interfaces, and configuration.
virtual void Send(Ptr< Packet > packet, Ipv4Address source, Ipv4Address destination, uint8_t protocol, Ptr< Ipv4Route > route)=0
Describes an IPv6 address.
bool IsIpv4MappedAddress() const
If the address is an IPv4-mapped address.
static Ipv6Address ConvertFrom(const Address &address)
Convert the Address object into an Ipv6Address ones.
Ipv4Address GetIpv4MappedAddress() const
Return the Ipv4 address.
static bool IsMatchingType(const Address &address)
If the Address matches the type.
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.
Ipv6EndPoint * Allocate()
Allocate a Ipv6EndPoint.
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.
std::list< Ipv6EndPoint * > EndPoints
Container of the IPv6 endpoints.
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.
IPv6 layer implementation.
static bool ChecksumEnabled()
Instantiate subclasses of ns3::Object.
Ptr< Object > Create() const
Create an Object instance of the configured TypeId.
void SetTypeId(TypeId tid)
Set the TypeId of the Objects to be created by this factory.
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.
void AggregateObject(Ptr< Object > other)
Aggregate two Objects together.
virtual void DoDispose()
Destructor implementation.
void AddHeader(const Header &header)
Add header to this packet.
uint32_t GetSize() const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
uint32_t PeekHeader(Header &header) const
Deserialize but does not remove the header from the internal buffer.
Base class for all RTT Estimators.
static TypeId GetTypeId()
Get the type ID.
SocketErrno
Enumeration of the possible errors returned by a socket.
Congestion control abstract class.
static TypeId GetTypeId()
Get the type ID.
TCP socket creation and multiplexing/demultiplexing.
void SetNode(Ptr< Node > node)
Set node associated with this stack.
void SendPacketV4(Ptr< Packet > pkt, const TcpHeader &outgoing, const Ipv4Address &saddr, const Ipv4Address &daddr, Ptr< NetDevice > oif=nullptr) const
Send a packet via TCP (IPv4)
void NoEndPointsFound(const TcpHeader &incomingHeader, const Address &incomingSAddr, const Address &incomingDAddr)
Check if RST packet should be sent, and in case, send it.
bool RemoveSocket(Ptr< TcpSocketBase > socket)
Remove a socket from the internal list.
enum IpL4Protocol::RxStatus Receive(Ptr< Packet > p, const Ipv4Header &incomingIpHeader, Ptr< Ipv4Interface > incomingInterface) override
Called from lower-level layers to send the packet up in the stack.
TypeId m_congestionTypeId
The socket TypeId.
enum IpL4Protocol::RxStatus PacketReceived(Ptr< Packet > packet, TcpHeader &incomingTcpHeader, const Address &source, const Address &destination)
Get the tcp header of the incoming packet and checks its checksum if needed.
TypeId m_recoveryTypeId
The recovery TypeId.
IpL4Protocol::DownTargetCallback m_downTarget
Callback to send packets over IPv4.
void SetDownTarget6(IpL4Protocol::DownTargetCallback6 cb) override
This method allows a caller to set the current down target callback set for this L4 protocol (IPv6 ca...
void DoDispose() override
Destructor implementation.
Ipv4EndPointDemux * m_endPoints
A list of IPv4 end points.
std::vector< Ptr< TcpSocketBase > > m_sockets
list of sockets
Ipv6EndPointDemux * m_endPoints6
A list of IPv6 end points.
Ptr< Node > m_node
the node this stack is associated with
static TypeId GetTypeId()
Get the type ID.
void NotifyNewAggregate() override
Setup socket factory and callbacks when aggregated to a node.
Ipv6EndPoint * Allocate6()
Allocate an IPv6 Endpoint.
void DeAllocate(Ipv4EndPoint *endPoint)
Remove an IPv4 Endpoint.
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]) override
Called from lower-level layers to send the ICMP packet up in the stack.
IpL4Protocol::DownTargetCallback GetDownTarget() const override
This method allows a caller to get the current down target callback set for this L4 protocol (IPv4 ca...
static const uint8_t PROT_NUMBER
protocol number (0x6)
~TcpL4Protocol() override
void SetDownTarget(IpL4Protocol::DownTargetCallback cb) override
This method allows a caller to set the current down target callback set for this L4 protocol (IPv4 ca...
Ptr< Socket > CreateSocket()
Create a TCP socket using the TypeId set by SocketType attribute.
void SendPacketV6(Ptr< Packet > pkt, const TcpHeader &outgoing, const Ipv6Address &saddr, const Ipv6Address &daddr, Ptr< NetDevice > oif=nullptr) const
Send a packet via TCP (IPv6)
IpL4Protocol::DownTargetCallback6 GetDownTarget6() const override
This method allows a caller to get the current down target callback set for this L4 protocol (IPv6 ca...
void SendPacket(Ptr< Packet > pkt, const TcpHeader &outgoing, const Address &saddr, const Address &daddr, Ptr< NetDevice > oif=nullptr) const
Send a packet via TCP (IP-agnostic)
void AddSocket(Ptr< TcpSocketBase > socket)
Make a socket fully operational.
IpL4Protocol::DownTargetCallback6 m_downTarget6
Callback to send packets over IPv6.
Ipv4EndPoint * Allocate()
Allocate an IPv4 Endpoint.
int GetProtocolNumber() const override
Returns the protocol number of this protocol.
TypeId m_rttTypeId
The RTT Estimator TypeId.
static TypeId GetTypeId()
Get the type ID.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
std::string GetName() const
Get the name.
AttributeValue implementation for TypeId.
#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 AttributeChecker > MakeTypeIdChecker()
Ptr< const AttributeAccessor > MakeTypeIdAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
#define NS_LOG_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
#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.
SequenceNumber< uint32_t, int32_t > SequenceNumber32
32 bit Sequence number.
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...