Skip to content

Commit

Permalink
Support for multiple pce's
Browse files Browse the repository at this point in the history
Signed-off-by: Javier Garcia <[email protected]>
  • Loading branch information
Javier Garcia committed Jun 23, 2020
1 parent 678424d commit 6519a25
Show file tree
Hide file tree
Showing 6 changed files with 408 additions and 67 deletions.
73 changes: 51 additions & 22 deletions pathd/path_pcep.c
Original file line number Diff line number Diff line change
Expand Up @@ -407,35 +407,30 @@ DEFUN_NOSH(
DEFUN(pcep_cli_no_pcc, pcep_cli_no_pcc_cmd, "no pcc",
NO_STR "PCC configuration\n")
{
pcep_ctrl_remove_pcc(pcep_g->fpt, 1);
if (pcep_g->pce_opts[0] != NULL) {
XFREE(MTYPE_PCEP, pcep_g->pce_opts[0]);
pcep_g->pce_opts[0] = NULL;
}
if (pcep_g->pcc_opts != NULL) {
XFREE(MTYPE_PCEP, pcep_g->pcc_opts);
pcep_g->pcc_opts = NULL;
}
pcep_ctrl_remove_pcc(pcep_g->fpt, NULL);
return CMD_SUCCESS;
}

DEFUN(pcep_cli_pce, pcep_cli_pce_cmd,
"pce <ip A.B.C.D | ipv6 X:X::X:X> [port (1024-65535)] [sr-draft07]",
"pce <ip A.B.C.D | ipv6 X:X::X:X> [port (1024-65535)] [sr-draft07] [precedence (0-255)]",
"PCE configuration\n"
"PCE IPv4 address\n"
"Remote PCE server IPv4 address\n"
"PCE IPv6 address\n"
"Remote PCE server IPv6 address\n"
"Remote PCE server port\n"
"Remote PCE server port value\n"
"Use the draft 07 of PCEP segemnt routing\n")
"Use the draft 07 of PCEP segment routing\n"
"Priority when multiple pce, the lower the more precedence\n"
"Priority value , (default 255)\n")
{
/* TODO: Add support for multiple PCE */

struct ipaddr pce_addr;
uint32_t pce_port = PCEP_DEFAULT_PORT;
struct pce_opts *pce_opts, *pce_opts_copy;
struct pce_opts *pce_opts;
bool draft07 = false;
uint8_t pce_precedence = PCE_DEFAULT_PRECEDENCE;
int i = 1;

/* Get the first argument, should be either ip or ipv6 */
Expand Down Expand Up @@ -479,22 +474,28 @@ DEFUN(pcep_cli_pce, pcep_cli_pce_cmd,
i++;
continue;
}
if (strcmp("precedence", argv[i]->arg) == 0) {
i++;
if (i >= argc)
return CMD_ERR_NO_MATCH;
pce_precedence = atoi(argv[i]->arg);
i++;
continue;
}
return CMD_ERR_NO_MATCH;
}

pce_opts = XCALLOC(MTYPE_PCEP, sizeof(*pce_opts));
IPADDR_COPY(&pce_opts->addr, &pce_addr);
pce_opts->port = pce_port;
pce_opts->draft07 = draft07;
pce_opts->precedence = pce_precedence;

if (pcep_ctrl_update_pce_options(pcep_g->fpt, 1, pce_opts))
#define NO_USE 0
if (pcep_ctrl_update_pce_options(pcep_g->fpt, NO_USE /*current_pcc_id*/,
pce_opts))
return CMD_WARNING;

if (pcep_g->pce_opts[0] != NULL)
XFREE(MTYPE_PCEP, pcep_g->pce_opts[0]);
pce_opts_copy = XCALLOC(MTYPE_PCEP, sizeof(*pce_opts));
pce_opts_copy = memcpy(pce_opts_copy, pce_opts, sizeof(*pce_opts));
pcep_g->pce_opts[0] = pce_opts_copy;

return CMD_SUCCESS;
}
Expand All @@ -511,12 +512,34 @@ DEFUN(pcep_cli_no_pce, pcep_cli_no_pce_cmd,
"Remote PCE server port value\n")
{
/* TODO: Add support for multiple PCE */
int i = 2;
static struct ipaddr pce_addr;
pce_addr.ipa_type = IPADDR_V4;
SET_IPADDR_V4(&pce_addr);
if (strcmp("ipv6", argv[i]->arg) == 0) {
SET_IPADDR_V6(&pce_addr);
} else if (strcmp("ip", argv[i]->arg) != 0) {
return CMD_ERR_NO_MATCH;
}

pcep_ctrl_remove_pcc(pcep_g->fpt, 1);
if (pcep_g->pce_opts[0] != NULL) {
XFREE(MTYPE_PCEP, pcep_g->pce_opts[0]);
pcep_g->pce_opts[0] = NULL;
/* Get the first argument value */
i++;
if (i >= argc) {
return CMD_ERR_NO_MATCH;
}
if (IS_IPADDR_V6(&pce_addr)) {
if (!inet_pton(AF_INET6, argv[i]->arg, &pce_addr.ipaddr_v6)) {
return CMD_ERR_INCOMPLETE;
}
} else {
if (!inet_pton(AF_INET, argv[i]->arg, &pce_addr.ipaddr_v4)) {
return CMD_ERR_INCOMPLETE;
}
}


pcep_ctrl_remove_pcc(pcep_g->fpt, &pce_addr /*current_pcc_id*/);

return CMD_SUCCESS;
}

Expand Down Expand Up @@ -625,6 +648,12 @@ int pcep_cli_pcc_config_write(struct vty *vty)
csnprintfrr(buff, sizeof(buff),
" sr-draft07");
}
if (pce_opts->precedence
!= PCE_DEFAULT_PRECEDENCE) {
csnprintfrr(buff, sizeof(buff),
" precedence %d",
pce_opts->precedence);
}
if (IS_IPADDR_V6(&pce_opts->addr)) {
vty_out(vty, " pce ipv6 %pI6%s\n",
&pce_opts->addr.ipaddr_v6,
Expand Down
6 changes: 5 additions & 1 deletion pathd/path_pcep.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@
#include "pathd/pathd.h"
#include "pathd/path_pcep_memory.h"

#define PCE_DEFAULT_PRECEDENCE 255
#define PCC_DEFAULT_MSD 4
#define PCEP_DEFAULT_PORT 4189
#define MAX_PCC 1
#define MAX_PCC 3
#define MAX_TAG_SIZE 50
#define PCEP_DEBUG_MODE_BASIC 0x01
#define PCEP_DEBUG_MODE_PATH 0x02
Expand Down Expand Up @@ -84,6 +85,9 @@ struct pce_opts {
struct ipaddr addr;
short port;
bool draft07;
uint8_t precedence;
bool is_best;
bool previous_best;
};

struct pcc_opts {
Expand Down
Loading

0 comments on commit 6519a25

Please sign in to comment.