A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
tcp-l4-protocol.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2007 Georgia Tech Research Corporation
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Raj Bhattacharjea <raj.b@gatech.edu>
7 */
8
9#include "tcp-l4-protocol.h"
10
12#include "ipv4-end-point.h"
13#include "ipv4-route.h"
16#include "ipv6-end-point.h"
17#include "ipv6-l3-protocol.h"
18#include "ipv6-route.h"
20#include "rtt-estimator.h"
21#include "tcp-congestion-ops.h"
22#include "tcp-cubic.h"
23#include "tcp-header.h"
24#include "tcp-prr-recovery.h"
25#include "tcp-recovery-ops.h"
26#include "tcp-socket-base.h"
28
29#include "ns3/assert.h"
30#include "ns3/boolean.h"
31#include "ns3/iana-internet-protocol-numbers.h"
32#include "ns3/log.h"
33#include "ns3/node.h"
34#include "ns3/nstime.h"
35#include "ns3/object-map.h"
36#include "ns3/packet.h"
37#include "ns3/simulator.h"
38
39#include <iomanip>
40#include <sstream>
41#include <unordered_map>
42#include <vector>
43
44namespace ns3
45{
46
47NS_LOG_COMPONENT_DEFINE("TcpL4Protocol");
48
50
51// TcpL4Protocol stuff----------------------------------------------------------
52
53#undef NS_LOG_APPEND_CONTEXT
54#define NS_LOG_APPEND_CONTEXT \
55 if (m_node) \
56 { \
57 ns3LogStream << " [node " << m_node->GetId() << "] "; \
58 }
59
60TypeId
62{
63 static TypeId tid =
64 TypeId("ns3::TcpL4Protocol")
66 .SetGroupName("Internet")
67 .AddConstructor<TcpL4Protocol>()
68 .AddAttribute("RttEstimatorType",
69 "Type of RttEstimator objects.",
73 .AddAttribute("SocketType",
74 "Socket type of TCP objects.",
78 .AddAttribute("RecoveryType",
79 "Recovery type of TCP objects.",
83 .AddAttribute("SocketList",
84 "A container of sockets associated to this protocol. "
85 "The underlying type is an unordered map, the attribute name "
86 "is kept for backward compatibility.",
90 return tid;
91}
92
99
104
105void
107{
108 NS_LOG_FUNCTION(this);
109 m_node = node;
110}
111
112void
114{
115 NS_LOG_FUNCTION(this);
116 Ptr<Node> node = this->GetObject<Node>();
117 Ptr<Ipv4> ipv4 = this->GetObject<Ipv4>();
118 Ptr<Ipv6> ipv6 = node->GetObject<Ipv6>();
119
120 if (!m_node)
121 {
122 if (node && (ipv4 || ipv6))
123 {
124 this->SetNode(node);
126 tcpFactory->SetTcp(this);
127 node->AggregateObject(tcpFactory);
128 }
129 }
130
131 // We set at least one of our 2 down targets to the IPv4/IPv6 send
132 // functions. Since these functions have different prototypes, we
133 // need to keep track of whether we are connected to an IPv4 or
134 // IPv6 lower layer and call the appropriate one.
135
136 if (ipv4 && m_downTarget.IsNull())
137 {
138 ipv4->Insert(this);
140 }
141 if (ipv6 && m_downTarget6.IsNull())
142 {
143 ipv6->Insert(this);
145 }
147}
148
149int
154
155void
157{
158 NS_LOG_FUNCTION(this);
159 m_sockets.clear();
160
161 if (m_endPoints != nullptr)
162 {
163 delete m_endPoints;
164 m_endPoints = nullptr;
165 }
166
167 if (m_endPoints6 != nullptr)
168 {
169 delete m_endPoints6;
170 m_endPoints6 = nullptr;
171 }
172
173 m_node = nullptr;
174 m_downTarget.Nullify();
175 m_downTarget6.Nullify();
177}
178
181{
182 return CreateSocket(congestionTypeId, m_recoveryTypeId);
183}
184
186TcpL4Protocol::CreateSocket(TypeId congestionTypeId, TypeId recoveryTypeId)
187{
188 NS_LOG_FUNCTION(this << congestionTypeId.GetName());
189 ObjectFactory rttFactory;
190 ObjectFactory congestionAlgorithmFactory;
191 ObjectFactory recoveryAlgorithmFactory;
192 rttFactory.SetTypeId(m_rttTypeId);
193 congestionAlgorithmFactory.SetTypeId(congestionTypeId);
194 recoveryAlgorithmFactory.SetTypeId(recoveryTypeId);
195
196 Ptr<RttEstimator> rtt = rttFactory.Create<RttEstimator>();
198 Ptr<TcpCongestionOps> algo = congestionAlgorithmFactory.Create<TcpCongestionOps>();
199 Ptr<TcpRecoveryOps> recovery = recoveryAlgorithmFactory.Create<TcpRecoveryOps>();
200
201 socket->SetNode(m_node);
202 socket->SetTcp(this);
203 socket->SetRtt(rtt);
204 socket->SetCongestionControlAlgorithm(algo);
205 socket->SetRecoveryAlgorithm(recovery);
206
207 m_sockets[m_socketIndex++] = socket;
208 return socket;
209}
210
216
219{
220 NS_LOG_FUNCTION(this);
221 return m_endPoints->Allocate();
222}
223
226{
227 NS_LOG_FUNCTION(this << address);
228 return m_endPoints->Allocate(address);
229}
230
233{
234 NS_LOG_FUNCTION(this << boundNetDevice << port);
235 return m_endPoints->Allocate(boundNetDevice, port);
236}
237
239TcpL4Protocol::Allocate(Ptr<NetDevice> boundNetDevice, Ipv4Address address, uint16_t port)
240{
241 NS_LOG_FUNCTION(this << boundNetDevice << address << port);
242 return m_endPoints->Allocate(boundNetDevice, address, port);
243}
244
247 Ipv4Address localAddress,
248 uint16_t localPort,
249 Ipv4Address peerAddress,
250 uint16_t peerPort)
251{
252 NS_LOG_FUNCTION(this << boundNetDevice << localAddress << localPort << peerAddress << peerPort);
253 return m_endPoints->Allocate(boundNetDevice, localAddress, localPort, peerAddress, peerPort);
254}
255
256void
258{
259 NS_LOG_FUNCTION(this << endPoint);
260 m_endPoints->DeAllocate(endPoint);
261}
262
265{
266 NS_LOG_FUNCTION(this);
267 return m_endPoints6->Allocate();
268}
269
272{
273 NS_LOG_FUNCTION(this << address);
274 return m_endPoints6->Allocate(address);
275}
276
279{
280 NS_LOG_FUNCTION(this << boundNetDevice << port);
281 return m_endPoints6->Allocate(boundNetDevice, port);
282}
283
285TcpL4Protocol::Allocate6(Ptr<NetDevice> boundNetDevice, Ipv6Address address, uint16_t port)
286{
287 NS_LOG_FUNCTION(this << boundNetDevice << address << port);
288 return m_endPoints6->Allocate(boundNetDevice, address, port);
289}
290
293 Ipv6Address localAddress,
294 uint16_t localPort,
295 Ipv6Address peerAddress,
296 uint16_t peerPort)
297{
298 NS_LOG_FUNCTION(this << boundNetDevice << localAddress << localPort << peerAddress << peerPort);
299 return m_endPoints6->Allocate(boundNetDevice, localAddress, localPort, peerAddress, peerPort);
300}
301
302void
304{
305 NS_LOG_FUNCTION(this << endPoint);
306 m_endPoints6->DeAllocate(endPoint);
307}
308
309void
311 uint8_t icmpTtl,
312 uint8_t icmpType,
313 uint8_t icmpCode,
314 uint32_t icmpInfo,
315 Ipv4Address payloadSource,
316 Ipv4Address payloadDestination,
317 const uint8_t payload[8])
318{
319 NS_LOG_FUNCTION(this << icmpSource << (uint16_t)icmpTtl << (uint16_t)icmpType
320 << (uint16_t)icmpCode << icmpInfo << payloadSource << payloadDestination);
321 uint16_t src;
322 uint16_t dst;
323 src = payload[0] << 8;
324 src |= payload[1];
325 dst = payload[2] << 8;
326 dst |= payload[3];
327
328 Ipv4EndPoint* endPoint = m_endPoints->SimpleLookup(payloadSource, src, payloadDestination, dst);
329 if (endPoint != nullptr)
330 {
331 endPoint->ForwardIcmp(icmpSource, icmpTtl, icmpType, icmpCode, icmpInfo);
332 }
333 else
334 {
335 NS_LOG_DEBUG("no endpoint found source=" << payloadSource
336 << ", destination=" << payloadDestination
337 << ", src=" << src << ", dst=" << dst);
338 }
339}
340
341void
343 uint8_t icmpTtl,
344 uint8_t icmpType,
345 uint8_t icmpCode,
346 uint32_t icmpInfo,
347 Ipv6Address payloadSource,
348 Ipv6Address payloadDestination,
349 const uint8_t payload[8])
350{
351 NS_LOG_FUNCTION(this << icmpSource << (uint16_t)icmpTtl << (uint16_t)icmpType
352 << (uint16_t)icmpCode << icmpInfo << payloadSource << payloadDestination);
353 uint16_t src;
354 uint16_t dst;
355 src = payload[0] << 8;
356 src |= payload[1];
357 dst = payload[2] << 8;
358 dst |= payload[3];
359
360 Ipv6EndPoint* endPoint =
361 m_endPoints6->SimpleLookup(payloadSource, src, payloadDestination, dst);
362 if (endPoint != nullptr)
363 {
364 endPoint->ForwardIcmp(icmpSource, icmpTtl, icmpType, icmpCode, icmpInfo);
365 }
366 else
367 {
368 NS_LOG_DEBUG("no endpoint found source=" << payloadSource
369 << ", destination=" << payloadDestination
370 << ", src=" << src << ", dst=" << dst);
371 }
372}
373
376 TcpHeader& incomingTcpHeader,
377 const Address& source,
378 const Address& destination)
379{
380 NS_LOG_FUNCTION(this << packet << incomingTcpHeader << source << destination);
381
383 {
384 incomingTcpHeader.EnableChecksums();
385 incomingTcpHeader.InitializeChecksum(source,
386 destination,
388 }
389
390 packet->PeekHeader(incomingTcpHeader);
391
392 NS_LOG_LOGIC("TcpL4Protocol " << this << " receiving seq "
393 << incomingTcpHeader.GetSequenceNumber() << " ack "
394 << incomingTcpHeader.GetAckNumber() << " flags "
395 << TcpHeader::FlagsToString(incomingTcpHeader.GetFlags())
396 << " data size " << packet->GetSize());
397
398 if (!incomingTcpHeader.IsChecksumOk())
399 {
400 NS_LOG_INFO("Bad checksum, dropping packet!");
402 }
403
404 return IpL4Protocol::RX_OK;
405}
406
407void
409 const Address& incomingSAddr,
410 const Address& incomingDAddr)
411{
412 NS_LOG_FUNCTION(this << incomingHeader << incomingSAddr << incomingDAddr);
413
414 if (!(incomingHeader.GetFlags() & TcpHeader::RST))
415 {
416 // build a RST packet and send
417 Ptr<Packet> rstPacket = Create<Packet>();
418 TcpHeader outgoingTcpHeader;
419
420 if (incomingHeader.GetFlags() & TcpHeader::ACK)
421 {
422 // ACK bit was set
423 outgoingTcpHeader.SetFlags(TcpHeader::RST);
424 outgoingTcpHeader.SetSequenceNumber(incomingHeader.GetAckNumber());
425 }
426 else
427 {
428 outgoingTcpHeader.SetFlags(TcpHeader::RST | TcpHeader::ACK);
429 outgoingTcpHeader.SetSequenceNumber(SequenceNumber32(0));
430 outgoingTcpHeader.SetAckNumber(incomingHeader.GetSequenceNumber() +
432 }
433
434 // Remember that parameters refer to the incoming packet; in reply,
435 // we need to swap src/dst
436
437 outgoingTcpHeader.SetSourcePort(incomingHeader.GetDestinationPort());
438 outgoingTcpHeader.SetDestinationPort(incomingHeader.GetSourcePort());
439
440 SendPacket(rstPacket, outgoingTcpHeader, incomingDAddr, incomingSAddr);
441 }
442}
443
446 const Ipv4Header& incomingIpHeader,
447 Ptr<Ipv4Interface> incomingInterface)
448{
449 NS_LOG_FUNCTION(this << packet << incomingIpHeader << incomingInterface);
450
451 TcpHeader incomingTcpHeader;
452 IpL4Protocol::RxStatus checksumControl;
453
454 checksumControl = PacketReceived(packet,
455 incomingTcpHeader,
456 incomingIpHeader.GetSource(),
457 incomingIpHeader.GetDestination());
458
459 if (checksumControl != IpL4Protocol::RX_OK)
460 {
461 return checksumControl;
462 }
463
465 endPoints = m_endPoints->Lookup(incomingIpHeader.GetDestination(),
466 incomingTcpHeader.GetDestinationPort(),
467 incomingIpHeader.GetSource(),
468 incomingTcpHeader.GetSourcePort(),
469 incomingInterface);
470
471 if (endPoints.empty())
472 {
473 if (this->GetObject<Ipv6L3Protocol>())
474 {
475 NS_LOG_LOGIC(" No Ipv4 endpoints matched on TcpL4Protocol, trying Ipv6 " << this);
476 Ptr<Ipv6Interface> fakeInterface;
477 Ipv6Header ipv6Header;
478 Ipv6Address src;
479 Ipv6Address dst;
480
481 src = Ipv6Address::MakeIpv4MappedAddress(incomingIpHeader.GetSource());
482 dst = Ipv6Address::MakeIpv4MappedAddress(incomingIpHeader.GetDestination());
483 ipv6Header.SetSource(src);
484 ipv6Header.SetDestination(dst);
485 return (this->Receive(packet, ipv6Header, fakeInterface));
486 }
487
488 NS_LOG_LOGIC("TcpL4Protocol "
489 << this
490 << " received a packet but"
491 " no endpoints matched."
492 << " destination IP: " << incomingIpHeader.GetDestination()
493 << " destination port: " << incomingTcpHeader.GetDestinationPort()
494 << " source IP: " << incomingIpHeader.GetSource()
495 << " source port: " << incomingTcpHeader.GetSourcePort());
496
497 NoEndPointsFound(incomingTcpHeader,
498 incomingIpHeader.GetSource(),
499 incomingIpHeader.GetDestination());
500
502 }
503
504 NS_ASSERT_MSG(endPoints.size() == 1, "Demux returned more than one endpoint");
505 NS_LOG_LOGIC("TcpL4Protocol " << this
506 << " received a packet and"
507 " now forwarding it up to endpoint/socket");
508
509 (*endPoints.begin())
510 ->ForwardUp(packet, incomingIpHeader, incomingTcpHeader.GetSourcePort(), incomingInterface);
511
512 return IpL4Protocol::RX_OK;
513}
514
517 const Ipv6Header& incomingIpHeader,
518 Ptr<Ipv6Interface> interface)
519{
520 NS_LOG_FUNCTION(this << packet << incomingIpHeader.GetSource()
521 << incomingIpHeader.GetDestination());
522
523 TcpHeader incomingTcpHeader;
524 IpL4Protocol::RxStatus checksumControl;
525
526 // If we are receiving a v4-mapped packet, we will re-calculate the TCP checksum
527 // Is it worth checking every received "v6" packet to see if it is v4-mapped in
528 // order to avoid re-calculating TCP checksums for v4-mapped packets?
529
530 checksumControl = PacketReceived(packet,
531 incomingTcpHeader,
532 incomingIpHeader.GetSource(),
533 incomingIpHeader.GetDestination());
534
535 if (checksumControl != IpL4Protocol::RX_OK)
536 {
537 return checksumControl;
538 }
539
541 m_endPoints6->Lookup(incomingIpHeader.GetDestination(),
542 incomingTcpHeader.GetDestinationPort(),
543 incomingIpHeader.GetSource(),
544 incomingTcpHeader.GetSourcePort(),
545 interface);
546 if (endPoints.empty())
547 {
548 NS_LOG_LOGIC("TcpL4Protocol "
549 << this
550 << " received a packet but"
551 " no endpoints matched."
552 << " destination IP: " << incomingIpHeader.GetDestination()
553 << " destination port: " << incomingTcpHeader.GetDestinationPort()
554 << " source IP: " << incomingIpHeader.GetSource()
555 << " source port: " << incomingTcpHeader.GetSourcePort());
556
557 NoEndPointsFound(incomingTcpHeader,
558 incomingIpHeader.GetSource(),
559 incomingIpHeader.GetDestination());
560
562 }
563
564 NS_ASSERT_MSG(endPoints.size() == 1, "Demux returned more than one endpoint");
565 NS_LOG_LOGIC("TcpL4Protocol " << this
566 << " received a packet and"
567 " now forwarding it up to endpoint/socket");
568
569 (*endPoints.begin())
570 ->ForwardUp(packet, incomingIpHeader, incomingTcpHeader.GetSourcePort(), interface);
571
572 return IpL4Protocol::RX_OK;
573}
574
575void
577 const TcpHeader& outgoing,
578 const Ipv4Address& saddr,
579 const Ipv4Address& daddr,
580 Ptr<NetDevice> oif) const
581{
582 NS_LOG_FUNCTION(this << packet << saddr << daddr << oif);
583 NS_LOG_LOGIC("TcpL4Protocol " << this << " sending seq " << outgoing.GetSequenceNumber()
584 << " ack " << outgoing.GetAckNumber() << " flags "
585 << TcpHeader::FlagsToString(outgoing.GetFlags()) << " data size "
586 << packet->GetSize());
587 // XXX outgoingHeader cannot be logged
588
589 TcpHeader outgoingHeader = outgoing;
590 /** @todo UrgentPointer */
591 /* outgoingHeader.SetUrgentPointer (0); */
593 {
594 outgoingHeader.EnableChecksums();
595 }
596 outgoingHeader.InitializeChecksum(saddr, daddr, iana::internetprotocolnumbers::TCP);
597
598 packet->AddHeader(outgoingHeader);
599
600 Ptr<Ipv4> ipv4 = m_node->GetObject<Ipv4>();
601 if (ipv4)
602 {
603 Ipv4Header header;
604 header.SetSource(saddr);
605 header.SetDestination(daddr);
607 Socket::SocketErrno errno_;
608 Ptr<Ipv4Route> route;
609 if (ipv4->GetRoutingProtocol())
610 {
611 route = ipv4->GetRoutingProtocol()->RouteOutput(packet, header, oif, errno_);
612 }
613 else
614 {
615 NS_LOG_ERROR("No IPV4 Routing Protocol");
616 route = nullptr;
617 }
618 m_downTarget(packet, saddr, daddr, iana::internetprotocolnumbers::TCP, route);
619 }
620 else
621 {
622 NS_FATAL_ERROR("Trying to use Tcp on a node without an Ipv4 interface");
623 }
624}
625
626void
628 const TcpHeader& outgoing,
629 const Ipv6Address& saddr,
630 const Ipv6Address& daddr,
631 Ptr<NetDevice> oif) const
632{
633 NS_LOG_FUNCTION(this << packet << saddr << daddr << oif);
634 NS_LOG_LOGIC("TcpL4Protocol " << this << " sending seq " << outgoing.GetSequenceNumber()
635 << " ack " << outgoing.GetAckNumber() << " flags "
636 << TcpHeader::FlagsToString(outgoing.GetFlags()) << " data size "
637 << packet->GetSize());
638 // XXX outgoingHeader cannot be logged
639
640 if (daddr.IsIpv4MappedAddress())
641 {
642 return (SendPacket(packet,
643 outgoing,
644 saddr.GetIpv4MappedAddress(),
645 daddr.GetIpv4MappedAddress(),
646 oif));
647 }
648 TcpHeader outgoingHeader = outgoing;
649 /** @todo UrgentPointer */
650 /* outgoingHeader.SetUrgentPointer (0); */
652 {
653 outgoingHeader.EnableChecksums();
654 }
655 outgoingHeader.InitializeChecksum(saddr, daddr, iana::internetprotocolnumbers::TCP);
656
657 packet->AddHeader(outgoingHeader);
658
659 Ptr<Ipv6L3Protocol> ipv6 = m_node->GetObject<Ipv6L3Protocol>();
660 if (ipv6)
661 {
662 Ipv6Header header;
663 header.SetSource(saddr);
664 header.SetDestination(daddr);
666 Socket::SocketErrno errno_;
667 Ptr<Ipv6Route> route;
668 if (ipv6->GetRoutingProtocol())
669 {
670 route = ipv6->GetRoutingProtocol()->RouteOutput(packet, header, oif, errno_);
671 }
672 else
673 {
674 NS_LOG_ERROR("No IPV6 Routing Protocol");
675 route = nullptr;
676 }
677 m_downTarget6(packet, saddr, daddr, iana::internetprotocolnumbers::TCP, route);
678 }
679 else
680 {
681 NS_FATAL_ERROR("Trying to use Tcp on a node without an Ipv6 interface");
682 }
683}
684
685void
687 const TcpHeader& outgoing,
688 const Address& saddr,
689 const Address& daddr,
690 Ptr<NetDevice> oif) const
691{
692 NS_LOG_FUNCTION(this << pkt << outgoing << saddr << daddr << oif);
694 {
696
697 SendPacketV4(pkt,
698 outgoing,
701 oif);
702
703 return;
704 }
705 else if (Ipv6Address::IsMatchingType(saddr))
706 {
708
709 SendPacketV6(pkt,
710 outgoing,
713 oif);
714
715 return;
716 }
717 else if (InetSocketAddress::IsMatchingType(saddr))
718 {
721
722 SendPacketV4(pkt, outgoing, s.GetIpv4(), d.GetIpv4(), oif);
723
724 return;
725 }
727 {
730
731 SendPacketV6(pkt, outgoing, s.GetIpv6(), d.GetIpv6(), oif);
732
733 return;
734 }
735
736 NS_FATAL_ERROR("Trying to send a packet without IP addresses");
737}
738
739void
741{
742 NS_LOG_FUNCTION(this << socket);
743
744 for (auto& socketItem : m_sockets)
745 {
746 if (socketItem.second == socket)
747 {
748 return;
749 }
750 }
751 m_sockets[m_socketIndex++] = socket;
752}
753
754bool
756{
757 NS_LOG_FUNCTION(this << socket);
758
759 for (auto& socketItem : m_sockets)
760 {
761 if (socketItem.second == socket)
762 {
763 socketItem.second = nullptr;
764 m_sockets.erase(socketItem.first);
765 return true;
766 }
767 }
768
769 return false;
770}
771
772void
777
780{
781 return m_downTarget;
782}
783
784void
789
792{
793 return m_downTarget6;
794}
795
796} // namespace ns3
a polymophic address class
Definition address.h:114
An Inet6 address class.
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.
an Inet address class
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.
Callback< void, Ptr< Packet >, Ipv4Address, Ipv4Address, uint8_t, Ptr< Ipv4Route > > DownTargetCallback
callback to send packets over IPv4
Callback< void, Ptr< Packet >, Ipv6Address, Ipv6Address, uint8_t, Ptr< Ipv6Route > > DownTargetCallback6
callback to send packets over IPv6
RxStatus
Rx status codes.
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.
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.
Packet header for IPv4.
Definition ipv4-header.h:23
void SetDestination(Ipv4Address destination)
Ipv4Address GetSource() const
Ipv4Address GetDestination() const
void SetProtocol(uint8_t num)
void SetSource(Ipv4Address source)
Access to the IPv4 forwarding table, interfaces, and configuration.
Definition ipv4.h:69
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.
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.
Packet header for IPv6.
Definition ipv6-header.h:24
void SetDestination(Ipv6Address dst)
Set the "Destination address" field.
void SetSource(Ipv6Address src)
Set the "Source address" field.
Ipv6Address GetDestination() const
Get the "Destination address" field.
Ipv6Address GetSource() const
Get the "Source address" field.
void SetNextHeader(uint8_t next)
Set the "Next header" field.
Access to the IPv6 forwarding table, interfaces, and configuration.
Definition ipv6.h:71
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()
Definition node.cc:267
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.
Definition object.cc:410
Ptr< T > GetObject() const
Get a pointer to the requested aggregated Object.
Definition object.h:518
virtual void DoDispose()
Destructor implementation.
Definition object.cc:431
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:70
Base class for all RTT Estimators.
static TypeId GetTypeId()
Get the type ID.
SocketErrno
Enumeration of the possible errors returned by a socket.
Definition socket.h:73
Congestion control abstract class.
static TypeId GetTypeId()
Get the type ID.
Definition tcp-cubic.cc:20
Header for the Transmission Control Protocol.
Definition tcp-header.h:36
void SetDestinationPort(uint16_t port)
Set the destination port.
Definition tcp-header.cc:59
void SetSequenceNumber(SequenceNumber32 sequenceNumber)
Set the sequence Number.
Definition tcp-header.cc:65
SequenceNumber32 GetSequenceNumber() const
Get the sequence number.
uint16_t GetDestinationPort() const
Get the destination port.
void SetFlags(uint8_t flags)
Set flags of the header.
Definition tcp-header.cc:77
void InitializeChecksum(const Ipv4Address &source, const Ipv4Address &destination, uint8_t protocol)
Initialize the TCP checksum.
static std::string FlagsToString(uint8_t flags, const std::string &delimiter="|")
Converts an integer into a human readable list of Tcp flags.
Definition tcp-header.cc:28
uint16_t GetSourcePort() const
Get the source port.
Definition tcp-header.cc:95
void SetSourcePort(uint16_t port)
Set the source port.
Definition tcp-header.cc:53
void EnableChecksums()
Enable checksum calculation for TCP.
Definition tcp-header.cc:47
void SetAckNumber(SequenceNumber32 ackNumber)
Set the ACK number.
Definition tcp-header.cc:71
uint8_t GetFlags() const
Get the flags.
SequenceNumber32 GetAckNumber() const
Get the ACK number.
bool IsChecksumOk() const
Is the TCP checksum correct ?
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.
TypeId m_congestionTypeId
The socket TypeId.
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.
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...
std::unordered_map< uint64_t, Ptr< TcpSocketBase > > m_sockets
Unordered map of socket IDs and corresponding sockets.
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).
uint64_t m_socketIndex
index of the next socket to be created
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.
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.
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.
recovery abstract class
a unique identifier for an interface.
Definition type-id.h:50
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1003
std::string GetName() const
Get the name.
Definition type-id.cc:1063
uint16_t port
Definition dsdv-manet.cc:33
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition assert.h:55
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Definition assert.h:76
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...
Definition callback.h:690
#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.
Definition log.h:253
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:201
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition log.h:267
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition log.h:281
#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.
Definition log.h:274
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:627
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition object-base.h:35
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition ptr.h:492
SequenceNumber< uint32_t > SequenceNumber32
32 bit Sequence number.
constexpr uint8_t TCP
Transmission Control [RFC9293].
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ObjectPtrContainerValue ObjectMapValue
ObjectMapValue is an alias for ObjectPtrContainerValue.
Definition object-map.h:29
Ptr< const AttributeChecker > MakeTypeIdChecker()
Definition type-id.cc:1359
Ptr< const AttributeAccessor > MakeObjectMapAccessor(U T::*memberVariable)
MakeAccessorHelper implementation for ObjectVector.
Definition object-map.h:65
Ptr< const AttributeChecker > MakeObjectMapChecker()
Definition object-map.h:110
Ptr< const AttributeAccessor > MakeTypeIdAccessor(T1 a1)
Definition type-id.h:666