Tuesday, December 31, 2013

Value with a constant growth factor

Many times we hear in the news, either financial news or economy in general, about growths with constant factor.  For example: "The appreciated value of residential property in townville grows at 4% per year', or "The stock price grows constantly at 5% per year", or "the population of villageville decreases by constant factor of 5%".

What does it mean?

Well, it is actually simple.  The value increases by factor of 4%.  If the current value is A0, next year its value is A0 + 4%*A0.  Next 2 years the value is A1 + 4%*A1 = A0*(1+4%)^2 and so on.  From this, we can deduct a general formula for a growth (which is a form of geometric series):

A(t) = A(0) * (1+g/100)^t

Where A(0) is the value at the initial evaluation (t = 0)
t = unit time for the growth
g = percentage of growth (in %), so we need to divide it by 100 there
A(t) = the value at t

From this formula, we also can find "Doubling Time", or the time needed for a value to be double.

Tdouble = ln(2) / ln( 1+g/100)

For example:
Michael bought his house in 2002 for $315,000.  The average appreciation rate of properties in his area is 2%/year.  How long he has to keep his house to make the house value double (assuming the appreciation rate stays the same)?


Tdouble = ln(2) / ln( 1 + 2/100) = 0.693/0.0198 = 35 years.

For negative growth (decrease), use negative g.

More complex calculation is if the growth factor is not constant.

Monday, December 16, 2013

How to mount disk used by ReadyNAS

The following steps are useful if we want to salvage data stored in the drive in ReadyNAS.
I am not sure if the steps below are going to work on other ReadyNAS models, but it works on my ReadyNAS Duo (Sparc CPU).

Basically, what we need is a SATA-to-USB cable (can be bought on the Internet for couple of bucks).
NETGEAR ReadyNAS partitions the drive into 4 partitions.  In my case, it is detected as /dev/sdc:

[root@r3000 media]# fdisk -l /dev/sdc

Disk /dev/sdc: 1000.2 GB, 1000204886016 bytes
255 heads, 63 sectors/track, 121601 cylinders, total 1953525168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1               2     4096001     2048000   83  Linux
/dev/sdc2         4096002     4608001      256000   82  Linux swap / Solaris
/dev/sdc3         4608002  1953092233   974242116    5  Extended
/dev/sdc5         4608003  1953092233   974242115+  8e  Linux LVM
[root@r3000 media]# 

There are couple of issues if we try to mount the partitions directly:

  1. ReadyNAS uses non-standard ext3 block-size, which in my case is 16384 bytes (use command "lvsc" to check)
  2. The home directory is partitioned as LV group, so conventional mount command is not gonna work
Here's the steps:
  • Scan the usb for LVM volumes and identify in the output the volume group name that has your READYNAS volume (mine proved to be c):
# vgscan
[root@r3000 media]# vgscan
  Reading all physical volumes.  This may take a while...
  Found volume group "c" using metadata type lvm2
  Found volume group "vg_r3000" using metadata type lvm2
  Found volume group "VolGroup" using metadata type lvm2

  • Activate the group for ReadyNAS (in this case, the group name is "C")
# vgchange -ay c
  • Find the logical volume that  (mine proved to be 'c'):
# lvs
  • root@r3000:/home/root# lvs
      LV   VG   Attr      LSize   Pool Origin Data%  Move Log Copy%  Convert
      c    c    -wi-ao--- 929.09g  
  • To display the logical name of the partition, use command "lvdisplay":
# lvdisplay /dev/c
  --- Logical volume ---
  LV Name                /dev/c/c
  VG Name                c
  LV UUID                7HUOrf-B5bL-ur6r-ULsd-yl4m-gCrA-zQc4s9
  LV Write Access        read/write
  LV Status              available
  # open                 0
  LV Size                929.09 GiB
  Current LE             29731
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:5

We cannot use regular command "mount" to mount the non-standard blocksize ext3 partition.  Fortunately, there is a tool called "fuse-ext3" running in userspace that can help us.  The tool can be downloaded here.

Here's an example how to mount my ReadyNAS's LV volume:

fuse-ext2 -o sync_read,allow_other,rw+ /dev/c/c /media/readynas2

And here is the command to mount the system (root) partition which has the Linux software (I will post later about how to reset root password without resetting the ReadyNAS to factory default etc.)

fuse-ext2 -o sync_read,allow_other,rw+ /dev/c/c /media/readynas2

Why we need to migrate to IPv6 sooner

The test result above was done using DOCSIS 3.0 modem, XFinity Blast and thru 5 MHz Wi-Fi (802.11n).
See how IPv6 improves the download speed more than 3 times of IPv4 in download test?

I think of the reason is that with IPv6, we no longer need NAT on the router.  So the router most likely bypassed the traffic and directly forward it from the server to my computer (using global IP address).

The latency also improves with IPv6.  This might be caused due to the fixed size of IPv6 header, unlike IPv4.  All other optional headers in IPv6 are moved beyond the header, so routers can forward packets faster.

Tuesday, December 3, 2013

AT&T U-Verse vs. Comcast Xfinity

Technology used

U-Verse: FTTN (Fiber-to-the Node) and VDSL
Comcast: DOCSIS (DataOver Cable Service Interface Specification) and HFC


CMTS = Cable Modem Termination System  (usually at curbside of a neighborhood serving house)
VRAD = Video-Ready Access Device (usually at curbside of a neighborhood serving house)
VDSL = Very-high-bit-rate Digital Subscriber Line
CPE = Customer Premise Equipment (e.g, U-Verse Residential Gateway)
FTTN = Fiber To The Node
HFC = Hybrid Fiber Coax
RG = Residential Gateway

How They Work

The central office above is a simplified of interwork of switches, edge routers (facing customers), and core routers (facing the Internet cloud, where Tier-1 backbone connections are interconnected).


The top network is AT&T network, while the bottom one is Comcast network.  Off course, the diagram above is oversimplified.  There are many other components of the Internet (web servers, mail servers, dhcp servers, dns servers, etc.  They will be discussed some day in separate blog).

AT&T's U-Verse network system consists of CPE sitting inside customer's home.  The upstream connection most of the time use existing coax cable that are usually pre-installed inside most houses for cable tv to minimize cross-talk and noise.  The Layer-1 protocol of this connection to VRAD is VDSL (or VDSL2 for higher speed [24 Mbps], or even VDSL2 bonding for even faster speed up to 45 Mbps.  Using VDSL2 vectoring, theoretically we can achieve even 100 Mbps).  

VRAD is an equipment (a rack equipment) sitting at the curb aggregating traffic from premises (homes).  It acts mostly like a layer-2 switch (with some layer-3 capability, such as DHCP, IGMP, some filtering).  The uplink connection to C.O is FTTN (Fiber To The Node) via optical fiber using GPON technology (or other optical technologies), while downlink connections to premises using existing regular phone's twisted pairs.  VRAD usually is equipped with backup batteries, so even when there is power outage, customers still can make phone call (if the customer uses VOIP, he also needs backup battery for his/her CPE).

The AT&T's CPE usually has multiple downlink ethernet ports and one (or two) POTS for VOIP (optional).  One of the Ethernet port is connected to setop-box (in case the customer subscribes to video as part of dual-play or triple-play).  Internet packets and IPTV packet streams are separated over separate VLAN.  For example, VLAN=100 for the Internet, while VLAN=999 for IPTV.  

When customer wants to watch a TV program by selecting a certain channel via remote, the setop-box sends IGMP join packet to VRAD.  VRAD, with its IGMP snooping capability, then requests C.O's router to send multicast packets containing the program.  This multicast packets are then forwarded to the customer's CPE as unicast packets.When other customers watch the same channel, they just join the multicast group and VRAD then forward the stream to them as unicast packets, so there is single multicast video stream coming from central office to VRAD.

All AT&T's residential gateway /CPE support Wi-Fi.  Wireless connection is treated like other wired connection in a sense it is bridged logically.  Once a CPE is up, as usual it sends DHCP (if it is set for automatic IP assignment).  This DHCP is snooped by VRAD and forwarded to C.O.  Once the client device has been assigned an IP address (public IP address), everything is the same as normal wired connection.  It is up to the CPE/RG to assign a local private IP address to any device connected to it (see previous posting for more detail about how it works).

Cable Network

Front Panel of a cable modem

Back panel of a cable modem

Cost Comparison

Sunday, December 1, 2013

Connecting Cable Modem to Two routers

Sometimes we want to split our home private network to two separate subnets, but want to maintain connectivity to the Internet/outside world. The following article tries to explain the basics and internals of most home WiFi routers in the market.

First, let see what are the basic components of a Wi-Fi router:

The following is an example of topology and connection of typical home network:

Router-1: Linksys WRT-54G running DD-WRT firmware
Router-2: NETGEAR Genie WNDR3400v2

The cable modem (DOCSIS modem) is connected to cable provider thru coax cable and its main function is to modulate/demodulate DOCSIS signal to regular ethernet frames (it might bind multiple channels [channel bonding] to increase bandwidth).  The cable provider assigns a public IP address to us to use.  This single public IP cannot be shared if we don't use router.

Router-1 and Router-2 see packets coming from modem, but they don't know how to route them to our devices at home yet.  Assume router-1 is the router that assigns DHCP IP address (running DHCP server), while DHCP server on router-1 is set to forwarder to router-2.  Router-2 is chosen as the main router because it has more recent hardware, supports 11n Wi-fi and supports IPv6 (PS3 is actually better to be connected to router-2 to lower the latency).

Other clients such as as Ooma, Roku and PS3 don't support IPv6 yet, so it's Ok to connect them to Router-2.

On Router-1:  
  • Set DHCP to DHCP forwarder (forward DHCP requests) to router-2 IP address
  • Set router IP address to
  • Set DNS to either public DNS (such as Google:, opendns's IPs or our own local DNS server)
  • Operation mode: router
  • Set wireless to bridged mode (so router-1's wifi is like another L2 ethernet device in our private LAN)
  • WAN type: Static IP.  If it is set to DHCP and the WAN port of router-1 is connected to the ethernet bridge, DHCP server at the ISP site may deny the request or even worse, shutdown the connection completely (thus require modem reboot to fix the problem).
  • Set WAN static IP to router-2 ip address.  This way, we assume router-2 is the gateway and delegates NAT work to router-2 (that's why we set the operation mode of router-1 to "router")

  • Enable AP mode
  • Set router IP address to
  • Internet IP: Get dynamically from ISP
  • Set DMZ to Router-1

How it works:

A tablet is trying to connect to the Internet via router-2.  All Wi-fi transactions have been done and now it sends DHCP request to router-2.  If this is an initial request made to router-2, router-2 doesn't learn any IP yet so it first learns for the tablet's MAC. Because router-2 runs local dhcp server, it snoops any DHCP request and serves it.  In this case, router-2 then assigns an address in the subnet along with DNS addresses and gateway IP (in this case, an ISP-assigned IP address) back to the tablet as DHCP RESP packet.

Now the tablet has a valid private address, now it can connect to the Internet via router-2.  All requests from the tablet is network-translated to public address and vice-versa.  So, if the public IP is a.b.c.d, tablet' IP address is and it is requesting access to www.google.com (http www.google.com:80) from a local tcp port xxxx, the actual packet in the public wire is "a.b.c.d:yyyy", where xxxx is a the original tcp port and yyyy is the translated tcp port by NAT (router-2 maps local to public IP via port) [ Click this for more info about NAT/PAT mechanism].

OK, everything seems to work.  Wait...what about all other devices connected to router-1? What happens if we want to watch Netflix on Roku?

When Roku device is turned on, it sends DHCP REQ similar to tablet above.  The sequence is the same, but the difference is, because router-1 doesn't run DHCP server, all DHCP packets are forwarded to router-2.  So, it is assigned an IP address in the same subnet (sorry, the diagram above is wrong, the subnet should be the same).  When the Roku starts sending tcp packets, the packets not-intended to the private subnet and coming to router-1 are assumed to be forwarded to its gateway (router-2).  Router-1 sees these packets coming from its DMZ and do the same translation to public IP.

An alternative is to subtend router-1 to router-2 directly, not via ethernet switch.  The rest is the same.