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/log.h"
32#include "ns3/node.h"
33#include "ns3/nstime.h"
34#include "ns3/object-map.h"
35#include "ns3/packet.h"
36#include "ns3/simulator.h"
37
38#include <iomanip>
39#include <sstream>
40#include <unordered_map>
41#include <vector>
42
43namespace ns3
44{
45
46NS_LOG_COMPONENT_DEFINE("TcpL4Protocol");
47
48NS_OBJECT_ENSURE_REGISTERED(TcpL4Protocol);
49
50// TcpL4Protocol stuff----------------------------------------------------------
51
52#undef NS_LOG_APPEND_CONTEXT
53#define NS_LOG_APPEND_CONTEXT \
54 if (m_node) \
55 { \
56 std::clog << " [node " << m_node->GetId() << "] "; \
57 }
58
59TypeId
61{
62 static TypeId tid =
63 TypeId("ns3::TcpL4Protocol")
65 .SetGroupName("Internet")
66 .AddConstructor<TcpL4Protocol>()
67 .AddAttribute("RttEstimatorType",
68 "Type of RttEstimator objects.",
72 .AddAttribute("SocketType",
73 "Socket type of TCP objects.",
77 .AddAttribute("RecoveryType",
78 "Recovery type of TCP objects.",
82 .AddAttribute("SocketList",
83 "A container of sockets associated to this protocol. "
84 "The underlying type is an unordered map, the attribute name "
85 "is kept for backward compatibility.",
89 return tid;
90}
91
93 : m_endPoints(new Ipv4EndPointDemux()),
94 m_endPoints6(new Ipv6EndPointDemux())
95{
96 NS_LOG_FUNCTION(this);
97}
98
103
104void
106{
107 NS_LOG_FUNCTION(this);
108 m_node = node;
109}
110
111void
113{
114 NS_LOG_FUNCTION(this);
115 Ptr<Node> node = this->GetObject<Node>();
116 Ptr<Ipv4> ipv4 = this->GetObject<Ipv4>();
117 Ptr<Ipv6> ipv6 = node->GetObject<Ipv6>();
118
119 if (!m_node)
120 {
121 if (node && (ipv4 || ipv6))
122 {
123 this->SetNode(node);
125 tcpFactory->SetTcp(this);
126 node->AggregateObject(tcpFactory);
127 }
128 }
129
130 // We set at least one of our 2 down targets to the IPv4/IPv6 send
131 // functions. Since these functions have different prototypes, we
132 // need to keep track of whether we are connected to an IPv4 or
133 // IPv6 lower layer and call the appropriate one.
134
135 if (ipv4 && m_downTarget.IsNull())
136 {
137 ipv4->Insert(this);
139 }
140 if (ipv6 && m_downTarget6.IsNull())
141 {
142 ipv6->Insert(this);
144 }
146}
147
148int
150{
151 return PROT_NUMBER;
152}
153
154void
156{
157 NS_LOG_FUNCTION(this);
158 m_sockets.clear();
159
160 if (m_endPoints != nullptr)
161 {
162 delete m_endPoints;
163 m_endPoints = nullptr;
164 }
165
166 if (m_endPoints6 != nullptr)
167 {
168 delete m_endPoints6;
169 m_endPoints6 = nullptr;
170 }
171
172 m_node = nullptr;
176}
177
180{
181 return CreateSocket(congestionTypeId, m_recoveryTypeId);
182}
183
185TcpL4Protocol::CreateSocket(TypeId congestionTypeId, TypeId recoveryTypeId)
186{
187 NS_LOG_FUNCTION(this << congestionTypeId.GetName());
188 ObjectFactory rttFactory;
189 ObjectFactory congestionAlgorithmFactory;
190 ObjectFactory recoveryAlgorithmFactory;
191 rttFactory.SetTypeId(m_rttTypeId);
192 congestionAlgorithmFactory.SetTypeId(congestionTypeId);
193 recoveryAlgorithmFactory.SetTypeId(recoveryTypeId);
194
195 Ptr<RttEstimator> rtt = rttFactory.Create<RttEstimator>();
197 Ptr<TcpCongestionOps> algo = congestionAlgorithmFactory.Create<TcpCongestionOps>();
198 Ptr<TcpRecoveryOps> recovery = recoveryAlgorithmFactory.Create<TcpRecoveryOps>();
199
200 socket->SetNode(m_node);
201 socket->SetTcp(this);
202 socket->SetRtt(rtt);
203 socket->SetCongestionControlAlgorithm(algo);
204 socket->SetRecoveryAlgorithm(recovery);
205
206 m_sockets[m_socketIndex++] = socket;
207 return socket;
208}
209
215
218{
219 NS_LOG_FUNCTION(this);
220 return m_endPoints->Allocate();
221}
222
225{
226 NS_LOG_FUNCTION(this << address);
227 return m_endPoints->Allocate(address);
228}
229
232{
233 NS_LOG_FUNCTION(this << boundNetDevice << port);
234 return m_endPoints->Allocate(boundNetDevice, port);
235}
236
238TcpL4Protocol::Allocate(Ptr<NetDevice> boundNetDevice, Ipv4Address address, uint16_t port)
239{
240 NS_LOG_FUNCTION(this << boundNetDevice << address << port);
241 return m_endPoints->Allocate(boundNetDevice, address, port);
242}
243
246 Ipv4Address localAddress,
247 uint16_t localPort,
248 Ipv4Address peerAddress,
249 uint16_t peerPort)
250{
251 NS_LOG_FUNCTION(this << boundNetDevice << localAddress << localPort << peerAddress << peerPort);
252 return m_endPoints->Allocate(boundNetDevice, localAddress, localPort, peerAddress, peerPort);
253}
254
255void
257{
258 NS_LOG_FUNCTION(this << endPoint);
259 m_endPoints->DeAllocate(endPoint);
260}
261
264{
265 NS_LOG_FUNCTION(this);
266 return m_endPoints6->Allocate();
267}
268
271{
272 NS_LOG_FUNCTION(this << address);
273 return m_endPoints6->Allocate(address);
274}
275
278{
279 NS_LOG_FUNCTION(this << boundNetDevice << port);
280 return m_endPoints6->Allocate(boundNetDevice, port);
281}
282
284TcpL4Protocol::Allocate6(Ptr<NetDevice> boundNetDevice, Ipv6Address address, uint16_t port)
285{
286 NS_LOG_FUNCTION(this << boundNetDevice << address << port);
287 return m_endPoints6->Allocate(boundNetDevice, address, port);
288}
289
292 Ipv6Address localAddress,
293 uint16_t localPort,
294 Ipv6Address peerAddress,
295 uint16_t peerPort)
296{
297 NS_LOG_FUNCTION(this << boundNetDevice << localAddress << localPort << peerAddress << peerPort);
298 return m_endPoints6->Allocate(boundNetDevice, localAddress, localPort, peerAddress, peerPort);
299}
300
301void
303{
304 NS_LOG_FUNCTION(this << endPoint);
305 m_endPoints6->DeAllocate(endPoint);
306}
307
308void
310 uint8_t icmpTtl,
311 uint8_t icmpType,
312 uint8_t icmpCode,
313 uint32_t icmpInfo,
314 Ipv4Address payloadSource,
315 Ipv4Address payloadDestination,
316 const uint8_t payload[8])
317{
318 NS_LOG_FUNCTION(this << icmpSource << (uint16_t)icmpTtl << (uint16_t)icmpType
319 << (uint16_t)icmpCode << icmpInfo << payloadSource << payloadDestination);
320 uint16_t src;
321 uint16_t dst;
322 src = payload[0] << 8;
323 src |= payload[1];
324 dst = payload[2] << 8;
325 dst |= payload[3];
326
327 Ipv4EndPoint* endPoint = m_endPoints->SimpleLookup(payloadSource, src, payloadDestination, dst);
328 if (endPoint != nullptr)
329 {
330 endPoint->ForwardIcmp(icmpSource, icmpTtl, icmpType, icmpCode, icmpInfo);
331 }
332 else
333 {
334 NS_LOG_DEBUG("no endpoint found source=" << payloadSource
335 << ", destination=" << payloadDestination
336 << ", src=" << src << ", dst=" << dst);
337 }
338}
339
340void
342 uint8_t icmpTtl,
343 uint8_t icmpType,
344 uint8_t icmpCode,
345 uint32_t icmpInfo,
346 Ipv6Address payloadSource,
347 Ipv6Address payloadDestination,
348 const uint8_t payload[8])
349{
350 NS_LOG_FUNCTION(this << icmpSource << (uint16_t)icmpTtl << (uint16_t)icmpType
351 << (uint16_t)icmpCode << icmpInfo << payloadSource << payloadDestination);
352 uint16_t src;
353 uint16_t dst;
354 src = payload[0] << 8;
355 src |= payload[1];
356 dst = payload[2] << 8;
357 dst |= payload[3];
358
359 Ipv6EndPoint* endPoint =
360 m_endPoints6->SimpleLookup(payloadSource, src, payloadDestination, dst);
361 if (endPoint != nullptr)
362 {
363 endPoint->ForwardIcmp(icmpSource, icmpTtl, icmpType, icmpCode, icmpInfo);
364 }
365 else
366 {
367 NS_LOG_DEBUG("no endpoint found source=" << payloadSource
368 << ", destination=" << payloadDestination
369 << ", src=" << src << ", dst=" << dst);
370 }
371}
372
375 TcpHeader& incomingTcpHeader,
376 const Address& source,
377 const Address& destination)
378{
379 NS_LOG_FUNCTION(this << packet << incomingTcpHeader << source << destination);
380
382 {
383 incomingTcpHeader.EnableChecksums();
384 incomingTcpHeader.InitializeChecksum(source, destination, PROT_NUMBER);
385 }
386
387 packet->PeekHeader(incomingTcpHeader);
388
389 NS_LOG_LOGIC("TcpL4Protocol " << this << " receiving seq "
390 << incomingTcpHeader.GetSequenceNumber() << " ack "
391 << incomingTcpHeader.GetAckNumber() << " flags "
392 << TcpHeader::FlagsToString(incomingTcpHeader.GetFlags())
393 << " data size " << packet->GetSize());
394
395 if (!incomingTcpHeader.IsChecksumOk())
396 {
397 NS_LOG_INFO("Bad checksum, dropping packet!");
399 }
400
401 return IpL4Protocol::RX_OK;
402}
403
404void
406 const Address& incomingSAddr,
407 const Address& incomingDAddr)
408{
409 NS_LOG_FUNCTION(this << incomingHeader << incomingSAddr << incomingDAddr);
410
411 if (!(incomingHeader.GetFlags() & TcpHeader::RST))
412 {
413 // build a RST packet and send
414 Ptr<Packet> rstPacket = Create<Packet>();
415 TcpHeader outgoingTcpHeader;
416
417 if (incomingHeader.GetFlags() & TcpHeader::ACK)
418 {
419 // ACK bit was set
420 outgoingTcpHeader.SetFlags(TcpHeader::RST);
421 outgoingTcpHeader.SetSequenceNumber(incomingHeader.GetAckNumber());
422 }
423 else
424 {
425 outgoingTcpHeader.SetFlags(TcpHeader::RST | TcpHeader::ACK);
426 outgoingTcpHeader.SetSequenceNumber(SequenceNumber32(0));
427 outgoingTcpHeader.SetAckNumber(incomingHeader.GetSequenceNumber() +
429 }
430
431 // Remember that parameters refer to the incoming packet; in reply,
432 // we need to swap src/dst
433
434 outgoingTcpHeader.SetSourcePort(incomingHeader.GetDestinationPort());
435 outgoingTcpHeader.SetDestinationPort(incomingHeader.GetSourcePort());
436
437 SendPacket(rstPacket, outgoingTcpHeader, incomingDAddr, incomingSAddr);
438 }
439}
440
443 const Ipv4Header& incomingIpHeader,
444 Ptr<Ipv4Interface> incomingInterface)
445{
446 NS_LOG_FUNCTION(this << packet << incomingIpHeader << incomingInterface);
447
448 TcpHeader incomingTcpHeader;
449 IpL4Protocol::RxStatus checksumControl;
450
451 checksumControl = PacketReceived(packet,
452 incomingTcpHeader,
453 incomingIpHeader.GetSource(),
454 incomingIpHeader.GetDestination());
455
456 if (checksumControl != IpL4Protocol::RX_OK)
457 {
458 return checksumControl;
459 }
460
462 endPoints = m_endPoints->Lookup(incomingIpHeader.GetDestination(),
463 incomingTcpHeader.GetDestinationPort(),
464 incomingIpHeader.GetSource(),
465 incomingTcpHeader.GetSourcePort(),
466 incomingInterface);
467
468 if (endPoints.empty())
469 {
470 if (this->GetObject<Ipv6L3Protocol>())
471 {
472 NS_LOG_LOGIC(" No Ipv4 endpoints matched on TcpL4Protocol, trying Ipv6 " << this);
473 Ptr<Ipv6Interface> fakeInterface;
474 Ipv6Header ipv6Header;
475 Ipv6Address src;
476 Ipv6Address dst;
477
478 src = Ipv6Address::MakeIpv4MappedAddress(incomingIpHeader.GetSource());
479 dst = Ipv6Address::MakeIpv4MappedAddress(incomingIpHeader.GetDestination());
480 ipv6Header.SetSource(src);
481 ipv6Header.SetDestination(dst);
482 return (this->Receive(packet, ipv6Header, fakeInterface));
483 }
484
485 NS_LOG_LOGIC("TcpL4Protocol "
486 << this
487 << " received a packet but"
488 " no endpoints matched."
489 << " destination IP: " << incomingIpHeader.GetDestination()
490 << " destination port: " << incomingTcpHeader.GetDestinationPort()
491 << " source IP: " << incomingIpHeader.GetSource()
492 << " source port: " << incomingTcpHeader.GetSourcePort());
493
494 NoEndPointsFound(incomingTcpHeader,
495 incomingIpHeader.GetSource(),
496 incomingIpHeader.GetDestination());
497
499 }
500
501 NS_ASSERT_MSG(endPoints.size() == 1, "Demux returned more than one endpoint");
502 NS_LOG_LOGIC("TcpL4Protocol " << this
503 << " received a packet and"
504 " now forwarding it up to endpoint/socket");
505
506 (*endPoints.begin())
507 ->ForwardUp(packet, incomingIpHeader, incomingTcpHeader.GetSourcePort(), incomingInterface);
508
509 return IpL4Protocol::RX_OK;
510}
511
514 const Ipv6Header& incomingIpHeader,
515 Ptr<Ipv6Interface> interface)
516{
517 NS_LOG_FUNCTION(this << packet << incomingIpHeader.GetSource()
518 << incomingIpHeader.GetDestination());
519
520 TcpHeader incomingTcpHeader;
521 IpL4Protocol::RxStatus checksumControl;
522
523 // If we are receiving a v4-mapped packet, we will re-calculate the TCP checksum
524 // Is it worth checking every received "v6" packet to see if it is v4-mapped in
525 // order to avoid re-calculating TCP checksums for v4-mapped packets?
526
527 checksumControl = PacketReceived(packet,
528 incomingTcpHeader,
529 incomingIpHeader.GetSource(),
530 incomingIpHeader.GetDestination());
531
532 if (checksumControl != IpL4Protocol::RX_OK)
533 {
534 return checksumControl;
535 }
536
538 m_endPoints6->Lookup(incomingIpHeader.GetDestination(),
539 incomingTcpHeader.GetDestinationPort(),
540 incomingIpHeader.GetSource(),
541 incomingTcpHeader.GetSourcePort(),
542 interface);
543 if (endPoints.empty())
544 {
545 NS_LOG_LOGIC("TcpL4Protocol "
546 << this
547 << " received a packet but"
548 " no endpoints matched."
549 << " destination IP: " << incomingIpHeader.GetDestination()
550 << " destination port: " << incomingTcpHeader.GetDestinationPort()
551 << " source IP: " << incomingIpHeader.GetSource()
552 << " source port: " << incomingTcpHeader.GetSourcePort());
553
554 NoEndPointsFound(incomingTcpHeader,
555 incomingIpHeader.GetSource(),
556 incomingIpHeader.GetDestination());
557
559 }
560
561 NS_ASSERT_MSG(endPoints.size() == 1, "Demux returned more than one endpoint");
562 NS_LOG_LOGIC("TcpL4Protocol " << this
563 << " received a packet and"
564 " now forwarding it up to endpoint/socket");
565
566 (*endPoints.begin())
567 ->ForwardUp(packet, incomingIpHeader, incomingTcpHeader.GetSourcePort(), interface);
568
569 return IpL4Protocol::RX_OK;
570}
571
572void
574 const TcpHeader& outgoing,
575 const Ipv4Address& saddr,
576 const Ipv4Address& daddr,
577 Ptr<NetDevice> oif) const
578{
579 NS_LOG_FUNCTION(this << packet << saddr << daddr << oif);
580 NS_LOG_LOGIC("TcpL4Protocol " << this << " sending seq " << outgoing.GetSequenceNumber()
581 << " ack " << outgoing.GetAckNumber() << " flags "
582 << TcpHeader::FlagsToString(outgoing.GetFlags()) << " data size "
583 << packet->GetSize());
584 // XXX outgoingHeader cannot be logged
585
586 TcpHeader outgoingHeader = outgoing;
587 /** @todo UrgentPointer */
588 /* outgoingHeader.SetUrgentPointer (0); */
590 {
591 outgoingHeader.EnableChecksums();
592 }
593 outgoingHeader.InitializeChecksum(saddr, daddr, PROT_NUMBER);
594
595 packet->AddHeader(outgoingHeader);
596
597 Ptr<Ipv4> ipv4 = m_node->GetObject<Ipv4>();
598 if (ipv4)
599 {
600 Ipv4Header header;
601 header.SetSource(saddr);
602 header.SetDestination(daddr);
603 header.SetProtocol(PROT_NUMBER);
604 Socket::SocketErrno errno_;
605 Ptr<Ipv4Route> route;
606 if (ipv4->GetRoutingProtocol())
607 {
608 route = ipv4->GetRoutingProtocol()->RouteOutput(packet, header, oif, errno_);
609 }
610 else
611 {
612 NS_LOG_ERROR("No IPV4 Routing Protocol");
613 route = nullptr;
614 }
615 m_downTarget(packet, saddr, daddr, PROT_NUMBER, route);
616 }
617 else
618 {
619 NS_FATAL_ERROR("Trying to use Tcp on a node without an Ipv4 interface");
620 }
621}
622
623void
625 const TcpHeader& outgoing,
626 const Ipv6Address& saddr,
627 const Ipv6Address& daddr,
628 Ptr<NetDevice> oif) const
629{
630 NS_LOG_FUNCTION(this << packet << saddr << daddr << oif);
631 NS_LOG_LOGIC("TcpL4Protocol " << this << " sending seq " << outgoing.GetSequenceNumber()
632 << " ack " << outgoing.GetAckNumber() << " flags "
633 << TcpHeader::FlagsToString(outgoing.GetFlags()) << " data size "
634 << packet->GetSize());
635 // XXX outgoingHeader cannot be logged
636
637 if (daddr.IsIpv4MappedAddress())
638 {
639 return (SendPacket(packet,
640 outgoing,
641 saddr.GetIpv4MappedAddress(),
642 daddr.GetIpv4MappedAddress(),
643 oif));
644 }
645 TcpHeader outgoingHeader = outgoing;
646 /** @todo UrgentPointer */
647 /* outgoingHeader.SetUrgentPointer (0); */
649 {
650 outgoingHeader.EnableChecksums();
651 }
652 outgoingHeader.InitializeChecksum(saddr, daddr, PROT_NUMBER);
653
654 packet->AddHeader(outgoingHeader);
655
657 if (ipv6)
658 {
659 Ipv6Header header;
660 header.SetSource(saddr);
661 header.SetDestination(daddr);
663 Socket::SocketErrno errno_;
664 Ptr<Ipv6Route> route;
665 if (ipv6->GetRoutingProtocol())
666 {
667 route = ipv6->GetRoutingProtocol()->RouteOutput(packet, header, oif, errno_);
668 }
669 else
670 {
671 NS_LOG_ERROR("No IPV6 Routing Protocol");
672 route = nullptr;
673 }
674 m_downTarget6(packet, saddr, daddr, PROT_NUMBER, route);
675 }
676 else
677 {
678 NS_FATAL_ERROR("Trying to use Tcp on a node without an Ipv6 interface");
679 }
680}
681
682void
684 const TcpHeader& outgoing,
685 const Address& saddr,
686 const Address& daddr,
687 Ptr<NetDevice> oif) const
688{
689 NS_LOG_FUNCTION(this << pkt << outgoing << saddr << daddr << oif);
691 {
693
694 SendPacketV4(pkt,
695 outgoing,
698 oif);
699
700 return;
701 }
702 else if (Ipv6Address::IsMatchingType(saddr))
703 {
705
706 SendPacketV6(pkt,
707 outgoing,
710 oif);
711
712 return;
713 }
714 else if (InetSocketAddress::IsMatchingType(saddr))
715 {
718
719 SendPacketV4(pkt, outgoing, s.GetIpv4(), d.GetIpv4(), oif);
720
721 return;
722 }
724 {
727
728 SendPacketV6(pkt, outgoing, s.GetIpv6(), d.GetIpv6(), oif);
729
730 return;
731 }
732
733 NS_FATAL_ERROR("Trying to send a packet without IP addresses");
734}
735
736void
738{
739 NS_LOG_FUNCTION(this << socket);
740
741 for (auto& socketItem : m_sockets)
742 {
743 if (socketItem.second == socket)
744 {
745 return;
746 }
747 }
748 m_sockets[m_socketIndex++] = socket;
749}
750
751bool
753{
754 NS_LOG_FUNCTION(this << socket);
755
756 for (auto& socketItem : m_sockets)
757 {
758 if (socketItem.second == socket)
759 {
760 socketItem.second = nullptr;
761 m_sockets.erase(socketItem.first);
762 return true;
763 }
764 }
765
766 return false;
767}
768
769void
774
777{
778 return m_downTarget;
779}
780
781void
786
789{
790 return m_downTarget6;
791}
792
793} // namespace ns3
a polymophic address class
Definition address.h:90
void Nullify()
Discard the implementation, set it to null.
Definition callback.h:561
bool IsNull() const
Check for null implementation.
Definition callback.h:555
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.
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.
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.
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.
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.
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:412
Ptr< T > GetObject() const
Get a pointer to the requested aggregated Object.
Definition object.h:511
virtual void DoDispose()
Destructor implementation.
Definition object.cc:433
Smart pointer class similar to boost::intrusive_ptr.
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:25
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.
static constexpr uint8_t PROT_NUMBER
Protocol number (see http://www.iana.org/assignments/protocol-numbers)
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:49
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
std::string GetName() const
Get the name.
Definition type-id.cc:1061
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:75
#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:243
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition log.h:257
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition log.h:271
#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:264
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:619
#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:436
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...
Definition callback.h:684
ObjectPtrContainerValue ObjectMapValue
ObjectMapValue is an alias for ObjectPtrContainerValue.
Definition object-map.h:29
Ptr< const AttributeChecker > MakeTypeIdChecker()
Definition type-id.cc:1335
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:641