Skip to content

Commit

Permalink
zebra: Add a feature to set initcwnd/rwnd value for route in route-map
Browse files Browse the repository at this point in the history
This feature adds support for setting the values of initcwnd and initrwnd attributes for any path using the functionality of route-map, similar to the 'set src xxx.xxx.xxx.xxx' command.

Signed-off-by: TAKADA Sokichi <[email protected]>
  • Loading branch information
soukichi committed Jun 9, 2023
1 parent f1128c8 commit 5e8729f
Show file tree
Hide file tree
Showing 15 changed files with 930 additions and 501 deletions.
2 changes: 2 additions & 0 deletions lib/nexthop.c
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,8 @@ void nexthop_copy_no_recurse(struct nexthop *copy,
memcpy(&copy->src, &nexthop->src, sizeof(nexthop->src));
memcpy(&copy->rmap_src, &nexthop->rmap_src, sizeof(nexthop->rmap_src));
copy->rparent = rparent;
copy->initcwnd = nexthop->initcwnd;
copy->initrwnd = nexthop->initrwnd;
if (nexthop->nh_label)
nexthop_add_labels(copy, nexthop->nh_label_type,
nexthop->nh_label->num_labels,
Expand Down
6 changes: 6 additions & 0 deletions lib/nexthop.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,12 @@ struct nexthop {

/* SRv6 information */
struct nexthop_srv6 *nh_srv6;

/* initial congestion window size */
uint32_t initcwnd;

/* initial advertised receive window size */
uint32_t initrwnd;
};

/* Utility to append one nexthop to another. */
Expand Down
2 changes: 2 additions & 0 deletions lib/routemap.h
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,8 @@ DECLARE_QOBJ_TYPE(route_map);
/* Zebra route-map set actions */
#define IS_SET_SRC(A) \
(strmatch(A, "frr-zebra-route-map:src-address"))
#define IS_SET_INITCWND(A) (strmatch(A, "frr-zebra-route-map:initcwnd"))
#define IS_SET_INITRWND(A) (strmatch(A, "frr-zebra-route-map:initrwnd"))
/* OSPF route-map set actions */
#define IS_SET_METRIC_TYPE(A) \
(strmatch(A, "frr-ospf-route-map:metric-type"))
Expand Down
11 changes: 11 additions & 0 deletions lib/routemap_cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -1112,6 +1112,17 @@ void route_map_action_show(struct vty *vty, const struct lyd_node *dnode,
yang_dnode_get_string(
dnode,
"./rmap-set-action/frr-zebra-route-map:ipv6-src-address"));
} else if (IS_SET_INITCWND(action)) {
Z vty_out(
vty, " set initcwnd %s\n",
yang_dnode_get_string(
dnode,
"./rmap-set-action/frr-zebra-route-map:initcwnd"));
} else if (IS_SET_INITRWND(action)) {
vty_out(vty, " set initrwnd %s\n",
yang_dnode_get_string(
dnode,
"./rmap-set-action/frr-zebra-route-map:initrwnd"));
} else if (IS_SET_METRIC_TYPE(action)) {
vty_out(vty, " set metric-type %s\n",
yang_dnode_get_string(
Expand Down
1,000 changes: 500 additions & 500 deletions tests/topotests/zebra_rib/r1/iproute.ref

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions tests/topotests/zebra_rib/r1/sharp_rmap.ref
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ route-map: sharp Invoked: 500 Optimization: enabled Processed Change: false
ip address 10
Set clauses:
src 192.168.214.1
initrwnd 22
Call clause:
Action:
Exit routemap
permit, sequence 20 Invoked 256
Match clauses:
Set clauses:
src 192.168.213.1
initcwnd 33
Call clause:
Action:
Exit routemap
2 changes: 2 additions & 0 deletions tests/topotests/zebra_rib/r1/static_rmap.ref
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ route-map: static Invoked: 2 Optimization: enabled Processed Change: false
Match clauses:
Set clauses:
src 192.168.215.1
initcwnd 30
initrwnd 30
Call clause:
Action:
Exit routemap
5 changes: 4 additions & 1 deletion tests/topotests/zebra_rib/test_zebra_rib.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,15 @@ def test_route_map_usage():
# set the delay timer to 1 to improve test coverage (HA)
r1.vtysh_cmd("conf\nzebra route-map delay-timer 1")
r1.vtysh_cmd("conf\nroute-map static permit 10\nset src 192.168.215.1")
r1.vtysh_cmd("conf\nroute-map static permit 10\nset initcwnd 30")
r1.vtysh_cmd("conf\nroute-map static permit 10\nset initrwnd 30")
r1.vtysh_cmd("conf\naccess-list 5 seq 5 permit 10.0.0.44/32")
r1.vtysh_cmd("conf\naccess-list 10 seq 5 permit 10.0.1.0/24")
r1.vtysh_cmd(
"conf\nroute-map sharp permit 10\nmatch ip address 10\nset src 192.168.214.1"
"conf\nroute-map sharp permit 10\nmatch ip address 10\nset src 192.168.214.1\nset initrwnd 22"
)
r1.vtysh_cmd("conf\nroute-map sharp permit 20\nset src 192.168.213.1")
r1.vtysh_cmd("conf\nroute-map sharp permit 20\nset initcwnd 33")
r1.vtysh_cmd("conf\nip protocol static route-map static")
r1.vtysh_cmd("conf\nip protocol sharp route-map sharp")
sleep(4)
Expand Down
30 changes: 30 additions & 0 deletions yang/frr-zebra-route-map.yang
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,18 @@ module frr-zebra-route-map {
"Set IPv4/IPv6 source address for route";
}

identity initcwnd {
base frr-route-map:rmap-set-type;
description
"Set initcwnd for route";
}

identity initrwnd {
base frr-route-map:rmap-set-type;
description
"Set initrwnd for route";
}

augment "/frr-route-map:lib"
+ "/frr-route-map:route-map"
+ "/frr-route-map:entry"
Expand Down Expand Up @@ -132,5 +144,23 @@ module frr-zebra-route-map {
}
}
}

case initcwnd {
when "derived-from-or-self(../frr-route-map:action, 'frr-zebra-route-map:initcwnd')";
leaf initcwnd {
type uint32 {
range "1..65535";
}
}
}

case initrwnd {
when "derived-from-or-self(../frr-route-map:action, 'frr-zebra-route-map:initrwnd')";
leaf initrwnd {
type uint32 {
range "1..65535";
}
}
}
}
}
68 changes: 68 additions & 0 deletions zebra/rt_netlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -2261,6 +2261,29 @@ ssize_t netlink_route_multipath_msg_encode(int cmd,
zlog_debug("%s: %pFX nhg_id is %u", __func__, p,
dplane_ctx_get_nhe_id(ctx));

if (nexthop->initcwnd || nexthop->initrwnd) {
struct rtattr *nnest;
nnest = nl_attr_nest(&req->n, datalen, RTA_METRICS);
if (nnest == NULL)
return 0;
if (nexthop->initcwnd) {
uint32_t initcwnd = nexthop->initcwnd;
if (!nl_attr_put(&req->n, datalen,
RTAX_INITCWND, &initcwnd,
sizeof(initcwnd)))
return 0;
}

if (nexthop->initrwnd) {
uint32_t initrwnd = nexthop->initrwnd;
if (!nl_attr_put(&req->n, datalen,
RTAX_INITRWND, &initrwnd,
sizeof(initrwnd)))
return 0;
}
nl_attr_nest_end(&req->n, nnest);
}

if (!nl_attr_put32(&req->n, datalen, RTA_NH_ID,
dplane_ctx_get_nhe_id(ctx)))
return 0;
Expand Down Expand Up @@ -2343,6 +2366,29 @@ ssize_t netlink_route_multipath_msg_encode(int cmd,
}
}

if (nexthop->initcwnd || nexthop->initrwnd) {
struct rtattr *nnest;
nnest = nl_attr_nest(&req->n, datalen, RTA_METRICS);
if (nnest == NULL)
return 0;
if (nexthop->initcwnd) {
uint32_t initcwnd = nexthop->initcwnd;
if (!nl_attr_put(&req->n, datalen,
RTAX_INITCWND, &initcwnd,
sizeof(initcwnd)))
return 0;
}

if (nexthop->initrwnd) {
uint32_t initrwnd = nexthop->initrwnd;
if (!nl_attr_put(&req->n, datalen,
RTAX_INITRWND, &initrwnd,
sizeof(initrwnd)))
return 0;
}
nl_attr_nest_end(&req->n, nnest);
}

if (setsrc) {
if (p->family == AF_INET) {
if (!nl_attr_put(&req->n, datalen, RTA_PREFSRC,
Expand Down Expand Up @@ -2416,6 +2462,28 @@ ssize_t netlink_route_multipath_msg_encode(int cmd,
}
}

if (nexthop->initcwnd || nexthop->initrwnd) {
struct rtattr *nnest;
nnest = nl_attr_nest(&req->n, datalen, RTA_METRICS);
if (nnest == NULL)
return 0;
if (nexthop->initcwnd) {
uint32_t initcwnd = nexthop->initcwnd;
if (!nl_attr_put(&req->n, datalen,
RTAX_INITCWND, &initcwnd,
sizeof(initcwnd)))
return 0;
}

if (nexthop->initrwnd) {
uint32_t initrwnd = nexthop->initrwnd;
if (!nl_attr_put(&req->n, datalen,
RTAX_INITRWND, &initrwnd,
sizeof(initrwnd)))
return 0;
}
nl_attr_nest_end(&req->n, nnest);
}

if (setsrc) {
if (p->family == AF_INET) {
Expand Down
Loading

0 comments on commit 5e8729f

Please sign in to comment.