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 | 313d35c | 2017-12-18 17:15:46 -0800 | [diff] [blame^] | 48 | elif scenario == 'hardware_scenario': |
| 49 | return self.get_values_for_hardware_scenario(o) |
| 50 | elif scenario == 'hardware_scenario_without_sdncontroller': |
| 51 | return self.get_values_for_hardware_scenario_wo_sdncontroller(o) |
Woojoong Kim | f000eda | 2017-10-20 15:00:43 -0700 | [diff] [blame] | 52 | else: |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 53 | return self.get_extra_attributes_for_manual(o) |
Woojoong Kim | f000eda | 2017-10-20 15:00:43 -0700 | [diff] [blame] | 54 | |
| 55 | # fields for manual case |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 56 | def get_extra_attributes_for_manual(self, o): |
Woojoong Kim | f000eda | 2017-10-20 15:00:43 -0700 | [diff] [blame] | 57 | fields = {} |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 58 | fields['scenario'] = self.get_scenario(o) |
Woojoong Kim | f000eda | 2017-10-20 15:00:43 -0700 | [diff] [blame] | 59 | # for interface.cfg file |
| 60 | fields['zmq_sub_ip'] = "manual" |
| 61 | fields['zmq_pub_ip'] = "manual" |
| 62 | fields['dp_comm_ip'] = "manual" |
| 63 | fields['cp_comm_ip'] = "manual" |
| 64 | fields['fpc_ip'] = "manual" |
| 65 | fields['cp_nb_server_ip'] = "manual" |
| 66 | |
| 67 | # for cp_config.cfg file |
| 68 | fields['s11_sgw_ip'] = "manual" |
| 69 | fields['s11_mme_ip'] = "manual" |
| 70 | fields['s1u_sgw_ip'] = "manual" |
| 71 | |
Woojoong Kim | 4f09cbf | 2017-11-19 21:25:37 -0800 | [diff] [blame] | 72 | # for rules setup in ONOS |
| 73 | fields['sgi_as_ip'] = "manual" |
| 74 | fields['sgi_spgwu_ip'] = "manual" |
| 75 | |
Woojoong Kim | f000eda | 2017-10-20 15:00:43 -0700 | [diff] [blame] | 76 | return fields |
| 77 | |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 78 | def get_values_for_normal_scenario(self, o): |
Woojoong Kim | 1a1e370 | 2017-10-27 13:26:34 -0700 | [diff] [blame] | 79 | fields = {} |
Woojoong Kim | 4f09cbf | 2017-11-19 21:25:37 -0800 | [diff] [blame] | 80 | fields['scenario'] = "normal_scenario" |
Woojoong Kim | 1a1e370 | 2017-10-27 13:26:34 -0700 | [diff] [blame] | 81 | # for interface.cfg file |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 82 | fields['zmq_sub_ip'] = self.get_ip_address_from_peer_service_instance( |
Sapan Bhatia | 9753629 | 2017-11-27 21:35:34 -0500 | [diff] [blame] | 83 | 'sbi_network', "SDNControllerServiceInstance", o, 'zmq_sub_ip') |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 84 | fields['zmq_pub_ip'] = self.get_ip_address_from_peer_service_instance( |
Sapan Bhatia | 9753629 | 2017-11-27 21:35:34 -0500 | [diff] [blame] | 85 | 'sbi_network', "SDNControllerServiceInstance", o, 'zmq_pub_ip') |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 86 | fields['dp_comm_ip'] = self.get_ip_address_from_peer_service_instance( |
Sapan Bhatia | 9753629 | 2017-11-27 21:35:34 -0500 | [diff] [blame] | 87 | 'sbi_network', "VSPGWUTenant", o, 'dp_comm_ip') |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 88 | 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] | 89 | 'nbi_network', o, o, 'cp_comm_ip') |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 90 | fields['fpc_ip'] = self.get_ip_address_from_peer_service_instance( |
Sapan Bhatia | 9753629 | 2017-11-27 21:35:34 -0500 | [diff] [blame] | 91 | 'nbi_network', "SDNControllerServiceInstance", o, 'fpc_ip') |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 92 | 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] | 93 | 'nbi_network', o, o, 'cp_nb_server_ip') |
Woojoong Kim | 1a1e370 | 2017-10-27 13:26:34 -0700 | [diff] [blame] | 94 | |
| 95 | # for cp_config.cfg file |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 96 | 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] | 97 | 's11_network', o, o, 's11_sgw_ip') |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 98 | fields['s1u_sgw_ip'] = self.get_ip_address_from_peer_service_instance( |
Sapan Bhatia | 9753629 | 2017-11-27 21:35:34 -0500 | [diff] [blame] | 99 | 's1u_network', "VSPGWUTenant", o, 's1u_sgw_ip') |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 100 | fields['s11_mme_ip'] = self.get_ip_address_from_peer_service_instance( |
Sapan Bhatia | 9753629 | 2017-11-27 21:35:34 -0500 | [diff] [blame] | 101 | 's11_network', "VMMETenant", o, 's11_mme_ip') |
Woojoong Kim | 1a1e370 | 2017-10-27 13:26:34 -0700 | [diff] [blame] | 102 | |
Woojoong Kim | 4f09cbf | 2017-11-19 21:25:37 -0800 | [diff] [blame] | 103 | # for rules setup in ONOS |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 104 | fields['sgi_as_ip'] = self.get_ip_address_from_peer_service_instance( |
Sapan Bhatia | 9753629 | 2017-11-27 21:35:34 -0500 | [diff] [blame] | 105 | 'sgi_network', "VENBServiceInstance", o, 'sgi_as_ip') |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 106 | fields['sgi_spgwu_ip'] = self.get_ip_address_from_peer_service_instance( |
Sapan Bhatia | 9753629 | 2017-11-27 21:35:34 -0500 | [diff] [blame] | 107 | 'sgi_network', "VSPGWUTenant", o, 'sgi_spgwu_ip') |
Woojoong Kim | 4f09cbf | 2017-11-19 21:25:37 -0800 | [diff] [blame] | 108 | |
Woojoong Kim | 1a1e370 | 2017-10-27 13:26:34 -0700 | [diff] [blame] | 109 | return fields |
| 110 | |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 111 | def get_values_for_normal_scenario_wo_sdncontroller(self, o): |
Woojoong Kim | 1a1e370 | 2017-10-27 13:26:34 -0700 | [diff] [blame] | 112 | fields = {} |
Woojoong Kim | 4f09cbf | 2017-11-19 21:25:37 -0800 | [diff] [blame] | 113 | fields['scenario'] = "normal_scenario_without_sdncontroller" |
Woojoong Kim | 1a1e370 | 2017-10-27 13:26:34 -0700 | [diff] [blame] | 114 | # for interface.cfg file |
| 115 | fields['zmq_sub_ip'] = "127.0.0.1" |
| 116 | fields['zmq_pub_ip'] = "127.0.0.1" |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 117 | fields['dp_comm_ip'] = self.get_ip_address_from_peer_service_instance( |
Sapan Bhatia | 9753629 | 2017-11-27 21:35:34 -0500 | [diff] [blame] | 118 | 'spgw_network', "VSPGWUTenant", o, 'dp_comm_ip') |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 119 | 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] | 120 | 'spgw_network', o, o, 'cp_comm_ip') |
Woojoong Kim | 1a1e370 | 2017-10-27 13:26:34 -0700 | [diff] [blame] | 121 | fields['fpc_ip'] = "127.0.0.1" |
| 122 | fields['cp_nb_server_ip'] = "127.0.0.1" |
| 123 | |
| 124 | # for cp_config.cfg file |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 125 | 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] | 126 | 's11_network', o, o, 's11_sgw_ip') |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 127 | fields['s1u_sgw_ip'] = self.get_ip_address_from_peer_service_instance( |
Sapan Bhatia | 9753629 | 2017-11-27 21:35:34 -0500 | [diff] [blame] | 128 | 's1u_network', "VSPGWUTenant", o, 's1u_sgw_ip') |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 129 | fields['s11_mme_ip'] = self.get_ip_address_from_peer_service_instance( |
Sapan Bhatia | 9753629 | 2017-11-27 21:35:34 -0500 | [diff] [blame] | 130 | 's11_network', "VMMETenant", o, 's11_mme_ip') |
Woojoong Kim | 1a1e370 | 2017-10-27 13:26:34 -0700 | [diff] [blame] | 131 | |
Woojoong Kim | 4f09cbf | 2017-11-19 21:25:37 -0800 | [diff] [blame] | 132 | # for rules setup in ONOS |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 133 | fields['sgi_as_ip'] = self.get_ip_address_from_peer_service_instance( |
Sapan Bhatia | 9753629 | 2017-11-27 21:35:34 -0500 | [diff] [blame] | 134 | 'sgi_network', "VENBServiceInstance", o, 'sgi_as_ip') |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 135 | fields['sgi_spgwu_ip'] = self.get_ip_address_from_peer_service_instance( |
Sapan Bhatia | 9753629 | 2017-11-27 21:35:34 -0500 | [diff] [blame] | 136 | 'sgi_network', "VSPGWUTenant", o, 'sgi_spgwu_ip') |
Woojoong Kim | 4f09cbf | 2017-11-19 21:25:37 -0800 | [diff] [blame] | 137 | |
Woojoong Kim | 1a1e370 | 2017-10-27 13:26:34 -0700 | [diff] [blame] | 138 | return fields |
| 139 | |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 140 | def get_values_for_emulator_scenario(self, o): |
Woojoong Kim | 1a1e370 | 2017-10-27 13:26:34 -0700 | [diff] [blame] | 141 | fields = {} |
Woojoong Kim | 4f09cbf | 2017-11-19 21:25:37 -0800 | [diff] [blame] | 142 | fields['scenario'] = "emulator_scenario" |
Woojoong Kim | 1a1e370 | 2017-10-27 13:26:34 -0700 | [diff] [blame] | 143 | # for interface.cfg file |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 144 | fields['zmq_sub_ip'] = self.get_ip_address_from_peer_service_instance( |
Sapan Bhatia | 9753629 | 2017-11-27 21:35:34 -0500 | [diff] [blame] | 145 | 'sbi_network', "SDNControllerServiceInstance", o, 'zmq_sub_ip') |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 146 | fields['zmq_pub_ip'] = self.get_ip_address_from_peer_service_instance( |
Sapan Bhatia | 9753629 | 2017-11-27 21:35:34 -0500 | [diff] [blame] | 147 | 'sbi_network', "SDNControllerServiceInstance", o, 'zmq_pub_ip') |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 148 | fields['dp_comm_ip'] = self.get_ip_address_from_peer_service_instance( |
Sapan Bhatia | 9753629 | 2017-11-27 21:35:34 -0500 | [diff] [blame] | 149 | 'sbi_network', "VSPGWUTenant", o, 'dp_comm_ip') |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 150 | 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] | 151 | 'nbi_network', o, o, 'cp_comm_ip') |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 152 | fields['fpc_ip'] = self.get_ip_address_from_peer_service_instance( |
Sapan Bhatia | 9753629 | 2017-11-27 21:35:34 -0500 | [diff] [blame] | 153 | 'nbi_network', "SDNControllerServiceInstance", o, 'fpc_ip') |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 154 | 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] | 155 | 'nbi_network', o, o, 'cp_nb_server_ip') |
Woojoong Kim | 1a1e370 | 2017-10-27 13:26:34 -0700 | [diff] [blame] | 156 | |
| 157 | # for cp_config.cfg file |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 158 | 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] | 159 | 's11_network', o, o, 's11_sgw_ip') |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 160 | fields['s1u_sgw_ip'] = self.get_ip_address_from_peer_service_instance( |
Sapan Bhatia | 9753629 | 2017-11-27 21:35:34 -0500 | [diff] [blame] | 161 | 's1u_network', "VSPGWUTenant", o, 's1u_sgw_ip') |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 162 | fields['s11_mme_ip'] = self.get_ip_address_from_peer_service_instance( |
Sapan Bhatia | 9753629 | 2017-11-27 21:35:34 -0500 | [diff] [blame] | 163 | 's11_network', "VENBServiceInstance", o, 's11_mme_ip') |
Woojoong Kim | 1a1e370 | 2017-10-27 13:26:34 -0700 | [diff] [blame] | 164 | |
Woojoong Kim | 4f09cbf | 2017-11-19 21:25:37 -0800 | [diff] [blame] | 165 | # for rules setup in ONOS |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 166 | fields['sgi_as_ip'] = self.get_ip_address_from_peer_service_instance( |
Sapan Bhatia | 9753629 | 2017-11-27 21:35:34 -0500 | [diff] [blame] | 167 | 'sgi_network', "VENBServiceInstance", o, 'sgi_as_ip') |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 168 | fields['sgi_spgwu_ip'] = self.get_ip_address_from_peer_service_instance( |
Sapan Bhatia | 9753629 | 2017-11-27 21:35:34 -0500 | [diff] [blame] | 169 | 'sgi_network', "VSPGWUTenant", o, 'sgi_spgwu_ip') |
Woojoong Kim | 4f09cbf | 2017-11-19 21:25:37 -0800 | [diff] [blame] | 170 | |
Woojoong Kim | 1a1e370 | 2017-10-27 13:26:34 -0700 | [diff] [blame] | 171 | return fields |
| 172 | |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 173 | def get_values_for_emulator_scenario_wo_sdncontroller(self, o): |
Woojoong Kim | 1a1e370 | 2017-10-27 13:26:34 -0700 | [diff] [blame] | 174 | fields = {} |
Woojoong Kim | 4f09cbf | 2017-11-19 21:25:37 -0800 | [diff] [blame] | 175 | fields['scenario'] = "emulator_scenario_without_sdncontroller" |
Woojoong Kim | 1a1e370 | 2017-10-27 13:26:34 -0700 | [diff] [blame] | 176 | # for interface.cfg file |
| 177 | fields['zmq_sub_ip'] = "127.0.0.1" |
| 178 | fields['zmq_pub_ip'] = "127.0.0.1" |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 179 | fields['dp_comm_ip'] = self.get_ip_address_from_peer_service_instance( |
Sapan Bhatia | 9753629 | 2017-11-27 21:35:34 -0500 | [diff] [blame] | 180 | 'spgw_network', "VSPGWUTenant", o, 'dp_comm_ip') |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 181 | 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] | 182 | 'spgw_network', o, o, 'cp_comm_ip') |
Woojoong Kim | 1a1e370 | 2017-10-27 13:26:34 -0700 | [diff] [blame] | 183 | fields['fpc_ip'] = "127.0.0.1" |
| 184 | fields['cp_nb_server_ip'] = "127.0.0.1" |
| 185 | |
| 186 | # for cp_config.cfg file |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 187 | 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] | 188 | 's11_network', o, o, 's11_sgw_ip') |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 189 | fields['s1u_sgw_ip'] = self.get_ip_address_from_peer_service_instance( |
Sapan Bhatia | 9753629 | 2017-11-27 21:35:34 -0500 | [diff] [blame] | 190 | 's1u_network', "VSPGWUTenant", o, 's1u_sgw_ip') |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 191 | fields['s11_mme_ip'] = self.get_ip_address_from_peer_service_instance( |
Sapan Bhatia | 9753629 | 2017-11-27 21:35:34 -0500 | [diff] [blame] | 192 | 's11_network', "VENBServiceInstance", o, 's11_mme_ip') |
Woojoong Kim | 1a1e370 | 2017-10-27 13:26:34 -0700 | [diff] [blame] | 193 | |
Woojoong Kim | 4f09cbf | 2017-11-19 21:25:37 -0800 | [diff] [blame] | 194 | # for rules setup in ONOS |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 195 | fields['sgi_as_ip'] = self.get_ip_address_from_peer_service_instance( |
Sapan Bhatia | 9753629 | 2017-11-27 21:35:34 -0500 | [diff] [blame] | 196 | 'sgi_network', "VENBServiceInstance", o, 'sgi_as_ip') |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 197 | fields['sgi_spgwu_ip'] = self.get_ip_address_from_peer_service_instance( |
Sapan Bhatia | 9753629 | 2017-11-27 21:35:34 -0500 | [diff] [blame] | 198 | 'sgi_network', "VSPGWUTenant", o, 'sgi_spgwu_ip') |
Woojoong Kim | 4f09cbf | 2017-11-19 21:25:37 -0800 | [diff] [blame] | 199 | |
Woojoong Kim | 1a1e370 | 2017-10-27 13:26:34 -0700 | [diff] [blame] | 200 | return fields |
| 201 | |
Woojoong Kim | 313d35c | 2017-12-18 17:15:46 -0800 | [diff] [blame^] | 202 | def get_values_for_hardware_scenario(self, o): |
| 203 | fields = {} |
| 204 | fields['scenario'] = "hardware_scenario" |
| 205 | |
| 206 | # for interface.cfg file |
| 207 | fields['zmq_sub_ip'] = self.get_ip_address_from_peer_service_instance( |
| 208 | 'sbi_network', "SDNControllerServiceInstance", o, 'zmq_sub_ip') |
| 209 | fields['zmq_pub_ip'] = self.get_ip_address_from_peer_service_instance( |
| 210 | 'sbi_network', "SDNControllerServiceInstance", o, 'zmq_pub_ip') |
| 211 | fields['dp_comm_ip'] = self.get_ip_address_from_peer_service_instance( |
| 212 | 'sbi_network', "VSPGWUTenant", o, 'dp_comm_ip') |
| 213 | fields['cp_comm_ip'] = self.get_ip_address_from_peer_service_instance_instance( |
| 214 | 'nbi_network', o, o, 'cp_comm_ip') |
| 215 | fields['fpc_ip'] = self.get_ip_address_from_peer_service_instance( |
| 216 | 'nbi_network', "SDNControllerServiceInstance", o, 'fpc_ip') |
| 217 | fields['cp_nb_server_ip'] = self.get_ip_address_from_peer_service_instance_instance( |
| 218 | 'nbi_network', o, o, 'cp_nb_server_ip') |
| 219 | |
| 220 | # for cp_config.cfg file |
| 221 | fields['s11_sgw_ip'] = self.get_ip_address_from_peer_service_instance_instance( |
| 222 | 's11_network', o, o, 's11_sgw_ip') |
| 223 | fields['s1u_sgw_ip'] = self.get_ip_address_from_peer_service_instance( |
| 224 | 'flat_network_s1u', "VSPGWUTenant", o, 's1u_sgw_ip') |
| 225 | fields['s11_mme_ip'] = self.get_ip_address_from_peer_service_instance( |
| 226 | 's11_network', "VMMETenant", o, 's11_mme_ip') |
| 227 | |
| 228 | # for rules setup in ONOS |
| 229 | fields['sgi_as_ip'] = "manual" |
| 230 | fields['sgi_spgwu_ip'] = self.get_ip_address_from_peer_service_instance( |
| 231 | 'sgi_network', "VSPGWUTenant", o, 'sgi_spgwu_ip') |
| 232 | |
| 233 | return fields |
| 234 | |
| 235 | def get_values_for_hardware_scenario_wo_sdncontroller(self, o): |
| 236 | fields = {} |
| 237 | fields['scenario'] = "hardware_scenario_without_sdncontroller" |
| 238 | |
| 239 | # for interface.cfg file |
| 240 | fields['zmq_sub_ip'] = "127.0.0.1" |
| 241 | fields['zmq_pub_ip'] = "127.0.0.1" |
| 242 | fields['dp_comm_ip'] = self.get_ip_address_from_peer_service_instance( |
| 243 | 'spgw_network', "VSPGWUTenant", o, 'dp_comm_ip') |
| 244 | fields['cp_comm_ip'] = self.get_ip_address_from_peer_service_instance_instance( |
| 245 | 'spgw_network', o, o, 'cp_comm_ip') |
| 246 | fields['fpc_ip'] = "127.0.0.1" |
| 247 | fields['cp_nb_server_ip'] = "127.0.0.1" |
| 248 | |
| 249 | # for cp_config.cfg file |
| 250 | fields['s11_sgw_ip'] = self.get_ip_address_from_peer_service_instance_instance( |
| 251 | 's11_network', o, o, 's11_sgw_ip') |
| 252 | fields['s1u_sgw_ip'] = self.get_ip_address_from_peer_service_instance( |
| 253 | 'flat_network_s1u', "VSPGWUTenant", o, 's1u_sgw_ip') |
| 254 | fields['s11_mme_ip'] = self.get_ip_address_from_peer_service_instance( |
| 255 | 's11_network', "VMMETenant", o, 's11_mme_ip') |
| 256 | |
| 257 | # for rules setup in ONOS |
| 258 | fields['sgi_as_ip'] = "manual" |
| 259 | fields['sgi_spgwu_ip'] = self.get_ip_address_from_peer_service_instance( |
| 260 | 'sgi_network', "VSPGWUTenant", o, 'sgi_spgwu_ip') |
| 261 | |
| 262 | return fields |
| 263 | |
| 264 | |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 265 | def get_scenario(self, o): |
| 266 | venb_flag = self.has_instance("VENBServiceInstance", o) |
| 267 | vmme_flag = self.has_instance("VMMETenant", o) |
| 268 | sdncontroller_flag = self.has_instance( |
| 269 | "SDNControllerServiceInstance", o) |
| 270 | vspgwu_flag = self.has_instance("VSPGWUTenant", o) |
| 271 | internetemulator_flag = self.has_instance( |
| 272 | "SDNControllerServiceInstance", o) |
Woojoong Kim | 4f09cbf | 2017-11-19 21:25:37 -0800 | [diff] [blame] | 273 | |
Woojoong Kim | 1a1e370 | 2017-10-27 13:26:34 -0700 | [diff] [blame] | 274 | 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] | 275 | return 'normal_scenario' |
Woojoong Kim | f000eda | 2017-10-20 15:00:43 -0700 | [diff] [blame] | 276 | |
Woojoong Kim | 1a1e370 | 2017-10-27 13:26:34 -0700 | [diff] [blame] | 277 | 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] | 278 | return 'normal_scenario_without_sdncontroller' |
Woojoong Kim | 1a1e370 | 2017-10-27 13:26:34 -0700 | [diff] [blame] | 279 | |
| 280 | 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] | 281 | return 'emulator_scenario' |
Woojoong Kim | 1a1e370 | 2017-10-27 13:26:34 -0700 | [diff] [blame] | 282 | |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 283 | if (not vmme_flag) and venb_flag and (not sdncontroller_flag) and vspgwu_flag and ( |
| 284 | not internetemulator_flag): |
Woojoong Kim | 3320906 | 2017-11-21 15:46:09 -0800 | [diff] [blame] | 285 | return 'emulator_scenario_without_sdncontroller' |
Woojoong Kim | 1a1e370 | 2017-10-27 13:26:34 -0700 | [diff] [blame] | 286 | |
Woojoong Kim | 313d35c | 2017-12-18 17:15:46 -0800 | [diff] [blame^] | 287 | if vmme_flag and sdncontroller_flag and vspgwu_flag and (not internetemulator_flag): |
| 288 | return 'hardware_scenario' |
| 289 | |
| 290 | if vmme_flag and (not sdncontroller_flag) and vspgwu_flag and (not internetemulator_flag): |
| 291 | return 'hardware_scenario_without_sdncontroller' |
| 292 | |
Woojoong Kim | 1a1e370 | 2017-10-27 13:26:34 -0700 | [diff] [blame] | 293 | return 'manual' |
| 294 | |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 295 | def get_ip_address_from_peer_service_instance(self, network_name, sitype, o, parameter=None): |
| 296 | peer_si = self.get_peer_serviceinstance_of_type(sitype, o) |
Sapan Bhatia | 9753629 | 2017-11-27 21:35:34 -0500 | [diff] [blame] | 297 | 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] | 298 | |
Sapan Bhatia | 9753629 | 2017-11-27 21:35:34 -0500 | [diff] [blame] | 299 | 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] | 300 | try: |
| 301 | net_id = self.get_network_id(network_name) |
Sapan Bhatia | 9753629 | 2017-11-27 21:35:34 -0500 | [diff] [blame] | 302 | ins_id = peer_si.leaf_model.instance_id |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 303 | ip_address = Port.objects.get( |
| 304 | network_id=net_id, instance_id=ins_id).ip |
| 305 | except Exception: |
| 306 | self.log.error("Failed to fetch parameter", |
| 307 | parameter=parameter, |
| 308 | network_name=network_name) |
Sapan Bhatia | 9753629 | 2017-11-27 21:35:34 -0500 | [diff] [blame] | 309 | self.defer_sync(o, "Waiting for parameters to become available") |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 310 | |
| 311 | return ip_address |
| 312 | |
| 313 | def get_peer_serviceinstance_of_type(self, sitype, o): |
| 314 | prov_link_set = ServiceInstanceLink.objects.filter( |
| 315 | subscriber_service_instance_id=o.id) |
| 316 | |
| 317 | try: |
| 318 | peer_service = next( |
Sapan Bhatia | 9753629 | 2017-11-27 21:35:34 -0500 | [diff] [blame] | 319 | 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] | 320 | except StopIteration: |
| 321 | sub_link_set = ServiceInstanceLink.objects.filter( |
| 322 | provider_service_instance_id=o.id) |
| 323 | try: |
| 324 | peer_service = next( |
Sapan Bhatia | 9753629 | 2017-11-27 21:35:34 -0500 | [diff] [blame] | 325 | 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] | 326 | except StopIteration: |
| 327 | self.log.error( |
| 328 | '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] | 329 | raise ServiceGraphException( |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 330 | "Synchronization failed due to incomplete service graph") |
Sapan Bhatia | 9753629 | 2017-11-27 21:35:34 -0500 | [diff] [blame] | 331 | |
| 332 | return peer_service |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 333 | |
Woojoong Kim | f000eda | 2017-10-20 15:00:43 -0700 | [diff] [blame] | 334 | # To get each network id |
| 335 | def get_network_id(self, network_name): |
| 336 | return Network.objects.get(name=network_name).id |
| 337 | |
| 338 | # To get service_instance (assumption: there is a single instance for each service) |
| 339 | def get_instance_id(self, serviceinstance): |
| 340 | instances = serviceinstance.objects.all() |
| 341 | instance_id = instances[0].instance_id |
| 342 | return instance_id |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 343 | |
| 344 | def has_instance(self, sitype, o): |
Sapan Bhatia | 28b7560 | 2017-11-28 14:18:21 -0500 | [diff] [blame] | 345 | try: |
| 346 | i = self.get_peer_serviceinstance_of_type(sitype, o) |
| 347 | except ServiceGraphException: |
Sapan Bhatia | a1fbd38 | 2017-11-22 13:18:11 -0500 | [diff] [blame] | 348 | self.log.info("Missing in ServiceInstance graph", |
| 349 | serviceinstance=sitype) |
| 350 | return False |
| 351 | |
Woojoong Kim | 38d8488 | 2017-11-28 15:38:39 -0800 | [diff] [blame] | 352 | return i.leaf_model.instance_id |