Adding test setup script to run the tests inside a test container.
Adding documentation for running the tests
diff --git a/docs/running.md b/docs/running.md
index e69de29..8b69e39 100644
--- a/docs/running.md
+++ b/docs/running.md
@@ -0,0 +1,47 @@
+# Documentation
+
+Use the cord-setup.sh bash script to run the tests for your test environment.
+
+* In order to build a fresh test container before running the test, use the -b option like below:
+
+'''
+sudo ./cord-setup.sh -o onos:latest -a freeradius:latest -b onos:runtest -t dhcp-igmp
+'''
+
+* The above would build a docker container called onos:runtest before running the test.
+Otherwise it tries to spawn an existing test container called, onos:nosetest to run the tests.
+
+* To start the cord-tester, make sure you have onos and radius containers started and running.
+* Then you can start it with the container id or tag like below:
+
+'''
+sudo ./cord-setup.sh -o onos:latest -a freeradius:latest -t dhcp
+'''
+
+* The above would spawn a test container and run the dhcp test.
+
+* If you want to run a list of tests, just separate them with hypens.
+
+'''
+sudo ./cord-setup.sh -o onos:latest -a freeradius:latest -t dhcp-igmp-tls
+'''
+
+* If you want to run a specific test, you can give the classname.testname like below
+
+'''
+sudo ./cord-setup.sh -o onos:latest -a freeradius:latest -t dhcp:dhcp_exchange.test_dhcp_1request-igmp:test_igmp_1group_join_latency
+'''
+
+* If you want to spawn a test and kill the test container after the tests are done, specify the -k option like below.
+
+'''
+sudo ./cord-setup.sh -o onos:latest -a freeradius:latest -t dhcp -k
+'''
+
+* If you want to cleanup all the test containers by tag onos:nosetest, then use the -C cleanup option to cleanup test containers.
+
+'''
+sudo ./cord-setup.sh -o onos:latest -C onos:nosetest
+'''
+
+* For other options, run with -h option.
diff --git a/src/test/dhcp/dhcpTest.py b/src/test/dhcp/dhcpTest.py
index db21c3b..370861f 100644
--- a/src/test/dhcp/dhcpTest.py
+++ b/src/test/dhcp/dhcpTest.py
@@ -28,6 +28,7 @@
 
     def setUp(self):
         ''' Activate the dhcp app'''
+        self.maxDiff = None ##for assert_equal compare outputs on failure
         self.onos_ctrl = OnosCtrl(self.app)
         status, _ = self.onos_ctrl.activate()
         assert_equal(status, True)
@@ -42,7 +43,7 @@
         if status is False:
             log.info('JSON request returned status %d' %code)
             assert_equal(status, True)
-        time.sleep(2)
+        time.sleep(3)
 
     def onos_dhcp_table_load(self, config = None):
           dhcp_dict = {'apps' : { 'org.onosproject.dhcp' : { 'dhcp' : copy.copy(self.dhcp_server_config) } } }
@@ -84,11 +85,11 @@
             ip_map[cip] = sip
 
     def test_dhcp_1release(self, iface = 'veth0'):
-        config = {'startip':'10.10.10.20', 'endip':'10.10.10.69', 
-                  'ip':'10.10.10.2', 'mac': "ca:fe:ca:fe:ca:fe",
-                  'subnet': '255.255.255.0', 'broadcast':'10.10.10.255', 'router':'10.10.10.1'}
+        config = {'startip':'10.10.100.20', 'endip':'10.10.100.21', 
+                  'ip':'10.10.100.2', 'mac': "ca:fe:ca:fe:8a:fe",
+                  'subnet': '255.255.255.0', 'broadcast':'10.10.100.255', 'router':'10.10.100.1'}
         self.onos_dhcp_table_load(config)
-        self.dhcp = DHCPTest(seed_ip = '10.10.10.10', iface = iface)
+        self.dhcp = DHCPTest(seed_ip = '10.10.100.10', iface = iface)
         cip, sip = self.send_recv()
         log.info('Releasing ip %s to server %s' %(cip, sip))
         assert_equal(self.dhcp.release(cip), True)
@@ -100,11 +101,11 @@
         assert_equal(self.dhcp.release(cip2), True)
 
     def test_dhcp_Nrelease(self, iface = 'veth0'):
-        config = {'startip':'192.168.1.20', 'endip':'192.168.1.69', 
-                  'ip':'192.168.1.2', 'mac': "ca:fe:ca:fe:cc:fe",
-                  'subnet': '255.255.255.0', 'broadcast':'192.168.1.255', 'router': '192.168.1.1'}
+        config = {'startip':'192.170.1.20', 'endip':'192.170.1.30', 
+                  'ip':'192.170.1.2', 'mac': "ca:fe:ca:fe:9a:fe",
+                  'subnet': '255.255.255.0', 'broadcast':'192.170.1.255', 'router': '192.170.1.1'}
         self.onos_dhcp_table_load(config)
-        self.dhcp = DHCPTest(seed_ip = '192.169.1.10', iface = iface)
+        self.dhcp = DHCPTest(seed_ip = '192.170.1.10', iface = iface)
         ip_map = {}
         for i in range(10):
             cip, sip = self.send_recv(update_seed = True)
@@ -124,4 +125,7 @@
             ip_map2[cip] = sip
 
         log.info('Verifying released IPs were given back on rediscover')
+        if ip_map != ip_map2:
+            log.info('Map before release %s' %ip_map)
+            log.info('Map after release %s' %ip_map2)
         assert_equal(ip_map, ip_map2)
diff --git a/src/test/setup/cord-test.sh b/src/test/setup/cord-test.sh
new file mode 100755
index 0000000..bbaa286
--- /dev/null
+++ b/src/test/setup/cord-test.sh
@@ -0,0 +1,151 @@
+#!/usr/bin/env bash
+
+function show_help {
+    echo "Usage: ${0#*/} -h | this help -n <onos_ip> -r <radius_ip> -o <onos cnt image> -a <radius cnt image> -t <test type> -c | cleanup test containers -C <cleanup container list> -k | kill the test container -b <test cnt image> | build test container docker image"
+    exit 1
+}
+
+function cnt_ipaddr {
+    local image="${1}"
+    local cnt=`docker ps |grep "${image}" |awk '{print $1}'`
+    local ipaddr
+    ipaddr=`docker inspect -f '{{.NetworkSettings.IPAddress}}' $cnt`
+    echo $ipaddr
+}
+
+test_type=dhcp
+onos_cnt_image=onos:igmp-test
+radius_cnt_image=radius-server:dev
+onos_ip=
+radius_ip=
+OPTIND=1
+nose_cnt_image="onos:nosetest"
+cleanup=0
+kill_test_cnt=0
+build_cnt_image=
+cleanup_cnt_list=
+
+while getopts "h?n:r:o:a:t:cC:kb:" opt; do 
+    case "$opt" in
+        h|\?)
+            show_help
+            exit 1
+            ;;
+        t)
+            test_type=$OPTARG
+            ;;
+        n)
+            onos_ip=$OPTARG
+            ;;
+        r)
+            radius_ip=$OPTARG
+            ;;
+        o)
+            onos_cnt_image=$OPTARG
+            ;;
+        a)
+            radius_cnt_image=$OPTARG
+            ;;
+        c)
+            cleanup=1
+            ;;
+        C)
+            cleanup=1
+            cleanup_cnt_list=$OPTARG
+            ;;
+        k)
+            kill_test_cnt=1
+            ;;
+        b)
+            build_cnt_image=$OPTARG
+            ;;
+    esac
+done
+
+shift $(($OPTIND-1))
+
+if [ $# -gt 0 ]; then
+    echo "Invalid args"
+    show_help
+fi
+
+if [ $cleanup -eq 1 ]; then
+    if [ x"$cleanup_cnt_list" != "x" ]; then
+        IFS='-' read -r -a cleanup_list <<<"${cleanup_cnt_list}"
+        for container in "${cleanup_list[@]}"; do
+            cnt_id=`docker ps | grep "${container}" | awk '{print $1}'`
+            echo "Killing container $cnt_id"
+            docker kill $cnt_id
+        done
+        exit 0
+    fi
+    for container in `docker ps | grep "${nose_cnt_image}" | awk '{print $1}'`; do
+        echo "Killing test container $container"
+        docker kill $container
+    done
+    exit 0
+fi
+
+if [ x"$onos_ip" = "x" ]; then
+    onos_ip=$(cnt_ipaddr $onos_cnt_image)
+fi
+
+if [ x"$radius_ip" = "x" ]; then
+    radius_ip=$(cnt_ipaddr $radius_cnt_image)
+fi
+
+echo "Onos IP $onos_ip, Radius IP $radius_ip, Test type $test_type"
+sed "s,%%CONTROLLER%%,$onos_ip,g" of-bridge-template.sh > $HOME/nose_exp/of-bridge.sh
+
+if [ x"$build_cnt_image" != "x" ]; then
+    echo "Building test container docker image $build_cnt_image"
+    (cd test_docker && docker build -t $build_cnt_image . )
+    sleep 2
+    echo "Done building docker image $build_cnt_image"
+    nose_cnt_image=$build_cnt_image
+fi
+echo "Starting test container $nose_cnt_image"
+
+test_cnt=`docker run -itd --privileged -v $HOME/nose_exp:/root/test -v /lib/modules:/lib/modules -e ONOS_CONTROLLER_IP=$onos_ip -e ONOS_AAA_IP=$radius_ip $nose_cnt_image /bin/bash`
+echo "Setting up test container $test_cnt"
+docker exec $test_cnt pip install monotonic
+echo "Starting up the OVS switch on the test container $test_cnt"
+docker exec $test_cnt /root/test/of-bridge.sh br0
+status=0
+while [ $status -ne 0 ]; do
+    echo "Waiting for the switch to get connected to controller"
+    docker exec $test_cnt ovs-ofctl dump-flows br0  | grep "type=0x8942"
+    status=$?
+    sleep 1
+done
+sleep 3
+
+IFS='-' read -r -a tests <<<"${test_type}"
+for t in "${tests[@]}"; do
+    test_method="${t#*:}"
+    test="${t%%:*}"
+    case "$test" in
+        tls)
+            test_file="$test"AuthTest.py
+            ;;
+        *)
+            test_file="$test"Test.py
+            ;;
+    esac
+    if [ "$test_method" != "$t" ]; then
+        test_case="$test_file":"${test_method}"
+    else
+        test_case="$test_file"
+    fi
+    echo "Running test $test, test case $test_case"
+    docker exec $test_cnt nosetests -v /root/test/git/cord-tester/src/test/$test/"${test_case}"
+    echo "Test $t exited with status $?"
+done
+
+echo "Done running tests."
+
+if [ $kill_test_cnt -eq 1 ]; then
+    echo "Killing test container $test_cnt"
+    docker kill $test_cnt
+fi
+
diff --git a/src/test/setup/of-bridge-template.sh b/src/test/setup/of-bridge-template.sh
new file mode 100755
index 0000000..2b602c9
--- /dev/null
+++ b/src/test/setup/of-bridge-template.sh
@@ -0,0 +1,33 @@
+#!/usr/bin/env bash
+bridge="$1"
+controller="$2"
+if [ x"$bridge" = "x" ]; then
+  bridge="br0"
+fi
+if [ x"$controller" = "x" ]; then
+  controller="%%CONTROLLER%%"
+fi
+service openvswitch-switch restart
+num_ports=8
+ports=$(($num_ports-1))
+for vports in $(seq 0 2 $ports); do
+   echo "Deleting veth$vports"
+   ip link del veth$vports
+done
+for vports in $(seq 0 2 $ports); do
+  ip link add type veth
+  ifconfig veth$vports up
+  ifconfig veth$(($vports+1)) up
+done
+echo "Configuring ovs bridge $bridge"
+ovs-vsctl del-br $bridge
+ovs-vsctl add-br $bridge
+for i in $(seq 1 2 7); do
+  ovs-vsctl add-port $bridge veth$i
+done
+my_ip=`ifconfig eth0 | grep "inet addr" | tr -s ' ' | cut -d":" -f2 |cut -d" " -f1`
+ovs-vsctl set-controller $bridge ptcp:6653:$my_ip tcp:$controller:6633
+ovs-vsctl set controller $bridge max_backoff=1000
+ovs-vsctl set bridge $bridge protocols=OpenFlow10,OpenFlow11,OpenFlow12,OpenFlow13
+ovs-vsctl show
+ovs-ofctl show $bridge
diff --git a/src/test/setup/test_docker/Dockerfile b/src/test/setup/test_docker/Dockerfile
new file mode 100644
index 0000000..e0ef270
--- /dev/null
+++ b/src/test/setup/test_docker/Dockerfile
@@ -0,0 +1,21 @@
+FROM ubuntu
+MAINTAINER chetan@ciena.com
+
+LABEL RUN docker pull ubuntu:14.04
+LABEL RUN docker run -it --name nosetest ubuntu:14.04
+
+RUN apt-get update 
+RUN apt-get -y install git python python-pip python-setuptools python-scapy tcpdump doxygen doxypy
+RUN easy_install nose
+RUN apt-get -y install openvswitch-common openvswitch-switch
+WORKDIR /root
+RUN mkdir ovs
+COPY ./openvswitch-2.4.0.tar.gz /root
+COPY ./build_ovs.sh /root/
+RUN /root/build_ovs.sh
+RUN apt-get -y install python-twisted
+RUN pip install scapy-ssl_tls
+RUN pip install monotonic
+RUN mv /usr/sbin/tcpdump /sbin/
+RUN ln -sf /sbin/tcpdump /usr/sbin/tcpdump
+CMD ["/bin/bash"]
diff --git a/src/test/setup/test_docker/build_ovs.sh b/src/test/setup/test_docker/build_ovs.sh
new file mode 100755
index 0000000..093d8c5
--- /dev/null
+++ b/src/test/setup/test_docker/build_ovs.sh
@@ -0,0 +1,7 @@
+#!/usr/bin/env bash
+echo "OVS installation"
+cd /root/ && tar zxpvf openvswitch-2.4.0.tar.gz -C /root/ovs
+cd /root/ovs
+cd openvswitch-2.4.0 && ./configure --prefix=/usr --sysconfdir=/etc --localstatedir=/var --disable-ssl && make && make install
+service openvswitch-controller stop
+service openvswitch-switch restart
diff --git a/src/test/setup/test_docker/openvswitch-2.4.0.tar.gz b/src/test/setup/test_docker/openvswitch-2.4.0.tar.gz
new file mode 100644
index 0000000..135022b
--- /dev/null
+++ b/src/test/setup/test_docker/openvswitch-2.4.0.tar.gz
Binary files differ