-class RoundRobinDcPlacementWithSAPs(object):
- """
- Placement: Distribute VNFs across all available DCs in a round robin fashion,
- every SAP is instantiated on the same DC as the connected VNF.
- """
-
- def place(self, nsd, vnfds, saps, dcs):
-
- # place vnfs
- c = 0
- dcs_list = list(dcs.itervalues())
- for id, vnfd in vnfds.iteritems():
- vnfd["dc"] = dcs_list[c % len(dcs_list)]
- c += 1 # inc. c to use next DC
-
- # place SAPs
- vlinks = nsd.get("virtual_links", [])
- eline_fwd_links = [l for l in vlinks if (
- l["connectivity_type"] == "E-Line")]
- elan_fwd_links = [l for l in vlinks if (
- l["connectivity_type"] == "E-LAN")]
-
- # SAPs on E-Line links are placed on the same DC as the VNF on the
- # E-Line
- for link in eline_fwd_links:
- src_id, src_if_name, src_sap_id = parse_interface(
- link["connection_points_reference"][0])
- dst_id, dst_if_name, dst_sap_id = parse_interface(
- link["connection_points_reference"][1])
-
- # check if there is a SAP in the link
- if src_sap_id in saps:
- # get dc where connected vnf is mapped to
- dc = vnfds[dst_id]['dc']
- saps[src_sap_id]['dc'] = dc
-
- if dst_sap_id in saps:
- # get dc where connected vnf is mapped to
- dc = vnfds[src_id]['dc']
- saps[dst_sap_id]['dc'] = dc
-
- # SAPs on E-LANs are placed on a random DC
- dcs_list = list(dcs.itervalues())
- dc_len = len(dcs_list)
- for link in elan_fwd_links:
- for intf in link["connection_points_reference"]:
- # find SAP interfaces
- intf_id, intf_name, intf_sap_id = parse_interface(intf)
- if intf_sap_id in saps:
- dc = dcs_list[randint(0, dc_len - 1)]
- saps[intf_sap_id]['dc'] = dc
-
-