Skip to content

Commit 0468f3a

Browse files
committed
Fix typos
Signed-off-by: Matias Ezequiel Vara Larsen <[email protected]>
1 parent 5dd4698 commit 0468f3a

File tree

1 file changed

+37
-37
lines changed

1 file changed

+37
-37
lines changed

Networking.md

+37-37
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# Networking
22
## Introduction
3-
This document presents how networking works in Toro unikernel. The unit in charge of networking is `Network.pas`. This document only describes the machinery to provide networking to the user application. This is not a tutorial. This document first present what is a network driver and how is registered to kernel. Then, the document presents the primitives to send and receive packets. It finishes by presenting how sockets are implemented by relying on those primitives.
3+
This document presents how networking works in Toro unikernel. The unit in charge of networking is `Network.pas`. This document only describes the machinery to provide networking to the user application. This is not a tutorial. This document first presents what is a network driver and how it is registered to the kernel. Then, the document presents the primitives to send and receive packets. It finishes by presenting how sockets are implemented by relying on those primitives.
44

55
## Network drivers
6-
Network drivers are units that registers a `TNetWorkInterface` to the kernel. The kernel uses this interface to send and receive packets through a network. A driver calls `RegisterNetworkInterface()` to register a new `PNetworkInterface` structure to the kernel. This procedure is declared as follows:
6+
Network drivers are units that register a `TNetWorkInterface` to the kernel. The kernel uses this interface to send and receive packets through a network. A driver calls `RegisterNetworkInterface()` to register a new `PNetworkInterface` structure to the kernel. This procedure is declared as follows:
77
```pascal
88
procedure RegisterNetworkInterface(NetInterface: PNetworkInterface);
99
```
@@ -30,12 +30,12 @@ During registration, the kernel enqueues the `PNetWorkInterface` structure into
3030
* `IncomingPackets`, a queue of incoming packets that follows a *last in first out* strategy
3131

3232
The structure defines a set of methods to interact with the kernel:
33-
* `start()`, initializates the driver
33+
* `start()`, initialises the driver
3434
* `send()`, sends a packet through the driver.
3535
* `reset()`, tells the driver to re-initialize the device
3636
* `stop()`, tells the driver to stop receiving packets.
3737

38-
Each network driver must be dedicated to a core before user can use it. The device can only be dedicated to a single core during the lifetime of the system. In other words, the dedicated core cannot change. The `CPUID` identifies which CPU is allowed to access to a driver.
38+
Each network driver must be dedicated to a core before the user can use it. The device can only be dedicated to a single core during the lifetime of the system. In other words, the dedicated core cannot change. The `CPUID` identifies which CPU is allowed to access a driver.
3939

4040
The user calls `DedicateNetworkSocket()` to dedicate a driver to the current core. The procedure uses the name of the driver to select a driver from the list. The procedure is declared as follows:
4141
```pascal
@@ -51,32 +51,32 @@ The function that handles packets is declared as follows:
5151
```pascal
5252
function ProcessSocketPacket(Param: Pointer): PtrUInt;
5353
```
54-
Toro only supports packets that conforms to **virtio-vsock**. Thus, the `ProcessSocketPacket()` function expects those type of packets. To add support for ethernet packets, a diferent function shall be used.
54+
Toro only supports packets that conforms to **virtio-vsock**. Thus, the `ProcessSocketPacket()` function expects those types of packets. To add support for ethernet packets, a different function shall be used.
5555

5656
## Network Packets
57-
* The Network unit provides the `SysNetworkSend()` and `SysNetworkRead()` functions to send and receive network packets. The functions use the driver that has been registered in the current core. These functions require to first registered a network card.
57+
* The Network unit provides the `SysNetworkSend()` and `SysNetworkRead()` functions to send and receive network packets. The functions use the driver that has been registered in the current core. These functions require you to first register a network card.
5858
* `SysNetWorkPacketSend()` is defined as follows:
5959
```pascal
6060
procedure SysNetworkSend(Packet: PPacket);
6161
```
62-
* These function is neither thread safe nor interruption safe. For this reason, it must not be used in the context of an interruption handler. The cooperative scheduler ensures non-preemption. That said, it is impossible to have two instances of the function in a different thread in the same core.
63-
* When using this function, sender loses the ownership of the packet. It is the network stack that releases the packet after the driver confirms that it has been sent.
62+
* This function is neither thread safe nor interruption safe. For this reason, it must not be used in the context of an interruption handler. The cooperative scheduler ensures non-preemption. That said, it is impossible to have two instances of the function in a different thread in the same core.
63+
* When using this function, the sender loses the ownership of the packet. It is the network stack that releases the packet after the driver confirms that it has been sent.
6464

6565
### Transmission Path
6666
* The transmission of a packet follows the these steps:
67-
1. During the SysNetworkSend(), the network stack gets the network interface that is dedicated to current core and issues a `send()` in the corresponding driver. The function returns without knowing if packet has been sent.
67+
1. During the SysNetworkSend(), the network stack gets the network interface that is dedicated to the current core and issues a `send()` in the corresponding driver. The function returns without knowing if the packet has been sent.
6868
2. The driver handles the new packet. For example, in the case of `VirtIOVSocket`, the `Packet.Data` buffer is enqueued in the available ring of the transmission queue.
6969
3. Once the packet has been sent, i.e., the device has consumed the buffer, the driver tells the kernel that the packet has been sent by invoking `DequeueOutgoingPacket()`:
7070
4. The kernel releases the `TPacket` structure and its payload, i.e., `Packet.Data`.
7171

72-
Note that in the case of the virtio-vsock driver, the data is enqueued in the available ring of the transmision queue. This is the buffer that SysSocketSend has allocated. After the device consumes the buffer, the driver informs the kernel that the packet has been sent. The kernel can release the memory for the packet.
72+
Note that in the case of the virtio-vsock driver, the data is enqueued in the available ring of the transmission queue. This is the buffer that SysSocketSend has allocated. After the device consumes the buffer, the driver informs the kernel that the packet has been sent. The kernel can release the memory for the packet.
7373

7474
### Reception Path
7575
* The reception of a packet happens in these steps:
7676
1. When a new packet is received, the driver informs the kernel by using `EnqueueIncomingPacket()`.
77-
2. The packet is enqueued in the network's card incoming packet queue. The only producer is the network card and the only consumer is the `SysNetworkRead()` function which is usually invoked by a single thread from the same core. Together with the cooperative scheduler, this ensures no race condition when reading such list. This function is not interrupt-safe so caller must disable interruptions. Otherwise, the arrival of a new packet will race with the current function. Packets are read by using `SysNetworkRead()` function. This function returns a packet from the `IncomingPackets` queue of the current core.
77+
2. The packet is enqueued in the network's card incoming packet queue. The only producer is the network card and the only consumer is the `SysNetworkRead()` function which is usually invoked by a single thread from the same core. Together with the cooperative scheduler, this ensures no race condition when reading such a list. This function is not interrupt-safe so the caller must disable interruptions. Otherwise, the arrival of a new packet will race with the current function. Packets are read by using the `SysNetworkRead()` function. This function returns a packet from the `IncomingPackets` queue of the current core.
7878

79-
## Processing Incomming Packets
79+
## Processing Incoming Packets
8080
TODO:
8181
```pascal
8282
function ProcessSocketPacket(Param: Pointer): PtrUInt;
@@ -194,8 +194,8 @@ end;
194194
```
195195

196196
## Sockets
197-
* On top of the networking primitives to send and receive packet, there is the socket layer that parses those packets and tranlates them a stream or datagram connections between two sockets. Sockets allow to communicate applications over a network. Toro supports only AF_VSOCK sockets. The Toro API to manipulate sockets looks like the POSIX API.
198-
* When using AF_VSOCK, the host is always identified with the number 2 and the the guest id is defined by the user when invoking QEMU.
197+
* On top of the networking primitives to send and receive packets, there is the socket layer that parses those packets and translates them into stream or datagram connections between two sockets. Sockets allow applications to communicate over a network. Toro supports only AF_VSOCK sockets. The Toro API to manipulate sockets looks like the POSIX API.
198+
* When using AF_VSOCK, the host is always identified with the number 2 and the guest id is defined by the user when invoking QEMU.
199199
*
200200
* A socket is defined as follows:
201201
```pascal
@@ -232,25 +232,25 @@ function SysSocket(SocketType: LongInt): PSocket;
232232
```
233233
* This function returns a pointer to a TSocket structure or Nil if it fails.
234234
* The only supported type is SOCKET_STREAM which refers to stream sockets.
235-
* A SOCKET_STREAM has control flow. SOCKET_DGRAM are not supported.
236-
* The function simple initializes the structures and returns a new socket.
235+
* A SOCKET_STREAM has control flow. SOCKET_DGRAM is not supported.
236+
* The function simply initialises the structures and returns a new socket.
237237
* The returned pointer to a socket is used for the remainder functions.
238238
* For example, the SysSocketListen() is often used after SysSocket() to bind a socket to a port. This function is defined as follows:
239239
```pascal
240240
function SysSocketListen(Socket: PSocket; QueueLen: LongInt): Boolean;
241241
```
242-
* This function accepts a Socket and QueueLen as arguments. Socket is a pointer to a previously created socket. QueueLen is the number of requests that the socket can accept at the same time. When the number of request is over QueueLen, the kernel starts to drop the requests.
243-
* This function returns True if sucess, Or, False, otherwise.
244-
* Before call this function, user has to set the local port in which the socket will listen and the mode, i.e., blocking or non-blocking socket. This is usually done as:
242+
* This function accepts Socket and QueueLen as arguments. Socket is a pointer to a previously created socket. QueueLen is the number of requests that the socket can accept at the same time. When the number of requests is over QueueLen, the kernel starts to drop the requests.
243+
* This function returns True if success, Or, False, otherwise.
244+
* Before calling this function, the user has to set the local port in which the socket will listen and the mode, i.e., blocking or non-blocking socket. This is usually done as:
245245
```pascal
246246
HttpServer := SysSocket(SOCKET_STREAM);
247247
HttpServer.Sourceport := 80;
248248
HttpServer.Blocking := True;
249249
SysSocketListen(HttpServer, 50);
250250
```
251-
* In this case, the HttpServer socket listens at port 80 and the len of queue is 50.
251+
* In this case, the HttpServer socket listens at port 80 and the length of the queue is 50.
252252
* SysSocketListen() only binds the port to the socket. It is SysSocketAccept() to get incoming sockets connections.
253-
* SysSocketAccept() accepts a pointer to a Socket as an argument. The functions waits until a new connection arrives. When this happens, it returns the new socket.
253+
* SysSocketAccept() accepts a pointer to a Socket as an argument. The function waits until a new connection arrives. When this happens, it returns the new socket.
254254
* The function is defined as follows:
255255
```pascal
256256
function SysSocketAccept(Socket: PSocket): PSocket;
@@ -272,7 +272,7 @@ The Service variable points to a PNetworkService which is a socket listening on
272272
ClientSocket: PSocket;
273273
end;
274274
```
275-
The ServerSocket is the socket that is listening. The ClientSocket is a simple queue list in which incomming connections are enqueued.
275+
The ServerSocket is the socket that is listening. The ClientSocket is a simple queue list in which incoming connections are enqueued.
276276
```
277277
while True do
278278
begin
@@ -295,10 +295,10 @@ The ServerSocket is the socket that is listening. The ClientSocket is a simple q
295295
end;
296296
end;
297297
```
298-
The function returns the head of the list of incomming connections. If the list is empty, it calls the scheduler. The function keeps calling the scheduler until an incomming connection arrives.
298+
The function returns the head of the list of incoming connections. If the list is empty, it calls the scheduler. The function keeps calling the scheduler until an incoming connection arrives.
299299

300300
## SysSocketSelect()
301-
* The next function is SysSocketSelect(). This functions blocks until an event arrives to the socket, e.g., new data, timeout, connection closed. The function behaves differently depending the socket is blocking or not blocking. The non-blocking path is not implemented yet. In case the socket is blocking, the function fist sets a timeout to wait for a new event.
301+
* The next function is SysSocketSelect(). This function blocks until an event arrives to the socket, e.g., new data, timeout, connection closed. The function behaves differently depending whether the socket is blocking or not blocking. The non-blocking path is not implemented yet. In case the socket is blocking, the function first sets a timeout to wait for a new event.
302302

303303
```pascal
304304
function SysSocketSelect(Socket: PSocket; TimeOut: LongInt): Boolean;
@@ -353,12 +353,12 @@ end;
353353
```
354354
* The function checks for three conditions for exiting:
355355
1. The remote peer has disconnected
356-
2. There is new data in the incomming buffer
356+
2. There is new data in the incoming buffer
357357
3. The timeout has running out of time
358-
If none of these conditions is satified, the function calls the scheduler. Note that here the timeout is aproximative, since the scheduler is cooperative, we do not know when the thread is going to be scheduler again. Other sort of timer are required for hard deadlines.
358+
If none of these conditions is satisfied, the function calls the scheduler. Note that here the timeout is approximative, since the scheduler is cooperative, we do not know when the thread is going to be scheduler again. Other sort of timers are required for hard deadlines.
359359

360360

361-
* The user can used the `UsedDefined` to store information for a given Socket. For example, this is used to store a extra buffer in the StaticWebServer example. For example, this is used in the StaticWebServer example:
361+
* The user can use the `UsedDefined` to store information for a given Socket. For example, this is used to store an extra buffer in the StaticWebServer example. For example, this is used in the StaticWebServer example:
362362
```pascal
363363
HttpClient := SysSocketAccept(HttpServer);
364364
rq := ToroGetMem(sizeof(TRequest));
@@ -370,8 +370,8 @@ If none of these conditions is satified, the function calls the scheduler. Note
370370
```
371371

372372
## SysSocketSend()
373-
* Sending data through a socket happens with the `SysSocketSend()` function. This is a non-blocking function. The function only blocks if the receiving side is not able to get more data. In this case, the function call the scheduler until the other side becomes available.
374-
* The function requires one copy from user's buffer.
373+
* Sending data through a socket happens with the `SysSocketSend()` function. This is a non-blocking function. The function only blocks if the receiving side is not able to get more data. In this case, the function calls the scheduler until the other side becomes available.
374+
* The function requires one copy from the user's buffer.
375375
* The function fills the vsock header.
376376
* It sends the date by using SysNetWorkSend(). This is a non-blocking function. The packets are enqueued into the available ring of the virtio-vsock device.
377377
* The function returns after sending all the packets
@@ -422,14 +422,14 @@ begin
422422
end;
423423
```
424424
## SysSocketRecv()
425-
* This funcion reads a number of `AddrLen` bytes from the socket buffer and stores them into `Addr`. This function requires one-copy from the Socket buffer.
426-
* The function inmediatly exits if:
425+
* This function reads a number of `AddrLen` bytes from the socket buffer and stores them into `Addr`. This function requires one-copy from the Socket buffer.
426+
* The function immediately exits if:
427427
1. The socket is not in SCK_TRANSMITTING state
428428
2. 0 bytes are requested to be read
429-
3. The is no more data to be read.
429+
3. There is no more data to be read.
430430
The function returns the number of bytes read from the socket buffer.
431431
The function consumes the data from the internal buffer.
432-
* This functions exits if there is no data in the internal buffer. This function is usually used together with Select() to block until data is received.
432+
* This function returns if there is no data in the internal buffer. This function is usually used together with Select() to block until data is received.
433433
```pascal
434434
function SysSocketRecv(Socket: PSocket; Addr: PChar; AddrLen, Flags: UInt32): LongInt;
435435
var
@@ -458,7 +458,7 @@ begin
458458
Inc(Socket.BufferReader, FragLen);
459459
if Socket.BufferReader = Socket.Buffer+Socket.BufferLength then
460460
begin
461-
{$IFDEF DebugSocket} WriteDebug('SysSocketRecv: Reseting Socket.BufferReader\n', []); {$ENDIF}
461+
{$IFDEF DebugSocket} WriteDebug('SysSocketRecv: Resetting Socket.BufferReader\n', []); {$ENDIF}
462462
Socket.BufferReader := Socket.Buffer;
463463
Socket.BufferLength := 0;
464464
Break;
@@ -468,7 +468,7 @@ end;
468468
```
469469

470470
## SysSocketPeek()
471-
The function behaves similar than SysSocketRecv. The main difference is that the data is not consumed from the socket buffer. This is useful when we want to read a whole structure from the buffer. We keep calling SysSocketPeek() until it sucess and then we get the whole structure by using SysSocketRecv().
471+
The function behaves similar than SysSocketRecv. The main difference is that the data is not consumed from the socket buffer. This is useful when we want to read a whole structure from the buffer. We keep calling SysSocketPeek() until it succeeds and then we get the whole structure by using SysSocketRecv().
472472

473473
```pascal
474474
function SysSocketPeek(Socket: PSocket; Addr: PChar; AddrLen: UInt32): LongInt;
@@ -500,7 +500,7 @@ begin
500500
end;
501501
```
502502
## SysSocketConnect()
503-
This function connects a socket to a remote peer. It returns True if sucesses, or False otherwise. The function is defined as follows:
503+
This function connects a socket to a remote peer. It returns True if successes, or False otherwise. The function is defined as follows:
504504
```pascal
505505
function SysSocketConnect(Socket: PSocket): Boolean;
506506
var
@@ -564,7 +564,7 @@ The function exits with error if there is not more memory for the local buffer o
564564
SysNetworkSend(Packet);
565565
SetSocketTimeOut(Socket, WAIT_ACK);
566566
```
567-
This call builds an `OP_REQUEST` packet and sends it to the destination CID. It sets an timeout to wait for the remote response. If non response is received, the function returns with error.
567+
This call builds an `OP_REQUEST` packet and sends it to the destination CID. It sets a timeout to wait for the remote response. If non response is received, the function returns with error.
568568
```pascal
569569
while True do
570570
begin

0 commit comments

Comments
 (0)