Ethernet broadband or baseband signalling Hub and repeaters Ethernet 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 purposes the destination address, the sending address; length of data (46,500 bytes), data of variable length, checksum
Ethernet Packet collision carrier sensing: not enough time = 0 A B time = T A B Message almost there at time T when B starts collision! Collision detection Sender s responsibility to detect A B time = 2T Minimum packet length in collision detection Send jamming signal, delay and try again Delay time is selected using binary exponential back-off 2 2
Middleware Applications, services RMI and RPC This chapter request-reply protocol marshalling and external data representation Middleware layers UDP and TCP 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 topics Interprocess communication (IPC); Java API for Internet transport protocols External data representation and marshalling 3 3
InterProcess Communication two basic models shared memory message passing two basic operations on messages Send (to, message) Receive (from, message) A typical communication system 4 4
Types of communication Persistent communication Stores message until communicated to user Transient communication Stored only when sending and receiving processes are alive Transport level protocols provide transient communication Asynchronous Sender continues after sending message Synchronous Sender blocks until message is stored at receiver's local buffer, delivered to receiver or processed by receiver Example of Persistent Asyn. Comm.: email system 5 5
c) Transient asynchronous communication: UDP, oneway 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. 6 6
IPC mechanisms Pipes processes must be related through a common ancestor impossible in a distributed environment shared memory Sockets 4.4BSD Unix Java message queues: Message-oriented Middleware (MOM) socket any port agreed port socket message client server other ports Internet address = 38.37.94.248 Internet address = 38.37.88.249 7 7
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 pipe Datagram 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 users Sequenced packet socket: No protocol for this typ 8 8
Socket creation: socket() communication domains local domain: at the same machine internet domain: Internet XNS domain: XEROX Network Systems s = socket(domain, type, protocol); A system call domain: AF_UNIX, AF_INET, or AF_NS type: SOCK_STREAM, SOCK_DGRAM, etc protocol: TCP or UDP. Auto selected if 0 Return a socket descriptor (a small integer for later reference) Ex: s = socket(af_inet, SOCK_STREAM, 0); Creation Failure: Reasons Lack of memory (ENOBUFS) Unknown protocol (EPROTONOSUPPORT) Socket without supporting protocol (EPROTOTYPE) 9 9
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 descriptor address: <local address, local port> or a path name len: the length of the address. Connection Establishment Asymmetric, involving a server and a client Server: create bind listen accept Client: create bind connect connect(s, address, len) s: socket descriptor address: server address len: the length of the address 0 0
Connection Failure Timeout (ETIMEDOUT) Server down or network corrupt Connection refused (ECONNREFUSED) Server not ready yet Network down or server down operational errors are returned by the underlying communication system Unknown host operational errors returned by intermediate gateways or switching nodes. System Call: listen() listen(s, max_num) s: socket descriptor max_num: the maximum number of outstanding connections which may be queued awaiting acceptance by the server process If the queue is full, a connection will be ignored (instead of refused). Why?
System call: accept() newsock = accept(s, from-addr, len) s: socket descriptor from-addr: to store the address of the client Usually a pointer, could be null len: length of from-addr Return a new socket. Usually block the caller Cannot select the client to be accepted. Data Transfer Once 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 2 2
Discarding Sockets close(s) Sockets which promises reliable transmission will still attempt transfer data. Shutdown(s, how), where how is 0: no more receiving : no more sending 2: no more receiving or sending server socket() client socket() bind() listen() connect() write() read() read() write() Start a thread accept() accept() Wait for new connection close() close() 3 3
Java Sockets server client socket() socket() accept() writeutf() readutf() readutf() writeutf() Start a thread accept() Wait for new connection close() close() 4 4
Java API for the Internet protocols Transport address: IP address + port number java.net.inetaddress Static InetAddress.getByName(String host) 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 number Socket types UDP socket TCP socket 5 5
UDP socket Data unit: datagram Called datagram socket Socket must be bound to a local port and one IP address Server: well-known port Client: any free one issues related to datagram communication Message size non-blocking send operations and blocking receive operations Timeouts applications use UDP: Domain Naming Service, Voice Over IP 6 6
UDP socket Encapsulated in Class DatagramSocket Datagram: Class DatagramPacket DatagramSocket.send(DatagramPacket) DatagramSocket.receive(DatagramPacket) DatagramSocket.setSoTimeout(int timeout) DatagramSocket.connect(InetAddress, int port ) public DatagramPacket(byte[] buf, int length, InetAddress address, int port) 7 7
TCP socket TCP is a connection-oriented protocol, a connection is established first. Server listens connection request Client asks for a connection Two types of TCP sockets: ordinary sockets and server sockets A 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 8 8
Some issues in stream communication Matching of data items Blocking Threads Applications use TCP: HTTP, FTP, Telnet, SMTP. ordinary TCP socket: Socket server socket: ServerSocket ServerSocket(int port), or ServerSocket.bind(SocketAddress, int port); Socket ServerSocket.accept(); InputStream and OutputStream classes An example in textbook 9 9
Message-oriented Middleware (MOM) Main features intermediate-term storage for messages: persistent! neither sender nor receiver is required to be active Message 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 queue Queue managers: Message Queue Interface (MQI) Overlay network 2 0 20
Message Brokers Issue: message format How to make sure the receiver understands sender s message? One format? Application are too diverse. Act as an application level gateway E.g. change delimiters at the end of records Application A outputs: Account Id, Trader Id, Price, Quantity, Date, Customer Id Application inputs: Date, Customer Id, Account Id, Price, Quantity, Trader Id Parse Rules Transform Application 2 inputs: Date, Price, Quantity, Trader Id Application B outputs: Customer Id, Account Id, Trader Id, Price, Quantity, Date Application 3 inputs: Date, Customer Id, Price, Quantity 2 2
Example: IBM MQSeries Queues Local Queue Remote Queue Alias Queue Model Queue Some 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 managers Channels Message Channels: message channel agent (MCA) MQI channels: client channels 2 2 22
Example: IBM MQSeries Messages descriptor + application data Four types of messages: request message reply message. one-way message report 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 Correlator Segmented Messages - allows ending of VERY LARGE messages (> 00 MB) A reply to address (the name of a Queue Manager and Queue). Messages are added and removed from queues in Units of Work 2 3 23
External data representation and marshalling Heterogeneity: different representations for simple data items. Big Endian vs. Little Endian Solutions transmitted in the sender s format together with an indication of the format used converted to an agreed external format An agreed standard for the representation: external data representation Marshaling vs. Unmarshalling CORBA s Common Data Representation (CDR); Java s object serialization; XML (Extensible Markup Language) 2 4 24
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 object sufficient information to reconstruct the object the receiving process has no knowledge about the types of objects Reference: handles Objects to be serialized in the stream may support either the Serializable or the Externalizable interface. the java.io.serializable interface 2 5 25
Java object serialization Serializable objects implement the java.io.serializable interface You can implement one or more of the methods readobject(), writeobject() to custom serialization. Externalizable objects implement the java.io.externalizable interface the 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. 2 6 26
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 stream writeobject(), writes an object to an output stream. Other methods that support the serialization and deserialization of primitive data types: readint, readfloat, writeint, writefloat, etc. 2 7 27