itevad – How to write your own protocol and its stack – part 1

From this post, as well as the following 4~6 posts, I will try to illustrate how to write your own protocol and its stack, step by step. You will learn all the related stuffs to write a carrier grade telecommunication protocol called ‘Itevad’ supporting both binary and text encoding/decoding. All the code could be found in repository of github called ‘itevad’. Have fun:)
Project Name: itevad
Destination: Itevad Protocol Design and Stack Implementation
Language: ASN.1, BNF, ABNF, Flex, Bison, C
Project Web: http://github.com/daveti/itevad
Git Read Only: https://github.com/daveti/itevad.git
Part 1 – General background

1. Carrier grade telecommunication protocol
A carrier grade telecommunication protocol usually supports both binary and text encoding/decoding with high performance. Binary format is hard to read manually but saving network traffic, while text format has the other side of the story. For binary format, performance mostly relies on TLV (tag, length, value) analysis. However, to achieve high performance, text format needs the help of flex and bison, especially when the protocol itself is complicated and even may be impossible to do pure string parsing.
2. ASN.1 and asn1c
For binary format, if we do not care about the detailed mapping between different tags and possible length and value, which means we focus on translating the protocol itself into binary format rather than encoding and decoding, then you have to know ASN.1. ASN.1 is a standard language used to describe the protocol with structure style.  In the following post, we will see how Itevad protocol looks like when it is written in ANS.1. Once we have the ASN.1 description, we could use any ANS.1 compiler to generate all the source code needed to encode and decode binary formatted protocol. asn1c is an open source ANS.1 compiler written by Lev Walkin and also the one we are using for Itevad.
NOTE: For detailed info about ASN.1 and ans1c, please refer to the link category for ‘H.248’ and ‘Compiler’ on your right side. ‘EGCP’ (a H.248 like protocol from Genband) may be the case where ANS.1 could not help.
3. BNF and ABNF
BNF is a metalanguage used to describe the grammar of certain language. As you could imagine, BNF is used to describe programming languages and telecommunication protocols. ABNF is an Augmented BNF with its own syntax and rules. Communication protocols from IETF and ITU-T are mostly have ABNF description if they support text format, like H.248.1. In my opinion, BNF/ABNF gives the guideline on how to write a flex/bison stack for text decoding.
4. Flex
As its ancestor lex, Flex is a fast lexer used to do lexical analysis, which is usually the front-end part of a compiler. The main job for Flex is to scan the text context and recognize certain pattern as a ‘token’. That is why Flex is also called tokenizer sometime. All detailed Flex info could be found under stuff of ‘Compiler’ at your right side.
5. Bison
As its ancestor yacc, Bison is a parser used to do syntax analysis, whose input is usually from output of Flex in a compiler system. The main job for Bison is to scan the text context to determine ‘meaning’ of the whole passage with the input of each ‘token’ from Flex. All detailed Bison info could be found under stuff of ‘Compiler’ at your right side.
6. Itevad
Itevad Protocol, which we will design and implement its stack step by step later, is a carrier grade telecommunication protocol supporting both binary and text encoding/decoding. As kind of difficult to show the binary msg of this protocol, here lists the text msg examples for a general view:
/* Message examples for Text ItevadProtocol */
[root@localhost ItevadBin]# cat itevad_text_msg.example
Itevad/1 [31.31.31.31]:7777
Transaction = 1 {
 Ask = "who r you?"
}

Itevad/2 [11.11.11.11]:6666
Reply = 1 {
 Answer = "i am itevad"
}
[root@localhost ItevadBin]#

About daveti

Interested in kernel hacking, compilers, machine learning and guitars.
This entry was posted in Dave's Tools, H.248/MEGACO/EGCP, Programming, Stuff about Compiler and tagged , , , , , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s