def erase(self, name): for prefix in nameutil.getPrefixes(name): if "CS1" in self.bfFib.table.get(prefix, []): self.bfFib.remove(prefix, "CS1") break else: self.bfCs.remove(prefix, "CS2")
def insert(self, name): for prefix in nameutil.getPrefixes(name): if "FIB" in self.bfFib.table.get(prefix, []): self.bfFib.add(prefix, "CS1") break else: self.bfCs.add(prefix, "CS2")
def processPacket(self, netType, name): """ Determine whether to accept or drop a packet. :param string netType: network layer type of the packet, either I or D :param string name: Interest or Data Name :return: accepted, reasonCodes :rtype: bool, list of strings """ reasonCodes = [] # get prefixes of the input name prefixes = nameutil.getPrefixes(name) # BF-FIB or BF-PIT prefix match prefixMatchBf, prefixMatchFpCode = self._prefixMatch[netType] for prefix in prefixes: result1 = prefixMatchBf.query(prefix) if result1 == False: pass elif result1 == "FP": reasonCodes += [prefixMatchFpCode] else: reasonCodes += result1 # BF-CS exact match for Interest if netType == "I": result2 = self.bfCs.query(name) if result2 == False: pass elif result2 == "FP": reasonCodes += ["FP2"] else: reasonCodes += result2 return len(reasonCodes) > 0, list(set(reasonCodes))
def erase(self, name): for prefix in nameutil.getPrefixes(name): self.bfCs.remove(prefix, "CS2")
def insert(self, name): for prefix in nameutil.getPrefixes(name): self.bfCs.add(prefix, "CS2")
def insert(self, name): for prefix in nameutil.getPrefixes(name): node = self.tree[prefix] node.inCs = True # node refers to the tree[name]
def insert(self, name): # update AIT newNodes = [] fibEntryNodeIndex = -1 for prefix in nameutil.getPrefixes(name): isNewNode = prefix not in self.ait node = self.ait[prefix] if not isNewNode: continue node.hasFibEntry = "FIB" in self.bfFib.table.get(prefix, []) if node.hasFibEntry and fibEntryNodeIndex < 0: fibEntryNodeIndex = len(newNodes) newNodes.append(node) node.inCs = True # node refers to the ait[name] self._trace("insert %s nNewNodes=%d" % (name, len(newNodes))) if len(newNodes) == 0: return # do nothing if already covered parentNode = newNodes[0].parent if parentNode is not None and not parentNode.hasCs2: # It's sufficient to check the parent of the top new node, # because that node must be covered previously. # If the parent has CS2, it means there's no CS1 in ancestors, # and therefore the new nodes are not covered. # Otherwise, the parent is covered by a CS1 key either on itself or an ancestor, # which implies new nodes are also covered by that CS1 key. self._trace("parentDegree %s degree=%d" % (parentNode.name, len(parentNode.children))) return # skip if covered by FIB entry if fibEntryNodeIndex >= 0: fibEntryNode = newNodes[fibEntryNodeIndex] self._trace("underFibEntry %s" % fibEntryNode.name) for node in newNodes[0:fibEntryNodeIndex]: node.labelCs2() fibEntryNode.labelCs1() self.ait.checkInvariants() return # XXX This implementation does not handle FIB entry deletion, and assumes FIB entry # has short names so that Transformation/Aggregation is not necessary. # add CS2 keys for node in newNodes: node.labelCs2() # check degree threshold if parentNode is not None and len( parentNode.children) > self.options.degreeThreshold( parentNode): assert parentNode.hasCs2 self._trace("exceedDegree %s degree=%d" % (parentNode.name, len(parentNode.children))) parentNode.labelCs1() # Transformation while len(self.bfCs) > self.bfCsHigh: target = self.ait.root.findTransformation() self._trace( "transformation bfCs=%d %s" % (len(self.bfCs), "none" if target is None else target.name)) if target is None: break target.labelCs1() # Aggregation while len(self.bfFib) > self.bfFibHigh: target = self.ait.root.findAggregation() self._trace( "aggregation bfFib=%d %s" % (len(self.bfFib), "none" if target is None else target.name)) if target is None: break target.labelCs1() self.ait.checkInvariants()