+ if not db_sce_net["type"]:
+ db_sce_net["type"] = "bridge"
+
+ # table sce_vnffgs (vnffgd)
+ for vnffg in nsd.get("vnffgd").itervalues():
+ sce_vnffg_uuid = str(uuid4())
+ uuid_list.append(sce_vnffg_uuid)
+ db_sce_vnffg = {
+ "uuid": sce_vnffg_uuid,
+ "name": get_str(vnffg, "name", 255),
+ "scenario_id": scenario_uuid,
+ "vendor": get_str(vnffg, "vendor", 255),
+ "description": get_str(vld, "description", 255),
+ }
+ db_sce_vnffgs.append(db_sce_vnffg)
+
+ # deal with rsps
+ db_sce_rsps = []
+ for rsp in vnffg.get("rsp").itervalues():
+ sce_rsp_uuid = str(uuid4())
+ uuid_list.append(sce_rsp_uuid)
+ db_sce_rsp = {
+ "uuid": sce_rsp_uuid,
+ "name": get_str(rsp, "name", 255),
+ "sce_vnffg_id": sce_vnffg_uuid,
+ "id": get_str(rsp, "id", 255), # only useful to link with classifiers; will be removed later in the code
+ }
+ db_sce_rsps.append(db_sce_rsp)
+ db_sce_rsp_hops = []
+ for iface in rsp.get("vnfd-connection-point-ref").itervalues():
+ vnf_index = int(iface['member-vnf-index-ref'])
+ if_order = int(iface['order'])
+ # check correct parameters
+ if vnf_index not in vnf_index2vnf_uuid:
+ raise NfvoException("Error. Invalid NS descriptor at 'nsd[{}]':'rsp[{}]':'vnfd-connection-point"
+ "-ref':'member-vnf-index-ref':'{}'. Reference to a non-existing index at "
+ "'nsd':'constituent-vnfd'".format(
+ str(nsd["id"]), str(rsp["id"]), str(iface["member-vnf-index-ref"])),
+ HTTP_Bad_Request)
+
+ existing_ifaces = mydb.get_rows(SELECT=('i.uuid as uuid',),
+ FROM="interfaces as i join vms on i.vm_id=vms.uuid",
+ WHERE={'vnf_id': vnf_index2vnf_uuid[vnf_index],
+ 'external_name': get_str(iface, "vnfd-connection-point-ref",
+ 255)})
+ if not existing_ifaces:
+ raise NfvoException("Error. Invalid NS descriptor at 'nsd[{}]':'rsp[{}]':'vnfd-connection-point"
+ "-ref':'vnfd-connection-point-ref':'{}'. Reference to a non-existing "
+ "connection-point name at VNFD '{}'".format(
+ str(nsd["id"]), str(rsp["id"]), str(iface["vnfd-connection-point-ref"]),
+ str(iface.get("vnfd-id-ref"))[:255]),
+ HTTP_Bad_Request)
+ interface_uuid = existing_ifaces[0]["uuid"]
+ sce_rsp_hop_uuid = str(uuid4())
+ uuid_list.append(sce_rsp_hop_uuid)
+ db_sce_rsp_hop = {
+ "uuid": sce_rsp_hop_uuid,
+ "if_order": if_order,
+ "interface_id": interface_uuid,
+ "sce_vnf_id": vnf_index2scevnf_uuid[vnf_index],
+ "sce_rsp_id": sce_rsp_uuid,
+ }
+ db_sce_rsp_hops.append(db_sce_rsp_hop)
+
+ # deal with classifiers
+ db_sce_classifiers = []
+ for classifier in vnffg.get("classifier").itervalues():
+ sce_classifier_uuid = str(uuid4())
+ uuid_list.append(sce_classifier_uuid)
+
+ # source VNF
+ vnf_index = int(classifier['member-vnf-index-ref'])
+ if vnf_index not in vnf_index2vnf_uuid:
+ raise NfvoException("Error. Invalid NS descriptor at 'nsd[{}]':'classifier[{}]':'vnfd-connection-point"
+ "-ref':'member-vnf-index-ref':'{}'. Reference to a non-existing index at "
+ "'nsd':'constituent-vnfd'".format(
+ str(nsd["id"]), str(classifier["id"]), str(classifier["member-vnf-index-ref"])),
+ HTTP_Bad_Request)
+ existing_ifaces = mydb.get_rows(SELECT=('i.uuid as uuid',),
+ FROM="interfaces as i join vms on i.vm_id=vms.uuid",
+ WHERE={'vnf_id': vnf_index2vnf_uuid[vnf_index],
+ 'external_name': get_str(classifier, "vnfd-connection-point-ref",
+ 255)})
+ if not existing_ifaces:
+ raise NfvoException("Error. Invalid NS descriptor at 'nsd[{}]':'rsp[{}]':'vnfd-connection-point"
+ "-ref':'vnfd-connection-point-ref':'{}'. Reference to a non-existing "
+ "connection-point name at VNFD '{}'".format(
+ str(nsd["id"]), str(rsp["id"]), str(iface["vnfd-connection-point-ref"]),
+ str(iface.get("vnfd-id-ref"))[:255]),
+ HTTP_Bad_Request)
+ interface_uuid = existing_ifaces[0]["uuid"]
+
+ db_sce_classifier = {
+ "uuid": sce_classifier_uuid,
+ "name": get_str(classifier, "name", 255),
+ "sce_vnffg_id": sce_vnffg_uuid,
+ "sce_vnf_id": vnf_index2scevnf_uuid[vnf_index],
+ "interface_id": interface_uuid,
+ }
+ rsp_id = get_str(classifier, "rsp-id-ref", 255)
+ rsp = next((item for item in db_sce_rsps if item["id"] == rsp_id), None)
+ db_sce_classifier["sce_rsp_id"] = rsp["uuid"]
+ db_sce_classifiers.append(db_sce_classifier)
+
+ db_sce_classifier_matches = []
+ for match in classifier.get("match-attributes").itervalues():
+ sce_classifier_match_uuid = str(uuid4())
+ uuid_list.append(sce_classifier_match_uuid)
+ db_sce_classifier_match = {
+ "uuid": sce_classifier_match_uuid,
+ "ip_proto": get_str(match, "ip-proto", 2),
+ "source_ip": get_str(match, "source-ip-address", 16),
+ "destination_ip": get_str(match, "destination-ip-address", 16),
+ "source_port": get_str(match, "source-port", 5),
+ "destination_port": get_str(match, "destination-port", 5),
+ "sce_classifier_id": sce_classifier_uuid,
+ }
+ db_sce_classifier_matches.append(db_sce_classifier_match)
+ # TODO: vnf/cp keys
+
+ # remove unneeded id's in sce_rsps
+ for rsp in db_sce_rsps:
+ rsp.pop('id')