NetSim Source Code Help v14.4
All 13 Components
 
Loading...
Searching...
No Matches
TCP_Outgoing.c
1/************************************************************************************
2* Copyright (C) 2023 *
3* TETCOS, Bangalore. India *
4* *
5* Tetcos owns the intellectual property rights in the Product and its content. *
6* The copying, redistribution, reselling or publication of any or all of the *
7* Product or its content without express prior written consent of Tetcos is *
8* prohibited. Ownership and / or any other right relating to the software and all *
9* intellectual property rights therein shall remain at all times with Tetcos. *
10* *
11* Author: Shashi Kant Suman *
12* *
13* ---------------------------------------------------------------------------------*/
14#include "main.h"
15#include "TCP.h"
16#include "TCP_Header.h"
17
18void send_segment(PNETSIM_SOCKET s)
19{
20 PTCB t = s->tcb;
21 UINT32 seq = t->SND.NXT;
22 if (!s->sId)
23 fnNetSimError("SOCKETINTERFACE is NULL for TCP connection %s:%d %s:%d in function %s\n",
24 s->localAddr->ip->str_ip,
25 s->localAddr->port,
26 s->remoteAddr->ip->str_ip,
27 s->remoteAddr->port,
28 __FUNCTION__);
29 NetSim_PACKET* p = fn_NetSim_Socket_GetPacketFromInterface(s->sId, 0);
30 if (!p)
31 s->waitFromApp = true; //Enable flag to signal application waiting.
32
33 t->SND.WND = window_scale_get_cwnd(s);
34 assert(t->SND.WND >= t->get_MSS(s));
35 while (p)
36 {
37 UINT32 l = (UINT32)p->pstruAppData->dPacketSize;
38 if (seq + l <= t->SND.WND + t->SND.UNA)
39 {
40 NetSim_PACKET* pt = fn_NetSim_Socket_GetPacketFromInterface(s->sId, 1);
41 if (pt->pstruAppData->nAppEndFlag)
42 s->isAPPClose = true; //Enable flag to signal application closing
43
44 add_tcp_hdr(pt, s);
45 t->SND.NXT += l;
46 seq += l;
47
48 s->tcpMetrics->segmentSent++;
49
50 send_to_network(pt, s);
51 add_timeout_event(s, pt);
52 write_congestion_plot(s, pt);
53 }
54 else
55 break; //No more segment allowed to send
56
57 p = fn_NetSim_Socket_GetPacketFromInterface(s->sId, 0);
58 }
59
60 if (s->isAPPClose)
61 tcp_close(s);
62}
63
64void resend_segment(PNETSIM_SOCKET s, NetSim_PACKET* expired)
65{
66 PTCP_SEGMENT_HDR hdr = TCP_GET_SEGMENT_HDR(expired);
67 PTCP_QUEUE q = &s->tcb->retransmissionQueue;
68
69 NetSim_PACKET* p = get_segment_from_queue(q, hdr->SeqNum);
70
71 if (p)
72 {
73 s->tcpMetrics->segmentRetransmitted++;
74 send_to_network(p, s);
75 add_timeout_event(s, p);
76 }
77}
78
79void resend_segment_without_timeout(PNETSIM_SOCKET s, UINT seq)
80{
81 bool isSacked = false;
82 PTCP_QUEUE q = &s->tcb->retransmissionQueue;
83
84 NetSim_PACKET* p = get_copy_segment_from_queue(q, seq, &isSacked);
85
86 if (s->tcb->isSackPermitted &&
87 isSacked)
88 {
89 //Don't retransmit
90 fn_NetSim_Packet_FreePacket(p);
91 p = NULL;
92 }
93
94 if (p)
95 {
96 set_highRxt(s, seq);
97 set_rescueRxt(s, seq);
98 s->tcpMetrics->segmentRetransmitted++;
99 send_to_network(p, s);
100 }
101}