Transcript Document

Communications

Most modern control involves interactions between many microprocessors Examples: PLC: Programming done on PC; uploaded to PLC Complex PLC control requires interaction between many PLC’s e.g. automation controls in an MTR station Microprocessor: Phone   Phone   Phone (e.g. to exchange phone numbers) PC (to upload address book) Networked video games with multiple players Computers: Internet, EDI

Communications

For devices to exchange data, several things must work together: Assume: Data  controlled change of voltage in a wire.

Bit-Streams

: Example: message = “Wow” W o w ASCII V 1010 111 1101 111 1110 111 mark 1 1 1 time 0 1 0 1 stop bits start bit 1 1 1 1 0 1 1 1 1 1 0 1 1 1 idle W: least significant bit  most significant bit

Communications

For devices to exchange data, several things must work together: W o w 1010 111 1101 111 1110 111 mark 1 1 1 0 1 0 1 stop bits start bit 1 1 1 1 0 1 1 1 1 1 0 1 1 1 idle - A wire must connect the devices - The voltage levels must match: sender sets “voltage of 5V”  ‘1’ => receiver must have a 5V sensor; (must interpret same way) - The duration for each bit (communication frequency, baud rate) - Start bit(s), stop bit(s) - Both must be using ASCII code …

Asynchronous vs Synchronous communications

Why do we need start/stop bits ?

Prepares the receiving device to start recording data  communication is ASYNCHRONOUS Idle Start bit seven asynchronous 7-bit character + parity bit LSB data bits Parity bit Stop bits Idle/next caracter Coordinated connection between the devices: SYNCHRONOUS communication - Receiver continually hunts for sync character (in ASCII: 1001 0110) - [Copies data into the data register; char available flag ON; data read] x CT - Check against CT; - end sync bit  hunt mode.

synchronous block of data SYNCSYNC D A T A ETX CT SYNC

Synchronization of communication

(a) Transmitter generates the synchronization reference Transmitter and Synchronization generator data synchro data (b) External synchronization clock unit Transmitter clock synchro data + synchro (c) Transmitter superposes clock and data Transmitter and Synchronization generator Receiver Receiver Receiver

Serial vs Parallel communication

Serial: one signal carrying wire Parallel: 8, 16, or 32 signal carrying wires  Parallel: faster, more expensive, used for short-distances only examples: Data bus, Control bus in a microprocessor; parallel port in PC

Bit coding

Binary Direct NRZ (non return to zero 1 0 1 0 0 0 1 1 NOT Good; constant HIGH voltage  delays [due to Capacitance/Inductance] RZ (return to zero) 0 V Signal during half-cycle then return to zero manchester coding differential manchester coding High-to-Low  Low-to-High  ‘1’ ‘0’ Very commonly used Voltage change at start of cycle No change at start of cycle   ‘1’ Voltage flips at mid-cycle ‘0’

Communication: Handling errors

Problem: some data sent from A  B may get ‘corrupted’ Why is this a big problem?

-

How will the receiver know they received ‘bad data’?

Probability of communication error is reduced by:

Error detection and Correction

Communications: Error detection and correction schemes

Importance of EDC (error detection and correction): Assume error rate of 0.1% Average sentence of text: 125 characters = 125 x 8 = 1000 bits 0.1% error  1 error per sentence! Techniques for EDC: 1. IF receiver detects error  requests sender to re-transmit 2. Receiver detects

and

corrects error without re-transmission

Error detection: Parity

Error detection: some information is added to message, that allows checking for errors.

PARITY 1 ASCII char = 7bits; 1 extra bit is added to each character, called parity bit: Even parity: value of parity bit is set to make total number of 1’s even.

Odd parity: value of parity bit is set to make total number of 1’s odd.

Example: ( ASCII ) W: 1010 111 ( odd parity ) W: 0 1010 111 ( even parity ) W: 1 1010 111

Error Detection: Checksums

Let: message = “ Hello, world ” == 12 bytes == 128 bits (including parity bit) Hello, world *assuming: parity bit = 0 72 101 108 108 111 44 32 119 111 114 108 100 Sum = 72 + 101 + 108 + … + 100 = 1128 Checksum [16-bits] = 1128 Checksum [8-bits] = 1128 mod 256 = 104 Message: 72 101 108 108 111 44 32 119 111 114 108 100 104 1 checksum/12 bytes   too much overhead typical use: 1 checksum byte per

128 Bytes

of data

Error Detection: Cyclic Redundancy Check (CRC)

Basic idea of CRC: Number: 629 Divisor: 25 mod( Number, Divisor): mod(629, 25) = 4 Pre-agreed between sender/receiver Transmit: (629,4) Receiver: mod( 629, 25) == 4 ?  Transmission probably OK

Error Detection: Cyclic Redundancy Check (CRC)

Implementation of CRC: Number: Bitstream of 1 Block (e.g. 128 Bytes) Divisor: common CRC schemes are: CRC12 1100000001011 CRC16 CRC-CCITT CRC32 11000000000000101 10001000000100001 100000100110000010001110110110111 M = mod( Number, Divisor): computed very efficiently with simple circuits FRAME: Number MOD Receiver: mod(Number MOD, CRC) = = M ?

Yes  Transmission probably OK

Error detection and Correction

Parity, Checksum, CRC: detect error, request re-transmit on error Redundant data transmission: detect error, and correct automatically!

Common methods: Repeating Hamming codes Reed-Muller codes, etc… Majority coding: Data: 010 Receive (with error): 001011000 Transmit: 000111000 0 1 0 select majority from each group of 3 Accepted data: 010

Hamming codes

Problem of Majority coding: (1) too much redundancy (2) burst errors can’t be handled Hamming code: main idea of a (7, 4) Hamming code Data: 0011 Add 1-bit to each circle, total of each circle  even

(7, 4) Hamming code

Data: 0011 transmit Error must be in bit shared by red and green red-circle : parity ERROR green circle : parity ERROR blue circle : parity OK  receiver

(7, 4) Hamming code…

Data: 0011 transmit Error must be in unshared bit of Blue circle!

red-circle : parity OK green circle : parity OK blue circle : parity ERROR  receiver HW: verify that ALL 1-bit errors can be detected and corrected!

Hamming code…

Data: bit-stream write data in particular sequence compute, add hamming code bits to data transmit receiver checks Hamming codes, corrects errors Corrected data Common Hamming code used: (12, 8) Hamming code

Extending Hamming code for longer bit-stream

1. All bit positions that are powers of two are used as parity bits.

(positions 1, 2, 4, 8, 16, 32, 64, etc.) 2. All other bit positions are for the data to be encoded.

(positions 3, 5, 6, 7, 9, 10, 11, 12, 13, 14, 15, 17, etc.) 3. Each parity bit stores the parity for assigned bits in the code word: The position of the parity bit determines the sequence of bits that it alternately checks and skips.

Position 1: skip 0 bits, check 1 bit, skip 1 bit, check 1 bit, skip 1 bit, … Position 2: skip 1 bit, check 2 bits, skip 2 bits, check 2 bits, skip 2 bits, … Position 4: skip 3 bits, check 4 bits, skip 4 bits, check 4 bits, skip 4 bits, … Position 8: skip 7 bits, check 8 bits, skip 8 bits, check 8 bits, skip 8 bits, … Position 16: skip 15 bits, check 16 bits, skip 16 bits, check 16 bits, skip 16 bits, … Position 32: skip 31 bits, check 32 bits, skip 32 bits, check 32 bits, skip 32 bits, …

Burst errors

Problem with Hamming: burst errors: several contiguous data bits in error) Handling burst errors: - Interleaving - Reed-Solomon coding Examples of usage: storage media (CDROM’s), …

Packets

Long message  p(error) is high  Need to re-transmit [part] of message Solution: Break message into small “packets”  send packets 1-by-1 To address From address Long message part 1 of 3 packets To address From address 1/3 To address From address 2/3 To address From address 3/3 data (part 1 of 3) data (part 2 of 3) data (part 3 of 3) EDC EDC EDC part 2 of 3 transmit part 3 of 3 Receiver Re-constructs Message from three parts received Typical packet size: 2048 - 4096 Bytes Note: later we’ll see structure of packet in more detail Question: Why do some web pages load in non-sequential fashion (some pictures load first, others later)

Network terminology

LAN

: Local Area Network A network of communicating devices in a small area (e.g. a building, a factory, etc.) Common ways of physically connecting computers in a LAN: Cables (wires), Bluetooth, Wi-Fi…

WAN

: Wide Area Network Two or more LAN’s connected to each other, over a large area, e.g. international communication networks.

Common ways of connecting between LAN’s in a WAN: Telephone networks, Long-distance cables, Satellites

Network topologies

Suppose N computers need to communicate with each other Pairwise connections: How many ?

Problems ?

Network topologies

Network topology describes how different devices are (physically) connected to each other.

6 1 5 4 (a) Ring topology 3 1 6 5 4 (c) Mesh topology 2 2 3 1 6 5 4 (b) Star topology 2 3 Central Hub 1 3

• • •

Stub Bus

••

4 2 5 Terminator 6 (d) Bus topology

Network communication basics

The following slides, based largely on the those provided by Kurose and Ross, will be used to get an introduction to real-world network communications.

Computer Networking: A Top Down Approach Featuring the Internet

, 3 rd edition. Jim Kurose, Keith Ross Addison-Wesley, July 2004.

What’s the Internet ?

• millions of connected computing devices:

hosts = end systems

running

network applications communication links

– fiber, copper, radio, satellite – transmission rate =

bandwidth

routers:

forward packets

router server local ISP workstation mobile regional ISP UST network

What’s the Internet..

• •

protocols

control sending, receiving of msgs – e.g., TCP, IP, HTTP, FTP, PPP

Internet:

“network of networks” – public: Internet – private: Intranet • Internet standards – RFC: Request for comments – IETF: Internet Engineering Task Force router server local ISP UST network workstation mobile regional ISP

What’s a protocol?

protocols define format, order of msgs sent and received among network entities, and actions taken on msg transmission, receipt

a human protocol and a computer network protocol:

Hi Hi

What’s the time?

2pm time

TCP connection req TCP connection response Get http://www.awl.com/kurose-ross

A closer look at network structure

• network edge: applications and hosts • network core: – routers – network of networks • access networks, physical media: communication links

The network edge

• end systems (hosts): – run application programs – e.g. Web, email – at “edge of network” • client/server model – client host requests, receives service from always-on server – e.g. Web browser/server; email client/server

Network edge: connection-oriented service

Goal:

data transfer between end systems

handshaking:

setup (prepare for) data transfer ahead of time – Hello, hello back human – protocol

set up “state”

in two communicating hosts e.g.

• • • TCP service [RFC 793]

reliable, in-order

transfer byte-stream data – loss: acknowledgements and retransmissions

flow control:

– sender won’t overwhelm receiver

congestion control:

– senders “slow down sending rate” when network congested

Network edge: connectionless service

Goal:

data transfer between end systems e.g.

UDP - User Datagram Protocol: connectionless unreliable data transfer no flow control no congestion control App’s using TCP: • HTTP (Web), FTP (file transfer), Telnet (remote login), SMTP (email) App’s using UDP: • streaming media, teleconferencing, DNS, Internet telephony

The Network Core

• • mesh of interconnected routers

the

fundamental question: how is data transferred through net?

– circuit switching: dedicated circuit per call: telephone net – packet-switching: data sent through net in discrete “chunks”

Network Core: Circuit Switching

End-end resources reserved for “call” • link bandwidth, switch capacity • dedicated resources: no sharing • circuit-like (guaranteed) performance • call setup required

Network Core: Packet Switching

Each end-end data stream divided into

packets

• user A, B packets

share

network resources • each packet uses full link bandwidth • resources used

as needed

Resource allocation: • total resource demand can exceed amount available • congestion: packets queue, wait for link use • store and forward: packets move one hop at a time – Node receives complete packet before forwarding Bandwidth division into “pieces” Dedicated allocation Resource reservation

Packet-switching: store-and-forward

L R R R • Packet Length: L bits • Baud rate: R bps • Time to push packet on link: L/R sec • Entire packet must arrive at router before it can be transmitted on next link:

store and forward

• delay = 3L/R

Example: • L = 7.5 Mbits • R = 1.5 Mbps • delay = 15 sec

Access networks and physical media

Q: How to connect end systems to edge router?

• residential access nets • institutional access networks (school, company) • mobile access networks

Residential access: point to point access

• Phone modem – up to 56Kbps direct access to router (often less) – Can’t surf and phone at same time: can’t be “always on” • ADSL: asymmetric digital subscriber line [ similar to NOW Broadband ] – up to 1 Mbps upstream – up to 8 Mbps downstream

Residential access… Cable modems

cable headend cable distribution network (simplified) home

Residential access: cable modems

Diagram: http://www.cabledatacomnews.com/cmic/diagram.html

Company access: local area networks

• company/univ local area network (LAN) connects end system to edge router • Ethernet: – shared or dedicated link connects end system and router – 10 Mbs, 100Mbps, Gigabit Ethernet

Wireless access networks

router base station

• • shared

wireless

access network connects end system to router – via base station aka “access point” wireless LANs: – 802.11b (WiFi): 11 Mbps (good for networks) – bluetooth: 720Kbps (good for device-to-device)

mobile hosts

Home networks

Typical home network components: • ADSL or cable modem • router/firewall/NAT • Ethernet • wireless access point to/from cable headend cable modem router/ firewall Ethernet wireless access point wireless laptops

Internet structure: network of networks

• a packet passes through many networks!

local ISP Tier 3 ISP Tier-2 ISP local ISP

Tier 1 ISP

local ISP Tier-2 ISP local ISP Network Access Point

Tier 1 ISP

local ISP Tier-2 ISP local ISP

Tier 1 ISP

Tier-2 ISP local ISP Tier-2 ISP local ISP

Protocol “Layers”

Networks are complex! • many “pieces”: – hosts – routers – links of various media – applications – protocols – hardware, software

Analogy: Organization of air travel

ticket (purchase) ticket (complain) baggage (check) baggage (claim) gates (load) gates (unload) runway takeoff runway landing airplane routing airplane routing airplane routing

Layering of airline functionality

ticket (purchase) baggage (check) gates (load) runway (takeoff) airplane routing departure airport airplane routing airplane routing intermediate air-traffic control centers ticket (complain) baggage (claim gates (unload) runway (land) airplane routing arrival airport ticket baggage gate takeoff/landing airplane routing Layers: each layer implements a service – via its own internal-layer actions – relying on services provided by layer below

Why layering?

Dealing with complex systems: • explicit structure allows identification, relationship of complex system’s pieces – layered reference model for discussion • modularization eases maintenance, updating of system – change of implementation of layer’s service transparent to rest of system – e.g., change in gate procedure doesn’t affect rest of system • layering considered harmful?

Internet protocol stack

• application: supporting network applications – FTP, SMTP, STTP • transport: host-host data transfer – TCP, UDP • network: routing of datagrams from source to destination – IP, routing protocols • link: data transfer between neighboring network elements – PPP, Ethernet • physical: bits “on the wire”

application transport network link physical

message segment datagram frame H l H n H n H t H t H t M M M M

source

application transport network link physical

Encapsulation

H l H n H t M link physical H l H n H t M

switch

H l H n H n H t H t H t M M M M destination application transport network link physical H l H n H n H t H t M M network link physical H l H n H n H t H t M M

router

The Network Layer: Internet Protocol

• What’s inside a router • Internet Protocol and IP addresses • How packets are routed

Internet Protocol (IP)

The Internet Protocol (IP) is a network-layer (Layer 3) protocol that contains addressing information and some control information that enables packets to be routed.

Network layer functions: Forwarding and Routing

routing algorithm local forwarding table header value output link 0100 0101 0111 1001 3 2 2 1

Forwarding

: determines which link to take at a specific router;

Routing

: plan of a series of forwarding data that can take the packet from source to destination value in arriving packet’s header 0111 3 2 1 DATAGRAM

IP datagram format

IP protocol version number header length (bytes) “type” of data max number remaining hops (decremented at each router) upper layer protocol to deliver payload to how much overhead with TCP?

• 20 bytes of TCP • 20 bytes of IP • = 40 bytes + app layer overhead 32 bits ver head.

len 16-bit identifier time to live type of service upper layer length flgs fragment Internet checksum 32 bit source IP address 32 bit destination IP address Options (if any) data (variable length, typically a TCP or UDP segment) total datagram length (bytes) for fragmentation/ reassembly E.g. timestamp, record route taken, specify list of routers to visit.

Datagram networks

• packets forwarded using destination host address – packets between same source-dest pair may take different paths application transport network data link physical 1. Send data 2. Receive data application transport network data link physical •

Main router functions:

• run routing algorithms/protocol (RIP, OSPF, BGP)

forwarding

datagrams from incoming to outgoing link

IP Addressing: introduction

• • IP address: 32-bit identifier for host, router

interface interface:

connection between host/router and physical link – router’s typically have multiple interfaces – host may have multiple interfaces – IP addresses associated with each interface 223.1.1.1

223.1.2.1

223.1.1.2

223.1.1.4

223.1.2.9

223.1.1.3

223.1.3.27

223.1.2.2

223.1.3.1

223.1.3.2

223.1.1.1 = 11011111 00000001 00000001 00000001 223 1 1 1

Subnets

• • IP address: – subnet part (high order bits) – host part (low order bits)

What’s a subnet ?

– device interfaces with same subnet part of IP address – can physically reach each other without intervening router 223.1.1.1

223.1.2.1

223.1.1.2

223.1.1.4

223.1.2.9

223.1.1.3

223.1.3.1

223.1.3.27

223.1.2.2

LAN 223.1.3.2

network consisting of 3 subnets

Subnets

• To determine the subnets, detach each interface from its host or router, creating islands of isolated networks. Each isolated network is called a subnet .

223.1.1.0/24 223.1.2.0/24 223.1.3.0/24

Subnet mask: /24

Subnets

How many?

223.1.1.2

223.1.1.1

223.1.1.4

223.1.9.2

223.1.1.3

223.1.7.0

223.1.2.1

223.1.9.1

223.1.8.1

223.1.2.6

223.1.8.0

223.1.7.1

223.1.2.2

223.1.3.1

223.1.3.27

223.1.3.2

IP addresses: how to get one?

Q: How does

host

get IP address?

• hard-coded by system administrator in a file – Wintel: control-panel->network->configuration->tcp/ip->properties • DHCP: D ynamic H ost C onfiguration P rotocol: dynamically get address from as server – “plug-and-play”

DNS: Domain Name System

People: many identifiers: – HKID, name, passport # Internet hosts, routers: – IP address (32 bit) - used for addressing datagrams – “name”, e.g., ww.yahoo.com - used by humans Q: map between IP addresses and name ?

• • Domain Name System:

distributed database

implemented in hierarchy of many

name servers application-layer protocol

host, routers, name servers to communicate to

resolve

names (address/name translation)

Transport services and protocols

• provide

logical communication

between app processes running on different hosts • Most common transport protocol:

TCP

application transport network data link physical The TCP provides a reliable, continuous stream of data - protocol for automatically requesting missing data - reordering IP packets that arrive out of order - converting IP datagrams to a streaming protocol - routing data within a computer to the correct application. network data link physical network data link physical network data link physical network data link physical network data link physical application transport network data link physical

The Application layer

• Principles of network applications • Web and HTTP • FTP • Electronic Mail – SMTP, POP3, IMAP • DNS • Socket programming with TCP • Building a Web server

Creating a network app

Write programs that – run on different end systems and – communicate over a network.

– e.g., Web: Web server software communicates with browser software No software written for devices in network core – Network core devices do not function at app layer – This design allows for rapid app development application transport network data link physical application transport network data link physical application transport network data link physical

Client-server architecture

server: – always-on host – permanent IP address clients: – communicate with server – may be intermittently connected – may have dynamic IP addresses – do not communicate directly with each other

Sockets

• process sends/receives messages to/from its socket • socket analogous to door – sending process shoves message out door – sending process relies on transport infrastructure on other side of door which brings message to socket at receiving process host or server process socket TCP with buffers, variables controlled by app developer Internet controlled by OS host or server process socket TCP with buffers, variables

Addressing processes

• For a process to receive messages, it must have an identifier • A host has a unique32-bit IP address • Q: does the IP address of the host on which the process runs suffice for identifying the process?

• Answer: No, many processes can be running on same host • Identifier includes both the IP address and port numbers associated with the process on the host.

• Example port numbers: – HTTP server: 80 – Mail server: 25

Socket programming

Goal: learn how to build client/server application that communicate using sockets Socket API • introduced in BSD4.1 UNIX, 1981 • explicitly created, used, released by apps • client/server paradigm • two types of transport service via socket API: – unreliable datagram – reliable, byte stream-oriented

socket

a

host-local

,

application-created

,

OS-controlled

interface (a “door”) into which application process can both send and receive messages to/from another application process

Socket-programming using TCP

Socket: a door between application process and end-end-transport protocol (UCP or TCP) TCP service: reliable transfer of

bytes

from one process to another controlled by application developer controlled by operating system process socket TCP with buffers, variables host or server internet process socket TCP with buffers, variables host or server controlled by application developer controlled by operating system

Socket programming

with TCP

Client must contact server • server process must first be running • server must have created socket (door) that welcomes client’s contact Client contacts server by: • creating client-local TCP socket • specifying IP address, port number of server process • When client creates socket : client TCP establishes connection to server TCP • When contacted by client, server TCP creates new socket for server process to communicate with client – allows server to talk with multiple clients – source port numbers used to distinguish clients application viewpoint

TCP provides reliable, in-order transfer of bytes (“pipe”) between client and server

Stream terminology

• A stream is a sequence of characters that flow into or out of a process.

• An input stream is attached to some input source for the process, eg, keyboard or socket.

• An output stream is attached to an output source, eg, monitor or socket.

Socket programming with TCP

keyboard monitor Example client-server app: 1) client reads line from standard input (

inFromUser

stream) , sends to server via socket (

outToServer

stream) 2) server reads line from socket 3) server converts line to uppercase, sends back to client 4) client reads, prints modified line from socket (

inFromServer

stream) Client Process input stream output stream input stream client TCP clientSocket socket TCP socket to network from network

Client/server socket interaction: TCP

Server

(running on

hostid

) create socket, port=

x

, for incoming request: welcomeSocket = ServerSocket() wait for incoming connection request connectionSocket = welcomeSocket.accept() TCP connection setup

Client

create socket, connect to

hostid

, port=

x

clientSocket = Socket() send request using clientSocket read request from connectionSocket write reply to connectionSocket close connectionSocket read reply from clientSocket close clientSocket

Example: Java client (TCP)

Create input stream Create client socket, connect to server Create output stream attached to socket import java.io.*; import java.net.*; class TCPClient { public static void main(String argv[]) throws Exception { String sentence; String modifiedSentence; BufferedReader inFromUser = new BufferedReader(new InputStreamReader(System.in)); Socket clientSocket = new Socket("hostname", 6789); DataOutputStream outToServer = new DataOutputStream(clientSocket.getOutputStream());

Example: Java client (TCP), cont.

Create input stream attached to socket Send line to server Read line from server } } BufferedReader inFromServer = new BufferedReader(new InputStreamReader(clientSocket.getInputStream())); sentence = inFromUser.readLine(); outToServer.writeBytes(sentence + '\n'); modifiedSentence = inFromServer.readLine(); System.out.println

("FROM SERVER: " + modifiedSentence ); clientSocket.close();

Example: Java server (TCP)

Create welcoming socket at port 6789 Wait, on welcoming socket for contact by client Create input stream, attached to socket import java.io.*; import java.net.*; class TCPServer { public static void main(String argv[]) throws Exception { String clientSentence; String capitalizedSentence; ServerSocket welcomeSocket = new ServerSocket(6789); while(true) { Socket connectionSocket = welcomeSocket.accept(); BufferedReader inFromClient = new BufferedReader(new InputStreamReader(connectionSocket.getInputStream()));

Example: Java server (TCP), cont

Create output stream, attached to socket Read in line from socket DataOutputStream outToClient = new DataOutputStream (connectionSocket.getOutputStream()); clientSentence = inFromClient.readLine(); capitalizedSentence = clientSentence.toUpperCase() + '\n'; Write out line to socket } } } outToClient.writeBytes(capitalizedSentence); End of while loop, loop back and wait for another client connection