avishai wool lecture 10 - 1 introduction to systems programming lecture 10 networks

45
Avishai Wool lecture 10 - 1 Introduction to Systems Programming Lecture 10 Networks

Post on 21-Dec-2015

214 views

Category:

Documents


1 download

TRANSCRIPT

Avishai Woollecture 10 - 1

Introduction to Systems Programming Lecture 10

Networks

Avishai Woollecture 10 - 2

Protocols & Layering

Avishai Woollecture 10 - 3

First Principles

• Goal: transfer information, as a string of bits, across space

• Requires interpretation conventions

• Such a convention is called a protocol.

Avishai Woollecture 10 - 4

A telephone call:

• Each layer obeys strict interface rules

• Each layer “talks” to its counterpart only

The Layering Approach

idea

wording

sound

signals wire

idea

wording

sound

signals

Avishai Woollecture 10 - 5

The ISO/OSI Model • International Standards Organization: ISO

– (A bunch of people).

• Open Standards Interconnect: OSI – (A bunch of documents).

• A convention of organizing network protocols into layers

• Gives terminology and central roles to various layers

Avishai Woollecture 10 - 6

ISO/OSI Layers

MACHINE #1 MACHINE #2

DATA

|DATA

||DATA

|||DATA

||||DATA

|||||DATA

||||||DATA

Application

PresentationSession

Transport

Network

Data Link

Physical

DATA

|DATA

||DATA

|||DATA

||||DATA

|||||DATA

||||||DATA

Application

PresentationSession

Transport

Network

Data Link

Physical

Avishai Woollecture 10 - 7

Layer 1: Physical

• Unit of exchange: Bits

• Convert bits to signals, and signals to bits.

• Physical interfaces

• Power

• Frequency, amplitude, phase

• Coding

• Modulation and demodulation

Avishai Woollecture 10 - 8

Layer 2: Data Link

• Also called: MAC: Medium Access Control

• Unit of exchange: Frame– Usually over common (broadcast) media– Handles multiple access to shared PHY layer – Controls a Local-Area Network (LAN)

– Bit ordering– Error-correction codes (ECC)– May be unreliable due to noise

Avishai Woollecture 10 - 9

Layer 3: Network

• Unit of exchange: Packet / Datagram

• Controlling the operation of multiple networks

• Addressing

• Routing: how to get a packet to its destination

• Unreliable– Packets can arrive out of order or be dropped

Avishai Woollecture 10 - 10

Layer 4: Transport

• Transport: create a reliable message channel from an unreliable packet channel.

• Acknowledgements (ACKs) and retransmissions

• Sequencing and re-ordering

• Congestion

• Source and Destination port numbers

• Handshake

Avishai Woollecture 10 - 11

Layers 5-7

• Higher level protocols

• Less defined roles

• Not clear where “Application” ends and “Presentation” begins

• Session examples: SQL (database), NFS (files)

• Presentation examples: MPEG, MIDI

Avishai Woollecture 10 - 12

TCP/IP Layers

Each sending layer adds a “wrapper” to message, corresponding receiving layer “peels” it

1. physical

2. data-link

3. network

4. transport

5-7. application message

messageTCP header

messageTCP headerIP header

messageTCP headerIP headerethernet header

Avishai Woollecture 10 - 13

Layer 2

Layer 4

Layer 3

Avishai Woollecture 10 - 14

Local Area Networks

Layer 2

Avishai Woollecture 10 - 15

LAN Basics

• Bus/ring: twisted pair, coax, fiber, wireless (radio)

• Broadcast medium (Multiple Access): – Everyone hears everyone else– No routing, no switching, no buffering, no servers– One sender at a time

• Requires conflict resolution protocol

Avishai Woollecture 10 - 16

Ethernet

Avishai Woollecture 10 - 17

Ethernet: IEEE 802.3• Metcalfe & Boggs (1973) Xerox Digital 3Com• Speed: 10 Mbps / 100Mbps / 1000Mbps• Cabling: coax, twisted-pair• Secret of success: ingenious conflict resolution protocol

“thin ethernet” – coax – BNC Ethernet – twisted-pair – RJ45

Ethernet

Classic Ethernet Switched Ethernet

Computer

(a) (b)

Avishai Woollecture 10 - 19

802.3 Protocol Basics• Addresses: unique 48 bits, up to 1024 on a net

(MAC Address)

• Each vendor has a unique prefix and his own numbering system

• Devices have MAC address “burned” into them (not really…)

• Frame size 64-1518 bytes, containing:– destination (maybe everybody!), source, data,

checksum

Avishai Woollecture 10 - 20

Basic Idea• Bus architecture:

• TX of each connected to RX of all others (broadcast)

• Problem: simultaneous transmissions (collisions) overwrite and destroy each other

Avishai Woollecture 10 - 21

Ethernet sensing

• When a station wants to transmit:

1. Listen (sense) the wire. • If busy: wait

2. Start transmitting – and listen to own transmission on wire.

3. If (my sensed bits != my transmitted bits) another station must be transmitting too collision – start conflict resolution.

Avishai Woollecture 10 - 22

Ethernet Conflict ResolutionSuppose 2 or more stations • collide (transmit at same time) and • sense (know) they collided.

What to do to avoid livelock? • Goal: One station should get priority and transmit. • Solution: CSMA/CD

– Carrier Sense

– Multiple Access

– Collision Detection

Avishai Woollecture 10 - 23

Backoff

First idea: use randomization!• Each colliding station i picks its own random

delay di

• Waits di time units, and tries to transmit again

• How to pick the range of random values?• Too small stations will get same value and

collide again• Too large slows down the communication

Avishai Woollecture 10 - 24

Exponential backoff• If they know how many stations are colliding (n),

each could pick di randomly from, e.g., [1,...2n]. – If range is [1,...2n] then it is very likely that the

minimal di is chosen by only one station

• Second idea: guess number of colliding stations!• Start with guess n=2; if unsuccessful, double n.• This is exponential:

– range of random numbers is 2, 4, 8, 16, 32, …

Avishai Woollecture 10 - 25

802.3 CSMA/CD Algorithm

ready to send

transmitand sense

sense channel

wait MAX_DELAY *random[0, 2attempts]

done

new attempt

busy

free

no collision

collision detected

Exponential Backoff

Collision Detection

Carrier Sense

Avishai Woollecture 10 - 26

Main properties• If diameter = 1 km, max_delay < 5S.• Collisions possible in first 2 •max_delay time• Minimum packet lengths – ensure that collision

will be sensed• Extremely flexible!• Throughput degrades under heavy load

– optimal: 1/e 37%

• Non-deterministic service: real time connections?• No fixed priorities

Avishai Woollecture 10 - 27

Wireless LAN (WiFi)

Avishai Woollecture 10 - 28

Wireless LAN: IEEE 802.11• Uses wireless communication• Base station / PCMCIA cards for laptops

• Operates in unregulated 2.4GHz range• Has to deal with interference from microwave

ovens, new cordless phones, etc.• 802.11b: up to 11Mbps. 802.11g: 54Mbs• Range of 10-100 meters• Frequency-hopping (Spread-Spectrum)

Avishai Woollecture 10 - 29

Vendor solutions

Avishai Woollecture 10 - 30

Hobbyists build antennas from:

Avishai Woollecture 10 - 31

And:

Avishai Woollecture 10 - 32

Properties of IEEE 802.11• Home-brew antennas have excellent range: over

350m.• http://www.turnpoint.net/wireless/has.html

• Uses encryption: Wire-Equivalent Privacy (WEP)• But: Major security problems

– Encryption broken– Authentication broken– Data integrity broken– By default WEP is turned OFF…

Avishai Woollecture 10 - 33

Connecting networks to each other

Avishai Woollecture 10 - 34

Repeaters

Goal: enhance physical layer

physical

data-link

network

physical

data-link

network

physical physical

a2d-d2a

Avishai Woollecture 10 - 35

Bridges/Switches/Hubs

physical

data-link

network

physical

data-link

network

physical physical

filter

data-link data-link

• Goal: connect at the data-link layer• Can connect different physical layers (WiFi +

Ethernet)• Multiple ports• Filter packets: listen and learn location of sources

Avishai Woollecture 10 - 36

Internet Protocol (IP)

Layer 3

Avishai Woollecture 10 - 37

Properties of IP• Point-to-point, datagram service• Connect multiple LANs to each other• Addressing: 32-bit IP-addresses.

– Must be unique in entire network (whole Internet!)

• Get the packets to their destination (routing).• Connectionless

– each packet carries its source & destination IP addresses

– each packet routed independently through network

• Unreliable– packets can arrive out of order or be dropped entirely

Avishai Woollecture 10 - 38

IP addresses

• 32-bit IP address usually written in “dotted-decimal” notation, each number in 0-255– 132.66.32.10

• IP addresses are a valuable resource. Allocated by IANA (Internet Assigned Number Authority)– http://www.iana.org/

• Allocated hierarchically through delegation– ARIN : North America– RIPE : Europe, Middle east

Avishai Woollecture 10 - 39

Routers: IP traffic junctions• Goal: forward IP packets towards destination• Means: “sit” on more than one network (a few ports);

maintain a routing table; forward according to table

network A

network B

network C

router

Cdefault

B18.4.*

A10.0.4.3

A192.168.2.4destination next hop

Avishai Woollecture 10 - 40

Routers – more detail

• Routers connect two or more LANs:Multiple network interface cards (NIC)Each NIC has its own MAC addressEach NIC has its own IP address!

IP address mapped to NIC, not to computer

Avishai Woollecture 10 - 41

Routing to directly connected hosts

• Router decides what to do with packet based on its destination IP address

• Directly connected == destination on same LAN as one of the router’s NICs– Find out the destination MAC address– Encapsulate packet in Ethernet frame, – Send to destination via layer 2

Routers do NOT modify the destination IP address!

Avishai Woollecture 10 - 42

Routing to remote addresses

• If destination IP address not directly connected:

• Router checks routing table

• Finds IP address of next-hop router– Next-hop router has to be directly connected!

• Finds MAC address of next hop router

• Encapsulate packet & send as before

Avishai Woollecture 10 - 43

How to find a MAC address ?

• “ARP”: Address Resolution Protocol

• Layer “2.5”: above Ethernet but below IP

– Broadcast to Ethernet “who is IP a.b.c.d?”– Owner of that IP responds (or timeout)– Each station keeps a table of recent mappings

• Windows/Unix: type “arp –a” to see table

Avishai Woollecture 10 - 44

Every computer is a “router”

• Every machine running IP is a “router”– Only one NIC– Only one IP address– Usually only one next-hop router (default gateway)

for non-local traffic

• To see contents of routing table:– Windows (command prompt): “route print”– Unix: netstat –rn

Avishai Woollecture 10 - 45

Concepts for review• ISO 7-layer model• Physical layer• DataLink layer• Network layer• Transport layer• Ethernet• MAC Address• Exponential backoff• Wireless LAN (802.11)• Bridge / Hub / Switch

• Internet Protocol (IP)• IP Address• Router• Routing table• Next-hop router