Skip to content

Commit

Permalink
yang: bond: add arp_ip_target and primary
Browse files Browse the repository at this point in the history
Signed-off-by: ali-aqrabawi <[email protected]>
  • Loading branch information
Ali-aqrabawi committed May 11, 2024
1 parent a3144fb commit e4257a2
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 11 deletions.
62 changes: 53 additions & 9 deletions src/lib/cmdgen.c
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ int create_cmd_arg_name(struct lyd_node *dnode, oper_t startcmd_op_val, char **a
* @param [in] curr_op_val starnode op_val
* @param [out] value the captured arg value value
*/
void create_cmd_arg_value(struct lyd_node *dnode, oper_t startcmd_op_val, char **arg_value)
int create_cmd_arg_value(struct lyd_node *dnode, oper_t startcmd_op_val, char **arg_value)
{
// if operation delete generate args only if:
// - node is key or startcmd has INCLUDE_ALL_ON_DELETE extention.
Expand All @@ -451,16 +451,16 @@ void create_cmd_arg_value(struct lyd_node *dnode, oper_t startcmd_op_val, char *
}

if (startcmd_op_val == DELETE_OPR && !lysc_is_key(dnode->schema) && !is_include_all_on_delete)
return;
return EXIT_SUCCESS;

// check if this is leaf delete
oper_t leaf_op_val = get_operation(dnode);
if (leaf_op_val == DELETE_OPR && !is_include_all_on_delete)
return;
return EXIT_SUCCESS;

// if FLAG extension, add schema name to the cmd and go to next iter.
if (get_extension(FLAG_EXT, dnode, NULL) == EXIT_SUCCESS) {
return;
return EXIT_SUCCESS;
}
if (arg_value == NULL)
arg_value = malloc(sizeof(char *));
Expand Down Expand Up @@ -531,7 +531,7 @@ void create_cmd_arg_value(struct lyd_node *dnode, oper_t startcmd_op_val, char *
"%s: failed to get xpath_arg found in AFTER_NODE_ADD_STATIC_ARG extension."
" for node = \"%s\" : %s\n",
__func__, dnode->schema->name, sr_strerror(ret));
// TODO: fine an exit way. the whole change should fail.
return EXIT_FAILURE;
}
}
free(xpath_arg);
Expand All @@ -541,6 +541,7 @@ void create_cmd_arg_value(struct lyd_node *dnode, oper_t startcmd_op_val, char *
*arg_value = strdup(fin_arg_value);
}
}
return EXIT_SUCCESS;
}

/**
Expand Down Expand Up @@ -659,14 +660,20 @@ char *lyd2cmdline_args(const struct lyd_node *startcmd_node, oper_t op_val)
if (include_node == NULL)
return NULL;

create_cmd_arg_value(include_node, op_val, &arg_value);
ret = create_cmd_arg_name(include_node, op_val, &arg_name);
if (ret != EXIT_SUCCESS) {
fprintf(stderr,
"%s: failed to create create_cmd_arg_name for node \"%s\".\n",
__func__, next->schema->name);
return NULL;
}
ret = create_cmd_arg_value(include_node, op_val, &arg_value);
if (ret != EXIT_SUCCESS) {
fprintf(stderr,
"%s: failed to create create_cmd_arg_value for node \"%s\".\n",
__func__, next->schema->name);
return NULL;
}

if (arg_name != NULL) {
strlcat(cmd_line, " ", sizeof(cmd_line));
Expand Down Expand Up @@ -701,13 +708,18 @@ char *lyd2cmdline_args(const struct lyd_node *startcmd_node, oper_t op_val)
__func__, next->schema->name);
return NULL;
}
create_cmd_arg_value(next, op_val, &arg_value);
ret = create_cmd_arg_name(next, op_val, &arg_name);
if (ret != EXIT_SUCCESS) {
fprintf(stderr, "%s: failed to create create_cmd_arg_name for node \"%s\".\n",
__func__, next->schema->name);
return NULL;
}
ret = create_cmd_arg_value(next, op_val, &arg_value);
if (ret != EXIT_SUCCESS) {
fprintf(stderr, "%s: failed to create create_cmd_arg_value for node \"%s\".\n",
__func__, next->schema->name);
return NULL;
}
if (arg_name != NULL) {
strlcat(cmd_line, " ", sizeof(cmd_line));
strlcat(cmd_line, arg_name, sizeof(cmd_line));
Expand All @@ -733,17 +745,49 @@ char *lyd2cmdline_args(const struct lyd_node *startcmd_node, oper_t op_val)
// leaf and leaflist cases to capture the arg_name arg_value for that node.
if (next->schema->nodetype != LYS_LEAF && next->schema->nodetype != LYS_LEAFLIST)
break;
case LYS_LEAF:
case LYS_LEAFLIST:
// TODO: add leaflist support.
// example of leaflist change:
// <bond-info yang:operation="none">
// <arp_ip_target yang:operation="create">1.1.1.1</arp_ip_target>
// <arp_ip_target yang:operation="create">2.4.4.4</arp_ip_target>
// <arp_ip_target yang:operation="create">2.2.2.2</arp_ip_target>
// </bond-info>
// char *leaf_list_separatot = NULL;
// arg_name = NULL;
// arg_value = NULL;
// get_extension(GROUP_LEAFS_VALUES_SEPARATOR_EXT,next,&leaf_list_separatot);
// // if the arg_name is not added to cmd, add it first
// if (next->priv == NULL){
// ret = create_cmd_arg_name(next, op_val, &arg_name);
// if (ret != EXIT_SUCCESS) {
// fprintf(stderr, "%s: failed to create create_cmd_arg_name for node \"%s\".\n",
// __func__, next->schema->name);
// return NULL;
// }
// if (arg_name){
// strlcat(cmd_line, " ", sizeof(cmd_line));
// strlcat(cmd_line, arg_name, sizeof(cmd_line));
// }
// // add all values
//
// }

case LYS_LEAF:
arg_name = NULL;
arg_value = NULL;
create_cmd_arg_value(next, op_val, &arg_value);
ret = create_cmd_arg_name(next, op_val, &arg_name);
if (ret != EXIT_SUCCESS) {
fprintf(stderr, "%s: failed to create create_cmd_arg_name for node \"%s\".\n",
__func__, next->schema->name);
return NULL;
}
ret = create_cmd_arg_value(next, op_val, &arg_value);
if (ret != EXIT_SUCCESS) {
fprintf(stderr, "%s: failed to create create_cmd_arg_value for node \"%s\".\n",
__func__, next->schema->name);
return NULL;
}
int is_tail_arg = 0;
if (get_extension(ADD_LEAF_AT_END, next, NULL) == EXIT_SUCCESS)
is_tail_arg = 1;
Expand Down
34 changes: 32 additions & 2 deletions yang/iproute2-ip-link.yang
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,18 @@ module iproute2-ip-link {
"vxcan device.";
}

identity erspan {
base link-type;
description
"erspan device.";
}

identity ip6erspan {
base link-type;
description
"erspan device.";
}

identity ether {
base oper-link-type;
description
Expand All @@ -253,6 +265,7 @@ module iproute2-ip-link {
"loopback device.";
}


/*
* groupings
*/
Expand Down Expand Up @@ -843,7 +856,7 @@ module iproute2-ip-link {
uses link-bridge;
container bond_slave {
ipr2cgen:add-static-arg "type bond_slave";
when "../master and /links/link[name=current()/../master]/type = 'iplink:bond'";
when "../master and /links/bond[name=current()/../master]";
description "set additional bonding related to link with master bond link";
leaf queue_id{
must "/links/link[name=current()/../../master]/type = 'iplink:bond'" {
Expand Down Expand Up @@ -1507,6 +1520,23 @@ module iproute2-ip-link {
description
"specify the active link in active-standby mode";
}
leaf primary {
ipr2cgen:not-dependency;
ipr2cgen:oper-stop-if "{\"mode\": [\"balance-rr\", \"802.3ad\", \"balance-xor\", \"broadcast\", \"balance-alb\", \"balance-tlb\"]}";
type link-ref;
must "../mode = 'active-backup'" {
error-message "'primary' support on active-backup bond mode only.";
}
description
"specifiy the primary physical link for the bond";

}
leaf arp_ip_target { // TODO: this should be leaflist, but still not supported.
ipr2cgen:oper-arg-name " "; // workaround to prevent processing in oper_data.
type inet:ip-address;
description
"Specifies the target IP address of ARP requests when the arp_interval parameter is enabled";
}
leaf miimon {
type uint32;
default 100;
Expand Down Expand Up @@ -1558,7 +1588,7 @@ module iproute2-ip-link {
"how often ARP monitoring occurs.";
}
leaf arp_validate {
ipr2cgen:oper-stop-if "{\"mode\": [\"802.3ad\", \"balance-tlb\", \"balance-alb\"]}";
ipr2cgen:oper-stop-if "{\"mode\": [\"802.3ad\", \"balance-tlb\", \"balance-alb\"]}";
must "(../mode = 'balance-rr') or (../mode = 'active-backup') or (../mode = 'balance-xor')
or (../mode = 'broadcast')" {
error-message "'arp_validate' is only supported on balance-rr, active-backup, balance-xor or broadcast bond modes.";
Expand Down

0 comments on commit e4257a2

Please sign in to comment.