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

Add CLI about locator and related funcs #16894

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions doc/user/zebra.rst
Original file line number Diff line number Diff line change
Expand Up @@ -894,19 +894,30 @@ and this section also helps that case.
function development holds the owner of the chunk of this locator, and no
other routing protocol will use this area.

Additionally, if a static local SID is configured,
it will also be displayed in this section.

::

router# show segment-routing srv6 locator loc1 detail
Name: loc1
Prefix: 2001:db8:1:1::/64
Chunks:
- prefix: 2001:db8:1:1::/64, owner: system
sids:
-opcode ::fff1:11:0:0:0/128
sidaction End.DT46
vrf Vrf1

router# show segment-routing srv6 locator loc2 detail
Name: loc2
Prefix: 2001:db8:2:2::/64
Chunks:
- prefix: 2001:db8:2:2::/64, owner: sharp
sids:
-opcode ::fff1:12:0:0:0/128
sidaction End.DT46
vrf Vrf2

.. clicmd:: segment-routing

Expand Down Expand Up @@ -991,6 +1002,37 @@ and this section also helps that case.
!
...

.. clicmd:: opcode WORD <end|end-dt4|end-dt46|end-dt6> [vrf VRF]

Specify the opcode manually. Configuring a local sid in a purely static mode
by specifying the opcode would generate a unique mySID table entry.
This feature will support the configuration of static SRv6 decapsulation on the system.
When configuring the local sid, if the action is set to 'end', no vrf should be set.
However, for any other action, it is necessary to specify a specific vrf.

::

router# configure terminal
router(config)# segment-routing
router(config-sr)# srv6
router(config-srv6)# locators
router(config-srv6-locators)# locator loc1
router(config-srv6-locator)# prefix fd00:202:202::/48 block-len 32 node-len 16 func-bits 16
router(config-srv6-locator)# opcode ::fff1:11:0:0:0 end-dt46 vrf Vrf1
router(config-srv6-locator)# opcode ::fff1:12:0:0:0 end-dt46 vrf Vrf2

router(config-srv6-locator)# show run
...
segment-routing
srv6
locators
locator loc1
prefix fd00:202:202::/48 block-len 32 node-len 16 func-bits 16
opcode ::fff1:11:0:0:0 end-dt46 vrf Vrf1
opcode ::fff1:12:0:0:0 end-dt46 vrf Vrf2
!
...

.. clicmd:: behavior usid

Specify the SRv6 locator as a Micro-segment (uSID) locator. When a locator is
Expand Down
1 change: 1 addition & 0 deletions lib/command.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ enum node_type {
SRV6_NODE, /* SRv6 node */
SRV6_LOCS_NODE, /* SRv6 locators node */
SRV6_LOC_NODE, /* SRv6 locator node */
SRV6_PREFIX_NODE, /* SRv6 locator prefix node */
SRV6_ENCAP_NODE, /* SRv6 encapsulation node */
SRV6_SID_FORMATS_NODE, /* SRv6 SID formats config node */
SRV6_SID_FORMAT_USID_F3216_NODE, /* SRv6 uSID f3216 format config node */
Expand Down
87 changes: 87 additions & 0 deletions lib/srv6.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,20 @@ struct srv6_locator *srv6_locator_alloc(const char *name)
locator->chunks = list_new();
locator->chunks->del = srv6_locator_chunk_list_free;

locator->sids = list_new();

QOBJ_REG(locator, srv6_locator);
return locator;
}
void srv6_locator_del(struct srv6_locator *locator)
{
if (locator->chunks)
list_delete(&locator->chunks);
if (locator->sids)
list_delete(&locator->sids);
XFREE(MTYPE_SRV6_LOCATOR, locator);
return;
}

struct srv6_locator_chunk *srv6_locator_chunk_alloc(void)
{
Expand Down Expand Up @@ -205,6 +216,49 @@ void srv6_locator_free(struct srv6_locator *locator)
}
}

struct seg6_sid *srv6_locator_sid_alloc(void)
{
struct seg6_sid *sid = NULL;

sid = XCALLOC(MTYPE_SRV6_LOCATOR_CHUNK, sizeof(struct seg6_sid));
strlcpy(sid->vrfName, "Default", sizeof(sid->vrfName));
return sid;
}
void srv6_locator_sid_free(struct seg6_sid *sid)
{
XFREE(MTYPE_SRV6_LOCATOR_CHUNK, sid);
return;
}

void combine_sid(struct srv6_locator *locator, struct in6_addr *sid_addr,
struct in6_addr *result_addr)
{
uint8_t idx = 0;
uint8_t funcid = 0;
uint8_t locatorbit = 0;
/* uint8_t sidbit = 0;*/
uint8_t totalbit = 0;
uint8_t funbit = 0;
locatorbit =
(locator->block_bits_length + locator->node_bits_length) / 8;
/* sidbit = 16 - locatorbit; */
totalbit = (locator->block_bits_length + locator->node_bits_length +
locator->function_bits_length +
locator->argument_bits_length) /
8;
funbit = (locator->function_bits_length +
locator->argument_bits_length) /
8;
for (idx = 0; idx < locatorbit; idx++) {
result_addr->s6_addr[idx] = locator->prefix.prefix.s6_addr[idx];
}
for (; idx < totalbit; idx++) {
result_addr->s6_addr[idx] =
sid_addr->s6_addr[16 - funbit + funcid];
funcid++;
}
}

void srv6_locator_chunk_free(struct srv6_locator_chunk **chunk)
{
XFREE(MTYPE_SRV6_LOCATOR_CHUNK, *chunk);
Expand Down Expand Up @@ -316,6 +370,27 @@ srv6_locator_chunk_detailed_json(const struct srv6_locator_chunk *chunk)
return jo_root;
}

json_object *srv6_locator_sid_detailed_json(const struct srv6_locator *locator,
const struct seg6_sid *sid)
{
json_object *jo_root = NULL;
char buf[256];

jo_root = json_object_new_object();

/* set opcode */
prefix2str(&sid->ipv6Addr, buf, sizeof(buf));
json_object_string_add(jo_root, "opcode", buf);

/* set sidaction */
json_object_string_add(jo_root, "sidaction", seg6local_action2str(sid->sidaction));

/* set vrf */
json_object_string_add(jo_root, "vrf", sid->vrfName);

return jo_root;
}

json_object *srv6_locator_json(const struct srv6_locator *loc)
{
struct listnode *node;
Expand Down Expand Up @@ -392,10 +467,14 @@ json_object *srv6_locator_json(const struct srv6_locator *loc)
json_object *srv6_locator_detailed_json(const struct srv6_locator *loc)
{
struct listnode *node;
struct listnode *sidnode;
struct srv6_locator_chunk *chunk;
struct seg6_sid *sid = NULL;
json_object *jo_root = NULL;
json_object *jo_chunk = NULL;
json_object *jo_chunks = NULL;
json_object *jo_sid = NULL;
json_object *jo_sids = NULL;

jo_root = json_object_new_object();

Expand Down Expand Up @@ -461,5 +540,13 @@ json_object *srv6_locator_detailed_json(const struct srv6_locator *loc)
json_object_array_add(jo_chunks, jo_chunk);
}

/* set sids */
jo_sids = json_object_new_array();
json_object_object_add(jo_root, "sids", jo_sids);
for (ALL_LIST_ELEMENTS_RO(loc->sids, sidnode, sid)) {
jo_sid = srv6_locator_sid_detailed_json(loc, sid);
json_object_array_add(jo_sids, jo_sid);
}

return jo_root;
}
16 changes: 16 additions & 0 deletions lib/srv6.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <zebra.h>
#include "prefix.h"
#include "json.h"
#include "vrf.h"

#include <arpa/inet.h>
#include <netinet/in.h>
Expand Down Expand Up @@ -125,6 +126,7 @@ struct srv6_locator {
uint64_t current;
bool status_up;
struct list *chunks;
struct list *sids;

uint8_t flags;
#define SRV6_LOCATOR_USID (1 << 0) /* The SRv6 Locator is a uSID Locator */
Expand Down Expand Up @@ -163,6 +165,12 @@ struct srv6_locator_chunk {
uint8_t flags;
};

struct seg6_sid {
enum seg6local_action_t sidaction;
char vrfName[VRF_NAMSIZ + 1];
struct prefix_ipv6 ipv6Addr;
char sidstr[PREFIX_STRLEN];
};
/*
* SRv6 Endpoint Behavior codepoints, as defined by IANA in
* https://www.iana.org/assignments/segment-routing/segment-routing.xhtml
Expand Down Expand Up @@ -372,8 +380,14 @@ static inline const char *srv6_sid_ctx2str(char *str, size_t size,
int snprintf_seg6_segs(char *str,
size_t size, const struct seg6_segs *segs);

extern void combine_sid(struct srv6_locator *locator, struct in6_addr *sid_addr,
struct in6_addr *result_addr);
extern void srv6_locator_del(struct srv6_locator *locator);

extern struct srv6_locator *srv6_locator_alloc(const char *name);
extern struct srv6_locator_chunk *srv6_locator_chunk_alloc(void);
extern struct seg6_sid *srv6_locator_sid_alloc(void);
extern void srv6_locator_sid_free(struct seg6_sid *sid);
extern void srv6_locator_free(struct srv6_locator *locator);
extern void srv6_locator_chunk_list_free(void *data);
extern void srv6_locator_chunk_free(struct srv6_locator_chunk **chunk);
Expand All @@ -384,6 +398,8 @@ json_object *srv6_locator_json(const struct srv6_locator *loc);
json_object *srv6_locator_detailed_json(const struct srv6_locator *loc);
json_object *
srv6_locator_chunk_detailed_json(const struct srv6_locator_chunk *chunk);
json_object *srv6_locator_sid_detailed_json(const struct srv6_locator *locator,
const struct seg6_sid *sid);

extern struct srv6_sid_format *srv6_sid_format_alloc(const char *name);
extern void srv6_sid_format_free(struct srv6_sid_format *format);
Expand Down
28 changes: 28 additions & 0 deletions lib/zclient.c
Original file line number Diff line number Diff line change
Expand Up @@ -1156,6 +1156,34 @@ int zapi_srv6_locator_decode(struct stream *s, struct srv6_locator *l)
return -1;
}

int zapi_srv6_locator_sid_encode(struct stream *s, struct srv6_locator *loc)
{
struct seg6_sid *sidtmp = NULL;
struct listnode *node = NULL;

stream_putw(s, strlen(loc->name));
stream_put(s, loc->name, strlen(loc->name));

stream_putw(s, loc->prefix.prefixlen);
stream_put(s, &loc->prefix.prefix, sizeof(loc->prefix.prefix));
stream_putc(s, loc->block_bits_length);
stream_putc(s, loc->node_bits_length);
stream_putc(s, loc->function_bits_length);
stream_putc(s, loc->argument_bits_length);

stream_putl(s, loc->sids->count);
for (ALL_LIST_ELEMENTS_RO(loc->sids, node, sidtmp)) {
stream_putw(s, sidtmp->ipv6Addr.prefixlen);
stream_put(s, &sidtmp->ipv6Addr.prefix,
sizeof(sidtmp->ipv6Addr.prefix));
stream_putl(s, sidtmp->sidaction);
stream_putw(s, strlen(sidtmp->vrfName));
stream_put(s, sidtmp->vrfName, strlen(sidtmp->vrfName));
}

return 0;
}

static int zapi_nhg_encode(struct stream *s, int cmd, struct zapi_nhg *api_nhg)
{
int i;
Expand Down
6 changes: 6 additions & 0 deletions lib/zclient.h
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,9 @@ typedef enum {
ZEBRA_SRV6_MANAGER_GET_LOCATOR,
ZEBRA_SRV6_MANAGER_GET_SRV6_SID,
ZEBRA_SRV6_MANAGER_RELEASE_SRV6_SID,
ZEBRA_SRV6_MANAGER_GET_LOCATOR_SID,
ZEBRA_SRV6_MANAGER_RELEASE_LOCATOR_SID,
ZEBRA_SRV6_MANAGER_GET_LOCATOR_ALL,
ZEBRA_ERROR,
ZEBRA_CLIENT_CAPABILITIES,
ZEBRA_OPAQUE_MESSAGE,
Expand Down Expand Up @@ -1088,6 +1091,9 @@ extern struct interface *zebra_interface_link_params_read(struct stream *s,
bool *changed);
extern size_t zebra_interface_link_params_write(struct stream *,
struct interface *);

extern int zapi_srv6_locator_sid_encode(struct stream *s,
struct srv6_locator *loc);
extern enum zclient_send_status
zclient_send_get_label_chunk(struct zclient *zclient, uint8_t keep,
uint32_t chunk_size, uint32_t base);
Expand Down
Empty file.
10 changes: 10 additions & 0 deletions tests/topotests/zebra_static_opcode_sid/r1/bgpd.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
router bgp 65000
no bgp ebgp-requires-policy
timers bgp start-timer 0
neighbor aaa peer-group
neighbor aaa remote-as 65001
neighbor 192.168.254.2 peer-group aaa
neighbor 192.168.255.2 remote-as 65001
neighbor 192.168.255.2 timers 3 10
exit-address-family
!
9 changes: 9 additions & 0 deletions tests/topotests/zebra_static_opcode_sid/r1/zebra.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
!
interface r1-eth0
ip address 192.168.255.1/24
!
interface r1-eth1
ip address 192.168.254.1/24
!
ip forwarding
!
10 changes: 10 additions & 0 deletions tests/topotests/zebra_static_opcode_sid/r2/bgpd.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
router bgp 65001
no bgp ebgp-requires-policy
timers bgp start-timer 0
neighbor aaa peer-group
neighbor aaa remote-as 65000
neighbor 192.168.254.1 peer-group aaa
neighbor 192.168.255.1 remote-as 65000
neighbor 192.168.255.1 timers 3 10
exit-address-family
!
9 changes: 9 additions & 0 deletions tests/topotests/zebra_static_opcode_sid/r2/zebra.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
!
interface r2-eth0
ip address 192.168.255.2/24
!
interface r2-eth1
ip address 192.168.254.2/24
!
ip forwarding
!
Loading
Loading