diff --git a/main.py b/main.py index 3ffe42a..2a51199 100644 --- a/main.py +++ b/main.py @@ -43,6 +43,7 @@ def __init__(self): self.flow_config = dict() self.filter_active = dict() self.routers = list() + self.vrfs = list() def addNewFlowRoute(self, flowRouteData=None): @@ -152,9 +153,32 @@ def getActiveFlowRoutes(self): # data = dev.rpc.get_config(filter_xml='routing-options/flow/route/name') frt = FlowRoutesTable(dev) - for flowtable in ['inetflow.0', 'inet6flow.0', 'trcps.inetflow.0', 'trcps.inet6flow.0']: + flowtables = list() + for vrf in self.vrfs: + if vrf == 'default': + flowtables.extend(['inetflow.0', 'inet6flow.0']) + else: + flowtables.extend(['{}.inetflow.0'.format(vrf), '{}.inet6flow.0'.format(vrf)]) +# for flowtable in ['inetflow.0', 'inet6flow.0', 'trcps.inetflow.0', 'trcps.inet6flow.0']: + for flowtable in flowtables: frt.get(table=flowtable) + _flowtable = flowtable.split('.') + _vrf = ['',''] + if len(_flowtable) == 2: + _vrf[0] = 'default' + if _flowtable[0] == 'inetflow': + _vrf[1] = 'v4' + if _flowtable[0] == 'inet6flow': + _vrf[1] = 'v6' + if len(_flowtable) > 2: + _vrf[0] = _flowtable[0] + if _flowtable[1] == 'inetflow': + _vrf[1] = 'v4' + if _flowtable[1] == 'inet6flow': + _vrf[1] = 'v6' + vrf = '{} ({})'.format(_vrf[0], _vrf[1]) + for flow in frt: destination = flow.destination.split(',') @@ -223,7 +247,7 @@ def getActiveFlowRoutes(self): if hex_dig not in self.flow_active: - self.flow_active[hex_dig] = {'router': name, 'vrf': flowtable, 'term': flow.term, 'destination': destination, + self.flow_active[hex_dig] = {'router': name, 'vrf': vrf, 'term': flow.term, 'destination': destination, 'commAction': commAction, 'krtAction': krt_actions, 'age': str(_age['current']), 'hash': hex_dig, 'status': 'new'} @@ -262,7 +286,13 @@ def getActiveFlowRouteFilter(self): with Device(host=value['ip'], user=self.dev_user, password=self.dev_pw) as dev: frft = FlowFilterTable(dev) - for table in ['__flowspec_default_inet__', '__flowspec_default_inet6__', '__flowspec_trcps_inet__', '__flowspec_trcps_inet6__']: + flowfilters = list() + for vrf in self.vrfs: + flowfilters.extend(['__flowspec_{}_inet__'.format(vrf), '__flowspec_{}_inet6__'.format(vrf)]) + + for table in flowfilters: +# for table in ['__flowspec_default_inet__', '__flowspec_default_inet6__', '__flowspec_trcps_inet__', '__flowspec_trcps_inet6__']: + frft.get(filtername=table) for filter in frft: @@ -273,7 +303,14 @@ def getActiveFlowRouteFilter(self): _item = item.split('=') data[didx] = _item[1] if len(_item) > 1 else _item[0] - self.filter_active[name].append({'vrf': table, 'data': data, 'packet_count': filter.packet_count, + _vrf = table.split('_') + if _vrf[4] == 'inet': + _vrf[4] = 'v4' + if _vrf[4] == 'inet6': + _vrf[4] = 'v6' + vrf = '{} ({})'.format(_vrf[3], _vrf[4]) + + self.filter_active[name].append({'vrf': vrf, 'data': data, 'packet_count': filter.packet_count, 'byte_count': filter.byte_count}) return True, self.filter_active @@ -403,6 +440,7 @@ def load_settings(self): self.dev_pw = config['dev_pw'] self.age_out_interval = config['age_out_interval'] self.routers = config['routers'] + self.vrfs = config['vrfs'] class BGPFlow(object): @@ -536,6 +574,6 @@ def POST(self): webapp.api.frft = Frft(my_dev=my_dev) cherrypy.config.update({'log.screen': True, 'server.socket_host': '0.0.0.0', - 'server.socket_port': 8088, + 'server.socket_port': 8080, }) cherrypy.quickstart(webapp, '/', conf) diff --git a/ui/index.html b/ui/index.html index 4cc11cc..a330eda 100644 --- a/ui/index.html +++ b/ui/index.html @@ -129,7 +129,7 @@

Monitoring BGP Flow - +
NameRouter VRF Destination Prefix Source Prefix