AETHER-724 Include vfioveth CNI and clean up Dockerfile

Change-Id: If6ebc78e8c19cdce42e279a503ce51287b074b75
diff --git a/Dockerfile b/Dockerfile
index 1fd5014..abc9ffc 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -14,43 +14,17 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-# Build sriov plugin
-FROM golang:1.10 AS sriov-cni
-RUN git clone -q -b dev/k8s-deviceid-model https://github.com/Intel-Corp/sriov-cni.git /go/src/github.com/intel-corp/sriov-cni
-WORKDIR /go/src/github.com/intel-corp/sriov-cni
-RUN ./build
-
-# Build sriov device plugin
-FROM golang:1.10 AS sriov-dp
-RUN git clone -q https://github.com/intel/sriov-network-device-plugin.git /go/src/github.com/intel/sriov-network-device-plugin
-WORKDIR /go/src/github.com/intel/sriov-network-device-plugin
-RUN make
-
-# Build centralip ipam plugin
-FROM golang:1.10 AS centralip-ipam
-RUN go get -u github.com/kardianos/govendor
-RUN git clone -q https://github.com/John-Lin/ovs-cni.git /go/src/github.com/John-Lin/ovs-cni
-WORKDIR /go/src/github.com/John-Lin/ovs-cni
-RUN govendor sync && ./build.sh
-
-# Build vfioveth plugin
-FROM busybox as vfioveth
-RUN wget -O /bin/vfioveth https://raw.githubusercontent.com/clearlinux/cloud-native-setup/master/clr-k8s-examples/9-multi-network/cni/vfioveth
-RUN wget -O /bin/jq https://github.com/stedolan/jq/releases/download/jq-1.6/jq-linux64
-RUN chmod +x /bin/vfioveth /bin/jq
-
-# Copy static IPAM plugin
 FROM busybox as static
 RUN wget https://github.com/containernetworking/plugins/releases/download/v0.8.2/cni-plugins-linux-amd64-v0.8.2.tgz
 RUN tar xvfz cni-plugins-linux-amd64-v0.8.2.tgz
 RUN cp ./static /bin/static
+RUN wget https://github.com/stedolan/jq/releases/download/jq-1.6/jq-linux64
+RUN cp ./jq-linux64 /bin/jq
+RUN chmod +x /bin/static /bin/jq
 
-# Final image
 FROM centos/systemd as omec-cni
 WORKDIR /tmp/cni/bin
-COPY --from=sriov-cni /go/src/github.com/intel-corp/sriov-cni/bin/sriov .
-COPY --from=vfioveth /bin/vfioveth .
-COPY --from=vfioveth /bin/jq .
+COPY vfioveth .
+COPY --from=nfvpe/sriov-cni:v2.5 /usr/bin/sriov .
+COPY --from=static /bin/jq .
 COPY --from=static /bin/static .
-WORKDIR /usr/bin
-COPY --from=sriov-dp /go/src/github.com/intel/sriov-network-device-plugin/build/sriovdp .
diff --git a/VERSION b/VERSION
index 6d7de6e..9084fa2 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-1.0.2
+1.1.0
diff --git a/vfioveth b/vfioveth
new file mode 100755
index 0000000..8fb1e5a
--- /dev/null
+++ b/vfioveth
@@ -0,0 +1,70 @@
+#!/bin/bash -x
+
+set -o errexit
+set -o pipefail
+set -o nounset
+
+exec 3>&1
+exec &>>/var/log/$(basename $0).log
+
+PATH="$CNI_PATH:$(dirname "${BASH_SOURCE[0]}"):$PATH"
+CNI_CONF=$(cat /dev/stdin)
+
+get_peer_name() {
+	echo "$1-vdev"
+}
+
+get_mac_with_vfpci() {
+	local pf=$(readlink /sys/devices/pci*/*/$1/physfn | awk '{print substr($1,4)}')
+	local pfName=$(ls /sys/devices/pci*/*/$pf/net/ | head -1)
+	local idx=$(ls -l /sys/devices/pci*/*/$pf | awk -v vf=$1 'substr($11,4)==vf {print substr($9,7)}')
+	local mac=$(ip link show dev $pfName | awk -v idx="$idx" '$1=="vf" && $2==idx {print substr($4,1,17)}')
+	echo $mac
+}
+
+ipam() {
+	local plugin=$(echo $CNI_CONF | jq -r '.ipam.type')
+	local res=$(echo $"$CNI_CONF" | "$plugin" | jq -c '.')
+	echo $res
+}
+
+add_pair_ns() {
+	vfpci=$(echo $CNI_CONF | jq -r '.deviceID')
+	mac=$(echo $CNI_CONF | jq -r '.runtimeConfig.mac')
+	if [ -z "$mac" ]; then
+		mac=$(get_mac_with_vfpci $vfpci)
+	fi
+	peer=$(get_peer_name $CNI_IFNAME)
+	ip=$1
+
+	mkdir -p /var/run/netns/
+	ln -sfT $CNI_NETNS /var/run/netns/$CNI_CONTAINERID
+
+	ip netns exec $CNI_CONTAINERID ip link add $CNI_IFNAME type veth peer name $peer
+	ip netns exec $CNI_CONTAINERID ip link set $CNI_IFNAME addr $mac up alias $vfpci
+	ip netns exec $CNI_CONTAINERID ip link set $peer up
+	ip netns exec $CNI_CONTAINERID ip addr add $ip dev $CNI_IFNAME
+}
+
+delete_pair_ns() {
+	ip netns exec $CNI_CONTAINERID ip link del $CNI_IFNAME
+}
+
+case $CNI_COMMAND in
+ADD)
+	res=$(ipam)
+	ip=$(echo $res | jq -r '.ips[0].address')
+	add_pair_ns $ip
+	echo '{"cniVersion":"0.3.1"}' | jq -c --arg ip $ip '.ips[0].address = $ip' >&3
+	;;
+DEL)
+	set +o errexit
+	ipam
+	delete_pair_ns
+	set -o errexit
+	;;
+*)
+	echo "CNI_COMMAND=[ADD|DEL] only supported"
+	exit 1
+	;;
+esac