Compare commits

...

7 commits

Author SHA1 Message Date
Z8Griz
cb12003d57
Merge dbe88c18c9 into a95d5559de 2024-10-04 04:29:58 -06:00
Z8Griz
dbe88c18c9 did not mean to include that specific code and file. 2024-08-27 20:21:38 -06:00
Z8Griz
295a97bf4c changed hardcoded to systemside clock or ticks. JIFFY_FREQ.
Noticed slightly better responsive times while reducing timeouts.
2024-08-27 19:04:03 -06:00
Z8Griz
e363a0b0b6 Unsure if this is correct but as far as connections and speeds goes, it remained unchanged. 2024-08-27 13:50:40 -06:00
Z8Griz
ff978b1ce3 RECEIVE WINDOW is different than RECEIVE BUFFER
The receive buffer is allocated per socket.
TCP receive buffer holds TCP data that has not yet been processed
(consumed via read/recv system calls) by the application.
2024-08-26 18:34:11 -06:00
Z8Griz
1a5368962b There is no receive window size.
Client(send) overrides host(receive) window size.
It's one of the reasons why telnet chars and gopher files/links tend to drop. Packetloss/timeout.
2024-08-26 07:16:48 -06:00
Z8Griz
1f750d9237 Most modern network cards and routers uses standard frame.
Lowered the frame size because if network card / router can't handle high frame,
it will causes fragmentation, leading to packetloss or lost connection.
It depends on the network card and router.
A standard frame is 1518 bytes on the wire (as far as any capturing device is concerned).
A tagged frame (single tag) is 1522 bytes on the wire.
These take up 1538 bytes or 1542 bytes of transmission space on the wire.
On most OS, it is usually set at 1542. As a safe measure.
If one wants run on 90s network card, it should be set at 1518.
I think this should be automated, not hardcoded.
2024-08-26 07:05:39 -06:00
4 changed files with 31 additions and 14 deletions

View file

@ -24,4 +24,4 @@ Cd(__DIR__);;
#include "Protocols/DHCP" #include "Protocols/DHCP"
#include "Utilities/NetHandler" // needs IPV4, UDP, ICMP #include "Utilities/NetHandler" // needs IPV4, UDP, ICMP

View file

@ -2,15 +2,28 @@
#define TCP_SRTT_ALPHA 0.9 #define TCP_SRTT_ALPHA 0.9
// Transmission Time Out to prevent network slugglish performance
#define TCP_RTO_BETA 2 #define TCP_RTO_BETA 2
#define TCP_RTO_MIN 0.2 #define TCP_RTO_MIN JIFFY_FREQ/5 // (linux TCP.H) should be using system timer/clock instead hardcoded
#define TCP_RTO_MAX 10 #define TCP_RTO_MAX 120*JIFFY_FREQ // JIFFY_FREZ = Hz. Hz is software clock ticks
#define TCP_WINDOW_SIZE 8192 #define TCP_MAX_WINDOW 32676 // Beyond this number, use window_scale(not implemented). 8192 is recommended/default.
U16 WINDOW_SIZE; // Initiate window size in CTPCPacketAllocate{} ?? Need more study
U16 RECEIVE_WINDOW; // gets host window size. It is not static.
U16 SEND_WINDOW; // gets receive window size from host, then adjust accordingly.
U32 RECEIVE_BUFFER; // is 32 too much? receive_buffer holds TCP data that has not yet been processed
#define TCP_MSS 536 // Max Segment Size default #define TCP_MSS 536 // Max Segment Size default
#define TCP_MIN_MSS 88 // Min Segment Size
#define TCP_TIMEOUT 5000 #define TCP_INIT_TIMEOUT 1*JIFFY_FREQ // TODO... Init RTO Value. Not sure if this is needed.
#define TCP_TIMEOUT 20*JIFFY_FREQ // Roughly a minute based on software clock
#define TCP_KEEPALIVE 120*JIFFY_FREQ // TODO... 1 hour
#define TCP_MAX_INCREASEACK 16 //TODO... At Initial start up, it's generally slow. This accelerates the process.
#define TCP_MAX_DELAYACK JIFFY_FREQ/5 //TODO... Delay max time ack
#define TCP_MIN_DELAYACK JIFFY_FREQ/25 //TODO... Delay min time ack
#define TCP_STATE_CLOSED 0 #define TCP_STATE_CLOSED 0
#define TCP_STATE_LISTEN 1 #define TCP_STATE_LISTEN 1
@ -24,7 +37,7 @@
#define TCP_STATE_LAST_ACK 9 #define TCP_STATE_LAST_ACK 9
#define TCP_STATE_TIME_WAIT 10 #define TCP_STATE_TIME_WAIT 10
// TCP header flags. Test with Bt(), e.g. Bt(&flags, TCPf_RST) // TCP header flags. Order of Operation matters. Test with Bt(), e.g. Bt(&flags, TCPf_RST)
#define TCPf_FIN 0 #define TCPf_FIN 0
#define TCPf_SYN 1 #define TCPf_SYN 1
#define TCPf_RST 2 #define TCPf_RST 2
@ -39,6 +52,8 @@
#define TCPF_ACK (1 << TCPf_ACK) #define TCPF_ACK (1 << TCPf_ACK)
//#define TCPF_URG (1 << TCPf_URG) // most stacks don't implement URGENT. //#define TCPF_URG (1 << TCPf_URG) // most stacks don't implement URGENT.
// U32 TCP_MAX_DELAYACK(CSocket *Socket); // TODO
class CTCPAckQueue:CQueue class CTCPAckQueue:CQueue
{ {

View file

@ -101,7 +101,7 @@ I64 TCPPacketAllocate(U8 **frame_out,
header->ack_num = EndianU32(ack_num); header->ack_num = EndianU32(ack_num);
header->data_offset = (sizeof(CTCPHeader) / 4) << 4; // ??? header->data_offset = (sizeof(CTCPHeader) / 4) << 4; // ???
header->flags = flags; header->flags = flags;
header->window_size = EndianU16(TCP_WINDOW_SIZE / 2);// TODO: What is window size supposed to be ? header->window_size = EndianU16(WINDOW_SIZE);// Window Size allocation data. Adjusted based on receive window.
header->checksum = 0; header->checksum = 0;
header->urgent_pointer = 0; header->urgent_pointer = 0;
@ -647,8 +647,8 @@ CTCPSocket TCPSocket(U16 domain=AF_UNSPEC)
QueueInit(accept_queue); // init pending connection queue QueueInit(accept_queue); // init pending connection queue
tcp_socket->accept_queue = accept_queue; tcp_socket->accept_queue = accept_queue;
tcp_socket->receive_buffer_size = TCP_WINDOW_SIZE; tcp_socket->receive_buffer_size = RECEIVE_BUFFER;
tcp_socket->receive_buffer = CAlloc(TCP_WINDOW_SIZE); tcp_socket->receive_buffer = CAlloc(RECEIVE_BUFFER);
tcp_socket->max_segment_size = TCP_MSS; tcp_socket->max_segment_size = TCP_MSS;
@ -1057,7 +1057,7 @@ I64 TCPSocketConnect(CTCPSocket *tcp_socket, CSocketAddressStorage *address)
} }
tcp_socket->connection_time = tS; tcp_socket->connection_time = tS;
tcp_socket->receive_window = TCP_WINDOW_SIZE; tcp_socket->receive_window = RECEIVE_WINDOW;
tcp_socket->state = TCP_STATE_SYN_SENT; tcp_socket->state = TCP_STATE_SYN_SENT;
TCPSendFlags(tcp_socket, TCPF_SYN); TCPSendFlags(tcp_socket, TCPF_SYN);
@ -1165,7 +1165,7 @@ CTCPSocket *TCPSocketAccept(CTCPSocket *tcp_socket)
new_socket->next_recv_seq_num = ++pending->segment_seq_num; new_socket->next_recv_seq_num = ++pending->segment_seq_num;
new_socket->connection_time = tS; new_socket->connection_time = tS;
new_socket->receive_window = TCP_WINDOW_SIZE; new_socket->receive_window = RECEIVE_WINDOW;
new_socket->timeout = tcp_socket->timeout; new_socket->timeout = tcp_socket->timeout;
temp_addr = &tcp_socket->source_address; temp_addr = &tcp_socket->source_address;

View file

@ -8,9 +8,11 @@
#define FCS_LENGTH 4 #define FCS_LENGTH 4
/* Ethernet Frame Size. /* Ethernet Frame Size.
Linux uses 1544, OSDev and Shrine use 1548. Based on IEEE 802.3as, max frame size was agreed upon as 2000 bytes. */ Based on IEEE 802.3 layer 1 Ethernet Max Frame is 1542 according to wiki. 72-1530 frame octet + 12 IPG octet
#define ETHERNET_FRAME_SIZE 2000 Default: 1538 | Vlan: 1542 | Jumbo: 9038 | JumboVlan: 9042 */
#define ETHERNET_FRAME_SIZE 1542
// Max PayLoad standard: 1500 | Jumbo: 9000 for Gignet (fiber)
#define ETHERNET_v2_MTU 1500 #define ETHERNET_v2_MTU 1500
#define HTYPE_ETHERNET 1 #define HTYPE_ETHERNET 1