From 111989b5acc5e2f9bf378ded5c0d1d91a4dda4bb Mon Sep 17 00:00:00 2001 From: lauren Date: Sat, 5 Nov 2022 02:21:09 -0400 Subject: [PATCH 1/6] add geant lg agent --- docker-compose.yml | 14 ++- etc/{lg-agent.json => lg-agent-cern.json} | 0 etc/lg-agent-geant.json | 54 +++++++++ setup.cfg | 1 + src/alto/agent/geantlg.py | 134 ++++++++++++++++++++++ 5 files changed, 200 insertions(+), 3 deletions(-) rename etc/{lg-agent.json => lg-agent-cern.json} (100%) create mode 100644 etc/lg-agent-geant.json create mode 100644 src/alto/agent/geantlg.py diff --git a/docker-compose.yml b/docker-compose.yml index 283a45e..61dbec0 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -15,13 +15,21 @@ services: - ./etc/alto.conf:/opt/alto/etc/alto.conf entrypoint: gunicorn command: ["-b", "0.0.0.0:8000", "--reload", "alto.server.northbound.wsgi", "--preload", "--capture-output"] - alto-lg-agent: + # alto-lg-agent-cern: + # image: openalto/alto + # volumes: + # - ./etc/lg-agent.json:/etc/lg-agent-cern.json + # - ./etc/alto.conf:/opt/alto/etc/alto.conf + # entrypoint: python + # command: ["-m", "alto.agent.manage", "--pid", "/tmp", "start", "-c", "/etc/lg-agent-cern.json", "-D", "cernlg"] + # network_mode: "service:alto-frontend" + alto-lg-agent-geant: image: openalto/alto volumes: - - ./etc/lg-agent.json:/etc/lg-agent.json + - ./etc/lg-agent-geant.json:/etc/lg-agent-geant.json - ./etc/alto.conf:/opt/alto/etc/alto.conf entrypoint: python - command: ["-m", "alto.agent.manage", "--pid", "/tmp", "start", "-c", "/etc/lg-agent.json", "-D", "cernlg"] + command: ["-m", "alto.agent.manage", "--pid", "/tmp", "start", "-c", "/etc/lg-agent-geant.json", "-D", "geantlg"] network_mode: "service:alto-frontend" alto-cric-agent: image: openalto/alto diff --git a/etc/lg-agent.json b/etc/lg-agent-cern.json similarity index 100% rename from etc/lg-agent.json rename to etc/lg-agent-cern.json diff --git a/etc/lg-agent-geant.json b/etc/lg-agent-geant.json new file mode 100644 index 0000000..eb34d30 --- /dev/null +++ b/etc/lg-agent-geant.json @@ -0,0 +1,54 @@ +{ + "namespace": "default", + "agent_class": "alto.agent.geantlg.LookingGlassAgent", + "uri": "https://lg.geant.org/rest/submit", + "listened_routers": [ + "mx2.bra.sk.geant.net", + "mx1.mil2.it.geant.net", + "mx1.lon.uk.geant.net", + "rt1.bil.es.geant.net", + "rt2.rig.lv.geant.net", + "rt2.tal.ee.geant.net", + "rt1.chi.md.geant.net", + "rt1.por.pt.geant.net", + "rt2.chi.md.geant.net", + "mx1.mad.es.geant.net", + "rt1.kau.lt.geant.net", + "mx1.buc.ro.geant.net", + "mx1.pra.cz.geant.net", + "mx1.bud.hu.geant.net", + "rt1.kie.ua.geant.net", + "rt2.ams.nl.geant.net", + "amt1.fra.de.re0.geant.net", + "mx2.bru.be.geant.net", + "mx1.gen.ch.geant.net", + "rt1.tal.ee.geant.net", + "rt1.rig.lv.geant.net", + "rt1.mar.fr.geant.net", + "mx1.fra.de.geant.net", + "mx1.dub2.ie.geant.net", + "rt1.bra.sk.geant.net", + "mx1.poz.pl.geant.net", + "rt2.bra.sk.geant.net", + "mx1.sof.bg.geant.net", + "mx2.zag.hr.geant.net", + "mx2.lis.pt.geant.net", + "mx1.par.fr.geant.net", + "rt1.mil2.it.geant.net", + "mx2.lju.si.geant.net", + "mx1.lon2.uk.geant.net", + "rt2.kie.ua.geant.net", + "rt2.kau.lt.geant.net", + "mx1.vie.at.geant.net", + "mx1.dub.ie.geant.net", + "mx1.ath2.gr.geant.net", + "mx1.ham.de.geant.net", + "mx2.ath.gr.geant.net", + "mx1.ams.nl.geant.net", + "amt1.lon2.uk.re0.geant.net" + ], + "refresh_interval": 300, + "prefixes": [ + "192.41.230.0/23" + ] +} diff --git a/setup.cfg b/setup.cfg index a551c0f..242fbcf 100644 --- a/setup.cfg +++ b/setup.cfg @@ -58,6 +58,7 @@ install_requires = lxml service gunicorn + xmltodict [options.packages.find] diff --git a/src/alto/agent/geantlg.py b/src/alto/agent/geantlg.py new file mode 100644 index 0000000..a032ed5 --- /dev/null +++ b/src/alto/agent/geantlg.py @@ -0,0 +1,134 @@ +import requests +import json +import logging +import time +import xmltodict + +from pytricia import PyTricia + +from alto.server.components.datasource import DBInfo, DataSourceAgent +from alto.server.components.db import data_broker_manager, ForwardingRule, Match, Action + +class LookingGlassAgent(DataSourceAgent): + """ + Class of data source agent for looking glass server. + """ + + def __init__(self, dbinfo: DBInfo, name: str, namespace='default', **cfg): + super().__init__(dbinfo, name, namespace) + + self.uri = self.ensure_field(cfg, 'uri') + self.router = cfg.get('default_router', None) + self.proxies = cfg.get('proxies', None) + self.refresh_interval = cfg.get('refresh_interval', None) + self.listened_routers = cfg.get('listened_routers', set()) + self.default_router = cfg.get('default_router', None) + self.prefixes = cfg.get('prefixes', set()) + + logging.info("Loading databases") + self.db = [ self.request_db(t) for t in ['forwarding', 'endpoint']] + + if self.default_router: + if len(self.listened_routers) == 0: + self.listened_routers |= { self.default_router } + + eb_trans = self.db[1].new_transaction() + default_sw = {'dpid': self.default_router, 'in_port': '0'} + eb_trans.add_property('0.0.0.0/0', default_sw) + eb_trans.commit() + + def _parse_routes(self, results_dict, width=19, route_dict=PyTricia(128)): + route_dict = dict() + for prefix in results_dict: + route_info = [] + for entry in results_dict[prefix]["rt"]["rt-entry"]: + attribute_dict = dict() + attribute_dict["selected"] = entry["active-tag"] == "*" + attribute_dict["preference"] = int(entry.get("preference", None)) + attribute_dict["peer"] = entry.get("learned-from", None) + attribute_dict["as_path"] = entry.get("as-path", None) + + if isinstance(entry.get("nh", None), list): + for hop in entry.get("nh", []): + if hop.get("selected-next-hop", True) is None: + attribute_dict["next_hop"] = hop.get("to", None) + attribute_dict["outgoing"] = hop.get("via", None) + elif isinstance(entry.get("nh", None), set): + hop = entry.get("nh") + if hop.get("selected-next-hop", True) is None: + attribute_dict["next_hop"] = hop.get("to", None) + attribute_dict["outgoing"] = hop.get("via", None) + + route_info.append(attribute_dict) + route_dict[prefix] = route_info + return route_dict + + def _do_query(self, router=None, args=None): + results = dict() + for prefix in args: + try: + data = requests.post(self.uri, + json={ + 'selectedRouters': [{"name": router}], + 'selectedCommand': { + 'value': f'show route {prefix} | display xml' + }, + }, + headers={ + 'Content-Type': 'application/json' + }, + proxies=self.proxies) + doctree = data.json()['output'][router]['commandResult'] + query_result = json.loads(json.dumps(xmltodict.parse(doctree))) + for table in query_result["rpc-reply"]["route-information"]["route-table"]: + if table["table-name"] == "lhcone-l3vpn.inet.0": + results.update({prefix : table}) + except: + logging.warn(f"Error fetching prefix {prefix} on router {router}; skipping") + return results + + def get_routes(self, ipprefix=None, router=None): + """ + Get a route entries. + + Parameters + ---------- + ipprefix : str + Destination IP prefix to lookup. If None, `prefixes` will be used. + router : str + Name of the looking glass router. If None, `default_router` will be + used. + + Returns + ------- + routes : list + All the route entries for the given destination IP prefix. + """ + logging.info('Loading routes on %s' % (router)) + args = ipprefix if ipprefix else self.prefixes + results_dict = self._do_query(router=router, args=args) + logging.info('Parsing routes on %s' % (router)) + routes = self._parse_routes(results_dict) + return routes + + def update(self): + fib_trans = self.db[0].new_transaction() + for _router in self.listened_routers: + routes = self.get_routes(router=_router) + for dst_prefix, route in routes.items(): + if route: + route = route[0] + else: + continue + pkt_match = Match(dst_prefix) + action = Action(**route) + rule = ForwardingRule(pkt_match, action) + fib_trans.add_rule(_router, rule) + fib_trans.commit() + + def run(self): + if self.refresh_interval is None: + self.refresh_interval = 60 + while True: + self.update() + time.sleep(self.refresh_interval) From dedb838d38e49f71a60bb3d1028be3ddc2beff41 Mon Sep 17 00:00:00 2001 From: lauren Date: Sat, 5 Nov 2022 12:13:34 -0400 Subject: [PATCH 2/6] add prefixes --- etc/lg-agent-geant.json | 63 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 62 insertions(+), 1 deletion(-) diff --git a/etc/lg-agent-geant.json b/etc/lg-agent-geant.json index eb34d30..3686e0d 100644 --- a/etc/lg-agent-geant.json +++ b/etc/lg-agent-geant.json @@ -49,6 +49,67 @@ ], "refresh_interval": 300, "prefixes": [ - "192.41.230.0/23" + "2001:48a8:68f7:4000::/50", "2001:48a8:68f7:c000::/50", "192.41.236.0/23", "192.41.238.0/28", "2001:48a8:68f7:8001::/64", "192.41.230.0/23", "192.41.238.0/28", + "2001:48a8:68f7:1::/64", "140.221.68.0/24", "140.221.69.0/24", "140.221.96.0/23", "2620:0:dc0:4800::/59", "153.5.72.0/23", "2001:1470:8000:406::/64", "194.249.156.0/24", + "2001:1470:ff8a::/48", "153.5.68.0/22", "2001:1470:ff94::/48", "128.250.185.224/27", "192.231.127.0/24", "192.43.208.0/24", "202.122.32.248/29", "202.122.32.45/32", + "202.122.32.160/27", "202.122.33.0/24", "202.122.35.0/24", "202.122.36.0/24", "202.122.37.128/28", "202.38.128.0/24", "202.38.129.0/24", "2401:de00::/64", + "2401:de00:1:32::/64", "2401:de00:1:32:7ae7:d1ff:feca:d1bb/128", "2401:de00:2:33::/64", "2401:de00:2:332::/64", "130.199.48.0/23", "130.199.54.0/24", "130.199.185.0/24", + "192.12.15.0/24", "192.33.128.0/24", "2620:0:210::/48", "200.133.193.160/27", "200.143.233.0/27", "192.5.207.0/24", "2610:58:3:aaaa::/64", "142.244.83.0/27", + "142.244.105.64/27", "205.189.32.79/32", "132.206.245.224/27", "206.12.127.0/24", "142.150.188.0/24", "206.12.154.0/24", "206.12.155.0/24", "2607:f8f0:c10:70f3::/64", + "2607:f8f0:c11:7000::/64", "206.12.48.224/27", "199.241.165.64/26", "152.84.101.0/24", "2804:1f10:8000:801::/64", "192.65.183.0/24", "2001:1458:a00::/48", "137.138.0.0/16", + "188.184.0.0/17", "188.185.0.0/17", "2001:1458:d00::/48", "192.16.166.0/24", "2001:1458:302::/48", "128.142.0.0/16", "188.184.128.0/17", "2001:1458:301::/48", + "2001:1458:303::/48", "192.101.161.128/26", "192.101.166.234/32", "2001:720:42c:aaee::/64", "192.84.86.0/24", "198.32.43.0/24", "198.32.44.0/24", "198.32.45.0/24", + "2605:d9c0::/32", "2607:f380:a4f::/48", "2001:1310:3121::/48", "202.179.241.216/30", "210.25.189.248/30", "2001:254:1:204::/64", "2001:252:0:112::/64", "149.156.5.192/27", + "195.113.186.64/26", "195.113.219.0/26", "195.113.179.104/30", "195.113.232.216/31", "195.113.232.218/31", "2001:718:401:6016::1:10/127", "188.1.153.0/24", + "131.169.160.0/21", "131.169.191.0/24", "131.169.192.0/24", "131.169.80.0/24", "131.169.98.0/24", "2001:638:700:1050::/64", "2001:638:700:1062::/64", "2001:638:700:10a0::/64", + "2001:638:700:10bf::/64", "2001:638:700:10c0::/64", "141.34.192.0/21", "141.34.200.0/24", "2001:638:700:f0c0::/64", "2001:638:700:f0c2::/64", "2001:638:700:f0c8::/64", + "146.83.90.0/24", "2001:1310:3121:1112::/64", "134.158.72.0/23", "134.158.78.0/24", "2001:660:3024::/48", "134.158.132.0/23", "2001:660:302c::/48", "134.158.158.0/23", + "2001:660:3036::/48", "157.180.228.0/22", "157.180.232.0/22", "192.108.45.0/24", "192.108.46.0/23", "192.108.68.0/24", "2a00:139c::/45", "62.40.103.0/24", "62.40.126.0/24", + "2001:798:111:1::/64", "128.104.227.0/24", "144.92.180.0/23", "2607:f388:101c:1000::/64", "195.251.201.128/26", "2001:648:2e01:110::/64", "192.54.205.0/24", "192.54.206.0/24", + "192.54.207.0/24", "2001:660:3031:110::/64", "140.181.2.0/24", "72.36.81.64/26", "72.36.96.0/24", "2620:0:e01:4800::/56", "144.16.112.0/24", "14.139.119.64/26", + "2405:8a00:c012::/48", "134.158.48.0/21", "134.158.104.0/21", "134.158.168.0/21", "134.158.208.0/21", "134.158.234.0/23", "134.158.238.0/24", "134.158.239.0/24", + "193.48.99.0/24", "2001:660:5009::/48", "193.48.99.0/24", "2001:660:5009:9::/64", "134.158.20.0/23", "2001:660:5408::/48", "134.158.83.0/24", "2001:660:5009:a013::/64", + "134.158.150.0/24", "134.158.151.0/24", "2001:660:4705::/48", "134.158.84.0/24", "134.158.102.0/23", "134.158.96.0/21", "2001:660:5310:400::/56", "2001:660:5310::/48", + "134.158.120.0/21", "2001:660:5104::/48", "193.48.83.0/24", "2001:660:530f::/48", "193.48.101.0/24", "2001:660:7224::/48", "144.16.111.0/24", "2406:f00:9::/48", + "149.165.243.0/24", "90.147.66.0/24", "90.147.75.0/24", "90.147.168.0/23", "2001:760:4227::/48", "90.147.16.0/23", "193.206.219.0/24", "2001:760:420d:80::/64", "192.84.128.0/24", + "2001:760:4228::/64", "192.135.35.224/27", "193.206.93.0/24", "2001:760:4229::/48", "192.135.14.0/24", "2001:760:4224::/48", "90.147.67.0/24", "2001:760:422a:137::/64", + "192.135.9.0/24", "193.205.76.0/23", "2001:760:422b::/48", "141.108.35.0/24", "141.108.36.0/22", "2001:760:422c:35::/64", "2001:760:422c:36::/64", "2001:760:422c:38::/64", + "131.154.128.0/17", "2001:760:4205::/48", "193.205.66.128/25", "193.206.184.0/26", "144.206.150.0/23", "2001:67c:1bec:f069::/64", "159.93.37.0/24", "159.93.39.0/24", + "159.93.220.0/22", "159.93.224.0/22", "2a05:81c5:302:37::/64", "2a05:81c5:302:224::/64", "159.93.228.0/22", "159.93.39.0/24", "2a05:81c5:301:228::/64", "202.180.40.0/27", + "202.13.197.192/26", "202.13.203.128/26", "202.13.207.128/25", "202.13.223.132/30", "2001:2f8:3e:cc21::/120", "133.11.254.16/30", "150.99.93.20/30", "202.13.223.52/30", + "202.13.223.192/29", "2001:2f8:3e:cc22::/64", "2001:2f8:102d:590::/64", "2001:2f8:ffd0:ffff::/64", "193.239.180.128/27", "193.239.180.208/29", "2a00:fc00:e009::/56", + "134.75.123.0/24", "134.75.124.0/24", "134.75.126.0/24", "134.75.127.0/24", "134.75.125.0/24", "2001:320:15:125::/64", "155.230.20.0/22", "2407:c000:c024::/48", "134.75.1.128/25", + "134.75.203.16/30", "134.75.203.240/30", "18.12.0.0/20", "2603:4000:c00::/48", "149.165.224.0/23", "2001:18e8:c02:5::/64", "149.165.236.64/29", "192.170.224.0/19", + "192.170.240.0/23", "2605:9a00:10::/48", "2605:9a00:10:200a::/64", "72.36.96.0/24", "2620:0:e01:4800::/64", "109.105.124.0/22", "2001:948:40::/42", "129.93.153.0/24", + "129.93.182.0/23", "129.93.239.128/26", "129.93.244.192/26", "2600:900:6:1101::/64", "2600:900:6:1102::/64", "2600:900:6:1103::/64", "2600:900:6:1301::/64", "2600:900:6:1302::/64", + "2600:900:6:3103::/64", "81.180.86.0/24", "2001:b30:4202:100::/64", "2a07:8504:120:e060::/64", "2a07:8504:120:e068::/64", "194.171.96.128/25", "194.171.98.112/29", + "194.171.96.128/25", "194.171.98.112/29", "2a07:8504:120:e060::/64", "2a07:8504:120:e068::/64", "206.12.127.0/24", "192.12.68.0/24", "192.188.182.0/24", "2620:0:2b3d:100::/56", + "2620:0:2b3d::/56", "129.15.40.0/23", "129.15.42.0/23", "156.110.41.0/24", "2610:1d8:a01:1::/64", "193.109.172.0/24", "2001:67c:1148:200::/64", "2001:67c:1148:201::/64", + "2001:67c:1148:202::/64", "2001:67c:1148:203::/64", "2001:67c:1148:204::/64", "2001:67c:1148:301::/64", "144.206.255.184/31", "149.156.5.16/30", "149.156.5.20/30", + "150.254.182.0/31", "213.135.50.84/30", "2001:67c:1bec::255:184/127", "2001:6a0:fff:ff0a::/64", "2001:6d8:0:20f::/64", "2001:6d8:0:21f::/64", "2001:808:2:22::/64", "147.231.11.0/25", + "147.231.25.0/24", "147.231.98.224/27", "195.113.219.0/25", "2001:718:19::/48", "2001:718:401:6017::/64", "2001:718:401:6025::/64", "2001:718:401:6e03::/64", + "2001:718:409:7000::/52", "150.254.198.0/25", "2001:808:1:b::/64", "128.211.128.0/19", "128.211.160.0/22", "2001:18e8:804::/48", "130.246.180.0/22", "130.246.216.0/21", + "2001:630:58:1800::/64", "130.246.176.0/22", "130.246.152.240/28", "2001:630:58:1820::/64", "81.180.86.0/24", "2001:b30:4202:100::/64", "81.180.86.0/24", "85.120.46.0/24", + "2001:b30:4210:1::/64", "193.231.25.224/27", "2001:b30:4202:100::/64", "85.122.16.0/20", "194.176.164.0/22", "144.206.237.0/24", "2001:67c:1bec:237::/64", "144.206.255.128/26", + "2001:67c:1bec::255:0/112", "144.206.224.0/24", "144.206.236.0/24", "2001:67c:1bec:224::/64", "2001:67c:1bec:236::/64", "144.206.221.0/24", "85.143.115.32/27", "2001:b08:22:90::/64", + "144.206.130.0/23", "2001:67c:1bdc:100::/64", "2001:67c:1bdc:101::/64", "2001:67c:1bdc:102::/64", "2001:67c:1bdc:200::/64", "2001:67c:1bdc:201::/64", "194.190.165.0/24", + "2001:678:7d8:2000::/52", "185.141.124.192/27", "2a07:a6c0:b:192::/64", "195.70.215.128/26", "2a02:208:0:1::/64", "185.207.88.0/24", "2a0e:e140::/64", "134.61.24.0/22", + "134.130.9.64/29", "137.226.38.108/30", "2a00:8a60:1030:a00::/64", "200.17.30.0/24", "2001:12d0:8120::/64", "200.136.60.0/24", "145.100.32.0/22", "2001:610:108:203a::/64", + "2001:610:108:3014::/64", "2001:610:108:3017::/64", "145.100.32.0/22", "2001:610:108:203a::/64", "206.12.24.0/25", "129.107.255.0/24", "2602:fd0f:0:1001::/64", "202.28.43.0/24", + "203.158.4.0/24", "193.40.127.224/27", "193.40.150.192/26", "2001:bb8:4004:ff::/64", "161.200.0.0/16", "192.207.64.0/24", "117.103.96.0/20", "140.109.98.0/24", "140.109.102.0/24", + "202.169.168.0/22", "202.140.160.0/19", "2400:4500::/64", "2400:4500:0:1::/64", "2400:4500:0:2::/64", "203.185.129.0/24", "203.185.131.0/24", "203.185.132.0/24", "203.185.133.0/24", + "203.185.134.0/24", "202.44.204.0/24", "203.185.64.0/19", "203.185.96.0/19", "202.29.12.0/24", "2001:3c8:1012::/48", "202.28.2.0/24", "202.28.194.0/24", "157.82.112.0/21", + "2001:2f8:102d:589::/64", "2404:d540:1:589::/64", "133.11.127.244/30", "133.11.255.181/32", "150.99.198.220/30", "161.9.255.0/24", "2001:a98:1e::/48", "206.12.1.0/24", "206.12.9.0/29", + "206.12.9.128/25", "2607:f8f0:660:2::/64", "2607:f8f0:660:3::/64", "140.115.32.0/24", "140.115.38.0/24", "140.110.122.96/28", "212.111.195.192/26", "2a01:5c40::ffff:d46f:c3c0/122", + "150.244.246.0/23", "2001:720:420:c003::/64", "67.58.50.0/28", "169.228.130.0/23", "2607:f720:1700:1b30::/60", "2607:f720:1700:1b30::/64", "2607:f720:1700:1b32::/64", + "128.227.10.0/24", "128.227.52.0/24", "128.227.53.0/24", "128.227.59.128/26", "128.227.78.0/24", "128.227.83.0/24", "128.227.90.0/24", "128.227.91.0/24", "128.227.92.0/24", + "128.227.132.0/24", "128.227.213.0/24", "128.227.221.0/24", "128.227.235.192/26", "128.227.246.0/24", "128.227.253.0/24", "2620:104:1f::/48", "2607:f5d8:5:1::/64", + "2607:f5d8:5:101::/64", "2607:f5d8:5:2::/64", "2607:f5d8:5:3::/64", "2607:f5d8:5:4::/64", "2607:f5d8:5:401::/64", "2607:f5d8:5:5::/64", "2607:f5d8:5:6::/64", "2607:f5d8:5:7::/64", + "2607:f5d8:5:ff::/64", "146.179.232.0/22", "2a0c:5bc0:c8:2::/64", "130.246.44.0/22", "2001:630:58:1c20::/64", "129.114.0.188/30", "129.114.62.0/27", "198.124.80.0/23", + "2001:400:f000::/40", "64.57.30.128/25", "137.164.26.136/31", "138.44.224.6/31", "144.206.255.148/31", "149.165.254.6/31", "192.17.10.72/30", "134.79.0.0/16", "198.51.111.0/24", + "128.111.120.96/28", "131.225.13.128/25", "131.225.67.0/24", "131.225.69.0/24", "131.225.2.0/24", "131.225.160.0/24", "131.225.184.0/22", "131.225.188.0/22", "131.225.204.0/22", + "2620:6a:0:2::/64", "2620:6a:0:187::/64", "2620:6a:0:8420::/64", "2620:6a:0:8421::/64", "2620:6a:0:8423::/64", "129.107.255.0/24", "2602:fd0f:0:1001::/64", "129.59.59.0/25", + "129.59.177.96/27", "129.59.197.0/24", "192.111.108.0/24", "192.111.110.80/28", "2607:8a00:17:736::/64", "2607:8a00:17:1496::/64", "132.195.124.0/23", "213.135.50.80/30", + "213.135.54.0/26", "2001:6a0:2001:112::/64" ] } From cae4f7a7acc598bd4db2571525f9fb8b0bbb5717 Mon Sep 17 00:00:00 2001 From: lauren Date: Sat, 5 Nov 2022 12:39:42 -0400 Subject: [PATCH 3/6] add selected capacity --- docker-compose.yml | 1 + src/alto/agent/geantlg.py | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 61dbec0..bf6f0b2 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,3 +1,4 @@ +version: "2.2" services: gateway: image: nginx diff --git a/src/alto/agent/geantlg.py b/src/alto/agent/geantlg.py index a032ed5..9791971 100644 --- a/src/alto/agent/geantlg.py +++ b/src/alto/agent/geantlg.py @@ -87,7 +87,7 @@ def _do_query(self, router=None, args=None): logging.warn(f"Error fetching prefix {prefix} on router {router}; skipping") return results - def get_routes(self, ipprefix=None, router=None): + def get_routes(self, ipprefix=None, router=None, selected=False): """ Get a route entries. @@ -109,12 +109,15 @@ def get_routes(self, ipprefix=None, router=None): results_dict = self._do_query(router=router, args=args) logging.info('Parsing routes on %s' % (router)) routes = self._parse_routes(results_dict) + if selected: + for p in routes: + routes[p] = [r for r in routes[p] if r.get('selected')] return routes def update(self): fib_trans = self.db[0].new_transaction() for _router in self.listened_routers: - routes = self.get_routes(router=_router) + routes = self.get_routes(router=_router, selected=True) for dst_prefix, route in routes.items(): if route: route = route[0] From 53e6aec9f894c258bdf59399fb1a19d7266f98c3 Mon Sep 17 00:00:00 2001 From: lauren Date: Sat, 5 Nov 2022 12:48:31 -0400 Subject: [PATCH 4/6] add timeout to lg requests to handle unresponsive routers --- src/alto/agent/geantlg.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/alto/agent/geantlg.py b/src/alto/agent/geantlg.py index 9791971..7cc69ca 100644 --- a/src/alto/agent/geantlg.py +++ b/src/alto/agent/geantlg.py @@ -77,7 +77,7 @@ def _do_query(self, router=None, args=None): headers={ 'Content-Type': 'application/json' }, - proxies=self.proxies) + proxies=self.proxies, timeout=5) doctree = data.json()['output'][router]['commandResult'] query_result = json.loads(json.dumps(xmltodict.parse(doctree))) for table in query_result["rpc-reply"]["route-information"]["route-table"]: From fd31ab55d6ba5bdac14e6caba8945101e0a0966e Mon Sep 17 00:00:00 2001 From: lauren Date: Sat, 5 Nov 2022 20:01:27 -0400 Subject: [PATCH 5/6] reduce prefixes --- etc/lg-agent-geant.json | 195 +++++++++++++++++++++++++++------------- 1 file changed, 133 insertions(+), 62 deletions(-) diff --git a/etc/lg-agent-geant.json b/etc/lg-agent-geant.json index 3686e0d..f665908 100644 --- a/etc/lg-agent-geant.json +++ b/etc/lg-agent-geant.json @@ -49,67 +49,138 @@ ], "refresh_interval": 300, "prefixes": [ - "2001:48a8:68f7:4000::/50", "2001:48a8:68f7:c000::/50", "192.41.236.0/23", "192.41.238.0/28", "2001:48a8:68f7:8001::/64", "192.41.230.0/23", "192.41.238.0/28", - "2001:48a8:68f7:1::/64", "140.221.68.0/24", "140.221.69.0/24", "140.221.96.0/23", "2620:0:dc0:4800::/59", "153.5.72.0/23", "2001:1470:8000:406::/64", "194.249.156.0/24", - "2001:1470:ff8a::/48", "153.5.68.0/22", "2001:1470:ff94::/48", "128.250.185.224/27", "192.231.127.0/24", "192.43.208.0/24", "202.122.32.248/29", "202.122.32.45/32", - "202.122.32.160/27", "202.122.33.0/24", "202.122.35.0/24", "202.122.36.0/24", "202.122.37.128/28", "202.38.128.0/24", "202.38.129.0/24", "2401:de00::/64", - "2401:de00:1:32::/64", "2401:de00:1:32:7ae7:d1ff:feca:d1bb/128", "2401:de00:2:33::/64", "2401:de00:2:332::/64", "130.199.48.0/23", "130.199.54.0/24", "130.199.185.0/24", - "192.12.15.0/24", "192.33.128.0/24", "2620:0:210::/48", "200.133.193.160/27", "200.143.233.0/27", "192.5.207.0/24", "2610:58:3:aaaa::/64", "142.244.83.0/27", - "142.244.105.64/27", "205.189.32.79/32", "132.206.245.224/27", "206.12.127.0/24", "142.150.188.0/24", "206.12.154.0/24", "206.12.155.0/24", "2607:f8f0:c10:70f3::/64", - "2607:f8f0:c11:7000::/64", "206.12.48.224/27", "199.241.165.64/26", "152.84.101.0/24", "2804:1f10:8000:801::/64", "192.65.183.0/24", "2001:1458:a00::/48", "137.138.0.0/16", - "188.184.0.0/17", "188.185.0.0/17", "2001:1458:d00::/48", "192.16.166.0/24", "2001:1458:302::/48", "128.142.0.0/16", "188.184.128.0/17", "2001:1458:301::/48", - "2001:1458:303::/48", "192.101.161.128/26", "192.101.166.234/32", "2001:720:42c:aaee::/64", "192.84.86.0/24", "198.32.43.0/24", "198.32.44.0/24", "198.32.45.0/24", - "2605:d9c0::/32", "2607:f380:a4f::/48", "2001:1310:3121::/48", "202.179.241.216/30", "210.25.189.248/30", "2001:254:1:204::/64", "2001:252:0:112::/64", "149.156.5.192/27", - "195.113.186.64/26", "195.113.219.0/26", "195.113.179.104/30", "195.113.232.216/31", "195.113.232.218/31", "2001:718:401:6016::1:10/127", "188.1.153.0/24", - "131.169.160.0/21", "131.169.191.0/24", "131.169.192.0/24", "131.169.80.0/24", "131.169.98.0/24", "2001:638:700:1050::/64", "2001:638:700:1062::/64", "2001:638:700:10a0::/64", - "2001:638:700:10bf::/64", "2001:638:700:10c0::/64", "141.34.192.0/21", "141.34.200.0/24", "2001:638:700:f0c0::/64", "2001:638:700:f0c2::/64", "2001:638:700:f0c8::/64", - "146.83.90.0/24", "2001:1310:3121:1112::/64", "134.158.72.0/23", "134.158.78.0/24", "2001:660:3024::/48", "134.158.132.0/23", "2001:660:302c::/48", "134.158.158.0/23", - "2001:660:3036::/48", "157.180.228.0/22", "157.180.232.0/22", "192.108.45.0/24", "192.108.46.0/23", "192.108.68.0/24", "2a00:139c::/45", "62.40.103.0/24", "62.40.126.0/24", - "2001:798:111:1::/64", "128.104.227.0/24", "144.92.180.0/23", "2607:f388:101c:1000::/64", "195.251.201.128/26", "2001:648:2e01:110::/64", "192.54.205.0/24", "192.54.206.0/24", - "192.54.207.0/24", "2001:660:3031:110::/64", "140.181.2.0/24", "72.36.81.64/26", "72.36.96.0/24", "2620:0:e01:4800::/56", "144.16.112.0/24", "14.139.119.64/26", - "2405:8a00:c012::/48", "134.158.48.0/21", "134.158.104.0/21", "134.158.168.0/21", "134.158.208.0/21", "134.158.234.0/23", "134.158.238.0/24", "134.158.239.0/24", - "193.48.99.0/24", "2001:660:5009::/48", "193.48.99.0/24", "2001:660:5009:9::/64", "134.158.20.0/23", "2001:660:5408::/48", "134.158.83.0/24", "2001:660:5009:a013::/64", - "134.158.150.0/24", "134.158.151.0/24", "2001:660:4705::/48", "134.158.84.0/24", "134.158.102.0/23", "134.158.96.0/21", "2001:660:5310:400::/56", "2001:660:5310::/48", - "134.158.120.0/21", "2001:660:5104::/48", "193.48.83.0/24", "2001:660:530f::/48", "193.48.101.0/24", "2001:660:7224::/48", "144.16.111.0/24", "2406:f00:9::/48", - "149.165.243.0/24", "90.147.66.0/24", "90.147.75.0/24", "90.147.168.0/23", "2001:760:4227::/48", "90.147.16.0/23", "193.206.219.0/24", "2001:760:420d:80::/64", "192.84.128.0/24", - "2001:760:4228::/64", "192.135.35.224/27", "193.206.93.0/24", "2001:760:4229::/48", "192.135.14.0/24", "2001:760:4224::/48", "90.147.67.0/24", "2001:760:422a:137::/64", - "192.135.9.0/24", "193.205.76.0/23", "2001:760:422b::/48", "141.108.35.0/24", "141.108.36.0/22", "2001:760:422c:35::/64", "2001:760:422c:36::/64", "2001:760:422c:38::/64", - "131.154.128.0/17", "2001:760:4205::/48", "193.205.66.128/25", "193.206.184.0/26", "144.206.150.0/23", "2001:67c:1bec:f069::/64", "159.93.37.0/24", "159.93.39.0/24", - "159.93.220.0/22", "159.93.224.0/22", "2a05:81c5:302:37::/64", "2a05:81c5:302:224::/64", "159.93.228.0/22", "159.93.39.0/24", "2a05:81c5:301:228::/64", "202.180.40.0/27", - "202.13.197.192/26", "202.13.203.128/26", "202.13.207.128/25", "202.13.223.132/30", "2001:2f8:3e:cc21::/120", "133.11.254.16/30", "150.99.93.20/30", "202.13.223.52/30", - "202.13.223.192/29", "2001:2f8:3e:cc22::/64", "2001:2f8:102d:590::/64", "2001:2f8:ffd0:ffff::/64", "193.239.180.128/27", "193.239.180.208/29", "2a00:fc00:e009::/56", - "134.75.123.0/24", "134.75.124.0/24", "134.75.126.0/24", "134.75.127.0/24", "134.75.125.0/24", "2001:320:15:125::/64", "155.230.20.0/22", "2407:c000:c024::/48", "134.75.1.128/25", - "134.75.203.16/30", "134.75.203.240/30", "18.12.0.0/20", "2603:4000:c00::/48", "149.165.224.0/23", "2001:18e8:c02:5::/64", "149.165.236.64/29", "192.170.224.0/19", - "192.170.240.0/23", "2605:9a00:10::/48", "2605:9a00:10:200a::/64", "72.36.96.0/24", "2620:0:e01:4800::/64", "109.105.124.0/22", "2001:948:40::/42", "129.93.153.0/24", - "129.93.182.0/23", "129.93.239.128/26", "129.93.244.192/26", "2600:900:6:1101::/64", "2600:900:6:1102::/64", "2600:900:6:1103::/64", "2600:900:6:1301::/64", "2600:900:6:1302::/64", - "2600:900:6:3103::/64", "81.180.86.0/24", "2001:b30:4202:100::/64", "2a07:8504:120:e060::/64", "2a07:8504:120:e068::/64", "194.171.96.128/25", "194.171.98.112/29", - "194.171.96.128/25", "194.171.98.112/29", "2a07:8504:120:e060::/64", "2a07:8504:120:e068::/64", "206.12.127.0/24", "192.12.68.0/24", "192.188.182.0/24", "2620:0:2b3d:100::/56", - "2620:0:2b3d::/56", "129.15.40.0/23", "129.15.42.0/23", "156.110.41.0/24", "2610:1d8:a01:1::/64", "193.109.172.0/24", "2001:67c:1148:200::/64", "2001:67c:1148:201::/64", - "2001:67c:1148:202::/64", "2001:67c:1148:203::/64", "2001:67c:1148:204::/64", "2001:67c:1148:301::/64", "144.206.255.184/31", "149.156.5.16/30", "149.156.5.20/30", - "150.254.182.0/31", "213.135.50.84/30", "2001:67c:1bec::255:184/127", "2001:6a0:fff:ff0a::/64", "2001:6d8:0:20f::/64", "2001:6d8:0:21f::/64", "2001:808:2:22::/64", "147.231.11.0/25", - "147.231.25.0/24", "147.231.98.224/27", "195.113.219.0/25", "2001:718:19::/48", "2001:718:401:6017::/64", "2001:718:401:6025::/64", "2001:718:401:6e03::/64", - "2001:718:409:7000::/52", "150.254.198.0/25", "2001:808:1:b::/64", "128.211.128.0/19", "128.211.160.0/22", "2001:18e8:804::/48", "130.246.180.0/22", "130.246.216.0/21", - "2001:630:58:1800::/64", "130.246.176.0/22", "130.246.152.240/28", "2001:630:58:1820::/64", "81.180.86.0/24", "2001:b30:4202:100::/64", "81.180.86.0/24", "85.120.46.0/24", - "2001:b30:4210:1::/64", "193.231.25.224/27", "2001:b30:4202:100::/64", "85.122.16.0/20", "194.176.164.0/22", "144.206.237.0/24", "2001:67c:1bec:237::/64", "144.206.255.128/26", - "2001:67c:1bec::255:0/112", "144.206.224.0/24", "144.206.236.0/24", "2001:67c:1bec:224::/64", "2001:67c:1bec:236::/64", "144.206.221.0/24", "85.143.115.32/27", "2001:b08:22:90::/64", - "144.206.130.0/23", "2001:67c:1bdc:100::/64", "2001:67c:1bdc:101::/64", "2001:67c:1bdc:102::/64", "2001:67c:1bdc:200::/64", "2001:67c:1bdc:201::/64", "194.190.165.0/24", - "2001:678:7d8:2000::/52", "185.141.124.192/27", "2a07:a6c0:b:192::/64", "195.70.215.128/26", "2a02:208:0:1::/64", "185.207.88.0/24", "2a0e:e140::/64", "134.61.24.0/22", - "134.130.9.64/29", "137.226.38.108/30", "2a00:8a60:1030:a00::/64", "200.17.30.0/24", "2001:12d0:8120::/64", "200.136.60.0/24", "145.100.32.0/22", "2001:610:108:203a::/64", - "2001:610:108:3014::/64", "2001:610:108:3017::/64", "145.100.32.0/22", "2001:610:108:203a::/64", "206.12.24.0/25", "129.107.255.0/24", "2602:fd0f:0:1001::/64", "202.28.43.0/24", - "203.158.4.0/24", "193.40.127.224/27", "193.40.150.192/26", "2001:bb8:4004:ff::/64", "161.200.0.0/16", "192.207.64.0/24", "117.103.96.0/20", "140.109.98.0/24", "140.109.102.0/24", - "202.169.168.0/22", "202.140.160.0/19", "2400:4500::/64", "2400:4500:0:1::/64", "2400:4500:0:2::/64", "203.185.129.0/24", "203.185.131.0/24", "203.185.132.0/24", "203.185.133.0/24", - "203.185.134.0/24", "202.44.204.0/24", "203.185.64.0/19", "203.185.96.0/19", "202.29.12.0/24", "2001:3c8:1012::/48", "202.28.2.0/24", "202.28.194.0/24", "157.82.112.0/21", - "2001:2f8:102d:589::/64", "2404:d540:1:589::/64", "133.11.127.244/30", "133.11.255.181/32", "150.99.198.220/30", "161.9.255.0/24", "2001:a98:1e::/48", "206.12.1.0/24", "206.12.9.0/29", - "206.12.9.128/25", "2607:f8f0:660:2::/64", "2607:f8f0:660:3::/64", "140.115.32.0/24", "140.115.38.0/24", "140.110.122.96/28", "212.111.195.192/26", "2a01:5c40::ffff:d46f:c3c0/122", - "150.244.246.0/23", "2001:720:420:c003::/64", "67.58.50.0/28", "169.228.130.0/23", "2607:f720:1700:1b30::/60", "2607:f720:1700:1b30::/64", "2607:f720:1700:1b32::/64", - "128.227.10.0/24", "128.227.52.0/24", "128.227.53.0/24", "128.227.59.128/26", "128.227.78.0/24", "128.227.83.0/24", "128.227.90.0/24", "128.227.91.0/24", "128.227.92.0/24", - "128.227.132.0/24", "128.227.213.0/24", "128.227.221.0/24", "128.227.235.192/26", "128.227.246.0/24", "128.227.253.0/24", "2620:104:1f::/48", "2607:f5d8:5:1::/64", - "2607:f5d8:5:101::/64", "2607:f5d8:5:2::/64", "2607:f5d8:5:3::/64", "2607:f5d8:5:4::/64", "2607:f5d8:5:401::/64", "2607:f5d8:5:5::/64", "2607:f5d8:5:6::/64", "2607:f5d8:5:7::/64", - "2607:f5d8:5:ff::/64", "146.179.232.0/22", "2a0c:5bc0:c8:2::/64", "130.246.44.0/22", "2001:630:58:1c20::/64", "129.114.0.188/30", "129.114.62.0/27", "198.124.80.0/23", - "2001:400:f000::/40", "64.57.30.128/25", "137.164.26.136/31", "138.44.224.6/31", "144.206.255.148/31", "149.165.254.6/31", "192.17.10.72/30", "134.79.0.0/16", "198.51.111.0/24", - "128.111.120.96/28", "131.225.13.128/25", "131.225.67.0/24", "131.225.69.0/24", "131.225.2.0/24", "131.225.160.0/24", "131.225.184.0/22", "131.225.188.0/22", "131.225.204.0/22", - "2620:6a:0:2::/64", "2620:6a:0:187::/64", "2620:6a:0:8420::/64", "2620:6a:0:8421::/64", "2620:6a:0:8423::/64", "129.107.255.0/24", "2602:fd0f:0:1001::/64", "129.59.59.0/25", - "129.59.177.96/27", "129.59.197.0/24", "192.111.108.0/24", "192.111.110.80/28", "2607:8a00:17:736::/64", "2607:8a00:17:1496::/64", "132.195.124.0/23", "213.135.50.80/30", - "213.135.54.0/26", "2001:6a0:2001:112::/64" + "14.139.119.64/26", + "18.12.0.0/20", + "62.40.0.0/16", + "64.57.30.128/25", + "67.58.50.0/28", + "72.36.0.0/16", + "81.180.86.0/24", + "85.120.46.0/24", + "85.122.16.0/20", + "85.143.115.32/27", + "90.147.0.0/16", + "109.105.124.0/22", + "117.103.96.0/20", + "128.104.227.0/24", + "128.111.120.96/28", + "128.142.0.0/16", + "128.211.0.0/16", + "128.227.0.0/16", + "128.250.185.224/27", + "129.15.40.0/22", + "129.59.0.0/16", + "129.93.0.0/16", + "129.107.255.0/24", + "129.114.0.0/16", + "130.199.0.0/16", + "130.246.0.0/16", + "131.154.128.0/17", + "131.169.0.0/16", + "131.225.0.0/16", + "132.195.124.0/23", + "132.206.245.224/27", + "133.11.0.0/16", + "134.61.24.0/22", + "134.75.0.0/16", + "134.79.0.0/16", + "134.130.9.64/29", + "134.158.0.0/16", + "137.138.0.0/16", + "137.164.26.136/31", + "137.226.38.108/30", + "138.44.224.6/31", + "140.109.0.0/16", + "140.110.122.96/28", + "140.115.0.0/16", + "140.181.2.0/24", + "140.221.0.0/16", + "141.34.0.0/16", + "141.108.0.0/16", + "142.150.188.0/24", + "142.244.0.0/16", + "144.16.0.0/16", + "144.92.180.0/23", + "144.206.0.0/16", + "145.100.32.0/22", + "146.83.90.0/24", + "146.179.232.0/22", + "147.231.0.0/16", + "149.156.0.0/16", + "150.99.0.0/16", + "150.244.246.0/23", + "150.254.0.0/16", + "152.84.101.0/24", + "153.5.0.0/16", + "155.230.20.0/22", + "156.110.41.0/24", + "157.82.112.0/21", + "157.180.0.0/16", + "159.93.0.0/16", + "161.9.255.0/24", + "161.200.0.0/16", + "169.228.130.0/23", + "185.141.124.192/27", + "185.207.88.0/24", + "188.1.153.0/24", + "188.184.0.0/16", + "188.185.0.0/17", + "192.5.207.0/24", + "192.12.0.0/16", + "192.16.166.0/24", + "192.17.10.72/30", + "192.33.128.0/24", + "192.41.0.0/16", + "192.43.208.0/24", + "192.54.0.0/16", + "192.65.183.0/24", + "192.84.0.0/16", + "192.101.0.0/16", + "192.108.0.0/16", + "192.111.0.0/16", + "192.135.0.0/16", + "192.170.224.0/19", + "192.188.182.0/24", + "192.207.64.0/24", + "192.231.127.0/24", + "193.40.0.0/16", + "193.48.0.0/16", + "193.109.172.0/24", + "193.205.0.0/16", + "193.206.0.0/16", + "193.231.25.224/27", + "193.239.0.0/16", + "194.171.0.0/16", + "194.176.164.0/22", + "194.190.165.0/24", + "194.249.156.0/24", + "195.70.215.128/26", + "195.113.0.0/16", + "195.251.201.128/26", + "198.32.0.0/16", + "198.51.111.0/24", + "198.124.80.0/23", + "199.241.165.64/26", + "200.17.30.0/24", + "200.133.193.160/27", + "200.136.60.0/24", + "200.143.233.0/27", + "202.13.0.0/16", + "202.28.0.0/16", + "202.29.12.0/24", + "202.38.128.0/23", + "202.44.204.0/24", + "202.122.0.0/16", + "202.140.160.0/19", + "202.169.168.0/22", + "202.179.241.216/30", + "202.180.40.0/27", + "203.158.4.0/24", + "203.185.0.0/16", + "205.189.32.79/32", + "206.12.0.0/16", + "210.25.189.248/30", + "212.111.195.192/26", + "213.135.0.0/16" ] } From 8168d6aa431a506b75b1d76319495447bb69b0e4 Mon Sep 17 00:00:00 2001 From: lauren Date: Sat, 5 Nov 2022 22:01:06 -0400 Subject: [PATCH 6/6] batch query --- src/alto/agent/geantlg.py | 68 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 65 insertions(+), 3 deletions(-) diff --git a/src/alto/agent/geantlg.py b/src/alto/agent/geantlg.py index 7cc69ca..be3db58 100644 --- a/src/alto/agent/geantlg.py +++ b/src/alto/agent/geantlg.py @@ -89,7 +89,7 @@ def _do_query(self, router=None, args=None): def get_routes(self, ipprefix=None, router=None, selected=False): """ - Get a route entries. + Get route entries for a single router. Parameters ---------- @@ -98,6 +98,8 @@ def get_routes(self, ipprefix=None, router=None, selected=False): router : str Name of the looking glass router. If None, `default_router` will be used. + selected : bool + Whether only return selected routes or not. Returns ------- @@ -114,11 +116,71 @@ def get_routes(self, ipprefix=None, router=None, selected=False): routes[p] = [r for r in routes[p] if r.get('selected')] return routes + def _do_batch_query(self, router_list=None, args=None): + results = [] + for prefix in args: + try: + data = requests.post(self.uri, + json={ + 'selectedRouters': [{"name": r} for r in router_list], + 'selectedCommand': { + 'value': f'show route {prefix} | display xml' + }, + }, + headers={ + 'Content-Type': 'application/json' + }, + proxies=self.proxies) + for router in router_list: + results_dict = dict() + doctree = data.json()['output'][router]['commandResult'] + query_result = json.loads(json.dumps(xmltodict.parse(doctree))) + for table in query_result["rpc-reply"]["route-information"]["route-table"]: + if table["table-name"] == "lhcone-l3vpn.inet.0": + results_dict.update({prefix : table}) + results.append(results_dict) + except: + logging.warn(f"Error fetching prefix {prefix} for batch; skipping") + return results + + def get_batch_routes(self, ipprefix=None, router_list=None, selected=False): + """ + Get a route entries. + + Parameters + ---------- + ipprefix : str + Destination IP prefix to lookup. If None, `prefixes` will be used. + router : str + Name of the looking glass router. If None, `listened_routers` will be + used. + selected : bool + Whether only return selected routes or not. + + Returns + ------- + routes : list + All the route entries for the given destination IP prefix. + """ + logging.info('Loading routes for batch') + args = ipprefix if ipprefix else self.prefixes + router_list = router_list if router_list else self.listened_routers + list_of_results_dict = self._do_batch_query(router_list=router_list, args=args) + logging.info('Parsing routes for batch') + routes_dict = [] + for i, r in enumerate(router_list): + routes = self._parse_routes(list_of_results_dict[i]) + if selected: + for p in routes: + routes[p] = [r for r in routes[p] if r.get('selected')] + routes_dict[r] = routes + return routes_dict + def update(self): fib_trans = self.db[0].new_transaction() + routes_dict = self.get_batch_routes(selected=True) for _router in self.listened_routers: - routes = self.get_routes(router=_router, selected=True) - for dst_prefix, route in routes.items(): + for dst_prefix, route in routes_dict[_router].items(): if route: route = route[0] else: