Kang Xi | 11d278c | 2018-04-06 16:56:04 -0400 | [diff] [blame] | 1 | #! /usr/bin/python |
| 2 | import sys |
| 3 | import logging |
| 4 | from vcpecommon import * |
| 5 | import soutils |
| 6 | from datetime import datetime |
| 7 | import preload |
| 8 | import vcpe_custom_service |
| 9 | import csar_parser |
| 10 | import config_sdnc_so |
Kang Xi | 6c76239 | 2018-05-30 09:27:34 -0400 | [diff] [blame] | 11 | import json |
Kang Xi | 11d278c | 2018-04-06 16:56:04 -0400 | [diff] [blame] | 12 | |
| 13 | |
| 14 | def config_sniro(vcpecommon, vgmux_svc_instance_uuid, vbrg_svc_instance_uuid): |
| 15 | logger = logging.getLogger(__name__) |
| 16 | |
| 17 | logger.info('\n----------------------------------------------------------------------------------') |
| 18 | logger.info('Start to config SNIRO homing emulator') |
| 19 | |
| 20 | preloader = preload.Preload(vcpecommon) |
| 21 | template_sniro_data = vcpecommon.find_file('sniro_data', 'json', 'preload_templates') |
| 22 | template_sniro_request = vcpecommon.find_file('sniro_request', 'json', 'preload_templates') |
| 23 | |
| 24 | vcperescust_csar = vcpecommon.find_file('rescust', 'csar', 'csar') |
| 25 | parser = csar_parser.CsarParser() |
| 26 | parser.parse_csar(vcperescust_csar) |
| 27 | tunnelxconn_ar_name = None |
| 28 | brg_ar_name = None |
| 29 | vgw_name = None |
| 30 | for model in parser.vnf_models: |
Yang Xu | 86c0e4a | 2018-12-02 13:10:41 -0500 | [diff] [blame] | 31 | logger.info('modelCustomizationName = %s', model['modelCustomizationName']) |
Kang Xi | 11d278c | 2018-04-06 16:56:04 -0400 | [diff] [blame] | 32 | if 'tunnel' in model['modelCustomizationName']: |
Yang Xu | 86c0e4a | 2018-12-02 13:10:41 -0500 | [diff] [blame] | 33 | logger.info('tunnel is in %s', model['modelCustomizationName']) |
Kang Xi | 11d278c | 2018-04-06 16:56:04 -0400 | [diff] [blame] | 34 | tunnelxconn_ar_name = model['modelCustomizationName'] |
| 35 | elif 'brg' in model['modelCustomizationName']: |
Yang Xu | 86c0e4a | 2018-12-02 13:10:41 -0500 | [diff] [blame] | 36 | logger.info('brg is in %s', model['modelCustomizationName']) |
Kang Xi | 11d278c | 2018-04-06 16:56:04 -0400 | [diff] [blame] | 37 | brg_ar_name = model['modelCustomizationName'] |
Yang Xu | 86c0e4a | 2018-12-02 13:10:41 -0500 | [diff] [blame] | 38 | #elif 'vgw' in model['modelCustomizationName']: |
| 39 | else: |
Kang Xi | 11d278c | 2018-04-06 16:56:04 -0400 | [diff] [blame] | 40 | vgw_name = model['modelCustomizationName'] |
| 41 | |
| 42 | if not (tunnelxconn_ar_name and brg_ar_name and vgw_name): |
| 43 | logger.error('Cannot find all names from %s.', vcperescust_csar) |
| 44 | sys.exit() |
| 45 | |
| 46 | preloader.preload_sniro(template_sniro_data, template_sniro_request, tunnelxconn_ar_name, vgw_name, brg_ar_name, |
| 47 | vgmux_svc_instance_uuid, vbrg_svc_instance_uuid) |
| 48 | |
| 49 | |
| 50 | def create_one_service(vcpecommon, csar_file, vnf_template_file, preload_dict, suffix, heatbridge=False): |
| 51 | """ |
| 52 | :return: service instance UUID |
| 53 | """ |
| 54 | so = soutils.SoUtils(vcpecommon, 'v4') |
| 55 | return so.create_entire_service(csar_file, vnf_template_file, preload_dict, suffix, heatbridge) |
| 56 | |
Kang Xi | 6c76239 | 2018-05-30 09:27:34 -0400 | [diff] [blame] | 57 | |
Kang Xi | 11d278c | 2018-04-06 16:56:04 -0400 | [diff] [blame] | 58 | def deploy_brg_only(): |
| 59 | logging.basicConfig(level=logging.INFO, format='%(message)s') |
| 60 | logger = logging.getLogger(__name__) |
| 61 | |
| 62 | vcpecommon = VcpeCommon() |
| 63 | preload_dict = vcpecommon.load_preload_data() |
Kang Xi | 6c76239 | 2018-05-30 09:27:34 -0400 | [diff] [blame] | 64 | # name_suffix = preload_dict['${brg_bng_net}'].split('_')[-1] |
| 65 | name_suffix = datetime.now().strftime('%Y%m%d%H%M') |
Kang Xi | 11d278c | 2018-04-06 16:56:04 -0400 | [diff] [blame] | 66 | |
| 67 | # create multiple services based on the pre-determined order |
| 68 | svc_instance_uuid = vcpecommon.load_object(vcpecommon.svc_instance_uuid_file) |
| 69 | for keyword in ['brg']: |
| 70 | heatbridge = 'gmux' == keyword |
| 71 | csar_file = vcpecommon.find_file(keyword, 'csar', 'csar') |
| 72 | vnf_template_file = vcpecommon.find_file(keyword, 'json', 'preload_templates') |
Kang Xi | 6c76239 | 2018-05-30 09:27:34 -0400 | [diff] [blame] | 73 | vcpecommon.increase_ip_address_or_vni_in_template(vnf_template_file, ['vbrgemu_private_ip_0']) |
Kang Xi | 11d278c | 2018-04-06 16:56:04 -0400 | [diff] [blame] | 74 | svc_instance_uuid[keyword] = create_one_service(vcpecommon, csar_file, vnf_template_file, preload_dict, |
| 75 | name_suffix, heatbridge) |
| 76 | if not svc_instance_uuid[keyword]: |
| 77 | sys.exit() |
| 78 | |
| 79 | # Setting up SNIRO |
| 80 | config_sniro(vcpecommon, svc_instance_uuid['gmux'], svc_instance_uuid['brg']) |
| 81 | |
Kang Xi | 6c76239 | 2018-05-30 09:27:34 -0400 | [diff] [blame] | 82 | |
Kang Xi | 11d278c | 2018-04-06 16:56:04 -0400 | [diff] [blame] | 83 | def deploy_infra(): |
Kang Xi | 11d278c | 2018-04-06 16:56:04 -0400 | [diff] [blame] | 84 | logger = logging.getLogger(__name__) |
| 85 | |
| 86 | vcpecommon = VcpeCommon() |
| 87 | |
| 88 | # preload all networks |
| 89 | network_template = vcpecommon.find_file('network', 'json', 'preload_templates') |
| 90 | name_suffix = datetime.now().strftime('%Y%m%d%H%M') |
| 91 | preloader = preload.Preload(vcpecommon) |
| 92 | preload_dict = preloader.preload_all_networks(network_template, name_suffix) |
| 93 | logger.debug('Initial preload dictionary:') |
| 94 | logger.debug(json.dumps(preload_dict, indent=4, sort_keys=True)) |
| 95 | if not preload_dict: |
| 96 | logger.error("Failed to preload networks.") |
| 97 | sys.exit() |
| 98 | vcpecommon.save_preload_data(preload_dict) |
| 99 | |
| 100 | # create multiple services based on the pre-determined order |
| 101 | svc_instance_uuid = {} |
| 102 | for keyword in ['infra', 'bng', 'gmux', 'brg']: |
| 103 | heatbridge = 'gmux' == keyword |
| 104 | csar_file = vcpecommon.find_file(keyword, 'csar', 'csar') |
| 105 | vnf_template_file = vcpecommon.find_file(keyword, 'json', 'preload_templates') |
| 106 | svc_instance_uuid[keyword] = create_one_service(vcpecommon, csar_file, vnf_template_file, preload_dict, |
| 107 | name_suffix, heatbridge) |
| 108 | if not svc_instance_uuid[keyword]: |
| 109 | sys.exit() |
| 110 | |
| 111 | vcpecommon.save_object(svc_instance_uuid, vcpecommon.svc_instance_uuid_file) |
| 112 | # Setting up SNIRO |
| 113 | config_sniro(vcpecommon, svc_instance_uuid['gmux'], svc_instance_uuid['brg']) |
| 114 | |
| 115 | print('----------------------------------------------------------------------------------------------------') |
| 116 | print('Congratulations! The following have been completed correctly:') |
| 117 | print(' - Infrastructure Service Instantiation: ') |
| 118 | print(' * 4 VMs: DHCP, AAA, DNS, Web Server') |
| 119 | print(' * 2 Networks: CPE_PUBLIC, CPE_SIGNAL') |
| 120 | print(' - vBNG Service Instantiation: ') |
| 121 | print(' * 1 VM: vBNG') |
| 122 | print(' * 2 Networks: BRG_BNG, BNG_MUX') |
| 123 | print(' - vGMUX Service Instantiation: ') |
| 124 | print(' * 1 VM: vGMUX') |
| 125 | print(' * 1 Network: MUX_GW') |
| 126 | print(' - vBRG Service Instantiation: ') |
| 127 | print(' * 1 VM: vBRG') |
| 128 | print(' - Adding vGMUX vServer information to AAI.') |
| 129 | print(' - SNIRO Homing Emulator configuration.') |
| 130 | |
| 131 | |
| 132 | def deploy_custom_service(): |
| 133 | nodes = ['brg', 'mux'] |
| 134 | vcpecommon = VcpeCommon(nodes) |
| 135 | custom_service = vcpe_custom_service.CustomService(vcpecommon) |
| 136 | |
| 137 | # clean up |
Kang Xi | 0e0a1d6 | 2018-07-23 16:53:54 -0400 | [diff] [blame] | 138 | host_dic = {k: vcpecommon.hosts[k] for k in nodes} |
| 139 | if False: |
| 140 | if not vcpecommon.delete_vxlan_interfaces(host_dic): |
| 141 | sys.exit() |
| 142 | custom_service.del_all_vgw_stacks(vcpecommon.vgw_name_keyword) |
Kang Xi | 11d278c | 2018-04-06 16:56:04 -0400 | [diff] [blame] | 143 | |
Kang Xi | 6c76239 | 2018-05-30 09:27:34 -0400 | [diff] [blame] | 144 | #custom_service.clean_up_sdnc() |
Kang Xi | 11d278c | 2018-04-06 16:56:04 -0400 | [diff] [blame] | 145 | |
| 146 | # create new service |
| 147 | csar_file = vcpecommon.find_file('rescust', 'csar', 'csar') |
| 148 | vgw_template_file = vcpecommon.find_file('vgw', 'json', 'preload_templates') |
Brian Freeman | 81f6e9e | 2018-11-11 22:36:20 -0500 | [diff] [blame] | 149 | vgw_gra_template_file = vcpecommon.find_file('gwgra', 'json', 'preload_templates') |
Kang Xi | 11d278c | 2018-04-06 16:56:04 -0400 | [diff] [blame] | 150 | preload_dict = vcpecommon.load_preload_data() |
Brian Freeman | 81f6e9e | 2018-11-11 22:36:20 -0500 | [diff] [blame] | 151 | custom_service.create_custom_service(csar_file, vgw_template_file, vgw_gra_template_file, preload_dict) |
Kang Xi | 11d278c | 2018-04-06 16:56:04 -0400 | [diff] [blame] | 152 | |
| 153 | |
| 154 | def closed_loop(lossrate=0): |
| 155 | if lossrate > 0: |
| 156 | while 'y' != raw_input('Please enter docker container "drools" in Policy VM and type "policy stop". Then enter y here: ').lower(): |
| 157 | continue |
| 158 | nodes = ['brg', 'mux'] |
| 159 | logger = logging.getLogger('__name__') |
| 160 | vcpecommon = VcpeCommon(nodes) |
| 161 | logger.info('Cleaning up vGMUX data reporting settings') |
| 162 | vcpecommon.del_vgmux_ves_mode() |
| 163 | time.sleep(2) |
| 164 | vcpecommon.del_vgmux_ves_collector() |
| 165 | |
Yang Xu | 9f935b2 | 2018-11-22 10:56:52 -0500 | [diff] [blame] | 166 | logger.info('Starting vGMUX data reporting to DCAE') |
Kang Xi | 11d278c | 2018-04-06 16:56:04 -0400 | [diff] [blame] | 167 | time.sleep(2) |
| 168 | vcpecommon.set_vgmux_ves_collector() |
| 169 | |
| 170 | logger.info('Setting vGMUX to report packet loss rate: %s', lossrate) |
| 171 | time.sleep(2) |
| 172 | vcpecommon.set_vgmux_packet_loss_rate(lossrate, vcpecommon.load_vgmux_vnf_name()) |
| 173 | if lossrate > 0: |
| 174 | print('Please enter docker container "drools" in Policy VM and type "policy start". Then observe vGMUX being restarted.') |
| 175 | |
| 176 | |
| 177 | def init_so_sdnc(): |
| 178 | logger = logging.getLogger('__name__') |
| 179 | vcpecommon = VcpeCommon() |
| 180 | config_sdnc_so.insert_customer_service_to_so(vcpecommon) |
Yang Xu | 63a0afd | 2018-11-20 16:01:01 -0500 | [diff] [blame] | 181 | #config_sdnc_so.insert_customer_service_to_sdnc(vcpecommon) |
Brian Freeman | 8076a87 | 2018-11-13 11:34:48 -0500 | [diff] [blame] | 182 | vgw_vfmod_name_index= 0 |
| 183 | vcpecommon.save_object(vgw_vfmod_name_index, vcpecommon.vgw_vfmod_name_index_file) |
Kang Xi | 11d278c | 2018-04-06 16:56:04 -0400 | [diff] [blame] | 184 | |
| 185 | |
Kang Xi | 6c76239 | 2018-05-30 09:27:34 -0400 | [diff] [blame] | 186 | def tmp_sniro(): |
| 187 | logger = logging.getLogger(__name__) |
| 188 | |
| 189 | vcpecommon = VcpeCommon() |
| 190 | |
| 191 | svc_instance_uuid = vcpecommon.load_object(vcpecommon.svc_instance_uuid_file) |
| 192 | # Setting up SNIRO |
| 193 | config_sniro(vcpecommon, svc_instance_uuid['gmux'], svc_instance_uuid['brg']) |
| 194 | |
Kang Xi | 11d278c | 2018-04-06 16:56:04 -0400 | [diff] [blame] | 195 | if __name__ == '__main__': |
Brian Freeman | a605bc7 | 2018-11-12 10:50:30 -0500 | [diff] [blame] | 196 | logging.basicConfig(level=logging.DEBUG, format='%(message)s') |
Kang Xi | 11d278c | 2018-04-06 16:56:04 -0400 | [diff] [blame] | 197 | |
| 198 | print('----------------------------------------------------------------------------------------------------') |
| 199 | print(' vcpe.py: Brief info about this program') |
| 200 | # print(' vcpe.py sdc: Onboard VNFs, design and distribute vCPE services (under development)') |
| 201 | print(' vcpe.py init: Add customer service data to SDNC and SO DBs.') |
| 202 | print(' vcpe.py infra: Deploy infrastructure, including DHCP, AAA, DNS, Web Server, vBNG, vGMUX, vBRG.') |
Brian Freeman | ec9fe0e | 2018-11-12 12:37:12 -0500 | [diff] [blame] | 203 | print(' vcpe.py brg: Deploy brg only (for testing after infra succeeds).') |
Kang Xi | 11d278c | 2018-04-06 16:56:04 -0400 | [diff] [blame] | 204 | print(' vcpe.py customer: Deploy customer service, including vGW and VxLANs') |
| 205 | print(' vcpe.py loop: Test closed loop control') |
| 206 | print('----------------------------------------------------------------------------------------------------') |
| 207 | |
| 208 | if len(sys.argv) != 2: |
| 209 | sys.exit() |
| 210 | |
| 211 | if sys.argv[1] == 'sdc': |
| 212 | print('Under development') |
| 213 | elif sys.argv[1] == 'init': |
| 214 | if 'y' == raw_input('Ready to add customer service data to SDNC and SO DBs? This is needed only once.' |
| 215 | 'y/n: ').lower(): |
| 216 | init_so_sdnc() |
| 217 | elif sys.argv[1] == 'infra': |
| 218 | if 'y' == raw_input('Ready to deploy infrastructure? y/n: ').lower(): |
| 219 | deploy_infra() |
| 220 | elif sys.argv[1] == 'customer': |
| 221 | if 'y' == raw_input('Ready to deploy customer service? y/n: ').lower(): |
| 222 | deploy_custom_service() |
| 223 | elif sys.argv[1] == 'loop': |
| 224 | closed_loop(22) |
| 225 | elif sys.argv[1] == 'noloss': |
| 226 | closed_loop(0) |
| 227 | elif sys.argv[1] == 'brg': |
| 228 | deploy_brg_only() |
Yang Xu | 86c0e4a | 2018-12-02 13:10:41 -0500 | [diff] [blame] | 229 | elif sys.argv[1] == 'sniro': |
| 230 | tmp_sniro() |
Kang Xi | 11d278c | 2018-04-06 16:56:04 -0400 | [diff] [blame] | 231 | |