16#include "TCP_Header.h"
18void send_segment(PNETSIM_SOCKET s)
21 UINT32 seq = t->SND.NXT;
23 fnNetSimError(
"SOCKETINTERFACE is NULL for TCP connection %s:%d %s:%d in function %s\n",
24 s->localAddr->ip->str_ip,
26 s->remoteAddr->ip->str_ip,
29 NetSim_PACKET* p = fn_NetSim_Socket_GetPacketFromInterface(s->sId, 0);
31 s->waitFromApp =
true;
33 t->SND.WND = window_scale_get_cwnd(s);
34 assert(t->SND.WND >= t->get_MSS(s));
37 UINT32 l = (UINT32)p->pstruAppData->dPacketSize;
38 if (seq + l <= t->SND.WND + t->SND.UNA)
40 NetSim_PACKET* pt = fn_NetSim_Socket_GetPacketFromInterface(s->sId, 1);
41 if (pt->pstruAppData->nAppEndFlag)
48 s->tcpMetrics->segmentSent++;
50 send_to_network(pt, s);
51 add_timeout_event(s, pt);
52 write_congestion_plot(s, pt);
57 p = fn_NetSim_Socket_GetPacketFromInterface(s->sId, 0);
64void resend_segment(PNETSIM_SOCKET s, NetSim_PACKET* expired)
66 PTCP_SEGMENT_HDR hdr = TCP_GET_SEGMENT_HDR(expired);
67 PTCP_QUEUE q = &s->tcb->retransmissionQueue;
69 NetSim_PACKET* p = get_segment_from_queue(q, hdr->SeqNum);
73 s->tcpMetrics->segmentRetransmitted++;
74 send_to_network(p, s);
75 add_timeout_event(s, p);
79void resend_segment_without_timeout(PNETSIM_SOCKET s, UINT seq)
81 bool isSacked =
false;
82 PTCP_QUEUE q = &s->tcb->retransmissionQueue;
84 NetSim_PACKET* p = get_copy_segment_from_queue(q, seq, &isSacked);
86 if (s->tcb->isSackPermitted &&
90 fn_NetSim_Packet_FreePacket(p);
97 set_rescueRxt(s, seq);
98 s->tcpMetrics->segmentRetransmitted++;
99 send_to_network(p, s);