Friday 24 April 2020

SMPP Protocol

What is SMPP (Short Message Peer –To-Peer)  :

SMPP is an application layer protocol. It follows client-server architect and act as interface between client and server host in more secure manner. The protocol is based on pairs of request and response exchanges using TCP connection (OSI layer terminology). 

Purpose of SMPP :

         SMPP is mostly used in telecommunication domain for exchanging SMS between two host systems. Now, you may be thinking what those two hosts are. Those are called as SMSC (Short Message Service Centers) and ESMSC (Extended or External or Entity Short Message Service Centers).  SMPP consists no of number PDU to carries short messages (includes normal SMS, WAP push-pull messages, voicemail notifications, EMS, USSD messages and others) and status of carried short messages (such as delivery status reports, Enquiry connection status between SMSC and ESMSC). The new version of SMPP PDU has been developed for interacting with billing systems about subscriber’s billing requests and responses.

PDU (Packet Data Unit) :

PDU is a SMPP packet which carries information in encoded format. It consists two parts,
·         Header
·         Body

Header :

Used to identify about what kind of PDU such as SMS submit or delivery report or connection status report or connection request or connection response and others

Body :

It contains the original information that has to request server or response to client.

PDU Format :



Types of PDUs :

·         Bind_transmitter (Tx)
·         Bind_transceiver (TRx)
·         Bind_receiver (Rx)
·         unbind
·         Data_sm
·         Submit_sm
·         Submit_muti
·         Submit_sm_resp
·         Deliver_sm
·         Deliver_sm_resp
·         Replace_sm
·         Auth_acc
·         Auth_acc_resp

Versions :

·         SMPP 3.3
·         SMPP 3.4
·         SMPP 4.0
·         SMPP 5.0

Network Flow :

SMPP PDU


I think you know about what is SMPP, Purpose of SMPP and what are the various PDU available. If not, You can refer my previous post to get an idea about it. Now, I am going about explain Bind PDU or SMPP session establishing PDU. Okay lets start....,


SMPP Bind or Session Management PDU :


Bind PDU is the initial one, Which is sent by ESME to SMSC through established network connection for creating SMPP session between ESME and SMSC.
Once, Connection request received from ESME, SMSC validates such as ESME is authorized access SMSC or not. If authorized, SMSC sends success response to ESME and establishes the SMPP session for further communication. If not authorized, SMSC sends failure response and discard the established network connection between SMSC and ESME.


Types of Session Management PDU :
  • Bind Trasmitter
  • Bind Receiver
  • Bind Transceiver

Bind Transmitter : (Half duplex)


A connected ESME sends transmitter bind request (using bind_transmitter PDU) to SMSC and receives response from SMSC for sent transmitter bind request. As I said early, Response can be success or failed. In success case, ESME transmitter can send short message (SMS) to SMSC and gets response for sent SMS from SMSC. ESME transmitter can send short message using submit_sm or replace_sm or query_sm PDU to SMSC. In failed case, SMSC closes the connection and will not allow communicating further.





Bind Receiver : (Haf duplex)


A connected ESME sends receiver bind request (using bind_receiver PDU) to SMSC and receives response from SMSC for sent receiver bind request. In success response, ESME receiver can receive PDU from SMSC such as deliver_sm or short messages (If SMSC needs to send SMS ESME). In failed response, SMSC closes the connection and will not allow communicating further.



Bind Transceiver : (Full duplex)


A connected ESME sends transceiver bind request (using bind_transceiver PDU) to SMSC and receives response from SMSC for sent transceiver bind request. In success response, ESME has access for send to SMSC and receive from SMSC on same connection. Such as submit_sm, deliver_sm, replace_sm, query_sm and others.


Parameters of Session PDU :


Header : Fixed for all SMPP PDUs


  • command_length
  • command_id
  • command_status
  • sequence_number
command_length :


It defines total length of the PDU packet including length field. The command_legth is type of integer and size is 4 octets. In this case, Overall length of bind_trasmitter or bind_receiver or bind_transceiver PDU.


command_id :
It is used to identify the what kind of SMPP PDU packet such as bind_transmitter, bind_receiver, bind_transceiver, bind_transmitter_resp, bind_receiver_resp, bind_transceiver_resp. The command_id is type of integer and size is 4 octets.


command_status :


It indicates the success or failure of sent SMPP request PDU. It is applicable for SMPP response PDU and It has to be NULL for SMPP request PDU. The command_status is type of integer and size is 4 octets.


sequence_number :


The sequence number contains unique transaction id and It is common factor in both request and response PDU of same transactions. The sequence_number field is generates by requester (request PDU) and response will be sent with same sequence_number from response (response PDU). Integer type and size is 4 octets.


Body :


Body contains mandatory and optional parameters and each PDU's body parameters may be different. Now, I am listing bind PDU's body parameters.
  • system_id
  • password
  • system_type
  • interface_version
  • addr_ton
  • addr_npi
  • address_range

system_id :


It allows SMSC to identify ESMS's system id and It is unique. Usally system_id generated by SMSC and provided to ESME for ensuring that the ESME is authorized to access SMSC. The system_id is type of C-style characters and size can be variable but max allowed upto 16 characters.


password :


Each system id has own password and It is used by SMSC to authenticate ESME bind request. The password is type of C-style characters and size can be variable but mac allowed upto 9 characters.

system_type :


To identify about bind requested ESME system such as what kind of system and purpose of system. The system_type is type of C-style character and max size can be 13 characters.


interface_version :
In denotes SMPP protocol version used by ESME such as 3.3 or 3.4 or 4.0 or 5.0. The interface_type is type of integer and size is 1 octet.


addr_ton :


Indicates Type of Number of ESME address and If not known can set as 0. Integer type and size is 1 octet.


addr_npi :


Indicates Numbering Plan Indicator of EMSE address and If unknown , Set as 0. Integer type and size is 1 octet.


address_range :


It contains ESME address, If not known set as NULL. Type of C-style character and max size allowed is 41 characters.


Example packet format :

00 00 00 2F 00 00 00 09 00 00 00 00 00 00 00 00 01 62 75 6c 6b 73 6d 73 00 62 75 6c 6b 31 32 33 00 53 4d 50 50 00 03 01 01 00


Header :


00 00 00 2F command_length 0x0000002F
00 00 00 09 command_id 0x00000009 (bind_transceiver)
00 00 00 00 command_status 0x00000000 (Usally request PDU contains 0)
00 00 00 01 sequence_number 0x00000001 (Unique number to identify)


Body :


62 75 6c 6b 73 6d 73 00 system_id bulksms padded with 0
62 75 6c 6b 31 32 33 00 password bulk123 padded with 0
53 4d 50 50 00 system_type SMPP padded with 0
03 interface_version 3
01 addr_ton 1
01 addr_npi 1
00 address_range 0

Response PDU for Bind request PDU :


Each bind request has it's own response PDU, Which is sentd by SMSC to ESME. All the bind response PDU has same structure and parameters in header and body portion.  Find the below list of response PDU,
  • bind_transmitter_resp
  • bind_receiver_resp
  • bind_transceiver_resp

Header parameters:
  • command_length
  • command_id
  • command_status
  • sequence_number

Body parameter :

system_id :


You can refer meaning of all parameter on above, Which i have mentioned in Request PDU of bind request.


Important note : The body portion of SMPP bind response PDU is not returned if the command_status parameter contains a non zero value. If there is any error in request PDU formation, SMSC will response with corresponding SMPP error code.

Example PDU for response :


00 00 00 2D 08 00 00 09 00 00 00 00 01 00 00 00 01 62 75 6c 6b 73 6d 73 00


Header :


00 00 00 2D command_length 0x0000002D
08 00 00 09 command_id 0x80000009 (bind_transceiver_resp)
00 00 00 01 command_status 0x00000001
00 00 00 01 sequence_number 0x00000001 (Unique number to identify)


Body :

62 75 6c 6b 73 6d 73 00 system_id bulksms


Wednesday 15 October 2014

Android Architecture



Google Android Architecture

Android operating system is a stack of software components which is roughly divided into five sections and four main layers as shown below in the architecture diagram.

Android Architecture

Linux kernel

At the bottom of the layers is Linux - Linux 2.6 with approximately 115 patches. This provides basic system functionality like process management, memory management, device management like camera, keypad, display etc. Also, the kernel handles all the things that Linux is really good at such as networking and a vast array of device drivers, which take the pain out of interfacing to peripheral hardware.

Google usually refers to the Android OS as a software stack. Each layer of the stack groups together several programs that support specific operating system functions.

The base of the stack is the kernel. Google used the Linux version 2.6 OS to build Android's kernel, which includes Android's memory management programs, security settings, power management software and several hardware drivers. Drivers are programs that control hardware devices. For example, the Nexus One has a camera. The Android kernel includes a camera driver, which allows the user to send commands to the camera hardware.

Libraries

On top of Linux kernel there is a set of libraries including open-source Web browser engine WebKit, well known library libc, SQLite database which is a useful repository for storage and sharing of application data, libraries to play and record audio and video, SSL libraries responsible for Internet security etc.

You can think of libraries as a set of instructions that tell the device how to handle different kinds of data. For example, the media framework library supports playback and recording of various audio, video and picture formats. Other libraries include a three-dimensional acceleration library (for devices with accelerometers) and a Web browser library.

Some of the important native libraries include the following:
Surface Manager: It is used for compositing window manager with off-screen buffering. Off-screen buffering means you cant directly draw into the screen, but your drawings go to the off-screen buffer. There it is combined with other drawings and form the final screen the user will see. This off screen buffer is the reason behind the transparency of windows.
Media framework: Media framework provides different media codecs allowing the recording and playback of different media formats
SQLite: SQLite is the database engine used in android for data storage purposes
WebKit: It is the browser engine used to display HTML content
OpenGL: Used to render 2D or 3D graphics content to the screen

Android Runtime

This is the third section of the architecture and available on the second layer from the bottom. This section provides a key component called Dalvik Virtual Machine which is a kind of Java Virtual Machine specially designed and optimized for Android.
The Dalvik VM makes use of Linux core features like memory management and multi-threading, which is intrinsic in the Java language. The Dalvik VM enables every Android application to run in its own process, with its own instance of the Dalvik virtual machine.
The Android runtime also provides a set of core libraries which enable Android application developers to write Android applications using standard Java programming language.

Located on the same level as the libraries layer, the Android runtime layer includes a set of core Java libraries -- Android application programmers build their apps using the Java programming language. It also includes the Dalvik Virtual Machine.

A virtual machine is a software application that behaves as if it were an independent device with its own operating system. You can run a virtual machine on a computer that operates on a completely different OS than the physical machine's OS. The Android OS uses virtual machines to run each application as its own process. That's important for a few reasons. First, no application is dependent upon another. Second, if an application crashes, it shouldn't affect any other applications running on the device. Third, it simplifies memory management.

Application Framework

The Application Framework layer provides many higher-level services to applications in the form of Java classes. Application developers are allowed to make use of these services in their applications.

This includes the programs that manage the phone's basic functions like resource allocation, telephone applications, switching between processes or programs and keeping track of the phone's physical location. Application developers have full access to Android's application framework. This allows them to take advantage of Android's processing capabilities and support features when building an Android application. Think of the application framework as a set of basic tools with which a developer can build much more complex tools.

Important blocks of Application framework are:
Activity Manager: Manages the activity life cycle of applications
Content Providers: Manage the data sharing between applications
Telephony Manager: Manages all voice calls. We use telephony manager if we want to access voice calls in our application.
Location Manager: Location management, using GPS or cell tower
Resource Manager: Manage the various types of resources we use in our Application

Applications

You will find all the Android application at the top layer. You will write your application to be installed on this layer only. Examples of such applications are Contacts Books, Browser, Games etc.

This is where you find the basic functions of the device such as making phone calls, accessing the Web browser and accessing your contacts list. If you're an average user, this is the layer you'll use most. You do that with the user interface. Only Google programmers, application developers and hardware manufacturers access the other layers further down the stack.

  • SMS client app
  • Dialer
  • Web browser
  • Contact manager

Friday 26 April 2013

SIP (Session Initiation Protocol)

The Session Initiation Protocol (SIP) allows phone calls and similar communication sessions to be made over the Internet, private data networks, or cellular networks. It defines the messages that are sent between parties (signaling) which govern establishment, termination, and other essential elements of a call (or, more generally, a session, hence the name).

SIP is an IETF-defined signaling protocol and is widely used for controlling communication sessions such as voice and video calls over Internet Protocol (IP). The protocol can be used for creating, modifying and terminating two-party (unicast) or multiparty (multicast) sessions. Sessions may consist of one or several media streams, such as voice or video data.

Other SIP applications include video conferencing, streaming multimedia distribution, instant messaging, presence information, file transfer and online games.

SIP is an application layer protocol designed to be independent of the underlying transport layer; it can run on Transmission Control Protocol (TCP), User Datagram Protocol (UDP), or Stream Control Transmission Protocol (SCTP). It is a text-based protocol, incorporating many elements of the Hypertext Transfer Protocol (HTTP) and the Simple Mail Transfer Protocol (SMTP).

Monday 25 March 2013

networking commands in linux/unix

Networking Commands Example in Unix and Linux 

These are most useful commands in my list while working on Linux server , this enables you to quickly troubleshoot connection issues e.g. whether other system is connected or not , whether other host is responding or not and while working for FIX connectivity for advanced trading system this tools saves quite a lot of time .

• finding host/domain name and IP address - hostname
• test network connection – ping
• getting network configuration – ifconfig
• Network connections, routing tables, interface statistics – netstat
• query DNS lookup name – nslookup
• communicate with other hostname – telnet
• outing steps that packets take to get to network host – traceroute
• view user informationfinger
• checking status of destination host - telnet



Example of Networking commands in Unix

let's see some example of various networking command in Unix and Linux. Some of them are quite basic  e.g. ping and telnet and some are more powerful e.g. nslookup and netstat. When you used these commands in combination of find and grep you can get anything you are looking for e.g. hostname, connection end points, connection status etc.


hostname

hostname with no options displays the machines host name
hostname –d displays the domain name the machine belongs to
hostname –f displays the fully qualified host and domain name
hostname –i displays the IP address for the current machine


ping
It sends packets of information to the user-defined source. If the packets are received, the destination device sends packets back. Ping can be used for two purposes

1. To ensure that a network connection can be established.
2. Timing information as to the speed of the connection.

If you do ping www.yahoo.com it will display its IP address. Use ctrl+C to stop the test.

ifconfig
View network configuration, it displays the current network adapter configuration. It is handy to determine if you are getting transmit (TX) or receive (RX) errors.


netstat
Most useful and very versatile for finding connection to and from the host. You can find out all the multicast groups (network) subscribed by this host by issuing "netstat -g"

netstat -nap | grep port will display process id of application which is using that port
netstat -a  or netstat –all will display all connections including TCP  and UDP
netstat --tcp  or netstat –t will display only TCP  connection
netstat --udp or netstat –u will display only UDP  connection
netstat -g will display all multicast network subscribed by this host.

nslookup
If you know the IP address it will display hostname. To find all the IP addresses for a given domain name, the command nslookup is used. You must have a connection to the internet for this utility to be useful.
E.g. nslookup blogger.com

You can also use nslookup to convert hostname to IP Address and from IP Address from hostname.

traceroute
A handy utility to view the number of hops and response time to get to a remote system or web site is traceroute. Again you need an internet connection to make use of this tool.


finger
View user information, displays a user’s login name, real name, terminal name and write status. this is pretty old unix command and rarely used now days.

telnet
Connects destination host via telnet protocol, if telnet connection establish on any port means connectivity between two hosts is working fine.
telnet hostname port   will telnet hostname with the port specified. Normally it is used to see whether host is alive and network connection is fine or not.



whois

This command allows you to check the Internic database for proper hostnames. This is very handy when you are trying to trace back an IP address to a specific hostname, or the reverse. I often use it when troubleshooting connectivity between hosts and checking whether the problem is a host configuration error or an actual physical connectivity error. The most commonly used version of the command is: 

whois -f 10.1.1.1
(replace the 10.1.1.1 with a specific server IP) 

The -f option forces the command to skip any cache that may have stored the host state, and instead goes to the actual server to perform a lookup and verify its hostname.
Another useful variation of the command, especially for trying to identify port problems is:

whois --port=8102 10.1.1.1
This command forces a test on the specific host's port 8102. You can benefit from force checking specific ports in many ways, and I highly recommend testing ports with this technique.


findsmb
       findsmb is used to list info about machines that respond to SMB name queries (for example windows based machines sharing their hard disk's).
    Command syntax:

       

     findsmb 
     
    This would find all machines possible, you may need to specify a particular subnet to query those machines only...

I. How Routing is Done? 

Route command is used to show/manipulate the IP routing table. It is primarily used to setup static routes to specific host or networks via an interface.

In this article we will see how to manipulate the routing tables in Linux using route command.
We’ll first explain how routing is done with some basic route command examples, and then we’ll explain using a sample network architecture about how to setup routes in your network.

I. How Routing is Done?

1. Display Existing Routes

route command by default will show the details of the kernel routing table entries. In this example, the ip-address of the system where the route command is being executed is 192.168.1.157

$ route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.1.0     *               255.255.255.0   U     0      0        0 eth0
 
The above command shows that if the destination is within the network range 192.168.1.0 – 192.168.1.255, then the gateway is *, which is 0.0.0.0.
When packets are sent within this IP range, then the MAC address of the destination is found through ARP Protocol and the packet will be sent to the MAC address.

If you don’t know what ARP is, you should first understand how ARP protocol works.
In order to send packets to destination which is not within this ip range, the packets will be forwarded to a default gateway, which decides further routing for that packet. We will see this shortly.
By default route command displays the host name in its output. We can request it to display the numerical IP address using -n option as shown below.

$ route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.1.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0
0.0.0.0         192.168.1.10    0.0.0.0         UG    0      0        0 eth0

2. Adding a Default Gateway

We can specify that the packets that are not within the network has to be forwarded to a Gateway address.
The following route add command will set the default gateway as 192.168.1.10.

$ route add default gw 192.168.1.10
 
Now the route command will display the following entries.

$ route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.1.0     *               255.255.255.0   U     0      0        0 eth0
default         gateway.co.in   0.0.0.0         UG    0      0        0 eth0
 
Now we have just added a default gateway to our machine. To verify whether it is working properly, ping some external host (for example, google.com) to send ICMP packet.

$ ping www.google.com
 
The following is the sequences of evets that happens when the above ping command is executed.
  1. First it will query the DNS server to obtain the ip-address of google.com ( for example: 74.125.236.34 )
  2. The destination address ( 74.125.236.34 ) is not within the network range.
  3. So, in Layer-3 (IP header) the DESTINATION IP will be set as “74.125.236.34″.
  4. In Layer-2, the DESTINATION MAC address will be the filled in as the MAC address of the default gateway ( 192.168.1.10′s MAC ). The MAC will be found by using ARP as described earlier.
  5. When the packet is sent out, the network switch ( which works on Layer-2 ), send the packet to the default gateway since the destination MAC is that of the gateway.
  6. Once the gateway receives the packet, based on its routing table, it will forward the packets further.
The above 2 examples would have given a good idea about how routing is done within a network. Now we will see other command line options available with route command.

3. List Kernel’s Routing Cache Information

Kernel maintains the routing cache information to route the packets faster. We can list the kernel’s routing cache information by using the -C flag.

$ route -Cn
Kernel IP routing cache
Source          Destination     Gateway         Flags Metric Ref    Use Iface
192.168.1.157   192.168.1.51    192.168.1.51          0      0        1 eth0
192.168.1.157   74.125.236.69   192.168.1.10          0      0        0 eth0
.
.
.

4. Reject Routing to a Particular Host or Network

Sometimes we may want to reject routing the packets to a particular host/network. To do that, add the following entry.

$ route add -host 192.168.1.51 reject
 
As you see below, we cannot access that particular host (i.e .51 host that we just rejected).

$ ping 192.168.1.51
connect: Network is unreachable
 
However we can still access other hosts in the network (for example, .52 host is still accessible).

$ ping 192.168.1.53
PING 192.168.1.53 (192.168.1.53) 56(84) bytes of data.
64 bytes from 192.168.1.53: icmp_seq=1 ttl=64 time=7.77 ms
 
If you want to reject an entire network ( 192.168.1.1 – 192.168.1.255 ), then add the following entry.

$ route add -net 192.168.1.0 netmask 255.255.255.0 reject
 
Now, you cannot access any of the host in that network (for example: .51, .52, .53, etc.)

$ ping 192.168.1.51
connect: Network is unreachable

$ ping 192.168.1.52
connect: Network is unreachable

$ ping 192.168.1.53
connect: Network is unreachable

II. A Sample Network Architecture (to understand routing)

Let us use the following sample network architecture for the rest of the examples.
In the diagram below, we have 2 individual networks ( 192.168.1.0 and 192.168.3.0, with subnet mask of 255.255.255.0 ).
We also have a “GATEWAY” machine with 3 network cards. 1st card is connected to 192.168.1.0, 2nd card is connected to 192.168.3.0, and the 3rd card is connected to the external world.

5. Make 192.168.3.* Accessible from 192.168.1.*

Now we need to add a routing entry such that we are able to ping 192.168.3. series ip-addresses from 192.168.1. series. The common point we have is the GATEWAY machine.
So, on each machine in 192.168.1.* network a default gateway will be added as shown below.

$ route add default gw 192.168.1.10
 
Now when 192.168.1.1 pings 192.168.3.1, it will go to the GATEWAY via 192.168.1.10.
In GATEWAY, add the following routing entry.

$ route add -net 192.168.3.0 netmask 255.255.255.0 gw 192.168.3.10
 
Now all the packets addressed to 192.168.3.* network will be forwarded via the 192.168.3.10 interface, which then delivers the packets to the addressed machine.

6. Make 192.168.1.* Accessible from 192.168.3.*

It is very similar to what we did earlier.
So, on each machine in 192.168.3.* network a default gateway will be added as shown below.

$ route add default gw 192.168.3.10
 
In GATEWAY, add the following routing entry.

$ route add -net 192.168.1.0 netmask 255.255.255.0 gw 192.168.1.10
 
Now 192.168.3.* machines can ping 192.168.1.* machines.

7. Allow Internet Access ( External World )

In the previous two example, we have interconnected the 2 different networks.
Now we need to access the internet from these 2 different networks. For that, we can add a default routing ( when no routing rule matches ) to the 125.250.60.59 which is connected to the external world as follows.

$ route add default gw 125.250.60.59
 
This is how it works:
  1. Now when you try to access the internet (for example: ping google.com) from any of these machines (for example, from 192.168.3.2), the following is the sequence of events that happens.
  2. Since the destination (google.com) is not within 3.* series, it will be forwarded to GATEWAY via 3.10 interface
  3. In GATEWAY, it checks whether the destination is within 1.* range. In this example, it is not.
  4. It then checks whether the destination is within 2.* range. IN this example, it is not
  5. Finally, it takes the default route to forward the packets (i.e using the 125.250.60.59 interface, which is connected to the external world). 

Start and Stop the Network Interface Card 


The ifconfig command can be used to start and stop network interface cards:
# ifconfig eth0 up
# ifconfig eth0 down
 
The ifup & ifdown command can also be used to start and stop network interface cards:
# ifup eth0
# ifdown eth0
 
The systemctl commands can also be used to enable, start, stop, restart and check the status of the network interface services -

# systemctl enable network.service
# systemctl start network.service
# systemctl stop network.service
# systemctl restart network.service
# systemctl status network.service

Displaying and Changing your System's Hostname

The command hostname displays the current hostname of the computer, which is 'Gateway':

# hostnameGateway

You can change the hostname by giving the new name at the end of the command -

# hostname Firewall-cx
 
This will change to the new hostname once you have logged out and logged in again. In fact, for any change in the interfaces, the change is implemented only after the user logs in the next time after a log-out.