[CORD-1977] Change Ansible Playbook code for changed image and implement build_and_run

Change-Id: Ia60f0daff0bbabf90c023849c3ce21e795d711b1
(cherry picked from commit 2cc578b1defd9e41dca01c8422dec730eeba6e9a)
diff --git a/xos/synchronizer/steps/roles/build_and_run/tasks/main.yml b/xos/synchronizer/steps/roles/build_and_run/tasks/main.yml
new file mode 100644
index 0000000..44167c2
--- /dev/null
+++ b/xos/synchronizer/steps/roles/build_and_run/tasks/main.yml
@@ -0,0 +1,42 @@
+# Copyright 2017-present Open Networking Foundation
+#
+# 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.
+
+---
+
+# Make shell script to run vSPGW-C with log
+- name: make run with log file
+  become: yes
+  template:
+    src=run_with_log.sh.j2
+    dest="{{source_path}}/dp/run_with_log.sh" owner=root group=root mode=755
+
+- name: build and run vspgwu
+  become: yes
+  shell: "{{ item }}"
+  args:
+    chdir: "{{ source_path }}/dp"
+  environment:
+    NG_CORE: "{{ source_path }}"
+    RTE_SDK: "{{ source_path }}/dpdk"
+    RTE_TARGET: "x86_64-native-linuxapp-gcc"
+    HYPERSCANDIR: "/root/ngic/hyperscan-4.1.0"
+  with_items:
+    - make clean
+    - make
+    - ./run_with_log.sh
+
+# Finish
+- name: write flag
+  become: yes
+  shell: "echo 1 > {{source_path}}/dp/finish_flag_build_and_run"
diff --git a/xos/synchronizer/steps/roles/build_and_run/templates/run_with_log.sh.j2 b/xos/synchronizer/steps/roles/build_and_run/templates/run_with_log.sh.j2
new file mode 100644
index 0000000..231c296
--- /dev/null
+++ b/xos/synchronizer/steps/roles/build_and_run/templates/run_with_log.sh.j2
@@ -0,0 +1,16 @@
+#! /bin/bash
+# Copyright 2017-present Open Networking Foundation
+#
+# 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.
+
+./udev.sh > results &
\ No newline at end of file
diff --git a/xos/synchronizer/steps/roles/interface_config/tasks/main.yml b/xos/synchronizer/steps/roles/interface_config/tasks/main.yml
index f7b3321..5f25326 100644
--- a/xos/synchronizer/steps/roles/interface_config/tasks/main.yml
+++ b/xos/synchronizer/steps/roles/interface_config/tasks/main.yml
@@ -24,16 +24,22 @@
     src=interface.cfg.j2
     dest="{{source_path}}/config/interface.cfg" owner=root group=root mode=755
 
+- name: make static_arp config file
+  become: yes
+  template:
+    src=static_arp.cfg.j2
+    dest="{{source_path}}/config/static_arp.cfg" owner=root group=root mode=755
+
 - name: get date
   shell: date +"%Y-%m-%d_%H-%M"
   register: tmp_date
 
 - name: get port_0 value
-  shell: lspci -v -k | grep -i 'ethernet' | head -n 1 | tail -n 1 | awk '{print "0000:"$1}'
+  shell: "ifconfig | grep -B 1 {{ s1u_ip }} | awk '{print $1}' | head -n 1"
   register: tmp_port_0
 
 - name: get port_1 value
-  shell: lspci -v -k | grep -i 'ethernet' | head -n 2 | tail -n 1 | awk '{print "0000:"$1}'
+  shell: "ifconfig | grep -B 1 {{ sgi_ip }} | awk '{print $1}' | head -n 1"
   register: tmp_port_1
 
 - name: get s1u_mac value
@@ -58,16 +64,12 @@
     src=dp_config.cfg.j2
     dest="{{source_path}}/config/dp_config.cfg" owner=root group=root mode=755
 
-#- name: Build ngic
-#  become: yes
-#  shell: "{{ item }}"
-#  args:
-#    chdir: "{{ source_path }}"
-#  environment:
-#    NG_CORE: "{{ source_path }}"
-#    RTE_SDK: "{{ source_path }}/dpdk"
-#    RTE_TARGET: "x86_64-native-linuxapp-gcc"
-#    HYPERSCANDIR: "/root/ngic/hyperscan-4.1.0"
-#  with_items:
-#    - make
-#    - /root/ngic/dp/run.sh -c 1
+- name: change Makefile.j2
+  become: yes
+  template:
+    src=Makefile.j2
+    dest="{{source_path}}/dp/Makefile" owner=root group=root mode=755
+
+- name: write flag for interface_config
+  become: yes
+  shell: "echo 1 > {{source_path}}/dp/finish_flag_interface_config"
\ No newline at end of file
diff --git a/xos/synchronizer/steps/roles/interface_config/templates/Makefile.j2 b/xos/synchronizer/steps/roles/interface_config/templates/Makefile.j2
new file mode 100644
index 0000000..f7939e1
--- /dev/null
+++ b/xos/synchronizer/steps/roles/interface_config/templates/Makefile.j2
@@ -0,0 +1,167 @@
+ifeq ($(RTE_SDK),)
+$(error "Please define RTE_SDK environment variable")
+endif
+
+MAKEFLAGS += -j
+
+# Default target, can be overriden by command line or environment
+RTE_TARGET ?= x86_64-native-linuxapp-gcc
+
+include $(RTE_SDK)/mk/rte.vars.mk
+include $(NG_CORE)/config/ng-core_cfg.mk
+
+#DIRS-y += pipeline
+# binary name
+APP = ngic_dataplane
+# all source are stored in SRCS-y
+SRCS-y := main.c\
+	pkt_handler.c\
+	cdr.c\
+	master_cdr.c\
+	session_cdr.c\
+	config.c\
+	init.c\
+	dataplane.c\
+	gtpu.c\
+	ether.c\
+	ipv4.c\
+	util.c\
+	acl.c\
+	meter.c\
+	adc_table.c\
+	pcc_table.c\
+	sess_table.c\
+	commands.c\
+	stats.c\
+	ddn_utils.c\
+	pipeline/epc_load_balance.o\
+	pipeline/epc_packet_framework.o\
+	pipeline/epc_tx.o\
+	pipeline/epc_rx.o\
+	pipeline/epc_worker.o\
+	pipeline/epc_arp_icmp.o\
+	pipeline/epc_spns_dns.o\
+	$(SRCDIR)/../interface/interface.o\
+	$(SRCDIR)/../cp_dp_api/vepc_cp_dp_api.o\
+	$(SRCDIR)/../test/simu_cp/nsb/nsb_test_util.o\
+	$(SRCDIR)/../test/simu_cp/simu_cp.o\
+	$(SRCDIR)/../interface/ipc/dp_ipc_api.o\
+	$(SRCDIR)/../interface/udp/vepc_udp.o\
+
+CFLAGS += -I$(SRCDIR)/
+CFLAGS += -I$(SRCDIR)/../interface
+CFLAGS += -I$(SRCDIR)/../interface/ipc
+CFLAGS += -I$(SRCDIR)/../interface/udp
+CFLAGS += -I$(SRCDIR)/../interface/sdn
+CFLAGS += -I$(SRCDIR)/../interface/zmq
+CFLAGS += -I$(SRCDIR)/../cp_dp_api
+CFLAGS += -I$(SRCDIR)/../test/simu_cp
+CFLAGS += -I$(SRCDIR)/../test/simu_cp/nsb
+CFLAGS += -I$(SRCDIR)/pipeline
+CFLAGS += -I$(SRCDIR)/../cp
+CFLAGS += -I$(SRCDIR)/../lib/libsponsdn
+
+CFLAGS += -Wno-psabi # suppress "The ABI for passing parameters with 64-byte alignment has changed in GCC 4.6"
+
+
+CFLAGS += -DLDB_DP	# should be included for dataplane.
+
+ifneq (,$(findstring SDN_ODL_BUILD, $(CFLAGS)))
+	SRCS-y += $(SRCDIR)/../interface/zmq/zmqsub.o
+	SRCS-y += $(SRCDIR)/../interface/zmq/zmqpub.o
+	LDFLAGS += -L/usr/local/lib -lzmq
+endif
+#CFLAGS += -g -O3
+CFLAGS += -g -O0
+
+# Un-comment below line to read fake cp config.
+#CFLAGS += -DSIMU_CP
+
+# ASR- Un-comment below line to enable GTPU HEADER Sequence Number option.
+#CFLAGS += -DGTPU_HDR_SEQNB
+
+# ASR- Un-comment below line to enable PCC, ADC, CDR, FILTERING, METERING pipeline stages.
+#CFLAGS += -DINCLUDE_PIPELINE_STAGE
+
+# Un-comment below line to enable PCC, ADC, CDR, FILTERING, METERING pipeline stages.
+#CFLAGS += -DINCLUDE_ADC_STAGE
+
+# Un-comment below line to enable PCC, ADC, CDR, FILTERING, METERING pipeline stages.
+#CFLAGS += -DINCLUDE_MTR_STAGE
+
+# Un-comment below line to enable NIC and pipeline stats.
+#CFLAGS += -DSTATS
+
+# Un-comment below line to get stats from command line (for test harness)
+#CFLAGS += -DCMDLINE_STATS
+
+# Un-comment below line to clear STATS after reading.
+#CFLAGS += -DSTATS_CLR
+
+# Un-comment below line to enable pipeline out stats, STATS flag should be enabled.
+#CFLAGS += -DOSTATS
+
+# Un-comment below line to enable DNS stats.
+CFLAGS += -DDNS_STATS
+
+# Un-comment below line to enable core RX and core TX. All
+# processing stages will be skipped.
+#CFLAGS += -DRX_TX
+
+# Un-comment below line to skip RX Meta access
+#CFLAGS += -DSKIP_RX_META
+
+# Un-comment below line to enable core RX, core LB and core TX. All
+# processing stages will be skipped.
+#CFLAGS += -DRX_LB_TX
+
+# Un-comment below line to enable SDF Metering
+#CFLAGS += -DSDF_MTR
+
+# Un-comment below line to enable APN Metering
+#CFLAGS += -DAPN_MTR
+
+# Un-comment below line to enable ADC upfront.
+CFLAGS += -DADC_UPFRONT
+
+# Un-comment below line to enable hyperscan DPI.
+#CFLAGS += -DHYPERSCAN_DPI
+
+# Un-comment below line to enable Rating group CDRs.
+#CFLAGS += -DRATING_GRP_CDR
+
+# Un-comment below line to skip LB rte_hash_crc_4byte
+# and enable LB based on UE ip last byte.
+#CFLAGS += -DSKIP_LB_HASH_CRC
+
+# set SGI port action handler equal to S1U action handler.
+#CFLAGS += -DSKIP_LB_GTPU_AH
+
+# Un-comment below line to read acl rules from file.
+#CFLAGS += -DACL_READ_CFG
+
+# Un-comment below line if you have 16 x 1GB hugepages.
+#CFLAGS += -DHUGE_PAGE_16GB
+
+# Un-comment below line to configure DP Tables from DP app.
+CFLAGS += -DDP_TABLE_CONFIG
+
+CFLAGS += -Werror
+CFLAGS += -Wunused-variable
+CFLAGS_config.o := -D_GNU_SOURCE
+
+# workaround for a gcc bug with noreturn attribute
+#  http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12603
+ifeq ($(CONFIG_RTE_TOOLCHAIN_GCC),y)
+CFLAGS_dataplane.o += -Wno-return-type
+endif
+
+LDFLAGS += -L$(RTE_SRCDIR)/../lib/libsponsdn/libsponsdn/x86_64-native-linuxapp-gcc/ -lsponsdn
+
+LDFLAGS += -L$(HYPERSCANDIR)/build/lib
+
+LDFLAGS += -lexpressionutil -lhs -lhs_runtime -lstdc++ -lm -lcrypto
+
+LDFLAGS += -lrte_pmd_af_packet
+
+include $(RTE_SDK)/mk/rte.extapp.mk
\ No newline at end of file
diff --git a/xos/synchronizer/steps/roles/interface_config/templates/dp_config.cfg.j2 b/xos/synchronizer/steps/roles/interface_config/templates/dp_config.cfg.j2
index 915c875..17081fd 100644
--- a/xos/synchronizer/steps/roles/interface_config/templates/dp_config.cfg.j2
+++ b/xos/synchronizer/steps/roles/interface_config/templates/dp_config.cfg.j2
@@ -1,7 +1,8 @@
 NOW={{ date }}
 FILE="logs/dp_{{ date }}.log"
-PORT0={{ port_0 }}
-PORT1={{ port_1 }}
+
+S1U_IFACE={{ port_0 }}
+SGI_IFACE={{ port_1 }}
 
 S1U_IP={{ s1u_ip }}
 S1U_MAC={{ s1u_mac }}
diff --git a/xos/synchronizer/steps/roles/interface_config/templates/static_arp.cfg.j2 b/xos/synchronizer/steps/roles/interface_config/templates/static_arp.cfg.j2
new file mode 100644
index 0000000..476e2c6
--- /dev/null
+++ b/xos/synchronizer/steps/roles/interface_config/templates/static_arp.cfg.j2
@@ -0,0 +1,24 @@
+; Copyright 2017-present Open Networking Foundation
+;
+; 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.
+
+; static arp entries are per port; syntax:
+; ipv4 [ipv4] = ethernet mac address
+
+[sgi]
+;115.0.0.14 115.0.0.14    = fa:16:3e:13:20:79
+{{ as_sgi_ip }} {{ as_sgi_ip }} = {{ as_sgi_mac }}
+
+[s1u]
+;111.0.0.14 111.0.0.14    = fa:16:3e:94:d9:7b
+{{ enb_s1u_ip }} {{ enb_s1u_ip }} = {{ enb_s1u_mac }}
\ No newline at end of file