Add container support

Change-Id: Ieaf282d880797e64e67d5220255886d057fe56ef
diff --git a/trellis/docker/Dockerfile b/trellis/docker/Dockerfile
new file mode 100644
index 0000000..b799dbc
--- /dev/null
+++ b/trellis/docker/Dockerfile
@@ -0,0 +1,44 @@
+FROM ubuntu:18.04
+MAINTAINER Charles Chan <rascov@gmail.com>
+
+ENV HOME /root
+
+# Install dependencies
+WORKDIR $HOME
+RUN apt-get update && \
+    DEBIAN_FRONTEND=noninteractive apt-get -yq --no-install-recommends install git gawk texinfo python-pip build-essential iptables automake autoconf libtool openvswitch-switch mininet \
+    isc-dhcp-server isc-dhcp-client iputils-ping net-tools curl iproute2 ethtool && \
+    pip install ipaddress && \
+    rm -rf /var/lib/apt/lists/*
+
+# Install Quagga
+RUN git clone -b onos-1.11 https://gerrit.opencord.org/quagga
+WORKDIR $HOME/quagga
+RUN ./bootstrap.sh
+RUN ./configure --enable-fpm --sbindir=/usr/lib/quagga enable_user=root enable_group=root
+RUN make
+RUN make install
+
+# Clone Trellis simulation repo
+WORKDIR $HOME
+RUN git clone https://gerrit.onosproject.org/routing
+
+# Update dynamic linker
+RUN ldconfig
+
+# Fetch ONOS netcfg tools
+WORKDIR $HOME
+RUN curl -o /usr/local/bin/onos-netcfg https://raw.githubusercontent.com/opennetworkinglab/onos/onos-1.12/tools/package/runtime/bin/onos-netcfg
+RUN curl -o /usr/local/bin/_rest-port https://raw.githubusercontent.com/opennetworkinglab/onos/onos-1.12/tools/package/runtime/bin/_rest-port
+RUN curl -o /usr/local/bin/_find-node https://raw.githubusercontent.com/opennetworkinglab/onos/onos-1.12/tools/package/runtime/bin/_find-node
+RUN curl -o /usr/local/bin/_check-json https://raw.githubusercontent.com/opennetworkinglab/onos/onos-1.12/tools/package/runtime/bin/_check-json
+RUN chmod a+x /usr/local/bin/onos-netcfg /usr/local/bin/_rest-port /usr/local/bin/_find-node /usr/local/bin/_check-json
+
+# Copy useful Mininet utility
+COPY m $HOME
+
+# Copy start script
+COPY entrypoint.sh $HOME
+
+# Requirement for Mininet NAT class
+RUN touch /etc/network/interfaces
diff --git a/trellis/docker/entrypoint.sh b/trellis/docker/entrypoint.sh
new file mode 100755
index 0000000..481249f
--- /dev/null
+++ b/trellis/docker/entrypoint.sh
@@ -0,0 +1,23 @@
+#!/bin/bash
+
+# Select topology to emulate
+TOPO=${TOPO:-trellis}
+ONOS_HOST=${ONOS_HOST:-localhost}
+
+# Resolve ONOS IP
+ONOS_IP=`getent hosts $ONOS_HOSTNAME | awk '{ print $1 }'`
+
+# Start and configure OVS
+# Avoid using Linux service since it will attempt but fail the kernel module check
+/usr/share/openvswitch/scripts/ovs-ctl --no-ovs-vswitchd --no-monitor --system-id=random start
+/usr/sbin/ovs-vswitchd --detach
+ovs-vsctl set Open_vSwitch . other_config:vlan-limit=2
+
+# Push netcfg to ONOS
+cd routing/trellis
+echo ${ONOS_IP}
+head ${TOPO}.json
+onos-netcfg ${ONOS_IP} ${TOPO}.json
+
+# Start mininet
+./${TOPO}.py -c ${ONOS_IP}
diff --git a/trellis/docker/m b/trellis/docker/m
new file mode 100755
index 0000000..b0d9de6
--- /dev/null
+++ b/trellis/docker/m
@@ -0,0 +1,44 @@
+#!/bin/bash
+
+# Attach to a Mininet host and run a command
+
+if [ -z $1 ]; then
+  echo "usage: $0 host cmd [args...]"
+  exit 1
+else
+  host=$1
+fi
+
+pid=`ps ax | grep "mininet:$host$" | grep bash | grep -v mnexec | awk '{print $1};'`
+
+if echo $pid | grep -q ' '; then
+  echo "Error: found multiple mininet:$host processes"
+  exit 2
+fi
+
+if [ "$pid" == "" ]; then
+  echo "Could not find Mininet host $host"
+  exit 3
+fi
+
+if [ -z $2 ]; then
+  cmd='bash'
+else
+  shift
+  cmd=$*
+fi
+
+cgroup=/sys/fs/cgroup/cpu/$host
+if [ -d "$cgroup" ]; then
+  cg="-g $host"
+fi
+
+# Check whether host should be running in a chroot dir
+rootdir="/var/run/mn/$host/root"
+if [ -d $rootdir -a -x $rootdir/bin/bash ]; then
+    cmd="'cd `pwd`; exec $cmd'"
+    cmd="chroot $rootdir /bin/bash -c $cmd"
+fi
+
+cmd="exec mnexec $cg -a $pid $cmd"
+eval $cmd