CST252 Network Software Design - PowerPoint PPT Presentation

1 / 51
About This Presentation
Title:

CST252 Network Software Design

Description:

21 = ftp. 23 = telnet. often low port numbers ( 1024) are not accessible ... InetAddress.getByName('tiger.wmin..'); Then access IP ... 97-09-01 21:43:15 50 0 ... – PowerPoint PPT presentation

Number of Views:55
Avg rating:3.0/5.0
Slides: 52
Provided by: Davi825
Category:

less

Transcript and Presenter's Notes

Title: CST252 Network Software Design


1
CST252 Network Software Design
  • Lecture 7 Transport and Application Layers

2
Resources
  • Course Website
  • users.wmin.ac.uk/lancasd/CCTM91
  • Book
  • A.Tanenbaum Computer Networks chapters 1,6,(7)

3
Admin
  • Coursework solution code on web
  • After vacation
  • Network programming using Java
  • CWK2 hand out on 15th April
  • due Thursday 9th May
  • based heavily on Lecture 8 Java Sockets
  • Second Phase test
  • will cover whole course
  • date to be announced

4
Lecture 6 Review
  • Layered Models
  • IP Layer
  • Datagrams
  • IP Addresses
  • network host
  • subnetting
  • Routing
  • IP is connectionless and unreliable
  • discussed alternative virtual circuit approach

5
TCP/IP Model
Host A
Host B
Application Protocol
Transport Protocol
Internet Protocol
Physical Medium
6
Quiz
  • 255.255.0.0 is the standard mask for which class
    of IP network?
  • What is ARP
  • In principle - how many distinct IPv4 addresses
    are there?
  • Why might you want to subnet a network?
  • What is the effect on the way local routers
    operate?
  • What is the effect outside the network?

7
L7 Transport and Application Layers
  • Transport Layer
  • What it must accomplish
  • TCP and UDP
  • TCP mechanisms
  • Application Layer
  • DNS
  • Java and IPaddresses
  • Client-Server
  • Telnet

8
Transport Layer
  • This is the layer that provides an API to the
    application programmer
  • Built on top of unreliable connectionless
    Internet layer
  • UDP - like using raw IP - unreliable datagrams -
    faster than TCP
  • TCP - implement connections, error and flow
    control

9
Transmission Control Protocol
  • TCP as point to point byte stream
  • What has to be accomplished at this layer?
  • Reliability
  • Connection oriented
  • Flow control
  • Mechanisms
  • 3-way Handshake
  • Sliding Window
  • Congestion control and other efficiency issues

10
Point to Point
  • Point to Point
  • TCP is not broadcast or multicast
  • Uses sockets to identify end points
  • Socket (IPaddress , port)
  • IP address network card
  • port identifies (running) code within host
    machine
  • A connection is specified by the two end points
  • (socket1 , socket2)

11
Sockets
  • TCP and UDP both use concept of socket
  • Socket IPaddress port
  • Port numbers 16-bit,
  • port lt256 are well-known ports
  • 21 ftp
  • 23 telnet
  • often low port numbers (lt1024) are not accessible
    to user space code
  • Finding services /etc/services and inetd

12
Byte Stream
  • Application passes data to TCP which may
  • send immediately (force with PUSH flag)
  • buffer temporarily
  • The local byte stream (not message stream)
  • broken into segments
  • attach TCP header
  • place into IP datagrams

13
TCP Segments
  • Up to TCP to decide how to break up the byte
    stream a segment
  • maximum must fit into IP datagram
  • minimum size 0
  • segments containing no data are legal and common
  • Fragmentation
  • segments may get broken up on some step of their
    journey because IP datagram is fragmented
  • reconstruct

14
TCP What has to be accomplished at this layer?
  • Reliability
  • acknowledgement packets
  • Connection oriented
  • sequence numbers
  • Flow control
  • receiver specifies space left in its buffer
  • Congestion control
  • various algorithms

15
TCP reliability
  • Resend lost packets
  • start a timer at the same moment that the packet
    is sent
  • when the packet is received, the destination host
    replies with an acknowledgement packet
  • if the timer on the source host goes off (a
    timeout) before the acknowledgement arrives, it
    resends the packet
  • (but dont have to wait for previous
    acknowledgement before sending next packet)

16
TCP Connections
  • Connection oriented
  • Packets from the source must be received in order
  • Attach a sequence number to each byte
  • Also aids reconstructing fragmented packets
  • But note - retransmission for reliability leads
    to the possibility of delayed duplicates
  • Each packet must be received only once

17
Sequence numbers and reliability
  • Delayed duplicates may occur due to basic
    reliability mechanism
  • Dont want machines to have to rely on keeping a
    history - what happens on a crash?
  • Bound the packet lifetime - TTL
  • This guarantees that there are no packets after a
    certain time T
  • Now use a big enough sequence space to ensure
    that within T all packets are unique
  • Use low order bits of real time clock to set
    initial sequence number

18
Flow Control
  • End to end - cf congestion
  • Ensure that the receiver can accept the data that
    is sent ie the receive buffer has space
  • Pass information about the amount of space left
    on the receive buffer back to the sender
  • The sender must not send more than this amount of
    data

19
TCP Segment Header
32-bits
Destination port
Source port
Sequence number
Acknowledgement number
F I N
Window size
various flags .....
Checksum
Urgent pointer
Options
20 byte fixed variable length optional part
20
TCP segment Header
  • 32-bit sequence and acknowledgement
  • 16-bit window size - zero is legal
  • Flags
  • if ACK 0 ignore the acknowledgement field
  • SYN for setting up connection
  • FIN for closing connection
  • PSH pushed data - request that it not be buffered

21
Setting up a Connection
  • A connection allows
  • the byte stream to be reconstructed from multiple
    packets
  • a flow control mechanism
  • Sets up an agreement on sequence and
    acknowledgement numbers
  • More difficult to set up than it appears due to
    the possibility of delayed duplicates
  • Three way handshake
  • Special SYN and ACK fields

22
Three way Handshake
Listen
SYN recv
SYN sent
ltSEQ40gtltSYNgt
ltSEQ200gtltACK41gtltACKgtltSYNgt
Established
send ACK
ltSEQ40gtltACK201gtltACKgt
Established
Established
Send data
ltSEQ41gtltACK201gtltACKgtltDATAgt
Recv Data
23
Three way Handshake
  • B listens to a port
  • A sends a segment with sequence number SA and SYN
    flag set
  • B replies with its own sequence number and
    acknowledgement number SA 1 and SYN and ACK
    set
  • A now considers connection established and sends
    acknowledgment with SYN and ACK set
  • B also considers connection established

24
Setup Issues
  • Important reason for such an elaborate setup is
    that it is robust - and works even in the
    presence of delayed duplicates
  • Draw pictures to convince yourself
  • Overhead for setup

25
Sending Data
  • Once the connection is set up - send data
  • Each data byte has a sequence number
  • Specify the amount of space left on the receive
    buffer in the window field of the header
  • Can send more than one segment before receiving
    acknowledgment of the first
  • Assuming duplex communication, piggyback
    acknowledgements (combined) onto a data packet
    from destination to source

26
Sliding Window
  • Implement both error control and flow control
    with a window
  • Window contains information about how much data
    can be sent and also which data has yet to be
    acknowledged
  • Upper and lower pointers define a region or
    window of sequence numbers

27
Send and Receive Windows
  • Send window
  • list of sequence numbers that can be sent
  • Receive window
  • list of sequence numbers that can be received
  • ignore any packet with sequence number outside
    this range

28
Congestion Control
  • Causes of dropped packets
  • hardware faults on a link - rare now (but still
    frequent for wireless)
  • buffer overflow in an intermediate router (due to
    excess traffic in the network)
  • So regard dropped packets (timeouts) as a signal
    of congestion
  • Control by adjusting the sending rate
  • (cf flow control - to ensure destination machine
    buffer does not overflow)

29
Congestion
  • To fix congestion - must fundamentally limit the
    amount rate of data
  • Besides window based on size of receive buffer
  • Introduce a congestion window
  • Send an amount of data determined by the minimum
    from each window

30
Congestion Window Size
  • Algorithm to determine congestion window, grows
    until there is a timeout - then backs-off
  • exponential slow start
  • up to threshold 1/2 pre-timeout value
  • then linear to max (receive window size)
  • Sometimes experience this on browsers

31
Timeout value
  • Too short unnecessary retransmissions
  • Too long bad performance due to long delay
    before resending
  • Dynamically set the timeout - based on times that
    previous packets were acknowledged
  • timeout RTT 4D
  • RTT best current estimate of round trip time
  • D cheaply calculated standard deviation

32
Closing the connection
  • Non trivial theoretically in the presence of
    delayed duplicates - but little problem in
    practice
  • Must ensure that any remaining packets are
    received
  • Either side may terminate
  • Use the FIN flag

33
Transmission Policy
  • Transmit data as soon as it is provided by the
    application - or buffer to make bigger segments?
  • Nagles Algorithm
  • buffer until first byte is acknowledged
  • improves bandwidth use, but bad for latency so
    sometimes want to turn it off
  • Case of slow receive application

34
UDP
  • User Datagram Protocol
  • UDP header just includes
  • source and destination ports
  • segment length
  • checksum
  • About 20 bytes
  • Less overhead - good for certain applications
    that do not require reliability

35
Application Layer
  • DNS
  • Java and network addresses
  • Client - Server
  • Telnet as a tool
  • Java sockets
  • Treat most application protocols as we come to
    them rather than abstractly here

36
DNS Domain Name Service
  • Addresses (eg of server on internet)
  • text for humans
  • tiger.wmin.ac.uk
  • numbers for computers (routers etc)
  • 161.74.107.60
  • Easy to keep track of mapping if there were only
    a few hosts
  • But as the internet got big - related by DNS
  • hierarchical naming scheme
  • distributed database for storing the map

37
DNS Namespace Domains
.........
com
edu
gov
org
jp
nl
uk
co
ac
keio
nec
cs
  • cs.keio.ac.jp
  • Case insensitive
  • Follows organizational, not network boundaries
  • Each domain controls the one below it to avoid
    name clashes

38
DNS Database
  • Map name to a resource record
  • Resource record includes
  • IP number
  • TTL (how stable is this record)
  • other stuff

39
DNS NameServers
  • When an application on your host needs the IP
    number corresponding to a domain name
  • Requests DNS nameserver using UDP
  • The whole database is not stored on each
    nameserver - divide into zones containing
  • Authoritative (primary) nameserver (info on disk)
  • Secondary nameservers (info from primary)

40
Lookup
  • Send request to local nameserver
  • If domain sought is in zone of that nameserver -
    get back authoritative IPaddress
  • If not - the nameserver queries the toplevel
    nameserver for the domain sought, which itself
    may need to make further queries
  • Cache the resulting IPaddress (not authoritiative
    - mark in TTL field)

41
Internet Addresses in Java
  • Utility methods in InetAddress class
  • InetAddress addr
  • InetAddress.getByName(tiger.wmin..)
  • Then access IP bytes with getBytes()
  • byte baddr addr.getBytes()
  • Some host names correspond to several IP numbers
    getAllByName()
  • InetAddressTest.java

42
Clients and Servers
  • Server
  • listens and responds
  • often just copies a file to the network
  • Client
  • connects to server using its address
  • requests a response
  • More general patterns possible
  • code sometimes requests, sometimes responds

43
Telnet as a tool
  • A generic network client program
  • Available on UNIX and windows
  • Connect to a server (address and port)
  • gt telnet time-A.timefreq.bldrdoc.gov 13
  • Responds with
  • 50692 97-09-01 214315 50 0 0 50.0 UTC(NIST)
  • The time according to an atomic clock at the
    National Institute of Standards and Technology,
    Boulder, Colorado

44
Client connects to Server
132.163.135.130 13 Data
Client
13
Internet
Ports
Server
45
Client Server is always like this
  • Client connects to an addressport number
  • Server is permanently running, listening to that
    port
  • server replies to the client
  • Client receives the reply
  • Differences between servers lie in the kind of
    request they expect (protocol) and reply they
    send

46
Another Server Example
  • Connect via telnet to
  • www.wmin.ac.uk
  • Type in telnet (gets passed to server)
  • GET / HTTP/1.0
  • Enter key twice (send an empty line)
  • Get back a bunch of html formatted text
  • This is exactly what a web browser does

47
Proxy issues
  • Actual experiments from lab
  • Take account of the University Proxy server
  • Port 8080

48
Client in Java
  • Repeat exactly what we did with telnet
  • Open a socket
  • Socket is an abstraction for the network software
  • This is a low level approach
  • Connect to an addressport
  • Get the response
  • SocketTest.java

49
SocketTest.java
  • import java.io.
  • import java.net.
  • public class SocketTest
  • public static void main(String args)
  • try
  • Socket s new Socket(time-A.timefreq.bldrdo
    c.gov,13)
  • BufferedReader in new BufferedReader
  • (new InputStreamReader(s.getInputStream()))
  • boolean more true
  • while (more)
  • String line in.readLine()
  • if (line null) more false
  • else System.out.println(line)
  • catch (IOException e)
  • System.out.println(Error e)

50
SocketTest Notes
  • Import both java.net and java.io
  • Open a socket using address and port
  • Once the socket is open, can get a stream
  • here just inputStream
  • Read reply using standard I/O layering of streams
    - just like reading a disk file
  • Catch exceptions

51
Exercise
  • Modify SocketTest.java to connect to a web server
    and get a web page
Write a Comment
User Comments (0)
About PowerShow.com