Skip to content

Commit cc1063e

Browse files
authored
Merge pull request FRRouting#18774 from raja-rajasekar/rajasekarr/nfl_len_node_len_0
SRv6: Allow configuring node-len 0
2 parents a81f6f3 + 5f00926 commit cc1063e

File tree

3 files changed

+159
-3
lines changed

3 files changed

+159
-3
lines changed
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
{
2+
"locators": [
3+
{
4+
"name": "loc1",
5+
"prefix": "2001:db8:3::/48",
6+
"blockBitsLength": 32,
7+
"nodeBitsLength": 16,
8+
"functionBitsLength": 16,
9+
"argumentBitsLength": 0,
10+
"statusUp": true,
11+
"chunks": [
12+
{
13+
"prefix": "2001:db8:3::/48",
14+
"proto": "system"
15+
}
16+
]
17+
},
18+
{
19+
"name": "loc2",
20+
"prefix": "2001:db8:3::/48",
21+
"blockBitsLength": 48,
22+
"nodeBitsLength": 0,
23+
"functionBitsLength": 16,
24+
"argumentBitsLength": 0,
25+
"statusUp": true,
26+
"chunks": [
27+
{
28+
"prefix": "2001:db8:3::/48",
29+
"proto": "system"
30+
}
31+
]
32+
},
33+
{
34+
"name": "loc3",
35+
"prefix": "2001:db8:3::/48",
36+
"blockBitsLength": 48,
37+
"nodeBitsLength": 0,
38+
"functionBitsLength": 16,
39+
"argumentBitsLength": 0,
40+
"statusUp": true,
41+
"chunks": [
42+
{
43+
"prefix": "2001:db8:3::/48",
44+
"proto": "system"
45+
}
46+
]
47+
},
48+
{
49+
"name": "loc4",
50+
"prefix": "2001:db8:3::/48",
51+
"blockBitsLength": 32,
52+
"nodeBitsLength": 16,
53+
"functionBitsLength": 16,
54+
"argumentBitsLength": 0,
55+
"statusUp": true,
56+
"chunks": [
57+
{
58+
"prefix": "2001:db8:3::/48",
59+
"proto": "system"
60+
}
61+
]
62+
},
63+
{
64+
"name": "loc5",
65+
"prefix": "2001:db8:3::/48",
66+
"blockBitsLength": 24,
67+
"nodeBitsLength": 24,
68+
"functionBitsLength": 16,
69+
"argumentBitsLength": 0,
70+
"statusUp": true,
71+
"chunks": [
72+
{
73+
"prefix": "2001:db8:3::/48",
74+
"proto": "system"
75+
}
76+
]
77+
},
78+
{
79+
"name": "loc6",
80+
"prefix": "2001:db8::/32",
81+
"blockBitsLength": 16,
82+
"nodeBitsLength": 16,
83+
"functionBitsLength": 0,
84+
"argumentBitsLength": 0,
85+
"statusUp": true,
86+
"chunks": [
87+
{
88+
"prefix": "2001:db8:3::/48",
89+
"proto": "system"
90+
}
91+
]
92+
},
93+
{
94+
"name": "loc7",
95+
"prefix": "2001::/16",
96+
"blockBitsLength": 16,
97+
"nodeBitsLength": 0,
98+
"functionBitsLength": 16,
99+
"argumentBitsLength": 0,
100+
"statusUp": true,
101+
"chunks": [
102+
{
103+
"prefix": "2001:db8:3::/48",
104+
"proto": "system"
105+
}
106+
]
107+
}
108+
]
109+
}

tests/topotests/srv6_locator_custom_bits_length/test_srv6_locator_custom_bits_length.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,49 @@ def check_srv6_locator(router, expected_file):
185185
check_srv6_locator(router, "expected_locators7.json")
186186

187187

188+
def test_srv6_locator_node_len():
189+
tgen = get_topogen()
190+
if tgen.routers_have_failure():
191+
pytest.skip(tgen.errors)
192+
router = tgen.gears["r1"]
193+
194+
def _check_srv6_locator(router, expected_locator_file):
195+
logger.info("checking zebra locator status")
196+
output = json.loads(router.vtysh_cmd("show segment-routing srv6 locator json"))
197+
expected = open_json_file("{}/{}".format(CWD, expected_locator_file))
198+
return topotest.json_cmp(output, expected)
199+
200+
def check_srv6_locator(router, expected_file):
201+
func = functools.partial(_check_srv6_locator, router, expected_file)
202+
_, result = topotest.run_and_expect(func, None, count=20, wait=1)
203+
assert result is None, "Failed"
204+
205+
logger.info("Configure various locators with and without node-len")
206+
router.vtysh_cmd(
207+
"""
208+
configure terminal
209+
segment-routing
210+
srv6
211+
locators
212+
locator loc1
213+
prefix 2001:db8:3::/48 block-len 32
214+
locator loc2
215+
prefix 2001:db8:3::/48 block-len 48 node-len 0
216+
locator loc3
217+
prefix 2001:db8:3::/48 node-len 0
218+
locator loc4
219+
prefix 2001:db8:3::/48 node-len 16
220+
locator loc5
221+
prefix 2001:db8:3::/48
222+
locator loc6
223+
prefix 2001:db8::/32 block-len 16 node-len 16 func-bits 0
224+
locator loc7
225+
prefix 2001::/16 block-len 16 node-len 0 func-bits 16
226+
"""
227+
)
228+
check_srv6_locator(router, "expected_locators8.json")
229+
230+
188231
if __name__ == "__main__":
189232
args = ["-s"] + sys.argv[1:]
190233
sys.exit(pytest.main(args))

zebra/zebra_srv6_vty.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -788,7 +788,7 @@ DEFUN (no_srv6_locator,
788788
DEFPY (locator_prefix,
789789
locator_prefix_cmd,
790790
"prefix X:X::X:X/M$prefix [block-len (16-64)$block_bit_len] \
791-
[node-len (16-64)$node_bit_len] [func-bits (0-64)$func_bit_len]",
791+
[node-len (0-64)$node_bit_len] [func-bits (0-64)$func_bit_len]",
792792
"Configure SRv6 locator prefix\n"
793793
"Specify SRv6 locator prefix\n"
794794
"Configure SRv6 locator block length in bits\n"
@@ -804,12 +804,16 @@ DEFPY (locator_prefix,
804804
uint8_t expected_prefixlen;
805805
struct srv6_sid_format *format;
806806
int idx = 0;
807+
bool node_bit_not_conf = false;
807808

808809
locator->prefix = *prefix;
809810
/* Only set default if func_bit_len was not provided in command */
810811
if (func_bit_len == 0 && !argv_find(argv, argc, "func-bits", &idx))
811812
func_bit_len = ZEBRA_SRV6_FUNCTION_LENGTH;
812813

814+
if (node_bit_len == 0 && !argv_find(argv, argc, "node-len", &idx))
815+
node_bit_not_conf = true;
816+
813817
expected_prefixlen = prefix->prefixlen;
814818
format = locator->sid_format;
815819
if (format) {
@@ -832,13 +836,13 @@ DEFPY (locator_prefix,
832836
}
833837

834838
/* Resolve optional arguments */
835-
if (block_bit_len == 0 && node_bit_len == 0) {
839+
if (block_bit_len == 0 && node_bit_not_conf) {
836840
block_bit_len = prefix->prefixlen -
837841
ZEBRA_SRV6_LOCATOR_NODE_LENGTH;
838842
node_bit_len = ZEBRA_SRV6_LOCATOR_NODE_LENGTH;
839843
} else if (block_bit_len == 0) {
840844
block_bit_len = prefix->prefixlen - node_bit_len;
841-
} else if (node_bit_len == 0) {
845+
} else if (node_bit_not_conf) {
842846
node_bit_len = prefix->prefixlen - block_bit_len;
843847
} else {
844848
if (block_bit_len + node_bit_len != prefix->prefixlen) {

0 commit comments

Comments
 (0)