Skip to content
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

bgpd, zebra: Add support for SRv6 uSID Behaviors #12219

Merged
4 changes: 3 additions & 1 deletion bgpd/bgp_attr.c
Original file line number Diff line number Diff line change
Expand Up @@ -4355,7 +4355,9 @@ bgp_size_t bgp_packet_attribute(struct bgp *bgp, struct peer *peer,
stream_put(s, &attr->srv6_l3vpn->sid,
sizeof(attr->srv6_l3vpn->sid)); /* sid */
stream_putc(s, 0); /* sid_flags */
stream_putw(s, 0xffff); /* endpoint */
stream_putw(s,
attr->srv6_l3vpn
->endpoint_behavior); /* endpoint */
stream_putc(s, 0); /* reserved */
stream_putc(
s,
Expand Down
18 changes: 16 additions & 2 deletions bgpd/bgp_mplsvpn.c
Original file line number Diff line number Diff line change
Expand Up @@ -1562,13 +1562,22 @@ void vpn_leak_from_vrf_update(struct bgp *to_bgp, /* to */

/* Set SID for SRv6 VPN */
if (from_bgp->vpn_policy[afi].tovpn_sid_locator) {
struct srv6_locator_chunk *locator =
from_bgp->vpn_policy[afi].tovpn_sid_locator;
encode_label(
from_bgp->vpn_policy[afi].tovpn_sid_transpose_label,
&label);
static_attr.srv6_l3vpn = XCALLOC(MTYPE_BGP_SRV6_L3VPN,
sizeof(struct bgp_attr_srv6_l3vpn));
static_attr.srv6_l3vpn->sid_flags = 0x00;
static_attr.srv6_l3vpn->endpoint_behavior = 0xffff;
static_attr.srv6_l3vpn->endpoint_behavior =
afi == AFI_IP
? (CHECK_FLAG(locator->flags, SRV6_LOCATOR_USID)
? SRV6_ENDPOINT_BEHAVIOR_END_DT4_USID
: SRV6_ENDPOINT_BEHAVIOR_END_DT4)
: (CHECK_FLAG(locator->flags, SRV6_LOCATOR_USID)
? SRV6_ENDPOINT_BEHAVIOR_END_DT6_USID
: SRV6_ENDPOINT_BEHAVIOR_END_DT6);
static_attr.srv6_l3vpn->loc_block_len =
from_bgp->vpn_policy[afi]
.tovpn_sid_locator->block_bits_length;
Expand All @@ -1595,12 +1604,17 @@ void vpn_leak_from_vrf_update(struct bgp *to_bgp, /* to */
.tovpn_sid_locator->prefix.prefix,
sizeof(struct in6_addr));
} else if (from_bgp->tovpn_sid_locator) {
struct srv6_locator_chunk *locator =
from_bgp->tovpn_sid_locator;
encode_label(from_bgp->tovpn_sid_transpose_label, &label);
static_attr.srv6_l3vpn =
XCALLOC(MTYPE_BGP_SRV6_L3VPN,
sizeof(struct bgp_attr_srv6_l3vpn));
static_attr.srv6_l3vpn->sid_flags = 0x00;
static_attr.srv6_l3vpn->endpoint_behavior = 0xffff;
static_attr.srv6_l3vpn->endpoint_behavior =
CHECK_FLAG(locator->flags, SRV6_LOCATOR_USID)
? SRV6_ENDPOINT_BEHAVIOR_END_DT46_USID
: SRV6_ENDPOINT_BEHAVIOR_END_DT46;
static_attr.srv6_l3vpn->loc_block_len =
from_bgp->tovpn_sid_locator->block_bits_length;
static_attr.srv6_l3vpn->loc_node_len =
Expand Down
30 changes: 30 additions & 0 deletions doc/user/zebra.rst
Original file line number Diff line number Diff line change
Expand Up @@ -810,6 +810,36 @@ and this section also helps that case.
!
...

.. clicmd:: behavior usid

Specify the SRv6 locator as a Micro-segment (uSID) locator. When a locator is
specified as a uSID locator, all the SRv6 SIDs allocated from the locator by the routing
protocols are bound to the SRv6 uSID behaviors. For example, if you configure BGP to use
a locator specified as a uSID locator, BGP instantiates and advertises SRv6 uSID behaviors
(e.g., ``uDT4`` / ``uDT6`` / ``uDT46``) instead of classic SRv6 behaviors
(e.g., ``End.DT4`` / ``End.DT6`` / ``End.DT46``).

::

router# configure terminal
router(config)# segment-routinig
router(config-sr)# srv6
router(config-srv6)# locators
router(config-srv6-locators)# locator loc1
router(config-srv6-locator)# prefix fc00:0:1::/48 block-len 32 node-len 16 func-bits 16
router(config-srv6-locator)# behavior usid

router(config-srv6-locator)# show run
...
segment-routing
srv6
locators
locator loc1
prefix fc00:0:1::/48
behavior usid
!
...

.. _multicast-rib-commands:

Multicast RIB Commands
Expand Down
8 changes: 8 additions & 0 deletions lib/srv6.c
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,10 @@ json_object *srv6_locator_json(const struct srv6_locator *loc)
json_object_int_add(jo_root, "argumentBitsLength",
loc->argument_bits_length);

/* set true if the locator is a Micro-segment (uSID) locator */
if (CHECK_FLAG(loc->flags, SRV6_LOCATOR_USID))
json_object_string_add(jo_root, "behavior", "usid");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest telling explicitly for the operator what is the behavior used, instead of just usid.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here the behavior defines the type of the locator which is usid. Based on the type of the locator, the other processes (e.g., bgpd) will use the proper behavior (e.g., uDT4 for L3VPNv4) and use the corresponding IANA codepoint.


/* set status_up */
json_object_boolean_add(jo_root, "statusUp",
loc->status_up);
Expand Down Expand Up @@ -290,6 +294,10 @@ json_object *srv6_locator_detailed_json(const struct srv6_locator *loc)
json_object_int_add(jo_root, "argumentBitsLength",
loc->argument_bits_length);

/* set true if the locator is a Micro-segment (uSID) locator */
if (CHECK_FLAG(loc->flags, SRV6_LOCATOR_USID))
json_object_string_add(jo_root, "behavior", "usid");

/* set algonum */
json_object_int_add(jo_root, "algoNum", loc->algonum);

Expand Down
20 changes: 20 additions & 0 deletions lib/srv6.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ struct srv6_locator {
bool status_up;
struct list *chunks;

uint8_t flags;
#define SRV6_LOCATOR_USID (1 << 0) /* The SRv6 Locator is a uSID Locator */

QOBJ_FIELDS;
};
DECLARE_QOBJ_TYPE(srv6_locator);
Expand All @@ -116,6 +119,23 @@ struct srv6_locator_chunk {
uint8_t proto;
uint16_t instance;
uint32_t session_id;

uint8_t flags;
};

/*
* SRv6 Endpoint Behavior codepoints, as defined by IANA in
* https://www.iana.org/assignments/segment-routing/segment-routing.xhtml
*/
enum srv6_endpoint_behavior_codepoint {
SRV6_ENDPOINT_BEHAVIOR_RESERVED = 0x0000,
SRV6_ENDPOINT_BEHAVIOR_END_DT6 = 0x0012,
SRV6_ENDPOINT_BEHAVIOR_END_DT4 = 0x0013,
SRV6_ENDPOINT_BEHAVIOR_END_DT46 = 0x0014,
SRV6_ENDPOINT_BEHAVIOR_END_DT6_USID = 0x003E,
SRV6_ENDPOINT_BEHAVIOR_END_DT4_USID = 0x003F,
SRV6_ENDPOINT_BEHAVIOR_END_DT46_USID = 0x0040,
SRV6_ENDPOINT_BEHAVIOR_OPAQUE = 0xFFFF,
};

struct nexthop_srv6 {
Expand Down
2 changes: 2 additions & 0 deletions lib/zclient.c
Original file line number Diff line number Diff line change
Expand Up @@ -1088,6 +1088,7 @@ int zapi_srv6_locator_chunk_encode(struct stream *s,
stream_putc(s, c->node_bits_length);
stream_putc(s, c->function_bits_length);
stream_putc(s, c->argument_bits_length);
stream_putc(s, c->flags);
return 0;
}

Expand All @@ -1109,6 +1110,7 @@ int zapi_srv6_locator_chunk_decode(struct stream *s,
STREAM_GETC(s, c->node_bits_length);
STREAM_GETC(s, c->function_bits_length);
STREAM_GETC(s, c->argument_bits_length);
STREAM_GETC(s, c->flags);
return 0;

stream_failure:
Expand Down
Empty file.
1 change: 1 addition & 0 deletions tests/topotests/srv6_locator_usid/expected_chunks_1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
8 changes: 8 additions & 0 deletions tests/topotests/srv6_locator_usid/expected_chunks_2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[
{
"name": "loc1",
"chunks": [
"fc00:0:1::/48"
]
}
]
1 change: 1 addition & 0 deletions tests/topotests/srv6_locator_usid/expected_chunks_3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
1 change: 1 addition & 0 deletions tests/topotests/srv6_locator_usid/expected_chunks_4.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
2 changes: 2 additions & 0 deletions tests/topotests/srv6_locator_usid/expected_chunks_5.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[
]
2 changes: 2 additions & 0 deletions tests/topotests/srv6_locator_usid/expected_chunks_6.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[
]
2 changes: 2 additions & 0 deletions tests/topotests/srv6_locator_usid/expected_chunks_7.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[
]
2 changes: 2 additions & 0 deletions tests/topotests/srv6_locator_usid/expected_chunks_8.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[
]
20 changes: 20 additions & 0 deletions tests/topotests/srv6_locator_usid/expected_locators_1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"locators":[
{
"name": "loc1",
"prefix": "fc00:0:1::/48",
"blockBitsLength": 32,
"nodeBitsLength": 16,
"functionBitsLength": 16,
"argumentBitsLength": 0,
"behavior": "usid",
"statusUp": true,
"chunks": [
{
"prefix": "fc00:0:1::/48",
"proto": "system"
}
]
}
]
}
20 changes: 20 additions & 0 deletions tests/topotests/srv6_locator_usid/expected_locators_2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"locators":[
{
"name": "loc1",
"prefix": "fc00:0:1::/48",
"blockBitsLength": 32,
"nodeBitsLength": 16,
"functionBitsLength": 16,
"argumentBitsLength": 0,
"behavior": "usid",
"statusUp": true,
"chunks": [
{
"prefix": "fc00:0:1::/48",
"proto": "sharp"
}
]
}
]
}
20 changes: 20 additions & 0 deletions tests/topotests/srv6_locator_usid/expected_locators_3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"locators":[
{
"name": "loc1",
"prefix": "fc00:0:1::/48",
"blockBitsLength": 32,
"nodeBitsLength": 16,
"functionBitsLength": 16,
"argumentBitsLength": 0,
"behavior": "usid",
"statusUp": true,
"chunks": [
{
"prefix": "fc00:0:1::/48",
"proto": "system"
}
]
}
]
}
35 changes: 35 additions & 0 deletions tests/topotests/srv6_locator_usid/expected_locators_4.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"locators":[
{
"name": "loc1",
"prefix": "fc00:0:1::/48",
"blockBitsLength": 32,
"nodeBitsLength": 16,
"functionBitsLength": 16,
"argumentBitsLength": 0,
"behavior": "usid",
"statusUp": true,
"chunks": [
{
"prefix": "fc00:0:1::/48",
"proto": "system"
}
]
},
{
"name": "loc2",
"prefix": "fc00:0:2::/48",
"blockBitsLength": 32,
"nodeBitsLength": 16,
"functionBitsLength": 16,
"argumentBitsLength": 0,
"statusUp": true,
"chunks": [
{
"prefix": "fc00:0:2::/48",
"proto": "system"
}
]
}
]
}
36 changes: 36 additions & 0 deletions tests/topotests/srv6_locator_usid/expected_locators_5.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"locators":[
{
"name": "loc1",
"prefix": "fc00:0:1::/48",
"blockBitsLength": 32,
"nodeBitsLength": 16,
"functionBitsLength": 16,
"argumentBitsLength": 0,
"behavior": "usid",
"statusUp": true,
"chunks": [
{
"prefix": "fc00:0:1::/48",
"proto": "system"
}
]
},
{
"name": "loc2",
"prefix": "fc00:0:2::/48",
"blockBitsLength": 32,
"nodeBitsLength": 16,
"functionBitsLength": 16,
"argumentBitsLength": 0,
"behavior": "usid",
"statusUp": true,
"chunks": [
{
"prefix": "fc00:0:2::/48",
"proto": "system"
}
]
}
]
}
35 changes: 35 additions & 0 deletions tests/topotests/srv6_locator_usid/expected_locators_6.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"locators":[
{
"name": "loc1",
"prefix": "fc00:0:1::/48",
"blockBitsLength": 32,
"nodeBitsLength": 16,
"functionBitsLength": 16,
"argumentBitsLength": 0,
"behavior": "usid",
"statusUp": true,
"chunks": [
{
"prefix": "fc00:0:1::/48",
"proto": "system"
}
]
},
{
"name": "loc2",
"prefix": "fc00:0:2::/48",
"blockBitsLength": 32,
"nodeBitsLength": 16,
"functionBitsLength": 16,
"argumentBitsLength": 0,
"statusUp": true,
"chunks": [
{
"prefix": "fc00:0:2::/48",
"proto": "system"
}
]
}
]
}
19 changes: 19 additions & 0 deletions tests/topotests/srv6_locator_usid/expected_locators_7.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"locators":[
{
"name": "loc2",
"prefix": "fc00:0:2::/48",
"statusUp": true,
"blockBitsLength": 32,
"nodeBitsLength": 16,
"functionBitsLength": 16,
"argumentBitsLength": 0,
"chunks":[
{
"prefix": "fc00:0:2::/48",
"proto": "system"
}
]
}
]
}
4 changes: 4 additions & 0 deletions tests/topotests/srv6_locator_usid/expected_locators_8.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"locators":[
]
}
2 changes: 2 additions & 0 deletions tests/topotests/srv6_locator_usid/r1/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ip link add dummy0 type dummy
ip link set dummy0 up
7 changes: 7 additions & 0 deletions tests/topotests/srv6_locator_usid/r1/sharpd.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
hostname r1
!
log stdout notifications
log monitor notifications
log commands
log file sharpd.log debugging
!
Loading