Title: Integration, Layers, Modules and APIs
1Integration, Layers, Modules and APIs
- Graham Knight (G.Knight_at_cs.ucl.ac.uk)
2Introduction
- The purpose of this section is
- To establish terminology
- Layer, protocol, service, PDU, request,
indication, confirmed, unconfirmed, connection
oriented, connectionless - To relate this terminolgy to programing concepts
such as - Module, method, specification, implementation,
call, return etc. - To note that thinking in terms of modules or
layers simplifies things (I hope)
3Services and Protocols
Service what it does
Protocol how it does it
Users often pieces of software (E.g. a Java
program) Service interface corresponds to an
API (E.g. the java.net.socket classes) Users make
requests (e.g. call methods of the socket
class) Users receive indications from the
service (e.g. via event handlers)
4Layers
PDUs
PDUs
PDUs
- PEs may use lower layer services to carry their
PDUs - TCP uses IP
- HTTP uses TCP
- The postal service uses air freight
- One Java class may use another in its
implementation
5API Example Unconfirmed Request
- Service interface IP datagram send
- An unconfirmed service
- Java DatagramSocket class method
- public void send(DatagramPacket p)
- DatagramPacket class wraps up
- Data to send IP address of the remote host
- What does it mean when method returns?
- Implementation has accepted request, may or may
not have executed it? - Datagram has been sent?
- Datagram has been sent and received?
6API Example Confirmed Request
- Service interface HTTP GET request
- Confirmed service
- Java URLConnection class method
- public Object getContent()
- Sends GET request and picks up the response
- What does it mean when method returns?
- Implementation has accepted request, may or may
not have executed it? - Request has been sent?
- Request has been sent and response received?
7API Example Connection Oriented 1
- The previous two examples were connectionless
services - Each request is independent no memory.
- Connection oriented Service
- Establish the connection
- Use it
- Close it
- Need requests and elements for each phase
8API Example Connection Oriented 2
- Example - Java socket class
- Stream connection connection oriented
- Socket s new Socket(addr, port)
- OutputStreamWriter wr new OutputStreamWriter(s.g
etOutputStream(), "UTF8") - wr.write(hi there)
- wr.write(here is some more text)
- wr.write(and some more)
- wr.close()
9API Example Connection Oriented 3
- wr.write(hi there)
- wr.write(here is some more text)
- wr.write(and some more)
- How many PDUs are sent?
- Answer 1
- Java buffers data to optimise transmission
- wr.write(hi there) wr.flush()
- wr.write(here is some more text) wr.flush()
- wr.write(and some more) wr.flush()
- Sends 3 PDUs
10Output Synchronisation
11API Example Indications
- Consider this method from the Java DatagramSocket
class - public void receive(DatagramPacket p)
- This method blocks
- Return gtDatagram has been received
- So-called synchronous operation
- Alternative a call-back
- public void datagramIn(DatagramPacket p)
- Method datagramIn()is supplied by user
- Method is called when datagram arrives
12Input Synchronisation
Synchronous input
Asynchronous input
Listener thread
Service thread
Call-back thread
datagramIn called
Process data
13Conclusions
- Comms. systems consist of services which use
other services - Try to think of one at a time!
- What does the service look like to its users?
- Think of service requests (formal) and API
(implementation in a language) - How is the service provided?
- Think of the protocol
- Think how the protocol uses another service