ethernet - cs.sfu.ca 3.pdfstream socket: provides for the bidirectional, reliable, sequenced, and...
TRANSCRIPT
1
1
Ethernet
broadband or baseband signallingHub and repeatersEthernet switches and bridges: Ethernet packets Ethernet topologies
Bus, star, tree.
Carrier-Sense Multiple Access with Collision Detection (CSMA/CD)All nodes are continuously ‘listening’ to the medium for packets that are addressed to them.Packets frames
Prefix: hardware timing purposesthe destination address, the sending address;length of data (46—1,500 bytes), data of variable length,checksum
2
2
Ethernet
Packet collisioncarrier sensing: not enough
Collision detection• Sender’s responsibility to detect
Minimum packet length in collision detectionSend jamming signal, delay and try againDelay time is selected using binary exponential back-off
A B
A B
Message almost there at time T whenB starts – collision!
time = 0
time = T’
time = 2T
A B
3
3
Middleware
Application programming interfaces (APIs)Examples of middleware services
Remote data access (RDA) -- SQL access to server-based DBMS.Remote procedure calls (RPC)Remote method invocation (RMI)
Today’s topicsInterprocess communication (IPC);Java API for Internet transport protocolsExternal data representation and marshalling
Applications, services
Middlewarelayers
request-reply protocol
marshalling and external data representation
UDP and TCP
Thischapter
RMI and RPC
4
4
InterProcess Communication
two basic modelsshared memorymessage passing
two basic operations on messages Send (to, message)Receive (from, message)
A typical communication system
5
5
Example of Persistent Asyn. Comm.: email system
Types of communicationPersistent communication – Stores message until communicated to userTransient communication – Stored only when sending and receiving processes are alive
• Transport level protocols provide transient communication
Asynchronous – Sender continues after sending messageSynchronous – Sender blocks until message is stored at receiver's local buffer, delivered to receiver or processed by receiver
6
6
c) Transient asynchronous communication: UDP, one-way RPCs.
d) Receipt-based transient synchronous communication
e) Delivery-based transient synchronous communication at message delivery: Asyn. RPCs
f) Response-based transient synchronous communication: PRCs, RMIs.
7
7
IPC mechanisms
Pipesprocesses must be related through a common ancestorimpossible in a distributed environment
shared memory Sockets
4.4BSD UnixJava
message queues: Message-oriented Middleware (MOM)
message
agreed portany port
socketsocket
Internet address = 138.37.88.249Internet address = 138.37.94.248
other ports
client server
8
8
Socket Types in 4.4BSD UNIX
Stream socket: provides for the bidirectional, reliable, sequenced, and unduplicated flow of data without record boundary.
Very similar to pipeDatagram socket: supports bidirectional flow of data which is not promised to be sequenced, reliable, or unduplicated
Reliability guaranteed by high-level apps.Most widely used in name service, time service.
A raw socket: provides users access to the underlying communication protocols which support socket abstractions.
Not for general usersSequenced packet socket: No protocol for this typ
9
9
Socket creation: socket()
communication domains local domain: at the same machineinternet domain: InternetXNS domain: XEROX Network Systems
s = socket(domain, type, protocol); A system calldomain: AF_UNIX, AF_INET, or AF_NStype: SOCK_STREAM, SOCK_DGRAM, etcprotocol: TCP or UDP. Auto selected if 0Return a socket descriptor (a small integer for later reference)Ex: s = socket(AF_INET, SOCK_STREAM, 0);
Creation Failure: ReasonsLack of memory (ENOBUFS)Unknown protocol (EPROTONOSUPPORT) Socket without supporting protocol (EPROTOTYPE)
10
10
Binding Names: bind()
Socket created without a name (i.e. port address)Process has no way to access it.
System call: bind(s, address, len)s: socket descriptoraddress: <local address, local port> or a path namelen: the length of the address.
Connection Establishment
Asymmetric, involving a server and a clientServer: create bind listen acceptClient: create bind connectconnect(s, address, len)
• s: socket descriptor• address: server address• len: the length of the address
11
11
Connection FailureTimeout (ETIMEDOUT)
Server down or network corrupt
Connection refused (ECONNREFUSED)Server not ready yet
Network down or server downoperational errors are returned by the underlying communication system
Unknown hostoperational errors returned by intermediate gateways or switching nodes.
System Call: listen()listen(s, max_num)
s: socket descriptormax_num: the maximum number of outstanding connections which may be queued awaiting acceptance by the server processIf the queue is full, a connection will be ignored (instead of refused). Why?
12
12
System call: accept()
newsock = accept(s, from-addr, len)s: socket descriptorfrom-addr: to store the address of the client
• Usually a pointer, could be nulllen: length of from-addrReturn a new socket.Usually block the callerCannot select the client to be accepted.
Data TransferOnce a connection is established, data flow may begin.write(s, buf, sizeof (buf));
send(s, buf, sizeof (buf), flags);read(s, buf, sizeof (buf));
recv(s, buf, sizeof (buf), flags); Flags: provide more features
13
13
Discarding Socketsclose(s)
Sockets which promises reliable transmission will still attempt transfer data.
Shutdown(s, how), where how is0: no more receiving1: no more sending2: no more receiving or sending
socket()
close()
read()
connect()
write()
client
socket()
bind()
listen()
accept()
accept()
read()
write()
close()
server
Start a thread
Wait for new connection
14
14
Java Sockets
close()
readUTF()
socket()
writeUTF()
client socket()
accept()
accept()
readUTF()
writeUTF()
close()
server
Start a thread
Wait for new connection
15
15
Java API for the Internet protocols
Transport address: IP address + port numberjava.net.InetAddress
host name: “java.sun.com”getHostAddress(): IP address string in textual presentation. getHostName(): the host name for this IP address.32-bit integers for port numberSocket types
UDP socketTCP socket
Static InetAddress.getByName(String host)
16
16
UDP socket
Data unit: datagramCalled datagram socketSocket must be bound to a local port and one IP address
Server: well-known portClient: any free one
issues related to datagram communicationMessage sizenon-blocking send operations and blocking receive operations Timeouts
applications use UDP: Domain Naming Service, Voice Over IP
17
17
UDP socket
Encapsulated in Class DatagramSocketDatagram: Class DatagramPacketDatagramSocket.send(DatagramPacket)DatagramSocket.receive(DatagramPacket)DatagramSocket.setSoTimeout(int timeout) DatagramSocket.connect(InetAddress, int port )public DatagramPacket(byte[] buf, int length, InetAddress address, int port)
18
18
TCP socket
TCP is a connection-oriented protocol, a connection is established first.Server listens connection requestClient asks for a connectionTwo types of TCP sockets: ordinary sockets and server socketsA client process constructs an ordinary socket and then it asks for a connection with the server.A server socket receives a connection request, it constructs an ordinary socket with an unused port number which completes the connection. No limit on data size.Streams: one in each direction
19
19
Some issues in stream communication
Matching of data itemsBlockingThreadsApplications use TCP: HTTP, FTP, Telnet, SMTP.ordinary TCP socket: Socketserver socket: ServerSocket
ServerSocket(int port), or ServerSocket.bind(SocketAddress, int port);Socket ServerSocket.accept();
InputStream and OutputStream classesAn example in textbook
20
20
Message-oriented Middleware (MOM)
Main featuresintermediate-term storage for messages: persistent !neither sender nor receiver is required to be activeMessage queue eliminate the need for programs to be logically connected: asynchronous !takes minutes
Only guarantee is that a message will be inserted in receivers’ queue. But no guarantees about when, or even if the message will actually be read Source queue & destination queueQueue managers: Message Queue Interface (MQI)Overlay network
21
21
Message BrokersIssue: message format
How to make sure the receiver understands sender’s message?
One format?Application are too diverse.
Act as an application level gatewayE.g. change delimiters at the end of records
Account Id, Trader Id, Price, Quantity, Date, Customer Id
Customer Id, Account Id, Trader Id, Price, Quantity, Date
Application A outputs:Application 1 inputs:
Application B outputs: Application 3 inputs:
ParseRules
Transform
Application 2 inputs:
Date, Customer Id, Account Id, Price, Quantity, Trader Id
Date, Price, Quantity, Trader Id
Date, Customer Id, Price, Quantity
22
22
Example: IBM MQSeries
QueuesLocal QueueRemote QueueAlias QueueModel QueueSome properties of local queues:
• Maximum Message Size• Maximum Queue Depth• Enable/Disable Put or Get• Persistent/Not Persistent• Local queues can generate events (messages) under
certain conditions (like queue full).
Queue managersChannels
Message Channels: message channel agent (MCA) MQI channels: client channels
23
23
Example: IBM MQSeries
Messagesdescriptor + application data
Four types of messages:request messagereply message.one-way messagereport message: generated by the Queue Manager. For example, Delivery confirmation.
Messages can have a “time-to-live”, called Expiry: Each queue manager can have a dead-letter queue.persistent or non-persistent messages Message Priority & Message CorrelatorSegmented Messages - allows ending of VERY LARGE messages (> 100 MB)A “reply to” address (the name of a Queue Manager and Queue).Messages are added and removed from queues in Units of Work
24
24
External data representation and marshalling
Heterogeneity: different representations for simple data items.Big Endian vs. Little EndianSolutions
transmitted in the sender’s format together with an indication of the format usedconverted to an agreed external format
An agreed standard for the representation: external data representationMarshaling vs. UnmarshallingCORBA’s Common Data Representation (CDR);Java’s object serialization;XML (Extensible Markup Language)
25
25
Java object serialization
Goal: supports the encoding of objects, and the objects reachable from them, into a stream of bytes and the complementary reconstruction of the object graph from the stream.the state of an objectsufficient information to reconstruct the objectthe receiving process has no knowledge about the types of objectsReference: handlesObjects to be serialized in the stream may support either the Serializable or the Externalizable interface.the “java.io.Serializable” interface
26
26
Java object serialization
Serializable objectsimplement the “java.io.Serializable”interfaceYou can implement one or more of the methods readObject(), writeObject() to custom serialization.
Externalizable objectsimplement the “java.io.Externalizable”interfacethe programmer takes full responsibility for the serialization and deserialization of objects.
java.io.ObjectOutputStream and java.io.ObjectInputStream
Serialization will preserve the state of all fields in the object graph except for fields marked transient or static or fields contained in superclasses that are not serializable.
27
27
Java object serialization
Visibility modifiers (e.g., private, protected, etc.) on fields do not affect serialization.
Any subclasses of a serializable class are serializable classes, and any data inside a serializable class are also serializable data.
Two important methods:readObject(), reads an object from the defined input streamwriteObject(), writes an object to an output stream.
Other methods that support the serialization and deserialization of primitive data types: readInt, readFloat, writeInt, writeFloat, etc.