Saturday, May 3, 2014

Configuring TP-Link TL-WR740N v4.27 for OpenFlow and OpenWRT

In this post, I detailed the configurations required for TP-Link TL-WR740N v4.27 to work with OpenFlow. Basically four files needs to be changed and I have included below the configurations, which worked for me.

This example configuration is considering you would like to use WAN port as management port and LAN ports as OpenFlow ports. In such you will have to make sure controller is running in same network as WAN port is configured.

/etc/config/network

config interface 'loopback'
option ifname 'lo'
option proto 'static'
option ipaddr '127.0.0.1'
option netmask '255.0.0.0'

config globals 'globals'
option ula_prefix 'fdaa:d16f:ceae::/48'

config switch
option name 'switch0'
option reset '1'
option enable_vlan '1'
option enable_learning '0'

config switch_vlan
option device 'switch0'
option vlan '1'
option ports '0t 1'
option vid '1'

config switch_vlan
option device 'switch0'
option vlan '3'
option ports '0t 4'
option vid '3'

config switch_vlan
option device 'switch0'
option vlan '4'
option ports '0t 3'
option vid '4'

config switch_vlan
option device 'switch0'
option vlan '2'
option ports '5 6'
option vid '2'

config switch_vlan
option device 'switch0'
option vlan '5'
option ports '0t 2'
option vid '5'

config interface 'lan1'
option ifname 'eth0.1'
option proto 'static'

config interface 'lan2'
option ifname 'eth0.2'
option proto 'static'

config interface 'lan3'
option ifname 'eth0.3'
option proto 'static'

config interface 'lan4'
option ifname 'eth0.4'
option proto 'static'

config interface
option ifname 'wlan0'
option proto 'static'

config interface 'wan'
option ifname 'eth1'
option _orig_ifname 'eth1'
option _orig_bridge 'false'
option proto 'static'
option ipaddr '10.0.0.2'
option netmask '255.255.255.0'
option gateway '10.0.0.1'
option broadcast '10.0.0.255'
option dns '10.0.0.1'

/etc/config/wireless

config wifi-device  radio0
option type     mac80211
option channel  11
option hwmode 11ng
option path 'platform/ar933x_wmac'
list ht_capab SHORT-GI-20
list ht_capab SHORT-GI-40
list ht_capab RX-STBC1
list ht_capab DSSS_CCK-40
option htmode HT20
# REMOVE THIS LINE TO ENABLE WIFI:
# option disabled 1

config wifi-iface
option device   radio0
# option network  lan
option mode     ap
option ssid     OpenWrt-10-lan
option encryption none

/etc/config/firewall

config defaults
        option syn_flood        1
        option input            ACCEPT
        option output           ACCEPT
        option forward          ACCEPT

/etc/config/openflow

config 'ofswitch'
option 'dp' 'dp0'
option 'dpid' '000000000001'
option 'ofports' 'eth0.1 eth0.2 eth0.3 eth0.4 wlan0'
option 'ofctl' 'tcp:10.0.0.99:6633'
option 'mode'  'outofband'

Monday, April 28, 2014

Installing lighttpd, PHP on OpenWRT

I have created this blog post because steps detailed on OpenWRT site did not work.

Installation and initial configurations are same as suggested on OpenWRT site.

1. Install PHP

opkg update
opkg install php5 php5-cgi

2. Instal lighttpd

opkg install lighttpd

3. Edit configuration file /etc/lighttpd/lighttpd.conf as per requirement

You might want to change server.document-root, server.port. Also confirm error log is enabled for debugging.

4. Step to configure PHP with lighttpd was not correct or outdated on http://wiki.openwrt.org/doc/howto/lamp#lighttpd1

Just adding below cgi.assign to configuration file gives duplicate variable error.
cgi.assign = ( ".php"  => "/usr/bin/php-cgi" ) }

First, you should comment cgi.assign entry in /etc/lighttpd/conf.d/10-cgi.conf.

5. And restart lighttpd using: /etc/init.d/lighttpd restart. If everything is configured properly, there should not be any error.

References:
http://wiki.openwrt.org/doc/howto/php
http://wiki.openwrt.org/doc/howto/http.lighttpd

Saturday, April 26, 2014

Configuring TP-LINK WR1043ND v2.1 as OpenFlow switch on OpenWRT


In my other post I provided details of compiling custom firmware for TP-LINK WR1043ND v2.1 to configure it as openflow enabled switch. In this post I detail the complete configurations to enable it as openflow enabled switch.

In my next post I will detail another configuration set along with openvswitch configuration details.

/etc/config/network

config switch
option name 'switch0'
option reset '1'
option enable_vlan '1'
option enable_learning '0'

config switch_vlan
option device 'switch0'
option vlan '1'
option ports '0t 1'
option vid '1'

config switch_vlan
option device 'switch0'
option vlan '3'
option ports '0t 4'
option vid '3'

config switch_vlan
option device 'switch0'
option vlan '4'
option ports '0t 3'
option vid '4'

config switch_vlan
option device 'switch0'
option vlan '2'
option ports '5 6'
option vid '2'

config switch_vlan
option device 'switch0'
option vlan '5'
option ports '0t 2'
option vid '5'

config interface 'loopback'
option ifname 'lo'
option proto 'static'
option ipaddr '127.0.0.1'
option netmask '255.0.0.0'

config interface
option ifname 'eth1.1'
option proto 'static'

config interface
option ifname 'eth1.3'
option proto 'static'

config interface 'lan3'
option ifname 'eth1.4'
option proto 'static'

config interface 'lan4'
option ifname 'eth1.5'
option proto 'static'

config interface 'wan'
option ifname 'eth0'
option type 'bridge'
option proto 'static'
option ipaddr '10.0.0.2'
option netmask '255.255.255.0'
option gateway '10.0.0.1'
option broadcast '10.0.0.255'
option dns '10.0.0.1'

/etc/config/openflow

config 'ofswitch'
option 'dp' 'dp0'
option 'dpid' '000000000001'
option 'ofports' 'eth1.1 eth1.3 eth1.4 eth1.5 wlan0'
option 'ofctl' 'tcp:10.0.0.27:6633'
option 'mode'  'outofband'

/etc/config/wireless

config wifi-device  radio0
option type     mac80211
option channel  11
option hwmode 11ng
option path 'platform/qca955x_wmac'
list ht_capab LDPC
list ht_capab SHORT-GI-20
list ht_capab SHORT-GI-40
list ht_capab TX-STBC
list ht_capab RX-STBC1
list ht_capab DSSS_CCK-40
option htmode HT20
# REMOVE THIS LINE TO ENABLE WIFI:
# option disabled 1

config wifi-iface
option device   radio0
# option network  lan
option mode     ap
option ssid     OpenWrt-13-lan
option encryption none

config wifi-iface
option device   radio0
option network  wan
option mode     ap
option ssid     OpenWrt-13-wan
option encryption none

/etc/config/firewall

config defaults
        option syn_flood        1
        option input            ACCEPT
        option output           ACCEPT
        option forward          ACCEPT


Reboot the router or restart network services after changing the configurations.

Here 10.0.0.1 is the my home gateway IP. Physically wan port on TP Link router is connected to one of the port on gateway.

/etc/init.d/openflow start

After starting the openflow service with above command, ofprotocol and ofdatapath should both be running on switch/router

To check: ps | grep of

Output:
 1522 root      1224 S    ofdatapath ptcp:6634 -i eth1.1 eth1.3 eth1.4 eth1.5
 1530 root      1020 S    ofprotocol tcp:127.0.0.1:6634 tcp:10.0.0.27:6633 --f

Compiled binaries:
Adding links to compiled binaries, which could be used directly with router in this post.
Binary for WR1043ND v2.1 with OF1 and USB packages.
Binary for WR1043ND v2.1 with OF1, USB and BRO packages.

References:
http://wiki.openwrt.org/toh/tp-link/tl-wr1043nd

Compiling custom firmware for wireless router with OpenWRT (Barrier Breaker from trunk) and OpenFlow

Environment: Ubuntu 12.04 with 30 GB HD and 1 GB RAM on VirtualBox (On I5 MacBook pro).
Hardware: Tested TP-LINK TL-WR740N v4.27 and TP-LINK TL-WR1043ND v2.1

1. Install prerequisite packages:
sudo apt-get update
sudo apt-get install autoconf binutils bison build-essential ccache flex gawk gettext git libncurses5-dev libssl-dev ncurses-term quilt sharutils subversion texinfo xsltproc zlib1g-dev 

2. Prepare directory and download OpenWRT source
mkdir ~/openwrt
cd ~/openwrt
svn co svn://svn.openwrt.org/openwrt/trunk/

3. Update and install feeds
cd ~/openwrt/trunk
./scripts/feeds update -a
./scripts/feeds install -a

4. Configure the build and verify prerequisites
cd ~/openwrt/trunk
make menuconfig
select 'Target System': Atheros AR71xxx/Ar9xxx
select 'Target Profile': TP-LINK TL-WR740N/ND        OR      TP-LINK TL-WR1043ND
make prereq
make (if only OpenWRT trunk version is desired. Following steps can be finished to include Openflow package, but running make at this point won't hurt and first compilation takes long time, but second time it will be faster)

5. Prepare directory, download openflow source for openwrt and link to OpenWRT for compilation
cd ~/openwrt

--------For OpenFlow 1.0--------
git clone git://gitosis.stanford.edu/openflow-openwrt
cd openflow-openwrt
git checkout -b openflow-1.0/tplink origin/openflow-1.0/tplink

cd ~/openwrt/trunk/package/
ln -s ~/openwrt/openflow-openwrt/openflow-1.0/
cd ~/openwrt/trunk/
ln -s ~/openwrt/openflow-openwrt/openflow-1.0/files
----------------------------------------
--------For OpenFlow 1.3--------
git clone https://github.com/CPqD/openflow-openwrt.git
cd ~/openwrt/trunk/package/
ln -s ~/openwrt/openflow-openwrt/openflow-1.3/
cd ~/openwrt/trunk/
ln -s ~/openwrt/openflow-openwrt/openflow-1.3/files
----------------------------------------
6. Configure the build with openflow
cd ~/openwrt/trunk
make menuconfig

select <*> 'openflow' package under 'Network'
select <*> 'tc' package under 'Network'
select <*> 'kmod-tun' under 'Kernel Modules -> network support'

IF TC PACKAGE NOT FOUND UNDER NETWORK in MENUCONFIG:
- select <*> 'kmod-sched-core' and 'kmod-sched' under 'Kernel Modules -> network support'
- 'kmod-sched-core' is prerequisite for TC.

save and exit

make kernel_menuconfig
select <*> 'Hierarchical Token Bucket (HTB)' under 'Networking support -> Networking options' in 'Queueing/Scheduling' section.

Note: Check my other post to select required packages if you need to enable pivot overlay

7. Make the final build
cd ~/openwrt/trunk
make V=s (Here, V=s is optional and will be useful to debug in case of any error)

8. Download and upload the image to router

Images can be found in cd ~/openwrt/trunk/bin/ar71xx/

Recommendations:
i. Before using your custom firmware flash router with openwrt-ar71xx-generic-tl-wr1043nd-v2-squashfs-factory.bin from trunk website, as it will be useful if you have to restore your settings to original
                    http://downloads.openwrt.org/snapshots/trunk/ar71xx/
ii. Use openwrt-ar71xx-generic-tl-wr1043nd-v2-squashfs-sysupgrade.bin version to upgrade existing firmware with you build
Before 
iii. See below link on how to do sysupgrade
                    http://wiki.openwrt.org/doc/howto/generic.sysupgrade

9. I used factory image from trunk website mentioned above. If it was new install there won't be password set and u can use Telnet for the first time to login and set password. If you upgraded from previous version of OpenWRT, password will be same.
Below is login message at first login after uploading factory image.

BusyBox v1.19.4 (2014-03-13 02:11:02 MST) built-in shell (ash)
Enter 'help' for a list of built-in commands.

  _______                     ________        __
 |       |.-----.-----.-----.|  |  |  |.----.|  |_
 |   -   ||  _  |  -__|     ||  |  |  ||   _||   _|
 |_______||   __|_____|__|__||________||__|  |____|
          |__| W I R E L E S S   F R E E D O M
 -----------------------------------------------------
 BARRIER BREAKER (Bleeding Edge, r39903)
 -----------------------------------------------------
  * 1/2 oz Galliano         Pour all ingredients into
  * 4 oz cold Coffee        an irish coffee mug filled
  * 1 1/2 oz Dark Rum       with crushed ice. Stir.
  * 2 tsp. Creme de Cacao
 -----------------------------------------------------
root@OpenWrt:~#

10. Later upgrade the factory image with squashfs-sysupgrade.bin mentioned in 8.ii, which was generated with your custom compilation.

From your machine:
scp openwrt-ar71xx-generic-tl-wr1043nd-v2-squashfs-sysupgrade.bin root@192.168.1.1:/tmp

On OpenWRT router:
sysupgrade -v openwrt-ar71xx-generic-tl-wr1043nd-v2-squashfs-sysupgrade.bin


You can notice below, now latest version of Bleeding Edge is installed:

BusyBox v1.19.4 (2014-03-14 05:08:51 EDT) built-in shell (ash)
Enter 'help' for a list of built-in commands.

  _______                     ________        __
 |       |.-----.-----.-----.|  |  |  |.----.|  |_
 |   -   ||  _  |  -__|     ||  |  |  ||   _||   _|
 |_______||   __|_____|__|__||________||__|  |____|
          |__| W I R E L E S S   F R E E D O M
 -----------------------------------------------------
 BARRIER BREAKER (Bleeding Edge, r39917)
 -----------------------------------------------------
  * 1/2 oz Galliano         Pour all ingredients into
  * 4 oz cold Coffee        an irish coffee mug filled
  * 1 1/2 oz Dark Rum       with crushed ice. Stir.
  * 2 tsp. Creme de Cacao
 -----------------------------------------------------

One other check you can do verify if you custom firmware is installed successfully is to verify difference between packages installed in steps 9 & 10. By using 'opkg list' command.

11. Install required packages manually

If TC was not installed before:
On desktop- scp ./tc_3.11.0-1_ar71xx.ipk root@192.168.1.1:/tmp/offline-packages
On router- opkg install ./tc_3.11.0-1_ar71xx.ipk

Create link for TC as follows, it's needed because openflow package won't start without TC.

cd /sbin
ln -s /usr/sbin/tc

Also create functions.sh link in /etc as below:

cd /etc
ln -s /lib/functions.sh

Reboot the router to verify if openflow running normally. It should be running ofprotocol and ofdatapath processes.

To check: ps | grep of

At least of protocol service should be running if network config and controller address is not correct.


For trunk version LUCI is not included in distribution by default. You can use "opkg install  luci" command to install it.

For some reason if you cannot use OPKG, it can be installed manually like TC package.


On router:

mkdir /tmp/offline-packages

On desktop:
mkdir ~/offline-packages

And download below packages:

libiwinfo-lua_35_ar71xx.ipk
liblua_5.1.5-1_ar71xx.ipk
libubus-lua_2014-02-23-334c38918063b5ece164624e20490021b2bff38a_ar71xx.ipk
libuci-lua_2014-02-18.1-1_ar71xx.ipk
lua_5.1.5-1_ar71xx.ipk
luci-app-bmx6_2_ar71xx.ipk
luci-i18n-english_trunk+svn9220-1_ar71xx.ipk
luci-lib-core_trunk+svn9220-1_ar71xx.ipk
luci-lib-ipkg_trunk+svn9220-1_ar71xx.ipk
luci-lib-lmo_trunk+svn9220-1_ar71xx.ipk
luci-lib-nixio_trunk+svn9220-1_ar71xx.ipk
luci-lib-sys_trunk+svn9220-1_ar71xx.ipk
luci-lib-web_trunk+svn9220-1_ar71xx.ipk
luci-mod-admin-core_trunk+svn9220-1_ar71xx.ipk
luci-mod-admin-full_trunk+svn9220-1_ar71xx.ipk
luci-proto-core_trunk+svn9220-1_ar71xx.ipk
luci-sgi-cgi_trunk+svn9220-1_ar71xx.ipk
luci-theme-base_trunk+svn9220-1_ar71xx.ipk
luci-theme-openwrt_trunk+svn9220-1_ar71xx.ipk
uhttpd_2013-11-21-cd66639800ee2882a0867ec54868502eb9b893d8_ar71xx.ipk

Also download tc package in case you were not able to select during compilation.

cd ~/offline-packages
scp ./*.ipk root@192.168.1.1:/tmp/offline-packages

On OpenWRT:
cd /tmp/offline-packages
opkg install ./*.ipk


If there is space issue in installing packages (/overlay is full) you will have clear configuration data first.

mtd -r erase rootfs_data

Device will reboot with factory settings, you will have to login using telnet and reset the password. But all the packages from last sys upgrade will be there.


Later packages can be installed one by one or few at a time. You are most likely to get space issues on WR740N. Enable commands are similar


References:

Thursday, April 24, 2014

Enabling recording of IPv6 responses in dns_spy component of POX controller


dns_spy Component which comes with POX does not support or record IPv6 addresses in DNS responses so I made some modifications to existing component.

To store IPv6 DNS replies, created two new dictionary variables ipv6_to_name and name_to_ipv6.

Note: I have commented out lookup function, as dictionaries can be accessed with core.DNSSpy.DictionaryName in other components

 # Copyright 2011-2012 James McCauley  
 #  
 # Licensed under the Apache License, Version 2.0 (the "License");  
 # you may not use this file except in compliance with the License.  
 # You may obtain a copy of the License at:  
 #  
 #   http://www.apache.org/licenses/LICENSE-2.0  
 #  
 # Unless required by applicable law or agreed to in writing, software  
 # distributed under the License is distributed on an "AS IS" BASIS,  
 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  
 # See the License for the specific language governing permissions and  
 # limitations under the License.  
 """  
 This component spies on DNS replies, stores the results, and raises events  
 when things are looked up or when its stored mappings are updated.  
 Similar to NOX's DNSSpy component, but with more features.  
 """  
 from pox.core import core  
 import pox.openflow.libopenflow_01 as of  
 import pox.lib.packet as pkt  
 import pox.lib.packet.dns as pkt_dns  
 from pox.lib.addresses import IPAddr  
 from pox.lib.addresses import IPAddr6  
 from pox.lib.revent import *  
 log = core.getLogger()  
 class DNSUpdate (Event):  
  def __init__ (self, item):  
   Event.__init__()  
   self.item = item  
 class DNSLookup (Event):  
  def __init__ (self, rr):  
   Event.__init__()  
   self.name = rr.name  
   self.qtype = rr.qtype  
   self.rr = rr  
   for t in pkt_dns.rrtype_to_str.values():  
    setattr(self, t, False)  
   t = pkt_dns.rrtype_to_str.get(rr.qtype)  
   if t is not None:  
    setattr(self, t, True)  
    setattr(self, "OTHER", False)  
   else:  
    setattr(self, "OTHER", True)  
 class DNSSpy (EventMixin):  
  _eventMixin_events = set([ DNSUpdate, DNSLookup ])  
  def __init__ (self, install_flow = True):  
   self._install_flow = install_flow  
   self.ip_to_name = {}  
   self.ipv6_to_name = {}  
   self.name_to_ip = {}  
   self.name_to_ipv6 = {}  
   self.cname = {}  
   core.openflow.addListeners(self)  
   # Add handy function to console  
   #core.Interactive.variables['lookup'] = self.lookup  
  def _handle_ConnectionUp (self, event):  
   if self._install_flow:  
    msg = of.ofp_flow_mod()  
    msg.match = of.ofp_match()  
    msg.match.dl_type = pkt.ethernet.IP_TYPE  
    msg.match.nw_proto = pkt.ipv4.UDP_PROTOCOL  
    msg.match.tp_src = 53  
    msg.actions.append(of.ofp_action_output(port = of.OFPP_CONTROLLER))  
    event.connection.send(msg)  
  #def lookup (self, something):  
  # if something in self.name_to_ip:  
  # return self.name_to_ip[something]  
  # if something in self.cname:  
  #  return self.lookup(self.cname[something])  
  # try:  
  #  return self.ip_to_name.get(IPAddr(something))  
  # except:  
  #  return None  
  def _record (self, ip, name):  
   # Handle reverse lookups correctly?  
   modified = False  
   val = self.ip_to_name.setdefault(ip, [])  
   if name not in val:  
    val.insert(0, name)  
    modified = True  
   val = self.name_to_ip.setdefault(name, [])  
   if ip not in val:  
    val.insert(0, ip)  
    modified = True  
   return modified  
  def _record_ipv6 (self, ip, name):  
   modified = False  
   val = self.ipv6_to_name.setdefault(ip, [])  
   if name not in val:  
    val.insert(0, name)  
    modified = True  
   val = self.name_to_ipv6.setdefault(name, [])  
   if ip not in val:  
    val.insert(0, ip)  
    modified = True  
   return modified  
  def _record_cname (self, name, cname):  
   modified = False  
   val = self.cname.setdefault(name, [])  
   if name not in val:  
    val.insert(0, cname)  
    modified = True  
   return modified  
  def _handle_PacketIn (self, event):  
   p = event.parsed.find('dns')  
   if p is not None and p.parsed:  
    log.debug(p)  
    for q in p.questions:  
     if q.qclass != 1: continue # Internet only  
     self.raiseEvent(DNSLookup, q)  
    def process_q (entry):  
     if entry.qclass != 1:  
      # Not internet  
      return  
     if entry.qtype == pkt.dns.rr.CNAME_TYPE:  
      if self._record_cname(entry.name, entry.rddata):  
       self.raiseEvent(DNSUpdate, entry.name)  
       log.info("add cname entry: %s %s" % (entry.rddata, entry.name))  
     elif entry.qtype == pkt.dns.rr.A_TYPE:  
      if self._record(entry.rddata, entry.name):  
       self.raiseEvent(DNSUpdate, entry.name)  
       log.info("add dns entry: %s %s" % (entry.rddata, entry.name))  
     elif entry.qtype == pkt.dns.rr.AAAA_TYPE:  
      if self._record_ipv6(entry.rddata, entry.name):  
       self.raiseEvent(DNSUpdate, entry.name)  
       log.info("add dns entry: %s %s" % (entry.rddata, entry.name))  
    for answer in p.answers:  
     process_q(answer)  
    for addition in p.additional:  
     process_q(addition)  
 def launch (no_flow = False):  
  core.registerNew(DNSSpy, not no_flow)  


Monday, April 21, 2014

OpenWRT Pivot overlay to external USB drive

I have tested this pivot overlay on TP-LINK WR1043ND v2.1 router

1. Compile custom firmware image as described in my previous post. For enabling usb select following packages in menuconfig.

kernel modules -> usb support -> kmod-usb-storage, kmod-usb-storage-extras, kmod-usb-uhci (If needed, ohci is selected by default)

kernel modules -> filesystems -> kmod-fs-ext4

Utilities -> Filesystem -> e2fsprogs

Utilities -> disc -> fdisk

Utilities -> usbutils

Base system -> block-mount

Alternately these packages can be installed using 'opkg install'

2. Create the linux partitions using fdisk as per your need

fdisk /dev/sda

m - Help
p - to print partition
n - new partition
d - delete partition

My partitions for example -

fdisk -l /dev/sda

Disk /dev/sda: 3.8 GiB, 4009754624 bytes, 7831552 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
Disklabel type: dos
Disk identifier: 0x00000000

Device    Boot     Start       End  Blocks  Id System
/dev/sda1           2048   7362559 3680256  83 Linux
/dev/sda2        7362560   7831551  234496  82 Linux swap / Solaris

3. Format the partition with ext4

mkfs.ext4 /dev/sda1

Now mount the filesystem

mkdir /mnt/sda1
mount /dev/sda1 /mnt/sda1

4. Copy contents from /overlay to usb device
tar -C /overlay -cvf - . | tar -C /mnt/sda1 -xf -

5. Generate and edit fstab file
block detect > /etc/config/fstab
vi /etc/config/fstab

change the target to '/overlay' & enabled option to '1'. Do not change UUID or other settings.

6. Restart the router.

7. Verify the mount after reboot (My output shown below).

Filesystem                Size      Used Available Use% Mounted on
rootfs                    3.4G      7.2M      3.2G   0% /
/dev/root                 3.0M      3.0M         0 100% /rom
tmpfs                    30.0M     48.0K     30.0M   0% /tmp
/dev/sda1                 3.4G      7.2M      3.2G   0% /overlay
overlayfs:/overlay        3.4G      7.2M      3.2G   0% /
tmpfs                   512.0K         0    512.0K   0% /dev

8. Block mount also detects other settings, fstab file after reboot with detected settings is shown below:

config 'global'
option anon_swap '0'
option anon_mount '0'
option auto_swap '1'
option auto_mount '1'
option delay_root '35'
option check_fs '0'

config 'mount'
option target '/overlay'
option uuid '4367f74a-86e8-4340-b8d2-fd458433f9d0'
option fstype 'ext4'
option options 'rw,sync'
option enabled_fsck '0'
option enabled '1'

References:
http://wiki.openwrt.org/doc/howto/extroot
http://wiki.openwrt.org/doc/uci/fstab

Running OpenWRT router as both OpenFlow switch and controller.


If your router does not have enough RAM, you would need to configure extroot/pivot overlay. If you have not already done so, you can see my previous post to configure that.

My other post details how to configure OpenWRT router as OpenFlow switch.

1. Install libffi and python-mini packages first as they are prerequisites. Then install python package. Only Python (2.7) package takes around 7.5 MB.

If you are installing using opkg install, prerequisite will be install automatically.

2. Install/get POX code directly on OpenWRT router or on local desktop and then SCP to router.

https://openflow.stanford.edu/display/ONL/POX+Wiki#POXWiki-GettingtheCode%2FInstallingPOX

3. Configure /etc/config/openflow: Since local openflow switch uses default port, for controller running on same router different port has to be used. So configure 'ofctl' parameter as below. All other settings remains same.

      option 'ofctl' 'tcp:127.0.0.1:6636'

4. For testing run openflow controller with new port as shown below:

cd ~/pox/
./pox.py log.level --DEBUG openflow.of_01 --port=6636 openflow.keepalive forwarding.l2_learning

openflow.keepalive parameter was required to avoid intermittent connection dropping between switch and controller.

References:
https://openflow.stanford.edu/display/ONL/POX+Wiki

Thursday, April 17, 2014

Observational Research at cafe in CMU

Observational Research 

We set out to observe the consumer behavior in one of the CMU’s cafe. We did this observation in two parts, first during noon on Monday and out of curiosity to compare the difference, the second one during morning hours on Tuesday. We noted that to reach same number of customer observations as that of afternoon it took around 50 minutes more in morning (double than that of afternoon). We made our other observations using certain set of parameters while people were making the purchase. Parameter categories include, Total Count of people, Gender, Type of their order, Menu Awareness, Payment Methodology, Location Preference, Group or Individual Purchase and the Effect of Item on Display. We also observed if there were any difference in all these preference for males and females. We discuss our findings for each parameter categories below.
For Type of Order category we observed if customer is buying drink, snack or both. Number of customers buying only drink was slightly more in morning than in afternoon (53%-60%), same for only snacks (6%-14%), but less customer purchased both drink & snacks (40%-26%). Considering genders, percent of male customers purchasing only drink was similar in afternoon and morning. Male customers who bought only snacks were tripled (5%-15%), while ones who bought both drink and snacks were decreased (35%-27%). Trend was similar for female customers in purchasing only snacks (7%-12%) and both drink & snacks (46%-24%) from afternoon to morning. But number of female customers purchasing only drink increased in morning (46%-64%). From these observations it can be concluded that almost 60% customers buy only drink. Female customers buy more snacks in afternoon, while same percent of male customers buy snacks during afternoon or morning.
For Payment Methodology category we observed whether customers preferred paying by cash or by card. We found that most of the purchases were being made using card but the major difference which we could observe was that 38% of people preferred cash in the morning while only 18% of the people preferred cash in the afternoon. Looking at the numbers we could conclude that more men preferred paying by card always, whereas women preferred paying by cash in the morning.
For Menu Awareness category we observed if customer was aware of the menu or not. Only 15% of total customers we observed asked for the menu. Number of female customers who asked the menu was significantly more (26%) compared to male customers (7%). Trend was similar in morning.
For Effect of Item on Display category we observed if the foods, which were on display, had any effect on the customer’s buying decision. In general a very small percentage of people preferred to buy the food, which was on display, in the morning this number was around 14% while in the afternoon it was about 20%. Both the times more percent of female customers were impacted by the food items on display.
For Location Preference category we observed if customers preferred to sit in the cafe to enjoy their food. What we understood from observing this cafe is that most customers who sit in the cafe don’t empty their seats for a long time. While 70% of customers preferred to take their food away, remaining 30% found place in cafe to have their food. Except that in morning more male customers preferred to sit in the cafe than in the afternoon. For female customers percentage was nearly same at both times.
For Purchasing Group category in total only 9% customers came in-group of two or more. 15% of female customers were in-group, while only 5% male were in-group in afternoon. The number was tripled for male customers (15%), while doubled for female customer (36%) in morning. This suggests during afternoon customer tend to purchase alone at coffee shop.
Another qualitative point during our observation we found was queue was building up at counter at certain time but used to clear within 5-10 minutes. If cashier was friendlier it took little bit more time to serve each customer, but there was more interaction with customers and they were leaving the counter with smile. Also most of the customers were students.
From all these observations we conclude that 60% customers were male while 40% were female. Majority of customers ordered drinks, almost all of them were aware of menu and majority of them took away the order. Majority of customers preferred to pay by card and most of them came individually.

Note 1: Quantitative data was recored on excel and can be downloaded from here

Note 2: This research was done as part of coursework for Marketing Research class at Tepper-CMU along with Vijith Venkatesh

Friday, March 14, 2014

Unbricking TP-LINK WR1043ND v2.1

In this blog I will detail the process to unbricking and connect WR1043ND to macbook pro using using serial connections on the 1043 board.

Hardware: windows 7 laptop, 1043ND, TTL to USB converter, soldering gun, etc.

1. First you need to open the device and solder the pins shown in v2.x picture as shown in first reference below.

2. Connect the USB to macbook pro.

3. If USB-TTL driver is not installed you will have to install the driver first.

In my case, my USB-TTL adapter used SILABS chip 2102 and I downloaded driver from: 

4. Make sure device is connected properly using below command. It should show device like name 'USBserial'
ls -lrt /dev/tty.*

5. Login to the serial prompt using below command
screen /dev/tty.SLAB_USBtoUART 115200

6. In my case network config was messed up, so I just corrected the network config and rebooted the router and it was working properly. I will post network config in other blog. If device needs to be reimaged steps in below link will be useful.
For using TFTP on my mac, below link will be useful. Using GUI is pretty intuitive.


My hardware setup for serial to USB connection is shown in below pictures for reference. I will update this post if I find more details.


Reference: