JianHao | 4a9550f | 2017-10-19 11:05:14 +0800 | [diff] [blame] | 1 | # Copyright 2017-present Open Networking Foundation |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | # you may not use this file except in compliance with the License. |
| 5 | # You may obtain a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | # See the License for the specific language governing permissions and |
| 13 | # limitations under the License. |
| 14 | |
| 15 | import os |
| 16 | import sys |
Woojoong Kim | 4f09cbf | 2017-11-19 21:25:37 -0800 | [diff] [blame] | 17 | import time |
JianHao | 4a9550f | 2017-10-19 11:05:14 +0800 | [diff] [blame] | 18 | from django.db.models import Q, F |
| 19 | from synchronizers.new_base.modelaccessor import * |
| 20 | from synchronizers.new_base.SyncInstanceUsingAnsible import SyncInstanceUsingAnsible |
| 21 | |
| 22 | parentdir = os.path.join(os.path.dirname(__file__), "..") |
| 23 | sys.path.insert(0, parentdir) |
| 24 | |
Sapan Bhatia | 28b7560 | 2017-11-28 14:18:21 -0500 | [diff] [blame] | 25 | class ServiceGraphException(Exception): |
| 26 | pass |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 27 | |
JianHao | 4a9550f | 2017-10-19 11:05:14 +0800 | [diff] [blame] | 28 | class SyncVSPGWCTenant(SyncInstanceUsingAnsible): |
JianHao | 4a9550f | 2017-10-19 11:05:14 +0800 | [diff] [blame] | 29 | observes = VSPGWCTenant |
JianHao | 4a9550f | 2017-10-19 11:05:14 +0800 | [diff] [blame] | 30 | template_name = "vspgwctenant_playbook.yaml" |
JianHao | 4a9550f | 2017-10-19 11:05:14 +0800 | [diff] [blame] | 31 | service_key_name = "/opt/xos/configurations/mcord/mcord_private_key" |
| 32 | |
| 33 | def __init__(self, *args, **kwargs): |
| 34 | super(SyncVSPGWCTenant, self).__init__(*args, **kwargs) |
| 35 | |
Woojoong Kim | f000eda | 2017-10-20 15:00:43 -0700 | [diff] [blame] | 36 | def get_extra_attributes(self, o): |
JianHao | 4a9550f | 2017-10-19 11:05:14 +0800 | [diff] [blame] | 37 | |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 38 | scenario = self.get_scenario(o) |
JianHao | 4a9550f | 2017-10-19 11:05:14 +0800 | [diff] [blame] | 39 | |
Woojoong Kim | 4f09cbf | 2017-11-19 21:25:37 -0800 | [diff] [blame] | 40 | if scenario == 'normal_scenario': |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 41 | return self.get_values_for_normal_scenario(o) |
Woojoong Kim | 4f09cbf | 2017-11-19 21:25:37 -0800 | [diff] [blame] | 42 | elif scenario == 'normal_scenario_without_sdncontroller': |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 43 | return self.get_values_for_normal_scenario_wo_sdncontroller(o) |
Woojoong Kim | 4f09cbf | 2017-11-19 21:25:37 -0800 | [diff] [blame] | 44 | elif scenario == 'emulator_scenario': |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 45 | return self.get_values_for_emulator_scenario(o) |
Woojoong Kim | 4f09cbf | 2017-11-19 21:25:37 -0800 | [diff] [blame] | 46 | elif scenario == 'emulator_scenario_without_sdncontroller': |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 47 | return self.get_values_for_emulator_scenario_wo_sdncontroller(o) |
Woojoong Kim | f000eda | 2017-10-20 15:00:43 -0700 | [diff] [blame] | 48 | else: |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 49 | return self.get_extra_attributes_for_manual(o) |
Woojoong Kim | f000eda | 2017-10-20 15:00:43 -0700 | [diff] [blame] | 50 | |
| 51 | # fields for manual case |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 52 | def get_extra_attributes_for_manual(self, o): |
Woojoong Kim | f000eda | 2017-10-20 15:00:43 -0700 | [diff] [blame] | 53 | fields = {} |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 54 | fields['scenario'] = self.get_scenario(o) |
Woojoong Kim | f000eda | 2017-10-20 15:00:43 -0700 | [diff] [blame] | 55 | # for interface.cfg file |
| 56 | fields['zmq_sub_ip'] = "manual" |
| 57 | fields['zmq_pub_ip'] = "manual" |
| 58 | fields['dp_comm_ip'] = "manual" |
| 59 | fields['cp_comm_ip'] = "manual" |
| 60 | fields['fpc_ip'] = "manual" |
| 61 | fields['cp_nb_server_ip'] = "manual" |
| 62 | |
| 63 | # for cp_config.cfg file |
| 64 | fields['s11_sgw_ip'] = "manual" |
| 65 | fields['s11_mme_ip'] = "manual" |
| 66 | fields['s1u_sgw_ip'] = "manual" |
| 67 | |
Woojoong Kim | 4f09cbf | 2017-11-19 21:25:37 -0800 | [diff] [blame] | 68 | # for rules setup in ONOS |
| 69 | fields['sgi_as_ip'] = "manual" |
| 70 | fields['sgi_spgwu_ip'] = "manual" |
| 71 | |
Woojoong Kim | f000eda | 2017-10-20 15:00:43 -0700 | [diff] [blame] | 72 | return fields |
| 73 | |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 74 | def get_values_for_normal_scenario(self, o): |
Woojoong Kim | 1a1e370 | 2017-10-27 13:26:34 -0700 | [diff] [blame] | 75 | fields = {} |
Woojoong Kim | 4f09cbf | 2017-11-19 21:25:37 -0800 | [diff] [blame] | 76 | fields['scenario'] = "normal_scenario" |
Woojoong Kim | 1a1e370 | 2017-10-27 13:26:34 -0700 | [diff] [blame] | 77 | # for interface.cfg file |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 78 | fields['zmq_sub_ip'] = self.get_ip_address_from_peer_service_instance( |
Sapan Bhatia | 9753629 | 2017-11-27 21:35:34 -0500 | [diff] [blame] | 79 | 'sbi_network', "SDNControllerServiceInstance", o, 'zmq_sub_ip') |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 80 | fields['zmq_pub_ip'] = self.get_ip_address_from_peer_service_instance( |
Sapan Bhatia | 9753629 | 2017-11-27 21:35:34 -0500 | [diff] [blame] | 81 | 'sbi_network', "SDNControllerServiceInstance", o, 'zmq_pub_ip') |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 82 | fields['dp_comm_ip'] = self.get_ip_address_from_peer_service_instance( |
Sapan Bhatia | 9753629 | 2017-11-27 21:35:34 -0500 | [diff] [blame] | 83 | 'sbi_network', "VSPGWUTenant", o, 'dp_comm_ip') |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 84 | fields['cp_comm_ip'] = self.get_ip_address_from_peer_service_instance_instance( |
Sapan Bhatia | 9753629 | 2017-11-27 21:35:34 -0500 | [diff] [blame] | 85 | 'nbi_network', o, o, 'cp_comm_ip') |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 86 | fields['fpc_ip'] = self.get_ip_address_from_peer_service_instance( |
Sapan Bhatia | 9753629 | 2017-11-27 21:35:34 -0500 | [diff] [blame] | 87 | 'nbi_network', "SDNControllerServiceInstance", o, 'fpc_ip') |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 88 | fields['cp_nb_server_ip'] = self.get_ip_address_from_peer_service_instance_instance( |
Sapan Bhatia | 9753629 | 2017-11-27 21:35:34 -0500 | [diff] [blame] | 89 | 'nbi_network', o, o, 'cp_nb_server_ip') |
Woojoong Kim | 1a1e370 | 2017-10-27 13:26:34 -0700 | [diff] [blame] | 90 | |
| 91 | # for cp_config.cfg file |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 92 | fields['s11_sgw_ip'] = self.get_ip_address_from_peer_service_instance_instance( |
Sapan Bhatia | 9753629 | 2017-11-27 21:35:34 -0500 | [diff] [blame] | 93 | 's11_network', o, o, 's11_sgw_ip') |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 94 | fields['s1u_sgw_ip'] = self.get_ip_address_from_peer_service_instance( |
Sapan Bhatia | 9753629 | 2017-11-27 21:35:34 -0500 | [diff] [blame] | 95 | 's1u_network', "VSPGWUTenant", o, 's1u_sgw_ip') |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 96 | fields['s11_mme_ip'] = self.get_ip_address_from_peer_service_instance( |
Sapan Bhatia | 9753629 | 2017-11-27 21:35:34 -0500 | [diff] [blame] | 97 | 's11_network', "VMMETenant", o, 's11_mme_ip') |
Woojoong Kim | 1a1e370 | 2017-10-27 13:26:34 -0700 | [diff] [blame] | 98 | |
Woojoong Kim | 4f09cbf | 2017-11-19 21:25:37 -0800 | [diff] [blame] | 99 | # for rules setup in ONOS |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 100 | fields['sgi_as_ip'] = self.get_ip_address_from_peer_service_instance( |
Sapan Bhatia | 9753629 | 2017-11-27 21:35:34 -0500 | [diff] [blame] | 101 | 'sgi_network', "VENBServiceInstance", o, 'sgi_as_ip') |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 102 | fields['sgi_spgwu_ip'] = self.get_ip_address_from_peer_service_instance( |
Sapan Bhatia | 9753629 | 2017-11-27 21:35:34 -0500 | [diff] [blame] | 103 | 'sgi_network', "VSPGWUTenant", o, 'sgi_spgwu_ip') |
Woojoong Kim | 4f09cbf | 2017-11-19 21:25:37 -0800 | [diff] [blame] | 104 | |
Woojoong Kim | 1a1e370 | 2017-10-27 13:26:34 -0700 | [diff] [blame] | 105 | return fields |
| 106 | |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 107 | def get_values_for_normal_scenario_wo_sdncontroller(self, o): |
Woojoong Kim | 1a1e370 | 2017-10-27 13:26:34 -0700 | [diff] [blame] | 108 | fields = {} |
Woojoong Kim | 4f09cbf | 2017-11-19 21:25:37 -0800 | [diff] [blame] | 109 | fields['scenario'] = "normal_scenario_without_sdncontroller" |
Woojoong Kim | 1a1e370 | 2017-10-27 13:26:34 -0700 | [diff] [blame] | 110 | # for interface.cfg file |
| 111 | fields['zmq_sub_ip'] = "127.0.0.1" |
| 112 | fields['zmq_pub_ip'] = "127.0.0.1" |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 113 | fields['dp_comm_ip'] = self.get_ip_address_from_peer_service_instance( |
Sapan Bhatia | 9753629 | 2017-11-27 21:35:34 -0500 | [diff] [blame] | 114 | 'spgw_network', "VSPGWUTenant", o, 'dp_comm_ip') |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 115 | fields['cp_comm_ip'] = self.get_ip_address_from_peer_service_instance_instance( |
Sapan Bhatia | 9753629 | 2017-11-27 21:35:34 -0500 | [diff] [blame] | 116 | 'spgw_network', o, o, 'cp_comm_ip') |
Woojoong Kim | 1a1e370 | 2017-10-27 13:26:34 -0700 | [diff] [blame] | 117 | fields['fpc_ip'] = "127.0.0.1" |
| 118 | fields['cp_nb_server_ip'] = "127.0.0.1" |
| 119 | |
| 120 | # for cp_config.cfg file |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 121 | fields['s11_sgw_ip'] = self.get_ip_address_from_peer_service_instance_instance( |
Sapan Bhatia | 9753629 | 2017-11-27 21:35:34 -0500 | [diff] [blame] | 122 | 's11_network', o, o, 's11_sgw_ip') |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 123 | fields['s1u_sgw_ip'] = self.get_ip_address_from_peer_service_instance( |
Sapan Bhatia | 9753629 | 2017-11-27 21:35:34 -0500 | [diff] [blame] | 124 | 's1u_network', "VSPGWUTenant", o, 's1u_sgw_ip') |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 125 | fields['s11_mme_ip'] = self.get_ip_address_from_peer_service_instance( |
Sapan Bhatia | 9753629 | 2017-11-27 21:35:34 -0500 | [diff] [blame] | 126 | 's11_network', "VMMETenant", o, 's11_mme_ip') |
Woojoong Kim | 1a1e370 | 2017-10-27 13:26:34 -0700 | [diff] [blame] | 127 | |
Woojoong Kim | 4f09cbf | 2017-11-19 21:25:37 -0800 | [diff] [blame] | 128 | # for rules setup in ONOS |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 129 | fields['sgi_as_ip'] = self.get_ip_address_from_peer_service_instance( |
Sapan Bhatia | 9753629 | 2017-11-27 21:35:34 -0500 | [diff] [blame] | 130 | 'sgi_network', "VENBServiceInstance", o, 'sgi_as_ip') |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 131 | fields['sgi_spgwu_ip'] = self.get_ip_address_from_peer_service_instance( |
Sapan Bhatia | 9753629 | 2017-11-27 21:35:34 -0500 | [diff] [blame] | 132 | 'sgi_network', "VSPGWUTenant", o, 'sgi_spgwu_ip') |
Woojoong Kim | 4f09cbf | 2017-11-19 21:25:37 -0800 | [diff] [blame] | 133 | |
Woojoong Kim | 1a1e370 | 2017-10-27 13:26:34 -0700 | [diff] [blame] | 134 | return fields |
| 135 | |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 136 | def get_values_for_emulator_scenario(self, o): |
Woojoong Kim | 1a1e370 | 2017-10-27 13:26:34 -0700 | [diff] [blame] | 137 | fields = {} |
Woojoong Kim | 4f09cbf | 2017-11-19 21:25:37 -0800 | [diff] [blame] | 138 | fields['scenario'] = "emulator_scenario" |
Woojoong Kim | 1a1e370 | 2017-10-27 13:26:34 -0700 | [diff] [blame] | 139 | # for interface.cfg file |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 140 | fields['zmq_sub_ip'] = self.get_ip_address_from_peer_service_instance( |
Sapan Bhatia | 9753629 | 2017-11-27 21:35:34 -0500 | [diff] [blame] | 141 | 'sbi_network', "SDNControllerServiceInstance", o, 'zmq_sub_ip') |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 142 | fields['zmq_pub_ip'] = self.get_ip_address_from_peer_service_instance( |
Sapan Bhatia | 9753629 | 2017-11-27 21:35:34 -0500 | [diff] [blame] | 143 | 'sbi_network', "SDNControllerServiceInstance", o, 'zmq_pub_ip') |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 144 | fields['dp_comm_ip'] = self.get_ip_address_from_peer_service_instance( |
Sapan Bhatia | 9753629 | 2017-11-27 21:35:34 -0500 | [diff] [blame] | 145 | 'sbi_network', "VSPGWUTenant", o, 'dp_comm_ip') |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 146 | fields['cp_comm_ip'] = self.get_ip_address_from_peer_service_instance_instance( |
Sapan Bhatia | 9753629 | 2017-11-27 21:35:34 -0500 | [diff] [blame] | 147 | 'nbi_network', o, o, 'cp_comm_ip') |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 148 | fields['fpc_ip'] = self.get_ip_address_from_peer_service_instance( |
Sapan Bhatia | 9753629 | 2017-11-27 21:35:34 -0500 | [diff] [blame] | 149 | 'nbi_network', "SDNControllerServiceInstance", o, 'fpc_ip') |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 150 | fields['cp_nb_server_ip'] = self.get_ip_address_from_peer_service_instance_instance( |
Sapan Bhatia | 9753629 | 2017-11-27 21:35:34 -0500 | [diff] [blame] | 151 | 'nbi_network', o, o, 'cp_nb_server_ip') |
Woojoong Kim | 1a1e370 | 2017-10-27 13:26:34 -0700 | [diff] [blame] | 152 | |
| 153 | # for cp_config.cfg file |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 154 | fields['s11_sgw_ip'] = self.get_ip_address_from_peer_service_instance_instance( |
Sapan Bhatia | 9753629 | 2017-11-27 21:35:34 -0500 | [diff] [blame] | 155 | 's11_network', o, o, 's11_sgw_ip') |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 156 | fields['s1u_sgw_ip'] = self.get_ip_address_from_peer_service_instance( |
Sapan Bhatia | 9753629 | 2017-11-27 21:35:34 -0500 | [diff] [blame] | 157 | 's1u_network', "VSPGWUTenant", o, 's1u_sgw_ip') |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 158 | fields['s11_mme_ip'] = self.get_ip_address_from_peer_service_instance( |
Sapan Bhatia | 9753629 | 2017-11-27 21:35:34 -0500 | [diff] [blame] | 159 | 's11_network', "VENBServiceInstance", o, 's11_mme_ip') |
Woojoong Kim | 1a1e370 | 2017-10-27 13:26:34 -0700 | [diff] [blame] | 160 | |
Woojoong Kim | 4f09cbf | 2017-11-19 21:25:37 -0800 | [diff] [blame] | 161 | # for rules setup in ONOS |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 162 | fields['sgi_as_ip'] = self.get_ip_address_from_peer_service_instance( |
Sapan Bhatia | 9753629 | 2017-11-27 21:35:34 -0500 | [diff] [blame] | 163 | 'sgi_network', "VENBServiceInstance", o, 'sgi_as_ip') |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 164 | fields['sgi_spgwu_ip'] = self.get_ip_address_from_peer_service_instance( |
Sapan Bhatia | 9753629 | 2017-11-27 21:35:34 -0500 | [diff] [blame] | 165 | 'sgi_network', "VSPGWUTenant", o, 'sgi_spgwu_ip') |
Woojoong Kim | 4f09cbf | 2017-11-19 21:25:37 -0800 | [diff] [blame] | 166 | |
Woojoong Kim | 1a1e370 | 2017-10-27 13:26:34 -0700 | [diff] [blame] | 167 | return fields |
| 168 | |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 169 | def get_values_for_emulator_scenario_wo_sdncontroller(self, o): |
Woojoong Kim | 1a1e370 | 2017-10-27 13:26:34 -0700 | [diff] [blame] | 170 | fields = {} |
Woojoong Kim | 4f09cbf | 2017-11-19 21:25:37 -0800 | [diff] [blame] | 171 | fields['scenario'] = "emulator_scenario_without_sdncontroller" |
Woojoong Kim | 1a1e370 | 2017-10-27 13:26:34 -0700 | [diff] [blame] | 172 | # for interface.cfg file |
| 173 | fields['zmq_sub_ip'] = "127.0.0.1" |
| 174 | fields['zmq_pub_ip'] = "127.0.0.1" |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 175 | fields['dp_comm_ip'] = self.get_ip_address_from_peer_service_instance( |
Sapan Bhatia | 9753629 | 2017-11-27 21:35:34 -0500 | [diff] [blame] | 176 | 'spgw_network', "VSPGWUTenant", o, 'dp_comm_ip') |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 177 | fields['cp_comm_ip'] = self.get_ip_address_from_peer_service_instance_instance( |
Sapan Bhatia | 9753629 | 2017-11-27 21:35:34 -0500 | [diff] [blame] | 178 | 'spgw_network', o, o, 'cp_comm_ip') |
Woojoong Kim | 1a1e370 | 2017-10-27 13:26:34 -0700 | [diff] [blame] | 179 | fields['fpc_ip'] = "127.0.0.1" |
| 180 | fields['cp_nb_server_ip'] = "127.0.0.1" |
| 181 | |
| 182 | # for cp_config.cfg file |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 183 | fields['s11_sgw_ip'] = self.get_ip_address_from_peer_service_instance_instance( |
Sapan Bhatia | 9753629 | 2017-11-27 21:35:34 -0500 | [diff] [blame] | 184 | 's11_network', o, o, 's11_sgw_ip') |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 185 | fields['s1u_sgw_ip'] = self.get_ip_address_from_peer_service_instance( |
Sapan Bhatia | 9753629 | 2017-11-27 21:35:34 -0500 | [diff] [blame] | 186 | 's1u_network', "VSPGWUTenant", o, 's1u_sgw_ip') |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 187 | fields['s11_mme_ip'] = self.get_ip_address_from_peer_service_instance( |
Sapan Bhatia | 9753629 | 2017-11-27 21:35:34 -0500 | [diff] [blame] | 188 | 's11_network', "VENBServiceInstance", o, 's11_mme_ip') |
Woojoong Kim | 1a1e370 | 2017-10-27 13:26:34 -0700 | [diff] [blame] | 189 | |
Woojoong Kim | 4f09cbf | 2017-11-19 21:25:37 -0800 | [diff] [blame] | 190 | # for rules setup in ONOS |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 191 | fields['sgi_as_ip'] = self.get_ip_address_from_peer_service_instance( |
Sapan Bhatia | 9753629 | 2017-11-27 21:35:34 -0500 | [diff] [blame] | 192 | 'sgi_network', "VENBServiceInstance", o, 'sgi_as_ip') |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 193 | fields['sgi_spgwu_ip'] = self.get_ip_address_from_peer_service_instance( |
Sapan Bhatia | 9753629 | 2017-11-27 21:35:34 -0500 | [diff] [blame] | 194 | 'sgi_network', "VSPGWUTenant", o, 'sgi_spgwu_ip') |
Woojoong Kim | 4f09cbf | 2017-11-19 21:25:37 -0800 | [diff] [blame] | 195 | |
Woojoong Kim | 1a1e370 | 2017-10-27 13:26:34 -0700 | [diff] [blame] | 196 | return fields |
| 197 | |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 198 | def get_scenario(self, o): |
| 199 | venb_flag = self.has_instance("VENBServiceInstance", o) |
| 200 | vmme_flag = self.has_instance("VMMETenant", o) |
| 201 | sdncontroller_flag = self.has_instance( |
| 202 | "SDNControllerServiceInstance", o) |
| 203 | vspgwu_flag = self.has_instance("VSPGWUTenant", o) |
| 204 | internetemulator_flag = self.has_instance( |
| 205 | "SDNControllerServiceInstance", o) |
Woojoong Kim | 4f09cbf | 2017-11-19 21:25:37 -0800 | [diff] [blame] | 206 | |
Woojoong Kim | 1a1e370 | 2017-10-27 13:26:34 -0700 | [diff] [blame] | 207 | if vmme_flag and venb_flag and sdncontroller_flag and vspgwu_flag and internetemulator_flag: |
Woojoong Kim | 3320906 | 2017-11-21 15:46:09 -0800 | [diff] [blame] | 208 | return 'normal_scenario' |
Woojoong Kim | f000eda | 2017-10-20 15:00:43 -0700 | [diff] [blame] | 209 | |
Woojoong Kim | 1a1e370 | 2017-10-27 13:26:34 -0700 | [diff] [blame] | 210 | if vmme_flag and venb_flag and (not sdncontroller_flag) and vspgwu_flag and internetemulator_flag: |
Woojoong Kim | 3320906 | 2017-11-21 15:46:09 -0800 | [diff] [blame] | 211 | return 'normal_scenario_without_sdncontroller' |
Woojoong Kim | 1a1e370 | 2017-10-27 13:26:34 -0700 | [diff] [blame] | 212 | |
| 213 | if (not vmme_flag) and venb_flag and sdncontroller_flag and vspgwu_flag and (not internetemulator_flag): |
Woojoong Kim | 3320906 | 2017-11-21 15:46:09 -0800 | [diff] [blame] | 214 | return 'emulator_scenario' |
Woojoong Kim | 1a1e370 | 2017-10-27 13:26:34 -0700 | [diff] [blame] | 215 | |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 216 | if (not vmme_flag) and venb_flag and (not sdncontroller_flag) and vspgwu_flag and ( |
| 217 | not internetemulator_flag): |
Woojoong Kim | 3320906 | 2017-11-21 15:46:09 -0800 | [diff] [blame] | 218 | return 'emulator_scenario_without_sdncontroller' |
Woojoong Kim | 1a1e370 | 2017-10-27 13:26:34 -0700 | [diff] [blame] | 219 | |
| 220 | return 'manual' |
| 221 | |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 222 | def get_ip_address_from_peer_service_instance(self, network_name, sitype, o, parameter=None): |
| 223 | peer_si = self.get_peer_serviceinstance_of_type(sitype, o) |
Sapan Bhatia | 9753629 | 2017-11-27 21:35:34 -0500 | [diff] [blame] | 224 | return self.get_ip_address_from_peer_service_instance_instance(network_name, peer_si, o, parameter) |
Woojoong Kim | f000eda | 2017-10-20 15:00:43 -0700 | [diff] [blame] | 225 | |
Sapan Bhatia | 9753629 | 2017-11-27 21:35:34 -0500 | [diff] [blame] | 226 | def get_ip_address_from_peer_service_instance_instance(self, network_name, peer_si, o, parameter=None): |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 227 | try: |
| 228 | net_id = self.get_network_id(network_name) |
Sapan Bhatia | 9753629 | 2017-11-27 21:35:34 -0500 | [diff] [blame] | 229 | ins_id = peer_si.leaf_model.instance_id |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 230 | ip_address = Port.objects.get( |
| 231 | network_id=net_id, instance_id=ins_id).ip |
| 232 | except Exception: |
| 233 | self.log.error("Failed to fetch parameter", |
| 234 | parameter=parameter, |
| 235 | network_name=network_name) |
Sapan Bhatia | 9753629 | 2017-11-27 21:35:34 -0500 | [diff] [blame] | 236 | self.defer_sync(o, "Waiting for parameters to become available") |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 237 | |
| 238 | return ip_address |
| 239 | |
| 240 | def get_peer_serviceinstance_of_type(self, sitype, o): |
| 241 | prov_link_set = ServiceInstanceLink.objects.filter( |
| 242 | subscriber_service_instance_id=o.id) |
| 243 | |
| 244 | try: |
| 245 | peer_service = next( |
Sapan Bhatia | 9753629 | 2017-11-27 21:35:34 -0500 | [diff] [blame] | 246 | p.provider_service_instance for p in prov_link_set if p.provider_service_instance.leaf_model_name == sitype) |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 247 | except StopIteration: |
| 248 | sub_link_set = ServiceInstanceLink.objects.filter( |
| 249 | provider_service_instance_id=o.id) |
| 250 | try: |
| 251 | peer_service = next( |
Sapan Bhatia | 9753629 | 2017-11-27 21:35:34 -0500 | [diff] [blame] | 252 | s.subscriber_service_instance for s in sub_link_set if s.subscriber_service_instance.leaf_model_name == sitype) |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 253 | except StopIteration: |
| 254 | self.log.error( |
| 255 | 'Could not find service type in service graph', service_type=sitype, object=o) |
Sapan Bhatia | 28b7560 | 2017-11-28 14:18:21 -0500 | [diff] [blame] | 256 | raise ServiceGraphException( |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 257 | "Synchronization failed due to incomplete service graph") |
Sapan Bhatia | 9753629 | 2017-11-27 21:35:34 -0500 | [diff] [blame] | 258 | |
| 259 | return peer_service |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 260 | |
Woojoong Kim | f000eda | 2017-10-20 15:00:43 -0700 | [diff] [blame] | 261 | # To get each network id |
| 262 | def get_network_id(self, network_name): |
| 263 | return Network.objects.get(name=network_name).id |
| 264 | |
| 265 | # To get service_instance (assumption: there is a single instance for each service) |
| 266 | def get_instance_id(self, serviceinstance): |
| 267 | instances = serviceinstance.objects.all() |
| 268 | instance_id = instances[0].instance_id |
| 269 | return instance_id |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 270 | |
| 271 | def has_instance(self, sitype, o): |
Sapan Bhatia | 28b7560 | 2017-11-28 14:18:21 -0500 | [diff] [blame] | 272 | try: |
| 273 | i = self.get_peer_serviceinstance_of_type(sitype, o) |
| 274 | except ServiceGraphException: |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 275 | self.log.info("Missing in ServiceInstance graph", |
| 276 | serviceinstance=sitype) |
| 277 | return False |
| 278 | |
Woojoong Kim | 38d8488 | 2017-11-28 15:38:39 -0800 | [diff] [blame] | 279 | return i.leaf_model.instance_id |