#!/usr/bin/python

FLOWFILE = "flowfile.bin"
SURFASSEN = [0, 288, 1101, 1103, 1104, 1124, 1125, 1126,
         1128, 1132, 1135, 1139, 1140, 1161, 1200, 1888,
         3333, 25152, 25182, 12654, 20969, 20507]


import flowd
import time


starttime = time.time()


flog = flowd.log( FLOWFILE )

totalin = {}
totalout = {}
flowcount = 0

while 1:
    flow = flog.readflow()
    if flow is None:
       break

    flowcount += 1

    source = flow.fields['src_as']
    destination = flow.fields['dst_as']
    octets = flow.fields['flow_octets']


    if (destination in SURFASSEN):
        try: totalin[destination] += octets
        except KeyError: totalin[destination] = octets

    elif (source in SURFASSEN):
        try: totalout[source] += octets
        except KeyError: totalout[source] = octets


print "finished in %i seconds" % round(time.time() - starttime,2)
print "flowcount: %s" % flowcount
print "%i msec each flow" % round((time.time()-starttime)/flowcount*1000.0,2)

