Tuesday, May 5, 2015

Designing of SMS protocol : Working all the C learnings in one small project : Part 1

Well we have seen the important things necessary to write code in C.

I was thinking , how about writing SMS protocol code in C.  But not able to find where i will use this .

But in one of HINDU great books "GITA" ,god has said that not think about the fruit but do the work.
So I will try to see how much I can code it .

One use case which I was thinking and interested in is IoT or connecting devices. Suppose I have two devices and need to pass data between them .


So I will use modified SMS protocol to communicate between devices. But where I get stopped is
AS layers ( Access Stratum in terms of 3gpp ) and (phy and data link layer in TCP/IP).

Since for any protocol to be optmized , what is needed how the data actually get pass.
If I uses TCP/IP stack to pass data , then there are already lots of APP protocol to do the job.

But lets do the code , lets not worry about what will happen.


So how will our modified SMS protocol will work. First let see how currently SMS protocol works.

When we sent some message from our device , it goes to Network node knows as MSC. It will acknowledge that message, if something wrong with message, it will send error.

Then MSC itself forwards message to other network node SMC . This is where Messages are stored.
It will also acknowledge the message. Once device get acknowledge from SMC , then only it knows message is success.


Again at the receiver side, SMC sends message to MSC, waits for the ack. MSC will send message to receiver device and wait for ack. Here receiver will send two ack , one for MSC and one for SMC.
Both will pass thru the MSC.



So we can use this where we have 3 set of devices.  one set of devices are user devices. Other are routers. and then third set is master device.

Maybe we can also trim this down, remove the MSC layer, and use in ROBOTICS.

The layer between device and MSC is known as CP layer and between devices and SMC is RP layer.


1) State Machine and Messages ( later see the contents of Message)

Sender will be referred as MO(Message Originator)  and Receiver as MR ( Message Receiver).

The first set of machines (ROUTERS) will be Router Layer machines(RLM), the last set of machines will be MLM( Master Layer machines).

The layer between MO/MR  and RLM will be  RL. Layer between MO/MR and MLM will be ML






As per above diagram , when MO sends message following will be state at different Layers and machines.

1.

 
After sending message, MO-ML layer will change from IDLE to  WAIT-FOR-MLACK.
Start timer  TMO-ML1 .

AT MO-RL , state will change from IDLE to WAIT-FOR-RLACK.
Start timer TMO-RL1.

Note , TMO-ML1 value should be such that it accounts for TMO-RL1 time and any retry at RL layer.

2a.

 RLM will forward message to MLM and will not for any ACK. Any failure in between will be taken care by the MO device retry.


2b.
 RLM will send back ACK to MO.
 MO will stop its TMO-RL1 timer.  and move back to IDLE state.  TMO-ML1 will be running and it will remain in WAIT-FOR-MLACK.


3.

RLM will send MLM ACK to MO, via RLM
MO will then stop its timer.


Also  below are messages which will be exchanged between all machines .

1.

MO -------->RLM ( MORL-DATA)  // Note this RL-DATA will encapsulate MOML-DATA.

The use will be even though RLM is very thin layer, we can have some intelligence in that to check for RL_DATA fields and if suspect some error based on our use cases, can send by ERROR to MO.

2a

RLM------>ML-DATA  (RLML-DATA) // This will have the MOML-DATA which MO has sent.

Plus we can some extra information in RLML-DATA fields.

2b

RLM----->;MO    //  MORL-ACK   or MORL-ERROR


3)

MLM---->RLM ---->MO   // RLML-ACK ( It will have MOML-ACK).



I will try to make Message Flow Diagram and upload the document for easy understanding.

Further what we learn is how to make  MAKE FILE,  rather than manually compiling each file and then linking them ...which will be very tedious, we will make a MAKE FILE, which will do our job of compiling.

And if I liked the code I have written, possibly I will upload that one on GIT HUB and give a short tutorial on using GIT.


No comments:

Post a Comment