CSE 489/589: Modern Networking Concepts

advertisement
CSE 489/589:
Modern Networking Concepts
TA - Ram Sheshadri
PA1 Deadline
• Due Time : 03/08/2015 @ 23:59:59 EDT
• Start early!
• No cheating! Don’t copy codes from your friends or
from senior students.
2
Outline
• Part1: Introduction to Socket Programming
–
–
–
–
Protocol Stack
TCP Overview
About Sockets
TCP Socket Overview
• Part2: Introduction to Programming Assignment 1
– Project Objective, Description, and Requirements
– PA1 Template, FAQs
– Tips and useful links
3
Part 1:
Introduction to Socket Programming
4
Protocol Stack

application layer: supporting network
applications
◦ HTTP, SMTP

transport layer: process-process data
transfer
◦ TCP, UDP

network layer: routing of datagrams
from source to destination
◦ IP, routing protocols

link layer: data transfer between
neighboring network elements
application
transport
network
link
physical
◦ Ethernet, MAC addresses

physical layer: bits “on the wire”
5
TCP Overview
• Establish connection
– 3-way handshake
• Data transmission
–
–
–
–
Reliable (retransmission with timer)
In-order delivery (reorder packets if necessary)
Support flow control (fast sender vs. slow receiver)
Full-duplex (data transferred both ways)
• Close connection
6
About Sockets
• Socket: a door between application process and
end-end-transport protocol (TCP or UDP)
IP Address + Port Number
7
TCP Socket Overview I
• TCP Connection Establishment
– Server gets ready (socket, bind, listen)
– Client gets ready (socket)
– Client requests connection (connect)
8
TCP Socket Overview II
9
TCP Socket Overview II
• Socket structure
– You need to fill all the values listed in the structure
10
TCP Socket Overview II
11
TCP Socket Overview II
12
TCP Socket Overview III
• TCP Connection Termination
–
–
–
–
A performs active close, sends FIN
B performs passive close & acknowledges
B closes its socket and sends FIN
A acknowledges the FIN
13
Part 2:
Introduction to Programming Assignment 1
14
Project Objective
• Develop a simple application for message exchange
(489) or file sharing (589) among remote hosts.
• Observe some network characteristics using it (589).
• Understand the packet-switching network behavior
and compare the results (589).
15
Project Description
Server
timberlake
embankment
underground
Clients
highgate
euston
16
Project Description
• Clients register with Server (489 and 589)
• Clients communicate with each other
– Message exchange (489)
– File sharing (589)
• Analyze the result and compare with iperf (589)
17
Project Description
• REGISTER <server IP> <port_no>
– The first task of every client is to register itself with the server by
sending the server a TCP message containing its listening port number.
The server should maintain a list of the IP address and the listening
ports of all the registered clients. Let’s call this list as “Server-IP-List”.
Whenever a new client registers or a registered client exits, the server
should update its Server-IP-List appropriately and then send this
updated list to all the registered clients. Client should always listen to
such updates from the server and update their own local copy of the
available peers.
– The REGISTER command takes 2 arguments. The first argument is the
IP address of the server and the second argument is the listening port
of the server.
18
Project Description
• Message exchange
– CONNECT <destination> <port no>
• This command establishes a new TCP connection to the
specified <destination> at the specified < port no>.
– Send <connection id> <msg>
• This will send the message to the host on the connection
that is designated by <connection id>. The message to be
sent can be up-to 100 characters long, including blank
spaces. On successfully executing the command, the sender
should display “Message sent to <connection id>” on the
screen. On receiving any message from the peer, the
receiver should display the received message along with the
sender information.
19
Project Requirements
• Make/Run on CSE Servers (dokken, underground, embankment, ….),
make sure it compiles/runs on these servers.
• Only one program is running on each server, but takes different
arguments:
• ./assignment1 s 4322
• ./assignment1 c 4322
• When launched, your process works like a “shell”
• C is recommended, C++ is acceptable, you cannot get any credits if
using JAVA or some other language.

If you’re using C++, you are not supposed to use any STLs (Standard Template
Library) for the socket programming part. If you have used any STLs for the
socket programming part, then your whole project will not be graded.
• Implement the commands according to the description.
• Multithreading is not allowed. The “select()” function should be
used to handle multiplexing between STDIN and incoming
connections.
20
Project submission
• What to submit?
– Your submission should contain a tar file [<ubit_name>.tar]:
• All source files including Makefile.
• The source containing the main() function should be named as
<ubit_name>_assignment1.c/<ubit_name>_assignment1.cpp
• Your analysis for sections 4.1, 4.2, 4.3 and 4.4 in a file named
Analysis_Assignment1.txt/pdf.
• Usage of graphs for your analysis is highly recommended.
• (CSE489 students don’t need to submit any analysis file)
• Please adhere to the naming convention for the tar file, don’t
make multiple submissions with different names, otherwise, there
is a 15% penalty.
21
Project submission
• How to submit?
– Use the submit scripts, available on CSE servers.
– For CSE 489
– For CSE 589
22
Comment your code
• At the start of the program - Author name and a small
description of what their whole program is (basically a
control flow).
• To describe the variables/data structures - why you
need it and how you are using it.
• At the start of each method/function, you should have
a line saying what the function does and what the
returning value is.
• References for code snippets (like beejs or online links).
23
•
•
•
•
•
•
•
•
•
Sample
// Class or file level comments //
/*
* proj1.cpp : Single file to handle the file sharing application
* Starts off as a server or a client on a given port
* Created for CSE 589 Spring 2014 Programming Assignment 1
* @author John Doe
* @created 29 January 2014
*/
•
•
•
•
•
•
//Method level comments //
/*
* Method to process the input line and split it into arguments.
* @arg line The user input line
* @return arguments parsed using whitespace delimiter added into a vector
* <MENTION ANY REFERENCES HERE: e.g. Copied from stackoverflow thread: http://stackoverflow....
*/
•
•
•
•
•
•
//code level comments //
...
} else {
// If valid: close socket, clear from list(s), clear from master fd list too
//conn id - 1 is the index into clnlist
//i dont know what to do if i close the server connection?
24
Tips
• Two types of file descriptors – STDIN (listening
command) and TCP socket.
• Put these two descriptors in the READSET for select()
as to be introduced in details in the next recitation.
25
Tips
• Get commands from STDIN
• Get the IP and hostname (the listening port can
be get from arguments)
– 127.0.0.1 is not accepted, so gethostbyname()
method is not recommended, it will looks into
/etc/hosts and return the ip address.
– Solution: create a UDP socket to any valid destination
– IP Address (like 8.8.8.8 or 8.8.4.4 provided by Google)
– Call connect() on this UDP socket.
26
Tips
• Functions and structures you need to be
familiar with
– struct sockaddr_in
– socket()
– bind(), listen(), accept()
– read(),write()
– select(), FD_SET(), FD_ISSET()
– htons(), htonl(), ntohs(), ntohl(), inet_ntoa(),
inet_aton(), inet_addr, inet_ntop(), inet_pton()
27
Tips
• I/O Multiplexing with select
28
Useful links
• Select() function
– http://www.mkssoftware.com/docs/man3/select.3.asp
• Beej’s guide to network programming
– http://beej.us/guide/bgnet/output/html/multipage/index.
html
– Chapter 5, 9 is important, Chapter 6 is the background,
Chapter 7 introduces select()
29
Download