Skip to content

Instantly share code, notes, and snippets.

@waqaraqeel
Last active August 29, 2015 14:17
Show Gist options
  • Save waqaraqeel/77fedcac270099c2135d to your computer and use it in GitHub Desktop.
Save waqaraqeel/77fedcac270099c2135d to your computer and use it in GitHub Desktop.
Temporary pyretic count sample
count_policy = count_bytes(interval=5, group_by=["dstip", "inport", "outport"])
count_policy.register_callback(self.__count_callback)
def __count_callback(self, pkt):
with self.count_lock:
for match, byte_count in pkt.iteritems():
if 'inport' in match.map and 'dstip' in match.map:
if match.map['inport'] is not None and match.map['dstip'] is not None:
ip = str(match.map['dstip'])
if not ip.startswith('172.0.0.'):
from_AS = self.__get_AS(match.map['inport'])
self.add_or_update_count( (ip, str(from_AS)), int(byte_count), INTERVAL)
#---------------------------------------------#
if_(ARP,
arp_policy,
identity
)) >> mac_learner >> byte_counter
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment