Skip to content

Commit

Permalink
Move FRR bond logic to generic Linux template
Browse files Browse the repository at this point in the history
  • Loading branch information
jbemmel committed Dec 10, 2024
1 parent ea77b3f commit d20c7ef
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 4 deletions.
51 changes: 51 additions & 0 deletions netsim/ansible/templates/lag/linux.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{% macro create_bond_dev(l) %}
{% if l.type=='lag' %}
{% set _m = l.lag.mode|default(lag.mode) %}
{% if _m=="802.3ad" %}
{% set _lacp = l.lag.lacp|default(lag.lacp) %}
{% set lacp_act = 'off' if _lacp=='off' else 'on' %}
{% set lacp_rate = (' lacp_rate ' + _lacp) if _lacp!='off' else '' %}
{% set _m = _m + " xmit_hash_policy encap3+4" + lacp_rate %}
{% if node_provider == 'clab' %}
{% set _m = _m + " lacp_active " + lacp_act %}
{% endif %}
{% endif %}
{% if node_provider != 'clab' %}
#
# Make sure 'bonding' module is loaded
#
if [[ ! -e /sys/module/bonding ]]; then
modprobe bonding miimon=100 mode=802.3ad lacp_rate=fast
fi
{% endif %}
if [[ ! -e /sys/class/net/{{l.ifname}} ]]; then
ip link add dev {{l.ifname}} type bond mode {{_m}}
fi
{% endif %}
{% endmacro -%}
#!/bin/bash
#
set -e # Exit immediately when any command fails
#
# Create bonds for LAGs, if any. Requires kernel bonding module loaded
#
{% for l in interfaces if 'lag' in l %}
{{ create_bond_dev(l) }}
ip link set dev {{ l.ifname }} down
{% endfor -%}

{% for l in interfaces if 'lag' in l and l.type != 'lag' %}
{% if l.type=='p2p' %}
{% if node_provider != 'clab' %}
ethtool -s {{ l.ifname }} autoneg off speed 1000 duplex full
{% endif %}
ip link set dev {{ l.ifname }} master {%
for i in interfaces if i.type=='lag' and i.linkindex==l.lag._parentindex %}{{ i.ifname }}
{% endfor %}
{% endif %}
ip link set dev {{ l.ifname }} up
{% endfor %}
{% for l in interfaces if 'lag' in l and l.type == 'lag' %}
ip link set dev {{ l.ifname }} up
{% endfor %}
exit 0
2 changes: 1 addition & 1 deletion netsim/devices/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def report_quirk(text: str, node: Box, quirk: str, **kwargs: typing.Any) -> None
q_state = topology.get(q_path,True)
if not q_state:
return

# Add the 'this is how you disable this quirk' hint
#
q_hint = f'Set {q_path} to False to disable this check'
Expand Down
2 changes: 1 addition & 1 deletion netsim/devices/cumulus_nvue.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def device_quirks(self, node: Box, topology: Box) -> None:
# NVUE specific quirks
if 'stp' in mods:
nvue_check_stp_features(node,topology)

if 'vrf' in mods:
nvue_check_vrf_route_leaking(node)

Expand Down
4 changes: 2 additions & 2 deletions netsim/devices/dellos10.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def check_anycast_gateways(node: Box) -> None:
for intf in node.get('interfaces',[]):
if intf.type != 'svi' and intf.get('gateway.anycast',None):
err_data.append(f'Interface {intf.ifname}')

if err_data:
report_quirk(
f'Dell OS10 (node {node.name}) does not support anycast on non-SVI interfaces',
Expand All @@ -51,7 +51,7 @@ def device_quirks(self, node: Box, topology: Box) -> None:
check_vlan_ospf(node,node.interfaces,'default')
for vname,vdata in node.get('vrfs',{}).items():
check_vlan_ospf(node,vdata.get('ospf.interfaces',[]),vname)

if 'gateway' in node.get('module',[]) and 'anycast' in node.get('gateway',{}):
check_anycast_gateways(node)

Expand Down

0 comments on commit d20c7ef

Please sign in to comment.