Socket Service Types The following socket types are defined: 1. - - PDF document

socket service types the following socket types are
SMART_READER_LITE
LIVE PREVIEW

Socket Service Types The following socket types are defined: 1. - - PDF document

Socket Service Types The following socket types are defined: 1. SOCK_STREAM : stream socket 2. SOCK_DGRAM : datagram socket 3. SOCK_RAW : raw-protocol interface 4. SOCK_RDM : reliably-delivered message 5. SOCK_SEQPACKET : sequenced packet stream


slide-1
SLIDE 1

1

Socket Service Types The following socket types are defined:

  • 1. SOCK_STREAM: stream socket
  • 2. SOCK_DGRAM: datagram socket
  • 3. SOCK_RAW: raw-protocol interface
  • 4. SOCK_RDM: reliably-delivered message
  • 5. SOCK_SEQPACKET: sequenced packet stream

More types may be defined in the future

slide-2
SLIDE 2

2

IPC Implementation in UNIX Socket Layer (specifies required service)

  • Abstract objects that provide distinct endpoints
  • f communication
  • Buffering

Protocol Layer (implements the service)

  • Domains and their protocols

Network Layer:

  • Interface to the network hardware

Socket STREAM DATAGRAM SEQ-DGM TCP UDP XNS Xerox Domain Decnet Domain Internet Domain le0 le1 IP RAW Protocol Network

slide-3
SLIDE 3

3

FUNCTION CALLS FOR TCP/IP

KERNEL SPACE rwuio() sosend () soreceive () SOCKET TCP IP NETWORK tcp_usrreq () tcp_output () ip_output () leoutput () ether_output () lestart () tcp_input () ipintr () do_protocol() leread () leintr () write () read () NETWORK APPLICATION SPACE write () read () SYSTEM soo_rw()

slide-4
SLIDE 4

4

IPC Packet/Data Queues

Application Application Network Socket IP Queue Network TCP/IP Buffers Queue Layer Socket Layer Network Layer

slide-5
SLIDE 5

5

Data Transmission Application Buffer Socket Buffer Network Protocol (TCP/IP)

Data Net TCP IP Data TCP IP Data Net TCP IP Data TCP IP Data Data

slide-6
SLIDE 6

6

Data Reception Application Buffer Socket Buffer Network Protocol (TCP/IP)

Data Net TCP IP Data TCP IP Data Net TCP IP Data TCP IP Data Data Data Data Data

slide-7
SLIDE 7

7

Memory Management Requirements

  • Allocate/deallocate memory fast and efficiently
  • Handle both small and large packets efficiently
  • Copy packets efficiently
  • Trim data from front (headers) or back

(trailers) of packets efficiently (without copying)

  • Preserve packet sequence (streams, sequenced

datagrams)

  • Preserve packet boundaries (datagrams)
slide-8
SLIDE 8

8

Solution: Mbufs What is an mbuf (memory buffer)? m_next m_off m_len m_type 128 bytes 112 m_dat m_act 12 4

slide-9
SLIDE 9

9

Mbuf chains and lists Mbufs can be linked to form Chains using the m_next field:

  • r linked to form Lists using the m_act field:

m_next m_next m_next m_next m_next m_next m_act m_next m_next m_next m_act

slide-10
SLIDE 10

10

Storing Large packets Instead of storing data in the mbuf itself, data can be stored in an external page: The mbufs are called Cluster Mbufs In a cluster mbuf the m_dat field is always empty

m_next m_off m_len m_type m_dat external page m_act 1024 bytes

slide-11
SLIDE 11

11

Mbuf Allocation/Deallocation During system initialization a pool of memory pages is allocated to the mbuf store: Some of these pages are used for mbufs. The rest are used as external store for cluster mbufs: All free mbufs are on the mbuf free list All free pages are on the page free list Mbuf Store: Never paged out! kernel memory Pages containing mbufs Pages for cluster mbufs

slide-12
SLIDE 12

12

Mbuf allocation struct mbuf *m = m_get () Returns a pointer to an mbuf from the free list: int mclget (m): Given an mbuf attach a page to create a cluster mbuf: mfree m m mclfree

slide-13
SLIDE 13

13

Mbuf Deallocation struct mbuf *m_free (m): Given an mbuf chain, free the first mbuf and return a pointer to the next mbuf: m_free () works on cluster mbufs too int m_freem (m): Free a chain of mbufs mfree m n

slide-14
SLIDE 14

14

Mbuf Copy struct mbuf *m1 = m_copy (m, off, len): Copies len data bytes from m starting at offset off Returns a new mbuf chain m1 Copying a cluster mbuf is accomplished by:

  • allocating a new mbuf
  • making m_off to point to the external page
  • incrementing the reference count of the external

page m m1 = m_copy (m) results to: m m1 refcnt = 2 refcnt = 1

slide-15
SLIDE 15

15

Trimming an Mbuf int m_adj (m, len): if len is positive, trim len data from head if len is negative, trim len data from tail

m_next m_off m_len m_type m_act m_dat

slide-16
SLIDE 16

16

Mbuf to Data and Data to Mbuf data = mtod (m, type): Return the address of the data in the mbuf casting it to type e.g.: int *p; p = mtod (m, int *) struct mbuf *m = dtom (ptr): The inverse of mtod () Return the address of the mbuf where ptr resides

slide-17
SLIDE 17

17

Making mbuf data contiguous struct mbuf *m1 = m_pullup (m, len): Rearrange mbuf chain m so that len bytes are contiguous in the data area. Return resulting mbuf

  • chain. Copies data if necessary.

Needed so that mtod () and dtom () will work (e.g., when accessing protocol headers)

slide-18
SLIDE 18

18

Data Movement with Mbufs Application Buffer Socket Buffer

TCP/IP

Network Queue

Cluster mbuf containing data Mbuf containing header

Network

M D M D

Physical copy Physical copy Physical or logical copy Page containing data

H M D H M D H M D M D M D H M D H

slide-19
SLIDE 19

19

Timers Two types of timers are provided by the OS:

  • Fast timer: every 200 ms
  • Slow timer: every 500 ms

Every time a timer fires, the list of active connections is traversed and the protocol user request function is called for each connection: Protocol processing (like retransmissions or delayed ack) can now take place Active connections state state state state pr_usrreq (pcb, FASTTIMEO,...)

slide-20
SLIDE 20

20

IPC Packet/Data Queues

Application Application Network Socket IP Queue Network TCP/IP Buffers Queue Layer Socket Layer Network Layer

slide-21
SLIDE 21

21

Kernel Scheduling What is a system call? The kernel address space is always mapped into each process’ address space. During a system call, a user process enters the kernel (supervisor bit is set) and executes kernel code. Once processing is done, the supervisor bit is cleared and the process returns to user space. Any normal kernel processing (e.g., scheduling, interrupt processing) is therefore not affected (unless the system call masks interrupts) User Code Kernel Kernel Code System Call

supervisor bit set supervisor bit cleared

slide-22
SLIDE 22

22

Sending Data: Datagrams User Process Socket Layer Kernel UDP Layer IP Layer Network driver

packet

Network interface queue user process in kernel space interrupt Network

slide-23
SLIDE 23

23

Receiving Datagrams User Process Socket Layer Kernel UDP Layer IP Layer Network driver

packet

Protocol queue user process in kernel space interrupt Network

packet

Socket queue software interrupt

slide-24
SLIDE 24

24

Sending Data: Streams User Process Socket Layer TCP Layer IP Layer Network driver

packet

Network fill sockbuf; user data

sockbuf packet

call protocol; if sockbuf is full make a window of packets; put packets in network Q; while packets in queue send a packet; while there is data to send sleep; return;

slide-25
SLIDE 25

25

Receiving Stream Data User Process Socket Layer TCP Receive IP Receive Network driver Network TCP Send IP Send Ack interrupt interrupt wake up application

slide-26
SLIDE 26

26

Delaying Acknowledgment User Process Socket Layer TCP Receive IP Receive Network driver Network TCP Send IP Send Ack interrupt interrupt set TF_DELACK FASTTIMEO interrupt sw interrupt To avoid “silly window”, ack may be delayed:

slide-27
SLIDE 27

27

Receiving Acks User Process Socket Layer TCP Receive IP Receive Network driver Network TCP Send IP Send Ack interrupt interrupt data