27 April 2010

How to: Setup a time server in linux

Configaration on NTP server (Linux machine)
cat > /etc/ntp.conf << EOF
server 0.pool.ntp.org
server 1.pool.ntp.org

server 127.127.1.0 # local clock
fudge 127.127.1.0 stratum 12

restrict default ignore
restrict 0.pool.ntp.org nomodify notrap noquery
restrict 1.pool.ntp.org nomodify notrap noquery
restrict 192.168.0.0 mask 255.255.0.0 nomodify notrap
restrict 127.0.0.1

driftfile /var/lib/ntp/drift
EOF

yum install ntp
ntpdate -b pool.ntp.org

chkconfig --level 2345 ntpd on
service ntpd restart
wait for around 20 min for NTP server to initialize
check with "ntpq -p" the output should be like this:
make sure "*LOCAL(0)" is there ("*" is important here).
# ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
adelaide.ip4.ph .INIT. 16 u - 64 0 0.000 0.000 0.000
ox.eicat.ca .INIT. 16 u - 64 0 0.000 0.000 0.000
*LOCAL(0) .LOCL. 12 l 14 64 377 0.000 0.000 0.001

Configuration on NTP client (Windows machine)
net stop w32time && net start w32time
w32tm /config /manualpeerlist:192.168.0.105 /syncfromflags:manual /update
w32tm /resync /rediscover

Other configuration commands on NTP Client (windows machine)
w32tm /config /syncfromflags:domhier /update
w32tm /resync /rediscover

w32tm /stripchart /computer:192.168.0.105 /samples:3 /dataonly
w32tm /monitor /computers:192.168.0.105

Configuration on NTP client (Linux machine)
ntpdate 192.168.0.105

service ntpd stop
ntpdate 0.pool.ntp.org
Configure SNTP client on Nortel switch
(config)# clock time-zone IST +5 30
(config)# clock source sntp

(config)# sntp server primary address 192.168.0.105
(config)# sntp enable

(config)# show clock
Current SNTP time : 2010-04-27 20:30:26 GMT+05:30
Daylight saving time is DISABLED
Time zone is set to 'IST', offset from UTC is 05:30

Reference:
Introduction to NTP
Another blog - an help for NTP server configuration
http://www.tuxweb.net/howto/ntp/network_time_howto.html
http://www.meinberg.de/english/info/ntp.htm
http://support.ntp.org/bin/view/Servers/WebHome
The_NTP_Server
sntp.pl

24 April 2010

lldp in Nortel switches

SynOptics Network Management Protocol (SONMP) --> Bay Network Management Protocol (BNMP) or Bay Discovery Protocol (BDP) --> Nortel Discovery Protocol (NDP)

Nortel switch 425 and 55x0 series support LLDP with a 5.x firmware.
show lldp neighbors
SONMP is supported only on Nortel switches and routers and is enabled by default. The Network Management Module table shows the slot number and port number of the remote device used to send out the topology packet.
show autotopology nmm-table
LLDP frames are sent by equipments on each port at a fixed frequency.
LLDP-MED (Media Endpoint Discovery) is an enhancement of LLDP.
Sample LLDP packets captured are: lldp.minimal.pcap, lldp.detailed.pcap, lldpmed_civicloc.pcap

Steps to install LLDP agent in a Linux machine:
download lldp demon from here.
./configure
make
make install

mkdir /var/run/lldpd
useradd _lldpd

lldpd
# lldpctl
LLDP neighbors:
Interface: eth0, via: LLDP, RID: 1, Time: 0 day, 19:20:38
Chassis:
ChassisID: mac AA:BB:CC:DD:EE:00
SysName: Not received
SysDescr: Not received
Port:
PortID: mac AA:BB:CC:DD:EE:15
PortDescr: Not received
This means eth0 of the current linux machine is connected to the port 15 of the switch with mac address AA:BB:CC:DD:EE:00.

Reference:
https://trac.luffy.cx/lldpd/wiki/CompatibleHardware#SONMP
https://trac.luffy.cx/lldpd/wiki/CompatibleHardware#Nortel
http://wiki.wireshark.org/SampleCaptures

customised ethtool

download customised ethtool.c from here.

# ./ethtool eth0
driver: pcnet32
version: 1.35
firmware-version:
bus-info: 0000:00:11.0

Reference:
ethtool.c
netdrv_ethtool.c

18 April 2010

AVL Tree

an AVL tree is a self-balancing binary search tree.
Lookup, insertion, and deletion all take O(log n).
The balance factor of a node is the height of its left subtree minus the height of its right subtree.
A node with balance factor 1, 0, or −1 is considered balanced.

a. Right rotation:
                  -2                             -1
80 80
/ \ / \
-2 -1 0 -1
30 100 15 100
/ \ / / \ /
-1 0 0 -1 0 0
15 40 90 ==> 10 30 90
/ \ / / \
-1 0 0 0 0
10 20 5 20 40
/
0
5
b. Double Rotation:

i. Left Rotaion at 30:
               -2                               -2
80 80
/ \ / \
+1 0 -1 0
30 100 50 100
/ \ / \ / \ / \
-1 +1 0 0 -1 -1 0 0
20 50 90 120 30 60 90 120
/ / \ / \ /
0 0 -1 -1 0 0
10 40 60 20 40 55
/ /
0 0
55 10
ii. Right Rotation at 80:
                -2                            0
80 50
/ \ / \
-1 0 -1 0
50 100 30 80
/ \ / \ / \ / \
-1 -1 0 0 -1 0 -1 0
30 60 90 120 20 40 60 100
/ \ / / / / \
-1 0 0 0 0 0 0
20 40 55 10 55 90 120
/
0
10
ALV Implemention File - avltree.c
AVL Tree Header File - avltree.h
Macro for Fatal Error - fatal.h
Test Program for AVL Tree - testavl.c
Makefile - Makefile

Reference:
www.cs.virginia.edu/~cs216/Fall2005/notes/avl_handout.pdf
http://cis.stvincent.edu/carlsond/swdesign/avltrees/avltrees.html
http://www.cs.uiuc.edu/class/fa05/cs400/_resources/_practice/avlsoln.html
http://cprogramminglanguage.net/avl-tree.aspx

12 April 2010

How To: Setup A Linux Syslog Server

redirect all dhcp messages to /var/log/boot.log
redirect all other messages to /var/log/messages
snmptrapd is listening on udp port 162
syslogd is listening on udp port 514
--> /etc/dhcpd.conf
>>> log-facility local7;

--> /etc/syslog.conf
>>> *.info;mail.none;authpriv.none;cron.none;local7.none \
/var/log/messages
>>>local7.* /var/log/boot.log

--> /etc/sysconfig/syslog
>>> SYSLOGD_OPTIONS="-m 0 -r"

# service dhcpd restart
# service syslog restart
# tail -f /var/log/messages

find the process name who is using port 162:
netstat -nlp | grep ":162"
netstat -nlp | awk '/:162 / {split($6,t,"/"); print t[2]}'
@echo off

for /F "usebackq tokens=4" %%f in (`netstat -ano ^| find ":%1"`) do call :process %%f
for /F "usebackq tokens=5" %%f in (`netstat -ano ^| find ":%1"`) do call :process %%f
goto :eof

:process
tasklist /FI "PID eq %1" /NH

configure syslog and snmptrap in baystack
(config)# logging remote address 192.168.80.10
(config)# logging remote level critical
(config)# logging remote level serious
(config)# logging remote level informational
(config)# logging remote enable
(config)# show logging config
Remote Logging: Enabled
Remote Logging Address: 192.168.80.10
Event Types To Log Remotely: Critical, Serious, Informational

(config)# snmp-server community public ro
(config)# snmp-server community private rw
(config)# show snmp-server view
(config)# snmp-server community humble read-view nncli \
write-view nncli notify-view nncli
(config)# show snmp-server community
(config)# snmp-server host 192.168.80.10 v2c humble
(config)# snmp-server enable

configure syslog and snmptrap in WC-8180
WC8180(config)# logging remote address 192.168.80.10
WC8180(config)# logging remote level critical
WC8180(config)# logging remote level serious
WC8180(config)# logging remote level informational
WC8180(config)# logging remote enable
WC8180(config)#show logging system config
Event Logging: Enabled
Volatile Logging Option: Overwrite
Event Types To Log: Critical, Serious, Informational
Event Types To Log To NV Storage: Critical
Remote Logging: Disabled
Remote Logging Address: 192.168.80.10
Secondary Remote Logging Address: 0.0.0.0
Event Types To Log Remotely: Critical, Serious, Informational

WC8180(config)# snmp-server community ro
>> public
WC8180(config)# snmp-server community rw
>> private
WC8180(config)# show snmp-server view
WC8180(config)# snmp-server community read-view nncli \
write-view nncli notify-view nncli
>> humble
(config)# snmp-server host 192.168.80.10 v2c humble
(config)# snmp-server enable

configure SNMP Trap Server:
--> vi /etc/snmp/snmptrapd.conf
>>> disableAuthorization yes

//snmptrapd -f -Le

service snmptrapd restart

send fake SNMP Trap to SNMP Trap Server:
#!/usr/bin/perl
use SNMP_util "0.54"; # load BER and SNMP_Session

# /usr/lib/perl5/vendor_perl/5.8.8/SNMP_Session.pm
# snmptrap($host, $ent, $agent, $gen, $spec, @vars);
snmptrap("public\@localhost:162", ".1.3.6.1.4.1.2789",
"192.168.80.115", "6", "3301",
".1.3.6.1.4.1.2789.3301.1", "int", "4278475",
".1.3.6.1.4.1.2789.3301.2", "string", "DB Stopped");
snmptrap -Ddumph_send,dumpv_send -v 2c -c public \
localhost:162 3 0 \
.1.3.6.1.4.1.2789.3301.1 i 4278475 \
.1.3.6.1.4.1.2789.3301.2 s "DB Stopped"

Reference:
http://www.linuxhomenetworking.com/wiki/index.php/Quick_HOWTO_:_Ch05_:_Troubleshooting_Linux_with_syslog
http://docstore.mik.ua/orelly/networking_2ndEd/snmp/ch10_03.htm
http://www.rekk.de/bloggy/2007/find-process-id-by-port-number

09 April 2010

script to clean linux 2.6.33 for x86

#!/bin/sh

ARCHDIRS="alpha blackfin h8300 m68knommu mn10300 s390 arm \
cris m32r microblaze parisc sh avr32 frv ia64 m68k mips \
powerpc sparc xtensa score"

echo -n "deleting"
for DIR in $ARCHDIRS; do
echo -n " $DIR"
rm -rf arch/$DIR
done

echo " Documentation"
rm -rf Documentation

echo ""
echo "creating Documentation Kbuild"
mkdir -p Documentation/DocBook
touch Documentation/Kbuild Documentation/DocBook/Kbuild

Reference:
script-remove-unwanted-folders-from.html

03 April 2010

Payment Systems in India

RTGS - Real Time Gross Settlement
This is the fastest possible money transfer system through the banking channel. The minimum amount to be remitted through RTGS is Rs.1 lakh.
NEFT - National Electronics Funds Transfer
NEFT settlement takes place 6 times a day during the week days (9.00 am, 11.00 am, 12.00 noon. 13.00 hours, 15.00 hours and 17.00 hours) and 3 times during Saturdays (9.00 am, 11.00 am and 12.00 noon).
ECS - Electronic Clearing System

http://www.visa.com
http://www.mastercard.com

Visa’s Card Verification Value (CVV / CVV2)
MasterCard’s Card Validation Code (CVC / CVC2)

=> Cardholder Verification is done in a traditional retail environment by reading a card's magnetic stripe with a point-of-sale (POS) terminal and verifiying Visa/Discover's Card Verification Value (CVV) or Mastercard's Card Validation Code (CVC).
=> However, the swipe cannot be validated when the card or a POS reader is not present. The goal of CVN programs are to provide a similar type of verification when the card is not present (online???).
=> The CVN is uniquely associated with the plastic card that is currently issued to the Cardholder. This number is never printed on a receipt or cardholder statement, nor may it be stored in a merchants' computer system. MasterCard refers to the code as CVC2, and Visa as CVV2.

Reference:
http://www.rbi.org.in/SCRIPTs/FAQView.aspx
Payment Systems in India - Vision 2005-08
rbi-plans-new-payment-systems-1
rbi-plans-new-payment-systems-2
Cardholder Verification Number (CVN)