Outline: ATM, Sockets Programming
- ATM (Asynchronous Transfer Mode)
- Routing
- QoS (Quality of Service)
- Sockets Programming
- socket
- connect
- bind
- listen
- accept
- read
- write
- read
- close
ATM
- Asynchronous Transfer Mode -- as opposed to SONET (Synchronous
Optical Network)
- originally telephone technology
- virtual circuits
- 53-byte fixed-size cells with 5-byte header
- resource reservation:
ATM Switching
- 5-byte header has a two-part identifier
- identifier is only meaningful in one direction along a single link
- when cell is received, switch:
- uses port number and identifier as index into table containing:
- outgoing identifier
- outgoing port number
- QoS indication
- places outgoing identifier into cell header
- routes cell to outgoing port
- table is set up at "virtual circuit setup time"
Example
Figure 2.8
ATM QoS
- Leaky bucket
- Example: 100 sources, each sending at rate r <= (0.1 + 1.5t)Mb/t
- if t >> 1, r =~ 1.5 Mb/s
- if t << 1, burst <= 0.1 Mb
- therefore, traffic can be carried with no loss by a 155Mb/s
link with a 10Mb buffer.
- Maximum delay is (10Mb / 155Mb/s) =~ 0.065 s = 65ms.
- Leaky bucket and QoS reservations can be used to bound delay
and eliminate or bound data loss.
Sockets: Overview
- Server listens for connections
- Server is identified by
(ip address, port number)
- Client initiates connections
- Client is assigned a port number automatically
- Data can be exchanged in either direction
- (ipA, portA, ipB, portB) uniquely identifies a socket
socket system call
-
socket
(int domain,
int type,
int protocol)
- socket returns a file descriptor
- socket domain is
AFINET
for internet
- socket type is
SOCKSTREAM
for TCP, SOCKDGRAM
for UDP
- protocol is given by
getprotobyname("tcp")
connect system call
IP address
struct hostent * hostentry;
struct sockaddrin sin;
struct sockaddr * sap =
(struct sockaddr *) &sin;
hostentry =
gethostbyname("maru.ics.hawaii.edu");
if ((hostentry == NULL) ||
(hostentry->haddrlist == NULL))
error("gethostbyname");
bzero (&sin, sizeof (sin));
sin.sinfamily = AFINET;
bcopy(hostentry->haddrlist[0],
&(sin.sinaddr),
hostentry->hlength);
sin.sinport = htons(portnumber);
if (connect(s, sap, sizeof(sin)) < 0)
error("connect");
Notes:
Skip this slide unless we have plenty of time.
bind
listen
accept
- accept is used by server to create a new socket when a new
connection is requested by the client.
-
int accept(int s,
struct sockaddr *addr,
int *addrlen);
- accept returns a new file descriptor for success, -1 for failure
- the address and addrlen pointers are optional (can
be NULL), only used if the server wants to know the address of
the client. If address is specified, before the call {\tt
addrlen} MUST have the size of the object pointed to by address.
read
- read is used by either side to receive data sent by the other side.
-
int read(int s,
char *buf,
int bufsize);
- read returns the number of bytes read for success, -1 for failure
- the buffer and buffer size must be specified.
- the buffer size must be the size of the area pointed to by buf
- the number of bytes read is always less than or equal to the bufsize
- after the call, the buffer does NOT contain a C string, because it
lacks the terminating null character.
Notes:
Skip this and the next two depending on time.
write
- write is used by either side to receive data sent by the
other side.
-
int write(int s,
char *buf,
int nbytes);
- write returns the number of bytes written for success, -1
for failure. The number of bytes written will always be less than or
equal to nbytes.
- the buffer and buffer size must be specified.
- the buffer size must be less than or equal to the size of the
area pointed to by buf
- write will happily write NULL characters, so use
strlen
to compute nbytes when writing C string.
close
- all file descriptors, including sockets, should be closed when no longer
needed (otherwise your program may run out of file descriptors).
-
int close(int fd);
- close returns 0 for success, -1
for failure.
Homework 1
- Experiment with Unix Clients and Servers
- See web page.
- Request Unix account if needed, by sending mail to sunx@hawaii.edu
- Request account IMMEDIATELY, since may take 1-2 days to set up
- Due on Friday September 4th (because project 1 will be assigned
on Friday), but can be handed in as late as Wed. (September 9th) for
full credit.