Commit 86438ca5 authored by Simon Redman's avatar Simon Redman

Add default routes to end-hosts

parent e1a734d6
......@@ -24,6 +24,7 @@ import ipaddress
import json
from netdiff import NetJsonParser
import re
from typing import List
LINK_LOCAL_COMMAND = "ip address list"
IPV4_COMMAND = "ip -4 address list"
......@@ -33,6 +34,7 @@ ULA_ADDER_HEADER_TEMPLATE = "#!/usr/bin/env bash\n# Script generated by add_rout
ADD_ADDR_COMMAND_TEMPLATE = "sudo ip -6 addr add {addr} dev {dev}"
DEFAULT_ROUTE_TEMPLATE = "sudo ip -6 route add default dev {interface}"
def parse_ipv4_networks(netgraph):
......@@ -221,6 +223,38 @@ def add_ULAs_to_hosts(netgraph, ULA_map):
def add_default_routes(netgraph, ULA_map, hosts: List[str]):
Add default routes to hosts in the passed list
There must be only and exactly one interface per host in the passed ULA map, and this will be used as the default
:param netgraph: networkx graph object with logged-in SSH sessions
:param ULA_map: mapping of hosts to interfaces to ULAs
:param hosts:
sessions = [netgraph._node[host]['session'] for host in hosts]
commands = []
for host in hosts:
interfaces = ULA_map[host]
assert len(interfaces) == 1, "Too many interfaces provided. Cannot select one as default!"
interface = list(interfaces.keys())[0]
ssh_helper.run_commands_on_many_hosts(sessions, commands)
except ssh_helper.SSHCommandErrorError as e:
while e is not None:
output = str.join(' ', e.output.splitlines()) # Get rid of newlines
if "RTNETLINK answers: File exists" in output:
# Everything is okay
e =
def add_interfaces_to_netgraph(netgraph, ULA_map):
......@@ -70,7 +70,7 @@ if __name__ == "__main__":
if re.match(args.ovs_regex, node_name):
# Prepare a list of nodes which are "consumer host nodes" and should thus be ignored for core network-related activities
# Prepare a list of nodes which are "customer host nodes" and should thus be ignored for core network-related activities
host_nodes = []
for node in netgraph.graph.nodes:
node_name = netgraph.graph._node[node]['label']
......@@ -80,10 +80,13 @@ if __name__ == "__main__":
frr_configurator.configure_nodes(netgraph.graph, ignore_nodes=ovs_nodes + host_nodes)
frr_configurator.start_frr_on_network(netgraph.graph, ignore_nodes=ovs_nodes + host_nodes)
# Customer hosts would normally be DHCP clients, etc., but for now just give them a route
add_routable_ipv6_addrs.add_default_routes(netgraph.graph, ULA_map, host_nodes)
if args.netgraph_write:
with open(args.netgraph_write) as outfile:
json.dumps(netgraph.json(dict=True), outfile)
with open(args.netgraph_write, 'w') as outfile:
json.dump(netgraph.json(dict=True), outfile)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment