







Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Notes; Professor: Xu; Class: COMPUTR NETWRK PROGRAMNG; Subject: Computer Science & Engineering; University: University of South Carolina - Columbia; Term: Fall 2008;
Typology: Study notes
1 / 13
This page cannot be seen from the preview
Don't miss anything!








CSCE515 – Computer Network Programming
OSI, TCP/IP
CSCE515 – Computer Network Programming
A simplified model The network layer
Hosts drop packets into this layer, layer routes towards destination- only promise- try my best The transport layer
Reliable/unreliable byte oriented stream
Application Presentation Session Transport Network Data link Physical
Transport Network
Application
Host to Network Layer
OSI model TCP/IP model
CSCE515 – Computer Network Programming
CSCE515 – Computer Network Programming
Physical Layer: no address necessary
Data Link Layer – address must specify the host
MAC address
Network Layer – address must identify the
network
IP address
Transport Layer - address must identify the
destination process.
Port #
CSCE515 – Computer Network Programming
Date Link Layer Functionality
What is the main Functionality of date link layer?
Provides reliable transfer of information between two adjacent nodes
What is the service provided by data link layer?
Encoding: Convert bits to signals and recover bits from received signals
Framing: decide on a minimum unit for sending bits
Error detection and /or correction of frames Parity, CRC
Flow control ARQ, Sliding WINDOW
CSCE515 – Computer Network Programming
Framing
A frame is a group of bits, typically in sequence
Issues:
Frame creation
Frame delineation
Use starting and ending characters (tags) to mark boundaries of frame
Problem: what if tag characters occur in the date or control portions of the frame
Use preamble + packet length
CSCE515 – Computer Network Programming
Error Control
No physical link is perfect, bits will be corrupted
We can either:
Detect errors and request retransmission
Or correct errors without retransmission
Error Detection
Parity bits Polynomial codes or checksums Cyclic Redundancy Check (CRC)
Given a polynomial code and a message, what is the checksummed message
Given a checksummed message, can you determine whether there are errors.
CSCE515 – Computer Network Programming
Ethernet - A Real Data-Link Layer
What is header of a typical Ethernet frame?
How is Ethernet connected? What is the address used in Ethernet?
example: 08:00:e4:b1:
What is the basic protocol? -- CSMA/CD
Multi-access (shared medium) many hosts on 1 wire
Carrier sense: can tell when another host is transmitting
Collision detection: How can a device detect collision? How to avoid two device collide again?
Transmit Algorithm
If line is idle…
send immediately
upper bound message size of 1500 bytes
must wait 9.6us between back-to-back frames
If line is busy…
wait until idle and transmit immediately
Collisions
CSCE515 – Computer Network Programming
Host and Network Addresses
A single network interface is assigned a single IP address called the host address.
A host may have multiple interfaces, and therefore multiple host addresses.
Hosts that share a network all have the same IP network address (the network ID).
Display all network interface on a host
ifconfig – a
netstat -i
CSCE515 – Computer Network Programming
IP Routing
Actual routing table contains: destination IP address, IP address of next-hop router, network interface, Flag
CSCE515 – Computer Network Programming
IP Routing
Forwarding:
When each packet arrives, looking up the outgoing line to use for it in the routing table
Done on a hop-by-hop basis
If destination is directly connected or on a shared network, send IP datagram directly to destination
Otherwise send datagram to a default router
Routing updates
filling in and updating the routing tables
CSCE515 – Computer Network Programming
Mapping IP Addresses to/from Hardware
Addresses
Address Resolution Protocol
How?
Why?
When?
Reverse Address Resolution
How?
Why?
When?
IP Addresses
Subnet Addressing
To make better use of class A and class B
addresses, divide host ID into subnet ID and
host ID
10 NetID^ SubnetID^ HostID
10 NetID HostID
Class BClass B
Subnet Mask
32-bit value containing “1” bits for network ID and subnet ID, and “0” bits for host ID 14 8 8
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 255.255 .255. 0xFFFF FF 00
B B 10 NetID^ SubnetID^ HostID
Example: A and B are class B addresses, using the same subnet mask. A = 165.230.82. B = 165.230.24.93 Same network? M = 255.255.255.0 Same subnet?
CSCE515 – Computer Network Programming
Subnetting
It is possible to have a single wire network
with multiple subnets?
CSCE515 – Computer Network Programming
Variable length subnetting
Subnet masks allow power of 2 subnets
Use a hierarchy of routers to allow subnets to be divided with different subnet masks
Another approach:
Variable length subnet masks
Allow a subnet to be defined by more than two masks
The router applies the masks one after another
mask: 255.255.255. 255.255.255.192 subnet 1
subnet 2,
mask: 255.255.255. subnet: 221.2.3.
mask: 255.255.255.
subnet: 221.2.3.
subnet: 221.2.3.
CSCE515 – Computer Network Programming
Question
If an ISP has a 203.6.8.0 Network, he has
5 customers who in turn has a network of
60, 60, 60, 30, 30 hosts. If the ISP wants to
assign a subnet to each customer
What should the subnet mask be?
What is the address range in each subnet?
What should the routing table entries be?
CSCE515 – Computer Network Programming
CIDR - (classless Inter domain routing)
Original addressing schemes (class-based):
32 bits divided into 2 parts:
Class A
Class B
Class C
Class C address has max of 254 hosts
Not enough for many organizations
Too many class C addresses Æ huge routing tables Use CIDR address mask to aggregate
CIDR introduced to solve 2 problems:
exhaustion of IP address space
size and growth rate of routing table
0 NetID HostID 10 NetID HostID
110 NetID HostID
Address Arithmetic: Address Blocks
Address format <IP address/prefix P>.
The prefix denotes the upper P bits of the IP address.
Can be used to specify arbitrary blocks of addresses
The <address/prefix> pair defines an address block:
Examples:
200.15.0.0/16 => [ 200.15.0.0 - 200.15.255.255 ]
192.24.0.0/13 => [ 192.24.0.0 - 192.31.255.255 ]
13th bits fixed Variable
Example of CIDR
CIDR Block Prefix # Equivalent Class C # of Host Addresses /27 1/8th of a Class C 32 hosts /26 1/4th of a Class C 64 hosts /25 1/2 of a Class C 128 hosts /24 1 Class C 256 hosts /23 2 Class C 512 hosts … /15 512 Class C 131,072 hosts /14 1,024 Class C 262,144 hosts /13 2,048 Class C 524,288 hosts
CSCE515 – Computer Network Programming
TCP
TCP provides the end-to-end reliable
connection that IP alone cannot support
The TCP protocol
Frame format
Connection Creation
Flow control
Congestion control
Connection termination
CSCE515 – Computer Network Programming
Addressing in TCP/IP
Each TCP/IP address includes:
Internet Address
Protocol (UDP or TCP)
Port Number
NOTE: TCP/IP is a protocol suite that includes IP, TCP and UDP.
CSCE515 – Computer Network Programming
Hmmmmm. TCP or UDP?
Electronic commerce?
Video server?
File transfer?
Email?
Chat groups?
Robotic surgery controlled remotely over a
network?
CSCE515 – Computer Network Programming
TCP Segment Format
0 15 16 31
20 bytes
destination port number
TCP checksum urgent pointer
option (if any)
source port number
window size
sequence number
acknowledgment number header length reserved
U R G
A C K
P S H
R S T
S Y N
F I N
data (if any)
TCP segment
There are a bunch of control flags:
URG: urgent data included. ACK: this segment is (among other things) an acknowledgement.
RST: error - abort the session.
SYN: Used to establish connection; synchronize Sequence Numbers (setup)
FIN: polite connection termination.
Client Server
SYN ISN= X
1
2
3
time
TCP Connection Establishment
“I want to talk, and I’m starting with byte number X+1 ”.
“OK, I’m here and I’ll talk. My first byte will be called number Y+1, and I know your first byte will be number X+1” “Got it - you start at byte number Y+1”.
CSCE515 – Computer Network Programming
TCP is a reliable service.
IP delivers each TCP segment.
IP is not reliable.
CSCE515 – Computer Network Programming
Sender
Application does a 2K write
Application reads 2k
Sender is blocked
2K SEQ=0^ empty
receiver 0 4K
recv’s buffer
ACK = 2048 WIN = 2048 Application does a 3K write 2K SEQ= Full ACK = 4096 WIN = 0
ACK = 4096 WIN = 2048
1k (^) SEQ=
Sender may send up to 2k
CSCE515 – Computer Network Programming
App1 App
1
2
4
3
“I have no more data for you” FIN_WAIT_
“ OK, I understand you are done sending .” CLOSE_WAIT
“OK - Now I’m also done sending data”. LAST_ACK
“Over and Out, Goodbye” TIME_WAIT
FIN_WAIT_
CLOSED
CSCE515 – Computer Network Programming
CSCE515 – Computer Network Programming
What is Socket?
Network API, developed by Berkeley
Between which two layers do the socket sit?
What is the wish list of a socket?
What functions should the socket provide?
What are the elements of a Socket?
What is a socket descriptor?
What are the two typical socket types?
Stream sockets
Datagram sockets
CSCE515 – Computer Network Programming
socket()
bind()
listen()
accept()
read()
write()
read()
close()
socket()
connect()
write()
read()
close()
TCP Client
TCP Server
well-known port
blocks until connection from client
process request
connection establishment data(request)
data(reply)
end-of-file notification
CSCE515 – Computer Network Programming
Server
3-way handshake complete
accept
arriving SYN
Completed connection queue
Incomplete connection queue
Sum of both queues cannot exceed backlog
CSCE515 – Computer Network Programming
How to create UDP sockets? sock = socket(PF_INET, SOCK_DGRAM,0);
What is the typical workflow for:
Client
Server
How to send data?
sendto() How to receive data?
recvfrom() If buff is not large enough, any extra data is lost forever... Timeout for recvfrom()
Connected mode?
Why?
How?
Who can?
socket()
bind()
recvfrom()
sendto()
socket()
sendto()
recvfrom()
close()
UDP Client
UDP Server well-known port
blocks until datagram received from client
process request
data(request)
data(reply)
signal(SIGALRM, sig_alrm); alarm(max_time_to_wait); if (recvfrom(…)<0) if (errno==EINTR) / timed out / else / some other error / else / no error or time out*
*- turn off alarm / alarm(0); There are some other (better) ways to do this - check out section 14.
static void sig_alrm(int signo) { return; }
CSCE515 – Computer Network Programming
Connected mode
A UDP socket can be used in a call to.
What will OS do after connect() is called?
Register the address of the peer in OS
No handshake
No data is sent
Once a UDP socket is connected:
can use write() and send()
can use read() and recv() only datagrams from the peer will be returned.
CSCE515 – Computer Network Programming
Connected UDP sockets for TFTP Concurrency
Client 2
UDP datagram
Client 1
Server
UDP(69)
UDP datagram
UDP(9001) UDP(9000)
CSCE515 – Computer Network Programming
Questions
Can UDP socket connected to a broadcast
address?
A: yes, a connected UDP socket exchanges
datagrams with only one IP address
Server A is connected to a broadcast
address, so….
Can this UDP socket send?
Can this UDP socket Receive?
IO Multiplexing
I/O Multiplexing
Why do we need I/O Multiplexing?
need to be able to monitor multiple descriptors
What are the options to achieve IO Multiplexing?
What are the cons and pros for each option?
Use nonblocking I/O. use fcntl() to set O_NONBLOCK
Use alarm and signal handler to interrupt slow system calls.
Use multiple processes/threads.
Use functions that support checking of multiple input sources at the same time.
Using select()
What does select() do?
system call allows us to use blocking I/O on a set of descriptors (file, socket, …).
How to use select()
Create fd_set
Clear the whole thing with FD_ZERO
Add each descriptor you want to watch using FD_SET.
Call select
when select returns, use FD_ISSET to see if I/O is possible on each descriptor.
CSCE515 – Computer Network Programming
Sample question 1
Show the execution of Dijkstra’s algorithm on the following graph, with vertex A as the source vertex. At each step, show the value of the chosen vertex ( w ) and the updates to the distance and parent vectors.
CSCE515 – Computer Network Programming
Sample question 2
Java port scanner. Write a port scan
program. In particular, you are asked to
write a program that will find out (print out)
which of the first 1024 ports seem to be
hosting TCP servers on a host
“broad.cse.sc.edu”
CSCE515 – Computer Network Programming
Sample question 3
Please explain the packet captured in wireshark.