#include "ldp_debug.h"
static void ifp2kif(struct interface *, struct kif *);
-static void ifc2kaddr(struct interface *, struct connected *,
- struct kaddr *);
+static void ifc2kaddr(struct interface *, struct connected *, struct kaddr *);
static int ldp_zebra_send_mpls_labels(int, struct kroute *);
static int ldp_router_id_update(ZAPI_CALLBACK_ARGS);
static int ldp_interface_address_add(ZAPI_CALLBACK_ARGS);
debug_zebra_out("pseudowire %s nexthop %s (add)",
zpw->ifname, log_addr(zpw->af, (union ldpd_addr *)&zpw->nexthop));
- return zebra_send_pw(zclient, ZEBRA_PW_ADD, zpw)
- == ZCLIENT_SEND_FAILURE;
+ return zebra_send_pw(zclient, ZEBRA_PW_ADD, zpw) == ZCLIENT_SEND_FAILURE;
}
int
debug_zebra_out("pseudowire %s nexthop %s (del)",
zpw->ifname, log_addr(zpw->af, (union ldpd_addr *)&zpw->nexthop));
- return zebra_send_pw(zclient, ZEBRA_PW_DELETE, zpw)
- == ZCLIENT_SEND_FAILURE;
+ return zebra_send_pw(zclient, ZEBRA_PW_DELETE, zpw) == ZCLIENT_SEND_FAILURE;
}
int
zpw->ifname, log_addr(zpw->af, (union ldpd_addr *)&zpw->nexthop),
zpw->local_label, zpw->remote_label);
- return zebra_send_pw(zclient, ZEBRA_PW_SET, zpw)
- == ZCLIENT_SEND_FAILURE;
+ return zebra_send_pw(zclient, ZEBRA_PW_SET, zpw) == ZCLIENT_SEND_FAILURE;
}
int
debug_zebra_out("pseudowire %s nexthop %s (unset)",
zpw->ifname, log_addr(zpw->af, (union ldpd_addr *)&zpw->nexthop));
- return zebra_send_pw(zclient, ZEBRA_PW_UNSET, zpw)
- == ZCLIENT_SEND_FAILURE;
+ return zebra_send_pw(zclient, ZEBRA_PW_UNSET, zpw) == ZCLIENT_SEND_FAILURE;
}
void
return (-1);
}
if (type == LDP_SOCKET_DISC) {
- if (sock_set_ipv4_mcast_ttl(fd,
- IP_DEFAULT_MULTICAST_TTL) == -1) {
+ if (sock_set_ipv4_mcast_ttl(fd, IP_DEFAULT_MULTICAST_TTL) == -1) {
close(fd);
return (-1);
}
close(fd);
return (-1);
}
- if (!(ldpd_conf->ipv6.flags & F_LDPD_AF_NO_GTSM)) {
+ if (!CHECK_FLAG(ldpd_conf->ipv6.flags, F_LDPD_AF_NO_GTSM)) {
/* ignore any possible error */
sock_set_ipv6_minhopcount(fd, 255);
}
#ifdef __OpenBSD__
opt = 1;
- if (setsockopt(fd, IPPROTO_TCP, TCP_MD5SIG, &opt,
- sizeof(opt)) == -1) {
+ if (setsockopt(fd, IPPROTO_TCP, TCP_MD5SIG, &opt, sizeof(opt)) == -1) {
if (errno == ENOPROTOOPT) { /* system w/o md5sig */
log_warnx("md5sig not available, disabling");
sysdep.no_md5sig = 1;
if ((flags = fcntl(fd, F_GETFL, 0)) == -1)
fatal("fcntl F_GETFL");
- flags |= O_NONBLOCK;
+ SET_FLAG(flags, O_NONBLOCK);
if (fcntl(fd, F_SETFL, flags) == -1)
fatal("fcntl F_SETFL");
if ((flags = fcntl(fd, F_GETFD, 0)) == -1)
fatal("fcntl F_GETFD");
- flags |= FD_CLOEXEC;
+ SET_FLAG(flags, FD_CLOEXEC);
if (fcntl(fd, F_SETFD, flags) == -1)
fatal("fcntl F_SETFD");
int bsize;
bsize = 65535;
- while (setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &bsize,
- sizeof(bsize)) == -1)
+ while (setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &bsize, sizeof(bsize)) == -1)
bsize /= 2;
}
int
sock_set_reuse(int fd, int enable)
{
- if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &enable,
- sizeof(int)) < 0) {
+ if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(int)) < 0) {
log_warn("%s: error setting SO_REUSEADDR", __func__);
return (-1);
}
{
#ifdef HAVE_SO_BINDANY
frr_with_privs(&ldpd_privs) {
- if (setsockopt(fd, SOL_SOCKET, SO_BINDANY, &enable,
- sizeof(int)) < 0) {
+ if (setsockopt(fd, SOL_SOCKET, SO_BINDANY, &enable, sizeof(int)) < 0) {
log_warn("%s: error setting SO_BINDANY", __func__);
return (-1);
}
return (0);
#elif defined(IP_BINDANY)
frr_with_privs(&ldpd_privs) {
- if (setsockopt(fd, IPPROTO_IP, IP_BINDANY, &enable, sizeof(int))
- < 0) {
+ if (setsockopt(fd, IPPROTO_IP, IP_BINDANY, &enable, sizeof(int)) < 0) {
log_warn("%s: error setting IP_BINDANY", __func__);
return (-1);
}
int
sock_set_ipv4_mcast_ttl(int fd, uint8_t ttl)
{
- if (setsockopt(fd, IPPROTO_IP, IP_MULTICAST_TTL,
- (char *)&ttl, sizeof(ttl)) < 0) {
- log_warn("%s: error setting IP_MULTICAST_TTL to %d",
- __func__, ttl);
+ if (setsockopt(fd, IPPROTO_IP, IP_MULTICAST_TTL, (char *)&ttl, sizeof(ttl)) < 0) {
+ log_warn("%s: error setting IP_MULTICAST_TTL to %d", __func__, ttl);
return (-1);
}
int
sock_set_ipv4_pktinfo(int fd, int enable)
{
- if (setsockopt(fd, IPPROTO_IP, IP_PKTINFO, &enable,
- sizeof(enable)) < 0) {
+ if (setsockopt(fd, IPPROTO_IP, IP_PKTINFO, &enable, sizeof(enable)) < 0) {
log_warn("%s: error setting IP_PKTINFO", __func__);
return (-1);
}
int
sock_set_ipv4_recvdstaddr(int fd, int enable)
{
- if (setsockopt(fd, IPPROTO_IP, IP_RECVDSTADDR, &enable,
- sizeof(enable)) < 0) {
+ if (setsockopt(fd, IPPROTO_IP, IP_RECVDSTADDR, &enable, sizeof(enable)) < 0) {
log_warn("%s: error setting IP_RECVDSTADDR", __func__);
return (-1);
}
int
sock_set_ipv6_dscp(int fd, int dscp)
{
- if (setsockopt(fd, IPPROTO_IPV6, IPV6_TCLASS, &dscp,
- sizeof(dscp)) < 0) {
+ if (setsockopt(fd, IPPROTO_IPV6, IPV6_TCLASS, &dscp, sizeof(dscp)) < 0) {
log_warn("%s: error setting IPV6_TCLASS", __func__);
return (-1);
}
int
sock_set_ipv6_pktinfo(int fd, int enable)
{
- if (setsockopt(fd, IPPROTO_IPV6, IPV6_RECVPKTINFO, &enable,
- sizeof(enable)) < 0) {
+ if (setsockopt(fd, IPPROTO_IPV6, IPV6_RECVPKTINFO, &enable, sizeof(enable)) < 0) {
log_warn("%s: error setting IPV6_RECVPKTINFO", __func__);
return (-1);
}
import pytest
import json
import tempfile
+from copy import deepcopy
from functools import partial
# Save the Current Working Directory to find configuration files.
# For all registered routers, load the zebra configuration file
for rname, router in router_list.items():
- router.load_config( TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)))
- router.load_config( TopoRouter.RD_ISIS, os.path.join(CWD, "{}/isisd.conf".format(rname)))
+ router.load_config(
+ TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname))
+ )
+ router.load_config(
+ TopoRouter.RD_ISIS, os.path.join(CWD, "{}/isisd.conf".format(rname))
+ )
tgen.start_router()
return tgen
+def router_json_cmp_exact_filter(router, cmd, expected):
+ output = router.vtysh_cmd(cmd)
+ logger.info("{}: {}\n{}".format(router.name, cmd, output))
+
+ json_output = json.loads(output)
+ router_output = deepcopy(json_output)
+
+ # filter out dynamic data from "show mpls table"
+ for label, data in json_output.items():
+ if "1500" in label:
+ # filter out SR local labels
+ router_output.pop(label)
+ continue
+ nexthops = data.get("nexthops", [])
+ for i in range(len(nexthops)):
+ if "fe80::" in nexthops[i].get("nexthop"):
+ router_output.get(label).get("nexthops")[i].pop("nexthop")
+ elif "." in nexthops[i].get("nexthop"):
+ # IPv4, just checking the nexthop
+ router_output.get(label).get("nexthops")[i].pop("interface")
+
+ return topotest.json_cmp(router_output, expected, exact=True)
+
+
def router_compare_json_output(rname, command, reference):
"Compare router JSON output"
expected = json.loads(reference)
# Run test function until we get an result. Wait at most 60 seconds.
- test_func = partial(topotest.router_json_cmp, tgen.gears[rname], command, expected)
+ test_func = partial(
+ router_json_cmp_exact_filter, tgen.gears[rname], command, expected
+ )
_, diff = topotest.run_and_expect(test_func, None, count=120, wait=0.5)
assertmsg = '"{}" JSON output mismatches the expected result'.format(rname)
assert diff is None, assertmsg
tgen = get_topogen()
# Run test function until we get an result. Wait at most 60 seconds.
- test_func = partial(topotest.router_output_cmp, tgen.gears[rname], command, reference)
+ test_func = partial(
+ topotest.router_output_cmp, tgen.gears[rname], command, reference
+ )
result, diff = topotest.run_and_expect(test_func, "", count=120, wait=0.5)
- assertmsg = '{} command "{}" output mismatches the expected result:\n{}'.format(rname, command, diff)
+ assertmsg = '{} command "{}" output mismatches the expected result:\n{}'.format(
+ rname, command, diff
+ )
assert result, assertmsg
# tgen.mininet_cli()
for rname in ["rt1", "rt2", "rt3"]:
router_compare_output(
- rname, "show isis flex-algo",
- outputs[rname][1]["show_isis_flex_algo.ref"])
+ rname, "show isis flex-algo", outputs[rname][1]["show_isis_flex_algo.ref"]
+ )
router_compare_json_output(
- rname, "show mpls table json",
- outputs[rname][1]["show_mpls_table.ref"])
+ rname, "show mpls table json", outputs[rname][1]["show_mpls_table.ref"]
+ )
#
router isis 1
flex-algo 203
no advertise-definition
- """)
+ """
+ )
# For Developers
# tgen.mininet_cli()
for rname in ["rt1", "rt2", "rt3"]:
router_compare_output(
- rname, "show isis flex-algo",
- outputs[rname][2]["show_isis_flex_algo.ref"])
+ rname, "show isis flex-algo", outputs[rname][2]["show_isis_flex_algo.ref"]
+ )
router_compare_json_output(
- rname, "show mpls table json",
- outputs[rname][2]["show_mpls_table.ref"])
+ rname, "show mpls table json", outputs[rname][2]["show_mpls_table.ref"]
+ )
#
router isis 1
flex-algo 203
no advertise-definition
- """)
+ """
+ )
# For Developers
# tgen.mininet_cli()
for rname in ["rt1", "rt2", "rt3"]:
router_compare_output(
- rname, "show isis flex-algo",
- outputs[rname][3]["show_isis_flex_algo.ref"])
+ rname, "show isis flex-algo", outputs[rname][3]["show_isis_flex_algo.ref"]
+ )
router_compare_json_output(
- rname, "show mpls table json",
- outputs[rname][3]["show_mpls_table.ref"])
+ rname, "show mpls table json", outputs[rname][3]["show_mpls_table.ref"]
+ )
#
router isis 1
flex-algo 203
advertise-definition
- """)
+ """
+ )
# For Developers
# tgen.mininet_cli()
for rname in ["rt1", "rt2", "rt3"]:
router_compare_output(
- rname, "show isis flex-algo",
- outputs[rname][4]["show_isis_flex_algo.ref"])
+ rname, "show isis flex-algo", outputs[rname][4]["show_isis_flex_algo.ref"]
+ )
router_compare_json_output(
- rname, "show mpls table json",
- outputs[rname][4]["show_mpls_table.ref"])
+ rname, "show mpls table json", outputs[rname][4]["show_mpls_table.ref"]
+ )
#
router isis 1
flex-algo 203
advertise-definition
- """)
+ """
+ )
# For Developers
# tgen.mininet_cli()
for rname in ["rt1", "rt2", "rt3"]:
router_compare_output(
- rname, "show isis flex-algo",
- outputs[rname][5]["show_isis_flex_algo.ref"])
+ rname, "show isis flex-algo", outputs[rname][5]["show_isis_flex_algo.ref"]
+ )
router_compare_json_output(
- rname, "show mpls table json",
- outputs[rname][5]["show_mpls_table.ref"])
+ rname, "show mpls table json", outputs[rname][5]["show_mpls_table.ref"]
+ )
#
router isis 1
flex-algo 203
no dataplane sr-mpls
- """)
+ """
+ )
# For Developers
# tgen.mininet_cli()
for rname in ["rt1", "rt2", "rt3"]:
router_compare_output(
- rname, "show isis flex-algo",
- outputs[rname][6]["show_isis_flex_algo.ref"])
+ rname, "show isis flex-algo", outputs[rname][6]["show_isis_flex_algo.ref"]
+ )
router_compare_json_output(
- rname, "show mpls table json",
- outputs[rname][6]["show_mpls_table.ref"])
+ rname, "show mpls table json", outputs[rname][6]["show_mpls_table.ref"]
+ )
#
configure terminal
router isis 1
no flex-algo 203
- """)
+ """
+ )
# For Developers
# tgen.mininet_cli()
for rname in ["rt1", "rt2", "rt3"]:
router_compare_output(
- rname, "show isis flex-algo",
- outputs[rname][7]["show_isis_flex_algo.ref"])
+ rname, "show isis flex-algo", outputs[rname][7]["show_isis_flex_algo.ref"]
+ )
router_compare_json_output(
- rname, "show mpls table json",
- outputs[rname][7]["show_mpls_table.ref"])
+ rname, "show mpls table json", outputs[rname][7]["show_mpls_table.ref"]
+ )
+
#
# Step 8
advertise-definition
affinity exclude-any green
dataplane sr-mpls
- """)
+ """
+ )
tgen.gears["rt2"].vtysh_cmd(
"""
advertise-definition
affinity exclude-any green
dataplane sr-mpls
- """)
+ """
+ )
tgen.gears["rt3"].vtysh_cmd(
"""
router isis 1
flex-algo 203
dataplane sr-mpls
- """)
+ """
+ )
# For Developers
# tgen.mininet_cli()
for rname in ["rt1", "rt2", "rt3"]:
router_compare_output(
- rname, "show isis flex-algo",
- outputs[rname][8]["show_isis_flex_algo.ref"])
+ rname, "show isis flex-algo", outputs[rname][8]["show_isis_flex_algo.ref"]
+ )
router_compare_json_output(
- rname, "show mpls table json",
- outputs[rname][8]["show_mpls_table.ref"])
+ rname, "show mpls table json", outputs[rname][8]["show_mpls_table.ref"]
+ )
#
router isis 1
no segment-routing prefix 1.1.1.1/32 algorithm 203 index 301
no segment-routing prefix 2001:db8:1000::1/128 algorithm 203 index 1301
- """)
+ """
+ )
# For Developers
# tgen.mininet_cli()
for rname in ["rt1", "rt2", "rt3"]:
router_compare_output(
- rname, "show isis flex-algo",
- outputs[rname][9]["show_isis_flex_algo.ref"])
+ rname, "show isis flex-algo", outputs[rname][9]["show_isis_flex_algo.ref"]
+ )
router_compare_json_output(
- rname, "show mpls table json",
- outputs[rname][9]["show_mpls_table.ref"])
+ rname, "show mpls table json", outputs[rname][9]["show_mpls_table.ref"]
+ )
#
router isis 1
segment-routing prefix 1.1.1.1/32 algorithm 203 index 301
segment-routing prefix 2001:db8:1000::1/128 algorithm 203 index 1301
- """)
+ """
+ )
# For Developers
# tgen.mininet_cli()
for rname in ["rt1", "rt2", "rt3"]:
router_compare_output(
- rname, "show isis flex-algo",
- outputs[rname][10]["show_isis_flex_algo.ref"])
+ rname, "show isis flex-algo", outputs[rname][10]["show_isis_flex_algo.ref"]
+ )
router_compare_json_output(
- rname, "show mpls table json",
- outputs[rname][10]["show_mpls_table.ref"])
+ rname, "show mpls table json", outputs[rname][10]["show_mpls_table.ref"]
+ )
#
router isis 1
segment-routing prefix 1.1.1.1/32 algorithm 203 index 311
segment-routing prefix 2001:db8:1000::1/128 algorithm 203 index 1311
- """)
+ """
+ )
# For Developers
# tgen.mininet_cli()
for rname in ["rt1", "rt2", "rt3"]:
router_compare_output(
- rname, "show isis flex-algo",
- outputs[rname][11]["show_isis_flex_algo.ref"])
+ rname, "show isis flex-algo", outputs[rname][11]["show_isis_flex_algo.ref"]
+ )
router_compare_json_output(
- rname, "show mpls table json",
- outputs[rname][11]["show_mpls_table.ref"])
+ rname, "show mpls table json", outputs[rname][11]["show_mpls_table.ref"]
+ )
if __name__ == "__main__":