Commit 95387b9a authored by Simon Redman's avatar Simon Redman

Add helper to build ospf6d conf file

parent 40f1b43c
...@@ -15,11 +15,76 @@ ...@@ -15,11 +15,76 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
# For future reference, here is the OSPFv6 RFC: https://tools.ietf.org/html/rfc2740.html
import ssh_helper import ssh_helper
import argparse import argparse
from netdiff import NetJsonParser import datetime
import getpass import getpass
import ipaddress
from netdiff import NetJsonParser
OSPF_CONF_TEMPLATE = """#
# ospf6d.conf generated by frr_configurator on {date}
#
hostname {hostname}
password zebra
log file /var/log/frr/ospf6d.log
service advanced-vty
{interfaces}
router ospf6
\trouter-id {router_id}
{router_info}
"""
# interface should be replaced with the Linux interface to speak OSPF on
# One of these per interface should be put in the interfaces section.
INTERFACE_LINE_TEMPLATE = "interface {interface}"
# AREA is an OSPF concept, but it looks like FRR only implements AREA as 0
# range should be replaced with the prefix of the interface, for instance 'fd00:10:10:2:54:28ff:fe8b:1395/64'
# interface should be replaced with the interface OSPF is being used on
# One of these per interface should be put in the router_info section
ROUTER_LINE_TEMPLATE = "\tarea 0.0.0.0 range {range}\n\tinterface {interface} area 0.0.0.0"
def build_ospf_conf_for_host(host, hostname, interfaces):
"""
Construct the OSPFv6 config file for the host specified
:param host: unique IPv4 address of the host to build a config file for
:param hostname: human-readable name associated with this host
:param interfaces: mapping of interface names to IPv6 addresses on that interface
:return: ospf6d config file
"""
interfaces_strs = []
router_info_strs = []
assert type(host) is ipaddress.IPv4Address, "Host should be an ip address to build a config for"
# More specifically, I need an IPv4Address because I am using it for the OSPF router-id which needs to be an IPv4Address-shaped thing
for interface in interfaces.keys():
interfaces_strs.append(INTERFACE_LINE_TEMPLATE.format(
interface=interface
))
router_info_strs.append(ROUTER_LINE_TEMPLATE.format(
range=interfaces[interface],
interface=interface,
))
config = OSPF_CONF_TEMPLATE.format(
date=datetime.datetime.today(),
hostname=hostname,
router_id=host,
interfaces=str.join('\n', interfaces_strs),
router_info=str.join('\n', router_info_strs),
)
return config
if __name__ == "__main__": if __name__ == "__main__":
......
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