Advanced UDP Sockets - PowerPoint PPT Presentation

1 / 40
About This Presentation
Title:

Advanced UDP Sockets

Description:

When to use UDP instead of TCP. Adding Reliability to a UDP Application ... Receiving Flags, Destination IP address, and Interface Index(1) ... – PowerPoint PPT presentation

Number of Views:25
Avg rating:3.0/5.0
Slides: 41
Provided by: comlabKwa
Category:
Tags: udp | advanced | index1 | sockets

less

Transcript and Presenter's Notes

Title: Advanced UDP Sockets


1
Advanced UDP Sockets
  • Kwangwoon Univ,
  • Department of Computer Science.
  • M.Sc masters course.
  • In-sik LEE (gohacker_at_kw.ac.kr)

2
Contents
  • Receiving Flags, Destination IP address, and
    Interface index
  • Datagram Truncation
  • When to use UDP instead of TCP
  • Adding Reliability to a UDP Application
  • Binding Interface Addresses
  • Concurrent UDP servers
  • IPv6 Packet Information
  • IPv6 Path MTU Control

3
Receiving Flags, Destination IP address, and
Interface Index(1)
  • Historically sendmsg, recvmsg have been used.
  • Will write a function recvfrom_flags.
  • Returned msg_flags value.
  • The destination address of the received datagram.
  • The index of the interface on the datagram was
    received.
  • Defined in unp.h
  • Value of index is zero(0) -gt unknown value
  • Destination address is zero (o.o.o.o) -gt unknown
    real value
  • RFC 1122
  • Valid only when a host booting , and does not yet
    known its IP address.

4
Receiving Flags, Destination IP address, and
Interface Index(2)
Recvform_flags functioncall recvmsg
5
Receiving Flags, Destination IP address, and
Interface Index(3)
Recvform_flags functioncall recvmsg
6
Receiving Flags, Destination IP address, and
Interface Index(4)
Recvform_flags functioncall recvmsg
7
Example (Destination IP and datagram truncated
Flag(1)
dg_echo function that call recvfrom_flag function
8
Example (Destination IP and datagram truncated
Flag(2)
dg_echo function that call recvfrom_flag function
9
Datagram Truncation
  • When a UDP datagram arrives that is larger than
    the applications buffer, recvmsg sets the
    MSG_TRUNC flag in the msg_flags member of the
    msghdr structure.
  • Three possible scenarios (other solution)
  • Discard the excess bytes, and return the
    MSG_TRUNC flag to the application. Application
    call recvmsg to receive the flag
  • BSD/OS
  • Discard the excess bytes, do not tell the
    application.
  • Solaris 2.5
  • Keep the excess bytes and return them in
    subsequent read operations on the socket.

10
When to use UDP instead of TCP(1)
  • Advantage of UDP
  • Support broadcasting and multicasting.
  • UDP must be used if the application uses
    broadcasting or multicasting.
  • Require only two packets to exchange a request
    and a reply. (size of each is less than the
    minimum MTU between the two end-system, TCP
    require about 10 packets)
  • Minimum transaction time for a UDP request-reply
    is RTT SPT (server processing time)
  • TCP connection is used for the request-reply, the
    minimum transaction time is (2 x RTT) SPT,

11
When to use UDP instead of TCP(2)
  • List of TCP that are not provided by UDP
  • Acknowledgments, retransmission, duplicate
    detection, sequencing of packets reordered by the
    network.
  • Windowed flow control
  • Receiving TCP tell the sender hoe much buffer
    space, and the sender cannot exceed this.
  • Slow start and congestion avoidance.
  • There are exception to these rules.
  • TFTP uses UDP for bulk data transfer.
  • Simpler than TCP in bootstrap code (TCP4500,
    UDP800)
  • NFS uses UDP for bulk data transfer.
  • Some might claim it is really a request-reply
    application.

12
Adding reliability to a UDP application.(1)
  • if use UDP for a request-reply application, then
    must add two features to our client.
  • Timeout and retransmission to handle datagram
    that are discarded.
  • Sequence number so the client can verify that a
    reply is for the appropriate request.
  • Problem
  • The RTT between a client and server can change
    rapidly with time, as network conditions change.
  • Calculate the RTO (retransmission timeout)

13
Adding reliability to a UDP application.(2)
  • Calculate RTO
  • srtt smoothed RTT estimator
  • rttvar smoothed mean deviation estimator
  • delta difference between measured RTT and the
    current smoothed RTT estimator (srtt)
  • g gain applied to the RTT estimator and equals
    1/8.
  • h gain applied to the mean deviation estimator
    and equals ¼.
  • When the retransmission timer expire, an
    exponential backoff (2,4,8,16)

14
Adding reliability to a UDP application.(3)
  • Following three possible scenario when our
    retransmission timer expires.
  • The request is lost
  • The reply is lost
  • The RTO is too small

15
Adding reliability to a UDP application.(4)
dg_send_recv function
16
Adding reliability to a UDP application.(5)
dg_send_recv function
17
Adding reliability to a UDP application.(6)
dg_send_recv function
18
Adding reliability to a UDP application.(7)
dg_send_recv function
19
Adding reliability to a UDP application.(8)
unprtt.h
20
Adding reliability to a UDP application.(9)
RTT_RTOCALC macro, rtt_minmax, rtt_init function
21
Adding reliability to a UDP application.(10)
rtt_ts, rtt_newpack, rtt_start function
22
Adding reliability to a UDP application.(11)
rtt_stop functionUpdate RTT estimators,
calculate new RTO
23
Adding reliability to a UDP application.(12)
rtt_timeout function exponential backoff
24
Binding Interface Addresses(1)
UDP server that binds all address
25
Binding Interface Addresses(2)
UDP server that binds all address
26
Binding Interface Addresses(3)
UDP server that binds all address
27
Binding Interface Addresses(4)
mydg_echo function
28
Binding Interface Addresses(4)
Execute udpserv03.c
29
Concurrent UDP Servers(1)
  • The server waits for a client request, reads the
    request, processes the request, sends back the
    reply, and then waits for the next client
    request.
  • TCP It is simple to just fork a new child (or
    create new thread) and let the child handle the
    new client.
  • UDP Must deal with two different types of
    servers

30
Concurrent UDP Servers(2)
31
IPv6 Packet Information(1)
  • IPv6 allows an application to specify up to five
    pieces of information for an outgoing datagram.
  • Source IPv6 address
  • Outgoing interface index
  • Outgoing hop limit
  • Next-hop address
  • Outgoing traffic class
  • Four similar pieces of information can be
    returned for a received packet (ancillary data
    with recvmsg)
  • Destination IPv6 address
  • Arriving interface index
  • Arriving hop limit
  • Arriving traffic class

32
IPv6 Packet Information(2)
33
IPv6 Packet Information(3)
  • An in6_pktinfo structure contain either the
    source IPv6 address and outgoing interface index
    for an outgoing datagram or the destination IPv6
    address and arriving interface index for a
    received datagram

struct in6_pktinfo struct in6_addr
ipi6_addr / src/dst IPv6 address
/ int ipi6_ifindex
/ send/recv interface index /
34
IPv6 Packet Information(4)
  • Outgoing and arriving interface
  • No interface is ever assigned an index of 0.
  • If the ipi6_ifindex value is 0, kernel will
    choose the outgoing interface.
  • Source and destination IPv6 addresses
  • The source IPv6 address is normally specified by
    calling bind. Source address together with the
    data may less overhead.
  • When specifying the source IPv6 address ancillary
    data, if ipi6_addr member of the in6_pktinfo
    structure is IN6ADDR_ANY_INIT then,
  • If and address is currently bound to the socket,
    Its use
  • if no, kernel will choose the source address.

35
IPv6 Packet Information(5)
  • Specifying the Next-Hop address
  • The IPV6_NEXTHOP ancillary data specifies the
    next hop for the datagram as a socket address
    structure.
  • In the cmsghdr structure containing this
    ancillary data.
  • cmsg_level member is IPPROTO_IPV6, the cmsg_type
    member is IPV6_NEXTHOP, and the first byte of
    data is the first byte of the socket address
    structure.
  • The node identified by that address must be a
    neighbor of the sending host.
  • If that address equals the destination IPv6
    address of the datagram, then this is equivalent
    to the existing SO_DONTROUTE socket option.

36
IPv6 Packet Information(6)
  • Specifying Receiving the traffic class
  • IPV6_TCLASS ancillary data specifies the traffic
    class for the datagram.
  • cmsg_type member will be IPV6_TCLASS. (diffserv)
  • Include the ancillary data with that packet.
  • Described in Section 27.7

37
IPv6 Path MTU Control(1)
  • Purpose program may want to modify the path MTU
    discovery behavior. Follow four socket option.
  • Sending with minimum MTU
  • Packets are normally fragmented using the MTU of
    the outgoing interface or the path MTU, whichever
    is smaller.
  • IPv6 defines a minimum MTU of 1,280 bytes.
  • Dropped packets and delay while the MTU is being
    discovered.
  • The use of the minimum MTU is controlled with the
    IPV6_USE_MIN_MTU socket option.
  • Three define value
  • -1 multicast (perform to unicast destination)
  • O performs path MTU discovery to all
    destination
  • 1 use the minimum MTU for all destination

38
IPv6 Path MTU Control(2)
  • IPV6_USE_MIN_MTU can also be sent as ancillary
    data.
  • cmsg_type is IPV6_USE_MIN_MTU.
  • Receiving path MTU change indications
  • Receive change notification is the path MTU, an
    application can enable the IPV6_RECVPATHMTU
    socket option.
  • Anytime it change (in ancillary data cmsghdr
    structure)
  • cmsg_type member will be IPV6_PATHMTU.

struct in6_mtuinfo struct sockaddr_in6
ip6m_addr / destination address /
unit32_t ipi6m_mtu /
path MTU in host byte order /
39
IPv6 Path MTU Control(3)
  • Determining the Current path MTU
  • If an application has not been keeping track with
    the IPV6_RECVPATHMTU option, it can determine the
    current path MTU of a connected socket with the
    IPV6_PATHMTU option.
  • Returns an ipv6_mtuinfo structure containing the
    current path MTU.
  • Avoiding fragmentation
  • An application such as traceroute may not want
    this automatic fragmentation.
  • The IPV6_DONTFRAG socket option is used to turn
    off automatic fragmentation.
  • 0 permit
  • 1 turn off

40
IPv6 Path MTU Control(4)
  • IPV6_DONTFRAG can also be sent as ancillary data.
  • cmsg_type member will be IPV6_DONTFRAG.
Write a Comment
User Comments (0)
About PowerShow.com