-
Notifications
You must be signed in to change notification settings - Fork 103
Juniper cSRX support #3344
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Juniper cSRX support #3344
Changes from all commits
23f14ad
1dd0538
83e54f3
c9bf061
3a9fec4
97e15f1
e7fbaac
f643b69
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| {% include 'junos/hosts.j2' %} | ||
|
|
||
| {% include 'junos/container_interfaces.j2' %} | ||
|
|
||
| security { | ||
| zones { | ||
| security-zone default { | ||
| interfaces { | ||
| {% for l in netlab_interfaces|default([]) %} | ||
| {{ l.ifname }}.0; | ||
| {% endfor %} | ||
| } | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| interfaces { | ||
| {% for l in netlab_interfaces|default([]) %} | ||
| {{ l.ifname }} { | ||
| {% if l.mtu is defined %} | ||
| mtu {{ l.mtu }}; | ||
| {% endif %} | ||
| {% if l.name is defined %} | ||
| description "{{ l.name }}{{ " ["+l.role+"]" if l.role is defined else "" }}"; | ||
| {% elif l.type|default("") == "stub" %} | ||
| description "Stub interface" | ||
| {% endif %} | ||
| unit 0 { | ||
| {# | ||
| IPv4 addresses | ||
| #} | ||
| {% if 'ipv4' in l %} | ||
| family inet { | ||
| {% if l.ipv4 == True %} | ||
| unnumbered-address lo0.0; | ||
| {% elif l.ipv4|ansible.utils.ipv4 %} | ||
| address {{ l.ipv4 }}; | ||
| {% else %} | ||
| ! Invalid IPv4 address {{ l.ipv4 }} | ||
| {% endif %} | ||
| } | ||
| {% endif %} | ||
| {# | ||
| IPv6 addresses | ||
| #} | ||
| {% if 'ipv6' in l %} | ||
| family inet6 { | ||
| {% if l.ipv6 is string %} | ||
| address {{ l.ipv6 }}; | ||
| {% endif %} | ||
| } | ||
| {% endif %} | ||
| } | ||
| } | ||
| {% endfor %} | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| system { | ||
| host-name {{ inventory_hostname }}; | ||
| static-host-mapping { | ||
| {% for k,v in hostvars.items() if k != inventory_hostname %} | ||
| {% if v.loopback.ipv4 is defined %} | ||
| {{ k|replace('_','') }} inet {{ v.loopback.ipv4|ansible.utils.ipaddr('address') }}; | ||
| {% elif v.interfaces|default([]) and v.interfaces[0].ipv4|default(False) is string %} | ||
| {{ k|replace('_','') }} inet {{ v.interfaces[0].ipv4|ansible.utils.ipaddr('address') }}; | ||
| {% endif %} | ||
| {% endfor %} | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| protocols { | ||
| lldp { | ||
| interface {{ mgmt.ifname|default('fxp0') }} { | ||
| disable; | ||
| } | ||
| interface all; | ||
| } | ||
| {% for l in netlab_interfaces if 'ipv6' in l and l.type != 'loopback' %} | ||
| {% if loop.first %} | ||
| router-advertisement { | ||
| {% endif %} | ||
| interface {{ l.ifname }}; | ||
| {% if loop.last %} | ||
| } | ||
| {% endif %} | ||
| {% endfor %} | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| {% if routing.static is defined %} | ||
| {% include 'junos/static.j2' %} | ||
| {% endif %} | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| # | ||
| # Juniper cSRX quirks | ||
| # | ||
| from box import Box | ||
|
|
||
| from ..utils import log | ||
| from . import _Quirks | ||
|
|
||
|
|
||
| def csrx_port_num(node: Box) -> None: | ||
| if_count = len(node.get('interfaces', [])) | ||
| node.clab.env.CSRX_PORT_NUM = if_count + 1 # +1 for the management interface | ||
| if if_count > 16: | ||
| log.error( | ||
| f'cSRX supports a maximum of 16 interfaces. Node {node.name} has {if_count} interfaces.', | ||
| category=log.IncorrectValue, | ||
| module=node.device) | ||
|
|
||
| class CSRX(_Quirks): | ||
|
|
||
| @classmethod | ||
| def device_quirks(self, node: Box, topology: Box) -> None: | ||
| csrx_port_num(node) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| --- | ||
| description: Juniper cSRX container | ||
| group_vars: | ||
| ansible_user: root | ||
| ansible_ssh_pass: "clab123" | ||
| netlab_device_type: csrx | ||
| netlab_check_retries: 20 | ||
|
|
||
| mgmt_if: fxp0 | ||
| ifindex_offset: 0 | ||
| interface_name: ge-0/0/{ifindex} | ||
| mtu: 1500 | ||
|
|
||
| features: | ||
| initial: | ||
| ipv4: | ||
| unnumbered: false # The 'unnumbered-address' family inet command does not work on cSRX | ||
| ipv6: | ||
| lla: true | ||
| routing: | ||
| static: | ||
| vrf: False | ||
| discard: True | ||
|
|
||
| clab: | ||
| image: csrx:23.4R1.9 | ||
| build: https://containerlab.dev/manual/kinds/csrx/ | ||
| node: | ||
| kind: juniper_csrx | ||
| config_templates: | ||
| hosts: /etc/hosts:shared | ||
| netlab-config: /config/netlab/netlab-config.sh:sh | ||
| interface: | ||
| name: eth{ifindex+1} | ||
| features: | ||
| initial: | ||
| config_mode: [ sh ] | ||
| group_vars: | ||
| netlab_config_mode: sh | ||
| netlab_show_command: [ cli, -c, 'show $@' ] | ||
| netlab_check_command: who | ||
| netlab_ready: [ ssh ] | ||
| netlab_default_shebang: '#!/config/netlab/netlab-config.sh' | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we want to use this or should we just use NETCONF to configure it? Or is NETCONF not working?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I based it on cRPD. I thought the connection/deployment methods other than shell scripts relied on Ansible which I know you're not the biggest fan of.
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
You're right ;) However, we need Ansible anyway to deploy configurations on other Junos devices, but admittedly the script-based configuration is faster. I'm OK with either one, just don't make it too complicated just to have a bash script. |
||
| netlab_config_path: /config/netlab/ | ||
|
|
||
| graphite.icon: firewall | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| {% include 'linux/hosts.j2' %} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| #!/bin/bash | ||
| tail -n +2 $1 > /tmp/config.conf # stop shebang being included in pushed config | ||
| cat <<CONFIG | cli | tee /tmp/cli-status | ||
| configure | ||
| load merge /tmp/config.conf | ||
| CONFIG | ||
| if grep -i error /tmp/cli-status >/dev/null; then | ||
| echo "Configuration load failed, aborting" | ||
| exit 1 | ||
| else | ||
| cat <<CONFIG | cli | tee /tmp/cli-status | ||
| configure | ||
| commit and-quit | ||
| CONFIG | ||
| if grep -i error /tmp/cli-status | grep -vi "Device or resource busy" >/dev/null; then | ||
| echo "Commit failed, aborting" | ||
| exit 1 | ||
| fi | ||
| fi |
Uh oh!
There was an error while loading. Please reload this page.