patch-atlas.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #!/usr/bin/env python3
  2. import sys
  3. import networkx as nx
  4. import copy
  5. if len(sys.argv) != 3:
  6. print("Usage: {} atlas.gml output.gml".format(sys.argv[0]))
  7. exit(1)
  8. # read first arg as a graph
  9. g = nx.read_gml(sys.argv[1])
  10. # add our 10gig node at a valid IP we know won't be in an atlas probe
  11. new_node = "node at 1.1.1.1"
  12. g.add_node(new_node,
  13. label=new_node,
  14. ip_address="1.1.1.1",
  15. city_code="4744870",
  16. country_code="US",
  17. bandwidth_down="10000000 Kibit",
  18. bandwidth_up="10000000 Kibit"
  19. )
  20. # then duplicate all edges with source or dest of the node we're imitating,
  21. imitated_node = "node at 76.104.11.141"
  22. edges_to_copy = g.edges(imitated_node, data=True)
  23. # but remaped to our new node
  24. def remap_edge(e):
  25. if e[0] == imitated_node:
  26. e[0] = new_node
  27. if e[1] == imitated_node:
  28. e[1] = new_node
  29. return e
  30. # (list(e) also gives us a shallow copy of e, good enough for us)
  31. copied_edges = map(remap_edge, [list(e) for e in edges_to_copy])
  32. g.add_edges_from(copied_edges)
  33. # create an edge between the new and old node
  34. edge = copy.deepcopy(g.get_edge_data(imitated_node, imitated_node))
  35. edge['label'] = "path from 1.1.1.1 to 76.104.11.141"
  36. g.add_edge(new_node, imitated_node)
  37. g[new_node][imitated_node].update(edge)
  38. # finally, save to the second arg
  39. nx.write_gml(g, sys.argv[2])