csci4220-week09x - Rensselaer Polytechnic Institute

doctorheavenlyNetworking and Communications

Oct 24, 2013 (3 years and 5 months ago)

59 views

Rensselaer Polytechnic Institute

CSCI
-
4220


Network Programming

David Goldschmidt, Ph.D.


In reality, not

all layers are

always used....


The Internet
uses only
four layers:


Application


Transport


Network


Physical


Ethernet encompasses both

the data link layer and the

physical layer


Ethernet (really
IEEE 802.3
)


Ethernet provides a shared

medium (multi
-
access)

Ethernet


Every Ethernet interface is assigned a
unique 48
-
bit (hardware) address


Represented as a sequence of 6 hexadecimal
bytes delimited by
':'

characters:


00:50:56:9F:27:3E



(use
/
sbin
/
ifconfig

to see network interfaces)


Also known as
MAC address

or
physical address



Ethernet addresses are assigned to

vendors by a central authority


Messages are sent over Ethernet via
frames
:






The
Preamble

is a sequence of

alternating
1
s and
0
s for synchronization


In hex:
AAAAAAAAAAAAAAAB



Transmitters are required to send

an
Interframe

Gap

of at least 12 octets

Preamble

Destination
Address

Source
Address

Len

Data

CRC

8 bytes

6 bytes

6 bytes

2



1500 bytes

4 bytes


How does an Ethernet interface know when
it can transmit a frame?


CSMA/CD



Carrier Sense (CS)
: a transmitter can tell when
another host is transmitting data


Multiple Access (MA)
: many transmitters


Collision Detection (CD)
: a transmitter can tell
when another host is transmitting data that
collides with its own transmission


How does an Ethernet interface know when
it should receive a frame?


Receivers look at all frames, discarding frames
not addressed to them


Receivers only receive frames addressed to them
(or broadcast messages)


Each layer prepends or appends its
information in a header or trailer

P

Ethernet Hdr
|

IP Hdr
|

TCP Hdr
|

HTTP Request
|

Cksum


IP Hdr
|

TCP Hdr
|

HTTP Request


TCP Hdr
|

HTTP Request


HTTP Request


Each layer on the client side
logically
communicates

with the same layer on

the server side

intermediate router

P

Q

client

server


IP is the network layer


IP provides host
-
to
-
host delivery service

of packets (called
datagrams
)


IP is connectionless


IP is unreliable


IP also provides translation between

different data link protocols


IP addresses are logical addresses at

the network layer


IP addresses are
not

Ethernet addresses



Why is this important?


IP must be able to provide communication
between hosts on different types of networks
(i.e. different data link implementations)


An IP address contains information about
what
network

the destination host is on


This enables
routing

at the network layer


An IP address (IPv4) is a series of 4 octets


128.113.2.68 (
www.rpi.edu
)


128.113.126.13 (
www.cs.rpi.edu
)


128.213.56.14 (
mary
-
kate.cs.rpi.edu
)


Each IP address contains information that
identifies the network ID and the host ID


Routing tables

rely on IP address
classes
:

from, you guessed it, Wikipedia!

8 bits



A


B

CLASS

C


D

NetID

0

HostID

NetID

10

HostID

NetID

110

HostID

Multicast Address

1110

8 bits

8 bits

8 bits

Decoding IP Addresses:

8 bits





B





NetID

10

HostID

8 bits

8 bits

8 bits


An organization can further subdivide its
host (
HostID
) space into
subnets
:

NetID

10

HostID

SubnetID

router

Subnet Q

128.213.1.x

Subnet R

128.213.2.x

Subnet S

128.213.3.x


Other
subnetting

notes:


Subnets can simplify routing


IP subnet broadcasts have a
HostID

of all
1
s


It is possible to have

a single wire network

with multiple subnets:


How would this work?


IP addresses are logical addresses; therefore
we need to map them to physical addresses


If we know the IP address of a host,

how do we find out the hardware address?


Address resolution

is the process of

finding the hardware address of a

host from a given IP address


ARP is used by a host when it needs to
determine a physical (Ethernet) address
from a given IP address


ARP is what’s known as a broadcast protocol


Every host on the network

receives the ARP request


Only the “right” one responds

That’s
me!


Address resolution does not need to be
performed every time an IP datagram is sent


Hosts cache IP
-
to
-
hardware

address mappings


This happens on both ends


i.e. the receiver also caches

the IP
-
to
-
hardware address

mapping of the transmitter

I know!

I remember you.

Me too!

Hey everyone!

Will IP 128.213.56.14 send
me your Ethernet address?

Not me.

Not me.

Not me.

Sure, that’s me!

My Ethernet address is
3F:55:83:02:AB:79
.


IP provides the following:


Connectionless delivery


i.e. each datagram is individually routed


Unreliable (non
-
guaranteed) delivery


Fragmentation and reassembly


Only at the source and destination hosts


If fragments are lost, the entire datagram is discarded


Routing


Error detection (via ICMP)

8 bits

HL

VERS

Fragment Length

Datagram ID

FLAG

Fragment Offset

Protocol

TTL

Header Checksum

Source Address

8 bits

8 bits

8 bits

Service

Destination Address

Options (if any)

Data

http://tools.ietf.org/html/rfc1122


Internet Control Message Protocol (ICMP)
:


ICMP is used to transmit control

(or out
-
of
-
band) messages


ICMP uses IP for delivery


ICMP messages are usually

generated and processed

by the IP software (not user processes)

http://tools.ietf.org/html/rfc792


ICMP message types include:


Echo Request (ping)


Echo Response (ping)


Destination Unreachable


Redirect


Time Exceeded


etc.


Two protocols at the Transport Layer:


Transmission Control Protocol (TCP)


Connection
-
oriented


Reliable byte
-
streaming


Full
-
duplex


3
-
way handshake (SYN/ACK/ACK)

to establish a connection


User Datagram Protocol (UDP)


Connectionless and unreliable

click me

8 bits

Source Port

Destination Port

Length

Checksum

8 bits

8 bits

8 bits

Data

http://www.ietf.org/rfc/rfc768.txt

8 bits

Destination Port

Sequence Number

Acknowledgment Number

Data
Offset

8 bits

8 bits

8 bits

Source Port

Checksum

Options (if any)

Data

http://www.ietf.org/rfc/rfc793.txt

Reserved

Control

Window

Urgent Pointer


Which is better? TCP or UDP?


Serving up Web pages


Financial transaction processing


Video
-
streaming server


File transfer


Email


Chat


Robotic surgery

controlled remotely

Get out of my
way, humans!