def update_supersets(self, pctrl, update): with lock: policies = pctrl.policies prefix_2_FEC = pctrl.prefix_2_FEC VNH_2_vmac = pctrl.VNH_2_vmac self.logger.debug("Updating supersets...") sdx_msgs = {"type": "update", "changes": []} # the list of prefixes who will have changed VMACs impacted_prefixes = [] self.rulecounts = self.recompute_rulecounts(pctrl) # if supersets haven't been computed at all yet if len(self.supersets) == 0: sdx_msgs = self.initial_computation(pctrl) return (sdx_msgs, impacted_prefixes) if ('withdraw' in update): prefix = update['withdraw'].prefix # withdraws always change the bits of a VMAC # check if for this vnh a garp was already sent if prefix in pctrl.prefix_2_BEC: BEC_id = pctrl.prefix_2_BEC[prefix]['id'] FEC_id = pctrl.prefix_2_FEC[prefix]['id'] vnh = pctrl.BECid_FECid_2_VNH[(BEC_id, FEC_id)] if vnh in VNH_2_vmac: return(sdx_msgs, impacted_prefixes) #impacted_prefixes.append(prefix) if ('announce' not in update): return(sdx_msgs, impacted_prefixes) prefix = update['announce'].prefix # check if for this vnh a garp was already sent BEC_id = pctrl.prefix_2_BEC[prefix]['id'] FEC_id = pctrl.prefix_2_FEC[prefix]['id'] vnh = pctrl.BECid_FECid_2_VNH[(BEC_id, FEC_id)] if vnh in VNH_2_vmac: return(sdx_msgs, impacted_prefixes) # get set of all participants advertising that prefix new_set = get_all_participants_advertising(pctrl, prefix) # clean out the inactive participants new_set = set(new_set) new_set.intersection_update(self.rulecounts.keys()) # if the prefix group is still a subset, no update needed if is_subset_of_superset(new_set, self.supersets): return(sdx_msgs, impacted_prefixes) expansion_index = best_ss_to_expand_greedy(new_set, self.supersets, self.rulecounts, self.mask_size) # if no merge is possible, recompute from scratch if expansion_index == -1: # Maybe can replace this with call to initial_computation() self.logger.debug("No SS merge was possible. Recomputing.") self.logger.debug('pre-recompute: ' + str(self.supersets)) self.recompute_all_supersets(pctrl) self.logger.debug('post-recompute: ' + str(self.supersets)) sdx_msgs = {"type": "new", "changes": []} for superset_index, superset in enumerate(self.supersets): for participant in superset: sdx_msgs["changes"].append({"participant_id": participant, "superset": superset_index, "position": self.supersets[superset_index].index(participant)}) return(sdx_msgs, impacted_prefixes) # if merge is possible, do the merge and add the new rules required else: # an expansion means the VMAC for this prefix changed impacted_prefixes.append(prefix) bestSuperset = self.supersets[expansion_index] new_members = list(new_set.difference(bestSuperset)) bestSuperset.extend(new_members) self.logger.debug("Merge possible. Merging "+str(new_set)+" into superset "+str(bestSuperset)) self.logger.debug("with new members "+str(new_members)) for participant in new_members: sdx_msgs["changes"].append({"participant_id": participant, "superset": expansion_index, "position": bestSuperset.index(participant)}) return (sdx_msgs, impacted_prefixes)
def update_supersets(self, pctrl, updates): policies = pctrl.policies self.logger.debug("Updating supersets...") sdx_msgs = {"type": "update", "changes": []} # the list of prefixes who will have changed VMACs impacted_prefixes = [] self.rulecounts = self.recompute_rulecounts(pctrl) # if supersets haven't been computed at all yet if len(self.supersets) == 0: sdx_msgs = self.initial_computation(pctrl) return (sdx_msgs, impacted_prefixes) for update in updates: if ('withdraw' in update): prefix = update['withdraw'].prefix # withdraws always change the bits of a VMAC impacted_prefixes.append(prefix) if ('announce' not in update): continue prefix = update['announce'].prefix # get set of all participants advertising that prefix new_set = get_all_participants_advertising(pctrl, prefix) # clean out the inactive participants new_set = set(new_set) new_set.intersection_update(self.rulecounts.keys()) # if the prefix group is still a subset, no update needed if is_subset_of_superset(new_set, self.supersets): continue expansion_index = best_ss_to_expand_greedy(new_set, self.supersets, self.rulecounts, self.mask_size) # if no merge is possible, recompute from scratch if expansion_index == -1: self.logger.debug("No SS merge was possible. Recomputing.") self.recompute_all_supersets(pctrl) sdx_msgs = {"type": "new", "changes": []} for superset_index, superset in enumerate(self.supersets): for participant in superset: sdx_msgs["changes"].append({ "participant_id": participant, "superset": superset_index, "position": self.supersets[superset_index].index(participant) }) break # if merge is possible, do the merge and add the new rules required else: # an expansion means the VMAC for this prefix changed impacted_prefixes.append(prefix) bestSuperset = self.supersets[expansion_index] new_members = list(new_set.difference(bestSuperset)) bestSuperset.extend(new_members) self.logger.debug("Merge possible. Merging " + str(new_set) + " into superset " + str(bestSuperset)) self.logger.debug("with new members " + str(new_members)) for participant in new_members: sdx_msgs["changes"].append({ "participant_id": participant, "superset": expansion_index, "position": bestSuperset.index(participant) }) # check which participants joined a new superset and communicate to the SDX controller return (sdx_msgs, impacted_prefixes)
def update_supersets(self, pctrl, updates): with lock: policies = pctrl.policies self.logger.debug("Updating supersets...") sdx_msgs = {"type": "update", "changes": []} # the list of prefixes who will have changed VMACs impacted_prefixes = [] self.rulecounts = self.recompute_rulecounts(pctrl) # if supersets haven't been computed at all yet if len(self.supersets) == 0: sdx_msgs = self.initial_computation(pctrl) return (sdx_msgs, impacted_prefixes) for update in updates: if ('withdraw' in update): prefix = update['withdraw'].prefix # withdraws always change the bits of a VMAC impacted_prefixes.append(prefix) if ('announce' not in update): continue prefix = update['announce'].prefix # get set of all participants advertising that prefix new_set = get_all_participants_advertising(pctrl, prefix) # clean out the inactive participants new_set = set(new_set) new_set.intersection_update(self.rulecounts.keys()) # if the prefix group is still a subset, no update needed if is_subset_of_superset(new_set, self.supersets): continue expansion_index = best_ss_to_expand_greedy(new_set, self.supersets, self.rulecounts, self.mask_size) # if no merge is possible, recompute from scratch if expansion_index == -1: self.logger.debug("No SS merge was possible. Recomputing.") self.recompute_all_supersets(pctrl) sdx_msgs = {"type": "new", "changes": []} for superset in self.supersets: for participant in superset: sdx_msgs["changes"].append({"participant_id": participant, "superset": superset_index, "position": self.supersets[superset_index].index(participant)}) break # if merge is possible, do the merge and add the new rules required else: # an expansion means the VMAC for this prefix changed impacted_prefixes.append(prefix) bestSuperset = self.supersets[expansion_index] new_members = list(new_set.difference(bestSuperset)) bestSuperset.extend(new_members) self.logger.debug("Merge possible. Merging "+str(new_set)+" into superset "+str(bestSuperset)) self.logger.debug("with new members "+str(new_members)) for participant in new_members: sdx_msgs["changes"].append({"participant_id": participant, "superset": expansion_index, "position": bestSuperset.index(participant)}) # check which participants joined a new superset and communicate to the SDX controller return (sdx_msgs, impacted_prefixes)
def update_supersets(self, pctrl, parts_set): with lock: policies = pctrl.policies self.logger.debug("Updating supersets...") sdx_msgs = {"type": "update", "changes": []} # the list of prefixes who will have changed VMACs impacted_prefixes = [] self.run_rulecounts(pctrl) # if supersets haven't been computed at all yet if len(self.supersets) == 0: sdx_msgs = self.initial_computation(pctrl) return (sdx_msgs, impacted_prefixes) for prefix in parts_set: self.logger.debug("[update_supersets] get active_set" + str(parts_set[prefix]) + "of prefix " + prefix) impacted_prefixes.append(prefix) new_set = set(parts_set[prefix]) # update prefix2set, pre-store self.prefix2set[prefix] = new_set # if the prefix group is still a subset, no update needed if is_subset_of_superset(new_set, self.supersets): continue expansion_index = best_ss_to_expand_greedy( new_set, self.supersets, self.rulecounts, self.mask_size) # if no merge is possible, recompute from scratch if expansion_index == -1: # Maybe can replace this with call to initial_computation() self.logger.debug("No SS merge was possible. Recomputing.") self.logger.debug('pre-recompute: ' + str(self.supersets)) self.recompute_all_supersets(pctrl) self.logger.debug('post-recompute: ' + str(self.supersets)) sdx_msgs = {"type": "new", "changes": []} for superset_index, superset in enumerate(self.supersets): for participant in superset: sdx_msgs["changes"].append({ "participant_id": participant, "superset": superset_index, "position": self.supersets[superset_index].index( participant) }) break # if merge is possible, do the merge and add the new rules required else: # an expansion means the VMAC for this prefix changed impacted_prefixes.append(prefix) bestSuperset = self.supersets[expansion_index] new_members = list(new_set.difference(bestSuperset)) bestSuperset.extend(new_members) self.logger.debug("Merge possible. Merging " + str(new_set) + " into superset " + str(bestSuperset)) self.logger.debug("with new members " + str(new_members)) for participant in new_members: sdx_msgs["changes"].append({ "participant_id": participant, "superset": expansion_index, "position": bestSuperset.index(participant) }) return (sdx_msgs, impacted_prefixes)