4 from vcpecommon import *
6 from datetime import datetime
8 import vcpe_custom_service
13 def config_sniro(vcpecommon, vgmux_svc_instance_uuid, vbrg_svc_instance_uuid):
14 logger = logging.getLogger(__name__)
16 logger.info('\n----------------------------------------------------------------------------------')
17 logger.info('Start to config SNIRO homing emulator')
19 preloader = preload.Preload(vcpecommon)
20 template_sniro_data = vcpecommon.find_file('sniro_data', 'json', 'preload_templates')
21 template_sniro_request = vcpecommon.find_file('sniro_request', 'json', 'preload_templates')
23 vcperescust_csar = vcpecommon.find_file('rescust', 'csar', 'csar')
24 parser = csar_parser.CsarParser()
25 parser.parse_csar(vcperescust_csar)
26 tunnelxconn_ar_name = None
29 for model in parser.vnf_models:
30 if 'tunnel' in model['modelCustomizationName']:
31 tunnelxconn_ar_name = model['modelCustomizationName']
32 elif 'brg' in model['modelCustomizationName']:
33 brg_ar_name = model['modelCustomizationName']
34 elif 'vgw' in model['modelCustomizationName']:
35 vgw_name = model['modelCustomizationName']
37 if not (tunnelxconn_ar_name and brg_ar_name and vgw_name):
38 logger.error('Cannot find all names from %s.', vcperescust_csar)
41 preloader.preload_sniro(template_sniro_data, template_sniro_request, tunnelxconn_ar_name, vgw_name, brg_ar_name,
42 vgmux_svc_instance_uuid, vbrg_svc_instance_uuid)
45 def create_one_service(vcpecommon, csar_file, vnf_template_file, preload_dict, suffix, heatbridge=False):
47 :return: service instance UUID
49 so = soutils.SoUtils(vcpecommon, 'v4')
50 return so.create_entire_service(csar_file, vnf_template_file, preload_dict, suffix, heatbridge)
52 def deploy_brg_only():
53 logging.basicConfig(level=logging.INFO, format='%(message)s')
54 logger = logging.getLogger(__name__)
56 vcpecommon = VcpeCommon()
57 preload_dict = vcpecommon.load_preload_data()
58 name_suffix = preload_dict['${brg_bng_net}'].split('_')[-1]
60 # create multiple services based on the pre-determined order
61 svc_instance_uuid = vcpecommon.load_object(vcpecommon.svc_instance_uuid_file)
62 for keyword in ['brg']:
63 heatbridge = 'gmux' == keyword
64 csar_file = vcpecommon.find_file(keyword, 'csar', 'csar')
65 vnf_template_file = vcpecommon.find_file(keyword, 'json', 'preload_templates')
66 svc_instance_uuid[keyword] = create_one_service(vcpecommon, csar_file, vnf_template_file, preload_dict,
67 name_suffix, heatbridge)
68 if not svc_instance_uuid[keyword]:
72 config_sniro(vcpecommon, svc_instance_uuid['gmux'], svc_instance_uuid['brg'])
75 logging.basicConfig(level=logging.INFO, format='%(message)s')
76 logger = logging.getLogger(__name__)
78 vcpecommon = VcpeCommon()
80 # preload all networks
81 network_template = vcpecommon.find_file('network', 'json', 'preload_templates')
82 name_suffix = datetime.now().strftime('%Y%m%d%H%M')
83 preloader = preload.Preload(vcpecommon)
84 preload_dict = preloader.preload_all_networks(network_template, name_suffix)
85 logger.debug('Initial preload dictionary:')
86 logger.debug(json.dumps(preload_dict, indent=4, sort_keys=True))
88 logger.error("Failed to preload networks.")
90 vcpecommon.save_preload_data(preload_dict)
92 # create multiple services based on the pre-determined order
93 svc_instance_uuid = {}
94 for keyword in ['infra', 'bng', 'gmux', 'brg']:
95 heatbridge = 'gmux' == keyword
96 csar_file = vcpecommon.find_file(keyword, 'csar', 'csar')
97 vnf_template_file = vcpecommon.find_file(keyword, 'json', 'preload_templates')
98 svc_instance_uuid[keyword] = create_one_service(vcpecommon, csar_file, vnf_template_file, preload_dict,
99 name_suffix, heatbridge)
100 if not svc_instance_uuid[keyword]:
103 vcpecommon.save_object(svc_instance_uuid, vcpecommon.svc_instance_uuid_file)
105 config_sniro(vcpecommon, svc_instance_uuid['gmux'], svc_instance_uuid['brg'])
107 print('----------------------------------------------------------------------------------------------------')
108 print('Congratulations! The following have been completed correctly:')
109 print(' - Infrastructure Service Instantiation: ')
110 print(' * 4 VMs: DHCP, AAA, DNS, Web Server')
111 print(' * 2 Networks: CPE_PUBLIC, CPE_SIGNAL')
112 print(' - vBNG Service Instantiation: ')
113 print(' * 1 VM: vBNG')
114 print(' * 2 Networks: BRG_BNG, BNG_MUX')
115 print(' - vGMUX Service Instantiation: ')
116 print(' * 1 VM: vGMUX')
117 print(' * 1 Network: MUX_GW')
118 print(' - vBRG Service Instantiation: ')
119 print(' * 1 VM: vBRG')
120 print(' - Adding vGMUX vServer information to AAI.')
121 print(' - SNIRO Homing Emulator configuration.')
124 def deploy_custom_service():
125 nodes = ['brg', 'mux']
126 vcpecommon = VcpeCommon(nodes)
127 custom_service = vcpe_custom_service.CustomService(vcpecommon)
130 host_dic = {k: vcpecommon.hosts[k] for k in nodes}
131 if not vcpecommon.delete_vxlan_interfaces(host_dic):
134 custom_service.clean_up_sdnc()
135 custom_service.del_all_vgw_stacks(vcpecommon.vgw_name_keyword)
138 csar_file = vcpecommon.find_file('rescust', 'csar', 'csar')
139 vgw_template_file = vcpecommon.find_file('vgw', 'json', 'preload_templates')
140 preload_dict = vcpecommon.load_preload_data()
141 custom_service.create_custom_service(csar_file, vgw_template_file, preload_dict)
144 def closed_loop(lossrate=0):
146 while 'y' != raw_input('Please enter docker container "drools" in Policy VM and type "policy stop". Then enter y here: ').lower():
148 nodes = ['brg', 'mux']
149 logger = logging.getLogger('__name__')
150 vcpecommon = VcpeCommon(nodes)
151 logger.info('Cleaning up vGMUX data reporting settings')
152 vcpecommon.del_vgmux_ves_mode()
154 vcpecommon.del_vgmux_ves_collector()
156 logger.info('Staring vGMUX data reporting to DCAE')
158 vcpecommon.set_vgmux_ves_collector()
160 logger.info('Setting vGMUX to report packet loss rate: %s', lossrate)
162 vcpecommon.set_vgmux_packet_loss_rate(lossrate, vcpecommon.load_vgmux_vnf_name())
164 print('Please enter docker container "drools" in Policy VM and type "policy start". Then observe vGMUX being restarted.')
168 logger = logging.getLogger('__name__')
169 vcpecommon = VcpeCommon()
170 config_sdnc_so.insert_customer_service_to_so(vcpecommon)
171 config_sdnc_so.insert_customer_service_to_sdnc(vcpecommon)
174 if __name__ == '__main__':
175 logging.basicConfig(level=logging.INFO, format='%(message)s')
177 print('----------------------------------------------------------------------------------------------------')
178 print(' vcpe.py: Brief info about this program')
179 # print(' vcpe.py sdc: Onboard VNFs, design and distribute vCPE services (under development)')
180 print(' vcpe.py init: Add customer service data to SDNC and SO DBs.')
181 print(' vcpe.py infra: Deploy infrastructure, including DHCP, AAA, DNS, Web Server, vBNG, vGMUX, vBRG.')
182 print(' vcpe.py customer: Deploy customer service, including vGW and VxLANs')
183 print(' vcpe.py loop: Test closed loop control')
184 print('----------------------------------------------------------------------------------------------------')
186 if len(sys.argv) != 2:
189 if sys.argv[1] == 'sdc':
190 print('Under development')
191 elif sys.argv[1] == 'init':
192 if 'y' == raw_input('Ready to add customer service data to SDNC and SO DBs? This is needed only once.'
195 elif sys.argv[1] == 'infra':
196 if 'y' == raw_input('Ready to deploy infrastructure? y/n: ').lower():
198 elif sys.argv[1] == 'customer':
199 if 'y' == raw_input('Ready to deploy customer service? y/n: ').lower():
200 deploy_custom_service()
201 elif sys.argv[1] == 'loop':
203 elif sys.argv[1] == 'noloss':
205 elif sys.argv[1] == 'brg':