From commits-return-25729-apmail-directory-commits-archive=directory.apache.org@directory.apache.org Fri May 07 17:19:22 2010 Return-Path: Delivered-To: apmail-directory-commits-archive@www.apache.org Received: (qmail 95733 invoked from network); 7 May 2010 17:19:22 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 7 May 2010 17:19:22 -0000 Received: (qmail 76420 invoked by uid 500); 7 May 2010 17:19:22 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 76371 invoked by uid 500); 7 May 2010 17:19:22 -0000 Mailing-List: contact commits-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@directory.apache.org Delivered-To: mailing list commits@directory.apache.org Received: (qmail 76364 invoked by uid 99); 7 May 2010 17:19:22 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 07 May 2010 17:19:22 +0000 X-ASF-Spam-Status: No, hits=-1328.8 required=10.0 tests=ALL_TRUSTED,AWL,HTML_FONT_LOW_CONTRAST,HTML_MESSAGE,MIME_HTML_ONLY X-Spam-Check-By: apache.org Received: from [140.211.11.22] (HELO thor.apache.org) (140.211.11.22) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 07 May 2010 17:19:20 +0000 Received: from thor (localhost [127.0.0.1]) by thor.apache.org (8.13.8+Sun/8.13.8) with ESMTP id o47HJ0ct028604 for ; Fri, 7 May 2010 17:19:00 GMT Date: Fri, 7 May 2010 13:19:00 -0400 (EDT) From: confluence@apache.org To: commits@directory.apache.org Message-ID: <27666347.2085.1273252740020.JavaMail.confluence@thor> Subject: [CONF] Apache Directory ASN.1 Documentation > ASN.1 MIME-Version: 1.0 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Auto-Submitted: auto-generated

ASN.1

Page edited by Emmanuel L=C3=A9charny


Changes (2)

=20 =20
...

h2. Implementations
Two Three codecs are currently available :
* [LdapCodec|LdapCodec] whic= h encodes and decodes LDAP messages
* [KerberosCodec|Kerberos] which encodes an decodes KERBEROS message= s
* [SpnegoCodec] which encode= s an decodes SPNEGO messages

Full Content

ASN.1 encoder/deco= der

Components

Communications between clients and server can be seen as a two ways / mu= lti layers system. The client submits a request to the server, whi= ch replies.

Layers are just used to facilitate the implementation of this c= ommunication. From the developer point of view, working on a specific level= , he just has to know the two layers above and under, but can be seen as a = communication at she same level between the client and the server. Here is = a view of these layers :

We have depicted three layers:

    =09
  • Request/Response: This is the more abstract layer. Exchanged message= s are 'human readable'. Each message is a Java Bean, containing all the inf= ormation about a Request or a Response.
  • =09
  • PDU: As communication petween the Client and the Server is done thro= ugh a network, we need to transform the beans to something more 'network fr= iendly'. The data are stored in PDU, or Protocol Data Unit. Those PDU contain an encoded form of messages, specified in RFC 2251 and ASN.1
  • =09
  • ByteBuffers: To trans= fer PDU from/to Client to/from Server, we need to store bytes in a structur= e that will permit to deal with network latency. Thus we are using byte buf= fers, which allow us to send pieces of PDU until the whole PDU has been tra= nsmitted. (Note : ByteBuffer= is also a Java NIO class, but can be seen just as a byte container. It cou= ld have been something totally different from the NIO class).

This layering allows many different implementations.

One can also imagine inter-layers used to trace debug informations.

Inter layer communication rely on a pipe-line: each layer push some piec= e of information to the next layer (up or down), and so on.

Each layer may implement its own strategy to fulfill the reception and t= ransmission of the data it is responsible of :

    =09
  • emission =09
      =09=09
    • asynchronous push
    • =09=09
    • synchronous push
    • =09=09
    • established and dedicated channel
    • =09=09
    • multiplexed channel
    • =09
    =09
  • =09
  • reception =09
      =09=09
    • listener
    • =09=09
    • established and dedicated channel
    • =09=09
    • multiplexed channel
    • =09
    =09

POJOs

POJOs are Java classes that contain high level informations.

A client create an instance of a class to communicate with the = server, which create an other one to reply. They implement a kind of ap= plication layer between clients and server.

Ideally, they are generated by an ASN.1 compiler, but can be hand= crafted.

PDUs/TLVs

PDU stands for Protocol Data Unit. An ASN.1 encoded= element is stored in a PDU. This is what is transfered between a client an= d a server.

TLV stands for Type/Length/Value. A PDU is made of TLV s. = Each TLV represent either a primitive element, and it has a V= alue, or a constructed element, and the Value is itself one ore more= TLV (The V can contain more than one TLV). The PDU= structure is like a tree, where the PDU is the whole tree, and = where TLV are leaves (primitives) and branches (constructed)

Further information about TLVs can be found here :

ByteBuffer

Buffering the incoming request or the ourgoing response is essential. As= a request or a response can be huge (for example, if we want to store imag= es), it is necessary to store bytes in buffers in order to be able to pipel= ine the processing. Flushing informations byte by byte is totally insane, f= rom the network point of view.

We are using the NIO B= yteBuffer structure to store chunks of information, before pushing them= on the network, and reversly, store incoming bytes into buffers before pro= cessing the request.

Compiler

TO BE DONE ...

Processing

There are two kind of processing: encoding and decoding. E= ncoding is quite easy, decoding is much more complicated.

3D""Important
Important : de= coding an ASN.1 PDU is generally not possible if you have no knowledge of t= he grammar being decoded. To limit the size of PDUs, the encoding schemes u= sed (PER, DER, BER, ...) permits the elimination of some TL if the construc= ted TLV that encapsulate the previous one is unambiguiously known. One who = want to decode a PDU MUST know which grammar has been used.

Encoder

The encoding process is quite easy. As we know what has to be encoded, t= he structure of the PDU is somehow dependent on the structure of the POJO w= hich contains the data. The only tricky things is the Length part, w= hich has to be computed. As a TLV may have a V part which is = itself one or more TLV s, its L part will be the sum of each = included TLV s length. This is typically a recursive processing, but= we can also process the POJO in two passes :

    =09
  • the first pass compute each length
  • =09
  • the second pass generate the PDU

The DIRxSBOX:Encoding Asn.1= page gives informations about the encoding process.

Decoder

The decoding process is a loop which reads PDUs and constructs objects o= n the fly. It can stop and restart without loosing information, as PDU may = be very long (it also means that we must store a current state for each dec= oding).

The DIRxSBOX:Decoding Asn.1= page gives informations about the encoding process.

Performance

TODO : performance against memory/scalability/failover
TODO : which kind of performance should we deliver? Maximum throughput =3D = bandwith/average PDU size. For instance, with a 1Gb network connection, ass= uming that we have an average PDU size of 100 bytes, the system must delive= r 1 M Pdu/s to saturate the network.

Actually, the new decoder eats 110 000 BindRequest PDU or 37 000 Sea= rchResultEntry PDU per second on my 2.8Ghz computer, but we have to take in= to account the works that must be done aside.

Implementations

Three codecs are currently available :

    =09
  • LdapCodec which encodes and decodes LDAP messages
  • =09
  • KerberosCodec which encodes an decodes KERBEROS messages
  • =09
  • SpnegoCodec which encodes an decodes SPNEGO messages