CORD-2407 MME playbook

Change-Id: Ifce2c1cc225d7469827f5da509b84957a45457e1
diff --git a/xos/make_synchronizer_manifest.sh b/xos/make_synchronizer_manifest.sh
index 4609e85..5351287 100755
--- a/xos/make_synchronizer_manifest.sh
+++ b/xos/make_synchronizer_manifest.sh
@@ -1,5 +1,3 @@
-#! /bin/bash
-
 # Copyright 2017-present Open Networking Foundation
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
@@ -14,4 +12,5 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-find synchronizer -type f | cut -b 14- > synchronizer/manifest 
+#! /bin/bash
+find synchronizer -type f | cut -b 14- > synchronizer/manifest
diff --git a/xos/synchronizer/steps/roles/sprint_mme_setup/tasks/main.yml b/xos/synchronizer/steps/roles/sprint_mme_setup/tasks/main.yml
new file mode 100644
index 0000000..d5548fe
--- /dev/null
+++ b/xos/synchronizer/steps/roles/sprint_mme_setup/tasks/main.yml
@@ -0,0 +1,18 @@
+---
+- name: Copy templates
+  template:
+    src: "templates/{{ item }}.j2"
+    dest: "{{ source_path }}/{{ item }}"
+  with_items:
+    - vbfd.conf
+    - vbsm_cfg.txt
+
+- name: Run make_certs.sh command
+  shell: "./make_certs.sh mme {{ realm }}"
+  args:
+    chdir: "{{ source_path }}"
+
+- name: Run vb_acc
+  shell: "./vb_acc"
+  args:
+    chdir: "{{ source_path }}"
diff --git a/xos/synchronizer/steps/roles/sprint_mme_setup/templates/vbfd.conf.j2 b/xos/synchronizer/steps/roles/sprint_mme_setup/templates/vbfd.conf.j2
new file mode 100644
index 0000000..a3f4b90
--- /dev/null
+++ b/xos/synchronizer/steps/roles/sprint_mme_setup/templates/vbfd.conf.j2
@@ -0,0 +1,87 @@
+{#
+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.
+#}
+# -------- Test configuration ---------
+
+# Identity = "<diameter_host>.<diameter_realm>";
+Identity = "{{ identity }}";
+Realm = "{{ realm }}";
+# Port = 3868;
+# SecPort = 3869;
+
+ConnectPeer = "{{ connect_peer }}" { ConnectTo = "{{ s6a_hss_ip }}"; No_TLS; port = {{ hss_port }}; };
+
+# TLS_Cred = "<diameter_host>.cert.pem", "<diameter_host>.key.pem";
+TLS_Cred = "mme.cert.pem",
+	   "mme.key.pem";
+TLS_CA = "cacert.pem";
+
+LoadExtension = "/usr/local/lib/freeDiameter/dict_3gpp2_avps.fdx";
+#LoadExtension = "/usr/local/lib/freeDiameter/dict_CreditControl.fdx";
+#LoadExtension = "/usr/local/lib/freeDiameter/dict_base_rfc6733.fdx";
+LoadExtension = "/usr/local/lib/freeDiameter/dict_draftload_avps.fdx";
+LoadExtension = "/usr/local/lib/freeDiameter/dict_etsi283034_avps.fdx";
+LoadExtension = "/usr/local/lib/freeDiameter/dict_rfc4004_avps.fdx";
+LoadExtension = "/usr/local/lib/freeDiameter/dict_rfc4006bis_avps.fdx";
+LoadExtension = "/usr/local/lib/freeDiameter/dict_rfc4072_avps.fdx";
+LoadExtension = "/usr/local/lib/freeDiameter/dict_rfc4590_avps.fdx";
+LoadExtension = "/usr/local/lib/freeDiameter/dict_rfc5447_avps.fdx";
+LoadExtension = "/usr/local/lib/freeDiameter/dict_rfc5580_avps.fdx";
+LoadExtension = "/usr/local/lib/freeDiameter/dict_rfc5777_avps.fdx";
+LoadExtension = "/usr/local/lib/freeDiameter/dict_rfc5778_avps.fdx";
+LoadExtension = "/usr/local/lib/freeDiameter/dict_rfc6734_avps.fdx";
+LoadExtension = "/usr/local/lib/freeDiameter/dict_rfc6942_avps.fdx";
+LoadExtension = "/usr/local/lib/freeDiameter/dict_rfc7155_avps.fdx";
+LoadExtension = "/usr/local/lib/freeDiameter/dict_rfc7683_avps.fdx";
+LoadExtension = "/usr/local/lib/freeDiameter/dict_rfc7944_avps.fdx";
+LoadExtension = "/usr/local/lib/freeDiameter/dict_ts29061_avps.fdx";
+LoadExtension = "/usr/local/lib/freeDiameter/dict_ts29128_avps.fdx";
+LoadExtension = "/usr/local/lib/freeDiameter/dict_ts29154_avps.fdx";
+LoadExtension = "/usr/local/lib/freeDiameter/dict_ts29173_avps.fdx";
+LoadExtension = "/usr/local/lib/freeDiameter/dict_ts29212_avps.fdx";
+LoadExtension = "/usr/local/lib/freeDiameter/dict_ts29214_avps.fdx";
+LoadExtension = "/usr/local/lib/freeDiameter/dict_ts29215_avps.fdx";
+LoadExtension = "/usr/local/lib/freeDiameter/dict_ts29217_avps.fdx";
+LoadExtension = "/usr/local/lib/freeDiameter/dict_ts29229_avps.fdx";
+LoadExtension = "/usr/local/lib/freeDiameter/dict_ts29272_avps.fdx";
+LoadExtension = "/usr/local/lib/freeDiameter/dict_ts29273_avps.fdx";
+LoadExtension = "/usr/local/lib/freeDiameter/dict_ts29329_avps.fdx";
+LoadExtension = "/usr/local/lib/freeDiameter/dict_ts29336_avps.fdx";
+LoadExtension = "/usr/local/lib/freeDiameter/dict_ts29337_avps.fdx";
+LoadExtension = "/usr/local/lib/freeDiameter/dict_ts29338_avps.fdx";
+LoadExtension = "/usr/local/lib/freeDiameter/dict_ts29343_avps.fdx";
+LoadExtension = "/usr/local/lib/freeDiameter/dict_ts29344_avps.fdx";
+LoadExtension = "/usr/local/lib/freeDiameter/dict_ts29345_avps.fdx";
+LoadExtension = "/usr/local/lib/freeDiameter/dict_ts29368_avps.fdx";
+LoadExtension = "/usr/local/lib/freeDiameter/dict_ts29468_avps.fdx";
+LoadExtension = "/usr/local/lib/freeDiameter/dict_ts32299_avps.fdx";
+#LoadExtension = "/usr/local/lib/freeDiameter/dict_CxDx.fdx";
+#LoadExtension = "/usr/local/lib/freeDiameter/dict_Gx.fdx";
+#LoadExtension = "/usr/local/lib/freeDiameter/dict_NAS.fdx";
+#LoadExtension = "/usr/local/lib/freeDiameter/dict_Rf.fdx";
+#LoadExtension = "/usr/local/lib/freeDiameter/dict_Ro.fdx";
+#LoadExtension = "/usr/local/lib/freeDiameter/dict_Rx.fdx";
+LoadExtension = "/usr/local/lib/freeDiameter/dict_S6as6d.fdx";
+#LoadExtension = "/usr/local/lib/freeDiameter/dict_S6c.fdx";
+#LoadExtension = "/usr/local/lib/freeDiameter/dict_S6mS6n.fdx";
+LoadExtension = "/usr/local/lib/freeDiameter/dict_S6t.fdx";
+#LoadExtension = "/usr/local/lib/freeDiameter/dict_S9.fdx";
+#LoadExtension = "/usr/local/lib/freeDiameter/dict_SGd.fdx";
+#LoadExtension = "/usr/local/lib/freeDiameter/dict_SLh.fdx";
+#LoadExtension = "/usr/local/lib/freeDiameter/dict_Sd.fdx";
+#LoadExtension = "/usr/local/lib/freeDiameter/dict_Sh.fdx";
+#LoadExtension = "/usr/local/lib/freeDiameter/dict_T4.fdx";
+LoadExtension = "/usr/local/lib/freeDiameter/dict_T6aT6bT7.fdx";
+#LoadExtension = "/usr/local/lib/freeDiameter/dict_Tsp.fdx";
diff --git a/xos/synchronizer/steps/roles/sprint_mme_setup/templates/vbsm_cfg.txt.j2 b/xos/synchronizer/steps/roles/sprint_mme_setup/templates/vbsm_cfg.txt.j2
new file mode 100644
index 0000000..1df4b79
--- /dev/null
+++ b/xos/synchronizer/steps/roles/sprint_mme_setup/templates/vbsm_cfg.txt.j2
@@ -0,0 +1,91 @@
+{#
+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.
+#}
+# Configuration file for MME
+
+#####  NOTE: Please Do NOT change the order of the parameters #####
+
+# EGTP related
+VBSM_EG_DFLT_PORT                2123                     # EGTP Default port
+VBSM_EG_NONDFLT_PORT             2124                     # EGTP Non Default port
+VBSM_EG_S10_NONDFLT_PORT         2125                     # EGTP Non Default
+VBSM_EG_S3_NONDFLT_PORT          2126                     # EGTP Non Default port for S3 interface towards SGSN
+                                                          # port for S10
+VBSM_EG_DFLT_HOST_NAME           "sutlej.ccin.ccpu.com"   # EGTP host name
+
+
+# E-NodeB related
+VBSM_ENB_ADDR_1                  "{{ s1mme_enb_ip }}"      # IP address of eNodeB
+VBSM_ENB_PORT_1                  32767              # eNodeB port
+#VBSM_ENB_ADDR_2                  "172.26.20.180"      # IP address of eNodeB
+#VBSM_ENB_PORT_2                  36422              # eNodeB port
+
+# MME related
+VBSM_MME_IPADDR                  "{{ s1mme_mme_ip }}"    # MME IP address
+VBSM_MME_S1AP_IPADDR             "{{ s1mme_mme_ip }}"    # MME IP address associated with the S1AP interface
+VBSM_MME_EGTP_IPADDR             "{{ s11_mme_ip }}"    # MME IP address associated with the EGTP interface
+VBSM_MME_SCTP_PORT               36412           # MME SCTP port
+
+VBSM_SGW_IPADDR                  "{{ s11_sgw_ip }}"   # SGW IP address
+VBSM_PGW_IPADDR                  "192.168.1.105"    # PDN-GW IP address
+
+VBSM_UE_NUM                      32             # DEC_14_FIX: Changes to support 35 UE's
+VBSM_SCTP_UDP_SERV_TYPE          0              #service type,default 0 SCTP
+
+# Debug mask to be set; each represent
+#different debug masks to be set (1 and 0 to unset)
+#in the form |LVB_DBGMASK_INFO|LVB_DBGMASK_ERROR|LVB_DBGMASK_TRC|LVB_DBGMASK_MEM
+
+VBSM_MME_DBG_MASK                1111
+VBSM_DBG_MASK                    1111
+VBSM_NW_INIATED_DETACH_TIMER     1000
+
+VBSM_MCC_DIG1         2
+VBSM_MCC_DIG2         0
+VBSM_MCC_DIG3         8
+
+VBSM_MNC_DIG1         0
+VBSM_MNC_DIG2         1
+VBSM_MNC_DIG3         -1 
+
+# Target PLMN ID format [ MCC + MNC], + is concatination operator
+# If MNC has two digits, the last charater shall be 'f'
+# Valid Configurations: 11223f, 112345.
+VBSM_TARGET_MME_PLMN_ID          31310f
+VBSM_TARGET_MME_IP_ADDR          "192.25.1.100"
+
+VBSM_T3412                        32
+
+VBSM_SGSN_IP_ADDR                "192.25.1.195"
+
+
+VBSM_SGSN_PLMN_ID        31311f
+
+VBSM_FD_CFG  "vbfd.conf"
+VBSM_HSS_HOST "hss.openair4G.eur"
+VBSM_HSS_REALM "openair4G.eur"
+
+# set VBSM_DISABLE_EPC_DNS 0 - enable DNS,  1 - disable DNS
+VBSM_DISABLE_EPC_DNS 1
+VBSM_REL_CAP 1
+VBSM_MME_NAME "vmme_standalone"
+VBSM_S1C_SCTP_INSTREAMS 10
+VBSM_S1C_SCTP_OUTSTREAMS 10
+VBSM_MAX_ENB  2
+VBSM_NO_OFGUMMEIS 1
+VBSM_MMECODE  1
+VBSM_MMEGRPID 1
+VBSM_NO_OF_TAI 1
+VBSM_TAI_LIST    {{1,2,0,8,0,1,1}}
diff --git a/xos/synchronizer/steps/sync_vmmetenant.py b/xos/synchronizer/steps/sync_vmmetenant.py
index 2a0c617..c642bb8 100644
--- a/xos/synchronizer/steps/sync_vmmetenant.py
+++ b/xos/synchronizer/steps/sync_vmmetenant.py
@@ -37,4 +37,59 @@
     def __init__(self, *args, **kwargs):
         super(SyncVMMETenant, self).__init__(*args, **kwargs)
 
+    def get_extra_attributes(self, o):
+        fields = {}
 
+        fields['s6a_hss_ip']   = self.get_ip_address_from_peer_service_instance('s6a_network', 'VHSSTenant', o, 's6a_hss_ip')
+        fields['s1mme_enb_ip'] = o.enodeb_ip_addr
+        fields['s1mme_mme_ip'] = self.get_my_ip_address(o, 'flat_network_s1mme', 's1mme_mme_ip')
+        fields['s11_mme_ip']   = self.get_my_ip_address(o, 's11_network', 's11_mme_ip')
+        fields['s11_sgw_ip']   = self.get_ip_address_from_peer_service_instance('s11_network', 'VSPGWCTenant', o, 's11_sgw_ip')
+
+        return fields
+
+    def get_my_ip_address(self, o, network_name, parameter=None):
+        return self.get_ip_address_from_peer_service_instance_instance(network_name, o, o, parameter)
+
+    def get_ip_address_from_peer_service_instance(self, network_name, sitype, o, parameter=None):
+        peer_si = self.get_peer_serviceinstance_of_type(sitype, o)
+        return self.get_ip_address_from_peer_service_instance_instance(network_name, peer_si, o, parameter)
+
+    def get_ip_address_from_peer_service_instance_instance(self, network_name, peer_si, o, parameter=None):
+        try:
+            net_id = self.get_network_id(network_name)
+            ins_id = peer_si.leaf_model.instance_id
+            ip_address = Port.objects.get(
+                network_id=net_id, instance_id=ins_id).ip
+        except Exception:
+            self.log.error("Failed to fetch parameter",
+                           parameter=parameter,
+                           network_name=network_name)
+            self.defer_sync(o, "Waiting for parameters to become available")
+
+        return ip_address
+
+    def get_peer_serviceinstance_of_type(self, sitype, o):
+        prov_link_set = ServiceInstanceLink.objects.filter(
+            subscriber_service_instance_id=o.id)
+
+        try:
+            peer_service = next(
+                p.provider_service_instance for p in prov_link_set if p.provider_service_instance.leaf_model_name == sitype)
+        except StopIteration:
+            sub_link_set = ServiceInstanceLink.objects.filter(
+                provider_service_instance_id=o.id)
+            try:
+                peer_service = next(
+                    s.subscriber_service_instance for s in sub_link_set if s.subscriber_service_instance.leaf_model_name == sitype)
+            except StopIteration:
+                self.log.error(
+                    'Could not find service type in service graph', service_type=sitype, object=o)
+                raise ServiceGraphException(
+                    "Synchronization failed due to incomplete service graph")
+
+        return peer_service
+
+    # To get each network id
+    def get_network_id(self, network_name):
+        return Network.objects.get(name=network_name).id
\ No newline at end of file
diff --git a/xos/synchronizer/steps/vmmetenant_playbook.yaml b/xos/synchronizer/steps/vmmetenant_playbook.yaml
index 05c13c1..5d90590 100644
--- a/xos/synchronizer/steps/vmmetenant_playbook.yaml
+++ b/xos/synchronizer/steps/vmmetenant_playbook.yaml
@@ -13,11 +13,21 @@
 # limitations under the License.
 
 ---
-- hosts: {{ instance_name }} 
-  gather_facts: False 
-  connection: ssh 
-  user: ubuntu 
-  sudo: yes 
-  tasks: 
+- hosts: {{ instance_name }}
+  gather_facts: False
+  connection: ssh
+  remote_user: ubuntu
+  become: yes
   vars:
- 
+    - source_path: /home/c3po/mme
+    - identity: "mme.localdomain"
+    - realm: "localdomain"
+    - connect_peer: "hss.openair4G.eur"
+    - hss_port: 3868
+    - s6a_hss_ip: {{ s6a_hss_ip }}
+    - s1mme_enb_ip: {{ s1mme_enb_ip }}
+    - s1mme_mme_ip: {{ s1mme_mme_ip }}
+    - s11_mme_ip: {{ s11_mme_ip }}
+    - s11_sgw_ip: {{ s11_sgw_ip }}
+  roles:
+    - sprint_mme_setup
diff --git a/xos/vmme.xproto b/xos/vmme.xproto
index 811d3e3..d8a4260 100644
--- a/xos/vmme.xproto
+++ b/xos/vmme.xproto
@@ -16,6 +16,7 @@
 message VMMETenant (TenantWithContainer){
     option verbose_name = "Virtual Mobility Management Entity Service Instance";
 
-    optional manytoone vmme_vendor->VMMEVendor:vendor_tenants = 1 [help_text = "select vendor of choice, leave blank for slice default", db_index = True, null = True, blank = True]; 
+    optional manytoone vmme_vendor->VMMEVendor:vendor_tenants = 1 [help_text = "select vendor of choice, leave blank for slice default", db_index = True, null = True, blank = True];
+    optional string enodeb_ip_addr = 2 [help_text = "external eNodeB IP address", max_length = 32, null = True, db_index = False, blank = True];
 }