def update_policy(self,pkt): pred = self.get_pred_from_pkt(pkt) # INCREMENT THE NUMBER OF TIMES MATCHING PKT SEEN try: self.seen[pred] += 1 except KeyError: self.seen[pred] = 1 if self.seen[pred] == self.limit: val = {h : pkt[h] for h in self.group_by} self.done.append(match(val)) self.policy = ~union(self.done)
def update_policy(self, pkt): pred = self.get_pred_from_pkt(pkt) # INCREMENT THE NUMBER OF TIMES MATCHING PKT SEEN try: self.seen[pred] += 1 except KeyError: self.seen[pred] = 1 if self.seen[pred] == self.limit: val = {h: pkt[h] for h in self.group_by} self.done.append(match(val)) self.policy = ~union(self.done)
def init_countbucket(self, pkt): """When a packet from a previously unseen grouping arrives, set up new count buckets for the same. """ pred = self.groupby_filter.get_pred_from_pkt(pkt) cb = CountBucket() cb.register_callback(self.collect_pred(pred)) self.bucket_policies.append(pred >> cb) self.bucket_dict[pred] = cb # Send the current packet to the new countbucket cb.eval(pkt) cb.apply() # In future, send all packets of this grouping directly to this bucket self.policy = (self.groupby_filter >> self.fb) + union(self.bucket_policies)
def update_policy(self, pkt): if self.group_by: # MATCH ON PROVIDED GROUP_BY pred = match([(field, pkt[field]) for field in self.group_by]) else: # OTHERWISE, MATCH ON ALL AVAILABLE GROUP_BY pred = match([(field, pkt[field]) for field in pkt.available_group_by()]) # INCREMENT THE NUMBER OF TIMES MATCHING PKT SEEN try: self.seen[pred] += 1 except KeyError: self.seen[pred] = 1 if self.seen[pred] == self.limit: val = {h: pkt[h] for h in self.group_by} self.done.append(match(val)) self.policy = ~union(self.done)
def init_countbucket(self, pkt): """When a packet from a previously unseen grouping arrives, set up new count buckets for the same. """ pred = self.groupby_filter.get_pred_from_pkt(pkt) cb = CountBucket() cb.register_callback(self.collect_pred(pred)) self.bucket_policies.append(pred >> cb) self.bucket_dict[pred] = cb # Send the current packet to the new countbucket cb.eval(pkt) cb.apply() # In future, send all packets of this grouping directly to this bucket self.policy = ((self.groupby_filter >> self.fb) + union(self.bucket_policies))
def set_field_prereqs(p): """ Set pre-requisite fields for netkat/openflow in match dictionary. """ from pyretic.core.language import _match, union iptype_list = [('ethtype', IP_TYPE)] ethtype_list = [('ethtype', IP_TYPE), ('ethtype', ARP_TYPE)] ipproto_list = [('protocol', TCP_TYPE), ('protocol', UDP_TYPE)] ''' Check and set various pairs in the current list of field=value maps. ''' fmaps = [copy.copy(dict(_match(**p.map).map))] fmaps = reduce(lambda acc, x: acc + x, map(lambda m: check_tp_prereqs(m, iptype_list), fmaps), []) fmaps = reduce(lambda acc, x: acc + x, map(lambda m: check_ip_proto_prereq(m, iptype_list), fmaps), []) fmaps = reduce(lambda acc, x: acc + x, map(lambda m: check_ip_prereqs(m, ethtype_list), fmaps), []) assert len(fmaps) >= 1 if len(fmaps) > 1: return to_pred(union([_match(m) for m in fmaps])) else: return match_to_pred(fmaps[0])
def set_field_prereqs(p): """ Set pre-requisite fields for netkat/openflow in match dictionary. """ from pyretic.core.language import _match, union iptype_list = [('ethtype', IP_TYPE)] ethtype_list = [('ethtype', IP_TYPE), ('ethtype', ARP_TYPE)] ipproto_list = [('protocol', TCP_TYPE), ('protocol', UDP_TYPE)] ''' Check and set various pairs in the current list of field=value maps. ''' fmaps = [copy.copy(dict(_match(**p.map).map))] fmaps = reduce(lambda acc, x: acc + x, map(lambda m: check_tp_prereqs(m, iptype_list), fmaps), []) fmaps = reduce(lambda acc, x: acc+ x, map(lambda m: check_ip_proto_prereq(m, iptype_list), fmaps), []) fmaps = reduce(lambda acc, x: acc + x, map(lambda m: check_ip_prereqs(m, ethtype_list), fmaps), []) assert len(fmaps) >= 1 if len(fmaps) > 1: return to_pred(union([_match(m) for m in fmaps])) else: return match_to_pred(fmaps[0])
def update_policy(self): self.policy = self.assay_mcm.get_assay_ruleset() + union(self.list_of_rules)
def __init__(self, field, group): self.group = group self.field = field super(_in, self).__init__(union([match({field: i}) for i in group]))
def __init__(self,field,group): self.group = group self.field = field super(_in,self).__init__(union([match({field : i}) for i in group]))