77
Communications t modern control involves interactions between many microproc xamples: LC: Programming done on PC; uploaded to PLC Complex PLC control requires interaction between many PL e.g. automation controls in an MTR station icroprocessor: Phone Phone (e.g. to exchange phone numbers) Phone PC (to upload address book) Networked video games with multiple players omputers: Internet, EDI

Communications Most modern control involves interactions between many microprocessors Examples: PLC: Programming done on PC; uploaded to PLC Complex PLC

  • View
    229

  • Download
    1

Embed Size (px)

Citation preview

Page 1: Communications Most modern control involves interactions between many microprocessors Examples: PLC: Programming done on PC; uploaded to PLC Complex PLC

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’se.g. automation controls in an MTR station

Microprocessor:Phone Phone (e.g. to exchange phone numbers)Phone PC (to upload address book)Networked video games with multiple players

Computers:Internet, EDI

Page 2: Communications Most modern control involves interactions between many microprocessors Examples: PLC: Programming done on PC; uploaded to PLC Complex PLC

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

1010 111 1101 111 1110 111

mark 1

0

1

0

11 1 stop bits

start bit

1 1

0

11 1 1 1 1 1

0

1 1 1 idle

ASCII

V

time

W: least significant bit most significant bit

Page 3: Communications Most modern control involves interactions between many microprocessors Examples: PLC: Programming done on PC; uploaded to PLC Complex PLC

Communications

W o w

1010 111 1101 111 1110 111

mark 1

0

1

0

11 1 stop bits

start bit

1 1

0

11 1 1 1 1 1

0

1 1 1 idle

For devices to exchange data, several things must work together:

- 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…

Page 4: Communications Most modern control involves interactions between many microprocessors Examples: PLC: Programming done on PC; uploaded to PLC Complex PLC

Asynchronous vs Synchronous communications

Why do we need start/stop bits ?

Prepares the receiving device to start recording data

communication is ASYNCHRONOUS

IdleStart bit

LSB

seven data bitsParity

bit Stop bits

Idle/next caracter

asynchronous 7-bit character + parity bit

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.

SYNCSYNC D A T A ETX CT SYNCsynchronous block of data

Page 5: Communications Most modern control involves interactions between many microprocessors Examples: PLC: Programming done on PC; uploaded to PLC Complex PLC

Synchronization of communication

Receiver

Transmitter and

Synchronization generator

data

synchro

(a) Transmitter generates the synchronization reference

ReceiverTransmitter

data

synchro

clock

(b) External synchronization clock unit

Receiver

Transmitter

and

Synchronization

generator

data + synchro

(c) Transmitter superposes clock and data

Page 6: Communications Most modern control involves interactions between many microprocessors Examples: PLC: Programming done on PC; uploaded to PLC Complex PLC

Serial vs Parallel communication

Serial: one signal carrying wireParallel: 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

Page 7: Communications Most modern control involves interactions between many microprocessors Examples: PLC: Programming done on PC; uploaded to PLC Complex PLC

Bit coding

Binary Direct NRZ (non-

return to zero

RZ (return to zero)

manchester coding

differential manchester

coding

1 0 1 0 0 0 1 1

0 V

NOT Good;constant HIGH voltage delays [due to Capacitance/Inductance]

Very commonly used

Signal during half-cyclethen return to zero

High-to-Low ‘1’Low-to-High ‘0’

Voltage change at start of cycle ‘0’No change at start of cycle ‘1’Voltage flips at mid-cycle

Page 8: Communications Most modern control involves interactions between many microprocessors Examples: PLC: Programming done on PC; uploaded to PLC Complex PLC

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

Page 9: Communications Most modern control involves interactions between many microprocessors Examples: PLC: Programming done on PC; uploaded to PLC Complex PLC

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 bits0.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

Page 10: Communications Most modern control involves interactions between many microprocessors Examples: PLC: Programming done on PC; uploaded to PLC Complex PLC

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

Page 11: Communications Most modern control involves interactions between many microprocessors Examples: PLC: Programming done on PC; uploaded to PLC Complex PLC

Error Detection: Checksums

Let: message = “Hello, world” == 12 bytes == 128 bits (including parity bit)

Hello, world

72 101 108 108 111 44 32 119 111 114 108 100

*assuming: parity bit = 0

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

Page 12: Communications Most modern control involves interactions between many microprocessors Examples: PLC: Programming done on PC; uploaded to PLC Complex PLC

Error Detection: Cyclic Redundancy Check (CRC)

Basic idea of CRC:

Number: 629 Divisor: 25

mod( Number, Divisor): mod(629, 25) = 4

Transmit: (629,4)

Receiver: mod( 629, 25) == 4 ? Transmission probably OK

Pre-agreed between sender/receiver

Page 13: Communications Most modern control involves interactions between many microprocessors Examples: PLC: Programming done on PC; uploaded to PLC Complex PLC

Error Detection: Cyclic Redundancy Check (CRC)

Implementation of CRC:

Number: Bitstream of 1 Block (e.g. 128 Bytes)

Divisor: common CRC schemes are:CRC12 1100000001011CRC16 11000000000000101 CRC-CCITT 10001000000100001 CRC32 100000100110000010001110110110111

M = mod( Number, Divisor): computed very efficiently with simple circuits

Receiver:

FRAME: Number MOD

mod(Number MOD, CRC) = = M ?

Yes Transmission probably OK

Page 14: Communications Most modern control involves interactions between many microprocessors Examples: PLC: Programming done on PC; uploaded to PLC Complex PLC

Error detection and Correction

Parity, Checksum, CRC: detect error, request re-transmit on error

Redundant data transmission: detect error, and correct automatically!

Common methods:RepeatingHamming codesReed-Muller codes, etc…

Majority coding:Data: 010 Transmit: 000111000

Receive (with error): 001011000

0 1 0

select majority from each group of 3

Accepted data: 010

Page 15: Communications Most modern control involves interactions between many microprocessors Examples: PLC: Programming done on PC; uploaded to PLC Complex PLC

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: 0011Add 1-bit to each circle,total of each circle even

Page 16: Communications Most modern control involves interactions between many microprocessors Examples: PLC: Programming done on PC; uploaded to PLC Complex PLC

(7, 4) Hamming code

Data: 0011

transmit

receiverred-circle: parity ERRORgreen circle: parity ERRORblue circle: parity OK

Error must bein bit shared byred and green

Page 17: Communications Most modern control involves interactions between many microprocessors Examples: PLC: Programming done on PC; uploaded to PLC Complex PLC

(7, 4) Hamming code…

Data: 0011

transmit

receiverred-circle: parity OKgreen circle: parity OKblue circle: parity ERROR

Error must bein unshared bitof Blue circle!

HW: verify that ALL 1-bit errors can be detected and corrected!

Page 18: Communications Most modern control involves interactions between many microprocessors Examples: PLC: Programming done on PC; uploaded to PLC Complex PLC

Hamming code…

Data: bit-stream write data in particular sequence

receiver checks Hamming codes, corrects errors

transmit

compute, add hamming code bits to data

Corrected data

Common Hamming code used: (12, 8) Hamming code

Page 19: Communications Most modern control involves interactions between many microprocessors Examples: PLC: Programming done on PC; uploaded to PLC Complex PLC

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, …

Page 20: Communications Most modern control involves interactions between many microprocessors Examples: PLC: Programming done on PC; uploaded to PLC Complex PLC

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), …

Page 21: Communications Most modern control involves interactions between many microprocessors Examples: PLC: Programming done on PC; uploaded to PLC Complex PLC

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 part 2 of 3 part 3 of 3

To address From address data (part 1 of 3) EDC1/3

To address From address data (part 2 of 3) EDC2/3

To address From address data (part 3 of 3) EDC3/3

packets

transmit

ReceiverRe-constructsMessage fromthree parts received

Typical packet size: 2048 - 4096 Bytes

Question: Why do some web pages load in non-sequential fashion (some pictures load first, others later)

Note: later we’ll see structure of packet in more detail

Page 22: Communications Most modern control involves interactions between many microprocessors Examples: PLC: Programming done on PC; uploaded to PLC Complex PLC

Network terminology

LAN: Local Area Network

A network of communicating devices in a small area (e.g. a building,a factory, etc.)

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 physically connecting computers in a LAN:

Cables (wires), Bluetooth, Wi-Fi…

Common ways of connecting between LAN’s in a WAN:

Telephone networks, Long-distance cables, Satellites

Page 23: Communications Most modern control involves interactions between many microprocessors Examples: PLC: Programming done on PC; uploaded to PLC Complex PLC

Network topologies

Suppose N computers need to communicate with each other

Pairwise connections: How many ?Problems ?

Page 24: Communications Most modern control involves interactions between many microprocessors Examples: PLC: Programming done on PC; uploaded to PLC Complex PLC

Network topologies

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

1

2

3

4

5

6

1

2

3

4

5

6

Central Hub

1

2

34

5

6

1

2

3

4

5

6

• • • •• •TapBus

Stub

(a) Ring topology (b) Star topology

(c) Mesh topology (d) Bus topology

Terminator

Page 25: Communications Most modern control involves interactions between many microprocessors Examples: PLC: Programming done on PC; uploaded to PLC Complex PLC

Network communication basics

Computer Networking: A Top Down Approach Featuring the Internet,

3rd edition. Jim Kurose, Keith RossAddison-Wesley, July

2004.

The following slides, based largely onthe those provided by Kurose and Ross,will be used to get an introduction to real-worldnetwork communications.

Page 26: Communications Most modern control involves interactions between many microprocessors Examples: PLC: Programming done on PC; uploaded to PLC Complex PLC

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

local ISP

USTnetwork

regional ISP

router workstation

servermobile

Page 27: Communications Most modern control involves interactions between many microprocessors Examples: PLC: Programming done on PC; uploaded to PLC Complex PLC

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

local ISP

USTnetwork

regional ISP

router workstation

servermobile

Page 28: Communications Most modern control involves interactions between many microprocessors Examples: PLC: Programming done on PC; uploaded to PLC Complex PLC

What’s a protocol?

a human protocol and a computer network protocol:

Hi

Hi

What’s thetime?

2pm

TCP connection req

TCP connectionresponse

Get http://www.awl.com/kurose-ross

<file>time

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

Page 29: Communications Most modern control involves interactions between many microprocessors Examples: PLC: Programming done on PC; uploaded to PLC Complex PLC

A closer look at network structure

• network edge: applications and hosts

• network core:

– routers

– network of networks

• access networks, physical media: communication links

Page 30: Communications Most modern control involves interactions between many microprocessors Examples: PLC: Programming done on PC; uploaded to PLC Complex PLC

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

Page 31: Communications Most modern control involves interactions between many microprocessors Examples: PLC: Programming done on PC; uploaded to PLC Complex PLC

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

TCP service [RFC 793]

• reliable, in-order byte-stream data transfer

– loss: acknowledgements and retransmissions

• flow control:

– sender won’t overwhelm receiver

• congestion control:

– senders “slow down sending rate” when network congested

e.g.

Page 32: Communications Most modern control involves interactions between many microprocessors Examples: PLC: Programming done on PC; uploaded to PLC Complex PLC

Network edge: connectionless service

Goal: data transfer between end systems

App’s using TCP:

• HTTP (Web), FTP (file transfer), Telnet (remote login), SMTP (email)

App’s using UDP:

• streaming media, teleconferencing, DNS, Internet telephony

UDP - User Datagram Protocol: connectionless unreliable data transferno flow controlno congestion control

e.g.

Page 33: Communications Most modern control involves interactions between many microprocessors Examples: PLC: Programming done on PC; uploaded to PLC Complex PLC

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”

Page 34: Communications Most modern control involves interactions between many microprocessors Examples: PLC: Programming done on PC; uploaded to PLC Complex PLC

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

Page 35: Communications Most modern control involves interactions between many microprocessors Examples: PLC: Programming done on PC; uploaded to PLC Complex PLC

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

Page 36: Communications Most modern control involves interactions between many microprocessors Examples: PLC: Programming done on PC; uploaded to PLC Complex PLC

Packet-switching: store-and-forward

• 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

R R RL

Page 37: Communications Most modern control involves interactions between many microprocessors Examples: PLC: Programming done on PC; uploaded to PLC Complex PLC

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

Page 38: Communications Most modern control involves interactions between many microprocessors Examples: PLC: Programming done on PC; uploaded to PLC Complex PLC

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

Page 39: Communications Most modern control involves interactions between many microprocessors Examples: PLC: Programming done on PC; uploaded to PLC Complex PLC

Residential access… Cable modems

home

cable headend

cable distributionnetwork (simplified)

Page 40: Communications Most modern control involves interactions between many microprocessors Examples: PLC: Programming done on PC; uploaded to PLC Complex PLC

Residential access: cable modems

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

Page 41: Communications Most modern control involves interactions between many microprocessors Examples: PLC: Programming done on PC; uploaded to PLC Complex PLC

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

Page 42: Communications Most modern control involves interactions between many microprocessors Examples: PLC: Programming done on PC; uploaded to PLC Complex PLC

Wireless access networks

• 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)

basestation

mobilehosts

router

Page 43: Communications Most modern control involves interactions between many microprocessors Examples: PLC: Programming done on PC; uploaded to PLC Complex PLC

Home networks

Typical home network components:

• ADSL or cable modem

• router/firewall/NAT

• Ethernet

• wireless access point

wirelessaccess point

wirelesslaptops

router/firewall

cablemodem

to/fromcable

headend

Ethernet

Page 44: Communications Most modern control involves interactions between many microprocessors Examples: PLC: Programming done on PC; uploaded to PLC Complex PLC

Internet structure: network of networks

• a packet passes through many networks!

Tier 1 ISP

Tier 1 ISP

Tier 1 ISP

Network Access Point

Tier-2 ISPTier-2 ISP

Tier-2 ISP Tier-2 ISP

Tier-2 ISP

localISPlocal

ISPlocalISP

localISP

localISP Tier 3

ISP

localISP

localISP

localISP

Page 45: Communications Most modern control involves interactions between many microprocessors Examples: PLC: Programming done on PC; uploaded to PLC Complex PLC

Protocol “Layers”

Networks are complex!

• many “pieces”:

– hosts

– routers

– links of various media

– applications

– protocols

– hardware, software

Page 46: Communications Most modern control involves interactions between many microprocessors Examples: PLC: Programming done on PC; uploaded to PLC Complex PLC

Analogy: Organization of air travel

ticket (purchase)

baggage (check)

gates (load)

runway takeoff

airplane routing

ticket (complain)

baggage (claim)

gates (unload)

runway landing

airplane routing

airplane routing

Page 47: Communications Most modern control involves interactions between many microprocessors Examples: PLC: Programming done on PC; uploaded to PLC Complex PLC

ticket (purchase)

baggage (check)

gates (load)

runway (takeoff)

airplane routing

departureairport

arrivalairport

intermediate air-trafficcontrol centers

airplane routing airplane routing

ticket (complain)

baggage (claim

gates (unload)

runway (land)

airplane routing

ticket

baggage

gate

takeoff/landing

airplane routing

Layering of airline functionality

Layers: each layer implements a service

– via its own internal-layer actions

– relying on services provided by layer below

Page 48: Communications Most modern control involves interactions between many microprocessors Examples: PLC: Programming done on PC; uploaded to PLC Complex PLC

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?

Page 49: Communications Most modern control involves interactions between many microprocessors Examples: PLC: Programming done on PC; uploaded to PLC Complex PLC

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

Page 50: Communications Most modern control involves interactions between many microprocessors Examples: PLC: Programming done on PC; uploaded to PLC Complex PLC

messagesegment

datagram

frame

sourceapplicatio

ntransportnetwork

linkphysical

HtHnHl M

HtHn M

Ht M

M

destination

application

transportnetwork

linkphysical

HtHnHl M

HtHn M

Ht M

M

networklink

physical

linkphysical

HtHnHl M

HtHn M

HtHnHl M

HtHn M

HtHnHl M HtHnHl M

router

switch

Encapsulation

Page 51: Communications Most modern control involves interactions between many microprocessors Examples: PLC: Programming done on PC; uploaded to PLC Complex PLC

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 containsaddressing information and some control information that enables packetsto be routed.

Page 52: Communications Most modern control involves interactions between many microprocessors Examples: PLC: Programming done on PC; uploaded to PLC Complex PLC

1

23

0111

value in arrivingpacket’s header

routing algorithm

local forwarding tableheader value output link

0100010101111001

3221

Network layer functions: Forwarding and Routing

Forwarding: determines which link totake at a specific router;

Routing: plan of a series of forwardingdata that can take the packet from sourceto destination

DATAGRAM

Page 53: Communications Most modern control involves interactions between many microprocessors Examples: PLC: Programming done on PC; uploaded to PLC Complex PLC

IP datagram format

ver length

32 bits

data (variable length,typically a TCP

or UDP segment)

16-bit identifier

Internet checksum

time tolive

32 bit source IP address

IP protocol versionnumber

header length (bytes)

max numberremaining hops

(decremented at each router)

forfragmentation/reassembly

total datagramlength (bytes)

upper layer protocolto deliver payload to

head.len

type ofservice

“type” of data flgsfragment

offsetupper layer

32 bit destination IP address

Options (if any) E.g. timestamp,record routetaken, specifylist of routers to visit.

how much overhead with TCP?

• 20 bytes of TCP

• 20 bytes of IP

• = 40 bytes + app layer overhead

Page 54: Communications Most modern control involves interactions between many microprocessors Examples: PLC: Programming done on PC; uploaded to PLC Complex PLC

Datagram networks

• packets forwarded using destination host address

– packets between same source-dest pair may take different paths

application

transportnetworkdata linkphysical

application

transportnetworkdata linkphysical

1. Send data 2. Receive data

Main router functions:

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

• forwarding datagrams from incoming to outgoing link

Page 55: Communications Most modern control involves interactions between many microprocessors Examples: PLC: Programming done on PC; uploaded to PLC Complex PLC

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.1.2

223.1.1.3

223.1.1.4 223.1.2.9

223.1.2.2

223.1.2.1

223.1.3.2223.1.3.1

223.1.3.27

223.1.1.1 = 11011111 00000001 00000001 00000001

223 1 11

Page 56: Communications Most modern control involves interactions between many microprocessors Examples: PLC: Programming done on PC; uploaded to PLC Complex PLC

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.1.2

223.1.1.3

223.1.1.4 223.1.2.9

223.1.2.2

223.1.2.1

223.1.3.2223.1.3.1

223.1.3.27

network consisting of 3 subnets

LAN

Page 57: Communications Most modern control involves interactions between many microprocessors Examples: PLC: Programming done on PC; uploaded to PLC Complex PLC

223.1.1.0/24223.1.2.0/24

223.1.3.0/24

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

Subnet mask: /24

Subnets

Page 58: Communications Most modern control involves interactions between many microprocessors Examples: PLC: Programming done on PC; uploaded to PLC Complex PLC

How many?

223.1.1.1

223.1.1.3

223.1.1.4

223.1.2.2223.1.2.1

223.1.2.6

223.1.3.2223.1.3.1

223.1.3.27

223.1.1.2

223.1.7.0

223.1.7.1223.1.8.0223.1.8.1

223.1.9.1

223.1.9.2

Subnets

Page 59: Communications Most modern control involves interactions between many microprocessors Examples: PLC: Programming done on PC; uploaded to PLC Complex PLC

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: Dynamic Host Configuration Protocol: dynamically get address from as server

– “plug-and-play”

Page 60: Communications Most modern control involves interactions between many microprocessors Examples: PLC: Programming done on PC; uploaded to PLC Complex PLC

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)

Page 61: Communications Most modern control involves interactions between many microprocessors Examples: PLC: Programming done on PC; uploaded to PLC Complex PLC

Transport services and protocols

• provide logical communication between app processes running on different hosts

• Most common transport protocol: TCP

application

transportnetworkdata linkphysical

application

transportnetworkdata linkphysical

networkdata linkphysical

networkdata linkphysical

networkdata linkphysical

networkdata linkphysicalnetwork

data linkphysical

logical end-end transport

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.

Page 62: Communications Most modern control involves interactions between many microprocessors Examples: PLC: Programming done on PC; uploaded to PLC Complex PLC

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

Page 63: Communications Most modern control involves interactions between many microprocessors Examples: PLC: Programming done on PC; uploaded to PLC Complex PLC

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

transportnetworkdata linkphysical

application

transportnetworkdata linkphysical

application

transportnetworkdata linkphysical

Page 64: Communications Most modern control involves interactions between many microprocessors Examples: PLC: Programming done on PC; uploaded to PLC Complex PLC

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

Page 65: Communications Most modern control involves interactions between many microprocessors Examples: PLC: Programming done on PC; uploaded to PLC Complex PLC

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

process

TCP withbuffers,variables

socket

host orserver

process

TCP withbuffers,variables

socket

host orserver

Internet

controlledby OS

controlled byapp developer

Page 66: Communications Most modern control involves interactions between many microprocessors Examples: PLC: Programming done on PC; uploaded to PLC Complex PLC

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

Page 67: Communications Most modern control involves interactions between many microprocessors Examples: PLC: Programming done on PC; uploaded to PLC Complex PLC

Socket programming

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

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

Goal: learn how to build client/server application that communicate using sockets

Page 68: Communications Most modern control involves interactions between many microprocessors Examples: PLC: Programming done on PC; uploaded to PLC Complex PLC

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

process

TCP withbuffers,

variables

socket

controlled byapplicationdeveloper

controlled byoperating

system

host orserver

process

TCP withbuffers,

variables

socket

controlled byapplicationdeveloper

controlled byoperatingsystem

host orserver

internet

Page 69: Communications Most modern control involves interactions between many microprocessors Examples: PLC: Programming done on PC; uploaded to PLC Complex PLC

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

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

application viewpoint

Page 70: Communications Most modern control involves interactions between many microprocessors Examples: PLC: Programming done on PC; uploaded to PLC Complex PLC

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.

Page 71: Communications Most modern control involves interactions between many microprocessors Examples: PLC: Programming done on PC; uploaded to PLC Complex PLC

Socket programming with TCP

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)

outT

oSer

ver

to network from network

inFr

omS

erve

r

inFr

omU

ser

keyboard monitor

Process

clientSocket

inputstream

inputstream

outputstream

TCPsocket

Clientprocess

client TCP socket

Page 72: Communications Most modern control involves interactions between many microprocessors Examples: PLC: Programming done on PC; uploaded to PLC Complex PLC

Client/server socket interaction: TCP

wait for incomingconnection requestconnectionSocket =welcomeSocket.accept()

create socket,port=x, forincoming request:welcomeSocket =

ServerSocket()

create socket,connect to hostid, port=xclientSocket =

Socket()

closeconnectionSocket

read reply fromclientSocket

closeclientSocket

Server (running on hostid) Client

send request usingclientSocketread request from

connectionSocket

write reply toconnectionSocket

TCP connection setup

Page 73: Communications Most modern control involves interactions between many microprocessors Examples: PLC: Programming done on PC; uploaded to PLC Complex PLC

Example: Java client (TCP)

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());

Createinput stream

Create client socket,

connect to server

Createoutput stream

attached to socket

Page 74: Communications Most modern control involves interactions between many microprocessors Examples: PLC: Programming done on PC; uploaded to PLC Complex PLC

Example: Java client (TCP), cont.

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(); } }

Createinput stream

attached to socket

Send lineto server

Read linefrom server

Page 75: Communications Most modern control involves interactions between many microprocessors Examples: PLC: Programming done on PC; uploaded to PLC Complex PLC

Example: Java server (TCP)

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()));

Createwelcoming socket

at port 6789

Wait, on welcomingsocket for contact

by client

Create inputstream, attached

to socket

Page 76: Communications Most modern control involves interactions between many microprocessors Examples: PLC: Programming done on PC; uploaded to PLC Complex PLC

Example: Java server (TCP), cont

DataOutputStream outToClient = new DataOutputStream(connectionSocket.getOutputStream());

clientSentence = inFromClient.readLine();

capitalizedSentence = clientSentence.toUpperCase() + '\n';

outToClient.writeBytes(capitalizedSentence); } } }

Read in linefrom socket

Create outputstream,

attached to socket

Write out lineto socket

End of while loop,loop back and wait foranother client connection

Page 77: Communications Most modern control involves interactions between many microprocessors Examples: PLC: Programming done on PC; uploaded to PLC Complex PLC