Файл: Embedded system development and labs for ARM (R. Muresan, 2005).pdf

ВУЗ: Не указан

Категория: Не указан

Дисциплина: Не указана

Добавлен: 13.06.2025

Просмотров: 2340

Скачиваний: 4

ВНИМАНИЕ! Если данный файл нарушает Ваши авторские права, то обязательно сообщите нам.

Embedded Systems Development and Labs; The English Edition

Foundation) started to support TCP/IP research and gradually played an important role. NFS aided the establishment of the global Internet network. and used TCP/IP as its communication protocol.

1) Architecture

TCP/IP is a four layers protocol. Every layer is independent and has its own specific function. The TCP/IP layer structure is shown in Figure 6-13.

Application Layer Layer 4

Transmission Layer Layer 3

Internet Layer Layer 2

Network Interface Layer Layer 1

Figure 6-13 TCP/IP Layered Protocol

Network Interface Layer: Responsible for receiving and sending physical frames. This layer defines the rules of forming frames and the rules of transmission. Frame represents a series of data and a frame is a communication unit of the network transmission. The network layer puts frames to the network or receives frames from the networks.

Internet Layer: Responsible for the inter-communication between two network nodes. This layer defines the format of the “information package” in the Ethernet and the information transmission mechanisms from one network node to the destination via one or more routers and routing algorithms. The main protocols used in this layer include IP, ARP, ICMP and IGMP.

Transmission Layer: Responsible for communication of end-to-end. It creates, manages and deletes end-to-end connections for two-user processes. The main protocols used in this layer include TCP, UDP, etc.

Application Layer: It defines the application programs that use the Internet. Application programs access the network via this layer by following BSD network application interface standard. The main protocols include SMTP, FTP, TELNET, and HTTP, etc.

2) An Introduction to the Main Protocols

(1) IP Protocol

Internet Protocol (IP) is the heart of TCP/IP and the most important protocol in the network layer.

IP layer receives data packages from the lower layer (network interface layer, Ethernet device driver for example) and sends these data packages to the higher layer – TCP or UDP layer. IP layer can also receive data from TCP or UDP layer and sends this data to the lower layer. The IP data package is not reliable because IP does not support mechanisms to check the data integrity and the transmission order of the packages. The IP data package has its sender’s IP address (source address) and its receiver’s IP address (target address).

IP protocol is a non-connection protocol and is mainly responsible for addressing between the hosts and setting the route for data packages. Before the data is exchanged, it doesn’t establish sessions because it doesn’t guarantees error free data transfers. On the other hand, when data is being received, IP doesn’t need to receive acknowledgment information. As a result the IP protocol is not a reliable protocol. If the IP address is for the current host, the IP will send the data directly to this host. If the IP address is for a remote host, the IP will check

247

Embedded Systems Development and Labs; The English Edition

the route of the remote host from the route table in the local host (like we dial 114). If a route is found, the IP will use this route to transfer data; if no route is found, the data package will be sent to a default gateway of the source host (this gate way is also called a router).

The current IP protocol includes the IPv4 version and the v6 version. IPv4 is currently being widely used; IPv6 is the basic protocol that will be used in the next generation of high speed Internet.

The header of IP protocol is shown in Figure 6-14.

0 4 8 16 32

-----------------------------------------------------------------------

|Version |Header Length |Service Type| Total Length |

----------------------------------------------------------------------

| Identification |Flags|Fragment Offset|

-----------------------------------------------------------------------

| Time to Live | Protocol | Header Checksum |

-----------------------------------------------------------------------

| Source IP Address |

-----------------------------------------------------------------------

| Destination IP Address |

-----------------------------------------------------------------------

| Options |

==================================== ===

| Data |

-----------------------------------------------------------------------

Figure 6-14 IPv4 Data Package Format

The C structure of the IP header is defined as following:

struct ip_header

{

UINT

ip_v:4;

/* Version */

UINT

ip_hl:4;

/* Header Length */

UINT8

ip_tos;

/* Service Type */

UINT16

ip_len;

/* Total Length */

248


Embedded Systems Development and Labs; The English Edition

UINT16

ip_id;

/* Identification */

UINT16

ip_off;

/* Fragment Offset */

UINT8

ip_ttl;

/* Time to Live */

UINT8

ip_p;

/* Higher layer Protocol */

UINT16

ip_sum;

/* checksum */

struct in_addr ip_src, ip_dst;

/* Source and Destination IP Address */

};

The description of these parameters are as following: ip_v Ip protocol version, Ipv is 4, Ipv6 is 6

ip_hl IP Header length. Based on 4 bytes unit. The length of IP header is fixed as 20 bytes. If there are no options included, this value is 5.

ip_tos Service type, describes the priority of services. ip_len IP package length. Use byte as a unit.

ip_id Identification of this package

ip_off Fragment Offset. Used with the above IP for reunite fragments.

ip_ttl Time to live. Minus 1 when passing a route, throw away the data package until this value becomes 0.

ip_p Protocol. The higher layer protocols that create this package. TCP or UDP,for example.

ip_sum Header checksum. It is used to provide verification to the IP header. ip_src,ip_dst Sender and receiver IP address.

For more detailed information of IP protocol, please refer to RFC791.

The IP address is actually a method used to unite the network physical addresses with the higher layer software via Internet Layer. This method uses uniform address format via a uniform management. Different hosts within the Ethernet have different addresses. In IPv4, each host IP address is 32 bits that consists of 4 bytes. In order to conveniently read the address by the users, decimal with dot separation format is used. For example, 211.154.134.93 is the IP address of Embedded Development Network Website. Each IP address has two parts. The network section describes the type of different scale networks. The host section describes the address of the

249

Embedded Systems Development and Labs; The English Edition

host in the network. According to the size of the network scale, the IP address can be divided into five classes A, B C, D, E and F. Among these classes, A, B and C are used as the main address types. D class address is used as multi transmission address for multicasting. E class address is used as an extended optional address.

(2) TCP Protocol

If an IP package has a packaged TCP package, the IP layer will transmit this package to the higher TCP layer. The TCP will sort the packages and do error checking. A virtual circuit connection will also be established. TCP package has a series number and an acknowledgment. The received package will be sorted by the series number. The damaged package will be re-transmitted.

The TCP sends its package to the higher layer programs such as Telnet service program or client programs. Application programs will alternatively send the message back to the TCP layer. The TCP layer will send the message down to the lower IP layer, device driver and physical media and at last to the end receiver. The format of the TCP protocol data package header is shown in Figure 6-15.

0 4 8 10 16 24 32

-----------------------------------------------------------

| Source Port | Destination Port |

-----------------------------------------------------------

| Series number |

-----------------------------------------------------------

| Acknowledgment Number |

-----------------------------------------------------------

|

|

|U|A|P|S|F|

|

| HL

| Reserved |R|C|S|Y|I| Window

|

|

|

|G|K|H|N|N|

|

-----------------------------------------------------------

| Checksum | Emergency Pointer |

-----------------------------------------------------------

| Options | Fills |

-----------------------------------------------------------

Figure 6-15 TCP Protocol Data Package Header Format

For detail information about the TCP protocol, please refer to the related documentations. A TCP session is established by a three times handshake initialization. The purpose of three times handshake initialization is to synchronize the data transmission, inform other hosts about the data quantity it can be received at one time and establish the virtual connection. The simplified process of three times handshake initialization is as following:

(1)Initialize the host and send a session request.

(2)The receiver host replies by sending a data segment with the following items: synchronization flag, the

250


Embedded Systems Development and Labs; The English Edition

series number of the data that will be sent, acknowledgment with the next series number of next data segment that will be received.

(3) Request the host to send another data segment with acknowledges series number and acknowledge number.

(3) UDP Protocol

UDP is at the same layer as the TCP protocol. UDP do not perform data package series, error

checking or retransmission. As a result, UDP is not used to virtual circuit services or connection oriented services. UDP is mainly used by those polling-answer services, NFS for example. These services require less information exchanging than FTP or Telnet. UDP services include NTP (Network Time Protocol) and DNS (DNS also use TCP). The header of UDP package is shown at Figure 6-16.

0 16 32

---------------------------------------------------------------

| UDP Source Port | UDP Target Port |

---------------------------------------------------------------

| UDP Datagram Length | UDP Datagram Checksum |

---------------------------------------------------------------

Figure 6-16 UDP Protocol Data Package Header Format

For more detailed information, please refer to related RFC documentation.

UDP protocol is often used in software applications that don’t need acknowledgment and that transmit small amounts of data.

(4) ICMP Protocol

ICMP is at the same layer as the IP protocol and is used to transmit the IP control message. It is mainly used to provide route information of the target address. The Redirect message of ICMP provides more accurate route information for the host that connects to other systems. The Unreachable message means routing problems. If a route cannot be used, ICMP can decently terminate a TCP connection. PING is the most often used, ICMP based service.

For more detailed information about ICMP, please refer to the related RFC documentation.

(5) ARP Protocol

In order to communicate between networks, a host must know the hardware address (network card physical address) of the target host. Address resolution is a process that maps the host IP address to the hardware address. Address Resolution Protocol (ARP) is used to get the hardware addresses in the same network.

The local network resolution process is as following:

1.When a host needs to communicate with another host, it initializes an ARP request. If the IP protocol has identified its local IP address, the source host will check out the hardware address of the target host from the ARP buffer.

2.If the target address of the target host mapping cannot be found, the ARP protocol will broadcast the source host IP address and hardware address. All hosts in the network will receive this request via

251


Embedded Systems Development and Labs; The English Edition

multicasting and process the request.

3.Every host in the network receives the muticast request and searches for the corresponding IP address.

4.When the target host finds that the IP address broadcasted is the same as its own IP address, the target

host will send an ARP reply to inform its hardware address to the source host. The target host also updates its ARP buffer with the source host IP address and hardware address. The source host will establish a communication after receives the reply.

For more detailed information about ARP, please refer to related RFC documentation.

(6) TFTP Protocol

TFTP is a simple protocol for transferring files. It is based on the UDP protocol. It supports user receive/send files from/to a remote host computer. This protocol is suitable only for small files. It doesn’t have same functions as the FTP protocol. It can only receive or write files from/to the host server computer. It can’t list file directory, no verification, it only transfers 8 bit type data.

Because TFTP uses UDP and UDP uses IP, and IP can communicate using other methods, a TFTP data package includes the following segments: local header, IP header, data package header, TFTP header, and the TFTP data. The TFTP doesn’t specify any data in the IP header but it uses UDP source and target address and length. The TID used in TFTP is a port number that must be within 0-65535 range.

The initial connection needs to send WRQ (Write Remote Request) or RRQ (Read Remote Request) and receive an acknowledgment message, a definite data package or the first data block. Normally an acknowledgment package includes a package number. Every data package has its block number. The block number start from 0 and the numbers are continuous. The WRQ is a special package and its block number is 0. If the receiver receives a wrong package, the received package will be rejected. When a connection is created, the two communicating parts will randomly select a TID. Because the selection is random, the chance of the same TID is very small. Each package has two IDs, one is for the sender, and the other is for the receiver. In the first request, the package will be sent to port 69 of the receiver host. When the receiver host sends an acknowledgment, it will use a selected TID as the source TID and use the TID in the former package as its target TID. These two IDs will be used in the entire process of communication.

After the connection is created, the first data package with series number 1 will be sent from the host. Later on, the two hosts must guarantee to communicate with the specified TIDs. If the source ID is not the same as the specified ID, the data package will be thrown away as a message that is being sent to a wrong address.

For more detailed information about TFTP, please refer to related RFC documentation.

3) Development Methods of Network Application Programs

There are two methods of developing network application programs. One is by using the BSD Socket standard interface. Using this method, the programs can be ported to other systems. The other method is by using directly the transmission layer interface. This method is more efficient.

(1) BSD Socket Interface Programming Methods

Socket is a programming method of communicating to other programs via standard FD. Each socket uses a half related description {protocol, local address, local port}. A completed socket uses a completed description {protocol, local address, local port, remote address, remote port}. Each socket has a local number that is specified by the operating system.

Socket has three types:

252