Skip to content

Commit

Permalink
Merge pull request #4263 from jvoss/srv6_locator_format
Browse files Browse the repository at this point in the history
srv6: T6984: add locator format configuration
  • Loading branch information
dmbaturin authored Jan 2, 2025
2 parents 825743b + 252e60e commit a779cfd
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 15 deletions.
3 changes: 3 additions & 0 deletions data/templates/frr/zebra.segment_routing.frr.j2
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ segment-routing
{% endif %}
{% if locator_config.behavior_usid is vyos_defined %}
behavior usid
{% endif %}
{% if locator_config.format is vyos_defined %}
format {{ locator_config.format }}
{% endif %}
exit
!
Expand Down
19 changes: 19 additions & 0 deletions interface-definitions/protocols_segment-routing.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,25 @@
</properties>
<defaultValue>24</defaultValue>
</leafNode>
<leafNode name="format">
<properties>
<help>SRv6 SID format</help>
<completionHelp>
<list>uncompressed-f4024 usid-f3216</list>
</completionHelp>
<valueHelp>
<format>uncompressed-f4024</format>
<description>Uncompressed f4024 format</description>
</valueHelp>
<valueHelp>
<format>usid-f3216</format>
<description>usid-f3216 format</description>
</valueHelp>
<constraint>
<regex>(uncompressed-f4024|usid-f3216)</regex>
</constraint>
</properties>
</leafNode>
</children>
</tagNode>
</children>
Expand Down
107 changes: 92 additions & 15 deletions smoketest/scripts/cli/test_protocols_segment-routing.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

base_path = ['protocols', 'segment-routing']


class TestProtocolsSegmentRouting(VyOSUnitTestSHIM.TestCase):
@classmethod
def setUpClass(cls):
Expand All @@ -47,14 +48,64 @@ def tearDown(self):
def test_srv6(self):
interfaces = Section.interfaces('ethernet', vlan=False)
locators = {
'foo' : { 'prefix' : '2001:a::/64' },
'foo' : { 'prefix' : '2001:b::/64', 'usid' : {} },
'foo1': {'prefix': '2001:a::/64'},
'foo2': {'prefix': '2001:b::/64', 'usid': {}},
'foo3': {'prefix': '2001:c::/64', 'format': 'uncompressed-f4024'},
'foo4': {
'prefix': '2001:d::/48',
'block-len': '32',
'node-len': '16',
'func-bits': '16',
'usid': {},
'format': 'usid-f3216',
},
}

for locator, locator_config in locators.items():
self.cli_set(base_path + ['srv6', 'locator', locator, 'prefix', locator_config['prefix']])
self.cli_set(
base_path
+ ['srv6', 'locator', locator, 'prefix', locator_config['prefix']]
)
if 'block-len' in locator_config:
self.cli_set(
base_path
+ [
'srv6',
'locator',
locator,
'block-len',
locator_config['block-len'],
]
)
if 'node-len' in locator_config:
self.cli_set(
base_path
+ [
'srv6',
'locator',
locator,
'node-len',
locator_config['node-len'],
]
)
if 'func-bits' in locator_config:
self.cli_set(
base_path
+ [
'srv6',
'locator',
locator,
'func-bits',
locator_config['func-bits'],
]
)
if 'usid' in locator_config:
self.cli_set(base_path + ['srv6', 'locator', locator, 'behavior-usid'])
if 'format' in locator_config:
self.cli_set(
base_path
+ ['srv6', 'locator', locator, 'format', locator_config['format']]
)

# verify() - SRv6 should be enabled on at least one interface!
with self.assertRaises(ConfigSessionError):
Expand All @@ -65,16 +116,33 @@ def test_srv6(self):
self.cli_commit()

for interface in interfaces:
self.assertEqual(sysctl_read(f'net.ipv6.conf.{interface}.seg6_enabled'), '1')
self.assertEqual(sysctl_read(f'net.ipv6.conf.{interface}.seg6_require_hmac'), '0') # default

frrconfig = self.getFRRconfig(f'segment-routing', endsection='^exit')
self.assertIn(f'segment-routing', frrconfig)
self.assertIn(f' srv6', frrconfig)
self.assertIn(f' locators', frrconfig)
self.assertEqual(
sysctl_read(f'net.ipv6.conf.{interface}.seg6_enabled'), '1'
)
self.assertEqual(
sysctl_read(f'net.ipv6.conf.{interface}.seg6_require_hmac'), '0'
) # default

frrconfig = self.getFRRconfig('segment-routing', endsection='^exit')
self.assertIn('segment-routing', frrconfig)
self.assertIn(' srv6', frrconfig)
self.assertIn(' locators', frrconfig)
for locator, locator_config in locators.items():
prefix = locator_config['prefix']
block_len = locator_config.get('block-len', '40')
node_len = locator_config.get('node-len', '24')
func_bits = locator_config.get('func-bits', '16')

self.assertIn(f' locator {locator}', frrconfig)
self.assertIn(f' prefix {locator_config["prefix"]} block-len 40 node-len 24 func-bits 16', frrconfig)
self.assertIn(
f' prefix {prefix} block-len {block_len} node-len {node_len} func-bits {func_bits}',
frrconfig,
)

if 'format' in locator_config:
self.assertIn(f' format {locator_config["format"]}', frrconfig)
if 'usid' in locator_config:
self.assertIn(' behavior usid', frrconfig)

def test_srv6_sysctl(self):
interfaces = Section.interfaces('ethernet', vlan=False)
Expand All @@ -86,8 +154,12 @@ def test_srv6_sysctl(self):
self.cli_commit()

for interface in interfaces:
self.assertEqual(sysctl_read(f'net.ipv6.conf.{interface}.seg6_enabled'), '1')
self.assertEqual(sysctl_read(f'net.ipv6.conf.{interface}.seg6_require_hmac'), '-1') # ignore
self.assertEqual(
sysctl_read(f'net.ipv6.conf.{interface}.seg6_enabled'), '1'
)
self.assertEqual(
sysctl_read(f'net.ipv6.conf.{interface}.seg6_require_hmac'), '-1'
) # ignore

# HMAC drop
for interface in interfaces:
Expand All @@ -96,8 +168,12 @@ def test_srv6_sysctl(self):
self.cli_commit()

for interface in interfaces:
self.assertEqual(sysctl_read(f'net.ipv6.conf.{interface}.seg6_enabled'), '1')
self.assertEqual(sysctl_read(f'net.ipv6.conf.{interface}.seg6_require_hmac'), '1') # drop
self.assertEqual(
sysctl_read(f'net.ipv6.conf.{interface}.seg6_enabled'), '1'
)
self.assertEqual(
sysctl_read(f'net.ipv6.conf.{interface}.seg6_require_hmac'), '1'
) # drop

# Disable SRv6 on first interface
first_if = interfaces[-1]
Expand All @@ -106,5 +182,6 @@ def test_srv6_sysctl(self):

self.assertEqual(sysctl_read(f'net.ipv6.conf.{first_if}.seg6_enabled'), '0')


if __name__ == '__main__':
unittest.main(verbosity=2)

0 comments on commit a779cfd

Please sign in to comment.