Sunday, January 26, 2014

Battle of sorting algorithms (Which sorting algorithm is the best?)

I was recently going through MIT Opencourseware's Algorithms course by professor Erik Demaine and Charles Leiserson (fantastic teaching by the way!). After finishing up the lectures on sorting and worse case linear order statistics, an innocent question to ask is "Which sorting algorithm is best?". Mind you, the lectures are exhaustive and walk you through the running time of almost all discussed algorithms. But there are constraints and involvement of constants which hinder the practical applicability of these algorithms. In this post, i wish to delineate the algorithm selection mystery assuming you are sorting numbers. (You can extend the below mentioned analysis for floating points, strings and so on).

Algorithms based on comparing a pair of numbers and minimizing the number of comparisons have a tight lower bound of (n log n). This means that nlogn is the worst case runtime of the best comparison based sorting algorithm. And the best algorithm, in practice, is randomized quick sort.The advantage of randomized quick sort is that it avoids the worst case of quick sort (which might take upto O(n^2) time for selected inputs such as sorted or a reverse sorted array).

So, is randomized quick sort the answer to all problems?

As the lecture demonstrates, we can sort in linear time too. With algorithms such as counting sort and radix sort, it is quite possible to get a upper bound of O(n), where n is the number of elements to be sorted. These algorithms do not fall under the comparison based model.

So, are counting sort and radix sort the answer to all problems?

Not quite. Each of them is useful in their own way. For example, after going through the rigorous analysis presented in the lecture, i've come up with a criteria of when to use each of them:

1) Counting sort (Stable): Use it when

     i) You know the maximum number in the elements to be sorted.
     ii) All numbers are integers
     iii) You can afford to allocate two auxiliary storages of size equal to the number of elements.
     iv) The numbers themselves are not very large (perhaps less than 10,000). This limit can be increased if you can write a multi-threaded version of counting sort where you sort the numbers in parallel.

2) Radix sort (MSD implementations can be stable): Use it when

     i)  You know the range of numbers to be sorted
     ii) Elements to be sorted consists of only integers, fixed size strings or anything which can be converted to a fixed size integer.
     iii) The number of digits in each integer is less than log n where base of the log is the base of the number to be sorted. For example, if we desire to sort 10^6 integers which are all in base 10, then we'll check if log 10^6 base 10 is less than the number of digits in each integer. If yes, we'll go ahead with the sort. The logic of this check is explained in the lecture found here.

3) Randomized quick sort: Use it when

     i) When 1) and 2) cannot be applied.
     ii) You want to your algorithm to work well with cache.
Technorati Tags: MIT, algorithms, sorting, counting-sort, radix-sort, best-sorting-algorithm, quick-sort, randomized-quick-sort

Sunday, May 12, 2013

Clarification on SIGKILL, SIGTERM, SIGINT, SIGQUIT, SIGSTP and SIGHUP

A few days ago, i landed upon unix signals that lead to process termination. I guess i was trying to remember the signals generated in linux when one presses Ctrl+Z and Ctrl+C. Memory did not serve me at that moment and i decided to look these up, one more time. I realized that having a consolidated book which explains these terms clearly is better than searching loads of webpages. I did the later since i had kept my unix os book away from my reach.To my disappointment, there was no single link that listed out all differences in an orderly fashion.

Hence, in this post, i wish to delineate these terms by consolidating my findings from stackoverflow, wikipedia and other unix internals websites. Here it goes:

SIGKILL: Terminates a process immediately. This signal cannot be handled (caught), ignored or blocked. (The "kill -9" command in linux generates the same signal).

SIGTERM: Terminates a process immediately. However, this signal can be handled, ignored or caught in code. If the signal is not caught by a process, the process is killed. Also, this is used for graceful termination of a process. (The "kill" command in linux if specified without any signal number like -9, will send SIGTERM)

SIGINT: Interrupts a process. (The default action is to terminate gracefully). This too, like, SIGTERM can be handled, ignored or caught. The difference between SIGINT and SIGTERM is that the former can be sent from a terminal as input characters. This is the signal generated when a user presses Ctrl+C. (Sidenote: Ctrl+C denotes EOT(End of Transmission) for (say) a network stream)

SIGQUIT: Terminates a process. This is different from both SIGKILL and SIGTERM in the sense that it generates a core dump of the process and also cleans up resources held up by a process. Like SIGINT, this can also be sent from the terminal as input characters. It can be handled, ignored or caught in code. This is the signal generated when a user presses Ctrl+\.

SIGSTP: Suspends a process. This too, can be handled, ignored or blocked. Since it does not terminate the process, the process can be resumed by sending a SIGCONT signal. This signal can be generated by pressing Ctrl+Z. (Sidenote: Ctrl+Z stands for substitute character which indicates End-of-File in DOS)

SIGHUP: (From Wikipedia): Hangs up a process when the controlling terminal is disconnected. This especially relates to modem/dial in connections. A process has to explicitly handle this signal for it to work. A good use is to "poke" a process and letting the process (as defined by the programmer) decide what to do with the signal is described here. Hence, SIGHUP can be handled, ignored or caught. This is the signal generated when a user presses Ctrl+D.

Technorati Tags: unix, signals, Unix-signals, SIGINT, SIGTERM, SIGKILL SIGQUIT, SIGSTP, SIGHUP

Monday, April 29, 2013

Designing a good security policy for your websites

Recently, i went through web server security and security analysis of forums based on phpBB. Although i do agree that humans are the weakest link in the security chain, there are a few measures a web developer can take to prevent malicious users from exploiting their website.

1) The login page (or any other page that requires authentication) should use HTTPS. The best approach is to use HTTPS throughout your website.

2) Set secure cookies and check them on each request from the user. This goes hand in hand with step 1.

3) Limit the maximum number of login attempts (say 5). Also, use techniques like exponential delay at each failed login attempt.

4) Deploy captcha verification on pages that require authentication (probably couple the captcha with the login page). Captcha should be account based rather than IP based (doing so prevents DDOS attacks since step 3 should stop login attempts after a few incorrect tries regardless of the IP used to log into the account)

5) After the maximum number of invalid login attempts have been reached, a web developer can go with two approaches.
     i) Deactivate the account and send password reset link at the user's registered email.
                                                                      OR
    ii)  Throw up a security question (entered earlier by the user) and follow the deactivation step if this too fails.

6) Set a password complexity policy (make digits, mixed alphabets and special characters mandatory along with a minimum password length)

7) Change the session ID on each request (for websites that require extra-security). Also, make sure that the session ID or any other session information is not a part of the query string (this will not be much of a problem if HTTPS is used throughout the website)

8) Force logout after a fixed period of inactivity.

9) Make extra authentication checks for administrator logins.

10) Never trust user input. Always validate it.

11) Maintain a blacklist (or whitelist) of users (IP based or whatever suits you best) to block malicious users who try to attack your website. It's not recommended to block them forever.

12) Understand and write your robots.txt with diligence.

13) Use vulnerability scanners to scan your website for security loopholes. Some good ones are jsky, acunetix and w3af. Fix the issues these scanners list and re-scan to confirm from various other scanners.

 14) Take regular backups of your website. In case of a security incident, the migration to another webserver or to restore the site back will be seamless with proper backups.

15) Monitor your website traffic and statistics on a regular basis. Watch out for unusual traffic (depending on IP, location, webpage requested and so on). Use google's webmaster's tool and google analytics to aid you in the development and monitoring process.

These are just my thoughts. Feedback or any other addition to the above listed policy is appreciated.

Technorati Tags: security, Policy, Web security, phpBB

Thursday, September 15, 2011

Mobremote: An insider's view

A usual morning at college with an ongoing data structures class suddenly hit us (Me and Nitesh) with a new software idea. Remote Control via text messages!

A lot has already been achieved in Remote Control, now that mobile devices are faster, slimmer and easy to use. But we had a different idea in our mind. To create something that eliminates the cost factor of a fancy cellphone. We started searching and we came across loads of different software, but we found some things common in almost all of them:

1. Either the user requires a second cellphone attached to his computer and controls the computer via another cellphone with him.

2. The cellphone as well as the computer have a fast internet connection and the client running on the computer talks with the cellphone via a protocol delivering the computer's current state on the cellphone's screen.

3. The cellphone updates a part of a common web server/user profiles (3rd party over which user has very little control) and the client would read the profile. This mostly is facilitated via a sms gateway (generally owned by a 3rd party website) which is most cases demands premium sms charges or subscription to their service.

In all the above mentioned, there are charges involved that the user needs to pay in order to control his computer remotely, either overhead of a second cellphone, bandwidth charges or lastly, premium sms or subscription charges.

The solution of these problems became the central idea behind our project and we named it MOBREMOTE. (short for Mobile Remote)


Mobremote provides the user with ability to send text messages containing the desired command to execute on his computer. There is absolutely NO need of an internet connection on the user's cellphone. The only requirement is that of an existing gmail account and the client computer only requires a minimal internet connection (even dialups would do!) which is generally cheaper than the cost of an additional cellphone and mostly better than subscription charges.

Advantages:
1. NO premium charges of sending the text message
2. NO internet connectivity required on the cellphone (saving extra bandwidth charges)
3. NO monthly subscription charges
4. Full Control over what can be remotely done with the cellphone (with different layers of security at each level)


So how do implement our idea? It's plain and simple. We came across a platform known as txtWeb which runs in India, United States Of America and Canada. The platform is run by Intuit, based in United States itself. Their primary aim is to bring the power of internet to user's cellphone for no extra charges except the cost of a standard text message. txtWeb has dedicated numbers assigned for each of these countries.

The path that we followed in implementing Mobremote was:

User's cellphone sends message at txtweb's number->> Process message and check for correctness->> Forward the message's content to user's specified gmail account->>Create a separate application to run on user's computer->>The application would periodically check for incoming commands in user's gmail account->> If the received message from user's gmail inbox passes all security checks, execute the specified command in the message.

This was the ultimate solution for us to go ahead and bring convert our idea into reality. So we started building a text-message handling application. We hosted the application on Google AppEngine for reliability, security as well as diagnostic reasons. Next we map a keyword on txtWeb's website that would point to our application hosted on AppEngine. By doing so, we ensure that when the user sends a message with our keyword and his details to txtWeb, txtWeb would in turn run our application with the message as a parameter and return the result back to the user (or forward the message to user's gmail account, sending back a success message to user's cellphone). We designed a format in which the user is required to specify his details in the text message.

Mobremote's current format is:
@mobremote -k (security key) -e (gmailid@gmail.com) -s command -c (command to execute)

Security key (5 digits entered in the Mobremote software installed on the user's computer) is implemented as a part of Mobremote’s security in order to protect the user’s computer from unwanted/fake commands from any other person other than the owner of the computer himself. The user is required to fill in the details specified in braces and send the text message to one of the txtWeb's numbers (9243342000 or 9900173324 for India, and 898932 for US and Canada).

The command is specified as digits ending with a $ sign. Mobremote currently supports 9 most basic commands the user may need when he/she is not physically near their computer.
The number to command mapping is as follows:

0:Stop listening to incoming commands from cellphone

1:Lock computer

2:Sleep Computer

3:Hibernate computer

4:Log off user

5:Restart computer

6:Shutdown computer

7:Force shutdown computer

8:End Unresponsive program


EXAMPLE: If your gmail id is dev@gmail.com with the configured security key as 12345 and you want to restart your computer, you will send to the appropriate txtWeb number: @mobremote -k 12345 -e dev@gmail.com -s command -c 5$

We offer several help options to our users via text messages like:

1. To get information on mobremote, send “@mobremote” (without quotes) to the above txtWeb number which applies to you according to your location.
2. To get the format of sending commands, send “@mobremote format”
3. To get a list of supported commands, send “@mobremote help”
4. To view an example, send “@mobremote example”


So, uptil now, our text message has travelled from user's cellphone to his/her gmail account. As stated above, we create another application that would run on the user's machine and regularly check for any incoming emails in the format of Mobremote. So we started writing code to create a good user interface along with added security to extend what the user can accomplish by using Mobremote. We wrote code in C++ utilizing Qt framework to provide a user friendly GUI. The user is required to fill in his details in the Mobremote software which includes his gmail account details, mobile number and security key and set the software in Running mode in order to listen to incoming commands from user's cellphone.

The Gmail ID and security key is required to be sent in the text message from user’s cellphone, so the user needs to remember these details entered on his/her computer. Mobremote executes commands only when it verifies user’s identity via his/her gmail account ID and security key.

The software installed on the end user's machine uses PHP with IMAP+SSL to securely fetch email messages containing commands sent from user's cellphone. To provide a scripting environment, we require installation of Apache.

We bought our own domain www.mobremote.com and created a website for our project.

After 6 months of coding, testing, debugging, finally we packed everything into a installer and it was ready to be distributed. We uploaded both 32 and 64 bit installer for Windows XP/Vista/7 along with Wampserver (contains Apache for Mobremote to make use of) in the download section of our website www.mobremote.com/download

Developing Mobremote was truly a learning and fun-filled experience. Of course, there were times when we were so frustrated that we wanted to smash our computer itself, but in the end it worked out well and we were good to go. Mobremote is written in around 5 computer languages all working together to provide remote control facility to the user. Ahead of time, we plan to add more features to Mobremote, including starting/stopping applications, automated downloads, facebook/twitter status updates and the list goes on!

Mobremote was developed with an open mind so it's free to use and re-distribute. However, we do not share our source code with anyone. Developers who are willing to contribute to our project can visit For Devs for more details.

Technorati Tags: mobremote, remote, sms, mobile, cellphone, software, free, txtweb, remote-control

Saturday, August 13, 2011

Plunge into Windows 7 and Windows 8 Preview

I've started writing for the technical section (named Tech-Tonic) of our college's e-magazine. Here's the first article published in August.                                 

Windows 7 has been around for quite a while and Windows 8 Beta is around the corner. After the delayed production of Windows Vista (Codenamed Longhorn) which was not as successful as its predecessor, Windows  7 has stood up to the mark when it comes to end user satisfaction, usability and reliability.

In this edition, I would be highlighting specific features of Windows 7 that you should be aware and make use of so as to harness the full capability of Windows 7.  In the “Tips & Tricks” section, this edition will carry some selected shortcuts for better maintaining and managing Windows 7. Finally, I will conclude with the expected feature set and how Windows 8 will differ from current line of operating systems.

Windows 7 Libraries
Libraries serve as virtual folders inside Windows 7. Many of us have various files cluttered all over our hard drive or even on external storage devices. This is time consuming when it comes to finding a particular file that u edited 3 months ago and now have forgotten where u actually saved it!  Libraries solve this problem quite efficiently. Users can add folders to a library without copying or creating shortcuts to the folder. The added folder appears under the library which can be accessed the same way as u access a real folder.  For example, I capture photos from my Sony Digital Camera and transfer them to my notebook running Windows 7. By default, Sony’s camera creates a folder named 101MSDCF and stores all captured photos in it. When my memory card fills up, I store some photos in the camera’s internal memory, which resides in a different location. Similarly, I also transfer images from a Olympus DigiCam from a relative of mine which has its own folder structure. After a year, I have tens of hundreds of folders all containing the photos I took or transferred but in separate locations. It’s a mess trying to remember which folder was copied to which location and retrieving a single image from a thousand captured from a single trip. This is when Windows 7’s Libraries come to play.
By default, Windows 7 includes 4 pre-defined libraries: Documents, Pictures, Music and Videos. Users can also create custom libraries to store relevant data according to need. For demonstration purpose, I’m going to create a custom library.
I open up explorer (Ctrl+E), select Libraries, click on “New library” and enter the library name as “Trip pics”.



In order to add folders to my Trip pics library, I navigate to each folder and select “Include in Library” drop down menu to select the library in which I want to put the selected folder. Alternatively, I right click the desired folder, select Include in library>Name of library I wish the folder to add to. Note that non-indexed locations, network paths and files from CD/DVD CANNOT be added to a library. To add non-indexed and network locations, use a 3rd party tool named “Win 7 Library Tool”.

Also note the effects of deleting folders from within a library and from their original location. If files/subfolders change in their original location, these changes are reflected in the library to which they belong. Files or subfolders deleted from their original location do not appear in the library at all. Deleting files or folders from within a library also affects the original folder or files. However, if folders are “removed” by selecting the locations link in a library and clicking on “Remove”, the folder is no longer a part of the library and is temporarily removed WITHOUT affecting files or subfolders in the original location.



After adding all the folders that I wish to keep in a separate library, I get something like shown in figure below:



I now have a clean way to have a quick glance and work with my scattered files from a central location. Yay!

Homegroups

Homegroups make file and printer sharing between Windows 7 machines fairly simple. However, there are some things u should keep in mind before getting started with your own homegroups. First and foremost, you should be connected to a network that has its location set to home. Secondly, homegroups require IPv6 to be enabled on your home network. Double check these two pre-requisites from your adapter settings via Network and Sharing Center.



After I’ve ensured the above requirements, I open my explorer and select Homegroup. While creating a homegroup, I have the ability to share Pictures, Documents, Music, Printers and Videos [Libraries, not folders]. After making my selections, Windows 7 assigns a password for other Windows 7 machines to connect to your homegroup.

On other computers, Windows 7 detects existing homegroups and provides you the option to add the computer to the created homegroup. Once this is complete, your libraries, printers as well as media can be accessed from other computers that are a part of the same homegroup. On other computers, navigate to Homegroups and select “Join Now”.


To change homegroup settings, such as Turning off password protected sharing (to not force users to type the password), change media sharing options, alter homegroup password, navigate to Control Panel->Network Internet->Homegroup. As a side note, other computers should have Network Discovery turned on, as well as File and Printer sharing to take the full advantage of homegroups.


However, before printing from other computers to a printer attached on a homegroup hosting computer, make sure u double click the printer in Network and Sharing Center->View computers and devices and the printer will be automatically installed for you to use.
Homegroups form a mesh-type of sharing where files shared by people in the homegroup are accessible by anyone in the homegroup. For users who shared files via Sharing Tab in folder properties in previous versions of Windows can also share files by Public Folders in Windows 7. However, sharing files/folders via the Public folders method requires a copy of the files to be present in the public folder. Homegroups simplify this procedure by placing links of shared libraries (which in turn use links to real folders) instead of the entire contents.

If media sharing is enabled (i.e. “Share my pictures, music and videos to all devices on my network” is checked) files from media libraries are available directly in windows media player of members in the homegroup without having the need to share them explicitly as files.
To add a custom library to your homegroup, simply navigate to your library via explorer and select the “Share with” option. U can specify nobody (deny), read, read/write or even specific permissions to different users in the homegroup.



Tips & Tricks

Essential Windows 7 management shortcuts for everyday use:

1. Win+1,2,3,4…: Launches shortcuts in taskbar bar in order from left
2. Win+Alt+1,2,3,4…: Opens up jump list for program in the taskbar in order from left
3. Win+Home: Minimizes every other window except the current one
4. Win+T: Cycle through programs in taskbar
5. Win+B: Select programs in order in the notification area
6. Win+Up/Down: Maximize/Minimize the current window
7. Win+Left/Right: Moves the current window to the left/right side of the screen
8. Ctrl+Shift+Esc: Opens up task manager without using Ctrl+Alt+Delete
9. Ctrl+Shift+N: Creates a new folder in the current directory
10. F10: Toggles the menu bar in Windows Explorer
11. Shift+F10: Opens the context menu for the current selection
12. Alt+Up: Move one folder up in the hierarchy
13. Shift+Delete: Delete the current selection permanently, without moving to recycle bin
14. Alt+Enter: Opens the properties of the current selection
15. F3 or Win+F: Opens up Windows Search
16. Ctrl+Esc: Opens up start menu (called as Orb in Windows 7)
17. Alt+Space: Opens up windows system menu (Restore, Move, Size, Minimize, Maximize, Close)
18. F2: Rename the current selection
19. Hold current window with mouse and shake left and right quickly several times: Minimizes every other window except the current one (=Win+Home)
20. Win+Tab/ Win+Shift+Tab: Flip 3D open windows in forward/reverse order


Previewing Windows 8

In the past 1-2 years, the Redmond based company is releasing a line of products for home/office use with lightning speed. With the release of Windows 7 and Internet Explorer 9, Microsoft made a mark yet again in both home and enterprise environments. But innovation and creativity does not halt as we already see milestones and newer windows 8 builds being mentioned on the internet.

The start menu (Orb in Windows 7) was doomed to be changed since Windows Vista. However it was untouched until Windows 7. In windows 8 we see a focus of touch input to control your favorite programs, although the same could be achieved via mouse and keyboard. The applications are now displayed in a larger form of vista gadgets, called as “Tiles” in windows 8. Users can now scroll through program tiles by using hand flicks both to the left and the right. Touch input, much like tablet pc, uses on screen keyboard to deliver keystrokes.
Microsoft has been considerate to post preview videos titled “Building Windows 8”. Using tiles allows the user to focus on a single application while keeping background tasks unaffected. Also, expanding a tile shows detailed information and allows user interaction.


The complete User Interface was re-designed when Microsoft transited from Windows XP to Windows Vista. Windows 7 is built on the same kernel with some improvements over the vista kernel. 
Rumors are spread throughout the internet with respect to Windows 8 features. Most systems today run on a 32 bit and some on 64 bit operating system. Windows Core development team may make Windows 8 a 128bit operating system allowing huge amount of allocable memory addresses. Some even say that Windows 8 will be EFI compatible, which is still to replace the current BIOS based systems.

With every new version of Windows, users expect speed and ease of use. However, providing eye-candy user interface can negatively impacts overall performance. We expect a balance of both system speed along with pleasing UI. Ideally, this is what makes an operating system successful and marketable.

Have a happy tech-month.

Technorati Tags: Windows 8, Windows 7, Microsoft, article, Magazine, operating system, libraries, homegroups

Saturday, June 25, 2011

Internship @ A Service Provider

The summer of 2011 was getting stressful than the last semester. As usual, i had a BIG to-do list. One of the task was sorta necessary and i was looking forward to it i.e. a 21 day internship, to be done as a part of our Bachelor of Engineering's course in Computer Science.
This year, BSNL a.k.a. Bharat Sanchar Nigam Limited (India's Largest Internet Service Provider) was hosting training for 2/3 year engineering students of Electronics/Electrical/Computer Science students. The RTTC (Regional Telecom Training Center) which is only one for a particular state was nearby my home. I initially joined their 4 weeks programme.

The RTTC is quite big, consisting of 3 floors, equipped with large lecture halls, conference rooms, seminar halls, a library, communication labs along with a separate MSC (Mobile Switching Center) and offices of the instructors (or rather employees of BSNL)

The first day, our mentor (more of a batch in-charge) T. D. Mishra, introduced himself and other senior employees present there. He handed over our schedule to us along with the timings. The four weeks were divided into separate units that include sessions, labs as well as visits to telephone exchanges. The lectures started with the overview of telecom networks and job opportunities for engineering students in the field of telecommunication. In the first week, we covered The PCM Principle along with Digital Switching. These topics demonstrate how every bit of your voice that u speak in your telephone reaches from point A to point B within no time via a huge network starting from the local loop(the line from your home which connects to the service provider's nearest exchange) to the ISP's switching modules, trunk lines (hopping from one exchange to the other) via copper or optical fibers to the correct exchange which further routes the signal to the nearest exchange the called person is connected to and finally transmitting it via another local loop to the correct telephone which decodes the signal back to comprehensible voice that the other person is able to hear and respond to in a similar manner.


Fun Fact: A mobile number generally is over 100 digits long! This includes all codes and identification numbers that can be used to pin-point a particular SIM card uniquely in the entire world. But when limited to within a country and considering the large amount of Service providers present, subscribers need to only remember 10 digits.

The second week was fun, conceptually as well as physically. We had a fiber optic systems session, coupled with SDH and DWDM concepts. Then two labs relating to fiber optics, where we understood how practically SDH systems are laid out in a large service provider's network, how they actually work and in what manner are they easy to troubleshoot.

Fun fact: A single optical fiber can be used to such an extent that it can facilitate simultaneous 1,25,000 calls via wavelength windows and loads of multiplexing. This is the reason why tariffs exist that reduce calls costs to only a few cents per minute.

Following this, the most interesting lab was where we got to join two optical fibers by fusion spilicing. The week ended with our first exchange visit where we got to enter all the rooms that stated "No Entry" or "Not Allowed" :-) including the MDF (Main Distribution Frame) Room, Switching and Power/Backup rooms.


Side View of MDF room (Click to view Full size image)
       
The third week seemed small to me, but it had great sessions, especially the GSM and CDMA parts as well as the visit to the Mobile Switching Center. I could not manage to get pictures of the inside of the MSC, but it was fascinating how it served millions of subscribers simultaneously.

Fun Fact: GSM is the most widely used mobile communication standard, because of which it is termed as "Global Systems for Mobile Communications"


(Click to view full size image)
Fig: A section of the MDF installed in an exchange. The mesh of wires terminating into vertical white boxes(called as modules) interconnect the subscriber's landline to the exchange's switching system
The final week was the best of them all as it included the concept of Intelligent Networks (seriously, that was a wow!), how SSP's, SCP's and SMP's work together in a secure manner to provide amazing services throughout the country. The last visit was to the biggest exchange in the city. Except for WiMAX, every other technology was implemented, including the 16Mbps-100Mbps fiber lines that provided high end connectivity to subscribers (IIRC it was implemented by using a HUAWEI box). Further, the exchange had separate 2G (more in number) and 3G racks (comparatively less in number) which were mostly implemented by Ericsson. The CDMA division was implemented by ZTE's BTS's (Base Trans-Receive Station, what is referred to as a "mobile tower" by the general public) and a software named Netnumen provided all possible controls for both physical and radio configurations. Amongst all these, the MSC's HLR's and VLR's were held in their own server racks (MSC is a collective term consisting of all mobile related registers). HLR or the "Home Location Register" (is populated with cell phone numbers local to a resident area) and VLR or the "Visitor Location Register" (temporary register, which is populated by roaming cellphone numbers) is an integral part of every MSC. By registers i mean to imply databases with focus on regular backups.

Fun Fact: BSNL's NIB (National Internet Backbone) consists of five Cisco 12416 routers interconnected in a mesh, each costing nearly 1 million dollars (~5 Crores INR)


The meaning of internship is not limited to going to a company and performing a task for a specified period of time, rather it involves regular learning, hands on experience along with the huge amount of life lessons that u get in a very short period of time. Special thanks to Mr. T.D. Mishra for sticking by me and answering even the most stupid question i had. After the completion of my training, everytime i move around and see cellphone towers(technically called as BTS's) it reminds me of my days at BSNL.

Technorati Tags: BSNL, internship, mobile, rttc, training, GSM, CDMA, NIB, server, telecommunication 

Thursday, January 6, 2011

Tid-Bits of Routing


The most fascinating part about networks is Routing. As the term indicates Routing describes the path a data packet takes to reach its destination. The term seems simple enough, but I will go step by step to describe the complex bits and bytes of the process of routing.
Every network device (for example a router, a computer, multilayer switches) contains a pre-configured routing table. On a host computer, this can be viewed by typing the “netstat –r” command or simply “route print” at the command line (in case of windows systems) and the “route” command for linux based systems.





In general, an IPv6 routing table and an interface list (in a case of a computer) will accompany the IPv4 table when u view the routing table of a device that supports both protocols. The routing table is composed of 6 parts as follows:-
  1. Network Destination: The IP address of the network of the device listed as the final destination for a packet.
  2. Netmask: Commonly termed as “Subnet Mask”. Separates the Network ID with the host ID.
  3. Gateway: The router through which the packet has to travel to reach to its destination.
  4. Interface: The IP address of the network adapter from which the packet originated (the local computer)
  5. Metric: A term which relates indirectly to the cost involved for the packet to reach to its destination if it takes the specified route. The lesser the metric, the better and faster the transfer of a packet.
  6. Persistent Routes: Manually added routes are termed as “Persistent” which stay even if the device reboots.


Let’s take an example route from the above routing table. The 6th entry in the routing table is shown as follows:-

192.168.91.0      255.255.255.0      On-link      192.168.91.1      4501

The “On-link” in the gateway column specifies that the packet can be directly forwarded to the specified network destination without any routing (i.e. the destination is on the local subnet)
It signifies that in order for a packet to travel from the interface with an IP address of 192.168.91.1 to the 192.168.91.0 network with a subnet mask of 255.255.255.0 it can to be directly forwarded to the network i.e. no routing required, with a cost of 4501.

If a gateway was specified e.g. 192.168.1.1 then the packet had to travel through it to reach the mentioned network destination. Complex algorithms are employed to determine each metric. Another thing to note here is the network destination specified as 0.0.0.0. This denotes all other network destinations other than the ones listed in the routing table.

By default, there are no persistent routes. But they can be added via command line.

To add a route manually type at the command line:-
route add “network destination” mask “netmask” “gateway”
e.g. route add 192.168.1.0 mask 255.255.255.0 192.168.1.1

To add a persistent route, type:
route add “network destination” mask “netmask” “gateway” –p
e.g. route add 192.168.1.0 mask 255.255.255.0 192.168.1.1 -p



If no metric is specified, it can be automatically calculated by the device.

To delete a route type:
route delete “network destination”
route delete 192.168.1.0

Routing can be broadly classified into two categories: Static and Dynamic

Static Routing: Network devices have to be configured and updated manually.
Dynamic Routing: Network devices communicate with each other to share their routing information.

Routing is governed by Routing Protocols which can also be divided into two categories: Distance Vector Routing and Link State Routing Protocol.

Distance Vector Routing Protocols: Each router communicates all the networks it knows about to other routers to which it is directly attached. Communication takes place on a regular basis.

Link State Routing Protocols: Each router generates a network map. A router communicates information about the networks it is connected to through LSAs i.e. Link State Advertisements. But communication, unlike distance vector routing protocols, takes places only when a change is made to the network.

Distance Vector Protocols include RIP(Routing Information Protocol), RIPv2 and BGP(Border Gateway Protocol).
RIP and RIPv2 both support a maximum of 15 hops(1 hop= 1 jump from a router) and updates every 30 seconds. RIP uses broadcast communication whereas RIPv2 uses multicast communication for obtaining updates. Also, RIPv2 supports authentication whereas RIP does not.

Link State Protocols include OSPF (Open Shortest Path First) and IS-IS (Intermediate System to Intermediate System) Protocols.

OSPF is used in medium-large networks which gives preferences to certain paths based upon metrics.
IS-IS is designed with the OSI model. Interestingly, IS-IS is another name for a router.

Hybrid Routing Protocol includes Cisco’s EIGRP(Extended Interior Gateway Routing Protocol). It uses the Diffusing Update Algorithm (DUAL) whereby each router keep a copy of it’s neighbor’s routing table and it periodically checks the state of its neighbors by sending a packet.

Technorati Tags: Networks, Protocols, Routing