19
LWIP TCP/IP Stack 김김김

LWIP TCP/IP Stack 김백규. What is LWIP? An implementation of the TCP/IP protocol stack. The focus of the lwIP stack is to reduce memory usage and code

Embed Size (px)

Citation preview

Page 1: LWIP TCP/IP Stack 김백규. What is LWIP?  An implementation of the TCP/IP protocol stack.  The focus of the lwIP stack is to reduce memory usage and code

LWIP TCP/IP Stack

김백규

Page 2: LWIP TCP/IP Stack 김백규. What is LWIP?  An implementation of the TCP/IP protocol stack.  The focus of the lwIP stack is to reduce memory usage and code

What is LWIP?

An implementation of the TCP/IP protocol stack.

The focus of the lwIP stack is to reduce memory usage and code size suitable for embedded systems.

uses a tailor made API that does not require any data copying.

Page 3: LWIP TCP/IP Stack 김백규. What is LWIP?  An implementation of the TCP/IP protocol stack.  The focus of the lwIP stack is to reduce memory usage and code

Features of TCP/IP stack(Traditional version) Designing in a layered

fashion leads to… communication

overhead between layers

Network communication is similar to IPC or file I/O APP can’t aware of the

buffer mechanisms. (e.g. reuse buffers

with frequently used data.)

<Layered model>

Page 4: LWIP TCP/IP Stack 김백규. What is LWIP?  An implementation of the TCP/IP protocol stack.  The focus of the lwIP stack is to reduce memory usage and code

Features of TCP/IP stack(LWIP version) Do not maintain a strict layer.

More relaxed scheme for communication between layers.

(By means of shared memory)- APP layer can use the buffer handling mechanisms

used by the lower layers.- APP can more efficiently reuse buffers.

Application process can use the same memory as the networking code App can read and write directly to the internal

buffers. Saving the expense of performing a copy

Page 5: LWIP TCP/IP Stack 김백규. What is LWIP?  An implementation of the TCP/IP protocol stack.  The focus of the lwIP stack is to reduce memory usage and code

Process model of LWIP

All protocols reside in a single process thus are separated from the OS kernel. Allow to be portable across different OS.

APP may either reside in the LWIP process or be in separate processes. Communicate are done by function calls. Or a more abstract API.

Page 6: LWIP TCP/IP Stack 김백규. What is LWIP?  An implementation of the TCP/IP protocol stack.  The focus of the lwIP stack is to reduce memory usage and code

The operating system emulation layers

OS specific function calls and data structures are not used directly in the code. The operating system emulation layer is used.

The OS emulation layer provides Timers, process synchronization, message

passing mechanisms, and so on.

Porting to a different OS Only need the operating system emulation

layer.

Page 7: LWIP TCP/IP Stack 김백규. What is LWIP?  An implementation of the TCP/IP protocol stack.  The focus of the lwIP stack is to reduce memory usage and code

Buffer and memory management

Packet buffers – pbufs LWIP’s internal representation of a packet, Designed for the special needs of the minimal st

ack.

Types of pbufs PBUF_RAM, PBUF_ROM, PBUF_POOL A pbuf chain may consist of multiple types of pbu

fs.

Page 8: LWIP TCP/IP Stack 김백규. What is LWIP?  An implementation of the TCP/IP protocol stack.  The focus of the lwIP stack is to reduce memory usage and code

PBUF_RAM pbuf

has the packet data stored in memory managed by the pbuf subsystem.

used when an application sends data that is dynamically generated.

Page 9: LWIP TCP/IP Stack 김백규. What is LWIP?  An implementation of the TCP/IP protocol stack.  The focus of the lwIP stack is to reduce memory usage and code

PBUF_ROM pbuf

Used when an application sends data that is located in memory managed by the application.

The main use is when the data is located in ROM Header that are prepended to the data in a PBUF_ROM pbuf ar

e stored in a PBUF_RAM pbuf.

Page 10: LWIP TCP/IP Stack 김백규. What is LWIP?  An implementation of the TCP/IP protocol stack.  The focus of the lwIP stack is to reduce memory usage and code

PBUF_POOL Consist of fixed size pbufs allocated from a pool of fixed size pbufs. Mainly used by network device drivers since the operation of allocati

ng a single pbuf is fast and is therefore suitable for use in an interrupt handler

Page 11: LWIP TCP/IP Stack 김백규. What is LWIP?  An implementation of the TCP/IP protocol stack.  The focus of the lwIP stack is to reduce memory usage and code

Network interfacesThe network interfaces are kept on a global linked list.

Reflect the kind of H/WEx) Bluetooth => bt

WLAN => wlThe function the device

driver should call when a packet has been received.

The function in the device driver that transmits a packet on the physical network and it is called by the IP layer when a

packet is to be sent.

Points to device driver specific state for the network interface and is set by the device driver.

Page 12: LWIP TCP/IP Stack 김백규. What is LWIP?  An implementation of the TCP/IP protocol stack.  The focus of the lwIP stack is to reduce memory usage and code

IP processing(1/3)

Receiving packets Network device driver calls ip_input() function.

Checking IP version, header length Computing the header checksum Checking destination address.

Sending packets Handled by the function ip_output()

Find the appropriate network interface. All IP header fields are filled. IP header checksum is computed. The source and destination address are passed.

Page 13: LWIP TCP/IP Stack 김백규. What is LWIP?  An implementation of the TCP/IP protocol stack.  The focus of the lwIP stack is to reduce memory usage and code

IP processing(2/3)

Forwarding packets The packet should be forwarded…

When none of the network interfaces has the same IP address as an incoming packet’s destination address.

This is done by the function ip_forward() ttl field is decreased. If ttl reaches zero, an ICMP error message is sent.

Page 14: LWIP TCP/IP Stack 김백규. What is LWIP?  An implementation of the TCP/IP protocol stack.  The focus of the lwIP stack is to reduce memory usage and code

IP processing(3/3)

ICMP processing This is for ICMP ECHO message. Just swapping the IP destination

and source address of the incoming packet.

Page 15: LWIP TCP/IP Stack 김백규. What is LWIP?  An implementation of the TCP/IP protocol stack.  The focus of the lwIP stack is to reduce memory usage and code

UDP processing(1/2)

The udp_pcb structureThe UDP PCBs are kept on a linked list which is searched for a match when a

UDP datagram arrives.

Called when a datagram is

received.

Page 16: LWIP TCP/IP Stack 김백규. What is LWIP?  An implementation of the TCP/IP protocol stack.  The focus of the lwIP stack is to reduce memory usage and code

UDP processing(2/2)

UDP processing

Page 17: LWIP TCP/IP Stack 김백규. What is LWIP?  An implementation of the TCP/IP protocol stack.  The focus of the lwIP stack is to reduce memory usage and code

TCP processing(1/2)

Next sequence number

Receiver’s window

Timer for TIME-WAIT

state

Used when passing received data to the

application layer.

Function to call when a listener has been

connected.

Page 18: LWIP TCP/IP Stack 김백규. What is LWIP?  An implementation of the TCP/IP protocol stack.  The focus of the lwIP stack is to reduce memory usage and code

TCP processing(2/2)

Page 19: LWIP TCP/IP Stack 김백규. What is LWIP?  An implementation of the TCP/IP protocol stack.  The focus of the lwIP stack is to reduce memory usage and code

Application Program Interface

The BSD socket API Require data that is to be sent to be copied from

application program to internal buffers in the TCP/IP stack.

Since the two layers reside in different protection domains.

The LWIP socket API Utilizes knowledge of the internal structure of

LWIP to achieve effectiveness. Does not require that data is copied. Since the application program can manipulate

the internal buffers directly.