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
59/* see http://www.iana.org/assignments/protocol-numbers */
60const uint8_t TcpL4Protocol::PROT_NUMBER = 6;
61
62TypeId
64{
65 static TypeId tid =
66 TypeId("ns3::TcpL4Protocol")
68 .SetGroupName("Internet")
69 .AddConstructor<TcpL4Protocol>()
70 .AddAttribute("RttEstimatorType",
71 "Type of RttEstimator objects.",
75 .AddAttribute("SocketType",
76 "Socket type of TCP objects.",
80 .AddAttribute("RecoveryType",
81 "Recovery type of TCP objects.",
85 .AddAttribute("SocketList",
86 "A container of sockets associated to this protocol. "
87 "The underlying type is an unordered map, the attribute name "
88 "is kept for backward compatibility.",
92 return tid;
93}
94
96 : m_endPoints(new Ipv4EndPointDemux()),
97 m_endPoints6(new Ipv6EndPointDemux())
98{
99 NS_LOG_FUNCTION(this);
100}
101
106
107void
109{
110 NS_LOG_FUNCTION(this);
111 m_node = node;
112}
113
114void
116{
117 NS_LOG_FUNCTION(this);
118 Ptr<Node> node = this->GetObject<Node>();
119 Ptr<Ipv4> ipv4 = this->GetObject<Ipv4>();
120 Ptr<Ipv6> ipv6 = node->GetObject<Ipv6>();
121
122 if (!m_node)
123 {
124 if (node && (ipv4 || ipv6))
125 {
126 this->SetNode(node);
128 tcpFactory->SetTcp(this);
129 node->AggregateObject(tcpFactory);
130 }
131 }
132
133 // We set at least one of our 2 down targets to the IPv4/IPv6 send
134 // functions. Since these functions have different prototypes, we
135 // need to keep track of whether we are connected to an IPv4 or
136 // IPv6 lower layer and call the appropriate one.
137
138 if (ipv4 && m_downTarget.IsNull())
139 {
140 ipv4->Insert(this);
142 }
143 if (ipv6 && m_downTarget6.IsNull())
144 {
145 ipv6->Insert(this);
147 }
149}
150
151int
153{
154 return PROT_NUMBER;
155}
156
157void
159{
160 NS_LOG_FUNCTION(this);
161 m_sockets.clear();
162
163 if (m_endPoints != nullptr)
164 {
165 delete m_endPoints;
166 m_endPoints = nullptr;
167 }
168
169 if (m_endPoints6 != nullptr)
170 {
171 delete m_endPoints6;
172 m_endPoints6 = nullptr;
173 }
174
175 m_node = nullptr;
179}
180
183{
184 return CreateSocket(congestionTypeId, m_recoveryTypeId);
185}
186
188TcpL4Protocol::CreateSocket(TypeId congestionTypeId, TypeId recoveryTypeId)
189{
190 NS_LOG_FUNCTION(this << congestionTypeId.GetName());
191 ObjectFactory rttFactory;
192 ObjectFactory congestionAlgorithmFactory;
193 ObjectFactory recoveryAlgorithmFactory;
194 rttFactory.SetTypeId(m_rttTypeId);
195 congestionAlgorithmFactory.SetTypeId(congestionTypeId);
196 recoveryAlgorithmFactory.SetTypeId(recoveryTypeId);
197
198 Ptr<RttEstimator> rtt = rttFactory.Create<RttEstimator>();
200 Ptr<TcpCongestionOps> algo = congestionAlgorithmFactory.Create<TcpCongestionOps>();
201 Ptr<TcpRecoveryOps> recovery = recoveryAlgorithmFactory.Create<TcpRecoveryOps>();
202
203 socket->SetNode(m_node);
204 socket->SetTcp(this);
205 socket->SetRtt(rtt);
206 socket->SetCongestionControlAlgorithm(algo);
207 socket->SetRecoveryAlgorithm(recovery);
208
209 m_sockets[m_socketIndex++] = socket;
210 return socket;
211}
212
218
221{
222 NS_LOG_FUNCTION(this);
223 return m_endPoints->Allocate();
224}
225
228{
229 NS_LOG_FUNCTION(this << address);
230 return m_endPoints->Allocate(address);
231}
232
235{
236 NS_LOG_FUNCTION(this << boundNetDevice << port);
237 return m_endPoints->Allocate(boundNetDevice, port);
238}
239
241TcpL4Protocol::Allocate(Ptr<NetDevice> boundNetDevice, Ipv4Address address, uint16_t port)
242{
243 NS_LOG_FUNCTION(this << boundNetDevice << address << port);
244 return m_endPoints->Allocate(boundNetDevice, address, port);
245}
246
249 Ipv4Address localAddress,
250 uint16_t localPort,
251 Ipv4Address peerAddress,
252 uint16_t peerPort)
253{
254 NS_LOG_FUNCTION(this << boundNetDevice << localAddress << localPort << peerAddress << peerPort);
255 return m_endPoints->Allocate(boundNetDevice, localAddress, localPort, peerAddress, peerPort);
256}
257
258void
260{
261 NS_LOG_FUNCTION(this << endPoint);
262 m_endPoints->DeAllocate(endPoint);
263}
264
267{
268 NS_LOG_FUNCTION(this);
269 return m_endPoints6->Allocate();
270}
271
274{
275 NS_LOG_FUNCTION(this << address);
276 return m_endPoints6->Allocate(address);
277}
278
281{
282 NS_LOG_FUNCTION(this << boundNetDevice << port);
283 return m_endPoints6->Allocate(boundNetDevice, port);
284}
285
287TcpL4Protocol::Allocate6(Ptr<NetDevice> boundNetDevice, Ipv6Address address, uint16_t port)
288{
289 NS_LOG_FUNCTION(this << boundNetDevice << address << port);
290 return m_endPoints6->Allocate(boundNetDevice, address, port);
291}
292
295 Ipv6Address localAddress,
296 uint16_t localPort,
297 Ipv6Address peerAddress,
298 uint16_t peerPort)
299{
300 NS_LOG_FUNCTION(this << boundNetDevice << localAddress << localPort << peerAddress << peerPort);
301 return m_endPoints6->Allocate(boundNetDevice, localAddress, localPort, peerAddress, peerPort);
302}
303
304void
306{
307 NS_LOG_FUNCTION(this << endPoint);
308 m_endPoints6->DeAllocate(endPoint);
309}
310
311void
313 uint8_t icmpTtl,
314 uint8_t icmpType,
315 uint8_t icmpCode,
316 uint32_t icmpInfo,
317 Ipv4Address payloadSource,
318 Ipv4Address payloadDestination,
319 const uint8_t payload[8])
320{
321 NS_LOG_FUNCTION(this << icmpSource << (uint16_t)icmpTtl << (uint16_t)icmpType
322 << (uint16_t)icmpCode << icmpInfo << payloadSource << payloadDestination);
323 uint16_t src;
324 uint16_t dst;
325 src = payload[0] << 8;
326 src |= payload[1];
327 dst = payload[2] << 8;
328 dst |= payload[3];
329
330 Ipv4EndPoint* endPoint = m_endPoints->SimpleLookup(payloadSource, src, payloadDestination, dst);
331 if (endPoint != nullptr)
332 {
333 endPoint->ForwardIcmp(icmpSource, icmpTtl, icmpType, icmpCode, icmpInfo);
334 }
335 else
336 {
337 NS_LOG_DEBUG("no endpoint found source=" << payloadSource
338 << ", destination=" << payloadDestination
339 << ", src=" << src << ", dst=" << dst);
340 }
341}
342
343void
345 uint8_t icmpTtl,
346 uint8_t icmpType,
347 uint8_t icmpCode,
348 uint32_t icmpInfo,
349 Ipv6Address payloadSource,
350 Ipv6Address payloadDestination,
351 const uint8_t payload[8])
352{
353 NS_LOG_FUNCTION(this << icmpSource << (uint16_t)icmpTtl << (uint16_t)icmpType
354 << (uint16_t)icmpCode << icmpInfo << payloadSource << payloadDestination);
355 uint16_t src;
356 uint16_t dst;
357 src = payload[0] << 8;
358 src |= payload[1];
359 dst = payload[2] << 8;
360 dst |= payload[3];
361
362 Ipv6EndPoint* endPoint =
363 m_endPoints6->SimpleLookup(payloadSource, src, payloadDestination, dst);
364 if (endPoint != nullptr)
365 {
366 endPoint->ForwardIcmp(icmpSource, icmpTtl, icmpType, icmpCode, icmpInfo);
367 }
368 else
369 {
370 NS_LOG_DEBUG("no endpoint found source=" << payloadSource
371 << ", destination=" << payloadDestination
372 << ", src=" << src << ", dst=" << dst);
373 }
374}
375
378 TcpHeader& incomingTcpHeader,
379 const Address& source,
380 const Address& destination)
381{
382 NS_LOG_FUNCTION(this << packet << incomingTcpHeader << source << destination);
383
385 {
386 incomingTcpHeader.EnableChecksums();
387 incomingTcpHeader.InitializeChecksum(source, destination, PROT_NUMBER);
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, PROT_NUMBER);
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);
606 header.SetProtocol(PROT_NUMBER);
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, PROT_NUMBER, 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, PROT_NUMBER);
656
657 packet->AddHeader(outgoingHeader);
658
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, PROT_NUMBER, 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: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...
static const uint8_t PROT_NUMBER
protocol number (0x6)
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:48
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
AttributeValue implementation for TypeId.
Definition type-id.h:617
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
ObjectPtrContainerValue ObjectMapValue
ObjectMapValue is an alias for ObjectPtrContainerValue.
Definition object-map.h:29
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 AttributeChecker > MakeTypeIdChecker()
Definition type-id.cc:1320
Ptr< const AttributeAccessor > MakeTypeIdAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Definition type-id.h:617
#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