Professional Documents
Culture Documents
Most modern control involves interactions between many microprocessors Examples: PLC: Programming done on PC; uploaded to PLC Complex PLC control requires interaction between many PLCs e.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
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
Wow
ASCII V
mark 1 1 1 0 1 0 start bit 1 stop bits 1 1 1 1 0 1 1 1 1 1 0 1 1 1 idle
1010 111
1101 111
1110 111
time
Communications
For devices to exchange data, several things must work together:
Wow 1010 111 1101 111 1110 111
mark
1 1 0
1 0
1 1 1
1 0
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
Idle/next caracter
- 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 DATA ETX CT SYNC
Synchronization of communication
data
Receiver
data
Transmitter
Receiver
synchro clock
data + synchro
Receiver
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
1 Binary Direct NRZ (nonreturn to zero 0 1 0 0 0 1
RZ (return to zero)
0V
manchester coding
Voltage change at start of cycle 0 No change at start of cycle 1 Voltage flips at mid-cycle
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?
Techniques for EDC: 1. IF receiver detects error requests sender to re-transmit 2. Receiver detects and corrects error without re-transmission
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 1s even. Odd parity: value of parity bit is set to make total number of 1s odd. Example: (ASCII) W: 1010 111 (odd parity) W: 0 1010 111 (even parity) W: 1 1010 111
Hello, world
72
101
108
108
111
44
32
119
111
114
108
100
1 checksum/12 bytes too much overhead typical use: 1 checksum byte per 128 Bytes of data
Number: 629
Divisor: 25
Transmit: (629,4)
Data: 010
Transmit: 000111000
0 1
Hamming codes
Problem of Majority coding: (1) too much redundancy (2) burst errors cant be handled
Data: 0011
red-circle: parity ERROR green circle: parity ERROR blue circle: parity OK
receiver
Data: 0011
receiver
HW: verify that ALL 1-bit errors can be detected and corrected!
Hamming code
Data: bit-stream write data in particular sequence
transmit
Corrected data
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)
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 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 transmit Receiver Re-constructs Message from three parts received Long message part 2 of 3 part 3 of 3
Typical packet size: 2048 - 4096 Bytes Note: later well 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 LANs connected to each other, over a large area, e.g. international communication networks. Common ways of connecting between LANs in a WAN: Telephone networks, Long-distance cables, Satellites
Network topologies
Suppose N computers need to communicate with each other
Network topologies
Network topology describes how different devices are (physically) connected to each other.
1 6 2 6 1 2 Central Hub 5 4 (a) Ring topology 3 5 4 (b) Star topology 3
1 3
5
Terminator
Stub 2
Bus
Tap
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, 3rd edition. Jim Kurose, Keith Ross Addison-Wesley, July 2004.
millions of connected computing devices: hosts = end systems running network applications communication links fiber, copper, radio, satellite transmission rate = bandwidth routers: forward packets
mobile
regional ISP
UST network
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
regional ISP
UST network
Whats 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
Whats the time?
2pm
time
<file>
network edge: applications and hosts network core: routers network of networks access networks, physical media: communication links
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
e.g.
e.g.
Apps using TCP: HTTP (Web), FTP (file transfer), Telnet (remote login), SMTP (email) Apps using UDP: streaming media, teleconferencing, DNS, Internet telephony
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
End-end resources reserved for call link bandwidth, switch capacity dedicated resources: no sharing circuit-like (guaranteed) performance call setup required
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
Q: How to connect end systems to edge router? residential access nets institutional access networks (school, company) mobile access networks
ADSL: asymmetric digital subscriber line [similar to NOW Broadband] up to 1 Mbps upstream up to 8 Mbps downstream
Diagram: http://www.cabledatacomnews.com/cmic/diagram.html
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
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
cable modem
local ISP
local ISP
local ISP
Tier 1 ISP
Tier 1 ISP
Tier-2 ISP local local ISP 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
ticket (complain)
baggage (claim) gates (unload) runway landing airplane routing
airplane routing
ticket (purchase) baggage (check) gates (load) runway (takeoff) airplane routing
departure airport
ticket (complain) baggage (claim gates (unload) runway (land) airplane routing airplane routing airplane routing
arrival airport
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 systems pieces layered reference model for discussion modularization eases maintenance, updating of system change of implementation of layers service transparent to rest of system e.g., change in gate procedure doesnt affect rest of system layering considered harmful?
source
datagram Hn Ht
Hl Hn Ht
message segment Ht
M M M M
frame
Encapsulation
link physical
Hl Hn Ht
switch
destination
M
Ht
Hn Ht Hl Hn Ht
M M M
Hn Ht Hl Hn Ht
M
M
Hn Ht Hl Hn Ht
M M
router
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.
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
1
3 2
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 32 bits
length fragment 16-bit identifier flgs offset upper time to Internet layer live checksum 32 bit source IP address 32 bit destination IP address Options (if any)
how much overhead with TCP? 20 bytes of TCP 20 bytes of IP = 40 bytes + app layer overhead
Datagram networks
packets forwarded using destination host address packets between same source-dest pair may take different paths
Main router functions: run routing algorithms/protocol (RIP, OSPF, BGP) forwarding datagrams from incoming to outgoing link
IP Addressing: introduction
223.1.1.1
IP address: 32-bit identifier for host, router interface interface: connection between host/router and physical link routers typically have multiple interfaces host may have multiple interfaces IP addresses associated with each interface
223.1.3.27
223.1.2.2
223.1.3.1
223.1.3.2
Subnets
IP address: subnet part (high order bits) host part (low order bits) Whats 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.1.3
223.1.2.9
223.1.2.2
223.1.3.27
LAN
223.1.3.1
223.1.3.2
Subnets
223.1.1.0/24
223.1.2.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.
223.1.3.0/24
Subnets
223.1.1.1
223.1.1.2
223.1.1.4 223.1.1.3
How many?
223.1.9.2
223.1.7.0
223.1.7.1
223.1.2.1
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)
network data link physical 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.
Principles of network applications Web and HTTP FTP Electronic Mail SMTP, POP3, IMAP DNS Socket programming with TCP Building a Web server
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 controlled by app developer host or server
process socket
process socket
Internet
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
application-created, OS-controlled interface
a host-local,
(a door) into which application process can both send and receive messages to/from another application process
internet
host or server
host or server
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.
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)
input stream
inFromUser
output stream
inFromServer
outToServer
input stream
TCP socket
from network
Client
TCP
setup
create socket, connect to hostid, port=x clientSocket = Socket() send request using clientSocket
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()));
Create welcoming socket at port 6789 Wait, on welcoming socket for contact by client Create input stream, attached to socket
DataOutputStream outToClient = new DataOutputStream(connectionSocket.getOutputStream()); clientSentence = inFromClient.readLine(); capitalizedSentence = clientSentence.toUpperCase() + '\n'; outToClient.writeBytes(capitalizedSentence); }