Entries Tagged as 'How-to'

Sequence for login

Quick post for the sequence for login Unix (Linux) shell, since we may not know some procedures in details.

  1. The system is connected to a tty (user port)
  2. The kernel invokes the getty program
  3. A login prompt is displayed continuously monitoring the communication port for any type of input.
  4. Control is passed on by invoking the program name found in the user’s entry in the password file.

Record My Desktop

It’s actually an application named recordmydesktop, which can be installed by sudo apt-get install recordmydesktop.

There are various kinds of purpose to use, but for me, I would like to present or show some mock-up to other people. I made a simple file

#!/bin/bash
recordmydesktop -windowid $( xwininfo -frame | awk ‘/Window id:/ {print $4}’ )

After running this script, there is a cross cursor which allows you to select a window. As soon as the window is selected, the recording start. To end the recording, simply type Ctrl+C. After several lines of screen output, there is a .ogv file generated.

You can use Movie Player to view the file if you are using Linux. However, you can still view this file by using VLC, which can be installed to both Mac and Windows.

OSPF Filtering and Range Summary sequence

OSPF Type-3 LSA Filtering can be used to permit or deny any arbitrary inter-area routes based on a prefix-list. The filtering process is in ABR under router ospf process.

  • area <#> filter-list <name> [in | out]

Also, for reducing routing table in other area, sometimes we will summarize network.

  • area <#> range <IP> <MASK>

However, here is a question, under ospf process, filter before range summary or range summary before filter? We do a test by the following scenario.

The topology may like this:

<–AREA 1–> ABR <—-AREA 0–>

Aare 1 has three networks. We can see them by “show ip route”.

  • 172.18.12.0/24
  • 172.18.13.0/24
  • 172.18.15.0/24

We also can summarize those three network to one network and advertise to Area 0.

  • area 1 range 172.18.12.0 255.255.252.0

First, we need to generate a filtering list by prefix list. If we only create a prefix list as following, the summary route (discards route in local) will not generated and the summary route is not advertised out.

  • ip prefix-list A1->A0 seq 5 permit 172.18.12.0/22

Why?

Because prefixe list will check both bits and subnet mask. Both would have to match for the network to be either permitted or denied. In the above case, there is only a “/” after the network (no le or ge), then the number after the “/” is both bits checked and subnet mask. So it will check the 22 bits from left to right (won’t care about the last 10 bits) AND it will make sure that it has a 22 bit mask. BOTH the 22 bits checked and the 22 bit subnet mask must match for the network to be permitted or denied. However, the scenario doesn’t have 22 bit submask network in routing table. Therefore, there will be nothing to generated and advertise out. If we revise the ip prefix list like the following, then the summary route is advertised out.

  • ip prefix-list A1->A0 seq 5 permit 172.18.12.0/22 ge 24 le 24

Why?

Because if we use either the le or ge (or both le and ge) after the “/”, then the number directly after the “/” becomes only bits checked and the number after the ge or le (or both) is the subnet mask. So in this case we are still going to check the first 22 bits of the network from left to right. If those match we are then going to check the subnet mask, which in this case can be GREATER THAN OR EQUAL TO 24 bits – meaning that as long as the first 22 bits of the network match the subnet mask could be 25,26,27,28,29,30,31,or 32 bits. They would all match.

So, we can safely say that, OSPF do filtering before range summary.

How to Calculate Memeory Usage

Normally we don’t calculate memory usage by ourselves. We can get percentage from system performance in Windows or System Monitor on GNOME. However, I am curious about how the percentage is calculated from back end.

We are all familiar with “top” or “htop” command in any Linux distribution. The memory usage is actually calculated from the raw data gotten from top command. The following screen shot is top running on my desktop.

As you can see that, I have 2G physical memory. I also have almost 4G swap memory which system allocated on hard disk for me. The physical memory is used 1769636K, which is actually divided to two parts. One parts is for all processes running on the system, the other part is for caching. We all know that Linux actively collect free physical memory to cache some instruction used by CPU. The idea behind caching is that it takes longer for your CPU to access data on the hard drive than it does to access data that is present in the main memory. So caching using the main memory effectively speeds up the system.

Therefore, we come up with two formula:

Cached Memory Usage = Cached Memory / Physical Total Memory

Program Memory Usage = (Used Physical Memory – Cached Memory ) / Physical Total Memory

The System Monitor on GNOME provide these two memory usage, which make us more clear about our desktop performance.

Format FAT-16 SD Card on Mac OS

I just got a SONY ebook reader. It support upmost 8G memory stick card and 2G SD card. Apparently, the ebook reader system (linux distribution) can only support FAT-16 file system for SD card. Mac OS is good that it doesn’t need any driver to install, but disk utility GUI can only format FAT-32 for the card. So, I google it and got the solution:

heng-dus-macbook-pro:~ hda2$ sudo diskutil partitionDisk /Volumes/HENRY_SD 1 MBRFormat “MS-DOS FAT16″ “HENRY_SD” 1000M
Password:
Started partitioning on disk disk1
Creating partition map
Formatting disk1s1 as MS-DOS (FAT16) with name HENRY_SD
[ + 0%..10%..20%..30%..40%..50%..60%..70%..80%..90%..100% ]
Finished partitioning on disk disk1
/dev/disk1
#:                       TYPE NAME                    SIZE       IDENTIFIER
0:     FDisk_partition_scheme                        *1.9 Gi     disk1
1:                 DOS_FAT_16 HENRY_SD                1.9 Gi     disk1s1

Terminator – Emacs-like Terminal

Since I am always working on Linux Terminal, I am looking forward some tools can be an Emacs-like environment. Recently, I noticed a tool named Terminator, which was written by Chris Jones on Jan 5 2008. Luckily I got this tool at the end of 2008, not so late. :)

It’s easy to install the tool by

sudo apt-get install terminator

Then, we may get menu by right click mouse. The menu includes “split vertically” and “split horizontally”.

We can split the panel horizontally.

Or, we can split sub panel vertically.

So, we don’t bother to arrange many terminal windows later on.

TCL Expect Script to Bring Lab Up

My Lab enviornment is running on a server with around 10 router-simulators. Without script, I have to login server by using SSH session first, then TELNET to dynagen session to interact with router simulator. This job is tedious. So, I came up with some script to automate my routing job.

First, we need a Tcl script for each connection.

#!/usr/bin/expect

spawn ssh root@10.2.111.198
expect “password:”
send “d7j3f8g8\n”
expect “root@common-server”
send “telnet 127.0.0.1 2000\n”
interact

There are two key parts. One is “expect “password:”. TCL Expect has a nice feature that you can send a password to interact with shell command. The other is “interact” command. Without it, we cannot interupt TCL session.

Then, we can put all start router-simulator script to a bash shell.

gnome-terminal -e ./open_router_sim.tcl

Simulate a Slow Link by Linux Bridge

To simulate the real world slow link network, sometimes network equipment is not enough. For example, LAN Switch can do rate-limit on each egress port, but it cannot allow packet forwarding delay, or, it cannot setup packet loss rate. The four major elements of QoS are: Bandwidth, Delay, Packet Loss and Jitter. So, in order to achieve the real situation, we can use Linux bridge plus traffic control (tc) features.

Setup Linux Bridge

Two NICs cannot be a bridge unless we install a bridge utility. “yum -y install bridge-utils” can be applied. Sorry I didn’t mention in Ubuntu distribution since I am always working on Fedora Core. Then, we need to plan which two NICs to be the member of the bridge. In my case, I use eth1 and eth2. So, make sure there is no ip on both of Ethernet cards first. Then, we need to type the following commands:

ifconfig eth0 0.0.0.0 up
ifconfig eth1 0.0.0.0 up
brctl addbr br0
brctl addif br0 eth0
brctl addif br0 eth1
ifconfig br0 up

We can assign an IP address to br0, like we assign vlan interface IP address in LAN Switch.

ifconfig br0 192.168.50.50 netmask 255.255.255.0 gw 192.168.50.254

However, since there is no routing over the bridge. we can just leave it as pure bridge.

Brief Introduction of TC

Traffic Control (TC) is a tool that do egress traffic shaping on every port. The primitive purpose to create a module named shaper.o is to slow down interface. It didn’t measure traffic instead, it was only able to decrease interface speed by suing PWM (Pulse Width Modulation). For example, you can transfer power equal to 12V from 36V by switching supply off for 2ms then switch on for 1ms. PWM has one advantage that it didn’t require much cpu usage.

Then, the CBQ (Class Based Queue) is appeared. It can classify traffic but it works in the same way as PWM.

Then, the HTB (Hierarchy Token Bucket) is coming. It controls traffic per packet instead of time slots. It allows to implement very precise control in expense of higher CPU usage.

The detailed description is available in tc manual.

Create a Delay Network

To make a simple work, we don’t need to use classes. We only need to add delay to root. However, very important, each time we have to clear “queue discipline”.

tc qdisc del dev eth1 root
tc qdisc del dev eth2 root

Then, we setup a 500 mini second delay.

tc qdisc add dev eth1 root handle 1:0 netem delay 500msec
tc qdisc add dev eth2 root handle 1:0 netem delay 500msec

Create a Low Bandwidth Network

Still, I didn’t compose any fancy shell script, instead I just use only two lines to achieve a 128K link.

tc qdisc del dev eth1 root
tc qdisc del dev eth2 root
tc qdisc add dev eth2 root tbf rate 128kbit burst 1024kbit latency 50ms
tc qdisc add dev eth1 root tbf rate 128kbit burst 1024kbit latency 50ms

So far I only got this level. I saw quite a lot blogs and tutorials in the web, which have more complicated network.

Process States in Linux

To help me memorize, I list all process states for Linux, which is actually from UNIX.

  • R – runnable which means the process has done a context switch and has the kernel.
  • S – sleeping which means the process is waiting on I/O completion (blocked), a pipe, memory, etc.
  • T – process has been stopped – sent a SIGSTOP usually with ctrl/z
  • Z – zombie – a process that has a process image in memory but no context, ie., not swappable.
  • O – means the process is the one that currenlty has the cpu

Port-channel Interface Cared by IOS

Although there is only 2 points for Trunking, it does need to carefully setup and verification. Two things need to keep in mind.

1. Don’t configure “interface Port-channel0″ in layer 2 channel-group. Cisco IOS takes care of it.

2. Make sure all swichports which participate in channel-group have the same configuration in physical layer, including speed, duplex, trunk mode and encapsulation.

HENRY_SW1#config t
HENRY_SW1(config)#inter range fa0/23, fa0/24
HENRY_SW1(config-if-range)#switchport trunk encapsulation dot1q
HENRY_SW1(config-if-range)#switchport trunk allowed vlan all
HENRY_SW1(config-if-range)#switchport mode trunk
HENRY_SW1(config-if-range)#channel-group 1 mode desirable
HENRY_SW1(config-if-range)#end

In case of loop when configure ethernet-channel, make sure that Port-channel participate spanning-tree, instead of those two ports.

HENRY_SW1#sh spanning-tree vlan 432

VLAN0432
Spanning tree enabled protocol ieee
Root ID Priority 32768
Address 0001.4327.7daf
Cost 145
Port 65 (Port-channel1)
Hello Time 2 sec Max Age 20 sec Forward Delay 15 sec

Bridge ID Priority 33200 (priority 32768 sys-id-ext 432)
Address 000d.29ad.2880
Hello Time 2 sec Max Age 20 sec Forward Delay 15 sec
Aging Time 300

Interface Role Sts Cost Prio.Nbr Type
—————- —- — ——— ——– ——————————–
Fa0/13 Desg FWD 19 128.13 P2p
Fa0/14 Desg FWD 19 128.14 P2p
Fa0/15 Desg FWD 19 128.15 P2p
Fa0/16 Desg FWD 100 128.16 Shr
Po1 Root FWD 12 128.65 P2p