Skip to content

Commit

Permalink
irr-as-set: multiple output format + tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pierky committed Jan 6, 2021
1 parent ec0179a commit 5ed7f3a
Show file tree
Hide file tree
Showing 18 changed files with 339 additions and 39 deletions.
57 changes: 56 additions & 1 deletion docs/USAGE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -281,12 +281,67 @@ Please note: the output file generated with this command contains only a subset
},
[...]
.. _irr-as-set:

Generation of route server AS-SET RPSL object
---------------------------------------------

The command ``arouteserver irr-as-set`` can be used to build the AS-SET RPSL object that describes the ASes and AS-SETs of route server clients. This object can then be used to update the relevant IRR DBs so that peering networks will also be able to build filters on their side.

The ``main.j2`` file contained in the ``templates/irr-as-set`` directory must be edited by the operator to set some mandatory attributes. It's strongly suggested to make a copy of the original file in a different directory, and then pass the path of the new dir to the command via the CLI option ``--templates-dir``. This will help to keep a consistent version of the local custom file and to avoid the ARouteServer upgrade process to raise warnings about the local file not being in sync with the upstream one.
At this time, ARouteServer is not able to perform any actual update on the IRR databases; it's up to the network operator to implement a mechanism to update the information on the appropriate IRRDB. It is not excluded that an automatic update feature will be implemented in the future.

Different templates can be used to build the object, depending on the output format that it is desired for it. Those templates are:

- ``plain_rpsl.j2``, to produce an output in plain RPSL format (can be used, for example, to update registries that are leveraging the email system to receive updates)

- ``ripe_ripeinator_yml.j2``, to build a YAML file that can be consumed by `ripeinator <https://github.com/xens/ripeinator>`__, to update AS-SET objects using the `RIPE REST-API <https://www.ripe.net/manage-ips-and-asns/db/support/documentation/ripe-database-documentation/updating-objects-in-the-ripe-database/6-1-restful-api>`__

To select the desired template, the CLI argument ``--template-file-name`` must be set. See instructions below for more details.

The template files contained in the ``templates/irr-as-set`` directory must be edited by the operator to set some mandatory attributes.
Instead of editing the original files distributed with the tool, it's strongly suggested to make a copy of them in a different directory, and then pass the path of the new dir to the command via the CLI option ``--templates-dir``. This will help to keep a consistent version of the local custom files and to avoid the ARouteServer upgrade process to raise warnings about the local file not being in sync with the upstream one.

Instructions:

1. create a directory where custom templates will be
stored (example: ``~/arouteserver/custom_templates``)

2) inside the new directory, create a new directory for
the templates used by the ``irr-as-set`` command; the
name of this sub-directory must be ``irr-as-set``, as
the command itself

3) copy the original files into the newly-created
``irr-as-set`` directory

4) edit the new files and customise them as needed
(``vim ~/arouteserver/custom_templates/irr-as-set/<file_to_edit>``)

5) run the ``arouteserver irr-as-set`` command and pass
the path of the main directory created in step 1 as
the ``--template-dir`` argument, and pass the name of
the template file to be used via the
``--template-file-name`` argument.

Example:

.. code:: console
$ mkdir -p ~/arouteserver/custom_templates
$ mkdir ~/arouteserver/custom_templates/irr-as-set
$ # assuming that ARouteServer config files were
$ # installed in /etc/arouteserver
$ cp \
/etc/arouteserver/templates/irr-as-set/plain_rpsl.j2 \
~/arouteserver/custom_templates/irr-as-set/plain_rpsl.j2
$ vim ~/arouteserver/custom_templates/irr-as-set/plain_rpsl.j2
$ arouteserver \
irr-as-set \
--output ~/arouteserver/my_as_set.txt \
--templates-dir ~/arouteserver/custom_templates \
--template-file-name plain_rpsl.j2
Output example:

.. literalinclude:: _static/examples_rich_irr-as-set.txt
:language: none
Expand Down
2 changes: 1 addition & 1 deletion pierky/arouteserver/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -1253,7 +1253,7 @@ def enrich_j2_environment(self, env):
# White lists.
if client_irrdb.get("white_list_asn", None):
for white_list_asn in client_irrdb.get("white_list_asn", []):
members.add("AS{}".format(client_irrdb["white_list_asn"]))
members.add("AS{}".format(white_list_asn))

# The client has its own list of AS-SETs.
# Use it and move to the next client.
Expand Down
31 changes: 31 additions & 0 deletions pierky/arouteserver/commands/tpl_rendering.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,3 +343,34 @@ class IRRASSetCommand(TemplateRenderingCommands):

def _get_template_sub_dir(self):
return "irr-as-set"

def run(self):
if not self.args.template_name:
templates_dir = os.path.join(
program_config.get_dir("templates_dir"),
self.COMMAND_NAME
)

templates = [
f
for f in os.listdir(templates_dir)
if (
os.path.isfile(
os.path.join(templates_dir, f)
) and \
f.endswith(".j2")
)
]

raise ARouteServerError(
"The '--template-file-name' argument is required; the name "
"of the template to be used to build the IRR AS-SET "
"object must be provided. Possible choices: {templates}\n"
"Fore more details please see {url}".format(
templates=", ".join(templates),
url="https://arouteserver.readthedocs.io/en/latest/"
"USAGE.html#irr-as-set"
)
)

super(IRRASSetCommand, self).run()
3 changes: 2 additions & 1 deletion templates/fingerprints.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ html:
macros.j2: 10a25573bd53f86980477e88f8faa47745d63620ac212d0103fe1376809ce81bcb641d9369775f2054000f737e03de21fe4746669f9d4fc1d012ee214ab69fdd
main.j2: efcdfb0191c76563b5b2bbac8a6aa345a71fedc19752cf7042859f3dfb792f437ed40fc563699efdd30f6e9fe52f7a46229965b273f1e58dedf8739c8fa20c0c
irr-as-set:
main.j2: ebf4472feac0f1ff788c49a3b50c67eedf9ddb23af6bbccafb07ac4b92fee861e2d137ebe09c8a5f3a047bb46070439db92c8cb51393214e4460f6bf4b722708
plain_rpsl.j2: 23d6a7dcf344bd84b02a957aa7e8935e0f433dd5732e6ed1eea0807b40abbdc3602dc7471433e9cd5e08e04b815769c9775074fabe9b8fa8c77cac857ec3ebf6
ripe_ripeinator_yml.j2: 6305b87e3a2c8af4eb1504e544b9512ef2eb0b5cd45146ab05dcc4b0e6655840222f789d497985607c2ca3be9d492699eeea399528e0a7a37f4d26bc21c3a6e3
openbgpd:
clients.j2: ccf0ab9e561b30db02470166f5df9c8e6367ec429afaf2ba88e3136e21479fe4946c43db16148f3a5a97749641db63550637363056ff448374de4bbdb2a2c38c
filters.j2: edc6ec402ea658f9a747385a140e5fd7fd8b4a43df125cff6435112316b7cfdfec66aa26dfa2b938f5286595757a4d9c6b002780c3a0e3ba6e3302fa8df20e5b
Expand Down
33 changes: 0 additions & 33 deletions templates/irr-as-set/main.j2

This file was deleted.

21 changes: 21 additions & 0 deletions templates/irr-as-set/plain_rpsl.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{#
This is the template used to build the RPSL AS-SET
object of the route server to update the relevant
IRR DBs.
See instructions at the following URL on how to
edit and use it.
https://arouteserver.readthedocs.io/en/latest/USAGE.html#irr-as-set
#}
as-set: AS-AS{{ cfg.rs_as }}-RS{{ ip_ver_suffix }}
descr: AS-AS{{ cfg.rs_as }} route server {{ ip_ver_descr }} routes
remarks: List of ASes and AS-SETs announced by {{ ip_ver_descr }}
remarks: clients to the AS{{ cfg.rs_as }} route servers.
tech-c: <to be set by the user>
admin-c: <to be set by the user>
mnt-by: <to be set by the user>
{% for member in as_sets_rpsl_objects|sort %}
members: {{ member }}
{% endfor %}
source: <to be set by the user>
23 changes: 23 additions & 0 deletions templates/irr-as-set/ripe_ripeinator_yml.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{#
This is the template used to build a YAML file
that can be consumed by ripeinator
(https://github.com/xens/ripeinator) to update
AS-SET objects using the RIPE REST-API.
See instructions at the following URL on how to
edit and use it.
https://arouteserver.readthedocs.io/en/latest/USAGE.html#irr-as-set
#}
AS-AS{{ cfg.rs_as }}-RS{{ ip_ver_suffix }}:
- as-set: AS-AS{{ cfg.rs_as }}-RS{{ ip_ver_suffix }}
- descr: AS-AS{{ cfg.rs_as }} route server {{ ip_ver_descr }} routes
- remarks: List of ASes and AS-SETs announced by {{ ip_ver_descr }}
- remarks: clients to the AS{{ cfg.rs_as }} route servers.
- tech-c: <to be set by the user>
- admin-c: <to be set by the user>
- mnt-by: <to be set by the user>
{% for member in as_sets_rpsl_objects|sort %}
- members: {{ member }}
{% endfor %}
- source: <to be set by the user>
17 changes: 17 additions & 0 deletions tests/cli
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,23 @@ run_cmd "clients-from-euroix" --url https://ixp.getafix.ph/api/v4/member-export/
SUB_TEST="$LINENO"
run_cmd "clients-from-euroix" --url https://ixpmanager.swissix.ch/api/v4/member-export/ixf/0.7 1 | must_contain "description: Packet Clearing House"

# ---------------------------------------------
# irr-as-set command
reset
TITLE="irr-as-set"
GENERAL="tests/var/general.yml"
cat << EOF > $GENERAL
cfg:
rs_as: 999
router_id: "192.0.2.2"
filtering:
irrdb:
peering_db: True
EOF

SUB_TEST="$LINENO"
build_cmd "irr-as-set" --template-file-name plain_rpsl.j2 | must_contain "members: AS-RIPENCC"

# ---------------------------------------------
ERROR=`cat $RES_FILE`
if [ $ERROR -eq 1 ]; then
Expand Down
4 changes: 4 additions & 0 deletions tests/static/irrdb_data/asset_AS-AS1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"asn_list": []
}

4 changes: 4 additions & 0 deletions tests/static/irrdb_data/asset_AS-AS2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"asn_list": []
}

4 changes: 4 additions & 0 deletions tests/static/irrdb_data/rset_AS-AS1_ipv4.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"prefix_list": []
}

4 changes: 4 additions & 0 deletions tests/static/irrdb_data/rset_AS-AS1_ipv6.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"prefix_list": []
}

4 changes: 4 additions & 0 deletions tests/static/irrdb_data/rset_AS-AS2_ipv4.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"prefix_list": []
}

4 changes: 4 additions & 0 deletions tests/static/irrdb_data/rset_AS-AS2_ipv6.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"prefix_list": []
}

2 changes: 1 addition & 1 deletion tests/static/test_cfg_program.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def test_050_setup_then_rm_templates(self):
self._mk_dir("templates")

errors = self.pr_cfg.verify_templates()
self.assertEqual(len(errors), 18)
self.assertEqual(len(errors), 19)
for err in errors:
self.assertTrue("expected but not found on the local templates directory" in err)

Expand Down
Loading

0 comments on commit 5ed7f3a

Please sign in to comment.