summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.clang-format14
-rw-r--r--.github/workflows/commitlint.yml5
-rw-r--r--Makefile.am21
-rw-r--r--alpine/APKBUILD.in6
-rw-r--r--babeld/babel_main.c4
-rw-r--r--babeld/babel_main.h2
-rw-r--r--babeld/babeld.c92
-rw-r--r--babeld/babeld.h8
-rw-r--r--babeld/kernel.c2
-rw-r--r--babeld/util.h9
-rw-r--r--bfdd/bfd.c52
-rw-r--r--bfdd/bfd.h34
-rw-r--r--bfdd/bfd_packet.c50
-rw-r--r--bfdd/bfdd.c6
-rw-r--r--bfdd/control.c46
-rw-r--r--bfdd/dplane.c78
-rw-r--r--bfdd/event.c22
-rw-r--r--bgpd/bgp_advertise.c2
-rw-r--r--bgpd/bgp_aspath.c14
-rw-r--r--bgpd/bgp_attr.c196
-rw-r--r--bgpd/bgp_bfd.c6
-rw-r--r--bgpd/bgp_bfd.h2
-rw-r--r--bgpd/bgp_bmp.c88
-rw-r--r--bgpd/bgp_bmp.h8
-rw-r--r--bgpd/bgp_community.c4
-rw-r--r--bgpd/bgp_community_alias.c6
-rw-r--r--bgpd/bgp_conditional_adv.c16
-rw-r--r--bgpd/bgp_damp.c16
-rw-r--r--bgpd/bgp_damp.h2
-rw-r--r--bgpd/bgp_dump.c23
-rw-r--r--bgpd/bgp_ecommunity.c33
-rw-r--r--bgpd/bgp_evpn.c88
-rw-r--r--bgpd/bgp_evpn.h2
-rw-r--r--bgpd/bgp_evpn_mh.c35
-rw-r--r--bgpd/bgp_evpn_mh.h2
-rw-r--r--bgpd/bgp_evpn_private.h8
-rw-r--r--bgpd/bgp_evpn_vty.c10
-rw-r--r--bgpd/bgp_flowspec.c9
-rw-r--r--bgpd/bgp_flowspec.h2
-rw-r--r--bgpd/bgp_fsm.c315
-rw-r--r--bgpd/bgp_fsm.h35
-rw-r--r--bgpd/bgp_io.c48
-rw-r--r--bgpd/bgp_keepalives.c11
-rw-r--r--bgpd/bgp_label.c6
-rw-r--r--bgpd/bgp_labelpool.c10
-rw-r--r--bgpd/bgp_labelpool.h2
-rw-r--r--bgpd/bgp_lcommunity.c4
-rw-r--r--bgpd/bgp_mac.c3
-rw-r--r--bgpd/bgp_main.c2
-rw-r--r--bgpd/bgp_mplsvpn.c14
-rw-r--r--bgpd/bgp_mplsvpn_snmp.c15
-rw-r--r--bgpd/bgp_network.c38
-rw-r--r--bgpd/bgp_network.h2
-rw-r--r--bgpd/bgp_nexthop.c14
-rw-r--r--bgpd/bgp_nht.c16
-rw-r--r--bgpd/bgp_open.c16
-rw-r--r--bgpd/bgp_packet.c44
-rw-r--r--bgpd/bgp_packet.h32
-rw-r--r--bgpd/bgp_pbr.c22
-rw-r--r--bgpd/bgp_route.c328
-rw-r--r--bgpd/bgp_route.h13
-rw-r--r--bgpd/bgp_routemap.c47
-rw-r--r--bgpd/bgp_routemap_nb_config.c10
-rw-r--r--bgpd/bgp_rpki.c43
-rw-r--r--bgpd/bgp_snmp.c4
-rw-r--r--bgpd/bgp_snmp_bgp4.c4
-rw-r--r--bgpd/bgp_snmp_bgp4.h2
-rw-r--r--bgpd/bgp_snmp_bgp4v2.c4
-rw-r--r--bgpd/bgp_snmp_bgp4v2.h2
-rw-r--r--bgpd/bgp_table.h2
-rw-r--r--bgpd/bgp_updgrp.c52
-rw-r--r--bgpd/bgp_updgrp.h6
-rw-r--r--bgpd/bgp_updgrp_adv.c35
-rw-r--r--bgpd/bgp_updgrp_packet.c2
-rw-r--r--bgpd/bgp_vty.c209
-rw-r--r--bgpd/bgp_zebra.c91
-rw-r--r--bgpd/bgp_zebra.h6
-rw-r--r--bgpd/bgpd.c113
-rw-r--r--bgpd/bgpd.h71
-rw-r--r--bgpd/rfapi/rfapi.h3
-rw-r--r--bgpd/rfapi/rfapi_backend.h2
-rw-r--r--bgpd/rfapi/rfapi_import.c117
-rw-r--r--bgpd/rfapi/rfapi_import.h2
-rw-r--r--bgpd/rfapi/rfapi_monitor.c32
-rw-r--r--bgpd/rfapi/rfapi_monitor.h4
-rw-r--r--bgpd/rfapi/rfapi_rib.c43
-rw-r--r--bgpd/rfapi/rfapi_rib.h2
-rw-r--r--bgpd/rfapi/rfapi_vty.c35
-rw-r--r--bgpd/rfapi/vnc_export_bgp.c14
-rw-r--r--bgpd/rfapi/vnc_export_table.h4
-rw-r--r--bgpd/rfapi/vnc_import_bgp.c9
-rw-r--r--bgpd/rfapi/vnc_zebra.c2
-rw-r--r--bgpd/rfp-example/librfp/rfp_example.c4
-rw-r--r--configure.ac77
-rw-r--r--debian/frr.install1
-rw-r--r--doc/developer/building-frr-for-centos6.rst2
-rw-r--r--doc/developer/building-frr-for-centos7.rst2
-rw-r--r--doc/developer/building-frr-for-centos8.rst3
-rw-r--r--doc/developer/building-frr-for-debian8.rst2
-rw-r--r--doc/developer/building-frr-for-debian9.rst3
-rw-r--r--doc/developer/building-frr-for-fedora.rst2
-rw-r--r--doc/developer/building-frr-for-freebsd10.rst3
-rw-r--r--doc/developer/building-frr-for-freebsd11.rst3
-rw-r--r--doc/developer/building-frr-for-freebsd9.rst2
-rw-r--r--doc/developer/building-frr-for-netbsd6.rst3
-rw-r--r--doc/developer/building-frr-for-netbsd7.rst3
-rw-r--r--doc/developer/building-frr-for-openbsd6.rst2
-rw-r--r--doc/developer/building-frr-for-opensuse.rst2
-rw-r--r--doc/developer/building-frr-for-ubuntu1404.rst7
-rw-r--r--doc/developer/building-frr-for-ubuntu1604.rst9
-rw-r--r--doc/developer/cli.rst46
-rw-r--r--doc/developer/frr-release-procedure.rst24
-rw-r--r--doc/developer/logging.rst53
-rw-r--r--doc/developer/modules.rst4
-rw-r--r--doc/developer/path-internals-pcep.rst2
-rw-r--r--doc/developer/process-architecture.rst36
-rw-r--r--doc/developer/rcu.rst2
-rw-r--r--doc/developer/topotests.rst6
-rw-r--r--doc/developer/tracing.rst4
-rw-r--r--doc/developer/workflow.rst2
-rw-r--r--doc/manpages/vtysh.rst9
-rw-r--r--doc/user/basic.rst4
-rw-r--r--doc/user/bgp.rst13
-rw-r--r--doc/user/index.rst1
-rw-r--r--doc/user/isisd.rst8
-rw-r--r--doc/user/mgmtd.rst366
-rw-r--r--doc/user/ospfd.rst51
-rw-r--r--doc/user/overview.rst2
-rw-r--r--doc/user/routemap.rst4
-rw-r--r--doc/user/subdir.am1
-rw-r--r--docker/alpine/Dockerfile1
-rw-r--r--docker/centos-7/Dockerfile1
-rw-r--r--docker/centos-8/Dockerfile1
-rw-r--r--docker/debian/Dockerfile2
-rw-r--r--docker/ubuntu18-ci/Dockerfile2
-rw-r--r--docker/ubuntu20-ci/Dockerfile2
-rw-r--r--eigrpd/eigrp_dump.c4
-rw-r--r--eigrpd/eigrp_filter.c22
-rw-r--r--eigrpd/eigrp_filter.h4
-rw-r--r--eigrpd/eigrp_fsm.c2
-rw-r--r--eigrpd/eigrp_hello.c24
-rw-r--r--eigrpd/eigrp_interface.c10
-rw-r--r--eigrpd/eigrp_macros.h2
-rw-r--r--eigrpd/eigrp_main.c4
-rw-r--r--eigrpd/eigrp_neighbor.c28
-rw-r--r--eigrpd/eigrp_neighbor.h2
-rw-r--r--eigrpd/eigrp_network.c2
-rw-r--r--eigrpd/eigrp_network.h2
-rw-r--r--eigrpd/eigrp_packet.c56
-rw-r--r--eigrpd/eigrp_packet.h12
-rw-r--r--eigrpd/eigrp_query.c2
-rw-r--r--eigrpd/eigrp_reply.c2
-rw-r--r--eigrpd/eigrp_siaquery.c2
-rw-r--r--eigrpd/eigrp_siareply.c2
-rw-r--r--eigrpd/eigrp_snmp.c2
-rw-r--r--eigrpd/eigrp_structs.h16
-rw-r--r--eigrpd/eigrp_update.c14
-rw-r--r--eigrpd/eigrp_vty.c2
-rw-r--r--eigrpd/eigrp_zebra.c4
-rw-r--r--eigrpd/eigrpd.c8
-rw-r--r--eigrpd/eigrpd.h4
-rw-r--r--gdb/lib.txt2
-rw-r--r--isisd/fabricd.c68
-rw-r--r--isisd/isis_adjacency.c68
-rw-r--r--isisd/isis_adjacency.h8
-rw-r--r--isisd/isis_bfd.c2
-rw-r--r--isisd/isis_bfd.h4
-rw-r--r--isisd/isis_circuit.c101
-rw-r--r--isisd/isis_circuit.h27
-rw-r--r--isisd/isis_cli.c53
-rw-r--r--isisd/isis_common.h8
-rw-r--r--isisd/isis_csm.c2
-rw-r--r--isisd/isis_dr.c64
-rw-r--r--isisd/isis_dr.h2
-rw-r--r--isisd/isis_dynhn.c22
-rw-r--r--isisd/isis_events.c44
-rw-r--r--isisd/isis_events.h2
-rw-r--r--isisd/isis_ldp_sync.c21
-rw-r--r--isisd/isis_lfa.c20
-rw-r--r--isisd/isis_lsp.c222
-rw-r--r--isisd/isis_lsp.h4
-rw-r--r--isisd/isis_main.c16
-rw-r--r--isisd/isis_misc.c107
-rw-r--r--isisd/isis_misc.h6
-rw-r--r--isisd/isis_mt.c15
-rw-r--r--isisd/isis_nb.c7
-rw-r--r--isisd/isis_nb.h3
-rw-r--r--isisd/isis_nb_config.c30
-rw-r--r--isisd/isis_nb_notifications.c36
-rw-r--r--isisd/isis_nb_state.c10
-rw-r--r--isisd/isis_pdu.c270
-rw-r--r--isisd/isis_pdu.h12
-rw-r--r--isisd/isis_pdu_counter.c22
-rw-r--r--isisd/isis_pdu_counter.h2
-rw-r--r--isisd/isis_pfpacket.c27
-rw-r--r--isisd/isis_route.c2
-rw-r--r--isisd/isis_routemap.c2
-rw-r--r--isisd/isis_snmp.c120
-rw-r--r--isisd/isis_spf.c45
-rw-r--r--isisd/isis_sr.c26
-rw-r--r--isisd/isis_sr.h2
-rw-r--r--isisd/isis_te.c39
-rw-r--r--isisd/isis_tlvs.c102
-rw-r--r--isisd/isis_tx_queue.c36
-rw-r--r--isisd/isis_zebra.c4
-rw-r--r--isisd/isis_zebra.h2
-rw-r--r--isisd/isisd.c97
-rw-r--r--isisd/isisd.h26
-rw-r--r--ldpd/accept.c32
-rw-r--r--ldpd/adjacency.c30
-rw-r--r--ldpd/control.c22
-rw-r--r--ldpd/interface.c28
-rw-r--r--ldpd/lde.c38
-rw-r--r--ldpd/lde.h4
-rw-r--r--ldpd/lde_lib.c11
-rw-r--r--ldpd/ldp_snmp.c4
-rw-r--r--ldpd/ldp_zebra.c40
-rw-r--r--ldpd/ldpd.c68
-rw-r--r--ldpd/ldpd.h34
-rw-r--r--ldpd/ldpe.c64
-rw-r--r--ldpd/ldpe.h22
-rw-r--r--ldpd/neighbor.c63
-rw-r--r--ldpd/packet.c46
-rw-r--r--lib/agentx.c42
-rw-r--r--lib/bfd.c30
-rw-r--r--lib/bfd.h5
-rw-r--r--lib/clippy.c48
-rw-r--r--lib/command.c8
-rw-r--r--lib/command.h5
-rw-r--r--lib/compiler.h8
-rw-r--r--lib/cspf.c2
-rw-r--r--lib/cspf.h2
-rw-r--r--lib/defun_lex.l19
-rw-r--r--lib/distribute.c15
-rw-r--r--lib/event.c (renamed from lib/thread.c)613
-rw-r--r--lib/ferr.c4
-rw-r--r--lib/filter_cli.c8
-rw-r--r--lib/filter_nb.c75
-rw-r--r--lib/frr_pthread.c20
-rw-r--r--lib/frr_pthread.h4
-rw-r--r--lib/frr_zmq.c77
-rw-r--r--lib/frr_zmq.h53
-rw-r--r--lib/frrevent.h295
-rw-r--r--lib/frrscript.c6
-rw-r--r--lib/getopt.c1011
-rw-r--r--lib/getopt.h143
-rw-r--r--lib/getopt1.c163
-rw-r--r--lib/grammar_sandbox_main.c10
-rw-r--r--lib/hash.c10
-rw-r--r--lib/hash.h11
-rw-r--r--lib/if_rmap.c17
-rw-r--r--lib/iso.c144
-rw-r--r--lib/iso.h49
-rw-r--r--lib/ldp_sync.c4
-rw-r--r--lib/ldp_sync.h2
-rw-r--r--lib/lib_vty.c11
-rw-r--r--lib/libfrr.c42
-rw-r--r--lib/libfrr.h16
-rw-r--r--lib/libfrr_trace.h12
-rw-r--r--lib/link_state.c24
-rw-r--r--lib/link_state.h4
-rw-r--r--lib/log.c24
-rw-r--r--lib/log.h1
-rw-r--r--lib/mgmt.proto331
-rw-r--r--lib/mgmt_be_client.c1219
-rw-r--r--lib/mgmt_be_client.h260
-rw-r--r--lib/mgmt_fe_client.c1072
-rw-r--r--lib/mgmt_fe_client.h346
-rw-r--r--lib/mgmt_msg.c414
-rw-r--r--lib/mgmt_msg.h73
-rw-r--r--lib/mgmt_pb.h25
-rw-r--r--lib/northbound.c308
-rw-r--r--lib/northbound.h226
-rw-r--r--lib/northbound_cli.c123
-rw-r--r--lib/northbound_cli.h2
-rw-r--r--lib/northbound_confd.c50
-rw-r--r--lib/northbound_grpc.cpp26
-rw-r--r--lib/northbound_sysrepo.c25
-rw-r--r--lib/prefix.c2
-rw-r--r--lib/prefix.h5
-rw-r--r--lib/pullwr.c25
-rw-r--r--lib/pullwr.h10
-rw-r--r--lib/qobj.c2
-rw-r--r--lib/resolver.c60
-rw-r--r--lib/resolver.h6
-rw-r--r--lib/routemap.c87
-rw-r--r--lib/sigevent.c17
-rw-r--r--lib/sigevent.h6
-rw-r--r--lib/smux.h4
-rw-r--r--lib/spf_backoff.c46
-rw-r--r--lib/spf_backoff.h4
-rw-r--r--lib/subdir.am36
-rw-r--r--lib/systemd.c12
-rw-r--r--lib/systemd.h4
-rw-r--r--lib/thread.h291
-rw-r--r--lib/vrf.c6
-rw-r--r--lib/vty.c582
-rw-r--r--lib/vty.h55
-rw-r--r--lib/wheel.c32
-rw-r--r--lib/wheel.h6
-rw-r--r--lib/workqueue.c39
-rw-r--r--lib/workqueue.h8
-rw-r--r--lib/xref.h2
-rw-r--r--lib/yang.c7
-rw-r--r--lib/yang.h2
-rw-r--r--lib/zclient.c48
-rw-r--r--lib/zclient.h10
-rw-r--r--lib/zlog.c4
-rw-r--r--lib/zlog_5424.c26
-rw-r--r--lib/zlog_5424.h8
-rw-r--r--lib/zlog_5424_cli.c6
-rw-r--r--mgmtd/.gitignore1
-rw-r--r--mgmtd/Makefile10
-rw-r--r--mgmtd/mgmt.c84
-rw-r--r--mgmtd/mgmt.h117
-rw-r--r--mgmtd/mgmt_be_adapter.c1094
-rw-r--r--mgmtd/mgmt_be_adapter.h219
-rw-r--r--mgmtd/mgmt_be_server.c160
-rw-r--r--mgmtd/mgmt_be_server.h20
-rw-r--r--mgmtd/mgmt_defines.h60
-rw-r--r--mgmtd/mgmt_ds.c645
-rw-r--r--mgmtd/mgmt_ds.h372
-rw-r--r--mgmtd/mgmt_fe_adapter.c1902
-rw-r--r--mgmtd/mgmt_fe_adapter.h183
-rw-r--r--mgmtd/mgmt_fe_server.c160
-rw-r--r--mgmtd/mgmt_fe_server.h20
-rw-r--r--mgmtd/mgmt_history.c380
-rw-r--r--mgmtd/mgmt_history.h57
-rw-r--r--mgmtd/mgmt_main.c287
-rw-r--r--mgmtd/mgmt_memory.c36
-rw-r--r--mgmtd/mgmt_memory.h28
-rw-r--r--mgmtd/mgmt_txn.c2835
-rw-r--r--mgmtd/mgmt_txn.h267
-rw-r--r--mgmtd/mgmt_vty.c534
-rw-r--r--mgmtd/subdir.am68
-rw-r--r--nhrpd/debug.h8
-rw-r--r--nhrpd/netlink_arp.c18
-rw-r--r--nhrpd/nhrp_cache.c42
-rw-r--r--nhrpd/nhrp_event.c46
-rw-r--r--nhrpd/nhrp_interface.c2
-rw-r--r--nhrpd/nhrp_main.c4
-rw-r--r--nhrpd/nhrp_multicast.c19
-rw-r--r--nhrpd/nhrp_nhs.c60
-rw-r--r--nhrpd/nhrp_packet.c10
-rw-r--r--nhrpd/nhrp_peer.c57
-rw-r--r--nhrpd/nhrp_shortcut.c44
-rw-r--r--nhrpd/nhrp_vc.c2
-rw-r--r--nhrpd/nhrpd.h16
-rw-r--r--nhrpd/vici.c42
-rw-r--r--ospf6d/ospf6_abr.c18
-rw-r--r--ospf6d/ospf6_area.c6
-rw-r--r--ospf6d/ospf6_area.h4
-rw-r--r--ospf6d/ospf6_asbr.c57
-rw-r--r--ospf6d/ospf6_bfd.c6
-rw-r--r--ospf6d/ospf6_flood.c87
-rw-r--r--ospf6d/ospf6_gr.c33
-rw-r--r--ospf6d/ospf6_gr_helper.c31
-rw-r--r--ospf6d/ospf6_interface.c169
-rw-r--r--ospf6d/ospf6_interface.h28
-rw-r--r--ospf6d/ospf6_intra.c22
-rw-r--r--ospf6d/ospf6_intra.h56
-rw-r--r--ospf6d/ospf6_lsa.c28
-rw-r--r--ospf6d/ospf6_lsa.h8
-rw-r--r--ospf6d/ospf6_lsdb.c31
-rw-r--r--ospf6d/ospf6_lsdb.h3
-rw-r--r--ospf6d/ospf6_main.c4
-rw-r--r--ospf6d/ospf6_message.c257
-rw-r--r--ospf6d/ospf6_message.h20
-rw-r--r--ospf6d/ospf6_neighbor.c213
-rw-r--r--ospf6d/ospf6_neighbor.h38
-rw-r--r--ospf6d/ospf6_network.h10
-rw-r--r--ospf6d/ospf6_nssa.c26
-rw-r--r--ospf6d/ospf6_snmp.c2
-rw-r--r--ospf6d/ospf6_spf.c22
-rw-r--r--ospf6d/ospf6_top.c47
-rw-r--r--ospf6d/ospf6_top.h22
-rw-r--r--ospf6d/ospf6_zebra.c2
-rw-r--r--ospf6d/ospf6_zebra.h2
-rw-r--r--ospf6d/ospf6d.c4
-rw-r--r--ospf6d/ospf6d.h6
-rw-r--r--ospfclient/ospf_apiclient.c2
-rw-r--r--ospfclient/ospfclient.c36
-rw-r--r--ospfd/ospf_abr.c346
-rw-r--r--ospfd/ospf_abr.h25
-rw-r--r--ospfd/ospf_api.c2
-rw-r--r--ospfd/ospf_apiserver.c69
-rw-r--r--ospfd/ospf_apiserver.h16
-rw-r--r--ospfd/ospf_asbr.c39
-rw-r--r--ospfd/ospf_ase.c10
-rw-r--r--ospfd/ospf_bfd.c4
-rw-r--r--ospfd/ospf_bfd.h2
-rw-r--r--ospfd/ospf_dump.c4
-rw-r--r--ospfd/ospf_dump.h12
-rw-r--r--ospfd/ospf_ext.c2
-rw-r--r--ospfd/ospf_flood.c2
-rw-r--r--ospfd/ospf_gr.c12
-rw-r--r--ospfd/ospf_gr.h2
-rw-r--r--ospfd/ospf_gr_helper.c20
-rw-r--r--ospfd/ospf_ia.c2
-rw-r--r--ospfd/ospf_interface.c13
-rw-r--r--ospfd/ospf_interface.h12
-rw-r--r--ospfd/ospf_ism.c38
-rw-r--r--ospfd/ospf_ism.h16
-rw-r--r--ospfd/ospf_ldp_sync.c19
-rw-r--r--ospfd/ospf_lsa.c179
-rw-r--r--ospfd/ospf_lsa.h11
-rw-r--r--ospfd/ospf_main.c4
-rw-r--r--ospfd/ospf_neighbor.c16
-rw-r--r--ospfd/ospf_neighbor.h10
-rw-r--r--ospfd/ospf_network.c28
-rw-r--r--ospfd/ospf_network.h10
-rw-r--r--ospfd/ospf_nsm.c55
-rw-r--r--ospfd/ospf_nsm.h16
-rw-r--r--ospfd/ospf_opaque.c79
-rw-r--r--ospfd/ospf_packet.c164
-rw-r--r--ospfd/ospf_packet.h10
-rw-r--r--ospfd/ospf_ri.c2
-rw-r--r--ospfd/ospf_route.c14
-rw-r--r--ospfd/ospf_route.h5
-rw-r--r--ospfd/ospf_routemap.c8
-rw-r--r--ospfd/ospf_snmp.c4
-rw-r--r--ospfd/ospf_spf.c13
-rw-r--r--ospfd/ospf_sr.c17
-rw-r--r--ospfd/ospf_sr.h2
-rw-r--r--ospfd/ospf_te.c22
-rw-r--r--ospfd/ospf_ti_lfa.c24
-rw-r--r--ospfd/ospf_vty.c1065
-rw-r--r--ospfd/ospf_zebra.c88
-rw-r--r--ospfd/ospf_zebra.h3
-rw-r--r--ospfd/ospfd.c203
-rw-r--r--ospfd/ospfd.h95
-rw-r--r--pathd/path_main.c4
-rw-r--r--pathd/path_pcep.c6
-rw-r--r--pathd/path_pcep.h2
-rw-r--r--pathd/path_pcep_config.c2
-rw-r--r--pathd/path_pcep_controller.c96
-rw-r--r--pathd/path_pcep_controller.h22
-rw-r--r--pathd/path_pcep_lib.c12
-rw-r--r--pathd/path_pcep_pcc.c10
-rw-r--r--pathd/path_pcep_pcc.h8
-rw-r--r--pathd/path_ted.c35
-rw-r--r--pathd/path_ted.h8
-rw-r--r--pathd/path_zebra.c4
-rw-r--r--pathd/path_zebra.h2
-rw-r--r--pathd/pathd.c22
-rw-r--r--pathd/pathd.h4
-rw-r--r--pbrd/pbr_main.c4
-rw-r--r--pbrd/pbr_map.c2
-rw-r--r--pbrd/pbr_vty.c4
-rw-r--r--pbrd/pbr_zebra.c2
-rw-r--r--pbrd/pbr_zebra.h2
-rw-r--r--pimd/pim6_cmd.c8
-rw-r--r--pimd/pim6_mld.c135
-rw-r--r--pimd/pim6_mld.h12
-rw-r--r--pimd/pim_assert.c10
-rw-r--r--pimd/pim_bsm.c30
-rw-r--r--pimd/pim_bsm.h4
-rw-r--r--pimd/pim_iface.c6
-rw-r--r--pimd/pim_iface.h4
-rw-r--r--pimd/pim_ifchannel.c96
-rw-r--r--pimd/pim_ifchannel.h6
-rw-r--r--pimd/pim_igmp.c48
-rw-r--r--pimd/pim_igmp.h14
-rw-r--r--pimd/pim_igmpv3.c19
-rw-r--r--pimd/pim_instance.c6
-rw-r--r--pimd/pim_instance.h10
-rw-r--r--pimd/pim_join.c5
-rw-r--r--pimd/pim_main.c2
-rw-r--r--pimd/pim_mlag.c12
-rw-r--r--pimd/pim_mroute.c10
-rw-r--r--pimd/pim_msdp.c73
-rw-r--r--pimd/pim_msdp.h36
-rw-r--r--pimd/pim_msdp_packet.c10
-rw-r--r--pimd/pim_msdp_packet.h2
-rw-r--r--pimd/pim_msdp_socket.c16
-rw-r--r--pimd/pim_neighbor.c28
-rw-r--r--pimd/pim_neighbor.h4
-rw-r--r--pimd/pim_pim.c35
-rw-r--r--pimd/pim_register.c6
-rw-r--r--pimd/pim_rp.c4
-rw-r--r--pimd/pim_ssmpingd.c10
-rw-r--r--pimd/pim_ssmpingd.h2
-rw-r--r--pimd/pim_time.c14
-rw-r--r--pimd/pim_time.h8
-rw-r--r--pimd/pim_upstream.c62
-rw-r--r--pimd/pim_upstream.h8
-rw-r--r--pimd/pim_util.c2
-rw-r--r--pimd/pim_vxlan.c18
-rw-r--r--pimd/pim_vxlan.h2
-rw-r--r--pimd/pim_zebra.c22
-rw-r--r--pimd/pim_zlookup.c32
-rw-r--r--pimd/pim_zpthread.c6
-rw-r--r--pkgsrc/mgmtd.sh.in44
-rw-r--r--python/xref2vtysh.py12
-rw-r--r--python/xrelfo.py4
-rw-r--r--qpb/subdir.am20
-rw-r--r--redhat/frr.spec.in6
-rw-r--r--ripd/rip_interface.c14
-rw-r--r--ripd/rip_main.c4
-rw-r--r--ripd/rip_nb.c60
-rw-r--r--ripd/rip_nb.h31
-rw-r--r--ripd/rip_nb_rpcs.c4
-rw-r--r--ripd/rip_nb_state.c161
-rw-r--r--ripd/rip_peer.c14
-rw-r--r--ripd/rip_snmp.c4
-rw-r--r--ripd/rip_zebra.c2
-rw-r--r--ripd/ripd.c117
-rw-r--r--ripd/ripd.h22
-rw-r--r--ripngd/ripng_interface.c14
-rw-r--r--ripngd/ripng_main.c4
-rw-r--r--ripngd/ripng_nb_rpcs.c4
-rw-r--r--ripngd/ripng_peer.c14
-rw-r--r--ripngd/ripng_zebra.c2
-rw-r--r--ripngd/ripngd.c114
-rw-r--r--ripngd/ripngd.h22
-rw-r--r--sharpd/sharp_logpump.c8
-rw-r--r--sharpd/sharp_main.c4
-rw-r--r--sharpd/sharp_vty.c5
-rw-r--r--sharpd/sharp_zebra.c6
-rw-r--r--staticd/static_bfd.c2
-rw-r--r--staticd/static_main.c78
-rw-r--r--staticd/static_routes.c24
-rw-r--r--staticd/static_routes.h29
-rw-r--r--staticd/static_vty.c84
-rw-r--r--staticd/static_zebra.c2
-rw-r--r--staticd/static_zebra.h2
-rw-r--r--tests/bgpd/test_aspath.c4
-rw-r--r--tests/bgpd/test_capability.c4
-rw-r--r--tests/bgpd/test_ecommunity.c2
-rw-r--r--tests/bgpd/test_mp_attr.c8
-rw-r--r--tests/bgpd/test_mpath.c6
-rw-r--r--tests/bgpd/test_packet.c6
-rw-r--r--tests/bgpd/test_peer_attr.c6
-rw-r--r--tests/helpers/c/main.c20
-rw-r--r--tests/isisd/test_common.c2
-rw-r--r--tests/isisd/test_common.h2
-rw-r--r--tests/isisd/test_fuzz_isis_tlv.c2
-rw-r--r--tests/isisd/test_isis_spf.c12
-rw-r--r--tests/lib/cli/common_cli.c14
-rw-r--r--tests/lib/cli/common_cli.h2
-rw-r--r--tests/lib/cli/test_commands.c2
-rw-r--r--tests/lib/cxxcompat.c3
-rw-r--r--tests/lib/fuzz_zlog.c2
-rw-r--r--tests/lib/northbound/test_oper_data.c14
-rw-r--r--tests/lib/subdir.am2
-rw-r--r--tests/lib/test_assert.c6
-rw-r--r--tests/lib/test_buffer.c2
-rw-r--r--tests/lib/test_checksum.c2
-rw-r--r--tests/lib/test_grpc.cpp26
-rw-r--r--tests/lib/test_heavy.c2
-rw-r--r--tests/lib/test_heavy_thread.c16
-rw-r--r--tests/lib/test_heavy_wq.c4
-rw-r--r--tests/lib/test_memory.c2
-rw-r--r--tests/lib/test_nexthop_iter.c2
-rw-r--r--tests/lib/test_privs.c2
-rw-r--r--tests/lib/test_resolver.c2
-rw-r--r--tests/lib/test_segv.c8
-rw-r--r--tests/lib/test_sig.c10
-rw-r--r--tests/lib/test_srcdest_table.c5
-rw-r--r--tests/lib/test_stream.c4
-rw-r--r--tests/lib/test_table.c2
-rw-r--r--tests/lib/test_timer_correctness.c24
-rw-r--r--tests/lib/test_timer_performance.c22
-rw-r--r--tests/lib/test_zmq.c22
-rw-r--r--tests/ospfd/common.c2
-rw-r--r--tests/ospfd/common.h2
-rw-r--r--tests/ospfd/test_ospf_spf.c12
-rw-r--r--tests/topotests/all_protocol_startup/r1/ospf6d.conf-pre-v48
-rw-r--r--tests/topotests/all_protocol_startup/r1/show_isis_interface_detail.ref4
-rw-r--r--tests/topotests/all_protocol_startup/test_all_protocol_startup.py12
-rw-r--r--tests/topotests/bfd_topo2/test_bfd_topo2.py1
-rw-r--r--tests/topotests/bfd_topo3/r5/bfdd.conf6
-rw-r--r--tests/topotests/bfd_topo3/r6/bfdd.conf6
-rw-r--r--tests/topotests/bgp_accept_own/ce1/bgpd.conf2
-rw-r--r--tests/topotests/bgp_accept_own/ce2/bgpd.conf2
-rw-r--r--tests/topotests/bgp_accept_own/pe1/bgpd.conf8
-rw-r--r--tests/topotests/bgp_accept_own/rr1/bgpd.conf2
-rw-r--r--tests/topotests/bgp_comm_list_match/r2/bgpd.conf2
-rw-r--r--tests/topotests/bgp_confed1/r1/bgpd.conf8
-rw-r--r--tests/topotests/bgp_confed1/r2/bgpd.conf8
-rw-r--r--tests/topotests/bgp_confed1/r3/bgpd.conf8
-rw-r--r--tests/topotests/bgp_confed1/r4/bgpd.conf8
-rw-r--r--tests/topotests/bgp_dont_capability_negotiate/r1/bgpd.conf2
-rwxr-xr-xtests/topotests/bgp_evpn_vxlan_svd_topo1/test_bgp_evpn_vxlan_svd.py50
-rwxr-xr-xtests/topotests/bgp_evpn_vxlan_topo1/test_bgp_evpn_vxlan.py18
-rw-r--r--tests/topotests/bgp_ipv6_ll_peering/__init__.py0
-rw-r--r--tests/topotests/bgp_ipv6_ll_peering/r1/bgpd.conf6
-rw-r--r--tests/topotests/bgp_ipv6_ll_peering/r1/zebra.conf4
-rw-r--r--tests/topotests/bgp_ipv6_ll_peering/r2/bgpd.conf6
-rw-r--r--tests/topotests/bgp_ipv6_ll_peering/r2/zebra.conf4
-rw-r--r--tests/topotests/bgp_ipv6_ll_peering/test_bgp_ipv6_ll_peering.py88
-rw-r--r--tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/scale_up.py19
-rw-r--r--tests/topotests/bgp_labeled_unicast_addpath/test_bgp_labeled_unicast_addpath.py56
-rw-r--r--tests/topotests/bgp_lu_explicitnull/r1/bgpd.conf15
-rw-r--r--tests/topotests/bgp_lu_explicitnull/r1/zebra.conf6
-rw-r--r--tests/topotests/bgp_lu_explicitnull/r2/bgpd.conf15
-rw-r--r--tests/topotests/bgp_lu_explicitnull/r2/zebra.conf6
-rw-r--r--tests/topotests/bgp_lu_explicitnull/test_bgp_lu_explicitnull.py194
-rw-r--r--tests/topotests/bgp_prefix_list_any/__init__.py0
-rw-r--r--tests/topotests/bgp_prefix_list_any/r1/bgpd.conf15
-rw-r--r--tests/topotests/bgp_prefix_list_any/r1/zebra.conf5
-rw-r--r--tests/topotests/bgp_prefix_list_any/r2/bgpd.conf50
-rw-r--r--tests/topotests/bgp_prefix_list_any/r2/zebra.conf5
-rw-r--r--tests/topotests/bgp_prefix_list_any/test_bgp_prefix_list_any.py105
-rw-r--r--tests/topotests/bgp_route_map_delay_timer/__init__.py0
-rw-r--r--tests/topotests/bgp_route_map_delay_timer/r1/bgpd.conf24
-rw-r--r--tests/topotests/bgp_route_map_delay_timer/r1/zebra.conf4
-rw-r--r--tests/topotests/bgp_route_map_delay_timer/r2/bgpd.conf4
-rw-r--r--tests/topotests/bgp_route_map_delay_timer/r2/zebra.conf4
-rw-r--r--tests/topotests/bgp_route_map_delay_timer/test_bgp_route_map_delay_timer.py120
-rw-r--r--tests/topotests/bgp_route_map_vpn_import/r1/bgpd.conf10
-rw-r--r--tests/topotests/bgp_route_origin_parser/pe1/bgpd.conf2
-rw-r--r--tests/topotests/bgp_route_origin_parser/test_bgp_route_origin_parser.py129
-rw-r--r--tests/topotests/bgp_snmp_bgp4v2mib/r2/bgpd.conf2
-rw-r--r--tests/topotests/bgp_srv6l3vpn_to_bgp_vrf2/r1/zebra.conf6
-rw-r--r--tests/topotests/bgp_srv6l3vpn_to_bgp_vrf2/r2/zebra.conf6
-rw-r--r--tests/topotests/bgp_srv6l3vpn_to_bgp_vrf3/r1/zebra.conf6
-rw-r--r--tests/topotests/bgp_srv6l3vpn_to_bgp_vrf3/r2/bgpd.conf2
-rw-r--r--tests/topotests/bgp_srv6l3vpn_to_bgp_vrf3/r2/zebra.conf6
-rw-r--r--tests/topotests/bgp_suppress_fib/r2/bgpd.allowas_in.conf12
-rw-r--r--tests/topotests/bgp_suppress_fib/r2/bgpd.conf8
-rw-r--r--tests/topotests/bgp_suppress_fib/test_bgp_suppress_fib.py14
-rw-r--r--tests/topotests/bgp_vrf_md5_peering/__init__.py0
-rw-r--r--tests/topotests/bgp_vrf_md5_peering/exabgp.env53
-rw-r--r--tests/topotests/bgp_vrf_md5_peering/peer1/exabgp.cfg13
-rw-r--r--tests/topotests/bgp_vrf_md5_peering/r1/bgpd.conf11
-rw-r--r--tests/topotests/bgp_vrf_md5_peering/r1/zebra.conf6
-rw-r--r--tests/topotests/bgp_vrf_md5_peering/test_bgp_vrf_md5_peering.py87
-rw-r--r--tests/topotests/config_timing/test_config_timing.py73
-rw-r--r--tests/topotests/isis_snmp/r5/ldpdconf8
-rw-r--r--tests/topotests/isis_topo1/test_isis_topo1.py92
-rw-r--r--tests/topotests/lib/common_config.py129
-rw-r--r--tests/topotests/lib/micronet_compat.py4
-rw-r--r--tests/topotests/lib/pim.py166
-rw-r--r--tests/topotests/lib/topogen.py37
-rw-r--r--tests/topotests/lib/topotest.py77
-rw-r--r--tests/topotests/mgmt_tests/test_yang_mgmt.py548
-rw-r--r--tests/topotests/mgmt_tests/yang_mgmt.json157
-rw-r--r--tests/topotests/msdp_mesh_topo1/test_msdp_mesh_topo1.py1
-rwxr-xr-xtests/topotests/msdp_topo1/test_msdp_topo1.py1
-rw-r--r--tests/topotests/multicast_pim6_sm_topo1/multicast_pim6_sm_topo1.json300
-rw-r--r--tests/topotests/multicast_pim6_sm_topo1/test_multicast_pim6_sm1.py1616
-rw-r--r--tests/topotests/multicast_pim6_sm_topo1/test_multicast_pim6_sm2.py606
-rwxr-xr-xtests/topotests/multicast_pim6_static_rp_topo1/test_multicast_pim6_static_rp1.py3
-rwxr-xr-xtests/topotests/multicast_pim6_static_rp_topo1/test_multicast_pim6_static_rp2.py3
-rw-r--r--tests/topotests/ospf6_ecmp_inter_area/r1/ospf6d.conf64
-rw-r--r--tests/topotests/ospf6_topo2/test_ospf6_topo2.py1
-rw-r--r--tests/topotests/ospf_basic_functionality/test_ospf_asbr_summary_topo1.py520
-rw-r--r--tests/topotests/ospf_basic_functionality/test_ospf_asbr_summary_type7_lsa.py22
-rw-r--r--tests/topotests/ospf_basic_functionality/test_ospf_authentication.py44
-rw-r--r--tests/topotests/ospf_basic_functionality/test_ospf_chaos.py32
-rw-r--r--tests/topotests/ospf_basic_functionality/test_ospf_ecmp.py20
-rw-r--r--tests/topotests/ospf_basic_functionality/test_ospf_ecmp_lan.py12
-rw-r--r--tests/topotests/ospf_basic_functionality/test_ospf_lan.py12
-rw-r--r--tests/topotests/ospf_basic_functionality/test_ospf_nssa.py6
-rw-r--r--tests/topotests/ospf_basic_functionality/test_ospf_routemaps.py40
-rw-r--r--tests/topotests/ospf_basic_functionality/test_ospf_rte_calc.py10
-rw-r--r--tests/topotests/ospf_basic_functionality/test_ospf_single_area.py44
-rw-r--r--tests/topotests/ospf_gr_helper/test_ospf_gr_helper1.py18
-rw-r--r--tests/topotests/ospf_gr_helper/test_ospf_gr_helper2.py14
-rw-r--r--tests/topotests/ospf_gr_helper/test_ospf_gr_helper3.py8
-rw-r--r--tests/topotests/ospf_nssa_topo1/__init__.py0
-rw-r--r--tests/topotests/ospf_nssa_topo1/rt1/ospfd.conf22
-rw-r--r--tests/topotests/ospf_nssa_topo1/rt1/staticd.conf6
-rw-r--r--tests/topotests/ospf_nssa_topo1/rt1/step1/show_ip_ospf_route.ref115
-rw-r--r--tests/topotests/ospf_nssa_topo1/rt1/step10/show_ip_ospf_route.ref115
-rw-r--r--tests/topotests/ospf_nssa_topo1/rt1/step2/show_ip_ospf_route.ref115
-rw-r--r--tests/topotests/ospf_nssa_topo1/rt1/step3/show_ip_ospf_route.ref115
-rw-r--r--tests/topotests/ospf_nssa_topo1/rt1/step4/show_ip_ospf_route.ref103
-rw-r--r--tests/topotests/ospf_nssa_topo1/rt1/step5/show_ip_ospf_route.ref103
-rw-r--r--tests/topotests/ospf_nssa_topo1/rt1/step6/show_ip_ospf_route.ref91
-rw-r--r--tests/topotests/ospf_nssa_topo1/rt1/step7/show_ip_ospf_route.ref103
-rw-r--r--tests/topotests/ospf_nssa_topo1/rt1/step8/show_ip_ospf_route.ref103
-rw-r--r--tests/topotests/ospf_nssa_topo1/rt1/step9/show_ip_ospf_route.ref91
-rw-r--r--tests/topotests/ospf_nssa_topo1/rt1/zebra.conf18
-rw-r--r--tests/topotests/ospf_nssa_topo1/rt2/ospfd.conf35
-rw-r--r--tests/topotests/ospf_nssa_topo1/rt2/staticd.conf6
-rw-r--r--tests/topotests/ospf_nssa_topo1/rt2/step1/show_ip_ospf_route.ref127
-rw-r--r--tests/topotests/ospf_nssa_topo1/rt2/step10/show_ip_ospf_route.ref127
-rw-r--r--tests/topotests/ospf_nssa_topo1/rt2/step2/show_ip_ospf_route.ref139
-rw-r--r--tests/topotests/ospf_nssa_topo1/rt2/step3/show_ip_ospf_route.ref127
-rw-r--r--tests/topotests/ospf_nssa_topo1/rt2/step4/show_ip_ospf_route.ref129
-rw-r--r--tests/topotests/ospf_nssa_topo1/rt2/step5/show_ip_ospf_route.ref117
-rw-r--r--tests/topotests/ospf_nssa_topo1/rt2/step6/show_ip_ospf_route.ref103
-rw-r--r--tests/topotests/ospf_nssa_topo1/rt2/step7/show_ip_ospf_route.ref129
-rw-r--r--tests/topotests/ospf_nssa_topo1/rt2/step8/show_ip_ospf_route.ref129
-rw-r--r--tests/topotests/ospf_nssa_topo1/rt2/step9/show_ip_ospf_route.ref127
-rw-r--r--tests/topotests/ospf_nssa_topo1/rt2/zebra.conf24
-rw-r--r--tests/topotests/ospf_nssa_topo1/rt3/ospfd.conf24
-rw-r--r--tests/topotests/ospf_nssa_topo1/rt3/staticd.conf8
-rw-r--r--tests/topotests/ospf_nssa_topo1/rt3/step1/show_ip_ospf_route.ref138
-rw-r--r--tests/topotests/ospf_nssa_topo1/rt3/step10/show_ip_ospf_route.ref150
-rw-r--r--tests/topotests/ospf_nssa_topo1/rt3/step2/show_ip_ospf_route.ref138
-rw-r--r--tests/topotests/ospf_nssa_topo1/rt3/step3/show_ip_ospf_route.ref138
-rw-r--r--tests/topotests/ospf_nssa_topo1/rt3/step4/show_ip_ospf_route.ref150
-rw-r--r--tests/topotests/ospf_nssa_topo1/rt3/step5/show_ip_ospf_route.ref138
-rw-r--r--tests/topotests/ospf_nssa_topo1/rt3/step6/show_ip_ospf_route.ref126
-rw-r--r--tests/topotests/ospf_nssa_topo1/rt3/step7/show_ip_ospf_route.ref150
-rw-r--r--tests/topotests/ospf_nssa_topo1/rt3/step8/show_ip_ospf_route.ref150
-rw-r--r--tests/topotests/ospf_nssa_topo1/rt3/step9/show_ip_ospf_route.ref150
-rw-r--r--tests/topotests/ospf_nssa_topo1/rt3/zebra.conf18
-rw-r--r--tests/topotests/ospf_nssa_topo1/rt4/ospfd.conf24
-rw-r--r--tests/topotests/ospf_nssa_topo1/rt4/staticd.conf9
-rw-r--r--tests/topotests/ospf_nssa_topo1/rt4/step1/show_ip_ospf_route.ref114
-rw-r--r--tests/topotests/ospf_nssa_topo1/rt4/step10/show_ip_ospf_route.ref126
-rw-r--r--tests/topotests/ospf_nssa_topo1/rt4/step2/show_ip_ospf_route.ref114
-rw-r--r--tests/topotests/ospf_nssa_topo1/rt4/step3/show_ip_ospf_route.ref114
-rw-r--r--tests/topotests/ospf_nssa_topo1/rt4/step4/show_ip_ospf_route.ref126
-rw-r--r--tests/topotests/ospf_nssa_topo1/rt4/step5/show_ip_ospf_route.ref126
-rw-r--r--tests/topotests/ospf_nssa_topo1/rt4/step6/show_ip_ospf_route.ref126
-rw-r--r--tests/topotests/ospf_nssa_topo1/rt4/step7/show_ip_ospf_route.ref126
-rw-r--r--tests/topotests/ospf_nssa_topo1/rt4/step8/show_ip_ospf_route.ref126
-rw-r--r--tests/topotests/ospf_nssa_topo1/rt4/step9/show_ip_ospf_route.ref126
-rw-r--r--tests/topotests/ospf_nssa_topo1/rt4/zebra.conf18
-rw-r--r--tests/topotests/ospf_nssa_topo1/test_ospf_nssa_topo1.py416
-rw-r--r--tests/topotests/ospf_suppress_fa/test_ospf_suppress_fa.py4
-rw-r--r--tests/topotests/ospfv3_basic_functionality/test_ospfv3_asbr_summary_topo1.py236
-rw-r--r--tests/topotests/ospfv3_basic_functionality/test_ospfv3_authentication.py80
-rw-r--r--tests/topotests/ospfv3_basic_functionality/test_ospfv3_ecmp.py8
-rw-r--r--tests/topotests/ospfv3_basic_functionality/test_ospfv3_ecmp_lan.py8
-rw-r--r--tests/topotests/ospfv3_basic_functionality/test_ospfv3_nssa.py2
-rw-r--r--tests/topotests/ospfv3_basic_functionality/test_ospfv3_nssa2.py8
-rw-r--r--tests/topotests/ospfv3_basic_functionality/test_ospfv3_routemaps.py12
-rw-r--r--tests/topotests/ospfv3_basic_functionality/test_ospfv3_rte_calc.py6
-rw-r--r--tests/topotests/ospfv3_basic_functionality/test_ospfv3_single_area.py97
-rw-r--r--tests/topotests/rip_allow_ecmp/__init__.py0
-rw-r--r--tests/topotests/rip_allow_ecmp/r1/frr.conf9
-rw-r--r--tests/topotests/rip_allow_ecmp/r2/frr.conf13
-rw-r--r--tests/topotests/rip_allow_ecmp/r3/frr.conf13
-rw-r--r--tests/topotests/rip_allow_ecmp/test_rip_allow_ecmp.py124
-rw-r--r--tests/topotests/static_routing_with_ebgp/test_static_routes_topo1_ebgp.py120
-rw-r--r--tests/topotests/static_routing_with_ebgp/test_static_routes_topo2_ebgp.py92
-rw-r--r--tests/topotests/static_routing_with_ebgp/test_static_routes_topo3_ebgp.py46
-rw-r--r--tests/topotests/static_routing_with_ebgp/test_static_routes_topo4_ebgp.py12
-rw-r--r--tests/topotests/static_routing_with_ibgp/test_static_routes_topo1_ibgp.py84
-rw-r--r--tests/topotests/static_routing_with_ibgp/test_static_routes_topo2_ibgp.py84
-rw-r--r--tests/topotests/static_routing_with_ibgp/test_static_routes_topo3_ibgp.py30
-rw-r--r--tests/topotests/static_routing_with_ibgp/test_static_routes_topo4_ibgp.py12
-rw-r--r--tests/topotests/static_simple/r1/mgmtd.conf1
-rw-r--r--tests/topotests/static_simple/r1/staticd.conf1
-rw-r--r--tests/topotests/static_simple/r1/zebra.conf11
-rw-r--r--tests/topotests/static_simple/test_static_simple.py214
-rw-r--r--tests/topotests/zebra_rib/test_zebra_rib.py3
-rw-r--r--tools/etc/frr/daemons1
-rw-r--r--tools/frr-llvm-cg.c12
-rwxr-xr-xtools/frr-reload.py6
-rwxr-xr-xtools/frr.in5
-rwxr-xr-xtools/frrcommon.sh.in5
-rw-r--r--tools/frrinit.sh.in2
-rw-r--r--vrrpd/vrrp.c93
-rw-r--r--vrrpd/vrrp.h12
-rw-r--r--vrrpd/vrrp_main.c7
-rw-r--r--vtysh/vtysh.c38
-rw-r--r--vtysh/vtysh.h30
-rw-r--r--vtysh/vtysh_config.c109
-rw-r--r--vtysh/vtysh_main.c71
-rw-r--r--watchfrr/watchfrr.c136
-rw-r--r--yang/frr-bgp-route-map.yang29
-rw-r--r--yang/frr-isisd.yang33
-rw-r--r--yang/frr-ripd.yang127
-rw-r--r--zebra/dpdk/zebra_dplane_dpdk.c4
-rw-r--r--zebra/dplane_fpm_nl.c272
-rw-r--r--zebra/if_netlink.c2
-rw-r--r--zebra/interface.c24
-rw-r--r--zebra/interface.h2
-rw-r--r--zebra/irdp.h6
-rw-r--r--zebra/irdp_interface.c6
-rw-r--r--zebra/irdp_main.c24
-rw-r--r--zebra/irdp_packet.c12
-rw-r--r--zebra/kernel_netlink.c18
-rw-r--r--zebra/kernel_socket.c14
-rw-r--r--zebra/label_manager.h2
-rw-r--r--zebra/main.c22
-rw-r--r--zebra/redistribute.c2
-rw-r--r--zebra/rib.h11
-rw-r--r--zebra/router-id.c10
-rw-r--r--zebra/rt_netlink.c2
-rw-r--r--zebra/rtadv.c36
-rw-r--r--zebra/rtadv.h4
-rw-r--r--zebra/sample_plugin.c2
-rw-r--r--zebra/table_manager.h2
-rw-r--r--zebra/zapi_msg.c6
-rw-r--r--zebra/zebra_dplane.c82
-rw-r--r--zebra/zebra_dplane.h2
-rw-r--r--zebra/zebra_evpn_mac.c42
-rw-r--r--zebra/zebra_evpn_mac.h4
-rw-r--r--zebra/zebra_evpn_mh.c50
-rw-r--r--zebra/zebra_evpn_mh.h4
-rw-r--r--zebra/zebra_evpn_neigh.c40
-rw-r--r--zebra/zebra_evpn_neigh.h6
-rw-r--r--zebra/zebra_fpm.c80
-rw-r--r--zebra/zebra_gr.c461
-rw-r--r--zebra/zebra_l2_bridge_if.c5
-rw-r--r--zebra/zebra_mlag.c32
-rw-r--r--zebra/zebra_mlag_private.c32
-rw-r--r--zebra/zebra_mpls.c28
-rw-r--r--zebra/zebra_mpls_vty.c12
-rw-r--r--zebra/zebra_netns_notify.c47
-rw-r--r--zebra/zebra_nhg.c18
-rw-r--r--zebra/zebra_nhg.h2
-rw-r--r--zebra/zebra_ns.h2
-rw-r--r--zebra/zebra_opaque.c20
-rw-r--r--zebra/zebra_ptm.c67
-rw-r--r--zebra/zebra_ptm.h8
-rw-r--r--zebra/zebra_pw.c28
-rw-r--r--zebra/zebra_pw.h2
-rw-r--r--zebra/zebra_rib.c125
-rw-r--r--zebra/zebra_rnh.c4
-rw-r--r--zebra/zebra_routemap.c22
-rw-r--r--zebra/zebra_router.c25
-rw-r--r--zebra/zebra_router.h10
-rw-r--r--zebra/zebra_snmp.c2
-rw-r--r--zebra/zebra_vty.c22
-rw-r--r--zebra/zebra_vxlan.c222
-rw-r--r--zebra/zebra_vxlan_if.c5
-rw-r--r--zebra/zserv.c71
-rw-r--r--zebra/zserv.h22
817 files changed, 36404 insertions, 10933 deletions
diff --git a/.clang-format b/.clang-format
index b01157b051..1b18323348 100644
--- a/.clang-format
+++ b/.clang-format
@@ -52,6 +52,11 @@ ForEachMacros:
- FOR_ALL_INTERFACES
- FOR_ALL_INTERFACES_ADDRESSES
- JSON_FOREACH
+ - FOREACH_BE_TXN_BATCH_IN_LIST
+ - FOREACH_BE_APPLY_BATCH_IN_LIST
+ - FOREACH_BE_TXN_IN_LIST
+ - FOREACH_SESSION_IN_LIST
+ - FOREACH_MGMTD_BE_CLIENT_ID
# libyang
- LY_FOR_KEYS
- LY_LIST_FOR
@@ -76,3 +81,12 @@ ForEachMacros:
- FOREACH_SAFI
# ospfd
- LSDB_LOOP
+ # mgmtd
+ - FOREACH_CMT_REC
+ - FOREACH_TXN_CFG_BATCH_IN_LIST
+ - FOREACH_TXN_REQ_IN_LIST
+ - FOREACH_TXN_IN_LIST
+ - FOREACH_MGMTD_DB_ID
+ - FOREACH_ADAPTER_IN_LIST
+ - FOREACH_SESSION_IN_LIST
+ - FOREACH_SESSION_IN_LIST_SAFE
diff --git a/.github/workflows/commitlint.yml b/.github/workflows/commitlint.yml
index ea5b704188..96cd118f3a 100644
--- a/.github/workflows/commitlint.yml
+++ b/.github/workflows/commitlint.yml
@@ -10,8 +10,9 @@ on:
- unlabeled
jobs:
- lint:
- if: github.repository == 'frrouting/frr'
+ commitlint:
+ if: ${{ github.repository == 'frrouting/frr' }} && ${{ github.base_ref == 'refs/heads/master' }}
+ name: Check if the commits meet the requirements of the guidelines
permissions:
contents: read
pull-requests: read
diff --git a/Makefile.am b/Makefile.am
index 44d2ab8e72..f56e1b8e0b 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -155,6 +155,21 @@ $(AUTOMAKE_DUMMY)install-moduleLTLIBRARIES: install-libLTLIBRARIES
$(AUTOMAKE_DUMMY)install-binPROGRAMS: install-libLTLIBRARIES
$(AUTOMAKE_DUMMY)install-sbinPROGRAMS: install-libLTLIBRARIES
+# Include default rules to compile protobuf message sources
+SUFFIXES += .proto .pb-c.c .pb-c.h
+
+# Rules
+
+AM_V_PROTOC_C = $(am__v_PROTOC_C_$(V))
+am__v_PROTOC_C_ = $(am__v_PROTOC_C_$(AM_DEFAULT_VERBOSITY))
+am__v_PROTOC_C_0 = @echo " PROTOC_C" $@;
+am__v_PROTOC_C_1 =
+
+%.pb-c.c %.pb-c.h : %.proto
+ $(AM_V_PROTOC_C)$(PROTOC_C) -I$(top_srcdir) --c_out=$(top_builddir) $^
+ $(AM_V_GEN)$(SED) -i -e '1i\
+ #include "config.h"' $@
+
include doc/subdir.am
include doc/user/subdir.am
include doc/manpages/subdir.am
@@ -169,6 +184,8 @@ include fpm/subdir.am
include grpc/subdir.am
include tools/subdir.am
+include mgmtd/subdir.am
+
include bgpd/subdir.am
include bgpd/rfp-example/librfp/subdir.am
include bgpd/rfp-example/rfptest/subdir.am
@@ -207,6 +224,7 @@ rc_SCRIPTS = \
pkgsrc/ripd.sh \
pkgsrc/ripngd.sh \
pkgsrc/zebra.sh \
+ pkgsrc/mgmtd.sh \
# end
endif
@@ -244,6 +262,7 @@ EXTRA_DIST += \
snapcraft/helpers \
snapcraft/snap \
babeld/Makefile \
+ mgmtd/Makefile \
bgpd/Makefile \
bgpd/rfp-example/librfp/Makefile \
bgpd/rfp-example/rfptest/Makefile \
@@ -321,7 +340,7 @@ redistclean:
$(MAKE) distclean CONFIG_CLEAN_FILES="$(filter-out $(EXTRA_DIST), $(CONFIG_CLEAN_FILES))"
indent:
- tools/indent.py `find sharpd bgpd eigrpd include isisd lib nhrpd ospf6d ospfd pimd qpb ripd vtysh zebra -name '*.[ch]' | grep -v include/linux`
+ tools/indent.py `find sharpd bgpd mgmtd eigrpd include isisd lib nhrpd ospf6d ospfd pimd qpb ripd vtysh zebra -name '*.[ch]' | grep -v include/linux`
if HAVE_GCOV
diff --git a/alpine/APKBUILD.in b/alpine/APKBUILD.in
index fef7a61ccc..fd3c02f47e 100644
--- a/alpine/APKBUILD.in
+++ b/alpine/APKBUILD.in
@@ -18,7 +18,8 @@ makedepends="ncurses-dev net-snmp-dev gawk texinfo perl
ncurses-libs ncurses-terminfo ncurses-terminfo-base patch pax-utils pcre2
perl pkgconf python3 python3-dev readline readline-dev sqlite-libs pcre2-dev
squashfs-tools sudo tar texinfo xorriso xz-libs py-pip rtrlib rtrlib-dev
- py3-sphinx elfutils elfutils-dev libyang-dev"
+ py3-sphinx elfutils elfutils-dev libyang-dev protobuf-c-compiler protobuf-c-dev
+ lua5.3-dev lua5.3"
checkdepends="pytest py-setuptools"
install="$pkgname.pre-install $pkgname.pre-deinstall $pkgname.post-deinstall"
subpackages="$pkgname-dev $pkgname-doc $pkgname-dbg"
@@ -47,7 +48,8 @@ build() {
--enable-vty-group=frrvty \
--enable-user=$_user \
--enable-group=$_user \
- --enable-pcre2posix
+ --enable-pcre2posix \
+ --enable-scripting
make -j $(nproc)
}
diff --git a/babeld/babel_main.c b/babeld/babel_main.c
index 0869c120ac..b6126d5b7d 100644
--- a/babeld/babel_main.c
+++ b/babeld/babel_main.c
@@ -8,7 +8,7 @@ Copyright 2011 by Matthieu Boutier and Juliusz Chroboczek
#include "getopt.h"
#include "if.h"
#include "log.h"
-#include "thread.h"
+#include "frrevent.h"
#include "privs.h"
#include "sigevent.h"
#include "lib/version.h"
@@ -37,7 +37,7 @@ static void babel_exit_properly(void);
static void babel_save_state_file(void);
-struct thread_master *master; /* quagga's threads handler */
+struct event_loop *master; /* quagga's threads handler */
struct timeval babel_now; /* current time */
unsigned char myid[8]; /* unique id (mac address of an interface) */
diff --git a/babeld/babel_main.h b/babeld/babel_main.h
index 659ddc70cf..0f9792b185 100644
--- a/babeld/babel_main.h
+++ b/babeld/babel_main.h
@@ -9,7 +9,7 @@ Copyright 2011 by Matthieu Boutier and Juliusz Chroboczek
#include "vty.h"
extern struct timeval babel_now; /* current time */
-extern struct thread_master *master; /* quagga's threads handler */
+extern struct event_loop *master; /* quagga's threads handler */
extern int debug;
extern int resend_delay;
diff --git a/babeld/babeld.c b/babeld/babeld.c
index 5104155936..f4c932971e 100644
--- a/babeld/babeld.c
+++ b/babeld/babeld.c
@@ -37,11 +37,11 @@ Copyright 2011 by Matthieu Boutier and Juliusz Chroboczek
DEFINE_MGROUP(BABELD, "babeld");
DEFINE_MTYPE_STATIC(BABELD, BABEL, "Babel Structure");
-static void babel_init_routing_process(struct thread *thread);
+static void babel_init_routing_process(struct event *thread);
static void babel_get_myid(void);
static void babel_initial_noise(void);
-static void babel_read_protocol(struct thread *thread);
-static void babel_main_loop(struct thread *thread);
+static void babel_read_protocol(struct event *thread);
+static void babel_main_loop(struct event *thread);
static void babel_set_timer(struct timeval *timeout);
static void babel_fill_with_next_timeout(struct timeval *tv);
static void
@@ -148,9 +148,11 @@ babel_create_routing_process (void)
}
/* Threads. */
- thread_add_read(master, babel_read_protocol, NULL, protocol_socket, &babel_routing_process->t_read);
+ event_add_read(master, babel_read_protocol, NULL, protocol_socket,
+ &babel_routing_process->t_read);
/* wait a little: zebra will announce interfaces, addresses, routes... */
- thread_add_timer_msec(master, babel_init_routing_process, NULL, 200L, &babel_routing_process->t_update);
+ event_add_timer_msec(master, babel_init_routing_process, NULL, 200L,
+ &babel_routing_process->t_update);
/* Distribute list install. */
babel_routing_process->distribute_ctx = distribute_list_ctx_create (vrf_lookup_by_id(VRF_DEFAULT));
@@ -163,7 +165,7 @@ fail:
}
/* thread reading entries form others babel daemons */
-static void babel_read_protocol(struct thread *thread)
+static void babel_read_protocol(struct event *thread)
{
int rc;
struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT);
@@ -193,13 +195,14 @@ static void babel_read_protocol(struct thread *thread)
}
/* re-add thread */
- thread_add_read(master, &babel_read_protocol, NULL, protocol_socket, &babel_routing_process->t_read);
+ event_add_read(master, &babel_read_protocol, NULL, protocol_socket,
+ &babel_routing_process->t_read);
}
/* Zebra will give some information, especially about interfaces. This function
must be call with a litte timeout wich may give zebra the time to do his job,
making these inits have sense. */
-static void babel_init_routing_process(struct thread *thread)
+static void babel_init_routing_process(struct event *thread)
{
myseqno = (frr_weak_random() & 0xFFFF);
babel_get_myid();
@@ -303,15 +306,15 @@ babel_clean_routing_process(void)
babel_interface_close_all();
/* cancel events */
- thread_cancel(&babel_routing_process->t_read);
- thread_cancel(&babel_routing_process->t_update);
+ event_cancel(&babel_routing_process->t_read);
+ event_cancel(&babel_routing_process->t_update);
distribute_list_delete(&babel_routing_process->distribute_ctx);
XFREE(MTYPE_BABEL, babel_routing_process);
}
/* Function used with timeout. */
-static void babel_main_loop(struct thread *thread)
+static void babel_main_loop(struct event *thread)
{
struct timeval tv;
struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT);
@@ -441,37 +444,39 @@ babel_fill_with_next_timeout(struct timeval *tv)
#if (defined NO_DEBUG)
#define printIfMin(a,b,c,d)
#else
-#define printIfMin(a,b,c,d) \
- if (UNLIKELY(debug & BABEL_DEBUG_TIMEOUT)) {printIfMin(a,b,c,d);}
-
- struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT);
- struct interface *ifp = NULL;
+#define printIfMin(a, b, c, d) \
+ if (unlikely(debug & BABEL_DEBUG_TIMEOUT)) { \
+ printIfMin(a, b, c, d); \
+ }
- *tv = check_neighbours_timeout;
- printIfMin(tv, 0, "check_neighbours_timeout", NULL);
- timeval_min_sec(tv, expiry_time);
- printIfMin(tv, 1, "expiry_time", NULL);
- timeval_min_sec(tv, source_expiry_time);
- printIfMin(tv, 1, "source_expiry_time", NULL);
- timeval_min(tv, &resend_time);
- printIfMin(tv, 1, "resend_time", NULL);
- FOR_ALL_INTERFACES(vrf, ifp) {
- babel_interface_nfo *babel_ifp = NULL;
- if(!if_up(ifp))
- continue;
- babel_ifp = babel_get_if_nfo(ifp);
- timeval_min(tv, &babel_ifp->flush_timeout);
- printIfMin(tv, 1, "flush_timeout", ifp->name);
- timeval_min(tv, &babel_ifp->hello_timeout);
- printIfMin(tv, 1, "hello_timeout", ifp->name);
- timeval_min(tv, &babel_ifp->update_timeout);
- printIfMin(tv, 1, "update_timeout", ifp->name);
- timeval_min(tv, &babel_ifp->update_flush_timeout);
- printIfMin(tv, 1, "update_flush_timeout",ifp->name);
- }
- timeval_min(tv, &unicast_flush_timeout);
- printIfMin(tv, 1, "unicast_flush_timeout", NULL);
- printIfMin(tv, 2, NULL, NULL);
+ struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT);
+ struct interface *ifp = NULL;
+
+ *tv = check_neighbours_timeout;
+ printIfMin(tv, 0, "check_neighbours_timeout", NULL);
+ timeval_min_sec(tv, expiry_time);
+ printIfMin(tv, 1, "expiry_time", NULL);
+ timeval_min_sec(tv, source_expiry_time);
+ printIfMin(tv, 1, "source_expiry_time", NULL);
+ timeval_min(tv, &resend_time);
+ printIfMin(tv, 1, "resend_time", NULL);
+ FOR_ALL_INTERFACES (vrf, ifp) {
+ babel_interface_nfo *babel_ifp = NULL;
+ if (!if_up(ifp))
+ continue;
+ babel_ifp = babel_get_if_nfo(ifp);
+ timeval_min(tv, &babel_ifp->flush_timeout);
+ printIfMin(tv, 1, "flush_timeout", ifp->name);
+ timeval_min(tv, &babel_ifp->hello_timeout);
+ printIfMin(tv, 1, "hello_timeout", ifp->name);
+ timeval_min(tv, &babel_ifp->update_timeout);
+ printIfMin(tv, 1, "update_timeout", ifp->name);
+ timeval_min(tv, &babel_ifp->update_flush_timeout);
+ printIfMin(tv, 1, "update_flush_timeout", ifp->name);
+ }
+ timeval_min(tv, &unicast_flush_timeout);
+ printIfMin(tv, 1, "unicast_flush_timeout", NULL);
+ printIfMin(tv, 2, NULL, NULL);
#undef printIfMin
#endif
}
@@ -482,8 +487,9 @@ static void
babel_set_timer(struct timeval *timeout)
{
long msecs = timeout->tv_sec * 1000 + timeout->tv_usec / 1000;
- thread_cancel(&(babel_routing_process->t_update));
- thread_add_timer_msec(master, babel_main_loop, NULL, msecs, &babel_routing_process->t_update);
+ event_cancel(&(babel_routing_process->t_update));
+ event_add_timer_msec(master, babel_main_loop, NULL, msecs,
+ &babel_routing_process->t_update);
}
void
diff --git a/babeld/babeld.h b/babeld/babeld.h
index a9ffb7ee43..619550f651 100644
--- a/babeld/babeld.h
+++ b/babeld/babeld.h
@@ -26,12 +26,8 @@ Copyright 2011 by Matthieu Boutier and Juliusz Chroboczek
#if defined(__GNUC__) && (__GNUC__ >= 3)
#define ATTRIBUTE(x) __attribute__ (x)
-#define LIKELY(_x) __builtin_expect(!!(_x), 1)
-#define UNLIKELY(_x) __builtin_expect(!!(_x), 0)
#else
#define ATTRIBUTE(x) /**/
-#define LIKELY(_x) !!(_x)
-#define UNLIKELY(_x) !!(_x)
#endif
#if defined(__GNUC__) && (__GNUC__ >= 4) && (__GNUC_MINOR__ >= 3)
@@ -84,8 +80,8 @@ Copyright 2011 by Matthieu Boutier and Juliusz Chroboczek
struct babel
{
/* Babel threads. */
- struct thread *t_read; /* on Babel protocol's socket */
- struct thread *t_update; /* timers */
+ struct event *t_read; /* on Babel protocol's socket */
+ struct event *t_update; /* timers */
/* distribute_ctx */
struct distribute_ctx *distribute_ctx;
};
diff --git a/babeld/kernel.c b/babeld/kernel.c
index f89fe268df..4fe5bcfea6 100644
--- a/babeld/kernel.c
+++ b/babeld/kernel.c
@@ -29,7 +29,7 @@ Copyright 2011, 2012 by Matthieu Boutier and Juliusz Chroboczek
#include "command.h"
#include "vty.h"
#include "memory.h"
-#include "thread.h"
+#include "frrevent.h"
#include "nexthop.h"
#include "util.h"
diff --git a/babeld/util.h b/babeld/util.h
index 5e5843543a..8535d4dd6a 100644
--- a/babeld/util.h
+++ b/babeld/util.h
@@ -122,10 +122,11 @@ extern const unsigned char v4prefix[16];
#define BABEL_DEBUG_ROUTE (1 << 5)
#define BABEL_DEBUG_ALL (0xFFFF)
-#define debugf(level, ...) \
-do { \
-if(UNLIKELY(debug & level)) zlog_debug(__VA_ARGS__); \
-} while(0)
+#define debugf(level, ...) \
+ do { \
+ if (unlikely(debug & level)) \
+ zlog_debug(__VA_ARGS__); \
+ } while (0)
#endif /* NO_DEBUG */
diff --git a/bfdd/bfd.c b/bfdd/bfd.c
index 2586c0b99c..3096f47d5c 100644
--- a/bfdd/bfd.c
+++ b/bfdd/bfd.c
@@ -618,25 +618,25 @@ struct bfd_session *ptm_bfd_sess_find(struct bfd_pkt *cp,
return bfd_key_lookup(key);
}
-void bfd_xmt_cb(struct thread *t)
+void bfd_xmt_cb(struct event *t)
{
- struct bfd_session *bs = THREAD_ARG(t);
+ struct bfd_session *bs = EVENT_ARG(t);
ptm_bfd_xmt_TO(bs, 0);
}
-void bfd_echo_xmt_cb(struct thread *t)
+void bfd_echo_xmt_cb(struct event *t)
{
- struct bfd_session *bs = THREAD_ARG(t);
+ struct bfd_session *bs = EVENT_ARG(t);
if (bs->echo_xmt_TO > 0)
ptm_bfd_echo_xmt_TO(bs);
}
/* Was ptm_bfd_detect_TO() */
-void bfd_recvtimer_cb(struct thread *t)
+void bfd_recvtimer_cb(struct event *t)
{
- struct bfd_session *bs = THREAD_ARG(t);
+ struct bfd_session *bs = EVENT_ARG(t);
switch (bs->ses_state) {
case PTM_BFD_INIT:
@@ -647,9 +647,9 @@ void bfd_recvtimer_cb(struct thread *t)
}
/* Was ptm_bfd_echo_detect_TO() */
-void bfd_echo_recvtimer_cb(struct thread *t)
+void bfd_echo_recvtimer_cb(struct event *t)
{
- struct bfd_session *bs = THREAD_ARG(t);
+ struct bfd_session *bs = EVENT_ARG(t);
switch (bs->ses_state) {
case PTM_BFD_INIT:
@@ -1957,23 +1957,23 @@ static int bfd_vrf_enable(struct vrf *vrf)
bvrf->bg_echov6 = bp_echov6_socket(vrf);
if (!bvrf->bg_ev[0] && bvrf->bg_shop != -1)
- thread_add_read(master, bfd_recv_cb, bvrf, bvrf->bg_shop,
- &bvrf->bg_ev[0]);
+ event_add_read(master, bfd_recv_cb, bvrf, bvrf->bg_shop,
+ &bvrf->bg_ev[0]);
if (!bvrf->bg_ev[1] && bvrf->bg_mhop != -1)
- thread_add_read(master, bfd_recv_cb, bvrf, bvrf->bg_mhop,
- &bvrf->bg_ev[1]);
+ event_add_read(master, bfd_recv_cb, bvrf, bvrf->bg_mhop,
+ &bvrf->bg_ev[1]);
if (!bvrf->bg_ev[2] && bvrf->bg_shop6 != -1)
- thread_add_read(master, bfd_recv_cb, bvrf, bvrf->bg_shop6,
- &bvrf->bg_ev[2]);
+ event_add_read(master, bfd_recv_cb, bvrf, bvrf->bg_shop6,
+ &bvrf->bg_ev[2]);
if (!bvrf->bg_ev[3] && bvrf->bg_mhop6 != -1)
- thread_add_read(master, bfd_recv_cb, bvrf, bvrf->bg_mhop6,
- &bvrf->bg_ev[3]);
+ event_add_read(master, bfd_recv_cb, bvrf, bvrf->bg_mhop6,
+ &bvrf->bg_ev[3]);
if (!bvrf->bg_ev[4] && bvrf->bg_echo != -1)
- thread_add_read(master, bfd_recv_cb, bvrf, bvrf->bg_echo,
- &bvrf->bg_ev[4]);
+ event_add_read(master, bfd_recv_cb, bvrf, bvrf->bg_echo,
+ &bvrf->bg_ev[4]);
if (!bvrf->bg_ev[5] && bvrf->bg_echov6 != -1)
- thread_add_read(master, bfd_recv_cb, bvrf, bvrf->bg_echov6,
- &bvrf->bg_ev[5]);
+ event_add_read(master, bfd_recv_cb, bvrf, bvrf->bg_echov6,
+ &bvrf->bg_ev[5]);
if (vrf->vrf_id != VRF_DEFAULT) {
bfdd_zclient_register(vrf->vrf_id);
@@ -1999,12 +1999,12 @@ static int bfd_vrf_disable(struct vrf *vrf)
zlog_debug("VRF disable %s id %d", vrf->name, vrf->vrf_id);
/* Disable read/write poll triggering. */
- THREAD_OFF(bvrf->bg_ev[0]);
- THREAD_OFF(bvrf->bg_ev[1]);
- THREAD_OFF(bvrf->bg_ev[2]);
- THREAD_OFF(bvrf->bg_ev[3]);
- THREAD_OFF(bvrf->bg_ev[4]);
- THREAD_OFF(bvrf->bg_ev[5]);
+ EVENT_OFF(bvrf->bg_ev[0]);
+ EVENT_OFF(bvrf->bg_ev[1]);
+ EVENT_OFF(bvrf->bg_ev[2]);
+ EVENT_OFF(bvrf->bg_ev[3]);
+ EVENT_OFF(bvrf->bg_ev[4]);
+ EVENT_OFF(bvrf->bg_ev[5]);
/* Close all descriptors. */
socket_close(&bvrf->bg_echo);
diff --git a/bfdd/bfd.h b/bfdd/bfd.h
index 97e45bb2c2..5451e66c23 100644
--- a/bfdd/bfd.h
+++ b/bfdd/bfd.h
@@ -265,12 +265,12 @@ struct bfd_session {
struct bfd_config_timers timers;
struct bfd_timers cur_timers;
uint64_t detect_TO;
- struct thread *echo_recvtimer_ev;
- struct thread *recvtimer_ev;
+ struct event *echo_recvtimer_ev;
+ struct event *recvtimer_ev;
uint64_t xmt_TO;
uint64_t echo_xmt_TO;
- struct thread *xmttimer_ev;
- struct thread *echo_xmttimer_ev;
+ struct event *xmttimer_ev;
+ struct event *echo_xmttimer_ev;
uint64_t echo_detect_TO;
/* software object state */
@@ -401,8 +401,8 @@ struct bfd_control_socket {
TAILQ_ENTRY(bfd_control_socket) bcs_entry;
int bcs_sd;
- struct thread *bcs_ev;
- struct thread *bcs_outev;
+ struct event *bcs_ev;
+ struct event *bcs_outev;
struct bcqueue bcs_bcqueue;
/* Notification data */
@@ -422,7 +422,7 @@ int control_init(const char *path);
void control_shutdown(void);
int control_notify(struct bfd_session *bs, uint8_t notify_state);
int control_notify_config(const char *op, struct bfd_session *bs);
-void control_accept(struct thread *t);
+void control_accept(struct event *t);
/*
@@ -439,7 +439,7 @@ struct bfd_vrf_global {
int bg_echov6;
struct vrf *vrf;
- struct thread *bg_ev[6];
+ struct event *bg_ev[6];
};
/* Forward declaration of data plane context struct. */
@@ -448,7 +448,7 @@ TAILQ_HEAD(dplane_queue, bfd_dplane_ctx);
struct bfd_global {
int bg_csock;
- struct thread *bg_csockev;
+ struct event *bg_csockev;
struct bcslist bg_bcslist;
struct pllist bg_pllist;
@@ -466,7 +466,7 @@ struct bfd_global {
/* Distributed BFD items. */
bool bg_use_dplane;
int bg_dplane_sock;
- struct thread *bg_dplane_sockev;
+ struct event *bg_dplane_sockev;
struct dplane_queue bg_dplaneq;
/* Debug options. */
@@ -553,7 +553,7 @@ void ptm_bfd_snd(struct bfd_session *bfd, int fbit);
void ptm_bfd_echo_snd(struct bfd_session *bfd);
void ptm_bfd_echo_fp_snd(struct bfd_session *bfd);
-void bfd_recv_cb(struct thread *t);
+void bfd_recv_cb(struct event *t);
/*
@@ -561,7 +561,7 @@ void bfd_recv_cb(struct thread *t);
*
* Contains the code related with event loop.
*/
-typedef void (*bfd_ev_cb)(struct thread *t);
+typedef void (*bfd_ev_cb)(struct event *t);
void bfd_recvtimer_update(struct bfd_session *bs);
void bfd_echo_recvtimer_update(struct bfd_session *bs);
@@ -686,12 +686,12 @@ void bfd_key_iterate(hash_iter_func hif, void *arg);
unsigned long bfd_get_session_count(void);
/* Export callback functions for `event.c`. */
-extern struct thread_master *master;
+extern struct event_loop *master;
-void bfd_recvtimer_cb(struct thread *t);
-void bfd_echo_recvtimer_cb(struct thread *t);
-void bfd_xmt_cb(struct thread *t);
-void bfd_echo_xmt_cb(struct thread *t);
+void bfd_recvtimer_cb(struct event *t);
+void bfd_echo_recvtimer_cb(struct event *t);
+void bfd_xmt_cb(struct event *t);
+void bfd_echo_xmt_cb(struct event *t);
extern struct in6_addr zero_addr;
diff --git a/bfdd/bfd_packet.c b/bfdd/bfd_packet.c
index 7be235326c..311ce4d379 100644
--- a/bfdd/bfd_packet.c
+++ b/bfdd/bfd_packet.c
@@ -140,7 +140,7 @@ int _ptm_bfd_send(struct bfd_session *bs, uint16_t *port, const void *data,
* sizeof(*pkt)
*
* ip
- * IP address that pkt will be transmitted from and too.
+ * IP address that pkt will be transmitted from and to.
*
* Returns:
* Checksum in network byte order.
@@ -481,12 +481,6 @@ ssize_t bfd_recv_ipv4_fp(int sd, uint8_t *msgbuf, size_t msgbuflen,
*ttl = ip->ttl;
if (*ttl != 254) {
- /* Echo should be looped in peer's forwarding plane, but it also
- * comes up to BFD so silently drop it
- */
- if (ip->daddr == ip->saddr)
- return -1;
-
if (bglobal.debug_network)
zlog_debug("%s: invalid TTL: %u", __func__, *ttl);
return -1;
@@ -707,29 +701,29 @@ ssize_t bfd_recv_ipv6(int sd, uint8_t *msgbuf, size_t msgbuflen, uint8_t *ttl,
static void bfd_sd_reschedule(struct bfd_vrf_global *bvrf, int sd)
{
if (sd == bvrf->bg_shop) {
- THREAD_OFF(bvrf->bg_ev[0]);
- thread_add_read(master, bfd_recv_cb, bvrf, bvrf->bg_shop,
- &bvrf->bg_ev[0]);
+ EVENT_OFF(bvrf->bg_ev[0]);
+ event_add_read(master, bfd_recv_cb, bvrf, bvrf->bg_shop,
+ &bvrf->bg_ev[0]);
} else if (sd == bvrf->bg_mhop) {
- THREAD_OFF(bvrf->bg_ev[1]);
- thread_add_read(master, bfd_recv_cb, bvrf, bvrf->bg_mhop,
- &bvrf->bg_ev[1]);
+ EVENT_OFF(bvrf->bg_ev[1]);
+ event_add_read(master, bfd_recv_cb, bvrf, bvrf->bg_mhop,
+ &bvrf->bg_ev[1]);
} else if (sd == bvrf->bg_shop6) {
- THREAD_OFF(bvrf->bg_ev[2]);
- thread_add_read(master, bfd_recv_cb, bvrf, bvrf->bg_shop6,
- &bvrf->bg_ev[2]);
+ EVENT_OFF(bvrf->bg_ev[2]);
+ event_add_read(master, bfd_recv_cb, bvrf, bvrf->bg_shop6,
+ &bvrf->bg_ev[2]);
} else if (sd == bvrf->bg_mhop6) {
- THREAD_OFF(bvrf->bg_ev[3]);
- thread_add_read(master, bfd_recv_cb, bvrf, bvrf->bg_mhop6,
- &bvrf->bg_ev[3]);
+ EVENT_OFF(bvrf->bg_ev[3]);
+ event_add_read(master, bfd_recv_cb, bvrf, bvrf->bg_mhop6,
+ &bvrf->bg_ev[3]);
} else if (sd == bvrf->bg_echo) {
- THREAD_OFF(bvrf->bg_ev[4]);
- thread_add_read(master, bfd_recv_cb, bvrf, bvrf->bg_echo,
- &bvrf->bg_ev[4]);
+ EVENT_OFF(bvrf->bg_ev[4]);
+ event_add_read(master, bfd_recv_cb, bvrf, bvrf->bg_echo,
+ &bvrf->bg_ev[4]);
} else if (sd == bvrf->bg_echov6) {
- THREAD_OFF(bvrf->bg_ev[5]);
- thread_add_read(master, bfd_recv_cb, bvrf, bvrf->bg_echov6,
- &bvrf->bg_ev[5]);
+ EVENT_OFF(bvrf->bg_ev[5]);
+ event_add_read(master, bfd_recv_cb, bvrf, bvrf->bg_echov6,
+ &bvrf->bg_ev[5]);
}
}
@@ -774,9 +768,9 @@ static void cp_debug(bool mhop, struct sockaddr_any *peer,
mhop ? "yes" : "no", peerstr, localstr, portstr, vrfstr);
}
-void bfd_recv_cb(struct thread *t)
+void bfd_recv_cb(struct event *t)
{
- int sd = THREAD_FD(t);
+ int sd = EVENT_FD(t);
struct bfd_session *bfd;
struct bfd_pkt *cp;
bool is_mhop;
@@ -787,7 +781,7 @@ void bfd_recv_cb(struct thread *t)
struct sockaddr_any local, peer;
uint8_t msgbuf[1516];
struct interface *ifp = NULL;
- struct bfd_vrf_global *bvrf = THREAD_ARG(t);
+ struct bfd_vrf_global *bvrf = EVENT_ARG(t);
/* Schedule next read. */
bfd_sd_reschedule(bvrf, sd);
diff --git a/bfdd/bfdd.c b/bfdd/bfdd.c
index a3751e4d33..5fbe2f48f6 100644
--- a/bfdd/bfdd.c
+++ b/bfdd/bfdd.c
@@ -32,7 +32,7 @@ DEFINE_MTYPE(BFDD, BFDD_CONTROL, "long-lived control socket memory");
DEFINE_MTYPE(BFDD, BFDD_NOTIFICATION, "short-lived control notification data");
/* Master of threads. */
-struct thread_master *master;
+struct event_loop *master;
/* BFDd privileges */
static zebra_capabilities_t _caps_p[] = {ZCAP_BIND, ZCAP_SYS_ADMIN, ZCAP_NET_RAW};
@@ -375,8 +375,8 @@ int main(int argc, char *argv[])
/* Initialize zebra connection. */
bfdd_zclient_init(&bglobal.bfdd_privs);
- thread_add_read(master, control_accept, NULL, bglobal.bg_csock,
- &bglobal.bg_csockev);
+ event_add_read(master, control_accept, NULL, bglobal.bg_csock,
+ &bglobal.bg_csockev);
/* Install commands. */
bfdd_vty_init();
diff --git a/bfdd/control.c b/bfdd/control.c
index a11ed3d895..f435358f33 100644
--- a/bfdd/control.c
+++ b/bfdd/control.c
@@ -39,8 +39,8 @@ struct bfd_notify_peer *control_notifypeer_find(struct bfd_control_socket *bcs,
struct bfd_control_socket *control_new(int sd);
static void control_free(struct bfd_control_socket *bcs);
static void control_reset_buf(struct bfd_control_buffer *bcb);
-static void control_read(struct thread *t);
-static void control_write(struct thread *t);
+static void control_read(struct event *t);
+static void control_write(struct event *t);
static void control_handle_request_add(struct bfd_control_socket *bcs,
struct bfd_control_msg *bcm);
@@ -132,7 +132,7 @@ void control_shutdown(void)
{
struct bfd_control_socket *bcs;
- thread_cancel(&bglobal.bg_csockev);
+ event_cancel(&bglobal.bg_csockev);
socket_close(&bglobal.bg_csock);
@@ -142,9 +142,9 @@ void control_shutdown(void)
}
}
-void control_accept(struct thread *t)
+void control_accept(struct event *t)
{
- int csock, sd = THREAD_FD(t);
+ int csock, sd = EVENT_FD(t);
csock = accept(sd, NULL, 0);
if (csock == -1) {
@@ -154,7 +154,7 @@ void control_accept(struct thread *t)
control_new(csock);
- thread_add_read(master, control_accept, NULL, sd, &bglobal.bg_csockev);
+ event_add_read(master, control_accept, NULL, sd, &bglobal.bg_csockev);
}
@@ -171,7 +171,7 @@ struct bfd_control_socket *control_new(int sd)
bcs->bcs_notify = 0;
bcs->bcs_sd = sd;
- thread_add_read(master, control_read, bcs, sd, &bcs->bcs_ev);
+ event_add_read(master, control_read, bcs, sd, &bcs->bcs_ev);
TAILQ_INIT(&bcs->bcs_bcqueue);
TAILQ_INIT(&bcs->bcs_bnplist);
@@ -185,8 +185,8 @@ static void control_free(struct bfd_control_socket *bcs)
struct bfd_control_queue *bcq;
struct bfd_notify_peer *bnp;
- thread_cancel(&(bcs->bcs_ev));
- thread_cancel(&(bcs->bcs_outev));
+ event_cancel(&(bcs->bcs_ev));
+ event_cancel(&(bcs->bcs_outev));
close(bcs->bcs_sd);
@@ -286,13 +286,13 @@ static int control_queue_dequeue(struct bfd_control_socket *bcs)
bcs->bcs_bout = &bcq->bcq_bcb;
bcs->bcs_outev = NULL;
- thread_add_write(master, control_write, bcs, bcs->bcs_sd,
- &bcs->bcs_outev);
+ event_add_write(master, control_write, bcs, bcs->bcs_sd,
+ &bcs->bcs_outev);
return 1;
empty_list:
- thread_cancel(&(bcs->bcs_outev));
+ event_cancel(&(bcs->bcs_outev));
bcs->bcs_bout = NULL;
return 0;
}
@@ -315,8 +315,8 @@ static int control_queue_enqueue(struct bfd_control_socket *bcs,
bcs->bcs_bout = bcb;
/* New messages, active write events. */
- thread_add_write(master, control_write, bcs, bcs->bcs_sd,
- &bcs->bcs_outev);
+ event_add_write(master, control_write, bcs, bcs->bcs_sd,
+ &bcs->bcs_outev);
}
return 0;
@@ -379,9 +379,9 @@ static void control_reset_buf(struct bfd_control_buffer *bcb)
bcb->bcb_left = 0;
}
-static void control_read(struct thread *t)
+static void control_read(struct event *t)
{
- struct bfd_control_socket *bcs = THREAD_ARG(t);
+ struct bfd_control_socket *bcs = EVENT_ARG(t);
struct bfd_control_buffer *bcb = &bcs->bcs_bin;
int sd = bcs->bcs_sd;
struct bfd_control_msg bcm;
@@ -511,12 +511,12 @@ skip_header:
schedule_next_read:
bcs->bcs_ev = NULL;
- thread_add_read(master, control_read, bcs, sd, &bcs->bcs_ev);
+ event_add_read(master, control_read, bcs, sd, &bcs->bcs_ev);
}
-static void control_write(struct thread *t)
+static void control_write(struct event *t)
{
- struct bfd_control_socket *bcs = THREAD_ARG(t);
+ struct bfd_control_socket *bcs = EVENT_ARG(t);
struct bfd_control_buffer *bcb = bcs->bcs_bout;
int sd = bcs->bcs_sd;
ssize_t bwrite;
@@ -529,8 +529,8 @@ static void control_write(struct thread *t)
if (bwrite < 0) {
if (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR) {
bcs->bcs_outev = NULL;
- thread_add_write(master, control_write, bcs,
- bcs->bcs_sd, &bcs->bcs_outev);
+ event_add_write(master, control_write, bcs, bcs->bcs_sd,
+ &bcs->bcs_outev);
return;
}
@@ -543,8 +543,8 @@ static void control_write(struct thread *t)
bcb->bcb_left -= bwrite;
if (bcb->bcb_left > 0) {
bcs->bcs_outev = NULL;
- thread_add_write(master, control_write, bcs, bcs->bcs_sd,
- &bcs->bcs_outev);
+ event_add_write(master, control_write, bcs, bcs->bcs_sd,
+ &bcs->bcs_outev);
return;
}
diff --git a/bfdd/dplane.c b/bfdd/dplane.c
index 99bd1886f4..d8539812e0 100644
--- a/bfdd/dplane.c
+++ b/bfdd/dplane.c
@@ -26,7 +26,7 @@
#include "lib/network.h"
#include "lib/printfrr.h"
#include "lib/stream.h"
-#include "lib/thread.h"
+#include "lib/frrevent.h"
#include "bfd.h"
#include "bfddp_packet.h"
@@ -63,11 +63,11 @@ struct bfd_dplane_ctx {
/** Output buffer data. */
struct stream *outbuf;
/** Input event data. */
- struct thread *inbufev;
+ struct event *inbufev;
/** Output event data. */
- struct thread *outbufev;
+ struct event *outbufev;
/** Connection event. */
- struct thread *connectev;
+ struct event *connectev;
/** Amount of bytes read. */
uint64_t in_bytes;
@@ -94,7 +94,7 @@ struct bfd_dplane_ctx {
*/
typedef void (*bfd_dplane_expect_cb)(struct bfddp_message *msg, void *arg);
-static void bfd_dplane_client_connect(struct thread *t);
+static void bfd_dplane_client_connect(struct event *t);
static bool bfd_dplane_client_connecting(struct bfd_dplane_ctx *bdc);
static void bfd_dplane_ctx_free(struct bfd_dplane_ctx *bdc);
static int _bfd_dplane_add_session(struct bfd_dplane_ctx *bdc,
@@ -307,14 +307,14 @@ static ssize_t bfd_dplane_flush(struct bfd_dplane_ctx *bdc)
stream_pulldown(bdc->outbuf);
/* Disable write ready events. */
- THREAD_OFF(bdc->outbufev);
+ EVENT_OFF(bdc->outbufev);
return total;
}
-static void bfd_dplane_write(struct thread *t)
+static void bfd_dplane_write(struct event *t)
{
- struct bfd_dplane_ctx *bdc = THREAD_ARG(t);
+ struct bfd_dplane_ctx *bdc = EVENT_ARG(t);
/* Handle connection stage. */
if (bdc->connecting && bfd_dplane_client_connecting(bdc))
@@ -429,8 +429,8 @@ static int bfd_dplane_enqueue(struct bfd_dplane_ctx *bdc, const void *buf,
/* Schedule if it is not yet. */
if (bdc->outbufev == NULL)
- thread_add_write(master, bfd_dplane_write, bdc, bdc->sock,
- &bdc->outbufev);
+ event_add_write(master, bfd_dplane_write, bdc, bdc->sock,
+ &bdc->outbufev);
return 0;
}
@@ -599,9 +599,9 @@ skip_read:
return 0;
}
-static void bfd_dplane_read(struct thread *t)
+static void bfd_dplane_read(struct event *t)
{
- struct bfd_dplane_ctx *bdc = THREAD_ARG(t);
+ struct bfd_dplane_ctx *bdc = EVENT_ARG(t);
int rv;
rv = bfd_dplane_expect(bdc, 0, bfd_dplane_handle_message, NULL);
@@ -609,7 +609,7 @@ static void bfd_dplane_read(struct thread *t)
return;
stream_pulldown(bdc->inbuf);
- thread_add_read(master, bfd_dplane_read, bdc, bdc->sock, &bdc->inbufev);
+ event_add_read(master, bfd_dplane_read, bdc, bdc->sock, &bdc->inbufev);
}
static void _bfd_session_register_dplane(struct hash_bucket *hb, void *arg)
@@ -641,7 +641,7 @@ static struct bfd_dplane_ctx *bfd_dplane_ctx_new(int sock)
if (sock == -1)
return bdc;
- thread_add_read(master, bfd_dplane_read, bdc, sock, &bdc->inbufev);
+ event_add_read(master, bfd_dplane_read, bdc, sock, &bdc->inbufev);
/* Register all unattached sessions. */
bfd_key_iterate(_bfd_session_register_dplane, bdc);
@@ -672,7 +672,7 @@ static void bfd_dplane_ctx_free(struct bfd_dplane_ctx *bdc)
/* Client mode has special treatment. */
if (bdc->client) {
/* Disable connection event if any. */
- THREAD_OFF(bdc->connectev);
+ EVENT_OFF(bdc->connectev);
/* Normal treatment on shutdown. */
if (bglobal.bg_shutdown)
@@ -680,10 +680,10 @@ static void bfd_dplane_ctx_free(struct bfd_dplane_ctx *bdc)
/* Attempt reconnection. */
socket_close(&bdc->sock);
- THREAD_OFF(bdc->inbufev);
- THREAD_OFF(bdc->outbufev);
- thread_add_timer(master, bfd_dplane_client_connect, bdc, 3,
- &bdc->connectev);
+ EVENT_OFF(bdc->inbufev);
+ EVENT_OFF(bdc->outbufev);
+ event_add_timer(master, bfd_dplane_client_connect, bdc, 3,
+ &bdc->connectev);
return;
}
@@ -699,8 +699,8 @@ free_resources:
socket_close(&bdc->sock);
stream_free(bdc->inbuf);
stream_free(bdc->outbuf);
- THREAD_OFF(bdc->inbufev);
- THREAD_OFF(bdc->outbufev);
+ EVENT_OFF(bdc->inbufev);
+ EVENT_OFF(bdc->outbufev);
XFREE(MTYPE_BFDD_DPLANE_CTX, bdc);
}
@@ -819,9 +819,9 @@ static uint16_t bfd_dplane_request_counters(const struct bfd_session *bs)
/*
* Data plane listening socket.
*/
-static void bfd_dplane_accept(struct thread *t)
+static void bfd_dplane_accept(struct event *t)
{
- struct bfd_global *bg = THREAD_ARG(t);
+ struct bfd_global *bg = EVENT_ARG(t);
struct bfd_dplane_ctx *bdc;
int sock;
@@ -840,8 +840,8 @@ static void bfd_dplane_accept(struct thread *t)
zlog_debug("%s: new data plane client connected", __func__);
reschedule_and_return:
- thread_add_read(master, bfd_dplane_accept, bg, bg->bg_dplane_sock,
- &bglobal.bg_dplane_sockev);
+ event_add_read(master, bfd_dplane_accept, bg, bg->bg_dplane_sock,
+ &bglobal.bg_dplane_sockev);
}
/*
@@ -856,7 +856,7 @@ static void _bfd_dplane_client_bootstrap(struct bfd_dplane_ctx *bdc)
stream_reset(bdc->outbuf);
/* Ask for read notifications. */
- thread_add_read(master, bfd_dplane_read, bdc, bdc->sock, &bdc->inbufev);
+ event_add_read(master, bfd_dplane_read, bdc, bdc->sock, &bdc->inbufev);
/* Remove all sessions then register again to send them all. */
bfd_key_iterate(_bfd_session_unregister_dplane, bdc);
@@ -899,9 +899,9 @@ static bool bfd_dplane_client_connecting(struct bfd_dplane_ctx *bdc)
}
}
-static void bfd_dplane_client_connect(struct thread *t)
+static void bfd_dplane_client_connect(struct event *t)
{
- struct bfd_dplane_ctx *bdc = THREAD_ARG(t);
+ struct bfd_dplane_ctx *bdc = EVENT_ARG(t);
int rv, sock;
socklen_t rvlen = sizeof(rv);
@@ -938,8 +938,8 @@ static void bfd_dplane_client_connect(struct thread *t)
/* If we are not connected yet, ask for write notifications. */
bdc->connecting = true;
- thread_add_write(master, bfd_dplane_write, bdc, bdc->sock,
- &bdc->outbufev);
+ event_add_write(master, bfd_dplane_write, bdc, bdc->sock,
+ &bdc->outbufev);
} else {
if (bglobal.debug_dplane)
zlog_debug("%s: server connection: %d", __func__, sock);
@@ -949,11 +949,11 @@ static void bfd_dplane_client_connect(struct thread *t)
}
reschedule_connect:
- THREAD_OFF(bdc->inbufev);
- THREAD_OFF(bdc->outbufev);
+ EVENT_OFF(bdc->inbufev);
+ EVENT_OFF(bdc->outbufev);
socket_close(&sock);
- thread_add_timer(master, bfd_dplane_client_connect, bdc, 3,
- &bdc->connectev);
+ event_add_timer(master, bfd_dplane_client_connect, bdc, 3,
+ &bdc->connectev);
}
static void bfd_dplane_client_init(const struct sockaddr *sa, socklen_t salen)
@@ -974,8 +974,8 @@ static void bfd_dplane_client_init(const struct sockaddr *sa, socklen_t salen)
bdc->client = true;
- thread_add_timer(master, bfd_dplane_client_connect, bdc, 0,
- &bdc->connectev);
+ event_add_timer(master, bfd_dplane_client_connect, bdc, 0,
+ &bdc->connectev);
/* Insert into data plane lists. */
TAILQ_INSERT_TAIL(&bglobal.bg_dplaneq, bdc, entry);
@@ -997,7 +997,7 @@ static int bfd_dplane_finish_late(void)
bfd_dplane_ctx_free(bdc);
/* Cancel accept thread and close socket. */
- THREAD_OFF(bglobal.bg_dplane_sockev);
+ EVENT_OFF(bglobal.bg_dplane_sockev);
close(bglobal.bg_dplane_sock);
return 0;
@@ -1067,8 +1067,8 @@ void bfd_dplane_init(const struct sockaddr *sa, socklen_t salen, bool client)
}
bglobal.bg_dplane_sock = sock;
- thread_add_read(master, bfd_dplane_accept, &bglobal, sock,
- &bglobal.bg_dplane_sockev);
+ event_add_read(master, bfd_dplane_accept, &bglobal, sock,
+ &bglobal.bg_dplane_sockev);
}
int bfd_dplane_add_session(struct bfd_session *bs)
diff --git a/bfdd/event.c b/bfdd/event.c
index 5a9ae39c3e..e797e71f05 100644
--- a/bfdd/event.c
+++ b/bfdd/event.c
@@ -36,8 +36,8 @@ void bfd_recvtimer_update(struct bfd_session *bs)
tv_normalize(&tv);
- thread_add_timer_tv(master, bfd_recvtimer_cb, bs, &tv,
- &bs->recvtimer_ev);
+ event_add_timer_tv(master, bfd_recvtimer_cb, bs, &tv,
+ &bs->recvtimer_ev);
}
void bfd_echo_recvtimer_update(struct bfd_session *bs)
@@ -54,8 +54,8 @@ void bfd_echo_recvtimer_update(struct bfd_session *bs)
tv_normalize(&tv);
- thread_add_timer_tv(master, bfd_echo_recvtimer_cb, bs, &tv,
- &bs->echo_recvtimer_ev);
+ event_add_timer_tv(master, bfd_echo_recvtimer_cb, bs, &tv,
+ &bs->echo_recvtimer_ev);
}
void bfd_xmttimer_update(struct bfd_session *bs, uint64_t jitter)
@@ -72,7 +72,7 @@ void bfd_xmttimer_update(struct bfd_session *bs, uint64_t jitter)
tv_normalize(&tv);
- thread_add_timer_tv(master, bfd_xmt_cb, bs, &tv, &bs->xmttimer_ev);
+ event_add_timer_tv(master, bfd_xmt_cb, bs, &tv, &bs->xmttimer_ev);
}
void bfd_echo_xmttimer_update(struct bfd_session *bs, uint64_t jitter)
@@ -89,26 +89,26 @@ void bfd_echo_xmttimer_update(struct bfd_session *bs, uint64_t jitter)
tv_normalize(&tv);
- thread_add_timer_tv(master, bfd_echo_xmt_cb, bs, &tv,
- &bs->echo_xmttimer_ev);
+ event_add_timer_tv(master, bfd_echo_xmt_cb, bs, &tv,
+ &bs->echo_xmttimer_ev);
}
void bfd_recvtimer_delete(struct bfd_session *bs)
{
- THREAD_OFF(bs->recvtimer_ev);
+ EVENT_OFF(bs->recvtimer_ev);
}
void bfd_echo_recvtimer_delete(struct bfd_session *bs)
{
- THREAD_OFF(bs->echo_recvtimer_ev);
+ EVENT_OFF(bs->echo_recvtimer_ev);
}
void bfd_xmttimer_delete(struct bfd_session *bs)
{
- THREAD_OFF(bs->xmttimer_ev);
+ EVENT_OFF(bs->xmttimer_ev);
}
void bfd_echo_xmttimer_delete(struct bfd_session *bs)
{
- THREAD_OFF(bs->echo_xmttimer_ev);
+ EVENT_OFF(bs->echo_xmttimer_ev);
}
diff --git a/bgpd/bgp_advertise.c b/bgpd/bgp_advertise.c
index 3469d129e4..9686b08a98 100644
--- a/bgpd/bgp_advertise.c
+++ b/bgpd/bgp_advertise.c
@@ -9,7 +9,7 @@
#include "memory.h"
#include "prefix.h"
#include "hash.h"
-#include "thread.h"
+#include "frrevent.h"
#include "queue.h"
#include "filter.h"
diff --git a/bgpd/bgp_aspath.c b/bgpd/bgp_aspath.c
index 2cc7e46573..2c0de43c9b 100644
--- a/bgpd/bgp_aspath.c
+++ b/bgpd/bgp_aspath.c
@@ -2095,9 +2095,7 @@ void aspath_init(void)
void aspath_finish(void)
{
- hash_clean(ashash, (void (*)(void *))aspath_free);
- hash_free(ashash);
- ashash = NULL;
+ hash_clean_and_free(&ashash, (void (*)(void *))aspath_free);
if (snmp_stream)
stream_free(snmp_stream);
@@ -2157,11 +2155,15 @@ static void bgp_aggr_aspath_prepare(struct hash_bucket *hb, void *arg)
{
struct aspath *hb_aspath = hb->data;
struct aspath **aggr_aspath = arg;
+ struct aspath *aspath = NULL;
- if (*aggr_aspath)
- *aggr_aspath = aspath_aggregate(*aggr_aspath, hb_aspath);
- else
+ if (*aggr_aspath) {
+ aspath = aspath_aggregate(*aggr_aspath, hb_aspath);
+ aspath_free(*aggr_aspath);
+ *aggr_aspath = aspath;
+ } else {
*aggr_aspath = aspath_dup(hb_aspath);
+ }
}
void bgp_aggr_aspath_remove(void *arg)
diff --git a/bgpd/bgp_attr.c b/bgpd/bgp_attr.c
index de77bd5304..5b06bc3913 100644
--- a/bgpd/bgp_attr.c
+++ b/bgpd/bgp_attr.c
@@ -186,9 +186,7 @@ static void cluster_init(void)
static void cluster_finish(void)
{
- hash_clean(cluster_hash, (void (*)(void *))cluster_free);
- hash_free(cluster_hash);
- cluster_hash = NULL;
+ hash_clean_and_free(&cluster_hash, (void (*)(void *))cluster_free);
}
static struct hash *encap_hash = NULL;
@@ -372,13 +370,9 @@ static void encap_init(void)
static void encap_finish(void)
{
- hash_clean(encap_hash, (void (*)(void *))encap_free);
- hash_free(encap_hash);
- encap_hash = NULL;
+ hash_clean_and_free(&encap_hash, (void (*)(void *))encap_free);
#ifdef ENABLE_BGP_VNC
- hash_clean(vnc_hash, (void (*)(void *))encap_free);
- hash_free(vnc_hash);
- vnc_hash = NULL;
+ hash_clean_and_free(&vnc_hash, (void (*)(void *))encap_free);
#endif
}
@@ -694,12 +688,9 @@ static void srv6_init(void)
static void srv6_finish(void)
{
- hash_clean(srv6_l3vpn_hash, (void (*)(void *))srv6_l3vpn_free);
- hash_free(srv6_l3vpn_hash);
- srv6_l3vpn_hash = NULL;
- hash_clean(srv6_vpn_hash, (void (*)(void *))srv6_vpn_free);
- hash_free(srv6_vpn_hash);
- srv6_vpn_hash = NULL;
+ hash_clean_and_free(&srv6_l3vpn_hash,
+ (void (*)(void *))srv6_l3vpn_free);
+ hash_clean_and_free(&srv6_vpn_hash, (void (*)(void *))srv6_vpn_free);
}
static unsigned int transit_hash_key_make(const void *p)
@@ -726,9 +717,7 @@ static void transit_init(void)
static void transit_finish(void)
{
- hash_clean(transit_hash, (void (*)(void *))transit_free);
- hash_free(transit_hash);
- transit_hash = NULL;
+ hash_clean_and_free(&transit_hash, (void (*)(void *))transit_free);
}
/* Attribute hash routines. */
@@ -810,55 +799,55 @@ bool attrhash_cmp(const void *p1, const void *p2)
&& attr1->med == attr2->med
&& attr1->local_pref == attr2->local_pref
&& attr1->rmap_change_flags == attr2->rmap_change_flags) {
- if (attr1->aggregator_as == attr2->aggregator_as
- && attr1->aggregator_addr.s_addr
- == attr2->aggregator_addr.s_addr
- && attr1->weight == attr2->weight
- && attr1->tag == attr2->tag
- && attr1->label_index == attr2->label_index
- && attr1->mp_nexthop_len == attr2->mp_nexthop_len
- && bgp_attr_get_ecommunity(attr1)
- == bgp_attr_get_ecommunity(attr2)
- && bgp_attr_get_ipv6_ecommunity(attr1)
- == bgp_attr_get_ipv6_ecommunity(attr2)
- && bgp_attr_get_lcommunity(attr1)
- == bgp_attr_get_lcommunity(attr2)
- && bgp_attr_get_cluster(attr1)
- == bgp_attr_get_cluster(attr2)
- && bgp_attr_get_transit(attr1)
- == bgp_attr_get_transit(attr2)
- && bgp_attr_get_aigp_metric(attr1)
- == bgp_attr_get_aigp_metric(attr2)
- && attr1->rmap_table_id == attr2->rmap_table_id
- && (attr1->encap_tunneltype == attr2->encap_tunneltype)
- && encap_same(attr1->encap_subtlvs, attr2->encap_subtlvs)
+ if (attr1->aggregator_as == attr2->aggregator_as &&
+ attr1->aggregator_addr.s_addr ==
+ attr2->aggregator_addr.s_addr &&
+ attr1->weight == attr2->weight &&
+ attr1->tag == attr2->tag &&
+ attr1->label_index == attr2->label_index &&
+ attr1->mp_nexthop_len == attr2->mp_nexthop_len &&
+ bgp_attr_get_ecommunity(attr1) ==
+ bgp_attr_get_ecommunity(attr2) &&
+ bgp_attr_get_ipv6_ecommunity(attr1) ==
+ bgp_attr_get_ipv6_ecommunity(attr2) &&
+ bgp_attr_get_lcommunity(attr1) ==
+ bgp_attr_get_lcommunity(attr2) &&
+ bgp_attr_get_cluster(attr1) ==
+ bgp_attr_get_cluster(attr2) &&
+ bgp_attr_get_transit(attr1) ==
+ bgp_attr_get_transit(attr2) &&
+ bgp_attr_get_aigp_metric(attr1) ==
+ bgp_attr_get_aigp_metric(attr2) &&
+ attr1->rmap_table_id == attr2->rmap_table_id &&
+ (attr1->encap_tunneltype == attr2->encap_tunneltype) &&
+ encap_same(attr1->encap_subtlvs, attr2->encap_subtlvs)
#ifdef ENABLE_BGP_VNC
&& encap_same(bgp_attr_get_vnc_subtlvs(attr1),
bgp_attr_get_vnc_subtlvs(attr2))
#endif
&& IPV6_ADDR_SAME(&attr1->mp_nexthop_global,
- &attr2->mp_nexthop_global)
- && IPV6_ADDR_SAME(&attr1->mp_nexthop_local,
- &attr2->mp_nexthop_local)
- && IPV4_ADDR_SAME(&attr1->mp_nexthop_global_in,
- &attr2->mp_nexthop_global_in)
- && IPV4_ADDR_SAME(&attr1->originator_id,
- &attr2->originator_id)
- && overlay_index_same(attr1, attr2)
- && !memcmp(&attr1->esi, &attr2->esi, sizeof(esi_t))
- && attr1->es_flags == attr2->es_flags
- && attr1->mm_sync_seqnum == attr2->mm_sync_seqnum
- && attr1->df_pref == attr2->df_pref
- && attr1->df_alg == attr2->df_alg
- && attr1->nh_ifindex == attr2->nh_ifindex
- && attr1->nh_lla_ifindex == attr2->nh_lla_ifindex
- && attr1->distance == attr2->distance
- && srv6_l3vpn_same(attr1->srv6_l3vpn, attr2->srv6_l3vpn)
- && srv6_vpn_same(attr1->srv6_vpn, attr2->srv6_vpn)
- && attr1->srte_color == attr2->srte_color
- && attr1->nh_type == attr2->nh_type
- && attr1->bh_type == attr2->bh_type
- && attr1->otc == attr2->otc)
+ &attr2->mp_nexthop_global) &&
+ IPV6_ADDR_SAME(&attr1->mp_nexthop_local,
+ &attr2->mp_nexthop_local) &&
+ IPV4_ADDR_SAME(&attr1->mp_nexthop_global_in,
+ &attr2->mp_nexthop_global_in) &&
+ IPV4_ADDR_SAME(&attr1->originator_id,
+ &attr2->originator_id) &&
+ overlay_index_same(attr1, attr2) &&
+ !memcmp(&attr1->esi, &attr2->esi, sizeof(esi_t)) &&
+ attr1->es_flags == attr2->es_flags &&
+ attr1->mm_sync_seqnum == attr2->mm_sync_seqnum &&
+ attr1->df_pref == attr2->df_pref &&
+ attr1->df_alg == attr2->df_alg &&
+ attr1->nh_ifindex == attr2->nh_ifindex &&
+ attr1->nh_lla_ifindex == attr2->nh_lla_ifindex &&
+ attr1->distance == attr2->distance &&
+ srv6_l3vpn_same(attr1->srv6_l3vpn, attr2->srv6_l3vpn) &&
+ srv6_vpn_same(attr1->srv6_vpn, attr2->srv6_vpn) &&
+ attr1->srte_color == attr2->srte_color &&
+ attr1->nh_type == attr2->nh_type &&
+ attr1->bh_type == attr2->bh_type &&
+ attr1->otc == attr2->otc)
return true;
}
@@ -881,9 +870,7 @@ static void attr_vfree(void *attr)
static void attrhash_finish(void)
{
- hash_clean(attrhash, attr_vfree);
- hash_free(attrhash);
- attrhash = NULL;
+ hash_clean_and_free(&attrhash, attr_vfree);
}
static void attr_show_all_iterator(struct hash_bucket *bucket, struct vty *vty)
@@ -2940,9 +2927,21 @@ bgp_attr_psid_sub(uint8_t type, uint16_t length,
int srgb_count;
uint8_t sid_type, sid_flags;
+ /*
+ * Check that we actually have at least as much data as
+ * specified by the length field
+ */
+ if (STREAM_READABLE(peer->curr) < length) {
+ flog_err(
+ EC_BGP_ATTR_LEN,
+ "Prefix SID specifies length %hu, but only %zu bytes remain",
+ length, STREAM_READABLE(peer->curr));
+ return bgp_attr_malformed(args, BGP_NOTIFY_UPDATE_ATTR_LENG_ERR,
+ args->total);
+ }
+
if (type == BGP_PREFIX_SID_LABEL_INDEX) {
- if (STREAM_READABLE(peer->curr) < length
- || length != BGP_PREFIX_SID_LABEL_INDEX_LENGTH) {
+ if (length != BGP_PREFIX_SID_LABEL_INDEX_LENGTH) {
flog_err(EC_BGP_ATTR_LEN,
"Prefix SID label index length is %hu instead of %u",
length, BGP_PREFIX_SID_LABEL_INDEX_LENGTH);
@@ -2964,12 +2963,8 @@ bgp_attr_psid_sub(uint8_t type, uint16_t length,
/* Store label index; subsequently, we'll check on
* address-family */
attr->label_index = label_index;
- }
-
- /* Placeholder code for the IPv6 SID type */
- else if (type == BGP_PREFIX_SID_IPV6) {
- if (STREAM_READABLE(peer->curr) < length
- || length != BGP_PREFIX_SID_IPV6_LENGTH) {
+ } else if (type == BGP_PREFIX_SID_IPV6) {
+ if (length != BGP_PREFIX_SID_IPV6_LENGTH) {
flog_err(EC_BGP_ATTR_LEN,
"Prefix SID IPv6 length is %hu instead of %u",
length, BGP_PREFIX_SID_IPV6_LENGTH);
@@ -2983,10 +2978,7 @@ bgp_attr_psid_sub(uint8_t type, uint16_t length,
stream_getw(peer->curr);
stream_get(&ipv6_sid, peer->curr, 16);
- }
-
- /* Placeholder code for the Originator SRGB type */
- else if (type == BGP_PREFIX_SID_ORIGINATOR_SRGB) {
+ } else if (type == BGP_PREFIX_SID_ORIGINATOR_SRGB) {
/*
* ietf-idr-bgp-prefix-sid-05:
* Length is the total length of the value portion of the
@@ -3012,19 +3004,6 @@ bgp_attr_psid_sub(uint8_t type, uint16_t length,
}
/*
- * Check that we actually have at least as much data as
- * specified by the length field
- */
- if (STREAM_READABLE(peer->curr) < length) {
- flog_err(EC_BGP_ATTR_LEN,
- "Prefix SID Originator SRGB specifies length %hu, but only %zu bytes remain",
- length, STREAM_READABLE(peer->curr));
- return bgp_attr_malformed(
- args, BGP_NOTIFY_UPDATE_ATTR_LENG_ERR,
- args->total);
- }
-
- /*
* Check that the portion of the TLV containing the sequence of
* SRGBs corresponds to a multiple of the SRGB size; to get
* that length, we skip the 16 bit flags field
@@ -3047,12 +3026,8 @@ bgp_attr_psid_sub(uint8_t type, uint16_t length,
stream_get(&srgb_base, peer->curr, 3);
stream_get(&srgb_range, peer->curr, 3);
}
- }
-
- /* Placeholder code for the VPN-SID Service type */
- else if (type == BGP_PREFIX_SID_VPN_SID) {
- if (STREAM_READABLE(peer->curr) < length
- || length != BGP_PREFIX_SID_VPN_SID_LENGTH) {
+ } else if (type == BGP_PREFIX_SID_VPN_SID) {
+ if (length != BGP_PREFIX_SID_VPN_SID_LENGTH) {
flog_err(EC_BGP_ATTR_LEN,
"Prefix SID VPN SID length is %hu instead of %u",
length, BGP_PREFIX_SID_VPN_SID_LENGTH);
@@ -3086,39 +3061,22 @@ bgp_attr_psid_sub(uint8_t type, uint16_t length,
attr->srv6_vpn->sid_flags = sid_flags;
sid_copy(&attr->srv6_vpn->sid, &ipv6_sid);
attr->srv6_vpn = srv6_vpn_intern(attr->srv6_vpn);
- }
-
- /* Placeholder code for the SRv6 L3 Service type */
- else if (type == BGP_PREFIX_SID_SRV6_L3_SERVICE) {
- if (STREAM_READABLE(peer->curr) < length) {
+ } else if (type == BGP_PREFIX_SID_SRV6_L3_SERVICE) {
+ if (STREAM_READABLE(peer->curr) < 1) {
flog_err(
EC_BGP_ATTR_LEN,
- "Prefix SID SRv6 L3-Service length is %hu, but only %zu bytes remain",
- length, STREAM_READABLE(peer->curr));
- return bgp_attr_malformed(args,
- BGP_NOTIFY_UPDATE_ATTR_LENG_ERR,
- args->total);
+ "Prefix SID SRV6 L3 Service not enough data left, it must be at least 1 byte");
+ return bgp_attr_malformed(
+ args, BGP_NOTIFY_UPDATE_ATTR_LENG_ERR,
+ args->total);
}
-
/* ignore reserved */
stream_getc(peer->curr);
return bgp_attr_srv6_service(args);
}
-
/* Placeholder code for Unsupported TLV */
else {
-
- if (STREAM_READABLE(peer->curr) < length) {
- flog_err(
- EC_BGP_ATTR_LEN,
- "Prefix SID SRv6 length is %hu - too long, only %zu remaining in this UPDATE",
- length, STREAM_READABLE(peer->curr));
- return bgp_attr_malformed(
- args, BGP_NOTIFY_UPDATE_ATTR_LENG_ERR,
- args->total);
- }
-
if (bgp_debug_update(peer, NULL, NULL, 1))
zlog_debug(
"%s attr Prefix-SID sub-type=%u is not supported, skipped",
diff --git a/bgpd/bgp_bfd.c b/bgpd/bgp_bfd.c
index 4a81b69ced..d1ddfd0460 100644
--- a/bgpd/bgp_bfd.c
+++ b/bgpd/bgp_bfd.c
@@ -11,7 +11,7 @@
#include "linklist.h"
#include "memory.h"
#include "prefix.h"
-#include "thread.h"
+#include "frrevent.h"
#include "buffer.h"
#include "stream.h"
#include "vrf.h"
@@ -55,7 +55,7 @@ static void bfd_session_status_update(struct bfd_session_params *bsp,
}
peer->last_reset = PEER_DOWN_BFD_DOWN;
- /* draft-ietf-idr-bfd-subcode */
+ /* rfc9384 */
if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status))
bgp_notify_send(peer, BGP_NOTIFY_CEASE,
BGP_NOTIFY_CEASE_BFD_DOWN);
@@ -609,7 +609,7 @@ DEFUN(no_neighbor_bfd_profile, no_neighbor_bfd_profile_cmd,
}
#endif /* HAVE_BFDD */
-void bgp_bfd_init(struct thread_master *tm)
+void bgp_bfd_init(struct event_loop *tm)
{
/* Initialize BFD client functions */
bfd_protocol_integration_init(zclient, tm);
diff --git a/bgpd/bgp_bfd.h b/bgpd/bgp_bfd.h
index c4045d4745..61b4b76605 100644
--- a/bgpd/bgp_bfd.h
+++ b/bgpd/bgp_bfd.h
@@ -12,7 +12,7 @@
((((peer)->sort == BGP_PEER_IBGP) && !(peer)->shared_network) \
|| is_ebgp_multihop_configured((peer)))
-extern void bgp_bfd_init(struct thread_master *tm);
+extern void bgp_bfd_init(struct event_loop *tm);
extern void bgp_bfd_peer_config_write(struct vty *vty, const struct peer *peer,
const char *addr);
diff --git a/bgpd/bgp_bmp.c b/bgpd/bgp_bmp.c
index 92d92ada2b..baf164679c 100644
--- a/bgpd/bgp_bmp.c
+++ b/bgpd/bgp_bmp.c
@@ -11,7 +11,7 @@
#include "sockunion.h"
#include "command.h"
#include "prefix.h"
-#include "thread.h"
+#include "frrevent.h"
#include "linklist.h"
#include "queue.h"
#include "pullwr.h"
@@ -389,13 +389,13 @@ static struct stream *bmp_peerstate(struct peer *peer, bool down)
/* Local Port, Remote Port */
if (peer->su_local->sa.sa_family == AF_INET6)
- stream_putw(s, peer->su_local->sin6.sin6_port);
+ stream_putw(s, htons(peer->su_local->sin6.sin6_port));
else if (peer->su_local->sa.sa_family == AF_INET)
- stream_putw(s, peer->su_local->sin.sin_port);
+ stream_putw(s, htons(peer->su_local->sin.sin_port));
if (peer->su_remote->sa.sa_family == AF_INET6)
- stream_putw(s, peer->su_remote->sin6.sin6_port);
+ stream_putw(s, htons(peer->su_remote->sin6.sin6_port));
else if (peer->su_remote->sa.sa_family == AF_INET)
- stream_putw(s, peer->su_remote->sin.sin_port);
+ stream_putw(s, htons(peer->su_remote->sin.sin_port));
static const uint8_t dummy_open[] = {
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
@@ -1175,8 +1175,8 @@ static bool bmp_wrqueue(struct bmp *bmp, struct pullwr *pullwr)
(bqe->safi == SAFI_MPLS_VPN);
struct prefix_rd *prd = is_vpn ? &bqe->rd : NULL;
- bn = bgp_afi_node_lookup(bmp->targets->bgp->rib[afi][safi], afi, safi,
- &bqe->p, prd);
+ bn = bgp_safi_node_lookup(bmp->targets->bgp->rib[afi][safi], safi,
+ &bqe->p, prd);
if (bmp->targets->afimon[afi][safi] & BMP_MON_POSTPOLICY) {
@@ -1335,17 +1335,17 @@ static void bmp_stat_put_u32(struct stream *s, size_t *cnt, uint16_t type,
(*cnt)++;
}
-static void bmp_stats(struct thread *thread)
+static void bmp_stats(struct event *thread)
{
- struct bmp_targets *bt = THREAD_ARG(thread);
+ struct bmp_targets *bt = EVENT_ARG(thread);
struct stream *s;
struct peer *peer;
struct listnode *node;
struct timeval tv;
if (bt->stat_msec)
- thread_add_timer_msec(bm->master, bmp_stats, bt, bt->stat_msec,
- &bt->t_stats);
+ event_add_timer_msec(bm->master, bmp_stats, bt, bt->stat_msec,
+ &bt->t_stats);
gettimeofday(&tv, NULL);
@@ -1388,9 +1388,9 @@ static void bmp_stats(struct thread *thread)
}
/* read from the BMP socket to detect session termination */
-static void bmp_read(struct thread *t)
+static void bmp_read(struct event *t)
{
- struct bmp *bmp = THREAD_ARG(t);
+ struct bmp *bmp = EVENT_ARG(t);
char buf[1024];
ssize_t n;
@@ -1409,7 +1409,7 @@ static void bmp_read(struct thread *t)
return;
}
- thread_add_read(bm->master, bmp_read, bmp, bmp->socket, &bmp->t_read);
+ event_add_read(bm->master, bmp_read, bmp, bmp->socket, &bmp->t_read);
}
static struct bmp *bmp_open(struct bmp_targets *bt, int bmp_sock)
@@ -1485,21 +1485,21 @@ static struct bmp *bmp_open(struct bmp_targets *bt, int bmp_sock)
bmp->state = BMP_PeerUp;
bmp->pullwr = pullwr_new(bm->master, bmp_sock, bmp, bmp_wrfill,
bmp_wrerr);
- thread_add_read(bm->master, bmp_read, bmp, bmp_sock, &bmp->t_read);
+ event_add_read(bm->master, bmp_read, bmp, bmp_sock, &bmp->t_read);
bmp_send_initiation(bmp);
return bmp;
}
/* Accept BMP connection. */
-static void bmp_accept(struct thread *thread)
+static void bmp_accept(struct event *thread)
{
union sockunion su;
- struct bmp_listener *bl = THREAD_ARG(thread);
+ struct bmp_listener *bl = EVENT_ARG(thread);
int bmp_sock;
/* We continue hearing BMP socket. */
- thread_add_read(bm->master, bmp_accept, bl, bl->sock, &bl->t_accept);
+ event_add_read(bm->master, bmp_accept, bl, bl->sock, &bl->t_accept);
memset(&su, 0, sizeof(union sockunion));
@@ -1517,7 +1517,7 @@ static void bmp_close(struct bmp *bmp)
struct bmp_queue_entry *bqe;
struct bmp_mirrorq *bmq;
- THREAD_OFF(bmp->t_read);
+ EVENT_OFF(bmp->t_read);
if (bmp->active)
bmp_active_disconnected(bmp->active);
@@ -1529,7 +1529,7 @@ static void bmp_close(struct bmp *bmp)
if (!bqe->refcount)
XFREE(MTYPE_BMP_QUEUE, bqe);
- THREAD_OFF(bmp->t_read);
+ EVENT_OFF(bmp->t_read);
pullwr_del(bmp->pullwr);
close(bmp->socket);
}
@@ -1644,7 +1644,7 @@ static void bmp_targets_put(struct bmp_targets *bt)
struct bmp *bmp;
struct bmp_active *ba;
- THREAD_OFF(bt->t_stats);
+ EVENT_OFF(bt->t_stats);
frr_each_safe (bmp_actives, &bt->actives, ba)
bmp_active_put(ba);
@@ -1721,7 +1721,7 @@ static void bmp_listener_start(struct bmp_listener *bl)
goto out_sock;
bl->sock = sock;
- thread_add_read(bm->master, bmp_accept, bl, sock, &bl->t_accept);
+ event_add_read(bm->master, bmp_accept, bl, sock, &bl->t_accept);
return;
out_sock:
close(sock);
@@ -1729,7 +1729,7 @@ out_sock:
static void bmp_listener_stop(struct bmp_listener *bl)
{
- THREAD_OFF(bl->t_accept);
+ EVENT_OFF(bl->t_accept);
if (bl->sock != -1)
close(bl->sock);
@@ -1768,9 +1768,9 @@ static struct bmp_active *bmp_active_get(struct bmp_targets *bt,
static void bmp_active_put(struct bmp_active *ba)
{
- THREAD_OFF(ba->t_timer);
- THREAD_OFF(ba->t_read);
- THREAD_OFF(ba->t_write);
+ EVENT_OFF(ba->t_timer);
+ EVENT_OFF(ba->t_read);
+ EVENT_OFF(ba->t_write);
bmp_actives_del(&ba->targets->actives, ba);
@@ -1902,18 +1902,18 @@ static void bmp_active_resolved(struct resolver_query *resq, const char *errstr,
bmp_active_connect(ba);
}
-static void bmp_active_thread(struct thread *t)
+static void bmp_active_thread(struct event *t)
{
- struct bmp_active *ba = THREAD_ARG(t);
+ struct bmp_active *ba = EVENT_ARG(t);
socklen_t slen;
int status, ret;
vrf_id_t vrf_id;
/* all 3 end up here, though only timer or read+write are active
* at a time */
- THREAD_OFF(ba->t_timer);
- THREAD_OFF(ba->t_read);
- THREAD_OFF(ba->t_write);
+ EVENT_OFF(ba->t_timer);
+ EVENT_OFF(ba->t_read);
+ EVENT_OFF(ba->t_write);
ba->last_err = NULL;
@@ -1967,9 +1967,9 @@ static void bmp_active_disconnected(struct bmp_active *ba)
static void bmp_active_setup(struct bmp_active *ba)
{
- THREAD_OFF(ba->t_timer);
- THREAD_OFF(ba->t_read);
- THREAD_OFF(ba->t_write);
+ EVENT_OFF(ba->t_timer);
+ EVENT_OFF(ba->t_read);
+ EVENT_OFF(ba->t_write);
if (ba->bmp)
return;
@@ -1980,12 +1980,12 @@ static void bmp_active_setup(struct bmp_active *ba)
ba->curretry = ba->maxretry;
if (ba->socket == -1)
- thread_add_timer_msec(bm->master, bmp_active_thread, ba,
- ba->curretry, &ba->t_timer);
+ event_add_timer_msec(bm->master, bmp_active_thread, ba,
+ ba->curretry, &ba->t_timer);
else {
- thread_add_read(bm->master, bmp_active_thread, ba, ba->socket,
- &ba->t_read);
- thread_add_write(bm->master, bmp_active_thread, ba, ba->socket,
+ event_add_read(bm->master, bmp_active_thread, ba, ba->socket,
+ &ba->t_read);
+ event_add_write(bm->master, bmp_active_thread, ba, ba->socket,
&ba->t_write);
}
}
@@ -2190,7 +2190,7 @@ DEFPY(bmp_stats_cfg,
{
VTY_DECLVAR_CONTEXT_SUB(bmp_targets, bt);
- THREAD_OFF(bt->t_stats);
+ EVENT_OFF(bt->t_stats);
if (no)
bt->stat_msec = 0;
else if (interval_str)
@@ -2199,8 +2199,8 @@ DEFPY(bmp_stats_cfg,
bt->stat_msec = BMP_STAT_DEFAULT_TIMER;
if (bt->stat_msec)
- thread_add_timer_msec(bm->master, bmp_stats, bt, bt->stat_msec,
- &bt->t_stats);
+ event_add_timer_msec(bm->master, bmp_stats, bt, bt->stat_msec,
+ &bt->t_stats);
return CMD_SUCCESS;
}
@@ -2408,7 +2408,7 @@ DEFPY(show_bmp,
uptime[0] = '\0';
if (ba->t_timer) {
- long trem = thread_timer_remain_second(
+ long trem = event_timer_remain_second(
ba->t_timer);
peer_uptime(monotime(NULL) - trem,
@@ -2526,7 +2526,7 @@ static int bmp_config_write(struct bgp *bgp, struct vty *vty)
return 0;
}
-static int bgp_bmp_init(struct thread_master *tm)
+static int bgp_bmp_init(struct event_loop *tm)
{
install_node(&bmp_node);
install_default(BMP_NODE);
diff --git a/bgpd/bgp_bmp.h b/bgpd/bgp_bmp.h
index 0c909e139b..ab7463fadc 100644
--- a/bgpd/bgp_bmp.h
+++ b/bgpd/bgp_bmp.h
@@ -112,7 +112,7 @@ struct bmp {
int socket;
char remote[SU_ADDRSTRLEN + 6];
- struct thread *t_read;
+ struct event *t_read;
struct pullwr *pullwr;
@@ -176,7 +176,7 @@ struct bmp_active {
union sockunion addrs[8];
int socket;
const char *last_err;
- struct thread *t_timer, *t_read, *t_write;
+ struct event *t_timer, *t_read, *t_write;
};
/* config & state for passive / listening sockets */
@@ -190,7 +190,7 @@ struct bmp_listener {
union sockunion addr;
int port;
- struct thread *t_accept;
+ struct event *t_accept;
int sock;
};
@@ -226,7 +226,7 @@ struct bmp_targets {
struct bmp_actives_head actives;
- struct thread *t_stats;
+ struct event *t_stats;
struct bmp_session_head sessions;
struct bmp_qhash_head updhash;
diff --git a/bgpd/bgp_community.c b/bgpd/bgp_community.c
index ff6e477355..f56bfc8bdc 100644
--- a/bgpd/bgp_community.c
+++ b/bgpd/bgp_community.c
@@ -919,9 +919,7 @@ static void community_hash_free(void *data)
void community_finish(void)
{
- hash_clean(comhash, community_hash_free);
- hash_free(comhash);
- comhash = NULL;
+ hash_clean_and_free(&comhash, community_hash_free);
}
static struct community *bgp_aggr_community_lookup(
diff --git a/bgpd/bgp_community_alias.c b/bgpd/bgp_community_alias.c
index 1ebe7c4c8c..96dc1ec8f9 100644
--- a/bgpd/bgp_community_alias.c
+++ b/bgpd/bgp_community_alias.c
@@ -74,10 +74,8 @@ static void bgp_ca_free(void *ca)
void bgp_community_alias_finish(void)
{
- hash_clean(bgp_ca_community_hash, bgp_ca_free);
- hash_free(bgp_ca_community_hash);
- hash_clean(bgp_ca_alias_hash, bgp_ca_free);
- hash_free(bgp_ca_alias_hash);
+ hash_clean_and_free(&bgp_ca_community_hash, bgp_ca_free);
+ hash_clean_and_free(&bgp_ca_alias_hash, bgp_ca_free);
}
static void bgp_community_alias_show_iterator(struct hash_bucket *hb,
diff --git a/bgpd/bgp_conditional_adv.c b/bgpd/bgp_conditional_adv.c
index 051e336e52..53652f7dce 100644
--- a/bgpd/bgp_conditional_adv.c
+++ b/bgpd/bgp_conditional_adv.c
@@ -150,7 +150,7 @@ static void bgp_conditional_adv_routes(struct peer *peer, afi_t afi,
/* Handler of conditional advertisement timer event.
* Each route in the condition-map is evaluated.
*/
-static void bgp_conditional_adv_timer(struct thread *t)
+static void bgp_conditional_adv_timer(struct event *t)
{
afi_t afi;
safi_t safi;
@@ -165,11 +165,11 @@ static void bgp_conditional_adv_timer(struct thread *t)
route_map_result_t ret;
bool advmap_table_changed = false;
- bgp = THREAD_ARG(t);
+ bgp = EVENT_ARG(t);
assert(bgp);
- thread_add_timer(bm->master, bgp_conditional_adv_timer, bgp,
- bgp->condition_check_period, &bgp->t_condition_check);
+ event_add_timer(bm->master, bgp_conditional_adv_timer, bgp,
+ bgp->condition_check_period, &bgp->t_condition_check);
/* loop through each peer and check if we have peers with
* advmap_table_change attribute set, to make sure we send
@@ -328,9 +328,9 @@ void bgp_conditional_adv_enable(struct peer *peer, afi_t afi, safi_t safi)
}
/* Register for conditional routes polling timer */
- if (!thread_is_scheduled(bgp->t_condition_check))
- thread_add_timer(bm->master, bgp_conditional_adv_timer, bgp, 0,
- &bgp->t_condition_check);
+ if (!event_is_scheduled(bgp->t_condition_check))
+ event_add_timer(bm->master, bgp_conditional_adv_timer, bgp, 0,
+ &bgp->t_condition_check);
}
void bgp_conditional_adv_disable(struct peer *peer, afi_t afi, safi_t safi)
@@ -351,7 +351,7 @@ void bgp_conditional_adv_disable(struct peer *peer, afi_t afi, safi_t safi)
}
/* Last filter removed. So cancel conditional routes polling thread. */
- THREAD_OFF(bgp->t_condition_check);
+ EVENT_OFF(bgp->t_condition_check);
}
static void peer_advertise_map_filter_update(struct peer *peer, afi_t afi,
diff --git a/bgpd/bgp_damp.c b/bgpd/bgp_damp.c
index 54bbf9b9ca..a6d0e74dc0 100644
--- a/bgpd/bgp_damp.c
+++ b/bgpd/bgp_damp.c
@@ -10,7 +10,7 @@
#include "memory.h"
#include "command.h"
#include "log.h"
-#include "thread.h"
+#include "frrevent.h"
#include "queue.h"
#include "filter.h"
@@ -98,17 +98,17 @@ int bgp_damp_decay(time_t tdiff, int penalty, struct bgp_damp_config *bdc)
/* Handler of reuse timer event. Each route in the current reuse-list
is evaluated. RFC2439 Section 4.8.7. */
-static void bgp_reuse_timer(struct thread *t)
+static void bgp_reuse_timer(struct event *t)
{
struct bgp_damp_info *bdi;
struct bgp_damp_info *next;
time_t t_now, t_diff;
- struct bgp_damp_config *bdc = THREAD_ARG(t);
+ struct bgp_damp_config *bdc = EVENT_ARG(t);
bdc->t_reuse = NULL;
- thread_add_timer(bm->master, bgp_reuse_timer, bdc, DELTA_REUSE,
- &bdc->t_reuse);
+ event_add_timer(bm->master, bgp_reuse_timer, bdc, DELTA_REUSE,
+ &bdc->t_reuse);
t_now = monotime(NULL);
@@ -395,8 +395,8 @@ int bgp_damp_enable(struct bgp *bgp, afi_t afi, safi_t safi, time_t half,
bgp_damp_parameter_set(half, reuse, suppress, max, bdc);
/* Register reuse timer. */
- thread_add_timer(bm->master, bgp_reuse_timer, bdc, DELTA_REUSE,
- &bdc->t_reuse);
+ event_add_timer(bm->master, bgp_reuse_timer, bdc, DELTA_REUSE,
+ &bdc->t_reuse);
return 0;
}
@@ -451,7 +451,7 @@ int bgp_damp_disable(struct bgp *bgp, afi_t afi, safi_t safi)
return 0;
/* Cancel reuse event. */
- THREAD_OFF(bdc->t_reuse);
+ EVENT_OFF(bdc->t_reuse);
/* Clean BGP dampening information. */
bgp_damp_info_clean(afi, safi);
diff --git a/bgpd/bgp_damp.h b/bgpd/bgp_damp.h
index 129e444164..5708e6fd55 100644
--- a/bgpd/bgp_damp.h
+++ b/bgpd/bgp_damp.h
@@ -92,7 +92,7 @@ struct bgp_damp_config {
struct bgp_damp_info *no_reuse_list;
/* Reuse timer thread per-set base. */
- struct thread *t_reuse;
+ struct event *t_reuse;
afi_t afi;
safi_t safi;
diff --git a/bgpd/bgp_dump.c b/bgpd/bgp_dump.c
index 794dd7b8b6..fe77e7e250 100644
--- a/bgpd/bgp_dump.c
+++ b/bgpd/bgp_dump.c
@@ -10,7 +10,7 @@
#include "sockunion.h"
#include "command.h"
#include "prefix.h"
-#include "thread.h"
+#include "frrevent.h"
#include "linklist.h"
#include "queue.h"
#include "memory.h"
@@ -69,11 +69,11 @@ struct bgp_dump {
char *interval_str;
- struct thread *t_interval;
+ struct event *t_interval;
};
static int bgp_dump_unset(struct bgp_dump *bgp_dump);
-static void bgp_dump_interval_func(struct thread *);
+static void bgp_dump_interval_func(struct event *);
/* BGP packet dump output buffer. */
struct stream *bgp_dump_obuf;
@@ -154,13 +154,13 @@ static int bgp_dump_interval_add(struct bgp_dump *bgp_dump, int interval)
interval = interval
- secs_into_day % interval; /* always > 0 */
}
- thread_add_timer(bm->master, bgp_dump_interval_func, bgp_dump,
- interval, &bgp_dump->t_interval);
+ event_add_timer(bm->master, bgp_dump_interval_func, bgp_dump,
+ interval, &bgp_dump->t_interval);
} else {
/* One-off dump: execute immediately, don't affect any scheduled
* dumps */
- thread_add_event(bm->master, bgp_dump_interval_func, bgp_dump,
- 0, &bgp_dump->t_interval);
+ event_add_event(bm->master, bgp_dump_interval_func, bgp_dump, 0,
+ &bgp_dump->t_interval);
}
return 0;
@@ -428,10 +428,10 @@ static unsigned int bgp_dump_routes_func(int afi, int first_run,
return seq;
}
-static void bgp_dump_interval_func(struct thread *t)
+static void bgp_dump_interval_func(struct event *t)
{
struct bgp_dump *bgp_dump;
- bgp_dump = THREAD_ARG(t);
+ bgp_dump = EVENT_ARG(t);
/* Reschedule dump even if file couldn't be opened this time... */
if (bgp_dump_open_file(bgp_dump) != NULL) {
@@ -691,7 +691,7 @@ static int bgp_dump_unset(struct bgp_dump *bgp_dump)
}
/* Removing interval event. */
- THREAD_OFF(bgp_dump->t_interval);
+ EVENT_OFF(bgp_dump->t_interval);
bgp_dump->interval = 0;
@@ -845,8 +845,7 @@ void bgp_dump_init(void)
memset(&bgp_dump_routes, 0, sizeof(bgp_dump_routes));
bgp_dump_obuf =
- stream_new((BGP_STANDARD_MESSAGE_MAX_PACKET_SIZE * 2)
- + BGP_DUMP_MSG_HEADER + BGP_DUMP_HEADER_SIZE);
+ stream_new(BGP_MAX_PACKET_SIZE + BGP_MAX_PACKET_SIZE_OVERFLOW);
install_node(&bgp_dump_node);
diff --git a/bgpd/bgp_ecommunity.c b/bgpd/bgp_ecommunity.c
index 0a4ebc5130..dc1905868b 100644
--- a/bgpd/bgp_ecommunity.c
+++ b/bgpd/bgp_ecommunity.c
@@ -364,9 +364,7 @@ void ecommunity_init(void)
void ecommunity_finish(void)
{
- hash_clean(ecomhash, (void (*)(void *))ecommunity_hash_free);
- hash_free(ecomhash);
- ecomhash = NULL;
+ hash_clean_and_free(&ecomhash, (void (*)(void *))ecommunity_hash_free);
}
/* Extended Communities token enum. */
@@ -505,6 +503,8 @@ static const char *ecommunity_gettoken(const char *str,
uint8_t ecomm_type;
char buf[INET_ADDRSTRLEN + 1];
struct ecommunity_val *eval = (struct ecommunity_val *)eval_ptr;
+ uint64_t tmp_as = 0;
+
/* Skip white space. */
while (isspace((unsigned char)*p)) {
p++;
@@ -583,9 +583,18 @@ static const char *ecommunity_gettoken(const char *str,
goto error;
endptr++;
- as = strtoul(endptr, &endptr, 10);
- if (*endptr != '\0' || as == BGP_AS4_MAX)
+ errno = 0;
+ tmp_as = strtoul(endptr, &endptr, 10);
+ /* 'unsigned long' is a uint64 on 64-bit
+ * systems, and uint32 on 32-bit systems. So for
+ * 64-bit we can just directly check the value
+ * against BGP_AS4_MAX/UINT32_MAX, and for
+ * 32-bit we can check for errno (set to ERANGE
+ * upon overflow).
+ */
+ if (*endptr != '\0' || tmp_as == BGP_AS4_MAX || errno)
goto error;
+ as = (as_t)tmp_as;
memcpy(buf, p, (limit - p));
buf[limit - p] = '\0';
@@ -627,9 +636,19 @@ static const char *ecommunity_gettoken(const char *str,
goto error;
} else {
/* ASN */
- as = strtoul(buf, &endptr, 10);
- if (*endptr != '\0' || as == BGP_AS4_MAX)
+ errno = 0;
+ tmp_as = strtoul(buf, &endptr, 10);
+ /* 'unsigned long' is a uint64 on 64-bit
+ * systems, and uint32 on 32-bit systems. So for
+ * 64-bit we can just directly check the value
+ * against BGP_AS4_MAX/UINT32_MAX, and for
+ * 32-bit we can check for errno (set to ERANGE
+ * upon overflow).
+ */
+ if (*endptr != '\0' || tmp_as > BGP_AS4_MAX ||
+ errno)
goto error;
+ as = (as_t)tmp_as;
}
} else if (*p == '.') {
if (separator)
diff --git a/bgpd/bgp_evpn.c b/bgpd/bgp_evpn.c
index a8560ab539..81117e94ef 100644
--- a/bgpd/bgp_evpn.c
+++ b/bgpd/bgp_evpn.c
@@ -674,11 +674,9 @@ struct bgp_dest *bgp_evpn_global_node_get(struct bgp_table *table, afi_t afi,
/*
* Wrapper for node lookup in global table.
*/
-struct bgp_dest *
-bgp_evpn_global_node_lookup(struct bgp_table *table, afi_t afi, safi_t safi,
- const struct prefix_evpn *evp,
- struct prefix_rd *prd,
- const struct bgp_path_info *local_pi)
+struct bgp_dest *bgp_evpn_global_node_lookup(
+ struct bgp_table *table, safi_t safi, const struct prefix_evpn *evp,
+ struct prefix_rd *prd, const struct bgp_path_info *local_pi)
{
struct prefix_evpn global_p;
@@ -709,7 +707,7 @@ bgp_evpn_global_node_lookup(struct bgp_table *table, afi_t afi, safi_t safi,
evp = &global_p;
}
- return bgp_afi_node_lookup(table, afi, safi, (struct prefix *)evp, prd);
+ return bgp_safi_node_lookup(table, safi, (struct prefix *)evp, prd);
}
/*
@@ -1358,7 +1356,7 @@ static void evpn_delete_old_local_route(struct bgp *bgp, struct bgpevpn *vpn,
* L3VPN routes.
*/
global_dest = bgp_evpn_global_node_lookup(
- bgp->rib[afi][safi], afi, safi,
+ bgp->rib[afi][safi], safi,
(const struct prefix_evpn *)bgp_dest_get_prefix(dest),
&vpn->prd, old_local);
if (global_dest) {
@@ -1837,6 +1835,7 @@ static int update_evpn_route_entry(struct bgp *bgp, struct bgpevpn *vpn,
struct bgp_path_info *tmp_pi;
struct bgp_path_info *local_pi;
struct attr *attr_new;
+ struct attr local_attr;
mpls_label_t label[BGP_MAX_LABELS];
uint32_t num_labels = 1;
int route_change = 1;
@@ -1870,13 +1869,15 @@ static int update_evpn_route_entry(struct bgp *bgp, struct bgpevpn *vpn,
add_mac_mobility_to_attr(seq, attr);
if (!local_pi) {
- /* Add (or update) attribute to hash. */
- attr_new = bgp_attr_intern(attr);
+ local_attr = *attr;
/* Extract MAC mobility sequence number, if any. */
- attr_new->mm_seqnum =
- bgp_attr_mac_mobility_seqnum(attr_new, &sticky);
- attr_new->sticky = sticky;
+ local_attr.mm_seqnum =
+ bgp_attr_mac_mobility_seqnum(&local_attr, &sticky);
+ local_attr.sticky = sticky;
+
+ /* Add (or update) attribute to hash. */
+ attr_new = bgp_attr_intern(&local_attr);
/* Create new route with its attribute. */
tmp_pi = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_STATIC, 0,
@@ -1952,14 +1953,16 @@ static int update_evpn_route_entry(struct bgp *bgp, struct bgpevpn *vpn,
/* The attribute has changed. */
/* Add (or update) attribute to hash. */
- attr_new = bgp_attr_intern(attr);
+ local_attr = *attr;
bgp_path_info_set_flag(dest, tmp_pi,
BGP_PATH_ATTR_CHANGED);
/* Extract MAC mobility sequence number, if any. */
- attr_new->mm_seqnum =
- bgp_attr_mac_mobility_seqnum(attr_new, &sticky);
- attr_new->sticky = sticky;
+ local_attr.mm_seqnum = bgp_attr_mac_mobility_seqnum(
+ &local_attr, &sticky);
+ local_attr.sticky = sticky;
+
+ attr_new = bgp_attr_intern(&local_attr);
/* Restore route, if needed. */
if (CHECK_FLAG(tmp_pi->flags, BGP_PATH_REMOVED))
@@ -2255,8 +2258,8 @@ static int delete_evpn_type5_route(struct bgp *bgp_vrf, struct prefix_evpn *evp)
return 0;
/* locate the global route entry for this type-5 prefix */
- dest = bgp_evpn_global_node_lookup(bgp_evpn->rib[afi][safi], afi, safi,
- evp, &bgp_vrf->vrf_prd, NULL);
+ dest = bgp_evpn_global_node_lookup(bgp_evpn->rib[afi][safi], safi, evp,
+ &bgp_vrf->vrf_prd, NULL);
if (!dest)
return 0;
@@ -2292,8 +2295,8 @@ static int delete_evpn_route(struct bgp *bgp, struct bgpevpn *vpn,
* this table is a 2-level tree (RD-level + Prefix-level) similar to
* L3VPN routes.
*/
- global_dest = bgp_evpn_global_node_lookup(bgp->rib[afi][safi], afi,
- safi, p, &vpn->prd, NULL);
+ global_dest = bgp_evpn_global_node_lookup(bgp->rib[afi][safi], safi, p,
+ &vpn->prd, NULL);
if (global_dest) {
/* Delete route entry in the global EVPN table. */
delete_evpn_route_entry(bgp, afi, safi, global_dest, &pi);
@@ -4312,8 +4315,8 @@ static int delete_withdraw_vni_routes(struct bgp *bgp, struct bgpevpn *vpn)
/* Remove type-3 route for this VNI from global table. */
build_evpn_type3_prefix(&p, vpn->originator_ip);
- global_dest = bgp_evpn_global_node_lookup(bgp->rib[afi][safi], afi,
- safi, &p, &vpn->prd, NULL);
+ global_dest = bgp_evpn_global_node_lookup(bgp->rib[afi][safi], safi, &p,
+ &vpn->prd, NULL);
if (global_dest) {
/* Delete route entry in the global EVPN table. */
delete_evpn_route_entry(bgp, afi, safi, global_dest, &pi);
@@ -5676,7 +5679,7 @@ void bgp_evpn_encode_prefix(struct stream *s, const struct prefix *p,
}
int bgp_nlri_parse_evpn(struct peer *peer, struct attr *attr,
- struct bgp_nlri *packet, int withdraw)
+ struct bgp_nlri *packet, bool withdraw)
{
uint8_t *pnt;
uint8_t *lim;
@@ -6232,6 +6235,14 @@ int bgp_evpn_local_l3vni_add(vni_t l3vni, vrf_id_t vrf_id,
l3vni);
return -1;
}
+
+ if (CHECK_FLAG(bgp_evpn->flags, BGP_FLAG_DELETE_IN_PROGRESS)) {
+ flog_err(EC_BGP_NO_DFLT,
+ "Cannot process L3VNI %u ADD - EVPN BGP instance is shutting down",
+ l3vni);
+ return -1;
+ }
+
as = bgp_evpn->as;
/* if the BGP vrf instance doesn't exist - create one */
@@ -6374,6 +6385,13 @@ int bgp_evpn_local_l3vni_del(vni_t l3vni, vrf_id_t vrf_id)
return -1;
}
+ if (CHECK_FLAG(bgp_evpn->flags, BGP_FLAG_DELETE_IN_PROGRESS)) {
+ flog_err(EC_BGP_NO_DFLT,
+ "Cannot process L3VNI %u ADD - EVPN BGP instance is shutting down",
+ l3vni);
+ return -1;
+ }
+
/* Remove remote routes from BGT VRF even if BGP_VRF_AUTO is configured,
* bgp_delete would not remove/decrement bgp_path_info of the ip_prefix
* routes. This will uninstalling the routes from zebra and decremnt the
@@ -6647,20 +6665,20 @@ void bgp_evpn_cleanup(struct bgp *bgp)
(void (*)(struct hash_bucket *, void *))free_vni_entry,
bgp);
- hash_clean(bgp->import_rt_hash, (void (*)(void *))hash_import_rt_free);
- hash_free(bgp->import_rt_hash);
- bgp->import_rt_hash = NULL;
+ hash_clean_and_free(&bgp->import_rt_hash,
+ (void (*)(void *))hash_import_rt_free);
+
+ hash_clean_and_free(&bgp->vrf_import_rt_hash,
+ (void (*)(void *))hash_vrf_import_rt_free);
- hash_clean(bgp->vrf_import_rt_hash,
- (void (*)(void *))hash_vrf_import_rt_free);
- hash_free(bgp->vrf_import_rt_hash);
- bgp->vrf_import_rt_hash = NULL;
+ hash_clean_and_free(&bgp->vni_svi_hash,
+ (void (*)(void *))hash_evpn_free);
- hash_clean(bgp->vni_svi_hash, (void (*)(void *))hash_evpn_free);
- hash_free(bgp->vni_svi_hash);
- bgp->vni_svi_hash = NULL;
- hash_free(bgp->vnihash);
- bgp->vnihash = NULL;
+ /*
+ * Why is the vnihash freed at the top of this function and
+ * then deleted here?
+ */
+ hash_clean_and_free(&bgp->vnihash, NULL);
list_delete(&bgp->vrf_import_rtl);
list_delete(&bgp->vrf_export_rtl);
diff --git a/bgpd/bgp_evpn.h b/bgpd/bgp_evpn.h
index 1dce4820d6..a034bfbd7e 100644
--- a/bgpd/bgp_evpn.h
+++ b/bgpd/bgp_evpn.h
@@ -150,7 +150,7 @@ extern void bgp_evpn_encode_prefix(struct stream *s, const struct prefix *p,
struct attr *attr, bool addpath_capable,
uint32_t addpath_tx_id);
extern int bgp_nlri_parse_evpn(struct peer *peer, struct attr *attr,
- struct bgp_nlri *packet, int withdraw);
+ struct bgp_nlri *packet, bool withdraw);
extern int bgp_evpn_import_route(struct bgp *bgp, afi_t afi, safi_t safi,
const struct prefix *p,
struct bgp_path_info *ri);
diff --git a/bgpd/bgp_evpn_mh.c b/bgpd/bgp_evpn_mh.c
index 2f95023aa9..4aff93514f 100644
--- a/bgpd/bgp_evpn_mh.c
+++ b/bgpd/bgp_evpn_mh.c
@@ -65,7 +65,7 @@ static void bgp_evpn_mac_update_on_es_local_chg(struct bgp_evpn_es *es,
bool is_local);
esi_t zero_esi_buf, *zero_esi = &zero_esi_buf;
-static void bgp_evpn_run_consistency_checks(struct thread *t);
+static void bgp_evpn_run_consistency_checks(struct event *t);
static void bgp_evpn_path_nh_info_free(struct bgp_path_evpn_nh_info *nh_info);
static void bgp_evpn_path_nh_unlink(struct bgp_path_evpn_nh_info *nh_info);
@@ -487,8 +487,8 @@ static int bgp_evpn_mh_route_delete(struct bgp *bgp, struct bgp_evpn_es *es,
/* Next, locate route node in the global EVPN routing table.
* Note that this table is a 2-level tree (RD-level + Prefix-level)
*/
- global_dest = bgp_evpn_global_node_lookup(bgp->rib[afi][safi], afi,
- safi, p, prd, NULL);
+ global_dest = bgp_evpn_global_node_lookup(bgp->rib[afi][safi], safi, p,
+ prd, NULL);
if (global_dest) {
/* Delete route entry in the global EVPN table. */
@@ -1071,7 +1071,8 @@ void update_type1_routes_for_evi(struct bgp *bgp, struct bgpevpn *vpn)
continue;
/* Update EAD-ES */
- bgp_evpn_ead_es_route_update(bgp, es);
+ if (bgp_evpn_local_es_is_active(es))
+ bgp_evpn_ead_es_route_update(bgp, es);
/* Update EAD-EVI */
if (CHECK_FLAG(es->flags, BGP_EVPNES_ADV_EVI)) {
@@ -2564,7 +2565,8 @@ static void bgp_evpn_es_show_entry(struct vty *vty,
bgp_evpn_es_vteps_str(vtep_str, es, sizeof(vtep_str));
vty_out(vty, "%-30s %-5s %-21pRDP %-8d %s\n", es->esi_str,
- type_str, &es->es_base_frag->prd,
+ type_str,
+ es->es_base_frag ? &es->es_base_frag->prd : NULL,
listcount(es->es_evi_list), vtep_str);
}
}
@@ -2607,6 +2609,9 @@ static void bgp_evpn_es_show_entry_detail(struct vty *vty,
listcount(es->macip_global_path_list));
json_object_int_add(json, "inconsistentVniVtepCount",
es->incons_evi_vtep_cnt);
+ if (es->flags & BGP_EVPNES_LOCAL)
+ json_object_int_add(json, "localEsDfPreference",
+ es->df_pref);
if (listcount(es->es_vtep_list)) {
json_vteps = json_object_new_array();
for (ALL_LIST_ELEMENTS_RO(es->es_vtep_list, node,
@@ -2640,7 +2645,8 @@ static void bgp_evpn_es_show_entry_detail(struct vty *vty,
vty_out(vty, "ESI: %s\n", es->esi_str);
vty_out(vty, " Type: %s\n", type_str);
- vty_out(vty, " RD: %pRDP\n", &es->es_base_frag->prd);
+ vty_out(vty, " RD: %pRDP\n",
+ es->es_base_frag ? &es->es_base_frag->prd : NULL);
vty_out(vty, " Originator-IP: %pI4\n", &es->originator_ip);
if (es->flags & BGP_EVPNES_LOCAL)
vty_out(vty, " Local ES DF preference: %u\n",
@@ -4172,9 +4178,9 @@ static void bgp_evpn_es_cons_checks_timer_start(void)
if (BGP_DEBUG(evpn_mh, EVPN_MH_ES))
zlog_debug("periodic consistency checking started");
- thread_add_timer(bm->master, bgp_evpn_run_consistency_checks, NULL,
- BGP_EVPN_CONS_CHECK_INTERVAL,
- &bgp_mh_info->t_cons_check);
+ event_add_timer(bm->master, bgp_evpn_run_consistency_checks, NULL,
+ BGP_EVPN_CONS_CHECK_INTERVAL,
+ &bgp_mh_info->t_cons_check);
}
/* queue up the es for background consistency checks */
@@ -4358,7 +4364,7 @@ static uint32_t bgp_evpn_es_run_consistency_checks(struct bgp_evpn_es *es)
return proc_cnt;
}
-static void bgp_evpn_run_consistency_checks(struct thread *t)
+static void bgp_evpn_run_consistency_checks(struct event *t)
{
int proc_cnt = 0;
struct listnode *node;
@@ -4378,7 +4384,7 @@ static void bgp_evpn_run_consistency_checks(struct thread *t)
}
/* restart the timer */
- thread_add_timer(bm->master, bgp_evpn_run_consistency_checks, NULL,
+ event_add_timer(bm->master, bgp_evpn_run_consistency_checks, NULL,
BGP_EVPN_CONS_CHECK_INTERVAL,
&bgp_mh_info->t_cons_check);
}
@@ -4593,9 +4599,8 @@ void bgp_evpn_nh_finish(struct bgp *bgp_vrf)
bgp_vrf->evpn_nh_table,
(void (*)(struct hash_bucket *, void *))bgp_evpn_nh_flush_cb,
NULL);
- hash_clean(bgp_vrf->evpn_nh_table, (void (*)(void *))hash_evpn_nh_free);
- hash_free(bgp_vrf->evpn_nh_table);
- bgp_vrf->evpn_nh_table = NULL;
+ hash_clean_and_free(&bgp_vrf->evpn_nh_table,
+ (void (*)(void *))hash_evpn_nh_free);
}
static void bgp_evpn_nh_update_ref_pi(struct bgp_evpn_nh *nh)
@@ -4935,7 +4940,7 @@ void bgp_evpn_mh_finish(void)
bgp_evpn_es_local_info_clear(es, true);
}
if (bgp_mh_info->t_cons_check)
- THREAD_OFF(bgp_mh_info->t_cons_check);
+ EVENT_OFF(bgp_mh_info->t_cons_check);
list_delete(&bgp_mh_info->local_es_list);
list_delete(&bgp_mh_info->pend_es_list);
list_delete(&bgp_mh_info->ead_es_export_rtl);
diff --git a/bgpd/bgp_evpn_mh.h b/bgpd/bgp_evpn_mh.h
index 613fece4d4..ee1f74989b 100644
--- a/bgpd/bgp_evpn_mh.h
+++ b/bgpd/bgp_evpn_mh.h
@@ -299,7 +299,7 @@ struct bgp_evpn_mh_info {
/* List of ESs with pending/periodic processing */
struct list *pend_es_list;
/* periodic timer for running background consistency checks */
- struct thread *t_cons_check;
+ struct event *t_cons_check;
/* config knobs for optimizing or interop */
/* Generate EAD-EVI routes even if the ES is oper-down. This can be
diff --git a/bgpd/bgp_evpn_private.h b/bgpd/bgp_evpn_private.h
index fbf3b19c37..fd8d2c118f 100644
--- a/bgpd/bgp_evpn_private.h
+++ b/bgpd/bgp_evpn_private.h
@@ -712,11 +712,9 @@ extern struct bgp_dest *
bgp_evpn_global_node_get(struct bgp_table *table, afi_t afi, safi_t safi,
const struct prefix_evpn *evp, struct prefix_rd *prd,
const struct bgp_path_info *local_pi);
-extern struct bgp_dest *
-bgp_evpn_global_node_lookup(struct bgp_table *table, afi_t afi, safi_t safi,
- const struct prefix_evpn *evp,
- struct prefix_rd *prd,
- const struct bgp_path_info *local_pi);
+extern struct bgp_dest *bgp_evpn_global_node_lookup(
+ struct bgp_table *table, safi_t safi, const struct prefix_evpn *evp,
+ struct prefix_rd *prd, const struct bgp_path_info *local_pi);
extern struct bgp_dest *
bgp_evpn_vni_ip_node_get(struct bgp_table *const table,
const struct prefix_evpn *evp,
diff --git a/bgpd/bgp_evpn_vty.c b/bgpd/bgp_evpn_vty.c
index e28a8c8057..c1bcbf77ce 100644
--- a/bgpd/bgp_evpn_vty.c
+++ b/bgpd/bgp_evpn_vty.c
@@ -2716,8 +2716,8 @@ static void evpn_show_route_rd_macip(struct vty *vty, struct bgp *bgp,
/* See if route exists. Look for both non-sticky and sticky. */
build_evpn_type2_prefix(&p, mac, ip);
- dest = bgp_afi_node_lookup(bgp->rib[afi][safi], afi, safi,
- (struct prefix *)&p, prd);
+ dest = bgp_safi_node_lookup(bgp->rib[afi][safi], safi,
+ (struct prefix *)&p, prd);
if (!dest || !bgp_dest_has_bgp_path_info_data(dest)) {
if (!json)
vty_out(vty, "%% Network not in table\n");
@@ -2946,9 +2946,9 @@ static void evpn_show_route_rd_all_macip(struct vty *vty, struct bgp *bgp,
* then search the l2vpn evpn table for it.
*/
build_evpn_type2_prefix(&ep, mac, ip);
- dest = bgp_afi_node_lookup(bgp->rib[afi][safi], afi, safi,
- (struct prefix *)&ep,
- (struct prefix_rd *)rd_destp);
+ dest = bgp_safi_node_lookup(bgp->rib[afi][safi], safi,
+ (struct prefix *)&ep,
+ (struct prefix_rd *)rd_destp);
if (!dest)
continue;
diff --git a/bgpd/bgp_flowspec.c b/bgpd/bgp_flowspec.c
index f9debe43cd..70bdbaf035 100644
--- a/bgpd/bgp_flowspec.c
+++ b/bgpd/bgp_flowspec.c
@@ -82,7 +82,7 @@ static int bgp_fs_nlri_validate(uint8_t *nlri_content, uint32_t len,
}
int bgp_nlri_parse_flowspec(struct peer *peer, struct attr *attr,
- struct bgp_nlri *packet, int withdraw)
+ struct bgp_nlri *packet, bool withdraw)
{
uint8_t *pnt;
uint8_t *lim;
@@ -98,6 +98,13 @@ int bgp_nlri_parse_flowspec(struct peer *peer, struct attr *attr,
afi = packet->afi;
safi = packet->safi;
+ /*
+ * All other AFI/SAFI's treat no attribute as a implicit
+ * withdraw. Flowspec should as well.
+ */
+ if (!attr)
+ withdraw = true;
+
if (packet->length >= FLOWSPEC_NLRI_SIZELIMIT_EXTENDED) {
flog_err(EC_BGP_FLOWSPEC_PACKET,
"BGP flowspec nlri length maximum reached (%u)",
diff --git a/bgpd/bgp_flowspec.h b/bgpd/bgp_flowspec.h
index 58fc1775ab..bc2f00511e 100644
--- a/bgpd/bgp_flowspec.h
+++ b/bgpd/bgp_flowspec.h
@@ -15,7 +15,7 @@
#define BGP_FLOWSPEC_NLRI_STRING_MAX 512
extern int bgp_nlri_parse_flowspec(struct peer *peer, struct attr *attr,
- struct bgp_nlri *packet, int withdraw);
+ struct bgp_nlri *packet, bool withdraw);
extern void bgp_flowspec_vty_init(void);
diff --git a/bgpd/bgp_fsm.c b/bgpd/bgp_fsm.c
index 59a8fcb92a..a289d3d67a 100644
--- a/bgpd/bgp_fsm.c
+++ b/bgpd/bgp_fsm.c
@@ -9,7 +9,7 @@
#include "linklist.h"
#include "prefix.h"
#include "sockunion.h"
-#include "thread.h"
+#include "frrevent.h"
#include "log.h"
#include "stream.h"
#include "ringbuf.h"
@@ -82,13 +82,13 @@ static const char *const bgp_event_str[] = {
function. */
/* BGP event function. */
-void bgp_event(struct thread *);
+void bgp_event(struct event *event);
/* BGP thread functions. */
-static void bgp_start_timer(struct thread *);
-static void bgp_connect_timer(struct thread *);
-static void bgp_holdtime_timer(struct thread *);
-static void bgp_delayopen_timer(struct thread *);
+static void bgp_start_timer(struct event *event);
+static void bgp_connect_timer(struct event *event);
+static void bgp_holdtime_timer(struct event *event);
+static void bgp_delayopen_timer(struct event *event);
/* BGP FSM functions. */
static enum bgp_fsm_state_progress bgp_start(struct peer *);
@@ -169,17 +169,17 @@ static struct peer *peer_xfer_conn(struct peer *from_peer)
*/
bgp_keepalives_off(from_peer);
- THREAD_OFF(peer->t_routeadv);
- THREAD_OFF(peer->t_connect);
- THREAD_OFF(peer->t_delayopen);
- THREAD_OFF(peer->t_connect_check_r);
- THREAD_OFF(peer->t_connect_check_w);
- THREAD_OFF(from_peer->t_routeadv);
- THREAD_OFF(from_peer->t_connect);
- THREAD_OFF(from_peer->t_delayopen);
- THREAD_OFF(from_peer->t_connect_check_r);
- THREAD_OFF(from_peer->t_connect_check_w);
- THREAD_OFF(from_peer->t_process_packet);
+ EVENT_OFF(peer->t_routeadv);
+ EVENT_OFF(peer->t_connect);
+ EVENT_OFF(peer->t_delayopen);
+ EVENT_OFF(peer->t_connect_check_r);
+ EVENT_OFF(peer->t_connect_check_w);
+ EVENT_OFF(from_peer->t_routeadv);
+ EVENT_OFF(from_peer->t_connect);
+ EVENT_OFF(from_peer->t_delayopen);
+ EVENT_OFF(from_peer->t_connect_check_r);
+ EVENT_OFF(from_peer->t_connect_check_w);
+ EVENT_OFF(from_peer->t_process_packet);
/*
* At this point in time, it is possible that there are packets pending
@@ -343,8 +343,8 @@ static struct peer *peer_xfer_conn(struct peer *from_peer)
bgp_reads_on(peer);
bgp_writes_on(peer);
- thread_add_event(bm->master, bgp_process_packet, peer, 0,
- &peer->t_process_packet);
+ event_add_event(bm->master, bgp_process_packet, peer, 0,
+ &peer->t_process_packet);
return (peer);
}
@@ -364,23 +364,23 @@ void bgp_timer_set(struct peer *peer)
inactive. All other timer must be turned off */
if (BGP_PEER_START_SUPPRESSED(peer) || !peer_active(peer)
|| peer->bgp->vrf_id == VRF_UNKNOWN) {
- THREAD_OFF(peer->t_start);
+ EVENT_OFF(peer->t_start);
} else {
BGP_TIMER_ON(peer->t_start, bgp_start_timer,
peer->v_start);
}
- THREAD_OFF(peer->t_connect);
- THREAD_OFF(peer->t_holdtime);
+ EVENT_OFF(peer->t_connect);
+ EVENT_OFF(peer->t_holdtime);
bgp_keepalives_off(peer);
- THREAD_OFF(peer->t_routeadv);
- THREAD_OFF(peer->t_delayopen);
+ EVENT_OFF(peer->t_routeadv);
+ EVENT_OFF(peer->t_delayopen);
break;
case Connect:
/* After start timer is expired, the peer moves to Connect
status. Make sure start timer is off and connect timer is
on. */
- THREAD_OFF(peer->t_start);
+ EVENT_OFF(peer->t_start);
if (CHECK_FLAG(peer->flags, PEER_FLAG_TIMER_DELAYOPEN))
BGP_TIMER_ON(peer->t_connect, bgp_connect_timer,
(peer->v_delayopen + peer->v_connect));
@@ -388,19 +388,19 @@ void bgp_timer_set(struct peer *peer)
BGP_TIMER_ON(peer->t_connect, bgp_connect_timer,
peer->v_connect);
- THREAD_OFF(peer->t_holdtime);
+ EVENT_OFF(peer->t_holdtime);
bgp_keepalives_off(peer);
- THREAD_OFF(peer->t_routeadv);
+ EVENT_OFF(peer->t_routeadv);
break;
case Active:
/* Active is waiting connection from remote peer. And if
connect timer is expired, change status to Connect. */
- THREAD_OFF(peer->t_start);
+ EVENT_OFF(peer->t_start);
/* If peer is passive mode, do not set connect timer. */
if (CHECK_FLAG(peer->flags, PEER_FLAG_PASSIVE)
|| CHECK_FLAG(peer->sflags, PEER_STATUS_NSF_WAIT)) {
- THREAD_OFF(peer->t_connect);
+ EVENT_OFF(peer->t_connect);
} else {
if (CHECK_FLAG(peer->flags, PEER_FLAG_TIMER_DELAYOPEN))
BGP_TIMER_ON(
@@ -410,80 +410,88 @@ void bgp_timer_set(struct peer *peer)
BGP_TIMER_ON(peer->t_connect, bgp_connect_timer,
peer->v_connect);
}
- THREAD_OFF(peer->t_holdtime);
+ EVENT_OFF(peer->t_holdtime);
bgp_keepalives_off(peer);
- THREAD_OFF(peer->t_routeadv);
+ EVENT_OFF(peer->t_routeadv);
break;
case OpenSent:
/* OpenSent status. */
- THREAD_OFF(peer->t_start);
- THREAD_OFF(peer->t_connect);
+ EVENT_OFF(peer->t_start);
+ EVENT_OFF(peer->t_connect);
if (peer->v_holdtime != 0) {
BGP_TIMER_ON(peer->t_holdtime, bgp_holdtime_timer,
peer->v_holdtime);
} else {
- THREAD_OFF(peer->t_holdtime);
+ EVENT_OFF(peer->t_holdtime);
}
bgp_keepalives_off(peer);
- THREAD_OFF(peer->t_routeadv);
- THREAD_OFF(peer->t_delayopen);
+ EVENT_OFF(peer->t_routeadv);
+ EVENT_OFF(peer->t_delayopen);
break;
case OpenConfirm:
/* OpenConfirm status. */
- THREAD_OFF(peer->t_start);
- THREAD_OFF(peer->t_connect);
+ EVENT_OFF(peer->t_start);
+ EVENT_OFF(peer->t_connect);
- /* If the negotiated Hold Time value is zero, then the Hold Time
- timer and KeepAlive timers are not started. */
- if (peer->v_holdtime == 0) {
- THREAD_OFF(peer->t_holdtime);
+ /*
+ * If the negotiated Hold Time value is zero, then the Hold Time
+ * timer and KeepAlive timers are not started.
+ * Additionally if a different hold timer has been negotiated
+ * than we must stop then start the timer again
+ */
+ EVENT_OFF(peer->t_holdtime);
+ if (peer->v_holdtime == 0)
bgp_keepalives_off(peer);
- } else {
+ else {
BGP_TIMER_ON(peer->t_holdtime, bgp_holdtime_timer,
peer->v_holdtime);
bgp_keepalives_on(peer);
}
- THREAD_OFF(peer->t_routeadv);
- THREAD_OFF(peer->t_delayopen);
+ EVENT_OFF(peer->t_routeadv);
+ EVENT_OFF(peer->t_delayopen);
break;
case Established:
/* In Established status start and connect timer is turned
off. */
- THREAD_OFF(peer->t_start);
- THREAD_OFF(peer->t_connect);
- THREAD_OFF(peer->t_delayopen);
-
- /* Same as OpenConfirm, if holdtime is zero then both holdtime
- and keepalive must be turned off. */
- if (peer->v_holdtime == 0) {
- THREAD_OFF(peer->t_holdtime);
+ EVENT_OFF(peer->t_start);
+ EVENT_OFF(peer->t_connect);
+ EVENT_OFF(peer->t_delayopen);
+
+ /*
+ * Same as OpenConfirm, if holdtime is zero then both holdtime
+ * and keepalive must be turned off.
+ * Additionally if a different hold timer has been negotiated
+ * then we must stop then start the timer again
+ */
+ EVENT_OFF(peer->t_holdtime);
+ if (peer->v_holdtime == 0)
bgp_keepalives_off(peer);
- } else {
+ else {
BGP_TIMER_ON(peer->t_holdtime, bgp_holdtime_timer,
peer->v_holdtime);
bgp_keepalives_on(peer);
}
break;
case Deleted:
- THREAD_OFF(peer->t_gr_restart);
- THREAD_OFF(peer->t_gr_stale);
+ EVENT_OFF(peer->t_gr_restart);
+ EVENT_OFF(peer->t_gr_stale);
FOREACH_AFI_SAFI (afi, safi)
- THREAD_OFF(peer->t_llgr_stale[afi][safi]);
+ EVENT_OFF(peer->t_llgr_stale[afi][safi]);
- THREAD_OFF(peer->t_pmax_restart);
- THREAD_OFF(peer->t_refresh_stalepath);
+ EVENT_OFF(peer->t_pmax_restart);
+ EVENT_OFF(peer->t_refresh_stalepath);
/* fallthru */
case Clearing:
- THREAD_OFF(peer->t_start);
- THREAD_OFF(peer->t_connect);
- THREAD_OFF(peer->t_holdtime);
+ EVENT_OFF(peer->t_start);
+ EVENT_OFF(peer->t_connect);
+ EVENT_OFF(peer->t_holdtime);
bgp_keepalives_off(peer);
- THREAD_OFF(peer->t_routeadv);
- THREAD_OFF(peer->t_delayopen);
+ EVENT_OFF(peer->t_routeadv);
+ EVENT_OFF(peer->t_delayopen);
break;
case BGP_STATUS_MAX:
flog_err(EC_LIB_DEVELOPMENT,
@@ -494,28 +502,28 @@ void bgp_timer_set(struct peer *peer)
/* BGP start timer. This function set BGP_Start event to thread value
and process event. */
-static void bgp_start_timer(struct thread *thread)
+static void bgp_start_timer(struct event *thread)
{
struct peer *peer;
- peer = THREAD_ARG(thread);
+ peer = EVENT_ARG(thread);
if (bgp_debug_neighbor_events(peer))
zlog_debug("%s [FSM] Timer (start timer expire).", peer->host);
- THREAD_VAL(thread) = BGP_Start;
+ EVENT_VAL(thread) = BGP_Start;
bgp_event(thread); /* bgp_event unlocks peer */
}
/* BGP connect retry timer. */
-static void bgp_connect_timer(struct thread *thread)
+static void bgp_connect_timer(struct event *thread)
{
struct peer *peer;
- peer = THREAD_ARG(thread);
+ peer = EVENT_ARG(thread);
/* stop the DelayOpenTimer if it is running */
- THREAD_OFF(peer->t_delayopen);
+ EVENT_OFF(peer->t_delayopen);
assert(!peer->t_write);
assert(!peer->t_read);
@@ -526,18 +534,18 @@ static void bgp_connect_timer(struct thread *thread)
if (CHECK_FLAG(peer->sflags, PEER_STATUS_ACCEPT_PEER))
bgp_stop(peer);
else {
- THREAD_VAL(thread) = ConnectRetry_timer_expired;
+ EVENT_VAL(thread) = ConnectRetry_timer_expired;
bgp_event(thread); /* bgp_event unlocks peer */
}
}
/* BGP holdtime timer. */
-static void bgp_holdtime_timer(struct thread *thread)
+static void bgp_holdtime_timer(struct event *thread)
{
atomic_size_t inq_count;
struct peer *peer;
- peer = THREAD_ARG(thread);
+ peer = EVENT_ARG(thread);
if (bgp_debug_neighbor_events(peer))
zlog_debug("%s [FSM] Timer (holdtime timer expire)",
@@ -559,15 +567,15 @@ static void bgp_holdtime_timer(struct thread *thread)
BGP_TIMER_ON(peer->t_holdtime, bgp_holdtime_timer,
peer->v_holdtime);
- THREAD_VAL(thread) = Hold_Timer_expired;
+ EVENT_VAL(thread) = Hold_Timer_expired;
bgp_event(thread); /* bgp_event unlocks peer */
}
-void bgp_routeadv_timer(struct thread *thread)
+void bgp_routeadv_timer(struct event *thread)
{
struct peer *peer;
- peer = THREAD_ARG(thread);
+ peer = EVENT_ARG(thread);
if (bgp_debug_neighbor_events(peer))
zlog_debug("%s [FSM] Timer (routeadv timer expire)",
@@ -575,8 +583,8 @@ void bgp_routeadv_timer(struct thread *thread)
peer->synctime = monotime(NULL);
- thread_add_timer_msec(bm->master, bgp_generate_updgrp_packets, peer, 0,
- &peer->t_generate_updgrp_packets);
+ event_add_timer_msec(bm->master, bgp_generate_updgrp_packets, peer, 0,
+ &peer->t_generate_updgrp_packets);
/* MRAI timer will be started again when FIFO is built, no need to
* do it here.
@@ -584,17 +592,17 @@ void bgp_routeadv_timer(struct thread *thread)
}
/* RFC 4271 DelayOpenTimer */
-void bgp_delayopen_timer(struct thread *thread)
+void bgp_delayopen_timer(struct event *thread)
{
struct peer *peer;
- peer = THREAD_ARG(thread);
+ peer = EVENT_ARG(thread);
if (bgp_debug_neighbor_events(peer))
zlog_debug("%s [FSM] Timer (DelayOpentimer expire)",
peer->host);
- THREAD_VAL(thread) = DelayOpen_timer_expired;
+ EVENT_VAL(thread) = DelayOpen_timer_expired;
bgp_event(thread); /* bgp_event unlocks peer */
}
@@ -647,7 +655,7 @@ static void bgp_graceful_restart_timer_off(struct peer *peer)
return;
UNSET_FLAG(peer->sflags, PEER_STATUS_NSF_WAIT);
- THREAD_OFF(peer->t_gr_stale);
+ EVENT_OFF(peer->t_gr_stale);
if (peer_dynamic_neighbor(peer) &&
!(CHECK_FLAG(peer->flags, PEER_FLAG_DELETE))) {
@@ -660,14 +668,14 @@ static void bgp_graceful_restart_timer_off(struct peer *peer)
bgp_timer_set(peer);
}
-static void bgp_llgr_stale_timer_expire(struct thread *thread)
+static void bgp_llgr_stale_timer_expire(struct event *thread)
{
struct peer_af *paf;
struct peer *peer;
afi_t afi;
safi_t safi;
- paf = THREAD_ARG(thread);
+ paf = EVENT_ARG(thread);
peer = paf->peer;
afi = paf->afi;
@@ -762,7 +770,7 @@ static void bgp_set_llgr_stale(struct peer *peer, afi_t afi, safi_t safi)
}
}
-static void bgp_graceful_restart_timer_expire(struct thread *thread)
+static void bgp_graceful_restart_timer_expire(struct event *thread)
{
struct peer *peer, *tmp_peer;
struct listnode *node, *nnode;
@@ -770,7 +778,7 @@ static void bgp_graceful_restart_timer_expire(struct thread *thread)
afi_t afi;
safi_t safi;
- peer = THREAD_ARG(thread);
+ peer = EVENT_ARG(thread);
if (bgp_debug_neighbor_events(peer)) {
zlog_debug("%pBP graceful restart timer expired", peer);
@@ -812,10 +820,9 @@ static void bgp_graceful_restart_timer_expire(struct thread *thread)
bgp_set_llgr_stale(peer, afi, safi);
bgp_clear_stale_route(peer, afi, safi);
- thread_add_timer(bm->master,
- bgp_llgr_stale_timer_expire, paf,
- peer->llgr[afi][safi].stale_time,
- &peer->t_llgr_stale[afi][safi]);
+ event_add_timer(bm->master, bgp_llgr_stale_timer_expire,
+ paf, peer->llgr[afi][safi].stale_time,
+ &peer->t_llgr_stale[afi][safi]);
for (ALL_LIST_ELEMENTS(peer->bgp->peer, node, nnode,
tmp_peer))
@@ -828,13 +835,13 @@ static void bgp_graceful_restart_timer_expire(struct thread *thread)
bgp_graceful_restart_timer_off(peer);
}
-static void bgp_graceful_stale_timer_expire(struct thread *thread)
+static void bgp_graceful_stale_timer_expire(struct event *thread)
{
struct peer *peer;
afi_t afi;
safi_t safi;
- peer = THREAD_ARG(thread);
+ peer = EVENT_ARG(thread);
if (bgp_debug_neighbor_events(peer))
zlog_debug("%pBP graceful restart stalepath timer expired",
@@ -847,14 +854,14 @@ static void bgp_graceful_stale_timer_expire(struct thread *thread)
}
/* Selection deferral timer processing function */
-static void bgp_graceful_deferral_timer_expire(struct thread *thread)
+static void bgp_graceful_deferral_timer_expire(struct event *thread)
{
struct afi_safi_info *info;
afi_t afi;
safi_t safi;
struct bgp *bgp;
- info = THREAD_ARG(thread);
+ info = EVENT_ARG(thread);
afi = info->afi;
safi = info->safi;
bgp = info->bgp;
@@ -901,8 +908,8 @@ bool bgp_update_delay_configured(struct bgp *bgp)
on ending the update delay. */
void bgp_update_delay_end(struct bgp *bgp)
{
- THREAD_OFF(bgp->t_update_delay);
- THREAD_OFF(bgp->t_establish_wait);
+ EVENT_OFF(bgp->t_update_delay);
+ EVENT_OFF(bgp->t_establish_wait);
/* Reset update-delay related state */
bgp->update_delay_over = 1;
@@ -965,7 +972,7 @@ void bgp_start_routeadv(struct bgp *bgp)
for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
if (!peer_established(peer))
continue;
- THREAD_OFF(peer->t_routeadv);
+ EVENT_OFF(peer->t_routeadv);
BGP_TIMER_ON(peer->t_routeadv, bgp_routeadv_timer, 0);
}
}
@@ -985,7 +992,7 @@ void bgp_adjust_routeadv(struct peer *peer)
* different
* duration and schedule write thread immediately.
*/
- THREAD_OFF(peer->t_routeadv);
+ EVENT_OFF(peer->t_routeadv);
peer->synctime = monotime(NULL);
/* If suppress fib pending is enabled, route is advertised to
@@ -1017,7 +1024,7 @@ void bgp_adjust_routeadv(struct peer *peer)
*/
diff = difftime(nowtime, peer->last_update);
if (diff > (double)peer->v_routeadv) {
- THREAD_OFF(peer->t_routeadv);
+ EVENT_OFF(peer->t_routeadv);
BGP_TIMER_ON(peer->t_routeadv, bgp_routeadv_timer, 0);
return;
}
@@ -1039,12 +1046,12 @@ void bgp_adjust_routeadv(struct peer *peer)
* (MRAI - m) < r
*/
if (peer->t_routeadv)
- remain = thread_timer_remain_second(peer->t_routeadv);
+ remain = event_timer_remain_second(peer->t_routeadv);
else
remain = peer->v_routeadv;
diff = peer->v_routeadv - diff;
if (diff <= (double)remain) {
- THREAD_OFF(peer->t_routeadv);
+ EVENT_OFF(peer->t_routeadv);
BGP_TIMER_ON(peer->t_routeadv, bgp_routeadv_timer, diff);
}
}
@@ -1117,14 +1124,14 @@ int bgp_fsm_error_subcode(int status)
}
/* The maxmed onstartup timer expiry callback. */
-static void bgp_maxmed_onstartup_timer(struct thread *thread)
+static void bgp_maxmed_onstartup_timer(struct event *thread)
{
struct bgp *bgp;
zlog_info("Max med on startup ended - timer expired.");
- bgp = THREAD_ARG(thread);
- THREAD_OFF(bgp->t_maxmed_onstartup);
+ bgp = EVENT_ARG(thread);
+ EVENT_OFF(bgp->t_maxmed_onstartup);
bgp->maxmed_onstartup_over = 1;
bgp_maxmed_update(bgp);
@@ -1139,8 +1146,8 @@ static void bgp_maxmed_onstartup_begin(struct bgp *bgp)
zlog_info("Begin maxmed onstartup mode - timer %d seconds",
bgp->v_maxmed_onstartup);
- thread_add_timer(bm->master, bgp_maxmed_onstartup_timer, bgp,
- bgp->v_maxmed_onstartup, &bgp->t_maxmed_onstartup);
+ event_add_timer(bm->master, bgp_maxmed_onstartup_timer, bgp,
+ bgp->v_maxmed_onstartup, &bgp->t_maxmed_onstartup);
if (!bgp->v_maxmed_admin) {
bgp->maxmed_active = 1;
@@ -1159,26 +1166,26 @@ static void bgp_maxmed_onstartup_process_status_change(struct peer *peer)
}
/* The update delay timer expiry callback. */
-static void bgp_update_delay_timer(struct thread *thread)
+static void bgp_update_delay_timer(struct event *thread)
{
struct bgp *bgp;
zlog_info("Update delay ended - timer expired.");
- bgp = THREAD_ARG(thread);
- THREAD_OFF(bgp->t_update_delay);
+ bgp = EVENT_ARG(thread);
+ EVENT_OFF(bgp->t_update_delay);
bgp_update_delay_end(bgp);
}
/* The establish wait timer expiry callback. */
-static void bgp_establish_wait_timer(struct thread *thread)
+static void bgp_establish_wait_timer(struct event *thread)
{
struct bgp *bgp;
zlog_info("Establish wait - timer expired.");
- bgp = THREAD_ARG(thread);
- THREAD_OFF(bgp->t_establish_wait);
+ bgp = EVENT_ARG(thread);
+ EVENT_OFF(bgp->t_establish_wait);
bgp_check_update_delay(bgp);
}
@@ -1198,12 +1205,12 @@ static void bgp_update_delay_begin(struct bgp *bgp)
peer->update_delay_over = 0;
/* Start the update-delay timer */
- thread_add_timer(bm->master, bgp_update_delay_timer, bgp,
- bgp->v_update_delay, &bgp->t_update_delay);
+ event_add_timer(bm->master, bgp_update_delay_timer, bgp,
+ bgp->v_update_delay, &bgp->t_update_delay);
if (bgp->v_establish_wait != bgp->v_update_delay)
- thread_add_timer(bm->master, bgp_establish_wait_timer, bgp,
- bgp->v_establish_wait, &bgp->t_establish_wait);
+ event_add_timer(bm->master, bgp_establish_wait_timer, bgp,
+ bgp->v_establish_wait, &bgp->t_establish_wait);
frr_timestamp(3, bgp->update_delay_begin_time,
sizeof(bgp->update_delay_begin_time));
@@ -1405,7 +1412,7 @@ enum bgp_fsm_state_progress bgp_stop(struct peer *peer)
/* graceful restart */
if (peer->t_gr_stale) {
- THREAD_OFF(peer->t_gr_stale);
+ EVENT_OFF(peer->t_gr_stale);
if (bgp_debug_neighbor_events(peer))
zlog_debug(
"%pBP graceful restart stalepath timer stopped",
@@ -1435,7 +1442,7 @@ enum bgp_fsm_state_progress bgp_stop(struct peer *peer)
/* Stop route-refresh stalepath timer */
if (peer->t_refresh_stalepath) {
- THREAD_OFF(peer->t_refresh_stalepath);
+ EVENT_OFF(peer->t_refresh_stalepath);
if (bgp_debug_neighbor_events(peer))
zlog_debug(
@@ -1469,11 +1476,11 @@ enum bgp_fsm_state_progress bgp_stop(struct peer *peer)
/* There is no pending EOR message */
if (gr_info->eor_required == 0) {
if (gr_info->t_select_deferral) {
- void *info = THREAD_ARG(
+ void *info = EVENT_ARG(
gr_info->t_select_deferral);
XFREE(MTYPE_TMP, info);
}
- THREAD_OFF(gr_info->t_select_deferral);
+ EVENT_OFF(gr_info->t_select_deferral);
gr_info->eor_received = 0;
}
}
@@ -1498,15 +1505,15 @@ enum bgp_fsm_state_progress bgp_stop(struct peer *peer)
bgp_writes_off(peer);
bgp_reads_off(peer);
- THREAD_OFF(peer->t_connect_check_r);
- THREAD_OFF(peer->t_connect_check_w);
+ EVENT_OFF(peer->t_connect_check_r);
+ EVENT_OFF(peer->t_connect_check_w);
/* Stop all timers. */
- THREAD_OFF(peer->t_start);
- THREAD_OFF(peer->t_connect);
- THREAD_OFF(peer->t_holdtime);
- THREAD_OFF(peer->t_routeadv);
- THREAD_OFF(peer->t_delayopen);
+ EVENT_OFF(peer->t_start);
+ EVENT_OFF(peer->t_connect);
+ EVENT_OFF(peer->t_holdtime);
+ EVENT_OFF(peer->t_routeadv);
+ EVENT_OFF(peer->t_delayopen);
/* Clear input and output buffer. */
frr_with_mutex (&peer->io_mtx) {
@@ -1646,21 +1653,21 @@ bgp_stop_with_notify(struct peer *peer, uint8_t code, uint8_t sub_code)
* when the connection is established. A read event is triggered when the
* connection is closed. Thus we need to cancel whichever one did not occur.
*/
-static void bgp_connect_check(struct thread *thread)
+static void bgp_connect_check(struct event *thread)
{
int status;
socklen_t slen;
int ret;
struct peer *peer;
- peer = THREAD_ARG(thread);
+ peer = EVENT_ARG(thread);
assert(!CHECK_FLAG(peer->thread_flags, PEER_THREAD_READS_ON));
assert(!CHECK_FLAG(peer->thread_flags, PEER_THREAD_WRITES_ON));
assert(!peer->t_read);
assert(!peer->t_write);
- THREAD_OFF(peer->t_connect_check_r);
- THREAD_OFF(peer->t_connect_check_w);
+ EVENT_OFF(peer->t_connect_check_r);
+ EVENT_OFF(peer->t_connect_check_w);
/* Check file descriptor. */
slen = sizeof(status);
@@ -1933,10 +1940,10 @@ enum bgp_fsm_state_progress bgp_start(struct peer *peer)
* bgp_connect_check() as the handler for each and cancel the
* unused event in that function.
*/
- thread_add_read(bm->master, bgp_connect_check, peer, peer->fd,
- &peer->t_connect_check_r);
- thread_add_write(bm->master, bgp_connect_check, peer, peer->fd,
- &peer->t_connect_check_w);
+ event_add_read(bm->master, bgp_connect_check, peer, peer->fd,
+ &peer->t_connect_check_r);
+ event_add_write(bm->master, bgp_connect_check, peer, peer->fd,
+ &peer->t_connect_check_w);
break;
}
return BGP_FSM_SUCCESS;
@@ -2005,7 +2012,7 @@ static enum bgp_fsm_state_progress
bgp_fsm_delayopen_timer_expire(struct peer *peer)
{
/* Stop the DelayOpenTimer */
- THREAD_OFF(peer->t_delayopen);
+ EVENT_OFF(peer->t_delayopen);
/* Send open message to peer */
bgp_open_send(peer);
@@ -2038,16 +2045,16 @@ static int bgp_start_deferral_timer(struct bgp *bgp, afi_t afi, safi_t safi,
thread_info->safi = safi;
thread_info->bgp = bgp;
- thread_add_timer(bm->master, bgp_graceful_deferral_timer_expire,
- thread_info, bgp->select_defer_time,
- &gr_info->t_select_deferral);
+ event_add_timer(bm->master, bgp_graceful_deferral_timer_expire,
+ thread_info, bgp->select_defer_time,
+ &gr_info->t_select_deferral);
}
gr_info->eor_required++;
/* Send message to RIB indicating route update pending */
if (gr_info->af_enabled[afi][safi] == false) {
gr_info->af_enabled[afi][safi] = true;
/* Send message to RIB */
- bgp_zebra_update(afi, safi, bgp->vrf_id,
+ bgp_zebra_update(bgp, afi, safi,
ZEBRA_CLIENT_ROUTE_UPDATE_PENDING);
}
if (BGP_DEBUG(update, UPDATE_OUT))
@@ -2194,7 +2201,7 @@ static enum bgp_fsm_state_progress bgp_establish(struct peer *peer)
/* Send route processing complete
message to RIB */
bgp_zebra_update(
- afi, safi, peer->bgp->vrf_id,
+ peer->bgp, afi, safi,
ZEBRA_CLIENT_ROUTE_UPDATE_COMPLETE);
}
} else {
@@ -2206,7 +2213,7 @@ static enum bgp_fsm_state_progress bgp_establish(struct peer *peer)
/* Send route processing complete
message to RIB */
bgp_zebra_update(
- afi, safi, peer->bgp->vrf_id,
+ peer->bgp, afi, safi,
ZEBRA_CLIENT_ROUTE_UPDATE_COMPLETE);
}
}
@@ -2218,7 +2225,7 @@ static enum bgp_fsm_state_progress bgp_establish(struct peer *peer)
else {
UNSET_FLAG(peer->sflags, PEER_STATUS_NSF_MODE);
if (peer->t_gr_stale) {
- THREAD_OFF(peer->t_gr_stale);
+ EVENT_OFF(peer->t_gr_stale);
if (bgp_debug_neighbor_events(peer))
zlog_debug(
"%pBP graceful restart stalepath timer stopped",
@@ -2227,7 +2234,7 @@ static enum bgp_fsm_state_progress bgp_establish(struct peer *peer)
}
if (peer->t_gr_restart) {
- THREAD_OFF(peer->t_gr_restart);
+ EVENT_OFF(peer->t_gr_restart);
if (bgp_debug_neighbor_events(peer))
zlog_debug("%pBP graceful restart timer stopped", peer);
}
@@ -2243,7 +2250,7 @@ static enum bgp_fsm_state_progress bgp_establish(struct peer *peer)
*/
FOREACH_AFI_SAFI (afi, safi) {
if (peer->t_llgr_stale[afi][safi]) {
- THREAD_OFF(peer->t_llgr_stale[afi][safi]);
+ EVENT_OFF(peer->t_llgr_stale[afi][safi]);
if (bgp_debug_neighbor_events(peer))
zlog_debug(
"%pBP Long-lived stale timer stopped for afi/safi: %d/%d",
@@ -2288,7 +2295,7 @@ static enum bgp_fsm_state_progress bgp_establish(struct peer *peer)
* of read-only mode.
*/
if (!bgp_update_delay_active(peer->bgp)) {
- THREAD_OFF(peer->t_routeadv);
+ EVENT_OFF(peer->t_routeadv);
BGP_TIMER_ON(peer->t_routeadv, bgp_routeadv_timer, 0);
}
@@ -2323,14 +2330,14 @@ static enum bgp_fsm_state_progress bgp_establish(struct peer *peer)
/* Keepalive packet is received. */
static enum bgp_fsm_state_progress bgp_fsm_keepalive(struct peer *peer)
{
- THREAD_OFF(peer->t_holdtime);
+ EVENT_OFF(peer->t_holdtime);
return BGP_FSM_SUCCESS;
}
/* Update packet is received. */
static enum bgp_fsm_state_progress bgp_fsm_update(struct peer *peer)
{
- THREAD_OFF(peer->t_holdtime);
+ EVENT_OFF(peer->t_holdtime);
return BGP_FSM_SUCCESS;
}
@@ -2372,13 +2379,13 @@ void bgp_fsm_nht_update(struct peer *peer, bool has_valid_nexthops)
break;
case Connect:
if (!has_valid_nexthops) {
- THREAD_OFF(peer->t_connect);
+ EVENT_OFF(peer->t_connect);
BGP_EVENT_ADD(peer, TCP_fatal_error);
}
break;
case Active:
if (has_valid_nexthops) {
- THREAD_OFF(peer->t_connect);
+ EVENT_OFF(peer->t_connect);
BGP_EVENT_ADD(peer, ConnectRetry_timer_expired);
}
break;
@@ -2564,13 +2571,13 @@ static const struct {
};
/* Execute event process. */
-void bgp_event(struct thread *thread)
+void bgp_event(struct event *thread)
{
enum bgp_fsm_events event;
struct peer *peer;
- peer = THREAD_ARG(thread);
- event = THREAD_VAL(thread);
+ peer = EVENT_ARG(thread);
+ event = EVENT_VAL(thread);
peer_lock(peer);
bgp_event_update(peer, event);
@@ -2817,7 +2824,7 @@ const char *print_peer_gr_cmd(enum peer_gr_command pr_gr_cmd)
const char *print_global_gr_mode(enum global_mode gl_mode)
{
- const char *global_gr_mode = NULL;
+ const char *global_gr_mode = "???";
switch (gl_mode) {
case GLOBAL_HELPER:
diff --git a/bgpd/bgp_fsm.h b/bgpd/bgp_fsm.h
index bd1a6adfe8..e3cfd0c893 100644
--- a/bgpd/bgp_fsm.h
+++ b/bgpd/bgp_fsm.h
@@ -11,33 +11,34 @@
#define BGP_TIMER_ON(T, F, V) \
do { \
if ((peer->status != Deleted)) \
- thread_add_timer(bm->master, (F), peer, (V), &(T)); \
+ event_add_timer(bm->master, (F), peer, (V), &(T)); \
} while (0)
#define BGP_EVENT_ADD(P, E) \
do { \
if ((P)->status != Deleted) \
- thread_add_event(bm->master, bgp_event, (P), (E), \
- NULL); \
+ event_add_event(bm->master, bgp_event, (P), (E), \
+ NULL); \
} while (0)
#define BGP_EVENT_FLUSH(P) \
do { \
assert(peer); \
- thread_cancel_event_ready(bm->master, (P)); \
+ event_cancel_event_ready(bm->master, (P)); \
} while (0)
-#define BGP_UPDATE_GROUP_TIMER_ON(T, F) \
- do { \
- if (BGP_SUPPRESS_FIB_ENABLED(peer->bgp) && \
- PEER_ROUTE_ADV_DELAY(peer)) \
- thread_add_timer_msec(bm->master, (F), peer, \
- (BGP_DEFAULT_UPDATE_ADVERTISEMENT_TIME * 1000),\
- (T)); \
- else \
- thread_add_timer_msec(bm->master, (F), peer, \
- 0, (T)); \
- } while (0) \
+#define BGP_UPDATE_GROUP_TIMER_ON(T, F) \
+ do { \
+ if (BGP_SUPPRESS_FIB_ENABLED(peer->bgp) && \
+ PEER_ROUTE_ADV_DELAY(peer)) \
+ event_add_timer_msec( \
+ bm->master, (F), peer, \
+ (BGP_DEFAULT_UPDATE_ADVERTISEMENT_TIME * \
+ 1000), \
+ (T)); \
+ else \
+ event_add_timer_msec(bm->master, (F), peer, 0, (T)); \
+ } while (0)
#define BGP_MSEC_JITTER 10
@@ -105,11 +106,11 @@
* Update FSM for peer based on whether we have valid nexthops or not.
*/
extern void bgp_fsm_nht_update(struct peer *peer, bool has_valid_nexthops);
-extern void bgp_event(struct thread *);
+extern void bgp_event(struct event *event);
extern int bgp_event_update(struct peer *, enum bgp_fsm_events event);
extern int bgp_stop(struct peer *peer);
extern void bgp_timer_set(struct peer *);
-extern void bgp_routeadv_timer(struct thread *);
+extern void bgp_routeadv_timer(struct event *event);
extern void bgp_fsm_change_status(struct peer *peer,
enum bgp_fsm_status status);
extern const char *const peer_down_str[];
diff --git a/bgpd/bgp_io.c b/bgpd/bgp_io.c
index 530b77987d..650adc1c9a 100644
--- a/bgpd/bgp_io.c
+++ b/bgpd/bgp_io.c
@@ -17,7 +17,7 @@
#include "network.h" // for ERRNO_IO_RETRY
#include "stream.h" // for stream_get_endp, stream_getw_from, str...
#include "ringbuf.h" // for ringbuf_remain, ringbuf_peek, ringbuf_...
-#include "thread.h" // for THREAD_OFF, THREAD_ARG, thread...
+#include "frrevent.h" // for EVENT_OFF, EVENT_ARG, thread...
#include "bgpd/bgp_io.h"
#include "bgpd/bgp_debug.h" // for bgp_debug_neighbor_events, bgp_type_str
@@ -31,8 +31,8 @@
/* forward declarations */
static uint16_t bgp_write(struct peer *);
static uint16_t bgp_read(struct peer *peer, int *code_p);
-static void bgp_process_writes(struct thread *);
-static void bgp_process_reads(struct thread *);
+static void bgp_process_writes(struct event *event);
+static void bgp_process_reads(struct event *event);
static bool validate_header(struct peer *);
/* generic i/o status codes */
@@ -55,8 +55,8 @@ void bgp_writes_on(struct peer *peer)
assert(!peer->t_connect_check_w);
assert(peer->fd);
- thread_add_write(fpt->master, bgp_process_writes, peer, peer->fd,
- &peer->t_write);
+ event_add_write(fpt->master, bgp_process_writes, peer, peer->fd,
+ &peer->t_write);
SET_FLAG(peer->thread_flags, PEER_THREAD_WRITES_ON);
}
@@ -65,8 +65,8 @@ void bgp_writes_off(struct peer *peer)
struct frr_pthread *fpt = bgp_pth_io;
assert(fpt->running);
- thread_cancel_async(fpt->master, &peer->t_write, NULL);
- THREAD_OFF(peer->t_generate_updgrp_packets);
+ event_cancel_async(fpt->master, &peer->t_write, NULL);
+ EVENT_OFF(peer->t_generate_updgrp_packets);
UNSET_FLAG(peer->thread_flags, PEER_THREAD_WRITES_ON);
}
@@ -85,8 +85,8 @@ void bgp_reads_on(struct peer *peer)
assert(!peer->t_connect_check_w);
assert(peer->fd);
- thread_add_read(fpt->master, bgp_process_reads, peer, peer->fd,
- &peer->t_read);
+ event_add_read(fpt->master, bgp_process_reads, peer, peer->fd,
+ &peer->t_read);
SET_FLAG(peer->thread_flags, PEER_THREAD_READS_ON);
}
@@ -96,9 +96,9 @@ void bgp_reads_off(struct peer *peer)
struct frr_pthread *fpt = bgp_pth_io;
assert(fpt->running);
- thread_cancel_async(fpt->master, &peer->t_read, NULL);
- THREAD_OFF(peer->t_process_packet);
- THREAD_OFF(peer->t_process_packet_error);
+ event_cancel_async(fpt->master, &peer->t_read, NULL);
+ EVENT_OFF(peer->t_process_packet);
+ EVENT_OFF(peer->t_process_packet_error);
UNSET_FLAG(peer->thread_flags, PEER_THREAD_READS_ON);
}
@@ -108,10 +108,10 @@ void bgp_reads_off(struct peer *peer)
/*
* Called from I/O pthread when a file descriptor has become ready for writing.
*/
-static void bgp_process_writes(struct thread *thread)
+static void bgp_process_writes(struct event *thread)
{
static struct peer *peer;
- peer = THREAD_ARG(thread);
+ peer = EVENT_ARG(thread);
uint16_t status;
bool reschedule;
bool fatal = false;
@@ -142,8 +142,8 @@ static void bgp_process_writes(struct thread *thread)
* sent in the update message
*/
if (reschedule) {
- thread_add_write(fpt->master, bgp_process_writes, peer,
- peer->fd, &peer->t_write);
+ event_add_write(fpt->master, bgp_process_writes, peer, peer->fd,
+ &peer->t_write);
} else if (!fatal) {
BGP_UPDATE_GROUP_TIMER_ON(&peer->t_generate_updgrp_packets,
bgp_generate_updgrp_packets);
@@ -210,7 +210,7 @@ static int read_ibuf_work(struct peer *peer)
* We read as much data as possible, process as many packets as we can and
* place them on peer->ibuf for secondary processing by the main thread.
*/
-static void bgp_process_reads(struct thread *thread)
+static void bgp_process_reads(struct event *thread)
{
/* clang-format off */
static struct peer *peer; /* peer to read from */
@@ -223,7 +223,7 @@ static void bgp_process_reads(struct thread *thread)
int ret = 1;
/* clang-format on */
- peer = THREAD_ARG(thread);
+ peer = EVENT_ARG(thread);
if (peer->fd < 0 || bm->terminating)
return;
@@ -247,8 +247,8 @@ static void bgp_process_reads(struct thread *thread)
/* Handle the error in the main pthread, include the
* specific state change from 'bgp_read'.
*/
- thread_add_event(bm->master, bgp_packet_process_error,
- peer, code, &peer->t_process_packet_error);
+ event_add_event(bm->master, bgp_packet_process_error, peer,
+ code, &peer->t_process_packet_error);
goto done;
}
@@ -292,11 +292,11 @@ done:
if (!ibuf_full)
assert(ringbuf_space(peer->ibuf_work) >= peer->max_packet_size);
- thread_add_read(fpt->master, bgp_process_reads, peer, peer->fd,
- &peer->t_read);
+ event_add_read(fpt->master, bgp_process_reads, peer, peer->fd,
+ &peer->t_read);
if (added_pkt)
- thread_add_event(bm->master, bgp_process_packet, peer, 0,
- &peer->t_process_packet);
+ event_add_event(bm->master, bgp_process_packet, peer, 0,
+ &peer->t_process_packet);
}
/*
diff --git a/bgpd/bgp_keepalives.c b/bgpd/bgp_keepalives.c
index b9e4d7c4c2..48bde1220d 100644
--- a/bgpd/bgp_keepalives.c
+++ b/bgpd/bgp_keepalives.c
@@ -15,7 +15,7 @@
#include "memory.h" // for MTYPE_TMP, XFREE, XCALLOC, XMALLOC
#include "monotime.h" // for monotime, monotime_since
-#include "bgpd/bgpd.h" // for peer, PEER_THREAD_KEEPALIVES_ON, peer...
+#include "bgpd/bgpd.h" // for peer, PEER_EVENT_KEEPALIVES_ON, peer...
#include "bgpd/bgp_debug.h" // for bgp_debug_neighbor_events
#include "bgpd/bgp_packet.h" // for bgp_keepalive_send
#include "bgpd/bgp_keepalives.h"
@@ -136,12 +136,7 @@ static unsigned int peer_hash_key(const void *arg)
/* Cleanup handler / deinitializer. */
static void bgp_keepalives_finish(void *arg)
{
- if (peerhash) {
- hash_clean(peerhash, pkat_del);
- hash_free(peerhash);
- }
-
- peerhash = NULL;
+ hash_clean_and_free(&peerhash, pkat_del);
pthread_mutex_unlock(peerhash_mtx);
pthread_mutex_destroy(peerhash_mtx);
@@ -167,7 +162,7 @@ void *bgp_keepalives_start(void *arg)
/*
* The RCU mechanism for each pthread is initialized in a "locked"
* state. That's ok for pthreads using the frr_pthread,
- * thread_fetch event loop, because that event loop unlocks regularly.
+ * event_fetch event loop, because that event loop unlocks regularly.
* For foreign pthreads, the lock needs to be unlocked so that the
* background rcu pthread can run.
*/
diff --git a/bgpd/bgp_label.c b/bgpd/bgp_label.c
index c4a5277553..0f3faeb297 100644
--- a/bgpd/bgp_label.c
+++ b/bgpd/bgp_label.c
@@ -6,7 +6,7 @@
#include <zebra.h>
#include "command.h"
-#include "thread.h"
+#include "frrevent.h"
#include "prefix.h"
#include "zclient.h"
#include "stream.h"
@@ -388,8 +388,6 @@ int bgp_nlri_parse_label(struct peer *peer, struct attr *attr,
EC_BGP_UPDATE_RCV,
"%s [Error] Update packet error (wrong label length 0)",
peer->host);
- bgp_notify_send(peer, BGP_NOTIFY_UPDATE_ERR,
- BGP_NOTIFY_UPDATE_INVAL_NETWORK);
return BGP_NLRI_PARSE_ERROR_LABEL_LENGTH;
}
p.prefixlen = prefixlen - BSIZE(llen);
@@ -399,8 +397,6 @@ int bgp_nlri_parse_label(struct peer *peer, struct attr *attr,
flog_err(EC_BGP_UPDATE_RCV,
"%s [Error] Update packet error (wrong label length %d)",
peer->host, prefixlen);
- bgp_notify_send(peer, BGP_NOTIFY_UPDATE_ERR,
- BGP_NOTIFY_UPDATE_INVAL_NETWORK);
return BGP_NLRI_PARSE_ERROR_LABEL_LENGTH;
}
diff --git a/bgpd/bgp_labelpool.c b/bgpd/bgp_labelpool.c
index f0f207442e..9943f57fb3 100644
--- a/bgpd/bgp_labelpool.c
+++ b/bgpd/bgp_labelpool.c
@@ -177,7 +177,7 @@ static void lp_chunk_free(void *goner)
XFREE(MTYPE_BGP_LABEL_CHUNK, goner);
}
-void bgp_lp_init(struct thread_master *master, struct labelpool *pool)
+void bgp_lp_init(struct event_loop *master, struct labelpool *pool)
{
if (BGP_DEBUG(labelpool, LABELPOOL))
zlog_debug("%s: entry", __func__);
@@ -1091,7 +1091,7 @@ struct lp_test {
struct timeval starttime;
struct skiplist *timestamps_alloc;
struct skiplist *timestamps_dealloc;
- struct thread *event_thread;
+ struct event *event_thread;
unsigned int counter[LPT_STAT_MAX];
};
@@ -1150,7 +1150,7 @@ static int test_cb(mpls_label_t label, void *labelid, bool allocated)
return 0;
}
-static void labelpool_test_event_handler(struct thread *thread)
+static void labelpool_test_event_handler(struct event *thread)
{
struct lp_test *tcb;
@@ -1202,7 +1202,7 @@ static void lptest_stop(void)
}
if (tcb->event_thread)
- thread_cancel(&tcb->event_thread);
+ event_cancel(&tcb->event_thread);
lpt_inprogress = false;
}
@@ -1491,7 +1491,7 @@ static void lptest_delete(void *val)
}
if (tcb->event_thread)
- thread_cancel(&tcb->event_thread);
+ event_cancel(&tcb->event_thread);
memset(tcb, 0, sizeof(*tcb));
diff --git a/bgpd/bgp_labelpool.h b/bgpd/bgp_labelpool.h
index 955ab2d697..9526cba0ce 100644
--- a/bgpd/bgp_labelpool.h
+++ b/bgpd/bgp_labelpool.h
@@ -31,7 +31,7 @@ struct labelpool {
uint32_t next_chunksize; /* request this many labels */
};
-extern void bgp_lp_init(struct thread_master *master, struct labelpool *pool);
+extern void bgp_lp_init(struct event_loop *master, struct labelpool *pool);
extern void bgp_lp_finish(void);
extern void bgp_lp_get(int type, void *labelid,
int (*cbfunc)(mpls_label_t label, void *labelid, bool allocated));
diff --git a/bgpd/bgp_lcommunity.c b/bgpd/bgp_lcommunity.c
index 2329bcb6c6..15bf419868 100644
--- a/bgpd/bgp_lcommunity.c
+++ b/bgpd/bgp_lcommunity.c
@@ -334,9 +334,7 @@ void lcommunity_init(void)
void lcommunity_finish(void)
{
- hash_clean(lcomhash, (void (*)(void *))lcommunity_hash_free);
- hash_free(lcomhash);
- lcomhash = NULL;
+ hash_clean_and_free(&lcomhash, (void (*)(void *))lcommunity_hash_free);
}
/* Get next Large Communities token from the string.
diff --git a/bgpd/bgp_mac.c b/bgpd/bgp_mac.c
index 5d49175e43..980f351303 100644
--- a/bgpd/bgp_mac.c
+++ b/bgpd/bgp_mac.c
@@ -64,8 +64,7 @@ static void bgp_mac_hash_free(void *data)
void bgp_mac_finish(void)
{
- hash_clean(bm->self_mac_hash, bgp_mac_hash_free);
- hash_free(bm->self_mac_hash);
+ hash_clean_and_free(&bm->self_mac_hash, bgp_mac_hash_free);
}
static void bgp_mac_hash_interface_string_del(void *val)
diff --git a/bgpd/bgp_main.c b/bgpd/bgp_main.c
index 85e4904372..074059c146 100644
--- a/bgpd/bgp_main.c
+++ b/bgpd/bgp_main.c
@@ -9,7 +9,7 @@
#include "vector.h"
#include "command.h"
#include "getopt.h"
-#include "thread.h"
+#include "frrevent.h"
#include <lib/version.h>
#include "memory.h"
#include "prefix.h"
diff --git a/bgpd/bgp_mplsvpn.c b/bgpd/bgp_mplsvpn.c
index 551da69249..63168f1e7a 100644
--- a/bgpd/bgp_mplsvpn.c
+++ b/bgpd/bgp_mplsvpn.c
@@ -1103,7 +1103,7 @@ leak_update(struct bgp *to_bgp, struct bgp_dest *bn,
struct bgp_path_info *new;
struct bgp_path_info_extra *extra;
uint32_t num_sids = 0;
- void *parent = source_bpi;
+ struct bgp_path_info *parent = source_bpi;
if (new_attr->srv6_l3vpn || new_attr->srv6_vpn)
num_sids = 1;
@@ -1311,7 +1311,7 @@ leak_update(struct bgp *to_bgp, struct bgp_dest *bn,
new->extra->parent = bgp_path_info_lock(parent);
bgp_dest_lock_node(
- (struct bgp_dest *)((struct bgp_path_info *)parent)->net);
+ (struct bgp_dest *)parent->net);
if (bgp_orig)
new->extra->bgp_orig = bgp_lock(bgp_orig);
if (nexthop_orig)
@@ -1647,6 +1647,8 @@ void vpn_leak_from_vrf_update(struct bgp *to_bgp, /* to */
*/
if (new_info)
vpn_leak_to_vrf_update(from_bgp, new_info, NULL);
+ else
+ bgp_dest_unlock_node(bn);
}
void vpn_leak_from_vrf_withdraw(struct bgp *to_bgp, /* to */
@@ -2075,9 +2077,11 @@ static bool vpn_leak_to_vrf_update_onevrf(struct bgp *to_bgp, /* to */
zlog_debug("%s: pfx %pBD: num_labels %d", __func__,
path_vpn->net, num_labels);
- leak_update(to_bgp, bn, new_attr, afi, safi, path_vpn, pLabels,
- num_labels, src_vrf, &nexthop_orig, nexthop_self_flag,
- debug);
+ if (!leak_update(to_bgp, bn, new_attr, afi, safi, path_vpn, pLabels,
+ num_labels, src_vrf, &nexthop_orig, nexthop_self_flag,
+ debug))
+ bgp_dest_unlock_node(bn);
+
return true;
}
diff --git a/bgpd/bgp_mplsvpn_snmp.c b/bgpd/bgp_mplsvpn_snmp.c
index 9b2ab66806..20fec6d77b 100644
--- a/bgpd/bgp_mplsvpn_snmp.c
+++ b/bgpd/bgp_mplsvpn_snmp.c
@@ -12,7 +12,7 @@
#include "log.h"
#include "prefix.h"
#include "command.h"
-#include "thread.h"
+#include "frrevent.h"
#include "smux.h"
#include "filter.h"
#include "hook.h"
@@ -1124,7 +1124,8 @@ static uint8_t *mplsL3vpnVrfRtTable(struct variable *v, oid name[],
struct bgp *l3vpn_bgp;
uint32_t rt_index = 0;
uint8_t rt_type = 0;
- char *rt_b;
+ char *rt_b = NULL;
+ static char rt_b_str[BUFSIZ] = {};
if (smux_header_table(v, name, length, exact, var_len, write_method)
== MATCH_FAILED)
@@ -1156,14 +1157,16 @@ static uint8_t *mplsL3vpnVrfRtTable(struct variable *v, oid name[],
ECOMMUNITY_ROUTE_TARGET);
break;
default:
- rt_b = NULL;
break;
}
- if (rt_b)
+ if (rt_b) {
*var_len = strnlen(rt_b, ECOMMUNITY_STRLEN);
- else
+ strlcpy(rt_b_str, rt_b, sizeof(rt_b_str));
+ XFREE(MTYPE_ECOMMUNITY_STR, rt_b);
+ } else {
*var_len = 0;
- return (uint8_t *)rt_b;
+ }
+ return (uint8_t *)rt_b_str;
case MPLSL3VPNVRFRTDESCR:
/* since we dont have a description generate one */
memset(rt_description, 0, VRF_NAMSIZ + RT_PREAMBLE_SIZE);
diff --git a/bgpd/bgp_network.c b/bgpd/bgp_network.c
index 1c2e686e1c..e235a61f59 100644
--- a/bgpd/bgp_network.c
+++ b/bgpd/bgp_network.c
@@ -5,7 +5,7 @@
#include <zebra.h>
-#include "thread.h"
+#include "frrevent.h"
#include "sockunion.h"
#include "sockopt.h"
#include "memory.h"
@@ -338,12 +338,12 @@ static void bgp_socket_set_buffer_size(const int fd)
}
/* Accept bgp connection. */
-static void bgp_accept(struct thread *thread)
+static void bgp_accept(struct event *thread)
{
int bgp_sock;
int accept_sock;
union sockunion su;
- struct bgp_listener *listener = THREAD_ARG(thread);
+ struct bgp_listener *listener = EVENT_ARG(thread);
struct peer *peer;
struct peer *peer1;
char buf[SU_ADDRSTRLEN];
@@ -354,7 +354,7 @@ static void bgp_accept(struct thread *thread)
bgp = bgp_lookup_by_name(listener->name);
/* Register accept thread. */
- accept_sock = THREAD_FD(thread);
+ accept_sock = EVENT_FD(thread);
if (accept_sock < 0) {
flog_err_sys(EC_LIB_SOCKET,
"[Error] BGP accept socket fd is negative: %d",
@@ -362,8 +362,8 @@ static void bgp_accept(struct thread *thread)
return;
}
- thread_add_read(bm->master, bgp_accept, listener, accept_sock,
- &listener->thread);
+ event_add_read(bm->master, bgp_accept, listener, accept_sock,
+ &listener->thread);
/* Accept client connection. */
bgp_sock = sockunion_accept(accept_sock, &su);
@@ -391,7 +391,7 @@ static void bgp_accept(struct thread *thread)
"[Error] accept() failed with error \"%s\" on BGP listener socket %d for BGP instance in VRF \"%s\"; refreshing socket",
safe_strerror(save_errno), accept_sock,
VRF_LOGNAME(vrf));
- THREAD_OFF(listener->thread);
+ EVENT_OFF(listener->thread);
} else {
flog_err_sys(
EC_LIB_SOCKET,
@@ -436,7 +436,7 @@ static void bgp_accept(struct thread *thread)
sockopt_tcp_mss_set(bgp_sock, peer1->tcp_mss);
bgp_fsm_change_status(peer1, Active);
- THREAD_OFF(
+ EVENT_OFF(
peer1->t_start); /* created in peer_create() */
if (peer_active(peer1)) {
@@ -569,7 +569,7 @@ static void bgp_accept(struct thread *thread)
}
bgp_peer_reg_with_nht(peer);
bgp_fsm_change_status(peer, Active);
- THREAD_OFF(peer->t_start); /* created in peer_create() */
+ EVENT_OFF(peer->t_start); /* created in peer_create() */
SET_FLAG(peer->sflags, PEER_STATUS_ACCEPT_PEER);
/* Make dummy peer until read Open packet. */
@@ -759,6 +759,9 @@ int bgp_connect(struct peer *peer)
? IPV4_MAX_BITLEN
: IPV6_MAX_BITLEN;
+ if (!BGP_PEER_SU_UNSPEC(peer))
+ bgp_md5_set(peer);
+
bgp_md5_set_connect(peer->fd, &peer->su, prefixlen,
peer->password);
}
@@ -805,9 +808,12 @@ int bgp_getsockname(struct peer *peer)
if (!bgp_zebra_nexthop_set(peer->su_local, peer->su_remote,
&peer->nexthop, peer)) {
- flog_err(EC_BGP_NH_UPD,
- "%s: nexthop_set failed, resetting connection - intf %p",
- peer->host, peer->nexthop.ifp);
+ flog_err(
+ EC_BGP_NH_UPD,
+ "%s: nexthop_set failed, resetting connection - intf %s",
+ peer->host,
+ peer->nexthop.ifp ? peer->nexthop.ifp->name
+ : "(Unknown)");
return -1;
}
return 0;
@@ -858,8 +864,8 @@ static int bgp_listener(int sock, struct sockaddr *sa, socklen_t salen,
listener->bgp = bgp;
memcpy(&listener->su, sa, salen);
- thread_add_read(bm->master, bgp_accept, listener, sock,
- &listener->thread);
+ event_add_read(bm->master, bgp_accept, listener, sock,
+ &listener->thread);
listnode_add(bm->listen_sockets, listener);
return 0;
@@ -958,7 +964,7 @@ void bgp_close_vrf_socket(struct bgp *bgp)
for (ALL_LIST_ELEMENTS(bm->listen_sockets, node, next, listener)) {
if (listener->bgp == bgp) {
- THREAD_OFF(listener->thread);
+ EVENT_OFF(listener->thread);
close(listener->fd);
listnode_delete(bm->listen_sockets, listener);
XFREE(MTYPE_BGP_LISTENER, listener->name);
@@ -980,7 +986,7 @@ void bgp_close(void)
for (ALL_LIST_ELEMENTS(bm->listen_sockets, node, next, listener)) {
if (listener->bgp)
continue;
- THREAD_OFF(listener->thread);
+ EVENT_OFF(listener->thread);
close(listener->fd);
listnode_delete(bm->listen_sockets, listener);
XFREE(MTYPE_BGP_LISTENER, listener->name);
diff --git a/bgpd/bgp_network.h b/bgpd/bgp_network.h
index f21b219e29..cf0b4362c5 100644
--- a/bgpd/bgp_network.h
+++ b/bgpd/bgp_network.h
@@ -11,7 +11,7 @@
struct bgp_listener {
int fd;
union sockunion su;
- struct thread *thread;
+ struct event *thread;
struct bgp *bgp;
char *name;
};
diff --git a/bgpd/bgp_nexthop.c b/bgpd/bgp_nexthop.c
index 00a0bc8402..c4b832ee59 100644
--- a/bgpd/bgp_nexthop.c
+++ b/bgpd/bgp_nexthop.c
@@ -6,7 +6,7 @@
#include <zebra.h>
#include "command.h"
-#include "thread.h"
+#include "frrevent.h"
#include "prefix.h"
#include "lib/json.h"
#include "zclient.h"
@@ -166,11 +166,7 @@ void bgp_tip_hash_init(struct bgp *bgp)
void bgp_tip_hash_destroy(struct bgp *bgp)
{
- if (bgp->tip_hash == NULL)
- return;
- hash_clean(bgp->tip_hash, bgp_tip_hash_free);
- hash_free(bgp->tip_hash);
- bgp->tip_hash = NULL;
+ hash_clean_and_free(&bgp->tip_hash, bgp_tip_hash_free);
}
/* Add/Update Tunnel-IP entry of bgp martian next-hop table.
@@ -305,11 +301,7 @@ void bgp_address_init(struct bgp *bgp)
void bgp_address_destroy(struct bgp *bgp)
{
- if (bgp->address_hash == NULL)
- return;
- hash_clean(bgp->address_hash, bgp_address_hash_free);
- hash_free(bgp->address_hash);
- bgp->address_hash = NULL;
+ hash_clean_and_free(&bgp->address_hash, bgp_address_hash_free);
}
static void bgp_address_add(struct bgp *bgp, struct connected *ifc,
diff --git a/bgpd/bgp_nht.c b/bgpd/bgp_nht.c
index 25b458a8e5..a294ebcc63 100644
--- a/bgpd/bgp_nht.c
+++ b/bgpd/bgp_nht.c
@@ -6,7 +6,7 @@
#include <zebra.h>
#include "command.h"
-#include "thread.h"
+#include "frrevent.h"
#include "prefix.h"
#include "zclient.h"
#include "stream.h"
@@ -37,7 +37,7 @@ extern struct zclient *zclient;
static void register_zebra_rnh(struct bgp_nexthop_cache *bnc);
static void unregister_zebra_rnh(struct bgp_nexthop_cache *bnc);
static int make_prefix(int afi, struct bgp_path_info *pi, struct prefix *p);
-static void bgp_nht_ifp_initial(struct thread *thread);
+static void bgp_nht_ifp_initial(struct event *thread);
static int bgp_isvalid_nexthop(struct bgp_nexthop_cache *bnc)
{
@@ -324,7 +324,7 @@ int bgp_find_or_add_nexthop(struct bgp *bgp_route, struct bgp *bgp_nexthop,
* Gather the ifindex for if up/down events to be
* tagged into this fun
*/
- if (afi == AFI_IP6 &&
+ if (afi == AFI_IP6 && peer->conf_if &&
IN6_IS_ADDR_LINKLOCAL(&peer->su.sin6.sin6_addr)) {
ifindex = peer->su.sin6.sin6_scope_id;
if (ifindex == 0) {
@@ -756,10 +756,10 @@ void bgp_nht_ifp_down(struct interface *ifp)
bgp_nht_ifp_handle(ifp, false);
}
-static void bgp_nht_ifp_initial(struct thread *thread)
+static void bgp_nht_ifp_initial(struct event *thread)
{
- ifindex_t ifindex = THREAD_VAL(thread);
- struct bgp *bgp = THREAD_ARG(thread);
+ ifindex_t ifindex = EVENT_VAL(thread);
+ struct bgp *bgp = EVENT_ARG(thread);
struct interface *ifp = if_lookup_by_index(ifindex, bgp->vrf_id);
if (!ifp)
@@ -811,8 +811,8 @@ void bgp_nht_interface_events(struct peer *peer)
return;
if (bnc->ifindex)
- thread_add_event(bm->master, bgp_nht_ifp_initial, bnc->bgp,
- bnc->ifindex, NULL);
+ event_add_event(bm->master, bgp_nht_ifp_initial, bnc->bgp,
+ bnc->ifindex, NULL);
}
void bgp_parse_nexthop_update(int command, vrf_id_t vrf_id)
diff --git a/bgpd/bgp_open.c b/bgpd/bgp_open.c
index 032767820f..0dd5463979 100644
--- a/bgpd/bgp_open.c
+++ b/bgpd/bgp_open.c
@@ -8,7 +8,7 @@
#include "linklist.h"
#include "prefix.h"
#include "stream.h"
-#include "thread.h"
+#include "frrevent.h"
#include "log.h"
#include "command.h"
#include "memory.h"
@@ -604,12 +604,24 @@ static int bgp_capability_restart(struct peer *peer,
static int bgp_capability_llgr(struct peer *peer,
struct capability_header *caphdr)
{
+/*
+ * +--------------------------------------------------+
+ * | Address Family Identifier (16 bits) |
+ * +--------------------------------------------------+
+ * | Subsequent Address Family Identifier (8 bits) |
+ * +--------------------------------------------------+
+ * | Flags for Address Family (8 bits) |
+ * +--------------------------------------------------+
+ * | Long-lived Stale Time (24 bits) |
+ * +--------------------------------------------------+
+ */
+#define BGP_CAP_LLGR_MIN_PACKET_LEN 7
struct stream *s = BGP_INPUT(peer);
size_t end = stream_get_getp(s) + caphdr->length;
SET_FLAG(peer->cap, PEER_CAP_LLGR_RCV);
- while (stream_get_getp(s) + 4 <= end) {
+ while (stream_get_getp(s) + BGP_CAP_LLGR_MIN_PACKET_LEN <= end) {
afi_t afi;
safi_t safi;
iana_afi_t pkt_afi = stream_getw(s);
diff --git a/bgpd/bgp_packet.c b/bgpd/bgp_packet.c
index 93672d29f1..9469a0778f 100644
--- a/bgpd/bgp_packet.c
+++ b/bgpd/bgp_packet.c
@@ -8,7 +8,7 @@
#include <zebra.h>
#include <sys/time.h>
-#include "thread.h"
+#include "frrevent.h"
#include "stream.h"
#include "network.h"
#include "prefix.h"
@@ -331,7 +331,7 @@ static void bgp_update_explicit_eors(struct peer *peer)
* calling safi function and for evpn, passed as parameter
*/
int bgp_nlri_parse(struct peer *peer, struct attr *attr,
- struct bgp_nlri *packet, int mp_withdraw)
+ struct bgp_nlri *packet, bool mp_withdraw)
{
switch (packet->safi) {
case SAFI_UNICAST:
@@ -442,9 +442,9 @@ static void bgp_write_proceed_actions(struct peer *peer)
* update group a peer belongs to, encode this information into packets, and
* enqueue the packets onto the peer's output buffer.
*/
-void bgp_generate_updgrp_packets(struct thread *thread)
+void bgp_generate_updgrp_packets(struct event *thread)
{
- struct peer *peer = THREAD_ARG(thread);
+ struct peer *peer = EVENT_ARG(thread);
struct stream *s;
struct peer_af *paf;
@@ -1792,11 +1792,11 @@ static int bgp_keepalive_receive(struct peer *peer, bgp_size_t size)
return Receive_KEEPALIVE_message;
}
-static void bgp_refresh_stalepath_timer_expire(struct thread *thread)
+static void bgp_refresh_stalepath_timer_expire(struct event *thread)
{
struct peer_af *paf;
- paf = THREAD_ARG(thread);
+ paf = EVENT_ARG(thread);
afi_t afi = paf->afi;
safi_t safi = paf->safi;
@@ -2106,11 +2106,11 @@ static int bgp_update_receive(struct peer *peer, bgp_size_t size)
"EOR RCV",
gr_info->eor_received);
if (gr_info->t_select_deferral) {
- void *info = THREAD_ARG(
+ void *info = EVENT_ARG(
gr_info->t_select_deferral);
XFREE(MTYPE_TMP, info);
}
- THREAD_OFF(gr_info->t_select_deferral);
+ EVENT_OFF(gr_info->t_select_deferral);
gr_info->eor_required = 0;
gr_info->eor_received = 0;
/* Best path selection */
@@ -2595,10 +2595,10 @@ static int bgp_route_refresh_receive(struct peer *peer, bgp_size_t size)
}
if (peer_established(peer))
- thread_add_timer(bm->master,
- bgp_refresh_stalepath_timer_expire,
- paf, peer->bgp->stalepath_time,
- &peer->t_refresh_stalepath);
+ event_add_timer(bm->master,
+ bgp_refresh_stalepath_timer_expire, paf,
+ peer->bgp->stalepath_time,
+ &peer->t_refresh_stalepath);
if (bgp_debug_neighbor_events(peer))
zlog_debug(
@@ -2613,7 +2613,7 @@ static int bgp_route_refresh_receive(struct peer *peer, bgp_size_t size)
return BGP_PACKET_NOOP;
}
- THREAD_OFF(peer->t_refresh_stalepath);
+ EVENT_OFF(peer->t_refresh_stalepath);
SET_FLAG(peer->af_sflags[afi][safi], PEER_STATUS_EORR_RECEIVED);
UNSET_FLAG(peer->af_sflags[afi][safi],
@@ -2863,11 +2863,11 @@ int bgp_capability_receive(struct peer *peer, bgp_size_t size)
* would not, making event flow difficult to understand. Please think twice
* before hacking this.
*
- * Thread type: THREAD_EVENT
+ * Thread type: EVENT_EVENT
* @param thread
* @return 0
*/
-void bgp_process_packet(struct thread *thread)
+void bgp_process_packet(struct event *thread)
{
/* Yes first of all get peer pointer. */
struct peer *peer; // peer
@@ -2875,7 +2875,7 @@ void bgp_process_packet(struct thread *thread)
int fsm_update_result; // return code of bgp_event_update()
int mprc; // message processing return code
- peer = THREAD_ARG(thread);
+ peer = EVENT_ARG(thread);
rpkt_quanta_old = atomic_load_explicit(&peer->bgp->rpkt_quanta,
memory_order_relaxed);
fsm_update_result = 0;
@@ -3021,9 +3021,9 @@ void bgp_process_packet(struct thread *thread)
frr_with_mutex (&peer->io_mtx) {
// more work to do, come back later
if (peer->ibuf->count > 0)
- thread_add_event(
- bm->master, bgp_process_packet, peer, 0,
- &peer->t_process_packet);
+ event_add_event(bm->master, bgp_process_packet,
+ peer, 0,
+ &peer->t_process_packet);
}
}
}
@@ -3044,13 +3044,13 @@ void bgp_send_delayed_eor(struct bgp *bgp)
* having the io pthread try to enqueue fsm events or mess with the peer
* struct.
*/
-void bgp_packet_process_error(struct thread *thread)
+void bgp_packet_process_error(struct event *thread)
{
struct peer *peer;
int code;
- peer = THREAD_ARG(thread);
- code = THREAD_VAL(thread);
+ peer = EVENT_ARG(thread);
+ code = EVENT_VAL(thread);
if (bgp_debug_neighbor_events(peer))
zlog_debug("%s [Event] BGP error %d on fd %d",
diff --git a/bgpd/bgp_packet.h b/bgpd/bgp_packet.h
index 2eb5693ae2..04bdb81849 100644
--- a/bgpd/bgp_packet.h
+++ b/bgpd/bgp_packet.h
@@ -42,37 +42,39 @@ DECLARE_HOOK(bgp_packet_send,
} while (0)
/* Packet send and receive function prototypes. */
-extern void bgp_keepalive_send(struct peer *);
-extern void bgp_open_send(struct peer *);
-extern void bgp_notify_send(struct peer *, uint8_t, uint8_t);
-extern void bgp_notify_send_with_data(struct peer *, uint8_t, uint8_t,
- uint8_t *, size_t);
+extern void bgp_keepalive_send(struct peer *peer);
+extern void bgp_open_send(struct peer *peer);
+extern void bgp_notify_send(struct peer *peer, uint8_t code, uint8_t sub_code);
+extern void bgp_notify_send_with_data(struct peer *peer, uint8_t code,
+ uint8_t sub_code, uint8_t *data,
+ size_t datalen);
void bgp_notify_io_invalid(struct peer *peer, uint8_t code, uint8_t sub_code,
uint8_t *data, size_t datalen);
extern void bgp_route_refresh_send(struct peer *peer, afi_t afi, safi_t safi,
uint8_t orf_type, uint8_t when_to_refresh,
int remove, uint8_t subtype);
-extern void bgp_capability_send(struct peer *, afi_t, safi_t, int, int);
+extern void bgp_capability_send(struct peer *peer, afi_t afi, safi_t safi,
+ int capabilty_code, int action);
-extern int bgp_capability_receive(struct peer *, bgp_size_t);
+extern int bgp_capability_receive(struct peer *peer, bgp_size_t length);
-extern int bgp_nlri_parse(struct peer *, struct attr *, struct bgp_nlri *,
- int mp_withdraw);
+extern int bgp_nlri_parse(struct peer *peer, struct attr *attr,
+ struct bgp_nlri *nlri, bool mp_withdraw);
-extern void bgp_update_restarted_peers(struct peer *);
-extern void bgp_update_implicit_eors(struct peer *);
-extern void bgp_check_update_delay(struct bgp *);
+extern void bgp_update_restarted_peers(struct peer *peer);
+extern void bgp_update_implicit_eors(struct peer *peer);
+extern void bgp_check_update_delay(struct bgp *peer);
extern int bgp_packet_set_marker(struct stream *s, uint8_t type);
extern void bgp_packet_set_size(struct stream *s);
-extern void bgp_generate_updgrp_packets(struct thread *);
-extern void bgp_process_packet(struct thread *);
+extern void bgp_generate_updgrp_packets(struct event *event);
+extern void bgp_process_packet(struct event *event);
extern void bgp_send_delayed_eor(struct bgp *bgp);
/* Task callback to handle socket error encountered in the io pthread */
-void bgp_packet_process_error(struct thread *thread);
+void bgp_packet_process_error(struct event *thread);
extern struct bgp_notify
bgp_notify_decapsulate_hard_reset(struct bgp_notify *notify);
extern bool bgp_has_graceful_restart_notification(struct peer *peer);
diff --git a/bgpd/bgp_pbr.c b/bgpd/bgp_pbr.c
index 7bced6cd33..bc9ecff7d9 100644
--- a/bgpd/bgp_pbr.c
+++ b/bgpd/bgp_pbr.c
@@ -1014,7 +1014,7 @@ static void bgp_pbr_match_free(void *arg)
bpm->action = NULL;
}
}
- hash_free(bpm->entry_hash);
+ hash_clean_and_free(&bpm->entry_hash, NULL);
XFREE(MTYPE_PBR_MATCH, bpm);
}
@@ -1386,23 +1386,13 @@ struct bgp_pbr_match *bgp_pbr_match_iptable_lookup(vrf_id_t vrf_id,
void bgp_pbr_cleanup(struct bgp *bgp)
{
- if (bgp->pbr_match_hash) {
- hash_clean(bgp->pbr_match_hash, bgp_pbr_match_free);
- hash_free(bgp->pbr_match_hash);
- bgp->pbr_match_hash = NULL;
- }
- if (bgp->pbr_rule_hash) {
- hash_clean(bgp->pbr_rule_hash, bgp_pbr_rule_free);
- hash_free(bgp->pbr_rule_hash);
- bgp->pbr_rule_hash = NULL;
- }
- if (bgp->pbr_action_hash) {
- hash_clean(bgp->pbr_action_hash, bgp_pbr_action_free);
- hash_free(bgp->pbr_action_hash);
- bgp->pbr_action_hash = NULL;
- }
+ hash_clean_and_free(&bgp->pbr_match_hash, bgp_pbr_match_free);
+ hash_clean_and_free(&bgp->pbr_rule_hash, bgp_pbr_rule_free);
+ hash_clean_and_free(&bgp->pbr_action_hash, bgp_pbr_action_free);
+
if (bgp->bgp_pbr_cfg == NULL)
return;
+
bgp_pbr_reset(bgp, AFI_IP);
bgp_pbr_reset(bgp, AFI_IP6);
XFREE(MTYPE_PBR, bgp->bgp_pbr_cfg);
diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c
index 1e9f9429c5..b49206adce 100644
--- a/bgpd/bgp_route.c
+++ b/bgpd/bgp_route.c
@@ -20,7 +20,7 @@
#include "buffer.h"
#include "sockunion.h"
#include "plist.h"
-#include "thread.h"
+#include "frrevent.h"
#include "workqueue.h"
#include "queue.h"
#include "memory.h"
@@ -151,9 +151,9 @@ struct bgp_dest *bgp_afi_node_get(struct bgp_table *table, afi_t afi,
return dest;
}
-struct bgp_dest *bgp_afi_node_lookup(struct bgp_table *table, afi_t afi,
- safi_t safi, const struct prefix *p,
- struct prefix_rd *prd)
+struct bgp_dest *bgp_safi_node_lookup(struct bgp_table *table, safi_t safi,
+ const struct prefix *p,
+ struct prefix_rd *prd)
{
struct bgp_dest *dest;
struct bgp_dest *pdest = NULL;
@@ -316,10 +316,15 @@ static int bgp_dest_set_defer_flag(struct bgp_dest *dest, bool delete)
return 0;
if (CHECK_FLAG(dest->flags, BGP_NODE_PROCESS_SCHEDULED)) {
- if (BGP_DEBUG(update, UPDATE_OUT))
+ if (BGP_DEBUG(update, UPDATE_OUT)) {
+ table = bgp_dest_table(dest);
+ if (table)
+ bgp = table->bgp;
+
zlog_debug(
- "Route %pBD is in workqueue and being processed, not deferred.",
- dest);
+ "Route %pBD(%s) is in workqueue and being processed, not deferred.",
+ dest, bgp ? bgp->name_pretty : "(Unknown)");
+ }
return 0;
}
@@ -367,8 +372,8 @@ static int bgp_dest_set_defer_flag(struct bgp_dest *dest, bool delete)
bgp->gr_info[afi][safi].gr_deferred++;
SET_FLAG(dest->flags, BGP_NODE_SELECT_DEFER);
if (BGP_DEBUG(update, UPDATE_OUT))
- zlog_debug("DEFER route %pBD, dest %p", dest,
- dest);
+ zlog_debug("DEFER route %pBD(%s), dest %p",
+ dest, bgp->name_pretty, dest);
return 0;
}
}
@@ -2381,7 +2386,10 @@ bool subgroup_announce_check(struct bgp_dest *dest, struct bgp_path_info *pi,
if (bgp_debug_update(NULL, p, subgrp->update_group, 0))
zlog_debug(
"%pBP [Update:SEND] %pFX is filtered by route-map '%s'",
- peer, p, ROUTE_MAP_OUT_NAME(filter));
+ peer, p,
+ bgp_path_suppressed(pi)
+ ? UNSUPPRESS_MAP_NAME(filter)
+ : ROUTE_MAP_OUT_NAME(filter));
bgp_attr_flush(rmap_path.attr);
return false;
}
@@ -2613,14 +2621,14 @@ bool subgroup_announce_check(struct bgp_dest *dest, struct bgp_path_info *pi,
return true;
}
-static void bgp_route_select_timer_expire(struct thread *thread)
+static void bgp_route_select_timer_expire(struct event *thread)
{
struct afi_safi_info *info;
afi_t afi;
safi_t safi;
struct bgp *bgp;
- info = THREAD_ARG(thread);
+ info = EVENT_ARG(thread);
afi = info->afi;
safi = info->safi;
bgp = info->bgp;
@@ -2755,8 +2763,10 @@ void bgp_best_selection(struct bgp *bgp, struct bgp_dest *dest,
bgp_path_info_reap(dest, pi);
if (debug)
- zlog_debug("%s: pi %p in holddown", __func__,
- pi);
+ zlog_debug(
+ "%s: %pBD(%s) pi from %s in holddown",
+ __func__, dest, bgp->name_pretty,
+ pi->peer->host);
continue;
}
@@ -2767,8 +2777,10 @@ void bgp_best_selection(struct bgp *bgp, struct bgp_dest *dest,
if (debug)
zlog_debug(
- "%s: pi %p non self peer %s not estab state",
- __func__, pi, pi->peer->host);
+ "%s: %pBD(%s) non self peer %s not estab state",
+ __func__, dest,
+ bgp->name_pretty,
+ pi->peer->host);
continue;
}
@@ -2777,7 +2789,9 @@ void bgp_best_selection(struct bgp *bgp, struct bgp_dest *dest,
&& (!CHECK_FLAG(pi->flags, BGP_PATH_DMED_SELECTED))) {
bgp_path_info_unset_flag(dest, pi, BGP_PATH_DMED_CHECK);
if (debug)
- zlog_debug("%s: pi %p dmed", __func__, pi);
+ zlog_debug("%s: %pBD(%s) pi %s dmed", __func__,
+ dest, bgp->name_pretty,
+ pi->peer->host);
continue;
}
@@ -2840,8 +2854,9 @@ void bgp_best_selection(struct bgp *bgp, struct bgp_dest *dest,
if (!bgp_path_info_nexthop_cmp(pi, new_select)) {
if (debug)
zlog_debug(
- "%pBD: %s has the same nexthop as the bestpath, skip it",
- dest, path_buf);
+ "%pBD(%s): %s has the same nexthop as the bestpath, skip it",
+ dest, bgp->name_pretty,
+ path_buf);
continue;
}
@@ -2852,8 +2867,9 @@ void bgp_best_selection(struct bgp *bgp, struct bgp_dest *dest,
if (paths_eq) {
if (debug)
zlog_debug(
- "%pBD: %s is equivalent to the bestpath, add to the multipath list",
- dest, path_buf);
+ "%pBD(%s): %s is equivalent to the bestpath, add to the multipath list",
+ dest, bgp->name_pretty,
+ path_buf);
bgp_mp_list_add(&mp_list, pi);
}
}
@@ -2921,10 +2937,14 @@ void subgroup_process_announce_selected(struct update_subgroup *subgrp,
* in FIB, then it is advertised
*/
if (advertise) {
- if (!bgp_check_withdrawal(bgp, dest))
- bgp_adj_out_set_subgroup(
- dest, subgrp, &attr, selected);
- else
+ if (!bgp_check_withdrawal(bgp, dest)) {
+ struct attr *adv_attr =
+ bgp_attr_intern(&attr);
+
+ bgp_adj_out_set_subgroup(dest, subgrp,
+ adv_attr,
+ selected);
+ } else
bgp_adj_out_unset_subgroup(
dest, subgrp, 1, addpath_tx_id);
}
@@ -3050,7 +3070,9 @@ static void bgp_process_evpn_route_injection(struct bgp *bgp, afi_t afi,
* the IMPLICIT_NULL label. This is pretty specialized: it's only called
* in a path where we basically _know_ this is a BGP-LU route.
*/
-static bool bgp_lu_need_imp_null(const struct bgp_path_info *new_select)
+static bool bgp_lu_need_null_label(struct bgp *bgp,
+ const struct bgp_path_info *new_select,
+ afi_t afi, mpls_label_t *label)
{
/* Certain types get imp null; so do paths where the nexthop is
* not labeled.
@@ -3059,12 +3081,20 @@ static bool bgp_lu_need_imp_null(const struct bgp_path_info *new_select)
|| new_select->sub_type == BGP_ROUTE_AGGREGATE
|| new_select->sub_type == BGP_ROUTE_REDISTRIBUTE)
return true;
- else if (new_select->extra == NULL ||
- !bgp_is_valid_label(&new_select->extra->label[0]))
- /* TODO -- should be configurable? */
+ else if (new_select->extra &&
+ bgp_is_valid_label(&new_select->extra->label[0]))
+ return false;
+ if (label == NULL)
return true;
+ if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_LU_EXPLICIT_NULL))
+ /* Disable PHP : explicit-null */
+ *label = afi == AFI_IP ? MPLS_LABEL_IPV4_EXPLICIT_NULL
+ : MPLS_LABEL_IPV6_EXPLICIT_NULL;
else
- return false;
+ /* Enforced PHP popping: implicit-null */
+ *label = MPLS_LABEL_IMPLICIT_NULL;
+
+ return true;
}
/*
@@ -3093,14 +3123,15 @@ static void bgp_process_main_one(struct bgp *bgp, struct bgp_dest *dest,
struct bgp_path_info *old_select;
struct bgp_path_info_pair old_and_new;
int debug = 0;
+ mpls_label_t mpls_label_null;
if (CHECK_FLAG(bgp->flags, BGP_FLAG_DELETE_IN_PROGRESS)) {
if (dest)
debug = bgp_debug_bestpath(dest);
if (debug)
zlog_debug(
- "%s: bgp delete in progress, ignoring event, p=%pBD",
- __func__, dest);
+ "%s: bgp delete in progress, ignoring event, p=%pBD(%s)",
+ __func__, dest, bgp->name_pretty);
return;
}
/* Is it end of initial update? (after startup) */
@@ -3123,7 +3154,7 @@ static void bgp_process_main_one(struct bgp *bgp, struct bgp_dest *dest,
debug = bgp_debug_bestpath(dest);
if (debug)
- zlog_debug("%s: p=%pBDi(%s) afi=%s, safi=%s start", __func__,
+ zlog_debug("%s: p=%pBD(%s) afi=%s, safi=%s start", __func__,
dest, bgp->name_pretty, afi2str(afi),
safi2str(safi));
@@ -3132,7 +3163,8 @@ static void bgp_process_main_one(struct bgp *bgp, struct bgp_dest *dest,
*/
if (CHECK_FLAG(dest->flags, BGP_NODE_SELECT_DEFER)) {
if (BGP_DEBUG(update, UPDATE_OUT))
- zlog_debug("SELECT_DEFER flag set for route %p", dest);
+ zlog_debug("SELECT_DEFER flag set for route %p(%s)",
+ dest, bgp->name_pretty);
return;
}
@@ -3146,7 +3178,7 @@ static void bgp_process_main_one(struct bgp *bgp, struct bgp_dest *dest,
* Right now, since we only deal with per-prefix labels, it is not
* necessary to do this upon changes to best path. Exceptions:
* - label index has changed -> recalculate resulting label
- * - path_info sub_type changed -> switch to/from implicit-null
+ * - path_info sub_type changed -> switch to/from null label value
* - no valid label (due to removed static label binding) -> get new one
*/
if (bgp->allocate_mpls_labels[afi][safi]) {
@@ -3155,11 +3187,12 @@ static void bgp_process_main_one(struct bgp *bgp, struct bgp_dest *dest,
|| bgp_label_index_differs(new_select, old_select)
|| new_select->sub_type != old_select->sub_type
|| !bgp_is_valid_label(&dest->local_label)) {
- /* Enforced penultimate hop popping:
- * implicit-null for local routes, aggregate
- * and redistributed routes
+ /* control label imposition for local routes,
+ * aggregate and redistributed routes
*/
- if (bgp_lu_need_imp_null(new_select)) {
+ mpls_label_null = MPLS_LABEL_IMPLICIT_NULL;
+ if (bgp_lu_need_null_label(bgp, new_select, afi,
+ &mpls_label_null)) {
if (CHECK_FLAG(
dest->flags,
BGP_NODE_REGISTERED_FOR_LABEL)
@@ -3168,8 +3201,7 @@ static void bgp_process_main_one(struct bgp *bgp, struct bgp_dest *dest,
BGP_NODE_LABEL_REQUESTED))
bgp_unregister_for_label(dest);
dest->local_label = mpls_lse_encode(
- MPLS_LABEL_IMPLICIT_NULL, 0, 0,
- 1);
+ mpls_label_null, 0, 0, 1);
bgp_set_valid_label(&dest->local_label);
} else
bgp_register_for_label(dest,
@@ -3207,11 +3239,6 @@ static void bgp_process_main_one(struct bgp *bgp, struct bgp_dest *dest,
if (bgp_fibupd_safi(safi)
&& !bgp_option_check(BGP_OPT_NO_FIB)) {
- if (BGP_SUPPRESS_FIB_ENABLED(bgp)
- && new_select->sub_type == BGP_ROUTE_NORMAL)
- SET_FLAG(dest->flags,
- BGP_NODE_FIB_INSTALL_PENDING);
-
if (new_select->type == ZEBRA_ROUTE_BGP
&& (new_select->sub_type == BGP_ROUTE_NORMAL
|| new_select->sub_type
@@ -3263,7 +3290,7 @@ static void bgp_process_main_one(struct bgp *bgp, struct bgp_dest *dest,
if (!bgp->t_rmap_def_originate_eval) {
bgp_lock(bgp);
- thread_add_timer(
+ event_add_timer(
bm->master,
update_group_refresh_default_originate_route_map,
bgp, RMAP_DEFAULT_ORIGINATE_EVAL_TIMER,
@@ -3317,10 +3344,6 @@ static void bgp_process_main_one(struct bgp *bgp, struct bgp_dest *dest,
|| new_select->sub_type == BGP_ROUTE_AGGREGATE
|| new_select->sub_type == BGP_ROUTE_IMPORTED)) {
- if (BGP_SUPPRESS_FIB_ENABLED(bgp))
- SET_FLAG(dest->flags,
- BGP_NODE_FIB_INSTALL_PENDING);
-
/* if this is an evpn imported type-5 prefix,
* we need to withdraw the route first to clear
* the nh neigh and the RMAC entry.
@@ -3363,11 +3386,11 @@ void bgp_best_path_select_defer(struct bgp *bgp, afi_t afi, safi_t safi)
struct afi_safi_info *thread_info;
if (bgp->gr_info[afi][safi].t_route_select) {
- struct thread *t = bgp->gr_info[afi][safi].t_route_select;
+ struct event *t = bgp->gr_info[afi][safi].t_route_select;
- thread_info = THREAD_ARG(t);
+ thread_info = EVENT_ARG(t);
XFREE(MTYPE_TMP, thread_info);
- THREAD_OFF(bgp->gr_info[afi][safi].t_route_select);
+ EVENT_OFF(bgp->gr_info[afi][safi].t_route_select);
}
if (BGP_DEBUG(update, UPDATE_OUT)) {
@@ -3401,7 +3424,7 @@ void bgp_best_path_select_defer(struct bgp *bgp, afi_t afi, safi_t safi)
if (!bgp->gr_info[afi][safi].gr_deferred) {
bgp_send_delayed_eor(bgp);
/* Send route processing complete message to RIB */
- bgp_zebra_update(afi, safi, bgp->vrf_id,
+ bgp_zebra_update(bgp, afi, safi,
ZEBRA_CLIENT_ROUTE_UPDATE_COMPLETE);
return;
}
@@ -3415,7 +3438,7 @@ void bgp_best_path_select_defer(struct bgp *bgp, afi_t afi, safi_t safi)
/* If there are more routes to be processed, start the
* selection timer
*/
- thread_add_timer(bm->master, bgp_route_select_timer_expire, thread_info,
+ event_add_timer(bm->master, bgp_route_select_timer_expire, thread_info,
BGP_ROUTE_SELECT_DELAY,
&bgp->gr_info[afi][safi].t_route_select);
}
@@ -3567,11 +3590,11 @@ void bgp_add_eoiu_mark(struct bgp *bgp)
work_queue_add(bgp->process_queue, pqnode);
}
-static void bgp_maximum_prefix_restart_timer(struct thread *thread)
+static void bgp_maximum_prefix_restart_timer(struct event *thread)
{
struct peer *peer;
- peer = THREAD_ARG(thread);
+ peer = EVENT_ARG(thread);
peer->t_pmax_restart = NULL;
if (bgp_debug_neighbor_events(peer))
@@ -3826,6 +3849,12 @@ bool bgp_update_martian_nexthop(struct bgp *bgp, afi_t afi, safi_t safi,
(type == ZEBRA_ROUTE_BGP && stype == BGP_ROUTE_STATIC) ? true
: false;
+ /* If `bgp allow-martian-nexthop` is turned on, return next-hop
+ * as good.
+ */
+ if (bgp->allow_martian)
+ return false;
+
/*
* Only validated for unicast and multicast currently.
* Also valid for EVPN where the nexthop is an IP address.
@@ -4250,18 +4279,6 @@ void bgp_update(struct peer *peer, const struct prefix *p, uint32_t addpath_id,
bgp_attr_flush(&new_attr);
goto filtered;
}
- /* The flag BGP_NODE_FIB_INSTALL_PENDING is for the following
- * condition :
- * Suppress fib is enabled
- * BGP_OPT_NO_FIB is not enabled
- * Route type is BGP_ROUTE_NORMAL (peer learnt routes)
- * Route is being installed first time (BGP_NODE_FIB_INSTALLED not set)
- */
- if (bgp_fibupd_safi(safi) && BGP_SUPPRESS_FIB_ENABLED(bgp)
- && (sub_type == BGP_ROUTE_NORMAL)
- && (!bgp_option_check(BGP_OPT_NO_FIB))
- && (!CHECK_FLAG(dest->flags, BGP_NODE_FIB_INSTALLED)))
- SET_FLAG(dest->flags, BGP_NODE_FIB_INSTALL_PENDING);
/* If neighbor soo is configured, tag all incoming routes with
* this SoO tag and then filter out advertisements in
@@ -5028,7 +5045,7 @@ void bgp_stop_announce_route_timer(struct peer_af *paf)
if (!paf->t_announce_route)
return;
- THREAD_OFF(paf->t_announce_route);
+ EVENT_OFF(paf->t_announce_route);
}
/*
@@ -5037,12 +5054,12 @@ void bgp_stop_announce_route_timer(struct peer_af *paf)
* Callback that is invoked when the route announcement timer for a
* peer_af expires.
*/
-static void bgp_announce_route_timer_expired(struct thread *t)
+static void bgp_announce_route_timer_expired(struct event *t)
{
struct peer_af *paf;
struct peer *peer;
- paf = THREAD_ARG(t);
+ paf = EVENT_ARG(t);
peer = paf->peer;
if (!peer_established(peer))
@@ -5091,11 +5108,11 @@ void bgp_announce_route(struct peer *peer, afi_t afi, safi_t safi, bool force)
* multiple peers and the announcement doesn't happen in the
* vty context.
*/
- thread_add_timer_msec(bm->master, bgp_announce_route_timer_expired, paf,
- (subgrp->peer_count == 1)
- ? BGP_ANNOUNCE_ROUTE_SHORT_DELAY_MS
- : BGP_ANNOUNCE_ROUTE_DELAY_MS,
- &paf->t_announce_route);
+ event_add_timer_msec(bm->master, bgp_announce_route_timer_expired, paf,
+ (subgrp->peer_count == 1)
+ ? BGP_ANNOUNCE_ROUTE_SHORT_DELAY_MS
+ : BGP_ANNOUNCE_ROUTE_DELAY_MS,
+ &paf->t_announce_route);
}
/*
@@ -5197,7 +5214,7 @@ static void bgp_soft_reconfig_table(struct peer *peer, afi_t afi, safi_t safi,
* Without splitting the full job into several part,
* vtysh waits for the job to finish before responding to a BGP command
*/
-static void bgp_soft_reconfig_table_task(struct thread *thread)
+static void bgp_soft_reconfig_table_task(struct event *thread)
{
uint32_t iter, max_iter;
struct bgp_dest *dest;
@@ -5207,7 +5224,7 @@ static void bgp_soft_reconfig_table_task(struct thread *thread)
struct prefix_rd *prd;
struct listnode *node, *nnode;
- table = THREAD_ARG(thread);
+ table = EVENT_ARG(thread);
prd = NULL;
max_iter = SOFT_RECONFIG_TASK_MAX_PREFIX;
@@ -5245,8 +5262,8 @@ static void bgp_soft_reconfig_table_task(struct thread *thread)
*/
if (dest || table->soft_reconfig_init) {
table->soft_reconfig_init = false;
- thread_add_event(bm->master, bgp_soft_reconfig_table_task,
- table, 0, &table->soft_reconfig_thread);
+ event_add_event(bm->master, bgp_soft_reconfig_table_task, table,
+ 0, &table->soft_reconfig_thread);
return;
}
/* we're done, clean up the background iteration context info and
@@ -5301,7 +5318,7 @@ void bgp_soft_reconfig_table_task_cancel(const struct bgp *bgp,
list_delete(&ntable->soft_reconfig_peers);
bgp_soft_reconfig_table_flag(ntable, false);
- THREAD_OFF(ntable->soft_reconfig_thread);
+ EVENT_OFF(ntable->soft_reconfig_thread);
}
}
@@ -5347,9 +5364,9 @@ bool bgp_soft_reconfig_in(struct peer *peer, afi_t afi, safi_t safi)
bgp_soft_reconfig_table_flag(table, true);
if (!table->soft_reconfig_thread)
- thread_add_event(bm->master,
- bgp_soft_reconfig_table_task, table, 0,
- &table->soft_reconfig_thread);
+ event_add_event(bm->master,
+ bgp_soft_reconfig_table_task, table, 0,
+ &table->soft_reconfig_thread);
/* Cancel bgp_announce_route_timer_expired threads.
* bgp_announce_route_timer_expired threads have been scheduled
* to announce routes as soon as the soft_reconfigure process
@@ -7239,7 +7256,7 @@ static struct bgp_aggregate *bgp_aggregate_new(void)
return XCALLOC(MTYPE_BGP_AGGREGATE, sizeof(struct bgp_aggregate));
}
-static void bgp_aggregate_free(struct bgp_aggregate *aggregate)
+void bgp_aggregate_free(struct bgp_aggregate *aggregate)
{
XFREE(MTYPE_ROUTE_MAP_NAME, aggregate->suppress_map_name);
route_map_counter_decrement(aggregate->suppress_map);
@@ -7452,6 +7469,10 @@ static void bgp_aggregate_install(
aggregate, atomic_aggregate, p);
if (!attr) {
+ aspath_free(aspath);
+ community_free(&community);
+ ecommunity_free(&ecommunity);
+ lcommunity_free(&lcommunity);
bgp_dest_unlock_node(dest);
bgp_aggregate_delete(bgp, p, afi, safi, aggregate);
if (BGP_DEBUG(update_groups, UPDATE_GROUPS))
@@ -7642,7 +7663,7 @@ static void bgp_aggregate_med_update(struct bgp_aggregate *aggregate,
}
/* Update an aggregate as routes are added/removed from the BGP table */
-void bgp_aggregate_route(struct bgp *bgp, const struct prefix *p, afi_t afi,
+bool bgp_aggregate_route(struct bgp *bgp, const struct prefix *p, afi_t afi,
safi_t safi, struct bgp_aggregate *aggregate)
{
struct bgp_table *table;
@@ -7661,10 +7682,8 @@ void bgp_aggregate_route(struct bgp *bgp, const struct prefix *p, afi_t afi,
* then do not create aggregate route
*/
if (CHECK_FLAG(bgp->flags, BGP_FLAG_DELETE_IN_PROGRESS) ||
- (bgp->peer_self == NULL)) {
- bgp_aggregate_free(aggregate);
- return;
- }
+ bgp->peer_self == NULL)
+ return false;
/* Initialize and test routes for MED difference. */
if (aggregate->match_med)
@@ -7856,6 +7875,8 @@ void bgp_aggregate_route(struct bgp *bgp, const struct prefix *p, afi_t afi,
bgp_aggregate_install(bgp, afi, safi, p, origin, aspath, community,
ecommunity, lcommunity, atomic_aggregate,
aggregate);
+
+ return true;
}
void bgp_aggregate_delete(struct bgp *bgp, const struct prefix *p, afi_t afi,
@@ -8334,59 +8355,7 @@ static int bgp_aggregate_unset(struct vty *vty, const char *prefix_str,
/* Unlock aggregate address configuration. */
bgp_dest_set_bgp_aggregate_info(dest, NULL);
- if (aggregate->community)
- community_free(&aggregate->community);
-
- if (aggregate->community_hash) {
- /* Delete all communities in the hash.
- */
- hash_clean(aggregate->community_hash,
- bgp_aggr_community_remove);
- /* Free up the community_hash.
- */
- hash_free(aggregate->community_hash);
- }
-
- if (aggregate->ecommunity)
- ecommunity_free(&aggregate->ecommunity);
-
- if (aggregate->ecommunity_hash) {
- /* Delete all ecommunities in the hash.
- */
- hash_clean(aggregate->ecommunity_hash,
- bgp_aggr_ecommunity_remove);
- /* Free up the ecommunity_hash.
- */
- hash_free(aggregate->ecommunity_hash);
- }
-
- if (aggregate->lcommunity)
- lcommunity_free(&aggregate->lcommunity);
-
- if (aggregate->lcommunity_hash) {
- /* Delete all lcommunities in the hash.
- */
- hash_clean(aggregate->lcommunity_hash,
- bgp_aggr_lcommunity_remove);
- /* Free up the lcommunity_hash.
- */
- hash_free(aggregate->lcommunity_hash);
- }
-
- if (aggregate->aspath)
- aspath_free(aggregate->aspath);
-
- if (aggregate->aspath_hash) {
- /* Delete all as-paths in the hash.
- */
- hash_clean(aggregate->aspath_hash,
- bgp_aggr_aspath_remove);
- /* Free up the aspath_hash.
- */
- hash_free(aggregate->aspath_hash);
- }
-
- bgp_aggregate_free(aggregate);
+ bgp_free_aggregate_info(aggregate);
bgp_dest_unlock_node(dest);
bgp_dest_unlock_node(dest);
@@ -8498,7 +8467,10 @@ static int bgp_aggregate_set(struct vty *vty, const char *prefix_str, afi_t afi,
bgp_dest_set_bgp_aggregate_info(dest, aggregate);
/* Aggregate address insert into BGP routing table. */
- bgp_aggregate_route(bgp, &p, afi, safi, aggregate);
+ if (!bgp_aggregate_route(bgp, &p, afi, safi, aggregate)) {
+ bgp_aggregate_free(aggregate);
+ bgp_dest_unlock_node(dest);
+ }
return CMD_SUCCESS;
}
@@ -8567,6 +8539,34 @@ DEFPY(aggregate_addressv4, aggregate_addressv4_cmd,
match_med != NULL, suppress_map);
}
+void bgp_free_aggregate_info(struct bgp_aggregate *aggregate)
+{
+ if (aggregate->community)
+ community_free(&aggregate->community);
+
+ hash_clean_and_free(&aggregate->community_hash,
+ bgp_aggr_community_remove);
+
+ if (aggregate->ecommunity)
+ ecommunity_free(&aggregate->ecommunity);
+
+ hash_clean_and_free(&aggregate->ecommunity_hash,
+ bgp_aggr_ecommunity_remove);
+
+ if (aggregate->lcommunity)
+ lcommunity_free(&aggregate->lcommunity);
+
+ hash_clean_and_free(&aggregate->lcommunity_hash,
+ bgp_aggr_lcommunity_remove);
+
+ if (aggregate->aspath)
+ aspath_free(aggregate->aspath);
+
+ hash_clean_and_free(&aggregate->aspath_hash, bgp_aggr_aspath_remove);
+
+ bgp_aggregate_free(aggregate);
+}
+
DEFPY(aggregate_addressv6, aggregate_addressv6_cmd,
"[no] aggregate-address X:X::X:X/M$prefix [{"
"as-set$as_set_s"
@@ -11109,7 +11109,7 @@ void route_vty_out_detail(struct vty *vty, struct bgp *bgp, struct bgp_dest *bn,
if (path->peer->t_gr_restart &&
CHECK_FLAG(path->flags, BGP_PATH_STALE)) {
unsigned long gr_remaining =
- thread_timer_remain_second(path->peer->t_gr_restart);
+ event_timer_remain_second(path->peer->t_gr_restart);
if (json_paths) {
json_object_int_add(json_path,
@@ -11125,7 +11125,7 @@ void route_vty_out_detail(struct vty *vty, struct bgp *bgp, struct bgp_dest *bn,
bgp_attr_get_community(attr) &&
community_include(bgp_attr_get_community(attr),
COMMUNITY_LLGR_STALE)) {
- unsigned long llgr_remaining = thread_timer_remain_second(
+ unsigned long llgr_remaining = event_timer_remain_second(
path->peer->t_llgr_stale[afi][safi]);
if (json_paths) {
@@ -11614,9 +11614,28 @@ static int bgp_show_table(struct vty *vty, struct bgp *bgp, safi_t safi,
vty_out(vty, ",\"%pFX\": ", dest_p);
}
+ /* This is used for 'json detail' vty keywords.
+ *
+ * In plain 'json' the per-prefix header is encoded
+ * as a standalone dictionary in the first json_paths
+ * array element:
+ * "<prefix>": [{header}, {path-1}, {path-N}]
+ * (which is confusing and borderline broken)
+ *
+ * For 'json detail' this changes the value
+ * of each prefix-key to be a dictionary where each
+ * header item has its own key, and json_paths is
+ * tucked under the "paths" key:
+ * "<prefix>": {
+ * "<header-key-1>": <header-val-1>,
+ * "<header-key-N>": <header-val-N>,
+ * "paths": [{path-1}, {path-N}]
+ * }
+ */
if (json_detail_header && json_paths != NULL) {
const struct prefix_rd *prd;
+ /* Start per-prefix dictionary */
vty_out(vty, "{\n");
prd = bgp_rd_from_dest(dest, safi);
@@ -11641,6 +11660,7 @@ static int bgp_show_table(struct vty *vty, struct bgp *bgp, safi_t safi,
*/
vty_json_no_pretty(vty, json_paths);
+ /* End per-prefix dictionary */
if (json_detail_header_used)
vty_out(vty, "} ");
@@ -13346,11 +13366,11 @@ static void bgp_table_stats_rn(struct bgp_dest *dest, struct bgp_dest *top,
}
}
-static void bgp_table_stats_walker(struct thread *t)
+static void bgp_table_stats_walker(struct event *t)
{
struct bgp_dest *dest, *ndest;
struct bgp_dest *top;
- struct bgp_table_stats *ts = THREAD_ARG(t);
+ struct bgp_table_stats *ts = EVENT_ARG(t);
unsigned int space = 0;
if (!(top = bgp_table_top(ts->table)))
@@ -13445,7 +13465,7 @@ static int bgp_table_stats_single(struct vty *vty, struct bgp *bgp, afi_t afi,
memset(&ts, 0, sizeof(ts));
ts.table = bgp->rib[afi][safi];
- thread_execute(bm->master, bgp_table_stats_walker, &ts, 0);
+ event_execute(bm->master, bgp_table_stats_walker, &ts, 0);
for (i = 0; i < BGP_STATS_MAX; i++) {
if ((!json && !table_stats_strs[i][TABLE_STATS_IDX_VTY])
@@ -13743,11 +13763,11 @@ static void bgp_peer_count_proc(struct bgp_dest *rn, struct peer_pcounts *pc)
}
}
-static void bgp_peer_count_walker(struct thread *t)
+static void bgp_peer_count_walker(struct event *t)
{
struct bgp_dest *rn, *rm;
const struct bgp_table *table;
- struct peer_pcounts *pc = THREAD_ARG(t);
+ struct peer_pcounts *pc = EVENT_ARG(t);
if (pc->safi == SAFI_MPLS_VPN || pc->safi == SAFI_ENCAP
|| pc->safi == SAFI_EVPN) {
@@ -13802,7 +13822,7 @@ static int bgp_peer_counts(struct vty *vty, struct peer *peer, afi_t afi,
* stats for the thread-walk (i.e. ensure this can't be blamed on
* on just vty_read()).
*/
- thread_execute(bm->master, bgp_peer_count_walker, &pcounts, 0);
+ event_execute(bm->master, bgp_peer_count_walker, &pcounts, 0);
if (use_json) {
json_object_string_add(json, "prefixCountsFor", peer->host);
diff --git a/bgpd/bgp_route.h b/bgpd/bgp_route.h
index 66cc62ab09..a64144b625 100644
--- a/bgpd/bgp_route.h
+++ b/bgpd/bgp_route.h
@@ -182,7 +182,7 @@ struct bgp_path_info_extra {
} export;
struct {
- struct thread *timer;
+ struct event *timer;
void *hme; /* encap monitor, if this is a VPN route */
struct prefix_rd
rd; /* import: route's route-distinguisher */
@@ -661,6 +661,7 @@ extern void bgp_process_queue_init(struct bgp *bgp);
extern void bgp_route_init(void);
extern void bgp_route_finish(void);
extern void bgp_cleanup_routes(struct bgp *);
+extern void bgp_free_aggregate_info(struct bgp_aggregate *aggregate);
extern void bgp_announce_route(struct peer *peer, afi_t afi, safi_t safi,
bool force);
extern void bgp_stop_announce_route_timer(struct peer_af *paf);
@@ -766,7 +767,7 @@ extern void bgp_config_write_distance(struct vty *, struct bgp *, afi_t,
extern void bgp_aggregate_delete(struct bgp *bgp, const struct prefix *p,
afi_t afi, safi_t safi,
struct bgp_aggregate *aggregate);
-extern void bgp_aggregate_route(struct bgp *bgp, const struct prefix *p,
+extern bool bgp_aggregate_route(struct bgp *bgp, const struct prefix *p,
afi_t afi, safi_t safi,
struct bgp_aggregate *aggregate);
extern void bgp_aggregate_increment(struct bgp *bgp, const struct prefix *p,
@@ -819,9 +820,10 @@ extern void bgp_peer_clear_node_queue_drain_immediate(struct peer *peer);
extern void bgp_process_queues_drain_immediate(void);
/* for encap/vpn */
-extern struct bgp_dest *bgp_afi_node_lookup(struct bgp_table *table, afi_t afi,
- safi_t safi, const struct prefix *p,
- struct prefix_rd *prd);
+extern struct bgp_dest *bgp_safi_node_lookup(struct bgp_table *table,
+ safi_t safi,
+ const struct prefix *p,
+ struct prefix_rd *prd);
extern void bgp_path_info_restore(struct bgp_dest *dest,
struct bgp_path_info *path);
@@ -876,6 +878,7 @@ extern void bgp_path_info_free_with_caller(const char *caller,
extern void bgp_path_info_add_with_caller(const char *caller,
struct bgp_dest *dest,
struct bgp_path_info *pi);
+extern void bgp_aggregate_free(struct bgp_aggregate *aggregate);
#define bgp_path_info_add(A, B) \
bgp_path_info_add_with_caller(__func__, (A), (B))
#define bgp_path_info_free(B) bgp_path_info_free_with_caller(__func__, (B))
diff --git a/bgpd/bgp_routemap.c b/bgpd/bgp_routemap.c
index 8fd46d00af..32ecb083be 100644
--- a/bgpd/bgp_routemap.c
+++ b/bgpd/bgp_routemap.c
@@ -461,7 +461,8 @@ route_match_ip_address(void *rule, const struct prefix *prefix, void *object)
if (prefix->family == AF_INET) {
alist = access_list_lookup(AFI_IP, (char *)rule);
if (alist == NULL) {
- if (CHECK_FLAG(rmap_debug, DEBUG_ROUTEMAP_DETAIL))
+ if (unlikely(CHECK_FLAG(rmap_debug,
+ DEBUG_ROUTEMAP_DETAIL)))
zlog_debug(
"%s: Access-List Specified: %s does not exist defaulting to NO_MATCH",
__func__, (char *)rule);
@@ -521,7 +522,8 @@ route_match_ip_next_hop(void *rule, const struct prefix *prefix, void *object)
alist = access_list_lookup(AFI_IP, (char *)rule);
if (alist == NULL) {
- if (CHECK_FLAG(rmap_debug, DEBUG_ROUTEMAP_DETAIL))
+ if (unlikely(CHECK_FLAG(rmap_debug,
+ DEBUG_ROUTEMAP_DETAIL)))
zlog_debug(
"%s: Access-List Specified: %s does not exist defaulting to NO_MATCH",
__func__, (char *)rule);
@@ -581,7 +583,8 @@ route_match_ip_route_source(void *rule, const struct prefix *pfx, void *object)
alist = access_list_lookup(AFI_IP, (char *)rule);
if (alist == NULL) {
- if (CHECK_FLAG(rmap_debug, DEBUG_ROUTEMAP_DETAIL))
+ if (unlikely(CHECK_FLAG(rmap_debug,
+ DEBUG_ROUTEMAP_DETAIL)))
zlog_debug(
"%s: Access-List Specified: %s does not exist defaulting to NO_MATCH",
__func__, (char *)rule);
@@ -676,7 +679,7 @@ route_match_address_prefix_list(void *rule, afi_t afi,
plist = prefix_list_lookup(afi, (char *)rule);
if (plist == NULL) {
- if (CHECK_FLAG(rmap_debug, DEBUG_ROUTEMAP_DETAIL))
+ if (unlikely(CHECK_FLAG(rmap_debug, DEBUG_ROUTEMAP_DETAIL)))
zlog_debug(
"%s: Prefix List %s specified does not exist defaulting to NO_MATCH",
__func__, (char *)rule);
@@ -737,7 +740,8 @@ route_match_ip_next_hop_prefix_list(void *rule, const struct prefix *prefix,
plist = prefix_list_lookup(AFI_IP, (char *)rule);
if (plist == NULL) {
- if (CHECK_FLAG(rmap_debug, DEBUG_ROUTEMAP_DETAIL))
+ if (unlikely(CHECK_FLAG(rmap_debug,
+ DEBUG_ROUTEMAP_DETAIL)))
zlog_debug(
"%s: Prefix List %s specified does not exist defaulting to NO_MATCH",
__func__, (char *)rule);
@@ -786,7 +790,8 @@ route_match_ipv6_next_hop_prefix_list(void *rule, const struct prefix *prefix,
plist = prefix_list_lookup(AFI_IP6, (char *)rule);
if (!plist) {
- if (CHECK_FLAG(rmap_debug, DEBUG_ROUTEMAP_DETAIL))
+ if (unlikely(CHECK_FLAG(rmap_debug,
+ DEBUG_ROUTEMAP_DETAIL)))
zlog_debug(
"%s: Prefix List %s specified does not exist defaulting to NO_MATCH",
__func__, (char *)rule);
@@ -891,7 +896,8 @@ route_match_ip_route_source_prefix_list(void *rule, const struct prefix *prefix,
plist = prefix_list_lookup(AFI_IP, (char *)rule);
if (plist == NULL) {
- if (CHECK_FLAG(rmap_debug, DEBUG_ROUTEMAP_DETAIL))
+ if (unlikely(CHECK_FLAG(rmap_debug,
+ DEBUG_ROUTEMAP_DETAIL)))
zlog_debug(
"%s: Prefix List %s specified does not exist defaulting to NO_MATCH",
__func__, (char *)rule);
@@ -956,7 +962,7 @@ route_match_mac_address(void *rule, const struct prefix *prefix, void *object)
alist = access_list_lookup(AFI_L2VPN, (char *)rule);
if (alist == NULL) {
- if (CHECK_FLAG(rmap_debug, DEBUG_ROUTEMAP_DETAIL))
+ if (unlikely(CHECK_FLAG(rmap_debug, DEBUG_ROUTEMAP_DETAIL)))
zlog_debug(
"%s: Access-List Specified: %s does not exist defaulting to NO_MATCH",
__func__, (char *)rule);
@@ -964,7 +970,7 @@ route_match_mac_address(void *rule, const struct prefix *prefix, void *object)
return RMAP_NOMATCH;
}
if (prefix->u.prefix_evpn.route_type != BGP_EVPN_MAC_IP_ROUTE) {
- if (CHECK_FLAG(rmap_debug, DEBUG_ROUTEMAP_DETAIL))
+ if (unlikely(CHECK_FLAG(rmap_debug, DEBUG_ROUTEMAP_DETAIL)))
zlog_debug(
"%s: Prefix %pFX is not a EVPN MAC IP ROUTE defaulting to NO_MATCH",
__func__, prefix);
@@ -3242,7 +3248,8 @@ route_match_ipv6_address(void *rule, const struct prefix *prefix, void *object)
if (prefix->family == AF_INET6) {
alist = access_list_lookup(AFI_IP6, (char *)rule);
if (alist == NULL) {
- if (CHECK_FLAG(rmap_debug, DEBUG_ROUTEMAP_DETAIL))
+ if (unlikely(CHECK_FLAG(rmap_debug,
+ DEBUG_ROUTEMAP_DETAIL)))
zlog_debug(
"%s: Access-List Specified: %s does not exist defaulting to NO_MATCH",
__func__, (char *)rule);
@@ -3299,7 +3306,8 @@ route_match_ipv6_next_hop(void *rule, const struct prefix *prefix, void *object)
alist = access_list_lookup(AFI_IP6, (char *)rule);
if (!alist) {
- if (CHECK_FLAG(rmap_debug, DEBUG_ROUTEMAP_DETAIL))
+ if (unlikely(CHECK_FLAG(rmap_debug,
+ DEBUG_ROUTEMAP_DETAIL)))
zlog_debug(
"%s: Access-List Specified: %s does not exist defaulting to NO_MATCH",
__func__, (char *)rule);
@@ -4266,8 +4274,8 @@ static void bgp_route_map_process_update(struct bgp *bgp, const char *rmap_name,
inet_ntop(bn_p->family,
&bn_p->u.prefix, buf,
sizeof(buf)));
- bgp_aggregate_route(bgp, bn_p, afi, safi,
- aggregate);
+ (void)bgp_aggregate_route(bgp, bn_p, afi, safi,
+ aggregate);
}
}
}
@@ -4344,7 +4352,7 @@ static void bgp_route_map_process_update_cb(char *rmap_name)
vpn_policy_routemap_event(rmap_name);
}
-void bgp_route_map_update_timer(struct thread *thread)
+void bgp_route_map_update_timer(struct event *thread)
{
route_map_walk_update_list(bgp_route_map_process_update_cb);
}
@@ -4357,13 +4365,12 @@ static void bgp_route_map_mark_update(const char *rmap_name)
/* If new update is received before the current timer timed out,
* turn it off and start a new timer.
*/
- THREAD_OFF(bm->t_rmap_update);
+ EVENT_OFF(bm->t_rmap_update);
/* rmap_update_timer of 0 means don't do route updates */
if (bm->rmap_update_timer) {
- thread_add_timer(bm->master, bgp_route_map_update_timer,
- NULL, bm->rmap_update_timer,
- &bm->t_rmap_update);
+ event_add_timer(bm->master, bgp_route_map_update_timer, NULL,
+ bm->rmap_update_timer, &bm->t_rmap_update);
/* Signal the groups that a route-map update event has
* started */
@@ -5512,7 +5519,7 @@ DEFUN_YANG (set_ip_nexthop_unchanged,
DEFUN_YANG (set_distance,
set_distance_cmd,
- "set distance (0-255)",
+ "set distance (1-255)",
SET_STR
"BGP Administrative Distance to use\n"
"Distance value\n")
@@ -5531,7 +5538,7 @@ DEFUN_YANG (set_distance,
DEFUN_YANG (no_set_distance,
no_set_distance_cmd,
- "no set distance [(0-255)]",
+ "no set distance [(1-255)]",
NO_STR SET_STR
"BGP Administrative Distance to use\n"
"Distance value\n")
diff --git a/bgpd/bgp_routemap_nb_config.c b/bgpd/bgp_routemap_nb_config.c
index 142bded6c5..4db8dba2cc 100644
--- a/bgpd/bgp_routemap_nb_config.c
+++ b/bgpd/bgp_routemap_nb_config.c
@@ -2628,8 +2628,18 @@ int
lib_route_map_entry_set_action_rmap_set_action_aggregator_aggregator_asn_modify(
struct nb_cb_modify_args *args)
{
+ const char *asn;
+ enum match_type match;
+
switch (args->event) {
case NB_EV_VALIDATE:
+ asn = yang_dnode_get_string(args->dnode, NULL);
+ if (!asn)
+ return NB_ERR_VALIDATION;
+ match = asn_str2asn_match(asn);
+ if (match == exact_match)
+ return NB_OK;
+ return NB_ERR_VALIDATION;
case NB_EV_PREPARE:
case NB_EV_ABORT:
case NB_EV_APPLY:
diff --git a/bgpd/bgp_rpki.c b/bgpd/bgp_rpki.c
index 32ca909fe6..c6e3131e02 100644
--- a/bgpd/bgp_rpki.c
+++ b/bgpd/bgp_rpki.c
@@ -23,7 +23,7 @@
#include "command.h"
#include "linklist.h"
#include "memory.h"
-#include "thread.h"
+#include "frrevent.h"
#include "filter.h"
#include "bgpd/bgpd.h"
#include "bgpd/bgp_table.h"
@@ -36,7 +36,6 @@
#include "northbound_cli.h"
#include "lib/network.h"
-#include "lib/thread.h"
#include "rtrlib/rtrlib.h"
#include "hook.h"
#include "libfrr.h"
@@ -54,7 +53,7 @@ DEFINE_MTYPE_STATIC(BGPD, BGP_RPKI_REVALIDATE, "BGP RPKI Revalidation");
#define RETRY_INTERVAL_DEFAULT 600
#define BGP_RPKI_CACHE_SERVER_SYNC_RETRY_TIMEOUT 3
-static struct thread *t_rpki_sync;
+static struct event *t_rpki_sync;
#define RPKI_DEBUG(...) \
if (rpki_debug) { \
@@ -382,9 +381,9 @@ struct rpki_revalidate_prefix {
safi_t safi;
};
-static void rpki_revalidate_prefix(struct thread *thread)
+static void rpki_revalidate_prefix(struct event *thread)
{
- struct rpki_revalidate_prefix *rrp = THREAD_ARG(thread);
+ struct rpki_revalidate_prefix *rrp = EVENT_ARG(thread);
struct bgp_dest *match, *node;
match = bgp_table_subtree_lookup(rrp->bgp->rib[rrp->afi][rrp->safi],
@@ -403,15 +402,15 @@ static void rpki_revalidate_prefix(struct thread *thread)
XFREE(MTYPE_BGP_RPKI_REVALIDATE, rrp);
}
-static void bgpd_sync_callback(struct thread *thread)
+static void bgpd_sync_callback(struct event *thread)
{
struct bgp *bgp;
struct listnode *node;
struct prefix prefix;
struct pfx_record rec;
- thread_add_read(bm->master, bgpd_sync_callback, NULL,
- rpki_sync_socket_bgpd, NULL);
+ event_add_read(bm->master, bgpd_sync_callback, NULL,
+ rpki_sync_socket_bgpd, NULL);
if (atomic_load_explicit(&rtr_update_overflow, memory_order_seq_cst)) {
while (read(rpki_sync_socket_bgpd, &rec,
@@ -449,8 +448,8 @@ static void bgpd_sync_callback(struct thread *thread)
rrp->prefix = prefix;
rrp->afi = afi;
rrp->safi = safi;
- thread_add_event(bm->master, rpki_revalidate_prefix,
- rrp, 0, &bgp->t_revalidate[afi][safi]);
+ event_add_event(bm->master, rpki_revalidate_prefix, rrp,
+ 0, &bgp->t_revalidate[afi][safi]);
}
}
}
@@ -490,9 +489,9 @@ struct rpki_revalidate_peer {
struct peer *peer;
};
-static void bgp_rpki_revalidate_peer(struct thread *thread)
+static void bgp_rpki_revalidate_peer(struct event *thread)
{
- struct rpki_revalidate_peer *rvp = THREAD_ARG(thread);
+ struct rpki_revalidate_peer *rvp = EVENT_ARG(thread);
/*
* Here's the expensive bit of gnomish deviousness
@@ -530,7 +529,7 @@ static void revalidate_all_routes(void)
rvp->afi = afi;
rvp->safi = safi;
- thread_add_event(
+ event_add_event(
bm->master, bgp_rpki_revalidate_peer,
rvp, 0,
&peer->t_revalidate_all[afi][safi]);
@@ -581,8 +580,8 @@ static void rpki_init_sync_socket(void)
}
- thread_add_read(bm->master, bgpd_sync_callback, NULL,
- rpki_sync_socket_bgpd, NULL);
+ event_add_read(bm->master, bgpd_sync_callback, NULL,
+ rpki_sync_socket_bgpd, NULL);
return;
@@ -592,7 +591,7 @@ err:
}
-static int bgp_rpki_init(struct thread_master *master)
+static int bgp_rpki_init(struct event_loop *master)
{
rpki_debug = false;
rtr_is_running = false;
@@ -632,13 +631,13 @@ static int bgp_rpki_module_init(void)
return 0;
}
-static void sync_expired(struct thread *thread)
+static void sync_expired(struct event *thread)
{
if (!rtr_mgr_conf_in_sync(rtr_config)) {
RPKI_DEBUG("rtr_mgr is not synced, retrying.");
- thread_add_timer(bm->master, sync_expired, NULL,
- BGP_RPKI_CACHE_SERVER_SYNC_RETRY_TIMEOUT,
- &t_rpki_sync);
+ event_add_timer(bm->master, sync_expired, NULL,
+ BGP_RPKI_CACHE_SERVER_SYNC_RETRY_TIMEOUT,
+ &t_rpki_sync);
return;
}
@@ -681,7 +680,7 @@ static int start(void)
return ERROR;
}
- thread_add_timer(bm->master, sync_expired, NULL, 0, &t_rpki_sync);
+ event_add_timer(bm->master, sync_expired, NULL, 0, &t_rpki_sync);
XFREE(MTYPE_BGP_RPKI_CACHE_GROUP, groups);
@@ -694,7 +693,7 @@ static void stop(void)
{
rtr_is_stopping = true;
if (is_running()) {
- THREAD_OFF(t_rpki_sync);
+ EVENT_OFF(t_rpki_sync);
rtr_mgr_stop(rtr_config);
rtr_mgr_free(rtr_config);
rtr_is_running = false;
diff --git a/bgpd/bgp_snmp.c b/bgpd/bgp_snmp.c
index 5aa5e14288..ce9442c1e0 100644
--- a/bgpd/bgp_snmp.c
+++ b/bgpd/bgp_snmp.c
@@ -12,7 +12,7 @@
#include "log.h"
#include "prefix.h"
#include "command.h"
-#include "thread.h"
+#include "frrevent.h"
#include "smux.h"
#include "filter.h"
#include "hook.h"
@@ -30,7 +30,7 @@
#include "bgpd/bgp_snmp_bgp4v2.h"
#include "bgpd/bgp_mplsvpn_snmp.h"
-static int bgp_snmp_init(struct thread_master *tm)
+static int bgp_snmp_init(struct event_loop *tm)
{
smux_init(tm);
bgp_snmp_bgp4_init(tm);
diff --git a/bgpd/bgp_snmp_bgp4.c b/bgpd/bgp_snmp_bgp4.c
index 186c9e2846..123d33bd14 100644
--- a/bgpd/bgp_snmp_bgp4.c
+++ b/bgpd/bgp_snmp_bgp4.c
@@ -12,7 +12,7 @@
#include "log.h"
#include "prefix.h"
#include "command.h"
-#include "thread.h"
+#include "frrevent.h"
#include "smux.h"
#include "filter.h"
#include "hook.h"
@@ -791,7 +791,7 @@ int bgpTrapBackwardTransition(struct peer *peer)
return 0;
}
-int bgp_snmp_bgp4_init(struct thread_master *tm)
+int bgp_snmp_bgp4_init(struct event_loop *tm)
{
REGISTER_MIB("mibII/bgp", bgp_variables, variable, bgp_oid);
return 0;
diff --git a/bgpd/bgp_snmp_bgp4.h b/bgpd/bgp_snmp_bgp4.h
index dffbf5fecf..ccf00d6b7c 100644
--- a/bgpd/bgp_snmp_bgp4.h
+++ b/bgpd/bgp_snmp_bgp4.h
@@ -71,6 +71,6 @@
extern int bgpTrapEstablished(struct peer *peer);
extern int bgpTrapBackwardTransition(struct peer *peer);
-extern int bgp_snmp_bgp4_init(struct thread_master *tm);
+extern int bgp_snmp_bgp4_init(struct event_loop *tm);
#endif /* _FRR_BGP_SNMP_BGP4_H_ */
diff --git a/bgpd/bgp_snmp_bgp4v2.c b/bgpd/bgp_snmp_bgp4v2.c
index 9c2599d5f4..712b5d4af8 100644
--- a/bgpd/bgp_snmp_bgp4v2.c
+++ b/bgpd/bgp_snmp_bgp4v2.c
@@ -13,7 +13,7 @@
#include "log.h"
#include "prefix.h"
#include "command.h"
-#include "thread.h"
+#include "frrevent.h"
#include "smux.h"
#include "filter.h"
#include "hook.h"
@@ -1394,7 +1394,7 @@ static struct variable bgpv2_variables[] = {
{1, 9, 1, BGP4V2_NLRI_PATH_ATTR_UNKNOWN, 2, 16}},
};
-int bgp_snmp_bgp4v2_init(struct thread_master *tm)
+int bgp_snmp_bgp4v2_init(struct event_loop *tm)
{
REGISTER_MIB("mibII/bgpv2", bgpv2_variables, variable, bgpv2_oid);
return 0;
diff --git a/bgpd/bgp_snmp_bgp4v2.h b/bgpd/bgp_snmp_bgp4v2.h
index 67f45a6173..7cdad586bc 100644
--- a/bgpd/bgp_snmp_bgp4v2.h
+++ b/bgpd/bgp_snmp_bgp4v2.h
@@ -81,6 +81,6 @@
#define BGP4V2_ESTABLISHED_NOTIFICATION 1
#define BGP4V2_BACKWARD_TRANSITION_NOTIFICATION 2
-extern int bgp_snmp_bgp4v2_init(struct thread_master *tm);
+extern int bgp_snmp_bgp4v2_init(struct event_loop *tm);
#endif /* _FRR_BGP_SNMP_BGP4V2_H_ */
diff --git a/bgpd/bgp_table.h b/bgpd/bgp_table.h
index 997efee9f3..9027af5ba3 100644
--- a/bgpd/bgp_table.h
+++ b/bgpd/bgp_table.h
@@ -29,7 +29,7 @@ struct bgp_table {
/* soft_reconfig_table in progress */
bool soft_reconfig_init;
- struct thread *soft_reconfig_thread;
+ struct event *soft_reconfig_thread;
/* list of peers on which soft_reconfig_table has to run */
struct list *soft_reconfig_peers;
diff --git a/bgpd/bgp_updgrp.c b/bgpd/bgp_updgrp.c
index 277492157f..72dca9f702 100644
--- a/bgpd/bgp_updgrp.c
+++ b/bgpd/bgp_updgrp.c
@@ -12,7 +12,7 @@
#include <zebra.h>
#include "prefix.h"
-#include "thread.h"
+#include "frrevent.h"
#include "buffer.h"
#include "stream.h"
#include "command.h"
@@ -101,12 +101,9 @@ static void sync_init(struct update_subgroup *subgrp,
static void sync_delete(struct update_subgroup *subgrp)
{
XFREE(MTYPE_BGP_SYNCHRONISE, subgrp->sync);
- if (subgrp->hash) {
- hash_clean(subgrp->hash,
- (void (*)(void *))bgp_advertise_attr_free);
- hash_free(subgrp->hash);
- }
- subgrp->hash = NULL;
+ hash_clean_and_free(&subgrp->hash,
+ (void (*)(void *))bgp_advertise_attr_free);
+
if (subgrp->work)
stream_free(subgrp->work);
subgrp->work = NULL;
@@ -322,6 +319,11 @@ static unsigned int updgrp_hash_key_make(const void *p)
afi_t afi;
safi_t safi;
+ /*
+ * IF YOU ADD AN ADDITION TO THE HASH KEY TO ENSURE
+ * THAT THE UPDATE GROUP CALCULATION IS CORRECT THEN
+ * PLEASE ADD IT TO THE DEBUG OUTPUT TOO AT THE BOTTOM
+ */
#define SEED1 999331
#define SEED2 2147483647
@@ -436,6 +438,10 @@ static unsigned int updgrp_hash_key_make(const void *p)
key = jhash_1word(jhash(soo_str, strlen(soo_str), SEED1), key);
}
+ /*
+ * ANY NEW ITEMS THAT ARE ADDED TO THE key, ENSURE DEBUG
+ * STATEMENT STAYS UP TO DATE
+ */
if (bgp_debug_neighbor_events(peer)) {
zlog_debug(
"%pBP Update Group Hash: sort: %d UpdGrpFlags: %ju UpdGrpAFFlags: %ju",
@@ -457,7 +463,7 @@ static unsigned int updgrp_hash_key_make(const void *p)
ROUTE_MAP_OUT_NAME(filter) ? ROUTE_MAP_OUT_NAME(filter)
: "(NONE)");
zlog_debug(
- "%pBP Update Group Hash: dlist out: %s plist out: %s aslist out: %s usmap out: %s advmap: %s",
+ "%pBP Update Group Hash: dlist out: %s plist out: %s aslist out: %s usmap out: %s advmap: %s %d",
peer,
DISTRIBUTE_OUT_NAME(filter)
? DISTRIBUTE_OUT_NAME(filter)
@@ -472,7 +478,8 @@ static unsigned int updgrp_hash_key_make(const void *p)
? UNSUPPRESS_MAP_NAME(filter)
: "(NONE)",
ADVERTISE_MAP_NAME(filter) ? ADVERTISE_MAP_NAME(filter)
- : "(NONE)");
+ : "(NONE)",
+ filter->advmap.update_type);
zlog_debug(
"%pBP Update Group Hash: default rmap: %s shared network and afi active network: %d",
peer,
@@ -490,6 +497,13 @@ static unsigned int updgrp_hash_key_make(const void *p)
PEER_CAP_ORF_PREFIX_SM_OLD_RCV),
(intmax_t)CHECK_FLAG(peer->af_flags[afi][safi],
PEER_FLAG_MAX_PREFIX_OUT));
+ zlog_debug(
+ "%pBP Update Group Hash: local role: %u AIGP: %d SOO: %s",
+ peer, peer->local_role,
+ !!CHECK_FLAG(peer->flags, PEER_FLAG_AIGP),
+ peer->soo[afi][safi]
+ ? ecommunity_str(peer->soo[afi][safi])
+ : "(NONE)");
zlog_debug("%pBP Update Group Hash key: %u", peer, key);
}
return key;
@@ -1085,8 +1099,8 @@ static void update_subgroup_delete(struct update_subgroup *subgrp)
if (subgrp->update_group)
UPDGRP_INCR_STAT(subgrp->update_group, subgrps_deleted);
- THREAD_OFF(subgrp->t_merge_check);
- THREAD_OFF(subgrp->t_coalesce);
+ EVENT_OFF(subgrp->t_merge_check);
+ EVENT_OFF(subgrp->t_coalesce);
bpacket_queue_cleanup(SUBGRP_PKTQ(subgrp));
subgroup_clear_table(subgrp);
@@ -1404,11 +1418,11 @@ bool update_subgroup_check_merge(struct update_subgroup *subgrp,
/*
* update_subgroup_merge_check_thread_cb
*/
-static void update_subgroup_merge_check_thread_cb(struct thread *thread)
+static void update_subgroup_merge_check_thread_cb(struct event *thread)
{
struct update_subgroup *subgrp;
- subgrp = THREAD_ARG(thread);
+ subgrp = EVENT_ARG(thread);
subgrp->t_merge_check = NULL;
@@ -1435,8 +1449,8 @@ bool update_subgroup_trigger_merge_check(struct update_subgroup *subgrp,
return false;
subgrp->t_merge_check = NULL;
- thread_add_timer_msec(bm->master, update_subgroup_merge_check_thread_cb,
- subgrp, 0, &subgrp->t_merge_check);
+ event_add_timer_msec(bm->master, update_subgroup_merge_check_thread_cb,
+ subgrp, 0, &subgrp->t_merge_check);
SUBGRP_INCR_STAT(subgrp, merge_checks_triggered);
@@ -2093,15 +2107,15 @@ update_group_default_originate_route_map_walkcb(struct update_group *updgrp,
return UPDWALK_CONTINUE;
}
-void update_group_refresh_default_originate_route_map(struct thread *thread)
+void update_group_refresh_default_originate_route_map(struct event *thread)
{
struct bgp *bgp;
char reason[] = "refresh default-originate route-map";
- bgp = THREAD_ARG(thread);
+ bgp = EVENT_ARG(thread);
update_group_walk(bgp, update_group_default_originate_route_map_walkcb,
reason);
- THREAD_OFF(bgp->t_rmap_def_originate_eval);
+ EVENT_OFF(bgp->t_rmap_def_originate_eval);
bgp_unlock(bgp);
}
@@ -2201,7 +2215,7 @@ void subgroup_trigger_write(struct update_subgroup *subgrp)
*/
SUBGRP_FOREACH_PEER (subgrp, paf)
if (peer_established(paf->peer))
- thread_add_timer_msec(
+ event_add_timer_msec(
bm->master, bgp_generate_updgrp_packets,
paf->peer, 0,
&paf->peer->t_generate_updgrp_packets);
diff --git a/bgpd/bgp_updgrp.h b/bgpd/bgp_updgrp.h
index 2b2fadcdf4..67c384ba02 100644
--- a/bgpd/bgp_updgrp.h
+++ b/bgpd/bgp_updgrp.h
@@ -197,10 +197,10 @@ struct update_subgroup {
/* announcement attribute hash */
struct hash *hash;
- struct thread *t_coalesce;
+ struct event *t_coalesce;
uint32_t v_coalesce;
- struct thread *t_merge_check;
+ struct event *t_merge_check;
/* table version that the subgroup has caught up to. */
uint64_t version;
@@ -373,7 +373,7 @@ extern void update_group_af_walk(struct bgp *bgp, afi_t afi, safi_t safi,
extern void update_group_walk(struct bgp *bgp, updgrp_walkcb cb, void *ctx);
extern void update_group_periodic_merge(struct bgp *bgp);
extern void
-update_group_refresh_default_originate_route_map(struct thread *thread);
+update_group_refresh_default_originate_route_map(struct event *thread);
extern void update_group_start_advtimer(struct bgp *bgp);
extern void update_subgroup_inherit_info(struct update_subgroup *to,
diff --git a/bgpd/bgp_updgrp_adv.c b/bgpd/bgp_updgrp_adv.c
index d6eb3ff20b..e4bc0176d1 100644
--- a/bgpd/bgp_updgrp_adv.c
+++ b/bgpd/bgp_updgrp_adv.c
@@ -17,7 +17,7 @@
#include "memory.h"
#include "prefix.h"
#include "hash.h"
-#include "thread.h"
+#include "frrevent.h"
#include "queue.h"
#include "routemap.h"
#include "filter.h"
@@ -298,12 +298,12 @@ static void updgrp_show_adj(struct bgp *bgp, afi_t afi, safi_t safi,
update_group_af_walk(bgp, afi, safi, updgrp_show_adj_walkcb, &ctx);
}
-static void subgroup_coalesce_timer(struct thread *thread)
+static void subgroup_coalesce_timer(struct event *thread)
{
struct update_subgroup *subgrp;
struct bgp *bgp;
- subgrp = THREAD_ARG(thread);
+ subgrp = EVENT_ARG(thread);
if (bgp_debug_update(NULL, NULL, subgrp->update_group, 0))
zlog_debug("u%" PRIu64 ":s%" PRIu64" announcing routes upon coalesce timer expiry(%u ms)",
(SUBGRP_UPDGRP(subgrp))->id, subgrp->id,
@@ -329,7 +329,7 @@ static void subgroup_coalesce_timer(struct thread *thread)
SUBGRP_FOREACH_PEER (subgrp, paf) {
peer = PAF_PEER(paf);
- THREAD_OFF(peer->t_routeadv);
+ EVENT_OFF(peer->t_routeadv);
BGP_TIMER_ON(peer->t_routeadv, bgp_routeadv_timer, 0);
}
}
@@ -497,6 +497,23 @@ void bgp_adj_out_set_subgroup(struct bgp_dest *dest,
zlog_debug("%s suppress UPDATE w/ attr: %s", peer->host,
attr_str);
}
+
+ /*
+ * If BGP is skipping sending this value to it's peers
+ * the version number should be updated just like it
+ * would if it sent the data. Why? Because update
+ * groups will not be coalesced until such time that
+ * the version numbers are the same.
+ *
+ * Imagine a scenario with say 2 peers and they come
+ * up and are placed in the same update group. Then
+ * a new peer comes up a bit later. Then a prefix is
+ * flapped that we decide for the first 2 peers are
+ * mapped to and we decide not to send the data to
+ * it. Then unless more network changes happen we
+ * will never be able to coalesce the 3rd peer down
+ */
+ subgrp->version = MAX(subgrp->version, dest->version);
return;
}
@@ -901,8 +918,8 @@ void subgroup_default_originate(struct update_subgroup *subgrp, int withdraw)
memset(&p, 0, sizeof(p));
p.family = afi2family(afi);
p.prefixlen = 0;
- dest = bgp_afi_node_lookup(bgp->rib[afi][safi_rib], afi, safi_rib, &p,
- NULL);
+ dest = bgp_safi_node_lookup(bgp->rib[afi][safi_rib], safi_rib, &p,
+ NULL);
if (withdraw) {
/* Withdraw the default route advertised using default
@@ -1004,9 +1021,9 @@ void subgroup_announce_all(struct update_subgroup *subgrp)
* We should wait for the coalesce timer. Arm the timer if not done.
*/
if (!subgrp->t_coalesce) {
- thread_add_timer_msec(bm->master, subgroup_coalesce_timer,
- subgrp, subgrp->v_coalesce,
- &subgrp->t_coalesce);
+ event_add_timer_msec(bm->master, subgroup_coalesce_timer,
+ subgrp, subgrp->v_coalesce,
+ &subgrp->t_coalesce);
}
}
diff --git a/bgpd/bgp_updgrp_packet.c b/bgpd/bgp_updgrp_packet.c
index 5106dcf354..e04d5ae245 100644
--- a/bgpd/bgp_updgrp_packet.c
+++ b/bgpd/bgp_updgrp_packet.c
@@ -12,7 +12,7 @@
#include <zebra.h>
#include "prefix.h"
-#include "thread.h"
+#include "frrevent.h"
#include "buffer.h"
#include "stream.h"
#include "command.h"
diff --git a/bgpd/bgp_vty.c b/bgpd/bgp_vty.c
index a1e9a9a8a9..de781d6b1e 100644
--- a/bgpd/bgp_vty.c
+++ b/bgpd/bgp_vty.c
@@ -16,7 +16,7 @@
#include "buffer.h"
#include "linklist.h"
#include "stream.h"
-#include "thread.h"
+#include "frrevent.h"
#include "log.h"
#include "memory.h"
#include "lib_vty.h"
@@ -1675,28 +1675,46 @@ DEFUN (no_router_bgp,
for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, tmp_bgp)) {
if (tmp_bgp->inst_type != BGP_INSTANCE_TYPE_VRF)
continue;
- if (CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
- BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT) ||
- CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
- BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT) ||
- CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
- BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT) ||
- CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
- BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT) ||
- CHECK_FLAG(tmp_bgp->af_flags[AFI_IP][SAFI_UNICAST],
+ if (CHECK_FLAG(
+ tmp_bgp->af_flags[AFI_IP]
+ [SAFI_UNICAST],
+ BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT) ||
+ CHECK_FLAG(
+ tmp_bgp->af_flags[AFI_IP6]
+ [SAFI_UNICAST],
+ BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT) ||
+ CHECK_FLAG(
+ tmp_bgp->af_flags[AFI_IP]
+ [SAFI_UNICAST],
+ BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT) ||
+ CHECK_FLAG(
+ tmp_bgp->af_flags[AFI_IP6]
+ [SAFI_UNICAST],
+ BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT) ||
+ CHECK_FLAG(tmp_bgp->af_flags[AFI_IP]
+ [SAFI_UNICAST],
BGP_CONFIG_VRF_TO_VRF_EXPORT) ||
- CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6][SAFI_UNICAST],
+ CHECK_FLAG(tmp_bgp->af_flags[AFI_IP6]
+ [SAFI_UNICAST],
BGP_CONFIG_VRF_TO_VRF_EXPORT) ||
(bgp == bgp_get_evpn() &&
- (CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
- BGP_L2VPN_EVPN_ADV_IPV4_UNICAST) ||
- CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
- BGP_L2VPN_EVPN_ADV_IPV4_UNICAST_GW_IP) ||
- CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
- BGP_L2VPN_EVPN_ADV_IPV6_UNICAST) ||
- CHECK_FLAG(tmp_bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
- BGP_L2VPN_EVPN_ADV_IPV6_UNICAST_GW_IP))) ||
- (hashcount(tmp_bgp->vnihash))) {
+ (CHECK_FLAG(
+ tmp_bgp->af_flags[AFI_L2VPN]
+ [SAFI_EVPN],
+ BGP_L2VPN_EVPN_ADV_IPV4_UNICAST) ||
+ CHECK_FLAG(
+ tmp_bgp->af_flags[AFI_L2VPN]
+ [SAFI_EVPN],
+ BGP_L2VPN_EVPN_ADV_IPV4_UNICAST_GW_IP) ||
+ CHECK_FLAG(
+ tmp_bgp->af_flags[AFI_L2VPN]
+ [SAFI_EVPN],
+ BGP_L2VPN_EVPN_ADV_IPV6_UNICAST) ||
+ CHECK_FLAG(
+ tmp_bgp->af_flags[AFI_L2VPN]
+ [SAFI_EVPN],
+ BGP_L2VPN_EVPN_ADV_IPV6_UNICAST_GW_IP))) ||
+ (tmp_bgp->l3vni)) {
vty_out(vty,
"%% Cannot delete default BGP instance. Dependent VRF instances exist\n");
return CMD_WARNING_CONFIG_FAILED;
@@ -2194,7 +2212,7 @@ DEFUN (no_bgp_maxmed_onstartup,
/* Cancel max-med onstartup if its on */
if (bgp->t_maxmed_onstartup) {
- THREAD_OFF(bgp->t_maxmed_onstartup);
+ EVENT_OFF(bgp->t_maxmed_onstartup);
bgp->maxmed_onstartup_over = 1;
}
@@ -2802,6 +2820,21 @@ DEFUN(no_bgp_ebgp_requires_policy, no_bgp_ebgp_requires_policy_cmd,
return CMD_SUCCESS;
}
+DEFPY(bgp_lu_uses_explicit_null, bgp_lu_uses_explicit_null_cmd,
+ "[no] bgp labeled-unicast explicit-null",
+ NO_STR BGP_STR
+ "BGP Labeled-unicast options\n"
+ "Use explicit-null label values for local prefixes\n")
+{
+ VTY_DECLVAR_CONTEXT(bgp, bgp);
+
+ if (no)
+ UNSET_FLAG(bgp->flags, BGP_FLAG_LU_EXPLICIT_NULL);
+ else
+ SET_FLAG(bgp->flags, BGP_FLAG_LU_EXPLICIT_NULL);
+ return CMD_SUCCESS;
+}
+
DEFUN(bgp_suppress_duplicates, bgp_suppress_duplicates_cmd,
"bgp suppress-duplicates",
BGP_STR
@@ -7518,9 +7551,9 @@ DEFUN (bgp_set_route_map_delay_timer,
* fired.
*/
if (!rmap_delay_timer && bm->t_rmap_update) {
- THREAD_OFF(bm->t_rmap_update);
- thread_execute(bm->master, bgp_route_map_update_timer,
- NULL, 0);
+ EVENT_OFF(bm->t_rmap_update);
+ event_execute(bm->master, bgp_route_map_update_timer,
+ NULL, 0);
}
return CMD_SUCCESS;
} else {
@@ -11036,10 +11069,10 @@ static char *bgp_peer_description_stripped(char *desc, uint32_t size)
{
static char stripped[BUFSIZ];
uint32_t i = 0;
- uint32_t last_space = 0;
+ uint32_t last_space = size;
while (i < size) {
- if (*(desc + i) == 0) {
+ if (*(desc + i) == '\0') {
stripped[i] = '\0';
return stripped;
}
@@ -11049,10 +11082,7 @@ static char *bgp_peer_description_stripped(char *desc, uint32_t size)
i++;
}
- if (last_space > size)
- stripped[size + 1] = '\0';
- else
- stripped[last_space] = '\0';
+ stripped[last_space] = '\0';
return stripped;
}
@@ -11676,37 +11706,22 @@ static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
vty_out(vty, "4 ");
vty_out(vty, ASN_FORMAT_SPACE(bgp->asnotation),
&peer->as);
- if (show_wide) {
+ if (show_wide)
vty_out(vty,
ASN_FORMAT_SPACE(
bgp->asnotation),
peer->change_local_as
? &peer->change_local_as
: &peer->local_as);
- vty_out(vty,
- " %9u %9u %8" PRIu64
- " %4zu %4zu %8s",
- PEER_TOTAL_RX(peer),
- PEER_TOTAL_TX(peer),
- peer->version[afi][safi],
- inq_count, outq_count,
- peer_uptime(peer->uptime,
- timebuf,
- BGP_UPTIME_LEN, 0,
- NULL));
- } else {
- vty_out(vty,
- " %9u %9u %8" PRIu64
- " %4zu %4zu %8s",
- PEER_TOTAL_RX(peer),
- PEER_TOTAL_TX(peer),
- peer->version[afi][safi],
- inq_count, outq_count,
- peer_uptime(peer->uptime,
- timebuf,
- BGP_UPTIME_LEN, 0,
- NULL));
- }
+ vty_out(vty,
+ " %9u %9u %8" PRIu64 " %4zu %4zu %8s",
+ PEER_TOTAL_RX(peer),
+ PEER_TOTAL_TX(peer),
+ peer->version[afi][safi], inq_count,
+ outq_count,
+ peer_uptime(peer->uptime, timebuf,
+ BGP_UPTIME_LEN, 0, NULL));
+
if (peer_established(peer)) {
if (peer->afc_recv[afi][safi]) {
if (CHECK_FLAG(
@@ -12345,7 +12360,7 @@ static void bgp_show_neighbor_graceful_restart_capability_per_afi_safi(
if (peer->t_gr_stale != NULL) {
json_object_int_add(json_timer,
"stalePathTimerRemaining",
- thread_timer_remain_second(
+ event_timer_remain_second(
peer->t_gr_stale));
}
@@ -12366,7 +12381,7 @@ static void bgp_show_neighbor_graceful_restart_capability_per_afi_safi(
json_object_int_add(
json_timer,
"selectionDeferralTimerRemaining",
- thread_timer_remain_second(
+ event_timer_remain_second(
peer->bgp->gr_info[afi][safi]
.t_select_deferral));
}
@@ -12379,7 +12394,7 @@ static void bgp_show_neighbor_graceful_restart_capability_per_afi_safi(
if (peer->t_gr_stale != NULL)
vty_out(vty,
" Stale Path Remaining(sec): %ld\n",
- thread_timer_remain_second(
+ event_timer_remain_second(
peer->t_gr_stale));
/* Display Configured Selection
* Deferral only when when
@@ -12394,7 +12409,7 @@ static void bgp_show_neighbor_graceful_restart_capability_per_afi_safi(
NULL)
vty_out(vty,
" Selection Deferral Time Remaining(sec): %ld\n",
- thread_timer_remain_second(
+ event_timer_remain_second(
peer->bgp->gr_info[afi][safi]
.t_select_deferral));
}
@@ -12428,7 +12443,7 @@ static void bgp_show_neighbor_graceful_restart_time(struct vty *vty,
if (p->t_gr_restart != NULL)
json_object_int_add(
json_timer, "restartTimerRemaining",
- thread_timer_remain_second(p->t_gr_restart));
+ event_timer_remain_second(p->t_gr_restart));
json_object_object_add(json, "timers", json_timer);
} else {
@@ -12441,10 +12456,10 @@ static void bgp_show_neighbor_graceful_restart_time(struct vty *vty,
p->v_gr_restart);
if (p->t_gr_restart != NULL)
vty_out(vty, " Restart Time Remaining(sec): %ld\n",
- thread_timer_remain_second(p->t_gr_restart));
+ event_timer_remain_second(p->t_gr_restart));
if (p->t_gr_restart != NULL) {
vty_out(vty, " Restart Time Remaining(sec): %ld\n",
- thread_timer_remain_second(p->t_gr_restart));
+ event_timer_remain_second(p->t_gr_restart));
}
}
}
@@ -13475,11 +13490,11 @@ static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
json_neigh,
"bgpTimerConfiguredConditionalAdvertisementsSec",
bgp->condition_check_period);
- if (thread_is_scheduled(bgp->t_condition_check))
+ if (event_is_scheduled(bgp->t_condition_check))
json_object_int_add(
json_neigh,
"bgpTimerUntilConditionalAdvertisementsSec",
- thread_timer_remain_second(
+ event_timer_remain_second(
bgp->t_condition_check));
} else {
/* Administrative shutdown. */
@@ -13556,10 +13571,10 @@ static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
vty_out(vty,
" Configured conditional advertisements interval is %d seconds\n",
bgp->condition_check_period);
- if (thread_is_scheduled(bgp->t_condition_check))
+ if (event_is_scheduled(bgp->t_condition_check))
vty_out(vty,
" Time until conditional advertisements begin is %lu seconds\n",
- thread_timer_remain_second(
+ event_timer_remain_second(
bgp->t_condition_check));
}
/* Capability. */
@@ -14496,13 +14511,13 @@ static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
if (p->t_gr_restart)
json_object_int_add(
json_grace, "gracefulRestartTimerMsecs",
- thread_timer_remain_second(p->t_gr_restart) *
+ event_timer_remain_second(p->t_gr_restart) *
1000);
if (p->t_gr_stale)
json_object_int_add(
json_grace, "gracefulStalepathTimerMsecs",
- thread_timer_remain_second(p->t_gr_stale) *
+ event_timer_remain_second(p->t_gr_stale) *
1000);
/* more gr info in new format */
BGP_SHOW_PEER_GR_CAPABILITY(vty, p, json_grace);
@@ -14543,12 +14558,12 @@ static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
if (p->t_gr_restart)
vty_out(vty,
" The remaining time of restart timer is %ld\n",
- thread_timer_remain_second(p->t_gr_restart));
+ event_timer_remain_second(p->t_gr_restart));
if (p->t_gr_stale)
vty_out(vty,
" The remaining time of stalepath timer is %ld\n",
- thread_timer_remain_second(p->t_gr_stale));
+ event_timer_remain_second(p->t_gr_stale));
/* more gr info in new format */
BGP_SHOW_PEER_GR_CAPABILITY(vty, p, NULL);
@@ -14782,14 +14797,15 @@ static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
json_neigh, "reducePrefixNumFrom");
json_object_int_add(json_neigh,
"restartInTimerMsec",
- thread_timer_remain_second(
- p->t_pmax_restart)
- * 1000);
+ event_timer_remain_second(
+ p->t_pmax_restart) *
+ 1000);
} else
vty_out(vty,
" Reduce the no. of prefix from %s, will restart in %ld seconds\n",
- p->host, thread_timer_remain_second(
- p->t_pmax_restart));
+ p->host,
+ event_timer_remain_second(
+ p->t_pmax_restart));
} else {
if (use_json)
json_object_boolean_true_add(
@@ -14941,19 +14957,18 @@ static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
if (p->t_start)
json_object_int_add(
json_neigh, "nextStartTimerDueInMsecs",
- thread_timer_remain_second(p->t_start) * 1000);
+ event_timer_remain_second(p->t_start) * 1000);
if (p->t_connect)
json_object_int_add(
json_neigh, "nextConnectTimerDueInMsecs",
- thread_timer_remain_second(p->t_connect)
- * 1000);
+ event_timer_remain_second(p->t_connect) * 1000);
if (p->t_routeadv) {
json_object_int_add(json_neigh, "mraiInterval",
p->v_routeadv);
json_object_int_add(
json_neigh, "mraiTimerExpireInMsecs",
- thread_timer_remain_second(p->t_routeadv)
- * 1000);
+ event_timer_remain_second(p->t_routeadv) *
+ 1000);
}
if (p->password)
json_object_int_add(json_neigh, "authenticationEnabled",
@@ -14982,15 +14997,15 @@ static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
}
if (p->t_start)
vty_out(vty, "Next start timer due in %ld seconds\n",
- thread_timer_remain_second(p->t_start));
+ event_timer_remain_second(p->t_start));
if (p->t_connect)
vty_out(vty, "Next connect timer due in %ld seconds\n",
- thread_timer_remain_second(p->t_connect));
+ event_timer_remain_second(p->t_connect));
if (p->t_routeadv)
vty_out(vty,
"MRAI (interval %u) timer expires in %ld seconds\n",
p->v_routeadv,
- thread_timer_remain_second(p->t_routeadv));
+ event_timer_remain_second(p->t_routeadv));
if (p->password)
vty_out(vty, "Peer Authentication Enabled\n");
@@ -18235,6 +18250,9 @@ int bgp_config_write(struct vty *vty)
? ""
: "no ");
+ if (!!CHECK_FLAG(bgp->flags, BGP_FLAG_LU_EXPLICIT_NULL))
+ vty_out(vty, " bgp labeled-unicast explicit-null\n");
+
/* draft-ietf-idr-deprecate-as-set-confed-set */
if (bgp->reject_as_sets)
vty_out(vty, " bgp reject-as-sets\n");
@@ -18779,14 +18797,14 @@ static const struct cmd_variable_handler bgp_var_peergroup[] = {
DEFINE_HOOK(bgp_config_end, (struct bgp *bgp), (bgp));
-static struct thread *t_bgp_cfg;
+static struct event *t_bgp_cfg;
bool bgp_config_inprocess(void)
{
- return thread_is_scheduled(t_bgp_cfg);
+ return event_is_scheduled(t_bgp_cfg);
}
-static void bgp_config_finish(struct thread *t)
+static void bgp_config_finish(struct event *t)
{
struct listnode *node;
struct bgp *bgp;
@@ -18798,9 +18816,9 @@ static void bgp_config_finish(struct thread *t)
static void bgp_config_start(void)
{
#define BGP_PRE_CONFIG_MAX_WAIT_SECONDS 600
- THREAD_OFF(t_bgp_cfg);
- thread_add_timer(bm->master, bgp_config_finish, NULL,
- BGP_PRE_CONFIG_MAX_WAIT_SECONDS, &t_bgp_cfg);
+ EVENT_OFF(t_bgp_cfg);
+ event_add_timer(bm->master, bgp_config_finish, NULL,
+ BGP_PRE_CONFIG_MAX_WAIT_SECONDS, &t_bgp_cfg);
}
/* When we receive a hook the configuration is read,
@@ -18812,8 +18830,8 @@ static void bgp_config_end(void)
{
#define BGP_POST_CONFIG_DELAY_SECONDS 1
uint32_t bgp_post_config_delay =
- thread_is_scheduled(bm->t_rmap_update)
- ? thread_timer_remain_second(bm->t_rmap_update)
+ event_is_scheduled(bm->t_rmap_update)
+ ? event_timer_remain_second(bm->t_rmap_update)
: BGP_POST_CONFIG_DELAY_SECONDS;
/* If BGP config processing thread isn't running, then
@@ -18822,13 +18840,13 @@ static void bgp_config_end(void)
if (!bgp_config_inprocess())
return;
- THREAD_OFF(t_bgp_cfg);
+ EVENT_OFF(t_bgp_cfg);
/* Start a new timer to make sure we don't send EoR
* before route-maps are processed.
*/
- thread_add_timer(bm->master, bgp_config_finish, NULL,
- bgp_post_config_delay, &t_bgp_cfg);
+ event_add_timer(bm->master, bgp_config_finish, NULL,
+ bgp_post_config_delay, &t_bgp_cfg);
}
static int config_write_interface_one(struct vty *vty, struct vrf *vrf)
@@ -19154,6 +19172,9 @@ void bgp_vty_init(void)
install_element(BGP_NODE, &bgp_ebgp_requires_policy_cmd);
install_element(BGP_NODE, &no_bgp_ebgp_requires_policy_cmd);
+ /* bgp labeled-unicast explicit-null */
+ install_element(BGP_NODE, &bgp_lu_uses_explicit_null_cmd);
+
/* bgp suppress-duplicates */
install_element(BGP_NODE, &bgp_suppress_duplicates_cmd);
install_element(BGP_NODE, &no_bgp_suppress_duplicates_cmd);
diff --git a/bgpd/bgp_zebra.c b/bgpd/bgp_zebra.c
index d05768da05..96b1f3e00f 100644
--- a/bgpd/bgp_zebra.c
+++ b/bgpd/bgp_zebra.c
@@ -13,7 +13,7 @@
#include "sockunion.h"
#include "zclient.h"
#include "routemap.h"
-#include "thread.h"
+#include "frrevent.h"
#include "queue.h"
#include "memory.h"
#include "lib/json.h"
@@ -834,6 +834,13 @@ bool bgp_zebra_nexthop_set(union sockunion *local, union sockunion *remote,
peer->bgp->vrf_id);
}
+ /* Handle peerings via loopbacks. For instance, peer between
+ * 127.0.0.1 and 127.0.0.2. In short, allow peering with self
+ * via 127.0.0.0/8.
+ */
+ if (!ifp && cmd_allow_reserved_ranges_get())
+ ifp = if_get_vrf_loopback(peer->bgp->vrf_id);
+
if (!ifp) {
/*
* BGP views do not currently get proper data
@@ -1046,19 +1053,19 @@ static bool bgp_table_map_apply(struct route_map *map, const struct prefix *p,
return false;
}
-static struct thread *bgp_tm_thread_connect;
+static struct event *bgp_tm_thread_connect;
static bool bgp_tm_status_connected;
static bool bgp_tm_chunk_obtained;
#define BGP_FLOWSPEC_TABLE_CHUNK 100000
static uint32_t bgp_tm_min, bgp_tm_max, bgp_tm_chunk_size;
struct bgp *bgp_tm_bgp;
-static void bgp_zebra_tm_connect(struct thread *t)
+static void bgp_zebra_tm_connect(struct event *t)
{
struct zclient *zclient;
int delay = 10, ret = 0;
- zclient = THREAD_ARG(t);
+ zclient = EVENT_ARG(t);
if (bgp_tm_status_connected && zclient->sock > 0)
delay = 60;
else {
@@ -1082,8 +1089,8 @@ static void bgp_zebra_tm_connect(struct thread *t)
}
}
}
- thread_add_timer(bm->master, bgp_zebra_tm_connect, zclient, delay,
- &bgp_tm_thread_connect);
+ event_add_timer(bm->master, bgp_zebra_tm_connect, zclient, delay,
+ &bgp_tm_thread_connect);
}
bool bgp_zebra_tm_chunk_obtained(void)
@@ -1113,8 +1120,8 @@ void bgp_zebra_init_tm_connect(struct bgp *bgp)
bgp_tm_min = bgp_tm_max = 0;
bgp_tm_chunk_size = BGP_FLOWSPEC_TABLE_CHUNK;
bgp_tm_bgp = bgp;
- thread_add_timer(bm->master, bgp_zebra_tm_connect, zclient, delay,
- &bgp_tm_thread_connect);
+ event_add_timer(bm->master, bgp_zebra_tm_connect, zclient, delay,
+ &bgp_tm_thread_connect);
}
int bgp_zebra_get_table_range(uint32_t chunk_size,
@@ -1309,6 +1316,14 @@ void bgp_zebra_announce(struct bgp_dest *dest, const struct prefix *p,
uint32_t bos = 0;
uint32_t exp = 0;
+ /*
+ * BGP is installing this route and bgp has been configured
+ * to suppress announcements until the route has been installed
+ * let's set the fact that we expect this route to be installed
+ */
+ if (BGP_SUPPRESS_FIB_ENABLED(bgp))
+ SET_FLAG(dest->flags, BGP_NODE_FIB_INSTALL_PENDING);
+
/* Don't try to install if we're not connected to Zebra or Zebra doesn't
* know of this instance.
*/
@@ -1760,6 +1775,12 @@ void bgp_zebra_withdraw(const struct prefix *p, struct bgp_path_info *info,
struct zapi_route api;
struct peer *peer;
+ /*
+ * If we are withdrawing the route, we don't need to have this
+ * flag set. So unset it.
+ */
+ UNSET_FLAG(info->net->flags, BGP_NODE_FIB_INSTALL_PENDING);
+
/* Don't try to install if we're not connected to Zebra or Zebra doesn't
* know of this instance.
*/
@@ -2596,8 +2617,8 @@ static int bgp_zebra_route_notify_owner(int command, struct zclient *zclient,
}
/* Find the bgp route node */
- dest = bgp_afi_node_lookup(bgp->rib[afi][safi], afi, safi, &p,
- &bgp->vrf_prd);
+ dest = bgp_safi_node_lookup(bgp->rib[afi][safi], safi, &p,
+ &bgp->vrf_prd);
if (!dest)
return -1;
@@ -3443,7 +3464,7 @@ void bgp_if_init(void)
hook_register_prio(if_del, 0, bgp_if_delete_hook);
}
-void bgp_zebra_init(struct thread_master *master, unsigned short instance)
+void bgp_zebra_init(struct event_loop *master, unsigned short instance)
{
zclient_num_connects = 0;
@@ -3748,16 +3769,22 @@ int bgp_zebra_send_capabilities(struct bgp *bgp, bool disable)
struct zapi_cap api;
int ret = BGP_GR_SUCCESS;
+ if (BGP_DEBUG(zebra, ZEBRA))
+ zlog_debug("%s: Sending %sable for %s", __func__,
+ disable ? "dis" : "en", bgp->name_pretty);
+
if (zclient == NULL) {
if (BGP_DEBUG(zebra, ZEBRA))
- zlog_debug("zclient invalid");
+ zlog_debug("%s: %s zclient invalid", __func__,
+ bgp->name_pretty);
return BGP_GR_FAILURE;
}
/* Check if the client is connected */
if ((zclient->sock < 0) || (zclient->t_connect)) {
if (BGP_DEBUG(zebra, ZEBRA))
- zlog_debug("client not connected");
+ zlog_debug("%s: %s client not connected", __func__,
+ bgp->name_pretty);
return BGP_GR_FAILURE;
}
@@ -3776,7 +3803,8 @@ int bgp_zebra_send_capabilities(struct bgp *bgp, bool disable)
if (zclient_capabilities_send(ZEBRA_CLIENT_CAPABILITIES, zclient, &api)
== ZCLIENT_SEND_FAILURE) {
- zlog_err("error sending capability");
+ zlog_err("%s: %s error sending capability", __func__,
+ bgp->name_pretty);
ret = BGP_GR_FAILURE;
} else {
if (disable)
@@ -3785,7 +3813,8 @@ int bgp_zebra_send_capabilities(struct bgp *bgp, bool disable)
bgp->present_zebra_gr_state = ZEBRA_GR_ENABLE;
if (BGP_DEBUG(zebra, ZEBRA))
- zlog_debug("send capabilty success");
+ zlog_debug("%s: %s send capabilty success", __func__,
+ bgp->name_pretty);
ret = BGP_GR_SUCCESS;
}
return ret;
@@ -3794,32 +3823,41 @@ int bgp_zebra_send_capabilities(struct bgp *bgp, bool disable)
/* Send route update pesding or completed status to RIB for the
* specific AFI, SAFI
*/
-int bgp_zebra_update(afi_t afi, safi_t safi, vrf_id_t vrf_id, int type)
+int bgp_zebra_update(struct bgp *bgp, afi_t afi, safi_t safi,
+ enum zserv_client_capabilities type)
{
struct zapi_cap api = {0};
+ if (BGP_DEBUG(zebra, ZEBRA))
+ zlog_debug("%s: %s afi: %u safi: %u Command %s", __func__,
+ bgp->name_pretty, afi, safi,
+ zserv_gr_client_cap_string(type));
+
if (zclient == NULL) {
if (BGP_DEBUG(zebra, ZEBRA))
- zlog_debug("zclient == NULL, invalid");
+ zlog_debug("%s: %s zclient == NULL, invalid", __func__,
+ bgp->name_pretty);
return BGP_GR_FAILURE;
}
/* Check if the client is connected */
if ((zclient->sock < 0) || (zclient->t_connect)) {
if (BGP_DEBUG(zebra, ZEBRA))
- zlog_debug("client not connected");
+ zlog_debug("%s: %s client not connected", __func__,
+ bgp->name_pretty);
return BGP_GR_FAILURE;
}
api.afi = afi;
api.safi = safi;
- api.vrf_id = vrf_id;
+ api.vrf_id = bgp->vrf_id;
api.cap = type;
if (zclient_capabilities_send(ZEBRA_CLIENT_CAPABILITIES, zclient, &api)
== ZCLIENT_SEND_FAILURE) {
if (BGP_DEBUG(zebra, ZEBRA))
- zlog_debug("error sending capability");
+ zlog_debug("%s: %s error sending capability", __func__,
+ bgp->name_pretty);
return BGP_GR_FAILURE;
}
return BGP_GR_SUCCESS;
@@ -3831,6 +3869,10 @@ int bgp_zebra_stale_timer_update(struct bgp *bgp)
{
struct zapi_cap api;
+ if (BGP_DEBUG(zebra, ZEBRA))
+ zlog_debug("%s: %s Timer Update to %u", __func__,
+ bgp->name_pretty, bgp->rib_stale_time);
+
if (zclient == NULL) {
if (BGP_DEBUG(zebra, ZEBRA))
zlog_debug("zclient invalid");
@@ -3840,7 +3882,8 @@ int bgp_zebra_stale_timer_update(struct bgp *bgp)
/* Check if the client is connected */
if ((zclient->sock < 0) || (zclient->t_connect)) {
if (BGP_DEBUG(zebra, ZEBRA))
- zlog_debug("client not connected");
+ zlog_debug("%s: %s client not connected", __func__,
+ bgp->name_pretty);
return BGP_GR_FAILURE;
}
@@ -3851,11 +3894,11 @@ int bgp_zebra_stale_timer_update(struct bgp *bgp)
if (zclient_capabilities_send(ZEBRA_CLIENT_CAPABILITIES, zclient, &api)
== ZCLIENT_SEND_FAILURE) {
if (BGP_DEBUG(zebra, ZEBRA))
- zlog_debug("error sending capability");
+ zlog_debug("%s: %s error sending capability", __func__,
+ bgp->name_pretty);
return BGP_GR_FAILURE;
}
- if (BGP_DEBUG(zebra, ZEBRA))
- zlog_debug("send capabilty success");
+
return BGP_GR_SUCCESS;
}
diff --git a/bgpd/bgp_zebra.h b/bgpd/bgp_zebra.h
index 8a0203c32d..b09be890e5 100644
--- a/bgpd/bgp_zebra.h
+++ b/bgpd/bgp_zebra.h
@@ -18,8 +18,7 @@
/* Default weight for next hop, if doing weighted ECMP. */
#define BGP_ZEBRA_DEFAULT_NHOP_WEIGHT 1
-extern void bgp_zebra_init(struct thread_master *master,
- unsigned short instance);
+extern void bgp_zebra_init(struct event_loop *master, unsigned short instance);
extern void bgp_if_init(void);
extern void bgp_zebra_init_tm_connect(struct bgp *bgp);
extern uint32_t bgp_zebra_tm_get_id(void);
@@ -114,7 +113,8 @@ extern void bgp_send_pbr_iptable(struct bgp_pbr_action *pba,
extern void bgp_zebra_announce_default(struct bgp *bgp, struct nexthop *nh,
afi_t afi, uint32_t table_id, bool announce);
extern int bgp_zebra_send_capabilities(struct bgp *bgp, bool disable);
-extern int bgp_zebra_update(afi_t afi, safi_t safi, vrf_id_t vrf_id, int type);
+extern int bgp_zebra_update(struct bgp *bgp, afi_t afi, safi_t safi,
+ enum zserv_client_capabilities);
extern int bgp_zebra_stale_timer_update(struct bgp *bgp);
extern int bgp_zebra_srv6_manager_get_locator_chunk(const char *name);
extern int bgp_zebra_srv6_manager_release_locator_chunk(const char *name);
diff --git a/bgpd/bgpd.c b/bgpd/bgpd.c
index 96c6a111ce..9d7a1f967e 100644
--- a/bgpd/bgpd.c
+++ b/bgpd/bgpd.c
@@ -6,7 +6,7 @@
#include <zebra.h>
#include "prefix.h"
-#include "thread.h"
+#include "frrevent.h"
#include "buffer.h"
#include "stream.h"
#include "ringbuf.h"
@@ -1126,9 +1126,9 @@ static void peer_free(struct peer *peer)
bgp_timer_set(peer);
bgp_reads_off(peer);
bgp_writes_off(peer);
- thread_cancel_event_ready(bm->master, peer);
+ event_cancel_event_ready(bm->master, peer);
FOREACH_AFI_SAFI (afi, safi)
- THREAD_OFF(peer->t_revalidate_all[afi][safi]);
+ EVENT_OFF(peer->t_revalidate_all[afi][safi]);
assert(!peer->t_write);
assert(!peer->t_read);
BGP_EVENT_FLUSH(peer);
@@ -1496,9 +1496,11 @@ void peer_xfer_config(struct peer *peer_dst, struct peer *peer_src)
peer_dst->v_delayopen = peer_src->v_delayopen;
/* password apply */
- if (peer_src->password && !peer_dst->password)
+ if (peer_src->password) {
+ XFREE(MTYPE_PEER_PASSWORD, peer_dst->password);
peer_dst->password =
XSTRDUP(MTYPE_PEER_PASSWORD, peer_src->password);
+ }
FOREACH_AFI_SAFI (afi, safi) {
peer_dst->afc[afi][safi] = peer_src->afc[afi][safi];
@@ -2467,16 +2469,16 @@ void peer_nsf_stop(struct peer *peer)
FOREACH_AFI_SAFI_NSF (afi, safi) {
peer->nsf[afi][safi] = 0;
- THREAD_OFF(peer->t_llgr_stale[afi][safi]);
+ EVENT_OFF(peer->t_llgr_stale[afi][safi]);
}
if (peer->t_gr_restart) {
- THREAD_OFF(peer->t_gr_restart);
+ EVENT_OFF(peer->t_gr_restart);
if (bgp_debug_neighbor_events(peer))
zlog_debug("%pBP graceful restart timer stopped", peer);
}
if (peer->t_gr_stale) {
- THREAD_OFF(peer->t_gr_stale);
+ EVENT_OFF(peer->t_gr_stale);
if (bgp_debug_neighbor_events(peer))
zlog_debug(
"%pBP graceful restart stalepath timer stopped",
@@ -2516,9 +2518,9 @@ int peer_delete(struct peer *peer)
bgp_keepalives_off(peer);
bgp_reads_off(peer);
bgp_writes_off(peer);
- thread_cancel_event_ready(bm->master, peer);
+ event_cancel_event_ready(bm->master, peer);
FOREACH_AFI_SAFI (afi, safi)
- THREAD_OFF(peer->t_revalidate_all[afi][safi]);
+ EVENT_OFF(peer->t_revalidate_all[afi][safi]);
assert(!CHECK_FLAG(peer->thread_flags, PEER_THREAD_WRITES_ON));
assert(!CHECK_FLAG(peer->thread_flags, PEER_THREAD_READS_ON));
assert(!CHECK_FLAG(peer->thread_flags, PEER_THREAD_KEEPALIVES_ON));
@@ -3197,11 +3199,11 @@ int peer_group_bind(struct bgp *bgp, union sockunion *su, struct peer *peer,
return 0;
}
-static void bgp_startup_timer_expire(struct thread *thread)
+static void bgp_startup_timer_expire(struct event *thread)
{
struct bgp *bgp;
- bgp = THREAD_ARG(thread);
+ bgp = EVENT_ARG(thread);
bgp->t_startup = NULL;
}
@@ -3355,8 +3357,8 @@ static struct bgp *bgp_create(as_t *as, const char *name,
if (name)
bgp->name = XSTRDUP(MTYPE_BGP, name);
- thread_add_timer(bm->master, bgp_startup_timer_expire, bgp,
- bgp->restart_time, &bgp->t_startup);
+ event_add_timer(bm->master, bgp_startup_timer_expire, bgp,
+ bgp->restart_time, &bgp->t_startup);
/* printable name we can use in debug messages */
if (inst_type == BGP_INSTANCE_TYPE_DEFAULT) {
@@ -3696,7 +3698,7 @@ void bgp_instance_down(struct bgp *bgp)
/* Stop timers. */
if (bgp->t_rmap_def_originate_eval) {
- THREAD_OFF(bgp->t_rmap_def_originate_eval);
+ EVENT_OFF(bgp->t_rmap_def_originate_eval);
bgp_unlock(bgp); /* TODO - This timer is started with a lock -
why? */
}
@@ -3748,39 +3750,39 @@ int bgp_delete(struct bgp *bgp)
hook_call(bgp_inst_delete, bgp);
FOREACH_AFI_SAFI (afi, safi)
- THREAD_OFF(bgp->t_revalidate[afi][safi]);
+ EVENT_OFF(bgp->t_revalidate[afi][safi]);
- THREAD_OFF(bgp->t_condition_check);
- THREAD_OFF(bgp->t_startup);
- THREAD_OFF(bgp->t_maxmed_onstartup);
- THREAD_OFF(bgp->t_update_delay);
- THREAD_OFF(bgp->t_establish_wait);
+ EVENT_OFF(bgp->t_condition_check);
+ EVENT_OFF(bgp->t_startup);
+ EVENT_OFF(bgp->t_maxmed_onstartup);
+ EVENT_OFF(bgp->t_update_delay);
+ EVENT_OFF(bgp->t_establish_wait);
/* Set flag indicating bgp instance delete in progress */
SET_FLAG(bgp->flags, BGP_FLAG_DELETE_IN_PROGRESS);
/* Delete the graceful restart info */
FOREACH_AFI_SAFI (afi, safi) {
- struct thread *t;
+ struct event *t;
gr_info = &bgp->gr_info[afi][safi];
if (!gr_info)
continue;
t = gr_info->t_select_deferral;
if (t) {
- void *info = THREAD_ARG(t);
+ void *info = EVENT_ARG(t);
XFREE(MTYPE_TMP, info);
}
- THREAD_OFF(gr_info->t_select_deferral);
+ EVENT_OFF(gr_info->t_select_deferral);
t = gr_info->t_route_select;
if (t) {
- void *info = THREAD_ARG(t);
+ void *info = EVENT_ARG(t);
XFREE(MTYPE_TMP, info);
}
- THREAD_OFF(gr_info->t_route_select);
+ EVENT_OFF(gr_info->t_route_select);
}
if (BGP_DEBUG(zebra, ZEBRA)) {
@@ -3803,7 +3805,7 @@ int bgp_delete(struct bgp *bgp)
/* Stop timers. */
if (bgp->t_rmap_def_originate_eval) {
- THREAD_OFF(bgp->t_rmap_def_originate_eval);
+ EVENT_OFF(bgp->t_rmap_def_originate_eval);
bgp_unlock(bgp); /* TODO - This timer is started with a lock -
why? */
}
@@ -3842,6 +3844,23 @@ int bgp_delete(struct bgp *bgp)
#ifdef ENABLE_BGP_VNC
rfapi_delete(bgp);
#endif
+
+ /* Free memory allocated with aggregate address configuration. */
+ FOREACH_AFI_SAFI (afi, safi) {
+ struct bgp_aggregate *aggregate = NULL;
+
+ for (struct bgp_dest *dest =
+ bgp_table_top(bgp->aggregate[afi][safi]);
+ dest; dest = bgp_route_next(dest)) {
+ aggregate = bgp_dest_get_bgp_aggregate_info(dest);
+ if (aggregate == NULL)
+ continue;
+
+ bgp_dest_set_bgp_aggregate_info(dest, NULL);
+ bgp_free_aggregate_info(aggregate);
+ }
+ }
+
bgp_cleanup_routes(bgp);
for (afi = 0; afi < AFI_MAX; ++afi) {
@@ -3897,7 +3916,7 @@ int bgp_delete(struct bgp *bgp)
if (bgp->process_queue)
work_queue_free_and_null(&bgp->process_queue);
- thread_master_free_unused(bm->master);
+ event_master_free_unused(bm->master);
bgp_unlock(bgp); /* initial reference */
return 0;
@@ -4528,7 +4547,7 @@ static void peer_flag_modify_action(struct peer *peer, uint64_t flag)
UNSET_FLAG(peer->sflags, PEER_STATUS_PREFIX_OVERFLOW);
if (peer->t_pmax_restart) {
- THREAD_OFF(peer->t_pmax_restart);
+ EVENT_OFF(peer->t_pmax_restart);
if (bgp_debug_neighbor_events(peer))
zlog_debug(
"%pBP Maximum-prefix restart timer canceled",
@@ -5676,20 +5695,9 @@ void peer_on_policy_change(struct peer *peer, afi_t afi, safi_t safi,
return;
if (CHECK_FLAG(peer->cap, PEER_CAP_REFRESH_OLD_RCV) ||
- CHECK_FLAG(peer->cap, PEER_CAP_REFRESH_NEW_RCV)) {
- if (CHECK_FLAG(peer->af_cap[afi][safi],
- PEER_CAP_ORF_PREFIX_SM_ADV) &&
- (CHECK_FLAG(peer->af_cap[afi][safi],
- PEER_CAP_ORF_PREFIX_RM_RCV) ||
- CHECK_FLAG(peer->af_cap[afi][safi],
- PEER_CAP_ORF_PREFIX_RM_OLD_RCV)))
- peer_clear_soft(peer, afi, safi,
- BGP_CLEAR_SOFT_IN_ORF_PREFIX);
- else
- bgp_route_refresh_send(
- peer, afi, safi, 0, 0, 0,
- BGP_ROUTE_REFRESH_NORMAL);
- }
+ CHECK_FLAG(peer->cap, PEER_CAP_REFRESH_NEW_RCV))
+ bgp_route_refresh_send(peer, afi, safi, 0, 0, 0,
+ BGP_ROUTE_REFRESH_NORMAL);
}
}
@@ -6930,11 +6938,18 @@ static void peer_prefix_list_update(struct prefix_list *plist)
/* If we touch prefix-list, we need to process
* new updates. This is important for ORF to
- * work correctly as well.
+ * work correctly.
*/
- if (peer->afc_nego[afi][safi])
- peer_on_policy_change(peer, afi, safi,
- 0);
+ if (CHECK_FLAG(peer->af_cap[afi][safi],
+ PEER_CAP_ORF_PREFIX_SM_ADV) &&
+ (CHECK_FLAG(peer->af_cap[afi][safi],
+ PEER_CAP_ORF_PREFIX_RM_RCV) ||
+ CHECK_FLAG(
+ peer->af_cap[afi][safi],
+ PEER_CAP_ORF_PREFIX_RM_OLD_RCV)))
+ peer_clear_soft(
+ peer, afi, safi,
+ BGP_CLEAR_SOFT_IN_ORF_PREFIX);
}
}
for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) {
@@ -7398,7 +7413,7 @@ static bool peer_maximum_prefix_clear_overflow(struct peer *peer)
UNSET_FLAG(peer->sflags, PEER_STATUS_PREFIX_OVERFLOW);
if (peer->t_pmax_restart) {
- THREAD_OFF(peer->t_pmax_restart);
+ EVENT_OFF(peer->t_pmax_restart);
if (bgp_debug_neighbor_events(peer))
zlog_debug(
"%pBP Maximum-prefix restart timer cancelled",
@@ -8010,7 +8025,7 @@ char *peer_uptime(time_t uptime2, char *buf, size_t len, bool use_json,
return buf;
}
-void bgp_master_init(struct thread_master *master, const int buffer_size,
+void bgp_master_init(struct event_loop *master, const int buffer_size,
struct list *addresses)
{
qobj_init();
@@ -8276,7 +8291,7 @@ void bgp_terminate(void)
if (bm->listen_sockets)
list_delete(&bm->listen_sockets);
- THREAD_OFF(bm->t_rmap_update);
+ EVENT_OFF(bm->t_rmap_update);
bgp_mac_finish();
}
diff --git a/bgpd/bgpd.h b/bgpd/bgpd.h
index c0dd8d5ef4..b6491bf799 100644
--- a/bgpd/bgpd.h
+++ b/bgpd/bgpd.h
@@ -98,7 +98,7 @@ struct bgp_master {
struct list *bgp;
/* BGP thread master. */
- struct thread_master *master;
+ struct event_loop *master;
/* Listening sockets */
struct list *listen_sockets;
@@ -126,7 +126,7 @@ struct bgp_master {
uint64_t subgrp_idspace;
/* timer to dampen route map changes */
- struct thread *t_rmap_update; /* Handle route map updates */
+ struct event *t_rmap_update; /* Handle route map updates */
uint32_t rmap_update_timer; /* Route map update timer */
#define RMAP_DEFAULT_UPDATE_TIMER 5 /* disabled by default */
@@ -266,11 +266,11 @@ struct graceful_restart_info {
/* Count of EOR received */
uint32_t eor_received;
/* Deferral Timer */
- struct thread *t_select_deferral;
+ struct event *t_select_deferral;
/* Routes Deferred */
uint32_t gr_deferred;
/* Best route select */
- struct thread *t_route_select;
+ struct event *t_route_select;
/* AFI, SAFI enabled */
bool af_enabled[AFI_MAX][SAFI_MAX];
/* Route update completed */
@@ -406,15 +406,16 @@ struct bgp {
struct as_confed *confed_peers;
int confed_peers_cnt;
- struct thread
- *t_startup; /* start-up timer on only once at the beginning */
+ /* start-up timer on only once at the beginning */
+ struct event *t_startup;
uint32_t v_maxmed_onstartup; /* Duration of max-med on start-up */
#define BGP_MAXMED_ONSTARTUP_UNCONFIGURED 0 /* 0 means off, its the default */
uint32_t maxmed_onstartup_value; /* Max-med value when active on
start-up */
- struct thread
- *t_maxmed_onstartup; /* non-null when max-med onstartup is on */
+
+ /* non-null when max-med onstartup is on */
+ struct event *t_maxmed_onstartup;
uint8_t maxmed_onstartup_over; /* Flag to make it effective only once */
bool v_maxmed_admin; /* true/false if max-med administrative is on/off
@@ -428,9 +429,9 @@ struct bgp {
uint32_t maxmed_value; /* Max-med value when its active */
/* BGP update delay on startup */
- struct thread *t_update_delay;
- struct thread *t_establish_wait;
- struct thread *t_revalidate[AFI_MAX][SAFI_MAX];
+ struct event *t_update_delay;
+ struct event *t_establish_wait;
+ struct event *t_revalidate[AFI_MAX][SAFI_MAX];
uint8_t update_delay_over;
uint8_t main_zebra_update_hold;
@@ -499,6 +500,8 @@ struct bgp {
#define BGP_FLAG_HARD_ADMIN_RESET (1ULL << 31)
/* Evaluate the AIGP attribute during the best path selection process */
#define BGP_FLAG_COMPARE_AIGP (1ULL << 32)
+/* For BGP-LU, force local prefixes to use explicit-null label */
+#define BGP_FLAG_LU_EXPLICIT_NULL (1ULL << 33)
/* BGP default address-families.
* New peers inherit enabled afi/safis from bgp instance.
@@ -590,7 +593,7 @@ struct bgp {
struct hash *pbr_action_hash;
/* timer to re-evaluate neighbor default-originate route-maps */
- struct thread *t_rmap_def_originate_eval;
+ struct event *t_rmap_def_originate_eval;
#define RMAP_DEFAULT_ORIGINATE_EVAL_TIMER 5
/* BGP distance configuration. */
@@ -769,7 +772,7 @@ struct bgp {
/* BGP Conditional advertisement */
uint32_t condition_check_period;
uint32_t condition_filter_count;
- struct thread *t_condition_check;
+ struct event *t_condition_check;
/* BGP VPN SRv6 backend */
bool srv6_enabled;
@@ -978,7 +981,7 @@ struct peer_af {
/*
* Trigger timer for bgp_announce_route().
*/
- struct thread *t_announce_route;
+ struct event *t_announce_route;
afi_t afi;
safi_t safi;
@@ -1509,24 +1512,24 @@ struct peer {
_Atomic uint32_t v_gr_restart;
/* Threads. */
- struct thread *t_read;
- struct thread *t_write;
- struct thread *t_start;
- struct thread *t_connect_check_r;
- struct thread *t_connect_check_w;
- struct thread *t_connect;
- struct thread *t_holdtime;
- struct thread *t_routeadv;
- struct thread *t_delayopen;
- struct thread *t_pmax_restart;
- struct thread *t_gr_restart;
- struct thread *t_gr_stale;
- struct thread *t_llgr_stale[AFI_MAX][SAFI_MAX];
- struct thread *t_revalidate_all[AFI_MAX][SAFI_MAX];
- struct thread *t_generate_updgrp_packets;
- struct thread *t_process_packet;
- struct thread *t_process_packet_error;
- struct thread *t_refresh_stalepath;
+ struct event *t_read;
+ struct event *t_write;
+ struct event *t_start;
+ struct event *t_connect_check_r;
+ struct event *t_connect_check_w;
+ struct event *t_connect;
+ struct event *t_holdtime;
+ struct event *t_routeadv;
+ struct event *t_delayopen;
+ struct event *t_pmax_restart;
+ struct event *t_gr_restart;
+ struct event *t_gr_stale;
+ struct event *t_llgr_stale[AFI_MAX][SAFI_MAX];
+ struct event *t_revalidate_all[AFI_MAX][SAFI_MAX];
+ struct event *t_generate_updgrp_packets;
+ struct event *t_process_packet;
+ struct event *t_process_packet_error;
+ struct event *t_refresh_stalepath;
/* Thread flags. */
_Atomic uint32_t thread_flags;
@@ -2155,7 +2158,7 @@ extern char *peer_uptime(time_t uptime2, char *buf, size_t len, bool use_json,
extern int bgp_config_write(struct vty *);
-extern void bgp_master_init(struct thread_master *master, const int buffer_size,
+extern void bgp_master_init(struct event_loop *master, const int buffer_size,
struct list *addresses);
extern void bgp_init(unsigned short instance);
@@ -2363,7 +2366,7 @@ extern int peer_ttl_security_hops_unset(struct peer *);
extern void peer_tx_shutdown_message_set(struct peer *, const char *msg);
extern void peer_tx_shutdown_message_unset(struct peer *);
-extern void bgp_route_map_update_timer(struct thread *thread);
+extern void bgp_route_map_update_timer(struct event *thread);
extern const char *bgp_get_name_by_role(uint8_t role);
extern enum asnotation_mode bgp_get_asnotation(struct bgp *bgp);
diff --git a/bgpd/rfapi/rfapi.h b/bgpd/rfapi/rfapi.h
index 44f7507d55..3f61d5be19 100644
--- a/bgpd/rfapi/rfapi.h
+++ b/bgpd/rfapi/rfapi.h
@@ -335,8 +335,7 @@ struct rfapi_rfp_cfg {
* return value:
* rfp_start_val rfp returned value passed on rfp_stop and other rfapi calls
--------------------------------------------*/
-extern void *rfp_start(struct thread_master *master,
- struct rfapi_rfp_cfg **cfgp,
+extern void *rfp_start(struct event_loop *master, struct rfapi_rfp_cfg **cfgp,
struct rfapi_rfp_cb_methods **cbmp);
/*------------------------------------------
diff --git a/bgpd/rfapi/rfapi_backend.h b/bgpd/rfapi/rfapi_backend.h
index 3870c31fca..32ea0a2821 100644
--- a/bgpd/rfapi/rfapi_backend.h
+++ b/bgpd/rfapi/rfapi_backend.h
@@ -14,7 +14,7 @@
#include "bgpd/bgp_nexthop.h"
extern void rfapi_init(void);
-extern void vnc_zebra_init(struct thread_master *master);
+extern void vnc_zebra_init(struct event_loop *master);
extern void vnc_zebra_destroy(void);
extern void rfapi_delete(struct bgp *);
diff --git a/bgpd/rfapi/rfapi_import.c b/bgpd/rfapi/rfapi_import.c
index 5c68545398..4b8e07a9c4 100644
--- a/bgpd/rfapi/rfapi_import.c
+++ b/bgpd/rfapi/rfapi_import.c
@@ -15,7 +15,7 @@
#include "lib/memory.h"
#include "lib/log.h"
#include "lib/skiplist.h"
-#include "lib/thread.h"
+#include "frrevent.h"
#include "lib/stream.h"
#include "lib/lib_errors.h"
@@ -127,7 +127,6 @@ void rfapiCheckRouteCount(void)
struct agg_node *rn;
int holddown_count = 0;
- int local_count = 0;
int imported_count = 0;
int remote_count = 0;
@@ -146,9 +145,7 @@ void rfapiCheckRouteCount(void)
++holddown_count;
} else {
- if (RFAPI_LOCAL_BI(bpi)) {
- ++local_count;
- } else {
+ if (!RFAPI_LOCAL_BI(bpi)) {
if (RFAPI_DIRECT_IMPORT_BI(
bpi)) {
++imported_count;
@@ -848,10 +845,10 @@ static void rfapiBgpInfoChainFree(struct bgp_path_info *bpi)
if (CHECK_FLAG(bpi->flags, BGP_PATH_REMOVED)
&& bpi->extra->vnc.import.timer) {
struct rfapi_withdraw *wcb =
- THREAD_ARG(bpi->extra->vnc.import.timer);
+ EVENT_ARG(bpi->extra->vnc.import.timer);
XFREE(MTYPE_RFAPI_WITHDRAW, wcb);
- THREAD_OFF(bpi->extra->vnc.import.timer);
+ EVENT_OFF(bpi->extra->vnc.import.timer);
}
next = bpi->next;
@@ -874,33 +871,39 @@ static void rfapiImportTableFlush(struct rfapi_import_table *it)
for (afi = AFI_IP; afi < AFI_MAX; ++afi) {
struct agg_node *rn;
+ struct agg_table *at;
- for (rn = agg_route_top(it->imported_vpn[afi]); rn;
- rn = agg_route_next(rn)) {
- /*
- * Each route_node has:
- * aggregate: points to rfapi_it_extra with monitor
- * chain(s)
- * info: points to chain of bgp_path_info
- */
- /* free bgp_path_info and its children */
- rfapiBgpInfoChainFree(rn->info);
- rn->info = NULL;
+ at = it->imported_vpn[afi];
+ if (at) {
+ for (rn = agg_route_top(at); rn;
+ rn = agg_route_next(rn)) {
+ /*
+ * Each route_node has:
+ * aggregate: points to rfapi_it_extra with
+ * monitor chain(s)
+ * info: points to chain of bgp_path_info
+ */
+ /* free bgp_path_info and its children */
+ rfapiBgpInfoChainFree(rn->info);
+ rn->info = NULL;
- rfapiMonitorExtraFlush(SAFI_MPLS_VPN, rn);
+ rfapiMonitorExtraFlush(SAFI_MPLS_VPN, rn);
+ }
+ agg_table_finish(at);
}
- for (rn = agg_route_top(it->imported_encap[afi]); rn;
- rn = agg_route_next(rn)) {
- /* free bgp_path_info and its children */
- rfapiBgpInfoChainFree(rn->info);
- rn->info = NULL;
+ if (at) {
+ at = it->imported_encap[afi];
+ for (rn = agg_route_top(at); rn;
+ rn = agg_route_next(rn)) {
+ /* free bgp_path_info and its children */
+ rfapiBgpInfoChainFree(rn->info);
+ rn->info = NULL;
- rfapiMonitorExtraFlush(SAFI_ENCAP, rn);
+ rfapiMonitorExtraFlush(SAFI_ENCAP, rn);
+ }
+ agg_table_finish(at);
}
-
- agg_table_finish(it->imported_vpn[afi]);
- agg_table_finish(it->imported_encap[afi]);
}
if (it->monitor_exterior_orphans) {
skiplist_free(it->monitor_exterior_orphans);
@@ -2339,9 +2342,9 @@ static void rfapiMonitorEncapDelete(struct bgp_path_info *vpn_bpi)
/*
* Timer callback for withdraw
*/
-static void rfapiWithdrawTimerVPN(struct thread *t)
+static void rfapiWithdrawTimerVPN(struct event *t)
{
- struct rfapi_withdraw *wcb = THREAD_ARG(t);
+ struct rfapi_withdraw *wcb = EVENT_ARG(t);
struct bgp_path_info *bpi = wcb->info;
struct bgp *bgp = bgp_get_default();
const struct prefix *p;
@@ -2648,9 +2651,9 @@ rfapiWithdrawEncapUpdateCachedUn(struct rfapi_import_table *import_table,
return 0;
}
-static void rfapiWithdrawTimerEncap(struct thread *t)
+static void rfapiWithdrawTimerEncap(struct event *t)
{
- struct rfapi_withdraw *wcb = THREAD_ARG(t);
+ struct rfapi_withdraw *wcb = EVENT_ARG(t);
struct bgp_path_info *bpi = wcb->info;
int was_first_route = 0;
struct rfapi_monitor_encap *em;
@@ -2733,7 +2736,7 @@ static void
rfapiBiStartWithdrawTimer(struct rfapi_import_table *import_table,
struct agg_node *rn, struct bgp_path_info *bpi,
afi_t afi, safi_t safi,
- void (*timer_service_func)(struct thread *))
+ void (*timer_service_func)(struct event *))
{
uint32_t lifetime;
struct rfapi_withdraw *wcb;
@@ -2783,8 +2786,8 @@ rfapiBiStartWithdrawTimer(struct rfapi_import_table *import_table,
if (lifetime > UINT32_MAX / 1001) {
/* sub-optimal case, but will probably never happen */
bpi->extra->vnc.import.timer = NULL;
- thread_add_timer(bm->master, timer_service_func, wcb, lifetime,
- &bpi->extra->vnc.import.timer);
+ event_add_timer(bm->master, timer_service_func, wcb, lifetime,
+ &bpi->extra->vnc.import.timer);
} else {
static uint32_t jitter;
uint32_t lifetime_msec;
@@ -2799,9 +2802,9 @@ rfapiBiStartWithdrawTimer(struct rfapi_import_table *import_table,
lifetime_msec = (lifetime * 1000) + jitter;
bpi->extra->vnc.import.timer = NULL;
- thread_add_timer_msec(bm->master, timer_service_func, wcb,
- lifetime_msec,
- &bpi->extra->vnc.import.timer);
+ event_add_timer_msec(bm->master, timer_service_func, wcb,
+ lifetime_msec,
+ &bpi->extra->vnc.import.timer);
}
/* re-sort route list (BGP_PATH_REMOVED routes are last) */
@@ -2825,7 +2828,7 @@ static void rfapiExpireEncapNow(struct rfapi_import_table *it,
struct agg_node *rn, struct bgp_path_info *bpi)
{
struct rfapi_withdraw *wcb;
- struct thread t;
+ struct event t;
/*
* pretend we're an expiring timer
@@ -3070,12 +3073,11 @@ static void rfapiBgpInfoFilteredImportEncap(
*/
if (CHECK_FLAG(bpi->flags, BGP_PATH_REMOVED)
&& bpi->extra->vnc.import.timer) {
- struct rfapi_withdraw *wcb = THREAD_ARG(
+ struct rfapi_withdraw *wcb = EVENT_ARG(
bpi->extra->vnc.import.timer);
XFREE(MTYPE_RFAPI_WITHDRAW, wcb);
- THREAD_OFF(
- bpi->extra->vnc.import.timer);
+ EVENT_OFF(bpi->extra->vnc.import.timer);
}
if (action == FIF_ACTION_UPDATE) {
@@ -3088,7 +3090,7 @@ static void rfapiBgpInfoFilteredImportEncap(
* bpi
*/
struct rfapi_withdraw *wcb;
- struct thread t;
+ struct event t;
/*
* pretend we're an expiring timer
@@ -3163,10 +3165,10 @@ static void rfapiBgpInfoFilteredImportEncap(
__func__);
if (bpi->extra->vnc.import.timer) {
struct rfapi_withdraw *wcb =
- THREAD_ARG(bpi->extra->vnc.import.timer);
+ EVENT_ARG(bpi->extra->vnc.import.timer);
XFREE(MTYPE_RFAPI_WITHDRAW, wcb);
- THREAD_OFF(bpi->extra->vnc.import.timer);
+ EVENT_OFF(bpi->extra->vnc.import.timer);
}
rfapiExpireEncapNow(import_table, rn, bpi);
}
@@ -3299,7 +3301,7 @@ static void rfapiExpireVpnNow(struct rfapi_import_table *it,
int lockoffset)
{
struct rfapi_withdraw *wcb;
- struct thread t;
+ struct event t;
/*
* pretend we're an expiring timer
@@ -3523,12 +3525,11 @@ void rfapiBgpInfoFilteredImportVPN(
*/
if (CHECK_FLAG(bpi->flags, BGP_PATH_REMOVED)
&& bpi->extra->vnc.import.timer) {
- struct rfapi_withdraw *wcb = THREAD_ARG(
+ struct rfapi_withdraw *wcb = EVENT_ARG(
bpi->extra->vnc.import.timer);
XFREE(MTYPE_RFAPI_WITHDRAW, wcb);
- THREAD_OFF(
- bpi->extra->vnc.import.timer);
+ EVENT_OFF(bpi->extra->vnc.import.timer);
import_table->holddown_count[afi] -= 1;
RFAPI_UPDATE_ITABLE_COUNT(
@@ -3742,10 +3743,10 @@ void rfapiBgpInfoFilteredImportVPN(
__func__);
if (bpi->extra->vnc.import.timer) {
struct rfapi_withdraw *wcb =
- THREAD_ARG(bpi->extra->vnc.import.timer);
+ EVENT_ARG(bpi->extra->vnc.import.timer);
XFREE(MTYPE_RFAPI_WITHDRAW, wcb);
- THREAD_OFF(bpi->extra->vnc.import.timer);
+ EVENT_OFF(bpi->extra->vnc.import.timer);
}
rfapiExpireVpnNow(import_table, rn, bpi, 0);
}
@@ -4040,7 +4041,7 @@ static void rfapiProcessPeerDownRt(struct peer *peer,
struct agg_node *rn;
struct bgp_path_info *bpi;
struct agg_table *rt = NULL;
- void (*timer_service_func)(struct thread *) = NULL;
+ void (*timer_service_func)(struct event *) = NULL;
assert(afi == AFI_IP || afi == AFI_IP6);
@@ -4260,10 +4261,7 @@ void bgp_rfapi_destroy(struct bgp *bgp, struct rfapi *h)
h->resolve_nve_nexthop = NULL;
}
- agg_table_finish(h->it_ce->imported_vpn[AFI_IP]);
- agg_table_finish(h->it_ce->imported_vpn[AFI_IP6]);
- agg_table_finish(h->it_ce->imported_encap[AFI_IP]);
- agg_table_finish(h->it_ce->imported_encap[AFI_IP6]);
+ rfapiImportTableFlush(h->it_ce);
if (h->import_mac) {
struct rfapi_import_table *it;
@@ -4482,7 +4480,7 @@ static void rfapiDeleteRemotePrefixesIt(
continue;
if (bpi->extra->vnc.import.timer) {
struct rfapi_withdraw *wcb =
- THREAD_ARG(
+ EVENT_ARG(
bpi->extra->vnc
.import
.timer);
@@ -4495,9 +4493,8 @@ static void rfapiDeleteRemotePrefixesIt(
afi, 1);
XFREE(MTYPE_RFAPI_WITHDRAW,
wcb);
- THREAD_OFF(
- bpi->extra->vnc.import
- .timer);
+ EVENT_OFF(bpi->extra->vnc.import
+ .timer);
}
} else {
if (!delete_active)
diff --git a/bgpd/rfapi/rfapi_import.h b/bgpd/rfapi/rfapi_import.h
index 3bec225f65..dd06afe7e2 100644
--- a/bgpd/rfapi/rfapi_import.h
+++ b/bgpd/rfapi/rfapi_import.h
@@ -13,7 +13,7 @@
#ifndef QUAGGA_HGP_RFAPI_IMPORT_H
#define QUAGGA_HGP_RFAPI_IMPORT_H
-#include "lib/thread.h"
+#include "frrevent.h"
/*
* These are per-rt-import-list
diff --git a/bgpd/rfapi/rfapi_monitor.c b/bgpd/rfapi/rfapi_monitor.c
index f169a7808c..3fe957ba4d 100644
--- a/bgpd/rfapi/rfapi_monitor.c
+++ b/bgpd/rfapi/rfapi_monitor.c
@@ -619,7 +619,7 @@ void rfapiMonitorDel(struct bgp *bgp, struct rfapi_descriptor *rfd,
rfapiMonitorDetachImport(m);
}
- THREAD_OFF(m->timer);
+ EVENT_OFF(m->timer);
/*
* remove from rfd list
@@ -656,7 +656,7 @@ int rfapiMonitorDelHd(struct rfapi_descriptor *rfd)
rfapiMonitorDetachImport(m);
}
- THREAD_OFF(m->timer);
+ EVENT_OFF(m->timer);
XFREE(MTYPE_RFAPI_MONITOR, m);
rn->info = NULL;
@@ -690,7 +690,7 @@ int rfapiMonitorDelHd(struct rfapi_descriptor *rfd)
#endif
}
- THREAD_OFF(mon_eth->timer);
+ EVENT_OFF(mon_eth->timer);
/*
* remove from rfd list
@@ -730,9 +730,9 @@ void rfapiMonitorResponseRemovalOn(struct bgp *bgp)
bgp->rfapi_cfg->flags &= ~BGP_VNC_CONFIG_RESPONSE_REMOVAL_DISABLE;
}
-static void rfapiMonitorTimerExpire(struct thread *t)
+static void rfapiMonitorTimerExpire(struct event *t)
{
- struct rfapi_monitor_vpn *m = THREAD_ARG(t);
+ struct rfapi_monitor_vpn *m = EVENT_ARG(t);
/* forget reference to thread, it's gone */
m->timer = NULL;
@@ -743,7 +743,7 @@ static void rfapiMonitorTimerExpire(struct thread *t)
static void rfapiMonitorTimerRestart(struct rfapi_monitor_vpn *m)
{
- unsigned long remain = thread_timer_remain_second(m->timer);
+ unsigned long remain = event_timer_remain_second(m->timer);
/* unexpected case, but avoid wraparound problems below */
if (remain > m->rfd->response_lifetime)
@@ -753,7 +753,7 @@ static void rfapiMonitorTimerRestart(struct rfapi_monitor_vpn *m)
if (m->rfd->response_lifetime - remain < 2)
return;
- THREAD_OFF(m->timer);
+ EVENT_OFF(m->timer);
{
char buf[BUFSIZ];
@@ -764,8 +764,8 @@ static void rfapiMonitorTimerRestart(struct rfapi_monitor_vpn *m)
m->rfd->response_lifetime);
}
- thread_add_timer(bm->master, rfapiMonitorTimerExpire, m,
- m->rfd->response_lifetime, &m->timer);
+ event_add_timer(bm->master, rfapiMonitorTimerExpire, m,
+ m->rfd->response_lifetime, &m->timer);
}
/*
@@ -1036,9 +1036,9 @@ void rfapiMonitorMovedUp(struct rfapi_import_table *import_table,
}
}
-static void rfapiMonitorEthTimerExpire(struct thread *t)
+static void rfapiMonitorEthTimerExpire(struct event *t)
{
- struct rfapi_monitor_eth *m = THREAD_ARG(t);
+ struct rfapi_monitor_eth *m = EVENT_ARG(t);
/* forget reference to thread, it's gone */
m->timer = NULL;
@@ -1051,7 +1051,7 @@ static void rfapiMonitorEthTimerExpire(struct thread *t)
static void rfapiMonitorEthTimerRestart(struct rfapi_monitor_eth *m)
{
- unsigned long remain = thread_timer_remain_second(m->timer);
+ unsigned long remain = event_timer_remain_second(m->timer);
/* unexpected case, but avoid wraparound problems below */
if (remain > m->rfd->response_lifetime)
@@ -1061,7 +1061,7 @@ static void rfapiMonitorEthTimerRestart(struct rfapi_monitor_eth *m)
if (m->rfd->response_lifetime - remain < 2)
return;
- THREAD_OFF(m->timer);
+ EVENT_OFF(m->timer);
{
char buf[BUFSIZ];
@@ -1072,8 +1072,8 @@ static void rfapiMonitorEthTimerRestart(struct rfapi_monitor_eth *m)
m->rfd->response_lifetime);
}
- thread_add_timer(bm->master, rfapiMonitorEthTimerExpire, m,
- m->rfd->response_lifetime, &m->timer);
+ event_add_timer(bm->master, rfapiMonitorEthTimerExpire, m,
+ m->rfd->response_lifetime, &m->timer);
}
static int mon_eth_cmp(const void *a, const void *b)
@@ -1399,7 +1399,7 @@ void rfapiMonitorEthDel(struct bgp *bgp, struct rfapi_descriptor *rfd,
rfapiMonitorEthDetachImport(bgp, val);
}
- THREAD_OFF(val->timer);
+ EVENT_OFF(val->timer);
/*
* remove from rfd list
diff --git a/bgpd/rfapi/rfapi_monitor.h b/bgpd/rfapi/rfapi_monitor.h
index 68ba5a48d8..3200079b39 100644
--- a/bgpd/rfapi/rfapi_monitor.h
+++ b/bgpd/rfapi/rfapi_monitor.h
@@ -25,7 +25,7 @@ struct rfapi_monitor_vpn {
#define RFAPI_MON_FLAG_NEEDCALLBACK 0x00000001 /* deferred callback */
// int dcount; /* debugging counter */
- struct thread *timer;
+ struct event *timer;
};
struct rfapi_monitor_encap {
@@ -41,7 +41,7 @@ struct rfapi_monitor_eth {
struct rfapi_descriptor *rfd; /* which NVE requested the route */
struct ethaddr macaddr;
uint32_t logical_net_id;
- struct thread *timer;
+ struct event *timer;
};
/*
diff --git a/bgpd/rfapi/rfapi_rib.c b/bgpd/rfapi/rfapi_rib.c
index f727f24f1d..be9d30768c 100644
--- a/bgpd/rfapi/rfapi_rib.c
+++ b/bgpd/rfapi/rfapi_rib.c
@@ -116,7 +116,6 @@ void rfapiRibCheckCounts(
struct bgp *bgp = bgp_get_default();
uint32_t t_pfx_active = 0;
- uint32_t t_pfx_deleted = 0;
uint32_t t_ri_active = 0;
uint32_t t_ri_deleted = 0;
@@ -131,7 +130,6 @@ void rfapiRibCheckCounts(
afi_t afi;
uint32_t pfx_active = 0;
- uint32_t pfx_deleted = 0;
for (afi = AFI_IP; afi < AFI_MAX; ++afi) {
@@ -156,8 +154,6 @@ void rfapiRibCheckCounts(
if (dsl) {
ri_deleted = skiplist_count(dsl);
t_ri_deleted += ri_deleted;
- ++pfx_deleted;
- ++t_pfx_deleted;
}
}
for (rn = agg_route_top(rfd->rib_pending[afi]); rn;
@@ -255,8 +251,8 @@ static void rfapi_info_free(struct rfapi_info *goner)
if (goner->timer) {
struct rfapi_rib_tcb *tcb;
- tcb = THREAD_ARG(goner->timer);
- THREAD_OFF(goner->timer);
+ tcb = EVENT_ARG(goner->timer);
+ EVENT_OFF(goner->timer);
XFREE(MTYPE_RFAPI_RECENT_DELETE, tcb);
}
XFREE(MTYPE_RFAPI_INFO, goner);
@@ -278,9 +274,9 @@ struct rfapi_rib_tcb {
/*
* remove route from rib
*/
-static void rfapiRibExpireTimer(struct thread *t)
+static void rfapiRibExpireTimer(struct event *t)
{
- struct rfapi_rib_tcb *tcb = THREAD_ARG(t);
+ struct rfapi_rib_tcb *tcb = EVENT_ARG(t);
RFAPI_RIB_CHECK_COUNTS(1, 0);
@@ -325,8 +321,8 @@ static void rfapiRibStartTimer(struct rfapi_descriptor *rfd,
struct rfapi_rib_tcb *tcb = NULL;
if (ri->timer) {
- tcb = THREAD_ARG(ri->timer);
- THREAD_OFF(ri->timer);
+ tcb = EVENT_ARG(ri->timer);
+ EVENT_OFF(ri->timer);
} else {
tcb = XCALLOC(MTYPE_RFAPI_RECENT_DELETE,
sizeof(struct rfapi_rib_tcb));
@@ -345,8 +341,8 @@ static void rfapiRibStartTimer(struct rfapi_descriptor *rfd,
vnc_zlog_debug_verbose("%s: rfd %p pfx %pRN life %u", __func__, rfd, rn,
ri->lifetime);
- thread_add_timer(bm->master, rfapiRibExpireTimer, tcb, ri->lifetime,
- &ri->timer);
+ event_add_timer(bm->master, rfapiRibExpireTimer, tcb, ri->lifetime,
+ &ri->timer);
}
extern void rfapi_rib_key_init(struct prefix *prefix, /* may be NULL */
@@ -900,8 +896,8 @@ static void process_pending_node(struct bgp *bgp, struct rfapi_descriptor *rfd,
if (ri->timer) {
struct rfapi_rib_tcb *tcb;
- tcb = THREAD_ARG(ri->timer);
- THREAD_OFF(ri->timer);
+ tcb = EVENT_ARG(ri->timer);
+ EVENT_OFF(ri->timer);
XFREE(MTYPE_RFAPI_RECENT_DELETE, tcb);
}
@@ -985,8 +981,8 @@ static void process_pending_node(struct bgp *bgp, struct rfapi_descriptor *rfd,
if (ori->timer) {
struct rfapi_rib_tcb *tcb;
- tcb = THREAD_ARG(ori->timer);
- THREAD_OFF(ori->timer);
+ tcb = EVENT_ARG(ori->timer);
+ EVENT_OFF(ori->timer);
XFREE(MTYPE_RFAPI_RECENT_DELETE, tcb);
}
@@ -1319,8 +1315,8 @@ callback:
if (ri->timer) {
struct rfapi_rib_tcb *tcb;
- tcb = THREAD_ARG(ri->timer);
- THREAD_OFF(ri->timer);
+ tcb = EVENT_ARG(ri->timer);
+ EVENT_OFF(ri->timer);
XFREE(MTYPE_RFAPI_RECENT_DELETE, tcb);
}
RFAPI_RIB_CHECK_COUNTS(0, delete_list->count);
@@ -2303,10 +2299,6 @@ void rfapiRibShowResponses(void *stream, struct prefix *pfx_match,
int printedheader = 0;
int routes_total = 0;
int nhs_total = 0;
- int prefixes_total = 0;
- int prefixes_displayed = 0;
- int nves_total = 0;
- int nves_with_routes = 0;
int nves_displayed = 0;
int routes_displayed = 0;
int nhs_displayed = 0;
@@ -2326,10 +2318,6 @@ void rfapiRibShowResponses(void *stream, struct prefix *pfx_match,
int printednve = 0;
afi_t afi;
- ++nves_total;
- if (rfd->rib_prefix_count)
- ++nves_with_routes;
-
for (afi = AFI_IP; afi < AFI_MAX; ++afi) {
struct agg_node *rn;
@@ -2355,14 +2343,11 @@ void rfapiRibShowResponses(void *stream, struct prefix *pfx_match,
routes_total++;
nhs_total += skiplist_count(sl);
- ++prefixes_total;
if (pfx_match && !prefix_match(pfx_match, p)
&& !prefix_match(p, pfx_match))
continue;
- ++prefixes_displayed;
-
if (!printedheader) {
++printedheader;
diff --git a/bgpd/rfapi/rfapi_rib.h b/bgpd/rfapi/rfapi_rib.h
index 1b626bd2e1..5fa838bd34 100644
--- a/bgpd/rfapi/rfapi_rib.h
+++ b/bgpd/rfapi/rfapi_rib.h
@@ -61,7 +61,7 @@ struct rfapi_info {
struct bgp_tea_options *tea_options;
struct rfapi_un_option *un_options;
struct rfapi_vn_option *vn_options;
- struct thread *timer;
+ struct event *timer;
};
/*
diff --git a/bgpd/rfapi/rfapi_vty.c b/bgpd/rfapi/rfapi_vty.c
index 2b768b8f8d..2877c29c20 100644
--- a/bgpd/rfapi/rfapi_vty.c
+++ b/bgpd/rfapi/rfapi_vty.c
@@ -516,10 +516,10 @@ void rfapiPrintBi(void *stream, struct bgp_path_info *bpi)
if (CHECK_FLAG(bpi->flags, BGP_PATH_REMOVED) && bpi->extra
&& bpi->extra->vnc.import.timer) {
- struct thread *t =
- (struct thread *)bpi->extra->vnc.import.timer;
+ struct event *t = (struct event *)bpi->extra->vnc.import.timer;
+
r = snprintf(p, REMAIN, " [%4lu] ",
- thread_timer_remain_second(t));
+ event_timer_remain_second(t));
INCP;
} else {
@@ -822,11 +822,6 @@ int rfapiShowVncQueries(void *stream, struct prefix *pfx_match)
const char *vty_newline;
int printedheader = 0;
-
- int nves_total = 0;
- int nves_with_queries = 0;
- int nves_displayed = 0;
-
int queries_total = 0;
int queries_displayed = 0;
@@ -850,15 +845,9 @@ int rfapiShowVncQueries(void *stream, struct prefix *pfx_match)
struct agg_node *rn;
int printedquerier = 0;
-
- ++nves_total;
-
- if (rfd->mon
- || (rfd->mon_eth && skiplist_count(rfd->mon_eth))) {
- ++nves_with_queries;
- } else {
+ if (!rfd->mon &&
+ !(rfd->mon_eth && skiplist_count(rfd->mon_eth)))
continue;
- }
/*
* IP Queries
@@ -904,13 +893,11 @@ int rfapiShowVncQueries(void *stream, struct prefix *pfx_match)
fp(out, "%-15s %-15s", buf_vn, buf_un);
printedquerier = 1;
-
- ++nves_displayed;
} else
fp(out, "%-15s %-15s", "", "");
buf_remain[0] = 0;
rfapiFormatSeconds(
- thread_timer_remain_second(m->timer),
+ event_timer_remain_second(m->timer),
buf_remain, BUFSIZ);
fp(out, " %-15s %-10s\n",
inet_ntop(m->p.family, &m->p.u.prefix,
@@ -978,12 +965,10 @@ int rfapiShowVncQueries(void *stream, struct prefix *pfx_match)
fp(out, "%-15s %-15s", buf_vn, buf_un);
printedquerier = 1;
-
- ++nves_displayed;
} else
fp(out, "%-15s %-15s", "", "");
buf_remain[0] = 0;
- rfapiFormatSeconds(thread_timer_remain_second(
+ rfapiFormatSeconds(event_timer_remain_second(
mon_eth->timer),
buf_remain, BUFSIZ);
fp(out, " %-17s %10d %-10s\n",
@@ -1114,9 +1099,8 @@ static int rfapiPrintRemoteRegBi(struct bgp *bgp, void *stream,
time_t age;
char buf_age[BUFSIZ];
- struct thread *t =
- (struct thread *)bpi->extra->vnc.import.timer;
- remaining = thread_timer_remain_second(t);
+ struct event *t = (struct event *)bpi->extra->vnc.import.timer;
+ remaining = event_timer_remain_second(t);
#ifdef RFAPI_REGISTRATIONS_REPORT_AGE
/*
@@ -1174,6 +1158,7 @@ static int rfapiPrintRemoteRegBi(struct bgp *bgp, void *stream,
}
if (tun_type != BGP_ENCAP_TYPE_MPLS && bpi->extra) {
uint32_t l = decode_label(&bpi->extra->label[0]);
+
if (!MPLS_LABEL_IS_NULL(l)) {
fp(out, " Label: %d", l);
if (nlines == 1)
diff --git a/bgpd/rfapi/vnc_export_bgp.c b/bgpd/rfapi/vnc_export_bgp.c
index 5449220448..7decb75782 100644
--- a/bgpd/rfapi/vnc_export_bgp.c
+++ b/bgpd/rfapi/vnc_export_bgp.c
@@ -1692,7 +1692,7 @@ void vnc_direct_bgp_rh_add_route(struct bgp *bgp, afi_t afi,
* export expiration timer is already running on
* this route: cancel it
*/
- THREAD_OFF(eti->timer);
+ EVENT_OFF(eti->timer);
bgp_update(peer, prefix, /* prefix */
0, /* addpath_id */
@@ -1704,9 +1704,9 @@ void vnc_direct_bgp_rh_add_route(struct bgp *bgp, afi_t afi,
bgp_attr_unintern(&iattr);
}
-static void vncExportWithdrawTimer(struct thread *t)
+static void vncExportWithdrawTimer(struct event *t)
{
- struct vnc_export_info *eti = THREAD_ARG(t);
+ struct vnc_export_info *eti = EVENT_ARG(t);
const struct prefix *p = agg_node_get_prefix(eti->node);
/*
@@ -1765,8 +1765,8 @@ void vnc_direct_bgp_rh_del_route(struct bgp *bgp, afi_t afi,
if (!eti->timer && eti->lifetime <= INT32_MAX) {
eti->timer = NULL;
- thread_add_timer(bm->master, vncExportWithdrawTimer, eti,
- eti->lifetime, &eti->timer);
+ event_add_timer(bm->master, vncExportWithdrawTimer, eti,
+ eti->lifetime, &eti->timer);
vnc_zlog_debug_verbose(
"%s: set expiration timer for %u seconds", __func__,
eti->lifetime);
@@ -1922,7 +1922,7 @@ void vnc_direct_bgp_rh_vpn_enable(struct bgp *bgp, afi_t afi)
* already running on
* this route: cancel it
*/
- THREAD_OFF(eti->timer);
+ EVENT_OFF(eti->timer);
vnc_zlog_debug_verbose(
"%s: calling bgp_update",
@@ -1991,7 +1991,7 @@ void vnc_direct_bgp_rh_vpn_disable(struct bgp *bgp, afi_t afi)
ZEBRA_ROUTE_VNC_DIRECT_RH,
BGP_ROUTE_REDISTRIBUTE);
if (eti) {
- THREAD_OFF(eti->timer);
+ EVENT_OFF(eti->timer);
vnc_eti_delete(eti);
}
diff --git a/bgpd/rfapi/vnc_export_table.h b/bgpd/rfapi/vnc_export_table.h
index 42c04f0c79..f715de0857 100644
--- a/bgpd/rfapi/vnc_export_table.h
+++ b/bgpd/rfapi/vnc_export_table.h
@@ -9,7 +9,7 @@
#define _QUAGGA_VNC_VNC_EXPORT_TABLE_H_
#include "lib/table.h"
-#include "lib/thread.h"
+#include "frrevent.h"
#include "lib/vty.h"
#include "bgpd/bgpd.h"
@@ -29,7 +29,7 @@ struct vnc_export_info {
uint8_t type;
uint8_t subtype;
uint32_t lifetime;
- struct thread *timer;
+ struct event *timer;
};
extern struct agg_node *vnc_etn_get(struct bgp *bgp, vnc_export_type_t type,
diff --git a/bgpd/rfapi/vnc_import_bgp.c b/bgpd/rfapi/vnc_import_bgp.c
index 7c8e8f35c9..3fcc0e6f5f 100644
--- a/bgpd/rfapi/vnc_import_bgp.c
+++ b/bgpd/rfapi/vnc_import_bgp.c
@@ -834,6 +834,8 @@ static void vnc_import_bgp_add_route_mode_plain(struct bgp *bgp,
if (ecom)
ecommunity_free(&ecom);
+ if (iattr)
+ bgp_attr_unintern(&iattr);
}
static void vnc_import_bgp_add_route_mode_nvegroup(
@@ -1030,6 +1032,8 @@ static void vnc_import_bgp_add_route_mode_nvegroup(
if (ecom)
ecommunity_free(&ecom);
+ if (iattr)
+ bgp_attr_unintern(&iattr);
}
static void vnc_import_bgp_del_route_mode_plain(struct bgp *bgp,
@@ -1982,8 +1986,6 @@ void vnc_import_bgp_exterior_add_route_interior(
if (RFAPI_HAS_MONITOR_EXTERIOR(rn_interior)) {
- int count = 0; /* debugging */
-
vnc_zlog_debug_verbose(
"%s: has exterior monitor; ext src: %p", __func__,
RFAPI_MONITOR_EXTERIOR(rn_interior)->source);
@@ -2007,9 +2009,6 @@ void vnc_import_bgp_exterior_add_route_interior(
struct attr new_attr;
uint32_t label = 0;
-
- ++count; /* debugging */
-
assert(bpi_exterior);
assert(pfx_exterior);
diff --git a/bgpd/rfapi/vnc_zebra.c b/bgpd/rfapi/vnc_zebra.c
index 4dab0bc333..4c55c2f633 100644
--- a/bgpd/rfapi/vnc_zebra.c
+++ b/bgpd/rfapi/vnc_zebra.c
@@ -890,7 +890,7 @@ static zclient_handler *const vnc_handlers[] = {
* Modeled after bgp_zebra.c'bgp_zebra_init()
* Charriere asks, "Is it possible to carry two?"
*/
-void vnc_zebra_init(struct thread_master *master)
+void vnc_zebra_init(struct event_loop *master)
{
/* Set default values. */
zclient_vnc = zclient_new(master, &zclient_options_default,
diff --git a/bgpd/rfp-example/librfp/rfp_example.c b/bgpd/rfp-example/librfp/rfp_example.c
index 3a512902e0..1ada36bbc0 100644
--- a/bgpd/rfp-example/librfp/rfp_example.c
+++ b/bgpd/rfp-example/librfp/rfp_example.c
@@ -17,7 +17,7 @@
struct rfp_instance_t {
struct rfapi_rfp_cfg rfapi_config;
struct rfapi_rfp_cb_methods rfapi_callbacks;
- struct thread_master *master;
+ struct event_loop *master;
uint32_t config_var;
};
@@ -271,7 +271,7 @@ static int rfp_cfg_write_cb(struct vty *vty, void *rfp_start_val)
* rfp_start_val rfp returned value passed on rfp_stop and rfp_cfg_write
*
--------------------------------------------*/
-void *rfp_start(struct thread_master *master, struct rfapi_rfp_cfg **cfgp,
+void *rfp_start(struct event_loop *master, struct rfapi_rfp_cfg **cfgp,
struct rfapi_rfp_cb_methods **cbmp)
{
memset(&global_rfi, 0, sizeof(global_rfi));
diff --git a/configure.ac b/configure.ac
index 495c89c0d6..79288c67e9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -299,14 +299,20 @@ if test "$enable_scripting" = "yes"; then
AX_LUA_HEADERS([], [
AC_MSG_ERROR([Lua 5.3 headers are required to build with Lua support. No other version is supported.])
])
- AX_LUA_LIBS([
+ PKG_CHECK_MODULES([LUA], [lua5.3], [
AC_DEFINE([HAVE_SCRIPTING], [1], [Have support for scripting])
- LIBS="$LIBS $LUA_LIB"
+ LIBS="$LIBS $LUA_LIBS"
SCRIPTING=true
], [
- SCRIPTING=false
- AC_MSG_ERROR([Lua 5.3 libraries are required to build with Lua support. No other version is supported.])
- ])
+ AX_LUA_LIBS([
+ AC_DEFINE([HAVE_SCRIPTING], [1], [Have support for scripting])
+ LIBS="$LIBS $LUA_LIB"
+ SCRIPTING=true
+ ], [
+ SCRIPTING=false
+ AC_MSG_ERROR([Lua 5.3 libraries are required to build with Lua support. No other version is supported.])
+ ])
+ ])
fi
dnl the following flags go in CFLAGS rather than AC_CFLAGS since they make
@@ -616,6 +622,10 @@ AC_ARG_ENABLE([zebra],
AS_HELP_STRING([--disable-zebra], [do not build zebra daemon]))
AC_ARG_ENABLE([bgpd],
AS_HELP_STRING([--disable-bgpd], [do not build bgpd]))
+AC_ARG_ENABLE([mgmtd],
+ AS_HELP_STRING([--disable-mgmtd], [do not build mgmtd]))
+AC_ARG_ENABLE([mgmtd_local_validations],
+ AS_HELP_STRING([--enable-mgmtd-local-validations], [dev: unimplemented local validation]))
AC_ARG_ENABLE([ripd],
AS_HELP_STRING([--disable-ripd], [do not build ripd]))
AC_ARG_ENABLE([ripngd],
@@ -890,10 +900,6 @@ if test "$enable_oldvpn_commands" = "yes"; then
AC_DEFINE([KEEP_OLD_VPN_COMMANDS], [1], [Define for compiling with old vpn commands])
fi
-#
-# End of logic for protobuf support.
-#
-
AC_MSG_CHECKING([if zebra should be configurable to send Route Advertisements])
if test "$enable_rtadv" != "no"; then
AC_MSG_RESULT([yes])
@@ -1338,21 +1344,21 @@ dnl ##########################################################################
# Logic for protobuf support.
#
PROTO3=false
-if test "$enable_protobuf" = "yes"; then
- # Check for protoc & protoc-c
-
- # protoc is not required, it's only for a "be nice" helper target
- AC_CHECK_PROGS([PROTOC], [protoc], [/bin/false])
+# Enable Protobuf by default at all times.
+# Check for protoc & protoc-c
+# protoc is not required, it's only for a "be nice" helper target
+AC_CHECK_PROGS([PROTOC], [protoc], [/bin/false])
- AC_CHECK_PROGS([PROTOC_C], [protoc-c], [/bin/false])
- if test "$PROTOC_C" = "/bin/false"; then
- AC_MSG_FAILURE([protobuf requested but protoc-c not found. Install protobuf-c.])
- fi
+AC_CHECK_PROGS([PROTOC_C], [protoc-c], [/bin/false])
+if test "$PROTOC_C" = "/bin/false"; then
+ AC_MSG_FAILURE([protobuf requested but protoc-c not found. Install protobuf-c.])
+fi
- PKG_CHECK_MODULES([PROTOBUF_C], [libprotobuf-c >= 0.14],, [
- AC_MSG_FAILURE([protobuf requested but libprotobuf-c not found. Install protobuf-c.])
- ])
+PKG_CHECK_MODULES([PROTOBUF_C], [libprotobuf-c >= 1.1.0],, [
+ AC_MSG_FAILURE([minimum version (1.1.0) of libprotobuf-c not found. Install minimum required version of protobuf-c.])
+])
+if test "$enable_protobuf3" = "yes"; then
PROTO3=true
AC_CHECK_HEADER([google/protobuf-c/protobuf-c.h],
[AC_CHECK_DECLS(PROTOBUF_C_LABEL_NONE,
@@ -1360,11 +1366,14 @@ if test "$enable_protobuf" = "yes"; then
[1], [Have Protobuf version 3]),
[PROTO3=false],
[#include <google/protobuf-c/protobuf-c.h>])],
- [PROTO3=false && AC_MSG_FAILURE([protobuf requested but protobuf-c.h not found. Install protobuf-c.])])
-
- AC_DEFINE([HAVE_PROTOBUF], [1], [protobuf])
+ [PROTO3=false && AC_MSG_FAILURE([protobuf3 requested but protobuf-c.h not found. Install protobuf-c.])])
fi
+AC_DEFINE([HAVE_PROTOBUF], [1], [protobuf])
+#
+# End of logic for protobuf support.
+#
+
dnl ---------------------
dnl Integrated VTY option
@@ -1728,6 +1737,16 @@ AS_IF([test "$enable_bgpd" != "no"], [
AC_DEFINE([HAVE_BGPD], [1], [bgpd])
])
+AS_IF([test "$enable_mgmtd" != "no"], [
+
+ AC_DEFINE([HAVE_MGMTD], [1], [mgmtd])
+
+ # Enable MGMTD local validations
+ AS_IF([test "$enable_mgmtd_local_validations" == "yes"], [
+ AC_DEFINE([MGMTD_LOCAL_VALIDATIONS_ENABLED], [1], [Enable mgmtd local validations.])
+ ])
+])
+
AS_IF([test "$enable_ripd" != "no"], [
AC_DEFINE([HAVE_RIPD], [1], [ripd])
])
@@ -2658,6 +2677,8 @@ AC_DEFINE_UNQUOTED([LDPD_SOCKET], ["$frr_statedir%s%s/ldpd.sock"], [ldpd control
AC_DEFINE_UNQUOTED([ZEBRA_SERV_PATH], ["$frr_statedir%s%s/zserv.api"], [zebra api socket])
AC_DEFINE_UNQUOTED([BFDD_CONTROL_SOCKET], ["$frr_statedir%s%s/bfdd.sock"], [bfdd control socket])
AC_DEFINE_UNQUOTED([OSPFD_GR_STATE], ["$frr_statedir%s/ospfd-gr.json"], [ospfd GR state information])
+AC_DEFINE_UNQUOTED([MGMTD_FE_SERVER_PATH], ["$frr_statedir/mgmtd_fe.sock"], [mgmtd frontend server socket])
+AC_DEFINE_UNQUOTED([MGMTD_BE_SERVER_PATH], ["$frr_statedir/mgmtd_be.sock"], [mgmtd backend server socket])
AC_DEFINE_UNQUOTED([OSPF6D_GR_STATE], ["$frr_statedir/ospf6d-gr.json"], [ospf6d GR state information])
AC_DEFINE_UNQUOTED([ISISD_RESTART], ["$frr_statedir%s/isid-restart.json"], [isisd restart information])
AC_DEFINE_UNQUOTED([OSPF6_AUTH_SEQ_NUM_FILE], ["$frr_statedir/ospf6d-at-seq-no.dat"], [ospf6d AT Sequence number information])
@@ -2678,6 +2699,7 @@ AC_SUBST([vtysh_bin])
CFG_SYSCONF="$sysconfdir"
CFG_SBIN="$sbindir"
+CFG_BIN="$bindir"
CFG_STATE="$frr_statedir"
CFG_MODULE="$moduledir"
CFG_YANGMODELS="$yangmodelsdir"
@@ -2685,6 +2707,7 @@ CFG_SCRIPT="$scriptdir"
for I in 1 2 3 4 5 6 7 8 9 10; do
eval CFG_SYSCONF="\"$CFG_SYSCONF\""
eval CFG_SBIN="\"$CFG_SBIN\""
+ eval CFG_BIN="\"$CFG_BIN\""
eval CFG_STATE="\"$CFG_STATE\""
eval CFG_MODULE="\"$CFG_MODULE\""
eval CFG_YANGMODELS="\"$CFG_YANGMODELS\""
@@ -2692,6 +2715,7 @@ for I in 1 2 3 4 5 6 7 8 9 10; do
done
AC_SUBST([CFG_SYSCONF])
AC_SUBST([CFG_SBIN])
+AC_SUBST([CFG_BIN])
AC_SUBST([CFG_STATE])
AC_SUBST([CFG_MODULE])
AC_SUBST([CFG_SCRIPT])
@@ -2716,7 +2740,7 @@ AM_CONDITIONAL([RPKI], [test "$RPKI" = "true"])
AM_CONDITIONAL([SNMP], [test "$SNMP_METHOD" = "agentx"])
AM_CONDITIONAL([IRDP], [$IRDP])
AM_CONDITIONAL([FPM], [test "$enable_fpm" = "yes"])
-AM_CONDITIONAL([HAVE_PROTOBUF], [test "$enable_protobuf" = "yes"])
+AM_CONDITIONAL([HAVE_PROTOBUF], [test "$enable_protobuf" != "no"])
AM_CONDITIONAL([HAVE_PROTOBUF3], [$PROTO3])
dnl PCEP plugin
@@ -2733,6 +2757,7 @@ dnl daemons
AM_CONDITIONAL([VTYSH], [test "$VTYSH" = "vtysh"])
AM_CONDITIONAL([ZEBRA], [test "$enable_zebra" != "no"])
AM_CONDITIONAL([BGPD], [test "$enable_bgpd" != "no"])
+AM_CONDITIONAL([MGMTD], [test "$enable_mgmtd" != "no"])
AM_CONDITIONAL([RIPD], [test "$enable_ripd" != "no"])
AM_CONDITIONAL([OSPFD], [test "$enable_ospfd" != "no"])
AM_CONDITIONAL([LDPD], [test "$enable_ldpd" != "no"])
@@ -2770,7 +2795,7 @@ AC_CONFIG_FILES([
alpine/APKBUILD
snapcraft/snapcraft.yaml
lib/version.h
- tests/lib/cli/test_cli.refout
+ tests/lib/cli/test_cli.refout pkgsrc/mgmtd.sh
pkgsrc/bgpd.sh pkgsrc/ospf6d.sh pkgsrc/ospfd.sh
pkgsrc/ripd.sh pkgsrc/ripngd.sh pkgsrc/zebra.sh
pkgsrc/eigrpd.sh])
diff --git a/debian/frr.install b/debian/frr.install
index 044b484984..02912d448d 100644
--- a/debian/frr.install
+++ b/debian/frr.install
@@ -8,6 +8,7 @@ usr/bin/vtysh
usr/lib/*/frr/libfrr.*
usr/lib/*/frr/libfrrcares.*
usr/lib/*/frr/libfrrospfapiclient.*
+usr/lib/*/frr/libmgmt_be_nb.*
usr/lib/*/frr/modules/bgpd_bmp.so
usr/lib/*/frr/modules/dplane_fpm_nl.so
usr/lib/*/frr/modules/zebra_cumulus_mlag.so
diff --git a/doc/developer/building-frr-for-centos6.rst b/doc/developer/building-frr-for-centos6.rst
index 7a7af42119..233d089f79 100644
--- a/doc/developer/building-frr-for-centos6.rst
+++ b/doc/developer/building-frr-for-centos6.rst
@@ -46,7 +46,7 @@ Add packages:
sudo yum install git autoconf automake libtool make \
readline-devel texinfo net-snmp-devel groff pkgconfig \
json-c-devel pam-devel flex epel-release c-ares-devel libcap-devel \
- elfutils-libelf-devel
+ elfutils-libelf-devel protobuf-c-devel
Install newer version of bison (CentOS 6 package source is too old) from CentOS
7:
diff --git a/doc/developer/building-frr-for-centos7.rst b/doc/developer/building-frr-for-centos7.rst
index c40b5de594..e6da830194 100644
--- a/doc/developer/building-frr-for-centos7.rst
+++ b/doc/developer/building-frr-for-centos7.rst
@@ -22,7 +22,7 @@ Add packages:
readline-devel texinfo net-snmp-devel groff pkgconfig \
json-c-devel pam-devel bison flex pytest c-ares-devel \
python-devel python-sphinx libcap-devel \
- elfutils-libelf-devel libunwind-devel
+ elfutils-libelf-devel libunwind-devel protobuf-c-devel
.. include:: building-libunwind-note.rst
diff --git a/doc/developer/building-frr-for-centos8.rst b/doc/developer/building-frr-for-centos8.rst
index 659752f6df..6d18e7be93 100644
--- a/doc/developer/building-frr-for-centos8.rst
+++ b/doc/developer/building-frr-for-centos8.rst
@@ -15,7 +15,8 @@ Add packages:
automake libtool make readline-devel texinfo net-snmp-devel pkgconfig \
groff pkgconfig json-c-devel pam-devel bison flex python2-pytest \
c-ares-devel python2-devel libcap-devel \
- elfutils-libelf-devel libunwind-devel
+ elfutils-libelf-devel libunwind-devel \
+ protobuf-c-devel
.. include:: building-libunwind-note.rst
diff --git a/doc/developer/building-frr-for-debian8.rst b/doc/developer/building-frr-for-debian8.rst
index 5e58854ed7..7071cb660d 100644
--- a/doc/developer/building-frr-for-debian8.rst
+++ b/doc/developer/building-frr-for-debian8.rst
@@ -18,7 +18,7 @@ Add packages:
sudo apt-get install git autoconf automake libtool make \
libreadline-dev texinfo libjson-c-dev pkg-config bison flex python3-pip \
libc-ares-dev python3-dev python3-sphinx build-essential \
- libsnmp-dev libcap-dev libelf-dev
+ libsnmp-dev libcap-dev libelf-dev libprotobuf-c-dev protobuf-c-compiler
Install newer pytest (>3.0) from pip
diff --git a/doc/developer/building-frr-for-debian9.rst b/doc/developer/building-frr-for-debian9.rst
index b2fdef9990..1b2f1b933a 100644
--- a/doc/developer/building-frr-for-debian9.rst
+++ b/doc/developer/building-frr-for-debian9.rst
@@ -11,7 +11,8 @@ Add packages:
sudo apt-get install git autoconf automake libtool make \
libreadline-dev texinfo libjson-c-dev pkg-config bison flex \
libc-ares-dev python3-dev python3-pytest python3-sphinx build-essential \
- libsnmp-dev libcap-dev libelf-dev libunwind-dev
+ libsnmp-dev libcap-dev libelf-dev libunwind-dev \
+ libprotobuf-c-dev protobuf-c-compiler
.. include:: building-libunwind-note.rst
diff --git a/doc/developer/building-frr-for-fedora.rst b/doc/developer/building-frr-for-fedora.rst
index aa10f1118d..35a24b2f43 100644
--- a/doc/developer/building-frr-for-fedora.rst
+++ b/doc/developer/building-frr-for-fedora.rst
@@ -15,7 +15,7 @@ Installing Dependencies
readline-devel texinfo net-snmp-devel groff pkgconfig json-c-devel \
pam-devel python3-pytest bison flex c-ares-devel python3-devel \
python3-sphinx perl-core patch libcap-devel \
- elfutils-libelf-devel libunwind-devel
+ elfutils-libelf-devel libunwind-devel protobuf-c-devel
.. include:: building-libunwind-note.rst
diff --git a/doc/developer/building-frr-for-freebsd10.rst b/doc/developer/building-frr-for-freebsd10.rst
index 5e70b81d43..707f1e7033 100644
--- a/doc/developer/building-frr-for-freebsd10.rst
+++ b/doc/developer/building-frr-for-freebsd10.rst
@@ -17,7 +17,8 @@ is first package install and asked)
::
pkg install git autoconf automake libtool gmake json-c pkgconf \
- bison flex py36-pytest c-ares python3.6 py36-sphinx libunwind
+ bison flex py36-pytest c-ares python3.6 py36-sphinx libunwind \
+ protobuf-c
.. include:: building-libunwind-note.rst
diff --git a/doc/developer/building-frr-for-freebsd11.rst b/doc/developer/building-frr-for-freebsd11.rst
index 808207b831..af0b72b16d 100644
--- a/doc/developer/building-frr-for-freebsd11.rst
+++ b/doc/developer/building-frr-for-freebsd11.rst
@@ -17,7 +17,8 @@ is first package install and asked)
.. code-block:: shell
pkg install git autoconf automake libtool gmake json-c pkgconf \
- bison flex py36-pytest c-ares python3.6 py36-sphinx texinfo libunwind
+ bison flex py36-pytest c-ares python3.6 py36-sphinx texinfo libunwind \
+ protobuf-c
.. include:: building-libunwind-note.rst
diff --git a/doc/developer/building-frr-for-freebsd9.rst b/doc/developer/building-frr-for-freebsd9.rst
index 1e97749795..30332875a0 100644
--- a/doc/developer/building-frr-for-freebsd9.rst
+++ b/doc/developer/building-frr-for-freebsd9.rst
@@ -18,7 +18,7 @@ is first package install and asked)
pkg install -y git autoconf automake libtool gmake \
pkgconf texinfo json-c bison flex py36-pytest c-ares \
- python3 py36-sphinx libexecinfo
+ python3 py36-sphinx libexecinfo protobuf-c
Make sure there is no /usr/bin/flex preinstalled (and use the newly
installed in /usr/local/bin): (FreeBSD frequently provides a older flex
diff --git a/doc/developer/building-frr-for-netbsd6.rst b/doc/developer/building-frr-for-netbsd6.rst
index a78f8b3c2f..8958862fea 100644
--- a/doc/developer/building-frr-for-netbsd6.rst
+++ b/doc/developer/building-frr-for-netbsd6.rst
@@ -23,7 +23,8 @@ Add packages:
::
sudo pkg_add git autoconf automake libtool gmake openssl \
- pkg-config json-c py36-test python36 py36-sphinx
+ pkg-config json-c py36-test python36 py36-sphinx \
+ protobuf-c
Install SSL Root Certificates (for git https access):
diff --git a/doc/developer/building-frr-for-netbsd7.rst b/doc/developer/building-frr-for-netbsd7.rst
index a52ece19a1..e751ba338c 100644
--- a/doc/developer/building-frr-for-netbsd7.rst
+++ b/doc/developer/building-frr-for-netbsd7.rst
@@ -14,7 +14,8 @@ Install required packages
::
sudo pkgin install git autoconf automake libtool gmake openssl \
- pkg-config json-c python36 py36-test py36-sphinx
+ pkg-config json-c python36 py36-test py36-sphinx \
+ protobuf-c
Install SSL Root Certificates (for git https access):
diff --git a/doc/developer/building-frr-for-openbsd6.rst b/doc/developer/building-frr-for-openbsd6.rst
index 88446685e0..00bc2e5f09 100644
--- a/doc/developer/building-frr-for-openbsd6.rst
+++ b/doc/developer/building-frr-for-openbsd6.rst
@@ -16,7 +16,7 @@ Add packages:
pkg_add clang libcares python3
pkg_add git autoconf-2.69p2 automake-1.15.1 libtool bison
- pkg_add gmake json-c py-test py-sphinx libexecinfo
+ pkg_add gmake json-c py-test py-sphinx libexecinfo protobuf-c
Select Python2.7 as default (required for pytest)
diff --git a/doc/developer/building-frr-for-opensuse.rst b/doc/developer/building-frr-for-opensuse.rst
index 38346fe881..3ff445bcd0 100644
--- a/doc/developer/building-frr-for-opensuse.rst
+++ b/doc/developer/building-frr-for-opensuse.rst
@@ -14,7 +14,7 @@ Installing Dependencies
readline-devel texinfo net-snmp-devel groff pkgconfig libjson-c-devel\
pam-devel python3-pytest bison flex c-ares-devel python3-devel\
python3-Sphinx perl patch libcap-devel libyang-devel \
- libelf-devel libunwind-devel
+ libelf-devel libunwind-devel protobuf-c
.. include:: building-libunwind-note.rst
diff --git a/doc/developer/building-frr-for-ubuntu1404.rst b/doc/developer/building-frr-for-ubuntu1404.rst
index 2711e92b6f..cc6c3c03f3 100644
--- a/doc/developer/building-frr-for-ubuntu1404.rst
+++ b/doc/developer/building-frr-for-ubuntu1404.rst
@@ -18,6 +18,13 @@ Installing Dependencies
.. include:: building-libyang.rst
+Protobuf
+^^^^^^^^
+
+.. code-block:: console
+
+ sudo apt-get install protobuf-c-compiler libprotobuf-c-dev
+
Building & Installing FRR
-------------------------
diff --git a/doc/developer/building-frr-for-ubuntu1604.rst b/doc/developer/building-frr-for-ubuntu1604.rst
index d79545c859..e5c2389f39 100644
--- a/doc/developer/building-frr-for-ubuntu1604.rst
+++ b/doc/developer/building-frr-for-ubuntu1604.rst
@@ -15,10 +15,17 @@ Installing Dependencies
pkg-config libpam0g-dev libjson-c-dev bison flex python3-pytest \
libc-ares-dev python3-dev python-ipaddress python3-sphinx \
install-info build-essential libsnmp-dev perl libcap-dev \
- libelf-dev
+ libelf-dev libprotobuf-c-dev protobuf-c-compiler
.. include:: building-libyang.rst
+Protobuf
+^^^^^^^^
+
+.. code-block:: console
+
+ sudo apt-get install protobuf-c-compiler libprotobuf-c-dev
+
Building & Installing FRR
-------------------------
diff --git a/doc/developer/cli.rst b/doc/developer/cli.rst
index 2a08531bd7..61b9cf6acb 100644
--- a/doc/developer/cli.rst
+++ b/doc/developer/cli.rst
@@ -177,29 +177,29 @@ parser, but this is merely a dumb copy job.
Here is a brief summary of the various token types along with examples.
-+-----------------+-------------------------+-------------------------------------------------------+
-| Token type | Syntax | Description |
-+=================+=========================+=======================================================+
-| ``WORD`` | ``show ip bgp`` | Matches itself. In the example every token is a WORD. |
-+-----------------+-------------------------+-------------------------------------------------------+
-| ``IPV4`` | ``A.B.C.D`` | Matches an IPv4 address. |
-+-----------------+-------------------------+-------------------------------------------------------+
-| ``IPV6`` | ``X:X::X:X`` | Matches an IPv6 address. |
-+-----------------+-------------------------+-------------------------------------------------------+
-| ``IPV4_PREFIX`` | ``A.B.C.D/M`` | Matches an IPv4 prefix in CIDR notation. |
-+-----------------+-------------------------+-------------------------------------------------------+
-| ``IPV6_PREFIX`` | ``X:X::X:X/M`` | Matches an IPv6 prefix in CIDR notation. |
-+-----------------+-------------------------+-------------------------------------------------------+
-| ``MAC`` | ``X:X:X:X:X:X`` | Matches a 48-bit mac address. |
-+-----------------+-------------------------+-------------------------------------------------------+
-| ``MAC_PREFIX`` | ``X:X:X:X:X:X/M`` | Matches a 48-bit mac address with a mask. |
-+-----------------+-------------------------+-------------------------------------------------------+
-| ``VARIABLE`` | ``FOOBAR`` | Matches anything. |
-+-----------------+-------------------------+-------------------------------------------------------+
-| ``RANGE`` | ``(X-Y)`` | Matches numbers in the range X..Y inclusive. |
-+-----------------+-------------------------+-------------------------------------------------------+
-| ``ASNUM`` | ``<A.B|(1-4294967295>`` | Matches an AS in plain or dot format. |
-+-----------------+-------------------------+-------------------------------------------------------+
++-----------------+--------------------------+-------------------------------------------------------+
+| Token type | Syntax | Description |
++=================+==========================+=======================================================+
+| ``WORD`` | ``show ip bgp`` | Matches itself. In the example every token is a WORD. |
++-----------------+--------------------------+-------------------------------------------------------+
+| ``IPV4`` | ``A.B.C.D`` | Matches an IPv4 address. |
++-----------------+--------------------------+-------------------------------------------------------+
+| ``IPV6`` | ``X:X::X:X`` | Matches an IPv6 address. |
++-----------------+--------------------------+-------------------------------------------------------+
+| ``IPV4_PREFIX`` | ``A.B.C.D/M`` | Matches an IPv4 prefix in CIDR notation. |
++-----------------+--------------------------+-------------------------------------------------------+
+| ``IPV6_PREFIX`` | ``X:X::X:X/M`` | Matches an IPv6 prefix in CIDR notation. |
++-----------------+--------------------------+-------------------------------------------------------+
+| ``MAC`` | ``X:X:X:X:X:X`` | Matches a 48-bit mac address. |
++-----------------+--------------------------+-------------------------------------------------------+
+| ``MAC_PREFIX`` | ``X:X:X:X:X:X/M`` | Matches a 48-bit mac address with a mask. |
++-----------------+--------------------------+-------------------------------------------------------+
+| ``VARIABLE`` | ``FOOBAR`` | Matches anything. |
++-----------------+--------------------------+-------------------------------------------------------+
+| ``RANGE`` | ``(X-Y)`` | Matches numbers in the range X..Y inclusive. |
++-----------------+--------------------------+-------------------------------------------------------+
+| ``ASNUM`` | ``<A.B|(1-4294967295)>`` | Matches an AS in plain or dot format. |
++-----------------+--------------------------+-------------------------------------------------------+
When presented with user input, the parser will search over all defined
commands in the current context to find a match. It is aware of the various
diff --git a/doc/developer/frr-release-procedure.rst b/doc/developer/frr-release-procedure.rst
index 6ba44b9c49..6088b52da4 100644
--- a/doc/developer/frr-release-procedure.rst
+++ b/doc/developer/frr-release-procedure.rst
@@ -145,6 +145,30 @@ Stage 2 - Staging
#. Kick off the Snapcraft build plan for the release.
+#. Build Docker images
+
+ 1. Log into the Netdef Docker build VM
+ 2. ``sudo -su builduser``
+ 3. Suppose we are releasing 8.5.0, then ``X.Y.Z`` is ``8.5.0``. Run this:
+
+ .. code-block:: console
+
+ cd /home/builduser/frr
+ TAG=X.Y.Z
+ git fetch --all
+ git checkout frr-<version>
+ docker buildx build --platform linux/amd64,linux/arm64,linux/ppc64le,linux/s390x,linux/arm/v7,linux/arm/v6 -f docker/alpine/Dockerfile -t quay.io/frrouting/frr:$TAG --push .
+ git tag docker/$TAG
+ git push origin docker/$TAG
+
+ This will build a multi-arch image and upload it to Quay, as well as
+ create a git tag corresponding to the commit that the image was built
+ from and upload that to Github. It's important that the git tag point to
+ the exact codebase that was used to build the docker image, so if any
+ changes need to be made on top of the ``frr-<version>`` release tag, make
+ sure these changes are committed and pointed at by the ``docker/X.Y.Z``
+ tag.
+
Stage 3 - Publish
-----------------
diff --git a/doc/developer/logging.rst b/doc/developer/logging.rst
index e262f6af94..2fe0a5989b 100644
--- a/doc/developer/logging.rst
+++ b/doc/developer/logging.rst
@@ -335,16 +335,16 @@ Time/interval formats
FRR library helper formats
^^^^^^^^^^^^^^^^^^^^^^^^^^
-.. frrfmt:: %pTH (struct thread *)
+.. frrfmt:: %pTH (struct event *)
- Print remaining time on timer thread. Interval-printing flag characters
+ Print remaining time on timer event. Interval-printing flag characters
listed above for ``%pTV`` can be added, e.g. ``%pTHtx``.
``NULL`` pointers are printed as ``-``.
-.. frrfmt:: %pTHD (struct thread *)
+.. frrfmt:: %pTHD (struct event *)
- Print debugging information for given thread. Sample output:
+ Print debugging information for given event. Sample output:
.. code-block:: none
@@ -502,6 +502,51 @@ General utility formats
representation for a hexdump. Non-printable characters are replaced with
a dot.
+.. frrfmt:: %pIS (struct iso_address *)
+
+ ([IS]o Network address) - Format ISO Network Address
+
+ ``%pIS``: :frrfmtout:`01.0203.04O5`
+ ISO Network address is printed as separated byte. The number of byte of the
+ address is embeded in the `iso_net` structure.
+
+ ``%pISl``: :frrfmtout:`01.0203.04O5.0607.0809.1011.1213.14` - long format to
+ print the long version of the ISO Network address which include the System
+ ID and the PSEUDO-ID of the IS-IS system
+
+ Note that the `ISO_ADDR_STRLEN` define gives the total size of the string
+ that could be used in conjunction to snprintfrr. Use like::
+
+ char buf[ISO_ADDR_STRLEN];
+ struct iso_net addr = {.len = 4, .addr = {1, 2, 3, 4}};
+ snprintfrr(buf, ISO_ADDR_STRLEN, "%pIS", &addr);
+
+.. frrfmt:: %pSY (uint8_t *)
+
+ (IS-IS [SY]stem ID) - Format IS-IS System ID
+
+ ``%pSY``: :frrfmtout:`0102.0304.0506`
+
+.. frrfmt:: %pPN (uint8_t *)
+
+ (IS-IS [P]seudo [N]ode System ID) - Format IS-IS Pseudo Node System ID
+
+ ``%pPN``: :frrfmtout:`0102.0304.0506.07`
+
+.. frrfmt:: %pLS (uint8_t *)
+
+ (IS-IS [L]sp fragment [S]ystem ID) - Format IS-IS Pseudo System ID
+
+ ``%pLS``: :frrfmtout:`0102.0304.0506.07-08`
+
+ Note that the `ISO_SYSID_STRLEN` define gives the total size of the string
+ that could be used in conjunction to snprintfrr. Use like::
+
+ char buf[ISO_SYSID_STRLEN];
+ uint8_t id[8] = {1, 2, 3, 4 , 5 , 6 , 7, 8};
+ snprintfrr(buf, SYS_ID_SIZE, "%pSY", id);
+
+
Integer formats
^^^^^^^^^^^^^^^
diff --git a/doc/developer/modules.rst b/doc/developer/modules.rst
index e95f8a1b4a..0feac8e738 100644
--- a/doc/developer/modules.rst
+++ b/doc/developer/modules.rst
@@ -56,9 +56,9 @@ Basic boilerplate:
#include "hook.h"
#include "module.h"
#include "libfrr.h"
- #include "thread.h"
+ #include "frrevent.h"
- static int module_late_init(struct thread_master *master)
+ static int module_late_init(struct event_loop *master)
{
/* Do initialization stuff here */
return 0;
diff --git a/doc/developer/path-internals-pcep.rst b/doc/developer/path-internals-pcep.rst
index ca318314f1..a6b22204c2 100644
--- a/doc/developer/path-internals-pcep.rst
+++ b/doc/developer/path-internals-pcep.rst
@@ -182,7 +182,7 @@ The controller is defined and implemented in `path_pcep_controller.[hc]`.
Part of the controller code runs in FRR main thread and part runs in its own
FRR pthread started to isolate the main thread from the PCCs' event loop.
To communicate between the threads it uses FRR events, timers and
-`thread_execute` calls.
+`event_execute` calls.
PCC
diff --git a/doc/developer/process-architecture.rst b/doc/developer/process-architecture.rst
index 37bd620f24..33ef278c4d 100644
--- a/doc/developer/process-architecture.rst
+++ b/doc/developer/process-architecture.rst
@@ -28,7 +28,7 @@ within the event system are variations on the term "thread". The primary
datastructure that holds the state of an event loop in this system is called a
"threadmaster". Events scheduled on the event loop - what would today be called
an 'event' or 'task' in systems such as libevent - are called "threads" and the
-datastructure for them is ``struct thread``. To add to the confusion, these
+datastructure for them is ``struct event``. To add to the confusion, these
"threads" have various types, one of which is "event". To hopefully avoid some
of this confusion, this document refers to these "threads" as a 'task' except
where the datastructures are explicitly named. When they are explicitly named,
@@ -47,7 +47,7 @@ section. For now it provides basic information necessary to understand the
interplay between the event system and kernel threads.
The core event system is implemented in :file:`lib/thread.[ch]`. The primary
-structure is ``struct thread_master``, hereafter referred to as a
+structure is ``struct event_loop``, hereafter referred to as a
``threadmaster``. A ``threadmaster`` is a global state object, or context, that
holds all the tasks currently pending execution as well as statistics on tasks
that have already executed. The event system is driven by adding tasks to this
@@ -57,7 +57,7 @@ execute. At initialization, a daemon will typically create one
fetch each task and execute it.
These tasks have various types corresponding to their general action. The types
-are given by integer macros in :file:`thread.h` and are:
+are given by integer macros in :file:`event.h` and are:
``THREAD_READ``
Task which waits for a file descriptor to become ready for reading and then
@@ -80,8 +80,8 @@ are given by integer macros in :file:`thread.h` and are:
Type used internally for tasks on the ready queue.
``THREAD_UNUSED``
- Type used internally for ``struct thread`` objects that aren't being used.
- The event system pools ``struct thread`` to avoid heap allocations; this is
+ Type used internally for ``struct event`` objects that aren't being used.
+ The event system pools ``struct event`` to avoid heap allocations; this is
the type they have when they're in the pool.
``THREAD_EXECUTE``
@@ -95,9 +95,9 @@ irrelevant for the time being) for the specific type. For example, to add a
::
- thread_add_read(struct thread_master *master, int (*handler)(struct thread *), void *arg, int fd, struct thread **ref);
+ event_add_read(struct event_loop *master, int (*handler)(struct event *), void *arg, int fd, struct event **ref);
-The ``struct thread`` is then created and added to the appropriate internal
+The ``struct event`` is then created and added to the appropriate internal
datastructure within the ``threadmaster``. Note that the ``READ`` and
``WRITE`` tasks are independent - a ``READ`` task only tests for
readability, for example.
@@ -111,13 +111,13 @@ program. When no more tasks are available, the program dies. Typically at
startup the first task added is an I/O task for VTYSH as well as any network
sockets needed for peerings or IPC.
-To retrieve the next task to run the program calls ``thread_fetch()``.
-``thread_fetch()`` internally computes which task to execute next based on
+To retrieve the next task to run the program calls ``event_fetch()``.
+``event_fetch()`` internally computes which task to execute next based on
rudimentary priority logic. Events (type ``THREAD_EVENT``) execute with the
highest priority, followed by expired timers and finally I/O tasks (type
``THREAD_READ`` and ``THREAD_WRITE``). When scheduling a task a function and an
-arbitrary argument are provided. The task returned from ``thread_fetch()`` is
-then executed with ``thread_call()``.
+arbitrary argument are provided. The task returned from ``event_fetch()`` is
+then executed with ``event_call()``.
The following diagram illustrates a simplified version of this infrastructure.
@@ -133,18 +133,18 @@ illustrated at the bottom.
Mapping the general names used in the figure to specific FRR functions:
-- ``task`` is ``struct thread *``
-- ``fetch`` is ``thread_fetch()``
-- ``exec()`` is ``thread_call``
-- ``cancel()`` is ``thread_cancel()``
-- ``schedule()`` is any of the various task-specific ``thread_add_*`` functions
+- ``task`` is ``struct event *``
+- ``fetch`` is ``event_fetch()``
+- ``exec()`` is ``event_call``
+- ``cancel()`` is ``event_cancel()``
+- ``schedule()`` is any of the various task-specific ``event_add_*`` functions
Adding tasks is done with various task-specific function-like macros. These
macros wrap underlying functions in :file:`thread.c` to provide additional
information added at compile time, such as the line number the task was
scheduled from, that can be accessed at runtime for debugging, logging and
informational purposes. Each task type has its own specific scheduling function
-that follow the naming convention ``thread_add_<type>``; see :file:`thread.h`
+that follow the naming convention ``event_add_<type>``; see :file:`event.h`
for details.
There are some gotchas to keep in mind:
@@ -228,7 +228,7 @@ well as *any other pthread*. This serves as the basis for inter-thread
communication and boils down to a slightly more complicated method of message
passing, where the messages are the regular task events as used in the
event-driven model. The only difference is thread cancellation, which requires
-calling ``thread_cancel_async()`` instead of ``thread_cancel`` to cancel a task
+calling ``event_cancel_async()`` instead of ``event_cancel`` to cancel a task
currently scheduled on a ``threadmaster`` belonging to a different pthread.
This is necessary to avoid race conditions in the specific case where one
pthread wants to guarantee that a task on another pthread is cancelled before
diff --git a/doc/developer/rcu.rst b/doc/developer/rcu.rst
index ac4405121e..4fd56587ae 100644
--- a/doc/developer/rcu.rst
+++ b/doc/developer/rcu.rst
@@ -120,7 +120,7 @@ atomic ops & datastructures with other types of locking, e.g. rwlocks.
The ``thread_master`` code currently always holds RCU everywhere, except
while doing the actual ``poll()`` syscall. This is both an optimization as
well as an "easement" into getting RCU going. The current implementation
- contract is that any ``struct thread *`` callback is called with a RCU
+ contract is that any ``struct event *`` callback is called with a RCU
holding depth of 1, and that this is owned by the thread so it may (should)
drop and reacquire it when doing some longer-running work.
diff --git a/doc/developer/topotests.rst b/doc/developer/topotests.rst
index ada182d847..5f90b8c5a4 100644
--- a/doc/developer/topotests.rst
+++ b/doc/developer/topotests.rst
@@ -79,9 +79,9 @@ following steps will get you there on Ubuntu 20.04.
apt install snmpd snmp
apt install snmp-mibs-downloader
download-mibs
- wget http://www.iana.org/assignments/ianaippmmetricsregistry-mib/ianaippmmetricsregistry-mib -O /usr/share/snmp/mibs/iana/IANA-IPPM-METRICS-REGISTRY-MIB
- wget http://pastebin.com/raw.php?i=p3QyuXzZ -O /usr/share/snmp/mibs/ietf/SNMPv2-PDU
- wget http://pastebin.com/raw.php?i=gG7j8nyk -O /usr/share/snmp/mibs/ietf/IPATM-IPMC-MIB
+ wget https://raw.githubusercontent.com/FRRouting/frr-mibs/main/iana/IANA-IPPM-METRICS-REGISTRY-MIB -O /usr/share/snmp/mibs/iana/IANA-IPPM-METRICS-REGISTRY-MIB
+ wget https://raw.githubusercontent.com/FRRouting/frr-mibs/main/ietf/SNMPv2-PDU -O /usr/share/snmp/mibs/ietf/SNMPv2-PDU
+ wget https://raw.githubusercontent.com/FRRouting/frr-mibs/main/ietf/IPATM-IPMC-MIB -O /usr/share/snmp/mibs/ietf/IPATM-IPMC-MIB
edit /etc/snmp/snmp.conf to look like this
# As the snmp packages come without MIB files due to license reasons, loading
# of MIBs is disabled by default. If you added the MIBs you can reenable
diff --git a/doc/developer/tracing.rst b/doc/developer/tracing.rst
index 63b04585f1..76f6004034 100644
--- a/doc/developer/tracing.rst
+++ b/doc/developer/tracing.rst
@@ -150,8 +150,8 @@ Example::
frr_libfrr:frr_pthread_stop (loglevel: TRACE_DEBUG_LINE (13)) (type: tracepoint)
frr_libfrr:frr_pthread_run (loglevel: TRACE_DEBUG_LINE (13)) (type: tracepoint)
frr_libfrr:thread_call (loglevel: TRACE_INFO (6)) (type: tracepoint)
- frr_libfrr:thread_cancel_async (loglevel: TRACE_INFO (6)) (type: tracepoint)
- frr_libfrr:thread_cancel (loglevel: TRACE_INFO (6)) (type: tracepoint)
+ frr_libfrr:event_cancel_async (loglevel: TRACE_INFO (6)) (type: tracepoint)
+ frr_libfrr:event_cancel (loglevel: TRACE_INFO (6)) (type: tracepoint)
frr_libfrr:schedule_write (loglevel: TRACE_INFO (6)) (type: tracepoint)
frr_libfrr:schedule_read (loglevel: TRACE_INFO (6)) (type: tracepoint)
frr_libfrr:schedule_event (loglevel: TRACE_INFO (6)) (type: tracepoint)
diff --git a/doc/developer/workflow.rst b/doc/developer/workflow.rst
index 835c1d1d99..f11fff5dee 100644
--- a/doc/developer/workflow.rst
+++ b/doc/developer/workflow.rst
@@ -95,7 +95,7 @@ March/July/November. Walking backwards from this date:
are considered lowest priority (regardless of when they were opened.)
- 4 weeks earlier, the stable branch separates from master (named
- ``dev/MAJOR.MINOR`` at this point) and tagged as ```base_X.Y``.
+ ``dev/MAJOR.MINOR`` at this point) and tagged as ``base_X.Y``.
Master is unfrozen and new features may again proceed.
Part of unfreezing master is editing the ``AC_INIT`` statement in
diff --git a/doc/manpages/vtysh.rst b/doc/manpages/vtysh.rst
index af527bea40..396fcfc66e 100644
--- a/doc/manpages/vtysh.rst
+++ b/doc/manpages/vtysh.rst
@@ -67,6 +67,15 @@ OPTIONS available for the vtysh command:
Display a usage message on standard output and exit.
+.. option:: -t, --timestamp
+
+ Print a timestamp before going to shell or reading the configuration file.
+
+.. option:: --no-fork
+
+ When used in conjunction with ``-b``, prevents vtysh from forking children to handle configuring each target daemon.
+
+
ENVIRONMENT VARIABLES
=====================
VTYSH_PAGER
diff --git a/doc/user/basic.rst b/doc/user/basic.rst
index 254dad8303..337cfff937 100644
--- a/doc/user/basic.rst
+++ b/doc/user/basic.rst
@@ -349,6 +349,10 @@ Basic Config Commands
Allow using IPv4 reserved (Class E) IP ranges for daemons. E.g.: setting
IPv4 addresses for interfaces or allowing reserved ranges in BGP next-hops.
+ If you need multiple FRR instances (or FRR + any other daemon) running in a
+ single router and peering via 127.0.0.0/8, it's also possible to use this
+ knob if turned on.
+
Default: off.
.. _sample-config-file:
diff --git a/doc/user/bgp.rst b/doc/user/bgp.rst
index 1798f1ad2a..97d7ce6b75 100644
--- a/doc/user/bgp.rst
+++ b/doc/user/bgp.rst
@@ -2290,7 +2290,7 @@ Numbered Community Lists
^^^^^^^^^^^^^^^^^^^^^^^^
When number is used for BGP community list name, the number has
-special meanings. Community list number in the range from 1 and 99 is
+special meanings. Community list number in the range from 1 to 99 is
standard community list. Community list number in the range from 100
to 500 is expanded community list. These community lists are called
as numbered community lists. On the other hand normal community lists
@@ -2767,6 +2767,17 @@ happened automatically if local-role is set.
value of his role (by setting local-role on his side). Otherwise, a Role
Mismatch Notification will be sent.
+Labeled unicast
+---------------
+
+*bgpd* supports labeled information, as per :rfc:`3107`.
+
+.. clicmd:: bgp labeled-unicast explicit-null
+
+By default, locally advertised prefixes use the `implicit-null` label to
+encode in the outgoing NLRI. The following command uses the `explicit-null`
+label value for all the BGP instances.
+
.. _bgp-l3vpn-vrfs:
L3VPN VRFs
diff --git a/doc/user/index.rst b/doc/user/index.rst
index 8b9b7e5af7..c02d10deda 100644
--- a/doc/user/index.rst
+++ b/doc/user/index.rst
@@ -66,6 +66,7 @@ Protocols
vrrp
bmp
watchfrr
+ mgmtd
########
Appendix
diff --git a/doc/user/isisd.rst b/doc/user/isisd.rst
index 055841d230..88fa78ddfa 100644
--- a/doc/user/isisd.rst
+++ b/doc/user/isisd.rst
@@ -68,6 +68,10 @@ writing, *isisd* does not support multiple ISIS processes.
Log changes in adjacency state.
+.. clicmd:: log-pdu-drops
+
+ Log any dropped PDUs.
+
.. clicmd:: metric-style [narrow | transition | wide]
Set old-style (ISO 10589) or new-style packet formats:
@@ -212,6 +216,10 @@ ISIS interface
Add padding to IS-IS hello packets.
+.. clicmd:: isis hello padding during-adjacency-formation
+
+ Add padding to IS-IS hello packets during adjacency formation only.
+
.. clicmd:: isis hello-interval (1-600) [level-1 | level-2]
Set Hello interval in seconds globally, for an area (level-1) or a domain
diff --git a/doc/user/mgmtd.rst b/doc/user/mgmtd.rst
new file mode 100644
index 0000000000..6614a568f8
--- /dev/null
+++ b/doc/user/mgmtd.rst
@@ -0,0 +1,366 @@
+.. _mgmtd:
+
+*************************
+MGMTd (Management Daemon)
+*************************
+
+The FRR Management Daemon (from now on referred to as MGMTd) is a new
+centralized entity representing the FRR Management Plane which can take
+management requests from any kind of UI/Frontend entity (e.g. CLI, Netconf,
+Restconf, Grpc etc.) over a new unified and common Frontend interface and
+can help maintain configurational data or retrieve operational data from
+any number of FRR managed entities/components that have been integrated
+with the new FRR Centralised Management Framework.
+
+For organizing the management data to be owned by the FRR Management plane,
+management data is stored in YANG in compliance with a pre-defined set
+of YANG based schema. Data shall also be stored/retrieved in YANG format only.
+
+The MGMTd also acts as a separate computational entity for offloading much
+of the management related computational overload involved in maintaining of
+management data and processing of management requests, from individual
+component daemons (which can otherwise be a signficant burden on the individual
+components, affecting performance of its other functionalities).
+
+Lastly, the MGMTd works in-tandem with one (or more) MGMT Frontend
+Clients and a bunch of MGMT Backend Clients to realize the entirety
+of the FRR Management plane. Some of the advanatages of this new framework
+are:
+
+ 1. Consolidation and management of all Management data by a single entity.
+ 2. Better control over configuration validation, commit and rollback.
+ 3. Faster collection of configuration data (without needing to involve
+ individual component daemons).
+ 4. Offload computational burden of YANG data parsing and validations
+ of new configuration data being provisoned away from individual
+ component daemons
+ 5. Improve performance of individual component daemons while loading
+ huge configuration or retrieving huge operational dataset.
+
+The new FRR Management Daemon consists of the following sub-components:
+ - MGMT Frontend Interface
+ - MGMT Backend Interface
+ - MGMT Transaction Engine
+
+.. _mgmt_fe:
+
+MGMT Frontend Interface
+=======================
+
+The MGMT Frontend Interface is a bunch of message-based APIs that lets
+any UI/Frontend client to interact with the MGMT daemon to requests a
+set of management operations on a specific datastore/database.
+Following is a list of databases/datastores supported by the MGMT
+Frontend Interface and MGMTd:
+
+ - Candidate Database:
+
+ - Consists of configuration data items only.
+ - Data can be edited anytime using SET_CONFIG API.
+ - Data can be retrieved anytime using GET_CONFIG/GET_DATA API.
+
+ - Running Database:
+
+ - Consists of configuration data items only.
+ - Data cannot be edited using SET_CONFIG API.
+ - Data can only be modified using COMMIT_CONFIG API after which un-committed
+ data from Candidate database will be first validated and applied to
+ individualBackend component(s). Only on successful validation and apply on
+ all individual components will the new data be copied over to the Running
+ database.
+ - Data can be retrieved anytime using GET_CONFIG/GET_DATA API.
+
+ - Operational Database:
+
+ - Consists of non-configurational data items.
+ - Data is not stored on MGMT daemon. Rather it will be need to be fetched
+ in real-time from the corresponding Backend component (if present).
+ - Data can be retrieved anytime using GET_DATA API.
+
+Frontend Clients connected to MGMTd via Frontend Interface can themselves have
+multiple connections from one (or more) of its own remote clients. The MGMT
+Frontend Interface supports reresenting each of the remote clients for a given
+Frontend client(e.g. Netconf clients on a single Netconf server) as individual
+Frontend Client Sessions. So a single connection from a single Frontend Client
+can create more than one Frontend Client sessions.
+
+Following are some of the management operations supported:
+ - INIT_SESSION/CLOSE_SESSION: Create/Destroy a session. Rest of all the
+ operations are supported only in the context of a specific session.
+ - LOCK_DB/UNLOCK_DB: Lock/Unlock Management datastores/databases.
+ - GET_CONFIG/GET_DATA: Retrieve configurational/operational data from a
+ specific datastore/database.
+ - SET_CONFIG/DELETE_CONFIG: Add/Modify/Delete specific data in a specific
+ datastore/database.
+ - COMMIT_CONFIG: Validate and/or apply the uncommited set of configurations
+ from one configuration database to another.
+ - Currently committing configurations from Candidate to Running database
+ is only allowed, and not vice versa.
+
+The exact set of message-based APIs are represented as Google Protobuf
+messages and can be found in the following file distributed with FRR codebase.
+
+.. code-block:: frr
+
+ lib/mgmt.proto
+
+The MGMT daemon implements a MGMT Frontend Server that opens a UNIX
+socket-based IPC channel on the following path to listen for incoming
+connections from all possible Frontend clients:
+
+.. code-block:: frr
+
+ /var/run/frr/mgmtd_fe.sock
+
+Each connection received from a Frontend client is managed and tracked
+as a MGMT Frontend adapter by the MGMT Frontend Adapter sub-component
+implemented by MGMTd.
+
+To facilitate faster development/integration of Frontend clients with
+MGMT Frontend Interface, a C-based library has been developed. The API
+specification of this library can be found at:
+
+.. code-block:: frr
+
+ lib/mgmt_fe_client.h
+
+Following is a list of message types supported on the MGMT Frontend Interface:
+ - SESSION_REQ<Client-Connection-Id, Destroy>
+ - SESSION_REPLY<Client-Connection-Id, Destroy, Session-Id>
+ - LOCK_DB_REQ <Session-Id, Database-Id>
+ - LOCK_DB_REPLY <Session-Id, Database-Id>
+ - UNLOCK_DB_REQ <Session-Id, Database-Id>
+ - UNLOCK_DB_REPLY <Session-Id, Database-Id>
+ - GET_CONFIG_REQ <Session-Id, Database-Id, Base-Yang-Xpath>
+ - GET_CONFIG_REPLY <Session-Id, Database-Id, Base-Yang-Xpath, Yang-Data-Set>
+ - SET_CONFIG_REQ <Session-Id, Database-Id, Base-Yang-Xpath, Delete, ...>
+ - SET_CONFIG_REPLY <Session-Id, Database-id, Base-Yang-Xpath, ..., Status>
+ - COMMIT_CONFIG_REQ <Session-Id, Source-Db-Id, Dest-Db-Id>
+ - COMMIT_CONFIG_REPLY <Session-Id, Source-Db-id, Dest-Db-Id, Status>
+ - GET_DATA_REQ <Session-Id, Database-Id, Base-Yang-Xpath>
+ - GET_DATA_REPLY <Session-Id, Database-id, Base-Yang-Xpath, Yang-Data-Set>
+ - REGISTER_NOTIFY_REQ <Session-Id, Database-Id, Base-Yang-Xpath>
+ - DATA_NOTIFY_REQ <Database-Id, Base-Yang-Xpath, Yang-Data-Set>
+
+Please refer to the MGMT Frontend Client Developers Reference and Guide
+(coming soon) for more details.
+
+MGMTD Backend Interface
+=======================
+The MGMT Backend Interface is a bunch of message-based APIs that can be
+used by individual component daemons like BGPd, Staticd, Zebra to connect
+with MGMTd and utilize the new FRR Management Framework to let any Frontend
+clients to retrieve any operational data or manipulate any configuration data
+owned by the individual daemon component.
+
+Like the MGMT Frontend Interface, the MGMT Backend Interface is is also
+comprised of the following:
+
+ - MGMT Backend Server (running on MGMT daemon)
+ - MGMT Backend Adapter (running on MGMT daemon)
+ - MGMT Backend client (running on Backend component daemons)
+
+The MGMT Backend Client and MGMT Backend Adapter sub-component communicates
+using a specific set of message-based APIs.
+
+The exact set of message-based APIs are represented as Google Protobuf
+messages and can be found in the following file distributed with FRR codebase.
+
+.. code-block:: frr
+
+ lib/mgmt.proto
+
+The MGMT daemon implements a MGMT Backend Server that opens a UNIX
+socket-based IPC channel on the following path to listen for incoming
+connections from all possible Backend clients:
+
+.. code-block:: frr
+
+ /var/run/frr/mgmtd_be.sock
+
+Each connection received from a Backend client is managed and tracked
+as a MGMT Backend adapter by the MGMT Backend Adapter sub-component
+implemented by MGMTd.
+
+To facilitate faster development/integration of Backend clients with
+MGMTd, a C-based library has been developed. The API specification
+of this library can be found at:
+
+.. code-block:: frr
+
+ lib/mgmt_be_client.h
+
+Following is a list of message types supported on the MGMT Backend Interface:
+
+ - SUBSCRIBE_REQ <Req-Id, Base-Yang-Xpath, Filter-Type>
+ - SUBSCRIBE_REPLY <Req-Id, Status>
+ - TXN_REQ <Txn-Id, Create>
+ - TXN_REPLY <Txn-Id, Status>
+ - CREATE_CFGDATA_REQ <Txn-Id, Req-Id, Batch-Id, ConfigDataContents>
+ - CREATE_CFGDATA_ERROR <Txn-Id, Req-Id, Batch-Id, Status>
+ - VALIDATE_CFGDATA_REQ <Txn-Id, Batch-Id>
+ - VALIDATE_CFGDATA_REPLY <Txn-Id, Batch-Id, Status, ErrorInfo>
+ - APPLY_CFGDATA_REQ <Txn-Id, Batch-Id>
+ - APPLY_CFGDATA_REPLY <Txn-Id, Batch-Id, Status, ErrorInfo>
+ - GET_OPERDATA_REQ <Txn-Id, Base-Yang-Xpath, Filter-Type>
+ - GET_OPERDATA_REPLY <Txn-Id, OperDataContents>
+
+Please refer to the MGMT Backend Client Developers Reference and Guide
+(coming soon) for more details.
+
+MGMTD Transaction Engine
+========================
+
+The MGMT Transaction sub-component is the main brain of the MGMT daemon that
+takes management requests from one (or more) Frontend Client translates
+them into transactions and drives them to completion in co-oridination with
+one (or more) Backend client daemons involved in the request.
+
+A transaction can be seen as a set of management procedures executed over
+the Backend Interface with one (or more) individual Backend component
+daemons, as a result of some management request initiated from a specific
+Frontend client session. These group of operations on the Backend Interface
+with one (or more) individual components involved should be executed without
+taking any further management requests from other Frontend client sessions.
+To maintain this kind of atomic behavior a lock needs to be acquired
+(sometimes implicitly if not explicitly) by the corresponding Frontend client
+session, on the various datastores/databases involved in the management request
+being executed. The same datastores/databases need to be unlocked when all
+the procedures have been executed and the transaction is being closed.
+
+Following are some of the transaction types supported by MGMT:
+
+ - Configuration Transactions
+
+ - Used to execute management operations like SET_CONFIG and COMMIT_CONFIG
+ that involve writing/over-writing the contents of Candidate and Running
+ databases.
+ - One (and only) can be created and be in-progress at any given time.
+ - Once initiated by a specific Frontend Client session and is still
+ in-progress, all subsequent SET_CONFIG and COMMIT_CONFIG operations
+ from other Frontend Client sessions will be rejected and responded
+ with failure.
+ - Requires acquiring write-lock on Candidate (and later Running) databases.
+
+ - Show Transactions
+
+ - Used to execute management operations like GET_CONFIG and GET_DATA
+ that involve only reading the contents of Candidate and Running
+ databases (and sometimes real-time retrieval of operational data
+ from individual component daemons).
+ - Multiple instance of this transaction type can be created and be
+ in-progress at any given time.
+ - However, when a configuration transaction is currently in-progress
+ show transaction can be initiated by any Frontend Client session.
+ - Requires acquiring read-lock on Candidate and/or Running databases.
+ - NOTE: Currently GET_DATA on Operational database is NOT supported. To
+ be added in a future time soon.
+
+MGMTD Configuration Rollback and Commit History
+===============================================
+
+The MGMT daemon maintains upto 10 last configuration commit buffers
+and can rollback the contents of the Running Database to any of the
+commit-ids maintained in the commit buffers.
+
+Once the number of commit buffers exceeds 10, the oldest commit
+buffer is deleted to make space for the latest commit. Also on
+rollback to a specific commit-id, buffer of all the later commits
+are deleted from commit record.
+
+Configuration rollback is only allowed via VTYSH shell as of today
+and is not possible through the MGMT Frontend interface.
+
+MGMT Configuration commands
+===========================
+
+.. clicmd:: mgmt set-config XPATH VALUE
+
+ This command uses a SET_CONFIG request over the MGMT Frontend Interface
+ for the specified xpath with specific value. This command is used for
+ testing purpose only. But can be used to set configuration data from CLI
+ using SET_CONFIG operations.
+
+.. clicmd:: mgmt delete-config XPATH
+
+ This command uses a SET_CONFIG request (with delete option) over the
+ MGMT Frontend Interface o delete the YANG data node at the given
+ xpath unless it is a key-leaf node(in which case it is not deleted).
+
+.. clicmd:: mgmt load-config FILE <merge|replace>
+
+ This command loads configuration in JSON format from the filepath specified,
+ and merges or replaces the Candidate DB as per the option specified.
+
+.. clicmd:: mgmt save-config <candidate|running> FILE
+
+ This command dumps the DB specified in the db-name into the file in JSON
+ format. This command in not supported for the Operational DB.
+
+.. clicmd:: mgmt commit abort
+
+ This command will abort any configuration present on the Candidate but not
+ been applied to the Running DB.
+
+.. clicmd:: mgmt commit apply
+
+ This command commits any uncommited changes in the Candidate DB to the
+ Running DB.
+
+.. clicmd:: mgmt commit check
+
+ This command validates the configuration but does not apply them to the
+ Running DB.
+
+.. clicmd:: mgmt rollback commit-id WORD
+
+ This command rolls back the Running Database contents to the state
+ corresponding to the commit-id specified.
+
+.. clicmd:: mgmt rollback last WORD
+
+ This command rolls back the last specified number of recent commits.
+
+
+MGMT Show commands
+==================
+
+.. clicmd:: show mgmt backend-adapter all
+
+ This command shows the backend adapter information and the clients/daemons
+ connected to the adapters.
+
+.. clicmd:: show mgmt backend-yang-xpath-registry
+
+ This command shows which Backend adapters are registered for which YANG
+ data subtree(s).
+
+.. clicmd:: show mgmt frontend-adapter all [detail]
+
+ This command shows the frontend adapter information and the clients
+ connected to the adapters.
+
+.. clicmd:: show mgmt transaction all
+
+ Shows the list of transaction and bunch of information about the transaction.
+
+.. clicmd:: show mgmt get-config [candidate|running] XPATH
+
+ This command uses the GET_CONFIG operation over the MGMT Frontend interface and
+ returns the xpaths and values of the nodes of the subtree pointed by the <xpath>.
+
+.. clicmd:: show mgmt get-data [candidate|operation|running] XPATH
+
+ This command uses the GET_DATA operation over the MGMT Frontend interface and
+ returns the xpaths and values of the nodes of the subtree pointed by the <xpath>.
+ Currenlty supported values for 'candidate' and 'running' only
+ ('operational' shall be supported in future soon).
+
+.. clicmd:: show mgmt database-contents [candidate|operation|running] [xpath WORD] [file WORD] json|xml
+
+ This command dumps the subtree pointed by the xpath in JSON or XML format. If filepath is
+ not present then the tree will be printed on the shell.
+
+.. clicmd:: show mgmt commit-history
+
+ This command dumps details of upto last 10 commits handled by MGMTd.
diff --git a/doc/user/ospfd.rst b/doc/user/ospfd.rst
index ce3648bf6d..a99785204b 100644
--- a/doc/user/ospfd.rst
+++ b/doc/user/ospfd.rst
@@ -310,6 +310,11 @@ To start OSPF process you have to specify the OSPF router.
of packets to process before returning. The defult value of this parameter
is 20.
+.. clicmd:: socket buffer <send | recv | all> (1-4000000000)
+
+ This command controls the ospf instance's socket buffer sizes. The
+ 'no' form resets one or both values to the default.
+
.. _ospf-area:
Areas
@@ -325,7 +330,6 @@ Areas
announced to other areas. This command can be used only in ABR and ONLY
router-LSAs (Type-1) and network-LSAs (Type-2) (i.e. LSAs with scope area) can
be summarized. Type-5 AS-external-LSAs can't be summarized - their scope is AS.
- Summarizing Type-7 AS-external-LSAs isn't supported yet by FRR.
.. code-block:: frr
@@ -431,6 +435,31 @@ Areas
configured not to advertise forwarding addresses into the backbone to direct
forwarded traffic to the NSSA ABR translator.
+.. clicmd:: area A.B.C.D nssa default-information-originate [metric-type (1-2)] [metric (0-16777214)]
+
+.. clicmd:: area (0-4294967295) nssa default-information-originate [metric-type (1-2)] [metric (0-16777214)]
+
+ NSSA ABRs and ASBRs can be configured with the `default-information-originate`
+ option to originate a Type-7 default route into the NSSA area. In the case
+ of NSSA ASBRs, the origination of the default route is conditioned to the
+ existence of a default route in the RIB that wasn't learned via the OSPF
+ protocol.
+
+.. clicmd:: area A.B.C.D nssa range A.B.C.D/M [<not-advertise|cost (0-16777215)>]
+
+.. clicmd:: area (0-4294967295) nssa range A.B.C.D/M [<not-advertise|cost (0-16777215)>]
+
+ Summarize a group of external subnets into a single Type-7 LSA, which is
+ then translated to a Type-5 LSA and avertised to the backbone.
+ This command can only be used at the area boundary (NSSA ABR router).
+
+ By default, the metric of the summary route is calculated as the highest
+ metric among the summarized routes. The `cost` option, however, can be used
+ to set an explicit metric.
+
+ The `not-advertise` option, when present, prevents the summary route from
+ being advertised, effectively filtering the summarized routes.
+
.. clicmd:: area A.B.C.D default-cost (0-16777215)
@@ -806,25 +835,23 @@ Showing Information
Json o/p of this command covers base route information
i.e all LSAs except opaque lsa info.
-.. clicmd:: show ip ospf [vrf <NAME|all>] database [json]
+.. clicmd:: show ip ospf [vrf <NAME|all>] database [self-originate] [json]
-.. clicmd:: show ip ospf [vrf <NAME|all>] database (asbr-summary|external|network|router|summary) [json]
-
-.. clicmd:: show ip ospf [vrf <NAME|all>] database (asbr-summary|external|network|router|summary) LINK-STATE-ID [json]
+ Show the OSPF database summary.
-.. clicmd:: show ip ospf [vrf <NAME|all>] database (asbr-summary|external|network|router|summary) LINK-STATE-ID adv-router ADV-ROUTER [json]
+.. clicmd:: show ip ospf [vrf <NAME|all>] database max-age [json]
-.. clicmd:: show ip ospf [vrf <NAME|all>] database (asbr-summary|external|network|router|summary) adv-router ADV-ROUTER [json]
+ Show all MaxAge LSAs present in the OSPF link-state database.
-.. clicmd:: show ip ospf [vrf <NAME|all>] database (asbr-summary|external|network|router|summary) LINK-STATE-ID self-originate [json]
+.. clicmd:: show ip ospf [vrf <NAME|all>] database detail [LINK-STATE-ID] [adv-router A.B.C.D] [json]
-.. clicmd:: show ip ospf [vrf <NAME|all>] database (asbr-summary|external|network|router|summary) self-originate [json]
+.. clicmd:: show ip ospf [vrf <NAME|all>] database detail [LINK-STATE-ID] [self-originate] [json]
-.. clicmd:: show ip ospf [vrf <NAME|all>] database max-age [json]
+.. clicmd:: show ip ospf [vrf <NAME|all>] database (asbr-summary|external|network|router|summary|nssa-external|opaque-link|opaque-area|opaque-as) [LINK-STATE-ID] [adv-router A.B.C.D] [json]
-.. clicmd:: show ip ospf [vrf <NAME|all>] database self-originate [json]
+.. clicmd:: show ip ospf [vrf <NAME|all>] database (asbr-summary|external|network|router|summary|nssa-external|opaque-link|opaque-area|opaque-as) [LINK-STATE-ID] [self-originate] [json]
- Show the OSPF database summary.
+ Show detailed information about the OSPF link-state database.
.. clicmd:: show ip ospf route [json]
diff --git a/doc/user/overview.rst b/doc/user/overview.rst
index 4a24fa52be..5ea33d62c9 100644
--- a/doc/user/overview.rst
+++ b/doc/user/overview.rst
@@ -424,6 +424,8 @@ BGP
:t:`Extended Optional Parameters Length for BGP OPEN Message. E. Chen, J. Scudder. July 2021.`
- :rfc:`9234`
:t:`Route Leak Prevention and Detection Using Roles in UPDATE and OPEN Messages. A. Azimov, E. Bogomazov, R. Bush, K. Patel, K. Sriram. May 2022.`
+- :rfc:`9384`
+ :t:`A BGP Cease NOTIFICATION Subcode for Bidirectional Forwarding Detection (BFD). J. Haas. March 2023.`
OSPF
----
diff --git a/doc/user/routemap.rst b/doc/user/routemap.rst
index c205122b0b..9e4d7a611a 100644
--- a/doc/user/routemap.rst
+++ b/doc/user/routemap.rst
@@ -294,9 +294,9 @@ Route Map Set Command
Subtract the BGP local preference from an existing `local_pref`.
-.. clicmd:: set distance DISTANCE
+.. clicmd:: set distance (1-255)
- Set the Administrative distance to DISTANCE to use for the route.
+ Set the Administrative distance to use for the route.
This is only locally significant and will not be dispersed to peers.
.. clicmd:: set weight WEIGHT
diff --git a/doc/user/subdir.am b/doc/user/subdir.am
index b8c5c70d9c..4879f7f7ef 100644
--- a/doc/user/subdir.am
+++ b/doc/user/subdir.am
@@ -54,6 +54,7 @@ user_RSTFILES = \
doc/user/flowspec.rst \
doc/user/watchfrr.rst \
doc/user/wecmp_linkbw.rst \
+ doc/user/mgmtd.rst \
# end
EXTRA_DIST += \
diff --git a/docker/alpine/Dockerfile b/docker/alpine/Dockerfile
index afc6be2312..54621a49fd 100644
--- a/docker/alpine/Dockerfile
+++ b/docker/alpine/Dockerfile
@@ -25,6 +25,7 @@ RUN source /src/alpine/APKBUILD.in \
gzip \
py-pip \
rtrlib \
+ protobuf-c-dev \
&& pip install pytest
RUN mkdir -p /pkgs/apk
COPY . /src
diff --git a/docker/centos-7/Dockerfile b/docker/centos-7/Dockerfile
index 2d1ee9efa4..8739cee09b 100644
--- a/docker/centos-7/Dockerfile
+++ b/docker/centos-7/Dockerfile
@@ -5,6 +5,7 @@ RUN yum install -y rpm-build autoconf automake libtool make \
readline-devel texinfo net-snmp-devel groff pkgconfig \
json-c-devel pam-devel bison flex pytest c-ares-devel \
python3-devel python3-sphinx libcap-devel systemd-devel \
+ protobuf-c-devel \
https://ci1.netdef.org/artifact/LIBYANG-LIBYANGV2/shared/build-2/CentOS-7-x86_64-Packages/libyang2-2.0.0.10.g2eb910e4-1.el7.x86_64.rpm \
https://ci1.netdef.org/artifact/LIBYANG-LIBYANGV2/shared/build-2/CentOS-7-x86_64-Packages/libyang2-devel-2.0.0.10.g2eb910e4-1.el7.x86_64.rpm \
https://ci1.netdef.org/artifact/RPKI-RTRLIB/shared/build-00146/CentOS-7-x86_64-Packages/librtr-0.8.0-1.el7.x86_64.rpm \
diff --git a/docker/centos-8/Dockerfile b/docker/centos-8/Dockerfile
index df772b8318..88a7d6a007 100644
--- a/docker/centos-8/Dockerfile
+++ b/docker/centos-8/Dockerfile
@@ -9,6 +9,7 @@ RUN dnf install --enablerepo=powertools -y rpm-build git autoconf pcre-devel \
automake libtool make readline-devel texinfo net-snmp-devel pkgconfig \
groff pkgconfig json-c-devel pam-devel bison flex python3-pytest \
c-ares-devel python3-devel python3-sphinx libcap-devel platform-python-devel \
+ protobuf-c-devel \
https://ci1.netdef.org/artifact/LIBYANG-LIBYANGV2/shared/build-2/CentOS-8-x86_64-Packages/libyang2-2.0.0.10.g2eb910e4-1.el8.x86_64.rpm \
https://ci1.netdef.org/artifact/LIBYANG-LIBYANGV2/shared/build-2/CentOS-8-x86_64-Packages/libyang2-devel-2.0.0.10.g2eb910e4-1.el8.x86_64.rpm \
https://ci1.netdef.org/artifact/RPKI-RTRLIB/shared/build-00146/CentOS-7-x86_64-Packages/librtr-0.8.0-1.el7.x86_64.rpm \
diff --git a/docker/debian/Dockerfile b/docker/debian/Dockerfile
index 7476e5fe3e..d136538c7d 100644
--- a/docker/debian/Dockerfile
+++ b/docker/debian/Dockerfile
@@ -7,7 +7,7 @@ ENV APT_KEY_DONT_WARN_ON_DANGEROUS_USAGE=DontWarn
RUN apt-get update && \
apt-get install -y libpcre3-dev apt-transport-https ca-certificates curl wget logrotate \
libc-ares2 libjson-c3 vim procps libreadline7 gnupg2 lsb-release apt-utils \
- tini && rm -rf /var/lib/apt/lists/*
+ libprotobuf-c-dev protobuf-c-compiler tini && rm -rf /var/lib/apt/lists/*
RUN curl -s https://deb.frrouting.org/frr/keys.asc | apt-key add -
RUN echo deb https://deb.frrouting.org/frr $(lsb_release -s -c) frr-stable | tee -a /etc/apt/sources.list.d/frr.list
diff --git a/docker/ubuntu18-ci/Dockerfile b/docker/ubuntu18-ci/Dockerfile
index 07a5a2f7e0..dab8606739 100644
--- a/docker/ubuntu18-ci/Dockerfile
+++ b/docker/ubuntu18-ci/Dockerfile
@@ -9,7 +9,7 @@ RUN apt update && \
pkg-config libpam0g-dev libjson-c-dev bison flex python3-pip \
libc-ares-dev python3-dev python3-sphinx \
install-info build-essential libsnmp-dev perl libcap-dev \
- libelf-dev \
+ libelf-dev libprotobuf-c-dev protobuf-c-compiler \
sudo gdb iputils-ping time \
python-pip net-tools iproute2 && \
python3 -m pip install wheel && \
diff --git a/docker/ubuntu20-ci/Dockerfile b/docker/ubuntu20-ci/Dockerfile
index b9fe385c3a..7e49910a72 100644
--- a/docker/ubuntu20-ci/Dockerfile
+++ b/docker/ubuntu20-ci/Dockerfile
@@ -9,7 +9,7 @@ RUN apt update && \
pkg-config libpam0g-dev libjson-c-dev bison flex python3-pip \
libc-ares-dev python3-dev python3-sphinx \
install-info build-essential libsnmp-dev perl \
- libcap-dev python2 libelf-dev \
+ libcap-dev python2 libelf-dev libprotobuf-c-dev protobuf-c-compiler \
sudo gdb curl iputils-ping time \
lua5.3 liblua5.3-dev \
net-tools iproute2 && \
diff --git a/eigrpd/eigrp_dump.c b/eigrpd/eigrp_dump.c
index 489b3bd1c5..2ebabd0efa 100644
--- a/eigrpd/eigrp_dump.c
+++ b/eigrpd/eigrp_dump.c
@@ -13,7 +13,7 @@
#include <zebra.h>
#include "linklist.h"
-#include "thread.h"
+#include "frrevent.h"
#include "prefix.h"
#include "command.h"
#include "stream.h"
@@ -192,7 +192,7 @@ void show_ip_eigrp_neighbor_sub(struct vty *vty, struct eigrp_neighbor *nbr,
vty_out(vty, "%-3u %-17pI4 %-21s", 0, &nbr->src, IF_NAME(nbr->ei));
if (nbr->t_holddown)
vty_out(vty, "%-7lu",
- thread_timer_remain_second(nbr->t_holddown));
+ event_timer_remain_second(nbr->t_holddown));
else
vty_out(vty, "- ");
vty_out(vty, "%-8u %-6u %-5u", 0, 0, EIGRP_PACKET_RETRANS_TIME);
diff --git a/eigrpd/eigrp_filter.c b/eigrpd/eigrp_filter.c
index 09ae6be6dc..eceef6b8a7 100644
--- a/eigrpd/eigrp_filter.c
+++ b/eigrpd/eigrp_filter.c
@@ -21,7 +21,7 @@
#include "command.h"
#include "prefix.h"
#include "table.h"
-#include "thread.h"
+#include "frrevent.h"
#include "memory.h"
#include "log.h"
#include "stream.h"
@@ -111,11 +111,11 @@ void eigrp_distribute_update(struct distribute_ctx *ctx,
// TODO: check Graceful restart after 10sec
/* cancel GR scheduled */
- thread_cancel(&(e->t_distribute));
+ event_cancel(&(e->t_distribute));
/* schedule Graceful restart for whole process in 10sec */
- thread_add_timer(master, eigrp_distribute_timer_process, e,
- (10), &e->t_distribute);
+ event_add_timer(master, eigrp_distribute_timer_process, e, (10),
+ &e->t_distribute);
return;
}
@@ -186,10 +186,10 @@ void eigrp_distribute_update(struct distribute_ctx *ctx,
// TODO: check Graceful restart after 10sec
/* Cancel GR scheduled */
- thread_cancel(&(ei->t_distribute));
+ event_cancel(&(ei->t_distribute));
/* schedule Graceful restart for interface in 10sec */
- thread_add_timer(master, eigrp_distribute_timer_interface, ei, 10,
- &ei->t_distribute);
+ event_add_timer(master, eigrp_distribute_timer_interface, ei, 10,
+ &ei->t_distribute);
}
/*
@@ -242,11 +242,11 @@ void eigrp_distribute_update_all_wrapper(struct access_list *notused)
* Called when 10sec waiting time expire and
* executes Graceful restart for whole process
*/
-void eigrp_distribute_timer_process(struct thread *thread)
+void eigrp_distribute_timer_process(struct event *thread)
{
struct eigrp *eigrp;
- eigrp = THREAD_ARG(thread);
+ eigrp = EVENT_ARG(thread);
/* execute GR for whole process */
eigrp_update_send_process_GR(eigrp, EIGRP_GR_FILTER, NULL);
@@ -263,11 +263,11 @@ void eigrp_distribute_timer_process(struct thread *thread)
* Called when 10sec waiting time expire and
* executes Graceful restart for interface
*/
-void eigrp_distribute_timer_interface(struct thread *thread)
+void eigrp_distribute_timer_interface(struct event *thread)
{
struct eigrp_interface *ei;
- ei = THREAD_ARG(thread);
+ ei = EVENT_ARG(thread);
ei->t_distribute = NULL;
/* execute GR for interface */
diff --git a/eigrpd/eigrp_filter.h b/eigrpd/eigrp_filter.h
index 493ba08f7d..dc8af8f535 100644
--- a/eigrpd/eigrp_filter.h
+++ b/eigrpd/eigrp_filter.h
@@ -23,7 +23,7 @@ extern void eigrp_distribute_update(struct distribute_ctx *ctx,
extern void eigrp_distribute_update_interface(struct interface *ifp);
extern void eigrp_distribute_update_all(struct prefix_list *plist);
extern void eigrp_distribute_update_all_wrapper(struct access_list *alist);
-extern void eigrp_distribute_timer_process(struct thread *thread);
-extern void eigrp_distribute_timer_interface(struct thread *thread);
+extern void eigrp_distribute_timer_process(struct event *thread);
+extern void eigrp_distribute_timer_interface(struct event *thread);
#endif /* EIGRPD_EIGRP_FILTER_H_ */
diff --git a/eigrpd/eigrp_fsm.c b/eigrpd/eigrp_fsm.c
index d065af0cb9..6d8061e572 100644
--- a/eigrpd/eigrp_fsm.c
+++ b/eigrpd/eigrp_fsm.c
@@ -53,8 +53,8 @@
*/
#include <zebra.h>
-#include <thread.h>
+#include "frrevent.h"
#include "prefix.h"
#include "table.h"
#include "memory.h"
diff --git a/eigrpd/eigrp_hello.c b/eigrpd/eigrp_hello.c
index f62f54b680..662c750e96 100644
--- a/eigrpd/eigrp_hello.c
+++ b/eigrpd/eigrp_hello.c
@@ -16,7 +16,7 @@
#include <zebra.h>
-#include "thread.h"
+#include "frrevent.h"
#include "memory.h"
#include "linklist.h"
#include "prefix.h"
@@ -66,11 +66,11 @@ static const struct message eigrp_general_tlv_type_str[] = {
* Sends hello packet via multicast for all interfaces eigrp
* is configured for
*/
-void eigrp_hello_timer(struct thread *thread)
+void eigrp_hello_timer(struct event *thread)
{
struct eigrp_interface *ei;
- ei = THREAD_ARG(thread);
+ ei = EVENT_ARG(thread);
if (IS_DEBUG_EIGRP(0, TIMERS))
zlog_debug("Start Hello Timer (%s) Expire [%u]", IF_NAME(ei),
@@ -80,8 +80,8 @@ void eigrp_hello_timer(struct thread *thread)
eigrp_hello_send(ei, EIGRP_HELLO_NORMAL, NULL);
/* Hello timer set. */
- thread_add_timer(master, eigrp_hello_timer, ei, ei->params.v_hello,
- &ei->t_hello);
+ event_add_timer(master, eigrp_hello_timer, ei, ei->params.v_hello,
+ &ei->t_hello);
}
/**
@@ -726,8 +726,8 @@ void eigrp_hello_send_ack(struct eigrp_neighbor *nbr)
listnode_add(nbr->ei->eigrp->oi_write_q, nbr->ei);
nbr->ei->on_write_q = 1;
}
- thread_add_write(master, eigrp_write, nbr->ei->eigrp,
- nbr->ei->eigrp->fd, &nbr->ei->eigrp->t_write);
+ event_add_write(master, eigrp_write, nbr->ei->eigrp,
+ nbr->ei->eigrp->fd, &nbr->ei->eigrp->t_write);
}
}
@@ -771,12 +771,12 @@ void eigrp_hello_send(struct eigrp_interface *ei, uint8_t flags,
if (ei->eigrp->t_write == NULL) {
if (flags & EIGRP_HELLO_GRACEFUL_SHUTDOWN) {
- thread_execute(master, eigrp_write, ei->eigrp,
- ei->eigrp->fd);
+ event_execute(master, eigrp_write, ei->eigrp,
+ ei->eigrp->fd);
} else {
- thread_add_write(master, eigrp_write, ei->eigrp,
- ei->eigrp->fd,
- &ei->eigrp->t_write);
+ event_add_write(master, eigrp_write, ei->eigrp,
+ ei->eigrp->fd,
+ &ei->eigrp->t_write);
}
}
}
diff --git a/eigrpd/eigrp_interface.c b/eigrpd/eigrp_interface.c
index 8d98dcf5a1..2381977dba 100644
--- a/eigrpd/eigrp_interface.c
+++ b/eigrpd/eigrp_interface.c
@@ -16,7 +16,7 @@
#include <zebra.h>
-#include "thread.h"
+#include "frrevent.h"
#include "linklist.h"
#include "prefix.h"
#include "if.h"
@@ -251,7 +251,7 @@ int eigrp_if_up(struct eigrp_interface *ei)
/* Set multicast memberships appropriately for new state. */
eigrp_if_set_multicast(ei);
- thread_add_event(master, eigrp_hello_timer, ei, (1), &ei->t_hello);
+ event_add_event(master, eigrp_hello_timer, ei, (1), &ei->t_hello);
/*Prepare metrics*/
metric.bandwidth = eigrp_bandwidth_to_scaled(ei->params.bandwidth);
@@ -333,7 +333,7 @@ int eigrp_if_down(struct eigrp_interface *ei)
return 0;
/* Shutdown packet reception and sending */
- THREAD_OFF(ei->t_hello);
+ EVENT_OFF(ei->t_hello);
eigrp_if_stream_unset(ei);
@@ -360,7 +360,7 @@ void eigrp_if_stream_unset(struct eigrp_interface *ei)
if (ei->on_write_q) {
listnode_delete(eigrp->oi_write_q, ei);
if (list_isempty(eigrp->oi_write_q))
- thread_cancel(&(eigrp->t_write));
+ event_cancel(&(eigrp->t_write));
ei->on_write_q = 0;
}
}
@@ -422,7 +422,7 @@ void eigrp_if_free(struct eigrp_interface *ei, int source)
struct eigrp *eigrp = ei->eigrp;
if (source == INTERFACE_DOWN_BY_VTY) {
- thread_cancel(&ei->t_hello);
+ event_cancel(&ei->t_hello);
eigrp_hello_send(ei, EIGRP_HELLO_GRACEFUL_SHUTDOWN, NULL);
}
diff --git a/eigrpd/eigrp_macros.h b/eigrpd/eigrp_macros.h
index b7cd22fee1..75f1d7e133 100644
--- a/eigrpd/eigrp_macros.h
+++ b/eigrpd/eigrp_macros.h
@@ -27,6 +27,6 @@
/* FSM macros*/
#define EIGRP_FSM_EVENT_SCHEDULE(I, E) \
- thread_add_event(master, eigrp_fsm_event, (I), (E))
+ event_add_event(master, eigrp_fsm_event, (I), (E))
#endif /* _ZEBRA_EIGRP_MACROS_H_ */
diff --git a/eigrpd/eigrp_main.c b/eigrpd/eigrp_main.c
index 3c1e5da340..6d7443b791 100644
--- a/eigrpd/eigrp_main.c
+++ b/eigrpd/eigrp_main.c
@@ -17,7 +17,7 @@
#include <lib/version.h>
#include "getopt.h"
-#include "thread.h"
+#include "frrevent.h"
#include "prefix.h"
#include "linklist.h"
#include "if.h"
@@ -76,7 +76,7 @@ struct zebra_privs_t eigrpd_privs = {
struct option longopts[] = {{0}};
/* Master of threads. */
-struct thread_master *master;
+struct event_loop *master;
/* Forward declaration of daemon info structure. */
static struct frr_daemon_info eigrpd_di;
diff --git a/eigrpd/eigrp_neighbor.c b/eigrpd/eigrp_neighbor.c
index 9288b0f1cd..25209c3bb3 100644
--- a/eigrpd/eigrp_neighbor.c
+++ b/eigrpd/eigrp_neighbor.c
@@ -20,7 +20,7 @@
#include "prefix.h"
#include "memory.h"
#include "command.h"
-#include "thread.h"
+#include "frrevent.h"
#include "stream.h"
#include "table.h"
#include "log.h"
@@ -164,19 +164,19 @@ void eigrp_nbr_delete(struct eigrp_neighbor *nbr)
eigrp_topology_neighbor_down(nbr->ei->eigrp, nbr);
/* Cancel all events. */ /* Thread lookup cost would be negligible. */
- thread_cancel_event(master, nbr);
+ event_cancel_event(master, nbr);
eigrp_fifo_free(nbr->multicast_queue);
eigrp_fifo_free(nbr->retrans_queue);
- THREAD_OFF(nbr->t_holddown);
+ EVENT_OFF(nbr->t_holddown);
if (nbr->ei)
listnode_delete(nbr->ei->nbrs, nbr);
XFREE(MTYPE_EIGRP_NEIGHBOR, nbr);
}
-void holddown_timer_expired(struct thread *thread)
+void holddown_timer_expired(struct event *thread)
{
- struct eigrp_neighbor *nbr = THREAD_ARG(thread);
+ struct eigrp_neighbor *nbr = EVENT_ARG(thread);
struct eigrp *eigrp = nbr->ei->eigrp;
zlog_info("Neighbor %pI4 (%s) is down: holding time expired", &nbr->src,
@@ -210,7 +210,7 @@ void eigrp_nbr_state_set(struct eigrp_neighbor *nbr, uint8_t state)
// hold time..
nbr->v_holddown = EIGRP_HOLD_INTERVAL_DEFAULT;
- THREAD_OFF(nbr->t_holddown);
+ EVENT_OFF(nbr->t_holddown);
/* out with the old */
if (nbr->multicast_queue)
@@ -252,24 +252,24 @@ void eigrp_nbr_state_update(struct eigrp_neighbor *nbr)
switch (nbr->state) {
case EIGRP_NEIGHBOR_DOWN: {
/*Start Hold Down Timer for neighbor*/
- // THREAD_OFF(nbr->t_holddown);
- // THREAD_TIMER_ON(master, nbr->t_holddown,
+ // EVENT_OFF(nbr->t_holddown);
+ // EVENT_TIMER_ON(master, nbr->t_holddown,
// holddown_timer_expired,
// nbr, nbr->v_holddown);
break;
}
case EIGRP_NEIGHBOR_PENDING: {
/*Reset Hold Down Timer for neighbor*/
- THREAD_OFF(nbr->t_holddown);
- thread_add_timer(master, holddown_timer_expired, nbr,
- nbr->v_holddown, &nbr->t_holddown);
+ EVENT_OFF(nbr->t_holddown);
+ event_add_timer(master, holddown_timer_expired, nbr,
+ nbr->v_holddown, &nbr->t_holddown);
break;
}
case EIGRP_NEIGHBOR_UP: {
/*Reset Hold Down Timer for neighbor*/
- THREAD_OFF(nbr->t_holddown);
- thread_add_timer(master, holddown_timer_expired, nbr,
- nbr->v_holddown, &nbr->t_holddown);
+ EVENT_OFF(nbr->t_holddown);
+ event_add_timer(master, holddown_timer_expired, nbr,
+ nbr->v_holddown, &nbr->t_holddown);
break;
}
}
diff --git a/eigrpd/eigrp_neighbor.h b/eigrpd/eigrp_neighbor.h
index 5c9e44e2b9..2ccc89cf3a 100644
--- a/eigrpd/eigrp_neighbor.h
+++ b/eigrpd/eigrp_neighbor.h
@@ -24,7 +24,7 @@ extern struct eigrp_neighbor *eigrp_nbr_get(struct eigrp_interface *ei,
extern struct eigrp_neighbor *eigrp_nbr_new(struct eigrp_interface *ei);
extern void eigrp_nbr_delete(struct eigrp_neighbor *neigh);
-extern void holddown_timer_expired(struct thread *thread);
+extern void holddown_timer_expired(struct event *thread);
extern int eigrp_neighborship_check(struct eigrp_neighbor *neigh,
struct TLV_Parameter_Type *tlv);
diff --git a/eigrpd/eigrp_network.c b/eigrpd/eigrp_network.c
index 68edd0898a..ef567fe4ef 100644
--- a/eigrpd/eigrp_network.c
+++ b/eigrpd/eigrp_network.c
@@ -12,7 +12,7 @@
#include <zebra.h>
-#include "thread.h"
+#include "frrevent.h"
#include "linklist.h"
#include "prefix.h"
#include "if.h"
diff --git a/eigrpd/eigrp_network.h b/eigrpd/eigrp_network.h
index 33d91c2fbf..ac5c47f6f9 100644
--- a/eigrpd/eigrp_network.h
+++ b/eigrpd/eigrp_network.h
@@ -20,7 +20,7 @@ extern int eigrp_if_ipmulticast(struct eigrp *, struct prefix *, unsigned int);
extern int eigrp_network_set(struct eigrp *eigrp, struct prefix *p);
extern int eigrp_network_unset(struct eigrp *eigrp, struct prefix *p);
-extern void eigrp_hello_timer(struct thread *thread);
+extern void eigrp_hello_timer(struct event *thread);
extern void eigrp_if_update(struct interface *);
extern int eigrp_if_add_allspfrouters(struct eigrp *, struct prefix *,
unsigned int);
diff --git a/eigrpd/eigrp_packet.c b/eigrpd/eigrp_packet.c
index e00d62fb08..963d229bc1 100644
--- a/eigrpd/eigrp_packet.c
+++ b/eigrpd/eigrp_packet.c
@@ -12,7 +12,7 @@
#include <zebra.h>
-#include "thread.h"
+#include "frrevent.h"
#include "memory.h"
#include "linklist.h"
#include "vty.h"
@@ -305,9 +305,9 @@ int eigrp_check_sha256_digest(struct stream *s,
return 1;
}
-void eigrp_write(struct thread *thread)
+void eigrp_write(struct event *thread)
{
- struct eigrp *eigrp = THREAD_ARG(thread);
+ struct eigrp *eigrp = EVENT_ARG(thread);
struct eigrp_header *eigrph;
struct eigrp_interface *ei;
struct eigrp_packet *ep;
@@ -453,13 +453,13 @@ out:
/* If packets still remain in queue, call write thread. */
if (!list_isempty(eigrp->oi_write_q)) {
- thread_add_write(master, eigrp_write, eigrp, eigrp->fd,
- &eigrp->t_write);
+ event_add_write(master, eigrp_write, eigrp, eigrp->fd,
+ &eigrp->t_write);
}
}
/* Starting point of packet process function. */
-void eigrp_read(struct thread *thread)
+void eigrp_read(struct event *thread)
{
int ret;
struct stream *ibuf;
@@ -474,10 +474,10 @@ void eigrp_read(struct thread *thread)
uint16_t length = 0;
/* first of all get interface pointer. */
- eigrp = THREAD_ARG(thread);
+ eigrp = EVENT_ARG(thread);
/* prepare for next packet. */
- thread_add_read(master, eigrp_read, eigrp, eigrp->fd, &eigrp->t_read);
+ event_add_read(master, eigrp_read, eigrp, eigrp->fd, &eigrp->t_read);
stream_reset(eigrp->ibuf);
if (!(ibuf = eigrp_recv_packet(eigrp, eigrp->fd, &ifp, eigrp->ibuf))) {
@@ -828,9 +828,9 @@ void eigrp_send_packet_reliably(struct eigrp_neighbor *nbr)
eigrp_fifo_push(nbr->ei->obuf, duplicate);
/*Start retransmission timer*/
- thread_add_timer(master, eigrp_unack_packet_retrans, nbr,
- EIGRP_PACKET_RETRANS_TIME,
- &ep->t_retrans_timer);
+ event_add_timer(master, eigrp_unack_packet_retrans, nbr,
+ EIGRP_PACKET_RETRANS_TIME,
+ &ep->t_retrans_timer);
/*Increment sequence number counter*/
nbr->ei->eigrp->sequence_number++;
@@ -840,8 +840,8 @@ void eigrp_send_packet_reliably(struct eigrp_neighbor *nbr)
listnode_add(nbr->ei->eigrp->oi_write_q, nbr->ei);
nbr->ei->on_write_q = 1;
}
- thread_add_write(master, eigrp_write, nbr->ei->eigrp,
- nbr->ei->eigrp->fd, &nbr->ei->eigrp->t_write);
+ event_add_write(master, eigrp_write, nbr->ei->eigrp,
+ nbr->ei->eigrp->fd, &nbr->ei->eigrp->t_write);
}
}
@@ -923,7 +923,7 @@ void eigrp_packet_free(struct eigrp_packet *ep)
if (ep->s)
stream_free(ep->s);
- THREAD_OFF(ep->t_retrans_timer);
+ EVENT_OFF(ep->t_retrans_timer);
XFREE(MTYPE_EIGRP_PACKET, ep);
}
@@ -970,10 +970,10 @@ static int eigrp_check_network_mask(struct eigrp_interface *ei,
return 0;
}
-void eigrp_unack_packet_retrans(struct thread *thread)
+void eigrp_unack_packet_retrans(struct event *thread)
{
struct eigrp_neighbor *nbr;
- nbr = (struct eigrp_neighbor *)THREAD_ARG(thread);
+ nbr = (struct eigrp_neighbor *)EVENT_ARG(thread);
struct eigrp_packet *ep;
ep = eigrp_fifo_next(nbr->retrans_queue);
@@ -992,24 +992,24 @@ void eigrp_unack_packet_retrans(struct thread *thread)
}
/*Start retransmission timer*/
- thread_add_timer(master, eigrp_unack_packet_retrans, nbr,
- EIGRP_PACKET_RETRANS_TIME,
- &ep->t_retrans_timer);
+ event_add_timer(master, eigrp_unack_packet_retrans, nbr,
+ EIGRP_PACKET_RETRANS_TIME,
+ &ep->t_retrans_timer);
/* Hook thread to write packet. */
if (nbr->ei->on_write_q == 0) {
listnode_add(nbr->ei->eigrp->oi_write_q, nbr->ei);
nbr->ei->on_write_q = 1;
}
- thread_add_write(master, eigrp_write, nbr->ei->eigrp,
- nbr->ei->eigrp->fd, &nbr->ei->eigrp->t_write);
+ event_add_write(master, eigrp_write, nbr->ei->eigrp,
+ nbr->ei->eigrp->fd, &nbr->ei->eigrp->t_write);
}
}
-void eigrp_unack_multicast_packet_retrans(struct thread *thread)
+void eigrp_unack_multicast_packet_retrans(struct event *thread)
{
struct eigrp_neighbor *nbr;
- nbr = (struct eigrp_neighbor *)THREAD_ARG(thread);
+ nbr = (struct eigrp_neighbor *)EVENT_ARG(thread);
struct eigrp_packet *ep;
ep = eigrp_fifo_next(nbr->multicast_queue);
@@ -1027,17 +1027,17 @@ void eigrp_unack_multicast_packet_retrans(struct thread *thread)
}
/*Start retransmission timer*/
- thread_add_timer(master, eigrp_unack_multicast_packet_retrans,
- nbr, EIGRP_PACKET_RETRANS_TIME,
- &ep->t_retrans_timer);
+ event_add_timer(master, eigrp_unack_multicast_packet_retrans,
+ nbr, EIGRP_PACKET_RETRANS_TIME,
+ &ep->t_retrans_timer);
/* Hook thread to write packet. */
if (nbr->ei->on_write_q == 0) {
listnode_add(nbr->ei->eigrp->oi_write_q, nbr->ei);
nbr->ei->on_write_q = 1;
}
- thread_add_write(master, eigrp_write, nbr->ei->eigrp,
- nbr->ei->eigrp->fd, &nbr->ei->eigrp->t_write);
+ event_add_write(master, eigrp_write, nbr->ei->eigrp,
+ nbr->ei->eigrp->fd, &nbr->ei->eigrp->t_write);
}
}
diff --git a/eigrpd/eigrp_packet.h b/eigrpd/eigrp_packet.h
index 4c1cfd4828..6a0360ed80 100644
--- a/eigrpd/eigrp_packet.h
+++ b/eigrpd/eigrp_packet.h
@@ -18,8 +18,8 @@
#define _ZEBRA_EIGRP_PACKET_H
/*Prototypes*/
-extern void eigrp_read(struct thread *thread);
-extern void eigrp_write(struct thread *thread);
+extern void eigrp_read(struct event *thread);
+extern void eigrp_write(struct event *thread);
extern struct eigrp_packet *eigrp_packet_new(size_t size,
struct eigrp_neighbor *nbr);
@@ -51,8 +51,8 @@ extern uint16_t eigrp_add_authTLV_MD5_to_stream(struct stream *s,
extern uint16_t eigrp_add_authTLV_SHA256_to_stream(struct stream *s,
struct eigrp_interface *ei);
-extern void eigrp_unack_packet_retrans(struct thread *thread);
-extern void eigrp_unack_multicast_packet_retrans(struct thread *thread);
+extern void eigrp_unack_packet_retrans(struct event *thread);
+extern void eigrp_unack_multicast_packet_retrans(struct event *thread);
/*
* untill there is reason to have their own header, these externs are found in
@@ -65,7 +65,7 @@ extern void eigrp_hello_send_ack(struct eigrp_neighbor *nbr);
extern void eigrp_hello_receive(struct eigrp *eigrp, struct ip *iph,
struct eigrp_header *eigrph, struct stream *s,
struct eigrp_interface *ei, int size);
-extern void eigrp_hello_timer(struct thread *thread);
+extern void eigrp_hello_timer(struct event *thread);
/*
* These externs are found in eigrp_update.c
@@ -81,7 +81,7 @@ extern void eigrp_update_send_all(struct eigrp *eigrp,
struct eigrp_interface *exception);
extern void eigrp_update_send_init(struct eigrp_neighbor *nbr);
extern void eigrp_update_send_EOT(struct eigrp_neighbor *nbr);
-extern void eigrp_update_send_GR_thread(struct thread *thread);
+extern void eigrp_update_send_GR_thread(struct event *thread);
extern void eigrp_update_send_GR(struct eigrp_neighbor *nbr,
enum GR_type gr_type, struct vty *vty);
extern void eigrp_update_send_interface_GR(struct eigrp_interface *ei,
diff --git a/eigrpd/eigrp_query.c b/eigrpd/eigrp_query.c
index 56498ed674..0e206cded6 100644
--- a/eigrpd/eigrp_query.c
+++ b/eigrpd/eigrp_query.c
@@ -12,7 +12,7 @@
#include <zebra.h>
-#include "thread.h"
+#include "frrevent.h"
#include "memory.h"
#include "linklist.h"
#include "prefix.h"
diff --git a/eigrpd/eigrp_reply.c b/eigrpd/eigrp_reply.c
index a1413fe9c7..aae89e832b 100644
--- a/eigrpd/eigrp_reply.c
+++ b/eigrpd/eigrp_reply.c
@@ -16,7 +16,7 @@
#include <zebra.h>
-#include "thread.h"
+#include "frrevent.h"
#include "memory.h"
#include "linklist.h"
#include "prefix.h"
diff --git a/eigrpd/eigrp_siaquery.c b/eigrpd/eigrp_siaquery.c
index 1c2ec3731f..71486a1f6f 100644
--- a/eigrpd/eigrp_siaquery.c
+++ b/eigrpd/eigrp_siaquery.c
@@ -12,7 +12,7 @@
#include <zebra.h>
-#include "thread.h"
+#include "frrevent.h"
#include "memory.h"
#include "linklist.h"
#include "prefix.h"
diff --git a/eigrpd/eigrp_siareply.c b/eigrpd/eigrp_siareply.c
index 37cca67373..6c8c1ef58d 100644
--- a/eigrpd/eigrp_siareply.c
+++ b/eigrpd/eigrp_siareply.c
@@ -11,7 +11,7 @@
*/
#include <zebra.h>
-#include "thread.h"
+#include "frrevent.h"
#include "memory.h"
#include "linklist.h"
#include "prefix.h"
diff --git a/eigrpd/eigrp_snmp.c b/eigrpd/eigrp_snmp.c
index f159415ccb..492ef3e713 100644
--- a/eigrpd/eigrp_snmp.c
+++ b/eigrpd/eigrp_snmp.c
@@ -16,7 +16,7 @@
#include <net-snmp/net-snmp-config.h>
#include <net-snmp/net-snmp-includes.h>
-#include "thread.h"
+#include "frrevent.h"
#include "memory.h"
#include "linklist.h"
#include "prefix.h"
diff --git a/eigrpd/eigrp_structs.h b/eigrpd/eigrp_structs.h
index 9c88e34f6c..8735c48661 100644
--- a/eigrpd/eigrp_structs.h
+++ b/eigrpd/eigrp_structs.h
@@ -71,9 +71,9 @@ struct eigrp {
struct list *oi_write_q;
/*Threads*/
- struct thread *t_write;
- struct thread *t_read;
- struct thread *t_distribute; /* timer for distribute list */
+ struct event *t_write;
+ struct event *t_read;
+ struct event *t_distribute; /* timer for distribute list */
struct route_table *networks; /* EIGRP config networks. */
@@ -165,8 +165,8 @@ struct eigrp_interface {
struct list *nbrs; /* EIGRP Neighbor List */
/* Threads. */
- struct thread *t_hello; /* timer */
- struct thread *t_distribute; /* timer for distribute list */
+ struct event *t_hello; /* timer */
+ struct event *t_distribute; /* timer for distribute list */
int on_write_q;
@@ -240,8 +240,8 @@ struct eigrp_neighbor {
uint16_t v_holddown;
/* Threads. */
- struct thread *t_holddown;
- struct thread *t_nbr_send_gr; /* thread for sending multiple GR packet
+ struct event *t_holddown;
+ struct event *t_nbr_send_gr; /* thread for sending multiple GR packet
chunks */
struct eigrp_fifo *retrans_queue;
@@ -271,7 +271,7 @@ struct eigrp_packet {
struct in_addr dst;
/*Packet retransmission thread*/
- struct thread *t_retrans_timer;
+ struct event *t_retrans_timer;
/*Packet retransmission counter*/
uint8_t retrans_counter;
diff --git a/eigrpd/eigrp_update.c b/eigrpd/eigrp_update.c
index 49acf30695..2237a611e8 100644
--- a/eigrpd/eigrp_update.c
+++ b/eigrpd/eigrp_update.c
@@ -16,7 +16,7 @@
#include <zebra.h>
-#include "thread.h"
+#include "frrevent.h"
#include "memory.h"
#include "linklist.h"
#include "prefix.h"
@@ -895,19 +895,19 @@ static void eigrp_update_send_GR_part(struct eigrp_neighbor *nbr)
*
* Uses nbr_gr_packet_type and t_nbr_send_gr from neighbor.
*/
-void eigrp_update_send_GR_thread(struct thread *thread)
+void eigrp_update_send_GR_thread(struct event *thread)
{
struct eigrp_neighbor *nbr;
/* get argument from thread */
- nbr = THREAD_ARG(thread);
+ nbr = EVENT_ARG(thread);
/* remove this thread pointer */
/* if there is packet waiting in queue,
* schedule this thread again with small delay */
if (nbr->retrans_queue->count > 0) {
- thread_add_timer_msec(master, eigrp_update_send_GR_thread, nbr,
- 10, &nbr->t_nbr_send_gr);
+ event_add_timer_msec(master, eigrp_update_send_GR_thread, nbr,
+ 10, &nbr->t_nbr_send_gr);
return;
}
@@ -916,7 +916,7 @@ void eigrp_update_send_GR_thread(struct thread *thread)
/* if it wasn't last chunk, schedule this thread again */
if (nbr->nbr_gr_packet_type != EIGRP_PACKET_PART_LAST) {
- thread_execute(master, eigrp_update_send_GR_thread, nbr, 0);
+ event_execute(master, eigrp_update_send_GR_thread, nbr, 0);
}
}
@@ -982,7 +982,7 @@ void eigrp_update_send_GR(struct eigrp_neighbor *nbr, enum GR_type gr_type,
/* indicate, that this is first GR Update packet chunk */
nbr->nbr_gr_packet_type = EIGRP_PACKET_PART_FIRST;
/* execute packet sending in thread */
- thread_execute(master, eigrp_update_send_GR_thread, nbr, 0);
+ event_execute(master, eigrp_update_send_GR_thread, nbr, 0);
}
/**
diff --git a/eigrpd/eigrp_vty.c b/eigrpd/eigrp_vty.c
index 33f728ec4b..88510e75af 100644
--- a/eigrpd/eigrp_vty.c
+++ b/eigrpd/eigrp_vty.c
@@ -17,7 +17,7 @@
#include <zebra.h>
#include "memory.h"
-#include "thread.h"
+#include "frrevent.h"
#include "prefix.h"
#include "table.h"
#include "vty.h"
diff --git a/eigrpd/eigrp_zebra.c b/eigrpd/eigrp_zebra.c
index 179c2d0f2a..94c2bcab71 100644
--- a/eigrpd/eigrp_zebra.c
+++ b/eigrpd/eigrp_zebra.c
@@ -12,7 +12,7 @@
#include <zebra.h>
-#include "thread.h"
+#include "frrevent.h"
#include "command.h"
#include "network.h"
#include "prefix.h"
@@ -49,7 +49,7 @@ static int eigrp_zebra_read_route(ZAPI_CALLBACK_ARGS);
struct zclient *zclient = NULL;
/* For registering threads. */
-extern struct thread_master *master;
+extern struct event_loop *master;
struct in_addr router_id_zebra;
/* Router-id update message from zebra. */
diff --git a/eigrpd/eigrpd.c b/eigrpd/eigrpd.c
index a382862e3d..c7dd96bfff 100644
--- a/eigrpd/eigrpd.c
+++ b/eigrpd/eigrpd.c
@@ -12,7 +12,7 @@
#include <zebra.h>
-#include "thread.h"
+#include "frrevent.h"
#include "vty.h"
#include "command.h"
#include "linklist.h"
@@ -157,7 +157,7 @@ static struct eigrp *eigrp_new(uint16_t as, vrf_id_t vrf_id)
eigrp->ibuf = stream_new(EIGRP_PACKET_MAX_LEN + 1);
- thread_add_read(master, eigrp_read, eigrp, eigrp->fd, &eigrp->t_read);
+ event_add_read(master, eigrp_read, eigrp, eigrp->fd, &eigrp->t_read);
eigrp->oi_write_q = list_new();
eigrp->topology_table = route_table_init();
@@ -260,8 +260,8 @@ void eigrp_finish_final(struct eigrp *eigrp)
eigrp_if_free(ei, INTERFACE_DOWN_BY_FINAL);
}
- THREAD_OFF(eigrp->t_write);
- THREAD_OFF(eigrp->t_read);
+ EVENT_OFF(eigrp->t_write);
+ EVENT_OFF(eigrp->t_read);
close(eigrp->fd);
list_delete(&eigrp->eiflist);
diff --git a/eigrpd/eigrpd.h b/eigrpd/eigrpd.h
index 6e5d5d13dc..a6a4e39a59 100644
--- a/eigrpd/eigrpd.h
+++ b/eigrpd/eigrpd.h
@@ -35,7 +35,7 @@ struct eigrp_master {
struct list *eigrp;
/* EIGRP thread master. */
- struct thread_master *master;
+ struct event_loop *master;
/* Zebra interface list. */
struct list *iflist;
@@ -51,7 +51,7 @@ struct eigrp_master {
/* Extern variables. */
extern struct zclient *zclient;
-extern struct thread_master *master;
+extern struct event_loop *master;
extern struct eigrp_master *eigrp_om;
extern struct zebra_privs_t eigrpd_privs;
diff --git a/gdb/lib.txt b/gdb/lib.txt
index b44c237985..5d22321b62 100644
--- a/gdb/lib.txt
+++ b/gdb/lib.txt
@@ -157,7 +157,7 @@ document walk_route_table
Walk through a routing table (or subset thereof) and dump all the non-null
(struct route_node *)->info pointers.
-Argument: A lib/thread.h::(struct route_node *) pointing to the route_node
+Argument: A lib/hread.h::(struct route_node *) pointing to the route_node
under which all data should be dumped
end
diff --git a/isisd/fabricd.c b/isisd/fabricd.c
index 64734f8628..0be36e175a 100644
--- a/isisd/fabricd.c
+++ b/isisd/fabricd.c
@@ -40,7 +40,7 @@ struct fabricd {
enum fabricd_sync_state initial_sync_state;
time_t initial_sync_start;
struct isis_circuit *initial_sync_circuit;
- struct thread *initial_sync_timeout;
+ struct event *initial_sync_timeout;
struct isis_spftree *spftree;
struct skiplist *neighbors;
@@ -49,8 +49,8 @@ struct fabricd {
uint8_t tier;
uint8_t tier_config;
uint8_t tier_pending;
- struct thread *tier_calculation_timer;
- struct thread *tier_set_timer;
+ struct event *tier_calculation_timer;
+ struct event *tier_set_timer;
int csnp_delay;
bool always_send_csnp;
@@ -225,11 +225,11 @@ struct fabricd *fabricd_new(struct isis_area *area)
void fabricd_finish(struct fabricd *f)
{
- THREAD_OFF(f->initial_sync_timeout);
+ EVENT_OFF(f->initial_sync_timeout);
- THREAD_OFF(f->tier_calculation_timer);
+ EVENT_OFF(f->tier_calculation_timer);
- THREAD_OFF(f->tier_set_timer);
+ EVENT_OFF(f->tier_set_timer);
isis_spftree_del(f->spftree);
neighbor_lists_clear(f);
@@ -237,9 +237,9 @@ void fabricd_finish(struct fabricd *f)
hash_free(f->neighbors_neighbors);
}
-static void fabricd_initial_sync_timeout(struct thread *thread)
+static void fabricd_initial_sync_timeout(struct event *thread)
{
- struct fabricd *f = THREAD_ARG(thread);
+ struct fabricd *f = EVENT_ARG(thread);
if (IS_DEBUG_ADJ_PACKETS)
zlog_debug(
@@ -267,14 +267,14 @@ void fabricd_initial_sync_hello(struct isis_circuit *circuit)
if (f->initial_sync_timeout)
return;
- thread_add_timer(master, fabricd_initial_sync_timeout, f,
- timeout, &f->initial_sync_timeout);
+ event_add_timer(master, fabricd_initial_sync_timeout, f, timeout,
+ &f->initial_sync_timeout);
f->initial_sync_start = monotime(NULL);
if (IS_DEBUG_ADJ_PACKETS)
zlog_debug(
- "OpenFabric: Started initial synchronization with %s on %s",
- sysid_print(circuit->u.p2p.neighbor->sysid),
+ "OpenFabric: Started initial synchronization with %pSY on %s",
+ circuit->u.p2p.neighbor->sysid,
circuit->interface->name);
}
@@ -325,7 +325,7 @@ void fabricd_initial_sync_finish(struct isis_area *area)
f->initial_sync_circuit->interface->name);
f->initial_sync_state = FABRICD_SYNC_COMPLETE;
f->initial_sync_circuit = NULL;
- THREAD_OFF(f->initial_sync_timeout);
+ EVENT_OFF(f->initial_sync_timeout);
}
static void fabricd_bump_tier_calculation_timer(struct fabricd *f);
@@ -359,7 +359,9 @@ static uint8_t fabricd_calculate_fabric_tier(struct isis_area *area)
return ISIS_TIER_UNDEFINED;
}
- zlog_info("OpenFabric: Found %s as furthest t0 from local system, dist == %u", rawlspid_print(furthest_t0->N.id), furthest_t0->d_N);
+ zlog_info(
+ "OpenFabric: Found %pLS as furthest t0 from local system, dist == %u",
+ furthest_t0->N.id, furthest_t0->d_N);
struct isis_spftree *remote_tree =
isis_run_hopcount_spf(area, furthest_t0->N.id, NULL);
@@ -372,8 +374,9 @@ static uint8_t fabricd_calculate_fabric_tier(struct isis_area *area)
isis_spftree_del(remote_tree);
return ISIS_TIER_UNDEFINED;
} else {
- zlog_info("OpenFabric: Found %s as furthest from remote dist == %u", rawlspid_print(furthest_from_remote->N.id),
- furthest_from_remote->d_N);
+ zlog_info(
+ "OpenFabric: Found %pLS as furthest from remote dist == %u",
+ furthest_from_remote->N.id, furthest_from_remote->d_N);
}
int64_t tier = furthest_from_remote->d_N - furthest_t0->d_N;
@@ -389,16 +392,16 @@ static uint8_t fabricd_calculate_fabric_tier(struct isis_area *area)
return tier;
}
-static void fabricd_tier_set_timer(struct thread *thread)
+static void fabricd_tier_set_timer(struct event *thread)
{
- struct fabricd *f = THREAD_ARG(thread);
+ struct fabricd *f = EVENT_ARG(thread);
fabricd_set_tier(f, f->tier_pending);
}
-static void fabricd_tier_calculation_cb(struct thread *thread)
+static void fabricd_tier_calculation_cb(struct event *thread)
{
- struct fabricd *f = THREAD_ARG(thread);
+ struct fabricd *f = EVENT_ARG(thread);
uint8_t tier = ISIS_TIER_UNDEFINED;
tier = fabricd_calculate_fabric_tier(f->area);
@@ -408,28 +411,27 @@ static void fabricd_tier_calculation_cb(struct thread *thread)
zlog_info("OpenFabric: Got tier %hhu from algorithm. Arming timer.",
tier);
f->tier_pending = tier;
- thread_add_timer(master, fabricd_tier_set_timer, f,
- f->area->lsp_gen_interval[ISIS_LEVEL2 - 1],
- &f->tier_set_timer);
-
+ event_add_timer(master, fabricd_tier_set_timer, f,
+ f->area->lsp_gen_interval[ISIS_LEVEL2 - 1],
+ &f->tier_set_timer);
}
static void fabricd_bump_tier_calculation_timer(struct fabricd *f)
{
/* Cancel timer if we already know our tier */
if (f->tier != ISIS_TIER_UNDEFINED || f->tier_set_timer) {
- THREAD_OFF(f->tier_calculation_timer);
+ EVENT_OFF(f->tier_calculation_timer);
return;
}
/* If we need to calculate the tier, wait some
* time for the topology to settle before running
* the calculation */
- THREAD_OFF(f->tier_calculation_timer);
+ EVENT_OFF(f->tier_calculation_timer);
- thread_add_timer(master, fabricd_tier_calculation_cb, f,
- 2 * f->area->lsp_gen_interval[ISIS_LEVEL2 - 1],
- &f->tier_calculation_timer);
+ event_add_timer(master, fabricd_tier_calculation_cb, f,
+ 2 * f->area->lsp_gen_interval[ISIS_LEVEL2 - 1],
+ &f->tier_calculation_timer);
}
static void fabricd_set_tier(struct fabricd *f, uint8_t tier)
@@ -710,10 +712,10 @@ void fabricd_trigger_csnp(struct isis_area *area, bool circuit_scoped)
if (!circuit->t_send_csnp[1])
continue;
- THREAD_OFF(circuit->t_send_csnp[ISIS_LEVEL2 - 1]);
- thread_add_timer_msec(master, send_l2_csnp, circuit,
- isis_jitter(f->csnp_delay, CSNP_JITTER),
- &circuit->t_send_csnp[ISIS_LEVEL2 - 1]);
+ EVENT_OFF(circuit->t_send_csnp[ISIS_LEVEL2 - 1]);
+ event_add_timer_msec(master, send_l2_csnp, circuit,
+ isis_jitter(f->csnp_delay, CSNP_JITTER),
+ &circuit->t_send_csnp[ISIS_LEVEL2 - 1]);
}
}
diff --git a/isisd/isis_adjacency.c b/isisd/isis_adjacency.c
index cb2cf8f611..30b71537e0 100644
--- a/isisd/isis_adjacency.c
+++ b/isisd/isis_adjacency.c
@@ -15,7 +15,7 @@
#include "hash.h"
#include "vty.h"
#include "linklist.h"
-#include "thread.h"
+#include "frrevent.h"
#include "if.h"
#include "stream.h"
#include "bfd.h"
@@ -148,7 +148,7 @@ void isis_delete_adj(void *arg)
/* Remove self from snmp list without walking the list*/
list_delete_node(adj->circuit->snmp_adj_list, adj->snmp_list_node);
- THREAD_OFF(adj->t_expire);
+ EVENT_OFF(adj->t_expire);
if (adj->adj_state != ISIS_ADJ_DOWN)
adj->adj_state = ISIS_ADJ_DOWN;
@@ -283,6 +283,8 @@ void isis_adj_process_threeway(struct isis_adjacency *adj,
}
const char *isis_adj_name(const struct isis_adjacency *adj)
{
+ static char buf[ISO_SYSID_STRLEN];
+
if (!adj)
return "NONE";
@@ -291,8 +293,9 @@ const char *isis_adj_name(const struct isis_adjacency *adj)
dyn = dynhn_find_by_id(adj->circuit->isis, adj->sysid);
if (dyn)
return dyn->hostname;
- else
- return sysid_print(adj->sysid);
+
+ snprintfrr(buf, sizeof(buf), "%pSY", adj->sysid);
+ return buf;
}
void isis_log_adj_change(struct isis_adjacency *adj,
enum isis_adj_state old_state,
@@ -396,13 +399,13 @@ void isis_adj_state_change(struct isis_adjacency **padj,
adj->flaps++;
if (level == IS_LEVEL_1) {
- thread_add_timer(master, send_l1_csnp,
- circuit, 0,
- &circuit->t_send_csnp[0]);
+ event_add_timer(
+ master, send_l1_csnp, circuit,
+ 0, &circuit->t_send_csnp[0]);
} else {
- thread_add_timer(master, send_l2_csnp,
- circuit, 0,
- &circuit->t_send_csnp[1]);
+ event_add_timer(
+ master, send_l2_csnp, circuit,
+ 0, &circuit->t_send_csnp[1]);
}
} else if (old_state == ISIS_ADJ_UP) {
circuit->upadjcount[level - 1]--;
@@ -439,9 +442,8 @@ void isis_adj_print(struct isis_adjacency *adj)
if (dyn)
zlog_debug("%s", dyn->hostname);
- zlog_debug("SystemId %20s SNPA %s, level %d; Holding Time %d",
- sysid_print(adj->sysid), snpa_print(adj->snpa), adj->level,
- adj->hold_time);
+ zlog_debug("SystemId %20pSY SNPA %pSY, level %d; Holding Time %d",
+ adj->sysid, adj->snpa, adj->level, adj->hold_time);
if (adj->ipv4_address_count) {
zlog_debug("IPv4 Address(es):");
for (unsigned int i = 0; i < adj->ipv4_address_count; i++)
@@ -478,14 +480,14 @@ const char *isis_adj_yang_state(enum isis_adj_state state)
assert(!"Reached end of function where we are not expecting to");
}
-void isis_adj_expire(struct thread *thread)
+void isis_adj_expire(struct event *thread)
{
struct isis_adjacency *adj;
/*
* Get the adjacency
*/
- adj = THREAD_ARG(thread);
+ adj = EVENT_ARG(thread);
assert(adj);
adj->t_expire = NULL;
@@ -530,7 +532,7 @@ void isis_adj_print_json(struct isis_adjacency *adj, struct json_object *json,
time2string(adj->last_upd +
adj->hold_time - now));
}
- json_object_string_add(json, "snpa", snpa_print(adj->snpa));
+ json_object_string_addf(json, "snpa", "%pSY", adj->snpa);
}
if (detail == ISIS_UI_LEVEL_DETAIL) {
@@ -581,8 +583,7 @@ void isis_adj_print_json(struct isis_adjacency *adj, struct json_object *json,
isis_mtid2str(adj->mt_set[i]));
}
}
- json_object_string_add(iface_json, "snpa",
- snpa_print(adj->snpa));
+ json_object_string_addf(iface_json, "snpa", "%pSY", adj->snpa);
if (adj->circuit &&
(adj->circuit->circ_type == CIRCUIT_T_BROADCAST)) {
dyn = dynhn_find_by_id(adj->circuit->isis, adj->lanid);
@@ -593,11 +594,8 @@ void isis_adj_print_json(struct isis_adjacency *adj, struct json_object *json,
json_object_string_add(iface_json, "lan-id",
buf);
} else {
- snprintfrr(buf, sizeof(buf), "%s-%02x",
- sysid_print(adj->lanid),
- adj->lanid[ISIS_SYS_ID_LEN]);
- json_object_string_add(iface_json, "lan-id",
- buf);
+ json_object_string_addf(iface_json, "lan-id",
+ "%pSY", adj->lanid);
}
json_object_int_add(iface_json, "lan-prio",
@@ -626,12 +624,9 @@ void isis_adj_print_json(struct isis_adjacency *adj, struct json_object *json,
area_addr_json);
for (unsigned int i = 0; i < adj->area_address_count;
i++) {
- json_object_string_add(
- area_addr_json, "isonet",
- isonet_print(adj->area_addresses[i]
- .area_addr,
- adj->area_addresses[i]
- .addr_len));
+ json_object_string_addf(
+ area_addr_json, "isonet", "%pIS",
+ &adj->area_addresses[i]);
}
}
if (adj->ipv4_address_count) {
@@ -736,7 +731,7 @@ void isis_adj_print_vty(struct isis_adjacency *adj, struct vty *vty,
+ adj->hold_time - now);
} else
vty_out(vty, "- ");
- vty_out(vty, "%-10s", snpa_print(adj->snpa));
+ vty_out(vty, "%-10pSY", adj->snpa);
vty_out(vty, "\n");
}
@@ -780,7 +775,7 @@ void isis_adj_print_vty(struct isis_adjacency *adj, struct vty *vty,
vty_out(vty, " %s\n",
isis_mtid2str(adj->mt_set[i]));
}
- vty_out(vty, " SNPA: %s", snpa_print(adj->snpa));
+ vty_out(vty, " SNPA: %pSY", adj->snpa);
if (adj->circuit
&& (adj->circuit->circ_type == CIRCUIT_T_BROADCAST)) {
dyn = dynhn_find_by_id(adj->circuit->isis, adj->lanid);
@@ -788,9 +783,7 @@ void isis_adj_print_vty(struct isis_adjacency *adj, struct vty *vty,
vty_out(vty, ", LAN id: %s.%02x", dyn->hostname,
adj->lanid[ISIS_SYS_ID_LEN]);
else
- vty_out(vty, ", LAN id: %s.%02x",
- sysid_print(adj->lanid),
- adj->lanid[ISIS_SYS_ID_LEN]);
+ vty_out(vty, ", LAN id: %pPN", adj->lanid);
vty_out(vty, "\n");
vty_out(vty, " LAN Priority: %u",
@@ -811,11 +804,8 @@ void isis_adj_print_vty(struct isis_adjacency *adj, struct vty *vty,
vty_out(vty, " Area Address(es):\n");
for (unsigned int i = 0; i < adj->area_address_count;
i++) {
- vty_out(vty, " %s\n",
- isonet_print(adj->area_addresses[i]
- .area_addr,
- adj->area_addresses[i]
- .addr_len));
+ vty_out(vty, " %pIS\n",
+ &adj->area_addresses[i]);
}
}
if (adj->ipv4_address_count) {
diff --git a/isisd/isis_adjacency.h b/isisd/isis_adjacency.h
index c260ce78de..c0c8e68145 100644
--- a/isisd/isis_adjacency.h
+++ b/isisd/isis_adjacency.h
@@ -69,7 +69,7 @@ struct isis_adjacency {
struct isis_dis_record dis_record[DIS_RECORDS * ISIS_LEVELS];
enum isis_adj_state adj_state; /* adjacencyState */
enum isis_adj_usage adj_usage; /* adjacencyUsage */
- struct area_addr *area_addresses; /* areaAdressesOfNeighbour */
+ struct iso_address *area_addresses; /* areaAdressesOfNeighbour */
unsigned int area_address_count;
struct nlpids nlpids; /* protocols spoken ... */
struct in_addr *ipv4_addresses;
@@ -90,7 +90,7 @@ struct isis_adjacency {
enum isis_threeway_state threeway_state;
uint32_t ext_circuit_id;
int flaps; /* number of adjacency flaps */
- struct thread *t_expire; /* expire after hold_time */
+ struct event *t_expire; /* expire after hold_time */
struct isis_circuit *circuit; /* back pointer */
uint16_t *mt_set; /* Topologies this adjacency is valid for */
unsigned int mt_count; /* Number of entries in mt_set */
@@ -128,7 +128,7 @@ void isis_adj_state_change(struct isis_adjacency **adj,
enum isis_adj_state state, const char *reason);
void isis_adj_print(struct isis_adjacency *adj);
const char *isis_adj_yang_state(enum isis_adj_state state);
-void isis_adj_expire(struct thread *thread);
+void isis_adj_expire(struct event *thread);
void isis_adj_print_vty(struct isis_adjacency *adj, struct vty *vty,
char detail);
void isis_adj_print_json(struct isis_adjacency *adj, struct json_object *json,
@@ -136,6 +136,6 @@ void isis_adj_print_json(struct isis_adjacency *adj, struct json_object *json,
void isis_adj_build_neigh_list(struct list *adjdb, struct list *list);
void isis_adj_build_up_list(struct list *adjdb, struct list *list);
int isis_adj_usage2levels(enum isis_adj_usage usage);
-void isis_bfd_startup_timer(struct thread *thread);
+void isis_bfd_startup_timer(struct event *thread);
const char *isis_adj_name(const struct isis_adjacency *adj);
#endif /* ISIS_ADJACENCY_H */
diff --git a/isisd/isis_bfd.c b/isisd/isis_bfd.c
index b973dd493d..5e24e35210 100644
--- a/isisd/isis_bfd.c
+++ b/isisd/isis_bfd.c
@@ -209,7 +209,7 @@ static int bfd_handle_circuit_add_addr(struct isis_circuit *circuit)
return 0;
}
-void isis_bfd_init(struct thread_master *tm)
+void isis_bfd_init(struct event_loop *tm)
{
bfd_protocol_integration_init(zclient, tm);
diff --git a/isisd/isis_bfd.h b/isisd/isis_bfd.h
index 30248ccece..3cf0ed5219 100644
--- a/isisd/isis_bfd.h
+++ b/isisd/isis_bfd.h
@@ -7,10 +7,10 @@
#define ISIS_BFD_H
struct isis_circuit;
-struct thread_master;
+struct event_loop;
void isis_bfd_circuit_cmd(struct isis_circuit *circuit);
-void isis_bfd_init(struct thread_master *tm);
+void isis_bfd_init(struct event_loop *tm);
#endif
diff --git a/isisd/isis_circuit.c b/isisd/isis_circuit.c
index 8644da2f08..feab451233 100644
--- a/isisd/isis_circuit.c
+++ b/isisd/isis_circuit.c
@@ -19,7 +19,7 @@
#include "if.h"
#include "linklist.h"
#include "command.h"
-#include "thread.h"
+#include "frrevent.h"
#include "vty.h"
#include "hash.h"
#include "prefix.h"
@@ -107,7 +107,7 @@ struct isis_circuit *isis_circuit_new(struct interface *ifp, const char *tag)
"/frr-interface:lib/interface/frr-isisd:isis/circuit-type");
circuit->flags = 0;
- circuit->pad_hellos = yang_get_default_bool(
+ circuit->pad_hellos = yang_get_default_enum(
"/frr-interface:lib/interface/frr-isisd:isis/hello/padding");
circuit->hello_interval[0] = yang_get_default_uint32(
"/frr-interface:lib/interface/frr-isisd:isis/hello/interval/level-1");
@@ -145,7 +145,7 @@ struct isis_circuit *isis_circuit_new(struct interface *ifp, const char *tag)
#else
circuit->is_type_config = IS_LEVEL_1_AND_2;
circuit->flags = 0;
- circuit->pad_hellos = 1;
+ circuit->pad_hellos = ISIS_HELLO_PADDING_ALWAYS;
for (i = 0; i < 2; i++) {
circuit->hello_interval[i] = DEFAULT_HELLO_INTERVAL;
circuit->hello_multiplier[i] = DEFAULT_HELLO_MULTIPLIER;
@@ -286,8 +286,7 @@ void isis_circuit_add_addr(struct isis_circuit *circuit,
if (connected->address->family == AF_INET) {
uint32_t addr = connected->address->u.prefix4.s_addr;
addr = ntohl(addr);
- if (IPV4_NET0(addr) || IPV4_NET127(addr) || IN_CLASSD(addr)
- || IPV4_LINKLOCAL(addr))
+ if (IPV4_NET0(addr) || IPV4_NET127(addr) || IN_CLASSD(addr))
return;
for (ALL_LIST_ELEMENTS_RO(circuit->ip_addrs, node, ipv4))
@@ -627,12 +626,12 @@ void isis_circuit_stream(struct isis_circuit *circuit, struct stream **stream)
void isis_circuit_prepare(struct isis_circuit *circuit)
{
#if ISIS_METHOD != ISIS_METHOD_DLPI
- thread_add_read(master, isis_receive, circuit, circuit->fd,
- &circuit->t_read);
+ event_add_read(master, isis_receive, circuit, circuit->fd,
+ &circuit->t_read);
#else
- thread_add_timer_msec(master, isis_receive, circuit,
- listcount(circuit->area->circuit_list) * 100,
- &circuit->t_read);
+ event_add_timer_msec(master, isis_receive, circuit,
+ listcount(circuit->area->circuit_list) * 100,
+ &circuit->t_read);
#endif
}
@@ -696,10 +695,9 @@ int isis_circuit_up(struct isis_circuit *circuit)
}
#ifdef EXTREME_DEGUG
if (IS_DEBUG_EVENTS)
- zlog_debug("%s: if_id %d, isomtu %d snpa %s", __func__,
- circuit->interface->ifindex,
- ISO_MTU(circuit),
- snpa_print(circuit->u.bc.snpa));
+ zlog_debug("%s: if_id %d, isomtu %d snpa %pSY",
+ __func__, circuit->interface->ifindex,
+ ISO_MTU(circuit), circuit->u.bc.snpa);
#endif /* EXTREME_DEBUG */
circuit->u.bc.adjdb[0] = list_new();
@@ -722,10 +720,10 @@ int isis_circuit_up(struct isis_circuit *circuit)
send_hello_sched(circuit, level, TRIGGERED_IIH_DELAY);
circuit->u.bc.lan_neighs[level - 1] = list_new();
- thread_add_timer(master, isis_run_dr,
- &circuit->level_arg[level - 1],
- 2 * circuit->hello_interval[level - 1],
- &circuit->u.bc.t_run_dr[level - 1]);
+ event_add_timer(master, isis_run_dr,
+ &circuit->level_arg[level - 1],
+ 2 * circuit->hello_interval[level - 1],
+ &circuit->u.bc.t_run_dr[level - 1]);
}
/* 8.4.1 b) FIXME: solicit ES - 8.4.6 */
@@ -740,13 +738,13 @@ int isis_circuit_up(struct isis_circuit *circuit)
/* initializing PSNP timers */
if (circuit->is_type & IS_LEVEL_1)
- thread_add_timer(
+ event_add_timer(
master, send_l1_psnp, circuit,
isis_jitter(circuit->psnp_interval[0], PSNP_JITTER),
&circuit->t_send_psnp[0]);
if (circuit->is_type & IS_LEVEL_2)
- thread_add_timer(
+ event_add_timer(
master, send_l2_psnp, circuit,
isis_jitter(circuit->psnp_interval[1], PSNP_JITTER),
&circuit->t_send_psnp[1]);
@@ -863,12 +861,12 @@ void isis_circuit_down(struct isis_circuit *circuit)
memset(circuit->u.bc.l2_desig_is, 0, ISIS_SYS_ID_LEN + 1);
memset(circuit->u.bc.snpa, 0, ETH_ALEN);
- THREAD_OFF(circuit->u.bc.t_send_lan_hello[0]);
- THREAD_OFF(circuit->u.bc.t_send_lan_hello[1]);
- THREAD_OFF(circuit->u.bc.t_run_dr[0]);
- THREAD_OFF(circuit->u.bc.t_run_dr[1]);
- THREAD_OFF(circuit->u.bc.t_refresh_pseudo_lsp[0]);
- THREAD_OFF(circuit->u.bc.t_refresh_pseudo_lsp[1]);
+ EVENT_OFF(circuit->u.bc.t_send_lan_hello[0]);
+ EVENT_OFF(circuit->u.bc.t_send_lan_hello[1]);
+ EVENT_OFF(circuit->u.bc.t_run_dr[0]);
+ EVENT_OFF(circuit->u.bc.t_run_dr[1]);
+ EVENT_OFF(circuit->u.bc.t_refresh_pseudo_lsp[0]);
+ EVENT_OFF(circuit->u.bc.t_refresh_pseudo_lsp[1]);
circuit->lsp_regenerate_pending[0] = 0;
circuit->lsp_regenerate_pending[1] = 0;
@@ -878,7 +876,7 @@ void isis_circuit_down(struct isis_circuit *circuit)
} else if (circuit->circ_type == CIRCUIT_T_P2P) {
isis_delete_adj(circuit->u.p2p.neighbor);
circuit->u.p2p.neighbor = NULL;
- THREAD_OFF(circuit->u.p2p.t_send_p2p_hello);
+ EVENT_OFF(circuit->u.p2p.t_send_p2p_hello);
}
/*
@@ -891,11 +889,11 @@ void isis_circuit_down(struct isis_circuit *circuit)
circuit->snmp_adj_idx_gen = 0;
/* Cancel all active threads */
- THREAD_OFF(circuit->t_send_csnp[0]);
- THREAD_OFF(circuit->t_send_csnp[1]);
- THREAD_OFF(circuit->t_send_psnp[0]);
- THREAD_OFF(circuit->t_send_psnp[1]);
- THREAD_OFF(circuit->t_read);
+ EVENT_OFF(circuit->t_send_csnp[0]);
+ EVENT_OFF(circuit->t_send_csnp[1]);
+ EVENT_OFF(circuit->t_send_psnp[0]);
+ EVENT_OFF(circuit->t_send_psnp[1]);
+ EVENT_OFF(circuit->t_read);
if (circuit->tx_queue) {
isis_tx_queue_free(circuit->tx_queue);
@@ -929,7 +927,7 @@ void isis_circuit_down(struct isis_circuit *circuit)
circuit->snd_stream = NULL;
}
- thread_cancel_event(master, circuit);
+ event_cancel_event(master, circuit);
return;
}
@@ -996,8 +994,8 @@ void isis_circuit_print_json(struct isis_circuit *circuit,
json_object_string_add(iface_json, "level",
circuit_t2string(circuit->is_type));
if (circuit->circ_type == CIRCUIT_T_BROADCAST)
- json_object_string_add(iface_json, "snpa",
- snpa_print(circuit->u.bc.snpa));
+ json_object_string_addf(iface_json, "snpa", "%pSY",
+ circuit->u.bc.snpa);
levels_json = json_object_new_array();
@@ -1029,7 +1027,8 @@ void isis_circuit_print_json(struct isis_circuit *circuit,
circuit->hello_multiplier[0]);
json_object_string_add(
hold_json, "pad",
- (circuit->pad_hellos ? "yes" : "no"));
+ isis_hello_padding2string(
+ circuit->pad_hellos));
json_object_int_add(level_json, "cnsp-interval",
circuit->csnp_interval[0]);
json_object_int_add(level_json, "psnp-interval",
@@ -1122,8 +1121,7 @@ void isis_circuit_print_vty(struct isis_circuit *circuit, struct vty *vty,
circuit_type2string(circuit->circ_type));
vty_out(vty, ", Level: %s", circuit_t2string(circuit->is_type));
if (circuit->circ_type == CIRCUIT_T_BROADCAST)
- vty_out(vty, ", SNPA: %-10s",
- snpa_print(circuit->u.bc.snpa));
+ vty_out(vty, ", SNPA: %-10pSY", circuit->u.bc.snpa);
vty_out(vty, "\n");
if (circuit->is_type & IS_LEVEL_1) {
vty_out(vty, " Level-1 Information:\n");
@@ -1137,11 +1135,11 @@ void isis_circuit_print_vty(struct isis_circuit *circuit, struct vty *vty,
vty_out(vty, ", Active neighbors: %u\n",
circuit->upadjcount[0]);
vty_out(vty,
- " Hello interval: %u, Holddown count: %u %s\n",
+ " Hello interval: %u, Holddown count: %u, Padding: %s\n",
circuit->hello_interval[0],
circuit->hello_multiplier[0],
- (circuit->pad_hellos ? "(pad)"
- : "(no-pad)"));
+ isis_hello_padding2string(
+ circuit->pad_hellos));
vty_out(vty,
" CNSP interval: %u, PSNP interval: %u\n",
circuit->csnp_interval[0],
@@ -1169,11 +1167,11 @@ void isis_circuit_print_vty(struct isis_circuit *circuit, struct vty *vty,
vty_out(vty, ", Active neighbors: %u\n",
circuit->upadjcount[1]);
vty_out(vty,
- " Hello interval: %u, Holddown count: %u %s\n",
+ " Hello interval: %u, Holddown count: %u, Padding: %s\n",
circuit->hello_interval[1],
circuit->hello_multiplier[1],
- (circuit->pad_hellos ? "(pad)"
- : "(no-pad)"));
+ isis_hello_padding2string(
+ circuit->pad_hellos));
vty_out(vty,
" CNSP interval: %u, PSNP interval: %u\n",
circuit->csnp_interval[1],
@@ -1319,11 +1317,20 @@ static int isis_interface_config_write(struct vty *vty)
}
}
- /* ISIS - Hello padding - Defaults to true so only
- * display if false */
- if (circuit->pad_hellos == 0) {
+ /* ISIS - Hello padding - Defaults to always so only
+ * display if not always */
+ switch (circuit->pad_hellos) {
+ case ISIS_HELLO_PADDING_DISABLED:
vty_out(vty, " no " PROTO_NAME " hello padding\n");
write++;
+ break;
+ case ISIS_HELLO_PADDING_DURING_ADJACENCY_FORMATION:
+ vty_out(vty, PROTO_NAME
+ " hello padding during-adjacency-formation\n");
+ write++;
+ break;
+ case ISIS_HELLO_PADDING_ALWAYS:
+ break;
}
if (circuit->disable_threeway_adj) {
diff --git a/isisd/isis_circuit.h b/isisd/isis_circuit.h
index 494e96b697..7acde419fc 100644
--- a/isisd/isis_circuit.h
+++ b/isisd/isis_circuit.h
@@ -41,21 +41,21 @@ struct metric {
struct isis_bcast_info {
uint8_t snpa[ETH_ALEN]; /* SNPA of this circuit */
char run_dr_elect[ISIS_LEVELS]; /* Should we run dr election ? */
- struct thread *t_run_dr[ISIS_LEVELS]; /* DR election thread */
- struct thread *t_send_lan_hello[ISIS_LEVELS]; /* send LAN IIHs in this
- thread */
+ struct event *t_run_dr[ISIS_LEVELS]; /* DR election thread */
+ struct event *t_send_lan_hello[ISIS_LEVELS]; /* send LAN IIHs in this
+ thread */
struct list *adjdb[ISIS_LEVELS]; /* adjacency dbs */
struct list *lan_neighs[ISIS_LEVELS]; /* list of lx neigh snpa */
char is_dr[ISIS_LEVELS]; /* Are we level x DR ? */
uint8_t l1_desig_is[ISIS_SYS_ID_LEN + 1]; /* level-1 DR */
uint8_t l2_desig_is[ISIS_SYS_ID_LEN + 1]; /* level-2 DR */
- struct thread *t_refresh_pseudo_lsp[ISIS_LEVELS]; /* refresh pseudo-node
+ struct event *t_refresh_pseudo_lsp[ISIS_LEVELS]; /* refresh pseudo-node
LSPs */
};
struct isis_p2p_info {
struct isis_adjacency *neighbor;
- struct thread *t_send_p2p_hello; /* send P2P IIHs in this thread */
+ struct event *t_send_p2p_hello; /* send P2P IIHs in this thread */
};
struct isis_circuit_arg {
@@ -63,6 +63,15 @@ struct isis_circuit_arg {
struct isis_circuit *circuit;
};
+/*
+ * Hello padding types
+ */
+enum isis_hello_padding {
+ ISIS_HELLO_PADDING_ALWAYS,
+ ISIS_HELLO_PADDING_DISABLED,
+ ISIS_HELLO_PADDING_DURING_ADJACENCY_FORMATION
+};
+
struct isis_circuit {
enum isis_circuit_state state;
uint8_t circuit_id; /* l1/l2 bcast CircuitID */
@@ -76,9 +85,9 @@ struct isis_circuit {
/*
* Threads
*/
- struct thread *t_read;
- struct thread *t_send_csnp[ISIS_LEVELS];
- struct thread *t_send_psnp[ISIS_LEVELS];
+ struct event *t_read;
+ struct event *t_send_csnp[ISIS_LEVELS];
+ struct event *t_send_psnp[ISIS_LEVELS];
struct isis_tx_queue *tx_queue;
struct isis_circuit_arg
level_arg[ISIS_LEVELS]; /* used as argument for threads */
@@ -100,7 +109,7 @@ struct isis_circuit {
struct isis_p2p_info p2p;
} u;
uint8_t priority[ISIS_LEVELS]; /* l1/2 IS configured priority */
- int pad_hellos; /* add padding to Hello PDUs ? */
+ enum isis_hello_padding pad_hellos; /* type of Hello PDUs padding */
char ext_domain; /* externalDomain (boolean) */
int lsp_regenerate_pending[ISIS_LEVELS];
uint64_t lsp_error_counter;
diff --git a/isisd/isis_cli.c b/isisd/isis_cli.c
index 4a598aa8c9..ee51e46858 100644
--- a/isisd/isis_cli.c
+++ b/isisd/isis_cli.c
@@ -2262,15 +2262,22 @@ void cli_show_ip_isis_threeway_shake(struct vty *vty,
/*
* XPath: /frr-interface:lib/interface/frr-isisd:isis/hello/padding
*/
-DEFPY_YANG(isis_hello_padding, isis_hello_padding_cmd, "[no] isis hello padding",
- NO_STR
- "IS-IS routing protocol\n"
- "Add padding to IS-IS hello packets\n"
- "Pad hello packets\n")
+DEFPY_YANG(isis_hello_padding, isis_hello_padding_cmd,
+ "[no] isis hello padding [during-adjacency-formation]$padding_type",
+ NO_STR
+ "IS-IS routing protocol\n"
+ "Type of padding for IS-IS hello packets\n"
+ "Pad hello packets\n"
+ "Add padding to hello packets during adjacency formation only.\n")
{
- nb_cli_enqueue_change(vty, "./frr-isisd:isis/hello/padding",
- NB_OP_MODIFY, no ? "false" : "true");
-
+ if (no) {
+ nb_cli_enqueue_change(vty, "./frr-isisd:isis/hello/padding",
+ NB_OP_MODIFY, "disabled");
+ } else {
+ nb_cli_enqueue_change(vty, "./frr-isisd:isis/hello/padding",
+ NB_OP_MODIFY,
+ padding_type ? padding_type : "always");
+ }
return nb_cli_apply_changes(vty, NULL);
}
@@ -2278,10 +2285,13 @@ void cli_show_ip_isis_hello_padding(struct vty *vty,
const struct lyd_node *dnode,
bool show_defaults)
{
- if (!yang_dnode_get_bool(dnode, NULL))
+ int hello_padding_type = yang_dnode_get_enum(dnode, NULL);
+ if (hello_padding_type == ISIS_HELLO_PADDING_DISABLED)
vty_out(vty, " no");
-
- vty_out(vty, " isis hello padding\n");
+ vty_out(vty, " isis hello padding");
+ if (hello_padding_type == ISIS_HELLO_PADDING_DURING_ADJACENCY_FORMATION)
+ vty_out(vty, " during-adjacency-formation");
+ vty_out(vty, "\n");
}
/*
@@ -3016,6 +3026,26 @@ void cli_show_isis_log_adjacency(struct vty *vty, const struct lyd_node *dnode,
}
/*
+ * XPath: /frr-isisd:isis/instance/log-pdu-drops
+ */
+DEFPY_YANG(log_pdu_drops, log_pdu_drops_cmd, "[no] log-pdu-drops",
+ NO_STR "Log any dropped PDUs\n")
+{
+ nb_cli_enqueue_change(vty, "./log-pdu-drops", NB_OP_MODIFY,
+ no ? "false" : "true");
+
+ return nb_cli_apply_changes(vty, NULL);
+}
+
+void cli_show_isis_log_pdu_drops(struct vty *vty, const struct lyd_node *dnode,
+ bool show_defaults)
+{
+ if (!yang_dnode_get_bool(dnode, NULL))
+ vty_out(vty, " no");
+ vty_out(vty, " log-pdu-drops\n");
+}
+
+/*
* XPath: /frr-isisd:isis/instance/mpls/ldp-sync
*/
DEFPY(isis_mpls_ldp_sync, isis_mpls_ldp_sync_cmd, "mpls ldp-sync",
@@ -3280,6 +3310,7 @@ void isis_cli_init(void)
install_element(INTERFACE_NODE, &isis_ti_lfa_cmd);
install_element(ISIS_NODE, &log_adj_changes_cmd);
+ install_element(ISIS_NODE, &log_pdu_drops_cmd);
install_element(ISIS_NODE, &isis_mpls_ldp_sync_cmd);
install_element(ISIS_NODE, &no_isis_mpls_ldp_sync_cmd);
diff --git a/isisd/isis_common.h b/isisd/isis_common.h
index c908dc2e24..2ded68f84d 100644
--- a/isisd/isis_common.h
+++ b/isisd/isis_common.h
@@ -11,14 +11,6 @@
#ifndef ISIS_COMMON_H
#define ISIS_COMMON_H
-/*
- * Area Address
- */
-struct area_addr {
- uint8_t addr_len;
- uint8_t area_addr[20];
-};
-
struct isis_passwd {
uint8_t len;
#define ISIS_PASSWD_TYPE_UNUSED 0
diff --git a/isisd/isis_csm.c b/isisd/isis_csm.c
index 95bbc077a3..9e278d47f8 100644
--- a/isisd/isis_csm.c
+++ b/isisd/isis_csm.c
@@ -14,7 +14,7 @@
#include "if.h"
#include "linklist.h"
#include "command.h"
-#include "thread.h"
+#include "frrevent.h"
#include "hash.h"
#include "prefix.h"
#include "stream.h"
diff --git a/isisd/isis_dr.c b/isisd/isis_dr.c
index b1a4215813..3b92160809 100644
--- a/isisd/isis_dr.c
+++ b/isisd/isis_dr.c
@@ -13,7 +13,7 @@
#include "log.h"
#include "hash.h"
-#include "thread.h"
+#include "frrevent.h"
#include "linklist.h"
#include "vty.h"
#include "stream.h"
@@ -48,9 +48,9 @@ const char *isis_disflag2string(int disflag)
return NULL; /* not reached */
}
-void isis_run_dr(struct thread *thread)
+void isis_run_dr(struct event *thread)
{
- struct isis_circuit_arg *arg = THREAD_ARG(thread);
+ struct isis_circuit_arg *arg = EVENT_ARG(thread);
assert(arg);
@@ -211,8 +211,8 @@ int isis_dr_resign(struct isis_circuit *circuit, int level)
circuit->u.bc.is_dr[level - 1] = 0;
circuit->u.bc.run_dr_elect[level - 1] = 0;
- THREAD_OFF(circuit->u.bc.t_run_dr[level - 1]);
- THREAD_OFF(circuit->u.bc.t_refresh_pseudo_lsp[level - 1]);
+ EVENT_OFF(circuit->u.bc.t_run_dr[level - 1]);
+ EVENT_OFF(circuit->u.bc.t_refresh_pseudo_lsp[level - 1]);
circuit->lsp_regenerate_pending[level - 1] = 0;
memcpy(id, circuit->isis->sysid, ISIS_SYS_ID_LEN);
@@ -223,29 +223,27 @@ int isis_dr_resign(struct isis_circuit *circuit, int level)
if (level == 1) {
memset(circuit->u.bc.l1_desig_is, 0, ISIS_SYS_ID_LEN + 1);
- thread_add_timer(master, send_l1_psnp, circuit,
- isis_jitter(circuit->psnp_interval[level - 1],
- PSNP_JITTER),
- &circuit->t_send_psnp[0]);
+ event_add_timer(master, send_l1_psnp, circuit,
+ isis_jitter(circuit->psnp_interval[level - 1],
+ PSNP_JITTER),
+ &circuit->t_send_psnp[0]);
} else {
memset(circuit->u.bc.l2_desig_is, 0, ISIS_SYS_ID_LEN + 1);
- thread_add_timer(master, send_l2_psnp, circuit,
- isis_jitter(circuit->psnp_interval[level - 1],
- PSNP_JITTER),
- &circuit->t_send_psnp[1]);
+ event_add_timer(master, send_l2_psnp, circuit,
+ isis_jitter(circuit->psnp_interval[level - 1],
+ PSNP_JITTER),
+ &circuit->t_send_psnp[1]);
}
- THREAD_OFF(circuit->t_send_csnp[level - 1]);
+ EVENT_OFF(circuit->t_send_csnp[level - 1]);
- thread_add_timer(master, isis_run_dr,
- &circuit->level_arg[level - 1],
- 2 * circuit->hello_interval[level - 1],
- &circuit->u.bc.t_run_dr[level - 1]);
+ event_add_timer(master, isis_run_dr, &circuit->level_arg[level - 1],
+ 2 * circuit->hello_interval[level - 1],
+ &circuit->u.bc.t_run_dr[level - 1]);
- thread_add_event(master, isis_event_dis_status_change, circuit, 0,
- NULL);
+ event_add_event(master, isis_event_dis_status_change, circuit, 0, NULL);
return ISIS_OK;
}
@@ -276,10 +274,10 @@ int isis_dr_commence(struct isis_circuit *circuit, int level)
assert(circuit->circuit_id); /* must be non-zero */
lsp_generate_pseudo(circuit, 1);
- thread_add_timer(master, send_l1_csnp, circuit,
- isis_jitter(circuit->csnp_interval[level - 1],
- CSNP_JITTER),
- &circuit->t_send_csnp[0]);
+ event_add_timer(master, send_l1_csnp, circuit,
+ isis_jitter(circuit->csnp_interval[level - 1],
+ CSNP_JITTER),
+ &circuit->t_send_csnp[0]);
} else {
memcpy(old_dr, circuit->u.bc.l2_desig_is, ISIS_SYS_ID_LEN + 1);
@@ -296,18 +294,16 @@ int isis_dr_commence(struct isis_circuit *circuit, int level)
assert(circuit->circuit_id); /* must be non-zero */
lsp_generate_pseudo(circuit, 2);
- thread_add_timer(master, send_l2_csnp, circuit,
- isis_jitter(circuit->csnp_interval[level - 1],
- CSNP_JITTER),
- &circuit->t_send_csnp[1]);
+ event_add_timer(master, send_l2_csnp, circuit,
+ isis_jitter(circuit->csnp_interval[level - 1],
+ CSNP_JITTER),
+ &circuit->t_send_csnp[1]);
}
- thread_add_timer(master, isis_run_dr,
- &circuit->level_arg[level - 1],
- 2 * circuit->hello_interval[level - 1],
- &circuit->u.bc.t_run_dr[level - 1]);
- thread_add_event(master, isis_event_dis_status_change, circuit, 0,
- NULL);
+ event_add_timer(master, isis_run_dr, &circuit->level_arg[level - 1],
+ 2 * circuit->hello_interval[level - 1],
+ &circuit->u.bc.t_run_dr[level - 1]);
+ event_add_event(master, isis_event_dis_status_change, circuit, 0, NULL);
return ISIS_OK;
}
diff --git a/isisd/isis_dr.h b/isisd/isis_dr.h
index 2b9bf60ffa..135916a4cb 100644
--- a/isisd/isis_dr.h
+++ b/isisd/isis_dr.h
@@ -11,7 +11,7 @@
#ifndef _ZEBRA_ISIS_DR_H
#define _ZEBRA_ISIS_DR_H
-void isis_run_dr(struct thread *thread);
+void isis_run_dr(struct event *thread);
int isis_dr_elect(struct isis_circuit *circuit, int level);
int isis_dr_resign(struct isis_circuit *circuit, int level);
int isis_dr_commence(struct isis_circuit *circuit, int level);
diff --git a/isisd/isis_dynhn.c b/isisd/isis_dynhn.c
index ef21de327e..61c49d08a7 100644
--- a/isisd/isis_dynhn.c
+++ b/isisd/isis_dynhn.c
@@ -16,7 +16,7 @@
#include "stream.h"
#include "command.h"
#include "if.h"
-#include "thread.h"
+#include "frrevent.h"
#include "isisd/isis_constants.h"
#include "isisd/isis_common.h"
@@ -29,14 +29,14 @@
DEFINE_MTYPE_STATIC(ISISD, ISIS_DYNHN, "ISIS dyn hostname");
-static void dyn_cache_cleanup(struct thread *);
+static void dyn_cache_cleanup(struct event *);
void dyn_cache_init(struct isis *isis)
{
isis->dyn_cache = list_new();
if (!CHECK_FLAG(im->options, F_ISIS_UNIT_TEST))
- thread_add_timer(master, dyn_cache_cleanup, isis, 120,
- &isis->t_dync_clean);
+ event_add_timer(master, dyn_cache_cleanup, isis, 120,
+ &isis->t_dync_clean);
}
void dyn_cache_finish(struct isis *isis)
@@ -44,7 +44,7 @@ void dyn_cache_finish(struct isis *isis)
struct listnode *node, *nnode;
struct isis_dynhn *dyn;
- THREAD_OFF(isis->t_dync_clean);
+ EVENT_OFF(isis->t_dync_clean);
for (ALL_LIST_ELEMENTS(isis->dyn_cache, node, nnode, dyn)) {
list_delete_node(isis->dyn_cache, node);
@@ -54,14 +54,14 @@ void dyn_cache_finish(struct isis *isis)
list_delete(&isis->dyn_cache);
}
-static void dyn_cache_cleanup(struct thread *thread)
+static void dyn_cache_cleanup(struct event *thread)
{
struct listnode *node, *nnode;
struct isis_dynhn *dyn;
time_t now = time(NULL);
struct isis *isis = NULL;
- isis = THREAD_ARG(thread);
+ isis = EVENT_ARG(thread);
isis->t_dync_clean = NULL;
@@ -72,7 +72,7 @@ static void dyn_cache_cleanup(struct thread *thread)
XFREE(MTYPE_ISIS_DYNHN, dyn);
}
- thread_add_timer(master, dyn_cache_cleanup, isis, 120,
+ event_add_timer(master, dyn_cache_cleanup, isis, 120,
&isis->t_dync_clean);
}
@@ -145,12 +145,10 @@ void dynhn_print_all(struct vty *vty, struct isis *isis)
vty_out(vty, "Level System ID Dynamic Hostname\n");
for (ALL_LIST_ELEMENTS_RO(isis->dyn_cache, node, dyn)) {
vty_out(vty, "%-7d", dyn->level);
- vty_out(vty, "%-15s%-15s\n", sysid_print(dyn->id),
- dyn->hostname);
+ vty_out(vty, "%pSY %-15s\n", dyn->id, dyn->hostname);
}
- vty_out(vty, " * %s %s\n", sysid_print(isis->sysid),
- cmd_hostname_get());
+ vty_out(vty, " * %pSY %s\n", isis->sysid, cmd_hostname_get());
return;
}
diff --git a/isisd/isis_events.c b/isisd/isis_events.c
index d7b3969114..32231a079f 100644
--- a/isisd/isis_events.c
+++ b/isisd/isis_events.c
@@ -13,7 +13,7 @@
#include "if.h"
#include "linklist.h"
#include "command.h"
-#include "thread.h"
+#include "frrevent.h"
#include "hash.h"
#include "prefix.h"
#include "stream.h"
@@ -63,23 +63,23 @@ static void circuit_commence_level(struct isis_circuit *circuit, int level)
if (!circuit->is_passive) {
if (level == 1) {
- thread_add_timer(master, send_l1_psnp, circuit,
- isis_jitter(circuit->psnp_interval[0],
- PSNP_JITTER),
- &circuit->t_send_psnp[0]);
+ event_add_timer(master, send_l1_psnp, circuit,
+ isis_jitter(circuit->psnp_interval[0],
+ PSNP_JITTER),
+ &circuit->t_send_psnp[0]);
} else {
- thread_add_timer(master, send_l2_psnp, circuit,
- isis_jitter(circuit->psnp_interval[1],
- PSNP_JITTER),
- &circuit->t_send_psnp[1]);
+ event_add_timer(master, send_l2_psnp, circuit,
+ isis_jitter(circuit->psnp_interval[1],
+ PSNP_JITTER),
+ &circuit->t_send_psnp[1]);
}
}
if (circuit->circ_type == CIRCUIT_T_BROADCAST) {
- thread_add_timer(master, isis_run_dr,
- &circuit->level_arg[level - 1],
- 2 * circuit->hello_interval[level - 1],
- &circuit->u.bc.t_run_dr[level - 1]);
+ event_add_timer(master, isis_run_dr,
+ &circuit->level_arg[level - 1],
+ 2 * circuit->hello_interval[level - 1],
+ &circuit->u.bc.t_run_dr[level - 1]);
send_hello_sched(circuit, level, TRIGGERED_IIH_DELAY);
circuit->u.bc.lan_neighs[level - 1] = list_new();
@@ -96,13 +96,13 @@ static void circuit_resign_level(struct isis_circuit *circuit, int level)
circuit->area->area_tag, circuit->circuit_id,
circuit->interface->name, level);
- THREAD_OFF(circuit->t_send_csnp[idx]);
- THREAD_OFF(circuit->t_send_psnp[idx]);
+ EVENT_OFF(circuit->t_send_csnp[idx]);
+ EVENT_OFF(circuit->t_send_psnp[idx]);
if (circuit->circ_type == CIRCUIT_T_BROADCAST) {
- THREAD_OFF(circuit->u.bc.t_send_lan_hello[idx]);
- THREAD_OFF(circuit->u.bc.t_run_dr[idx]);
- THREAD_OFF(circuit->u.bc.t_refresh_pseudo_lsp[idx]);
+ EVENT_OFF(circuit->u.bc.t_send_lan_hello[idx]);
+ EVENT_OFF(circuit->u.bc.t_run_dr[idx]);
+ EVENT_OFF(circuit->u.bc.t_refresh_pseudo_lsp[idx]);
circuit->lsp_regenerate_pending[idx] = 0;
circuit->u.bc.run_dr_elect[idx] = 0;
circuit->u.bc.is_dr[idx] = 0;
@@ -196,11 +196,11 @@ void isis_circuit_is_type_set(struct isis_circuit *circuit, int newtype)
/* events supporting code */
-void isis_event_dis_status_change(struct thread *thread)
+void isis_event_dis_status_change(struct event *thread)
{
struct isis_circuit *circuit;
- circuit = THREAD_ARG(thread);
+ circuit = EVENT_ARG(thread);
/* invalid arguments */
if (!circuit || !circuit->area)
@@ -217,8 +217,8 @@ void isis_event_auth_failure(char *area_tag, const char *error_string,
uint8_t *sysid)
{
if (IS_DEBUG_EVENTS)
- zlog_debug("ISIS-Evt (%s) Authentication failure %s from %s",
- area_tag, error_string, sysid_print(sysid));
+ zlog_debug("ISIS-Evt (%s) Authentication failure %s from %pSY",
+ area_tag, error_string, sysid);
return;
}
diff --git a/isisd/isis_events.h b/isisd/isis_events.h
index e827f75a83..a0ac964fab 100644
--- a/isisd/isis_events.h
+++ b/isisd/isis_events.h
@@ -18,7 +18,7 @@ void isis_event_circuit_type_change(struct isis_circuit *circuit, int newtype);
/*
* Events related to adjacencies
*/
-void isis_event_dis_status_change(struct thread *thread);
+void isis_event_dis_status_change(struct event *thread);
/*
* Error events
diff --git a/isisd/isis_ldp_sync.c b/isisd/isis_ldp_sync.c
index 817e2a2015..53676ffe36 100644
--- a/isisd/isis_ldp_sync.c
+++ b/isisd/isis_ldp_sync.c
@@ -9,7 +9,7 @@
#include "monotime.h"
#include "memory.h"
-#include "thread.h"
+#include "frrevent.h"
#include "prefix.h"
#include "table.h"
#include "vty.h"
@@ -171,7 +171,7 @@ void isis_ldp_sync_if_complete(struct isis_circuit *circuit)
if (ldp_sync_info->state == LDP_IGP_SYNC_STATE_REQUIRED_NOT_UP)
ldp_sync_info->state = LDP_IGP_SYNC_STATE_REQUIRED_UP;
- THREAD_OFF(ldp_sync_info->t_holddown);
+ EVENT_OFF(ldp_sync_info->t_holddown);
isis_ldp_sync_set_if_metric(circuit, true);
}
@@ -191,7 +191,7 @@ void isis_ldp_sync_ldp_fail(struct isis_circuit *circuit)
if (ldp_sync_info &&
ldp_sync_info->enabled == LDP_IGP_SYNC_ENABLED &&
ldp_sync_info->state != LDP_IGP_SYNC_STATE_NOT_REQUIRED) {
- THREAD_OFF(ldp_sync_info->t_holddown);
+ EVENT_OFF(ldp_sync_info->t_holddown);
ldp_sync_info->state = LDP_IGP_SYNC_STATE_REQUIRED_NOT_UP;
isis_ldp_sync_set_if_metric(circuit, true);
}
@@ -331,7 +331,7 @@ void isis_ldp_sync_set_if_metric(struct isis_circuit *circuit, bool run_regen)
/*
* LDP-SYNC holddown timer routines
*/
-static void isis_ldp_sync_holddown_timer(struct thread *thread)
+static void isis_ldp_sync_holddown_timer(struct event *thread)
{
struct isis_circuit *circuit;
struct ldp_sync_info *ldp_sync_info;
@@ -340,7 +340,7 @@ static void isis_ldp_sync_holddown_timer(struct thread *thread)
* didn't receive msg from LDP indicating sync-complete
* restore interface cost to original value
*/
- circuit = THREAD_ARG(thread);
+ circuit = EVENT_ARG(thread);
if (circuit->ldp_sync_info == NULL)
return;
@@ -373,9 +373,8 @@ void isis_ldp_sync_holddown_timer_add(struct isis_circuit *circuit)
ils_debug("%s: start holddown timer for %s time %d", __func__,
circuit->interface->name, ldp_sync_info->holddown);
- thread_add_timer(master, isis_ldp_sync_holddown_timer,
- circuit, ldp_sync_info->holddown,
- &ldp_sync_info->t_holddown);
+ event_add_timer(master, isis_ldp_sync_holddown_timer, circuit,
+ ldp_sync_info->holddown, &ldp_sync_info->t_holddown);
}
/*
@@ -517,7 +516,7 @@ void isis_if_ldp_sync_disable(struct isis_circuit *circuit)
if (!CHECK_FLAG(area->ldp_sync_cmd.flags, LDP_SYNC_FLAG_ENABLE))
return;
- THREAD_OFF(ldp_sync_info->t_holddown);
+ EVENT_OFF(ldp_sync_info->t_holddown);
ldp_sync_info->state = LDP_IGP_SYNC_STATE_NOT_REQUIRED;
isis_ldp_sync_set_if_metric(circuit, true);
}
@@ -576,8 +575,8 @@ static void isis_circuit_ldp_sync_print_vty(struct isis_circuit *circuit,
break;
case LDP_IGP_SYNC_STATE_REQUIRED_NOT_UP:
if (ldp_sync_info->t_holddown != NULL) {
- struct timeval remain = thread_timer_remain(
- ldp_sync_info->t_holddown);
+ struct timeval remain =
+ event_timer_remain(ldp_sync_info->t_holddown);
vty_out(vty,
" Holddown timer is running %lld.%03lld remaining\n",
(long long)remain.tv_sec,
diff --git a/isisd/isis_lfa.c b/isisd/isis_lfa.c
index 599dca1298..abb6168393 100644
--- a/isisd/isis_lfa.c
+++ b/isisd/isis_lfa.c
@@ -1388,9 +1388,9 @@ static struct rlfa *rlfa_lookup(struct isis_spftree *spftree,
return rlfa_tree_find(&spftree->lfa.remote.rlfas, &s);
}
-static void isis_area_verify_routes_cb(struct thread *thread)
+static void isis_area_verify_routes_cb(struct event *thread)
{
- struct isis_area *area = THREAD_ARG(thread);
+ struct isis_area *area = EVENT_ARG(thread);
if (IS_DEBUG_LFA)
zlog_debug("ISIS-LFA: updating RLFAs in the RIB");
@@ -1466,8 +1466,8 @@ int isis_rlfa_activate(struct isis_spftree *spftree, struct rlfa *rlfa,
if (ldp_label == MPLS_INVALID_LABEL) {
if (IS_DEBUG_LFA)
zlog_debug(
- "ISIS-LFA: failed to activate RLFA: missing LDP label to reach PQ node through %s",
- sysid_print(vadj->sadj->id));
+ "ISIS-LFA: failed to activate RLFA: missing LDP label to reach PQ node through %pSY",
+ vadj->sadj->id);
return -1;
}
@@ -1506,9 +1506,9 @@ int isis_rlfa_activate(struct isis_spftree *spftree, struct rlfa *rlfa,
spftree->route_table_backup);
spftree->lfa.protection_counters.rlfa[vertex->N.ip.priority] += 1;
- THREAD_OFF(area->t_rlfa_rib_update);
- thread_add_timer(master, isis_area_verify_routes_cb, area, 2,
- &area->t_rlfa_rib_update);
+ EVENT_OFF(area->t_rlfa_rib_update);
+ event_add_timer(master, isis_area_verify_routes_cb, area, 2,
+ &area->t_rlfa_rib_update);
return 0;
}
@@ -1525,9 +1525,9 @@ void isis_rlfa_deactivate(struct isis_spftree *spftree, struct rlfa *rlfa)
isis_route_delete(area, rn, spftree->route_table_backup);
spftree->lfa.protection_counters.rlfa[vertex->N.ip.priority] -= 1;
- THREAD_OFF(area->t_rlfa_rib_update);
- thread_add_timer(master, isis_area_verify_routes_cb, area, 2,
- &area->t_rlfa_rib_update);
+ EVENT_OFF(area->t_rlfa_rib_update);
+ event_add_timer(master, isis_area_verify_routes_cb, area, 2,
+ &area->t_rlfa_rib_update);
}
void isis_rlfa_list_init(struct isis_spftree *spftree)
diff --git a/isisd/isis_lsp.c b/isisd/isis_lsp.c
index 4a332d0aed..fb69448d04 100644
--- a/isisd/isis_lsp.c
+++ b/isisd/isis_lsp.c
@@ -12,7 +12,7 @@
#include <zebra.h>
#include "linklist.h"
-#include "thread.h"
+#include "frrevent.h"
#include "vty.h"
#include "stream.h"
#include "memory.h"
@@ -49,9 +49,9 @@
DEFINE_MTYPE_STATIC(ISISD, ISIS_LSP, "ISIS LSP");
-static void lsp_refresh(struct thread *thread);
-static void lsp_l1_refresh_pseudo(struct thread *thread);
-static void lsp_l2_refresh_pseudo(struct thread *thread);
+static void lsp_refresh(struct event *thread);
+static void lsp_l1_refresh_pseudo(struct event *thread);
+static void lsp_l2_refresh_pseudo(struct event *thread);
static void lsp_destroy(struct isis_lsp *lsp);
@@ -193,10 +193,9 @@ int lsp_compare(char *areatag, struct isis_lsp *lsp, uint32_t seqno,
|| (lsp->hdr.rem_lifetime != 0 && rem_lifetime != 0))) {
if (IS_DEBUG_SNP_PACKETS) {
zlog_debug(
- "ISIS-Snp (%s): Compare LSP %s seq 0x%08x, cksum 0x%04hx, lifetime %hus",
- areatag, rawlspid_print(lsp->hdr.lsp_id),
- lsp->hdr.seqno, lsp->hdr.checksum,
- lsp->hdr.rem_lifetime);
+ "ISIS-Snp (%s): Compare LSP %pLS seq 0x%08x, cksum 0x%04hx, lifetime %hus",
+ areatag, lsp->hdr.lsp_id, lsp->hdr.seqno,
+ lsp->hdr.checksum, lsp->hdr.rem_lifetime);
zlog_debug(
"ISIS-Snp (%s): is equal to ours seq 0x%08x, cksum 0x%04hx, lifetime %hus",
areatag, seqno, checksum, rem_lifetime);
@@ -223,9 +222,9 @@ int lsp_compare(char *areatag, struct isis_lsp *lsp, uint32_t seqno,
&& lsp->hdr.rem_lifetime)))) {
if (IS_DEBUG_SNP_PACKETS) {
zlog_debug(
- "ISIS-Snp (%s): Compare LSP %s seq 0x%08x, cksum 0x%04hx, lifetime %hus",
- areatag, rawlspid_print(lsp->hdr.lsp_id), seqno,
- checksum, rem_lifetime);
+ "ISIS-Snp (%s): Compare LSP %pLS seq 0x%08x, cksum 0x%04hx, lifetime %hus",
+ areatag, lsp->hdr.lsp_id, seqno, checksum,
+ rem_lifetime);
zlog_debug(
"ISIS-Snp (%s): is newer than ours seq 0x%08x, cksum 0x%04hx, lifetime %hus",
areatag, lsp->hdr.seqno, lsp->hdr.checksum,
@@ -234,9 +233,10 @@ int lsp_compare(char *areatag, struct isis_lsp *lsp, uint32_t seqno,
return LSP_NEWER;
}
if (IS_DEBUG_SNP_PACKETS) {
- zlog_debug("ISIS-Snp (%s): Compare LSP %s seq 0x%08x, cksum 0x%04hx, lifetime %hus",
- areatag, rawlspid_print(lsp->hdr.lsp_id), seqno,
- checksum, rem_lifetime);
+ zlog_debug(
+ "ISIS-Snp (%s): Compare LSP %pLS seq 0x%08x, cksum 0x%04hx, lifetime %hus",
+ areatag, lsp->hdr.lsp_id, seqno, checksum,
+ rem_lifetime);
zlog_debug(
"ISIS-Snp (%s): is older than ours seq 0x%08x, cksum 0x%04hx, lifetime %hus",
areatag, lsp->hdr.seqno, lsp->hdr.checksum,
@@ -429,9 +429,9 @@ bool isis_level2_adj_up(struct isis_area *area)
/*
* Unset the overload bit after the timer expires
*/
-void set_overload_on_start_timer(struct thread *thread)
+void set_overload_on_start_timer(struct event *thread)
{
- struct isis_area *area = THREAD_ARG(thread);
+ struct isis_area *area = EVENT_ARG(thread);
assert(area);
area->t_overload_on_startup_timer = NULL;
@@ -554,8 +554,8 @@ void lsp_update(struct isis_lsp *lsp, struct isis_lsp_hdr *hdr,
if (lsp->own_lsp) {
flog_err(
EC_LIB_DEVELOPMENT,
- "ISIS-Upd (%s): BUG updating LSP %s still marked as own LSP",
- area->area_tag, rawlspid_print(lsp->hdr.lsp_id));
+ "ISIS-Upd (%s): BUG updating LSP %pLS still marked as own LSP",
+ area->area_tag, lsp->hdr.lsp_id);
lsp_clear_data(lsp);
lsp->own_lsp = 0;
}
@@ -634,10 +634,8 @@ struct isis_lsp *lsp_new(struct isis_area *area, uint8_t *lsp_id,
put_lsp_hdr(lsp, NULL, false);
if (IS_DEBUG_EVENTS)
- zlog_debug("New LSP with ID %s-%02x-%02x len %d seqnum %08x",
- sysid_print(lsp_id), LSP_PSEUDO_ID(lsp->hdr.lsp_id),
- LSP_FRAGMENT(lsp->hdr.lsp_id), lsp->hdr.pdu_len,
- lsp->hdr.seqno);
+ zlog_debug("New LSP with ID %pLS len %d seqnum %08x", lsp_id,
+ lsp->hdr.pdu_len, lsp->hdr.seqno);
return lsp;
}
@@ -704,7 +702,7 @@ void lspid_print(uint8_t *lsp_id, char *dest, size_t dest_len, char dynhost,
else if (!memcmp(isis->sysid, lsp_id, ISIS_SYS_ID_LEN) && dynhost)
snprintf(id, sizeof(id), "%.14s", cmd_hostname_get());
else
- memcpy(id, sysid_print(lsp_id), 15);
+ snprintf(id, sizeof(id), "%pSY", lsp_id);
if (frag)
snprintf(dest, dest_len, "%s.%02x-%02x", id,
@@ -1250,10 +1248,8 @@ static void lsp_build(struct isis_lsp *lsp, struct isis_area *area)
if (LSP_PSEUDO_ID(ne_id)) {
if (area->oldmetric) {
lsp_debug(
- "ISIS (%s): Adding DIS %s.%02x as old-style neighbor",
- area->area_tag,
- sysid_print(ne_id),
- LSP_PSEUDO_ID(ne_id));
+ "ISIS (%s): Adding DIS %pPN as old-style neighbor",
+ area->area_tag, ne_id);
isis_tlvs_add_oldstyle_reach(
lsp->tlvs, ne_id,
metric);
@@ -1279,9 +1275,8 @@ static void lsp_build(struct isis_lsp *lsp, struct isis_area *area)
if (area->oldmetric) {
lsp_debug(
- "ISIS (%s): Adding old-style is reach for %s",
- area->area_tag,
- sysid_print(ne_id));
+ "ISIS (%s): Adding old-style is reach for %pSY",
+ area->area_tag, ne_id);
isis_tlvs_add_oldstyle_reach(
lsp->tlvs, ne_id, metric);
}
@@ -1372,7 +1367,7 @@ int lsp_generate(struct isis_area *area, int level)
return ISIS_ERROR;
/* Check if config is still being processed */
- if (thread_is_scheduled(t_isis_cfg))
+ if (event_is_scheduled(t_isis_cfg))
return ISIS_OK;
memset(&lspid, 0, ISIS_SYS_ID_LEN + 2);
@@ -1384,9 +1379,9 @@ int lsp_generate(struct isis_area *area, int level)
overload_time = isis_restart_read_overload_time(area);
if (overload_time > 0) {
isis_area_overload_bit_set(area, true);
- thread_add_timer(master, set_overload_on_start_timer,
- area, overload_time,
- &area->t_overload_on_startup_timer);
+ event_add_timer(master, set_overload_on_start_timer,
+ area, overload_time,
+ &area->t_overload_on_startup_timer);
}
device_startup = false;
}
@@ -1418,19 +1413,18 @@ int lsp_generate(struct isis_area *area, int level)
refresh_time = lsp_refresh_time(newlsp, rem_lifetime);
- THREAD_OFF(area->t_lsp_refresh[level - 1]);
+ EVENT_OFF(area->t_lsp_refresh[level - 1]);
area->lsp_regenerate_pending[level - 1] = 0;
- thread_add_timer(master, lsp_refresh,
- &area->lsp_refresh_arg[level - 1], refresh_time,
- &area->t_lsp_refresh[level - 1]);
+ event_add_timer(master, lsp_refresh, &area->lsp_refresh_arg[level - 1],
+ refresh_time, &area->t_lsp_refresh[level - 1]);
if (IS_DEBUG_UPDATE_PACKETS) {
- zlog_debug("ISIS-Upd (%s): Building L%d LSP %s, len %hu, seq 0x%08x, cksum 0x%04hx, lifetime %hus refresh %hus",
- area->area_tag, level,
- rawlspid_print(newlsp->hdr.lsp_id),
- newlsp->hdr.pdu_len, newlsp->hdr.seqno,
- newlsp->hdr.checksum, newlsp->hdr.rem_lifetime,
- refresh_time);
+ zlog_debug(
+ "ISIS-Upd (%s): Building L%d LSP %pLS, len %hu, seq 0x%08x, cksum 0x%04hx, lifetime %hus refresh %hus",
+ area->area_tag, level, newlsp->hdr.lsp_id,
+ newlsp->hdr.pdu_len, newlsp->hdr.seqno,
+ newlsp->hdr.checksum, newlsp->hdr.rem_lifetime,
+ refresh_time);
}
sched_debug(
"ISIS (%s): Built L%d LSP. Set triggered regenerate to non-pending.",
@@ -1501,15 +1495,14 @@ static int lsp_regenerate(struct isis_area *area, int level)
lsp_seqno_update(lsp);
refresh_time = lsp_refresh_time(lsp, rem_lifetime);
- thread_add_timer(master, lsp_refresh,
- &area->lsp_refresh_arg[level - 1], refresh_time,
- &area->t_lsp_refresh[level - 1]);
+ event_add_timer(master, lsp_refresh, &area->lsp_refresh_arg[level - 1],
+ refresh_time, &area->t_lsp_refresh[level - 1]);
area->lsp_regenerate_pending[level - 1] = 0;
if (IS_DEBUG_UPDATE_PACKETS) {
zlog_debug(
- "ISIS-Upd (%s): Refreshed our L%d LSP %s, len %hu, seq 0x%08x, cksum 0x%04hx, lifetime %hus refresh %hus",
- area->area_tag, level, rawlspid_print(lsp->hdr.lsp_id),
+ "ISIS-Upd (%s): Refreshed our L%d LSP %pLS, len %hu, seq 0x%08x, cksum 0x%04hx, lifetime %hus refresh %hus",
+ area->area_tag, level, lsp->hdr.lsp_id,
lsp->hdr.pdu_len, lsp->hdr.seqno, lsp->hdr.checksum,
lsp->hdr.rem_lifetime, refresh_time);
}
@@ -1523,9 +1516,9 @@ static int lsp_regenerate(struct isis_area *area, int level)
/*
* Something has changed or periodic refresh -> regenerate LSP
*/
-static void lsp_refresh(struct thread *thread)
+static void lsp_refresh(struct event *thread)
{
- struct lsp_refresh_arg *arg = THREAD_ARG(thread);
+ struct lsp_refresh_arg *arg = EVENT_ARG(thread);
assert(arg);
@@ -1605,7 +1598,7 @@ int _lsp_regenerate_schedule(struct isis_area *area, int level,
* Note: in case of a BFD 'down' message the refresh is
* scheduled once again just to be sure
*/
- struct timeval remain = thread_timer_remain(
+ struct timeval remain = event_timer_remain(
area->t_lsp_refresh[lvl - 1]);
sched_debug(
"ISIS (%s): Regeneration is already pending, nothing todo. (Due in %lld.%03lld seconds)",
@@ -1629,7 +1622,7 @@ int _lsp_regenerate_schedule(struct isis_area *area, int level,
"ISIS (%s): Will schedule regen timer. Last run was: %lld, Now is: %lld",
area->area_tag, (long long)lsp->last_generated,
(long long)now);
- THREAD_OFF(area->t_lsp_refresh[lvl - 1]);
+ EVENT_OFF(area->t_lsp_refresh[lvl - 1]);
diff = now - lsp->last_generated;
if (diff < area->lsp_gen_interval[lvl - 1]
&& !(area->bfd_signalled_down)) {
@@ -1668,10 +1661,9 @@ int _lsp_regenerate_schedule(struct isis_area *area, int level,
}
area->lsp_regenerate_pending[lvl - 1] = 1;
- thread_add_timer_msec(master, lsp_refresh,
- &area->lsp_refresh_arg[lvl - 1],
- timeout,
- &area->t_lsp_refresh[lvl - 1]);
+ event_add_timer_msec(master, lsp_refresh,
+ &area->lsp_refresh_arg[lvl - 1], timeout,
+ &area->t_lsp_refresh[lvl - 1]);
}
if (all_pseudo) {
@@ -1701,9 +1693,9 @@ static void lsp_build_pseudo(struct isis_lsp *lsp, struct isis_circuit *circuit,
lsp_clear_data(lsp);
lsp->tlvs = isis_alloc_tlvs();
lsp_debug(
- "ISIS (%s): Constructing pseudo LSP %s for interface %s level %d",
- area->area_tag, rawlspid_print(lsp->hdr.lsp_id),
- circuit->interface->name, level);
+ "ISIS (%s): Constructing pseudo LSP %pLS for interface %s level %d",
+ area->area_tag, lsp->hdr.lsp_id, circuit->interface->name,
+ level);
lsp->level = level;
/* RFC3787 section 4 SHOULD not set overload bit in pseudo LSPs */
@@ -1720,10 +1712,8 @@ static void lsp_build_pseudo(struct isis_lsp *lsp, struct isis_circuit *circuit,
if (circuit->area->oldmetric) {
isis_tlvs_add_oldstyle_reach(lsp->tlvs, ne_id, 0);
- lsp_debug(
- "ISIS (%s): Adding %s.%02x as old-style neighbor (self)",
- area->area_tag, sysid_print(ne_id),
- LSP_PSEUDO_ID(ne_id));
+ lsp_debug("ISIS (%s): Adding %pPN as old-style neighbor (self)",
+ area->area_tag, ne_id);
}
if (circuit->area->newmetric) {
if (area_is_mt(circuit->area))
@@ -1731,10 +1721,8 @@ static void lsp_build_pseudo(struct isis_lsp *lsp, struct isis_circuit *circuit,
else
mtid = ISIS_MT_DISABLE;
isis_tlvs_add_extended_reach(lsp->tlvs, mtid, ne_id, 0, NULL);
- lsp_debug(
- "ISIS (%s): Adding %s.%02x as te-style neighbor (self)",
- area->area_tag, sysid_print(ne_id),
- LSP_PSEUDO_ID(ne_id));
+ lsp_debug("ISIS (%s): Adding %pPN as te-style neighbor (self)",
+ area->area_tag, ne_id);
}
adj_list = list_new();
@@ -1743,8 +1731,8 @@ static void lsp_build_pseudo(struct isis_lsp *lsp, struct isis_circuit *circuit,
for (ALL_LIST_ELEMENTS_RO(adj_list, node, adj)) {
if (!(adj->level & level)) {
lsp_debug(
- "ISIS (%s): Ignoring neighbor %s, level does not intersect",
- area->area_tag, sysid_print(adj->sysid));
+ "ISIS (%s): Ignoring neighbor %pSY, level does not intersect",
+ area->area_tag, adj->sysid);
continue;
}
@@ -1756,8 +1744,8 @@ static void lsp_build_pseudo(struct isis_lsp *lsp, struct isis_circuit *circuit,
&& !(level == IS_LEVEL_2
&& adj->sys_type == ISIS_SYSTYPE_L2_IS)) {
lsp_debug(
- "ISIS (%s): Ignoring neighbor %s, level does not match",
- area->area_tag, sysid_print(adj->sysid));
+ "ISIS (%s): Ignoring neighbor %pSY, level does not match",
+ area->area_tag, adj->sysid);
continue;
}
@@ -1765,18 +1753,16 @@ static void lsp_build_pseudo(struct isis_lsp *lsp, struct isis_circuit *circuit,
if (circuit->area->oldmetric) {
isis_tlvs_add_oldstyle_reach(lsp->tlvs, ne_id, 0);
lsp_debug(
- "ISIS (%s): Adding %s.%02x as old-style neighbor (peer)",
- area->area_tag, sysid_print(ne_id),
- LSP_PSEUDO_ID(ne_id));
+ "ISIS (%s): Adding %pPN as old-style neighbor (peer)",
+ area->area_tag, ne_id);
}
if (circuit->area->newmetric) {
isis_tlvs_add_extended_reach(lsp->tlvs,
ISIS_MT_IPV4_UNICAST,
ne_id, 0, NULL);
lsp_debug(
- "ISIS (%s): Adding %s.%02x as te-style neighbor (peer)",
- area->area_tag, sysid_print(ne_id),
- LSP_PSEUDO_ID(ne_id));
+ "ISIS (%s): Adding %pPN as te-style neighbor (peer)",
+ area->area_tag, ne_id);
}
}
list_delete(&adj_list);
@@ -1822,23 +1808,22 @@ int lsp_generate_pseudo(struct isis_circuit *circuit, int level)
lsp_flood(lsp, NULL);
refresh_time = lsp_refresh_time(lsp, rem_lifetime);
- THREAD_OFF(circuit->u.bc.t_refresh_pseudo_lsp[level - 1]);
+ EVENT_OFF(circuit->u.bc.t_refresh_pseudo_lsp[level - 1]);
circuit->lsp_regenerate_pending[level - 1] = 0;
if (level == IS_LEVEL_1)
- thread_add_timer(
- master, lsp_l1_refresh_pseudo, circuit, refresh_time,
- &circuit->u.bc.t_refresh_pseudo_lsp[level - 1]);
+ event_add_timer(master, lsp_l1_refresh_pseudo, circuit,
+ refresh_time,
+ &circuit->u.bc.t_refresh_pseudo_lsp[level - 1]);
else if (level == IS_LEVEL_2)
- thread_add_timer(
- master, lsp_l2_refresh_pseudo, circuit, refresh_time,
- &circuit->u.bc.t_refresh_pseudo_lsp[level - 1]);
+ event_add_timer(master, lsp_l2_refresh_pseudo, circuit,
+ refresh_time,
+ &circuit->u.bc.t_refresh_pseudo_lsp[level - 1]);
if (IS_DEBUG_UPDATE_PACKETS) {
zlog_debug(
- "ISIS-Upd (%s): Built L%d Pseudo LSP %s, len %hu, seq 0x%08x, cksum 0x%04hx, lifetime %hus, refresh %hus",
- circuit->area->area_tag, level,
- rawlspid_print(lsp->hdr.lsp_id), lsp->hdr.pdu_len,
- lsp->hdr.seqno, lsp->hdr.checksum,
+ "ISIS-Upd (%s): Built L%d Pseudo LSP %pLS, len %hu, seq 0x%08x, cksum 0x%04hx, lifetime %hus, refresh %hus",
+ circuit->area->area_tag, level, lsp->hdr.lsp_id,
+ lsp->hdr.pdu_len, lsp->hdr.seqno, lsp->hdr.checksum,
lsp->hdr.rem_lifetime, refresh_time);
}
@@ -1866,8 +1851,8 @@ static int lsp_regenerate_pseudo(struct isis_circuit *circuit, int level)
if (!lsp) {
flog_err(EC_LIB_DEVELOPMENT,
- "lsp_regenerate_pseudo: no l%d LSP %s found!", level,
- rawlspid_print(lsp_id));
+ "lsp_regenerate_pseudo: no l%d LSP %pLS found!", level,
+ lsp_id);
return ISIS_ERROR;
}
@@ -1880,20 +1865,19 @@ static int lsp_regenerate_pseudo(struct isis_circuit *circuit, int level)
refresh_time = lsp_refresh_time(lsp, rem_lifetime);
if (level == IS_LEVEL_1)
- thread_add_timer(
- master, lsp_l1_refresh_pseudo, circuit, refresh_time,
- &circuit->u.bc.t_refresh_pseudo_lsp[level - 1]);
+ event_add_timer(master, lsp_l1_refresh_pseudo, circuit,
+ refresh_time,
+ &circuit->u.bc.t_refresh_pseudo_lsp[level - 1]);
else if (level == IS_LEVEL_2)
- thread_add_timer(
- master, lsp_l2_refresh_pseudo, circuit, refresh_time,
- &circuit->u.bc.t_refresh_pseudo_lsp[level - 1]);
+ event_add_timer(master, lsp_l2_refresh_pseudo, circuit,
+ refresh_time,
+ &circuit->u.bc.t_refresh_pseudo_lsp[level - 1]);
if (IS_DEBUG_UPDATE_PACKETS) {
zlog_debug(
- "ISIS-Upd (%s): Refreshed L%d Pseudo LSP %s, len %hu, seq 0x%08x, cksum 0x%04hx, lifetime %hus, refresh %hus",
- circuit->area->area_tag, level,
- rawlspid_print(lsp->hdr.lsp_id), lsp->hdr.pdu_len,
- lsp->hdr.seqno, lsp->hdr.checksum,
+ "ISIS-Upd (%s): Refreshed L%d Pseudo LSP %pLS, len %hu, seq 0x%08x, cksum 0x%04hx, lifetime %hus, refresh %hus",
+ circuit->area->area_tag, level, lsp->hdr.lsp_id,
+ lsp->hdr.pdu_len, lsp->hdr.seqno, lsp->hdr.checksum,
lsp->hdr.rem_lifetime, refresh_time);
}
@@ -1903,12 +1887,12 @@ static int lsp_regenerate_pseudo(struct isis_circuit *circuit, int level)
/*
* Something has changed or periodic refresh -> regenerate pseudo LSP
*/
-static void lsp_l1_refresh_pseudo(struct thread *thread)
+static void lsp_l1_refresh_pseudo(struct event *thread)
{
struct isis_circuit *circuit;
uint8_t id[ISIS_SYS_ID_LEN + 2];
- circuit = THREAD_ARG(thread);
+ circuit = EVENT_ARG(thread);
circuit->u.bc.t_refresh_pseudo_lsp[0] = NULL;
circuit->lsp_regenerate_pending[0] = 0;
@@ -1925,12 +1909,12 @@ static void lsp_l1_refresh_pseudo(struct thread *thread)
lsp_regenerate_pseudo(circuit, IS_LEVEL_1);
}
-static void lsp_l2_refresh_pseudo(struct thread *thread)
+static void lsp_l2_refresh_pseudo(struct event *thread)
{
struct isis_circuit *circuit;
uint8_t id[ISIS_SYS_ID_LEN + 2];
- circuit = THREAD_ARG(thread);
+ circuit = EVENT_ARG(thread);
circuit->u.bc.t_refresh_pseudo_lsp[1] = NULL;
circuit->lsp_regenerate_pending[1] = 0;
@@ -1989,7 +1973,7 @@ int lsp_regenerate_schedule_pseudo(struct isis_circuit *circuit, int level)
}
if (circuit->lsp_regenerate_pending[lvl - 1]) {
- struct timeval remain = thread_timer_remain(
+ struct timeval remain = event_timer_remain(
circuit->u.bc.t_refresh_pseudo_lsp[lvl - 1]);
sched_debug(
"ISIS (%s): Regenerate is already pending, nothing todo. (Due in %lld.%03lld seconds)",
@@ -2013,7 +1997,7 @@ int lsp_regenerate_schedule_pseudo(struct isis_circuit *circuit, int level)
"ISIS (%s): Will schedule PSN regen timer. Last run was: %lld, Now is: %lld",
area->area_tag, (long long)lsp->last_generated,
(long long)now);
- THREAD_OFF(circuit->u.bc.t_refresh_pseudo_lsp[lvl - 1]);
+ EVENT_OFF(circuit->u.bc.t_refresh_pseudo_lsp[lvl - 1]);
diff = now - lsp->last_generated;
if (diff < circuit->area->lsp_gen_interval[lvl - 1]) {
timeout =
@@ -2032,11 +2016,11 @@ int lsp_regenerate_schedule_pseudo(struct isis_circuit *circuit, int level)
circuit->lsp_regenerate_pending[lvl - 1] = 1;
if (lvl == IS_LEVEL_1) {
- thread_add_timer_msec(
+ event_add_timer_msec(
master, lsp_l1_refresh_pseudo, circuit, timeout,
&circuit->u.bc.t_refresh_pseudo_lsp[lvl - 1]);
} else if (lvl == IS_LEVEL_2) {
- thread_add_timer_msec(
+ event_add_timer_msec(
master, lsp_l2_refresh_pseudo, circuit, timeout,
&circuit->u.bc.t_refresh_pseudo_lsp[lvl - 1]);
}
@@ -2049,7 +2033,7 @@ int lsp_regenerate_schedule_pseudo(struct isis_circuit *circuit, int level)
* Walk through LSPs for an area
* - set remaining lifetime
*/
-void lsp_tick(struct thread *thread)
+void lsp_tick(struct event *thread)
{
struct isis_area *area;
struct isis_lsp *lsp;
@@ -2057,10 +2041,10 @@ void lsp_tick(struct thread *thread)
uint16_t rem_lifetime;
bool fabricd_sync_incomplete = false;
- area = THREAD_ARG(thread);
+ area = EVENT_ARG(thread);
assert(area);
area->t_tick = NULL;
- thread_add_timer(master, lsp_tick, area, 1, &area->t_tick);
+ event_add_timer(master, lsp_tick, area, 1, &area->t_tick);
struct isis_circuit *fabricd_init_c = fabricd_initial_sync_circuit(area);
@@ -2104,10 +2088,9 @@ void lsp_tick(struct thread *thread)
if (lsp->age_out == 0) {
zlog_debug(
- "ISIS-Upd (%s): L%u LSP %s seq 0x%08x aged out",
+ "ISIS-Upd (%s): L%u LSP %pLS seq 0x%08x aged out",
area->area_tag, lsp->level,
- rawlspid_print(lsp->hdr.lsp_id),
- lsp->hdr.seqno);
+ lsp->hdr.lsp_id, lsp->hdr.seqno);
/* if we're aging out fragment 0, lsp_destroy()
* below will delete all other fragments too,
@@ -2210,11 +2193,10 @@ void _lsp_flood(struct isis_lsp *lsp, struct isis_circuit *circuit,
const char *func, const char *file, int line)
{
if (IS_DEBUG_FLOODING) {
- zlog_debug("Flooding LSP %s%s%s (From %s %s:%d)",
- rawlspid_print(lsp->hdr.lsp_id),
- circuit ? " except on " : "",
- circuit ? circuit->interface->name : "",
- func, file, line);
+ zlog_debug("Flooding LSP %pLS%s%s (From %s %s:%d)",
+ lsp->hdr.lsp_id, circuit ? " except on " : "",
+ circuit ? circuit->interface->name : "", func, file,
+ line);
}
if (!fabricd)
diff --git a/isisd/isis_lsp.h b/isisd/isis_lsp.h
index 5bb2b949c7..3839a9504c 100644
--- a/isisd/isis_lsp.h
+++ b/isisd/isis_lsp.h
@@ -52,8 +52,8 @@ DECLARE_RBTREE_UNIQ(lspdb, struct isis_lsp, dbe, lspdb_compare);
void lsp_db_init(struct lspdb_head *head);
void lsp_db_fini(struct lspdb_head *head);
-void lsp_tick(struct thread *thread);
-void set_overload_on_start_timer(struct thread *thread);
+void lsp_tick(struct event *thread);
+void set_overload_on_start_timer(struct event *thread);
int lsp_generate(struct isis_area *area, int level);
#define lsp_regenerate_schedule(area, level, all_pseudo) \
diff --git a/isisd/isis_main.c b/isisd/isis_main.c
index 25ea187492..2f4e4e0bd6 100644
--- a/isisd/isis_main.c
+++ b/isisd/isis_main.c
@@ -10,7 +10,7 @@
#include <zebra.h>
#include "getopt.h"
-#include "thread.h"
+#include "frrevent.h"
#include "log.h"
#include <lib/version.h>
#include "command.h"
@@ -77,7 +77,7 @@ static const struct option longopts[] = {
{0}};
/* Master of threads. */
-struct thread_master *master;
+struct event_loop *master;
/*
* Prototypes.
@@ -169,7 +169,7 @@ static const struct frr_yang_module_info *const isisd_yang_modules[] = {
/* clang-format on */
-static void isis_config_finish(struct thread *t)
+static void isis_config_finish(struct event *t)
{
struct listnode *node, *inode;
struct isis *isis;
@@ -185,9 +185,9 @@ static void isis_config_start(void)
{
/* Max wait time for config to load before generating lsp */
#define ISIS_PRE_CONFIG_MAX_WAIT_SECONDS 600
- THREAD_OFF(t_isis_cfg);
- thread_add_timer(im->master, isis_config_finish, NULL,
- ISIS_PRE_CONFIG_MAX_WAIT_SECONDS, &t_isis_cfg);
+ EVENT_OFF(t_isis_cfg);
+ event_add_timer(im->master, isis_config_finish, NULL,
+ ISIS_PRE_CONFIG_MAX_WAIT_SECONDS, &t_isis_cfg);
}
static void isis_config_end(void)
@@ -195,10 +195,10 @@ static void isis_config_end(void)
/* If ISIS config processing thread isn't running, then
* we can return and rely it's properly handled.
*/
- if (!thread_is_scheduled(t_isis_cfg))
+ if (!event_is_scheduled(t_isis_cfg))
return;
- THREAD_OFF(t_isis_cfg);
+ EVENT_OFF(t_isis_cfg);
isis_config_finish(t_isis_cfg);
}
diff --git a/isisd/isis_misc.c b/isisd/isis_misc.c
index 4a490ab5ac..09ffa3479a 100644
--- a/isisd/isis_misc.c
+++ b/isisd/isis_misc.c
@@ -32,48 +32,13 @@
#include "isisd/isis_dynhn.h"
/* staticly assigned vars for printing purposes */
+static char sys_hostname[ISO_SYSID_STRLEN];
struct in_addr new_prefix;
-/* len of xx.xxxx.xxxx.xxxx.xxxx.xxxx.xxxx.xxxx.xxxx.xxxx.xx */
-/* + place for #0 termination */
-char isonet[51];
/* len of xxYxxMxWxdxxhxxmxxs + place for #0 termination */
char datestring[20];
char nlpidstring[30];
/*
- * This converts the isonet to its printable format
- */
-const char *isonet_print(const uint8_t *from, int len)
-{
- int i = 0;
- char tbuf[4];
- isonet[0] = '\0';
-
- if (!from)
- return "unknown";
-
- while (i < len) {
- if (i & 1) {
- snprintf(tbuf, sizeof(tbuf), "%02x", *(from + i));
- strlcat(isonet, tbuf, sizeof(isonet));
- } else {
- if (i == (len - 1)) { /* No dot at the end of address */
- snprintf(tbuf, sizeof(tbuf), "%02x",
- *(from + i));
- strlcat(isonet, tbuf, sizeof(isonet));
- } else {
- snprintf(tbuf, sizeof(tbuf), "%02x.",
- *(from + i));
- strlcat(isonet, tbuf, sizeof(isonet));
- }
- }
- i++;
- }
-
- return isonet;
-}
-
-/*
* Returns 0 on error, length of buff on ok
* extract dot from the dotted str, and insert all the number in a buff
*/
@@ -294,58 +259,17 @@ const char *syst2string(int type)
return NULL; /* not reached */
}
-/*
- * Print functions - we print to static vars
- */
-const char *snpa_print(const uint8_t *from)
-{
- return isis_format_id(from, ISIS_SYS_ID_LEN);
-}
-
-const char *sysid_print(const uint8_t *from)
+const char *isis_hello_padding2string(int hello_padding_type)
{
- return isis_format_id(from, ISIS_SYS_ID_LEN);
-}
-
-const char *rawlspid_print(const uint8_t *from)
-{
- return isis_format_id(from, 8);
-}
-
-#define FORMAT_ID_SIZE sizeof("0000.0000.0000.00-00")
-const char *isis_format_id(const uint8_t *id, size_t len)
-{
-#define FORMAT_BUF_COUNT 4
- static char buf_ring[FORMAT_BUF_COUNT][FORMAT_ID_SIZE];
- static size_t cur_buf = 0;
-
- char *rv;
-
- cur_buf++;
- if (cur_buf >= FORMAT_BUF_COUNT)
- cur_buf = 0;
-
- rv = buf_ring[cur_buf];
-
- if (!id) {
- snprintf(rv, FORMAT_ID_SIZE, "unknown");
- return rv;
- }
-
- if (len < 6) {
- snprintf(rv, FORMAT_ID_SIZE, "Short ID");
- return rv;
+ switch (hello_padding_type) {
+ case ISIS_HELLO_PADDING_DISABLED:
+ return "no";
+ case ISIS_HELLO_PADDING_DURING_ADJACENCY_FORMATION:
+ return "during-adjacency-formation";
+ case ISIS_HELLO_PADDING_ALWAYS:
+ return "yes";
}
-
- snprintf(rv, FORMAT_ID_SIZE, "%02x%02x.%02x%02x.%02x%02x", id[0], id[1],
- id[2], id[3], id[4], id[5]);
-
- if (len > 6)
- snprintf(rv + 14, FORMAT_ID_SIZE - 14, ".%02x", id[6]);
- if (len > 7)
- snprintf(rv + 17, FORMAT_ID_SIZE - 17, "-%02x", id[7]);
-
- return rv;
+ return NULL; /* not reached */
}
const char *time2string(uint32_t time)
@@ -461,7 +385,8 @@ const char *print_sys_hostname(const uint8_t *sysid)
return dyn->hostname;
}
- return sysid_print(sysid);
+ snprintfrr(sys_hostname, ISO_SYSID_STRLEN, "%pSY", sysid);
+ return sys_hostname;
}
/*
@@ -495,11 +420,11 @@ void zlog_dump_data(void *data, int len)
/* store hex str (for left side) */
snprintf(bytestr, sizeof(bytestr), "%02X ", *p);
- strncat(hexstr, bytestr, sizeof(hexstr) - strlen(hexstr) - 1);
+ strlcat(hexstr, bytestr, sizeof(hexstr) - strlen(hexstr) - 1);
/* store char str (for right side) */
snprintf(bytestr, sizeof(bytestr), "%c", c);
- strncat(charstr, bytestr,
+ strlcat(charstr, bytestr,
sizeof(charstr) - strlen(charstr) - 1);
if ((i % 16) == 0) {
@@ -510,9 +435,9 @@ void zlog_dump_data(void *data, int len)
charstr[0] = 0;
} else if ((i % 8) == 0) {
/* half line: add whitespaces */
- strncat(hexstr, " ",
+ strlcat(hexstr, " ",
sizeof(hexstr) - strlen(hexstr) - 1);
- strncat(charstr, " ",
+ strlcat(charstr, " ",
sizeof(charstr) - strlen(charstr) - 1);
}
p++; /* next byte */
diff --git a/isisd/isis_misc.h b/isisd/isis_misc.h
index b8b4ebd280..3a1d136b1d 100644
--- a/isisd/isis_misc.h
+++ b/isisd/isis_misc.h
@@ -16,6 +16,7 @@ const char *circuit_t2string(int);
const char *circuit_state2string(int state);
const char *circuit_type2string(int type);
const char *syst2string(int);
+const char *isis_hello_padding2string(int hello_padding_type);
struct in_addr newprefix2inaddr(uint8_t *prefix_start, uint8_t prefix_masklen);
/*
* Converting input to memory stored format
@@ -27,11 +28,6 @@ int sysid2buff(uint8_t *, const char *);
/*
* Printing functions
*/
-const char *isonet_print(const uint8_t *, int len);
-const char *sysid_print(const uint8_t *);
-const char *snpa_print(const uint8_t *);
-const char *rawlspid_print(const uint8_t *);
-const char *isis_format_id(const uint8_t *id, size_t len);
const char *time2string(uint32_t);
const char *nlpid2str(uint8_t nlpid);
/* typedef struct nlpids nlpids; */
diff --git a/isisd/isis_mt.c b/isisd/isis_mt.c
index fcc0f53815..d04a24dc46 100644
--- a/isisd/isis_mt.c
+++ b/isisd/isis_mt.c
@@ -507,8 +507,8 @@ static void tlvs_add_mt_set(struct isis_area *area, struct isis_tlvs *tlvs,
/* Check if MT is enable for this area */
if (!area_is_mt(area)) {
lsp_debug(
- "ISIS (%s): Adding %s.%02x as te-style neighbor (MT disable)",
- area->area_tag, sysid_print(id), LSP_PSEUDO_ID(id));
+ "ISIS (%s): Adding %pPN as te-style neighbor (MT disable)",
+ area->area_tag, id);
isis_tlvs_add_extended_reach(tlvs, ISIS_MT_DISABLE, id, metric,
ext);
return;
@@ -518,15 +518,12 @@ static void tlvs_add_mt_set(struct isis_area *area, struct isis_tlvs *tlvs,
for (unsigned int i = 0; i < mt_count; i++) {
uint16_t mtid = mt_set[i];
if (mt_set[i] == ISIS_MT_IPV4_UNICAST) {
- lsp_debug(
- "ISIS (%s): Adding %s.%02x as te-style neighbor",
- area->area_tag, sysid_print(id),
- LSP_PSEUDO_ID(id));
+ lsp_debug("ISIS (%s): Adding %pPN as te-style neighbor",
+ area->area_tag, id);
} else {
lsp_debug(
- "ISIS (%s): Adding %s.%02x as mt-style neighbor for %s",
- area->area_tag, sysid_print(id),
- LSP_PSEUDO_ID(id), isis_mtid2str(mtid));
+ "ISIS (%s): Adding %pPN as mt-style neighbor for %s",
+ area->area_tag, id, isis_mtid2str(mtid));
}
isis_tlvs_add_extended_reach(tlvs, mtid, id, metric, ext);
}
diff --git a/isisd/isis_nb.c b/isisd/isis_nb.c
index 7dc3a0eb3d..9141bfc46c 100644
--- a/isisd/isis_nb.c
+++ b/isisd/isis_nb.c
@@ -559,6 +559,13 @@ const struct frr_yang_module_info frr_isisd_info = {
},
},
{
+ .xpath = "/frr-isisd:isis/instance/log-pdu-drops",
+ .cbs = {
+ .cli_show = cli_show_isis_log_pdu_drops,
+ .modify = isis_instance_log_pdu_drops_modify,
+ },
+ },
+ {
.xpath = "/frr-isisd:isis/instance/mpls-te",
.cbs = {
.cli_show = cli_show_isis_mpls_te,
diff --git a/isisd/isis_nb.h b/isisd/isis_nb.h
index 480b2ce041..9a1f1f786f 100644
--- a/isisd/isis_nb.h
+++ b/isisd/isis_nb.h
@@ -196,6 +196,7 @@ int isis_instance_fast_reroute_level_2_remote_lfa_prefix_list_modify(
int isis_instance_fast_reroute_level_2_remote_lfa_prefix_list_destroy(
struct nb_cb_destroy_args *args);
int isis_instance_log_adjacency_changes_modify(struct nb_cb_modify_args *args);
+int isis_instance_log_pdu_drops_modify(struct nb_cb_modify_args *args);
int isis_instance_mpls_te_create(struct nb_cb_create_args *args);
int isis_instance_mpls_te_destroy(struct nb_cb_destroy_args *args);
int isis_instance_mpls_te_router_address_modify(struct nb_cb_modify_args *args);
@@ -609,6 +610,8 @@ void cli_show_ip_isis_priority(struct vty *vty, const struct lyd_node *dnode,
bool show_defaults);
void cli_show_isis_log_adjacency(struct vty *vty, const struct lyd_node *dnode,
bool show_defaults);
+void cli_show_isis_log_pdu_drops(struct vty *vty, const struct lyd_node *dnode,
+ bool show_defaults);
void cli_show_isis_mpls_ldp_sync(struct vty *vty, const struct lyd_node *dnode,
bool show_defaults);
void cli_show_isis_mpls_ldp_sync_holddown(struct vty *vty,
diff --git a/isisd/isis_nb_config.c b/isisd/isis_nb_config.c
index 2b3355bc9f..022bfbed6e 100644
--- a/isisd/isis_nb_config.c
+++ b/isisd/isis_nb_config.c
@@ -103,14 +103,14 @@ int isis_instance_is_type_modify(struct nb_cb_modify_args *args)
}
struct sysid_iter {
- struct area_addr *addr;
+ struct iso_address *addr;
bool same;
};
static int sysid_iter_cb(const struct lyd_node *dnode, void *arg)
{
struct sysid_iter *iter = arg;
- struct area_addr addr;
+ struct iso_address addr;
const char *net;
net = yang_dnode_get_string(dnode, NULL);
@@ -130,7 +130,7 @@ static int sysid_iter_cb(const struct lyd_node *dnode, void *arg)
int isis_instance_area_address_create(struct nb_cb_create_args *args)
{
struct isis_area *area;
- struct area_addr addr, *addrr = NULL, *addrp = NULL;
+ struct iso_address addr, *addrr = NULL, *addrp = NULL;
struct listnode *node;
struct sysid_iter iter;
uint8_t buff[255];
@@ -161,7 +161,8 @@ int isis_instance_area_address_create(struct nb_cb_create_args *args)
}
break;
case NB_EV_PREPARE:
- addrr = XMALLOC(MTYPE_ISIS_AREA_ADDR, sizeof(struct area_addr));
+ addrr = XMALLOC(MTYPE_ISIS_AREA_ADDR,
+ sizeof(struct iso_address));
addrr->addr_len = dotformat2buff(buff, net_title);
memcpy(addrr->area_addr, buff, addrr->addr_len);
args->resource->ptr = addrr;
@@ -217,7 +218,7 @@ int isis_instance_area_address_create(struct nb_cb_create_args *args)
int isis_instance_area_address_destroy(struct nb_cb_destroy_args *args)
{
- struct area_addr addr, *addrp = NULL;
+ struct iso_address addr, *addrp = NULL;
struct listnode *node;
uint8_t buff[255];
struct isis_area *area;
@@ -1830,6 +1831,23 @@ int isis_instance_log_adjacency_changes_modify(struct nb_cb_modify_args *args)
}
/*
+ * XPath: /frr-isisd:isis/instance/log-pdu-drops
+ */
+int isis_instance_log_pdu_drops_modify(struct nb_cb_modify_args *args)
+{
+ struct isis_area *area;
+ bool log = yang_dnode_get_bool(args->dnode, NULL);
+
+ if (args->event != NB_EV_APPLY)
+ return NB_OK;
+
+ area = nb_running_get_entry(args->dnode, NULL, true);
+ area->log_pdu_drops = log ? 1 : 0;
+
+ return NB_OK;
+}
+
+/*
* XPath: /frr-isisd:isis/instance/mpls-te
*/
int isis_instance_mpls_te_create(struct nb_cb_create_args *args)
@@ -2783,7 +2801,7 @@ int lib_interface_isis_hello_padding_modify(struct nb_cb_modify_args *args)
return NB_OK;
circuit = nb_running_get_entry(args->dnode, NULL, true);
- circuit->pad_hellos = yang_dnode_get_bool(args->dnode, NULL);
+ circuit->pad_hellos = yang_dnode_get_enum(args->dnode, NULL);
return NB_OK;
}
diff --git a/isisd/isis_nb_notifications.c b/isisd/isis_nb_notifications.c
index 94b1c47d3e..5a1e312b4d 100644
--- a/isisd/isis_nb_notifications.c
+++ b/isisd/isis_nb_notifications.c
@@ -134,6 +134,7 @@ void isis_notif_lsp_too_large(const struct isis_circuit *circuit,
const char *xpath = "/frr-isisd:lsp-too-large";
struct list *arguments = yang_data_list_new();
char xpath_arg[XPATH_MAXLEN];
+ char xpath_value[ISO_SYSID_STRLEN];
struct yang_data *data;
struct isis_area *area = circuit->area;
@@ -143,7 +144,8 @@ void isis_notif_lsp_too_large(const struct isis_circuit *circuit,
data = yang_data_new_uint32(xpath_arg, pdu_size);
listnode_add(arguments, data);
snprintf(xpath_arg, sizeof(xpath_arg), "%s/lsp-id", xpath);
- data = yang_data_new_string(xpath_arg, rawlspid_print(lsp_id));
+ snprintfrr(xpath_value, ISO_SYSID_STRLEN, "%pLS", lsp_id);
+ data = yang_data_new_string(xpath_arg, xpath_value);
listnode_add(arguments, data);
hook_call(isis_hook_lsp_too_large, circuit, pdu_size, lsp_id);
@@ -180,11 +182,13 @@ void isis_notif_corrupted_lsp(const struct isis_area *area,
const char *xpath = "/frr-isisd:corrupted-lsp-detected";
struct list *arguments = yang_data_list_new();
char xpath_arg[XPATH_MAXLEN];
+ char xpath_value[ISO_SYSID_STRLEN];
struct yang_data *data;
notif_prep_instance_hdr(xpath, area, "default", arguments);
snprintf(xpath_arg, sizeof(xpath_arg), "%s/lsp-id", xpath);
- data = yang_data_new_string(xpath_arg, rawlspid_print(lsp_id));
+ snprintfrr(xpath_value, ISO_SYSID_STRLEN, "%pLS", lsp_id);
+ data = yang_data_new_string(xpath_arg, xpath_value);
listnode_add(arguments, data);
hook_call(isis_hook_corrupted_lsp, area);
@@ -201,11 +205,13 @@ void isis_notif_lsp_exceed_max(const struct isis_area *area,
const char *xpath = "/frr-isisd:attempt-to-exceed-max-sequence";
struct list *arguments = yang_data_list_new();
char xpath_arg[XPATH_MAXLEN];
+ char xpath_value[ISO_SYSID_STRLEN];
struct yang_data *data;
notif_prep_instance_hdr(xpath, area, "default", arguments);
snprintf(xpath_arg, sizeof(xpath_arg), "%s/lsp-id", xpath);
- data = yang_data_new_string(xpath_arg, rawlspid_print(lsp_id));
+ snprintfrr(xpath_value, ISO_SYSID_STRLEN, "%pLS", lsp_id);
+ data = yang_data_new_string(xpath_arg, xpath_value);
listnode_add(arguments, data);
hook_call(isis_hook_lsp_exceed_max, area, lsp_id);
@@ -299,6 +305,7 @@ void isis_notif_adj_state_change(const struct isis_adjacency *adj,
const char *xpath = "/frr-isisd:adjacency-state-change";
struct list *arguments = yang_data_list_new();
char xpath_arg[XPATH_MAXLEN];
+ char xpath_value[ISO_SYSID_STRLEN];
struct yang_data *data;
struct isis_circuit *circuit = adj->circuit;
struct isis_area *area = circuit->area;
@@ -312,7 +319,8 @@ void isis_notif_adj_state_change(const struct isis_adjacency *adj,
listnode_add(arguments, data);
}
snprintf(xpath_arg, sizeof(xpath_arg), "%s/neighbor-system-id", xpath);
- data = yang_data_new_string(xpath_arg, sysid_print(adj->sysid));
+ snprintfrr(xpath_value, ISO_SYSID_STRLEN, "%pSY", adj->sysid);
+ data = yang_data_new_string(xpath_arg, xpath_value);
listnode_add(arguments, data);
snprintf(xpath_arg, sizeof(xpath_arg), "%s/state", xpath);
@@ -389,13 +397,15 @@ void isis_notif_lsp_received(const struct isis_circuit *circuit,
const char *xpath = "/frr-isisd:lsp-received";
struct list *arguments = yang_data_list_new();
char xpath_arg[XPATH_MAXLEN];
+ char xpath_value[ISO_SYSID_STRLEN];
struct yang_data *data;
struct isis_area *area = circuit->area;
notif_prep_instance_hdr(xpath, area, "default", arguments);
notif_prepr_iface_hdr(xpath, circuit, arguments);
snprintf(xpath_arg, sizeof(xpath_arg), "%s/lsp-id", xpath);
- data = yang_data_new_string(xpath_arg, rawlspid_print(lsp_id));
+ snprintfrr(xpath_value, ISO_SYSID_STRLEN, "%pLS", lsp_id);
+ data = yang_data_new_string(xpath_arg, xpath_value);
listnode_add(arguments, data);
snprintf(xpath_arg, sizeof(xpath_arg), "%s/sequence", xpath);
data = yang_data_new_uint32(xpath_arg, seqno);
@@ -419,11 +429,13 @@ void isis_notif_lsp_gen(const struct isis_area *area, const uint8_t *lsp_id,
const char *xpath = "/frr-isisd:lsp-generation";
struct list *arguments = yang_data_list_new();
char xpath_arg[XPATH_MAXLEN];
+ char xpath_value[ISO_SYSID_STRLEN];
struct yang_data *data;
notif_prep_instance_hdr(xpath, area, "default", arguments);
snprintf(xpath_arg, sizeof(xpath_arg), "%s/lsp-id", xpath);
- data = yang_data_new_string(xpath_arg, rawlspid_print(lsp_id));
+ snprintfrr(xpath_value, ISO_SYSID_STRLEN, "%pLS", lsp_id);
+ data = yang_data_new_string(xpath_arg, xpath_value);
listnode_add(arguments, data);
snprintf(xpath_arg, sizeof(xpath_arg), "%s/sequence", xpath);
data = yang_data_new_uint32(xpath_arg, seqno);
@@ -503,13 +515,15 @@ void isis_notif_lsp_error(const struct isis_circuit *circuit,
const char *xpath = "/frr-isisd:lsp-error-detected";
struct list *arguments = yang_data_list_new();
char xpath_arg[XPATH_MAXLEN];
+ char xpath_value[ISO_SYSID_STRLEN];
struct yang_data *data;
struct isis_area *area = circuit->area;
notif_prep_instance_hdr(xpath, area, "default", arguments);
notif_prepr_iface_hdr(xpath, circuit, arguments);
snprintf(xpath_arg, sizeof(xpath_arg), "%s/lsp-id", xpath);
- data = yang_data_new_string(xpath_arg, rawlspid_print(lsp_id));
+ snprintfrr(xpath_value, ISO_SYSID_STRLEN, "%pLS", lsp_id);
+ data = yang_data_new_string(xpath_arg, xpath_value);
listnode_add(arguments, data);
snprintf(xpath_arg, sizeof(xpath_arg), "%s/raw-pdu", xpath);
data = yang_data_new_binary(xpath_arg, raw_pdu, raw_pdu_len);
@@ -530,13 +544,15 @@ void isis_notif_seqno_skipped(const struct isis_circuit *circuit,
const char *xpath = "/frr-isisd:sequence-number-skipped";
struct list *arguments = yang_data_list_new();
char xpath_arg[XPATH_MAXLEN];
+ char xpath_value[ISO_SYSID_STRLEN];
struct yang_data *data;
struct isis_area *area = circuit->area;
notif_prep_instance_hdr(xpath, area, "default", arguments);
notif_prepr_iface_hdr(xpath, circuit, arguments);
snprintf(xpath_arg, sizeof(xpath_arg), "%s/lsp-id", xpath);
- data = yang_data_new_string(xpath_arg, rawlspid_print(lsp_id));
+ snprintfrr(xpath_value, ISO_SYSID_STRLEN, "%pLS", lsp_id);
+ data = yang_data_new_string(xpath_arg, xpath_value);
listnode_add(arguments, data);
hook_call(isis_hook_seqno_skipped, circuit, lsp_id);
@@ -553,13 +569,15 @@ void isis_notif_own_lsp_purge(const struct isis_circuit *circuit,
const char *xpath = "/frr-isisd:own-lsp-purge";
struct list *arguments = yang_data_list_new();
char xpath_arg[XPATH_MAXLEN];
+ char xpath_value[ISO_SYSID_STRLEN];
struct yang_data *data;
struct isis_area *area = circuit->area;
notif_prep_instance_hdr(xpath, area, "default", arguments);
notif_prepr_iface_hdr(xpath, circuit, arguments);
snprintf(xpath_arg, sizeof(xpath_arg), "%s/lsp-id", xpath);
- data = yang_data_new_string(xpath_arg, rawlspid_print(lsp_id));
+ snprintfrr(xpath_value, ISO_SYSID_STRLEN, "%pLS", lsp_id);
+ data = yang_data_new_string(xpath_arg, xpath_value);
listnode_add(arguments, data);
hook_call(isis_hook_own_lsp_purge, circuit, lsp_id);
diff --git a/isisd/isis_nb_state.c b/isisd/isis_nb_state.c
index 13fdddf555..b7c33ed27b 100644
--- a/isisd/isis_nb_state.c
+++ b/isisd/isis_nb_state.c
@@ -132,8 +132,11 @@ lib_interface_state_isis_adjacencies_adjacency_neighbor_sysid_get_elem(
struct nb_cb_get_elem_args *args)
{
const struct isis_adjacency *adj = args->list_entry;
+ char xpath_value[ISO_SYSID_STRLEN];
- return yang_data_new_string(args->xpath, sysid_print(adj->sysid));
+ snprintfrr(xpath_value, ISO_SYSID_STRLEN, "%pSY", adj->sysid);
+
+ return yang_data_new_string(args->xpath, xpath_value);
}
/*
@@ -158,8 +161,11 @@ lib_interface_state_isis_adjacencies_adjacency_neighbor_snpa_get_elem(
struct nb_cb_get_elem_args *args)
{
const struct isis_adjacency *adj = args->list_entry;
+ char xpath_value[ISO_SYSID_STRLEN];
+
+ snprintfrr(xpath_value, ISO_SYSID_STRLEN, "%pSY", adj->snpa);
- return yang_data_new_string(args->xpath, snpa_print(adj->snpa));
+ return yang_data_new_string(args->xpath, xpath_value);
}
/*
diff --git a/isisd/isis_pdu.c b/isisd/isis_pdu.c
index 70ec2426d3..0cd43a7abc 100644
--- a/isisd/isis_pdu.c
+++ b/isisd/isis_pdu.c
@@ -11,7 +11,7 @@
#include <zebra.h>
#include "memory.h"
-#include "thread.h"
+#include "frrevent.h"
#include "linklist.h"
#include "log.h"
#include "stream.h"
@@ -192,9 +192,9 @@ static int process_p2p_hello(struct iih_info *iih)
adj);
/* lets take care of the expiry */
- THREAD_OFF(adj->t_expire);
- thread_add_timer(master, isis_adj_expire, adj, (long)adj->hold_time,
- &adj->t_expire);
+ EVENT_OFF(adj->t_expire);
+ event_add_timer(master, isis_adj_expire, adj, (long)adj->hold_time,
+ &adj->t_expire);
/* While fabricds initial sync is in progress, ignore hellos from other
* interfaces than the one we are performing the initial sync on. */
@@ -466,8 +466,8 @@ static int process_lan_hello(struct iih_info *iih)
: iih->circuit->u.bc.l2_desig_is;
if (memcmp(dis, iih->dis, ISIS_SYS_ID_LEN + 1)) {
- thread_add_event(master, isis_event_dis_status_change,
- iih->circuit, 0, NULL);
+ event_add_event(master, isis_event_dis_status_change,
+ iih->circuit, 0, NULL);
memcpy(dis, iih->dis, ISIS_SYS_ID_LEN + 1);
}
}
@@ -484,9 +484,9 @@ static int process_lan_hello(struct iih_info *iih)
adj);
/* lets take care of the expiry */
- THREAD_OFF(adj->t_expire);
- thread_add_timer(master, isis_adj_expire, adj, (long)adj->hold_time,
- &adj->t_expire);
+ EVENT_OFF(adj->t_expire);
+ event_add_timer(master, isis_adj_expire, adj, (long)adj->hold_time,
+ &adj->t_expire);
/*
* If the snpa for this circuit is found from LAN Neighbours TLV
@@ -514,9 +514,9 @@ static int process_lan_hello(struct iih_info *iih)
if (IS_DEBUG_ADJ_PACKETS) {
zlog_debug(
- "ISIS-Adj (%s): Rcvd L%d LAN IIH from %s on %s, cirType %s, cirID %u, length %zd",
- iih->circuit->area->area_tag, iih->level,
- snpa_print(iih->ssnpa), iih->circuit->interface->name,
+ "ISIS-Adj (%s): Rcvd L%d LAN IIH from %pSY on %s, cirType %s, cirID %u, length %zd",
+ iih->circuit->area->area_tag, iih->level, iih->ssnpa,
+ iih->circuit->interface->name,
circuit_t2string(iih->circuit->is_type),
iih->circuit->circuit_id,
stream_get_endp(iih->circuit->rcv_stream));
@@ -862,31 +862,32 @@ static int process_lsp(uint8_t pdu_type, struct isis_circuit *circuit,
#ifndef FABRICD
/* send northbound notification */
+ char buf[ISO_SYSID_STRLEN];
+
+ snprintfrr(buf, ISO_SYSID_STRLEN, "%pSY", hdr.lsp_id);
isis_notif_lsp_received(circuit, hdr.lsp_id, hdr.seqno, time(NULL),
- sysid_print(hdr.lsp_id));
+ buf);
#endif /* ifndef FABRICD */
if (pdu_len_validate(hdr.pdu_len, circuit)) {
- zlog_debug("ISIS-Upd (%s): LSP %s invalid LSP length %hu",
- circuit->area->area_tag, rawlspid_print(hdr.lsp_id),
- hdr.pdu_len);
+ zlog_debug("ISIS-Upd (%s): LSP %pLS invalid LSP length %hu",
+ circuit->area->area_tag, hdr.lsp_id, hdr.pdu_len);
return ISIS_WARNING;
}
if (IS_DEBUG_UPDATE_PACKETS) {
- zlog_debug("ISIS-Upd (%s): Rcvd L%d LSP %s, seq 0x%08x, cksum 0x%04hx, lifetime %hus, len %hu, on %s",
- circuit->area->area_tag, level,
- rawlspid_print(hdr.lsp_id), hdr.seqno, hdr.checksum,
- hdr.rem_lifetime, hdr.pdu_len,
- circuit->interface->name);
+ zlog_debug(
+ "ISIS-Upd (%s): Rcvd L%d LSP %pLS, seq 0x%08x, cksum 0x%04hx, lifetime %hus, len %hu, on %s",
+ circuit->area->area_tag, level, hdr.lsp_id, hdr.seqno,
+ hdr.checksum, hdr.rem_lifetime, hdr.pdu_len,
+ circuit->interface->name);
}
/* lsp is_type check */
if ((hdr.lsp_bits & IS_LEVEL_1) != IS_LEVEL_1) {
- zlog_debug(
- "ISIS-Upd (%s): LSP %s invalid LSP is type 0x%x",
- circuit->area->area_tag, rawlspid_print(hdr.lsp_id),
- hdr.lsp_bits & IS_LEVEL_1_AND_2);
+ zlog_debug("ISIS-Upd (%s): LSP %pLS invalid LSP is type 0x%x",
+ circuit->area->area_tag, hdr.lsp_id,
+ hdr.lsp_bits & IS_LEVEL_1_AND_2);
/* continue as per RFC1122 Be liberal in what you accept, and
* conservative in what you send */
}
@@ -896,27 +897,25 @@ static int process_lsp(uint8_t pdu_type, struct isis_circuit *circuit,
if (iso_csum_verify(STREAM_DATA(circuit->rcv_stream) + 12,
hdr.pdu_len - 12, hdr.checksum, 12)) {
zlog_debug(
- "ISIS-Upd (%s): LSP %s invalid LSP checksum 0x%04hx",
- circuit->area->area_tag, rawlspid_print(hdr.lsp_id),
- hdr.checksum);
+ "ISIS-Upd (%s): LSP %pLS invalid LSP checksum 0x%04hx",
+ circuit->area->area_tag, hdr.lsp_id, hdr.checksum);
return ISIS_WARNING;
}
/* 7.3.15.1 a) 1 - external domain circuit will discard lsps */
if (circuit->ext_domain) {
zlog_debug(
- "ISIS-Upd (%s): LSP %s received at level %d over circuit with externalDomain = true",
- circuit->area->area_tag, rawlspid_print(hdr.lsp_id),
- level);
+ "ISIS-Upd (%s): LSP %pLS received at level %d over circuit with externalDomain = true",
+ circuit->area->area_tag, hdr.lsp_id, level);
return ISIS_WARNING;
}
/* 7.3.15.1 a) 2,3 - manualL2OnlyMode not implemented */
if (!(circuit->is_type & level)) {
zlog_debug(
- "ISIS-Upd (%s): LSP %s received at level %d over circuit of type %s",
- circuit->area->area_tag, rawlspid_print(hdr.lsp_id),
- level, circuit_t2string(circuit->is_type));
+ "ISIS-Upd (%s): LSP %pLS received at level %d over circuit of type %s",
+ circuit->area->area_tag, hdr.lsp_id, level,
+ circuit_t2string(circuit->is_type));
return ISIS_WARNING;
}
@@ -1016,11 +1015,11 @@ static int process_lsp(uint8_t pdu_type, struct isis_circuit *circuit,
if (circuit->circ_type == CIRCUIT_T_BROADCAST) {
if (!isis_adj_lookup_snpa(ssnpa,
circuit->u.bc.adjdb[level - 1])) {
- zlog_debug("(%s): DS ======= LSP %s, seq 0x%08x, cksum 0x%04hx, lifetime %hus on %s",
- circuit->area->area_tag,
- rawlspid_print(hdr.lsp_id), hdr.seqno,
- hdr.checksum, hdr.rem_lifetime,
- circuit->interface->name);
+ zlog_debug(
+ "(%s): DS ======= LSP %pLS, seq 0x%08x, cksum 0x%04hx, lifetime %hus on %s",
+ circuit->area->area_tag, hdr.lsp_id, hdr.seqno,
+ hdr.checksum, hdr.rem_lifetime,
+ circuit->interface->name);
goto out; /* Silently discard */
}
}
@@ -1057,9 +1056,9 @@ dontcheckadj:
if (lsp && (lsp->hdr.seqno == hdr.seqno)
&& (lsp->hdr.checksum != hdr.checksum)
&& hdr.rem_lifetime) {
- zlog_warn("ISIS-Upd (%s): LSP %s seq 0x%08x with confused checksum received.",
- circuit->area->area_tag, rawlspid_print(hdr.lsp_id),
- hdr.seqno);
+ zlog_warn(
+ "ISIS-Upd (%s): LSP %pLS seq 0x%08x with confused checksum received.",
+ circuit->area->area_tag, hdr.lsp_id, hdr.seqno);
hdr.rem_lifetime = 0;
lsp_confusion = true;
} else
@@ -1153,10 +1152,9 @@ dontcheckadj:
}
if (IS_DEBUG_UPDATE_PACKETS)
zlog_debug(
- "ISIS-Upd (%s): (1) re-originating LSP %s new seq 0x%08x",
+ "ISIS-Upd (%s): (1) re-originating LSP %pLS new seq 0x%08x",
circuit->area->area_tag,
- rawlspid_print(hdr.lsp_id),
- lsp->hdr.seqno);
+ hdr.lsp_id, lsp->hdr.seqno);
} else {
/* our own LSP with 0 remaining life time */
#ifndef FABRICD
@@ -1194,9 +1192,8 @@ dontcheckadj:
#endif /* ifndef FABRICD */
if (IS_DEBUG_UPDATE_PACKETS) {
zlog_debug(
- "ISIS-Upd (%s): (2) re-originating LSP %s new seq 0x%08x",
- circuit->area->area_tag,
- rawlspid_print(hdr.lsp_id),
+ "ISIS-Upd (%s): (2) re-originating LSP %pLS new seq 0x%08x",
+ circuit->area->area_tag, hdr.lsp_id,
lsp->hdr.seqno);
}
lsp_flood(lsp, NULL);
@@ -1361,9 +1358,9 @@ static int process_snp(uint8_t pdu_type, struct isis_circuit *circuit,
if (!is_csnp && (circuit->circ_type == CIRCUIT_T_BROADCAST)
&& !circuit->u.bc.is_dr[level - 1]) {
zlog_debug(
- "ISIS-Snp (%s): Rcvd L%d %cSNP from %s on %s, skipping: we are not the DIS",
- circuit->area->area_tag, level, typechar,
- snpa_print(ssnpa), circuit->interface->name);
+ "ISIS-Snp (%s): Rcvd L%d %cSNP from %pSY on %s, skipping: we are not the DIS",
+ circuit->area->area_tag, level, typechar, ssnpa,
+ circuit->interface->name);
return ISIS_OK;
}
@@ -1452,16 +1449,16 @@ static int process_snp(uint8_t pdu_type, struct isis_circuit *circuit,
/* debug isis snp-packets */
if (IS_DEBUG_SNP_PACKETS) {
- zlog_debug("ISIS-Snp (%s): Rcvd L%d %cSNP from %s on %s",
- circuit->area->area_tag, level, typechar,
- snpa_print(ssnpa), circuit->interface->name);
+ zlog_debug("ISIS-Snp (%s): Rcvd L%d %cSNP from %pSY on %s",
+ circuit->area->area_tag, level, typechar, ssnpa,
+ circuit->interface->name);
for (struct isis_lsp_entry *entry = entry_head; entry;
entry = entry->next) {
zlog_debug(
- "ISIS-Snp (%s): %cSNP entry %s, seq 0x%08x, cksum 0x%04hx, lifetime %hus",
- circuit->area->area_tag, typechar,
- rawlspid_print(entry->id), entry->seqno,
- entry->checksum, entry->rem_lifetime);
+ "ISIS-Snp (%s): %cSNP entry %pLS, seq 0x%08x, cksum 0x%04hx, lifetime %hus",
+ circuit->area->area_tag, typechar, entry->id,
+ entry->seqno, entry->checksum,
+ entry->rem_lifetime);
}
}
@@ -1654,12 +1651,14 @@ int isis_handle_pdu(struct isis_circuit *circuit, uint8_t *ssnpa)
if (idrp == ISO9542_ESIS) {
flog_err(EC_LIB_DEVELOPMENT,
"No support for ES-IS packet IDRP=%hhx", idrp);
+ pdu_counter_count_drop(circuit->area, pdu_type);
return ISIS_ERROR;
}
if (idrp != ISO10589_ISIS) {
flog_err(EC_ISIS_PACKET, "Not an IS-IS packet IDRP=%hhx",
idrp);
+ pdu_counter_count_drop(circuit->area, pdu_type);
return ISIS_ERROR;
}
@@ -1670,6 +1669,7 @@ int isis_handle_pdu(struct isis_circuit *circuit, uint8_t *ssnpa)
isis_notif_version_skew(circuit, version1, raw_pdu,
sizeof(raw_pdu));
#endif /* ifndef FABRICD */
+ pdu_counter_count_drop(circuit->area, pdu_type);
return ISIS_WARNING;
}
@@ -1693,12 +1693,14 @@ int isis_handle_pdu(struct isis_circuit *circuit, uint8_t *ssnpa)
isis_notif_id_len_mismatch(circuit, id_len, raw_pdu,
sizeof(raw_pdu));
#endif /* ifndef FABRICD */
+ pdu_counter_count_drop(circuit->area, pdu_type);
return ISIS_ERROR;
}
uint8_t expected_length;
if (pdu_size(pdu_type, &expected_length)) {
zlog_warn("Unsupported ISIS PDU %hhu", pdu_type);
+ pdu_counter_count_drop(circuit->area, pdu_type);
return ISIS_WARNING;
}
@@ -1706,6 +1708,7 @@ int isis_handle_pdu(struct isis_circuit *circuit, uint8_t *ssnpa)
flog_err(EC_ISIS_PACKET,
"Expected fixed header length = %hhu but got %hhu",
expected_length, length);
+ pdu_counter_count_drop(circuit->area, pdu_type);
return ISIS_ERROR;
}
@@ -1713,6 +1716,7 @@ int isis_handle_pdu(struct isis_circuit *circuit, uint8_t *ssnpa)
flog_err(
EC_ISIS_PACKET,
"PDU is too short to contain fixed header of given PDU type.");
+ pdu_counter_count_drop(circuit->area, pdu_type);
return ISIS_ERROR;
}
@@ -1723,12 +1727,14 @@ int isis_handle_pdu(struct isis_circuit *circuit, uint8_t *ssnpa)
isis_notif_version_skew(circuit, version2, raw_pdu,
sizeof(raw_pdu));
#endif /* ifndef FABRICD */
+ pdu_counter_count_drop(circuit->area, pdu_type);
return ISIS_WARNING;
}
if (circuit->is_passive) {
zlog_warn("Received ISIS PDU on passive circuit %s",
circuit->interface->name);
+ pdu_counter_count_drop(circuit->area, pdu_type);
return ISIS_WARNING;
}
@@ -1747,6 +1753,7 @@ int isis_handle_pdu(struct isis_circuit *circuit, uint8_t *ssnpa)
isis_notif_max_area_addr_mismatch(circuit, max_area_addrs,
raw_pdu, sizeof(raw_pdu));
#endif /* ifndef FABRICD */
+ pdu_counter_count_drop(circuit->area, pdu_type);
return ISIS_ERROR;
}
@@ -1754,17 +1761,22 @@ int isis_handle_pdu(struct isis_circuit *circuit, uint8_t *ssnpa)
case L1_LAN_HELLO:
case L2_LAN_HELLO:
case P2P_HELLO:
- if (fabricd && pdu_type != P2P_HELLO)
+ if (fabricd && pdu_type != P2P_HELLO) {
+ pdu_counter_count_drop(circuit->area, pdu_type);
return ISIS_ERROR;
+ }
+
retval = process_hello(pdu_type, circuit, ssnpa);
break;
case L1_LINK_STATE:
case L2_LINK_STATE:
case FS_LINK_STATE:
- if (fabricd
- && pdu_type != L2_LINK_STATE
- && pdu_type != FS_LINK_STATE)
+ if (fabricd && pdu_type != L2_LINK_STATE &&
+ pdu_type != FS_LINK_STATE) {
+ pdu_counter_count_drop(circuit->area, pdu_type);
return ISIS_ERROR;
+ }
+
retval = process_lsp(pdu_type, circuit, ssnpa, max_area_addrs);
break;
case L1_COMPLETE_SEQ_NUM:
@@ -1774,13 +1786,17 @@ int isis_handle_pdu(struct isis_circuit *circuit, uint8_t *ssnpa)
retval = process_snp(pdu_type, circuit, ssnpa);
break;
default:
+ pdu_counter_count_drop(circuit->area, pdu_type);
return ISIS_ERROR;
}
+ if (retval != ISIS_OK)
+ pdu_counter_count_drop(circuit->area, pdu_type);
+
return retval;
}
-void isis_receive(struct thread *thread)
+void isis_receive(struct event *thread)
{
struct isis_circuit *circuit;
uint8_t ssnpa[ETH_ALEN];
@@ -1788,7 +1804,7 @@ void isis_receive(struct thread *thread)
/*
* Get the circuit
*/
- circuit = THREAD_ARG(thread);
+ circuit = EVENT_ARG(thread);
assert(circuit);
circuit->t_read = NULL;
@@ -1964,8 +1980,14 @@ int send_hello(struct isis_circuit *circuit, int level)
isis_tlvs_add_global_ipv6_addresses(tlvs,
circuit->ipv6_non_link);
+ bool should_pad_hello =
+ circuit->pad_hellos == ISIS_HELLO_PADDING_ALWAYS ||
+ (circuit->pad_hellos ==
+ ISIS_HELLO_PADDING_DURING_ADJACENCY_FORMATION &&
+ circuit->upadjcount[0] + circuit->upadjcount[1] == 0);
+
if (isis_pack_tlvs(tlvs, circuit->snd_stream, len_pointer,
- circuit->pad_hellos, false)) {
+ should_pad_hello, false)) {
isis_free_tlvs(tlvs);
return ISIS_WARNING; /* XXX: Maybe Log TLV structure? */
}
@@ -2003,9 +2025,9 @@ int send_hello(struct isis_circuit *circuit, int level)
return retval;
}
-static void send_hello_cb(struct thread *thread)
+static void send_hello_cb(struct event *thread)
{
- struct isis_circuit_arg *arg = THREAD_ARG(thread);
+ struct isis_circuit_arg *arg = EVENT_ARG(thread);
assert(arg);
struct isis_circuit *circuit = arg->circuit;
@@ -2044,20 +2066,18 @@ static void send_hello_cb(struct thread *thread)
}
static void _send_hello_sched(struct isis_circuit *circuit,
- struct thread **threadp,
- int level, long delay)
+ struct event **threadp, int level, long delay)
{
if (*threadp) {
- if (thread_timer_remain_msec(*threadp) < (unsigned long)delay)
+ if (event_timer_remain_msec(*threadp) < (unsigned long)delay)
return;
- THREAD_OFF(*threadp);
+ EVENT_OFF(*threadp);
}
- thread_add_timer_msec(master, send_hello_cb,
- &circuit->level_arg[level - 1],
- isis_jitter(delay, IIH_JITTER),
- threadp);
+ event_add_timer_msec(master, send_hello_cb,
+ &circuit->level_arg[level - 1],
+ isis_jitter(delay, IIH_JITTER), threadp);
}
void send_hello_sched(struct isis_circuit *circuit, int level, long delay)
@@ -2234,11 +2254,11 @@ int send_csnp(struct isis_circuit *circuit, int level)
return ISIS_OK;
}
-void send_l1_csnp(struct thread *thread)
+void send_l1_csnp(struct event *thread)
{
struct isis_circuit *circuit;
- circuit = THREAD_ARG(thread);
+ circuit = EVENT_ARG(thread);
assert(circuit);
circuit->t_send_csnp[0] = NULL;
@@ -2249,16 +2269,16 @@ void send_l1_csnp(struct thread *thread)
send_csnp(circuit, 1);
}
/* set next timer thread */
- thread_add_timer(master, send_l1_csnp, circuit,
- isis_jitter(circuit->csnp_interval[0], CSNP_JITTER),
- &circuit->t_send_csnp[0]);
+ event_add_timer(master, send_l1_csnp, circuit,
+ isis_jitter(circuit->csnp_interval[0], CSNP_JITTER),
+ &circuit->t_send_csnp[0]);
}
-void send_l2_csnp(struct thread *thread)
+void send_l2_csnp(struct event *thread)
{
struct isis_circuit *circuit;
- circuit = THREAD_ARG(thread);
+ circuit = EVENT_ARG(thread);
assert(circuit);
circuit->t_send_csnp[1] = NULL;
@@ -2269,9 +2289,9 @@ void send_l2_csnp(struct thread *thread)
send_csnp(circuit, 2);
}
/* set next timer thread */
- thread_add_timer(master, send_l2_csnp, circuit,
- isis_jitter(circuit->csnp_interval[1], CSNP_JITTER),
- &circuit->t_send_csnp[1]);
+ event_add_timer(master, send_l2_csnp, circuit,
+ isis_jitter(circuit->csnp_interval[1], CSNP_JITTER),
+ &circuit->t_send_csnp[1]);
}
/*
@@ -2388,32 +2408,32 @@ static int send_psnp(int level, struct isis_circuit *circuit)
return ISIS_OK;
}
-void send_l1_psnp(struct thread *thread)
+void send_l1_psnp(struct event *thread)
{
struct isis_circuit *circuit;
- circuit = THREAD_ARG(thread);
+ circuit = EVENT_ARG(thread);
assert(circuit);
circuit->t_send_psnp[0] = NULL;
send_psnp(1, circuit);
/* set next timer thread */
- thread_add_timer(master, send_l1_psnp, circuit,
- isis_jitter(circuit->psnp_interval[0], PSNP_JITTER),
- &circuit->t_send_psnp[0]);
+ event_add_timer(master, send_l1_psnp, circuit,
+ isis_jitter(circuit->psnp_interval[0], PSNP_JITTER),
+ &circuit->t_send_psnp[0]);
}
/*
* 7.3.15.4 action on expiration of partial SNP interval
* level 2
*/
-void send_l2_psnp(struct thread *thread)
+void send_l2_psnp(struct event *thread)
{
struct isis_circuit *circuit;
- circuit = THREAD_ARG(thread);
+ circuit = EVENT_ARG(thread);
assert(circuit);
circuit->t_send_psnp[1] = NULL;
@@ -2421,9 +2441,9 @@ void send_l2_psnp(struct thread *thread)
send_psnp(2, circuit);
/* set next timer thread */
- thread_add_timer(master, send_l2_psnp, circuit,
- isis_jitter(circuit->psnp_interval[1], PSNP_JITTER),
- &circuit->t_send_psnp[1]);
+ event_add_timer(master, send_l2_psnp, circuit,
+ isis_jitter(circuit->psnp_interval[1], PSNP_JITTER),
+ &circuit->t_send_psnp[1]);
}
/*
@@ -2456,11 +2476,11 @@ void send_lsp(struct isis_circuit *circuit, struct isis_lsp *lsp,
if (stream_get_endp(lsp->pdu) > stream_get_size(circuit->snd_stream)) {
flog_err(
EC_ISIS_PACKET,
- "ISIS-Upd (%s): Can't send L%d LSP %s, seq 0x%08x, cksum 0x%04hx, lifetime %hus on %s. LSP Size is %zu while interface stream size is %zu.",
- circuit->area->area_tag, lsp->level,
- rawlspid_print(lsp->hdr.lsp_id), lsp->hdr.seqno,
- lsp->hdr.checksum, lsp->hdr.rem_lifetime,
- circuit->interface->name, stream_get_endp(lsp->pdu),
+ "ISIS-Upd (%s): Can't send L%d LSP %pLS, seq 0x%08x, cksum 0x%04hx, lifetime %hus on %s. LSP Size is %zu while interface stream size is %zu.",
+ circuit->area->area_tag, lsp->level, lsp->hdr.lsp_id,
+ lsp->hdr.seqno, lsp->hdr.checksum,
+ lsp->hdr.rem_lifetime, circuit->interface->name,
+ stream_get_endp(lsp->pdu),
stream_get_size(circuit->snd_stream));
#ifndef FABRICD
/* send a northbound notification */
@@ -2484,14 +2504,14 @@ void send_lsp(struct isis_circuit *circuit, struct isis_lsp *lsp,
}
if (IS_DEBUG_UPDATE_PACKETS) {
- zlog_debug("ISIS-Upd (%s): Sending %sL%d LSP %s, seq 0x%08x, cksum 0x%04hx, lifetime %hus on %s",
- circuit->area->area_tag,
- (tx_type == TX_LSP_CIRCUIT_SCOPED)
- ? "Circuit scoped " : "",
- lsp->level,
- rawlspid_print(lsp->hdr.lsp_id), lsp->hdr.seqno,
- lsp->hdr.checksum, lsp->hdr.rem_lifetime,
- circuit->interface->name);
+ zlog_debug(
+ "ISIS-Upd (%s): Sending %sL%d LSP %pLS, seq 0x%08x, cksum 0x%04hx, lifetime %hus on %s",
+ circuit->area->area_tag,
+ (tx_type == TX_LSP_CIRCUIT_SCOPED) ? "Circuit scoped "
+ : "",
+ lsp->level, lsp->hdr.lsp_id, lsp->hdr.seqno,
+ lsp->hdr.checksum, lsp->hdr.rem_lifetime,
+ circuit->interface->name);
if (IS_DEBUG_PACKET_DUMP)
zlog_dump_data(STREAM_DATA(circuit->snd_stream),
stream_get_endp(circuit->snd_stream));
@@ -2529,3 +2549,37 @@ out:
isis_tx_queue_del(circuit->tx_queue, lsp);
}
}
+
+void isis_log_pdu_drops(struct isis_area *area, const char *pdu_type)
+{
+ uint64_t total_drops = 0;
+
+ for (int i = 0; i < PDU_COUNTER_SIZE; i++) {
+ if (!area->pdu_drop_counters[i])
+ continue;
+ total_drops += area->pdu_drop_counters[i];
+ }
+
+ zlog_info("PDU drop detected of type: %s. %" PRIu64
+ " Total Drops; %" PRIu64 " L1 IIH drops; %" PRIu64
+ " L2 IIH drops; %" PRIu64 " P2P IIH drops; %" PRIu64
+ " L1 LSP drops; %" PRIu64 " L2 LSP drops; %" PRIu64
+ " FS LSP drops; %" PRIu64 " L1 CSNP drops; %" PRIu64
+ " L2 CSNP drops; %" PRIu64 " L1 PSNP drops; %" PRIu64
+ " L2 PSNP drops.",
+ pdu_type, total_drops,
+ pdu_counter_get_count(area->pdu_drop_counters, L1_LAN_HELLO),
+ pdu_counter_get_count(area->pdu_drop_counters, L2_LAN_HELLO),
+ pdu_counter_get_count(area->pdu_drop_counters, P2P_HELLO),
+ pdu_counter_get_count(area->pdu_drop_counters, L1_LINK_STATE),
+ pdu_counter_get_count(area->pdu_drop_counters, L2_LINK_STATE),
+ pdu_counter_get_count(area->pdu_drop_counters, FS_LINK_STATE),
+ pdu_counter_get_count(area->pdu_drop_counters,
+ L1_COMPLETE_SEQ_NUM),
+ pdu_counter_get_count(area->pdu_drop_counters,
+ L2_COMPLETE_SEQ_NUM),
+ pdu_counter_get_count(area->pdu_drop_counters,
+ L1_PARTIAL_SEQ_NUM),
+ pdu_counter_get_count(area->pdu_drop_counters,
+ L2_PARTIAL_SEQ_NUM));
+}
diff --git a/isisd/isis_pdu.h b/isisd/isis_pdu.h
index 5124394000..5303c61d38 100644
--- a/isisd/isis_pdu.h
+++ b/isisd/isis_pdu.h
@@ -182,7 +182,7 @@ struct isis_partial_seqnum_hdr {
/*
* Function for receiving IS-IS PDUs
*/
-void isis_receive(struct thread *thread);
+void isis_receive(struct event *thread);
/*
* calling arguments for snp_process ()
@@ -197,13 +197,15 @@ void isis_receive(struct thread *thread);
*/
void send_hello_sched(struct isis_circuit *circuit, int level, long delay);
int send_csnp(struct isis_circuit *circuit, int level);
-void send_l1_csnp(struct thread *thread);
-void send_l2_csnp(struct thread *thread);
-void send_l1_psnp(struct thread *thread);
-void send_l2_psnp(struct thread *thread);
+void send_l1_csnp(struct event *thread);
+void send_l2_csnp(struct event *thread);
+void send_l1_psnp(struct event *thread);
+void send_l2_psnp(struct event *thread);
void send_lsp(struct isis_circuit *circuit,
struct isis_lsp *lsp, enum isis_tx_type tx_type);
void fill_fixed_hdr(uint8_t pdu_type, struct stream *stream);
int send_hello(struct isis_circuit *circuit, int level);
int isis_handle_pdu(struct isis_circuit *circuit, uint8_t *ssnpa);
+void isis_log_pdu_drops(struct isis_area *area, const char *pdu_type);
+
#endif /* _ZEBRA_ISIS_PDU_H */
diff --git a/isisd/isis_pdu_counter.c b/isisd/isis_pdu_counter.c
index 9d07b5e598..a3605a32a1 100644
--- a/isisd/isis_pdu_counter.c
+++ b/isisd/isis_pdu_counter.c
@@ -8,10 +8,10 @@
#include "vty.h"
-#include "isisd/isis_pdu_counter.h"
#include "isisd/isisd.h"
#include "isisd/isis_circuit.h"
#include "isisd/isis_pdu.h"
+#include "isisd/isis_pdu_counter.h"
static int pdu_type_to_counter_index(uint8_t pdu_type)
{
@@ -91,3 +91,23 @@ void pdu_counter_print(struct vty *vty, const char *prefix,
pdu_counter_index_to_name(i), counter[i]);
}
}
+
+void pdu_counter_count_drop(struct isis_area *area, uint8_t pdu_type)
+{
+ pdu_counter_count(area->pdu_drop_counters, pdu_type);
+
+ if (area->log_pdu_drops) {
+ isis_log_pdu_drops(
+ area, pdu_counter_index_to_name(
+ pdu_type_to_counter_index(pdu_type)));
+ }
+}
+
+uint64_t pdu_counter_get_count(pdu_counter_t counter, uint8_t pdu_type)
+{
+ int index = pdu_type_to_counter_index(pdu_type);
+
+ if (index < 0)
+ return -1;
+ return counter[index];
+}
diff --git a/isisd/isis_pdu_counter.h b/isisd/isis_pdu_counter.h
index c53c47368f..5c35b4fb51 100644
--- a/isisd/isis_pdu_counter.h
+++ b/isisd/isis_pdu_counter.h
@@ -24,5 +24,7 @@ typedef uint64_t pdu_counter_t[PDU_COUNTER_SIZE];
void pdu_counter_print(struct vty *vty, const char *prefix,
pdu_counter_t counter);
void pdu_counter_count(pdu_counter_t counter, uint8_t pdu_type);
+void pdu_counter_count_drop(struct isis_area *area, uint8_t pdu_type);
+uint64_t pdu_counter_get_count(pdu_counter_t counter, uint8_t pdu_type);
#endif
diff --git a/isisd/isis_pfpacket.c b/isisd/isis_pfpacket.c
index 4f8ea4a5e7..af69fac1cd 100644
--- a/isisd/isis_pfpacket.c
+++ b/isisd/isis_pfpacket.c
@@ -35,14 +35,25 @@
/* tcpdump -i eth0 'isis' -dd */
static const struct sock_filter isisfilter[] = {
/* NB: we're in SOCK_DGRAM, so src/dst mac + length are stripped
- * off!
- * (OTOH it's a bit more lower-layer agnostic and might work
- * over GRE?) */
- /* { 0x28, 0, 0, 0x0000000c - 14 }, */
- /* { 0x25, 5, 0, 0x000005dc }, */
- {0x28, 0, 0, 0x0000000e - 14}, {0x15, 0, 3, 0x0000fefe},
- {0x30, 0, 0, 0x00000011 - 14}, {0x15, 0, 1, 0x00000083},
- {0x6, 0, 0, 0x00040000}, {0x6, 0, 0, 0x00000000},
+ * off! */
+ /* The following BPF filter accepts IS-IS over LLC and IS-IS over
+ * ethertype 0x00fe.
+ * BPF assembly:
+ * l0: ldh [0]
+ * l1: jeq #0xfefe, l2, l4
+ * l2: ldb [3]
+ * l3: jmp l7
+ * l4: ldh proto
+ * l5: jeq #0x00fe, l6, l9
+ * l6: ldb [0]
+ * l7: jeq #0x83, l8, l9
+ * l8: ret #0x40000
+ * l9: ret #0 */
+ {0x28, 0, 0, 0000000000}, {0x15, 0, 2, 0x0000fefe},
+ {0x30, 0, 0, 0x00000003}, {0x05, 0, 0, 0x00000003},
+ {0x28, 0, 0, 0xfffff000}, {0x15, 0, 3, 0x000000fe},
+ {0x30, 0, 0, 0000000000}, {0x15, 0, 1, 0x00000083},
+ {0x06, 0, 0, 0x00040000}, {0x06, 0, 0, 0000000000},
};
static const struct sock_fprog bpf = {
diff --git a/isisd/isis_route.c b/isisd/isis_route.c
index 711d5cbed9..3b653194bf 100644
--- a/isisd/isis_route.c
+++ b/isisd/isis_route.c
@@ -11,7 +11,7 @@
#include <zebra.h>
-#include "thread.h"
+#include "frrevent.h"
#include "linklist.h"
#include "vty.h"
#include "log.h"
diff --git a/isisd/isis_routemap.c b/isisd/isis_routemap.c
index 632b4ff95e..9be133c788 100644
--- a/isisd/isis_routemap.c
+++ b/isisd/isis_routemap.c
@@ -18,7 +18,7 @@
#include "plist.h"
#include "routemap.h"
#include "table.h"
-#include "thread.h"
+#include "frrevent.h"
#include "vty.h"
#include "isis_constants.h"
diff --git a/isisd/isis_snmp.c b/isisd/isis_snmp.c
index ae570a0864..f9e3780e29 100644
--- a/isisd/isis_snmp.c
+++ b/isisd/isis_snmp.c
@@ -259,11 +259,6 @@
/* Declare static local variables for convenience. */
SNMP_LOCAL_VARIABLES
-/* If ARRAY_SIZE is not available use a primitive substitution */
-#ifndef ARRAY_SIZE
-#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
-#endif
-
/*
* Define time function, it serves two purposes
* 1. Uses unint32_t for unix time and encapsulates
@@ -425,7 +420,7 @@ static struct isis_func_to_prefix isis_func_to_prefix_arr[] = {
{isis_snmp_find_isadj_ipaddr, {ISIS_ISADJIPADDR_ENTRY}, 4},
{isis_snmp_find_isadj_prot_supp, {ISIS_ISADJPROTSUPP_ENTRY}, 4},
};
-static size_t isis_func_to_prefix_count = ARRAY_SIZE(isis_func_to_prefix_arr);
+static size_t isis_func_to_prefix_count = array_size(isis_func_to_prefix_arr);
static struct variable isis_var_arr[] = {
{ISIS_SYS_VERSION, INTEGER, RONLY, isis_snmp_find_sys_object},
@@ -554,7 +549,7 @@ static struct variable isis_var_arr[] = {
isis_snmp_find_isadj_prot_supp},
};
-static const size_t isis_var_count = ARRAY_SIZE(isis_var_arr);
+static const size_t isis_var_count = array_size(isis_var_arr);
/* Minimal set of hard-coded data */
#define ISIS_VERSION (1)
@@ -838,12 +833,12 @@ static int isis_snmp_conv_next(uint8_t *buf, size_t max_len, size_t *out_len,
*/
static int isis_snmp_area_addr_lookup_exact(oid *oid_idx, size_t oid_idx_len,
struct isis_area **ret_area,
- struct area_addr **ret_addr)
+ struct iso_address **ret_addr)
{
uint8_t cmp_buf[ISIS_SNMP_OSI_ADDR_LEN_MAX];
size_t addr_len;
struct isis_area *area = NULL;
- struct area_addr *addr = NULL;
+ struct iso_address *addr = NULL;
struct listnode *addr_node;
struct isis *isis = isis_lookup_by_vrfid(VRF_DEFAULT);
@@ -885,15 +880,15 @@ static int isis_snmp_area_addr_lookup_exact(oid *oid_idx, size_t oid_idx_len,
static int isis_snmp_area_addr_lookup_next(oid *oid_idx, size_t oid_idx_len,
struct isis_area **ret_area,
- struct area_addr **ret_addr)
+ struct iso_address **ret_addr)
{
uint8_t cmp_buf[ISIS_SNMP_OSI_ADDR_LEN_MAX];
size_t addr_len;
int try_exact = 0;
struct isis_area *found_area = NULL;
struct isis_area *area = NULL;
- struct area_addr *found_addr = NULL;
- struct area_addr *addr = NULL;
+ struct iso_address *found_addr = NULL;
+ struct iso_address *addr = NULL;
struct listnode *addr_node;
struct isis *isis = isis_lookup_by_vrfid(VRF_DEFAULT);
@@ -1506,7 +1501,7 @@ static uint8_t *isis_snmp_find_man_area(struct variable *v, oid *name,
WriteMethod **write_method)
{
int res;
- struct area_addr *area_addr = NULL;
+ struct iso_address *area_addr = NULL;
oid *oid_idx;
size_t oid_idx_len;
size_t off = 0;
@@ -2161,7 +2156,10 @@ static uint8_t *isis_snmp_find_circ(struct variable *v, oid *name,
/*
* return false if lan hellos must be padded
*/
- if (circuit->pad_hellos)
+ if (circuit->pad_hellos == ISIS_HELLO_PADDING_ALWAYS ||
+ (circuit->pad_hellos ==
+ ISIS_HELLO_PADDING_DURING_ADJACENCY_FORMATION &&
+ circuit->upadjcount[0] + circuit->upadjcount[1] == 0))
return SNMP_INTEGER(ISIS_SNMP_TRUTH_VALUE_FALSE);
return SNMP_INTEGER(ISIS_SNMP_TRUTH_VALUE_TRUE);
@@ -2487,6 +2485,11 @@ static uint8_t *isis_snmp_find_isadj(struct variable *v, oid *name,
uint32_t delta_ticks;
time_t now_time;
+ /* Ring buffer to print SNPA */
+#define FORMAT_BUF_COUNT 4
+ static char snpa[FORMAT_BUF_COUNT][ISO_SYSID_STRLEN];
+ static size_t cur_buf = 0;
+
*write_method = NULL;
if (*length <= v->namelen) {
@@ -2533,9 +2536,10 @@ static uint8_t *isis_snmp_find_isadj(struct variable *v, oid *name,
return SNMP_INTEGER(adj->threeway_state);
case ISIS_ISADJ_NEIGHSNPAADDRESS: {
- const char *snpa = (char *)snpa_print(adj->snpa);
- *var_len = strlen(snpa);
- return (uint8_t *)snpa;
+ cur_buf = (cur_buf + 1) % FORMAT_BUF_COUNT;
+ snprintfrr(snpa[cur_buf], ISO_SYSID_STRLEN, "%pSY", adj->snpa);
+ *var_len = strlen(snpa[cur_buf]);
+ return (uint8_t *)snpa[cur_buf];
}
case ISIS_ISADJ_NEIGHSYSTYPE:
@@ -2794,7 +2798,7 @@ static uint8_t *isis_snmp_find_isadj_prot_supp(struct variable *v, oid *name,
/* Register ISIS-MIB. */
-static int isis_snmp_init(struct thread_master *tm)
+static int isis_snmp_init(struct event_loop *tm)
{
struct isis_func_to_prefix *h2f = isis_func_to_prefix_arr;
struct variable *v;
@@ -2856,7 +2860,7 @@ static int isis_snmp_db_overload_update(const struct isis_area *area)
/* Put in trap value */
snmp_varlist_add_variable(&notification_vars, isis_snmp_trap_var,
- ARRAY_SIZE(isis_snmp_trap_var), ASN_OBJECT_ID,
+ array_size(isis_snmp_trap_var), ASN_OBJECT_ID,
(uint8_t *)&isis_snmp_trap_val_db_overload,
sizeof(isis_snmp_trap_val_db_overload));
@@ -2865,11 +2869,11 @@ static int isis_snmp_db_overload_update(const struct isis_area *area)
snmp_varlist_add_variable(
&notification_vars, isis_snmp_trap_data_var_sys_level_index,
- ARRAY_SIZE(isis_snmp_trap_data_var_sys_level_index), INTEGER,
+ array_size(isis_snmp_trap_data_var_sys_level_index), INTEGER,
(uint8_t *)&val, sizeof(val));
/* Patch sys_level_state with proper index */
- off = ARRAY_SIZE(isis_snmp_trap_data_var_sys_level_state) - 1;
+ off = array_size(isis_snmp_trap_data_var_sys_level_state) - 1;
isis_snmp_trap_data_var_sys_level_state[off] = val;
/* Prepare data */
@@ -2880,7 +2884,7 @@ static int isis_snmp_db_overload_update(const struct isis_area *area)
snmp_varlist_add_variable(
&notification_vars, isis_snmp_trap_data_var_sys_level_state,
- ARRAY_SIZE(isis_snmp_trap_data_var_sys_level_state), INTEGER,
+ array_size(isis_snmp_trap_data_var_sys_level_state), INTEGER,
(uint8_t *)&val, sizeof(val));
send_v2trap(notification_vars);
@@ -2902,7 +2906,7 @@ static int isis_snmp_lsp_exceed_max_update(const struct isis_area *area,
/* Put in trap value */
snmp_varlist_add_variable(&notification_vars, isis_snmp_trap_var,
- ARRAY_SIZE(isis_snmp_trap_var), ASN_OBJECT_ID,
+ array_size(isis_snmp_trap_var), ASN_OBJECT_ID,
(uint8_t *)&isis_snmp_trap_val_lsp_exceed_max,
sizeof(isis_snmp_trap_val_lsp_exceed_max));
@@ -2911,12 +2915,12 @@ static int isis_snmp_lsp_exceed_max_update(const struct isis_area *area,
snmp_varlist_add_variable(
&notification_vars, isis_snmp_trap_data_var_sys_level_index,
- ARRAY_SIZE(isis_snmp_trap_data_var_sys_level_index), INTEGER,
+ array_size(isis_snmp_trap_data_var_sys_level_index), INTEGER,
(uint8_t *)&val, sizeof(val));
snmp_varlist_add_variable(
&notification_vars, isis_snmp_trap_data_var_pdu_lsp_id,
- ARRAY_SIZE(isis_snmp_trap_data_var_pdu_lsp_id), STRING, lsp_id,
+ array_size(isis_snmp_trap_data_var_pdu_lsp_id), STRING, lsp_id,
ISIS_SYS_ID_LEN + 2);
send_v2trap(notification_vars);
@@ -2959,18 +2963,18 @@ static void isis_snmp_update_worker_a(const struct isis_circuit *circuit,
/* Put in trap value */
memcpy(var_name, isis_snmp_notifications,
sizeof(isis_snmp_notifications));
- var_count = ARRAY_SIZE(isis_snmp_notifications);
+ var_count = array_size(isis_snmp_notifications);
var_name[var_count++] = trap_id;
/* Put in trap value */
snmp_varlist_add_variable(&notification_vars, isis_snmp_trap_var,
- ARRAY_SIZE(isis_snmp_trap_var), ASN_OBJECT_ID,
+ array_size(isis_snmp_trap_var), ASN_OBJECT_ID,
(uint8_t *)var_name, var_count * sizeof(oid));
val = circuit->is_type;
snmp_varlist_add_variable(
&notification_vars, isis_snmp_trap_data_var_sys_level_index,
- ARRAY_SIZE(isis_snmp_trap_data_var_sys_level_index), INTEGER,
+ array_size(isis_snmp_trap_data_var_sys_level_index), INTEGER,
(uint8_t *)&val, sizeof(val));
if (oid_a_len != 0) {
@@ -2989,7 +2993,7 @@ static void isis_snmp_update_worker_a(const struct isis_circuit *circuit,
snmp_varlist_add_variable(
&notification_vars, isis_snmp_trap_data_var_circ_if_index,
- ARRAY_SIZE(isis_snmp_trap_data_var_circ_if_index), UNSIGNED32,
+ array_size(isis_snmp_trap_data_var_circ_if_index), UNSIGNED32,
(uint8_t *)&val, sizeof(val));
@@ -3039,18 +3043,18 @@ static void isis_snmp_update_worker_b(const struct isis_circuit *circuit,
/* Put in trap value */
memcpy(var_name, isis_snmp_notifications,
sizeof(isis_snmp_notifications));
- var_count = ARRAY_SIZE(isis_snmp_notifications);
+ var_count = array_size(isis_snmp_notifications);
var_name[var_count++] = trap_id;
/* Put in trap value */
snmp_varlist_add_variable(&notification_vars, isis_snmp_trap_var,
- ARRAY_SIZE(isis_snmp_trap_var), ASN_OBJECT_ID,
+ array_size(isis_snmp_trap_var), ASN_OBJECT_ID,
(uint8_t *)var_name, var_count * sizeof(oid));
val = circuit->is_type;
snmp_varlist_add_variable(
&notification_vars, isis_snmp_trap_data_var_sys_level_index,
- ARRAY_SIZE(isis_snmp_trap_data_var_sys_level_index), INTEGER,
+ array_size(isis_snmp_trap_data_var_sys_level_index), INTEGER,
(uint8_t *)&val, sizeof(val));
if (circuit->interface == NULL)
@@ -3060,7 +3064,7 @@ static void isis_snmp_update_worker_b(const struct isis_circuit *circuit,
snmp_varlist_add_variable(
&notification_vars, isis_snmp_trap_data_var_circ_if_index,
- ARRAY_SIZE(isis_snmp_trap_data_var_circ_if_index), UNSIGNED32,
+ array_size(isis_snmp_trap_data_var_circ_if_index), UNSIGNED32,
(uint8_t *)&val, sizeof(val));
@@ -3105,9 +3109,9 @@ static int isis_snmp_id_len_mismatch_update(const struct isis_circuit *circuit,
isis_snmp_update_worker_a(
circuit, ISIS_TRAP_ID_LEN_MISMATCH,
isis_snmp_trap_data_var_pdu_field_len,
- ARRAY_SIZE(isis_snmp_trap_data_var_pdu_field_len), UNSIGNED32,
+ array_size(isis_snmp_trap_data_var_pdu_field_len), UNSIGNED32,
&val, sizeof(val), isis_snmp_trap_data_var_pdu_fragment,
- ARRAY_SIZE(isis_snmp_trap_data_var_pdu_fragment), STRING,
+ array_size(isis_snmp_trap_data_var_pdu_fragment), STRING,
raw_pdu, raw_pdu_len);
return 0;
}
@@ -3130,10 +3134,10 @@ isis_snmp_max_area_addr_mismatch_update(const struct isis_circuit *circuit,
isis_snmp_update_worker_a(
circuit, ISIS_TRAP_MAX_AREA_ADDR_MISMATCH,
isis_snmp_trap_data_var_pdu_max_area_addr,
- ARRAY_SIZE(isis_snmp_trap_data_var_pdu_max_area_addr),
+ array_size(isis_snmp_trap_data_var_pdu_max_area_addr),
UNSIGNED32, &val, sizeof(val),
isis_snmp_trap_data_var_pdu_fragment,
- ARRAY_SIZE(isis_snmp_trap_data_var_pdu_fragment), STRING,
+ array_size(isis_snmp_trap_data_var_pdu_fragment), STRING,
raw_pdu, raw_pdu_len);
return 0;
}
@@ -3147,7 +3151,7 @@ static int isis_snmp_own_lsp_purge_update(const struct isis_circuit *circuit,
isis_snmp_update_worker_a(
circuit, ISIS_TRAP_OWN_LSP_PURGE, NULL, 0, STRING, NULL, 0,
isis_snmp_trap_data_var_pdu_lsp_id,
- ARRAY_SIZE(isis_snmp_trap_data_var_pdu_lsp_id), STRING, lsp_id,
+ array_size(isis_snmp_trap_data_var_pdu_lsp_id), STRING, lsp_id,
ISIS_SYS_ID_LEN + 2);
return 0;
}
@@ -3161,7 +3165,7 @@ static int isis_snmp_seqno_skipped_update(const struct isis_circuit *circuit,
isis_snmp_update_worker_a(
circuit, ISIS_TRAP_SEQNO_SKIPPED, NULL, 0, STRING, NULL, 0,
isis_snmp_trap_data_var_pdu_lsp_id,
- ARRAY_SIZE(isis_snmp_trap_data_var_pdu_lsp_id), STRING, lsp_id,
+ array_size(isis_snmp_trap_data_var_pdu_lsp_id), STRING, lsp_id,
ISIS_SYS_ID_LEN + 2);
return 0;
}
@@ -3180,7 +3184,7 @@ isis_snmp_authentication_type_failure_update(const struct isis_circuit *circuit,
isis_snmp_update_worker_a(
circuit, ISIS_TRAP_AUTHEN_TYPE_FAILURE, NULL, 0, STRING, NULL,
0, isis_snmp_trap_data_var_pdu_fragment,
- ARRAY_SIZE(isis_snmp_trap_data_var_pdu_fragment), STRING,
+ array_size(isis_snmp_trap_data_var_pdu_fragment), STRING,
raw_pdu, raw_pdu_len);
return 0;
}
@@ -3198,7 +3202,7 @@ isis_snmp_authentication_failure_update(const struct isis_circuit *circuit,
isis_snmp_update_worker_a(
circuit, ISIS_TRAP_AUTHEN_FAILURE, NULL, 0, STRING, NULL, 0,
isis_snmp_trap_data_var_pdu_fragment,
- ARRAY_SIZE(isis_snmp_trap_data_var_pdu_fragment), STRING,
+ array_size(isis_snmp_trap_data_var_pdu_fragment), STRING,
raw_pdu, raw_pdu_len);
return 0;
}
@@ -3220,9 +3224,9 @@ static int isis_snmp_version_skew_update(const struct isis_circuit *circuit,
isis_snmp_update_worker_b(
circuit, ISIS_TRAP_VERSION_SKEW,
isis_snmp_trap_data_var_pdu_proto_ver,
- ARRAY_SIZE(isis_snmp_trap_data_var_pdu_proto_ver), UNSIGNED32,
+ array_size(isis_snmp_trap_data_var_pdu_proto_ver), UNSIGNED32,
&val, sizeof(val), isis_snmp_trap_data_var_pdu_fragment,
- ARRAY_SIZE(isis_snmp_trap_data_var_pdu_fragment), STRING,
+ array_size(isis_snmp_trap_data_var_pdu_fragment), STRING,
raw_pdu, raw_pdu_len);
return 0;
}
@@ -3245,7 +3249,7 @@ static int isis_snmp_area_mismatch_update(const struct isis_circuit *circuit,
/* Put in trap value */
snmp_varlist_add_variable(&notification_vars, isis_snmp_trap_var,
- ARRAY_SIZE(isis_snmp_trap_var), ASN_OBJECT_ID,
+ array_size(isis_snmp_trap_var), ASN_OBJECT_ID,
(uint8_t *)&isis_snmp_trap_val_area_mismatch,
sizeof(isis_snmp_trap_val_area_mismatch));
@@ -3257,7 +3261,7 @@ static int isis_snmp_area_mismatch_update(const struct isis_circuit *circuit,
snmp_varlist_add_variable(
&notification_vars, isis_snmp_trap_data_var_circ_if_index,
- ARRAY_SIZE(isis_snmp_trap_data_var_circ_if_index), UNSIGNED32,
+ array_size(isis_snmp_trap_data_var_circ_if_index), UNSIGNED32,
(uint8_t *)&val, sizeof(val));
@@ -3266,7 +3270,7 @@ static int isis_snmp_area_mismatch_update(const struct isis_circuit *circuit,
snmp_varlist_add_variable(
&notification_vars, isis_snmp_trap_data_var_pdu_fragment,
- ARRAY_SIZE(isis_snmp_trap_data_var_pdu_fragment), STRING,
+ array_size(isis_snmp_trap_data_var_pdu_fragment), STRING,
raw_pdu, raw_pdu_len);
send_v2trap(notification_vars);
@@ -3289,7 +3293,7 @@ static int isis_snmp_reject_adjacency_update(const struct isis_circuit *circuit,
isis_snmp_update_worker_a(
circuit, ISIS_TRAP_REJ_ADJACENCY, NULL, 0, STRING, NULL, 0,
isis_snmp_trap_data_var_pdu_fragment,
- ARRAY_SIZE(isis_snmp_trap_data_var_pdu_fragment), STRING,
+ array_size(isis_snmp_trap_data_var_pdu_fragment), STRING,
raw_pdu, raw_pdu_len);
return 0;
}
@@ -3304,9 +3308,9 @@ static int isis_snmp_lsp_too_large_update(const struct isis_circuit *circuit,
isis_snmp_update_worker_b(
circuit, ISIS_TRAP_LSP_TOO_LARGE,
isis_snmp_trap_data_var_pdu_lsp_size,
- ARRAY_SIZE(isis_snmp_trap_data_var_pdu_lsp_size), UNSIGNED32,
+ array_size(isis_snmp_trap_data_var_pdu_lsp_size), UNSIGNED32,
&pdu_size, sizeof(pdu_size), isis_snmp_trap_data_var_pdu_lsp_id,
- ARRAY_SIZE(isis_snmp_trap_data_var_pdu_lsp_id), STRING, lsp_id,
+ array_size(isis_snmp_trap_data_var_pdu_lsp_id), STRING, lsp_id,
ISIS_SYS_ID_LEN + 2);
return 0;
}
@@ -3331,9 +3335,9 @@ static int isis_snmp_adj_state_change_update(const struct isis_adjacency *adj)
isis_snmp_update_worker_b(
adj->circuit, ISIS_TRAP_ADJ_STATE_CHANGE,
isis_snmp_trap_data_var_pdu_lsp_id,
- ARRAY_SIZE(isis_snmp_trap_data_var_pdu_lsp_id), STRING, lsp_id,
+ array_size(isis_snmp_trap_data_var_pdu_lsp_id), STRING, lsp_id,
ISIS_SYS_ID_LEN + 2, isis_snmp_trap_data_var_adj_state,
- ARRAY_SIZE(isis_snmp_trap_data_var_adj_state), INTEGER, &val,
+ array_size(isis_snmp_trap_data_var_adj_state), INTEGER, &val,
sizeof(val));
return 0;
}
@@ -3356,7 +3360,7 @@ static int isis_snmp_lsp_error_update(const struct isis_circuit *circuit,
/* Put in trap value */
snmp_varlist_add_variable(&notification_vars, isis_snmp_trap_var,
- ARRAY_SIZE(isis_snmp_trap_var), ASN_OBJECT_ID,
+ array_size(isis_snmp_trap_var), ASN_OBJECT_ID,
(uint8_t *)&isis_snmp_trap_val_lsp_error,
sizeof(isis_snmp_trap_val_lsp_error));
@@ -3365,13 +3369,13 @@ static int isis_snmp_lsp_error_update(const struct isis_circuit *circuit,
snmp_varlist_add_variable(
&notification_vars, isis_snmp_trap_data_var_sys_level_index,
- ARRAY_SIZE(isis_snmp_trap_data_var_sys_level_index), INTEGER,
+ array_size(isis_snmp_trap_data_var_sys_level_index), INTEGER,
(uint8_t *)&val, sizeof(val));
snmp_varlist_add_variable(
&notification_vars, isis_snmp_trap_data_var_pdu_lsp_id,
- ARRAY_SIZE(isis_snmp_trap_data_var_pdu_lsp_id), STRING, lsp_id,
+ array_size(isis_snmp_trap_data_var_pdu_lsp_id), STRING, lsp_id,
ISIS_SYS_ID_LEN + 2);
/* Prepare data */
@@ -3382,7 +3386,7 @@ static int isis_snmp_lsp_error_update(const struct isis_circuit *circuit,
snmp_varlist_add_variable(
&notification_vars, isis_snmp_trap_data_var_circ_if_index,
- ARRAY_SIZE(isis_snmp_trap_data_var_circ_if_index), UNSIGNED32,
+ array_size(isis_snmp_trap_data_var_circ_if_index), UNSIGNED32,
(uint8_t *)&val, sizeof(val));
/* Prepare data */
@@ -3391,7 +3395,7 @@ static int isis_snmp_lsp_error_update(const struct isis_circuit *circuit,
snmp_varlist_add_variable(
&notification_vars, isis_snmp_trap_data_var_pdu_fragment,
- ARRAY_SIZE(isis_snmp_trap_data_var_pdu_fragment), STRING,
+ array_size(isis_snmp_trap_data_var_pdu_fragment), STRING,
raw_pdu, raw_pdu_len);
/* Prepare data */
@@ -3399,7 +3403,7 @@ static int isis_snmp_lsp_error_update(const struct isis_circuit *circuit,
snmp_varlist_add_variable(
&notification_vars, isis_snmp_trap_data_var_error_offset,
- ARRAY_SIZE(isis_snmp_trap_data_var_error_offset), UNSIGNED32,
+ array_size(isis_snmp_trap_data_var_error_offset), UNSIGNED32,
(uint8_t *)&val, sizeof(val));
/* Prepare data */
@@ -3407,7 +3411,7 @@ static int isis_snmp_lsp_error_update(const struct isis_circuit *circuit,
snmp_varlist_add_variable(
&notification_vars, isis_snmp_trap_data_var_error_tlv_type,
- ARRAY_SIZE(isis_snmp_trap_data_var_error_tlv_type), UNSIGNED32,
+ array_size(isis_snmp_trap_data_var_error_tlv_type), UNSIGNED32,
(uint8_t *)&val, sizeof(val));
send_v2trap(notification_vars);
diff --git a/isisd/isis_spf.c b/isisd/isis_spf.c
index e1aec683d8..8597049ac0 100644
--- a/isisd/isis_spf.c
+++ b/isisd/isis_spf.c
@@ -11,7 +11,7 @@
#include <zebra.h>
-#include "thread.h"
+#include "frrevent.h"
#include "linklist.h"
#include "vty.h"
#include "log.h"
@@ -241,11 +241,7 @@ void isis_vertex_del(struct isis_vertex *vertex)
{
list_delete(&vertex->Adj_N);
list_delete(&vertex->parents);
- if (vertex->firsthops) {
- hash_clean(vertex->firsthops, NULL);
- hash_free(vertex->firsthops);
- vertex->firsthops = NULL;
- }
+ hash_clean_and_free(&vertex->firsthops, NULL);
memset(vertex, 0, sizeof(struct isis_vertex));
XFREE(MTYPE_ISIS_VERTEX, vertex);
@@ -371,8 +367,7 @@ struct isis_spftree *isis_spftree_new(struct isis_area *area,
void isis_spftree_del(struct isis_spftree *spftree)
{
- hash_clean(spftree->prefix_sids, NULL);
- hash_free(spftree->prefix_sids);
+ hash_clean_and_free(&spftree->prefix_sids, NULL);
isis_zebra_rlfa_unregister_all(spftree);
isis_rlfa_list_clear(spftree);
list_delete(&spftree->lfa.remote.pc_spftrees);
@@ -1072,8 +1067,8 @@ end:
&& !isis_level2_adj_up(spftree->area)) {
struct prefix_pair ip_info = { {0} };
if (IS_DEBUG_RTE_EVENTS)
- zlog_debug("ISIS-Spf (%s): add default %s route",
- rawlspid_print(lsp->hdr.lsp_id),
+ zlog_debug("ISIS-Spf (%pLS): add default %s route",
+ lsp->hdr.lsp_id,
spftree->family == AF_INET ? "ipv4"
: "ipv6");
@@ -1212,9 +1207,8 @@ static void isis_spf_preload_tent(struct isis_spftree *spftree,
if (isis_lfa_excise_adj_check(spftree, adj_id)) {
if (IS_DEBUG_LFA)
- zlog_debug("ISIS-SPF: excising adjacency %s",
- isis_format_id(sadj->id,
- ISIS_SYS_ID_LEN + 1));
+ zlog_debug("ISIS-SPF: excising adjacency %pPN",
+ sadj->id);
continue;
}
@@ -1329,8 +1323,8 @@ static void spf_adj_list_parse_tlv(struct isis_spftree *spftree,
LSP_FRAGMENT(lspid) = 0;
lsp = lsp_search(spftree->lspdb, lspid);
if (lsp == NULL || lsp->hdr.rem_lifetime == 0) {
- zlog_warn("ISIS-SPF: No LSP found from root to L%d %s",
- spftree->level, rawlspid_print(lspid));
+ zlog_warn("ISIS-SPF: No LSP found from root to L%d %pLS",
+ spftree->level, lspid);
return;
}
@@ -1668,9 +1662,8 @@ static void isis_spf_loop(struct isis_spftree *spftree,
lsp = lsp_for_vertex(spftree, vertex);
if (!lsp) {
- zlog_warn("ISIS-SPF: No LSP found for %s",
- isis_format_id(vertex->N.id,
- sizeof(vertex->N.id)));
+ zlog_warn("ISIS-SPF: No LSP found for %pPN",
+ vertex->N.id);
continue;
}
@@ -1858,9 +1851,9 @@ void isis_spf_switchover_routes(struct isis_area *area,
family, nexthop_ip, ifindex);
}
-static void isis_run_spf_cb(struct thread *thread)
+static void isis_run_spf_cb(struct event *thread)
{
- struct isis_spf_run *run = THREAD_ARG(thread);
+ struct isis_spf_run *run = EVENT_ARG(thread);
struct isis_area *area = run->area;
int level = run->level;
int have_run = 0;
@@ -1955,7 +1948,7 @@ int _isis_spf_schedule(struct isis_area *area, int level,
area->area_tag, level, diff, func, file, line);
}
- THREAD_OFF(area->t_rlfa_rib_update);
+ EVENT_OFF(area->t_rlfa_rib_update);
if (area->spf_delay_ietf[level - 1]) {
/* Need to call schedule function also if spf delay is running
* to
@@ -1966,9 +1959,9 @@ int _isis_spf_schedule(struct isis_area *area, int level,
if (area->spf_timer[level - 1])
return ISIS_OK;
- thread_add_timer_msec(master, isis_run_spf_cb,
- isis_run_spf_arg(area, level), delay,
- &area->spf_timer[level - 1]);
+ event_add_timer_msec(master, isis_run_spf_cb,
+ isis_run_spf_arg(area, level), delay,
+ &area->spf_timer[level - 1]);
return ISIS_OK;
}
@@ -1995,8 +1988,8 @@ int _isis_spf_schedule(struct isis_area *area, int level,
timer = area->min_spf_interval[level - 1] - diff;
}
- thread_add_timer(master, isis_run_spf_cb, isis_run_spf_arg(area, level),
- timer, &area->spf_timer[level - 1]);
+ event_add_timer(master, isis_run_spf_cb, isis_run_spf_arg(area, level),
+ timer, &area->spf_timer[level - 1]);
if (IS_DEBUG_SPF_EVENTS)
zlog_debug("ISIS-SPF (%s) L%d SPF scheduled %ld sec from now",
diff --git a/isisd/isis_sr.c b/isisd/isis_sr.c
index 4293991654..e43b84ab2e 100644
--- a/isisd/isis_sr.c
+++ b/isisd/isis_sr.c
@@ -1022,14 +1022,14 @@ static void show_node(struct vty *vty, struct isis_area *area, int level)
if (!cap)
continue;
- ttable_add_row(
- tt, "%s|%u - %u|%u - %u|%s|%u",
- sysid_print(lsp->hdr.lsp_id), cap->srgb.lower_bound,
- cap->srgb.lower_bound + cap->srgb.range_size - 1,
- cap->srlb.lower_bound,
- cap->srlb.lower_bound + cap->srlb.range_size - 1,
- cap->algo[0] == SR_ALGORITHM_SPF ? "SPF" : "S-SPF",
- cap->msd);
+ ttable_add_row(tt, "%pSY|%u - %u|%u - %u|%s|%u",
+ lsp->hdr.lsp_id, cap->srgb.lower_bound,
+ cap->srgb.lower_bound + cap->srgb.range_size - 1,
+ cap->srlb.lower_bound,
+ cap->srlb.lower_bound + cap->srlb.range_size - 1,
+ cap->algo[0] == SR_ALGORITHM_SPF ? "SPF"
+ : "S-SPF",
+ cap->msd);
}
/* Dump the generated table. */
@@ -1081,11 +1081,11 @@ DEFUN(show_sr_node, show_sr_node_cmd,
*
* @return 1 on success
*/
-static void sr_start_label_manager(struct thread *start)
+static void sr_start_label_manager(struct event *start)
{
struct isis_area *area;
- area = THREAD_ARG(start);
+ area = EVENT_ARG(start);
/* re-attempt to start SR & Label Manager connection */
isis_sr_start(area);
@@ -1108,8 +1108,8 @@ int isis_sr_start(struct isis_area *area)
if (!isis_zebra_label_manager_ready())
if (isis_zebra_label_manager_connect() < 0) {
/* Re-attempt to connect to Label Manager in 1 sec. */
- thread_add_timer(master, sr_start_label_manager, area,
- 1, &srdb->t_start_lm);
+ event_add_timer(master, sr_start_label_manager, area, 1,
+ &srdb->t_start_lm);
return -1;
}
@@ -1168,7 +1168,7 @@ void isis_sr_stop(struct isis_area *area)
area->area_tag);
/* Disable any re-attempt to connect to Label Manager */
- THREAD_OFF(srdb->t_start_lm);
+ EVENT_OFF(srdb->t_start_lm);
/* Uninstall all local Adjacency-SIDs. */
for (ALL_LIST_ELEMENTS(area->srdb.adj_sids, node, nnode, sra))
diff --git a/isisd/isis_sr.h b/isisd/isis_sr.h
index 627f1fb748..4ced5f4e83 100644
--- a/isisd/isis_sr.h
+++ b/isisd/isis_sr.h
@@ -155,7 +155,7 @@ struct isis_sr_db {
bool enabled;
/* Thread timer to start Label Manager */
- struct thread *t_start_lm;
+ struct event *t_start_lm;
/* List of local Adjacency-SIDs. */
struct list *adj_sids;
diff --git a/isisd/isis_te.c b/isisd/isis_te.c
index 3659f4e07c..4e180ead61 100644
--- a/isisd/isis_te.c
+++ b/isisd/isis_te.c
@@ -13,7 +13,7 @@
#include <math.h>
#include "linklist.h"
-#include "thread.h"
+#include "frrevent.h"
#include "vty.h"
#include "stream.h"
#include "memory.h"
@@ -903,7 +903,7 @@ static int lsp_to_edge_cb(const uint8_t *id, uint32_t metric, bool old_metric,
struct ls_edge *edge, *dst;
struct ls_attributes *attr;
- te_debug(" |- Process Extended IS for %s", sysid_print(id));
+ te_debug(" |- Process Extended IS for %pSY", id);
/* Check parameters */
if (old_metric || !args || !tlvs)
@@ -1075,16 +1075,29 @@ static int lsp_to_subnet_cb(const struct prefix *prefix, uint32_t metric,
}
if (!std)
prefix_copy(&p, prefix);
- else
+ else {
+ /* Remove old subnet if any before prefix adjustment */
+ subnet = ls_find_subnet(args->ted, prefix);
+ if (subnet) {
+ if (args->export) {
+ subnet->status = DELETE;
+ isis_te_export(LS_MSG_TYPE_PREFIX, subnet);
+ }
+ te_debug(" |- Remove subnet with prefix %pFX",
+ &subnet->key);
+ ls_subnet_del_all(args->ted, subnet);
+ }
te_debug(" |- Adjust prefix %pFX with local address to: %pFX",
prefix, &p);
+ }
/* Search existing Subnet in TED ... */
- subnet = ls_find_subnet(args->ted, p);
+ subnet = ls_find_subnet(args->ted, &p);
/* ... and create a new Subnet if not found */
if (!subnet) {
- ls_pref = ls_prefix_new(vertex->node->adv, p);
+ ls_pref = ls_prefix_new(vertex->node->adv, &p);
subnet = ls_subnet_add(args->ted, ls_pref);
+ /* Stop processing if we are unable to create a new subnet */
if (!subnet)
return LSP_ITER_CONTINUE;
}
@@ -1167,14 +1180,14 @@ static void isis_te_parse_lsp(struct mpls_te_area *mta, struct isis_lsp *lsp)
ted = mta->ted;
- te_debug("ISIS-TE(%s): Parse LSP %s", lsp->area->area_tag,
- sysid_print(lsp->hdr.lsp_id));
+ te_debug("ISIS-TE(%s): Parse LSP %pSY", lsp->area->area_tag,
+ lsp->hdr.lsp_id);
/* First parse LSP to obtain the corresponding Vertex */
vertex = lsp_to_vertex(ted, lsp);
if (!vertex) {
- zlog_warn("Unable to build Vertex from LSP %s. Abort!",
- sysid_print(lsp->hdr.lsp_id));
+ zlog_warn("Unable to build Vertex from LSP %pSY. Abort!",
+ lsp->hdr.lsp_id);
return;
}
@@ -1238,8 +1251,8 @@ static void isis_te_delete_lsp(struct mpls_te_area *mta, struct isis_lsp *lsp)
if (!IS_MPLS_TE(mta) || !mta->ted || !lsp)
return;
- te_debug("ISIS-TE(%s): Delete Link State TED objects from LSP %s",
- lsp->area->area_tag, sysid_print(lsp->hdr.lsp_id));
+ te_debug("ISIS-TE(%s): Delete Link State TED objects from LSP %pSY",
+ lsp->area->area_tag, lsp->hdr.lsp_id);
/* Compute Link State Node ID from IS-IS sysID ... */
if (lsp->level == ISIS_LEVEL1)
@@ -1822,7 +1835,7 @@ static int show_ted(struct vty *vty, struct cmd_token *argv[], int argc,
return CMD_WARNING_CONFIG_FAILED;
}
/* Get the Subnet from the Link State Database */
- subnet = ls_find_subnet(ted, pref);
+ subnet = ls_find_subnet(ted, &pref);
if (!subnet) {
vty_out(vty, "No subnet found for ID %pFX\n",
&pref);
@@ -1835,7 +1848,7 @@ static int show_ted(struct vty *vty, struct cmd_token *argv[], int argc,
return CMD_WARNING_CONFIG_FAILED;
}
/* Get the Subnet from the Link State Database */
- subnet = ls_find_subnet(ted, pref);
+ subnet = ls_find_subnet(ted, &pref);
if (!subnet) {
vty_out(vty, "No subnet found for ID %pFX\n",
&pref);
diff --git a/isisd/isis_tlvs.c b/isisd/isis_tlvs.c
index b52a38be7f..3b6db0ee17 100644
--- a/isisd/isis_tlvs.c
+++ b/isisd/isis_tlvs.c
@@ -661,7 +661,7 @@ static void format_item_ext_subtlvs(struct isis_ext_subtlvs *exts,
sbuf_push(
buf, indent,
"Lan-Adjacency-SID: %u, Weight: %hhu, Flags: F:%c B:%c, V:%c, L:%c, S:%c, P:%c\n"
- " Neighbor-ID: %s\n",
+ " Neighbor-ID: %pSY\n",
lan->sid, lan->weight,
lan->flags & EXT_SUBTLV_LINK_ADJ_SID_FFLG
? '1'
@@ -681,7 +681,7 @@ static void format_item_ext_subtlvs(struct isis_ext_subtlvs *exts,
lan->flags & EXT_SUBTLV_LINK_ADJ_SID_PFLG
? '1'
: '0',
- isis_format_id(lan->neighbor_id, 6));
+ lan->neighbor_id);
}
}
}
@@ -1590,14 +1590,14 @@ static void format_item_area_address(uint16_t mtid, struct isis_item *i,
int indent)
{
struct isis_area_address *addr = (struct isis_area_address *)i;
+ struct iso_address iso_addr;
- if (json) {
- json_object_string_add(json, "area-addr",
- isonet_print(addr->addr, addr->len));
- } else {
- sbuf_push(buf, indent, "Area Address: %s\n",
- isonet_print(addr->addr, addr->len));
- }
+ memcpy(iso_addr.area_addr, addr->addr, ISO_ADDR_SIZE);
+ iso_addr.addr_len = addr->len;
+ if (json)
+ json_object_string_addf(json, "area-addr", "%pIS", &iso_addr);
+ else
+ sbuf_push(buf, indent, "Area Address: %pIS\n", &iso_addr);
}
static void free_item_area_address(struct isis_item *i)
@@ -1678,17 +1678,18 @@ static void format_item_oldstyle_reach(uint16_t mtid, struct isis_item *i,
struct json_object *json, int indent)
{
struct isis_oldstyle_reach *r = (struct isis_oldstyle_reach *)i;
+ char sys_id[ISO_SYSID_STRLEN];
+ snprintfrr(sys_id, ISO_SYSID_STRLEN, "%pPN", r->id);
if (json) {
struct json_object *old_json;
old_json = json_object_new_object();
json_object_object_add(json, "old-reach-style", old_json);
- json_object_string_add(old_json, "is-reach",
- isis_format_id(r->id, 7));
+ json_object_string_add(old_json, "is-reach", sys_id);
json_object_int_add(old_json, "metric", r->metric);
} else
sbuf_push(buf, indent, "IS Reachability: %s (Metric: %hhu)\n",
- isis_format_id(r->id, 7), r->metric);
+ sys_id, r->metric);
}
static void free_item_oldstyle_reach(struct isis_item *i)
@@ -1760,13 +1761,13 @@ static void format_item_lan_neighbor(uint16_t mtid, struct isis_item *i,
int indent)
{
struct isis_lan_neighbor *n = (struct isis_lan_neighbor *)i;
+ char sys_id[ISO_SYSID_STRLEN];
- if (json) {
- json_object_string_add(json, "lan-neighbor",
- isis_format_id(n->mac, 6));
- } else
- sbuf_push(buf, indent, "LAN Neighbor: %s\n",
- isis_format_id(n->mac, 6));
+ snprintfrr(sys_id, ISO_SYSID_STRLEN, "%pSY", n->mac);
+ if (json)
+ json_object_string_add(json, "lan-neighbor", sys_id);
+ else
+ sbuf_push(buf, indent, "LAN Neighbor: %s\n", sys_id);
}
static void free_item_lan_neighbor(struct isis_item *i)
@@ -1831,23 +1832,25 @@ static void format_item_lsp_entry(uint16_t mtid, struct isis_item *i,
int indent)
{
struct isis_lsp_entry *e = (struct isis_lsp_entry *)i;
+ char sys_id[ISO_SYSID_STRLEN];
+ snprintfrr(sys_id, ISO_SYSID_STRLEN, "%pLS", e->id);
if (json) {
char buf[255];
struct json_object *lsp_json;
lsp_json = json_object_new_object();
json_object_object_add(json, "lsp-entry", lsp_json);
- json_object_string_add(lsp_json, "id", isis_format_id(e->id, 8));
+ json_object_string_add(lsp_json, "id", sys_id);
snprintfrr(buf,sizeof(buf),"0x%08x",e->seqno);
json_object_string_add(lsp_json, "seq", buf);
snprintfrr(buf,sizeof(buf),"0x%04hx",e->checksum);
json_object_string_add(lsp_json, "chksum", buf);
json_object_int_add(lsp_json, "lifetime", e->checksum);
} else
- sbuf_push(buf, indent,
- "LSP Entry: %s, seq 0x%08x, cksum 0x%04hx, lifetime %hus\n",
- isis_format_id(e->id, 8), e->seqno, e->checksum,
- e->rem_lifetime);
+ sbuf_push(
+ buf, indent,
+ "LSP Entry: %s, seq 0x%08x, cksum 0x%04hx, lifetime %hus\n",
+ sys_id, e->seqno, e->checksum, e->rem_lifetime);
}
static void free_item_lsp_entry(struct isis_item *i)
@@ -1919,7 +1922,9 @@ static void format_item_extended_reach(uint16_t mtid, struct isis_item *i,
struct json_object *json, int indent)
{
struct isis_extended_reach *r = (struct isis_extended_reach *)i;
+ char sys_id[ISO_SYSID_STRLEN];
+ snprintfrr(sys_id, ISO_SYSID_STRLEN, "%pPN", r->id);
if (json) {
struct json_object *reach_json;
reach_json = json_object_new_object();
@@ -1927,8 +1932,7 @@ static void format_item_extended_reach(uint16_t mtid, struct isis_item *i,
json_object_string_add(
reach_json, "mt-id",
(mtid == ISIS_MT_IPV4_UNICAST) ? "Extended" : "MT");
- json_object_string_add(reach_json, "id",
- isis_format_id(r->id, 7));
+ json_object_string_add(reach_json, "id", sys_id);
json_object_int_add(reach_json, "metric", r->metric);
if (mtid != ISIS_MT_IPV4_UNICAST)
json_object_string_add(reach_json, "mt-name",
@@ -1940,7 +1944,7 @@ static void format_item_extended_reach(uint16_t mtid, struct isis_item *i,
} else {
sbuf_push(buf, indent, "%s Reachability: %s (Metric: %u)",
(mtid == ISIS_MT_IPV4_UNICAST) ? "Extended" : "MT",
- isis_format_id(r->id, 7), r->metric);
+ sys_id, r->metric);
if (mtid != ISIS_MT_IPV4_UNICAST)
sbuf_push(buf, 0, " %s", isis_mtid2str(mtid));
sbuf_push(buf, 0, "\n");
@@ -3125,9 +3129,12 @@ static void
format_tlv_threeway_adj(const struct isis_threeway_adj *threeway_adj,
struct sbuf *buf, struct json_object *json, int indent)
{
+ char sys_id[ISO_SYSID_STRLEN];
+
if (!threeway_adj)
return;
+ snprintfrr(sys_id, ISO_SYSID_STRLEN, "%pSY", threeway_adj->neighbor_id);
if (json) {
struct json_object *three_json;
three_json = json_object_new_object();
@@ -3140,9 +3147,7 @@ format_tlv_threeway_adj(const struct isis_threeway_adj *threeway_adj,
threeway_adj->local_circuit_id);
if (!threeway_adj->neighbor_set)
return;
- json_object_string_add(
- three_json, "neigh-system-id",
- isis_format_id(threeway_adj->neighbor_id, 6));
+ json_object_string_add(three_json, "neigh-system-id", sys_id);
json_object_int_add(three_json, "neigh-ext-circuit-id",
threeway_adj->neighbor_circuit_id);
} else {
@@ -3155,8 +3160,7 @@ format_tlv_threeway_adj(const struct isis_threeway_adj *threeway_adj,
if (!threeway_adj->neighbor_set)
return;
- sbuf_push(buf, indent, " Neighbor System ID: %s\n",
- isis_format_id(threeway_adj->neighbor_id, 6));
+ sbuf_push(buf, indent, " Neighbor System ID: %s\n", sys_id);
sbuf_push(buf, indent, " Neighbor Extended Circuit ID: %u\n",
threeway_adj->neighbor_circuit_id);
}
@@ -3988,33 +3992,29 @@ static void format_tlv_purge_originator(struct isis_purge_originator *poi,
struct sbuf *buf,
struct json_object *json, int indent)
{
+ char sen_id[ISO_SYSID_STRLEN];
+ char gen_id[ISO_SYSID_STRLEN];
+
if (!poi)
return;
+ snprintfrr(gen_id, ISO_SYSID_STRLEN, "%pSY", poi->generator);
+ if (poi->sender_set)
+ snprintfrr(sen_id, ISO_SYSID_STRLEN, "%pSY", poi->sender);
+
if (json) {
struct json_object *purge_json;
purge_json = json_object_new_object();
json_object_object_add(json, "purge_originator", purge_json);
- json_object_string_add(
- purge_json, "id",
- isis_format_id(poi->generator, sizeof(poi->generator)));
- if (poi->sender_set) {
- json_object_string_add(
- purge_json, "rec-from",
- isis_format_id(poi->sender,
- sizeof(poi->sender)));
- }
+ json_object_string_add(purge_json, "id", gen_id);
+ if (poi->sender_set)
+ json_object_string_add(purge_json, "rec-from", sen_id);
} else {
sbuf_push(buf, indent, "Purge Originator Identification:\n");
- sbuf_push(
- buf, indent, " Generator: %s\n",
- isis_format_id(poi->generator, sizeof(poi->generator)));
- if (poi->sender_set) {
- sbuf_push(buf, indent, " Received-From: %s\n",
- isis_format_id(poi->sender,
- sizeof(poi->sender)));
- }
+ sbuf_push(buf, indent, " Generator: %s\n", gen_id);
+ if (poi->sender_set)
+ sbuf_push(buf, indent, " Received-From: %s\n", sen_id);
}
}
@@ -5271,14 +5271,14 @@ void isis_tlvs_add_area_addresses(struct isis_tlvs *tlvs,
struct list *addresses)
{
struct listnode *node;
- struct area_addr *area_addr;
+ struct iso_address *area_addr;
for (ALL_LIST_ELEMENTS_RO(addresses, node, area_addr)) {
struct isis_area_address *a =
XCALLOC(MTYPE_ISIS_TLV, sizeof(*a));
a->len = area_addr->addr_len;
- memcpy(a->addr, area_addr->area_addr, 20);
+ memcpy(a->addr, area_addr->area_addr, ISO_ADDR_SIZE);
append_item(&tlvs->area_addresses, (struct isis_item *)a);
}
}
@@ -5475,7 +5475,7 @@ bool isis_tlvs_area_addresses_match(struct isis_tlvs *tlvs,
for (struct isis_area_address *addr = addr_head; addr;
addr = addr->next) {
struct listnode *node;
- struct area_addr *a;
+ struct iso_address *a;
for (ALL_LIST_ELEMENTS_RO(addresses, node, a)) {
if (a->addr_len == addr->len
diff --git a/isisd/isis_tx_queue.c b/isisd/isis_tx_queue.c
index ad91059766..caf97f1174 100644
--- a/isisd/isis_tx_queue.c
+++ b/isisd/isis_tx_queue.c
@@ -32,7 +32,7 @@ struct isis_tx_queue_entry {
struct isis_lsp *lsp;
enum isis_tx_type type;
bool is_retry;
- struct thread *retry;
+ struct event *retry;
struct isis_tx_queue *queue;
};
@@ -79,15 +79,14 @@ static void tx_queue_element_free(void *element)
{
struct isis_tx_queue_entry *e = element;
- THREAD_OFF(e->retry);
+ EVENT_OFF(e->retry);
XFREE(MTYPE_TX_QUEUE_ENTRY, e);
}
void isis_tx_queue_free(struct isis_tx_queue *queue)
{
- hash_clean(queue->hash, tx_queue_element_free);
- hash_free(queue->hash);
+ hash_clean_and_free(&queue->hash, tx_queue_element_free);
XFREE(MTYPE_TX_QUEUE, queue);
}
@@ -101,12 +100,12 @@ static struct isis_tx_queue_entry *tx_queue_find(struct isis_tx_queue *queue,
return hash_lookup(queue->hash, &e);
}
-static void tx_queue_send_event(struct thread *thread)
+static void tx_queue_send_event(struct event *thread)
{
- struct isis_tx_queue_entry *e = THREAD_ARG(thread);
+ struct isis_tx_queue_entry *e = EVENT_ARG(thread);
struct isis_tx_queue *queue = e->queue;
- thread_add_timer(master, tx_queue_send_event, e, 5, &e->retry);
+ event_add_timer(master, tx_queue_send_event, e, 5, &e->retry);
if (e->is_retry)
queue->circuit->area->lsp_rxmt_count++;
@@ -127,12 +126,12 @@ void _isis_tx_queue_add(struct isis_tx_queue *queue,
return;
if (IS_DEBUG_TX_QUEUE) {
- zlog_debug("Add LSP %s to %s queue as %s LSP. (From %s %s:%d)",
- rawlspid_print(lsp->hdr.lsp_id),
- queue->circuit->interface->name,
- (type == TX_LSP_CIRCUIT_SCOPED) ?
- "circuit scoped" : "regular",
- func, file, line);
+ zlog_debug(
+ "Add LSP %pLS to %s queue as %s LSP. (From %s %s:%d)",
+ lsp->hdr.lsp_id, queue->circuit->interface->name,
+ (type == TX_LSP_CIRCUIT_SCOPED) ? "circuit scoped"
+ : "regular",
+ func, file, line);
}
struct isis_tx_queue_entry *e = tx_queue_find(queue, lsp);
@@ -148,8 +147,8 @@ void _isis_tx_queue_add(struct isis_tx_queue *queue,
e->type = type;
- THREAD_OFF(e->retry);
- thread_add_event(master, tx_queue_send_event, e, 0, &e->retry);
+ EVENT_OFF(e->retry);
+ event_add_event(master, tx_queue_send_event, e, 0, &e->retry);
e->is_retry = false;
}
@@ -165,13 +164,12 @@ void _isis_tx_queue_del(struct isis_tx_queue *queue, struct isis_lsp *lsp,
return;
if (IS_DEBUG_TX_QUEUE) {
- zlog_debug("Remove LSP %s from %s queue. (From %s %s:%d)",
- rawlspid_print(lsp->hdr.lsp_id),
- queue->circuit->interface->name,
+ zlog_debug("Remove LSP %pLS from %s queue. (From %s %s:%d)",
+ lsp->hdr.lsp_id, queue->circuit->interface->name,
func, file, line);
}
- THREAD_OFF(e->retry);
+ EVENT_OFF(e->retry);
hash_release(queue->hash, e);
XFREE(MTYPE_TX_QUEUE_ENTRY, e);
diff --git a/isisd/isis_zebra.c b/isisd/isis_zebra.c
index 7e85576c7a..8cd8f57c47 100644
--- a/isisd/isis_zebra.c
+++ b/isisd/isis_zebra.c
@@ -10,7 +10,7 @@
#include <zebra.h>
-#include "thread.h"
+#include "frrevent.h"
#include "command.h"
#include "memory.h"
#include "log.h"
@@ -828,7 +828,7 @@ static zclient_handler *const isis_handlers[] = {
[ZEBRA_CLIENT_CLOSE_NOTIFY] = isis_zebra_client_close_notify,
};
-void isis_zebra_init(struct thread_master *master, int instance)
+void isis_zebra_init(struct event_loop *master, int instance)
{
/* Initialize asynchronous zclient. */
zclient = zclient_new(master, &zclient_options_default, isis_handlers,
diff --git a/isisd/isis_zebra.h b/isisd/isis_zebra.h
index f34088f98e..359e39b59d 100644
--- a/isisd/isis_zebra.h
+++ b/isisd/isis_zebra.h
@@ -20,7 +20,7 @@ struct label_chunk {
};
#define CHUNK_SIZE 64
-void isis_zebra_init(struct thread_master *master, int instance);
+void isis_zebra_init(struct event_loop *master, int instance);
void isis_zebra_stop(void);
struct isis_route_info;
diff --git a/isisd/isisd.c b/isisd/isisd.c
index 586785b05f..fd6b91b42e 100644
--- a/isisd/isisd.c
+++ b/isisd/isisd.c
@@ -9,7 +9,7 @@
#include <zebra.h>
-#include "thread.h"
+#include "frrevent.h"
#include "vty.h"
#include "command.h"
#include "log.h"
@@ -88,7 +88,7 @@ static struct isis_master isis_master;
struct isis_master *im;
/* ISIS config processing thread */
-struct thread *t_isis_cfg;
+struct event *t_isis_cfg;
#ifndef FABRICD
DEFINE_HOOK(isis_hook_db_overload, (const struct isis_area *area), (area));
@@ -166,7 +166,7 @@ struct isis *isis_lookup_by_sysid(const uint8_t *sysid)
return NULL;
}
-void isis_master_init(struct thread_master *master)
+void isis_master_init(struct event_loop *master)
{
memset(&isis_master, 0, sizeof(isis_master));
im = &isis_master;
@@ -272,7 +272,7 @@ void isis_area_del_circuit(struct isis_area *area, struct isis_circuit *circuit)
static void delete_area_addr(void *arg)
{
- struct area_addr *addr = (struct area_addr *)arg;
+ struct iso_address *addr = (struct iso_address *)arg;
XFREE(MTYPE_ISIS_AREA_ADDR, addr);
}
@@ -325,7 +325,7 @@ struct isis_area *isis_area_create(const char *area_tag, const char *vrf_name)
area->area_addrs->del = delete_area_addr;
if (!CHECK_FLAG(im->options, F_ISIS_UNIT_TEST))
- thread_add_timer(master, lsp_tick, area, 1, &area->t_tick);
+ event_add_timer(master, lsp_tick, area, 1, &area->t_tick);
flags_initialize(&area->flags);
isis_sr_area_init(area);
@@ -519,11 +519,11 @@ void isis_area_destroy(struct isis_area *area)
spftree_area_del(area);
if (area->spf_timer[0])
- isis_spf_timer_free(THREAD_ARG(area->spf_timer[0]));
- THREAD_OFF(area->spf_timer[0]);
+ isis_spf_timer_free(EVENT_ARG(area->spf_timer[0]));
+ EVENT_OFF(area->spf_timer[0]);
if (area->spf_timer[1])
- isis_spf_timer_free(THREAD_ARG(area->spf_timer[1]));
- THREAD_OFF(area->spf_timer[1]);
+ isis_spf_timer_free(EVENT_ARG(area->spf_timer[1]));
+ EVENT_OFF(area->spf_timer[1]);
spf_backoff_free(area->spf_delay_ietf[0]);
spf_backoff_free(area->spf_delay_ietf[1]);
@@ -543,12 +543,12 @@ void isis_area_destroy(struct isis_area *area)
isis_lfa_tiebreakers_clear(area, ISIS_LEVEL1);
isis_lfa_tiebreakers_clear(area, ISIS_LEVEL2);
- THREAD_OFF(area->t_tick);
- THREAD_OFF(area->t_lsp_refresh[0]);
- THREAD_OFF(area->t_lsp_refresh[1]);
- THREAD_OFF(area->t_rlfa_rib_update);
+ EVENT_OFF(area->t_tick);
+ EVENT_OFF(area->t_lsp_refresh[0]);
+ EVENT_OFF(area->t_lsp_refresh[1]);
+ EVENT_OFF(area->t_rlfa_rib_update);
- thread_cancel_event(master, area);
+ event_cancel_event(master, area);
listnode_delete(area->isis->area_list, area);
@@ -809,8 +809,8 @@ static void area_set_mt_overload(struct isis_area *area, uint16_t mtid,
int area_net_title(struct vty *vty, const char *net_title)
{
VTY_DECLVAR_CONTEXT(isis_area, area);
- struct area_addr *addr;
- struct area_addr *addrp;
+ struct iso_address *addr;
+ struct iso_address *addrp;
struct listnode *node;
uint8_t buff[255];
@@ -823,14 +823,14 @@ int area_net_title(struct vty *vty, const char *net_title)
return CMD_ERR_NOTHING_TODO;
}
- addr = XMALLOC(MTYPE_ISIS_AREA_ADDR, sizeof(struct area_addr));
+ addr = XMALLOC(MTYPE_ISIS_AREA_ADDR, sizeof(struct iso_address));
addr->addr_len = dotformat2buff(buff, net_title);
memcpy(addr->area_addr, buff, addr->addr_len);
#ifdef EXTREME_DEBUG
zlog_debug("added area address %s for area %s (address length %d)",
net_title, area->area_tag, addr->addr_len);
#endif /* EXTREME_DEBUG */
- if (addr->addr_len < 8 || addr->addr_len > 20) {
+ if (addr->addr_len < ISO_ADDR_MIN || addr->addr_len > ISO_ADDR_SIZE) {
vty_out(vty,
"area address must be at least 8..20 octets long (%d)\n",
addr->addr_len);
@@ -852,8 +852,8 @@ int area_net_title(struct vty *vty, const char *net_title)
memcpy(area->isis->sysid, GETSYSID(addr), ISIS_SYS_ID_LEN);
area->isis->sysid_set = 1;
if (IS_DEBUG_EVENTS)
- zlog_debug("Router has SystemID %s",
- sysid_print(area->isis->sysid));
+ zlog_debug("Router has SystemID %pSY",
+ area->isis->sysid);
} else {
/*
* Check that the SystemID portions match
@@ -899,12 +899,12 @@ int area_net_title(struct vty *vty, const char *net_title)
int area_clear_net_title(struct vty *vty, const char *net_title)
{
VTY_DECLVAR_CONTEXT(isis_area, area);
- struct area_addr addr, *addrp = NULL;
+ struct iso_address addr, *addrp = NULL;
struct listnode *node;
uint8_t buff[255];
addr.addr_len = dotformat2buff(buff, net_title);
- if (addr.addr_len < 8 || addr.addr_len > 20) {
+ if (addr.addr_len < ISO_ADDR_MIN || addr.addr_len > ISO_ADDR_SIZE) {
vty_out(vty,
"Unsupported area address length %d, should be 8...20 \n",
addr.addr_len);
@@ -2250,7 +2250,7 @@ static void isis_spf_ietf_common(struct vty *vty, struct isis *isis)
vty_out(vty, " Level-%d:\n", level);
vty_out(vty, " SPF delay status: ");
if (area->spf_timer[level - 1]) {
- struct timeval remain = thread_timer_remain(
+ struct timeval remain = event_timer_remain(
area->spf_timer[level - 1]);
vty_out(vty, "Pending, due in %lld msec\n",
(long long)remain.tv_sec * 1000
@@ -2348,11 +2348,11 @@ static void common_isis_summary_json(struct json_object *json,
time_t cur;
char uptime[MONOTIME_STRLEN];
char stier[5];
+
json_object_string_add(json, "vrf", isis->name);
json_object_int_add(json, "process-id", isis->process_id);
if (isis->sysid_set)
- json_object_string_add(json, "system-id",
- sysid_print(isis->sysid));
+ json_object_string_addf(json, "system-id", "%pSY", isis->sysid);
cur = time(NULL);
cur -= isis->uptime;
@@ -2380,16 +2380,11 @@ static void common_isis_summary_json(struct json_object *json,
}
if (listcount(area->area_addrs) > 0) {
- struct area_addr *area_addr;
+ struct iso_address *area_addr;
for (ALL_LIST_ELEMENTS_RO(area->area_addrs, node2,
- area_addr)) {
- json_object_string_add(
- area_json, "net",
- isonet_print(area_addr->area_addr,
- area_addr->addr_len +
- ISIS_SYS_ID_LEN +
- 1));
- }
+ area_addr))
+ json_object_string_addf(area_json, "net",
+ "%pISl", area_addr);
}
tx_pdu_json = json_object_new_object();
@@ -2462,8 +2457,7 @@ static void common_isis_summary_vty(struct vty *vty, struct isis *isis)
vty_out(vty, "vrf : %s\n", isis->name);
vty_out(vty, "Process Id : %ld\n", isis->process_id);
if (isis->sysid_set)
- vty_out(vty, "System Id : %s\n",
- sysid_print(isis->sysid));
+ vty_out(vty, "System Id : %pSY\n", isis->sysid);
vty_out(vty, "Up time : ");
vty_out_timestr(vty, isis->uptime);
@@ -2485,15 +2479,10 @@ static void common_isis_summary_vty(struct vty *vty, struct isis *isis)
}
if (listcount(area->area_addrs) > 0) {
- struct area_addr *area_addr;
+ struct iso_address *area_addr;
for (ALL_LIST_ELEMENTS_RO(area->area_addrs, node2,
- area_addr)) {
- vty_out(vty, " Net: %s\n",
- isonet_print(area_addr->area_addr,
- area_addr->addr_len
- + ISIS_SYS_ID_LEN
- + 1));
- }
+ area_addr))
+ vty_out(vty, " Net: %pISl\n", area_addr);
}
vty_out(vty, " TX counters per PDU type:\n");
@@ -2503,6 +2492,9 @@ static void common_isis_summary_vty(struct vty *vty, struct isis *isis)
vty_out(vty, " RX counters per PDU type:\n");
pdu_counter_print(vty, " ", area->pdu_rx_counters);
+ vty_out(vty, " Drop counters per PDU type:\n");
+ pdu_counter_print(vty, " ", area->pdu_drop_counters);
+
vty_out(vty, " Advertise high metrics: %s\n",
area->advertise_high_metrics ? "Enabled" : "Disabled");
@@ -3119,14 +3111,14 @@ static void area_resign_level(struct isis_area *area, int level)
}
if (area->spf_timer[level - 1])
- isis_spf_timer_free(THREAD_ARG(area->spf_timer[level - 1]));
+ isis_spf_timer_free(EVENT_ARG(area->spf_timer[level - 1]));
- THREAD_OFF(area->spf_timer[level - 1]);
+ EVENT_OFF(area->spf_timer[level - 1]);
sched_debug(
"ISIS (%s): Resigned from L%d - canceling LSP regeneration timer.",
area->area_tag, level);
- THREAD_OFF(area->t_lsp_refresh[level - 1]);
+ EVENT_OFF(area->t_lsp_refresh[level - 1]);
area->lsp_regenerate_pending[level - 1] = 0;
}
@@ -3215,7 +3207,7 @@ void isis_area_overload_bit_set(struct isis_area *area, bool overload_bit)
} else {
/* Cancel overload on startup timer if it's running */
if (area->t_overload_on_startup_timer) {
- THREAD_OFF(area->t_overload_on_startup_timer);
+ EVENT_OFF(area->t_overload_on_startup_timer);
area->t_overload_on_startup_timer = NULL;
}
}
@@ -3494,15 +3486,10 @@ static int isis_config_write(struct vty *vty)
write++;
/* ISIS - Net */
if (listcount(area->area_addrs) > 0) {
- struct area_addr *area_addr;
+ struct iso_address *area_addr;
for (ALL_LIST_ELEMENTS_RO(area->area_addrs,
node2, area_addr)) {
- vty_out(vty, " net %s\n",
- isonet_print(
- area_addr->area_addr,
- area_addr->addr_len
- + ISIS_SYS_ID_LEN
- + 1));
+ vty_out(vty, " net %pISl\n", area_addr);
write++;
}
}
diff --git a/isisd/isisd.h b/isisd/isisd.h
index 37a36fd37a..12d9cd36c4 100644
--- a/isisd/isisd.h
+++ b/isisd/isisd.h
@@ -24,6 +24,7 @@
#include "isis_lfa.h"
#include "qobj.h"
#include "ldp_sync.h"
+#include "iso.h"
DECLARE_MGROUP(ISISD);
@@ -71,7 +72,7 @@ struct isis_master {
/* ISIS instance. */
struct list *isis;
/* ISIS thread master. */
- struct thread_master *master;
+ struct event_loop *master;
uint8_t options;
};
#define F_ISIS_UNIT_TEST 0x01
@@ -87,9 +88,9 @@ struct isis {
uint32_t router_id; /* Router ID from zebra */
struct list *area_list; /* list of IS-IS areas */
uint8_t max_area_addrs; /* maximumAreaAdresses */
- struct area_addr *man_area_addrs; /* manualAreaAddresses */
+ struct iso_address *man_area_addrs; /* manualAreaAddresses */
time_t uptime; /* when did we start */
- struct thread *t_dync_clean; /* dynamic hostname cache cleanup thread */
+ struct event *t_dync_clean; /* dynamic hostname cache cleanup thread */
uint32_t circuit_ids_used[8]; /* 256 bits to track circuit ids 1 through 255 */
int snmp_notifications;
struct list *dyn_cache;
@@ -99,7 +100,7 @@ struct isis {
extern struct isis_master *im;
-extern struct thread *t_isis_cfg;
+extern struct event *t_isis_cfg;
enum spf_tree_id {
SPFTREE_IPV4 = 0,
@@ -129,11 +130,11 @@ struct isis_area {
struct list *circuit_list; /* IS-IS circuits */
struct list *adjacency_list; /* IS-IS adjacencies */
struct flags flags;
- struct thread *t_tick; /* LSP walker */
- struct thread *t_lsp_refresh[ISIS_LEVELS];
- struct thread *t_overload_on_startup_timer;
+ struct event *t_tick; /* LSP walker */
+ struct event *t_lsp_refresh[ISIS_LEVELS];
+ struct event *t_overload_on_startup_timer;
struct timeval last_lsp_refresh_event[ISIS_LEVELS];
- struct thread *t_rlfa_rib_update;
+ struct event *t_rlfa_rib_update;
/* t_lsp_refresh is used in two ways:
* a) regular refresh of LSPs
* b) (possibly throttled) updates to LSPs
@@ -195,6 +196,8 @@ struct isis_area {
int ip_circuits;
/* logging adjacency changes? */
uint8_t log_adj_changes;
+ /* logging pdu drops? */
+ uint8_t log_pdu_drops;
/* multi topology settings */
struct list *mt_settings;
/* MPLS-TE settings */
@@ -226,12 +229,13 @@ struct isis_area {
struct spf_backoff *spf_delay_ietf[ISIS_LEVELS]; /*Structure with IETF
SPF algo
parameters*/
- struct thread *spf_timer[ISIS_LEVELS];
+ struct event *spf_timer[ISIS_LEVELS];
struct lsp_refresh_arg lsp_refresh_arg[ISIS_LEVELS];
pdu_counter_t pdu_tx_counters;
pdu_counter_t pdu_rx_counters;
+ pdu_counter_t pdu_drop_counters;
uint64_t lsp_rxmt_count;
/* Area counters */
@@ -252,7 +256,7 @@ DECLARE_MTYPE(ISIS_PLIST_NAME);
DECLARE_HOOK(isis_area_overload_bit_update, (struct isis_area * area), (area));
void isis_terminate(void);
-void isis_master_init(struct thread_master *master);
+void isis_master_init(struct event_loop *master);
void isis_vrf_link(struct isis *isis, struct vrf *vrf);
void isis_vrf_unlink(struct isis *isis, struct vrf *vrf);
struct isis *isis_lookup_by_vrfid(vrf_id_t vrf_id);
@@ -329,7 +333,7 @@ void config_end_lsp_generate(struct isis_area *area);
#define ISIS_SR "/frr-isisd:isis/instance/segment-routing"
/* Master of threads. */
-extern struct thread_master *master;
+extern struct event_loop *master;
extern unsigned long debug_adj_pkt;
extern unsigned long debug_snp_pkt;
diff --git a/ldpd/accept.c b/ldpd/accept.c
index 170c079b52..8e881e78ae 100644
--- a/ldpd/accept.c
+++ b/ldpd/accept.c
@@ -13,21 +13,21 @@
struct accept_ev {
LIST_ENTRY(accept_ev) entry;
- struct thread *ev;
- void (*accept_cb)(struct thread *);
+ struct event *ev;
+ void (*accept_cb)(struct event *);
void *arg;
int fd;
};
struct {
LIST_HEAD(, accept_ev) queue;
- struct thread *evt;
+ struct event *evt;
} accept_queue;
static void accept_arm(void);
static void accept_unarm(void);
-static void accept_cb(struct thread *);
-static void accept_timeout(struct thread *);
+static void accept_cb(struct event *);
+static void accept_timeout(struct event *);
void
accept_init(void)
@@ -35,7 +35,7 @@ accept_init(void)
LIST_INIT(&accept_queue.queue);
}
-int accept_add(int fd, void (*cb)(struct thread *), void *arg)
+int accept_add(int fd, void (*cb)(struct event *), void *arg)
{
struct accept_ev *av;
@@ -46,7 +46,7 @@ int accept_add(int fd, void (*cb)(struct thread *), void *arg)
av->arg = arg;
LIST_INSERT_HEAD(&accept_queue.queue, av, entry);
- thread_add_read(master, accept_cb, av, av->fd, &av->ev);
+ event_add_read(master, accept_cb, av, av->fd, &av->ev);
log_debug("%s: accepting on fd %d", __func__, fd);
@@ -61,7 +61,7 @@ accept_del(int fd)
LIST_FOREACH(av, &accept_queue.queue, entry)
if (av->fd == fd) {
log_debug("%s: %d removed from queue", __func__, fd);
- THREAD_OFF(av->ev);
+ EVENT_OFF(av->ev);
LIST_REMOVE(av, entry);
free(av);
return;
@@ -73,7 +73,7 @@ accept_pause(void)
{
log_debug(__func__);
accept_unarm();
- thread_add_timer(master, accept_timeout, NULL, 1, &accept_queue.evt);
+ event_add_timer(master, accept_timeout, NULL, 1, &accept_queue.evt);
}
void
@@ -81,7 +81,7 @@ accept_unpause(void)
{
if (accept_queue.evt != NULL) {
log_debug(__func__);
- THREAD_OFF(accept_queue.evt);
+ EVENT_OFF(accept_queue.evt);
accept_arm();
}
}
@@ -91,7 +91,7 @@ accept_arm(void)
{
struct accept_ev *av;
LIST_FOREACH(av, &accept_queue.queue, entry) {
- thread_add_read(master, accept_cb, av, av->fd, &av->ev);
+ event_add_read(master, accept_cb, av, av->fd, &av->ev);
}
}
@@ -100,17 +100,17 @@ accept_unarm(void)
{
struct accept_ev *av;
LIST_FOREACH(av, &accept_queue.queue, entry)
- THREAD_OFF(av->ev);
+ EVENT_OFF(av->ev);
}
-static void accept_cb(struct thread *thread)
+static void accept_cb(struct event *thread)
{
- struct accept_ev *av = THREAD_ARG(thread);
- thread_add_read(master, accept_cb, av, av->fd, &av->ev);
+ struct accept_ev *av = EVENT_ARG(thread);
+ event_add_read(master, accept_cb, av, av->fd, &av->ev);
av->accept_cb(thread);
}
-static void accept_timeout(struct thread *thread)
+static void accept_timeout(struct event *thread)
{
accept_queue.evt = NULL;
diff --git a/ldpd/adjacency.c b/ldpd/adjacency.c
index 42c3ef0535..0108af8044 100644
--- a/ldpd/adjacency.c
+++ b/ldpd/adjacency.c
@@ -15,12 +15,12 @@
#include "log.h"
static __inline int adj_compare(const struct adj *, const struct adj *);
-static void adj_itimer(struct thread *);
+static void adj_itimer(struct event *);
static __inline int tnbr_compare(const struct tnbr *, const struct tnbr *);
static void tnbr_del(struct ldpd_conf *, struct tnbr *);
static void tnbr_start(struct tnbr *);
static void tnbr_stop(struct tnbr *);
-static void tnbr_hello_timer(struct thread *);
+static void tnbr_hello_timer(struct event *);
static void tnbr_start_hello_timer(struct tnbr *);
static void tnbr_stop_hello_timer(struct tnbr *);
@@ -161,9 +161,9 @@ adj_get_af(const struct adj *adj)
/* adjacency timers */
/* ARGSUSED */
-static void adj_itimer(struct thread *thread)
+static void adj_itimer(struct event *thread)
{
- struct adj *adj = THREAD_ARG(thread);
+ struct adj *adj = EVENT_ARG(thread);
adj->inactivity_timer = NULL;
@@ -185,16 +185,16 @@ static void adj_itimer(struct thread *thread)
void
adj_start_itimer(struct adj *adj)
{
- THREAD_OFF(adj->inactivity_timer);
+ EVENT_OFF(adj->inactivity_timer);
adj->inactivity_timer = NULL;
- thread_add_timer(master, adj_itimer, adj, adj->holdtime,
- &adj->inactivity_timer);
+ event_add_timer(master, adj_itimer, adj, adj->holdtime,
+ &adj->inactivity_timer);
}
void
adj_stop_itimer(struct adj *adj)
{
- THREAD_OFF(adj->inactivity_timer);
+ EVENT_OFF(adj->inactivity_timer);
}
/* targeted neighbors */
@@ -331,9 +331,9 @@ tnbr_get_hello_interval(struct tnbr *tnbr)
/* target neighbors timers */
/* ARGSUSED */
-static void tnbr_hello_timer(struct thread *thread)
+static void tnbr_hello_timer(struct event *thread)
{
- struct tnbr *tnbr = THREAD_ARG(thread);
+ struct tnbr *tnbr = EVENT_ARG(thread);
tnbr->hello_timer = NULL;
send_hello(HELLO_TARGETED, NULL, tnbr);
@@ -343,16 +343,16 @@ static void tnbr_hello_timer(struct thread *thread)
static void
tnbr_start_hello_timer(struct tnbr *tnbr)
{
- THREAD_OFF(tnbr->hello_timer);
+ EVENT_OFF(tnbr->hello_timer);
tnbr->hello_timer = NULL;
- thread_add_timer(master, tnbr_hello_timer, tnbr, tnbr_get_hello_interval(tnbr),
- &tnbr->hello_timer);
+ event_add_timer(master, tnbr_hello_timer, tnbr,
+ tnbr_get_hello_interval(tnbr), &tnbr->hello_timer);
}
static void
tnbr_stop_hello_timer(struct tnbr *tnbr)
{
- THREAD_OFF(tnbr->hello_timer);
+ EVENT_OFF(tnbr->hello_timer);
}
struct ctl_adj *
@@ -375,7 +375,7 @@ adj_to_ctl(struct adj *adj)
}
actl.holdtime = adj->holdtime;
actl.holdtime_remaining =
- thread_timer_remain_second(adj->inactivity_timer);
+ event_timer_remain_second(adj->inactivity_timer);
actl.trans_addr = adj->trans_addr;
actl.ds_tlv = adj->ds_tlv;
diff --git a/ldpd/control.c b/ldpd/control.c
index b1260feb68..6bb5204d13 100644
--- a/ldpd/control.c
+++ b/ldpd/control.c
@@ -15,11 +15,11 @@
#define CONTROL_BACKLOG 5
-static void control_accept(struct thread *);
+static void control_accept(struct event *);
static struct ctl_conn *control_connbyfd(int);
static struct ctl_conn *control_connbypid(pid_t);
static void control_close(int);
-static void control_dispatch_imsg(struct thread *);
+static void control_dispatch_imsg(struct event *);
struct ctl_conns ctl_conns;
@@ -90,7 +90,7 @@ control_cleanup(char *path)
}
/* ARGSUSED */
-static void control_accept(struct thread *thread)
+static void control_accept(struct event *thread)
{
int connfd;
socklen_t len;
@@ -98,8 +98,8 @@ static void control_accept(struct thread *thread)
struct ctl_conn *c;
len = sizeof(s_un);
- if ((connfd = accept(THREAD_FD(thread), (struct sockaddr *)&s_un,
- &len)) == -1) {
+ if ((connfd = accept(EVENT_FD(thread), (struct sockaddr *)&s_un,
+ &len)) == -1) {
/*
* Pause accept if we are out of file descriptors, or
* libevent will haunt us here too.
@@ -122,8 +122,8 @@ static void control_accept(struct thread *thread)
imsg_init(&c->iev.ibuf, connfd);
c->iev.handler_read = control_dispatch_imsg;
c->iev.ev_read = NULL;
- thread_add_read(master, c->iev.handler_read, &c->iev, c->iev.ibuf.fd,
- &c->iev.ev_read);
+ event_add_read(master, c->iev.handler_read, &c->iev, c->iev.ibuf.fd,
+ &c->iev.ev_read);
c->iev.handler_write = ldp_write_handler;
c->iev.ev_write = NULL;
@@ -169,17 +169,17 @@ control_close(int fd)
msgbuf_clear(&c->iev.ibuf.w);
TAILQ_REMOVE(&ctl_conns, c, entry);
- THREAD_OFF(c->iev.ev_read);
- THREAD_OFF(c->iev.ev_write);
+ EVENT_OFF(c->iev.ev_read);
+ EVENT_OFF(c->iev.ev_write);
close(c->iev.ibuf.fd);
accept_unpause();
free(c);
}
/* ARGSUSED */
-static void control_dispatch_imsg(struct thread *thread)
+static void control_dispatch_imsg(struct event *thread)
{
- int fd = THREAD_FD(thread);
+ int fd = EVENT_FD(thread);
struct ctl_conn *c;
struct imsg imsg;
ssize_t n;
diff --git a/ldpd/interface.c b/ldpd/interface.c
index 5d1859298e..ad5d853b65 100644
--- a/ldpd/interface.c
+++ b/ldpd/interface.c
@@ -22,7 +22,7 @@ static struct if_addr *if_addr_lookup(struct if_addr_head *, struct kaddr *);
static int if_start(struct iface *, int);
static int if_reset(struct iface *, int);
static void if_update_af(struct iface_af *);
-static void if_hello_timer(struct thread *thread);
+static void if_hello_timer(struct event *thread);
static void if_start_hello_timer(struct iface_af *);
static void if_stop_hello_timer(struct iface_af *);
static int if_join_ipv4_group(struct iface *, struct in_addr *);
@@ -32,7 +32,7 @@ static int if_leave_ipv6_group(struct iface *, struct in6_addr *);
static int ldp_sync_fsm_init(struct iface *iface, int state);
static int ldp_sync_act_iface_start_sync(struct iface *iface);
-static void iface_wait_for_ldp_sync_timer(struct thread *thread);
+static void iface_wait_for_ldp_sync_timer(struct event *thread);
static void start_wait_for_ldp_sync_timer(struct iface *iface);
static void stop_wait_for_ldp_sync_timer(struct iface *iface);
static int ldp_sync_act_ldp_start_sync(struct iface *iface);
@@ -444,9 +444,9 @@ if_get_wait_for_sync_interval(void)
/* timers */
/* ARGSUSED */
-static void if_hello_timer(struct thread *thread)
+static void if_hello_timer(struct event *thread)
{
- struct iface_af *ia = THREAD_ARG(thread);
+ struct iface_af *ia = EVENT_ARG(thread);
ia->hello_timer = NULL;
send_hello(HELLO_LINK, ia, NULL);
@@ -456,15 +456,15 @@ static void if_hello_timer(struct thread *thread)
static void
if_start_hello_timer(struct iface_af *ia)
{
- THREAD_OFF(ia->hello_timer);
- thread_add_timer(master, if_hello_timer, ia, if_get_hello_interval(ia),
- &ia->hello_timer);
+ EVENT_OFF(ia->hello_timer);
+ event_add_timer(master, if_hello_timer, ia, if_get_hello_interval(ia),
+ &ia->hello_timer);
}
static void
if_stop_hello_timer(struct iface_af *ia)
{
- THREAD_OFF(ia->hello_timer);
+ EVENT_OFF(ia->hello_timer);
}
struct ctl_iface *
@@ -533,7 +533,7 @@ ldp_sync_to_ctl(struct iface *iface)
ictl.timer_running = iface->ldp_sync.wait_for_sync_timer ? true : false;
ictl.wait_time_remaining =
- thread_timer_remain_second(iface->ldp_sync.wait_for_sync_timer);
+ event_timer_remain_second(iface->ldp_sync.wait_for_sync_timer);
memset(&ictl.peer_ldp_id, 0, sizeof(ictl.peer_ldp_id));
@@ -720,9 +720,9 @@ ldp_sync_act_iface_start_sync(struct iface *iface)
return (0);
}
-static void iface_wait_for_ldp_sync_timer(struct thread *thread)
+static void iface_wait_for_ldp_sync_timer(struct event *thread)
{
- struct iface *iface = THREAD_ARG(thread);
+ struct iface *iface = EVENT_ARG(thread);
ldp_sync_fsm(iface, LDP_SYNC_EVT_LDP_SYNC_COMPLETE);
}
@@ -732,15 +732,15 @@ static void start_wait_for_ldp_sync_timer(struct iface *iface)
if (iface->ldp_sync.wait_for_sync_timer)
return;
- THREAD_OFF(iface->ldp_sync.wait_for_sync_timer);
- thread_add_timer(master, iface_wait_for_ldp_sync_timer, iface,
+ EVENT_OFF(iface->ldp_sync.wait_for_sync_timer);
+ event_add_timer(master, iface_wait_for_ldp_sync_timer, iface,
if_get_wait_for_sync_interval(),
&iface->ldp_sync.wait_for_sync_timer);
}
static void stop_wait_for_ldp_sync_timer(struct iface *iface)
{
- THREAD_OFF(iface->ldp_sync.wait_for_sync_timer);
+ EVENT_OFF(iface->ldp_sync.wait_for_sync_timer);
}
static int
diff --git a/ldpd/lde.c b/ldpd/lde.c
index 325b33d057..806bab6a21 100644
--- a/ldpd/lde.c
+++ b/ldpd/lde.c
@@ -30,8 +30,8 @@
#include "libfrr.h"
static void lde_shutdown(void);
-static void lde_dispatch_imsg(struct thread *thread);
-static void lde_dispatch_parent(struct thread *thread);
+static void lde_dispatch_imsg(struct event *thread);
+static void lde_dispatch_parent(struct event *thread);
static __inline int lde_nbr_compare(const struct lde_nbr *,
const struct lde_nbr *);
static struct lde_nbr *lde_nbr_new(uint32_t, struct lde_nbr *);
@@ -134,8 +134,8 @@ lde(void)
fatal(NULL);
imsg_init(&iev_main->ibuf, LDPD_FD_ASYNC);
iev_main->handler_read = lde_dispatch_parent;
- thread_add_read(master, iev_main->handler_read, iev_main, iev_main->ibuf.fd,
- &iev_main->ev_read);
+ event_add_read(master, iev_main->handler_read, iev_main,
+ iev_main->ibuf.fd, &iev_main->ev_read);
iev_main->handler_write = ldp_write_handler;
memset(&iev_main_sync_data, 0, sizeof(iev_main_sync_data));
@@ -145,9 +145,9 @@ lde(void)
/* create base configuration */
ldeconf = config_new_empty();
- struct thread thread;
- while (thread_fetch(master, &thread))
- thread_call(&thread);
+ struct event thread;
+ while (event_fetch(master, &thread))
+ event_call(&thread);
/* NOTREACHED */
return;
@@ -232,9 +232,9 @@ lde_imsg_compose_ldpe(int type, uint32_t peerid, pid_t pid, void *data,
}
/* ARGSUSED */
-static void lde_dispatch_imsg(struct thread *thread)
+static void lde_dispatch_imsg(struct event *thread)
{
- struct imsgev *iev = THREAD_ARG(thread);
+ struct imsgev *iev = EVENT_ARG(thread);
struct imsgbuf *ibuf = &iev->ibuf;
struct imsg imsg;
struct lde_nbr *ln;
@@ -395,14 +395,14 @@ static void lde_dispatch_imsg(struct thread *thread)
imsg_event_add(iev);
else {
/* this pipe is dead, so remove the event handlers and exit */
- THREAD_OFF(iev->ev_read);
- THREAD_OFF(iev->ev_write);
+ EVENT_OFF(iev->ev_read);
+ EVENT_OFF(iev->ev_write);
lde_shutdown();
}
}
/* ARGSUSED */
-static void lde_dispatch_parent(struct thread *thread)
+static void lde_dispatch_parent(struct event *thread)
{
static struct ldpd_conf *nconf;
struct iface *iface, *niface;
@@ -415,7 +415,7 @@ static void lde_dispatch_parent(struct thread *thread)
struct kif *kif;
struct kroute *kr;
int fd;
- struct imsgev *iev = THREAD_ARG(thread);
+ struct imsgev *iev = EVENT_ARG(thread);
struct imsgbuf *ibuf = &iev->ibuf;
ssize_t n;
int shut = 0;
@@ -523,8 +523,8 @@ static void lde_dispatch_parent(struct thread *thread)
fatal(NULL);
imsg_init(&iev_ldpe->ibuf, fd);
iev_ldpe->handler_read = lde_dispatch_imsg;
- thread_add_read(master, iev_ldpe->handler_read, iev_ldpe, iev_ldpe->ibuf.fd,
- &iev_ldpe->ev_read);
+ event_add_read(master, iev_ldpe->handler_read, iev_ldpe,
+ iev_ldpe->ibuf.fd, &iev_ldpe->ev_read);
iev_ldpe->handler_write = ldp_write_handler;
iev_ldpe->ev_write = NULL;
break;
@@ -673,8 +673,8 @@ static void lde_dispatch_parent(struct thread *thread)
imsg_event_add(iev);
else {
/* this pipe is dead, so remove the event handlers and exit */
- THREAD_OFF(iev->ev_read);
- THREAD_OFF(iev->ev_write);
+ EVENT_OFF(iev->ev_read);
+ EVENT_OFF(iev->ev_write);
lde_shutdown();
}
}
@@ -2123,7 +2123,7 @@ lde_address_list_free(struct lde_nbr *ln)
/*
* Event callback used to retry the label-manager sync zapi session.
*/
-static void zclient_sync_retry(struct thread *thread)
+static void zclient_sync_retry(struct event *thread)
{
zclient_sync_init();
}
@@ -2178,7 +2178,7 @@ retry:
zclient_sync = NULL;
/* Retry using a timer */
- thread_add_timer(master, zclient_sync_retry, NULL, 1, NULL);
+ event_add_timer(master, zclient_sync_retry, NULL, 1, NULL);
}
static void
diff --git a/ldpd/lde.h b/ldpd/lde.h
index 3a64f0d3b9..2688b6a86b 100644
--- a/ldpd/lde.h
+++ b/ldpd/lde.h
@@ -132,7 +132,7 @@ struct label_chunk {
extern struct ldpd_conf *ldeconf;
extern struct fec_tree ft;
extern struct nbr_tree lde_nbrs;
-extern struct thread *gc_timer;
+extern struct event *gc_timer;
/* lde.c */
void lde(void);
@@ -216,7 +216,7 @@ void lde_check_withdraw(struct map *, struct lde_nbr *);
void lde_check_withdraw_wcard(struct map *, struct lde_nbr *);
int lde_wildcard_apply(struct map *, struct fec *,
struct lde_map *);
-void lde_gc_timer(struct thread *thread);
+void lde_gc_timer(struct event *thread);
void lde_gc_start_timer(void);
void lde_gc_stop_timer(void);
diff --git a/ldpd/lde_lib.c b/ldpd/lde_lib.c
index d737e9f416..470580ff5e 100644
--- a/ldpd/lde_lib.c
+++ b/ldpd/lde_lib.c
@@ -28,7 +28,7 @@ static void fec_nh_del(struct fec_nh *);
RB_GENERATE(fec_tree, fec, entry, fec_compare)
struct fec_tree ft = RB_INITIALIZER(&ft);
-struct thread *gc_timer;
+struct event *gc_timer;
/* FEC tree functions */
void
@@ -1026,7 +1026,7 @@ lde_wildcard_apply(struct map *wcard, struct fec *fec, struct lde_map *me)
/* gabage collector timer: timer to remove dead entries from the LIB */
/* ARGSUSED */
-void lde_gc_timer(struct thread *thread)
+void lde_gc_timer(struct event *thread)
{
struct fec *fec, *safe;
struct fec_node *fn;
@@ -1057,13 +1057,12 @@ void lde_gc_timer(struct thread *thread)
void
lde_gc_start_timer(void)
{
- THREAD_OFF(gc_timer);
- thread_add_timer(master, lde_gc_timer, NULL, LDE_GC_INTERVAL,
- &gc_timer);
+ EVENT_OFF(gc_timer);
+ event_add_timer(master, lde_gc_timer, NULL, LDE_GC_INTERVAL, &gc_timer);
}
void
lde_gc_stop_timer(void)
{
- THREAD_OFF(gc_timer);
+ EVENT_OFF(gc_timer);
}
diff --git a/ldpd/ldp_snmp.c b/ldpd/ldp_snmp.c
index 9a26a8d17b..ed391ac600 100644
--- a/ldpd/ldp_snmp.c
+++ b/ldpd/ldp_snmp.c
@@ -1173,7 +1173,7 @@ static int ldp_snmp_nbr_state_change(struct nbr * nbr, int old_state)
return 0;
}
-static int ldp_snmp_init(struct thread_master *tm)
+static int ldp_snmp_init(struct event_loop *tm)
{
hook_register(agentx_enabled, ldp_snmp_agentx_enabled);
@@ -1182,7 +1182,7 @@ static int ldp_snmp_init(struct thread_master *tm)
return 0;
}
-static int ldp_snmp_register_mib(struct thread_master *tm)
+static int ldp_snmp_register_mib(struct event_loop *tm)
{
static int registered = 0;
diff --git a/ldpd/ldp_zebra.c b/ldpd/ldp_zebra.c
index 6f0f990e49..e3ace30582 100644
--- a/ldpd/ldp_zebra.c
+++ b/ldpd/ldp_zebra.c
@@ -89,7 +89,7 @@ pw2zpw(struct l2vpn_pw *pw, struct zapi_pw *zpw)
zpw->nexthop.ipv6 = pw->addr.v6;
zpw->local_label = NO_LABEL;
zpw->remote_label = NO_LABEL;
- if (pw->flags & F_PW_CWORD)
+ if (CHECK_FLAG(pw->flags, F_PW_CWORD))
zpw->flags = F_PSEUDOWIRE_CWORD;
zpw->data.ldp.lsr_id = pw->lsr_id;
zpw->data.ldp.pwid = pw->pwid;
@@ -162,10 +162,10 @@ ldp_zebra_opaque_msg_handler(ZAPI_CALLBACK_ARGS)
struct zapi_rlfa_igp igp;
struct zapi_rlfa_request rlfa;
- s = zclient->ibuf;
+ s = zclient->ibuf;
- if (zclient_opaque_decode(s, &info) != 0)
- return -1;
+ if(zclient_opaque_decode(s, &info) != 0)
+ return -1;
switch (info.type) {
case LDP_IGP_SYNC_IF_STATE_REQUEST:
@@ -239,7 +239,7 @@ ldp_zebra_send_mpls_labels(int cmd, struct kroute *kr)
* dropping them).
*/
if (kr->remote_label == NO_LABEL
- && !(ldpd_conf->flags & F_LDPD_ALLOW_BROKEN_LSP)
+ && !CHECK_FLAG(ldpd_conf->flags, F_LDPD_ALLOW_BROKEN_LSP)
&& cmd == ZEBRA_MPLS_LABELS_ADD)
return 0;
@@ -349,8 +349,7 @@ kif_redistribute(const char *ifname)
for (ALL_LIST_ELEMENTS_RO(ifp->connected, cnode, ifc)) {
ifc2kaddr(ifp, ifc, &ka);
- main_imsg_compose_ldpe(IMSG_NEWADDR, 0, &ka,
- sizeof(ka));
+ main_imsg_compose_ldpe(IMSG_NEWADDR, 0, &ka, sizeof(ka));
}
}
}
@@ -418,14 +417,12 @@ ldp_interface_status_change(struct interface *ifp)
if (if_is_operative(ifp)) {
for (ALL_LIST_ELEMENTS_RO(ifp->connected, node, ifc)) {
ifc2kaddr(ifp, ifc, &ka);
- main_imsg_compose_ldpe(IMSG_NEWADDR, 0, &ka,
- sizeof(ka));
+ main_imsg_compose_ldpe(IMSG_NEWADDR, 0, &ka, sizeof(ka));
}
} else {
for (ALL_LIST_ELEMENTS_RO(ifp->connected, node, ifc)) {
ifc2kaddr(ifp, ifc, &ka);
- main_imsg_compose_ldpe(IMSG_DELADDR, 0, &ka,
- sizeof(ka));
+ main_imsg_compose_ldpe(IMSG_DELADDR, 0, &ka, sizeof(ka));
}
}
@@ -530,7 +527,7 @@ ldp_zebra_read_route(ZAPI_CALLBACK_ARGS)
switch (api.type) {
case ZEBRA_ROUTE_CONNECT:
- kr.flags |= F_CONNECTED;
+ SET_FLAG(kr.flags, F_CONNECTED);
break;
case ZEBRA_ROUTE_BGP:
/* LDP should follow the IGP and ignore BGP routes */
@@ -580,7 +577,7 @@ ldp_zebra_read_route(ZAPI_CALLBACK_ARGS)
kr.ifindex = api_nh->ifindex;
break;
case NEXTHOP_TYPE_IFINDEX:
- if (!(kr.flags & F_CONNECTED))
+ if (!CHECK_FLAG(kr.flags, F_CONNECTED))
continue;
break;
case NEXTHOP_TYPE_BLACKHOLE:
@@ -593,8 +590,7 @@ ldp_zebra_read_route(ZAPI_CALLBACK_ARGS)
zebra_route_string(api.type));
if (add)
- main_imsg_compose_lde(IMSG_NETWORK_ADD, 0, &kr,
- sizeof(kr));
+ main_imsg_compose_lde(IMSG_NETWORK_ADD, 0, &kr, sizeof(kr));
}
main_imsg_compose_lde(IMSG_NETWORK_UPDATE, 0, &kr, sizeof(kr));
@@ -655,7 +651,7 @@ ldp_zebra_connected(struct zclient *zclient)
/* if MPLS was already enabled and we are re-connecting, register again
*/
- if (vty_conf->flags & F_LDPD_ENABLED)
+ if (CHECK_FLAG(vty_conf->flags, F_LDPD_ENABLED))
ldp_zebra_regdereg_zebra_info(true);
ldp_zebra_opaque_register();
@@ -670,11 +666,9 @@ ldp_zebra_filter_update(struct access_list *access)
if (access && access->name[0] != '\0') {
strlcpy(laccess.name, access->name, sizeof(laccess.name));
- debug_evt("%s ACL update filter name %s", __func__,
- access->name);
+ debug_evt("%s ACL update filter name %s", __func__, access->name);
- main_imsg_compose_both(IMSG_FILTER_UPDATE, &laccess,
- sizeof(laccess));
+ main_imsg_compose_both(IMSG_FILTER_UPDATE, &laccess, sizeof(laccess));
}
}
@@ -690,11 +684,9 @@ static zclient_handler *const ldp_handlers[] = {
[ZEBRA_OPAQUE_MESSAGE] = ldp_zebra_opaque_msg_handler,
};
-void
-ldp_zebra_init(struct thread_master *master)
+void ldp_zebra_init(struct event_loop *master)
{
- if_zapi_callbacks(ldp_ifp_create, ldp_ifp_up,
- ldp_ifp_down, ldp_ifp_destroy);
+ if_zapi_callbacks(ldp_ifp_create, ldp_ifp_up, ldp_ifp_down, ldp_ifp_destroy);
/* Set default values. */
zclient = zclient_new(master, &zclient_options_default, ldp_handlers,
diff --git a/ldpd/ldpd.c b/ldpd/ldpd.c
index 2026a7857c..3c616d4a8c 100644
--- a/ldpd/ldpd.c
+++ b/ldpd/ldpd.c
@@ -35,8 +35,8 @@
static void ldpd_shutdown(void);
static pid_t start_child(enum ldpd_process, char *, int, int);
-static void main_dispatch_ldpe(struct thread *thread);
-static void main_dispatch_lde(struct thread *thread);
+static void main_dispatch_ldpe(struct event *thread);
+static void main_dispatch_lde(struct event *thread);
static int main_imsg_send_ipc_sockets(struct imsgbuf *,
struct imsgbuf *);
static void main_imsg_send_net_sockets(int);
@@ -77,7 +77,7 @@ static pid_t lde_pid;
static struct frr_daemon_info ldpd_di;
-DEFINE_HOOK(ldp_register_mib, (struct thread_master * tm), (tm));
+DEFINE_HOOK(ldp_register_mib, (struct event_loop * tm), (tm));
static void ldp_load_module(const char *name)
{
@@ -104,7 +104,7 @@ enum ldpd_process ldpd_process;
#define LDP_VTY_PORT 2612
/* Master of threads. */
-struct thread_master *master;
+struct event_loop *master;
/* ldpd privileges */
static zebra_capabilities_t _caps_p [] =
@@ -208,7 +208,7 @@ FRR_DAEMON_INFO(ldpd, LDP,
.n_yang_modules = array_size(ldpd_yang_modules),
);
-static void ldp_config_fork_apply(struct thread *t)
+static void ldp_config_fork_apply(struct event *t)
{
/*
* So the frr_config_fork() function schedules
@@ -383,7 +383,7 @@ main(int argc, char *argv[])
frr_config_fork();
/* apply configuration */
- thread_add_event(master, ldp_config_fork_apply, NULL, 0, NULL);
+ event_add_event(master, ldp_config_fork_apply, NULL, 0, NULL);
/* setup pipes to children */
if ((iev_ldpe = calloc(1, sizeof(struct imsgev))) == NULL ||
@@ -394,26 +394,26 @@ main(int argc, char *argv[])
imsg_init(&iev_ldpe->ibuf, pipe_parent2ldpe[0]);
iev_ldpe->handler_read = main_dispatch_ldpe;
- thread_add_read(master, iev_ldpe->handler_read, iev_ldpe, iev_ldpe->ibuf.fd,
- &iev_ldpe->ev_read);
+ event_add_read(master, iev_ldpe->handler_read, iev_ldpe,
+ iev_ldpe->ibuf.fd, &iev_ldpe->ev_read);
iev_ldpe->handler_write = ldp_write_handler;
imsg_init(&iev_ldpe_sync->ibuf, pipe_parent2ldpe_sync[0]);
iev_ldpe_sync->handler_read = main_dispatch_ldpe;
- thread_add_read(master, iev_ldpe_sync->handler_read, iev_ldpe_sync, iev_ldpe_sync->ibuf.fd,
- &iev_ldpe_sync->ev_read);
+ event_add_read(master, iev_ldpe_sync->handler_read, iev_ldpe_sync,
+ iev_ldpe_sync->ibuf.fd, &iev_ldpe_sync->ev_read);
iev_ldpe_sync->handler_write = ldp_write_handler;
imsg_init(&iev_lde->ibuf, pipe_parent2lde[0]);
iev_lde->handler_read = main_dispatch_lde;
- thread_add_read(master, iev_lde->handler_read, iev_lde, iev_lde->ibuf.fd,
- &iev_lde->ev_read);
+ event_add_read(master, iev_lde->handler_read, iev_lde, iev_lde->ibuf.fd,
+ &iev_lde->ev_read);
iev_lde->handler_write = ldp_write_handler;
imsg_init(&iev_lde_sync->ibuf, pipe_parent2lde_sync[0]);
iev_lde_sync->handler_read = main_dispatch_lde;
- thread_add_read(master, iev_lde_sync->handler_read, iev_lde_sync, iev_lde_sync->ibuf.fd,
- &iev_lde_sync->ev_read);
+ event_add_read(master, iev_lde_sync->handler_read, iev_lde_sync,
+ iev_lde_sync->ibuf.fd, &iev_lde_sync->ev_read);
iev_lde_sync->handler_write = ldp_write_handler;
if (main_imsg_send_ipc_sockets(&iev_ldpe->ibuf, &iev_lde->ibuf))
@@ -557,9 +557,9 @@ start_child(enum ldpd_process p, char *argv0, int fd_async, int fd_sync)
/* imsg handling */
/* ARGSUSED */
-static void main_dispatch_ldpe(struct thread *thread)
+static void main_dispatch_ldpe(struct event *thread)
{
- struct imsgev *iev = THREAD_ARG(thread);
+ struct imsgev *iev = EVENT_ARG(thread);
struct imsgbuf *ibuf = &iev->ibuf;
struct imsg imsg;
int af;
@@ -613,8 +613,8 @@ static void main_dispatch_ldpe(struct thread *thread)
imsg_event_add(iev);
else {
/* this pipe is dead, so remove the event handlers and exit */
- THREAD_OFF(iev->ev_read);
- THREAD_OFF(iev->ev_write);
+ EVENT_OFF(iev->ev_read);
+ EVENT_OFF(iev->ev_write);
ldpe_pid = 0;
if (lde_pid == 0)
@@ -625,9 +625,9 @@ static void main_dispatch_ldpe(struct thread *thread)
}
/* ARGSUSED */
-static void main_dispatch_lde(struct thread *thread)
+static void main_dispatch_lde(struct event *thread)
{
- struct imsgev *iev = THREAD_ARG(thread);
+ struct imsgev *iev = EVENT_ARG(thread);
struct imsgbuf *ibuf = &iev->ibuf;
struct imsg imsg;
ssize_t n;
@@ -722,8 +722,8 @@ static void main_dispatch_lde(struct thread *thread)
imsg_event_add(iev);
else {
/* this pipe is dead, so remove the event handlers and exit */
- THREAD_OFF(iev->ev_read);
- THREAD_OFF(iev->ev_write);
+ EVENT_OFF(iev->ev_read);
+ EVENT_OFF(iev->ev_write);
lde_pid = 0;
if (ldpe_pid == 0)
ldpd_shutdown();
@@ -733,9 +733,9 @@ static void main_dispatch_lde(struct thread *thread)
}
/* ARGSUSED */
-void ldp_write_handler(struct thread *thread)
+void ldp_write_handler(struct event *thread)
{
- struct imsgev *iev = THREAD_ARG(thread);
+ struct imsgev *iev = EVENT_ARG(thread);
struct imsgbuf *ibuf = &iev->ibuf;
ssize_t n;
@@ -745,8 +745,8 @@ void ldp_write_handler(struct thread *thread)
fatal("msgbuf_write");
if (n == 0) {
/* this pipe is dead, so remove the event handlers */
- THREAD_OFF(iev->ev_read);
- THREAD_OFF(iev->ev_write);
+ EVENT_OFF(iev->ev_read);
+ EVENT_OFF(iev->ev_write);
return;
}
@@ -787,12 +787,12 @@ void
imsg_event_add(struct imsgev *iev)
{
if (iev->handler_read)
- thread_add_read(master, iev->handler_read, iev, iev->ibuf.fd,
- &iev->ev_read);
+ event_add_read(master, iev->handler_read, iev, iev->ibuf.fd,
+ &iev->ev_read);
if (iev->handler_write && iev->ibuf.w.queued)
- thread_add_write(master, iev->handler_write, iev,
- iev->ibuf.fd, &iev->ev_write);
+ event_add_write(master, iev->handler_write, iev, iev->ibuf.fd,
+ &iev->ev_write);
}
int
@@ -819,11 +819,11 @@ void
evbuf_event_add(struct evbuf *eb)
{
if (eb->wbuf.queued)
- thread_add_write(master, eb->handler, eb->arg, eb->wbuf.fd,
- &eb->ev);
+ event_add_write(master, eb->handler, eb->arg, eb->wbuf.fd,
+ &eb->ev);
}
-void evbuf_init(struct evbuf *eb, int fd, void (*handler)(struct thread *),
+void evbuf_init(struct evbuf *eb, int fd, void (*handler)(struct event *),
void *arg)
{
msgbuf_init(&eb->wbuf);
@@ -835,7 +835,7 @@ void evbuf_init(struct evbuf *eb, int fd, void (*handler)(struct thread *),
void
evbuf_clear(struct evbuf *eb)
{
- THREAD_OFF(eb->ev);
+ EVENT_OFF(eb->ev);
msgbuf_clear(&eb->wbuf);
eb->wbuf.fd = -1;
}
diff --git a/ldpd/ldpd.h b/ldpd/ldpd.h
index dc993e3d7c..1fec5beafc 100644
--- a/ldpd/ldpd.h
+++ b/ldpd/ldpd.h
@@ -14,7 +14,7 @@
#include "queue.h"
#include "openbsd-tree.h"
#include "imsg.h"
-#include "thread.h"
+#include "frrevent.h"
#include "qobj.h"
#include "prefix.h"
#include "filter.h"
@@ -51,17 +51,17 @@
struct evbuf {
struct msgbuf wbuf;
- struct thread *ev;
- void (*handler)(struct thread *);
+ struct event *ev;
+ void (*handler)(struct event *);
void *arg;
};
struct imsgev {
struct imsgbuf ibuf;
- void (*handler_write)(struct thread *);
- struct thread *ev_write;
- void (*handler_read)(struct thread *);
- struct thread *ev_read;
+ void (*handler_write)(struct event *);
+ struct event *ev_write;
+ void (*handler_read)(struct event *);
+ struct event *ev_read;
};
enum imsg_type {
@@ -329,14 +329,14 @@ struct iface_af {
int state;
struct ia_adj_head adj_tree;
time_t uptime;
- struct thread *hello_timer;
+ struct event *hello_timer;
uint16_t hello_holdtime;
uint16_t hello_interval;
};
struct iface_ldp_sync {
int state;
- struct thread *wait_for_sync_timer;
+ struct event *wait_for_sync_timer;
};
struct iface {
@@ -359,7 +359,7 @@ DECLARE_QOBJ_TYPE(iface);
/* source of targeted hellos */
struct tnbr {
RB_ENTRY(tnbr) entry;
- struct thread *hello_timer;
+ struct event *hello_timer;
struct adj *adj;
int af;
union ldpd_addr addr;
@@ -582,8 +582,8 @@ DECLARE_QOBJ_TYPE(ldpd_conf);
#define F_LDPD_ALLOW_BROKEN_LSP 0x0010
struct ldpd_af_global {
- struct thread *disc_ev;
- struct thread *edisc_ev;
+ struct event *disc_ev;
+ struct event *edisc_ev;
int ldp_disc_socket;
int ldp_edisc_socket;
int ldp_session_socket;
@@ -781,7 +781,7 @@ void sa2addr(struct sockaddr *, int *, union ldpd_addr *,
socklen_t sockaddr_len(struct sockaddr *);
/* ldpd.c */
-void ldp_write_handler(struct thread *thread);
+void ldp_write_handler(struct event *thread);
void main_imsg_compose_ldpe(int, pid_t, void *, uint16_t);
void main_imsg_compose_lde(int, pid_t, void *, uint16_t);
int main_imsg_compose_both(enum imsg_type, void *,
@@ -791,7 +791,7 @@ int imsg_compose_event(struct imsgev *, uint16_t, uint32_t,
pid_t, int, void *, uint16_t);
void evbuf_enqueue(struct evbuf *, struct ibuf *);
void evbuf_event_add(struct evbuf *);
-void evbuf_init(struct evbuf *, int, void (*)(struct thread *), void *);
+void evbuf_init(struct evbuf *, int, void (*)(struct event *), void *);
void evbuf_clear(struct evbuf *);
int ldp_acl_request(struct imsgev *, char *, int,
union ldpd_addr *, uint8_t);
@@ -883,11 +883,11 @@ const char *pw_type_name(uint16_t);
const char *pw_error_code(uint8_t);
/* quagga */
-extern struct thread_master *master;
+extern struct event_loop *master;
extern char ctl_sock_path[MAXPATHLEN];
/* ldp_zebra.c */
-void ldp_zebra_init(struct thread_master *);
+void ldp_zebra_init(struct event_loop *m);
void ldp_zebra_destroy(void);
int ldp_sync_zebra_send_state_update(struct ldp_igp_sync_if_state *);
int ldp_zebra_send_rlfa_labels(struct zapi_rlfa_response *
@@ -904,7 +904,7 @@ void ldp_zebra_regdereg_zebra_info(bool want_register);
(__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_INTFACELOCAL))
#endif
-DECLARE_HOOK(ldp_register_mib, (struct thread_master * tm), (tm));
+DECLARE_HOOK(ldp_register_mib, (struct event_loop * tm), (tm));
extern void ldp_agentx_enabled(void);
diff --git a/ldpd/ldpe.c b/ldpd/ldpe.c
index f53dc72540..d3193b16d7 100644
--- a/ldpd/ldpe.c
+++ b/ldpd/ldpe.c
@@ -25,10 +25,10 @@
#include "libfrr.h"
static void ldpe_shutdown(void);
-static void ldpe_dispatch_main(struct thread *thread);
-static void ldpe_dispatch_lde(struct thread *thread);
+static void ldpe_dispatch_main(struct event *thread);
+static void ldpe_dispatch_lde(struct event *thread);
#ifdef __OpenBSD__
-static void ldpe_dispatch_pfkey(struct thread *thread);
+static void ldpe_dispatch_pfkey(struct event *thread);
#endif
static void ldpe_setup_sockets(int, int, int, int);
static void ldpe_close_sockets(int);
@@ -44,7 +44,7 @@ static struct imsgev iev_main_data;
static struct imsgev *iev_main, *iev_main_sync;
static struct imsgev *iev_lde;
#ifdef __OpenBSD__
-static struct thread *pfkey_ev;
+static struct event *pfkey_ev;
#endif
/* ldpe privileges */
@@ -111,8 +111,8 @@ ldpe(void)
fatal(NULL);
imsg_init(&iev_main->ibuf, LDPD_FD_ASYNC);
iev_main->handler_read = ldpe_dispatch_main;
- thread_add_read(master, iev_main->handler_read, iev_main, iev_main->ibuf.fd,
- &iev_main->ev_read);
+ event_add_read(master, iev_main->handler_read, iev_main,
+ iev_main->ibuf.fd, &iev_main->ev_read);
iev_main->handler_write = ldp_write_handler;
memset(&iev_main_data, 0, sizeof(iev_main_data));
@@ -122,9 +122,9 @@ ldpe(void)
/* create base configuration */
leconf = config_new_empty();
- struct thread thread;
- while (thread_fetch(master, &thread))
- thread_call(&thread);
+ struct event thread;
+ while (event_fetch(master, &thread))
+ event_call(&thread);
/* NOTREACHED */
return;
@@ -137,8 +137,8 @@ ldpe_init(struct ldpd_init *init)
/* This socket must be open before dropping privileges. */
global.pfkeysock = pfkey_init();
if (sysdep.no_pfkey == 0) {
- thread_add_read(master, ldpe_dispatch_pfkey, NULL, global.pfkeysock,
- &pfkey_ev);
+ event_add_read(master, ldpe_dispatch_pfkey, NULL,
+ global.pfkeysock, &pfkey_ev);
}
#endif
@@ -200,7 +200,7 @@ ldpe_shutdown(void)
#ifdef __OpenBSD__
if (sysdep.no_pfkey == 0) {
- THREAD_OFF(pfkey_ev);
+ EVENT_OFF(pfkey_ev);
close(global.pfkeysock);
}
#endif
@@ -262,7 +262,7 @@ ldpe_imsg_compose_lde(int type, uint32_t peerid, pid_t pid, void *data,
}
/* ARGSUSED */
-static void ldpe_dispatch_main(struct thread *thread)
+static void ldpe_dispatch_main(struct event *thread)
{
static struct ldpd_conf *nconf;
struct iface *niface;
@@ -273,7 +273,7 @@ static void ldpe_dispatch_main(struct thread *thread)
struct l2vpn_pw *pw, *npw;
struct imsg imsg;
int fd;
- struct imsgev *iev = THREAD_ARG(thread);
+ struct imsgev *iev = EVENT_ARG(thread);
struct imsgbuf *ibuf = &iev->ibuf;
struct iface *iface = NULL;
struct kif *kif;
@@ -363,8 +363,8 @@ static void ldpe_dispatch_main(struct thread *thread)
fatal(NULL);
imsg_init(&iev_lde->ibuf, fd);
iev_lde->handler_read = ldpe_dispatch_lde;
- thread_add_read(master, iev_lde->handler_read, iev_lde, iev_lde->ibuf.fd,
- &iev_lde->ev_read);
+ event_add_read(master, iev_lde->handler_read, iev_lde,
+ iev_lde->ibuf.fd, &iev_lde->ev_read);
iev_lde->handler_write = ldp_write_handler;
iev_lde->ev_write = NULL;
break;
@@ -615,16 +615,16 @@ static void ldpe_dispatch_main(struct thread *thread)
imsg_event_add(iev);
else {
/* this pipe is dead, so remove the event handlers and exit */
- THREAD_OFF(iev->ev_read);
- THREAD_OFF(iev->ev_write);
+ EVENT_OFF(iev->ev_read);
+ EVENT_OFF(iev->ev_write);
ldpe_shutdown();
}
}
/* ARGSUSED */
-static void ldpe_dispatch_lde(struct thread *thread)
+static void ldpe_dispatch_lde(struct event *thread)
{
- struct imsgev *iev = THREAD_ARG(thread);
+ struct imsgev *iev = EVENT_ARG(thread);
struct imsgbuf *ibuf = &iev->ibuf;
struct imsg imsg;
struct map *map;
@@ -751,20 +751,20 @@ static void ldpe_dispatch_lde(struct thread *thread)
imsg_event_add(iev);
else {
/* this pipe is dead, so remove the event handlers and exit */
- THREAD_OFF(iev->ev_read);
- THREAD_OFF(iev->ev_write);
+ EVENT_OFF(iev->ev_read);
+ EVENT_OFF(iev->ev_write);
ldpe_shutdown();
}
}
#ifdef __OpenBSD__
/* ARGSUSED */
-static void ldpe_dispatch_pfkey(struct thread *thread)
+static void ldpe_dispatch_pfkey(struct event *thread)
{
- int fd = THREAD_FD(thread);
+ int fd = EVENT_FD(thread);
- thread_add_read(master, ldpe_dispatch_pfkey, NULL, global.pfkeysock,
- &pfkey_ev);
+ event_add_read(master, ldpe_dispatch_pfkey, NULL, global.pfkeysock,
+ &pfkey_ev);
if (pfkey_read(fd, NULL) == -1)
fatal("pfkey_read failed, exiting...");
@@ -781,13 +781,13 @@ ldpe_setup_sockets(int af, int disc_socket, int edisc_socket,
/* discovery socket */
af_global->ldp_disc_socket = disc_socket;
- thread_add_read(master, disc_recv_packet, &af_global->disc_ev, af_global->ldp_disc_socket,
- &af_global->disc_ev);
+ event_add_read(master, disc_recv_packet, &af_global->disc_ev,
+ af_global->ldp_disc_socket, &af_global->disc_ev);
/* extended discovery socket */
af_global->ldp_edisc_socket = edisc_socket;
- thread_add_read(master, disc_recv_packet, &af_global->edisc_ev, af_global->ldp_edisc_socket,
- &af_global->edisc_ev);
+ event_add_read(master, disc_recv_packet, &af_global->edisc_ev,
+ af_global->ldp_edisc_socket, &af_global->edisc_ev);
/* session socket */
af_global->ldp_session_socket = session_socket;
@@ -802,14 +802,14 @@ ldpe_close_sockets(int af)
af_global = ldp_af_global_get(&global, af);
/* discovery socket */
- THREAD_OFF(af_global->disc_ev);
+ EVENT_OFF(af_global->disc_ev);
if (af_global->ldp_disc_socket != -1) {
close(af_global->ldp_disc_socket);
af_global->ldp_disc_socket = -1;
}
/* extended discovery socket */
- THREAD_OFF(af_global->edisc_ev);
+ EVENT_OFF(af_global->edisc_ev);
if (af_global->ldp_edisc_socket != -1) {
close(af_global->ldp_edisc_socket);
af_global->ldp_edisc_socket = -1;
diff --git a/ldpd/ldpe.h b/ldpd/ldpe.h
index e799538b62..f310ba5dd2 100644
--- a/ldpd/ldpe.h
+++ b/ldpd/ldpe.h
@@ -37,7 +37,7 @@ struct adj {
struct nbr *nbr;
int ds_tlv;
struct hello_source source;
- struct thread *inactivity_timer;
+ struct event *inactivity_timer;
uint16_t holdtime;
union ldpd_addr trans_addr;
};
@@ -50,7 +50,7 @@ struct tcp_conn {
int fd;
struct ibuf_read *rbuf;
struct evbuf wbuf;
- struct thread *rev;
+ struct event *rev;
in_port_t lport;
in_port_t rport;
};
@@ -59,11 +59,11 @@ struct nbr {
RB_ENTRY(nbr) id_tree, addr_tree, pid_tree;
struct tcp_conn *tcp;
struct nbr_adj_head adj_tree; /* adjacencies */
- struct thread *ev_connect;
- struct thread *keepalive_timer;
- struct thread *keepalive_timeout;
- struct thread *init_timeout;
- struct thread *initdelay_timer;
+ struct event *ev_connect;
+ struct event *keepalive_timer;
+ struct event *keepalive_timeout;
+ struct event *init_timeout;
+ struct event *initdelay_timer;
struct mapping_head mapping_list;
struct mapping_head withdraw_list;
@@ -115,7 +115,7 @@ struct pending_conn {
int fd;
int af;
union ldpd_addr addr;
- struct thread *ev_timeout;
+ struct event *ev_timeout;
};
#define PENDING_CONN_TIMEOUT 5
@@ -137,7 +137,7 @@ extern struct nbr_pid_head nbrs_by_pid;
/* accept.c */
void accept_init(void);
-int accept_add(int, void (*)(struct thread *), void *);
+int accept_add(int, void (*)(struct event *), void *);
void accept_del(int);
void accept_pause(void);
void accept_unpause(void);
@@ -281,8 +281,8 @@ int gen_ldp_hdr(struct ibuf *, uint16_t);
int gen_msg_hdr(struct ibuf *, uint16_t, uint16_t);
int send_packet(int, int, union ldpd_addr *,
struct iface_af *, void *, size_t);
-void disc_recv_packet(struct thread *thread);
-void session_accept(struct thread *thread);
+void disc_recv_packet(struct event *thread);
+void session_accept(struct event *thread);
void session_accept_nbr(struct nbr *, int);
void session_shutdown(struct nbr *, uint32_t, uint32_t,
uint32_t);
diff --git a/ldpd/neighbor.c b/ldpd/neighbor.c
index 831f2a6aba..6f9177fe8b 100644
--- a/ldpd/neighbor.c
+++ b/ldpd/neighbor.c
@@ -24,13 +24,13 @@ static __inline int nbr_addr_compare(const struct nbr *,
static __inline int nbr_pid_compare(const struct nbr *,
const struct nbr *);
static void nbr_update_peerid(struct nbr *);
-static void nbr_ktimer(struct thread *thread);
+static void nbr_ktimer(struct event *thread);
static void nbr_start_ktimer(struct nbr *);
-static void nbr_ktimeout(struct thread *thread);
+static void nbr_ktimeout(struct event *thread);
static void nbr_start_ktimeout(struct nbr *);
-static void nbr_itimeout(struct thread *thread);
+static void nbr_itimeout(struct event *thread);
static void nbr_start_itimeout(struct nbr *);
-static void nbr_idtimer(struct thread *thread);
+static void nbr_idtimer(struct event *thread);
static int nbr_act_session_operational(struct nbr *);
static void nbr_send_labelmappings(struct nbr *);
static __inline int nbr_params_compare(const struct nbr_params *,
@@ -296,7 +296,7 @@ nbr_del(struct nbr *nbr)
nbr->auth.method = AUTH_NONE;
if (nbr_pending_connect(nbr))
- THREAD_OFF(nbr->ev_connect);
+ EVENT_OFF(nbr->ev_connect);
nbr_stop_ktimer(nbr);
nbr_stop_ktimeout(nbr);
nbr_stop_itimeout(nbr);
@@ -407,9 +407,9 @@ nbr_session_active_role(struct nbr *nbr)
/* Keepalive timer: timer to send keepalive message to neighbors */
-static void nbr_ktimer(struct thread *thread)
+static void nbr_ktimer(struct event *thread)
{
- struct nbr *nbr = THREAD_ARG(thread);
+ struct nbr *nbr = EVENT_ARG(thread);
nbr->keepalive_timer = NULL;
send_keepalive(nbr);
@@ -423,22 +423,22 @@ nbr_start_ktimer(struct nbr *nbr)
/* send three keepalives per period */
secs = nbr->keepalive / KEEPALIVE_PER_PERIOD;
- THREAD_OFF(nbr->keepalive_timer);
+ EVENT_OFF(nbr->keepalive_timer);
nbr->keepalive_timer = NULL;
- thread_add_timer(master, nbr_ktimer, nbr, secs, &nbr->keepalive_timer);
+ event_add_timer(master, nbr_ktimer, nbr, secs, &nbr->keepalive_timer);
}
void
nbr_stop_ktimer(struct nbr *nbr)
{
- THREAD_OFF(nbr->keepalive_timer);
+ EVENT_OFF(nbr->keepalive_timer);
}
/* Keepalive timeout: if the nbr hasn't sent keepalive */
-static void nbr_ktimeout(struct thread *thread)
+static void nbr_ktimeout(struct event *thread)
{
- struct nbr *nbr = THREAD_ARG(thread);
+ struct nbr *nbr = EVENT_ARG(thread);
nbr->keepalive_timeout = NULL;
@@ -450,23 +450,23 @@ static void nbr_ktimeout(struct thread *thread)
static void
nbr_start_ktimeout(struct nbr *nbr)
{
- THREAD_OFF(nbr->keepalive_timeout);
+ EVENT_OFF(nbr->keepalive_timeout);
nbr->keepalive_timeout = NULL;
- thread_add_timer(master, nbr_ktimeout, nbr, nbr->keepalive,
- &nbr->keepalive_timeout);
+ event_add_timer(master, nbr_ktimeout, nbr, nbr->keepalive,
+ &nbr->keepalive_timeout);
}
void
nbr_stop_ktimeout(struct nbr *nbr)
{
- THREAD_OFF(nbr->keepalive_timeout);
+ EVENT_OFF(nbr->keepalive_timeout);
}
/* Session initialization timeout: if nbr got stuck in the initialization FSM */
-static void nbr_itimeout(struct thread *thread)
+static void nbr_itimeout(struct event *thread)
{
- struct nbr *nbr = THREAD_ARG(thread);
+ struct nbr *nbr = EVENT_ARG(thread);
log_debug("%s: lsr-id %pI4", __func__, &nbr->id);
@@ -479,22 +479,22 @@ nbr_start_itimeout(struct nbr *nbr)
int secs;
secs = INIT_FSM_TIMEOUT;
- THREAD_OFF(nbr->init_timeout);
+ EVENT_OFF(nbr->init_timeout);
nbr->init_timeout = NULL;
- thread_add_timer(master, nbr_itimeout, nbr, secs, &nbr->init_timeout);
+ event_add_timer(master, nbr_itimeout, nbr, secs, &nbr->init_timeout);
}
void
nbr_stop_itimeout(struct nbr *nbr)
{
- THREAD_OFF(nbr->init_timeout);
+ EVENT_OFF(nbr->init_timeout);
}
/* Init delay timer: timer to retry to iniziatize session */
-static void nbr_idtimer(struct thread *thread)
+static void nbr_idtimer(struct event *thread)
{
- struct nbr *nbr = THREAD_ARG(thread);
+ struct nbr *nbr = EVENT_ARG(thread);
nbr->initdelay_timer = NULL;
@@ -525,16 +525,15 @@ nbr_start_idtimer(struct nbr *nbr)
break;
}
- THREAD_OFF(nbr->initdelay_timer);
+ EVENT_OFF(nbr->initdelay_timer);
nbr->initdelay_timer = NULL;
- thread_add_timer(master, nbr_idtimer, nbr, secs,
- &nbr->initdelay_timer);
+ event_add_timer(master, nbr_idtimer, nbr, secs, &nbr->initdelay_timer);
}
void
nbr_stop_idtimer(struct nbr *nbr)
{
- THREAD_OFF(nbr->initdelay_timer);
+ EVENT_OFF(nbr->initdelay_timer);
}
int
@@ -549,9 +548,9 @@ nbr_pending_connect(struct nbr *nbr)
return (nbr->ev_connect != NULL);
}
-static void nbr_connect_cb(struct thread *thread)
+static void nbr_connect_cb(struct event *thread)
{
- struct nbr *nbr = THREAD_ARG(thread);
+ struct nbr *nbr = EVENT_ARG(thread);
int error;
socklen_t len;
@@ -650,8 +649,8 @@ nbr_establish_connection(struct nbr *nbr)
if (connect(nbr->fd, &remote_su.sa, sockaddr_len(&remote_su.sa))
== -1) {
if (errno == EINPROGRESS) {
- thread_add_write(master, nbr_connect_cb, nbr, nbr->fd,
- &nbr->ev_connect);
+ event_add_write(master, nbr_connect_cb, nbr, nbr->fd,
+ &nbr->ev_connect);
return (0);
}
log_warn("%s: error while connecting to %s", __func__,
@@ -836,7 +835,7 @@ nbr_to_ctl(struct nbr *nbr)
nctl.flags = nbr->flags;
nctl.max_pdu_len = nbr->max_pdu_len;
nctl.hold_time_remaining =
- thread_timer_remain_second(nbr->keepalive_timer);
+ event_timer_remain_second(nbr->keepalive_timer);
gettimeofday(&now, NULL);
if (nbr->state == NBR_STA_OPER) {
diff --git a/ldpd/packet.c b/ldpd/packet.c
index a253ef4660..71eeb1adb6 100644
--- a/ldpd/packet.c
+++ b/ldpd/packet.c
@@ -17,12 +17,12 @@
static struct iface *disc_find_iface(unsigned int, int,
union ldpd_addr *);
-static void session_read(struct thread *thread);
-static void session_write(struct thread *thread);
+static void session_read(struct event *thread);
+static void session_write(struct event *thread);
static ssize_t session_get_pdu(struct ibuf_read *, char **);
static void tcp_close(struct tcp_conn *);
static struct pending_conn *pending_conn_new(int, int, union ldpd_addr *);
-static void pending_conn_timeout(struct thread *thread);
+static void pending_conn_timeout(struct event *thread);
int
gen_ldp_hdr(struct ibuf *buf, uint16_t size)
@@ -95,10 +95,10 @@ send_packet(int fd, int af, union ldpd_addr *dst, struct iface_af *ia,
}
/* Discovery functions */
-void disc_recv_packet(struct thread *thread)
+void disc_recv_packet(struct event *thread)
{
- int fd = THREAD_FD(thread);
- struct thread **threadp = THREAD_ARG(thread);
+ int fd = EVENT_FD(thread);
+ struct event **threadp = EVENT_ARG(thread);
union {
struct cmsghdr hdr;
@@ -129,7 +129,7 @@ void disc_recv_packet(struct thread *thread)
struct in_addr lsr_id;
/* reschedule read */
- thread_add_read(master, disc_recv_packet, threadp, fd, threadp);
+ event_add_read(master, disc_recv_packet, threadp, fd, threadp);
/* setup buffer */
memset(&m, 0, sizeof(m));
@@ -290,9 +290,9 @@ disc_find_iface(unsigned int ifindex, int af, union ldpd_addr *src)
return (iface);
}
-void session_accept(struct thread *thread)
+void session_accept(struct event *thread)
{
- int fd = THREAD_FD(thread);
+ int fd = EVENT_FD(thread);
struct sockaddr_storage src;
socklen_t len = sizeof(src);
int newfd;
@@ -394,10 +394,10 @@ session_accept_nbr(struct nbr *nbr, int fd)
nbr_fsm(nbr, NBR_EVT_MATCH_ADJ);
}
-static void session_read(struct thread *thread)
+static void session_read(struct event *thread)
{
- int fd = THREAD_FD(thread);
- struct nbr *nbr = THREAD_ARG(thread);
+ int fd = EVENT_FD(thread);
+ struct nbr *nbr = EVENT_ARG(thread);
struct tcp_conn *tcp = nbr->tcp;
struct ldp_hdr *ldp_hdr;
struct ldp_msg *msg;
@@ -406,7 +406,7 @@ static void session_read(struct thread *thread)
uint16_t pdu_len, msg_len, msg_size, max_pdu_len;
int ret;
- thread_add_read(master, session_read, nbr, fd, &tcp->rev);
+ event_add_read(master, session_read, nbr, fd, &tcp->rev);
if ((n = read(fd, tcp->rbuf->buf + tcp->rbuf->wpos,
sizeof(tcp->rbuf->buf) - tcp->rbuf->wpos)) == -1) {
@@ -610,9 +610,9 @@ static void session_read(struct thread *thread)
free(buf);
}
-static void session_write(struct thread *thread)
+static void session_write(struct event *thread)
{
- struct tcp_conn *tcp = THREAD_ARG(thread);
+ struct tcp_conn *tcp = EVENT_ARG(thread);
struct nbr *nbr = tcp->nbr;
tcp->wbuf.ev = NULL;
@@ -640,7 +640,7 @@ session_shutdown(struct nbr *nbr, uint32_t status, uint32_t msg_id,
switch (nbr->state) {
case NBR_STA_PRESENT:
if (nbr_pending_connect(nbr))
- THREAD_OFF(nbr->ev_connect);
+ EVENT_OFF(nbr->ev_connect);
break;
case NBR_STA_INITIAL:
case NBR_STA_OPENREC:
@@ -721,7 +721,7 @@ tcp_new(int fd, struct nbr *nbr)
if ((tcp->rbuf = calloc(1, sizeof(struct ibuf_read))) == NULL)
fatal(__func__);
- thread_add_read(master, session_read, nbr, tcp->fd, &tcp->rev);
+ event_add_read(master, session_read, nbr, tcp->fd, &tcp->rev);
tcp->nbr = nbr;
}
@@ -745,7 +745,7 @@ tcp_close(struct tcp_conn *tcp)
evbuf_clear(&tcp->wbuf);
if (tcp->nbr) {
- THREAD_OFF(tcp->rev);
+ EVENT_OFF(tcp->rev);
free(tcp->rbuf);
tcp->nbr->tcp = NULL;
}
@@ -768,8 +768,8 @@ pending_conn_new(int fd, int af, union ldpd_addr *addr)
pconn->addr = *addr;
TAILQ_INSERT_TAIL(&global.pending_conns, pconn, entry);
pconn->ev_timeout = NULL;
- thread_add_timer(master, pending_conn_timeout, pconn, PENDING_CONN_TIMEOUT,
- &pconn->ev_timeout);
+ event_add_timer(master, pending_conn_timeout, pconn,
+ PENDING_CONN_TIMEOUT, &pconn->ev_timeout);
return (pconn);
}
@@ -777,7 +777,7 @@ pending_conn_new(int fd, int af, union ldpd_addr *addr)
void
pending_conn_del(struct pending_conn *pconn)
{
- THREAD_OFF(pconn->ev_timeout);
+ EVENT_OFF(pconn->ev_timeout);
TAILQ_REMOVE(&global.pending_conns, pconn, entry);
free(pconn);
}
@@ -795,9 +795,9 @@ pending_conn_find(int af, union ldpd_addr *addr)
return (NULL);
}
-static void pending_conn_timeout(struct thread *thread)
+static void pending_conn_timeout(struct event *thread)
{
- struct pending_conn *pconn = THREAD_ARG(thread);
+ struct pending_conn *pconn = EVENT_ARG(thread);
struct tcp_conn *tcp;
pconn->ev_timeout = NULL;
diff --git a/lib/agentx.c b/lib/agentx.c
index 2f45ae8332..45f14c2703 100644
--- a/lib/agentx.c
+++ b/lib/agentx.c
@@ -27,13 +27,13 @@ DEFINE_HOOK(agentx_enabled, (), ());
static bool agentx_enabled = false;
-static struct thread_master *agentx_tm;
-static struct thread *timeout_thr = NULL;
+static struct event_loop *agentx_tm;
+static struct event *timeout_thr = NULL;
static struct list *events = NULL;
static void agentx_events_update(void);
-static void agentx_timeout(struct thread *t)
+static void agentx_timeout(struct event *t)
{
snmp_timeout();
run_alarms();
@@ -41,18 +41,18 @@ static void agentx_timeout(struct thread *t)
agentx_events_update();
}
-static void agentx_read(struct thread *t)
+static void agentx_read(struct event *t)
{
fd_set fds;
int flags, new_flags = 0;
int nonblock = false;
- struct listnode *ln = THREAD_ARG(t);
- struct thread **thr = listgetdata(ln);
+ struct listnode *ln = EVENT_ARG(t);
+ struct event **thr = listgetdata(ln);
XFREE(MTYPE_TMP, thr);
list_delete_node(events, ln);
/* fix for non blocking socket */
- flags = fcntl(THREAD_FD(t), F_GETFL, 0);
+ flags = fcntl(EVENT_FD(t), F_GETFL, 0);
if (-1 == flags) {
flog_err(EC_LIB_SYSTEM_CALL, "Failed to get FD settings fcntl: %s(%d)",
strerror(errno), errno);
@@ -62,19 +62,19 @@ static void agentx_read(struct thread *t)
if (flags & O_NONBLOCK)
nonblock = true;
else
- new_flags = fcntl(THREAD_FD(t), F_SETFL, flags | O_NONBLOCK);
+ new_flags = fcntl(EVENT_FD(t), F_SETFL, flags | O_NONBLOCK);
if (new_flags == -1)
flog_err(EC_LIB_SYSTEM_CALL, "Failed to set snmp fd non blocking: %s(%d)",
strerror(errno), errno);
FD_ZERO(&fds);
- FD_SET(THREAD_FD(t), &fds);
+ FD_SET(EVENT_FD(t), &fds);
snmp_read(&fds);
/* Reset the flag */
if (!nonblock) {
- new_flags = fcntl(THREAD_FD(t), F_SETFL, flags);
+ new_flags = fcntl(EVENT_FD(t), F_SETFL, flags);
if (new_flags == -1)
flog_err(
@@ -94,22 +94,22 @@ static void agentx_events_update(void)
struct timeval timeout = {.tv_sec = 0, .tv_usec = 0};
fd_set fds;
struct listnode *ln;
- struct thread **thr;
+ struct event **thr;
int fd, thr_fd;
- thread_cancel(&timeout_thr);
+ event_cancel(&timeout_thr);
FD_ZERO(&fds);
snmp_select_info(&maxfd, &fds, &timeout, &block);
if (!block) {
- thread_add_timer_tv(agentx_tm, agentx_timeout, NULL, &timeout,
- &timeout_thr);
+ event_add_timer_tv(agentx_tm, agentx_timeout, NULL, &timeout,
+ &timeout_thr);
}
ln = listhead(events);
thr = ln ? listgetdata(ln) : NULL;
- thr_fd = thr ? THREAD_FD(*thr) : -1;
+ thr_fd = thr ? EVENT_FD(*thr) : -1;
/* "two-pointer" / two-list simultaneous iteration
* ln/thr/thr_fd point to the next existing event listener to hit while
@@ -119,21 +119,21 @@ static void agentx_events_update(void)
if (thr_fd == fd) {
struct listnode *nextln = listnextnode(ln);
if (!FD_ISSET(fd, &fds)) {
- thread_cancel(thr);
+ event_cancel(thr);
XFREE(MTYPE_TMP, thr);
list_delete_node(events, ln);
}
ln = nextln;
thr = ln ? listgetdata(ln) : NULL;
- thr_fd = thr ? THREAD_FD(*thr) : -1;
+ thr_fd = thr ? EVENT_FD(*thr) : -1;
}
/* need listener, but haven't hit one where it would be */
else if (FD_ISSET(fd, &fds)) {
struct listnode *newln;
- thr = XCALLOC(MTYPE_TMP, sizeof(struct thread *));
+ thr = XCALLOC(MTYPE_TMP, sizeof(struct event *));
newln = listnode_add_before(events, ln, thr);
- thread_add_read(agentx_tm, agentx_read, newln, fd, thr);
+ event_add_read(agentx_tm, agentx_read, newln, fd, thr);
}
}
@@ -142,7 +142,7 @@ static void agentx_events_update(void)
while (ln) {
struct listnode *nextln = listnextnode(ln);
thr = listgetdata(ln);
- thread_cancel(thr);
+ event_cancel(thr);
XFREE(MTYPE_TMP, thr);
list_delete_node(events, ln);
ln = nextln;
@@ -244,7 +244,7 @@ bool smux_enabled(void)
return agentx_enabled;
}
-void smux_init(struct thread_master *tm)
+void smux_init(struct event_loop *tm)
{
agentx_tm = tm;
diff --git a/lib/bfd.c b/lib/bfd.c
index 0d77c5c822..cc6d09a60f 100644
--- a/lib/bfd.c
+++ b/lib/bfd.c
@@ -10,7 +10,7 @@
#include "command.h"
#include "memory.h"
#include "prefix.h"
-#include "thread.h"
+#include "frrevent.h"
#include "stream.h"
#include "vrf.h"
#include "zclient.h"
@@ -75,7 +75,7 @@ struct bfd_session_params {
* Next event.
*
* This variable controls what action to execute when the command batch
- * finishes. Normally we'd use `thread_add_event` value, however since
+ * finishes. Normally we'd use `event_add_event` value, however since
* that function is going to be called multiple times and the value
* might be different we'll use this variable to keep track of it.
*/
@@ -87,7 +87,7 @@ struct bfd_session_params {
* configuration load or northbound batch), so we'll use this to
* install/uninstall the BFD session parameters only once.
*/
- struct thread *installev;
+ struct event *installev;
/** BFD session installation state. */
bool installed;
@@ -111,7 +111,7 @@ struct bfd_sessions_global {
struct bfd_source_list source_list;
/** Pointer to FRR's event manager. */
- struct thread_master *tm;
+ struct event_loop *tm;
/** Pointer to zebra client data structure. */
struct zclient *zc;
@@ -485,9 +485,9 @@ static bool _bfd_sess_valid(const struct bfd_session_params *bsp)
return true;
}
-static void _bfd_sess_send(struct thread *t)
+static void _bfd_sess_send(struct event *t)
{
- struct bfd_session_params *bsp = THREAD_ARG(t);
+ struct bfd_session_params *bsp = EVENT_ARG(t);
int rv;
/* Validate configuration before trying to send bogus data. */
@@ -532,16 +532,16 @@ static void _bfd_sess_send(struct thread *t)
static void _bfd_sess_remove(struct bfd_session_params *bsp)
{
+ /* Cancel any pending installation request. */
+ EVENT_OFF(bsp->installev);
+
/* Not installed, nothing to do. */
if (!bsp->installed)
return;
- /* Cancel any pending installation request. */
- THREAD_OFF(bsp->installev);
-
/* Send request to remove any session. */
bsp->lastev = BSE_UNINSTALL;
- thread_execute(bsglobal.tm, _bfd_sess_send, bsp, 0);
+ event_execute(bsglobal.tm, _bfd_sess_send, bsp, 0);
}
void bfd_sess_free(struct bfd_session_params **bsp)
@@ -733,13 +733,13 @@ void bfd_sess_set_auto_source(struct bfd_session_params *bsp, bool enable)
void bfd_sess_install(struct bfd_session_params *bsp)
{
bsp->lastev = BSE_INSTALL;
- thread_add_event(bsglobal.tm, _bfd_sess_send, bsp, 0, &bsp->installev);
+ event_add_event(bsglobal.tm, _bfd_sess_send, bsp, 0, &bsp->installev);
}
void bfd_sess_uninstall(struct bfd_session_params *bsp)
{
bsp->lastev = BSE_UNINSTALL;
- thread_add_event(bsglobal.tm, _bfd_sess_send, bsp, 0, &bsp->installev);
+ event_add_event(bsglobal.tm, _bfd_sess_send, bsp, 0, &bsp->installev);
}
enum bfd_session_state bfd_sess_status(const struct bfd_session_params *bsp)
@@ -890,11 +890,11 @@ int zclient_bfd_session_replay(ZAPI_CALLBACK_ARGS)
bsp->installed = false;
/* Cancel any pending installation request. */
- THREAD_OFF(bsp->installev);
+ EVENT_OFF(bsp->installev);
/* Ask for installation. */
bsp->lastev = BSE_INSTALL;
- thread_execute(bsglobal.tm, _bfd_sess_send, bsp, 0);
+ event_execute(bsglobal.tm, _bfd_sess_send, bsp, 0);
}
return 0;
@@ -1039,7 +1039,7 @@ static int bfd_protocol_integration_finish(void)
return 0;
}
-void bfd_protocol_integration_init(struct zclient *zc, struct thread_master *tm)
+void bfd_protocol_integration_init(struct zclient *zc, struct event_loop *tm)
{
/* Initialize data structure. */
TAILQ_INIT(&bsglobal.bsplist);
diff --git a/lib/bfd.h b/lib/bfd.h
index 66c08cde74..bfa5287340 100644
--- a/lib/bfd.h
+++ b/lib/bfd.h
@@ -348,7 +348,7 @@ void bfd_sess_show(struct vty *vty, struct json_object *json,
* Initializes the BFD integration library. This function executes the
* following actions:
*
- * - Copy the `struct thread_master` pointer to use as "thread" to execute
+ * - Copy the `struct event_loop` pointer to use as "thread" to execute
* the BFD session parameters installation.
* - Copy the `struct zclient` pointer to install its callbacks.
* - Initializes internal data structures.
@@ -356,8 +356,7 @@ void bfd_sess_show(struct vty *vty, struct json_object *json,
* \param tm normally the daemon main thread event manager.
* \param zc the zebra client of the daemon.
*/
-void bfd_protocol_integration_init(struct zclient *zc,
- struct thread_master *tm);
+void bfd_protocol_integration_init(struct zclient *zc, struct event_loop *tm);
/**
* BFD session registration arguments.
diff --git a/lib/clippy.c b/lib/clippy.c
index c3c9f5c401..d414053c55 100644
--- a/lib/clippy.c
+++ b/lib/clippy.c
@@ -14,6 +14,53 @@
#include "command_graph.h"
#include "clippy.h"
+#if PY_VERSION_HEX >= 0x03080000
+/* new python init/config API added in Python 3.8 */
+int main(int argc, char **argv)
+{
+ PyStatus status;
+ PyPreConfig preconfig[1];
+ PyConfig config[1];
+
+ PyPreConfig_InitPythonConfig(preconfig);
+ preconfig->configure_locale = 0;
+ preconfig->coerce_c_locale = 1;
+ preconfig->coerce_c_locale_warn = 0;
+ preconfig->isolated = 0;
+ preconfig->utf8_mode = 1;
+ preconfig->parse_argv = 0;
+
+ status = Py_PreInitializeFromBytesArgs(preconfig, argc, argv);
+ if (PyStatus_Exception(status))
+ Py_ExitStatusException(status);
+
+ PyConfig_InitPythonConfig(config);
+#if PY_VERSION_HEX >= 0x030b0000 /* 3.11 */
+ config->safe_path = 0;
+#endif
+
+ status = PyConfig_SetBytesArgv(config, argc, argv);
+ if (PyStatus_Exception(status))
+ Py_ExitStatusException(status);
+
+ PyConfig_SetBytesString(config, &config->program_name,
+ argc > 0 ? argv[0] : "clippy");
+ if (argc > 1)
+ PyConfig_SetBytesString(config, &config->run_filename, argv[1]);
+
+ PyImport_AppendInittab("_clippy", command_py_init);
+
+ status = Py_InitializeFromConfig(config);
+ if (PyStatus_Exception(status))
+ Py_ExitStatusException(status);
+
+ PyConfig_Clear(config);
+
+ return Py_RunMain();
+}
+
+#else /* Python < 3.8 */
+/* old python init/config API, deprecated in Python 3.11 */
#if PY_MAJOR_VERSION >= 3
#define pychar wchar_t
static wchar_t *wconv(const char *s)
@@ -89,6 +136,7 @@ int main(int argc, char **argv)
free(wargv);
return 0;
}
+#endif /* Python < 3.8 */
/* and now for the ugly part... provide simplified logging functions so we
* don't need to link libzebra (which would be a circular build dep) */
diff --git a/lib/command.c b/lib/command.c
index ee5a3889e8..97ea200ff4 100644
--- a/lib/command.c
+++ b/lib/command.c
@@ -17,7 +17,7 @@
#include "memory.h"
#include "log.h"
#include "log_vty.h"
-#include "thread.h"
+#include "frrevent.h"
#include "vector.h"
#include "linklist.h"
#include "vty.h"
@@ -2542,7 +2542,7 @@ void cmd_init(int terminal)
install_default(CONFIG_NODE);
- thread_cmd_init();
+ event_cmd_init();
workqueue_cmd_init();
hash_cmd_init();
}
@@ -2596,9 +2596,7 @@ void cmd_terminate(void)
// well
graph_delete_graph(cmd_node->cmdgraph);
vector_free(cmd_node->cmd_vector);
- hash_clean(cmd_node->cmd_hash, NULL);
- hash_free(cmd_node->cmd_hash);
- cmd_node->cmd_hash = NULL;
+ hash_clean_and_free(&cmd_node->cmd_hash, NULL);
}
vector_free(cmdvec);
diff --git a/lib/command.h b/lib/command.h
index 6538e56588..8856f9f09f 100644
--- a/lib/command.h
+++ b/lib/command.h
@@ -429,6 +429,11 @@ struct cmd_node {
#define SHARP_STR "Sharp Routing Protocol\n"
#define OSPF_GR_STR \
"OSPF non-stop forwarding (NSF) also known as OSPF Graceful Restart\n"
+#define MGMTD_STR "Management Daemon (MGMTD) information\n"
+#define MGMTD_BE_ADAPTER_STR "MGMTD Backend Adapter information\n"
+#define MGMTD_FE_ADAPTER_STR "MGMTD Frontend Adapter information\n"
+#define MGMTD_TXN_STR "MGMTD Transaction information\n"
+#define MGMTD_DS_STR "MGMTD Datastore information\n"
#define CMD_VNI_RANGE "(1-16777215)"
#define CONF_BACKUP_EXT ".sav"
diff --git a/lib/compiler.h b/lib/compiler.h
index d12e282832..29fcfbefbf 100644
--- a/lib/compiler.h
+++ b/lib/compiler.h
@@ -439,6 +439,14 @@ _Static_assert(sizeof(_uint64_t) == 8 && sizeof(_int64_t) == 8,
#pragma diag_suppress 167
#endif /* __INTELISENSE__ */
+#if defined(__GNUC__) && (__GNUC__ >= 3)
+#define likely(_x) __builtin_expect(!!(_x), 1)
+#define unlikely(_x) __builtin_expect(!!(_x), 0)
+#else
+#define likely(_x) !!(_x)
+#define unlikely(_x) !!(_x)
+#endif
+
#ifdef __cplusplus
}
#endif
diff --git a/lib/cspf.c b/lib/cspf.c
index b92c9cb395..6a0fb7f63c 100644
--- a/lib/cspf.c
+++ b/lib/cspf.c
@@ -88,7 +88,7 @@ static struct c_path *cpath_copy(struct c_path *dest, const struct c_path *src)
*
* @param path Constrained Path structure to be deleted
*/
-static void cpath_del(struct c_path *path)
+void cpath_del(struct c_path *path)
{
if (!path)
return;
diff --git a/lib/cspf.h b/lib/cspf.h
index 3eceaa04af..bba685a617 100644
--- a/lib/cspf.h
+++ b/lib/cspf.h
@@ -191,6 +191,8 @@ extern void cspf_del(struct cspf *algo);
*/
extern struct c_path *compute_p2p_path(struct cspf *algo, struct ls_ted *ted);
+extern void cpath_del(struct c_path *path);
+
#ifdef __cplusplus
}
#endif
diff --git a/lib/defun_lex.l b/lib/defun_lex.l
index 505ea59b0b..124f864166 100644
--- a/lib/defun_lex.l
+++ b/lib/defun_lex.l
@@ -53,6 +53,7 @@ int comment_link;
char string_end;
char *value;
+static const char *yyfilename;
static void extendbuf(char **what, const char *arg)
{
@@ -119,8 +120,17 @@ SPECIAL [(),]
}
}
<rstring>\\\n /* ignore */
+<rstring>\n {
+ fprintf(stderr,
+ "%s:%d: string continues past the end of the line\n",
+ yyfilename, yylineno);
+ free(value);
+ value = NULL;
+ BEGIN(INITIAL);
+ return STRING;
+ }
<rstring>\\. extend(yytext);
-<rstring>[^\\\"\']+ extend(yytext);
+<rstring>[^\\\"\'\n]+ extend(yytext);
"DEFUN" value = strdup(yytext); return DEFUNNY;
"DEFUN_NOSH" value = strdup(yytext); return DEFUNNY;
@@ -207,6 +217,10 @@ static PyObject *get_args(const char *filename, int lineno)
if (tval[0] == ')')
depth--;
}
+ if (!tval)
+ return PyErr_Format(PyExc_ValueError,
+ "%s:%d: invalid token in DEFPY parameters",
+ filename, lineno);
if (!pyArg)
pyArg = PyList_New(0);
PyList_Append(pyArg, PyUnicode_FromString(tval));
@@ -231,6 +245,7 @@ PyObject *clippy_parse(PyObject *self, PyObject *args)
int token;
yyin = fd;
value = NULL;
+ yyfilename = filename;
PyObject *pyCont = PyDict_New();
PyObject *pyObj = PyList_New(0);
@@ -248,6 +263,7 @@ PyObject *clippy_parse(PyObject *self, PyObject *args)
if (!pyArgs) {
free(tval);
Py_DECREF(pyCont);
+ yyfilename = NULL;
return NULL;
}
pyItem = PyDict_New();
@@ -276,5 +292,6 @@ PyObject *clippy_parse(PyObject *self, PyObject *args)
}
def_yylex_destroy();
fclose(fd);
+ yyfilename = NULL;
return pyCont;
}
diff --git a/lib/distribute.c b/lib/distribute.c
index 4cfdcc7840..65487676d6 100644
--- a/lib/distribute.c
+++ b/lib/distribute.c
@@ -445,14 +445,15 @@ int config_write_distribute(struct vty *vty,
void distribute_list_delete(struct distribute_ctx **ctx)
{
- if ((*ctx)->disthash) {
- hash_clean((*ctx)->disthash, (void (*)(void *))distribute_free);
+ hash_clean_and_free(&(*ctx)->disthash,
+ (void (*)(void *))distribute_free);
+
+ if (dist_ctx_list) {
+ listnode_delete(dist_ctx_list, *ctx);
+ if (list_isempty(dist_ctx_list))
+ list_delete(&dist_ctx_list);
}
- if (!dist_ctx_list)
- dist_ctx_list = list_new();
- listnode_delete(dist_ctx_list, *ctx);
- if (list_isempty(dist_ctx_list))
- list_delete(&dist_ctx_list);
+
XFREE(MTYPE_DISTRIBUTE_CTX, (*ctx));
}
diff --git a/lib/thread.c b/lib/event.c
index 8324783a7b..a8eb89f48d 100644
--- a/lib/thread.c
+++ b/lib/event.c
@@ -8,7 +8,7 @@
#include <zebra.h>
#include <sys/resource.h>
-#include "thread.h"
+#include "frrevent.h"
#include "memory.h"
#include "frrcu.h"
#include "log.h"
@@ -24,23 +24,23 @@
#include "libfrr.h"
DEFINE_MTYPE_STATIC(LIB, THREAD, "Thread");
-DEFINE_MTYPE_STATIC(LIB, THREAD_MASTER, "Thread master");
-DEFINE_MTYPE_STATIC(LIB, THREAD_POLL, "Thread Poll Info");
-DEFINE_MTYPE_STATIC(LIB, THREAD_STATS, "Thread stats");
+DEFINE_MTYPE_STATIC(LIB, EVENT_MASTER, "Thread master");
+DEFINE_MTYPE_STATIC(LIB, EVENT_POLL, "Thread Poll Info");
+DEFINE_MTYPE_STATIC(LIB, EVENT_STATS, "Thread stats");
-DECLARE_LIST(thread_list, struct thread, threaditem);
+DECLARE_LIST(event_list, struct event, eventitem);
struct cancel_req {
int flags;
- struct thread *thread;
+ struct event *thread;
void *eventobj;
- struct thread **threadref;
+ struct event **threadref;
};
/* Flags for task cancellation */
-#define THREAD_CANCEL_FLAG_READY 0x01
+#define EVENT_CANCEL_FLAG_READY 0x01
-static int thread_timer_cmp(const struct thread *a, const struct thread *b)
+static int event_timer_cmp(const struct event *a, const struct event *b)
{
if (a->u.sands.tv_sec < b->u.sands.tv_sec)
return -1;
@@ -53,7 +53,7 @@ static int thread_timer_cmp(const struct thread *a, const struct thread *b)
return 0;
}
-DECLARE_HEAP(thread_timer_list, struct thread, timeritem, thread_timer_cmp);
+DECLARE_HEAP(event_timer_list, struct event, timeritem, event_timer_cmp);
#if defined(__APPLE__)
#include <mach/mach.h>
@@ -64,7 +64,7 @@ DECLARE_HEAP(thread_timer_list, struct thread, timeritem, thread_timer_cmp);
do { \
const unsigned char wakebyte = 0x01; \
write(m->io_pipe[1], &wakebyte, 1); \
- } while (0);
+ } while (0)
/* control variable for initializer */
static pthread_once_t init_once = PTHREAD_ONCE_INIT;
@@ -73,7 +73,7 @@ pthread_key_t thread_current;
static pthread_mutex_t masters_mtx = PTHREAD_MUTEX_INITIALIZER;
static struct list *masters;
-static void thread_free(struct thread_master *master, struct thread *thread);
+static void thread_free(struct event_loop *master, struct event *thread);
#ifndef EXCLUDE_CPU_TIME
#define EXCLUDE_CPU_TIME 0
@@ -87,25 +87,26 @@ unsigned long cputime_threshold = CONSUMED_TIME_CHECK;
unsigned long walltime_threshold = CONSUMED_TIME_CHECK;
/* CLI start ---------------------------------------------------------------- */
-#include "lib/thread_clippy.c"
+#include "lib/event_clippy.c"
-static unsigned int cpu_record_hash_key(const struct cpu_thread_history *a)
+static unsigned int cpu_record_hash_key(const struct cpu_event_history *a)
{
int size = sizeof(a->func);
return jhash(&a->func, size, 0);
}
-static bool cpu_record_hash_cmp(const struct cpu_thread_history *a,
- const struct cpu_thread_history *b)
+static bool cpu_record_hash_cmp(const struct cpu_event_history *a,
+ const struct cpu_event_history *b)
{
return a->func == b->func;
}
-static void *cpu_record_hash_alloc(struct cpu_thread_history *a)
+static void *cpu_record_hash_alloc(struct cpu_event_history *a)
{
- struct cpu_thread_history *new;
- new = XCALLOC(MTYPE_THREAD_STATS, sizeof(struct cpu_thread_history));
+ struct cpu_event_history *new;
+
+ new = XCALLOC(MTYPE_EVENT_STATS, sizeof(struct cpu_event_history));
new->func = a->func;
new->funcname = a->funcname;
return new;
@@ -113,13 +114,13 @@ static void *cpu_record_hash_alloc(struct cpu_thread_history *a)
static void cpu_record_hash_free(void *a)
{
- struct cpu_thread_history *hist = a;
+ struct cpu_event_history *hist = a;
- XFREE(MTYPE_THREAD_STATS, hist);
+ XFREE(MTYPE_EVENT_STATS, hist);
}
-static void vty_out_cpu_thread_history(struct vty *vty,
- struct cpu_thread_history *a)
+static void vty_out_cpu_event_history(struct vty *vty,
+ struct cpu_event_history *a)
{
vty_out(vty,
"%5zu %10zu.%03zu %9zu %8zu %9zu %8zu %9zu %9zu %9zu %10zu",
@@ -128,21 +129,21 @@ static void vty_out_cpu_thread_history(struct vty *vty,
(a->real.total / a->total_calls), a->real.max,
a->total_cpu_warn, a->total_wall_warn, a->total_starv_warn);
vty_out(vty, " %c%c%c%c%c %s\n",
- a->types & (1 << THREAD_READ) ? 'R' : ' ',
- a->types & (1 << THREAD_WRITE) ? 'W' : ' ',
- a->types & (1 << THREAD_TIMER) ? 'T' : ' ',
- a->types & (1 << THREAD_EVENT) ? 'E' : ' ',
- a->types & (1 << THREAD_EXECUTE) ? 'X' : ' ', a->funcname);
+ a->types & (1 << EVENT_READ) ? 'R' : ' ',
+ a->types & (1 << EVENT_WRITE) ? 'W' : ' ',
+ a->types & (1 << EVENT_TIMER) ? 'T' : ' ',
+ a->types & (1 << EVENT_EVENT) ? 'E' : ' ',
+ a->types & (1 << EVENT_EXECUTE) ? 'X' : ' ', a->funcname);
}
static void cpu_record_hash_print(struct hash_bucket *bucket, void *args[])
{
- struct cpu_thread_history *totals = args[0];
- struct cpu_thread_history copy;
+ struct cpu_event_history *totals = args[0];
+ struct cpu_event_history copy;
struct vty *vty = args[1];
uint8_t *filter = args[2];
- struct cpu_thread_history *a = bucket->data;
+ struct cpu_event_history *a = bucket->data;
copy.total_active =
atomic_load_explicit(&a->total_active, memory_order_seq_cst);
@@ -167,7 +168,7 @@ static void cpu_record_hash_print(struct hash_bucket *bucket, void *args[])
if (!(copy.types & *filter))
return;
- vty_out_cpu_thread_history(vty, &copy);
+ vty_out_cpu_event_history(vty, &copy);
totals->total_active += copy.total_active;
totals->total_calls += copy.total_calls;
totals->total_cpu_warn += copy.total_cpu_warn;
@@ -183,9 +184,9 @@ static void cpu_record_hash_print(struct hash_bucket *bucket, void *args[])
static void cpu_record_print(struct vty *vty, uint8_t filter)
{
- struct cpu_thread_history tmp;
+ struct cpu_event_history tmp;
void *args[3] = {&tmp, vty, &filter};
- struct thread_master *m;
+ struct event_loop *m;
struct listnode *ln;
if (!cputime_enabled)
@@ -203,8 +204,8 @@ static void cpu_record_print(struct vty *vty, uint8_t filter)
frr_with_mutex (&masters_mtx) {
for (ALL_LIST_ELEMENTS_RO(masters, ln, m)) {
const char *name = m->name ? m->name : "main";
-
char underline[strlen(name) + 1];
+
memset(underline, '-', sizeof(underline));
underline[sizeof(underline) - 1] = '\0';
@@ -244,7 +245,7 @@ static void cpu_record_print(struct vty *vty, uint8_t filter)
vty_out(vty, " Type Thread\n");
if (tmp.total_calls > 0)
- vty_out_cpu_thread_history(vty, &tmp);
+ vty_out_cpu_event_history(vty, &tmp);
}
static void cpu_record_hash_clear(struct hash_bucket *bucket, void *args[])
@@ -252,7 +253,7 @@ static void cpu_record_hash_clear(struct hash_bucket *bucket, void *args[])
uint8_t *filter = args[0];
struct hash *cpu_record = args[1];
- struct cpu_thread_history *a = bucket->data;
+ struct cpu_event_history *a = bucket->data;
if (!(a->types & *filter))
return;
@@ -263,13 +264,14 @@ static void cpu_record_hash_clear(struct hash_bucket *bucket, void *args[])
static void cpu_record_clear(uint8_t filter)
{
uint8_t *tmp = &filter;
- struct thread_master *m;
+ struct event_loop *m;
struct listnode *ln;
frr_with_mutex (&masters_mtx) {
for (ALL_LIST_ELEMENTS_RO(masters, ln, m)) {
frr_with_mutex (&m->mtx) {
void *args[2] = {tmp, m->cpu_record};
+
hash_iterate(
m->cpu_record,
(void (*)(struct hash_bucket *,
@@ -289,23 +291,23 @@ static uint8_t parse_filter(const char *filterstr)
switch (filterstr[i]) {
case 'r':
case 'R':
- filter |= (1 << THREAD_READ);
+ filter |= (1 << EVENT_READ);
break;
case 'w':
case 'W':
- filter |= (1 << THREAD_WRITE);
+ filter |= (1 << EVENT_WRITE);
break;
case 't':
case 'T':
- filter |= (1 << THREAD_TIMER);
+ filter |= (1 << EVENT_TIMER);
break;
case 'e':
case 'E':
- filter |= (1 << THREAD_EVENT);
+ filter |= (1 << EVENT_EVENT);
break;
case 'x':
case 'X':
- filter |= (1 << THREAD_EXECUTE);
+ filter |= (1 << EVENT_EXECUTE);
break;
default:
break;
@@ -395,11 +397,11 @@ ALIAS (service_walltime_warning,
"Set up miscellaneous service\n"
"Warn for tasks exceeding total wallclock threshold\n")
-static void show_thread_poll_helper(struct vty *vty, struct thread_master *m)
+static void show_thread_poll_helper(struct vty *vty, struct event_loop *m)
{
const char *name = m->name ? m->name : "main";
char underline[strlen(name) + 1];
- struct thread *thread;
+ struct event *thread;
uint32_t i;
memset(underline, '-', sizeof(underline));
@@ -444,12 +446,11 @@ DEFUN_NOSH (show_thread_poll,
"Show poll FD's and information\n")
{
struct listnode *node;
- struct thread_master *m;
+ struct event_loop *m;
frr_with_mutex (&masters_mtx) {
- for (ALL_LIST_ELEMENTS_RO(masters, node, m)) {
+ for (ALL_LIST_ELEMENTS_RO(masters, node, m))
show_thread_poll_helper(vty, m);
- }
}
return CMD_SUCCESS;
@@ -481,11 +482,11 @@ DEFUN (clear_thread_cpu,
return CMD_SUCCESS;
}
-static void show_thread_timers_helper(struct vty *vty, struct thread_master *m)
+static void show_thread_timers_helper(struct vty *vty, struct event_loop *m)
{
const char *name = m->name ? m->name : "main";
char underline[strlen(name) + 1];
- struct thread *thread;
+ struct event *thread;
memset(underline, '-', sizeof(underline));
underline[sizeof(underline) - 1] = '\0';
@@ -493,7 +494,7 @@ static void show_thread_timers_helper(struct vty *vty, struct thread_master *m)
vty_out(vty, "\nShowing timers for %s\n", name);
vty_out(vty, "-------------------%s\n", underline);
- frr_each (thread_timer_list, &m->timer, thread) {
+ frr_each (event_timer_list, &m->timer, thread) {
vty_out(vty, " %-50s%pTH\n", thread->hist->funcname, thread);
}
}
@@ -506,7 +507,7 @@ DEFPY_NOSH (show_thread_timers,
"Show all timers and how long they have in the system\n")
{
struct listnode *node;
- struct thread_master *m;
+ struct event_loop *m;
frr_with_mutex (&masters_mtx) {
for (ALL_LIST_ELEMENTS_RO(masters, node, m))
@@ -516,7 +517,7 @@ DEFPY_NOSH (show_thread_timers,
return CMD_SUCCESS;
}
-void thread_cmd_init(void)
+void event_cmd_init(void)
{
install_element(VIEW_NODE, &show_thread_cpu_cmd);
install_element(VIEW_NODE, &show_thread_poll_cmd);
@@ -544,14 +545,14 @@ static void initializer(void)
pthread_key_create(&thread_current, NULL);
}
-struct thread_master *thread_master_create(const char *name)
+struct event_loop *event_master_create(const char *name)
{
- struct thread_master *rv;
+ struct event_loop *rv;
struct rlimit limit;
pthread_once(&init_once, &initializer);
- rv = XCALLOC(MTYPE_THREAD_MASTER, sizeof(struct thread_master));
+ rv = XCALLOC(MTYPE_EVENT_MASTER, sizeof(struct event_loop));
/* Initialize master mutex */
pthread_mutex_init(&rv->mtx, NULL);
@@ -559,7 +560,7 @@ struct thread_master *thread_master_create(const char *name)
/* Set name */
name = name ? name : "default";
- rv->name = XSTRDUP(MTYPE_THREAD_MASTER, name);
+ rv->name = XSTRDUP(MTYPE_EVENT_MASTER, name);
/* Initialize I/O task data structures */
@@ -570,13 +571,14 @@ struct thread_master *thread_master_create(const char *name)
rv->fd_limit = (int)limit.rlim_cur;
}
- rv->read = XCALLOC(MTYPE_THREAD_POLL,
- sizeof(struct thread *) * rv->fd_limit);
+ rv->read = XCALLOC(MTYPE_EVENT_POLL,
+ sizeof(struct event *) * rv->fd_limit);
- rv->write = XCALLOC(MTYPE_THREAD_POLL,
- sizeof(struct thread *) * rv->fd_limit);
+ rv->write = XCALLOC(MTYPE_EVENT_POLL,
+ sizeof(struct event *) * rv->fd_limit);
char tmhashname[strlen(name) + 32];
+
snprintf(tmhashname, sizeof(tmhashname), "%s - threadmaster event hash",
name);
rv->cpu_record = hash_create_size(
@@ -584,12 +586,12 @@ struct thread_master *thread_master_create(const char *name)
(bool (*)(const void *, const void *))cpu_record_hash_cmp,
tmhashname);
- thread_list_init(&rv->event);
- thread_list_init(&rv->ready);
- thread_list_init(&rv->unuse);
- thread_timer_list_init(&rv->timer);
+ event_list_init(&rv->event);
+ event_list_init(&rv->ready);
+ event_list_init(&rv->unuse);
+ event_timer_list_init(&rv->timer);
- /* Initialize thread_fetch() settings */
+ /* Initialize event_fetch() settings */
rv->spin = true;
rv->handle_signals = true;
@@ -607,9 +609,9 @@ struct thread_master *thread_master_create(const char *name)
/* Initialize data structures for poll() */
rv->handler.pfdsize = rv->fd_limit;
rv->handler.pfdcount = 0;
- rv->handler.pfds = XCALLOC(MTYPE_THREAD_MASTER,
+ rv->handler.pfds = XCALLOC(MTYPE_EVENT_MASTER,
sizeof(struct pollfd) * rv->handler.pfdsize);
- rv->handler.copy = XCALLOC(MTYPE_THREAD_MASTER,
+ rv->handler.copy = XCALLOC(MTYPE_EVENT_MASTER,
sizeof(struct pollfd) * rv->handler.pfdsize);
/* add to list of threadmasters */
@@ -623,32 +625,32 @@ struct thread_master *thread_master_create(const char *name)
return rv;
}
-void thread_master_set_name(struct thread_master *master, const char *name)
+void event_master_set_name(struct event_loop *master, const char *name)
{
frr_with_mutex (&master->mtx) {
- XFREE(MTYPE_THREAD_MASTER, master->name);
- master->name = XSTRDUP(MTYPE_THREAD_MASTER, name);
+ XFREE(MTYPE_EVENT_MASTER, master->name);
+ master->name = XSTRDUP(MTYPE_EVENT_MASTER, name);
}
}
-#define THREAD_UNUSED_DEPTH 10
+#define EVENT_UNUSED_DEPTH 10
/* Move thread to unuse list. */
-static void thread_add_unuse(struct thread_master *m, struct thread *thread)
+static void thread_add_unuse(struct event_loop *m, struct event *thread)
{
pthread_mutex_t mtxc = thread->mtx;
assert(m != NULL && thread != NULL);
thread->hist->total_active--;
- memset(thread, 0, sizeof(struct thread));
- thread->type = THREAD_UNUSED;
+ memset(thread, 0, sizeof(struct event));
+ thread->type = EVENT_UNUSED;
/* Restore the thread mutex context. */
thread->mtx = mtxc;
- if (thread_list_count(&m->unuse) < THREAD_UNUSED_DEPTH) {
- thread_list_add_tail(&m->unuse, thread);
+ if (event_list_count(&m->unuse) < EVENT_UNUSED_DEPTH) {
+ event_list_add_tail(&m->unuse, thread);
return;
}
@@ -656,19 +658,17 @@ static void thread_add_unuse(struct thread_master *m, struct thread *thread)
}
/* Free all unused thread. */
-static void thread_list_free(struct thread_master *m,
- struct thread_list_head *list)
+static void thread_list_free(struct event_loop *m, struct event_list_head *list)
{
- struct thread *t;
+ struct event *t;
- while ((t = thread_list_pop(list)))
+ while ((t = event_list_pop(list)))
thread_free(m, t);
}
-static void thread_array_free(struct thread_master *m,
- struct thread **thread_array)
+static void thread_array_free(struct event_loop *m, struct event **thread_array)
{
- struct thread *t;
+ struct event *t;
int index;
for (index = 0; index < m->fd_limit; ++index) {
@@ -678,41 +678,41 @@ static void thread_array_free(struct thread_master *m,
thread_free(m, t);
}
}
- XFREE(MTYPE_THREAD_POLL, thread_array);
+ XFREE(MTYPE_EVENT_POLL, thread_array);
}
/*
- * thread_master_free_unused
+ * event_master_free_unused
*
* As threads are finished with they are put on the
* unuse list for later reuse.
* If we are shutting down, Free up unused threads
* So we can see if we forget to shut anything off
*/
-void thread_master_free_unused(struct thread_master *m)
+void event_master_free_unused(struct event_loop *m)
{
frr_with_mutex (&m->mtx) {
- struct thread *t;
- while ((t = thread_list_pop(&m->unuse)))
+ struct event *t;
+
+ while ((t = event_list_pop(&m->unuse)))
thread_free(m, t);
}
}
/* Stop thread scheduler. */
-void thread_master_free(struct thread_master *m)
+void event_master_free(struct event_loop *m)
{
- struct thread *t;
+ struct event *t;
frr_with_mutex (&masters_mtx) {
listnode_delete(masters, m);
- if (masters->count == 0) {
+ if (masters->count == 0)
list_delete(&masters);
- }
}
thread_array_free(m, m->read);
thread_array_free(m, m->write);
- while ((t = thread_timer_list_pop(&m->timer)))
+ while ((t = event_timer_list_pop(&m->timer)))
thread_free(m, t);
thread_list_free(m, &m->event);
thread_list_free(m, &m->ready);
@@ -724,22 +724,20 @@ void thread_master_free(struct thread_master *m)
list_delete(&m->cancel_req);
m->cancel_req = NULL;
- hash_clean(m->cpu_record, cpu_record_hash_free);
- hash_free(m->cpu_record);
- m->cpu_record = NULL;
+ hash_clean_and_free(&m->cpu_record, cpu_record_hash_free);
- XFREE(MTYPE_THREAD_MASTER, m->name);
- XFREE(MTYPE_THREAD_MASTER, m->handler.pfds);
- XFREE(MTYPE_THREAD_MASTER, m->handler.copy);
- XFREE(MTYPE_THREAD_MASTER, m);
+ XFREE(MTYPE_EVENT_MASTER, m->name);
+ XFREE(MTYPE_EVENT_MASTER, m->handler.pfds);
+ XFREE(MTYPE_EVENT_MASTER, m->handler.copy);
+ XFREE(MTYPE_EVENT_MASTER, m);
}
/* Return remain time in milliseconds. */
-unsigned long thread_timer_remain_msec(struct thread *thread)
+unsigned long event_timer_remain_msec(struct event *thread)
{
int64_t remain;
- if (!thread_is_scheduled(thread))
+ if (!event_is_scheduled(thread))
return 0;
frr_with_mutex (&thread->mtx) {
@@ -750,14 +748,15 @@ unsigned long thread_timer_remain_msec(struct thread *thread)
}
/* Return remain time in seconds. */
-unsigned long thread_timer_remain_second(struct thread *thread)
+unsigned long event_timer_remain_second(struct event *thread)
{
- return thread_timer_remain_msec(thread) / 1000LL;
+ return event_timer_remain_msec(thread) / 1000LL;
}
-struct timeval thread_timer_remain(struct thread *thread)
+struct timeval event_timer_remain(struct event *thread)
{
struct timeval remain;
+
frr_with_mutex (&thread->mtx) {
monotime_until(&thread->u.sands, &remain);
}
@@ -782,28 +781,26 @@ static int time_hhmmss(char *buf, int buf_size, long sec)
return wr != 8;
}
-char *thread_timer_to_hhmmss(char *buf, int buf_size,
- struct thread *t_timer)
+char *event_timer_to_hhmmss(char *buf, int buf_size, struct event *t_timer)
{
- if (t_timer) {
- time_hhmmss(buf, buf_size,
- thread_timer_remain_second(t_timer));
- } else {
+ if (t_timer)
+ time_hhmmss(buf, buf_size, event_timer_remain_second(t_timer));
+ else
snprintf(buf, buf_size, "--:--:--");
- }
+
return buf;
}
/* Get new thread. */
-static struct thread *thread_get(struct thread_master *m, uint8_t type,
- void (*func)(struct thread *), void *arg,
- const struct xref_threadsched *xref)
+static struct event *thread_get(struct event_loop *m, uint8_t type,
+ void (*func)(struct event *), void *arg,
+ const struct xref_eventsched *xref)
{
- struct thread *thread = thread_list_pop(&m->unuse);
- struct cpu_thread_history tmp;
+ struct event *thread = event_list_pop(&m->unuse);
+ struct cpu_event_history tmp;
if (!thread) {
- thread = XCALLOC(MTYPE_THREAD, sizeof(struct thread));
+ thread = XCALLOC(MTYPE_THREAD, sizeof(struct event));
/* mutex only needs to be initialized at struct creation. */
pthread_mutex_init(&thread->mtx, NULL);
m->alloc++;
@@ -813,7 +810,7 @@ static struct thread *thread_get(struct thread_master *m, uint8_t type,
thread->add_type = type;
thread->master = m;
thread->arg = arg;
- thread->yield = THREAD_YIELD_TIME_SLOT; /* default */
+ thread->yield = EVENT_YIELD_TIME_SLOT; /* default */
thread->ref = NULL;
thread->ignore_timer_late = false;
@@ -842,7 +839,7 @@ static struct thread *thread_get(struct thread_master *m, uint8_t type,
return thread;
}
-static void thread_free(struct thread_master *master, struct thread *thread)
+static void thread_free(struct event_loop *master, struct event *thread)
{
/* Update statistics. */
assert(master->alloc > 0);
@@ -853,7 +850,7 @@ static void thread_free(struct thread_master *master, struct thread *thread)
XFREE(MTYPE_THREAD, thread);
}
-static int fd_poll(struct thread_master *m, const struct timeval *timer_wait,
+static int fd_poll(struct event_loop *m, const struct timeval *timer_wait,
bool *eintr_p)
{
sigset_t origsigs;
@@ -862,7 +859,7 @@ static int fd_poll(struct thread_master *m, const struct timeval *timer_wait,
/*
* If timer_wait is null here, that means poll() should block
- * indefinitely, unless the thread_master has overridden it by setting
+ * indefinitely, unless the event_master has overridden it by setting
* ->selectpoll_timeout.
*
* If the value is positive, it specifies the maximum number of
@@ -875,15 +872,17 @@ static int fd_poll(struct thread_master *m, const struct timeval *timer_wait,
/* number of file descriptors with events */
int num;
- if (timer_wait != NULL
- && m->selectpoll_timeout == 0) // use the default value
+ if (timer_wait != NULL && m->selectpoll_timeout == 0) {
+ /* use the default value */
timeout = (timer_wait->tv_sec * 1000)
+ (timer_wait->tv_usec / 1000);
- else if (m->selectpoll_timeout > 0) // use the user's timeout
+ } else if (m->selectpoll_timeout > 0) {
+ /* use the user's timeout */
timeout = m->selectpoll_timeout;
- else if (m->selectpoll_timeout
- < 0) // effect a poll (return immediately)
+ } else if (m->selectpoll_timeout < 0) {
+ /* effect a poll (return immediately) */
timeout = 0;
+ }
zlog_tls_buffer_flush();
rcu_read_unlock();
@@ -951,16 +950,15 @@ done:
}
/* Add new read thread. */
-void _thread_add_read_write(const struct xref_threadsched *xref,
- struct thread_master *m,
- void (*func)(struct thread *), void *arg, int fd,
- struct thread **t_ptr)
+void _event_add_read_write(const struct xref_eventsched *xref,
+ struct event_loop *m, void (*func)(struct event *),
+ void *arg, int fd, struct event **t_ptr)
{
- int dir = xref->thread_type;
- struct thread *thread = NULL;
- struct thread **thread_array;
+ int dir = xref->event_type;
+ struct event *thread = NULL;
+ struct event **thread_array;
- if (dir == THREAD_READ)
+ if (dir == EVENT_READ)
frrtrace(9, frr_libfrr, schedule_read, m,
xref->funcname, xref->xref.file, xref->xref.line,
t_ptr, fd, 0, arg, 0);
@@ -974,20 +972,22 @@ void _thread_add_read_write(const struct xref_threadsched *xref,
assert(!"Number of FD's open is greater than FRR currently configured to handle, aborting");
frr_with_mutex (&m->mtx) {
+ /* Thread is already scheduled; don't reschedule */
if (t_ptr && *t_ptr)
- // thread is already scheduled; don't reschedule
break;
/* default to a new pollfd */
nfds_t queuepos = m->handler.pfdcount;
- if (dir == THREAD_READ)
+ if (dir == EVENT_READ)
thread_array = m->read;
else
thread_array = m->write;
- /* if we already have a pollfd for our file descriptor, find and
- * use it */
+ /*
+ * if we already have a pollfd for our file descriptor, find and
+ * use it
+ */
for (nfds_t i = 0; i < m->handler.pfdcount; i++)
if (m->handler.pfds[i].fd == fd) {
queuepos = i;
@@ -1010,7 +1010,7 @@ void _thread_add_read_write(const struct xref_threadsched *xref,
m->handler.pfds[queuepos].fd = fd;
m->handler.pfds[queuepos].events |=
- (dir == THREAD_READ ? POLLIN : POLLOUT);
+ (dir == EVENT_READ ? POLLIN : POLLOUT);
if (queuepos == m->handler.pfdcount)
m->handler.pfdcount++;
@@ -1031,13 +1031,13 @@ void _thread_add_read_write(const struct xref_threadsched *xref,
}
}
-static void _thread_add_timer_timeval(const struct xref_threadsched *xref,
- struct thread_master *m,
- void (*func)(struct thread *), void *arg,
- struct timeval *time_relative,
- struct thread **t_ptr)
+static void _event_add_timer_timeval(const struct xref_eventsched *xref,
+ struct event_loop *m,
+ void (*func)(struct event *), void *arg,
+ struct timeval *time_relative,
+ struct event **t_ptr)
{
- struct thread *thread;
+ struct event *thread;
struct timeval t;
assert(m != NULL);
@@ -1057,11 +1057,11 @@ static void _thread_add_timer_timeval(const struct xref_threadsched *xref,
/* thread is already scheduled; don't reschedule */
return;
- thread = thread_get(m, THREAD_TIMER, func, arg, xref);
+ thread = thread_get(m, EVENT_TIMER, func, arg, xref);
frr_with_mutex (&thread->mtx) {
thread->u.sands = t;
- thread_timer_list_add(&m->timer, thread);
+ event_timer_list_add(&m->timer, thread);
if (t_ptr) {
*t_ptr = thread;
thread->ref = t_ptr;
@@ -1072,7 +1072,7 @@ static void _thread_add_timer_timeval(const struct xref_threadsched *xref,
* might change the time we'll wait for, give the pthread
* a chance to re-compute.
*/
- if (thread_timer_list_first(&m->timer) == thread)
+ if (event_timer_list_first(&m->timer) == thread)
AWAKEN(m);
}
#define ONEYEAR2SEC (60 * 60 * 24 * 365)
@@ -1085,9 +1085,9 @@ static void _thread_add_timer_timeval(const struct xref_threadsched *xref,
/* Add timer event thread. */
-void _thread_add_timer(const struct xref_threadsched *xref,
- struct thread_master *m, void (*func)(struct thread *),
- void *arg, long timer, struct thread **t_ptr)
+void _event_add_timer(const struct xref_eventsched *xref, struct event_loop *m,
+ void (*func)(struct event *), void *arg, long timer,
+ struct event **t_ptr)
{
struct timeval trel;
@@ -1096,14 +1096,13 @@ void _thread_add_timer(const struct xref_threadsched *xref,
trel.tv_sec = timer;
trel.tv_usec = 0;
- _thread_add_timer_timeval(xref, m, func, arg, &trel, t_ptr);
+ _event_add_timer_timeval(xref, m, func, arg, &trel, t_ptr);
}
/* Add timer event thread with "millisecond" resolution */
-void _thread_add_timer_msec(const struct xref_threadsched *xref,
- struct thread_master *m,
- void (*func)(struct thread *), void *arg,
- long timer, struct thread **t_ptr)
+void _event_add_timer_msec(const struct xref_eventsched *xref,
+ struct event_loop *m, void (*func)(struct event *),
+ void *arg, long timer, struct event **t_ptr)
{
struct timeval trel;
@@ -1112,24 +1111,23 @@ void _thread_add_timer_msec(const struct xref_threadsched *xref,
trel.tv_sec = timer / 1000;
trel.tv_usec = 1000 * (timer % 1000);
- _thread_add_timer_timeval(xref, m, func, arg, &trel, t_ptr);
+ _event_add_timer_timeval(xref, m, func, arg, &trel, t_ptr);
}
/* Add timer event thread with "timeval" resolution */
-void _thread_add_timer_tv(const struct xref_threadsched *xref,
- struct thread_master *m,
- void (*func)(struct thread *), void *arg,
- struct timeval *tv, struct thread **t_ptr)
+void _event_add_timer_tv(const struct xref_eventsched *xref,
+ struct event_loop *m, void (*func)(struct event *),
+ void *arg, struct timeval *tv, struct event **t_ptr)
{
- _thread_add_timer_timeval(xref, m, func, arg, tv, t_ptr);
+ _event_add_timer_timeval(xref, m, func, arg, tv, t_ptr);
}
/* Add simple event thread. */
-void _thread_add_event(const struct xref_threadsched *xref,
- struct thread_master *m, void (*func)(struct thread *),
- void *arg, int val, struct thread **t_ptr)
+void _event_add_event(const struct xref_eventsched *xref, struct event_loop *m,
+ void (*func)(struct event *), void *arg, int val,
+ struct event **t_ptr)
{
- struct thread *thread = NULL;
+ struct event *thread = NULL;
frrtrace(9, frr_libfrr, schedule_event, m,
xref->funcname, xref->xref.file, xref->xref.line,
@@ -1142,10 +1140,10 @@ void _thread_add_event(const struct xref_threadsched *xref,
/* thread is already scheduled; don't reschedule */
break;
- thread = thread_get(m, THREAD_EVENT, func, arg, xref);
+ thread = thread_get(m, EVENT_EVENT, func, arg, xref);
frr_with_mutex (&thread->mtx) {
thread->u.val = val;
- thread_list_add_tail(&m->event, thread);
+ event_list_add_tail(&m->event, thread);
}
if (t_ptr) {
@@ -1163,7 +1161,7 @@ void _thread_add_event(const struct xref_threadsched *xref,
* NOT's out the .events field of pollfd corresponding to the given file
* descriptor. The event to be NOT'd is passed in the 'state' parameter.
*
- * This needs to happen for both copies of pollfd's. See 'thread_fetch'
+ * This needs to happen for both copies of pollfd's. See 'event_fetch'
* implementation for details.
*
* @param master
@@ -1173,8 +1171,8 @@ void _thread_add_event(const struct xref_threadsched *xref,
* - POLLIN
* - POLLOUT
*/
-static void thread_cancel_rw(struct thread_master *master, int fd, short state,
- int idx_hint)
+static void event_cancel_rw(struct event_loop *master, int fd, short state,
+ int idx_hint)
{
bool found = false;
@@ -1218,8 +1216,10 @@ static void thread_cancel_rw(struct thread_master *master, int fd, short state,
master->handler.pfds[master->handler.pfdcount].events = 0;
}
- /* If we have the same pollfd in the copy, perform the same operations,
- * otherwise return. */
+ /*
+ * If we have the same pollfd in the copy, perform the same operations,
+ * otherwise return.
+ */
if (i >= master->handler.copycount)
return;
@@ -1231,7 +1231,7 @@ static void thread_cancel_rw(struct thread_master *master, int fd, short state,
* sizeof(struct pollfd));
master->handler.copycount--;
master->handler.copy[master->handler.copycount].fd = 0;
- master->handler.copy[master->handler.copycount].events = 0;
+ master->handler.copy[master->handler.copycount].events = 0;
}
}
@@ -1239,10 +1239,10 @@ static void thread_cancel_rw(struct thread_master *master, int fd, short state,
* Process task cancellation given a task argument: iterate through the
* various lists of tasks, looking for any that match the argument.
*/
-static void cancel_arg_helper(struct thread_master *master,
+static void cancel_arg_helper(struct event_loop *master,
const struct cancel_req *cr)
{
- struct thread *t;
+ struct event *t;
nfds_t i;
int fd;
struct pollfd *pfd;
@@ -1252,26 +1252,26 @@ static void cancel_arg_helper(struct thread_master *master,
return;
/* First process the ready lists. */
- frr_each_safe(thread_list, &master->event, t) {
+ frr_each_safe (event_list, &master->event, t) {
if (t->arg != cr->eventobj)
continue;
- thread_list_del(&master->event, t);
+ event_list_del(&master->event, t);
if (t->ref)
*t->ref = NULL;
thread_add_unuse(master, t);
}
- frr_each_safe(thread_list, &master->ready, t) {
+ frr_each_safe (event_list, &master->ready, t) {
if (t->arg != cr->eventobj)
continue;
- thread_list_del(&master->ready, t);
+ event_list_del(&master->ready, t);
if (t->ref)
*t->ref = NULL;
thread_add_unuse(master, t);
}
/* If requested, stop here and ignore io and timers */
- if (CHECK_FLAG(cr->flags, THREAD_CANCEL_FLAG_READY))
+ if (CHECK_FLAG(cr->flags, EVENT_CANCEL_FLAG_READY))
return;
/* Check the io tasks */
@@ -1287,7 +1287,7 @@ static void cancel_arg_helper(struct thread_master *master,
fd = pfd->fd;
/* Found a match to cancel: clean up fd arrays */
- thread_cancel_rw(master, pfd->fd, pfd->events, i);
+ event_cancel_rw(master, pfd->fd, pfd->events, i);
/* Clean up thread arrays */
master->read[fd] = NULL;
@@ -1307,14 +1307,14 @@ static void cancel_arg_helper(struct thread_master *master,
}
/* Check the timer tasks */
- t = thread_timer_list_first(&master->timer);
+ t = event_timer_list_first(&master->timer);
while (t) {
- struct thread *t_next;
+ struct event *t_next;
- t_next = thread_timer_list_next(&master->timer, t);
+ t_next = event_timer_list_next(&master->timer, t);
if (t->arg == cr->eventobj) {
- thread_timer_list_del(&master->timer, t);
+ event_timer_list_del(&master->timer, t);
if (t->ref)
*t->ref = NULL;
thread_add_unuse(master, t);
@@ -1327,16 +1327,16 @@ static void cancel_arg_helper(struct thread_master *master,
/**
* Process cancellation requests.
*
- * This may only be run from the pthread which owns the thread_master.
+ * This may only be run from the pthread which owns the event_master.
*
* @param master the thread master to process
* @REQUIRE master->mtx
*/
-static void do_thread_cancel(struct thread_master *master)
+static void do_event_cancel(struct event_loop *master)
{
- struct thread_list_head *list = NULL;
- struct thread **thread_array = NULL;
- struct thread *thread;
+ struct event_list_head *list = NULL;
+ struct event **thread_array = NULL;
+ struct event *thread;
struct cancel_req *cr;
struct listnode *ln;
@@ -1367,33 +1367,33 @@ static void do_thread_cancel(struct thread_master *master)
/* Determine the appropriate queue to cancel the thread from */
switch (thread->type) {
- case THREAD_READ:
- thread_cancel_rw(master, thread->u.fd, POLLIN, -1);
+ case EVENT_READ:
+ event_cancel_rw(master, thread->u.fd, POLLIN, -1);
thread_array = master->read;
break;
- case THREAD_WRITE:
- thread_cancel_rw(master, thread->u.fd, POLLOUT, -1);
+ case EVENT_WRITE:
+ event_cancel_rw(master, thread->u.fd, POLLOUT, -1);
thread_array = master->write;
break;
- case THREAD_TIMER:
- thread_timer_list_del(&master->timer, thread);
+ case EVENT_TIMER:
+ event_timer_list_del(&master->timer, thread);
break;
- case THREAD_EVENT:
+ case EVENT_EVENT:
list = &master->event;
break;
- case THREAD_READY:
+ case EVENT_READY:
list = &master->ready;
break;
- default:
+ case EVENT_UNUSED:
+ case EVENT_EXECUTE:
continue;
break;
}
- if (list) {
- thread_list_del(list, thread);
- } else if (thread_array) {
+ if (list)
+ event_list_del(list, thread);
+ else if (thread_array)
thread_array[thread->u.fd] = NULL;
- }
if (thread->ref)
*thread->ref = NULL;
@@ -1405,7 +1405,7 @@ static void do_thread_cancel(struct thread_master *master)
if (master->cancel_req)
list_delete_all_node(master->cancel_req);
- /* Wake up any threads which may be blocked in thread_cancel_async() */
+ /* Wake up any threads which may be blocked in event_cancel_async() */
master->canceled = true;
pthread_cond_broadcast(&master->cancel_cond);
}
@@ -1413,7 +1413,7 @@ static void do_thread_cancel(struct thread_master *master)
/*
* Helper function used for multiple flavors of arg-based cancellation.
*/
-static void cancel_event_helper(struct thread_master *m, void *arg, int flags)
+static void cancel_event_helper(struct event_loop *m, void *arg, int flags)
{
struct cancel_req *cr;
@@ -1430,7 +1430,7 @@ static void cancel_event_helper(struct thread_master *m, void *arg, int flags)
frr_with_mutex (&m->mtx) {
cr->eventobj = arg;
listnode_add(m->cancel_req, cr);
- do_thread_cancel(m);
+ do_event_cancel(m);
}
}
@@ -1439,10 +1439,10 @@ static void cancel_event_helper(struct thread_master *m, void *arg, int flags)
*
* MT-Unsafe
*
- * @param m the thread_master to cancel from
+ * @param m the event_master to cancel from
* @param arg the argument passed when creating the event
*/
-void thread_cancel_event(struct thread_master *master, void *arg)
+void event_cancel_event(struct event_loop *master, void *arg)
{
cancel_event_helper(master, arg, 0);
}
@@ -1452,14 +1452,14 @@ void thread_cancel_event(struct thread_master *master, void *arg)
*
* MT-Unsafe
*
- * @param m the thread_master to cancel from
+ * @param m the event_master to cancel from
* @param arg the argument passed when creating the event
*/
-void thread_cancel_event_ready(struct thread_master *m, void *arg)
+void event_cancel_event_ready(struct event_loop *m, void *arg)
{
/* Only cancel ready/event tasks */
- cancel_event_helper(m, arg, THREAD_CANCEL_FLAG_READY);
+ cancel_event_helper(m, arg, EVENT_CANCEL_FLAG_READY);
}
/**
@@ -1469,19 +1469,19 @@ void thread_cancel_event_ready(struct thread_master *m, void *arg)
*
* @param thread task to cancel
*/
-void thread_cancel(struct thread **thread)
+void event_cancel(struct event **thread)
{
- struct thread_master *master;
+ struct event_loop *master;
if (thread == NULL || *thread == NULL)
return;
master = (*thread)->master;
- frrtrace(9, frr_libfrr, thread_cancel, master,
- (*thread)->xref->funcname, (*thread)->xref->xref.file,
- (*thread)->xref->xref.line, NULL, (*thread)->u.fd,
- (*thread)->u.val, (*thread)->arg, (*thread)->u.sands.tv_sec);
+ frrtrace(9, frr_libfrr, event_cancel, master, (*thread)->xref->funcname,
+ (*thread)->xref->xref.file, (*thread)->xref->xref.line, NULL,
+ (*thread)->u.fd, (*thread)->u.val, (*thread)->arg,
+ (*thread)->u.sands.tv_sec);
assert(master->owner == pthread_self());
@@ -1490,7 +1490,7 @@ void thread_cancel(struct thread **thread)
XCALLOC(MTYPE_TMP, sizeof(struct cancel_req));
cr->thread = *thread;
listnode_add(master->cancel_req, cr);
- do_thread_cancel(master);
+ do_event_cancel(master);
}
*thread = NULL;
@@ -1499,7 +1499,7 @@ void thread_cancel(struct thread **thread)
/**
* Asynchronous cancellation.
*
- * Called with either a struct thread ** or void * to an event argument,
+ * Called with either a struct event ** or void * to an event argument,
* this function posts the correct cancellation request and blocks until it is
* serviced.
*
@@ -1508,7 +1508,7 @@ void thread_cancel(struct thread **thread)
* The last two parameters are mutually exclusive, i.e. if you pass one the
* other must be NULL.
*
- * When the cancellation procedure executes on the target thread_master, the
+ * When the cancellation procedure executes on the target event_master, the
* thread * provided is checked for nullity. If it is null, the thread is
* assumed to no longer exist and the cancellation request is a no-op. Thus
* users of this API must pass a back-reference when scheduling the original
@@ -1520,19 +1520,19 @@ void thread_cancel(struct thread **thread)
* @param thread pointer to thread to cancel
* @param eventobj the event
*/
-void thread_cancel_async(struct thread_master *master, struct thread **thread,
- void *eventobj)
+void event_cancel_async(struct event_loop *master, struct event **thread,
+ void *eventobj)
{
assert(!(thread && eventobj) && (thread || eventobj));
if (thread && *thread)
- frrtrace(9, frr_libfrr, thread_cancel_async, master,
+ frrtrace(9, frr_libfrr, event_cancel_async, master,
(*thread)->xref->funcname, (*thread)->xref->xref.file,
(*thread)->xref->xref.line, NULL, (*thread)->u.fd,
(*thread)->u.val, (*thread)->arg,
(*thread)->u.sands.tv_sec);
else
- frrtrace(9, frr_libfrr, thread_cancel_async, master, NULL, NULL,
+ frrtrace(9, frr_libfrr, event_cancel_async, master, NULL, NULL,
0, NULL, 0, 0, eventobj, 0);
assert(master->owner != pthread_self());
@@ -1562,30 +1562,30 @@ void thread_cancel_async(struct thread_master *master, struct thread **thread,
}
/* ------------------------------------------------------------------------- */
-static struct timeval *thread_timer_wait(struct thread_timer_list_head *timers,
+static struct timeval *thread_timer_wait(struct event_timer_list_head *timers,
struct timeval *timer_val)
{
- if (!thread_timer_list_count(timers))
+ if (!event_timer_list_count(timers))
return NULL;
- struct thread *next_timer = thread_timer_list_first(timers);
+ struct event *next_timer = event_timer_list_first(timers);
+
monotime_until(&next_timer->u.sands, timer_val);
return timer_val;
}
-static struct thread *thread_run(struct thread_master *m, struct thread *thread,
- struct thread *fetch)
+static struct event *thread_run(struct event_loop *m, struct event *thread,
+ struct event *fetch)
{
*fetch = *thread;
thread_add_unuse(m, thread);
return fetch;
}
-static int thread_process_io_helper(struct thread_master *m,
- struct thread *thread, short state,
- short actual_state, int pos)
+static int thread_process_io_helper(struct event_loop *m, struct event *thread,
+ short state, short actual_state, int pos)
{
- struct thread **thread_array;
+ struct event **thread_array;
/*
* poll() clears the .events field, but the pollfd array we
@@ -1608,14 +1608,14 @@ static int thread_process_io_helper(struct thread_master *m,
return 0;
}
- if (thread->type == THREAD_READ)
+ if (thread->type == EVENT_READ)
thread_array = m->read;
else
thread_array = m->write;
thread_array[thread->u.fd] = NULL;
- thread_list_add_tail(&m->ready, thread);
- thread->type = THREAD_READY;
+ event_list_add_tail(&m->ready, thread);
+ thread->type = EVENT_READY;
return 1;
}
@@ -1629,7 +1629,7 @@ static int thread_process_io_helper(struct thread_master *m,
* @param m the thread master
* @param num the number of active file descriptors (return value of poll())
*/
-static void thread_process_io(struct thread_master *m, unsigned int num)
+static void thread_process_io(struct event_loop *m, unsigned int num)
{
unsigned int ready = 0;
struct pollfd *pfds = m->handler.copy;
@@ -1642,10 +1642,10 @@ static void thread_process_io(struct thread_master *m, unsigned int num)
ready++;
/*
- * Unless someone has called thread_cancel from another
+ * Unless someone has called event_cancel from another
* pthread, the only thing that could have changed in
* m->handler.pfds while we were asleep is the .events
- * field in a given pollfd. Barring thread_cancel() that
+ * field in a given pollfd. Barring event_cancel() that
* value should be a superset of the values we have in our
* copy, so there's no need to update it. Similarily,
* barring deletion, the fd should still be a valid index
@@ -1663,9 +1663,10 @@ static void thread_process_io(struct thread_master *m, unsigned int num)
thread_process_io_helper(m, m->write[pfds[i].fd],
POLLOUT, pfds[i].revents, i);
- /* if one of our file descriptors is garbage, remove the same
- * from
- * both pfds + update sizes and index */
+ /*
+ * if one of our file descriptors is garbage, remove the same
+ * from both pfds + update sizes and index
+ */
if (pfds[i].revents & POLLNVAL) {
memmove(m->handler.pfds + i, m->handler.pfds + i + 1,
(m->handler.pfdcount - i - 1)
@@ -1687,15 +1688,15 @@ static void thread_process_io(struct thread_master *m, unsigned int num)
}
/* Add all timers that have popped to the ready list. */
-static unsigned int thread_process_timers(struct thread_master *m,
+static unsigned int thread_process_timers(struct event_loop *m,
struct timeval *timenow)
{
struct timeval prev = *timenow;
bool displayed = false;
- struct thread *thread;
+ struct event *thread;
unsigned int ready = 0;
- while ((thread = thread_timer_list_first(&m->timer))) {
+ while ((thread = event_timer_list_first(&m->timer))) {
if (timercmp(timenow, &thread->u.sands, <))
break;
prev = thread->u.sands;
@@ -1719,9 +1720,9 @@ static unsigned int thread_process_timers(struct thread_master *m,
}
}
- thread_timer_list_pop(&m->timer);
- thread->type = THREAD_READY;
- thread_list_add_tail(&m->ready, thread);
+ event_timer_list_pop(&m->timer);
+ thread->type = EVENT_READY;
+ event_list_add_tail(&m->ready, thread);
ready++;
}
@@ -1729,14 +1730,14 @@ static unsigned int thread_process_timers(struct thread_master *m,
}
/* process a list en masse, e.g. for event thread lists */
-static unsigned int thread_process(struct thread_list_head *list)
+static unsigned int thread_process(struct event_list_head *list)
{
- struct thread *thread;
+ struct event *thread;
unsigned int ready = 0;
- while ((thread = thread_list_pop(list))) {
- thread->type = THREAD_READY;
- thread_list_add_tail(&thread->master->ready, thread);
+ while ((thread = event_list_pop(list))) {
+ thread->type = EVENT_READY;
+ event_list_add_tail(&thread->master->ready, thread);
ready++;
}
return ready;
@@ -1744,9 +1745,9 @@ static unsigned int thread_process(struct thread_list_head *list)
/* Fetch next ready thread. */
-struct thread *thread_fetch(struct thread_master *m, struct thread *fetch)
+struct event *event_fetch(struct event_loop *m, struct event *fetch)
{
- struct thread *thread = NULL;
+ struct event *thread = NULL;
struct timeval now;
struct timeval zerotime = {0, 0};
struct timeval tv;
@@ -1762,13 +1763,13 @@ struct thread *thread_fetch(struct thread_master *m, struct thread *fetch)
pthread_mutex_lock(&m->mtx);
/* Process any pending cancellation requests */
- do_thread_cancel(m);
+ do_event_cancel(m);
/*
* Attempt to flush ready queue before going into poll().
* This is performance-critical. Think twice before modifying.
*/
- if ((thread = thread_list_pop(&m->ready))) {
+ if ((thread = event_list_pop(&m->ready))) {
fetch = thread_run(m, thread, fetch);
if (fetch->ref)
*fetch->ref = NULL;
@@ -1804,11 +1805,11 @@ struct thread *thread_fetch(struct thread_master *m, struct thread *fetch)
* In every case except the last, we need to hit poll() at least
* once per loop to avoid starvation by events
*/
- if (!thread_list_count(&m->ready))
+ if (!event_list_count(&m->ready))
tw = thread_timer_wait(&m->timer, &tv);
- if (thread_list_count(&m->ready) ||
- (tw && !timercmp(tw, &zerotime, >)))
+ if (event_list_count(&m->ready) ||
+ (tw && !timercmp(tw, &zerotime, >)))
tw = &zerotime;
if (!tw && m->handler.pfdcount == 0) { /* die */
@@ -1869,8 +1870,8 @@ static unsigned long timeval_elapsed(struct timeval a, struct timeval b)
+ (a.tv_usec - b.tv_usec));
}
-unsigned long thread_consumed_time(RUSAGE_T *now, RUSAGE_T *start,
- unsigned long *cputime)
+unsigned long event_consumed_time(RUSAGE_T *now, RUSAGE_T *start,
+ unsigned long *cputime)
{
#ifdef HAVE_CLOCK_THREAD_CPUTIME_ID
@@ -1904,19 +1905,22 @@ unsigned long thread_consumed_time(RUSAGE_T *now, RUSAGE_T *start,
return timeval_elapsed(now->real, start->real);
}
-/* We should aim to yield after yield milliseconds, which defaults
- to THREAD_YIELD_TIME_SLOT .
- Note: we are using real (wall clock) time for this calculation.
- It could be argued that CPU time may make more sense in certain
- contexts. The things to consider are whether the thread may have
- blocked (in which case wall time increases, but CPU time does not),
- or whether the system is heavily loaded with other processes competing
- for CPU time. On balance, wall clock time seems to make sense.
- Plus it has the added benefit that gettimeofday should be faster
- than calling getrusage. */
-int thread_should_yield(struct thread *thread)
+/*
+ * We should aim to yield after yield milliseconds, which defaults
+ * to EVENT_YIELD_TIME_SLOT .
+ * Note: we are using real (wall clock) time for this calculation.
+ * It could be argued that CPU time may make more sense in certain
+ * contexts. The things to consider are whether the thread may have
+ * blocked (in which case wall time increases, but CPU time does not),
+ * or whether the system is heavily loaded with other processes competing
+ * for CPU time. On balance, wall clock time seems to make sense.
+ * Plus it has the added benefit that gettimeofday should be faster
+ * than calling getrusage.
+ */
+int event_should_yield(struct event *thread)
{
int result;
+
frr_with_mutex (&thread->mtx) {
result = monotime_since(&thread->real, NULL)
> (int64_t)thread->yield;
@@ -1924,14 +1928,14 @@ int thread_should_yield(struct thread *thread)
return result;
}
-void thread_set_yield_time(struct thread *thread, unsigned long yield_time)
+void event_set_yield_time(struct event *thread, unsigned long yield_time)
{
frr_with_mutex (&thread->mtx) {
thread->yield = yield_time;
}
}
-void thread_getrusage(RUSAGE_T *r)
+void event_getrusage(RUSAGE_T *r)
{
monotime(&r->real);
if (!cputime_enabled) {
@@ -1965,7 +1969,7 @@ void thread_getrusage(RUSAGE_T *r)
* particular, the maximum real and cpu times must be monotonically increasing
* or this code is not correct.
*/
-void thread_call(struct thread *thread)
+void event_call(struct event *thread)
{
RUSAGE_T before, after;
@@ -1982,10 +1986,10 @@ void thread_call(struct thread *thread)
thread->real = before.real;
- frrtrace(9, frr_libfrr, thread_call, thread->master,
+ frrtrace(9, frr_libfrr, event_call, thread->master,
thread->xref->funcname, thread->xref->xref.file,
- thread->xref->xref.line, NULL, thread->u.fd,
- thread->u.val, thread->arg, thread->u.sands.tv_sec);
+ thread->xref->xref.line, NULL, thread->u.fd, thread->u.val,
+ thread->arg, thread->u.sands.tv_sec);
pthread_setspecific(thread_current, thread);
(*thread->func)(thread);
@@ -1997,7 +2001,7 @@ void thread_call(struct thread *thread)
unsigned long walltime, cputime;
unsigned long exp;
- walltime = thread_consumed_time(&after, &before, &cputime);
+ walltime = event_consumed_time(&after, &before, &cputime);
/* update walltime */
atomic_fetch_add_explicit(&thread->hist->real.total, walltime,
@@ -2061,26 +2065,25 @@ void thread_call(struct thread *thread)
}
/* Execute thread */
-void _thread_execute(const struct xref_threadsched *xref,
- struct thread_master *m, void (*func)(struct thread *),
- void *arg, int val)
+void _event_execute(const struct xref_eventsched *xref, struct event_loop *m,
+ void (*func)(struct event *), void *arg, int val)
{
- struct thread *thread;
+ struct event *thread;
/* Get or allocate new thread to execute. */
frr_with_mutex (&m->mtx) {
- thread = thread_get(m, THREAD_EVENT, func, arg, xref);
+ thread = thread_get(m, EVENT_EVENT, func, arg, xref);
/* Set its event value. */
frr_with_mutex (&thread->mtx) {
- thread->add_type = THREAD_EXECUTE;
+ thread->add_type = EVENT_EXECUTE;
thread->u.val = val;
thread->ref = &thread;
}
}
/* Execute thread doing all accounting. */
- thread_call(thread);
+ event_call(thread);
/* Give back or free thread. */
thread_add_unuse(m, thread);
@@ -2133,16 +2136,13 @@ void debug_signals(const sigset_t *sigs)
}
static ssize_t printfrr_thread_dbg(struct fbuf *buf, struct printfrr_eargs *ea,
- const struct thread *thread)
-{
- static const char * const types[] = {
- [THREAD_READ] = "read",
- [THREAD_WRITE] = "write",
- [THREAD_TIMER] = "timer",
- [THREAD_EVENT] = "event",
- [THREAD_READY] = "ready",
- [THREAD_UNUSED] = "unused",
- [THREAD_EXECUTE] = "exec",
+ const struct event *thread)
+{
+ static const char *const types[] = {
+ [EVENT_READ] = "read", [EVENT_WRITE] = "write",
+ [EVENT_TIMER] = "timer", [EVENT_EVENT] = "event",
+ [EVENT_READY] = "ready", [EVENT_UNUSED] = "unused",
+ [EVENT_EXECUTE] = "exec",
};
ssize_t rv = 0;
char info[16] = "";
@@ -2158,14 +2158,19 @@ static ssize_t printfrr_thread_dbg(struct fbuf *buf, struct printfrr_eargs *ea,
rv += bprintfrr(buf, " INVALID(%u)", thread->type);
switch (thread->type) {
- case THREAD_READ:
- case THREAD_WRITE:
+ case EVENT_READ:
+ case EVENT_WRITE:
snprintfrr(info, sizeof(info), "fd=%d", thread->u.fd);
break;
- case THREAD_TIMER:
+ case EVENT_TIMER:
snprintfrr(info, sizeof(info), "r=%pTVMud", &thread->u.sands);
break;
+ case EVENT_READY:
+ case EVENT_EVENT:
+ case EVENT_UNUSED:
+ case EVENT_EXECUTE:
+ break;
}
rv += bprintfrr(buf, " %-12s %s() %s from %s:%d}", info,
@@ -2178,7 +2183,7 @@ printfrr_ext_autoreg_p("TH", printfrr_thread);
static ssize_t printfrr_thread(struct fbuf *buf, struct printfrr_eargs *ea,
const void *ptr)
{
- const struct thread *thread = ptr;
+ const struct event *thread = ptr;
struct timespec remain = {};
if (ea->fmt[0] == 'D') {
diff --git a/lib/ferr.c b/lib/ferr.c
index 5998befec2..33bcb075fa 100644
--- a/lib/ferr.c
+++ b/lib/ferr.c
@@ -180,9 +180,7 @@ void log_ref_init(void)
void log_ref_fini(void)
{
frr_with_mutex (&refs_mtx) {
- hash_clean(refs, NULL);
- hash_free(refs);
- refs = NULL;
+ hash_clean_and_free(&refs, NULL);
}
}
diff --git a/lib/filter_cli.c b/lib/filter_cli.c
index 7ef0d47f67..5c3dc5e49d 100644
--- a/lib/filter_cli.c
+++ b/lib/filter_cli.c
@@ -1272,9 +1272,6 @@ DEFPY_YANG(
pda.any = true;
}
- if (plist_is_dup(vty->candidate_config->dnode, &pda))
- return CMD_SUCCESS;
-
/*
* Create the prefix-list first, so we can generate sequence if
* none given (backward compatibility).
@@ -1326,6 +1323,7 @@ DEFPY_YANG(
vty, "./ipv4-prefix-length-lesser-or-equal",
NB_OP_DESTROY, NULL);
}
+ nb_cli_enqueue_change(vty, "./any", NB_OP_DESTROY, NULL);
} else {
nb_cli_enqueue_change(vty, "./any", NB_OP_CREATE, NULL);
}
@@ -1476,9 +1474,6 @@ DEFPY_YANG(
pda.any = true;
}
- if (plist_is_dup(vty->candidate_config->dnode, &pda))
- return CMD_SUCCESS;
-
/*
* Create the prefix-list first, so we can generate sequence if
* none given (backward compatibility).
@@ -1530,6 +1525,7 @@ DEFPY_YANG(
vty, "./ipv6-prefix-length-lesser-or-equal",
NB_OP_DESTROY, NULL);
}
+ nb_cli_enqueue_change(vty, "./any", NB_OP_DESTROY, NULL);
} else {
nb_cli_enqueue_change(vty, "./any", NB_OP_CREATE, NULL);
}
diff --git a/lib/filter_nb.c b/lib/filter_nb.c
index a14f232339..9511b8f5b5 100644
--- a/lib/filter_nb.c
+++ b/lib/filter_nb.c
@@ -456,24 +456,6 @@ bool plist_is_dup(const struct lyd_node *dnode, struct plist_dup_args *pda)
return pda->pda_found;
}
-static bool plist_is_dup_nb(const struct lyd_node *dnode)
-{
- const struct lyd_node *entry_dnode =
- yang_dnode_get_parent(dnode, "entry");
- struct plist_dup_args pda = {};
-
- /* Initialize. */
- pda.pda_type = yang_dnode_get_string(entry_dnode, "../type");
- pda.pda_name = yang_dnode_get_string(entry_dnode, "../name");
- pda.pda_action = yang_dnode_get_string(entry_dnode, "action");
- pda.pda_entry_dnode = entry_dnode;
-
- plist_dnode_to_prefix(entry_dnode, &pda.any, &pda.prefix, &pda.ge,
- &pda.le);
-
- return plist_is_dup(entry_dnode, &pda);
-}
-
/*
* XPath: /frr-filter:lib/access-list
*/
@@ -1331,13 +1313,6 @@ lib_prefix_list_entry_ipv4_prefix_modify(struct nb_cb_modify_args *args)
const struct lyd_node *plist_dnode =
yang_dnode_get_parent(args->dnode, "prefix-list");
- if (plist_is_dup_nb(args->dnode)) {
- snprintf(args->errmsg, args->errmsg_len,
- "duplicated prefix list value: %s",
- yang_dnode_get_string(args->dnode, NULL));
- return NB_ERR_VALIDATION;
- }
-
return prefix_list_nb_validate_v4_af_type(
plist_dnode, args->errmsg, args->errmsg_len);
}
@@ -1366,13 +1341,6 @@ lib_prefix_list_entry_ipv6_prefix_modify(struct nb_cb_modify_args *args)
const struct lyd_node *plist_dnode =
yang_dnode_get_parent(args->dnode, "prefix-list");
- if (plist_is_dup_nb(args->dnode)) {
- snprintf(args->errmsg, args->errmsg_len,
- "duplicated prefix list value: %s",
- yang_dnode_get_string(args->dnode, NULL));
- return NB_ERR_VALIDATION;
- }
-
return prefix_list_nb_validate_v6_af_type(
plist_dnode, args->errmsg, args->errmsg_len);
}
@@ -1404,13 +1372,6 @@ static int lib_prefix_list_entry_ipv4_prefix_length_greater_or_equal_modify(
const struct lyd_node *plist_dnode =
yang_dnode_get_parent(args->dnode, "prefix-list");
- if (plist_is_dup_nb(args->dnode)) {
- snprintf(args->errmsg, args->errmsg_len,
- "duplicated prefix list value: %s",
- yang_dnode_get_string(args->dnode, NULL));
- return NB_ERR_VALIDATION;
- }
-
return prefix_list_nb_validate_v4_af_type(
plist_dnode, args->errmsg, args->errmsg_len);
}
@@ -1448,13 +1409,6 @@ static int lib_prefix_list_entry_ipv4_prefix_length_lesser_or_equal_modify(
const struct lyd_node *plist_dnode =
yang_dnode_get_parent(args->dnode, "prefix-list");
- if (plist_is_dup_nb(args->dnode)) {
- snprintf(args->errmsg, args->errmsg_len,
- "duplicated prefix list value: %s",
- yang_dnode_get_string(args->dnode, NULL));
- return NB_ERR_VALIDATION;
- }
-
return prefix_list_nb_validate_v4_af_type(
plist_dnode, args->errmsg, args->errmsg_len);
}
@@ -1492,13 +1446,6 @@ static int lib_prefix_list_entry_ipv6_prefix_length_greater_or_equal_modify(
const struct lyd_node *plist_dnode =
yang_dnode_get_parent(args->dnode, "prefix-list");
- if (plist_is_dup_nb(args->dnode)) {
- snprintf(args->errmsg, args->errmsg_len,
- "duplicated prefix list value: %s",
- yang_dnode_get_string(args->dnode, NULL));
- return NB_ERR_VALIDATION;
- }
-
return prefix_list_nb_validate_v6_af_type(
plist_dnode, args->errmsg, args->errmsg_len);
}
@@ -1536,13 +1483,6 @@ static int lib_prefix_list_entry_ipv6_prefix_length_lesser_or_equal_modify(
const struct lyd_node *plist_dnode =
yang_dnode_get_parent(args->dnode, "prefix-list");
- if (plist_is_dup_nb(args->dnode)) {
- snprintf(args->errmsg, args->errmsg_len,
- "duplicated prefix list value: %s",
- yang_dnode_get_string(args->dnode, NULL));
- return NB_ERR_VALIDATION;
- }
-
return prefix_list_nb_validate_v6_af_type(
plist_dnode, args->errmsg, args->errmsg_len);
}
@@ -1574,16 +1514,11 @@ static int lib_prefix_list_entry_any_create(struct nb_cb_create_args *args)
struct prefix_list_entry *ple;
int type;
- if (args->event == NB_EV_VALIDATE) {
- if (plist_is_dup_nb(args->dnode)) {
- snprintf(args->errmsg, args->errmsg_len,
- "duplicated prefix list value: %s",
- yang_dnode_get_string(args->dnode, NULL));
- return NB_ERR_VALIDATION;
- }
-
+ /*
+ * If we have gotten to this point, it's legal
+ */
+ if (args->event == NB_EV_VALIDATE)
return NB_OK;
- }
if (args->event != NB_EV_APPLY)
return NB_OK;
@@ -1630,7 +1565,7 @@ static int lib_prefix_list_entry_any_destroy(struct nb_cb_destroy_args *args)
/* Start prefix entry update procedure. */
prefix_list_entry_update_start(ple);
- prefix_list_entry_set_empty(ple);
+ ple->any = false;
/* Finish prefix entry update procedure. */
prefix_list_entry_update_finish(ple);
diff --git a/lib/frr_pthread.c b/lib/frr_pthread.c
index 0c617238fa..c4ead01bf6 100644
--- a/lib/frr_pthread.c
+++ b/lib/frr_pthread.c
@@ -75,7 +75,7 @@ struct frr_pthread *frr_pthread_new(const struct frr_pthread_attr *attr,
/* initialize mutex */
pthread_mutex_init(&fpt->mtx, NULL);
/* create new thread master */
- fpt->master = thread_master_create(name);
+ fpt->master = event_master_create(name);
/* set attributes */
fpt->attr = *attr;
name = (name ? name : "Anonymous thread");
@@ -101,7 +101,7 @@ struct frr_pthread *frr_pthread_new(const struct frr_pthread_attr *attr,
static void frr_pthread_destroy_nolock(struct frr_pthread *fpt)
{
- thread_master_free(fpt->master);
+ event_master_free(fpt->master);
pthread_mutex_destroy(&fpt->mtx);
pthread_mutex_destroy(fpt->running_cond_mtx);
pthread_cond_destroy(fpt->running_cond);
@@ -224,14 +224,14 @@ void frr_pthread_stop_all(void)
*/
/* dummy task for sleeper pipe */
-static void fpt_dummy(struct thread *thread)
+static void fpt_dummy(struct event *thread)
{
}
/* poison pill task to end event loop */
-static void fpt_finish(struct thread *thread)
+static void fpt_finish(struct event *thread)
{
- struct frr_pthread *fpt = THREAD_ARG(thread);
+ struct frr_pthread *fpt = EVENT_ARG(thread);
atomic_store_explicit(&fpt->running, false, memory_order_relaxed);
}
@@ -239,7 +239,7 @@ static void fpt_finish(struct thread *thread)
/* stop function, called from other threads to halt this one */
static int fpt_halt(struct frr_pthread *fpt, void **res)
{
- thread_add_event(fpt->master, &fpt_finish, fpt, 0, NULL);
+ event_add_event(fpt->master, &fpt_finish, fpt, 0, NULL);
pthread_join(fpt->thread, res);
return 0;
@@ -281,7 +281,7 @@ static void *fpt_run(void *arg)
int sleeper[2];
pipe(sleeper);
- thread_add_read(fpt->master, &fpt_dummy, NULL, sleeper[0], NULL);
+ event_add_read(fpt->master, &fpt_dummy, NULL, sleeper[0], NULL);
fpt->master->handle_signals = false;
@@ -289,11 +289,11 @@ static void *fpt_run(void *arg)
frr_pthread_notify_running(fpt);
- struct thread task;
+ struct event task;
while (atomic_load_explicit(&fpt->running, memory_order_relaxed)) {
pthread_testcancel();
- if (thread_fetch(fpt->master, &task)) {
- thread_call(&task);
+ if (event_fetch(fpt->master, &task)) {
+ event_call(&task);
}
}
diff --git a/lib/frr_pthread.h b/lib/frr_pthread.h
index b1d08717fb..f91044dfae 100644
--- a/lib/frr_pthread.h
+++ b/lib/frr_pthread.h
@@ -11,7 +11,7 @@
#include "frratomic.h"
#include "memory.h"
#include "frrcu.h"
-#include "thread.h"
+#include "frrevent.h"
#ifdef __cplusplus
extern "C" {
@@ -41,7 +41,7 @@ struct frr_pthread {
struct rcu_thread *rcu_thread;
/* thread master for this pthread's thread.c event loop */
- struct thread_master *master;
+ struct event_loop *master;
/* caller-specified data; start & stop funcs, name, id */
struct frr_pthread_attr attr;
diff --git a/lib/frr_zmq.c b/lib/frr_zmq.c
index 2673d57605..b28dd7f1bb 100644
--- a/lib/frr_zmq.c
+++ b/lib/frr_zmq.c
@@ -15,7 +15,7 @@
#include <zebra.h>
#include <zmq.h>
-#include "thread.h"
+#include "frrevent.h"
#include "memory.h"
#include "frr_zmq.h"
#include "log.h"
@@ -43,9 +43,9 @@ void frrzmq_finish(void)
}
}
-static void frrzmq_read_msg(struct thread *t)
+static void frrzmq_read_msg(struct event *t)
{
- struct frrzmq_cb **cbp = THREAD_ARG(t);
+ struct frrzmq_cb **cbp = EVENT_ARG(t);
struct frrzmq_cb *cb;
zmq_msg_t msg;
unsigned partno;
@@ -138,8 +138,8 @@ static void frrzmq_read_msg(struct thread *t)
if (read)
frrzmq_check_events(cbp, &cb->write, ZMQ_POLLOUT);
- thread_add_read(t->master, frrzmq_read_msg, cbp,
- cb->fd, &cb->read.thread);
+ event_add_read(t->master, frrzmq_read_msg, cbp, cb->fd,
+ &cb->read.thread);
return;
out_err:
@@ -149,14 +149,13 @@ out_err:
cb->read.cb_error(cb->read.arg, cb->zmqsock);
}
-int _frrzmq_thread_add_read(const struct xref_threadsched *xref,
- struct thread_master *master,
- void (*msgfunc)(void *arg, void *zmqsock),
- void (*partfunc)(void *arg, void *zmqsock,
- zmq_msg_t *msg, unsigned partnum),
- void (*errfunc)(void *arg, void *zmqsock),
- void *arg, void *zmqsock,
- struct frrzmq_cb **cbp)
+int _frrzmq_event_add_read(const struct xref_eventsched *xref,
+ struct event_loop *master,
+ void (*msgfunc)(void *arg, void *zmqsock),
+ void (*partfunc)(void *arg, void *zmqsock,
+ zmq_msg_t *msg, unsigned partnum),
+ void (*errfunc)(void *arg, void *zmqsock), void *arg,
+ void *zmqsock, struct frrzmq_cb **cbp)
{
int fd, events;
size_t len;
@@ -191,19 +190,19 @@ int _frrzmq_thread_add_read(const struct xref_threadsched *xref,
cb->in_cb = false;
if (events & ZMQ_POLLIN) {
- thread_cancel(&cb->read.thread);
+ event_cancel(&cb->read.thread);
- thread_add_event(master, frrzmq_read_msg, cbp, fd,
- &cb->read.thread);
- } else
- thread_add_read(master, frrzmq_read_msg, cbp, fd,
+ event_add_event(master, frrzmq_read_msg, cbp, fd,
&cb->read.thread);
+ } else
+ event_add_read(master, frrzmq_read_msg, cbp, fd,
+ &cb->read.thread);
return 0;
}
-static void frrzmq_write_msg(struct thread *t)
+static void frrzmq_write_msg(struct event *t)
{
- struct frrzmq_cb **cbp = THREAD_ARG(t);
+ struct frrzmq_cb **cbp = EVENT_ARG(t);
struct frrzmq_cb *cb;
unsigned char written = 0;
int ret;
@@ -247,8 +246,8 @@ static void frrzmq_write_msg(struct thread *t)
if (written)
frrzmq_check_events(cbp, &cb->read, ZMQ_POLLIN);
- thread_add_write(t->master, frrzmq_write_msg, cbp,
- cb->fd, &cb->write.thread);
+ event_add_write(t->master, frrzmq_write_msg, cbp, cb->fd,
+ &cb->write.thread);
return;
out_err:
@@ -258,11 +257,11 @@ out_err:
cb->write.cb_error(cb->write.arg, cb->zmqsock);
}
-int _frrzmq_thread_add_write(const struct xref_threadsched *xref,
- struct thread_master *master,
- void (*msgfunc)(void *arg, void *zmqsock),
- void (*errfunc)(void *arg, void *zmqsock),
- void *arg, void *zmqsock, struct frrzmq_cb **cbp)
+int _frrzmq_event_add_write(const struct xref_eventsched *xref,
+ struct event_loop *master,
+ void (*msgfunc)(void *arg, void *zmqsock),
+ void (*errfunc)(void *arg, void *zmqsock),
+ void *arg, void *zmqsock, struct frrzmq_cb **cbp)
{
int fd, events;
size_t len;
@@ -297,13 +296,13 @@ int _frrzmq_thread_add_write(const struct xref_threadsched *xref,
cb->in_cb = false;
if (events & ZMQ_POLLOUT) {
- thread_cancel(&cb->write.thread);
+ event_cancel(&cb->write.thread);
- _thread_add_event(xref, master, frrzmq_write_msg, cbp, fd,
- &cb->write.thread);
- } else
- thread_add_write(master, frrzmq_write_msg, cbp, fd,
+ _event_add_event(xref, master, frrzmq_write_msg, cbp, fd,
&cb->write.thread);
+ } else
+ event_add_write(master, frrzmq_write_msg, cbp, fd,
+ &cb->write.thread);
return 0;
}
@@ -312,7 +311,7 @@ void frrzmq_thread_cancel(struct frrzmq_cb **cb, struct cb_core *core)
if (!cb || !*cb)
return;
core->cancelled = true;
- thread_cancel(&core->thread);
+ event_cancel(&core->thread);
/* If cancelled from within a callback, don't try to free memory
* in this path.
@@ -343,15 +342,15 @@ void frrzmq_check_events(struct frrzmq_cb **cbp, struct cb_core *core,
if (zmq_getsockopt(cb->zmqsock, ZMQ_EVENTS, &events, &len))
return;
if ((events & event) && core->thread && !core->cancelled) {
- struct thread_master *tm = core->thread->master;
+ struct event_loop *tm = core->thread->master;
- thread_cancel(&core->thread);
+ event_cancel(&core->thread);
if (event == ZMQ_POLLIN)
- thread_add_event(tm, frrzmq_read_msg,
- cbp, cb->fd, &core->thread);
+ event_add_event(tm, frrzmq_read_msg, cbp, cb->fd,
+ &core->thread);
else
- thread_add_event(tm, frrzmq_write_msg,
- cbp, cb->fd, &core->thread);
+ event_add_event(tm, frrzmq_write_msg, cbp, cb->fd,
+ &core->thread);
}
}
diff --git a/lib/frr_zmq.h b/lib/frr_zmq.h
index f12291d602..73da3770f4 100644
--- a/lib/frr_zmq.h
+++ b/lib/frr_zmq.h
@@ -7,7 +7,7 @@
#ifndef _FRRZMQ_H
#define _FRRZMQ_H
-#include "thread.h"
+#include "frrevent.h"
#include <zmq.h>
#ifdef __cplusplus
@@ -26,7 +26,7 @@ extern "C" {
/* callback integration */
struct cb_core {
- struct thread *thread;
+ struct event *thread;
void *arg;
bool cancelled;
@@ -59,30 +59,29 @@ extern void frrzmq_finish(void);
#define _xref_zmq_a(type, f, d, call) \
({ \
- static const struct xref_threadsched _xref \
- __attribute__((used)) = { \
- .xref = XREF_INIT(XREFT_THREADSCHED, NULL, __func__), \
+ static const struct xref_eventsched _xref __attribute__( \
+ (used)) = { \
+ .xref = XREF_INIT(XREFT_EVENTSCHED, NULL, __func__), \
.funcname = #f, \
.dest = #d, \
- .thread_type = THREAD_ ## type, \
+ .event_type = EVENT_##type, \
}; \
XREF_LINK(_xref.xref); \
call; \
- }) \
- /* end */
+ }) /* end */
/* core event registration, one of these 2 macros should be used */
-#define frrzmq_thread_add_read_msg(m, f, e, a, z, d) \
+#define frrzmq_event_add_read_msg(m, f, e, a, z, d) \
_xref_zmq_a(READ, f, d, \
- _frrzmq_thread_add_read(&_xref, m, f, NULL, e, a, z, d))
+ _frrzmq_event_add_read(&_xref, m, f, NULL, e, a, z, d))
-#define frrzmq_thread_add_read_part(m, f, e, a, z, d) \
+#define frrzmq_event_add_read_part(m, f, e, a, z, d) \
_xref_zmq_a(READ, f, d, \
- _frrzmq_thread_add_read(&_xref, m, NULL, f, e, a, z, d))
+ _frrzmq_event_add_read(&_xref, m, NULL, f, e, a, z, d))
-#define frrzmq_thread_add_write_msg(m, f, e, a, z, d) \
+#define frrzmq_event_add_write_msg(m, f, e, a, z, d) \
_xref_zmq_a(WRITE, f, d, \
- _frrzmq_thread_add_write(&_xref, m, f, e, a, z, d))
+ _frrzmq_event_add_write(&_xref, m, f, e, a, z, d))
struct cb_core;
struct frrzmq_cb;
@@ -108,18 +107,20 @@ struct frrzmq_cb;
* may schedule the event to run as soon as libfrr is back in its main
* loop.
*/
-extern int _frrzmq_thread_add_read(
- const struct xref_threadsched *xref, struct thread_master *master,
- void (*msgfunc)(void *arg, void *zmqsock),
- void (*partfunc)(void *arg, void *zmqsock, zmq_msg_t *msg,
- unsigned partnum),
- void (*errfunc)(void *arg, void *zmqsock), void *arg, void *zmqsock,
- struct frrzmq_cb **cb);
-extern int _frrzmq_thread_add_write(
- const struct xref_threadsched *xref, struct thread_master *master,
- void (*msgfunc)(void *arg, void *zmqsock),
- void (*errfunc)(void *arg, void *zmqsock), void *arg, void *zmqsock,
- struct frrzmq_cb **cb);
+extern int
+_frrzmq_event_add_read(const struct xref_eventsched *xref,
+ struct event_loop *master,
+ void (*msgfunc)(void *arg, void *zmqsock),
+ void (*partfunc)(void *arg, void *zmqsock,
+ zmq_msg_t *msg, unsigned partnum),
+ void (*errfunc)(void *arg, void *zmqsock), void *arg,
+ void *zmqsock, struct frrzmq_cb **cb);
+extern int _frrzmq_event_add_write(const struct xref_eventsched *xref,
+ struct event_loop *master,
+ void (*msgfunc)(void *arg, void *zmqsock),
+ void (*errfunc)(void *arg, void *zmqsock),
+ void *arg, void *zmqsock,
+ struct frrzmq_cb **cb);
extern void frrzmq_thread_cancel(struct frrzmq_cb **cb, struct cb_core *core);
diff --git a/lib/frrevent.h b/lib/frrevent.h
new file mode 100644
index 0000000000..2b0c52bb51
--- /dev/null
+++ b/lib/frrevent.h
@@ -0,0 +1,295 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/* Event management routine header.
+ * Copyright (C) 1998 Kunihiro Ishiguro
+ */
+
+#ifndef _ZEBRA_THREAD_H
+#define _ZEBRA_THREAD_H
+
+#include <zebra.h>
+#include <pthread.h>
+#include <poll.h>
+#include "monotime.h"
+#include "frratomic.h"
+#include "typesafe.h"
+#include "xref.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern bool cputime_enabled;
+extern unsigned long cputime_threshold;
+/* capturing wallclock time is always enabled since it is fast (reading
+ * hardware TSC w/o syscalls)
+ */
+extern unsigned long walltime_threshold;
+
+struct rusage_t {
+#ifdef HAVE_CLOCK_THREAD_CPUTIME_ID
+ struct timespec cpu;
+#else
+ struct rusage cpu;
+#endif
+ struct timeval real;
+};
+#define RUSAGE_T struct rusage_t
+
+#define GETRUSAGE(X) event_getrusage(X)
+
+PREDECL_LIST(event_list);
+PREDECL_HEAP(event_timer_list);
+
+struct fd_handler {
+ /* number of pfd that fit in the allocated space of pfds. This is a
+ * constant and is the same for both pfds and copy.
+ */
+ nfds_t pfdsize;
+
+ /* file descriptors to monitor for i/o */
+ struct pollfd *pfds;
+ /* number of pollfds stored in pfds */
+ nfds_t pfdcount;
+
+ /* chunk used for temp copy of pollfds */
+ struct pollfd *copy;
+ /* number of pollfds stored in copy */
+ nfds_t copycount;
+};
+
+struct xref_eventsched {
+ struct xref xref;
+
+ const char *funcname;
+ const char *dest;
+ uint32_t event_type;
+};
+
+/* Master of the theads. */
+struct event_loop {
+ char *name;
+
+ struct event **read;
+ struct event **write;
+ struct event_timer_list_head timer;
+ struct event_list_head event, ready, unuse;
+ struct list *cancel_req;
+ bool canceled;
+ pthread_cond_t cancel_cond;
+ struct hash *cpu_record;
+ int io_pipe[2];
+ int fd_limit;
+ struct fd_handler handler;
+ unsigned long alloc;
+ long selectpoll_timeout;
+ bool spin;
+ bool handle_signals;
+ pthread_mutex_t mtx;
+ pthread_t owner;
+
+ bool ready_run_loop;
+ RUSAGE_T last_getrusage;
+};
+
+/* Event types. */
+enum event_types {
+ EVENT_READ,
+ EVENT_WRITE,
+ EVENT_TIMER,
+ EVENT_EVENT,
+ EVENT_READY,
+ EVENT_UNUSED,
+ EVENT_EXECUTE,
+};
+
+/* Event itself. */
+struct event {
+ enum event_types type; /* event type */
+ enum event_types add_type; /* event type */
+ struct event_list_item eventitem;
+ struct event_timer_list_item timeritem;
+ struct event **ref; /* external reference (if given) */
+ struct event_loop *master; /* pointer to the struct event_loop */
+ void (*func)(struct event *e); /* event function */
+ void *arg; /* event argument */
+ union {
+ int val; /* second argument of the event. */
+ int fd; /* file descriptor in case of r/w */
+ struct timeval sands; /* rest of time sands value. */
+ } u;
+ struct timeval real;
+ struct cpu_event_history *hist; /* cache pointer to cpu_history */
+ unsigned long yield; /* yield time in microseconds */
+ const struct xref_eventsched *xref; /* origin location */
+ pthread_mutex_t mtx; /* mutex for thread.c functions */
+ bool ignore_timer_late;
+};
+
+#ifdef _FRR_ATTRIBUTE_PRINTFRR
+#pragma FRR printfrr_ext "%pTH"(struct event *)
+#endif
+
+struct cpu_event_history {
+ void (*func)(struct event *e);
+ atomic_size_t total_cpu_warn;
+ atomic_size_t total_wall_warn;
+ atomic_size_t total_starv_warn;
+ atomic_size_t total_calls;
+ atomic_size_t total_active;
+ struct time_stats {
+ atomic_size_t total, max;
+ } real;
+ struct time_stats cpu;
+ atomic_uint_fast32_t types;
+ const char *funcname;
+};
+
+/* Struct timeval's tv_usec one second value. */
+#define TIMER_SECOND_MICRO 1000000L
+
+/* Event yield time. */
+#define EVENT_YIELD_TIME_SLOT 10 * 1000L /* 10ms */
+
+#define EVENT_TIMER_STRLEN 12
+
+/* Macros. */
+#define EVENT_ARG(X) ((X)->arg)
+#define EVENT_FD(X) ((X)->u.fd)
+#define EVENT_VAL(X) ((X)->u.val)
+
+/*
+ * Please consider this macro deprecated, and do not use it in new code.
+ */
+#define EVENT_OFF(thread) \
+ do { \
+ if ((thread)) \
+ event_cancel(&(thread)); \
+ } while (0)
+
+/*
+ * Macro wrappers to generate xrefs for all thread add calls. Includes
+ * file/line/function info for debugging/tracing.
+ */
+#include "lib/xref.h"
+
+#define _xref_t_a(addfn, type, m, f, a, v, t) \
+ ({ \
+ static const struct xref_eventsched _xref __attribute__( \
+ (used)) = { \
+ .xref = XREF_INIT(XREFT_EVENTSCHED, NULL, __func__), \
+ .funcname = #f, \
+ .dest = #t, \
+ .event_type = EVENT_##type, \
+ }; \
+ XREF_LINK(_xref.xref); \
+ _event_add_##addfn(&_xref, m, f, a, v, t); \
+ }) /* end */
+
+#define event_add_read(m, f, a, v, t) _xref_t_a(read_write, READ, m, f, a, v, t)
+#define event_add_write(m, f, a, v, t) \
+ _xref_t_a(read_write, WRITE, m, f, a, v, t)
+#define event_add_timer(m, f, a, v, t) _xref_t_a(timer, TIMER, m, f, a, v, t)
+#define event_add_timer_msec(m, f, a, v, t) \
+ _xref_t_a(timer_msec, TIMER, m, f, a, v, t)
+#define event_add_timer_tv(m, f, a, v, t) \
+ _xref_t_a(timer_tv, TIMER, m, f, a, v, t)
+#define event_add_event(m, f, a, v, t) _xref_t_a(event, EVENT, m, f, a, v, t)
+
+#define event_execute(m, f, a, v) \
+ ({ \
+ static const struct xref_eventsched _xref __attribute__( \
+ (used)) = { \
+ .xref = XREF_INIT(XREFT_EVENTSCHED, NULL, __func__), \
+ .funcname = #f, \
+ .dest = NULL, \
+ .event_type = EVENT_EXECUTE, \
+ }; \
+ XREF_LINK(_xref.xref); \
+ _event_execute(&_xref, m, f, a, v); \
+ }) /* end */
+
+/* Prototypes. */
+extern struct event_loop *event_master_create(const char *name);
+void event_master_set_name(struct event_loop *master, const char *name);
+extern void event_master_free(struct event_loop *m);
+extern void event_master_free_unused(struct event_loop *m);
+
+extern void _event_add_read_write(const struct xref_eventsched *xref,
+ struct event_loop *master,
+ void (*fn)(struct event *), void *arg, int fd,
+ struct event **tref);
+
+extern void _event_add_timer(const struct xref_eventsched *xref,
+ struct event_loop *master,
+ void (*fn)(struct event *), void *arg, long t,
+ struct event **tref);
+
+extern void _event_add_timer_msec(const struct xref_eventsched *xref,
+ struct event_loop *master,
+ void (*fn)(struct event *), void *arg, long t,
+ struct event **tref);
+
+extern void _event_add_timer_tv(const struct xref_eventsched *xref,
+ struct event_loop *master,
+ void (*fn)(struct event *), void *arg,
+ struct timeval *tv, struct event **tref);
+
+extern void _event_add_event(const struct xref_eventsched *xref,
+ struct event_loop *master,
+ void (*fn)(struct event *), void *arg, int val,
+ struct event **tref);
+
+extern void _event_execute(const struct xref_eventsched *xref,
+ struct event_loop *master,
+ void (*fn)(struct event *), void *arg, int val);
+
+extern void event_cancel(struct event **event);
+extern void event_cancel_async(struct event_loop *m, struct event **eptr,
+ void *data);
+/* Cancel ready tasks with an arg matching 'arg' */
+extern void event_cancel_event_ready(struct event_loop *m, void *arg);
+/* Cancel all tasks with an arg matching 'arg', including timers and io */
+extern void event_cancel_event(struct event_loop *m, void *arg);
+extern struct event *event_fetch(struct event_loop *m, struct event *event);
+extern void event_call(struct event *event);
+extern unsigned long event_timer_remain_second(struct event *event);
+extern struct timeval event_timer_remain(struct event *event);
+extern unsigned long event_timer_remain_msec(struct event *event);
+extern int event_should_yield(struct event *event);
+/* set yield time for thread */
+extern void event_set_yield_time(struct event *event, unsigned long ytime);
+
+/* Internal libfrr exports */
+extern void event_getrusage(RUSAGE_T *r);
+extern void event_cmd_init(void);
+
+/* Returns elapsed real (wall clock) time. */
+extern unsigned long event_consumed_time(RUSAGE_T *after, RUSAGE_T *before,
+ unsigned long *cpu_time_elapsed);
+
+/* only for use in logging functions! */
+extern pthread_key_t thread_current;
+extern char *event_timer_to_hhmmss(char *buf, int buf_size,
+ struct event *t_timer);
+
+static inline bool event_is_scheduled(struct event *thread)
+{
+ if (thread)
+ return true;
+
+ return false;
+}
+
+/* Debug signal mask */
+void debug_signals(const sigset_t *sigs);
+
+static inline void event_ignore_late_timer(struct event *event)
+{
+ event->ignore_timer_late = true;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _ZEBRA_THREAD_H */
diff --git a/lib/frrscript.c b/lib/frrscript.c
index 4248a45002..1b99c7e2c6 100644
--- a/lib/frrscript.c
+++ b/lib/frrscript.c
@@ -398,8 +398,7 @@ fail:
void frrscript_delete(struct frrscript *fs)
{
- hash_clean(fs->lua_function_hash, lua_function_free);
- hash_free(fs->lua_function_hash);
+ hash_clean_and_free(&fs->lua_function_hash, lua_function_free);
XFREE(MTYPE_SCRIPT, fs->name);
XFREE(MTYPE_SCRIPT, fs);
}
@@ -417,8 +416,7 @@ void frrscript_init(const char *sd)
void frrscript_fini(void)
{
- hash_clean(codec_hash, codec_free);
- hash_free(codec_hash);
+ hash_clean_and_free(&codec_hash, codec_free);
frrscript_names_destroy();
}
diff --git a/lib/getopt.c b/lib/getopt.c
deleted file mode 100644
index 9d0a311310..0000000000
--- a/lib/getopt.c
+++ /dev/null
@@ -1,1011 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0-or-later
-/* Getopt for GNU.
- * NOTE: getopt is now part of the C library, so if you don't know what
- * "Keep this file name-space clean" means, talk to drepper@gnu.org
- * before changing it!
- *
- * Copyright (C) 1987, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98
- * Free Software Foundation, Inc.
- *
- * NOTE: The canonical source of this file is maintained with the GNU C Library.
- * Bugs can be reported to bug-glibc@gnu.org.
- */
-
-/* This tells Alpha OSF/1 not to define a getopt prototype in <stdio.h>.
- Ditto for AIX 3.2 and <stdlib.h>. */
-#ifndef _NO_PROTO
-# define _NO_PROTO
-#endif
-
-#include <zebra.h>
-
-#if !defined __STDC__ || !__STDC__
-/* This is a separate conditional since some stdc systems
- reject `defined (const)'. */
-#ifndef const
-# define const
-#endif
-#endif
-
-#include <stdio.h>
-
-/* Comment out all this code if we are using the GNU C Library, and are not
- actually compiling the library itself. This code is part of the GNU C
- Library, but also included in many other GNU distributions. Compiling
- and linking in this code is a waste when using the GNU C library
- (especially if it is a shared library). Rather than having every GNU
- program understand `configure --with-gnu-libc' and omit the object files,
- it is simpler to just do this in the source for each such file. */
-
-#define GETOPT_INTERFACE_VERSION 2
-#if !defined _LIBC && defined __GLIBC__ && __GLIBC__ >= 2
-#include <gnu-versions.h>
-#if _GNU_GETOPT_INTERFACE_VERSION == GETOPT_INTERFACE_VERSION
-# define ELIDE_CODE
-#endif
-#endif
-
-#ifndef ELIDE_CODE
-
-
-/* This needs to come after some library #include
- to get __GNU_LIBRARY__ defined. */
-#ifdef __GNU_LIBRARY__
-/* Don't include stdlib.h for non-GNU C libraries because some of them
- contain conflicting prototypes for getopt. */
-#include <stdlib.h>
-#include <unistd.h>
-#endif /* GNU C library. */
-
-#ifdef VMS
-#include <unixlib.h>
-#if HAVE_STRING_H - 0
-#include <string.h>
-#endif
-#endif
-
-#ifndef _
-/* This is for other GNU distributions with internationalized messages.
- When compiling libc, the _ macro is predefined. */
-#ifdef HAVE_LIBINTL_H
-#include <libintl.h>
-# define _(msgid) gettext (msgid)
-#else
-# define _(msgid) (msgid)
-#endif
-#endif
-
-/* This version of `getopt' appears to the caller like standard Unix `getopt'
- but it behaves differently for the user, since it allows the user
- to intersperse the options with the other arguments.
-
- As `getopt' works, it permutes the elements of ARGV so that,
- when it is done, all the options precede everything else. Thus
- all application programs are extended to handle flexible argument order.
-
- Setting the environment variable POSIXLY_CORRECT disables permutation.
- Then the behavior is completely standard.
-
- GNU application programs can use a third alternative mode in which
- they can distinguish the relative order of options and other arguments. */
-
-#include "getopt.h"
-
-/* For communication from `getopt' to the caller.
- When `getopt' finds an option that takes an argument,
- the argument value is returned here.
- Also, when `ordering' is RETURN_IN_ORDER,
- each non-option ARGV-element is returned here. */
-
-char *optarg = NULL;
-
-/* Index in ARGV of the next element to be scanned.
- This is used for communication to and from the caller
- and for communication between successive calls to `getopt'.
-
- On entry to `getopt', zero means this is the first call; initialize.
-
- When `getopt' returns -1, this is the index of the first of the
- non-option elements that the caller should itself scan.
-
- Otherwise, `optind' communicates from one call to the next
- how much of ARGV has been scanned so far. */
-
-/* 1003.2 says this must be 1 before any call. */
-int optind = 1;
-
-/* Formerly, initialization of getopt depended on optind==0, which
- causes problems with re-calling getopt as programs generally don't
- know that. */
-
-int __getopt_initialized = 0;
-
-/* The next char to be scanned in the option-element
- in which the last option character we returned was found.
- This allows us to pick up the scan where we left off.
-
- If this is zero, or a null string, it means resume the scan
- by advancing to the next ARGV-element. */
-
-static char *nextchar;
-
-/* Callers store zero here to inhibit the error message
- for unrecognized options. */
-
-int opterr = 1;
-
-/* Set to an option character which was unrecognized.
- This must be initialized on some systems to avoid linking in the
- system's own getopt implementation. */
-
-int optopt = '?';
-
-/* Describe how to deal with options that follow non-option ARGV-elements.
-
- If the caller did not specify anything,
- the default is REQUIRE_ORDER if the environment variable
- POSIXLY_CORRECT is defined, PERMUTE otherwise.
-
- REQUIRE_ORDER means don't recognize them as options;
- stop option processing when the first non-option is seen.
- This is what Unix does.
- This mode of operation is selected by either setting the environment
- variable POSIXLY_CORRECT, or using `+' as the first character
- of the list of option characters.
-
- PERMUTE is the default. We permute the contents of ARGV as we scan,
- so that eventually all the non-options are at the end. This allows options
- to be given in any order, even with programs that were not written to
- expect this.
-
- RETURN_IN_ORDER is an option available to programs that were written
- to expect options and other ARGV-elements in any order and that care about
- the ordering of the two. We describe each non-option ARGV-element
- as if it were the argument of an option with character code 1.
- Using `-' as the first character of the list of option characters
- selects this mode of operation.
-
- The special argument `--' forces an end of option-scanning regardless
- of the value of `ordering'. In the case of RETURN_IN_ORDER, only
- `--' can cause `getopt' to return -1 with `optind' != ARGC. */
-
-static enum { REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER } ordering;
-
-/* Value of POSIXLY_CORRECT environment variable. */
-static char *posixly_correct;
-
-#ifdef __GNU_LIBRARY__
-/* We want to avoid inclusion of string.h with non-GNU libraries
- because there are many ways it can cause trouble.
- On some systems, it contains special magic macros that don't work
- in GCC. */
-#include <string.h>
-# define my_index strchr
-#else
-
-#if HAVE_STRING_H
-#include <string.h>
-#else
-#include <strings.h>
-#endif
-
-/* Avoid depending on library functions or files
- whose names are inconsistent. */
-
-#ifndef getenv
-extern char *getenv(const char *);
-#endif
-
-static char *my_index(const char *str, int chr)
-{
- while (*str) {
- if (*str == chr)
- return (char *)str;
- str++;
- }
- return 0;
-}
-
-/* If using GCC, we can safely declare strlen this way.
- If not using GCC, it is ok not to declare it. */
-#ifdef __GNUC__
-/* Note that Motorola Delta 68k R3V7 comes with GCC but not stddef.h.
- That was relevant to code that was here before. */
-#if (!defined __STDC__ || !__STDC__) && !defined strlen
-/* gcc with -traditional declares the built-in strlen to return int,
- and has done so at least since version 2.4.5. -- rms. */
-extern int strlen(const char *);
-#endif /* not __STDC__ */
-#endif /* __GNUC__ */
-
-#endif /* not __GNU_LIBRARY__ */
-
-/* Handle permutation of arguments. */
-
-/* Describe the part of ARGV that contains non-options that have
- been skipped. `first_nonopt' is the index in ARGV of the first of them;
- `last_nonopt' is the index after the last of them. */
-
-static int first_nonopt;
-static int last_nonopt;
-
-#ifdef _LIBC
-/* Bash 2.0 gives us an environment variable containing flags
- indicating ARGV elements that should not be considered arguments. */
-
-/* Defined in getopt_init.c */
-extern char *__getopt_nonoption_flags;
-
-static int nonoption_flags_max_len;
-static int nonoption_flags_len;
-
-static int original_argc;
-static char *const *original_argv;
-
-/* Make sure the environment variable bash 2.0 puts in the environment
- is valid for the getopt call we must make sure that the ARGV passed
- to getopt is that one passed to the process. */
-static void __attribute__((unused))
-store_args_and_env(int argc, char *const *argv)
-{
- /* XXX This is no good solution. We should rather copy the args so
- that we can compare them later. But we must not use malloc(3). */
- original_argc = argc;
- original_argv = argv;
-}
-#ifdef text_set_element
-text_set_element(__libc_subinit, store_args_and_env);
-#endif /* text_set_element */
-
-#define SWAP_FLAGS(ch1, ch2) \
- if (nonoption_flags_len > 0) { \
- char __tmp = __getopt_nonoption_flags[ch1]; \
- __getopt_nonoption_flags[ch1] = __getopt_nonoption_flags[ch2]; \
- __getopt_nonoption_flags[ch2] = __tmp; \
- }
-#else /* !_LIBC */
-# define SWAP_FLAGS(ch1, ch2)
-#endif /* _LIBC */
-
-/* Exchange two adjacent subsequences of ARGV.
- One subsequence is elements [first_nonopt,last_nonopt)
- which contains all the non-options that have been skipped so far.
- The other is elements [last_nonopt,optind), which contains all
- the options processed since those non-options were skipped.
-
- `first_nonopt' and `last_nonopt' are relocated so that they describe
- the new indices of the non-options in ARGV after they are moved. */
-
-#if defined __STDC__ && __STDC__
-static void exchange(char **);
-#endif
-
-static void exchange(argv) char **argv;
-{
- int bottom = first_nonopt;
- int middle = last_nonopt;
- int top = optind;
- char *tem;
-
-/* Exchange the shorter segment with the far end of the longer segment.
- That puts the shorter segment into the right place.
- It leaves the longer segment in the right place overall,
- but it consists of two parts that need to be swapped next. */
-
-#ifdef _LIBC
- /* First make sure the handling of the `__getopt_nonoption_flags'
- string can work normally. Our top argument must be in the range
- of the string. */
- if (nonoption_flags_len > 0 && top >= nonoption_flags_max_len) {
- /* We must extend the array. The user plays games with us and
- presents new arguments. */
- char *new_str = malloc(top + 1);
- if (new_str == NULL)
- nonoption_flags_len = nonoption_flags_max_len = 0;
- else {
- memset(__mempcpy(new_str, __getopt_nonoption_flags,
- nonoption_flags_max_len),
- '\0', top + 1 - nonoption_flags_max_len);
- nonoption_flags_max_len = top + 1;
- __getopt_nonoption_flags = new_str;
- }
- }
-#endif
-
- while (top > middle && middle > bottom) {
- if (top - middle > middle - bottom) {
- /* Bottom segment is the short one. */
- int len = middle - bottom;
- register int i;
-
- /* Swap it with the top part of the top segment. */
- for (i = 0; i < len; i++) {
- tem = argv[bottom + i];
- argv[bottom + i] =
- argv[top - (middle - bottom) + i];
- argv[top - (middle - bottom) + i] = tem;
- SWAP_FLAGS(bottom + i,
- top - (middle - bottom) + i);
- }
- /* Exclude the moved bottom segment from further
- * swapping. */
- top -= len;
- } else {
- /* Top segment is the short one. */
- int len = top - middle;
- register int i;
-
- /* Swap it with the bottom part of the bottom segment.
- */
- for (i = 0; i < len; i++) {
- tem = argv[bottom + i];
- argv[bottom + i] = argv[middle + i];
- argv[middle + i] = tem;
- SWAP_FLAGS(bottom + i, middle + i);
- }
- /* Exclude the moved top segment from further swapping.
- */
- bottom += len;
- }
- }
-
- /* Update records for the slots the non-options now occupy. */
-
- first_nonopt += (optind - last_nonopt);
- last_nonopt = optind;
-}
-
-/* Initialize the internal data when the first call is made. */
-
-#if defined __STDC__ && __STDC__
-static const char *_getopt_initialize(int, char *const *, const char *);
-#endif
-static const char *_getopt_initialize(argc, argv, optstring) int argc;
-char *const *argv;
-const char *optstring;
-{
- /* Start processing options with ARGV-element 1 (since ARGV-element 0
- is the program name); the sequence of previously skipped
- non-option ARGV-elements is empty. */
-
- first_nonopt = last_nonopt = optind;
-
- nextchar = NULL;
-
- posixly_correct = getenv("POSIXLY_CORRECT");
-
- /* Determine how to handle the ordering of options and nonoptions. */
-
- if (optstring[0] == '-') {
- ordering = RETURN_IN_ORDER;
- ++optstring;
- } else if (optstring[0] == '+') {
- ordering = REQUIRE_ORDER;
- ++optstring;
- } else if (posixly_correct != NULL)
- ordering = REQUIRE_ORDER;
- else
- ordering = PERMUTE;
-
-#ifdef _LIBC
- if (posixly_correct == NULL && argc == original_argc
- && argv == original_argv) {
- if (nonoption_flags_max_len == 0) {
- if (__getopt_nonoption_flags == NULL
- || __getopt_nonoption_flags[0] == '\0')
- nonoption_flags_max_len = -1;
- else {
- const char *orig_str = __getopt_nonoption_flags;
- int len = nonoption_flags_max_len =
- strlen(orig_str);
- if (nonoption_flags_max_len < argc)
- nonoption_flags_max_len = argc;
- __getopt_nonoption_flags =
- (char *)malloc(nonoption_flags_max_len);
- if (__getopt_nonoption_flags == NULL)
- nonoption_flags_max_len = -1;
- else
- memset(__mempcpy(
- __getopt_nonoption_flags,
- orig_str, len),
- '\0',
- nonoption_flags_max_len - len);
- }
- }
- nonoption_flags_len = nonoption_flags_max_len;
- } else
- nonoption_flags_len = 0;
-#endif
-
- return optstring;
-}
-
-/* Scan elements of ARGV (whose length is ARGC) for option characters
- given in OPTSTRING.
-
- If an element of ARGV starts with '-', and is not exactly "-" or "--",
- then it is an option element. The characters of this element
- (aside from the initial '-') are option characters. If `getopt'
- is called repeatedly, it returns successively each of the option characters
- from each of the option elements.
-
- If `getopt' finds another option character, it returns that character,
- updating `optind' and `nextchar' so that the next call to `getopt' can
- resume the scan with the following option character or ARGV-element.
-
- If there are no more option characters, `getopt' returns -1.
- Then `optind' is the index in ARGV of the first ARGV-element
- that is not an option. (The ARGV-elements have been permuted
- so that those that are not options now come last.)
-
- OPTSTRING is a string containing the legitimate option characters.
- If an option character is seen that is not listed in OPTSTRING,
- return '?' after printing an error message. If you set `opterr' to
- zero, the error message is suppressed but we still return '?'.
-
- If a char in OPTSTRING is followed by a colon, that means it wants an arg,
- so the following text in the same ARGV-element, or the text of the following
- ARGV-element, is returned in `optarg'. Two colons mean an option that
- wants an optional arg; if there is text in the current ARGV-element,
- it is returned in `optarg', otherwise `optarg' is set to zero.
-
- If OPTSTRING starts with `-' or `+', it requests different methods of
- handling the non-option ARGV-elements.
- See the comments about RETURN_IN_ORDER and REQUIRE_ORDER, above.
-
- Long-named options begin with `--' instead of `-'.
- Their names may be abbreviated as long as the abbreviation is unique
- or is an exact match for some defined option. If they have an
- argument, it follows the option name in the same ARGV-element, separated
- from the option name by a `=', or else the in next ARGV-element.
- When `getopt' finds a long-named option, it returns 0 if that option's
- `flag' field is nonzero, the value of the option's `val' field
- if the `flag' field is zero.
-
- The elements of ARGV aren't really const, because we permute them.
- But we pretend they're const in the prototype to be compatible
- with other systems.
-
- LONGOPTS is a vector of `struct option' terminated by an
- element containing a name which is zero.
-
- LONGIND returns the index in LONGOPT of the long-named option found.
- It is only valid when a long-named option has been found by the most
- recent call.
-
- If LONG_ONLY is nonzero, '-' as well as '--' can introduce
- long-named options. */
-
-int _getopt_internal(argc, argv, optstring, longopts, longind,
- long_only) int argc;
-char *const *argv;
-const char *optstring;
-const struct option *longopts;
-int *longind;
-int long_only;
-{
- optarg = NULL;
-
- if (optind == 0 || !__getopt_initialized) {
- if (optind == 0)
- optind = 1; /* Don't scan ARGV[0], the program name. */
- optstring = _getopt_initialize(argc, argv, optstring);
- __getopt_initialized = 1;
- }
-
-/* Test whether ARGV[optind] points to a non-option argument.
- Either it does not have option syntax, or there is an environment flag
- from the shell indicating it is not an option. The later information
- is only used when the used in the GNU libc. */
-#ifdef _LIBC
-#define NONOPTION_P \
- (argv[optind][0] != '-' || argv[optind][1] == '\0' \
- || (optind < nonoption_flags_len \
- && __getopt_nonoption_flags[optind] == '1'))
-#else
-# define NONOPTION_P (argv[optind][0] != '-' || argv[optind][1] == '\0')
-#endif
-
- if (nextchar == NULL || *nextchar == '\0') {
- /* Advance to the next ARGV-element. */
-
- /* Give FIRST_NONOPT & LAST_NONOPT rational values if OPTIND has
- been
- moved back by the user (who may also have changed the
- arguments). */
- if (last_nonopt > optind)
- last_nonopt = optind;
- if (first_nonopt > optind)
- first_nonopt = optind;
-
- if (ordering == PERMUTE) {
- /* If we have just processed some options following some
- non-options,
- exchange them so that the options come first. */
-
- if (first_nonopt != last_nonopt
- && last_nonopt != optind)
- exchange((char **)argv);
- else if (last_nonopt != optind)
- first_nonopt = optind;
-
- /* Skip any additional non-options
- and extend the range of non-options previously
- skipped. */
-
- while (optind < argc && NONOPTION_P)
- optind++;
- last_nonopt = optind;
- }
-
- /* The special ARGV-element `--' means premature end of options.
- Skip it like a null option,
- then exchange with previous non-options as if it were an
- option,
- then skip everything else like a non-option. */
-
- if (optind != argc && !strcmp(argv[optind], "--")) {
- optind++;
-
- if (first_nonopt != last_nonopt
- && last_nonopt != optind)
- exchange((char **)argv);
- else if (first_nonopt == last_nonopt)
- first_nonopt = optind;
- last_nonopt = argc;
-
- optind = argc;
- }
-
- /* If we have done all the ARGV-elements, stop the scan
- and back over any non-options that we skipped and permuted.
- */
-
- if (optind == argc) {
- /* Set the next-arg-index to point at the non-options
- that we previously skipped, so the caller will digest
- them. */
- if (first_nonopt != last_nonopt)
- optind = first_nonopt;
- return -1;
- }
-
- /* If we have come to a non-option and did not permute it,
- either stop the scan or describe it to the caller and pass it
- by. */
-
- if (NONOPTION_P) {
- if (ordering == REQUIRE_ORDER)
- return -1;
- optarg = argv[optind++];
- return 1;
- }
-
- /* We have found another option-ARGV-element.
- Skip the initial punctuation. */
-
- nextchar = (argv[optind] + 1
- + (longopts != NULL && argv[optind][1] == '-'));
- }
-
- /* Decode the current option-ARGV-element. */
-
- /* Check whether the ARGV-element is a long option.
-
- If long_only and the ARGV-element has the form "-f", where f is
- a valid short option, don't consider it an abbreviated form of
- a long option that starts with f. Otherwise there would be no
- way to give the -f short option.
-
- On the other hand, if there's a long option "fubar" and
- the ARGV-element is "-fu", do consider that an abbreviation of
- the long option, just like "--fu", and not "-f" with arg "u".
-
- This distinction seems to be the most useful approach. */
-
- if (longopts != NULL
- && (argv[optind][1] == '-'
- || (long_only && (argv[optind][2]
- || !my_index(optstring, argv[optind][1]))))) {
- char *nameend;
- const struct option *p;
- const struct option *pfound = NULL;
- int exact = 0;
- int ambig = 0;
- int indfound = -1;
- int option_index;
-
- for (nameend = nextchar; *nameend && *nameend != '='; nameend++)
- /* Do nothing. */;
-
- /* Test all long options for either exact match
- or abbreviated matches. */
- for (p = longopts, option_index = 0; p->name;
- p++, option_index++)
- if (!strncmp(p->name, nextchar, nameend - nextchar)) {
- if ((unsigned int)(nameend - nextchar)
- == (unsigned int)strlen(p->name)) {
- /* Exact match found. */
- pfound = p;
- indfound = option_index;
- exact = 1;
- break;
- } else if (pfound == NULL) {
- /* First nonexact match found. */
- pfound = p;
- indfound = option_index;
- } else
- /* Second or later nonexact match found.
- */
- ambig = 1;
- }
-
- if (ambig && !exact) {
- if (opterr)
- fprintf(stderr,
- _("%s: option `%s' is ambiguous\n"),
- argv[0], argv[optind]);
- nextchar += strlen(nextchar);
- optind++;
- optopt = 0;
- return '?';
- }
-
- if (pfound != NULL) {
- option_index = indfound;
- optind++;
- if (*nameend) {
- /* Don't test has_arg with >, because some C
- compilers don't
- allow it to be used on enums. */
- if (pfound->has_arg)
- optarg = nameend + 1;
- else {
- if (opterr) {
- if (argv[optind - 1][1] == '-')
- /* --option */
- fprintf(stderr,
- _("%s: option `--%s' doesn't allow an argument\n"),
- argv[0],
- pfound->name);
- else
- /* +option or -option */
- fprintf(stderr,
- _("%s: option `%c%s' doesn't allow an argument\n"),
- argv[0],
- argv[optind - 1]
- [0],
- pfound->name);
- }
-
- nextchar += strlen(nextchar);
-
- optopt = pfound->val;
- return '?';
- }
- } else if (pfound->has_arg == 1) {
- if (optind < argc)
- optarg = argv[optind++];
- else {
- if (opterr)
- fprintf(stderr,
- _("%s: option `%s' requires an argument\n"),
- argv[0],
- argv[optind - 1]);
- nextchar += strlen(nextchar);
- optopt = pfound->val;
- return optstring[0] == ':' ? ':' : '?';
- }
- }
- nextchar += strlen(nextchar);
- if (longind != NULL)
- *longind = option_index;
- if (pfound->flag) {
- *(pfound->flag) = pfound->val;
- return 0;
- }
- return pfound->val;
- }
-
- /* Can't find it as a long option. If this is not
- getopt_long_only,
- or the option starts with '--' or is not a valid short
- option, then it's an error.
- Otherwise interpret it as a short option. */
- if (!long_only || argv[optind][1] == '-'
- || my_index(optstring, *nextchar) == NULL) {
- if (opterr) {
- if (argv[optind][1] == '-')
- /* --option */
- fprintf(stderr,
- _("%s: unrecognized option `--%s'\n"),
- argv[0], nextchar);
- else
- /* +option or -option */
- fprintf(stderr,
- _("%s: unrecognized option `%c%s'\n"),
- argv[0], argv[optind][0],
- nextchar);
- }
- nextchar = (char *)"";
- optind++;
- optopt = 0;
- return '?';
- }
- }
-
- /* Look at and handle the next short option-character. */
-
- {
- char c = *nextchar++;
- char *temp = my_index(optstring, c);
-
- /* Increment `optind' when we start to process its last
- * character. */
- if (*nextchar == '\0')
- ++optind;
-
- if (temp == NULL || c == ':') {
- if (opterr) {
- if (posixly_correct)
- /* 1003.2 specifies the format of this
- * message. */
- fprintf(stderr,
- _("%s: illegal option -- %c\n"),
- argv[0], c);
- else
- fprintf(stderr,
- _("%s: invalid option -- %c\n"),
- argv[0], c);
- }
- optopt = c;
- return '?';
- }
- /* Convenience. Treat POSIX -W foo same as long option --foo */
- if (temp[0] == 'W' && temp[1] == ';') {
- char *nameend;
- const struct option *p;
- const struct option *pfound = NULL;
- int exact = 0;
- int ambig = 0;
- int indfound = 0;
- int option_index;
-
- /* This is an option that requires an argument. */
- if (*nextchar != '\0') {
- optarg = nextchar;
- /* If we end this ARGV-element by taking the
- rest as an arg,
- we must advance to the next element now. */
- optind++;
- } else if (optind == argc) {
- if (opterr) {
- /* 1003.2 specifies the format of this
- * message. */
- fprintf(stderr,
- _("%s: option requires an argument -- %c\n"),
- argv[0], c);
- }
- optopt = c;
- if (optstring[0] == ':')
- c = ':';
- else
- c = '?';
- return c;
- } else
- /* We already incremented `optind' once;
- increment it again when taking next ARGV-elt
- as argument. */
- optarg = argv[optind++];
-
- /* optarg is now the argument, see if it's in the
- table of longopts. */
-
- for (nextchar = nameend = optarg;
- *nameend && *nameend != '='; nameend++)
- /* Do nothing. */;
-
- /* Test all long options for either exact match
- or abbreviated matches. */
- for (p = longopts, option_index = 0; p->name;
- p++, option_index++)
- if (!strncmp(p->name, nextchar,
- nameend - nextchar)) {
- if ((unsigned int)(nameend - nextchar)
- == strlen(p->name)) {
- /* Exact match found. */
- pfound = p;
- indfound = option_index;
- exact = 1;
- break;
- } else if (pfound == NULL) {
- /* First nonexact match found.
- */
- pfound = p;
- indfound = option_index;
- } else
- /* Second or later nonexact
- * match found. */
- ambig = 1;
- }
- if (ambig && !exact) {
- if (opterr)
- fprintf(stderr,
- _("%s: option `-W %s' is ambiguous\n"),
- argv[0], argv[optind]);
- nextchar += strlen(nextchar);
- optind++;
- return '?';
- }
- if (pfound != NULL) {
- option_index = indfound;
- if (*nameend) {
- /* Don't test has_arg with >, because
- some C compilers don't
- allow it to be used on enums. */
- if (pfound->has_arg)
- optarg = nameend + 1;
- else {
- if (opterr)
- fprintf(stderr, _("\
-%s: option `-W %s' doesn't allow an argument\n"),
- argv[0],
- pfound->name);
-
- nextchar += strlen(nextchar);
- return '?';
- }
- } else if (pfound->has_arg == 1) {
- if (optind < argc)
- optarg = argv[optind++];
- else {
- if (opterr)
- fprintf(stderr,
- _("%s: option `%s' requires an argument\n"),
- argv[0],
- argv[optind
- - 1]);
- nextchar += strlen(nextchar);
- return optstring[0] == ':'
- ? ':'
- : '?';
- }
- }
- nextchar += strlen(nextchar);
- if (longind != NULL)
- *longind = option_index;
- if (pfound->flag) {
- *(pfound->flag) = pfound->val;
- return 0;
- }
- return pfound->val;
- }
- nextchar = NULL;
- return 'W'; /* Let the application handle it. */
- }
- if (temp[1] == ':') {
- if (temp[2] == ':') {
- /* This is an option that accepts an argument
- * optionally. */
- if (*nextchar != '\0') {
- optarg = nextchar;
- optind++;
- } else
- optarg = NULL;
- nextchar = NULL;
- } else {
- /* This is an option that requires an argument.
- */
- if (*nextchar != '\0') {
- optarg = nextchar;
- /* If we end this ARGV-element by taking
- the rest as an arg,
- we must advance to the next element
- now. */
- optind++;
- } else if (optind == argc) {
- if (opterr) {
- /* 1003.2 specifies the format
- * of this message. */
- fprintf(stderr,
- _("%s: option requires an argument -- %c\n"),
- argv[0], c);
- }
- optopt = c;
- if (optstring[0] == ':')
- c = ':';
- else
- c = '?';
- } else
- /* We already incremented `optind' once;
- increment it again when taking next
- ARGV-elt as argument. */
- optarg = argv[optind++];
- nextchar = NULL;
- }
- }
- return c;
- }
-}
-
-#ifdef REALLY_NEED_PLAIN_GETOPT
-
-int getopt(argc, argv, optstring) int argc;
-char *const *argv;
-const char *optstring;
-{
- return _getopt_internal(argc, argv, optstring, (const struct option *)0,
- (int *)0, 0);
-}
-
-#endif /* REALLY_NEED_PLAIN_GETOPT */
-
-#endif /* Not ELIDE_CODE. */
-
-#ifdef TEST
-
-/* Compile with -DTEST to make an executable for use in testing
- the above definition of `getopt'. */
-
-int main(argc, argv) int argc;
-char **argv;
-{
- int c;
- int digit_optind = 0;
-
- while (1) {
- int this_option_optind = optind ? optind : 1;
-
- c = getopt(argc, argv, "abc:d:0123456789");
- if (c == -1)
- break;
-
- switch (c) {
- case '0':
- case '1':
- case '2':
- case '3':
- case '4':
- case '5':
- case '6':
- case '7':
- case '8':
- case '9':
- if (digit_optind != 0
- && digit_optind != this_option_optind)
- printf("digits occur in two different argv-elements.\n");
- digit_optind = this_option_optind;
- printf("option %c\n", c);
- break;
-
- case 'a':
- printf("option a\n");
- break;
-
- case 'b':
- printf("option b\n");
- break;
-
- case 'c':
- printf("option c with value `%s'\n", optarg);
- break;
-
- case '?':
- break;
-
- default:
- printf("?? getopt returned character code 0%o ??\n", c);
- }
- }
-
- if (optind < argc) {
- printf("non-option ARGV-elements: ");
- while (optind < argc)
- printf("%s ", argv[optind++]);
- printf("\n");
- }
-
- exit(0);
-}
-
-#endif /* TEST */
diff --git a/lib/getopt.h b/lib/getopt.h
deleted file mode 100644
index 7863bdb66a..0000000000
--- a/lib/getopt.h
+++ /dev/null
@@ -1,143 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0-or-later
-/* Declarations for getopt.
- * Copyright (C) 1989,90,91,92,93,94,96,97 Free Software Foundation, Inc.
- *
- * NOTE: The canonical source of this file is maintained with the GNU C Library.
- * Bugs can be reported to bug-glibc@gnu.org.
- */
-
-#ifndef _GETOPT_H
-#define _GETOPT_H 1
-
-/*
- * The operating system may or may not provide getopt_long(), and if
- * so it may or may not be a version we are willing to use. Our
- * strategy is to declare getopt here, and then provide code unless
- * the supplied version is adequate. The difficult case is when a
- * declaration for getopt is provided, as our declaration must match.
- *
- * XXX Arguably this version should be named differently, and the
- * local names defined to refer to the system version when we choose
- * to use the system version.
- */
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/* For communication from `getopt' to the caller.
- When `getopt' finds an option that takes an argument,
- the argument value is returned here.
- Also, when `ordering' is RETURN_IN_ORDER,
- each non-option ARGV-element is returned here. */
-
-extern char *optarg;
-
-/* Index in ARGV of the next element to be scanned.
- This is used for communication to and from the caller
- and for communication between successive calls to `getopt'.
-
- On entry to `getopt', zero means this is the first call; initialize.
-
- When `getopt' returns -1, this is the index of the first of the
- non-option elements that the caller should itself scan.
-
- Otherwise, `optind' communicates from one call to the next
- how much of ARGV has been scanned so far. */
-
-extern int optind;
-
-/* Callers store zero here to inhibit the error message `getopt' prints
- for unrecognized options. */
-
-extern int opterr;
-
-/* Set to an option character which was unrecognized. */
-
-extern int optopt;
-
-/* Describe the long-named options requested by the application.
- The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector
- of `struct option' terminated by an element containing a name which is
- zero.
-
- The field `has_arg' is:
- no_argument (or 0) if the option does not take an argument,
- required_argument (or 1) if the option requires an argument,
- optional_argument (or 2) if the option takes an optional argument.
-
- If the field `flag' is not NULL, it points to a variable that is set
- to the value given in the field `val' when the option is found, but
- left unchanged if the option is not found.
-
- To have a long-named option do something other than set an `int' to
- a compiled-in constant, such as set a value from `optarg', set the
- option's `flag' field to zero and its `val' field to a nonzero
- value (the equivalent single-letter option character, if there is
- one). For long options that have a zero `flag' field, `getopt'
- returns the contents of the `val' field. */
-
-struct option {
-#if defined(__STDC__) && __STDC__
- const char *name;
-#else
- char *name;
-#endif
- /* has_arg can't be an enum because some compilers complain about
- type mismatches in all the code that assumes it is an int. */
- int has_arg;
- int *flag;
- int val;
-};
-
-/* Names for the values of the `has_arg' field of `struct option'. */
-
-#define no_argument 0
-#define required_argument 1
-#define optional_argument 2
-
-#if defined(__STDC__) && __STDC__
-
-#ifdef REALLY_NEED_PLAIN_GETOPT
-
-/*
- * getopt is defined in POSIX.2. Assume that if the system defines
- * getopt that it complies with POSIX.2. If not, an autoconf test
- * should be written to define NONPOSIX_GETOPT_DEFINITION.
- */
-#ifndef NONPOSIX_GETOPT_DEFINITION
-extern int getopt(int argc, char *const *argv, const char *shortopts);
-#else /* NONPOSIX_GETOPT_DEFINITION */
-extern int getopt(void);
-#endif /* NONPOSIX_GETOPT_DEFINITION */
-
-#endif
-
-
-extern int getopt_long(int argc, char *const *argv, const char *shortopts,
- const struct option *longopts, int *longind);
-extern int getopt_long_only(int argc, char *const *argv, const char *shortopts,
- const struct option *longopts, int *longind);
-
-/* Internal only. Users should not call this directly. */
-extern int _getopt_internal(int argc, char *const *argv, const char *shortopts,
- const struct option *longopts, int *longind,
- int long_only);
-#else /* not __STDC__ */
-
-#ifdef REALLY_NEED_PLAIN_GETOPT
-extern int getopt();
-#endif /* REALLY_NEED_PLAIN_GETOPT */
-
-extern int getopt_long();
-extern int getopt_long_only();
-
-extern int _getopt_internal();
-
-#endif /* __STDC__ */
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* getopt.h */
diff --git a/lib/getopt1.c b/lib/getopt1.c
deleted file mode 100644
index cf21c3aab4..0000000000
--- a/lib/getopt1.c
+++ /dev/null
@@ -1,163 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0-or-later
-/* getopt_long and getopt_long_only entry points for GNU getopt.
- * Copyright (C) 1987,88,89,90,91,92,93,94,96,97,98
- * Free Software Foundation, Inc.
- *
- * NOTE: The canonical source of this file is maintained with the GNU C Library.
- * Bugs can be reported to bug-glibc@gnu.org.
- */
-
-#include <zebra.h>
-#include "getopt.h"
-
-#if !defined __STDC__ || !__STDC__
-/* This is a separate conditional since some stdc systems
- reject `defined (const)'. */
-#ifndef const
-#define const
-#endif
-#endif
-
-#include <stdio.h>
-
-/* Comment out all this code if we are using the GNU C Library, and are not
- actually compiling the library itself. This code is part of the GNU C
- Library, but also included in many other GNU distributions. Compiling
- and linking in this code is a waste when using the GNU C library
- (especially if it is a shared library). Rather than having every GNU
- program understand `configure --with-gnu-libc' and omit the object files,
- it is simpler to just do this in the source for each such file. */
-
-#define GETOPT_INTERFACE_VERSION 2
-#if !defined _LIBC && defined __GLIBC__ && __GLIBC__ >= 2
-#include <gnu-versions.h>
-#if _GNU_GETOPT_INTERFACE_VERSION == GETOPT_INTERFACE_VERSION
-#define ELIDE_CODE
-#endif
-#endif
-
-#ifndef ELIDE_CODE
-
-
-/* This needs to come after some library #include
- to get __GNU_LIBRARY__ defined. */
-#ifdef __GNU_LIBRARY__
-#include <stdlib.h>
-#endif
-
-#ifndef NULL
-#define NULL 0
-#endif
-
-int getopt_long(argc, argv, options, long_options, opt_index) int argc;
-char *const *argv;
-const char *options;
-const struct option *long_options;
-int *opt_index;
-{
- return _getopt_internal(argc, argv, options, long_options, opt_index,
- 0);
-}
-
-/* Like getopt_long, but '-' as well as '--' can indicate a long option.
- If an option that starts with '-' (not '--') doesn't match a long option,
- but does match a short option, it is parsed as a short option
- instead. */
-
-int getopt_long_only(argc, argv, options, long_options, opt_index) int argc;
-char *const *argv;
-const char *options;
-const struct option *long_options;
-int *opt_index;
-{
- return _getopt_internal(argc, argv, options, long_options, opt_index,
- 1);
-}
-
-
-#endif /* Not ELIDE_CODE. */
-
-#ifdef TEST
-
-#include <stdio.h>
-
-int main(argc, argv) int argc;
-char **argv;
-{
- int c;
- int digit_optind = 0;
-
- while (1) {
- int this_option_optind = optind ? optind : 1;
- int option_index = 0;
- static struct option long_options[] = {
- {"add", 1, 0, 0}, {"append", 0, 0, 0},
- {"delete", 1, 0, 0}, {"verbose", 0, 0, 0},
- {"create", 0, 0, 0}, {"file", 1, 0, 0},
- {0, 0, 0, 0}};
-
- c = getopt_long(argc, argv, "abc:d:0123456789", long_options,
- &option_index);
- if (c == -1)
- break;
-
- switch (c) {
- case 0:
- printf("option %s", long_options[option_index].name);
- if (optarg)
- printf(" with arg %s", optarg);
- printf("\n");
- break;
-
- case '0':
- case '1':
- case '2':
- case '3':
- case '4':
- case '5':
- case '6':
- case '7':
- case '8':
- case '9':
- if (digit_optind != 0
- && digit_optind != this_option_optind)
- printf("digits occur in two different argv-elements.\n");
- digit_optind = this_option_optind;
- printf("option %c\n", c);
- break;
-
- case 'a':
- printf("option a\n");
- break;
-
- case 'b':
- printf("option b\n");
- break;
-
- case 'c':
- printf("option c with value `%s'\n", optarg);
- break;
-
- case 'd':
- printf("option d with value `%s'\n", optarg);
- break;
-
- case '?':
- break;
-
- default:
- printf("?? getopt returned character code 0%o ??\n", c);
- }
- }
-
- if (optind < argc) {
- printf("non-option ARGV-elements: ");
- while (optind < argc)
- printf("%s ", argv[optind++]);
- printf("\n");
- }
-
- exit(0);
-}
-
-#endif /* TEST */
diff --git a/lib/grammar_sandbox_main.c b/lib/grammar_sandbox_main.c
index cdb1c3adb4..abd42f359f 100644
--- a/lib/grammar_sandbox_main.c
+++ b/lib/grammar_sandbox_main.c
@@ -23,13 +23,13 @@ static void vty_do_exit(int isexit)
exit(0);
}
-struct thread_master *master;
+struct event_loop *master;
int main(int argc, char **argv)
{
- struct thread thread;
+ struct event event;
- master = thread_master_create(NULL);
+ master = event_master_create(NULL);
zlog_aux_init("NONE: ", LOG_DEBUG);
@@ -45,8 +45,8 @@ int main(int argc, char **argv)
vty_stdio(vty_do_exit);
/* Fetch next active thread. */
- while (thread_fetch(master, &thread))
- thread_call(&thread);
+ while (event_fetch(master, &event))
+ event_call(&event);
/* Not reached. */
exit(0);
diff --git a/lib/hash.c b/lib/hash.c
index 97a77a2b9a..df56243985 100644
--- a/lib/hash.c
+++ b/lib/hash.c
@@ -297,6 +297,16 @@ void hash_clean(struct hash *hash, void (*free_func)(void *))
hash->stats.empty = hash->size;
}
+void hash_clean_and_free(struct hash **hash, void (*free_func)(void *))
+{
+ if (!*hash)
+ return;
+
+ hash_clean(*hash, free_func);
+ hash_free(*hash);
+ *hash = NULL;
+}
+
static void hash_to_list_iter(struct hash_bucket *hb, void *arg)
{
struct list *list = arg;
diff --git a/lib/hash.h b/lib/hash.h
index f32309d804..810faf9030 100644
--- a/lib/hash.h
+++ b/lib/hash.h
@@ -278,6 +278,17 @@ extern void hash_walk(struct hash *hash,
extern void hash_clean(struct hash *hash, void (*free_func)(void *));
/*
+ * Remove all elements from a hash table and free the table,
+ * setting the pointer to NULL.
+ *
+ * hash
+ * hash table to operate on
+ * free_func
+ * function to call with each removed item, intended to free the data
+ */
+extern void hash_clean_and_free(struct hash **hash, void (*free_func)(void *));
+
+/*
* Delete a hash table.
*
* This function assumes the table is empty. Call hash_clean to delete the
diff --git a/lib/if_rmap.c b/lib/if_rmap.c
index fa8899e9f8..0d305a7af1 100644
--- a/lib/if_rmap.c
+++ b/lib/if_rmap.c
@@ -10,6 +10,7 @@
#include "memory.h"
#include "if.h"
#include "if_rmap.h"
+#include "ripd/ripd.h"
DEFINE_MTYPE_STATIC(LIB, IF_RMAP_CTX, "Interface route map container");
DEFINE_MTYPE_STATIC(LIB, IF_RMAP_CTX_NAME,
@@ -186,8 +187,13 @@ DEFUN (if_rmap,
int idx_in_out = 2;
int idx_ifname = 3;
enum if_rmap_type type;
- struct if_rmap_ctx *ctx =
- (struct if_rmap_ctx *)listnode_head(if_rmap_ctx_list);
+ struct if_rmap_ctx *ctx;
+ const struct lyd_node *dnode;
+ struct rip *rip;
+
+ dnode = yang_dnode_get(running_config->dnode, VTY_CURR_XPATH);
+ rip = nb_running_get_entry(dnode, NULL, true);
+ ctx = rip->if_rmap_ctx;
if (strncmp(argv[idx_in_out]->text, "in", 1) == 0)
type = IF_RMAP_IN;
@@ -276,9 +282,9 @@ int config_write_if_rmap(struct vty *vty,
void if_rmap_ctx_delete(struct if_rmap_ctx *ctx)
{
listnode_delete(if_rmap_ctx_list, ctx);
- hash_clean(ctx->ifrmaphash, (void (*)(void *))if_rmap_free);
+ hash_clean_and_free(&ctx->ifrmaphash, (void (*)(void *))if_rmap_free);
if (ctx->name)
- XFREE(MTYPE_IF_RMAP_CTX_NAME, ctx);
+ XFREE(MTYPE_IF_RMAP_CTX_NAME, ctx->name);
XFREE(MTYPE_IF_RMAP_CTX, ctx);
}
@@ -289,8 +295,7 @@ struct if_rmap_ctx *if_rmap_ctx_create(const char *name)
ctx = XCALLOC(MTYPE_IF_RMAP_CTX, sizeof(struct if_rmap_ctx));
- if (ctx->name)
- ctx->name = XSTRDUP(MTYPE_IF_RMAP_CTX_NAME, name);
+ ctx->name = XSTRDUP(MTYPE_IF_RMAP_CTX_NAME, name);
ctx->ifrmaphash = hash_create_size(4, if_rmap_hash_make, if_rmap_hash_cmp,
"Interface Route-Map Hash");
if (!if_rmap_ctx_list)
diff --git a/lib/iso.c b/lib/iso.c
new file mode 100644
index 0000000000..fe97776ade
--- /dev/null
+++ b/lib/iso.c
@@ -0,0 +1,144 @@
+/*
+ * ISO Network functions - iso_net.c
+ *
+ * Author: Olivier Dugeon <olivier.dugeon@orange.com>
+ *
+ * Copyright (C) 2023 Orange http://www.orange.com
+ *
+ * This file is part of Free Range Routing (FRR).
+ *
+ * FRR is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2, or (at your option) any
+ * later version.
+ *
+ * FRR is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; see the file COPYING; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "compiler.h"
+
+#include <string.h>
+#include <ctype.h>
+#include <time.h>
+
+#include "printfrr.h"
+#include "iso.h"
+
+/**
+ * Print ISO System ID as 0000.0000.0000
+ *
+ * @param Print buffer
+ * @param Print argument
+ * @param Pointer to the System ID to be printed
+ *
+ * @return Number of printed characters
+ */
+printfrr_ext_autoreg_p("SY", printfrr_iso_sysid);
+static ssize_t printfrr_iso_sysid(struct fbuf *buf, struct printfrr_eargs *ea,
+ const void *vptr)
+{
+ const uint8_t *id = vptr;
+
+ if (!id)
+ return bputs(buf, "(null)");
+
+ return bprintfrr(buf, "%02x%02x.%02x%02x.%02x%02x",
+ id[0], id[1], id[2], id[3], id[4], id[5]);
+}
+
+/**
+ * Print ISO Pseudo Node system ID as 0000.0000.0000.00
+ *
+ * @param Print buffer
+ * @param Print argument
+ * @param Pointer to the System ID to be printed
+ *
+ * @return Number of printed characters
+ */
+printfrr_ext_autoreg_p("PN", printfrr_iso_pseudo);
+static ssize_t printfrr_iso_pseudo(struct fbuf *buf, struct printfrr_eargs *ea,
+ const void *vptr)
+{
+ const uint8_t *id = vptr;
+
+ if (!id)
+ return bputs(buf, "(null)");
+
+ return bprintfrr(buf, "%02x%02x.%02x%02x.%02x%02x.%02x",
+ id[0], id[1], id[2], id[3], id[4], id[5], id[6]);
+}
+
+/**
+ * Print ISO LSP Fragment System ID as 0000.0000.0000.00-00
+ *
+ * @param Print buffer
+ * @param Print argument
+ * @param Pointer to the System ID to be printed
+ *
+ * @return Number of printed characters
+ */
+printfrr_ext_autoreg_p("LS", printfrr_iso_frag_id);
+static ssize_t printfrr_iso_frag_id(struct fbuf *buf, struct printfrr_eargs *ea,
+ const void *vptr)
+{
+ const uint8_t *id = vptr;
+
+ if (!id)
+ return bputs(buf, "(null)");
+
+ return bprintfrr(buf, "%02x%02x.%02x%02x.%02x%02x.%02x-%02x",
+ id[0], id[1], id[2], id[3], id[4], id[5], id[6],
+ id[7]);
+}
+
+/**
+ * Print ISO Network address as 00.0000.0000.0000 ... with the System ID
+ * as 0000.0000.0000.00 when long 'l' option is added to '%pIS'
+ *
+ * @param Print buffer
+ * @param Print argument
+ * @param Pointer to the ISO Network address
+ *
+ * @return Number of printed characters
+ */
+printfrr_ext_autoreg_p("IS", printfrr_iso_addr);
+static ssize_t printfrr_iso_addr(struct fbuf *buf, struct printfrr_eargs *ea,
+ const void *vptr)
+{
+ const struct iso_address *ia = vptr;
+ uint8_t len = 0;
+ int i = 0;
+ ssize_t ret = 0;
+
+ if (ea->fmt[0] == 'l') {
+ len = 7; /* ISO SYSTEM ID + 1 */
+ ea->fmt++;
+ }
+
+ if (!ia)
+ return bputs(buf, "(null)");
+
+ len += ia->addr_len;
+ while (i < len) {
+ /* No dot for odd index and at the end of address */
+ if ((i & 1) || (i == (len - 1)))
+ ret += bprintfrr(buf, "%02x", ia->area_addr[i]);
+ else
+ ret += bprintfrr(buf, "%02x.", ia->area_addr[i]);
+ i++;
+ }
+
+ return ret;
+}
+
diff --git a/lib/iso.h b/lib/iso.h
new file mode 100644
index 0000000000..975d3c154b
--- /dev/null
+++ b/lib/iso.h
@@ -0,0 +1,49 @@
+/*
+ * ISO Network definition - iso_net.h
+ *
+ * Author: Olivier Dugeon <olivier.dugeon@orange.com>
+ *
+ * Copyright (C) 2023 Orange http://www.orange.com
+ *
+ * This file is part of Free Range Routing (FRR).
+ *
+ * FRR is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2, or (at your option) any
+ * later version.
+ *
+ * FRR is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; see the file COPYING; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef LIB_ISO_H_
+#define LIB_ISO_H_
+
+#include "compiler.h"
+
+/* len of "xx.xxxx.xxxx.xxxx.xxxx.xxxx.xxxx.xxxx.xxxx.xxxx.xx" + '\0' */
+#define ISO_ADDR_STRLEN 51
+#define ISO_ADDR_MIN 8
+#define ISO_ADDR_SIZE 20
+struct iso_address {
+ uint8_t addr_len;
+ uint8_t area_addr[ISO_ADDR_SIZE];
+};
+
+/* len of "xxxx.xxxx.xxxx.xx-xx" + '\0' */
+#define ISO_SYSID_STRLEN 21
+
+#ifdef _FRR_ATTRIBUTE_PRINTFRR
+#pragma FRR printfrr_ext "%pSY" (uint8_t *)
+#pragma FRR printfrr_ext "%pPN" (uint8_t *)
+#pragma FRR printfrr_ext "%pLS" (uint8_t *)
+#pragma FRR printfrr_ext "%pIS" (struct iso_address *)
+#endif
+
+#endif /* LIB_ISO_H_ */
diff --git a/lib/ldp_sync.c b/lib/ldp_sync.c
index b01cf87287..d55819dfaf 100644
--- a/lib/ldp_sync.c
+++ b/lib/ldp_sync.c
@@ -10,7 +10,7 @@
#include "memory.h"
#include "prefix.h"
#include "log.h"
-#include "thread.h"
+#include "frrevent.h"
#include "stream.h"
#include "zclient.h"
#include "table.h"
@@ -66,7 +66,7 @@ bool ldp_sync_if_down(struct ldp_sync_info *ldp_sync_info)
* update state
*/
if (ldp_sync_info && ldp_sync_info->enabled == LDP_IGP_SYNC_ENABLED) {
- THREAD_OFF(ldp_sync_info->t_holddown);
+ EVENT_OFF(ldp_sync_info->t_holddown);
if (ldp_sync_info->state == LDP_IGP_SYNC_STATE_REQUIRED_UP)
ldp_sync_info->state =
diff --git a/lib/ldp_sync.h b/lib/ldp_sync.h
index 5b6ebbf887..f7601ebf9d 100644
--- a/lib/ldp_sync.h
+++ b/lib/ldp_sync.h
@@ -37,7 +37,7 @@ struct ldp_sync_info {
uint8_t enabled; /* enabled */
uint8_t state; /* running state */
uint16_t holddown; /* timer value */
- struct thread *t_holddown; /* holddown timer*/
+ struct event *t_holddown; /* holddown timer*/
uint32_t metric[2]; /* isis interface metric */
};
diff --git a/lib/lib_vty.c b/lib/lib_vty.c
index 2c8f2e9047..c13d88a1e8 100644
--- a/lib/lib_vty.c
+++ b/lib/lib_vty.c
@@ -242,6 +242,17 @@ DEFUN_NOSH(end_config, end_config_cmd, "XFRR_end_configuration",
ret = nb_cli_pending_commit_check(vty);
zlog_info("Configuration Read in Took: %s", readin_time_str);
+ zlog_debug("%s: VTY:%p, pending SET-CFG: %u", __func__, vty,
+ (uint32_t)vty->mgmt_num_pending_setcfg);
+
+ /*
+ * If (and only if) we have sent any CLI config commands to MGMTd
+ * FE interface using vty_mgmt_send_config_data() without implicit
+ * commit before, should we need to send an explicit COMMIT-REQ now
+ * to apply all those commands at once.
+ */
+ if (vty->mgmt_num_pending_setcfg && vty_mgmt_fe_enabled())
+ vty_mgmt_send_commit_config(vty, false, false);
if (callback.end_config)
(*callback.end_config)();
diff --git a/lib/libfrr.c b/lib/libfrr.c
index d1b7dd133e..07e2eafec5 100644
--- a/lib/libfrr.c
+++ b/lib/libfrr.c
@@ -33,10 +33,10 @@
#include "frrscript.h"
#include "systemd.h"
-DEFINE_HOOK(frr_early_init, (struct thread_master * tm), (tm));
-DEFINE_HOOK(frr_late_init, (struct thread_master * tm), (tm));
-DEFINE_HOOK(frr_config_pre, (struct thread_master * tm), (tm));
-DEFINE_HOOK(frr_config_post, (struct thread_master * tm), (tm));
+DEFINE_HOOK(frr_early_init, (struct event_loop * tm), (tm));
+DEFINE_HOOK(frr_late_init, (struct event_loop * tm), (tm));
+DEFINE_HOOK(frr_config_pre, (struct event_loop * tm), (tm));
+DEFINE_HOOK(frr_config_post, (struct event_loop * tm), (tm));
DEFINE_KOOH(frr_early_fini, (), ());
DEFINE_KOOH(frr_fini, (), ());
@@ -696,8 +696,8 @@ static void _err_print(const void *cookie, const char *errstr)
fprintf(stderr, "%s: %s\n", prefix, errstr);
}
-static struct thread_master *master;
-struct thread_master *frr_init(void)
+static struct event_loop *master;
+struct event_loop *frr_init(void)
{
struct option_chain *oc;
struct log_arg *log_arg;
@@ -769,7 +769,7 @@ struct thread_master *frr_init(void)
zprivs_init(di->privs);
- master = thread_master_create(NULL);
+ master = event_master_create(NULL);
signal_init(master, di->n_signals, di->signals);
hook_call(frr_early_init, master);
@@ -964,7 +964,7 @@ static void frr_daemonize(void)
* to read the config in after thread execution starts, so that
* we can match this behavior.
*/
-static void frr_config_read_in(struct thread *t)
+static void frr_config_read_in(struct event *t)
{
hook_call(frr_config_pre, master);
@@ -1015,8 +1015,8 @@ void frr_config_fork(void)
exit(0);
}
- thread_add_event(master, frr_config_read_in, NULL, 0,
- &di->read_in);
+ event_add_event(master, frr_config_read_in, NULL, 0,
+ &di->read_in);
}
if (di->daemon_mode || di->terminal)
@@ -1095,9 +1095,9 @@ static void frr_terminal_close(int isexit)
}
}
-static struct thread *daemon_ctl_thread = NULL;
+static struct event *daemon_ctl_thread = NULL;
-static void frr_daemon_ctl(struct thread *t)
+static void frr_daemon_ctl(struct event *t)
{
char buf[1];
ssize_t nr;
@@ -1129,8 +1129,8 @@ static void frr_daemon_ctl(struct thread *t)
}
out:
- thread_add_read(master, frr_daemon_ctl, NULL, daemon_ctl_sock,
- &daemon_ctl_thread);
+ event_add_read(master, frr_daemon_ctl, NULL, daemon_ctl_sock,
+ &daemon_ctl_thread);
}
void frr_detach(void)
@@ -1139,7 +1139,7 @@ void frr_detach(void)
frr_check_detach();
}
-void frr_run(struct thread_master *master)
+void frr_run(struct event_loop *master)
{
char instanceinfo[64] = "";
@@ -1158,8 +1158,8 @@ void frr_run(struct thread_master *master)
vty_stdio(frr_terminal_close);
if (daemon_ctl_sock != -1) {
set_nonblocking(daemon_ctl_sock);
- thread_add_read(master, frr_daemon_ctl, NULL,
- daemon_ctl_sock, &daemon_ctl_thread);
+ event_add_read(master, frr_daemon_ctl, NULL,
+ daemon_ctl_sock, &daemon_ctl_thread);
}
} else if (di->daemon_mode) {
int nullfd = open("/dev/null", O_RDONLY | O_NOCTTY);
@@ -1180,9 +1180,9 @@ void frr_run(struct thread_master *master)
/* end fixed stderr startup logging */
zlog_startup_end();
- struct thread thread;
- while (thread_fetch(master, &thread))
- thread_call(&thread);
+ struct event thread;
+ while (event_fetch(master, &thread))
+ event_call(&thread);
}
void frr_early_fini(void)
@@ -1213,7 +1213,7 @@ void frr_fini(void)
frr_pthread_finish();
zprivs_terminate(di->privs);
/* signal_init -> nothing needed */
- thread_master_free(master);
+ event_master_free(master);
master = NULL;
zlog_tls_buffer_fini();
zlog_fini();
diff --git a/lib/libfrr.h b/lib/libfrr.h
index 97e9b93c10..c05bc01e4f 100644
--- a/lib/libfrr.h
+++ b/lib/libfrr.h
@@ -11,7 +11,7 @@
#include "typesafe.h"
#include "sigevent.h"
#include "privs.h"
-#include "thread.h"
+#include "frrevent.h"
#include "log.h"
#include "getopt.h"
#include "module.h"
@@ -70,7 +70,7 @@ struct frr_daemon_info {
bool terminal;
enum frr_cli_mode cli_mode;
- struct thread *read_in;
+ struct event *read_in;
const char *config_file;
const char *backup_config_file;
const char *pid_file;
@@ -133,22 +133,22 @@ extern int frr_getopt(int argc, char *const argv[], int *longindex);
extern __attribute__((__noreturn__)) void frr_help_exit(int status);
-extern struct thread_master *frr_init(void);
+extern struct event_loop *frr_init(void);
extern const char *frr_get_progname(void);
extern enum frr_cli_mode frr_get_cli_mode(void);
extern uint32_t frr_get_fd_limit(void);
extern bool frr_is_startup_fd(int fd);
/* call order of these hooks is as ordered here */
-DECLARE_HOOK(frr_early_init, (struct thread_master * tm), (tm));
-DECLARE_HOOK(frr_late_init, (struct thread_master * tm), (tm));
+DECLARE_HOOK(frr_early_init, (struct event_loop * tm), (tm));
+DECLARE_HOOK(frr_late_init, (struct event_loop * tm), (tm));
/* fork() happens between late_init and config_pre */
-DECLARE_HOOK(frr_config_pre, (struct thread_master * tm), (tm));
-DECLARE_HOOK(frr_config_post, (struct thread_master * tm), (tm));
+DECLARE_HOOK(frr_config_pre, (struct event_loop * tm), (tm));
+DECLARE_HOOK(frr_config_post, (struct event_loop * tm), (tm));
extern void frr_config_fork(void);
-extern void frr_run(struct thread_master *master);
+extern void frr_run(struct event_loop *master);
extern void frr_detach(void);
extern bool frr_zclient_addr(struct sockaddr_storage *sa, socklen_t *sa_len,
diff --git a/lib/libfrr_trace.h b/lib/libfrr_trace.h
index 92c469706a..05c958fa42 100644
--- a/lib/libfrr_trace.h
+++ b/lib/libfrr_trace.h
@@ -21,7 +21,7 @@
#include <lttng/tracepoint.h>
#include "hash.h"
-#include "thread.h"
+#include "frrevent.h"
#include "memory.h"
#include "linklist.h"
#include "table.h"
@@ -73,8 +73,8 @@ TRACEPOINT_EVENT(
TRACEPOINT_LOGLEVEL(frr_libfrr, hash_release, TRACE_INFO)
#define THREAD_SCHEDULE_ARGS \
- TP_ARGS(struct thread_master *, master, const char *, funcname, \
- const char *, schedfrom, int, fromln, struct thread **, \
+ TP_ARGS(struct event_loop *, master, const char *, funcname, \
+ const char *, schedfrom, int, fromln, struct event **, \
thread_ptr, int, fd, int, val, void *, arg, long, time)
TRACEPOINT_EVENT_CLASS(
@@ -103,9 +103,9 @@ THREAD_OPERATION_TRACEPOINT_INSTANCE(schedule_timer)
THREAD_OPERATION_TRACEPOINT_INSTANCE(schedule_event)
THREAD_OPERATION_TRACEPOINT_INSTANCE(schedule_read)
THREAD_OPERATION_TRACEPOINT_INSTANCE(schedule_write)
-THREAD_OPERATION_TRACEPOINT_INSTANCE(thread_cancel)
-THREAD_OPERATION_TRACEPOINT_INSTANCE(thread_cancel_async)
-THREAD_OPERATION_TRACEPOINT_INSTANCE(thread_call)
+THREAD_OPERATION_TRACEPOINT_INSTANCE(event_cancel)
+THREAD_OPERATION_TRACEPOINT_INSTANCE(event_cancel_async)
+THREAD_OPERATION_TRACEPOINT_INSTANCE(event_call)
TRACEPOINT_EVENT(
frr_libfrr,
diff --git a/lib/link_state.c b/lib/link_state.c
index 589c0ae704..076030a839 100644
--- a/lib/link_state.c
+++ b/lib/link_state.c
@@ -26,6 +26,7 @@
#include "printfrr.h"
#include <lib/json.h>
#include "link_state.h"
+#include "iso.h"
/* Link State Memory allocation */
DEFINE_MTYPE_STATIC(LIB, LS_DB, "Link State Database");
@@ -333,7 +334,7 @@ int ls_attributes_same(struct ls_attributes *l1, struct ls_attributes *l2)
/**
* Link State prefix management functions
*/
-struct ls_prefix *ls_prefix_new(struct ls_node_id adv, struct prefix p)
+struct ls_prefix *ls_prefix_new(struct ls_node_id adv, struct prefix *p)
{
struct ls_prefix *new;
@@ -342,7 +343,7 @@ struct ls_prefix *ls_prefix_new(struct ls_node_id adv, struct prefix p)
new = XCALLOC(MTYPE_LS_DB, sizeof(struct ls_prefix));
new->adv = adv;
- new->pref = p;
+ new->pref = *p;
return new;
}
@@ -889,7 +890,7 @@ struct ls_subnet *ls_subnet_update(struct ls_ted *ted, struct ls_prefix *pref)
if (pref == NULL)
return NULL;
- old = ls_find_subnet(ted, pref->pref);
+ old = ls_find_subnet(ted, &pref->pref);
if (old) {
if (!ls_prefix_same(old->ls_pref, pref)) {
ls_prefix_del(old->ls_pref);
@@ -942,11 +943,12 @@ void ls_subnet_del_all(struct ls_ted *ted, struct ls_subnet *subnet)
ls_subnet_del(ted, subnet);
}
-struct ls_subnet *ls_find_subnet(struct ls_ted *ted, const struct prefix prefix)
+struct ls_subnet *ls_find_subnet(struct ls_ted *ted,
+ const struct prefix *prefix)
{
struct ls_subnet subnet = {};
- subnet.key = prefix;
+ subnet.key = *prefix;
return subnets_find(&ted->subnets, &subnet);
}
@@ -1846,7 +1848,7 @@ struct ls_subnet *ls_msg2subnet(struct ls_ted *ted, struct ls_message *msg,
subnet->status = UPDATE;
break;
case LS_MSG_EVENT_DELETE:
- subnet = ls_find_subnet(ted, pref->pref);
+ subnet = ls_find_subnet(ted, &pref->pref);
if (subnet) {
if (delete)
ls_subnet_del_all(ted, subnet);
@@ -1965,13 +1967,9 @@ static const char *const status2txt[] = {
static const char *ls_node_id_to_text(struct ls_node_id lnid, char *str,
size_t size)
{
- if (lnid.origin == ISIS_L1 || lnid.origin == ISIS_L2) {
- uint8_t *id;
-
- id = lnid.id.iso.sys_id;
- snprintfrr(str, size, "%02x%02x.%02x%02x.%02x%02x", id[0],
- id[1], id[2], id[3], id[4], id[5]);
- } else
+ if (lnid.origin == ISIS_L1 || lnid.origin == ISIS_L2)
+ snprintfrr(str, size, "%pSY", lnid.id.iso.sys_id);
+ else
snprintfrr(str, size, "%pI4", &lnid.id.ip.addr);
return str;
diff --git a/lib/link_state.h b/lib/link_state.h
index e6a6388ba4..b75f035431 100644
--- a/lib/link_state.h
+++ b/lib/link_state.h
@@ -314,7 +314,7 @@ extern int ls_attributes_same(struct ls_attributes *a1,
*
* @return New Link State Prefix
*/
-extern struct ls_prefix *ls_prefix_new(struct ls_node_id adv, struct prefix p);
+extern struct ls_prefix *ls_prefix_new(struct ls_node_id adv, struct prefix *p);
/**
* Remove Link State Prefix. Data Structure is freed.
@@ -709,7 +709,7 @@ extern void ls_subnet_del_all(struct ls_ted *ted, struct ls_subnet *subnet);
* @return Subnet if found, NULL otherwise
*/
extern struct ls_subnet *ls_find_subnet(struct ls_ted *ted,
- const struct prefix prefix);
+ const struct prefix *prefix);
/**
* Create a new Link State Data Base.
diff --git a/lib/log.c b/lib/log.c
index b1a06bfb26..00b897dca1 100644
--- a/lib/log.c
+++ b/lib/log.c
@@ -140,7 +140,7 @@ void zlog_signal(int signo, const char *action, void *siginfo_v,
fb.pos = buf;
- struct thread *tc;
+ struct event *tc;
tc = pthread_getspecific(thread_current);
if (!tc)
@@ -284,7 +284,7 @@ void zlog_backtrace(int priority)
void zlog_thread_info(int log_level)
{
- struct thread *tc;
+ struct event *tc;
tc = pthread_getspecific(thread_current);
if (tc)
@@ -506,6 +506,26 @@ const char *zserv_command_string(unsigned int command)
return command_types[command].string;
}
+#define DESC_ENTRY(T) [(T)] = {(T), (#T), '\0'}
+static const struct zebra_desc_table gr_client_cap_types[] = {
+ DESC_ENTRY(ZEBRA_CLIENT_GR_CAPABILITIES),
+ DESC_ENTRY(ZEBRA_CLIENT_ROUTE_UPDATE_COMPLETE),
+ DESC_ENTRY(ZEBRA_CLIENT_ROUTE_UPDATE_PENDING),
+ DESC_ENTRY(ZEBRA_CLIENT_GR_DISABLE),
+ DESC_ENTRY(ZEBRA_CLIENT_RIB_STALE_TIME),
+};
+#undef DESC_ENTRY
+
+const char *zserv_gr_client_cap_string(uint32_t zcc)
+{
+ if (zcc >= array_size(gr_client_cap_types)) {
+ flog_err(EC_LIB_DEVELOPMENT, "unknown zserv command type: %u",
+ zcc);
+ return unknown.string;
+ }
+ return gr_client_cap_types[zcc].string;
+}
+
int proto_name2num(const char *s)
{
unsigned i;
diff --git a/lib/log.h b/lib/log.h
index b8452ac215..8a95b7a005 100644
--- a/lib/log.h
+++ b/lib/log.h
@@ -113,6 +113,7 @@ extern int proto_name2num(const char *s);
extern int proto_redistnum(int afi, const char *s);
extern const char *zserv_command_string(unsigned int command);
+extern const char *zserv_gr_client_cap_string(unsigned int zcc);
#define OSPF_LOG(level, cond, fmt, ...) \
do { \
diff --git a/lib/mgmt.proto b/lib/mgmt.proto
new file mode 100644
index 0000000000..8a11ff0fa5
--- /dev/null
+++ b/lib/mgmt.proto
@@ -0,0 +1,331 @@
+// SPDX-License-Identifier: ISC
+//
+// mgmt.proto
+//
+// @copyright Copyright (C) 2021 Vmware, Inc.
+//
+// @author Pushpasis Sarkar <spushpasis@vmware.com>
+//
+
+syntax = "proto2";
+
+//
+// Protobuf definitions pertaining to the MGMTD component.
+//
+
+package mgmtd;
+
+//
+// Common Sub-Messages
+//
+
+message YangDataXPath {
+ required string xpath = 1;
+}
+
+message YangDataValue {
+ oneof value {
+ //
+ // NOTE: For now let's use stringized value ONLY.
+ // We will enhance it later to pass native-format
+ // if needed.
+ //
+ // bool bool_val = 2;
+ // double double_val = 3;
+ // float float_val = 4;
+ // string string_val = 5;
+ // bytes bytes_val = 6;
+ // int32 int32_val = 7;
+ // int64 int64_val = 8;
+ // uint32 uint32_val = 9;
+ // uint64 uint64_val = 10;
+ // int32 int8_val = 11;
+ // uint32 uint8_val = 12;
+ // int32 int16_val = 13;
+ // uint32 uint16_val = 14;
+ string encoded_str_val = 100;
+ }
+}
+
+message YangData {
+ required string xpath = 1;
+ optional YangDataValue value = 2;
+}
+
+enum CfgDataReqType {
+ REQ_TYPE_NONE = 0;
+ SET_DATA = 1;
+ DELETE_DATA = 2;
+}
+
+message YangCfgDataReq {
+ required YangData data = 1;
+ required CfgDataReqType req_type = 2;
+}
+
+message YangGetDataReq {
+ required YangData data = 1;
+ required int64 next_indx = 2;
+}
+
+//
+// Backend Interface Messages
+//
+message BeSubscribeReq {
+ required string client_name = 1;
+ required bool subscribe_xpaths = 2;
+ repeated string xpath_reg = 3;
+}
+
+message BeSubscribeReply {
+ required bool success = 1;
+}
+
+message BeTxnReq {
+ required uint64 txn_id = 1;
+ required bool create = 2;
+}
+
+message BeTxnReply {
+ required uint64 txn_id = 1;
+ required bool create = 2;
+ required bool success = 3;
+}
+
+message BeCfgDataCreateReq {
+ required uint64 txn_id = 1;
+ required uint64 batch_id = 2;
+ repeated YangCfgDataReq data_req = 3;
+ required bool end_of_data = 4;
+}
+
+message BeCfgDataCreateReply {
+ required uint64 txn_id = 1;
+ required uint64 batch_id = 2;
+ required bool success = 3;
+ optional string error_if_any = 4;
+}
+
+message BeCfgDataApplyReq {
+ required uint64 txn_id = 1;
+}
+
+message BeCfgDataApplyReply {
+ required uint64 txn_id = 1;
+ repeated uint64 batch_ids = 2;
+ required bool success = 3;
+ optional string error_if_any = 4;
+}
+
+message BeOperDataGetReq {
+ required uint64 txn_id = 1;
+ required uint64 batch_id = 2;
+ repeated YangGetDataReq data = 3;
+}
+
+message YangDataReply {
+ repeated YangData data = 1;
+ required int64 next_indx = 2;
+}
+
+message BeOperDataGetReply {
+ required uint64 txn_id = 1;
+ required uint64 batch_id = 2;
+ required bool success = 3;
+ optional string error = 4;
+ optional YangDataReply data = 5;
+}
+
+message BeOperDataNotify {
+ required YangDataReply data = 5;
+}
+
+message BeConfigCmdReq {
+ required string cmd = 1;
+}
+
+message BeConfigCmdReply {
+ required bool success = 1;
+ required string error_if_any = 2;
+}
+
+message BeShowCmdReq {
+ required string cmd = 1;
+}
+
+message BeShowCmdReply {
+ required bool success = 1;
+ required string cmd_ouput = 2;
+}
+
+//
+// Any message on the MGMTD Backend Interface.
+//
+message BeMessage {
+ oneof message {
+ BeSubscribeReq subscr_req = 2;
+ BeSubscribeReply subscr_reply = 3;
+ BeTxnReq txn_req = 4;
+ BeTxnReply txn_reply = 5;
+ BeCfgDataCreateReq cfg_data_req = 6;
+ BeCfgDataCreateReply cfg_data_reply = 7;
+ BeCfgDataApplyReq cfg_apply_req = 8;
+ BeCfgDataApplyReply cfg_apply_reply = 9;
+ BeOperDataGetReq get_req = 10;
+ BeOperDataGetReply get_reply = 11;
+ BeOperDataNotify notify_data = 12;
+ BeConfigCmdReq cfg_cmd_req = 13;
+ BeConfigCmdReply cfg_cmd_reply = 14;
+ BeShowCmdReq show_cmd_req = 15;
+ BeShowCmdReply show_cmd_reply = 16;
+ }
+}
+
+
+//
+// Frontend Interface Messages
+//
+
+message FeRegisterReq {
+ required string client_name = 1;
+}
+
+message FeSessionReq {
+ required bool create = 1;
+ oneof id {
+ uint64 client_conn_id = 2; // Applicable for create request only
+ uint64 session_id = 3; // Applicable for delete request only
+ }
+}
+
+message FeSessionReply {
+ required bool create = 1;
+ required bool success = 2;
+ optional uint64 client_conn_id = 3; // Applicable for create request only
+ required uint64 session_id = 4;
+}
+
+enum DatastoreId {
+ DS_NONE = 0;
+ RUNNING_DS = 1;
+ CANDIDATE_DS = 2;
+ OPERATIONAL_DS = 3;
+ STARTUP_DS = 4;
+}
+
+message FeLockDsReq {
+ required uint64 session_id = 1;
+ required uint64 req_id = 2;
+ required DatastoreId ds_id = 3;
+ required bool lock = 4;
+}
+
+message FeLockDsReply {
+ required uint64 session_id = 1;
+ required uint64 req_id = 2;
+ required DatastoreId ds_id = 3;
+ required bool lock = 4;
+ required bool success = 5;
+ optional string error_if_any = 6;
+}
+
+message FeSetConfigReq {
+ required uint64 session_id = 1;
+ required DatastoreId ds_id = 2;
+ required uint64 req_id = 3;
+ repeated YangCfgDataReq data = 4;
+ required bool implicit_commit = 5;
+ required DatastoreId commit_ds_id = 6;
+}
+
+message FeSetConfigReply {
+ required uint64 session_id = 1;
+ required DatastoreId ds_id = 2;
+ required uint64 req_id = 3;
+ required bool success = 4;
+ optional string error_if_any = 5;
+}
+
+message FeCommitConfigReq {
+ required uint64 session_id = 1;
+ required DatastoreId src_ds_id = 2;
+ required DatastoreId dst_ds_id = 3;
+ required uint64 req_id = 4;
+ required bool validate_only = 5;
+ required bool abort = 6;
+}
+
+message FeCommitConfigReply {
+ required uint64 session_id = 1;
+ required DatastoreId src_ds_id = 2;
+ required DatastoreId dst_ds_id = 3;
+ required uint64 req_id = 4;
+ required bool validate_only = 5;
+ required bool success = 6;
+ required bool abort = 7;
+ optional string error_if_any = 8;
+}
+
+message FeGetConfigReq {
+ required uint64 session_id = 1;
+ required DatastoreId ds_id = 2;
+ required uint64 req_id = 3;
+ repeated YangGetDataReq data = 4;
+}
+
+message FeGetConfigReply {
+ required uint64 session_id = 1;
+ required DatastoreId ds_id = 2;
+ required uint64 req_id = 3;
+ required bool success = 4;
+ optional string error_if_any = 5;
+ optional YangDataReply data = 6;
+}
+
+message FeGetDataReq {
+ required uint64 session_id = 1;
+ required DatastoreId ds_id = 2;
+ required uint64 req_id = 3;
+ repeated YangGetDataReq data = 4;
+}
+
+message FeGetDataReply {
+ required uint64 session_id = 1;
+ required DatastoreId ds_id = 2;
+ required uint64 req_id = 3;
+ required bool success = 4;
+ optional string error_if_any = 5;
+ optional YangDataReply data = 6;
+}
+
+message FeNotifyDataReq {
+ repeated YangData data = 1;
+}
+
+message FeRegisterNotifyReq {
+ required uint64 session_id = 1;
+ required DatastoreId ds_id = 2;
+ required bool register_req = 3;
+ required uint64 req_id = 4;
+ repeated YangDataXPath data_xpath = 5;
+}
+
+message FeMessage {
+ oneof message {
+ FeRegisterReq register_req = 2;
+ FeSessionReq session_req = 3;
+ FeSessionReply session_reply = 4;
+ FeLockDsReq lockds_req = 5;
+ FeLockDsReply lockds_reply = 6;
+ FeSetConfigReq setcfg_req = 7;
+ FeSetConfigReply setcfg_reply = 8;
+ FeCommitConfigReq commcfg_req = 9;
+ FeCommitConfigReply commcfg_reply = 10;
+ FeGetConfigReq getcfg_req = 11;
+ FeGetConfigReply getcfg_reply = 12;
+ FeGetDataReq getdata_req = 13;
+ FeGetDataReply getdata_reply = 14;
+ FeNotifyDataReq notify_data_req = 15;
+ FeRegisterNotifyReq regnotify_req = 16;
+ }
+}
diff --git a/lib/mgmt_be_client.c b/lib/mgmt_be_client.c
new file mode 100644
index 0000000000..36c78052bc
--- /dev/null
+++ b/lib/mgmt_be_client.c
@@ -0,0 +1,1219 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * MGMTD Backend Client Library api interfaces
+ * Copyright (C) 2021 Vmware, Inc.
+ * Pushpasis Sarkar <spushpasis@vmware.com>
+ */
+
+#include <zebra.h>
+#include "libfrr.h"
+#include "mgmtd/mgmt.h"
+#include "mgmt_be_client.h"
+#include "mgmt_msg.h"
+#include "mgmt_pb.h"
+#include "network.h"
+#include "stream.h"
+#include "sockopt.h"
+
+#ifdef REDIRECT_DEBUG_TO_STDERR
+#define MGMTD_BE_CLIENT_DBG(fmt, ...) \
+ fprintf(stderr, "%s: " fmt "\n", __func__, ##__VA_ARGS__)
+#define MGMTD_BE_CLIENT_ERR(fmt, ...) \
+ fprintf(stderr, "%s: ERROR, " fmt "\n", __func__, ##__VA_ARGS__)
+#else /* REDIRECT_DEBUG_TO_STDERR */
+#define MGMTD_BE_CLIENT_DBG(fmt, ...) \
+ do { \
+ if (mgmt_debug_be_client) \
+ zlog_debug("%s: " fmt, __func__, ##__VA_ARGS__); \
+ } while (0)
+#define MGMTD_BE_CLIENT_ERR(fmt, ...) \
+ zlog_err("%s: ERROR: " fmt, __func__, ##__VA_ARGS__)
+#endif /* REDIRECT_DEBUG_TO_STDERR */
+
+DEFINE_MTYPE_STATIC(LIB, MGMTD_BE_BATCH,
+ "MGMTD backend transaction batch data");
+DEFINE_MTYPE_STATIC(LIB, MGMTD_BE_TXN, "MGMTD backend transaction data");
+
+enum mgmt_be_txn_event {
+ MGMTD_BE_TXN_PROC_SETCFG = 1,
+ MGMTD_BE_TXN_PROC_GETCFG,
+ MGMTD_BE_TXN_PROC_GETDATA
+};
+
+struct mgmt_be_set_cfg_req {
+ struct nb_cfg_change cfg_changes[MGMTD_MAX_CFG_CHANGES_IN_BATCH];
+ uint16_t num_cfg_changes;
+};
+
+struct mgmt_be_get_data_req {
+ char *xpaths[MGMTD_MAX_NUM_DATA_REQ_IN_BATCH];
+ uint16_t num_xpaths;
+};
+
+struct mgmt_be_txn_req {
+ enum mgmt_be_txn_event event;
+ union {
+ struct mgmt_be_set_cfg_req set_cfg;
+ struct mgmt_be_get_data_req get_data;
+ } req;
+};
+
+PREDECL_LIST(mgmt_be_batches);
+struct mgmt_be_batch_ctx {
+ /* Batch-Id as assigned by MGMTD */
+ uint64_t batch_id;
+
+ struct mgmt_be_txn_req txn_req;
+
+ uint32_t flags;
+
+ struct mgmt_be_batches_item list_linkage;
+};
+#define MGMTD_BE_BATCH_FLAGS_CFG_PREPARED (1U << 0)
+#define MGMTD_BE_TXN_FLAGS_CFG_APPLIED (1U << 1)
+DECLARE_LIST(mgmt_be_batches, struct mgmt_be_batch_ctx, list_linkage);
+
+struct mgmt_be_client_ctx;
+
+PREDECL_LIST(mgmt_be_txns);
+struct mgmt_be_txn_ctx {
+ /* Txn-Id as assigned by MGMTD */
+ uint64_t txn_id;
+ uint32_t flags;
+
+ struct mgmt_be_client_txn_ctx client_data;
+ struct mgmt_be_client_ctx *client_ctx;
+
+ /* List of batches belonging to this transaction */
+ struct mgmt_be_batches_head cfg_batches;
+ struct mgmt_be_batches_head apply_cfgs;
+
+ struct mgmt_be_txns_item list_linkage;
+
+ struct nb_transaction *nb_txn;
+ uint32_t nb_txn_id;
+};
+#define MGMTD_BE_TXN_FLAGS_CFGPREP_FAILED (1U << 1)
+
+DECLARE_LIST(mgmt_be_txns, struct mgmt_be_txn_ctx, list_linkage);
+
+#define FOREACH_BE_TXN_BATCH_IN_LIST(txn, batch) \
+ frr_each_safe (mgmt_be_batches, &(txn)->cfg_batches, (batch))
+
+#define FOREACH_BE_APPLY_BATCH_IN_LIST(txn, batch) \
+ frr_each_safe (mgmt_be_batches, &(txn)->apply_cfgs, (batch))
+
+struct mgmt_be_client_ctx {
+ int conn_fd;
+ struct event_loop *tm;
+ struct event *conn_retry_tmr;
+ struct event *conn_read_ev;
+ struct event *conn_write_ev;
+ struct event *conn_writes_on;
+ struct event *msg_proc_ev;
+ uint32_t flags;
+
+ struct mgmt_msg_state mstate;
+
+ struct nb_config *candidate_config;
+ struct nb_config *running_config;
+
+ unsigned long num_batch_find;
+ unsigned long avg_batch_find_tm;
+ unsigned long num_edit_nb_cfg;
+ unsigned long avg_edit_nb_cfg_tm;
+ unsigned long num_prep_nb_cfg;
+ unsigned long avg_prep_nb_cfg_tm;
+ unsigned long num_apply_nb_cfg;
+ unsigned long avg_apply_nb_cfg_tm;
+
+ struct mgmt_be_txns_head txn_head;
+ struct mgmt_be_client_params client_params;
+};
+
+#define MGMTD_BE_CLIENT_FLAGS_WRITES_OFF (1U << 0)
+
+#define FOREACH_BE_TXN_IN_LIST(client_ctx, txn) \
+ frr_each_safe (mgmt_be_txns, &(client_ctx)->txn_head, (txn))
+
+static bool mgmt_debug_be_client;
+
+static struct mgmt_be_client_ctx mgmt_be_client_ctx = {
+ .conn_fd = -1,
+};
+
+const char *mgmt_be_client_names[MGMTD_BE_CLIENT_ID_MAX + 1] = {
+#ifdef HAVE_STATICD
+ [MGMTD_BE_CLIENT_ID_STATICD] = "staticd",
+#endif
+ [MGMTD_BE_CLIENT_ID_MAX] = "Unknown/Invalid",
+};
+
+/* Forward declarations */
+static void
+mgmt_be_client_register_event(struct mgmt_be_client_ctx *client_ctx,
+ enum mgmt_be_event event);
+static void
+mgmt_be_client_schedule_conn_retry(struct mgmt_be_client_ctx *client_ctx,
+ unsigned long intvl_secs);
+static int mgmt_be_client_send_msg(struct mgmt_be_client_ctx *client_ctx,
+ Mgmtd__BeMessage *be_msg);
+
+static void
+mgmt_be_server_disconnect(struct mgmt_be_client_ctx *client_ctx,
+ bool reconnect)
+{
+ /* Notify client through registered callback (if any) */
+ if (client_ctx->client_params.client_connect_notify)
+ (void)(*client_ctx->client_params.client_connect_notify)(
+ (uintptr_t)client_ctx,
+ client_ctx->client_params.user_data, false);
+
+ if (client_ctx->conn_fd != -1) {
+ close(client_ctx->conn_fd);
+ client_ctx->conn_fd = -1;
+ }
+
+ if (reconnect)
+ mgmt_be_client_schedule_conn_retry(
+ client_ctx,
+ client_ctx->client_params.conn_retry_intvl_sec);
+}
+
+static struct mgmt_be_batch_ctx *
+mgmt_be_find_batch_by_id(struct mgmt_be_txn_ctx *txn,
+ uint64_t batch_id)
+{
+ struct mgmt_be_batch_ctx *batch = NULL;
+
+ FOREACH_BE_TXN_BATCH_IN_LIST (txn, batch) {
+ if (batch->batch_id == batch_id)
+ return batch;
+ }
+
+ return NULL;
+}
+
+static struct mgmt_be_batch_ctx *
+mgmt_be_batch_create(struct mgmt_be_txn_ctx *txn, uint64_t batch_id)
+{
+ struct mgmt_be_batch_ctx *batch = NULL;
+
+ batch = mgmt_be_find_batch_by_id(txn, batch_id);
+ if (!batch) {
+ batch = XCALLOC(MTYPE_MGMTD_BE_BATCH,
+ sizeof(struct mgmt_be_batch_ctx));
+ assert(batch);
+
+ batch->batch_id = batch_id;
+ mgmt_be_batches_add_tail(&txn->cfg_batches, batch);
+
+ MGMTD_BE_CLIENT_DBG("Added new batch 0x%llx to transaction",
+ (unsigned long long)batch_id);
+ }
+
+ return batch;
+}
+
+static void mgmt_be_batch_delete(struct mgmt_be_txn_ctx *txn,
+ struct mgmt_be_batch_ctx **batch)
+{
+ uint16_t indx;
+
+ if (!batch)
+ return;
+
+ mgmt_be_batches_del(&txn->cfg_batches, *batch);
+ if ((*batch)->txn_req.event == MGMTD_BE_TXN_PROC_SETCFG) {
+ for (indx = 0; indx < MGMTD_MAX_CFG_CHANGES_IN_BATCH; indx++) {
+ if ((*batch)->txn_req.req.set_cfg.cfg_changes[indx]
+ .value) {
+ free((char *)(*batch)
+ ->txn_req.req.set_cfg
+ .cfg_changes[indx]
+ .value);
+ }
+ }
+ }
+
+ XFREE(MTYPE_MGMTD_BE_BATCH, *batch);
+ *batch = NULL;
+}
+
+static void mgmt_be_cleanup_all_batches(struct mgmt_be_txn_ctx *txn)
+{
+ struct mgmt_be_batch_ctx *batch = NULL;
+
+ FOREACH_BE_TXN_BATCH_IN_LIST (txn, batch) {
+ mgmt_be_batch_delete(txn, &batch);
+ }
+
+ FOREACH_BE_APPLY_BATCH_IN_LIST (txn, batch) {
+ mgmt_be_batch_delete(txn, &batch);
+ }
+}
+
+static struct mgmt_be_txn_ctx *
+mgmt_be_find_txn_by_id(struct mgmt_be_client_ctx *client_ctx,
+ uint64_t txn_id)
+{
+ struct mgmt_be_txn_ctx *txn = NULL;
+
+ FOREACH_BE_TXN_IN_LIST (client_ctx, txn) {
+ if (txn->txn_id == txn_id)
+ return txn;
+ }
+
+ return NULL;
+}
+
+static struct mgmt_be_txn_ctx *
+mgmt_be_txn_create(struct mgmt_be_client_ctx *client_ctx,
+ uint64_t txn_id)
+{
+ struct mgmt_be_txn_ctx *txn = NULL;
+
+ txn = mgmt_be_find_txn_by_id(client_ctx, txn_id);
+ if (!txn) {
+ txn = XCALLOC(MTYPE_MGMTD_BE_TXN,
+ sizeof(struct mgmt_be_txn_ctx));
+ assert(txn);
+
+ txn->txn_id = txn_id;
+ txn->client_ctx = client_ctx;
+ mgmt_be_batches_init(&txn->cfg_batches);
+ mgmt_be_batches_init(&txn->apply_cfgs);
+ mgmt_be_txns_add_tail(&client_ctx->txn_head, txn);
+
+ MGMTD_BE_CLIENT_DBG("Added new transaction 0x%llx",
+ (unsigned long long)txn_id);
+ }
+
+ return txn;
+}
+
+static void mgmt_be_txn_delete(struct mgmt_be_client_ctx *client_ctx,
+ struct mgmt_be_txn_ctx **txn)
+{
+ char err_msg[] = "MGMT Transaction Delete";
+
+ if (!txn)
+ return;
+
+ /*
+ * Remove the transaction from the list of transactions
+ * so that future lookups with the same transaction id
+ * does not return this one.
+ */
+ mgmt_be_txns_del(&client_ctx->txn_head, *txn);
+
+ /*
+ * Time to delete the transaction which should also
+ * take care of cleaning up all batches created via
+ * CFGDATA_CREATE_REQs. But first notify the client
+ * about the transaction delete.
+ */
+ if (client_ctx->client_params.txn_notify)
+ (void)(*client_ctx->client_params
+ .txn_notify)(
+ (uintptr_t)client_ctx,
+ client_ctx->client_params.user_data,
+ &(*txn)->client_data, true);
+
+ mgmt_be_cleanup_all_batches(*txn);
+ if ((*txn)->nb_txn)
+ nb_candidate_commit_abort((*txn)->nb_txn, err_msg,
+ sizeof(err_msg));
+ XFREE(MTYPE_MGMTD_BE_TXN, *txn);
+
+ *txn = NULL;
+}
+
+static void
+mgmt_be_cleanup_all_txns(struct mgmt_be_client_ctx *client_ctx)
+{
+ struct mgmt_be_txn_ctx *txn = NULL;
+
+ FOREACH_BE_TXN_IN_LIST (client_ctx, txn) {
+ mgmt_be_txn_delete(client_ctx, &txn);
+ }
+}
+
+static int mgmt_be_send_txn_reply(struct mgmt_be_client_ctx *client_ctx,
+ uint64_t txn_id, bool create,
+ bool success)
+{
+ Mgmtd__BeMessage be_msg;
+ Mgmtd__BeTxnReply txn_reply;
+
+ mgmtd__be_txn_reply__init(&txn_reply);
+ txn_reply.create = create;
+ txn_reply.txn_id = txn_id;
+ txn_reply.success = success;
+
+ mgmtd__be_message__init(&be_msg);
+ be_msg.message_case = MGMTD__BE_MESSAGE__MESSAGE_TXN_REPLY;
+ be_msg.txn_reply = &txn_reply;
+
+ MGMTD_BE_CLIENT_DBG(
+ "Sending TXN_REPLY message to MGMTD for txn 0x%llx",
+ (unsigned long long)txn_id);
+
+ return mgmt_be_client_send_msg(client_ctx, &be_msg);
+}
+
+static int mgmt_be_process_txn_req(struct mgmt_be_client_ctx *client_ctx,
+ uint64_t txn_id, bool create)
+{
+ struct mgmt_be_txn_ctx *txn;
+
+ txn = mgmt_be_find_txn_by_id(client_ctx, txn_id);
+ if (create) {
+ if (txn) {
+ /*
+ * Transaction with same txn-id already exists.
+ * Should not happen under any circumstances.
+ */
+ MGMTD_BE_CLIENT_ERR(
+ "Transaction 0x%llx already exists!!!",
+ (unsigned long long)txn_id);
+ mgmt_be_send_txn_reply(client_ctx, txn_id, create,
+ false);
+ }
+
+ MGMTD_BE_CLIENT_DBG("Created new transaction 0x%llx",
+ (unsigned long long)txn_id);
+ txn = mgmt_be_txn_create(client_ctx, txn_id);
+
+ if (client_ctx->client_params.txn_notify)
+ (void)(*client_ctx->client_params
+ .txn_notify)(
+ (uintptr_t)client_ctx,
+ client_ctx->client_params.user_data,
+ &txn->client_data, false);
+ } else {
+ if (!txn) {
+ /*
+ * Transaction with same txn-id does not exists.
+ * Return sucess anyways.
+ */
+ MGMTD_BE_CLIENT_DBG(
+ "Transaction to delete 0x%llx does NOT exists!!!",
+ (unsigned long long)txn_id);
+ } else {
+ MGMTD_BE_CLIENT_DBG("Delete transaction 0x%llx",
+ (unsigned long long)txn_id);
+ mgmt_be_txn_delete(client_ctx, &txn);
+ }
+ }
+
+ mgmt_be_send_txn_reply(client_ctx, txn_id, create, true);
+
+ return 0;
+}
+
+static int
+mgmt_be_send_cfgdata_create_reply(struct mgmt_be_client_ctx *client_ctx,
+ uint64_t txn_id, uint64_t batch_id,
+ bool success, const char *error_if_any)
+{
+ Mgmtd__BeMessage be_msg;
+ Mgmtd__BeCfgDataCreateReply cfgdata_reply;
+
+ mgmtd__be_cfg_data_create_reply__init(&cfgdata_reply);
+ cfgdata_reply.txn_id = (uint64_t)txn_id;
+ cfgdata_reply.batch_id = (uint64_t)batch_id;
+ cfgdata_reply.success = success;
+ if (error_if_any)
+ cfgdata_reply.error_if_any = (char *)error_if_any;
+
+ mgmtd__be_message__init(&be_msg);
+ be_msg.message_case = MGMTD__BE_MESSAGE__MESSAGE_CFG_DATA_REPLY;
+ be_msg.cfg_data_reply = &cfgdata_reply;
+
+ MGMTD_BE_CLIENT_DBG(
+ "Sending CFGDATA_CREATE_REPLY message to MGMTD for txn 0x%llx batch 0x%llx",
+ (unsigned long long)txn_id, (unsigned long long)batch_id);
+
+ return mgmt_be_client_send_msg(client_ctx, &be_msg);
+}
+
+static void mgmt_be_txn_cfg_abort(struct mgmt_be_txn_ctx *txn)
+{
+ char errmsg[BUFSIZ] = {0};
+
+ assert(txn && txn->client_ctx);
+ if (txn->nb_txn) {
+ MGMTD_BE_CLIENT_ERR(
+ "Aborting configurations after prep for Txn 0x%llx",
+ (unsigned long long)txn->txn_id);
+ nb_candidate_commit_abort(txn->nb_txn, errmsg, sizeof(errmsg));
+ txn->nb_txn = 0;
+ }
+
+ /*
+ * revert candidate back to running
+ *
+ * This is one txn ctx but the candidate_config is per client ctx, how
+ * does that work?
+ */
+ MGMTD_BE_CLIENT_DBG(
+ "Reset candidate configurations after abort of Txn 0x%llx",
+ (unsigned long long)txn->txn_id);
+ nb_config_replace(txn->client_ctx->candidate_config,
+ txn->client_ctx->running_config, true);
+}
+
+static int mgmt_be_txn_cfg_prepare(struct mgmt_be_txn_ctx *txn)
+{
+ struct mgmt_be_client_ctx *client_ctx;
+ struct mgmt_be_txn_req *txn_req = NULL;
+ struct nb_context nb_ctx = {0};
+ struct timeval edit_nb_cfg_start;
+ struct timeval edit_nb_cfg_end;
+ unsigned long edit_nb_cfg_tm;
+ struct timeval prep_nb_cfg_start;
+ struct timeval prep_nb_cfg_end;
+ unsigned long prep_nb_cfg_tm;
+ struct mgmt_be_batch_ctx *batch;
+ bool error;
+ char err_buf[BUFSIZ];
+ size_t num_processed;
+ bool debug_be = mgmt_debug_be_client;
+ int err;
+
+ assert(txn && txn->client_ctx);
+ client_ctx = txn->client_ctx;
+
+ num_processed = 0;
+ FOREACH_BE_TXN_BATCH_IN_LIST (txn, batch) {
+ txn_req = &batch->txn_req;
+ error = false;
+ nb_ctx.client = NB_CLIENT_CLI;
+ nb_ctx.user = (void *)client_ctx->client_params.user_data;
+
+ if (!txn->nb_txn) {
+ /*
+ * This happens when the current backend client is only
+ * interested in consuming the config items but is not
+ * interested in validating it.
+ */
+ error = false;
+ if (debug_be)
+ gettimeofday(&edit_nb_cfg_start, NULL);
+ nb_candidate_edit_config_changes(
+ client_ctx->candidate_config,
+ txn_req->req.set_cfg.cfg_changes,
+ (size_t)txn_req->req.set_cfg.num_cfg_changes,
+ NULL, NULL, 0, err_buf, sizeof(err_buf),
+ &error);
+ if (error) {
+ err_buf[sizeof(err_buf) - 1] = 0;
+ MGMTD_BE_CLIENT_ERR(
+ "Failed to update configs for Txn %llx Batch %llx to Candidate! Err: '%s'",
+ (unsigned long long)txn->txn_id,
+ (unsigned long long)batch->batch_id,
+ err_buf);
+ return -1;
+ }
+ if (debug_be) {
+ gettimeofday(&edit_nb_cfg_end, NULL);
+ edit_nb_cfg_tm = timeval_elapsed(
+ edit_nb_cfg_end, edit_nb_cfg_start);
+ client_ctx->avg_edit_nb_cfg_tm =
+ ((client_ctx->avg_edit_nb_cfg_tm
+ * client_ctx->num_edit_nb_cfg)
+ + edit_nb_cfg_tm)
+ / (client_ctx->num_edit_nb_cfg + 1);
+ }
+ client_ctx->num_edit_nb_cfg++;
+ }
+
+ num_processed++;
+ }
+
+ if (!num_processed)
+ return 0;
+
+ /*
+ * Now prepare all the batches we have applied in one go.
+ */
+ nb_ctx.client = NB_CLIENT_CLI;
+ nb_ctx.user = (void *)client_ctx->client_params.user_data;
+ if (debug_be)
+ gettimeofday(&prep_nb_cfg_start, NULL);
+ err = nb_candidate_commit_prepare(nb_ctx, client_ctx->candidate_config,
+ "MGMTD Backend Txn", &txn->nb_txn,
+#ifdef MGMTD_LOCAL_VALIDATIONS_ENABLED
+ true, true,
+#else
+ false, true,
+#endif
+ err_buf, sizeof(err_buf) - 1);
+ if (err != NB_OK) {
+ err_buf[sizeof(err_buf) - 1] = 0;
+ if (err == NB_ERR_VALIDATION)
+ MGMTD_BE_CLIENT_ERR(
+ "Failed to validate configs for Txn %llx %u Batches! Err: '%s'",
+ (unsigned long long)txn->txn_id,
+ (uint32_t)num_processed, err_buf);
+ else
+ MGMTD_BE_CLIENT_ERR(
+ "Failed to prepare configs for Txn %llx, %u Batches! Err: '%s'",
+ (unsigned long long)txn->txn_id,
+ (uint32_t)num_processed, err_buf);
+ error = true;
+ SET_FLAG(txn->flags, MGMTD_BE_TXN_FLAGS_CFGPREP_FAILED);
+ } else
+ MGMTD_BE_CLIENT_DBG(
+ "Prepared configs for Txn %llx, %u Batches! successfully!",
+ (unsigned long long)txn->txn_id,
+ (uint32_t)num_processed);
+ if (debug_be) {
+ gettimeofday(&prep_nb_cfg_end, NULL);
+ prep_nb_cfg_tm =
+ timeval_elapsed(prep_nb_cfg_end, prep_nb_cfg_start);
+ client_ctx->avg_prep_nb_cfg_tm =
+ ((client_ctx->avg_prep_nb_cfg_tm
+ * client_ctx->num_prep_nb_cfg)
+ + prep_nb_cfg_tm)
+ / (client_ctx->num_prep_nb_cfg + 1);
+ }
+ client_ctx->num_prep_nb_cfg++;
+
+ FOREACH_BE_TXN_BATCH_IN_LIST (txn, batch) {
+ mgmt_be_send_cfgdata_create_reply(
+ client_ctx, txn->txn_id, batch->batch_id,
+ error ? false : true, error ? err_buf : NULL);
+ if (!error) {
+ SET_FLAG(batch->flags,
+ MGMTD_BE_BATCH_FLAGS_CFG_PREPARED);
+ mgmt_be_batches_del(&txn->cfg_batches, batch);
+ mgmt_be_batches_add_tail(&txn->apply_cfgs, batch);
+ }
+ }
+
+ if (debug_be)
+ MGMTD_BE_CLIENT_DBG(
+ "Avg-nb-edit-duration %lu uSec, nb-prep-duration %lu (avg: %lu) uSec, batch size %u",
+ client_ctx->avg_edit_nb_cfg_tm, prep_nb_cfg_tm,
+ client_ctx->avg_prep_nb_cfg_tm, (uint32_t)num_processed);
+
+ if (error)
+ mgmt_be_txn_cfg_abort(txn);
+
+ return 0;
+}
+
+/*
+ * Process all CFG_DATA_REQs received so far and prepare them all in one go.
+ */
+static int
+mgmt_be_update_setcfg_in_batch(struct mgmt_be_client_ctx *client_ctx,
+ struct mgmt_be_txn_ctx *txn,
+ uint64_t batch_id,
+ Mgmtd__YangCfgDataReq * cfg_req[],
+ int num_req)
+{
+ struct mgmt_be_batch_ctx *batch = NULL;
+ struct mgmt_be_txn_req *txn_req = NULL;
+ int index;
+ struct nb_cfg_change *cfg_chg;
+
+ batch = mgmt_be_batch_create(txn, batch_id);
+ if (!batch) {
+ MGMTD_BE_CLIENT_ERR("Batch create failed!");
+ return -1;
+ }
+
+ txn_req = &batch->txn_req;
+ txn_req->event = MGMTD_BE_TXN_PROC_SETCFG;
+ MGMTD_BE_CLIENT_DBG(
+ "Created Set-Config request for batch 0x%llx, txn id 0x%llx, cfg-items:%d",
+ (unsigned long long)batch_id, (unsigned long long)txn->txn_id,
+ num_req);
+
+ txn_req->req.set_cfg.num_cfg_changes = num_req;
+ for (index = 0; index < num_req; index++) {
+ cfg_chg = &txn_req->req.set_cfg.cfg_changes[index];
+
+ if (cfg_req[index]->req_type
+ == MGMTD__CFG_DATA_REQ_TYPE__DELETE_DATA)
+ cfg_chg->operation = NB_OP_DESTROY;
+ else
+ cfg_chg->operation = NB_OP_CREATE;
+
+ strlcpy(cfg_chg->xpath, cfg_req[index]->data->xpath,
+ sizeof(cfg_chg->xpath));
+ cfg_chg->value = (cfg_req[index]->data->value
+ && cfg_req[index]
+ ->data->value
+ ->encoded_str_val
+ ? strdup(cfg_req[index]
+ ->data->value
+ ->encoded_str_val)
+ : NULL);
+ if (cfg_chg->value
+ && !strncmp(cfg_chg->value, MGMTD_BE_CONTAINER_NODE_VAL,
+ strlen(MGMTD_BE_CONTAINER_NODE_VAL))) {
+ free((char *)cfg_chg->value);
+ cfg_chg->value = NULL;
+ }
+ }
+
+ return 0;
+}
+
+static int
+mgmt_be_process_cfgdata_req(struct mgmt_be_client_ctx *client_ctx,
+ uint64_t txn_id, uint64_t batch_id,
+ Mgmtd__YangCfgDataReq * cfg_req[], int num_req,
+ bool end_of_data)
+{
+ struct mgmt_be_txn_ctx *txn;
+
+ txn = mgmt_be_find_txn_by_id(client_ctx, txn_id);
+ if (!txn) {
+ MGMTD_BE_CLIENT_ERR(
+ "Invalid txn-id 0x%llx provided from MGMTD server",
+ (unsigned long long)txn_id);
+ mgmt_be_send_cfgdata_create_reply(
+ client_ctx, txn_id, batch_id, false,
+ "Transaction context not created yet");
+ } else {
+ mgmt_be_update_setcfg_in_batch(client_ctx, txn, batch_id,
+ cfg_req, num_req);
+ }
+
+ if (txn && end_of_data) {
+ MGMTD_BE_CLIENT_DBG("Triggering CFG_PREPARE_REQ processing");
+ mgmt_be_txn_cfg_prepare(txn);
+ }
+
+ return 0;
+}
+
+static int mgmt_be_send_apply_reply(struct mgmt_be_client_ctx *client_ctx,
+ uint64_t txn_id, uint64_t batch_ids[],
+ size_t num_batch_ids, bool success,
+ const char *error_if_any)
+{
+ Mgmtd__BeMessage be_msg;
+ Mgmtd__BeCfgDataApplyReply apply_reply;
+
+ mgmtd__be_cfg_data_apply_reply__init(&apply_reply);
+ apply_reply.success = success;
+ apply_reply.txn_id = txn_id;
+ apply_reply.batch_ids = (uint64_t *)batch_ids;
+ apply_reply.n_batch_ids = num_batch_ids;
+
+ if (error_if_any)
+ apply_reply.error_if_any = (char *)error_if_any;
+
+ mgmtd__be_message__init(&be_msg);
+ be_msg.message_case = MGMTD__BE_MESSAGE__MESSAGE_CFG_APPLY_REPLY;
+ be_msg.cfg_apply_reply = &apply_reply;
+
+ MGMTD_BE_CLIENT_DBG(
+ "Sending CFG_APPLY_REPLY message to MGMTD for txn 0x%llx, %d batches [0x%llx - 0x%llx]",
+ (unsigned long long)txn_id, (int)num_batch_ids,
+ success && num_batch_ids ?
+ (unsigned long long)batch_ids[0] : 0,
+ success && num_batch_ids ?
+ (unsigned long long)batch_ids[num_batch_ids - 1] : 0);
+
+ return mgmt_be_client_send_msg(client_ctx, &be_msg);
+}
+
+static int mgmt_be_txn_proc_cfgapply(struct mgmt_be_txn_ctx *txn)
+{
+ struct mgmt_be_client_ctx *client_ctx;
+ struct timeval apply_nb_cfg_start;
+ struct timeval apply_nb_cfg_end;
+ unsigned long apply_nb_cfg_tm;
+ struct mgmt_be_batch_ctx *batch;
+ char err_buf[BUFSIZ];
+ size_t num_processed;
+ static uint64_t batch_ids[MGMTD_BE_MAX_BATCH_IDS_IN_REQ];
+ bool debug_be = mgmt_debug_be_client;
+
+ assert(txn && txn->client_ctx);
+ client_ctx = txn->client_ctx;
+
+ assert(txn->nb_txn);
+ num_processed = 0;
+
+ /*
+ * Now apply all the batches we have applied in one go.
+ */
+ if (debug_be)
+ gettimeofday(&apply_nb_cfg_start, NULL);
+ (void)nb_candidate_commit_apply(txn->nb_txn, true, &txn->nb_txn_id,
+ err_buf, sizeof(err_buf) - 1);
+ if (debug_be) {
+ gettimeofday(&apply_nb_cfg_end, NULL);
+ apply_nb_cfg_tm =
+ timeval_elapsed(apply_nb_cfg_end, apply_nb_cfg_start);
+ client_ctx->avg_apply_nb_cfg_tm =
+ ((client_ctx->avg_apply_nb_cfg_tm
+ * client_ctx->num_apply_nb_cfg)
+ + apply_nb_cfg_tm)
+ / (client_ctx->num_apply_nb_cfg + 1);
+ }
+ client_ctx->num_apply_nb_cfg++;
+ txn->nb_txn = NULL;
+
+ /*
+ * Send back CFG_APPLY_REPLY for all batches applied.
+ */
+ FOREACH_BE_APPLY_BATCH_IN_LIST (txn, batch) {
+ /*
+ * No need to delete the batch yet. Will be deleted during
+ * transaction cleanup on receiving TXN_DELETE_REQ.
+ */
+ SET_FLAG(batch->flags, MGMTD_BE_TXN_FLAGS_CFG_APPLIED);
+ mgmt_be_batches_del(&txn->apply_cfgs, batch);
+ mgmt_be_batches_add_tail(&txn->cfg_batches, batch);
+
+ batch_ids[num_processed] = batch->batch_id;
+ num_processed++;
+ if (num_processed == MGMTD_BE_MAX_BATCH_IDS_IN_REQ) {
+ mgmt_be_send_apply_reply(client_ctx, txn->txn_id,
+ batch_ids, num_processed,
+ true, NULL);
+ num_processed = 0;
+ }
+ }
+
+ mgmt_be_send_apply_reply(client_ctx, txn->txn_id, batch_ids,
+ num_processed, true, NULL);
+
+ if (debug_be)
+ MGMTD_BE_CLIENT_DBG("Nb-apply-duration %lu (avg: %lu) uSec",
+ apply_nb_cfg_tm,
+ client_ctx->avg_apply_nb_cfg_tm);
+
+ return 0;
+}
+
+static int
+mgmt_be_process_cfg_apply(struct mgmt_be_client_ctx *client_ctx,
+ uint64_t txn_id)
+{
+ struct mgmt_be_txn_ctx *txn;
+
+ txn = mgmt_be_find_txn_by_id(client_ctx, txn_id);
+ if (!txn) {
+ mgmt_be_send_apply_reply(client_ctx, txn_id, NULL, 0, false,
+ "Transaction not created yet!");
+ return -1;
+ }
+
+ MGMTD_BE_CLIENT_DBG("Trigger CFG_APPLY_REQ processing");
+ mgmt_be_txn_proc_cfgapply(txn);
+
+ return 0;
+}
+
+static int
+mgmt_be_client_handle_msg(struct mgmt_be_client_ctx *client_ctx,
+ Mgmtd__BeMessage *be_msg)
+{
+ /*
+ * protobuf-c adds a max size enum with an internal, and changing by
+ * version, name; cast to an int to avoid unhandled enum warnings
+ */
+ switch ((int)be_msg->message_case) {
+ case MGMTD__BE_MESSAGE__MESSAGE_SUBSCR_REPLY:
+ MGMTD_BE_CLIENT_DBG("Subscribe Reply Msg from mgmt, status %u",
+ be_msg->subscr_reply->success);
+ break;
+ case MGMTD__BE_MESSAGE__MESSAGE_TXN_REQ:
+ mgmt_be_process_txn_req(client_ctx,
+ be_msg->txn_req->txn_id,
+ be_msg->txn_req->create);
+ break;
+ case MGMTD__BE_MESSAGE__MESSAGE_CFG_DATA_REQ:
+ mgmt_be_process_cfgdata_req(
+ client_ctx, be_msg->cfg_data_req->txn_id,
+ be_msg->cfg_data_req->batch_id,
+ be_msg->cfg_data_req->data_req,
+ be_msg->cfg_data_req->n_data_req,
+ be_msg->cfg_data_req->end_of_data);
+ break;
+ case MGMTD__BE_MESSAGE__MESSAGE_CFG_APPLY_REQ:
+ mgmt_be_process_cfg_apply(
+ client_ctx, (uint64_t)be_msg->cfg_apply_req->txn_id);
+ break;
+ case MGMTD__BE_MESSAGE__MESSAGE_GET_REQ:
+ case MGMTD__BE_MESSAGE__MESSAGE_SUBSCR_REQ:
+ case MGMTD__BE_MESSAGE__MESSAGE_CFG_CMD_REQ:
+ case MGMTD__BE_MESSAGE__MESSAGE_SHOW_CMD_REQ:
+ /*
+ * TODO: Add handling code in future.
+ */
+ break;
+ /*
+ * NOTE: The following messages are always sent from Backend
+ * clients to MGMTd only and/or need not be handled here.
+ */
+ case MGMTD__BE_MESSAGE__MESSAGE_GET_REPLY:
+ case MGMTD__BE_MESSAGE__MESSAGE_TXN_REPLY:
+ case MGMTD__BE_MESSAGE__MESSAGE_CFG_DATA_REPLY:
+ case MGMTD__BE_MESSAGE__MESSAGE_CFG_APPLY_REPLY:
+ case MGMTD__BE_MESSAGE__MESSAGE_CFG_CMD_REPLY:
+ case MGMTD__BE_MESSAGE__MESSAGE_SHOW_CMD_REPLY:
+ case MGMTD__BE_MESSAGE__MESSAGE_NOTIFY_DATA:
+ case MGMTD__BE_MESSAGE__MESSAGE__NOT_SET:
+ default:
+ /*
+ * A 'default' case is being added contrary to the
+ * FRR code guidelines to take care of build
+ * failures on certain build systems (courtesy of
+ * the proto-c package).
+ */
+ break;
+ }
+
+ return 0;
+}
+
+static void mgmt_be_client_process_msg(void *user_ctx, uint8_t *data,
+ size_t len)
+{
+ struct mgmt_be_client_ctx *client_ctx = user_ctx;
+ Mgmtd__BeMessage *be_msg;
+
+ be_msg = mgmtd__be_message__unpack(NULL, len, data);
+ if (!be_msg) {
+ MGMTD_BE_CLIENT_DBG("Failed to decode %zu bytes from server",
+ len);
+ return;
+ }
+ MGMTD_BE_CLIENT_DBG(
+ "Decoded %zu bytes of message(msg: %u/%u) from server", len,
+ be_msg->message_case, be_msg->message_case);
+ (void)mgmt_be_client_handle_msg(client_ctx, be_msg);
+ mgmtd__be_message__free_unpacked(be_msg, NULL);
+}
+
+static void mgmt_be_client_proc_msgbufs(struct event *thread)
+{
+ struct mgmt_be_client_ctx *client_ctx = EVENT_ARG(thread);
+
+ if (mgmt_msg_procbufs(&client_ctx->mstate, mgmt_be_client_process_msg,
+ client_ctx, mgmt_debug_be_client))
+ mgmt_be_client_register_event(client_ctx, MGMTD_BE_PROC_MSG);
+}
+
+static void mgmt_be_client_read(struct event *thread)
+{
+ struct mgmt_be_client_ctx *client_ctx = EVENT_ARG(thread);
+ enum mgmt_msg_rsched rv;
+
+ rv = mgmt_msg_read(&client_ctx->mstate, client_ctx->conn_fd,
+ mgmt_debug_be_client);
+ if (rv == MSR_DISCONNECT) {
+ mgmt_be_server_disconnect(client_ctx, true);
+ return;
+ }
+ if (rv == MSR_SCHED_BOTH)
+ mgmt_be_client_register_event(client_ctx, MGMTD_BE_PROC_MSG);
+ mgmt_be_client_register_event(client_ctx, MGMTD_BE_CONN_READ);
+}
+
+static inline void
+mgmt_be_client_sched_msg_write(struct mgmt_be_client_ctx *client_ctx)
+{
+ if (!CHECK_FLAG(client_ctx->flags, MGMTD_BE_CLIENT_FLAGS_WRITES_OFF))
+ mgmt_be_client_register_event(client_ctx,
+ MGMTD_BE_CONN_WRITE);
+}
+
+static inline void
+mgmt_be_client_writes_on(struct mgmt_be_client_ctx *client_ctx)
+{
+ MGMTD_BE_CLIENT_DBG("Resume writing msgs");
+ UNSET_FLAG(client_ctx->flags, MGMTD_BE_CLIENT_FLAGS_WRITES_OFF);
+ mgmt_be_client_sched_msg_write(client_ctx);
+}
+
+static inline void
+mgmt_be_client_writes_off(struct mgmt_be_client_ctx *client_ctx)
+{
+ SET_FLAG(client_ctx->flags, MGMTD_BE_CLIENT_FLAGS_WRITES_OFF);
+ MGMTD_BE_CLIENT_DBG("Paused writing msgs");
+}
+
+static int mgmt_be_client_send_msg(struct mgmt_be_client_ctx *client_ctx,
+ Mgmtd__BeMessage *be_msg)
+{
+ if (client_ctx->conn_fd == -1) {
+ MGMTD_BE_CLIENT_DBG("can't send message on closed connection");
+ return -1;
+ }
+
+ int rv = mgmt_msg_send_msg(
+ &client_ctx->mstate, be_msg,
+ mgmtd__be_message__get_packed_size(be_msg),
+ (size_t(*)(void *, void *))mgmtd__be_message__pack,
+ mgmt_debug_be_client);
+ mgmt_be_client_sched_msg_write(client_ctx);
+ return rv;
+}
+
+static void mgmt_be_client_write(struct event *thread)
+{
+ struct mgmt_be_client_ctx *client_ctx = EVENT_ARG(thread);
+ enum mgmt_msg_wsched rv;
+
+ rv = mgmt_msg_write(&client_ctx->mstate, client_ctx->conn_fd,
+ mgmt_debug_be_client);
+ if (rv == MSW_SCHED_STREAM)
+ mgmt_be_client_register_event(client_ctx, MGMTD_BE_CONN_WRITE);
+ else if (rv == MSW_DISCONNECT)
+ mgmt_be_server_disconnect(client_ctx, true);
+ else if (rv == MSW_SCHED_WRITES_OFF) {
+ mgmt_be_client_writes_off(client_ctx);
+ mgmt_be_client_register_event(client_ctx,
+ MGMTD_BE_CONN_WRITES_ON);
+ } else
+ assert(rv == MSW_SCHED_NONE);
+}
+
+static void mgmt_be_client_resume_writes(struct event *thread)
+{
+ struct mgmt_be_client_ctx *client_ctx;
+
+ client_ctx = (struct mgmt_be_client_ctx *)EVENT_ARG(thread);
+ assert(client_ctx && client_ctx->conn_fd != -1);
+
+ mgmt_be_client_writes_on(client_ctx);
+}
+
+static int mgmt_be_send_subscr_req(struct mgmt_be_client_ctx *client_ctx,
+ bool subscr_xpaths, uint16_t num_reg_xpaths,
+ char **reg_xpaths)
+{
+ Mgmtd__BeMessage be_msg;
+ Mgmtd__BeSubscribeReq subscr_req;
+
+ mgmtd__be_subscribe_req__init(&subscr_req);
+ subscr_req.client_name = client_ctx->client_params.name;
+ subscr_req.n_xpath_reg = num_reg_xpaths;
+ if (num_reg_xpaths)
+ subscr_req.xpath_reg = reg_xpaths;
+ else
+ subscr_req.xpath_reg = NULL;
+ subscr_req.subscribe_xpaths = subscr_xpaths;
+
+ mgmtd__be_message__init(&be_msg);
+ be_msg.message_case = MGMTD__BE_MESSAGE__MESSAGE_SUBSCR_REQ;
+ be_msg.subscr_req = &subscr_req;
+
+ return mgmt_be_client_send_msg(client_ctx, &be_msg);
+}
+
+static void mgmt_be_server_connect(struct mgmt_be_client_ctx *client_ctx)
+{
+ const char *dbgtag = mgmt_debug_be_client ? "BE-client" : NULL;
+
+ assert(client_ctx->conn_fd == -1);
+ client_ctx->conn_fd = mgmt_msg_connect(
+ MGMTD_BE_SERVER_PATH, MGMTD_SOCKET_BE_SEND_BUF_SIZE,
+ MGMTD_SOCKET_BE_RECV_BUF_SIZE, dbgtag);
+
+ /* Send SUBSCRIBE_REQ message */
+ if (client_ctx->conn_fd == -1 ||
+ mgmt_be_send_subscr_req(client_ctx, false, 0, NULL) != 0) {
+ mgmt_be_server_disconnect(client_ctx, true);
+ return;
+ }
+
+ /* Start reading from the socket */
+ mgmt_be_client_register_event(client_ctx, MGMTD_BE_CONN_READ);
+
+ /* Notify client through registered callback (if any) */
+ if (client_ctx->client_params.client_connect_notify)
+ (void)(*client_ctx->client_params.client_connect_notify)(
+ (uintptr_t)client_ctx,
+ client_ctx->client_params.user_data, true);
+}
+
+static void mgmt_be_client_conn_timeout(struct event *thread)
+{
+ mgmt_be_server_connect(EVENT_ARG(thread));
+}
+
+static void
+mgmt_be_client_register_event(struct mgmt_be_client_ctx *client_ctx,
+ enum mgmt_be_event event)
+{
+ struct timeval tv = {0};
+
+ switch (event) {
+ case MGMTD_BE_CONN_READ:
+ event_add_read(client_ctx->tm, mgmt_be_client_read,
+ client_ctx, client_ctx->conn_fd,
+ &client_ctx->conn_read_ev);
+ break;
+ case MGMTD_BE_CONN_WRITE:
+ event_add_write(client_ctx->tm, mgmt_be_client_write,
+ client_ctx, client_ctx->conn_fd,
+ &client_ctx->conn_write_ev);
+ break;
+ case MGMTD_BE_PROC_MSG:
+ tv.tv_usec = MGMTD_BE_MSG_PROC_DELAY_USEC;
+ event_add_timer_tv(client_ctx->tm, mgmt_be_client_proc_msgbufs,
+ client_ctx, &tv, &client_ctx->msg_proc_ev);
+ break;
+ case MGMTD_BE_CONN_WRITES_ON:
+ event_add_timer_msec(client_ctx->tm,
+ mgmt_be_client_resume_writes, client_ctx,
+ MGMTD_BE_MSG_WRITE_DELAY_MSEC,
+ &client_ctx->conn_writes_on);
+ break;
+ case MGMTD_BE_SERVER:
+ case MGMTD_BE_CONN_INIT:
+ case MGMTD_BE_SCHED_CFG_PREPARE:
+ case MGMTD_BE_RESCHED_CFG_PREPARE:
+ case MGMTD_BE_SCHED_CFG_APPLY:
+ case MGMTD_BE_RESCHED_CFG_APPLY:
+ assert(!"mgmt_be_client_post_event() called incorrectly");
+ break;
+ }
+}
+
+static void
+mgmt_be_client_schedule_conn_retry(struct mgmt_be_client_ctx *client_ctx,
+ unsigned long intvl_secs)
+{
+ MGMTD_BE_CLIENT_DBG(
+ "Scheduling MGMTD Backend server connection retry after %lu seconds",
+ intvl_secs);
+ event_add_timer(client_ctx->tm, mgmt_be_client_conn_timeout,
+ (void *)client_ctx, intvl_secs,
+ &client_ctx->conn_retry_tmr);
+}
+
+extern struct nb_config *running_config;
+
+/*
+ * Initialize library and try connecting with MGMTD.
+ */
+uintptr_t mgmt_be_client_lib_init(struct mgmt_be_client_params *params,
+ struct event_loop *master_thread)
+{
+ assert(master_thread && params && strlen(params->name)
+ && !mgmt_be_client_ctx.tm);
+
+ mgmt_be_client_ctx.tm = master_thread;
+
+ if (!running_config)
+ assert(!"MGMTD Be Client lib_init() after frr_init() only!");
+ mgmt_be_client_ctx.running_config = running_config;
+ mgmt_be_client_ctx.candidate_config = nb_config_new(NULL);
+
+ memcpy(&mgmt_be_client_ctx.client_params, params,
+ sizeof(mgmt_be_client_ctx.client_params));
+ if (!mgmt_be_client_ctx.client_params.conn_retry_intvl_sec)
+ mgmt_be_client_ctx.client_params.conn_retry_intvl_sec =
+ MGMTD_BE_DEFAULT_CONN_RETRY_INTVL_SEC;
+
+ mgmt_be_txns_init(&mgmt_be_client_ctx.txn_head);
+ mgmt_msg_init(&mgmt_be_client_ctx.mstate, MGMTD_BE_MAX_NUM_MSG_PROC,
+ MGMTD_BE_MAX_NUM_MSG_WRITE, MGMTD_BE_MSG_MAX_LEN,
+ "BE-client");
+
+ /* Start trying to connect to MGMTD backend server immediately */
+ mgmt_be_client_schedule_conn_retry(&mgmt_be_client_ctx, 1);
+
+ MGMTD_BE_CLIENT_DBG("Initialized client '%s'", params->name);
+
+ return (uintptr_t)&mgmt_be_client_ctx;
+}
+
+/*
+ * Subscribe with MGMTD for one or more YANG subtree(s).
+ */
+enum mgmt_result mgmt_be_subscribe_yang_data(uintptr_t lib_hndl,
+ char *reg_yang_xpaths[],
+ int num_reg_xpaths)
+{
+ struct mgmt_be_client_ctx *client_ctx;
+
+ client_ctx = (struct mgmt_be_client_ctx *)lib_hndl;
+ if (!client_ctx)
+ return MGMTD_INVALID_PARAM;
+
+ if (mgmt_be_send_subscr_req(client_ctx, true, num_reg_xpaths,
+ reg_yang_xpaths)
+ != 0)
+ return MGMTD_INTERNAL_ERROR;
+
+ return MGMTD_SUCCESS;
+}
+
+/*
+ * Unsubscribe with MGMTD for one or more YANG subtree(s).
+ */
+enum mgmt_result mgmt_be_unsubscribe_yang_data(uintptr_t lib_hndl,
+ char *reg_yang_xpaths[],
+ int num_reg_xpaths)
+{
+ struct mgmt_be_client_ctx *client_ctx;
+
+ client_ctx = (struct mgmt_be_client_ctx *)lib_hndl;
+ if (!client_ctx)
+ return MGMTD_INVALID_PARAM;
+
+
+ if (mgmt_be_send_subscr_req(client_ctx, false, num_reg_xpaths,
+ reg_yang_xpaths)
+ < 0)
+ return MGMTD_INTERNAL_ERROR;
+
+ return MGMTD_SUCCESS;
+}
+
+/*
+ * Send one or more YANG notifications to MGMTD daemon.
+ */
+enum mgmt_result mgmt_be_send_yang_notify(uintptr_t lib_hndl,
+ Mgmtd__YangData * data_elems[],
+ int num_elems)
+{
+ struct mgmt_be_client_ctx *client_ctx;
+
+ client_ctx = (struct mgmt_be_client_ctx *)lib_hndl;
+ if (!client_ctx)
+ return MGMTD_INVALID_PARAM;
+
+ return MGMTD_SUCCESS;
+}
+
+/*
+ * Destroy library and cleanup everything.
+ */
+void mgmt_be_client_lib_destroy(uintptr_t lib_hndl)
+{
+ struct mgmt_be_client_ctx *client_ctx;
+
+ client_ctx = (struct mgmt_be_client_ctx *)lib_hndl;
+ assert(client_ctx);
+
+ MGMTD_BE_CLIENT_DBG("Destroying MGMTD Backend Client '%s'",
+ client_ctx->client_params.name);
+
+ mgmt_be_server_disconnect(client_ctx, false);
+
+ mgmt_msg_destroy(&client_ctx->mstate);
+
+ EVENT_OFF(client_ctx->conn_retry_tmr);
+ EVENT_OFF(client_ctx->conn_read_ev);
+ EVENT_OFF(client_ctx->conn_write_ev);
+ EVENT_OFF(client_ctx->conn_writes_on);
+ EVENT_OFF(client_ctx->msg_proc_ev);
+ mgmt_be_cleanup_all_txns(client_ctx);
+ mgmt_be_txns_fini(&client_ctx->txn_head);
+}
diff --git a/lib/mgmt_be_client.h b/lib/mgmt_be_client.h
new file mode 100644
index 0000000000..db427457a4
--- /dev/null
+++ b/lib/mgmt_be_client.h
@@ -0,0 +1,260 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * MGMTD Backend Client Library api interfaces
+ * Copyright (C) 2021 Vmware, Inc.
+ * Pushpasis Sarkar <spushpasis@vmware.com>
+ */
+
+#ifndef _FRR_MGMTD_BE_CLIENT_H_
+#define _FRR_MGMTD_BE_CLIENT_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include "northbound.h"
+#include "mgmt_pb.h"
+#include "mgmtd/mgmt_defines.h"
+
+/***************************************************************
+ * Client IDs
+ ***************************************************************/
+
+/*
+ * Add enum value for each supported component, wrap with
+ * #ifdef HAVE_COMPONENT
+ */
+enum mgmt_be_client_id {
+ MGMTD_BE_CLIENT_ID_MIN = 0,
+ MGMTD_BE_CLIENT_ID_INIT = -1,
+#ifdef HAVE_STATICD
+ MGMTD_BE_CLIENT_ID_STATICD,
+#endif
+ MGMTD_BE_CLIENT_ID_MAX
+};
+
+#define FOREACH_MGMTD_BE_CLIENT_ID(id) \
+ for ((id) = MGMTD_BE_CLIENT_ID_MIN; \
+ (id) < MGMTD_BE_CLIENT_ID_MAX; (id)++)
+
+/***************************************************************
+ * Constants
+ ***************************************************************/
+
+#define MGMTD_BE_CLIENT_ERROR_STRING_MAX_LEN 32
+
+#define MGMTD_BE_DEFAULT_CONN_RETRY_INTVL_SEC 5
+
+#define MGMTD_BE_MSG_PROC_DELAY_USEC 10
+#define MGMTD_BE_MAX_NUM_MSG_PROC 500
+
+#define MGMTD_BE_MSG_WRITE_DELAY_MSEC 1
+#define MGMTD_BE_MAX_NUM_MSG_WRITE 1000
+
+#define GMGD_BE_MAX_NUM_REQ_ITEMS 64
+
+#define MGMTD_BE_MSG_MAX_LEN 16384
+
+#define MGMTD_SOCKET_BE_SEND_BUF_SIZE 65535
+#define MGMTD_SOCKET_BE_RECV_BUF_SIZE MGMTD_SOCKET_BE_SEND_BUF_SIZE
+
+#define MGMTD_MAX_CFG_CHANGES_IN_BATCH \
+ ((10 * MGMTD_BE_MSG_MAX_LEN) / \
+ (MGMTD_MAX_XPATH_LEN + MGMTD_MAX_YANG_VALUE_LEN))
+
+/*
+ * MGMTD_BE_MSG_MAX_LEN must be used 80%
+ * since there is overhead of google protobuf
+ * that gets added to sent message
+ */
+#define MGMTD_BE_CFGDATA_PACKING_EFFICIENCY 0.8
+#define MGMTD_BE_CFGDATA_MAX_MSG_LEN \
+ (MGMTD_BE_MSG_MAX_LEN * MGMTD_BE_CFGDATA_PACKING_EFFICIENCY)
+
+#define MGMTD_BE_MAX_BATCH_IDS_IN_REQ \
+ (MGMTD_BE_MSG_MAX_LEN - 128) / sizeof(uint64_t)
+
+#define MGMTD_BE_CONTAINER_NODE_VAL "<<container>>"
+
+/***************************************************************
+ * Data-structures
+ ***************************************************************/
+
+#define MGMTD_BE_MAX_CLIENTS_PER_XPATH_REG 32
+
+struct mgmt_be_client_txn_ctx {
+ uintptr_t *user_ctx;
+};
+
+/*
+ * All the client-specific information this library needs to
+ * initialize itself, setup connection with MGMTD BackEnd interface
+ * and carry on all required procedures appropriately.
+ *
+ * BackEnd clients need to initialise a instance of this structure
+ * with appropriate data and pass it while calling the API
+ * to initialize the library (See mgmt_be_client_lib_init for
+ * more details).
+ */
+struct mgmt_be_client_params {
+ char name[MGMTD_CLIENT_NAME_MAX_LEN];
+ uintptr_t user_data;
+ unsigned long conn_retry_intvl_sec;
+
+ void (*client_connect_notify)(uintptr_t lib_hndl,
+ uintptr_t usr_data,
+ bool connected);
+
+ void (*client_subscribe_notify)(
+ uintptr_t lib_hndl, uintptr_t usr_data,
+ struct nb_yang_xpath **xpath,
+ enum mgmt_result subscribe_result[], int num_paths);
+
+ void (*txn_notify)(
+ uintptr_t lib_hndl, uintptr_t usr_data,
+ struct mgmt_be_client_txn_ctx *txn_ctx, bool destroyed);
+
+ enum mgmt_result (*data_validate)(
+ uintptr_t lib_hndl, uintptr_t usr_data,
+ struct mgmt_be_client_txn_ctx *txn_ctx,
+ struct nb_yang_xpath *xpath, struct nb_yang_value *data,
+ bool delete, char *error_if_any);
+
+ enum mgmt_result (*data_apply)(
+ uintptr_t lib_hndl, uintptr_t usr_data,
+ struct mgmt_be_client_txn_ctx *txn_ctx,
+ struct nb_yang_xpath *xpath, struct nb_yang_value *data,
+ bool delete);
+
+ enum mgmt_result (*get_data_elem)(
+ uintptr_t lib_hndl, uintptr_t usr_data,
+ struct mgmt_be_client_txn_ctx *txn_ctx,
+ struct nb_yang_xpath *xpath, struct nb_yang_xpath_elem *elem);
+
+ enum mgmt_result (*get_data)(
+ uintptr_t lib_hndl, uintptr_t usr_data,
+ struct mgmt_be_client_txn_ctx *txn_ctx,
+ struct nb_yang_xpath *xpath, bool keys_only,
+ struct nb_yang_xpath_elem **elems, int *num_elems,
+ int *next_key);
+
+ enum mgmt_result (*get_next_data)(
+ uintptr_t lib_hndl, uintptr_t usr_data,
+ struct mgmt_be_client_txn_ctx *txn_ctx,
+ struct nb_yang_xpath *xpath, bool keys_only,
+ struct nb_yang_xpath_elem **elems, int *num_elems);
+};
+
+/***************************************************************
+ * Global data exported
+ ***************************************************************/
+
+extern const char *mgmt_be_client_names[MGMTD_BE_CLIENT_ID_MAX + 1];
+
+static inline const char *mgmt_be_client_id2name(enum mgmt_be_client_id id)
+{
+ if (id > MGMTD_BE_CLIENT_ID_MAX)
+ id = MGMTD_BE_CLIENT_ID_MAX;
+ return mgmt_be_client_names[id];
+}
+
+static inline enum mgmt_be_client_id
+mgmt_be_client_name2id(const char *name)
+{
+ enum mgmt_be_client_id id;
+
+ FOREACH_MGMTD_BE_CLIENT_ID (id) {
+ if (!strncmp(mgmt_be_client_names[id], name,
+ MGMTD_CLIENT_NAME_MAX_LEN))
+ return id;
+ }
+
+ return MGMTD_BE_CLIENT_ID_MAX;
+}
+
+/***************************************************************
+ * API prototypes
+ ***************************************************************/
+
+/*
+ * Initialize library and try connecting with MGMTD.
+ *
+ * params
+ * Backend client parameters.
+ *
+ * master_thread
+ * Thread master.
+ *
+ * Returns:
+ * Backend client lib handler (nothing but address of mgmt_be_client_ctx)
+ */
+extern uintptr_t mgmt_be_client_lib_init(struct mgmt_be_client_params *params,
+ struct event_loop *master_thread);
+
+/*
+ * Subscribe with MGMTD for one or more YANG subtree(s).
+ *
+ * lib_hndl
+ * Client library handler.
+ *
+ * reg_yang_xpaths
+ * Yang xpath(s) that needs to be subscribed to.
+ *
+ * num_xpaths
+ * Number of xpaths
+ *
+ * Returns:
+ * MGMTD_SUCCESS on success, MGMTD_* otherwise.
+ */
+extern enum mgmt_result mgmt_be_subscribe_yang_data(uintptr_t lib_hndl,
+ char **reg_yang_xpaths,
+ int num_xpaths);
+
+/*
+ * Send one or more YANG notifications to MGMTD daemon.
+ *
+ * lib_hndl
+ * Client library handler.
+ *
+ * data_elems
+ * Yang data elements from data tree.
+ *
+ * num_elems
+ * Number of data elements.
+ *
+ * Returns:
+ * MGMTD_SUCCESS on success, MGMTD_* otherwise.
+ */
+extern enum mgmt_result
+mgmt_be_send_yang_notify(uintptr_t lib_hndl, Mgmtd__YangData **data_elems,
+ int num_elems);
+
+/*
+ * Un-subscribe with MGMTD for one or more YANG subtree(s).
+ *
+ * lib_hndl
+ * Client library handler.
+ *
+ * reg_yang_xpaths
+ * Yang xpath(s) that needs to be un-subscribed from.
+ *
+ * num_reg_xpaths
+ * Number of subscribed xpaths
+ *
+ * Returns:
+ * MGMTD_SUCCESS on success, MGMTD_* otherwise.
+ */
+enum mgmt_result mgmt_be_unsubscribe_yang_data(uintptr_t lib_hndl,
+ char **reg_yang_xpaths,
+ int num_reg_xpaths);
+
+/*
+ * Destroy library and cleanup everything.
+ */
+extern void mgmt_be_client_lib_destroy(uintptr_t lib_hndl);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _FRR_MGMTD_BE_CLIENT_H_ */
diff --git a/lib/mgmt_fe_client.c b/lib/mgmt_fe_client.c
new file mode 100644
index 0000000000..a2c4fd6572
--- /dev/null
+++ b/lib/mgmt_fe_client.c
@@ -0,0 +1,1072 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * MGMTD Frontend Client Library api interfaces
+ * Copyright (C) 2021 Vmware, Inc.
+ * Pushpasis Sarkar <spushpasis@vmware.com>
+ */
+
+#include <zebra.h>
+#include "memory.h"
+#include "libfrr.h"
+#include "mgmt_fe_client.h"
+#include "mgmt_msg.h"
+#include "mgmt_pb.h"
+#include "network.h"
+#include "stream.h"
+#include "sockopt.h"
+
+#ifdef REDIRECT_DEBUG_TO_STDERR
+#define MGMTD_FE_CLIENT_DBG(fmt, ...) \
+ fprintf(stderr, "%s: " fmt "\n", __func__, ##__VA_ARGS__)
+#define MGMTD_FE_CLIENT_ERR(fmt, ...) \
+ fprintf(stderr, "%s: ERROR, " fmt "\n", __func__, ##__VA_ARGS__)
+#else /* REDIRECT_DEBUG_TO_STDERR */
+#define MGMTD_FE_CLIENT_DBG(fmt, ...) \
+ do { \
+ if (mgmt_debug_fe_client) \
+ zlog_debug("%s: " fmt, __func__, ##__VA_ARGS__); \
+ } while (0)
+#define MGMTD_FE_CLIENT_ERR(fmt, ...) \
+ zlog_err("%s: ERROR: " fmt, __func__, ##__VA_ARGS__)
+#endif /* REDIRECT_DEBUG_TO_STDERR */
+
+struct mgmt_fe_client_ctx;
+
+PREDECL_LIST(mgmt_sessions);
+
+struct mgmt_fe_client_session {
+ uint64_t client_id;
+ uint64_t session_id;
+ struct mgmt_fe_client_ctx *client_ctx;
+ uintptr_t user_ctx;
+
+ struct mgmt_sessions_item list_linkage;
+};
+
+DECLARE_LIST(mgmt_sessions, struct mgmt_fe_client_session, list_linkage);
+
+DEFINE_MTYPE_STATIC(LIB, MGMTD_FE_SESSION, "MGMTD Frontend session");
+
+struct mgmt_fe_client_ctx {
+ int conn_fd;
+ struct event_loop *tm;
+ struct event *conn_retry_tmr;
+ struct event *conn_read_ev;
+ struct event *conn_write_ev;
+ struct event *conn_writes_on;
+ struct event *msg_proc_ev;
+ uint32_t flags;
+
+ struct mgmt_msg_state mstate;
+
+ struct mgmt_fe_client_params client_params;
+
+ struct mgmt_sessions_head client_sessions;
+};
+
+#define MGMTD_FE_CLIENT_FLAGS_WRITES_OFF (1U << 0)
+
+#define FOREACH_SESSION_IN_LIST(client_ctx, session) \
+ frr_each_safe (mgmt_sessions, &(client_ctx)->client_sessions, (session))
+
+static bool mgmt_debug_fe_client;
+
+static struct mgmt_fe_client_ctx mgmt_fe_client_ctx = {
+ .conn_fd = -1,
+};
+
+/* Forward declarations */
+static void
+mgmt_fe_client_register_event(struct mgmt_fe_client_ctx *client_ctx,
+ enum mgmt_fe_event event);
+static void mgmt_fe_client_schedule_conn_retry(
+ struct mgmt_fe_client_ctx *client_ctx, unsigned long intvl_secs);
+
+static struct mgmt_fe_client_session *
+mgmt_fe_find_session_by_client_id(struct mgmt_fe_client_ctx *client_ctx,
+ uint64_t client_id)
+{
+ struct mgmt_fe_client_session *session;
+
+ FOREACH_SESSION_IN_LIST (client_ctx, session) {
+ if (session->client_id == client_id) {
+ MGMTD_FE_CLIENT_DBG(
+ "Found session %p for client-id %llu.", session,
+ (unsigned long long)client_id);
+ return session;
+ }
+ }
+
+ return NULL;
+}
+
+static struct mgmt_fe_client_session *
+mgmt_fe_find_session_by_session_id(struct mgmt_fe_client_ctx *client_ctx,
+ uint64_t session_id)
+{
+ struct mgmt_fe_client_session *session;
+
+ FOREACH_SESSION_IN_LIST (client_ctx, session) {
+ if (session->session_id == session_id) {
+ MGMTD_FE_CLIENT_DBG(
+ "Found session %p for session-id %llu.", session,
+ (unsigned long long)session_id);
+ return session;
+ }
+ }
+
+ return NULL;
+}
+
+static void
+mgmt_fe_server_disconnect(struct mgmt_fe_client_ctx *client_ctx,
+ bool reconnect)
+{
+ if (client_ctx->conn_fd != -1) {
+ close(client_ctx->conn_fd);
+ client_ctx->conn_fd = -1;
+ }
+
+ if (reconnect)
+ mgmt_fe_client_schedule_conn_retry(
+ client_ctx,
+ client_ctx->client_params.conn_retry_intvl_sec);
+}
+
+static inline void
+mgmt_fe_client_sched_msg_write(struct mgmt_fe_client_ctx *client_ctx)
+{
+ if (!CHECK_FLAG(client_ctx->flags, MGMTD_FE_CLIENT_FLAGS_WRITES_OFF))
+ mgmt_fe_client_register_event(client_ctx,
+ MGMTD_FE_CONN_WRITE);
+}
+
+static inline void
+mgmt_fe_client_writes_on(struct mgmt_fe_client_ctx *client_ctx)
+{
+ MGMTD_FE_CLIENT_DBG("Resume writing msgs");
+ UNSET_FLAG(client_ctx->flags, MGMTD_FE_CLIENT_FLAGS_WRITES_OFF);
+ mgmt_fe_client_sched_msg_write(client_ctx);
+}
+
+static inline void
+mgmt_fe_client_writes_off(struct mgmt_fe_client_ctx *client_ctx)
+{
+ SET_FLAG(client_ctx->flags, MGMTD_FE_CLIENT_FLAGS_WRITES_OFF);
+ MGMTD_FE_CLIENT_DBG("Paused writing msgs");
+}
+
+static int mgmt_fe_client_send_msg(struct mgmt_fe_client_ctx *client_ctx,
+ Mgmtd__FeMessage *fe_msg)
+{
+ /* users current expect this to fail here */
+ if (client_ctx->conn_fd == -1) {
+ MGMTD_FE_CLIENT_DBG("can't send message on closed connection");
+ return -1;
+ }
+
+ int rv = mgmt_msg_send_msg(
+ &client_ctx->mstate, fe_msg,
+ mgmtd__fe_message__get_packed_size(fe_msg),
+ (size_t(*)(void *, void *))mgmtd__fe_message__pack,
+ mgmt_debug_fe_client);
+ mgmt_fe_client_sched_msg_write(client_ctx);
+ return rv;
+}
+
+static void mgmt_fe_client_write(struct event *thread)
+{
+ struct mgmt_fe_client_ctx *client_ctx;
+ enum mgmt_msg_wsched rv;
+
+ client_ctx = (struct mgmt_fe_client_ctx *)EVENT_ARG(thread);
+ rv = mgmt_msg_write(&client_ctx->mstate, client_ctx->conn_fd,
+ mgmt_debug_fe_client);
+ if (rv == MSW_SCHED_STREAM)
+ mgmt_fe_client_register_event(client_ctx, MGMTD_FE_CONN_WRITE);
+ else if (rv == MSW_DISCONNECT)
+ mgmt_fe_server_disconnect(client_ctx, true);
+ else if (rv == MSW_SCHED_WRITES_OFF) {
+ mgmt_fe_client_writes_off(client_ctx);
+ mgmt_fe_client_register_event(client_ctx,
+ MGMTD_FE_CONN_WRITES_ON);
+ } else
+ assert(rv == MSW_SCHED_NONE);
+}
+
+static void mgmt_fe_client_resume_writes(struct event *thread)
+{
+ struct mgmt_fe_client_ctx *client_ctx;
+
+ client_ctx = (struct mgmt_fe_client_ctx *)EVENT_ARG(thread);
+ assert(client_ctx && client_ctx->conn_fd != -1);
+
+ mgmt_fe_client_writes_on(client_ctx);
+}
+
+static int
+mgmt_fe_send_register_req(struct mgmt_fe_client_ctx *client_ctx)
+{
+ Mgmtd__FeMessage fe_msg;
+ Mgmtd__FeRegisterReq rgstr_req;
+
+ mgmtd__fe_register_req__init(&rgstr_req);
+ rgstr_req.client_name = client_ctx->client_params.name;
+
+ mgmtd__fe_message__init(&fe_msg);
+ fe_msg.message_case = MGMTD__FE_MESSAGE__MESSAGE_REGISTER_REQ;
+ fe_msg.register_req = &rgstr_req;
+
+ MGMTD_FE_CLIENT_DBG(
+ "Sending REGISTER_REQ message to MGMTD Frontend server");
+
+ return mgmt_fe_client_send_msg(client_ctx, &fe_msg);
+}
+
+static int
+mgmt_fe_send_session_req(struct mgmt_fe_client_ctx *client_ctx,
+ struct mgmt_fe_client_session *session,
+ bool create)
+{
+ Mgmtd__FeMessage fe_msg;
+ Mgmtd__FeSessionReq sess_req;
+
+ mgmtd__fe_session_req__init(&sess_req);
+ sess_req.create = create;
+ if (create) {
+ sess_req.id_case = MGMTD__FE_SESSION_REQ__ID_CLIENT_CONN_ID;
+ sess_req.client_conn_id = session->client_id;
+ } else {
+ sess_req.id_case = MGMTD__FE_SESSION_REQ__ID_SESSION_ID;
+ sess_req.session_id = session->session_id;
+ }
+
+ mgmtd__fe_message__init(&fe_msg);
+ fe_msg.message_case = MGMTD__FE_MESSAGE__MESSAGE_SESSION_REQ;
+ fe_msg.session_req = &sess_req;
+
+ MGMTD_FE_CLIENT_DBG(
+ "Sending SESSION_REQ message for %s session %llu to MGMTD Frontend server",
+ create ? "creating" : "destroying",
+ (unsigned long long)session->client_id);
+
+ return mgmt_fe_client_send_msg(client_ctx, &fe_msg);
+}
+
+static int
+mgmt_fe_send_lockds_req(struct mgmt_fe_client_ctx *client_ctx,
+ struct mgmt_fe_client_session *session, bool lock,
+ uint64_t req_id, Mgmtd__DatastoreId ds_id)
+{
+ (void)req_id;
+ Mgmtd__FeMessage fe_msg;
+ Mgmtd__FeLockDsReq lockds_req;
+
+ mgmtd__fe_lock_ds_req__init(&lockds_req);
+ lockds_req.session_id = session->session_id;
+ lockds_req.req_id = req_id;
+ lockds_req.ds_id = ds_id;
+ lockds_req.lock = lock;
+
+ mgmtd__fe_message__init(&fe_msg);
+ fe_msg.message_case = MGMTD__FE_MESSAGE__MESSAGE_LOCKDS_REQ;
+ fe_msg.lockds_req = &lockds_req;
+
+ MGMTD_FE_CLIENT_DBG(
+ "Sending %sLOCK_REQ message for Ds:%d session %llu to MGMTD Frontend server",
+ lock ? "" : "UN", ds_id, (unsigned long long)session->client_id);
+
+ return mgmt_fe_client_send_msg(client_ctx, &fe_msg);
+}
+
+static int
+mgmt_fe_send_setcfg_req(struct mgmt_fe_client_ctx *client_ctx,
+ struct mgmt_fe_client_session *session,
+ uint64_t req_id, Mgmtd__DatastoreId ds_id,
+ Mgmtd__YangCfgDataReq **data_req, int num_data_reqs,
+ bool implicit_commit, Mgmtd__DatastoreId dst_ds_id)
+{
+ (void)req_id;
+ Mgmtd__FeMessage fe_msg;
+ Mgmtd__FeSetConfigReq setcfg_req;
+
+ mgmtd__fe_set_config_req__init(&setcfg_req);
+ setcfg_req.session_id = session->session_id;
+ setcfg_req.ds_id = ds_id;
+ setcfg_req.req_id = req_id;
+ setcfg_req.data = data_req;
+ setcfg_req.n_data = (size_t)num_data_reqs;
+ setcfg_req.implicit_commit = implicit_commit;
+ setcfg_req.commit_ds_id = dst_ds_id;
+
+ mgmtd__fe_message__init(&fe_msg);
+ fe_msg.message_case = MGMTD__FE_MESSAGE__MESSAGE_SETCFG_REQ;
+ fe_msg.setcfg_req = &setcfg_req;
+
+ MGMTD_FE_CLIENT_DBG(
+ "Sending SET_CONFIG_REQ message for Ds:%d session %llu (#xpaths:%d) to MGMTD Frontend server",
+ ds_id, (unsigned long long)session->client_id, num_data_reqs);
+
+ return mgmt_fe_client_send_msg(client_ctx, &fe_msg);
+}
+
+static int
+mgmt_fe_send_commitcfg_req(struct mgmt_fe_client_ctx *client_ctx,
+ struct mgmt_fe_client_session *session,
+ uint64_t req_id, Mgmtd__DatastoreId src_ds_id,
+ Mgmtd__DatastoreId dest_ds_id, bool validate_only,
+ bool abort)
+{
+ (void)req_id;
+ Mgmtd__FeMessage fe_msg;
+ Mgmtd__FeCommitConfigReq commitcfg_req;
+
+ mgmtd__fe_commit_config_req__init(&commitcfg_req);
+ commitcfg_req.session_id = session->session_id;
+ commitcfg_req.src_ds_id = src_ds_id;
+ commitcfg_req.dst_ds_id = dest_ds_id;
+ commitcfg_req.req_id = req_id;
+ commitcfg_req.validate_only = validate_only;
+ commitcfg_req.abort = abort;
+
+ mgmtd__fe_message__init(&fe_msg);
+ fe_msg.message_case = MGMTD__FE_MESSAGE__MESSAGE_COMMCFG_REQ;
+ fe_msg.commcfg_req = &commitcfg_req;
+
+ MGMTD_FE_CLIENT_DBG(
+ "Sending COMMIT_CONFIG_REQ message for Src-Ds:%d, Dst-Ds:%d session %llu to MGMTD Frontend server",
+ src_ds_id, dest_ds_id, (unsigned long long)session->client_id);
+
+ return mgmt_fe_client_send_msg(client_ctx, &fe_msg);
+}
+
+static int
+mgmt_fe_send_getcfg_req(struct mgmt_fe_client_ctx *client_ctx,
+ struct mgmt_fe_client_session *session,
+ uint64_t req_id, Mgmtd__DatastoreId ds_id,
+ Mgmtd__YangGetDataReq * data_req[],
+ int num_data_reqs)
+{
+ (void)req_id;
+ Mgmtd__FeMessage fe_msg;
+ Mgmtd__FeGetConfigReq getcfg_req;
+
+ mgmtd__fe_get_config_req__init(&getcfg_req);
+ getcfg_req.session_id = session->session_id;
+ getcfg_req.ds_id = ds_id;
+ getcfg_req.req_id = req_id;
+ getcfg_req.data = data_req;
+ getcfg_req.n_data = (size_t)num_data_reqs;
+
+ mgmtd__fe_message__init(&fe_msg);
+ fe_msg.message_case = MGMTD__FE_MESSAGE__MESSAGE_GETCFG_REQ;
+ fe_msg.getcfg_req = &getcfg_req;
+
+ MGMTD_FE_CLIENT_DBG(
+ "Sending GET_CONFIG_REQ message for Ds:%d session %llu (#xpaths:%d) to MGMTD Frontend server",
+ ds_id, (unsigned long long)session->client_id, num_data_reqs);
+
+ return mgmt_fe_client_send_msg(client_ctx, &fe_msg);
+}
+
+static int
+mgmt_fe_send_getdata_req(struct mgmt_fe_client_ctx *client_ctx,
+ struct mgmt_fe_client_session *session,
+ uint64_t req_id, Mgmtd__DatastoreId ds_id,
+ Mgmtd__YangGetDataReq * data_req[],
+ int num_data_reqs)
+{
+ (void)req_id;
+ Mgmtd__FeMessage fe_msg;
+ Mgmtd__FeGetDataReq getdata_req;
+
+ mgmtd__fe_get_data_req__init(&getdata_req);
+ getdata_req.session_id = session->session_id;
+ getdata_req.ds_id = ds_id;
+ getdata_req.req_id = req_id;
+ getdata_req.data = data_req;
+ getdata_req.n_data = (size_t)num_data_reqs;
+
+ mgmtd__fe_message__init(&fe_msg);
+ fe_msg.message_case = MGMTD__FE_MESSAGE__MESSAGE_GETDATA_REQ;
+ fe_msg.getdata_req = &getdata_req;
+
+ MGMTD_FE_CLIENT_DBG(
+ "Sending GET_CONFIG_REQ message for Ds:%d session %llu (#xpaths:%d) to MGMTD Frontend server",
+ ds_id, (unsigned long long)session->client_id, num_data_reqs);
+
+ return mgmt_fe_client_send_msg(client_ctx, &fe_msg);
+}
+
+static int mgmt_fe_send_regnotify_req(
+ struct mgmt_fe_client_ctx *client_ctx,
+ struct mgmt_fe_client_session *session, uint64_t req_id,
+ Mgmtd__DatastoreId ds_id, bool register_req,
+ Mgmtd__YangDataXPath * data_req[], int num_data_reqs)
+{
+ (void)req_id;
+ Mgmtd__FeMessage fe_msg;
+ Mgmtd__FeRegisterNotifyReq regntfy_req;
+
+ mgmtd__fe_register_notify_req__init(&regntfy_req);
+ regntfy_req.session_id = session->session_id;
+ regntfy_req.ds_id = ds_id;
+ regntfy_req.register_req = register_req;
+ regntfy_req.data_xpath = data_req;
+ regntfy_req.n_data_xpath = (size_t)num_data_reqs;
+
+ mgmtd__fe_message__init(&fe_msg);
+ fe_msg.message_case = MGMTD__FE_MESSAGE__MESSAGE_REGNOTIFY_REQ;
+ fe_msg.regnotify_req = &regntfy_req;
+
+ return mgmt_fe_client_send_msg(client_ctx, &fe_msg);
+}
+
+static int
+mgmt_fe_client_handle_msg(struct mgmt_fe_client_ctx *client_ctx,
+ Mgmtd__FeMessage *fe_msg)
+{
+ struct mgmt_fe_client_session *session = NULL;
+
+ /*
+ * protobuf-c adds a max size enum with an internal, and changing by
+ * version, name; cast to an int to avoid unhandled enum warnings
+ */
+ switch ((int)fe_msg->message_case) {
+ case MGMTD__FE_MESSAGE__MESSAGE_SESSION_REPLY:
+ if (fe_msg->session_reply->create
+ && fe_msg->session_reply->has_client_conn_id) {
+ MGMTD_FE_CLIENT_DBG(
+ "Got Session Create Reply Msg for client-id %llu with session-id: %llu.",
+ (unsigned long long)
+ fe_msg->session_reply->client_conn_id,
+ (unsigned long long)
+ fe_msg->session_reply->session_id);
+
+ session = mgmt_fe_find_session_by_client_id(
+ client_ctx,
+ fe_msg->session_reply->client_conn_id);
+
+ if (session && fe_msg->session_reply->success) {
+ MGMTD_FE_CLIENT_DBG(
+ "Session Create for client-id %llu successful.",
+ (unsigned long long)fe_msg
+ ->session_reply->client_conn_id);
+ session->session_id =
+ fe_msg->session_reply->session_id;
+ } else {
+ MGMTD_FE_CLIENT_ERR(
+ "Session Create for client-id %llu failed.",
+ (unsigned long long)fe_msg
+ ->session_reply->client_conn_id);
+ }
+ } else if (!fe_msg->session_reply->create) {
+ MGMTD_FE_CLIENT_DBG(
+ "Got Session Destroy Reply Msg for session-id %llu",
+ (unsigned long long)
+ fe_msg->session_reply->session_id);
+
+ session = mgmt_fe_find_session_by_session_id(
+ client_ctx, fe_msg->session_req->session_id);
+ }
+
+ if (session && session->client_ctx
+ && session->client_ctx->client_params
+ .client_session_notify)
+ (*session->client_ctx->client_params
+ .client_session_notify)(
+ (uintptr_t)client_ctx,
+ client_ctx->client_params.user_data,
+ session->client_id,
+ fe_msg->session_reply->create,
+ fe_msg->session_reply->success,
+ (uintptr_t)session, session->user_ctx);
+ break;
+ case MGMTD__FE_MESSAGE__MESSAGE_LOCKDS_REPLY:
+ MGMTD_FE_CLIENT_DBG(
+ "Got LockDs Reply Msg for session-id %llu",
+ (unsigned long long)
+ fe_msg->lockds_reply->session_id);
+ session = mgmt_fe_find_session_by_session_id(
+ client_ctx, fe_msg->lockds_reply->session_id);
+
+ if (session && session->client_ctx
+ && session->client_ctx->client_params
+ .lock_ds_notify)
+ (*session->client_ctx->client_params
+ .lock_ds_notify)(
+ (uintptr_t)client_ctx,
+ client_ctx->client_params.user_data,
+ session->client_id, (uintptr_t)session,
+ session->user_ctx,
+ fe_msg->lockds_reply->req_id,
+ fe_msg->lockds_reply->lock,
+ fe_msg->lockds_reply->success,
+ fe_msg->lockds_reply->ds_id,
+ fe_msg->lockds_reply->error_if_any);
+ break;
+ case MGMTD__FE_MESSAGE__MESSAGE_SETCFG_REPLY:
+ MGMTD_FE_CLIENT_DBG(
+ "Got Set Config Reply Msg for session-id %llu",
+ (unsigned long long)
+ fe_msg->setcfg_reply->session_id);
+
+ session = mgmt_fe_find_session_by_session_id(
+ client_ctx, fe_msg->setcfg_reply->session_id);
+
+ if (session && session->client_ctx
+ && session->client_ctx->client_params
+ .set_config_notify)
+ (*session->client_ctx->client_params
+ .set_config_notify)(
+ (uintptr_t)client_ctx,
+ client_ctx->client_params.user_data,
+ session->client_id, (uintptr_t)session,
+ session->user_ctx,
+ fe_msg->setcfg_reply->req_id,
+ fe_msg->setcfg_reply->success,
+ fe_msg->setcfg_reply->ds_id,
+ fe_msg->setcfg_reply->error_if_any);
+ break;
+ case MGMTD__FE_MESSAGE__MESSAGE_COMMCFG_REPLY:
+ MGMTD_FE_CLIENT_DBG(
+ "Got Commit Config Reply Msg for session-id %llu",
+ (unsigned long long)
+ fe_msg->commcfg_reply->session_id);
+
+ session = mgmt_fe_find_session_by_session_id(
+ client_ctx, fe_msg->commcfg_reply->session_id);
+
+ if (session && session->client_ctx
+ && session->client_ctx->client_params
+ .commit_config_notify)
+ (*session->client_ctx->client_params
+ .commit_config_notify)(
+ (uintptr_t)client_ctx,
+ client_ctx->client_params.user_data,
+ session->client_id, (uintptr_t)session,
+ session->user_ctx,
+ fe_msg->commcfg_reply->req_id,
+ fe_msg->commcfg_reply->success,
+ fe_msg->commcfg_reply->src_ds_id,
+ fe_msg->commcfg_reply->dst_ds_id,
+ fe_msg->commcfg_reply->validate_only,
+ fe_msg->commcfg_reply->error_if_any);
+ break;
+ case MGMTD__FE_MESSAGE__MESSAGE_GETCFG_REPLY:
+ MGMTD_FE_CLIENT_DBG(
+ "Got Get Config Reply Msg for session-id %llu",
+ (unsigned long long)
+ fe_msg->getcfg_reply->session_id);
+
+ session = mgmt_fe_find_session_by_session_id(
+ client_ctx, fe_msg->getcfg_reply->session_id);
+
+ if (session && session->client_ctx
+ && session->client_ctx->client_params
+ .get_data_notify)
+ (*session->client_ctx->client_params
+ .get_data_notify)(
+ (uintptr_t)client_ctx,
+ client_ctx->client_params.user_data,
+ session->client_id, (uintptr_t)session,
+ session->user_ctx,
+ fe_msg->getcfg_reply->req_id,
+ fe_msg->getcfg_reply->success,
+ fe_msg->getcfg_reply->ds_id,
+ fe_msg->getcfg_reply->data
+ ? fe_msg->getcfg_reply->data->data
+ : NULL,
+ fe_msg->getcfg_reply->data
+ ? fe_msg->getcfg_reply->data->n_data
+ : 0,
+ fe_msg->getcfg_reply->data
+ ? fe_msg->getcfg_reply->data
+ ->next_indx
+ : 0,
+ fe_msg->getcfg_reply->error_if_any);
+ break;
+ case MGMTD__FE_MESSAGE__MESSAGE_GETDATA_REPLY:
+ MGMTD_FE_CLIENT_DBG(
+ "Got Get Data Reply Msg for session-id %llu",
+ (unsigned long long)
+ fe_msg->getdata_reply->session_id);
+
+ session = mgmt_fe_find_session_by_session_id(
+ client_ctx, fe_msg->getdata_reply->session_id);
+
+ if (session && session->client_ctx
+ && session->client_ctx->client_params
+ .get_data_notify)
+ (*session->client_ctx->client_params
+ .get_data_notify)(
+ (uintptr_t)client_ctx,
+ client_ctx->client_params.user_data,
+ session->client_id, (uintptr_t)session,
+ session->user_ctx,
+ fe_msg->getdata_reply->req_id,
+ fe_msg->getdata_reply->success,
+ fe_msg->getdata_reply->ds_id,
+ fe_msg->getdata_reply->data
+ ? fe_msg->getdata_reply->data->data
+ : NULL,
+ fe_msg->getdata_reply->data
+ ? fe_msg->getdata_reply->data
+ ->n_data
+ : 0,
+ fe_msg->getdata_reply->data
+ ? fe_msg->getdata_reply->data
+ ->next_indx
+ : 0,
+ fe_msg->getdata_reply->error_if_any);
+ break;
+ case MGMTD__FE_MESSAGE__MESSAGE_NOTIFY_DATA_REQ:
+ case MGMTD__FE_MESSAGE__MESSAGE_REGNOTIFY_REQ:
+ /*
+ * TODO: Add handling code in future.
+ */
+ break;
+ /*
+ * NOTE: The following messages are always sent from Frontend
+ * clients to MGMTd only and/or need not be handled here.
+ */
+ case MGMTD__FE_MESSAGE__MESSAGE_REGISTER_REQ:
+ case MGMTD__FE_MESSAGE__MESSAGE_SESSION_REQ:
+ case MGMTD__FE_MESSAGE__MESSAGE_LOCKDS_REQ:
+ case MGMTD__FE_MESSAGE__MESSAGE_SETCFG_REQ:
+ case MGMTD__FE_MESSAGE__MESSAGE_COMMCFG_REQ:
+ case MGMTD__FE_MESSAGE__MESSAGE_GETCFG_REQ:
+ case MGMTD__FE_MESSAGE__MESSAGE_GETDATA_REQ:
+ case MGMTD__FE_MESSAGE__MESSAGE__NOT_SET:
+ default:
+ /*
+ * A 'default' case is being added contrary to the
+ * FRR code guidelines to take care of build
+ * failures on certain build systems (courtesy of
+ * the proto-c package).
+ */
+ break;
+ }
+
+ return 0;
+}
+
+static void mgmt_fe_client_process_msg(void *user_ctx, uint8_t *data,
+ size_t len)
+{
+ struct mgmt_fe_client_ctx *client_ctx = user_ctx;
+ Mgmtd__FeMessage *fe_msg;
+
+ fe_msg = mgmtd__fe_message__unpack(NULL, len, data);
+ if (!fe_msg) {
+ MGMTD_FE_CLIENT_DBG("Failed to decode %zu bytes from server.",
+ len);
+ return;
+ }
+ MGMTD_FE_CLIENT_DBG(
+ "Decoded %zu bytes of message(msg: %u/%u) from server", len,
+ fe_msg->message_case, fe_msg->message_case);
+ (void)mgmt_fe_client_handle_msg(client_ctx, fe_msg);
+ mgmtd__fe_message__free_unpacked(fe_msg, NULL);
+}
+
+static void mgmt_fe_client_proc_msgbufs(struct event *thread)
+{
+ struct mgmt_fe_client_ctx *client_ctx;
+
+ client_ctx = (struct mgmt_fe_client_ctx *)EVENT_ARG(thread);
+ if (mgmt_msg_procbufs(&client_ctx->mstate, mgmt_fe_client_process_msg,
+ client_ctx, mgmt_debug_fe_client))
+ mgmt_fe_client_register_event(client_ctx, MGMTD_FE_PROC_MSG);
+}
+
+static void mgmt_fe_client_read(struct event *thread)
+{
+ struct mgmt_fe_client_ctx *client_ctx;
+ enum mgmt_msg_rsched rv;
+
+ client_ctx = (struct mgmt_fe_client_ctx *)EVENT_ARG(thread);
+
+ rv = mgmt_msg_read(&client_ctx->mstate, client_ctx->conn_fd,
+ mgmt_debug_fe_client);
+ if (rv == MSR_DISCONNECT) {
+ mgmt_fe_server_disconnect(client_ctx, true);
+ return;
+ }
+ if (rv == MSR_SCHED_BOTH)
+ mgmt_fe_client_register_event(client_ctx, MGMTD_FE_PROC_MSG);
+ mgmt_fe_client_register_event(client_ctx, MGMTD_FE_CONN_READ);
+}
+
+static void mgmt_fe_server_connect(struct mgmt_fe_client_ctx *client_ctx)
+{
+ const char *dbgtag = mgmt_debug_fe_client ? "FE-client" : NULL;
+
+ assert(client_ctx->conn_fd == -1);
+ client_ctx->conn_fd = mgmt_msg_connect(
+ MGMTD_FE_SERVER_PATH, MGMTD_SOCKET_FE_SEND_BUF_SIZE,
+ MGMTD_SOCKET_FE_RECV_BUF_SIZE, dbgtag);
+
+ /* Send REGISTER_REQ message */
+ if (client_ctx->conn_fd == -1 ||
+ mgmt_fe_send_register_req(client_ctx) != 0) {
+ mgmt_fe_server_disconnect(client_ctx, true);
+ return;
+ }
+
+ /* Start reading from the socket */
+ mgmt_fe_client_register_event(client_ctx, MGMTD_FE_CONN_READ);
+
+ /* Notify client through registered callback (if any) */
+ if (client_ctx->client_params.client_connect_notify)
+ (void)(*client_ctx->client_params.client_connect_notify)(
+ (uintptr_t)client_ctx,
+ client_ctx->client_params.user_data, true);
+}
+
+
+static void mgmt_fe_client_conn_timeout(struct event *thread)
+{
+ mgmt_fe_server_connect(EVENT_ARG(thread));
+}
+
+static void
+mgmt_fe_client_register_event(struct mgmt_fe_client_ctx *client_ctx,
+ enum mgmt_fe_event event)
+{
+ struct timeval tv = {0};
+
+ switch (event) {
+ case MGMTD_FE_CONN_READ:
+ event_add_read(client_ctx->tm, mgmt_fe_client_read,
+ client_ctx, client_ctx->conn_fd,
+ &client_ctx->conn_read_ev);
+ break;
+ case MGMTD_FE_CONN_WRITE:
+ event_add_write(client_ctx->tm, mgmt_fe_client_write,
+ client_ctx, client_ctx->conn_fd,
+ &client_ctx->conn_write_ev);
+ break;
+ case MGMTD_FE_PROC_MSG:
+ tv.tv_usec = MGMTD_FE_MSG_PROC_DELAY_USEC;
+ event_add_timer_tv(client_ctx->tm,
+ mgmt_fe_client_proc_msgbufs, client_ctx,
+ &tv, &client_ctx->msg_proc_ev);
+ break;
+ case MGMTD_FE_CONN_WRITES_ON:
+ event_add_timer_msec(
+ client_ctx->tm, mgmt_fe_client_resume_writes,
+ client_ctx, MGMTD_FE_MSG_WRITE_DELAY_MSEC,
+ &client_ctx->conn_writes_on);
+ break;
+ case MGMTD_FE_SERVER:
+ assert(!"mgmt_fe_client_ctx_post_event called incorrectly");
+ break;
+ }
+}
+
+static void mgmt_fe_client_schedule_conn_retry(
+ struct mgmt_fe_client_ctx *client_ctx, unsigned long intvl_secs)
+{
+ MGMTD_FE_CLIENT_DBG(
+ "Scheduling MGMTD Frontend server connection retry after %lu seconds",
+ intvl_secs);
+ event_add_timer(client_ctx->tm, mgmt_fe_client_conn_timeout,
+ (void *)client_ctx, intvl_secs,
+ &client_ctx->conn_retry_tmr);
+}
+
+/*
+ * Initialize library and try connecting with MGMTD.
+ */
+uintptr_t mgmt_fe_client_lib_init(struct mgmt_fe_client_params *params,
+ struct event_loop *master_thread)
+{
+ assert(master_thread && params && strlen(params->name)
+ && !mgmt_fe_client_ctx.tm);
+
+ mgmt_fe_client_ctx.tm = master_thread;
+ memcpy(&mgmt_fe_client_ctx.client_params, params,
+ sizeof(mgmt_fe_client_ctx.client_params));
+ if (!mgmt_fe_client_ctx.client_params.conn_retry_intvl_sec)
+ mgmt_fe_client_ctx.client_params.conn_retry_intvl_sec =
+ MGMTD_FE_DEFAULT_CONN_RETRY_INTVL_SEC;
+
+ mgmt_msg_init(&mgmt_fe_client_ctx.mstate, MGMTD_FE_MAX_NUM_MSG_PROC,
+ MGMTD_FE_MAX_NUM_MSG_WRITE, MGMTD_FE_MSG_MAX_LEN,
+ "FE-client");
+
+ mgmt_sessions_init(&mgmt_fe_client_ctx.client_sessions);
+
+ /* Start trying to connect to MGMTD frontend server immediately */
+ mgmt_fe_client_schedule_conn_retry(&mgmt_fe_client_ctx, 1);
+
+ MGMTD_FE_CLIENT_DBG("Initialized client '%s'", params->name);
+
+ return (uintptr_t)&mgmt_fe_client_ctx;
+}
+
+/*
+ * Create a new Session for a Frontend Client connection.
+ */
+enum mgmt_result mgmt_fe_create_client_session(uintptr_t lib_hndl,
+ uint64_t client_id,
+ uintptr_t user_ctx)
+{
+ struct mgmt_fe_client_ctx *client_ctx;
+ struct mgmt_fe_client_session *session;
+
+ client_ctx = (struct mgmt_fe_client_ctx *)lib_hndl;
+ if (!client_ctx)
+ return MGMTD_INVALID_PARAM;
+
+ session = XCALLOC(MTYPE_MGMTD_FE_SESSION,
+ sizeof(struct mgmt_fe_client_session));
+ assert(session);
+ session->user_ctx = user_ctx;
+ session->client_id = client_id;
+ session->client_ctx = client_ctx;
+ session->session_id = 0;
+
+ if (mgmt_fe_send_session_req(client_ctx, session, true) != 0) {
+ XFREE(MTYPE_MGMTD_FE_SESSION, session);
+ return MGMTD_INTERNAL_ERROR;
+ }
+ mgmt_sessions_add_tail(&client_ctx->client_sessions, session);
+
+ return MGMTD_SUCCESS;
+}
+
+/*
+ * Delete an existing Session for a Frontend Client connection.
+ */
+enum mgmt_result mgmt_fe_destroy_client_session(uintptr_t lib_hndl,
+ uint64_t client_id)
+{
+ struct mgmt_fe_client_ctx *client_ctx;
+ struct mgmt_fe_client_session *session;
+
+ client_ctx = (struct mgmt_fe_client_ctx *)lib_hndl;
+ if (!client_ctx)
+ return MGMTD_INVALID_PARAM;
+
+ session = mgmt_fe_find_session_by_client_id(client_ctx, client_id);
+ if (!session || session->client_ctx != client_ctx)
+ return MGMTD_INVALID_PARAM;
+
+ if (session->session_id &&
+ mgmt_fe_send_session_req(client_ctx, session, false) != 0)
+ MGMTD_FE_CLIENT_ERR(
+ "Failed to send session destroy request for the session-id %lu",
+ (unsigned long)session->session_id);
+
+ mgmt_sessions_del(&client_ctx->client_sessions, session);
+ XFREE(MTYPE_MGMTD_FE_SESSION, session);
+
+ return MGMTD_SUCCESS;
+}
+
+static void mgmt_fe_destroy_client_sessions(uintptr_t lib_hndl)
+{
+ struct mgmt_fe_client_ctx *client_ctx;
+ struct mgmt_fe_client_session *session;
+
+ client_ctx = (struct mgmt_fe_client_ctx *)lib_hndl;
+ if (!client_ctx)
+ return;
+
+ FOREACH_SESSION_IN_LIST (client_ctx, session)
+ mgmt_fe_destroy_client_session(lib_hndl, session->client_id);
+}
+
+/*
+ * Send UN/LOCK_DS_REQ to MGMTD for a specific Datastore DS.
+ */
+enum mgmt_result mgmt_fe_lock_ds(uintptr_t lib_hndl, uintptr_t session_id,
+ uint64_t req_id, Mgmtd__DatastoreId ds_id,
+ bool lock_ds)
+{
+ struct mgmt_fe_client_ctx *client_ctx;
+ struct mgmt_fe_client_session *session;
+
+ client_ctx = (struct mgmt_fe_client_ctx *)lib_hndl;
+ if (!client_ctx)
+ return MGMTD_INVALID_PARAM;
+
+ session = (struct mgmt_fe_client_session *)session_id;
+ if (!session || session->client_ctx != client_ctx)
+ return MGMTD_INVALID_PARAM;
+
+ if (mgmt_fe_send_lockds_req(client_ctx, session, lock_ds, req_id,
+ ds_id)
+ != 0)
+ return MGMTD_INTERNAL_ERROR;
+
+ return MGMTD_SUCCESS;
+}
+
+/*
+ * Send SET_CONFIG_REQ to MGMTD for one or more config data(s).
+ */
+enum mgmt_result
+mgmt_fe_set_config_data(uintptr_t lib_hndl, uintptr_t session_id,
+ uint64_t req_id, Mgmtd__DatastoreId ds_id,
+ Mgmtd__YangCfgDataReq **config_req, int num_reqs,
+ bool implicit_commit, Mgmtd__DatastoreId dst_ds_id)
+{
+ struct mgmt_fe_client_ctx *client_ctx;
+ struct mgmt_fe_client_session *session;
+
+ client_ctx = (struct mgmt_fe_client_ctx *)lib_hndl;
+ if (!client_ctx)
+ return MGMTD_INVALID_PARAM;
+
+ session = (struct mgmt_fe_client_session *)session_id;
+ if (!session || session->client_ctx != client_ctx)
+ return MGMTD_INVALID_PARAM;
+
+ if (mgmt_fe_send_setcfg_req(client_ctx, session, req_id, ds_id,
+ config_req, num_reqs, implicit_commit,
+ dst_ds_id)
+ != 0)
+ return MGMTD_INTERNAL_ERROR;
+
+ return MGMTD_SUCCESS;
+}
+
+/*
+ * Send SET_CONFIG_REQ to MGMTD for one or more config data(s).
+ */
+enum mgmt_result mgmt_fe_commit_config_data(uintptr_t lib_hndl,
+ uintptr_t session_id,
+ uint64_t req_id,
+ Mgmtd__DatastoreId src_ds_id,
+ Mgmtd__DatastoreId dst_ds_id,
+ bool validate_only, bool abort)
+{
+ struct mgmt_fe_client_ctx *client_ctx;
+ struct mgmt_fe_client_session *session;
+
+ client_ctx = (struct mgmt_fe_client_ctx *)lib_hndl;
+ if (!client_ctx)
+ return MGMTD_INVALID_PARAM;
+
+ session = (struct mgmt_fe_client_session *)session_id;
+ if (!session || session->client_ctx != client_ctx)
+ return MGMTD_INVALID_PARAM;
+
+ if (mgmt_fe_send_commitcfg_req(client_ctx, session, req_id, src_ds_id,
+ dst_ds_id, validate_only, abort)
+ != 0)
+ return MGMTD_INTERNAL_ERROR;
+
+ return MGMTD_SUCCESS;
+}
+
+/*
+ * Send GET_CONFIG_REQ to MGMTD for one or more config data item(s).
+ */
+enum mgmt_result
+mgmt_fe_get_config_data(uintptr_t lib_hndl, uintptr_t session_id,
+ uint64_t req_id, Mgmtd__DatastoreId ds_id,
+ Mgmtd__YangGetDataReq * data_req[], int num_reqs)
+{
+ struct mgmt_fe_client_ctx *client_ctx;
+ struct mgmt_fe_client_session *session;
+
+ client_ctx = (struct mgmt_fe_client_ctx *)lib_hndl;
+ if (!client_ctx)
+ return MGMTD_INVALID_PARAM;
+
+ session = (struct mgmt_fe_client_session *)session_id;
+ if (!session || session->client_ctx != client_ctx)
+ return MGMTD_INVALID_PARAM;
+
+ if (mgmt_fe_send_getcfg_req(client_ctx, session, req_id, ds_id,
+ data_req, num_reqs)
+ != 0)
+ return MGMTD_INTERNAL_ERROR;
+
+ return MGMTD_SUCCESS;
+}
+
+/*
+ * Send GET_DATA_REQ to MGMTD for one or more config data item(s).
+ */
+enum mgmt_result mgmt_fe_get_data(uintptr_t lib_hndl, uintptr_t session_id,
+ uint64_t req_id, Mgmtd__DatastoreId ds_id,
+ Mgmtd__YangGetDataReq * data_req[],
+ int num_reqs)
+{
+ struct mgmt_fe_client_ctx *client_ctx;
+ struct mgmt_fe_client_session *session;
+
+ client_ctx = (struct mgmt_fe_client_ctx *)lib_hndl;
+ if (!client_ctx)
+ return MGMTD_INVALID_PARAM;
+
+ session = (struct mgmt_fe_client_session *)session_id;
+ if (!session || session->client_ctx != client_ctx)
+ return MGMTD_INVALID_PARAM;
+
+ if (mgmt_fe_send_getdata_req(client_ctx, session, req_id, ds_id,
+ data_req, num_reqs)
+ != 0)
+ return MGMTD_INTERNAL_ERROR;
+
+ return MGMTD_SUCCESS;
+}
+
+/*
+ * Send NOTIFY_REGISTER_REQ to MGMTD daemon.
+ */
+enum mgmt_result
+mgmt_fe_register_yang_notify(uintptr_t lib_hndl, uintptr_t session_id,
+ uint64_t req_id, Mgmtd__DatastoreId ds_id,
+ bool register_req,
+ Mgmtd__YangDataXPath * data_req[],
+ int num_reqs)
+{
+ struct mgmt_fe_client_ctx *client_ctx;
+ struct mgmt_fe_client_session *session;
+
+ client_ctx = (struct mgmt_fe_client_ctx *)lib_hndl;
+ if (!client_ctx)
+ return MGMTD_INVALID_PARAM;
+
+ session = (struct mgmt_fe_client_session *)session_id;
+ if (!session || session->client_ctx != client_ctx)
+ return MGMTD_INVALID_PARAM;
+
+ if (mgmt_fe_send_regnotify_req(client_ctx, session, req_id, ds_id,
+ register_req, data_req, num_reqs)
+ != 0)
+ return MGMTD_INTERNAL_ERROR;
+
+ return MGMTD_SUCCESS;
+}
+
+/*
+ * Destroy library and cleanup everything.
+ */
+void mgmt_fe_client_lib_destroy(uintptr_t lib_hndl)
+{
+ struct mgmt_fe_client_ctx *client_ctx;
+
+ client_ctx = (struct mgmt_fe_client_ctx *)lib_hndl;
+ assert(client_ctx);
+
+ MGMTD_FE_CLIENT_DBG("Destroying MGMTD Frontend Client '%s'",
+ client_ctx->client_params.name);
+
+ mgmt_fe_server_disconnect(client_ctx, false);
+
+ mgmt_fe_destroy_client_sessions(lib_hndl);
+
+ EVENT_OFF(client_ctx->conn_retry_tmr);
+ EVENT_OFF(client_ctx->conn_read_ev);
+ EVENT_OFF(client_ctx->conn_write_ev);
+ EVENT_OFF(client_ctx->conn_writes_on);
+ EVENT_OFF(client_ctx->msg_proc_ev);
+ mgmt_msg_destroy(&client_ctx->mstate);
+}
diff --git a/lib/mgmt_fe_client.h b/lib/mgmt_fe_client.h
new file mode 100644
index 0000000000..aa3371f03c
--- /dev/null
+++ b/lib/mgmt_fe_client.h
@@ -0,0 +1,346 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * MGMTD Frontend Client Library api interfaces
+ * Copyright (C) 2021 Vmware, Inc.
+ * Pushpasis Sarkar <spushpasis@vmware.com>
+ */
+
+#ifndef _FRR_MGMTD_FE_CLIENT_H_
+#define _FRR_MGMTD_FE_CLIENT_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include "mgmt_pb.h"
+#include "frrevent.h"
+#include "mgmtd/mgmt_defines.h"
+
+/***************************************************************
+ * Macros
+ ***************************************************************/
+
+/*
+ * The server port MGMTD daemon is listening for Backend Client
+ * connections.
+ */
+
+#define MGMTD_FE_CLIENT_ERROR_STRING_MAX_LEN 32
+
+#define MGMTD_FE_DEFAULT_CONN_RETRY_INTVL_SEC 5
+
+#define MGMTD_FE_MSG_PROC_DELAY_USEC 10
+#define MGMTD_FE_MAX_NUM_MSG_PROC 500
+
+#define MGMTD_FE_MSG_WRITE_DELAY_MSEC 1
+#define MGMTD_FE_MAX_NUM_MSG_WRITE 100
+
+#define GMGD_FE_MAX_NUM_REQ_ITEMS 64
+
+#define MGMTD_FE_MSG_MAX_LEN 9000
+
+#define MGMTD_SOCKET_FE_SEND_BUF_SIZE 65535
+#define MGMTD_SOCKET_FE_RECV_BUF_SIZE MGMTD_SOCKET_FE_SEND_BUF_SIZE
+
+/***************************************************************
+ * Data-structures
+ ***************************************************************/
+
+#define MGMTD_SESSION_ID_NONE 0
+
+#define MGMTD_CLIENT_ID_NONE 0
+
+#define MGMTD_DS_NONE MGMTD__DATASTORE_ID__DS_NONE
+#define MGMTD_DS_RUNNING MGMTD__DATASTORE_ID__RUNNING_DS
+#define MGMTD_DS_CANDIDATE MGMTD__DATASTORE_ID__CANDIDATE_DS
+#define MGMTD_DS_OPERATIONAL MGMTD__DATASTORE_ID__OPERATIONAL_DS
+#define MGMTD_DS_MAX_ID MGMTD_DS_OPERATIONAL + 1
+
+/*
+ * All the client specific information this library needs to
+ * initialize itself, setup connection with MGMTD FrontEnd interface
+ * and carry on all required procedures appropriately.
+ *
+ * FrontEnd clients need to initialise a instance of this structure
+ * with appropriate data and pass it while calling the API
+ * to initialize the library (See mgmt_fe_client_lib_init for
+ * more details).
+ */
+struct mgmt_fe_client_params {
+ char name[MGMTD_CLIENT_NAME_MAX_LEN];
+ uintptr_t user_data;
+ unsigned long conn_retry_intvl_sec;
+
+ void (*client_connect_notify)(uintptr_t lib_hndl,
+ uintptr_t user_data,
+ bool connected);
+
+ void (*client_session_notify)(uintptr_t lib_hndl,
+ uintptr_t user_data,
+ uint64_t client_id,
+ bool create, bool success,
+ uintptr_t session_id,
+ uintptr_t user_session_ctx);
+
+ void (*lock_ds_notify)(uintptr_t lib_hndl, uintptr_t user_data,
+ uint64_t client_id, uintptr_t session_id,
+ uintptr_t user_session_ctx, uint64_t req_id,
+ bool lock_ds, bool success,
+ Mgmtd__DatastoreId ds_id, char *errmsg_if_any);
+
+ void (*set_config_notify)(uintptr_t lib_hndl, uintptr_t user_data,
+ uint64_t client_id, uintptr_t session_id,
+ uintptr_t user_session_ctx, uint64_t req_id,
+ bool success, Mgmtd__DatastoreId ds_id,
+ char *errmsg_if_any);
+
+ void (*commit_config_notify)(
+ uintptr_t lib_hndl, uintptr_t user_data, uint64_t client_id,
+ uintptr_t session_id, uintptr_t user_session_ctx,
+ uint64_t req_id, bool success, Mgmtd__DatastoreId src_ds_id,
+ Mgmtd__DatastoreId dst_ds_id, bool validate_only,
+ char *errmsg_if_any);
+
+ enum mgmt_result (*get_data_notify)(
+ uintptr_t lib_hndl, uintptr_t user_data, uint64_t client_id,
+ uintptr_t session_id, uintptr_t user_session_ctx,
+ uint64_t req_id, bool success, Mgmtd__DatastoreId ds_id,
+ Mgmtd__YangData **yang_data, size_t num_data, int next_key,
+ char *errmsg_if_any);
+
+ enum mgmt_result (*data_notify)(
+ uint64_t client_id, uint64_t session_id, uintptr_t user_data,
+ uint64_t req_id, Mgmtd__DatastoreId ds_id,
+ Mgmtd__YangData **yang_data, size_t num_data);
+};
+
+/***************************************************************
+ * API prototypes
+ ***************************************************************/
+
+/*
+ * Initialize library and try connecting with MGMTD FrontEnd interface.
+ *
+ * params
+ * Frontend client parameters.
+ *
+ * master_thread
+ * Thread master.
+ *
+ * Returns:
+ * Frontend client lib handler (nothing but address of mgmt_fe_client_ctx)
+ */
+extern uintptr_t mgmt_fe_client_lib_init(struct mgmt_fe_client_params *params,
+ struct event_loop *master_thread);
+
+/*
+ * Create a new Session for a Frontend Client connection.
+ *
+ * lib_hndl
+ * Client library handler.
+ *
+ * client_id
+ * Unique identifier of client.
+ *
+ * user_ctx
+ * Client context.
+ *
+ * Returns:
+ * MGMTD_SUCCESS on success, MGMTD_* otherwise.
+ */
+extern enum mgmt_result mgmt_fe_create_client_session(uintptr_t lib_hndl,
+ uint64_t client_id,
+ uintptr_t user_ctx);
+
+/*
+ * Delete an existing Session for a Frontend Client connection.
+ *
+ * lib_hndl
+ * Client library handler.
+ *
+ * client_id
+ * Unique identifier of client.
+ *
+ * Returns:
+ * MGMTD_SUCCESS on success, MGMTD_* otherwise.
+ */
+extern enum mgmt_result mgmt_fe_destroy_client_session(uintptr_t lib_hndl,
+ uint64_t client_id);
+
+/*
+ * Send UN/LOCK_DS_REQ to MGMTD for a specific Datastore DS.
+ *
+ * lib_hndl
+ * Client library handler.
+ *
+ * session_id
+ * Client session ID.
+ *
+ * req_id
+ * Client request ID.
+ *
+ * ds_id
+ * Datastore ID (Running/Candidate/Oper/Startup)
+ *
+ * lock_ds
+ * TRUE for lock request, FALSE for unlock request.
+ *
+ * Returns:
+ * MGMTD_SUCCESS on success, MGMTD_* otherwise.
+ */
+extern enum mgmt_result
+mgmt_fe_lock_ds(uintptr_t lib_hndl, uintptr_t session_id, uint64_t req_id,
+ Mgmtd__DatastoreId ds_id, bool lock_ds);
+
+/*
+ * Send SET_CONFIG_REQ to MGMTD for one or more config data(s).
+ *
+ * lib_hndl
+ * Client library handler.
+ *
+ * session_id
+ * Client session ID.
+ *
+ * req_id
+ * Client request ID.
+ *
+ * ds_id
+ * Datastore ID (Running/Candidate/Oper/Startup)
+ *
+ * conf_req
+ * Details regarding the SET_CONFIG_REQ.
+ *
+ * num_req
+ * Number of config requests.
+ *
+ * implcit commit
+ * TRUE for implicit commit, FALSE otherwise.
+ *
+ * dst_ds_id
+ * Destination Datastore ID where data needs to be set.
+ *
+ * Returns:
+ * MGMTD_SUCCESS on success, MGMTD_* otherwise.
+ */
+extern enum mgmt_result
+mgmt_fe_set_config_data(uintptr_t lib_hndl, uintptr_t session_id,
+ uint64_t req_id, Mgmtd__DatastoreId ds_id,
+ Mgmtd__YangCfgDataReq **config_req, int num_req,
+ bool implicit_commit, Mgmtd__DatastoreId dst_ds_id);
+
+/*
+ * Send SET_COMMMIT_REQ to MGMTD for one or more config data(s).
+ *
+ * lib_hndl
+ * Client library handler.
+ *
+ * session_id
+ * Client session ID.
+ *
+ * req_id
+ * Client request ID.
+ *
+ * src_ds_id
+ * Source datastore ID from where data needs to be committed from.
+ *
+ * dst_ds_id
+ * Destination datastore ID where data needs to be committed to.
+ *
+ * validate_only
+ * TRUE if data needs to be validated only, FALSE otherwise.
+ *
+ * abort
+ * TRUE if need to restore Src DS back to Dest DS, FALSE otherwise.
+ *
+ * Returns:
+ * MGMTD_SUCCESS on success, MGMTD_* otherwise.
+ */
+extern enum mgmt_result
+mgmt_fe_commit_config_data(uintptr_t lib_hndl, uintptr_t session_id,
+ uint64_t req_id, Mgmtd__DatastoreId src_ds_id,
+ Mgmtd__DatastoreId dst_ds_id, bool validate_only,
+ bool abort);
+
+/*
+ * Send GET_CONFIG_REQ to MGMTD for one or more config data item(s).
+ *
+ * lib_hndl
+ * Client library handler.
+ *
+ * session_id
+ * Client session ID.
+ *
+ * req_id
+ * Client request ID.
+ *
+ * ds_id
+ * Datastore ID (Running/Candidate)
+ *
+ * data_req
+ * Get config requested.
+ *
+ * num_req
+ * Number of get config requests.
+ *
+ * Returns:
+ * MGMTD_SUCCESS on success, MGMTD_* otherwise.
+ */
+extern enum mgmt_result
+mgmt_fe_get_config_data(uintptr_t lib_hndl, uintptr_t session_id,
+ uint64_t req_id, Mgmtd__DatastoreId ds_id,
+ Mgmtd__YangGetDataReq **data_req, int num_reqs);
+
+/*
+ * Send GET_DATA_REQ to MGMTD for one or more data item(s).
+ *
+ * Similar to get config request but supports getting data
+ * from operational ds aka backend clients directly.
+ */
+extern enum mgmt_result
+mgmt_fe_get_data(uintptr_t lib_hndl, uintptr_t session_id, uint64_t req_id,
+ Mgmtd__DatastoreId ds_id, Mgmtd__YangGetDataReq **data_req,
+ int num_reqs);
+
+/*
+ * Send NOTIFY_REGISTER_REQ to MGMTD daemon.
+ *
+ * lib_hndl
+ * Client library handler.
+ *
+ * session_id
+ * Client session ID.
+ *
+ * req_id
+ * Client request ID.
+ *
+ * ds_id
+ * Datastore ID.
+ *
+ * register_req
+ * TRUE if registering, FALSE otherwise.
+ *
+ * data_req
+ * Details of the YANG notification data.
+ *
+ * num_reqs
+ * Number of data requests.
+ *
+ * Returns:
+ * MGMTD_SUCCESS on success, MGMTD_* otherwise.
+ */
+extern enum mgmt_result
+mgmt_fe_register_yang_notify(uintptr_t lib_hndl, uintptr_t session_id,
+ uint64_t req_id, Mgmtd__DatastoreId ds_id,
+ bool register_req,
+ Mgmtd__YangDataXPath **data_req, int num_reqs);
+
+/*
+ * Destroy library and cleanup everything.
+ */
+extern void mgmt_fe_client_lib_destroy(uintptr_t lib_hndl);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _FRR_MGMTD_FE_CLIENT_H_ */
diff --git a/lib/mgmt_msg.c b/lib/mgmt_msg.c
new file mode 100644
index 0000000000..3f55f82024
--- /dev/null
+++ b/lib/mgmt_msg.c
@@ -0,0 +1,414 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * March 6 2023, Christian Hopps <chopps@labn.net>
+ *
+ * Copyright (C) 2021 Vmware, Inc.
+ * Pushpasis Sarkar <spushpasis@vmware.com>
+ * Copyright (c) 2023, LabN Consulting, L.L.C.
+ */
+#include <zebra.h>
+#include "network.h"
+#include "sockopt.h"
+#include "stream.h"
+#include "frrevent.h"
+#include "mgmt_msg.h"
+
+
+#define MGMT_MSG_DBG(dbgtag, fmt, ...) \
+ do { \
+ if (dbgtag) \
+ zlog_debug("%s: %s: " fmt, dbgtag, __func__, \
+ ##__VA_ARGS__); \
+ } while (0)
+
+#define MGMT_MSG_ERR(ms, fmt, ...) \
+ zlog_err("%s: %s: " fmt, ms->idtag, __func__, ##__VA_ARGS__)
+
+/**
+ * Read data from a socket into streams containing 1 or more full msgs headed by
+ * mgmt_msg_hdr which contain API messages (currently protobuf).
+ *
+ * Args:
+ * ms: mgmt_msg_state for this process.
+ * fd: socket/file to read data from.
+ * debug: true to enable debug logging.
+ *
+ * Returns:
+ * MPP_DISCONNECT - socket should be closed and connect retried.
+ * MSV_SCHED_STREAM - this call should be rescheduled to run.
+ * MPP_SCHED_BOTH - this call and the procmsg buf should be scheduled to
+ *run.
+ */
+enum mgmt_msg_rsched mgmt_msg_read(struct mgmt_msg_state *ms, int fd,
+ bool debug)
+{
+ const char *dbgtag = debug ? ms->idtag : NULL;
+ size_t avail = STREAM_WRITEABLE(ms->ins);
+ struct mgmt_msg_hdr *mhdr = NULL;
+ size_t total = 0;
+ size_t mcount = 0;
+ ssize_t n, left;
+
+ assert(ms && fd != -1);
+
+ /*
+ * Read as much as we can into the stream.
+ */
+ while (avail > sizeof(struct mgmt_msg_hdr)) {
+ n = stream_read_try(ms->ins, fd, avail);
+ MGMT_MSG_DBG(dbgtag, "got %zd bytes", n);
+
+ /* -2 is normal nothing read, and to retry */
+ if (n == -2)
+ break;
+ if (n <= 0) {
+ if (n == 0)
+ MGMT_MSG_ERR(ms, "got EOF/disconnect");
+ else
+ MGMT_MSG_ERR(ms,
+ "got error while reading: '%s'",
+ safe_strerror(errno));
+ return MSR_DISCONNECT;
+ }
+ ms->nrxb += n;
+ avail -= n;
+ }
+
+ /*
+ * Check if we have read a complete messages or not.
+ */
+ assert(stream_get_getp(ms->ins) == 0);
+ left = stream_get_endp(ms->ins);
+ while (left > (long)sizeof(struct mgmt_msg_hdr)) {
+ mhdr = (struct mgmt_msg_hdr *)(STREAM_DATA(ms->ins) + total);
+ if (mhdr->marker != MGMT_MSG_MARKER) {
+ MGMT_MSG_DBG(dbgtag, "recv corrupt buffer, disconnect");
+ return MSR_DISCONNECT;
+ }
+ if ((ssize_t)mhdr->len > left)
+ break;
+
+ MGMT_MSG_DBG(dbgtag, "read full message len %u", mhdr->len);
+ total += mhdr->len;
+ left -= mhdr->len;
+ mcount++;
+ }
+
+ if (!mcount)
+ return MSR_SCHED_STREAM;
+
+ /*
+ * We have read at least one message into the stream, queue it up.
+ */
+ mhdr = (struct mgmt_msg_hdr *)(STREAM_DATA(ms->ins) + total);
+ stream_set_endp(ms->ins, total);
+ stream_fifo_push(&ms->inq, ms->ins);
+ ms->ins = stream_new(ms->max_msg_sz);
+ if (left) {
+ stream_put(ms->ins, mhdr, left);
+ stream_set_endp(ms->ins, left);
+ }
+
+ return MSR_SCHED_BOTH;
+}
+
+/**
+ * Process streams containing whole messages that have been pushed onto the
+ * FIFO. This should be called from an event/timer handler and should be
+ * reschedulable.
+ *
+ * Args:
+ * ms: mgmt_msg_state for this process.
+ * handle_mgs: function to call for each received message.
+ * user: opaque value passed through to handle_msg.
+ * debug: true to enable debug logging.
+ *
+ * Returns:
+ * true if more to process (so reschedule) else false
+ */
+bool mgmt_msg_procbufs(struct mgmt_msg_state *ms,
+ void (*handle_msg)(void *user, uint8_t *msg,
+ size_t msglen),
+ void *user, bool debug)
+{
+ const char *dbgtag = debug ? ms->idtag : NULL;
+ struct mgmt_msg_hdr *mhdr;
+ struct stream *work;
+ uint8_t *data;
+ size_t left, nproc;
+
+ MGMT_MSG_DBG(dbgtag, "Have %zu streams to process", ms->inq.count);
+
+ nproc = 0;
+ while (nproc < ms->max_read_buf) {
+ work = stream_fifo_pop(&ms->inq);
+ if (!work)
+ break;
+
+ data = STREAM_DATA(work);
+ left = stream_get_endp(work);
+ MGMT_MSG_DBG(dbgtag, "Processing stream of len %zu", left);
+
+ for (; left > sizeof(struct mgmt_msg_hdr);
+ left -= mhdr->len, data += mhdr->len) {
+ mhdr = (struct mgmt_msg_hdr *)data;
+
+ assert(mhdr->marker == MGMT_MSG_MARKER);
+ assert(left >= mhdr->len);
+
+ handle_msg(user, (uint8_t *)(mhdr + 1),
+ mhdr->len - sizeof(struct mgmt_msg_hdr));
+ ms->nrxm++;
+ nproc++;
+ }
+
+ if (work != ms->ins)
+ stream_free(work); /* Free it up */
+ else
+ stream_reset(work); /* Reset stream for next read */
+ }
+
+ /* return true if should reschedule b/c more to process. */
+ return stream_fifo_head(&ms->inq) != NULL;
+}
+
+/**
+ * Write data from a onto the socket, using streams that have been queued for
+ * sending by mgmt_msg_send_msg. This function should be reschedulable.
+ *
+ * Args:
+ * ms: mgmt_msg_state for this process.
+ * fd: socket/file to read data from.
+ * debug: true to enable debug logging.
+ *
+ * Returns:
+ * MSW_SCHED_NONE - do not reschedule anything.
+ * MSW_SCHED_STREAM - this call should be rescheduled to run again.
+ * MSW_SCHED_WRITES_OFF - writes should be disabled with a timer to
+ * re-enable them a short time later
+ * MSW_DISCONNECT - socket should be closed and reconnect retried.
+ *run.
+ */
+enum mgmt_msg_wsched mgmt_msg_write(struct mgmt_msg_state *ms, int fd,
+ bool debug)
+{
+ const char *dbgtag = debug ? ms->idtag : NULL;
+ struct stream *s;
+ size_t nproc = 0;
+ ssize_t left;
+ ssize_t n;
+
+ if (ms->outs) {
+ MGMT_MSG_DBG(dbgtag,
+ "found unqueued stream with %zu bytes, queueing",
+ stream_get_endp(ms->outs));
+ stream_fifo_push(&ms->outq, ms->outs);
+ ms->outs = NULL;
+ }
+
+ for (s = stream_fifo_head(&ms->outq); s && nproc < ms->max_write_buf;
+ s = stream_fifo_head(&ms->outq)) {
+ left = STREAM_READABLE(s);
+ assert(left);
+
+ n = stream_flush(s, fd);
+ if (n <= 0) {
+ if (n == 0)
+ MGMT_MSG_ERR(ms,
+ "connection closed while writing");
+ else if (ERRNO_IO_RETRY(errno)) {
+ MGMT_MSG_DBG(
+ dbgtag,
+ "retry error while writing %zd bytes: %s (%d)",
+ left, safe_strerror(errno), errno);
+ return MSW_SCHED_STREAM;
+ } else
+ MGMT_MSG_ERR(
+ ms,
+ "error while writing %zd bytes: %s (%d)",
+ left, safe_strerror(errno), errno);
+
+ n = mgmt_msg_reset_writes(ms);
+ MGMT_MSG_DBG(dbgtag, "drop and freed %zd streams", n);
+
+ return MSW_DISCONNECT;
+ }
+
+ ms->ntxb += n;
+ if (n != left) {
+ MGMT_MSG_DBG(dbgtag, "short stream write %zd of %zd", n,
+ left);
+ stream_forward_getp(s, n);
+ return MSW_SCHED_STREAM;
+ }
+
+ stream_free(stream_fifo_pop(&ms->outq));
+ MGMT_MSG_DBG(dbgtag, "wrote stream of %zd bytes", n);
+ nproc++;
+ }
+ if (s) {
+ MGMT_MSG_DBG(
+ dbgtag,
+ "reached %zu buffer writes, pausing with %zu streams left",
+ ms->max_write_buf, ms->outq.count);
+ return MSW_SCHED_WRITES_OFF;
+ }
+ MGMT_MSG_DBG(dbgtag, "flushed all streams from output q");
+ return MSW_SCHED_NONE;
+}
+
+
+/**
+ * Send a message by enqueueing it to be written over the socket by
+ * mgmt_msg_write.
+ *
+ * Args:
+ * ms: mgmt_msg_state for this process.
+ * fd: socket/file to read data from.
+ * debug: true to enable debug logging.
+ *
+ * Returns:
+ * 0 on success, otherwise -1 on failure. The only failure mode is if a
+ * the message exceeds the maximum message size configured on init.
+ */
+int mgmt_msg_send_msg(struct mgmt_msg_state *ms, void *msg, size_t len,
+ mgmt_msg_packf packf, bool debug)
+{
+ const char *dbgtag = debug ? ms->idtag : NULL;
+ struct mgmt_msg_hdr *mhdr;
+ struct stream *s;
+ uint8_t *dstbuf;
+ size_t endp, n;
+ size_t mlen = len + sizeof(*mhdr);
+
+ if (mlen > ms->max_msg_sz) {
+ MGMT_MSG_ERR(ms, "Message %zu > max size %zu, dropping", mlen,
+ ms->max_msg_sz);
+ return -1;
+ }
+
+ if (!ms->outs) {
+ MGMT_MSG_DBG(dbgtag, "creating new stream for msg len %zu",
+ len);
+ ms->outs = stream_new(ms->max_msg_sz);
+ } else if (STREAM_WRITEABLE(ms->outs) < mlen) {
+ MGMT_MSG_DBG(
+ dbgtag,
+ "enq existing stream len %zu and creating new stream for msg len %zu",
+ STREAM_WRITEABLE(ms->outs), mlen);
+ stream_fifo_push(&ms->outq, ms->outs);
+ ms->outs = stream_new(ms->max_msg_sz);
+ } else {
+ MGMT_MSG_DBG(
+ dbgtag,
+ "using existing stream with avail %zu for msg len %zu",
+ STREAM_WRITEABLE(ms->outs), mlen);
+ }
+ s = ms->outs;
+
+ /* We have a stream with space, pack the message into it. */
+ mhdr = (struct mgmt_msg_hdr *)(STREAM_DATA(s) + s->endp);
+ mhdr->marker = MGMT_MSG_MARKER;
+ mhdr->len = mlen;
+ stream_forward_endp(s, sizeof(*mhdr));
+ endp = stream_get_endp(s);
+ dstbuf = STREAM_DATA(s) + endp;
+ n = packf(msg, dstbuf);
+ stream_set_endp(s, endp + n);
+ ms->ntxm++;
+
+ return 0;
+}
+
+/**
+ * Create and open a unix domain stream socket on the given path
+ * setting non-blocking and send and receive buffer sizes.
+ *
+ * Args:
+ * path: path of unix domain socket to connect to.
+ * sendbuf: size of socket send buffer.
+ * recvbuf: size of socket receive buffer.
+ * dbgtag: if non-NULL enable log debug, and use this tag.
+ *
+ * Returns:
+ * socket fd or -1 on error.
+ */
+int mgmt_msg_connect(const char *path, size_t sendbuf, size_t recvbuf,
+ const char *dbgtag)
+{
+ int ret, sock, len;
+ struct sockaddr_un addr;
+
+ MGMT_MSG_DBG(dbgtag, "connecting to server on %s", path);
+ sock = socket(AF_UNIX, SOCK_STREAM, 0);
+ if (sock < 0) {
+ MGMT_MSG_DBG(dbgtag, "socket failed: %s", safe_strerror(errno));
+ return -1;
+ }
+
+ memset(&addr, 0, sizeof(struct sockaddr_un));
+ addr.sun_family = AF_UNIX;
+ strlcpy(addr.sun_path, path, sizeof(addr.sun_path));
+#ifdef HAVE_STRUCT_SOCKADDR_UN_SUN_LEN
+ len = addr.sun_len = SUN_LEN(&addr);
+#else
+ len = sizeof(addr.sun_family) + strlen(addr.sun_path);
+#endif /* HAVE_STRUCT_SOCKADDR_UN_SUN_LEN */
+ ret = connect(sock, (struct sockaddr *)&addr, len);
+ if (ret < 0) {
+ MGMT_MSG_DBG(dbgtag, "failed to connect on %s: %s", path,
+ safe_strerror(errno));
+ close(sock);
+ return -1;
+ }
+
+ MGMT_MSG_DBG(dbgtag, "connected to server on %s", path);
+ set_nonblocking(sock);
+ setsockopt_so_sendbuf(sock, sendbuf);
+ setsockopt_so_recvbuf(sock, recvbuf);
+ return sock;
+}
+
+/**
+ * Reset the sending queue, by dequeueing all streams and freeing them. Return
+ * the number of streams freed.
+ *
+ * Args:
+ * ms: mgmt_msg_state for this process.
+ *
+ * Returns:
+ * Number of streams that were freed.
+ *
+ */
+size_t mgmt_msg_reset_writes(struct mgmt_msg_state *ms)
+{
+ struct stream *s;
+ size_t nproc = 0;
+
+ for (s = stream_fifo_pop(&ms->outq); s;
+ s = stream_fifo_pop(&ms->outq), nproc++)
+ stream_free(s);
+
+ return nproc;
+}
+
+void mgmt_msg_init(struct mgmt_msg_state *ms, size_t max_read_buf,
+ size_t max_write_buf, size_t max_msg_sz, const char *idtag)
+{
+ memset(ms, 0, sizeof(*ms));
+ ms->ins = stream_new(max_msg_sz);
+ stream_fifo_init(&ms->inq);
+ stream_fifo_init(&ms->outq);
+ ms->max_read_buf = max_write_buf;
+ ms->max_write_buf = max_read_buf;
+ ms->max_msg_sz = max_msg_sz;
+ ms->idtag = strdup(idtag);
+}
+
+void mgmt_msg_destroy(struct mgmt_msg_state *ms)
+{
+ mgmt_msg_reset_writes(ms);
+ if (ms->ins)
+ stream_free(ms->ins);
+ free(ms->idtag);
+}
diff --git a/lib/mgmt_msg.h b/lib/mgmt_msg.h
new file mode 100644
index 0000000000..e2dd2d476a
--- /dev/null
+++ b/lib/mgmt_msg.h
@@ -0,0 +1,73 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * March 6 2023, Christian Hopps <chopps@labn.net>
+ *
+ * Copyright (c) 2023, LabN Consulting, L.L.C.
+ */
+#ifndef _MGMT_MSG_H
+#define _MGMT_MSG_H
+
+#include "stream.h"
+#include "frrevent.h"
+
+#define MGMT_MSG_MARKER (0x4D724B21u) /* ASCII - "MrK!"*/
+
+struct mgmt_msg_state {
+ struct stream *ins;
+ struct stream *outs;
+ struct stream_fifo inq;
+ struct stream_fifo outq;
+ uint64_t nrxm; /* number of received messages */
+ uint64_t nrxb; /* number of received bytes */
+ uint64_t ntxm; /* number of sent messages */
+ uint64_t ntxb; /* number of sent bytes */
+ size_t max_read_buf; /* should replace with max time value */
+ size_t max_write_buf; /* should replace with max time value */
+ size_t max_msg_sz;
+ char *idtag; /* identifying tag for messages */
+};
+
+struct mgmt_msg_hdr {
+ uint32_t marker;
+ uint32_t len;
+};
+
+enum mgmt_msg_rsched {
+ MSR_SCHED_BOTH, /* schedule both queue and read */
+ MSR_SCHED_STREAM, /* schedule read */
+ MSR_DISCONNECT, /* disconnect and start reconnecting */
+};
+
+enum mgmt_msg_wsched {
+ MSW_SCHED_NONE, /* no scheduling required */
+ MSW_SCHED_STREAM, /* schedule writing */
+ MSW_SCHED_WRITES_OFF, /* toggle writes off */
+ MSW_DISCONNECT, /* disconnect and start reconnecting */
+};
+
+static inline uint8_t *msg_payload(struct mgmt_msg_hdr *mhdr)
+{
+ return (uint8_t *)(mhdr + 1);
+}
+
+typedef size_t (*mgmt_msg_packf)(void *msg, void *data);
+
+extern int mgmt_msg_connect(const char *path, size_t sendbuf, size_t recvbuf,
+ const char *dbgtag);
+extern void mgmt_msg_destroy(struct mgmt_msg_state *ms);
+extern void mgmt_msg_init(struct mgmt_msg_state *ms, size_t max_read_buf,
+ size_t max_write_buf, size_t max_msg_sz,
+ const char *idtag);
+extern bool mgmt_msg_procbufs(struct mgmt_msg_state *ms,
+ void (*handle_msg)(void *user, uint8_t *msg,
+ size_t msglen),
+ void *user, bool debug);
+extern enum mgmt_msg_rsched mgmt_msg_read(struct mgmt_msg_state *ms, int fd,
+ bool debug);
+extern size_t mgmt_msg_reset_writes(struct mgmt_msg_state *ms);
+extern int mgmt_msg_send_msg(struct mgmt_msg_state *ms, void *msg, size_t len,
+ size_t (*packf)(void *msg, void *buf), bool debug);
+extern enum mgmt_msg_wsched mgmt_msg_write(struct mgmt_msg_state *ms, int fd,
+ bool debug);
+
+#endif /* _MGMT_MSG_H */
diff --git a/lib/mgmt_pb.h b/lib/mgmt_pb.h
new file mode 100644
index 0000000000..08bb748233
--- /dev/null
+++ b/lib/mgmt_pb.h
@@ -0,0 +1,25 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * MGMTD protobuf main header file
+ * Copyright (C) 2021 Vmware, Inc.
+ * Pushpasis Sarkar <spushpasis@vmware.com>
+ */
+
+#ifndef _FRR_MGMTD_PB_H_
+#define _FRR_MGMTD_PB_H_
+
+#include "lib/mgmt.pb-c.h"
+
+#define mgmt_yang_data_xpath_init(ptr) mgmtd__yang_data_xpath__init(ptr)
+
+#define mgmt_yang_data_value_init(ptr) mgmtd__yang_data_value__init(ptr)
+
+#define mgmt_yang_data_init(ptr) mgmtd__yang_data__init(ptr)
+
+#define mgmt_yang_data_reply_init(ptr) mgmtd__yang_data_reply__init(ptr)
+
+#define mgmt_yang_cfg_data_req_init(ptr) mgmtd__yang_cfg_data_req__init(ptr)
+
+#define mgmt_yang_get_data_req_init(ptr) mgmtd__yang_get_data_req__init(ptr)
+
+#endif /* _FRR_MGMTD_PB_H_ */
diff --git a/lib/northbound.c b/lib/northbound.c
index 6f2c522a29..307cf0fb49 100644
--- a/lib/northbound.c
+++ b/lib/northbound.c
@@ -93,7 +93,9 @@ static int nb_node_new_cb(const struct lysc_node *snode, void *arg)
{
struct nb_node *nb_node;
struct lysc_node *sparent, *sparent_list;
+ struct frr_yang_module_info *module;
+ module = (struct frr_yang_module_info *)arg;
nb_node = XCALLOC(MTYPE_NB_NODE, sizeof(*nb_node));
yang_snode_get_path(snode, YANG_PATH_DATA, nb_node->xpath,
sizeof(nb_node->xpath));
@@ -128,6 +130,9 @@ static int nb_node_new_cb(const struct lysc_node *snode, void *arg)
assert(snode->priv == NULL);
((struct lysc_node *)snode)->priv = nb_node;
+ if (module && module->ignore_cbs)
+ SET_FLAG(nb_node->flags, F_NB_NODE_IGNORE_CBS);
+
return YANG_ITER_CONTINUE;
}
@@ -230,6 +235,9 @@ static unsigned int nb_node_validate_cbs(const struct nb_node *nb_node)
{
unsigned int error = 0;
+ if (CHECK_FLAG(nb_node->flags, F_NB_NODE_IGNORE_CBS))
+ return error;
+
error += nb_node_validate_cb(nb_node, NB_OP_CREATE,
!!nb_node->cbs.create, false);
error += nb_node_validate_cb(nb_node, NB_OP_MODIFY,
@@ -297,6 +305,8 @@ struct nb_config *nb_config_new(struct lyd_node *dnode)
config->dnode = yang_dnode_new(ly_native_ctx, true);
config->version = 0;
+ RB_INIT(nb_config_cbs, &config->cfg_chgs);
+
return config;
}
@@ -304,6 +314,7 @@ void nb_config_free(struct nb_config *config)
{
if (config->dnode)
yang_dnode_free(config->dnode);
+ nb_config_diff_del_changes(&config->cfg_chgs);
XFREE(MTYPE_NB_CONFIG, config);
}
@@ -315,6 +326,8 @@ struct nb_config *nb_config_dup(const struct nb_config *config)
dup->dnode = yang_dnode_dup(config->dnode);
dup->version = config->version;
+ RB_INIT(nb_config_cbs, &dup->cfg_chgs);
+
return dup;
}
@@ -405,7 +418,7 @@ static void nb_config_diff_add_change(struct nb_config_cbs *changes,
RB_INSERT(nb_config_cbs, changes, &change->cb);
}
-static void nb_config_diff_del_changes(struct nb_config_cbs *changes)
+void nb_config_diff_del_changes(struct nb_config_cbs *changes)
{
while (!RB_EMPTY(nb_config_cbs, changes)) {
struct nb_config_change *change;
@@ -422,8 +435,8 @@ static void nb_config_diff_del_changes(struct nb_config_cbs *changes)
* configurations. Given a new subtree, calculate all new YANG data nodes,
* excluding default leafs and leaf-lists. This is a recursive function.
*/
-static void nb_config_diff_created(const struct lyd_node *dnode, uint32_t *seq,
- struct nb_config_cbs *changes)
+void nb_config_diff_created(const struct lyd_node *dnode, uint32_t *seq,
+ struct nb_config_cbs *changes)
{
enum nb_operation operation;
struct lyd_node *child;
@@ -525,10 +538,16 @@ static inline void nb_config_diff_dnode_log(const char *context,
}
#endif
-/* Calculate the delta between two different configurations. */
-static void nb_config_diff(const struct nb_config *config1,
- const struct nb_config *config2,
- struct nb_config_cbs *changes)
+/*
+ * Calculate the delta between two different configurations.
+ *
+ * NOTE: 'config1' is the reference DB, while 'config2' is
+ * the DB being compared against 'config1'. Typically 'config1'
+ * should be the Running DB and 'config2' is the Candidate DB.
+ */
+void nb_config_diff(const struct nb_config *config1,
+ const struct nb_config *config2,
+ struct nb_config_cbs *changes)
{
struct lyd_node *diff = NULL;
const struct lyd_node *root, *dnode;
@@ -734,6 +753,169 @@ int nb_candidate_edit(struct nb_config *candidate,
return NB_OK;
}
+static void nb_update_candidate_changes(struct nb_config *candidate,
+ struct nb_cfg_change *change,
+ uint32_t *seq)
+{
+ enum nb_operation oper = change->operation;
+ char *xpath = change->xpath;
+ struct lyd_node *root = NULL;
+ struct lyd_node *dnode;
+ struct nb_config_cbs *cfg_chgs = &candidate->cfg_chgs;
+ int op;
+
+ switch (oper) {
+ case NB_OP_CREATE:
+ case NB_OP_MODIFY:
+ root = yang_dnode_get(candidate->dnode, xpath);
+ break;
+ case NB_OP_DESTROY:
+ root = yang_dnode_get(running_config->dnode, xpath);
+ /* code */
+ break;
+ case NB_OP_MOVE:
+ case NB_OP_PRE_VALIDATE:
+ case NB_OP_APPLY_FINISH:
+ case NB_OP_GET_ELEM:
+ case NB_OP_GET_NEXT:
+ case NB_OP_GET_KEYS:
+ case NB_OP_LOOKUP_ENTRY:
+ case NB_OP_RPC:
+ break;
+ default:
+ assert(!"non-enum value, invalid");
+ }
+
+ if (!root)
+ return;
+
+ LYD_TREE_DFS_BEGIN (root, dnode) {
+ op = nb_lyd_diff_get_op(dnode);
+ switch (op) {
+ case 'c':
+ nb_config_diff_created(dnode, seq, cfg_chgs);
+ LYD_TREE_DFS_continue = 1;
+ break;
+ case 'd':
+ nb_config_diff_deleted(dnode, seq, cfg_chgs);
+ LYD_TREE_DFS_continue = 1;
+ break;
+ case 'r':
+ nb_config_diff_add_change(cfg_chgs, NB_OP_MODIFY, seq,
+ dnode);
+ break;
+ default:
+ break;
+ }
+ LYD_TREE_DFS_END(root, dnode);
+ }
+}
+
+static bool nb_is_operation_allowed(struct nb_node *nb_node,
+ struct nb_cfg_change *change)
+{
+ enum nb_operation oper = change->operation;
+
+ if (lysc_is_key(nb_node->snode)) {
+ if (oper == NB_OP_MODIFY || oper == NB_OP_DESTROY)
+ return false;
+ }
+ return true;
+}
+
+void nb_candidate_edit_config_changes(
+ struct nb_config *candidate_config, struct nb_cfg_change cfg_changes[],
+ size_t num_cfg_changes, const char *xpath_base, const char *curr_xpath,
+ int xpath_index, char *err_buf, int err_bufsize, bool *error)
+{
+ uint32_t seq = 0;
+
+ if (error)
+ *error = false;
+
+ if (xpath_base == NULL)
+ xpath_base = "";
+
+ /* Edit candidate configuration. */
+ for (size_t i = 0; i < num_cfg_changes; i++) {
+ struct nb_cfg_change *change = &cfg_changes[i];
+ struct nb_node *nb_node;
+ char xpath[XPATH_MAXLEN];
+ struct yang_data *data;
+ int ret;
+
+ /* Handle relative XPaths. */
+ memset(xpath, 0, sizeof(xpath));
+ if (xpath_index > 0 &&
+ (xpath_base[0] == '.' || change->xpath[0] == '.'))
+ strlcpy(xpath, curr_xpath, sizeof(xpath));
+ if (xpath_base[0]) {
+ if (xpath_base[0] == '.')
+ strlcat(xpath, xpath_base + 1, sizeof(xpath));
+ else
+ strlcat(xpath, xpath_base, sizeof(xpath));
+ }
+ if (change->xpath[0] == '.')
+ strlcat(xpath, change->xpath + 1, sizeof(xpath));
+ else
+ strlcpy(xpath, change->xpath, sizeof(xpath));
+
+ /* Find the northbound node associated to the data path. */
+ nb_node = nb_node_find(xpath);
+ if (!nb_node) {
+ flog_warn(EC_LIB_YANG_UNKNOWN_DATA_PATH,
+ "%s: unknown data path: %s", __func__, xpath);
+ if (error)
+ *error = true;
+ continue;
+ }
+ /* Find if the node to be edited is not a key node */
+ if (!nb_is_operation_allowed(nb_node, change)) {
+ zlog_err(" Xpath %s points to key node", xpath);
+ if (error)
+ *error = true;
+ break;
+ }
+
+ /* If the value is not set, get the default if it exists. */
+ if (change->value == NULL)
+ change->value = yang_snode_get_default(nb_node->snode);
+ data = yang_data_new(xpath, change->value);
+
+ /*
+ * Ignore "not found" errors when editing the candidate
+ * configuration.
+ */
+ ret = nb_candidate_edit(candidate_config, nb_node,
+ change->operation, xpath, NULL, data);
+ yang_data_free(data);
+ if (ret != NB_OK && ret != NB_ERR_NOT_FOUND) {
+ flog_warn(
+ EC_LIB_NB_CANDIDATE_EDIT_ERROR,
+ "%s: failed to edit candidate configuration: operation [%s] xpath [%s]",
+ __func__, nb_operation_name(change->operation),
+ xpath);
+ if (error)
+ *error = true;
+ continue;
+ }
+ nb_update_candidate_changes(candidate_config, change, &seq);
+ }
+
+ if (error && *error) {
+ char buf[BUFSIZ];
+
+ /*
+ * Failure to edit the candidate configuration should never
+ * happen in practice, unless there's a bug in the code. When
+ * that happens, log the error but otherwise ignore it.
+ */
+ snprintf(err_buf, err_bufsize,
+ "%% Failed to edit configuration.\n\n%s",
+ yang_print_errors(ly_native_ctx, buf, sizeof(buf)));
+ }
+}
+
bool nb_candidate_needs_update(const struct nb_config *candidate)
{
if (candidate->version < running_config->version)
@@ -761,12 +943,13 @@ int nb_candidate_update(struct nb_config *candidate)
* WARNING: lyd_validate() can change the configuration as part of the
* validation process.
*/
-static int nb_candidate_validate_yang(struct nb_config *candidate, char *errmsg,
- size_t errmsg_len)
+int nb_candidate_validate_yang(struct nb_config *candidate, bool no_state,
+ char *errmsg, size_t errmsg_len)
{
if (lyd_validate_all(&candidate->dnode, ly_native_ctx,
- LYD_VALIDATE_NO_STATE, NULL)
- != 0) {
+ no_state ? LYD_VALIDATE_NO_STATE
+ : LYD_VALIDATE_PRESENT,
+ NULL) != 0) {
yang_print_errors(ly_native_ctx, errmsg, errmsg_len);
return NB_ERR_VALIDATION;
}
@@ -775,10 +958,10 @@ static int nb_candidate_validate_yang(struct nb_config *candidate, char *errmsg,
}
/* Perform code-level validation using the northbound callbacks. */
-static int nb_candidate_validate_code(struct nb_context *context,
- struct nb_config *candidate,
- struct nb_config_cbs *changes,
- char *errmsg, size_t errmsg_len)
+int nb_candidate_validate_code(struct nb_context *context,
+ struct nb_config *candidate,
+ struct nb_config_cbs *changes, char *errmsg,
+ size_t errmsg_len)
{
struct nb_config_cb *cb;
struct lyd_node *root, *child;
@@ -816,6 +999,21 @@ static int nb_candidate_validate_code(struct nb_context *context,
return NB_OK;
}
+int nb_candidate_diff_and_validate_yang(struct nb_context *context,
+ struct nb_config *candidate,
+ struct nb_config_cbs *changes,
+ char *errmsg, size_t errmsg_len)
+{
+ if (nb_candidate_validate_yang(candidate, true, errmsg,
+ sizeof(errmsg_len)) != NB_OK)
+ return NB_ERR_VALIDATION;
+
+ RB_INIT(nb_config_cbs, changes);
+ nb_config_diff(running_config, candidate, changes);
+
+ return NB_OK;
+}
+
int nb_candidate_validate(struct nb_context *context,
struct nb_config *candidate, char *errmsg,
size_t errmsg_len)
@@ -823,11 +1021,11 @@ int nb_candidate_validate(struct nb_context *context,
struct nb_config_cbs changes;
int ret;
- if (nb_candidate_validate_yang(candidate, errmsg, errmsg_len) != NB_OK)
- return NB_ERR_VALIDATION;
+ ret = nb_candidate_diff_and_validate_yang(context, candidate, &changes,
+ errmsg, errmsg_len);
+ if (ret != NB_OK)
+ return ret;
- RB_INIT(nb_config_cbs, &changes);
- nb_config_diff(running_config, candidate, &changes);
ret = nb_candidate_validate_code(context, candidate, &changes, errmsg,
errmsg_len);
nb_config_diff_del_changes(&changes);
@@ -839,12 +1037,14 @@ int nb_candidate_commit_prepare(struct nb_context context,
struct nb_config *candidate,
const char *comment,
struct nb_transaction **transaction,
+ bool skip_validate, bool ignore_zero_change,
char *errmsg, size_t errmsg_len)
{
struct nb_config_cbs changes;
- if (nb_candidate_validate_yang(candidate, errmsg, errmsg_len)
- != NB_OK) {
+ if (!skip_validate &&
+ nb_candidate_validate_yang(candidate, true, errmsg, errmsg_len) !=
+ NB_OK) {
flog_warn(EC_LIB_NB_CANDIDATE_INVALID,
"%s: failed to validate candidate configuration",
__func__);
@@ -853,14 +1053,15 @@ int nb_candidate_commit_prepare(struct nb_context context,
RB_INIT(nb_config_cbs, &changes);
nb_config_diff(running_config, candidate, &changes);
- if (RB_EMPTY(nb_config_cbs, &changes)) {
+ if (!ignore_zero_change && RB_EMPTY(nb_config_cbs, &changes)) {
snprintf(
errmsg, errmsg_len,
"No changes to apply were found during preparation phase");
return NB_ERR_NO_CHANGES;
}
- if (nb_candidate_validate_code(&context, candidate, &changes, errmsg,
+ if (!skip_validate &&
+ nb_candidate_validate_code(&context, candidate, &changes, errmsg,
errmsg_len) != NB_OK) {
flog_warn(EC_LIB_NB_CANDIDATE_INVALID,
"%s: failed to validate candidate configuration",
@@ -869,8 +1070,12 @@ int nb_candidate_commit_prepare(struct nb_context context,
return NB_ERR_VALIDATION;
}
- *transaction = nb_transaction_new(context, candidate, &changes, comment,
- errmsg, errmsg_len);
+ /*
+ * Re-use an existing transaction if provided. Else allocate a new one.
+ */
+ if (!*transaction)
+ *transaction = nb_transaction_new(context, candidate, &changes,
+ comment, errmsg, errmsg_len);
if (*transaction == NULL) {
flog_warn(EC_LIB_NB_TRANSACTION_CREATION_FAILED,
"%s: failed to create transaction: %s", __func__,
@@ -921,7 +1126,8 @@ int nb_candidate_commit(struct nb_context context, struct nb_config *candidate,
int ret;
ret = nb_candidate_commit_prepare(context, candidate, comment,
- &transaction, errmsg, errmsg_len);
+ &transaction, false, false, errmsg,
+ errmsg_len);
/*
* Apply the changes if the preparation phase succeeded. Otherwise abort
* the transaction.
@@ -1015,6 +1221,8 @@ static int nb_callback_create(struct nb_context *context,
bool unexpected_error = false;
int ret;
+ assert(!CHECK_FLAG(nb_node->flags, F_NB_NODE_IGNORE_CBS));
+
nb_log_config_callback(event, NB_OP_CREATE, dnode);
args.context = context;
@@ -1064,6 +1272,8 @@ static int nb_callback_modify(struct nb_context *context,
bool unexpected_error = false;
int ret;
+ assert(!CHECK_FLAG(nb_node->flags, F_NB_NODE_IGNORE_CBS));
+
nb_log_config_callback(event, NB_OP_MODIFY, dnode);
args.context = context;
@@ -1113,6 +1323,8 @@ static int nb_callback_destroy(struct nb_context *context,
bool unexpected_error = false;
int ret;
+ assert(!CHECK_FLAG(nb_node->flags, F_NB_NODE_IGNORE_CBS));
+
nb_log_config_callback(event, NB_OP_DESTROY, dnode);
args.context = context;
@@ -1156,6 +1368,8 @@ static int nb_callback_move(struct nb_context *context,
bool unexpected_error = false;
int ret;
+ assert(!CHECK_FLAG(nb_node->flags, F_NB_NODE_IGNORE_CBS));
+
nb_log_config_callback(event, NB_OP_MOVE, dnode);
args.context = context;
@@ -1199,6 +1413,9 @@ static int nb_callback_pre_validate(struct nb_context *context,
bool unexpected_error = false;
int ret;
+ if (CHECK_FLAG(nb_node->flags, F_NB_NODE_IGNORE_CBS))
+ return 0;
+
nb_log_config_callback(NB_EV_VALIDATE, NB_OP_PRE_VALIDATE, dnode);
args.dnode = dnode;
@@ -1230,6 +1447,9 @@ static void nb_callback_apply_finish(struct nb_context *context,
{
struct nb_cb_apply_finish_args args = {};
+ if (CHECK_FLAG(nb_node->flags, F_NB_NODE_IGNORE_CBS))
+ return;
+
nb_log_config_callback(NB_EV_APPLY, NB_OP_APPLY_FINISH, dnode);
args.context = context;
@@ -1245,6 +1465,9 @@ struct yang_data *nb_callback_get_elem(const struct nb_node *nb_node,
{
struct nb_cb_get_elem_args args = {};
+ if (CHECK_FLAG(nb_node->flags, F_NB_NODE_IGNORE_CBS))
+ return NULL;
+
DEBUGD(&nb_dbg_cbs_state,
"northbound callback (get_elem): xpath [%s] list_entry [%p]",
xpath, list_entry);
@@ -1260,6 +1483,9 @@ const void *nb_callback_get_next(const struct nb_node *nb_node,
{
struct nb_cb_get_next_args args = {};
+ if (CHECK_FLAG(nb_node->flags, F_NB_NODE_IGNORE_CBS))
+ return NULL;
+
DEBUGD(&nb_dbg_cbs_state,
"northbound callback (get_next): node [%s] parent_list_entry [%p] list_entry [%p]",
nb_node->xpath, parent_list_entry, list_entry);
@@ -1274,6 +1500,9 @@ int nb_callback_get_keys(const struct nb_node *nb_node, const void *list_entry,
{
struct nb_cb_get_keys_args args = {};
+ if (CHECK_FLAG(nb_node->flags, F_NB_NODE_IGNORE_CBS))
+ return 0;
+
DEBUGD(&nb_dbg_cbs_state,
"northbound callback (get_keys): node [%s] list_entry [%p]",
nb_node->xpath, list_entry);
@@ -1289,6 +1518,9 @@ const void *nb_callback_lookup_entry(const struct nb_node *nb_node,
{
struct nb_cb_lookup_entry_args args = {};
+ if (CHECK_FLAG(nb_node->flags, F_NB_NODE_IGNORE_CBS))
+ return NULL;
+
DEBUGD(&nb_dbg_cbs_state,
"northbound callback (lookup_entry): node [%s] parent_list_entry [%p]",
nb_node->xpath, parent_list_entry);
@@ -1304,6 +1536,9 @@ int nb_callback_rpc(const struct nb_node *nb_node, const char *xpath,
{
struct nb_cb_rpc_args args = {};
+ if (CHECK_FLAG(nb_node->flags, F_NB_NODE_IGNORE_CBS))
+ return 0;
+
DEBUGD(&nb_dbg_cbs_rpc, "northbound RPC: %s", xpath);
args.xpath = xpath;
@@ -1330,6 +1565,9 @@ static int nb_callback_configuration(struct nb_context *context,
union nb_resource *resource;
int ret = NB_ERR;
+ if (CHECK_FLAG(nb_node->flags, F_NB_NODE_IGNORE_CBS))
+ return NB_OK;
+
if (event == NB_EV_VALIDATE)
resource = NULL;
else
@@ -1733,7 +1971,7 @@ static int nb_oper_data_iter_list(const struct nb_node *nb_node,
/* Iterate over all list entries. */
do {
const struct lysc_node_leaf *skey;
- struct yang_list_keys list_keys;
+ struct yang_list_keys list_keys = {};
char xpath[XPATH_MAXLEN * 2];
int ret;
@@ -2389,6 +2627,10 @@ const char *nb_client_name(enum nb_client client)
return "gRPC";
case NB_CLIENT_PCEP:
return "Pcep";
+ case NB_CLIENT_MGMTD_SERVER:
+ return "MGMTD Server";
+ case NB_CLIENT_MGMTD_BE:
+ return "MGMT Backend";
case NB_CLIENT_NONE:
return "None";
}
@@ -2398,6 +2640,10 @@ const char *nb_client_name(enum nb_client client)
static void nb_load_callbacks(const struct frr_yang_module_info *module)
{
+
+ if (module->ignore_cbs)
+ return;
+
for (size_t i = 0; module->nodes[i].xpath; i++) {
struct nb_node *nb_node;
uint32_t priority;
@@ -2439,7 +2685,7 @@ void nb_validate_callbacks(void)
}
-void nb_init(struct thread_master *tm,
+void nb_init(struct event_loop *tm,
const struct frr_yang_module_info *const modules[],
size_t nmodules, bool db_enabled)
{
@@ -2471,7 +2717,8 @@ void nb_init(struct thread_master *tm,
/* Initialize the compiled nodes with northbound data */
for (size_t i = 0; i < nmodules; i++) {
- yang_snodes_iterate(loaded[i]->info, nb_node_new_cb, 0, NULL);
+ yang_snodes_iterate(loaded[i]->info, nb_node_new_cb, 0,
+ (void *)modules[i]);
nb_load_callbacks(modules[i]);
}
@@ -2498,8 +2745,7 @@ void nb_terminate(void)
nb_nodes_delete();
/* Delete the running configuration. */
- hash_clean(running_config_entries, running_config_entry_free);
- hash_free(running_config_entries);
+ hash_clean_and_free(&running_config_entries, running_config_entry_free);
nb_config_free(running_config);
pthread_mutex_destroy(&running_config_mgmt_lock.mtx);
}
diff --git a/lib/northbound.h b/lib/northbound.h
index 152810b3a9..1723a87e4e 100644
--- a/lib/northbound.h
+++ b/lib/northbound.h
@@ -7,7 +7,7 @@
#ifndef _FRR_NORTHBOUND_H_
#define _FRR_NORTHBOUND_H_
-#include "thread.h"
+#include "frrevent.h"
#include "hook.h"
#include "linklist.h"
#include "openbsd-tree.h"
@@ -22,6 +22,39 @@ extern "C" {
struct vty;
struct debug;
+struct nb_yang_xpath_tag {
+ uint32_t ns;
+ uint32_t id;
+};
+
+struct nb_yang_value {
+ struct lyd_value value;
+ LY_DATA_TYPE value_type;
+ uint8_t value_flags;
+};
+
+struct nb_yang_xpath_elem {
+ struct nb_yang_xpath_tag tag;
+ struct nb_yang_value val;
+};
+
+#define NB_MAX_NUM_KEYS UINT8_MAX
+#define NB_MAX_NUM_XPATH_TAGS UINT8_MAX
+
+struct nb_yang_xpath {
+ uint8_t length;
+ struct {
+ uint8_t num_keys;
+ struct nb_yang_xpath_elem keys[NB_MAX_NUM_KEYS];
+ } tags[NB_MAX_NUM_XPATH_TAGS];
+};
+
+#define NB_YANG_XPATH_KEY(__xpath, __indx1, __indx2) \
+ ((__xpath->num_tags > __indx1) && \
+ (__xpath->tags[__indx1].num_keys > __indx2) \
+ ? &__xpath->tags[__indx1].keys[__indx2] \
+ : NULL)
+
/* Northbound events. */
enum nb_event {
/*
@@ -68,6 +101,12 @@ enum nb_operation {
NB_OP_RPC,
};
+struct nb_cfg_change {
+ char xpath[XPATH_MAXLEN];
+ enum nb_operation operation;
+ const char *value;
+};
+
union nb_resource {
int fd;
void *ptr;
@@ -558,6 +597,8 @@ struct nb_node {
#define F_NB_NODE_CONFIG_ONLY 0x01
/* The YANG list doesn't contain key leafs. */
#define F_NB_NODE_KEYLESS_LIST 0x02
+/* Ignore callbacks for this node */
+#define F_NB_NODE_IGNORE_CBS 0x04
/*
* HACK: old gcc versions (< 5.x) have a bug that prevents C99 flexible arrays
@@ -570,6 +611,12 @@ struct frr_yang_module_info {
/* YANG module name. */
const char *name;
+ /*
+ * Ignore callbacks for this module. Set this to true to
+ * load module without any callbacks.
+ */
+ bool ignore_cbs;
+
/* Northbound callbacks. */
const struct {
/* Data path of this YANG node. */
@@ -613,6 +660,8 @@ enum nb_client {
NB_CLIENT_SYSREPO,
NB_CLIENT_GRPC,
NB_CLIENT_PCEP,
+ NB_CLIENT_MGMTD_SERVER,
+ NB_CLIENT_MGMTD_BE,
};
/* Northbound context. */
@@ -624,12 +673,6 @@ struct nb_context {
const void *user;
};
-/* Northbound configuration. */
-struct nb_config {
- struct lyd_node *dnode;
- uint32_t version;
-};
-
/* Northbound configuration callback. */
struct nb_config_cb {
RB_ENTRY(nb_config_cb) entry;
@@ -656,6 +699,13 @@ struct nb_transaction {
struct nb_config_cbs changes;
};
+/* Northbound configuration. */
+struct nb_config {
+ struct lyd_node *dnode;
+ uint32_t version;
+ struct nb_config_cbs cfg_chgs;
+};
+
/* Callback function used by nb_oper_data_iterate(). */
typedef int (*nb_oper_data_cb)(const struct lysc_node *snode,
struct yang_translator *translator,
@@ -826,6 +876,22 @@ extern int nb_candidate_edit(struct nb_config *candidate,
const struct yang_data *data);
/*
+ * Create diff for configuration.
+ *
+ * dnode
+ * Pointer to a libyang data node containing the configuration data. If NULL
+ * is given, an empty configuration will be created.
+ *
+ * seq
+ * Returns sequence number assigned to the specific change.
+ *
+ * changes
+ * Northbound config callback head.
+ */
+extern void nb_config_diff_created(const struct lyd_node *dnode, uint32_t *seq,
+ struct nb_config_cbs *changes);
+
+/*
* Check if a candidate configuration is outdated and needs to be updated.
*
* candidate
@@ -837,6 +903,140 @@ extern int nb_candidate_edit(struct nb_config *candidate,
extern bool nb_candidate_needs_update(const struct nb_config *candidate);
/*
+ * Edit candidate configuration changes.
+ *
+ * candidate_config
+ * Candidate configuration to edit.
+ *
+ * cfg_changes
+ * Northbound config changes.
+ *
+ * num_cfg_changes
+ * Number of config changes.
+ *
+ * xpath_base
+ * Base xpath for config.
+ *
+ * curr_xpath
+ * Current xpath for config.
+ *
+ * xpath_index
+ * Index of xpath being processed.
+ *
+ * err_buf
+ * Buffer to store human-readable error message in case of error.
+ *
+ * err_bufsize
+ * Size of err_buf.
+ *
+ * error
+ * TRUE on error, FALSE on success
+ */
+extern void nb_candidate_edit_config_changes(
+ struct nb_config *candidate_config, struct nb_cfg_change cfg_changes[],
+ size_t num_cfg_changes, const char *xpath_base, const char *curr_xpath,
+ int xpath_index, char *err_buf, int err_bufsize, bool *error);
+
+/*
+ * Delete candidate configuration changes.
+ *
+ * changes
+ * Northbound config changes.
+ */
+extern void nb_config_diff_del_changes(struct nb_config_cbs *changes);
+
+/*
+ * Create candidate diff and validate on yang tree
+ *
+ * context
+ * Context of the northbound transaction.
+ *
+ * candidate
+ * Candidate DB configuration.
+ *
+ * changes
+ * Northbound config changes.
+ *
+ * errmsg
+ * Buffer to store human-readable error message in case of error.
+ *
+ * errmsg_len
+ * Size of errmsg.
+ *
+ * Returns:
+ * NB_OK on success, NB_ERR_VALIDATION otherwise
+ */
+extern int nb_candidate_diff_and_validate_yang(struct nb_context *context,
+ struct nb_config *candidate,
+ struct nb_config_cbs *changes,
+ char *errmsg, size_t errmsg_len);
+
+/*
+ * Calculate the delta between two different configurations.
+ *
+ * reference
+ * Running DB config changes to be compared against.
+ *
+ * incremental
+ * Candidate DB config changes that will be compared against reference.
+ *
+ * changes
+ * Will hold the final diff generated.
+ *
+ */
+extern void nb_config_diff(const struct nb_config *reference,
+ const struct nb_config *incremental,
+ struct nb_config_cbs *changes);
+
+/*
+ * Perform YANG syntactic and semantic validation.
+ *
+ * WARNING: lyd_validate() can change the configuration as part of the
+ * validation process.
+ *
+ * candidate
+ * Candidate DB configuration.
+ *
+ * errmsg
+ * Buffer to store human-readable error message in case of error.
+ *
+ * errmsg_len
+ * Size of errmsg.
+ *
+ * Returns:
+ * NB_OK on success, NB_ERR_VALIDATION otherwise
+ */
+extern int nb_candidate_validate_yang(struct nb_config *candidate,
+ bool no_state, char *errmsg,
+ size_t errmsg_len);
+
+/*
+ * Perform code-level validation using the northbound callbacks.
+ *
+ * context
+ * Context of the northbound transaction.
+ *
+ * candidate
+ * Candidate DB configuration.
+ *
+ * changes
+ * Northbound config changes.
+ *
+ * errmsg
+ * Buffer to store human-readable error message in case of error.
+ *
+ * errmsg_len
+ * Size of errmsg.
+ *
+ * Returns:
+ * NB_OK on success, NB_ERR_VALIDATION otherwise
+ */
+extern int nb_candidate_validate_code(struct nb_context *context,
+ struct nb_config *candidate,
+ struct nb_config_cbs *changes,
+ char *errmsg, size_t errmsg_len);
+
+/*
* Update a candidate configuration by rebasing the changes on top of the latest
* running configuration. Resolve conflicts automatically by giving preference
* to the changes done in the candidate configuration.
@@ -895,6 +1095,12 @@ extern int nb_candidate_validate(struct nb_context *context,
* nb_candidate_commit_abort() or committed using
* nb_candidate_commit_apply().
*
+ * skip_validate
+ * TRUE to skip commit validation, FALSE otherwise.
+ *
+ * ignore_zero_change
+ * TRUE to ignore if zero changes, FALSE otherwise.
+ *
* errmsg
* Buffer to store human-readable error message in case of error.
*
@@ -915,7 +1121,9 @@ extern int nb_candidate_commit_prepare(struct nb_context context,
struct nb_config *candidate,
const char *comment,
struct nb_transaction **transaction,
- char *errmsg, size_t errmsg_len);
+ bool skip_validate,
+ bool ignore_zero_change, char *errmsg,
+ size_t errmsg_len);
/*
* Abort a previously created configuration transaction, releasing all resources
@@ -1270,7 +1478,7 @@ void nb_validate_callbacks(void);
* db_enabled
* Set this to record the transactions in the transaction log.
*/
-extern void nb_init(struct thread_master *tm,
+extern void nb_init(struct event_loop *tm,
const struct frr_yang_module_info *const modules[],
size_t nmodules, bool db_enabled);
diff --git a/lib/northbound_cli.c b/lib/northbound_cli.c
index fa5884fb78..5cf5f93b43 100644
--- a/lib/northbound_cli.c
+++ b/lib/northbound_cli.c
@@ -29,7 +29,7 @@ struct debug nb_dbg_events = {0, "Northbound events"};
struct debug nb_dbg_libyang = {0, "libyang debugging"};
struct nb_config *vty_shared_candidate_config;
-static struct thread_master *master;
+static struct event_loop *master;
static void vty_show_nb_errors(struct vty *vty, int error, const char *errmsg)
{
@@ -120,7 +120,7 @@ static int nb_cli_schedule_command(struct vty *vty)
void nb_cli_enqueue_change(struct vty *vty, const char *xpath,
enum nb_operation operation, const char *value)
{
- struct vty_cfg_change *change;
+ struct nb_cfg_change *change;
if (vty->num_cfg_changes == VTY_MAXCFGCHANGES) {
/* Not expected to happen. */
@@ -141,79 +141,21 @@ static int nb_cli_apply_changes_internal(struct vty *vty,
bool clear_pending)
{
bool error = false;
-
- if (xpath_base == NULL)
- xpath_base = "";
+ char buf[BUFSIZ];
VTY_CHECK_XPATH;
- /* Edit candidate configuration. */
- for (size_t i = 0; i < vty->num_cfg_changes; i++) {
- struct vty_cfg_change *change = &vty->cfg_changes[i];
- struct nb_node *nb_node;
- char xpath[XPATH_MAXLEN];
- struct yang_data *data;
- int ret;
-
- /* Handle relative XPaths. */
- memset(xpath, 0, sizeof(xpath));
- if (vty->xpath_index > 0
- && (xpath_base[0] == '.' || change->xpath[0] == '.'))
- strlcpy(xpath, VTY_CURR_XPATH, sizeof(xpath));
- if (xpath_base[0]) {
- if (xpath_base[0] == '.')
- strlcat(xpath, xpath_base + 1, sizeof(xpath));
- else
- strlcat(xpath, xpath_base, sizeof(xpath));
- }
- if (change->xpath[0] == '.')
- strlcat(xpath, change->xpath + 1, sizeof(xpath));
- else
- strlcpy(xpath, change->xpath, sizeof(xpath));
-
- /* Find the northbound node associated to the data path. */
- nb_node = nb_node_find(xpath);
- if (!nb_node) {
- flog_warn(EC_LIB_YANG_UNKNOWN_DATA_PATH,
- "%s: unknown data path: %s", __func__, xpath);
- error = true;
- continue;
- }
-
- /* If the value is not set, get the default if it exists. */
- if (change->value == NULL)
- change->value = yang_snode_get_default(nb_node->snode);
- data = yang_data_new(xpath, change->value);
-
- /*
- * Ignore "not found" errors when editing the candidate
- * configuration.
- */
- ret = nb_candidate_edit(vty->candidate_config, nb_node,
- change->operation, xpath, NULL, data);
- yang_data_free(data);
- if (ret != NB_OK && ret != NB_ERR_NOT_FOUND) {
- flog_warn(
- EC_LIB_NB_CANDIDATE_EDIT_ERROR,
- "%s: failed to edit candidate configuration: operation [%s] xpath [%s]",
- __func__, nb_operation_name(change->operation),
- xpath);
- error = true;
- continue;
- }
- }
-
+ nb_candidate_edit_config_changes(
+ vty->candidate_config, vty->cfg_changes, vty->num_cfg_changes,
+ xpath_base, VTY_CURR_XPATH, vty->xpath_index, buf, sizeof(buf),
+ &error);
if (error) {
- char buf[BUFSIZ];
-
/*
* Failure to edit the candidate configuration should never
* happen in practice, unless there's a bug in the code. When
* that happens, log the error but otherwise ignore it.
*/
- vty_out(vty, "%% Failed to edit configuration.\n\n");
- vty_out(vty, "%s",
- yang_print_errors(ly_native_ctx, buf, sizeof(buf)));
+ vty_out(vty, "%s", buf);
}
/*
@@ -241,6 +183,8 @@ static int nb_cli_apply_changes_internal(struct vty *vty,
int nb_cli_apply_changes(struct vty *vty, const char *xpath_base_fmt, ...)
{
char xpath_base[XPATH_MAXLEN] = {};
+ bool implicit_commit;
+ int ret;
/* Parse the base XPath format string. */
if (xpath_base_fmt) {
@@ -250,6 +194,17 @@ int nb_cli_apply_changes(struct vty *vty, const char *xpath_base_fmt, ...)
vsnprintf(xpath_base, sizeof(xpath_base), xpath_base_fmt, ap);
va_end(ap);
}
+
+ if (vty_mgmt_fe_enabled()) {
+ VTY_CHECK_XPATH;
+
+ implicit_commit = vty_needs_implicit_commit(vty);
+ ret = vty_mgmt_send_config_data(vty);
+ if (ret >= 0 && !implicit_commit)
+ vty->mgmt_num_pending_setcfg++;
+ return ret;
+ }
+
return nb_cli_apply_changes_internal(vty, xpath_base, false);
}
@@ -257,6 +212,8 @@ int nb_cli_apply_changes_clear_pending(struct vty *vty,
const char *xpath_base_fmt, ...)
{
char xpath_base[XPATH_MAXLEN] = {};
+ bool implicit_commit;
+ int ret;
/* Parse the base XPath format string. */
if (xpath_base_fmt) {
@@ -266,6 +223,17 @@ int nb_cli_apply_changes_clear_pending(struct vty *vty,
vsnprintf(xpath_base, sizeof(xpath_base), xpath_base_fmt, ap);
va_end(ap);
}
+
+ if (vty_mgmt_fe_enabled()) {
+ VTY_CHECK_XPATH;
+
+ implicit_commit = vty_needs_implicit_commit(vty);
+ ret = vty_mgmt_send_config_data(vty);
+ if (ret >= 0 && !implicit_commit)
+ vty->mgmt_num_pending_setcfg++;
+ return ret;
+ }
+
return nb_cli_apply_changes_internal(vty, xpath_base, true);
}
@@ -297,7 +265,7 @@ int nb_cli_rpc(struct vty *vty, const char *xpath, struct list *input,
void nb_cli_confirmed_commit_clean(struct vty *vty)
{
- thread_cancel(&vty->t_confirmed_commit_timeout);
+ event_cancel(&vty->t_confirmed_commit_timeout);
nb_config_free(vty->confirmed_commit_rollback);
vty->confirmed_commit_rollback = NULL;
}
@@ -332,9 +300,9 @@ int nb_cli_confirmed_commit_rollback(struct vty *vty)
return ret;
}
-static void nb_cli_confirmed_commit_timeout(struct thread *thread)
+static void nb_cli_confirmed_commit_timeout(struct event *thread)
{
- struct vty *vty = THREAD_ARG(thread);
+ struct vty *vty = EVENT_ARG(thread);
/* XXX: broadcast this message to all logged-in users? */
vty_out(vty,
@@ -360,11 +328,10 @@ static int nb_cli_commit(struct vty *vty, bool force,
"%% Resetting confirmed-commit timeout to %u minute(s)\n\n",
confirmed_timeout);
- thread_cancel(&vty->t_confirmed_commit_timeout);
- thread_add_timer(master,
- nb_cli_confirmed_commit_timeout, vty,
- confirmed_timeout * 60,
- &vty->t_confirmed_commit_timeout);
+ event_cancel(&vty->t_confirmed_commit_timeout);
+ event_add_timer(master, nb_cli_confirmed_commit_timeout,
+ vty, confirmed_timeout * 60,
+ &vty->t_confirmed_commit_timeout);
} else {
/* Accept commit confirmation. */
vty_out(vty, "%% Commit complete.\n\n");
@@ -387,9 +354,9 @@ static int nb_cli_commit(struct vty *vty, bool force,
vty->confirmed_commit_rollback = nb_config_dup(running_config);
vty->t_confirmed_commit_timeout = NULL;
- thread_add_timer(master, nb_cli_confirmed_commit_timeout, vty,
- confirmed_timeout * 60,
- &vty->t_confirmed_commit_timeout);
+ event_add_timer(master, nb_cli_confirmed_commit_timeout, vty,
+ confirmed_timeout * 60,
+ &vty->t_confirmed_commit_timeout);
}
context.client = NB_CLIENT_CLI;
@@ -1909,7 +1876,7 @@ static const struct cmd_variable_handler yang_var_handlers[] = {
.completions = yang_translator_autocomplete},
{.completions = NULL}};
-void nb_cli_init(struct thread_master *tm)
+void nb_cli_init(struct event_loop *tm)
{
master = tm;
diff --git a/lib/northbound_cli.h b/lib/northbound_cli.h
index ef2ef44eb0..c8f8a8481a 100644
--- a/lib/northbound_cli.h
+++ b/lib/northbound_cli.h
@@ -137,7 +137,7 @@ extern void nb_cli_show_config_prepare(struct nb_config *config,
extern void nb_cli_confirmed_commit_clean(struct vty *vty);
extern int nb_cli_confirmed_commit_rollback(struct vty *vty);
extern void nb_cli_install_default(int node);
-extern void nb_cli_init(struct thread_master *tm);
+extern void nb_cli_init(struct event_loop *tm);
extern void nb_cli_terminate(void);
#ifdef __cplusplus
diff --git a/lib/northbound_confd.c b/lib/northbound_confd.c
index 2b57ff2707..34406a110b 100644
--- a/lib/northbound_confd.c
+++ b/lib/northbound_confd.c
@@ -23,10 +23,10 @@ DEFINE_MTYPE_STATIC(LIB, CONFD, "ConfD module");
static struct debug nb_dbg_client_confd = {0, "Northbound client: ConfD"};
-static struct thread_master *master;
+static struct event_loop *master;
static struct sockaddr confd_addr;
static int cdb_sub_sock, dp_ctl_sock, dp_worker_sock;
-static struct thread *t_cdb_sub, *t_dp_ctl, *t_dp_worker;
+static struct event *t_cdb_sub, *t_dp_ctl, *t_dp_worker;
static struct confd_daemon_ctx *dctx;
static struct confd_notification_ctx *live_ctx;
static bool confd_connected;
@@ -312,7 +312,8 @@ static void frr_confd_cdb_read_cb_prepare(int fd, int *subp, int reslen)
transaction = NULL;
context.client = NB_CLIENT_CONFD;
ret = nb_candidate_commit_prepare(context, candidate, NULL,
- &transaction, errmsg, sizeof(errmsg));
+ &transaction, false, false, errmsg,
+ sizeof(errmsg));
if (ret != NB_OK && ret != NB_ERR_NO_CHANGES) {
enum confd_errcode errcode;
@@ -400,15 +401,15 @@ static int frr_confd_cdb_read_cb_abort(int fd, int *subp, int reslen)
return 0;
}
-static void frr_confd_cdb_read_cb(struct thread *thread)
+static void frr_confd_cdb_read_cb(struct event *thread)
{
- int fd = THREAD_FD(thread);
+ int fd = EVENT_FD(thread);
enum cdb_sub_notification cdb_ev;
int flags;
int *subp = NULL;
int reslen = 0;
- thread_add_read(master, frr_confd_cdb_read_cb, NULL, fd, &t_cdb_sub);
+ event_add_read(master, frr_confd_cdb_read_cb, NULL, fd, &t_cdb_sub);
if (cdb_read_subscription_socket2(fd, &cdb_ev, &flags, &subp, &reslen)
!= CONFD_OK) {
@@ -573,8 +574,8 @@ static int frr_confd_init_cdb(void)
}
pthread_detach(cdb_trigger_thread);
- thread_add_read(master, frr_confd_cdb_read_cb, NULL, cdb_sub_sock,
- &t_cdb_sub);
+ event_add_read(master, frr_confd_cdb_read_cb, NULL, cdb_sub_sock,
+ &t_cdb_sub);
return 0;
@@ -587,7 +588,7 @@ error:
static void frr_confd_finish_cdb(void)
{
if (cdb_sub_sock > 0) {
- THREAD_OFF(t_cdb_sub);
+ EVENT_OFF(t_cdb_sub);
cdb_close(cdb_sub_sock);
}
}
@@ -1172,22 +1173,23 @@ static int frr_confd_dp_read(struct confd_daemon_ctx *dctx, int fd)
return 0;
}
-static void frr_confd_dp_ctl_read(struct thread *thread)
+static void frr_confd_dp_ctl_read(struct event *thread)
{
- struct confd_daemon_ctx *dctx = THREAD_ARG(thread);
- int fd = THREAD_FD(thread);
+ struct confd_daemon_ctx *dctx = EVENT_ARG(thread);
+ int fd = EVENT_FD(thread);
- thread_add_read(master, frr_confd_dp_ctl_read, dctx, fd, &t_dp_ctl);
+ event_add_read(master, frr_confd_dp_ctl_read, dctx, fd, &t_dp_ctl);
frr_confd_dp_read(dctx, fd);
}
-static void frr_confd_dp_worker_read(struct thread *thread)
+static void frr_confd_dp_worker_read(struct event *thread)
{
- struct confd_daemon_ctx *dctx = THREAD_ARG(thread);
- int fd = THREAD_FD(thread);
+ struct confd_daemon_ctx *dctx = EVENT_ARG(thread);
+ int fd = EVENT_FD(thread);
- thread_add_read(master, frr_confd_dp_worker_read, dctx, fd, &t_dp_worker);
+ event_add_read(master, frr_confd_dp_worker_read, dctx, fd,
+ &t_dp_worker);
frr_confd_dp_read(dctx, fd);
}
@@ -1319,10 +1321,10 @@ static int frr_confd_init_dp(const char *program_name)
goto error;
}
- thread_add_read(master, frr_confd_dp_ctl_read, dctx, dp_ctl_sock,
- &t_dp_ctl);
- thread_add_read(master, frr_confd_dp_worker_read, dctx, dp_worker_sock,
- &t_dp_worker);
+ event_add_read(master, frr_confd_dp_ctl_read, dctx, dp_ctl_sock,
+ &t_dp_ctl);
+ event_add_read(master, frr_confd_dp_worker_read, dctx, dp_worker_sock,
+ &t_dp_worker);
return 0;
@@ -1335,11 +1337,11 @@ error:
static void frr_confd_finish_dp(void)
{
if (dp_worker_sock > 0) {
- THREAD_OFF(t_dp_worker);
+ EVENT_OFF(t_dp_worker);
close(dp_worker_sock);
}
if (dp_ctl_sock > 0) {
- THREAD_OFF(t_dp_ctl);
+ EVENT_OFF(t_dp_ctl);
close(dp_ctl_sock);
}
if (dctx != NULL)
@@ -1463,7 +1465,7 @@ static int frr_confd_finish(void)
return 0;
}
-static int frr_confd_module_late_init(struct thread_master *tm)
+static int frr_confd_module_late_init(struct event_loop *tm)
{
master = tm;
diff --git a/lib/northbound_grpc.cpp b/lib/northbound_grpc.cpp
index 1459146eab..6c33351cef 100644
--- a/lib/northbound_grpc.cpp
+++ b/lib/northbound_grpc.cpp
@@ -12,7 +12,7 @@
#include "log.h"
#include "libfrr.h"
#include "lib/version.h"
-#include "lib/thread.h"
+#include "frrevent.h"
#include "command.h"
#include "lib_errors.h"
#include "northbound.h"
@@ -38,7 +38,7 @@
*/
static bool nb_dbg_client_grpc = 0;
-static struct thread_master *main_master;
+static struct event_loop *main_master;
static struct frr_pthread *fpt;
@@ -157,8 +157,7 @@ class RpcStateBase
* state will either be MORE or FINISH. It will always be FINISH
* for Unary RPCs.
*/
- thread_add_event(main_master, c_callback, (void *)this, 0,
- NULL);
+ event_add_event(main_master, c_callback, (void *)this, 0, NULL);
pthread_mutex_lock(&this->cmux);
while (this->state == PROCESS)
@@ -181,11 +180,11 @@ class RpcStateBase
}
protected:
- virtual CallState run_mainthread(struct thread *thread) = 0;
+ virtual CallState run_mainthread(struct event *thread) = 0;
- static void c_callback(struct thread *thread)
+ static void c_callback(struct event *thread)
{
- auto _tag = static_cast<RpcStateBase *>(THREAD_ARG(thread));
+ auto _tag = static_cast<RpcStateBase *>(EVENT_ARG(thread));
/*
* We hold the lock until the callback finishes and has updated
* _tag->state, then we signal done and release.
@@ -250,7 +249,7 @@ template <typename Q, typename S> class UnaryRpcState : public RpcStateBase
&copy->responder, cq, cq, copy);
}
- CallState run_mainthread(struct thread *thread) override
+ CallState run_mainthread(struct event *thread) override
{
// Unary RPC are always finished, see "Unary" :)
grpc::Status status = this->callback(this);
@@ -302,7 +301,7 @@ class StreamRpcState : public RpcStateBase
&copy->async_responder, cq, cq, copy);
}
- CallState run_mainthread(struct thread *thread) override
+ CallState run_mainthread(struct event *thread) override
{
if (this->callback(this))
return MORE;
@@ -825,7 +824,8 @@ HandleUnaryCommit(UnaryRpcState<frr::CommitRequest, frr::CommitResponse> *tag)
grpc_debug("`-> Performing PREPARE");
ret = nb_candidate_commit_prepare(
context, candidate->config, comment.c_str(),
- &candidate->transaction, errmsg, sizeof(errmsg));
+ &candidate->transaction, false, false, errmsg,
+ sizeof(errmsg));
break;
case frr::CommitRequest::ABORT:
grpc_debug("`-> Performing ABORT");
@@ -1274,7 +1274,7 @@ static int frr_grpc_finish(void)
* fork. This is done by scheduling this init function as an event task, since
* the event loop doesn't run until after fork.
*/
-static void frr_grpc_module_very_late_init(struct thread *thread)
+static void frr_grpc_module_very_late_init(struct event *thread)
{
const char *args = THIS_MODULE->load_args;
uint port = GRPC_DEFAULT_PORT;
@@ -1298,11 +1298,11 @@ error:
flog_err(EC_LIB_GRPC_INIT, "failed to initialize the gRPC module");
}
-static int frr_grpc_module_late_init(struct thread_master *tm)
+static int frr_grpc_module_late_init(struct event_loop *tm)
{
main_master = tm;
hook_register(frr_fini, frr_grpc_finish);
- thread_add_event(tm, frr_grpc_module_very_late_init, NULL, 0, NULL);
+ event_add_event(tm, frr_grpc_module_very_late_init, NULL, 0, NULL);
return 0;
}
diff --git a/lib/northbound_sysrepo.c b/lib/northbound_sysrepo.c
index 096414ff24..86105d2e77 100644
--- a/lib/northbound_sysrepo.c
+++ b/lib/northbound_sysrepo.c
@@ -23,12 +23,12 @@ DEFINE_MTYPE_STATIC(LIB, SYSREPO, "Sysrepo module");
static struct debug nb_dbg_client_sysrepo = {0, "Northbound client: Sysrepo"};
-static struct thread_master *master;
+static struct event_loop *master;
static sr_session_ctx_t *session;
static sr_conn_ctx_t *connection;
static struct nb_transaction *transaction;
-static void frr_sr_read_cb(struct thread *thread);
+static void frr_sr_read_cb(struct event *thread);
static int frr_sr_finish(void);
/* Convert FRR YANG data value to sysrepo YANG data value. */
@@ -269,7 +269,8 @@ static int frr_sr_config_change_cb_prepare(sr_session_ctx_t *session,
* required to apply them.
*/
ret = nb_candidate_commit_prepare(context, candidate, NULL,
- &transaction, errmsg, sizeof(errmsg));
+ &transaction, false, false, errmsg,
+ sizeof(errmsg));
if (ret != NB_OK && ret != NB_ERR_NO_CHANGES)
flog_warn(
EC_LIB_LIBSYSREPO,
@@ -513,10 +514,10 @@ static int frr_sr_notification_send(const char *xpath, struct list *arguments)
return NB_OK;
}
-static void frr_sr_read_cb(struct thread *thread)
+static void frr_sr_read_cb(struct event *thread)
{
- struct yang_module *module = THREAD_ARG(thread);
- int fd = THREAD_FD(thread);
+ struct yang_module *module = EVENT_ARG(thread);
+ int fd = EVENT_FD(thread);
int ret;
ret = sr_subscription_process_events(module->sr_subscription, session,
@@ -527,7 +528,7 @@ static void frr_sr_read_cb(struct thread *thread)
return;
}
- thread_add_read(master, frr_sr_read_cb, module, fd, &module->sr_thread);
+ event_add_read(master, frr_sr_read_cb, module, fd, &module->sr_thread);
}
static void frr_sr_subscribe_config(struct yang_module *module)
@@ -687,8 +688,8 @@ static int frr_sr_init(void)
sr_strerror(ret));
goto cleanup;
}
- thread_add_read(master, frr_sr_read_cb, module,
- event_pipe, &module->sr_thread);
+ event_add_read(master, frr_sr_read_cb, module, event_pipe,
+ &module->sr_thread);
}
hook_register(nb_notification_send, frr_sr_notification_send);
@@ -709,7 +710,7 @@ static int frr_sr_finish(void)
if (!module->sr_subscription)
continue;
sr_unsubscribe(module->sr_subscription);
- THREAD_OFF(module->sr_thread);
+ EVENT_OFF(module->sr_thread);
}
if (session)
@@ -720,7 +721,7 @@ static int frr_sr_finish(void)
return 0;
}
-static int frr_sr_module_config_loaded(struct thread_master *tm)
+static int frr_sr_module_config_loaded(struct event_loop *tm)
{
master = tm;
@@ -735,7 +736,7 @@ static int frr_sr_module_config_loaded(struct thread_master *tm)
return 0;
}
-static int frr_sr_module_late_init(struct thread_master *tm)
+static int frr_sr_module_late_init(struct event_loop *tm)
{
frr_sr_cli_init();
diff --git a/lib/prefix.c b/lib/prefix.c
index a6aae08a6a..b8cad910f4 100644
--- a/lib/prefix.c
+++ b/lib/prefix.c
@@ -1399,7 +1399,7 @@ bool ipv4_unicast_valid(const struct in_addr *addr)
if (IPV4_CLASS_D(ip))
return false;
- if (IPV4_CLASS_E(ip)) {
+ if (IPV4_NET0(ip) || IPV4_NET127(ip) || IPV4_CLASS_E(ip)) {
if (cmd_allow_reserved_ranges_get())
return true;
else
diff --git a/lib/prefix.h b/lib/prefix.h
index 9c57283706..88a228b55c 100644
--- a/lib/prefix.h
+++ b/lib/prefix.h
@@ -499,11 +499,8 @@ extern int macstr2prefix_evpn(const char *str, struct prefix_evpn *p);
/* NOTE: This routine expects the address argument in network byte order. */
static inline bool ipv4_martian(const struct in_addr *addr)
{
- in_addr_t ip = ntohl(addr->s_addr);
-
- if (IPV4_NET0(ip) || IPV4_NET127(ip) || !ipv4_unicast_valid(addr)) {
+ if (!ipv4_unicast_valid(addr))
return true;
- }
return false;
}
diff --git a/lib/pullwr.c b/lib/pullwr.c
index 5bc566c285..3967eb5875 100644
--- a/lib/pullwr.c
+++ b/lib/pullwr.c
@@ -16,9 +16,9 @@
struct pullwr {
int fd;
- struct thread_master *tm;
+ struct event_loop *tm;
/* writer == NULL <=> we're idle */
- struct thread *writer;
+ struct event *writer;
void *arg;
void (*fill)(void *, struct pullwr *);
@@ -38,12 +38,11 @@ struct pullwr {
DEFINE_MTYPE_STATIC(LIB, PULLWR_HEAD, "pull-driven write controller");
DEFINE_MTYPE_STATIC(LIB, PULLWR_BUF, "pull-driven write buffer");
-static void pullwr_run(struct thread *t);
+static void pullwr_run(struct event *t);
-struct pullwr *_pullwr_new(struct thread_master *tm, int fd,
- void *arg,
- void (*fill)(void *, struct pullwr *),
- void (*err)(void *, struct pullwr *, bool))
+struct pullwr *_pullwr_new(struct event_loop *tm, int fd, void *arg,
+ void (*fill)(void *, struct pullwr *),
+ void (*err)(void *, struct pullwr *, bool))
{
struct pullwr *pullwr;
@@ -62,7 +61,7 @@ struct pullwr *_pullwr_new(struct thread_master *tm, int fd,
void pullwr_del(struct pullwr *pullwr)
{
- THREAD_OFF(pullwr->writer);
+ EVENT_OFF(pullwr->writer);
XFREE(MTYPE_PULLWR_BUF, pullwr->buffer);
XFREE(MTYPE_PULLWR_HEAD, pullwr);
@@ -80,7 +79,7 @@ void pullwr_bump(struct pullwr *pullwr)
if (pullwr->writer)
return;
- thread_add_timer(pullwr->tm, pullwr_run, pullwr, 0, &pullwr->writer);
+ event_add_timer(pullwr->tm, pullwr_run, pullwr, 0, &pullwr->writer);
}
static size_t pullwr_iov(struct pullwr *pullwr, struct iovec *iov)
@@ -176,9 +175,9 @@ void pullwr_write(struct pullwr *pullwr, const void *data, size_t len)
pullwr_bump(pullwr);
}
-static void pullwr_run(struct thread *t)
+static void pullwr_run(struct event *t)
{
- struct pullwr *pullwr = THREAD_ARG(t);
+ struct pullwr *pullwr = EVENT_ARG(t);
struct iovec iov[2];
size_t niov, lastvalid;
ssize_t nwr;
@@ -206,7 +205,7 @@ static void pullwr_run(struct thread *t)
if (pullwr->valid == 0) {
/* we made a fill() call above that didn't feed any
* data in, and we have nothing more queued, so we go
- * into idle, i.e. no calling thread_add_write()
+ * into idle, i.e. no calling event_add_write()
*/
pullwr_resize(pullwr, 0);
return;
@@ -237,7 +236,7 @@ static void pullwr_run(struct thread *t)
* is full and we go wait until it's available for writing again.
*/
- thread_add_write(pullwr->tm, pullwr_run, pullwr, pullwr->fd,
+ event_add_write(pullwr->tm, pullwr_run, pullwr, pullwr->fd,
&pullwr->writer);
/* if we hit the time limit, just keep the buffer, we'll probably need
diff --git a/lib/pullwr.h b/lib/pullwr.h
index 77ecf855b4..ef2e01c04e 100644
--- a/lib/pullwr.h
+++ b/lib/pullwr.h
@@ -10,7 +10,7 @@
#include <stdbool.h>
#include <stdint.h>
-#include "thread.h"
+#include "frrevent.h"
#include "stream.h"
#ifdef __cplusplus
@@ -45,10 +45,10 @@ struct pullwr;
* and released with pullwr_del(). This can be done from inside the callback,
* the pullwr code holds no more references on it when calling err().
*/
-extern struct pullwr *_pullwr_new(struct thread_master *tm, int fd,
- void *arg,
- void (*fill)(void *, struct pullwr *),
- void (*err)(void *, struct pullwr *, bool eof));
+extern struct pullwr *_pullwr_new(struct event_loop *tm, int fd, void *arg,
+ void (*fill)(void *, struct pullwr *),
+ void (*err)(void *, struct pullwr *,
+ bool eof));
extern void pullwr_del(struct pullwr *pullwr);
/* type-checking wrapper. makes sure fill() and err() take a first argument
diff --git a/lib/qobj.c b/lib/qobj.c
index 09b156ba39..b9630e7547 100644
--- a/lib/qobj.c
+++ b/lib/qobj.c
@@ -7,7 +7,7 @@
#include <zebra.h>
-#include "thread.h"
+#include "frrevent.h"
#include "memory.h"
#include "hash.h"
#include "log.h"
diff --git a/lib/resolver.c b/lib/resolver.c
index 2918576c03..99bf356eb3 100644
--- a/lib/resolver.c
+++ b/lib/resolver.c
@@ -12,7 +12,7 @@
#include "typesafe.h"
#include "jhash.h"
-#include "thread.h"
+#include "frrevent.h"
#include "lib_errors.h"
#include "resolver.h"
#include "command.h"
@@ -23,8 +23,8 @@ XREF_SETUP();
struct resolver_state {
ares_channel channel;
- struct thread_master *master;
- struct thread *timeout;
+ struct event_loop *master;
+ struct event *timeout;
};
static struct resolver_state state;
@@ -47,7 +47,7 @@ struct resolver_fd {
int fd;
struct resolver_state *state;
- struct thread *t_read, *t_write;
+ struct event *t_read, *t_write;
};
static int resolver_fd_cmp(const struct resolver_fd *a,
@@ -100,38 +100,38 @@ static void resolver_fd_drop_maybe(struct resolver_fd *resfd)
static void resolver_update_timeouts(struct resolver_state *r);
-static void resolver_cb_timeout(struct thread *t)
+static void resolver_cb_timeout(struct event *t)
{
- struct resolver_state *r = THREAD_ARG(t);
+ struct resolver_state *r = EVENT_ARG(t);
ares_process(r->channel, NULL, NULL);
resolver_update_timeouts(r);
}
-static void resolver_cb_socket_readable(struct thread *t)
+static void resolver_cb_socket_readable(struct event *t)
{
- struct resolver_fd *resfd = THREAD_ARG(t);
+ struct resolver_fd *resfd = EVENT_ARG(t);
struct resolver_state *r = resfd->state;
- thread_add_read(r->master, resolver_cb_socket_readable, resfd,
- resfd->fd, &resfd->t_read);
+ event_add_read(r->master, resolver_cb_socket_readable, resfd, resfd->fd,
+ &resfd->t_read);
/* ^ ordering important:
- * ares_process_fd may transitively call THREAD_OFF(resfd->t_read)
+ * ares_process_fd may transitively call EVENT_OFF(resfd->t_read)
* combined with resolver_fd_drop_maybe, so resfd may be free'd after!
*/
ares_process_fd(r->channel, resfd->fd, ARES_SOCKET_BAD);
resolver_update_timeouts(r);
}
-static void resolver_cb_socket_writable(struct thread *t)
+static void resolver_cb_socket_writable(struct event *t)
{
- struct resolver_fd *resfd = THREAD_ARG(t);
+ struct resolver_fd *resfd = EVENT_ARG(t);
struct resolver_state *r = resfd->state;
- thread_add_write(r->master, resolver_cb_socket_writable, resfd,
- resfd->fd, &resfd->t_write);
+ event_add_write(r->master, resolver_cb_socket_writable, resfd,
+ resfd->fd, &resfd->t_write);
/* ^ ordering important:
- * ares_process_fd may transitively call THREAD_OFF(resfd->t_write)
+ * ares_process_fd may transitively call EVENT_OFF(resfd->t_write)
* combined with resolver_fd_drop_maybe, so resfd may be free'd after!
*/
ares_process_fd(r->channel, ARES_SOCKET_BAD, resfd->fd);
@@ -142,13 +142,13 @@ static void resolver_update_timeouts(struct resolver_state *r)
{
struct timeval *tv, tvbuf;
- THREAD_OFF(r->timeout);
+ EVENT_OFF(r->timeout);
tv = ares_timeout(r->channel, NULL, &tvbuf);
if (tv) {
unsigned int timeoutms = tv->tv_sec * 1000 + tv->tv_usec / 1000;
- thread_add_timer_msec(r->master, resolver_cb_timeout, r,
- timeoutms, &r->timeout);
+ event_add_timer_msec(r->master, resolver_cb_timeout, r,
+ timeoutms, &r->timeout);
}
}
@@ -165,16 +165,16 @@ static void ares_socket_cb(void *data, ares_socket_t fd, int readable,
assert(resfd->state == r);
if (!readable)
- THREAD_OFF(resfd->t_read);
+ EVENT_OFF(resfd->t_read);
else if (!resfd->t_read)
- thread_add_read(r->master, resolver_cb_socket_readable, resfd,
- fd, &resfd->t_read);
+ event_add_read(r->master, resolver_cb_socket_readable, resfd,
+ fd, &resfd->t_read);
if (!writable)
- THREAD_OFF(resfd->t_write);
+ EVENT_OFF(resfd->t_write);
else if (!resfd->t_write)
- thread_add_write(r->master, resolver_cb_socket_writable, resfd,
- fd, &resfd->t_write);
+ event_add_write(r->master, resolver_cb_socket_writable, resfd,
+ fd, &resfd->t_write);
resolver_fd_drop_maybe(resfd);
}
@@ -222,9 +222,9 @@ static void ares_address_cb(void *arg, int status, int timeouts,
callback(query, NULL, i, &addr[0]);
}
-static void resolver_cb_literal(struct thread *t)
+static void resolver_cb_literal(struct event *t)
{
- struct resolver_query *query = THREAD_ARG(t);
+ struct resolver_query *query = EVENT_ARG(t);
void (*callback)(struct resolver_query *, const char *, int,
union sockunion *);
@@ -264,8 +264,8 @@ void resolver_resolve(struct resolver_query *query, int af, vrf_id_t vrf_id,
/* for consistency with proper name lookup, don't call the
* callback immediately; defer to thread loop
*/
- thread_add_timer_msec(state.master, resolver_cb_literal,
- query, 0, &query->literal_cb);
+ event_add_timer_msec(state.master, resolver_cb_literal, query,
+ 0, &query->literal_cb);
return;
}
@@ -314,7 +314,7 @@ static int resolver_config_write_debug(struct vty *vty)
}
-void resolver_init(struct thread_master *tm)
+void resolver_init(struct event_loop *tm)
{
struct ares_options ares_opts;
diff --git a/lib/resolver.h b/lib/resolver.h
index d3f38f742d..87e8ecdc4a 100644
--- a/lib/resolver.h
+++ b/lib/resolver.h
@@ -6,7 +6,7 @@
#ifndef _FRR_RESOLVER_H
#define _FRR_RESOLVER_H
-#include "thread.h"
+#include "frrevent.h"
#include "sockunion.h"
#ifdef __cplusplus
@@ -19,10 +19,10 @@ struct resolver_query {
/* used to immediate provide the result if IP literal is passed in */
union sockunion literal_addr;
- struct thread *literal_cb;
+ struct event *literal_cb;
};
-void resolver_init(struct thread_master *tm);
+void resolver_init(struct event_loop *tm);
void resolver_resolve(struct resolver_query *query, int af, vrf_id_t vrf_id,
const char *hostname,
void (*cb)(struct resolver_query *, const char *, int,
diff --git a/lib/routemap.c b/lib/routemap.c
index 9f5c9e693e..20dcd2a53d 100644
--- a/lib/routemap.c
+++ b/lib/routemap.c
@@ -669,7 +669,7 @@ static struct route_map *route_map_add(const char *name)
if (!map->ipv6_prefix_table)
map->ipv6_prefix_table = route_table_init();
- if (CHECK_FLAG(rmap_debug, DEBUG_ROUTEMAP))
+ if (unlikely(CHECK_FLAG(rmap_debug, DEBUG_ROUTEMAP)))
zlog_debug("Add route-map %s", name);
return map;
}
@@ -689,7 +689,7 @@ static void route_map_free_map(struct route_map *map)
while ((index = map->head) != NULL)
route_map_index_delete(index, 0);
- if (CHECK_FLAG(rmap_debug, DEBUG_ROUTEMAP))
+ if (unlikely(CHECK_FLAG(rmap_debug, DEBUG_ROUTEMAP)))
zlog_debug("Deleting route-map %s", map->name);
list = &route_map_master;
@@ -706,6 +706,9 @@ static void route_map_free_map(struct route_map *map)
else
list->head = map->next;
+ route_table_finish(map->ipv4_prefix_table);
+ route_table_finish(map->ipv6_prefix_table);
+
hash_release(route_map_master_hash, map);
XFREE(MTYPE_ROUTE_MAP_NAME, map->name);
XFREE(MTYPE_ROUTE_MAP, map);
@@ -1120,7 +1123,7 @@ void route_map_index_delete(struct route_map_index *index, int notify)
QOBJ_UNREG(index);
- if (CHECK_FLAG(rmap_debug, DEBUG_ROUTEMAP))
+ if (unlikely(CHECK_FLAG(rmap_debug, DEBUG_ROUTEMAP)))
zlog_debug("Deleting route-map %s sequence %d",
index->map->name, index->pref);
@@ -1231,7 +1234,7 @@ route_map_index_add(struct route_map *map, enum route_map_type type, int pref)
route_map_notify_dependencies(map->name, RMAP_EVENT_CALL_ADDED);
}
- if (CHECK_FLAG(rmap_debug, DEBUG_ROUTEMAP))
+ if (unlikely(CHECK_FLAG(rmap_debug, DEBUG_ROUTEMAP)))
zlog_debug("Route-map %s add sequence %d, type: %s",
map->name, pref, route_map_type_str(type));
@@ -1811,10 +1814,8 @@ route_map_get_index(struct route_map *map, const struct prefix *prefix,
* must be AF_INET or AF_INET6 in order for the lookup to succeed. So if
* the AF doesn't line up with the LPM trees, skip the optimization.
*/
- if (map->optimization_disabled ||
- (prefix->family == AF_INET && !map->ipv4_prefix_table) ||
- (prefix->family == AF_INET6 && !map->ipv6_prefix_table)) {
- if (CHECK_FLAG(rmap_debug, DEBUG_ROUTEMAP_DETAIL))
+ if (map->optimization_disabled) {
+ if (unlikely(CHECK_FLAG(rmap_debug, DEBUG_ROUTEMAP_DETAIL)))
zlog_debug(
"Skipping route-map optimization for route-map: %s, pfx: %pFX, family: %d",
map->name, prefix, prefix->family);
@@ -1826,9 +1827,6 @@ route_map_get_index(struct route_map *map, const struct prefix *prefix,
else
table = map->ipv6_prefix_table;
- if (!table)
- return NULL;
-
do {
candidate_rmap_list =
route_map_get_index_list(&rn, prefix, table);
@@ -1914,19 +1912,10 @@ static void route_map_pfx_table_add_default(afi_t afi,
p.family = afi2family(afi);
p.prefixlen = 0;
- if (p.family == AF_INET) {
- table = index->map->ipv4_prefix_table;
- if (!table)
- index->map->ipv4_prefix_table = route_table_init();
-
+ if (p.family == AF_INET)
table = index->map->ipv4_prefix_table;
- } else {
+ else
table = index->map->ipv6_prefix_table;
- if (!table)
- index->map->ipv6_prefix_table = route_table_init();
-
- table = index->map->ipv6_prefix_table;
- }
/* Add default route to table */
rn = route_node_get(table, &p);
@@ -2317,8 +2306,6 @@ static void route_map_pfx_tbl_update(route_map_event_t event,
struct route_map_index *index, afi_t afi,
const char *plist_name)
{
- struct route_map *rmap = NULL;
-
if (!index)
return;
@@ -2332,19 +2319,6 @@ static void route_map_pfx_tbl_update(route_map_event_t event,
route_map_pfx_table_del_default(AFI_IP, index);
route_map_pfx_table_del_default(AFI_IP6, index);
- if ((index->map->head == NULL) && (index->map->tail == NULL)) {
- rmap = index->map;
-
- if (rmap->ipv4_prefix_table) {
- route_table_finish(rmap->ipv4_prefix_table);
- rmap->ipv4_prefix_table = NULL;
- }
-
- if (rmap->ipv6_prefix_table) {
- route_table_finish(rmap->ipv6_prefix_table);
- rmap->ipv6_prefix_table = NULL;
- }
- }
return;
}
@@ -2569,12 +2543,14 @@ route_map_result_t route_map_apply_ext(struct route_map *map,
*/
if (prefix->family == AF_EVPN) {
if (evpn_prefix2prefix(prefix, &conv) != 0) {
- if (CHECK_FLAG(rmap_debug, DEBUG_ROUTEMAP_DETAIL))
+ if (unlikely(CHECK_FLAG(rmap_debug,
+ DEBUG_ROUTEMAP_DETAIL)))
zlog_debug(
"Unable to convert EVPN prefix %pFX into IPv4/IPv6 prefix. Falling back to non-optimized route-map lookup",
prefix);
} else {
- if (CHECK_FLAG(rmap_debug, DEBUG_ROUTEMAP_DETAIL))
+ if (unlikely(CHECK_FLAG(rmap_debug,
+ DEBUG_ROUTEMAP_DETAIL)))
zlog_debug(
"Converted EVPN prefix %pFX into %pFX for optimized route-map lookup",
prefix, &conv);
@@ -2586,13 +2562,13 @@ route_map_result_t route_map_apply_ext(struct route_map *map,
index = route_map_get_index(map, prefix, match_object, &match_ret);
if (index) {
index->applied++;
- if (CHECK_FLAG(rmap_debug, DEBUG_ROUTEMAP))
+ if (unlikely(CHECK_FLAG(rmap_debug, DEBUG_ROUTEMAP)))
zlog_debug(
"Best match route-map: %s, sequence: %d for pfx: %pFX, result: %s",
map->name, index->pref, prefix,
route_map_cmd_result_str(match_ret));
} else {
- if (CHECK_FLAG(rmap_debug, DEBUG_ROUTEMAP))
+ if (unlikely(CHECK_FLAG(rmap_debug, DEBUG_ROUTEMAP)))
zlog_debug(
"No best match sequence for pfx: %pFX in route-map: %s, result: %s",
prefix, map->name,
@@ -2615,7 +2591,7 @@ route_map_result_t route_map_apply_ext(struct route_map *map,
/* Apply this index. */
match_ret = route_map_apply_match(&index->match_list,
prefix, match_object);
- if (CHECK_FLAG(rmap_debug, DEBUG_ROUTEMAP)) {
+ if (unlikely(CHECK_FLAG(rmap_debug, DEBUG_ROUTEMAP))) {
zlog_debug(
"Route-map: %s, sequence: %d, prefix: %pFX, result: %s",
map->name, index->pref, prefix,
@@ -2728,7 +2704,7 @@ route_map_result_t route_map_apply_ext(struct route_map *map,
}
route_map_apply_end:
- if (CHECK_FLAG(rmap_debug, DEBUG_ROUTEMAP))
+ if (unlikely(CHECK_FLAG(rmap_debug, DEBUG_ROUTEMAP)))
zlog_debug("Route-map: %s, prefix: %pFX, result: %s",
(map ? map->name : "null"), prefix,
route_map_result_str(ret));
@@ -2783,7 +2759,7 @@ static void route_map_clear_reference(struct hash_bucket *bucket, void *arg)
tmp_dep_data.rname = arg;
dep_data = hash_release(dep->dep_rmap_hash, &tmp_dep_data);
if (dep_data) {
- if (CHECK_FLAG(rmap_debug, DEBUG_ROUTEMAP))
+ if (unlikely(CHECK_FLAG(rmap_debug, DEBUG_ROUTEMAP)))
zlog_debug("Clearing reference for %s to %s count: %d",
dep->dep_name, tmp_dep_data.rname,
dep_data->refcnt);
@@ -2803,7 +2779,7 @@ static void route_map_clear_all_references(char *rmap_name)
{
int i;
- if (CHECK_FLAG(rmap_debug, DEBUG_ROUTEMAP))
+ if (unlikely(CHECK_FLAG(rmap_debug, DEBUG_ROUTEMAP)))
zlog_debug("Clearing references for %s", rmap_name);
for (i = 1; i < ROUTE_MAP_DEP_MAX; i++) {
@@ -2879,7 +2855,7 @@ static int route_map_dep_update(struct hash *dephash, const char *dep_name,
case RMAP_EVENT_LLIST_ADDED:
case RMAP_EVENT_CALL_ADDED:
case RMAP_EVENT_FILTER_ADDED:
- if (CHECK_FLAG(rmap_debug, DEBUG_ROUTEMAP))
+ if (unlikely(CHECK_FLAG(rmap_debug, DEBUG_ROUTEMAP)))
zlog_debug("Adding dependency for filter %s in route-map %s",
dep_name, rmap_name);
dep = (struct route_map_dep *)hash_get(
@@ -2908,7 +2884,7 @@ static int route_map_dep_update(struct hash *dephash, const char *dep_name,
case RMAP_EVENT_LLIST_DELETED:
case RMAP_EVENT_CALL_DELETED:
case RMAP_EVENT_FILTER_DELETED:
- if (CHECK_FLAG(rmap_debug, DEBUG_ROUTEMAP))
+ if (unlikely(CHECK_FLAG(rmap_debug, DEBUG_ROUTEMAP)))
zlog_debug("Deleting dependency for filter %s in route-map %s",
dep_name, rmap_name);
dep = (struct route_map_dep *)hash_get(dephash, dname, NULL);
@@ -3034,7 +3010,7 @@ static void route_map_process_dependency(struct hash_bucket *bucket, void *data)
dep_data = bucket->data;
rmap_name = dep_data->rname;
- if (CHECK_FLAG(rmap_debug, DEBUG_ROUTEMAP))
+ if (unlikely(CHECK_FLAG(rmap_debug, DEBUG_ROUTEMAP)))
zlog_debug("Notifying %s of dependency", rmap_name);
if (route_map_master.event_hook)
(*route_map_master.event_hook)(rmap_name);
@@ -3082,7 +3058,7 @@ void route_map_notify_dependencies(const char *affected_name,
if (!dep->this_hash)
dep->this_hash = upd8_hash;
- if (CHECK_FLAG(rmap_debug, DEBUG_ROUTEMAP))
+ if (unlikely(CHECK_FLAG(rmap_debug, DEBUG_ROUTEMAP)))
zlog_debug("Filter %s updated", dep->dep_name);
hash_iterate(dep->dep_rmap_hash, route_map_process_dependency,
(void *)event);
@@ -3101,27 +3077,24 @@ static void clear_route_map_helper(struct route_map *map)
index->applied_clear = index->applied;
}
-DEFUN (rmap_clear_counters,
+DEFPY (rmap_clear_counters,
rmap_clear_counters_cmd,
- "clear route-map counters [WORD]",
+ "clear route-map counters [RMAP_NAME$rmapname]",
CLEAR_STR
"route-map information\n"
"counters associated with the specified route-map\n"
"route-map name\n")
{
- int idx_word = 2;
struct route_map *map;
- const char *name = (argc == 3 ) ? argv[idx_word]->arg : NULL;
-
- if (name) {
- map = route_map_lookup_by_name(name);
+ if (rmapname) {
+ map = route_map_lookup_by_name(rmapname);
if (map)
clear_route_map_helper(map);
else {
vty_out(vty, "%s: 'route-map %s' not found\n",
- frr_protonameinst, name);
+ frr_protonameinst, rmapname);
return CMD_SUCCESS;
}
} else {
diff --git a/lib/sigevent.c b/lib/sigevent.c
index 3ed34894e5..3cd65eb800 100644
--- a/lib/sigevent.c
+++ b/lib/sigevent.c
@@ -22,7 +22,7 @@
/* master signals descriptor struct */
static struct frr_sigevent_master_t {
- struct thread *t;
+ struct event *t;
struct frr_signal_t *signals;
int sigc;
@@ -127,14 +127,14 @@ int frr_sigevent_process(void)
#ifdef SIGEVENT_SCHEDULE_THREAD
/* timer thread to check signals. shouldn't be needed */
-void frr_signal_timer(struct thread *t)
+void frr_signal_timer(struct event *t)
{
struct frr_sigevent_master_t *sigm;
- sigm = THREAD_ARG(t);
+ sigm = EVENT_ARG(t);
sigm->t = NULL;
- thread_add_timer(sigm->t->master, frr_signal_timer, &sigmaster,
- FRR_SIGNAL_TIMER_INTERVAL, &sigm->t);
+ event_add_timer(sigm->t->master, frr_signal_timer, &sigmaster,
+ FRR_SIGNAL_TIMER_INTERVAL, &sigm->t);
frr_sigevent_process();
}
#endif /* SIGEVENT_SCHEDULE_THREAD */
@@ -331,8 +331,7 @@ static void trap_default_signals(void)
}
}
-void signal_init(struct thread_master *m, int sigc,
- struct frr_signal_t signals[])
+void signal_init(struct event_loop *m, int sigc, struct frr_signal_t signals[])
{
int i = 0;
@@ -354,7 +353,7 @@ void signal_init(struct thread_master *m, int sigc,
#ifdef SIGEVENT_SCHEDULE_THREAD
sigmaster.t = NULL;
- thread_add_timer(m, frr_signal_timer, &sigmaster,
- FRR_SIGNAL_TIMER_INTERVAL, &sigmaster.t);
+ event_add_timer(m, frr_signal_timer, &sigmaster,
+ FRR_SIGNAL_TIMER_INTERVAL, &sigmaster.t);
#endif /* SIGEVENT_SCHEDULE_THREAD */
}
diff --git a/lib/sigevent.h b/lib/sigevent.h
index e58b9a70c0..0b07f594c1 100644
--- a/lib/sigevent.h
+++ b/lib/sigevent.h
@@ -8,7 +8,7 @@
#ifndef _FRR_SIGNAL_H
#define _FRR_SIGNAL_H
-#include <thread.h>
+#include <frrevent.h>
#ifdef __cplusplus
extern "C" {
@@ -25,12 +25,12 @@ struct frr_signal_t {
/* initialise sigevent system
* takes:
- * - pointer to valid struct thread_master
+ * - pointer to valid struct event_loop
* - number of elements in passed in signals array
* - array of frr_signal_t's describing signals to handle
* and handlers to use for each signal
*/
-extern void signal_init(struct thread_master *m, int sigc,
+extern void signal_init(struct event_loop *m, int sigc,
struct frr_signal_t *signals);
diff --git a/lib/smux.h b/lib/smux.h
index 28a303cf72..cec4d2a1bf 100644
--- a/lib/smux.h
+++ b/lib/smux.h
@@ -9,7 +9,7 @@
#include <net-snmp/agent/net-snmp-agent-includes.h>
#include <net-snmp/agent/snmp_vars.h>
-#include "thread.h"
+#include "frrevent.h"
#include "hook.h"
#ifdef __cplusplus
@@ -99,7 +99,7 @@ struct index_oid {
*/
extern bool smux_enabled(void);
-extern void smux_init(struct thread_master *tm);
+extern void smux_init(struct event_loop *tm);
extern void smux_agentx_enable(void);
extern void smux_register_mib(const char *, struct variable *, size_t, int,
oid[], size_t);
diff --git a/lib/spf_backoff.c b/lib/spf_backoff.c
index 1e80b5ec2d..b05c44ddf7 100644
--- a/lib/spf_backoff.c
+++ b/lib/spf_backoff.c
@@ -17,7 +17,7 @@
#include "command.h"
#include "memory.h"
-#include "thread.h"
+#include "frrevent.h"
#include "vty.h"
DEFINE_MTYPE_STATIC(LIB, SPF_BACKOFF, "SPF backoff");
@@ -37,7 +37,7 @@ enum spf_backoff_state {
};
struct spf_backoff {
- struct thread_master *m;
+ struct event_loop *m;
/* Timers as per draft */
long init_delay;
@@ -48,8 +48,8 @@ struct spf_backoff {
/* State machine */
enum spf_backoff_state state;
- struct thread *t_holddown;
- struct thread *t_timetolearn;
+ struct event *t_holddown;
+ struct event *t_timetolearn;
/* For debugging */
char *name;
@@ -70,7 +70,7 @@ static const char *spf_backoff_state2str(enum spf_backoff_state state)
return "???";
}
-struct spf_backoff *spf_backoff_new(struct thread_master *m, const char *name,
+struct spf_backoff *spf_backoff_new(struct event_loop *m, const char *name,
long init_delay, long short_delay,
long long_delay, long holddown,
long timetolearn)
@@ -97,27 +97,27 @@ void spf_backoff_free(struct spf_backoff *backoff)
if (!backoff)
return;
- thread_cancel(&backoff->t_holddown);
- thread_cancel(&backoff->t_timetolearn);
+ event_cancel(&backoff->t_holddown);
+ event_cancel(&backoff->t_timetolearn);
XFREE(MTYPE_SPF_BACKOFF_NAME, backoff->name);
XFREE(MTYPE_SPF_BACKOFF, backoff);
}
-static void spf_backoff_timetolearn_elapsed(struct thread *thread)
+static void spf_backoff_timetolearn_elapsed(struct event *thread)
{
- struct spf_backoff *backoff = THREAD_ARG(thread);
+ struct spf_backoff *backoff = EVENT_ARG(thread);
backoff->state = SPF_BACKOFF_LONG_WAIT;
backoff_debug("SPF Back-off(%s) TIMETOLEARN elapsed, move to state %s",
backoff->name, spf_backoff_state2str(backoff->state));
}
-static void spf_backoff_holddown_elapsed(struct thread *thread)
+static void spf_backoff_holddown_elapsed(struct event *thread)
{
- struct spf_backoff *backoff = THREAD_ARG(thread);
+ struct spf_backoff *backoff = EVENT_ARG(thread);
- THREAD_OFF(backoff->t_timetolearn);
+ EVENT_OFF(backoff->t_timetolearn);
timerclear(&backoff->first_event_time);
backoff->state = SPF_BACKOFF_QUIET;
backoff_debug("SPF Back-off(%s) HOLDDOWN elapsed, move to state %s",
@@ -139,21 +139,21 @@ long spf_backoff_schedule(struct spf_backoff *backoff)
switch (backoff->state) {
case SPF_BACKOFF_QUIET:
backoff->state = SPF_BACKOFF_SHORT_WAIT;
- thread_add_timer_msec(
+ event_add_timer_msec(
backoff->m, spf_backoff_timetolearn_elapsed, backoff,
backoff->timetolearn, &backoff->t_timetolearn);
- thread_add_timer_msec(backoff->m, spf_backoff_holddown_elapsed,
- backoff, backoff->holddown,
- &backoff->t_holddown);
+ event_add_timer_msec(backoff->m, spf_backoff_holddown_elapsed,
+ backoff, backoff->holddown,
+ &backoff->t_holddown);
backoff->first_event_time = now;
rv = backoff->init_delay;
break;
case SPF_BACKOFF_SHORT_WAIT:
case SPF_BACKOFF_LONG_WAIT:
- thread_cancel(&backoff->t_holddown);
- thread_add_timer_msec(backoff->m, spf_backoff_holddown_elapsed,
- backoff, backoff->holddown,
- &backoff->t_holddown);
+ event_cancel(&backoff->t_holddown);
+ event_add_timer_msec(backoff->m, spf_backoff_holddown_elapsed,
+ backoff, backoff->holddown,
+ &backoff->t_holddown);
if (backoff->state == SPF_BACKOFF_SHORT_WAIT)
rv = backoff->short_delay;
else
@@ -204,8 +204,8 @@ void spf_backoff_show(struct spf_backoff *backoff, struct vty *vty,
vty_out(vty, "%sHolddown timer: %ld msec\n", prefix,
backoff->holddown);
if (backoff->t_holddown) {
- struct timeval remain =
- thread_timer_remain(backoff->t_holddown);
+ struct timeval remain = event_timer_remain(backoff->t_holddown);
+
vty_out(vty, "%s Still runs for %lld msec\n",
prefix,
(long long)remain.tv_sec * 1000
@@ -218,7 +218,7 @@ void spf_backoff_show(struct spf_backoff *backoff, struct vty *vty,
backoff->timetolearn);
if (backoff->t_timetolearn) {
struct timeval remain =
- thread_timer_remain(backoff->t_timetolearn);
+ event_timer_remain(backoff->t_timetolearn);
vty_out(vty, "%s Still runs for %lld msec\n",
prefix,
(long long)remain.tv_sec * 1000
diff --git a/lib/spf_backoff.h b/lib/spf_backoff.h
index 87aa4a0825..83f1b76adc 100644
--- a/lib/spf_backoff.h
+++ b/lib/spf_backoff.h
@@ -18,10 +18,10 @@ extern "C" {
#endif
struct spf_backoff;
-struct thread_master;
+struct event_loop;
struct vty;
-struct spf_backoff *spf_backoff_new(struct thread_master *m, const char *name,
+struct spf_backoff *spf_backoff_new(struct event_loop *m, const char *name,
long init_delay, long short_delay,
long long_delay, long holddown,
long timetolearn);
diff --git a/lib/subdir.am b/lib/subdir.am
index beef8675aa..83eecbee57 100644
--- a/lib/subdir.am
+++ b/lib/subdir.am
@@ -38,8 +38,6 @@ lib_libfrr_la_SOURCES = \
lib/frrscript.c \
lib/frr_pthread.c \
lib/frrstr.c \
- lib/getopt.c \
- lib/getopt1.c \
lib/grammar_sandbox.c \
lib/graph.c \
lib/hash.c \
@@ -49,6 +47,7 @@ lib_libfrr_la_SOURCES = \
lib/if_rmap.c \
lib/imsg-buffer.c \
lib/imsg.c \
+ lib/iso.c \
lib/jhash.c \
lib/json.c \
lib/keychain.c \
@@ -64,6 +63,9 @@ lib_libfrr_la_SOURCES = \
lib/log_vty.c \
lib/md5.c \
lib/memory.c \
+ lib/mgmt_be_client.c \
+ lib/mgmt_fe_client.c \
+ lib/mgmt_msg.c \
lib/mlag.c \
lib/module.c \
lib/mpls.c \
@@ -105,7 +107,7 @@ lib_libfrr_la_SOURCES = \
lib/systemd.c \
lib/table.c \
lib/termtable.c \
- lib/thread.c \
+ lib/event.c \
lib/typerb.c \
lib/typesafe.c \
lib/vector.c \
@@ -146,6 +148,23 @@ nodist_lib_libfrr_la_SOURCES = \
yang/frr-module-translator.yang.c \
# end
+# Add logic to build mgmt.proto
+lib_libfrr_la_LIBADD += $(PROTOBUF_C_LIBS)
+
+BUILT_SOURCES += \
+ lib/mgmt.pb-c.c \
+ lib/mgmt.pb-c.h \
+ # end
+
+CLEANFILES += \
+ lib/mgmt.pb-c.h \
+ lib/mgmt.pb-c.c \
+ # end
+
+lib_libfrr_la_SOURCES += \
+ lib/mgmt.pb-c.c \
+ #end
+
if SQLITE3
lib_libfrr_la_LIBADD += $(SQLITE3_LIBS)
lib_libfrr_la_SOURCES += lib/db.c
@@ -161,7 +180,7 @@ clippy_scan += \
lib/plist.c \
lib/routemap.c \
lib/routemap_cli.c \
- lib/thread.c \
+ lib/event.c \
lib/vty.c \
lib/zlog_5424_cli.c \
# end
@@ -197,7 +216,6 @@ pkginclude_HEADERS += \
lib/frratomic.h \
lib/frrcu.h \
lib/frrstr.h \
- lib/getopt.h \
lib/graph.h \
lib/hash.h \
lib/hook.h \
@@ -207,6 +225,7 @@ pkginclude_HEADERS += \
lib/if_rmap.h \
lib/imsg.h \
lib/ipaddr.h \
+ lib/iso.h \
lib/jhash.h \
lib/json.h \
lib/keychain.h \
@@ -222,6 +241,11 @@ pkginclude_HEADERS += \
lib/log_vty.h \
lib/md5.h \
lib/memory.h \
+ lib/mgmt.pb-c.h \
+ lib/mgmt_be_client.h \
+ lib/mgmt_fe_client.h \
+ lib/mgmt_msg.h \
+ lib/mgmt_pb.h \
lib/module.h \
lib/monotime.h \
lib/mpls.h \
@@ -263,7 +287,7 @@ pkginclude_HEADERS += \
lib/systemd.h \
lib/table.h \
lib/termtable.h \
- lib/thread.h \
+ lib/frrevent.h \
lib/trace.h \
lib/typerb.h \
lib/typesafe.h \
diff --git a/lib/systemd.c b/lib/systemd.c
index 0106e88b93..56a53a6e78 100644
--- a/lib/systemd.c
+++ b/lib/systemd.c
@@ -7,7 +7,7 @@
#include <zebra.h>
#include <sys/un.h>
-#include "thread.h"
+#include "frrevent.h"
#include "systemd.h"
#include "lib_errors.h"
@@ -63,18 +63,18 @@ void systemd_send_stopping(void)
systemd_send_information("STOPPING=1");
}
-static struct thread_master *systemd_master = NULL;
+static struct event_loop *systemd_master = NULL;
-static void systemd_send_watchdog(struct thread *t)
+static void systemd_send_watchdog(struct event *t)
{
systemd_send_information("WATCHDOG=1");
assert(watchdog_msec > 0);
- thread_add_timer_msec(systemd_master, systemd_send_watchdog, NULL,
- watchdog_msec, NULL);
+ event_add_timer_msec(systemd_master, systemd_send_watchdog, NULL,
+ watchdog_msec, NULL);
}
-void systemd_send_started(struct thread_master *m)
+void systemd_send_started(struct event_loop *m)
{
assert(m != NULL);
diff --git a/lib/systemd.h b/lib/systemd.h
index 09f27a70ba..ba2461b8a1 100644
--- a/lib/systemd.h
+++ b/lib/systemd.h
@@ -21,11 +21,11 @@ extern bool sd_stderr_is_journal;
void systemd_send_stopping(void);
/*
- * master - The struct thread_master * to use to schedule ourself
+ * master - The struct event_loop * to use to schedule ourself
* the_process - Should we send watchdog if we are not the requested
* process?
*/
-void systemd_send_started(struct thread_master *master);
+void systemd_send_started(struct event_loop *master);
/*
* status - A status string to send to systemd
diff --git a/lib/thread.h b/lib/thread.h
deleted file mode 100644
index 128d11b6eb..0000000000
--- a/lib/thread.h
+++ /dev/null
@@ -1,291 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0-or-later
-/* Thread management routine header.
- * Copyright (C) 1998 Kunihiro Ishiguro
- */
-
-#ifndef _ZEBRA_THREAD_H
-#define _ZEBRA_THREAD_H
-
-#include <zebra.h>
-#include <pthread.h>
-#include <poll.h>
-#include "monotime.h"
-#include "frratomic.h"
-#include "typesafe.h"
-#include "xref.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-extern bool cputime_enabled;
-extern unsigned long cputime_threshold;
-/* capturing wallclock time is always enabled since it is fast (reading
- * hardware TSC w/o syscalls)
- */
-extern unsigned long walltime_threshold;
-
-struct rusage_t {
-#ifdef HAVE_CLOCK_THREAD_CPUTIME_ID
- struct timespec cpu;
-#else
- struct rusage cpu;
-#endif
- struct timeval real;
-};
-#define RUSAGE_T struct rusage_t
-
-#define GETRUSAGE(X) thread_getrusage(X)
-
-PREDECL_LIST(thread_list);
-PREDECL_HEAP(thread_timer_list);
-
-struct fd_handler {
- /* number of pfd that fit in the allocated space of pfds. This is a
- * constant and is the same for both pfds and copy.
- */
- nfds_t pfdsize;
-
- /* file descriptors to monitor for i/o */
- struct pollfd *pfds;
- /* number of pollfds stored in pfds */
- nfds_t pfdcount;
-
- /* chunk used for temp copy of pollfds */
- struct pollfd *copy;
- /* number of pollfds stored in copy */
- nfds_t copycount;
-};
-
-struct xref_threadsched {
- struct xref xref;
-
- const char *funcname;
- const char *dest;
- uint32_t thread_type;
-};
-
-/* Master of the theads. */
-struct thread_master {
- char *name;
-
- struct thread **read;
- struct thread **write;
- struct thread_timer_list_head timer;
- struct thread_list_head event, ready, unuse;
- struct list *cancel_req;
- bool canceled;
- pthread_cond_t cancel_cond;
- struct hash *cpu_record;
- int io_pipe[2];
- int fd_limit;
- struct fd_handler handler;
- unsigned long alloc;
- long selectpoll_timeout;
- bool spin;
- bool handle_signals;
- pthread_mutex_t mtx;
- pthread_t owner;
-
- bool ready_run_loop;
- RUSAGE_T last_getrusage;
-};
-
-/* Thread itself. */
-struct thread {
- uint8_t type; /* thread type */
- uint8_t add_type; /* thread type */
- struct thread_list_item threaditem;
- struct thread_timer_list_item timeritem;
- struct thread **ref; /* external reference (if given) */
- struct thread_master *master; /* pointer to the struct thread_master */
- void (*func)(struct thread *); /* event function */
- void *arg; /* event argument */
- union {
- int val; /* second argument of the event. */
- int fd; /* file descriptor in case of r/w */
- struct timeval sands; /* rest of time sands value. */
- } u;
- struct timeval real;
- struct cpu_thread_history *hist; /* cache pointer to cpu_history */
- unsigned long yield; /* yield time in microseconds */
- const struct xref_threadsched *xref; /* origin location */
- pthread_mutex_t mtx; /* mutex for thread.c functions */
- bool ignore_timer_late;
-};
-
-#ifdef _FRR_ATTRIBUTE_PRINTFRR
-#pragma FRR printfrr_ext "%pTH" (struct thread *)
-#endif
-
-struct cpu_thread_history {
- void (*func)(struct thread *);
- atomic_size_t total_cpu_warn;
- atomic_size_t total_wall_warn;
- atomic_size_t total_starv_warn;
- atomic_size_t total_calls;
- atomic_size_t total_active;
- struct time_stats {
- atomic_size_t total, max;
- } real;
- struct time_stats cpu;
- atomic_uint_fast32_t types;
- const char *funcname;
-};
-
-/* Struct timeval's tv_usec one second value. */
-#define TIMER_SECOND_MICRO 1000000L
-
-/* Thread types. */
-#define THREAD_READ 0
-#define THREAD_WRITE 1
-#define THREAD_TIMER 2
-#define THREAD_EVENT 3
-#define THREAD_READY 4
-#define THREAD_UNUSED 5
-#define THREAD_EXECUTE 6
-
-/* Thread yield time. */
-#define THREAD_YIELD_TIME_SLOT 10 * 1000L /* 10ms */
-
-#define THREAD_TIMER_STRLEN 12
-
-/* Macros. */
-#define THREAD_ARG(X) ((X)->arg)
-#define THREAD_FD(X) ((X)->u.fd)
-#define THREAD_VAL(X) ((X)->u.val)
-
-/*
- * Please consider this macro deprecated, and do not use it in new code.
- */
-#define THREAD_OFF(thread) \
- do { \
- if ((thread)) \
- thread_cancel(&(thread)); \
- } while (0)
-
-/*
- * Macro wrappers to generate xrefs for all thread add calls. Includes
- * file/line/function info for debugging/tracing.
- */
-#include "lib/xref.h"
-
-#define _xref_t_a(addfn, type, m, f, a, v, t) \
- ({ \
- static const struct xref_threadsched _xref \
- __attribute__((used)) = { \
- .xref = XREF_INIT(XREFT_THREADSCHED, NULL, __func__), \
- .funcname = #f, \
- .dest = #t, \
- .thread_type = THREAD_ ## type, \
- }; \
- XREF_LINK(_xref.xref); \
- _thread_add_ ## addfn(&_xref, m, f, a, v, t); \
- }) \
- /* end */
-
-#define thread_add_read(m,f,a,v,t) _xref_t_a(read_write, READ, m,f,a,v,t)
-#define thread_add_write(m,f,a,v,t) _xref_t_a(read_write, WRITE, m,f,a,v,t)
-#define thread_add_timer(m,f,a,v,t) _xref_t_a(timer, TIMER, m,f,a,v,t)
-#define thread_add_timer_msec(m,f,a,v,t) _xref_t_a(timer_msec, TIMER, m,f,a,v,t)
-#define thread_add_timer_tv(m,f,a,v,t) _xref_t_a(timer_tv, TIMER, m,f,a,v,t)
-#define thread_add_event(m,f,a,v,t) _xref_t_a(event, EVENT, m,f,a,v,t)
-
-#define thread_execute(m,f,a,v) \
- ({ \
- static const struct xref_threadsched _xref \
- __attribute__((used)) = { \
- .xref = XREF_INIT(XREFT_THREADSCHED, NULL, __func__), \
- .funcname = #f, \
- .dest = NULL, \
- .thread_type = THREAD_EXECUTE, \
- }; \
- XREF_LINK(_xref.xref); \
- _thread_execute(&_xref, m, f, a, v); \
- }) /* end */
-
-/* Prototypes. */
-extern struct thread_master *thread_master_create(const char *);
-void thread_master_set_name(struct thread_master *master, const char *name);
-extern void thread_master_free(struct thread_master *);
-extern void thread_master_free_unused(struct thread_master *);
-
-extern void _thread_add_read_write(const struct xref_threadsched *xref,
- struct thread_master *master,
- void (*fn)(struct thread *), void *arg,
- int fd, struct thread **tref);
-
-extern void _thread_add_timer(const struct xref_threadsched *xref,
- struct thread_master *master,
- void (*fn)(struct thread *), void *arg, long t,
- struct thread **tref);
-
-extern void _thread_add_timer_msec(const struct xref_threadsched *xref,
- struct thread_master *master,
- void (*fn)(struct thread *), void *arg,
- long t, struct thread **tref);
-
-extern void _thread_add_timer_tv(const struct xref_threadsched *xref,
- struct thread_master *master,
- void (*fn)(struct thread *), void *arg,
- struct timeval *tv, struct thread **tref);
-
-extern void _thread_add_event(const struct xref_threadsched *xref,
- struct thread_master *master,
- void (*fn)(struct thread *), void *arg, int val,
- struct thread **tref);
-
-extern void _thread_execute(const struct xref_threadsched *xref,
- struct thread_master *master,
- void (*fn)(struct thread *), void *arg, int val);
-
-extern void thread_cancel(struct thread **event);
-extern void thread_cancel_async(struct thread_master *, struct thread **,
- void *);
-/* Cancel ready tasks with an arg matching 'arg' */
-extern void thread_cancel_event_ready(struct thread_master *m, void *arg);
-/* Cancel all tasks with an arg matching 'arg', including timers and io */
-extern void thread_cancel_event(struct thread_master *m, void *arg);
-extern struct thread *thread_fetch(struct thread_master *, struct thread *);
-extern void thread_call(struct thread *);
-extern unsigned long thread_timer_remain_second(struct thread *);
-extern struct timeval thread_timer_remain(struct thread *);
-extern unsigned long thread_timer_remain_msec(struct thread *);
-extern int thread_should_yield(struct thread *);
-/* set yield time for thread */
-extern void thread_set_yield_time(struct thread *, unsigned long);
-
-/* Internal libfrr exports */
-extern void thread_getrusage(RUSAGE_T *);
-extern void thread_cmd_init(void);
-
-/* Returns elapsed real (wall clock) time. */
-extern unsigned long thread_consumed_time(RUSAGE_T *after, RUSAGE_T *before,
- unsigned long *cpu_time_elapsed);
-
-/* only for use in logging functions! */
-extern pthread_key_t thread_current;
-extern char *thread_timer_to_hhmmss(char *buf, int buf_size,
- struct thread *t_timer);
-
-static inline bool thread_is_scheduled(struct thread *thread)
-{
- if (thread)
- return true;
-
- return false;
-}
-
-/* Debug signal mask */
-void debug_signals(const sigset_t *sigs);
-
-static inline void thread_ignore_late_timer(struct thread *thread)
-{
- thread->ignore_timer_late = true;
-}
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* _ZEBRA_THREAD_H */
diff --git a/lib/vrf.c b/lib/vrf.c
index a60f532f41..73f5d8ff72 100644
--- a/lib/vrf.c
+++ b/lib/vrf.c
@@ -394,11 +394,7 @@ void vrf_bitmap_free(vrf_bitmap_t bmap)
{
struct hash *vrf_hash = bmap;
- if (vrf_hash == NULL)
- return;
-
- hash_clean(vrf_hash, vrf_hash_bitmap_free);
- hash_free(vrf_hash);
+ hash_clean_and_free(&vrf_hash, vrf_hash_bitmap_free);
}
void vrf_bitmap_set(vrf_bitmap_t bmap, vrf_id_t vrf_id)
diff --git a/lib/vty.c b/lib/vty.c
index 786271abe8..974f5380d3 100644
--- a/lib/vty.c
+++ b/lib/vty.c
@@ -22,7 +22,7 @@
#include <stdio.h>
#include "linklist.h"
-#include "thread.h"
+#include "frrevent.h"
#include "buffer.h"
#include "command.h"
#include "sockunion.h"
@@ -65,6 +65,14 @@ enum vty_event {
#endif /* VTYSH */
};
+struct nb_config *vty_mgmt_candidate_config;
+
+static uintptr_t mgmt_lib_hndl;
+static bool mgmt_fe_connected;
+static bool mgmt_candidate_ds_wr_locked;
+static uint64_t mgmt_client_id_next;
+static uint64_t mgmt_last_req_id = UINT64_MAX;
+
PREDECL_DLIST(vtyservs);
struct vty_serv {
@@ -73,13 +81,14 @@ struct vty_serv {
int sock;
bool vtysh;
- struct thread *t_accept;
+ struct event *t_accept;
};
DECLARE_DLIST(vtyservs, struct vty_serv, itm);
static void vty_event_serv(enum vty_event event, struct vty_serv *);
static void vty_event(enum vty_event, struct vty *);
+static int vtysh_flush(struct vty *vty);
/* Extern host structure from command.c */
extern struct host host;
@@ -112,6 +121,36 @@ static char integrate_default[] = SYSCONFDIR INTEGRATE_DEFAULT_CONFIG;
static bool do_log_commands;
static bool do_log_commands_perm;
+void vty_mgmt_resume_response(struct vty *vty, bool success)
+{
+ uint8_t header[4] = {0, 0, 0, 0};
+ int ret = CMD_SUCCESS;
+
+ if (!vty->mgmt_req_pending) {
+ zlog_err(
+ "vty response called without setting mgmt_req_pending");
+ return;
+ }
+
+ if (!success)
+ ret = CMD_WARNING_CONFIG_FAILED;
+
+ vty->mgmt_req_pending = false;
+ header[3] = ret;
+ buffer_put(vty->obuf, header, 4);
+
+ if (!vty->t_write && (vtysh_flush(vty) < 0))
+ /* Try to flush results; exit if a write
+ * error occurs.
+ */
+ return;
+
+ if (vty->status == VTY_CLOSE)
+ vty_close(vty);
+ else
+ vty_event(VTYSH_READ, vty);
+}
+
void vty_frame(struct vty *vty, const char *format, ...)
{
va_list args;
@@ -506,7 +545,7 @@ static int vty_command(struct vty *vty, char *buf)
GETRUSAGE(&after);
- walltime = thread_consumed_time(&after, &before, &cputime);
+ walltime = event_consumed_time(&after, &before, &cputime);
if (cputime_enabled_here && cputime_enabled && cputime_threshold
&& cputime > cputime_threshold)
@@ -1321,13 +1360,13 @@ static void vty_buffer_reset(struct vty *vty)
}
/* Read data via vty socket. */
-static void vty_read(struct thread *thread)
+static void vty_read(struct event *thread)
{
int i;
int nbytes;
unsigned char buf[VTY_READ_BUFSIZ];
- struct vty *vty = THREAD_ARG(thread);
+ struct vty *vty = EVENT_ARG(thread);
/* Read raw data from socket */
if ((nbytes = read(vty->fd, buf, VTY_READ_BUFSIZ)) <= 0) {
@@ -1524,15 +1563,15 @@ static void vty_read(struct thread *thread)
}
/* Flush buffer to the vty. */
-static void vty_flush(struct thread *thread)
+static void vty_flush(struct event *thread)
{
int erase;
buffer_status_t flushrc;
- struct vty *vty = THREAD_ARG(thread);
+ struct vty *vty = EVENT_ARG(thread);
/* Tempolary disable read thread. */
if (vty->lines == 0)
- THREAD_OFF(vty->t_read);
+ EVENT_OFF(vty->t_read);
/* Function execution continue. */
erase = ((vty->status == VTY_MORE || vty->status == VTY_MORELINE));
@@ -1586,6 +1625,16 @@ struct vty *vty_new(void)
new->max = VTY_BUFSIZ;
new->pass_fd = -1;
+ if (mgmt_lib_hndl) {
+ new->mgmt_client_id = mgmt_client_id_next++;
+ if (mgmt_fe_create_client_session(
+ mgmt_lib_hndl, new->mgmt_client_id,
+ (uintptr_t) new) != MGMTD_SUCCESS)
+ zlog_err(
+ "Failed to open a MGMTD Frontend session for VTY session %p!!",
+ new);
+ }
+
return new;
}
@@ -1708,9 +1757,9 @@ void vty_stdio_suspend(void)
if (!stdio_vty)
return;
- THREAD_OFF(stdio_vty->t_write);
- THREAD_OFF(stdio_vty->t_read);
- THREAD_OFF(stdio_vty->t_timeout);
+ EVENT_OFF(stdio_vty->t_write);
+ EVENT_OFF(stdio_vty->t_read);
+ EVENT_OFF(stdio_vty->t_timeout);
if (stdio_termios)
tcsetattr(0, TCSANOW, &stdio_orig_termios);
@@ -1774,9 +1823,9 @@ struct vty *vty_stdio(void (*atclose)(int isexit))
}
/* Accept connection from the network. */
-static void vty_accept(struct thread *thread)
+static void vty_accept(struct event *thread)
{
- struct vty_serv *vtyserv = THREAD_ARG(thread);
+ struct vty_serv *vtyserv = EVENT_ARG(thread);
int vty_sock;
union sockunion su;
int ret;
@@ -1987,9 +2036,9 @@ static void vty_serv_un(const char *path)
/* #define VTYSH_DEBUG 1 */
-static void vtysh_accept(struct thread *thread)
+static void vtysh_accept(struct event *thread)
{
- struct vty_serv *vtyserv = THREAD_ARG(thread);
+ struct vty_serv *vtyserv = EVENT_ARG(thread);
int accept_sock = vtyserv->sock;
int sock;
int client_len;
@@ -2117,7 +2166,7 @@ void vty_pass_fd(struct vty *vty, int fd)
vty->pass_fd = fd;
}
-static void vtysh_read(struct thread *thread)
+static void vtysh_read(struct event *thread)
{
int ret;
int sock;
@@ -2127,8 +2176,8 @@ static void vtysh_read(struct thread *thread)
unsigned char *p;
uint8_t header[4] = {0, 0, 0, 0};
- sock = THREAD_FD(thread);
- vty = THREAD_ARG(thread);
+ sock = EVENT_FD(thread);
+ vty = EVENT_ARG(thread);
if ((nbytes = read(sock, buf, VTY_READ_BUFSIZ)) <= 0) {
if (nbytes < 0) {
@@ -2201,6 +2250,12 @@ static void vtysh_read(struct thread *thread)
if (ret == CMD_SUSPEND)
break;
+ /* with new infra we need to stop response till
+ * we get response through callback.
+ */
+ if (vty->mgmt_req_pending)
+ return;
+
/* warning: watchfrr hardcodes this result write
*/
header[3] = ret;
@@ -2220,9 +2275,9 @@ static void vtysh_read(struct thread *thread)
vty_event(VTYSH_READ, vty);
}
-static void vtysh_write(struct thread *thread)
+static void vtysh_write(struct event *thread)
{
- struct vty *vty = THREAD_ARG(thread);
+ struct vty *vty = EVENT_ARG(thread);
vtysh_flush(vty);
}
@@ -2257,13 +2312,19 @@ void vty_close(struct vty *vty)
int i;
bool was_stdio = false;
+ if (mgmt_lib_hndl) {
+ mgmt_fe_destroy_client_session(mgmt_lib_hndl,
+ vty->mgmt_client_id);
+ vty->mgmt_session_id = 0;
+ }
+
/* Drop out of configure / transaction if needed. */
vty_config_exit(vty);
/* Cancel threads.*/
- THREAD_OFF(vty->t_read);
- THREAD_OFF(vty->t_write);
- THREAD_OFF(vty->t_timeout);
+ EVENT_OFF(vty->t_read);
+ EVENT_OFF(vty->t_write);
+ EVENT_OFF(vty->t_timeout);
if (vty->pass_fd != -1) {
close(vty->pass_fd);
@@ -2321,11 +2382,11 @@ void vty_close(struct vty *vty)
}
/* When time out occur output message then close connection. */
-static void vty_timeout(struct thread *thread)
+static void vty_timeout(struct event *thread)
{
struct vty *vty;
- vty = THREAD_ARG(thread);
+ vty = EVENT_ARG(thread);
vty->v_timeout = 0;
/* Clear buffer*/
@@ -2339,7 +2400,7 @@ static void vty_timeout(struct thread *thread)
}
/* Read up configuration file from file_name. */
-static void vty_read_file(struct nb_config *config, FILE *confp)
+void vty_read_file(struct nb_config *config, FILE *confp)
{
int ret;
struct vty *vty;
@@ -2632,6 +2693,23 @@ int vty_config_enter(struct vty *vty, bool private_config, bool exclusive)
return CMD_WARNING;
}
+ if (vty_mgmt_fe_enabled()) {
+ if (!mgmt_candidate_ds_wr_locked) {
+ if (vty_mgmt_send_lockds_req(vty, MGMTD_DS_CANDIDATE,
+ true) != 0) {
+ vty_out(vty, "Not able to lock candidate DS\n");
+ return CMD_WARNING;
+ }
+ } else {
+ vty_out(vty,
+ "Candidate DS already locked by different session\n");
+ return CMD_WARNING;
+ }
+
+ vty->mgmt_locked_candidate_ds = true;
+ mgmt_candidate_ds_wr_locked = true;
+ }
+
vty->node = CONFIG_NODE;
vty->config = true;
vty->private_config = private_config;
@@ -2643,7 +2721,14 @@ int vty_config_enter(struct vty *vty, bool private_config, bool exclusive)
vty_out(vty,
"Warning: uncommitted changes will be discarded on exit.\n\n");
} else {
- vty->candidate_config = vty_shared_candidate_config;
+ /*
+ * NOTE: On the MGMTD daemon we point the VTY candidate DS to
+ * the global MGMTD candidate DS. Else we point to the VTY
+ * Shared Candidate Config.
+ */
+ vty->candidate_config = vty_mgmt_candidate_config
+ ? vty_mgmt_candidate_config
+ : vty_shared_candidate_config;
if (frr_get_cli_mode() == FRR_CLI_TRANSACTIONAL)
vty->candidate_config_base =
nb_config_dup(running_config);
@@ -2676,6 +2761,18 @@ int vty_config_node_exit(struct vty *vty)
{
vty->xpath_index = 0;
+ if (vty_mgmt_fe_enabled() && mgmt_candidate_ds_wr_locked &&
+ vty->mgmt_locked_candidate_ds) {
+ if (vty_mgmt_send_lockds_req(vty, MGMTD_DS_CANDIDATE, false) !=
+ 0) {
+ vty_out(vty, "Not able to unlock candidate DS\n");
+ return CMD_WARNING;
+ }
+
+ vty->mgmt_locked_candidate_ds = false;
+ mgmt_candidate_ds_wr_locked = false;
+ }
+
/* Perform any pending commits. */
(void)nb_cli_pending_commit_check(vty);
@@ -2704,19 +2801,19 @@ int vty_config_node_exit(struct vty *vty)
}
/* Master of the threads. */
-static struct thread_master *vty_master;
+static struct event_loop *vty_master;
static void vty_event_serv(enum vty_event event, struct vty_serv *vty_serv)
{
switch (event) {
case VTY_SERV:
- thread_add_read(vty_master, vty_accept, vty_serv,
- vty_serv->sock, &vty_serv->t_accept);
+ event_add_read(vty_master, vty_accept, vty_serv, vty_serv->sock,
+ &vty_serv->t_accept);
break;
#ifdef VTYSH
case VTYSH_SERV:
- thread_add_read(vty_master, vtysh_accept, vty_serv,
- vty_serv->sock, &vty_serv->t_accept);
+ event_add_read(vty_master, vtysh_accept, vty_serv,
+ vty_serv->sock, &vty_serv->t_accept);
break;
#endif /* VTYSH */
case VTY_READ:
@@ -2733,34 +2830,34 @@ static void vty_event(enum vty_event event, struct vty *vty)
switch (event) {
#ifdef VTYSH
case VTYSH_READ:
- thread_add_read(vty_master, vtysh_read, vty, vty->fd,
- &vty->t_read);
+ event_add_read(vty_master, vtysh_read, vty, vty->fd,
+ &vty->t_read);
break;
case VTYSH_WRITE:
- thread_add_write(vty_master, vtysh_write, vty, vty->wfd,
- &vty->t_write);
+ event_add_write(vty_master, vtysh_write, vty, vty->wfd,
+ &vty->t_write);
break;
#endif /* VTYSH */
case VTY_READ:
- thread_add_read(vty_master, vty_read, vty, vty->fd,
- &vty->t_read);
+ event_add_read(vty_master, vty_read, vty, vty->fd,
+ &vty->t_read);
/* Time out treatment. */
if (vty->v_timeout) {
- THREAD_OFF(vty->t_timeout);
- thread_add_timer(vty_master, vty_timeout, vty,
- vty->v_timeout, &vty->t_timeout);
+ EVENT_OFF(vty->t_timeout);
+ event_add_timer(vty_master, vty_timeout, vty,
+ vty->v_timeout, &vty->t_timeout);
}
break;
case VTY_WRITE:
- thread_add_write(vty_master, vty_flush, vty, vty->wfd,
- &vty->t_write);
+ event_add_write(vty_master, vty_flush, vty, vty->wfd,
+ &vty->t_write);
break;
case VTY_TIMEOUT_RESET:
- THREAD_OFF(vty->t_timeout);
+ EVENT_OFF(vty->t_timeout);
if (vty->v_timeout)
- thread_add_timer(vty_master, vty_timeout, vty,
- vty->v_timeout, &vty->t_timeout);
+ event_add_timer(vty_master, vty_timeout, vty,
+ vty->v_timeout, &vty->t_timeout);
break;
case VTY_SERV:
case VTYSH_SERV:
@@ -3173,8 +3270,392 @@ void vty_init_vtysh(void)
/* currently nothing to do, but likely to have future use */
}
+static void vty_mgmt_server_connected(uintptr_t lib_hndl, uintptr_t usr_data,
+ bool connected)
+{
+ zlog_err("%sGot %sconnected %s MGMTD Frontend Server",
+ !connected ? "ERROR: " : "", !connected ? "dis: " : "",
+ !connected ? "from" : "to");
+
+ mgmt_fe_connected = connected;
+
+ /*
+ * TODO: Setup or teardown front-end sessions for existing
+ * VTY connections.
+ */
+}
+
+static void vty_mgmt_session_created(uintptr_t lib_hndl, uintptr_t usr_data,
+ uint64_t client_id, bool create,
+ bool success, uintptr_t session_id,
+ uintptr_t session_ctx)
+{
+ struct vty *vty;
+
+ vty = (struct vty *)session_ctx;
+
+ if (!success) {
+ zlog_err("%s session for client %llu failed!",
+ create ? "Creating" : "Destroying",
+ (unsigned long long)client_id);
+ return;
+ }
+
+ zlog_err("%s session for client %llu successfully!",
+ create ? "Created" : "Destroyed",
+ (unsigned long long)client_id);
+ if (create)
+ vty->mgmt_session_id = session_id;
+}
+
+static void vty_mgmt_ds_lock_notified(uintptr_t lib_hndl, uintptr_t usr_data,
+ uint64_t client_id, uintptr_t session_id,
+ uintptr_t session_ctx, uint64_t req_id,
+ bool lock_ds, bool success,
+ Mgmtd__DatastoreId ds_id,
+ char *errmsg_if_any)
+{
+ struct vty *vty;
+
+ vty = (struct vty *)session_ctx;
+
+ if (!success) {
+ zlog_err("%socking for DS %u failed! Err: '%s'",
+ lock_ds ? "L" : "Unl", ds_id, errmsg_if_any);
+ vty_out(vty, "ERROR: %socking for DS %u failed! Err: '%s'\n",
+ lock_ds ? "L" : "Unl", ds_id, errmsg_if_any);
+ } else {
+ zlog_err("%socked DS %u successfully!", lock_ds ? "L" : "Unl",
+ ds_id);
+ }
+
+ vty_mgmt_resume_response(vty, success);
+}
+
+static void vty_mgmt_set_config_result_notified(
+ uintptr_t lib_hndl, uintptr_t usr_data, uint64_t client_id,
+ uintptr_t session_id, uintptr_t session_ctx, uint64_t req_id,
+ bool success, Mgmtd__DatastoreId ds_id, char *errmsg_if_any)
+{
+ struct vty *vty;
+
+ vty = (struct vty *)session_ctx;
+
+ if (!success) {
+ zlog_err(
+ "SET_CONFIG request for client 0x%llx failed! Error: '%s'",
+ (unsigned long long)client_id,
+ errmsg_if_any ? errmsg_if_any : "Unknown");
+ vty_out(vty, "ERROR: SET_CONFIG request failed! Error: %s\n",
+ errmsg_if_any ? errmsg_if_any : "Unknown");
+ } else {
+ zlog_err(
+ "SET_CONFIG request for client 0x%llx req-id %llu was successfull!",
+ (unsigned long long)client_id,
+ (unsigned long long)req_id);
+ }
+
+ vty_mgmt_resume_response(vty, success);
+}
+
+static void vty_mgmt_commit_config_result_notified(
+ uintptr_t lib_hndl, uintptr_t usr_data, uint64_t client_id,
+ uintptr_t session_id, uintptr_t session_ctx, uint64_t req_id,
+ bool success, Mgmtd__DatastoreId src_ds_id,
+ Mgmtd__DatastoreId dst_ds_id, bool validate_only, char *errmsg_if_any)
+{
+ struct vty *vty;
+
+ vty = (struct vty *)session_ctx;
+
+ if (!success) {
+ zlog_err(
+ "COMMIT_CONFIG request for client 0x%llx failed! Error: '%s'",
+ (unsigned long long)client_id,
+ errmsg_if_any ? errmsg_if_any : "Unknown");
+ vty_out(vty, "ERROR: COMMIT_CONFIG request failed! Error: %s\n",
+ errmsg_if_any ? errmsg_if_any : "Unknown");
+ } else {
+ zlog_err(
+ "COMMIT_CONFIG request for client 0x%llx req-id %llu was successfull!",
+ (unsigned long long)client_id,
+ (unsigned long long)req_id);
+ if (errmsg_if_any)
+ vty_out(vty, "MGMTD: %s\n", errmsg_if_any);
+ }
+
+ vty_mgmt_resume_response(vty, success);
+}
+
+static enum mgmt_result vty_mgmt_get_data_result_notified(
+ uintptr_t lib_hndl, uintptr_t usr_data, uint64_t client_id,
+ uintptr_t session_id, uintptr_t session_ctx, uint64_t req_id,
+ bool success, Mgmtd__DatastoreId ds_id, Mgmtd__YangData **yang_data,
+ size_t num_data, int next_key, char *errmsg_if_any)
+{
+ struct vty *vty;
+ size_t indx;
+
+ vty = (struct vty *)session_ctx;
+
+ if (!success) {
+ zlog_err(
+ "GET_DATA request for client 0x%llx failed! Error: '%s'",
+ (unsigned long long)client_id,
+ errmsg_if_any ? errmsg_if_any : "Unknown");
+ vty_out(vty, "ERROR: GET_DATA request failed! Error: %s\n",
+ errmsg_if_any ? errmsg_if_any : "Unknown");
+ vty_mgmt_resume_response(vty, success);
+ return MGMTD_INTERNAL_ERROR;
+ }
+
+ zlog_debug(
+ "GET_DATA request for client 0x%llx req-id %llu was successfull!",
+ (unsigned long long)client_id, (unsigned long long)req_id);
+
+ if (req_id != mgmt_last_req_id) {
+ mgmt_last_req_id = req_id;
+ vty_out(vty, "[\n");
+ }
+
+ for (indx = 0; indx < num_data; indx++) {
+ vty_out(vty, " \"%s\": \"%s\"\n", yang_data[indx]->xpath,
+ yang_data[indx]->value->encoded_str_val);
+ }
+ if (next_key < 0) {
+ vty_out(vty, "]\n");
+ vty_mgmt_resume_response(vty, success);
+ }
+
+ return MGMTD_SUCCESS;
+}
+
+static struct mgmt_fe_client_params client_params = {
+ .client_connect_notify = vty_mgmt_server_connected,
+ .client_session_notify = vty_mgmt_session_created,
+ .lock_ds_notify = vty_mgmt_ds_lock_notified,
+ .set_config_notify = vty_mgmt_set_config_result_notified,
+ .commit_config_notify = vty_mgmt_commit_config_result_notified,
+ .get_data_notify = vty_mgmt_get_data_result_notified,
+};
+
+void vty_init_mgmt_fe(void)
+{
+ if (!vty_master) {
+ zlog_err("Always call vty_mgmt_init_fe() after vty_init()!!");
+ return;
+ }
+
+ assert(!mgmt_lib_hndl);
+ snprintf(client_params.name, sizeof(client_params.name), "%s-%lld",
+ frr_get_progname(), (long long)getpid());
+ mgmt_lib_hndl = mgmt_fe_client_lib_init(&client_params, vty_master);
+ assert(mgmt_lib_hndl);
+}
+
+bool vty_mgmt_fe_enabled(void)
+{
+ return mgmt_lib_hndl && mgmt_fe_connected ? true : false;
+}
+
+int vty_mgmt_send_lockds_req(struct vty *vty, Mgmtd__DatastoreId ds_id,
+ bool lock)
+{
+ enum mgmt_result ret;
+
+ if (mgmt_lib_hndl && vty->mgmt_session_id) {
+ vty->mgmt_req_id++;
+ ret = mgmt_fe_lock_ds(mgmt_lib_hndl, vty->mgmt_session_id,
+ vty->mgmt_req_id, ds_id, lock);
+ if (ret != MGMTD_SUCCESS) {
+ zlog_err(
+ "Failed to send %sLOCK-DS-REQ to MGMTD for req-id %llu.",
+ lock ? "" : "UN",
+ (unsigned long long)vty->mgmt_req_id);
+ vty_out(vty, "Failed to send %sLOCK-DS-REQ to MGMTD!",
+ lock ? "" : "UN");
+ return -1;
+ }
+
+ vty->mgmt_req_pending = true;
+ }
+
+ return 0;
+}
+
+int vty_mgmt_send_config_data(struct vty *vty)
+{
+ Mgmtd__YangDataValue value[VTY_MAXCFGCHANGES];
+ Mgmtd__YangData cfg_data[VTY_MAXCFGCHANGES];
+ Mgmtd__YangCfgDataReq cfg_req[VTY_MAXCFGCHANGES];
+ Mgmtd__YangCfgDataReq *cfgreq[VTY_MAXCFGCHANGES] = {0};
+ size_t indx;
+ int cnt;
+ bool implicit_commit = false;
+
+ if (mgmt_lib_hndl && vty->mgmt_session_id) {
+ cnt = 0;
+ for (indx = 0; indx < vty->num_cfg_changes; indx++) {
+ mgmt_yang_data_init(&cfg_data[cnt]);
+
+ if (vty->cfg_changes[indx].value) {
+ mgmt_yang_data_value_init(&value[cnt]);
+ value[cnt].encoded_str_val =
+ (char *)vty->cfg_changes[indx].value;
+ value[cnt].value_case =
+ MGMTD__YANG_DATA_VALUE__VALUE_ENCODED_STR_VAL;
+ cfg_data[cnt].value = &value[cnt];
+ }
+
+ cfg_data[cnt].xpath = vty->cfg_changes[indx].xpath;
+
+ mgmt_yang_cfg_data_req_init(&cfg_req[cnt]);
+ cfg_req[cnt].data = &cfg_data[cnt];
+ switch (vty->cfg_changes[indx].operation) {
+ case NB_OP_DESTROY:
+ cfg_req[cnt].req_type =
+ MGMTD__CFG_DATA_REQ_TYPE__DELETE_DATA;
+ break;
+
+ case NB_OP_CREATE:
+ case NB_OP_MODIFY:
+ case NB_OP_MOVE:
+ case NB_OP_PRE_VALIDATE:
+ case NB_OP_APPLY_FINISH:
+ cfg_req[cnt].req_type =
+ MGMTD__CFG_DATA_REQ_TYPE__SET_DATA;
+ break;
+ case NB_OP_GET_ELEM:
+ case NB_OP_GET_NEXT:
+ case NB_OP_GET_KEYS:
+ case NB_OP_LOOKUP_ENTRY:
+ case NB_OP_RPC:
+ assert(!"Invalid type of operation");
+ break;
+ default:
+ assert(!"non-enum value, invalid");
+ }
+
+ cfgreq[cnt] = &cfg_req[cnt];
+ cnt++;
+ }
+
+ vty->mgmt_req_id++;
+ implicit_commit = vty_needs_implicit_commit(vty);
+ if (cnt && mgmt_fe_set_config_data(
+ mgmt_lib_hndl, vty->mgmt_session_id,
+ vty->mgmt_req_id, MGMTD_DS_CANDIDATE, cfgreq,
+ cnt, implicit_commit,
+ MGMTD_DS_RUNNING) != MGMTD_SUCCESS) {
+ zlog_err("Failed to send %d Config Xpaths to MGMTD!!",
+ (int)indx);
+ return -1;
+ }
+
+ vty->mgmt_req_pending = true;
+ }
+
+ return 0;
+}
+
+int vty_mgmt_send_commit_config(struct vty *vty, bool validate_only, bool abort)
+{
+ enum mgmt_result ret;
+
+ if (mgmt_lib_hndl && vty->mgmt_session_id) {
+ vty->mgmt_req_id++;
+ ret = mgmt_fe_commit_config_data(
+ mgmt_lib_hndl, vty->mgmt_session_id, vty->mgmt_req_id,
+ MGMTD_DS_CANDIDATE, MGMTD_DS_RUNNING, validate_only,
+ abort);
+ if (ret != MGMTD_SUCCESS) {
+ zlog_err(
+ "Failed to send COMMIT-REQ to MGMTD for req-id %llu.",
+ (unsigned long long)vty->mgmt_req_id);
+ vty_out(vty, "Failed to send COMMIT-REQ to MGMTD!");
+ return -1;
+ }
+
+ vty->mgmt_req_pending = true;
+ vty->mgmt_num_pending_setcfg = 0;
+ }
+
+ return 0;
+}
+
+int vty_mgmt_send_get_config(struct vty *vty, Mgmtd__DatastoreId datastore,
+ const char **xpath_list, int num_req)
+{
+ enum mgmt_result ret;
+ Mgmtd__YangData yang_data[VTY_MAXCFGCHANGES];
+ Mgmtd__YangGetDataReq get_req[VTY_MAXCFGCHANGES];
+ Mgmtd__YangGetDataReq *getreq[VTY_MAXCFGCHANGES];
+ int i;
+
+ vty->mgmt_req_id++;
+
+ for (i = 0; i < num_req; i++) {
+ mgmt_yang_get_data_req_init(&get_req[i]);
+ mgmt_yang_data_init(&yang_data[i]);
+
+ yang_data->xpath = (char *)xpath_list[i];
+
+ get_req[i].data = &yang_data[i];
+ getreq[i] = &get_req[i];
+ }
+ ret = mgmt_fe_get_config_data(mgmt_lib_hndl, vty->mgmt_session_id,
+ vty->mgmt_req_id, datastore, getreq,
+ num_req);
+
+ if (ret != MGMTD_SUCCESS) {
+ zlog_err("Failed to send GET-CONFIG to MGMTD for req-id %llu.",
+ (unsigned long long)vty->mgmt_req_id);
+ vty_out(vty, "Failed to send GET-CONFIG to MGMTD!");
+ return -1;
+ }
+
+ vty->mgmt_req_pending = true;
+
+ return 0;
+}
+
+int vty_mgmt_send_get_data(struct vty *vty, Mgmtd__DatastoreId datastore,
+ const char **xpath_list, int num_req)
+{
+ enum mgmt_result ret;
+ Mgmtd__YangData yang_data[VTY_MAXCFGCHANGES];
+ Mgmtd__YangGetDataReq get_req[VTY_MAXCFGCHANGES];
+ Mgmtd__YangGetDataReq *getreq[VTY_MAXCFGCHANGES];
+ int i;
+
+ vty->mgmt_req_id++;
+
+ for (i = 0; i < num_req; i++) {
+ mgmt_yang_get_data_req_init(&get_req[i]);
+ mgmt_yang_data_init(&yang_data[i]);
+
+ yang_data->xpath = (char *)xpath_list[i];
+
+ get_req[i].data = &yang_data[i];
+ getreq[i] = &get_req[i];
+ }
+ ret = mgmt_fe_get_data(mgmt_lib_hndl, vty->mgmt_session_id,
+ vty->mgmt_req_id, datastore, getreq, num_req);
+
+ if (ret != MGMTD_SUCCESS) {
+ zlog_err("Failed to send GET-DATA to MGMTD for req-id %llu.",
+ (unsigned long long)vty->mgmt_req_id);
+ vty_out(vty, "Failed to send GET-DATA to MGMTD!");
+ return -1;
+ }
+
+ vty->mgmt_req_pending = true;
+
+ return 0;
+}
+
/* Install vty's own commands like `who' command. */
-void vty_init(struct thread_master *master_thread, bool do_command_logging)
+void vty_init(struct event_loop *master_thread, bool do_command_logging)
{
/* For further configuration read, preserve current directory. */
vty_save_cwd();
@@ -3220,6 +3701,11 @@ void vty_terminate(void)
struct vty *vty;
struct vty_serv *vtyserv;
+ if (mgmt_lib_hndl) {
+ mgmt_fe_client_lib_destroy(mgmt_lib_hndl);
+ mgmt_lib_hndl = 0;
+ }
+
memset(vty_cwd, 0x00, sizeof(vty_cwd));
vty_reset();
@@ -3240,7 +3726,7 @@ void vty_terminate(void)
vtys_init(vtysh_sessions);
while ((vtyserv = vtyservs_pop(vty_servs))) {
- THREAD_OFF(vtyserv->t_accept);
+ EVENT_OFF(vtyserv->t_accept);
close(vtyserv->sock);
XFREE(MTYPE_VTY_SERV, vtyserv);
}
diff --git a/lib/vty.h b/lib/vty.h
index 3cab9590f1..5114238f6a 100644
--- a/lib/vty.h
+++ b/lib/vty.h
@@ -18,13 +18,15 @@
#include <regex.h>
#endif /* HAVE_LIBPCRE2_POSIX */
-#include "thread.h"
+#include "frrevent.h"
#include "log.h"
#include "sockunion.h"
#include "qobj.h"
#include "compiler.h"
#include "northbound.h"
#include "zlog_live.h"
+#include "libfrr.h"
+#include "mgmt_fe_client.h"
#ifdef __cplusplus
extern "C" {
@@ -113,12 +115,18 @@ struct vty {
/* Changes enqueued to be applied in the candidate configuration. */
size_t num_cfg_changes;
- struct vty_cfg_change cfg_changes[VTY_MAXCFGCHANGES];
+ struct nb_cfg_change cfg_changes[VTY_MAXCFGCHANGES];
/* XPath of the current node */
int xpath_index;
char xpath[VTY_MAXDEPTH][XPATH_MAXLEN];
+ /*
+ * Keep track of how many SET_CFG requests has been sent so far that
+ * has not been committed yet.
+ */
+ size_t mgmt_num_pending_setcfg;
+
/* In configure mode. */
bool config;
@@ -134,12 +142,13 @@ struct vty {
/* Dynamic transaction information. */
bool pending_allowed;
bool pending_commit;
+ bool no_implicit_commit;
char *pending_cmds_buf;
size_t pending_cmds_buflen;
size_t pending_cmds_bufpos;
/* Confirmed-commit timeout and rollback configuration. */
- struct thread *t_confirmed_commit_timeout;
+ struct event *t_confirmed_commit_timeout;
struct nb_config *confirmed_commit_rollback;
/* qobj object ID (replacement for "index") */
@@ -193,12 +202,12 @@ struct vty {
int lines;
/* Read and write thread. */
- struct thread *t_read;
- struct thread *t_write;
+ struct event *t_read;
+ struct event *t_write;
/* Timeout seconds and thread. */
unsigned long v_timeout;
- struct thread *t_timeout;
+ struct event *t_timeout;
/* What address is this vty comming from. */
char address[SU_ADDRSTRLEN];
@@ -208,6 +217,12 @@ struct vty {
* without any output. */
size_t frame_pos;
char frame[1024];
+
+ uintptr_t mgmt_session_id;
+ uint64_t mgmt_client_id;
+ uint64_t mgmt_req_id;
+ bool mgmt_req_pending;
+ bool mgmt_locked_candidate_ds;
};
static inline void vty_push_context(struct vty *vty, int node, uint64_t id)
@@ -319,8 +334,10 @@ struct vty_arg {
#define IS_DIRECTORY_SEP(c) ((c) == DIRECTORY_SEP)
#endif
+extern struct nb_config *vty_mgmt_candidate_config;
+
/* Prototypes. */
-extern void vty_init(struct thread_master *, bool do_command_logging);
+extern void vty_init(struct event_loop *m, bool do_command_logging);
extern void vty_init_vtysh(void);
extern void vty_terminate(void);
extern void vty_reset(void);
@@ -352,6 +369,7 @@ extern void vty_pass_fd(struct vty *vty, int fd);
extern bool vty_read_config(struct nb_config *config, const char *config_file,
char *config_default_dir);
+extern void vty_read_file(struct nb_config *config, FILE *confp);
extern void vty_time_print(struct vty *, int);
extern void vty_serv_sock(const char *, unsigned short, const char *);
extern void vty_close(struct vty *);
@@ -370,6 +388,29 @@ extern void vty_stdio_suspend(void);
extern void vty_stdio_resume(void);
extern void vty_stdio_close(void);
+extern void vty_init_mgmt_fe(void);
+extern bool vty_mgmt_fe_enabled(void);
+extern int vty_mgmt_send_config_data(struct vty *vty);
+extern int vty_mgmt_send_commit_config(struct vty *vty, bool validate_only,
+ bool abort);
+extern int vty_mgmt_send_get_config(struct vty *vty,
+ Mgmtd__DatastoreId datastore,
+ const char **xpath_list, int num_req);
+extern int vty_mgmt_send_get_data(struct vty *vty, Mgmtd__DatastoreId datastore,
+ const char **xpath_list, int num_req);
+extern int vty_mgmt_send_lockds_req(struct vty *vty, Mgmtd__DatastoreId ds_id,
+ bool lock);
+extern void vty_mgmt_resume_response(struct vty *vty, bool success);
+
+static inline bool vty_needs_implicit_commit(struct vty *vty)
+{
+ return (frr_get_cli_mode() == FRR_CLI_CLASSIC
+ ? ((vty->pending_allowed || vty->no_implicit_commit)
+ ? false
+ : true)
+ : false);
+}
+
#ifdef __cplusplus
}
#endif
diff --git a/lib/wheel.c b/lib/wheel.c
index 4aca23481b..e17995c64a 100644
--- a/lib/wheel.c
+++ b/lib/wheel.c
@@ -6,7 +6,7 @@
*/
#include "zebra.h"
#include "linklist.h"
-#include "thread.h"
+#include "frrevent.h"
#include "memory.h"
#include "wheel.h"
#include "log.h"
@@ -16,9 +16,9 @@ DEFINE_MTYPE_STATIC(LIB, TIMER_WHEEL_LIST, "Timer Wheel Slot List");
static int debug_timer_wheel = 0;
-static void wheel_timer_thread(struct thread *t);
+static void wheel_timer_thread(struct event *t);
-static void wheel_timer_thread_helper(struct thread *t)
+static void wheel_timer_thread_helper(struct event *t)
{
struct listnode *node, *nextnode;
unsigned long long curr_slot;
@@ -26,7 +26,7 @@ static void wheel_timer_thread_helper(struct thread *t)
struct timer_wheel *wheel;
void *data;
- wheel = THREAD_ARG(t);
+ wheel = EVENT_ARG(t);
wheel->curr_slot += wheel->slots_to_skip;
@@ -47,23 +47,23 @@ static void wheel_timer_thread_helper(struct thread *t)
slots_to_skip++;
wheel->slots_to_skip = slots_to_skip;
- thread_add_timer_msec(wheel->master, wheel_timer_thread, wheel,
- wheel->nexttime * slots_to_skip, &wheel->timer);
+ event_add_timer_msec(wheel->master, wheel_timer_thread, wheel,
+ wheel->nexttime * slots_to_skip, &wheel->timer);
}
-static void wheel_timer_thread(struct thread *t)
+static void wheel_timer_thread(struct event *t)
{
struct timer_wheel *wheel;
- wheel = THREAD_ARG(t);
+ wheel = EVENT_ARG(t);
- thread_execute(wheel->master, wheel_timer_thread_helper, wheel, 0);
+ event_execute(wheel->master, wheel_timer_thread_helper, wheel, 0);
}
-struct timer_wheel *wheel_init(struct thread_master *master, int period,
- size_t slots, unsigned int (*slot_key)(const void *),
- void (*slot_run)(void *),
- const char *run_name)
+struct timer_wheel *wheel_init(struct event_loop *master, int period,
+ size_t slots,
+ unsigned int (*slot_key)(const void *),
+ void (*slot_run)(void *), const char *run_name)
{
struct timer_wheel *wheel;
size_t i;
@@ -85,8 +85,8 @@ struct timer_wheel *wheel_init(struct thread_master *master, int period,
for (i = 0; i < slots; i++)
wheel->wheel_slot_lists[i] = list_new();
- thread_add_timer_msec(wheel->master, wheel_timer_thread, wheel,
- wheel->nexttime, &wheel->timer);
+ event_add_timer_msec(wheel->master, wheel_timer_thread, wheel,
+ wheel->nexttime, &wheel->timer);
return wheel;
}
@@ -99,7 +99,7 @@ void wheel_delete(struct timer_wheel *wheel)
list_delete(&wheel->wheel_slot_lists[i]);
}
- THREAD_OFF(wheel->timer);
+ EVENT_OFF(wheel->timer);
XFREE(MTYPE_TIMER_WHEEL_LIST, wheel->wheel_slot_lists);
XFREE(MTYPE_TIMER_WHEEL, wheel->name);
XFREE(MTYPE_TIMER_WHEEL, wheel);
diff --git a/lib/wheel.h b/lib/wheel.h
index 9aa808cdfd..0d9ac10020 100644
--- a/lib/wheel.h
+++ b/lib/wheel.h
@@ -13,7 +13,7 @@ extern "C" {
struct timer_wheel {
char *name;
- struct thread_master *master;
+ struct event_loop *master;
int slots;
long long curr_slot;
unsigned int period;
@@ -21,7 +21,7 @@ struct timer_wheel {
unsigned int slots_to_skip;
struct list **wheel_slot_lists;
- struct thread *timer;
+ struct event *timer;
/*
* Key to determine what slot the item belongs in
*/
@@ -66,7 +66,7 @@ struct timer_wheel {
* and cause significant amount of time handling thread events instead
* of running your code.
*/
-struct timer_wheel *wheel_init(struct thread_master *master, int period,
+struct timer_wheel *wheel_init(struct event_loop *master, int period,
size_t slots,
unsigned int (*slot_key)(const void *),
void (*slot_run)(void *), const char *run_name);
diff --git a/lib/workqueue.c b/lib/workqueue.c
index 5477aadd65..fa5d585360 100644
--- a/lib/workqueue.c
+++ b/lib/workqueue.c
@@ -6,7 +6,7 @@
*/
#include <zebra.h>
-#include "thread.h"
+#include "frrevent.h"
#include "memory.h"
#include "workqueue.h"
#include "linklist.h"
@@ -59,8 +59,7 @@ static void work_queue_item_remove(struct work_queue *wq,
}
/* create new work queue */
-struct work_queue *work_queue_new(struct thread_master *m,
- const char *queue_name)
+struct work_queue *work_queue_new(struct event_loop *m, const char *queue_name)
{
struct work_queue *new;
@@ -78,7 +77,7 @@ struct work_queue *work_queue_new(struct thread_master *m,
/* Default values, can be overridden by caller */
new->spec.hold = WORK_QUEUE_DEFAULT_HOLD;
- new->spec.yield = THREAD_YIELD_TIME_SLOT;
+ new->spec.yield = EVENT_YIELD_TIME_SLOT;
new->spec.retry = WORK_QUEUE_DEFAULT_RETRY;
return new;
@@ -88,7 +87,7 @@ void work_queue_free_and_null(struct work_queue **wqp)
{
struct work_queue *wq = *wqp;
- THREAD_OFF(wq->thread);
+ EVENT_OFF(wq->thread);
while (!work_queue_empty(wq)) {
struct work_queue_item *item = work_queue_last_item(wq);
@@ -106,29 +105,29 @@ void work_queue_free_and_null(struct work_queue **wqp)
bool work_queue_is_scheduled(struct work_queue *wq)
{
- return thread_is_scheduled(wq->thread);
+ return event_is_scheduled(wq->thread);
}
static int work_queue_schedule(struct work_queue *wq, unsigned int delay)
{
/* if appropriate, schedule work queue thread */
if (CHECK_FLAG(wq->flags, WQ_UNPLUGGED) &&
- !thread_is_scheduled(wq->thread) && !work_queue_empty(wq)) {
+ !event_is_scheduled(wq->thread) && !work_queue_empty(wq)) {
/* Schedule timer if there's a delay, otherwise just schedule
* as an 'event'
*/
if (delay > 0) {
- thread_add_timer_msec(wq->master, work_queue_run, wq,
- delay, &wq->thread);
- thread_ignore_late_timer(wq->thread);
+ event_add_timer_msec(wq->master, work_queue_run, wq,
+ delay, &wq->thread);
+ event_ignore_late_timer(wq->thread);
} else
- thread_add_event(wq->master, work_queue_run, wq, 0,
- &wq->thread);
+ event_add_event(wq->master, work_queue_run, wq, 0,
+ &wq->thread);
/* set thread yield time, if needed */
- if (thread_is_scheduled(wq->thread) &&
- wq->spec.yield != THREAD_YIELD_TIME_SLOT)
- thread_set_yield_time(wq->thread, wq->spec.yield);
+ if (event_is_scheduled(wq->thread) &&
+ wq->spec.yield != EVENT_YIELD_TIME_SLOT)
+ event_set_yield_time(wq->thread, wq->spec.yield);
return 1;
} else
return 0;
@@ -198,7 +197,7 @@ void workqueue_cmd_init(void)
*/
void work_queue_plug(struct work_queue *wq)
{
- THREAD_OFF(wq->thread);
+ EVENT_OFF(wq->thread);
UNSET_FLAG(wq->flags, WQ_UNPLUGGED);
}
@@ -218,7 +217,7 @@ void work_queue_unplug(struct work_queue *wq)
* will reschedule itself if required,
* otherwise work_queue_item_add
*/
-void work_queue_run(struct thread *thread)
+void work_queue_run(struct event *thread)
{
struct work_queue *wq;
struct work_queue_item *item, *titem;
@@ -226,7 +225,7 @@ void work_queue_run(struct thread *thread)
unsigned int cycles = 0;
char yielded = 0;
- wq = THREAD_ARG(thread);
+ wq = EVENT_ARG(thread);
assert(wq);
@@ -311,8 +310,8 @@ void work_queue_run(struct thread *thread)
cycles++;
/* test if we should yield */
- if (!(cycles % wq->cycles.granularity)
- && thread_should_yield(thread)) {
+ if (!(cycles % wq->cycles.granularity) &&
+ event_should_yield(thread)) {
yielded = 1;
goto stats;
}
diff --git a/lib/workqueue.h b/lib/workqueue.h
index c7ed14b056..5d84739d5c 100644
--- a/lib/workqueue.h
+++ b/lib/workqueue.h
@@ -47,8 +47,8 @@ struct work_queue {
/* Everything but the specification struct is private
* the following may be read
*/
- struct thread_master *master; /* thread master */
- struct thread *thread; /* thread, if one is active */
+ struct event_loop *master; /* thread master */
+ struct event *thread; /* thread, if one is active */
char *name; /* work queue name */
/* Specification for this work queue.
@@ -137,7 +137,7 @@ static inline void work_queue_item_dequeue(struct work_queue *wq,
* user must fill in the spec of the returned work queue before adding
* anything to it
*/
-extern struct work_queue *work_queue_new(struct thread_master *m,
+extern struct work_queue *work_queue_new(struct event_loop *m,
const char *queue_name);
/* destroy work queue */
@@ -158,7 +158,7 @@ extern void work_queue_unplug(struct work_queue *wq);
bool work_queue_is_scheduled(struct work_queue *wq);
/* Helpers, exported for thread.c and command.c */
-extern void work_queue_run(struct thread *thread);
+extern void work_queue_run(struct event *thread);
extern void workqueue_cmd_init(void);
diff --git a/lib/xref.h b/lib/xref.h
index b49c9eb2f2..f06d65b422 100644
--- a/lib/xref.h
+++ b/lib/xref.h
@@ -20,7 +20,7 @@ extern "C" {
enum xref_type {
XREFT_NONE = 0,
- XREFT_THREADSCHED = 0x100,
+ XREFT_EVENTSCHED = 0x100,
XREFT_LOGMSG = 0x200,
XREFT_ASSERT = 0x280,
diff --git a/lib/yang.c b/lib/yang.c
index 78738f7d4d..70a3251ab3 100644
--- a/lib/yang.c
+++ b/lib/yang.c
@@ -395,7 +395,12 @@ struct lyd_node *yang_dnode_get(const struct lyd_node *dnode, const char *xpath)
xpath += 2;
if (lyd_find_xpath(dnode, xpath, &set)) {
- assert(0); /* XXX replicates old libyang1 base code */
+ /*
+ * Commenting out the below assert failure as it crashes mgmtd
+ * when bad xpath is passed.
+ *
+ * assert(0); XXX replicates old libyang1 base code
+ */
goto exit;
}
if (set->count == 0)
diff --git a/lib/yang.h b/lib/yang.h
index 91cd641ce8..654c246f0d 100644
--- a/lib/yang.h
+++ b/lib/yang.h
@@ -50,7 +50,7 @@ struct yang_module {
#endif
#ifdef HAVE_SYSREPO
sr_subscription_ctx_t *sr_subscription;
- struct thread *sr_thread;
+ struct event *sr_thread;
#endif
};
RB_HEAD(yang_modules, yang_module);
diff --git a/lib/zclient.c b/lib/zclient.c
index 0e49d65528..d42cb20191 100644
--- a/lib/zclient.c
+++ b/lib/zclient.c
@@ -14,7 +14,7 @@
#include "vrf_int.h"
#include "if.h"
#include "log.h"
-#include "thread.h"
+#include "frrevent.h"
#include "zclient.h"
#include "memory.h"
#include "table.h"
@@ -51,7 +51,7 @@ socklen_t zclient_addr_len;
static int zclient_debug;
/* Allocate zclient structure. */
-struct zclient *zclient_new(struct thread_master *master,
+struct zclient *zclient_new(struct event_loop *master,
struct zclient_options *opt,
zclient_handler *const *handlers, size_t n_handlers)
{
@@ -160,9 +160,9 @@ void zclient_stop(struct zclient *zclient)
zlog_debug("zclient %p stopped", zclient);
/* Stop threads. */
- THREAD_OFF(zclient->t_read);
- THREAD_OFF(zclient->t_connect);
- THREAD_OFF(zclient->t_write);
+ EVENT_OFF(zclient->t_read);
+ EVENT_OFF(zclient->t_connect);
+ EVENT_OFF(zclient->t_write);
/* Reset streams. */
stream_reset(zclient->ibuf);
@@ -249,9 +249,9 @@ static enum zclient_send_status zclient_failed(struct zclient *zclient)
return ZCLIENT_SEND_FAILURE;
}
-static void zclient_flush_data(struct thread *thread)
+static void zclient_flush_data(struct event *thread)
{
- struct zclient *zclient = THREAD_ARG(thread);
+ struct zclient *zclient = EVENT_ARG(thread);
zclient->t_write = NULL;
if (zclient->sock < 0)
@@ -266,8 +266,8 @@ static void zclient_flush_data(struct thread *thread)
return;
case BUFFER_PENDING:
zclient->t_write = NULL;
- thread_add_write(zclient->master, zclient_flush_data, zclient,
- zclient->sock, &zclient->t_write);
+ event_add_write(zclient->master, zclient_flush_data, zclient,
+ zclient->sock, &zclient->t_write);
break;
case BUFFER_EMPTY:
if (zclient->zebra_buffer_write_ready)
@@ -295,11 +295,11 @@ enum zclient_send_status zclient_send_message(struct zclient *zclient)
__func__, zclient->sock);
return zclient_failed(zclient);
case BUFFER_EMPTY:
- THREAD_OFF(zclient->t_write);
+ EVENT_OFF(zclient->t_write);
return ZCLIENT_SEND_SUCCESS;
case BUFFER_PENDING:
- thread_add_write(zclient->master, zclient_flush_data, zclient,
- zclient->sock, &zclient->t_write);
+ event_add_write(zclient->master, zclient_flush_data, zclient,
+ zclient->sock, &zclient->t_write);
return ZCLIENT_SEND_BUFFERED;
}
@@ -744,11 +744,11 @@ void zclient_init(struct zclient *zclient, int redist_default,
/* This function is a wrapper function for calling zclient_start from
timer or event thread. */
-static void zclient_connect(struct thread *t)
+static void zclient_connect(struct event *t)
{
struct zclient *zclient;
- zclient = THREAD_ARG(t);
+ zclient = EVENT_ARG(t);
zclient->t_connect = NULL;
if (zclient_debug)
@@ -4026,7 +4026,7 @@ static zclient_handler *const lib_handlers[] = {
};
/* Zebra client message read function. */
-static void zclient_read(struct thread *thread)
+static void zclient_read(struct event *thread)
{
size_t already;
uint16_t length, command;
@@ -4035,7 +4035,7 @@ static void zclient_read(struct thread *thread)
struct zclient *zclient;
/* Get socket to zebra. */
- zclient = THREAD_ARG(thread);
+ zclient = EVENT_ARG(thread);
zclient->t_read = NULL;
/* Read zebra header (if we don't have it already). */
@@ -4204,22 +4204,22 @@ static void zclient_event(enum zclient_event event, struct zclient *zclient)
{
switch (event) {
case ZCLIENT_SCHEDULE:
- thread_add_event(zclient->master, zclient_connect, zclient, 0,
- &zclient->t_connect);
+ event_add_event(zclient->master, zclient_connect, zclient, 0,
+ &zclient->t_connect);
break;
case ZCLIENT_CONNECT:
if (zclient_debug)
zlog_debug(
"zclient connect failures: %d schedule interval is now %d",
zclient->fail, zclient->fail < 3 ? 10 : 60);
- thread_add_timer(zclient->master, zclient_connect, zclient,
- zclient->fail < 3 ? 10 : 60,
- &zclient->t_connect);
+ event_add_timer(zclient->master, zclient_connect, zclient,
+ zclient->fail < 3 ? 10 : 60,
+ &zclient->t_connect);
break;
case ZCLIENT_READ:
zclient->t_read = NULL;
- thread_add_read(zclient->master, zclient_read, zclient,
- zclient->sock, &zclient->t_read);
+ event_add_read(zclient->master, zclient_read, zclient,
+ zclient->sock, &zclient->t_read);
break;
}
}
@@ -4294,6 +4294,8 @@ int32_t zapi_capabilities_decode(struct stream *s, struct zapi_cap *api)
memset(api, 0, sizeof(*api));
+ api->safi = SAFI_UNICAST;
+
STREAM_GETL(s, api->cap);
switch (api->cap) {
case ZEBRA_CLIENT_GR_CAPABILITIES:
diff --git a/lib/zclient.h b/lib/zclient.h
index 53c7038c88..367e5b1474 100644
--- a/lib/zclient.h
+++ b/lib/zclient.h
@@ -290,7 +290,7 @@ typedef int (zclient_handler)(ZAPI_CALLBACK_ARGS);
/* Structure for the zebra client. */
struct zclient {
/* The thread master we schedule ourselves on */
- struct thread_master *master;
+ struct event_loop *master;
/* Privileges to change socket values */
struct zebra_privs_t *privs;
@@ -323,11 +323,11 @@ struct zclient {
struct buffer *wb;
/* Read and connect thread. */
- struct thread *t_read;
- struct thread *t_connect;
+ struct event *t_read;
+ struct event *t_connect;
/* Thread to write buffered data to zebra. */
- struct thread *t_write;
+ struct event *t_write;
/* Redistribute information. */
uint8_t redist_default; /* clients protocol */
@@ -862,7 +862,7 @@ int zclient_neigh_ip_encode(struct stream *s, uint16_t cmd, union sockunion *in,
extern uint32_t zclient_get_nhg_start(uint32_t proto);
-extern struct zclient *zclient_new(struct thread_master *m,
+extern struct zclient *zclient_new(struct event_loop *m,
struct zclient_options *opt,
zclient_handler *const *handlers,
size_t n_handlers);
diff --git a/lib/zlog.c b/lib/zlog.c
index e05720fd9e..309a955fa9 100644
--- a/lib/zlog.c
+++ b/lib/zlog.c
@@ -48,7 +48,7 @@
#include "frrcu.h"
#include "zlog.h"
#include "libfrr_trace.h"
-#include "thread.h"
+#include "frrevent.h"
DEFINE_MTYPE_STATIC(LIB, LOG_MESSAGE, "log message");
DEFINE_MTYPE_STATIC(LIB, LOG_TLSBUF, "log thread-local buffer");
@@ -506,7 +506,7 @@ static void vzlog_tls(struct zlog_tls *zlog_tls, const struct xref_logmsg *xref,
static void zlog_backtrace_msg(const struct xref_logmsg *xref, int prio)
{
- struct thread *tc = pthread_getspecific(thread_current);
+ struct event *tc = pthread_getspecific(thread_current);
const char *uid = xref->xref.xrefdata->uid;
bool found_thread = false;
diff --git a/lib/zlog_5424.c b/lib/zlog_5424.c
index 5264dda0f8..c15bdece29 100644
--- a/lib/zlog_5424.c
+++ b/lib/zlog_5424.c
@@ -26,7 +26,7 @@
#include "frr_pthread.h"
#include "command.h"
#include "monotime.h"
-#include "thread.h"
+#include "frrevent.h"
#include "lib/version.h"
#include "lib/lib_errors.h"
@@ -789,10 +789,10 @@ static void zlog_5424_cycle(struct zlog_cfg_5424 *zcf, int fd)
rcu_free(MTYPE_LOG_5424, oldt, zt.rcu_head);
}
-static void zlog_5424_reconnect(struct thread *t)
+static void zlog_5424_reconnect(struct event *t)
{
- struct zlog_cfg_5424 *zcf = THREAD_ARG(t);
- int fd = THREAD_FD(t);
+ struct zlog_cfg_5424 *zcf = EVENT_ARG(t);
+ int fd = EVENT_FD(t);
char dummy[256];
ssize_t ret;
@@ -800,8 +800,8 @@ static void zlog_5424_reconnect(struct thread *t)
ret = read(fd, dummy, sizeof(dummy));
if (ret > 0) {
/* logger is sending us something?!?! */
- thread_add_read(t->master, zlog_5424_reconnect, zcf, fd,
- &zcf->t_reconnect);
+ event_add_read(t->master, zlog_5424_reconnect, zcf, fd,
+ &zcf->t_reconnect);
return;
}
@@ -1030,14 +1030,14 @@ static int zlog_5424_open(struct zlog_cfg_5424 *zcf, int sock_type)
assert(zcf->master);
if (fd != -1) {
- thread_add_read(zcf->master, zlog_5424_reconnect, zcf,
- fd, &zcf->t_reconnect);
+ event_add_read(zcf->master, zlog_5424_reconnect, zcf,
+ fd, &zcf->t_reconnect);
zcf->reconn_backoff_cur = zcf->reconn_backoff;
} else {
- thread_add_timer_msec(zcf->master, zlog_5424_reconnect,
- zcf, zcf->reconn_backoff_cur,
- &zcf->t_reconnect);
+ event_add_timer_msec(zcf->master, zlog_5424_reconnect,
+ zcf, zcf->reconn_backoff_cur,
+ &zcf->t_reconnect);
zcf->reconn_backoff_cur += zcf->reconn_backoff_cur / 2;
if (zcf->reconn_backoff_cur > zcf->reconn_backoff_max)
@@ -1053,7 +1053,7 @@ bool zlog_5424_apply_dst(struct zlog_cfg_5424 *zcf)
{
int fd = -1;
- thread_cancel(&zcf->t_reconnect);
+ event_cancel(&zcf->t_reconnect);
if (zcf->prio_min != ZLOG_DISABLED)
fd = zlog_5424_open(zcf, -1);
@@ -1106,7 +1106,7 @@ bool zlog_5424_rotate(struct zlog_cfg_5424 *zcf)
if (!zcf->active)
return true;
- thread_cancel(&zcf->t_reconnect);
+ event_cancel(&zcf->t_reconnect);
/* need to retain the socket type because it also influences
* other fields (packets) and we can't atomically swap these
diff --git a/lib/zlog_5424.h b/lib/zlog_5424.h
index 377e7be220..06525c0044 100644
--- a/lib/zlog_5424.h
+++ b/lib/zlog_5424.h
@@ -13,8 +13,8 @@
#include "zlog_targets.h"
#include "qobj.h"
-struct thread;
-struct thread_master;
+struct event;
+struct event_loop;
enum zlog_5424_dst {
/* can be used to disable a target temporarily */
@@ -78,8 +78,8 @@ struct zlog_cfg_5424 {
*/
/* sockets only - read handler to reconnect on errors */
- struct thread_master *master;
- struct thread *t_reconnect;
+ struct event_loop *master;
+ struct event *t_reconnect;
unsigned int reconn_backoff, reconn_backoff_cur, reconn_backoff_max;
int sock_type;
struct sockaddr_storage sa;
diff --git a/lib/zlog_5424_cli.c b/lib/zlog_5424_cli.c
index 7f070afbc5..3003df542f 100644
--- a/lib/zlog_5424_cli.c
+++ b/lib/zlog_5424_cli.c
@@ -28,7 +28,7 @@ DECLARE_RBTREE_UNIQ(targets, struct zlog_cfg_5424_user, targets_item,
DEFINE_QOBJ_TYPE(zlog_cfg_5424_user);
static struct targets_head targets = INIT_RBTREE_UNIQ(targets);
-static struct thread_master *log_5424_master;
+static struct event_loop *log_5424_master;
static void clear_dst(struct zlog_cfg_5424_user *cfg);
@@ -948,7 +948,7 @@ void log_5424_cmd_init(void)
/* hooks */
-static int log_5424_early_init(struct thread_master *master);
+static int log_5424_early_init(struct event_loop *master);
static int log_5424_rotate(void);
static int log_5424_fini(void);
@@ -959,7 +959,7 @@ __attribute__((_CONSTRUCTOR(475))) static void zlog_5424_startup_init(void)
hook_register(frr_fini, log_5424_fini);
}
-static int log_5424_early_init(struct thread_master *master)
+static int log_5424_early_init(struct event_loop *master)
{
log_5424_master = master;
diff --git a/mgmtd/.gitignore b/mgmtd/.gitignore
new file mode 100644
index 0000000000..7ce107e93b
--- /dev/null
+++ b/mgmtd/.gitignore
@@ -0,0 +1 @@
+mgmtd
diff --git a/mgmtd/Makefile b/mgmtd/Makefile
new file mode 100644
index 0000000000..d69ec5f65a
--- /dev/null
+++ b/mgmtd/Makefile
@@ -0,0 +1,10 @@
+all: ALWAYS
+ @$(MAKE) -s -C .. mgmtd/mgmtd
+%: ALWAYS
+ @$(MAKE) -s -C .. mgmtd/$@
+
+Makefile:
+ #nothing
+ALWAYS:
+.PHONY: ALWAYS makefiles
+.SUFFIXES:
diff --git a/mgmtd/mgmt.c b/mgmtd/mgmt.c
new file mode 100644
index 0000000000..a5c0eb34a3
--- /dev/null
+++ b/mgmtd/mgmt.c
@@ -0,0 +1,84 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * FRR Management Daemon (MGMTD) program
+ *
+ * Copyright (C) 2021 Vmware, Inc.
+ * Pushpasis Sarkar
+ */
+
+#include <zebra.h>
+#include "mgmtd/mgmt.h"
+#include "mgmtd/mgmt_be_server.h"
+#include "mgmtd/mgmt_be_adapter.h"
+#include "mgmtd/mgmt_fe_server.h"
+#include "mgmtd/mgmt_fe_adapter.h"
+#include "mgmtd/mgmt_ds.h"
+#include "mgmtd/mgmt_history.h"
+#include "mgmtd/mgmt_memory.h"
+
+bool mgmt_debug_be;
+bool mgmt_debug_fe;
+bool mgmt_debug_ds;
+bool mgmt_debug_txn;
+
+/* MGMTD process wide configuration. */
+static struct mgmt_master mgmt_master;
+
+/* MGMTD process wide configuration pointer to export. */
+struct mgmt_master *mm;
+
+void mgmt_master_init(struct event_loop *master, const int buffer_size)
+{
+ memset(&mgmt_master, 0, sizeof(struct mgmt_master));
+
+ mm = &mgmt_master;
+ mm->master = master;
+ mm->terminating = false;
+ mm->socket_buffer = buffer_size;
+ mm->perf_stats_en = true;
+}
+
+void mgmt_init(void)
+{
+
+ /*
+ * Allocates some vital data structures used by peer commands in
+ * vty_init
+ */
+ vty_init_mgmt_fe();
+
+ /* Initialize datastores */
+ mgmt_ds_init(mm);
+
+ /* Initialize history */
+ mgmt_history_init();
+
+ /* Initialize MGMTD Transaction module */
+ mgmt_txn_init(mm, mm->master);
+
+ /* Initialize the MGMTD Backend Adapter Module */
+ mgmt_be_adapter_init(mm->master);
+
+ /* Initialize the MGMTD Frontend Adapter Module */
+ mgmt_fe_adapter_init(mm->master, mm);
+
+ /* Start the MGMTD Backend Server for clients to connect */
+ mgmt_be_server_init(mm->master);
+
+ /* Start the MGMTD Frontend Server for clients to connect */
+ mgmt_fe_server_init(mm->master);
+
+ /* MGMTD VTY commands installation. */
+ mgmt_vty_init();
+}
+
+void mgmt_terminate(void)
+{
+ mgmt_fe_server_destroy();
+ mgmt_fe_adapter_destroy();
+ mgmt_be_server_destroy();
+ mgmt_be_adapter_destroy();
+ mgmt_txn_destroy();
+ mgmt_history_destroy();
+ mgmt_ds_destroy();
+}
diff --git a/mgmtd/mgmt.h b/mgmtd/mgmt.h
new file mode 100644
index 0000000000..9579b02230
--- /dev/null
+++ b/mgmtd/mgmt.h
@@ -0,0 +1,117 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * MGMTD message definition header.
+ *
+ * Copyright (C) 2021 Vmware, Inc.
+ * Pushpasis Sarkar <spushpasis@vmware.com>
+ */
+
+#ifndef _FRR_MGMTD_H
+#define _FRR_MGMTD_H
+
+#include "vrf.h"
+#include "defaults.h"
+#include "stream.h"
+
+#include "mgmtd/mgmt_memory.h"
+#include "mgmtd/mgmt_defines.h"
+#include "mgmtd/mgmt_history.h"
+#include "mgmtd/mgmt_txn.h"
+#include "mgmtd/mgmt_ds.h"
+
+#define MGMTD_VTY_PORT 2622
+#define MGMTD_SOCKET_BUF_SIZE 65535
+#define MGMTD_MAX_COMMIT_LIST 10
+
+extern bool mgmt_debug_be;
+extern bool mgmt_debug_fe;
+extern bool mgmt_debug_ds;
+extern bool mgmt_debug_txn;
+
+struct mgmt_txn_ctx;
+
+/*
+ * MGMTD master for system wide configurations and variables.
+ */
+struct mgmt_master {
+ struct event_loop *master;
+
+ /* How big should we set the socket buffer size */
+ uint32_t socket_buffer;
+
+ /* The single instance of config transaction allowed at any time */
+ struct mgmt_txns_head txn_list;
+
+ /* Map of Transactions and its ID */
+ struct hash *txn_hash;
+ uint64_t next_txn_id;
+
+ /* The single instance of config transaction allowed at any time */
+ struct mgmt_txn_ctx *cfg_txn;
+
+ /* Datastores */
+ struct mgmt_ds_ctx *running_ds;
+ struct mgmt_ds_ctx *candidate_ds;
+ struct mgmt_ds_ctx *oper_ds;
+
+ bool terminating; /* global flag that sigint terminate seen */
+ bool perf_stats_en; /* to enable performance stats measurement */
+
+ /* List of commit infos */
+ struct mgmt_cmt_infos_head cmts; /* List of last 10 commits executed. */
+};
+
+extern struct mgmt_master *mm;
+extern char const *const mgmt_daemons[];
+extern uint mgmt_daemons_count;
+
+/* Inline functions */
+static inline unsigned long timeval_elapsed(struct timeval a, struct timeval b)
+{
+ return (((a.tv_sec - b.tv_sec) * TIMER_SECOND_MICRO)
+ + (a.tv_usec - b.tv_usec));
+}
+
+/*
+ * Remove trailing separator from a string.
+ *
+ * str
+ * A null terminated string.
+ *
+ * sep
+ * Trailing character that needs to be removed.
+ */
+static inline void mgmt_remove_trailing_separator(char *str, char sep)
+{
+ size_t len;
+
+ len = strlen(str);
+ if (len && str[len - 1] == sep)
+ str[len - 1] = '\0';
+}
+
+/* Prototypes. */
+extern void mgmt_terminate(void);
+extern void mgmt_reset(void);
+extern time_t mgmt_clock(void);
+
+extern int mgmt_config_write(struct vty *vty);
+
+extern void mgmt_master_init(struct event_loop *master, const int buffer_size);
+
+extern void mgmt_init(void);
+extern void mgmt_vty_init(void);
+
+static inline char *mgmt_realtime_to_string(struct timeval *tv, char *buf,
+ size_t sz)
+{
+ struct tm tm;
+ size_t n;
+
+ localtime_r((const time_t *)&tv->tv_sec, &tm);
+ n = strftime(buf, sz, "%Y-%m-%dT%H:%M:%S", &tm);
+ snprintf(&buf[n], sz - n, ",%06u000", (unsigned int)tv->tv_usec);
+ return buf;
+}
+
+#endif /* _FRR_MGMTD_H */
diff --git a/mgmtd/mgmt_be_adapter.c b/mgmtd/mgmt_be_adapter.c
new file mode 100644
index 0000000000..af43cf3eae
--- /dev/null
+++ b/mgmtd/mgmt_be_adapter.c
@@ -0,0 +1,1094 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * MGMTD Backend Client Connection Adapter
+ *
+ * Copyright (C) 2021 Vmware, Inc.
+ * Pushpasis Sarkar <spushpasis@vmware.com>
+ */
+
+#include <zebra.h>
+#include "frrevent.h"
+#include "sockopt.h"
+#include "network.h"
+#include "libfrr.h"
+#include "mgmt_msg.h"
+#include "mgmt_pb.h"
+#include "mgmtd/mgmt.h"
+#include "mgmtd/mgmt_memory.h"
+#include "mgmt_be_client.h"
+#include "mgmtd/mgmt_be_adapter.h"
+
+#ifdef REDIRECT_DEBUG_TO_STDERR
+#define MGMTD_BE_ADAPTER_DBG(fmt, ...) \
+ fprintf(stderr, "%s: " fmt "\n", __func__, ##__VA_ARGS__)
+#define MGMTD_BE_ADAPTER_ERR(fmt, ...) \
+ fprintf(stderr, "%s: ERROR, " fmt "\n", __func__, ##__VA_ARGS__)
+#else /* REDIRECT_DEBUG_TO_STDERR */
+#define MGMTD_BE_ADAPTER_DBG(fmt, ...) \
+ do { \
+ if (mgmt_debug_be) \
+ zlog_debug("%s: " fmt, __func__, ##__VA_ARGS__); \
+ } while (0)
+#define MGMTD_BE_ADAPTER_ERR(fmt, ...) \
+ zlog_err("%s: ERROR: " fmt, __func__, ##__VA_ARGS__)
+#endif /* REDIRECT_DEBUG_TO_STDERR */
+
+#define FOREACH_ADAPTER_IN_LIST(adapter) \
+ frr_each_safe (mgmt_be_adapters, &mgmt_be_adapters, (adapter))
+
+/*
+ * Static mapping of YANG XPath regular expressions and
+ * the corresponding interested backend clients.
+ * NOTE: Thiis is a static mapping defined by all MGMTD
+ * backend client modules (for now, till we develop a
+ * more dynamic way of creating and updating this map).
+ * A running map is created by MGMTD in run-time to
+ * handle real-time mapping of YANG xpaths to one or
+ * more interested backend client adapters.
+ *
+ * Please see xpath_map_reg[] in lib/mgmt_be_client.c
+ * for the actual map
+ */
+struct mgmt_be_xpath_map_reg {
+ const char *xpath_regexp; /* Longest matching regular expression */
+ enum mgmt_be_client_id *be_clients; /* clients to notify */
+};
+
+struct mgmt_be_xpath_regexp_map {
+ const char *xpath_regexp;
+ struct mgmt_be_client_subscr_info be_subscrs;
+};
+
+struct mgmt_be_get_adapter_config_params {
+ struct mgmt_be_client_adapter *adapter;
+ struct nb_config_cbs *cfg_chgs;
+ uint32_t seq;
+};
+
+/*
+ * Static mapping of YANG XPath regular expressions and
+ * the corresponding interested backend clients.
+ * NOTE: Thiis is a static mapping defined by all MGMTD
+ * backend client modules (for now, till we develop a
+ * more dynamic way of creating and updating this map).
+ * A running map is created by MGMTD in run-time to
+ * handle real-time mapping of YANG xpaths to one or
+ * more interested backend client adapters.
+ */
+static const struct mgmt_be_xpath_map_reg xpath_static_map_reg[] = {
+ {.xpath_regexp = "/frr-vrf:lib/*",
+ .be_clients =
+ (enum mgmt_be_client_id[]){
+#if HAVE_STATICD
+ MGMTD_BE_CLIENT_ID_STATICD,
+#endif
+ MGMTD_BE_CLIENT_ID_MAX}},
+ {.xpath_regexp = "/frr-interface:lib/*",
+ .be_clients =
+ (enum mgmt_be_client_id[]){
+#if HAVE_STATICD
+ MGMTD_BE_CLIENT_ID_STATICD,
+#endif
+ MGMTD_BE_CLIENT_ID_MAX}},
+ {.xpath_regexp =
+ "/frr-routing:routing/control-plane-protocols/control-plane-protocol[type='frr-staticd:staticd'][name='staticd'][vrf='default']/frr-staticd:staticd/*",
+
+ .be_clients =
+ (enum mgmt_be_client_id[]){
+#if HAVE_STATICD
+ MGMTD_BE_CLIENT_ID_STATICD,
+#endif
+ MGMTD_BE_CLIENT_ID_MAX}},
+};
+
+#define MGMTD_BE_MAX_NUM_XPATH_MAP 256
+static struct mgmt_be_xpath_regexp_map
+ mgmt_xpath_map[MGMTD_BE_MAX_NUM_XPATH_MAP];
+static int mgmt_num_xpath_maps;
+
+static struct event_loop *mgmt_be_adapter_tm;
+
+static struct mgmt_be_adapters_head mgmt_be_adapters;
+
+static struct mgmt_be_client_adapter
+ *mgmt_be_adapters_by_id[MGMTD_BE_CLIENT_ID_MAX];
+
+/* Forward declarations */
+static void
+mgmt_be_adapter_register_event(struct mgmt_be_client_adapter *adapter,
+ enum mgmt_be_event event);
+
+static struct mgmt_be_client_adapter *
+mgmt_be_find_adapter_by_fd(int conn_fd)
+{
+ struct mgmt_be_client_adapter *adapter;
+
+ FOREACH_ADAPTER_IN_LIST (adapter) {
+ if (adapter->conn_fd == conn_fd)
+ return adapter;
+ }
+
+ return NULL;
+}
+
+static struct mgmt_be_client_adapter *
+mgmt_be_find_adapter_by_name(const char *name)
+{
+ struct mgmt_be_client_adapter *adapter;
+
+ FOREACH_ADAPTER_IN_LIST (adapter) {
+ if (!strncmp(adapter->name, name, sizeof(adapter->name)))
+ return adapter;
+ }
+
+ return NULL;
+}
+
+static void
+mgmt_be_cleanup_adapters(void)
+{
+ struct mgmt_be_client_adapter *adapter;
+
+ FOREACH_ADAPTER_IN_LIST (adapter)
+ mgmt_be_adapter_unlock(&adapter);
+}
+
+static void mgmt_be_xpath_map_init(void)
+{
+ int indx, num_xpath_maps;
+ uint16_t indx1;
+ enum mgmt_be_client_id id;
+
+ MGMTD_BE_ADAPTER_DBG("Init XPath Maps");
+
+ num_xpath_maps = (int)array_size(xpath_static_map_reg);
+ for (indx = 0; indx < num_xpath_maps; indx++) {
+ MGMTD_BE_ADAPTER_DBG(" - XPATH: '%s'",
+ xpath_static_map_reg[indx].xpath_regexp);
+ mgmt_xpath_map[indx].xpath_regexp =
+ xpath_static_map_reg[indx].xpath_regexp;
+ for (indx1 = 0;; indx1++) {
+ id = xpath_static_map_reg[indx].be_clients[indx1];
+ if (id == MGMTD_BE_CLIENT_ID_MAX)
+ break;
+ MGMTD_BE_ADAPTER_DBG(" -- Client: %s Id: %u",
+ mgmt_be_client_id2name(id),
+ id);
+ if (id < MGMTD_BE_CLIENT_ID_MAX) {
+ mgmt_xpath_map[indx]
+ .be_subscrs.xpath_subscr[id]
+ .validate_config = 1;
+ mgmt_xpath_map[indx]
+ .be_subscrs.xpath_subscr[id]
+ .notify_config = 1;
+ mgmt_xpath_map[indx]
+ .be_subscrs.xpath_subscr[id]
+ .own_oper_data = 1;
+ }
+ }
+ }
+
+ mgmt_num_xpath_maps = indx;
+ MGMTD_BE_ADAPTER_DBG("Total XPath Maps: %u", mgmt_num_xpath_maps);
+}
+
+static int mgmt_be_eval_regexp_match(const char *xpath_regexp,
+ const char *xpath)
+{
+ int match_len = 0, re_indx = 0, xp_indx = 0;
+ int rexp_len, xpath_len;
+ bool match = true, re_wild = false, xp_wild = false;
+ bool delim = false, enter_wild_match = false;
+ char wild_delim = 0;
+
+ rexp_len = strlen(xpath_regexp);
+ xpath_len = strlen(xpath);
+
+ /*
+ * Remove the trailing wildcard from the regexp and Xpath.
+ */
+ if (rexp_len && xpath_regexp[rexp_len-1] == '*')
+ rexp_len--;
+ if (xpath_len && xpath[xpath_len-1] == '*')
+ xpath_len--;
+
+ if (!rexp_len || !xpath_len)
+ return 0;
+
+ for (re_indx = 0, xp_indx = 0;
+ match && re_indx < rexp_len && xp_indx < xpath_len;) {
+ match = (xpath_regexp[re_indx] == xpath[xp_indx]);
+
+ /*
+ * Check if we need to enter wildcard matching.
+ */
+ if (!enter_wild_match && !match &&
+ (xpath_regexp[re_indx] == '*'
+ || xpath[xp_indx] == '*')) {
+ /*
+ * Found wildcard
+ */
+ enter_wild_match =
+ (xpath_regexp[re_indx-1] == '/'
+ || xpath_regexp[re_indx-1] == '\''
+ || xpath[xp_indx-1] == '/'
+ || xpath[xp_indx-1] == '\'');
+ if (enter_wild_match) {
+ if (xpath_regexp[re_indx] == '*') {
+ /*
+ * Begin RE wildcard match.
+ */
+ re_wild = true;
+ wild_delim = xpath_regexp[re_indx-1];
+ } else if (xpath[xp_indx] == '*') {
+ /*
+ * Begin XP wildcard match.
+ */
+ xp_wild = true;
+ wild_delim = xpath[xp_indx-1];
+ }
+ }
+ }
+
+ /*
+ * Check if we need to exit wildcard matching.
+ */
+ if (enter_wild_match) {
+ if (re_wild && xpath[xp_indx] == wild_delim) {
+ /*
+ * End RE wildcard matching.
+ */
+ re_wild = false;
+ if (re_indx < rexp_len-1)
+ re_indx++;
+ enter_wild_match = false;
+ } else if (xp_wild
+ && xpath_regexp[re_indx] == wild_delim) {
+ /*
+ * End XP wildcard matching.
+ */
+ xp_wild = false;
+ if (xp_indx < xpath_len-1)
+ xp_indx++;
+ enter_wild_match = false;
+ }
+ }
+
+ match = (xp_wild || re_wild
+ || xpath_regexp[re_indx] == xpath[xp_indx]);
+
+ /*
+ * Check if we found a delimiter in both the Xpaths
+ */
+ if ((xpath_regexp[re_indx] == '/'
+ && xpath[xp_indx] == '/')
+ || (xpath_regexp[re_indx] == ']'
+ && xpath[xp_indx] == ']')
+ || (xpath_regexp[re_indx] == '['
+ && xpath[xp_indx] == '[')) {
+ /*
+ * Increment the match count if we have a
+ * new delimiter.
+ */
+ if (match && re_indx && xp_indx && !delim)
+ match_len++;
+ delim = true;
+ } else {
+ delim = false;
+ }
+
+ /*
+ * Proceed to the next character in the RE/XP string as
+ * necessary.
+ */
+ if (!re_wild)
+ re_indx++;
+ if (!xp_wild)
+ xp_indx++;
+ }
+
+ /*
+ * If we finished matching and the last token was a full match
+ * increment the match count appropriately.
+ */
+ if (match && !delim &&
+ (xpath_regexp[re_indx] == '/'
+ || xpath_regexp[re_indx] == ']'))
+ match_len++;
+
+ return match_len;
+}
+
+static void mgmt_be_adapter_disconnect(struct mgmt_be_client_adapter *adapter)
+{
+ if (adapter->conn_fd >= 0) {
+ close(adapter->conn_fd);
+ adapter->conn_fd = -1;
+ }
+
+ /*
+ * Notify about client disconnect for appropriate cleanup
+ */
+ mgmt_txn_notify_be_adapter_conn(adapter, false);
+
+ if (adapter->id < MGMTD_BE_CLIENT_ID_MAX) {
+ mgmt_be_adapters_by_id[adapter->id] = NULL;
+ adapter->id = MGMTD_BE_CLIENT_ID_MAX;
+ }
+
+ mgmt_be_adapters_del(&mgmt_be_adapters, adapter);
+
+ mgmt_be_adapter_unlock(&adapter);
+}
+
+static void
+mgmt_be_adapter_cleanup_old_conn(struct mgmt_be_client_adapter *adapter)
+{
+ struct mgmt_be_client_adapter *old;
+
+ FOREACH_ADAPTER_IN_LIST (old) {
+ if (old != adapter
+ && !strncmp(adapter->name, old->name, sizeof(adapter->name))) {
+ /*
+ * We have a Zombie lingering around
+ */
+ MGMTD_BE_ADAPTER_DBG(
+ "Client '%s' (FD:%d) seems to have reconnected. Removing old connection (FD:%d)!",
+ adapter->name, adapter->conn_fd, old->conn_fd);
+ mgmt_be_adapter_disconnect(old);
+ }
+ }
+}
+
+static int
+mgmt_be_adapter_handle_msg(struct mgmt_be_client_adapter *adapter,
+ Mgmtd__BeMessage *be_msg)
+{
+ /*
+ * protobuf-c adds a max size enum with an internal, and changing by
+ * version, name; cast to an int to avoid unhandled enum warnings
+ */
+ switch ((int)be_msg->message_case) {
+ case MGMTD__BE_MESSAGE__MESSAGE_SUBSCR_REQ:
+ MGMTD_BE_ADAPTER_DBG(
+ "Got Subscribe Req Msg from '%s' to %sregister %u xpaths",
+ be_msg->subscr_req->client_name,
+ !be_msg->subscr_req->subscribe_xpaths
+ && be_msg->subscr_req->n_xpath_reg
+ ? "de"
+ : "",
+ (uint32_t)be_msg->subscr_req->n_xpath_reg);
+
+ if (strlen(be_msg->subscr_req->client_name)) {
+ strlcpy(adapter->name, be_msg->subscr_req->client_name,
+ sizeof(adapter->name));
+ adapter->id = mgmt_be_client_name2id(adapter->name);
+ if (adapter->id >= MGMTD_BE_CLIENT_ID_MAX) {
+ MGMTD_BE_ADAPTER_ERR(
+ "Unable to resolve adapter '%s' to a valid ID. Disconnecting!",
+ adapter->name);
+ mgmt_be_adapter_disconnect(adapter);
+ }
+ mgmt_be_adapters_by_id[adapter->id] = adapter;
+ mgmt_be_adapter_cleanup_old_conn(adapter);
+ }
+ break;
+ case MGMTD__BE_MESSAGE__MESSAGE_TXN_REPLY:
+ MGMTD_BE_ADAPTER_DBG(
+ "Got %s TXN_REPLY Msg for Txn-Id 0x%llx from '%s' with '%s'",
+ be_msg->txn_reply->create ? "Create" : "Delete",
+ (unsigned long long)be_msg->txn_reply->txn_id,
+ adapter->name,
+ be_msg->txn_reply->success ? "success" : "failure");
+ /*
+ * Forward the TXN_REPLY to txn module.
+ */
+ mgmt_txn_notify_be_txn_reply(
+ be_msg->txn_reply->txn_id,
+ be_msg->txn_reply->create,
+ be_msg->txn_reply->success, adapter);
+ break;
+ case MGMTD__BE_MESSAGE__MESSAGE_CFG_DATA_REPLY:
+ MGMTD_BE_ADAPTER_DBG(
+ "Got CFGDATA_REPLY Msg from '%s' for Txn-Id 0x%llx Batch-Id 0x%llx with Err:'%s'",
+ adapter->name,
+ (unsigned long long)be_msg->cfg_data_reply->txn_id,
+ (unsigned long long)be_msg->cfg_data_reply->batch_id,
+ be_msg->cfg_data_reply->error_if_any
+ ? be_msg->cfg_data_reply->error_if_any
+ : "None");
+ /*
+ * Forward the CGFData-create reply to txn module.
+ */
+ mgmt_txn_notify_be_cfgdata_reply(
+ be_msg->cfg_data_reply->txn_id,
+ be_msg->cfg_data_reply->batch_id,
+ be_msg->cfg_data_reply->success,
+ be_msg->cfg_data_reply->error_if_any, adapter);
+ break;
+ case MGMTD__BE_MESSAGE__MESSAGE_CFG_APPLY_REPLY:
+ MGMTD_BE_ADAPTER_DBG(
+ "Got %s CFG_APPLY_REPLY Msg from '%s' for Txn-Id 0x%llx for %d batches (Id 0x%llx-0x%llx), Err:'%s'",
+ be_msg->cfg_apply_reply->success ? "successful"
+ : "failed",
+ adapter->name,
+ (unsigned long long)
+ be_msg->cfg_apply_reply->txn_id,
+ (int)be_msg->cfg_apply_reply->n_batch_ids,
+ (unsigned long long)
+ be_msg->cfg_apply_reply->batch_ids[0],
+ (unsigned long long)be_msg->cfg_apply_reply
+ ->batch_ids[be_msg->cfg_apply_reply
+ ->n_batch_ids
+ - 1],
+ be_msg->cfg_apply_reply->error_if_any
+ ? be_msg->cfg_apply_reply->error_if_any
+ : "None");
+ /*
+ * Forward the CGFData-apply reply to txn module.
+ */
+ mgmt_txn_notify_be_cfg_apply_reply(
+ be_msg->cfg_apply_reply->txn_id,
+ be_msg->cfg_apply_reply->success,
+ (uint64_t *)be_msg->cfg_apply_reply->batch_ids,
+ be_msg->cfg_apply_reply->n_batch_ids,
+ be_msg->cfg_apply_reply->error_if_any, adapter);
+ break;
+ case MGMTD__BE_MESSAGE__MESSAGE_GET_REPLY:
+ case MGMTD__BE_MESSAGE__MESSAGE_CFG_CMD_REPLY:
+ case MGMTD__BE_MESSAGE__MESSAGE_SHOW_CMD_REPLY:
+ case MGMTD__BE_MESSAGE__MESSAGE_NOTIFY_DATA:
+ /*
+ * TODO: Add handling code in future.
+ */
+ break;
+ /*
+ * NOTE: The following messages are always sent from MGMTD to
+ * Backend clients only and/or need not be handled on MGMTd.
+ */
+ case MGMTD__BE_MESSAGE__MESSAGE_SUBSCR_REPLY:
+ case MGMTD__BE_MESSAGE__MESSAGE_GET_REQ:
+ case MGMTD__BE_MESSAGE__MESSAGE_TXN_REQ:
+ case MGMTD__BE_MESSAGE__MESSAGE_CFG_DATA_REQ:
+ case MGMTD__BE_MESSAGE__MESSAGE_CFG_APPLY_REQ:
+ case MGMTD__BE_MESSAGE__MESSAGE_CFG_CMD_REQ:
+ case MGMTD__BE_MESSAGE__MESSAGE_SHOW_CMD_REQ:
+ case MGMTD__BE_MESSAGE__MESSAGE__NOT_SET:
+ default:
+ /*
+ * A 'default' case is being added contrary to the
+ * FRR code guidelines to take care of build
+ * failures on certain build systems (courtesy of
+ * the proto-c package).
+ */
+ break;
+ }
+
+ return 0;
+}
+
+static inline void
+mgmt_be_adapter_sched_msg_write(struct mgmt_be_client_adapter *adapter)
+{
+ if (!CHECK_FLAG(adapter->flags, MGMTD_BE_ADAPTER_FLAGS_WRITES_OFF))
+ mgmt_be_adapter_register_event(adapter, MGMTD_BE_CONN_WRITE);
+}
+
+static inline void
+mgmt_be_adapter_writes_on(struct mgmt_be_client_adapter *adapter)
+{
+ MGMTD_BE_ADAPTER_DBG("Resume writing msgs for '%s'", adapter->name);
+ UNSET_FLAG(adapter->flags, MGMTD_BE_ADAPTER_FLAGS_WRITES_OFF);
+ mgmt_be_adapter_sched_msg_write(adapter);
+}
+
+static inline void
+mgmt_be_adapter_writes_off(struct mgmt_be_client_adapter *adapter)
+{
+ SET_FLAG(adapter->flags, MGMTD_BE_ADAPTER_FLAGS_WRITES_OFF);
+ MGMTD_BE_ADAPTER_DBG("Pause writing msgs for '%s'", adapter->name);
+}
+
+static int mgmt_be_adapter_send_msg(struct mgmt_be_client_adapter *adapter,
+ Mgmtd__BeMessage *be_msg)
+{
+ if (adapter->conn_fd == -1) {
+ MGMTD_BE_ADAPTER_DBG("can't send message on closed connection");
+ return -1;
+ }
+
+ int rv = mgmt_msg_send_msg(
+ &adapter->mstate, be_msg,
+ mgmtd__be_message__get_packed_size(be_msg),
+ (size_t(*)(void *, void *))mgmtd__be_message__pack,
+ mgmt_debug_be);
+ mgmt_be_adapter_sched_msg_write(adapter);
+ return rv;
+}
+
+static int mgmt_be_send_txn_req(struct mgmt_be_client_adapter *adapter,
+ uint64_t txn_id, bool create)
+{
+ Mgmtd__BeMessage be_msg;
+ Mgmtd__BeTxnReq txn_req;
+
+ mgmtd__be_txn_req__init(&txn_req);
+ txn_req.create = create;
+ txn_req.txn_id = txn_id;
+
+ mgmtd__be_message__init(&be_msg);
+ be_msg.message_case = MGMTD__BE_MESSAGE__MESSAGE_TXN_REQ;
+ be_msg.txn_req = &txn_req;
+
+ MGMTD_BE_ADAPTER_DBG(
+ "Sending TXN_REQ message to Backend client '%s' for Txn-Id %llx",
+ adapter->name, (unsigned long long)txn_id);
+
+ return mgmt_be_adapter_send_msg(adapter, &be_msg);
+}
+
+static int
+mgmt_be_send_cfgdata_create_req(struct mgmt_be_client_adapter *adapter,
+ uint64_t txn_id, uint64_t batch_id,
+ Mgmtd__YangCfgDataReq **cfgdata_reqs,
+ size_t num_reqs, bool end_of_data)
+{
+ Mgmtd__BeMessage be_msg;
+ Mgmtd__BeCfgDataCreateReq cfgdata_req;
+
+ mgmtd__be_cfg_data_create_req__init(&cfgdata_req);
+ cfgdata_req.batch_id = batch_id;
+ cfgdata_req.txn_id = txn_id;
+ cfgdata_req.data_req = cfgdata_reqs;
+ cfgdata_req.n_data_req = num_reqs;
+ cfgdata_req.end_of_data = end_of_data;
+
+ mgmtd__be_message__init(&be_msg);
+ be_msg.message_case = MGMTD__BE_MESSAGE__MESSAGE_CFG_DATA_REQ;
+ be_msg.cfg_data_req = &cfgdata_req;
+
+ MGMTD_BE_ADAPTER_DBG(
+ "Sending CFGDATA_CREATE_REQ message to Backend client '%s' for Txn-Id %llx, Batch-Id: %llx",
+ adapter->name, (unsigned long long)txn_id,
+ (unsigned long long)batch_id);
+
+ return mgmt_be_adapter_send_msg(adapter, &be_msg);
+}
+
+static int mgmt_be_send_cfgapply_req(struct mgmt_be_client_adapter *adapter,
+ uint64_t txn_id)
+{
+ Mgmtd__BeMessage be_msg;
+ Mgmtd__BeCfgDataApplyReq apply_req;
+
+ mgmtd__be_cfg_data_apply_req__init(&apply_req);
+ apply_req.txn_id = txn_id;
+
+ mgmtd__be_message__init(&be_msg);
+ be_msg.message_case = MGMTD__BE_MESSAGE__MESSAGE_CFG_APPLY_REQ;
+ be_msg.cfg_apply_req = &apply_req;
+
+ MGMTD_BE_ADAPTER_DBG(
+ "Sending CFG_APPLY_REQ message to Backend client '%s' for Txn-Id 0x%llx",
+ adapter->name, (unsigned long long)txn_id);
+
+ return mgmt_be_adapter_send_msg(adapter, &be_msg);
+}
+
+static void mgmt_be_adapter_process_msg(void *user_ctx, uint8_t *data,
+ size_t len)
+{
+ struct mgmt_be_client_adapter *adapter = user_ctx;
+ Mgmtd__BeMessage *be_msg;
+
+ be_msg = mgmtd__be_message__unpack(NULL, len, data);
+ if (!be_msg) {
+ MGMTD_BE_ADAPTER_DBG(
+ "Failed to decode %zu bytes for adapter: %s", len,
+ adapter->name);
+ return;
+ }
+ MGMTD_BE_ADAPTER_DBG("Decoded %zu bytes of message: %u for adapter: %s",
+ len, be_msg->message_case, adapter->name);
+ (void)mgmt_be_adapter_handle_msg(adapter, be_msg);
+ mgmtd__be_message__free_unpacked(be_msg, NULL);
+}
+
+static void mgmt_be_adapter_proc_msgbufs(struct event *thread)
+{
+ struct mgmt_be_client_adapter *adapter = EVENT_ARG(thread);
+
+ if (mgmt_msg_procbufs(&adapter->mstate, mgmt_be_adapter_process_msg,
+ adapter, mgmt_debug_be))
+ mgmt_be_adapter_register_event(adapter, MGMTD_BE_PROC_MSG);
+}
+
+static void mgmt_be_adapter_read(struct event *thread)
+{
+ struct mgmt_be_client_adapter *adapter;
+ enum mgmt_msg_rsched rv;
+
+ adapter = (struct mgmt_be_client_adapter *)EVENT_ARG(thread);
+
+ rv = mgmt_msg_read(&adapter->mstate, adapter->conn_fd, mgmt_debug_be);
+ if (rv == MSR_DISCONNECT) {
+ mgmt_be_adapter_disconnect(adapter);
+ return;
+ }
+ if (rv == MSR_SCHED_BOTH)
+ mgmt_be_adapter_register_event(adapter, MGMTD_BE_PROC_MSG);
+ mgmt_be_adapter_register_event(adapter, MGMTD_BE_CONN_READ);
+}
+
+static void mgmt_be_adapter_write(struct event *thread)
+{
+ struct mgmt_be_client_adapter *adapter = EVENT_ARG(thread);
+ enum mgmt_msg_wsched rv;
+
+ rv = mgmt_msg_write(&adapter->mstate, adapter->conn_fd, mgmt_debug_be);
+ if (rv == MSW_SCHED_STREAM)
+ mgmt_be_adapter_register_event(adapter, MGMTD_BE_CONN_WRITE);
+ else if (rv == MSW_DISCONNECT)
+ mgmt_be_adapter_disconnect(adapter);
+ else if (rv == MSW_SCHED_WRITES_OFF) {
+ mgmt_be_adapter_writes_off(adapter);
+ mgmt_be_adapter_register_event(adapter,
+ MGMTD_BE_CONN_WRITES_ON);
+ } else
+ assert(rv == MSW_SCHED_NONE);
+}
+
+static void mgmt_be_adapter_resume_writes(struct event *thread)
+{
+ struct mgmt_be_client_adapter *adapter;
+
+ adapter = (struct mgmt_be_client_adapter *)EVENT_ARG(thread);
+ assert(adapter && adapter->conn_fd >= 0);
+
+ mgmt_be_adapter_writes_on(adapter);
+}
+
+static void mgmt_be_iter_and_get_cfg(struct mgmt_ds_ctx *ds_ctx,
+ char *xpath, struct lyd_node *node,
+ struct nb_node *nb_node, void *ctx)
+{
+ struct mgmt_be_client_subscr_info subscr_info;
+ struct mgmt_be_get_adapter_config_params *parms;
+ struct mgmt_be_client_adapter *adapter;
+ struct nb_config_cbs *root;
+ uint32_t *seq;
+
+ if (mgmt_be_get_subscr_info_for_xpath(xpath, &subscr_info) != 0) {
+ MGMTD_BE_ADAPTER_ERR(
+ "ERROR: Failed to get subscriber for '%s'", xpath);
+ return;
+ }
+
+ parms = (struct mgmt_be_get_adapter_config_params *)ctx;
+
+ adapter = parms->adapter;
+ if (!subscr_info.xpath_subscr[adapter->id].subscribed)
+ return;
+
+ root = parms->cfg_chgs;
+ seq = &parms->seq;
+ nb_config_diff_created(node, seq, root);
+}
+
+static void mgmt_be_adapter_conn_init(struct event *thread)
+{
+ struct mgmt_be_client_adapter *adapter;
+
+ adapter = (struct mgmt_be_client_adapter *)EVENT_ARG(thread);
+ assert(adapter && adapter->conn_fd >= 0);
+
+ /*
+ * Check first if the current session can run a CONFIG
+ * transaction or not. Reschedule if a CONFIG transaction
+ * from another session is already in progress.
+ */
+ if (mgmt_config_txn_in_progress() != MGMTD_SESSION_ID_NONE) {
+ mgmt_be_adapter_register_event(adapter, MGMTD_BE_CONN_INIT);
+ return;
+ }
+
+ /*
+ * Notify TXN module to create a CONFIG transaction and
+ * download the CONFIGs identified for this new client.
+ * If the TXN module fails to initiate the CONFIG transaction
+ * disconnect from the client forcing a reconnect later.
+ * That should also take care of destroying the adapter.
+ */
+ if (mgmt_txn_notify_be_adapter_conn(adapter, true) != 0) {
+ mgmt_be_adapter_disconnect(adapter);
+ adapter = NULL;
+ }
+}
+
+static void
+mgmt_be_adapter_register_event(struct mgmt_be_client_adapter *adapter,
+ enum mgmt_be_event event)
+{
+ struct timeval tv = {0};
+
+ switch (event) {
+ case MGMTD_BE_CONN_INIT:
+ event_add_timer_msec(mgmt_be_adapter_tm,
+ mgmt_be_adapter_conn_init, adapter,
+ MGMTD_BE_CONN_INIT_DELAY_MSEC,
+ &adapter->conn_init_ev);
+ break;
+ case MGMTD_BE_CONN_READ:
+ event_add_read(mgmt_be_adapter_tm, mgmt_be_adapter_read,
+ adapter, adapter->conn_fd, &adapter->conn_read_ev);
+ break;
+ case MGMTD_BE_CONN_WRITE:
+ if (adapter->conn_write_ev)
+ MGMTD_BE_ADAPTER_DBG(
+ "write ready notify already set for client %s",
+ adapter->name);
+ else
+ MGMTD_BE_ADAPTER_DBG(
+ "scheduling write ready notify for client %s",
+ adapter->name);
+ event_add_write(mgmt_be_adapter_tm, mgmt_be_adapter_write,
+ adapter, adapter->conn_fd, &adapter->conn_write_ev);
+ assert(adapter->conn_write_ev);
+ break;
+ case MGMTD_BE_PROC_MSG:
+ tv.tv_usec = MGMTD_BE_MSG_PROC_DELAY_USEC;
+ event_add_timer_tv(mgmt_be_adapter_tm,
+ mgmt_be_adapter_proc_msgbufs, adapter, &tv,
+ &adapter->proc_msg_ev);
+ break;
+ case MGMTD_BE_CONN_WRITES_ON:
+ event_add_timer_msec(mgmt_be_adapter_tm,
+ mgmt_be_adapter_resume_writes, adapter,
+ MGMTD_BE_MSG_WRITE_DELAY_MSEC,
+ &adapter->conn_writes_on);
+ break;
+ case MGMTD_BE_SERVER:
+ case MGMTD_BE_SCHED_CFG_PREPARE:
+ case MGMTD_BE_RESCHED_CFG_PREPARE:
+ case MGMTD_BE_SCHED_CFG_APPLY:
+ case MGMTD_BE_RESCHED_CFG_APPLY:
+ assert(!"mgmt_be_adapter_post_event() called incorrectly");
+ break;
+ }
+}
+
+void mgmt_be_adapter_lock(struct mgmt_be_client_adapter *adapter)
+{
+ adapter->refcount++;
+}
+
+extern void mgmt_be_adapter_unlock(struct mgmt_be_client_adapter **adapter)
+{
+ assert(*adapter && (*adapter)->refcount);
+
+ (*adapter)->refcount--;
+ if (!(*adapter)->refcount) {
+ mgmt_be_adapters_del(&mgmt_be_adapters, *adapter);
+ EVENT_OFF((*adapter)->conn_init_ev);
+ EVENT_OFF((*adapter)->conn_read_ev);
+ EVENT_OFF((*adapter)->conn_write_ev);
+ EVENT_OFF((*adapter)->conn_writes_on);
+ EVENT_OFF((*adapter)->proc_msg_ev);
+ mgmt_msg_destroy(&(*adapter)->mstate);
+ XFREE(MTYPE_MGMTD_BE_ADPATER, *adapter);
+ }
+
+ *adapter = NULL;
+}
+
+int mgmt_be_adapter_init(struct event_loop *tm)
+{
+ if (!mgmt_be_adapter_tm) {
+ mgmt_be_adapter_tm = tm;
+ memset(mgmt_xpath_map, 0, sizeof(mgmt_xpath_map));
+ mgmt_num_xpath_maps = 0;
+ memset(mgmt_be_adapters_by_id, 0,
+ sizeof(mgmt_be_adapters_by_id));
+ mgmt_be_adapters_init(&mgmt_be_adapters);
+ mgmt_be_xpath_map_init();
+ }
+
+ return 0;
+}
+
+void mgmt_be_adapter_destroy(void)
+{
+ mgmt_be_cleanup_adapters();
+}
+
+struct mgmt_be_client_adapter *
+mgmt_be_create_adapter(int conn_fd, union sockunion *from)
+{
+ struct mgmt_be_client_adapter *adapter = NULL;
+
+ adapter = mgmt_be_find_adapter_by_fd(conn_fd);
+ if (!adapter) {
+ adapter = XCALLOC(MTYPE_MGMTD_BE_ADPATER,
+ sizeof(struct mgmt_be_client_adapter));
+ assert(adapter);
+
+ adapter->conn_fd = conn_fd;
+ adapter->id = MGMTD_BE_CLIENT_ID_MAX;
+ memcpy(&adapter->conn_su, from, sizeof(adapter->conn_su));
+ snprintf(adapter->name, sizeof(adapter->name), "Unknown-FD-%d",
+ adapter->conn_fd);
+ mgmt_msg_init(&adapter->mstate, MGMTD_BE_MAX_NUM_MSG_PROC,
+ MGMTD_BE_MAX_NUM_MSG_WRITE, MGMTD_BE_MSG_MAX_LEN,
+ "BE-adapter");
+ mgmt_be_adapter_lock(adapter);
+
+ mgmt_be_adapter_register_event(adapter, MGMTD_BE_CONN_READ);
+ mgmt_be_adapters_add_tail(&mgmt_be_adapters, adapter);
+
+ RB_INIT(nb_config_cbs, &adapter->cfg_chgs);
+
+ MGMTD_BE_ADAPTER_DBG("Added new MGMTD Backend adapter '%s'",
+ adapter->name);
+ }
+
+ /* Make client socket non-blocking. */
+ set_nonblocking(adapter->conn_fd);
+ setsockopt_so_sendbuf(adapter->conn_fd, MGMTD_SOCKET_BE_SEND_BUF_SIZE);
+ setsockopt_so_recvbuf(adapter->conn_fd, MGMTD_SOCKET_BE_RECV_BUF_SIZE);
+
+ /* Trigger resync of config with the new adapter */
+ mgmt_be_adapter_register_event(adapter, MGMTD_BE_CONN_INIT);
+
+ return adapter;
+}
+
+struct mgmt_be_client_adapter *
+mgmt_be_get_adapter_by_id(enum mgmt_be_client_id id)
+{
+ return (id < MGMTD_BE_CLIENT_ID_MAX ? mgmt_be_adapters_by_id[id]
+ : NULL);
+}
+
+struct mgmt_be_client_adapter *
+mgmt_be_get_adapter_by_name(const char *name)
+{
+ return mgmt_be_find_adapter_by_name(name);
+}
+
+int mgmt_be_get_adapter_config(struct mgmt_be_client_adapter *adapter,
+ struct mgmt_ds_ctx *ds_ctx,
+ struct nb_config_cbs **cfg_chgs)
+{
+ char base_xpath[] = "/";
+ struct mgmt_be_get_adapter_config_params parms;
+
+ assert(cfg_chgs);
+
+ if (RB_EMPTY(nb_config_cbs, &adapter->cfg_chgs)) {
+ parms.adapter = adapter;
+ parms.cfg_chgs = &adapter->cfg_chgs;
+ parms.seq = 0;
+
+ mgmt_ds_iter_data(ds_ctx, base_xpath,
+ mgmt_be_iter_and_get_cfg, (void *)&parms,
+ false);
+ }
+
+ *cfg_chgs = &adapter->cfg_chgs;
+ return 0;
+}
+
+int mgmt_be_create_txn(struct mgmt_be_client_adapter *adapter,
+ uint64_t txn_id)
+{
+ return mgmt_be_send_txn_req(adapter, txn_id, true);
+}
+
+int mgmt_be_destroy_txn(struct mgmt_be_client_adapter *adapter,
+ uint64_t txn_id)
+{
+ return mgmt_be_send_txn_req(adapter, txn_id, false);
+}
+
+int mgmt_be_send_cfg_data_create_req(struct mgmt_be_client_adapter *adapter,
+ uint64_t txn_id, uint64_t batch_id,
+ struct mgmt_be_cfgreq *cfg_req,
+ bool end_of_data)
+{
+ return mgmt_be_send_cfgdata_create_req(
+ adapter, txn_id, batch_id, cfg_req->cfgdata_reqs,
+ cfg_req->num_reqs, end_of_data);
+}
+
+extern int
+mgmt_be_send_cfg_apply_req(struct mgmt_be_client_adapter *adapter,
+ uint64_t txn_id)
+{
+ return mgmt_be_send_cfgapply_req(adapter, txn_id);
+}
+
+/*
+ * This function maps a YANG dtata Xpath to one or more
+ * Backend Clients that should be contacted for various purposes.
+ */
+int mgmt_be_get_subscr_info_for_xpath(
+ const char *xpath, struct mgmt_be_client_subscr_info *subscr_info)
+{
+ int indx, match, max_match = 0, num_reg;
+ enum mgmt_be_client_id id;
+ struct mgmt_be_client_subscr_info
+ *reg_maps[array_size(mgmt_xpath_map)] = {0};
+ bool root_xp = false;
+
+ if (!subscr_info)
+ return -1;
+
+ num_reg = 0;
+ memset(subscr_info, 0, sizeof(*subscr_info));
+
+ if (strlen(xpath) <= 2 && xpath[0] == '/'
+ && (!xpath[1] || xpath[1] == '*')) {
+ root_xp = true;
+ }
+
+ MGMTD_BE_ADAPTER_DBG("XPATH: %s", xpath);
+ for (indx = 0; indx < mgmt_num_xpath_maps; indx++) {
+ /*
+ * For Xpaths: '/' and '/ *' all xpath maps should match
+ * the given xpath.
+ */
+ if (!root_xp) {
+ match = mgmt_be_eval_regexp_match(
+ mgmt_xpath_map[indx].xpath_regexp, xpath);
+
+ if (!match || match < max_match)
+ continue;
+
+ if (match > max_match) {
+ num_reg = 0;
+ max_match = match;
+ }
+ }
+
+ reg_maps[num_reg] = &mgmt_xpath_map[indx].be_subscrs;
+ num_reg++;
+ }
+
+ for (indx = 0; indx < num_reg; indx++) {
+ FOREACH_MGMTD_BE_CLIENT_ID (id) {
+ if (reg_maps[indx]->xpath_subscr[id].subscribed) {
+ MGMTD_BE_ADAPTER_DBG(
+ "Cient: %s",
+ mgmt_be_client_id2name(id));
+ memcpy(&subscr_info->xpath_subscr[id],
+ &reg_maps[indx]->xpath_subscr[id],
+ sizeof(subscr_info->xpath_subscr[id]));
+ }
+ }
+ }
+
+ return 0;
+}
+
+void mgmt_be_adapter_status_write(struct vty *vty)
+{
+ struct mgmt_be_client_adapter *adapter;
+
+ vty_out(vty, "MGMTD Backend Adapters\n");
+
+ FOREACH_ADAPTER_IN_LIST (adapter) {
+ vty_out(vty, " Client: \t\t\t%s\n", adapter->name);
+ vty_out(vty, " Conn-FD: \t\t\t%d\n", adapter->conn_fd);
+ vty_out(vty, " Client-Id: \t\t\t%d\n", adapter->id);
+ vty_out(vty, " Ref-Count: \t\t\t%u\n", adapter->refcount);
+ vty_out(vty, " Msg-Recvd: \t\t\t%" PRIu64 "\n",
+ adapter->mstate.nrxm);
+ vty_out(vty, " Bytes-Recvd: \t\t%" PRIu64 "\n",
+ adapter->mstate.nrxb);
+ vty_out(vty, " Msg-Sent: \t\t\t%" PRIu64 "\n",
+ adapter->mstate.ntxm);
+ vty_out(vty, " Bytes-Sent: \t\t%" PRIu64 "\n",
+ adapter->mstate.ntxb);
+ }
+ vty_out(vty, " Total: %d\n",
+ (int)mgmt_be_adapters_count(&mgmt_be_adapters));
+}
+
+void mgmt_be_xpath_register_write(struct vty *vty)
+{
+ int indx;
+ enum mgmt_be_client_id id;
+ struct mgmt_be_client_adapter *adapter;
+
+ vty_out(vty, "MGMTD Backend XPath Registry\n");
+
+ for (indx = 0; indx < mgmt_num_xpath_maps; indx++) {
+ vty_out(vty, " - XPATH: '%s'\n",
+ mgmt_xpath_map[indx].xpath_regexp);
+ FOREACH_MGMTD_BE_CLIENT_ID (id) {
+ if (mgmt_xpath_map[indx]
+ .be_subscrs.xpath_subscr[id]
+ .subscribed) {
+ vty_out(vty,
+ " -- Client: '%s' \t Validate:%s, Notify:%s, Own:%s\n",
+ mgmt_be_client_id2name(id),
+ mgmt_xpath_map[indx]
+ .be_subscrs
+ .xpath_subscr[id]
+ .validate_config
+ ? "T"
+ : "F",
+ mgmt_xpath_map[indx]
+ .be_subscrs
+ .xpath_subscr[id]
+ .notify_config
+ ? "T"
+ : "F",
+ mgmt_xpath_map[indx]
+ .be_subscrs
+ .xpath_subscr[id]
+ .own_oper_data
+ ? "T"
+ : "F");
+ adapter = mgmt_be_get_adapter_by_id(id);
+ if (adapter) {
+ vty_out(vty, " -- Adapter: %p\n",
+ adapter);
+ }
+ }
+ }
+ }
+
+ vty_out(vty, "Total XPath Registries: %u\n", mgmt_num_xpath_maps);
+}
+
+void mgmt_be_xpath_subscr_info_write(struct vty *vty, const char *xpath)
+{
+ struct mgmt_be_client_subscr_info subscr;
+ enum mgmt_be_client_id id;
+ struct mgmt_be_client_adapter *adapter;
+
+ if (mgmt_be_get_subscr_info_for_xpath(xpath, &subscr) != 0) {
+ vty_out(vty, "ERROR: Failed to get subscriber for '%s'\n",
+ xpath);
+ return;
+ }
+
+ vty_out(vty, "XPath: '%s'\n", xpath);
+ FOREACH_MGMTD_BE_CLIENT_ID (id) {
+ if (subscr.xpath_subscr[id].subscribed) {
+ vty_out(vty,
+ " -- Client: '%s' \t Validate:%s, Notify:%s, Own:%s\n",
+ mgmt_be_client_id2name(id),
+ subscr.xpath_subscr[id].validate_config ? "T"
+ : "F",
+ subscr.xpath_subscr[id].notify_config ? "T"
+ : "F",
+ subscr.xpath_subscr[id].own_oper_data ? "T"
+ : "F");
+ adapter = mgmt_be_get_adapter_by_id(id);
+ if (adapter)
+ vty_out(vty, " -- Adapter: %p\n", adapter);
+ }
+ }
+}
diff --git a/mgmtd/mgmt_be_adapter.h b/mgmtd/mgmt_be_adapter.h
new file mode 100644
index 0000000000..88d54a7842
--- /dev/null
+++ b/mgmtd/mgmt_be_adapter.h
@@ -0,0 +1,219 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * MGMTD Backend Client Connection Adapter
+ *
+ * Copyright (C) 2021 Vmware, Inc.
+ * Pushpasis Sarkar <spushpasis@vmware.com>
+ */
+
+#ifndef _FRR_MGMTD_BE_ADAPTER_H_
+#define _FRR_MGMTD_BE_ADAPTER_H_
+
+#include "mgmt_be_client.h"
+#include "mgmt_msg.h"
+#include "mgmtd/mgmt_defines.h"
+#include "mgmtd/mgmt_ds.h"
+
+#define MGMTD_BE_CONN_INIT_DELAY_MSEC 50
+
+#define MGMTD_FIND_ADAPTER_BY_INDEX(adapter_index) \
+ mgmt_adaptr_ref[adapter_index]
+
+enum mgmt_be_req_type {
+ MGMTD_BE_REQ_NONE = 0,
+ MGMTD_BE_REQ_CFG_VALIDATE,
+ MGMTD_BE_REQ_CFG_APPLY,
+ MGMTD_BE_REQ_DATA_GET_ELEM,
+ MGMTD_BE_REQ_DATA_GET_NEXT
+};
+
+struct mgmt_be_cfgreq {
+ Mgmtd__YangCfgDataReq **cfgdata_reqs;
+ size_t num_reqs;
+};
+
+struct mgmt_be_datareq {
+ Mgmtd__YangGetDataReq **getdata_reqs;
+ size_t num_reqs;
+};
+
+PREDECL_LIST(mgmt_be_adapters);
+PREDECL_LIST(mgmt_txn_badapters);
+
+struct mgmt_be_client_adapter {
+ enum mgmt_be_client_id id;
+ int conn_fd;
+ union sockunion conn_su;
+ struct event *conn_init_ev;
+ struct event *conn_read_ev;
+ struct event *conn_write_ev;
+ struct event *conn_writes_on;
+ struct event *proc_msg_ev;
+ uint32_t flags;
+ char name[MGMTD_CLIENT_NAME_MAX_LEN];
+ uint8_t num_xpath_reg;
+ char xpath_reg[MGMTD_MAX_NUM_XPATH_REG][MGMTD_MAX_XPATH_LEN];
+
+ /* IO streams for read and write */
+ struct mgmt_msg_state mstate;
+
+ int refcount;
+
+ /*
+ * List of config items that should be sent to the
+ * backend during re/connect. This is temporarily
+ * created and then freed-up as soon as the initial
+ * config items has been applied onto the backend.
+ */
+ struct nb_config_cbs cfg_chgs;
+
+ struct mgmt_be_adapters_item list_linkage;
+ struct mgmt_txn_badapters_item txn_list_linkage;
+};
+
+#define MGMTD_BE_ADAPTER_FLAGS_WRITES_OFF (1U << 0)
+#define MGMTD_BE_ADAPTER_FLAGS_CFG_SYNCED (1U << 1)
+
+DECLARE_LIST(mgmt_be_adapters, struct mgmt_be_client_adapter, list_linkage);
+DECLARE_LIST(mgmt_txn_badapters, struct mgmt_be_client_adapter,
+ txn_list_linkage);
+
+union mgmt_be_xpath_subscr_info {
+ uint8_t subscribed;
+ struct {
+ uint8_t validate_config : 1;
+ uint8_t notify_config : 1;
+ uint8_t own_oper_data : 1;
+ };
+};
+
+struct mgmt_be_client_subscr_info {
+ union mgmt_be_xpath_subscr_info xpath_subscr[MGMTD_BE_CLIENT_ID_MAX];
+};
+
+/* Initialise backend adapter module. */
+extern int mgmt_be_adapter_init(struct event_loop *tm);
+
+/* Destroy the backend adapter module. */
+extern void mgmt_be_adapter_destroy(void);
+
+/* Acquire lock for backend adapter. */
+extern void mgmt_be_adapter_lock(struct mgmt_be_client_adapter *adapter);
+
+/* Remove lock from backend adapter. */
+extern void mgmt_be_adapter_unlock(struct mgmt_be_client_adapter **adapter);
+
+/* Create backend adapter. */
+extern struct mgmt_be_client_adapter *
+mgmt_be_create_adapter(int conn_fd, union sockunion *su);
+
+/* Fetch backend adapter given an adapter name. */
+extern struct mgmt_be_client_adapter *
+mgmt_be_get_adapter_by_name(const char *name);
+
+/* Fetch backend adapter given an client ID. */
+extern struct mgmt_be_client_adapter *
+mgmt_be_get_adapter_by_id(enum mgmt_be_client_id id);
+
+/* Fetch backend adapter config. */
+extern int
+mgmt_be_get_adapter_config(struct mgmt_be_client_adapter *adapter,
+ struct mgmt_ds_ctx *ds_ctx,
+ struct nb_config_cbs **cfg_chgs);
+
+/* Create a transaction. */
+extern int mgmt_be_create_txn(struct mgmt_be_client_adapter *adapter,
+ uint64_t txn_id);
+
+/* Destroy a transaction. */
+extern int mgmt_be_destroy_txn(struct mgmt_be_client_adapter *adapter,
+ uint64_t txn_id);
+
+/*
+ * Send config data create request to backend client.
+ *
+ * adaptr
+ * Backend adapter information.
+ *
+ * txn_id
+ * Unique transaction identifier.
+ *
+ * batch_id
+ * Request batch ID.
+ *
+ * cfg_req
+ * Config data request.
+ *
+ * end_of_data
+ * TRUE if the data from last batch, FALSE otherwise.
+ *
+ * Returns:
+ * 0 on success, -1 on failure.
+ */
+extern int mgmt_be_send_cfg_data_create_req(
+ struct mgmt_be_client_adapter *adapter, uint64_t txn_id,
+ uint64_t batch_id, struct mgmt_be_cfgreq *cfg_req, bool end_of_data);
+
+/*
+ * Send config validate request to backend client.
+ *
+ * adaptr
+ * Backend adapter information.
+ *
+ * txn_id
+ * Unique transaction identifier.
+ *
+ * batch_ids
+ * List of request batch IDs.
+ *
+ * num_batch_ids
+ * Number of batch ids.
+ *
+ * Returns:
+ * 0 on success, -1 on failure.
+ */
+extern int
+mgmt_be_send_cfg_validate_req(struct mgmt_be_client_adapter *adapter,
+ uint64_t txn_id, uint64_t batch_ids[],
+ size_t num_batch_ids);
+
+/*
+ * Send config apply request to backend client.
+ *
+ * adaptr
+ * Backend adapter information.
+ *
+ * txn_id
+ * Unique transaction identifier.
+ *
+ * Returns:
+ * 0 on success, -1 on failure.
+ */
+extern int
+mgmt_be_send_cfg_apply_req(struct mgmt_be_client_adapter *adapter,
+ uint64_t txn_id);
+
+/*
+ * Dump backend adapter status to vty.
+ */
+extern void mgmt_be_adapter_status_write(struct vty *vty);
+
+/*
+ * Dump xpath registry for each backend client to vty.
+ */
+extern void mgmt_be_xpath_register_write(struct vty *vty);
+
+/*
+ * Maps a YANG dtata Xpath to one or more
+ * backend clients that should be contacted for various purposes.
+ */
+extern int mgmt_be_get_subscr_info_for_xpath(
+ const char *xpath, struct mgmt_be_client_subscr_info *subscr_info);
+
+/*
+ * Dump backend client information for a given xpath to vty.
+ */
+extern void mgmt_be_xpath_subscr_info_write(struct vty *vty,
+ const char *xpath);
+
+#endif /* _FRR_MGMTD_BE_ADAPTER_H_ */
diff --git a/mgmtd/mgmt_be_server.c b/mgmtd/mgmt_be_server.c
new file mode 100644
index 0000000000..0fa7ddd6d6
--- /dev/null
+++ b/mgmtd/mgmt_be_server.c
@@ -0,0 +1,160 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * MGMTD Backend Server
+ *
+ * Copyright (C) 2021 Vmware, Inc.
+ * Pushpasis Sarkar <spushpasis@vmware.com>
+ */
+
+#include <zebra.h>
+#include "network.h"
+#include "libfrr.h"
+#include "mgmtd/mgmt.h"
+#include "mgmtd/mgmt_be_server.h"
+#include "mgmtd/mgmt_be_adapter.h"
+
+#ifdef REDIRECT_DEBUG_TO_STDERR
+#define MGMTD_BE_SRVR_DBG(fmt, ...) \
+ fprintf(stderr, "%s: " fmt "\n", __func__, ##__VA_ARGS__)
+#define MGMTD_BE_SRVR_ERR(fmt, ...) \
+ fprintf(stderr, "%s: ERROR, " fmt "\n", __func__, ##__VA_ARGS__)
+#else /* REDIRECT_DEBUG_TO_STDERR */
+#define MGMTD_BE_SRVR_DBG(fmt, ...) \
+ do { \
+ if (mgmt_debug_be) \
+ zlog_debug("%s: " fmt, __func__, ##__VA_ARGS__); \
+ } while (0)
+#define MGMTD_BE_SRVR_ERR(fmt, ...) \
+ zlog_err("%s: ERROR: " fmt, __func__, ##__VA_ARGS__)
+#endif /* REDIRECT_DEBUG_TO_STDERR */
+
+static int mgmt_be_listen_fd = -1;
+static struct event_loop *mgmt_be_listen_tm;
+static struct event *mgmt_be_listen_ev;
+static void mgmt_be_server_register_event(enum mgmt_be_event event);
+
+static void mgmt_be_conn_accept(struct event *thread)
+{
+ int client_conn_fd;
+ union sockunion su;
+
+ if (mgmt_be_listen_fd < 0)
+ return;
+
+ /* We continue hearing server listen socket. */
+ mgmt_be_server_register_event(MGMTD_BE_SERVER);
+
+ memset(&su, 0, sizeof(union sockunion));
+
+ /* We can handle IPv4 or IPv6 socket. */
+ client_conn_fd = sockunion_accept(mgmt_be_listen_fd, &su);
+ if (client_conn_fd < 0) {
+ MGMTD_BE_SRVR_ERR(
+ "Failed to accept MGMTD Backend client connection : %s",
+ safe_strerror(errno));
+ return;
+ }
+ set_nonblocking(client_conn_fd);
+ set_cloexec(client_conn_fd);
+
+ MGMTD_BE_SRVR_DBG("Got a new MGMTD Backend connection");
+
+ mgmt_be_create_adapter(client_conn_fd, &su);
+}
+
+static void mgmt_be_server_register_event(enum mgmt_be_event event)
+{
+ if (event == MGMTD_BE_SERVER) {
+ event_add_read(mgmt_be_listen_tm, mgmt_be_conn_accept,
+ NULL, mgmt_be_listen_fd,
+ &mgmt_be_listen_ev);
+ assert(mgmt_be_listen_ev);
+ } else {
+ assert(!"mgmt_be_server_post_event() called incorrectly");
+ }
+}
+
+static void mgmt_be_server_start(const char *hostname)
+{
+ int ret;
+ int sock;
+ struct sockaddr_un addr;
+ mode_t old_mask;
+
+ /* Set umask */
+ old_mask = umask(0077);
+
+ sock = socket(AF_UNIX, SOCK_STREAM, PF_UNSPEC);
+ if (sock < 0) {
+ MGMTD_BE_SRVR_ERR("Failed to create server socket: %s",
+ safe_strerror(errno));
+ goto mgmt_be_server_start_failed;
+ }
+
+ addr.sun_family = AF_UNIX,
+ strlcpy(addr.sun_path, MGMTD_BE_SERVER_PATH, sizeof(addr.sun_path));
+ unlink(addr.sun_path);
+ ret = bind(sock, (struct sockaddr *)&addr, sizeof(addr));
+ if (ret < 0) {
+ MGMTD_BE_SRVR_ERR(
+ "Failed to bind server socket to '%s'. Err: %s",
+ addr.sun_path, safe_strerror(errno));
+ goto mgmt_be_server_start_failed;
+ }
+
+ ret = listen(sock, MGMTD_BE_MAX_CONN);
+ if (ret < 0) {
+ MGMTD_BE_SRVR_ERR("Failed to listen on server socket: %s",
+ safe_strerror(errno));
+ goto mgmt_be_server_start_failed;
+ }
+
+ /* Restore umask */
+ umask(old_mask);
+
+ mgmt_be_listen_fd = sock;
+ mgmt_be_server_register_event(MGMTD_BE_SERVER);
+
+ MGMTD_BE_SRVR_DBG("Started MGMTD Backend Server!");
+ return;
+
+mgmt_be_server_start_failed:
+ if (sock)
+ close(sock);
+
+ mgmt_be_listen_fd = -1;
+ exit(-1);
+}
+
+int mgmt_be_server_init(struct event_loop *master)
+{
+ if (mgmt_be_listen_tm) {
+ MGMTD_BE_SRVR_DBG("MGMTD Backend Server already running!");
+ return 0;
+ }
+
+ mgmt_be_listen_tm = master;
+
+ mgmt_be_server_start("localhost");
+
+ return 0;
+}
+
+void mgmt_be_server_destroy(void)
+{
+ if (mgmt_be_listen_tm) {
+ MGMTD_BE_SRVR_DBG("Closing MGMTD Backend Server!");
+
+ if (mgmt_be_listen_ev) {
+ EVENT_OFF(mgmt_be_listen_ev);
+ mgmt_be_listen_ev = NULL;
+ }
+
+ if (mgmt_be_listen_fd >= 0) {
+ close(mgmt_be_listen_fd);
+ mgmt_be_listen_fd = -1;
+ }
+
+ mgmt_be_listen_tm = NULL;
+ }
+}
diff --git a/mgmtd/mgmt_be_server.h b/mgmtd/mgmt_be_server.h
new file mode 100644
index 0000000000..63731a0ef5
--- /dev/null
+++ b/mgmtd/mgmt_be_server.h
@@ -0,0 +1,20 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * MGMTD Backend Server
+ *
+ * Copyright (C) 2021 Vmware, Inc.
+ * Pushpasis Sarkar
+ */
+
+#ifndef _FRR_MGMTD_BE_SERVER_H_
+#define _FRR_MGMTD_BE_SERVER_H_
+
+#define MGMTD_BE_MAX_CONN 32
+
+/* Initialise backend server */
+extern int mgmt_be_server_init(struct event_loop *master);
+
+/* Destroy backend server */
+extern void mgmt_be_server_destroy(void);
+
+#endif /* _FRR_MGMTD_BE_SERVER_H_ */
diff --git a/mgmtd/mgmt_defines.h b/mgmtd/mgmt_defines.h
new file mode 100644
index 0000000000..ee2f376f48
--- /dev/null
+++ b/mgmtd/mgmt_defines.h
@@ -0,0 +1,60 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * MGMTD public defines.
+ *
+ * Copyright (C) 2021 Vmware, Inc.
+ * Pushpasis Sarkar <spushpasis@vmware.com>
+ */
+
+#ifndef _FRR_MGMTD_DEFINES_H
+#define _FRR_MGMTD_DEFINES_H
+
+#include "yang.h"
+
+#define MGMTD_CLIENT_NAME_MAX_LEN 32
+
+#define MGMTD_MAX_XPATH_LEN XPATH_MAXLEN
+
+#define MGMTD_MAX_YANG_VALUE_LEN YANG_VALUE_MAXLEN
+
+#define MGMTD_MAX_NUM_XPATH_REG 128
+
+#define MGMTD_MAX_NUM_DATA_REQ_IN_BATCH 32
+#define MGMTD_MAX_NUM_DATA_REPLY_IN_BATCH 8
+
+enum mgmt_result {
+ MGMTD_SUCCESS = 0,
+ MGMTD_INVALID_PARAM,
+ MGMTD_INTERNAL_ERROR,
+ MGMTD_NO_CFG_CHANGES,
+ MGMTD_DS_LOCK_FAILED,
+ MGMTD_DS_UNLOCK_FAILED,
+ MGMTD_UNKNOWN_FAILURE
+};
+
+enum mgmt_fe_event {
+ MGMTD_FE_SERVER = 1,
+ MGMTD_FE_CONN_READ,
+ MGMTD_FE_CONN_WRITE,
+ MGMTD_FE_CONN_WRITES_ON,
+ MGMTD_FE_PROC_MSG
+};
+
+enum mgmt_be_event {
+ MGMTD_BE_SERVER = 1,
+ MGMTD_BE_CONN_INIT,
+ MGMTD_BE_CONN_READ,
+ MGMTD_BE_CONN_WRITE,
+ MGMTD_BE_CONN_WRITES_ON,
+ MGMTD_BE_PROC_MSG,
+ MGMTD_BE_SCHED_CFG_PREPARE,
+ MGMTD_BE_RESCHED_CFG_PREPARE,
+ MGMTD_BE_SCHED_CFG_APPLY,
+ MGMTD_BE_RESCHED_CFG_APPLY,
+};
+
+#define MGMTD_TXN_ID_NONE 0
+
+#define MGMTD_TXN_BATCH_ID_NONE 0
+
+#endif /* _FRR_MGMTD_DEFINES_H */
diff --git a/mgmtd/mgmt_ds.c b/mgmtd/mgmt_ds.c
new file mode 100644
index 0000000000..10b3cecb92
--- /dev/null
+++ b/mgmtd/mgmt_ds.c
@@ -0,0 +1,645 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * MGMTD Datastores
+ *
+ * Copyright (C) 2021 Vmware, Inc.
+ * Pushpasis Sarkar <spushpasis@vmware.com>
+ */
+
+#include <zebra.h>
+#include "md5.h"
+#include "mgmtd/mgmt.h"
+#include "mgmtd/mgmt_memory.h"
+#include "mgmtd/mgmt_ds.h"
+#include "mgmtd/mgmt_history.h"
+#include "mgmtd/mgmt_txn.h"
+#include "libyang/libyang.h"
+
+#ifdef REDIRECT_DEBUG_TO_STDERR
+#define MGMTD_DS_DBG(fmt, ...) \
+ fprintf(stderr, "%s: " fmt "\n", __func__, ##__VA_ARGS__)
+#define MGMTD_DS_ERR(fmt, ...) \
+ fprintf(stderr, "%s: ERROR, " fmt "\n", __func__, ##__VA_ARGS__)
+#else /* REDIRECT_DEBUG_TO_STDERR */
+#define MGMTD_DS_DBG(fmt, ...) \
+ do { \
+ if (mgmt_debug_ds) \
+ zlog_err("%s: " fmt, __func__, ##__VA_ARGS__); \
+ } while (0)
+#define MGMTD_DS_ERR(fmt, ...) \
+ zlog_err("%s: ERROR: " fmt, __func__, ##__VA_ARGS__)
+#endif /* REDIRECT_DEBUG_TO_STDERR */
+
+struct mgmt_ds_ctx {
+ Mgmtd__DatastoreId ds_id;
+ int lock; /* 0 unlocked, >0 read locked < write locked */
+
+ bool config_ds;
+
+ union {
+ struct nb_config *cfg_root;
+ struct lyd_node *dnode_root;
+ } root;
+};
+
+const char *mgmt_ds_names[MGMTD_DS_MAX_ID + 1] = {
+ MGMTD_DS_NAME_NONE, /* MGMTD_DS_NONE */
+ MGMTD_DS_NAME_RUNNING, /* MGMTD_DS_RUNNING */
+ MGMTD_DS_NAME_CANDIDATE, /* MGMTD_DS_CANDIDATE */
+ MGMTD_DS_NAME_OPERATIONAL, /* MGMTD_DS_OPERATIONAL */
+ "Unknown/Invalid", /* MGMTD_DS_ID_MAX */
+};
+
+static struct mgmt_master *mgmt_ds_mm;
+static struct mgmt_ds_ctx running, candidate, oper;
+
+/* Dump the data tree of the specified format in the file pointed by the path */
+static int mgmt_ds_dump_in_memory(struct mgmt_ds_ctx *ds_ctx,
+ const char *base_xpath, LYD_FORMAT format,
+ struct ly_out *out)
+{
+ struct lyd_node *root;
+ uint32_t options = 0;
+
+ if (base_xpath[0] == '\0')
+ root = ds_ctx->config_ds ? ds_ctx->root.cfg_root->dnode
+ : ds_ctx->root.dnode_root;
+ else
+ root = yang_dnode_get(ds_ctx->config_ds
+ ? ds_ctx->root.cfg_root->dnode
+ : ds_ctx->root.dnode_root,
+ base_xpath);
+ if (!root)
+ return -1;
+
+ options = ds_ctx->config_ds ? LYD_PRINT_WD_TRIM :
+ LYD_PRINT_WD_EXPLICIT;
+
+ if (base_xpath[0] == '\0')
+ lyd_print_all(out, root, format, options);
+ else
+ lyd_print_tree(out, root, format, options);
+
+ return 0;
+}
+
+static int mgmt_ds_replace_dst_with_src_ds(struct mgmt_ds_ctx *src,
+ struct mgmt_ds_ctx *dst)
+{
+ struct lyd_node *dst_dnode, *src_dnode;
+
+ if (!src || !dst)
+ return -1;
+ MGMTD_DS_DBG("Replacing %d with %d", dst->ds_id, src->ds_id);
+
+ src_dnode = src->config_ds ? src->root.cfg_root->dnode
+ : dst->root.dnode_root;
+ dst_dnode = dst->config_ds ? dst->root.cfg_root->dnode
+ : dst->root.dnode_root;
+
+ if (dst_dnode)
+ yang_dnode_free(dst_dnode);
+
+ /* Not using nb_config_replace as the oper ds does not contain nb_config
+ */
+ dst_dnode = yang_dnode_dup(src_dnode);
+ if (dst->config_ds)
+ dst->root.cfg_root->dnode = dst_dnode;
+ else
+ dst->root.dnode_root = dst_dnode;
+
+ if (src->ds_id == MGMTD_DS_CANDIDATE) {
+ /*
+ * Drop the changes in scratch-buffer.
+ */
+ MGMTD_DS_DBG("Emptying Candidate Scratch buffer!");
+ nb_config_diff_del_changes(&src->root.cfg_root->cfg_chgs);
+ }
+
+ /* TODO: Update the versions if nb_config present */
+
+ return 0;
+}
+
+static int mgmt_ds_merge_src_with_dst_ds(struct mgmt_ds_ctx *src,
+ struct mgmt_ds_ctx *dst)
+{
+ int ret;
+ struct lyd_node **dst_dnode, *src_dnode;
+
+ if (!src || !dst)
+ return -1;
+
+ MGMTD_DS_DBG("Merging DS %d with %d", dst->ds_id, src->ds_id);
+
+ src_dnode = src->config_ds ? src->root.cfg_root->dnode
+ : dst->root.dnode_root;
+ dst_dnode = dst->config_ds ? &dst->root.cfg_root->dnode
+ : &dst->root.dnode_root;
+ ret = lyd_merge_siblings(dst_dnode, src_dnode, 0);
+ if (ret != 0) {
+ MGMTD_DS_ERR("lyd_merge() failed with err %d", ret);
+ return ret;
+ }
+
+ if (src->ds_id == MGMTD_DS_CANDIDATE) {
+ /*
+ * Drop the changes in scratch-buffer.
+ */
+ MGMTD_DS_DBG("Emptying Candidate Scratch buffer!");
+ nb_config_diff_del_changes(&src->root.cfg_root->cfg_chgs);
+ }
+
+ return 0;
+}
+
+static int mgmt_ds_load_cfg_from_file(const char *filepath,
+ struct lyd_node **dnode)
+{
+ LY_ERR ret;
+
+ *dnode = NULL;
+ ret = lyd_parse_data_path(ly_native_ctx, filepath, LYD_JSON,
+ LYD_PARSE_STRICT, 0, dnode);
+
+ if (ret != LY_SUCCESS) {
+ if (*dnode)
+ yang_dnode_free(*dnode);
+ return -1;
+ }
+
+ return 0;
+}
+
+void mgmt_ds_reset_candidate(void)
+{
+ struct lyd_node *dnode = mm->candidate_ds->root.cfg_root->dnode;
+ if (dnode)
+ yang_dnode_free(dnode);
+
+ dnode = yang_dnode_new(ly_native_ctx, true);
+ mm->candidate_ds->root.cfg_root->dnode = dnode;
+}
+
+
+int mgmt_ds_init(struct mgmt_master *mm)
+{
+ if (mgmt_ds_mm || mm->running_ds || mm->candidate_ds || mm->oper_ds)
+ assert(!"MGMTD: Call ds_init only once!");
+
+ /* Use Running DS from NB module??? */
+ if (!running_config)
+ assert(!"MGMTD: Call ds_init after frr_init only!");
+
+ running.root.cfg_root = running_config;
+ running.config_ds = true;
+ running.ds_id = MGMTD_DS_RUNNING;
+
+ candidate.root.cfg_root = nb_config_dup(running.root.cfg_root);
+ candidate.config_ds = true;
+ candidate.ds_id = MGMTD_DS_CANDIDATE;
+
+ /*
+ * Redirect lib/vty candidate-config datastore to the global candidate
+ * config Ds on the MGMTD process.
+ */
+ vty_mgmt_candidate_config = candidate.root.cfg_root;
+
+ oper.root.dnode_root = yang_dnode_new(ly_native_ctx, true);
+ oper.config_ds = false;
+ oper.ds_id = MGMTD_DS_OPERATIONAL;
+
+ mm->running_ds = &running;
+ mm->candidate_ds = &candidate;
+ mm->oper_ds = &oper;
+ mgmt_ds_mm = mm;
+
+ return 0;
+}
+
+void mgmt_ds_destroy(void)
+{
+ /*
+ * TODO: Free the datastores.
+ */
+}
+
+struct mgmt_ds_ctx *mgmt_ds_get_ctx_by_id(struct mgmt_master *mm,
+ Mgmtd__DatastoreId ds_id)
+{
+ switch (ds_id) {
+ case MGMTD_DS_CANDIDATE:
+ return (mm->candidate_ds);
+ case MGMTD_DS_RUNNING:
+ return (mm->running_ds);
+ case MGMTD_DS_OPERATIONAL:
+ return (mm->oper_ds);
+ case MGMTD_DS_NONE:
+ case MGMTD__DATASTORE_ID__STARTUP_DS:
+ case _MGMTD__DATASTORE_ID_IS_INT_SIZE:
+ return 0;
+ }
+
+ return 0;
+}
+
+bool mgmt_ds_is_config(struct mgmt_ds_ctx *ds_ctx)
+{
+ if (!ds_ctx)
+ return false;
+
+ return ds_ctx->config_ds;
+}
+
+int mgmt_ds_read_lock(struct mgmt_ds_ctx *ds_ctx)
+{
+ if (!ds_ctx)
+ return EINVAL;
+ if (ds_ctx->lock < 0)
+ return EBUSY;
+ ++ds_ctx->lock;
+ return 0;
+}
+
+int mgmt_ds_write_lock(struct mgmt_ds_ctx *ds_ctx)
+{
+ if (!ds_ctx)
+ return EINVAL;
+ if (ds_ctx->lock != 0)
+ return EBUSY;
+ ds_ctx->lock = -1;
+ return 0;
+}
+
+int mgmt_ds_unlock(struct mgmt_ds_ctx *ds_ctx)
+{
+ if (!ds_ctx)
+ return EINVAL;
+ if (ds_ctx->lock > 0)
+ --ds_ctx->lock;
+ else if (ds_ctx->lock < 0) {
+ assert(ds_ctx->lock == -1);
+ ds_ctx->lock = 0;
+ } else {
+ assert(ds_ctx->lock != 0);
+ return EINVAL;
+ }
+ return 0;
+}
+
+int mgmt_ds_copy_dss(struct mgmt_ds_ctx *src_ds_ctx,
+ struct mgmt_ds_ctx *dst_ds_ctx, bool updt_cmt_rec)
+{
+ if (mgmt_ds_replace_dst_with_src_ds(src_ds_ctx, dst_ds_ctx) != 0)
+ return -1;
+
+ if (updt_cmt_rec && dst_ds_ctx->ds_id == MGMTD_DS_RUNNING)
+ mgmt_history_new_record(dst_ds_ctx);
+
+ return 0;
+}
+
+int mgmt_ds_dump_ds_to_file(char *file_name, struct mgmt_ds_ctx *ds_ctx)
+{
+ struct ly_out *out;
+ int ret = 0;
+
+ if (ly_out_new_filepath(file_name, &out) == LY_SUCCESS) {
+ ret = mgmt_ds_dump_in_memory(ds_ctx, "", LYD_JSON, out);
+ ly_out_free(out, NULL, 0);
+ }
+
+ return ret;
+}
+
+struct nb_config *mgmt_ds_get_nb_config(struct mgmt_ds_ctx *ds_ctx)
+{
+ if (!ds_ctx)
+ return NULL;
+
+ return ds_ctx->config_ds ? ds_ctx->root.cfg_root : NULL;
+}
+
+static int mgmt_walk_ds_nodes(
+ struct mgmt_ds_ctx *ds_ctx, char *base_xpath,
+ struct lyd_node *base_dnode,
+ void (*mgmt_ds_node_iter_fn)(struct mgmt_ds_ctx *ds_ctx, char *xpath,
+ struct lyd_node *node,
+ struct nb_node *nb_node, void *ctx),
+ void *ctx, char *xpaths[], int *num_nodes, bool childs_as_well,
+ bool alloc_xp_copy)
+{
+ uint32_t indx;
+ char *xpath, *xpath_buf, *iter_xp;
+ int ret, num_left = 0, num_found = 0;
+ struct lyd_node *dnode;
+ struct nb_node *nbnode;
+ bool alloc_xp = false;
+
+ if (xpaths)
+ assert(num_nodes);
+
+ if (num_nodes && !*num_nodes)
+ return 0;
+
+ if (num_nodes) {
+ num_left = *num_nodes;
+ MGMTD_DS_DBG(" -- START: num_left:%d", num_left);
+ *num_nodes = 0;
+ }
+
+ MGMTD_DS_DBG(" -- START: Base: %s", base_xpath);
+
+ if (!base_dnode)
+ base_dnode = yang_dnode_get(
+ ds_ctx->config_ds ? ds_ctx->root.cfg_root->dnode
+ : ds_ctx->root.dnode_root,
+ base_xpath);
+ if (!base_dnode)
+ return -1;
+
+ if (mgmt_ds_node_iter_fn) {
+ /*
+ * In case the caller is interested in getting a copy
+ * of the xpath for themselves (by setting
+ * 'alloc_xp_copy' to 'true') we make a copy for the
+ * caller and pass it. Else we pass the original xpath
+ * buffer.
+ *
+ * NOTE: In such case caller will have to take care of
+ * the copy later.
+ */
+ iter_xp = alloc_xp_copy ? strdup(base_xpath) : base_xpath;
+
+ nbnode = (struct nb_node *)base_dnode->schema->priv;
+ (*mgmt_ds_node_iter_fn)(ds_ctx, iter_xp, base_dnode, nbnode,
+ ctx);
+ }
+
+ if (num_nodes) {
+ (*num_nodes)++;
+ num_left--;
+ }
+
+ /*
+ * If the base_xpath points to a leaf node, or we don't need to
+ * visit any children we can skip the tree walk.
+ */
+ if (!childs_as_well || base_dnode->schema->nodetype & LYD_NODE_TERM)
+ return 0;
+
+ indx = 0;
+ LY_LIST_FOR (lyd_child(base_dnode), dnode) {
+ assert(dnode->schema && dnode->schema->priv);
+
+ xpath = NULL;
+ if (xpaths) {
+ if (!xpaths[*num_nodes]) {
+ alloc_xp = true;
+ xpaths[*num_nodes] =
+ (char *)calloc(1, MGMTD_MAX_XPATH_LEN);
+ }
+ xpath = lyd_path(dnode, LYD_PATH_STD,
+ xpaths[*num_nodes],
+ MGMTD_MAX_XPATH_LEN);
+ } else {
+ alloc_xp = true;
+ xpath_buf = (char *)calloc(1, MGMTD_MAX_XPATH_LEN);
+ (void) lyd_path(dnode, LYD_PATH_STD, xpath_buf,
+ MGMTD_MAX_XPATH_LEN);
+ xpath = xpath_buf;
+ }
+
+ assert(xpath);
+ MGMTD_DS_DBG(" -- XPATH: %s", xpath);
+
+ if (num_nodes)
+ num_found = num_left;
+
+ ret = mgmt_walk_ds_nodes(ds_ctx, xpath, dnode,
+ mgmt_ds_node_iter_fn, ctx,
+ xpaths ? &xpaths[*num_nodes] : NULL,
+ num_nodes ? &num_found : NULL,
+ childs_as_well, alloc_xp_copy);
+
+ if (num_nodes) {
+ num_left -= num_found;
+ (*num_nodes) += num_found;
+ }
+
+ if (alloc_xp)
+ free(xpath);
+
+ if (ret != 0)
+ break;
+
+ indx++;
+ }
+
+
+ if (num_nodes) {
+ MGMTD_DS_DBG(" -- END: *num_nodes:%d, num_left:%d", *num_nodes,
+ num_left);
+ }
+
+ return 0;
+}
+
+int mgmt_ds_lookup_data_nodes(struct mgmt_ds_ctx *ds_ctx, const char *xpath,
+ char *dxpaths[], int *num_nodes,
+ bool get_childs_as_well, bool alloc_xp_copy)
+{
+ char base_xpath[MGMTD_MAX_XPATH_LEN];
+
+ if (!ds_ctx || !num_nodes)
+ return -1;
+
+ if (xpath[0] == '.' && xpath[1] == '/')
+ xpath += 2;
+
+ strlcpy(base_xpath, xpath, sizeof(base_xpath));
+ mgmt_remove_trailing_separator(base_xpath, '/');
+
+ return (mgmt_walk_ds_nodes(ds_ctx, base_xpath, NULL, NULL, NULL,
+ dxpaths, num_nodes, get_childs_as_well,
+ alloc_xp_copy));
+}
+
+struct lyd_node *mgmt_ds_find_data_node_by_xpath(struct mgmt_ds_ctx *ds_ctx,
+ const char *xpath)
+{
+ if (!ds_ctx)
+ return NULL;
+
+ return yang_dnode_get(ds_ctx->config_ds ? ds_ctx->root.cfg_root->dnode
+ : ds_ctx->root.dnode_root,
+ xpath);
+}
+
+int mgmt_ds_delete_data_nodes(struct mgmt_ds_ctx *ds_ctx, const char *xpath)
+{
+ struct nb_node *nb_node;
+ struct lyd_node *dnode, *dep_dnode;
+ char dep_xpath[XPATH_MAXLEN];
+
+ if (!ds_ctx)
+ return -1;
+
+ nb_node = nb_node_find(xpath);
+
+ dnode = yang_dnode_get(ds_ctx->config_ds
+ ? ds_ctx->root.cfg_root->dnode
+ : ds_ctx->root.dnode_root,
+ xpath);
+
+ if (!dnode)
+ /*
+ * Return a special error code so the caller can choose
+ * whether to ignore it or not.
+ */
+ return NB_ERR_NOT_FOUND;
+ /* destroy dependant */
+ if (nb_node->dep_cbs.get_dependant_xpath) {
+ nb_node->dep_cbs.get_dependant_xpath(dnode, dep_xpath);
+
+ dep_dnode = yang_dnode_get(
+ ds_ctx->config_ds ? ds_ctx->root.cfg_root->dnode
+ : ds_ctx->root.dnode_root,
+ dep_xpath);
+ if (dep_dnode)
+ lyd_free_tree(dep_dnode);
+ }
+ lyd_free_tree(dnode);
+
+ return 0;
+}
+
+int mgmt_ds_load_config_from_file(struct mgmt_ds_ctx *dst,
+ const char *file_path, bool merge)
+{
+ struct lyd_node *iter;
+ struct mgmt_ds_ctx parsed;
+
+ if (!dst)
+ return -1;
+
+ if (mgmt_ds_load_cfg_from_file(file_path, &iter) != 0) {
+ MGMTD_DS_ERR("Failed to load config from the file %s",
+ file_path);
+ return -1;
+ }
+
+ parsed.root.cfg_root = nb_config_new(iter);
+ parsed.config_ds = true;
+ parsed.ds_id = dst->ds_id;
+
+ if (merge)
+ mgmt_ds_merge_src_with_dst_ds(&parsed, dst);
+ else
+ mgmt_ds_replace_dst_with_src_ds(&parsed, dst);
+
+ nb_config_free(parsed.root.cfg_root);
+
+ return 0;
+}
+
+int mgmt_ds_iter_data(struct mgmt_ds_ctx *ds_ctx, char *base_xpath,
+ void (*mgmt_ds_node_iter_fn)(struct mgmt_ds_ctx *ds_ctx,
+ char *xpath,
+ struct lyd_node *node,
+ struct nb_node *nb_node,
+ void *ctx),
+ void *ctx, bool alloc_xp_copy)
+{
+ int ret;
+ char xpath[MGMTD_MAX_XPATH_LEN];
+ struct lyd_node *base_dnode = NULL;
+ struct lyd_node *node;
+
+ if (!ds_ctx)
+ return -1;
+
+ mgmt_remove_trailing_separator(base_xpath, '/');
+
+ strlcpy(xpath, base_xpath, sizeof(xpath));
+
+ MGMTD_DS_DBG(" -- START DS walk for DSid: %d", ds_ctx->ds_id);
+
+ /* If the base_xpath is empty then crawl the sibblings */
+ if (xpath[0] == '\0') {
+ base_dnode = ds_ctx->config_ds ? ds_ctx->root.cfg_root->dnode
+ : ds_ctx->root.dnode_root;
+
+ /* get first top-level sibling */
+ while (base_dnode->parent)
+ base_dnode = lyd_parent(base_dnode);
+
+ while (base_dnode->prev->next)
+ base_dnode = base_dnode->prev;
+
+ LY_LIST_FOR (base_dnode, node) {
+ ret = mgmt_walk_ds_nodes(
+ ds_ctx, xpath, node, mgmt_ds_node_iter_fn,
+ ctx, NULL, NULL, true, alloc_xp_copy);
+ }
+ } else
+ ret = mgmt_walk_ds_nodes(ds_ctx, xpath, base_dnode,
+ mgmt_ds_node_iter_fn, ctx, NULL, NULL,
+ true, alloc_xp_copy);
+
+ return ret;
+}
+
+void mgmt_ds_dump_tree(struct vty *vty, struct mgmt_ds_ctx *ds_ctx,
+ const char *xpath, FILE *f, LYD_FORMAT format)
+{
+ struct ly_out *out;
+ char *str;
+ char base_xpath[MGMTD_MAX_XPATH_LEN] = {0};
+
+ if (!ds_ctx) {
+ vty_out(vty, " >>>>> Datastore Not Initialized!\n");
+ return;
+ }
+
+ if (xpath) {
+ strlcpy(base_xpath, xpath, MGMTD_MAX_XPATH_LEN);
+ mgmt_remove_trailing_separator(base_xpath, '/');
+ }
+
+ if (f)
+ ly_out_new_file(f, &out);
+ else
+ ly_out_new_memory(&str, 0, &out);
+
+ mgmt_ds_dump_in_memory(ds_ctx, base_xpath, format, out);
+
+ if (!f)
+ vty_out(vty, "%s\n", str);
+
+ ly_out_free(out, NULL, 0);
+}
+
+void mgmt_ds_status_write_one(struct vty *vty, struct mgmt_ds_ctx *ds_ctx)
+{
+ if (!ds_ctx) {
+ vty_out(vty, " >>>>> Datastore Not Initialized!\n");
+ return;
+ }
+
+ vty_out(vty, " DS: %s\n", mgmt_ds_id2name(ds_ctx->ds_id));
+ vty_out(vty, " DS-Hndl: \t\t\t%p\n", ds_ctx);
+ vty_out(vty, " Config: \t\t\t%s\n",
+ ds_ctx->config_ds ? "True" : "False");
+}
+
+void mgmt_ds_status_write(struct vty *vty)
+{
+ vty_out(vty, "MGMTD Datastores\n");
+
+ mgmt_ds_status_write_one(vty, mgmt_ds_mm->running_ds);
+
+ mgmt_ds_status_write_one(vty, mgmt_ds_mm->candidate_ds);
+
+ mgmt_ds_status_write_one(vty, mgmt_ds_mm->oper_ds);
+}
diff --git a/mgmtd/mgmt_ds.h b/mgmtd/mgmt_ds.h
new file mode 100644
index 0000000000..8d01f3d5b1
--- /dev/null
+++ b/mgmtd/mgmt_ds.h
@@ -0,0 +1,372 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * MGMTD Datastores
+ *
+ * Copyright (C) 2021 Vmware, Inc.
+ * Pushpasis Sarkar <spushpasis@vmware.com>
+ */
+
+#ifndef _FRR_MGMTD_DS_H_
+#define _FRR_MGMTD_DS_H_
+
+#include "mgmt_fe_client.h"
+#include "northbound.h"
+
+#include "mgmtd/mgmt_defines.h"
+#include "mgmtd/mgmt_be_adapter.h"
+#include "mgmtd/mgmt_fe_adapter.h"
+
+#define MGMTD_MAX_NUM_DSNODES_PER_BATCH 128
+
+#define MGMTD_DS_NAME_MAX_LEN 32
+#define MGMTD_DS_NAME_NONE "none"
+#define MGMTD_DS_NAME_RUNNING "running"
+#define MGMTD_DS_NAME_CANDIDATE "candidate"
+#define MGMTD_DS_NAME_OPERATIONAL "operational"
+
+#define FOREACH_MGMTD_DS_ID(id) \
+ for ((id) = MGMTD_DS_NONE; (id) < MGMTD_DS_MAX_ID; (id)++)
+
+#define MGMTD_MAX_COMMIT_LIST 10
+#define MGMTD_MD5_HASH_LEN 16
+#define MGMTD_MD5_HASH_STR_HEX_LEN 33
+
+#define MGMTD_COMMIT_FILE_PATH DAEMON_DB_DIR "/commit-%s.json"
+#define MGMTD_COMMIT_INDEX_FILE_NAME DAEMON_DB_DIR "/commit-index.dat"
+#define MGMTD_COMMIT_TIME_STR_LEN 100
+
+extern struct nb_config *running_config;
+
+struct mgmt_ds_ctx;
+
+/***************************************************************
+ * Global data exported
+ ***************************************************************/
+
+extern const char *mgmt_ds_names[MGMTD_DS_MAX_ID + 1];
+
+/*
+ * Convert datastore ID to datastore name.
+ *
+ * id
+ * Datastore ID.
+ *
+ * Returns:
+ * Datastore name.
+ */
+static inline const char *mgmt_ds_id2name(Mgmtd__DatastoreId id)
+{
+ if (id > MGMTD_DS_MAX_ID)
+ id = MGMTD_DS_MAX_ID;
+ return mgmt_ds_names[id];
+}
+
+/*
+ * Convert datastore name to datastore ID.
+ *
+ * id
+ * Datastore name.
+ *
+ * Returns:
+ * Datastore ID.
+ */
+static inline Mgmtd__DatastoreId mgmt_ds_name2id(const char *name)
+{
+ Mgmtd__DatastoreId id;
+
+ FOREACH_MGMTD_DS_ID (id) {
+ if (!strncmp(mgmt_ds_names[id], name, MGMTD_DS_NAME_MAX_LEN))
+ return id;
+ }
+
+ return MGMTD_DS_NONE;
+}
+
+/*
+ * Convert datastore ID to datastore name.
+ *
+ * similar to above funtion.
+ */
+static inline Mgmtd__DatastoreId mgmt_get_ds_id_by_name(const char *ds_name)
+{
+ if (!strncmp(ds_name, "candidate", sizeof("candidate")))
+ return MGMTD_DS_CANDIDATE;
+ else if (!strncmp(ds_name, "running", sizeof("running")))
+ return MGMTD_DS_RUNNING;
+ else if (!strncmp(ds_name, "operational", sizeof("operational")))
+ return MGMTD_DS_OPERATIONAL;
+ return MGMTD_DS_NONE;
+}
+
+/*
+ * Appends trail wildcard '/' '*' to a given xpath.
+ *
+ * xpath
+ * YANG xpath.
+ *
+ * path_len
+ * xpath length.
+ */
+static inline void mgmt_xpath_append_trail_wildcard(char *xpath,
+ size_t *xpath_len)
+{
+ if (!xpath || !xpath_len)
+ return;
+
+ if (!*xpath_len)
+ *xpath_len = strlen(xpath);
+
+ if (*xpath_len > 2 && *xpath_len < MGMTD_MAX_XPATH_LEN - 2) {
+ if (xpath[*xpath_len - 1] == '/') {
+ xpath[*xpath_len] = '*';
+ xpath[*xpath_len + 1] = 0;
+ (*xpath_len)++;
+ } else if (xpath[*xpath_len - 1] != '*') {
+ xpath[*xpath_len] = '/';
+ xpath[*xpath_len + 1] = '*';
+ xpath[*xpath_len + 2] = 0;
+ (*xpath_len) += 2;
+ }
+ }
+}
+
+/*
+ * Removes trail wildcard '/' '*' from a given xpath.
+ *
+ * xpath
+ * YANG xpath.
+ *
+ * path_len
+ * xpath length.
+ */
+static inline void mgmt_xpath_remove_trail_wildcard(char *xpath,
+ size_t *xpath_len)
+{
+ if (!xpath || !xpath_len)
+ return;
+
+ if (!*xpath_len)
+ *xpath_len = strlen(xpath);
+
+ if (*xpath_len > 2 && xpath[*xpath_len - 2] == '/'
+ && xpath[*xpath_len - 1] == '*') {
+ xpath[*xpath_len - 2] = 0;
+ (*xpath_len) -= 2;
+ }
+}
+
+/* Initialise datastore */
+extern int mgmt_ds_init(struct mgmt_master *cm);
+
+/* Destroy datastore */
+extern void mgmt_ds_destroy(void);
+
+/*
+ * Get datastore handler by ID
+ *
+ * mm
+ * Management master structure.
+ *
+ * ds_id
+ * Datastore ID.
+ *
+ * Returns:
+ * Datastore context (Holds info about ID, lock, root node etc).
+ */
+extern struct mgmt_ds_ctx *mgmt_ds_get_ctx_by_id(struct mgmt_master *mm,
+ Mgmtd__DatastoreId ds_id);
+
+/*
+ * Check if a given datastore is config ds
+ */
+extern bool mgmt_ds_is_config(struct mgmt_ds_ctx *ds_ctx);
+
+/*
+ * Acquire read lock to a ds given a ds_handle
+ */
+extern int mgmt_ds_read_lock(struct mgmt_ds_ctx *ds_ctx);
+
+/*
+ * Acquire write lock to a ds given a ds_handle
+ */
+extern int mgmt_ds_write_lock(struct mgmt_ds_ctx *ds_ctx);
+
+/*
+ * Remove a lock from ds given a ds_handle
+ */
+extern int mgmt_ds_unlock(struct mgmt_ds_ctx *ds_ctx);
+
+/*
+ * Copy from source to destination datastore.
+ *
+ * src_ds
+ * Source datastore handle (ds to be copied from).
+ *
+ * dst_ds
+ * Destination datastore handle (ds to be copied to).
+ *
+ * update_cmd_rec
+ * TRUE if need to update commit record, FALSE otherwise.
+ *
+ * Returns:
+ * 0 on success, -1 on failure.
+ */
+extern int mgmt_ds_copy_dss(struct mgmt_ds_ctx *src_ds_ctx,
+ struct mgmt_ds_ctx *dst_ds_ctx,
+ bool update_cmt_rec);
+
+/*
+ * Fetch northbound configuration for a given datastore context.
+ */
+extern struct nb_config *mgmt_ds_get_nb_config(struct mgmt_ds_ctx *ds_ctx);
+
+/*
+ * Lookup YANG data nodes.
+ *
+ * ds_ctx
+ * Datastore context.
+ *
+ * xpath
+ * YANG base xpath.
+ *
+ * dxpaths
+ * Out param - array of YANG data xpaths.
+ *
+ * num_nodes
+ * In-out param - number of YANG data xpaths.
+ * Note - Caller should init this to the size of the array
+ * provided in dxpaths.
+ * On return this will have the actual number of xpaths
+ * being returned.
+ *
+ * get_childs_as_well
+ * TRUE if child nodes needs to be fetched as well, FALSE otherwise.
+ *
+ * alloc_xp_copy
+ * TRUE if the caller is interested in getting a copy of the xpath.
+ *
+ * Returns:
+ * 0 on success, -1 on failure.
+ */
+extern int mgmt_ds_lookup_data_nodes(struct mgmt_ds_ctx *ds_ctx,
+ const char *xpath, char *dxpaths[],
+ int *num_nodes, bool get_childs_as_well,
+ bool alloc_xp_copy);
+
+/*
+ * Find YANG data node given a datastore handle YANG xpath.
+ */
+extern struct lyd_node *
+mgmt_ds_find_data_node_by_xpath(struct mgmt_ds_ctx *ds_ctx,
+ const char *xpath);
+
+/*
+ * Delete YANG data node given a datastore handle and YANG xpath.
+ */
+extern int mgmt_ds_delete_data_nodes(struct mgmt_ds_ctx *ds_ctx,
+ const char *xpath);
+
+/*
+ * Iterate over datastore data.
+ *
+ * ds_ctx
+ * Datastore context.
+ *
+ * base_xpath
+ * Base YANG xpath from where needs to be iterated.
+ *
+ * iter_fn
+ * function that will be called during each iteration.
+ *
+ * ctx
+ * User defined opaque value normally used to pass
+ * reference to some user private context that will
+ * be passed to the iterator function provided in
+ * 'iter_fn'.
+ *
+ * alloc_xp_copy
+ * TRUE if the caller is interested in getting a copy of the xpath.
+ *
+ * Returns:
+ * 0 on success, -1 on failure.
+ */
+extern int mgmt_ds_iter_data(
+ struct mgmt_ds_ctx *ds_ctx, char *base_xpath,
+ void (*mgmt_ds_node_iter_fn)(struct mgmt_ds_ctx *ds_ctx, char *xpath,
+ struct lyd_node *node,
+ struct nb_node *nb_node, void *ctx),
+ void *ctx, bool alloc_xp_copy);
+
+/*
+ * Load config to datastore from a file.
+ *
+ * ds_ctx
+ * Datastore context.
+ *
+ * file_path
+ * File path of the configuration file.
+ *
+ * merge
+ * TRUE if you want to merge with existing config,
+ * FALSE if you want to replace with existing config
+ *
+ * Returns:
+ * 0 on success, -1 on failure.
+ */
+extern int mgmt_ds_load_config_from_file(struct mgmt_ds_ctx *ds_ctx,
+ const char *file_path, bool merge);
+
+/*
+ * Dump the data tree to a file with JSON/XML format.
+ *
+ * vty
+ * VTY context.
+ *
+ * ds_ctx
+ * Datastore context.
+ *
+ * xpath
+ * Base YANG xpath from where data needs to be dumped.
+ *
+ * f
+ * File pointer to where data to be dumped.
+ *
+ * format
+ * JSON/XML
+ */
+extern void mgmt_ds_dump_tree(struct vty *vty, struct mgmt_ds_ctx *ds_ctx,
+ const char *xpath, FILE *f, LYD_FORMAT format);
+
+/*
+ * Dump the complete data tree to a file with JSON format.
+ *
+ * file_name
+ * File path to where data to be dumped.
+ *
+ * ds
+ * Datastore context.
+ *
+ * Returns:
+ * 0 on success, -1 on failure.
+ */
+extern int mgmt_ds_dump_ds_to_file(char *file_name,
+ struct mgmt_ds_ctx *ds_ctx);
+
+/*
+ * Dump information about specific datastore.
+ */
+extern void mgmt_ds_status_write_one(struct vty *vty,
+ struct mgmt_ds_ctx *ds_ctx);
+
+/*
+ * Dump information about all the datastores.
+ */
+extern void mgmt_ds_status_write(struct vty *vty);
+
+
+/*
+ * Reset the candidate DS to empty state
+ */
+void mgmt_ds_reset_candidate(void);
+
+#endif /* _FRR_MGMTD_DS_H_ */
diff --git a/mgmtd/mgmt_fe_adapter.c b/mgmtd/mgmt_fe_adapter.c
new file mode 100644
index 0000000000..5826b17de7
--- /dev/null
+++ b/mgmtd/mgmt_fe_adapter.c
@@ -0,0 +1,1902 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * MGMTD Frontend Client Connection Adapter
+ *
+ * Copyright (C) 2021 Vmware, Inc.
+ * Pushpasis Sarkar <spushpasis@vmware.com>
+ */
+
+#include <zebra.h>
+#include "sockopt.h"
+#include "network.h"
+#include "libfrr.h"
+#include "mgmt_fe_client.h"
+#include "mgmt_msg.h"
+#include "mgmt_pb.h"
+#include "hash.h"
+#include "jhash.h"
+#include "mgmtd/mgmt.h"
+#include "mgmtd/mgmt_memory.h"
+#include "mgmtd/mgmt_fe_adapter.h"
+
+#ifdef REDIRECT_DEBUG_TO_STDERR
+#define MGMTD_FE_ADAPTER_DBG(fmt, ...) \
+ fprintf(stderr, "%s: " fmt "\n", __func__, ##__VA_ARGS__)
+#define MGMTD_FE_ADAPTER_ERR(fmt, ...) \
+ fprintf(stderr, "%s: ERROR, " fmt "\n", __func__, ##__VA_ARGS__)
+#else /* REDIRECT_DEBUG_TO_STDERR */
+#define MGMTD_FE_ADAPTER_DBG(fmt, ...) \
+ do { \
+ if (mgmt_debug_fe) \
+ zlog_debug("%s: " fmt, __func__, ##__VA_ARGS__); \
+ } while (0)
+#define MGMTD_FE_ADAPTER_ERR(fmt, ...) \
+ zlog_err("%s: ERROR: " fmt, __func__, ##__VA_ARGS__)
+#endif /* REDIRECT_DEBUG_TO_STDERR */
+
+#define FOREACH_ADAPTER_IN_LIST(adapter) \
+ frr_each_safe (mgmt_fe_adapters, &mgmt_fe_adapters, (adapter))
+
+enum mgmt_session_event {
+ MGMTD_FE_SESSION_CFG_TXN_CLNUP = 1,
+ MGMTD_FE_SESSION_SHOW_TXN_CLNUP,
+};
+
+struct mgmt_fe_session_ctx {
+ struct mgmt_fe_client_adapter *adapter;
+ uint64_t session_id;
+ uint64_t client_id;
+ uint64_t txn_id;
+ uint64_t cfg_txn_id;
+ uint8_t ds_write_locked[MGMTD_DS_MAX_ID];
+ uint8_t ds_read_locked[MGMTD_DS_MAX_ID];
+ uint8_t ds_locked_implict[MGMTD_DS_MAX_ID];
+ struct event *proc_cfg_txn_clnp;
+ struct event *proc_show_txn_clnp;
+
+ struct mgmt_fe_sessions_item list_linkage;
+};
+
+DECLARE_LIST(mgmt_fe_sessions, struct mgmt_fe_session_ctx, list_linkage);
+
+#define FOREACH_SESSION_IN_LIST(adapter, session) \
+ frr_each_safe (mgmt_fe_sessions, &(adapter)->fe_sessions, (session))
+
+static struct event_loop *mgmt_fe_adapter_tm;
+static struct mgmt_master *mgmt_fe_adapter_mm;
+
+static struct mgmt_fe_adapters_head mgmt_fe_adapters;
+
+static struct hash *mgmt_fe_sessions;
+static uint64_t mgmt_fe_next_session_id;
+
+/* Forward declarations */
+static void
+mgmt_fe_adapter_register_event(struct mgmt_fe_client_adapter *adapter,
+ enum mgmt_fe_event event);
+static void
+mgmt_fe_adapter_disconnect(struct mgmt_fe_client_adapter *adapter);
+static void
+mgmt_fe_session_register_event(struct mgmt_fe_session_ctx *session,
+ enum mgmt_session_event event);
+
+static int
+mgmt_fe_session_write_lock_ds(Mgmtd__DatastoreId ds_id,
+ struct mgmt_ds_ctx *ds_ctx,
+ struct mgmt_fe_session_ctx *session)
+{
+ if (!session->ds_write_locked[ds_id]) {
+ if (mgmt_ds_write_lock(ds_ctx) != 0) {
+ MGMTD_FE_ADAPTER_DBG(
+ "Failed to lock the DS %u for Sessn: %p from %s!",
+ ds_id, session, session->adapter->name);
+ return -1;
+ }
+
+ session->ds_write_locked[ds_id] = true;
+ MGMTD_FE_ADAPTER_DBG(
+ "Write-Locked the DS %u for Sessn: %p from %s!", ds_id,
+ session, session->adapter->name);
+ }
+
+ return 0;
+}
+
+static int
+mgmt_fe_session_read_lock_ds(Mgmtd__DatastoreId ds_id,
+ struct mgmt_ds_ctx *ds_ctx,
+ struct mgmt_fe_session_ctx *session)
+{
+ if (!session->ds_read_locked[ds_id]) {
+ if (mgmt_ds_read_lock(ds_ctx) != 0) {
+ MGMTD_FE_ADAPTER_DBG(
+ "Failed to lock the DS %u for Sessn: %p from %s!",
+ ds_id, session, session->adapter->name);
+ return -1;
+ }
+
+ session->ds_read_locked[ds_id] = true;
+ MGMTD_FE_ADAPTER_DBG(
+ "Read-Locked the DS %u for Sessn: %p from %s!", ds_id,
+ session, session->adapter->name);
+ }
+
+ return 0;
+}
+
+static int mgmt_fe_session_unlock_ds(Mgmtd__DatastoreId ds_id,
+ struct mgmt_ds_ctx *ds_ctx,
+ struct mgmt_fe_session_ctx *session,
+ bool unlock_write, bool unlock_read)
+{
+ if (unlock_write && session->ds_write_locked[ds_id]) {
+ session->ds_write_locked[ds_id] = false;
+ session->ds_locked_implict[ds_id] = false;
+ if (mgmt_ds_unlock(ds_ctx) != 0) {
+ MGMTD_FE_ADAPTER_DBG(
+ "Failed to unlock the DS %u taken earlier by Sessn: %p from %s!",
+ ds_id, session, session->adapter->name);
+ return -1;
+ }
+
+ MGMTD_FE_ADAPTER_DBG(
+ "Unlocked DS %u write-locked earlier by Sessn: %p from %s",
+ ds_id, session, session->adapter->name);
+ } else if (unlock_read && session->ds_read_locked[ds_id]) {
+ session->ds_read_locked[ds_id] = false;
+ session->ds_locked_implict[ds_id] = false;
+ if (mgmt_ds_unlock(ds_ctx) != 0) {
+ MGMTD_FE_ADAPTER_DBG(
+ "Failed to unlock the DS %u taken earlier by Sessn: %p from %s!",
+ ds_id, session, session->adapter->name);
+ return -1;
+ }
+
+ MGMTD_FE_ADAPTER_DBG(
+ "Unlocked DS %u read-locked earlier by Sessn: %p from %s",
+ ds_id, session, session->adapter->name);
+ }
+
+ return 0;
+}
+
+static void
+mgmt_fe_session_cfg_txn_cleanup(struct mgmt_fe_session_ctx *session)
+{
+ Mgmtd__DatastoreId ds_id;
+ struct mgmt_ds_ctx *ds_ctx;
+
+ /*
+ * Ensure any uncommitted changes in Candidate DS
+ * is discarded.
+ */
+ mgmt_ds_copy_dss(mm->running_ds, mm->candidate_ds, false);
+
+ for (ds_id = 0; ds_id < MGMTD_DS_MAX_ID; ds_id++) {
+ ds_ctx = mgmt_ds_get_ctx_by_id(mgmt_fe_adapter_mm, ds_id);
+ if (ds_ctx) {
+ if (session->ds_locked_implict[ds_id])
+ mgmt_fe_session_unlock_ds(
+ ds_id, ds_ctx, session, true, false);
+ }
+ }
+
+ /*
+ * Destroy the actual transaction created earlier.
+ */
+ if (session->cfg_txn_id != MGMTD_TXN_ID_NONE)
+ mgmt_destroy_txn(&session->cfg_txn_id);
+}
+
+static void
+mgmt_fe_session_show_txn_cleanup(struct mgmt_fe_session_ctx *session)
+{
+ Mgmtd__DatastoreId ds_id;
+ struct mgmt_ds_ctx *ds_ctx;
+
+ for (ds_id = 0; ds_id < MGMTD_DS_MAX_ID; ds_id++) {
+ ds_ctx = mgmt_ds_get_ctx_by_id(mgmt_fe_adapter_mm, ds_id);
+ if (ds_ctx) {
+ mgmt_fe_session_unlock_ds(ds_id, ds_ctx, session,
+ false, true);
+ }
+ }
+
+ /*
+ * Destroy the transaction created recently.
+ */
+ if (session->txn_id != MGMTD_TXN_ID_NONE)
+ mgmt_destroy_txn(&session->txn_id);
+}
+
+static void
+mgmt_fe_adapter_compute_set_cfg_timers(struct mgmt_setcfg_stats *setcfg_stats)
+{
+ setcfg_stats->last_exec_tm = timeval_elapsed(setcfg_stats->last_end,
+ setcfg_stats->last_start);
+ if (setcfg_stats->last_exec_tm > setcfg_stats->max_tm)
+ setcfg_stats->max_tm = setcfg_stats->last_exec_tm;
+
+ if (setcfg_stats->last_exec_tm < setcfg_stats->min_tm)
+ setcfg_stats->min_tm = setcfg_stats->last_exec_tm;
+
+ setcfg_stats->avg_tm =
+ (((setcfg_stats->avg_tm * (setcfg_stats->set_cfg_count - 1))
+ + setcfg_stats->last_exec_tm)
+ / setcfg_stats->set_cfg_count);
+}
+
+static void
+mgmt_fe_session_compute_commit_timers(struct mgmt_commit_stats *cmt_stats)
+{
+ cmt_stats->last_exec_tm =
+ timeval_elapsed(cmt_stats->last_end, cmt_stats->last_start);
+ if (cmt_stats->last_exec_tm > cmt_stats->max_tm) {
+ cmt_stats->max_tm = cmt_stats->last_exec_tm;
+ cmt_stats->max_batch_cnt = cmt_stats->last_batch_cnt;
+ }
+
+ if (cmt_stats->last_exec_tm < cmt_stats->min_tm) {
+ cmt_stats->min_tm = cmt_stats->last_exec_tm;
+ cmt_stats->min_batch_cnt = cmt_stats->last_batch_cnt;
+ }
+}
+
+static void mgmt_fe_cleanup_session(struct mgmt_fe_session_ctx **session)
+{
+ if ((*session)->adapter) {
+ mgmt_fe_session_cfg_txn_cleanup((*session));
+ mgmt_fe_session_show_txn_cleanup((*session));
+ mgmt_fe_session_unlock_ds(MGMTD_DS_CANDIDATE,
+ mgmt_fe_adapter_mm->candidate_ds,
+ *session, true, true);
+ mgmt_fe_session_unlock_ds(MGMTD_DS_RUNNING,
+ mgmt_fe_adapter_mm->running_ds,
+ *session, true, true);
+
+ mgmt_fe_sessions_del(&(*session)->adapter->fe_sessions,
+ *session);
+ mgmt_fe_adapter_unlock(&(*session)->adapter);
+ }
+
+ hash_release(mgmt_fe_sessions, *session);
+ XFREE(MTYPE_MGMTD_FE_SESSION, *session);
+ *session = NULL;
+}
+
+static struct mgmt_fe_session_ctx *
+mgmt_fe_find_session_by_client_id(struct mgmt_fe_client_adapter *adapter,
+ uint64_t client_id)
+{
+ struct mgmt_fe_session_ctx *session;
+
+ FOREACH_SESSION_IN_LIST (adapter, session) {
+ if (session->client_id == client_id)
+ return session;
+ }
+
+ return NULL;
+}
+
+static unsigned int mgmt_fe_session_hash_key(const void *data)
+{
+ const struct mgmt_fe_session_ctx *session = data;
+
+ return jhash2((uint32_t *) &session->session_id,
+ sizeof(session->session_id) / sizeof(uint32_t), 0);
+}
+
+static bool mgmt_fe_session_hash_cmp(const void *d1, const void *d2)
+{
+ const struct mgmt_fe_session_ctx *session1 = d1;
+ const struct mgmt_fe_session_ctx *session2 = d2;
+
+ return (session1->session_id == session2->session_id);
+}
+
+static void mgmt_fe_session_hash_free(void *data)
+{
+ struct mgmt_fe_session_ctx *session = data;
+
+ mgmt_fe_cleanup_session(&session);
+}
+
+static void mgmt_fe_session_hash_destroy(void)
+{
+ if (mgmt_fe_sessions == NULL)
+ return;
+
+ hash_clean(mgmt_fe_sessions,
+ mgmt_fe_session_hash_free);
+ hash_free(mgmt_fe_sessions);
+ mgmt_fe_sessions = NULL;
+}
+
+static inline struct mgmt_fe_session_ctx *
+mgmt_session_id2ctx(uint64_t session_id)
+{
+ struct mgmt_fe_session_ctx key = {0};
+ struct mgmt_fe_session_ctx *session;
+
+ if (!mgmt_fe_sessions)
+ return NULL;
+
+ key.session_id = session_id;
+ session = hash_lookup(mgmt_fe_sessions, &key);
+
+ return session;
+}
+
+static struct mgmt_fe_session_ctx *
+mgmt_fe_create_session(struct mgmt_fe_client_adapter *adapter,
+ uint64_t client_id)
+{
+ struct mgmt_fe_session_ctx *session;
+
+ session = mgmt_fe_find_session_by_client_id(adapter, client_id);
+ if (session)
+ mgmt_fe_cleanup_session(&session);
+
+ session = XCALLOC(MTYPE_MGMTD_FE_SESSION,
+ sizeof(struct mgmt_fe_session_ctx));
+ assert(session);
+ session->client_id = client_id;
+ session->adapter = adapter;
+ session->txn_id = MGMTD_TXN_ID_NONE;
+ session->cfg_txn_id = MGMTD_TXN_ID_NONE;
+ mgmt_fe_adapter_lock(adapter);
+ mgmt_fe_sessions_add_tail(&adapter->fe_sessions, session);
+ if (!mgmt_fe_next_session_id)
+ mgmt_fe_next_session_id++;
+ session->session_id = mgmt_fe_next_session_id++;
+ hash_get(mgmt_fe_sessions, session, hash_alloc_intern);
+
+ return session;
+}
+
+static void
+mgmt_fe_cleanup_sessions(struct mgmt_fe_client_adapter *adapter)
+{
+ struct mgmt_fe_session_ctx *session;
+
+ FOREACH_SESSION_IN_LIST (adapter, session)
+ mgmt_fe_cleanup_session(&session);
+}
+
+static inline void
+mgmt_fe_adapter_sched_msg_write(struct mgmt_fe_client_adapter *adapter)
+{
+ if (!CHECK_FLAG(adapter->flags, MGMTD_FE_ADAPTER_FLAGS_WRITES_OFF))
+ mgmt_fe_adapter_register_event(adapter,
+ MGMTD_FE_CONN_WRITE);
+}
+
+static inline void
+mgmt_fe_adapter_writes_on(struct mgmt_fe_client_adapter *adapter)
+{
+ MGMTD_FE_ADAPTER_DBG("Resume writing msgs for '%s'", adapter->name);
+ UNSET_FLAG(adapter->flags, MGMTD_FE_ADAPTER_FLAGS_WRITES_OFF);
+ mgmt_fe_adapter_sched_msg_write(adapter);
+}
+
+static inline void
+mgmt_fe_adapter_writes_off(struct mgmt_fe_client_adapter *adapter)
+{
+ SET_FLAG(adapter->flags, MGMTD_FE_ADAPTER_FLAGS_WRITES_OFF);
+ MGMTD_FE_ADAPTER_DBG("Paused writing msgs for '%s'", adapter->name);
+}
+
+static int
+mgmt_fe_adapter_send_msg(struct mgmt_fe_client_adapter *adapter,
+ Mgmtd__FeMessage *fe_msg)
+{
+ if (adapter->conn_fd == -1) {
+ MGMTD_FE_ADAPTER_DBG("can't send message on closed connection");
+ return -1;
+ }
+
+ int rv = mgmt_msg_send_msg(
+ &adapter->mstate, fe_msg,
+ mgmtd__fe_message__get_packed_size(fe_msg),
+ (size_t(*)(void *, void *))mgmtd__fe_message__pack,
+ mgmt_debug_fe);
+ mgmt_fe_adapter_sched_msg_write(adapter);
+ return rv;
+}
+
+static int
+mgmt_fe_send_session_reply(struct mgmt_fe_client_adapter *adapter,
+ struct mgmt_fe_session_ctx *session,
+ bool create, bool success)
+{
+ Mgmtd__FeMessage fe_msg;
+ Mgmtd__FeSessionReply session_reply;
+
+ mgmtd__fe_session_reply__init(&session_reply);
+ session_reply.create = create;
+ if (create) {
+ session_reply.has_client_conn_id = 1;
+ session_reply.client_conn_id = session->client_id;
+ }
+ session_reply.session_id = session->session_id;
+ session_reply.success = success;
+
+ mgmtd__fe_message__init(&fe_msg);
+ fe_msg.message_case = MGMTD__FE_MESSAGE__MESSAGE_SESSION_REPLY;
+ fe_msg.session_reply = &session_reply;
+
+ MGMTD_FE_ADAPTER_DBG(
+ "Sending SESSION_REPLY message to MGMTD Frontend client '%s'",
+ adapter->name);
+
+ return mgmt_fe_adapter_send_msg(adapter, &fe_msg);
+}
+
+static int mgmt_fe_send_lockds_reply(struct mgmt_fe_session_ctx *session,
+ Mgmtd__DatastoreId ds_id,
+ uint64_t req_id, bool lock_ds,
+ bool success, const char *error_if_any)
+{
+ Mgmtd__FeMessage fe_msg;
+ Mgmtd__FeLockDsReply lockds_reply;
+
+ assert(session->adapter);
+
+ mgmtd__fe_lock_ds_reply__init(&lockds_reply);
+ lockds_reply.session_id = session->session_id;
+ lockds_reply.ds_id = ds_id;
+ lockds_reply.req_id = req_id;
+ lockds_reply.lock = lock_ds;
+ lockds_reply.success = success;
+ if (error_if_any)
+ lockds_reply.error_if_any = (char *)error_if_any;
+
+ mgmtd__fe_message__init(&fe_msg);
+ fe_msg.message_case = MGMTD__FE_MESSAGE__MESSAGE_LOCKDS_REPLY;
+ fe_msg.lockds_reply = &lockds_reply;
+
+ MGMTD_FE_ADAPTER_DBG(
+ "Sending LOCK_DS_REPLY message to MGMTD Frontend client '%s'",
+ session->adapter->name);
+
+ return mgmt_fe_adapter_send_msg(session->adapter, &fe_msg);
+}
+
+static int mgmt_fe_send_setcfg_reply(struct mgmt_fe_session_ctx *session,
+ Mgmtd__DatastoreId ds_id,
+ uint64_t req_id, bool success,
+ const char *error_if_any,
+ bool implicit_commit)
+{
+ Mgmtd__FeMessage fe_msg;
+ Mgmtd__FeSetConfigReply setcfg_reply;
+
+ assert(session->adapter);
+
+ if (implicit_commit && session->cfg_txn_id)
+ mgmt_fe_session_register_event(
+ session, MGMTD_FE_SESSION_CFG_TXN_CLNUP);
+
+ mgmtd__fe_set_config_reply__init(&setcfg_reply);
+ setcfg_reply.session_id = session->session_id;
+ setcfg_reply.ds_id = ds_id;
+ setcfg_reply.req_id = req_id;
+ setcfg_reply.success = success;
+ if (error_if_any)
+ setcfg_reply.error_if_any = (char *)error_if_any;
+
+ mgmtd__fe_message__init(&fe_msg);
+ fe_msg.message_case = MGMTD__FE_MESSAGE__MESSAGE_SETCFG_REPLY;
+ fe_msg.setcfg_reply = &setcfg_reply;
+
+ MGMTD_FE_ADAPTER_DBG(
+ "Sending SET_CONFIG_REPLY message to MGMTD Frontend client '%s'",
+ session->adapter->name);
+
+ if (implicit_commit) {
+ if (mm->perf_stats_en)
+ gettimeofday(&session->adapter->cmt_stats.last_end, NULL);
+ mgmt_fe_session_compute_commit_timers(
+ &session->adapter->cmt_stats);
+ }
+
+ if (mm->perf_stats_en)
+ gettimeofday(&session->adapter->setcfg_stats.last_end, NULL);
+ mgmt_fe_adapter_compute_set_cfg_timers(&session->adapter->setcfg_stats);
+
+ return mgmt_fe_adapter_send_msg(session->adapter, &fe_msg);
+}
+
+static int mgmt_fe_send_commitcfg_reply(
+ struct mgmt_fe_session_ctx *session, Mgmtd__DatastoreId src_ds_id,
+ Mgmtd__DatastoreId dst_ds_id, uint64_t req_id, enum mgmt_result result,
+ bool validate_only, const char *error_if_any)
+{
+ Mgmtd__FeMessage fe_msg;
+ Mgmtd__FeCommitConfigReply commcfg_reply;
+
+ assert(session->adapter);
+
+ mgmtd__fe_commit_config_reply__init(&commcfg_reply);
+ commcfg_reply.session_id = session->session_id;
+ commcfg_reply.src_ds_id = src_ds_id;
+ commcfg_reply.dst_ds_id = dst_ds_id;
+ commcfg_reply.req_id = req_id;
+ commcfg_reply.success =
+ (result == MGMTD_SUCCESS || result == MGMTD_NO_CFG_CHANGES)
+ ? true
+ : false;
+ commcfg_reply.validate_only = validate_only;
+ if (error_if_any)
+ commcfg_reply.error_if_any = (char *)error_if_any;
+
+ mgmtd__fe_message__init(&fe_msg);
+ fe_msg.message_case = MGMTD__FE_MESSAGE__MESSAGE_COMMCFG_REPLY;
+ fe_msg.commcfg_reply = &commcfg_reply;
+
+ MGMTD_FE_ADAPTER_DBG(
+ "Sending COMMIT_CONFIG_REPLY message to MGMTD Frontend client '%s'",
+ session->adapter->name);
+
+ /*
+ * Cleanup the CONFIG transaction associated with this session.
+ */
+ if (session->cfg_txn_id
+ && ((result == MGMTD_SUCCESS && !validate_only)
+ || (result == MGMTD_NO_CFG_CHANGES)))
+ mgmt_fe_session_register_event(
+ session, MGMTD_FE_SESSION_CFG_TXN_CLNUP);
+
+ if (mm->perf_stats_en)
+ gettimeofday(&session->adapter->cmt_stats.last_end, NULL);
+ mgmt_fe_session_compute_commit_timers(&session->adapter->cmt_stats);
+ return mgmt_fe_adapter_send_msg(session->adapter, &fe_msg);
+}
+
+static int mgmt_fe_send_getcfg_reply(struct mgmt_fe_session_ctx *session,
+ Mgmtd__DatastoreId ds_id,
+ uint64_t req_id, bool success,
+ Mgmtd__YangDataReply *data,
+ const char *error_if_any)
+{
+ Mgmtd__FeMessage fe_msg;
+ Mgmtd__FeGetConfigReply getcfg_reply;
+
+ assert(session->adapter);
+
+ mgmtd__fe_get_config_reply__init(&getcfg_reply);
+ getcfg_reply.session_id = session->session_id;
+ getcfg_reply.ds_id = ds_id;
+ getcfg_reply.req_id = req_id;
+ getcfg_reply.success = success;
+ getcfg_reply.data = data;
+ if (error_if_any)
+ getcfg_reply.error_if_any = (char *)error_if_any;
+
+ mgmtd__fe_message__init(&fe_msg);
+ fe_msg.message_case = MGMTD__FE_MESSAGE__MESSAGE_GETCFG_REPLY;
+ fe_msg.getcfg_reply = &getcfg_reply;
+
+ MGMTD_FE_ADAPTER_DBG(
+ "Sending GET_CONFIG_REPLY message to MGMTD Frontend client '%s'",
+ session->adapter->name);
+
+ /*
+ * Cleanup the SHOW transaction associated with this session.
+ */
+ if (session->txn_id && (!success || (data && data->next_indx < 0)))
+ mgmt_fe_session_register_event(
+ session, MGMTD_FE_SESSION_SHOW_TXN_CLNUP);
+
+ return mgmt_fe_adapter_send_msg(session->adapter, &fe_msg);
+}
+
+static int mgmt_fe_send_getdata_reply(struct mgmt_fe_session_ctx *session,
+ Mgmtd__DatastoreId ds_id,
+ uint64_t req_id, bool success,
+ Mgmtd__YangDataReply *data,
+ const char *error_if_any)
+{
+ Mgmtd__FeMessage fe_msg;
+ Mgmtd__FeGetDataReply getdata_reply;
+
+ assert(session->adapter);
+
+ mgmtd__fe_get_data_reply__init(&getdata_reply);
+ getdata_reply.session_id = session->session_id;
+ getdata_reply.ds_id = ds_id;
+ getdata_reply.req_id = req_id;
+ getdata_reply.success = success;
+ getdata_reply.data = data;
+ if (error_if_any)
+ getdata_reply.error_if_any = (char *)error_if_any;
+
+ mgmtd__fe_message__init(&fe_msg);
+ fe_msg.message_case = MGMTD__FE_MESSAGE__MESSAGE_GETDATA_REPLY;
+ fe_msg.getdata_reply = &getdata_reply;
+
+ MGMTD_FE_ADAPTER_DBG(
+ "Sending GET_DATA_REPLY message to MGMTD Frontend client '%s'",
+ session->adapter->name);
+
+ /*
+ * Cleanup the SHOW transaction associated with this session.
+ */
+ if (session->txn_id && (!success || (data && data->next_indx < 0)))
+ mgmt_fe_session_register_event(
+ session, MGMTD_FE_SESSION_SHOW_TXN_CLNUP);
+
+ return mgmt_fe_adapter_send_msg(session->adapter, &fe_msg);
+}
+
+static void mgmt_fe_session_cfg_txn_clnup(struct event *thread)
+{
+ struct mgmt_fe_session_ctx *session;
+
+ session = (struct mgmt_fe_session_ctx *)EVENT_ARG(thread);
+
+ mgmt_fe_session_cfg_txn_cleanup(session);
+}
+
+static void mgmt_fe_session_show_txn_clnup(struct event *thread)
+{
+ struct mgmt_fe_session_ctx *session;
+
+ session = (struct mgmt_fe_session_ctx *)EVENT_ARG(thread);
+
+ mgmt_fe_session_show_txn_cleanup(session);
+}
+
+static void
+mgmt_fe_session_register_event(struct mgmt_fe_session_ctx *session,
+ enum mgmt_session_event event)
+{
+ struct timeval tv = {.tv_sec = 0,
+ .tv_usec = MGMTD_FE_MSG_PROC_DELAY_USEC};
+
+ switch (event) {
+ case MGMTD_FE_SESSION_CFG_TXN_CLNUP:
+ event_add_timer_tv(mgmt_fe_adapter_tm,
+ mgmt_fe_session_cfg_txn_clnup, session,
+ &tv, &session->proc_cfg_txn_clnp);
+ break;
+ case MGMTD_FE_SESSION_SHOW_TXN_CLNUP:
+ event_add_timer_tv(mgmt_fe_adapter_tm,
+ mgmt_fe_session_show_txn_clnup, session,
+ &tv, &session->proc_show_txn_clnp);
+ break;
+ }
+}
+
+static struct mgmt_fe_client_adapter *
+mgmt_fe_find_adapter_by_fd(int conn_fd)
+{
+ struct mgmt_fe_client_adapter *adapter;
+
+ FOREACH_ADAPTER_IN_LIST (adapter) {
+ if (adapter->conn_fd == conn_fd)
+ return adapter;
+ }
+
+ return NULL;
+}
+
+static struct mgmt_fe_client_adapter *
+mgmt_fe_find_adapter_by_name(const char *name)
+{
+ struct mgmt_fe_client_adapter *adapter;
+
+ FOREACH_ADAPTER_IN_LIST (adapter) {
+ if (!strncmp(adapter->name, name, sizeof(adapter->name)))
+ return adapter;
+ }
+
+ return NULL;
+}
+
+static void mgmt_fe_adapter_disconnect(struct mgmt_fe_client_adapter *adapter)
+{
+ if (adapter->conn_fd >= 0) {
+ close(adapter->conn_fd);
+ adapter->conn_fd = -1;
+ }
+
+ /* TODO: notify about client disconnect for appropriate cleanup */
+ mgmt_fe_cleanup_sessions(adapter);
+ mgmt_fe_sessions_fini(&adapter->fe_sessions);
+ mgmt_fe_adapters_del(&mgmt_fe_adapters, adapter);
+
+ mgmt_fe_adapter_unlock(&adapter);
+}
+
+static void
+mgmt_fe_adapter_cleanup_old_conn(struct mgmt_fe_client_adapter *adapter)
+{
+ struct mgmt_fe_client_adapter *old;
+
+ FOREACH_ADAPTER_IN_LIST (old) {
+ if (old != adapter
+ && !strncmp(adapter->name, old->name, sizeof(adapter->name))) {
+ /*
+ * We have a Zombie lingering around
+ */
+ MGMTD_FE_ADAPTER_DBG(
+ "Client '%s' (FD:%d) seems to have reconnected. Removing old connection (FD:%d)!",
+ adapter->name, adapter->conn_fd, old->conn_fd);
+ mgmt_fe_adapter_disconnect(old);
+ }
+ }
+}
+
+static void
+mgmt_fe_cleanup_adapters(void)
+{
+ struct mgmt_fe_client_adapter *adapter;
+
+ FOREACH_ADAPTER_IN_LIST (adapter) {
+ mgmt_fe_cleanup_sessions(adapter);
+ mgmt_fe_adapter_unlock(&adapter);
+ }
+}
+
+static int
+mgmt_fe_session_handle_lockds_req_msg(struct mgmt_fe_session_ctx *session,
+ Mgmtd__FeLockDsReq *lockds_req)
+{
+ struct mgmt_ds_ctx *ds_ctx;
+
+ /*
+ * Next check first if the SET_CONFIG_REQ is for Candidate DS
+ * or not. Report failure if its not. MGMTD currently only
+ * supports editing the Candidate DS.
+ */
+ if (lockds_req->ds_id != MGMTD_DS_CANDIDATE) {
+ mgmt_fe_send_lockds_reply(
+ session, lockds_req->ds_id, lockds_req->req_id,
+ lockds_req->lock, false,
+ "Lock/Unlock on datastores other than Candidate DS not permitted!");
+ return -1;
+ }
+
+ ds_ctx =
+ mgmt_ds_get_ctx_by_id(mgmt_fe_adapter_mm, lockds_req->ds_id);
+ if (!ds_ctx) {
+ mgmt_fe_send_lockds_reply(
+ session, lockds_req->ds_id, lockds_req->req_id,
+ lockds_req->lock, false,
+ "Failed to retrieve handle for DS!");
+ return -1;
+ }
+
+ if (lockds_req->lock) {
+ if (mgmt_fe_session_write_lock_ds(lockds_req->ds_id,
+ ds_ctx, session)
+ != 0) {
+ mgmt_fe_send_lockds_reply(
+ session, lockds_req->ds_id, lockds_req->req_id,
+ lockds_req->lock, false,
+ "Lock already taken on DS by another session!");
+ return -1;
+ }
+
+ session->ds_locked_implict[lockds_req->ds_id] = false;
+ } else {
+ if (!session->ds_write_locked[lockds_req->ds_id]) {
+ mgmt_fe_send_lockds_reply(
+ session, lockds_req->ds_id, lockds_req->req_id,
+ lockds_req->lock, false,
+ "Lock on DS was not taken by this session!");
+ return 0;
+ }
+
+ (void)mgmt_fe_session_unlock_ds(lockds_req->ds_id, ds_ctx,
+ session, true, false);
+ }
+
+ if (mgmt_fe_send_lockds_reply(session, lockds_req->ds_id,
+ lockds_req->req_id, lockds_req->lock,
+ true, NULL)
+ != 0) {
+ MGMTD_FE_ADAPTER_DBG(
+ "Failed to send LOCK_DS_REPLY for DS %u Sessn: %p from %s",
+ lockds_req->ds_id, session, session->adapter->name);
+ }
+
+ return 0;
+}
+
+static int
+mgmt_fe_session_handle_setcfg_req_msg(struct mgmt_fe_session_ctx *session,
+ Mgmtd__FeSetConfigReq *setcfg_req)
+{
+ uint64_t cfg_session_id;
+ struct mgmt_ds_ctx *ds_ctx, *dst_ds_ctx;
+
+ if (mm->perf_stats_en)
+ gettimeofday(&session->adapter->setcfg_stats.last_start, NULL);
+
+ /*
+ * Next check first if the SET_CONFIG_REQ is for Candidate DS
+ * or not. Report failure if its not. MGMTD currently only
+ * supports editing the Candidate DS.
+ */
+ if (setcfg_req->ds_id != MGMTD_DS_CANDIDATE) {
+ mgmt_fe_send_setcfg_reply(
+ session, setcfg_req->ds_id, setcfg_req->req_id, false,
+ "Set-Config on datastores other than Candidate DS not permitted!",
+ setcfg_req->implicit_commit);
+ return 0;
+ }
+
+ /*
+ * Get the DS handle.
+ */
+ ds_ctx =
+ mgmt_ds_get_ctx_by_id(mgmt_fe_adapter_mm, setcfg_req->ds_id);
+ if (!ds_ctx) {
+ mgmt_fe_send_setcfg_reply(
+ session, setcfg_req->ds_id, setcfg_req->req_id, false,
+ "No such DS exists!", setcfg_req->implicit_commit);
+ return 0;
+ }
+
+ if (session->cfg_txn_id == MGMTD_TXN_ID_NONE) {
+ /*
+ * Check first if the current session can run a CONFIG
+ * transaction or not. Report failure if a CONFIG transaction
+ * from another session is already in progress.
+ */
+ cfg_session_id = mgmt_config_txn_in_progress();
+ if (cfg_session_id != MGMTD_SESSION_ID_NONE
+ && cfg_session_id != session->session_id) {
+ mgmt_fe_send_setcfg_reply(
+ session, setcfg_req->ds_id, setcfg_req->req_id,
+ false,
+ "Configuration already in-progress through a different user session!",
+ setcfg_req->implicit_commit);
+ goto mgmt_fe_sess_handle_setcfg_req_failed;
+ }
+
+
+ /*
+ * Try taking write-lock on the requested DS (if not already).
+ */
+ if (!session->ds_write_locked[setcfg_req->ds_id]) {
+ if (mgmt_fe_session_write_lock_ds(setcfg_req->ds_id,
+ ds_ctx, session)
+ != 0) {
+ mgmt_fe_send_setcfg_reply(
+ session, setcfg_req->ds_id,
+ setcfg_req->req_id, false,
+ "Failed to lock the DS!",
+ setcfg_req->implicit_commit);
+ goto mgmt_fe_sess_handle_setcfg_req_failed;
+ }
+
+ session->ds_locked_implict[setcfg_req->ds_id] = true;
+ }
+
+ /*
+ * Start a CONFIG Transaction (if not started already)
+ */
+ session->cfg_txn_id = mgmt_create_txn(session->session_id,
+ MGMTD_TXN_TYPE_CONFIG);
+ if (session->cfg_txn_id == MGMTD_SESSION_ID_NONE) {
+ mgmt_fe_send_setcfg_reply(
+ session, setcfg_req->ds_id, setcfg_req->req_id,
+ false,
+ "Failed to create a Configuration session!",
+ setcfg_req->implicit_commit);
+ goto mgmt_fe_sess_handle_setcfg_req_failed;
+ }
+
+ MGMTD_FE_ADAPTER_DBG(
+ "Created new Config Txn 0x%llx for session %p",
+ (unsigned long long)session->cfg_txn_id, session);
+ } else {
+ MGMTD_FE_ADAPTER_DBG(
+ "Config Txn 0x%llx for session %p already created",
+ (unsigned long long)session->cfg_txn_id, session);
+
+ if (setcfg_req->implicit_commit) {
+ /*
+ * In this scenario need to skip cleanup of the txn,
+ * so setting implicit commit to false.
+ */
+ mgmt_fe_send_setcfg_reply(
+ session, setcfg_req->ds_id, setcfg_req->req_id,
+ false,
+ "A Configuration transaction is already in progress!",
+ false);
+ return 0;
+ }
+ }
+
+ dst_ds_ctx = 0;
+ if (setcfg_req->implicit_commit) {
+ dst_ds_ctx = mgmt_ds_get_ctx_by_id(mgmt_fe_adapter_mm,
+ setcfg_req->commit_ds_id);
+ if (!dst_ds_ctx) {
+ mgmt_fe_send_setcfg_reply(
+ session, setcfg_req->ds_id, setcfg_req->req_id,
+ false, "No such commit DS exists!",
+ setcfg_req->implicit_commit);
+ return 0;
+ }
+ }
+
+ /*
+ * Create the SETConfig request under the transaction.
+ */
+ if (mgmt_txn_send_set_config_req(
+ session->cfg_txn_id, setcfg_req->req_id, setcfg_req->ds_id,
+ ds_ctx, setcfg_req->data, setcfg_req->n_data,
+ setcfg_req->implicit_commit, setcfg_req->commit_ds_id,
+ dst_ds_ctx)
+ != 0) {
+ mgmt_fe_send_setcfg_reply(
+ session, setcfg_req->ds_id, setcfg_req->req_id, false,
+ "Request processing for SET-CONFIG failed!",
+ setcfg_req->implicit_commit);
+ goto mgmt_fe_sess_handle_setcfg_req_failed;
+ }
+
+ return 0;
+
+mgmt_fe_sess_handle_setcfg_req_failed:
+
+ /*
+ * Delete transaction created recently.
+ */
+ if (session->cfg_txn_id != MGMTD_TXN_ID_NONE)
+ mgmt_destroy_txn(&session->cfg_txn_id);
+ if (ds_ctx && session->ds_write_locked[setcfg_req->ds_id])
+ mgmt_fe_session_unlock_ds(setcfg_req->ds_id, ds_ctx, session,
+ true, false);
+
+ return 0;
+}
+
+static int
+mgmt_fe_session_handle_getcfg_req_msg(struct mgmt_fe_session_ctx *session,
+ Mgmtd__FeGetConfigReq *getcfg_req)
+{
+ struct mgmt_ds_ctx *ds_ctx;
+
+ /*
+ * Get the DS handle.
+ */
+ ds_ctx =
+ mgmt_ds_get_ctx_by_id(mgmt_fe_adapter_mm, getcfg_req->ds_id);
+ if (!ds_ctx) {
+ mgmt_fe_send_getcfg_reply(session, getcfg_req->ds_id,
+ getcfg_req->req_id, false, NULL,
+ "No such DS exists!");
+ return 0;
+ }
+
+ /*
+ * Next check first if the SET_CONFIG_REQ is for Candidate DS
+ * or not. Report failure if its not. MGMTD currently only
+ * supports editing the Candidate DS.
+ */
+ if (getcfg_req->ds_id != MGMTD_DS_CANDIDATE
+ && getcfg_req->ds_id != MGMTD_DS_RUNNING) {
+ mgmt_fe_send_getcfg_reply(
+ session, getcfg_req->ds_id, getcfg_req->req_id, false,
+ NULL,
+ "Get-Config on datastores other than Candidate or Running DS not permitted!");
+ return 0;
+ }
+
+ if (session->txn_id == MGMTD_TXN_ID_NONE) {
+ /*
+ * Try taking read-lock on the requested DS (if not already
+ * locked). If the DS has already been write-locked by a ongoing
+ * CONFIG transaction we may allow reading the contents of the
+ * same DS.
+ */
+ if (!session->ds_read_locked[getcfg_req->ds_id]
+ && !session->ds_write_locked[getcfg_req->ds_id]) {
+ if (mgmt_fe_session_read_lock_ds(getcfg_req->ds_id,
+ ds_ctx, session)
+ != 0) {
+ mgmt_fe_send_getcfg_reply(
+ session, getcfg_req->ds_id,
+ getcfg_req->req_id, false, NULL,
+ "Failed to lock the DS! Another session might have locked it!");
+ goto mgmt_fe_sess_handle_getcfg_req_failed;
+ }
+
+ session->ds_locked_implict[getcfg_req->ds_id] = true;
+ }
+
+ /*
+ * Start a SHOW Transaction (if not started already)
+ */
+ session->txn_id = mgmt_create_txn(session->session_id,
+ MGMTD_TXN_TYPE_SHOW);
+ if (session->txn_id == MGMTD_SESSION_ID_NONE) {
+ mgmt_fe_send_getcfg_reply(
+ session, getcfg_req->ds_id, getcfg_req->req_id,
+ false, NULL,
+ "Failed to create a Show transaction!");
+ goto mgmt_fe_sess_handle_getcfg_req_failed;
+ }
+
+ MGMTD_FE_ADAPTER_DBG(
+ "Created new Show Txn 0x%llx for session %p",
+ (unsigned long long)session->txn_id, session);
+ } else {
+ MGMTD_FE_ADAPTER_DBG(
+ "Show Txn 0x%llx for session %p already created",
+ (unsigned long long)session->txn_id, session);
+ }
+
+ /*
+ * Create a GETConfig request under the transaction.
+ */
+ if (mgmt_txn_send_get_config_req(session->txn_id, getcfg_req->req_id,
+ getcfg_req->ds_id, ds_ctx,
+ getcfg_req->data, getcfg_req->n_data)
+ != 0) {
+ mgmt_fe_send_getcfg_reply(
+ session, getcfg_req->ds_id, getcfg_req->req_id, false,
+ NULL, "Request processing for GET-CONFIG failed!");
+ goto mgmt_fe_sess_handle_getcfg_req_failed;
+ }
+
+ return 0;
+
+mgmt_fe_sess_handle_getcfg_req_failed:
+
+ /*
+ * Destroy the transaction created recently.
+ */
+ if (session->txn_id != MGMTD_TXN_ID_NONE)
+ mgmt_destroy_txn(&session->txn_id);
+ if (ds_ctx && session->ds_read_locked[getcfg_req->ds_id])
+ mgmt_fe_session_unlock_ds(getcfg_req->ds_id, ds_ctx, session,
+ false, true);
+
+ return -1;
+}
+
+static int
+mgmt_fe_session_handle_getdata_req_msg(struct mgmt_fe_session_ctx *session,
+ Mgmtd__FeGetDataReq *getdata_req)
+{
+ struct mgmt_ds_ctx *ds_ctx;
+
+ /*
+ * Get the DS handle.
+ */
+ ds_ctx = mgmt_ds_get_ctx_by_id(mgmt_fe_adapter_mm,
+ getdata_req->ds_id);
+ if (!ds_ctx) {
+ mgmt_fe_send_getdata_reply(session, getdata_req->ds_id,
+ getdata_req->req_id, false, NULL,
+ "No such DS exists!");
+ return 0;
+ }
+
+ if (session->txn_id == MGMTD_TXN_ID_NONE) {
+ /*
+ * Try taking read-lock on the requested DS (if not already
+ * locked). If the DS has already been write-locked by a ongoing
+ * CONFIG transaction we may allow reading the contents of the
+ * same DS.
+ */
+ if (!session->ds_read_locked[getdata_req->ds_id]
+ && !session->ds_write_locked[getdata_req->ds_id]) {
+ if (mgmt_fe_session_read_lock_ds(getdata_req->ds_id,
+ ds_ctx, session)
+ != 0) {
+ mgmt_fe_send_getdata_reply(
+ session, getdata_req->ds_id,
+ getdata_req->req_id, false, NULL,
+ "Failed to lock the DS! Another session might have locked it!");
+ goto mgmt_fe_sess_handle_getdata_req_failed;
+ }
+
+ session->ds_locked_implict[getdata_req->ds_id] = true;
+ }
+
+ /*
+ * Start a SHOW Transaction (if not started already)
+ */
+ session->txn_id = mgmt_create_txn(session->session_id,
+ MGMTD_TXN_TYPE_SHOW);
+ if (session->txn_id == MGMTD_SESSION_ID_NONE) {
+ mgmt_fe_send_getdata_reply(
+ session, getdata_req->ds_id, getdata_req->req_id,
+ false, NULL,
+ "Failed to create a Show transaction!");
+ goto mgmt_fe_sess_handle_getdata_req_failed;
+ }
+
+ MGMTD_FE_ADAPTER_DBG(
+ "Created new Show Txn 0x%llx for session %p",
+ (unsigned long long)session->txn_id, session);
+ } else {
+ MGMTD_FE_ADAPTER_DBG(
+ "Show Txn 0x%llx for session %p already created",
+ (unsigned long long)session->txn_id, session);
+ }
+
+ /*
+ * Create a GETData request under the transaction.
+ */
+ if (mgmt_txn_send_get_data_req(session->txn_id, getdata_req->req_id,
+ getdata_req->ds_id, ds_ctx,
+ getdata_req->data, getdata_req->n_data)
+ != 0) {
+ mgmt_fe_send_getdata_reply(
+ session, getdata_req->ds_id, getdata_req->req_id, false,
+ NULL, "Request processing for GET-CONFIG failed!");
+ goto mgmt_fe_sess_handle_getdata_req_failed;
+ }
+
+ return 0;
+
+mgmt_fe_sess_handle_getdata_req_failed:
+
+ /*
+ * Destroy the transaction created recently.
+ */
+ if (session->txn_id != MGMTD_TXN_ID_NONE)
+ mgmt_destroy_txn(&session->txn_id);
+
+ if (ds_ctx && session->ds_read_locked[getdata_req->ds_id])
+ mgmt_fe_session_unlock_ds(getdata_req->ds_id, ds_ctx,
+ session, false, true);
+
+ return -1;
+}
+
+static int mgmt_fe_session_handle_commit_config_req_msg(
+ struct mgmt_fe_session_ctx *session,
+ Mgmtd__FeCommitConfigReq *commcfg_req)
+{
+ struct mgmt_ds_ctx *src_ds_ctx, *dst_ds_ctx;
+
+ if (mm->perf_stats_en)
+ gettimeofday(&session->adapter->cmt_stats.last_start, NULL);
+ session->adapter->cmt_stats.commit_cnt++;
+ /*
+ * Get the source DS handle.
+ */
+ src_ds_ctx = mgmt_ds_get_ctx_by_id(mgmt_fe_adapter_mm,
+ commcfg_req->src_ds_id);
+ if (!src_ds_ctx) {
+ mgmt_fe_send_commitcfg_reply(
+ session, commcfg_req->src_ds_id, commcfg_req->dst_ds_id,
+ commcfg_req->req_id, MGMTD_INTERNAL_ERROR,
+ commcfg_req->validate_only,
+ "No such source DS exists!");
+ return 0;
+ }
+
+ /*
+ * Get the destination DS handle.
+ */
+ dst_ds_ctx = mgmt_ds_get_ctx_by_id(mgmt_fe_adapter_mm,
+ commcfg_req->dst_ds_id);
+ if (!dst_ds_ctx) {
+ mgmt_fe_send_commitcfg_reply(
+ session, commcfg_req->src_ds_id, commcfg_req->dst_ds_id,
+ commcfg_req->req_id, MGMTD_INTERNAL_ERROR,
+ commcfg_req->validate_only,
+ "No such destination DS exists!");
+ return 0;
+ }
+
+ /*
+ * Next check first if the SET_CONFIG_REQ is for Candidate DS
+ * or not. Report failure if its not. MGMTD currently only
+ * supports editing the Candidate DS.
+ */
+ if (commcfg_req->dst_ds_id != MGMTD_DS_RUNNING) {
+ mgmt_fe_send_commitcfg_reply(
+ session, commcfg_req->src_ds_id, commcfg_req->dst_ds_id,
+ commcfg_req->req_id, MGMTD_INTERNAL_ERROR,
+ commcfg_req->validate_only,
+ "Set-Config on datastores other than Running DS not permitted!");
+ return 0;
+ }
+
+ if (session->cfg_txn_id == MGMTD_TXN_ID_NONE) {
+ /*
+ * Start a CONFIG Transaction (if not started already)
+ */
+ session->cfg_txn_id = mgmt_create_txn(session->session_id,
+ MGMTD_TXN_TYPE_CONFIG);
+ if (session->cfg_txn_id == MGMTD_SESSION_ID_NONE) {
+ mgmt_fe_send_commitcfg_reply(
+ session, commcfg_req->src_ds_id,
+ commcfg_req->dst_ds_id, commcfg_req->req_id,
+ MGMTD_INTERNAL_ERROR,
+ commcfg_req->validate_only,
+ "Failed to create a Configuration session!");
+ return 0;
+ }
+ MGMTD_FE_ADAPTER_DBG("Created txn %" PRIu64
+ " for session %" PRIu64
+ " for COMMIT-CFG-REQ",
+ session->cfg_txn_id, session->session_id);
+ }
+
+
+ /*
+ * Try taking write-lock on the destination DS (if not already).
+ */
+ if (!session->ds_write_locked[commcfg_req->dst_ds_id]) {
+ if (mgmt_fe_session_write_lock_ds(commcfg_req->dst_ds_id,
+ dst_ds_ctx, session)
+ != 0) {
+ mgmt_fe_send_commitcfg_reply(
+ session, commcfg_req->src_ds_id,
+ commcfg_req->dst_ds_id, commcfg_req->req_id,
+ MGMTD_DS_LOCK_FAILED,
+ commcfg_req->validate_only,
+ "Failed to lock the destination DS!");
+ return 0;
+ }
+
+ session->ds_locked_implict[commcfg_req->dst_ds_id] = true;
+ }
+
+ /*
+ * Create COMMITConfig request under the transaction
+ */
+ if (mgmt_txn_send_commit_config_req(
+ session->cfg_txn_id, commcfg_req->req_id,
+ commcfg_req->src_ds_id, src_ds_ctx, commcfg_req->dst_ds_id,
+ dst_ds_ctx, commcfg_req->validate_only, commcfg_req->abort,
+ false)
+ != 0) {
+ mgmt_fe_send_commitcfg_reply(
+ session, commcfg_req->src_ds_id, commcfg_req->dst_ds_id,
+ commcfg_req->req_id, MGMTD_INTERNAL_ERROR,
+ commcfg_req->validate_only,
+ "Request processing for COMMIT-CONFIG failed!");
+ return 0;
+ }
+
+ return 0;
+}
+
+static int
+mgmt_fe_adapter_handle_msg(struct mgmt_fe_client_adapter *adapter,
+ Mgmtd__FeMessage *fe_msg)
+{
+ struct mgmt_fe_session_ctx *session;
+
+ /*
+ * protobuf-c adds a max size enum with an internal, and changing by
+ * version, name; cast to an int to avoid unhandled enum warnings
+ */
+ switch ((int)fe_msg->message_case) {
+ case MGMTD__FE_MESSAGE__MESSAGE_REGISTER_REQ:
+ MGMTD_FE_ADAPTER_DBG("Got Register Req Msg from '%s'",
+ fe_msg->register_req->client_name);
+
+ if (strlen(fe_msg->register_req->client_name)) {
+ strlcpy(adapter->name,
+ fe_msg->register_req->client_name,
+ sizeof(adapter->name));
+ mgmt_fe_adapter_cleanup_old_conn(adapter);
+ }
+ break;
+ case MGMTD__FE_MESSAGE__MESSAGE_SESSION_REQ:
+ if (fe_msg->session_req->create
+ && fe_msg->session_req->id_case
+ == MGMTD__FE_SESSION_REQ__ID_CLIENT_CONN_ID) {
+ MGMTD_FE_ADAPTER_DBG(
+ "Got Session Create Req Msg for client-id %llu from '%s'",
+ (unsigned long long)
+ fe_msg->session_req->client_conn_id,
+ adapter->name);
+
+ session = mgmt_fe_create_session(
+ adapter, fe_msg->session_req->client_conn_id);
+ mgmt_fe_send_session_reply(adapter, session, true,
+ session ? true : false);
+ } else if (
+ !fe_msg->session_req->create
+ && fe_msg->session_req->id_case
+ == MGMTD__FE_SESSION_REQ__ID_SESSION_ID) {
+ MGMTD_FE_ADAPTER_DBG(
+ "Got Session Destroy Req Msg for session-id %llu from '%s'",
+ (unsigned long long)
+ fe_msg->session_req->session_id,
+ adapter->name);
+
+ session = mgmt_session_id2ctx(
+ fe_msg->session_req->session_id);
+ mgmt_fe_send_session_reply(adapter, session, false,
+ true);
+ mgmt_fe_cleanup_session(&session);
+ }
+ break;
+ case MGMTD__FE_MESSAGE__MESSAGE_LOCKDS_REQ:
+ session = mgmt_session_id2ctx(
+ fe_msg->lockds_req->session_id);
+ MGMTD_FE_ADAPTER_DBG(
+ "Got %sockDS Req Msg for DS:%d for session-id %llx from '%s'",
+ fe_msg->lockds_req->lock ? "L" : "Unl",
+ fe_msg->lockds_req->ds_id,
+ (unsigned long long)fe_msg->lockds_req->session_id,
+ adapter->name);
+ mgmt_fe_session_handle_lockds_req_msg(
+ session, fe_msg->lockds_req);
+ break;
+ case MGMTD__FE_MESSAGE__MESSAGE_SETCFG_REQ:
+ session = mgmt_session_id2ctx(
+ fe_msg->setcfg_req->session_id);
+ session->adapter->setcfg_stats.set_cfg_count++;
+ MGMTD_FE_ADAPTER_DBG(
+ "Got Set Config Req Msg (%d Xpaths, Implicit:%c) on DS:%d for session-id %llu from '%s'",
+ (int)fe_msg->setcfg_req->n_data,
+ fe_msg->setcfg_req->implicit_commit ? 'T':'F',
+ fe_msg->setcfg_req->ds_id,
+ (unsigned long long)fe_msg->setcfg_req->session_id,
+ adapter->name);
+
+ mgmt_fe_session_handle_setcfg_req_msg(
+ session, fe_msg->setcfg_req);
+ break;
+ case MGMTD__FE_MESSAGE__MESSAGE_COMMCFG_REQ:
+ session = mgmt_session_id2ctx(
+ fe_msg->commcfg_req->session_id);
+ MGMTD_FE_ADAPTER_DBG(
+ "Got Commit Config Req Msg for src-DS:%d dst-DS:%d (Abort:%c) on session-id %llu from '%s'",
+ fe_msg->commcfg_req->src_ds_id,
+ fe_msg->commcfg_req->dst_ds_id,
+ fe_msg->commcfg_req->abort ? 'T':'F',
+ (unsigned long long)fe_msg->commcfg_req->session_id,
+ adapter->name);
+ mgmt_fe_session_handle_commit_config_req_msg(
+ session, fe_msg->commcfg_req);
+ break;
+ case MGMTD__FE_MESSAGE__MESSAGE_GETCFG_REQ:
+ session = mgmt_session_id2ctx(
+ fe_msg->getcfg_req->session_id);
+ MGMTD_FE_ADAPTER_DBG(
+ "Got Get-Config Req Msg for DS:%d (xpaths: %d) on session-id %llu from '%s'",
+ fe_msg->getcfg_req->ds_id,
+ (int)fe_msg->getcfg_req->n_data,
+ (unsigned long long)fe_msg->getcfg_req->session_id,
+ adapter->name);
+ mgmt_fe_session_handle_getcfg_req_msg(
+ session, fe_msg->getcfg_req);
+ break;
+ case MGMTD__FE_MESSAGE__MESSAGE_GETDATA_REQ:
+ session = mgmt_session_id2ctx(
+ fe_msg->getdata_req->session_id);
+ MGMTD_FE_ADAPTER_DBG(
+ "Got Get-Data Req Msg for DS:%d (xpaths: %d) on session-id %llu from '%s'",
+ fe_msg->getdata_req->ds_id,
+ (int)fe_msg->getdata_req->n_data,
+ (unsigned long long)fe_msg->getdata_req->session_id,
+ adapter->name);
+ mgmt_fe_session_handle_getdata_req_msg(
+ session, fe_msg->getdata_req);
+ break;
+ case MGMTD__FE_MESSAGE__MESSAGE_NOTIFY_DATA_REQ:
+ case MGMTD__FE_MESSAGE__MESSAGE_REGNOTIFY_REQ:
+ /*
+ * TODO: Add handling code in future.
+ */
+ break;
+ /*
+ * NOTE: The following messages are always sent from MGMTD to
+ * Frontend clients only and/or need not be handled on MGMTd.
+ */
+ case MGMTD__FE_MESSAGE__MESSAGE_SESSION_REPLY:
+ case MGMTD__FE_MESSAGE__MESSAGE_LOCKDS_REPLY:
+ case MGMTD__FE_MESSAGE__MESSAGE_SETCFG_REPLY:
+ case MGMTD__FE_MESSAGE__MESSAGE_COMMCFG_REPLY:
+ case MGMTD__FE_MESSAGE__MESSAGE_GETCFG_REPLY:
+ case MGMTD__FE_MESSAGE__MESSAGE_GETDATA_REPLY:
+ case MGMTD__FE_MESSAGE__MESSAGE__NOT_SET:
+ default:
+ /*
+ * A 'default' case is being added contrary to the
+ * FRR code guidelines to take care of build
+ * failures on certain build systems (courtesy of
+ * the proto-c package).
+ */
+ break;
+ }
+
+ return 0;
+}
+
+static void mgmt_fe_adapter_process_msg(void *user_ctx, uint8_t *data,
+ size_t len)
+{
+ struct mgmt_fe_client_adapter *adapter = user_ctx;
+ Mgmtd__FeMessage *fe_msg;
+
+ fe_msg = mgmtd__fe_message__unpack(NULL, len, data);
+ if (!fe_msg) {
+ MGMTD_FE_ADAPTER_DBG(
+ "Failed to decode %zu bytes for adapter: %s", len,
+ adapter->name);
+ return;
+ }
+ MGMTD_FE_ADAPTER_DBG(
+ "Decoded %zu bytes of message: %u from adapter: %s", len,
+ fe_msg->message_case, adapter->name);
+ (void)mgmt_fe_adapter_handle_msg(adapter, fe_msg);
+ mgmtd__fe_message__free_unpacked(fe_msg, NULL);
+}
+
+static void mgmt_fe_adapter_proc_msgbufs(struct event *thread)
+{
+ struct mgmt_fe_client_adapter *adapter = EVENT_ARG(thread);
+
+ if (mgmt_msg_procbufs(&adapter->mstate, mgmt_fe_adapter_process_msg,
+ adapter, mgmt_debug_fe))
+ mgmt_fe_adapter_register_event(adapter, MGMTD_FE_PROC_MSG);
+}
+
+static void mgmt_fe_adapter_read(struct event *thread)
+{
+ struct mgmt_fe_client_adapter *adapter = EVENT_ARG(thread);
+ enum mgmt_msg_rsched rv;
+
+ rv = mgmt_msg_read(&adapter->mstate, adapter->conn_fd, mgmt_debug_fe);
+ if (rv == MSR_DISCONNECT) {
+ mgmt_fe_adapter_disconnect(adapter);
+ return;
+ }
+ if (rv == MSR_SCHED_BOTH)
+ mgmt_fe_adapter_register_event(adapter, MGMTD_FE_PROC_MSG);
+ mgmt_fe_adapter_register_event(adapter, MGMTD_FE_CONN_READ);
+}
+
+static void mgmt_fe_adapter_write(struct event *thread)
+{
+ struct mgmt_fe_client_adapter *adapter = EVENT_ARG(thread);
+ enum mgmt_msg_wsched rv;
+
+ rv = mgmt_msg_write(&adapter->mstate, adapter->conn_fd, mgmt_debug_fe);
+ if (rv == MSW_SCHED_STREAM)
+ mgmt_fe_adapter_register_event(adapter, MGMTD_FE_CONN_WRITE);
+ else if (rv == MSW_DISCONNECT)
+ mgmt_fe_adapter_disconnect(adapter);
+ else if (rv == MSW_SCHED_WRITES_OFF) {
+ mgmt_fe_adapter_writes_off(adapter);
+ mgmt_fe_adapter_register_event(adapter,
+ MGMTD_FE_CONN_WRITES_ON);
+ } else
+ assert(rv == MSW_SCHED_NONE);
+}
+
+static void mgmt_fe_adapter_resume_writes(struct event *thread)
+{
+ struct mgmt_fe_client_adapter *adapter;
+
+ adapter = (struct mgmt_fe_client_adapter *)EVENT_ARG(thread);
+ assert(adapter && adapter->conn_fd != -1);
+
+ mgmt_fe_adapter_writes_on(adapter);
+}
+
+static void
+mgmt_fe_adapter_register_event(struct mgmt_fe_client_adapter *adapter,
+ enum mgmt_fe_event event)
+{
+ struct timeval tv = {0};
+
+ switch (event) {
+ case MGMTD_FE_CONN_READ:
+ event_add_read(mgmt_fe_adapter_tm, mgmt_fe_adapter_read,
+ adapter, adapter->conn_fd, &adapter->conn_read_ev);
+ break;
+ case MGMTD_FE_CONN_WRITE:
+ event_add_write(mgmt_fe_adapter_tm,
+ mgmt_fe_adapter_write, adapter,
+ adapter->conn_fd, &adapter->conn_write_ev);
+ break;
+ case MGMTD_FE_PROC_MSG:
+ tv.tv_usec = MGMTD_FE_MSG_PROC_DELAY_USEC;
+ event_add_timer_tv(mgmt_fe_adapter_tm,
+ mgmt_fe_adapter_proc_msgbufs, adapter,
+ &tv, &adapter->proc_msg_ev);
+ break;
+ case MGMTD_FE_CONN_WRITES_ON:
+ event_add_timer_msec(mgmt_fe_adapter_tm,
+ mgmt_fe_adapter_resume_writes, adapter,
+ MGMTD_FE_MSG_WRITE_DELAY_MSEC,
+ &adapter->conn_writes_on);
+ break;
+ case MGMTD_FE_SERVER:
+ assert(!"mgmt_fe_adapter_post_event() called incorrectly");
+ break;
+ }
+}
+
+void mgmt_fe_adapter_lock(struct mgmt_fe_client_adapter *adapter)
+{
+ adapter->refcount++;
+}
+
+extern void
+mgmt_fe_adapter_unlock(struct mgmt_fe_client_adapter **adapter)
+{
+ assert(*adapter && (*adapter)->refcount);
+
+ (*adapter)->refcount--;
+ if (!(*adapter)->refcount) {
+ mgmt_fe_adapters_del(&mgmt_fe_adapters, *adapter);
+ EVENT_OFF((*adapter)->conn_read_ev);
+ EVENT_OFF((*adapter)->conn_write_ev);
+ EVENT_OFF((*adapter)->proc_msg_ev);
+ EVENT_OFF((*adapter)->conn_writes_on);
+ mgmt_msg_destroy(&(*adapter)->mstate);
+ XFREE(MTYPE_MGMTD_FE_ADPATER, *adapter);
+ }
+
+ *adapter = NULL;
+}
+
+int mgmt_fe_adapter_init(struct event_loop *tm, struct mgmt_master *mm)
+{
+ if (!mgmt_fe_adapter_tm) {
+ mgmt_fe_adapter_tm = tm;
+ mgmt_fe_adapter_mm = mm;
+ mgmt_fe_adapters_init(&mgmt_fe_adapters);
+
+ assert(!mgmt_fe_sessions);
+ mgmt_fe_sessions = hash_create(mgmt_fe_session_hash_key,
+ mgmt_fe_session_hash_cmp,
+ "MGMT Frontend Sessions");
+ }
+
+ return 0;
+}
+
+void mgmt_fe_adapter_destroy(void)
+{
+ mgmt_fe_cleanup_adapters();
+ mgmt_fe_session_hash_destroy();
+}
+
+struct mgmt_fe_client_adapter *
+mgmt_fe_create_adapter(int conn_fd, union sockunion *from)
+{
+ struct mgmt_fe_client_adapter *adapter = NULL;
+
+ adapter = mgmt_fe_find_adapter_by_fd(conn_fd);
+ if (!adapter) {
+ adapter = XCALLOC(MTYPE_MGMTD_FE_ADPATER,
+ sizeof(struct mgmt_fe_client_adapter));
+ assert(adapter);
+
+ adapter->conn_fd = conn_fd;
+ memcpy(&adapter->conn_su, from, sizeof(adapter->conn_su));
+ snprintf(adapter->name, sizeof(adapter->name), "Unknown-FD-%d",
+ adapter->conn_fd);
+ mgmt_fe_sessions_init(&adapter->fe_sessions);
+
+ mgmt_msg_init(&adapter->mstate, MGMTD_FE_MAX_NUM_MSG_PROC,
+ MGMTD_FE_MAX_NUM_MSG_WRITE, MGMTD_FE_MSG_MAX_LEN,
+ "FE-adapter");
+ mgmt_fe_adapter_lock(adapter);
+
+ mgmt_fe_adapter_register_event(adapter, MGMTD_FE_CONN_READ);
+ mgmt_fe_adapters_add_tail(&mgmt_fe_adapters, adapter);
+
+ adapter->setcfg_stats.min_tm = ULONG_MAX;
+ adapter->cmt_stats.min_tm = ULONG_MAX;
+ MGMTD_FE_ADAPTER_DBG("Added new MGMTD Frontend adapter '%s'",
+ adapter->name);
+ }
+
+ /* Make client socket non-blocking. */
+ set_nonblocking(adapter->conn_fd);
+ setsockopt_so_sendbuf(adapter->conn_fd,
+ MGMTD_SOCKET_FE_SEND_BUF_SIZE);
+ setsockopt_so_recvbuf(adapter->conn_fd,
+ MGMTD_SOCKET_FE_RECV_BUF_SIZE);
+ return adapter;
+}
+
+struct mgmt_fe_client_adapter *mgmt_fe_get_adapter(const char *name)
+{
+ return mgmt_fe_find_adapter_by_name(name);
+}
+
+int mgmt_fe_send_set_cfg_reply(uint64_t session_id, uint64_t txn_id,
+ Mgmtd__DatastoreId ds_id, uint64_t req_id,
+ enum mgmt_result result,
+ const char *error_if_any,
+ bool implicit_commit)
+{
+ struct mgmt_fe_session_ctx *session;
+
+ session = mgmt_session_id2ctx(session_id);
+ if (!session || session->cfg_txn_id != txn_id) {
+ if (session)
+ MGMTD_FE_ADAPTER_ERR(
+ "Txn_id doesnot match, session txn is 0x%llx, current txn 0x%llx",
+ (unsigned long long)session->cfg_txn_id,
+ (unsigned long long)txn_id);
+ return -1;
+ }
+
+ return mgmt_fe_send_setcfg_reply(
+ session, ds_id, req_id, result == MGMTD_SUCCESS ? true : false,
+ error_if_any, implicit_commit);
+}
+
+int mgmt_fe_send_commit_cfg_reply(uint64_t session_id, uint64_t txn_id,
+ Mgmtd__DatastoreId src_ds_id,
+ Mgmtd__DatastoreId dst_ds_id,
+ uint64_t req_id, bool validate_only,
+ enum mgmt_result result,
+ const char *error_if_any)
+{
+ struct mgmt_fe_session_ctx *session;
+
+ session = mgmt_session_id2ctx(session_id);
+ if (!session || session->cfg_txn_id != txn_id)
+ return -1;
+
+ return mgmt_fe_send_commitcfg_reply(session, src_ds_id, dst_ds_id,
+ req_id, result, validate_only,
+ error_if_any);
+}
+
+int mgmt_fe_send_get_cfg_reply(uint64_t session_id, uint64_t txn_id,
+ Mgmtd__DatastoreId ds_id, uint64_t req_id,
+ enum mgmt_result result,
+ Mgmtd__YangDataReply *data_resp,
+ const char *error_if_any)
+{
+ struct mgmt_fe_session_ctx *session;
+
+ session = mgmt_session_id2ctx(session_id);
+ if (!session || session->txn_id != txn_id)
+ return -1;
+
+ return mgmt_fe_send_getcfg_reply(session, ds_id, req_id,
+ result == MGMTD_SUCCESS, data_resp,
+ error_if_any);
+}
+
+int mgmt_fe_send_get_data_reply(uint64_t session_id, uint64_t txn_id,
+ Mgmtd__DatastoreId ds_id, uint64_t req_id,
+ enum mgmt_result result,
+ Mgmtd__YangDataReply *data_resp,
+ const char *error_if_any)
+{
+ struct mgmt_fe_session_ctx *session;
+
+ session = mgmt_session_id2ctx(session_id);
+ if (!session || session->txn_id != txn_id)
+ return -1;
+
+ return mgmt_fe_send_getdata_reply(session, ds_id, req_id,
+ result == MGMTD_SUCCESS,
+ data_resp, error_if_any);
+}
+
+int mgmt_fe_send_data_notify(Mgmtd__DatastoreId ds_id,
+ Mgmtd__YangData * data_resp[], int num_data)
+{
+ /* struct mgmt_fe_session_ctx *session; */
+
+ return 0;
+}
+
+struct mgmt_setcfg_stats *
+mgmt_fe_get_session_setcfg_stats(uint64_t session_id)
+{
+ struct mgmt_fe_session_ctx *session;
+
+ session = mgmt_session_id2ctx(session_id);
+ if (!session || !session->adapter)
+ return NULL;
+
+ return &session->adapter->setcfg_stats;
+}
+
+struct mgmt_commit_stats *
+mgmt_fe_get_session_commit_stats(uint64_t session_id)
+{
+ struct mgmt_fe_session_ctx *session;
+
+ session = mgmt_session_id2ctx(session_id);
+ if (!session || !session->adapter)
+ return NULL;
+
+ return &session->adapter->cmt_stats;
+}
+
+static void
+mgmt_fe_adapter_cmt_stats_write(struct vty *vty,
+ struct mgmt_fe_client_adapter *adapter)
+{
+ char buf[100] = {0};
+
+ if (!mm->perf_stats_en)
+ return;
+
+ vty_out(vty, " Num-Commits: \t\t\t%lu\n",
+ adapter->cmt_stats.commit_cnt);
+ if (adapter->cmt_stats.commit_cnt > 0) {
+ if (mm->perf_stats_en)
+ vty_out(vty, " Max-Commit-Duration: \t\t%lu uSecs\n",
+ adapter->cmt_stats.max_tm);
+ vty_out(vty, " Max-Commit-Batch-Size: \t\t%lu\n",
+ adapter->cmt_stats.max_batch_cnt);
+ if (mm->perf_stats_en)
+ vty_out(vty, " Min-Commit-Duration: \t\t%lu uSecs\n",
+ adapter->cmt_stats.min_tm);
+ vty_out(vty, " Min-Commit-Batch-Size: \t\t%lu\n",
+ adapter->cmt_stats.min_batch_cnt);
+ if (mm->perf_stats_en)
+ vty_out(vty,
+ " Last-Commit-Duration: \t\t%lu uSecs\n",
+ adapter->cmt_stats.last_exec_tm);
+ vty_out(vty, " Last-Commit-Batch-Size: \t\t%lu\n",
+ adapter->cmt_stats.last_batch_cnt);
+ vty_out(vty, " Last-Commit-CfgData-Reqs: \t\t%lu\n",
+ adapter->cmt_stats.last_num_cfgdata_reqs);
+ vty_out(vty, " Last-Commit-CfgApply-Reqs: \t\t%lu\n",
+ adapter->cmt_stats.last_num_apply_reqs);
+ if (mm->perf_stats_en) {
+ vty_out(vty, " Last-Commit-Details:\n");
+ vty_out(vty, " Commit Start: \t\t\t%s\n",
+ mgmt_realtime_to_string(
+ &adapter->cmt_stats.last_start, buf,
+ sizeof(buf)));
+#ifdef MGMTD_LOCAL_VALIDATIONS_ENABLED
+ vty_out(vty, " Config-Validate Start: \t\t%s\n",
+ mgmt_realtime_to_string(
+ &adapter->cmt_stats.validate_start, buf,
+ sizeof(buf)));
+#endif
+ vty_out(vty, " Prep-Config Start: \t\t%s\n",
+ mgmt_realtime_to_string(
+ &adapter->cmt_stats.prep_cfg_start, buf,
+ sizeof(buf)));
+ vty_out(vty, " Txn-Create Start: \t\t%s\n",
+ mgmt_realtime_to_string(
+ &adapter->cmt_stats.txn_create_start,
+ buf, sizeof(buf)));
+ vty_out(vty,
+#ifdef MGMTD_LOCAL_VALIDATIONS_ENABLED
+ " Send-Config Start: \t\t%s\n",
+#else
+ " Send-Config-Validate Start: \t%s\n",
+#endif
+ mgmt_realtime_to_string(
+ &adapter->cmt_stats.send_cfg_start, buf,
+ sizeof(buf)));
+ vty_out(vty, " Apply-Config Start: \t\t%s\n",
+ mgmt_realtime_to_string(
+ &adapter->cmt_stats.apply_cfg_start, buf,
+ sizeof(buf)));
+ vty_out(vty, " Apply-Config End: \t\t%s\n",
+ mgmt_realtime_to_string(
+ &adapter->cmt_stats.apply_cfg_end, buf,
+ sizeof(buf)));
+ vty_out(vty, " Txn-Delete Start: \t\t%s\n",
+ mgmt_realtime_to_string(
+ &adapter->cmt_stats.txn_del_start, buf,
+ sizeof(buf)));
+ vty_out(vty, " Commit End: \t\t\t%s\n",
+ mgmt_realtime_to_string(
+ &adapter->cmt_stats.last_end, buf,
+ sizeof(buf)));
+ }
+ }
+}
+
+static void
+mgmt_fe_adapter_setcfg_stats_write(struct vty *vty,
+ struct mgmt_fe_client_adapter *adapter)
+{
+ char buf[100] = {0};
+
+ if (!mm->perf_stats_en)
+ return;
+
+ vty_out(vty, " Num-Set-Cfg: \t\t\t%lu\n",
+ adapter->setcfg_stats.set_cfg_count);
+ if (mm->perf_stats_en && adapter->setcfg_stats.set_cfg_count > 0) {
+ vty_out(vty, " Max-Set-Cfg-Duration: \t\t%lu uSec\n",
+ adapter->setcfg_stats.max_tm);
+ vty_out(vty, " Min-Set-Cfg-Duration: \t\t%lu uSec\n",
+ adapter->setcfg_stats.min_tm);
+ vty_out(vty, " Avg-Set-Cfg-Duration: \t\t%lu uSec\n",
+ adapter->setcfg_stats.avg_tm);
+ vty_out(vty, " Last-Set-Cfg-Details:\n");
+ vty_out(vty, " Set-Cfg Start: \t\t\t%s\n",
+ mgmt_realtime_to_string(&adapter->setcfg_stats.last_start,
+ buf, sizeof(buf)));
+ vty_out(vty, " Set-Cfg End: \t\t\t%s\n",
+ mgmt_realtime_to_string(&adapter->setcfg_stats.last_end,
+ buf, sizeof(buf)));
+ }
+}
+
+void mgmt_fe_adapter_status_write(struct vty *vty, bool detail)
+{
+ struct mgmt_fe_client_adapter *adapter;
+ struct mgmt_fe_session_ctx *session;
+ Mgmtd__DatastoreId ds_id;
+ bool locked = false;
+
+ vty_out(vty, "MGMTD Frontend Adpaters\n");
+
+ FOREACH_ADAPTER_IN_LIST (adapter) {
+ vty_out(vty, " Client: \t\t\t\t%s\n", adapter->name);
+ vty_out(vty, " Conn-FD: \t\t\t\t%d\n", adapter->conn_fd);
+ if (detail) {
+ mgmt_fe_adapter_setcfg_stats_write(vty, adapter);
+ mgmt_fe_adapter_cmt_stats_write(vty, adapter);
+ }
+ vty_out(vty, " Sessions\n");
+ FOREACH_SESSION_IN_LIST (adapter, session) {
+ vty_out(vty, " Session: \t\t\t\t%p\n", session);
+ vty_out(vty, " Client-Id: \t\t\t%llu\n",
+ (unsigned long long)session->client_id);
+ vty_out(vty, " Session-Id: \t\t\t%llx\n",
+ (unsigned long long)session->session_id);
+ vty_out(vty, " DS-Locks:\n");
+ FOREACH_MGMTD_DS_ID (ds_id) {
+ if (session->ds_write_locked[ds_id]
+ || session->ds_read_locked[ds_id]) {
+ locked = true;
+ vty_out(vty,
+ " %s\t\t\t%s, %s\n",
+ mgmt_ds_id2name(ds_id),
+ session->ds_write_locked[ds_id]
+ ? "Write"
+ : "Read",
+ session->ds_locked_implict[ds_id]
+ ? "Implicit"
+ : "Explicit");
+ }
+ }
+ if (!locked)
+ vty_out(vty, " None\n");
+ }
+ vty_out(vty, " Total-Sessions: \t\t\t%d\n",
+ (int)mgmt_fe_sessions_count(&adapter->fe_sessions));
+ vty_out(vty, " Msg-Recvd: \t\t\t\t%" PRIu64 "\n",
+ adapter->mstate.nrxm);
+ vty_out(vty, " Bytes-Recvd: \t\t\t%" PRIu64 "\n",
+ adapter->mstate.nrxb);
+ vty_out(vty, " Msg-Sent: \t\t\t\t%" PRIu64 "\n",
+ adapter->mstate.ntxm);
+ vty_out(vty, " Bytes-Sent: \t\t\t%" PRIu64 "\n",
+ adapter->mstate.ntxb);
+ }
+ vty_out(vty, " Total: %d\n",
+ (int)mgmt_fe_adapters_count(&mgmt_fe_adapters));
+}
+
+void mgmt_fe_adapter_perf_measurement(struct vty *vty, bool config)
+{
+ mm->perf_stats_en = config;
+}
+
+void mgmt_fe_adapter_reset_perf_stats(struct vty *vty)
+{
+ struct mgmt_fe_client_adapter *adapter;
+ struct mgmt_fe_session_ctx *session;
+
+ FOREACH_ADAPTER_IN_LIST (adapter) {
+ memset(&adapter->setcfg_stats, 0, sizeof(adapter->setcfg_stats));
+ FOREACH_SESSION_IN_LIST (adapter, session) {
+ memset(&adapter->cmt_stats, 0, sizeof(adapter->cmt_stats));
+ }
+ }
+}
diff --git a/mgmtd/mgmt_fe_adapter.h b/mgmtd/mgmt_fe_adapter.h
new file mode 100644
index 0000000000..6f72837031
--- /dev/null
+++ b/mgmtd/mgmt_fe_adapter.h
@@ -0,0 +1,183 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * MGMTD Frontend Client Connection Adapter
+ *
+ * Copyright (C) 2021 Vmware, Inc.
+ * Pushpasis Sarkar <spushpasis@vmware.com>
+ */
+
+#ifndef _FRR_MGMTD_FE_ADAPTER_H_
+#define _FRR_MGMTD_FE_ADAPTER_H_
+
+#include "mgmt_fe_client.h"
+#include "mgmt_msg.h"
+#include "mgmtd/mgmt_defines.h"
+
+struct mgmt_fe_client_adapter;
+struct mgmt_master;
+
+struct mgmt_commit_stats {
+ struct timeval last_start;
+#ifdef MGMTD_LOCAL_VALIDATIONS_ENABLED
+ struct timeval validate_start;
+#endif
+ struct timeval prep_cfg_start;
+ struct timeval txn_create_start;
+ struct timeval send_cfg_start;
+ struct timeval apply_cfg_start;
+ struct timeval apply_cfg_end;
+ struct timeval txn_del_start;
+ struct timeval last_end;
+ unsigned long last_exec_tm;
+ unsigned long max_tm;
+ unsigned long min_tm;
+ unsigned long last_batch_cnt;
+ unsigned long last_num_cfgdata_reqs;
+ unsigned long last_num_apply_reqs;
+ unsigned long max_batch_cnt;
+ unsigned long min_batch_cnt;
+ unsigned long commit_cnt;
+};
+
+struct mgmt_setcfg_stats {
+ struct timeval last_start;
+ struct timeval last_end;
+ unsigned long last_exec_tm;
+ unsigned long max_tm;
+ unsigned long min_tm;
+ unsigned long avg_tm;
+ unsigned long set_cfg_count;
+};
+
+PREDECL_LIST(mgmt_fe_sessions);
+
+PREDECL_LIST(mgmt_fe_adapters);
+
+struct mgmt_fe_client_adapter {
+ int conn_fd;
+ union sockunion conn_su;
+ struct event *conn_read_ev;
+ struct event *conn_write_ev;
+ struct event *conn_writes_on;
+ struct event *proc_msg_ev;
+ uint32_t flags;
+
+ char name[MGMTD_CLIENT_NAME_MAX_LEN];
+
+ /* List of sessions created and being maintained for this client. */
+ struct mgmt_fe_sessions_head fe_sessions;
+
+ /* IO streams for read and write */
+ struct mgmt_msg_state mstate;
+
+ int refcount;
+ struct mgmt_commit_stats cmt_stats;
+ struct mgmt_setcfg_stats setcfg_stats;
+
+ struct mgmt_fe_adapters_item list_linkage;
+};
+
+#define MGMTD_FE_ADAPTER_FLAGS_WRITES_OFF (1U << 0)
+
+DECLARE_LIST(mgmt_fe_adapters, struct mgmt_fe_client_adapter, list_linkage);
+
+/* Initialise frontend adapter module */
+extern int mgmt_fe_adapter_init(struct event_loop *tm, struct mgmt_master *cm);
+
+/* Destroy frontend adapter module */
+extern void mgmt_fe_adapter_destroy(void);
+
+/* Acquire lock for frontend adapter */
+extern void mgmt_fe_adapter_lock(struct mgmt_fe_client_adapter *adapter);
+
+/* Remove lock from frontend adapter */
+extern void
+mgmt_fe_adapter_unlock(struct mgmt_fe_client_adapter **adapter);
+
+/* Create frontend adapter */
+extern struct mgmt_fe_client_adapter *
+mgmt_fe_create_adapter(int conn_fd, union sockunion *su);
+
+/* Fetch frontend adapter given a name */
+extern struct mgmt_fe_client_adapter *
+mgmt_fe_get_adapter(const char *name);
+
+/*
+ * Send set-config reply to the frontend client.
+ *
+ * session
+ * Unique session identifier.
+ *
+ * txn_id
+ * Unique transaction identifier.
+ *
+ * ds_id
+ * Datastore ID.
+ *
+ * req_id
+ * Config request ID.
+ *
+ * result
+ * Config request result (MGMT_*).
+ *
+ * error_if_any
+ * Buffer to store human-readable error message in case of error.
+ *
+ * implicit_commit
+ * TRUE if the commit is implicit, FALSE otherwise.
+ *
+ * Returns:
+ * 0 on success, -1 on failures.
+ */
+extern int mgmt_fe_send_set_cfg_reply(uint64_t session_id, uint64_t txn_id,
+ Mgmtd__DatastoreId ds_id,
+ uint64_t req_id,
+ enum mgmt_result result,
+ const char *error_if_any,
+ bool implcit_commit);
+
+/*
+ * Send commit-config reply to the frontend client.
+ */
+extern int mgmt_fe_send_commit_cfg_reply(
+ uint64_t session_id, uint64_t txn_id, Mgmtd__DatastoreId src_ds_id,
+ Mgmtd__DatastoreId dst_ds_id, uint64_t req_id, bool validate_only,
+ enum mgmt_result result, const char *error_if_any);
+
+/*
+ * Send get-config reply to the frontend client.
+ */
+extern int mgmt_fe_send_get_cfg_reply(uint64_t session_id, uint64_t txn_id,
+ Mgmtd__DatastoreId ds_id,
+ uint64_t req_id,
+ enum mgmt_result result,
+ Mgmtd__YangDataReply *data_resp,
+ const char *error_if_any);
+
+/*
+ * Send get-data reply to the frontend client.
+ */
+extern int mgmt_fe_send_get_data_reply(
+ uint64_t session_id, uint64_t txn_id, Mgmtd__DatastoreId ds_id,
+ uint64_t req_id, enum mgmt_result result,
+ Mgmtd__YangDataReply *data_resp, const char *error_if_any);
+
+/*
+ * Send data notify to the frontend client.
+ */
+extern int mgmt_fe_send_data_notify(Mgmtd__DatastoreId ds_id,
+ Mgmtd__YangData * data_resp[],
+ int num_data);
+
+/* Fetch frontend client session set-config stats */
+extern struct mgmt_setcfg_stats *
+mgmt_fe_get_session_setcfg_stats(uint64_t session_id);
+
+/* Fetch frontend client session commit stats */
+extern struct mgmt_commit_stats *
+mgmt_fe_get_session_commit_stats(uint64_t session_id);
+
+extern void mgmt_fe_adapter_status_write(struct vty *vty, bool detail);
+extern void mgmt_fe_adapter_perf_measurement(struct vty *vty, bool config);
+extern void mgmt_fe_adapter_reset_perf_stats(struct vty *vty);
+#endif /* _FRR_MGMTD_FE_ADAPTER_H_ */
diff --git a/mgmtd/mgmt_fe_server.c b/mgmtd/mgmt_fe_server.c
new file mode 100644
index 0000000000..6097c23aac
--- /dev/null
+++ b/mgmtd/mgmt_fe_server.c
@@ -0,0 +1,160 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * MGMTD Frontend Server
+ *
+ * Copyright (C) 2021 Vmware, Inc.
+ * Pushpasis Sarkar <spushpasis@vmware.com>
+ */
+
+#include <zebra.h>
+#include "network.h"
+#include "libfrr.h"
+#include "mgmtd/mgmt.h"
+#include "mgmtd/mgmt_fe_server.h"
+#include "mgmtd/mgmt_fe_adapter.h"
+
+#ifdef REDIRECT_DEBUG_TO_STDERR
+#define MGMTD_FE_SRVR_DBG(fmt, ...) \
+ fprintf(stderr, "%s: " fmt "\n", __func__, ##__VA_ARGS__)
+#define MGMTD_FE_SRVR_ERR(fmt, ...) \
+ fprintf(stderr, "%s: ERROR, " fmt "\n", __func__, ##__VA_ARGS__)
+#else /* REDIRECT_DEBUG_TO_STDERR */
+#define MGMTD_FE_SRVR_DBG(fmt, ...) \
+ do { \
+ if (mgmt_debug_fe) \
+ zlog_debug("%s: " fmt, __func__, ##__VA_ARGS__); \
+ } while (0)
+#define MGMTD_FE_SRVR_ERR(fmt, ...) \
+ zlog_err("%s: ERROR: " fmt, __func__, ##__VA_ARGS__)
+#endif /* REDIRECT_DEBUG_TO_STDERR */
+
+static int mgmt_fe_listen_fd = -1;
+static struct event_loop *mgmt_fe_listen_tm;
+static struct event *mgmt_fe_listen_ev;
+static void mgmt_fe_server_register_event(enum mgmt_fe_event event);
+
+static void mgmt_fe_conn_accept(struct event *thread)
+{
+ int client_conn_fd;
+ union sockunion su;
+
+ if (mgmt_fe_listen_fd < 0)
+ return;
+
+ /* We continue hearing server listen socket. */
+ mgmt_fe_server_register_event(MGMTD_FE_SERVER);
+
+ memset(&su, 0, sizeof(union sockunion));
+
+ /* We can handle IPv4 or IPv6 socket. */
+ client_conn_fd = sockunion_accept(mgmt_fe_listen_fd, &su);
+ if (client_conn_fd < 0) {
+ MGMTD_FE_SRVR_ERR(
+ "Failed to accept MGMTD Frontend client connection : %s",
+ safe_strerror(errno));
+ return;
+ }
+ set_nonblocking(client_conn_fd);
+ set_cloexec(client_conn_fd);
+
+ MGMTD_FE_SRVR_DBG("Got a new MGMTD Frontend connection");
+
+ mgmt_fe_create_adapter(client_conn_fd, &su);
+}
+
+static void mgmt_fe_server_register_event(enum mgmt_fe_event event)
+{
+ if (event == MGMTD_FE_SERVER) {
+ event_add_read(mgmt_fe_listen_tm, mgmt_fe_conn_accept,
+ NULL, mgmt_fe_listen_fd,
+ &mgmt_fe_listen_ev);
+ assert(mgmt_fe_listen_ev);
+ } else {
+ assert(!"mgmt_fe_server_post_event() called incorrectly");
+ }
+}
+
+static void mgmt_fe_server_start(const char *hostname)
+{
+ int ret;
+ int sock;
+ struct sockaddr_un addr;
+ mode_t old_mask;
+
+ /* Set umask */
+ old_mask = umask(0077);
+
+ sock = socket(AF_UNIX, SOCK_STREAM, PF_UNSPEC);
+ if (sock < 0) {
+ MGMTD_FE_SRVR_ERR("Failed to create server socket: %s",
+ safe_strerror(errno));
+ goto mgmt_fe_server_start_failed;
+ }
+
+ addr.sun_family = AF_UNIX,
+ strlcpy(addr.sun_path, MGMTD_FE_SERVER_PATH, sizeof(addr.sun_path));
+ unlink(addr.sun_path);
+ ret = bind(sock, (struct sockaddr *)&addr, sizeof(addr));
+ if (ret < 0) {
+ MGMTD_FE_SRVR_ERR(
+ "Failed to bind server socket to '%s'. Err: %s",
+ addr.sun_path, safe_strerror(errno));
+ goto mgmt_fe_server_start_failed;
+ }
+
+ ret = listen(sock, MGMTD_FE_MAX_CONN);
+ if (ret < 0) {
+ MGMTD_FE_SRVR_ERR("Failed to listen on server socket: %s",
+ safe_strerror(errno));
+ goto mgmt_fe_server_start_failed;
+ }
+
+ /* Restore umask */
+ umask(old_mask);
+
+ mgmt_fe_listen_fd = sock;
+ mgmt_fe_server_register_event(MGMTD_FE_SERVER);
+
+ MGMTD_FE_SRVR_DBG("Started MGMTD Frontend Server!");
+ return;
+
+mgmt_fe_server_start_failed:
+ if (sock)
+ close(sock);
+
+ mgmt_fe_listen_fd = -1;
+ exit(-1);
+}
+
+int mgmt_fe_server_init(struct event_loop *master)
+{
+ if (mgmt_fe_listen_tm) {
+ MGMTD_FE_SRVR_DBG("MGMTD Frontend Server already running!");
+ return 0;
+ }
+
+ mgmt_fe_listen_tm = master;
+
+ mgmt_fe_server_start("localhost");
+
+ return 0;
+}
+
+void mgmt_fe_server_destroy(void)
+{
+ if (mgmt_fe_listen_tm) {
+ MGMTD_FE_SRVR_DBG("Closing MGMTD Frontend Server!");
+
+ if (mgmt_fe_listen_ev) {
+ EVENT_OFF(mgmt_fe_listen_ev);
+ mgmt_fe_listen_ev = NULL;
+ }
+
+ if (mgmt_fe_listen_fd >= 0) {
+ close(mgmt_fe_listen_fd);
+ mgmt_fe_listen_fd = -1;
+ }
+
+ mgmt_fe_listen_tm = NULL;
+ }
+}
diff --git a/mgmtd/mgmt_fe_server.h b/mgmtd/mgmt_fe_server.h
new file mode 100644
index 0000000000..6f676ba4da
--- /dev/null
+++ b/mgmtd/mgmt_fe_server.h
@@ -0,0 +1,20 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * MGMTD Frontend Server
+ *
+ * Copyright (C) 2021 Vmware, Inc.
+ * Pushpasis Sarkar <spushpasis@vmware.com>
+ */
+
+#ifndef _FRR_MGMTD_FE_SERVER_H_
+#define _FRR_MGMTD_FE_SERVER_H_
+
+#define MGMTD_FE_MAX_CONN 32
+
+/* Initialise frontend server */
+extern int mgmt_fe_server_init(struct event_loop *master);
+
+/* Destroy frontend server */
+extern void mgmt_fe_server_destroy(void);
+
+#endif /* _FRR_MGMTD_FE_SERVER_H_ */
diff --git a/mgmtd/mgmt_history.c b/mgmtd/mgmt_history.c
new file mode 100644
index 0000000000..6f9f2dd63f
--- /dev/null
+++ b/mgmtd/mgmt_history.c
@@ -0,0 +1,380 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2021 Vmware, Inc.
+ * Pushpasis Sarkar <spushpasis@vmware.com>
+ * Copyright (c) 2023, LabN Consulting, L.L.C.
+ */
+
+#include <zebra.h>
+#include "md5.h"
+#include "frrevent.h"
+#include "xref.h"
+
+#include "mgmt_fe_client.h"
+#include "mgmtd/mgmt.h"
+#include "mgmtd/mgmt_ds.h"
+#include "mgmtd/mgmt_history.h"
+
+struct mgmt_cmt_info_t {
+ struct mgmt_cmt_infos_item cmts;
+
+ char cmtid_str[MGMTD_MD5_HASH_STR_HEX_LEN];
+ char time_str[MGMTD_COMMIT_TIME_STR_LEN];
+ char cmt_json_file[PATH_MAX];
+};
+
+
+DECLARE_DLIST(mgmt_cmt_infos, struct mgmt_cmt_info_t, cmts);
+
+#define FOREACH_CMT_REC(mm, cmt_info) \
+ frr_each_safe (mgmt_cmt_infos, &mm->cmts, cmt_info)
+
+/*
+ * The only instance of VTY session that has triggered an ongoing
+ * config rollback operation.
+ */
+static struct vty *rollback_vty = NULL;
+
+static bool mgmt_history_record_exists(char *file_path)
+{
+ int exist;
+
+ exist = access(file_path, F_OK);
+ if (exist == 0)
+ return true;
+ else
+ return false;
+}
+
+static void mgmt_history_remove_file(char *name)
+{
+ if (remove(name) == 0)
+ zlog_debug("Old commit info deletion succeeded");
+ else
+ zlog_err("Old commit info deletion failed");
+}
+
+static void mgmt_history_hash(const char *input_str, char *hash)
+{
+ int i;
+ unsigned char digest[MGMTD_MD5_HASH_LEN];
+ MD5_CTX ctx;
+
+ memset(&ctx, 0, sizeof(ctx));
+ MD5Init(&ctx);
+ MD5Update(&ctx, input_str, strlen(input_str));
+ MD5Final(digest, &ctx);
+
+ for (i = 0; i < MGMTD_MD5_HASH_LEN; i++)
+ snprintf(&hash[i * 2], MGMTD_MD5_HASH_STR_HEX_LEN, "%02x",
+ (unsigned int)digest[i]);
+}
+
+static struct mgmt_cmt_info_t *mgmt_history_create_cmt_rec(void)
+{
+ struct mgmt_cmt_info_t *new;
+ struct mgmt_cmt_info_t *cmt_info;
+ struct mgmt_cmt_info_t *last_cmt_info = NULL;
+ struct timeval cmt_recd_tv;
+
+ new = XCALLOC(MTYPE_MGMTD_CMT_INFO, sizeof(struct mgmt_cmt_info_t));
+ gettimeofday(&cmt_recd_tv, NULL);
+ mgmt_realtime_to_string(&cmt_recd_tv, new->time_str,
+ sizeof(new->time_str));
+ mgmt_history_hash(new->time_str, new->cmtid_str);
+ snprintf(new->cmt_json_file, sizeof(new->cmt_json_file),
+ MGMTD_COMMIT_FILE_PATH, new->cmtid_str);
+
+ if (mgmt_cmt_infos_count(&mm->cmts) == MGMTD_MAX_COMMIT_LIST) {
+ FOREACH_CMT_REC (mm, cmt_info)
+ last_cmt_info = cmt_info;
+
+ if (last_cmt_info) {
+ mgmt_history_remove_file(last_cmt_info->cmt_json_file);
+ mgmt_cmt_infos_del(&mm->cmts, last_cmt_info);
+ XFREE(MTYPE_MGMTD_CMT_INFO, last_cmt_info);
+ }
+ }
+
+ mgmt_cmt_infos_add_head(&mm->cmts, new);
+ return new;
+}
+
+static struct mgmt_cmt_info_t *mgmt_history_find_cmt_record(const char *cmtid_str)
+{
+ struct mgmt_cmt_info_t *cmt_info;
+
+ FOREACH_CMT_REC (mm, cmt_info) {
+ if (strncmp(cmt_info->cmtid_str, cmtid_str,
+ MGMTD_MD5_HASH_STR_HEX_LEN) == 0)
+ return cmt_info;
+ }
+
+ return NULL;
+}
+
+static bool mgmt_history_read_cmt_record_index(void)
+{
+ FILE *fp;
+ struct mgmt_cmt_info_t cmt_info;
+ struct mgmt_cmt_info_t *new;
+ int cnt = 0;
+
+ fp = fopen(MGMTD_COMMIT_INDEX_FILE_NAME, "rb");
+ if (!fp) {
+ zlog_err("Failed to open file %s rb mode",
+ MGMTD_COMMIT_INDEX_FILE_NAME);
+ return false;
+ }
+
+ while ((fread(&cmt_info, sizeof(cmt_info), 1, fp)) > 0) {
+ if (cnt < MGMTD_MAX_COMMIT_LIST) {
+ if (!mgmt_history_record_exists(cmt_info.cmt_json_file)) {
+ zlog_err(
+ "Commit record present in index_file, but commit file %s missing",
+ cmt_info.cmt_json_file);
+ continue;
+ }
+
+ new = XCALLOC(MTYPE_MGMTD_CMT_INFO,
+ sizeof(struct mgmt_cmt_info_t));
+ memcpy(new, &cmt_info, sizeof(struct mgmt_cmt_info_t));
+ mgmt_cmt_infos_add_tail(&mm->cmts, new);
+ } else {
+ zlog_err("More records found in index file %s",
+ MGMTD_COMMIT_INDEX_FILE_NAME);
+ fclose(fp);
+ return false;
+ }
+
+ cnt++;
+ }
+
+ fclose(fp);
+ return true;
+}
+
+static bool mgmt_history_dump_cmt_record_index(void)
+{
+ FILE *fp;
+ int ret = 0;
+ struct mgmt_cmt_info_t *cmt_info;
+ struct mgmt_cmt_info_t cmt_info_set[10];
+ int cnt = 0;
+
+ mgmt_history_remove_file((char *)MGMTD_COMMIT_INDEX_FILE_NAME);
+ fp = fopen(MGMTD_COMMIT_INDEX_FILE_NAME, "ab");
+ if (!fp) {
+ zlog_err("Failed to open file %s ab mode",
+ MGMTD_COMMIT_INDEX_FILE_NAME);
+ return false;
+ }
+
+ FOREACH_CMT_REC (mm, cmt_info) {
+ memcpy(&cmt_info_set[cnt], cmt_info,
+ sizeof(struct mgmt_cmt_info_t));
+ cnt++;
+ }
+
+ if (!cnt) {
+ fclose(fp);
+ return false;
+ }
+
+ ret = fwrite(&cmt_info_set, sizeof(struct mgmt_cmt_info_t), cnt, fp);
+ fclose(fp);
+ if (ret != cnt) {
+ zlog_err("Write record failed");
+ return false;
+ } else {
+ return true;
+ }
+}
+
+static int mgmt_history_rollback_to_cmt(struct vty *vty,
+ struct mgmt_cmt_info_t *cmt_info,
+ bool skip_file_load)
+{
+ struct mgmt_ds_ctx *src_ds_ctx;
+ struct mgmt_ds_ctx *dst_ds_ctx;
+ int ret = 0;
+
+ if (rollback_vty) {
+ vty_out(vty, "ERROR: Rollback already in progress!\n");
+ return -1;
+ }
+
+ src_ds_ctx = mgmt_ds_get_ctx_by_id(mm, MGMTD_DS_CANDIDATE);
+ if (!src_ds_ctx) {
+ vty_out(vty, "ERROR: Couldnot access Candidate datastore!\n");
+ return -1;
+ }
+
+ /*
+ * Note: Write lock on src_ds is not required. This is already
+ * taken in 'conf te'.
+ */
+ dst_ds_ctx = mgmt_ds_get_ctx_by_id(mm, MGMTD_DS_RUNNING);
+ if (!dst_ds_ctx) {
+ vty_out(vty, "ERROR: Couldnot access Running datastore!\n");
+ return -1;
+ }
+
+ ret = mgmt_ds_write_lock(dst_ds_ctx);
+ if (ret != 0) {
+ vty_out(vty,
+ "Failed to lock the DS %u for rollback Reason: %s!\n",
+ MGMTD_DS_RUNNING, strerror(ret));
+ return -1;
+ }
+
+ if (!skip_file_load) {
+ ret = mgmt_ds_load_config_from_file(
+ src_ds_ctx, cmt_info->cmt_json_file, false);
+ if (ret != 0) {
+ mgmt_ds_unlock(dst_ds_ctx);
+ vty_out(vty,
+ "Error with parsing the file with error code %d\n",
+ ret);
+ return ret;
+ }
+ }
+
+ /* Internally trigger a commit-request. */
+ ret = mgmt_txn_rollback_trigger_cfg_apply(src_ds_ctx, dst_ds_ctx);
+ if (ret != 0) {
+ mgmt_ds_unlock(dst_ds_ctx);
+ vty_out(vty,
+ "Error with creating commit apply txn with error code %d\n",
+ ret);
+ return ret;
+ }
+
+ mgmt_history_dump_cmt_record_index();
+
+ /*
+ * Block the rollback command from returning till the rollback
+ * is completed. On rollback completion mgmt_history_rollback_complete()
+ * shall be called to resume the rollback command return to VTYSH.
+ */
+ vty->mgmt_req_pending = true;
+ rollback_vty = vty;
+ return 0;
+}
+
+void mgmt_history_rollback_complete(bool success)
+{
+ vty_mgmt_resume_response(rollback_vty, success);
+ rollback_vty = NULL;
+}
+
+int mgmt_history_rollback_by_id(struct vty *vty, const char *cmtid_str)
+{
+ int ret = 0;
+ struct mgmt_cmt_info_t *cmt_info;
+
+ if (!mgmt_cmt_infos_count(&mm->cmts) ||
+ !mgmt_history_find_cmt_record(cmtid_str)) {
+ vty_out(vty, "Invalid commit Id\n");
+ return -1;
+ }
+
+ FOREACH_CMT_REC (mm, cmt_info) {
+ if (strncmp(cmt_info->cmtid_str, cmtid_str,
+ MGMTD_MD5_HASH_STR_HEX_LEN) == 0) {
+ ret = mgmt_history_rollback_to_cmt(vty, cmt_info, false);
+ return ret;
+ }
+
+ mgmt_history_remove_file(cmt_info->cmt_json_file);
+ mgmt_cmt_infos_del(&mm->cmts, cmt_info);
+ XFREE(MTYPE_MGMTD_CMT_INFO, cmt_info);
+ }
+
+ return 0;
+}
+
+int mgmt_history_rollback_n(struct vty *vty, int num_cmts)
+{
+ int ret = 0;
+ int cnt = 0;
+ struct mgmt_cmt_info_t *cmt_info;
+ size_t cmts;
+
+ if (!num_cmts)
+ num_cmts = 1;
+
+ cmts = mgmt_cmt_infos_count(&mm->cmts);
+ if ((int)cmts < num_cmts) {
+ vty_out(vty,
+ "Number of commits found (%d) less than required to rollback\n",
+ (int)cmts);
+ return -1;
+ }
+
+ if ((int)cmts == 1 || (int)cmts == num_cmts) {
+ vty_out(vty,
+ "Number of commits found (%d), Rollback of last commit is not supported\n",
+ (int)cmts);
+ return -1;
+ }
+
+ FOREACH_CMT_REC (mm, cmt_info) {
+ if (cnt == num_cmts) {
+ ret = mgmt_history_rollback_to_cmt(vty, cmt_info, false);
+ return ret;
+ }
+
+ cnt++;
+ mgmt_history_remove_file(cmt_info->cmt_json_file);
+ mgmt_cmt_infos_del(&mm->cmts, cmt_info);
+ XFREE(MTYPE_MGMTD_CMT_INFO, cmt_info);
+ }
+
+ if (!mgmt_cmt_infos_count(&mm->cmts)) {
+ mgmt_ds_reset_candidate();
+ ret = mgmt_history_rollback_to_cmt(vty, cmt_info, true);
+ }
+
+ return ret;
+}
+
+void show_mgmt_cmt_history(struct vty *vty)
+{
+ struct mgmt_cmt_info_t *cmt_info;
+ int slno = 0;
+
+ vty_out(vty, "Last 10 commit history:\n");
+ vty_out(vty, " Sl.No\tCommit-ID(HEX)\t\t\t Commit-Record-Time\n");
+ FOREACH_CMT_REC (mm, cmt_info) {
+ vty_out(vty, " %d\t%s %s\n", slno, cmt_info->cmtid_str,
+ cmt_info->time_str);
+ slno++;
+ }
+}
+
+void mgmt_history_new_record(struct mgmt_ds_ctx *ds_ctx)
+{
+ struct mgmt_cmt_info_t *cmt_info = mgmt_history_create_cmt_rec();
+ mgmt_ds_dump_ds_to_file(cmt_info->cmt_json_file, ds_ctx);
+ mgmt_history_dump_cmt_record_index();
+}
+
+void mgmt_history_init(void)
+{
+ /* Create commit record for previously stored commit-apply */
+ mgmt_cmt_infos_init(&mm->cmts);
+ mgmt_history_read_cmt_record_index();
+}
+
+void mgmt_history_destroy(void)
+{
+ struct mgmt_cmt_info_t *cmt_info;
+
+ FOREACH_CMT_REC(mm, cmt_info) {
+ mgmt_cmt_infos_del(&mm->cmts, cmt_info);
+ XFREE(MTYPE_MGMTD_CMT_INFO, cmt_info);
+ }
+
+ mgmt_cmt_infos_fini(&mm->cmts);
+}
diff --git a/mgmtd/mgmt_history.h b/mgmtd/mgmt_history.h
new file mode 100644
index 0000000000..29a1d7738e
--- /dev/null
+++ b/mgmtd/mgmt_history.h
@@ -0,0 +1,57 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2021 Vmware, Inc.
+ * Pushpasis Sarkar <spushpasis@vmware.com>
+ * Copyright (c) 2023, LabN Consulting, L.L.C.
+ *
+ */
+#ifndef _FRR_MGMTD_HISTORY_H_
+#define _FRR_MGMTD_HISTORY_H_
+
+#include "vrf.h"
+
+PREDECL_DLIST(mgmt_cmt_infos);
+
+struct mgmt_ds_ctx;
+
+/*
+ * Rollback specific commit from commit history.
+ *
+ * vty
+ * VTY context.
+ *
+ * cmtid_str
+ * Specific commit id from commit history.
+ *
+ * Returns:
+ * 0 on success, -1 on failure.
+ */
+extern int mgmt_history_rollback_by_id(struct vty *vty, const char *cmtid_str);
+
+/*
+ * Rollback n commits from commit history.
+ *
+ * vty
+ * VTY context.
+ *
+ * num_cmts
+ * Number of commits to be rolled back.
+ *
+ * Returns:
+ * 0 on success, -1 on failure.
+ */
+extern int mgmt_history_rollback_n(struct vty *vty, int num_cmts);
+
+extern void mgmt_history_rollback_complete(bool success);
+
+/*
+ * Show mgmt commit history.
+ */
+extern void show_mgmt_cmt_history(struct vty *vty);
+
+extern void mgmt_history_new_record(struct mgmt_ds_ctx *ds_ctx);
+
+extern void mgmt_history_destroy(void);
+extern void mgmt_history_init(void);
+
+#endif /* _FRR_MGMTD_HISTORY_H_ */
diff --git a/mgmtd/mgmt_main.c b/mgmtd/mgmt_main.c
new file mode 100644
index 0000000000..08c999260d
--- /dev/null
+++ b/mgmtd/mgmt_main.c
@@ -0,0 +1,287 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Main routine of mgmt.
+ *
+ * Copyright (C) 2021 Vmware, Inc.
+ * Pushpasis Sarkar
+ */
+
+#include <zebra.h>
+#include "lib/version.h"
+#include "routemap.h"
+#include "filter.h"
+#include "libfrr.h"
+#include "frr_pthread.h"
+#include "mgmtd/mgmt.h"
+#include "mgmtd/mgmt_ds.h"
+#include "routing_nb.h"
+
+
+char const *const mgmt_daemons[] = {
+#ifdef HAVE_STATICD
+ "staticd",
+#endif
+};
+uint mgmt_daemons_count = array_size(mgmt_daemons);
+
+/* mgmt options, we use GNU getopt library. */
+static const struct option longopts[] = {
+ {"skip_runas", no_argument, NULL, 'S'},
+ {"no_zebra", no_argument, NULL, 'Z'},
+ {"socket_size", required_argument, NULL, 's'},
+ {0}
+};
+
+static void mgmt_exit(int);
+static void mgmt_vrf_terminate(void);
+
+/* privileges */
+static zebra_capabilities_t _caps_p[] = {ZCAP_BIND, ZCAP_NET_RAW,
+ ZCAP_NET_ADMIN, ZCAP_SYS_ADMIN};
+
+struct zebra_privs_t mgmt_privs = {
+#if defined(FRR_USER) && defined(FRR_GROUP)
+ .user = FRR_USER,
+ .group = FRR_GROUP,
+#endif
+#ifdef VTY_GROUP
+ .vty_group = VTY_GROUP,
+#endif
+ .caps_p = _caps_p,
+ .cap_num_p = array_size(_caps_p),
+ .cap_num_i = 0,
+};
+
+static struct frr_daemon_info mgmtd_di;
+char backup_config_file[256];
+
+/* SIGHUP handler. */
+static void sighup(void)
+{
+ zlog_info("SIGHUP received, ignoring");
+
+ return;
+
+ /*
+ * This is turned off for the moment. There is all
+ * sorts of config turned off by mgmt_terminate
+ * that is not setup properly again in mgmt_reset.
+ * I see no easy way to do this nor do I see that
+ * this is a desirable way to reload config
+ * given the yang work.
+ */
+ /* Terminate all thread. */
+ mgmt_terminate();
+
+ /*
+ * mgmt_reset();
+ */
+ zlog_info("MGMTD restarting!");
+
+ /*
+ * Reload config file.
+ * vty_read_config(NULL, mgmtd_di.config_file, config_default);
+ */
+ /* Try to return to normal operation. */
+}
+
+/* SIGINT handler. */
+static __attribute__((__noreturn__)) void sigint(void)
+{
+ zlog_notice("Terminating on signal");
+ assert(mm->terminating == false);
+ mm->terminating = true; /* global flag that shutting down */
+
+ mgmt_terminate();
+
+ mgmt_exit(0);
+
+ exit(0);
+}
+
+/* SIGUSR1 handler. */
+static void sigusr1(void)
+{
+ zlog_rotate();
+}
+
+/*
+ * Try to free up allocations we know about so that diagnostic tools such as
+ * valgrind are able to better illuminate leaks.
+ *
+ * Zebra route removal and protocol teardown are not meant to be done here.
+ * For example, "retain_mode" may be set.
+ */
+static __attribute__((__noreturn__)) void mgmt_exit(int status)
+{
+ /* it only makes sense for this to be called on a clean exit */
+ assert(status == 0);
+
+ frr_early_fini();
+
+ /* stop pthreads (if any) */
+ frr_pthread_stop_all();
+
+ mgmt_vrf_terminate();
+
+ frr_fini();
+ exit(status);
+}
+
+static struct frr_signal_t mgmt_signals[] = {
+ {
+ .signal = SIGHUP,
+ .handler = &sighup,
+ },
+ {
+ .signal = SIGUSR1,
+ .handler = &sigusr1,
+ },
+ {
+ .signal = SIGINT,
+ .handler = &sigint,
+ },
+ {
+ .signal = SIGTERM,
+ .handler = &sigint,
+ },
+};
+
+static int mgmt_vrf_new(struct vrf *vrf)
+{
+ zlog_debug("VRF Created: %s(%u)", vrf->name, vrf->vrf_id);
+
+ return 0;
+}
+
+static int mgmt_vrf_delete(struct vrf *vrf)
+{
+ zlog_debug("VRF Deletion: %s(%u)", vrf->name, vrf->vrf_id);
+
+ return 0;
+}
+
+static int mgmt_vrf_enable(struct vrf *vrf)
+{
+ zlog_debug("VRF Enable: %s(%u)", vrf->name, vrf->vrf_id);
+
+ return 0;
+}
+
+static int mgmt_vrf_disable(struct vrf *vrf)
+{
+ zlog_debug("VRF Disable: %s(%u)", vrf->name, vrf->vrf_id);
+
+ /* Note: This is a callback, the VRF will be deleted by the caller. */
+ return 0;
+}
+
+static int mgmt_vrf_config_write(struct vty *vty)
+{
+ return 0;
+}
+
+static void mgmt_vrf_init(void)
+{
+ vrf_init(mgmt_vrf_new, mgmt_vrf_enable, mgmt_vrf_disable,
+ mgmt_vrf_delete);
+ vrf_cmd_init(mgmt_vrf_config_write);
+}
+
+static void mgmt_vrf_terminate(void)
+{
+ vrf_terminate();
+}
+
+/*
+ * List of YANG modules to be loaded in the process context of
+ * MGMTd.
+ *
+ * NOTE: In future this will also include the YANG modules of
+ * all individual Backend clients.
+ */
+static const struct frr_yang_module_info *const mgmt_yang_modules[] = {
+ &frr_filter_info, &frr_interface_info, &frr_route_map_info,
+ &frr_routing_info, &frr_vrf_info,
+/*
+ * YANG module info supported by backend clients get added here.
+ * NOTE: Always set .ignore_cbs true for to avoid validating
+ * backend northbound callbacks during loading.
+ */
+#ifdef HAVE_STATICD
+ &(struct frr_yang_module_info){.name = "frr-staticd",
+ .ignore_cbs = true},
+#endif
+};
+
+FRR_DAEMON_INFO(mgmtd, MGMTD, .vty_port = MGMTD_VTY_PORT,
+
+ .proghelp = "FRR Management Daemon.",
+
+ .signals = mgmt_signals, .n_signals = array_size(mgmt_signals),
+
+ .privs = &mgmt_privs, .yang_modules = mgmt_yang_modules,
+ .n_yang_modules = array_size(mgmt_yang_modules),
+);
+
+#define DEPRECATED_OPTIONS ""
+
+/* Main routine of mgmt. Treatment of argument and start mgmt finite
+ * state machine is handled at here.
+ */
+int main(int argc, char **argv)
+{
+ int opt;
+ int buffer_size = MGMTD_SOCKET_BUF_SIZE;
+
+ frr_preinit(&mgmtd_di, argc, argv);
+ frr_opt_add(
+ "s:" DEPRECATED_OPTIONS, longopts,
+ " -s, --socket_size Set MGMTD peer socket send buffer size\n");
+
+ /* Command line argument treatment. */
+ while (1) {
+ opt = frr_getopt(argc, argv, 0);
+
+ if (opt && opt < 128 && strchr(DEPRECATED_OPTIONS, opt)) {
+ fprintf(stderr,
+ "The -%c option no longer exists.\nPlease refer to the manual.\n",
+ opt);
+ continue;
+ }
+
+ if (opt == EOF)
+ break;
+
+ switch (opt) {
+ case 0:
+ break;
+ case 's':
+ buffer_size = atoi(optarg);
+ break;
+ default:
+ frr_help_exit(1);
+ break;
+ }
+ }
+
+ /* MGMTD master init. */
+ mgmt_master_init(frr_init(), buffer_size);
+
+ /* VRF Initializations. */
+ mgmt_vrf_init();
+
+ /* MGMTD related initialization. */
+ mgmt_init();
+
+ snprintf(backup_config_file, sizeof(backup_config_file),
+ "%s/zebra.conf", frr_sysconfdir);
+ mgmtd_di.backup_config_file = backup_config_file;
+
+ frr_config_fork();
+
+ frr_run(mm->master);
+
+ /* Not reached. */
+ return 0;
+}
diff --git a/mgmtd/mgmt_memory.c b/mgmtd/mgmt_memory.c
new file mode 100644
index 0000000000..2858bc7e45
--- /dev/null
+++ b/mgmtd/mgmt_memory.c
@@ -0,0 +1,36 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * mgmt memory type definitions
+ *
+ * Copyright (C) 2021 Vmware, Inc.
+ * Pushpasis Sarkar <spushpasis@vmware.com>
+ */
+
+#include <zebra.h>
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "mgmt_memory.h"
+
+/* this file is temporary in nature; definitions should be moved to the
+ * files they're used in
+ */
+
+DEFINE_MGROUP(MGMTD, "mgmt");
+DEFINE_MTYPE(MGMTD, MGMTD, "MGMTD instance");
+DEFINE_MTYPE(MGMTD, MGMTD_BE_ADPATER, "MGMTD backend adapter");
+DEFINE_MTYPE(MGMTD, MGMTD_FE_ADPATER, "MGMTD Frontend adapter");
+DEFINE_MTYPE(MGMTD, MGMTD_FE_SESSION, "MGMTD Frontend Client Session");
+DEFINE_MTYPE(MGMTD, MGMTD_TXN, "MGMTD Transaction");
+DEFINE_MTYPE(MGMTD, MGMTD_TXN_REQ, "MGMTD Transaction Requests");
+DEFINE_MTYPE(MGMTD, MGMTD_TXN_SETCFG_REQ,
+ "MGMTD Transaction Set-Config Requests");
+DEFINE_MTYPE(MGMTD, MGMTD_TXN_COMMCFG_REQ,
+ "MGMTD Transaction Commit-Config Requests");
+DEFINE_MTYPE(MGMTD, MGMTD_TXN_GETDATA_REQ,
+ "MGMTD Transaction Get-Data Requests");
+DEFINE_MTYPE(MGMTD, MGMTD_TXN_GETDATA_REPLY,
+ "MGMTD Transaction Get-Data Replies");
+DEFINE_MTYPE(MGMTD, MGMTD_TXN_CFG_BATCH, "MGMTD Transaction Gonfig Batches");
+DEFINE_MTYPE(MGMTD, MGMTD_CMT_INFO, "MGMTD commit info for tracking commits");
diff --git a/mgmtd/mgmt_memory.h b/mgmtd/mgmt_memory.h
new file mode 100644
index 0000000000..5cfcafc749
--- /dev/null
+++ b/mgmtd/mgmt_memory.h
@@ -0,0 +1,28 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * mgmt memory type declarations
+ *
+ * Copyright (C) 2021 Vmware, Inc.
+ * Pushpasis Sarkar <spushpasis@vmware.com>
+ */
+
+#ifndef _FRR_MGMTD_MEMORY_H
+#define _FRR_MGMTD_MEMORY_H
+
+#include "memory.h"
+
+DECLARE_MGROUP(MGMTD);
+DECLARE_MTYPE(MGMTD);
+DECLARE_MTYPE(MGMTD_BE_ADPATER);
+DECLARE_MTYPE(MGMTD_FE_ADPATER);
+DECLARE_MTYPE(MGMTD_FE_SESSION);
+DECLARE_MTYPE(MGMTD_TXN);
+DECLARE_MTYPE(MGMTD_TXN_REQ);
+DECLARE_MTYPE(MGMTD_TXN_SETCFG_REQ);
+DECLARE_MTYPE(MGMTD_TXN_COMMCFG_REQ);
+DECLARE_MTYPE(MGMTD_TXN_GETDATA_REQ);
+DECLARE_MTYPE(MGMTD_TXN_GETDATA_REPLY);
+DECLARE_MTYPE(MGMTD_TXN_CFG_BATCH);
+DECLARE_MTYPE(MGMTD_BE_ADAPTER_MSG_BUF);
+DECLARE_MTYPE(MGMTD_CMT_INFO);
+#endif /* _FRR_MGMTD_MEMORY_H */
diff --git a/mgmtd/mgmt_txn.c b/mgmtd/mgmt_txn.c
new file mode 100644
index 0000000000..5fa8aabfd6
--- /dev/null
+++ b/mgmtd/mgmt_txn.c
@@ -0,0 +1,2835 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * MGMTD Transactions
+ *
+ * Copyright (C) 2021 Vmware, Inc.
+ * Pushpasis Sarkar <spushpasis@vmware.com>
+ */
+
+#include <zebra.h>
+#include "hash.h"
+#include "jhash.h"
+#include "libfrr.h"
+#include "mgmtd/mgmt.h"
+#include "mgmtd/mgmt_memory.h"
+#include "mgmtd/mgmt_txn.h"
+
+#ifdef REDIRECT_DEBUG_TO_STDERR
+#define MGMTD_TXN_DBG(fmt, ...) \
+ fprintf(stderr, "%s: " fmt "\n", __func__, ##__VA_ARGS__)
+#define MGMTD_TXN_ERR(fmt, ...) \
+ fprintf(stderr, "%s: ERROR, " fmt "\n", __func__, ##__VA_ARGS__)
+#else /* REDIRECT_DEBUG_TO_STDERR */
+#define MGMTD_TXN_DBG(fmt, ...) \
+ do { \
+ if (mgmt_debug_txn) \
+ zlog_err("%s: " fmt, __func__, ##__VA_ARGS__); \
+ } while (0)
+#define MGMTD_TXN_ERR(fmt, ...) \
+ zlog_err("%s: ERROR: " fmt, __func__, ##__VA_ARGS__)
+#endif /* REDIRECT_DEBUG_TO_STDERR */
+
+#define MGMTD_TXN_LOCK(txn) mgmt_txn_lock(txn, __FILE__, __LINE__)
+#define MGMTD_TXN_UNLOCK(txn) mgmt_txn_unlock(txn, __FILE__, __LINE__)
+
+enum mgmt_txn_event {
+ MGMTD_TXN_PROC_SETCFG = 1,
+ MGMTD_TXN_PROC_COMMITCFG,
+ MGMTD_TXN_PROC_GETCFG,
+ MGMTD_TXN_PROC_GETDATA,
+ MGMTD_TXN_COMMITCFG_TIMEOUT,
+ MGMTD_TXN_CLEANUP
+};
+
+PREDECL_LIST(mgmt_txn_reqs);
+
+struct mgmt_set_cfg_req {
+ Mgmtd__DatastoreId ds_id;
+ struct mgmt_ds_ctx *ds_ctx;
+ struct nb_cfg_change cfg_changes[MGMTD_MAX_CFG_CHANGES_IN_BATCH];
+ uint16_t num_cfg_changes;
+ bool implicit_commit;
+ Mgmtd__DatastoreId dst_ds_id;
+ struct mgmt_ds_ctx *dst_ds_ctx;
+ struct mgmt_setcfg_stats *setcfg_stats;
+};
+
+enum mgmt_commit_phase {
+ MGMTD_COMMIT_PHASE_PREPARE_CFG = 0,
+ MGMTD_COMMIT_PHASE_TXN_CREATE,
+ MGMTD_COMMIT_PHASE_SEND_CFG,
+ MGMTD_COMMIT_PHASE_APPLY_CFG,
+ MGMTD_COMMIT_PHASE_TXN_DELETE,
+ MGMTD_COMMIT_PHASE_MAX
+};
+
+static inline const char *
+mgmt_commit_phase2str(enum mgmt_commit_phase cmt_phase)
+{
+ switch (cmt_phase) {
+ case MGMTD_COMMIT_PHASE_PREPARE_CFG:
+ return "PREP-CFG";
+ case MGMTD_COMMIT_PHASE_TXN_CREATE:
+ return "CREATE-TXN";
+ case MGMTD_COMMIT_PHASE_SEND_CFG:
+ return "SEND-CFG";
+ case MGMTD_COMMIT_PHASE_APPLY_CFG:
+ return "APPLY-CFG";
+ case MGMTD_COMMIT_PHASE_TXN_DELETE:
+ return "DELETE-TXN";
+ case MGMTD_COMMIT_PHASE_MAX:
+ return "Invalid/Unknown";
+ }
+
+ return "Invalid/Unknown";
+}
+
+PREDECL_LIST(mgmt_txn_batches);
+
+struct mgmt_txn_be_cfg_batch {
+ struct mgmt_txn_ctx *txn;
+ uint64_t batch_id;
+ enum mgmt_be_client_id be_id;
+ struct mgmt_be_client_adapter *be_adapter;
+ union mgmt_be_xpath_subscr_info
+ xp_subscr[MGMTD_MAX_CFG_CHANGES_IN_BATCH];
+ Mgmtd__YangCfgDataReq cfg_data[MGMTD_MAX_CFG_CHANGES_IN_BATCH];
+ Mgmtd__YangCfgDataReq * cfg_datap[MGMTD_MAX_CFG_CHANGES_IN_BATCH];
+ Mgmtd__YangData data[MGMTD_MAX_CFG_CHANGES_IN_BATCH];
+ Mgmtd__YangDataValue value[MGMTD_MAX_CFG_CHANGES_IN_BATCH];
+ size_t num_cfg_data;
+ int buf_space_left;
+ enum mgmt_commit_phase comm_phase;
+ struct mgmt_txn_batches_item list_linkage;
+};
+
+DECLARE_LIST(mgmt_txn_batches, struct mgmt_txn_be_cfg_batch, list_linkage);
+
+#define FOREACH_TXN_CFG_BATCH_IN_LIST(list, batch) \
+ frr_each_safe (mgmt_txn_batches, list, batch)
+
+struct mgmt_commit_cfg_req {
+ Mgmtd__DatastoreId src_ds_id;
+ struct mgmt_ds_ctx *src_ds_ctx;
+ Mgmtd__DatastoreId dst_ds_id;
+ struct mgmt_ds_ctx *dst_ds_ctx;
+ uint32_t nb_txn_id;
+ uint8_t validate_only : 1;
+ uint8_t abort : 1;
+ uint8_t implicit : 1;
+ uint8_t rollback : 1;
+
+ /* Track commit phases */
+ enum mgmt_commit_phase curr_phase;
+ enum mgmt_commit_phase next_phase;
+
+ /*
+ * Set of config changes to commit. This is used only
+ * when changes are NOT to be determined by comparing
+ * candidate and running DSs. This is typically used
+ * for downloading all relevant configs for a new backend
+ * client that has recently come up and connected with
+ * MGMTD.
+ */
+ struct nb_config_cbs *cfg_chgs;
+
+ /*
+ * Details on all the Backend Clients associated with
+ * this commit.
+ */
+ struct mgmt_be_client_subscr_info subscr_info;
+
+ /*
+ * List of backend batches for this commit to be validated
+ * and applied at the backend.
+ *
+ * FIXME: Need to re-think this design for the case set of
+ * validators for a given YANG data item is different from
+ * the set of notifiers for the same. We may need to have
+ * separate list of batches for VALIDATE and APPLY.
+ */
+ struct mgmt_txn_batches_head curr_batches[MGMTD_BE_CLIENT_ID_MAX];
+ struct mgmt_txn_batches_head next_batches[MGMTD_BE_CLIENT_ID_MAX];
+ /*
+ * The last batch added for any backend client. This is always on
+ * 'curr_batches'
+ */
+ struct mgmt_txn_be_cfg_batch
+ *last_be_cfg_batch[MGMTD_BE_CLIENT_ID_MAX];
+ struct hash *batches;
+ uint64_t next_batch_id;
+
+ struct mgmt_commit_stats *cmt_stats;
+};
+
+struct mgmt_get_data_reply {
+ /* Buffer space for preparing data reply */
+ int num_reply;
+ int last_batch;
+ Mgmtd__YangDataReply data_reply;
+ Mgmtd__YangData reply_data[MGMTD_MAX_NUM_DATA_REPLY_IN_BATCH];
+ Mgmtd__YangData * reply_datap[MGMTD_MAX_NUM_DATA_REPLY_IN_BATCH];
+ Mgmtd__YangDataValue reply_value[MGMTD_MAX_NUM_DATA_REPLY_IN_BATCH];
+ char *reply_xpathp[MGMTD_MAX_NUM_DATA_REPLY_IN_BATCH];
+};
+
+struct mgmt_get_data_req {
+ Mgmtd__DatastoreId ds_id;
+ struct mgmt_ds_ctx *ds_ctx;
+ char *xpaths[MGMTD_MAX_NUM_DATA_REQ_IN_BATCH];
+ int num_xpaths;
+
+ /*
+ * Buffer space for preparing reply.
+ * NOTE: Should only be malloc-ed on demand to reduce
+ * memory footprint. Freed up via mgmt_trx_req_free()
+ */
+ struct mgmt_get_data_reply *reply;
+
+ int total_reply;
+};
+
+struct mgmt_txn_req {
+ struct mgmt_txn_ctx *txn;
+ enum mgmt_txn_event req_event;
+ uint64_t req_id;
+ union {
+ struct mgmt_set_cfg_req *set_cfg;
+ struct mgmt_get_data_req *get_data;
+ struct mgmt_commit_cfg_req commit_cfg;
+ } req;
+
+ bool pending_be_proc;
+ struct mgmt_txn_reqs_item list_linkage;
+};
+
+DECLARE_LIST(mgmt_txn_reqs, struct mgmt_txn_req, list_linkage);
+
+#define FOREACH_TXN_REQ_IN_LIST(list, req) \
+ frr_each_safe (mgmt_txn_reqs, list, req)
+
+struct mgmt_txn_ctx {
+ uint64_t session_id; /* One transaction per client session */
+ uint64_t txn_id;
+ enum mgmt_txn_type type;
+
+ /* struct mgmt_master *mm; */
+
+ struct event *proc_set_cfg;
+ struct event *proc_comm_cfg;
+ struct event *proc_get_cfg;
+ struct event *proc_get_data;
+ struct event *comm_cfg_timeout;
+ struct event *clnup;
+
+ /* List of backend adapters involved in this transaction */
+ struct mgmt_txn_badapters_head be_adapters;
+
+ int refcount;
+
+ struct mgmt_txns_item list_linkage;
+
+ /*
+ * List of pending set-config requests for a given
+ * transaction/session. Just one list for requests
+ * not processed at all. There's no backend interaction
+ * involved.
+ */
+ struct mgmt_txn_reqs_head set_cfg_reqs;
+ /*
+ * List of pending get-config requests for a given
+ * transaction/session. Just one list for requests
+ * not processed at all. There's no backend interaction
+ * involved.
+ */
+ struct mgmt_txn_reqs_head get_cfg_reqs;
+ /*
+ * List of pending get-data requests for a given
+ * transaction/session Two lists, one for requests
+ * not processed at all, and one for requests that
+ * has been sent to backend for processing.
+ */
+ struct mgmt_txn_reqs_head get_data_reqs;
+ struct mgmt_txn_reqs_head pending_get_datas;
+ /*
+ * There will always be one commit-config allowed for a given
+ * transaction/session. No need to maintain lists for it.
+ */
+ struct mgmt_txn_req *commit_cfg_req;
+};
+
+DECLARE_LIST(mgmt_txns, struct mgmt_txn_ctx, list_linkage);
+
+#define FOREACH_TXN_IN_LIST(mm, txn) \
+ frr_each_safe (mgmt_txns, &(mm)->txn_list, (txn))
+
+static int mgmt_txn_send_commit_cfg_reply(struct mgmt_txn_ctx *txn,
+ enum mgmt_result result,
+ const char *error_if_any);
+
+static inline const char *
+mgmt_txn_commit_phase_str(struct mgmt_txn_ctx *txn, bool curr)
+{
+ if (!txn->commit_cfg_req)
+ return "None";
+
+ return (mgmt_commit_phase2str(
+ curr ? txn->commit_cfg_req->req.commit_cfg.curr_phase
+ : txn->commit_cfg_req->req.commit_cfg.next_phase));
+}
+
+static void mgmt_txn_lock(struct mgmt_txn_ctx *txn, const char *file,
+ int line);
+static void mgmt_txn_unlock(struct mgmt_txn_ctx **txn, const char *file,
+ int line);
+static int
+mgmt_txn_send_be_txn_delete(struct mgmt_txn_ctx *txn,
+ struct mgmt_be_client_adapter *adapter);
+
+static struct event_loop *mgmt_txn_tm;
+static struct mgmt_master *mgmt_txn_mm;
+
+static void mgmt_txn_register_event(struct mgmt_txn_ctx *txn,
+ enum mgmt_txn_event event);
+
+static int
+mgmt_move_be_commit_to_next_phase(struct mgmt_txn_ctx *txn,
+ struct mgmt_be_client_adapter *adapter);
+
+static struct mgmt_txn_be_cfg_batch *
+mgmt_txn_cfg_batch_alloc(struct mgmt_txn_ctx *txn,
+ enum mgmt_be_client_id id,
+ struct mgmt_be_client_adapter *be_adapter)
+{
+ struct mgmt_txn_be_cfg_batch *cfg_btch;
+
+ cfg_btch = XCALLOC(MTYPE_MGMTD_TXN_CFG_BATCH,
+ sizeof(struct mgmt_txn_be_cfg_batch));
+ assert(cfg_btch);
+ cfg_btch->be_id = id;
+
+ cfg_btch->txn = txn;
+ MGMTD_TXN_LOCK(txn);
+ assert(txn->commit_cfg_req);
+ mgmt_txn_batches_add_tail(
+ &txn->commit_cfg_req->req.commit_cfg.curr_batches[id],
+ cfg_btch);
+ cfg_btch->be_adapter = be_adapter;
+ cfg_btch->buf_space_left = MGMTD_BE_CFGDATA_MAX_MSG_LEN;
+ if (be_adapter)
+ mgmt_be_adapter_lock(be_adapter);
+
+ txn->commit_cfg_req->req.commit_cfg.last_be_cfg_batch[id] =
+ cfg_btch;
+ if (!txn->commit_cfg_req->req.commit_cfg.next_batch_id)
+ txn->commit_cfg_req->req.commit_cfg.next_batch_id++;
+ cfg_btch->batch_id =
+ txn->commit_cfg_req->req.commit_cfg.next_batch_id++;
+ hash_get(txn->commit_cfg_req->req.commit_cfg.batches, cfg_btch,
+ hash_alloc_intern);
+
+ return cfg_btch;
+}
+
+static void
+mgmt_txn_cfg_batch_free(struct mgmt_txn_be_cfg_batch **cfg_btch)
+{
+ size_t indx;
+ struct mgmt_commit_cfg_req *cmtcfg_req;
+
+ MGMTD_TXN_DBG(" Batch: %p, Txn: %p", *cfg_btch, (*cfg_btch)->txn);
+
+ assert((*cfg_btch)->txn
+ && (*cfg_btch)->txn->type == MGMTD_TXN_TYPE_CONFIG);
+
+ cmtcfg_req = &(*cfg_btch)->txn->commit_cfg_req->req.commit_cfg;
+ hash_release(cmtcfg_req->batches, *cfg_btch);
+ mgmt_txn_batches_del(&cmtcfg_req->curr_batches[(*cfg_btch)->be_id],
+ *cfg_btch);
+ mgmt_txn_batches_del(&cmtcfg_req->next_batches[(*cfg_btch)->be_id],
+ *cfg_btch);
+
+ if ((*cfg_btch)->be_adapter)
+ mgmt_be_adapter_unlock(&(*cfg_btch)->be_adapter);
+
+ for (indx = 0; indx < (*cfg_btch)->num_cfg_data; indx++) {
+ if ((*cfg_btch)->data[indx].xpath) {
+ free((*cfg_btch)->data[indx].xpath);
+ (*cfg_btch)->data[indx].xpath = NULL;
+ }
+ }
+
+ MGMTD_TXN_UNLOCK(&(*cfg_btch)->txn);
+
+ XFREE(MTYPE_MGMTD_TXN_CFG_BATCH, *cfg_btch);
+ *cfg_btch = NULL;
+}
+
+static unsigned int mgmt_txn_cfgbatch_hash_key(const void *data)
+{
+ const struct mgmt_txn_be_cfg_batch *batch = data;
+
+ return jhash2((uint32_t *) &batch->batch_id,
+ sizeof(batch->batch_id) / sizeof(uint32_t), 0);
+}
+
+static bool mgmt_txn_cfgbatch_hash_cmp(const void *d1, const void *d2)
+{
+ const struct mgmt_txn_be_cfg_batch *batch1 = d1;
+ const struct mgmt_txn_be_cfg_batch *batch2 = d2;
+
+ return (batch1->batch_id == batch2->batch_id);
+}
+
+static void mgmt_txn_cfgbatch_hash_free(void *data)
+{
+ struct mgmt_txn_be_cfg_batch *batch = data;
+
+ mgmt_txn_cfg_batch_free(&batch);
+}
+
+static inline struct mgmt_txn_be_cfg_batch *
+mgmt_txn_cfgbatch_id2ctx(struct mgmt_txn_ctx *txn, uint64_t batch_id)
+{
+ struct mgmt_txn_be_cfg_batch key = {0};
+ struct mgmt_txn_be_cfg_batch *batch;
+
+ if (!txn->commit_cfg_req)
+ return NULL;
+
+ key.batch_id = batch_id;
+ batch = hash_lookup(txn->commit_cfg_req->req.commit_cfg.batches,
+ &key);
+
+ return batch;
+}
+
+static void mgmt_txn_cleanup_be_cfg_batches(struct mgmt_txn_ctx *txn,
+ enum mgmt_be_client_id id)
+{
+ struct mgmt_txn_be_cfg_batch *cfg_btch;
+ struct mgmt_txn_batches_head *list;
+
+ list = &txn->commit_cfg_req->req.commit_cfg.curr_batches[id];
+ FOREACH_TXN_CFG_BATCH_IN_LIST (list, cfg_btch)
+ mgmt_txn_cfg_batch_free(&cfg_btch);
+
+ mgmt_txn_batches_fini(list);
+
+ list = &txn->commit_cfg_req->req.commit_cfg.next_batches[id];
+ FOREACH_TXN_CFG_BATCH_IN_LIST (list, cfg_btch)
+ mgmt_txn_cfg_batch_free(&cfg_btch);
+
+ mgmt_txn_batches_fini(list);
+
+ txn->commit_cfg_req->req.commit_cfg.last_be_cfg_batch[id] = NULL;
+}
+
+static struct mgmt_txn_req *mgmt_txn_req_alloc(struct mgmt_txn_ctx *txn,
+ uint64_t req_id,
+ enum mgmt_txn_event req_event)
+{
+ struct mgmt_txn_req *txn_req;
+ enum mgmt_be_client_id id;
+
+ txn_req = XCALLOC(MTYPE_MGMTD_TXN_REQ, sizeof(struct mgmt_txn_req));
+ assert(txn_req);
+ txn_req->txn = txn;
+ txn_req->req_id = req_id;
+ txn_req->req_event = req_event;
+ txn_req->pending_be_proc = false;
+
+ switch (txn_req->req_event) {
+ case MGMTD_TXN_PROC_SETCFG:
+ txn_req->req.set_cfg = XCALLOC(MTYPE_MGMTD_TXN_SETCFG_REQ,
+ sizeof(struct mgmt_set_cfg_req));
+ assert(txn_req->req.set_cfg);
+ mgmt_txn_reqs_add_tail(&txn->set_cfg_reqs, txn_req);
+ MGMTD_TXN_DBG(
+ "Added a new SETCFG Req: %p for Txn: %p, Sessn: 0x%llx",
+ txn_req, txn, (unsigned long long)txn->session_id);
+ break;
+ case MGMTD_TXN_PROC_COMMITCFG:
+ txn->commit_cfg_req = txn_req;
+ MGMTD_TXN_DBG(
+ "Added a new COMMITCFG Req: %p for Txn: %p, Sessn: 0x%llx",
+ txn_req, txn, (unsigned long long)txn->session_id);
+
+ FOREACH_MGMTD_BE_CLIENT_ID (id) {
+ mgmt_txn_batches_init(
+ &txn_req->req.commit_cfg.curr_batches[id]);
+ mgmt_txn_batches_init(
+ &txn_req->req.commit_cfg.next_batches[id]);
+ }
+
+ txn_req->req.commit_cfg.batches =
+ hash_create(mgmt_txn_cfgbatch_hash_key,
+ mgmt_txn_cfgbatch_hash_cmp,
+ "MGMT Config Batches");
+ break;
+ case MGMTD_TXN_PROC_GETCFG:
+ txn_req->req.get_data =
+ XCALLOC(MTYPE_MGMTD_TXN_GETDATA_REQ,
+ sizeof(struct mgmt_get_data_req));
+ assert(txn_req->req.get_data);
+ mgmt_txn_reqs_add_tail(&txn->get_cfg_reqs, txn_req);
+ MGMTD_TXN_DBG(
+ "Added a new GETCFG Req: %p for Txn: %p, Sessn: 0x%llx",
+ txn_req, txn, (unsigned long long)txn->session_id);
+ break;
+ case MGMTD_TXN_PROC_GETDATA:
+ txn_req->req.get_data =
+ XCALLOC(MTYPE_MGMTD_TXN_GETDATA_REQ,
+ sizeof(struct mgmt_get_data_req));
+ assert(txn_req->req.get_data);
+ mgmt_txn_reqs_add_tail(&txn->get_data_reqs, txn_req);
+ MGMTD_TXN_DBG(
+ "Added a new GETDATA Req: %p for Txn: %p, Sessn: 0x%llx",
+ txn_req, txn, (unsigned long long)txn->session_id);
+ break;
+ case MGMTD_TXN_COMMITCFG_TIMEOUT:
+ case MGMTD_TXN_CLEANUP:
+ break;
+ }
+
+ MGMTD_TXN_LOCK(txn);
+
+ return txn_req;
+}
+
+static void mgmt_txn_req_free(struct mgmt_txn_req **txn_req)
+{
+ int indx;
+ struct mgmt_txn_reqs_head *req_list = NULL;
+ struct mgmt_txn_reqs_head *pending_list = NULL;
+ enum mgmt_be_client_id id;
+ struct mgmt_be_client_adapter *adapter;
+
+ switch ((*txn_req)->req_event) {
+ case MGMTD_TXN_PROC_SETCFG:
+ for (indx = 0; indx < (*txn_req)->req.set_cfg->num_cfg_changes;
+ indx++) {
+ if ((*txn_req)->req.set_cfg->cfg_changes[indx].value) {
+ MGMTD_TXN_DBG(
+ "Freeing value for %s at %p ==> '%s'",
+ (*txn_req)
+ ->req.set_cfg->cfg_changes[indx]
+ .xpath,
+ (*txn_req)
+ ->req.set_cfg->cfg_changes[indx]
+ .value,
+ (*txn_req)
+ ->req.set_cfg->cfg_changes[indx]
+ .value);
+ free((void *)(*txn_req)
+ ->req.set_cfg->cfg_changes[indx]
+ .value);
+ }
+ }
+ req_list = &(*txn_req)->txn->set_cfg_reqs;
+ MGMTD_TXN_DBG("Deleting SETCFG Req: %p for Txn: %p",
+ *txn_req, (*txn_req)->txn);
+ XFREE(MTYPE_MGMTD_TXN_SETCFG_REQ, (*txn_req)->req.set_cfg);
+ break;
+ case MGMTD_TXN_PROC_COMMITCFG:
+ MGMTD_TXN_DBG("Deleting COMMITCFG Req: %p for Txn: %p",
+ *txn_req, (*txn_req)->txn);
+ FOREACH_MGMTD_BE_CLIENT_ID (id) {
+ /*
+ * Send TXN_DELETE to cleanup state for this
+ * transaction on backend
+ */
+ if ((*txn_req)->req.commit_cfg.curr_phase
+ >= MGMTD_COMMIT_PHASE_TXN_CREATE
+ && (*txn_req)->req.commit_cfg.curr_phase
+ < MGMTD_COMMIT_PHASE_TXN_DELETE
+ && (*txn_req)
+ ->req.commit_cfg.subscr_info
+ .xpath_subscr[id]
+ .subscribed) {
+ adapter = mgmt_be_get_adapter_by_id(id);
+ if (adapter)
+ mgmt_txn_send_be_txn_delete(
+ (*txn_req)->txn, adapter);
+ }
+
+ mgmt_txn_cleanup_be_cfg_batches((*txn_req)->txn,
+ id);
+ if ((*txn_req)->req.commit_cfg.batches) {
+ hash_clean((*txn_req)->req.commit_cfg.batches,
+ mgmt_txn_cfgbatch_hash_free);
+ hash_free((*txn_req)->req.commit_cfg.batches);
+ (*txn_req)->req.commit_cfg.batches = NULL;
+ }
+ }
+ break;
+ case MGMTD_TXN_PROC_GETCFG:
+ for (indx = 0; indx < (*txn_req)->req.get_data->num_xpaths;
+ indx++) {
+ if ((*txn_req)->req.get_data->xpaths[indx])
+ free((void *)(*txn_req)
+ ->req.get_data->xpaths[indx]);
+ }
+ req_list = &(*txn_req)->txn->get_cfg_reqs;
+ MGMTD_TXN_DBG("Deleting GETCFG Req: %p for Txn: %p",
+ *txn_req, (*txn_req)->txn);
+ if ((*txn_req)->req.get_data->reply)
+ XFREE(MTYPE_MGMTD_TXN_GETDATA_REPLY,
+ (*txn_req)->req.get_data->reply);
+ XFREE(MTYPE_MGMTD_TXN_GETDATA_REQ, (*txn_req)->req.get_data);
+ break;
+ case MGMTD_TXN_PROC_GETDATA:
+ for (indx = 0; indx < (*txn_req)->req.get_data->num_xpaths;
+ indx++) {
+ if ((*txn_req)->req.get_data->xpaths[indx])
+ free((void *)(*txn_req)
+ ->req.get_data->xpaths[indx]);
+ }
+ pending_list = &(*txn_req)->txn->pending_get_datas;
+ req_list = &(*txn_req)->txn->get_data_reqs;
+ MGMTD_TXN_DBG("Deleting GETDATA Req: %p for Txn: %p",
+ *txn_req, (*txn_req)->txn);
+ if ((*txn_req)->req.get_data->reply)
+ XFREE(MTYPE_MGMTD_TXN_GETDATA_REPLY,
+ (*txn_req)->req.get_data->reply);
+ XFREE(MTYPE_MGMTD_TXN_GETDATA_REQ, (*txn_req)->req.get_data);
+ break;
+ case MGMTD_TXN_COMMITCFG_TIMEOUT:
+ case MGMTD_TXN_CLEANUP:
+ break;
+ }
+
+ if ((*txn_req)->pending_be_proc && pending_list) {
+ mgmt_txn_reqs_del(pending_list, *txn_req);
+ MGMTD_TXN_DBG("Removed Req: %p from pending-list (left:%d)",
+ *txn_req, (int)mgmt_txn_reqs_count(pending_list));
+ } else if (req_list) {
+ mgmt_txn_reqs_del(req_list, *txn_req);
+ MGMTD_TXN_DBG("Removed Req: %p from request-list (left:%d)",
+ *txn_req, (int)mgmt_txn_reqs_count(req_list));
+ }
+
+ (*txn_req)->pending_be_proc = false;
+ MGMTD_TXN_UNLOCK(&(*txn_req)->txn);
+ XFREE(MTYPE_MGMTD_TXN_REQ, (*txn_req));
+ *txn_req = NULL;
+}
+
+static void mgmt_txn_process_set_cfg(struct event *thread)
+{
+ struct mgmt_txn_ctx *txn;
+ struct mgmt_txn_req *txn_req;
+ struct mgmt_ds_ctx *ds_ctx;
+ struct nb_config *nb_config;
+ char err_buf[1024];
+ bool error;
+ int num_processed = 0;
+ size_t left;
+ struct mgmt_commit_stats *cmt_stats;
+ int ret = 0;
+
+ txn = (struct mgmt_txn_ctx *)EVENT_ARG(thread);
+ assert(txn);
+ cmt_stats = mgmt_fe_get_session_commit_stats(txn->session_id);
+
+ MGMTD_TXN_DBG(
+ "Processing %d SET_CONFIG requests for Txn:%p Session:0x%llx",
+ (int)mgmt_txn_reqs_count(&txn->set_cfg_reqs), txn,
+ (unsigned long long)txn->session_id);
+
+ FOREACH_TXN_REQ_IN_LIST (&txn->set_cfg_reqs, txn_req) {
+ error = false;
+ assert(txn_req->req_event == MGMTD_TXN_PROC_SETCFG);
+ ds_ctx = txn_req->req.set_cfg->ds_ctx;
+ if (!ds_ctx) {
+ mgmt_fe_send_set_cfg_reply(
+ txn->session_id, txn->txn_id,
+ txn_req->req.set_cfg->ds_id, txn_req->req_id,
+ MGMTD_INTERNAL_ERROR, "No such datastore!",
+ txn_req->req.set_cfg->implicit_commit);
+ error = true;
+ goto mgmt_txn_process_set_cfg_done;
+ }
+
+ nb_config = mgmt_ds_get_nb_config(ds_ctx);
+ if (!nb_config) {
+ mgmt_fe_send_set_cfg_reply(
+ txn->session_id, txn->txn_id,
+ txn_req->req.set_cfg->ds_id, txn_req->req_id,
+ MGMTD_INTERNAL_ERROR,
+ "Unable to retrieve DS Config Tree!",
+ txn_req->req.set_cfg->implicit_commit);
+ error = true;
+ goto mgmt_txn_process_set_cfg_done;
+ }
+
+ error = false;
+ nb_candidate_edit_config_changes(
+ nb_config, txn_req->req.set_cfg->cfg_changes,
+ (size_t)txn_req->req.set_cfg->num_cfg_changes, NULL,
+ NULL, 0, err_buf, sizeof(err_buf), &error);
+ if (error) {
+ mgmt_fe_send_set_cfg_reply(
+ txn->session_id, txn->txn_id,
+ txn_req->req.set_cfg->ds_id, txn_req->req_id,
+ MGMTD_INTERNAL_ERROR, err_buf,
+ txn_req->req.set_cfg->implicit_commit);
+ goto mgmt_txn_process_set_cfg_done;
+ }
+
+ if (txn_req->req.set_cfg->implicit_commit) {
+ assert(mgmt_txn_reqs_count(&txn->set_cfg_reqs) == 1);
+ assert(txn_req->req.set_cfg->dst_ds_ctx);
+
+ ret = mgmt_ds_write_lock(
+ txn_req->req.set_cfg->dst_ds_ctx);
+ if (ret != 0) {
+ MGMTD_TXN_ERR(
+ "Failed to lock the DS %u for txn: %p session 0x%llx, errstr %s!",
+ txn_req->req.set_cfg->dst_ds_id, txn,
+ (unsigned long long)txn->session_id,
+ strerror(ret));
+ mgmt_txn_send_commit_cfg_reply(
+ txn, MGMTD_DS_LOCK_FAILED,
+ "Lock running DS before implicit commit failed!");
+ goto mgmt_txn_process_set_cfg_done;
+ }
+
+ mgmt_txn_send_commit_config_req(
+ txn->txn_id, txn_req->req_id,
+ txn_req->req.set_cfg->ds_id,
+ txn_req->req.set_cfg->ds_ctx,
+ txn_req->req.set_cfg->dst_ds_id,
+ txn_req->req.set_cfg->dst_ds_ctx, false,
+ false, true);
+
+ if (mm->perf_stats_en)
+ gettimeofday(&cmt_stats->last_start, NULL);
+ cmt_stats->commit_cnt++;
+ } else if (mgmt_fe_send_set_cfg_reply(
+ txn->session_id, txn->txn_id,
+ txn_req->req.set_cfg->ds_id,
+ txn_req->req_id, MGMTD_SUCCESS, NULL, false)
+ != 0) {
+ MGMTD_TXN_ERR(
+ "Failed to send SET_CONFIG_REPLY for txn %p session 0x%llx",
+ txn, (unsigned long long)txn->session_id);
+ error = true;
+ }
+
+ mgmt_txn_process_set_cfg_done:
+
+ /*
+ * Note: The following will remove it from the list as well.
+ */
+ mgmt_txn_req_free(&txn_req);
+
+ num_processed++;
+ if (num_processed == MGMTD_TXN_MAX_NUM_SETCFG_PROC)
+ break;
+ }
+
+ left = mgmt_txn_reqs_count(&txn->set_cfg_reqs);
+ if (left) {
+ MGMTD_TXN_DBG(
+ "Processed maximum number of Set-Config requests (%d/%d/%d). Rescheduling for rest.",
+ num_processed, MGMTD_TXN_MAX_NUM_SETCFG_PROC,
+ (int)left);
+ mgmt_txn_register_event(txn, MGMTD_TXN_PROC_SETCFG);
+ }
+}
+
+static int mgmt_txn_send_commit_cfg_reply(struct mgmt_txn_ctx *txn,
+ enum mgmt_result result,
+ const char *error_if_any)
+{
+ int ret = 0;
+ bool success, create_cmt_info_rec;
+
+ if (!txn->commit_cfg_req)
+ return -1;
+
+ success = (result == MGMTD_SUCCESS || result == MGMTD_NO_CFG_CHANGES);
+
+ if (!txn->commit_cfg_req->req.commit_cfg.implicit && txn->session_id
+ && mgmt_fe_send_commit_cfg_reply(
+ txn->session_id, txn->txn_id,
+ txn->commit_cfg_req->req.commit_cfg.src_ds_id,
+ txn->commit_cfg_req->req.commit_cfg.dst_ds_id,
+ txn->commit_cfg_req->req_id,
+ txn->commit_cfg_req->req.commit_cfg.validate_only,
+ result, error_if_any)
+ != 0) {
+ MGMTD_TXN_ERR(
+ "Failed to send COMMIT-CONFIG-REPLY for Txn %p Sessn 0x%llx",
+ txn, (unsigned long long)txn->session_id);
+ }
+
+ if (txn->commit_cfg_req->req.commit_cfg.implicit && txn->session_id
+ && mgmt_fe_send_set_cfg_reply(
+ txn->session_id, txn->txn_id,
+ txn->commit_cfg_req->req.commit_cfg.src_ds_id,
+ txn->commit_cfg_req->req_id,
+ success ? MGMTD_SUCCESS : MGMTD_INTERNAL_ERROR,
+ error_if_any, true)
+ != 0) {
+ MGMTD_TXN_ERR(
+ "Failed to send SET-CONFIG-REPLY for Txn %p Sessn 0x%llx",
+ txn, (unsigned long long)txn->session_id);
+ }
+
+ if (success) {
+ /* Stop the commit-timeout timer */
+ EVENT_OFF(txn->comm_cfg_timeout);
+
+ create_cmt_info_rec =
+ (result != MGMTD_NO_CFG_CHANGES &&
+ !txn->commit_cfg_req->req.commit_cfg.rollback);
+
+ /*
+ * Successful commit: Merge Src DS into Dst DS if and only if
+ * this was not a validate-only or abort request.
+ */
+ if ((txn->session_id
+ && !txn->commit_cfg_req->req.commit_cfg.validate_only
+ && !txn->commit_cfg_req->req.commit_cfg.abort)
+ || txn->commit_cfg_req->req.commit_cfg.rollback) {
+ mgmt_ds_copy_dss(txn->commit_cfg_req->req.commit_cfg
+ .src_ds_ctx,
+ txn->commit_cfg_req->req.commit_cfg
+ .dst_ds_ctx,
+ create_cmt_info_rec);
+ }
+
+ /*
+ * Restore Src DS back to Dest DS only through a commit abort
+ * request.
+ */
+ if (txn->session_id
+ && txn->commit_cfg_req->req.commit_cfg.abort)
+ mgmt_ds_copy_dss(txn->commit_cfg_req->req.commit_cfg
+ .dst_ds_ctx,
+ txn->commit_cfg_req->req.commit_cfg
+ .src_ds_ctx,
+ false);
+ } else {
+ /*
+ * The commit has failied. For implicit commit requests restore
+ * back the contents of the candidate DS.
+ */
+ if (txn->commit_cfg_req->req.commit_cfg.implicit)
+ mgmt_ds_copy_dss(txn->commit_cfg_req->req.commit_cfg
+ .dst_ds_ctx,
+ txn->commit_cfg_req->req.commit_cfg
+ .src_ds_ctx,
+ false);
+ }
+
+ if (txn->commit_cfg_req->req.commit_cfg.rollback) {
+ ret = mgmt_ds_unlock(
+ txn->commit_cfg_req->req.commit_cfg.dst_ds_ctx);
+ if (ret != 0)
+ MGMTD_TXN_ERR(
+ "Failed to unlock the dst DS during rollback : %s",
+ strerror(ret));
+
+ /*
+ * Resume processing the rollback command.
+ */
+ mgmt_history_rollback_complete(success);
+ }
+
+ if (txn->commit_cfg_req->req.commit_cfg.implicit)
+ if (mgmt_ds_unlock(
+ txn->commit_cfg_req->req.commit_cfg.dst_ds_ctx)
+ != 0)
+ MGMTD_TXN_ERR(
+ "Failed to unlock the dst DS during implicit : %s",
+ strerror(ret));
+
+ txn->commit_cfg_req->req.commit_cfg.cmt_stats = NULL;
+ mgmt_txn_req_free(&txn->commit_cfg_req);
+
+ /*
+ * The CONFIG Transaction should be destroyed from Frontend-adapter.
+ * But in case the transaction is not triggered from a front-end session
+ * we need to cleanup by itself.
+ */
+ if (!txn->session_id)
+ mgmt_txn_register_event(txn, MGMTD_TXN_CLEANUP);
+
+ return 0;
+}
+
+static void
+mgmt_move_txn_cfg_batch_to_next(struct mgmt_commit_cfg_req *cmtcfg_req,
+ struct mgmt_txn_be_cfg_batch *cfg_btch,
+ struct mgmt_txn_batches_head *src_list,
+ struct mgmt_txn_batches_head *dst_list,
+ bool update_commit_phase,
+ enum mgmt_commit_phase to_phase)
+{
+ mgmt_txn_batches_del(src_list, cfg_btch);
+
+ if (update_commit_phase) {
+ MGMTD_TXN_DBG("Move Txn-Id %p Batch-Id %p from '%s' --> '%s'",
+ cfg_btch->txn, cfg_btch,
+ mgmt_commit_phase2str(cfg_btch->comm_phase),
+ mgmt_txn_commit_phase_str(cfg_btch->txn, false));
+ cfg_btch->comm_phase = to_phase;
+ }
+
+ mgmt_txn_batches_add_tail(dst_list, cfg_btch);
+}
+
+static void mgmt_move_txn_cfg_batches(struct mgmt_txn_ctx *txn,
+ struct mgmt_commit_cfg_req *cmtcfg_req,
+ struct mgmt_txn_batches_head *src_list,
+ struct mgmt_txn_batches_head *dst_list,
+ bool update_commit_phase,
+ enum mgmt_commit_phase to_phase)
+{
+ struct mgmt_txn_be_cfg_batch *cfg_btch;
+
+ FOREACH_TXN_CFG_BATCH_IN_LIST (src_list, cfg_btch) {
+ mgmt_move_txn_cfg_batch_to_next(cmtcfg_req, cfg_btch, src_list,
+ dst_list, update_commit_phase,
+ to_phase);
+ }
+}
+
+static int
+mgmt_try_move_commit_to_next_phase(struct mgmt_txn_ctx *txn,
+ struct mgmt_commit_cfg_req *cmtcfg_req)
+{
+ struct mgmt_txn_batches_head *curr_list, *next_list;
+ enum mgmt_be_client_id id;
+
+ MGMTD_TXN_DBG("Txn-Id %p, Phase(current:'%s' next:'%s')", txn,
+ mgmt_txn_commit_phase_str(txn, true),
+ mgmt_txn_commit_phase_str(txn, false));
+
+ /*
+ * Check if all clients has moved to next phase or not.
+ */
+ FOREACH_MGMTD_BE_CLIENT_ID (id) {
+ if (cmtcfg_req->subscr_info.xpath_subscr[id].subscribed &&
+ mgmt_txn_batches_count(&cmtcfg_req->curr_batches[id])) {
+ /*
+ * There's atleast once client who hasn't moved to
+ * next phase.
+ *
+ * TODO: Need to re-think this design for the case
+ * set of validators for a given YANG data item is
+ * different from the set of notifiers for the same.
+ */
+ return -1;
+ }
+ }
+
+ MGMTD_TXN_DBG("Move entire Txn-Id %p from '%s' to '%s'", txn,
+ mgmt_txn_commit_phase_str(txn, true),
+ mgmt_txn_commit_phase_str(txn, false));
+
+ /*
+ * If we are here, it means all the clients has moved to next phase.
+ * So we can move the whole commit to next phase.
+ */
+ cmtcfg_req->curr_phase = cmtcfg_req->next_phase;
+ cmtcfg_req->next_phase++;
+ MGMTD_TXN_DBG(
+ "Move back all config batches for Txn %p from next to current branch",
+ txn);
+ FOREACH_MGMTD_BE_CLIENT_ID (id) {
+ curr_list = &cmtcfg_req->curr_batches[id];
+ next_list = &cmtcfg_req->next_batches[id];
+ mgmt_move_txn_cfg_batches(txn, cmtcfg_req, next_list,
+ curr_list, false, 0);
+ }
+
+ mgmt_txn_register_event(txn, MGMTD_TXN_PROC_COMMITCFG);
+
+ return 0;
+}
+
+static int
+mgmt_move_be_commit_to_next_phase(struct mgmt_txn_ctx *txn,
+ struct mgmt_be_client_adapter *adapter)
+{
+ struct mgmt_commit_cfg_req *cmtcfg_req;
+ struct mgmt_txn_batches_head *curr_list, *next_list;
+
+ if (txn->type != MGMTD_TXN_TYPE_CONFIG || !txn->commit_cfg_req)
+ return -1;
+
+ cmtcfg_req = &txn->commit_cfg_req->req.commit_cfg;
+
+ MGMTD_TXN_DBG(
+ "Move Txn-Id %p for '%s' Phase(current: '%s' next:'%s')", txn,
+ adapter->name, mgmt_txn_commit_phase_str(txn, true),
+ mgmt_txn_commit_phase_str(txn, false));
+
+ MGMTD_TXN_DBG(
+ "Move all config batches for '%s' from current to next list",
+ adapter->name);
+ curr_list = &cmtcfg_req->curr_batches[adapter->id];
+ next_list = &cmtcfg_req->next_batches[adapter->id];
+ mgmt_move_txn_cfg_batches(txn, cmtcfg_req, curr_list, next_list, true,
+ cmtcfg_req->next_phase);
+
+ MGMTD_TXN_DBG("Txn-Id %p, Phase(current:'%s' next:'%s')", txn,
+ mgmt_txn_commit_phase_str(txn, true),
+ mgmt_txn_commit_phase_str(txn, false));
+
+ /*
+ * Check if all clients has moved to next phase or not.
+ */
+ mgmt_try_move_commit_to_next_phase(txn, cmtcfg_req);
+
+ return 0;
+}
+
+static int mgmt_txn_create_config_batches(struct mgmt_txn_req *txn_req,
+ struct nb_config_cbs *changes)
+{
+ struct nb_config_cb *cb, *nxt;
+ struct nb_config_change *chg;
+ struct mgmt_txn_be_cfg_batch *cfg_btch;
+ struct mgmt_be_client_subscr_info subscr_info;
+ char *xpath = NULL, *value = NULL;
+ char err_buf[1024];
+ enum mgmt_be_client_id id;
+ struct mgmt_be_client_adapter *adapter;
+ struct mgmt_commit_cfg_req *cmtcfg_req;
+ bool found_validator;
+ int num_chgs = 0;
+ int xpath_len, value_len;
+
+ cmtcfg_req = &txn_req->req.commit_cfg;
+
+ RB_FOREACH_SAFE (cb, nb_config_cbs, changes, nxt) {
+ chg = (struct nb_config_change *)cb;
+
+ /*
+ * Could have directly pointed to xpath in nb_node.
+ * But dont want to mess with it now.
+ * xpath = chg->cb.nb_node->xpath;
+ */
+ xpath = lyd_path(chg->cb.dnode, LYD_PATH_STD, NULL, 0);
+ if (!xpath) {
+ (void)mgmt_txn_send_commit_cfg_reply(
+ txn_req->txn, MGMTD_INTERNAL_ERROR,
+ "Internal error! Could not get Xpath from Ds node!");
+ goto mgmt_txn_create_config_batches_failed;
+ }
+
+ value = (char *)lyd_get_value(chg->cb.dnode);
+ if (!value)
+ value = (char *)MGMTD_BE_CONTAINER_NODE_VAL;
+
+ MGMTD_TXN_DBG("XPATH: %s, Value: '%s'", xpath,
+ value ? value : "NIL");
+
+ if (mgmt_be_get_subscr_info_for_xpath(xpath, &subscr_info)
+ != 0) {
+ snprintf(err_buf, sizeof(err_buf),
+ "No backend module found for XPATH: '%s",
+ xpath);
+ (void)mgmt_txn_send_commit_cfg_reply(
+ txn_req->txn, MGMTD_INTERNAL_ERROR, err_buf);
+ goto mgmt_txn_create_config_batches_failed;
+ }
+
+ xpath_len = strlen(xpath) + 1;
+ value_len = strlen(value) + 1;
+ found_validator = false;
+ FOREACH_MGMTD_BE_CLIENT_ID (id) {
+ if (!subscr_info.xpath_subscr[id].validate_config
+ && !subscr_info.xpath_subscr[id].notify_config)
+ continue;
+
+ adapter = mgmt_be_get_adapter_by_id(id);
+ if (!adapter)
+ continue;
+
+ cfg_btch = cmtcfg_req->last_be_cfg_batch[id];
+ if (!cfg_btch
+ || (cfg_btch->num_cfg_data
+ == MGMTD_MAX_CFG_CHANGES_IN_BATCH)
+ || (cfg_btch->buf_space_left
+ < (xpath_len + value_len))) {
+ /* Allocate a new config batch */
+ cfg_btch = mgmt_txn_cfg_batch_alloc(
+ txn_req->txn, id, adapter);
+ }
+
+ cfg_btch->buf_space_left -= (xpath_len + value_len);
+ memcpy(&cfg_btch->xp_subscr[cfg_btch->num_cfg_data],
+ &subscr_info.xpath_subscr[id],
+ sizeof(cfg_btch->xp_subscr[0]));
+
+ mgmt_yang_cfg_data_req_init(
+ &cfg_btch->cfg_data[cfg_btch->num_cfg_data]);
+ cfg_btch->cfg_datap[cfg_btch->num_cfg_data] =
+ &cfg_btch->cfg_data[cfg_btch->num_cfg_data];
+
+ if (chg->cb.operation == NB_OP_DESTROY)
+ cfg_btch->cfg_data[cfg_btch->num_cfg_data]
+ .req_type =
+ MGMTD__CFG_DATA_REQ_TYPE__DELETE_DATA;
+ else
+ cfg_btch->cfg_data[cfg_btch->num_cfg_data]
+ .req_type =
+ MGMTD__CFG_DATA_REQ_TYPE__SET_DATA;
+
+ mgmt_yang_data_init(
+ &cfg_btch->data[cfg_btch->num_cfg_data]);
+ cfg_btch->cfg_data[cfg_btch->num_cfg_data].data =
+ &cfg_btch->data[cfg_btch->num_cfg_data];
+ cfg_btch->data[cfg_btch->num_cfg_data].xpath = xpath;
+ xpath = NULL;
+
+ mgmt_yang_data_value_init(
+ &cfg_btch->value[cfg_btch->num_cfg_data]);
+ cfg_btch->data[cfg_btch->num_cfg_data].value =
+ &cfg_btch->value[cfg_btch->num_cfg_data];
+ cfg_btch->value[cfg_btch->num_cfg_data].value_case =
+ MGMTD__YANG_DATA_VALUE__VALUE_ENCODED_STR_VAL;
+ cfg_btch->value[cfg_btch->num_cfg_data]
+ .encoded_str_val = value;
+ value = NULL;
+
+ if (subscr_info.xpath_subscr[id].validate_config)
+ found_validator = true;
+
+ cmtcfg_req->subscr_info.xpath_subscr[id].subscribed |=
+ subscr_info.xpath_subscr[id].subscribed;
+ MGMTD_TXN_DBG(
+ " -- %s, {V:%d, N:%d}, Batch: %p, Item:%d",
+ adapter->name,
+ subscr_info.xpath_subscr[id].validate_config,
+ subscr_info.xpath_subscr[id].notify_config,
+ cfg_btch, (int)cfg_btch->num_cfg_data);
+
+ cfg_btch->num_cfg_data++;
+ num_chgs++;
+ }
+
+ if (!found_validator) {
+ snprintf(err_buf, sizeof(err_buf),
+ "No validator module found for XPATH: '%s",
+ xpath);
+ MGMTD_TXN_ERR("***** %s", err_buf);
+ }
+ }
+
+ cmtcfg_req->cmt_stats->last_batch_cnt = num_chgs;
+ if (!num_chgs) {
+ (void)mgmt_txn_send_commit_cfg_reply(
+ txn_req->txn, MGMTD_NO_CFG_CHANGES,
+ "No changes found to commit!");
+ goto mgmt_txn_create_config_batches_failed;
+ }
+
+ cmtcfg_req->next_phase = MGMTD_COMMIT_PHASE_TXN_CREATE;
+ return 0;
+
+mgmt_txn_create_config_batches_failed:
+
+ if (xpath)
+ free(xpath);
+
+ return -1;
+}
+
+static int mgmt_txn_prepare_config(struct mgmt_txn_ctx *txn)
+{
+ struct nb_context nb_ctx;
+ struct nb_config *nb_config;
+ struct nb_config_cbs changes;
+ struct nb_config_cbs *cfg_chgs = NULL;
+ int ret;
+ bool del_cfg_chgs = false;
+
+ ret = 0;
+ memset(&nb_ctx, 0, sizeof(nb_ctx));
+ memset(&changes, 0, sizeof(changes));
+ if (txn->commit_cfg_req->req.commit_cfg.cfg_chgs) {
+ cfg_chgs = txn->commit_cfg_req->req.commit_cfg.cfg_chgs;
+ del_cfg_chgs = true;
+ goto mgmt_txn_prep_config_validation_done;
+ }
+
+ if (txn->commit_cfg_req->req.commit_cfg.src_ds_id
+ != MGMTD_DS_CANDIDATE) {
+ (void)mgmt_txn_send_commit_cfg_reply(
+ txn, MGMTD_INVALID_PARAM,
+ "Source DS cannot be any other than CANDIDATE!");
+ ret = -1;
+ goto mgmt_txn_prepare_config_done;
+ }
+
+ if (txn->commit_cfg_req->req.commit_cfg.dst_ds_id
+ != MGMTD_DS_RUNNING) {
+ (void)mgmt_txn_send_commit_cfg_reply(
+ txn, MGMTD_INVALID_PARAM,
+ "Destination DS cannot be any other than RUNNING!");
+ ret = -1;
+ goto mgmt_txn_prepare_config_done;
+ }
+
+ if (!txn->commit_cfg_req->req.commit_cfg.src_ds_ctx) {
+ (void)mgmt_txn_send_commit_cfg_reply(
+ txn, MGMTD_INVALID_PARAM, "No such source datastore!");
+ ret = -1;
+ goto mgmt_txn_prepare_config_done;
+ }
+
+ if (!txn->commit_cfg_req->req.commit_cfg.dst_ds_ctx) {
+ (void)mgmt_txn_send_commit_cfg_reply(
+ txn, MGMTD_INVALID_PARAM,
+ "No such destination datastore!");
+ ret = -1;
+ goto mgmt_txn_prepare_config_done;
+ }
+
+ if (txn->commit_cfg_req->req.commit_cfg.abort) {
+ /*
+ * This is a commit abort request. Return back success.
+ * That should trigger a restore of Candidate datastore to
+ * Running.
+ */
+ (void)mgmt_txn_send_commit_cfg_reply(txn, MGMTD_SUCCESS,
+ NULL);
+ goto mgmt_txn_prepare_config_done;
+ }
+
+ nb_config = mgmt_ds_get_nb_config(
+ txn->commit_cfg_req->req.commit_cfg.src_ds_ctx);
+ if (!nb_config) {
+ (void)mgmt_txn_send_commit_cfg_reply(
+ txn, MGMTD_INTERNAL_ERROR,
+ "Unable to retrieve Commit DS Config Tree!");
+ ret = -1;
+ goto mgmt_txn_prepare_config_done;
+ }
+
+ /*
+ * Check for diffs from scratch buffer. If found empty
+ * get the diff from Candidate DS itself.
+ */
+ cfg_chgs = &nb_config->cfg_chgs;
+ if (RB_EMPTY(nb_config_cbs, cfg_chgs)) {
+ /*
+ * This could be the case when the config is directly
+ * loaded onto the candidate DS from a file. Get the
+ * diff from a full comparison of the candidate and
+ * running DSs.
+ */
+ nb_config_diff(
+ mgmt_ds_get_nb_config(txn->commit_cfg_req->req
+ .commit_cfg.dst_ds_ctx),
+ nb_config, &changes);
+ cfg_chgs = &changes;
+ del_cfg_chgs = true;
+ }
+
+ if (RB_EMPTY(nb_config_cbs, cfg_chgs)) {
+ /*
+ * This means there's no changes to commit whatsoever
+ * is the source of the changes in config.
+ */
+ (void)mgmt_txn_send_commit_cfg_reply(
+ txn, MGMTD_NO_CFG_CHANGES,
+ "No changes found to be committed!");
+ ret = -1;
+ goto mgmt_txn_prepare_config_done;
+ }
+
+#ifdef MGMTD_LOCAL_VALIDATIONS_ENABLED
+ if (mm->perf_stats_en)
+ gettimeofday(&txn->commit_cfg_req->req.commit_cfg.cmt_stats
+ ->validate_start,
+ NULL);
+ /*
+ * Validate YANG contents of the source DS and get the diff
+ * between source and destination DS contents.
+ */
+ char err_buf[1024] = {0};
+ nb_ctx.client = NB_CLIENT_MGMTD_SERVER;
+ nb_ctx.user = (void *)txn;
+ ret = nb_candidate_validate_yang(nb_config, false, err_buf,
+ sizeof(err_buf) - 1);
+ if (ret != NB_OK) {
+ if (strncmp(err_buf, " ", strlen(err_buf)) == 0)
+ strlcpy(err_buf, "Validation failed", sizeof(err_buf));
+ (void)mgmt_txn_send_commit_cfg_reply(txn, MGMTD_INVALID_PARAM,
+ err_buf);
+ ret = -1;
+ goto mgmt_txn_prepare_config_done;
+ }
+ /*
+ * Perform application level validations locally on the MGMTD
+ * process by calling application specific validation routines
+ * loaded onto MGMTD process using libraries.
+ */
+ ret = nb_candidate_validate_code(&nb_ctx, nb_config, &changes, err_buf,
+ sizeof(err_buf) - 1);
+ if (ret != NB_OK) {
+ if (strncmp(err_buf, " ", strlen(err_buf)) == 0)
+ strlcpy(err_buf, "Validation failed", sizeof(err_buf));
+ (void)mgmt_txn_send_commit_cfg_reply(txn, MGMTD_INVALID_PARAM,
+ err_buf);
+ ret = -1;
+ goto mgmt_txn_prepare_config_done;
+ }
+
+ if (txn->commit_cfg_req->req.commit_cfg.validate_only) {
+ /*
+ * This was a validate-only COMMIT request return success.
+ */
+ (void)mgmt_txn_send_commit_cfg_reply(txn, MGMTD_SUCCESS,
+ NULL);
+ goto mgmt_txn_prepare_config_done;
+ }
+#endif /* ifdef MGMTD_LOCAL_VALIDATIONS_ENABLED */
+
+mgmt_txn_prep_config_validation_done:
+
+ if (mm->perf_stats_en)
+ gettimeofday(&txn->commit_cfg_req->req.commit_cfg.cmt_stats
+ ->prep_cfg_start,
+ NULL);
+
+ /*
+ * Iterate over the diffs and create ordered batches of config
+ * commands to be validated.
+ */
+ ret = mgmt_txn_create_config_batches(txn->commit_cfg_req, cfg_chgs);
+ if (ret != 0) {
+ ret = -1;
+ goto mgmt_txn_prepare_config_done;
+ }
+
+ /* Move to the Transaction Create Phase */
+ txn->commit_cfg_req->req.commit_cfg.curr_phase =
+ MGMTD_COMMIT_PHASE_TXN_CREATE;
+ mgmt_txn_register_event(txn, MGMTD_TXN_PROC_COMMITCFG);
+
+ /*
+ * Start the COMMIT Timeout Timer to abort Txn if things get stuck at
+ * backend.
+ */
+ mgmt_txn_register_event(txn, MGMTD_TXN_COMMITCFG_TIMEOUT);
+mgmt_txn_prepare_config_done:
+
+ if (cfg_chgs && del_cfg_chgs)
+ nb_config_diff_del_changes(cfg_chgs);
+
+ return ret;
+}
+
+static int mgmt_txn_send_be_txn_create(struct mgmt_txn_ctx *txn)
+{
+ enum mgmt_be_client_id id;
+ struct mgmt_be_client_adapter *adapter;
+ struct mgmt_commit_cfg_req *cmtcfg_req;
+ struct mgmt_txn_be_cfg_batch *cfg_btch;
+
+ assert(txn->type == MGMTD_TXN_TYPE_CONFIG && txn->commit_cfg_req);
+
+ cmtcfg_req = &txn->commit_cfg_req->req.commit_cfg;
+ FOREACH_MGMTD_BE_CLIENT_ID (id) {
+ if (cmtcfg_req->subscr_info.xpath_subscr[id].subscribed) {
+ adapter = mgmt_be_get_adapter_by_id(id);
+ if (mgmt_be_create_txn(adapter, txn->txn_id)
+ != 0) {
+ (void)mgmt_txn_send_commit_cfg_reply(
+ txn, MGMTD_INTERNAL_ERROR,
+ "Could not send TXN_CREATE to backend adapter");
+ return -1;
+ }
+
+ FOREACH_TXN_CFG_BATCH_IN_LIST (
+ &txn->commit_cfg_req->req.commit_cfg
+ .curr_batches[id],
+ cfg_btch)
+ cfg_btch->comm_phase =
+ MGMTD_COMMIT_PHASE_TXN_CREATE;
+ }
+ }
+
+ txn->commit_cfg_req->req.commit_cfg.next_phase =
+ MGMTD_COMMIT_PHASE_SEND_CFG;
+
+ /*
+ * Dont move the commit to next phase yet. Wait for the TXN_REPLY to
+ * come back.
+ */
+
+ MGMTD_TXN_DBG(
+ "Txn:%p Session:0x%llx, Phase(Current:'%s', Next: '%s')", txn,
+ (unsigned long long)txn->session_id,
+ mgmt_txn_commit_phase_str(txn, true),
+ mgmt_txn_commit_phase_str(txn, false));
+
+ return 0;
+}
+
+static int
+mgmt_txn_send_be_cfg_data(struct mgmt_txn_ctx *txn,
+ struct mgmt_be_client_adapter *adapter)
+{
+ struct mgmt_commit_cfg_req *cmtcfg_req;
+ struct mgmt_txn_be_cfg_batch *cfg_btch;
+ struct mgmt_be_cfgreq cfg_req = {0};
+ size_t num_batches, indx;
+
+ assert(txn->type == MGMTD_TXN_TYPE_CONFIG && txn->commit_cfg_req);
+
+ cmtcfg_req = &txn->commit_cfg_req->req.commit_cfg;
+ assert(cmtcfg_req->subscr_info.xpath_subscr[adapter->id].subscribed);
+
+ indx = 0;
+ num_batches =
+ mgmt_txn_batches_count(&cmtcfg_req->curr_batches[adapter->id]);
+ FOREACH_TXN_CFG_BATCH_IN_LIST (&cmtcfg_req->curr_batches[adapter->id],
+ cfg_btch) {
+ assert(cmtcfg_req->next_phase == MGMTD_COMMIT_PHASE_SEND_CFG);
+
+ cfg_req.cfgdata_reqs = cfg_btch->cfg_datap;
+ cfg_req.num_reqs = cfg_btch->num_cfg_data;
+ indx++;
+ if (mgmt_be_send_cfg_data_create_req(
+ adapter, txn->txn_id, cfg_btch->batch_id, &cfg_req,
+ indx == num_batches ? true : false)
+ != 0) {
+ (void)mgmt_txn_send_commit_cfg_reply(
+ txn, MGMTD_INTERNAL_ERROR,
+ "Internal Error! Could not send config data to backend!");
+ MGMTD_TXN_ERR(
+ "Could not send CFGDATA_CREATE for Txn %p Batch %p to client '%s",
+ txn, cfg_btch, adapter->name);
+ return -1;
+ }
+
+ cmtcfg_req->cmt_stats->last_num_cfgdata_reqs++;
+ mgmt_move_txn_cfg_batch_to_next(
+ cmtcfg_req, cfg_btch,
+ &cmtcfg_req->curr_batches[adapter->id],
+ &cmtcfg_req->next_batches[adapter->id], true,
+ MGMTD_COMMIT_PHASE_SEND_CFG);
+ }
+
+ /*
+ * This could ne the last Backend Client to send CFGDATA_CREATE_REQ to.
+ * Try moving the commit to next phase.
+ */
+ mgmt_try_move_commit_to_next_phase(txn, cmtcfg_req);
+
+ return 0;
+}
+
+static int
+mgmt_txn_send_be_txn_delete(struct mgmt_txn_ctx *txn,
+ struct mgmt_be_client_adapter *adapter)
+{
+ struct mgmt_commit_cfg_req *cmtcfg_req;
+ struct mgmt_txn_be_cfg_batch *cfg_btch;
+
+ assert(txn->type == MGMTD_TXN_TYPE_CONFIG && txn->commit_cfg_req);
+
+ cmtcfg_req = &txn->commit_cfg_req->req.commit_cfg;
+ if (cmtcfg_req->subscr_info.xpath_subscr[adapter->id].subscribed) {
+ adapter = mgmt_be_get_adapter_by_id(adapter->id);
+ (void)mgmt_be_destroy_txn(adapter, txn->txn_id);
+
+ FOREACH_TXN_CFG_BATCH_IN_LIST (
+ &txn->commit_cfg_req->req.commit_cfg
+ .curr_batches[adapter->id],
+ cfg_btch)
+ cfg_btch->comm_phase = MGMTD_COMMIT_PHASE_TXN_DELETE;
+ }
+
+ return 0;
+}
+
+static void mgmt_txn_cfg_commit_timedout(struct event *thread)
+{
+ struct mgmt_txn_ctx *txn;
+
+ txn = (struct mgmt_txn_ctx *)EVENT_ARG(thread);
+ assert(txn);
+
+ assert(txn->type == MGMTD_TXN_TYPE_CONFIG);
+
+ if (!txn->commit_cfg_req)
+ return;
+
+ MGMTD_TXN_ERR(
+ "Backend operations for Config Txn %p has timedout! Aborting commit!!",
+ txn);
+
+ /*
+ * Send a COMMIT_CONFIG_REPLY with failure.
+ * NOTE: The transaction cleanup will be triggered from Front-end
+ * adapter.
+ */
+ mgmt_txn_send_commit_cfg_reply(
+ txn, MGMTD_INTERNAL_ERROR,
+ "Operation on the backend timed-out. Aborting commit!");
+}
+
+/*
+ * Send CFG_APPLY_REQs to all the backend client.
+ *
+ * NOTE: This is always dispatched when all CFGDATA_CREATE_REQs
+ * for all backend clients has been generated. Please see
+ * mgmt_txn_register_event() and mgmt_txn_process_commit_cfg()
+ * for details.
+ */
+static int mgmt_txn_send_be_cfg_apply(struct mgmt_txn_ctx *txn)
+{
+ enum mgmt_be_client_id id;
+ struct mgmt_be_client_adapter *adapter;
+ struct mgmt_commit_cfg_req *cmtcfg_req;
+ struct mgmt_txn_batches_head *btch_list;
+ struct mgmt_txn_be_cfg_batch *cfg_btch;
+
+ assert(txn->type == MGMTD_TXN_TYPE_CONFIG && txn->commit_cfg_req);
+
+ cmtcfg_req = &txn->commit_cfg_req->req.commit_cfg;
+ if (cmtcfg_req->validate_only) {
+ /*
+ * If this was a validate-only COMMIT request return success.
+ */
+ (void)mgmt_txn_send_commit_cfg_reply(txn, MGMTD_SUCCESS,
+ NULL);
+ return 0;
+ }
+
+ FOREACH_MGMTD_BE_CLIENT_ID (id) {
+ if (cmtcfg_req->subscr_info.xpath_subscr[id].notify_config) {
+ adapter = mgmt_be_get_adapter_by_id(id);
+ if (!adapter)
+ return -1;
+
+ btch_list = &cmtcfg_req->curr_batches[id];
+ if (mgmt_be_send_cfg_apply_req(adapter, txn->txn_id)
+ != 0) {
+ (void)mgmt_txn_send_commit_cfg_reply(
+ txn, MGMTD_INTERNAL_ERROR,
+ "Could not send CFG_APPLY_REQ to backend adapter");
+ return -1;
+ }
+ cmtcfg_req->cmt_stats->last_num_apply_reqs++;
+
+ UNSET_FLAG(adapter->flags,
+ MGMTD_BE_ADAPTER_FLAGS_CFG_SYNCED);
+
+ FOREACH_TXN_CFG_BATCH_IN_LIST (btch_list, cfg_btch)
+ cfg_btch->comm_phase =
+ MGMTD_COMMIT_PHASE_APPLY_CFG;
+ }
+ }
+
+ txn->commit_cfg_req->req.commit_cfg.next_phase =
+ MGMTD_COMMIT_PHASE_TXN_DELETE;
+
+ /*
+ * Dont move the commit to next phase yet. Wait for all VALIDATE_REPLIES
+ * to come back.
+ */
+
+ return 0;
+}
+
+static void mgmt_txn_process_commit_cfg(struct event *thread)
+{
+ struct mgmt_txn_ctx *txn;
+ struct mgmt_commit_cfg_req *cmtcfg_req;
+
+ txn = (struct mgmt_txn_ctx *)EVENT_ARG(thread);
+ assert(txn);
+
+ MGMTD_TXN_DBG(
+ "Processing COMMIT_CONFIG for Txn:%p Session:0x%llx, Phase(Current:'%s', Next: '%s')",
+ txn, (unsigned long long)txn->session_id,
+ mgmt_txn_commit_phase_str(txn, true),
+ mgmt_txn_commit_phase_str(txn, false));
+
+ assert(txn->commit_cfg_req);
+ cmtcfg_req = &txn->commit_cfg_req->req.commit_cfg;
+ switch (cmtcfg_req->curr_phase) {
+ case MGMTD_COMMIT_PHASE_PREPARE_CFG:
+ mgmt_txn_prepare_config(txn);
+ break;
+ case MGMTD_COMMIT_PHASE_TXN_CREATE:
+ if (mm->perf_stats_en)
+ gettimeofday(&cmtcfg_req->cmt_stats->txn_create_start,
+ NULL);
+ /*
+ * Send TXN_CREATE_REQ to all Backend now.
+ */
+ mgmt_txn_send_be_txn_create(txn);
+ break;
+ case MGMTD_COMMIT_PHASE_SEND_CFG:
+ if (mm->perf_stats_en)
+ gettimeofday(&cmtcfg_req->cmt_stats->send_cfg_start,
+ NULL);
+ /*
+ * All CFGDATA_CREATE_REQ should have been sent to
+ * Backend by now.
+ */
+#ifndef MGMTD_LOCAL_VALIDATIONS_ENABLED
+ assert(cmtcfg_req->next_phase == MGMTD_COMMIT_PHASE_APPLY_CFG);
+ MGMTD_TXN_DBG(
+ "Txn:%p Session:0x%llx, trigger sending CFG_VALIDATE_REQ to all backend clients",
+ txn, (unsigned long long)txn->session_id);
+#else /* ifndef MGMTD_LOCAL_VALIDATIONS_ENABLED */
+ assert(cmtcfg_req->next_phase == MGMTD_COMMIT_PHASE_APPLY_CFG);
+ MGMTD_TXN_DBG(
+ "Txn:%p Session:0x%llx, trigger sending CFG_APPLY_REQ to all backend clients",
+ txn, (unsigned long long)txn->session_id);
+#endif /* ifndef MGMTD_LOCAL_VALIDATIONS_ENABLED */
+ break;
+ case MGMTD_COMMIT_PHASE_APPLY_CFG:
+ if (mm->perf_stats_en)
+ gettimeofday(&cmtcfg_req->cmt_stats->apply_cfg_start,
+ NULL);
+ /*
+ * We should have received successful CFG_VALIDATE_REPLY from
+ * all concerned Backend Clients by now. Send out the
+ * CFG_APPLY_REQs now.
+ */
+ mgmt_txn_send_be_cfg_apply(txn);
+ break;
+ case MGMTD_COMMIT_PHASE_TXN_DELETE:
+ if (mm->perf_stats_en)
+ gettimeofday(&cmtcfg_req->cmt_stats->txn_del_start,
+ NULL);
+ /*
+ * We would have sent TXN_DELETE_REQ to all backend by now.
+ * Send a successful CONFIG_COMMIT_REPLY back to front-end.
+ * NOTE: This should also trigger DS merge/unlock and Txn
+ * cleanup. Please see mgmt_fe_send_commit_cfg_reply() for
+ * more details.
+ */
+ EVENT_OFF(txn->comm_cfg_timeout);
+ mgmt_txn_send_commit_cfg_reply(txn, MGMTD_SUCCESS, NULL);
+ break;
+ case MGMTD_COMMIT_PHASE_MAX:
+ break;
+ }
+
+ MGMTD_TXN_DBG(
+ "Txn:%p Session:0x%llx, Phase updated to (Current:'%s', Next: '%s')",
+ txn, (unsigned long long)txn->session_id,
+ mgmt_txn_commit_phase_str(txn, true),
+ mgmt_txn_commit_phase_str(txn, false));
+}
+
+static void mgmt_init_get_data_reply(struct mgmt_get_data_reply *get_reply)
+{
+ size_t indx;
+
+ for (indx = 0; indx < array_size(get_reply->reply_data); indx++)
+ get_reply->reply_datap[indx] = &get_reply->reply_data[indx];
+}
+
+static void mgmt_reset_get_data_reply(struct mgmt_get_data_reply *get_reply)
+{
+ int indx;
+
+ for (indx = 0; indx < get_reply->num_reply; indx++) {
+ if (get_reply->reply_xpathp[indx]) {
+ free(get_reply->reply_xpathp[indx]);
+ get_reply->reply_xpathp[indx] = 0;
+ }
+ if (get_reply->reply_data[indx].xpath) {
+ zlog_debug("%s free xpath %p", __func__,
+ get_reply->reply_data[indx].xpath);
+ free(get_reply->reply_data[indx].xpath);
+ get_reply->reply_data[indx].xpath = 0;
+ }
+ }
+
+ get_reply->num_reply = 0;
+ memset(&get_reply->data_reply, 0, sizeof(get_reply->data_reply));
+ memset(&get_reply->reply_data, 0, sizeof(get_reply->reply_data));
+ memset(&get_reply->reply_datap, 0, sizeof(get_reply->reply_datap));
+
+ memset(&get_reply->reply_value, 0, sizeof(get_reply->reply_value));
+
+ mgmt_init_get_data_reply(get_reply);
+}
+
+static void mgmt_reset_get_data_reply_buf(struct mgmt_get_data_req *get_data)
+{
+ if (get_data->reply)
+ mgmt_reset_get_data_reply(get_data->reply);
+}
+
+static void mgmt_txn_send_getcfg_reply_data(struct mgmt_txn_req *txn_req,
+ struct mgmt_get_data_req *get_req)
+{
+ struct mgmt_get_data_reply *get_reply;
+ Mgmtd__YangDataReply *data_reply;
+
+ get_reply = get_req->reply;
+ if (!get_reply)
+ return;
+
+ data_reply = &get_reply->data_reply;
+ mgmt_yang_data_reply_init(data_reply);
+ data_reply->n_data = get_reply->num_reply;
+ data_reply->data = get_reply->reply_datap;
+ data_reply->next_indx =
+ (!get_reply->last_batch ? get_req->total_reply : -1);
+
+ MGMTD_TXN_DBG("Sending %d Get-Config/Data replies (next-idx:%lld)",
+ (int) data_reply->n_data,
+ (long long)data_reply->next_indx);
+
+ switch (txn_req->req_event) {
+ case MGMTD_TXN_PROC_GETCFG:
+ if (mgmt_fe_send_get_cfg_reply(
+ txn_req->txn->session_id, txn_req->txn->txn_id,
+ get_req->ds_id, txn_req->req_id, MGMTD_SUCCESS,
+ data_reply, NULL)
+ != 0) {
+ MGMTD_TXN_ERR(
+ "Failed to send GET-CONFIG-REPLY for Txn %p, Sessn: 0x%llx, Req: %llu",
+ txn_req->txn,
+ (unsigned long long)txn_req->txn->session_id,
+ (unsigned long long)txn_req->req_id);
+ }
+ break;
+ case MGMTD_TXN_PROC_GETDATA:
+ if (mgmt_fe_send_get_data_reply(
+ txn_req->txn->session_id, txn_req->txn->txn_id,
+ get_req->ds_id, txn_req->req_id, MGMTD_SUCCESS,
+ data_reply, NULL)
+ != 0) {
+ MGMTD_TXN_ERR(
+ "Failed to send GET-DATA-REPLY for Txn %p, Sessn: 0x%llx, Req: %llu",
+ txn_req->txn,
+ (unsigned long long)txn_req->txn->session_id,
+ (unsigned long long)txn_req->req_id);
+ }
+ break;
+ case MGMTD_TXN_PROC_SETCFG:
+ case MGMTD_TXN_PROC_COMMITCFG:
+ case MGMTD_TXN_COMMITCFG_TIMEOUT:
+ case MGMTD_TXN_CLEANUP:
+ MGMTD_TXN_ERR("Invalid Txn-Req-Event %u",
+ txn_req->req_event);
+ break;
+ }
+
+ /*
+ * Reset reply buffer for next reply.
+ */
+ mgmt_reset_get_data_reply_buf(get_req);
+}
+
+static void mgmt_txn_iter_and_send_get_cfg_reply(struct mgmt_ds_ctx *ds_ctx,
+ char *xpath,
+ struct lyd_node *node,
+ struct nb_node *nb_node,
+ void *ctx)
+{
+ struct mgmt_txn_req *txn_req;
+ struct mgmt_get_data_req *get_req;
+ struct mgmt_get_data_reply *get_reply;
+ Mgmtd__YangData *data;
+ Mgmtd__YangDataValue *data_value;
+
+ txn_req = (struct mgmt_txn_req *)ctx;
+ if (!txn_req)
+ goto mgmtd_ignore_get_cfg_reply_data;
+
+ if (!(node->schema->nodetype & LYD_NODE_TERM))
+ goto mgmtd_ignore_get_cfg_reply_data;
+
+ assert(txn_req->req_event == MGMTD_TXN_PROC_GETCFG
+ || txn_req->req_event == MGMTD_TXN_PROC_GETDATA);
+
+ get_req = txn_req->req.get_data;
+ assert(get_req);
+ get_reply = get_req->reply;
+ data = &get_reply->reply_data[get_reply->num_reply];
+ data_value = &get_reply->reply_value[get_reply->num_reply];
+
+ mgmt_yang_data_init(data);
+ data->xpath = xpath;
+ mgmt_yang_data_value_init(data_value);
+ data_value->value_case = MGMTD__YANG_DATA_VALUE__VALUE_ENCODED_STR_VAL;
+ data_value->encoded_str_val = (char *)lyd_get_value(node);
+ data->value = data_value;
+
+ get_reply->num_reply++;
+ get_req->total_reply++;
+ MGMTD_TXN_DBG(" [%d] XPATH: '%s', Value: '%s'", get_req->total_reply,
+ data->xpath, data_value->encoded_str_val);
+
+ if (get_reply->num_reply == MGMTD_MAX_NUM_DATA_REPLY_IN_BATCH)
+ mgmt_txn_send_getcfg_reply_data(txn_req, get_req);
+
+ return;
+
+mgmtd_ignore_get_cfg_reply_data:
+ if (xpath)
+ free(xpath);
+}
+
+static int mgmt_txn_get_config(struct mgmt_txn_ctx *txn,
+ struct mgmt_txn_req *txn_req,
+ struct mgmt_ds_ctx *ds_ctx)
+{
+ struct mgmt_txn_reqs_head *req_list = NULL;
+ struct mgmt_txn_reqs_head *pending_list = NULL;
+ int indx;
+ struct mgmt_get_data_req *get_data;
+ struct mgmt_get_data_reply *get_reply;
+
+ switch (txn_req->req_event) {
+ case MGMTD_TXN_PROC_GETCFG:
+ req_list = &txn->get_cfg_reqs;
+ break;
+ case MGMTD_TXN_PROC_GETDATA:
+ req_list = &txn->get_data_reqs;
+ break;
+ case MGMTD_TXN_PROC_SETCFG:
+ case MGMTD_TXN_PROC_COMMITCFG:
+ case MGMTD_TXN_COMMITCFG_TIMEOUT:
+ case MGMTD_TXN_CLEANUP:
+ assert(!"Wrong txn request type!");
+ break;
+ }
+
+ get_data = txn_req->req.get_data;
+
+ if (!get_data->reply) {
+ get_data->reply = XCALLOC(MTYPE_MGMTD_TXN_GETDATA_REPLY,
+ sizeof(struct mgmt_get_data_reply));
+ if (!get_data->reply) {
+ mgmt_fe_send_get_cfg_reply(
+ txn->session_id, txn->txn_id,
+ get_data->ds_id, txn_req->req_id,
+ MGMTD_INTERNAL_ERROR, NULL,
+ "Internal error: Unable to allocate reply buffers!");
+ goto mgmt_txn_get_config_failed;
+ }
+ }
+
+ /*
+ * Read data contents from the DS and respond back directly.
+ * No need to go to backend for getting data.
+ */
+ get_reply = get_data->reply;
+ for (indx = 0; indx < get_data->num_xpaths; indx++) {
+ MGMTD_TXN_DBG("Trying to get all data under '%s'",
+ get_data->xpaths[indx]);
+ mgmt_init_get_data_reply(get_reply);
+ if (mgmt_ds_iter_data(get_data->ds_ctx, get_data->xpaths[indx],
+ mgmt_txn_iter_and_send_get_cfg_reply,
+ (void *)txn_req, true)
+ == -1) {
+ MGMTD_TXN_DBG("Invalid Xpath '%s",
+ get_data->xpaths[indx]);
+ mgmt_fe_send_get_cfg_reply(
+ txn->session_id, txn->txn_id,
+ get_data->ds_id, txn_req->req_id,
+ MGMTD_INTERNAL_ERROR, NULL, "Invalid xpath");
+ goto mgmt_txn_get_config_failed;
+ }
+ MGMTD_TXN_DBG("Got %d remaining data-replies for xpath '%s'",
+ get_reply->num_reply, get_data->xpaths[indx]);
+ get_reply->last_batch = true;
+ mgmt_txn_send_getcfg_reply_data(txn_req, get_data);
+ }
+
+mgmt_txn_get_config_failed:
+
+ if (pending_list) {
+ /*
+ * Move the transaction to corresponding pending list.
+ */
+ if (req_list)
+ mgmt_txn_reqs_del(req_list, txn_req);
+ txn_req->pending_be_proc = true;
+ mgmt_txn_reqs_add_tail(pending_list, txn_req);
+ MGMTD_TXN_DBG(
+ "Moved Req: %p for Txn: %p from Req-List to Pending-List",
+ txn_req, txn_req->txn);
+ } else {
+ /*
+ * Delete the txn request. It will also remove it from request
+ * list.
+ */
+ mgmt_txn_req_free(&txn_req);
+ }
+
+ return 0;
+}
+
+static void mgmt_txn_process_get_cfg(struct event *thread)
+{
+ struct mgmt_txn_ctx *txn;
+ struct mgmt_txn_req *txn_req;
+ struct mgmt_ds_ctx *ds_ctx;
+ int num_processed = 0;
+ bool error;
+
+ txn = (struct mgmt_txn_ctx *)EVENT_ARG(thread);
+ assert(txn);
+
+ MGMTD_TXN_DBG(
+ "Processing %d GET_CONFIG requests for Txn:%p Session:0x%llx",
+ (int)mgmt_txn_reqs_count(&txn->get_cfg_reqs), txn,
+ (unsigned long long)txn->session_id);
+
+ FOREACH_TXN_REQ_IN_LIST (&txn->get_cfg_reqs, txn_req) {
+ error = false;
+ assert(txn_req->req_event == MGMTD_TXN_PROC_GETCFG);
+ ds_ctx = txn_req->req.get_data->ds_ctx;
+ if (!ds_ctx) {
+ mgmt_fe_send_get_cfg_reply(
+ txn->session_id, txn->txn_id,
+ txn_req->req.get_data->ds_id, txn_req->req_id,
+ MGMTD_INTERNAL_ERROR, NULL,
+ "No such datastore!");
+ error = true;
+ goto mgmt_txn_process_get_cfg_done;
+ }
+
+ if (mgmt_txn_get_config(txn, txn_req, ds_ctx) != 0) {
+ MGMTD_TXN_ERR(
+ "Unable to retrieve Config from DS %d for Txn %p, Sessn: 0x%llx, Req: %llu!",
+ txn_req->req.get_data->ds_id, txn,
+ (unsigned long long)txn->session_id,
+ (unsigned long long)txn_req->req_id);
+ error = true;
+ }
+
+ mgmt_txn_process_get_cfg_done:
+
+ if (error) {
+ /*
+ * Delete the txn request.
+ * Note: The following will remove it from the list
+ * as well.
+ */
+ mgmt_txn_req_free(&txn_req);
+ }
+
+ /*
+ * Else the transaction would have been already deleted or
+ * moved to corresponding pending list. No need to delete it.
+ */
+ num_processed++;
+ if (num_processed == MGMTD_TXN_MAX_NUM_GETCFG_PROC)
+ break;
+ }
+
+ if (mgmt_txn_reqs_count(&txn->get_cfg_reqs)) {
+ MGMTD_TXN_DBG(
+ "Processed maximum number of Get-Config requests (%d/%d). Rescheduling for rest.",
+ num_processed, MGMTD_TXN_MAX_NUM_GETCFG_PROC);
+ mgmt_txn_register_event(txn, MGMTD_TXN_PROC_GETCFG);
+ }
+}
+
+static void mgmt_txn_process_get_data(struct event *thread)
+{
+ struct mgmt_txn_ctx *txn;
+ struct mgmt_txn_req *txn_req;
+ struct mgmt_ds_ctx *ds_ctx;
+ int num_processed = 0;
+ bool error;
+
+ txn = (struct mgmt_txn_ctx *)EVENT_ARG(thread);
+ assert(txn);
+
+ MGMTD_TXN_DBG(
+ "Processing %d GET_DATA requests for Txn:%p Session:0x%llx",
+ (int)mgmt_txn_reqs_count(&txn->get_data_reqs), txn,
+ (unsigned long long)txn->session_id);
+
+ FOREACH_TXN_REQ_IN_LIST (&txn->get_data_reqs, txn_req) {
+ error = false;
+ assert(txn_req->req_event == MGMTD_TXN_PROC_GETDATA);
+ ds_ctx = txn_req->req.get_data->ds_ctx;
+ if (!ds_ctx) {
+ mgmt_fe_send_get_data_reply(
+ txn->session_id, txn->txn_id,
+ txn_req->req.get_data->ds_id, txn_req->req_id,
+ MGMTD_INTERNAL_ERROR, NULL,
+ "No such datastore!");
+ error = true;
+ goto mgmt_txn_process_get_data_done;
+ }
+
+ if (mgmt_ds_is_config(ds_ctx)) {
+ if (mgmt_txn_get_config(txn, txn_req, ds_ctx)
+ != 0) {
+ MGMTD_TXN_ERR(
+ "Unable to retrieve Config from DS %d for Txn %p, Sessn: 0x%llx, Req: %llu!",
+ txn_req->req.get_data->ds_id, txn,
+ (unsigned long long)txn->session_id,
+ (unsigned long long)txn_req->req_id);
+ error = true;
+ }
+ } else {
+ /*
+ * TODO: Trigger GET procedures for Backend
+ * For now return back error.
+ */
+ mgmt_fe_send_get_data_reply(
+ txn->session_id, txn->txn_id,
+ txn_req->req.get_data->ds_id, txn_req->req_id,
+ MGMTD_INTERNAL_ERROR, NULL,
+ "GET-DATA on Oper DS is not supported yet!");
+ error = true;
+ }
+
+ mgmt_txn_process_get_data_done:
+
+ if (error) {
+ /*
+ * Delete the txn request.
+ * Note: The following will remove it from the list
+ * as well.
+ */
+ mgmt_txn_req_free(&txn_req);
+ }
+
+ /*
+ * Else the transaction would have been already deleted or
+ * moved to corresponding pending list. No need to delete it.
+ */
+ num_processed++;
+ if (num_processed == MGMTD_TXN_MAX_NUM_GETDATA_PROC)
+ break;
+ }
+
+ if (mgmt_txn_reqs_count(&txn->get_data_reqs)) {
+ MGMTD_TXN_DBG(
+ "Processed maximum number of Get-Data requests (%d/%d). Rescheduling for rest.",
+ num_processed, MGMTD_TXN_MAX_NUM_GETDATA_PROC);
+ mgmt_txn_register_event(txn, MGMTD_TXN_PROC_GETDATA);
+ }
+}
+
+static struct mgmt_txn_ctx *
+mgmt_fe_find_txn_by_session_id(struct mgmt_master *cm, uint64_t session_id,
+ enum mgmt_txn_type type)
+{
+ struct mgmt_txn_ctx *txn;
+
+ FOREACH_TXN_IN_LIST (cm, txn) {
+ if (txn->session_id == session_id && txn->type == type)
+ return txn;
+ }
+
+ return NULL;
+}
+
+static struct mgmt_txn_ctx *mgmt_txn_create_new(uint64_t session_id,
+ enum mgmt_txn_type type)
+{
+ struct mgmt_txn_ctx *txn = NULL;
+
+ /*
+ * For 'CONFIG' transaction check if one is already created
+ * or not.
+ */
+ if (type == MGMTD_TXN_TYPE_CONFIG && mgmt_txn_mm->cfg_txn) {
+ if (mgmt_config_txn_in_progress() == session_id)
+ txn = mgmt_txn_mm->cfg_txn;
+ goto mgmt_create_txn_done;
+ }
+
+ txn = mgmt_fe_find_txn_by_session_id(mgmt_txn_mm, session_id,
+ type);
+ if (!txn) {
+ txn = XCALLOC(MTYPE_MGMTD_TXN, sizeof(struct mgmt_txn_ctx));
+ assert(txn);
+
+ txn->session_id = session_id;
+ txn->type = type;
+ mgmt_txn_badapters_init(&txn->be_adapters);
+ mgmt_txns_add_tail(&mgmt_txn_mm->txn_list, txn);
+ mgmt_txn_reqs_init(&txn->set_cfg_reqs);
+ mgmt_txn_reqs_init(&txn->get_cfg_reqs);
+ mgmt_txn_reqs_init(&txn->get_data_reqs);
+ mgmt_txn_reqs_init(&txn->pending_get_datas);
+ txn->commit_cfg_req = NULL;
+ txn->refcount = 0;
+ if (!mgmt_txn_mm->next_txn_id)
+ mgmt_txn_mm->next_txn_id++;
+ txn->txn_id = mgmt_txn_mm->next_txn_id++;
+ hash_get(mgmt_txn_mm->txn_hash, txn, hash_alloc_intern);
+
+ MGMTD_TXN_DBG("Added new '%s' MGMTD Transaction '%p'",
+ mgmt_txn_type2str(type), txn);
+
+ if (type == MGMTD_TXN_TYPE_CONFIG)
+ mgmt_txn_mm->cfg_txn = txn;
+
+ MGMTD_TXN_LOCK(txn);
+ }
+
+mgmt_create_txn_done:
+ return txn;
+}
+
+static void mgmt_txn_delete(struct mgmt_txn_ctx **txn)
+{
+ MGMTD_TXN_UNLOCK(txn);
+}
+
+static unsigned int mgmt_txn_hash_key(const void *data)
+{
+ const struct mgmt_txn_ctx *txn = data;
+
+ return jhash2((uint32_t *) &txn->txn_id,
+ sizeof(txn->txn_id) / sizeof(uint32_t), 0);
+}
+
+static bool mgmt_txn_hash_cmp(const void *d1, const void *d2)
+{
+ const struct mgmt_txn_ctx *txn1 = d1;
+ const struct mgmt_txn_ctx *txn2 = d2;
+
+ return (txn1->txn_id == txn2->txn_id);
+}
+
+static void mgmt_txn_hash_free(void *data)
+{
+ struct mgmt_txn_ctx *txn = data;
+
+ mgmt_txn_delete(&txn);
+}
+
+static void mgmt_txn_hash_init(void)
+{
+ if (!mgmt_txn_mm || mgmt_txn_mm->txn_hash)
+ return;
+
+ mgmt_txn_mm->txn_hash = hash_create(mgmt_txn_hash_key,
+ mgmt_txn_hash_cmp,
+ "MGMT Transactions");
+}
+
+static void mgmt_txn_hash_destroy(void)
+{
+ if (!mgmt_txn_mm || !mgmt_txn_mm->txn_hash)
+ return;
+
+ hash_clean(mgmt_txn_mm->txn_hash,
+ mgmt_txn_hash_free);
+ hash_free(mgmt_txn_mm->txn_hash);
+ mgmt_txn_mm->txn_hash = NULL;
+}
+
+static inline struct mgmt_txn_ctx *
+mgmt_txn_id2ctx(uint64_t txn_id)
+{
+ struct mgmt_txn_ctx key = {0};
+ struct mgmt_txn_ctx *txn;
+
+ if (!mgmt_txn_mm || !mgmt_txn_mm->txn_hash)
+ return NULL;
+
+ key.txn_id = txn_id;
+ txn = hash_lookup(mgmt_txn_mm->txn_hash, &key);
+
+ return txn;
+}
+
+static void mgmt_txn_lock(struct mgmt_txn_ctx *txn, const char *file,
+ int line)
+{
+ txn->refcount++;
+ MGMTD_TXN_DBG("%s:%d --> Lock %s Txn %p, Count: %d", file, line,
+ mgmt_txn_type2str(txn->type), txn, txn->refcount);
+}
+
+static void mgmt_txn_unlock(struct mgmt_txn_ctx **txn, const char *file,
+ int line)
+{
+ assert(*txn && (*txn)->refcount);
+
+ (*txn)->refcount--;
+ MGMTD_TXN_DBG("%s:%d --> Unlock %s Txn %p, Count: %d", file, line,
+ mgmt_txn_type2str((*txn)->type), *txn,
+ (*txn)->refcount);
+ if (!(*txn)->refcount) {
+ if ((*txn)->type == MGMTD_TXN_TYPE_CONFIG)
+ if (mgmt_txn_mm->cfg_txn == *txn)
+ mgmt_txn_mm->cfg_txn = NULL;
+ EVENT_OFF((*txn)->proc_get_cfg);
+ EVENT_OFF((*txn)->proc_get_data);
+ EVENT_OFF((*txn)->proc_comm_cfg);
+ EVENT_OFF((*txn)->comm_cfg_timeout);
+ hash_release(mgmt_txn_mm->txn_hash, *txn);
+ mgmt_txns_del(&mgmt_txn_mm->txn_list, *txn);
+
+ MGMTD_TXN_DBG("Deleted %s Txn %p for Sessn: 0x%llx",
+ mgmt_txn_type2str((*txn)->type), *txn,
+ (unsigned long long)(*txn)->session_id);
+
+ XFREE(MTYPE_MGMTD_TXN, *txn);
+ }
+
+ *txn = NULL;
+}
+
+static void mgmt_txn_cleanup_txn(struct mgmt_txn_ctx **txn)
+{
+ /* TODO: Any other cleanup applicable */
+
+ mgmt_txn_delete(txn);
+}
+
+static void
+mgmt_txn_cleanup_all_txns(void)
+{
+ struct mgmt_txn_ctx *txn;
+
+ if (!mgmt_txn_mm || !mgmt_txn_mm->txn_hash)
+ return;
+
+ FOREACH_TXN_IN_LIST (mgmt_txn_mm, txn)
+ mgmt_txn_cleanup_txn(&txn);
+}
+
+static void mgmt_txn_cleanup(struct event *thread)
+{
+ struct mgmt_txn_ctx *txn;
+
+ txn = (struct mgmt_txn_ctx *)EVENT_ARG(thread);
+ assert(txn);
+
+ mgmt_txn_cleanup_txn(&txn);
+}
+
+static void mgmt_txn_register_event(struct mgmt_txn_ctx *txn,
+ enum mgmt_txn_event event)
+{
+ struct timeval tv = {.tv_sec = 0,
+ .tv_usec = MGMTD_TXN_PROC_DELAY_USEC};
+
+ assert(mgmt_txn_mm && mgmt_txn_tm);
+
+ switch (event) {
+ case MGMTD_TXN_PROC_SETCFG:
+ event_add_timer_tv(mgmt_txn_tm, mgmt_txn_process_set_cfg,
+ txn, &tv, &txn->proc_set_cfg);
+ break;
+ case MGMTD_TXN_PROC_COMMITCFG:
+ event_add_timer_tv(mgmt_txn_tm, mgmt_txn_process_commit_cfg,
+ txn, &tv, &txn->proc_comm_cfg);
+ break;
+ case MGMTD_TXN_PROC_GETCFG:
+ event_add_timer_tv(mgmt_txn_tm, mgmt_txn_process_get_cfg,
+ txn, &tv, &txn->proc_get_cfg);
+ break;
+ case MGMTD_TXN_PROC_GETDATA:
+ event_add_timer_tv(mgmt_txn_tm, mgmt_txn_process_get_data,
+ txn, &tv, &txn->proc_get_data);
+ break;
+ case MGMTD_TXN_COMMITCFG_TIMEOUT:
+ event_add_timer_msec(mgmt_txn_tm,
+ mgmt_txn_cfg_commit_timedout, txn,
+ MGMTD_TXN_CFG_COMMIT_MAX_DELAY_MSEC,
+ &txn->comm_cfg_timeout);
+ break;
+ case MGMTD_TXN_CLEANUP:
+ tv.tv_usec = MGMTD_TXN_CLEANUP_DELAY_USEC;
+ event_add_timer_tv(mgmt_txn_tm, mgmt_txn_cleanup, txn, &tv,
+ &txn->clnup);
+ }
+}
+
+int mgmt_txn_init(struct mgmt_master *mm, struct event_loop *tm)
+{
+ if (mgmt_txn_mm || mgmt_txn_tm)
+ assert(!"MGMTD TXN: Call txn_init() only once");
+
+ mgmt_txn_mm = mm;
+ mgmt_txn_tm = tm;
+ mgmt_txns_init(&mm->txn_list);
+ mgmt_txn_hash_init();
+ assert(!mm->cfg_txn);
+ mm->cfg_txn = NULL;
+
+ return 0;
+}
+
+void mgmt_txn_destroy(void)
+{
+ mgmt_txn_cleanup_all_txns();
+ mgmt_txn_hash_destroy();
+}
+
+uint64_t mgmt_config_txn_in_progress(void)
+{
+ if (mgmt_txn_mm && mgmt_txn_mm->cfg_txn)
+ return mgmt_txn_mm->cfg_txn->session_id;
+
+ return MGMTD_SESSION_ID_NONE;
+}
+
+uint64_t mgmt_create_txn(uint64_t session_id, enum mgmt_txn_type type)
+{
+ struct mgmt_txn_ctx *txn;
+
+ txn = mgmt_txn_create_new(session_id, type);
+ return txn ? txn->txn_id : MGMTD_TXN_ID_NONE;
+}
+
+bool mgmt_txn_id_is_valid(uint64_t txn_id)
+{
+ return mgmt_txn_id2ctx(txn_id) ? true : false;
+}
+
+void mgmt_destroy_txn(uint64_t *txn_id)
+{
+ struct mgmt_txn_ctx *txn;
+
+ txn = mgmt_txn_id2ctx(*txn_id);
+ if (!txn)
+ return;
+
+ mgmt_txn_delete(&txn);
+ *txn_id = MGMTD_TXN_ID_NONE;
+}
+
+enum mgmt_txn_type mgmt_get_txn_type(uint64_t txn_id)
+{
+ struct mgmt_txn_ctx *txn;
+
+ txn = mgmt_txn_id2ctx(txn_id);
+ if (!txn)
+ return MGMTD_TXN_TYPE_NONE;
+
+ return txn->type;
+}
+
+int mgmt_txn_send_set_config_req(uint64_t txn_id, uint64_t req_id,
+ Mgmtd__DatastoreId ds_id,
+ struct mgmt_ds_ctx *ds_ctx,
+ Mgmtd__YangCfgDataReq **cfg_req,
+ size_t num_req, bool implicit_commit,
+ Mgmtd__DatastoreId dst_ds_id,
+ struct mgmt_ds_ctx *dst_ds_ctx)
+{
+ struct mgmt_txn_ctx *txn;
+ struct mgmt_txn_req *txn_req;
+ size_t indx;
+ uint16_t *num_chgs;
+ struct nb_cfg_change *cfg_chg;
+
+ txn = mgmt_txn_id2ctx(txn_id);
+ if (!txn)
+ return -1;
+
+ if (implicit_commit && mgmt_txn_reqs_count(&txn->set_cfg_reqs)) {
+ MGMTD_TXN_ERR(
+ "For implicit commit config only one SETCFG-REQ can be allowed!");
+ return -1;
+ }
+
+ txn_req = mgmt_txn_req_alloc(txn, req_id, MGMTD_TXN_PROC_SETCFG);
+ txn_req->req.set_cfg->ds_id = ds_id;
+ txn_req->req.set_cfg->ds_ctx = ds_ctx;
+ num_chgs = &txn_req->req.set_cfg->num_cfg_changes;
+ for (indx = 0; indx < num_req; indx++) {
+ cfg_chg = &txn_req->req.set_cfg->cfg_changes[*num_chgs];
+
+ if (cfg_req[indx]->req_type
+ == MGMTD__CFG_DATA_REQ_TYPE__DELETE_DATA)
+ cfg_chg->operation = NB_OP_DESTROY;
+ else if (cfg_req[indx]->req_type
+ == MGMTD__CFG_DATA_REQ_TYPE__SET_DATA)
+ cfg_chg->operation =
+ mgmt_ds_find_data_node_by_xpath(
+ ds_ctx, cfg_req[indx]->data->xpath)
+ ? NB_OP_MODIFY
+ : NB_OP_CREATE;
+ else
+ continue;
+
+ MGMTD_TXN_DBG(
+ "XPath: '%s', Value: '%s'", cfg_req[indx]->data->xpath,
+ (cfg_req[indx]->data->value
+ && cfg_req[indx]
+ ->data->value
+ ->encoded_str_val
+ ? cfg_req[indx]->data->value->encoded_str_val
+ : "NULL"));
+ strlcpy(cfg_chg->xpath, cfg_req[indx]->data->xpath,
+ sizeof(cfg_chg->xpath));
+ cfg_chg->value = (cfg_req[indx]->data->value
+ && cfg_req[indx]
+ ->data->value
+ ->encoded_str_val
+ ? strdup(cfg_req[indx]
+ ->data->value
+ ->encoded_str_val)
+ : NULL);
+ if (cfg_chg->value)
+ MGMTD_TXN_DBG("Allocated value at %p ==> '%s'",
+ cfg_chg->value, cfg_chg->value);
+
+ (*num_chgs)++;
+ }
+ txn_req->req.set_cfg->implicit_commit = implicit_commit;
+ txn_req->req.set_cfg->dst_ds_id = dst_ds_id;
+ txn_req->req.set_cfg->dst_ds_ctx = dst_ds_ctx;
+ txn_req->req.set_cfg->setcfg_stats =
+ mgmt_fe_get_session_setcfg_stats(txn->session_id);
+ mgmt_txn_register_event(txn, MGMTD_TXN_PROC_SETCFG);
+
+ return 0;
+}
+
+int mgmt_txn_send_commit_config_req(uint64_t txn_id, uint64_t req_id,
+ Mgmtd__DatastoreId src_ds_id,
+ struct mgmt_ds_ctx *src_ds_ctx,
+ Mgmtd__DatastoreId dst_ds_id,
+ struct mgmt_ds_ctx *dst_ds_ctx,
+ bool validate_only, bool abort,
+ bool implicit)
+{
+ struct mgmt_txn_ctx *txn;
+ struct mgmt_txn_req *txn_req;
+
+ txn = mgmt_txn_id2ctx(txn_id);
+ if (!txn)
+ return -1;
+
+ if (txn->commit_cfg_req) {
+ MGMTD_TXN_ERR(
+ "A commit is already in-progress for Txn %p, session 0x%llx. Cannot start another!",
+ txn, (unsigned long long)txn->session_id);
+ return -1;
+ }
+
+ txn_req = mgmt_txn_req_alloc(txn, req_id, MGMTD_TXN_PROC_COMMITCFG);
+ txn_req->req.commit_cfg.src_ds_id = src_ds_id;
+ txn_req->req.commit_cfg.src_ds_ctx = src_ds_ctx;
+ txn_req->req.commit_cfg.dst_ds_id = dst_ds_id;
+ txn_req->req.commit_cfg.dst_ds_ctx = dst_ds_ctx;
+ txn_req->req.commit_cfg.validate_only = validate_only;
+ txn_req->req.commit_cfg.abort = abort;
+ txn_req->req.commit_cfg.implicit = implicit;
+ txn_req->req.commit_cfg.cmt_stats =
+ mgmt_fe_get_session_commit_stats(txn->session_id);
+
+ /*
+ * Trigger a COMMIT-CONFIG process.
+ */
+ mgmt_txn_register_event(txn, MGMTD_TXN_PROC_COMMITCFG);
+ return 0;
+}
+
+int mgmt_txn_notify_be_adapter_conn(struct mgmt_be_client_adapter *adapter,
+ bool connect)
+{
+ struct mgmt_txn_ctx *txn;
+ struct mgmt_txn_req *txn_req;
+ struct mgmt_commit_cfg_req *cmtcfg_req;
+ static struct mgmt_commit_stats dummy_stats;
+ struct nb_config_cbs *adapter_cfgs = NULL;
+
+ memset(&dummy_stats, 0, sizeof(dummy_stats));
+ if (connect) {
+ /* Get config for this single backend client */
+ mgmt_be_get_adapter_config(adapter, mm->running_ds,
+ &adapter_cfgs);
+
+ if (!adapter_cfgs || RB_EMPTY(nb_config_cbs, adapter_cfgs)) {
+ SET_FLAG(adapter->flags,
+ MGMTD_BE_ADAPTER_FLAGS_CFG_SYNCED);
+ return 0;
+ }
+
+ /*
+ * Create a CONFIG transaction to push the config changes
+ * provided to the backend client.
+ */
+ txn = mgmt_txn_create_new(0, MGMTD_TXN_TYPE_CONFIG);
+ if (!txn) {
+ MGMTD_TXN_ERR(
+ "Failed to create CONFIG Transaction for downloading CONFIGs for client '%s'",
+ adapter->name);
+ return -1;
+ }
+
+ MGMTD_TXN_DBG("Created initial txn %" PRIu64
+ " for BE connection %s",
+ txn->txn_id, adapter->name);
+ /*
+ * Set the changeset for transaction to commit and trigger the
+ * commit request.
+ */
+ txn_req =
+ mgmt_txn_req_alloc(txn, 0, MGMTD_TXN_PROC_COMMITCFG);
+ txn_req->req.commit_cfg.src_ds_id = MGMTD_DS_NONE;
+ txn_req->req.commit_cfg.src_ds_ctx = 0;
+ txn_req->req.commit_cfg.dst_ds_id = MGMTD_DS_NONE;
+ txn_req->req.commit_cfg.dst_ds_ctx = 0;
+ txn_req->req.commit_cfg.validate_only = false;
+ txn_req->req.commit_cfg.abort = false;
+ txn_req->req.commit_cfg.cmt_stats = &dummy_stats;
+ txn_req->req.commit_cfg.cfg_chgs = adapter_cfgs;
+
+ /*
+ * Trigger a COMMIT-CONFIG process.
+ */
+ mgmt_txn_register_event(txn, MGMTD_TXN_PROC_COMMITCFG);
+
+ } else {
+ /*
+ * Check if any transaction is currently on-going that
+ * involves this backend client. If so, report the transaction
+ * has failed.
+ */
+ FOREACH_TXN_IN_LIST (mgmt_txn_mm, txn) {
+ if (txn->type == MGMTD_TXN_TYPE_CONFIG) {
+ cmtcfg_req = txn->commit_cfg_req
+ ? &txn->commit_cfg_req
+ ->req.commit_cfg
+ : NULL;
+ if (cmtcfg_req
+ && cmtcfg_req->subscr_info
+ .xpath_subscr[adapter->id]
+ .subscribed) {
+ mgmt_txn_send_commit_cfg_reply(
+ txn, MGMTD_INTERNAL_ERROR,
+ "Backend daemon disconnected while processing commit!");
+ }
+ }
+ }
+ }
+
+ return 0;
+}
+
+int mgmt_txn_notify_be_txn_reply(uint64_t txn_id, bool create,
+ bool success,
+ struct mgmt_be_client_adapter *adapter)
+{
+ struct mgmt_txn_ctx *txn;
+ struct mgmt_commit_cfg_req *cmtcfg_req = NULL;
+
+ txn = mgmt_txn_id2ctx(txn_id);
+ if (!txn || txn->type != MGMTD_TXN_TYPE_CONFIG)
+ return -1;
+
+ if (!create && !txn->commit_cfg_req)
+ return 0;
+
+ assert(txn->commit_cfg_req);
+ cmtcfg_req = &txn->commit_cfg_req->req.commit_cfg;
+ if (create) {
+ if (success) {
+ /*
+ * Done with TXN_CREATE. Move the backend client to
+ * next phase.
+ */
+ assert(cmtcfg_req->curr_phase
+ == MGMTD_COMMIT_PHASE_TXN_CREATE);
+
+ /*
+ * Send CFGDATA_CREATE-REQs to the backend immediately.
+ */
+ mgmt_txn_send_be_cfg_data(txn, adapter);
+ } else {
+ mgmt_txn_send_commit_cfg_reply(
+ txn, MGMTD_INTERNAL_ERROR,
+ "Internal error! Failed to initiate transaction at backend!");
+ }
+ } else {
+ /*
+ * Done with TXN_DELETE. Move the backend client to next phase.
+ */
+ if (false)
+ mgmt_move_be_commit_to_next_phase(txn, adapter);
+ }
+
+ return 0;
+}
+
+int mgmt_txn_notify_be_cfgdata_reply(
+ uint64_t txn_id, uint64_t batch_id, bool success, char *error_if_any,
+ struct mgmt_be_client_adapter *adapter)
+{
+ struct mgmt_txn_ctx *txn;
+ struct mgmt_txn_be_cfg_batch *cfg_btch;
+ struct mgmt_commit_cfg_req *cmtcfg_req = NULL;
+
+ txn = mgmt_txn_id2ctx(txn_id);
+ if (!txn || txn->type != MGMTD_TXN_TYPE_CONFIG)
+ return -1;
+
+ if (!txn->commit_cfg_req)
+ return -1;
+ cmtcfg_req = &txn->commit_cfg_req->req.commit_cfg;
+
+ cfg_btch = mgmt_txn_cfgbatch_id2ctx(txn, batch_id);
+ if (!cfg_btch || cfg_btch->txn != txn)
+ return -1;
+
+ if (!success) {
+ MGMTD_TXN_ERR(
+ "CFGDATA_CREATE_REQ sent to '%s' failed for Txn %p, Batch %p, Err: %s",
+ adapter->name, txn, cfg_btch,
+ error_if_any ? error_if_any : "None");
+ mgmt_txn_send_commit_cfg_reply(
+ txn, MGMTD_INTERNAL_ERROR,
+ error_if_any ? error_if_any :
+ "Internal error! Failed to download config data to backend!");
+ return 0;
+ }
+
+ MGMTD_TXN_DBG(
+ "CFGDATA_CREATE_REQ sent to '%s' was successful for Txn %p, Batch %p, Err: %s",
+ adapter->name, txn, cfg_btch,
+ error_if_any ? error_if_any : "None");
+ mgmt_move_txn_cfg_batch_to_next(
+ cmtcfg_req, cfg_btch, &cmtcfg_req->curr_batches[adapter->id],
+ &cmtcfg_req->next_batches[adapter->id], true,
+ MGMTD_COMMIT_PHASE_APPLY_CFG);
+
+ mgmt_try_move_commit_to_next_phase(txn, cmtcfg_req);
+
+ return 0;
+}
+
+int mgmt_txn_notify_be_cfg_apply_reply(uint64_t txn_id, bool success,
+ uint64_t batch_ids[],
+ size_t num_batch_ids, char *error_if_any,
+ struct mgmt_be_client_adapter *adapter)
+{
+ struct mgmt_txn_ctx *txn;
+ struct mgmt_txn_be_cfg_batch *cfg_btch;
+ struct mgmt_commit_cfg_req *cmtcfg_req = NULL;
+ size_t indx;
+
+ txn = mgmt_txn_id2ctx(txn_id);
+ if (!txn || txn->type != MGMTD_TXN_TYPE_CONFIG
+ || !txn->commit_cfg_req)
+ return -1;
+
+ cmtcfg_req = &txn->commit_cfg_req->req.commit_cfg;
+
+ if (!success) {
+ MGMTD_TXN_ERR(
+ "CFGDATA_APPLY_REQ sent to '%s' failed for Txn %p, Batches [0x%llx - 0x%llx], Err: %s",
+ adapter->name, txn, (unsigned long long)batch_ids[0],
+ (unsigned long long)batch_ids[num_batch_ids - 1],
+ error_if_any ? error_if_any : "None");
+ mgmt_txn_send_commit_cfg_reply(
+ txn, MGMTD_INTERNAL_ERROR,
+ error_if_any ? error_if_any :
+ "Internal error! Failed to apply config data on backend!");
+ return 0;
+ }
+
+ for (indx = 0; indx < num_batch_ids; indx++) {
+ cfg_btch = mgmt_txn_cfgbatch_id2ctx(txn, batch_ids[indx]);
+ if (cfg_btch->txn != txn)
+ return -1;
+ mgmt_move_txn_cfg_batch_to_next(
+ cmtcfg_req, cfg_btch,
+ &cmtcfg_req->curr_batches[adapter->id],
+ &cmtcfg_req->next_batches[adapter->id], true,
+ MGMTD_COMMIT_PHASE_TXN_DELETE);
+ }
+
+ if (!mgmt_txn_batches_count(&cmtcfg_req->curr_batches[adapter->id])) {
+ /*
+ * All configuration for the specific backend has been applied.
+ * Send TXN-DELETE to wrap up the transaction for this backend.
+ */
+ SET_FLAG(adapter->flags, MGMTD_BE_ADAPTER_FLAGS_CFG_SYNCED);
+ mgmt_txn_send_be_txn_delete(txn, adapter);
+ }
+
+ mgmt_try_move_commit_to_next_phase(txn, cmtcfg_req);
+ if (mm->perf_stats_en)
+ gettimeofday(&cmtcfg_req->cmt_stats->apply_cfg_end, NULL);
+
+ return 0;
+}
+
+int mgmt_txn_send_commit_config_reply(uint64_t txn_id,
+ enum mgmt_result result,
+ const char *error_if_any)
+{
+ struct mgmt_txn_ctx *txn;
+
+ txn = mgmt_txn_id2ctx(txn_id);
+ if (!txn)
+ return -1;
+
+ if (!txn->commit_cfg_req) {
+ MGMTD_TXN_ERR(
+ "NO commit in-progress for Txn %p, session 0x%llx!",
+ txn, (unsigned long long)txn->session_id);
+ return -1;
+ }
+
+ return mgmt_txn_send_commit_cfg_reply(txn, result, error_if_any);
+}
+
+int mgmt_txn_send_get_config_req(uint64_t txn_id, uint64_t req_id,
+ Mgmtd__DatastoreId ds_id,
+ struct mgmt_ds_ctx *ds_ctx,
+ Mgmtd__YangGetDataReq **data_req,
+ size_t num_reqs)
+{
+ struct mgmt_txn_ctx *txn;
+ struct mgmt_txn_req *txn_req;
+ size_t indx;
+
+ txn = mgmt_txn_id2ctx(txn_id);
+ if (!txn)
+ return -1;
+
+ txn_req = mgmt_txn_req_alloc(txn, req_id, MGMTD_TXN_PROC_GETCFG);
+ txn_req->req.get_data->ds_id = ds_id;
+ txn_req->req.get_data->ds_ctx = ds_ctx;
+ for (indx = 0;
+ indx < num_reqs && indx < MGMTD_MAX_NUM_DATA_REPLY_IN_BATCH;
+ indx++) {
+ MGMTD_TXN_DBG("XPath: '%s'", data_req[indx]->data->xpath);
+ txn_req->req.get_data->xpaths[indx] =
+ strdup(data_req[indx]->data->xpath);
+ txn_req->req.get_data->num_xpaths++;
+ }
+
+ mgmt_txn_register_event(txn, MGMTD_TXN_PROC_GETCFG);
+
+ return 0;
+}
+
+int mgmt_txn_send_get_data_req(uint64_t txn_id, uint64_t req_id,
+ Mgmtd__DatastoreId ds_id,
+ struct mgmt_ds_ctx *ds_ctx,
+ Mgmtd__YangGetDataReq **data_req,
+ size_t num_reqs)
+{
+ struct mgmt_txn_ctx *txn;
+ struct mgmt_txn_req *txn_req;
+ size_t indx;
+
+ txn = mgmt_txn_id2ctx(txn_id);
+ if (!txn)
+ return -1;
+
+ txn_req = mgmt_txn_req_alloc(txn, req_id, MGMTD_TXN_PROC_GETDATA);
+ txn_req->req.get_data->ds_id = ds_id;
+ txn_req->req.get_data->ds_ctx = ds_ctx;
+ for (indx = 0;
+ indx < num_reqs && indx < MGMTD_MAX_NUM_DATA_REPLY_IN_BATCH;
+ indx++) {
+ MGMTD_TXN_DBG("XPath: '%s'", data_req[indx]->data->xpath);
+ txn_req->req.get_data->xpaths[indx] =
+ strdup(data_req[indx]->data->xpath);
+ txn_req->req.get_data->num_xpaths++;
+ }
+
+ mgmt_txn_register_event(txn, MGMTD_TXN_PROC_GETDATA);
+
+ return 0;
+}
+
+void mgmt_txn_status_write(struct vty *vty)
+{
+ struct mgmt_txn_ctx *txn;
+
+ vty_out(vty, "MGMTD Transactions\n");
+
+ FOREACH_TXN_IN_LIST (mgmt_txn_mm, txn) {
+ vty_out(vty, " Txn: \t\t\t%p\n", txn);
+ vty_out(vty, " Txn-Id: \t\t\t%llu\n",
+ (unsigned long long)txn->txn_id);
+ vty_out(vty, " Session-Id: \t\t%llu\n",
+ (unsigned long long)txn->session_id);
+ vty_out(vty, " Type: \t\t\t%s\n",
+ mgmt_txn_type2str(txn->type));
+ vty_out(vty, " Ref-Count: \t\t\t%d\n", txn->refcount);
+ }
+ vty_out(vty, " Total: %d\n",
+ (int)mgmt_txns_count(&mgmt_txn_mm->txn_list));
+}
+
+int mgmt_txn_rollback_trigger_cfg_apply(struct mgmt_ds_ctx *src_ds_ctx,
+ struct mgmt_ds_ctx *dst_ds_ctx)
+{
+ static struct nb_config_cbs changes;
+ struct nb_config_cbs *cfg_chgs = NULL;
+ struct mgmt_txn_ctx *txn;
+ struct mgmt_txn_req *txn_req;
+ static struct mgmt_commit_stats dummy_stats;
+
+ memset(&changes, 0, sizeof(changes));
+ memset(&dummy_stats, 0, sizeof(dummy_stats));
+ /*
+ * This could be the case when the config is directly
+ * loaded onto the candidate DS from a file. Get the
+ * diff from a full comparison of the candidate and
+ * running DSs.
+ */
+ nb_config_diff(mgmt_ds_get_nb_config(dst_ds_ctx),
+ mgmt_ds_get_nb_config(src_ds_ctx), &changes);
+ cfg_chgs = &changes;
+
+ if (RB_EMPTY(nb_config_cbs, cfg_chgs)) {
+ /*
+ * This means there's no changes to commit whatsoever
+ * is the source of the changes in config.
+ */
+ return -1;
+ }
+
+ /*
+ * Create a CONFIG transaction to push the config changes
+ * provided to the backend client.
+ */
+ txn = mgmt_txn_create_new(0, MGMTD_TXN_TYPE_CONFIG);
+ if (!txn) {
+ MGMTD_TXN_ERR(
+ "Failed to create CONFIG Transaction for downloading CONFIGs");
+ return -1;
+ }
+
+ MGMTD_TXN_DBG("Created rollback txn %" PRIu64, txn->txn_id);
+
+ /*
+ * Set the changeset for transaction to commit and trigger the commit
+ * request.
+ */
+ txn_req = mgmt_txn_req_alloc(txn, 0, MGMTD_TXN_PROC_COMMITCFG);
+ txn_req->req.commit_cfg.src_ds_id = MGMTD_DS_CANDIDATE;
+ txn_req->req.commit_cfg.src_ds_ctx = src_ds_ctx;
+ txn_req->req.commit_cfg.dst_ds_id = MGMTD_DS_RUNNING;
+ txn_req->req.commit_cfg.dst_ds_ctx = dst_ds_ctx;
+ txn_req->req.commit_cfg.validate_only = false;
+ txn_req->req.commit_cfg.abort = false;
+ txn_req->req.commit_cfg.rollback = true;
+ txn_req->req.commit_cfg.cmt_stats = &dummy_stats;
+ txn_req->req.commit_cfg.cfg_chgs = cfg_chgs;
+
+ /*
+ * Trigger a COMMIT-CONFIG process.
+ */
+ mgmt_txn_register_event(txn, MGMTD_TXN_PROC_COMMITCFG);
+ return 0;
+}
diff --git a/mgmtd/mgmt_txn.h b/mgmtd/mgmt_txn.h
new file mode 100644
index 0000000000..be781ab954
--- /dev/null
+++ b/mgmtd/mgmt_txn.h
@@ -0,0 +1,267 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * MGMTD Transactions
+ *
+ * Copyright (C) 2021 Vmware, Inc.
+ * Pushpasis Sarkar <spushpasis@vmware.com>
+ */
+
+#ifndef _FRR_MGMTD_TXN_H_
+#define _FRR_MGMTD_TXN_H_
+
+#include "mgmtd/mgmt_be_adapter.h"
+#include "mgmtd/mgmt.h"
+#include "mgmtd/mgmt_ds.h"
+
+#define MGMTD_TXN_PROC_DELAY_MSEC 5
+#define MGMTD_TXN_PROC_DELAY_USEC 10
+#define MGMTD_TXN_MAX_NUM_SETCFG_PROC 128
+#define MGMTD_TXN_MAX_NUM_GETCFG_PROC 128
+#define MGMTD_TXN_MAX_NUM_GETDATA_PROC 128
+
+#define MGMTD_TXN_SEND_CFGVALIDATE_DELAY_MSEC 100
+#define MGMTD_TXN_SEND_CFGAPPLY_DELAY_MSEC 100
+#define MGMTD_TXN_CFG_COMMIT_MAX_DELAY_MSEC 30000 /* 30 seconds */
+
+#define MGMTD_TXN_CLEANUP_DELAY_MSEC 100
+#define MGMTD_TXN_CLEANUP_DELAY_USEC 10
+
+/*
+ * The following definition enables local validation of config
+ * on the MGMTD process by loading client-defined NB callbacks
+ * and calling them locally before sening CNFG_APPLY_REQ to
+ * backend for actual apply of configuration on internal state
+ * of the backend application.
+ *
+ * #define MGMTD_LOCAL_VALIDATIONS_ENABLED
+ *
+ * Note: Enabled by default in configure.ac, if this needs to be
+ * disabled then pass --enable-mgmtd-local-validations=no to
+ * the list of arguments passed to ./configure
+ */
+
+PREDECL_LIST(mgmt_txns);
+
+struct mgmt_master;
+
+enum mgmt_txn_type {
+ MGMTD_TXN_TYPE_NONE = 0,
+ MGMTD_TXN_TYPE_CONFIG,
+ MGMTD_TXN_TYPE_SHOW
+};
+
+static inline const char *mgmt_txn_type2str(enum mgmt_txn_type type)
+{
+ switch (type) {
+ case MGMTD_TXN_TYPE_NONE:
+ return "None";
+ case MGMTD_TXN_TYPE_CONFIG:
+ return "CONFIG";
+ case MGMTD_TXN_TYPE_SHOW:
+ return "SHOW";
+ }
+
+ return "Unknown";
+}
+
+/* Initialise transaction module. */
+extern int mgmt_txn_init(struct mgmt_master *cm, struct event_loop *tm);
+
+/* Destroy the transaction module. */
+extern void mgmt_txn_destroy(void);
+
+/*
+ * Check if transaction is in progress.
+ *
+ * Returns:
+ * session ID if in-progress, MGMTD_SESSION_ID_NONE otherwise.
+ */
+extern uint64_t mgmt_config_txn_in_progress(void);
+
+/*
+ * Create transaction.
+ *
+ * session_id
+ * Session ID.
+ *
+ * type
+ * Transaction type (CONFIG/SHOW/NONE)
+ *
+ * Returns:
+ * transaction ID.
+ */
+extern uint64_t mgmt_create_txn(uint64_t session_id, enum mgmt_txn_type type);
+
+/*
+ * Destroy transaction.
+ *
+ * txn_id
+ * Unique transaction identifier.
+ */
+extern void mgmt_destroy_txn(uint64_t *txn_id);
+
+/*
+ * Check if transaction is valid given an ID.
+ */
+extern bool mgmt_txn_id_is_valid(uint64_t txn_id);
+
+/*
+ * Returns the type of transaction given an ID.
+ */
+extern enum mgmt_txn_type mgmt_get_txn_type(uint64_t txn_id);
+
+/*
+ * Send set-config request to be processed later in transaction.
+ *
+ * txn_id
+ * Unique transaction identifier.
+ *
+ * req_id
+ * Unique transaction request identifier.
+ *
+ * ds_id
+ * Datastore ID.
+ *
+ * ds_hndl
+ * Datastore handle.
+ *
+ * cfg_req
+ * Config requests.
+ *
+ * num_req
+ * Number of config requests.
+ *
+ * implicit_commit
+ * TRUE if the commit is implicit, FALSE otherwise.
+ *
+ * dst_ds_id
+ * Destination datastore ID.
+ *
+ * dst_ds_handle
+ * Destination datastore handle.
+ *
+ * Returns:
+ * 0 on success, -1 on failures.
+ */
+extern int mgmt_txn_send_set_config_req(uint64_t txn_id, uint64_t req_id,
+ Mgmtd__DatastoreId ds_id,
+ struct mgmt_ds_ctx *ds_ctx,
+ Mgmtd__YangCfgDataReq **cfg_req,
+ size_t num_req, bool implicit_commit,
+ Mgmtd__DatastoreId dst_ds_id,
+ struct mgmt_ds_ctx *dst_ds_ctx);
+
+/*
+ * Send commit-config request to be processed later in transaction.
+ *
+ * txn_id
+ * Unique transaction identifier.
+ *
+ * req_id
+ * Unique transaction request identifier.
+ *
+ * src_ds_id
+ * Source datastore ID.
+ *
+ * src_ds_hndl
+ * Source Datastore handle.
+ *
+ * validate_only
+ * TRUE if commit request needs to be validated only, FALSE otherwise.
+ *
+ * abort
+ * TRUE if need to restore Src DS back to Dest DS, FALSE otherwise.
+ *
+ * implicit
+ * TRUE if the commit is implicit, FALSE otherwise.
+ *
+ * Returns:
+ * 0 on success, -1 on failures.
+ */
+extern int mgmt_txn_send_commit_config_req(uint64_t txn_id, uint64_t req_id,
+ Mgmtd__DatastoreId src_ds_id,
+ struct mgmt_ds_ctx *dst_ds_ctx,
+ Mgmtd__DatastoreId dst_ds_id,
+ struct mgmt_ds_ctx *src_ds_ctx,
+ bool validate_only, bool abort,
+ bool implicit);
+
+extern int mgmt_txn_send_commit_config_reply(uint64_t txn_id,
+ enum mgmt_result result,
+ const char *error_if_any);
+
+/*
+ * Send get-config request to be processed later in transaction.
+ *
+ * Similar to set-config request.
+ */
+extern int mgmt_txn_send_get_config_req(uint64_t txn_id, uint64_t req_id,
+ Mgmtd__DatastoreId ds_id,
+ struct mgmt_ds_ctx *ds_ctx,
+ Mgmtd__YangGetDataReq **data_req,
+ size_t num_reqs);
+
+/*
+ * Send get-data request to be processed later in transaction.
+ *
+ * Similar to get-config request, but here data is fetched from backedn client.
+ */
+extern int mgmt_txn_send_get_data_req(uint64_t txn_id, uint64_t req_id,
+ Mgmtd__DatastoreId ds_id,
+ struct mgmt_ds_ctx *ds_ctx,
+ Mgmtd__YangGetDataReq **data_req,
+ size_t num_reqs);
+
+/*
+ * Notifiy backend adapter on connection.
+ */
+extern int
+mgmt_txn_notify_be_adapter_conn(struct mgmt_be_client_adapter *adapter,
+ bool connect);
+
+/*
+ * Reply to backend adapter about transaction create/delete.
+ */
+extern int
+mgmt_txn_notify_be_txn_reply(uint64_t txn_id, bool create, bool success,
+ struct mgmt_be_client_adapter *adapter);
+
+/*
+ * Reply to backend adapater with config data create request.
+ */
+extern int
+mgmt_txn_notify_be_cfgdata_reply(uint64_t txn_id, uint64_t batch_id,
+ bool success, char *error_if_any,
+ struct mgmt_be_client_adapter *adapter);
+
+/*
+ * Reply to backend adapater with config data validate request.
+ */
+extern int mgmt_txn_notify_be_cfg_validate_reply(
+ uint64_t txn_id, bool success, uint64_t batch_ids[],
+ size_t num_batch_ids, char *error_if_any,
+ struct mgmt_be_client_adapter *adapter);
+
+/*
+ * Reply to backend adapater with config data apply request.
+ */
+extern int
+mgmt_txn_notify_be_cfg_apply_reply(uint64_t txn_id, bool success,
+ uint64_t batch_ids[],
+ size_t num_batch_ids, char *error_if_any,
+ struct mgmt_be_client_adapter *adapter);
+
+/*
+ * Dump transaction status to vty.
+ */
+extern void mgmt_txn_status_write(struct vty *vty);
+
+/*
+ * Trigger rollback config apply.
+ *
+ * Creates a new transaction and commit request for rollback.
+ */
+extern int
+mgmt_txn_rollback_trigger_cfg_apply(struct mgmt_ds_ctx *src_ds_ctx,
+ struct mgmt_ds_ctx *dst_ds_ctx);
+#endif /* _FRR_MGMTD_TXN_H_ */
diff --git a/mgmtd/mgmt_vty.c b/mgmtd/mgmt_vty.c
new file mode 100644
index 0000000000..cb09544fdc
--- /dev/null
+++ b/mgmtd/mgmt_vty.c
@@ -0,0 +1,534 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * MGMTD VTY Interface
+ *
+ * Copyright (C) 2021 Vmware, Inc.
+ * Pushpasis Sarkar <spushpasis@vmware.com>
+ */
+
+#include <zebra.h>
+
+#include "command.h"
+#include "json.h"
+#include "northbound_cli.h"
+
+#include "mgmtd/mgmt.h"
+#include "mgmtd/mgmt_be_server.h"
+#include "mgmtd/mgmt_be_adapter.h"
+#include "mgmtd/mgmt_fe_server.h"
+#include "mgmtd/mgmt_fe_adapter.h"
+#include "mgmtd/mgmt_ds.h"
+#include "mgmtd/mgmt_history.h"
+
+#include "mgmtd/mgmt_vty_clippy.c"
+
+DEFPY(show_mgmt_be_adapter,
+ show_mgmt_be_adapter_cmd,
+ "show mgmt backend-adapter all",
+ SHOW_STR
+ MGMTD_STR
+ MGMTD_BE_ADAPTER_STR
+ "Display all Backend Adapters\n")
+{
+ mgmt_be_adapter_status_write(vty);
+
+ return CMD_SUCCESS;
+}
+
+DEFPY(show_mgmt_be_xpath_reg,
+ show_mgmt_be_xpath_reg_cmd,
+ "show mgmt backend-yang-xpath-registry",
+ SHOW_STR
+ MGMTD_STR
+ "Backend Adapter YANG Xpath Registry\n")
+{
+ mgmt_be_xpath_register_write(vty);
+
+ return CMD_SUCCESS;
+}
+
+DEFPY(show_mgmt_fe_adapter, show_mgmt_fe_adapter_cmd,
+ "show mgmt frontend-adapter all [detail$detail]",
+ SHOW_STR
+ MGMTD_STR
+ MGMTD_FE_ADAPTER_STR
+ "Display all Frontend Adapters\n"
+ "Display more details\n")
+{
+ mgmt_fe_adapter_status_write(vty, !!detail);
+
+ return CMD_SUCCESS;
+}
+
+DEFPY_HIDDEN(mgmt_performance_measurement,
+ mgmt_performance_measurement_cmd,
+ "[no] mgmt performance-measurement",
+ NO_STR
+ MGMTD_STR
+ "Enable performance measurement\n")
+{
+ if (no)
+ mgmt_fe_adapter_perf_measurement(vty, false);
+ else
+ mgmt_fe_adapter_perf_measurement(vty, true);
+
+ return CMD_SUCCESS;
+}
+
+DEFPY(mgmt_reset_performance_stats,
+ mgmt_reset_performance_stats_cmd,
+ "mgmt reset-statistics",
+ MGMTD_STR
+ "Reset the Performance measurement statistics\n")
+{
+ mgmt_fe_adapter_reset_perf_stats(vty);
+
+ return CMD_SUCCESS;
+}
+
+DEFPY(show_mgmt_txn,
+ show_mgmt_txn_cmd,
+ "show mgmt transaction all",
+ SHOW_STR
+ MGMTD_STR
+ MGMTD_TXN_STR
+ "Display all Transactions\n")
+{
+ mgmt_txn_status_write(vty);
+
+ return CMD_SUCCESS;
+}
+
+DEFPY(show_mgmt_ds,
+ show_mgmt_ds_cmd,
+ "show mgmt datastore [all|candidate|operational|running]$dsname",
+ SHOW_STR
+ MGMTD_STR
+ MGMTD_DS_STR
+ "All datastores (default)\n"
+ "Candidate datastore\n"
+ "Operational datastore\n"
+ "Running datastore\n")
+{
+ struct mgmt_ds_ctx *ds_ctx;
+
+ if (!dsname || dsname[0] == 'a') {
+ mgmt_ds_status_write(vty);
+ return CMD_SUCCESS;
+ }
+ ds_ctx = mgmt_ds_get_ctx_by_id(mm, mgmt_ds_name2id(dsname));
+ if (!ds_ctx) {
+ vty_out(vty, "ERROR: Could not access %s datastore!\n", dsname);
+ return CMD_ERR_NO_MATCH;
+ }
+ mgmt_ds_status_write_one(vty, ds_ctx);
+
+ return CMD_SUCCESS;
+}
+
+DEFPY(mgmt_commit,
+ mgmt_commit_cmd,
+ "mgmt commit <check|apply|abort>$type",
+ MGMTD_STR
+ "Commit action\n"
+ "Validate the set of config commands\n"
+ "Validate and apply the set of config commands\n"
+ "Abort and drop the set of config commands recently added\n")
+{
+ bool validate_only = type[0] == 'c';
+ bool abort = type[1] == 'b';
+
+ if (vty_mgmt_send_commit_config(vty, validate_only, abort) != 0)
+ return CMD_WARNING_CONFIG_FAILED;
+ return CMD_SUCCESS;
+}
+
+DEFPY(mgmt_set_config_data, mgmt_set_config_data_cmd,
+ "mgmt set-config WORD$path VALUE",
+ MGMTD_STR
+ "Set configuration data\n"
+ "XPath expression specifying the YANG data path\n"
+ "Value of the data to set\n")
+{
+ strlcpy(vty->cfg_changes[0].xpath, path,
+ sizeof(vty->cfg_changes[0].xpath));
+ vty->cfg_changes[0].value = value;
+ vty->cfg_changes[0].operation = NB_OP_CREATE;
+ vty->num_cfg_changes = 1;
+
+ vty->no_implicit_commit = true;
+ vty_mgmt_send_config_data(vty);
+ vty->no_implicit_commit = false;
+ return CMD_SUCCESS;
+}
+
+DEFPY(mgmt_delete_config_data, mgmt_delete_config_data_cmd,
+ "mgmt delete-config WORD$path",
+ MGMTD_STR
+ "Delete configuration data\n"
+ "XPath expression specifying the YANG data path\n")
+{
+
+ strlcpy(vty->cfg_changes[0].xpath, path,
+ sizeof(vty->cfg_changes[0].xpath));
+ vty->cfg_changes[0].value = NULL;
+ vty->cfg_changes[0].operation = NB_OP_DESTROY;
+ vty->num_cfg_changes = 1;
+
+ vty->no_implicit_commit = true;
+ vty_mgmt_send_config_data(vty);
+ vty->no_implicit_commit = false;
+ return CMD_SUCCESS;
+}
+
+DEFPY(show_mgmt_get_config, show_mgmt_get_config_cmd,
+ "show mgmt get-config [candidate|operational|running]$dsname WORD$path",
+ SHOW_STR MGMTD_STR
+ "Get configuration data from a specific configuration datastore\n"
+ "Candidate datastore (default)\n"
+ "Operational datastore\n"
+ "Running datastore\n"
+ "XPath expression specifying the YANG data path\n")
+{
+ const char *xpath_list[VTY_MAXCFGCHANGES] = {0};
+ Mgmtd__DatastoreId datastore = MGMTD_DS_CANDIDATE;
+
+ if (dsname)
+ datastore = mgmt_ds_name2id(dsname);
+
+ xpath_list[0] = path;
+ vty_mgmt_send_get_config(vty, datastore, xpath_list, 1);
+ return CMD_SUCCESS;
+}
+
+DEFPY(show_mgmt_get_data, show_mgmt_get_data_cmd,
+ "show mgmt get-data [candidate|operational|running]$dsname WORD$path",
+ SHOW_STR MGMTD_STR
+ "Get data from a specific datastore\n"
+ "Candidate datastore\n"
+ "Operational datastore (default)\n"
+ "Running datastore\n"
+ "XPath expression specifying the YANG data path\n")
+{
+ const char *xpath_list[VTY_MAXCFGCHANGES] = {0};
+ Mgmtd__DatastoreId datastore = MGMTD_DS_OPERATIONAL;
+
+ if (dsname)
+ datastore = mgmt_ds_name2id(dsname);
+
+ xpath_list[0] = path;
+ vty_mgmt_send_get_data(vty, datastore, xpath_list, 1);
+ return CMD_SUCCESS;
+}
+
+DEFPY(show_mgmt_dump_data,
+ show_mgmt_dump_data_cmd,
+ "show mgmt datastore-contents [candidate|operational|running]$dsname [xpath WORD$path] [file WORD$filepath] <json|xml>$fmt",
+ SHOW_STR
+ MGMTD_STR
+ "Get Datastore contents from a specific datastore\n"
+ "Candidate datastore (default)\n"
+ "Operational datastore\n"
+ "Running datastore\n"
+ "XPath expression specifying the YANG data path\n"
+ "XPath string\n"
+ "Dump the contents to a file\n"
+ "Full path of the file\n"
+ "json output\n"
+ "xml output\n")
+{
+ struct mgmt_ds_ctx *ds_ctx;
+ Mgmtd__DatastoreId datastore = MGMTD_DS_CANDIDATE;
+ LYD_FORMAT format = fmt[0] == 'j' ? LYD_JSON : LYD_XML;
+ FILE *f = NULL;
+
+ if (datastore)
+ datastore = mgmt_ds_name2id(dsname);
+
+ ds_ctx = mgmt_ds_get_ctx_by_id(mm, datastore);
+ if (!ds_ctx) {
+ vty_out(vty, "ERROR: Could not access datastore!\n");
+ return CMD_ERR_NO_MATCH;
+ }
+
+ if (filepath) {
+ f = fopen(filepath, "w");
+ if (!f) {
+ vty_out(vty,
+ "Could not open file pointed by filepath %s\n",
+ filepath);
+ return CMD_SUCCESS;
+ }
+ }
+
+ mgmt_ds_dump_tree(vty, ds_ctx, path, f, format);
+
+ if (f)
+ fclose(f);
+ return CMD_SUCCESS;
+}
+
+DEFPY(show_mgmt_map_xpath,
+ show_mgmt_map_xpath_cmd,
+ "show mgmt yang-xpath-subscription WORD$path",
+ SHOW_STR
+ MGMTD_STR
+ "Get YANG Backend Subscription\n"
+ "XPath expression specifying the YANG data path\n")
+{
+ mgmt_be_xpath_subscr_info_write(vty, path);
+ return CMD_SUCCESS;
+}
+
+DEFPY(mgmt_load_config,
+ mgmt_load_config_cmd,
+ "mgmt load-config WORD$filepath <merge|replace>$type",
+ MGMTD_STR
+ "Load configuration onto Candidate Datastore\n"
+ "Full path of the file\n"
+ "Merge configuration with contents of Candidate Datastore\n"
+ "Replace the existing contents of Candidate datastore\n")
+{
+ bool merge = type[0] == 'm' ? true : false;
+ struct mgmt_ds_ctx *ds_ctx;
+ int ret;
+
+ if (access(filepath, F_OK) == -1) {
+ vty_out(vty, "ERROR: File %s : %s\n", filepath,
+ strerror(errno));
+ return CMD_ERR_NO_FILE;
+ }
+
+ ds_ctx = mgmt_ds_get_ctx_by_id(mm, MGMTD_DS_CANDIDATE);
+ if (!ds_ctx) {
+ vty_out(vty, "ERROR: Could not access Candidate datastore!\n");
+ return CMD_ERR_NO_MATCH;
+ }
+
+ ret = mgmt_ds_load_config_from_file(ds_ctx, filepath, merge);
+ if (ret != 0)
+ vty_out(vty, "Error with parsing the file with error code %d\n",
+ ret);
+ return CMD_SUCCESS;
+}
+
+DEFPY(mgmt_save_config,
+ mgmt_save_config_cmd,
+ "mgmt save-config <candidate|running>$dsname WORD$filepath",
+ MGMTD_STR
+ "Save configuration from datastore\n"
+ "Candidate datastore\n"
+ "Running datastore\n"
+ "Full path of the file\n")
+{
+ Mgmtd__DatastoreId datastore = mgmt_ds_name2id(dsname);
+ struct mgmt_ds_ctx *ds_ctx;
+ FILE *f;
+
+ ds_ctx = mgmt_ds_get_ctx_by_id(mm, datastore);
+ if (!ds_ctx) {
+ vty_out(vty, "ERROR: Could not access the '%s' datastore!\n",
+ dsname);
+ return CMD_ERR_NO_MATCH;
+ }
+
+ if (!filepath) {
+ vty_out(vty, "ERROR: No file path mentioned!\n");
+ return CMD_ERR_NO_MATCH;
+ }
+
+ f = fopen(filepath, "w");
+ if (!f) {
+ vty_out(vty, "Could not open file pointed by filepath %s\n",
+ filepath);
+ return CMD_SUCCESS;
+ }
+
+ mgmt_ds_dump_tree(vty, ds_ctx, "/", f, LYD_JSON);
+
+ fclose(f);
+
+ return CMD_SUCCESS;
+}
+
+DEFPY(show_mgmt_cmt_hist,
+ show_mgmt_cmt_hist_cmd,
+ "show mgmt commit-history",
+ SHOW_STR
+ MGMTD_STR
+ "Show commit history\n")
+{
+ show_mgmt_cmt_history(vty);
+ return CMD_SUCCESS;
+}
+
+DEFPY(mgmt_rollback,
+ mgmt_rollback_cmd,
+ "mgmt rollback <commit-id WORD$commit | last [(1-10)]$last>",
+ MGMTD_STR
+ "Rollback commits\n"
+ "Rollback to commit ID\n"
+ "Commit-ID\n"
+ "Rollbak n commits\n"
+ "Number of commits\n")
+{
+ if (commit)
+ mgmt_history_rollback_by_id(vty, commit);
+ else
+ mgmt_history_rollback_n(vty, last);
+
+ return CMD_SUCCESS;
+}
+
+static int config_write_mgmt_debug(struct vty *vty);
+static struct cmd_node debug_node = {
+ .name = "debug",
+ .node = DEBUG_NODE,
+ .prompt = "",
+ .config_write = config_write_mgmt_debug,
+};
+
+static int config_write_mgmt_debug_helper(struct vty *vty, bool config)
+{
+ int n = mgmt_debug_be + mgmt_debug_fe + mgmt_debug_ds + mgmt_debug_txn;
+ if (!n)
+ return 0;
+
+ if (config && mgmt_debug_be && mgmt_debug_fe && mgmt_debug_ds &&
+ mgmt_debug_txn) {
+ vty_out(vty, "debug mgmt all\n");
+ return 0;
+ }
+
+ vty_out(vty, "debug mgmt");
+ if (mgmt_debug_be)
+ vty_out(vty, " backend");
+ if (mgmt_debug_ds)
+ vty_out(vty, " datastore");
+ if (mgmt_debug_fe)
+ vty_out(vty, " frontend");
+ if (mgmt_debug_txn)
+ vty_out(vty, " transaction");
+
+ vty_out(vty, "\n");
+
+ return 0;
+}
+
+static int config_write_mgmt_debug(struct vty *vty)
+{
+ return config_write_mgmt_debug_helper(vty, true);
+}
+
+DEFUN_NOSH(show_debugging_mgmt, show_debugging_mgmt_cmd,
+ "show debugging [mgmt]", SHOW_STR DEBUG_STR "MGMT Information\n")
+{
+ vty_out(vty, "MGMT debugging status:\n");
+
+ config_write_mgmt_debug_helper(vty, false);
+
+ cmd_show_lib_debugs(vty);
+
+ return CMD_SUCCESS;
+}
+
+DEFPY(debug_mgmt, debug_mgmt_cmd,
+ "[no$no] debug mgmt <all$all|{backend$be|datastore$ds|frontend$fe|transaction$txn}>",
+ NO_STR DEBUG_STR MGMTD_STR
+ "All debug\n"
+ "Back-end debug\n"
+ "Datastore debug\n"
+ "Front-end debug\n"
+ "Transaction debug\n")
+{
+ bool set = !no;
+ if (all)
+ be = fe = ds = txn = set ? all : NULL;
+
+ if (be)
+ mgmt_debug_be = set;
+ if (ds)
+ mgmt_debug_ds = set;
+ if (fe)
+ mgmt_debug_fe = set;
+ if (txn)
+ mgmt_debug_txn = set;
+
+ return CMD_SUCCESS;
+}
+
+/*
+ * Analog of `frr_config_read_in()`, instead of our config file though we loop
+ * over all daemons that have transitioned to mgmtd, loading their configs
+ */
+static int mgmt_config_pre_hook(struct event_loop *loop)
+{
+ FILE *confp;
+ char *p;
+
+ for (uint i = 0; i < mgmt_daemons_count; i++) {
+ p = asprintfrr(MTYPE_TMP, "%s/%s.conf", frr_sysconfdir,
+ mgmt_daemons[i]);
+ confp = fopen(p, "r");
+ if (confp == NULL) {
+ if (errno != ENOENT)
+ zlog_err("%s: couldn't read config file %s: %s",
+ __func__, p, safe_strerror(errno));
+ } else {
+ zlog_info("mgmtd: reading daemon config from %s", p);
+ vty_read_file(vty_shared_candidate_config, confp);
+ fclose(confp);
+ }
+ XFREE(MTYPE_TMP, p);
+ }
+ return 0;
+}
+
+void mgmt_vty_init(void)
+{
+ /*
+ * Initialize command handling from VTYSH connection.
+ * Call command initialization routines defined by
+ * backend components that are moved to new MGMTD infra
+ * here one by one.
+ */
+#if HAVE_STATICD
+ extern void static_vty_init(void);
+ static_vty_init();
+#endif
+
+ hook_register(frr_config_pre, mgmt_config_pre_hook);
+
+ install_node(&debug_node);
+
+ install_element(VIEW_NODE, &show_mgmt_be_adapter_cmd);
+ install_element(VIEW_NODE, &show_mgmt_be_xpath_reg_cmd);
+ install_element(VIEW_NODE, &show_mgmt_fe_adapter_cmd);
+ install_element(VIEW_NODE, &show_mgmt_txn_cmd);
+ install_element(VIEW_NODE, &show_mgmt_ds_cmd);
+ install_element(VIEW_NODE, &show_mgmt_get_config_cmd);
+ install_element(VIEW_NODE, &show_mgmt_get_data_cmd);
+ install_element(VIEW_NODE, &show_mgmt_dump_data_cmd);
+ install_element(VIEW_NODE, &show_mgmt_map_xpath_cmd);
+ install_element(VIEW_NODE, &show_mgmt_cmt_hist_cmd);
+
+ install_element(CONFIG_NODE, &mgmt_commit_cmd);
+ install_element(CONFIG_NODE, &mgmt_set_config_data_cmd);
+ install_element(CONFIG_NODE, &mgmt_delete_config_data_cmd);
+ install_element(CONFIG_NODE, &mgmt_load_config_cmd);
+ install_element(CONFIG_NODE, &mgmt_save_config_cmd);
+ install_element(CONFIG_NODE, &mgmt_rollback_cmd);
+
+ install_element(VIEW_NODE, &debug_mgmt_cmd);
+ install_element(CONFIG_NODE, &debug_mgmt_cmd);
+
+ /* Enable view */
+ install_element(ENABLE_NODE, &mgmt_performance_measurement_cmd);
+ install_element(ENABLE_NODE, &mgmt_reset_performance_stats_cmd);
+
+ install_element(ENABLE_NODE, &show_debugging_mgmt_cmd);
+
+ /*
+ * TODO: Register and handlers for auto-completion here.
+ */
+}
diff --git a/mgmtd/subdir.am b/mgmtd/subdir.am
new file mode 100644
index 0000000000..a93f8f9441
--- /dev/null
+++ b/mgmtd/subdir.am
@@ -0,0 +1,68 @@
+#
+# mgmtd -- Mangagement Daemon
+#
+
+# dist_examples_DATA += \
+ # end
+
+vtysh_daemons += mgmtd
+
+# man8 += $(MANBUILD)/frr-mgmtd.8
+# endif
+
+clippy_scan += \
+ mgmtd/mgmt_vty.c \
+ # end
+
+lib_LTLIBRARIES += mgmtd/libmgmt_be_nb.la
+nodist_mgmtd_libmgmt_be_nb_la_SOURCES = \
+ # end
+mgmtd_libmgmt_be_nb_la_CFLAGS = $(AM_CFLAGS) -DINCLUDE_MGMTD_CMDDEFS_ONLY
+mgmtd_libmgmt_be_nb_la_CPPFLAGS = $(AM_CPPFLAGS) -DINCLUDE_MGMTD_CMDDEFS_ONLY
+mgmtd_libmgmt_be_nb_la_LDFLAGS = -version-info 0:0:0
+
+noinst_LIBRARIES += mgmtd/libmgmtd.a
+mgmtd_libmgmtd_a_SOURCES = \
+ mgmtd/mgmt.c \
+ mgmtd/mgmt_ds.c \
+ mgmtd/mgmt_be_server.c \
+ mgmtd/mgmt_be_adapter.c \
+ mgmtd/mgmt_fe_server.c \
+ mgmtd/mgmt_fe_adapter.c \
+ mgmtd/mgmt_history.c \
+ mgmtd/mgmt_memory.c \
+ mgmtd/mgmt_txn.c \
+ mgmtd/mgmt_vty.c \
+ # end
+
+mgmtdheaderdir = $(pkgincludedir)/mgmtd
+mgmtdheader_HEADERS = \
+ mgmtd/mgmt_defines.h \
+ # end
+
+noinst_HEADERS += \
+ mgmtd/mgmt.h \
+ mgmtd/mgmt_be_server.h \
+ mgmtd/mgmt_be_adapter.h \
+ mgmtd/mgmt_ds.h \
+ mgmtd/mgmt_fe_server.h \
+ mgmtd/mgmt_fe_adapter.h \
+ mgmtd/mgmt_history.h \
+ mgmtd/mgmt_memory.h \
+ mgmtd/mgmt_txn.h \
+ # end
+
+sbin_PROGRAMS += mgmtd/mgmtd
+
+mgmtd_mgmtd_SOURCES = \
+ mgmtd/mgmt_main.c \
+ # end
+mgmtd_mgmtd_CFLAGS = $(AM_CFLAGS) -I ./
+mgmtd_mgmtd_LDADD = mgmtd/libmgmtd.a lib/libfrr.la $(LIBCAP) $(LIBM) $(LIBYANG_LIBS) $(UST_LIBS)
+mgmtd_mgmtd_LDADD += mgmtd/libmgmt_be_nb.la
+
+if STATICD
+$(mgmtd_mgmtd_OBJECTS): yang/frr-staticd.yang.c
+CLEANFILES += yang/frr-staticd.yang.c
+nodist_mgmtd_libmgmt_be_nb_la_SOURCES += staticd/static_vty.c
+endif
diff --git a/nhrpd/debug.h b/nhrpd/debug.h
index e9428fa90a..f2c7022ad4 100644
--- a/nhrpd/debug.h
+++ b/nhrpd/debug.h
@@ -1,13 +1,5 @@
#include "log.h"
-#if defined(__GNUC__) && (__GNUC__ >= 3)
-#define likely(_x) __builtin_expect(!!(_x), 1)
-#define unlikely(_x) __builtin_expect(!!(_x), 0)
-#else
-#define likely(_x) !!(_x)
-#define unlikely(_x) !!(_x)
-#endif
-
#define NHRP_DEBUG_COMMON (1 << 0)
#define NHRP_DEBUG_KERNEL (1 << 1)
#define NHRP_DEBUG_IF (1 << 2)
diff --git a/nhrpd/netlink_arp.c b/nhrpd/netlink_arp.c
index 877659b4c0..2e22f8e247 100644
--- a/nhrpd/netlink_arp.c
+++ b/nhrpd/netlink_arp.c
@@ -14,7 +14,7 @@
#include <linux/neighbour.h>
#include <linux/netfilter/nfnetlink_log.h>
-#include "thread.h"
+#include "frrevent.h"
#include "stream.h"
#include "prefix.h"
#include "nhrpd.h"
@@ -23,7 +23,7 @@
int netlink_nflog_group;
static int netlink_log_fd = -1;
-static struct thread *netlink_log_thread;
+static struct event *netlink_log_thread;
void netlink_update_binding(struct interface *ifp, union sockunion *proto,
union sockunion *nbma)
@@ -96,10 +96,10 @@ static void netlink_log_indication(struct nlmsghdr *msg, struct zbuf *zb)
nhrp_peer_send_indication(ifp, htons(pkthdr->hw_protocol), &pktpl);
}
-static void netlink_log_recv(struct thread *t)
+static void netlink_log_recv(struct event *t)
{
uint8_t buf[ZNL_BUFFER_SIZE];
- int fd = THREAD_FD(t);
+ int fd = EVENT_FD(t);
struct zbuf payload, zb;
struct nlmsghdr *n;
@@ -118,14 +118,14 @@ static void netlink_log_recv(struct thread *t)
}
}
- thread_add_read(master, netlink_log_recv, 0, netlink_log_fd,
- &netlink_log_thread);
+ event_add_read(master, netlink_log_recv, 0, netlink_log_fd,
+ &netlink_log_thread);
}
void netlink_set_nflog_group(int nlgroup)
{
if (netlink_log_fd >= 0) {
- thread_cancel(&netlink_log_thread);
+ event_cancel(&netlink_log_thread);
close(netlink_log_fd);
netlink_log_fd = -1;
}
@@ -136,8 +136,8 @@ void netlink_set_nflog_group(int nlgroup)
return;
netlink_log_register(netlink_log_fd, nlgroup);
- thread_add_read(master, netlink_log_recv, 0, netlink_log_fd,
- &netlink_log_thread);
+ event_add_read(master, netlink_log_recv, 0, netlink_log_fd,
+ &netlink_log_thread);
}
}
diff --git a/nhrpd/nhrp_cache.c b/nhrpd/nhrp_cache.c
index 31b370cbf8..1a11e0d98b 100644
--- a/nhrpd/nhrp_cache.c
+++ b/nhrpd/nhrp_cache.c
@@ -5,7 +5,7 @@
#include "zebra.h"
#include "memory.h"
-#include "thread.h"
+#include "frrevent.h"
#include "hash.h"
#include "nhrpd.h"
@@ -70,8 +70,10 @@ static void nhrp_cache_free(struct nhrp_cache *c)
notifier_call(&c->notifier_list, NOTIFY_CACHE_DELETE);
assert(!notifier_active(&c->notifier_list));
hash_release(nifp->cache_hash, c);
- THREAD_OFF(c->t_timeout);
- THREAD_OFF(c->t_auth);
+ nhrp_peer_unref(c->cur.peer);
+ nhrp_peer_unref(c->new.peer);
+ EVENT_OFF(c->t_timeout);
+ EVENT_OFF(c->t_auth);
XFREE(MTYPE_NHRP_CACHE, c);
}
@@ -193,17 +195,17 @@ struct nhrp_cache *nhrp_cache_get(struct interface *ifp,
create ? nhrp_cache_alloc : NULL);
}
-static void nhrp_cache_do_free(struct thread *t)
+static void nhrp_cache_do_free(struct event *t)
{
- struct nhrp_cache *c = THREAD_ARG(t);
+ struct nhrp_cache *c = EVENT_ARG(t);
c->t_timeout = NULL;
nhrp_cache_free(c);
}
-static void nhrp_cache_do_timeout(struct thread *t)
+static void nhrp_cache_do_timeout(struct event *t)
{
- struct nhrp_cache *c = THREAD_ARG(t);
+ struct nhrp_cache *c = EVENT_ARG(t);
c->t_timeout = NULL;
if (c->cur.type != NHRP_CACHE_INVALID)
@@ -308,7 +310,7 @@ static void nhrp_cache_peer_notifier(struct notifier_block *n,
static void nhrp_cache_reset_new(struct nhrp_cache *c)
{
- THREAD_OFF(c->t_auth);
+ EVENT_OFF(c->t_auth);
if (notifier_list_anywhere(&c->newpeer_notifier))
nhrp_peer_notify_del(c->new.peer, &c->newpeer_notifier);
nhrp_peer_unref(c->new.peer);
@@ -318,13 +320,13 @@ static void nhrp_cache_reset_new(struct nhrp_cache *c)
static void nhrp_cache_update_timers(struct nhrp_cache *c)
{
- THREAD_OFF(c->t_timeout);
+ EVENT_OFF(c->t_timeout);
switch (c->cur.type) {
case NHRP_CACHE_INVALID:
if (!c->t_auth)
- thread_add_timer_msec(master, nhrp_cache_do_free, c, 10,
- &c->t_timeout);
+ event_add_timer_msec(master, nhrp_cache_do_free, c, 10,
+ &c->t_timeout);
break;
case NHRP_CACHE_INCOMPLETE:
case NHRP_CACHE_NEGATIVE:
@@ -335,9 +337,9 @@ static void nhrp_cache_update_timers(struct nhrp_cache *c)
case NHRP_CACHE_LOCAL:
case NHRP_CACHE_NUM_TYPES:
if (c->cur.expires)
- thread_add_timer(master, nhrp_cache_do_timeout, c,
- c->cur.expires - monotime(NULL),
- &c->t_timeout);
+ event_add_timer(master, nhrp_cache_do_timeout, c,
+ c->cur.expires - monotime(NULL),
+ &c->t_timeout);
break;
}
}
@@ -393,9 +395,9 @@ static void nhrp_cache_authorize_binding(struct nhrp_reqid *r, void *arg)
nhrp_cache_update_timers(c);
}
-static void nhrp_cache_do_auth_timeout(struct thread *t)
+static void nhrp_cache_do_auth_timeout(struct event *t)
{
- struct nhrp_cache *c = THREAD_ARG(t);
+ struct nhrp_cache *c = EVENT_ARG(t);
c->t_auth = NULL;
nhrp_cache_authorize_binding(&c->eventid, (void *)"timeout");
}
@@ -411,8 +413,8 @@ static void nhrp_cache_newpeer_notifier(struct notifier_block *n,
if (nhrp_peer_check(c->new.peer, 1)) {
evmgr_notify("authorize-binding", c,
nhrp_cache_authorize_binding);
- thread_add_timer(master, nhrp_cache_do_auth_timeout, c,
- 10, &c->t_auth);
+ event_add_timer(master, nhrp_cache_do_auth_timeout, c,
+ 10, &c->t_auth);
}
break;
case NOTIFY_PEER_DOWN:
@@ -504,8 +506,8 @@ int nhrp_cache_update_binding(struct nhrp_cache *c, enum nhrp_cache_type type,
nhrp_cache_newpeer_notifier);
nhrp_cache_newpeer_notifier(&c->newpeer_notifier,
NOTIFY_PEER_UP);
- thread_add_timer(master, nhrp_cache_do_auth_timeout, c,
- 60, &c->t_auth);
+ event_add_timer(master, nhrp_cache_do_auth_timeout, c,
+ 60, &c->t_auth);
}
}
nhrp_cache_update_timers(c);
diff --git a/nhrpd/nhrp_event.c b/nhrpd/nhrp_event.c
index 9c11890831..ba318581d5 100644
--- a/nhrpd/nhrp_event.c
+++ b/nhrpd/nhrp_event.c
@@ -11,7 +11,7 @@
#include <sys/socket.h>
#include <sys/un.h>
-#include "thread.h"
+#include "frrevent.h"
#include "zbuf.h"
#include "log.h"
#include "nhrpd.h"
@@ -20,19 +20,19 @@ const char *nhrp_event_socket_path;
struct nhrp_reqid_pool nhrp_event_reqid;
struct event_manager {
- struct thread *t_reconnect, *t_read, *t_write;
+ struct event *t_reconnect, *t_read, *t_write;
struct zbuf ibuf;
struct zbuf_queue obuf;
int fd;
uint8_t ibuf_data[4 * 1024];
};
-static void evmgr_reconnect(struct thread *t);
+static void evmgr_reconnect(struct event *t);
static void evmgr_connection_error(struct event_manager *evmgr)
{
- THREAD_OFF(evmgr->t_read);
- THREAD_OFF(evmgr->t_write);
+ EVENT_OFF(evmgr->t_read);
+ EVENT_OFF(evmgr->t_write);
zbuf_reset(&evmgr->ibuf);
zbufq_reset(&evmgr->obuf);
@@ -40,8 +40,8 @@ static void evmgr_connection_error(struct event_manager *evmgr)
close(evmgr->fd);
evmgr->fd = -1;
if (nhrp_event_socket_path)
- thread_add_timer_msec(master, evmgr_reconnect, evmgr, 10,
- &evmgr->t_reconnect);
+ event_add_timer_msec(master, evmgr_reconnect, evmgr, 10,
+ &evmgr->t_reconnect);
}
static void evmgr_recv_message(struct event_manager *evmgr, struct zbuf *zb)
@@ -74,9 +74,9 @@ static void evmgr_recv_message(struct event_manager *evmgr, struct zbuf *zb)
}
}
-static void evmgr_read(struct thread *t)
+static void evmgr_read(struct event *t)
{
- struct event_manager *evmgr = THREAD_ARG(t);
+ struct event_manager *evmgr = EVENT_ARG(t);
struct zbuf *ibuf = &evmgr->ibuf;
struct zbuf msg;
@@ -89,18 +89,18 @@ static void evmgr_read(struct thread *t)
while (zbuf_may_pull_until(ibuf, "\n\n", &msg))
evmgr_recv_message(evmgr, &msg);
- thread_add_read(master, evmgr_read, evmgr, evmgr->fd, &evmgr->t_read);
+ event_add_read(master, evmgr_read, evmgr, evmgr->fd, &evmgr->t_read);
}
-static void evmgr_write(struct thread *t)
+static void evmgr_write(struct event *t)
{
- struct event_manager *evmgr = THREAD_ARG(t);
+ struct event_manager *evmgr = EVENT_ARG(t);
int r;
r = zbufq_write(&evmgr->obuf, evmgr->fd);
if (r > 0) {
- thread_add_write(master, evmgr_write, evmgr, evmgr->fd,
- &evmgr->t_write);
+ event_add_write(master, evmgr_write, evmgr, evmgr->fd,
+ &evmgr->t_write);
} else if (r < 0) {
evmgr_connection_error(evmgr);
}
@@ -175,13 +175,13 @@ static void evmgr_submit(struct event_manager *evmgr, struct zbuf *obuf)
zbuf_put(obuf, "\n", 1);
zbufq_queue(&evmgr->obuf, obuf);
if (evmgr->fd >= 0)
- thread_add_write(master, evmgr_write, evmgr, evmgr->fd,
- &evmgr->t_write);
+ event_add_write(master, evmgr_write, evmgr, evmgr->fd,
+ &evmgr->t_write);
}
-static void evmgr_reconnect(struct thread *t)
+static void evmgr_reconnect(struct event *t)
{
- struct event_manager *evmgr = THREAD_ARG(t);
+ struct event_manager *evmgr = EVENT_ARG(t);
int fd;
if (evmgr->fd >= 0 || !nhrp_event_socket_path)
@@ -192,14 +192,14 @@ static void evmgr_reconnect(struct thread *t)
zlog_warn("%s: failure connecting nhrp-event socket: %s",
__func__, strerror(errno));
zbufq_reset(&evmgr->obuf);
- thread_add_timer(master, evmgr_reconnect, evmgr, 10,
- &evmgr->t_reconnect);
+ event_add_timer(master, evmgr_reconnect, evmgr, 10,
+ &evmgr->t_reconnect);
return;
}
zlog_info("Connected to Event Manager");
evmgr->fd = fd;
- thread_add_read(master, evmgr_read, evmgr, evmgr->fd, &evmgr->t_read);
+ event_add_read(master, evmgr_read, evmgr, evmgr->fd, &evmgr->t_read);
}
static struct event_manager evmgr_connection;
@@ -211,8 +211,8 @@ void evmgr_init(void)
evmgr->fd = -1;
zbuf_init(&evmgr->ibuf, evmgr->ibuf_data, sizeof(evmgr->ibuf_data), 0);
zbufq_init(&evmgr->obuf);
- thread_add_timer_msec(master, evmgr_reconnect, evmgr, 10,
- &evmgr->t_reconnect);
+ event_add_timer_msec(master, evmgr_reconnect, evmgr, 10,
+ &evmgr->t_reconnect);
}
void evmgr_set_socket(const char *socket)
diff --git a/nhrpd/nhrp_interface.c b/nhrpd/nhrp_interface.c
index d396f510ed..7c84fde367 100644
--- a/nhrpd/nhrp_interface.c
+++ b/nhrpd/nhrp_interface.c
@@ -11,7 +11,7 @@
#include "zebra.h"
#include "linklist.h"
#include "memory.h"
-#include "thread.h"
+#include "frrevent.h"
#include "nhrpd.h"
#include "os.h"
diff --git a/nhrpd/nhrp_main.c b/nhrpd/nhrp_main.c
index 10d3c8f82f..593498ca13 100644
--- a/nhrpd/nhrp_main.c
+++ b/nhrpd/nhrp_main.c
@@ -12,7 +12,7 @@
#include "zebra.h"
#include "privs.h"
#include "getopt.h"
-#include "thread.h"
+#include "frrevent.h"
#include "sigevent.h"
#include "lib/version.h"
#include "log.h"
@@ -28,7 +28,7 @@ DEFINE_MGROUP(NHRPD, "NHRP");
unsigned int debug_flags = 0;
-struct thread_master *master;
+struct event_loop *master;
struct timeval current_time;
/* nhrpd options. */
diff --git a/nhrpd/nhrp_multicast.c b/nhrpd/nhrp_multicast.c
index cdd79e25f4..fdc1a31f25 100644
--- a/nhrpd/nhrp_multicast.c
+++ b/nhrpd/nhrp_multicast.c
@@ -18,7 +18,7 @@
#include <sys/types.h>
#include <sys/socket.h>
-#include "thread.h"
+#include "frrevent.h"
#include "nhrpd.h"
#include "netlink.h"
#include "znl.h"
@@ -28,7 +28,7 @@ DEFINE_MTYPE_STATIC(NHRPD, NHRP_MULTICAST, "NHRP Multicast");
int netlink_mcast_nflog_group;
static int netlink_mcast_log_fd = -1;
-static struct thread *netlink_mcast_log_thread;
+static struct event *netlink_mcast_log_thread;
struct mcast_ctx {
struct interface *ifp;
@@ -138,10 +138,10 @@ static void netlink_mcast_log_handler(struct nlmsghdr *msg, struct zbuf *zb)
}
}
-static void netlink_mcast_log_recv(struct thread *t)
+static void netlink_mcast_log_recv(struct event *t)
{
uint8_t buf[65535]; /* Max OSPF Packet size */
- int fd = THREAD_FD(t);
+ int fd = EVENT_FD(t);
struct zbuf payload, zb;
struct nlmsghdr *n;
@@ -160,8 +160,8 @@ static void netlink_mcast_log_recv(struct thread *t)
}
}
- thread_add_read(master, netlink_mcast_log_recv, 0, netlink_mcast_log_fd,
- &netlink_mcast_log_thread);
+ event_add_read(master, netlink_mcast_log_recv, 0, netlink_mcast_log_fd,
+ &netlink_mcast_log_thread);
}
static void netlink_mcast_log_register(int fd, int group)
@@ -190,7 +190,7 @@ static void netlink_mcast_log_register(int fd, int group)
void netlink_mcast_set_nflog_group(int nlgroup)
{
if (netlink_mcast_log_fd >= 0) {
- THREAD_OFF(netlink_mcast_log_thread);
+ EVENT_OFF(netlink_mcast_log_thread);
close(netlink_mcast_log_fd);
netlink_mcast_log_fd = -1;
debugf(NHRP_DEBUG_COMMON, "De-register nflog group");
@@ -202,9 +202,8 @@ void netlink_mcast_set_nflog_group(int nlgroup)
return;
netlink_mcast_log_register(netlink_mcast_log_fd, nlgroup);
- thread_add_read(master, netlink_mcast_log_recv, 0,
- netlink_mcast_log_fd,
- &netlink_mcast_log_thread);
+ event_add_read(master, netlink_mcast_log_recv, 0,
+ netlink_mcast_log_fd, &netlink_mcast_log_thread);
debugf(NHRP_DEBUG_COMMON, "Register nflog group: %d",
netlink_mcast_nflog_group);
}
diff --git a/nhrpd/nhrp_nhs.c b/nhrpd/nhrp_nhs.c
index 49f881df1f..b2af0da429 100644
--- a/nhrpd/nhrp_nhs.c
+++ b/nhrpd/nhrp_nhs.c
@@ -6,15 +6,15 @@
#include "zebra.h"
#include "zbuf.h"
#include "memory.h"
-#include "thread.h"
+#include "frrevent.h"
#include "nhrpd.h"
#include "nhrp_protocol.h"
DEFINE_MTYPE_STATIC(NHRPD, NHRP_NHS, "NHRP next hop server");
DEFINE_MTYPE_STATIC(NHRPD, NHRP_REGISTRATION, "NHRP registration entries");
-static void nhrp_nhs_resolve(struct thread *t);
-static void nhrp_reg_send_req(struct thread *t);
+static void nhrp_nhs_resolve(struct event *t);
+static void nhrp_reg_send_req(struct event *t);
static void nhrp_reg_reply(struct nhrp_reqid *reqid, void *arg)
{
@@ -88,12 +88,12 @@ static void nhrp_reg_reply(struct nhrp_reqid *reqid, void *arg)
/* Success - schedule next registration, and route NHS */
r->timeout = 2;
holdtime = nifp->afi[nhs->afi].holdtime;
- THREAD_OFF(r->t_register);
+ EVENT_OFF(r->t_register);
/* RFC 2332 5.2.3 - Registration is recommend to be renewed
* every one third of holdtime */
- thread_add_timer(master, nhrp_reg_send_req, r, holdtime / 3,
- &r->t_register);
+ event_add_timer(master, nhrp_reg_send_req, r, holdtime / 3,
+ &r->t_register);
r->proto_addr = p->dst_proto;
c = nhrp_cache_get(ifp, &p->dst_proto, 1);
@@ -103,9 +103,9 @@ static void nhrp_reg_reply(struct nhrp_reqid *reqid, void *arg)
&cie_nbma_nhs);
}
-static void nhrp_reg_timeout(struct thread *t)
+static void nhrp_reg_timeout(struct event *t)
{
- struct nhrp_registration *r = THREAD_ARG(t);
+ struct nhrp_registration *r = EVENT_ARG(t);
struct nhrp_cache *c;
@@ -133,7 +133,7 @@ static void nhrp_reg_timeout(struct thread *t)
}
r->timeout = 2;
}
- thread_add_timer_msec(master, nhrp_reg_send_req, r, 10, &r->t_register);
+ event_add_timer_msec(master, nhrp_reg_send_req, r, 10, &r->t_register);
}
static void nhrp_reg_peer_notify(struct notifier_block *n, unsigned long cmd)
@@ -148,16 +148,16 @@ static void nhrp_reg_peer_notify(struct notifier_block *n, unsigned long cmd)
case NOTIFY_PEER_MTU_CHANGED:
debugf(NHRP_DEBUG_COMMON, "NHS: Flush timer for %pSU",
&r->peer->vc->remote.nbma);
- THREAD_OFF(r->t_register);
- thread_add_timer_msec(master, nhrp_reg_send_req, r, 10,
- &r->t_register);
+ EVENT_OFF(r->t_register);
+ event_add_timer_msec(master, nhrp_reg_send_req, r, 10,
+ &r->t_register);
break;
}
}
-static void nhrp_reg_send_req(struct thread *t)
+static void nhrp_reg_send_req(struct event *t)
{
- struct nhrp_registration *r = THREAD_ARG(t);
+ struct nhrp_registration *r = EVENT_ARG(t);
struct nhrp_nhs *nhs = r->nhs;
struct interface *ifp = nhs->ifp;
struct nhrp_interface *nifp = ifp->info;
@@ -171,13 +171,13 @@ static void nhrp_reg_send_req(struct thread *t)
if (!nhrp_peer_check(r->peer, 2)) {
debugf(NHRP_DEBUG_COMMON, "NHS: Waiting link for %pSU",
&r->peer->vc->remote.nbma);
- thread_add_timer(master, nhrp_reg_send_req, r, 120,
- &r->t_register);
+ event_add_timer(master, nhrp_reg_send_req, r, 120,
+ &r->t_register);
return;
}
- thread_add_timer(master, nhrp_reg_timeout, r, r->timeout,
- &r->t_register);
+ event_add_timer(master, nhrp_reg_timeout, r, r->timeout,
+ &r->t_register);
/* RFC2332 5.2.3 NHC uses it's own address as dst if NHS is unknown */
dst_proto = &nhs->proto_addr;
@@ -244,7 +244,7 @@ static void nhrp_reg_delete(struct nhrp_registration *r)
nhrp_peer_notify_del(r->peer, &r->peer_notifier);
nhrp_peer_unref(r->peer);
nhrp_reglist_del(&r->nhs->reglist_head, r);
- THREAD_OFF(r->t_register);
+ EVENT_OFF(r->t_register);
XFREE(MTYPE_NHRP_REGISTRATION, r);
}
@@ -269,13 +269,13 @@ static void nhrp_nhs_resolve_cb(struct resolver_query *q, const char *errstr,
if (n < 0) {
/* Failed, retry in a moment */
- thread_add_timer(master, nhrp_nhs_resolve, nhs, 5,
- &nhs->t_resolve);
+ event_add_timer(master, nhrp_nhs_resolve, nhs, 5,
+ &nhs->t_resolve);
return;
}
- thread_add_timer(master, nhrp_nhs_resolve, nhs, 2 * 60 * 60,
- &nhs->t_resolve);
+ event_add_timer(master, nhrp_nhs_resolve, nhs, 2 * 60 * 60,
+ &nhs->t_resolve);
frr_each (nhrp_reglist, &nhs->reglist_head, reg)
reg->mark = 1;
@@ -300,8 +300,8 @@ static void nhrp_nhs_resolve_cb(struct resolver_query *q, const char *errstr,
nhrp_reglist_add_tail(&nhs->reglist_head, reg);
nhrp_peer_notify_add(reg->peer, &reg->peer_notifier,
nhrp_reg_peer_notify);
- thread_add_timer_msec(master, nhrp_reg_send_req, reg, 50,
- &reg->t_register);
+ event_add_timer_msec(master, nhrp_reg_send_req, reg, 50,
+ &reg->t_register);
}
frr_each_safe (nhrp_reglist, &nhs->reglist_head, reg)
@@ -309,9 +309,9 @@ static void nhrp_nhs_resolve_cb(struct resolver_query *q, const char *errstr,
nhrp_reg_delete(reg);
}
-static void nhrp_nhs_resolve(struct thread *t)
+static void nhrp_nhs_resolve(struct event *t)
{
- struct nhrp_nhs *nhs = THREAD_ARG(t);
+ struct nhrp_nhs *nhs = EVENT_ARG(t);
resolver_resolve(&nhs->dns_resolve, AF_INET, VRF_DEFAULT,
nhs->nbma_fqdn, nhrp_nhs_resolve_cb);
@@ -347,8 +347,8 @@ int nhrp_nhs_add(struct interface *ifp, afi_t afi, union sockunion *proto_addr,
.reglist_head = INIT_DLIST(nhs->reglist_head),
};
nhrp_nhslist_add_tail(&nifp->afi[afi].nhslist_head, nhs);
- thread_add_timer_msec(master, nhrp_nhs_resolve, nhs, 1000,
- &nhs->t_resolve);
+ event_add_timer_msec(master, nhrp_nhs_resolve, nhs, 1000,
+ &nhs->t_resolve);
return NHRP_OK;
}
@@ -383,7 +383,7 @@ int nhrp_nhs_free(struct nhrp_interface *nifp, afi_t afi, struct nhrp_nhs *nhs)
frr_each_safe (nhrp_reglist, &nhs->reglist_head, r)
nhrp_reg_delete(r);
- THREAD_OFF(nhs->t_resolve);
+ EVENT_OFF(nhs->t_resolve);
nhrp_nhslist_del(&nifp->afi[afi].nhslist_head, nhs);
free((void *)nhs->nbma_fqdn);
XFREE(MTYPE_NHRP_NHS, nhs);
diff --git a/nhrpd/nhrp_packet.c b/nhrpd/nhrp_packet.c
index ecf8aa0b13..9d0b30cfee 100644
--- a/nhrpd/nhrp_packet.c
+++ b/nhrpd/nhrp_packet.c
@@ -10,7 +10,7 @@
#include <netinet/if_ether.h>
#include "nhrpd.h"
#include "zbuf.h"
-#include "thread.h"
+#include "frrevent.h"
#include "hash.h"
#include "nhrp_protocol.h"
@@ -286,9 +286,9 @@ err:
return -1;
}
-static void nhrp_packet_recvraw(struct thread *t)
+static void nhrp_packet_recvraw(struct event *t)
{
- int fd = THREAD_FD(t), ifindex;
+ int fd = EVENT_FD(t), ifindex;
struct zbuf *zb;
struct interface *ifp;
struct nhrp_peer *p;
@@ -296,7 +296,7 @@ static void nhrp_packet_recvraw(struct thread *t)
uint8_t addr[64];
size_t len, addrlen;
- thread_add_read(master, nhrp_packet_recvraw, 0, fd, NULL);
+ event_add_read(master, nhrp_packet_recvraw, 0, fd, NULL);
zb = zbuf_alloc(1500);
if (!zb)
@@ -336,6 +336,6 @@ err:
int nhrp_packet_init(void)
{
- thread_add_read(master, nhrp_packet_recvraw, 0, os_socket(), NULL);
+ event_add_read(master, nhrp_packet_recvraw, 0, os_socket(), NULL);
return 0;
}
diff --git a/nhrpd/nhrp_peer.c b/nhrpd/nhrp_peer.c
index 0c9d5ade37..ffb6cf7506 100644
--- a/nhrpd/nhrp_peer.c
+++ b/nhrpd/nhrp_peer.c
@@ -11,7 +11,7 @@
#include "zebra.h"
#include "memory.h"
-#include "thread.h"
+#include "frrevent.h"
#include "hash.h"
#include "network.h"
@@ -43,17 +43,17 @@ static void nhrp_peer_check_delete(struct nhrp_peer *p)
debugf(NHRP_DEBUG_COMMON, "Deleting peer ref:%d remote:%pSU local:%pSU",
p->ref, &p->vc->remote.nbma, &p->vc->local.nbma);
- THREAD_OFF(p->t_fallback);
- THREAD_OFF(p->t_timer);
+ EVENT_OFF(p->t_fallback);
+ EVENT_OFF(p->t_timer);
hash_release(nifp->peer_hash, p);
nhrp_interface_notify_del(p->ifp, &p->ifp_notifier);
nhrp_vc_notify_del(p->vc, &p->vc_notifier);
XFREE(MTYPE_NHRP_PEER, p);
}
-static void nhrp_peer_notify_up(struct thread *t)
+static void nhrp_peer_notify_up(struct event *t)
{
- struct nhrp_peer *p = THREAD_ARG(t);
+ struct nhrp_peer *p = EVENT_ARG(t);
struct nhrp_vc *vc = p->vc;
struct interface *ifp = p->ifp;
struct nhrp_interface *nifp = ifp->info;
@@ -76,14 +76,14 @@ static void __nhrp_peer_check(struct nhrp_peer *p)
online = nifp->enabled && (!nifp->ipsec_profile || vc->ipsec);
if (p->online != online) {
- THREAD_OFF(p->t_fallback);
+ EVENT_OFF(p->t_fallback);
if (online && notifier_active(&p->notifier_list)) {
/* If we requested the IPsec connection, delay
* the up notification a bit to allow things
* settle down. This allows IKE to install
* SPDs and SAs. */
- thread_add_timer_msec(master, nhrp_peer_notify_up, p,
- 50, &p->t_fallback);
+ event_add_timer_msec(master, nhrp_peer_notify_up, p, 50,
+ &p->t_fallback);
} else {
nhrp_peer_ref(p);
p->online = online;
@@ -201,12 +201,7 @@ void nhrp_peer_interface_del(struct interface *ifp)
debugf(NHRP_DEBUG_COMMON, "Cleaning up undeleted peer entries (%lu)",
nifp->peer_hash ? nifp->peer_hash->count : 0);
- if (nifp->peer_hash) {
- hash_clean(nifp->peer_hash, do_peer_hash_free);
- assert(nifp->peer_hash->count == 0);
- hash_free(nifp->peer_hash);
- nifp->peer_hash = NULL;
- }
+ hash_clean_and_free(&nifp->peer_hash, do_peer_hash_free);
}
struct nhrp_peer *nhrp_peer_get(struct interface *ifp,
@@ -253,9 +248,9 @@ void nhrp_peer_unref(struct nhrp_peer *p)
}
}
-static void nhrp_peer_request_timeout(struct thread *t)
+static void nhrp_peer_request_timeout(struct event *t)
{
- struct nhrp_peer *p = THREAD_ARG(t);
+ struct nhrp_peer *p = EVENT_ARG(t);
struct nhrp_vc *vc = p->vc;
struct interface *ifp = p->ifp;
struct nhrp_interface *nifp = ifp->info;
@@ -269,21 +264,21 @@ static void nhrp_peer_request_timeout(struct thread *t)
p->fallback_requested = 1;
vici_request_vc(nifp->ipsec_fallback_profile, &vc->local.nbma,
&vc->remote.nbma, p->prio);
- thread_add_timer(master, nhrp_peer_request_timeout, p, 30,
- &p->t_fallback);
+ event_add_timer(master, nhrp_peer_request_timeout, p, 30,
+ &p->t_fallback);
} else {
p->requested = p->fallback_requested = 0;
}
}
-static void nhrp_peer_defer_vici_request(struct thread *t)
+static void nhrp_peer_defer_vici_request(struct event *t)
{
- struct nhrp_peer *p = THREAD_ARG(t);
+ struct nhrp_peer *p = EVENT_ARG(t);
struct nhrp_vc *vc = p->vc;
struct interface *ifp = p->ifp;
struct nhrp_interface *nifp = ifp->info;
- THREAD_OFF(p->t_timer);
+ EVENT_OFF(p->t_timer);
if (p->online) {
debugf(NHRP_DEBUG_COMMON,
@@ -292,10 +287,10 @@ static void nhrp_peer_defer_vici_request(struct thread *t)
} else {
vici_request_vc(nifp->ipsec_profile, &vc->local.nbma,
&vc->remote.nbma, p->prio);
- thread_add_timer(
- master, nhrp_peer_request_timeout, p,
- (nifp->ipsec_fallback_profile && !p->prio) ? 15 : 30,
- &p->t_fallback);
+ event_add_timer(master, nhrp_peer_request_timeout, p,
+ (nifp->ipsec_fallback_profile && !p->prio) ? 15
+ : 30,
+ &p->t_fallback);
}
}
@@ -325,10 +320,10 @@ int nhrp_peer_check(struct nhrp_peer *p, int establish)
if (p->prio) {
vici_request_vc(nifp->ipsec_profile, &vc->local.nbma,
&vc->remote.nbma, p->prio);
- thread_add_timer(
- master, nhrp_peer_request_timeout, p,
- (nifp->ipsec_fallback_profile && !p->prio) ? 15 : 30,
- &p->t_fallback);
+ event_add_timer(master, nhrp_peer_request_timeout, p,
+ (nifp->ipsec_fallback_profile && !p->prio) ? 15
+ : 30,
+ &p->t_fallback);
} else {
/* Maximum timeout is 1 second */
int r_time_ms = frr_weak_random() % 1000;
@@ -336,8 +331,8 @@ int nhrp_peer_check(struct nhrp_peer *p, int establish)
debugf(NHRP_DEBUG_COMMON,
"Initiating IPsec connection request to %pSU after %d ms:",
&vc->remote.nbma, r_time_ms);
- thread_add_timer_msec(master, nhrp_peer_defer_vici_request,
- p, r_time_ms, &p->t_timer);
+ event_add_timer_msec(master, nhrp_peer_defer_vici_request, p,
+ r_time_ms, &p->t_timer);
}
return 0;
diff --git a/nhrpd/nhrp_shortcut.c b/nhrpd/nhrp_shortcut.c
index 90fb1d67c2..04dad2aea6 100644
--- a/nhrpd/nhrp_shortcut.c
+++ b/nhrpd/nhrp_shortcut.c
@@ -10,7 +10,7 @@
#include "nhrpd.h"
#include "table.h"
#include "memory.h"
-#include "thread.h"
+#include "frrevent.h"
#include "log.h"
#include "nhrp_protocol.h"
@@ -18,7 +18,7 @@ DEFINE_MTYPE_STATIC(NHRPD, NHRP_SHORTCUT, "NHRP shortcut");
static struct route_table *shortcut_rib[AFI_MAX];
-static void nhrp_shortcut_do_purge(struct thread *t);
+static void nhrp_shortcut_do_purge(struct event *t);
static void nhrp_shortcut_delete(struct nhrp_shortcut *s);
static void nhrp_shortcut_send_resolution_req(struct nhrp_shortcut *s);
@@ -31,12 +31,12 @@ static void nhrp_shortcut_check_use(struct nhrp_shortcut *s)
}
}
-static void nhrp_shortcut_do_expire(struct thread *t)
+static void nhrp_shortcut_do_expire(struct event *t)
{
- struct nhrp_shortcut *s = THREAD_ARG(t);
+ struct nhrp_shortcut *s = EVENT_ARG(t);
- thread_add_timer(master, nhrp_shortcut_do_purge, s, s->holding_time / 3,
- &s->t_timer);
+ event_add_timer(master, nhrp_shortcut_do_purge, s, s->holding_time / 3,
+ &s->t_timer);
s->expiring = 1;
nhrp_shortcut_check_use(s);
}
@@ -123,12 +123,12 @@ static void nhrp_shortcut_update_binding(struct nhrp_shortcut *s,
s->route_installed = 0;
}
- THREAD_OFF(s->t_timer);
+ EVENT_OFF(s->t_timer);
if (holding_time) {
s->expiring = 0;
s->holding_time = holding_time;
- thread_add_timer(master, nhrp_shortcut_do_expire, s,
- 2 * holding_time / 3, &s->t_timer);
+ event_add_timer(master, nhrp_shortcut_do_expire, s,
+ 2 * holding_time / 3, &s->t_timer);
}
}
@@ -137,7 +137,7 @@ static void nhrp_shortcut_delete(struct nhrp_shortcut *s)
struct route_node *rn;
afi_t afi = family2afi(PREFIX_FAMILY(s->p));
- THREAD_OFF(s->t_timer);
+ EVENT_OFF(s->t_timer);
nhrp_reqid_free(&nhrp_packet_reqid, &s->reqid);
debugf(NHRP_DEBUG_ROUTE, "Shortcut %pFX purged", s->p);
@@ -154,9 +154,9 @@ static void nhrp_shortcut_delete(struct nhrp_shortcut *s)
}
}
-static void nhrp_shortcut_do_purge(struct thread *t)
+static void nhrp_shortcut_do_purge(struct event *t)
{
- struct nhrp_shortcut *s = THREAD_ARG(t);
+ struct nhrp_shortcut *s = EVENT_ARG(t);
s->t_timer = NULL;
nhrp_shortcut_delete(s);
}
@@ -204,8 +204,8 @@ static void nhrp_shortcut_recv_resolution_rep(struct nhrp_reqid *reqid,
int holding_time = pp->if_ad->holdtime;
nhrp_reqid_free(&nhrp_packet_reqid, &s->reqid);
- THREAD_OFF(s->t_timer);
- thread_add_timer(master, nhrp_shortcut_do_purge, s, 1, &s->t_timer);
+ EVENT_OFF(s->t_timer);
+ event_add_timer(master, nhrp_shortcut_do_purge, s, 1, &s->t_timer);
if (pp->hdr->type != NHRP_PACKET_RESOLUTION_REPLY) {
if (pp->hdr->type == NHRP_PACKET_ERROR_INDICATION
@@ -454,9 +454,9 @@ void nhrp_shortcut_initiate(union sockunion *addr)
s = nhrp_shortcut_get(&p);
if (s && s->type != NHRP_CACHE_INCOMPLETE) {
s->addr = *addr;
- THREAD_OFF(s->t_timer);
- thread_add_timer(master, nhrp_shortcut_do_purge, s, 30,
- &s->t_timer);
+ EVENT_OFF(s->t_timer);
+ event_add_timer(master, nhrp_shortcut_do_purge, s, 30,
+ &s->t_timer);
nhrp_shortcut_send_resolution_req(s);
}
}
@@ -499,13 +499,13 @@ struct purge_ctx {
void nhrp_shortcut_purge(struct nhrp_shortcut *s, int force)
{
- THREAD_OFF(s->t_timer);
+ EVENT_OFF(s->t_timer);
nhrp_reqid_free(&nhrp_packet_reqid, &s->reqid);
if (force) {
/* Immediate purge on route with draw or pending shortcut */
- thread_add_timer_msec(master, nhrp_shortcut_do_purge, s, 5,
- &s->t_timer);
+ event_add_timer_msec(master, nhrp_shortcut_do_purge, s, 5,
+ &s->t_timer);
} else {
/* Soft expire - force immediate renewal, but purge
* in few seconds to make sure stale route is not
@@ -514,8 +514,8 @@ void nhrp_shortcut_purge(struct nhrp_shortcut *s, int force)
* This allows to keep nhrp route up, and to not
* cause temporary rerouting via hubs causing latency
* jitter. */
- thread_add_timer_msec(master, nhrp_shortcut_do_purge, s, 3000,
- &s->t_timer);
+ event_add_timer_msec(master, nhrp_shortcut_do_purge, s, 3000,
+ &s->t_timer);
s->expiring = 1;
nhrp_shortcut_check_use(s);
}
diff --git a/nhrpd/nhrp_vc.c b/nhrpd/nhrp_vc.c
index bffb2f6e94..2c3201438b 100644
--- a/nhrpd/nhrp_vc.c
+++ b/nhrpd/nhrp_vc.c
@@ -7,7 +7,7 @@
#include "memory.h"
#include "stream.h"
#include "hash.h"
-#include "thread.h"
+#include "frrevent.h"
#include "jhash.h"
#include "nhrpd.h"
diff --git a/nhrpd/nhrpd.h b/nhrpd/nhrpd.h
index c01296bee5..1421f0fc38 100644
--- a/nhrpd/nhrpd.h
+++ b/nhrpd/nhrpd.h
@@ -19,7 +19,7 @@ DECLARE_MGROUP(NHRPD);
#define NHRP_VTY_PORT 2610
#define NHRP_DEFAULT_CONFIG "nhrpd.conf"
-extern struct thread_master *master;
+extern struct event_loop *master;
enum { NHRP_OK = 0,
NHRP_ERR_FAIL,
@@ -166,9 +166,9 @@ struct nhrp_peer {
struct notifier_list notifier_list;
struct interface *ifp;
struct nhrp_vc *vc;
- struct thread *t_fallback;
+ struct event *t_fallback;
struct notifier_block vc_notifier, ifp_notifier;
- struct thread *t_timer;
+ struct event *t_timer;
};
struct nhrp_packet_parser {
@@ -232,8 +232,8 @@ struct nhrp_cache {
struct notifier_block newpeer_notifier;
struct notifier_list notifier_list;
struct nhrp_reqid eventid;
- struct thread *t_timeout;
- struct thread *t_auth;
+ struct event *t_timeout;
+ struct event *t_auth;
struct {
enum nhrp_cache_type type;
@@ -251,7 +251,7 @@ struct nhrp_shortcut {
union sockunion addr;
struct nhrp_reqid reqid;
- struct thread *t_timer;
+ struct event *t_timer;
enum nhrp_cache_type type;
unsigned int holding_time;
@@ -275,7 +275,7 @@ struct nhrp_nhs {
union sockunion proto_addr;
const char *nbma_fqdn; /* IP-address or FQDN */
- struct thread *t_resolve;
+ struct event *t_resolve;
struct resolver_query dns_resolve;
struct nhrp_reglist_head reglist_head;
};
@@ -293,7 +293,7 @@ DECLARE_DLIST(nhrp_mcastlist, struct nhrp_multicast, mcastlist_entry);
struct nhrp_registration {
struct nhrp_reglist_item reglist_entry;
- struct thread *t_register;
+ struct event *t_register;
struct nhrp_nhs *nhs;
struct nhrp_reqid reqid;
unsigned int timeout;
diff --git a/nhrpd/vici.c b/nhrpd/vici.c
index 1dbb4e4f5e..2f76362603 100644
--- a/nhrpd/vici.c
+++ b/nhrpd/vici.c
@@ -11,7 +11,7 @@
#include <sys/socket.h>
#include <sys/un.h>
-#include "thread.h"
+#include "frrevent.h"
#include "zbuf.h"
#include "log.h"
#include "lib_errors.h"
@@ -44,7 +44,7 @@ static int blob2buf(const struct blob *b, char *buf, size_t n)
}
struct vici_conn {
- struct thread *t_reconnect, *t_read, *t_write;
+ struct event *t_reconnect, *t_read, *t_write;
struct zbuf ibuf;
struct zbuf_queue obuf;
int fd;
@@ -56,7 +56,7 @@ struct vici_message_ctx {
int nsections;
};
-static void vici_reconnect(struct thread *t);
+static void vici_reconnect(struct event *t);
static void vici_submit_request(struct vici_conn *vici, const char *name, ...);
static void vici_zbuf_puts(struct zbuf *obuf, const char *str)
@@ -70,14 +70,14 @@ static void vici_connection_error(struct vici_conn *vici)
{
nhrp_vc_reset();
- THREAD_OFF(vici->t_read);
- THREAD_OFF(vici->t_write);
+ EVENT_OFF(vici->t_read);
+ EVENT_OFF(vici->t_write);
zbuf_reset(&vici->ibuf);
zbufq_reset(&vici->obuf);
close(vici->fd);
vici->fd = -1;
- thread_add_timer(master, vici_reconnect, vici, 2, &vici->t_reconnect);
+ event_add_timer(master, vici_reconnect, vici, 2, &vici->t_reconnect);
}
static void vici_parse_message(struct vici_conn *vici, struct zbuf *msg,
@@ -357,9 +357,9 @@ static void vici_recv_message(struct vici_conn *vici, struct zbuf *msg)
}
}
-static void vici_read(struct thread *t)
+static void vici_read(struct event *t)
{
- struct vici_conn *vici = THREAD_ARG(t);
+ struct vici_conn *vici = EVENT_ARG(t);
struct zbuf *ibuf = &vici->ibuf;
struct zbuf pktbuf;
@@ -384,18 +384,18 @@ static void vici_read(struct thread *t)
vici_recv_message(vici, &pktbuf);
} while (1);
- thread_add_read(master, vici_read, vici, vici->fd, &vici->t_read);
+ event_add_read(master, vici_read, vici, vici->fd, &vici->t_read);
}
-static void vici_write(struct thread *t)
+static void vici_write(struct event *t)
{
- struct vici_conn *vici = THREAD_ARG(t);
+ struct vici_conn *vici = EVENT_ARG(t);
int r;
r = zbufq_write(&vici->obuf, vici->fd);
if (r > 0) {
- thread_add_write(master, vici_write, vici, vici->fd,
- &vici->t_write);
+ event_add_write(master, vici_write, vici, vici->fd,
+ &vici->t_write);
} else if (r < 0) {
vici_connection_error(vici);
}
@@ -409,7 +409,7 @@ static void vici_submit(struct vici_conn *vici, struct zbuf *obuf)
}
zbufq_queue(&vici->obuf, obuf);
- thread_add_write(master, vici_write, vici, vici->fd, &vici->t_write);
+ event_add_write(master, vici_write, vici, vici->fd, &vici->t_write);
}
static void vici_submit_request(struct vici_conn *vici, const char *name, ...)
@@ -500,9 +500,9 @@ static char *vici_get_charon_filepath(void)
return buff;
}
-static void vici_reconnect(struct thread *t)
+static void vici_reconnect(struct event *t)
{
- struct vici_conn *vici = THREAD_ARG(t);
+ struct vici_conn *vici = EVENT_ARG(t);
int fd;
char *file_path;
@@ -519,14 +519,14 @@ static void vici_reconnect(struct thread *t)
debugf(NHRP_DEBUG_VICI,
"%s: failure connecting VICI socket: %s", __func__,
strerror(errno));
- thread_add_timer(master, vici_reconnect, vici, 2,
- &vici->t_reconnect);
+ event_add_timer(master, vici_reconnect, vici, 2,
+ &vici->t_reconnect);
return;
}
debugf(NHRP_DEBUG_COMMON, "VICI: Connected");
vici->fd = fd;
- thread_add_read(master, vici_read, vici, vici->fd, &vici->t_read);
+ event_add_read(master, vici_read, vici, vici->fd, &vici->t_read);
/* Send event subscribtions */
// vici_register_event(vici, "child-updown");
@@ -547,8 +547,8 @@ void vici_init(void)
vici->fd = -1;
zbuf_init(&vici->ibuf, vici->ibuf_data, sizeof(vici->ibuf_data), 0);
zbufq_init(&vici->obuf);
- thread_add_timer_msec(master, vici_reconnect, vici, 10,
- &vici->t_reconnect);
+ event_add_timer_msec(master, vici_reconnect, vici, 10,
+ &vici->t_reconnect);
}
void vici_terminate(void)
diff --git a/ospf6d/ospf6_abr.c b/ospf6d/ospf6_abr.c
index 4def3c7386..f4202a4a29 100644
--- a/ospf6d/ospf6_abr.c
+++ b/ospf6d/ospf6_abr.c
@@ -12,7 +12,7 @@
#include "vty.h"
#include "linklist.h"
#include "command.h"
-#include "thread.h"
+#include "frrevent.h"
#include "plist.h"
#include "filter.h"
@@ -515,11 +515,21 @@ int ospf6_abr_originate_summary_to_area(struct ospf6_route *route,
summary->path.origin.id =
ADV_ROUTER_IN_PREFIX(&route->prefix);
} else {
+ struct ospf6_lsa *old;
+
summary->path.origin.type =
htons(OSPF6_LSTYPE_INTER_PREFIX);
- summary->path.origin.id = ospf6_new_ls_id(
- summary->path.origin.type,
- summary->path.origin.adv_router, area->lsdb);
+
+ /* Try to reuse LS-ID from previous running instance. */
+ old = ospf6_find_inter_prefix_lsa(area->ospf6, area,
+ &route->prefix);
+ if (old)
+ summary->path.origin.id = old->header->id;
+ else
+ summary->path.origin.id = ospf6_new_ls_id(
+ summary->path.origin.type,
+ summary->path.origin.adv_router,
+ area->lsdb);
}
summary = ospf6_route_add(summary, summary_table);
} else {
diff --git a/ospf6d/ospf6_area.c b/ospf6d/ospf6_area.c
index 5795690a78..69c711bf06 100644
--- a/ospf6d/ospf6_area.c
+++ b/ospf6d/ospf6_area.c
@@ -8,7 +8,7 @@
#include "log.h"
#include "memory.h"
#include "linklist.h"
-#include "thread.h"
+#include "frrevent.h"
#include "vty.h"
#include "command.h"
#include "if.h"
@@ -421,8 +421,8 @@ void ospf6_area_disable(struct ospf6_area *oa)
ospf6_spf_table_finish(oa->spf_table);
ospf6_route_remove_all(oa->route_table);
- THREAD_OFF(oa->thread_router_lsa);
- THREAD_OFF(oa->thread_intra_prefix_lsa);
+ EVENT_OFF(oa->thread_router_lsa);
+ EVENT_OFF(oa->thread_intra_prefix_lsa);
}
diff --git a/ospf6d/ospf6_area.h b/ospf6d/ospf6_area.h
index 62b32d3762..d9afd65d81 100644
--- a/ospf6d/ospf6_area.h
+++ b/ospf6d/ospf6_area.h
@@ -60,8 +60,8 @@ struct ospf6_area {
uint32_t spf_calculation; /* SPF calculation count */
- struct thread *thread_router_lsa;
- struct thread *thread_intra_prefix_lsa;
+ struct event *thread_router_lsa;
+ struct event *thread_intra_prefix_lsa;
uint32_t router_lsa_size_limit;
/* Area announce list */
diff --git a/ospf6d/ospf6_asbr.c b/ospf6d/ospf6_asbr.c
index b2cdbc9b57..713dd82075 100644
--- a/ospf6d/ospf6_asbr.c
+++ b/ospf6d/ospf6_asbr.c
@@ -13,7 +13,7 @@
#include "routemap.h"
#include "table.h"
#include "plist.h"
-#include "thread.h"
+#include "frrevent.h"
#include "linklist.h"
#include "lib/northbound_cli.h"
@@ -180,13 +180,13 @@ struct ospf6_lsa *ospf6_as_external_lsa_originate(struct ospf6_route *route,
return lsa;
}
-void ospf6_orig_as_external_lsa(struct thread *thread)
+void ospf6_orig_as_external_lsa(struct event *thread)
{
struct ospf6_interface *oi;
struct ospf6_lsa *lsa;
uint32_t type, adv_router;
- oi = (struct ospf6_interface *)THREAD_ARG(thread);
+ oi = (struct ospf6_interface *)EVENT_ARG(thread);
if (oi->state == OSPF6_INTERFACE_DOWN)
return;
@@ -1065,9 +1065,9 @@ static void ospf6_asbr_routemap_unset(struct ospf6_redist *red)
ROUTEMAP(red) = NULL;
}
-static void ospf6_asbr_routemap_update_timer(struct thread *thread)
+static void ospf6_asbr_routemap_update_timer(struct event *thread)
{
- struct ospf6 *ospf6 = THREAD_ARG(thread);
+ struct ospf6 *ospf6 = EVENT_ARG(thread);
struct ospf6_redist *red;
int type;
@@ -1104,15 +1104,14 @@ void ospf6_asbr_distribute_list_update(struct ospf6 *ospf6,
{
SET_FLAG(red->flag, OSPF6_IS_RMAP_CHANGED);
- if (thread_is_scheduled(ospf6->t_distribute_update))
+ if (event_is_scheduled(ospf6->t_distribute_update))
return;
if (IS_OSPF6_DEBUG_ASBR)
zlog_debug("%s: trigger redistribute reset thread", __func__);
- thread_add_timer_msec(master, ospf6_asbr_routemap_update_timer, ospf6,
- OSPF_MIN_LS_INTERVAL,
- &ospf6->t_distribute_update);
+ event_add_timer_msec(master, ospf6_asbr_routemap_update_timer, ospf6,
+ OSPF_MIN_LS_INTERVAL, &ospf6->t_distribute_update);
}
void ospf6_asbr_routemap_update(const char *mapname)
@@ -3023,9 +3022,9 @@ static void ospf6_aggr_handle_external_info(void *data)
if (IS_OSPF6_DEBUG_AGGR)
zlog_debug("%s: LSA found, refresh it",
__func__);
- THREAD_OFF(lsa->refresh);
- thread_add_event(master, ospf6_lsa_refresh, lsa, 0,
- &lsa->refresh);
+ EVENT_OFF(lsa->refresh);
+ event_add_event(master, ospf6_lsa_refresh, lsa, 0,
+ &lsa->refresh);
return;
}
}
@@ -3133,11 +3132,9 @@ static void ospf6_handle_external_aggr_update(struct ospf6 *ospf6)
aggr->action = OSPF6_ROUTE_AGGR_NONE;
ospf6_asbr_summary_config_delete(ospf6, rn);
- if (OSPF6_EXTERNAL_RT_COUNT(aggr))
- hash_clean(aggr->match_extnl_hash,
- ospf6_aggr_handle_external_info);
+ hash_clean_and_free(&aggr->match_extnl_hash,
+ ospf6_aggr_handle_external_info);
- hash_free(aggr->match_extnl_hash);
XFREE(MTYPE_OSPF6_EXTERNAL_RT_AGGR, aggr);
} else if (aggr->action == OSPF6_ROUTE_AGGR_MODIFY) {
@@ -3175,18 +3172,14 @@ static void ospf6_aggr_unlink_external_info(void *data)
void ospf6_external_aggregator_free(struct ospf6_external_aggr_rt *aggr)
{
- if (OSPF6_EXTERNAL_RT_COUNT(aggr))
- hash_clean(aggr->match_extnl_hash,
- ospf6_aggr_unlink_external_info);
+ hash_clean_and_free(&aggr->match_extnl_hash,
+ ospf6_aggr_unlink_external_info);
if (IS_OSPF6_DEBUG_AGGR)
zlog_debug("%s: Release the aggregator Address(%pFX)",
__func__,
&aggr->p);
- hash_free(aggr->match_extnl_hash);
- aggr->match_extnl_hash = NULL;
-
XFREE(MTYPE_OSPF6_EXTERNAL_RT_AGGR, aggr);
}
@@ -3232,9 +3225,9 @@ static void ospf6_handle_exnl_rt_after_aggr_del(struct ospf6 *ospf6,
lsa = ospf6_find_external_lsa(ospf6, &rt->prefix);
if (lsa) {
- THREAD_OFF(lsa->refresh);
- thread_add_event(master, ospf6_lsa_refresh, lsa, 0,
- &lsa->refresh);
+ EVENT_OFF(lsa->refresh);
+ event_add_event(master, ospf6_lsa_refresh, lsa, 0,
+ &lsa->refresh);
} else {
if (IS_OSPF6_DEBUG_AGGR)
zlog_debug("%s: Originate external route(%pFX)",
@@ -3338,9 +3331,9 @@ ospf6_handle_external_aggr_add(struct ospf6 *ospf6)
}
}
-static void ospf6_asbr_summary_process(struct thread *thread)
+static void ospf6_asbr_summary_process(struct event *thread)
{
- struct ospf6 *ospf6 = THREAD_ARG(thread);
+ struct ospf6 *ospf6 = EVENT_ARG(thread);
int operation = 0;
operation = ospf6->aggr_action;
@@ -3370,7 +3363,7 @@ ospf6_start_asbr_summary_delay_timer(struct ospf6 *ospf6,
{
aggr->action = operation;
- if (thread_is_scheduled(ospf6->t_external_aggr)) {
+ if (event_is_scheduled(ospf6->t_external_aggr)) {
if (ospf6->aggr_action == OSPF6_ROUTE_AGGR_ADD) {
if (IS_OSPF6_DEBUG_AGGR)
@@ -3383,7 +3376,7 @@ ospf6_start_asbr_summary_delay_timer(struct ospf6 *ospf6,
if (IS_OSPF6_DEBUG_AGGR)
zlog_debug("%s, Restarting Aggregator delay timer.",
__func__);
- THREAD_OFF(ospf6->t_external_aggr);
+ EVENT_OFF(ospf6->t_external_aggr);
}
}
@@ -3392,10 +3385,8 @@ ospf6_start_asbr_summary_delay_timer(struct ospf6 *ospf6,
__func__, ospf6->aggr_delay_interval);
ospf6->aggr_action = operation;
- thread_add_timer(master,
- ospf6_asbr_summary_process,
- ospf6, ospf6->aggr_delay_interval,
- &ospf6->t_external_aggr);
+ event_add_timer(master, ospf6_asbr_summary_process, ospf6,
+ ospf6->aggr_delay_interval, &ospf6->t_external_aggr);
}
int ospf6_asbr_external_rt_advertise(struct ospf6 *ospf6,
diff --git a/ospf6d/ospf6_bfd.c b/ospf6d/ospf6_bfd.c
index 6cc9c3013b..6379f9d992 100644
--- a/ospf6d/ospf6_bfd.c
+++ b/ospf6d/ospf6_bfd.c
@@ -11,7 +11,7 @@
#include "linklist.h"
#include "memory.h"
#include "prefix.h"
-#include "thread.h"
+#include "frrevent.h"
#include "buffer.h"
#include "stream.h"
#include "zclient.h"
@@ -105,8 +105,8 @@ static void ospf6_bfd_callback(struct bfd_session_params *bsp,
if (bss->state == BFD_STATUS_DOWN
&& bss->previous_state == BFD_STATUS_UP) {
- THREAD_OFF(on->inactivity_timer);
- thread_add_event(master, inactivity_timer, on, 0, NULL);
+ EVENT_OFF(on->inactivity_timer);
+ event_add_event(master, inactivity_timer, on, 0, NULL);
}
}
diff --git a/ospf6d/ospf6_flood.c b/ospf6d/ospf6_flood.c
index 2d2069566c..a81d5222d6 100644
--- a/ospf6d/ospf6_flood.c
+++ b/ospf6d/ospf6_flood.c
@@ -6,7 +6,7 @@
#include <zebra.h>
#include "log.h"
-#include "thread.h"
+#include "frrevent.h"
#include "linklist.h"
#include "vty.h"
#include "command.h"
@@ -103,9 +103,9 @@ void ospf6_lsa_originate(struct ospf6 *ospf6, struct ospf6_lsa *lsa)
lsdb_self = ospf6_get_scoped_lsdb_self(lsa);
ospf6_lsdb_add(ospf6_lsa_copy(lsa), lsdb_self);
- THREAD_OFF(lsa->refresh);
- thread_add_timer(master, ospf6_lsa_refresh, lsa, OSPF_LS_REFRESH_TIME,
- &lsa->refresh);
+ EVENT_OFF(lsa->refresh);
+ event_add_timer(master, ospf6_lsa_refresh, lsa, OSPF_LS_REFRESH_TIME,
+ &lsa->refresh);
if (IS_OSPF6_DEBUG_LSA_TYPE(lsa->header->type)
|| IS_OSPF6_DEBUG_ORIGINATE_TYPE(lsa->header->type)) {
@@ -168,8 +168,8 @@ void ospf6_lsa_purge(struct ospf6_lsa *lsa)
self = ospf6_lsdb_lookup(lsa->header->type, lsa->header->id,
lsa->header->adv_router, lsdb_self);
if (self) {
- THREAD_OFF(self->expire);
- THREAD_OFF(self->refresh);
+ EVENT_OFF(self->expire);
+ EVENT_OFF(self->refresh);
ospf6_lsdb_remove(self, lsdb_self);
}
@@ -250,17 +250,17 @@ void ospf6_install_lsa(struct ospf6_lsa *lsa)
lsa->name);
lsa->external_lsa_id = old->external_lsa_id;
}
- THREAD_OFF(old->expire);
- THREAD_OFF(old->refresh);
+ EVENT_OFF(old->expire);
+ EVENT_OFF(old->refresh);
ospf6_flood_clear(old);
}
monotime(&now);
if (!OSPF6_LSA_IS_MAXAGE(lsa)) {
- thread_add_timer(master, ospf6_lsa_expire, lsa,
- OSPF_LSA_MAXAGE + lsa->birth.tv_sec
- - now.tv_sec,
- &lsa->expire);
+ event_add_timer(master, ospf6_lsa_expire, lsa,
+ OSPF_LSA_MAXAGE + lsa->birth.tv_sec -
+ now.tv_sec,
+ &lsa->expire);
} else
lsa->expire = NULL;
@@ -473,10 +473,10 @@ void ospf6_flood_interface(struct ospf6_neighbor *from, struct ospf6_lsa *lsa,
ospf6_lsdb_add(ospf6_lsa_copy(lsa),
on->retrans_list);
- thread_add_timer(
- master, ospf6_lsupdate_send_neighbor,
- on, on->ospf6_if->rxmt_interval,
- &on->thread_send_lsupdate);
+ event_add_timer(master,
+ ospf6_lsupdate_send_neighbor,
+ on, on->ospf6_if->rxmt_interval,
+ &on->thread_send_lsupdate);
retrans_added++;
}
}
@@ -520,14 +520,14 @@ void ospf6_flood_interface(struct ospf6_neighbor *from, struct ospf6_lsa *lsa,
if ((oi->type == OSPF_IFTYPE_BROADCAST)
|| (oi->type == OSPF_IFTYPE_POINTOPOINT)) {
ospf6_lsdb_add(ospf6_lsa_copy(lsa), oi->lsupdate_list);
- thread_add_event(master, ospf6_lsupdate_send_interface, oi, 0,
- &oi->thread_send_lsupdate);
+ event_add_event(master, ospf6_lsupdate_send_interface, oi, 0,
+ &oi->thread_send_lsupdate);
} else {
/* reschedule retransmissions to all neighbors */
for (ALL_LIST_ELEMENTS(oi->neighbor_list, node, nnode, on)) {
- THREAD_OFF(on->thread_send_lsupdate);
- thread_add_event(master, ospf6_lsupdate_send_neighbor,
- on, 0, &on->thread_send_lsupdate);
+ EVENT_OFF(on->thread_send_lsupdate);
+ event_add_event(master, ospf6_lsupdate_send_neighbor,
+ on, 0, &on->thread_send_lsupdate);
}
}
}
@@ -697,8 +697,8 @@ static void ospf6_acknowledge_lsa_bdrouter(struct ospf6_lsa *lsa,
"Delayed acknowledgement (BDR & MoreRecent & from DR)");
/* Delayed acknowledgement */
ospf6_lsdb_add(ospf6_lsa_copy(lsa), oi->lsack_list);
- thread_add_timer(master, ospf6_lsack_send_interface, oi,
- 3, &oi->thread_send_lsack);
+ event_add_timer(master, ospf6_lsack_send_interface, oi,
+ 3, &oi->thread_send_lsack);
} else {
if (is_debug)
zlog_debug(
@@ -718,8 +718,8 @@ static void ospf6_acknowledge_lsa_bdrouter(struct ospf6_lsa *lsa,
"Delayed acknowledgement (BDR & Duplicate & ImpliedAck & from DR)");
/* Delayed acknowledgement */
ospf6_lsdb_add(ospf6_lsa_copy(lsa), oi->lsack_list);
- thread_add_timer(master, ospf6_lsack_send_interface, oi,
- 3, &oi->thread_send_lsack);
+ event_add_timer(master, ospf6_lsack_send_interface, oi,
+ 3, &oi->thread_send_lsack);
} else {
if (is_debug)
zlog_debug(
@@ -736,8 +736,8 @@ static void ospf6_acknowledge_lsa_bdrouter(struct ospf6_lsa *lsa,
if (is_debug)
zlog_debug("Direct acknowledgement (BDR & Duplicate)");
ospf6_lsdb_add(ospf6_lsa_copy(lsa), from->lsack_list);
- thread_add_event(master, ospf6_lsack_send_neighbor, from, 0,
- &from->thread_send_lsack);
+ event_add_event(master, ospf6_lsack_send_neighbor, from, 0,
+ &from->thread_send_lsack);
return;
}
@@ -778,8 +778,8 @@ static void ospf6_acknowledge_lsa_allother(struct ospf6_lsa *lsa,
"Delayed acknowledgement (AllOther & MoreRecent)");
/* Delayed acknowledgement */
ospf6_lsdb_add(ospf6_lsa_copy(lsa), oi->lsack_list);
- thread_add_timer(master, ospf6_lsack_send_interface, oi, 3,
- &oi->thread_send_lsack);
+ event_add_timer(master, ospf6_lsack_send_interface, oi, 3,
+ &oi->thread_send_lsack);
return;
}
@@ -802,8 +802,8 @@ static void ospf6_acknowledge_lsa_allother(struct ospf6_lsa *lsa,
zlog_debug(
"Direct acknowledgement (AllOther & Duplicate)");
ospf6_lsdb_add(ospf6_lsa_copy(lsa), from->lsack_list);
- thread_add_event(master, ospf6_lsack_send_neighbor, from, 0,
- &from->thread_send_lsack);
+ event_add_event(master, ospf6_lsack_send_neighbor, from, 0,
+ &from->thread_send_lsack);
return;
}
@@ -921,7 +921,11 @@ void ospf6_receive_lsa(struct ospf6_neighbor *from,
/* (1) LSA Checksum */
if (!ospf6_lsa_checksum_valid(new->header)) {
if (is_debug)
- zlog_debug("Wrong LSA Checksum, discard");
+ zlog_debug(
+ "Wrong LSA Checksum %s (Router-ID: %pI4) [Type:%s Checksum:%#06hx), discard",
+ from->name, &from->router_id,
+ ospf6_lstype_name(new->header->type),
+ ntohs(new->header->checksum));
ospf6_lsa_delete(new);
return;
}
@@ -969,8 +973,8 @@ void ospf6_receive_lsa(struct ospf6_neighbor *from,
/* a) Acknowledge back to neighbor (Direct acknowledgement,
* 13.5) */
ospf6_lsdb_add(ospf6_lsa_copy(new), from->lsack_list);
- thread_add_event(master, ospf6_lsack_send_neighbor, from, 0,
- &from->thread_send_lsack);
+ event_add_event(master, ospf6_lsack_send_neighbor, from, 0,
+ &from->thread_send_lsack);
/* b) Discard */
ospf6_lsa_delete(new);
@@ -1101,13 +1105,16 @@ void ospf6_receive_lsa(struct ospf6_neighbor *from,
"Newer instance of the self-originated LSA");
zlog_debug("Schedule reorigination");
}
- thread_add_event(master, ospf6_lsa_refresh, new, 0,
- &new->refresh);
+ event_add_event(master, ospf6_lsa_refresh, new, 0,
+ &new->refresh);
}
+ /* GR: check for network topology change. */
struct ospf6 *ospf6 = from->ospf6_if->area->ospf6;
struct ospf6_area *area = from->ospf6_if->area;
- if (ospf6->gr_info.restart_in_progress)
+ if (ospf6->gr_info.restart_in_progress &&
+ (new->header->type == ntohs(OSPF6_LSTYPE_ROUTER) ||
+ new->header->type == ntohs(OSPF6_LSTYPE_NETWORK)))
ospf6_gr_check_lsdb_consistency(ospf6, area);
return;
@@ -1127,7 +1134,7 @@ void ospf6_receive_lsa(struct ospf6_neighbor *from,
new->name);
/* BadLSReq */
- thread_add_event(master, bad_lsreq, from, 0, NULL);
+ event_add_event(master, bad_lsreq, from, 0, NULL);
ospf6_lsa_delete(new);
return;
@@ -1224,8 +1231,8 @@ void ospf6_receive_lsa(struct ospf6_neighbor *from,
ospf6_lsdb_add(ospf6_lsa_copy(old),
from->lsupdate_list);
- thread_add_event(master, ospf6_lsupdate_send_neighbor,
- from, 0, &from->thread_send_lsupdate);
+ event_add_event(master, ospf6_lsupdate_send_neighbor,
+ from, 0, &from->thread_send_lsupdate);
ospf6_lsa_delete(new);
return;
diff --git a/ospf6d/ospf6_gr.c b/ospf6d/ospf6_gr.c
index c182e48f2e..976eb529d7 100644
--- a/ospf6d/ospf6_gr.c
+++ b/ospf6d/ospf6_gr.c
@@ -127,13 +127,14 @@ static void ospf6_gr_restart_exit(struct ospf6 *ospf6, const char *reason)
{
struct ospf6_area *area;
struct listnode *onode, *anode;
+ struct ospf6_route *route;
if (IS_DEBUG_OSPF6_GR)
zlog_debug("GR: exiting graceful restart: %s", reason);
ospf6->gr_info.restart_in_progress = false;
ospf6->gr_info.finishing_restart = true;
- THREAD_OFF(ospf6->gr_info.t_grace_period);
+ EVENT_OFF(ospf6->gr_info.t_grace_period);
/* Record in non-volatile memory that the restart is complete. */
ospf6_gr_nvm_delete(ospf6);
@@ -148,8 +149,16 @@ static void ospf6_gr_restart_exit(struct ospf6 *ospf6, const char *reason)
*/
OSPF6_ROUTER_LSA_EXECUTE(area);
+ /*
+ * Force reorigination of intra-area-prefix-LSAs to handle
+ * areas without any full adjacency.
+ */
+ OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB(area);
+
for (ALL_LIST_ELEMENTS_RO(area->if_list, anode, oi)) {
- OSPF6_LINK_LSA_EXECUTE(oi);
+ /* Reoriginate Link-LSA. */
+ if (oi->type != OSPF_IFTYPE_VIRTUALLINK)
+ OSPF6_LINK_LSA_EXECUTE(oi);
/*
* 2) The router should reoriginate network-LSAs on all
@@ -161,6 +170,16 @@ static void ospf6_gr_restart_exit(struct ospf6 *ospf6, const char *reason)
}
/*
+ * While all self-originated NSSA and AS-external LSAs were already
+ * learned from the helping neighbors, we need to reoriginate them in
+ * order to ensure they will be refreshed periodically.
+ */
+ for (route = ospf6_route_head(ospf6->external_table); route;
+ route = ospf6_route_next(route))
+ ospf6_handle_external_lsa_origination(ospf6, route,
+ &route->prefix);
+
+ /*
* 3) The router reruns its OSPF routing calculations, this time
* installing the results into the system forwarding table, and
* originating summary-LSAs, Type-7 LSAs and AS-external-LSAs as
@@ -440,9 +459,9 @@ static bool ospf6_gr_check_adjs(struct ospf6 *ospf6)
}
/* Handling of grace period expiry. */
-static void ospf6_gr_grace_period_expired(struct thread *thread)
+static void ospf6_gr_grace_period_expired(struct event *thread)
{
- struct ospf6 *ospf6 = THREAD_ARG(thread);
+ struct ospf6 *ospf6 = EVENT_ARG(thread);
ospf6_gr_restart_exit(ospf6, "grace period has expired");
}
@@ -573,9 +592,9 @@ void ospf6_gr_nvm_read(struct ospf6 *ospf6)
zlog_debug(
"GR: remaining time until grace period expires: %lu(s)",
remaining_time);
- thread_add_timer(master, ospf6_gr_grace_period_expired,
- ospf6, remaining_time,
- &ospf6->gr_info.t_grace_period);
+ event_add_timer(master, ospf6_gr_grace_period_expired,
+ ospf6, remaining_time,
+ &ospf6->gr_info.t_grace_period);
}
}
diff --git a/ospf6d/ospf6_gr_helper.c b/ospf6d/ospf6_gr_helper.c
index 65ce078fcb..d313510cfa 100644
--- a/ospf6d/ospf6_gr_helper.c
+++ b/ospf6d/ospf6_gr_helper.c
@@ -110,10 +110,8 @@ static void ospf6_enable_rtr_hash_destroy(struct ospf6 *ospf6)
if (ospf6->ospf6_helper_cfg.enable_rtr_list == NULL)
return;
- hash_clean(ospf6->ospf6_helper_cfg.enable_rtr_list,
- ospf6_disable_rtr_hash_free);
- hash_free(ospf6->ospf6_helper_cfg.enable_rtr_list);
- ospf6->ospf6_helper_cfg.enable_rtr_list = NULL;
+ hash_clean_and_free(&ospf6->ospf6_helper_cfg.enable_rtr_list,
+ ospf6_disable_rtr_hash_free);
}
/*
@@ -197,9 +195,9 @@ static int ospf6_extract_grace_lsa_fields(struct ospf6_lsa *lsa,
* Returns:
* Nothing
*/
-static void ospf6_handle_grace_timer_expiry(struct thread *thread)
+static void ospf6_handle_grace_timer_expiry(struct event *thread)
{
- struct ospf6_neighbor *nbr = THREAD_ARG(thread);
+ struct ospf6_neighbor *nbr = EVENT_ARG(thread);
ospf6_gr_helper_exit(nbr, OSPF6_GR_HELPER_GRACE_TIMEOUT);
}
@@ -280,8 +278,9 @@ int ospf6_process_grace_lsa(struct ospf6 *ospf6, struct ospf6_lsa *lsa,
if (IS_DEBUG_OSPF6_GR)
zlog_debug(
- "%s, Grace LSA received from %pI4, grace interval:%u, restart reason :%s",
- __func__, &restarter->router_id, grace_interval,
+ "%s, Grace LSA received from %s(%pI4), grace interval:%u, restart reason:%s",
+ __func__, restarter->name, &restarter->router_id,
+ grace_interval,
ospf6_restart_reason_desc[restart_reason]);
/* Verify Helper enabled globally */
@@ -383,7 +382,7 @@ int ospf6_process_grace_lsa(struct ospf6 *ospf6, struct ospf6_lsa *lsa,
}
if (OSPF6_GR_IS_ACTIVE_HELPER(restarter)) {
- THREAD_OFF(restarter->gr_helper_info.t_grace_timer);
+ EVENT_OFF(restarter->gr_helper_info.t_grace_timer);
if (ospf6->ospf6_helper_cfg.active_restarter_cnt > 0)
ospf6->ospf6_helper_cfg.active_restarter_cnt--;
@@ -416,9 +415,9 @@ int ospf6_process_grace_lsa(struct ospf6 *ospf6, struct ospf6_lsa *lsa,
actual_grace_interval);
/* Start the grace timer */
- thread_add_timer(master, ospf6_handle_grace_timer_expiry, restarter,
- actual_grace_interval,
- &restarter->gr_helper_info.t_grace_timer);
+ event_add_timer(master, ospf6_handle_grace_timer_expiry, restarter,
+ actual_grace_interval,
+ &restarter->gr_helper_info.t_grace_timer);
return OSPF6_GR_ACTIVE_HELPER;
}
@@ -471,7 +470,7 @@ void ospf6_gr_helper_exit(struct ospf6_neighbor *nbr,
* expiry, stop the grace timer.
*/
if (reason != OSPF6_GR_HELPER_GRACE_TIMEOUT)
- THREAD_OFF(nbr->gr_helper_info.t_grace_timer);
+ EVENT_OFF(nbr->gr_helper_info.t_grace_timer);
if (ospf6->ospf6_helper_cfg.active_restarter_cnt <= 0) {
zlog_err(
@@ -834,7 +833,7 @@ static void show_ospfv6_gr_helper_per_nbr(struct vty *vty, json_object *json,
vty_out(vty, " Actual Grace period : %d(in seconds)\n",
nbr->gr_helper_info.actual_grace_period);
vty_out(vty, " Remaining GraceTime:%ld(in seconds).\n",
- thread_timer_remain_second(
+ event_timer_remain_second(
nbr->gr_helper_info.t_grace_timer));
vty_out(vty, " Graceful Restart reason: %s.\n\n",
ospf6_restart_reason_desc[nbr->gr_helper_info
@@ -851,8 +850,8 @@ static void show_ospfv6_gr_helper_per_nbr(struct vty *vty, json_object *json,
json_object_int_add(json_neigh, "actualGraceInterval",
nbr->gr_helper_info.actual_grace_period);
json_object_int_add(json_neigh, "remainGracetime",
- thread_timer_remain_second(
- nbr->gr_helper_info.t_grace_timer));
+ event_timer_remain_second(
+ nbr->gr_helper_info.t_grace_timer));
json_object_string_add(json_neigh, "restartReason",
ospf6_restart_reason_desc[
nbr->gr_helper_info.gr_restart_reason]);
diff --git a/ospf6d/ospf6_interface.c b/ospf6d/ospf6_interface.c
index 7a22fdf064..e7148d66ba 100644
--- a/ospf6d/ospf6_interface.c
+++ b/ospf6d/ospf6_interface.c
@@ -9,7 +9,7 @@
#include "if.h"
#include "log.h"
#include "command.h"
-#include "thread.h"
+#include "frrevent.h"
#include "prefix.h"
#include "plist.h"
#include "zclient.h"
@@ -260,11 +260,11 @@ void ospf6_interface_delete(struct ospf6_interface *oi)
list_delete(&oi->neighbor_list);
- THREAD_OFF(oi->thread_send_hello);
- THREAD_OFF(oi->thread_send_lsupdate);
- THREAD_OFF(oi->thread_send_lsack);
- THREAD_OFF(oi->thread_sso);
- THREAD_OFF(oi->thread_wait_timer);
+ EVENT_OFF(oi->thread_send_hello);
+ EVENT_OFF(oi->thread_send_lsupdate);
+ EVENT_OFF(oi->thread_send_lsack);
+ EVENT_OFF(oi->thread_sso);
+ EVENT_OFF(oi->thread_wait_timer);
ospf6_lsdb_remove_all(oi->lsdb);
ospf6_lsdb_remove_all(oi->lsupdate_list);
@@ -307,23 +307,23 @@ void ospf6_interface_disable(struct ospf6_interface *oi)
{
SET_FLAG(oi->flag, OSPF6_INTERFACE_DISABLE);
- thread_execute(master, interface_down, oi, 0);
+ event_execute(master, interface_down, oi, 0);
ospf6_lsdb_remove_all(oi->lsdb);
ospf6_lsdb_remove_all(oi->lsdb_self);
ospf6_lsdb_remove_all(oi->lsupdate_list);
ospf6_lsdb_remove_all(oi->lsack_list);
- THREAD_OFF(oi->thread_send_hello);
- THREAD_OFF(oi->thread_send_lsupdate);
- THREAD_OFF(oi->thread_send_lsack);
- THREAD_OFF(oi->thread_sso);
+ EVENT_OFF(oi->thread_send_hello);
+ EVENT_OFF(oi->thread_send_lsupdate);
+ EVENT_OFF(oi->thread_send_lsack);
+ EVENT_OFF(oi->thread_sso);
- THREAD_OFF(oi->thread_network_lsa);
- THREAD_OFF(oi->thread_link_lsa);
- THREAD_OFF(oi->thread_intra_prefix_lsa);
- THREAD_OFF(oi->thread_as_extern_lsa);
- THREAD_OFF(oi->thread_wait_timer);
+ EVENT_OFF(oi->thread_network_lsa);
+ EVENT_OFF(oi->thread_link_lsa);
+ EVENT_OFF(oi->thread_intra_prefix_lsa);
+ EVENT_OFF(oi->thread_as_extern_lsa);
+ EVENT_OFF(oi->thread_wait_timer);
}
static struct in6_addr *
@@ -382,9 +382,9 @@ void ospf6_interface_state_update(struct interface *ifp)
if (if_is_operative(ifp)
&& (ospf6_interface_get_linklocal_address(oi->interface)
|| if_is_loopback(oi->interface)))
- thread_execute(master, interface_up, oi, 0);
+ event_execute(master, interface_up, oi, 0);
else
- thread_execute(master, interface_down, oi, 0);
+ event_execute(master, interface_down, oi, 0);
return;
}
@@ -592,6 +592,7 @@ static struct ospf6_neighbor *better_drouter(struct ospf6_neighbor *a,
uint8_t dr_election(struct ospf6_interface *oi)
{
+ struct ospf6 *ospf6 = oi->area->ospf6;
struct listnode *node, *nnode;
struct ospf6_neighbor *on, *drouter, *bdrouter, myself;
struct ospf6_neighbor *best_drouter, *best_bdrouter;
@@ -602,13 +603,12 @@ uint8_t dr_election(struct ospf6_interface *oi)
/* pseudo neighbor myself, including noting current DR/BDR (1) */
memset(&myself, 0, sizeof(myself));
- inet_ntop(AF_INET, &oi->area->ospf6->router_id, myself.name,
- sizeof(myself.name));
+ inet_ntop(AF_INET, &ospf6->router_id, myself.name, sizeof(myself.name));
myself.state = OSPF6_NEIGHBOR_TWOWAY;
myself.drouter = oi->drouter;
myself.bdrouter = oi->bdrouter;
myself.priority = oi->priority;
- myself.router_id = oi->area->ospf6->router_id;
+ myself.router_id = ospf6->router_id;
/* Electing BDR (2) */
for (ALL_LIST_ELEMENTS(oi->neighbor_list, node, nnode, on))
@@ -657,8 +657,10 @@ uint8_t dr_election(struct ospf6_interface *oi)
/* If DR or BDR change, invoke AdjOK? for each neighbor (7) */
/* RFC 2328 section 12.4. Originating LSAs (3) will be handled
accordingly after AdjOK */
- if (oi->drouter != (drouter ? drouter->router_id : htonl(0))
- || oi->bdrouter != (bdrouter ? bdrouter->router_id : htonl(0))) {
+
+ if (oi->drouter != (drouter ? drouter->router_id : htonl(0)) ||
+ oi->bdrouter != (bdrouter ? bdrouter->router_id : htonl(0)) ||
+ ospf6->gr_info.restart_in_progress) {
if (IS_OSPF6_DEBUG_INTERFACE)
zlog_debug("DR Election on %s: DR: %s BDR: %s",
oi->interface->name,
@@ -669,8 +671,8 @@ uint8_t dr_election(struct ospf6_interface *oi)
if (on->state < OSPF6_NEIGHBOR_TWOWAY)
continue;
/* Schedule AdjOK. */
- thread_add_event(master, adj_ok, on, 0,
- &on->thread_adj_ok);
+ event_add_event(master, adj_ok, on, 0,
+ &on->thread_adj_ok);
}
}
@@ -718,18 +720,18 @@ static bool ifmaddr_check(ifindex_t ifindex, struct in6_addr *addr)
#endif /* __FreeBSD__ */
/* Interface State Machine */
-void interface_up(struct thread *thread)
+void interface_up(struct event *thread)
{
struct ospf6_interface *oi;
struct ospf6 *ospf6;
- oi = (struct ospf6_interface *)THREAD_ARG(thread);
+ oi = (struct ospf6_interface *)EVENT_ARG(thread);
assert(oi && oi->interface);
if (!oi->type_cfg)
oi->type = ospf6_default_iftype(oi->interface);
- thread_cancel(&oi->thread_sso);
+ event_cancel(&oi->thread_sso);
if (IS_OSPF6_DEBUG_INTERFACE)
zlog_debug("Interface Event %s: [InterfaceUp]",
@@ -783,9 +785,8 @@ void interface_up(struct thread *thread)
zlog_info(
"Interface %s is still in all routers group, rescheduling for SSO",
oi->interface->name);
- thread_add_timer(master, interface_up, oi,
- OSPF6_INTERFACE_SSO_RETRY_INT,
- &oi->thread_sso);
+ event_add_timer(master, interface_up, oi,
+ OSPF6_INTERFACE_SSO_RETRY_INT, &oi->thread_sso);
return;
}
#endif /* __FreeBSD__ */
@@ -800,9 +801,9 @@ void interface_up(struct thread *thread)
zlog_info(
"Scheduling %s for sso retry, trial count: %d",
oi->interface->name, oi->sso_try_cnt);
- thread_add_timer(master, interface_up, oi,
- OSPF6_INTERFACE_SSO_RETRY_INT,
- &oi->thread_sso);
+ event_add_timer(master, interface_up, oi,
+ OSPF6_INTERFACE_SSO_RETRY_INT,
+ &oi->thread_sso);
}
return;
}
@@ -814,8 +815,8 @@ void interface_up(struct thread *thread)
/* Schedule Hello */
if (!CHECK_FLAG(oi->flag, OSPF6_INTERFACE_PASSIVE)
&& !if_is_loopback(oi->interface)) {
- thread_add_timer(master, ospf6_hello_send, oi, 0,
- &oi->thread_send_hello);
+ event_add_timer(master, ospf6_hello_send, oi, 0,
+ &oi->thread_send_hello);
}
/* decide next interface state */
@@ -827,16 +828,16 @@ void interface_up(struct thread *thread)
ospf6_interface_state_change(OSPF6_INTERFACE_DROTHER, oi);
else {
ospf6_interface_state_change(OSPF6_INTERFACE_WAITING, oi);
- thread_add_timer(master, wait_timer, oi, oi->dead_interval,
- &oi->thread_wait_timer);
+ event_add_timer(master, wait_timer, oi, oi->dead_interval,
+ &oi->thread_wait_timer);
}
}
-void wait_timer(struct thread *thread)
+void wait_timer(struct event *thread)
{
struct ospf6_interface *oi;
- oi = (struct ospf6_interface *)THREAD_ARG(thread);
+ oi = (struct ospf6_interface *)EVENT_ARG(thread);
assert(oi && oi->interface);
if (IS_OSPF6_DEBUG_INTERFACE)
@@ -847,11 +848,11 @@ void wait_timer(struct thread *thread)
ospf6_interface_state_change(dr_election(oi), oi);
}
-void backup_seen(struct thread *thread)
+void backup_seen(struct event *thread)
{
struct ospf6_interface *oi;
- oi = (struct ospf6_interface *)THREAD_ARG(thread);
+ oi = (struct ospf6_interface *)EVENT_ARG(thread);
assert(oi && oi->interface);
if (IS_OSPF6_DEBUG_INTERFACE)
@@ -862,11 +863,11 @@ void backup_seen(struct thread *thread)
ospf6_interface_state_change(dr_election(oi), oi);
}
-void neighbor_change(struct thread *thread)
+void neighbor_change(struct event *thread)
{
struct ospf6_interface *oi;
- oi = (struct ospf6_interface *)THREAD_ARG(thread);
+ oi = (struct ospf6_interface *)EVENT_ARG(thread);
assert(oi && oi->interface);
if (IS_OSPF6_DEBUG_INTERFACE)
@@ -879,14 +880,14 @@ void neighbor_change(struct thread *thread)
ospf6_interface_state_change(dr_election(oi), oi);
}
-void interface_down(struct thread *thread)
+void interface_down(struct event *thread)
{
struct ospf6_interface *oi;
struct listnode *node, *nnode;
struct ospf6_neighbor *on;
struct ospf6 *ospf6;
- oi = (struct ospf6_interface *)THREAD_ARG(thread);
+ oi = (struct ospf6_interface *)EVENT_ARG(thread);
assert(oi && oi->interface);
if (IS_OSPF6_DEBUG_INTERFACE)
@@ -894,10 +895,10 @@ void interface_down(struct thread *thread)
oi->interface->name);
/* Stop Hellos */
- THREAD_OFF(oi->thread_send_hello);
+ EVENT_OFF(oi->thread_send_hello);
/* Stop trying to set socket options. */
- THREAD_OFF(oi->thread_sso);
+ EVENT_OFF(oi->thread_sso);
/* Cease the HELPER role for all the neighbours
* of this interface.
@@ -934,7 +935,7 @@ void interface_down(struct thread *thread)
if (oi->on_write_q) {
listnode_delete(ospf6->oi_write_q, oi);
if (list_isempty(ospf6->oi_write_q))
- thread_cancel(&ospf6->t_write);
+ event_cancel(&ospf6->t_write);
oi->on_write_q = 0;
}
@@ -1139,7 +1140,7 @@ static int ospf6_interface_show(struct vty *vty, struct interface *ifp,
if (use_json) {
timerclear(&res);
- if (thread_is_scheduled(oi->thread_send_lsupdate))
+ if (event_is_scheduled(oi->thread_send_lsupdate))
timersub(&oi->thread_send_lsupdate->u.sands, &now,
&res);
timerstring(&res, duration, sizeof(duration));
@@ -1149,9 +1150,8 @@ static int ospf6_interface_show(struct vty *vty, struct interface *ifp,
duration);
json_object_string_add(
json_obj, "lsUpdateSendThread",
- (thread_is_scheduled(oi->thread_send_lsupdate)
- ? "on"
- : "off"));
+ (event_is_scheduled(oi->thread_send_lsupdate) ? "on"
+ : "off"));
json_arr = json_object_new_array();
for (ALL_LSDB(oi->lsupdate_list, lsa, lsanext))
@@ -1161,7 +1161,7 @@ static int ospf6_interface_show(struct vty *vty, struct interface *ifp,
json_arr);
timerclear(&res);
- if (thread_is_scheduled(oi->thread_send_lsack))
+ if (event_is_scheduled(oi->thread_send_lsack))
timersub(&oi->thread_send_lsack->u.sands, &now, &res);
timerstring(&res, duration, sizeof(duration));
@@ -1171,8 +1171,8 @@ static int ospf6_interface_show(struct vty *vty, struct interface *ifp,
duration);
json_object_string_add(
json_obj, "lsAckSendThread",
- (thread_is_scheduled(oi->thread_send_lsack) ? "on"
- : "off"));
+ (event_is_scheduled(oi->thread_send_lsack) ? "on"
+ : "off"));
json_arr = json_object_new_array();
for (ALL_LSDB(oi->lsack_list, lsa, lsanext))
@@ -1182,28 +1182,27 @@ static int ospf6_interface_show(struct vty *vty, struct interface *ifp,
} else {
timerclear(&res);
- if (thread_is_scheduled(oi->thread_send_lsupdate))
+ if (event_is_scheduled(oi->thread_send_lsupdate))
timersub(&oi->thread_send_lsupdate->u.sands, &now,
&res);
timerstring(&res, duration, sizeof(duration));
vty_out(vty,
" %d Pending LSAs for LSUpdate in Time %s [thread %s]\n",
oi->lsupdate_list->count, duration,
- (thread_is_scheduled(oi->thread_send_lsupdate)
- ? "on"
- : "off"));
+ (event_is_scheduled(oi->thread_send_lsupdate) ? "on"
+ : "off"));
for (ALL_LSDB(oi->lsupdate_list, lsa, lsanext))
vty_out(vty, " %s\n", lsa->name);
timerclear(&res);
- if (thread_is_scheduled(oi->thread_send_lsack))
+ if (event_is_scheduled(oi->thread_send_lsack))
timersub(&oi->thread_send_lsack->u.sands, &now, &res);
timerstring(&res, duration, sizeof(duration));
vty_out(vty,
" %d Pending LSAs for LSAck in Time %s [thread %s]\n",
oi->lsack_list->count, duration,
- (thread_is_scheduled(oi->thread_send_lsack) ? "on"
- : "off"));
+ (event_is_scheduled(oi->thread_send_lsack) ? "on"
+ : "off"));
for (ALL_LSDB(oi->lsack_list, lsa, lsanext))
vty_out(vty, " %s\n", lsa->name);
}
@@ -1877,8 +1876,8 @@ DEFUN (ipv6_ospf6_ifmtu,
/* re-establish adjacencies */
for (ALL_LIST_ELEMENTS(oi->neighbor_list, node, nnode, on)) {
- THREAD_OFF(on->inactivity_timer);
- thread_add_event(master, inactivity_timer, on, 0, NULL);
+ EVENT_OFF(on->inactivity_timer);
+ event_add_event(master, inactivity_timer, on, 0, NULL);
}
return CMD_SUCCESS;
@@ -1923,8 +1922,8 @@ DEFUN (no_ipv6_ospf6_ifmtu,
/* re-establish adjacencies */
for (ALL_LIST_ELEMENTS(oi->neighbor_list, node, nnode, on)) {
- THREAD_OFF(on->inactivity_timer);
- thread_add_event(master, inactivity_timer, on, 0, NULL);
+ EVENT_OFF(on->inactivity_timer);
+ event_add_event(master, inactivity_timer, on, 0, NULL);
}
return CMD_SUCCESS;
@@ -2106,11 +2105,11 @@ DEFUN (ipv6_ospf6_hellointerval,
/*
* If the thread is scheduled, send the new hello now.
*/
- if (thread_is_scheduled(oi->thread_send_hello)) {
- THREAD_OFF(oi->thread_send_hello);
+ if (event_is_scheduled(oi->thread_send_hello)) {
+ EVENT_OFF(oi->thread_send_hello);
- thread_add_timer(master, ospf6_hello_send, oi, 0,
- &oi->thread_send_hello);
+ event_add_timer(master, ospf6_hello_send, oi, 0,
+ &oi->thread_send_hello);
}
return CMD_SUCCESS;
}
@@ -2323,12 +2322,12 @@ DEFUN (ipv6_ospf6_passive,
assert(oi);
SET_FLAG(oi->flag, OSPF6_INTERFACE_PASSIVE);
- THREAD_OFF(oi->thread_send_hello);
- THREAD_OFF(oi->thread_sso);
+ EVENT_OFF(oi->thread_send_hello);
+ EVENT_OFF(oi->thread_sso);
for (ALL_LIST_ELEMENTS(oi->neighbor_list, node, nnode, on)) {
- THREAD_OFF(on->inactivity_timer);
- thread_add_event(master, inactivity_timer, on, 0, NULL);
+ EVENT_OFF(on->inactivity_timer);
+ event_add_event(master, inactivity_timer, on, 0, NULL);
}
return CMD_SUCCESS;
@@ -2353,13 +2352,13 @@ DEFUN (no_ipv6_ospf6_passive,
assert(oi);
UNSET_FLAG(oi->flag, OSPF6_INTERFACE_PASSIVE);
- THREAD_OFF(oi->thread_send_hello);
- THREAD_OFF(oi->thread_sso);
+ EVENT_OFF(oi->thread_send_hello);
+ EVENT_OFF(oi->thread_sso);
/* don't send hellos over loopback interface */
if (!if_is_loopback(oi->interface))
- thread_add_timer(master, ospf6_hello_send, oi, 0,
- &oi->thread_send_hello);
+ event_add_timer(master, ospf6_hello_send, oi, 0,
+ &oi->thread_send_hello);
return CMD_SUCCESS;
}
@@ -2519,8 +2518,8 @@ DEFUN (ipv6_ospf6_network,
}
/* Reset the interface */
- thread_execute(master, interface_down, oi, 0);
- thread_execute(master, interface_up, oi, 0);
+ event_execute(master, interface_down, oi, 0);
+ event_execute(master, interface_up, oi, 0);
return CMD_SUCCESS;
}
@@ -2555,8 +2554,8 @@ DEFUN (no_ipv6_ospf6_network,
oi->type = type;
/* Reset the interface */
- thread_execute(master, interface_down, oi, 0);
- thread_execute(master, interface_up, oi, 0);
+ event_execute(master, interface_down, oi, 0);
+ event_execute(master, interface_up, oi, 0);
return CMD_SUCCESS;
}
@@ -2772,8 +2771,8 @@ void ospf6_interface_clear(struct interface *ifp)
zlog_debug("Interface %s: clear by reset", ifp->name);
/* Reset the interface */
- thread_execute(master, interface_down, oi, 0);
- thread_execute(master, interface_up, oi, 0);
+ event_execute(master, interface_down, oi, 0);
+ event_execute(master, interface_up, oi, 0);
}
/* Clear interface */
diff --git a/ospf6d/ospf6_interface.h b/ospf6d/ospf6_interface.h
index e04842a7c8..ae0744b25d 100644
--- a/ospf6d/ospf6_interface.h
+++ b/ospf6d/ospf6_interface.h
@@ -90,7 +90,7 @@ struct ospf6_interface {
/* Interface socket setting trial counter, resets on success */
uint8_t sso_try_cnt;
- struct thread *thread_sso;
+ struct event *thread_sso;
/* OSPF6 Interface flag */
char flag;
@@ -115,15 +115,15 @@ struct ospf6_interface {
struct ospf6_lsdb *lsack_list;
/* Ongoing Tasks */
- struct thread *thread_send_hello;
- struct thread *thread_send_lsupdate;
- struct thread *thread_send_lsack;
+ struct event *thread_send_hello;
+ struct event *thread_send_lsupdate;
+ struct event *thread_send_lsack;
- struct thread *thread_network_lsa;
- struct thread *thread_link_lsa;
- struct thread *thread_intra_prefix_lsa;
- struct thread *thread_as_extern_lsa;
- struct thread *thread_wait_timer;
+ struct event *thread_network_lsa;
+ struct event *thread_link_lsa;
+ struct event *thread_intra_prefix_lsa;
+ struct event *thread_as_extern_lsa;
+ struct event *thread_wait_timer;
struct ospf6_route_table *route_connected;
@@ -211,11 +211,11 @@ extern struct in6_addr *
ospf6_interface_get_global_address(struct interface *ifp);
/* interface event */
-extern void interface_up(struct thread *thread);
-extern void interface_down(struct thread *thread);
-extern void wait_timer(struct thread *thread);
-extern void backup_seen(struct thread *thread);
-extern void neighbor_change(struct thread *thread);
+extern void interface_up(struct event *thread);
+extern void interface_down(struct event *thread);
+extern void wait_timer(struct event *thread);
+extern void backup_seen(struct event *thread);
+extern void neighbor_change(struct event *thread);
extern void ospf6_interface_init(void);
extern void ospf6_interface_clear(struct interface *ifp);
diff --git a/ospf6d/ospf6_intra.c b/ospf6d/ospf6_intra.c
index e7ce2f5f72..301fccecd7 100644
--- a/ospf6d/ospf6_intra.c
+++ b/ospf6d/ospf6_intra.c
@@ -7,7 +7,7 @@
#include "log.h"
#include "linklist.h"
-#include "thread.h"
+#include "frrevent.h"
#include "memory.h"
#include "if.h"
#include "prefix.h"
@@ -209,7 +209,7 @@ int ospf6_router_is_stub_router(struct ospf6_lsa *lsa)
return OSPF6_NOT_STUB_ROUTER;
}
-void ospf6_router_lsa_originate(struct thread *thread)
+void ospf6_router_lsa_originate(struct event *thread)
{
struct ospf6_area *oa;
@@ -228,7 +228,7 @@ void ospf6_router_lsa_originate(struct thread *thread)
uint32_t router;
int count;
- oa = (struct ospf6_area *)THREAD_ARG(thread);
+ oa = (struct ospf6_area *)EVENT_ARG(thread);
if (oa->ospf6->gr_info.restart_in_progress) {
if (IS_DEBUG_OSPF6_GR)
@@ -494,7 +494,7 @@ static int ospf6_network_lsa_show(struct vty *vty, struct ospf6_lsa *lsa,
return 0;
}
-void ospf6_network_lsa_originate(struct thread *thread)
+void ospf6_network_lsa_originate(struct event *thread)
{
struct ospf6_interface *oi;
@@ -510,7 +510,7 @@ void ospf6_network_lsa_originate(struct thread *thread)
struct listnode *i;
uint16_t type;
- oi = (struct ospf6_interface *)THREAD_ARG(thread);
+ oi = (struct ospf6_interface *)EVENT_ARG(thread);
/* The interface must be enabled until here. A Network-LSA of a
disabled interface (but was once enabled) should be flushed
@@ -746,7 +746,7 @@ static int ospf6_link_lsa_show(struct vty *vty, struct ospf6_lsa *lsa,
return 0;
}
-void ospf6_link_lsa_originate(struct thread *thread)
+void ospf6_link_lsa_originate(struct event *thread)
{
struct ospf6_interface *oi;
@@ -758,7 +758,7 @@ void ospf6_link_lsa_originate(struct thread *thread)
struct ospf6_route *route;
struct ospf6_prefix *op;
- oi = (struct ospf6_interface *)THREAD_ARG(thread);
+ oi = (struct ospf6_interface *)EVENT_ARG(thread);
assert(oi->area);
@@ -982,7 +982,7 @@ static int ospf6_intra_prefix_lsa_show(struct vty *vty, struct ospf6_lsa *lsa,
return 0;
}
-void ospf6_intra_prefix_lsa_originate_stub(struct thread *thread)
+void ospf6_intra_prefix_lsa_originate_stub(struct event *thread)
{
struct ospf6_area *oa;
@@ -1001,7 +1001,7 @@ void ospf6_intra_prefix_lsa_originate_stub(struct thread *thread)
struct ospf6_route_table *route_advertise;
int ls_id = 0;
- oa = (struct ospf6_area *)THREAD_ARG(thread);
+ oa = (struct ospf6_area *)EVENT_ARG(thread);
if (oa->ospf6->gr_info.restart_in_progress) {
if (IS_DEBUG_OSPF6_GR)
@@ -1217,7 +1217,7 @@ void ospf6_intra_prefix_lsa_originate_stub(struct thread *thread)
}
-void ospf6_intra_prefix_lsa_originate_transit(struct thread *thread)
+void ospf6_intra_prefix_lsa_originate_transit(struct event *thread)
{
struct ospf6_interface *oi;
@@ -1237,7 +1237,7 @@ void ospf6_intra_prefix_lsa_originate_transit(struct thread *thread)
char *start, *end, *current;
uint16_t type;
- oi = (struct ospf6_interface *)THREAD_ARG(thread);
+ oi = (struct ospf6_interface *)EVENT_ARG(thread);
assert(oi->area);
diff --git a/ospf6d/ospf6_intra.h b/ospf6d/ospf6_intra.h
index 79b5eb0ed9..0f286f0ab1 100644
--- a/ospf6d/ospf6_intra.h
+++ b/ospf6d/ospf6_intra.h
@@ -139,32 +139,32 @@ struct ospf6_intra_prefix_lsa {
#define OSPF6_ROUTER_LSA_SCHEDULE(oa) \
do { \
if (CHECK_FLAG((oa)->flag, OSPF6_AREA_ENABLE)) \
- thread_add_event(master, ospf6_router_lsa_originate, \
- oa, 0, &(oa)->thread_router_lsa); \
+ event_add_event(master, ospf6_router_lsa_originate, \
+ oa, 0, &(oa)->thread_router_lsa); \
} while (0)
#define OSPF6_NETWORK_LSA_SCHEDULE(oi) \
do { \
if (!CHECK_FLAG((oi)->flag, OSPF6_INTERFACE_DISABLE)) \
- thread_add_event(master, ospf6_network_lsa_originate, \
- oi, 0, &(oi)->thread_network_lsa); \
+ event_add_event(master, ospf6_network_lsa_originate, \
+ oi, 0, &(oi)->thread_network_lsa); \
} while (0)
#define OSPF6_LINK_LSA_SCHEDULE(oi) \
do { \
if (!CHECK_FLAG((oi)->flag, OSPF6_INTERFACE_DISABLE)) \
- thread_add_event(master, ospf6_link_lsa_originate, oi, \
- 0, &(oi)->thread_link_lsa); \
+ event_add_event(master, ospf6_link_lsa_originate, oi, \
+ 0, &(oi)->thread_link_lsa); \
} while (0)
#define OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB(oa) \
do { \
if (CHECK_FLAG((oa)->flag, OSPF6_AREA_ENABLE)) \
- thread_add_event( \
+ event_add_event( \
master, ospf6_intra_prefix_lsa_originate_stub, \
oa, 0, &(oa)->thread_intra_prefix_lsa); \
} while (0)
#define OSPF6_INTRA_PREFIX_LSA_SCHEDULE_TRANSIT(oi) \
do { \
if (!CHECK_FLAG((oi)->flag, OSPF6_INTERFACE_DISABLE)) \
- thread_add_event( \
+ event_add_event( \
master, \
ospf6_intra_prefix_lsa_originate_transit, oi, \
0, &(oi)->thread_intra_prefix_lsa); \
@@ -173,42 +173,42 @@ struct ospf6_intra_prefix_lsa {
#define OSPF6_AS_EXTERN_LSA_SCHEDULE(oi) \
do { \
if (!CHECK_FLAG((oi)->flag, OSPF6_INTERFACE_DISABLE)) \
- thread_add_event(master, ospf6_orig_as_external_lsa, \
- oi, 0, &(oi)->thread_as_extern_lsa); \
+ event_add_event(master, ospf6_orig_as_external_lsa, \
+ oi, 0, &(oi)->thread_as_extern_lsa); \
} while (0)
#define OSPF6_ROUTER_LSA_EXECUTE(oa) \
do { \
if (CHECK_FLAG((oa)->flag, OSPF6_AREA_ENABLE)) \
- thread_execute(master, ospf6_router_lsa_originate, oa, \
- 0); \
+ event_execute(master, ospf6_router_lsa_originate, oa, \
+ 0); \
} while (0)
#define OSPF6_NETWORK_LSA_EXECUTE(oi) \
do { \
- THREAD_OFF((oi)->thread_network_lsa); \
- thread_execute(master, ospf6_network_lsa_originate, oi, 0); \
+ EVENT_OFF((oi)->thread_network_lsa); \
+ event_execute(master, ospf6_network_lsa_originate, oi, 0); \
} while (0)
#define OSPF6_LINK_LSA_EXECUTE(oi) \
do { \
if (!CHECK_FLAG((oi)->flag, OSPF6_INTERFACE_DISABLE)) \
- thread_execute(master, ospf6_link_lsa_originate, oi, \
- 0); \
+ event_execute(master, ospf6_link_lsa_originate, oi, \
+ 0); \
} while (0)
#define OSPF6_INTRA_PREFIX_LSA_EXECUTE_TRANSIT(oi) \
do { \
- THREAD_OFF((oi)->thread_intra_prefix_lsa); \
- thread_execute(master, \
- ospf6_intra_prefix_lsa_originate_transit, oi, \
- 0); \
+ EVENT_OFF((oi)->thread_intra_prefix_lsa); \
+ event_execute(master, \
+ ospf6_intra_prefix_lsa_originate_transit, oi, \
+ 0); \
} while (0)
#define OSPF6_AS_EXTERN_LSA_EXECUTE(oi) \
do { \
- THREAD_OFF((oi)->thread_as_extern_lsa); \
- thread_execute(master, ospf6_orig_as_external_lsa, oi, 0); \
+ EVENT_OFF((oi)->thread_as_extern_lsa); \
+ event_execute(master, ospf6_orig_as_external_lsa, oi, 0); \
} while (0)
/* Function Prototypes */
@@ -220,14 +220,14 @@ extern char *ospf6_network_lsdesc_lookup(uint32_t router_id,
struct ospf6_lsa *lsa);
extern int ospf6_router_is_stub_router(struct ospf6_lsa *lsa);
-extern void ospf6_router_lsa_originate(struct thread *thread);
-extern void ospf6_network_lsa_originate(struct thread *thread);
-extern void ospf6_link_lsa_originate(struct thread *thread);
-extern void ospf6_intra_prefix_lsa_originate_transit(struct thread *thread);
-extern void ospf6_intra_prefix_lsa_originate_stub(struct thread *thread);
+extern void ospf6_router_lsa_originate(struct event *thread);
+extern void ospf6_network_lsa_originate(struct event *thread);
+extern void ospf6_link_lsa_originate(struct event *thread);
+extern void ospf6_intra_prefix_lsa_originate_transit(struct event *thread);
+extern void ospf6_intra_prefix_lsa_originate_stub(struct event *thread);
extern void ospf6_intra_prefix_lsa_add(struct ospf6_lsa *lsa);
extern void ospf6_intra_prefix_lsa_remove(struct ospf6_lsa *lsa);
-extern void ospf6_orig_as_external_lsa(struct thread *thread);
+extern void ospf6_orig_as_external_lsa(struct event *thread);
extern void ospf6_intra_route_calculation(struct ospf6_area *oa);
extern void ospf6_intra_brouter_calculation(struct ospf6_area *oa);
extern void ospf6_intra_prefix_route_ecmp_path(struct ospf6_area *oa,
diff --git a/ospf6d/ospf6_lsa.c b/ospf6d/ospf6_lsa.c
index fe085b4cb4..2b806afe06 100644
--- a/ospf6d/ospf6_lsa.c
+++ b/ospf6d/ospf6_lsa.c
@@ -12,7 +12,7 @@
#include "vty.h"
#include "command.h"
#include "memory.h"
-#include "thread.h"
+#include "frrevent.h"
#include "checksum.h"
#include "frrstr.h"
@@ -302,8 +302,8 @@ void ospf6_lsa_premature_aging(struct ospf6_lsa *lsa)
if (IS_OSPF6_DEBUG_LSA_TYPE(lsa->header->type))
zlog_debug("LSA: Premature aging: %s", lsa->name);
- THREAD_OFF(lsa->expire);
- THREAD_OFF(lsa->refresh);
+ EVENT_OFF(lsa->expire);
+ EVENT_OFF(lsa->refresh);
/*
* We clear the LSA from the neighbor retx lists now because it
@@ -333,7 +333,7 @@ void ospf6_lsa_premature_aging(struct ospf6_lsa *lsa)
ospf6_flood_clear(lsa);
lsa->header->age = htons(OSPF_LSA_MAXAGE);
- thread_execute(master, ospf6_lsa_expire, lsa, 0);
+ event_execute(master, ospf6_lsa_expire, lsa, 0);
}
/* check which is more recent. if a is more recent, return -1;
@@ -760,8 +760,8 @@ void ospf6_lsa_delete(struct ospf6_lsa *lsa)
assert(lsa->lock == 0);
/* cancel threads */
- THREAD_OFF(lsa->expire);
- THREAD_OFF(lsa->refresh);
+ EVENT_OFF(lsa->expire);
+ EVENT_OFF(lsa->refresh);
/* do free */
XFREE(MTYPE_OSPF6_LSA_HEADER, lsa->header);
@@ -812,18 +812,18 @@ struct ospf6_lsa *ospf6_lsa_unlock(struct ospf6_lsa *lsa)
/* ospf6 lsa expiry */
-void ospf6_lsa_expire(struct thread *thread)
+void ospf6_lsa_expire(struct event *thread)
{
struct ospf6_lsa *lsa;
struct ospf6 *ospf6;
- lsa = (struct ospf6_lsa *)THREAD_ARG(thread);
+ lsa = (struct ospf6_lsa *)EVENT_ARG(thread);
assert(lsa && lsa->header);
assert(OSPF6_LSA_IS_MAXAGE(lsa));
assert(!lsa->refresh);
- lsa->expire = (struct thread *)NULL;
+ lsa->expire = (struct event *)NULL;
if (IS_OSPF6_DEBUG_LSA_TYPE(lsa->header->type)) {
zlog_debug("LSA Expire:");
@@ -845,15 +845,15 @@ void ospf6_lsa_expire(struct thread *thread)
ospf6_maxage_remove(ospf6);
}
-void ospf6_lsa_refresh(struct thread *thread)
+void ospf6_lsa_refresh(struct event *thread)
{
struct ospf6_lsa *old, *self, *new;
struct ospf6_lsdb *lsdb_self;
- old = (struct ospf6_lsa *)THREAD_ARG(thread);
+ old = (struct ospf6_lsa *)EVENT_ARG(thread);
assert(old && old->header);
- old->refresh = (struct thread *)NULL;
+ old->refresh = (struct event *)NULL;
lsdb_self = ospf6_get_scoped_lsdb_self(old);
self = ospf6_lsdb_lookup(old->header->type, old->header->id,
@@ -875,8 +875,8 @@ void ospf6_lsa_refresh(struct thread *thread)
new = ospf6_lsa_create(self->header);
new->lsdb = old->lsdb;
- thread_add_timer(master, ospf6_lsa_refresh, new, OSPF_LS_REFRESH_TIME,
- &new->refresh);
+ event_add_timer(master, ospf6_lsa_refresh, new, OSPF_LS_REFRESH_TIME,
+ &new->refresh);
/* store it in the LSDB for self-originated LSAs */
ospf6_lsdb_add(ospf6_lsa_copy(new), lsdb_self);
diff --git a/ospf6d/ospf6_lsa.h b/ospf6d/ospf6_lsa.h
index acb24d791d..be7b94f3d3 100644
--- a/ospf6d/ospf6_lsa.h
+++ b/ospf6d/ospf6_lsa.h
@@ -119,8 +119,8 @@ struct ospf6_lsa {
struct timeval received; /* used by MinLSArrival check */
struct timeval installed;
- struct thread *expire;
- struct thread *refresh; /* For self-originated LSA */
+ struct event *expire;
+ struct event *refresh; /* For self-originated LSA */
int retrans_count;
@@ -241,8 +241,8 @@ extern struct ospf6_lsa *ospf6_lsa_copy(struct ospf6_lsa *lsa);
extern struct ospf6_lsa *ospf6_lsa_lock(struct ospf6_lsa *lsa);
extern struct ospf6_lsa *ospf6_lsa_unlock(struct ospf6_lsa *lsa);
-extern void ospf6_lsa_expire(struct thread *thread);
-extern void ospf6_lsa_refresh(struct thread *thread);
+extern void ospf6_lsa_expire(struct event *thread);
+extern void ospf6_lsa_refresh(struct event *thread);
extern unsigned short ospf6_lsa_checksum(struct ospf6_lsa_header *lsah);
extern int ospf6_lsa_checksum_valid(struct ospf6_lsa_header *lsah);
diff --git a/ospf6d/ospf6_lsdb.c b/ospf6d/ospf6_lsdb.c
index 0221102b59..7925a8b2f4 100644
--- a/ospf6d/ospf6_lsdb.c
+++ b/ospf6d/ospf6_lsdb.c
@@ -13,8 +13,10 @@
#include "vty.h"
#include "ospf6_proto.h"
+#include "ospf6_area.h"
#include "ospf6_lsa.h"
#include "ospf6_lsdb.h"
+#include "ospf6_abr.h"
#include "ospf6_asbr.h"
#include "ospf6_route.h"
#include "ospf6d.h"
@@ -216,6 +218,31 @@ struct ospf6_lsa *ospf6_find_external_lsa(struct ospf6 *ospf6, struct prefix *p)
return lsa;
}
+struct ospf6_lsa *ospf6_find_inter_prefix_lsa(struct ospf6 *ospf6,
+ struct ospf6_area *area,
+ struct prefix *p)
+{
+ struct ospf6_lsa *lsa;
+ uint16_t type = htons(OSPF6_LSTYPE_INTER_PREFIX);
+
+ for (ALL_LSDB_TYPED_ADVRTR(area->lsdb, type, ospf6->router_id, lsa)) {
+ struct ospf6_inter_prefix_lsa *prefix_lsa;
+ struct prefix prefix;
+
+ prefix_lsa =
+ (struct ospf6_inter_prefix_lsa *)OSPF6_LSA_HEADER_END(
+ lsa->header);
+ prefix.family = AF_INET6;
+ prefix.prefixlen = prefix_lsa->prefix.prefix_length;
+ ospf6_prefix_in6_addr(&prefix.u.prefix6, prefix_lsa,
+ &prefix_lsa->prefix);
+ if (prefix_same(p, &prefix))
+ return lsa;
+ }
+
+ return NULL;
+}
+
struct ospf6_lsa *ospf6_lsdb_lookup_next(uint16_t type, uint32_t id,
uint32_t adv_router,
struct ospf6_lsdb *lsdb)
@@ -368,8 +395,8 @@ int ospf6_lsdb_maxage_remover(struct ospf6_lsdb *lsdb)
htonl(OSPF_MAX_SEQUENCE_NUMBER + 1);
ospf6_lsa_checksum(lsa->header);
- THREAD_OFF(lsa->refresh);
- thread_execute(master, ospf6_lsa_refresh, lsa, 0);
+ EVENT_OFF(lsa->refresh);
+ event_execute(master, ospf6_lsa_refresh, lsa, 0);
} else {
zlog_debug("calling ospf6_lsdb_remove %s", lsa->name);
ospf6_lsdb_remove(lsa, lsdb);
diff --git a/ospf6d/ospf6_lsdb.h b/ospf6d/ospf6_lsdb.h
index 7e20b05447..a2444f1c14 100644
--- a/ospf6d/ospf6_lsdb.h
+++ b/ospf6d/ospf6_lsdb.h
@@ -29,6 +29,9 @@ extern struct ospf6_lsa *ospf6_lsdb_lookup(uint16_t type, uint32_t id,
extern struct ospf6_lsa *ospf6_lsdb_lookup_next(uint16_t type, uint32_t id,
uint32_t adv_router,
struct ospf6_lsdb *lsdb);
+extern struct ospf6_lsa *ospf6_find_inter_prefix_lsa(struct ospf6 *ospf6,
+ struct ospf6_area *area,
+ struct prefix *p);
extern void ospf6_lsdb_add(struct ospf6_lsa *lsa, struct ospf6_lsdb *lsdb);
extern void ospf6_lsdb_remove(struct ospf6_lsa *lsa, struct ospf6_lsdb *lsdb);
diff --git a/ospf6d/ospf6_main.c b/ospf6d/ospf6_main.c
index abc460249d..fdb93475d4 100644
--- a/ospf6d/ospf6_main.c
+++ b/ospf6d/ospf6_main.c
@@ -9,7 +9,7 @@
#include <stdlib.h>
#include "getopt.h"
-#include "thread.h"
+#include "frrevent.h"
#include "log.h"
#include "command.h"
#include "vty.h"
@@ -62,7 +62,7 @@ struct zebra_privs_t ospf6d_privs = {
struct option longopts[] = {{0}};
/* Master of threads. */
-struct thread_master *master;
+struct event_loop *master;
static void __attribute__((noreturn)) ospf6_exit(int status)
{
diff --git a/ospf6d/ospf6_message.c b/ospf6d/ospf6_message.c
index b7f261fcf9..14b02dac79 100644
--- a/ospf6d/ospf6_message.c
+++ b/ospf6d/ospf6_message.c
@@ -9,7 +9,7 @@
#include "log.h"
#include "vty.h"
#include "command.h"
-#include "thread.h"
+#include "frrevent.h"
#include "linklist.h"
#include "lib_errors.h"
#include "checksum.h"
@@ -410,26 +410,29 @@ static void ospf6_hello_recv(struct in6_addr *src, struct in6_addr *dst,
/* HelloInterval check */
if (ntohs(hello->hello_interval) != oi->hello_interval) {
zlog_warn(
- "VRF %s: I/F %s HelloInterval mismatch: (my %d, rcvd %d)",
- oi->interface->vrf->name, oi->interface->name,
- oi->hello_interval, ntohs(hello->hello_interval));
+ "VRF %s: I/F %s HelloInterval mismatch from %pI6 (%pI4): (my %d, rcvd %d)",
+ oi->interface->vrf->name, oi->interface->name, src,
+ &oh->router_id, oi->hello_interval,
+ ntohs(hello->hello_interval));
return;
}
/* RouterDeadInterval check */
if (ntohs(hello->dead_interval) != oi->dead_interval) {
zlog_warn(
- "VRF %s: I/F %s DeadInterval mismatch: (my %d, rcvd %d)",
- oi->interface->vrf->name, oi->interface->name,
- oi->dead_interval, ntohs(hello->dead_interval));
+ "VRF %s: I/F %s DeadInterval mismatch from %pI6 (%pI4): (my %d, rcvd %d)",
+ oi->interface->vrf->name, oi->interface->name, src,
+ &oh->router_id, oi->dead_interval,
+ ntohs(hello->dead_interval));
return;
}
/* E-bit check */
- if (OSPF6_OPT_ISSET(hello->options, OSPF6_OPT_E)
- != OSPF6_OPT_ISSET(oi->area->options, OSPF6_OPT_E)) {
- zlog_warn("VRF %s: IF %s E-bit mismatch",
- oi->interface->vrf->name, oi->interface->name);
+ if (OSPF6_OPT_ISSET(hello->options, OSPF6_OPT_E) !=
+ OSPF6_OPT_ISSET(oi->area->options, OSPF6_OPT_E)) {
+ zlog_warn("VRF %s: IF %s E-bit mismatch from %pI6 (%pI4)",
+ oi->interface->vrf->name, oi->interface->name, src,
+ &oh->router_id);
return;
}
@@ -532,9 +535,9 @@ static void ospf6_hello_recv(struct in6_addr *src, struct in6_addr *dst,
oi->hello_in++;
/* Execute neighbor events */
- thread_execute(master, hello_received, on, 0);
+ event_execute(master, hello_received, on, 0);
if (twoway)
- thread_execute(master, twoway_received, on, 0);
+ event_execute(master, twoway_received, on, 0);
else {
if (OSPF6_GR_IS_ACTIVE_HELPER(on)) {
if (IS_DEBUG_OSPF6_GR)
@@ -550,7 +553,7 @@ static void ospf6_hello_recv(struct in6_addr *src, struct in6_addr *dst,
* receives one_way hellow when it acts as HELPER for
* that specific neighbor.
*/
- thread_execute(master, oneway_received, on, 0);
+ event_execute(master, oneway_received, on, 0);
}
}
@@ -591,9 +594,9 @@ static void ospf6_hello_recv(struct in6_addr *src, struct in6_addr *dst,
/* Schedule interface events */
if (backupseen)
- thread_add_event(master, backup_seen, oi, 0, NULL);
+ event_add_event(master, backup_seen, oi, 0, NULL);
if (neighborchange)
- thread_add_event(master, neighbor_change, oi, 0, NULL);
+ event_add_event(master, neighbor_change, oi, 0, NULL);
if (neighbor_ifindex_change && on->state == OSPF6_NEIGHBOR_FULL)
OSPF6_ROUTER_LSA_SCHEDULE(oi->area);
@@ -621,7 +624,7 @@ static void ospf6_dbdesc_recv_master(struct ospf6_header *oh,
return;
case OSPF6_NEIGHBOR_INIT:
- thread_execute(master, twoway_received, on, 0);
+ event_execute(master, twoway_received, on, 0);
if (on->state != OSPF6_NEIGHBOR_EXSTART) {
if (IS_OSPF6_DEBUG_MESSAGE(oh->type, RECV_HDR))
zlog_debug(
@@ -637,7 +640,7 @@ static void ospf6_dbdesc_recv_master(struct ospf6_header *oh,
&& !CHECK_FLAG(dbdesc->bits, OSPF6_DBDESC_IBIT)
&& ntohl(dbdesc->seqnum) == on->dbdesc_seqnum) {
/* execute NegotiationDone */
- thread_execute(master, negotiation_done, on, 0);
+ event_execute(master, negotiation_done, on, 0);
/* Record neighbor options */
memcpy(on->options, dbdesc->options,
@@ -664,32 +667,33 @@ static void ospf6_dbdesc_recv_master(struct ospf6_header *oh,
zlog_warn(
"DbDesc recv: Master/Slave bit mismatch Nbr %s",
on->name);
- thread_add_event(master, seqnumber_mismatch, on, 0,
- NULL);
+ event_add_event(master, seqnumber_mismatch, on, 0,
+ NULL);
return;
}
if (CHECK_FLAG(dbdesc->bits, OSPF6_DBDESC_IBIT)) {
zlog_warn("DbDesc recv: Initialize bit mismatch Nbr %s",
on->name);
- thread_add_event(master, seqnumber_mismatch, on, 0,
- NULL);
+ event_add_event(master, seqnumber_mismatch, on, 0,
+ NULL);
return;
}
if (memcmp(on->options, dbdesc->options, sizeof(on->options))) {
zlog_warn("DbDesc recv: Option field mismatch Nbr %s",
on->name);
- thread_add_event(master, seqnumber_mismatch, on, 0,
- NULL);
+ event_add_event(master, seqnumber_mismatch, on, 0,
+ NULL);
return;
}
if (ntohl(dbdesc->seqnum) != on->dbdesc_seqnum) {
zlog_warn(
- "DbDesc recv: Sequence number mismatch Nbr %s (%#lx expected)",
- on->name, (unsigned long)on->dbdesc_seqnum);
- thread_add_event(master, seqnumber_mismatch, on, 0,
+ "DbDesc recv: Sequence number mismatch Nbr %s (received %#lx, %#lx expected)",
+ on->name, (unsigned long)ntohl(dbdesc->seqnum),
+ (unsigned long)on->dbdesc_seqnum);
+ event_add_event(master, seqnumber_mismatch, on, 0,
NULL);
return;
}
@@ -710,7 +714,7 @@ static void ospf6_dbdesc_recv_master(struct ospf6_header *oh,
zlog_warn(
"DbDesc recv: Not duplicate dbdesc in state %s Nbr %s",
ospf6_neighbor_state_str[on->state], on->name);
- thread_add_event(master, seqnumber_mismatch, on, 0, NULL);
+ event_add_event(master, seqnumber_mismatch, on, 0, NULL);
return;
default:
@@ -754,8 +758,8 @@ static void ospf6_dbdesc_recv_master(struct ospf6_header *oh,
zlog_debug(
"SeqNumMismatch (E-bit mismatch), discard");
ospf6_lsa_delete(his);
- thread_add_event(master, seqnumber_mismatch, on, 0,
- NULL);
+ event_add_event(master, seqnumber_mismatch, on, 0,
+ NULL);
return;
}
@@ -783,19 +787,19 @@ static void ospf6_dbdesc_recv_master(struct ospf6_header *oh,
/* schedule send lsreq */
if (on->request_list->count)
- thread_add_event(master, ospf6_lsreq_send, on, 0,
- &on->thread_send_lsreq);
+ event_add_event(master, ospf6_lsreq_send, on, 0,
+ &on->thread_send_lsreq);
- THREAD_OFF(on->thread_send_dbdesc);
+ EVENT_OFF(on->thread_send_dbdesc);
/* More bit check */
if (!CHECK_FLAG(dbdesc->bits, OSPF6_DBDESC_MBIT)
&& !CHECK_FLAG(on->dbdesc_bits, OSPF6_DBDESC_MBIT))
- thread_add_event(master, exchange_done, on, 0,
- &on->thread_exchange_done);
+ event_add_event(master, exchange_done, on, 0,
+ &on->thread_exchange_done);
else {
- thread_add_event(master, ospf6_dbdesc_send_newone, on, 0,
- &on->thread_send_dbdesc);
+ event_add_event(master, ospf6_dbdesc_send_newone, on, 0,
+ &on->thread_send_dbdesc);
}
/* save last received dbdesc */
@@ -824,7 +828,7 @@ static void ospf6_dbdesc_recv_slave(struct ospf6_header *oh,
return;
case OSPF6_NEIGHBOR_INIT:
- thread_execute(master, twoway_received, on, 0);
+ event_execute(master, twoway_received, on, 0);
if (on->state != OSPF6_NEIGHBOR_EXSTART) {
if (IS_OSPF6_DEBUG_MESSAGE(oh->type, RECV_HDR))
zlog_debug(
@@ -851,7 +855,7 @@ static void ospf6_dbdesc_recv_slave(struct ospf6_header *oh,
on->dbdesc_seqnum = ntohl(dbdesc->seqnum);
/* schedule NegotiationDone */
- thread_execute(master, negotiation_done, on, 0);
+ event_execute(master, negotiation_done, on, 0);
/* Record neighbor options */
memcpy(on->options, dbdesc->options,
@@ -871,9 +875,9 @@ static void ospf6_dbdesc_recv_slave(struct ospf6_header *oh,
if (IS_OSPF6_DEBUG_MESSAGE(oh->type, RECV_HDR))
zlog_debug(
"Duplicated dbdesc causes retransmit");
- THREAD_OFF(on->thread_send_dbdesc);
- thread_add_event(master, ospf6_dbdesc_send, on, 0,
- &on->thread_send_dbdesc);
+ EVENT_OFF(on->thread_send_dbdesc);
+ event_add_event(master, ospf6_dbdesc_send, on, 0,
+ &on->thread_send_dbdesc);
return;
}
@@ -881,8 +885,8 @@ static void ospf6_dbdesc_recv_slave(struct ospf6_header *oh,
zlog_warn(
"DbDesc slave recv: Master/Slave bit mismatch Nbr %s",
on->name);
- thread_add_event(master, seqnumber_mismatch, on, 0,
- NULL);
+ event_add_event(master, seqnumber_mismatch, on, 0,
+ NULL);
return;
}
@@ -890,8 +894,8 @@ static void ospf6_dbdesc_recv_slave(struct ospf6_header *oh,
zlog_warn(
"DbDesc slave recv: Initialize bit mismatch Nbr %s",
on->name);
- thread_add_event(master, seqnumber_mismatch, on, 0,
- NULL);
+ event_add_event(master, seqnumber_mismatch, on, 0,
+ NULL);
return;
}
@@ -899,16 +903,17 @@ static void ospf6_dbdesc_recv_slave(struct ospf6_header *oh,
zlog_warn(
"DbDesc slave recv: Option field mismatch Nbr %s",
on->name);
- thread_add_event(master, seqnumber_mismatch, on, 0,
- NULL);
+ event_add_event(master, seqnumber_mismatch, on, 0,
+ NULL);
return;
}
if (ntohl(dbdesc->seqnum) != on->dbdesc_seqnum + 1) {
zlog_warn(
- "DbDesc slave recv: Sequence number mismatch Nbr %s (%#lx expected)",
- on->name, (unsigned long)on->dbdesc_seqnum + 1);
- thread_add_event(master, seqnumber_mismatch, on, 0,
+ "DbDesc slave recv: Sequence number mismatch Nbr %s (received %#lx, %#lx expected)",
+ on->name, (unsigned long)ntohl(dbdesc->seqnum),
+ (unsigned long)on->dbdesc_seqnum + 1);
+ event_add_event(master, seqnumber_mismatch, on, 0,
NULL);
return;
}
@@ -923,16 +928,16 @@ static void ospf6_dbdesc_recv_slave(struct ospf6_header *oh,
if (IS_OSPF6_DEBUG_MESSAGE(oh->type, RECV_HDR))
zlog_debug(
"Duplicated dbdesc causes retransmit");
- THREAD_OFF(on->thread_send_dbdesc);
- thread_add_event(master, ospf6_dbdesc_send, on, 0,
- &on->thread_send_dbdesc);
+ EVENT_OFF(on->thread_send_dbdesc);
+ event_add_event(master, ospf6_dbdesc_send, on, 0,
+ &on->thread_send_dbdesc);
return;
}
zlog_warn(
"DbDesc slave recv: Not duplicate dbdesc in state %s Nbr %s",
ospf6_neighbor_state_str[on->state], on->name);
- thread_add_event(master, seqnumber_mismatch, on, 0, NULL);
+ event_add_event(master, seqnumber_mismatch, on, 0, NULL);
return;
default:
@@ -972,8 +977,8 @@ static void ospf6_dbdesc_recv_slave(struct ospf6_header *oh,
if (IS_OSPF6_DEBUG_MESSAGE(oh->type, RECV))
zlog_debug("E-bit mismatch with LSA Headers");
ospf6_lsa_delete(his);
- thread_add_event(master, seqnumber_mismatch, on, 0,
- NULL);
+ event_add_event(master, seqnumber_mismatch, on, 0,
+ NULL);
return;
}
@@ -994,12 +999,12 @@ static void ospf6_dbdesc_recv_slave(struct ospf6_header *oh,
/* schedule send lsreq */
if (on->request_list->count)
- thread_add_event(master, ospf6_lsreq_send, on, 0,
- &on->thread_send_lsreq);
+ event_add_event(master, ospf6_lsreq_send, on, 0,
+ &on->thread_send_lsreq);
- THREAD_OFF(on->thread_send_dbdesc);
- thread_add_event(master, ospf6_dbdesc_send_newone, on, 0,
- &on->thread_send_dbdesc);
+ EVENT_OFF(on->thread_send_dbdesc);
+ event_add_event(master, ospf6_dbdesc_send_newone, on, 0,
+ &on->thread_send_dbdesc);
/* save last received dbdesc */
memcpy(&on->dbdesc_last, dbdesc, sizeof(struct ospf6_dbdesc));
@@ -1121,7 +1126,7 @@ static void ospf6_lsreq_recv(struct in6_addr *src, struct in6_addr *dst,
"Can't find requested lsa [%s Id:%pI4 Adv:%pI4] send badLSReq",
ospf6_lstype_name(e->type), &e->id,
&e->adv_router);
- thread_add_event(master, bad_lsreq, on, 0, NULL);
+ event_add_event(master, bad_lsreq, on, 0, NULL);
return;
}
@@ -1131,9 +1136,9 @@ static void ospf6_lsreq_recv(struct in6_addr *src, struct in6_addr *dst,
assert(p == OSPF6_MESSAGE_END(oh));
/* schedule send lsupdate */
- THREAD_OFF(on->thread_send_lsupdate);
- thread_add_event(master, ospf6_lsupdate_send_neighbor, on, 0,
- &on->thread_send_lsupdate);
+ EVENT_OFF(on->thread_send_lsupdate);
+ event_add_event(master, ospf6_lsupdate_send_neighbor, on, 0,
+ &on->thread_send_lsupdate);
}
/* Verify, that the specified memory area contains exactly N valid IPv6
@@ -1537,20 +1542,25 @@ static int ospf6_rxpacket_examin(struct ospf6_interface *oi,
struct ospf6_header *oh,
const unsigned bytesonwire)
{
+ struct ospf6_neighbor *on;
if (MSG_OK != ospf6_packet_examin(oh, bytesonwire))
return MSG_NG;
+ on = ospf6_neighbor_lookup(oh->router_id, oi);
+
/* Area-ID check */
if (oh->area_id != oi->area->area_id) {
if (oh->area_id == OSPF_AREA_BACKBONE)
zlog_warn(
- "VRF %s: I/F %s Message may be via Virtual Link: not supported",
- oi->interface->vrf->name, oi->interface->name);
+ "VRF %s: I/F %s (%s, Router-ID: %pI4) Message may be via Virtual Link: not supported",
+ oi->interface->vrf->name, oi->interface->name,
+ on ? on->name : "null", &oh->router_id);
else
zlog_warn(
- "VRF %s: I/F %s Area-ID mismatch (my %pI4, rcvd %pI4)",
+ "VRF %s: I/F %s (%s, Router-ID: %pI4) Area-ID mismatch (my %pI4, rcvd %pI4)",
oi->interface->vrf->name, oi->interface->name,
+ on ? on->name : "null", &oh->router_id,
&oi->area->area_id, &oh->area_id);
return MSG_NG;
}
@@ -1558,9 +1568,10 @@ static int ospf6_rxpacket_examin(struct ospf6_interface *oi,
/* Instance-ID check */
if (oh->instance_id != oi->instance_id) {
zlog_warn(
- "VRF %s: I/F %s Instance-ID mismatch (my %u, rcvd %u)",
+ "VRF %s: I/F %s (%s, Router-ID: %pI4) Instance-ID mismatch (my %u, rcvd %u)",
oi->interface->vrf->name, oi->interface->name,
- oi->instance_id, oh->instance_id);
+ on ? on->name : "null", &oh->router_id, oi->instance_id,
+ oh->instance_id);
return MSG_NG;
}
@@ -1896,18 +1907,18 @@ static int ospf6_read_helper(int sockfd, struct ospf6 *ospf6)
return OSPF6_READ_CONTINUE;
}
-void ospf6_receive(struct thread *thread)
+void ospf6_receive(struct event *thread)
{
int sockfd;
struct ospf6 *ospf6;
int count = 0;
/* add next read thread */
- ospf6 = THREAD_ARG(thread);
- sockfd = THREAD_FD(thread);
+ ospf6 = EVENT_ARG(thread);
+ sockfd = EVENT_FD(thread);
- thread_add_read(master, ospf6_receive, ospf6, ospf6->fd,
- &ospf6->t_ospf6_receive);
+ event_add_read(master, ospf6_receive, ospf6, ospf6->fd,
+ &ospf6->t_ospf6_receive);
while (count < ospf6->write_oi_count) {
count++;
@@ -2071,9 +2082,9 @@ static uint16_t ospf6_make_hello(struct ospf6_interface *oi, struct stream *s)
return length;
}
-static void ospf6_write(struct thread *thread)
+static void ospf6_write(struct event *thread)
{
- struct ospf6 *ospf6 = THREAD_ARG(thread);
+ struct ospf6 *ospf6 = EVENT_ARG(thread);
struct ospf6_interface *oi;
struct ospf6_header *oh;
struct ospf6_packet *op;
@@ -2221,17 +2232,17 @@ static void ospf6_write(struct thread *thread)
/* If packets still remain in queue, call write thread. */
if (!list_isempty(ospf6->oi_write_q))
- thread_add_write(master, ospf6_write, ospf6, ospf6->fd,
- &ospf6->t_write);
+ event_add_write(master, ospf6_write, ospf6, ospf6->fd,
+ &ospf6->t_write);
}
-void ospf6_hello_send(struct thread *thread)
+void ospf6_hello_send(struct event *thread)
{
struct ospf6_interface *oi;
struct ospf6_packet *op;
uint16_t length = OSPF6_HEADER_SIZE;
- oi = (struct ospf6_interface *)THREAD_ARG(thread);
+ oi = (struct ospf6_interface *)EVENT_ARG(thread);
if (oi->state <= OSPF6_INTERFACE_DOWN) {
if (IS_OSPF6_DEBUG_MESSAGE(OSPF6_MESSAGE_TYPE_HELLO, SEND_HDR))
@@ -2268,8 +2279,8 @@ void ospf6_hello_send(struct thread *thread)
ospf6_packet_add_top(oi, op);
/* set next thread */
- thread_add_timer(master, ospf6_hello_send, oi, oi->hello_interval,
- &oi->thread_send_hello);
+ event_add_timer(master, ospf6_hello_send, oi, oi->hello_interval,
+ &oi->thread_send_hello);
OSPF6_MESSAGE_WRITE_ON(oi);
}
@@ -2322,13 +2333,13 @@ static uint16_t ospf6_make_dbdesc(struct ospf6_neighbor *on, struct stream *s)
return length;
}
-void ospf6_dbdesc_send(struct thread *thread)
+void ospf6_dbdesc_send(struct event *thread)
{
struct ospf6_neighbor *on;
uint16_t length = OSPF6_HEADER_SIZE;
struct ospf6_packet *op;
- on = (struct ospf6_neighbor *)THREAD_ARG(thread);
+ on = (struct ospf6_neighbor *)EVENT_ARG(thread);
if (on->state < OSPF6_NEIGHBOR_EXSTART) {
if (IS_OSPF6_DEBUG_MESSAGE(OSPF6_MESSAGE_TYPE_DBDESC, SEND))
@@ -2340,9 +2351,9 @@ void ospf6_dbdesc_send(struct thread *thread)
/* set next thread if master */
if (CHECK_FLAG(on->dbdesc_bits, OSPF6_DBDESC_MSBIT))
- thread_add_timer(master, ospf6_dbdesc_send, on,
- on->ospf6_if->rxmt_interval,
- &on->thread_send_dbdesc);
+ event_add_timer(master, ospf6_dbdesc_send, on,
+ on->ospf6_if->rxmt_interval,
+ &on->thread_send_dbdesc);
op = ospf6_packet_new(on->ospf6_if->ifmtu);
ospf6_make_header(OSPF6_MESSAGE_TYPE_DBDESC, on->ospf6_if, op->s);
@@ -2365,13 +2376,13 @@ void ospf6_dbdesc_send(struct thread *thread)
OSPF6_MESSAGE_WRITE_ON(on->ospf6_if);
}
-void ospf6_dbdesc_send_newone(struct thread *thread)
+void ospf6_dbdesc_send_newone(struct event *thread)
{
struct ospf6_neighbor *on;
struct ospf6_lsa *lsa, *lsanext;
unsigned int size = 0;
- on = (struct ospf6_neighbor *)THREAD_ARG(thread);
+ on = (struct ospf6_neighbor *)EVENT_ARG(thread);
ospf6_lsdb_remove_all(on->dbdesc_list);
/* move LSAs from summary_list to dbdesc_list (within neighbor
@@ -2407,10 +2418,10 @@ void ospf6_dbdesc_send_newone(struct thread *thread)
if (!CHECK_FLAG(on->dbdesc_bits, OSPF6_DBDESC_MSBIT) && /* Slave */
!CHECK_FLAG(on->dbdesc_last.bits, OSPF6_DBDESC_MBIT)
&& !CHECK_FLAG(on->dbdesc_bits, OSPF6_DBDESC_MBIT))
- thread_add_event(master, exchange_done, on, 0,
- &on->thread_exchange_done);
+ event_add_event(master, exchange_done, on, 0,
+ &on->thread_exchange_done);
- thread_execute(master, ospf6_dbdesc_send, on, 0);
+ event_execute(master, ospf6_dbdesc_send, on, 0);
}
static uint16_t ospf6_make_lsreq(struct ospf6_neighbor *on, struct stream *s)
@@ -2487,13 +2498,13 @@ static uint16_t ospf6_make_lsack_neighbor(struct ospf6_neighbor *on,
return length;
}
-void ospf6_lsreq_send(struct thread *thread)
+void ospf6_lsreq_send(struct event *thread)
{
struct ospf6_neighbor *on;
struct ospf6_packet *op;
uint16_t length = OSPF6_HEADER_SIZE;
- on = (struct ospf6_neighbor *)THREAD_ARG(thread);
+ on = (struct ospf6_neighbor *)EVENT_ARG(thread);
/* LSReq will be sent only in ExStart or Loading */
if (on->state != OSPF6_NEIGHBOR_EXCHANGE
@@ -2507,7 +2518,7 @@ void ospf6_lsreq_send(struct thread *thread)
/* schedule loading_done if request list is empty */
if (on->request_list->count == 0) {
- thread_add_event(master, loading_done, on, 0, NULL);
+ event_add_event(master, loading_done, on, 0, NULL);
return;
}
@@ -2540,9 +2551,9 @@ void ospf6_lsreq_send(struct thread *thread)
/* set next thread */
if (on->request_list->count != 0) {
- thread_add_timer(master, ospf6_lsreq_send, on,
- on->ospf6_if->rxmt_interval,
- &on->thread_send_lsreq);
+ event_add_timer(master, ospf6_lsreq_send, on,
+ on->ospf6_if->rxmt_interval,
+ &on->thread_send_lsreq);
}
}
@@ -2581,7 +2592,7 @@ static void ospf6_send_lsupdate(struct ospf6_neighbor *on,
listnode_add(oi->area->ospf6->oi_write_q, oi);
oi->on_write_q = 1;
}
- thread_execute(master, ospf6_write, oi->area->ospf6, 0);
+ event_execute(master, ospf6_write, oi->area->ospf6, 0);
} else
OSPF6_MESSAGE_WRITE_ON(oi);
}
@@ -2665,14 +2676,14 @@ static uint16_t ospf6_make_ls_retrans_list(struct ospf6_neighbor *on,
return length;
}
-void ospf6_lsupdate_send_neighbor(struct thread *thread)
+void ospf6_lsupdate_send_neighbor(struct event *thread)
{
struct ospf6_neighbor *on;
struct ospf6_packet *op;
uint16_t length = OSPF6_HEADER_SIZE;
int lsa_cnt = 0;
- on = (struct ospf6_neighbor *)THREAD_ARG(thread);
+ on = (struct ospf6_neighbor *)EVENT_ARG(thread);
if (IS_OSPF6_DEBUG_MESSAGE(OSPF6_MESSAGE_TYPE_LSUPDATE, SEND_HDR))
zlog_debug("LSUpdate to neighbor %s", on->name);
@@ -2723,12 +2734,12 @@ void ospf6_lsupdate_send_neighbor(struct thread *thread)
ospf6_packet_free(op);
if (on->lsupdate_list->count != 0) {
- thread_add_event(master, ospf6_lsupdate_send_neighbor, on, 0,
- &on->thread_send_lsupdate);
+ event_add_event(master, ospf6_lsupdate_send_neighbor, on, 0,
+ &on->thread_send_lsupdate);
} else if (on->retrans_list->count != 0) {
- thread_add_timer(master, ospf6_lsupdate_send_neighbor, on,
- on->ospf6_if->rxmt_interval,
- &on->thread_send_lsupdate);
+ event_add_timer(master, ospf6_lsupdate_send_neighbor, on,
+ on->ospf6_if->rxmt_interval,
+ &on->thread_send_lsupdate);
}
}
@@ -2800,14 +2811,14 @@ static uint16_t ospf6_make_lsupdate_interface(struct ospf6_interface *oi,
return length;
}
-void ospf6_lsupdate_send_interface(struct thread *thread)
+void ospf6_lsupdate_send_interface(struct event *thread)
{
struct ospf6_interface *oi;
struct ospf6_packet *op;
uint16_t length = OSPF6_HEADER_SIZE;
int lsa_cnt = 0;
- oi = (struct ospf6_interface *)THREAD_ARG(thread);
+ oi = (struct ospf6_interface *)EVENT_ARG(thread);
if (oi->state <= OSPF6_INTERFACE_WAITING) {
if (IS_OSPF6_DEBUG_MESSAGE(OSPF6_MESSAGE_TYPE_LSUPDATE,
@@ -2836,18 +2847,18 @@ void ospf6_lsupdate_send_interface(struct thread *thread)
ospf6_packet_free(op);
if (oi->lsupdate_list->count > 0) {
- thread_add_event(master, ospf6_lsupdate_send_interface, oi, 0,
- &oi->thread_send_lsupdate);
+ event_add_event(master, ospf6_lsupdate_send_interface, oi, 0,
+ &oi->thread_send_lsupdate);
}
}
-void ospf6_lsack_send_neighbor(struct thread *thread)
+void ospf6_lsack_send_neighbor(struct event *thread)
{
struct ospf6_neighbor *on;
struct ospf6_packet *op;
uint16_t length = OSPF6_HEADER_SIZE;
- on = (struct ospf6_neighbor *)THREAD_ARG(thread);
+ on = (struct ospf6_neighbor *)EVENT_ARG(thread);
if (on->state < OSPF6_NEIGHBOR_EXCHANGE) {
if (IS_OSPF6_DEBUG_MESSAGE(OSPF6_MESSAGE_TYPE_LSACK, SEND_HDR))
@@ -2882,8 +2893,8 @@ void ospf6_lsack_send_neighbor(struct thread *thread)
OSPF6_MESSAGE_WRITE_ON(on->ospf6_if);
if (on->lsack_list->count > 0)
- thread_add_event(master, ospf6_lsack_send_neighbor, on, 0,
- &on->thread_send_lsack);
+ event_add_event(master, ospf6_lsack_send_neighbor, on, 0,
+ &on->thread_send_lsack);
}
static uint16_t ospf6_make_lsack_interface(struct ospf6_interface *oi,
@@ -2898,9 +2909,9 @@ static uint16_t ospf6_make_lsack_interface(struct ospf6_interface *oi,
> ospf6_packet_max(oi)) {
/* if we run out of packet size/space here,
better to try again soon. */
- THREAD_OFF(oi->thread_send_lsack);
- thread_add_event(master, ospf6_lsack_send_interface, oi,
- 0, &oi->thread_send_lsack);
+ EVENT_OFF(oi->thread_send_lsack);
+ event_add_event(master, ospf6_lsack_send_interface, oi,
+ 0, &oi->thread_send_lsack);
ospf6_lsa_unlock(lsa);
if (lsanext)
@@ -2917,13 +2928,13 @@ static uint16_t ospf6_make_lsack_interface(struct ospf6_interface *oi,
return length;
}
-void ospf6_lsack_send_interface(struct thread *thread)
+void ospf6_lsack_send_interface(struct event *thread)
{
struct ospf6_interface *oi;
struct ospf6_packet *op;
uint16_t length = OSPF6_HEADER_SIZE;
- oi = (struct ospf6_interface *)THREAD_ARG(thread);
+ oi = (struct ospf6_interface *)EVENT_ARG(thread);
if (oi->state <= OSPF6_INTERFACE_WAITING) {
if (IS_OSPF6_DEBUG_MESSAGE(OSPF6_MESSAGE_TYPE_LSACK, SEND_HDR))
@@ -2964,8 +2975,8 @@ void ospf6_lsack_send_interface(struct thread *thread)
OSPF6_MESSAGE_WRITE_ON(oi);
if (oi->lsack_list->count > 0)
- thread_add_event(master, ospf6_lsack_send_interface, oi, 0,
- &oi->thread_send_lsack);
+ event_add_event(master, ospf6_lsack_send_interface, oi, 0,
+ &oi->thread_send_lsack);
}
/* Commands */
diff --git a/ospf6d/ospf6_message.h b/ospf6d/ospf6_message.h
index 1f6a7e86e0..2b25b07445 100644
--- a/ospf6d/ospf6_message.h
+++ b/ospf6d/ospf6_message.h
@@ -158,16 +158,16 @@ extern void ospf6_fifo_free(struct ospf6_fifo *fifo);
extern int ospf6_iobuf_size(unsigned int size);
extern void ospf6_message_terminate(void);
-extern void ospf6_receive(struct thread *thread);
-
-extern void ospf6_hello_send(struct thread *thread);
-extern void ospf6_dbdesc_send(struct thread *thread);
-extern void ospf6_dbdesc_send_newone(struct thread *thread);
-extern void ospf6_lsreq_send(struct thread *thread);
-extern void ospf6_lsupdate_send_interface(struct thread *thread);
-extern void ospf6_lsupdate_send_neighbor(struct thread *thread);
-extern void ospf6_lsack_send_interface(struct thread *thread);
-extern void ospf6_lsack_send_neighbor(struct thread *thread);
+extern void ospf6_receive(struct event *thread);
+
+extern void ospf6_hello_send(struct event *thread);
+extern void ospf6_dbdesc_send(struct event *thread);
+extern void ospf6_dbdesc_send_newone(struct event *thread);
+extern void ospf6_lsreq_send(struct event *thread);
+extern void ospf6_lsupdate_send_interface(struct event *thread);
+extern void ospf6_lsupdate_send_neighbor(struct event *thread);
+extern void ospf6_lsack_send_interface(struct event *thread);
+extern void ospf6_lsack_send_neighbor(struct event *thread);
extern int config_write_ospf6_debug_message(struct vty *);
extern void install_element_ospf6_debug_message(void);
diff --git a/ospf6d/ospf6_neighbor.c b/ospf6d/ospf6_neighbor.c
index 85002962ca..42e4074522 100644
--- a/ospf6d/ospf6_neighbor.c
+++ b/ospf6d/ospf6_neighbor.c
@@ -7,7 +7,7 @@
#include "log.h"
#include "memory.h"
-#include "thread.h"
+#include "frrevent.h"
#include "linklist.h"
#include "vty.h"
#include "command.h"
@@ -163,18 +163,18 @@ void ospf6_neighbor_delete(struct ospf6_neighbor *on)
ospf6_lsdb_delete(on->lsupdate_list);
ospf6_lsdb_delete(on->lsack_list);
- THREAD_OFF(on->inactivity_timer);
+ EVENT_OFF(on->inactivity_timer);
- THREAD_OFF(on->last_dbdesc_release_timer);
+ EVENT_OFF(on->last_dbdesc_release_timer);
- THREAD_OFF(on->thread_send_dbdesc);
- THREAD_OFF(on->thread_send_lsreq);
- THREAD_OFF(on->thread_send_lsupdate);
- THREAD_OFF(on->thread_send_lsack);
- THREAD_OFF(on->thread_exchange_done);
- THREAD_OFF(on->thread_adj_ok);
+ EVENT_OFF(on->thread_send_dbdesc);
+ EVENT_OFF(on->thread_send_lsreq);
+ EVENT_OFF(on->thread_send_lsupdate);
+ EVENT_OFF(on->thread_send_lsack);
+ EVENT_OFF(on->thread_exchange_done);
+ EVENT_OFF(on->thread_adj_ok);
- THREAD_OFF(on->gr_helper_info.t_grace_timer);
+ EVENT_OFF(on->gr_helper_info.t_grace_timer);
bfd_sess_free(&on->bfd_session);
XFREE(MTYPE_OSPF6_NEIGHBOR, on);
@@ -196,10 +196,12 @@ static void ospf6_neighbor_state_change(uint8_t next_state,
/* log */
if (IS_OSPF6_DEBUG_NEIGHBOR(STATE)) {
- zlog_debug("Neighbor state change %s: [%s]->[%s] (%s)",
- on->name, ospf6_neighbor_state_str[prev_state],
- ospf6_neighbor_state_str[next_state],
- ospf6_neighbor_event_string(event));
+ zlog_debug(
+ "Neighbor state change %s (Router-ID: %pI4): [%s]->[%s] (%s)",
+ on->name, &on->router_id,
+ ospf6_neighbor_state_str[prev_state],
+ ospf6_neighbor_state_str[next_state],
+ ospf6_neighbor_event_string(event));
}
/* Optionally notify about adjacency changes */
@@ -209,10 +211,13 @@ static void ospf6_neighbor_state_change(uint8_t next_state,
OSPF6_LOG_ADJACENCY_DETAIL)
|| (next_state == OSPF6_NEIGHBOR_FULL)
|| (next_state < prev_state)))
- zlog_notice("AdjChg: Nbr %s: %s -> %s (%s)", on->name,
- ospf6_neighbor_state_str[prev_state],
- ospf6_neighbor_state_str[next_state],
- ospf6_neighbor_event_string(event));
+ zlog_notice(
+ "AdjChg: Nbr %pI4(%s) on %s: %s -> %s (%s)",
+ &on->router_id,
+ vrf_id_to_name(on->ospf6_if->interface->vrf->vrf_id),
+ on->name, ospf6_neighbor_state_str[prev_state],
+ ospf6_neighbor_state_str[next_state],
+ ospf6_neighbor_event_string(event));
if (prev_state == OSPF6_NEIGHBOR_FULL
|| next_state == OSPF6_NEIGHBOR_FULL) {
@@ -267,31 +272,31 @@ static int need_adjacency(struct ospf6_neighbor *on)
return 0;
}
-void hello_received(struct thread *thread)
+void hello_received(struct event *thread)
{
struct ospf6_neighbor *on;
- on = (struct ospf6_neighbor *)THREAD_ARG(thread);
+ on = (struct ospf6_neighbor *)EVENT_ARG(thread);
assert(on);
if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT))
zlog_debug("Neighbor Event %s: *HelloReceived*", on->name);
/* reset Inactivity Timer */
- THREAD_OFF(on->inactivity_timer);
- thread_add_timer(master, inactivity_timer, on,
- on->ospf6_if->dead_interval, &on->inactivity_timer);
+ EVENT_OFF(on->inactivity_timer);
+ event_add_timer(master, inactivity_timer, on,
+ on->ospf6_if->dead_interval, &on->inactivity_timer);
if (on->state <= OSPF6_NEIGHBOR_DOWN)
ospf6_neighbor_state_change(OSPF6_NEIGHBOR_INIT, on,
OSPF6_NEIGHBOR_EVENT_HELLO_RCVD);
}
-void twoway_received(struct thread *thread)
+void twoway_received(struct event *thread)
{
struct ospf6_neighbor *on;
- on = (struct ospf6_neighbor *)THREAD_ARG(thread);
+ on = (struct ospf6_neighbor *)EVENT_ARG(thread);
assert(on);
if (on->state > OSPF6_NEIGHBOR_INIT)
@@ -300,7 +305,7 @@ void twoway_received(struct thread *thread)
if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT))
zlog_debug("Neighbor Event %s: *2Way-Received*", on->name);
- thread_add_event(master, neighbor_change, on->ospf6_if, 0, NULL);
+ event_add_event(master, neighbor_change, on->ospf6_if, 0, NULL);
if (!need_adjacency(on)) {
ospf6_neighbor_state_change(OSPF6_NEIGHBOR_TWOWAY, on,
@@ -314,17 +319,17 @@ void twoway_received(struct thread *thread)
SET_FLAG(on->dbdesc_bits, OSPF6_DBDESC_MBIT);
SET_FLAG(on->dbdesc_bits, OSPF6_DBDESC_IBIT);
- THREAD_OFF(on->thread_send_dbdesc);
- thread_add_event(master, ospf6_dbdesc_send, on, 0,
- &on->thread_send_dbdesc);
+ EVENT_OFF(on->thread_send_dbdesc);
+ event_add_event(master, ospf6_dbdesc_send, on, 0,
+ &on->thread_send_dbdesc);
}
-void negotiation_done(struct thread *thread)
+void negotiation_done(struct event *thread)
{
struct ospf6_neighbor *on;
struct ospf6_lsa *lsa, *lsanext;
- on = (struct ospf6_neighbor *)THREAD_ARG(thread);
+ on = (struct ospf6_neighbor *)EVENT_ARG(thread);
assert(on);
if (on->state != OSPF6_NEIGHBOR_EXSTART)
@@ -368,19 +373,19 @@ void negotiation_done(struct thread *thread)
OSPF6_NEIGHBOR_EVENT_NEGOTIATION_DONE);
}
-static void ospf6_neighbor_last_dbdesc_release(struct thread *thread)
+static void ospf6_neighbor_last_dbdesc_release(struct event *thread)
{
- struct ospf6_neighbor *on = THREAD_ARG(thread);
+ struct ospf6_neighbor *on = EVENT_ARG(thread);
assert(on);
memset(&on->dbdesc_last, 0, sizeof(struct ospf6_dbdesc));
}
-void exchange_done(struct thread *thread)
+void exchange_done(struct event *thread)
{
struct ospf6_neighbor *on;
- on = (struct ospf6_neighbor *)THREAD_ARG(thread);
+ on = (struct ospf6_neighbor *)EVENT_ARG(thread);
assert(on);
if (on->state != OSPF6_NEIGHBOR_EXCHANGE)
@@ -389,15 +394,15 @@ void exchange_done(struct thread *thread)
if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT))
zlog_debug("Neighbor Event %s: *ExchangeDone*", on->name);
- THREAD_OFF(on->thread_send_dbdesc);
+ EVENT_OFF(on->thread_send_dbdesc);
ospf6_lsdb_remove_all(on->dbdesc_list);
/* RFC 2328 (10.8): Release the last dbdesc after dead_interval */
if (!CHECK_FLAG(on->dbdesc_bits, OSPF6_DBDESC_MSBIT)) {
- THREAD_OFF(on->last_dbdesc_release_timer);
- thread_add_timer(master, ospf6_neighbor_last_dbdesc_release, on,
- on->ospf6_if->dead_interval,
- &on->last_dbdesc_release_timer);
+ EVENT_OFF(on->last_dbdesc_release_timer);
+ event_add_timer(master, ospf6_neighbor_last_dbdesc_release, on,
+ on->ospf6_if->dead_interval,
+ &on->last_dbdesc_release_timer);
}
if (on->request_list->count == 0)
@@ -407,8 +412,8 @@ void exchange_done(struct thread *thread)
ospf6_neighbor_state_change(OSPF6_NEIGHBOR_LOADING, on,
OSPF6_NEIGHBOR_EVENT_EXCHANGE_DONE);
- thread_add_event(master, ospf6_lsreq_send, on, 0,
- &on->thread_send_lsreq);
+ event_add_event(master, ospf6_lsreq_send, on, 0,
+ &on->thread_send_lsreq);
}
}
@@ -423,20 +428,20 @@ void ospf6_check_nbr_loading(struct ospf6_neighbor *on)
if ((on->state == OSPF6_NEIGHBOR_LOADING)
|| (on->state == OSPF6_NEIGHBOR_EXCHANGE)) {
if (on->request_list->count == 0)
- thread_add_event(master, loading_done, on, 0, NULL);
+ event_add_event(master, loading_done, on, 0, NULL);
else if (on->last_ls_req == NULL) {
- THREAD_OFF(on->thread_send_lsreq);
- thread_add_event(master, ospf6_lsreq_send, on, 0,
- &on->thread_send_lsreq);
+ EVENT_OFF(on->thread_send_lsreq);
+ event_add_event(master, ospf6_lsreq_send, on, 0,
+ &on->thread_send_lsreq);
}
}
}
-void loading_done(struct thread *thread)
+void loading_done(struct event *thread)
{
struct ospf6_neighbor *on;
- on = (struct ospf6_neighbor *)THREAD_ARG(thread);
+ on = (struct ospf6_neighbor *)EVENT_ARG(thread);
assert(on);
if (on->state != OSPF6_NEIGHBOR_LOADING)
@@ -451,11 +456,11 @@ void loading_done(struct thread *thread)
OSPF6_NEIGHBOR_EVENT_LOADING_DONE);
}
-void adj_ok(struct thread *thread)
+void adj_ok(struct event *thread)
{
struct ospf6_neighbor *on;
- on = (struct ospf6_neighbor *)THREAD_ARG(thread);
+ on = (struct ospf6_neighbor *)EVENT_ARG(thread);
assert(on);
if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT))
@@ -468,9 +473,9 @@ void adj_ok(struct thread *thread)
SET_FLAG(on->dbdesc_bits, OSPF6_DBDESC_MBIT);
SET_FLAG(on->dbdesc_bits, OSPF6_DBDESC_IBIT);
- THREAD_OFF(on->thread_send_dbdesc);
- thread_add_event(master, ospf6_dbdesc_send, on, 0,
- &on->thread_send_dbdesc);
+ EVENT_OFF(on->thread_send_dbdesc);
+ event_add_event(master, ospf6_dbdesc_send, on, 0,
+ &on->thread_send_dbdesc);
} else if (on->state >= OSPF6_NEIGHBOR_EXSTART && !need_adjacency(on)) {
ospf6_neighbor_state_change(OSPF6_NEIGHBOR_TWOWAY, on,
@@ -479,11 +484,11 @@ void adj_ok(struct thread *thread)
}
}
-void seqnumber_mismatch(struct thread *thread)
+void seqnumber_mismatch(struct event *thread)
{
struct ospf6_neighbor *on;
- on = (struct ospf6_neighbor *)THREAD_ARG(thread);
+ on = (struct ospf6_neighbor *)EVENT_ARG(thread);
assert(on);
if (on->state < OSPF6_NEIGHBOR_EXCHANGE)
@@ -500,18 +505,18 @@ void seqnumber_mismatch(struct thread *thread)
ospf6_neighbor_clear_ls_lists(on);
- THREAD_OFF(on->thread_send_dbdesc);
+ EVENT_OFF(on->thread_send_dbdesc);
on->dbdesc_seqnum++; /* Incr seqnum as per RFC2328, sec 10.3 */
- thread_add_event(master, ospf6_dbdesc_send, on, 0,
- &on->thread_send_dbdesc);
+ event_add_event(master, ospf6_dbdesc_send, on, 0,
+ &on->thread_send_dbdesc);
}
-void bad_lsreq(struct thread *thread)
+void bad_lsreq(struct event *thread)
{
struct ospf6_neighbor *on;
- on = (struct ospf6_neighbor *)THREAD_ARG(thread);
+ on = (struct ospf6_neighbor *)EVENT_ARG(thread);
assert(on);
if (on->state < OSPF6_NEIGHBOR_EXCHANGE)
@@ -528,19 +533,18 @@ void bad_lsreq(struct thread *thread)
ospf6_neighbor_clear_ls_lists(on);
- THREAD_OFF(on->thread_send_dbdesc);
+ EVENT_OFF(on->thread_send_dbdesc);
on->dbdesc_seqnum++; /* Incr seqnum as per RFC2328, sec 10.3 */
- thread_add_event(master, ospf6_dbdesc_send, on, 0,
- &on->thread_send_dbdesc);
-
+ event_add_event(master, ospf6_dbdesc_send, on, 0,
+ &on->thread_send_dbdesc);
}
-void oneway_received(struct thread *thread)
+void oneway_received(struct event *thread)
{
struct ospf6_neighbor *on;
- on = (struct ospf6_neighbor *)THREAD_ARG(thread);
+ on = (struct ospf6_neighbor *)EVENT_ARG(thread);
assert(on);
if (on->state < OSPF6_NEIGHBOR_TWOWAY)
@@ -551,23 +555,23 @@ void oneway_received(struct thread *thread)
ospf6_neighbor_state_change(OSPF6_NEIGHBOR_INIT, on,
OSPF6_NEIGHBOR_EVENT_ONEWAY_RCVD);
- thread_add_event(master, neighbor_change, on->ospf6_if, 0, NULL);
+ event_add_event(master, neighbor_change, on->ospf6_if, 0, NULL);
ospf6_neighbor_clear_ls_lists(on);
- THREAD_OFF(on->thread_send_dbdesc);
- THREAD_OFF(on->thread_send_lsreq);
- THREAD_OFF(on->thread_send_lsupdate);
- THREAD_OFF(on->thread_send_lsack);
- THREAD_OFF(on->thread_exchange_done);
- THREAD_OFF(on->thread_adj_ok);
+ EVENT_OFF(on->thread_send_dbdesc);
+ EVENT_OFF(on->thread_send_lsreq);
+ EVENT_OFF(on->thread_send_lsupdate);
+ EVENT_OFF(on->thread_send_lsack);
+ EVENT_OFF(on->thread_exchange_done);
+ EVENT_OFF(on->thread_adj_ok);
}
-void inactivity_timer(struct thread *thread)
+void inactivity_timer(struct event *thread)
{
struct ospf6_neighbor *on;
- on = (struct ospf6_neighbor *)THREAD_ARG(thread);
+ on = (struct ospf6_neighbor *)EVENT_ARG(thread);
assert(on);
if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT))
@@ -583,8 +587,7 @@ void inactivity_timer(struct thread *thread)
ospf6_neighbor_state_change(
OSPF6_NEIGHBOR_DOWN, on,
OSPF6_NEIGHBOR_EVENT_INACTIVITY_TIMER);
- thread_add_event(master, neighbor_change, on->ospf6_if, 0,
- NULL);
+ event_add_event(master, neighbor_change, on->ospf6_if, 0, NULL);
listnode_delete(on->ospf6_if->neighbor_list, on);
ospf6_neighbor_delete(on);
@@ -595,9 +598,9 @@ void inactivity_timer(struct thread *thread)
"%s, Acting as HELPER for this neighbour, So restart the dead timer.",
__PRETTY_FUNCTION__);
- thread_add_timer(master, inactivity_timer, on,
- on->ospf6_if->dead_interval,
- &on->inactivity_timer);
+ event_add_timer(master, inactivity_timer, on,
+ on->ospf6_if->dead_interval,
+ &on->inactivity_timer);
}
}
@@ -812,7 +815,7 @@ static void ospf6_neighbor_show_detail(struct vty *vty,
timerclear(&res);
- if (thread_is_scheduled(on->thread_send_dbdesc))
+ if (event_is_scheduled(on->thread_send_dbdesc))
timersub(&on->thread_send_dbdesc->u.sands, &now, &res);
timerstring(&res, duration, sizeof(duration));
json_object_int_add(json_neighbor, "pendingLsaDbDescCount",
@@ -821,8 +824,8 @@ static void ospf6_neighbor_show_detail(struct vty *vty,
duration);
json_object_string_add(
json_neighbor, "dbDescSendThread",
- (thread_is_scheduled(on->thread_send_dbdesc) ? "on"
- : "off"));
+ (event_is_scheduled(on->thread_send_dbdesc) ? "on"
+ : "off"));
json_array = json_object_new_array();
for (ALL_LSDB(on->dbdesc_list, lsa, lsanext))
json_object_array_add(
@@ -831,7 +834,7 @@ static void ospf6_neighbor_show_detail(struct vty *vty,
json_array);
timerclear(&res);
- if (thread_is_scheduled(on->thread_send_lsreq))
+ if (event_is_scheduled(on->thread_send_lsreq))
timersub(&on->thread_send_lsreq->u.sands, &now, &res);
timerstring(&res, duration, sizeof(duration));
json_object_int_add(json_neighbor, "pendingLsaLsReqCount",
@@ -840,8 +843,8 @@ static void ospf6_neighbor_show_detail(struct vty *vty,
duration);
json_object_string_add(
json_neighbor, "lsReqSendThread",
- (thread_is_scheduled(on->thread_send_lsreq) ? "on"
- : "off"));
+ (event_is_scheduled(on->thread_send_lsreq) ? "on"
+ : "off"));
json_array = json_object_new_array();
for (ALL_LSDB(on->request_list, lsa, lsanext))
json_object_array_add(
@@ -851,7 +854,7 @@ static void ospf6_neighbor_show_detail(struct vty *vty,
timerclear(&res);
- if (thread_is_scheduled(on->thread_send_lsupdate))
+ if (event_is_scheduled(on->thread_send_lsupdate))
timersub(&on->thread_send_lsupdate->u.sands, &now,
&res);
timerstring(&res, duration, sizeof(duration));
@@ -861,9 +864,8 @@ static void ospf6_neighbor_show_detail(struct vty *vty,
duration);
json_object_string_add(
json_neighbor, "lsUpdateSendThread",
- (thread_is_scheduled(on->thread_send_lsupdate)
- ? "on"
- : "off"));
+ (event_is_scheduled(on->thread_send_lsupdate) ? "on"
+ : "off"));
json_array = json_object_new_array();
for (ALL_LSDB(on->lsupdate_list, lsa, lsanext))
json_object_array_add(
@@ -872,7 +874,7 @@ static void ospf6_neighbor_show_detail(struct vty *vty,
json_array);
timerclear(&res);
- if (thread_is_scheduled(on->thread_send_lsack))
+ if (event_is_scheduled(on->thread_send_lsack))
timersub(&on->thread_send_lsack->u.sands, &now, &res);
timerstring(&res, duration, sizeof(duration));
json_object_int_add(json_neighbor, "pendingLsaLsAckCount",
@@ -881,8 +883,8 @@ static void ospf6_neighbor_show_detail(struct vty *vty,
duration);
json_object_string_add(
json_neighbor, "lsAckSendThread",
- (thread_is_scheduled(on->thread_send_lsack) ? "on"
- : "off"));
+ (event_is_scheduled(on->thread_send_lsack) ? "on"
+ : "off"));
json_array = json_object_new_array();
for (ALL_LSDB(on->lsack_list, lsa, lsanext))
json_object_array_add(
@@ -970,52 +972,51 @@ static void ospf6_neighbor_show_detail(struct vty *vty,
vty_out(vty, " %s\n", lsa->name);
timerclear(&res);
- if (thread_is_scheduled(on->thread_send_dbdesc))
+ if (event_is_scheduled(on->thread_send_dbdesc))
timersub(&on->thread_send_dbdesc->u.sands, &now, &res);
timerstring(&res, duration, sizeof(duration));
vty_out(vty,
" %d Pending LSAs for DbDesc in Time %s [thread %s]\n",
on->dbdesc_list->count, duration,
- (thread_is_scheduled(on->thread_send_dbdesc) ? "on"
- : "off"));
+ (event_is_scheduled(on->thread_send_dbdesc) ? "on"
+ : "off"));
for (ALL_LSDB(on->dbdesc_list, lsa, lsanext))
vty_out(vty, " %s\n", lsa->name);
timerclear(&res);
- if (thread_is_scheduled(on->thread_send_lsreq))
+ if (event_is_scheduled(on->thread_send_lsreq))
timersub(&on->thread_send_lsreq->u.sands, &now, &res);
timerstring(&res, duration, sizeof(duration));
vty_out(vty,
" %d Pending LSAs for LSReq in Time %s [thread %s]\n",
on->request_list->count, duration,
- (thread_is_scheduled(on->thread_send_lsreq) ? "on"
- : "off"));
+ (event_is_scheduled(on->thread_send_lsreq) ? "on"
+ : "off"));
for (ALL_LSDB(on->request_list, lsa, lsanext))
vty_out(vty, " %s\n", lsa->name);
timerclear(&res);
- if (thread_is_scheduled(on->thread_send_lsupdate))
+ if (event_is_scheduled(on->thread_send_lsupdate))
timersub(&on->thread_send_lsupdate->u.sands, &now,
&res);
timerstring(&res, duration, sizeof(duration));
vty_out(vty,
" %d Pending LSAs for LSUpdate in Time %s [thread %s]\n",
on->lsupdate_list->count, duration,
- (thread_is_scheduled(on->thread_send_lsupdate)
- ? "on"
- : "off"));
+ (event_is_scheduled(on->thread_send_lsupdate) ? "on"
+ : "off"));
for (ALL_LSDB(on->lsupdate_list, lsa, lsanext))
vty_out(vty, " %s\n", lsa->name);
timerclear(&res);
- if (thread_is_scheduled(on->thread_send_lsack))
+ if (event_is_scheduled(on->thread_send_lsack))
timersub(&on->thread_send_lsack->u.sands, &now, &res);
timerstring(&res, duration, sizeof(duration));
vty_out(vty,
" %d Pending LSAs for LSAck in Time %s [thread %s]\n",
on->lsack_list->count, duration,
- (thread_is_scheduled(on->thread_send_lsack) ? "on"
- : "off"));
+ (event_is_scheduled(on->thread_send_lsack) ? "on"
+ : "off"));
for (ALL_LSDB(on->lsack_list, lsa, lsanext))
vty_out(vty, " %s\n", lsa->name);
diff --git a/ospf6d/ospf6_neighbor.h b/ospf6d/ospf6_neighbor.h
index d9abd1ff94..5ec754d3a4 100644
--- a/ospf6d/ospf6_neighbor.h
+++ b/ospf6d/ospf6_neighbor.h
@@ -36,7 +36,7 @@ struct ospf6_helper_info {
* helper until this timer until
* this timer expires.
*/
- struct thread *t_grace_timer;
+ struct event *t_grace_timer;
/* Helper status */
uint32_t gr_helper_status;
@@ -111,18 +111,18 @@ struct ospf6_neighbor {
struct ospf6_lsa *last_ls_req;
/* Inactivity timer */
- struct thread *inactivity_timer;
+ struct event *inactivity_timer;
/* Timer to release the last dbdesc packet */
- struct thread *last_dbdesc_release_timer;
+ struct event *last_dbdesc_release_timer;
/* Thread for sending message */
- struct thread *thread_send_dbdesc;
- struct thread *thread_send_lsreq;
- struct thread *thread_send_lsupdate;
- struct thread *thread_send_lsack;
- struct thread *thread_exchange_done;
- struct thread *thread_adj_ok;
+ struct event *thread_send_dbdesc;
+ struct event *thread_send_lsreq;
+ struct event *thread_send_lsupdate;
+ struct event *thread_send_lsack;
+ struct event *thread_exchange_done;
+ struct event *thread_adj_ok;
/* BFD information */
struct bfd_session_params *bfd_session;
@@ -190,16 +190,16 @@ struct ospf6_neighbor *ospf6_neighbor_create(uint32_t router_id,
void ospf6_neighbor_delete(struct ospf6_neighbor *on);
/* Neighbor event */
-extern void hello_received(struct thread *thread);
-extern void twoway_received(struct thread *thread);
-extern void negotiation_done(struct thread *thread);
-extern void exchange_done(struct thread *thread);
-extern void loading_done(struct thread *thread);
-extern void adj_ok(struct thread *thread);
-extern void seqnumber_mismatch(struct thread *thread);
-extern void bad_lsreq(struct thread *thread);
-extern void oneway_received(struct thread *thread);
-extern void inactivity_timer(struct thread *thread);
+extern void hello_received(struct event *thread);
+extern void twoway_received(struct event *thread);
+extern void negotiation_done(struct event *thread);
+extern void exchange_done(struct event *thread);
+extern void loading_done(struct event *thread);
+extern void adj_ok(struct event *thread);
+extern void seqnumber_mismatch(struct event *thread);
+extern void bad_lsreq(struct event *thread);
+extern void oneway_received(struct event *thread);
+extern void inactivity_timer(struct event *thread);
extern void ospf6_check_nbr_loading(struct ospf6_neighbor *on);
extern void ospf6_neighbor_init(void);
diff --git a/ospf6d/ospf6_network.h b/ospf6d/ospf6_network.h
index c5627212f8..60b7cc59e9 100644
--- a/ospf6d/ospf6_network.h
+++ b/ospf6d/ospf6_network.h
@@ -29,11 +29,11 @@ extern int ospf6_recvmsg(struct in6_addr *src, struct in6_addr *dst,
listnode_add(oi->area->ospf6->oi_write_q, (oi)); \
(oi)->on_write_q = 1; \
} \
- if (list_was_empty \
- && !list_isempty(oi->area->ospf6->oi_write_q)) \
- thread_add_write(master, ospf6_write, oi->area->ospf6, \
- oi->area->ospf6->fd, \
- &oi->area->ospf6->t_write); \
+ if (list_was_empty && \
+ !list_isempty(oi->area->ospf6->oi_write_q)) \
+ event_add_write(master, ospf6_write, oi->area->ospf6, \
+ oi->area->ospf6->fd, \
+ &oi->area->ospf6->t_write); \
} while (0)
#endif /* OSPF6_NETWORK_H */
diff --git a/ospf6d/ospf6_nssa.c b/ospf6d/ospf6_nssa.c
index d62a3a6322..e7a10eba41 100644
--- a/ospf6d/ospf6_nssa.c
+++ b/ospf6d/ospf6_nssa.c
@@ -13,7 +13,7 @@
#include "vty.h"
#include "linklist.h"
#include "command.h"
-#include "thread.h"
+#include "frrevent.h"
#include "plist.h"
#include "filter.h"
@@ -976,9 +976,9 @@ int ospf6_redistribute_check(struct ospf6 *ospf6, struct ospf6_route *route,
}
/* This function performs ABR related processing */
-static void ospf6_abr_task_timer(struct thread *thread)
+static void ospf6_abr_task_timer(struct event *thread)
{
- struct ospf6 *ospf6 = THREAD_ARG(thread);
+ struct ospf6 *ospf6 = EVENT_ARG(thread);
if (IS_OSPF6_DEBUG_ABR)
zlog_debug("Running ABR task on timer");
@@ -992,7 +992,7 @@ static void ospf6_abr_task_timer(struct thread *thread)
void ospf6_schedule_abr_task(struct ospf6 *ospf6)
{
- if (thread_is_scheduled(ospf6->t_abr_task)) {
+ if (event_is_scheduled(ospf6->t_abr_task)) {
if (IS_OSPF6_DEBUG_ABR)
zlog_debug("ABR task already scheduled");
return;
@@ -1001,8 +1001,8 @@ void ospf6_schedule_abr_task(struct ospf6 *ospf6)
if (IS_OSPF6_DEBUG_ABR)
zlog_debug("Scheduling ABR task");
- thread_add_timer(master, ospf6_abr_task_timer, ospf6,
- OSPF6_ABR_TASK_DELAY, &ospf6->t_abr_task);
+ event_add_timer(master, ospf6_abr_task_timer, ospf6,
+ OSPF6_ABR_TASK_DELAY, &ospf6->t_abr_task);
}
/* Flush the NSSA LSAs from the area */
@@ -1089,9 +1089,9 @@ static void ospf6_ase_lsa_refresh(struct ospf6 *o)
route->path.origin.id, o->router_id,
o->lsdb);
if (old) {
- THREAD_OFF(old->refresh);
- thread_add_event(master, ospf6_lsa_refresh, old, 0,
- &old->refresh);
+ EVENT_OFF(old->refresh);
+ event_add_event(master, ospf6_lsa_refresh, old, 0,
+ &old->refresh);
} else {
ospf6_as_external_lsa_originate(route, o);
}
@@ -1164,9 +1164,9 @@ void ospf6_area_nssa_update(struct ospf6_area *area)
lsa)) {
if (IS_OSPF6_DEBUG_NSSA)
ospf6_lsa_header_print(lsa);
- THREAD_OFF(lsa->refresh);
- thread_add_event(master, ospf6_lsa_refresh, lsa,
- 0, &lsa->refresh);
+ EVENT_OFF(lsa->refresh);
+ event_add_event(master, ospf6_lsa_refresh, lsa,
+ 0, &lsa->refresh);
}
}
}
@@ -1436,7 +1436,7 @@ DEFPY (no_area_nssa_range,
SET_FLAG(range->flag, OSPF6_ROUTE_REMOVE);
/* Redo summaries if required */
- thread_execute(master, ospf6_abr_task_timer, ospf6, 0);
+ event_execute(master, ospf6_abr_task_timer, ospf6, 0);
}
ospf6_route_remove(range, oa->nssa_range_table);
diff --git a/ospf6d/ospf6_snmp.c b/ospf6d/ospf6_snmp.c
index 46fa27dd9e..f88667bfd0 100644
--- a/ospf6d/ospf6_snmp.c
+++ b/ospf6d/ospf6_snmp.c
@@ -1383,7 +1383,7 @@ static int ospf6TrapIfStateChange(struct ospf6_interface *oi, int next_state,
}
/* Register OSPFv3-MIB. */
-static int ospf6_snmp_init(struct thread_master *master)
+static int ospf6_snmp_init(struct event_loop *master)
{
smux_init(master);
REGISTER_MIB("OSPFv3MIB", ospfv3_variables, variable, ospfv3_oid);
diff --git a/ospf6d/ospf6_spf.c b/ospf6d/ospf6_spf.c
index 112934bf1e..3cc0d5e963 100644
--- a/ospf6d/ospf6_spf.c
+++ b/ospf6d/ospf6_spf.c
@@ -13,7 +13,7 @@
#include "vty.h"
#include "prefix.h"
#include "linklist.h"
-#include "thread.h"
+#include "frrevent.h"
#include "lib_errors.h"
#include "ospf6_lsa.h"
@@ -590,7 +590,7 @@ static void ospf6_spf_log_database(struct ospf6_area *oa)
zlog_debug("%s", buffer);
}
-static void ospf6_spf_calculation_thread(struct thread *t)
+static void ospf6_spf_calculation_thread(struct event *t)
{
struct ospf6_area *oa;
struct ospf6 *ospf6;
@@ -599,7 +599,7 @@ static void ospf6_spf_calculation_thread(struct thread *t)
int areas_processed = 0;
char rbuf[32];
- ospf6 = (struct ospf6 *)THREAD_ARG(t);
+ ospf6 = (struct ospf6 *)EVENT_ARG(t);
/* execute SPF calculation */
monotime(&start);
@@ -687,7 +687,7 @@ void ospf6_spf_schedule(struct ospf6 *ospf6, unsigned int reason)
}
/* SPF calculation timer is already scheduled. */
- if (thread_is_scheduled(ospf6->t_spf_calc)) {
+ if (event_is_scheduled(ospf6->t_spf_calc)) {
if (IS_OSPF6_DEBUG_SPF(PROCESS) || IS_OSPF6_DEBUG_SPF(TIME))
zlog_debug(
"SPF: calculation timer is already scheduled: %p",
@@ -724,9 +724,9 @@ void ospf6_spf_schedule(struct ospf6 *ospf6, unsigned int reason)
if (IS_OSPF6_DEBUG_SPF(PROCESS) || IS_OSPF6_DEBUG_SPF(TIME))
zlog_debug("SPF: Rescheduling in %ld msec", delay);
- THREAD_OFF(ospf6->t_spf_calc);
- thread_add_timer_msec(master, ospf6_spf_calculation_thread, ospf6,
- delay, &ospf6->t_spf_calc);
+ EVENT_OFF(ospf6->t_spf_calc);
+ event_add_timer_msec(master, ospf6_spf_calculation_thread, ospf6, delay,
+ &ospf6->t_spf_calc);
}
void ospf6_spf_display_subtree(struct vty *vty, const char *prefix, int rest,
@@ -1228,7 +1228,7 @@ int ospf6_ase_calculate_route(struct ospf6 *ospf6, struct ospf6_lsa *lsa,
return 0;
}
-static void ospf6_ase_calculate_timer(struct thread *t)
+static void ospf6_ase_calculate_timer(struct event *t)
{
struct ospf6 *ospf6;
struct ospf6_lsa *lsa;
@@ -1236,7 +1236,7 @@ static void ospf6_ase_calculate_timer(struct thread *t)
struct ospf6_area *area;
uint16_t type;
- ospf6 = THREAD_ARG(t);
+ ospf6 = EVENT_ARG(t);
/* Calculate external route for each AS-external-LSA */
type = htons(OSPF6_LSTYPE_AS_EXTERNAL);
@@ -1272,6 +1272,6 @@ void ospf6_ase_calculate_timer_add(struct ospf6 *ospf6)
if (ospf6 == NULL)
return;
- thread_add_timer(master, ospf6_ase_calculate_timer, ospf6,
- OSPF6_ASE_CALC_INTERVAL, &ospf6->t_ase_calc);
+ event_add_timer(master, ospf6_ase_calculate_timer, ospf6,
+ OSPF6_ASE_CALC_INTERVAL, &ospf6->t_ase_calc);
}
diff --git a/ospf6d/ospf6_top.c b/ospf6d/ospf6_top.c
index bd5aedb45e..c2aa3abeed 100644
--- a/ospf6d/ospf6_top.c
+++ b/ospf6d/ospf6_top.c
@@ -11,7 +11,7 @@
#include "linklist.h"
#include "prefix.h"
#include "table.h"
-#include "thread.h"
+#include "frrevent.h"
#include "command.h"
#include "defaults.h"
#include "lib/json.h"
@@ -176,7 +176,7 @@ static int ospf6_vrf_disable(struct vrf *vrf)
* from VRF and make it "down".
*/
ospf6_vrf_unlink(ospf6, vrf);
- thread_cancel(&ospf6->t_ospf6_receive);
+ event_cancel(&ospf6->t_ospf6_receive);
close(ospf6->fd);
ospf6->fd = -1;
}
@@ -207,8 +207,8 @@ static int ospf6_vrf_enable(struct vrf *vrf)
ret = ospf6_serv_sock(ospf6);
if (ret < 0 || ospf6->fd <= 0)
return 0;
- thread_add_read(master, ospf6_receive, ospf6, ospf6->fd,
- &ospf6->t_ospf6_receive);
+ event_add_read(master, ospf6_receive, ospf6, ospf6->fd,
+ &ospf6->t_ospf6_receive);
ospf6_router_id_update(ospf6, true);
}
@@ -471,8 +471,8 @@ struct ospf6 *ospf6_instance_create(const char *name)
*/
ospf6_gr_nvm_read(ospf6);
- thread_add_read(master, ospf6_receive, ospf6, ospf6->fd,
- &ospf6->t_ospf6_receive);
+ event_add_read(master, ospf6_receive, ospf6, ospf6->fd,
+ &ospf6->t_ospf6_receive);
return ospf6;
}
@@ -552,19 +552,19 @@ static void ospf6_disable(struct ospf6 *o)
ospf6_route_remove_all(o->route_table);
ospf6_route_remove_all(o->brouter_table);
- THREAD_OFF(o->maxage_remover);
- THREAD_OFF(o->t_spf_calc);
- THREAD_OFF(o->t_ase_calc);
- THREAD_OFF(o->t_distribute_update);
- THREAD_OFF(o->t_ospf6_receive);
- THREAD_OFF(o->t_external_aggr);
- THREAD_OFF(o->gr_info.t_grace_period);
- THREAD_OFF(o->t_write);
- THREAD_OFF(o->t_abr_task);
+ EVENT_OFF(o->maxage_remover);
+ EVENT_OFF(o->t_spf_calc);
+ EVENT_OFF(o->t_ase_calc);
+ EVENT_OFF(o->t_distribute_update);
+ EVENT_OFF(o->t_ospf6_receive);
+ EVENT_OFF(o->t_external_aggr);
+ EVENT_OFF(o->gr_info.t_grace_period);
+ EVENT_OFF(o->t_write);
+ EVENT_OFF(o->t_abr_task);
}
}
-void ospf6_master_init(struct thread_master *master)
+void ospf6_master_init(struct event_loop *master)
{
memset(&ospf6_master, 0, sizeof(ospf6_master));
@@ -573,9 +573,9 @@ void ospf6_master_init(struct thread_master *master)
om6->master = master;
}
-static void ospf6_maxage_remover(struct thread *thread)
+static void ospf6_maxage_remover(struct event *thread)
{
- struct ospf6 *o = (struct ospf6 *)THREAD_ARG(thread);
+ struct ospf6 *o = (struct ospf6 *)EVENT_ARG(thread);
struct ospf6_area *oa;
struct ospf6_interface *oi;
struct ospf6_neighbor *on;
@@ -619,9 +619,9 @@ static void ospf6_maxage_remover(struct thread *thread)
void ospf6_maxage_remove(struct ospf6 *o)
{
if (o)
- thread_add_timer(master, ospf6_maxage_remover, o,
- OSPF_LSA_MAXAGE_REMOVE_DELAY_DEFAULT,
- &o->maxage_remover);
+ event_add_timer(master, ospf6_maxage_remover, o,
+ OSPF_LSA_MAXAGE_REMOVE_DELAY_DEFAULT,
+ &o->maxage_remover);
}
bool ospf6_router_id_update(struct ospf6 *ospf6, bool init)
@@ -1359,7 +1359,7 @@ static void ospf6_show(struct vty *vty, struct ospf6 *o, json_object *json,
} else
json_object_boolean_false_add(json, "spfHasRun");
- if (thread_is_scheduled(o->t_spf_calc)) {
+ if (event_is_scheduled(o->t_spf_calc)) {
long time_store;
json_object_boolean_true_add(json, "spfTimerActive");
@@ -1452,8 +1452,7 @@ static void ospf6_show(struct vty *vty, struct ospf6 *o, json_object *json,
threadtimer_string(now, o->t_spf_calc, buf, sizeof(buf));
vty_out(vty, " SPF timer %s%s\n",
- (thread_is_scheduled(o->t_spf_calc) ? "due in "
- : "is "),
+ (event_is_scheduled(o->t_spf_calc) ? "due in " : "is "),
buf);
if (CHECK_FLAG(o->flag, OSPF6_STUB_ROUTER))
diff --git a/ospf6d/ospf6_top.h b/ospf6d/ospf6_top.h
index 08595a69d0..8fdd291122 100644
--- a/ospf6d/ospf6_top.h
+++ b/ospf6d/ospf6_top.h
@@ -13,7 +13,7 @@ struct ospf6_master {
/* OSPFv3 instance. */
struct list *ospf6;
/* OSPFv3 thread master. */
- struct thread_master *master;
+ struct event_loop *master;
};
/* ospf6->config_flags */
@@ -51,7 +51,7 @@ struct ospf6_gr_info {
bool prepare_in_progress;
bool finishing_restart;
uint32_t grace_period;
- struct thread *t_grace_period;
+ struct event *t_grace_period;
};
struct ospf6_gr_helper {
@@ -168,14 +168,14 @@ struct ospf6 {
int fd;
/* Threads */
- struct thread *t_spf_calc; /* SPF calculation timer. */
- struct thread *t_ase_calc; /* ASE calculation timer. */
- struct thread *maxage_remover;
- struct thread *t_distribute_update; /* Distirbute update timer. */
- struct thread *t_ospf6_receive; /* OSPF6 receive timer */
- struct thread *t_external_aggr; /* OSPF6 aggregation timer */
+ struct event *t_spf_calc; /* SPF calculation timer. */
+ struct event *t_ase_calc; /* ASE calculation timer. */
+ struct event *maxage_remover;
+ struct event *t_distribute_update; /* Distirbute update timer. */
+ struct event *t_ospf6_receive; /* OSPF6 receive timer */
+ struct event *t_external_aggr; /* OSPF6 aggregation timer */
#define OSPF6_WRITE_INTERFACE_COUNT_DEFAULT 20
- struct thread *t_write;
+ struct event *t_write;
int write_oi_count; /* Num of packets sent per thread invocation */
uint32_t ref_bandwidth;
@@ -205,7 +205,7 @@ struct ospf6 {
/* Count of NSSA areas */
uint8_t anyNSSA;
- struct thread *t_abr_task; /* ABR task timer. */
+ struct event *t_abr_task; /* ABR task timer. */
struct list *oi_write_q;
uint32_t redist_count;
@@ -233,7 +233,7 @@ extern struct ospf6 *ospf6;
extern struct ospf6_master *om6;
/* prototypes */
-extern void ospf6_master_init(struct thread_master *master);
+extern void ospf6_master_init(struct event_loop *master);
extern void install_element_ospf6_clear_process(void);
extern void ospf6_top_init(void);
extern void ospf6_delete(struct ospf6 *o);
diff --git a/ospf6d/ospf6_zebra.c b/ospf6d/ospf6_zebra.c
index 0ccbb4d65d..6b3d4955da 100644
--- a/ospf6d/ospf6_zebra.c
+++ b/ospf6d/ospf6_zebra.c
@@ -750,7 +750,7 @@ static zclient_handler *const ospf6_handlers[] = {
[ZEBRA_NEXTHOP_UPDATE] = ospf6_zebra_import_check_update,
};
-void ospf6_zebra_init(struct thread_master *master)
+void ospf6_zebra_init(struct event_loop *master)
{
/* Allocate zebra structure. */
zclient = zclient_new(master, &zclient_options_default, ospf6_handlers,
diff --git a/ospf6d/ospf6_zebra.h b/ospf6d/ospf6_zebra.h
index eb6d919b37..9f41dfca9a 100644
--- a/ospf6d/ospf6_zebra.h
+++ b/ospf6d/ospf6_zebra.h
@@ -39,7 +39,7 @@ extern void ospf6_zebra_redistribute(int, vrf_id_t vrf_id);
extern void ospf6_zebra_no_redistribute(int, vrf_id_t vrf_id);
#define ospf6_zebra_is_redistribute(type, vrf_id) \
vrf_bitmap_check(zclient->redist[AFI_IP6][type], vrf_id)
-extern void ospf6_zebra_init(struct thread_master *tm);
+extern void ospf6_zebra_init(struct event_loop *tm);
extern void ospf6_zebra_import_default_route(struct ospf6 *ospf6, bool unreg);
extern void ospf6_zebra_add_discard(struct ospf6_route *request,
struct ospf6 *ospf6);
diff --git a/ospf6d/ospf6d.c b/ospf6d/ospf6d.c
index 257a0f2b0e..214007d041 100644
--- a/ospf6d/ospf6d.c
+++ b/ospf6d/ospf6d.c
@@ -5,7 +5,7 @@
#include <zebra.h>
-#include "thread.h"
+#include "frrevent.h"
#include "linklist.h"
#include "vty.h"
#include "command.h"
@@ -1375,7 +1375,7 @@ DEFUN(show_ipv6_ospf6_linkstate_detail, show_ipv6_ospf6_linkstate_detail_cmd,
}
/* Install ospf related commands. */
-void ospf6_init(struct thread_master *master)
+void ospf6_init(struct event_loop *master)
{
ospf6_top_init();
ospf6_area_init();
diff --git a/ospf6d/ospf6d.h b/ospf6d/ospf6d.h
index 234a0e881d..980a365265 100644
--- a/ospf6d/ospf6d.h
+++ b/ospf6d/ospf6d.h
@@ -7,13 +7,13 @@
#define OSPF6D_H
#include "libospf.h"
-#include "thread.h"
+#include "frrevent.h"
#include "memory.h"
DECLARE_MGROUP(OSPF6D);
/* global variables */
-extern struct thread_master *master;
+extern struct event_loop *master;
/* Historical for KAME. */
#ifndef IPV6_JOIN_GROUP
@@ -109,6 +109,6 @@ extern struct zebra_privs_t ospf6d_privs;
extern struct route_node *route_prev(struct route_node *node);
extern void ospf6_debug(void);
-extern void ospf6_init(struct thread_master *master);
+extern void ospf6_init(struct event_loop *master);
#endif /* OSPF6D_H */
diff --git a/ospfclient/ospf_apiclient.c b/ospfclient/ospf_apiclient.c
index c5bbc01501..a1193001fa 100644
--- a/ospfclient/ospf_apiclient.c
+++ b/ospfclient/ospf_apiclient.c
@@ -8,7 +8,7 @@
#include <lib/version.h>
#include "getopt.h"
-#include "thread.h"
+#include "frrevent.h"
#include "prefix.h"
#include "linklist.h"
#include "if.h"
diff --git a/ospfclient/ospfclient.c b/ospfclient/ospfclient.c
index cbc53ad353..24ff08561d 100644
--- a/ospfclient/ospfclient.c
+++ b/ospfclient/ospfclient.c
@@ -43,7 +43,7 @@ struct zebra_privs_t ospfd_privs = {.user = NULL,
free to use any thread library (like pthreads). */
#include "ospfd/ospf_dump.h" /* for ospf_lsa_header_dump */
-#include "thread.h"
+#include "frrevent.h"
#include "log.h"
/* Local portnumber for async channel. Note that OSPF API library will also
@@ -51,7 +51,7 @@ struct zebra_privs_t ospfd_privs = {.user = NULL,
#define ASYNCPORT 4000
/* Master thread */
-struct thread_master *master;
+struct event_loop *master;
/* Global variables */
struct ospf_apiclient *oclient;
@@ -69,13 +69,13 @@ struct my_opaque_lsa {
* ---------------------------------------------------------
*/
-static void lsa_delete(struct thread *t)
+static void lsa_delete(struct event *t)
{
struct ospf_apiclient *oclient;
struct in_addr area_id;
int rc;
- oclient = THREAD_ARG(t);
+ oclient = EVENT_ARG(t);
rc = inet_aton(args[6], &area_id);
if (rc <= 0) {
@@ -92,7 +92,7 @@ static void lsa_delete(struct thread *t)
printf("done, return code is = %d\n", rc);
}
-static void lsa_inject(struct thread *t)
+static void lsa_inject(struct event *t)
{
struct ospf_apiclient *cl;
struct in_addr ifaddr;
@@ -106,7 +106,7 @@ static void lsa_inject(struct thread *t)
static uint32_t counter = 1; /* Incremented each time invoked */
int rc;
- cl = THREAD_ARG(t);
+ cl = EVENT_ARG(t);
rc = inet_aton(args[5], &ifaddr);
if (rc <= 0) {
@@ -138,7 +138,7 @@ static void lsa_inject(struct thread *t)
/* This thread handles asynchronous messages coming in from the OSPF
API server */
-static void lsa_read(struct thread *thread)
+static void lsa_read(struct event *thread)
{
struct ospf_apiclient *oclient;
int fd;
@@ -146,8 +146,8 @@ static void lsa_read(struct thread *thread)
printf("lsa_read called\n");
- oclient = THREAD_ARG(thread);
- fd = THREAD_FD(thread);
+ oclient = EVENT_ARG(thread);
+ fd = EVENT_FD(thread);
/* Handle asynchronous message */
ret = ospf_apiclient_handle_async(oclient);
@@ -157,7 +157,7 @@ static void lsa_read(struct thread *thread)
}
/* Reschedule read thread */
- thread_add_read(master, lsa_read, oclient, fd, NULL);
+ event_add_read(master, lsa_read, oclient, fd, NULL);
}
/* ---------------------------------------------------------
@@ -209,13 +209,13 @@ static void ready_callback(uint8_t lsa_type, uint8_t opaque_type,
lsa_type, opaque_type, &addr);
/* Schedule opaque LSA originate in 5 secs */
- thread_add_timer(master, lsa_inject, oclient, 5, NULL);
+ event_add_timer(master, lsa_inject, oclient, 5, NULL);
/* Schedule opaque LSA update with new value */
- thread_add_timer(master, lsa_inject, oclient, 10, NULL);
+ event_add_timer(master, lsa_inject, oclient, 10, NULL);
/* Schedule delete */
- thread_add_timer(master, lsa_delete, oclient, 30, NULL);
+ event_add_timer(master, lsa_delete, oclient, 30, NULL);
}
static void new_if_callback(struct in_addr ifaddr, struct in_addr area_id)
@@ -269,7 +269,7 @@ static int usage(void)
int main(int argc, char *argv[])
{
- struct thread thread;
+ struct event thread;
args = argv;
@@ -293,7 +293,7 @@ int main(int argc, char *argv[])
/* Initialization */
zprivs_preinit(&ospfd_privs);
zprivs_init(&ospfd_privs);
- master = thread_master_create(NULL);
+ master = event_master_create(NULL);
/* Open connection to OSPF daemon */
oclient = ospf_apiclient_connect(args[1], ASYNCPORT);
@@ -316,12 +316,12 @@ int main(int argc, char *argv[])
ospf_apiclient_sync_lsdb(oclient);
/* Schedule thread that handles asynchronous messages */
- thread_add_read(master, lsa_read, oclient, oclient->fd_async, NULL);
+ event_add_read(master, lsa_read, oclient, oclient->fd_async, NULL);
/* Now connection is established, run loop */
while (1) {
- thread_fetch(master, &thread);
- thread_call(&thread);
+ event_fetch(master, &thread);
+ event_call(&thread);
}
/* Never reached */
diff --git a/ospfd/ospf_abr.c b/ospfd/ospf_abr.c
index 8f177cbce1..ded520889f 100644
--- a/ospfd/ospf_abr.c
+++ b/ospfd/ospf_abr.c
@@ -7,7 +7,7 @@
#include <zebra.h>
-#include "thread.h"
+#include "frrevent.h"
#include "memory.h"
#include "linklist.h"
#include "prefix.h"
@@ -54,6 +54,7 @@ static void ospf_area_range_free(struct ospf_area_range *range)
}
static void ospf_area_range_add(struct ospf_area *area,
+ struct route_table *ranges,
struct ospf_area_range *range)
{
struct route_node *rn;
@@ -64,7 +65,7 @@ static void ospf_area_range_add(struct ospf_area *area,
p.prefix = range->addr;
apply_mask_ipv4(&p);
- rn = route_node_get(area->ranges, (struct prefix *)&p);
+ rn = route_node_get(ranges, (struct prefix *)&p);
if (rn->info)
route_unlock_node(rn);
else
@@ -75,10 +76,12 @@ static void ospf_area_range_delete(struct ospf_area *area,
struct route_node *rn)
{
struct ospf_area_range *range = rn->info;
+ bool nssa = CHECK_FLAG(range->flags, OSPF_AREA_RANGE_NSSA);
- if (range->specifics != 0)
+ if (ospf_area_range_active(range) &&
+ CHECK_FLAG(range->flags, OSPF_AREA_RANGE_ADVERTISE))
ospf_delete_discard_route(area->ospf, area->ospf->new_table,
- (struct prefix_ipv4 *)&rn->p);
+ (struct prefix_ipv4 *)&rn->p, nssa);
ospf_area_range_free(range);
rn->info = NULL;
@@ -87,11 +90,12 @@ static void ospf_area_range_delete(struct ospf_area *area,
}
struct ospf_area_range *ospf_area_range_lookup(struct ospf_area *area,
+ struct route_table *ranges,
struct prefix_ipv4 *p)
{
struct route_node *rn;
- rn = route_node_lookup(area->ranges, (struct prefix *)p);
+ rn = route_node_lookup(ranges, (struct prefix *)p);
if (rn) {
route_unlock_node(rn);
return rn->info;
@@ -133,11 +137,12 @@ struct ospf_area_range *ospf_area_range_lookup_next(struct ospf_area *area,
}
static struct ospf_area_range *ospf_area_range_match(struct ospf_area *area,
+ struct route_table *ranges,
struct prefix_ipv4 *p)
{
struct route_node *node;
- node = route_node_match(area->ranges, (struct prefix *)p);
+ node = route_node_match(ranges, (struct prefix *)p);
if (node) {
route_unlock_node(node);
return node->info;
@@ -153,7 +158,7 @@ struct ospf_area_range *ospf_area_range_match_any(struct ospf *ospf,
struct listnode *node;
for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area))
- if ((range = ospf_area_range_match(area, p)))
+ if ((range = ospf_area_range_match(area, area->ranges, p)))
return range;
return NULL;
@@ -169,17 +174,13 @@ static int ospf_area_actively_attached(struct ospf_area *area)
return area->act_ints;
}
-int ospf_area_range_set(struct ospf *ospf, struct in_addr area_id,
- struct prefix_ipv4 *p, int advertise)
+int ospf_area_range_set(struct ospf *ospf, struct ospf_area *area,
+ struct route_table *ranges, struct prefix_ipv4 *p,
+ int advertise, bool nssa)
{
- struct ospf_area *area;
struct ospf_area_range *range;
- area = ospf_area_get(ospf, area_id);
- if (area == NULL)
- return 0;
-
- range = ospf_area_range_lookup(area, p);
+ range = ospf_area_range_lookup(area, ranges, p);
if (range != NULL) {
if (!CHECK_FLAG(advertise, OSPF_AREA_RANGE_ADVERTISE))
range->cost_config = OSPF_AREA_RANGE_COST_UNSPEC;
@@ -190,7 +191,7 @@ int ospf_area_range_set(struct ospf *ospf, struct in_addr area_id,
ospf_schedule_abr_task(ospf);
} else {
range = ospf_area_range_new(p);
- ospf_area_range_add(area, range);
+ ospf_area_range_add(area, ranges, range);
ospf_schedule_abr_task(ospf);
}
@@ -201,20 +202,19 @@ int ospf_area_range_set(struct ospf *ospf, struct in_addr area_id,
range->cost_config = OSPF_AREA_RANGE_COST_UNSPEC;
}
+ if (nssa)
+ SET_FLAG(range->flags, OSPF_AREA_RANGE_NSSA);
+
return 1;
}
-int ospf_area_range_cost_set(struct ospf *ospf, struct in_addr area_id,
- struct prefix_ipv4 *p, uint32_t cost)
+int ospf_area_range_cost_set(struct ospf *ospf, struct ospf_area *area,
+ struct route_table *ranges, struct prefix_ipv4 *p,
+ uint32_t cost)
{
- struct ospf_area *area;
struct ospf_area_range *range;
- area = ospf_area_get(ospf, area_id);
- if (area == NULL)
- return 0;
-
- range = ospf_area_range_lookup(area, p);
+ range = ospf_area_range_lookup(area, ranges, p);
if (range == NULL)
return 0;
@@ -227,17 +227,12 @@ int ospf_area_range_cost_set(struct ospf *ospf, struct in_addr area_id,
return 1;
}
-int ospf_area_range_unset(struct ospf *ospf, struct in_addr area_id,
- struct prefix_ipv4 *p)
+int ospf_area_range_unset(struct ospf *ospf, struct ospf_area *area,
+ struct route_table *ranges, struct prefix_ipv4 *p)
{
- struct ospf_area *area;
struct route_node *rn;
- area = ospf_area_lookup_by_area_id(ospf, area_id);
- if (area == NULL)
- return 0;
-
- rn = route_node_lookup(area->ranges, (struct prefix *)p);
+ rn = route_node_lookup(ranges, (struct prefix *)p);
if (rn == NULL)
return 0;
@@ -249,14 +244,12 @@ int ospf_area_range_unset(struct ospf *ospf, struct in_addr area_id,
return 1;
}
-int ospf_area_range_substitute_set(struct ospf *ospf, struct in_addr area_id,
+int ospf_area_range_substitute_set(struct ospf *ospf, struct ospf_area *area,
struct prefix_ipv4 *p, struct prefix_ipv4 *s)
{
- struct ospf_area *area;
struct ospf_area_range *range;
- area = ospf_area_get(ospf, area_id);
- range = ospf_area_range_lookup(area, p);
+ range = ospf_area_range_lookup(area, area->ranges, p);
if (range != NULL) {
if (!CHECK_FLAG(range->flags, OSPF_AREA_RANGE_ADVERTISE)
@@ -264,7 +257,7 @@ int ospf_area_range_substitute_set(struct ospf *ospf, struct in_addr area_id,
ospf_schedule_abr_task(ospf);
} else {
range = ospf_area_range_new(p);
- ospf_area_range_add(area, range);
+ ospf_area_range_add(area, area->ranges, range);
ospf_schedule_abr_task(ospf);
}
@@ -276,17 +269,12 @@ int ospf_area_range_substitute_set(struct ospf *ospf, struct in_addr area_id,
return 1;
}
-int ospf_area_range_substitute_unset(struct ospf *ospf, struct in_addr area_id,
+int ospf_area_range_substitute_unset(struct ospf *ospf, struct ospf_area *area,
struct prefix_ipv4 *p)
{
- struct ospf_area *area;
struct ospf_area_range *range;
- area = ospf_area_lookup_by_area_id(ospf, area_id);
- if (area == NULL)
- return 0;
-
- range = ospf_area_range_lookup(area, p);
+ range = ospf_area_range_lookup(area, area->ranges, p);
if (range == NULL)
return 0;
@@ -538,8 +526,7 @@ void ospf_check_abr_status(struct ospf *ospf)
}
static void ospf_abr_update_aggregate(struct ospf_area_range *range,
- struct ospf_route * or,
- struct ospf_area *area)
+ uint32_t cost, struct ospf_area *area)
{
if (IS_DEBUG_OSPF_EVENT)
zlog_debug("%s: Start", __func__);
@@ -557,20 +544,18 @@ static void ospf_abr_update_aggregate(struct ospf_area_range *range,
range->cost = range->cost_config;
} else {
- if (range->specifics == 0) {
+ if (!ospf_area_range_active(range)) {
if (IS_DEBUG_OSPF_EVENT)
- zlog_debug("%s: use or->cost %d", __func__,
- or->cost);
+ zlog_debug("%s: use cost %d", __func__, cost);
- range->cost = or->cost; /* 1st time get 1st cost */
+ range->cost = cost; /* 1st time get 1st cost */
}
- if (or->cost > range->cost) {
+ if (cost > range->cost) {
if (IS_DEBUG_OSPF_EVENT)
- zlog_debug("%s: update to %d", __func__,
- or->cost);
+ zlog_debug("%s: update to %d", __func__, cost);
- range->cost = or->cost;
+ range->cost = cost;
}
}
@@ -605,6 +590,7 @@ static int ospf_abr_translate_nssa(struct ospf_area *area, struct ospf_lsa *lsa)
struct ospf_lsa *old = NULL, *new = NULL;
struct as_external_lsa *ext7;
struct prefix_ipv4 p;
+ struct ospf_area_range *range;
if (!CHECK_FLAG(lsa->data->options, OSPF_OPTION_NP)) {
if (IS_DEBUG_OSPF_NSSA)
@@ -646,6 +632,18 @@ static int ospf_abr_translate_nssa(struct ospf_area *area, struct ospf_lsa *lsa)
return 1;
}
+ range = ospf_area_range_match(area, area->nssa_ranges, &p);
+ if (range) {
+ if (IS_DEBUG_OSPF_NSSA)
+ zlog_debug("Suppressed by range %pI4/%u of area %pI4",
+ &range->addr, range->masklen,
+ &area->area_id);
+
+ ospf_abr_update_aggregate(range, GET_METRIC(ext7->e[0].metric),
+ area);
+ return 1;
+ }
+
if (old && CHECK_FLAG(old->flags, OSPF_LSA_APPROVED)) {
if (IS_DEBUG_OSPF_NSSA)
zlog_debug(
@@ -675,17 +673,27 @@ static int ospf_abr_translate_nssa(struct ospf_area *area, struct ospf_lsa *lsa)
}
}
- /* Area where Aggregate testing will be inserted, just like summary
- advertisements */
- /* ospf_abr_check_nssa_range (p_arg, lsa-> cost, lsa -> area); */
-
return 0;
}
-static void ospf_abr_translate_nssa_range(struct prefix_ipv4 *p, uint32_t cost)
+static void ospf_abr_translate_nssa_range(struct ospf *ospf,
+ struct prefix_ipv4 *p, uint32_t cost)
{
- /* The Type-7 is created from the aggregated prefix and forwarded
- for lsa installation and flooding... to be added... */
+ struct external_info ei = {};
+ struct ospf_lsa *lsa;
+
+ prefix_copy(&ei.p, p);
+ ei.type = ZEBRA_ROUTE_OSPF;
+ ei.route_map_set.metric = cost;
+ ei.route_map_set.metric_type = -1;
+
+ lsa = ospf_external_info_find_lsa(ospf, p);
+ if (lsa)
+ lsa = ospf_external_lsa_refresh(ospf, lsa, &ei,
+ LSA_REFRESH_FORCE, true);
+ else
+ lsa = ospf_external_lsa_originate(ospf, &ei);
+ SET_FLAG(lsa->flags, OSPF_LSA_LOCAL_XLT);
}
void ospf_abr_announce_network_to_area(struct prefix_ipv4 *p, uint32_t cost,
@@ -892,9 +900,11 @@ static void ospf_abr_announce_network(struct ospf *ospf, struct prefix_ipv4 *p,
zlog_debug(
"%s: this is intra-area route to %pFX",
__func__, p);
- if ((range = ospf_area_range_match(or_area, p))
- && !ospf_area_is_transit(area))
- ospf_abr_update_aggregate(range, or, area);
+ if ((range = ospf_area_range_match(
+ or_area, or_area->ranges, p)) &&
+ !ospf_area_is_transit(area))
+ ospf_abr_update_aggregate(range, or->cost,
+ area);
else
ospf_abr_announce_network_to_area(p, or->cost,
area);
@@ -1345,7 +1355,7 @@ static void ospf_abr_unapprove_summaries(struct ospf *ospf)
zlog_debug("%s: Stop", __func__);
}
-static void ospf_abr_prepare_aggregates(struct ospf *ospf)
+static void ospf_abr_prepare_aggregates(struct ospf *ospf, bool nssa)
{
struct listnode *node;
struct route_node *rn;
@@ -1356,7 +1366,14 @@ static void ospf_abr_prepare_aggregates(struct ospf *ospf)
zlog_debug("%s: Start", __func__);
for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) {
- for (rn = route_top(area->ranges); rn; rn = route_next(rn))
+ struct route_table *ranges;
+
+ if (nssa)
+ ranges = area->nssa_ranges;
+ else
+ ranges = area->ranges;
+
+ for (rn = route_top(ranges); rn; rn = route_next(rn))
if ((range = rn->info) != NULL) {
range->cost = 0;
range->specifics = 0;
@@ -1409,7 +1426,7 @@ static void ospf_abr_announce_aggregates(struct ospf *ospf)
p.prefixlen = range->subst_masklen;
}
- if (range->specifics) {
+ if (ospf_area_range_active(range)) {
if (IS_DEBUG_OSPF_EVENT)
zlog_debug("%s: active range",
__func__);
@@ -1452,13 +1469,11 @@ static void ospf_abr_announce_aggregates(struct ospf *ospf)
zlog_debug("%s: Stop", __func__);
}
-static void
-ospf_abr_send_nssa_aggregates(struct ospf *ospf) /* temporarily turned off */
+static void ospf_abr_send_nssa_aggregates(struct ospf *ospf)
{
- struct listnode *node; /*, n; */
- struct ospf_area *area; /*, *ar; */
+ struct listnode *node;
+ struct ospf_area *area;
struct route_node *rn;
- struct ospf_area_range *range;
struct prefix_ipv4 p;
if (IS_DEBUG_OSPF_NSSA)
@@ -1472,20 +1487,13 @@ ospf_abr_send_nssa_aggregates(struct ospf *ospf) /* temporarily turned off */
zlog_debug("%s: looking at area %pI4", __func__,
&area->area_id);
- for (rn = route_top(area->ranges); rn; rn = route_next(rn)) {
- if (rn->info == NULL)
- continue;
+ for (rn = route_top(area->nssa_ranges); rn;
+ rn = route_next(rn)) {
+ struct ospf_area_range *range;
range = rn->info;
-
- if (!CHECK_FLAG(range->flags,
- OSPF_AREA_RANGE_ADVERTISE)) {
- if (IS_DEBUG_OSPF_NSSA)
- zlog_debug(
- "%s: discarding suppress-ranges",
- __func__);
+ if (!range)
continue;
- }
p.family = AF_INET;
p.prefix = range->addr;
@@ -1495,14 +1503,9 @@ ospf_abr_send_nssa_aggregates(struct ospf *ospf) /* temporarily turned off */
zlog_debug("%s: this is range: %pFX", __func__,
&p);
- if (CHECK_FLAG(range->flags,
- OSPF_AREA_RANGE_SUBSTITUTE)) {
- p.family = AF_INET;
- p.prefix = range->subst_addr;
- p.prefixlen = range->subst_masklen;
- }
-
- if (range->specifics) {
+ if (ospf_area_range_active(range)
+ && CHECK_FLAG(range->flags,
+ OSPF_AREA_RANGE_ADVERTISE)) {
if (IS_DEBUG_OSPF_NSSA)
zlog_debug("%s: active range",
__func__);
@@ -1512,7 +1515,8 @@ ospf_abr_send_nssa_aggregates(struct ospf *ospf) /* temporarily turned off */
* translate, Install (as Type-5), Approve, and
* Flood
*/
- ospf_abr_translate_nssa_range(&p, range->cost);
+ ospf_abr_translate_nssa_range(ospf, &p,
+ range->cost);
}
} /* all area ranges*/
} /* all areas */
@@ -1727,13 +1731,13 @@ bool ospf_check_fr_enabled_all(struct ospf *ospf)
* @param thread
* @return 0.
*/
-static void ospf_abr_announce_non_dna_routers(struct thread *thread)
+static void ospf_abr_announce_non_dna_routers(struct event *thread)
{
struct ospf_area *area;
struct listnode *node;
- struct ospf *ospf = THREAD_ARG(thread);
+ struct ospf *ospf = EVENT_ARG(thread);
- THREAD_OFF(ospf->t_abr_fr);
+ EVENT_OFF(ospf->t_abr_fr);
if (!IS_OSPF_ABR(ospf))
return;
@@ -1807,6 +1811,82 @@ static void ospf_abr_announce_non_dna_routers(struct thread *thread)
OSPF_LOG_DEBUG(IS_DEBUG_OSPF_EVENT, "%s(): Stop", __func__);
}
+static void ospf_abr_nssa_type7_default_create(struct ospf *ospf,
+ struct ospf_area *area,
+ struct ospf_lsa *lsa)
+{
+ struct external_info ei;
+
+ if (IS_DEBUG_OSPF_NSSA)
+ zlog_debug(
+ "Announcing Type-7 default route into NSSA area %pI4",
+ &area->area_id);
+
+ /* Prepare the extrenal_info for aggregator */
+ memset(&ei, 0, sizeof(struct external_info));
+ ei.p.family = AF_INET;
+ ei.p.prefixlen = 0;
+ ei.tag = 0;
+ ei.type = 0;
+ ei.instance = ospf->instance;
+
+ /* Compute default route type and metric. */
+ if (area->nssa_default_originate.metric_value != -1)
+ ei.route_map_set.metric =
+ area->nssa_default_originate.metric_value;
+ else
+ ei.route_map_set.metric = DEFAULT_DEFAULT_ALWAYS_METRIC;
+ if (area->nssa_default_originate.metric_type != -1)
+ ei.route_map_set.metric_type =
+ area->nssa_default_originate.metric_type;
+ else
+ ei.route_map_set.metric_type = DEFAULT_METRIC_TYPE;
+
+ if (!lsa)
+ ospf_nssa_lsa_originate(area, &ei);
+ else
+ ospf_nssa_lsa_refresh(area, lsa, &ei);
+}
+
+static void ospf_abr_nssa_type7_default_delete(struct ospf *ospf,
+ struct ospf_area *area,
+ struct ospf_lsa *lsa)
+{
+ if (lsa && !CHECK_FLAG(lsa->flags, OSPF_LSA_IN_MAXAGE)) {
+ if (IS_DEBUG_OSPF_NSSA)
+ zlog_debug(
+ "Withdrawing Type-7 default route from area %pI4",
+ &area->area_id);
+
+ ospf_ls_retransmit_delete_nbr_area(area, lsa);
+ ospf_refresher_unregister_lsa(ospf, lsa);
+ ospf_lsa_flush_area(lsa, area);
+ }
+}
+
+/* NSSA Type-7 default route. */
+void ospf_abr_nssa_type7_defaults(struct ospf *ospf)
+{
+ struct ospf_area *area;
+ struct listnode *node;
+
+ for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) {
+ struct in_addr id = {};
+ struct ospf_lsa *lsa;
+
+ lsa = ospf_lsdb_lookup_by_id(area->lsdb, OSPF_AS_NSSA_LSA, id,
+ area->ospf->router_id);
+ if (area->external_routing == OSPF_AREA_NSSA
+ && area->nssa_default_originate.enabled
+ && (IS_OSPF_ABR(ospf)
+ || (IS_OSPF_ASBR(ospf)
+ && ospf->nssa_default_import_check.status)))
+ ospf_abr_nssa_type7_default_create(ospf, area, lsa);
+ else
+ ospf_abr_nssa_type7_default_delete(ospf, area, lsa);
+ }
+}
+
static int ospf_abr_remove_unapproved_translates_apply(struct ospf *ospf,
struct ospf_lsa *lsa)
{
@@ -1874,30 +1954,39 @@ static void ospf_abr_remove_unapproved_summaries(struct ospf *ospf)
zlog_debug("%s: Stop", __func__);
}
-static void ospf_abr_manage_discard_routes(struct ospf *ospf)
+static void ospf_abr_manage_discard_routes(struct ospf *ospf, bool nssa)
{
struct listnode *node, *nnode;
struct route_node *rn;
struct ospf_area *area;
- struct ospf_area_range *range;
- for (ALL_LIST_ELEMENTS(ospf->areas, node, nnode, area))
- for (rn = route_top(area->ranges); rn; rn = route_next(rn))
- if ((range = rn->info) != NULL)
- if (CHECK_FLAG(range->flags,
- OSPF_AREA_RANGE_ADVERTISE)) {
- if (range->specifics)
- ospf_add_discard_route(
- ospf, ospf->new_table,
- area,
- (struct prefix_ipv4
- *)&rn->p);
- else
- ospf_delete_discard_route(
- ospf, ospf->new_table,
- (struct prefix_ipv4
- *)&rn->p);
- }
+ for (ALL_LIST_ELEMENTS(ospf->areas, node, nnode, area)) {
+ struct route_table *ranges;
+
+ if (nssa)
+ ranges = area->nssa_ranges;
+ else
+ ranges = area->ranges;
+
+ for (rn = route_top(ranges); rn; rn = route_next(rn)) {
+ struct ospf_area_range *range;
+
+ range = rn->info;
+ if (!range)
+ continue;
+
+ if (ospf_area_range_active(range)
+ && CHECK_FLAG(range->flags,
+ OSPF_AREA_RANGE_ADVERTISE))
+ ospf_add_discard_route(
+ ospf, ospf->new_table, area,
+ (struct prefix_ipv4 *)&rn->p, nssa);
+ else
+ ospf_delete_discard_route(
+ ospf, ospf->new_table,
+ (struct prefix_ipv4 *)&rn->p, nssa);
+ }
+ }
}
/* This is the function taking care about ABR NSSA, i.e. NSSA
@@ -1925,7 +2014,7 @@ static void ospf_abr_manage_discard_routes(struct ospf *ospf)
For External Calculations, any NSSA areas use the Type-7 AREA-LSDB,
any ABR-non-NSSA areas use the Type-5 GLOBAL-LSDB. */
-static void ospf_abr_nssa_task(struct ospf *ospf) /* called only if any_nssa */
+void ospf_abr_nssa_task(struct ospf *ospf) /* called only if any_nssa */
{
if (ospf->gr_info.restart_in_progress)
return;
@@ -1952,7 +2041,7 @@ static void ospf_abr_nssa_task(struct ospf *ospf) /* called only if any_nssa */
/* RESET all Ranges in every Area, same as summaries */
if (IS_DEBUG_OSPF_NSSA)
zlog_debug("%s: NSSA initialize aggregates", __func__);
- ospf_abr_prepare_aggregates(ospf); /*TURNED OFF just for now */
+ ospf_abr_prepare_aggregates(ospf, true);
/* For all NSSAs, Type-7s, translate to 5's, INSTALL/FLOOD, or
* Aggregate as Type-7
@@ -1983,7 +2072,7 @@ static void ospf_abr_nssa_task(struct ospf *ospf) /* called only if any_nssa */
zlog_debug("%s: remove unapproved translates", __func__);
ospf_abr_remove_unapproved_translates(ospf);
- ospf_abr_manage_discard_routes(ospf); /* same as normal...discard */
+ ospf_abr_manage_discard_routes(ospf, true);
if (IS_DEBUG_OSPF_NSSA)
zlog_debug("%s: Stop", __func__);
@@ -2012,7 +2101,7 @@ void ospf_abr_task(struct ospf *ospf)
if (IS_DEBUG_OSPF_EVENT)
zlog_debug("%s: prepare aggregates", __func__);
- ospf_abr_prepare_aggregates(ospf);
+ ospf_abr_prepare_aggregates(ospf, false);
if (IS_OSPF_ABR(ospf)) {
if (IS_DEBUG_OSPF_EVENT)
@@ -2031,6 +2120,11 @@ void ospf_abr_task(struct ospf *ospf)
zlog_debug("%s: announce stub defaults", __func__);
ospf_abr_announce_stub_defaults(ospf);
+ if (IS_DEBUG_OSPF_EVENT)
+ zlog_debug("%s: announce NSSA Type-7 defaults",
+ __func__);
+ ospf_abr_nssa_type7_defaults(ospf);
+
if (ospf->fr_configured) {
OSPF_LOG_DEBUG(IS_DEBUG_OSPF_EVENT,
"%s(): announce non-DNArouters",
@@ -2040,9 +2134,9 @@ void ospf_abr_task(struct ospf *ospf)
* giving time for route synchronization in
* all the routers.
*/
- thread_add_timer(
- master, ospf_abr_announce_non_dna_routers, ospf,
- OSPF_ABR_DNA_TIMER, &ospf->t_abr_fr);
+ event_add_timer(master,
+ ospf_abr_announce_non_dna_routers, ospf,
+ OSPF_ABR_DNA_TIMER, &ospf->t_abr_fr);
}
}
@@ -2050,15 +2144,15 @@ void ospf_abr_task(struct ospf *ospf)
zlog_debug("%s: remove unapproved summaries", __func__);
ospf_abr_remove_unapproved_summaries(ospf);
- ospf_abr_manage_discard_routes(ospf);
+ ospf_abr_manage_discard_routes(ospf, false);
if (IS_DEBUG_OSPF_EVENT)
zlog_debug("%s: Stop", __func__);
}
-static void ospf_abr_task_timer(struct thread *thread)
+static void ospf_abr_task_timer(struct event *thread)
{
- struct ospf *ospf = THREAD_ARG(thread);
+ struct ospf *ospf = EVENT_ARG(thread);
ospf->t_abr_task = 0;
@@ -2077,6 +2171,6 @@ void ospf_schedule_abr_task(struct ospf *ospf)
if (IS_DEBUG_OSPF_EVENT)
zlog_debug("Scheduling ABR task");
- thread_add_timer(master, ospf_abr_task_timer, ospf, OSPF_ABR_TASK_DELAY,
- &ospf->t_abr_task);
+ event_add_timer(master, ospf_abr_task_timer, ospf, OSPF_ABR_TASK_DELAY,
+ &ospf->t_abr_task);
}
diff --git a/ospfd/ospf_abr.h b/ospfd/ospf_abr.h
index 19d444b125..cc2b2b0548 100644
--- a/ospfd/ospf_abr.h
+++ b/ospfd/ospf_abr.h
@@ -16,6 +16,7 @@
#define OSPF_AREA_RANGE_ADVERTISE (1 << 0)
#define OSPF_AREA_RANGE_SUBSTITUTE (1 << 1)
+#define OSPF_AREA_RANGE_NSSA (1 << 2)
/* Area range. */
struct ospf_area_range {
@@ -44,23 +45,23 @@ struct ospf_area_range {
/* Prototypes. */
extern struct ospf_area_range *ospf_area_range_lookup(struct ospf_area *,
+ struct route_table *,
struct prefix_ipv4 *);
-
-extern struct ospf_area_range *ospf_some_area_range_match(struct prefix_ipv4 *);
-
extern struct ospf_area_range *
ospf_area_range_lookup_next(struct ospf_area *, struct in_addr *, int);
-extern int ospf_area_range_set(struct ospf *, struct in_addr,
- struct prefix_ipv4 *, int);
-extern int ospf_area_range_cost_set(struct ospf *, struct in_addr,
- struct prefix_ipv4 *, uint32_t);
-extern int ospf_area_range_unset(struct ospf *, struct in_addr,
- struct prefix_ipv4 *);
-extern int ospf_area_range_substitute_set(struct ospf *, struct in_addr,
+extern int ospf_area_range_set(struct ospf *, struct ospf_area *,
+ struct route_table *, struct prefix_ipv4 *, int,
+ bool);
+extern int ospf_area_range_cost_set(struct ospf *, struct ospf_area *,
+ struct route_table *, struct prefix_ipv4 *,
+ uint32_t);
+extern int ospf_area_range_unset(struct ospf *, struct ospf_area *,
+ struct route_table *, struct prefix_ipv4 *);
+extern int ospf_area_range_substitute_set(struct ospf *, struct ospf_area *,
struct prefix_ipv4 *,
struct prefix_ipv4 *);
-extern int ospf_area_range_substitute_unset(struct ospf *, struct in_addr,
+extern int ospf_area_range_substitute_unset(struct ospf *, struct ospf_area *,
struct prefix_ipv4 *);
extern struct ospf_area_range *ospf_area_range_match_any(struct ospf *,
struct prefix_ipv4 *);
@@ -69,10 +70,12 @@ extern int ospf_act_bb_connection(struct ospf *);
extern void ospf_check_abr_status(struct ospf *);
extern void ospf_abr_task(struct ospf *);
+extern void ospf_abr_nssa_task(struct ospf *ospf);
extern void ospf_schedule_abr_task(struct ospf *);
extern void ospf_abr_announce_network_to_area(struct prefix_ipv4 *, uint32_t,
struct ospf_area *);
+extern void ospf_abr_nssa_type7_defaults(struct ospf *ospf);
extern void ospf_abr_nssa_check_status(struct ospf *ospf);
extern void ospf_abr_generate_indication_lsa(struct ospf *ospf,
const struct ospf_area *area);
diff --git a/ospfd/ospf_api.c b/ospfd/ospf_api.c
index 3cb1287be5..213ee8c1fd 100644
--- a/ospfd/ospf_api.c
+++ b/ospfd/ospf_api.c
@@ -18,7 +18,7 @@
#include "vty.h"
#include "stream.h"
#include "log.h"
-#include "thread.h"
+#include "frrevent.h"
#include "hash.h"
#include "sockunion.h" /* for inet_aton() */
#include "buffer.h"
diff --git a/ospfd/ospf_apiserver.c b/ospfd/ospf_apiserver.c
index 5e4fc30a28..1aacc341aa 100644
--- a/ospfd/ospf_apiserver.c
+++ b/ospfd/ospf_apiserver.c
@@ -18,14 +18,14 @@
#include "vty.h"
#include "stream.h"
#include "log.h"
-#include "thread.h"
+#include "frrevent.h"
#include "hash.h"
#include "sockunion.h" /* for inet_aton() */
#include "buffer.h"
#include <sys/types.h>
-#include "ospfd/ospfd.h" /* for "struct thread_master" */
+#include "ospfd/ospfd.h" /* for "struct event_loop" */
#include "ospfd/ospf_interface.h"
#include "ospfd/ospf_ism.h"
#include "ospfd/ospf_asbr.h"
@@ -166,9 +166,14 @@ void ospf_apiserver_term(void)
* Free all client instances. ospf_apiserver_free removes the node
* from the list, so we examine the head of the list anew each time.
*/
- while (apiserver_list
- && (apiserv = listgetdata(listhead(apiserver_list))) != NULL)
+ if (!apiserver_list)
+ return;
+
+ while (listcount(apiserver_list)) {
+ apiserv = listgetdata(listhead(apiserver_list));
+
ospf_apiserver_free(apiserv);
+ }
/* Free client list itself */
if (apiserver_list)
@@ -273,28 +278,28 @@ void ospf_apiserver_event(enum ospf_apiserver_event event, int fd,
{
switch (event) {
case OSPF_APISERVER_ACCEPT:
- (void)thread_add_read(master, ospf_apiserver_accept, apiserv,
- fd, NULL);
+ (void)event_add_read(master, ospf_apiserver_accept, apiserv, fd,
+ NULL);
break;
case OSPF_APISERVER_SYNC_READ:
apiserv->t_sync_read = NULL;
- thread_add_read(master, ospf_apiserver_read, apiserv, fd,
- &apiserv->t_sync_read);
+ event_add_read(master, ospf_apiserver_read, apiserv, fd,
+ &apiserv->t_sync_read);
break;
#ifdef USE_ASYNC_READ
case OSPF_APISERVER_ASYNC_READ:
apiserv->t_async_read = NULL;
- thread_add_read(master, ospf_apiserver_read, apiserv, fd,
- &apiserv->t_async_read);
+ event_add_read(master, ospf_apiserver_read, apiserv, fd,
+ &apiserv->t_async_read);
break;
#endif /* USE_ASYNC_READ */
case OSPF_APISERVER_SYNC_WRITE:
- thread_add_write(master, ospf_apiserver_sync_write, apiserv, fd,
- &apiserv->t_sync_write);
+ event_add_write(master, ospf_apiserver_sync_write, apiserv, fd,
+ &apiserv->t_sync_write);
break;
case OSPF_APISERVER_ASYNC_WRITE:
- thread_add_write(master, ospf_apiserver_async_write, apiserv,
- fd, &apiserv->t_async_write);
+ event_add_write(master, ospf_apiserver_async_write, apiserv, fd,
+ &apiserv->t_async_write);
break;
}
}
@@ -307,12 +312,12 @@ void ospf_apiserver_free(struct ospf_apiserver *apiserv)
struct listnode *node;
/* Cancel read and write threads. */
- THREAD_OFF(apiserv->t_sync_read);
+ EVENT_OFF(apiserv->t_sync_read);
#ifdef USE_ASYNC_READ
- THREAD_OFF(apiserv->t_async_read);
+ EVENT_OFF(apiserv->t_async_read);
#endif /* USE_ASYNC_READ */
- THREAD_OFF(apiserv->t_sync_write);
- THREAD_OFF(apiserv->t_async_write);
+ EVENT_OFF(apiserv->t_sync_write);
+ EVENT_OFF(apiserv->t_async_write);
/* Unregister all opaque types that application registered
and flush opaque LSAs if still in LSDB. */
@@ -323,6 +328,7 @@ void ospf_apiserver_free(struct ospf_apiserver *apiserv)
ospf_apiserver_unregister_opaque_type(
apiserv, regtype->lsa_type, regtype->opaque_type);
}
+ list_delete(&apiserv->opaque_types);
/* Close connections to OSPFd. */
if (apiserv->fd_sync > 0) {
@@ -344,6 +350,8 @@ void ospf_apiserver_free(struct ospf_apiserver *apiserv)
/* Remove from the list of active clients. */
listnode_delete(apiserver_list, apiserv);
+ XFREE(MTYPE_APISERVER_MSGFILTER, apiserv->filter);
+
if (IS_DEBUG_OSPF_EVENT)
zlog_debug("API: Delete apiserv(%p), total#(%d)",
(void *)apiserv, apiserver_list->count);
@@ -352,15 +360,15 @@ void ospf_apiserver_free(struct ospf_apiserver *apiserv)
XFREE(MTYPE_APISERVER, apiserv);
}
-void ospf_apiserver_read(struct thread *thread)
+void ospf_apiserver_read(struct event *thread)
{
struct ospf_apiserver *apiserv;
struct msg *msg;
int fd;
enum ospf_apiserver_event event;
- apiserv = THREAD_ARG(thread);
- fd = THREAD_FD(thread);
+ apiserv = EVENT_ARG(thread);
+ fd = EVENT_FD(thread);
if (fd == apiserv->fd_sync) {
event = OSPF_APISERVER_SYNC_READ;
@@ -411,16 +419,16 @@ void ospf_apiserver_read(struct thread *thread)
msg_free(msg);
}
-void ospf_apiserver_sync_write(struct thread *thread)
+void ospf_apiserver_sync_write(struct event *thread)
{
struct ospf_apiserver *apiserv;
struct msg *msg;
int fd;
int rc = -1;
- apiserv = THREAD_ARG(thread);
+ apiserv = EVENT_ARG(thread);
assert(apiserv);
- fd = THREAD_FD(thread);
+ fd = EVENT_FD(thread);
apiserv->t_sync_write = NULL;
@@ -471,16 +479,16 @@ out:
}
-void ospf_apiserver_async_write(struct thread *thread)
+void ospf_apiserver_async_write(struct event *thread)
{
struct ospf_apiserver *apiserv;
struct msg *msg;
int fd;
int rc = -1;
- apiserv = THREAD_ARG(thread);
+ apiserv = EVENT_ARG(thread);
assert(apiserv);
- fd = THREAD_FD(thread);
+ fd = EVENT_FD(thread);
apiserv->t_async_write = NULL;
@@ -569,7 +577,7 @@ int ospf_apiserver_serv_sock_family(unsigned short port, int family)
/* Accept connection request from external applications. For each
accepted connection allocate own connection instance. */
-void ospf_apiserver_accept(struct thread *thread)
+void ospf_apiserver_accept(struct event *thread)
{
int accept_sock;
int new_sync_sock;
@@ -581,8 +589,8 @@ void ospf_apiserver_accept(struct thread *thread)
unsigned int peerlen;
int ret;
- /* THREAD_ARG (thread) is NULL */
- accept_sock = THREAD_FD(thread);
+ /* EVENT_ARG (thread) is NULL */
+ accept_sock = EVENT_FD(thread);
/* Keep hearing on socket for further connections. */
ospf_apiserver_event(OSPF_APISERVER_ACCEPT, accept_sock, NULL);
@@ -889,6 +897,7 @@ int ospf_apiserver_unregister_opaque_type(struct ospf_apiserver *apiserv,
/* Remove from list of registered opaque types */
listnode_delete(apiserv->opaque_types, regtype);
+ XFREE(MTYPE_APISERVER, regtype);
if (IS_DEBUG_OSPF_EVENT)
zlog_debug(
"API: Del LSA-type(%d)/Opaque-type(%d) from apiserv(%p), total#(%d)",
diff --git a/ospfd/ospf_apiserver.h b/ospfd/ospf_apiserver.h
index a90d18573b..0aaf67c1f3 100644
--- a/ospfd/ospf_apiserver.h
+++ b/ospfd/ospf_apiserver.h
@@ -48,12 +48,12 @@ struct ospf_apiserver {
struct msg_fifo *out_async_fifo;
/* Read and write threads */
- struct thread *t_sync_read;
+ struct event *t_sync_read;
#ifdef USE_ASYNC_READ
- struct thread *t_async_read;
+ struct event *t_async_read;
#endif /* USE_ASYNC_READ */
- struct thread *t_sync_write;
- struct thread *t_async_write;
+ struct event *t_sync_write;
+ struct event *t_async_write;
};
enum ospf_apiserver_event {
@@ -79,10 +79,10 @@ extern void ospf_apiserver_free(struct ospf_apiserver *apiserv);
extern void ospf_apiserver_event(enum ospf_apiserver_event event, int fd,
struct ospf_apiserver *apiserv);
extern int ospf_apiserver_serv_sock_family(unsigned short port, int family);
-extern void ospf_apiserver_accept(struct thread *thread);
-extern void ospf_apiserver_read(struct thread *thread);
-extern void ospf_apiserver_sync_write(struct thread *thread);
-extern void ospf_apiserver_async_write(struct thread *thread);
+extern void ospf_apiserver_accept(struct event *thread);
+extern void ospf_apiserver_read(struct event *thread);
+extern void ospf_apiserver_sync_write(struct event *thread);
+extern void ospf_apiserver_async_write(struct event *thread);
extern int ospf_apiserver_send_reply(struct ospf_apiserver *apiserv,
uint32_t seqnr, uint8_t rc);
diff --git a/ospfd/ospf_asbr.c b/ospfd/ospf_asbr.c
index 5b5367811b..7befcc1086 100644
--- a/ospfd/ospf_asbr.c
+++ b/ospfd/ospf_asbr.c
@@ -6,7 +6,7 @@
#include <zebra.h>
-#include "thread.h"
+#include "frrevent.h"
#include "memory.h"
#include "linklist.h"
#include "prefix.h"
@@ -264,9 +264,9 @@ void ospf_asbr_status_update(struct ospf *ospf, uint8_t status)
/* If there's redistribution configured, we need to refresh external
* LSAs in order to install Type-7 and flood to all NSSA Areas
*/
-static void ospf_asbr_nssa_redist_update_timer(struct thread *thread)
+static void ospf_asbr_nssa_redist_update_timer(struct event *thread)
{
- struct ospf *ospf = THREAD_ARG(thread);
+ struct ospf *ospf = EVENT_ARG(thread);
int type;
ospf->t_asbr_nssa_redist_update = NULL;
@@ -297,9 +297,9 @@ void ospf_schedule_asbr_nssa_redist_update(struct ospf *ospf)
if (IS_DEBUG_OSPF_EVENT)
zlog_debug("Scheduling ASBR NSSA redistribution update");
- thread_add_timer(master, ospf_asbr_nssa_redist_update_timer, ospf,
- OSPF_ASBR_NSSA_REDIST_UPDATE_DELAY,
- &ospf->t_asbr_nssa_redist_update);
+ event_add_timer(master, ospf_asbr_nssa_redist_update_timer, ospf,
+ OSPF_ASBR_NSSA_REDIST_UPDATE_DELAY,
+ &ospf->t_asbr_nssa_redist_update);
}
void ospf_redistribute_withdraw(struct ospf *ospf, uint8_t type,
@@ -450,15 +450,12 @@ static void ospf_aggr_unlink_external_info(void *data)
void ospf_external_aggregator_free(struct ospf_external_aggr_rt *aggr)
{
- if (OSPF_EXTERNAL_RT_COUNT(aggr))
- hash_clean(aggr->match_extnl_hash,
- (void *)ospf_aggr_unlink_external_info);
+ hash_clean_and_free(&aggr->match_extnl_hash,
+ (void *)ospf_aggr_unlink_external_info);
if (IS_DEBUG_OSPF(lsa, EXTNL_LSA_AGGR))
zlog_debug("%s: Release the aggregator Address(%pI4/%d)",
__func__, &aggr->p.prefix, aggr->p.prefixlen);
- hash_free(aggr->match_extnl_hash);
- aggr->match_extnl_hash = NULL;
XFREE(MTYPE_OSPF_EXTERNAL_RT_AGGR, aggr);
}
@@ -983,13 +980,9 @@ static void ospf_handle_external_aggr_update(struct ospf *ospf)
aggr->action = OSPF_ROUTE_AGGR_NONE;
ospf_external_aggr_delete(ospf, rn);
- if (OSPF_EXTERNAL_RT_COUNT(aggr))
- hash_clean(
- aggr->match_extnl_hash,
- (void *)ospf_aggr_handle_external_info);
-
- hash_free(aggr->match_extnl_hash);
- XFREE(MTYPE_OSPF_EXTERNAL_RT_AGGR, aggr);
+ hash_clean_and_free(
+ &aggr->match_extnl_hash,
+ (void *)ospf_aggr_handle_external_info);
} else if (aggr->action == OSPF_ROUTE_AGGR_MODIFY) {
@@ -1047,9 +1040,9 @@ static void ospf_handle_external_aggr_update(struct ospf *ospf)
}
}
-static void ospf_asbr_external_aggr_process(struct thread *thread)
+static void ospf_asbr_external_aggr_process(struct event *thread)
{
- struct ospf *ospf = THREAD_ARG(thread);
+ struct ospf *ospf = EVENT_ARG(thread);
int operation = 0;
ospf->t_external_aggr = NULL;
@@ -1091,7 +1084,7 @@ static void ospf_external_aggr_timer(struct ospf *ospf,
zlog_debug(
"%s, Restarting Aggregator delay timer.",
__func__);
- THREAD_OFF(ospf->t_external_aggr);
+ EVENT_OFF(ospf->t_external_aggr);
}
}
@@ -1100,8 +1093,8 @@ static void ospf_external_aggr_timer(struct ospf *ospf,
__func__, ospf->aggr_delay_interval);
ospf->aggr_action = operation;
- thread_add_timer(master, ospf_asbr_external_aggr_process, ospf,
- ospf->aggr_delay_interval, &ospf->t_external_aggr);
+ event_add_timer(master, ospf_asbr_external_aggr_process, ospf,
+ ospf->aggr_delay_interval, &ospf->t_external_aggr);
}
int ospf_asbr_external_aggregator_set(struct ospf *ospf, struct prefix_ipv4 *p,
diff --git a/ospfd/ospf_ase.c b/ospfd/ospf_ase.c
index b43f0cb378..80390af505 100644
--- a/ospfd/ospf_ase.c
+++ b/ospfd/ospf_ase.c
@@ -6,7 +6,7 @@
#include <zebra.h>
-#include "thread.h"
+#include "frrevent.h"
#include "memory.h"
#include "hash.h"
#include "linklist.h"
@@ -549,7 +549,7 @@ static int ospf_ase_compare_tables(struct ospf *ospf,
return 0;
}
-static void ospf_ase_calculate_timer(struct thread *t)
+static void ospf_ase_calculate_timer(struct event *t)
{
struct ospf *ospf;
struct ospf_lsa *lsa;
@@ -558,7 +558,7 @@ static void ospf_ase_calculate_timer(struct thread *t)
struct ospf_area *area;
struct timeval start_time, stop_time;
- ospf = THREAD_ARG(t);
+ ospf = EVENT_ARG(t);
ospf->t_ase_calc = NULL;
if (ospf->ase_calc) {
@@ -630,8 +630,8 @@ void ospf_ase_calculate_timer_add(struct ospf *ospf)
if (ospf == NULL)
return;
- thread_add_timer(master, ospf_ase_calculate_timer, ospf,
- OSPF_ASE_CALC_INTERVAL, &ospf->t_ase_calc);
+ event_add_timer(master, ospf_ase_calculate_timer, ospf,
+ OSPF_ASE_CALC_INTERVAL, &ospf->t_ase_calc);
}
void ospf_ase_register_external_lsa(struct ospf_lsa *lsa, struct ospf *top)
diff --git a/ospfd/ospf_bfd.c b/ospfd/ospf_bfd.c
index 0b0016745d..7d4c7c06b8 100644
--- a/ospfd/ospf_bfd.c
+++ b/ospfd/ospf_bfd.c
@@ -12,7 +12,7 @@
#include "linklist.h"
#include "memory.h"
#include "prefix.h"
-#include "thread.h"
+#include "frrevent.h"
#include "buffer.h"
#include "stream.h"
#include "zclient.h"
@@ -310,7 +310,7 @@ DEFUN (no_ip_ospf_bfd,
return CMD_SUCCESS;
}
-void ospf_bfd_init(struct thread_master *tm)
+void ospf_bfd_init(struct event_loop *tm)
{
bfd_protocol_integration_init(zclient, tm);
diff --git a/ospfd/ospf_bfd.h b/ospfd/ospf_bfd.h
index 3c4e1e6c5f..d454f9c97b 100644
--- a/ospfd/ospf_bfd.h
+++ b/ospfd/ospf_bfd.h
@@ -11,7 +11,7 @@
#include "ospfd/ospf_interface.h"
#include "json.h"
-extern void ospf_bfd_init(struct thread_master *tm);
+extern void ospf_bfd_init(struct event_loop *tm);
extern void ospf_bfd_write_config(struct vty *vty,
const struct ospf_if_params *params);
diff --git a/ospfd/ospf_dump.c b/ospfd/ospf_dump.c
index b74b84e37d..dbe6dd97d0 100644
--- a/ospfd/ospf_dump.c
+++ b/ospfd/ospf_dump.c
@@ -9,7 +9,7 @@
#include "lib/bfd.h"
#include "monotime.h"
#include "linklist.h"
-#include "thread.h"
+#include "frrevent.h"
#include "prefix.h"
#include "command.h"
#include "stream.h"
@@ -235,7 +235,7 @@ const char *ospf_timeval_dump(struct timeval *t, char *buf, size_t size)
return buf;
}
-const char *ospf_timer_dump(struct thread *t, char *buf, size_t size)
+const char *ospf_timer_dump(struct event *t, char *buf, size_t size)
{
struct timeval result;
if (!t)
diff --git a/ospfd/ospf_dump.h b/ospfd/ospf_dump.h
index 0f217971ee..0d47be2565 100644
--- a/ospfd/ospf_dump.h
+++ b/ospfd/ospf_dump.h
@@ -136,15 +136,15 @@ extern unsigned long term_debug_ospf_client_api;
extern char *ospf_lsa_type_str[];
/* Prototypes. */
-extern const char *ospf_area_name_string(struct ospf_area *);
-extern const char *ospf_area_desc_string(struct ospf_area *);
-extern const char *ospf_if_name_string(struct ospf_interface *);
+extern const char *ospf_area_name_string(struct ospf_area *area);
+extern const char *ospf_area_desc_string(struct ospf_area *area);
+extern const char *ospf_if_name_string(struct ospf_interface *oip);
extern int ospf_nbr_ism_state(struct ospf_neighbor *nbr);
extern void ospf_nbr_ism_state_message(struct ospf_neighbor *nbr, char *buf,
size_t size);
-extern const char *ospf_timer_dump(struct thread *, char *, size_t);
-extern const char *ospf_timeval_dump(struct timeval *, char *, size_t);
-extern void ospf_packet_dump(struct stream *);
+extern const char *ospf_timer_dump(struct event *e, char *buf, size_t size);
+extern const char *ospf_timeval_dump(struct timeval *t, char *buf, size_t size);
+extern void ospf_packet_dump(struct stream *s);
extern void ospf_debug_init(void);
/* Appropriate buffer size to use with ospf_timer_dump and ospf_timeval_dump: */
diff --git a/ospfd/ospf_ext.c b/ospfd/ospf_ext.c
index 5faaed076b..75b58035a3 100644
--- a/ospfd/ospf_ext.c
+++ b/ospfd/ospf_ext.c
@@ -25,7 +25,7 @@
#include "vty.h"
#include "stream.h"
#include "log.h"
-#include "thread.h"
+#include "frrevent.h"
#include "hash.h"
#include "sockunion.h" /* for inet_aton() */
#include "network.h"
diff --git a/ospfd/ospf_flood.c b/ospfd/ospf_flood.c
index d0453bbc4a..f3fe504a07 100644
--- a/ospfd/ospf_flood.c
+++ b/ospfd/ospf_flood.c
@@ -12,7 +12,7 @@
#include "if.h"
#include "command.h"
#include "table.h"
-#include "thread.h"
+#include "frrevent.h"
#include "memory.h"
#include "log.h"
#include "zclient.h"
diff --git a/ospfd/ospf_gr.c b/ospfd/ospf_gr.c
index e83ff1dccf..f60f0e863e 100644
--- a/ospfd/ospf_gr.c
+++ b/ospfd/ospf_gr.c
@@ -201,7 +201,7 @@ static void ospf_gr_restart_exit(struct ospf *ospf, const char *reason)
zlog_debug("GR: exiting graceful restart: %s", reason);
ospf->gr_info.restart_in_progress = false;
- THREAD_OFF(ospf->gr_info.t_grace_period);
+ EVENT_OFF(ospf->gr_info.t_grace_period);
/* Record in non-volatile memory that the restart is complete. */
ospf_gr_nvm_delete(ospf);
@@ -495,9 +495,9 @@ void ospf_gr_check_adjs(struct ospf *ospf)
}
/* Handling of grace period expiry. */
-static void ospf_gr_grace_period_expired(struct thread *thread)
+static void ospf_gr_grace_period_expired(struct event *thread)
{
- struct ospf *ospf = THREAD_ARG(thread);
+ struct ospf *ospf = EVENT_ARG(thread);
ospf->gr_info.t_grace_period = NULL;
ospf_gr_restart_exit(ospf, "grace period has expired");
@@ -648,9 +648,9 @@ void ospf_gr_nvm_read(struct ospf *ospf)
zlog_debug(
"GR: remaining time until grace period expires: %lu(s)",
remaining_time);
- thread_add_timer(master, ospf_gr_grace_period_expired,
- ospf, remaining_time,
- &ospf->gr_info.t_grace_period);
+ event_add_timer(master, ospf_gr_grace_period_expired,
+ ospf, remaining_time,
+ &ospf->gr_info.t_grace_period);
}
}
diff --git a/ospfd/ospf_gr.h b/ospfd/ospf_gr.h
index 65aa91d421..9760bb1728 100644
--- a/ospfd/ospf_gr.h
+++ b/ospfd/ospf_gr.h
@@ -90,7 +90,7 @@ struct ospf_helper_info {
* helper until this timer until
* this timer expires.
*/
- struct thread *t_grace_timer;
+ struct event *t_grace_timer;
/* Helper status */
uint32_t gr_helper_status;
diff --git a/ospfd/ospf_gr_helper.c b/ospfd/ospf_gr_helper.c
index 0263df48c5..b97b6802b2 100644
--- a/ospfd/ospf_gr_helper.c
+++ b/ospfd/ospf_gr_helper.c
@@ -8,7 +8,7 @@
#include <zebra.h>
-#include "thread.h"
+#include "frrevent.h"
#include "memory.h"
#include "linklist.h"
#include "prefix.h"
@@ -99,9 +99,7 @@ static void ospf_enable_rtr_hash_destroy(struct ospf *ospf)
if (ospf->enable_rtr_list == NULL)
return;
- hash_clean(ospf->enable_rtr_list, ospf_disable_rtr_hash_free);
- hash_free(ospf->enable_rtr_list);
- ospf->enable_rtr_list = NULL;
+ hash_clean_and_free(&ospf->enable_rtr_list, ospf_disable_rtr_hash_free);
}
/*
@@ -331,9 +329,9 @@ static int ospf_extract_grace_lsa_fields(struct ospf_lsa *lsa,
* Returns:
* Nothing
*/
-static void ospf_handle_grace_timer_expiry(struct thread *thread)
+static void ospf_handle_grace_timer_expiry(struct event *thread)
{
- struct ospf_neighbor *nbr = THREAD_ARG(thread);
+ struct ospf_neighbor *nbr = EVENT_ARG(thread);
nbr->gr_helper_info.t_grace_timer = NULL;
@@ -502,7 +500,7 @@ int ospf_process_grace_lsa(struct ospf *ospf, struct ospf_lsa *lsa,
if (OSPF_GR_IS_ACTIVE_HELPER(restarter)) {
if (restarter->gr_helper_info.t_grace_timer)
- THREAD_OFF(restarter->gr_helper_info.t_grace_timer);
+ EVENT_OFF(restarter->gr_helper_info.t_grace_timer);
if (ospf->active_restarter_cnt > 0)
ospf->active_restarter_cnt--;
@@ -535,9 +533,9 @@ int ospf_process_grace_lsa(struct ospf *ospf, struct ospf_lsa *lsa,
actual_grace_interval);
/* Start the grace timer */
- thread_add_timer(master, ospf_handle_grace_timer_expiry, restarter,
- actual_grace_interval,
- &restarter->gr_helper_info.t_grace_timer);
+ event_add_timer(master, ospf_handle_grace_timer_expiry, restarter,
+ actual_grace_interval,
+ &restarter->gr_helper_info.t_grace_timer);
return OSPF_GR_ACTIVE_HELPER;
}
@@ -701,7 +699,7 @@ void ospf_gr_helper_exit(struct ospf_neighbor *nbr,
* expiry, stop the grace timer.
*/
if (reason != OSPF_GR_HELPER_GRACE_TIMEOUT)
- THREAD_OFF(nbr->gr_helper_info.t_grace_timer);
+ EVENT_OFF(nbr->gr_helper_info.t_grace_timer);
/* check exit triggered due to successful completion
* of graceful restart.
diff --git a/ospfd/ospf_ia.c b/ospfd/ospf_ia.c
index d3c9626d9a..59112b2cd2 100644
--- a/ospfd/ospf_ia.c
+++ b/ospfd/ospf_ia.c
@@ -7,7 +7,7 @@
#include <zebra.h>
-#include "thread.h"
+#include "frrevent.h"
#include "memory.h"
#include "hash.h"
#include "linklist.h"
diff --git a/ospfd/ospf_interface.c b/ospfd/ospf_interface.c
index 4ea367ecad..649ba70e02 100644
--- a/ospfd/ospf_interface.c
+++ b/ospfd/ospf_interface.c
@@ -6,7 +6,7 @@
#include <zebra.h>
-#include "thread.h"
+#include "frrevent.h"
#include "linklist.h"
#include "prefix.h"
#include "if.h"
@@ -289,7 +289,7 @@ void ospf_if_cleanup(struct ospf_interface *oi)
/* oi->nbrs and oi->nbr_nbma should be deleted on InterfaceDown event */
/* delete all static neighbors attached to this interface */
for (ALL_LIST_ELEMENTS(oi->nbr_nbma, node, nnode, nbr_nbma)) {
- THREAD_OFF(nbr_nbma->t_poll);
+ EVENT_OFF(nbr_nbma->t_poll);
if (nbr_nbma->nbr) {
nbr_nbma->nbr->nbr_nbma = NULL;
@@ -356,7 +356,7 @@ void ospf_if_free(struct ospf_interface *oi)
listnode_delete(oi->ospf->oiflist, oi);
listnode_delete(oi->area->oiflist, oi);
- thread_cancel_event(master, oi);
+ event_cancel_event(master, oi);
memset(oi, 0, sizeof(*oi));
XFREE(MTYPE_OSPF_IF, oi);
@@ -492,7 +492,7 @@ void ospf_interface_fifo_flush(struct ospf_interface *oi)
if (oi->on_write_q) {
listnode_delete(ospf->oi_write_q, oi);
if (list_isempty(ospf->oi_write_q))
- THREAD_OFF(ospf->t_write);
+ EVENT_OFF(ospf->t_write);
oi->on_write_q = 0;
}
}
@@ -977,7 +977,6 @@ static void ospf_vl_if_delete(struct ospf_vl_data *vl_data)
if_delete(&ifp);
if (!vrf_is_enabled(vrf))
vrf_delete(vrf);
- vlink_count--;
}
/* for a defined area, count the number of configured vl
@@ -1471,7 +1470,7 @@ void ospf_reset_hello_timer(struct interface *ifp, struct in_addr addr,
ospf_hello_send(oi);
/* Restart hello timer for this interface */
- THREAD_OFF(oi->t_hello);
+ EVENT_OFF(oi->t_hello);
OSPF_HELLO_TIMER_ON(oi);
}
@@ -1495,7 +1494,7 @@ void ospf_reset_hello_timer(struct interface *ifp, struct in_addr addr,
ospf_hello_send(oi);
/* Restart the hello timer. */
- THREAD_OFF(oi->t_hello);
+ EVENT_OFF(oi->t_hello);
OSPF_HELLO_TIMER_ON(oi);
}
}
diff --git a/ospfd/ospf_interface.h b/ospfd/ospf_interface.h
index 0ee0cd4a3c..8625a72ac1 100644
--- a/ospfd/ospf_interface.h
+++ b/ospfd/ospf_interface.h
@@ -228,12 +228,12 @@ struct ospf_interface {
uint32_t v_ls_ack; /* Delayed Link State Acknowledgment */
/* Threads. */
- struct thread *t_hello; /* timer */
- struct thread *t_wait; /* timer */
- struct thread *t_ls_ack; /* timer */
- struct thread *t_ls_ack_direct; /* event */
- struct thread *t_ls_upd_event; /* event */
- struct thread *t_opaque_lsa_self; /* Type-9 Opaque-LSAs */
+ struct event *t_hello; /* timer */
+ struct event *t_wait; /* timer */
+ struct event *t_ls_ack; /* timer */
+ struct event *t_ls_ack_direct; /* event */
+ struct event *t_ls_upd_event; /* event */
+ struct event *t_opaque_lsa_self; /* Type-9 Opaque-LSAs */
int on_write_q;
diff --git a/ospfd/ospf_ism.c b/ospfd/ospf_ism.c
index 173ebdf207..9f795ea918 100644
--- a/ospfd/ospf_ism.c
+++ b/ospfd/ospf_ism.c
@@ -7,7 +7,7 @@
#include <zebra.h>
-#include "thread.h"
+#include "frrevent.h"
#include "linklist.h"
#include "prefix.h"
#include "if.h"
@@ -237,11 +237,11 @@ int ospf_dr_election(struct ospf_interface *oi)
}
-void ospf_hello_timer(struct thread *thread)
+void ospf_hello_timer(struct event *thread)
{
struct ospf_interface *oi;
- oi = THREAD_ARG(thread);
+ oi = EVENT_ARG(thread);
oi->t_hello = NULL;
if (IS_DEBUG_OSPF(ism, ISM_TIMERS))
@@ -254,11 +254,11 @@ void ospf_hello_timer(struct thread *thread)
OSPF_HELLO_TIMER_ON(oi);
}
-static void ospf_wait_timer(struct thread *thread)
+static void ospf_wait_timer(struct event *thread)
{
struct ospf_interface *oi;
- oi = THREAD_ARG(thread);
+ oi = EVENT_ARG(thread);
oi->t_wait = NULL;
if (IS_DEBUG_OSPF(ism, ISM_TIMERS))
@@ -279,16 +279,16 @@ static void ism_timer_set(struct ospf_interface *oi)
interface parameters must be set to initial values, and
timers are
reset also. */
- THREAD_OFF(oi->t_hello);
- THREAD_OFF(oi->t_wait);
- THREAD_OFF(oi->t_ls_ack);
+ EVENT_OFF(oi->t_hello);
+ EVENT_OFF(oi->t_wait);
+ EVENT_OFF(oi->t_ls_ack);
break;
case ISM_Loopback:
/* In this state, the interface may be looped back and will be
unavailable for regular data traffic. */
- THREAD_OFF(oi->t_hello);
- THREAD_OFF(oi->t_wait);
- THREAD_OFF(oi->t_ls_ack);
+ EVENT_OFF(oi->t_hello);
+ EVENT_OFF(oi->t_wait);
+ EVENT_OFF(oi->t_ls_ack);
break;
case ISM_Waiting:
/* The router is trying to determine the identity of DRouter and
@@ -298,7 +298,7 @@ static void ism_timer_set(struct ospf_interface *oi)
OSPF_ISM_TIMER_MSEC_ON(oi->t_hello, ospf_hello_timer, 1);
OSPF_ISM_TIMER_ON(oi->t_wait, ospf_wait_timer,
OSPF_IF_PARAM(oi, v_wait));
- THREAD_OFF(oi->t_ls_ack);
+ EVENT_OFF(oi->t_ls_ack);
break;
case ISM_PointToPoint:
/* The interface connects to a physical Point-to-point network
@@ -307,7 +307,7 @@ static void ism_timer_set(struct ospf_interface *oi)
neighboring router. Hello packets are also sent. */
/* send first hello immediately */
OSPF_ISM_TIMER_MSEC_ON(oi->t_hello, ospf_hello_timer, 1);
- THREAD_OFF(oi->t_wait);
+ EVENT_OFF(oi->t_wait);
OSPF_ISM_TIMER_ON(oi->t_ls_ack, ospf_ls_ack_timer,
oi->v_ls_ack);
break;
@@ -317,7 +317,7 @@ static void ism_timer_set(struct ospf_interface *oi)
and the router itself is neither Designated Router nor
Backup Designated Router. */
OSPF_HELLO_TIMER_ON(oi);
- THREAD_OFF(oi->t_wait);
+ EVENT_OFF(oi->t_wait);
OSPF_ISM_TIMER_ON(oi->t_ls_ack, ospf_ls_ack_timer,
oi->v_ls_ack);
break;
@@ -326,7 +326,7 @@ static void ism_timer_set(struct ospf_interface *oi)
network,
and the router is Backup Designated Router. */
OSPF_HELLO_TIMER_ON(oi);
- THREAD_OFF(oi->t_wait);
+ EVENT_OFF(oi->t_wait);
OSPF_ISM_TIMER_ON(oi->t_ls_ack, ospf_ls_ack_timer,
oi->v_ls_ack);
break;
@@ -335,7 +335,7 @@ static void ism_timer_set(struct ospf_interface *oi)
network,
and the router is Designated Router. */
OSPF_HELLO_TIMER_ON(oi);
- THREAD_OFF(oi->t_wait);
+ EVENT_OFF(oi->t_wait);
OSPF_ISM_TIMER_ON(oi->t_ls_ack, ospf_ls_ack_timer,
oi->v_ls_ack);
break;
@@ -560,14 +560,14 @@ static void ism_change_state(struct ospf_interface *oi, int state)
}
/* Execute ISM event process. */
-void ospf_ism_event(struct thread *thread)
+void ospf_ism_event(struct event *thread)
{
int event;
int next_state;
struct ospf_interface *oi;
- oi = THREAD_ARG(thread);
- event = THREAD_VAL(thread);
+ oi = EVENT_ARG(thread);
+ event = EVENT_VAL(thread);
/* Call function. */
next_state = (*(ISM[oi->state][event].func))(oi);
diff --git a/ospfd/ospf_ism.h b/ospfd/ospf_ism.h
index d0516f61a1..426dda7733 100644
--- a/ospfd/ospf_ism.h
+++ b/ospfd/ospf_ism.h
@@ -39,15 +39,15 @@
oi->on_write_q = 1; \
} \
if (!list_isempty((O)->oi_write_q)) \
- thread_add_write(master, ospf_write, (O), (O)->fd, \
- &(O)->t_write); \
+ event_add_write(master, ospf_write, (O), (O)->fd, \
+ &(O)->t_write); \
} while (0)
/* Macro for OSPF ISM timer turn on. */
-#define OSPF_ISM_TIMER_ON(T, F, V) thread_add_timer(master, (F), oi, (V), &(T))
+#define OSPF_ISM_TIMER_ON(T, F, V) event_add_timer(master, (F), oi, (V), &(T))
#define OSPF_ISM_TIMER_MSEC_ON(T, F, V) \
- thread_add_timer_msec(master, (F), oi, (V), &(T))
+ event_add_timer_msec(master, (F), oi, (V), &(T))
/* convenience macro to set hello timer correctly, according to
* whether fast-hello is set or not
@@ -65,16 +65,16 @@
/* Macro for OSPF schedule event. */
#define OSPF_ISM_EVENT_SCHEDULE(I, E) \
- thread_add_event(master, ospf_ism_event, (I), (E), NULL)
+ event_add_event(master, ospf_ism_event, (I), (E), NULL)
/* Macro for OSPF execute event. */
#define OSPF_ISM_EVENT_EXECUTE(I, E) \
- thread_execute(master, ospf_ism_event, (I), (E))
+ event_execute(master, ospf_ism_event, (I), (E))
/* Prototypes. */
-extern void ospf_ism_event(struct thread *thread);
+extern void ospf_ism_event(struct event *thread);
extern void ism_change_status(struct ospf_interface *, int);
-extern void ospf_hello_timer(struct thread *thread);
+extern void ospf_hello_timer(struct event *thread);
extern int ospf_dr_election(struct ospf_interface *oi);
DECLARE_HOOK(ospf_ism_change,
diff --git a/ospfd/ospf_ldp_sync.c b/ospfd/ospf_ldp_sync.c
index d3da5003aa..b97e87faa0 100644
--- a/ospfd/ospf_ldp_sync.c
+++ b/ospfd/ospf_ldp_sync.c
@@ -9,7 +9,7 @@
#include "monotime.h"
#include "memory.h"
-#include "thread.h"
+#include "frrevent.h"
#include "prefix.h"
#include "table.h"
#include "vty.h"
@@ -190,7 +190,7 @@ void ospf_ldp_sync_if_complete(struct interface *ifp)
if (ldp_sync_info && ldp_sync_info->enabled == LDP_IGP_SYNC_ENABLED) {
if (ldp_sync_info->state == LDP_IGP_SYNC_STATE_REQUIRED_NOT_UP)
ldp_sync_info->state = LDP_IGP_SYNC_STATE_REQUIRED_UP;
- THREAD_OFF(ldp_sync_info->t_holddown);
+ EVENT_OFF(ldp_sync_info->t_holddown);
ospf_if_recalculate_output_cost(ifp);
}
}
@@ -241,7 +241,7 @@ void ospf_ldp_sync_ldp_fail(struct interface *ifp)
if (ldp_sync_info &&
ldp_sync_info->enabled == LDP_IGP_SYNC_ENABLED &&
ldp_sync_info->state != LDP_IGP_SYNC_STATE_NOT_REQUIRED) {
- THREAD_OFF(ldp_sync_info->t_holddown);
+ EVENT_OFF(ldp_sync_info->t_holddown);
ldp_sync_info->state = LDP_IGP_SYNC_STATE_REQUIRED_NOT_UP;
ospf_if_recalculate_output_cost(ifp);
}
@@ -305,7 +305,7 @@ void ospf_ldp_sync_if_remove(struct interface *ifp, bool remove)
*/
ols_debug("%s: Removed from if %s", __func__, ifp->name);
- THREAD_OFF(ldp_sync_info->t_holddown);
+ EVENT_OFF(ldp_sync_info->t_holddown);
ldp_sync_info->state = LDP_IGP_SYNC_STATE_NOT_REQUIRED;
ospf_if_recalculate_output_cost(ifp);
@@ -339,7 +339,7 @@ static int ospf_ldp_sync_ism_change(struct ospf_interface *oi, int state,
/*
* LDP-SYNC holddown timer routines
*/
-static void ospf_ldp_sync_holddown_timer(struct thread *thread)
+static void ospf_ldp_sync_holddown_timer(struct event *thread)
{
struct interface *ifp;
struct ospf_if_params *params;
@@ -349,7 +349,7 @@ static void ospf_ldp_sync_holddown_timer(struct thread *thread)
* didn't receive msg from LDP indicating sync-complete
* restore interface cost to original value
*/
- ifp = THREAD_ARG(thread);
+ ifp = EVENT_ARG(thread);
params = IF_DEF_PARAMS(ifp);
if (params->ldp_sync_info) {
ldp_sync_info = params->ldp_sync_info;
@@ -383,9 +383,8 @@ void ospf_ldp_sync_holddown_timer_add(struct interface *ifp)
ols_debug("%s: start holddown timer for %s time %d", __func__,
ifp->name, ldp_sync_info->holddown);
- thread_add_timer(master, ospf_ldp_sync_holddown_timer,
- ifp, ldp_sync_info->holddown,
- &ldp_sync_info->t_holddown);
+ event_add_timer(master, ospf_ldp_sync_holddown_timer, ifp,
+ ldp_sync_info->holddown, &ldp_sync_info->t_holddown);
}
/*
@@ -899,7 +898,7 @@ DEFPY (no_mpls_ldp_sync,
SET_FLAG(ldp_sync_info->flags, LDP_SYNC_FLAG_IF_CONFIG);
ldp_sync_info->enabled = LDP_IGP_SYNC_DEFAULT;
ldp_sync_info->state = LDP_IGP_SYNC_STATE_NOT_REQUIRED;
- THREAD_OFF(ldp_sync_info->t_holddown);
+ EVENT_OFF(ldp_sync_info->t_holddown);
ospf_if_recalculate_output_cost(ifp);
return CMD_SUCCESS;
diff --git a/ospfd/ospf_lsa.c b/ospfd/ospf_lsa.c
index 49e342d72b..87b683b15d 100644
--- a/ospfd/ospf_lsa.c
+++ b/ospfd/ospf_lsa.c
@@ -14,7 +14,7 @@
#include "memory.h"
#include "stream.h"
#include "log.h"
-#include "thread.h"
+#include "frrevent.h"
#include "hash.h"
#include "sockunion.h" /* for inet_aton() */
#include "checksum.h"
@@ -38,7 +38,7 @@
#include "ospfd/ospf_abr.h"
#include "ospfd/ospf_errors.h"
-static struct ospf_lsa *ospf_handle_summarylsa_lsId_chg(struct ospf *ospf,
+static struct ospf_lsa *ospf_handle_summarylsa_lsId_chg(struct ospf_area *area,
struct prefix_ipv4 *p,
uint8_t type,
uint32_t metric,
@@ -742,9 +742,9 @@ void ospf_router_lsa_body_set(struct stream **s, struct ospf_area *area)
stream_putw_at(*s, putp, cnt);
}
-static void ospf_stub_router_timer(struct thread *t)
+static void ospf_stub_router_timer(struct event *t)
{
- struct ospf_area *area = THREAD_ARG(t);
+ struct ospf_area *area = EVENT_ARG(t);
area->t_stub_router = NULL;
@@ -1283,23 +1283,24 @@ ospf_summary_lsa_prepare_and_flood(struct prefix_ipv4 *p, uint32_t metric,
return new;
}
-static struct ospf_lsa *ospf_handle_summarylsa_lsId_chg(struct ospf *ospf,
+static struct ospf_lsa *ospf_handle_summarylsa_lsId_chg(struct ospf_area *area,
struct prefix_ipv4 *p,
uint8_t type,
uint32_t metric,
struct in_addr old_id)
{
struct ospf_lsa *lsa = NULL;
- struct ospf_lsa *new = NULL;
+ struct ospf_lsa *summary_lsa = NULL;
struct summary_lsa *sl = NULL;
struct ospf_area *old_area = NULL;
+ struct ospf *ospf = area->ospf;
struct prefix_ipv4 old_prefix;
uint32_t old_metric;
struct in_addr mask;
uint32_t metric_val;
char *metric_buf;
- lsa = ospf_lsdb_lookup_by_id(ospf->lsdb, type, p->prefix,
+ lsa = ospf_lsdb_lookup_by_id(area->lsdb, type, p->prefix,
ospf->router_id);
if (!lsa) {
@@ -1327,19 +1328,19 @@ static struct ospf_lsa *ospf_handle_summarylsa_lsId_chg(struct ospf *ospf,
if (type == OSPF_SUMMARY_LSA) {
/*Refresh the LSA with new LSA*/
- ospf_summary_lsa_refresh(ospf, lsa);
+ summary_lsa = ospf_summary_lsa_refresh(ospf, lsa);
- new = ospf_summary_lsa_prepare_and_flood(
- &old_prefix, old_metric, old_area, old_id);
+ ospf_summary_lsa_prepare_and_flood(&old_prefix, old_metric,
+ old_area, old_id);
} else {
/*Refresh the LSA with new LSA*/
- ospf_summary_asbr_lsa_refresh(ospf, lsa);
+ summary_lsa = ospf_summary_asbr_lsa_refresh(ospf, lsa);
- new = ospf_asbr_summary_lsa_prepare_and_flood(
- &old_prefix, old_metric, old_area, old_id);
+ ospf_asbr_summary_lsa_prepare_and_flood(&old_prefix, old_metric,
+ old_area, old_id);
}
- return new;
+ return summary_lsa;
}
/* Originate Summary-LSA. */
@@ -1358,8 +1359,8 @@ struct ospf_lsa *ospf_summary_lsa_originate(struct prefix_ipv4 *p,
if (IS_DEBUG_OSPF(lsa, LSA_GENERATE))
zlog_debug("Link ID has to be changed.");
- new = ospf_handle_summarylsa_lsId_chg(
- area->ospf, p, OSPF_SUMMARY_LSA, metric, id);
+ new = ospf_handle_summarylsa_lsId_chg(area, p, OSPF_SUMMARY_LSA,
+ metric, id);
return new;
} else if (status == LSID_NOT_AVAILABLE) {
/* Link State ID not available. */
@@ -1521,7 +1522,7 @@ struct ospf_lsa *ospf_summary_asbr_lsa_originate(struct prefix_ipv4 *p,
zlog_debug("Link ID has to be changed.");
new = ospf_handle_summarylsa_lsId_chg(
- area->ospf, p, OSPF_ASBR_SUMMARY_LSA, metric, id);
+ area, p, OSPF_ASBR_SUMMARY_LSA, metric, id);
return new;
} else if (status == LSID_NOT_AVAILABLE) {
/* Link State ID not available. */
@@ -1653,9 +1654,6 @@ struct in_addr ospf_get_nssa_ip(struct ospf_area *area)
if (best_default.s_addr != INADDR_ANY)
return best_default;
- if (best_default.s_addr != INADDR_ANY)
- return best_default;
-
return fwd;
}
@@ -1867,8 +1865,7 @@ static struct ospf_lsa *ospf_external_lsa_new(struct ospf *ospf,
}
/* As Type-7 */
-static void ospf_install_flood_nssa(struct ospf *ospf, struct ospf_lsa *lsa,
- struct external_info *ei)
+static void ospf_install_flood_nssa(struct ospf *ospf, struct ospf_lsa *lsa)
{
struct ospf_lsa *new;
struct as_external_lsa *extlsa;
@@ -2252,7 +2249,7 @@ struct ospf_lsa *ospf_external_lsa_originate(struct ospf *ospf,
/* stay away from translated LSAs! */
!(CHECK_FLAG(new->flags, OSPF_LSA_LOCAL_XLT)))
ospf_install_flood_nssa(
- ospf, new, ei); /* Install/Flood Type-7 to all NSSAs */
+ ospf, new); /* Install/Flood Type-7 to all NSSAs */
/* Debug logging. */
if (IS_DEBUG_OSPF(lsa, LSA_GENERATE)) {
@@ -2265,6 +2262,100 @@ struct ospf_lsa *ospf_external_lsa_originate(struct ospf *ospf,
return new;
}
+/* Originate an NSSA-LSA, install and flood. */
+struct ospf_lsa *ospf_nssa_lsa_originate(struct ospf_area *area,
+ struct external_info *ei)
+{
+ struct ospf *ospf = area->ospf;
+ struct ospf_lsa *new;
+
+ if (ospf->gr_info.restart_in_progress) {
+ if (IS_DEBUG_OSPF(lsa, LSA_GENERATE))
+ zlog_debug(
+ "LSA[Type7]: Graceful Restart in progress, don't originate");
+ return NULL;
+ }
+
+ if (ospf->router_id.s_addr == INADDR_ANY) {
+ if (IS_DEBUG_OSPF_EVENT)
+ zlog_debug(
+ "LSA[Type7:%pI4]: deferring NSSA-LSA origination, router ID is zero",
+ &ei->p.prefix);
+ return NULL;
+ }
+
+ /* Create new NSSA-LSA instance. */
+ if ((new = ospf_external_lsa_new(ospf, ei, NULL)) == NULL) {
+ if (IS_DEBUG_OSPF_EVENT)
+ zlog_debug(
+ "LSA[Type7:%pI4]: Could not originate NSSA-LSA",
+ &ei->p.prefix);
+ return NULL;
+ }
+ new->data->type = OSPF_AS_NSSA_LSA;
+ new->area = area;
+
+ /* Install newly created LSA into Type-7 LSDB. */
+ ospf_lsa_install(ospf, NULL, new);
+
+ /* Update LSA origination count. */
+ ospf->lsa_originate_count++;
+
+ /* Flooding new LSA */
+ ospf_flood_through_area(area, NULL, new);
+
+ /* Debug logging. */
+ if (IS_DEBUG_OSPF(lsa, LSA_GENERATE)) {
+ zlog_debug("LSA[Type%d:%pI4]: Originate NSSA-LSA %p",
+ new->data->type, &new->data->id, (void *)new);
+ ospf_lsa_header_dump(new->data);
+ }
+
+ return new;
+}
+
+/* Refresh NSSA-LSA. */
+struct ospf_lsa *ospf_nssa_lsa_refresh(struct ospf_area *area,
+ struct ospf_lsa *lsa,
+ struct external_info *ei)
+{
+ struct ospf *ospf = area->ospf;
+ struct ospf_lsa *new;
+
+ /* Delete LSA from neighbor retransmit-list. */
+ ospf_ls_retransmit_delete_nbr_as(ospf, lsa);
+
+ /* Unregister AS-external-LSA from refresh-list. */
+ ospf_refresher_unregister_lsa(ospf, lsa);
+
+ /* Create new NSSA-LSA instance. */
+ if ((new = ospf_external_lsa_new(ospf, ei, NULL)) == NULL) {
+ if (IS_DEBUG_OSPF_EVENT)
+ zlog_debug(
+ "LSA[Type7:%pI4]: Could not originate NSSA-LSA",
+ &ei->p.prefix);
+ return NULL;
+ }
+ new->data->type = OSPF_AS_NSSA_LSA;
+ new->data->ls_seqnum = lsa_seqnum_increment(lsa);
+ new->area = area;
+
+ /* Install newly created LSA into Type-7 LSDB. */
+ ospf_lsa_install(ospf, NULL, new);
+
+ /* Flooding new LSA */
+ ospf_flood_through_area(area, NULL, new);
+
+ /* Debug logging. */
+ if (IS_DEBUG_OSPF(lsa, LSA_GENERATE)) {
+ zlog_debug("LSA[Type%d:%pI4]: NSSA-LSA refresh",
+ new->data->type, &new->data->id);
+ ospf_lsa_header_dump(new->data);
+ }
+
+ return new;
+}
+
static struct external_info *ospf_default_external_info(struct ospf *ospf)
{
int type;
@@ -2610,8 +2701,8 @@ struct ospf_lsa *ospf_external_lsa_refresh(struct ospf *ospf,
/* If any attached NSSA, install as Type-7, flood to all NSSA Areas */
if (ospf->anyNSSA && !(CHECK_FLAG(new->flags, OSPF_LSA_LOCAL_XLT)))
- ospf_install_flood_nssa(ospf, new,
- ei); /* Install/Flood per new rules */
+ ospf_install_flood_nssa(ospf,
+ new); /* Install/Flood per new rules */
/* Register self-originated LSA to refresh queue.
* Translated LSAs should not be registered, but refreshed upon
@@ -3041,9 +3132,9 @@ int ospf_check_nbr_status(struct ospf *ospf)
}
-void ospf_maxage_lsa_remover(struct thread *thread)
+void ospf_maxage_lsa_remover(struct event *thread)
{
- struct ospf *ospf = THREAD_ARG(thread);
+ struct ospf *ospf = EVENT_ARG(thread);
struct ospf_lsa *lsa, *old;
struct route_node *rn;
int reschedule = 0;
@@ -3073,7 +3164,7 @@ void ospf_maxage_lsa_remover(struct thread *thread)
}
/* TODO: maybe convert this function to a work-queue */
- if (thread_should_yield(thread)) {
+ if (event_should_yield(thread)) {
OSPF_TIMER_ON(ospf->t_maxage,
ospf_maxage_lsa_remover, 0);
route_unlock_node(
@@ -3289,9 +3380,9 @@ static int ospf_lsa_maxage_walker_remover(struct ospf *ospf,
}
/* Periodical check of MaxAge LSA. */
-void ospf_lsa_maxage_walker(struct thread *thread)
+void ospf_lsa_maxage_walker(struct event *thread)
{
- struct ospf *ospf = THREAD_ARG(thread);
+ struct ospf *ospf = EVENT_ARG(thread);
struct route_node *rn;
struct ospf_lsa *lsa;
struct ospf_area *area;
@@ -3651,8 +3742,8 @@ void ospf_flush_self_originated_lsas_now(struct ospf *ospf)
* without conflicting to other threads.
*/
if (ospf->t_maxage != NULL) {
- THREAD_OFF(ospf->t_maxage);
- thread_execute(master, ospf_maxage_lsa_remover, ospf, 0);
+ EVENT_OFF(ospf->t_maxage);
+ event_execute(master, ospf_maxage_lsa_remover, ospf, 0);
}
return;
@@ -3837,11 +3928,11 @@ struct lsa_action {
struct ospf_lsa *lsa;
};
-static void ospf_lsa_action(struct thread *t)
+static void ospf_lsa_action(struct event *t)
{
struct lsa_action *data;
- data = THREAD_ARG(t);
+ data = EVENT_ARG(t);
if (IS_DEBUG_OSPF(lsa, LSA) == OSPF_DEBUG_LSA)
zlog_debug("LSA[Action]: Performing scheduled LSA action: %d",
@@ -3869,7 +3960,7 @@ void ospf_schedule_lsa_flood_area(struct ospf_area *area, struct ospf_lsa *lsa)
data->area = area;
data->lsa = ospf_lsa_lock(lsa); /* Message / Flood area */
- thread_add_event(master, ospf_lsa_action, data, 0, NULL);
+ event_add_event(master, ospf_lsa_action, data, 0, NULL);
}
void ospf_schedule_lsa_flush_area(struct ospf_area *area, struct ospf_lsa *lsa)
@@ -3881,7 +3972,7 @@ void ospf_schedule_lsa_flush_area(struct ospf_area *area, struct ospf_lsa *lsa)
data->area = area;
data->lsa = ospf_lsa_lock(lsa); /* Message / Flush area */
- thread_add_event(master, ospf_lsa_action, data, 0, NULL);
+ event_add_event(master, ospf_lsa_action, data, 0, NULL);
}
@@ -4028,11 +4119,11 @@ void ospf_refresher_unregister_lsa(struct ospf *ospf, struct ospf_lsa *lsa)
}
}
-void ospf_lsa_refresh_walker(struct thread *t)
+void ospf_lsa_refresh_walker(struct event *t)
{
struct list *refresh_list;
struct listnode *node, *nnode;
- struct ospf *ospf = THREAD_ARG(t);
+ struct ospf *ospf = EVENT_ARG(t);
struct ospf_lsa *lsa;
int i;
struct list *lsa_to_refresh = list_new();
@@ -4090,19 +4181,19 @@ void ospf_lsa_refresh_walker(struct thread *t)
}
ospf->t_lsa_refresher = NULL;
- thread_add_timer(master, ospf_lsa_refresh_walker, ospf,
- ospf->lsa_refresh_interval, &ospf->t_lsa_refresher);
+ event_add_timer(master, ospf_lsa_refresh_walker, ospf,
+ ospf->lsa_refresh_interval, &ospf->t_lsa_refresher);
ospf->lsa_refresher_started = monotime(NULL);
for (ALL_LIST_ELEMENTS(lsa_to_refresh, node, nnode, lsa)) {
dna_lsa = ospf_check_dna_lsa(lsa);
if (!dna_lsa) { /* refresh only non-DNA LSAs */
ospf_lsa_refresh(ospf, lsa);
- assert(lsa->lock > 0);
- ospf_lsa_unlock(&lsa); /* lsa_refresh_queue & temp for
- * lsa_to_refresh.
- */
}
+ assert(lsa->lock > 0);
+ ospf_lsa_unlock(&lsa); /* lsa_refresh_queue & temp for
+ * lsa_to_refresh.
+ */
}
list_delete(&lsa_to_refresh);
diff --git a/ospfd/ospf_lsa.h b/ospfd/ospf_lsa.h
index 3c7ea3fda5..d5ca0694cc 100644
--- a/ospfd/ospf_lsa.h
+++ b/ospfd/ospf_lsa.h
@@ -278,6 +278,11 @@ extern struct in_addr ospf_get_ip_from_ifp(struct ospf_interface *);
extern struct ospf_lsa *ospf_external_lsa_originate(struct ospf *,
struct external_info *);
+extern struct ospf_lsa *ospf_nssa_lsa_originate(struct ospf_area *area,
+ struct external_info *ei);
+extern struct ospf_lsa *ospf_nssa_lsa_refresh(struct ospf_area *area,
+ struct ospf_lsa *lsa,
+ struct external_info *ei);
extern void ospf_external_lsa_rid_change(struct ospf *ospf);
extern struct ospf_lsa *ospf_lsa_lookup(struct ospf *ospf, struct ospf_area *,
uint32_t, struct in_addr,
@@ -300,7 +305,7 @@ extern struct ospf_lsa *ospf_lsa_lookup_by_prefix(struct ospf_lsdb *, uint8_t,
extern void ospf_lsa_maxage(struct ospf *, struct ospf_lsa *);
extern uint32_t get_metric(uint8_t *);
-extern void ospf_lsa_maxage_walker(struct thread *thread);
+extern void ospf_lsa_maxage_walker(struct event *thread);
extern struct ospf_lsa *ospf_lsa_refresh(struct ospf *, struct ospf_lsa *);
extern void ospf_external_lsa_refresh_default(struct ospf *);
@@ -320,7 +325,7 @@ extern void ospf_schedule_lsa_flush_area(struct ospf_area *, struct ospf_lsa *);
extern void ospf_refresher_register_lsa(struct ospf *, struct ospf_lsa *);
extern void ospf_refresher_unregister_lsa(struct ospf *, struct ospf_lsa *);
-extern void ospf_lsa_refresh_walker(struct thread *thread);
+extern void ospf_lsa_refresh_walker(struct event *thread);
extern void ospf_lsa_maxage_delete(struct ospf *, struct ospf_lsa *);
@@ -346,7 +351,7 @@ extern void ospf_check_and_gen_init_seq_lsa(struct ospf_interface *oi,
struct ospf_lsa *lsa);
extern void ospf_flush_lsa_from_area(struct ospf *ospf, struct in_addr area_id,
int type);
-extern void ospf_maxage_lsa_remover(struct thread *thread);
+extern void ospf_maxage_lsa_remover(struct event *thread);
extern bool ospf_check_dna_lsa(const struct ospf_lsa *lsa);
extern void ospf_refresh_area_self_lsas(struct ospf_area *area);
diff --git a/ospfd/ospf_main.c b/ospfd/ospf_main.c
index 05fc5c95d1..1f476a7e3d 100644
--- a/ospfd/ospf_main.c
+++ b/ospfd/ospf_main.c
@@ -9,7 +9,7 @@
#include <lib/version.h>
#include "bfd.h"
#include "getopt.h"
-#include "thread.h"
+#include "frrevent.h"
#include "prefix.h"
#include "linklist.h"
#include "if.h"
@@ -70,7 +70,7 @@ const struct option longopts[] = {
/* OSPFd program name */
/* Master of threads. */
-struct thread_master *master;
+struct event_loop *master;
#ifdef SUPPORT_OSPF_API
extern int ospf_apiserver_enable;
diff --git a/ospfd/ospf_neighbor.c b/ospfd/ospf_neighbor.c
index 8338c43077..c238f051df 100644
--- a/ospfd/ospf_neighbor.c
+++ b/ospfd/ospf_neighbor.c
@@ -11,7 +11,7 @@
#include "prefix.h"
#include "memory.h"
#include "command.h"
-#include "thread.h"
+#include "frrevent.h"
#include "stream.h"
#include "table.h"
#include "log.h"
@@ -125,17 +125,17 @@ void ospf_nbr_free(struct ospf_neighbor *nbr)
}
/* Cancel all timers. */
- THREAD_OFF(nbr->t_inactivity);
- THREAD_OFF(nbr->t_db_desc);
- THREAD_OFF(nbr->t_ls_req);
- THREAD_OFF(nbr->t_ls_upd);
+ EVENT_OFF(nbr->t_inactivity);
+ EVENT_OFF(nbr->t_db_desc);
+ EVENT_OFF(nbr->t_ls_req);
+ EVENT_OFF(nbr->t_ls_upd);
/* Cancel all events. */ /* Thread lookup cost would be negligible. */
- thread_cancel_event(master, nbr);
+ event_cancel_event(master, nbr);
bfd_sess_free(&nbr->bfd_session);
- THREAD_OFF(nbr->gr_helper_info.t_grace_timer);
+ EVENT_OFF(nbr->gr_helper_info.t_grace_timer);
nbr->oi = NULL;
XFREE(MTYPE_OSPF_NEIGHBOR, nbr);
@@ -441,7 +441,7 @@ static struct ospf_neighbor *ospf_nbr_add(struct ospf_interface *oi,
nbr->nbr_nbma = nbr_nbma;
if (nbr_nbma->t_poll)
- THREAD_OFF(nbr_nbma->t_poll);
+ EVENT_OFF(nbr_nbma->t_poll);
nbr->state_change = nbr_nbma->state_change + 1;
}
diff --git a/ospfd/ospf_neighbor.h b/ospfd/ospf_neighbor.h
index 7bd5b1209d..07d095f03d 100644
--- a/ospfd/ospf_neighbor.h
+++ b/ospfd/ospf_neighbor.h
@@ -57,11 +57,11 @@ struct ospf_neighbor {
uint32_t v_ls_upd;
/* Threads. */
- struct thread *t_inactivity;
- struct thread *t_db_desc;
- struct thread *t_ls_req;
- struct thread *t_ls_upd;
- struct thread *t_hello_reply;
+ struct event *t_inactivity;
+ struct event *t_db_desc;
+ struct event *t_ls_req;
+ struct event *t_ls_upd;
+ struct event *t_hello_reply;
/* NBMA configured neighbour */
struct ospf_nbr_nbma *nbr_nbma;
diff --git a/ospfd/ospf_network.c b/ospfd/ospf_network.c
index e89ad020b1..bd5cd7682a 100644
--- a/ospfd/ospf_network.c
+++ b/ospfd/ospf_network.c
@@ -6,7 +6,7 @@
#include <zebra.h>
-#include "thread.h"
+#include "frrevent.h"
#include "linklist.h"
#include "prefix.h"
#include "if.h"
@@ -111,7 +111,7 @@ int ospf_if_drop_alldrouters(struct ospf *top, struct prefix *p,
"can't setsockopt IP_DROP_MEMBERSHIP (fd %d, addr %pI4, ifindex %u, AllDRouters): %s",
top->fd, &p->u.prefix4, ifindex,
safe_strerror(errno));
- else
+ else if (IS_DEBUG_OSPF_EVENT)
zlog_debug(
"interface %pI4 [%u] leave AllDRouters Multicast group.",
&p->u.prefix4, ifindex);
@@ -159,7 +159,6 @@ int ospf_sock_init(struct ospf *ospf)
{
int ospf_sock;
int ret, hincl = 1;
- int bufsize = (8 * 1024 * 1024);
/* silently ignore. already done */
if (ospf->fd > 0)
@@ -213,9 +212,28 @@ int ospf_sock_init(struct ospf *ospf)
ospf_sock);
}
- setsockopt_so_sendbuf(ospf_sock, bufsize);
- setsockopt_so_recvbuf(ospf_sock, bufsize);
+ /* Update socket buffer sizes */
+ ospf_sock_bufsize_update(ospf, ospf_sock, OSPF_SOCK_BOTH);
ospf->fd = ospf_sock;
return ret;
}
+
+/*
+ * Update a socket bufsize(s), based on its ospf instance
+ */
+void ospf_sock_bufsize_update(const struct ospf *ospf, int sock,
+ enum ospf_sock_type_e type)
+{
+ int bufsize;
+
+ if (type == OSPF_SOCK_BOTH || type == OSPF_SOCK_RECV) {
+ bufsize = ospf->recv_sock_bufsize;
+ setsockopt_so_recvbuf(sock, bufsize);
+ }
+
+ if (type == OSPF_SOCK_BOTH || type == OSPF_SOCK_SEND) {
+ bufsize = ospf->send_sock_bufsize;
+ setsockopt_so_sendbuf(sock, bufsize);
+ }
+}
diff --git a/ospfd/ospf_network.h b/ospfd/ospf_network.h
index 33fd8980bf..d9b579c04a 100644
--- a/ospfd/ospf_network.h
+++ b/ospfd/ospf_network.h
@@ -16,4 +16,14 @@ extern int ospf_if_drop_alldrouters(struct ospf *, struct prefix *, ifindex_t);
extern int ospf_if_ipmulticast(struct ospf *, struct prefix *, ifindex_t);
extern int ospf_sock_init(struct ospf *ospf);
+enum ospf_sock_type_e {
+ OSPF_SOCK_NONE = 0,
+ OSPF_SOCK_RECV,
+ OSPF_SOCK_SEND,
+ OSPF_SOCK_BOTH
+};
+
+void ospf_sock_bufsize_update(const struct ospf *ospf, int sock,
+ enum ospf_sock_type_e type);
+
#endif /* _ZEBRA_OSPF_NETWORK_H */
diff --git a/ospfd/ospf_nsm.c b/ospfd/ospf_nsm.c
index 65c7720481..bcbe028795 100644
--- a/ospfd/ospf_nsm.c
+++ b/ospfd/ospf_nsm.c
@@ -7,7 +7,7 @@
#include <zebra.h>
-#include "thread.h"
+#include "frrevent.h"
#include "memory.h"
#include "hash.h"
#include "linklist.h"
@@ -44,11 +44,11 @@ DEFINE_HOOK(ospf_nsm_change,
static void nsm_clear_adj(struct ospf_neighbor *);
/* OSPF NSM Timer functions. */
-static void ospf_inactivity_timer(struct thread *thread)
+static void ospf_inactivity_timer(struct event *thread)
{
struct ospf_neighbor *nbr;
- nbr = THREAD_ARG(thread);
+ nbr = EVENT_ARG(thread);
nbr->t_inactivity = NULL;
if (IS_DEBUG_OSPF(nsm, NSM_TIMERS))
@@ -71,11 +71,11 @@ static void ospf_inactivity_timer(struct thread *thread)
}
}
-static void ospf_db_desc_timer(struct thread *thread)
+static void ospf_db_desc_timer(struct event *thread)
{
struct ospf_neighbor *nbr;
- nbr = THREAD_ARG(thread);
+ nbr = EVENT_ARG(thread);
nbr->t_db_desc = NULL;
if (IS_DEBUG_OSPF(nsm, NSM_TIMERS))
@@ -105,32 +105,32 @@ static void nsm_timer_set(struct ospf_neighbor *nbr)
switch (nbr->state) {
case NSM_Deleted:
case NSM_Down:
- THREAD_OFF(nbr->t_inactivity);
- THREAD_OFF(nbr->t_hello_reply);
+ EVENT_OFF(nbr->t_inactivity);
+ EVENT_OFF(nbr->t_hello_reply);
/* fallthru */
case NSM_Attempt:
case NSM_Init:
case NSM_TwoWay:
- THREAD_OFF(nbr->t_db_desc);
- THREAD_OFF(nbr->t_ls_upd);
- THREAD_OFF(nbr->t_ls_req);
+ EVENT_OFF(nbr->t_db_desc);
+ EVENT_OFF(nbr->t_ls_upd);
+ EVENT_OFF(nbr->t_ls_req);
break;
case NSM_ExStart:
OSPF_NSM_TIMER_ON(nbr->t_db_desc, ospf_db_desc_timer,
nbr->v_db_desc);
- THREAD_OFF(nbr->t_ls_upd);
- THREAD_OFF(nbr->t_ls_req);
+ EVENT_OFF(nbr->t_ls_upd);
+ EVENT_OFF(nbr->t_ls_req);
break;
case NSM_Exchange:
OSPF_NSM_TIMER_ON(nbr->t_ls_upd, ospf_ls_upd_timer,
nbr->v_ls_upd);
if (!IS_SET_DD_MS(nbr->dd_flags))
- THREAD_OFF(nbr->t_db_desc);
+ EVENT_OFF(nbr->t_db_desc);
break;
case NSM_Loading:
case NSM_Full:
default:
- THREAD_OFF(nbr->t_db_desc);
+ EVENT_OFF(nbr->t_db_desc);
break;
}
}
@@ -161,13 +161,13 @@ int nsm_should_adj(struct ospf_neighbor *nbr)
static int nsm_hello_received(struct ospf_neighbor *nbr)
{
/* Start or Restart Inactivity Timer. */
- THREAD_OFF(nbr->t_inactivity);
+ EVENT_OFF(nbr->t_inactivity);
OSPF_NSM_TIMER_ON(nbr->t_inactivity, ospf_inactivity_timer,
nbr->v_inactivity);
if (nbr->oi->type == OSPF_IFTYPE_NBMA && nbr->nbr_nbma)
- THREAD_OFF(nbr->nbr_nbma->t_poll);
+ EVENT_OFF(nbr->nbr_nbma->t_poll);
/* Send proactive ARP requests */
if (nbr->state < NSM_Exchange)
@@ -179,9 +179,9 @@ static int nsm_hello_received(struct ospf_neighbor *nbr)
static int nsm_start(struct ospf_neighbor *nbr)
{
if (nbr->nbr_nbma)
- THREAD_OFF(nbr->nbr_nbma->t_poll);
+ EVENT_OFF(nbr->nbr_nbma->t_poll);
- THREAD_OFF(nbr->t_inactivity);
+ EVENT_OFF(nbr->t_inactivity);
OSPF_NSM_TIMER_ON(nbr->t_inactivity, ospf_inactivity_timer,
nbr->v_inactivity);
@@ -629,12 +629,13 @@ static void nsm_notice_state_change(struct ospf_neighbor *nbr, int next_state,
if (CHECK_FLAG(nbr->oi->ospf->config, OSPF_LOG_ADJACENCY_CHANGES)
&& (CHECK_FLAG(nbr->oi->ospf->config, OSPF_LOG_ADJACENCY_DETAIL)
|| (next_state == NSM_Full) || (next_state < nbr->state)))
- zlog_notice("AdjChg: Nbr %pI4(%s) on %s: %s -> %s (%s)",
- &nbr->router_id,
- ospf_get_name(nbr->oi->ospf), IF_NAME(nbr->oi),
- lookup_msg(ospf_nsm_state_msg, nbr->state, NULL),
- lookup_msg(ospf_nsm_state_msg, next_state, NULL),
- ospf_nsm_event_str[event]);
+ zlog_notice(
+ "AdjChg: Nbr %pI4, NbrIP %pI4 (%s) on %s: %s -> %s (%s)",
+ &nbr->router_id, &nbr->src,
+ ospf_get_name(nbr->oi->ospf), IF_NAME(nbr->oi),
+ lookup_msg(ospf_nsm_state_msg, nbr->state, NULL),
+ lookup_msg(ospf_nsm_state_msg, next_state, NULL),
+ ospf_nsm_event_str[event]);
/* Advance in NSM */
if (next_state > nbr->state)
@@ -790,14 +791,14 @@ static void nsm_change_state(struct ospf_neighbor *nbr, int state)
}
/* Execute NSM event process. */
-void ospf_nsm_event(struct thread *thread)
+void ospf_nsm_event(struct event *thread)
{
int event;
int next_state;
struct ospf_neighbor *nbr;
- nbr = THREAD_ARG(thread);
- event = THREAD_VAL(thread);
+ nbr = EVENT_ARG(thread);
+ event = EVENT_VAL(thread);
if (IS_DEBUG_OSPF(nsm, NSM_EVENTS))
zlog_debug("NSM[%s:%pI4:%s]: %s (%s)", IF_NAME(nbr->oi),
diff --git a/ospfd/ospf_nsm.h b/ospfd/ospf_nsm.h
index b53a05914f..9973b4870d 100644
--- a/ospfd/ospf_nsm.h
+++ b/ospfd/ospf_nsm.h
@@ -41,22 +41,22 @@
#define OSPF_NSM_EVENT_MAX 14
/* Macro for OSPF NSM timer turn on. */
-#define OSPF_NSM_TIMER_ON(T,F,V) thread_add_timer (master, (F), nbr, (V), &(T))
+#define OSPF_NSM_TIMER_ON(T, F, V) event_add_timer(master, (F), nbr, (V), &(T))
/* Macro for OSPF NSM schedule event. */
#define OSPF_NSM_EVENT_SCHEDULE(N, E) \
- thread_add_event(master, ospf_nsm_event, (N), (E), NULL)
+ event_add_event(master, ospf_nsm_event, (N), (E), NULL)
/* Macro for OSPF NSM execute event. */
#define OSPF_NSM_EVENT_EXECUTE(N, E) \
- thread_execute(master, ospf_nsm_event, (N), (E))
+ event_execute(master, ospf_nsm_event, (N), (E))
/* Prototypes. */
-extern void ospf_nsm_event(struct thread *);
-extern void ospf_check_nbr_loading(struct ospf_neighbor *);
-extern int ospf_db_summary_isempty(struct ospf_neighbor *);
-extern int ospf_db_summary_count(struct ospf_neighbor *);
-extern void ospf_db_summary_clear(struct ospf_neighbor *);
+extern void ospf_nsm_event(struct event *e);
+extern void ospf_check_nbr_loading(struct ospf_neighbor *nbr);
+extern int ospf_db_summary_isempty(struct ospf_neighbor *nbr);
+extern int ospf_db_summary_count(struct ospf_neighbor *nbr);
+extern void ospf_db_summary_clear(struct ospf_neighbor *nbr);
extern int nsm_should_adj(struct ospf_neighbor *nbr);
DECLARE_HOOK(ospf_nsm_change,
(struct ospf_neighbor * on, int state, int oldstate),
diff --git a/ospfd/ospf_opaque.c b/ospfd/ospf_opaque.c
index 2e8e48bb5a..6f66ee10a1 100644
--- a/ospfd/ospf_opaque.c
+++ b/ospfd/ospf_opaque.c
@@ -16,7 +16,7 @@
#include "vty.h"
#include "stream.h"
#include "log.h"
-#include "thread.h"
+#include "frrevent.h"
#include "hash.h"
#include "sockunion.h" /* for inet_aton() */
#include "printfrr.h"
@@ -117,6 +117,10 @@ void ospf_opaque_finish(void)
ospf_ext_finish();
+#ifdef SUPPORT_OSPF_API
+ ospf_apiserver_term();
+#endif
+
ospf_sr_finish();
}
@@ -133,7 +137,7 @@ int ospf_opaque_type9_lsa_init(struct ospf_interface *oi)
void ospf_opaque_type9_lsa_term(struct ospf_interface *oi)
{
- THREAD_OFF(oi->t_opaque_lsa_self);
+ EVENT_OFF(oi->t_opaque_lsa_self);
if (oi->opaque_lsa_self != NULL)
list_delete(&oi->opaque_lsa_self);
oi->opaque_lsa_self = NULL;
@@ -162,7 +166,7 @@ void ospf_opaque_type10_lsa_term(struct ospf_area *area)
area->lsdb->new_lsa_hook = area->lsdb->del_lsa_hook = NULL;
#endif /* MONITOR_LSDB_CHANGE */
- THREAD_OFF(area->t_opaque_lsa_self);
+ EVENT_OFF(area->t_opaque_lsa_self);
if (area->opaque_lsa_self != NULL)
list_delete(&area->opaque_lsa_self);
return;
@@ -190,7 +194,7 @@ void ospf_opaque_type11_lsa_term(struct ospf *top)
top->lsdb->new_lsa_hook = top->lsdb->del_lsa_hook = NULL;
#endif /* MONITOR_LSDB_CHANGE */
- THREAD_OFF(top->t_opaque_lsa_self);
+ EVENT_OFF(top->t_opaque_lsa_self);
if (top->opaque_lsa_self != NULL)
list_delete(&top->opaque_lsa_self);
return;
@@ -475,7 +479,7 @@ struct opaque_info_per_type {
* to (re-)originate their own Opaque-LSAs out-of-sync with others.
* This thread is prepared for that specific purpose.
*/
- struct thread *t_opaque_lsa_self;
+ struct event *t_opaque_lsa_self;
/*
* Backpointer to an "owner" which is LSA-type dependent.
@@ -497,7 +501,7 @@ struct opaque_info_per_id {
uint32_t opaque_id;
/* Thread for refresh/flush scheduling for this opaque-type/id. */
- struct thread *t_opaque_lsa_self;
+ struct event *t_opaque_lsa_self;
/* Backpointer to Opaque-LSA control information per opaque-type. */
struct opaque_info_per_type *opqctl_type;
@@ -586,7 +590,7 @@ static void free_opaque_info_per_type(struct opaque_info_per_type *oipt,
ospf_opaque_lsa_flush_schedule(lsa);
}
- THREAD_OFF(oipt->t_opaque_lsa_self);
+ EVENT_OFF(oipt->t_opaque_lsa_self);
list_delete(&oipt->id_list);
if (cleanup_owner) {
/* Remove from its owner's self-originated LSA list. */
@@ -693,7 +697,7 @@ static void free_opaque_info_per_id(void *val)
{
struct opaque_info_per_id *oipi = (struct opaque_info_per_id *)val;
- THREAD_OFF(oipi->t_opaque_lsa_self);
+ EVENT_OFF(oipi->t_opaque_lsa_self);
if (oipi->lsa != NULL)
ospf_lsa_unlock(&oipi->lsa);
XFREE(MTYPE_OPAQUE_INFO_PER_ID, oipi);
@@ -1280,9 +1284,9 @@ out:
* Following are Opaque-LSA origination/refresh management functions.
*------------------------------------------------------------------------*/
-static void ospf_opaque_type9_lsa_originate(struct thread *t);
-static void ospf_opaque_type10_lsa_originate(struct thread *t);
-static void ospf_opaque_type11_lsa_originate(struct thread *t);
+static void ospf_opaque_type9_lsa_originate(struct event *t);
+static void ospf_opaque_type10_lsa_originate(struct event *t);
+static void ospf_opaque_type11_lsa_originate(struct event *t);
static void ospf_opaque_lsa_reoriginate_resume(struct list *listtop, void *arg);
void ospf_opaque_lsa_originate_schedule(struct ospf_interface *oi, int *delay0)
@@ -1328,8 +1332,8 @@ void ospf_opaque_lsa_originate_schedule(struct ospf_interface *oi, int *delay0)
"Schedule Type-9 Opaque-LSA origination in %d ms later.",
delay);
oi->t_opaque_lsa_self = NULL;
- thread_add_timer_msec(master, ospf_opaque_type9_lsa_originate,
- oi, delay, &oi->t_opaque_lsa_self);
+ event_add_timer_msec(master, ospf_opaque_type9_lsa_originate,
+ oi, delay, &oi->t_opaque_lsa_self);
delay += top->min_ls_interval;
}
@@ -1346,8 +1350,8 @@ void ospf_opaque_lsa_originate_schedule(struct ospf_interface *oi, int *delay0)
"Schedule Type-10 Opaque-LSA origination in %d ms later.",
delay);
area->t_opaque_lsa_self = NULL;
- thread_add_timer_msec(master, ospf_opaque_type10_lsa_originate,
- area, delay, &area->t_opaque_lsa_self);
+ event_add_timer_msec(master, ospf_opaque_type10_lsa_originate,
+ area, delay, &area->t_opaque_lsa_self);
delay += top->min_ls_interval;
}
@@ -1364,8 +1368,8 @@ void ospf_opaque_lsa_originate_schedule(struct ospf_interface *oi, int *delay0)
"Schedule Type-11 Opaque-LSA origination in %d ms later.",
delay);
top->t_opaque_lsa_self = NULL;
- thread_add_timer_msec(master, ospf_opaque_type11_lsa_originate,
- top, delay, &top->t_opaque_lsa_self);
+ event_add_timer_msec(master, ospf_opaque_type11_lsa_originate,
+ top, delay, &top->t_opaque_lsa_self);
delay += top->min_ls_interval;
}
@@ -1452,11 +1456,11 @@ void ospf_opaque_lsa_originate_schedule(struct ospf_interface *oi, int *delay0)
*delay0 = delay;
}
-static void ospf_opaque_type9_lsa_originate(struct thread *t)
+static void ospf_opaque_type9_lsa_originate(struct event *t)
{
struct ospf_interface *oi;
- oi = THREAD_ARG(t);
+ oi = EVENT_ARG(t);
oi->t_opaque_lsa_self = NULL;
if (IS_DEBUG_OSPF_EVENT)
@@ -1466,11 +1470,11 @@ static void ospf_opaque_type9_lsa_originate(struct thread *t)
opaque_lsa_originate_callback(ospf_opaque_type9_funclist, oi);
}
-static void ospf_opaque_type10_lsa_originate(struct thread *t)
+static void ospf_opaque_type10_lsa_originate(struct event *t)
{
struct ospf_area *area;
- area = THREAD_ARG(t);
+ area = EVENT_ARG(t);
area->t_opaque_lsa_self = NULL;
if (IS_DEBUG_OSPF_EVENT)
@@ -1481,11 +1485,11 @@ static void ospf_opaque_type10_lsa_originate(struct thread *t)
opaque_lsa_originate_callback(ospf_opaque_type10_funclist, area);
}
-static void ospf_opaque_type11_lsa_originate(struct thread *t)
+static void ospf_opaque_type11_lsa_originate(struct event *t)
{
struct ospf *top;
- top = THREAD_ARG(t);
+ top = EVENT_ARG(t);
top->t_opaque_lsa_self = NULL;
if (IS_DEBUG_OSPF_EVENT)
@@ -1639,15 +1643,16 @@ struct ospf_lsa *ospf_opaque_lsa_refresh(struct ospf_lsa *lsa)
* triggered by external interventions (vty session, signaling, etc).
*------------------------------------------------------------------------*/
-#define OSPF_OPAQUE_TIMER_ON(T,F,L,V) thread_add_timer_msec (master, (F), (L), (V), &(T))
+#define OSPF_OPAQUE_TIMER_ON(T, F, L, V) \
+ event_add_timer_msec(master, (F), (L), (V), &(T))
static struct ospf_lsa *pseudo_lsa(struct ospf_interface *oi,
struct ospf_area *area, uint8_t lsa_type,
uint8_t opaque_type);
-static void ospf_opaque_type9_lsa_reoriginate_timer(struct thread *t);
-static void ospf_opaque_type10_lsa_reoriginate_timer(struct thread *t);
-static void ospf_opaque_type11_lsa_reoriginate_timer(struct thread *t);
-static void ospf_opaque_lsa_refresh_timer(struct thread *t);
+static void ospf_opaque_type9_lsa_reoriginate_timer(struct event *t);
+static void ospf_opaque_type10_lsa_reoriginate_timer(struct event *t);
+static void ospf_opaque_type11_lsa_reoriginate_timer(struct event *t);
+static void ospf_opaque_lsa_refresh_timer(struct event *t);
void ospf_opaque_lsa_reoriginate_schedule(void *lsa_type_dependent,
uint8_t lsa_type, uint8_t opaque_type)
@@ -1658,7 +1663,7 @@ void ospf_opaque_lsa_reoriginate_schedule(void *lsa_type_dependent,
struct ospf_lsa *lsa;
struct opaque_info_per_type *oipt;
- void (*func)(struct thread * t) = NULL;
+ void (*func)(struct event * t) = NULL;
int delay;
switch (lsa_type) {
@@ -1818,14 +1823,14 @@ static struct ospf_lsa *pseudo_lsa(struct ospf_interface *oi,
return &lsa;
}
-static void ospf_opaque_type9_lsa_reoriginate_timer(struct thread *t)
+static void ospf_opaque_type9_lsa_reoriginate_timer(struct event *t)
{
struct opaque_info_per_type *oipt;
struct ospf_opaque_functab *functab;
struct ospf *top;
struct ospf_interface *oi;
- oipt = THREAD_ARG(t);
+ oipt = EVENT_ARG(t);
if ((functab = oipt->functab) == NULL
|| functab->lsa_originator == NULL) {
@@ -1859,7 +1864,7 @@ static void ospf_opaque_type9_lsa_reoriginate_timer(struct thread *t)
(*functab->lsa_originator)(oi);
}
-static void ospf_opaque_type10_lsa_reoriginate_timer(struct thread *t)
+static void ospf_opaque_type10_lsa_reoriginate_timer(struct event *t)
{
struct opaque_info_per_type *oipt;
struct ospf_opaque_functab *functab;
@@ -1869,7 +1874,7 @@ static void ospf_opaque_type10_lsa_reoriginate_timer(struct thread *t)
struct ospf_interface *oi;
int n;
- oipt = THREAD_ARG(t);
+ oipt = EVENT_ARG(t);
if ((functab = oipt->functab) == NULL
|| functab->lsa_originator == NULL) {
@@ -1908,13 +1913,13 @@ static void ospf_opaque_type10_lsa_reoriginate_timer(struct thread *t)
(*functab->lsa_originator)(area);
}
-static void ospf_opaque_type11_lsa_reoriginate_timer(struct thread *t)
+static void ospf_opaque_type11_lsa_reoriginate_timer(struct event *t)
{
struct opaque_info_per_type *oipt;
struct ospf_opaque_functab *functab;
struct ospf *top;
- oipt = THREAD_ARG(t);
+ oipt = EVENT_ARG(t);
if ((functab = oipt->functab) == NULL
|| functab->lsa_originator == NULL) {
@@ -2008,7 +2013,7 @@ out:
return;
}
-static void ospf_opaque_lsa_refresh_timer(struct thread *t)
+static void ospf_opaque_lsa_refresh_timer(struct event *t)
{
struct opaque_info_per_id *oipi;
struct ospf_opaque_functab *functab;
@@ -2017,7 +2022,7 @@ static void ospf_opaque_lsa_refresh_timer(struct thread *t)
if (IS_DEBUG_OSPF_EVENT)
zlog_debug("Timer[Opaque-LSA]: (Opaque-LSA Refresh expire)");
- oipi = THREAD_ARG(t);
+ oipi = EVENT_ARG(t);
if ((lsa = oipi->lsa) != NULL)
if ((functab = oipi->opqctl_type->functab) != NULL)
diff --git a/ospfd/ospf_packet.c b/ospfd/ospf_packet.c
index 5268c9896b..5f7d49e0bb 100644
--- a/ospfd/ospf_packet.c
+++ b/ospfd/ospf_packet.c
@@ -7,7 +7,7 @@
#include <zebra.h>
#include "monotime.h"
-#include "thread.h"
+#include "frrevent.h"
#include "memory.h"
#include "linklist.h"
#include "prefix.h"
@@ -308,8 +308,10 @@ static int ospf_check_md5_digest(struct ospf_interface *oi,
ck = ospf_crypt_key_lookup(OSPF_IF_PARAM(oi, auth_crypt),
ospfh->u.crypt.key_id);
if (ck == NULL) {
- flog_warn(EC_OSPF_MD5, "interface %s: ospf_check_md5 no key %d",
- IF_NAME(oi), ospfh->u.crypt.key_id);
+ flog_warn(
+ EC_OSPF_MD5,
+ "interface %s: ospf_check_md5 no key %d, Router-ID: %pI4",
+ IF_NAME(oi), ospfh->u.crypt.key_id, &ospfh->router_id);
return 0;
}
@@ -320,9 +322,9 @@ static int ospf_check_md5_digest(struct ospf_interface *oi,
&& ntohl(nbr->crypt_seqnum) > ntohl(ospfh->u.crypt.crypt_seqnum)) {
flog_warn(
EC_OSPF_MD5,
- "interface %s: ospf_check_md5 bad sequence %d (expect %d)",
+ "interface %s: ospf_check_md5 bad sequence %d (expect %d), Router-ID: %pI4",
IF_NAME(oi), ntohl(ospfh->u.crypt.crypt_seqnum),
- ntohl(nbr->crypt_seqnum));
+ ntohl(nbr->crypt_seqnum), &ospfh->router_id);
return 0;
}
@@ -345,9 +347,10 @@ static int ospf_check_md5_digest(struct ospf_interface *oi,
/* compare the two */
if (memcmp((caddr_t)ospfh + length, digest, OSPF_AUTH_MD5_SIZE)) {
- flog_warn(EC_OSPF_MD5,
- "interface %s: ospf_check_md5 checksum mismatch",
- IF_NAME(oi));
+ flog_warn(
+ EC_OSPF_MD5,
+ "interface %s: ospf_check_md5 checksum mismatch, Router-ID: %pI4",
+ IF_NAME(oi), &ospfh->router_id);
return 0;
}
@@ -426,20 +429,21 @@ static int ospf_make_md5_digest(struct ospf_interface *oi,
if (stream_get_endp(op->s) != op->length)
/* XXX size_t */
- flog_warn(EC_OSPF_MD5,
- "%s: length mismatch stream %lu ospf_packet %u",
- __func__, (unsigned long)stream_get_endp(op->s),
- op->length);
+ flog_warn(
+ EC_OSPF_MD5,
+ "%s: length mismatch stream %lu ospf_packet %u, Router-ID %pI4",
+ __func__, (unsigned long)stream_get_endp(op->s),
+ op->length, &ospfh->router_id);
return OSPF_AUTH_MD5_SIZE;
}
-static void ospf_ls_req_timer(struct thread *thread)
+static void ospf_ls_req_timer(struct event *thread)
{
struct ospf_neighbor *nbr;
- nbr = THREAD_ARG(thread);
+ nbr = EVENT_ARG(thread);
nbr->t_ls_req = NULL;
/* Send Link State Request. */
@@ -452,17 +456,17 @@ static void ospf_ls_req_timer(struct thread *thread)
void ospf_ls_req_event(struct ospf_neighbor *nbr)
{
- THREAD_OFF(nbr->t_ls_req);
- thread_add_event(master, ospf_ls_req_timer, nbr, 0, &nbr->t_ls_req);
+ EVENT_OFF(nbr->t_ls_req);
+ event_add_event(master, ospf_ls_req_timer, nbr, 0, &nbr->t_ls_req);
}
/* Cyclic timer function. Fist registered in ospf_nbr_new () in
ospf_neighbor.c */
-void ospf_ls_upd_timer(struct thread *thread)
+void ospf_ls_upd_timer(struct event *thread)
{
struct ospf_neighbor *nbr;
- nbr = THREAD_ARG(thread);
+ nbr = EVENT_ARG(thread);
nbr->t_ls_upd = NULL;
/* Send Link State Update. */
@@ -516,11 +520,11 @@ void ospf_ls_upd_timer(struct thread *thread)
OSPF_NSM_TIMER_ON(nbr->t_ls_upd, ospf_ls_upd_timer, nbr->v_ls_upd);
}
-void ospf_ls_ack_timer(struct thread *thread)
+void ospf_ls_ack_timer(struct event *thread)
{
struct ospf_interface *oi;
- oi = THREAD_ARG(thread);
+ oi = EVENT_ARG(thread);
oi->t_ls_ack = NULL;
/* Send Link State Acknowledgment. */
@@ -604,9 +608,9 @@ static void ospf_write_frags(int fd, struct ospf_packet *op, struct ip *iph,
}
#endif /* WANT_OSPF_WRITE_FRAGMENT */
-static void ospf_write(struct thread *thread)
+static void ospf_write(struct event *thread)
{
- struct ospf *ospf = THREAD_ARG(thread);
+ struct ospf *ospf = EVENT_ARG(thread);
struct ospf_interface *oi;
struct ospf_packet *op;
struct sockaddr_in sa_dst;
@@ -843,8 +847,8 @@ static void ospf_write(struct thread *thread)
/* If packets still remain in queue, call write thread. */
if (!list_isempty(ospf->oi_write_q))
- thread_add_write(master, ospf_write, ospf, ospf->fd,
- &ospf->t_write);
+ event_add_write(master, ospf_write, ospf, ospf->fd,
+ &ospf->t_write);
}
/* OSPF Hello message read -- RFC2328 Section 10.5. */
@@ -896,11 +900,11 @@ static void ospf_hello(struct ip *iph, struct ospf_header *ospfh,
/* Compare Router Dead Interval. */
if (OSPF_IF_PARAM(oi, v_wait) != ntohl(hello->dead_interval)) {
- flog_warn(EC_OSPF_PACKET,
- "Packet %pI4 [Hello:RECV]: RouterDeadInterval mismatch (expected %u, but received %u).",
- &ospfh->router_id,
- OSPF_IF_PARAM(oi, v_wait),
- ntohl(hello->dead_interval));
+ flog_warn(
+ EC_OSPF_PACKET,
+ "Packet %pI4 [Hello:RECV]: RouterDeadInterval mismatch on %s (expected %u, but received %u).",
+ &ospfh->router_id, IF_NAME(oi),
+ OSPF_IF_PARAM(oi, v_wait), ntohl(hello->dead_interval));
return;
}
@@ -910,8 +914,8 @@ static void ospf_hello(struct ip *iph, struct ospf_header *ospfh,
!= ntohs(hello->hello_interval)) {
flog_warn(
EC_OSPF_PACKET,
- "Packet %pI4 [Hello:RECV]: HelloInterval mismatch (expected %u, but received %u).",
- &ospfh->router_id,
+ "Packet %pI4 [Hello:RECV]: HelloInterval mismatch on %s (expected %u, but received %u).",
+ &ospfh->router_id, IF_NAME(oi),
OSPF_IF_PARAM(oi, v_hello),
ntohs(hello->hello_interval));
return;
@@ -919,8 +923,8 @@ static void ospf_hello(struct ip *iph, struct ospf_header *ospfh,
}
if (IS_DEBUG_OSPF_EVENT)
- zlog_debug("Packet %pI4 [Hello:RECV]: Options %s vrf %s",
- &ospfh->router_id,
+ zlog_debug("Packet %pI4 [Hello:RECV]: Options on %s %s vrf %s",
+ &ospfh->router_id, IF_NAME(oi),
ospf_options_dump(hello->options),
ospf_vrf_id_to_name(oi->ospf->vrf_id));
@@ -934,8 +938,8 @@ static void ospf_hello(struct ip *iph, struct ospf_header *ospfh,
* relationship.
*/
flog_warn(EC_OSPF_PACKET,
- "Packet %pI4 [Hello:RECV]: T-bit on, drop it.",
- &ospfh->router_id);
+ "Packet %pI4 [Hello:RECV]: T-bit ON on %s, drop it.",
+ &ospfh->router_id, IF_NAME(oi));
return;
}
#endif /* REJECT_IF_TBIT_ON */
@@ -947,8 +951,8 @@ static void ospf_hello(struct ip *iph, struct ospf_header *ospfh,
* the bit should be set in DD packet only.
*/
flog_warn(EC_OSPF_PACKET,
- "Packet %pI4 [Hello:RECV]: O-bit abuse?",
- &ospfh->router_id);
+ "Packet %pI4 [Hello:RECV]: O-bit abuse? on %s",
+ &ospfh->router_id, IF_NAME(oi));
#ifdef STRICT_OBIT_USAGE_CHECK
return; /* Reject this packet. */
#else /* STRICT_OBIT_USAGE_CHECK */
@@ -2102,6 +2106,14 @@ static void ospf_ls_upd(struct ospf *ospf, struct ip *iph,
if (ospf_flood(oi->ospf, nbr, current, lsa)
< 0) /* Trap NSSA later. */
DISCARD_LSA(lsa, 5);
+
+ /* GR: check for network topology change. */
+ if (ospf->gr_info.restart_in_progress &&
+ ((lsa->data->type == OSPF_ROUTER_LSA ||
+ lsa->data->type == OSPF_NETWORK_LSA)))
+ ospf_gr_check_lsdb_consistency(oi->ospf,
+ oi->area);
+
continue;
}
@@ -2214,9 +2226,6 @@ static void ospf_ls_upd(struct ospf *ospf, struct ip *iph,
assert(listcount(lsas) == 0);
list_delete(&lsas);
-
- if (ospf->gr_info.restart_in_progress)
- ospf_gr_check_lsdb_consistency(oi->ospf, oi->area);
}
/* OSPF Link State Acknowledgment message read -- RFC2328 Section 13.7. */
@@ -2470,10 +2479,11 @@ static int ospf_check_auth(struct ospf_interface *oi, struct ospf_header *ospfh)
if (IS_DEBUG_OSPF_PACKET(ospfh->type - 1, RECV))
flog_warn(
EC_OSPF_PACKET,
- "interface %s: auth-type mismatch, local %s, rcvd Null",
+ "interface %s: auth-type mismatch, local %s, rcvd Null, Router-ID %pI4",
IF_NAME(oi),
lookup_msg(ospf_auth_type_str,
- iface_auth_type, NULL));
+ iface_auth_type, NULL),
+ &ospfh->router_id);
return 0;
}
if (!ospf_check_sum(ospfh)) {
@@ -2492,18 +2502,20 @@ static int ospf_check_auth(struct ospf_interface *oi, struct ospf_header *ospfh)
if (IS_DEBUG_OSPF_PACKET(ospfh->type - 1, RECV))
flog_warn(
EC_OSPF_PACKET,
- "interface %s: auth-type mismatch, local %s, rcvd Simple",
+ "interface %s: auth-type mismatch, local %s, rcvd Simple, Router-ID %pI4",
IF_NAME(oi),
lookup_msg(ospf_auth_type_str,
- iface_auth_type, NULL));
+ iface_auth_type, NULL),
+ &ospfh->router_id);
return 0;
}
if (memcmp(OSPF_IF_PARAM(oi, auth_simple), ospfh->u.auth_data,
OSPF_AUTH_SIMPLE_SIZE)) {
if (IS_DEBUG_OSPF_PACKET(ospfh->type - 1, RECV))
- flog_warn(EC_OSPF_PACKET,
- "interface %s: Simple auth failed",
- IF_NAME(oi));
+ flog_warn(
+ EC_OSPF_PACKET,
+ "interface %s: Simple auth failed, Router-ID %pI4",
+ IF_NAME(oi), &ospfh->router_id);
return 0;
}
if (!ospf_check_sum(ospfh)) {
@@ -2522,18 +2534,19 @@ static int ospf_check_auth(struct ospf_interface *oi, struct ospf_header *ospfh)
if (IS_DEBUG_OSPF_PACKET(ospfh->type - 1, RECV))
flog_warn(
EC_OSPF_PACKET,
- "interface %s: auth-type mismatch, local %s, rcvd Cryptographic",
+ "interface %s: auth-type mismatch, local %s, rcvd Cryptographic, Router-ID %pI4",
IF_NAME(oi),
lookup_msg(ospf_auth_type_str,
- iface_auth_type, NULL));
+ iface_auth_type, NULL),
+ &ospfh->router_id);
return 0;
}
if (ospfh->checksum) {
if (IS_DEBUG_OSPF_PACKET(ospfh->type - 1, RECV))
flog_warn(
EC_OSPF_PACKET,
- "interface %s: OSPF header checksum is not 0",
- IF_NAME(oi));
+ "interface %s: OSPF header checksum is not 0, Router-ID %pI4",
+ IF_NAME(oi), &ospfh->router_id);
return 0;
}
/* only MD5 crypto method can pass ospf_packet_examin() */
@@ -2546,9 +2559,10 @@ static int ospf_check_auth(struct ospf_interface *oi, struct ospf_header *ospfh)
bug? */
!ospf_check_md5_digest(oi, ospfh)) {
if (IS_DEBUG_OSPF_PACKET(ospfh->type - 1, RECV))
- flog_warn(EC_OSPF_MD5,
- "interface %s: MD5 auth failed",
- IF_NAME(oi));
+ flog_warn(
+ EC_OSPF_MD5,
+ "interface %s: MD5 auth failed, Router-ID %pI4",
+ IF_NAME(oi), &ospfh->router_id);
return 0;
}
return 1;
@@ -2556,8 +2570,8 @@ static int ospf_check_auth(struct ospf_interface *oi, struct ospf_header *ospfh)
if (IS_DEBUG_OSPF_PACKET(ospfh->type - 1, RECV))
flog_warn(
EC_OSPF_PACKET,
- "interface %s: invalid packet auth-type (%02x)",
- IF_NAME(oi), pkt_auth_type);
+ "interface %s: invalid packet auth-type (%02x), Router-ID %pI4",
+ IF_NAME(oi), pkt_auth_type, &ospfh->router_id);
return 0;
}
}
@@ -3189,17 +3203,17 @@ static enum ospf_read_return_enum ospf_read_helper(struct ospf *ospf)
}
/* Starting point of packet process function. */
-void ospf_read(struct thread *thread)
+void ospf_read(struct event *thread)
{
struct ospf *ospf;
int32_t count = 0;
enum ospf_read_return_enum ret;
/* first of all get interface pointer. */
- ospf = THREAD_ARG(thread);
+ ospf = EVENT_ARG(thread);
/* prepare for next packet. */
- thread_add_read(master, ospf_read, ospf, ospf->fd, &ospf->t_read);
+ event_add_read(master, ospf_read, ospf, ospf->fd, &ospf->t_read);
while (count < ospf->write_oi_count) {
count++;
@@ -3724,11 +3738,11 @@ static void ospf_poll_send(struct ospf_nbr_nbma *nbr_nbma)
ospf_hello_send_sub(oi, nbr_nbma->addr.s_addr);
}
-void ospf_poll_timer(struct thread *thread)
+void ospf_poll_timer(struct event *thread)
{
struct ospf_nbr_nbma *nbr_nbma;
- nbr_nbma = THREAD_ARG(thread);
+ nbr_nbma = EVENT_ARG(thread);
nbr_nbma->t_poll = NULL;
if (IS_DEBUG_OSPF(nsm, NSM_TIMERS))
@@ -3743,11 +3757,11 @@ void ospf_poll_timer(struct thread *thread)
}
-void ospf_hello_reply_timer(struct thread *thread)
+void ospf_hello_reply_timer(struct event *thread)
{
struct ospf_neighbor *nbr;
- nbr = THREAD_ARG(thread);
+ nbr = EVENT_ARG(thread);
nbr->t_hello_reply = NULL;
if (IS_DEBUG_OSPF(nsm, NSM_TIMERS))
@@ -4058,7 +4072,7 @@ static void ospf_ls_upd_queue_send(struct ospf_interface *oi,
ospf_packet_add(oi, op);
/* Call ospf_write() right away to send ospf packets to neighbors */
if (send_lsupd_now) {
- struct thread os_packet_thd;
+ struct event os_packet_thd;
os_packet_thd.arg = (void *)oi->ospf;
if (oi->on_write_q == 0) {
@@ -4082,16 +4096,16 @@ static void ospf_ls_upd_queue_send(struct ospf_interface *oi,
* is actually turned off.
*/
if (list_isempty(oi->ospf->oi_write_q))
- THREAD_OFF(oi->ospf->t_write);
+ EVENT_OFF(oi->ospf->t_write);
} else {
/* Hook thread to write packet. */
OSPF_ISM_WRITE_ON(oi->ospf);
}
}
-static void ospf_ls_upd_send_queue_event(struct thread *thread)
+static void ospf_ls_upd_send_queue_event(struct event *thread)
{
- struct ospf_interface *oi = THREAD_ARG(thread);
+ struct ospf_interface *oi = EVENT_ARG(thread);
struct route_node *rn;
struct route_node *rnext;
struct list *update;
@@ -4126,8 +4140,8 @@ static void ospf_ls_upd_send_queue_event(struct thread *thread)
"%s: update lists not cleared, %d nodes to try again, raising new event",
__func__, again);
oi->t_ls_upd_event = NULL;
- thread_add_event(master, ospf_ls_upd_send_queue_event, oi, 0,
- &oi->t_ls_upd_event);
+ event_add_event(master, ospf_ls_upd_send_queue_event, oi, 0,
+ &oi->t_ls_upd_event);
}
if (IS_DEBUG_OSPF_EVENT)
@@ -4198,8 +4212,8 @@ void ospf_ls_upd_send(struct ospf_neighbor *nbr, struct list *update, int flag,
rn->p.u.prefix4, 1);
}
} else
- thread_add_event(master, ospf_ls_upd_send_queue_event, oi, 0,
- &oi->t_ls_upd_event);
+ event_add_event(master, ospf_ls_upd_send_queue_event, oi, 0,
+ &oi->t_ls_upd_event);
}
static void ospf_ls_ack_send_list(struct ospf_interface *oi, struct list *ack,
@@ -4236,9 +4250,9 @@ static void ospf_ls_ack_send_list(struct ospf_interface *oi, struct list *ack,
OSPF_ISM_WRITE_ON(oi->ospf);
}
-static void ospf_ls_ack_send_event(struct thread *thread)
+static void ospf_ls_ack_send_event(struct event *thread)
{
- struct ospf_interface *oi = THREAD_ARG(thread);
+ struct ospf_interface *oi = EVENT_ARG(thread);
oi->t_ls_ack_direct = NULL;
@@ -4262,8 +4276,8 @@ void ospf_ls_ack_send(struct ospf_neighbor *nbr, struct ospf_lsa *lsa)
listnode_add(oi->ls_ack_direct.ls_ack, ospf_lsa_lock(lsa));
- thread_add_event(master, ospf_ls_ack_send_event, oi, 0,
- &oi->t_ls_ack_direct);
+ event_add_event(master, ospf_ls_ack_send_event, oi, 0,
+ &oi->t_ls_ack_direct);
}
/* Send Link State Acknowledgment delayed. */
diff --git a/ospfd/ospf_packet.h b/ospfd/ospf_packet.h
index e8b279b9d8..4003e2add6 100644
--- a/ospfd/ospf_packet.h
+++ b/ospfd/ospf_packet.h
@@ -124,7 +124,7 @@ extern struct ospf_packet *ospf_fifo_head(struct ospf_fifo *);
extern void ospf_fifo_flush(struct ospf_fifo *);
extern void ospf_fifo_free(struct ospf_fifo *);
-extern void ospf_read(struct thread *thread);
+extern void ospf_read(struct event *thread);
extern void ospf_hello_send(struct ospf_interface *);
extern void ospf_db_desc_send(struct ospf_neighbor *);
extern void ospf_db_desc_resend(struct ospf_neighbor *);
@@ -137,10 +137,10 @@ extern void ospf_ls_ack_send_delayed(struct ospf_interface *);
extern void ospf_ls_retransmit(struct ospf_interface *, struct ospf_lsa *);
extern void ospf_ls_req_event(struct ospf_neighbor *);
-extern void ospf_ls_upd_timer(struct thread *thread);
-extern void ospf_ls_ack_timer(struct thread *thread);
-extern void ospf_poll_timer(struct thread *thread);
-extern void ospf_hello_reply_timer(struct thread *thread);
+extern void ospf_ls_upd_timer(struct event *thread);
+extern void ospf_ls_ack_timer(struct event *thread);
+extern void ospf_poll_timer(struct event *thread);
+extern void ospf_hello_reply_timer(struct event *thread);
extern const struct message ospf_packet_type_str[];
extern const size_t ospf_packet_type_str_max;
diff --git a/ospfd/ospf_ri.c b/ospfd/ospf_ri.c
index a808ddc9f6..0179f9ee0b 100644
--- a/ospfd/ospf_ri.c
+++ b/ospfd/ospf_ri.c
@@ -20,7 +20,7 @@
#include "vty.h"
#include "stream.h"
#include "log.h"
-#include "thread.h"
+#include "frrevent.h"
#include "hash.h"
#include "sockunion.h" /* for inet_aton() */
#include "mpls.h"
diff --git a/ospfd/ospf_route.c b/ospfd/ospf_route.c
index 5f18bff1cf..75868056ad 100644
--- a/ospfd/ospf_route.c
+++ b/ospfd/ospf_route.c
@@ -1008,7 +1008,8 @@ void ospf_prune_unreachable_routers(struct route_table *rtrs)
}
int ospf_add_discard_route(struct ospf *ospf, struct route_table *rt,
- struct ospf_area *area, struct prefix_ipv4 *p)
+ struct ospf_area *area, struct prefix_ipv4 *p,
+ bool nssa)
{
struct route_node *rn;
struct ospf_route * or, *new_or;
@@ -1027,7 +1028,7 @@ int ospf_add_discard_route(struct ospf *ospf, struct route_table *rt,
or = rn->info;
- if (or->path_type == OSPF_PATH_INTRA_AREA) {
+ if (!nssa && or->path_type == OSPF_PATH_INTRA_AREA) {
if (IS_DEBUG_OSPF_EVENT)
zlog_debug("%s: an intra-area route exists",
__func__);
@@ -1054,7 +1055,10 @@ int ospf_add_discard_route(struct ospf *ospf, struct route_table *rt,
new_or->cost = 0;
new_or->u.std.area_id = area->area_id;
new_or->u.std.external_routing = area->external_routing;
- new_or->path_type = OSPF_PATH_INTER_AREA;
+ if (nssa)
+ new_or->path_type = OSPF_PATH_TYPE2_EXTERNAL;
+ else
+ new_or->path_type = OSPF_PATH_INTER_AREA;
rn->info = new_or;
ospf_zebra_add_discard(ospf, p);
@@ -1063,7 +1067,7 @@ int ospf_add_discard_route(struct ospf *ospf, struct route_table *rt,
}
void ospf_delete_discard_route(struct ospf *ospf, struct route_table *rt,
- struct prefix_ipv4 *p)
+ struct prefix_ipv4 *p, bool nssa)
{
struct route_node *rn;
struct ospf_route * or ;
@@ -1081,7 +1085,7 @@ void ospf_delete_discard_route(struct ospf *ospf, struct route_table *rt,
or = rn->info;
- if (or->path_type == OSPF_PATH_INTRA_AREA) {
+ if (!nssa && or->path_type == OSPF_PATH_INTRA_AREA) {
if (IS_DEBUG_OSPF_EVENT)
zlog_debug("%s: an intra-area route exists", __func__);
return;
diff --git a/ospfd/ospf_route.h b/ospfd/ospf_route.h
index 2582067aec..7639a0049e 100644
--- a/ospfd/ospf_route.h
+++ b/ospfd/ospf_route.h
@@ -152,9 +152,10 @@ extern void ospf_route_subst_nexthops(struct ospf_route *, struct list *);
extern void ospf_prune_unreachable_networks(struct route_table *);
extern void ospf_prune_unreachable_routers(struct route_table *);
extern int ospf_add_discard_route(struct ospf *, struct route_table *,
- struct ospf_area *, struct prefix_ipv4 *);
+ struct ospf_area *, struct prefix_ipv4 *,
+ bool);
extern void ospf_delete_discard_route(struct ospf *, struct route_table *,
- struct prefix_ipv4 *);
+ struct prefix_ipv4 *, bool);
extern int ospf_route_match_same(struct route_table *, struct prefix_ipv4 *,
struct ospf_route *);
diff --git a/ospfd/ospf_routemap.c b/ospfd/ospf_routemap.c
index 3087008819..3d5c5aa2d5 100644
--- a/ospfd/ospf_routemap.c
+++ b/ospfd/ospf_routemap.c
@@ -120,7 +120,7 @@ route_match_ip_nexthop(void *rule, const struct prefix *prefix, void *object)
alist = access_list_lookup(AFI_IP, (char *)rule);
if (alist == NULL) {
- if (CHECK_FLAG(rmap_debug, DEBUG_ROUTEMAP_DETAIL))
+ if (unlikely(CHECK_FLAG(rmap_debug, DEBUG_ROUTEMAP_DETAIL)))
zlog_debug(
"%s: Access-List Specified: %s does not exist defaulting to NO_MATCH",
__func__, (char *)rule);
@@ -168,7 +168,7 @@ route_match_ip_next_hop_prefix_list(void *rule, const struct prefix *prefix,
plist = prefix_list_lookup(AFI_IP, (char *)rule);
if (plist == NULL) {
- if (CHECK_FLAG(rmap_debug, DEBUG_ROUTEMAP_DETAIL))
+ if (unlikely(CHECK_FLAG(rmap_debug, DEBUG_ROUTEMAP_DETAIL)))
zlog_debug(
"%s: Prefix List %s specified does not exist defaulting to NO_MATCH",
__func__, (char *)rule);
@@ -245,7 +245,7 @@ route_match_ip_address(void *rule, const struct prefix *prefix, void *object)
alist = access_list_lookup(AFI_IP, (char *)rule);
if (alist == NULL) {
- if (CHECK_FLAG(rmap_debug, DEBUG_ROUTEMAP_DETAIL))
+ if (unlikely(CHECK_FLAG(rmap_debug, DEBUG_ROUTEMAP_DETAIL)))
zlog_debug(
"%s: Access-List Specified: %s does not exist defaulting to NO_MATCH",
__func__, (char *)rule);
@@ -286,7 +286,7 @@ route_match_ip_address_prefix_list(void *rule, const struct prefix *prefix,
plist = prefix_list_lookup(AFI_IP, (char *)rule);
if (plist == NULL) {
- if (CHECK_FLAG(rmap_debug, DEBUG_ROUTEMAP_DETAIL))
+ if (unlikely(CHECK_FLAG(rmap_debug, DEBUG_ROUTEMAP_DETAIL)))
zlog_debug(
"%s: Prefix List %s specified does not exist defaulting to NO_MATCH",
__func__, (char *)rule);
diff --git a/ospfd/ospf_snmp.c b/ospfd/ospf_snmp.c
index fb9f36349a..fcc43e7311 100644
--- a/ospfd/ospf_snmp.c
+++ b/ospfd/ospf_snmp.c
@@ -1112,7 +1112,7 @@ static struct ospf_area_range *ospfAreaRangeLookup(struct variable *v,
oid2in_addr(offset, IN_ADDR_SIZE, range_net);
p.prefix = *range_net;
- return ospf_area_range_lookup(area, &p);
+ return ospf_area_range_lookup(area, area->ranges, &p);
} else {
/* Set OID offset for Area ID. */
offset = name + v->namelen;
@@ -2525,7 +2525,7 @@ static int ospf_snmp_ism_change(struct ospf_interface *oi, int state,
}
/* Register OSPF2-MIB. */
-static int ospf_snmp_init(struct thread_master *tm)
+static int ospf_snmp_init(struct event_loop *tm)
{
ospf_snmp_iflist = list_new();
ospf_snmp_vl_table = route_table_init();
diff --git a/ospfd/ospf_spf.c b/ospfd/ospf_spf.c
index 7c1f9f17ac..274d5bc9af 100644
--- a/ospfd/ospf_spf.c
+++ b/ospfd/ospf_spf.c
@@ -6,7 +6,7 @@
#include <zebra.h>
#include "monotime.h"
-#include "thread.h"
+#include "frrevent.h"
#include "memory.h"
#include "hash.h"
#include "linklist.h"
@@ -1764,7 +1764,8 @@ void ospf_spf_calculate(struct ospf_area *area, struct ospf_lsa *root_lsa,
if (v->type != OSPF_VERTEX_ROUTER)
ospf_intra_add_transit(new_table, v, area);
else {
- ospf_intra_add_router(new_rtrs, v, area, false);
+ if (new_rtrs)
+ ospf_intra_add_router(new_rtrs, v, area, false);
if (all_rtrs)
ospf_intra_add_router(all_rtrs, v, area, true);
}
@@ -1841,9 +1842,9 @@ void ospf_spf_calculate_areas(struct ospf *ospf, struct route_table *new_table,
}
/* Worker for SPF calculation scheduler. */
-static void ospf_spf_calculate_schedule_worker(struct thread *thread)
+static void ospf_spf_calculate_schedule_worker(struct event *thread)
{
- struct ospf *ospf = THREAD_ARG(thread);
+ struct ospf *ospf = EVENT_ARG(thread);
struct route_table *new_table, *new_rtrs;
struct route_table *all_rtrs = NULL;
struct timeval start_time, spf_start_time;
@@ -2043,8 +2044,8 @@ void ospf_spf_calculate_schedule(struct ospf *ospf, ospf_spf_reason_t reason)
zlog_debug("SPF: calculation timer delay = %ld msec", delay);
ospf->t_spf_calc = NULL;
- thread_add_timer_msec(master, ospf_spf_calculate_schedule_worker, ospf,
- delay, &ospf->t_spf_calc);
+ event_add_timer_msec(master, ospf_spf_calculate_schedule_worker, ospf,
+ delay, &ospf->t_spf_calc);
}
/* Restart OSPF SPF algorithm*/
diff --git a/ospfd/ospf_sr.c b/ospfd/ospf_sr.c
index adb14ec6b1..467cb0504d 100644
--- a/ospfd/ospf_sr.c
+++ b/ospfd/ospf_sr.c
@@ -37,7 +37,7 @@
#include "sockunion.h" /* for inet_aton() */
#include "stream.h"
#include "table.h"
-#include "thread.h"
+#include "frrevent.h"
#include "vty.h"
#include "zclient.h"
#include "sbuf.h"
@@ -457,11 +457,11 @@ int ospf_sr_local_block_release_label(mpls_label_t label)
*
* @return 1 on success
*/
-static void sr_start_label_manager(struct thread *start)
+static void sr_start_label_manager(struct event *start)
{
struct ospf *ospf;
- ospf = THREAD_ARG(start);
+ ospf = EVENT_ARG(start);
/* re-attempt to start SR & Label Manager connection */
ospf_sr_start(ospf);
@@ -496,8 +496,8 @@ static int ospf_sr_start(struct ospf *ospf)
if (!ospf_zebra_label_manager_ready())
if (ospf_zebra_label_manager_connect() < 0) {
/* Re-attempt to connect to Label Manager in 1 sec. */
- thread_add_timer(master, sr_start_label_manager, ospf,
- 1, &OspfSR.t_start_lm);
+ event_add_timer(master, sr_start_label_manager, ospf, 1,
+ &OspfSR.t_start_lm);
osr_debug(" |- Failed to start the Label Manager");
return -1;
}
@@ -565,7 +565,7 @@ static void ospf_sr_stop(void)
osr_debug("SR (%s): Stop Segment Routing", __func__);
/* Disable any re-attempt to connect to Label Manager */
- THREAD_OFF(OspfSR.t_start_lm);
+ EVENT_OFF(OspfSR.t_start_lm);
/* Release SRGB if active */
sr_global_block_delete();
@@ -639,10 +639,7 @@ void ospf_sr_term(void)
/* Stop Segment Routing */
ospf_sr_stop();
- /* Clear SR Node Table */
- if (OspfSR.neighbors)
- hash_free(OspfSR.neighbors);
-
+ hash_clean_and_free(&OspfSR.neighbors, (void *)sr_node_del);
}
/*
diff --git a/ospfd/ospf_sr.h b/ospfd/ospf_sr.h
index 2c189083be..fa61f669a7 100644
--- a/ospfd/ospf_sr.h
+++ b/ospfd/ospf_sr.h
@@ -243,7 +243,7 @@ struct ospf_sr_db {
uint8_t msd;
/* Thread timer to start Label Manager */
- struct thread *t_start_lm;
+ struct event *t_start_lm;
};
/* Structure aggregating all received SR info from LSAs by node */
diff --git a/ospfd/ospf_te.c b/ospfd/ospf_te.c
index e3869abe59..b140027147 100644
--- a/ospfd/ospf_te.c
+++ b/ospfd/ospf_te.c
@@ -24,7 +24,7 @@
#include "vty.h"
#include "stream.h"
#include "log.h"
-#include "thread.h"
+#include "frrevent.h"
#include "hash.h"
#include "sockunion.h" /* for inet_aton() */
#include "network.h"
@@ -1781,7 +1781,7 @@ static void ospf_te_update_link(struct ls_ted *ted, struct ls_vertex *vertex,
* @param metric Standard metric attached to this Edge
*/
static void ospf_te_update_subnet(struct ls_ted *ted, struct ls_vertex *vertex,
- struct prefix p, uint8_t metric)
+ struct prefix *p, uint8_t metric)
{
struct ls_subnet *subnet;
struct ls_prefix *ls_pref;
@@ -1840,7 +1840,7 @@ static void ospf_te_delete_subnet(struct ls_ted *ted, struct in_addr addr)
p.family = AF_INET;
p.prefixlen = IPV4_MAX_BITLEN;
p.u.prefix4 = addr;
- subnet = ls_find_subnet(ted, p);
+ subnet = ls_find_subnet(ted, &p);
/* Remove subnet if found */
if (subnet) {
@@ -1933,7 +1933,7 @@ static int ospf_te_parse_router_lsa(struct ls_ted *ted, struct ospf_lsa *lsa)
p.prefixlen = IPV4_MAX_BITLEN;
p.u.prefix4 = rl->link[i].link_data;
metric = ntohs(rl->link[i].metric);
- ospf_te_update_subnet(ted, vertex, p, metric);
+ ospf_te_update_subnet(ted, vertex, &p, metric);
break;
case LSA_LINK_TYPE_STUB:
/* Keep only /32 prefix */
@@ -1942,7 +1942,7 @@ static int ospf_te_parse_router_lsa(struct ls_ted *ted, struct ospf_lsa *lsa)
p.family = AF_INET;
p.u.prefix4 = rl->link[i].link_id;
metric = ntohs(rl->link[i].metric);
- ospf_te_update_subnet(ted, vertex, p, metric);
+ ospf_te_update_subnet(ted, vertex, &p, metric);
}
break;
default:
@@ -2074,12 +2074,12 @@ static void ospf_te_update_remote_asbr(struct ls_ted *ted, struct ls_edge *edge)
p.family = AF_INET;
p.prefixlen = IPV4_MAX_BITLEN;
p.u.prefix4 = attr->standard.local;
- ospf_te_update_subnet(ted, edge->source, p, attr->standard.te_metric);
+ ospf_te_update_subnet(ted, edge->source, &p, attr->standard.te_metric);
p.family = AF_INET;
p.prefixlen = IPV4_MAX_BITLEN;
p.u.prefix4 = attr->standard.remote_addr;
- ospf_te_update_subnet(ted, vertex, p, attr->standard.te_metric);
+ ospf_te_update_subnet(ted, vertex, &p, attr->standard.te_metric);
/* Connect Edge to the remote Vertex */
if (edge->destination == NULL) {
@@ -2625,14 +2625,14 @@ static int ospf_te_parse_ext_pref(struct ls_ted *ted, struct ospf_lsa *lsa)
pref.family = AF_INET;
pref.prefixlen = ext->pref_length;
pref.u.prefix4 = ext->address;
- subnet = ls_find_subnet(ted, pref);
+ subnet = ls_find_subnet(ted, &pref);
/* Create new Link State Prefix if not found */
if (!subnet) {
lnid.origin = OSPFv2;
lnid.id.ip.addr = lsa->data->adv_router;
lnid.id.ip.area_id = lsa->area->area_id;
- ls_pref = ls_prefix_new(lnid, pref);
+ ls_pref = ls_prefix_new(lnid, &pref);
/* and add it to the TED */
subnet = ls_subnet_add(ted, ls_pref);
}
@@ -2698,7 +2698,7 @@ static int ospf_te_delete_ext_pref(struct ls_ted *ted, struct ospf_lsa *lsa)
pref.family = AF_INET;
pref.prefixlen = ext->pref_length;
pref.u.prefix4 = ext->address;
- subnet = ls_find_subnet(ted, pref);
+ subnet = ls_find_subnet(ted, &pref);
/* Check if there is a corresponding subnet */
if (!subnet)
@@ -4398,7 +4398,7 @@ DEFUN (show_ip_ospf_mpls_te_db,
return CMD_WARNING_CONFIG_FAILED;
}
/* Get the Subnet from the Link State Database */
- subnet = ls_find_subnet(OspfMplsTE.ted, pref);
+ subnet = ls_find_subnet(OspfMplsTE.ted, &pref);
if (!subnet) {
vty_out(vty, "No subnet found for ID %pFX\n",
&pref);
diff --git a/ospfd/ospf_ti_lfa.c b/ospfd/ospf_ti_lfa.c
index b14200868e..da9428aba6 100644
--- a/ospfd/ospf_ti_lfa.c
+++ b/ospfd/ospf_ti_lfa.c
@@ -237,7 +237,7 @@ static void ospf_ti_lfa_generate_inner_label_stack(
struct q_space *q_space,
struct ospf_ti_lfa_inner_backup_path_info *inner_backup_path_info)
{
- struct route_table *new_table, *new_rtrs;
+ struct route_table *new_table;
struct vertex *q_node;
struct vertex *start_vertex, *end_vertex;
struct vertex_parent *vertex_parent;
@@ -300,7 +300,6 @@ static void ospf_ti_lfa_generate_inner_label_stack(
start_vertex, end_vertex);
new_table = route_table_init();
- new_rtrs = route_table_init();
/* Copy the current state ... */
spf_orig = area->spf;
@@ -311,7 +310,7 @@ static void ospf_ti_lfa_generate_inner_label_stack(
XCALLOC(MTYPE_OSPF_P_SPACE, sizeof(struct p_spaces_head));
/* dry run true, root node false */
- ospf_spf_calculate(area, start_vertex->lsa_p, new_table, NULL, new_rtrs,
+ ospf_spf_calculate(area, start_vertex->lsa_p, new_table, NULL, NULL,
true, false);
q_node = ospf_spf_vertex_find(end_vertex->id, area->spf_vertex_list);
@@ -622,7 +621,7 @@ static void ospf_ti_lfa_generate_q_spaces(struct ospf_area *area,
{
struct listnode *node;
struct vertex *child;
- struct route_table *new_table, *new_rtrs;
+ struct route_table *new_table;
struct q_space *q_space, q_space_search;
char label_buf[MPLS_LABEL_STRLEN];
char res_buf[PROTECTED_RESOURCE_STRLEN];
@@ -661,15 +660,13 @@ static void ospf_ti_lfa_generate_q_spaces(struct ospf_area *area,
sizeof(struct ospf_ti_lfa_node_info));
new_table = route_table_init();
- /* XXX do these get freed?? */
- new_rtrs = route_table_init();
/*
* Generate a new (reversed!) SPF tree for this vertex,
* dry run true, root node false
*/
area->spf_reversed = true;
- ospf_spf_calculate(area, dest->lsa_p, new_table, NULL, new_rtrs, true,
+ ospf_spf_calculate(area, dest->lsa_p, new_table, NULL, NULL, true,
false);
/* Reset the flag for reverse SPF */
@@ -692,6 +689,11 @@ static void ospf_ti_lfa_generate_q_spaces(struct ospf_area *area,
"%s: NO backup path found for root %pI4 and destination %pI4 for %s, aborting ...",
__func__, &p_space->root->id, &q_space->root->id,
res_buf);
+
+ XFREE(MTYPE_OSPF_Q_SPACE, q_space->p_node_info);
+ XFREE(MTYPE_OSPF_Q_SPACE, q_space->q_node_info);
+ XFREE(MTYPE_OSPF_Q_SPACE, q_space);
+
return;
}
@@ -734,11 +736,9 @@ static void ospf_ti_lfa_generate_q_spaces(struct ospf_area *area,
static void ospf_ti_lfa_generate_post_convergence_spf(struct ospf_area *area,
struct p_space *p_space)
{
- struct route_table *new_table, *new_rtrs;
+ struct route_table *new_table;
new_table = route_table_init();
- /* XXX do these get freed?? */
- new_rtrs = route_table_init();
area->spf_protected_resource = p_space->protected_resource;
@@ -757,8 +757,8 @@ static void ospf_ti_lfa_generate_post_convergence_spf(struct ospf_area *area,
* endeavour (because LSAs are stored as a 'raw' stream), so we go with
* this rather hacky way for now.
*/
- ospf_spf_calculate(area, area->router_lsa_self, new_table, NULL,
- new_rtrs, true, false);
+ ospf_spf_calculate(area, area->router_lsa_self, new_table, NULL, NULL,
+ true, false);
p_space->pc_spf = area->spf;
p_space->pc_vertex_list = area->spf_vertex_list;
diff --git a/ospfd/ospf_vty.c b/ospfd/ospf_vty.c
index eb03a9c3a7..9b918798c0 100644
--- a/ospfd/ospf_vty.c
+++ b/ospfd/ospf_vty.c
@@ -10,7 +10,7 @@
#include "printfrr.h"
#include "monotime.h"
#include "memory.h"
-#include "thread.h"
+#include "frrevent.h"
#include "prefix.h"
#include "table.h"
#include "vty.h"
@@ -611,6 +611,7 @@ DEFUN (ospf_area_range,
"Advertised metric for this range\n")
{
VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
+ struct ospf_area *area;
int idx_ipv4_number = 1;
int idx_ipv4_prefixlen = 3;
int idx_cost = 6;
@@ -622,12 +623,14 @@ DEFUN (ospf_area_range,
VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg);
str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p);
- ospf_area_range_set(ospf, area_id, &p, OSPF_AREA_RANGE_ADVERTISE);
- ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id),
- format);
+ area = ospf_area_get(ospf, area_id);
+ ospf_area_display_format_set(ospf, area, format);
+
+ ospf_area_range_set(ospf, area, area->ranges, &p,
+ OSPF_AREA_RANGE_ADVERTISE, false);
if (argc > 5) {
cost = strtoul(argv[idx_cost]->arg, NULL, 10);
- ospf_area_range_cost_set(ospf, area_id, &p, cost);
+ ospf_area_range_cost_set(ospf, area, area->ranges, &p, cost);
}
return CMD_SUCCESS;
@@ -647,6 +650,7 @@ DEFUN (ospf_area_range_cost,
"Network prefix to be announced instead of range\n")
{
VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
+ struct ospf_area *area;
int idx_ipv4_number = 1;
int idx_ipv4_prefixlen = 3;
int idx = 4;
@@ -658,19 +662,20 @@ DEFUN (ospf_area_range_cost,
VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg);
str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p);
- ospf_area_range_set(ospf, area_id, &p, OSPF_AREA_RANGE_ADVERTISE);
- ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id),
- format);
+ area = ospf_area_get(ospf, area_id);
+ ospf_area_display_format_set(ospf, area, format);
+ ospf_area_range_set(ospf, area, area->ranges, &p,
+ OSPF_AREA_RANGE_ADVERTISE, false);
if (argv_find(argv, argc, "cost", &idx)) {
cost = strtoul(argv[idx + 1]->arg, NULL, 10);
- ospf_area_range_cost_set(ospf, area_id, &p, cost);
+ ospf_area_range_cost_set(ospf, area, area->ranges, &p, cost);
}
idx = 4;
if (argv_find(argv, argc, "substitute", &idx)) {
str2prefix_ipv4(argv[idx + 1]->arg, &s);
- ospf_area_range_substitute_set(ospf, area_id, &p, &s);
+ ospf_area_range_substitute_set(ospf, area, &p, &s);
}
return CMD_SUCCESS;
@@ -687,6 +692,7 @@ DEFUN (ospf_area_range_not_advertise,
"DoNotAdvertise this range\n")
{
VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
+ struct ospf_area *area;
int idx_ipv4_number = 1;
int idx_ipv4_prefixlen = 3;
struct prefix_ipv4 p;
@@ -696,10 +702,11 @@ DEFUN (ospf_area_range_not_advertise,
VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg);
str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p);
- ospf_area_range_set(ospf, area_id, &p, 0);
- ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id),
- format);
- ospf_area_range_substitute_unset(ospf, area_id, &p);
+ area = ospf_area_get(ospf, area_id);
+ ospf_area_display_format_set(ospf, area, format);
+
+ ospf_area_range_set(ospf, area, area->ranges, &p, 0, false);
+ ospf_area_range_substitute_unset(ospf, area, &p);
return CMD_SUCCESS;
}
@@ -721,6 +728,7 @@ DEFUN (no_ospf_area_range,
"DoNotAdvertise this range\n")
{
VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
+ struct ospf_area *area;
int idx_ipv4_number = 2;
int idx_ipv4_prefixlen = 4;
struct prefix_ipv4 p;
@@ -730,7 +738,10 @@ DEFUN (no_ospf_area_range,
VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg);
str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p);
- ospf_area_range_unset(ospf, area_id, &p);
+ area = ospf_area_get(ospf, area_id);
+ ospf_area_display_format_set(ospf, area, format);
+
+ ospf_area_range_unset(ospf, area, area->ranges, &p);
return CMD_SUCCESS;
}
@@ -748,6 +759,7 @@ DEFUN (no_ospf_area_range_substitute,
"Network prefix to be announced instead of range\n")
{
VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
+ struct ospf_area *area;
int idx_ipv4_number = 2;
int idx_ipv4_prefixlen = 4;
int idx_ipv4_prefixlen_2 = 6;
@@ -759,7 +771,10 @@ DEFUN (no_ospf_area_range_substitute,
str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p);
str2prefix_ipv4(argv[idx_ipv4_prefixlen_2]->arg, &s);
- ospf_area_range_substitute_unset(ospf, area_id, &p);
+ area = ospf_area_get(ospf, area_id);
+ ospf_area_display_format_set(ospf, area, format);
+
+ ospf_area_range_substitute_unset(ospf, area, &p);
return CMD_SUCCESS;
}
@@ -1433,15 +1448,35 @@ DEFUN (no_ospf_area_stub_no_summary,
return CMD_SUCCESS;
}
-static int ospf_area_nssa_cmd_handler(struct vty *vty, int argc,
- struct cmd_token **argv, int cfg_nosum,
- int nosum)
+DEFPY (ospf_area_nssa,
+ ospf_area_nssa_cmd,
+ "area <A.B.C.D|(0-4294967295)>$area_str nssa\
+ [{\
+ <translate-candidate|translate-never|translate-always>$translator_role\
+ |default-information-originate$dflt_originate [{metric (0-16777214)$mval|metric-type (1-2)$mtype}]\
+ |no-summary$no_summary\
+ |suppress-fa$suppress_fa\
+ }]",
+ "OSPF area parameters\n"
+ "OSPF area ID in IP address format\n"
+ "OSPF area ID as a decimal value\n"
+ "Configure OSPF area as nssa\n"
+ "Configure NSSA-ABR for translate election (default)\n"
+ "Configure NSSA-ABR to never translate\n"
+ "Configure NSSA-ABR to always translate\n"
+ "Originate Type 7 default into NSSA area\n"
+ "OSPF default metric\n"
+ "OSPF metric\n"
+ "OSPF metric type for default routes\n"
+ "Set OSPF External Type 1/2 metrics\n"
+ "Do not inject inter-area routes into nssa\n"
+ "Suppress forwarding address\n")
{
VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
struct in_addr area_id;
int ret, format;
- VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id, format, argv[1]->arg);
+ VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id, format, area_str);
ret = ospf_area_nssa_set(ospf, area_id);
ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id),
@@ -1452,14 +1487,14 @@ static int ospf_area_nssa_cmd_handler(struct vty *vty, int argc,
return CMD_WARNING_CONFIG_FAILED;
}
- if (argc > 3) {
- if (strncmp(argv[3]->text, "translate-c", 11) == 0)
+ if (translator_role) {
+ if (strncmp(translator_role, "translate-c", 11) == 0)
ospf_area_nssa_translator_role_set(
ospf, area_id, OSPF_NSSA_ROLE_CANDIDATE);
- else if (strncmp(argv[3]->text, "translate-n", 11) == 0)
+ else if (strncmp(translator_role, "translate-n", 11) == 0)
ospf_area_nssa_translator_role_set(
ospf, area_id, OSPF_NSSA_ROLE_NEVER);
- else if (strncmp(argv[3]->text, "translate-a", 11) == 0)
+ else if (strncmp(translator_role, "translate-a", 11) == 0)
ospf_area_nssa_translator_role_set(
ospf, area_id, OSPF_NSSA_ROLE_ALWAYS);
} else {
@@ -1467,12 +1502,27 @@ static int ospf_area_nssa_cmd_handler(struct vty *vty, int argc,
OSPF_NSSA_ROLE_CANDIDATE);
}
- if (cfg_nosum) {
- if (nosum)
- ospf_area_no_summary_set(ospf, area_id);
- else
- ospf_area_no_summary_unset(ospf, area_id);
- }
+ if (dflt_originate) {
+ int metric_type = DEFAULT_METRIC_TYPE;
+
+ if (mval_str == NULL)
+ mval = -1;
+ if (mtype_str)
+ (void)str2metric_type(mtype_str, &metric_type);
+ ospf_area_nssa_default_originate_set(ospf, area_id, mval,
+ metric_type);
+ } else
+ ospf_area_nssa_default_originate_unset(ospf, area_id);
+
+ if (no_summary)
+ ospf_area_nssa_no_summary_set(ospf, area_id);
+ else
+ ospf_area_no_summary_unset(ospf, area_id);
+
+ if (suppress_fa)
+ ospf_area_nssa_suppress_fa_set(ospf, area_id);
+ else
+ ospf_area_nssa_suppress_fa_unset(ospf, area_id);
/* Flush the external LSA for the specified area */
ospf_flush_lsa_from_area(ospf, area_id, OSPF_AS_EXTERNAL_LSA);
@@ -1482,168 +1532,125 @@ static int ospf_area_nssa_cmd_handler(struct vty *vty, int argc,
return CMD_SUCCESS;
}
-
-DEFUN (ospf_area_nssa_translate,
- ospf_area_nssa_translate_cmd,
- "area <A.B.C.D|(0-4294967295)> nssa <translate-candidate|translate-never|translate-always>",
+DEFPY (no_ospf_area_nssa,
+ no_ospf_area_nssa_cmd,
+ "no area <A.B.C.D|(0-4294967295)>$area_str nssa\
+ [{\
+ <translate-candidate|translate-never|translate-always>\
+ |default-information-originate [{metric (0-16777214)|metric-type (1-2)}]\
+ |no-summary\
+ |suppress-fa\
+ }]",
+ NO_STR
"OSPF area parameters\n"
"OSPF area ID in IP address format\n"
"OSPF area ID as a decimal value\n"
"Configure OSPF area as nssa\n"
"Configure NSSA-ABR for translate election (default)\n"
"Configure NSSA-ABR to never translate\n"
- "Configure NSSA-ABR to always translate\n")
-{
- return ospf_area_nssa_cmd_handler(vty, argc, argv, 0, 0);
-}
-
-DEFUN (ospf_area_nssa,
- ospf_area_nssa_cmd,
- "area <A.B.C.D|(0-4294967295)> nssa",
- "OSPF area parameters\n"
- "OSPF area ID in IP address format\n"
- "OSPF area ID as a decimal value\n"
- "Configure OSPF area as nssa\n")
-{
- return ospf_area_nssa_cmd_handler(vty, argc, argv, 0, 0);
-}
-
-DEFUN(ospf_area_nssa_suppress_fa, ospf_area_nssa_suppress_fa_cmd,
- "area <A.B.C.D|(0-4294967295)> nssa suppress-fa",
- "OSPF area parameters\n"
- "OSPF area ID in IP address format\n"
- "OSPF area ID as a decimal value\n"
- "Configure OSPF area as nssa\n"
- "Suppress forwarding address\n")
+ "Configure NSSA-ABR to always translate\n"
+ "Originate Type 7 default into NSSA area\n"
+ "OSPF default metric\n"
+ "OSPF metric\n"
+ "OSPF metric type for default routes\n"
+ "Set OSPF External Type 1/2 metrics\n"
+ "Do not inject inter-area routes into nssa\n"
+ "Suppress forwarding address\n")
{
- int idx_ipv4_number = 1;
- struct in_addr area_id;
- int format;
-
VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
- VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id, format,
- argv[idx_ipv4_number]->arg);
-
- ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id),
- format);
- ospf_area_nssa_suppress_fa_set(ospf, area_id);
-
- ospf_schedule_abr_task(ospf);
-
- return CMD_SUCCESS;
-}
-
-DEFUN(no_ospf_area_nssa_suppress_fa, no_ospf_area_nssa_suppress_fa_cmd,
- "no area <A.B.C.D|(0-4294967295)> nssa suppress-fa",
- NO_STR
- "OSPF area parameters\n"
- "OSPF area ID in IP address format\n"
- "OSPF area ID as a decimal value\n"
- "Configure OSPF area as nssa\n"
- "Suppress forwarding address\n")
-{
- int idx_ipv4_number = 2;
struct in_addr area_id;
int format;
- VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
-
- VTY_GET_OSPF_AREA_ID_NO_BB("nssa", area_id, format,
- argv[idx_ipv4_number]->arg);
+ VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id, format, area_str);
- ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id),
- format);
+ /* Flush the NSSA LSA for the specified area */
+ ospf_flush_lsa_from_area(ospf, area_id, OSPF_AS_NSSA_LSA);
+ ospf_area_no_summary_unset(ospf, area_id);
+ ospf_area_nssa_default_originate_unset(ospf, area_id);
ospf_area_nssa_suppress_fa_unset(ospf, area_id);
+ ospf_area_nssa_unset(ospf, area_id);
ospf_schedule_abr_task(ospf);
return CMD_SUCCESS;
}
-DEFUN (ospf_area_nssa_no_summary,
- ospf_area_nssa_no_summary_cmd,
- "area <A.B.C.D|(0-4294967295)> nssa no-summary",
+DEFPY (ospf_area_nssa_range,
+ ospf_area_nssa_range_cmd,
+ "area <A.B.C.D|(0-4294967295)>$area_str nssa range A.B.C.D/M$prefix [<not-advertise$not_adv|cost (0-16777215)$cost>]",
"OSPF area parameters\n"
"OSPF area ID in IP address format\n"
"OSPF area ID as a decimal value\n"
"Configure OSPF area as nssa\n"
- "Do not inject inter-area routes into nssa\n")
+ "Configured address range\n"
+ "Specify IPv4 prefix\n"
+ "Do not advertise\n"
+ "User specified metric for this range\n"
+ "Advertised metric for this range\n")
{
- int idx_ipv4_number = 1;
- struct in_addr area_id;
- int format;
-
VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
- VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id, format,
- argv[idx_ipv4_number]->arg);
-
- ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id),
- format);
- ospf_area_nssa_no_summary_set(ospf, area_id);
-
- ospf_schedule_abr_task(ospf);
-
- return CMD_SUCCESS;
-}
-
-DEFUN (no_ospf_area_nssa_no_summary,
- no_ospf_area_nssa_no_summary_cmd,
- "no area <A.B.C.D|(0-4294967295)> nssa no-summary",
- NO_STR
- "OSPF area parameters\n"
- "OSPF area ID in IP address format\n"
- "OSPF area ID as a decimal value\n"
- "Configure OSPF area as nssa\n"
- "Do not inject inter-area routes into nssa\n")
-{
- int idx_ipv4_number = 2;
+ struct ospf_area *area;
struct in_addr area_id;
int format;
+ int advertise = 0;
- VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
+ VTY_GET_OSPF_AREA_ID(area_id, format, area_str);
+ area = ospf_area_get(ospf, area_id);
+ ospf_area_display_format_set(ospf, area, format);
- VTY_GET_OSPF_AREA_ID_NO_BB("nssa", area_id, format,
- argv[idx_ipv4_number]->arg);
+ if (area->external_routing != OSPF_AREA_NSSA) {
+ vty_out(vty, "%% First configure %s as an NSSA area\n",
+ area_str);
+ return CMD_WARNING;
+ }
- ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id),
- format);
- ospf_area_no_summary_unset(ospf, area_id);
+ if (!not_adv)
+ advertise = OSPF_AREA_RANGE_ADVERTISE;
- ospf_schedule_abr_task(ospf);
+ ospf_area_range_set(ospf, area, area->nssa_ranges,
+ (struct prefix_ipv4 *)prefix, advertise, true);
+ if (cost_str)
+ ospf_area_range_cost_set(ospf, area, area->nssa_ranges,
+ (struct prefix_ipv4 *)prefix, cost);
return CMD_SUCCESS;
}
-DEFUN (no_ospf_area_nssa,
- no_ospf_area_nssa_cmd,
- "no area <A.B.C.D|(0-4294967295)> nssa [<translate-candidate|translate-never|translate-always>]",
+DEFPY (no_ospf_area_nssa_range,
+ no_ospf_area_nssa_range_cmd,
+ "no area <A.B.C.D|(0-4294967295)>$area_str nssa range A.B.C.D/M$prefix [<not-advertise|cost (0-16777215)>]",
NO_STR
"OSPF area parameters\n"
"OSPF area ID in IP address format\n"
"OSPF area ID as a decimal value\n"
"Configure OSPF area as nssa\n"
- "Configure NSSA-ABR for translate election (default)\n"
- "Configure NSSA-ABR to never translate\n"
- "Configure NSSA-ABR to always translate\n")
+ "Configured address range\n"
+ "Specify IPv4 prefix\n"
+ "Do not advertise\n"
+ "User specified metric for this range\n"
+ "Advertised metric for this range\n")
{
VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
- int idx_ipv4_number = 2;
+ struct ospf_area *area;
struct in_addr area_id;
int format;
- VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id, format,
- argv[idx_ipv4_number]->arg);
+ VTY_GET_OSPF_AREA_ID(area_id, format, area_str);
+ area = ospf_area_get(ospf, area_id);
+ ospf_area_display_format_set(ospf, area, format);
- /* Flush the NSSA LSA for the specified area */
- ospf_flush_lsa_from_area(ospf, area_id, OSPF_AS_NSSA_LSA);
- ospf_area_nssa_unset(ospf, area_id, argc);
+ if (area->external_routing != OSPF_AREA_NSSA) {
+ vty_out(vty, "%% First configure %s as an NSSA area\n",
+ area_str);
+ return CMD_WARNING;
+ }
- ospf_schedule_abr_task(ospf);
+ ospf_area_range_unset(ospf, area, area->nssa_ranges,
+ (struct prefix_ipv4 *)prefix);
return CMD_SUCCESS;
}
-
DEFUN (ospf_area_default_cost,
ospf_area_default_cost_cmd,
"area <A.B.C.D|(0-4294967295)> default-cost (0-16777215)",
@@ -3396,6 +3403,23 @@ static int show_ip_ospf_common(struct vty *vty, struct ospf *ospf,
/* show LDP-Sync status */
ospf_ldp_sync_show_info(vty, ospf, json_vrf, json ? 1 : 0);
+ /* Socket buffer sizes */
+ if (json) {
+ if (ospf->recv_sock_bufsize != OSPF_DEFAULT_SOCK_BUFSIZE)
+ json_object_int_add(json_vrf, "recvSockBufsize",
+ ospf->recv_sock_bufsize);
+ if (ospf->send_sock_bufsize != OSPF_DEFAULT_SOCK_BUFSIZE)
+ json_object_int_add(json_vrf, "sendSockBufsize",
+ ospf->send_sock_bufsize);
+ } else {
+ if (ospf->recv_sock_bufsize != OSPF_DEFAULT_SOCK_BUFSIZE)
+ vty_out(vty, " Receive socket bufsize: %u\n",
+ ospf->recv_sock_bufsize);
+ if (ospf->send_sock_bufsize != OSPF_DEFAULT_SOCK_BUFSIZE)
+ vty_out(vty, " Send socket bufsize: %u\n",
+ ospf->send_sock_bufsize);
+ }
+
/* Show each area status. */
for (ALL_LIST_ELEMENTS(ospf->areas, node, nnode, area))
show_ip_ospf_area(vty, area, json_areas, json ? 1 : 0);
@@ -5065,6 +5089,7 @@ static void show_ip_ospf_neighbor_detail_sub(struct vty *vty,
json_object *json_neigh = NULL, *json_neigh_array = NULL;
char neigh_str[INET_ADDRSTRLEN] = {0};
char neigh_state[16] = {0};
+ struct ospf_neighbor *nbr_dr, *nbr_bdr;
if (use_json) {
if (prev_nbr &&
@@ -5192,19 +5217,38 @@ static void show_ip_ospf_neighbor_detail_sub(struct vty *vty,
}
}
- /* Show Designated Rotuer ID. */
- if (use_json)
- json_object_string_addf(json_neigh, "routerDesignatedId",
- "%pI4", &nbr->d_router);
- else
- vty_out(vty, " DR is %pI4,", &nbr->d_router);
+ /* Show Designated Router ID. */
+ if (DR(oi).s_addr == INADDR_ANY) {
+ if (!use_json)
+ vty_out(vty,
+ " No designated router on this network\n");
+ } else {
+ nbr_dr = ospf_nbr_lookup_by_addr(oi->nbrs, &DR(oi));
+ if (nbr_dr) {
+ if (use_json)
+ json_object_string_addf(
+ json_neigh, "routerDesignatedId",
+ "%pI4", &nbr_dr->router_id);
+ else
+ vty_out(vty, " DR is %pI4,",
+ &nbr_dr->router_id);
+ }
+ }
- /* Show Backup Designated Rotuer ID. */
- if (use_json)
- json_object_string_addf(json_neigh, "routerDesignatedBackupId",
- "%pI4", &nbr->bd_router);
- else
- vty_out(vty, " BDR is %pI4\n", &nbr->bd_router);
+ /* Show Backup Designated Router ID. */
+ nbr_bdr = ospf_nbr_lookup_by_addr(oi->nbrs, &BDR(oi));
+ if (nbr_bdr == NULL) {
+ if (!use_json)
+ vty_out(vty,
+ " No backup designated router on this network\n");
+ } else {
+ if (use_json)
+ json_object_string_addf(json_neigh,
+ "routerDesignatedBackupId",
+ "%pI4", &nbr_bdr->router_id);
+ else
+ vty_out(vty, " BDR is %pI4\n", &nbr_bdr->router_id);
+ }
/* Show options. */
if (use_json) {
@@ -6800,31 +6844,24 @@ static void show_lsa_detail_adv_router_proc(struct vty *vty,
struct in_addr *adv_router,
json_object *json)
{
- char buf[PREFIX_STRLEN];
struct route_node *rn;
struct ospf_lsa *lsa;
+ json_object *json_lsa = NULL;
for (rn = route_top(rt); rn; rn = route_next(rn))
if ((lsa = rn->info)) {
- json_object *json_lsa = NULL;
-
if (IPV4_ADDR_SAME(adv_router,
&lsa->data->adv_router)) {
if (CHECK_FLAG(lsa->flags, OSPF_LSA_LOCAL_XLT))
continue;
- if (json)
+ if (json) {
json_lsa = json_object_new_object();
+ json_object_array_add(json, json_lsa);
+ }
if (show_function[lsa->data->type] != NULL)
show_function[lsa->data->type](
vty, lsa, json_lsa);
- if (json)
- json_object_object_add(
- json,
- inet_ntop(AF_INET,
- &lsa->data->id,
- buf, sizeof(buf)),
- json_lsa);
}
}
}
@@ -6837,11 +6874,12 @@ static void show_lsa_detail_adv_router(struct vty *vty, struct ospf *ospf,
struct listnode *node;
struct ospf_area *area;
char buf[PREFIX_STRLEN];
- json_object *json_lstype = NULL;
- json_object *json_area = NULL;
+ json_object *json_lsa_type = NULL;
+ json_object *json_areas = NULL;
+ json_object *json_lsa_array = NULL;
if (json)
- json_lstype = json_object_new_object();
+ json_lsa_type = json_object_new_object();
switch (type) {
case OSPF_AS_EXTERNAL_LSA:
@@ -6849,38 +6887,49 @@ static void show_lsa_detail_adv_router(struct vty *vty, struct ospf *ospf,
if (!json)
vty_out(vty, " %s \n\n",
show_database_desc[type]);
+ else
+ json_lsa_array = json_object_new_array();
show_lsa_detail_adv_router_proc(vty, AS_LSDB(ospf, type),
- adv_router, json_lstype);
+ adv_router, json_lsa_array);
+ if (json)
+ json_object_object_add(json,
+ show_database_desc_json[type],
+ json_lsa_array);
break;
default:
+ if (json)
+ json_areas = json_object_new_object();
for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) {
- if (json)
- json_area = json_object_new_object();
- else
+ if (!json) {
vty_out(vty,
"\n %s (Area %s)\n\n",
show_database_desc[type],
ospf_area_desc_string(area));
- show_lsa_detail_adv_router_proc(vty,
- AREA_LSDB(area, type),
- adv_router, json_area);
+ } else {
+ json_lsa_array = json_object_new_array();
+ json_object_object_add(
+ json_areas,
+ inet_ntop(AF_INET, &area->area_id, buf,
+ sizeof(buf)),
+ json_lsa_array);
+ }
- if (json)
- json_object_object_add(json_lstype,
- inet_ntop(AF_INET,
- &area->area_id,
- buf,
- sizeof(buf)),
- json_area);
+ show_lsa_detail_adv_router_proc(
+ vty, AREA_LSDB(area, type), adv_router,
+ json_lsa_array);
+ }
+
+ if (json) {
+ json_object_object_add(json_lsa_type, "areas",
+ json_areas);
+ json_object_object_add(json,
+ show_database_desc_json[type],
+ json_lsa_type);
}
break;
}
-
- if (json)
- json_object_object_add(json, show_database_desc[type],
- json_lstype);
}
void show_ip_ospf_database_summary(struct vty *vty, struct ospf *ospf, int self,
@@ -7084,15 +7133,13 @@ static void show_ip_ospf_database_maxage(struct vty *vty, struct ospf *ospf,
OSPF_LSA_TYPE_OPAQUE_LINK_DESC OSPF_LSA_TYPE_OPAQUE_AREA_DESC \
OSPF_LSA_TYPE_OPAQUE_AS_DESC
-static int show_ip_ospf_database_common(struct vty *vty, struct ospf *ospf,
- int arg_base, int argc,
- struct cmd_token **argv,
- uint8_t use_vrf, json_object *json,
- bool uj)
+static int
+show_ip_ospf_database_common(struct vty *vty, struct ospf *ospf, bool maxage,
+ bool self, bool detail, const char *type_name,
+ struct in_addr *lsid, struct in_addr *adv_router,
+ bool use_vrf, json_object *json, bool uj)
{
- int idx_type = 4;
- int type, ret;
- struct in_addr id, adv_router;
+ int type;
json_object *json_vrf = NULL;
if (uj) {
@@ -7121,298 +7168,79 @@ static int show_ip_ospf_database_common(struct vty *vty, struct ospf *ospf,
&ospf->router_id);
}
- /* Show all LSA. */
- if ((argc == arg_base + 4) || (uj && (argc == arg_base + 5))) {
- show_ip_ospf_database_summary(vty, ospf, 0, json_vrf);
- if (json) {
- if (use_vrf)
- json_object_object_add(
- json, ospf_get_name(ospf), json_vrf);
- }
- return CMD_SUCCESS;
- }
-
- /* Set database type to show. */
- if (strncmp(argv[arg_base + idx_type]->text, "r", 1) == 0)
- type = OSPF_ROUTER_LSA;
- else if (strncmp(argv[arg_base + idx_type]->text, "ne", 2) == 0)
- type = OSPF_NETWORK_LSA;
- else if (strncmp(argv[arg_base + idx_type]->text, "ns", 2) == 0)
- type = OSPF_AS_NSSA_LSA;
- else if (strncmp(argv[arg_base + idx_type]->text, "su", 2) == 0)
- type = OSPF_SUMMARY_LSA;
- else if (strncmp(argv[arg_base + idx_type]->text, "a", 1) == 0)
- type = OSPF_ASBR_SUMMARY_LSA;
- else if (strncmp(argv[arg_base + idx_type]->text, "e", 1) == 0)
- type = OSPF_AS_EXTERNAL_LSA;
- else if (strncmp(argv[arg_base + idx_type]->text, "se", 2) == 0) {
- show_ip_ospf_database_summary(vty, ospf, 1, json_vrf);
- if (json) {
- if (use_vrf)
- json_object_object_add(
- json, ospf_get_name(ospf), json_vrf);
- }
- return CMD_SUCCESS;
- } else if (strncmp(argv[arg_base + idx_type]->text, "m", 1) == 0) {
+ /* Show MaxAge LSAs */
+ if (maxage) {
show_ip_ospf_database_maxage(vty, ospf, json_vrf);
if (json) {
- if (use_vrf)
- json_object_object_add(
- json, ospf_get_name(ospf), json_vrf);
- }
- return CMD_SUCCESS;
- } else if (strncmp(argv[arg_base + idx_type]->text, "opaque-l", 8) == 0)
- type = OSPF_OPAQUE_LINK_LSA;
- else if (strncmp(argv[arg_base + idx_type]->text, "opaque-ar", 9) == 0)
- type = OSPF_OPAQUE_AREA_LSA;
- else if (strncmp(argv[arg_base + idx_type]->text, "opaque-as", 9) == 0)
- type = OSPF_OPAQUE_AS_LSA;
- else
- return CMD_WARNING;
-
- /* `show ip ospf database LSA'. */
- if ((argc == arg_base + 5) || (uj && (argc == arg_base + 6)))
- show_lsa_detail(vty, ospf, type, NULL, NULL, json_vrf);
- else if (argc >= arg_base + 6) {
- ret = inet_aton(argv[arg_base + 5]->arg, &id);
- if (!ret)
- return CMD_WARNING;
-
- /* `show ip ospf database LSA ID'. */
- if ((argc == arg_base + 6) || (uj && (argc == arg_base + 7)))
- show_lsa_detail(vty, ospf, type, &id, NULL, json_vrf);
- /* `show ip ospf database LSA ID adv-router ADV_ROUTER'. */
- else if ((argc == arg_base + 7)
- || (uj && (argc == arg_base + 8))) {
- if (strncmp(argv[arg_base + 6]->text, "s", 1) == 0)
- adv_router = ospf->router_id;
- else {
- ret = inet_aton(argv[arg_base + 7]->arg,
- &adv_router);
- if (!ret)
- return CMD_WARNING;
+ if (use_vrf) {
+ if (ospf->vrf_id == VRF_DEFAULT)
+ json_object_object_add(json, "default",
+ json_vrf);
+ else
+ json_object_object_add(json, ospf->name,
+ json_vrf);
}
- show_lsa_detail(vty, ospf, type, &id, &adv_router,
- json_vrf);
}
+ return CMD_SUCCESS;
}
- if (json) {
- if (use_vrf)
- json_object_object_add(json, ospf_get_name(ospf),
- json_vrf);
- }
-
- return CMD_SUCCESS;
-}
-
-DEFUN (show_ip_ospf_database_max,
- show_ip_ospf_database_max_cmd,
- "show ip ospf [vrf <NAME|all>] database <max-age|self-originate> [json]",
- SHOW_STR
- IP_STR
- "OSPF information\n"
- VRF_CMD_HELP_STR
- "All VRFs\n"
- "Database summary\n"
- "LSAs in MaxAge list\n"
- "Self-originated link states\n"
- JSON_STR)
-{
- struct ospf *ospf = NULL;
- struct listnode *node = NULL;
- char *vrf_name = NULL;
- bool all_vrf = false;
- int ret = CMD_SUCCESS;
- int inst = 0;
- int idx_vrf = 0;
- uint8_t use_vrf = 0;
- bool uj = use_json(argc, argv);
- json_object *json = NULL;
-
- if (uj)
- json = json_object_new_object();
-
- OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
-
- if (vrf_name) {
- bool ospf_output = false;
-
- use_vrf = 1;
-
- if (all_vrf) {
- for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
- if (!ospf->oi_running)
+ /* Show all LSAs. */
+ if (!type_name) {
+ if (detail) {
+ for (int i = OSPF_ROUTER_LSA; i <= OSPF_OPAQUE_AS_LSA;
+ i++) {
+ switch (i) {
+ case OSPF_GROUP_MEMBER_LSA:
+ case OSPF_EXTERNAL_ATTRIBUTES_LSA:
+ /* ignore deprecated LSA types */
continue;
- ospf_output = true;
- ret = show_ip_ospf_database_common(
- vty, ospf, idx_vrf ? 2 : 0, argc, argv,
- use_vrf, json, uj);
- }
-
- if (!ospf_output)
- vty_out(vty, "%% OSPF is not enabled\n");
- } else {
- ospf = ospf_lookup_by_inst_name(inst, vrf_name);
- if (ospf == NULL || !ospf->oi_running) {
- vty_out(vty,
- "%% OSPF is not enabled in vrf %s\n",
- vrf_name);
- if (uj)
- json_object_free(json);
+ default:
+ break;
+ }
- return CMD_SUCCESS;
+ if (adv_router && !lsid)
+ show_lsa_detail_adv_router(vty, ospf, i,
+ adv_router,
+ json_vrf);
+ else
+ show_lsa_detail(vty, ospf, i, lsid,
+ adv_router, json_vrf);
}
- ret = (show_ip_ospf_database_common(
- vty, ospf, idx_vrf ? 2 : 0, argc, argv, use_vrf,
- json, uj));
- }
- } else {
- /* Display default ospf (instance 0) info */
- ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
- if (ospf == NULL || !ospf->oi_running) {
- vty_out(vty, "%% OSPF is not enabled in vrf default\n");
- if (uj)
- json_object_free(json);
+ } else
+ show_ip_ospf_database_summary(vty, ospf, self,
+ json_vrf);
- return CMD_SUCCESS;
+ if (json) {
+ if (use_vrf) {
+ if (ospf->vrf_id == VRF_DEFAULT)
+ json_object_object_add(json, "default",
+ json_vrf);
+ else
+ json_object_object_add(json, ospf->name,
+ json_vrf);
+ }
}
-
- ret = show_ip_ospf_database_common(vty, ospf, 0, argc, argv,
- use_vrf, json, uj);
- }
-
- if (uj)
- vty_json(vty, json);
-
- return ret;
-}
-
-ALIAS (show_ip_ospf_database_max,
- show_ip_ospf_database_cmd,
- "show ip ospf [vrf <NAME|all>] database [<asbr-summary|external|network|router|summary|nssa-external|opaque-link|opaque-area|opaque-as> [A.B.C.D [<self-originate|adv-router A.B.C.D>]]] [json]",
- SHOW_STR
- IP_STR
- "OSPF information\n"
- VRF_CMD_HELP_STR
- "All VRFs\n"
- "Database summary\n"
- OSPF_LSA_TYPES_DESC
- "Link State ID (as an IP address)\n"
- "Self-originated link states\n"
- "Advertising Router link states\n"
- "Advertising Router (as an IP address)\n"
- JSON_STR)
-
-DEFUN (show_ip_ospf_instance_database_max,
- show_ip_ospf_instance_database_max_cmd,
- "show ip ospf (1-65535) database <max-age|self-originate> [json]",
- SHOW_STR
- IP_STR
- "OSPF information\n"
- "Instance ID\n"
- "Database summary\n"
- "LSAs in MaxAge list\n"
- "Self-originated link states\n"
- JSON_STR)
-{
- int idx_number = 3;
- struct ospf *ospf;
- unsigned short instance = 0;
- bool uj = use_json(argc, argv);
- json_object *json = NULL;
-
- if (uj)
- json = json_object_new_object();
-
- instance = strtoul(argv[idx_number]->arg, NULL, 10);
- if (instance != ospf_instance)
- return CMD_NOT_MY_INSTANCE;
-
- ospf = ospf_lookup_instance(instance);
- if (!ospf || !ospf->oi_running)
return CMD_SUCCESS;
-
- show_ip_ospf_database_common(vty, ospf, 1, argc, argv, 0, json, uj);
-
- if (uj)
- vty_json(vty, json);
-
- return CMD_SUCCESS;
-}
-
-ALIAS (show_ip_ospf_instance_database_max,
- show_ip_ospf_instance_database_cmd,
- "show ip ospf (1-65535) database [<asbr-summary|external|network|router|summary|nssa-external|opaque-link|opaque-area|opaque-as> [A.B.C.D [<self-originate|adv-router A.B.C.D>]]] [json]",
- SHOW_STR
- IP_STR
- "OSPF information\n"
- "Instance ID\n"
- "Database summary\n"
- OSPF_LSA_TYPES_DESC
- "Link State ID (as an IP address)\n"
- "Self-originated link states\n"
- "Advertising Router link states\n"
- "Advertising Router (as an IP address)\n"
- JSON_STR)
-
-static int show_ip_ospf_database_type_adv_router_common(struct vty *vty,
- struct ospf *ospf,
- int arg_base, int argc,
- struct cmd_token **argv,
- uint8_t use_vrf,
- json_object *json,
- bool uj)
-{
- int idx_type = 4;
- int type, ret;
- struct in_addr adv_router;
- json_object *json_vrf = NULL;
-
- if (uj) {
- if (use_vrf)
- json_vrf = json_object_new_object();
- else
- json_vrf = json;
- }
-
- if (ospf->instance) {
- if (uj)
- json_object_int_add(json, "ospfInstance",
- ospf->instance);
- else
- vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
- }
-
- ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf);
-
- /* Show Router ID. */
- if (uj) {
- json_object_string_addf(json_vrf, "routerId", "%pI4",
- &ospf->router_id);
- } else {
- vty_out(vty, "\n OSPF Router with ID (%pI4)\n\n",
- &ospf->router_id);
}
/* Set database type to show. */
- if (strncmp(argv[arg_base + idx_type]->text, "r", 1) == 0)
+ if (strncmp(type_name, "r", 1) == 0)
type = OSPF_ROUTER_LSA;
- else if (strncmp(argv[arg_base + idx_type]->text, "ne", 2) == 0)
+ else if (strncmp(type_name, "ne", 2) == 0)
type = OSPF_NETWORK_LSA;
- else if (strncmp(argv[arg_base + idx_type]->text, "ns", 2) == 0)
+ else if (strncmp(type_name, "ns", 2) == 0)
type = OSPF_AS_NSSA_LSA;
- else if (strncmp(argv[arg_base + idx_type]->text, "s", 1) == 0)
+ else if (strncmp(type_name, "su", 2) == 0)
type = OSPF_SUMMARY_LSA;
- else if (strncmp(argv[arg_base + idx_type]->text, "a", 1) == 0)
+ else if (strncmp(type_name, "a", 1) == 0)
type = OSPF_ASBR_SUMMARY_LSA;
- else if (strncmp(argv[arg_base + idx_type]->text, "e", 1) == 0)
+ else if (strncmp(type_name, "e", 1) == 0)
type = OSPF_AS_EXTERNAL_LSA;
- else if (strncmp(argv[arg_base + idx_type]->text, "opaque-l", 8) == 0)
+ else if (strncmp(type_name, "opaque-l", 8) == 0)
type = OSPF_OPAQUE_LINK_LSA;
- else if (strncmp(argv[arg_base + idx_type]->text, "opaque-ar", 9) == 0)
+ else if (strncmp(type_name, "opaque-ar", 9) == 0)
type = OSPF_OPAQUE_AREA_LSA;
- else if (strncmp(argv[arg_base + idx_type]->text, "opaque-as", 9) == 0)
+ else if (strncmp(type_name, "opaque-as", 9) == 0)
type = OSPF_OPAQUE_AS_LSA;
else {
if (uj) {
@@ -7422,155 +7250,119 @@ static int show_ip_ospf_database_type_adv_router_common(struct vty *vty,
return CMD_WARNING;
}
- /* `show ip ospf database LSA adv-router ADV_ROUTER'. */
- if (strncmp(argv[arg_base + 5]->text, "s", 1) == 0)
- adv_router = ospf->router_id;
- else {
- ret = inet_aton(argv[arg_base + 6]->arg, &adv_router);
- if (!ret) {
- if (uj) {
- if (use_vrf)
- json_object_free(json_vrf);
- }
- return CMD_WARNING;
- }
- }
-
- show_lsa_detail_adv_router(vty, ospf, type, &adv_router, json_vrf);
+ if (adv_router && !lsid)
+ show_lsa_detail_adv_router(vty, ospf, type, adv_router,
+ json_vrf);
+ else
+ show_lsa_detail(vty, ospf, type, lsid, adv_router, json_vrf);
if (json) {
- if (use_vrf)
- json_object_object_add(json, ospf_get_name(ospf),
- json_vrf);
+ if (use_vrf) {
+ if (ospf->vrf_id == VRF_DEFAULT)
+ json_object_object_add(json, "default",
+ json_vrf);
+ else
+ json_object_object_add(json, ospf->name,
+ json_vrf);
+ }
}
return CMD_SUCCESS;
}
-DEFUN (show_ip_ospf_database_type_adv_router,
- show_ip_ospf_database_type_adv_router_cmd,
- "show ip ospf [vrf <NAME|all>] database <asbr-summary|external|network|router|summary|nssa-external|opaque-link|opaque-area|opaque-as> <adv-router A.B.C.D|self-originate> [json]",
+DEFPY (show_ip_ospf_database,
+ show_ip_ospf_database_cmd,
+ "show ip ospf [(1-65535)$instance_id] [vrf <NAME|all>$vrf_name] database\
+ [<\
+ max-age$maxage\
+ |self-originate$selforig\
+ |<\
+ detail$detail\
+ |<asbr-summary|external|network|router|summary|nssa-external|opaque-link|opaque-area|opaque-as>$type_name\
+ >\
+ [{\
+ A.B.C.D$lsid\
+ |<adv-router A.B.C.D$adv_router|self-originate$adv_router_self>\
+ }]\
+ >]\
+ [json]",
SHOW_STR
IP_STR
"OSPF information\n"
+ "Instance ID\n"
VRF_CMD_HELP_STR
"All VRFs\n"
"Database summary\n"
+ "LSAs in MaxAge list\n"
+ "Self-originated link states\n"
+ "Show detailed information\n"
OSPF_LSA_TYPES_DESC
+ "Link State ID (as an IP address)\n"
"Advertising Router link states\n"
"Advertising Router (as an IP address)\n"
"Self-originated link states\n"
JSON_STR)
{
- struct ospf *ospf = NULL;
- struct listnode *node = NULL;
- char *vrf_name = NULL;
- bool all_vrf = false;
+ struct ospf *ospf;
int ret = CMD_SUCCESS;
- int inst = 0;
- int idx_vrf = 0;
- uint8_t use_vrf = 0;
+ bool use_vrf = !!vrf_name;
bool uj = use_json(argc, argv);
+ struct in_addr *lsid_p = NULL;
+ struct in_addr *adv_router_p = NULL;
json_object *json = NULL;
if (uj)
json = json_object_new_object();
+ if (lsid_str)
+ lsid_p = &lsid;
+ if (adv_router_str)
+ adv_router_p = &adv_router;
- OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
-
- if (vrf_name) {
+ if (vrf_name && strmatch(vrf_name, "all")) {
+ struct listnode *node;
bool ospf_output = false;
- use_vrf = 1;
+ for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
+ if (!ospf->oi_running)
+ continue;
+ if (ospf->instance != instance_id)
+ continue;
- if (all_vrf) {
- for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
- if (!ospf->oi_running)
- continue;
- ospf_output = true;
- ret = show_ip_ospf_database_type_adv_router_common(
- vty, ospf, 2, argc, argv, use_vrf, json,
- uj);
- }
- if (!ospf_output)
- vty_out(vty, "%% OSPF is not enabled\n");
- } else {
- ospf = ospf_lookup_by_inst_name(inst, vrf_name);
- if ((ospf == NULL) || !ospf->oi_running) {
- if (uj)
- vty_json(vty, json);
- else
- vty_out(vty,
- "%% OSPF is not enabled in vrf %s\n",
- vrf_name);
- return CMD_SUCCESS;
- }
+ if (adv_router_self)
+ adv_router_p = &ospf->router_id;
- ret = show_ip_ospf_database_type_adv_router_common(
- vty, ospf, 2, argc, argv, use_vrf, json, uj);
+ ospf_output = true;
+ ret = show_ip_ospf_database_common(
+ vty, ospf, !!maxage, !!selforig, !!detail,
+ type_name, lsid_p, adv_router_p, use_vrf, json,
+ uj);
}
+
+ if (!ospf_output && !uj)
+ vty_out(vty, "%% OSPF is not enabled\n");
} else {
- /* Display default ospf (instance 0) info */
- ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
+ if (!vrf_name)
+ vrf_name = VRF_DEFAULT_NAME;
+ ospf = ospf_lookup_by_inst_name(instance_id, vrf_name);
if (ospf == NULL || !ospf->oi_running) {
if (uj)
vty_json(vty, json);
else
- vty_out(vty,
- "%% OSPF is not enabled on vrf default\n");
+ vty_out(vty, "%% OSPF instance not found\n");
return CMD_SUCCESS;
}
+ if (adv_router_self)
+ adv_router_p = &ospf->router_id;
- ret = show_ip_ospf_database_type_adv_router_common(
- vty, ospf, 0, argc, argv, use_vrf, json, uj);
+ ret = (show_ip_ospf_database_common(
+ vty, ospf, !!maxage, !!selforig, !!detail, type_name,
+ lsid_p, adv_router_p, use_vrf, json, uj));
}
- if (uj) {
- vty_out(vty, "%s\n", json_object_to_json_string(json));
- json_object_free(json);
- }
-
- return ret;
-}
-
-DEFUN (show_ip_ospf_instance_database_type_adv_router,
- show_ip_ospf_instance_database_type_adv_router_cmd,
- "show ip ospf (1-65535) database <asbr-summary|external|network|router|summary|nssa-external|opaque-link|opaque-area|opaque-as> <adv-router A.B.C.D|self-originate> [json]",
- SHOW_STR
- IP_STR
- "OSPF information\n"
- "Instance ID\n"
- "Database summary\n"
- OSPF_LSA_TYPES_DESC
- "Advertising Router link states\n"
- "Advertising Router (as an IP address)\n"
- "Self-originated link states\n"
- JSON_STR)
-{
- int idx_number = 3;
- struct ospf *ospf;
- unsigned short instance = 0;
- bool uj = use_json(argc, argv);
- json_object *json = NULL;
-
- if (uj)
- json = json_object_new_object();
-
- instance = strtoul(argv[idx_number]->arg, NULL, 10);
- if (instance != ospf_instance)
- return CMD_NOT_MY_INSTANCE;
-
- ospf = ospf_lookup_instance(instance);
- if (!ospf || !ospf->oi_running)
- return CMD_SUCCESS;
-
- show_ip_ospf_database_type_adv_router_common(vty, ospf, 1, argc, argv,
- 0, json, uj);
-
if (uj)
vty_json(vty, json);
- return CMD_SUCCESS;
+ return ret;
}
DEFUN (ip_ospf_authentication_args,
@@ -9891,7 +9683,7 @@ DEFUN (no_ospf_max_metric_router_lsa_startup,
for (ALL_LIST_ELEMENTS_RO(ospf->areas, ln, area)) {
SET_FLAG(area->stub_router_state,
OSPF_AREA_WAS_START_STUB_ROUTED);
- THREAD_OFF(area->t_stub_router);
+ EVENT_OFF(area->t_stub_router);
/* Don't trample on admin stub routed */
if (!CHECK_FLAG(area->stub_router_state,
@@ -10388,9 +10180,9 @@ static int ospf_show_gr_helper_details(struct vty *vty, struct ospf *ospf,
.actual_grace_period);
vty_out(vty,
" Remaining GraceTime:%ld(in seconds).\n",
- thread_timer_remain_second(
+ event_timer_remain_second(
nbr->gr_helper_info
- .t_grace_timer));
+ .t_grace_timer));
vty_out(vty,
" Graceful Restart reason: %s.\n\n",
ospf_restart_reason2str(
@@ -10421,9 +10213,9 @@ static int ospf_show_gr_helper_details(struct vty *vty, struct ospf *ospf,
.actual_grace_period);
json_object_int_add(
json_neigh, "remainGracetime",
- thread_timer_remain_second(
+ event_timer_remain_second(
nbr->gr_helper_info
- .t_grace_timer));
+ .t_grace_timer));
json_object_string_add(
json_neigh, "restartReason",
ospf_restart_reason2str(
@@ -12233,29 +12025,62 @@ static int config_write_ospf_area(struct vty *vty, struct ospf *ospf)
vty_out(vty, " no-summary\n");
vty_out(vty, "\n");
} else if (area->external_routing == OSPF_AREA_NSSA) {
+ vty_out(vty, " area %s nssa", buf);
+
switch (area->NSSATranslatorRole) {
case OSPF_NSSA_ROLE_NEVER:
- vty_out(vty,
- " area %s nssa translate-never\n",
- buf);
+ vty_out(vty, " translate-never");
break;
case OSPF_NSSA_ROLE_ALWAYS:
- vty_out(vty,
- " area %s nssa translate-always\n",
- buf);
+ vty_out(vty, " translate-always");
break;
case OSPF_NSSA_ROLE_CANDIDATE:
- vty_out(vty, " area %s nssa \n", buf);
break;
}
- if (area->no_summary)
+
+ if (area->nssa_default_originate.enabled) {
vty_out(vty,
- " area %s nssa no-summary\n",
- buf);
+ " default-information-originate");
+ if (area->nssa_default_originate
+ .metric_value != -1)
+ vty_out(vty, " metric %d",
+ area->nssa_default_originate
+ .metric_value);
+ if (area->nssa_default_originate
+ .metric_type !=
+ DEFAULT_METRIC_TYPE)
+ vty_out(vty, " metric-type 1");
+ }
+
+ if (area->no_summary)
+ vty_out(vty, " no-summary");
if (area->suppress_fa)
- vty_out(vty,
- " area %s nssa suppress-fa\n",
- buf);
+ vty_out(vty, " suppress-fa");
+ vty_out(vty, "\n");
+
+ for (rn1 = route_top(area->nssa_ranges); rn1;
+ rn1 = route_next(rn1)) {
+ struct ospf_area_range *range;
+
+ range = rn1->info;
+ if (!range)
+ continue;
+
+ vty_out(vty, " area %s nssa range %pFX",
+ buf, &rn1->p);
+
+ if (range->cost_config !=
+ OSPF_AREA_RANGE_COST_UNSPEC)
+ vty_out(vty, " cost %u",
+ range->cost_config);
+
+ if (!CHECK_FLAG(
+ range->flags,
+ OSPF_AREA_RANGE_ADVERTISE))
+ vty_out(vty, " not-advertise");
+
+ vty_out(vty, "\n");
+ }
}
if (area->default_cost != 1)
@@ -12742,6 +12567,22 @@ static int ospf_config_write_one(struct vty *vty, struct ospf *ospf)
/* LDP-Sync print */
ospf_ldp_sync_write_config(vty, ospf);
+ /* Socket buffer sizes */
+ if (ospf->recv_sock_bufsize != OSPF_DEFAULT_SOCK_BUFSIZE) {
+ if (ospf->send_sock_bufsize == ospf->recv_sock_bufsize)
+ vty_out(vty, " socket buffer all %u\n",
+ ospf->recv_sock_bufsize);
+ else
+ vty_out(vty, " socket buffer recv %u\n",
+ ospf->recv_sock_bufsize);
+ }
+
+ if (ospf->send_sock_bufsize != OSPF_DEFAULT_SOCK_BUFSIZE &&
+ ospf->send_sock_bufsize != ospf->recv_sock_bufsize)
+ vty_out(vty, " socket buffer send %u\n",
+ ospf->send_sock_bufsize);
+
+
vty_out(vty, "exit\n");
write++;
@@ -12781,13 +12622,6 @@ void ospf_vty_show_init(void)
/* "show ip ospf database" commands. */
install_element(VIEW_NODE, &show_ip_ospf_database_cmd);
- install_element(VIEW_NODE, &show_ip_ospf_database_max_cmd);
- install_element(VIEW_NODE,
- &show_ip_ospf_database_type_adv_router_cmd);
- install_element(VIEW_NODE,
- &show_ip_ospf_instance_database_type_adv_router_cmd);
- install_element(VIEW_NODE, &show_ip_ospf_instance_database_cmd);
- install_element(VIEW_NODE, &show_ip_ospf_instance_database_max_cmd);
/* "show ip ospf interface" commands. */
install_element(VIEW_NODE, &show_ip_ospf_interface_cmd);
@@ -13061,7 +12895,7 @@ DEFPY_HIDDEN(ospf_maxage_delay_timer, ospf_maxage_delay_timer_cmd,
else
ospf->maxage_delay = value;
- THREAD_OFF(ospf->t_maxage);
+ EVENT_OFF(ospf->t_maxage);
OSPF_TIMER_ON(ospf->t_maxage, ospf_maxage_lsa_remover,
ospf->maxage_delay);
@@ -13205,6 +13039,42 @@ DEFPY(no_flood_reduction_area, no_flood_reduction_area_cmd,
return CMD_SUCCESS;
}
+DEFPY(ospf_socket_bufsizes,
+ ospf_socket_bufsizes_cmd,
+ "[no] socket buffer <send$send_val | recv$recv_val | all$all_val> \
+ ![(1-4000000000)$bufsize]",
+ NO_STR
+ "Socket parameters\n"
+ "Buffer size configuration\n"
+ "Send buffer size\n"
+ "Receive buffer size\n"
+ "Both send and receive buffer sizes\n"
+ "Buffer size, in bytes\n")
+{
+ VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
+ uint32_t recvsz, sendsz;
+
+ if (no)
+ bufsize = OSPF_DEFAULT_SOCK_BUFSIZE;
+
+ if (all_val) {
+ recvsz = bufsize;
+ sendsz = bufsize;
+ } else if (send_val) {
+ sendsz = bufsize;
+ recvsz = ospf->recv_sock_bufsize;
+ } else if (recv_val) {
+ recvsz = bufsize;
+ sendsz = ospf->send_sock_bufsize;
+ } else
+ return CMD_SUCCESS;
+
+ /* React to a change by modifying existing sockets */
+ ospf_update_bufsize(ospf, recvsz, sendsz);
+
+ return CMD_SUCCESS;
+}
+
void ospf_vty_clear_init(void)
{
install_element(ENABLE_NODE, &clear_ip_ospf_interface_cmd);
@@ -13288,12 +13158,9 @@ void ospf_vty_init(void)
/* "area nssa" commands. */
install_element(OSPF_NODE, &ospf_area_nssa_cmd);
- install_element(OSPF_NODE, &ospf_area_nssa_translate_cmd);
- install_element(OSPF_NODE, &ospf_area_nssa_no_summary_cmd);
- install_element(OSPF_NODE, &no_ospf_area_nssa_no_summary_cmd);
- install_element(OSPF_NODE, &ospf_area_nssa_suppress_fa_cmd);
- install_element(OSPF_NODE, &no_ospf_area_nssa_suppress_fa_cmd);
install_element(OSPF_NODE, &no_ospf_area_nssa_cmd);
+ install_element(OSPF_NODE, &ospf_area_nssa_range_cmd);
+ install_element(OSPF_NODE, &no_ospf_area_nssa_range_cmd);
install_element(OSPF_NODE, &ospf_area_default_cost_cmd);
install_element(OSPF_NODE, &no_ospf_area_default_cost_cmd);
@@ -13371,6 +13238,8 @@ void ospf_vty_init(void)
install_element(OSPF_NODE, &flood_reduction_area_cmd);
install_element(OSPF_NODE, &no_flood_reduction_area_cmd);
+ install_element(OSPF_NODE, &ospf_socket_bufsizes_cmd);
+
/* Init interface related vty commands. */
ospf_vty_if_init();
diff --git a/ospfd/ospf_zebra.c b/ospfd/ospf_zebra.c
index 46fb653f3a..3f967e41e4 100644
--- a/ospfd/ospf_zebra.c
+++ b/ospfd/ospf_zebra.c
@@ -6,7 +6,7 @@
#include <zebra.h>
-#include "thread.h"
+#include "frrevent.h"
#include "command.h"
#include "network.h"
#include "prefix.h"
@@ -20,6 +20,7 @@
#include "log.h"
#include "route_opaque.h"
#include "lib/bfd.h"
+#include "lib/lib_errors.h"
#include "nexthop.h"
#include "ospfd/ospfd.h"
@@ -49,7 +50,7 @@ struct zclient *zclient = NULL;
static struct zclient *zclient_sync;
/* For registering threads. */
-extern struct thread_master *master;
+extern struct event_loop *master;
/* Router-id update message from zebra. */
static int ospf_router_id_update_zebra(ZAPI_CALLBACK_ARGS)
@@ -509,10 +510,10 @@ bool ospf_external_default_routemap_apply_walk(struct ospf *ospf,
* Function to originate or flush default after applying
* route-map on all ei.
*/
-static void ospf_external_lsa_default_routemap_timer(struct thread *thread)
+static void ospf_external_lsa_default_routemap_timer(struct event *thread)
{
struct list *ext_list;
- struct ospf *ospf = THREAD_ARG(thread);
+ struct ospf *ospf = EVENT_ARG(thread);
struct prefix_ipv4 p;
int type;
int ret = 0;
@@ -579,8 +580,8 @@ void ospf_external_del(struct ospf *ospf, uint8_t type, unsigned short instance)
/*
* Check if default needs to be flushed too.
*/
- thread_add_event(master, ospf_external_lsa_default_routemap_timer, ospf,
- 0, &ospf->t_default_routemap_timer);
+ event_add_event(master, ospf_external_lsa_default_routemap_timer, ospf,
+ 0, &ospf->t_default_routemap_timer);
}
/* Update NHLFE for Prefix SID */
@@ -1124,9 +1125,9 @@ static bool ospf_external_lsa_default_routemap_apply(struct ospf *ospf,
* there are any other external info which can still trigger
* default route origination else flush it.
*/
- thread_add_event(master,
- ospf_external_lsa_default_routemap_timer, ospf,
- 0, &ospf->t_default_routemap_timer);
+ event_add_event(master,
+ ospf_external_lsa_default_routemap_timer, ospf,
+ 0, &ospf->t_default_routemap_timer);
}
return true;
@@ -1470,6 +1471,61 @@ static int ospf_zebra_read_route(ZAPI_CALLBACK_ARGS)
return 0;
}
+void ospf_zebra_import_default_route(struct ospf *ospf, bool unreg)
+{
+ struct prefix prefix = {};
+ int command;
+
+ if (zclient->sock < 0) {
+ if (IS_DEBUG_OSPF(zebra, ZEBRA))
+ zlog_debug(" Not connected to Zebra");
+ return;
+ }
+
+ prefix.family = AF_INET;
+ prefix.prefixlen = 0;
+
+ if (unreg)
+ command = ZEBRA_NEXTHOP_UNREGISTER;
+ else
+ command = ZEBRA_NEXTHOP_REGISTER;
+
+ if (IS_DEBUG_OSPF(zebra, ZEBRA))
+ zlog_debug("%s: sending cmd %s for %pFX (vrf %u)", __func__,
+ zserv_command_string(command), &prefix,
+ ospf->vrf_id);
+
+ if (zclient_send_rnh(zclient, command, &prefix, SAFI_UNICAST, false,
+ true, ospf->vrf_id) == ZCLIENT_SEND_FAILURE)
+ flog_err(EC_LIB_ZAPI_SOCKET, "%s: zclient_send_rnh() failed",
+ __func__);
+}
+
+static int ospf_zebra_import_check_update(ZAPI_CALLBACK_ARGS)
+{
+ struct ospf *ospf;
+ struct zapi_route nhr;
+ struct prefix matched;
+
+ ospf = ospf_lookup_by_vrf_id(vrf_id);
+ if (ospf == NULL || !IS_OSPF_ASBR(ospf))
+ return 0;
+
+ if (!zapi_nexthop_update_decode(zclient->ibuf, &matched, &nhr)) {
+ zlog_err("%s[%u]: Failure to decode route", __func__,
+ ospf->vrf_id);
+ return -1;
+ }
+
+ if (matched.family != AF_INET || matched.prefixlen != 0 ||
+ nhr.type == ZEBRA_ROUTE_OSPF)
+ return 0;
+
+ ospf->nssa_default_import_check.status = !!nhr.nexthop_num;
+ ospf_abr_nssa_type7_defaults(ospf);
+
+ return 0;
+}
int ospf_distribute_list_out_set(struct ospf *ospf, int type, const char *name)
{
@@ -1510,14 +1566,14 @@ int ospf_distribute_list_out_unset(struct ospf *ospf, int type,
}
/* distribute-list update timer. */
-static void ospf_distribute_list_update_timer(struct thread *thread)
+static void ospf_distribute_list_update_timer(struct event *thread)
{
struct route_node *rn;
struct external_info *ei;
struct route_table *rt;
struct ospf_lsa *lsa;
int type, default_refresh = 0;
- struct ospf *ospf = THREAD_ARG(thread);
+ struct ospf *ospf = EVENT_ARG(thread);
if (ospf == NULL)
return;
@@ -1641,9 +1697,8 @@ void ospf_distribute_list_update(struct ospf *ospf, int type,
return;
/* Set timer. If timer is already started, this call does nothing. */
- thread_add_timer_msec(master, ospf_distribute_list_update_timer, ospf,
- ospf->min_ls_interval,
- &ospf->t_distribute_update);
+ event_add_timer_msec(master, ospf_distribute_list_update_timer, ospf,
+ ospf->min_ls_interval, &ospf->t_distribute_update);
}
/* If access-list is updated, apply some check. */
@@ -1787,7 +1842,7 @@ static void ospf_prefix_list_update(struct prefix_list *plist)
&& strcmp(PREFIX_NAME_OUT(area),
prefix_list_name(plist))
== 0) {
- PREFIX_LIST_IN(area) = prefix_list_lookup(
+ PREFIX_LIST_OUT(area) = prefix_list_lookup(
AFI_IP, PREFIX_NAME_OUT(area));
abr_inv++;
}
@@ -2133,13 +2188,14 @@ static zclient_handler *const ospf_handlers[] = {
[ZEBRA_REDISTRIBUTE_ROUTE_ADD] = ospf_zebra_read_route,
[ZEBRA_REDISTRIBUTE_ROUTE_DEL] = ospf_zebra_read_route,
+ [ZEBRA_NEXTHOP_UPDATE] = ospf_zebra_import_check_update,
[ZEBRA_OPAQUE_MESSAGE] = ospf_opaque_msg_handler,
[ZEBRA_CLIENT_CLOSE_NOTIFY] = ospf_zebra_client_close_notify,
};
-void ospf_zebra_init(struct thread_master *master, unsigned short instance)
+void ospf_zebra_init(struct event_loop *master, unsigned short instance)
{
/* Allocate zebra structure. */
zclient = zclient_new(master, &zclient_options_default, ospf_handlers,
diff --git a/ospfd/ospf_zebra.h b/ospfd/ospf_zebra.h
index adc338fb1a..86a5678fc4 100644
--- a/ospfd/ospf_zebra.h
+++ b/ospfd/ospf_zebra.h
@@ -69,6 +69,7 @@ extern int ospf_redistribute_set(struct ospf *, struct ospf_redist *, int,
unsigned short, int, int);
extern int ospf_redistribute_unset(struct ospf *, int, unsigned short);
extern int ospf_redistribute_default_set(struct ospf *, int, int, int);
+extern void ospf_zebra_import_default_route(struct ospf *ospf, bool unreg);
extern int ospf_distribute_list_out_set(struct ospf *, int, const char *);
extern int ospf_distribute_list_out_unset(struct ospf *, int, const char *);
extern void ospf_routemap_set(struct ospf_redist *, const char *);
@@ -79,7 +80,7 @@ extern int ospf_distance_set(struct vty *, struct ospf *, const char *,
const char *, const char *);
extern int ospf_distance_unset(struct vty *, struct ospf *, const char *,
const char *, const char *);
-extern void ospf_zebra_init(struct thread_master *, unsigned short);
+extern void ospf_zebra_init(struct event_loop *m, unsigned short instance);
extern void ospf_zebra_vrf_register(struct ospf *ospf);
extern void ospf_zebra_vrf_deregister(struct ospf *ospf);
bool ospf_external_default_routemap_apply_walk(
diff --git a/ospfd/ospfd.c b/ospfd/ospfd.c
index 0296d9d9f5..15ce1c48a4 100644
--- a/ospfd/ospfd.c
+++ b/ospfd/ospfd.c
@@ -5,7 +5,7 @@
#include <zebra.h>
-#include "thread.h"
+#include "frrevent.h"
#include "vty.h"
#include "command.h"
#include "linklist.h"
@@ -385,8 +385,8 @@ struct ospf *ospf_new_alloc(unsigned short instance, const char *name)
new->maxage_delay = OSPF_LSA_MAXAGE_REMOVE_DELAY_DEFAULT;
new->maxage_lsa = route_table_init();
new->t_maxage_walker = NULL;
- thread_add_timer(master, ospf_lsa_maxage_walker, new,
- OSPF_LSA_MAXAGE_CHECK_INTERVAL, &new->t_maxage_walker);
+ event_add_timer(master, ospf_lsa_maxage_walker, new,
+ OSPF_LSA_MAXAGE_CHECK_INTERVAL, &new->t_maxage_walker);
/* Max paths initialization */
new->max_multipath = MULTIPATH_NUM;
@@ -398,8 +398,8 @@ struct ospf *ospf_new_alloc(unsigned short instance, const char *name)
new->lsa_refresh_interval = OSPF_LSA_REFRESH_INTERVAL_DEFAULT;
new->lsa_refresh_timer = OSPF_LS_REFRESH_TIME;
new->t_lsa_refresher = NULL;
- thread_add_timer(master, ospf_lsa_refresh_walker, new,
- new->lsa_refresh_interval, &new->t_lsa_refresher);
+ event_add_timer(master, ospf_lsa_refresh_walker, new,
+ new->lsa_refresh_interval, &new->t_lsa_refresher);
new->lsa_refresher_started = monotime(NULL);
new->ibuf = stream_new(OSPF_MAX_PACKET_SIZE + 1);
@@ -420,6 +420,9 @@ struct ospf *ospf_new_alloc(unsigned short instance, const char *name)
new->fd = -1;
+ new->recv_sock_bufsize = OSPF_DEFAULT_SOCK_BUFSIZE;
+ new->send_sock_bufsize = OSPF_DEFAULT_SOCK_BUFSIZE;
+
return new;
}
@@ -441,7 +444,7 @@ static struct ospf *ospf_new(unsigned short instance, const char *name)
return new;
}
- thread_add_read(master, ospf_read, new, new->fd, &new->t_read);
+ event_add_read(master, ospf_read, new, new->fd, &new->t_read);
new->oi_running = 1;
ospf_router_id_update(new);
@@ -579,7 +582,7 @@ static struct ospf *ospf_lookup_by_name(const char *vrf_name)
static void ospf_deferred_shutdown_finish(struct ospf *ospf)
{
ospf->stub_router_shutdown_time = OSPF_STUB_ROUTER_UNCONFIGURED;
- THREAD_OFF(ospf->t_deferred_shutdown);
+ EVENT_OFF(ospf->t_deferred_shutdown);
ospf_finish_final(ospf);
@@ -596,9 +599,9 @@ static void ospf_deferred_shutdown_finish(struct ospf *ospf)
}
/* Timer thread for G-R */
-static void ospf_deferred_shutdown_timer(struct thread *t)
+static void ospf_deferred_shutdown_timer(struct event *t)
{
- struct ospf *ospf = THREAD_ARG(t);
+ struct ospf *ospf = EVENT_ARG(t);
ospf_deferred_shutdown_finish(ospf);
}
@@ -761,7 +764,7 @@ static void ospf_finish_final(struct ospf *ospf)
/* Clear static neighbors */
for (rn = route_top(ospf->nbr_nbma); rn; rn = route_next(rn))
if ((nbr_nbma = rn->info)) {
- THREAD_OFF(nbr_nbma->t_poll);
+ EVENT_OFF(nbr_nbma->t_poll);
if (nbr_nbma->nbr) {
nbr_nbma->nbr->nbr_nbma = NULL;
@@ -797,23 +800,23 @@ static void ospf_finish_final(struct ospf *ospf)
}
/* Cancel all timers. */
- THREAD_OFF(ospf->t_read);
- THREAD_OFF(ospf->t_write);
- THREAD_OFF(ospf->t_spf_calc);
- THREAD_OFF(ospf->t_ase_calc);
- THREAD_OFF(ospf->t_maxage);
- THREAD_OFF(ospf->t_maxage_walker);
- THREAD_OFF(ospf->t_abr_task);
- THREAD_OFF(ospf->t_abr_fr);
- THREAD_OFF(ospf->t_asbr_check);
- THREAD_OFF(ospf->t_asbr_nssa_redist_update);
- THREAD_OFF(ospf->t_distribute_update);
- THREAD_OFF(ospf->t_lsa_refresher);
- THREAD_OFF(ospf->t_opaque_lsa_self);
- THREAD_OFF(ospf->t_sr_update);
- THREAD_OFF(ospf->t_default_routemap_timer);
- THREAD_OFF(ospf->t_external_aggr);
- THREAD_OFF(ospf->gr_info.t_grace_period);
+ EVENT_OFF(ospf->t_read);
+ EVENT_OFF(ospf->t_write);
+ EVENT_OFF(ospf->t_spf_calc);
+ EVENT_OFF(ospf->t_ase_calc);
+ EVENT_OFF(ospf->t_maxage);
+ EVENT_OFF(ospf->t_maxage_walker);
+ EVENT_OFF(ospf->t_abr_task);
+ EVENT_OFF(ospf->t_abr_fr);
+ EVENT_OFF(ospf->t_asbr_check);
+ EVENT_OFF(ospf->t_asbr_nssa_redist_update);
+ EVENT_OFF(ospf->t_distribute_update);
+ EVENT_OFF(ospf->t_lsa_refresher);
+ EVENT_OFF(ospf->t_opaque_lsa_self);
+ EVENT_OFF(ospf->t_sr_update);
+ EVENT_OFF(ospf->t_default_routemap_timer);
+ EVENT_OFF(ospf->t_external_aggr);
+ EVENT_OFF(ospf->gr_info.t_grace_period);
LSDB_LOOP (OPAQUE_AS_LSDB(ospf), rn, lsa)
ospf_discard_from_db(ospf, ospf->lsdb, lsa);
@@ -963,6 +966,7 @@ struct ospf_area *ospf_area_new(struct ospf *ospf, struct in_addr area_id)
new->oiflist = list_new();
new->ranges = route_table_init();
+ new->nssa_ranges = route_table_init();
if (area_id.s_addr == OSPF_AREA_BACKBONE)
ospf->backbone = new;
@@ -1006,6 +1010,7 @@ static void ospf_area_free(struct ospf_area *area)
ospf_lsa_unlock(&area->router_lsa_self);
route_table_finish(area->ranges);
+ route_table_finish(area->nssa_ranges);
list_delete(&area->oiflist);
if (EXPORT_NAME(area))
@@ -1015,8 +1020,8 @@ static void ospf_area_free(struct ospf_area *area)
free(IMPORT_NAME(area));
/* Cancel timer. */
- THREAD_OFF(area->t_stub_router);
- THREAD_OFF(area->t_opaque_lsa_self);
+ EVENT_OFF(area->t_stub_router);
+ EVENT_OFF(area->t_opaque_lsa_self);
if (OSPF_IS_AREA_BACKBONE(area))
area->ospf->backbone = NULL;
@@ -1029,13 +1034,14 @@ void ospf_area_check_free(struct ospf *ospf, struct in_addr area_id)
struct ospf_area *area;
area = ospf_area_lookup_by_area_id(ospf, area_id);
- if (area && listcount(area->oiflist) == 0 && area->ranges->top == NULL
- && !ospf_vl_count(ospf, area)
- && area->shortcut_configured == OSPF_SHORTCUT_DEFAULT
- && area->external_routing == OSPF_AREA_DEFAULT
- && area->no_summary == 0 && area->default_cost == 1
- && EXPORT_NAME(area) == NULL && IMPORT_NAME(area) == NULL
- && area->auth_type == OSPF_AUTH_NULL) {
+ if (area && listcount(area->oiflist) == 0 &&
+ area->ranges->top == NULL && area->nssa_ranges->top == NULL &&
+ !ospf_vl_count(ospf, area) &&
+ area->shortcut_configured == OSPF_SHORTCUT_DEFAULT &&
+ area->external_routing == OSPF_AREA_DEFAULT &&
+ area->no_summary == 0 && area->default_cost == 1 &&
+ EXPORT_NAME(area) == NULL && IMPORT_NAME(area) == NULL &&
+ area->auth_type == OSPF_AUTH_NULL) {
listnode_delete(ospf->areas, area);
ospf_area_free(area);
}
@@ -1451,7 +1457,7 @@ void ospf_ls_upd_queue_empty(struct ospf_interface *oi)
}
/* remove update event */
- THREAD_OFF(oi->t_ls_upd_event);
+ EVENT_OFF(oi->t_ls_upd_event);
}
void ospf_if_update(struct ospf *ospf, struct interface *ifp)
@@ -1701,7 +1707,7 @@ int ospf_area_nssa_set(struct ospf *ospf, struct in_addr area_id)
return 1;
}
-int ospf_area_nssa_unset(struct ospf *ospf, struct in_addr area_id, int argc)
+int ospf_area_nssa_unset(struct ospf *ospf, struct in_addr area_id)
{
struct ospf_area *area;
@@ -1709,22 +1715,14 @@ int ospf_area_nssa_unset(struct ospf *ospf, struct in_addr area_id, int argc)
if (area == NULL)
return 0;
- /* argc < 5 -> 'no area x nssa' */
- if (argc < 5 && area->external_routing == OSPF_AREA_NSSA) {
- ospf->anyNSSA--;
- /* set NSSA area defaults */
- area->no_summary = 0;
- area->suppress_fa = 0;
- area->NSSATranslatorRole = OSPF_NSSA_ROLE_CANDIDATE;
- area->NSSATranslatorState = OSPF_NSSA_TRANSLATE_DISABLED;
- area->NSSATranslatorStabilityInterval =
- OSPF_NSSA_TRANS_STABLE_DEFAULT;
- ospf_area_type_set(area, OSPF_AREA_DEFAULT);
- } else {
- ospf_area_nssa_translator_role_set(ospf, area_id,
- OSPF_NSSA_ROLE_CANDIDATE);
- }
-
+ ospf->anyNSSA--;
+ /* set NSSA area defaults */
+ area->no_summary = 0;
+ area->suppress_fa = 0;
+ area->NSSATranslatorRole = OSPF_NSSA_ROLE_CANDIDATE;
+ area->NSSATranslatorState = OSPF_NSSA_TRANSLATE_DISABLED;
+ area->NSSATranslatorStabilityInterval = OSPF_NSSA_TRANS_STABLE_DEFAULT;
+ ospf_area_type_set(area, OSPF_AREA_DEFAULT);
ospf_area_check_free(ospf, area_id);
return 1;
@@ -1782,6 +1780,51 @@ int ospf_area_nssa_translator_role_set(struct ospf *ospf,
return 1;
}
+void ospf_area_nssa_default_originate_set(struct ospf *ospf,
+ struct in_addr area_id, int metric,
+ int metric_type)
+{
+ struct ospf_area *area;
+
+ area = ospf_area_lookup_by_area_id(ospf, area_id);
+ if (area == NULL)
+ return;
+
+ if (!area->nssa_default_originate.enabled) {
+ area->nssa_default_originate.enabled = true;
+ if (++ospf->nssa_default_import_check.refcnt == 1) {
+ ospf->nssa_default_import_check.status = false;
+ ospf_zebra_import_default_route(ospf, false);
+ }
+ }
+
+ area->nssa_default_originate.metric_value = metric;
+ area->nssa_default_originate.metric_type = metric_type;
+}
+
+void ospf_area_nssa_default_originate_unset(struct ospf *ospf,
+ struct in_addr area_id)
+{
+ struct ospf_area *area;
+
+ area = ospf_area_lookup_by_area_id(ospf, area_id);
+ if (area == NULL)
+ return;
+
+ if (area->nssa_default_originate.enabled) {
+ area->nssa_default_originate.enabled = false;
+ if (--ospf->nssa_default_import_check.refcnt == 0) {
+ ospf->nssa_default_import_check.status = false;
+ ospf_zebra_import_default_route(ospf, true);
+ }
+ area->nssa_default_originate.metric_value = -1;
+ area->nssa_default_originate.metric_type = -1;
+
+ if (!IS_OSPF_ABR(ospf))
+ ospf_abr_nssa_type7_defaults(ospf);
+ }
+}
+
int ospf_area_export_list_set(struct ospf *ospf, struct ospf_area *area,
const char *list_name)
{
@@ -1859,9 +1902,9 @@ int ospf_timers_refresh_set(struct ospf *ospf, int interval)
- (monotime(NULL) - ospf->lsa_refresher_started);
if (time_left > interval) {
- THREAD_OFF(ospf->t_lsa_refresher);
- thread_add_timer(master, ospf_lsa_refresh_walker, ospf,
- interval, &ospf->t_lsa_refresher);
+ EVENT_OFF(ospf->t_lsa_refresher);
+ event_add_timer(master, ospf_lsa_refresh_walker, ospf, interval,
+ &ospf->t_lsa_refresher);
}
ospf->lsa_refresh_interval = interval;
@@ -1876,11 +1919,11 @@ int ospf_timers_refresh_unset(struct ospf *ospf)
- (monotime(NULL) - ospf->lsa_refresher_started);
if (time_left > OSPF_LSA_REFRESH_INTERVAL_DEFAULT) {
- THREAD_OFF(ospf->t_lsa_refresher);
+ EVENT_OFF(ospf->t_lsa_refresher);
ospf->t_lsa_refresher = NULL;
- thread_add_timer(master, ospf_lsa_refresh_walker, ospf,
- OSPF_LSA_REFRESH_INTERVAL_DEFAULT,
- &ospf->t_lsa_refresher);
+ event_add_timer(master, ospf_lsa_refresh_walker, ospf,
+ OSPF_LSA_REFRESH_INTERVAL_DEFAULT,
+ &ospf->t_lsa_refresher);
}
ospf->lsa_refresh_interval = OSPF_LSA_REFRESH_INTERVAL_DEFAULT;
@@ -1928,7 +1971,7 @@ static void ospf_nbr_nbma_delete(struct ospf *ospf,
static void ospf_nbr_nbma_down(struct ospf_nbr_nbma *nbr_nbma)
{
- THREAD_OFF(nbr_nbma->t_poll);
+ EVENT_OFF(nbr_nbma->t_poll);
if (nbr_nbma->nbr) {
nbr_nbma->nbr->nbr_nbma = NULL;
@@ -2117,7 +2160,7 @@ int ospf_nbr_nbma_poll_interval_set(struct ospf *ospf, struct in_addr nbr_addr,
if (nbr_nbma->v_poll != interval) {
nbr_nbma->v_poll = interval;
if (nbr_nbma->oi && ospf_if_is_up(nbr_nbma->oi)) {
- THREAD_OFF(nbr_nbma->t_poll);
+ EVENT_OFF(nbr_nbma->t_poll);
OSPF_POLL_TIMER_ON(nbr_nbma->t_poll, ospf_poll_timer,
nbr_nbma->v_poll);
}
@@ -2140,7 +2183,33 @@ int ospf_nbr_nbma_poll_interval_unset(struct ospf *ospf, struct in_addr addr)
return 1;
}
-void ospf_master_init(struct thread_master *master)
+/*
+ * Update socket bufsize(s), usually after config change
+ */
+void ospf_update_bufsize(struct ospf *ospf, uint32_t recvsize,
+ uint32_t sendsize)
+{
+ enum ospf_sock_type_e type = OSPF_SOCK_NONE;
+
+ /* Figure out whether there's been a change */
+ if (recvsize != ospf->recv_sock_bufsize) {
+ type = OSPF_SOCK_RECV;
+ ospf->recv_sock_bufsize = recvsize;
+
+ if (sendsize != ospf->send_sock_bufsize) {
+ type = OSPF_SOCK_BOTH;
+ ospf->send_sock_bufsize = sendsize;
+ }
+ } else if (sendsize != ospf->send_sock_bufsize) {
+ type = OSPF_SOCK_SEND;
+ ospf->send_sock_bufsize = sendsize;
+ }
+
+ if (type != OSPF_SOCK_NONE)
+ ospf_sock_bufsize_update(ospf, ospf->fd, type);
+}
+
+void ospf_master_init(struct event_loop *master)
{
memset(&ospf_master, 0, sizeof(ospf_master));
@@ -2247,8 +2316,8 @@ static int ospf_vrf_enable(struct vrf *vrf)
ret = ospf_sock_init(ospf);
if (ret < 0 || ospf->fd <= 0)
return 0;
- thread_add_read(master, ospf_read, ospf, ospf->fd,
- &ospf->t_read);
+ event_add_read(master, ospf_read, ospf, ospf->fd,
+ &ospf->t_read);
ospf->oi_running = 1;
ospf_router_id_update(ospf);
}
@@ -2286,7 +2355,7 @@ static int ospf_vrf_disable(struct vrf *vrf)
if (IS_DEBUG_OSPF_EVENT)
zlog_debug("%s: ospf old_vrf_id %d unlinked", __func__,
old_vrf_id);
- THREAD_OFF(ospf->t_read);
+ EVENT_OFF(ospf->t_read);
close(ospf->fd);
ospf->fd = -1;
}
diff --git a/ospfd/ospfd.h b/ospfd/ospfd.h
index 4df65ea759..1b66d4d930 100644
--- a/ospfd/ospfd.h
+++ b/ospfd/ospfd.h
@@ -67,6 +67,9 @@
#define OSPF_LS_REFRESH_SHIFT (60 * 15)
#define OSPF_LS_REFRESH_JITTER 60
+/* Default socket buffer size */
+#define OSPF_DEFAULT_SOCK_BUFSIZE (8 * 1024 * 1024)
+
struct ospf_external {
unsigned short instance;
struct route_table *external_info;
@@ -78,7 +81,7 @@ struct ospf_master {
struct list *ospf;
/* OSPF thread master. */
- struct thread_master *master;
+ struct event_loop *master;
/* Various OSPF global configuration. */
uint8_t options;
@@ -145,7 +148,7 @@ struct ospf_gr_info {
bool prepare_in_progress;
bool finishing_restart;
uint32_t grace_period;
- struct thread *t_grace_period;
+ struct event *t_grace_period;
};
/* OSPF instance structure. */
@@ -257,31 +260,30 @@ struct ospf {
int redistribute; /* Num of redistributed protocols. */
/* Threads. */
- struct thread *t_abr_task; /* ABR task timer. */
- struct thread *t_abr_fr; /* ABR FR timer. */
- struct thread *t_asbr_check; /* ASBR check timer. */
- struct thread *t_asbr_nssa_redist_update; /* ASBR NSSA redistribution
+ struct event *t_abr_task; /* ABR task timer. */
+ struct event *t_abr_fr; /* ABR FR timer. */
+ struct event *t_asbr_check; /* ASBR check timer. */
+ struct event *t_asbr_nssa_redist_update; /* ASBR NSSA redistribution
update timer. */
- struct thread *t_distribute_update; /* Distirbute list update timer. */
- struct thread *t_spf_calc; /* SPF calculation timer. */
- struct thread *t_ase_calc; /* ASE calculation timer. */
- struct thread
- *t_opaque_lsa_self; /* Type-11 Opaque-LSAs origin event. */
- struct thread *t_sr_update; /* Segment Routing update timer */
+ struct event *t_distribute_update; /* Distirbute list update timer. */
+ struct event *t_spf_calc; /* SPF calculation timer. */
+ struct event *t_ase_calc; /* ASE calculation timer. */
+ struct event *t_opaque_lsa_self; /* Type-11 Opaque-LSAs origin event. */
+ struct event *t_sr_update; /* Segment Routing update timer */
unsigned int maxage_delay; /* Delay on Maxage remover timer, sec */
- struct thread *t_maxage; /* MaxAge LSA remover timer. */
- struct thread *t_maxage_walker; /* MaxAge LSA checking timer. */
+ struct event *t_maxage; /* MaxAge LSA remover timer. */
+ struct event *t_maxage_walker; /* MaxAge LSA checking timer. */
- struct thread
+ struct event
*t_deferred_shutdown; /* deferred/stub-router shutdown timer*/
- struct thread *t_write;
+ struct event *t_write;
#define OSPF_WRITE_INTERFACE_COUNT_DEFAULT 20
- struct thread *t_default_routemap_timer;
+ struct event *t_default_routemap_timer;
int write_oi_count; /* Num of packets sent per thread invocation */
- struct thread *t_read;
+ struct event *t_read;
int fd;
struct stream *ibuf;
struct list *oi_write_q;
@@ -303,6 +305,18 @@ struct ospf {
int default_metric; /* Default metric for redistribute. */
+ /* NSSA default-information-originate */
+ struct {
+ /* # of NSSA areas requesting default information */
+ uint16_t refcnt;
+
+ /*
+ * Whether a default route known through non-OSPF protocol is
+ * present in the RIB.
+ */
+ bool status;
+ } nssa_default_import_check;
+
#define OSPF_LSA_REFRESHER_GRANULARITY 10
#define OSPF_LSA_REFRESHER_SLOTS \
((OSPF_LS_REFRESH_TIME + OSPF_LS_REFRESH_SHIFT) \
@@ -313,7 +327,7 @@ struct ospf {
struct list *qs[OSPF_LSA_REFRESHER_SLOTS];
} lsa_refresh_queue;
- struct thread *t_lsa_refresher;
+ struct event *t_lsa_refresher;
time_t lsa_refresher_started;
#define OSPF_LSA_REFRESH_INTERVAL_DEFAULT 10
uint16_t lsa_refresh_interval;
@@ -382,7 +396,7 @@ struct ospf {
/* delay timer to process external routes
* with summary address.
*/
- struct thread *t_external_aggr;
+ struct event *t_external_aggr;
/* delay interval in seconds */
uint16_t aggr_delay_interval;
@@ -413,6 +427,10 @@ struct ospf {
/* Flood Reduction configuration state */
bool fr_configured;
+ /* Socket buffer sizes */
+ uint32_t recv_sock_bufsize;
+ uint32_t send_sock_bufsize;
+
QOBJ_FIELDS;
};
DECLARE_QOBJ_TYPE(ospf);
@@ -518,6 +536,7 @@ struct ospf_area {
#define OSPF_TRANSIT_FALSE 0
#define OSPF_TRANSIT_TRUE 1
struct route_table *ranges; /* Configured Area Ranges. */
+ struct route_table *nssa_ranges; /* Configured NSSA Area Ranges. */
/* RFC3137 stub router state flags for area */
uint8_t stub_router_state;
@@ -562,6 +581,13 @@ struct ospf_area {
#define PREFIX_LIST_OUT(A) (A)->plist_out.list
#define PREFIX_NAME_OUT(A) (A)->plist_out.name
+ /* NSSA default-information-originate */
+ struct {
+ bool enabled;
+ int metric_type;
+ int metric_value;
+ } nssa_default_originate;
+
/* Shortest Path Tree. */
struct vertex *spf;
struct list *spf_vertex_list;
@@ -578,8 +604,8 @@ struct ospf_area {
struct p_spaces_head *p_spaces;
/* Threads. */
- struct thread *t_stub_router; /* Stub-router timer */
- struct thread *t_opaque_lsa_self; /* Type-10 Opaque-LSAs origin. */
+ struct event *t_stub_router; /* Stub-router timer */
+ struct event *t_opaque_lsa_self; /* Type-10 Opaque-LSAs origin. */
/* Statistics field. */
uint32_t spf_calculation; /* SPF Calculation Count. */
@@ -627,7 +653,7 @@ struct ospf_nbr_nbma {
uint32_t v_poll;
/* Poll timer thread. */
- struct thread *t_poll;
+ struct event *t_poll;
/* State change. */
uint32_t state_change;
@@ -654,16 +680,18 @@ struct ospf_nbr_nbma {
#define LSA_OPTIONS_NSSA_GET(area) \
(((area)->external_routing == OSPF_AREA_NSSA) ? OSPF_OPTION_NP : 0)
-#define OSPF_TIMER_ON(T,F,V) thread_add_timer (master,(F),ospf,(V),&(T))
-#define OSPF_AREA_TIMER_ON(T,F,V) thread_add_timer (master, (F), area, (V), &(T))
-#define OSPF_POLL_TIMER_ON(T,F,V) thread_add_timer (master, (F), nbr_nbma, (V), &(T))
+#define OSPF_TIMER_ON(T, F, V) event_add_timer(master, (F), ospf, (V), &(T))
+#define OSPF_AREA_TIMER_ON(T, F, V) \
+ event_add_timer(master, (F), area, (V), &(T))
+#define OSPF_POLL_TIMER_ON(T, F, V) \
+ event_add_timer(master, (F), nbr_nbma, (V), &(T))
/* Extern variables. */
extern struct ospf_master *om;
extern unsigned short ospf_instance;
extern const int ospf_redistributed_proto_max;
extern struct zclient *zclient;
-extern struct thread_master *master;
+extern struct event_loop *master;
extern int ospf_zlog;
extern struct zebra_privs_t ospfd_privs;
@@ -696,14 +724,18 @@ extern int ospf_area_no_summary_set(struct ospf *ospf, struct in_addr area_id);
extern int ospf_area_no_summary_unset(struct ospf *ospf,
struct in_addr area_id);
extern int ospf_area_nssa_set(struct ospf *ospf, struct in_addr area_id);
-extern int ospf_area_nssa_unset(struct ospf *ospf, struct in_addr area_id,
- int argc);
+extern int ospf_area_nssa_unset(struct ospf *ospf, struct in_addr area_id);
extern int ospf_area_nssa_suppress_fa_set(struct ospf *ospf,
struct in_addr area_id);
extern int ospf_area_nssa_suppress_fa_unset(struct ospf *ospf,
struct in_addr area_id);
extern int ospf_area_nssa_translator_role_set(struct ospf *ospf,
struct in_addr area_id, int role);
+extern void ospf_area_nssa_default_originate_set(struct ospf *ospf,
+ struct in_addr area_id,
+ int metric, int metric_type);
+extern void ospf_area_nssa_default_originate_unset(struct ospf *ospf,
+ struct in_addr area_id);
extern int ospf_area_export_list_set(struct ospf *ospf,
struct ospf_area *area_id,
const char *list_name);
@@ -757,7 +789,7 @@ extern void ospf_interface_area_unset(struct ospf *ospf, struct interface *ifp);
extern void ospf_route_map_init(void);
-extern void ospf_master_init(struct thread_master *master);
+extern void ospf_master_init(struct event_loop *master);
extern void ospf_vrf_init(void);
extern void ospf_vrf_terminate(void);
extern void ospf_vrf_link(struct ospf *ospf, struct vrf *vrf);
@@ -768,6 +800,9 @@ int ospf_area_nssa_no_summary_set(struct ospf *ospf, struct in_addr area_id);
const char *ospf_get_name(const struct ospf *ospf);
extern struct ospf_interface *add_ospf_interface(struct connected *co,
struct ospf_area *area);
+/* Update socket bufsize(s), after config change */
+void ospf_update_bufsize(struct ospf *ospf, uint32_t recvsize,
+ uint32_t sendsize);
extern int p_spaces_compare_func(const struct p_space *a,
const struct p_space *b);
diff --git a/pathd/path_main.c b/pathd/path_main.c
index 3d35b9f9b3..c333162f2b 100644
--- a/pathd/path_main.c
+++ b/pathd/path_main.c
@@ -6,7 +6,7 @@
#include <lib/version.h>
#include "getopt.h"
-#include "thread.h"
+#include "frrevent.h"
#include "command.h"
#include "log.h"
#include "memory.h"
@@ -41,7 +41,7 @@ struct zebra_privs_t pathd_privs = {
struct option longopts[] = {{0}};
/* Master of threads. */
-struct thread_master *master;
+struct event_loop *master;
static struct frr_daemon_info pathd_di;
diff --git a/pathd/path_pcep.c b/pathd/path_pcep.c
index 0c5e495044..ec9d8adfc1 100644
--- a/pathd/path_pcep.c
+++ b/pathd/path_pcep.c
@@ -58,7 +58,7 @@ static void notify_status(struct path *path, bool not_changed);
/* Module Functions */
static int pcep_module_finish(void);
-static int pcep_module_late_init(struct thread_master *tm);
+static int pcep_module_late_init(struct event_loop *tm);
static int pcep_module_init(void);
/* ------------ Path Helper Functions ------------ */
@@ -310,7 +310,7 @@ int pathd_candidate_removed_handler(struct srte_candidate *candidate)
* run before config load, so the CLI commands don't try to touch things that
* aren't set up yet...
*/
-static int pcep_module_config_pre(struct thread_master *tm)
+static int pcep_module_config_pre(struct event_loop *tm)
{
assert(pcep_g->fpt == NULL);
assert(pcep_g->master == NULL);
@@ -329,7 +329,7 @@ static int pcep_module_config_pre(struct thread_master *tm)
return 0;
}
-static int pcep_module_late_init(struct thread_master *tm)
+static int pcep_module_late_init(struct event_loop *tm)
{
hook_register(pathd_candidate_created, pathd_candidate_created_handler);
hook_register(pathd_candidate_updated, pathd_candidate_updated_handler);
diff --git a/pathd/path_pcep.h b/pathd/path_pcep.h
index 6f92d76362..5c6a02372f 100644
--- a/pathd/path_pcep.h
+++ b/pathd/path_pcep.h
@@ -294,7 +294,7 @@ struct path {
struct pcep_glob {
struct debug dbg;
- struct thread_master *master;
+ struct event_loop *master;
struct frr_pthread *fpt;
uint8_t num_pce_opts_cli;
struct pce_opts_cli *pce_opts_cli[MAX_PCE];
diff --git a/pathd/path_pcep_config.c b/pathd/path_pcep_config.c
index 21d127bcfe..da7ee89f2f 100644
--- a/pathd/path_pcep_config.c
+++ b/pathd/path_pcep_config.c
@@ -13,7 +13,7 @@
#include "pathd/path_pcep.h"
#include "pathd/path_pcep_config.h"
#include "pathd/path_pcep_debug.h"
-#include "thread.h"
+#include "frrevent.h"
#define MAX_XPATH 256
#define MAX_FLOAT_LEN 22
diff --git a/pathd/path_pcep_controller.c b/pathd/path_pcep_controller.c
index 405749b50f..a00a114086 100644
--- a/pathd/path_pcep_controller.c
+++ b/pathd/path_pcep_controller.c
@@ -78,28 +78,28 @@ struct get_pcep_session_args {
/* Internal Functions Called From Main Thread */
static int pcep_ctrl_halt_cb(struct frr_pthread *fpt, void **res);
-static void pcep_refine_path_event_cb(struct thread *thread);
+static void pcep_refine_path_event_cb(struct event *thread);
/* Internal Functions Called From Controller Thread */
-static void pcep_thread_finish_event_handler(struct thread *thread);
+static void pcep_thread_finish_event_handler(struct event *thread);
/* Controller Thread Timer Handler */
static int schedule_thread_timer(struct ctrl_state *ctrl_state, int pcc_id,
enum pcep_ctrl_timer_type timer_type,
enum pcep_ctrl_timeout_type timeout_type,
uint32_t delay, void *payload,
- struct thread **thread);
+ struct event **thread);
static int schedule_thread_timer_with_cb(
struct ctrl_state *ctrl_state, int pcc_id,
enum pcep_ctrl_timer_type timer_type,
enum pcep_ctrl_timeout_type timeout_type, uint32_t delay, void *payload,
- struct thread **thread, pcep_ctrl_thread_callback timer_cb);
-static void pcep_thread_timer_handler(struct thread *thread);
+ struct event **thread, pcep_ctrl_thread_callback timer_cb);
+static void pcep_thread_timer_handler(struct event *thread);
/* Controller Thread Socket read/write Handler */
static int schedule_thread_socket(struct ctrl_state *ctrl_state, int pcc_id,
enum pcep_ctrl_socket_type type, bool is_read,
- void *payload, int fd, struct thread **thread,
+ void *payload, int fd, struct event **thread,
pcep_ctrl_thread_callback cb);
/* Controller Thread Event Handler */
@@ -110,7 +110,7 @@ static int send_to_thread_with_cb(struct ctrl_state *ctrl_state, int pcc_id,
enum pcep_ctrl_event_type type,
uint32_t sub_type, void *payload,
pcep_ctrl_thread_callback event_cb);
-static void pcep_thread_event_handler(struct thread *thread);
+static void pcep_thread_event_handler(struct event *thread);
static int pcep_thread_event_update_pcc_options(struct ctrl_state *ctrl_state,
struct pcc_opts *opts);
static int pcep_thread_event_update_pce_options(struct ctrl_state *ctrl_state,
@@ -135,7 +135,7 @@ pcep_thread_path_refined_event(struct ctrl_state *ctrl_state,
/* Main Thread Event Handler */
static int send_to_main(struct ctrl_state *ctrl_state, int pcc_id,
enum pcep_main_event_type type, void *payload);
-static void pcep_main_event_handler(struct thread *thread);
+static void pcep_main_event_handler(struct event *thread);
/* Helper functions */
static void set_ctrl_state(struct frr_pthread *fpt,
@@ -152,7 +152,7 @@ static const char *timeout_type_name(enum pcep_ctrl_timeout_type type);
/* ------------ API Functions Called from Main Thread ------------ */
-int pcep_ctrl_initialize(struct thread_master *main_thread,
+int pcep_ctrl_initialize(struct event_loop *main_thread,
struct frr_pthread **fpt,
pcep_main_event_handler_t event_handler)
{
@@ -319,16 +319,16 @@ int pcep_ctrl_send_error(struct frr_pthread *fpt, int pcc_id,
int pcep_ctrl_halt_cb(struct frr_pthread *fpt, void **res)
{
- thread_add_event(fpt->master, pcep_thread_finish_event_handler,
- (void *)fpt, 0, NULL);
+ event_add_event(fpt->master, pcep_thread_finish_event_handler,
+ (void *)fpt, 0, NULL);
pthread_join(fpt->thread, res);
return 0;
}
-void pcep_refine_path_event_cb(struct thread *thread)
+void pcep_refine_path_event_cb(struct event *thread)
{
- struct pcep_refine_path_event_data *data = THREAD_ARG(thread);
+ struct pcep_refine_path_event_data *data = EVENT_ARG(thread);
assert(data != NULL);
struct ctrl_state *ctrl_state = data->ctrl_state;
struct path *path = data->path;
@@ -377,20 +377,20 @@ void pcep_thread_remove_candidate_path_segments(struct ctrl_state *ctrl_state,
void pcep_thread_schedule_sync_best_pce(struct ctrl_state *ctrl_state,
int pcc_id, int delay,
- struct thread **thread)
+ struct event **thread)
{
schedule_thread_timer(ctrl_state, pcc_id, TM_CALCULATE_BEST_PCE,
TO_UNDEFINED, delay, NULL, thread);
}
-void pcep_thread_cancel_timer(struct thread **thread)
+void pcep_thread_cancel_timer(struct event **thread)
{
if (thread == NULL || *thread == NULL) {
return;
}
- struct pcep_ctrl_timer_data *data = THREAD_ARG(*thread);
+ struct pcep_ctrl_timer_data *data = EVENT_ARG(*thread);
PCEP_DEBUG("Timer %s / %s canceled", timer_type_name(data->timer_type),
timeout_type_name(data->timeout_type));
if (data != NULL) {
@@ -398,14 +398,14 @@ void pcep_thread_cancel_timer(struct thread **thread)
}
if ((*thread)->master->owner == pthread_self()) {
- thread_cancel(thread);
+ event_cancel(thread);
} else {
- thread_cancel_async((*thread)->master, thread, NULL);
+ event_cancel_async((*thread)->master, thread, NULL);
}
}
void pcep_thread_schedule_reconnect(struct ctrl_state *ctrl_state, int pcc_id,
- int retry_count, struct thread **thread)
+ int retry_count, struct event **thread)
{
uint32_t delay = backoff_delay(MAX_RECONNECT_DELAY, 1, retry_count);
PCEP_DEBUG("Schedule RECONNECT_PCC for %us (retry %u)", delay,
@@ -417,7 +417,7 @@ void pcep_thread_schedule_reconnect(struct ctrl_state *ctrl_state, int pcc_id,
void pcep_thread_schedule_timeout(struct ctrl_state *ctrl_state, int pcc_id,
enum pcep_ctrl_timeout_type timeout_type,
uint32_t delay, void *param,
- struct thread **thread)
+ struct event **thread)
{
assert(timeout_type > TO_UNDEFINED);
assert(timeout_type < TO_MAX);
@@ -429,7 +429,7 @@ void pcep_thread_schedule_timeout(struct ctrl_state *ctrl_state, int pcc_id,
void pcep_thread_schedule_pceplib_timer(struct ctrl_state *ctrl_state,
int delay, void *payload,
- struct thread **thread,
+ struct event **thread,
pcep_ctrl_thread_callback timer_cb)
{
PCEP_DEBUG("Schedule PCEPLIB_TIMER for %us", delay);
@@ -440,7 +440,7 @@ void pcep_thread_schedule_pceplib_timer(struct ctrl_state *ctrl_state,
void pcep_thread_schedule_session_timeout(struct ctrl_state *ctrl_state,
int pcc_id, int delay,
- struct thread **thread)
+ struct event **thread)
{
PCEP_DEBUG("Schedule session_timeout interval for %us", delay);
schedule_thread_timer(ctrl_state, pcc_id, TM_SESSION_TIMEOUT_PCC,
@@ -469,8 +469,8 @@ int pcep_thread_refine_path(struct ctrl_state *ctrl_state, int pcc_id,
data->continue_lsp_update_handler = cb;
data->payload = payload;
- thread_add_event(ctrl_state->main, pcep_refine_path_event_cb,
- (void *)data, 0, NULL);
+ event_add_event(ctrl_state->main, pcep_refine_path_event_cb,
+ (void *)data, 0, NULL);
return 0;
}
@@ -493,10 +493,10 @@ void pcep_thread_path_refined_event(struct ctrl_state *ctrl_state,
/* ------------ Internal Functions Called From Controller Thread ------------ */
-void pcep_thread_finish_event_handler(struct thread *thread)
+void pcep_thread_finish_event_handler(struct event *thread)
{
int i;
- struct frr_pthread *fpt = THREAD_ARG(thread);
+ struct frr_pthread *fpt = EVENT_ARG(thread);
struct ctrl_state *ctrl_state = fpt->data;
assert(ctrl_state != NULL);
@@ -521,7 +521,7 @@ int schedule_thread_timer_with_cb(struct ctrl_state *ctrl_state, int pcc_id,
enum pcep_ctrl_timer_type timer_type,
enum pcep_ctrl_timeout_type timeout_type,
uint32_t delay, void *payload,
- struct thread **thread,
+ struct event **thread,
pcep_ctrl_thread_callback timer_cb)
{
assert(thread != NULL);
@@ -535,8 +535,8 @@ int schedule_thread_timer_with_cb(struct ctrl_state *ctrl_state, int pcc_id,
data->pcc_id = pcc_id;
data->payload = payload;
- thread_add_timer(ctrl_state->self, timer_cb, (void *)data, delay,
- thread);
+ event_add_timer(ctrl_state->self, timer_cb, (void *)data, delay,
+ thread);
return 0;
}
@@ -544,17 +544,17 @@ int schedule_thread_timer_with_cb(struct ctrl_state *ctrl_state, int pcc_id,
int schedule_thread_timer(struct ctrl_state *ctrl_state, int pcc_id,
enum pcep_ctrl_timer_type timer_type,
enum pcep_ctrl_timeout_type timeout_type,
- uint32_t delay, void *payload, struct thread **thread)
+ uint32_t delay, void *payload, struct event **thread)
{
return schedule_thread_timer_with_cb(ctrl_state, pcc_id, timer_type,
timeout_type, delay, payload,
thread, pcep_thread_timer_handler);
}
-void pcep_thread_timer_handler(struct thread *thread)
+void pcep_thread_timer_handler(struct event *thread)
{
/* data unpacking */
- struct pcep_ctrl_timer_data *data = THREAD_ARG(thread);
+ struct pcep_ctrl_timer_data *data = EVENT_ARG(thread);
assert(data != NULL);
struct ctrl_state *ctrl_state = data->ctrl_state;
assert(ctrl_state != NULL);
@@ -598,9 +598,9 @@ void pcep_thread_timer_handler(struct thread *thread)
}
}
-void pcep_thread_pcep_event(struct thread *thread)
+void pcep_thread_pcep_event(struct event *thread)
{
- struct pcep_ctrl_event_data *data = THREAD_ARG(thread);
+ struct pcep_ctrl_event_data *data = EVENT_ARG(thread);
assert(data != NULL);
struct ctrl_state *ctrl_state = data->ctrl_state;
pcep_event *event = data->payload;
@@ -624,7 +624,7 @@ void pcep_thread_pcep_event(struct thread *thread)
int schedule_thread_socket(struct ctrl_state *ctrl_state, int pcc_id,
enum pcep_ctrl_socket_type type, bool is_read,
- void *payload, int fd, struct thread **thread,
+ void *payload, int fd, struct event **thread,
pcep_ctrl_thread_callback socket_cb)
{
assert(thread != NULL);
@@ -640,11 +640,11 @@ int schedule_thread_socket(struct ctrl_state *ctrl_state, int pcc_id,
data->payload = payload;
if (is_read) {
- thread_add_read(ctrl_state->self, socket_cb, (void *)data, fd,
- thread);
+ event_add_read(ctrl_state->self, socket_cb, (void *)data, fd,
+ thread);
} else {
- thread_add_write(ctrl_state->self, socket_cb, (void *)data, fd,
- thread);
+ event_add_write(ctrl_state->self, socket_cb, (void *)data, fd,
+ thread);
}
return 0;
@@ -656,7 +656,7 @@ int pcep_thread_socket_write(void *fpt, void **thread, int fd, void *payload,
struct ctrl_state *ctrl_state = ((struct frr_pthread *)fpt)->data;
return schedule_thread_socket(ctrl_state, 0, SOCK_PCEPLIB, false,
- payload, fd, (struct thread **)thread,
+ payload, fd, (struct event **)thread,
socket_cb);
}
@@ -666,7 +666,7 @@ int pcep_thread_socket_read(void *fpt, void **thread, int fd, void *payload,
struct ctrl_state *ctrl_state = ((struct frr_pthread *)fpt)->data;
return schedule_thread_socket(ctrl_state, 0, SOCK_PCEPLIB, true,
- payload, fd, (struct thread **)thread,
+ payload, fd, (struct event **)thread,
socket_cb);
}
@@ -702,15 +702,15 @@ int send_to_thread_with_cb(struct ctrl_state *ctrl_state, int pcc_id,
data->pcc_id = pcc_id;
data->payload = payload;
- thread_add_event(ctrl_state->self, event_cb, (void *)data, 0, NULL);
+ event_add_event(ctrl_state->self, event_cb, (void *)data, 0, NULL);
return 0;
}
-void pcep_thread_event_handler(struct thread *thread)
+void pcep_thread_event_handler(struct event *thread)
{
/* data unpacking */
- struct pcep_ctrl_event_data *data = THREAD_ARG(thread);
+ struct pcep_ctrl_event_data *data = EVENT_ARG(thread);
assert(data != NULL);
struct ctrl_state *ctrl_state = data->ctrl_state;
assert(ctrl_state != NULL);
@@ -964,15 +964,15 @@ int send_to_main(struct ctrl_state *ctrl_state, int pcc_id,
data->pcc_id = pcc_id;
data->payload = payload;
- thread_add_event(ctrl_state->main, pcep_main_event_handler,
- (void *)data, 0, NULL);
+ event_add_event(ctrl_state->main, pcep_main_event_handler, (void *)data,
+ 0, NULL);
return 0;
}
-void pcep_main_event_handler(struct thread *thread)
+void pcep_main_event_handler(struct event *thread)
{
/* data unpacking */
- struct pcep_main_event_data *data = THREAD_ARG(thread);
+ struct pcep_main_event_data *data = EVENT_ARG(thread);
assert(data != NULL);
pcep_main_event_handler_t handler = data->handler;
enum pcep_main_event_type type = data->type;
diff --git a/pathd/path_pcep_controller.h b/pathd/path_pcep_controller.h
index c2359beb23..236b267715 100644
--- a/pathd/path_pcep_controller.h
+++ b/pathd/path_pcep_controller.h
@@ -33,8 +33,8 @@ enum pcep_pathd_event_type {
};
struct ctrl_state {
- struct thread_master *main;
- struct thread_master *self;
+ struct event_loop *main;
+ struct event_loop *self;
pcep_main_event_handler_t main_event_handler;
struct pcc_opts *pcc_opts;
int pcc_count;
@@ -77,7 +77,7 @@ struct pcep_ctrl_socket_data {
void *payload;
};
-typedef void (*pcep_ctrl_thread_callback)(struct thread *);
+typedef void (*pcep_ctrl_thread_callback)(struct event *);
/* PCC connection information, populated in a thread-safe
* manner with pcep_ctrl_get_pcc_info() */
@@ -97,7 +97,7 @@ struct pcep_pcc_info {
};
/* Functions called from the main thread */
-int pcep_ctrl_initialize(struct thread_master *main_thread,
+int pcep_ctrl_initialize(struct event_loop *main_thread,
struct frr_pthread **fpt,
pcep_main_event_handler_t event_handler);
int pcep_ctrl_finalize(struct frr_pthread **fpt);
@@ -134,25 +134,25 @@ void pcep_thread_update_path(struct ctrl_state *ctrl_state, int pcc_id,
struct path *path);
void pcep_thread_initiate_path(struct ctrl_state *ctrl_state, int pcc_id,
struct path *path);
-void pcep_thread_cancel_timer(struct thread **thread);
+void pcep_thread_cancel_timer(struct event **thread);
void pcep_thread_schedule_reconnect(struct ctrl_state *ctrl_state, int pcc_id,
- int retry_count, struct thread **thread);
+ int retry_count, struct event **thread);
void pcep_thread_schedule_timeout(struct ctrl_state *ctrl_state, int pcc_id,
enum pcep_ctrl_timeout_type type,
uint32_t delay, void *param,
- struct thread **thread);
+ struct event **thread);
void pcep_thread_schedule_session_timeout(struct ctrl_state *ctrl_state,
int pcc_id, int delay,
- struct thread **thread);
+ struct event **thread);
void pcep_thread_remove_candidate_path_segments(struct ctrl_state *ctrl_state,
struct pcc_state *pcc_state);
void pcep_thread_schedule_sync_best_pce(struct ctrl_state *ctrl_state,
int pcc_id, int delay,
- struct thread **thread);
+ struct event **thread);
void pcep_thread_schedule_pceplib_timer(struct ctrl_state *ctrl_state,
int delay, void *payload,
- struct thread **thread,
+ struct event **thread,
pcep_ctrl_thread_callback cb);
int pcep_thread_socket_read(void *fpt, void **thread, int fd, void *payload,
pcep_ctrl_thread_callback cb);
@@ -161,7 +161,7 @@ int pcep_thread_socket_write(void *fpt, void **thread, int fd, void *payload,
int pcep_thread_send_ctrl_event(void *fpt, void *payload,
pcep_ctrl_thread_callback cb);
-void pcep_thread_pcep_event(struct thread *thread);
+void pcep_thread_pcep_event(struct event *thread);
int pcep_thread_pcc_count(struct ctrl_state *ctrl_state);
/* Called by the PCC to refine a path in the main thread */
int pcep_thread_refine_path(struct ctrl_state *ctrl_state, int pcc_id,
diff --git a/pathd/path_pcep_lib.c b/pathd/path_pcep_lib.c
index 502f2336c7..d43fdb083e 100644
--- a/pathd/path_pcep_lib.c
+++ b/pathd/path_pcep_lib.c
@@ -33,8 +33,8 @@ static int pcep_lib_pceplib_socket_read_cb(void *fpt, void **thread, int fd,
void *payload);
static int pcep_lib_pceplib_socket_write_cb(void *fpt, void **thread, int fd,
void *payload);
-static void pcep_lib_socket_read_ready(struct thread *thread);
-static void pcep_lib_socket_write_ready(struct thread *thread);
+static void pcep_lib_socket_read_ready(struct event *thread);
+static void pcep_lib_socket_write_ready(struct event *thread);
/* pceplib pcep_event callbacks */
static void pcep_lib_pceplib_event_cb(void *fpt, pcep_event *event);
@@ -229,18 +229,18 @@ int pcep_lib_pceplib_socket_read_cb(void *fpt, void **thread, int fd,
/* Callbacks called by path_pcep_controller when a socket is ready to read/write
*/
-void pcep_lib_socket_write_ready(struct thread *thread)
+void pcep_lib_socket_write_ready(struct event *thread)
{
- struct pcep_ctrl_socket_data *data = THREAD_ARG(thread);
+ struct pcep_ctrl_socket_data *data = EVENT_ARG(thread);
assert(data != NULL);
pceplib_external_socket_write(data->fd, data->payload);
XFREE(MTYPE_PCEP, data);
}
-void pcep_lib_socket_read_ready(struct thread *thread)
+void pcep_lib_socket_read_ready(struct event *thread)
{
- struct pcep_ctrl_socket_data *data = THREAD_ARG(thread);
+ struct pcep_ctrl_socket_data *data = EVENT_ARG(thread);
assert(data != NULL);
pceplib_external_socket_read(data->fd, data->payload);
diff --git a/pathd/path_pcep_pcc.c b/pathd/path_pcep_pcc.c
index 0ff0b4403a..f18eff2888 100644
--- a/pathd/path_pcep_pcc.c
+++ b/pathd/path_pcep_pcc.c
@@ -190,17 +190,17 @@ void pcep_pcc_finalize(struct ctrl_state *ctrl_state,
}
if (pcc_state->t_reconnect != NULL) {
- thread_cancel(&pcc_state->t_reconnect);
+ event_cancel(&pcc_state->t_reconnect);
pcc_state->t_reconnect = NULL;
}
if (pcc_state->t_update_best != NULL) {
- thread_cancel(&pcc_state->t_update_best);
+ event_cancel(&pcc_state->t_update_best);
pcc_state->t_update_best = NULL;
}
if (pcc_state->t_session_timeout != NULL) {
- thread_cancel(&pcc_state->t_session_timeout);
+ event_cancel(&pcc_state->t_session_timeout);
pcc_state->t_session_timeout = NULL;
}
@@ -340,7 +340,7 @@ int pcep_pcc_enable(struct ctrl_state *ctrl_state, struct pcc_state *pcc_state)
assert(pcc_state->sess == NULL);
if (pcc_state->t_reconnect != NULL) {
- thread_cancel(&pcc_state->t_reconnect);
+ event_cancel(&pcc_state->t_reconnect);
pcc_state->t_reconnect = NULL;
}
@@ -408,7 +408,7 @@ int pcep_pcc_enable(struct ctrl_state *ctrl_state, struct pcc_state *pcc_state)
// In case some best pce alternative were waiting to activate
if (pcc_state->t_update_best != NULL) {
- thread_cancel(&pcc_state->t_update_best);
+ event_cancel(&pcc_state->t_update_best);
pcc_state->t_update_best = NULL;
}
diff --git a/pathd/path_pcep_pcc.h b/pathd/path_pcep_pcc.h
index 039d67d2e2..f3d0f290a5 100644
--- a/pathd/path_pcep_pcc.h
+++ b/pathd/path_pcep_pcc.h
@@ -41,7 +41,7 @@ struct req_map_data {
struct req_entry {
RB_ENTRY(req_entry) entry;
- struct thread *t_retry;
+ struct event *t_retry;
int retry_count;
bool was_sent;
struct path *path;
@@ -66,9 +66,9 @@ struct pcc_state {
pcep_session *sess;
uint32_t retry_count;
bool synchronized;
- struct thread *t_reconnect;
- struct thread *t_update_best;
- struct thread *t_session_timeout;
+ struct event *t_reconnect;
+ struct event *t_update_best;
+ struct event *t_session_timeout;
uint32_t next_reqid;
uint32_t next_plspid;
struct plspid_map_head plspid_map;
diff --git a/pathd/path_ted.c b/pathd/path_ted.c
index bc0da969e3..fd5c342d84 100644
--- a/pathd/path_ted.c
+++ b/pathd/path_ted.c
@@ -28,8 +28,8 @@ static void path_ted_unregister_vty(void);
static uint32_t path_ted_start_importing_igp(const char *daemon_str);
static uint32_t path_ted_stop_importing_igp(void);
static enum zclient_send_status path_ted_link_state_sync(void);
-static void path_ted_timer_handler_sync(struct thread *thread);
-static void path_ted_timer_handler_refresh(struct thread *thread);
+static void path_ted_timer_handler_sync(struct event *thread);
+static void path_ted_timer_handler_refresh(struct event *thread);
static int path_ted_cli_debug_config_write(struct vty *vty);
static int path_ted_cli_debug_set_all(uint32_t flags, bool set);
@@ -41,7 +41,7 @@ struct ted_state ted_state_g = {};
* path_path_ted public API function implementations
*/
-void path_ted_init(struct thread_master *master)
+void path_ted_init(struct event_loop *master)
{
ted_state_g.main = master;
ted_state_g.link_state_delay_interval = TIMER_RETRY_DELAY;
@@ -268,7 +268,7 @@ uint32_t path_ted_query_type_c(struct prefix *prefix, uint8_t algo)
switch (prefix->family) {
case AF_INET:
case AF_INET6:
- subnet = ls_find_subnet(ted_state_g.ted, *prefix);
+ subnet = ls_find_subnet(ted_state_g.ted, prefix);
if (subnet) {
if ((CHECK_FLAG(subnet->ls_pref->flags, LS_PREF_SR))
&& (subnet->ls_pref->sr.algo == algo))
@@ -298,7 +298,7 @@ uint32_t path_ted_query_type_e(struct prefix *prefix, uint32_t iface_id)
switch (prefix->family) {
case AF_INET:
case AF_INET6:
- subnet = ls_find_subnet(ted_state_g.ted, *prefix);
+ subnet = ls_find_subnet(ted_state_g.ted, prefix);
if (subnet && subnet->vertex
&& subnet->vertex->outgoing_edges) {
/* from the vertex linked in subnet */
@@ -583,9 +583,9 @@ enum zclient_send_status path_ted_link_state_sync(void)
PATH_TED_DEBUG("%s: PATHD-TED: Opaque asked for TED sync ",
__func__);
}
- thread_add_timer(ted_state_g.main, path_ted_timer_handler_sync,
- &ted_state_g, ted_state_g.link_state_delay_interval,
- &ted_state_g.t_link_state_sync);
+ event_add_timer(ted_state_g.main, path_ted_timer_handler_sync,
+ &ted_state_g, ted_state_g.link_state_delay_interval,
+ &ted_state_g.t_link_state_sync);
return status;
}
@@ -597,10 +597,10 @@ enum zclient_send_status path_ted_link_state_sync(void)
*
* @return status
*/
-void path_ted_timer_handler_sync(struct thread *thread)
+void path_ted_timer_handler_sync(struct event *thread)
{
/* data unpacking */
- struct ted_state *data = THREAD_ARG(thread);
+ struct ted_state *data = EVENT_ARG(thread);
assert(data != NULL);
/* Retry the sync */
@@ -619,10 +619,9 @@ int path_ted_segment_list_refresh(void)
int status = 0;
path_ted_timer_refresh_cancel();
- thread_add_timer(ted_state_g.main, path_ted_timer_handler_refresh,
- &ted_state_g,
- ted_state_g.segment_list_refresh_interval,
- &ted_state_g.t_segment_list_refresh);
+ event_add_timer(ted_state_g.main, path_ted_timer_handler_refresh,
+ &ted_state_g, ted_state_g.segment_list_refresh_interval,
+ &ted_state_g.t_segment_list_refresh);
return status;
}
@@ -634,14 +633,14 @@ int path_ted_segment_list_refresh(void)
*
* @return status
*/
-void path_ted_timer_handler_refresh(struct thread *thread)
+void path_ted_timer_handler_refresh(struct event *thread)
{
if (!path_ted_is_initialized())
return;
PATH_TED_DEBUG("%s: PATHD-TED: Refresh sid from current TED", __func__);
/* data unpacking */
- struct ted_state *data = THREAD_ARG(thread);
+ struct ted_state *data = EVENT_ARG(thread);
assert(data != NULL);
@@ -658,7 +657,7 @@ void path_ted_timer_handler_refresh(struct thread *thread)
void path_ted_timer_sync_cancel(void)
{
if (ted_state_g.t_link_state_sync != NULL) {
- thread_cancel(&ted_state_g.t_link_state_sync);
+ event_cancel(&ted_state_g.t_link_state_sync);
ted_state_g.t_link_state_sync = NULL;
}
}
@@ -673,7 +672,7 @@ void path_ted_timer_sync_cancel(void)
void path_ted_timer_refresh_cancel(void)
{
if (ted_state_g.t_segment_list_refresh != NULL) {
- thread_cancel(&ted_state_g.t_segment_list_refresh);
+ event_cancel(&ted_state_g.t_segment_list_refresh);
ted_state_g.t_segment_list_refresh = NULL;
}
}
diff --git a/pathd/path_ted.h b/pathd/path_ted.h
index 10cdd545f1..a1bc784b7f 100644
--- a/pathd/path_ted.h
+++ b/pathd/path_ted.h
@@ -41,7 +41,7 @@ enum igp_import {
IMPORT_OSPFv3
};
struct ted_state {
- struct thread_master *main;
+ struct event_loop *main;
/* Status of TED: enable or disable */
bool enabled;
/* From which igp is going to receive data */
@@ -49,9 +49,9 @@ struct ted_state {
/* The TED itself as in link_state.h */
struct ls_ted *ted;
/* Timer for ted sync */
- struct thread *t_link_state_sync;
+ struct event *t_link_state_sync;
/* Timer for refresh sid in segment list */
- struct thread *t_segment_list_refresh;
+ struct event *t_segment_list_refresh;
/* delay interval in seconds */
uint32_t link_state_delay_interval;
/* delay interval refresh in seconds */
@@ -84,7 +84,7 @@ struct ted_state {
/* TED management functions */
bool path_ted_is_initialized(void);
-void path_ted_init(struct thread_master *master);
+void path_ted_init(struct event_loop *master);
uint32_t path_ted_teardown(void);
void path_ted_timer_sync_cancel(void);
void path_ted_timer_refresh_cancel(void);
diff --git a/pathd/path_zebra.c b/pathd/path_zebra.c
index efc016f750..dad26383e9 100644
--- a/pathd/path_zebra.c
+++ b/pathd/path_zebra.c
@@ -5,7 +5,7 @@
#include <zebra.h>
-#include "thread.h"
+#include "frrevent.h"
#include "log.h"
#include "lib_errors.h"
#include "if.h"
@@ -318,7 +318,7 @@ static zclient_handler *const path_handlers[] = {
*
* @param master The master thread
*/
-void path_zebra_init(struct thread_master *master)
+void path_zebra_init(struct event_loop *master)
{
struct zclient_options options = zclient_options_default;
options.synchronous = true;
diff --git a/pathd/path_zebra.h b/pathd/path_zebra.h
index 0d435bb519..74a62e38b3 100644
--- a/pathd/path_zebra.h
+++ b/pathd/path_zebra.h
@@ -16,7 +16,7 @@ void path_zebra_add_sr_policy(struct srte_policy *policy,
void path_zebra_delete_sr_policy(struct srte_policy *policy);
int path_zebra_request_label(mpls_label_t label);
void path_zebra_release_label(mpls_label_t label);
-void path_zebra_init(struct thread_master *master);
+void path_zebra_init(struct event_loop *master);
void path_zebra_stop(void);
#endif /* _FRR_PATH_MPLS_H_ */
diff --git a/pathd/pathd.c b/pathd/pathd.c
index 86501f7ad8..6c13503c7d 100644
--- a/pathd/pathd.c
+++ b/pathd/pathd.c
@@ -45,9 +45,9 @@ struct debug path_policy_debug;
static void trigger_pathd_candidate_created(struct srte_candidate *candidate);
-static void trigger_pathd_candidate_created_timer(struct thread *thread);
+static void trigger_pathd_candidate_created_timer(struct event *thread);
static void trigger_pathd_candidate_updated(struct srte_candidate *candidate);
-static void trigger_pathd_candidate_updated_timer(struct thread *thread);
+static void trigger_pathd_candidate_updated_timer(struct event *thread);
static void trigger_pathd_candidate_removed(struct srte_candidate *candidate);
static const char *
srte_candidate_metric_name(enum srte_candidate_metric_type type);
@@ -1293,13 +1293,13 @@ void trigger_pathd_candidate_created(struct srte_candidate *candidate)
from changing the candidate by hand with the console */
if (candidate->hook_timer != NULL)
return;
- thread_add_timer(master, trigger_pathd_candidate_created_timer,
- (void *)candidate, HOOK_DELAY, &candidate->hook_timer);
+ event_add_timer(master, trigger_pathd_candidate_created_timer,
+ (void *)candidate, HOOK_DELAY, &candidate->hook_timer);
}
-void trigger_pathd_candidate_created_timer(struct thread *thread)
+void trigger_pathd_candidate_created_timer(struct event *thread)
{
- struct srte_candidate *candidate = THREAD_ARG(thread);
+ struct srte_candidate *candidate = EVENT_ARG(thread);
candidate->hook_timer = NULL;
hook_call(pathd_candidate_created, candidate);
}
@@ -1313,13 +1313,13 @@ void trigger_pathd_candidate_updated(struct srte_candidate *candidate)
from changing the candidate by hand with the console */
if (candidate->hook_timer != NULL)
return;
- thread_add_timer(master, trigger_pathd_candidate_updated_timer,
- (void *)candidate, HOOK_DELAY, &candidate->hook_timer);
+ event_add_timer(master, trigger_pathd_candidate_updated_timer,
+ (void *)candidate, HOOK_DELAY, &candidate->hook_timer);
}
-void trigger_pathd_candidate_updated_timer(struct thread *thread)
+void trigger_pathd_candidate_updated_timer(struct event *thread)
{
- struct srte_candidate *candidate = THREAD_ARG(thread);
+ struct srte_candidate *candidate = EVENT_ARG(thread);
candidate->hook_timer = NULL;
hook_call(pathd_candidate_updated, candidate);
}
@@ -1329,7 +1329,7 @@ void trigger_pathd_candidate_removed(struct srte_candidate *candidate)
/* The hook needs to be call synchronously, otherwise the candidate
path will be already deleted when the handler is called */
if (candidate->hook_timer != NULL) {
- thread_cancel(&candidate->hook_timer);
+ event_cancel(&candidate->hook_timer);
candidate->hook_timer = NULL;
}
hook_call(pathd_candidate_removed, candidate);
diff --git a/pathd/pathd.h b/pathd/pathd.h
index f1a59b1167..73ad49226e 100644
--- a/pathd/pathd.h
+++ b/pathd/pathd.h
@@ -311,7 +311,7 @@ struct srte_candidate {
uint32_t affinity_filters[MAX_AFFINITY_FILTER_TYPE];
/* Hooks delaying timer */
- struct thread *hook_timer;
+ struct event *hook_timer;
};
RB_HEAD(srte_candidate_head, srte_candidate);
@@ -371,7 +371,7 @@ extern struct srte_policy_head srte_policies;
extern struct zebra_privs_t pathd_privs;
/* master thread, defined in path_main.c */
-extern struct thread_master *master;
+extern struct event_loop *master;
/* pathd.c */
struct srte_segment_list *srte_segment_list_add(const char *name);
diff --git a/pbrd/pbr_main.c b/pbrd/pbr_main.c
index 9b34815c4d..c4708d3f08 100644
--- a/pbrd/pbr_main.c
+++ b/pbrd/pbr_main.c
@@ -8,7 +8,7 @@
#include <lib/version.h>
#include "getopt.h"
-#include "thread.h"
+#include "frrevent.h"
#include "prefix.h"
#include "linklist.h"
#include "if.h"
@@ -56,7 +56,7 @@ struct zebra_privs_t pbr_privs = {
struct option longopts[] = { { 0 } };
/* Master of threads. */
-struct thread_master *master;
+struct event_loop *master;
/* SIGHUP handler. */
static void sighup(void)
diff --git a/pbrd/pbr_map.c b/pbrd/pbr_map.c
index 0e18f1198d..16cea3b4cd 100644
--- a/pbrd/pbr_map.c
+++ b/pbrd/pbr_map.c
@@ -6,7 +6,7 @@
*/
#include <zebra.h>
-#include "thread.h"
+#include "frrevent.h"
#include "linklist.h"
#include "prefix.h"
#include "table.h"
diff --git a/pbrd/pbr_vty.c b/pbrd/pbr_vty.c
index bb09a10b98..c4e36ebd46 100644
--- a/pbrd/pbr_vty.c
+++ b/pbrd/pbr_vty.c
@@ -125,7 +125,7 @@ DEFPY(pbr_map_match_src, pbr_map_match_src_cmd,
if (!pbrms)
return CMD_WARNING_CONFIG_FAILED;
- if (pbrms->dst && pbrms->family && prefix->family != pbrms->family) {
+ if (pbrms->dst && prefix->family != pbrms->dst->family) {
vty_out(vty, "Cannot mismatch families within match src/dst\n");
return CMD_WARNING_CONFIG_FAILED;
}
@@ -161,7 +161,7 @@ DEFPY(pbr_map_match_dst, pbr_map_match_dst_cmd,
if (!pbrms)
return CMD_WARNING_CONFIG_FAILED;
- if (pbrms->src && pbrms->family && prefix->family != pbrms->family) {
+ if (pbrms->src && prefix->family != pbrms->src->family) {
vty_out(vty, "Cannot mismatch families within match src/dst\n");
return CMD_WARNING_CONFIG_FAILED;
}
diff --git a/pbrd/pbr_zebra.c b/pbrd/pbr_zebra.c
index 1b18853d2b..097c9f2964 100644
--- a/pbrd/pbr_zebra.c
+++ b/pbrd/pbr_zebra.c
@@ -6,7 +6,7 @@
*/
#include <zebra.h>
-#include "thread.h"
+#include "frrevent.h"
#include "command.h"
#include "network.h"
#include "prefix.h"
diff --git a/pbrd/pbr_zebra.h b/pbrd/pbr_zebra.h
index 850e5f06d1..ef844ef797 100644
--- a/pbrd/pbr_zebra.h
+++ b/pbrd/pbr_zebra.h
@@ -11,7 +11,7 @@ struct pbr_interface {
char mapname[100];
};
-extern struct thread_master *master;
+extern struct event_loop *master;
extern void pbr_zebra_init(void);
diff --git a/pimd/pim6_cmd.c b/pimd/pim6_cmd.c
index eb29a57e20..9394e4c15a 100644
--- a/pimd/pim6_cmd.c
+++ b/pimd/pim6_cmd.c
@@ -539,6 +539,14 @@ DEFPY (interface_ipv6_mld_join,
"Source address\n")
{
char xpath[XPATH_MAXLEN];
+ struct ipaddr group_addr = {0};
+
+ (void)str2ipaddr(group_str, &group_addr);
+
+ if (!IN6_IS_ADDR_MULTICAST(&group_addr)) {
+ vty_out(vty, "Invalid Multicast Address\n");
+ return CMD_WARNING_CONFIG_FAILED;
+ }
if (source_str) {
if (IPV6_ADDR_SAME(&source, &in6addr_any)) {
diff --git a/pimd/pim6_mld.c b/pimd/pim6_mld.c
index fcece56c6f..1d84a9941b 100644
--- a/pimd/pim6_mld.c
+++ b/pimd/pim6_mld.c
@@ -19,7 +19,7 @@
#include "lib/jhash.h"
#include "lib/prefix.h"
#include "lib/checksum.h"
-#include "lib/thread.h"
+#include "lib/frrevent.h"
#include "termtable.h"
#include "pimd/pim6_mld.h"
@@ -45,7 +45,7 @@ DEFINE_MTYPE_STATIC(PIMD, GM_SG, "MLD (S,G)");
DEFINE_MTYPE_STATIC(PIMD, GM_GRP_PENDING, "MLD group query state");
DEFINE_MTYPE_STATIC(PIMD, GM_GSQ_PENDING, "MLD group/source query aggregate");
-static void gm_t_query(struct thread *t);
+static void gm_t_query(struct event *t);
static void gm_trigger_specific(struct gm_sg *sg);
static void gm_sg_timer_start(struct gm_if *gm_ifp, struct gm_sg *sg,
struct timeval expire_wait);
@@ -329,7 +329,7 @@ static void gm_expiry_calc(struct gm_query_timers *timers)
static void gm_sg_free(struct gm_sg *sg)
{
/* t_sg_expiry is handled before this is reached */
- THREAD_OFF(sg->t_sg_query);
+ EVENT_OFF(sg->t_sg_query);
gm_packet_sg_subs_fini(sg->subs_negative);
gm_packet_sg_subs_fini(sg->subs_positive);
XFREE(MTYPE_GM_SG, sg);
@@ -404,7 +404,7 @@ static void gm_sg_update(struct gm_sg *sg, bool has_expired)
gm_expiry_calc(&timers);
gm_sg_timer_start(gm_ifp, sg, timers.expire_wait);
- THREAD_OFF(sg->t_sg_query);
+ EVENT_OFF(sg->t_sg_query);
sg->n_query = gm_ifp->cur_lmqc;
sg->query_sbit = false;
gm_trigger_specific(sg);
@@ -438,6 +438,13 @@ static void gm_sg_update(struct gm_sg *sg, bool has_expired)
}
if (desired == GM_SG_NOINFO) {
+ /* multiple paths can lead to the last state going away;
+ * t_sg_expire can still be running if we're arriving from
+ * another path.
+ */
+ if (has_expired)
+ EVENT_OFF(sg->t_sg_expire);
+
assertf((!sg->t_sg_expire &&
!gm_packet_sg_subs_count(sg->subs_positive) &&
!gm_packet_sg_subs_count(sg->subs_negative)),
@@ -575,7 +582,7 @@ static void gm_sg_expiry_cancel(struct gm_sg *sg)
{
if (sg->t_sg_expire && PIM_DEBUG_GM_TRACE)
zlog_debug(log_sg(sg, "alive, cancelling expiry timer"));
- THREAD_OFF(sg->t_sg_expire);
+ EVENT_OFF(sg->t_sg_expire);
sg->query_sbit = true;
}
@@ -1022,9 +1029,9 @@ static void gm_handle_v1_leave(struct gm_if *gm_ifp,
* its own path too and won't hit this. This is really only triggered when a
* host straight up disappears.
*/
-static void gm_t_expire(struct thread *t)
+static void gm_t_expire(struct event *t)
{
- struct gm_if *gm_ifp = THREAD_ARG(t);
+ struct gm_if *gm_ifp = EVENT_ARG(t);
struct gm_packet_state *pkt;
zlog_info(log_ifp("general expiry timer"));
@@ -1041,8 +1048,8 @@ static void gm_t_expire(struct thread *t)
log_ifp("next general expiry in %" PRId64 "ms"),
remain_ms / 1000);
- thread_add_timer_tv(router->master, gm_t_expire, gm_ifp,
- &remain, &gm_ifp->t_expire);
+ event_add_timer_tv(router->master, gm_t_expire, gm_ifp,
+ &remain, &gm_ifp->t_expire);
return;
}
@@ -1096,7 +1103,7 @@ static void gm_handle_q_general(struct gm_if *gm_ifp,
gm_ifp->n_pending--;
if (!gm_ifp->n_pending)
- THREAD_OFF(gm_ifp->t_expire);
+ EVENT_OFF(gm_ifp->t_expire);
}
/* people might be messing with their configs or something */
@@ -1112,16 +1119,16 @@ static void gm_handle_q_general(struct gm_if *gm_ifp,
zlog_debug(
log_ifp("starting general timer @ 0: %pTVMu"),
&pend->expiry);
- thread_add_timer_tv(router->master, gm_t_expire, gm_ifp,
- &timers->expire_wait, &gm_ifp->t_expire);
+ event_add_timer_tv(router->master, gm_t_expire, gm_ifp,
+ &timers->expire_wait, &gm_ifp->t_expire);
} else if (PIM_DEBUG_GM_TRACE)
zlog_debug(log_ifp("appending general timer @ %u: %pTVMu"),
gm_ifp->n_pending, &pend->expiry);
}
-static void gm_t_sg_expire(struct thread *t)
+static void gm_t_sg_expire(struct event *t)
{
- struct gm_sg *sg = THREAD_ARG(t);
+ struct gm_sg *sg = EVENT_ARG(t);
struct gm_if *gm_ifp = sg->iface;
struct gm_packet_sg *item;
@@ -1201,15 +1208,15 @@ static void gm_sg_timer_start(struct gm_if *gm_ifp, struct gm_sg *sg,
if (sg->t_sg_expire) {
struct timeval remain;
- remain = thread_timer_remain(sg->t_sg_expire);
+ remain = event_timer_remain(sg->t_sg_expire);
if (timercmp(&remain, &expire_wait, <=))
return;
- THREAD_OFF(sg->t_sg_expire);
+ EVENT_OFF(sg->t_sg_expire);
}
- thread_add_timer_tv(router->master, gm_t_sg_expire, sg, &expire_wait,
- &sg->t_sg_expire);
+ event_add_timer_tv(router->master, gm_t_sg_expire, sg, &expire_wait,
+ &sg->t_sg_expire);
}
static void gm_handle_q_groupsrc(struct gm_if *gm_ifp,
@@ -1225,7 +1232,7 @@ static void gm_handle_q_groupsrc(struct gm_if *gm_ifp,
}
}
-static void gm_t_grp_expire(struct thread *t)
+static void gm_t_grp_expire(struct event *t)
{
/* if we're here, that means when we received the group-specific query
* there was one or more active S,G for this group. For *,G the timer
@@ -1233,7 +1240,7 @@ static void gm_t_grp_expire(struct thread *t)
* receive a report, so that work is left to gm_t_sg_expire and we
* shouldn't worry about it here.
*/
- struct gm_grp_pending *pend = THREAD_ARG(t);
+ struct gm_grp_pending *pend = EVENT_ARG(t);
struct gm_if *gm_ifp = pend->iface;
struct gm_sg *sg, *sg_start, sg_ref = {};
@@ -1262,7 +1269,7 @@ static void gm_t_grp_expire(struct thread *t)
* parallel. But if we received nothing for the *,G query,
* the S,G query is kinda irrelevant.
*/
- THREAD_OFF(sg->t_sg_expire);
+ EVENT_OFF(sg->t_sg_expire);
frr_each_safe (gm_packet_sg_subs, sg->subs_positive, item)
/* this will also drop the EXCLUDE S,G lists */
@@ -1309,11 +1316,11 @@ static void gm_handle_q_group(struct gm_if *gm_ifp,
if (pend) {
struct timeval remain;
- remain = thread_timer_remain(pend->t_expire);
+ remain = event_timer_remain(pend->t_expire);
if (timercmp(&remain, &timers->expire_wait, <=))
return;
- THREAD_OFF(pend->t_expire);
+ EVENT_OFF(pend->t_expire);
} else {
pend = XCALLOC(MTYPE_GM_GRP_PENDING, sizeof(*pend));
pend->grp = grp;
@@ -1322,8 +1329,8 @@ static void gm_handle_q_group(struct gm_if *gm_ifp,
}
monotime(&pend->query);
- thread_add_timer_tv(router->master, gm_t_grp_expire, pend,
- &timers->expire_wait, &pend->t_expire);
+ event_add_timer_tv(router->master, gm_t_grp_expire, pend,
+ &timers->expire_wait, &pend->t_expire);
if (PIM_DEBUG_GM_TRACE)
zlog_debug(log_ifp("*,%pPAs S,G timer started: %pTHD"), &grp,
@@ -1334,7 +1341,7 @@ static void gm_bump_querier(struct gm_if *gm_ifp)
{
struct pim_interface *pim_ifp = gm_ifp->ifp->info;
- THREAD_OFF(gm_ifp->t_query);
+ EVENT_OFF(gm_ifp->t_query);
if (pim_addr_is_any(pim_ifp->ll_lowest))
return;
@@ -1343,12 +1350,12 @@ static void gm_bump_querier(struct gm_if *gm_ifp)
gm_ifp->n_startup = gm_ifp->cur_qrv;
- thread_execute(router->master, gm_t_query, gm_ifp, 0);
+ event_execute(router->master, gm_t_query, gm_ifp, 0);
}
-static void gm_t_other_querier(struct thread *t)
+static void gm_t_other_querier(struct event *t)
{
- struct gm_if *gm_ifp = THREAD_ARG(t);
+ struct gm_if *gm_ifp = EVENT_ARG(t);
struct pim_interface *pim_ifp = gm_ifp->ifp->info;
zlog_info(log_ifp("other querier timer expired"));
@@ -1356,7 +1363,7 @@ static void gm_t_other_querier(struct thread *t)
gm_ifp->querier = pim_ifp->ll_lowest;
gm_ifp->n_startup = gm_ifp->cur_qrv;
- thread_execute(router->master, gm_t_query, gm_ifp, 0);
+ event_execute(router->master, gm_t_query, gm_ifp, 0);
}
static void gm_handle_query(struct gm_if *gm_ifp,
@@ -1459,13 +1466,12 @@ static void gm_handle_query(struct gm_if *gm_ifp,
if (IPV6_ADDR_CMP(&pkt_src->sin6_addr, &pim_ifp->ll_lowest) < 0) {
unsigned int other_ms;
- THREAD_OFF(gm_ifp->t_query);
- THREAD_OFF(gm_ifp->t_other_querier);
+ EVENT_OFF(gm_ifp->t_query);
+ EVENT_OFF(gm_ifp->t_other_querier);
other_ms = timers.qrv * timers.qqic_ms + timers.max_resp_ms / 2;
- thread_add_timer_msec(router->master, gm_t_other_querier,
- gm_ifp, other_ms,
- &gm_ifp->t_other_querier);
+ event_add_timer_msec(router->master, gm_t_other_querier, gm_ifp,
+ other_ms, &gm_ifp->t_other_querier);
}
if (len == sizeof(struct mld_v1_pkt)) {
@@ -1579,9 +1585,9 @@ static bool ip6_check_hopopts_ra(uint8_t *hopopts, size_t hopopt_len,
return false;
}
-static void gm_t_recv(struct thread *t)
+static void gm_t_recv(struct event *t)
{
- struct pim_instance *pim = THREAD_ARG(t);
+ struct pim_instance *pim = EVENT_ARG(t);
union {
char buf[CMSG_SPACE(sizeof(struct in6_pktinfo)) +
CMSG_SPACE(256) /* hop options */ +
@@ -1600,8 +1606,8 @@ static void gm_t_recv(struct thread *t)
ssize_t nread;
size_t pktlen;
- thread_add_read(router->master, gm_t_recv, pim, pim->gm_socket,
- &pim->t_gm_recv);
+ event_add_read(router->master, gm_t_recv, pim, pim->gm_socket,
+ &pim->t_gm_recv);
iov->iov_base = rxbuf;
iov->iov_len = sizeof(rxbuf);
@@ -1851,9 +1857,9 @@ static void gm_send_query(struct gm_if *gm_ifp, pim_addr grp,
}
}
-static void gm_t_query(struct thread *t)
+static void gm_t_query(struct event *t)
{
- struct gm_if *gm_ifp = THREAD_ARG(t);
+ struct gm_if *gm_ifp = EVENT_ARG(t);
unsigned int timer_ms = gm_ifp->cur_query_intv;
if (gm_ifp->n_startup) {
@@ -1861,15 +1867,15 @@ static void gm_t_query(struct thread *t)
gm_ifp->n_startup--;
}
- thread_add_timer_msec(router->master, gm_t_query, gm_ifp, timer_ms,
- &gm_ifp->t_query);
+ event_add_timer_msec(router->master, gm_t_query, gm_ifp, timer_ms,
+ &gm_ifp->t_query);
gm_send_query(gm_ifp, PIMADDR_ANY, NULL, 0, false);
}
-static void gm_t_sg_query(struct thread *t)
+static void gm_t_sg_query(struct event *t)
{
- struct gm_sg *sg = THREAD_ARG(t);
+ struct gm_sg *sg = EVENT_ARG(t);
gm_trigger_specific(sg);
}
@@ -1888,9 +1894,9 @@ static void gm_send_specific(struct gm_gsq_pending *pend_gsq)
XFREE(MTYPE_GM_GSQ_PENDING, pend_gsq);
}
-static void gm_t_gsq_pend(struct thread *t)
+static void gm_t_gsq_pend(struct event *t)
{
- struct gm_gsq_pending *pend_gsq = THREAD_ARG(t);
+ struct gm_gsq_pending *pend_gsq = EVENT_ARG(t);
gm_send_specific(pend_gsq);
}
@@ -1903,9 +1909,9 @@ static void gm_trigger_specific(struct gm_sg *sg)
sg->n_query--;
if (sg->n_query)
- thread_add_timer_msec(router->master, gm_t_sg_query, sg,
- gm_ifp->cur_query_intv_trig,
- &sg->t_sg_query);
+ event_add_timer_msec(router->master, gm_t_sg_query, sg,
+ gm_ifp->cur_query_intv_trig,
+ &sg->t_sg_query);
if (!IPV6_ADDR_SAME(&gm_ifp->querier, &pim_ifp->ll_lowest))
return;
@@ -1931,9 +1937,8 @@ static void gm_trigger_specific(struct gm_sg *sg)
pend_gsq->iface = gm_ifp;
gm_gsq_pends_add(gm_ifp->gsq_pends, pend_gsq);
- thread_add_timer_tv(router->master, gm_t_gsq_pend, pend_gsq,
- &gm_ifp->cfg_timing_fuzz,
- &pend_gsq->t_send);
+ event_add_timer_tv(router->master, gm_t_gsq_pend, pend_gsq,
+ &gm_ifp->cfg_timing_fuzz, &pend_gsq->t_send);
}
assert(pend_gsq->n_src < array_size(pend_gsq->srcs));
@@ -1942,7 +1947,7 @@ static void gm_trigger_specific(struct gm_sg *sg)
pend_gsq->n_src++;
if (pend_gsq->n_src == array_size(pend_gsq->srcs)) {
- THREAD_OFF(pend_gsq->t_send);
+ EVENT_OFF(pend_gsq->t_send);
gm_send_specific(pend_gsq);
pend_gsq = NULL;
}
@@ -2039,8 +2044,8 @@ static void gm_vrf_socket_incref(struct pim_instance *pim)
vrf->name);
}
- thread_add_read(router->master, gm_t_recv, pim, pim->gm_socket,
- &pim->t_gm_recv);
+ event_add_read(router->master, gm_t_recv, pim, pim->gm_socket,
+ &pim->t_gm_recv);
}
static void gm_vrf_socket_decref(struct pim_instance *pim)
@@ -2048,7 +2053,7 @@ static void gm_vrf_socket_decref(struct pim_instance *pim)
if (--pim->gm_socket_if_count)
return;
- THREAD_OFF(pim->t_gm_recv);
+ EVENT_OFF(pim->t_gm_recv);
close(pim->gm_socket);
pim->gm_socket = -1;
}
@@ -2121,17 +2126,17 @@ void gm_group_delete(struct gm_if *gm_ifp)
gm_packet_drop(pkt, false);
while ((pend_grp = gm_grp_pends_pop(gm_ifp->grp_pends))) {
- THREAD_OFF(pend_grp->t_expire);
+ EVENT_OFF(pend_grp->t_expire);
XFREE(MTYPE_GM_GRP_PENDING, pend_grp);
}
while ((pend_gsq = gm_gsq_pends_pop(gm_ifp->gsq_pends))) {
- THREAD_OFF(pend_gsq->t_send);
+ EVENT_OFF(pend_gsq->t_send);
XFREE(MTYPE_GM_GSQ_PENDING, pend_gsq);
}
while ((sg = gm_sgs_pop(gm_ifp->sgs))) {
- THREAD_OFF(sg->t_sg_expire);
+ EVENT_OFF(sg->t_sg_expire);
assertf(!gm_packet_sg_subs_count(sg->subs_negative), "%pSG",
&sg->sgaddr);
assertf(!gm_packet_sg_subs_count(sg->subs_positive), "%pSG",
@@ -2159,9 +2164,9 @@ void gm_ifp_teardown(struct interface *ifp)
if (PIM_DEBUG_GM_EVENTS)
zlog_debug(log_ifp("MLD stop"));
- THREAD_OFF(gm_ifp->t_query);
- THREAD_OFF(gm_ifp->t_other_querier);
- THREAD_OFF(gm_ifp->t_expire);
+ EVENT_OFF(gm_ifp->t_query);
+ EVENT_OFF(gm_ifp->t_other_querier);
+ EVENT_OFF(gm_ifp->t_expire);
frr_with_privs (&pimd_privs) {
struct ipv6_mreq mreq;
@@ -2204,7 +2209,7 @@ static void gm_update_ll(struct interface *ifp)
gm_ifp->cur_ll_lowest = pim_ifp->ll_lowest;
if (was_querier)
gm_ifp->querier = pim_ifp->ll_lowest;
- THREAD_OFF(gm_ifp->t_query);
+ EVENT_OFF(gm_ifp->t_query);
if (pim_addr_is_any(gm_ifp->cur_ll_lowest)) {
if (was_querier)
@@ -2225,7 +2230,7 @@ static void gm_update_ll(struct interface *ifp)
return;
gm_ifp->n_startup = gm_ifp->cur_qrv;
- thread_execute(router->master, gm_t_query, gm_ifp, 0);
+ event_execute(router->master, gm_t_query, gm_ifp, 0);
}
void gm_ifp_update(struct interface *ifp)
diff --git a/pimd/pim6_mld.h b/pimd/pim6_mld.h
index 2af1c77c24..d3f1d39257 100644
--- a/pimd/pim6_mld.h
+++ b/pimd/pim6_mld.h
@@ -10,7 +10,7 @@
#include "typesafe.h"
#include "pim_addr.h"
-struct thread;
+struct event;
struct pim_instance;
struct gm_packet_sg;
struct gm_if;
@@ -65,14 +65,14 @@ struct gm_sg {
* (implies we haven't received any report yet, since it's cancelled
* by that)
*/
- struct thread *t_sg_expire;
+ struct event *t_sg_expire;
/* last-member-left triggered queries (group/group-source specific)
*
* this timer will be running even if we aren't the elected querier,
* in case the election result changes midway through.
*/
- struct thread *t_sg_query;
+ struct event *t_sg_query;
/* we must keep sending (QRV) queries even if we get a positive
* response, to make sure other routers are updated. query_sbit
@@ -226,7 +226,7 @@ struct gm_grp_pending {
pim_addr grp;
struct timeval query;
- struct thread *t_expire;
+ struct event *t_expire;
};
/* guaranteed MTU for IPv6 is 1280 bytes. IPv6 header is 40 bytes, MLDv2
@@ -247,7 +247,7 @@ struct gm_gsq_pending {
struct gm_gsq_pends_item itm;
struct gm_if *iface;
- struct thread *t_send;
+ struct event *t_send;
pim_addr grp;
bool s_bit;
@@ -300,7 +300,7 @@ struct gm_if_stats {
struct gm_if {
struct interface *ifp;
struct pim_instance *pim;
- struct thread *t_query, *t_other_querier, *t_expire;
+ struct event *t_query, *t_other_querier, *t_expire;
bool stopping;
diff --git a/pimd/pim_assert.c b/pimd/pim_assert.c
index e46fa2cfac..86d9a745ea 100644
--- a/pimd/pim_assert.c
+++ b/pimd/pim_assert.c
@@ -493,12 +493,12 @@ static int pim_assert_cancel(struct pim_ifchannel *ch)
return pim_assert_do(ch, metric);
}
-static void on_assert_timer(struct thread *t)
+static void on_assert_timer(struct event *t)
{
struct pim_ifchannel *ch;
struct interface *ifp;
- ch = THREAD_ARG(t);
+ ch = EVENT_ARG(t);
ifp = ch->interface;
@@ -535,7 +535,7 @@ static void assert_timer_off(struct pim_ifchannel *ch)
__func__, ch->sg_str, ch->interface->name);
}
}
- THREAD_OFF(ch->t_ifassert_timer);
+ EVENT_OFF(ch->t_ifassert_timer);
}
static void pim_assert_timer_set(struct pim_ifchannel *ch, int interval)
@@ -547,8 +547,8 @@ static void pim_assert_timer_set(struct pim_ifchannel *ch, int interval)
__func__, ch->sg_str, interval, ch->interface->name);
}
- thread_add_timer(router->master, on_assert_timer, ch, interval,
- &ch->t_ifassert_timer);
+ event_add_timer(router->master, on_assert_timer, ch, interval,
+ &ch->t_ifassert_timer);
}
static void pim_assert_timer_reset(struct pim_ifchannel *ch)
diff --git a/pimd/pim_bsm.c b/pimd/pim_bsm.c
index c249f323df..b36e006311 100644
--- a/pimd/pim_bsm.c
+++ b/pimd/pim_bsm.c
@@ -54,7 +54,7 @@ void pim_bsm_write_config(struct vty *vty, struct interface *ifp)
static void pim_bsm_rpinfo_free(struct bsm_rpinfo *bsrp_info)
{
- THREAD_OFF(bsrp_info->g2rp_timer);
+ EVENT_OFF(bsrp_info->g2rp_timer);
XFREE(MTYPE_PIM_BSRP_INFO, bsrp_info);
}
@@ -140,15 +140,15 @@ static struct bsgrp_node *pim_bsm_new_bsgrp_node(struct route_table *rt,
return bsgrp;
}
-static void pim_on_bs_timer(struct thread *t)
+static void pim_on_bs_timer(struct event *t)
{
struct route_node *rn;
struct bsm_scope *scope;
struct bsgrp_node *bsgrp_node;
struct bsm_rpinfo *bsrp;
- scope = THREAD_ARG(t);
- THREAD_OFF(scope->bs_timer);
+ scope = EVENT_ARG(t);
+ EVENT_OFF(scope->bs_timer);
if (PIM_DEBUG_BSM)
zlog_debug("%s: Bootstrap Timer expired for scope: %d",
@@ -189,7 +189,7 @@ static void pim_bs_timer_stop(struct bsm_scope *scope)
if (PIM_DEBUG_BSM)
zlog_debug("%s : BS timer being stopped of sz: %d", __func__,
scope->sz_id);
- THREAD_OFF(scope->bs_timer);
+ EVENT_OFF(scope->bs_timer);
}
static void pim_bs_timer_start(struct bsm_scope *scope, int bs_timeout)
@@ -199,13 +199,13 @@ static void pim_bs_timer_start(struct bsm_scope *scope, int bs_timeout)
zlog_debug("%s : Invalid scope(NULL).", __func__);
return;
}
- THREAD_OFF(scope->bs_timer);
+ EVENT_OFF(scope->bs_timer);
if (PIM_DEBUG_BSM)
zlog_debug(
"%s : starting bs timer for scope %d with timeout %d secs",
__func__, scope->sz_id, bs_timeout);
- thread_add_timer(router->master, pim_on_bs_timer, scope, bs_timeout,
- &scope->bs_timer);
+ event_add_timer(router->master, pim_on_bs_timer, scope, bs_timeout,
+ &scope->bs_timer);
}
static inline void pim_bs_timer_restart(struct bsm_scope *scope, int bs_timeout)
@@ -257,7 +257,7 @@ static bool is_hold_time_elapsed(void *data)
return true;
}
-static void pim_on_g2rp_timer(struct thread *t)
+static void pim_on_g2rp_timer(struct event *t)
{
struct bsm_rpinfo *bsrp;
struct bsm_rpinfo *bsrp_node;
@@ -268,8 +268,8 @@ static void pim_on_g2rp_timer(struct thread *t)
uint16_t elapse;
pim_addr bsrp_addr;
- bsrp = THREAD_ARG(t);
- THREAD_OFF(bsrp->g2rp_timer);
+ bsrp = EVENT_ARG(t);
+ EVENT_OFF(bsrp->g2rp_timer);
bsgrp_node = bsrp->bsgrp_node;
/* elapse time is the hold time of expired node */
@@ -331,15 +331,15 @@ static void pim_g2rp_timer_start(struct bsm_rpinfo *bsrp, int hold_time)
zlog_debug("%s : Invalid brsp(NULL).", __func__);
return;
}
- THREAD_OFF(bsrp->g2rp_timer);
+ EVENT_OFF(bsrp->g2rp_timer);
if (PIM_DEBUG_BSM)
zlog_debug(
"%s : starting g2rp timer for grp: %pFX - rp: %pPAs with timeout %d secs(Actual Hold time : %d secs)",
__func__, &bsrp->bsgrp_node->group, &bsrp->rp_address,
hold_time, bsrp->rp_holdtime);
- thread_add_timer(router->master, pim_on_g2rp_timer, bsrp, hold_time,
- &bsrp->g2rp_timer);
+ event_add_timer(router->master, pim_on_g2rp_timer, bsrp, hold_time,
+ &bsrp->g2rp_timer);
}
static inline void pim_g2rp_timer_restart(struct bsm_rpinfo *bsrp,
@@ -358,7 +358,7 @@ static void pim_g2rp_timer_stop(struct bsm_rpinfo *bsrp)
__func__, &bsrp->bsgrp_node->group,
&bsrp->rp_address);
- THREAD_OFF(bsrp->g2rp_timer);
+ EVENT_OFF(bsrp->g2rp_timer);
}
static bool is_hold_time_zero(void *data)
diff --git a/pimd/pim_bsm.h b/pimd/pim_bsm.h
index 5e40adb806..fb09e3b1cc 100644
--- a/pimd/pim_bsm.h
+++ b/pimd/pim_bsm.h
@@ -59,7 +59,7 @@ struct bsm_scope {
struct bsm_frags_head bsm_frags[1];
struct route_table *bsrp_table; /* group2rp mapping rcvd from BSR */
- struct thread *bs_timer; /* Boot strap timer */
+ struct event *bs_timer; /* Boot strap timer */
};
/* BSM packet (= fragment) - this is stored as list in bsm_frags inside scope
@@ -103,7 +103,7 @@ struct bsm_rpinfo {
uint16_t rp_holdtime; /* RP holdtime - g2rp timer value */
pim_addr rp_address; /* RP Address */
struct bsgrp_node *bsgrp_node; /* Back ptr to bsgrp_node */
- struct thread *g2rp_timer; /* Run only for elected RP node */
+ struct event *g2rp_timer; /* Run only for elected RP node */
};
extern int pim_bsm_rpinfo_cmp(const struct bsm_rpinfo *a,
diff --git a/pimd/pim_iface.c b/pimd/pim_iface.c
index d284912d1d..ead02d8bd7 100644
--- a/pimd/pim_iface.c
+++ b/pimd/pim_iface.c
@@ -982,6 +982,12 @@ int pim_if_add_vif(struct interface *ifp, bool ispimreg, bool is_vxlan_term)
zlog_warn("%s: ifindex=%d < 1 on interface %s", __func__,
ifp->ifindex, ifp->name);
return -2;
+ } else if ((ifp->ifindex == 0) &&
+ ((strncmp(ifp->name, "pimreg", 6)) &&
+ (strncmp(ifp->name, "pim6reg", 7)))) {
+ zlog_warn("%s: ifindex=%d == 0 on interface %s", __func__,
+ ifp->ifindex, ifp->name);
+ return -2;
}
ifaddr = pim_ifp->primary_address;
diff --git a/pimd/pim_iface.h b/pimd/pim_iface.h
index 83079020b8..0aff56d558 100644
--- a/pimd/pim_iface.h
+++ b/pimd/pim_iface.h
@@ -104,10 +104,10 @@ struct pim_interface {
struct gm_if *mld;
int pim_sock_fd; /* PIM socket file descriptor */
- struct thread *t_pim_sock_read; /* thread for reading PIM socket */
+ struct event *t_pim_sock_read; /* thread for reading PIM socket */
int64_t pim_sock_creation; /* timestamp of PIM socket creation */
- struct thread *t_pim_hello_timer;
+ struct event *t_pim_hello_timer;
int pim_hello_period;
int pim_default_holdtime;
int pim_triggered_hello_delay;
diff --git a/pimd/pim_ifchannel.c b/pimd/pim_ifchannel.c
index 136498beb7..bc6b84ff2c 100644
--- a/pimd/pim_ifchannel.c
+++ b/pimd/pim_ifchannel.c
@@ -7,7 +7,7 @@
#include <zebra.h>
#include "linklist.h"
-#include "thread.h"
+#include "frrevent.h"
#include "memory.h"
#include "if.h"
#include "vrf.h"
@@ -193,9 +193,9 @@ void pim_ifchannel_delete(struct pim_ifchannel *ch)
ch->upstream = NULL;
- THREAD_OFF(ch->t_ifjoin_expiry_timer);
- THREAD_OFF(ch->t_ifjoin_prune_pending_timer);
- THREAD_OFF(ch->t_ifassert_timer);
+ EVENT_OFF(ch->t_ifjoin_expiry_timer);
+ EVENT_OFF(ch->t_ifjoin_prune_pending_timer);
+ EVENT_OFF(ch->t_ifassert_timer);
if (ch->parent) {
listnode_delete(ch->parent->sources, ch);
@@ -411,7 +411,7 @@ const char *pim_ifchannel_ifassert_name(enum pim_ifassert_state ifassert_state)
*/
void reset_ifassert_state(struct pim_ifchannel *ch)
{
- THREAD_OFF(ch->t_ifassert_timer);
+ EVENT_OFF(ch->t_ifassert_timer);
pim_ifassert_winner_set(ch, PIM_IFASSERT_NOINFO, PIMADDR_ANY,
router->infinite_assert_metric);
@@ -628,11 +628,11 @@ static void ifjoin_to_noinfo(struct pim_ifchannel *ch)
delete_on_noinfo(ch);
}
-static void on_ifjoin_expiry_timer(struct thread *t)
+static void on_ifjoin_expiry_timer(struct event *t)
{
struct pim_ifchannel *ch;
- ch = THREAD_ARG(t);
+ ch = EVENT_ARG(t);
if (PIM_DEBUG_PIM_TRACE)
zlog_debug("%s: ifchannel %s expiry timer", __func__,
@@ -642,14 +642,14 @@ static void on_ifjoin_expiry_timer(struct thread *t)
/* ch may have been deleted */
}
-static void on_ifjoin_prune_pending_timer(struct thread *t)
+static void on_ifjoin_prune_pending_timer(struct event *t)
{
struct pim_ifchannel *ch;
int send_prune_echo; /* boolean */
struct interface *ifp;
struct pim_interface *pim_ifp;
- ch = THREAD_ARG(t);
+ ch = EVENT_ARG(t);
if (PIM_DEBUG_PIM_TRACE)
zlog_debug("%s: IFCHANNEL%pSG %s Prune Pending Timer Popped",
@@ -896,7 +896,7 @@ void pim_ifchannel_join_add(struct interface *ifp, pim_addr neigh_addr,
previously received join message with holdtime=0xFFFF.
*/
if (ch->t_ifjoin_expiry_timer) {
- unsigned long remain = thread_timer_remain_second(
+ unsigned long remain = event_timer_remain_second(
ch->t_ifjoin_expiry_timer);
if (remain > holdtime) {
/*
@@ -920,13 +920,13 @@ void pim_ifchannel_join_add(struct interface *ifp, pim_addr neigh_addr,
return;
}
}
- THREAD_OFF(ch->t_ifjoin_expiry_timer);
+ EVENT_OFF(ch->t_ifjoin_expiry_timer);
break;
case PIM_IFJOIN_PRUNE:
if (source_flags & PIM_ENCODE_RPT_BIT) {
pim_ifchannel_ifjoin_switch(__func__, ch,
PIM_IFJOIN_NOINFO);
- THREAD_OFF(ch->t_ifjoin_expiry_timer);
+ EVENT_OFF(ch->t_ifjoin_expiry_timer);
delete_on_noinfo(ch);
return;
} else
@@ -943,7 +943,7 @@ void pim_ifchannel_join_add(struct interface *ifp, pim_addr neigh_addr,
* maximum of its current value and the HoldTime from the
* triggering Join/Prune message.
*/
- THREAD_OFF(ch->t_ifjoin_prune_pending_timer);
+ EVENT_OFF(ch->t_ifjoin_prune_pending_timer);
/* Check if SGRpt join Received */
if ((source_flags & PIM_ENCODE_RPT_BIT) &&
@@ -955,7 +955,7 @@ void pim_ifchannel_join_add(struct interface *ifp, pim_addr neigh_addr,
* I transitions to the NoInfo state.The ET and PPT are
* cancelled.
*/
- THREAD_OFF(ch->t_ifjoin_expiry_timer);
+ EVENT_OFF(ch->t_ifjoin_expiry_timer);
pim_ifchannel_ifjoin_switch(__func__, ch,
PIM_IFJOIN_NOINFO);
return;
@@ -964,13 +964,13 @@ void pim_ifchannel_join_add(struct interface *ifp, pim_addr neigh_addr,
pim_ifchannel_ifjoin_handler(ch, pim_ifp);
if (ch->t_ifjoin_expiry_timer) {
- unsigned long remain = thread_timer_remain_second(
+ unsigned long remain = event_timer_remain_second(
ch->t_ifjoin_expiry_timer);
if (remain > holdtime)
return;
}
- THREAD_OFF(ch->t_ifjoin_expiry_timer);
+ EVENT_OFF(ch->t_ifjoin_expiry_timer);
break;
case PIM_IFJOIN_PRUNE_TMP:
@@ -980,8 +980,8 @@ void pim_ifchannel_join_add(struct interface *ifp, pim_addr neigh_addr,
}
if (holdtime != 0xFFFF) {
- thread_add_timer(router->master, on_ifjoin_expiry_timer, ch,
- holdtime, &ch->t_ifjoin_expiry_timer);
+ event_add_timer(router->master, on_ifjoin_expiry_timer, ch,
+ holdtime, &ch->t_ifjoin_expiry_timer);
}
}
@@ -1030,15 +1030,15 @@ void pim_ifchannel_prune(struct interface *ifp, pim_addr upstream,
be taken not to use "ch" afterwards since it would be
deleted. */
- THREAD_OFF(ch->t_ifjoin_prune_pending_timer);
- THREAD_OFF(ch->t_ifjoin_expiry_timer);
- thread_add_timer_msec(
- router->master, on_ifjoin_prune_pending_timer,
- ch, jp_override_interval_msec,
- &ch->t_ifjoin_prune_pending_timer);
- thread_add_timer(router->master, on_ifjoin_expiry_timer,
- ch, holdtime,
- &ch->t_ifjoin_expiry_timer);
+ EVENT_OFF(ch->t_ifjoin_prune_pending_timer);
+ EVENT_OFF(ch->t_ifjoin_expiry_timer);
+ event_add_timer_msec(router->master,
+ on_ifjoin_prune_pending_timer, ch,
+ jp_override_interval_msec,
+ &ch->t_ifjoin_prune_pending_timer);
+ event_add_timer(router->master, on_ifjoin_expiry_timer,
+ ch, holdtime,
+ &ch->t_ifjoin_expiry_timer);
pim_upstream_update_join_desired(pim_ifp->pim,
ch->upstream);
}
@@ -1068,15 +1068,15 @@ void pim_ifchannel_prune(struct interface *ifp, pim_addr upstream,
/* If we called ifjoin_prune() directly instead, care should
be taken not to use "ch" afterwards since it would be
deleted. */
- THREAD_OFF(ch->t_ifjoin_prune_pending_timer);
- thread_add_timer_msec(router->master,
- on_ifjoin_prune_pending_timer, ch,
- jp_override_interval_msec,
- &ch->t_ifjoin_prune_pending_timer);
+ EVENT_OFF(ch->t_ifjoin_prune_pending_timer);
+ event_add_timer_msec(router->master,
+ on_ifjoin_prune_pending_timer, ch,
+ jp_override_interval_msec,
+ &ch->t_ifjoin_prune_pending_timer);
break;
case PIM_IFJOIN_PRUNE:
if (source_flags & PIM_ENCODE_RPT_BIT) {
- THREAD_OFF(ch->t_ifjoin_prune_pending_timer);
+ EVENT_OFF(ch->t_ifjoin_prune_pending_timer);
/*
* While in Prune State, Receive SGRpt Prune.
* RFC 7761 Sec 4.5.3:
@@ -1087,35 +1087,35 @@ void pim_ifchannel_prune(struct interface *ifp, pim_addr upstream,
* Join/Prune message.
*/
if (ch->t_ifjoin_expiry_timer) {
- unsigned long rem = thread_timer_remain_second(
+ unsigned long rem = event_timer_remain_second(
ch->t_ifjoin_expiry_timer);
if (rem > holdtime)
return;
- THREAD_OFF(ch->t_ifjoin_expiry_timer);
+ EVENT_OFF(ch->t_ifjoin_expiry_timer);
}
- thread_add_timer(router->master, on_ifjoin_expiry_timer,
- ch, holdtime,
- &ch->t_ifjoin_expiry_timer);
+ event_add_timer(router->master, on_ifjoin_expiry_timer,
+ ch, holdtime,
+ &ch->t_ifjoin_expiry_timer);
}
break;
case PIM_IFJOIN_PRUNE_TMP:
if (source_flags & PIM_ENCODE_RPT_BIT) {
ch->ifjoin_state = PIM_IFJOIN_PRUNE;
- THREAD_OFF(ch->t_ifjoin_expiry_timer);
- thread_add_timer(router->master, on_ifjoin_expiry_timer,
- ch, holdtime,
- &ch->t_ifjoin_expiry_timer);
+ EVENT_OFF(ch->t_ifjoin_expiry_timer);
+ event_add_timer(router->master, on_ifjoin_expiry_timer,
+ ch, holdtime,
+ &ch->t_ifjoin_expiry_timer);
}
break;
case PIM_IFJOIN_PRUNE_PENDING_TMP:
if (source_flags & PIM_ENCODE_RPT_BIT) {
ch->ifjoin_state = PIM_IFJOIN_PRUNE_PENDING;
- THREAD_OFF(ch->t_ifjoin_expiry_timer);
- thread_add_timer(router->master, on_ifjoin_expiry_timer,
- ch, holdtime,
- &ch->t_ifjoin_expiry_timer);
+ EVENT_OFF(ch->t_ifjoin_expiry_timer);
+ event_add_timer(router->master, on_ifjoin_expiry_timer,
+ ch, holdtime,
+ &ch->t_ifjoin_expiry_timer);
}
break;
}
@@ -1466,8 +1466,8 @@ void pim_ifchannel_set_star_g_join_state(struct pim_ifchannel *ch, int eom,
break;
if (child->ifjoin_state == PIM_IFJOIN_PRUNE_PENDING_TMP)
- THREAD_OFF(child->t_ifjoin_prune_pending_timer);
- THREAD_OFF(child->t_ifjoin_expiry_timer);
+ EVENT_OFF(child->t_ifjoin_prune_pending_timer);
+ EVENT_OFF(child->t_ifjoin_expiry_timer);
PIM_IF_FLAG_UNSET_S_G_RPT(child->flags);
child->ifjoin_state = PIM_IFJOIN_NOINFO;
diff --git a/pimd/pim_ifchannel.h b/pimd/pim_ifchannel.h
index 7ab491e99b..4b0ff955f9 100644
--- a/pimd/pim_ifchannel.h
+++ b/pimd/pim_ifchannel.h
@@ -86,13 +86,13 @@ struct pim_ifchannel {
/* Per-interface (S,G) Join/Prune State (Section 4.1.4 of RFC4601) */
enum pim_ifjoin_state ifjoin_state;
- struct thread *t_ifjoin_expiry_timer;
- struct thread *t_ifjoin_prune_pending_timer;
+ struct event *t_ifjoin_expiry_timer;
+ struct event *t_ifjoin_prune_pending_timer;
int64_t ifjoin_creation; /* Record uptime of ifjoin state */
/* Per-interface (S,G) Assert State (Section 4.6.1 of RFC4601) */
enum pim_ifassert_state ifassert_state;
- struct thread *t_ifassert_timer;
+ struct event *t_ifassert_timer;
pim_addr ifassert_winner;
struct pim_assert_metric ifassert_winner_metric;
int64_t ifassert_creation; /* Record uptime of ifassert state */
diff --git a/pimd/pim_igmp.c b/pimd/pim_igmp.c
index bff0c0683e..063ba6edd2 100644
--- a/pimd/pim_igmp.c
+++ b/pimd/pim_igmp.c
@@ -29,7 +29,7 @@
#include "pim_tib.h"
static void group_timer_off(struct gm_group *group);
-static void pim_igmp_general_query(struct thread *t);
+static void pim_igmp_general_query(struct event *t);
void igmp_anysource_forward_start(struct pim_instance *pim,
struct gm_group *group)
@@ -325,11 +325,11 @@ struct gm_sock *pim_igmp_sock_lookup_ifaddr(struct list *igmp_sock_list,
return NULL;
}
-static void pim_igmp_other_querier_expire(struct thread *t)
+static void pim_igmp_other_querier_expire(struct event *t)
{
struct gm_sock *igmp;
- igmp = THREAD_ARG(t);
+ igmp = EVENT_ARG(t);
assert(!igmp->t_igmp_query_timer);
@@ -377,7 +377,7 @@ void pim_igmp_other_querier_timer_on(struct gm_sock *igmp)
"Querier %s resetting TIMER event for Other-Querier-Present",
ifaddr_str);
}
- THREAD_OFF(igmp->t_other_querier_timer);
+ EVENT_OFF(igmp->t_other_querier_timer);
} else {
/*
We are the current querier, then stop sending general queries:
@@ -420,9 +420,9 @@ void pim_igmp_other_querier_timer_on(struct gm_sock *igmp)
other_querier_present_interval_msec % 1000);
}
- thread_add_timer_msec(router->master, pim_igmp_other_querier_expire,
- igmp, other_querier_present_interval_msec,
- &igmp->t_other_querier_timer);
+ event_add_timer_msec(router->master, pim_igmp_other_querier_expire,
+ igmp, other_querier_present_interval_msec,
+ &igmp->t_other_querier_timer);
}
void pim_igmp_other_querier_timer_off(struct gm_sock *igmp)
@@ -439,7 +439,7 @@ void pim_igmp_other_querier_timer_off(struct gm_sock *igmp)
ifaddr_str, igmp->fd, igmp->interface->name);
}
}
- THREAD_OFF(igmp->t_other_querier_timer);
+ EVENT_OFF(igmp->t_other_querier_timer);
}
int igmp_validate_checksum(char *igmp_msg, int igmp_msg_len)
@@ -865,8 +865,8 @@ void pim_igmp_general_query_on(struct gm_sock *igmp)
ifaddr_str, query_interval,
startup_mode ? "startup" : "non-startup", igmp->fd);
}
- thread_add_timer(router->master, pim_igmp_general_query, igmp,
- query_interval, &igmp->t_igmp_query_timer);
+ event_add_timer(router->master, pim_igmp_general_query, igmp,
+ query_interval, &igmp->t_igmp_query_timer);
}
void pim_igmp_general_query_off(struct gm_sock *igmp)
@@ -883,11 +883,11 @@ void pim_igmp_general_query_off(struct gm_sock *igmp)
ifaddr_str, igmp->fd, igmp->interface->name);
}
}
- THREAD_OFF(igmp->t_igmp_query_timer);
+ EVENT_OFF(igmp->t_igmp_query_timer);
}
/* Issue IGMP general query */
-static void pim_igmp_general_query(struct thread *t)
+static void pim_igmp_general_query(struct event *t)
{
struct gm_sock *igmp;
struct in_addr dst_addr;
@@ -895,7 +895,7 @@ static void pim_igmp_general_query(struct thread *t)
struct pim_interface *pim_ifp;
int query_buf_size;
- igmp = THREAD_ARG(t);
+ igmp = EVENT_ARG(t);
assert(igmp->interface);
assert(igmp->interface->info);
@@ -953,7 +953,7 @@ static void sock_close(struct gm_sock *igmp)
igmp->interface->name);
}
}
- THREAD_OFF(igmp->t_igmp_read);
+ EVENT_OFF(igmp->t_igmp_read);
if (close(igmp->fd)) {
flog_err(
@@ -1045,7 +1045,7 @@ void igmp_group_delete(struct gm_group *group)
igmp_source_delete(src);
}
- THREAD_OFF(group->t_group_query_retransmit_timer);
+ EVENT_OFF(group->t_group_query_retransmit_timer);
group_timer_off(group);
igmp_group_count_decr(pim_ifp);
@@ -1208,10 +1208,10 @@ static struct gm_sock *igmp_sock_new(int fd, struct in_addr ifaddr,
static void igmp_read_on(struct gm_sock *igmp);
-static void pim_igmp_read(struct thread *t)
+static void pim_igmp_read(struct event *t)
{
uint8_t buf[10000];
- struct gm_sock *igmp = (struct gm_sock *)THREAD_ARG(t);
+ struct gm_sock *igmp = (struct gm_sock *)EVENT_ARG(t);
struct sockaddr_storage from;
struct sockaddr_storage to;
socklen_t fromlen = sizeof(from);
@@ -1243,8 +1243,8 @@ static void igmp_read_on(struct gm_sock *igmp)
zlog_debug("Scheduling READ event on IGMP socket fd=%d",
igmp->fd);
}
- thread_add_read(router->master, pim_igmp_read, igmp, igmp->fd,
- &igmp->t_igmp_read);
+ event_add_read(router->master, pim_igmp_read, igmp, igmp->fd,
+ &igmp->t_igmp_read);
}
struct gm_sock *pim_igmp_sock_add(struct list *igmp_sock_list,
@@ -1300,11 +1300,11 @@ struct gm_sock *pim_igmp_sock_add(struct list *igmp_sock_list,
source records. Source records whose timers are zero (from the
previous EXCLUDE mode) are deleted.
*/
-static void igmp_group_timer(struct thread *t)
+static void igmp_group_timer(struct event *t)
{
struct gm_group *group;
- group = THREAD_ARG(t);
+ group = EVENT_ARG(t);
if (PIM_DEBUG_GM_TRACE) {
char group_str[INET_ADDRSTRLEN];
@@ -1348,7 +1348,7 @@ static void group_timer_off(struct gm_group *group)
zlog_debug("Cancelling TIMER event for group %s on %s",
group_str, group->interface->name);
}
- THREAD_OFF(group->t_group_timer);
+ EVENT_OFF(group->t_group_timer);
}
void igmp_group_timer_on(struct gm_group *group, long interval_msec,
@@ -1375,8 +1375,8 @@ void igmp_group_timer_on(struct gm_group *group, long interval_msec,
*/
assert(group->group_filtermode_isexcl);
- thread_add_timer_msec(router->master, igmp_group_timer, group,
- interval_msec, &group->t_group_timer);
+ event_add_timer_msec(router->master, igmp_group_timer, group,
+ interval_msec, &group->t_group_timer);
}
struct gm_group *find_group_by_addr(struct gm_sock *igmp,
diff --git a/pimd/pim_igmp.h b/pimd/pim_igmp.h
index e275b5b398..a1f19b3c6e 100644
--- a/pimd/pim_igmp.h
+++ b/pimd/pim_igmp.h
@@ -64,10 +64,10 @@ struct gm_sock {
pim_addr ifaddr;
time_t sock_creation;
- struct thread *t_igmp_read; /* read: IGMP sockets */
- struct thread
- *t_igmp_query_timer; /* timer: issue IGMP general queries */
- struct thread *t_other_querier_timer; /* timer: other querier present */
+ struct event *t_igmp_read; /* read: IGMP sockets */
+ /* timer: issue IGMP general queries */
+ struct event *t_igmp_query_timer;
+ struct event *t_other_querier_timer; /* timer: other querier present */
pim_addr querier_addr; /* IP address of the querier */
int querier_query_interval; /* QQI */
int querier_robustness_variable; /* QRV */
@@ -144,7 +144,7 @@ static inline void pim_igmp_other_querier_timer_off(struct gm_sock *igmp)
struct gm_source {
pim_addr source_addr;
- struct thread *t_source_timer;
+ struct event *t_source_timer;
struct gm_group *source_group; /* back pointer */
time_t source_creation;
uint32_t source_flags;
@@ -165,11 +165,11 @@ struct gm_group {
represents the time for the *filter-mode* of the group to expire and
switch to INCLUDE mode.
*/
- struct thread *t_group_timer;
+ struct event *t_group_timer;
/* Shared between group-specific and
group-and-source-specific retransmissions */
- struct thread *t_group_query_retransmit_timer;
+ struct event *t_group_query_retransmit_timer;
/* Counter exclusive for group-specific retransmissions
(not used by group-and-source-specific retransmissions,
diff --git a/pimd/pim_igmpv3.c b/pimd/pim_igmpv3.c
index f10bcaf04b..15078dd1ec 100644
--- a/pimd/pim_igmpv3.c
+++ b/pimd/pim_igmpv3.c
@@ -107,12 +107,12 @@ void igmp_group_reset_gmi(struct gm_group *group)
igmp_group_timer_on(group, group_membership_interval_msec, ifp->name);
}
-static void igmp_source_timer(struct thread *t)
+static void igmp_source_timer(struct event *t)
{
struct gm_source *source;
struct gm_group *group;
- source = THREAD_ARG(t);
+ source = EVENT_ARG(t);
group = source->source_group;
@@ -187,7 +187,7 @@ static void source_timer_off(struct gm_group *group, struct gm_source *source)
group_str, source_str, group->interface->name);
}
- THREAD_OFF(source->t_source_timer);
+ EVENT_OFF(source->t_source_timer);
}
static void igmp_source_timer_on(struct gm_group *group,
@@ -209,8 +209,8 @@ static void igmp_source_timer_on(struct gm_group *group,
source_str, group->interface->name);
}
- thread_add_timer_msec(router->master, igmp_source_timer, source,
- interval_msec, &source->t_source_timer);
+ event_add_timer_msec(router->master, igmp_source_timer, source,
+ interval_msec, &source->t_source_timer);
/*
RFC 3376: 6.3. IGMPv3 Source-Specific Forwarding Rules
@@ -1200,13 +1200,13 @@ static int group_retransmit_sources(struct gm_group *group,
return num_retransmit_sources_left;
}
-static void igmp_group_retransmit(struct thread *t)
+static void igmp_group_retransmit(struct event *t)
{
struct gm_group *group;
int num_retransmit_sources_left;
int send_with_sflag_set; /* boolean */
- group = THREAD_ARG(t);
+ group = EVENT_ARG(t);
if (PIM_DEBUG_GM_TRACE) {
char group_str[INET_ADDRSTRLEN];
@@ -1281,9 +1281,8 @@ static void group_retransmit_timer_on(struct gm_group *group)
group->interface->name);
}
- thread_add_timer_msec(router->master, igmp_group_retransmit, group,
- lmqi_msec,
- &group->t_group_query_retransmit_timer);
+ event_add_timer_msec(router->master, igmp_group_retransmit, group,
+ lmqi_msec, &group->t_group_query_retransmit_timer);
}
static long igmp_group_timer_remain_msec(struct gm_group *group)
diff --git a/pimd/pim_instance.c b/pimd/pim_instance.c
index b50d9954f7..6f33af0601 100644
--- a/pimd/pim_instance.c
+++ b/pimd/pim_instance.c
@@ -45,11 +45,7 @@ static void pim_instance_terminate(struct pim_instance *pim)
pim_bsm_proc_free(pim);
/* Traverse and cleanup rpf_hash */
- if (pim->rpf_hash) {
- hash_clean(pim->rpf_hash, (void *)pim_rp_list_hash_clean);
- hash_free(pim->rpf_hash);
- pim->rpf_hash = NULL;
- }
+ hash_clean_and_free(&pim->rpf_hash, (void *)pim_rp_list_hash_clean);
pim_if_terminate(pim);
diff --git a/pimd/pim_instance.h b/pimd/pim_instance.h
index fa90e38a16..11577ae46d 100644
--- a/pimd/pim_instance.h
+++ b/pimd/pim_instance.h
@@ -64,7 +64,7 @@ enum pim_mlag_flags {
};
struct pim_router {
- struct thread_master *master;
+ struct event_loop *master;
uint32_t debugs;
@@ -92,7 +92,7 @@ struct pim_router {
/* Holds the client data(unencoded) that need to be pushed to MCLAGD*/
struct stream_fifo *mlag_fifo;
struct stream *mlag_stream;
- struct thread *zpthread_mlag_write;
+ struct event *zpthread_mlag_write;
struct in_addr anycast_vtep_ip;
struct in_addr local_vtep_ip;
struct pim_mlag_stats mlag_stats;
@@ -120,7 +120,7 @@ struct pim_instance {
int send_v6_secondary;
- struct thread *thread;
+ struct event *thread;
int mroute_socket;
int reg_sock; /* Socket to send register msg */
int64_t mroute_socket_creation;
@@ -157,7 +157,7 @@ struct pim_instance {
unsigned int gm_socket_if_count;
int gm_socket;
- struct thread *t_gm_recv;
+ struct event *t_gm_recv;
unsigned int gm_group_count;
unsigned int gm_watermark_limit;
@@ -176,7 +176,7 @@ struct pim_instance {
uint64_t bsm_dropped;
/* If we need to rescan all our upstreams */
- struct thread *rpf_cache_refresher;
+ struct event *rpf_cache_refresher;
int64_t rpf_cache_refresh_requests;
int64_t rpf_cache_refresh_events;
int64_t rpf_cache_refresh_last;
diff --git a/pimd/pim_join.c b/pimd/pim_join.c
index 20821d58b8..671f7a37a5 100644
--- a/pimd/pim_join.c
+++ b/pimd/pim_join.c
@@ -326,10 +326,9 @@ int pim_joinprune_recv(struct interface *ifp, struct pim_neighbor *neigh,
if (PIM_IF_FLAG_TEST_S_G_RPT(child->flags)) {
if (child->ifjoin_state
== PIM_IFJOIN_PRUNE_PENDING_TMP)
- THREAD_OFF(
+ EVENT_OFF(
child->t_ifjoin_prune_pending_timer);
- THREAD_OFF(
- child->t_ifjoin_expiry_timer);
+ EVENT_OFF(child->t_ifjoin_expiry_timer);
PIM_IF_FLAG_UNSET_S_G_RPT(child->flags);
child->ifjoin_state = PIM_IFJOIN_NOINFO;
delete_on_noinfo(child);
diff --git a/pimd/pim_main.c b/pimd/pim_main.c
index ce4326c616..7db0a7676b 100644
--- a/pimd/pim_main.c
+++ b/pimd/pim_main.c
@@ -11,7 +11,7 @@
#include "lib/version.h"
#include <getopt.h>
#include "command.h"
-#include "thread.h"
+#include "frrevent.h"
#include <signal.h>
#include "memory.h"
diff --git a/pimd/pim_mlag.c b/pimd/pim_mlag.c
index 61cf2860fd..5d72eb6581 100644
--- a/pimd/pim_mlag.c
+++ b/pimd/pim_mlag.c
@@ -921,7 +921,7 @@ int pim_zebra_mlag_process_down(ZAPI_CALLBACK_ARGS)
return 0;
}
-static void pim_mlag_register_handler(struct thread *thread)
+static void pim_mlag_register_handler(struct event *thread)
{
uint32_t bit_mask = 0;
@@ -952,11 +952,11 @@ void pim_mlag_register(void)
router->mlag_process_register = true;
- thread_add_event(router->master, pim_mlag_register_handler, NULL, 0,
- NULL);
+ event_add_event(router->master, pim_mlag_register_handler, NULL, 0,
+ NULL);
}
-static void pim_mlag_deregister_handler(struct thread *thread)
+static void pim_mlag_deregister_handler(struct event *thread)
{
if (!zclient)
return;
@@ -980,8 +980,8 @@ void pim_mlag_deregister(void)
router->mlag_process_register = false;
- thread_add_event(router->master, pim_mlag_deregister_handler, NULL, 0,
- NULL);
+ event_add_event(router->master, pim_mlag_deregister_handler, NULL, 0,
+ NULL);
}
void pim_if_configure_mlag_dualactive(struct pim_interface *pim_ifp)
diff --git a/pimd/pim_mroute.c b/pimd/pim_mroute.c
index adf0540f65..4d5da31827 100644
--- a/pimd/pim_mroute.c
+++ b/pimd/pim_mroute.c
@@ -767,7 +767,7 @@ int pim_mroute_msg(struct pim_instance *pim, const char *buf, size_t buf_size,
return 0;
}
-static void mroute_read(struct thread *t)
+static void mroute_read(struct event *t)
{
struct pim_instance *pim;
static long long count;
@@ -775,7 +775,7 @@ static void mroute_read(struct thread *t)
int cont = 1;
int rd;
ifindex_t ifindex;
- pim = THREAD_ARG(t);
+ pim = EVENT_ARG(t);
while (cont) {
rd = pim_socket_recvfromto(pim->mroute_socket, (uint8_t *)buf,
@@ -809,13 +809,13 @@ done:
static void mroute_read_on(struct pim_instance *pim)
{
- thread_add_read(router->master, mroute_read, pim, pim->mroute_socket,
- &pim->thread);
+ event_add_read(router->master, mroute_read, pim, pim->mroute_socket,
+ &pim->thread);
}
static void mroute_read_off(struct pim_instance *pim)
{
- THREAD_OFF(pim->thread);
+ EVENT_OFF(pim->thread);
}
int pim_mroute_socket_enable(struct pim_instance *pim)
diff --git a/pimd/pim_msdp.c b/pimd/pim_msdp.c
index dfa5ffeeec..b1b6958fe1 100644
--- a/pimd/pim_msdp.c
+++ b/pimd/pim_msdp.c
@@ -12,7 +12,7 @@
#include <lib/prefix.h>
#include <lib/sockunion.h>
#include <lib/stream.h>
-#include <lib/thread.h>
+#include <frrevent.h>
#include <lib/vty.h>
#include <lib/plist.h>
#include <lib/lib_errors.h>
@@ -54,9 +54,9 @@ static void pim_msdp_sa_timer_expiry_log(struct pim_msdp_sa *sa,
}
/* RFC-3618:Sec-5.1 - global active source advertisement timer */
-static void pim_msdp_sa_adv_timer_cb(struct thread *t)
+static void pim_msdp_sa_adv_timer_cb(struct event *t)
{
- struct pim_instance *pim = THREAD_ARG(t);
+ struct pim_instance *pim = EVENT_ARG(t);
if (PIM_DEBUG_MSDP_EVENTS) {
zlog_debug("MSDP SA advertisement timer expired");
@@ -68,20 +68,20 @@ static void pim_msdp_sa_adv_timer_cb(struct thread *t)
static void pim_msdp_sa_adv_timer_setup(struct pim_instance *pim, bool start)
{
- THREAD_OFF(pim->msdp.sa_adv_timer);
+ EVENT_OFF(pim->msdp.sa_adv_timer);
if (start) {
- thread_add_timer(pim->msdp.master, pim_msdp_sa_adv_timer_cb,
- pim, PIM_MSDP_SA_ADVERTISMENT_TIME,
- &pim->msdp.sa_adv_timer);
+ event_add_timer(pim->msdp.master, pim_msdp_sa_adv_timer_cb, pim,
+ PIM_MSDP_SA_ADVERTISMENT_TIME,
+ &pim->msdp.sa_adv_timer);
}
}
/* RFC-3618:Sec-5.3 - SA cache state timer */
-static void pim_msdp_sa_state_timer_cb(struct thread *t)
+static void pim_msdp_sa_state_timer_cb(struct event *t)
{
struct pim_msdp_sa *sa;
- sa = THREAD_ARG(t);
+ sa = EVENT_ARG(t);
if (PIM_DEBUG_MSDP_EVENTS) {
pim_msdp_sa_timer_expiry_log(sa, "state");
@@ -92,11 +92,11 @@ static void pim_msdp_sa_state_timer_cb(struct thread *t)
static void pim_msdp_sa_state_timer_setup(struct pim_msdp_sa *sa, bool start)
{
- THREAD_OFF(sa->sa_state_timer);
+ EVENT_OFF(sa->sa_state_timer);
if (start) {
- thread_add_timer(sa->pim->msdp.master,
- pim_msdp_sa_state_timer_cb, sa,
- PIM_MSDP_SA_HOLD_TIME, &sa->sa_state_timer);
+ event_add_timer(sa->pim->msdp.master,
+ pim_msdp_sa_state_timer_cb, sa,
+ PIM_MSDP_SA_HOLD_TIME, &sa->sa_state_timer);
}
}
@@ -861,11 +861,11 @@ static void pim_msdp_peer_timer_expiry_log(struct pim_msdp_peer *mp,
}
/* RFC-3618:Sec-5.4 - peer hold timer */
-static void pim_msdp_peer_hold_timer_cb(struct thread *t)
+static void pim_msdp_peer_hold_timer_cb(struct event *t)
{
struct pim_msdp_peer *mp;
- mp = THREAD_ARG(t);
+ mp = EVENT_ARG(t);
if (PIM_DEBUG_MSDP_EVENTS) {
pim_msdp_peer_timer_expiry_log(mp, "hold");
@@ -884,20 +884,20 @@ static void pim_msdp_peer_hold_timer_cb(struct thread *t)
static void pim_msdp_peer_hold_timer_setup(struct pim_msdp_peer *mp, bool start)
{
struct pim_instance *pim = mp->pim;
- THREAD_OFF(mp->hold_timer);
+ EVENT_OFF(mp->hold_timer);
if (start) {
- thread_add_timer(pim->msdp.master, pim_msdp_peer_hold_timer_cb,
- mp, pim->msdp.hold_time, &mp->hold_timer);
+ event_add_timer(pim->msdp.master, pim_msdp_peer_hold_timer_cb,
+ mp, pim->msdp.hold_time, &mp->hold_timer);
}
}
/* RFC-3618:Sec-5.5 - peer keepalive timer */
-static void pim_msdp_peer_ka_timer_cb(struct thread *t)
+static void pim_msdp_peer_ka_timer_cb(struct event *t)
{
struct pim_msdp_peer *mp;
- mp = THREAD_ARG(t);
+ mp = EVENT_ARG(t);
if (PIM_DEBUG_MSDP_EVENTS) {
pim_msdp_peer_timer_expiry_log(mp, "ka");
@@ -909,11 +909,10 @@ static void pim_msdp_peer_ka_timer_cb(struct thread *t)
static void pim_msdp_peer_ka_timer_setup(struct pim_msdp_peer *mp, bool start)
{
- THREAD_OFF(mp->ka_timer);
+ EVENT_OFF(mp->ka_timer);
if (start) {
- thread_add_timer(mp->pim->msdp.master,
- pim_msdp_peer_ka_timer_cb, mp,
- mp->pim->msdp.keep_alive, &mp->ka_timer);
+ event_add_timer(mp->pim->msdp.master, pim_msdp_peer_ka_timer_cb,
+ mp, mp->pim->msdp.keep_alive, &mp->ka_timer);
}
}
@@ -954,11 +953,11 @@ static void pim_msdp_peer_active_connect(struct pim_msdp_peer *mp)
}
/* RFC-3618:Sec-5.6 - connection retry on active peer */
-static void pim_msdp_peer_cr_timer_cb(struct thread *t)
+static void pim_msdp_peer_cr_timer_cb(struct event *t)
{
struct pim_msdp_peer *mp;
- mp = THREAD_ARG(t);
+ mp = EVENT_ARG(t);
if (PIM_DEBUG_MSDP_EVENTS) {
pim_msdp_peer_timer_expiry_log(mp, "connect-retry");
@@ -973,11 +972,11 @@ static void pim_msdp_peer_cr_timer_cb(struct thread *t)
static void pim_msdp_peer_cr_timer_setup(struct pim_msdp_peer *mp, bool start)
{
- THREAD_OFF(mp->cr_timer);
+ EVENT_OFF(mp->cr_timer);
if (start) {
- thread_add_timer(mp->pim->msdp.master,
- pim_msdp_peer_cr_timer_cb, mp,
- mp->pim->msdp.connection_retry, &mp->cr_timer);
+ event_add_timer(mp->pim->msdp.master, pim_msdp_peer_cr_timer_cb,
+ mp, mp->pim->msdp.connection_retry,
+ &mp->cr_timer);
}
}
@@ -1334,7 +1333,7 @@ static void pim_msdp_enable(struct pim_instance *pim)
}
/* MSDP init */
-void pim_msdp_init(struct pim_instance *pim, struct thread_master *master)
+void pim_msdp_init(struct pim_instance *pim, struct event_loop *master)
{
pim->msdp.master = master;
char hash_name[64];
@@ -1367,21 +1366,13 @@ void pim_msdp_exit(struct pim_instance *pim)
while ((mg = SLIST_FIRST(&pim->msdp.mglist)) != NULL)
pim_msdp_mg_free(pim, &mg);
- if (pim->msdp.peer_hash) {
- hash_clean(pim->msdp.peer_hash, NULL);
- hash_free(pim->msdp.peer_hash);
- pim->msdp.peer_hash = NULL;
- }
+ hash_clean_and_free(&pim->msdp.peer_hash, NULL);
if (pim->msdp.peer_list) {
list_delete(&pim->msdp.peer_list);
}
- if (pim->msdp.sa_hash) {
- hash_clean(pim->msdp.sa_hash, NULL);
- hash_free(pim->msdp.sa_hash);
- pim->msdp.sa_hash = NULL;
- }
+ hash_clean_and_free(&pim->msdp.sa_hash, NULL);
if (pim->msdp.sa_list) {
list_delete(&pim->msdp.sa_list);
diff --git a/pimd/pim_msdp.h b/pimd/pim_msdp.h
index f0a03f076b..ddc015f9b6 100644
--- a/pimd/pim_msdp.h
+++ b/pimd/pim_msdp.h
@@ -74,7 +74,7 @@ struct pim_msdp_sa {
/* rfc-3618 is missing default value for SA-hold-down-Period. pulled
* this number from industry-standards */
#define PIM_MSDP_SA_HOLD_TIME ((3*60)+30)
- struct thread *sa_state_timer; // 5.6
+ struct event *sa_state_timer; // 5.6
int64_t uptime;
struct pim_upstream *up;
@@ -109,18 +109,18 @@ struct pim_msdp_peer {
/* protocol timers */
#define PIM_MSDP_PEER_HOLD_TIME 75
- struct thread *hold_timer; // 5.4
+ struct event *hold_timer; // 5.4
#define PIM_MSDP_PEER_KA_TIME 60
- struct thread *ka_timer; // 5.5
+ struct event *ka_timer; // 5.5
#define PIM_MSDP_PEER_CONNECT_RETRY_TIME 30
- struct thread *cr_timer; // 5.6
+ struct event *cr_timer; // 5.6
/* packet thread and buffers */
uint32_t packet_size;
struct stream *ibuf;
struct stream_fifo *obuf;
- struct thread *t_read;
- struct thread *t_write;
+ struct event *t_read;
+ struct event *t_write;
/* stats */
uint32_t conn_attempts;
@@ -167,12 +167,12 @@ enum pim_msdp_flags {
struct pim_msdp_listener {
int fd;
union sockunion su;
- struct thread *thread;
+ struct event *thread;
};
struct pim_msdp {
enum pim_msdp_flags flags;
- struct thread_master *master;
+ struct event_loop *master;
struct pim_msdp_listener listener;
uint32_t rejected_accepts;
@@ -182,7 +182,7 @@ struct pim_msdp {
/* MSDP active-source info */
#define PIM_MSDP_SA_ADVERTISMENT_TIME 60
- struct thread *sa_adv_timer; // 5.6
+ struct event *sa_adv_timer; // 5.6
struct hash *sa_hash;
struct list *sa_list;
uint32_t local_cnt;
@@ -204,20 +204,20 @@ struct pim_msdp {
};
#define PIM_MSDP_PEER_READ_ON(mp) \
- thread_add_read(mp->pim->msdp.master, pim_msdp_read, mp, mp->fd, \
- &mp->t_read)
+ event_add_read(mp->pim->msdp.master, pim_msdp_read, mp, mp->fd, \
+ &mp->t_read)
#define PIM_MSDP_PEER_WRITE_ON(mp) \
- thread_add_write(mp->pim->msdp.master, pim_msdp_write, mp, mp->fd, \
- &mp->t_write)
+ event_add_write(mp->pim->msdp.master, pim_msdp_write, mp, mp->fd, \
+ &mp->t_write)
-#define PIM_MSDP_PEER_READ_OFF(mp) thread_cancel(&mp->t_read)
-#define PIM_MSDP_PEER_WRITE_OFF(mp) thread_cancel(&mp->t_write)
+#define PIM_MSDP_PEER_READ_OFF(mp) event_cancel(&mp->t_read)
+#define PIM_MSDP_PEER_WRITE_OFF(mp) event_cancel(&mp->t_write)
#if PIM_IPV != 6
// struct pim_msdp *msdp;
struct pim_instance;
-void pim_msdp_init(struct pim_instance *pim, struct thread_master *master);
+void pim_msdp_init(struct pim_instance *pim, struct event_loop *master);
void pim_msdp_exit(struct pim_instance *pim);
char *pim_msdp_state_dump(enum pim_msdp_peer_state state, char *buf,
int buf_size);
@@ -227,7 +227,7 @@ void pim_msdp_peer_established(struct pim_msdp_peer *mp);
void pim_msdp_peer_pkt_rxed(struct pim_msdp_peer *mp);
void pim_msdp_peer_stop_tcp_conn(struct pim_msdp_peer *mp, bool chg_state);
void pim_msdp_peer_reset_tcp_conn(struct pim_msdp_peer *mp, const char *rc_str);
-void pim_msdp_write(struct thread *thread);
+void pim_msdp_write(struct event *thread);
int pim_msdp_config_write(struct pim_instance *pim, struct vty *vty,
const char *spaces);
bool pim_msdp_peer_config_write(struct vty *vty, struct pim_instance *pim,
@@ -308,7 +308,7 @@ void pim_msdp_peer_change_source(struct pim_msdp_peer *mp,
#else /* PIM_IPV == 6 */
static inline void pim_msdp_init(struct pim_instance *pim,
- struct thread_master *master)
+ struct event_loop *master)
{
}
diff --git a/pimd/pim_msdp_packet.c b/pimd/pim_msdp_packet.c
index a6f318e61e..a414736ccc 100644
--- a/pimd/pim_msdp_packet.c
+++ b/pimd/pim_msdp_packet.c
@@ -8,7 +8,7 @@
#include <lib/log.h>
#include <lib/network.h>
#include <lib/stream.h>
-#include <lib/thread.h>
+#include "frrevent.h"
#include <lib/vty.h>
#include <lib/lib_errors.h>
@@ -190,7 +190,7 @@ static void pim_msdp_write_proceed_actions(struct pim_msdp_peer *mp)
}
}
-void pim_msdp_write(struct thread *thread)
+void pim_msdp_write(struct event *thread)
{
struct pim_msdp_peer *mp;
struct stream *s;
@@ -200,7 +200,7 @@ void pim_msdp_write(struct thread *thread)
int work_cnt = 0;
int work_max_cnt = 100;
- mp = THREAD_ARG(thread);
+ mp = EVENT_ARG(thread);
mp->t_write = NULL;
if (PIM_DEBUG_MSDP_INTERNAL) {
@@ -686,13 +686,13 @@ static int pim_msdp_read_packet(struct pim_msdp_peer *mp)
return 0;
}
-void pim_msdp_read(struct thread *thread)
+void pim_msdp_read(struct event *thread)
{
struct pim_msdp_peer *mp;
int rc;
uint32_t len;
- mp = THREAD_ARG(thread);
+ mp = EVENT_ARG(thread);
mp->t_read = NULL;
if (PIM_DEBUG_MSDP_INTERNAL) {
diff --git a/pimd/pim_msdp_packet.h b/pimd/pim_msdp_packet.h
index efb14cdf72..1584a24539 100644
--- a/pimd/pim_msdp_packet.h
+++ b/pimd/pim_msdp_packet.h
@@ -51,7 +51,7 @@
#define PIM_MSDP_PKT_TYPE_STRLEN 16
void pim_msdp_pkt_ka_tx(struct pim_msdp_peer *mp);
-void pim_msdp_read(struct thread *thread);
+void pim_msdp_read(struct event *thread);
void pim_msdp_pkt_sa_tx(struct pim_instance *pim);
void pim_msdp_pkt_sa_tx_one(struct pim_msdp_sa *sa);
void pim_msdp_pkt_sa_tx_to_one_peer(struct pim_msdp_peer *mp);
diff --git a/pimd/pim_msdp_socket.c b/pimd/pim_msdp_socket.c
index a6b5ee11b6..fe8d5e934a 100644
--- a/pimd/pim_msdp_socket.c
+++ b/pimd/pim_msdp_socket.c
@@ -9,7 +9,7 @@
#include <lib/log.h>
#include <lib/network.h>
#include <lib/sockunion.h>
-#include <lib/thread.h>
+#include "frrevent.h"
#include <lib/vty.h>
#include <lib/if.h>
#include <lib/vrf.h>
@@ -50,10 +50,10 @@ static void pim_msdp_update_sock_send_buffer_size(int fd)
}
/* passive peer socket accept */
-static void pim_msdp_sock_accept(struct thread *thread)
+static void pim_msdp_sock_accept(struct event *thread)
{
union sockunion su;
- struct pim_instance *pim = THREAD_ARG(thread);
+ struct pim_instance *pim = EVENT_ARG(thread);
int accept_sock;
int msdp_sock;
struct pim_msdp_peer *mp;
@@ -61,15 +61,15 @@ static void pim_msdp_sock_accept(struct thread *thread)
sockunion_init(&su);
/* re-register accept thread */
- accept_sock = THREAD_FD(thread);
+ accept_sock = EVENT_FD(thread);
if (accept_sock < 0) {
flog_err(EC_LIB_DEVELOPMENT, "accept_sock is negative value %d",
accept_sock);
return;
}
pim->msdp.listener.thread = NULL;
- thread_add_read(router->master, pim_msdp_sock_accept, pim, accept_sock,
- &pim->msdp.listener.thread);
+ event_add_read(router->master, pim_msdp_sock_accept, pim, accept_sock,
+ &pim->msdp.listener.thread);
/* accept client connection. */
msdp_sock = sockunion_accept(accept_sock, &su);
@@ -192,8 +192,8 @@ int pim_msdp_sock_listen(struct pim_instance *pim)
/* add accept thread */
listener->fd = sock;
memcpy(&listener->su, &sin, socklen);
- thread_add_read(pim->msdp.master, pim_msdp_sock_accept, pim, sock,
- &listener->thread);
+ event_add_read(pim->msdp.master, pim_msdp_sock_accept, pim, sock,
+ &listener->thread);
pim->msdp.flags |= PIM_MSDPF_LISTENER;
return 0;
diff --git a/pimd/pim_neighbor.c b/pimd/pim_neighbor.c
index 0b7ea0ad9d..3d0ecb1bf4 100644
--- a/pimd/pim_neighbor.c
+++ b/pimd/pim_neighbor.c
@@ -188,13 +188,13 @@ static void update_dr_priority(struct pim_neighbor *neigh,
}
}
-static void on_neighbor_timer(struct thread *t)
+static void on_neighbor_timer(struct event *t)
{
struct pim_neighbor *neigh;
struct interface *ifp;
char msg[100];
- neigh = THREAD_ARG(t);
+ neigh = EVENT_ARG(t);
ifp = neigh->interface;
@@ -220,7 +220,7 @@ void pim_neighbor_timer_reset(struct pim_neighbor *neigh, uint16_t holdtime)
{
neigh->holdtime = holdtime;
- THREAD_OFF(neigh->t_expire_timer);
+ EVENT_OFF(neigh->t_expire_timer);
/*
0xFFFF is request for no holdtime
@@ -234,13 +234,13 @@ void pim_neighbor_timer_reset(struct pim_neighbor *neigh, uint16_t holdtime)
__func__, neigh->holdtime, &neigh->source_addr,
neigh->interface->name);
- thread_add_timer(router->master, on_neighbor_timer, neigh,
- neigh->holdtime, &neigh->t_expire_timer);
+ event_add_timer(router->master, on_neighbor_timer, neigh,
+ neigh->holdtime, &neigh->t_expire_timer);
}
-static void on_neighbor_jp_timer(struct thread *t)
+static void on_neighbor_jp_timer(struct event *t)
{
- struct pim_neighbor *neigh = THREAD_ARG(t);
+ struct pim_neighbor *neigh = EVENT_ARG(t);
struct pim_rpf rpf;
if (PIM_DEBUG_PIM_TRACE)
@@ -253,15 +253,15 @@ static void on_neighbor_jp_timer(struct thread *t)
rpf.rpf_addr = neigh->source_addr;
pim_joinprune_send(&rpf, neigh->upstream_jp_agg);
- thread_add_timer(router->master, on_neighbor_jp_timer, neigh,
- router->t_periodic, &neigh->jp_timer);
+ event_add_timer(router->master, on_neighbor_jp_timer, neigh,
+ router->t_periodic, &neigh->jp_timer);
}
static void pim_neighbor_start_jp_timer(struct pim_neighbor *neigh)
{
- THREAD_OFF(neigh->jp_timer);
- thread_add_timer(router->master, on_neighbor_jp_timer, neigh,
- router->t_periodic, &neigh->jp_timer);
+ EVENT_OFF(neigh->jp_timer);
+ event_add_timer(router->master, on_neighbor_jp_timer, neigh,
+ router->t_periodic, &neigh->jp_timer);
}
static struct pim_neighbor *
@@ -375,7 +375,7 @@ void pim_neighbor_free(struct pim_neighbor *neigh)
delete_prefix_list(neigh);
list_delete(&neigh->upstream_jp_agg);
- THREAD_OFF(neigh->jp_timer);
+ EVENT_OFF(neigh->jp_timer);
bfd_sess_free(&neigh->bfd_session);
@@ -579,7 +579,7 @@ void pim_neighbor_delete(struct interface *ifp, struct pim_neighbor *neigh,
zlog_notice("PIM NEIGHBOR DOWN: neighbor %pPA on interface %s: %s",
&neigh->source_addr, ifp->name, delete_message);
- THREAD_OFF(neigh->t_expire_timer);
+ EVENT_OFF(neigh->t_expire_timer);
pim_if_assert_on_neighbor_down(ifp, neigh->source_addr);
diff --git a/pimd/pim_neighbor.h b/pimd/pim_neighbor.h
index f7375745a1..69e9976de5 100644
--- a/pimd/pim_neighbor.h
+++ b/pimd/pim_neighbor.h
@@ -27,10 +27,10 @@ struct pim_neighbor {
uint32_t dr_priority;
uint32_t generation_id;
struct list *prefix_list; /* list of struct prefix */
- struct thread *t_expire_timer;
+ struct event *t_expire_timer;
struct interface *interface;
- struct thread *jp_timer;
+ struct event *jp_timer;
struct list *upstream_jp_agg;
struct bfd_session_params *bfd_session;
};
diff --git a/pimd/pim_pim.c b/pimd/pim_pim.c
index 1248db3de4..4a272a4802 100644
--- a/pimd/pim_pim.c
+++ b/pimd/pim_pim.c
@@ -7,7 +7,7 @@
#include <zebra.h>
#include "log.h"
-#include "thread.h"
+#include "frrevent.h"
#include "memory.h"
#include "if.h"
#include "network.h"
@@ -31,7 +31,7 @@
#include "pim_bsm.h"
#include <lib/lib_errors.h>
-static void on_pim_hello_send(struct thread *t);
+static void on_pim_hello_send(struct event *t);
static const char *pim_pim_msgtype2str(enum pim_msg_type type)
{
@@ -70,7 +70,7 @@ static void sock_close(struct interface *ifp)
pim_ifp->pim_sock_fd, ifp->name);
}
}
- THREAD_OFF(pim_ifp->t_pim_sock_read);
+ EVENT_OFF(pim_ifp->t_pim_sock_read);
if (PIM_DEBUG_PIM_TRACE) {
if (pim_ifp->t_pim_hello_timer) {
@@ -79,7 +79,7 @@ static void sock_close(struct interface *ifp)
ifp->name);
}
}
- THREAD_OFF(pim_ifp->t_pim_hello_timer);
+ EVENT_OFF(pim_ifp->t_pim_hello_timer);
if (PIM_DEBUG_PIM_TRACE) {
zlog_debug("Deleting PIM socket fd=%d on interface %s",
@@ -334,7 +334,7 @@ int pim_pim_packet(struct interface *ifp, uint8_t *buf, size_t len,
static void pim_sock_read_on(struct interface *ifp);
-static void pim_sock_read(struct thread *t)
+static void pim_sock_read(struct event *t)
{
struct interface *ifp, *orig_ifp;
struct pim_interface *pim_ifp;
@@ -350,8 +350,8 @@ static void pim_sock_read(struct thread *t)
static long long count = 0;
int cont = 1;
- orig_ifp = ifp = THREAD_ARG(t);
- fd = THREAD_FD(t);
+ orig_ifp = ifp = EVENT_ARG(t);
+ fd = EVENT_FD(t);
pim_ifp = ifp->info;
@@ -431,8 +431,8 @@ static void pim_sock_read_on(struct interface *ifp)
zlog_debug("Scheduling READ event on PIM socket fd=%d",
pim_ifp->pim_sock_fd);
}
- thread_add_read(router->master, pim_sock_read, ifp,
- pim_ifp->pim_sock_fd, &pim_ifp->t_pim_sock_read);
+ event_add_read(router->master, pim_sock_read, ifp, pim_ifp->pim_sock_fd,
+ &pim_ifp->t_pim_sock_read);
}
static int pim_sock_open(struct interface *ifp)
@@ -821,21 +821,20 @@ static void hello_resched(struct interface *ifp)
zlog_debug("Rescheduling %d sec hello on interface %s",
pim_ifp->pim_hello_period, ifp->name);
}
- THREAD_OFF(pim_ifp->t_pim_hello_timer);
- thread_add_timer(router->master, on_pim_hello_send, ifp,
- pim_ifp->pim_hello_period,
- &pim_ifp->t_pim_hello_timer);
+ EVENT_OFF(pim_ifp->t_pim_hello_timer);
+ event_add_timer(router->master, on_pim_hello_send, ifp,
+ pim_ifp->pim_hello_period, &pim_ifp->t_pim_hello_timer);
}
/*
Periodic hello timer
*/
-static void on_pim_hello_send(struct thread *t)
+static void on_pim_hello_send(struct event *t)
{
struct pim_interface *pim_ifp;
struct interface *ifp;
- ifp = THREAD_ARG(t);
+ ifp = EVENT_ARG(t);
pim_ifp = ifp->info;
/*
@@ -924,7 +923,7 @@ void pim_hello_restart_triggered(struct interface *ifp)
return;
}
- THREAD_OFF(pim_ifp->t_pim_hello_timer);
+ EVENT_OFF(pim_ifp->t_pim_hello_timer);
}
random_msec = triggered_hello_delay_msec;
@@ -935,8 +934,8 @@ void pim_hello_restart_triggered(struct interface *ifp)
random_msec, ifp->name);
}
- thread_add_timer_msec(router->master, on_pim_hello_send, ifp,
- random_msec, &pim_ifp->t_pim_hello_timer);
+ event_add_timer_msec(router->master, on_pim_hello_send, ifp,
+ random_msec, &pim_ifp->t_pim_hello_timer);
}
int pim_sock_add(struct interface *ifp)
diff --git a/pimd/pim_register.c b/pimd/pim_register.c
index 5144fe67b8..b5d9df6f2a 100644
--- a/pimd/pim_register.c
+++ b/pimd/pim_register.c
@@ -9,7 +9,7 @@
#include "log.h"
#include "if.h"
-#include "thread.h"
+#include "frrevent.h"
#include "prefix.h"
#include "vty.h"
#include "plist.h"
@@ -32,7 +32,7 @@
#include "pim_vxlan.h"
#include "pim_addr.h"
-struct thread *send_test_packet_timer = NULL;
+struct event *send_test_packet_timer = NULL;
void pim_register_join(struct pim_upstream *up)
{
@@ -743,7 +743,7 @@ void pim_reg_del_on_couldreg_fail(struct interface *ifp)
&& (up->reg_state != PIM_REG_NOINFO)) {
pim_channel_del_oif(up->channel_oil, pim->regiface,
PIM_OIF_FLAG_PROTO_PIM, __func__);
- THREAD_OFF(up->t_rs_timer);
+ EVENT_OFF(up->t_rs_timer);
up->reg_state = PIM_REG_NOINFO;
}
}
diff --git a/pimd/pim_rp.c b/pimd/pim_rp.c
index e2ee6656d1..c7516242f5 100644
--- a/pimd/pim_rp.c
+++ b/pimd/pim_rp.c
@@ -47,9 +47,7 @@ void pim_rp_list_hash_clean(void *data)
list_delete(&pnc->rp_list);
- hash_clean(pnc->upstream_hash, NULL);
- hash_free(pnc->upstream_hash);
- pnc->upstream_hash = NULL;
+ hash_clean_and_free(&pnc->upstream_hash, NULL);
if (pnc->nexthop)
nexthops_free(pnc->nexthop);
diff --git a/pimd/pim_ssmpingd.c b/pimd/pim_ssmpingd.c
index 2fc30b4915..dadf29f535 100644
--- a/pimd/pim_ssmpingd.c
+++ b/pimd/pim_ssmpingd.c
@@ -196,7 +196,7 @@ static void ssmpingd_delete(struct ssmpingd_sock *ss)
{
assert(ss);
- THREAD_OFF(ss->t_sock_read);
+ EVENT_OFF(ss->t_sock_read);
if (close(ss->sock_fd)) {
zlog_warn(
@@ -286,11 +286,11 @@ static int ssmpingd_read_msg(struct ssmpingd_sock *ss)
return 0;
}
-static void ssmpingd_sock_read(struct thread *t)
+static void ssmpingd_sock_read(struct event *t)
{
struct ssmpingd_sock *ss;
- ss = THREAD_ARG(t);
+ ss = EVENT_ARG(t);
ssmpingd_read_msg(ss);
@@ -300,8 +300,8 @@ static void ssmpingd_sock_read(struct thread *t)
static void ssmpingd_read_on(struct ssmpingd_sock *ss)
{
- thread_add_read(router->master, ssmpingd_sock_read, ss, ss->sock_fd,
- &ss->t_sock_read);
+ event_add_read(router->master, ssmpingd_sock_read, ss, ss->sock_fd,
+ &ss->t_sock_read);
}
static struct ssmpingd_sock *ssmpingd_new(struct pim_instance *pim,
diff --git a/pimd/pim_ssmpingd.h b/pimd/pim_ssmpingd.h
index fe15839793..71286e4964 100644
--- a/pimd/pim_ssmpingd.h
+++ b/pimd/pim_ssmpingd.h
@@ -17,7 +17,7 @@ struct ssmpingd_sock {
struct pim_instance *pim;
int sock_fd; /* socket */
- struct thread *t_sock_read; /* thread for reading socket */
+ struct event *t_sock_read; /* thread for reading socket */
pim_addr source_addr; /* source address */
int64_t creation; /* timestamp of socket creation */
int64_t requests; /* counter */
diff --git a/pimd/pim_time.c b/pimd/pim_time.c
index c9555f5310..205945e5ae 100644
--- a/pimd/pim_time.c
+++ b/pimd/pim_time.c
@@ -11,7 +11,7 @@
#include <time.h>
#include "log.h"
-#include "thread.h"
+#include "frrevent.h"
#include "lib_errors.h"
#include "pim_time.h"
@@ -121,21 +121,21 @@ static int pim_time_hhmmss(char *buf, int buf_size, long sec)
return wr != 8;
}
-void pim_time_timer_to_mmss(char *buf, int buf_size, struct thread *t_timer)
+void pim_time_timer_to_mmss(char *buf, int buf_size, struct event *t_timer)
{
if (t_timer) {
pim_time_mmss(buf, buf_size,
- thread_timer_remain_second(t_timer));
+ event_timer_remain_second(t_timer));
} else {
snprintf(buf, buf_size, "--:--");
}
}
-void pim_time_timer_to_hhmmss(char *buf, int buf_size, struct thread *t_timer)
+void pim_time_timer_to_hhmmss(char *buf, int buf_size, struct event *t_timer)
{
if (t_timer) {
pim_time_hhmmss(buf, buf_size,
- thread_timer_remain_second(t_timer));
+ event_timer_remain_second(t_timer));
} else {
snprintf(buf, buf_size, "--:--:--");
}
@@ -156,9 +156,9 @@ void pim_time_uptime_begin(char *buf, int buf_size, int64_t now, int64_t begin)
snprintf(buf, buf_size, "--:--:--");
}
-long pim_time_timer_remain_msec(struct thread *t_timer)
+long pim_time_timer_remain_msec(struct event *t_timer)
{
/* no timer thread running means timer has expired: return 0 */
- return t_timer ? thread_timer_remain_msec(t_timer) : 0;
+ return t_timer ? event_timer_remain_msec(t_timer) : 0;
}
diff --git a/pimd/pim_time.h b/pimd/pim_time.h
index fd1e79e2bb..6c0e07396a 100644
--- a/pimd/pim_time.h
+++ b/pimd/pim_time.h
@@ -10,16 +10,16 @@
#include <stdint.h>
#include <zebra.h>
-#include "thread.h"
+#include "frrevent.h"
int64_t pim_time_monotonic_sec(void);
int64_t pim_time_monotonic_dsec(void);
int64_t pim_time_monotonic_usec(void);
int pim_time_mmss(char *buf, int buf_size, long sec);
-void pim_time_timer_to_mmss(char *buf, int buf_size, struct thread *t);
-void pim_time_timer_to_hhmmss(char *buf, int buf_size, struct thread *t);
+void pim_time_timer_to_mmss(char *buf, int buf_size, struct event *t);
+void pim_time_timer_to_hhmmss(char *buf, int buf_size, struct event *t);
void pim_time_uptime(char *buf, int buf_size, int64_t uptime_sec);
void pim_time_uptime_begin(char *buf, int buf_size, int64_t now, int64_t begin);
-long pim_time_timer_remain_msec(struct thread *t_timer);
+long pim_time_timer_remain_msec(struct event *t_timer);
#endif /* PIM_TIME_H */
diff --git a/pimd/pim_upstream.c b/pimd/pim_upstream.c
index b0f1158596..8fa7b7cf96 100644
--- a/pimd/pim_upstream.c
+++ b/pimd/pim_upstream.c
@@ -9,7 +9,7 @@
#include "log.h"
#include "zclient.h"
#include "memory.h"
-#include "thread.h"
+#include "frrevent.h"
#include "linklist.h"
#include "vty.h"
#include "plist.h"
@@ -166,10 +166,10 @@ static void upstream_channel_oil_detach(struct pim_upstream *up)
static void pim_upstream_timers_stop(struct pim_upstream *up)
{
- THREAD_OFF(up->t_ka_timer);
- THREAD_OFF(up->t_rs_timer);
- THREAD_OFF(up->t_msdp_reg_timer);
- THREAD_OFF(up->t_join_timer);
+ EVENT_OFF(up->t_ka_timer);
+ EVENT_OFF(up->t_rs_timer);
+ EVENT_OFF(up->t_msdp_reg_timer);
+ EVENT_OFF(up->t_join_timer);
}
struct pim_upstream *pim_upstream_del(struct pim_instance *pim,
@@ -289,11 +289,11 @@ void pim_upstream_send_join(struct pim_upstream *up)
pim_jp_agg_single_upstream_send(&up->rpf, up, 1 /* join */);
}
-static void on_join_timer(struct thread *t)
+static void on_join_timer(struct event *t)
{
struct pim_upstream *up;
- up = THREAD_ARG(t);
+ up = EVENT_ARG(t);
if (!up->rpf.source_nexthop.interface) {
if (PIM_DEBUG_PIM_TRACE)
@@ -323,7 +323,7 @@ static void join_timer_stop(struct pim_upstream *up)
{
struct pim_neighbor *nbr = NULL;
- THREAD_OFF(up->t_join_timer);
+ EVENT_OFF(up->t_join_timer);
if (up->rpf.source_nexthop.interface)
nbr = pim_neighbor_find(up->rpf.source_nexthop.interface,
@@ -353,9 +353,9 @@ void join_timer_start(struct pim_upstream *up)
if (nbr)
pim_jp_agg_add_group(nbr->upstream_jp_agg, up, 1, nbr);
else {
- THREAD_OFF(up->t_join_timer);
- thread_add_timer(router->master, on_join_timer, up,
- router->t_periodic, &up->t_join_timer);
+ EVENT_OFF(up->t_join_timer);
+ event_add_timer(router->master, on_join_timer, up,
+ router->t_periodic, &up->t_join_timer);
}
pim_jp_agg_upstream_verification(up, true);
}
@@ -370,7 +370,7 @@ void join_timer_start(struct pim_upstream *up)
void pim_upstream_join_timer_restart(struct pim_upstream *up,
struct pim_rpf *old)
{
- // THREAD_OFF(up->t_join_timer);
+ // EVENT_OFF(up->t_join_timer);
join_timer_start(up);
}
@@ -382,9 +382,9 @@ static void pim_upstream_join_timer_restart_msec(struct pim_upstream *up,
__func__, interval_msec, up->sg_str);
}
- THREAD_OFF(up->t_join_timer);
- thread_add_timer_msec(router->master, on_join_timer, up, interval_msec,
- &up->t_join_timer);
+ EVENT_OFF(up->t_join_timer);
+ event_add_timer_msec(router->master, on_join_timer, up, interval_msec,
+ &up->t_join_timer);
}
void pim_update_suppress_timers(uint32_t suppress_time)
@@ -1361,7 +1361,7 @@ static void pim_upstream_fhr_kat_expiry(struct pim_instance *pim,
up->sg_str);
/* stop reg-stop timer */
- THREAD_OFF(up->t_rs_timer);
+ EVENT_OFF(up->t_rs_timer);
/* remove regiface from the OIL if it is there*/
pim_channel_del_oif(up->channel_oil, pim->regiface,
PIM_OIF_FLAG_PROTO_PIM, __func__);
@@ -1461,11 +1461,11 @@ struct pim_upstream *pim_upstream_keep_alive_timer_proc(
return up;
}
-static void pim_upstream_keep_alive_timer(struct thread *t)
+static void pim_upstream_keep_alive_timer(struct event *t)
{
struct pim_upstream *up;
- up = THREAD_ARG(t);
+ up = EVENT_ARG(t);
/* pull the stats and re-check */
if (pim_upstream_sg_running_proc(up))
@@ -1482,9 +1482,9 @@ void pim_upstream_keep_alive_timer_start(struct pim_upstream *up, uint32_t time)
zlog_debug("kat start on %s with no stream reference",
up->sg_str);
}
- THREAD_OFF(up->t_ka_timer);
- thread_add_timer(router->master, pim_upstream_keep_alive_timer, up,
- time, &up->t_ka_timer);
+ EVENT_OFF(up->t_ka_timer);
+ event_add_timer(router->master, pim_upstream_keep_alive_timer, up, time,
+ &up->t_ka_timer);
/* any time keepalive is started against a SG we will have to
* re-evaluate our active source database */
@@ -1494,9 +1494,9 @@ void pim_upstream_keep_alive_timer_start(struct pim_upstream *up, uint32_t time)
}
/* MSDP on RP needs to know if a source is registerable to this RP */
-static void pim_upstream_msdp_reg_timer(struct thread *t)
+static void pim_upstream_msdp_reg_timer(struct event *t)
{
- struct pim_upstream *up = THREAD_ARG(t);
+ struct pim_upstream *up = EVENT_ARG(t);
struct pim_instance *pim = up->channel_oil->pim;
/* source is no longer active - pull the SA from MSDP's cache */
@@ -1505,9 +1505,9 @@ static void pim_upstream_msdp_reg_timer(struct thread *t)
void pim_upstream_msdp_reg_timer_start(struct pim_upstream *up)
{
- THREAD_OFF(up->t_msdp_reg_timer);
- thread_add_timer(router->master, pim_upstream_msdp_reg_timer, up,
- PIM_MSDP_REG_RXED_PERIOD, &up->t_msdp_reg_timer);
+ EVENT_OFF(up->t_msdp_reg_timer);
+ event_add_timer(router->master, pim_upstream_msdp_reg_timer, up,
+ PIM_MSDP_REG_RXED_PERIOD, &up->t_msdp_reg_timer);
pim_msdp_sa_local_update(up);
}
@@ -1680,12 +1680,12 @@ const char *pim_reg_state2str(enum pim_reg_state reg_state, char *state_str,
return state_str;
}
-static void pim_upstream_register_stop_timer(struct thread *t)
+static void pim_upstream_register_stop_timer(struct event *t)
{
struct pim_interface *pim_ifp;
struct pim_instance *pim;
struct pim_upstream *up;
- up = THREAD_ARG(t);
+ up = EVENT_ARG(t);
pim = up->channel_oil->pim;
if (PIM_DEBUG_PIM_TRACE) {
@@ -1749,7 +1749,7 @@ void pim_upstream_start_register_stop_timer(struct pim_upstream *up,
{
uint32_t time;
- THREAD_OFF(up->t_rs_timer);
+ EVENT_OFF(up->t_rs_timer);
if (!null_register) {
uint32_t lower = (0.5 * router->register_suppress_time);
@@ -1768,8 +1768,8 @@ void pim_upstream_start_register_stop_timer(struct pim_upstream *up,
"%s: (S,G)=%s Starting upstream register stop timer %d",
__func__, up->sg_str, time);
}
- thread_add_timer(router->master, pim_upstream_register_stop_timer, up,
- time, &up->t_rs_timer);
+ event_add_timer(router->master, pim_upstream_register_stop_timer, up,
+ time, &up->t_rs_timer);
}
int pim_upstream_inherited_olist_decide(struct pim_instance *pim,
diff --git a/pimd/pim_upstream.h b/pimd/pim_upstream.h
index 890ba7d169..4e0926e294 100644
--- a/pimd/pim_upstream.h
+++ b/pimd/pim_upstream.h
@@ -237,19 +237,19 @@ struct pim_upstream {
struct pim_up_mlag mlag;
- struct thread *t_join_timer;
+ struct event *t_join_timer;
/*
* RST(S,G)
*/
- struct thread *t_rs_timer;
+ struct event *t_rs_timer;
#define PIM_REGISTER_SUPPRESSION_PERIOD (60)
#define PIM_REGISTER_PROBE_PERIOD (5)
/*
* KAT(S,G)
*/
- struct thread *t_ka_timer;
+ struct event *t_ka_timer;
#define PIM_KEEPALIVE_PERIOD (210)
#define PIM_RP_KEEPALIVE_PERIOD \
(3 * router->register_suppress_time + router->register_probe_time)
@@ -257,7 +257,7 @@ struct pim_upstream {
/* on the RP we restart a timer to indicate if registers are being rxed
* for
* SG. This is needed by MSDP to determine its local SA cache */
- struct thread *t_msdp_reg_timer;
+ struct event *t_msdp_reg_timer;
#define PIM_MSDP_REG_RXED_PERIOD (3 * (1.5 * router->register_suppress_time))
int64_t state_transition; /* Record current state uptime */
diff --git a/pimd/pim_util.c b/pimd/pim_util.c
index 948b615f71..657e84ae50 100644
--- a/pimd/pim_util.c
+++ b/pimd/pim_util.c
@@ -159,7 +159,7 @@ int pim_get_all_mcast_group(struct prefix *prefix)
bool pim_addr_is_multicast(pim_addr addr)
{
#if PIM_IPV == 4
- if (IN_MULTICAST(addr.s_addr))
+ if (IN_MULTICAST(ntohl(addr.s_addr)))
return true;
#else
if (IN6_IS_ADDR_MULTICAST(&addr))
diff --git a/pimd/pim_vxlan.c b/pimd/pim_vxlan.c
index 4c317a2546..8df3c90f00 100644
--- a/pimd/pim_vxlan.c
+++ b/pimd/pim_vxlan.c
@@ -169,7 +169,7 @@ void pim_vxlan_update_sg_reg_state(struct pim_instance *pim,
pim_vxlan_del_work(vxlan_sg);
}
-static void pim_vxlan_work_timer_cb(struct thread *t)
+static void pim_vxlan_work_timer_cb(struct event *t)
{
pim_vxlan_do_reg_work();
pim_vxlan_work_timer_setup(true /* start */);
@@ -178,10 +178,10 @@ static void pim_vxlan_work_timer_cb(struct thread *t)
/* global 1second timer used for periodic processing */
static void pim_vxlan_work_timer_setup(bool start)
{
- THREAD_OFF(vxlan_info.work_timer);
+ EVENT_OFF(vxlan_info.work_timer);
if (start)
- thread_add_timer(router->master, pim_vxlan_work_timer_cb, NULL,
- PIM_VXLAN_WORK_TIME, &vxlan_info.work_timer);
+ event_add_timer(router->master, pim_vxlan_work_timer_cb, NULL,
+ PIM_VXLAN_WORK_TIME, &vxlan_info.work_timer);
}
/**************************** vxlan origination mroutes ***********************
@@ -225,7 +225,7 @@ static void pim_vxlan_orig_mr_up_del(struct pim_vxlan_sg *vxlan_sg)
* if there are no other references.
*/
if (PIM_UPSTREAM_FLAG_TEST_SRC_STREAM(up->flags)) {
- THREAD_OFF(up->t_ka_timer);
+ EVENT_OFF(up->t_ka_timer);
up = pim_upstream_keep_alive_timer_proc(up);
} else {
/* this is really unexpected as we force vxlan
@@ -1172,12 +1172,8 @@ void pim_vxlan_init(struct pim_instance *pim)
void pim_vxlan_exit(struct pim_instance *pim)
{
- if (pim->vxlan.sg_hash) {
- hash_clean(pim->vxlan.sg_hash,
- (void (*)(void *))pim_vxlan_sg_del_item);
- hash_free(pim->vxlan.sg_hash);
- pim->vxlan.sg_hash = NULL;
- }
+ hash_clean_and_free(&pim->vxlan.sg_hash,
+ (void (*)(void *))pim_vxlan_sg_del_item);
}
void pim_vxlan_terminate(void)
diff --git a/pimd/pim_vxlan.h b/pimd/pim_vxlan.h
index 6e1e066f07..9a135ca6b8 100644
--- a/pimd/pim_vxlan.h
+++ b/pimd/pim_vxlan.h
@@ -75,7 +75,7 @@ enum pim_vxlan_flags {
struct pim_vxlan {
enum pim_vxlan_flags flags;
- struct thread *work_timer;
+ struct event *work_timer;
struct list *work_list;
struct listnode *next_work;
int max_work_cnt;
diff --git a/pimd/pim_zebra.c b/pimd/pim_zebra.c
index 29aac7f1c7..97b68c0a32 100644
--- a/pimd/pim_zebra.c
+++ b/pimd/pim_zebra.c
@@ -55,6 +55,8 @@ static int pim_zebra_interface_vrf_update(ZAPI_CALLBACK_ARGS)
{
struct interface *ifp;
vrf_id_t new_vrf_id;
+ struct pim_instance *pim;
+ struct pim_interface *pim_ifp;
ifp = zebra_interface_vrf_update_read(zclient->ibuf, vrf_id,
&new_vrf_id);
@@ -65,8 +67,18 @@ static int pim_zebra_interface_vrf_update(ZAPI_CALLBACK_ARGS)
zlog_debug("%s: %s updating from %u to %u", __func__, ifp->name,
vrf_id, new_vrf_id);
+ pim = pim_get_pim_instance(new_vrf_id);
+
if_update_to_new_vrf(ifp, new_vrf_id);
+ pim_ifp = ifp->info;
+ if (!pim_ifp)
+ return 0;
+
+ pim_ifp->pim->mcast_if_count--;
+ pim_ifp->pim = pim;
+ pim_ifp->pim->mcast_if_count++;
+
return 0;
}
@@ -385,9 +397,9 @@ void pim_scan_oil(struct pim_instance *pim)
pim_upstream_mroute_iif_update(c_oil, __func__);
}
-static void on_rpf_cache_refresh(struct thread *t)
+static void on_rpf_cache_refresh(struct event *t)
{
- struct pim_instance *pim = THREAD_ARG(t);
+ struct pim_instance *pim = EVENT_ARG(t);
/* update kernel multicast forwarding cache (MFC) */
pim_scan_oil(pim);
@@ -417,9 +429,9 @@ void sched_rpf_cache_refresh(struct pim_instance *pim)
router->rpf_cache_refresh_delay_msec);
}
- thread_add_timer_msec(router->master, on_rpf_cache_refresh, pim,
- router->rpf_cache_refresh_delay_msec,
- &pim->rpf_cache_refresher);
+ event_add_timer_msec(router->master, on_rpf_cache_refresh, pim,
+ router->rpf_cache_refresh_delay_msec,
+ &pim->rpf_cache_refresher);
}
static void pim_zebra_connected(struct zclient *zclient)
diff --git a/pimd/pim_zlookup.c b/pimd/pim_zlookup.c
index 08807d0dcc..05a72269d6 100644
--- a/pimd/pim_zlookup.c
+++ b/pimd/pim_zlookup.c
@@ -11,7 +11,7 @@
#include "zclient.h"
#include "stream.h"
#include "network.h"
-#include "thread.h"
+#include "frrevent.h"
#include "prefix.h"
#include "vty.h"
#include "lib_errors.h"
@@ -27,17 +27,17 @@
#include "pim_addr.h"
static struct zclient *zlookup = NULL;
-struct thread *zlookup_read;
+struct event *zlookup_read;
static void zclient_lookup_sched(struct zclient *zlookup, int delay);
-static void zclient_lookup_read_pipe(struct thread *thread);
+static void zclient_lookup_read_pipe(struct event *thread);
/* Connect to zebra for nexthop lookup. */
-static void zclient_lookup_connect(struct thread *t)
+static void zclient_lookup_connect(struct event *t)
{
struct zclient *zlookup;
- zlookup = THREAD_ARG(t);
+ zlookup = EVENT_ARG(t);
if (zlookup->sock >= 0) {
return;
@@ -65,15 +65,15 @@ static void zclient_lookup_connect(struct thread *t)
return;
}
- thread_add_timer(router->master, zclient_lookup_read_pipe, zlookup, 60,
- &zlookup_read);
+ event_add_timer(router->master, zclient_lookup_read_pipe, zlookup, 60,
+ &zlookup_read);
}
/* Schedule connection with delay. */
static void zclient_lookup_sched(struct zclient *zlookup, int delay)
{
- thread_add_timer(router->master, zclient_lookup_connect, zlookup, delay,
- &zlookup->t_connect);
+ event_add_timer(router->master, zclient_lookup_connect, zlookup, delay,
+ &zlookup->t_connect);
zlog_notice("%s: zclient lookup connection scheduled for %d seconds",
__func__, delay);
@@ -82,8 +82,8 @@ static void zclient_lookup_sched(struct zclient *zlookup, int delay)
/* Schedule connection for now. */
static void zclient_lookup_sched_now(struct zclient *zlookup)
{
- thread_add_event(router->master, zclient_lookup_connect, zlookup, 0,
- &zlookup->t_connect);
+ event_add_event(router->master, zclient_lookup_connect, zlookup, 0,
+ &zlookup->t_connect);
zlog_notice("%s: zclient lookup immediate connection scheduled",
__func__);
@@ -114,7 +114,7 @@ static void zclient_lookup_failed(struct zclient *zlookup)
void zclient_lookup_free(void)
{
- THREAD_OFF(zlookup_read);
+ EVENT_OFF(zlookup_read);
zclient_stop(zlookup);
zclient_free(zlookup);
zlookup = NULL;
@@ -364,9 +364,9 @@ static int zclient_lookup_nexthop_once(struct pim_instance *pim,
return zclient_read_nexthop(pim, zlookup, nexthop_tab, tab_size, addr);
}
-void zclient_lookup_read_pipe(struct thread *thread)
+void zclient_lookup_read_pipe(struct event *thread)
{
- struct zclient *zlookup = THREAD_ARG(thread);
+ struct zclient *zlookup = EVENT_ARG(thread);
struct pim_instance *pim = pim_get_pim_instance(VRF_DEFAULT);
struct pim_zlookup_nexthop nexthop_tab[10];
pim_addr l = PIMADDR_ANY;
@@ -378,8 +378,8 @@ void zclient_lookup_read_pipe(struct thread *thread)
}
zclient_lookup_nexthop_once(pim, nexthop_tab, 10, l);
- thread_add_timer(router->master, zclient_lookup_read_pipe, zlookup, 60,
- &zlookup_read);
+ event_add_timer(router->master, zclient_lookup_read_pipe, zlookup, 60,
+ &zlookup_read);
}
int zclient_lookup_nexthop(struct pim_instance *pim,
diff --git a/pimd/pim_zpthread.c b/pimd/pim_zpthread.c
index bc515f27ed..d6b2621ff4 100644
--- a/pimd/pim_zpthread.c
+++ b/pimd/pim_zpthread.c
@@ -133,7 +133,7 @@ static void pim_mlag_zebra_check_for_buffer_flush(uint32_t curr_msg_type,
* Thsi thread reads the clients data from the Gloabl queue and encodes with
* protobuf and pass on to the MLAG socket.
*/
-static void pim_mlag_zthread_handler(struct thread *event)
+static void pim_mlag_zthread_handler(struct event *event)
{
struct stream *read_s;
uint32_t wr_count = 0;
@@ -209,8 +209,8 @@ int pim_mlag_signal_zpthread(void)
if (PIM_DEBUG_MLAG)
zlog_debug(":%s: Scheduling PIM MLAG write Thread",
__func__);
- thread_add_event(router->master, pim_mlag_zthread_handler, NULL,
- 0, &router->zpthread_mlag_write);
+ event_add_event(router->master, pim_mlag_zthread_handler, NULL,
+ 0, &router->zpthread_mlag_write);
}
return (0);
}
diff --git a/pkgsrc/mgmtd.sh.in b/pkgsrc/mgmtd.sh.in
new file mode 100644
index 0000000000..fb57c0a2fb
--- /dev/null
+++ b/pkgsrc/mgmtd.sh.in
@@ -0,0 +1,44 @@
+#!/bin/sh
+#
+# mgmtd is part of the quagga routing beast
+#
+# PROVIDE: mgmtd
+# REQUIRE: none
+##
+
+PATH=/sbin:/bin:/usr/sbin:/usr/bin:@prefix@/sbin:@prefix@/bin
+export PATH
+
+if [ -f /etc/rc.subr ]
+then
+ . /etc/rc.subr
+fi
+
+name="mgmtd"
+rcvar=$name
+required_files="@sysconfdir@/${name}.conf"
+command="@prefix@/sbin/${name}"
+command_args="-d"
+
+start_precmd="zebra_precmd"
+socket_dir=@localstatedir@
+pidfile="${socket_dir}/${name}.pid"
+
+zebra_precmd()
+{
+ rc_flags="$(
+ set -- $rc_flags
+ while [ $# -ne 0 ]; do
+ if [ X"$1" = X-P -o X"$1" = X-A ]; then
+ break
+ fi
+ shift
+ done
+ if [ $# -eq 0 ]; then
+ echo "-P 0"
+ fi
+ ) $rc_flags"
+}
+
+load_rc_config $name
+run_rc_command "$1"
diff --git a/python/xref2vtysh.py b/python/xref2vtysh.py
index a4f8560bb0..c325979d24 100644
--- a/python/xref2vtysh.py
+++ b/python/xref2vtysh.py
@@ -44,7 +44,7 @@ daemon_flags = {
"lib/routemap.c": "VTYSH_RMAP",
"lib/routemap_cli.c": "VTYSH_RMAP",
"lib/spf_backoff.c": "VTYSH_ISISD",
- "lib/thread.c": "VTYSH_ALL",
+ "lib/event.c": "VTYSH_ALL",
"lib/vrf.c": "VTYSH_VRF",
"lib/vty.c": "VTYSH_ALL",
}
@@ -325,7 +325,17 @@ class CommandEntry:
def load(cls, xref):
nodes = NodeDict()
+ mgmtname = "mgmtd/libmgmt_be_nb.la"
for cmd_name, origins in xref.get("cli", {}).items():
+ # If mgmtd has a yang version of a CLI command, make it the only daemon
+ # to handle it. For now, daemons can still be compiling their cmds into the
+ # binaries to allow for running standalone with CLI config files. When they
+ # do this they will also be present in the xref file, but we want to ignore
+ # those in vtysh.
+ if "yang" in origins.get(mgmtname, {}).get("attrs", []):
+ CommandEntry.process(nodes, cmd_name, mgmtname, origins[mgmtname])
+ continue
+
for origin, spec in origins.items():
CommandEntry.process(nodes, cmd_name, origin, spec)
return nodes
diff --git a/python/xrelfo.py b/python/xrelfo.py
index 4c956ca6ac..a40b19e5fb 100644
--- a/python/xrelfo.py
+++ b/python/xrelfo.py
@@ -40,7 +40,7 @@ tool available) could not be found. It should be included with the sources.
# constants, need to be kept in sync manually...
-XREFT_THREADSCHED = 0x100
+XREFT_EVENTSCHED = 0x100
XREFT_LOGMSG = 0x200
XREFT_DEFUN = 0x300
XREFT_INSTALL_ELEMENT = 0x301
@@ -110,7 +110,7 @@ class XrefThreadSched(ELFDissectStruct, XrelfoJson):
struct = "xref_threadsched"
-Xref.containers[XREFT_THREADSCHED] = XrefThreadSched
+Xref.containers[XREFT_EVENTSCHED] = XrefThreadSched
class XrefLogmsg(ELFDissectStruct, XrelfoJson):
diff --git a/qpb/subdir.am b/qpb/subdir.am
index e897822ecc..21aa84df5c 100644
--- a/qpb/subdir.am
+++ b/qpb/subdir.am
@@ -29,23 +29,3 @@ CLEANFILES += \
# end
EXTRA_DIST += qpb/qpb.proto
-SUFFIXES += .proto .pb-c.c .pb-c.h
-
-if HAVE_PROTOBUF
-
-# Rules
-.proto.pb.h:
- $(PROTOC) -I$(top_srcdir) --cpp_out=$(top_builddir) $^
-
-AM_V_PROTOC_C = $(am__v_PROTOC_C_$(V))
-am__v_PROTOC_C_ = $(am__v_PROTOC_C_$(AM_DEFAULT_VERBOSITY))
-am__v_PROTOC_C_0 = @echo " PROTOC_C" $@;
-am__v_PROTOC_C_1 =
-
-.proto.pb-c.c:
- $(AM_V_PROTOC_C)$(PROTOC_C) -I$(top_srcdir) --c_out=$(top_builddir) $^
- $(AM_V_GEN)$(SED) -e '1i#include "config.h"' -i $@
-.pb-c.c.pb-c.h:
- @/bin/true
-
-endif # HAVE_PROTOBUF
diff --git a/redhat/frr.spec.in b/redhat/frr.spec.in
index 14973ba890..4dec84b8fb 100644
--- a/redhat/frr.spec.in
+++ b/redhat/frr.spec.in
@@ -667,6 +667,7 @@ fi
%{_sbindir}/ospfd
%{_sbindir}/ripd
%{_sbindir}/bgpd
+%{_sbindir}/mgmtd
%exclude %{_sbindir}/ssd
%if %{with_watchfrr}
%{_sbindir}/watchfrr
@@ -716,6 +717,9 @@ fi
%{_libdir}/frr/modules/dplane_fpm_nl.so
%{_libdir}/frr/modules/zebra_irdp.so
%{_libdir}/frr/modules/bgpd_bmp.so
+%{_libdir}/libfrr_pb.so*
+%{_libdir}/libfrrfpm_pb.so*
+%{_libdir}/libmgmt_be_nb.so*
%{_bindir}/*
%config(noreplace) %{configdir}/[!v]*.conf*
%config(noreplace) %attr(750,%{frr_user},%{frr_user}) %{configdir}/daemons
@@ -775,6 +779,8 @@ sed -i 's/ -M rpki//' %{_sysconfdir}/frr/daemons
%{_libdir}/lib*.so
%dir %{_includedir}/%{name}
%{_includedir}/%{name}/*.h
+%dir %{_includedir}/%{name}/mgmtd
+%{_includedir}/%{name}/mgmtd/*.h
%dir %{_includedir}/%{name}/ospfd
%{_includedir}/%{name}/ospfd/*.h
%if %{with_bfdd}
diff --git a/ripd/rip_interface.c b/ripd/rip_interface.c
index 3e62321725..0b92f174b1 100644
--- a/ripd/rip_interface.c
+++ b/ripd/rip_interface.c
@@ -14,7 +14,7 @@
#include "table.h"
#include "log.h"
#include "stream.h"
-#include "thread.h"
+#include "frrevent.h"
#include "zclient.h"
#include "filter.h"
#include "sockopt.h"
@@ -413,7 +413,7 @@ static void rip_interface_clean(struct rip_interface *ri)
ri->enable_interface = 0;
ri->running = 0;
- THREAD_OFF(ri->t_wakeup);
+ EVENT_OFF(ri->t_wakeup);
}
void rip_interfaces_clean(struct rip *rip)
@@ -472,7 +472,7 @@ int rip_if_down(struct interface *ifp)
ri = ifp->info;
- THREAD_OFF(ri->t_wakeup);
+ EVENT_OFF(ri->t_wakeup);
rip = ri->rip;
if (rip) {
@@ -774,13 +774,13 @@ int rip_enable_if_delete(struct rip *rip, const char *ifname)
}
/* Join to multicast group and send request to the interface. */
-static void rip_interface_wakeup(struct thread *t)
+static void rip_interface_wakeup(struct event *t)
{
struct interface *ifp;
struct rip_interface *ri;
/* Get interface. */
- ifp = THREAD_ARG(t);
+ ifp = EVENT_ARG(t);
ri = ifp->info;
@@ -885,8 +885,8 @@ void rip_enable_apply(struct interface *ifp)
zlog_debug("turn on %s", ifp->name);
/* Add interface wake up thread. */
- thread_add_timer(master, rip_interface_wakeup, ifp, 1,
- &ri->t_wakeup);
+ event_add_timer(master, rip_interface_wakeup, ifp, 1,
+ &ri->t_wakeup);
rip_connect_set(ifp, 1);
} else if (ri->running) {
/* Might as well clean up the route table as well
diff --git a/ripd/rip_main.c b/ripd/rip_main.c
index e26424adeb..a6e4ad776b 100644
--- a/ripd/rip_main.c
+++ b/ripd/rip_main.c
@@ -7,7 +7,7 @@
#include <lib/version.h>
#include "getopt.h"
-#include "thread.h"
+#include "frrevent.h"
#include "command.h"
#include "memory.h"
#include "prefix.h"
@@ -47,7 +47,7 @@ struct zebra_privs_t ripd_privs = {
.cap_num_i = 0};
/* Master of threads. */
-struct thread_master *master;
+struct event_loop *master;
static struct frr_daemon_info ripd_di;
diff --git a/ripd/rip_nb.c b/ripd/rip_nb.c
index 9947c01af5..c332b2a5b7 100644
--- a/ripd/rip_nb.c
+++ b/ripd/rip_nb.c
@@ -338,6 +338,66 @@ const struct frr_yang_module_info frr_ripd_info = {
},
},
{
+ .xpath = "/frr-ripd:ripd/instance/state/routes/route/nexthops/nexthop",
+ .cbs = {
+ .get_next = ripd_instance_state_routes_route_nexthops_nexthop_get_next,
+ }
+ },
+ {
+ .xpath = "/frr-ripd:ripd/instance/state/routes/route/nexthops/nexthop/nh-type",
+ .cbs = {
+ .get_elem = ripd_instance_state_routes_route_nexthops_nexthop_nh_type_get_elem,
+ }
+ },
+ {
+ .xpath = "/frr-ripd:ripd/instance/state/routes/route/nexthops/nexthop/protocol",
+ .cbs = {
+ .get_elem = ripd_instance_state_routes_route_nexthops_nexthop_protocol_get_elem,
+ }
+ },
+ {
+ .xpath = "/frr-ripd:ripd/instance/state/routes/route/nexthops/nexthop/rip-type",
+ .cbs = {
+ .get_elem = ripd_instance_state_routes_route_nexthops_nexthop_rip_type_get_elem,
+ }
+ },
+ {
+ .xpath = "/frr-ripd:ripd/instance/state/routes/route/nexthops/nexthop/gateway",
+ .cbs = {
+ .get_elem = ripd_instance_state_routes_route_nexthops_nexthop_gateway_get_elem,
+ }
+ },
+ {
+ .xpath = "/frr-ripd:ripd/instance/state/routes/route/nexthops/nexthop/interface",
+ .cbs = {
+ .get_elem = ripd_instance_state_routes_route_nexthops_nexthop_interface_get_elem,
+ }
+ },
+ {
+ .xpath = "/frr-ripd:ripd/instance/state/routes/route/nexthops/nexthop/from",
+ .cbs = {
+ .get_elem = ripd_instance_state_routes_route_nexthops_nexthop_from_get_elem,
+ }
+ },
+ {
+ .xpath = "/frr-ripd:ripd/instance/state/routes/route/nexthops/nexthop/tag",
+ .cbs = {
+ .get_elem = ripd_instance_state_routes_route_nexthops_nexthop_tag_get_elem,
+ }
+ },
+ {
+ .xpath = "/frr-ripd:ripd/instance/state/routes/route/nexthops/nexthop/external-metric",
+ .cbs = {
+ .get_elem = ripd_instance_state_routes_route_nexthops_nexthop_external_metric_get_elem,
+ }
+ },
+ {
+ .xpath = "/frr-ripd:ripd/instance/state/routes/route/nexthops/nexthop/expire-time",
+ .cbs = {
+ .get_elem = ripd_instance_state_routes_route_nexthops_nexthop_expire_time_get_elem,
+ }
+ },
+ {
.xpath = "/frr-ripd:ripd/instance/state/routes/route/metric",
.cbs = {
.get_elem = ripd_instance_state_routes_route_metric_get_elem,
diff --git a/ripd/rip_nb.h b/ripd/rip_nb.h
index 99114c9928..a30e579e1c 100644
--- a/ripd/rip_nb.h
+++ b/ripd/rip_nb.h
@@ -89,6 +89,37 @@ struct yang_data *ripd_instance_state_routes_route_interface_get_elem(
struct nb_cb_get_elem_args *args);
struct yang_data *ripd_instance_state_routes_route_metric_get_elem(
struct nb_cb_get_elem_args *args);
+const void *ripd_instance_state_routes_route_nexthops_nexthop_get_next(
+ struct nb_cb_get_next_args *args);
+struct yang_data *
+ripd_instance_state_routes_route_nexthops_nexthop_nh_type_get_elem(
+ struct nb_cb_get_elem_args *args);
+struct yang_data *
+ripd_instance_state_routes_route_nexthops_nexthop_protocol_get_elem(
+ struct nb_cb_get_elem_args *args);
+struct yang_data *
+ripd_instance_state_routes_route_nexthops_nexthop_rip_type_get_elem(
+ struct nb_cb_get_elem_args *args);
+struct yang_data *
+ripd_instance_state_routes_route_nexthops_nexthop_gateway_get_elem(
+ struct nb_cb_get_elem_args *args);
+struct yang_data *
+ripd_instance_state_routes_route_nexthops_nexthop_interface_get_elem(
+ struct nb_cb_get_elem_args *args);
+struct yang_data *
+ripd_instance_state_routes_route_nexthops_nexthop_from_get_elem(
+ struct nb_cb_get_elem_args *args);
+struct yang_data *
+ripd_instance_state_routes_route_nexthops_nexthop_tag_get_elem(
+ struct nb_cb_get_elem_args *args);
+struct yang_data *
+ripd_instance_state_routes_route_nexthops_nexthop_external_metric_get_elem(
+ struct nb_cb_get_elem_args *args);
+struct yang_data *
+ripd_instance_state_routes_route_nexthops_nexthop_expire_time_get_elem(
+ struct nb_cb_get_elem_args *args);
+struct yang_data *ripd_instance_state_routes_route_metric_get_elem(
+ struct nb_cb_get_elem_args *args);
int clear_rip_route_rpc(struct nb_cb_rpc_args *args);
int lib_interface_rip_split_horizon_modify(struct nb_cb_modify_args *args);
int lib_interface_rip_v2_broadcast_modify(struct nb_cb_modify_args *args);
diff --git a/ripd/rip_nb_rpcs.c b/ripd/rip_nb_rpcs.c
index be55284819..bbe3d0f0f8 100644
--- a/ripd/rip_nb_rpcs.c
+++ b/ripd/rip_nb_rpcs.c
@@ -51,8 +51,8 @@ static void clear_rip_route(struct rip *rip)
}
if (rinfo) {
- THREAD_OFF(rinfo->t_timeout);
- THREAD_OFF(rinfo->t_garbage_collect);
+ EVENT_OFF(rinfo->t_timeout);
+ EVENT_OFF(rinfo->t_garbage_collect);
listnode_delete(list, rinfo);
rip_info_free(rinfo);
}
diff --git a/ripd/rip_nb_state.c b/ripd/rip_nb_state.c
index 0e2931b464..fa0d382a0e 100644
--- a/ripd/rip_nb_state.c
+++ b/ripd/rip_nb_state.c
@@ -207,10 +207,171 @@ struct yang_data *ripd_instance_state_routes_route_prefix_get_elem(
const struct route_node *rn = args->list_entry;
const struct rip_info *rinfo = listnode_head(rn->info);
+ assert(rinfo);
return yang_data_new_ipv4p(args->xpath, &rinfo->rp->p);
}
/*
+ * XPath: /frr-ripd:ripd/instance/state/routes/route/nexthops/nexthop
+ */
+const void *ripd_instance_state_routes_route_nexthops_nexthop_get_next(
+ struct nb_cb_get_next_args *args)
+{
+ const struct route_node *rn = args->parent_list_entry;
+ const struct listnode *node = args->list_entry;
+
+ assert(rn);
+ if (node)
+ return listnextnode(node);
+ assert(rn->info);
+ return listhead((struct list *)rn->info);
+}
+
+static inline const struct rip_info *get_rip_info(const void *info)
+{
+ return (const struct rip_info *)listgetdata(
+ (const struct listnode *)info);
+}
+
+/*
+ * XPath: /frr-ripd:ripd/instance/state/routes/route/nexthops/nexthop/nh-type
+ */
+struct yang_data *
+ripd_instance_state_routes_route_nexthops_nexthop_nh_type_get_elem(
+ struct nb_cb_get_elem_args *args)
+{
+ const struct rip_info *rinfo = get_rip_info(args->list_entry);
+
+ assert(rinfo);
+ return yang_data_new_enum(args->xpath, rinfo->nh.type);
+}
+
+/*
+ * XPath: /frr-ripd:ripd/instance/state/routes/route/nexthops/nexthop/protocol
+ */
+struct yang_data *
+ripd_instance_state_routes_route_nexthops_nexthop_protocol_get_elem(
+ struct nb_cb_get_elem_args *args)
+{
+ const struct rip_info *rinfo = get_rip_info(args->list_entry);
+
+ assert(rinfo);
+ return yang_data_new_enum(args->xpath, rinfo->type);
+}
+
+/*
+ * XPath: /frr-ripd:ripd/instance/state/routes/route/nexthops/nexthop/rip-type
+ */
+struct yang_data *
+ripd_instance_state_routes_route_nexthops_nexthop_rip_type_get_elem(
+ struct nb_cb_get_elem_args *args)
+{
+ const struct rip_info *rinfo = get_rip_info(args->list_entry);
+
+ assert(rinfo);
+ return yang_data_new_enum(args->xpath, rinfo->sub_type);
+}
+
+/*
+ * XPath: /frr-ripd:ripd/instance/state/routes/route/nexthops/nexthop/gateway
+ */
+struct yang_data *
+ripd_instance_state_routes_route_nexthops_nexthop_gateway_get_elem(
+ struct nb_cb_get_elem_args *args)
+{
+ const struct rip_info *rinfo = get_rip_info(args->list_entry);
+
+ if (rinfo->nh.type != NEXTHOP_TYPE_IPV4 &&
+ rinfo->nh.type != NEXTHOP_TYPE_IPV4_IFINDEX)
+ return NULL;
+
+ return yang_data_new_ipv4(args->xpath, &rinfo->nh.gate.ipv4);
+}
+
+/*
+ * XPath: /frr-ripd:ripd/instance/state/routes/route/nexthops/nexthop/interface
+ */
+struct yang_data *
+ripd_instance_state_routes_route_nexthops_nexthop_interface_get_elem(
+ struct nb_cb_get_elem_args *args)
+{
+ const struct rip_info *rinfo = get_rip_info(args->list_entry);
+ const struct rip *rip = rip_info_get_instance(rinfo);
+
+ if (rinfo->nh.type != NEXTHOP_TYPE_IFINDEX &&
+ rinfo->nh.type != NEXTHOP_TYPE_IPV4_IFINDEX)
+ return NULL;
+
+ return yang_data_new_string(
+ args->xpath,
+ ifindex2ifname(rinfo->nh.ifindex, rip->vrf->vrf_id));
+}
+
+/*
+ * XPath: /frr-ripd:ripd/instance/state/routes/route/nexthops/nexthop/from
+ */
+struct yang_data *
+ripd_instance_state_routes_route_nexthops_nexthop_from_get_elem(
+ struct nb_cb_get_elem_args *args)
+{
+ const struct rip_info *rinfo = get_rip_info(args->list_entry);
+
+ if (rinfo->type != ZEBRA_ROUTE_RIP || rinfo->sub_type != RIP_ROUTE_RTE)
+ return NULL;
+
+ return yang_data_new_ipv4(args->xpath, &rinfo->from);
+}
+
+/*
+ * XPath: /frr-ripd:ripd/instance/state/routes/route/nexthops/nexthop/tag
+ */
+struct yang_data *
+ripd_instance_state_routes_route_nexthops_nexthop_tag_get_elem(
+ struct nb_cb_get_elem_args *args)
+{
+ const struct rip_info *rinfo = get_rip_info(args->list_entry);
+
+ return yang_data_new_uint32(args->xpath, rinfo->tag);
+}
+
+/*
+ * XPath:
+ * /frr-ripd:ripd/instance/state/routes/route/nexthops/nexthop/external-metric
+ */
+struct yang_data *
+ripd_instance_state_routes_route_nexthops_nexthop_external_metric_get_elem(
+ struct nb_cb_get_elem_args *args)
+{
+ const struct rip_info *rinfo = get_rip_info(args->list_entry);
+
+ if ((rinfo->type == ZEBRA_ROUTE_RIP &&
+ rinfo->sub_type == RIP_ROUTE_RTE) ||
+ rinfo->metric == RIP_METRIC_INFINITY || rinfo->external_metric == 0)
+ return NULL;
+ return yang_data_new_uint32(args->xpath, rinfo->external_metric);
+}
+
+/*
+ * XPath:
+ * /frr-ripd:ripd/instance/state/routes/route/nexthops/nexthop/expire-time
+ */
+struct yang_data *
+ripd_instance_state_routes_route_nexthops_nexthop_expire_time_get_elem(
+ struct nb_cb_get_elem_args *args)
+{
+ const struct rip_info *rinfo = get_rip_info(args->list_entry);
+ struct event *event;
+
+ if ((event = rinfo->t_timeout) == NULL)
+ event = rinfo->t_garbage_collect;
+ if (!event)
+ return NULL;
+
+ return yang_data_new_uint32(args->xpath,
+ event_timer_remain_second(event));
+}
+
+/*
* XPath: /frr-ripd:ripd/instance/state/routes/route/next-hop
*/
struct yang_data *ripd_instance_state_routes_route_next_hop_get_elem(
diff --git a/ripd/rip_peer.c b/ripd/rip_peer.c
index a3cba598d2..9410ef380e 100644
--- a/ripd/rip_peer.c
+++ b/ripd/rip_peer.c
@@ -9,7 +9,7 @@
#include "prefix.h"
#include "command.h"
#include "linklist.h"
-#include "thread.h"
+#include "frrevent.h"
#include "memory.h"
#include "ripd/ripd.h"
@@ -23,7 +23,7 @@ static struct rip_peer *rip_peer_new(void)
static void rip_peer_free(struct rip_peer *peer)
{
- THREAD_OFF(peer->t_timeout);
+ EVENT_OFF(peer->t_timeout);
XFREE(MTYPE_RIP_PEER, peer);
}
@@ -52,11 +52,11 @@ struct rip_peer *rip_peer_lookup_next(struct rip *rip, struct in_addr *addr)
}
/* RIP peer is timeout. */
-static void rip_peer_timeout(struct thread *t)
+static void rip_peer_timeout(struct event *t)
{
struct rip_peer *peer;
- peer = THREAD_ARG(t);
+ peer = EVENT_ARG(t);
listnode_delete(peer->rip->peer_list, peer);
rip_peer_free(peer);
}
@@ -69,7 +69,7 @@ static struct rip_peer *rip_peer_get(struct rip *rip, struct in_addr *addr)
peer = rip_peer_lookup(rip, addr);
if (peer) {
- THREAD_OFF(peer->t_timeout);
+ EVENT_OFF(peer->t_timeout);
} else {
peer = rip_peer_new();
peer->rip = rip;
@@ -78,8 +78,8 @@ static struct rip_peer *rip_peer_get(struct rip *rip, struct in_addr *addr)
}
/* Update timeout thread. */
- thread_add_timer(master, rip_peer_timeout, peer, RIP_PEER_TIMER_DEFAULT,
- &peer->t_timeout);
+ event_add_timer(master, rip_peer_timeout, peer, RIP_PEER_TIMER_DEFAULT,
+ &peer->t_timeout);
/* Last update time set. */
time(&peer->uptime);
diff --git a/ripd/rip_snmp.c b/ripd/rip_snmp.c
index ab80dd1b8a..0e5d4d54c9 100644
--- a/ripd/rip_snmp.c
+++ b/ripd/rip_snmp.c
@@ -135,7 +135,7 @@ static struct variable rip_variables[] = {
{RIP2PEERRCVBADPACKETS, COUNTER, RONLY, rip2PeerTable, 3, {4, 1, 5}},
{RIP2PEERRCVBADROUTES, COUNTER, RONLY, rip2PeerTable, 3, {4, 1, 6}}};
-extern struct thread_master *master;
+extern struct event_loop *master;
static uint8_t *rip2Globals(struct variable *v, oid name[], size_t *length,
int exact, size_t *var_len,
@@ -553,7 +553,7 @@ static uint8_t *rip2PeerTable(struct variable *v, oid name[], size_t *length,
}
/* Register RIPv2-MIB. */
-static int rip_snmp_init(struct thread_master *master)
+static int rip_snmp_init(struct event_loop *master)
{
rip_ifaddr_table = route_table_init();
diff --git a/ripd/rip_zebra.c b/ripd/rip_zebra.c
index 4a58d1225e..35c4b1f1be 100644
--- a/ripd/rip_zebra.c
+++ b/ripd/rip_zebra.c
@@ -223,7 +223,7 @@ zclient_handler *const rip_handlers[] = {
[ZEBRA_REDISTRIBUTE_ROUTE_DEL] = rip_zebra_read_route,
};
-void rip_zclient_init(struct thread_master *master)
+void rip_zclient_init(struct event_loop *master)
{
/* Set default value to the zebra client structure. */
zclient = zclient_new(master, &zclient_options_default, rip_handlers,
diff --git a/ripd/ripd.c b/ripd/ripd.c
index bde7e858f1..7dbe2bbccf 100644
--- a/ripd/ripd.c
+++ b/ripd/ripd.c
@@ -11,7 +11,7 @@
#include "command.h"
#include "prefix.h"
#include "table.h"
-#include "thread.h"
+#include "frrevent.h"
#include "memory.h"
#include "log.h"
#include "stream.h"
@@ -50,7 +50,7 @@ DEFINE_MTYPE_STATIC(RIPD, RIP_DISTANCE, "RIP distance");
/* Prototypes. */
static void rip_output_process(struct connected *, struct sockaddr_in *, int,
uint8_t);
-static void rip_triggered_update(struct thread *);
+static void rip_triggered_update(struct event *);
static int rip_update_jitter(unsigned long);
static void rip_distance_table_node_cleanup(struct route_table *table,
struct route_node *node);
@@ -121,15 +121,15 @@ struct rip *rip_info_get_instance(const struct rip_info *rinfo)
}
/* RIP route garbage collect timer. */
-static void rip_garbage_collect(struct thread *t)
+static void rip_garbage_collect(struct event *t)
{
struct rip_info *rinfo;
struct route_node *rp;
- rinfo = THREAD_ARG(t);
+ rinfo = EVENT_ARG(t);
/* Off timeout timer. */
- THREAD_OFF(rinfo->t_timeout);
+ EVENT_OFF(rinfo->t_timeout);
/* Get route_node pointer. */
rp = rinfo->rp;
@@ -211,14 +211,14 @@ struct rip_info *rip_ecmp_replace(struct rip *rip, struct rip_info *rinfo_new)
if (tmp_rinfo == rinfo)
continue;
- THREAD_OFF(tmp_rinfo->t_timeout);
- THREAD_OFF(tmp_rinfo->t_garbage_collect);
+ EVENT_OFF(tmp_rinfo->t_timeout);
+ EVENT_OFF(tmp_rinfo->t_garbage_collect);
list_delete_node(list, node);
rip_info_free(tmp_rinfo);
}
- THREAD_OFF(rinfo->t_timeout);
- THREAD_OFF(rinfo->t_garbage_collect);
+ EVENT_OFF(rinfo->t_timeout);
+ EVENT_OFF(rinfo->t_garbage_collect);
memcpy(rinfo, rinfo_new, sizeof(struct rip_info));
if (rip_route_rte(rinfo)) {
@@ -247,12 +247,12 @@ struct rip_info *rip_ecmp_delete(struct rip *rip, struct rip_info *rinfo)
struct route_node *rp = rinfo->rp;
struct list *list = (struct list *)rp->info;
- THREAD_OFF(rinfo->t_timeout);
+ EVENT_OFF(rinfo->t_timeout);
if (listcount(list) > 1) {
/* Some other ECMP entries still exist. Just delete this entry.
*/
- THREAD_OFF(rinfo->t_garbage_collect);
+ EVENT_OFF(rinfo->t_garbage_collect);
listnode_delete(list, rinfo);
if (rip_route_rte(rinfo)
&& CHECK_FLAG(rinfo->flags, RIP_RTF_FIB))
@@ -287,9 +287,9 @@ struct rip_info *rip_ecmp_delete(struct rip *rip, struct rip_info *rinfo)
}
/* Timeout RIP routes. */
-static void rip_timeout(struct thread *t)
+static void rip_timeout(struct event *t)
{
- struct rip_info *rinfo = THREAD_ARG(t);
+ struct rip_info *rinfo = EVENT_ARG(t);
struct rip *rip = rip_info_get_instance(rinfo);
rip_ecmp_delete(rip, rinfo);
@@ -298,9 +298,9 @@ static void rip_timeout(struct thread *t)
static void rip_timeout_update(struct rip *rip, struct rip_info *rinfo)
{
if (rinfo->metric != RIP_METRIC_INFINITY) {
- THREAD_OFF(rinfo->t_timeout);
- thread_add_timer(master, rip_timeout, rinfo, rip->timeout_time,
- &rinfo->t_timeout);
+ EVENT_OFF(rinfo->t_timeout);
+ event_add_timer(master, rip_timeout, rinfo, rip->timeout_time,
+ &rinfo->t_timeout);
}
}
@@ -644,8 +644,8 @@ static void rip_rte_process(struct rte *rte, struct sockaddr_in *from,
assert(newinfo.metric
!= RIP_METRIC_INFINITY);
- THREAD_OFF(rinfo->t_timeout);
- THREAD_OFF(rinfo->t_garbage_collect);
+ EVENT_OFF(rinfo->t_timeout);
+ EVENT_OFF(rinfo->t_garbage_collect);
memcpy(rinfo, &newinfo,
sizeof(struct rip_info));
rip_timeout_update(rip, rinfo);
@@ -1500,7 +1500,7 @@ static int rip_send_packet(uint8_t *buf, int size, struct sockaddr_in *to,
ret = sendmsg(rip->sock, &msg, 0);
if (IS_RIP_DEBUG_EVENT)
- zlog_debug("SEND to %pI4%d", &sin.sin_addr,
+ zlog_debug("SEND to %pI4 port %d", &sin.sin_addr,
ntohs(sin.sin_port));
if (ret < 0)
@@ -1598,7 +1598,7 @@ void rip_redistribute_delete(struct rip *rip, int type, int sub_type,
RIP_TIMER_ON(rinfo->t_garbage_collect,
rip_garbage_collect,
rip->garbage_time);
- THREAD_OFF(rinfo->t_timeout);
+ EVENT_OFF(rinfo->t_timeout);
rinfo->flags |= RIP_RTF_CHANGED;
if (IS_RIP_DEBUG_EVENT)
@@ -1697,9 +1697,9 @@ static void rip_request_process(struct rip_packet *packet, int size,
}
/* First entry point of RIP packet. */
-static void rip_read(struct thread *t)
+static void rip_read(struct event *t)
{
- struct rip *rip = THREAD_ARG(t);
+ struct rip *rip = EVENT_ARG(t);
int sock;
int ret;
int rtenum;
@@ -1715,7 +1715,7 @@ static void rip_read(struct thread *t)
struct prefix p;
/* Fetch socket then register myself. */
- sock = THREAD_FD(t);
+ sock = EVENT_FD(t);
/* Add myself to tne next event */
rip_event(rip, RIP_READ, sock);
@@ -2478,9 +2478,9 @@ static void rip_update_process(struct rip *rip, int route_type)
}
/* RIP's periodical timer. */
-static void rip_update(struct thread *t)
+static void rip_update(struct event *t)
{
- struct rip *rip = THREAD_ARG(t);
+ struct rip *rip = EVENT_ARG(t);
if (IS_RIP_DEBUG_EVENT)
zlog_debug("update timer fire!");
@@ -2490,7 +2490,7 @@ static void rip_update(struct thread *t)
/* Triggered updates may be suppressed if a regular update is due by
the time the triggered update would be sent. */
- THREAD_OFF(rip->t_triggered_interval);
+ EVENT_OFF(rip->t_triggered_interval);
rip->trigger = 0;
/* Register myself. */
@@ -2520,9 +2520,9 @@ static void rip_clear_changed_flag(struct rip *rip)
}
/* Triggered update interval timer. */
-static void rip_triggered_interval(struct thread *t)
+static void rip_triggered_interval(struct event *t)
{
- struct rip *rip = THREAD_ARG(t);
+ struct rip *rip = EVENT_ARG(t);
if (rip->trigger) {
rip->trigger = 0;
@@ -2531,13 +2531,13 @@ static void rip_triggered_interval(struct thread *t)
}
/* Execute triggered update. */
-static void rip_triggered_update(struct thread *t)
+static void rip_triggered_update(struct event *t)
{
- struct rip *rip = THREAD_ARG(t);
+ struct rip *rip = EVENT_ARG(t);
int interval;
/* Cancel interval timer. */
- THREAD_OFF(rip->t_triggered_interval);
+ EVENT_OFF(rip->t_triggered_interval);
rip->trigger = 0;
/* Logging triggered update. */
@@ -2558,8 +2558,8 @@ static void rip_triggered_update(struct thread *t)
update is triggered when the timer expires. */
interval = (frr_weak_random() % 5) + 1;
- thread_add_timer(master, rip_triggered_interval, rip, interval,
- &rip->t_triggered_interval);
+ event_add_timer(master, rip_triggered_interval, rip, interval,
+ &rip->t_triggered_interval);
}
/* Withdraw redistributed route. */
@@ -2587,7 +2587,7 @@ void rip_redistribute_withdraw(struct rip *rip, int type)
rinfo->metric = RIP_METRIC_INFINITY;
RIP_TIMER_ON(rinfo->t_garbage_collect, rip_garbage_collect,
rip->garbage_time);
- THREAD_OFF(rinfo->t_timeout);
+ EVENT_OFF(rinfo->t_timeout);
rinfo->flags |= RIP_RTF_CHANGED;
if (IS_RIP_DEBUG_EVENT) {
@@ -2766,21 +2766,21 @@ void rip_event(struct rip *rip, enum rip_event event, int sock)
switch (event) {
case RIP_READ:
- thread_add_read(master, rip_read, rip, sock, &rip->t_read);
+ event_add_read(master, rip_read, rip, sock, &rip->t_read);
break;
case RIP_UPDATE_EVENT:
- THREAD_OFF(rip->t_update);
+ EVENT_OFF(rip->t_update);
jitter = rip_update_jitter(rip->update_time);
- thread_add_timer(master, rip_update, rip,
- sock ? 2 : rip->update_time + jitter,
- &rip->t_update);
+ event_add_timer(master, rip_update, rip,
+ sock ? 2 : rip->update_time + jitter,
+ &rip->t_update);
break;
case RIP_TRIGGERED_UPDATE:
if (rip->t_triggered_interval)
rip->trigger = 1;
else
- thread_add_event(master, rip_triggered_update, rip, 0,
- &rip->t_triggered_update);
+ event_add_event(master, rip_triggered_update, rip, 0,
+ &rip->t_triggered_update);
break;
default:
break;
@@ -2836,16 +2836,11 @@ uint8_t rip_distance_apply(struct rip *rip, struct rip_info *rinfo)
if (access_list_apply(alist, &rinfo->rp->p)
== FILTER_DENY)
return 0;
-
- return rdistance->distance;
- } else
- return rdistance->distance;
+ }
+ return rdistance->distance;
}
- if (rip->distance)
- return rip->distance;
-
- return 0;
+ return rip->distance;
}
static void rip_distance_show(struct vty *vty, struct rip *rip)
@@ -2899,8 +2894,8 @@ void rip_ecmp_disable(struct rip *rip)
if (tmp_rinfo == rinfo)
continue;
- THREAD_OFF(tmp_rinfo->t_timeout);
- THREAD_OFF(tmp_rinfo->t_garbage_collect);
+ EVENT_OFF(tmp_rinfo->t_timeout);
+ EVENT_OFF(tmp_rinfo->t_garbage_collect);
list_delete_node(list, node);
rip_info_free(tmp_rinfo);
}
@@ -2923,15 +2918,15 @@ static void rip_vty_out_uptime(struct vty *vty, struct rip_info *rinfo)
struct tm tm;
#define TIME_BUF 25
char timebuf[TIME_BUF];
- struct thread *thread;
+ struct event *thread;
if ((thread = rinfo->t_timeout) != NULL) {
- clock = thread_timer_remain_second(thread);
+ clock = event_timer_remain_second(thread);
gmtime_r(&clock, &tm);
strftime(timebuf, TIME_BUF, "%M:%S", &tm);
vty_out(vty, "%5s", timebuf);
} else if ((thread = rinfo->t_garbage_collect) != NULL) {
- clock = thread_timer_remain_second(thread);
+ clock = event_timer_remain_second(thread);
gmtime_r(&clock, &tm);
strftime(timebuf, TIME_BUF, "%M:%S", &tm);
vty_out(vty, "%5s", timebuf);
@@ -3106,7 +3101,7 @@ DEFUN (show_ip_rip_status,
vty_out(vty, " Sending updates every %u seconds with +/-50%%,",
rip->update_time);
vty_out(vty, " next due in %lu seconds\n",
- thread_timer_remain_second(rip->t_update));
+ event_timer_remain_second(rip->t_update));
vty_out(vty, " Timeout after %u seconds,", rip->timeout_time);
vty_out(vty, " garbage collect after %u seconds\n", rip->garbage_time);
@@ -3492,8 +3487,8 @@ static void rip_instance_disable(struct rip *rip)
rip_zebra_ipv4_delete(rip, rp);
for (ALL_LIST_ELEMENTS_RO(list, listnode, rinfo)) {
- THREAD_OFF(rinfo->t_timeout);
- THREAD_OFF(rinfo->t_garbage_collect);
+ EVENT_OFF(rinfo->t_timeout);
+ EVENT_OFF(rinfo->t_garbage_collect);
rip_info_free(rinfo);
}
list_delete(&list);
@@ -3505,12 +3500,12 @@ static void rip_instance_disable(struct rip *rip)
rip_redistribute_disable(rip);
/* Cancel RIP related timers. */
- THREAD_OFF(rip->t_update);
- THREAD_OFF(rip->t_triggered_update);
- THREAD_OFF(rip->t_triggered_interval);
+ EVENT_OFF(rip->t_update);
+ EVENT_OFF(rip->t_triggered_update);
+ EVENT_OFF(rip->t_triggered_interval);
/* Cancel read thread. */
- THREAD_OFF(rip->t_read);
+ EVENT_OFF(rip->t_read);
/* Close RIP socket. */
close(rip->sock);
diff --git a/ripd/ripd.h b/ripd/ripd.h
index 4894cb8632..176a3bfc37 100644
--- a/ripd/ripd.h
+++ b/ripd/ripd.h
@@ -117,15 +117,15 @@ struct rip {
struct list *peer_list;
/* RIP threads. */
- struct thread *t_read;
+ struct event *t_read;
/* Update and garbage timer. */
- struct thread *t_update;
+ struct event *t_update;
/* Triggered update hack. */
int trigger;
- struct thread *t_triggered_update;
- struct thread *t_triggered_interval;
+ struct event *t_triggered_update;
+ struct event *t_triggered_interval;
/* RIP timer values. */
uint32_t update_time;
@@ -239,8 +239,8 @@ struct rip_info {
uint8_t flags;
/* Garbage collect timer. */
- struct thread *t_timeout;
- struct thread *t_garbage_collect;
+ struct event *t_timeout;
+ struct event *t_garbage_collect;
/* Route-map futures - this variables can be changed. */
struct in_addr nexthop_out;
@@ -309,7 +309,7 @@ struct rip_interface {
struct route_map *routemap[RIP_FILTER_MAX];
/* Wake up thread. */
- struct thread *t_wakeup;
+ struct event *t_wakeup;
/* Interface statistics. */
int recv_badpackets;
@@ -342,7 +342,7 @@ struct rip_peer {
int recv_badroutes;
/* Timeout thread. */
- struct thread *t_timeout;
+ struct event *t_timeout;
};
struct rip_distance {
@@ -387,7 +387,7 @@ enum rip_event {
};
/* Macro for timer turn on. */
-#define RIP_TIMER_ON(T,F,V) thread_add_timer (master, (F), rinfo, (V), &(T))
+#define RIP_TIMER_ON(T, F, V) event_add_timer(master, (F), rinfo, (V), &(T))
#define RIP_OFFSET_LIST_IN 0
#define RIP_OFFSET_LIST_OUT 1
@@ -418,7 +418,7 @@ extern void rip_if_init(void);
extern void rip_route_map_init(void);
extern void rip_zebra_vrf_register(struct vrf *vrf);
extern void rip_zebra_vrf_deregister(struct vrf *vrf);
-extern void rip_zclient_init(struct thread_master *);
+extern void rip_zclient_init(struct event_loop *e);
extern void rip_zclient_stop(void);
extern int if_check_address(struct rip *rip, struct in_addr addr);
extern struct rip *rip_lookup_by_vrf_id(vrf_id_t vrf_id);
@@ -509,7 +509,7 @@ extern struct zebra_privs_t ripd_privs;
extern struct rip_instance_head rip_instances;
/* Master thread structure. */
-extern struct thread_master *master;
+extern struct event_loop *master;
DECLARE_HOOK(rip_ifaddr_add, (struct connected * ifc), (ifc));
DECLARE_HOOK(rip_ifaddr_del, (struct connected * ifc), (ifc));
diff --git a/ripngd/ripng_interface.c b/ripngd/ripng_interface.c
index 1fc6f2553e..1d9d53e47a 100644
--- a/ripngd/ripng_interface.c
+++ b/ripngd/ripng_interface.c
@@ -17,7 +17,7 @@
#include "zclient.h"
#include "command.h"
#include "agg_table.h"
-#include "thread.h"
+#include "frrevent.h"
#include "privs.h"
#include "vrf.h"
#include "lib_errors.h"
@@ -155,7 +155,7 @@ static int ripng_if_down(struct interface *ifp)
ri = ifp->info;
- THREAD_OFF(ri->t_wakeup);
+ EVENT_OFF(ri->t_wakeup);
ripng = ri->ripng;
@@ -301,7 +301,7 @@ void ripng_interface_clean(struct ripng *ripng)
ri->enable_interface = 0;
ri->running = 0;
- THREAD_OFF(ri->t_wakeup);
+ EVENT_OFF(ri->t_wakeup);
}
}
@@ -586,13 +586,13 @@ int ripng_enable_if_delete(struct ripng *ripng, const char *ifname)
}
/* Wake up interface. */
-static void ripng_interface_wakeup(struct thread *t)
+static void ripng_interface_wakeup(struct event *t)
{
struct interface *ifp;
struct ripng_interface *ri;
/* Get interface. */
- ifp = THREAD_ARG(t);
+ ifp = EVENT_ARG(t);
ri = ifp->info;
@@ -698,8 +698,8 @@ void ripng_enable_apply(struct interface *ifp)
zlog_info("RIPng INTERFACE ON %s", ifp->name);
/* Add interface wake up thread. */
- thread_add_timer(master, ripng_interface_wakeup, ifp, 1,
- &ri->t_wakeup);
+ event_add_timer(master, ripng_interface_wakeup, ifp, 1,
+ &ri->t_wakeup);
ripng_connect_set(ifp, 1);
} else {
diff --git a/ripngd/ripng_main.c b/ripngd/ripng_main.c
index 14e69834ca..1d392efdde 100644
--- a/ripngd/ripng_main.c
+++ b/ripngd/ripng_main.c
@@ -12,7 +12,7 @@
#include "vty.h"
#include "command.h"
#include "memory.h"
-#include "thread.h"
+#include "frrevent.h"
#include "log.h"
#include "prefix.h"
#include "if.h"
@@ -48,7 +48,7 @@ struct zebra_privs_t ripngd_privs = {
/* Master of threads. */
-struct thread_master *master;
+struct event_loop *master;
static struct frr_daemon_info ripngd_di;
diff --git a/ripngd/ripng_nb_rpcs.c b/ripngd/ripng_nb_rpcs.c
index 381ff717c1..b23572d492 100644
--- a/ripngd/ripng_nb_rpcs.c
+++ b/ripngd/ripng_nb_rpcs.c
@@ -53,8 +53,8 @@ static void clear_ripng_route(struct ripng *ripng)
}
if (rinfo) {
- THREAD_OFF(rinfo->t_timeout);
- THREAD_OFF(rinfo->t_garbage_collect);
+ EVENT_OFF(rinfo->t_timeout);
+ EVENT_OFF(rinfo->t_garbage_collect);
listnode_delete(list, rinfo);
ripng_info_free(rinfo);
}
diff --git a/ripngd/ripng_peer.c b/ripngd/ripng_peer.c
index 75a9ed77fe..901b548a42 100644
--- a/ripngd/ripng_peer.c
+++ b/ripngd/ripng_peer.c
@@ -13,7 +13,7 @@
#include "prefix.h"
#include "command.h"
#include "linklist.h"
-#include "thread.h"
+#include "frrevent.h"
#include "memory.h"
#include "ripngd/ripngd.h"
@@ -28,7 +28,7 @@ static struct ripng_peer *ripng_peer_new(void)
static void ripng_peer_free(struct ripng_peer *peer)
{
- THREAD_OFF(peer->t_timeout);
+ EVENT_OFF(peer->t_timeout);
XFREE(MTYPE_RIPNG_PEER, peer);
}
@@ -60,11 +60,11 @@ struct ripng_peer *ripng_peer_lookup_next(struct ripng *ripng,
/* RIPng peer is timeout.
* Garbage collector.
**/
-static void ripng_peer_timeout(struct thread *t)
+static void ripng_peer_timeout(struct event *t)
{
struct ripng_peer *peer;
- peer = THREAD_ARG(t);
+ peer = EVENT_ARG(t);
listnode_delete(peer->ripng->peer_list, peer);
ripng_peer_free(peer);
}
@@ -78,7 +78,7 @@ static struct ripng_peer *ripng_peer_get(struct ripng *ripng,
peer = ripng_peer_lookup(ripng, addr);
if (peer) {
- THREAD_OFF(peer->t_timeout);
+ EVENT_OFF(peer->t_timeout);
} else {
peer = ripng_peer_new();
peer->ripng = ripng;
@@ -87,8 +87,8 @@ static struct ripng_peer *ripng_peer_get(struct ripng *ripng,
}
/* Update timeout thread. */
- thread_add_timer(master, ripng_peer_timeout, peer,
- RIPNG_PEER_TIMER_DEFAULT, &peer->t_timeout);
+ event_add_timer(master, ripng_peer_timeout, peer,
+ RIPNG_PEER_TIMER_DEFAULT, &peer->t_timeout);
/* Last update time set. */
time(&peer->uptime);
diff --git a/ripngd/ripng_zebra.c b/ripngd/ripng_zebra.c
index b126a15b5b..d974d65df5 100644
--- a/ripngd/ripng_zebra.c
+++ b/ripngd/ripng_zebra.c
@@ -228,7 +228,7 @@ static zclient_handler *const ripng_handlers[] = {
};
/* Initialize zebra structure and it's commands. */
-void zebra_init(struct thread_master *master)
+void zebra_init(struct event_loop *master)
{
/* Allocate zebra structure. */
zclient = zclient_new(master, &zclient_options_default, ripng_handlers,
diff --git a/ripngd/ripngd.c b/ripngd/ripngd.c
index f01371f41e..79e8871f6a 100644
--- a/ripngd/ripngd.c
+++ b/ripngd/ripngd.c
@@ -8,7 +8,7 @@
#include "prefix.h"
#include "filter.h"
#include "log.h"
-#include "thread.h"
+#include "frrevent.h"
#include "memory.h"
#include "if.h"
#include "stream.h"
@@ -46,7 +46,7 @@ void ripng_output_process(struct interface *, struct sockaddr_in6 *, int);
static void ripng_instance_enable(struct ripng *ripng, struct vrf *vrf,
int sock);
static void ripng_instance_disable(struct ripng *ripng);
-static void ripng_triggered_update(struct thread *);
+static void ripng_triggered_update(struct event *);
static void ripng_if_rmap_update(struct if_rmap_ctx *ctx,
struct if_rmap *if_rmap);
@@ -408,15 +408,15 @@ static int ripng_lladdr_check(struct interface *ifp, struct in6_addr *addr)
}
/* RIPng route garbage collect timer. */
-static void ripng_garbage_collect(struct thread *t)
+static void ripng_garbage_collect(struct event *t)
{
struct ripng_info *rinfo;
struct agg_node *rp;
- rinfo = THREAD_ARG(t);
+ rinfo = EVENT_ARG(t);
/* Off timeout timer. */
- THREAD_OFF(rinfo->t_timeout);
+ EVENT_OFF(rinfo->t_timeout);
/* Get route_node pointer. */
rp = rinfo->rp;
@@ -503,14 +503,14 @@ struct ripng_info *ripng_ecmp_replace(struct ripng *ripng,
/* Re-use the first entry, and delete the others. */
for (ALL_LIST_ELEMENTS(list, node, nextnode, tmp_rinfo))
if (tmp_rinfo != rinfo) {
- THREAD_OFF(tmp_rinfo->t_timeout);
- THREAD_OFF(tmp_rinfo->t_garbage_collect);
+ EVENT_OFF(tmp_rinfo->t_timeout);
+ EVENT_OFF(tmp_rinfo->t_garbage_collect);
list_delete_node(list, node);
ripng_info_free(tmp_rinfo);
}
- THREAD_OFF(rinfo->t_timeout);
- THREAD_OFF(rinfo->t_garbage_collect);
+ EVENT_OFF(rinfo->t_timeout);
+ EVENT_OFF(rinfo->t_garbage_collect);
memcpy(rinfo, rinfo_new, sizeof(struct ripng_info));
if (ripng_route_rte(rinfo)) {
@@ -542,7 +542,7 @@ struct ripng_info *ripng_ecmp_delete(struct ripng *ripng,
struct agg_node *rp = rinfo->rp;
struct list *list = (struct list *)rp->info;
- THREAD_OFF(rinfo->t_timeout);
+ EVENT_OFF(rinfo->t_timeout);
if (rinfo->metric != RIPNG_METRIC_INFINITY)
ripng_aggregate_decrement(rp, rinfo);
@@ -550,7 +550,7 @@ struct ripng_info *ripng_ecmp_delete(struct ripng *ripng,
if (listcount(list) > 1) {
/* Some other ECMP entries still exist. Just delete this entry.
*/
- THREAD_OFF(rinfo->t_garbage_collect);
+ EVENT_OFF(rinfo->t_garbage_collect);
listnode_delete(list, rinfo);
if (ripng_route_rte(rinfo)
&& CHECK_FLAG(rinfo->flags, RIPNG_RTF_FIB))
@@ -585,9 +585,9 @@ struct ripng_info *ripng_ecmp_delete(struct ripng *ripng,
}
/* Timeout RIPng routes. */
-static void ripng_timeout(struct thread *t)
+static void ripng_timeout(struct event *t)
{
- struct ripng_info *rinfo = THREAD_ARG(t);
+ struct ripng_info *rinfo = EVENT_ARG(t);
struct ripng *ripng = ripng_info_get_instance(rinfo);
ripng_ecmp_delete(ripng, rinfo);
@@ -596,9 +596,9 @@ static void ripng_timeout(struct thread *t)
static void ripng_timeout_update(struct ripng *ripng, struct ripng_info *rinfo)
{
if (rinfo->metric != RIPNG_METRIC_INFINITY) {
- THREAD_OFF(rinfo->t_timeout);
- thread_add_timer(master, ripng_timeout, rinfo,
- ripng->timeout_time, &rinfo->t_timeout);
+ EVENT_OFF(rinfo->t_timeout);
+ event_add_timer(master, ripng_timeout, rinfo,
+ ripng->timeout_time, &rinfo->t_timeout);
}
}
@@ -877,18 +877,18 @@ static void ripng_route_process(struct rte *rte, struct sockaddr_in6 *from,
* but
* highly recommended".
*/
- if (!ripng->ecmp && !same && rinfo->metric == rte->metric
- && rinfo->t_timeout
- && (thread_timer_remain_second(rinfo->t_timeout)
- < (ripng->timeout_time / 2))) {
+ if (!ripng->ecmp && !same && rinfo->metric == rte->metric &&
+ rinfo->t_timeout &&
+ (event_timer_remain_second(rinfo->t_timeout) <
+ (ripng->timeout_time / 2))) {
ripng_ecmp_replace(ripng, &newinfo);
}
/* Next, compare the metrics. If the datagram is from the same
router as the existing route, and the new metric is different
than the old one; or, if the new metric is lower than the old
one; do the following actions: */
- else if ((same && rinfo->metric != rte->metric)
- || rte->metric < rinfo->metric) {
+ else if ((same && rinfo->metric != rte->metric) ||
+ rte->metric < rinfo->metric) {
if (listcount(list) == 1) {
if (newinfo.metric != RIPNG_METRIC_INFINITY)
ripng_ecmp_replace(ripng, &newinfo);
@@ -1007,7 +1007,7 @@ void ripng_redistribute_delete(struct ripng *ripng, int type, int sub_type,
RIPNG_TIMER_ON(rinfo->t_garbage_collect,
ripng_garbage_collect,
ripng->garbage_time);
- THREAD_OFF(rinfo->t_timeout);
+ EVENT_OFF(rinfo->t_timeout);
/* Aggregate count decrement. */
ripng_aggregate_decrement(rp, rinfo);
@@ -1046,7 +1046,7 @@ void ripng_redistribute_withdraw(struct ripng *ripng, int type)
RIPNG_TIMER_ON(rinfo->t_garbage_collect,
ripng_garbage_collect,
ripng->garbage_time);
- THREAD_OFF(rinfo->t_timeout);
+ EVENT_OFF(rinfo->t_timeout);
/* Aggregate count decrement. */
ripng_aggregate_decrement(rp, rinfo);
@@ -1282,9 +1282,9 @@ static void ripng_request_process(struct ripng_packet *packet, int size,
}
/* First entry point of reading RIPng packet. */
-static void ripng_read(struct thread *thread)
+static void ripng_read(struct event *thread)
{
- struct ripng *ripng = THREAD_ARG(thread);
+ struct ripng *ripng = EVENT_ARG(thread);
int len;
int sock;
struct sockaddr_in6 from;
@@ -1299,7 +1299,7 @@ static void ripng_read(struct thread *thread)
/* Fetch thread data and set read pointer to empty for event
managing. `sock' sould be same as ripng->sock. */
- sock = THREAD_FD(thread);
+ sock = EVENT_FD(thread);
/* Add myself to the next event. */
ripng_event(ripng, RIPNG_READ, sock);
@@ -1390,9 +1390,9 @@ static void ripng_clear_changed_flag(struct ripng *ripng)
/* Regular update of RIPng route. Send all routing formation to RIPng
enabled interface. */
-static void ripng_update(struct thread *t)
+static void ripng_update(struct event *t)
{
- struct ripng *ripng = THREAD_ARG(t);
+ struct ripng *ripng = EVENT_ARG(t);
struct interface *ifp;
struct ripng_interface *ri;
@@ -1430,7 +1430,7 @@ static void ripng_update(struct thread *t)
/* Triggered updates may be suppressed if a regular update is due by
the time the triggered update would be sent. */
- THREAD_OFF(ripng->t_triggered_interval);
+ EVENT_OFF(ripng->t_triggered_interval);
ripng->trigger = 0;
/* Reset flush event. */
@@ -1438,9 +1438,9 @@ static void ripng_update(struct thread *t)
}
/* Triggered update interval timer. */
-static void ripng_triggered_interval(struct thread *t)
+static void ripng_triggered_interval(struct event *t)
{
- struct ripng *ripng = THREAD_ARG(t);
+ struct ripng *ripng = EVENT_ARG(t);
if (ripng->trigger) {
ripng->trigger = 0;
@@ -1449,15 +1449,15 @@ static void ripng_triggered_interval(struct thread *t)
}
/* Execute triggered update. */
-void ripng_triggered_update(struct thread *t)
+void ripng_triggered_update(struct event *t)
{
- struct ripng *ripng = THREAD_ARG(t);
+ struct ripng *ripng = EVENT_ARG(t);
struct interface *ifp;
struct ripng_interface *ri;
int interval;
/* Cancel interval timer. */
- THREAD_OFF(ripng->t_triggered_interval);
+ EVENT_OFF(ripng->t_triggered_interval);
ripng->trigger = 0;
/* Logging triggered update. */
@@ -1493,8 +1493,8 @@ void ripng_triggered_update(struct thread *t)
update is triggered when the timer expires. */
interval = (frr_weak_random() % 5) + 1;
- thread_add_timer(master, ripng_triggered_interval, ripng, interval,
- &ripng->t_triggered_interval);
+ event_add_timer(master, ripng_triggered_interval, ripng, interval,
+ &ripng->t_triggered_interval);
}
/* Write routing table entry to the stream and return next index of
@@ -1898,25 +1898,24 @@ void ripng_event(struct ripng *ripng, enum ripng_event event, int sock)
switch (event) {
case RIPNG_READ:
- thread_add_read(master, ripng_read, ripng, sock,
- &ripng->t_read);
+ event_add_read(master, ripng_read, ripng, sock, &ripng->t_read);
break;
case RIPNG_UPDATE_EVENT:
- THREAD_OFF(ripng->t_update);
+ EVENT_OFF(ripng->t_update);
/* Update timer jitter. */
jitter = ripng_update_jitter(ripng->update_time);
- thread_add_timer(master, ripng_update, ripng,
- sock ? 2 : ripng->update_time + jitter,
- &ripng->t_update);
+ event_add_timer(master, ripng_update, ripng,
+ sock ? 2 : ripng->update_time + jitter,
+ &ripng->t_update);
break;
case RIPNG_TRIGGERED_UPDATE:
if (ripng->t_triggered_interval)
ripng->trigger = 1;
else
- thread_add_event(master, ripng_triggered_update, ripng,
- 0, &ripng->t_triggered_update);
+ event_add_event(master, ripng_triggered_update, ripng,
+ 0, &ripng->t_triggered_update);
break;
case RIPNG_ZEBRA:
case RIPNG_REQUEST_EVENT:
@@ -1932,15 +1931,15 @@ static void ripng_vty_out_uptime(struct vty *vty, struct ripng_info *rinfo)
struct tm tm;
#define TIME_BUF 25
char timebuf[TIME_BUF];
- struct thread *thread;
+ struct event *thread;
if ((thread = rinfo->t_timeout) != NULL) {
- clock = thread_timer_remain_second(thread);
+ clock = event_timer_remain_second(thread);
gmtime_r(&clock, &tm);
strftime(timebuf, TIME_BUF, "%M:%S", &tm);
vty_out(vty, "%5s", timebuf);
} else if ((thread = rinfo->t_garbage_collect) != NULL) {
- clock = thread_timer_remain_second(thread);
+ clock = event_timer_remain_second(thread);
gmtime_r(&clock, &tm);
strftime(timebuf, TIME_BUF, "%M:%S", &tm);
vty_out(vty, "%5s", timebuf);
@@ -2129,7 +2128,7 @@ DEFUN (show_ipv6_ripng_status,
vty_out(vty, " Sending updates every %u seconds with +/-50%%,",
ripng->update_time);
vty_out(vty, " next due in %lu seconds\n",
- thread_timer_remain_second(ripng->t_update));
+ event_timer_remain_second(ripng->t_update));
vty_out(vty, " Timeout after %u seconds,", ripng->timeout_time);
vty_out(vty, " garbage collect after %u seconds\n",
ripng->garbage_time);
@@ -2195,9 +2194,8 @@ void ripng_ecmp_disable(struct ripng *ripng)
/* Drop all other entries, except the first one. */
for (ALL_LIST_ELEMENTS(list, node, nextnode, tmp_rinfo))
if (tmp_rinfo != rinfo) {
- THREAD_OFF(tmp_rinfo->t_timeout);
- THREAD_OFF(
- tmp_rinfo->t_garbage_collect);
+ EVENT_OFF(tmp_rinfo->t_timeout);
+ EVENT_OFF(tmp_rinfo->t_garbage_collect);
list_delete_node(list, node);
ripng_info_free(tmp_rinfo);
}
@@ -2514,8 +2512,8 @@ static void ripng_instance_disable(struct ripng *ripng)
ripng_zebra_ipv6_delete(ripng, rp);
for (ALL_LIST_ELEMENTS_RO(list, listnode, rinfo)) {
- THREAD_OFF(rinfo->t_timeout);
- THREAD_OFF(rinfo->t_garbage_collect);
+ EVENT_OFF(rinfo->t_timeout);
+ EVENT_OFF(rinfo->t_garbage_collect);
ripng_info_free(rinfo);
}
list_delete(&list);
@@ -2534,12 +2532,12 @@ static void ripng_instance_disable(struct ripng *ripng)
ripng_redistribute_disable(ripng);
/* Cancel the RIPng timers */
- THREAD_OFF(ripng->t_update);
- THREAD_OFF(ripng->t_triggered_update);
- THREAD_OFF(ripng->t_triggered_interval);
+ EVENT_OFF(ripng->t_update);
+ EVENT_OFF(ripng->t_triggered_update);
+ EVENT_OFF(ripng->t_triggered_interval);
/* Cancel the read thread */
- THREAD_OFF(ripng->t_read);
+ EVENT_OFF(ripng->t_read);
/* Close the RIPng socket */
if (ripng->sock >= 0) {
diff --git a/ripngd/ripngd.h b/ripngd/ripngd.h
index 59b948b8f1..eefcb0ee69 100644
--- a/ripngd/ripngd.h
+++ b/ripngd/ripngd.h
@@ -121,13 +121,13 @@ struct ripng {
struct list *offset_list_master;
/* RIPng threads. */
- struct thread *t_read;
- struct thread *t_update;
+ struct event *t_read;
+ struct event *t_update;
/* Triggered update hack. */
int trigger;
- struct thread *t_triggered_update;
- struct thread *t_triggered_interval;
+ struct event *t_triggered_update;
+ struct event *t_triggered_interval;
/* RIPng ECMP flag */
bool ecmp;
@@ -200,8 +200,8 @@ struct ripng_info {
uint8_t flags;
/* Garbage collect timer. */
- struct thread *t_timeout;
- struct thread *t_garbage_collect;
+ struct event *t_timeout;
+ struct event *t_garbage_collect;
/* Route-map features - this variables can be changed. */
struct in6_addr nexthop_out;
@@ -254,7 +254,7 @@ struct ripng_interface {
uint8_t default_only;
/* Wake up thread. */
- struct thread *t_wakeup;
+ struct event *t_wakeup;
/* Passive interface. */
int passive;
@@ -282,7 +282,7 @@ struct ripng_peer {
int recv_badroutes;
/* Timeout thread. */
- struct thread *t_timeout;
+ struct event *t_timeout;
};
/* All RIPng events. */
@@ -295,7 +295,7 @@ enum ripng_event {
};
/* RIPng timer on/off macro. */
-#define RIPNG_TIMER_ON(T,F,V) thread_add_timer (master, (F), rinfo, (V), &(T))
+#define RIPNG_TIMER_ON(T, F, V) event_add_timer(master, (F), rinfo, (V), &(T))
#define RIPNG_OFFSET_LIST_IN 0
#define RIPNG_OFFSET_LIST_OUT 1
@@ -316,7 +316,7 @@ struct ripng_offset_list {
/* Extern variables. */
extern struct zebra_privs_t ripngd_privs;
-extern struct thread_master *master;
+extern struct event_loop *master;
extern struct ripng_instance_head ripng_instances;
/* Prototypes. */
@@ -338,7 +338,7 @@ extern void ripng_zebra_vrf_register(struct vrf *vrf);
extern void ripng_zebra_vrf_deregister(struct vrf *vrf);
extern void ripng_terminate(void);
/* zclient_init() is done by ripng_zebra.c:zebra_init() */
-extern void zebra_init(struct thread_master *);
+extern void zebra_init(struct event_loop *master);
extern void ripng_zebra_stop(void);
extern void ripng_redistribute_conf_update(struct ripng *ripng, int type);
extern void ripng_redistribute_conf_delete(struct ripng *ripng, int type);
diff --git a/sharpd/sharp_logpump.c b/sharpd/sharp_logpump.c
index cadd818953..5474e80b11 100644
--- a/sharpd/sharp_logpump.c
+++ b/sharpd/sharp_logpump.c
@@ -11,7 +11,7 @@
#include "prefix.h"
#include "nexthop.h"
#include "log.h"
-#include "thread.h"
+#include "frrevent.h"
#include "vrf.h"
#include "zclient.h"
#include "frr_pthread.h"
@@ -28,9 +28,9 @@ static size_t lp_ctr, lp_expect;
static struct rusage lp_rusage;
static struct vty *lp_vty;
-extern struct thread_master *master;
+extern struct event_loop *master;
-static void logpump_done(struct thread *thread)
+static void logpump_done(struct event *thread)
{
double x;
@@ -105,7 +105,7 @@ static void *logpump_run(void *arg)
getrusage(RUSAGE_SELF, &lp_rusage);
#endif
- thread_add_timer_msec(master, logpump_done, NULL, 0, NULL);
+ event_add_timer_msec(master, logpump_done, NULL, 0, NULL);
return NULL;
}
diff --git a/sharpd/sharp_main.c b/sharpd/sharp_main.c
index 9d33fc89a7..fa85c2b448 100644
--- a/sharpd/sharp_main.c
+++ b/sharpd/sharp_main.c
@@ -8,7 +8,7 @@
#include <lib/version.h>
#include "getopt.h"
-#include "thread.h"
+#include "frrevent.h"
#include "prefix.h"
#include "linklist.h"
#include "if.h"
@@ -55,7 +55,7 @@ struct zebra_privs_t sharp_privs = {
struct option longopts[] = {{0}};
/* Master of threads. */
-struct thread_master *master;
+struct event_loop *master;
/* SIGHUP handler. */
static void sighup(void)
diff --git a/sharpd/sharp_vty.c b/sharpd/sharp_vty.c
index 77b562d6a6..0d7ba34530 100644
--- a/sharpd/sharp_vty.c
+++ b/sharpd/sharp_vty.c
@@ -1059,7 +1059,7 @@ DEFUN (show_sharp_ted,
return CMD_WARNING_CONFIG_FAILED;
}
/* Get the Subnet from the Link State Database */
- subnet = ls_find_subnet(sg.ted, pref);
+ subnet = ls_find_subnet(sg.ted, &pref);
if (!subnet) {
vty_out(vty, "No subnet found for ID %pFX\n",
&pref);
@@ -1245,6 +1245,7 @@ DEFPY (show_sharp_cspf,
}
if (path->status != SUCCESS) {
vty_out(vty, "Path computation failed: %d\n", path->status);
+ cpath_del(path);
return CMD_SUCCESS;
}
@@ -1260,7 +1261,7 @@ DEFPY (show_sharp_cspf,
&edge->attributes->standard.remote6);
}
vty_out(vty, "\n");
-
+ cpath_del(path);
return CMD_SUCCESS;
}
diff --git a/sharpd/sharp_zebra.c b/sharpd/sharp_zebra.c
index df06f5537e..91fb7f03b1 100644
--- a/sharpd/sharp_zebra.c
+++ b/sharpd/sharp_zebra.c
@@ -6,7 +6,7 @@
*/
#include <zebra.h>
-#include "thread.h"
+#include "frrevent.h"
#include "command.h"
#include "network.h"
#include "prefix.h"
@@ -26,7 +26,7 @@
struct zclient *zclient = NULL;
/* For registering threads. */
-extern struct thread_master *master;
+extern struct event_loop *master;
/* Privs info */
extern struct zebra_privs_t sharp_privs;
@@ -790,7 +790,7 @@ static int sharp_opaque_handler(ZAPI_CALLBACK_ARGS)
zclient->session_id, info.type);
if (info.type == LINK_STATE_UPDATE) {
- lse = ls_stream2ted(sg.ted, s, false);
+ lse = ls_stream2ted(sg.ted, s, true);
if (lse) {
zlog_debug(" |- Got %s %s from Link State Database",
status2txt[lse->status],
diff --git a/staticd/static_bfd.c b/staticd/static_bfd.c
index ccf7d206f2..78d8c05807 100644
--- a/staticd/static_bfd.c
+++ b/staticd/static_bfd.c
@@ -201,7 +201,7 @@ void static_next_hop_bfd_profile(struct static_nexthop *sn, const char *name)
bfd_sess_install(sn->bsp);
}
-void static_bfd_initialize(struct zclient *zc, struct thread_master *tm)
+void static_bfd_initialize(struct zclient *zc, struct event_loop *tm)
{
/* Initialize BFD integration library. */
bfd_protocol_integration_init(zc, tm);
diff --git a/staticd/static_main.c b/staticd/static_main.c
index bc501b3d69..9809d9751a 100644
--- a/staticd/static_main.c
+++ b/staticd/static_main.c
@@ -8,7 +8,7 @@
#include <lib/version.h>
#include "getopt.h"
-#include "thread.h"
+#include "frrevent.h"
#include "command.h"
#include "log.h"
#include "memory.h"
@@ -27,6 +27,8 @@
#include "static_debug.h"
#include "static_nb.h"
+#include "mgmt_be_client.h"
+
char backup_config_file[256];
bool mpls_enabled;
@@ -49,7 +51,9 @@ struct zebra_privs_t static_privs = {
struct option longopts[] = { { 0 } };
/* Master of threads. */
-struct thread_master *master;
+struct event_loop *master;
+
+uintptr_t mgmt_lib_hndl;
static struct frr_daemon_info staticd_di;
/* SIGHUP handler. */
@@ -64,6 +68,11 @@ static void sigint(void)
{
zlog_notice("Terminating on signal");
+ /* Disable BFD events to avoid wasting processing. */
+ bfd_protocol_integration_set_shutdown(true);
+
+ mgmt_be_client_lib_destroy(mgmt_lib_hndl);
+
static_vrf_terminate();
static_zebra_stop();
@@ -97,6 +106,51 @@ struct frr_signal_t static_signals[] = {
},
};
+static void static_mgmt_be_client_connect(uintptr_t lib_hndl,
+ uintptr_t usr_data, bool connected)
+{
+ (void)usr_data;
+
+ assert(lib_hndl == mgmt_lib_hndl);
+
+ zlog_debug("Got %s %s MGMTD Backend Client Server",
+ connected ? "connected" : "disconnected",
+ connected ? "to" : "from");
+
+ if (connected)
+ (void)mgmt_be_subscribe_yang_data(mgmt_lib_hndl, NULL, 0);
+}
+
+#if 0
+static void
+static_mgmt_txn_notify(uintptr_t lib_hndl, uintptr_t usr_data,
+ struct mgmt_be_client_txn_ctx *txn_ctx,
+ bool destroyed)
+{
+ zlog_debug("Got Txn %s Notify from MGMTD server",
+ destroyed ? "DESTROY" : "CREATE");
+
+ if (!destroyed) {
+ /*
+ * TODO: Allocate and install a private scratchpad for this
+ * transaction if required
+ */
+ } else {
+ /*
+ * TODO: Uninstall and deallocate the private scratchpad for
+ * this transaction if installed earlier.
+ */
+ }
+}
+#endif
+
+static struct mgmt_be_client_params mgmt_params = {
+ .name = "staticd",
+ .conn_retry_intvl_sec = 3,
+ .client_connect_notify = static_mgmt_be_client_connect,
+ .txn_notify = NULL, /* static_mgmt_txn_notify */
+};
+
static const struct frr_yang_module_info *const staticd_yang_modules[] = {
&frr_filter_info,
&frr_interface_info,
@@ -107,6 +161,10 @@ static const struct frr_yang_module_info *const staticd_yang_modules[] = {
#define STATIC_VTY_PORT 2616
+/*
+ * NOTE: .flags == FRR_NO_SPLIT_CONFIG to avoid reading split config, mgmtd will
+ * do this for us now
+ */
FRR_DAEMON_INFO(staticd, STATIC, .vty_port = STATIC_VTY_PORT,
.proghelp = "Implementation of STATIC.",
@@ -116,7 +174,8 @@ FRR_DAEMON_INFO(staticd, STATIC, .vty_port = STATIC_VTY_PORT,
.privs = &static_privs, .yang_modules = staticd_yang_modules,
.n_yang_modules = array_size(staticd_yang_modules),
-);
+
+ .flags = FRR_NO_SPLIT_CONFIG);
int main(int argc, char **argv, char **envp)
{
@@ -147,14 +206,21 @@ int main(int argc, char **argv, char **envp)
static_zebra_init();
static_vty_init();
+ /* Initialize MGMT backend functionalities */
+ mgmt_lib_hndl = mgmt_be_client_lib_init(&mgmt_params, master);
+ assert(mgmt_lib_hndl);
+
hook_register(routing_conf_event,
routing_control_plane_protocols_name_validate);
routing_control_plane_protocols_register_vrf_dependency();
- snprintf(backup_config_file, sizeof(backup_config_file),
- "%s/zebra.conf", frr_sysconfdir);
- staticd_di.backup_config_file = backup_config_file;
+ /*
+ * We set FRR_NO_SPLIT_CONFIG flag to avoid reading our config, but we
+ * still need to write one if vtysh tells us to. Setting the host
+ * config filename does this.
+ */
+ host_config_set(config_default);
frr_config_fork();
frr_run(master);
diff --git a/staticd/static_routes.c b/staticd/static_routes.c
index 3399686a90..1fbbf7e99d 100644
--- a/staticd/static_routes.c
+++ b/staticd/static_routes.c
@@ -757,30 +757,6 @@ void static_ifindex_update(struct interface *ifp, bool up)
static_ifindex_update_af(ifp, up, AFI_IP6, SAFI_MULTICAST);
}
-void static_get_nh_type(enum static_nh_type stype, char *type, size_t size)
-{
- switch (stype) {
- case STATIC_IFNAME:
- strlcpy(type, "ifindex", size);
- break;
- case STATIC_IPV4_GATEWAY:
- strlcpy(type, "ip4", size);
- break;
- case STATIC_IPV4_GATEWAY_IFNAME:
- strlcpy(type, "ip4-ifindex", size);
- break;
- case STATIC_BLACKHOLE:
- strlcpy(type, "blackhole", size);
- break;
- case STATIC_IPV6_GATEWAY:
- strlcpy(type, "ip6", size);
- break;
- case STATIC_IPV6_GATEWAY_IFNAME:
- strlcpy(type, "ip6-ifindex", size);
- break;
- };
-}
-
struct stable_info *static_get_stable_info(struct route_node *rn)
{
struct route_table *table;
diff --git a/staticd/static_routes.h b/staticd/static_routes.h
index eb7953db2c..3be6fd6b14 100644
--- a/staticd/static_routes.h
+++ b/staticd/static_routes.h
@@ -159,6 +159,31 @@ static_route_info_from_rnode(struct route_node *rn)
return (struct static_route_info *)(rn->info);
}
+static inline void static_get_nh_type(enum static_nh_type stype, char *type,
+ size_t size)
+{
+ switch (stype) {
+ case STATIC_IFNAME:
+ strlcpy(type, "ifindex", size);
+ break;
+ case STATIC_IPV4_GATEWAY:
+ strlcpy(type, "ip4", size);
+ break;
+ case STATIC_IPV4_GATEWAY_IFNAME:
+ strlcpy(type, "ip4-ifindex", size);
+ break;
+ case STATIC_BLACKHOLE:
+ strlcpy(type, "blackhole", size);
+ break;
+ case STATIC_IPV6_GATEWAY:
+ strlcpy(type, "ip6", size);
+ break;
+ case STATIC_IPV6_GATEWAY_IFNAME:
+ strlcpy(type, "ip6-ifindex", size);
+ break;
+ };
+}
+
extern bool mpls_enabled;
extern uint32_t zebra_ecmp_count;
@@ -192,8 +217,6 @@ extern struct static_path *static_add_path(struct route_node *rn,
uint32_t table_id, uint8_t distance);
extern void static_del_path(struct static_path *pn);
-extern void static_get_nh_type(enum static_nh_type stype, char *type,
- size_t size);
extern bool static_add_nexthop_validate(const char *nh_vrf_name,
enum static_nh_type type,
struct ipaddr *ipaddr);
@@ -229,7 +252,7 @@ extern void static_next_hop_bfd_profile(struct static_nexthop *sn,
extern void static_next_hop_bfd_multi_hop(struct static_nexthop *sn, bool mhop);
/** Call this function after zebra client initialization. */
-extern void static_bfd_initialize(struct zclient *zc, struct thread_master *tm);
+extern void static_bfd_initialize(struct zclient *zc, struct event_loop *tm);
extern void static_bfd_show(struct vty *vty, bool isjson);
diff --git a/staticd/static_vty.c b/staticd/static_vty.c
index d87ca16c61..386b255a85 100644
--- a/staticd/static_vty.c
+++ b/staticd/static_vty.c
@@ -285,10 +285,10 @@ static int static_route_nb_run(struct vty *vty, struct static_route_args *args)
nb_cli_enqueue_change(vty, ab_xpath,
NB_OP_MODIFY, "false");
}
- if (type == STATIC_IPV4_GATEWAY
- || type == STATIC_IPV6_GATEWAY
- || type == STATIC_IPV4_GATEWAY_IFNAME
- || type == STATIC_IPV6_GATEWAY_IFNAME) {
+ if (type == STATIC_IPV4_GATEWAY ||
+ type == STATIC_IPV6_GATEWAY ||
+ type == STATIC_IPV4_GATEWAY_IFNAME ||
+ type == STATIC_IPV6_GATEWAY_IFNAME) {
strlcpy(ab_xpath, xpath_nexthop, sizeof(ab_xpath));
strlcat(ab_xpath, FRR_STATIC_ROUTE_NH_COLOR_XPATH,
sizeof(ab_xpath));
@@ -368,25 +368,51 @@ static int static_route_nb_run(struct vty *vty, struct static_route_args *args)
ret = nb_cli_apply_changes(vty, "%s", xpath_prefix);
} else {
- if (args->source)
- snprintf(ab_xpath, sizeof(ab_xpath),
- FRR_DEL_S_ROUTE_SRC_NH_KEY_NO_DISTANCE_XPATH,
- "frr-staticd:staticd", "staticd", args->vrf,
- buf_prefix,
- yang_afi_safi_value2identity(args->afi,
- args->safi),
- buf_src_prefix, table_id, buf_nh_type,
- args->nexthop_vrf, buf_gate_str,
- args->interface_name);
- else
- snprintf(ab_xpath, sizeof(ab_xpath),
- FRR_DEL_S_ROUTE_NH_KEY_NO_DISTANCE_XPATH,
- "frr-staticd:staticd", "staticd", args->vrf,
- buf_prefix,
- yang_afi_safi_value2identity(args->afi,
- args->safi),
- table_id, buf_nh_type, args->nexthop_vrf,
- buf_gate_str, args->interface_name);
+ if (args->source) {
+ if (args->distance)
+ snprintf(ab_xpath, sizeof(ab_xpath),
+ FRR_DEL_S_ROUTE_SRC_NH_KEY_XPATH,
+ "frr-staticd:staticd", "staticd",
+ args->vrf, buf_prefix,
+ yang_afi_safi_value2identity(
+ args->afi, args->safi),
+ buf_src_prefix, table_id, distance,
+ buf_nh_type, args->nexthop_vrf,
+ buf_gate_str, args->interface_name);
+ else
+ snprintf(
+ ab_xpath, sizeof(ab_xpath),
+ FRR_DEL_S_ROUTE_SRC_NH_KEY_NO_DISTANCE_XPATH,
+ "frr-staticd:staticd", "staticd",
+ args->vrf, buf_prefix,
+ yang_afi_safi_value2identity(
+ args->afi, args->safi),
+ buf_src_prefix, table_id, buf_nh_type,
+ args->nexthop_vrf, buf_gate_str,
+ args->interface_name);
+ } else {
+ if (args->distance)
+ snprintf(ab_xpath, sizeof(ab_xpath),
+ FRR_DEL_S_ROUTE_NH_KEY_XPATH,
+ "frr-staticd:staticd", "staticd",
+ args->vrf, buf_prefix,
+ yang_afi_safi_value2identity(
+ args->afi, args->safi),
+ table_id, distance, buf_nh_type,
+ args->nexthop_vrf, buf_gate_str,
+ args->interface_name);
+ else
+ snprintf(
+ ab_xpath, sizeof(ab_xpath),
+ FRR_DEL_S_ROUTE_NH_KEY_NO_DISTANCE_XPATH,
+ "frr-staticd:staticd", "staticd",
+ args->vrf, buf_prefix,
+ yang_afi_safi_value2identity(
+ args->afi, args->safi),
+ table_id, buf_nh_type,
+ args->nexthop_vrf, buf_gate_str,
+ args->interface_name);
+ }
dnode = yang_dnode_get(vty->candidate_config->dnode, ab_xpath);
if (!dnode) {
@@ -1452,15 +1478,18 @@ DEFPY_YANG(debug_staticd, debug_staticd_cmd,
"Debug route\n"
"Debug bfd\n")
{
+#ifndef INCLUDE_MGMTD_CMDDEFS_ONLY
/* If no specific category, change all */
if (strmatch(argv[argc - 1]->text, "static"))
static_debug_set(vty->node, !no, true, true, true);
else
static_debug_set(vty->node, !no, !!events, !!route, !!bfd);
+#endif /* ifndef INCLUDE_MGMTD_CMDDEFS_ONLY */
return CMD_SUCCESS;
}
+#ifndef INCLUDE_MGMTD_CMDDEFS_ONLY
DEFPY(staticd_show_bfd_routes, staticd_show_bfd_routes_cmd,
"show bfd static route [json]$isjson",
SHOW_STR
@@ -1496,9 +1525,15 @@ static struct cmd_node debug_node = {
.config_write = static_config_write_debug,
};
+#endif /* ifndef INCLUDE_MGMTD_CMDDEFS_ONLY */
+
void static_vty_init(void)
{
+#ifndef INCLUDE_MGMTD_CMDDEFS_ONLY
install_node(&debug_node);
+ install_element(ENABLE_NODE, &show_debugging_static_cmd);
+ install_element(ENABLE_NODE, &staticd_show_bfd_routes_cmd);
+#endif /* ifndef INCLUDE_MGMTD_CMDDEFS_ONLY */
install_element(CONFIG_NODE, &ip_mroute_dist_cmd);
@@ -1516,9 +1551,6 @@ void static_vty_init(void)
install_element(CONFIG_NODE, &ipv6_route_cmd);
install_element(VRF_NODE, &ipv6_route_vrf_cmd);
- install_element(ENABLE_NODE, &show_debugging_static_cmd);
install_element(ENABLE_NODE, &debug_staticd_cmd);
install_element(CONFIG_NODE, &debug_staticd_cmd);
-
- install_element(ENABLE_NODE, &staticd_show_bfd_routes_cmd);
}
diff --git a/staticd/static_zebra.c b/staticd/static_zebra.c
index f220b476fb..4f3ccde53d 100644
--- a/staticd/static_zebra.c
+++ b/staticd/static_zebra.c
@@ -6,7 +6,7 @@
*/
#include <zebra.h>
-#include "thread.h"
+#include "frrevent.h"
#include "command.h"
#include "network.h"
#include "prefix.h"
diff --git a/staticd/static_zebra.h b/staticd/static_zebra.h
index 5f21d6c386..c4f4ebdcbc 100644
--- a/staticd/static_zebra.h
+++ b/staticd/static_zebra.h
@@ -11,7 +11,7 @@
extern "C" {
#endif
-extern struct thread_master *master;
+extern struct event_loop *master;
extern void static_zebra_nht_register(struct static_nexthop *nh, bool reg);
diff --git a/tests/bgpd/test_aspath.c b/tests/bgpd/test_aspath.c
index 926097f571..57aa2af9de 100644
--- a/tests/bgpd/test_aspath.c
+++ b/tests/bgpd/test_aspath.c
@@ -26,7 +26,7 @@
/* need these to link in libbgp */
struct zebra_privs_t bgpd_privs = {};
-struct thread_master *master = NULL;
+struct event_loop *master = NULL;
static int failed = 0;
@@ -1405,7 +1405,7 @@ int main(void)
{
int i = 0;
qobj_init();
- bgp_master_init(thread_master_create(NULL), BGP_SOCKET_SNDBUF_SIZE,
+ bgp_master_init(event_master_create(NULL), BGP_SOCKET_SNDBUF_SIZE,
list_new());
master = bm->master;
bgp_option_set(BGP_OPT_NO_LISTEN);
diff --git a/tests/bgpd/test_capability.c b/tests/bgpd/test_capability.c
index 8ef5748671..da17471fd1 100644
--- a/tests/bgpd/test_capability.c
+++ b/tests/bgpd/test_capability.c
@@ -30,7 +30,7 @@
/* need these to link in libbgp */
struct zebra_privs_t bgpd_privs = {};
-struct thread_master *master = NULL;
+struct event_loop *master = NULL;
static int failed = 0;
static int tty = 0;
@@ -925,7 +925,7 @@ int main(void)
term_bgp_debug_as4 = -1UL;
qobj_init();
- master = thread_master_create(NULL);
+ master = event_master_create(NULL);
bgp_master_init(master, BGP_SOCKET_SNDBUF_SIZE, list_new());
vrf_init(NULL, NULL, NULL, NULL);
bgp_option_set(BGP_OPT_NO_LISTEN);
diff --git a/tests/bgpd/test_ecommunity.c b/tests/bgpd/test_ecommunity.c
index bb360722c8..49322d3e2d 100644
--- a/tests/bgpd/test_ecommunity.c
+++ b/tests/bgpd/test_ecommunity.c
@@ -16,7 +16,7 @@
/* need these to link in libbgp */
struct zebra_privs_t bgpd_privs = {};
-struct thread_master *master = NULL;
+struct event_loop *master = NULL;
static int failed = 0;
diff --git a/tests/bgpd/test_mp_attr.c b/tests/bgpd/test_mp_attr.c
index b1f3314f1f..ae7903e0cc 100644
--- a/tests/bgpd/test_mp_attr.c
+++ b/tests/bgpd/test_mp_attr.c
@@ -35,7 +35,7 @@
/* need these to link in libbgp */
struct zebra_privs_t bgpd_privs = {};
-struct thread_master *master = NULL;
+struct event_loop *master = NULL;
static int failed = 0;
static int tty = 0;
@@ -1042,9 +1042,9 @@ static void parse_test(struct peer *peer, struct test_segment *t, int type)
if (!parse_ret) {
if (type == BGP_ATTR_MP_REACH_NLRI)
- nlri_ret = bgp_nlri_parse(peer, &attr, &nlri, 0);
+ nlri_ret = bgp_nlri_parse(peer, &attr, &nlri, false);
else if (type == BGP_ATTR_MP_UNREACH_NLRI)
- nlri_ret = bgp_nlri_parse(peer, &attr, &nlri, 1);
+ nlri_ret = bgp_nlri_parse(peer, &attr, &nlri, true);
}
handle_result(peer, t, parse_ret, nlri_ret);
}
@@ -1070,7 +1070,7 @@ int main(void)
qobj_init();
cmd_init(0);
bgp_vty_init();
- master = thread_master_create("test mp attr");
+ master = event_master_create("test mp attr");
bgp_master_init(master, BGP_SOCKET_SNDBUF_SIZE, list_new());
vrf_init(NULL, NULL, NULL, NULL);
bgp_option_set(BGP_OPT_NO_LISTEN);
diff --git a/tests/bgpd/test_mpath.c b/tests/bgpd/test_mpath.c
index 3662805971..0124ad9b22 100644
--- a/tests/bgpd/test_mpath.c
+++ b/tests/bgpd/test_mpath.c
@@ -61,7 +61,7 @@ struct testcase_t__ {
};
/* need these to link in libbgp */
-struct thread_master *master = NULL;
+struct event_loop *master = NULL;
extern struct zclient *zclient;
struct zebra_privs_t bgpd_privs = {
.user = NULL,
@@ -378,7 +378,7 @@ int all_tests_count = array_size(all_tests);
static int global_test_init(void)
{
qobj_init();
- master = thread_master_create(NULL);
+ master = event_master_create(NULL);
zclient = zclient_new(master, &zclient_options_default, NULL, 0);
bgp_master_init(master, BGP_SOCKET_SNDBUF_SIZE, list_new());
vrf_init(NULL, NULL, NULL, NULL);
@@ -393,7 +393,7 @@ static int global_test_cleanup(void)
{
if (zclient != NULL)
zclient_free(zclient);
- thread_master_free(master);
+ event_master_free(master);
return 0;
}
diff --git a/tests/bgpd/test_packet.c b/tests/bgpd/test_packet.c
index aeebbd9a35..94c3feaa93 100644
--- a/tests/bgpd/test_packet.c
+++ b/tests/bgpd/test_packet.c
@@ -25,7 +25,7 @@
/* need these to link in libbgp */
struct zebra_privs_t bgpd_privs = {};
-struct thread_master *master = NULL;
+struct event_loop *master = NULL;
static struct bgp *bgp;
static as_t asn = 100;
@@ -41,11 +41,11 @@ int main(int argc, char *argv[])
{
struct peer *peer;
int i, j;
- struct thread t;
+ struct event t;
qobj_init();
bgp_attr_init();
- master = thread_master_create(NULL);
+ master = event_master_create(NULL);
bgp_master_init(master, BGP_SOCKET_SNDBUF_SIZE, list_new());
vrf_init(NULL, NULL, NULL, NULL);
bgp_option_set(BGP_OPT_NO_LISTEN);
diff --git a/tests/bgpd/test_peer_attr.c b/tests/bgpd/test_peer_attr.c
index dde38c8693..bc6eba9069 100644
--- a/tests/bgpd/test_peer_attr.c
+++ b/tests/bgpd/test_peer_attr.c
@@ -106,7 +106,7 @@
/* Required variables to link in libbgp */
struct zebra_privs_t bgpd_privs = {0};
-struct thread_master *master;
+struct event_loop *master;
enum test_state {
TEST_SUCCESS,
@@ -1363,7 +1363,7 @@ static void bgp_startup(void)
zprivs_preinit(&bgpd_privs);
zprivs_init(&bgpd_privs);
- master = thread_master_create(NULL);
+ master = event_master_create(NULL);
nb_init(master, NULL, 0, false);
bgp_master_init(master, BGP_SOCKET_SNDBUF_SIZE, list_new());
bgp_option_set(BGP_OPT_NO_LISTEN);
@@ -1412,7 +1412,7 @@ static void bgp_shutdown(void)
nb_terminate();
yang_terminate();
zprivs_terminate(&bgpd_privs);
- thread_master_free(master);
+ event_master_free(master);
master = NULL;
}
diff --git a/tests/helpers/c/main.c b/tests/helpers/c/main.c
index bb8acd2c44..cd2b5665e2 100644
--- a/tests/helpers/c/main.c
+++ b/tests/helpers/c/main.c
@@ -6,7 +6,7 @@
#include <lib/version.h>
#include "getopt.h"
-#include "thread.h"
+#include "frrevent.h"
#include "vty.h"
#include "command.h"
#include "memory.h"
@@ -14,7 +14,7 @@
extern void test_init(void);
-struct thread_master *master;
+struct event_loop *master;
struct option longopts[] = {{"daemon", no_argument, NULL, 'd'},
{"config_file", required_argument, NULL, 'f'},
@@ -33,17 +33,17 @@ DEFUN (daemon_exit,
}
static int timer_count;
-static void test_timer(struct thread *thread)
+static void test_timer(struct event *thread)
{
- int *count = THREAD_ARG(thread);
+ int *count = EVENT_ARG(thread);
printf("run %d of timer\n", (*count)++);
- thread_add_timer(master, test_timer, count, 5, NULL);
+ event_add_timer(master, test_timer, count, 5, NULL);
}
static void test_timer_init(void)
{
- thread_add_timer(master, test_timer, &timer_count, 10, NULL);
+ event_add_timer(master, test_timer, &timer_count, 10, NULL);
}
static void test_vty_init(void)
@@ -82,7 +82,7 @@ int main(int argc, char **argv)
int vty_port = 4000;
int daemon_mode = 0;
char *progname;
- struct thread thread;
+ struct event thread;
char *config_file = NULL;
/* Set umask before anything for security */
@@ -92,7 +92,7 @@ int main(int argc, char **argv)
progname = ((p = strrchr(argv[0], '/')) ? ++p : argv[0]);
/* master init. */
- master = thread_master_create(NULL);
+ master = event_master_create(NULL);
while (1) {
int opt;
@@ -164,8 +164,8 @@ int main(int argc, char **argv)
test_init();
/* Fetch next active thread. */
- while (thread_fetch(master, &thread))
- thread_call(&thread);
+ while (event_fetch(master, &thread))
+ event_call(&thread);
/* Not reached. */
exit(0);
diff --git a/tests/isisd/test_common.c b/tests/isisd/test_common.c
index 0f37752ce2..d0288f600d 100644
--- a/tests/isisd/test_common.c
+++ b/tests/isisd/test_common.c
@@ -12,7 +12,7 @@
#include "test_common.h"
-struct thread_master *master;
+struct event_loop *master;
struct zebra_privs_t isisd_privs;
int isis_sock_init(struct isis_circuit *circuit)
diff --git a/tests/isisd/test_common.h b/tests/isisd/test_common.h
index 9b83b30ba7..f0c5493c9d 100644
--- a/tests/isisd/test_common.h
+++ b/tests/isisd/test_common.h
@@ -65,7 +65,7 @@ extern int test_topology_load(const struct isis_topology *topology,
struct lspdb_head lspdb[]);
/* Global variables. */
-extern struct thread_master *master;
+extern struct event_loop *master;
extern struct zebra_privs_t isisd_privs;
extern struct isis_topology test_topologies[];
diff --git a/tests/isisd/test_fuzz_isis_tlv.c b/tests/isisd/test_fuzz_isis_tlv.c
index 8f0b92d0fc..627ccfee6f 100644
--- a/tests/isisd/test_fuzz_isis_tlv.c
+++ b/tests/isisd/test_fuzz_isis_tlv.c
@@ -9,7 +9,7 @@
#include "memory.h"
#include "sbuf.h"
#include "stream.h"
-#include "thread.h"
+#include "frrevent.h"
#include "isisd/isis_circuit.h"
#include "isisd/isis_tlvs.h"
diff --git a/tests/isisd/test_isis_spf.c b/tests/isisd/test_isis_spf.c
index 0cccf05678..85ddfea5b5 100644
--- a/tests/isisd/test_isis_spf.c
+++ b/tests/isisd/test_isis_spf.c
@@ -8,7 +8,7 @@
#include <lib/version.h>
#include "getopt.h"
-#include "thread.h"
+#include "frrevent.h"
#include "vty.h"
#include "command.h"
#include "log.h"
@@ -455,7 +455,7 @@ static void vty_do_exit(int isexit)
cmd_terminate();
vty_terminate();
yang_terminate();
- thread_master_free(master);
+ event_master_free(master);
log_memstats(stderr, "test-isis-spf");
if (!isexit)
@@ -488,7 +488,7 @@ int main(int argc, char **argv)
{
char *p;
char *progname;
- struct thread thread;
+ struct event thread;
bool debug = false;
/* Set umask before anything for security */
@@ -521,7 +521,7 @@ int main(int argc, char **argv)
}
/* master init. */
- master = thread_master_create(NULL);
+ master = event_master_create(NULL);
isis_master_init(master);
/* Library inits. */
@@ -549,8 +549,8 @@ int main(int argc, char **argv)
vty_stdio(vty_do_exit);
/* Fetch next active thread. */
- while (thread_fetch(master, &thread))
- thread_call(&thread);
+ while (event_fetch(master, &thread))
+ event_call(&thread);
/* Not reached. */
exit(0);
diff --git a/tests/lib/cli/common_cli.c b/tests/lib/cli/common_cli.c
index 29dad7d80f..e0981b991a 100644
--- a/tests/lib/cli/common_cli.c
+++ b/tests/lib/cli/common_cli.c
@@ -8,7 +8,7 @@
#include <zebra.h>
-#include "thread.h"
+#include "frrevent.h"
#include "vty.h"
#include "command.h"
#include "memory.h"
@@ -17,7 +17,7 @@
#include "common_cli.h"
-struct thread_master *master;
+struct event_loop *master;
int dump_args(struct vty *vty, const char *descr, int argc,
struct cmd_token *argv[])
@@ -39,7 +39,7 @@ static void vty_do_exit(int isexit)
vty_terminate();
nb_terminate();
yang_terminate();
- thread_master_free(master);
+ event_master_free(master);
log_memstats(stderr, "testcli");
if (!isexit)
@@ -52,14 +52,14 @@ int test_log_prio = ZLOG_DISABLED;
/* main routine. */
int main(int argc, char **argv)
{
- struct thread thread;
+ struct event thread;
size_t yangcount;
/* Set umask before anything for security */
umask(0027);
/* master init. */
- master = thread_master_create(NULL);
+ master = event_master_create(NULL);
zlog_aux_init("NONE: ", test_log_prio);
@@ -81,8 +81,8 @@ int main(int argc, char **argv)
vty_stdio(vty_do_exit);
/* Fetch next active thread. */
- while (thread_fetch(master, &thread))
- thread_call(&thread);
+ while (event_fetch(master, &thread))
+ event_call(&thread);
/* Not reached. */
exit(0);
diff --git a/tests/lib/cli/common_cli.h b/tests/lib/cli/common_cli.h
index 7ef4d860bd..4a1de940df 100644
--- a/tests/lib/cli/common_cli.h
+++ b/tests/lib/cli/common_cli.h
@@ -22,7 +22,7 @@ extern void test_init(int argc, char **argv);
/* functions provided by common cli
* (includes main())
*/
-extern struct thread_master *master;
+extern struct event_loop *master;
extern int test_log_prio;
diff --git a/tests/lib/cli/test_commands.c b/tests/lib/cli/test_commands.c
index 54db795757..ea84120fc1 100644
--- a/tests/lib/cli/test_commands.c
+++ b/tests/lib/cli/test_commands.c
@@ -30,7 +30,7 @@ extern vector cmdvec;
extern struct cmd_node vty_node;
extern void test_init_cmd(void); /* provided in test-commands-defun.c */
-struct thread_master *master; /* dummy for libfrr*/
+struct event_loop *master; /* dummy for libfrr*/
static vector test_cmds;
static char test_buf[32768];
diff --git a/tests/lib/cxxcompat.c b/tests/lib/cxxcompat.c
index 7aab88eeb9..4ad41fca42 100644
--- a/tests/lib/cxxcompat.c
+++ b/tests/lib/cxxcompat.c
@@ -25,7 +25,6 @@
#include "lib/frr_pthread.h"
#include "lib/frratomic.h"
#include "lib/frrstr.h"
-#include "lib/getopt.h"
#include "lib/graph.h"
#include "lib/hash.h"
#include "lib/hook.h"
@@ -78,7 +77,7 @@
#include "lib/stream.h"
#include "lib/table.h"
#include "lib/termtable.h"
-#include "lib/thread.h"
+#include "frrevent.h"
#include "lib/typesafe.h"
#include "lib/typerb.h"
#include "lib/vector.h"
diff --git a/tests/lib/fuzz_zlog.c b/tests/lib/fuzz_zlog.c
index ad9677a718..d308f8eb2f 100644
--- a/tests/lib/fuzz_zlog.c
+++ b/tests/lib/fuzz_zlog.c
@@ -94,7 +94,7 @@ int main(int argc, char **argv)
cfg->fd = fd;
cmd_hostname_set("TEST");
- cfg->master = thread_master_create("TEST");
+ cfg->master = event_master_create("TEST");
zlog_5424_apply_dst(cfg);
diff --git a/tests/lib/northbound/test_oper_data.c b/tests/lib/northbound/test_oper_data.c
index 3abda75f40..f82eddd3bf 100644
--- a/tests/lib/northbound/test_oper_data.c
+++ b/tests/lib/northbound/test_oper_data.c
@@ -6,7 +6,7 @@
#include <zebra.h>
-#include "thread.h"
+#include "frrevent.h"
#include "vty.h"
#include "command.h"
#include "memory.h"
@@ -14,7 +14,7 @@
#include "log.h"
#include "northbound.h"
-static struct thread_master *master;
+static struct event_loop *master;
struct troute {
struct prefix_ipv4 prefix;
@@ -351,7 +351,7 @@ static void vty_do_exit(int isexit)
vty_terminate();
nb_terminate();
yang_terminate();
- thread_master_free(master);
+ event_master_free(master);
log_memstats(stderr, "test-nb-oper-data");
if (!isexit)
@@ -361,7 +361,7 @@ static void vty_do_exit(int isexit)
/* main routine. */
int main(int argc, char **argv)
{
- struct thread thread;
+ struct event thread;
unsigned int num_vrfs = 2;
unsigned int num_interfaces = 4;
unsigned int num_routes = 6;
@@ -377,7 +377,7 @@ int main(int argc, char **argv)
umask(0027);
/* master init. */
- master = thread_master_create(NULL);
+ master = event_master_create(NULL);
zlog_aux_init("NONE: ", ZLOG_DISABLED);
@@ -395,8 +395,8 @@ int main(int argc, char **argv)
vty_stdio(vty_do_exit);
/* Fetch next active thread. */
- while (thread_fetch(master, &thread))
- thread_call(&thread);
+ while (event_fetch(master, &thread))
+ event_call(&thread);
/* Not reached. */
exit(0);
diff --git a/tests/lib/subdir.am b/tests/lib/subdir.am
index 1bc092a49e..e950d0120d 100644
--- a/tests/lib/subdir.am
+++ b/tests/lib/subdir.am
@@ -15,7 +15,7 @@ tests_lib_test_frrscript_CFLAGS = $(TESTS_CFLAGS)
tests_lib_test_frrscript_CPPFLAGS = $(TESTS_CPPFLAGS)
tests_lib_test_frrscript_LDADD = $(ALL_TESTS_LDADD)
tests_lib_test_frrscript_SOURCES = tests/lib/test_frrscript.c
-EXTRA_DIST += tests/lib/test_frrscript.py
+EXTRA_DIST += tests/lib/test_frrscript.py tests/lib/script1.lua
##############################################################################
diff --git a/tests/lib/test_assert.c b/tests/lib/test_assert.c
index d68ee8a819..4440075b41 100644
--- a/tests/lib/test_assert.c
+++ b/tests/lib/test_assert.c
@@ -22,13 +22,13 @@ static void func_for_bt(int number)
#include <zebra.h>
#include "lib/zlog.h"
-#include "lib/thread.h"
+#include "frrevent.h"
#include "lib/sigevent.h"
int main(int argc, char **argv)
{
int number = 10;
- struct thread_master *master;
+ struct event_loop *master;
zlog_aux_init("NONE: ", LOG_DEBUG);
@@ -39,7 +39,7 @@ int main(int argc, char **argv)
assertf(number > 1, "(B) the number was %d", number);
/* set up SIGABRT handler */
- master = thread_master_create("test");
+ master = event_master_create("test");
signal_init(master, 0, NULL);
func_for_bt(number);
diff --git a/tests/lib/test_buffer.c b/tests/lib/test_buffer.c
index 9f501f4e35..bfb4600848 100644
--- a/tests/lib/test_buffer.c
+++ b/tests/lib/test_buffer.c
@@ -8,7 +8,7 @@
#include <lib_vty.h>
#include <buffer.h>
-struct thread_master *master;
+struct event_loop *master;
int main(int argc, char **argv)
{
diff --git a/tests/lib/test_checksum.c b/tests/lib/test_checksum.c
index fcb79ee28d..329ae6087e 100644
--- a/tests/lib/test_checksum.c
+++ b/tests/lib/test_checksum.c
@@ -11,7 +11,7 @@
#include "network.h"
#include "prng.h"
-struct thread_master *master;
+struct event_loop *master;
struct acc_vals {
int c0;
diff --git a/tests/lib/test_grpc.cpp b/tests/lib/test_grpc.cpp
index 282161c3df..fd30f04346 100644
--- a/tests/lib/test_grpc.cpp
+++ b/tests/lib/test_grpc.cpp
@@ -14,7 +14,7 @@
#include "libfrr.h"
#include "routing_nb.h"
#include "northbound_cli.h"
-#include "thread.h"
+#include "frrevent.h"
#include "vrf.h"
#include "vty.h"
@@ -34,13 +34,13 @@
#include <grpcpp/security/credentials.h>
#include "grpc/frr-northbound.grpc.pb.h"
-DEFINE_HOOK(frr_late_init, (struct thread_master * tm), (tm));
+DEFINE_HOOK(frr_late_init, (struct event_loop * tm), (tm));
DEFINE_KOOH(frr_fini, (), ());
struct vty *vty;
bool mpls_enabled;
-struct thread_master *master;
+struct event_loop *master;
struct zebra_privs_t static_privs = {0};
struct frrmod_runtime *grpc_module;
char binpath[2 * MAXPATHLEN + 1];
@@ -66,7 +66,7 @@ static const struct frr_yang_module_info *const staticd_yang_modules[] = {
&frr_staticd_info, &frr_vrf_info,
};
-static void grpc_thread_stop(struct thread *thread);
+static void grpc_thread_stop(struct event *thread);
static void _err_print(const void *cookie, const char *errstr)
{
@@ -97,7 +97,7 @@ static void static_startup(void)
static_debug_init();
- master = thread_master_create(NULL);
+ master = event_master_create(NULL);
nb_init(master, staticd_yang_modules, array_size(staticd_yang_modules),
false);
@@ -139,7 +139,7 @@ static void static_shutdown(void)
cmd_terminate();
nb_terminate();
yang_terminate();
- thread_master_free(master);
+ event_master_free(master);
master = NULL;
}
@@ -479,14 +479,14 @@ void *grpc_client_test_start(void *arg)
// Signal FRR event loop to stop
test_debug("client: pthread: adding event to stop us");
- thread_add_event(master, grpc_thread_stop, NULL, 0, NULL);
+ event_add_event(master, grpc_thread_stop, NULL, 0, NULL);
test_debug("client: pthread: DONE (returning)");
return NULL;
}
-static void grpc_thread_start(struct thread *thread)
+static void grpc_thread_start(struct event *thread)
{
struct frr_pthread_attr client = {
.start = grpc_client_test_start,
@@ -498,7 +498,7 @@ static void grpc_thread_start(struct thread *thread)
frr_pthread_wait_running(pth);
}
-static void grpc_thread_stop(struct thread *thread)
+static void grpc_thread_stop(struct event *thread)
{
std::cout << __func__ << ": frr_pthread_stop_all" << std::endl;
frr_pthread_stop_all();
@@ -542,12 +542,12 @@ int main(int argc, char **argv)
static_startup();
- thread_add_event(master, grpc_thread_start, NULL, 0, NULL);
+ event_add_event(master, grpc_thread_start, NULL, 0, NULL);
/* Event Loop */
- struct thread thread;
- while (thread_fetch(master, &thread))
- thread_call(&thread);
+ struct event thread;
+ while (event_fetch(master, &thread))
+ event_call(&thread);
return 0;
}
diff --git a/tests/lib/test_heavy.c b/tests/lib/test_heavy.c
index 2d54fe6c68..1e56940831 100644
--- a/tests/lib/test_heavy.c
+++ b/tests/lib/test_heavy.c
@@ -13,7 +13,7 @@
*/
#include <zebra.h>
-#include "thread.h"
+#include "frrevent.h"
#include "vty.h"
#include "command.h"
#include "memory.h"
diff --git a/tests/lib/test_heavy_thread.c b/tests/lib/test_heavy_thread.c
index afbd205451..4fb9ebfa3a 100644
--- a/tests/lib/test_heavy_thread.c
+++ b/tests/lib/test_heavy_thread.c
@@ -14,7 +14,7 @@
#include <zebra.h>
#include <math.h>
-#include "thread.h"
+#include "frrevent.h"
#include "vty.h"
#include "command.h"
#include "memory.h"
@@ -22,7 +22,7 @@
#include "tests.h"
-extern struct thread_master *master;
+extern struct event_loop *master;
enum { ITERS_FIRST = 0,
ITERS_ERR = 100,
@@ -56,9 +56,9 @@ static void slow_func(struct vty *vty, const char *str, const int i)
printf("%s did %d, x = %g\n", str, i, x);
}
-static void clear_something(struct thread *thread)
+static void clear_something(struct event *thread)
{
- struct work_state *ws = THREAD_ARG(thread);
+ struct work_state *ws = EVENT_ARG(thread);
/* this could be like iterating through 150k of route_table
* or worse, iterating through a list of peers, to bgp_stop them with
@@ -67,9 +67,9 @@ static void clear_something(struct thread *thread)
while (ws->i < ITERS_MAX) {
slow_func(ws->vty, ws->str, ws->i);
ws->i++;
- if (thread_should_yield(thread)) {
- thread_add_timer_msec(master, clear_something, ws, 0,
- NULL);
+ if (event_should_yield(thread)) {
+ event_add_timer_msec(master, clear_something, ws, 0,
+ NULL);
return;
}
}
@@ -102,7 +102,7 @@ DEFUN (clear_foo,
ws->vty = vty;
ws->i = ITERS_FIRST;
- thread_add_timer_msec(master, clear_something, ws, 0, NULL);
+ event_add_timer_msec(master, clear_something, ws, 0, NULL);
return CMD_SUCCESS;
}
diff --git a/tests/lib/test_heavy_wq.c b/tests/lib/test_heavy_wq.c
index 9b2cfa5730..225573ae92 100644
--- a/tests/lib/test_heavy_wq.c
+++ b/tests/lib/test_heavy_wq.c
@@ -13,7 +13,7 @@
*/
#include <zebra.h>
-#include "thread.h"
+#include "frrevent.h"
#include "vty.h"
#include "command.h"
#include "memory.h"
@@ -27,7 +27,7 @@ DEFINE_MGROUP(TEST_HEAVYWQ, "heavy-wq test");
DEFINE_MTYPE_STATIC(TEST_HEAVYWQ, WQ_NODE, "heavy_wq_node");
DEFINE_MTYPE_STATIC(TEST_HEAVYWQ, WQ_NODE_STR, "heavy_wq_node->str");
-extern struct thread_master *master;
+extern struct event_loop *master;
static struct work_queue *heavy_wq;
struct heavy_wq_node {
diff --git a/tests/lib/test_memory.c b/tests/lib/test_memory.c
index e4423b0b5b..aba4c3589c 100644
--- a/tests/lib/test_memory.c
+++ b/tests/lib/test_memory.c
@@ -15,7 +15,7 @@ DEFINE_MTYPE_STATIC(TEST_MEMORY, TEST, "generic test mtype");
* CVS
*/
-struct thread_master *master;
+struct event_loop *master;
#if 0 /* set to 1 to use system alloc directly */
#undef XMALLOC
diff --git a/tests/lib/test_nexthop_iter.c b/tests/lib/test_nexthop_iter.c
index 2bb0b1233c..91380f1111 100644
--- a/tests/lib/test_nexthop_iter.c
+++ b/tests/lib/test_nexthop_iter.c
@@ -13,7 +13,7 @@
#include "zebra/rib.h"
#include "prng.h"
-struct thread_master *master;
+struct event_loop *master;
static int verbose;
static void str_append(char **buf, const char *repr)
diff --git a/tests/lib/test_privs.c b/tests/lib/test_privs.c
index d7bc0b3153..e26754857b 100644
--- a/tests/lib/test_privs.c
+++ b/tests/lib/test_privs.c
@@ -50,7 +50,7 @@ Report bugs to %s\n",
exit(status);
}
-struct thread_master *master;
+struct event_loop *master;
/* main routine. */
int main(int argc, char **argv)
{
diff --git a/tests/lib/test_resolver.c b/tests/lib/test_resolver.c
index b4d8992b95..d72ff4f5a1 100644
--- a/tests/lib/test_resolver.c
+++ b/tests/lib/test_resolver.c
@@ -26,7 +26,7 @@
#include "tests/lib/cli/common_cli.h"
-extern struct thread_master *master;
+extern struct event_loop *master;
static void resolver_result(struct resolver_query *resq, const char *errstr,
int numaddrs, union sockunion *addr)
diff --git a/tests/lib/test_segv.c b/tests/lib/test_segv.c
index 8532da7c2d..af5f3aec63 100644
--- a/tests/lib/test_segv.c
+++ b/tests/lib/test_segv.c
@@ -17,7 +17,7 @@
struct frr_signal_t sigs[] = {};
-struct thread_master *master;
+struct event_loop *master;
void func1(int *arg);
void func3(void);
@@ -49,19 +49,19 @@ void func3(void)
func2(6, buf);
}
-static void threadfunc(struct thread *thread)
+static void threadfunc(struct event *thread)
{
func3();
}
int main(void)
{
- master = thread_master_create(NULL);
+ master = event_master_create(NULL);
signal_init(master, array_size(sigs), sigs);
zlog_aux_init("NONE: ", LOG_DEBUG);
- thread_execute(master, threadfunc, 0, 0);
+ event_execute(master, threadfunc, 0, 0);
exit(0);
}
diff --git a/tests/lib/test_sig.c b/tests/lib/test_sig.c
index 897e004b40..2bd7f30976 100644
--- a/tests/lib/test_sig.c
+++ b/tests/lib/test_sig.c
@@ -35,18 +35,18 @@ struct frr_signal_t sigs[] = {{
.handler = &sigusr2,
}};
-struct thread_master *master;
-struct thread t;
+struct event_loop *master;
+struct event t;
int main(void)
{
- master = thread_master_create(NULL);
+ master = event_master_create(NULL);
signal_init(master, array_size(sigs), sigs);
zlog_aux_init("NONE: ", LOG_DEBUG);
- while (thread_fetch(master, &t))
- thread_call(&t);
+ while (event_fetch(master, &t))
+ event_call(&t);
exit(0);
}
diff --git a/tests/lib/test_srcdest_table.c b/tests/lib/test_srcdest_table.c
index de0482d694..6d6c5156a7 100644
--- a/tests/lib/test_srcdest_table.c
+++ b/tests/lib/test_srcdest_table.c
@@ -24,7 +24,7 @@
#define s6_addr32 __u6_addr.__u6_addr32
#endif /*s6_addr32*/
-struct thread_master *master;
+struct event_loop *master;
/* This structure is copied from lib/srcdest_table.c to which it is
* private as far as other parts of Quagga are concerned.
@@ -121,8 +121,7 @@ static struct test_state *test_state_new(void)
static void test_state_free(struct test_state *test)
{
route_table_finish(test->table);
- hash_clean(test->log, log_free);
- hash_free(test->log);
+ hash_clean_and_free(&test->log, log_free);
XFREE(MTYPE_TMP, test);
}
diff --git a/tests/lib/test_stream.c b/tests/lib/test_stream.c
index 015dc41db1..d38dfe0eb0 100644
--- a/tests/lib/test_stream.c
+++ b/tests/lib/test_stream.c
@@ -6,12 +6,12 @@
#include <zebra.h>
#include <stream.h>
-#include <thread.h>
+#include "frrevent.h"
#include "printfrr.h"
static unsigned long long ham = 0xdeadbeefdeadbeef;
-struct thread_master *master;
+struct event_loop *master;
static void print_stream(struct stream *s)
{
diff --git a/tests/lib/test_table.c b/tests/lib/test_table.c
index 41d7003956..51bfda2345 100644
--- a/tests/lib/test_table.c
+++ b/tests/lib/test_table.c
@@ -25,7 +25,7 @@ typedef struct test_node_t_ {
char *prefix_str;
} test_node_t;
-struct thread_master *master;
+struct event_loop *master;
/*
* add_node
diff --git a/tests/lib/test_timer_correctness.c b/tests/lib/test_timer_correctness.c
index 37eb4939a1..04c0516889 100644
--- a/tests/lib/test_timer_correctness.c
+++ b/tests/lib/test_timer_correctness.c
@@ -16,14 +16,14 @@
#include "memory.h"
#include "prng.h"
-#include "thread.h"
+#include "frrevent.h"
#define SCHEDULE_TIMERS 800
#define REMOVE_TIMERS 200
#define TIMESTR_LEN strlen("4294967296.999999")
-struct thread_master *master;
+struct event_loop *master;
static size_t log_buf_len;
static size_t log_buf_pos;
@@ -35,7 +35,7 @@ static char *expected_buf;
static struct prng *prng;
-static struct thread **timers;
+static struct event **timers;
static int timers_pending;
@@ -54,7 +54,7 @@ static void terminate_test(void)
exit_code = 0;
}
- thread_master_free(master);
+ event_master_free(master);
XFREE(MTYPE_TMP, log_buf);
XFREE(MTYPE_TMP, expected_buf);
prng_free(prng);
@@ -63,7 +63,7 @@ static void terminate_test(void)
exit(exit_code);
}
-static void timer_func(struct thread *thread)
+static void timer_func(struct event *thread)
{
int rv;
@@ -94,10 +94,10 @@ static int cmp_timeval(const void *a, const void *b)
int main(int argc, char **argv)
{
int i, j;
- struct thread t;
+ struct event t;
struct timeval **alarms;
- master = thread_master_create(NULL);
+ master = event_master_create(NULL);
log_buf_len = SCHEDULE_TIMERS * (TIMESTR_LEN + 1) + 1;
log_buf_pos = 0;
@@ -119,8 +119,8 @@ int main(int argc, char **argv)
/* Schedule timers to expire in 0..5 seconds */
interval_msec = prng_rand(prng) % 5000;
arg = XMALLOC(MTYPE_TMP, TIMESTR_LEN + 1);
- thread_add_timer_msec(master, timer_func, arg, interval_msec,
- &timers[i]);
+ event_add_timer_msec(master, timer_func, arg, interval_msec,
+ &timers[i]);
ret = snprintf(arg, TIMESTR_LEN + 1, "%lld.%06lld",
(long long)timers[i]->u.sands.tv_sec,
(long long)timers[i]->u.sands.tv_usec);
@@ -137,7 +137,7 @@ int main(int argc, char **argv)
continue;
XFREE(MTYPE_TMP, timers[index]->arg);
- thread_cancel(&timers[index]);
+ event_cancel(&timers[index]);
timers_pending--;
}
@@ -166,8 +166,8 @@ int main(int argc, char **argv)
}
XFREE(MTYPE_TMP, alarms);
- while (thread_fetch(master, &t))
- thread_call(&t);
+ while (event_fetch(master, &t))
+ event_call(&t);
return 0;
}
diff --git a/tests/lib/test_timer_performance.c b/tests/lib/test_timer_performance.c
index 21976e8d31..3ace076b43 100644
--- a/tests/lib/test_timer_performance.c
+++ b/tests/lib/test_timer_performance.c
@@ -14,15 +14,15 @@
#include <stdio.h>
#include <unistd.h>
-#include "thread.h"
+#include "frrevent.h"
#include "prng.h"
#define SCHEDULE_TIMERS 1000000
#define REMOVE_TIMERS 500000
-struct thread_master *master;
+struct event_loop *master;
-static void dummy_func(struct thread *thread)
+static void dummy_func(struct event *thread)
{
}
@@ -30,21 +30,21 @@ int main(int argc, char **argv)
{
struct prng *prng;
int i;
- struct thread **timers;
+ struct event **timers;
struct timeval tv_start, tv_lap, tv_stop;
unsigned long t_schedule, t_remove;
- master = thread_master_create(NULL);
+ master = event_master_create(NULL);
prng = prng_new(0);
timers = calloc(SCHEDULE_TIMERS, sizeof(*timers));
/* create thread structures so they won't be allocated during the
* time measurement */
for (i = 0; i < SCHEDULE_TIMERS; i++) {
- thread_add_timer_msec(master, dummy_func, NULL, 0, &timers[i]);
+ event_add_timer_msec(master, dummy_func, NULL, 0, &timers[i]);
}
for (i = 0; i < SCHEDULE_TIMERS; i++)
- thread_cancel(&timers[i]);
+ event_cancel(&timers[i]);
monotime(&tv_start);
@@ -52,8 +52,8 @@ int main(int argc, char **argv)
long interval_msec;
interval_msec = prng_rand(prng) % (100 * SCHEDULE_TIMERS);
- thread_add_timer_msec(master, dummy_func, NULL, interval_msec,
- &timers[i]);
+ event_add_timer_msec(master, dummy_func, NULL, interval_msec,
+ &timers[i]);
}
monotime(&tv_lap);
@@ -62,7 +62,7 @@ int main(int argc, char **argv)
int index;
index = prng_rand(prng) % SCHEDULE_TIMERS;
- thread_cancel(&timers[index]);
+ event_cancel(&timers[index]);
}
monotime(&tv_stop);
@@ -80,7 +80,7 @@ int main(int argc, char **argv)
fflush(stdout);
free(timers);
- thread_master_free(master);
+ event_master_free(master);
prng_free(prng);
return 0;
}
diff --git a/tests/lib/test_zmq.c b/tests/lib/test_zmq.c
index 59a596e1c8..2cd9d47cb4 100644
--- a/tests/lib/test_zmq.c
+++ b/tests/lib/test_zmq.c
@@ -12,7 +12,7 @@
DEFINE_MTYPE_STATIC(LIB, TESTBUF, "zmq test buffer");
DEFINE_MTYPE_STATIC(LIB, ZMQMSG, "zmq message");
-static struct thread_master *master;
+static struct event_loop *master;
static void msg_buf_free(void *data, void *hint)
{
@@ -212,8 +212,8 @@ static void serverpartfn(void *arg, void *zmqsock, zmq_msg_t *msg,
printf("server recv: %s\n", buf);
fflush(stdout);
- frrzmq_thread_add_write_msg(master, serverwritefn, NULL, msg_id,
- zmqsock, &cb);
+ frrzmq_event_add_write_msg(master, serverwritefn, NULL, msg_id, zmqsock,
+ &cb);
}
static void serverfn(void *arg, void *zmqsock)
@@ -242,8 +242,8 @@ static void serverfn(void *arg, void *zmqsock)
frrzmq_thread_cancel(&cb, &cb->read);
frrzmq_thread_cancel(&cb, &cb->write);
- frrzmq_thread_add_read_part(master, serverpartfn, NULL, NULL, zmqsock,
- &cb);
+ frrzmq_event_add_read_part(master, serverpartfn, NULL, NULL, zmqsock,
+ &cb);
}
static void sigchld(void)
@@ -264,9 +264,9 @@ static void run_server(int syncfd)
{
void *zmqsock;
char dummy = 0;
- struct thread t;
+ struct event t;
- master = thread_master_create(NULL);
+ master = event_master_create(NULL);
signal_init(master, array_size(sigs), sigs);
frrzmq_init();
@@ -276,15 +276,15 @@ static void run_server(int syncfd)
exit(1);
}
- frrzmq_thread_add_read_msg(master, serverfn, NULL, NULL, zmqsock, &cb);
+ frrzmq_event_add_read_msg(master, serverfn, NULL, NULL, zmqsock, &cb);
write(syncfd, &dummy, sizeof(dummy));
- while (thread_fetch(master, &t))
- thread_call(&t);
+ while (event_fetch(master, &t))
+ event_call(&t);
zmq_close(zmqsock);
frrzmq_finish();
- thread_master_free(master);
+ event_master_free(master);
log_memstats_stderr("test");
}
diff --git a/tests/ospfd/common.c b/tests/ospfd/common.c
index ef5e3ed177..e3941865ab 100644
--- a/tests/ospfd/common.c
+++ b/tests/ospfd/common.c
@@ -17,7 +17,7 @@
#include "common.h"
-struct thread_master *master;
+struct event_loop *master;
struct zebra_privs_t ospfd_privs;
diff --git a/tests/ospfd/common.h b/tests/ospfd/common.h
index 6d3e63e359..18e412bd3c 100644
--- a/tests/ospfd/common.h
+++ b/tests/ospfd/common.h
@@ -30,7 +30,7 @@ extern int topology_load(struct vty *vty, struct ospf_topology *topology,
struct ospf_test_node *root, struct ospf *ospf);
/* Global variables. */
-extern struct thread_master *master;
+extern struct event_loop *master;
extern struct ospf_topology topo1;
extern struct ospf_topology topo2;
extern struct ospf_topology topo3;
diff --git a/tests/ospfd/test_ospf_spf.c b/tests/ospfd/test_ospf_spf.c
index b8a2aef69e..fc6b8e89ec 100644
--- a/tests/ospfd/test_ospf_spf.c
+++ b/tests/ospfd/test_ospf_spf.c
@@ -1,7 +1,7 @@
#include <zebra.h>
#include "getopt.h"
-#include "thread.h"
+#include "frrevent.h"
#include <lib/version.h>
#include "vty.h"
#include "command.h"
@@ -208,7 +208,7 @@ static void vty_do_exit(int isexit)
cmd_terminate();
vty_terminate();
- thread_master_free(master);
+ event_master_free(master);
if (!isexit)
exit(0);
@@ -240,7 +240,7 @@ int main(int argc, char **argv)
{
char *p;
char *progname;
- struct thread thread;
+ struct event thread;
bool debug = false;
/* Set umask before anything for security */
@@ -273,7 +273,7 @@ int main(int argc, char **argv)
}
/* master init. */
- master = thread_master_create(NULL);
+ master = event_master_create(NULL);
/* Library inits. */
cmd_init(1);
@@ -297,8 +297,8 @@ int main(int argc, char **argv)
vty_stdio(vty_do_exit);
/* Fetch next active thread. */
- while (thread_fetch(master, &thread))
- thread_call(&thread);
+ while (event_fetch(master, &thread))
+ event_call(&thread);
/* Not reached. */
exit(0);
diff --git a/tests/topotests/all_protocol_startup/r1/ospf6d.conf-pre-v4 b/tests/topotests/all_protocol_startup/r1/ospf6d.conf-pre-v4
index 6d870f355f..9ce2f2e825 100644
--- a/tests/topotests/all_protocol_startup/r1/ospf6d.conf-pre-v4
+++ b/tests/topotests/all_protocol_startup/r1/ospf6d.conf-pre-v4
@@ -1,9 +1,9 @@
log file ospf6d.log
!
-debug ospf6 lsa unknown
-debug ospf6 zebra
-debug ospf6 interface
-debug ospf6 neighbor
+!debug ospf6 lsa unknown
+!debug ospf6 zebra
+!debug ospf6 interface
+!debug ospf6 neighbor
!
interface r1-eth4
!
diff --git a/tests/topotests/all_protocol_startup/r1/show_isis_interface_detail.ref b/tests/topotests/all_protocol_startup/r1/show_isis_interface_detail.ref
index 0534b64d33..865970065c 100644
--- a/tests/topotests/all_protocol_startup/r1/show_isis_interface_detail.ref
+++ b/tests/topotests/all_protocol_startup/r1/show_isis_interface_detail.ref
@@ -3,7 +3,7 @@ Area test:
Type: lan, Level: L1, SNPA: XXXX.XXXX.XXXX
Level-1 Information:
Metric: 10, Active neighbors: 0
- Hello interval: 3, Holddown count: 10 (pad)
+ Hello interval: 3, Holddown count: 10, Padding: yes
CNSP interval: 10, PSNP interval: 2
LAN Priority: 64, is not DIS
IP Prefix(es):
@@ -17,7 +17,7 @@ Area test:
Type: lan, Level: L2, SNPA: XXXX.XXXX.XXXX
Level-2 Information:
Metric: 10, Active neighbors: 0
- Hello interval: 3, Holddown count: 10 (pad)
+ Hello interval: 3, Holddown count: 10, Padding: yes
CNSP interval: 10, PSNP interval: 2
LAN Priority: 64, is not DIS
IP Prefix(es):
diff --git a/tests/topotests/all_protocol_startup/test_all_protocol_startup.py b/tests/topotests/all_protocol_startup/test_all_protocol_startup.py
index fe84d496ac..92bb99c8f2 100644
--- a/tests/topotests/all_protocol_startup/test_all_protocol_startup.py
+++ b/tests/topotests/all_protocol_startup/test_all_protocol_startup.py
@@ -82,6 +82,7 @@ def setup_module(module):
#
# Main router
for i in range(1, 2):
+ net["r%s" % i].loadConf("mgmtd", "%s/r%s/zebra.conf" % (thisDir, i))
net["r%s" % i].loadConf("zebra", "%s/r%s/zebra.conf" % (thisDir, i))
net["r%s" % i].loadConf("ripd", "%s/r%s/ripd.conf" % (thisDir, i))
net["r%s" % i].loadConf("ripngd", "%s/r%s/ripngd.conf" % (thisDir, i))
@@ -287,6 +288,17 @@ def test_converge_protocols():
thisDir = os.path.dirname(os.path.realpath(__file__))
+ # We need loopback to have a link local so it always is the
+ # "selected" router for fe80::/64 when we static compare below.
+ print("Adding link-local to loopback for stable results")
+ cmd = (
+ "mac=`cat /sys/class/net/lo/address`; echo lo: $mac;"
+ " [ -z \"$mac\" ] && continue; IFS=':'; set $mac; unset IFS;"
+ " ip address add dev lo scope link"
+ " fe80::$(printf %02x $((0x$1 ^ 2)))$2:${3}ff:fe$4:$5$6/64"
+ )
+ net["r1"].cmd_raises(cmd)
+
print("\n\n** Waiting for protocols convergence")
print("******************************************\n")
diff --git a/tests/topotests/bfd_topo2/test_bfd_topo2.py b/tests/topotests/bfd_topo2/test_bfd_topo2.py
index b720218e9b..636dbf354d 100644
--- a/tests/topotests/bfd_topo2/test_bfd_topo2.py
+++ b/tests/topotests/bfd_topo2/test_bfd_topo2.py
@@ -45,6 +45,7 @@ def setup_module(mod):
router_list = tgen.routers()
for rname, router in router_list.items():
+
daemon_file = "{}/{}/zebra.conf".format(CWD, rname)
router.load_config(TopoRouter.RD_ZEBRA, daemon_file)
diff --git a/tests/topotests/bfd_topo3/r5/bfdd.conf b/tests/topotests/bfd_topo3/r5/bfdd.conf
index 6d4483acc4..ec62d8d275 100644
--- a/tests/topotests/bfd_topo3/r5/bfdd.conf
+++ b/tests/topotests/bfd_topo3/r5/bfdd.conf
@@ -1,6 +1,6 @@
-debug bfd network
-debug bfd peer
-debug bfd zebra
+!debug bfd network
+!debug bfd peer
+!debug bfd zebra
!
bfd
profile slow-tx
diff --git a/tests/topotests/bfd_topo3/r6/bfdd.conf b/tests/topotests/bfd_topo3/r6/bfdd.conf
index 6d4483acc4..ec62d8d275 100644
--- a/tests/topotests/bfd_topo3/r6/bfdd.conf
+++ b/tests/topotests/bfd_topo3/r6/bfdd.conf
@@ -1,6 +1,6 @@
-debug bfd network
-debug bfd peer
-debug bfd zebra
+!debug bfd network
+!debug bfd peer
+!debug bfd zebra
!
bfd
profile slow-tx
diff --git a/tests/topotests/bgp_accept_own/ce1/bgpd.conf b/tests/topotests/bgp_accept_own/ce1/bgpd.conf
index fa53a42919..44f95b9bb3 100644
--- a/tests/topotests/bgp_accept_own/ce1/bgpd.conf
+++ b/tests/topotests/bgp_accept_own/ce1/bgpd.conf
@@ -1,5 +1,5 @@
!
-debug bgp updates
+!debug bgp updates
!
router bgp 65010
no bgp ebgp-requires-policy
diff --git a/tests/topotests/bgp_accept_own/ce2/bgpd.conf b/tests/topotests/bgp_accept_own/ce2/bgpd.conf
index cdf8898c90..d60fdcf7cb 100644
--- a/tests/topotests/bgp_accept_own/ce2/bgpd.conf
+++ b/tests/topotests/bgp_accept_own/ce2/bgpd.conf
@@ -1,5 +1,5 @@
!
-debug bgp updates
+!debug bgp updates
!
router bgp 65020
no bgp ebgp-requires-policy
diff --git a/tests/topotests/bgp_accept_own/pe1/bgpd.conf b/tests/topotests/bgp_accept_own/pe1/bgpd.conf
index 109e0eadbb..15466b4259 100644
--- a/tests/topotests/bgp_accept_own/pe1/bgpd.conf
+++ b/tests/topotests/bgp_accept_own/pe1/bgpd.conf
@@ -1,8 +1,8 @@
!
-debug bgp updates
-debug bgp vpn leak-from-vrf
-debug bgp vpn leak-to-vrf
-debug bgp nht
+!debug bgp updates
+!debug bgp vpn leak-from-vrf
+!debug bgp vpn leak-to-vrf
+!debug bgp nht
!
router bgp 65001
bgp router-id 10.10.10.10
diff --git a/tests/topotests/bgp_accept_own/rr1/bgpd.conf b/tests/topotests/bgp_accept_own/rr1/bgpd.conf
index 4f0a6ab0f1..ad0ee3e471 100644
--- a/tests/topotests/bgp_accept_own/rr1/bgpd.conf
+++ b/tests/topotests/bgp_accept_own/rr1/bgpd.conf
@@ -1,5 +1,5 @@
!
-debug bgp updates
+!debug bgp updates
!
router bgp 65001
bgp router-id 10.10.10.101
diff --git a/tests/topotests/bgp_comm_list_match/r2/bgpd.conf b/tests/topotests/bgp_comm_list_match/r2/bgpd.conf
index 35ad2d32e6..98a9780688 100644
--- a/tests/topotests/bgp_comm_list_match/r2/bgpd.conf
+++ b/tests/topotests/bgp_comm_list_match/r2/bgpd.conf
@@ -1,5 +1,5 @@
!
-debug bgp updates
+!debug bgp updates
!
router bgp 65002
no bgp ebgp-requires-policy
diff --git a/tests/topotests/bgp_confed1/r1/bgpd.conf b/tests/topotests/bgp_confed1/r1/bgpd.conf
index 8413ef7fc3..107d2ad8d2 100644
--- a/tests/topotests/bgp_confed1/r1/bgpd.conf
+++ b/tests/topotests/bgp_confed1/r1/bgpd.conf
@@ -1,7 +1,7 @@
-debug bgp neighbor-events
-debug bgp nht
-debug bgp updates in
-debug bgp updates out
+!debug bgp neighbor-events
+!debug bgp nht
+!debug bgp updates in
+!debug bgp updates out
!
router bgp 100
no bgp ebgp-requires-policy
diff --git a/tests/topotests/bgp_confed1/r2/bgpd.conf b/tests/topotests/bgp_confed1/r2/bgpd.conf
index 9f6a9852de..fe13dfe729 100644
--- a/tests/topotests/bgp_confed1/r2/bgpd.conf
+++ b/tests/topotests/bgp_confed1/r2/bgpd.conf
@@ -1,7 +1,7 @@
-debug bgp neighbor-events
-debug bgp nht
-debug bgp updates in
-debug bgp updates out
+!debug bgp neighbor-events
+!debug bgp nht
+!debug bgp updates in
+!debug bgp updates out
!
router bgp 200
no bgp ebgp-requires-policy
diff --git a/tests/topotests/bgp_confed1/r3/bgpd.conf b/tests/topotests/bgp_confed1/r3/bgpd.conf
index 3a018a42b3..74d5fd6e29 100644
--- a/tests/topotests/bgp_confed1/r3/bgpd.conf
+++ b/tests/topotests/bgp_confed1/r3/bgpd.conf
@@ -1,7 +1,7 @@
-debug bgp neighbor-events
-debug bgp nht
-debug bgp updates in
-debug bgp updates out
+!debug bgp neighbor-events
+!debug bgp nht
+!debug bgp updates in
+!debug bgp updates out
!
router bgp 300
no bgp ebgp-requires-policy
diff --git a/tests/topotests/bgp_confed1/r4/bgpd.conf b/tests/topotests/bgp_confed1/r4/bgpd.conf
index 134f221543..89a85e5a34 100644
--- a/tests/topotests/bgp_confed1/r4/bgpd.conf
+++ b/tests/topotests/bgp_confed1/r4/bgpd.conf
@@ -1,7 +1,7 @@
-debug bgp neighbor-events
-debug bgp nht
-debug bgp updates in
-debug bgp updates out
+!debug bgp neighbor-events
+!debug bgp nht
+!debug bgp updates in
+!debug bgp updates out
!
router bgp 400
no bgp ebgp-requires-policy
diff --git a/tests/topotests/bgp_dont_capability_negotiate/r1/bgpd.conf b/tests/topotests/bgp_dont_capability_negotiate/r1/bgpd.conf
index e2ff1df965..2f76d59d4a 100644
--- a/tests/topotests/bgp_dont_capability_negotiate/r1/bgpd.conf
+++ b/tests/topotests/bgp_dont_capability_negotiate/r1/bgpd.conf
@@ -1,5 +1,5 @@
!
-debug bgp neighbor
+!debug bgp neighbor
!
router bgp 65001
no bgp ebgp-requires-policy
diff --git a/tests/topotests/bgp_evpn_vxlan_svd_topo1/test_bgp_evpn_vxlan_svd.py b/tests/topotests/bgp_evpn_vxlan_svd_topo1/test_bgp_evpn_vxlan_svd.py
index f8af210ed7..65c0c3532a 100755
--- a/tests/topotests/bgp_evpn_vxlan_svd_topo1/test_bgp_evpn_vxlan_svd.py
+++ b/tests/topotests/bgp_evpn_vxlan_svd_topo1/test_bgp_evpn_vxlan_svd.py
@@ -83,6 +83,7 @@ def build_topo(tgen):
switch.add_link(tgen.gears["PE2"])
switch.add_link(tgen.gears["host2"])
+
def setup_pe_router(tgen, pe_name, tunnel_local_ip, svi_ip, intf):
pe = tgen.gears[pe_name]
@@ -100,7 +101,9 @@ def setup_pe_router(tgen, pe_name, tunnel_local_ip, svi_ip, intf):
# setup single vxlan device
pe.run(
- "ip link add dev vxlan0 type vxlan dstport 4789 local {0} nolearning external".format(tunnel_local_ip)
+ "ip link add dev vxlan0 type vxlan dstport 4789 local {0} nolearning external".format(
+ tunnel_local_ip
+ )
)
pe.run("ip link set dev vxlan0 master bridge")
pe.run("bridge link set dev vxlan0 vlan_tunnel on")
@@ -136,10 +139,12 @@ def setup_pe_router(tgen, pe_name, tunnel_local_ip, svi_ip, intf):
pe.run("bridge vlan add dev vxlan0 vid 300")
pe.run("bridge vlan add dev vxlan0 vid 300 tunnel_info id 300")
+
def setup_p_router(tgen, p_name):
p1 = tgen.gears[p_name]
p1.run("sysctl -w net.ipv4.ip_forward=1")
+
def setup_module(mod):
"Sets up the pytest environment"
@@ -180,7 +185,7 @@ def teardown_module(mod):
"Teardown the pytest environment"
tgen = get_topogen()
- #tgen.mininet_cli()
+ # tgen.mininet_cli()
# This function tears down the whole topology.
tgen.stop_topology()
@@ -204,17 +209,21 @@ def check_vni_macs_present(tgen, router, vni, maclist):
)
return None
+
def check_flood_entry_present(pe, vni, vtep):
if not topotest.iproute2_is_fdb_get_capable():
return None
- output = pe.run("bridge fdb get 00:00:00:00:00:00 dev vxlan0 vni {} self".format(vni))
+ output = pe.run(
+ "bridge fdb get 00:00:00:00:00:00 dev vxlan0 vni {} self".format(vni)
+ )
if str(vtep) not in output:
return output
return None
+
def test_pe1_converge_evpn():
"Wait for protocol convergence"
@@ -231,6 +240,15 @@ def test_pe1_converge_evpn():
_, result = topotest.run_and_expect(test_func, None, count=45, wait=1)
assertmsg = '"{}" JSON output mismatches'.format(pe1.name)
+ # Let's ensure that the hosts have actually tried talking to
+ # each other. Otherwise under certain startup conditions
+ # they may not actually do any l2 arp'ing and as such
+ # the bridges won't know about the hosts on their networks
+ host1 = tgen.gears["host1"]
+ host1.run("ping -c 1 10.10.1.56")
+ host2 = tgen.gears["host2"]
+ host2.run("ping -c 1 10.10.1.55")
+
test_func = partial(
check_vni_macs_present,
tgen,
@@ -249,11 +267,12 @@ def test_pe1_converge_evpn():
assertmsg = '"{}" Flood FDB Entry for VTEP {} not found'.format(pe1.name, vtep)
assert result is None, assertmsg
+
def test_pe2_converge_evpn():
"Wait for protocol convergence"
tgen = get_topogen()
-#Don't run this test if we have any failure.
+ # Don't run this test if we have any failure.
if tgen.routers_have_failure():
pytest.skip(tgen.errors)
@@ -284,6 +303,7 @@ def test_pe2_converge_evpn():
assertmsg = '"{}" Flood FDB Entry for VTEP {} not found'.format(pe2.name, vtep)
assert result is None, assertmsg
+
def mac_learn_test(host, local):
"check the host MAC gets learned by the VNI"
@@ -389,11 +409,11 @@ def ip_learn_test(tgen, host, local, remote, ip_addr):
if "HWaddr" in line_items[0]:
mac = line_items[1]
break
- #print(host_output)
+ # print(host_output)
# check we have a local association between the MAC and IP
local_output = local.vtysh_cmd("show evpn mac vni 101 mac {} json".format(mac))
- #print(local_output)
+ # print(local_output)
local_output_json = json.loads(local_output)
mac_type = local_output_json[mac]["type"]
assertmsg = "Failed to learn local IP address on host {}".format(host.name)
@@ -417,7 +437,7 @@ def ip_learn_test(tgen, host, local, remote, ip_addr):
remote_output = remote.vtysh_cmd(
"show evpn mac vni 101 mac {} json".format(mac)
)
- #print(remote_output)
+ # print(remote_output)
remote_output_json = json.loads(remote_output)
type = remote_output_json[mac]["type"]
if not remote_output_json[mac]["neighbors"] == "none":
@@ -431,12 +451,12 @@ def ip_learn_test(tgen, host, local, remote, ip_addr):
count += 1
sleep(1)
- #print("tries: {}".format(count))
+ # print("tries: {}".format(count))
assertmsg = "{} remote learned mac no address: {} ".format(host.name, mac)
# some debug for this failure
if not converged == True:
log_output = remote.run("cat zebra.log")
- #print(log_output)
+ # print(log_output)
assert converged == True, assertmsg
if remote_output_json[mac]["neighbors"]["active"]:
@@ -463,8 +483,8 @@ def test_ip_pe1_learn():
host1 = tgen.gears["host1"]
pe1 = tgen.gears["PE1"]
pe2 = tgen.gears["PE2"]
- pe2.vtysh_cmd("debug zebra vxlan")
- pe2.vtysh_cmd("debug zebra kernel")
+ # pe2.vtysh_cmd("debug zebra vxlan")
+ # pe2.vtysh_cmd("debug zebra kernel")
# lets populate that arp cache
host1.run("ping -c1 10.10.1.1")
ip_learn_test(tgen, host1, pe1, pe2, "10.10.1.55")
@@ -482,13 +502,14 @@ def test_ip_pe2_learn():
host2 = tgen.gears["host2"]
pe1 = tgen.gears["PE1"]
pe2 = tgen.gears["PE2"]
- pe1.vtysh_cmd("debug zebra vxlan")
- pe1.vtysh_cmd("debug zebra kernel")
+ # pe1.vtysh_cmd("debug zebra vxlan")
+ # pe1.vtysh_cmd("debug zebra kernel")
# lets populate that arp cache
host2.run("ping -c1 10.10.1.3")
ip_learn_test(tgen, host2, pe2, pe1, "10.10.1.56")
# tgen.mininet_cli()
+
def show_dvni_route(pe, vni, prefix, vrf):
output = pe.vtysh_cmd("show ip route vrf {} {}".format(vrf, prefix))
@@ -502,6 +523,7 @@ def show_dvni_route(pe, vni, prefix, vrf):
return None
+
def test_dvni():
"test Downstream VNI works as expected importing into PE1"
@@ -517,7 +539,7 @@ def test_dvni():
_, result = topotest.run_and_expect(test_func, None, count=30, wait=1)
assertmsg = '"{}" DVNI route {} not found'.format(pe1.name, prefix)
assert result is None, assertmsg
- #tgen.mininet_cli()
+ # tgen.mininet_cli()
def test_memory_leak():
diff --git a/tests/topotests/bgp_evpn_vxlan_topo1/test_bgp_evpn_vxlan.py b/tests/topotests/bgp_evpn_vxlan_topo1/test_bgp_evpn_vxlan.py
index 48b79ab5ee..2884043012 100755
--- a/tests/topotests/bgp_evpn_vxlan_topo1/test_bgp_evpn_vxlan.py
+++ b/tests/topotests/bgp_evpn_vxlan_topo1/test_bgp_evpn_vxlan.py
@@ -164,6 +164,15 @@ def test_pe1_converge_evpn():
_, result = topotest.run_and_expect(test_func, None, count=45, wait=1)
assertmsg = '"{}" JSON output mismatches'.format(pe1.name)
+ # Let's ensure that the hosts have actually tried talking to
+ # each other. Otherwise under certain startup conditions
+ # they may not actually do any l2 arp'ing and as such
+ # the bridges won't know about the hosts on their networks
+ host1 = tgen.gears["host1"]
+ host1.run("ping -c 1 10.10.1.56")
+ host2 = tgen.gears["host2"]
+ host2.run("ping -c 1 10.10.1.55")
+
test_func = partial(
check_vni_macs_present,
tgen,
@@ -171,6 +180,7 @@ def test_pe1_converge_evpn():
101,
(("host1", "host1-eth0"), ("host2", "host2-eth0")),
)
+
_, result = topotest.run_and_expect(test_func, None, count=30, wait=1)
if result:
logger.warning("%s", result)
@@ -385,8 +395,8 @@ def test_ip_pe1_learn():
host1 = tgen.gears["host1"]
pe1 = tgen.gears["PE1"]
pe2 = tgen.gears["PE2"]
- pe2.vtysh_cmd("debug zebra vxlan")
- pe2.vtysh_cmd("debug zebra kernel")
+ # pe2.vtysh_cmd("debug zebra vxlan")
+ # pe2.vtysh_cmd("debug zebra kernel")
# lets populate that arp cache
host1.run("ping -c1 10.10.1.1")
ip_learn_test(tgen, host1, pe1, pe2, "10.10.1.55")
@@ -404,8 +414,8 @@ def test_ip_pe2_learn():
host2 = tgen.gears["host2"]
pe1 = tgen.gears["PE1"]
pe2 = tgen.gears["PE2"]
- pe1.vtysh_cmd("debug zebra vxlan")
- pe1.vtysh_cmd("debug zebra kernel")
+ # pe1.vtysh_cmd("debug zebra vxlan")
+ # pe1.vtysh_cmd("debug zebra kernel")
# lets populate that arp cache
host2.run("ping -c1 10.10.1.3")
ip_learn_test(tgen, host2, pe2, pe1, "10.10.1.56")
diff --git a/tests/topotests/bgp_ipv6_ll_peering/__init__.py b/tests/topotests/bgp_ipv6_ll_peering/__init__.py
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/tests/topotests/bgp_ipv6_ll_peering/__init__.py
diff --git a/tests/topotests/bgp_ipv6_ll_peering/r1/bgpd.conf b/tests/topotests/bgp_ipv6_ll_peering/r1/bgpd.conf
new file mode 100644
index 0000000000..724cbf84ab
--- /dev/null
+++ b/tests/topotests/bgp_ipv6_ll_peering/r1/bgpd.conf
@@ -0,0 +1,6 @@
+router bgp 65001
+ bgp router-id 10.0.0.1
+ no bgp ebgp-requires-policy
+ neighbor fe80:1::2 remote-as external
+ neighbor fe80:1::2 timers 3 10
+ neighbor fe80:1::2 interface r1-eth0
diff --git a/tests/topotests/bgp_ipv6_ll_peering/r1/zebra.conf b/tests/topotests/bgp_ipv6_ll_peering/r1/zebra.conf
new file mode 100644
index 0000000000..4e93d4f4e5
--- /dev/null
+++ b/tests/topotests/bgp_ipv6_ll_peering/r1/zebra.conf
@@ -0,0 +1,4 @@
+!
+interface r1-eth0
+ ipv6 address fe80:1::1/64
+!
diff --git a/tests/topotests/bgp_ipv6_ll_peering/r2/bgpd.conf b/tests/topotests/bgp_ipv6_ll_peering/r2/bgpd.conf
new file mode 100644
index 0000000000..44f79dfc33
--- /dev/null
+++ b/tests/topotests/bgp_ipv6_ll_peering/r2/bgpd.conf
@@ -0,0 +1,6 @@
+router bgp 65002
+ bgp router-id 10.0.0.2
+ no bgp ebgp-requires-policy
+ neighbor fe80:1::1 remote-as external
+ neighbor fe80:1::1 timers 3 10
+ neighbor fe80:1::1 interface r2-eth0
diff --git a/tests/topotests/bgp_ipv6_ll_peering/r2/zebra.conf b/tests/topotests/bgp_ipv6_ll_peering/r2/zebra.conf
new file mode 100644
index 0000000000..1e703cda36
--- /dev/null
+++ b/tests/topotests/bgp_ipv6_ll_peering/r2/zebra.conf
@@ -0,0 +1,4 @@
+!
+interface r2-eth0
+ ipv6 address fe80:1::2/64
+!
diff --git a/tests/topotests/bgp_ipv6_ll_peering/test_bgp_ipv6_ll_peering.py b/tests/topotests/bgp_ipv6_ll_peering/test_bgp_ipv6_ll_peering.py
new file mode 100644
index 0000000000..ea974b5302
--- /dev/null
+++ b/tests/topotests/bgp_ipv6_ll_peering/test_bgp_ipv6_ll_peering.py
@@ -0,0 +1,88 @@
+#!/usr/bin/env python
+# SPDX-License-Identifier: ISC
+
+#
+# Copyright (c) 2023 by
+# Donatas Abraitis <donatas@opensourcerouting.org>
+#
+
+"""
+Check if IPv6 Link-Local BGP peering works fine.
+"""
+
+import os
+import sys
+import json
+import pytest
+import functools
+
+CWD = os.path.dirname(os.path.realpath(__file__))
+sys.path.append(os.path.join(CWD, "../"))
+
+# pylint: disable=C0413
+from lib import topotest
+from lib.topogen import Topogen, TopoRouter, get_topogen
+
+pytestmark = [pytest.mark.bgpd]
+
+
+def build_topo(tgen):
+ for routern in range(1, 3):
+ tgen.add_router("r{}".format(routern))
+
+ switch = tgen.add_switch("s1")
+ switch.add_link(tgen.gears["r1"])
+ switch.add_link(tgen.gears["r2"])
+
+
+def setup_module(mod):
+ tgen = Topogen(build_topo, mod.__name__)
+ tgen.start_topology()
+
+ router_list = tgen.routers()
+
+ for i, (rname, router) in enumerate(router_list.items(), 1):
+ router.load_config(
+ TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname))
+ )
+ router.load_config(
+ TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname))
+ )
+
+ tgen.start_router()
+
+
+def teardown_module(mod):
+ tgen = get_topogen()
+ tgen.stop_topology()
+
+
+def test_bgp_ipv6_link_local_peering():
+ tgen = get_topogen()
+
+ if tgen.routers_have_failure():
+ pytest.skip(tgen.errors)
+
+ r1 = tgen.gears["r1"]
+
+ def _bgp_converge():
+ output = json.loads(r1.vtysh_cmd("show bgp summary json"))
+ expected = {
+ "ipv4Unicast": {
+ "peers": {
+ "fe80:1::2": {
+ "state": "Established",
+ }
+ }
+ }
+ }
+ return topotest.json_cmp(output, expected)
+
+ test_func = functools.partial(_bgp_converge)
+ _, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5)
+ assert result is None, "Failed to see BGP convergence on R2"
+
+
+if __name__ == "__main__":
+ args = ["-s"] + sys.argv[1:]
+ sys.exit(pytest.main(args))
diff --git a/tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/scale_up.py b/tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/scale_up.py
index eaa6aa4c30..46993c7d9a 100644
--- a/tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/scale_up.py
+++ b/tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/scale_up.py
@@ -62,6 +62,25 @@ else:
"pass",
"Adding {} routes".format(num),
)
+ luCommand(
+ "ce1",
+ 'vtysh -c "show ip route summ" | grep "sharp" | cut -d " " -f 33',
+ str(num),
+ "wait",
+ "See all sharp routes in rib on ce1",
+ wait,
+ wait_time=10,
+ )
+ luCommand(
+ "ce2",
+ 'vtysh -c "show ip route summ" | grep "sharp" | cut -d " " -f 33',
+ str(num),
+ "wait",
+ "See all sharp routes in rib on ce2",
+ wait,
+ wait_time=10,
+ )
+
rtrs = ["ce1", "ce2", "ce3"]
for rtr in rtrs:
luCommand(
diff --git a/tests/topotests/bgp_labeled_unicast_addpath/test_bgp_labeled_unicast_addpath.py b/tests/topotests/bgp_labeled_unicast_addpath/test_bgp_labeled_unicast_addpath.py
index 3af779c427..f4bb487e40 100644
--- a/tests/topotests/bgp_labeled_unicast_addpath/test_bgp_labeled_unicast_addpath.py
+++ b/tests/topotests/bgp_labeled_unicast_addpath/test_bgp_labeled_unicast_addpath.py
@@ -82,53 +82,23 @@ def test_bgp_addpath_labeled_unicast():
r3 = tgen.gears["r3"]
r4 = tgen.gears["r4"]
- def _bgp_check_advertised_routes(prefix_num):
- output = json.loads(
- r3.vtysh_cmd(
- "show bgp ipv4 labeled-unicast neighbors 192.168.34.4 advertised-routes json"
- )
- )
+ def _bgp_check_received_routes(pfxcount):
+ output = json.loads(r4.vtysh_cmd("show bgp ipv4 labeled-unicast summary json"))
expected = {
- "advertisedRoutes": {
- "10.0.0.1/32": {
- "appliedStatusSymbols": {
- "*": True,
- ">": True,
- "=": True,
- }
+ "peers": {
+ "192.168.34.3": {
+ "pfxRcd": pfxcount,
+ "state": "Established",
}
- },
- "totalPrefixCounter": prefix_num,
+ }
}
return topotest.json_cmp(output, expected)
- test_func = functools.partial(_bgp_check_advertised_routes, 2)
+ test_func = functools.partial(_bgp_check_received_routes, 2)
_, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5)
assert (
result is None
- ), "Failed to advertise labeled-unicast with addpath (multipath)"
-
- def _bgp_check_received_routes():
- output = json.loads(r4.vtysh_cmd("show bgp ipv4 labeled-unicast json"))
- expected = {
- "routes": {
- "10.0.0.1/32": [
- {
- "valid": True,
- "path": "65003 65001",
- },
- {
- "valid": True,
- "path": "65003 65002",
- },
- ]
- }
- }
- return topotest.json_cmp(output, expected)
-
- test_func = functools.partial(_bgp_check_received_routes)
- _, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5)
- assert result is None, "Failed to receive labeled-unicast with addpath (multipath)"
+ ), "Failed to receive labeled-unicast with addpath (multipath=2)"
step("Enable BGP session for R5")
r3.vtysh_cmd(
@@ -139,11 +109,11 @@ def test_bgp_addpath_labeled_unicast():
"""
)
- test_func = functools.partial(_bgp_check_advertised_routes, 3)
+ test_func = functools.partial(_bgp_check_received_routes, 3)
_, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5)
assert (
result is None
- ), "Failed to advertise labeled-unicast with addpath (multipath)"
+ ), "Failed to receive labeled-unicast with addpath (multipath=3)"
step("Disable BGP session for R5")
r3.vtysh_cmd(
@@ -154,11 +124,11 @@ def test_bgp_addpath_labeled_unicast():
"""
)
- test_func = functools.partial(_bgp_check_advertised_routes, 2)
+ test_func = functools.partial(_bgp_check_received_routes, 2)
_, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5)
assert (
result is None
- ), "Failed to advertise labeled-unicast with addpath (multipath)"
+ ), "Failed to receive labeled-unicast with addpath (multipath=2)"
if __name__ == "__main__":
diff --git a/tests/topotests/bgp_lu_explicitnull/r1/bgpd.conf b/tests/topotests/bgp_lu_explicitnull/r1/bgpd.conf
new file mode 100644
index 0000000000..a31439c984
--- /dev/null
+++ b/tests/topotests/bgp_lu_explicitnull/r1/bgpd.conf
@@ -0,0 +1,15 @@
+router bgp 65500
+ bgp router-id 192.0.2.1
+ no bgp ebgp-requires-policy
+ bgp labeled-unicast explicit-null
+ neighbor 192.0.2.2 remote-as 65501
+!
+ address-family ipv4 unicast
+ no neighbor 192.0.2.2 activate
+ network 192.168.2.1/32
+ exit-address-family
+ !
+ address-family ipv4 labeled-unicast
+ neighbor 192.0.2.2 activate
+ exit-address-family
+!
diff --git a/tests/topotests/bgp_lu_explicitnull/r1/zebra.conf b/tests/topotests/bgp_lu_explicitnull/r1/zebra.conf
new file mode 100644
index 0000000000..b84574891e
--- /dev/null
+++ b/tests/topotests/bgp_lu_explicitnull/r1/zebra.conf
@@ -0,0 +1,6 @@
+interface r1-eth0
+ ip address 192.0.2.1/24
+!
+interface r1-eth1
+ ip address 192.168.2.1/32
+! \ No newline at end of file
diff --git a/tests/topotests/bgp_lu_explicitnull/r2/bgpd.conf b/tests/topotests/bgp_lu_explicitnull/r2/bgpd.conf
new file mode 100644
index 0000000000..41c2b9b6fa
--- /dev/null
+++ b/tests/topotests/bgp_lu_explicitnull/r2/bgpd.conf
@@ -0,0 +1,15 @@
+router bgp 65501
+ bgp router-id 192.0.2.2
+ no bgp ebgp-requires-policy
+ bgp labeled-unicast explicit-null
+ neighbor 192.0.2.1 remote-as 65500
+!
+ address-family ipv4 unicast
+ no neighbor 192.0.2.1 activate
+ network 192.168.2.2/32
+ exit-address-family
+ !
+ address-family ipv4 labeled-unicast
+ neighbor 192.0.2.1 activate
+ exit-address-family
+!
diff --git a/tests/topotests/bgp_lu_explicitnull/r2/zebra.conf b/tests/topotests/bgp_lu_explicitnull/r2/zebra.conf
new file mode 100644
index 0000000000..9a639610c1
--- /dev/null
+++ b/tests/topotests/bgp_lu_explicitnull/r2/zebra.conf
@@ -0,0 +1,6 @@
+interface r2-eth0
+ ip address 192.0.2.2/24
+!
+interface r2-eth1
+ ip address 192.168.2.2/32
+!
diff --git a/tests/topotests/bgp_lu_explicitnull/test_bgp_lu_explicitnull.py b/tests/topotests/bgp_lu_explicitnull/test_bgp_lu_explicitnull.py
new file mode 100644
index 0000000000..d53ac68e84
--- /dev/null
+++ b/tests/topotests/bgp_lu_explicitnull/test_bgp_lu_explicitnull.py
@@ -0,0 +1,194 @@
+#!/usr/bin/env python
+# SPDX-License-Identifier: ISC
+#
+# test_bgp_explicitnull.py
+#
+# Part of NetDEF Topology Tests
+#
+# Copyright 2023 by 6WIND S.A.
+#
+
+"""
+test_bgp_lu_explicitnull.py: Test BGP LU label allocation
+"""
+
+import os
+import sys
+import json
+import functools
+import pytest
+
+# Save the Current Working Directory to find configuration files.
+CWD = os.path.dirname(os.path.realpath(__file__))
+sys.path.append(os.path.join(CWD, "../"))
+
+# pylint: disable=C0413
+# Import topogen and topotest helpers
+from lib import topotest
+from lib.topogen import Topogen, TopoRouter, get_topogen
+from lib.topolog import logger
+
+
+pytestmark = [pytest.mark.bgpd]
+
+
+# Basic scenario for BGP-LU. Nodes are directly connected.
+# The 192.168.2.2/32 prefix is advertised from r2 to r1
+# The explicit-null label should be used
+# The 192.168.2.1/32 prefix is advertised from r1 to r2
+# The explicit-null label should be used
+# Traffic from 192.168.2.1 to 192.168.2.2 should use explicit-null label
+#
+# AS65500 BGP-LU AS65501
+# +-----+ +-----+
+# | |.1 .2| |
+# | 1 +----------------+ 2 + 192.168.0.2/32
+# | | 192.0.2.0/24 | |
+# +-----+ +-----+
+
+
+def build_topo(tgen):
+ "Build function"
+
+ # Create routers
+ tgen.add_router("r1")
+ tgen.add_router("r2")
+
+ # r1-r2
+ switch = tgen.add_switch("s1")
+ switch.add_link(tgen.gears["r1"])
+ switch.add_link(tgen.gears["r2"])
+
+ # r1
+ switch = tgen.add_switch("s2")
+ switch.add_link(tgen.gears["r1"])
+
+ # r2
+ switch = tgen.add_switch("s3")
+ switch.add_link(tgen.gears["r2"])
+
+
+def setup_module(mod):
+ "Sets up the pytest environment"
+ # This function initiates the topology build with Topogen...
+ tgen = Topogen(build_topo, mod.__name__)
+
+ # Skip if no mpls support
+ if not tgen.hasmpls:
+ logger.info("MPLS is not available, skipping test")
+ pytest.skip("MPLS is not available, skipping")
+ return
+
+ # ... and here it calls Mininet initialization functions.
+ tgen.start_topology()
+
+ # This is a sample of configuration loading.
+ router_list = tgen.routers()
+
+ # Enable mpls input for routers, so we can ping
+ sval = "net.mpls.conf.{}.input"
+ topotest.sysctl_assure(router_list["r2"], sval.format("r2-eth0"), 1)
+ topotest.sysctl_assure(router_list["r1"], sval.format("r1-eth0"), 1)
+
+ # For all registred 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_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname))
+ )
+
+ # After loading the configurations, this function loads configured daemons.
+ tgen.start_router()
+
+
+def teardown_module(mod):
+ "Teardown the pytest environment"
+ tgen = get_topogen()
+
+ # This function tears down the whole topology.
+ tgen.stop_topology()
+
+
+def check_show_ip_label_prefix_found(router, ipversion, prefix, label):
+ output = json.loads(
+ router.vtysh_cmd("show {} route {} json".format(ipversion, prefix))
+ )
+ expected = {prefix: [{"prefix": prefix, "nexthops": [{"fib": True, "labels": [label]}]}]}
+ ret = topotest.json_cmp(output, expected)
+ if ret is None:
+ return "not good"
+ return None
+
+def test_converge_bgplu():
+ "Wait for protocol convergence"
+
+ tgen = get_topogen()
+ # Don't run this test if we have any failure.
+ if tgen.routers_have_failure():
+ pytest.skip(tgen.errors)
+
+ # tgen.mininet_cli();
+ r1 = tgen.gears["r1"]
+ r2 = tgen.gears["r2"]
+ # Check r1 gets prefix 192.168.2.2/32
+ test_func = functools.partial(
+ check_show_ip_label_prefix_found,
+ tgen.gears["r1"],
+ "ip",
+ "192.168.2.2/32",
+ "0",
+ )
+ success, result = topotest.run_and_expect(test_func, None, count=10, wait=0.5)
+ assert (
+ success
+ ), "r1, prefix 192.168.2.2/32 from r2 not present"
+
+ # Check r2 gets prefix 192.168.2.1/32
+ test_func = functools.partial(
+ check_show_ip_label_prefix_found,
+ tgen.gears["r2"],
+ "ip",
+ "192.168.2.1/32",
+ "0",
+ )
+ success, result = topotest.run_and_expect(test_func, None, count=10, wait=0.5)
+ assert (
+ success
+ ), "r2, prefix 192.168.2.1/32 from r1 not present"
+
+def test_traffic_connectivity():
+ "Wait for protocol convergence"
+
+ tgen = get_topogen()
+ # Don't run this test if we have any failure.
+ if tgen.routers_have_failure():
+ pytest.skip(tgen.errors)
+
+ def _check_ping(name, dest_addr, src_addr):
+ tgen = get_topogen()
+ output = tgen.gears[name].run("ping {} -c 1 -w 1 -I {}".format(dest_addr, src_addr))
+ logger.info(output)
+ if " 0% packet loss" not in output:
+ return True
+
+ logger.info("r1, check ping 192.168.2.2 from 192.168.2.1 is OK")
+ tgen = get_topogen()
+ func = functools.partial(_check_ping, "r1", "192.168.2.2", "192.168.2.1")
+ # tgen.mininet_cli()
+ success, result = topotest.run_and_expect(func, None, count=10, wait=0.5)
+ assert result is None, "r1, ping to 192.168.2.2 from 192.168.2.1 fails"
+
+def test_memory_leak():
+ "Run the memory leak test and report results."
+ tgen = get_topogen()
+ if not tgen.is_memleak_enabled():
+ pytest.skip("Memory leak test/report is disabled")
+
+ tgen.report_memory_leaks()
+
+
+if __name__ == "__main__":
+ args = ["-s"] + sys.argv[1:]
+ sys.exit(pytest.main(args))
diff --git a/tests/topotests/bgp_prefix_list_any/__init__.py b/tests/topotests/bgp_prefix_list_any/__init__.py
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/tests/topotests/bgp_prefix_list_any/__init__.py
diff --git a/tests/topotests/bgp_prefix_list_any/r1/bgpd.conf b/tests/topotests/bgp_prefix_list_any/r1/bgpd.conf
new file mode 100644
index 0000000000..14c28ca906
--- /dev/null
+++ b/tests/topotests/bgp_prefix_list_any/r1/bgpd.conf
@@ -0,0 +1,15 @@
+!
+router bgp 65001
+ no bgp ebgp-requires-policy
+ no bgp network import-check
+ neighbor 192.168.1.2 remote-as external
+ neighbor 2001:db8:1::2 remote-as external
+ address-family ipv4 unicast
+ network 192.168.0.1/32
+ no neighbor 2001:db8:1::2 activate
+ exit-address-family
+ address-family ipv6 unicast
+ neighbor 2001:db8:1::2 activate
+ network 2001:db8::1/128
+ exit-address-family
+!
diff --git a/tests/topotests/bgp_prefix_list_any/r1/zebra.conf b/tests/topotests/bgp_prefix_list_any/r1/zebra.conf
new file mode 100644
index 0000000000..c01a8cf033
--- /dev/null
+++ b/tests/topotests/bgp_prefix_list_any/r1/zebra.conf
@@ -0,0 +1,5 @@
+!
+int r1-eth0
+ ip address 192.168.1.1/24
+ ipv6 address 2001:db8:1::1/64
+!
diff --git a/tests/topotests/bgp_prefix_list_any/r2/bgpd.conf b/tests/topotests/bgp_prefix_list_any/r2/bgpd.conf
new file mode 100644
index 0000000000..733205928f
--- /dev/null
+++ b/tests/topotests/bgp_prefix_list_any/r2/bgpd.conf
@@ -0,0 +1,50 @@
+!
+!debug bgp updates
+!
+router bgp 65002
+ no bgp ebgp-requires-policy
+ no bgp network import-check
+ neighbor 192.168.1.1 remote-as external
+ neighbor 2001:db8:1::1 remote-as external
+ address-family ipv4 unicast
+ network 10.10.10.1/32
+ network 10.10.10.2/32
+ network 10.10.10.3/32
+ network 10.10.10.10/32
+ no neighbor 2001:db8:1::1 activate
+ neighbor 192.168.1.1 route-map r1-v4 out
+ exit-address-family
+ address-family ipv6 unicast
+ network 2001:db8:10::1/128
+ network 2001:db8:10::2/128
+ network 2001:db8:10::3/128
+ network 2001:db8:10::10/128
+ neighbor 2001:db8:1::1 activate
+ neighbor 2001:db8:1::1 route-map r1-v6 out
+ exit-address-family
+!
+ip prefix-list r1-1 seq 5 permit 10.10.10.1/32
+ip prefix-list r1-1 seq 10 permit 10.10.10.2/32
+ip prefix-list r1-1 seq 15 permit 10.10.10.3/32
+ip prefix-list r1-2 seq 5 permit 10.10.10.10/32
+!
+ipv6 prefix-list r1-1 seq 5 permit 2001:db8:10::1/128
+ipv6 prefix-list r1-1 seq 10 permit 2001:db8:10::2/128
+ipv6 prefix-list r1-1 seq 15 permit 2001:db8:10::3/128
+ipv6 prefix-list r1-2 seq 5 permit 2001:db8:10::10/128
+!
+route-map r1-v4 permit 10
+ match ip address prefix-list r1-1
+exit
+!
+route-map r1-v4 permit 20
+ match ip address prefix-list r1-2
+exit
+!
+route-map r1-v6 permit 10
+ match ipv6 address prefix-list r1-1
+exit
+!
+route-map r1-v6 permit 20
+ match ipv6 address prefix-list r1-2
+exit
diff --git a/tests/topotests/bgp_prefix_list_any/r2/zebra.conf b/tests/topotests/bgp_prefix_list_any/r2/zebra.conf
new file mode 100644
index 0000000000..e90135c786
--- /dev/null
+++ b/tests/topotests/bgp_prefix_list_any/r2/zebra.conf
@@ -0,0 +1,5 @@
+!
+int r2-eth0
+ ip address 192.168.1.2/24
+ ipv6 address 2001:db8:1::2/64
+!
diff --git a/tests/topotests/bgp_prefix_list_any/test_bgp_prefix_list_any.py b/tests/topotests/bgp_prefix_list_any/test_bgp_prefix_list_any.py
new file mode 100644
index 0000000000..0eb244717e
--- /dev/null
+++ b/tests/topotests/bgp_prefix_list_any/test_bgp_prefix_list_any.py
@@ -0,0 +1,105 @@
+#!/usr/bin/env python
+# SPDX-License-Identifier: ISC
+
+# Copyright (c) 2023 by
+# Donatas Abraitis <donatas@opensourcerouting.org>
+#
+
+"""
+Test if route-map works correctly when modifying prefix-list
+from deny to permit with any, and vice-versa.
+"""
+
+import os
+import sys
+import json
+import pytest
+import functools
+
+pytestmark = pytest.mark.bgpd
+
+CWD = os.path.dirname(os.path.realpath(__file__))
+sys.path.append(os.path.join(CWD, "../"))
+
+# pylint: disable=C0413
+from lib import topotest
+from lib.topogen import Topogen, TopoRouter, get_topogen
+
+pytestmark = [pytest.mark.bgpd]
+
+
+def setup_module(mod):
+ topodef = {"s1": ("r1", "r2")}
+ tgen = Topogen(topodef, mod.__name__)
+ tgen.start_topology()
+
+ router_list = tgen.routers()
+
+ for i, (rname, router) in enumerate(router_list.items(), 1):
+ router.load_config(
+ TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname))
+ )
+ router.load_config(
+ TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname))
+ )
+
+ tgen.start_router()
+
+
+def teardown_module(mod):
+ tgen = get_topogen()
+ tgen.stop_topology()
+
+
+def test_bgp_route_map_prefix_list():
+ tgen = get_topogen()
+
+ if tgen.routers_have_failure():
+ pytest.skip(tgen.errors)
+
+ r2 = tgen.gears["r2"]
+
+ def _bgp_prefixes_sent(count):
+ output = json.loads(r2.vtysh_cmd("show bgp summary json"))
+ expected = {
+ "ipv4Unicast": {
+ "peers": {"192.168.1.1": {"pfxSnt": count, "state": "Established"}}
+ },
+ "ipv6Unicast": {
+ "peers": {"2001:db8:1::1": {"pfxSnt": count, "state": "Established"}}
+ },
+ }
+ return topotest.json_cmp(output, expected)
+
+ test_func = functools.partial(_bgp_prefixes_sent, 4)
+ _, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5)
+ assert result is None, "Can't converge initial topology"
+
+ r2.vtysh_cmd(
+ """
+ configure terminal
+ ip prefix-list r1-2 seq 5 deny any
+ ipv6 prefix-list r1-2 seq 5 deny any
+ """
+ )
+
+ test_func = functools.partial(_bgp_prefixes_sent, 3)
+ _, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5)
+ assert result is None, "Only 3 prefixes MUST be advertised, seeing more"
+
+ r2.vtysh_cmd(
+ """
+ configure terminal
+ ip prefix-list r1-2 seq 5 permit 10.10.10.10/32
+ ipv6 prefix-list r1-2 seq 5 permit 2001:db8:10::10/128
+ """
+ )
+
+ test_func = functools.partial(_bgp_prefixes_sent, 4)
+ _, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5)
+ assert result is None, "More or less prefixes advertised to r1, MUST be 4"
+
+
+if __name__ == "__main__":
+ args = ["-s"] + sys.argv[1:]
+ sys.exit(pytest.main(args))
diff --git a/tests/topotests/bgp_route_map_delay_timer/__init__.py b/tests/topotests/bgp_route_map_delay_timer/__init__.py
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/tests/topotests/bgp_route_map_delay_timer/__init__.py
diff --git a/tests/topotests/bgp_route_map_delay_timer/r1/bgpd.conf b/tests/topotests/bgp_route_map_delay_timer/r1/bgpd.conf
new file mode 100644
index 0000000000..e5325c91bc
--- /dev/null
+++ b/tests/topotests/bgp_route_map_delay_timer/r1/bgpd.conf
@@ -0,0 +1,24 @@
+!
+!debug bgp updates
+!debug bgp neighbor
+!
+bgp route-map delay-timer 5
+!
+router bgp 65001
+ no bgp ebgp-requires-policy
+ no bgp network import-check
+ neighbor 192.168.1.2 remote-as external
+ address-family ipv4 unicast
+ network 10.10.10.1/32
+ network 10.10.10.2/32
+ network 10.10.10.3/32
+ aggregate-address 10.10.10.0/24 summary-only
+ neighbor 192.168.1.2 unsuppress-map r2
+ exit-address-family
+!
+ip prefix-list r1 seq 5 permit 10.10.10.1/32
+ip prefix-list r1 seq 10 permit 10.10.10.2/32
+!
+route-map r2 permit 10
+ match ip address prefix-list r1
+exit
diff --git a/tests/topotests/bgp_route_map_delay_timer/r1/zebra.conf b/tests/topotests/bgp_route_map_delay_timer/r1/zebra.conf
new file mode 100644
index 0000000000..b29940f46a
--- /dev/null
+++ b/tests/topotests/bgp_route_map_delay_timer/r1/zebra.conf
@@ -0,0 +1,4 @@
+!
+int r1-eth0
+ ip address 192.168.1.1/24
+!
diff --git a/tests/topotests/bgp_route_map_delay_timer/r2/bgpd.conf b/tests/topotests/bgp_route_map_delay_timer/r2/bgpd.conf
new file mode 100644
index 0000000000..36653e6b1c
--- /dev/null
+++ b/tests/topotests/bgp_route_map_delay_timer/r2/bgpd.conf
@@ -0,0 +1,4 @@
+router bgp 65002
+ no bgp ebgp-requires-policy
+ neighbor 192.168.1.1 remote-as external
+!
diff --git a/tests/topotests/bgp_route_map_delay_timer/r2/zebra.conf b/tests/topotests/bgp_route_map_delay_timer/r2/zebra.conf
new file mode 100644
index 0000000000..cffe827363
--- /dev/null
+++ b/tests/topotests/bgp_route_map_delay_timer/r2/zebra.conf
@@ -0,0 +1,4 @@
+!
+int r2-eth0
+ ip address 192.168.1.2/24
+!
diff --git a/tests/topotests/bgp_route_map_delay_timer/test_bgp_route_map_delay_timer.py b/tests/topotests/bgp_route_map_delay_timer/test_bgp_route_map_delay_timer.py
new file mode 100644
index 0000000000..15a077da2e
--- /dev/null
+++ b/tests/topotests/bgp_route_map_delay_timer/test_bgp_route_map_delay_timer.py
@@ -0,0 +1,120 @@
+#!/usr/bin/env python
+# SPDX-License-Identifier: ISC
+
+# Copyright (c) 2023 by
+# Donatas Abraitis <donatas@opensourcerouting.org>
+#
+
+"""
+
+"""
+
+import os
+import sys
+import json
+import pytest
+import functools
+
+pytestmark = pytest.mark.bgpd
+
+CWD = os.path.dirname(os.path.realpath(__file__))
+sys.path.append(os.path.join(CWD, "../"))
+
+# pylint: disable=C0413
+from lib import topotest
+from lib.topogen import Topogen, TopoRouter, get_topogen
+
+pytestmark = [pytest.mark.bgpd]
+
+
+def setup_module(mod):
+ topodef = {"s1": ("r1", "r2")}
+ tgen = Topogen(topodef, mod.__name__)
+ tgen.start_topology()
+
+ router_list = tgen.routers()
+
+ for i, (rname, router) in enumerate(router_list.items(), 1):
+ router.load_config(
+ TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname))
+ )
+ router.load_config(
+ TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname))
+ )
+
+ tgen.start_router()
+
+
+def teardown_module(mod):
+ tgen = get_topogen()
+ tgen.stop_topology()
+
+
+def test_bgp_route_map_delay_timer():
+ tgen = get_topogen()
+
+ if tgen.routers_have_failure():
+ pytest.skip(tgen.errors)
+
+ r1 = tgen.gears["r1"]
+ r2 = tgen.gears["r2"]
+
+ def _bgp_converge_1():
+ output = json.loads(
+ r1.vtysh_cmd(
+ "show bgp ipv4 unicast neighbor 192.168.1.2 advertised-routes json"
+ )
+ )
+ expected = {
+ "advertisedRoutes": {
+ "10.10.10.0/24": {},
+ "10.10.10.1/32": {},
+ "10.10.10.2/32": {},
+ "10.10.10.3/32": None,
+ }
+ }
+ return topotest.json_cmp(output, expected)
+
+ test_func = functools.partial(_bgp_converge_1)
+ _, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5)
+ assert result is None, "10.10.10.3/32 should not be advertised to r2"
+
+ # Set route-map delay-timer to max value and remove 10.10.10.2/32.
+ # After this, r1 MUST do not announce updates immediately, and wait
+ # 600 seconds before withdrawing 10.10.10.2/32.
+ r2.vtysh_cmd(
+ """
+ configure terminal
+ bgp route-map delay-timer 600
+ no ip prefix-list r1 seq 10 permit 10.10.10.2/32
+ """
+ )
+
+ def _bgp_converge_2():
+ output = json.loads(
+ r1.vtysh_cmd(
+ "show bgp ipv4 unicast neighbor 192.168.1.2 advertised-routes json"
+ )
+ )
+ expected = {
+ "advertisedRoutes": {
+ "10.10.10.0/24": {},
+ "10.10.10.1/32": {},
+ "10.10.10.2/32": None,
+ "10.10.10.3/32": None,
+ }
+ }
+ return topotest.json_cmp(output, expected)
+
+ # We are checking `not None` here to wait count*wait time and if we have different
+ # results than expected, it means good - 10.10.10.2/32 wasn't withdrawn immediately.
+ test_func = functools.partial(_bgp_converge_2)
+ _, result = topotest.run_and_expect(test_func, not None, count=60, wait=0.5)
+ assert (
+ result is not None
+ ), "10.10.10.2/32 advertised, but should not be advertised to r2"
+
+
+if __name__ == "__main__":
+ args = ["-s"] + sys.argv[1:]
+ sys.exit(pytest.main(args))
diff --git a/tests/topotests/bgp_route_map_vpn_import/r1/bgpd.conf b/tests/topotests/bgp_route_map_vpn_import/r1/bgpd.conf
index c9ad0b1a5b..4aa11ec9d0 100644
--- a/tests/topotests/bgp_route_map_vpn_import/r1/bgpd.conf
+++ b/tests/topotests/bgp_route_map_vpn_import/r1/bgpd.conf
@@ -1,9 +1,9 @@
!
-debug bgp updates
-debug bgp vpn leak-from-vrf
-debug bgp vpn leak-to-vrf
-debug bgp nht
-debug route-map
+!debug bgp updates
+!debug bgp vpn leak-from-vrf
+!debug bgp vpn leak-to-vrf
+!debug bgp nht
+!debug route-map
!
router bgp 65001
bgp router-id 10.10.10.10
diff --git a/tests/topotests/bgp_route_origin_parser/pe1/bgpd.conf b/tests/topotests/bgp_route_origin_parser/pe1/bgpd.conf
new file mode 100644
index 0000000000..1929dfa69b
--- /dev/null
+++ b/tests/topotests/bgp_route_origin_parser/pe1/bgpd.conf
@@ -0,0 +1,2 @@
+router bgp 65001
+ neighbor 192.168.2.1 remote-as external
diff --git a/tests/topotests/bgp_route_origin_parser/test_bgp_route_origin_parser.py b/tests/topotests/bgp_route_origin_parser/test_bgp_route_origin_parser.py
new file mode 100644
index 0000000000..673efc2c73
--- /dev/null
+++ b/tests/topotests/bgp_route_origin_parser/test_bgp_route_origin_parser.py
@@ -0,0 +1,129 @@
+#!/usr/bin/env python
+# SPDX-License-Identifier: GPL-2.0-or-later
+#
+# April 03 2023, Trey Aspelund <taspelund@nvidia.com>
+#
+# Copyright (C) 2023 NVIDIA Corporation
+#
+# Test if the CLI parser for RT/SoO ecoms correctly
+# constrain user input to valid 4-byte ASN values.
+#
+
+import os
+import sys
+import json
+import pytest
+import functools
+
+CWD = os.path.dirname(os.path.realpath(__file__))
+sys.path.append(os.path.join(CWD, "../"))
+
+# pylint: disable=C0413
+from lib import topotest
+from lib.topogen import Topogen, TopoRouter, get_topogen
+from lib.common_config import step
+
+pytestmark = [pytest.mark.bgpd]
+
+
+def build_topo(tgen):
+ tgen.add_router("pe1")
+
+
+def setup_module(mod):
+ tgen = Topogen(build_topo, mod.__name__)
+ tgen.start_topology()
+ pe1 = tgen.gears["pe1"]
+ pe1.load_config(TopoRouter.RD_BGP, os.path.join(CWD, "pe1/bgpd.conf"))
+ tgen.start_router()
+
+
+def teardown_module(mod):
+ tgen = get_topogen()
+ tgen.stop_topology()
+
+
+def test_bgp_route_origin_parser():
+ tgen = get_topogen()
+
+ if tgen.routers_have_failure():
+ pytest.skip(tgen.errors)
+
+ pe1 = tgen.gears["pe1"]
+
+ def _invalid_soo_accepted():
+ pe1.vtysh_cmd(
+ """
+ configure terminal
+ router bgp 65001
+ address-family ipv4 unicast
+ neighbor 192.168.2.1 soo 4294967296:65
+ """
+ )
+ run_cfg = pe1.vtysh_cmd("show run")
+ return "soo" in run_cfg
+
+ def _max_soo_accepted():
+ pe1.vtysh_cmd(
+ """
+ configure terminal
+ router bgp 65001
+ address-family ipv4 unicast
+ neighbor 192.168.2.1 soo 4294967295:65
+ """
+ )
+ run_cfg = pe1.vtysh_cmd("show run")
+ return "soo 4294967295:65" in run_cfg
+
+ def _invalid_rt_accepted():
+ pe1.vtysh_cmd(
+ """
+ configure terminal
+ router bgp 65001
+ address-family ipv4 unicast
+ rt vpn both 4294967296:65
+ """
+ )
+ run_cfg = pe1.vtysh_cmd("show run")
+ return "rt vpn" in run_cfg
+
+ def _max_rt_accepted():
+ pe1.vtysh_cmd(
+ """
+ configure terminal
+ router bgp 65001
+ address-family ipv4 unicast
+ rt vpn both 4294967295:65
+ """
+ )
+ run_cfg = pe1.vtysh_cmd("show run")
+ return "rt vpn both 4294967295:65" in run_cfg
+
+ step(
+ "Configure invalid 4-byte value SoO (4294967296:65), this should not be accepted"
+ )
+ test_func = functools.partial(_invalid_soo_accepted)
+ _, result = topotest.run_and_expect(test_func, False, count=30, wait=0.5)
+ assert result is False, "invalid 4-byte value of SoO accepted"
+
+ step("Configure max 4-byte value SoO (4294967295:65), this should be accepted")
+ test_func = functools.partial(_max_soo_accepted)
+ _, result = topotest.run_and_expect(test_func, True, count=30, wait=0.5)
+ assert result is True, "max 4-byte value of SoO not accepted"
+
+ step(
+ "Configure invalid 4-byte value RT (4294967296:65), this should not be accepted"
+ )
+ test_func = functools.partial(_invalid_rt_accepted)
+ _, result = topotest.run_and_expect(test_func, False, count=30, wait=0.5)
+ assert result is False, "invalid 4-byte value of RT accepted"
+
+ step("Configure max 4-byte value RT (4294967295:65), this should be accepted")
+ test_func = functools.partial(_max_rt_accepted)
+ _, result = topotest.run_and_expect(test_func, True, count=30, wait=0.5)
+ assert result is True, "max 4-byte value of RT not accepted"
+
+
+if __name__ == "__main__":
+ args = ["-s"] + sys.argv[1:]
+ sys.exit(pytest.main(args))
diff --git a/tests/topotests/bgp_snmp_bgp4v2mib/r2/bgpd.conf b/tests/topotests/bgp_snmp_bgp4v2mib/r2/bgpd.conf
index 3512e66cec..cf0013e1b7 100644
--- a/tests/topotests/bgp_snmp_bgp4v2mib/r2/bgpd.conf
+++ b/tests/topotests/bgp_snmp_bgp4v2mib/r2/bgpd.conf
@@ -1,5 +1,5 @@
!
-debug bgp updates
+!debug bgp updates
!
router bgp 65002
no bgp ebgp-requires-policy
diff --git a/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf2/r1/zebra.conf b/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf2/r1/zebra.conf
index a9319a6aed..cbc5ce1f09 100644
--- a/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf2/r1/zebra.conf
+++ b/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf2/r1/zebra.conf
@@ -7,9 +7,9 @@ log stdout notifications
log monitor notifications
log commands
!
-debug zebra packet
-debug zebra dplane
-debug zebra kernel
+!debug zebra packet
+!debug zebra dplane
+!debug zebra kernel
!
interface eth0
ipv6 address 2001::1/64
diff --git a/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf2/r2/zebra.conf b/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf2/r2/zebra.conf
index 9e5fa0ac07..449ca74d5e 100644
--- a/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf2/r2/zebra.conf
+++ b/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf2/r2/zebra.conf
@@ -7,9 +7,9 @@ log stdout notifications
log monitor notifications
log commands
!
-debug zebra packet
-debug zebra dplane
-debug zebra kernel
+!debug zebra packet
+!debug zebra dplane
+!debug zebra kernel
!
interface eth0
ipv6 address 2001::2/64
diff --git a/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf3/r1/zebra.conf b/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf3/r1/zebra.conf
index 2c560dfc06..f913b9f002 100644
--- a/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf3/r1/zebra.conf
+++ b/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf3/r1/zebra.conf
@@ -7,9 +7,9 @@ log stdout notifications
log monitor notifications
log commands
!
-debug zebra packet
-debug zebra dplane
-debug zebra kernel
+!debug zebra packet
+!debug zebra dplane
+!debug zebra kernel
!
interface eth0
ipv6 address 2001::1/64
diff --git a/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf3/r2/bgpd.conf b/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf3/r2/bgpd.conf
index 8700f12d63..4ab5b98c12 100644
--- a/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf3/r2/bgpd.conf
+++ b/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf3/r2/bgpd.conf
@@ -1,6 +1,6 @@
frr defaults traditional
!
-bgp send-extra-data zebra
+!bgp send-extra-data zebra
!
hostname r2
password zebra
diff --git a/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf3/r2/zebra.conf b/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf3/r2/zebra.conf
index b9277a9a8c..201d0cce23 100644
--- a/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf3/r2/zebra.conf
+++ b/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf3/r2/zebra.conf
@@ -7,9 +7,9 @@ log stdout notifications
log monitor notifications
log commands
!
-debug zebra packet
-debug zebra dplane
-debug zebra kernel
+!debug zebra packet
+!debug zebra dplane
+!debug zebra kernel
!
interface eth0
ipv6 address 2001::2/64
diff --git a/tests/topotests/bgp_suppress_fib/r2/bgpd.allowas_in.conf b/tests/topotests/bgp_suppress_fib/r2/bgpd.allowas_in.conf
index caebb0e922..fb6980a139 100644
--- a/tests/topotests/bgp_suppress_fib/r2/bgpd.allowas_in.conf
+++ b/tests/topotests/bgp_suppress_fib/r2/bgpd.allowas_in.conf
@@ -2,12 +2,12 @@ access-list access seq 10 permit 192.168.1.1/32
!
ip route 192.168.1.1/32 10.0.0.10
!
-debug bgp bestpath
-debug bgp nht
-debug bgp updates
-debug bgp update-groups
-debug bgp zebra
-debug zebra rib detail
+!debug bgp bestpath
+!debug bgp nht
+!debug bgp updates
+!debug bgp update-groups
+!debug bgp zebra
+!debug zebra rib detail
!
router bgp 2
address-family ipv4 uni
diff --git a/tests/topotests/bgp_suppress_fib/r2/bgpd.conf b/tests/topotests/bgp_suppress_fib/r2/bgpd.conf
index 010e86aad7..129b812036 100644
--- a/tests/topotests/bgp_suppress_fib/r2/bgpd.conf
+++ b/tests/topotests/bgp_suppress_fib/r2/bgpd.conf
@@ -1,6 +1,6 @@
-debug bgp updates
-debug bgp bestpath 40.0.0.0/8
-debug bgp zebra
+!debug bgp updates
+!debug bgp bestpath 40.0.0.0/8
+!debug bgp zebra
!
router bgp 2
no bgp ebgp-requires-policy
@@ -8,4 +8,4 @@ router bgp 2
neighbor 10.0.0.1 remote-as 1
neighbor 10.0.0.10 remote-as 3
address-family ipv4 uni
- network 60.0.0.0/24 \ No newline at end of file
+ network 60.0.0.0/24
diff --git a/tests/topotests/bgp_suppress_fib/test_bgp_suppress_fib.py b/tests/topotests/bgp_suppress_fib/test_bgp_suppress_fib.py
index ed8e41903f..ef9200b197 100644
--- a/tests/topotests/bgp_suppress_fib/test_bgp_suppress_fib.py
+++ b/tests/topotests/bgp_suppress_fib/test_bgp_suppress_fib.py
@@ -217,6 +217,20 @@ def test_bgp_allow_as_in():
assertmsg = '"r2" 192.168.1.1/32 route should be gone'
assert result is None, assertmsg
+def test_local_vs_non_local():
+ tgen = get_topogen()
+
+ if tgen.routers_have_failure():
+ pytest.skip(tgen.errors)
+
+ r2 = tgen.gears["r2"]
+
+ output = json.loads(r2.vtysh_cmd("show bgp ipv4 uni 60.0.0.0/24 json"))
+ paths = output["paths"]
+ for i in range(len(paths)):
+ if "fibPending" in paths[i]:
+ assert(False), "Route 60.0.0.0/24 should not have fibPending"
+
if __name__ == "__main__":
args = ["-s"] + sys.argv[1:]
diff --git a/tests/topotests/bgp_vrf_md5_peering/__init__.py b/tests/topotests/bgp_vrf_md5_peering/__init__.py
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/tests/topotests/bgp_vrf_md5_peering/__init__.py
diff --git a/tests/topotests/bgp_vrf_md5_peering/exabgp.env b/tests/topotests/bgp_vrf_md5_peering/exabgp.env
new file mode 100644
index 0000000000..28e642360a
--- /dev/null
+++ b/tests/topotests/bgp_vrf_md5_peering/exabgp.env
@@ -0,0 +1,53 @@
+[exabgp.api]
+encoder = text
+highres = false
+respawn = false
+socket = ''
+
+[exabgp.bgp]
+openwait = 60
+
+[exabgp.cache]
+attributes = true
+nexthops = true
+
+[exabgp.daemon]
+daemonize = true
+pid = '/var/run/exabgp/exabgp.pid'
+user = 'exabgp'
+##daemonize = false
+
+[exabgp.log]
+all = false
+configuration = true
+daemon = true
+destination = '/var/log/exabgp.log'
+enable = true
+level = INFO
+message = false
+network = true
+packets = false
+parser = false
+processes = true
+reactor = true
+rib = false
+routes = false
+short = false
+timers = false
+
+[exabgp.pdb]
+enable = false
+
+[exabgp.profile]
+enable = false
+file = ''
+
+[exabgp.reactor]
+speed = 1.0
+
+[exabgp.tcp]
+acl = false
+bind = ''
+delay = 0
+once = false
+port = 179
diff --git a/tests/topotests/bgp_vrf_md5_peering/peer1/exabgp.cfg b/tests/topotests/bgp_vrf_md5_peering/peer1/exabgp.cfg
new file mode 100644
index 0000000000..3260513903
--- /dev/null
+++ b/tests/topotests/bgp_vrf_md5_peering/peer1/exabgp.cfg
@@ -0,0 +1,13 @@
+neighbor 10.0.0.1 {
+ router-id 10.0.0.2;
+ local-address 10.0.0.2;
+ local-as 65001;
+ peer-as 65534;
+ md5 test123;
+
+ static {
+ route 192.168.100.1/32 {
+ next-hop 10.0.0.2;
+ }
+ }
+}
diff --git a/tests/topotests/bgp_vrf_md5_peering/r1/bgpd.conf b/tests/topotests/bgp_vrf_md5_peering/r1/bgpd.conf
new file mode 100644
index 0000000000..9f2ee19357
--- /dev/null
+++ b/tests/topotests/bgp_vrf_md5_peering/r1/bgpd.conf
@@ -0,0 +1,11 @@
+!
+!debug bgp neighbor
+!
+router bgp 65534 vrf public
+ bgp router-id 10.0.0.1
+ no bgp ebgp-requires-policy
+ neighbor 10.0.0.2 remote-as external
+ neighbor 10.0.0.2 timers 3 10
+ neighbor 10.0.0.2 timers connect 1
+ neighbor 10.0.0.2 password test123
+!
diff --git a/tests/topotests/bgp_vrf_md5_peering/r1/zebra.conf b/tests/topotests/bgp_vrf_md5_peering/r1/zebra.conf
new file mode 100644
index 0000000000..0c183ae785
--- /dev/null
+++ b/tests/topotests/bgp_vrf_md5_peering/r1/zebra.conf
@@ -0,0 +1,6 @@
+!
+interface r1-eth0 vrf public
+ ip address 10.0.0.1/24
+!
+ip forwarding
+!
diff --git a/tests/topotests/bgp_vrf_md5_peering/test_bgp_vrf_md5_peering.py b/tests/topotests/bgp_vrf_md5_peering/test_bgp_vrf_md5_peering.py
new file mode 100644
index 0000000000..eefe586d7b
--- /dev/null
+++ b/tests/topotests/bgp_vrf_md5_peering/test_bgp_vrf_md5_peering.py
@@ -0,0 +1,87 @@
+#!/usr/bin/env python
+# SPDX-License-Identifier: ISC
+
+#
+# Copyright (c) 2023 by
+# Donatas Abraitis <donatas.abraitis@gmail.com>
+#
+
+"""
+Test if BGP MD5 basic authentication works per-VRF.
+"""
+
+import os
+import sys
+import json
+import pytest
+import functools
+
+CWD = os.path.dirname(os.path.realpath(__file__))
+sys.path.append(os.path.join(CWD, "../"))
+
+# pylint: disable=C0413
+from lib import topotest
+from lib.topogen import Topogen, TopoRouter, get_topogen
+
+pytestmark = [pytest.mark.bgpd]
+
+
+def build_topo(tgen):
+ r1 = tgen.add_router("r1")
+ peer1 = tgen.add_exabgp_peer("peer1", ip="10.0.0.2", defaultRoute="via 10.0.0.1")
+
+ switch = tgen.add_switch("s1")
+ switch.add_link(r1)
+ switch.add_link(peer1)
+
+
+def setup_module(mod):
+ tgen = Topogen(build_topo, mod.__name__)
+ tgen.start_topology()
+
+ r1 = tgen.gears["r1"]
+ r1.load_config(TopoRouter.RD_ZEBRA, os.path.join(CWD, "r1/zebra.conf"))
+ r1.load_config(TopoRouter.RD_BGP, os.path.join(CWD, "r1/bgpd.conf"))
+ r1.start()
+
+ peer = tgen.gears["peer1"]
+ peer.start(os.path.join(CWD, "peer1"), os.path.join(CWD, "exabgp.env"))
+
+ # VRF 'public'
+ r1.cmd_raises("ip link add public type vrf table 1001")
+ r1.cmd_raises("ip link set up dev public")
+ r1.cmd_raises("ip link set r1-eth0 master public")
+
+
+def teardown_module(mod):
+ tgen = get_topogen()
+ tgen.stop_topology()
+
+
+def test_bgp_vrf_md5_peering():
+ tgen = get_topogen()
+
+ if tgen.routers_have_failure():
+ pytest.skip(tgen.errors)
+
+ def _bgp_converge():
+ output = json.loads(
+ tgen.gears["r1"].vtysh_cmd("show ip bgp vrf public neighbor 10.0.0.2 json")
+ )
+ expected = {
+ "10.0.0.2": {
+ "bgpState": "Established",
+ "addressFamilyInfo": {"ipv4Unicast": {"acceptedPrefixCounter": 1}},
+ }
+ }
+ return topotest.json_cmp(output, expected)
+
+ test_func = functools.partial(_bgp_converge)
+ _, result = topotest.run_and_expect(test_func, None, count=30, wait=1)
+
+ assert result is None, "Can't peer with md5 per-VRF"
+
+
+if __name__ == "__main__":
+ args = ["-s"] + sys.argv[1:]
+ sys.exit(pytest.main(args))
diff --git a/tests/topotests/config_timing/test_config_timing.py b/tests/topotests/config_timing/test_config_timing.py
index fec9d485b5..5c1b97262c 100644
--- a/tests/topotests/config_timing/test_config_timing.py
+++ b/tests/topotests/config_timing/test_config_timing.py
@@ -24,7 +24,7 @@ import math
import os
import sys
import pytest
-
+from lib import topotest
CWD = os.path.dirname(os.path.realpath(__file__))
sys.path.append(os.path.join(CWD, "../"))
@@ -109,7 +109,9 @@ def test_static_timing():
router.logdir, rname, "{}-routes-{}.conf".format(iptype.lower(), optype)
)
with open(config_file, "w") as f:
- for i, net in enumerate(get_ip_networks(super_prefix, base_count, count)):
+ for i, net in enumerate(
+ get_ip_networks(super_prefix, base_count, count)
+ ):
if i in bad_indices:
if add:
f.write("ip route {} {} bad_input\n".format(net, via))
@@ -131,7 +133,7 @@ def test_static_timing():
delta = (datetime.datetime.now() - tstamp).total_seconds()
tot_delta += delta
- router.logger.info(
+ router.logger.debug(
"\nvtysh command => {}\nvtysh output <= {}\nin {}s".format(
load_command, output, delta
)
@@ -148,10 +150,9 @@ def test_static_timing():
return tot_delta
-
# Number of static routes
router = tgen.gears["r1"]
- output = router.run("vtysh -h | grep address-sanitizer")
+ output = router.net.cmd_legacy("vtysh -h | grep address-sanitizer", warn=False)
if output == "":
logger.info("No Address Sanitizer, generating 10000 routes")
prefix_count = 10000
@@ -164,20 +165,49 @@ def test_static_timing():
[u"2100:1111:2220::/44", u"2100:3333:4440::/44"],
]
+ # This apparently needed to allow for various mgmtd/staticd/zebra connections to form
+ # which then SLOWS execution down. If we don't include this value then the
+ # initial, baseline establishing, time is 2 time faster (e.g., 5s instead of 10s),
+ # but all later runs are slower and fail.
+ #
+ # This should be done differently based on actual facts.
+ topotest.sleep(5)
+
bad_indices = []
for ipv6 in [False, True]:
base_delta = do_config(
- prefix_count, prefix_count, bad_indices, 0, 0, True, ipv6, prefix_base[ipv6][0]
+ prefix_count,
+ prefix_count,
+ bad_indices,
+ 0,
+ 0,
+ True,
+ ipv6,
+ prefix_base[ipv6][0],
)
# Another set of same number of prefixes
do_config(
- prefix_count, prefix_count, bad_indices, base_delta, 3, True, ipv6, prefix_base[ipv6][1]
+ prefix_count,
+ prefix_count,
+ bad_indices,
+ base_delta,
+ 3,
+ True,
+ ipv6,
+ prefix_base[ipv6][1],
)
# Duplicate config
do_config(
- prefix_count, prefix_count, bad_indices, base_delta, 3, True, ipv6, prefix_base[ipv6][0]
+ prefix_count,
+ prefix_count,
+ bad_indices,
+ base_delta,
+ 3,
+ True,
+ ipv6,
+ prefix_base[ipv6][0],
)
# Remove 1/2 of duplicate
@@ -194,15 +224,36 @@ def test_static_timing():
# Add all back in so 1/2 replicate 1/2 new
do_config(
- prefix_count, prefix_count, bad_indices, base_delta, 3, True, ipv6, prefix_base[ipv6][0]
+ prefix_count,
+ prefix_count,
+ bad_indices,
+ base_delta,
+ 3,
+ True,
+ ipv6,
+ prefix_base[ipv6][0],
)
# remove all
delta = do_config(
- prefix_count, prefix_count, bad_indices, base_delta, 3, False, ipv6, prefix_base[ipv6][0]
+ prefix_count,
+ prefix_count,
+ bad_indices,
+ base_delta,
+ 3,
+ False,
+ ipv6,
+ prefix_base[ipv6][0],
)
delta += do_config(
- prefix_count, prefix_count, bad_indices, base_delta, 3, False, ipv6, prefix_base[ipv6][1]
+ prefix_count,
+ prefix_count,
+ bad_indices,
+ base_delta,
+ 3,
+ False,
+ ipv6,
+ prefix_base[ipv6][1],
)
diff --git a/tests/topotests/isis_snmp/r5/ldpdconf b/tests/topotests/isis_snmp/r5/ldpdconf
index fc700608b5..b3d10b07ec 100644
--- a/tests/topotests/isis_snmp/r5/ldpdconf
+++ b/tests/topotests/isis_snmp/r5/ldpdconf
@@ -1,10 +1,10 @@
hostname r5
log file ldpd.log
!
-debug mpls ldp zebra
-debug mpls ldp event
-debug mpls ldp errors
-debug mpls ldp sync
+!debug mpls ldp zebra
+!debug mpls ldp event
+!debug mpls ldp errors
+!debug mpls ldp sync
!
mpls ldp
router-id 3.3.3.3
diff --git a/tests/topotests/isis_topo1/test_isis_topo1.py b/tests/topotests/isis_topo1/test_isis_topo1.py
index baacba613d..48e9d5336f 100644
--- a/tests/topotests/isis_topo1/test_isis_topo1.py
+++ b/tests/topotests/isis_topo1/test_isis_topo1.py
@@ -572,6 +572,98 @@ def test_isis_advertise_passive_only():
assert result is True, result
+def test_isis_hello_padding_during_adjacency_formation():
+ """Check that IIH packets is only padded when adjacency is still being formed
+ when isis hello padding during-adjacency-formation is configured
+ """
+ tgen = get_topogen()
+ net = get_topogen().net
+ # Don't run this test if we have any failure.
+ if tgen.routers_have_failure():
+ pytest.skip(tgen.errors)
+
+ logger.info("Testing isis hello padding during-adjacency-formation behavior")
+ r3 = tgen.gears["r3"]
+
+ # Reduce hello-multiplier to make the adjacency go down faster.
+ r3.vtysh_cmd(
+ """
+ configure
+ interface r3-eth0
+ isis hello-multiplier 2
+ """
+ )
+
+ r1 = tgen.gears["r1"]
+ cmd_output = r1.vtysh_cmd(
+ """
+ configure
+ interface r1-eth0
+ isis hello padding during-adjacency-formation
+ end
+ debug isis adj-packets
+ """
+ )
+ result = check_last_iih_packet_for_padding(r1, expect_padding=False)
+ assert result is True, result
+
+ r3.vtysh_cmd(
+ """
+ configure
+ interface r3-eth0
+ shutdown
+ """
+ )
+ result = check_last_iih_packet_for_padding(r1, expect_padding=True)
+ assert result is True, result
+
+ r3 = tgen.gears["r3"]
+ r3.vtysh_cmd(
+ """
+ configure
+ interface r3-eth0
+ no shutdown
+ """
+ )
+ result = check_last_iih_packet_for_padding(r1, expect_padding=False)
+ assert result is True, result
+
+
+@retry(retry_timeout=5)
+def check_last_iih_packet_for_padding(router, expect_padding):
+ logfilename = "{}/{}".format(router.gearlogdir, "isisd.log")
+ last_hello_packet_line = None
+ with open(logfilename, "r") as f:
+ lines = f.readlines()
+ for line in lines:
+ if re.search("Sending .+? IIH", line):
+ last_hello_packet_line = line
+
+ if last_hello_packet_line is None:
+ return "Expected IIH packet in {}, but no packet found".format(logfilename)
+
+ interface_name, packet_length = re.search(
+ r"Sending .+ IIH on (.+), length (\d+)", last_hello_packet_line
+ ).group(1, 2)
+ packet_length = int(packet_length)
+ interface_output = router.vtysh_cmd("show interface {} json".format(interface_name))
+ interface_json = json.loads(interface_output)
+ padded_packet_length = interface_json[interface_name]["mtu"] - 3
+ if expect_padding:
+ if packet_length == padded_packet_length:
+ return True
+ return (
+ "Expected padded packet with length {}, got packet with length {}".format(
+ padded_packet_length, packet_length
+ )
+ )
+ if packet_length < padded_packet_length:
+ return True
+ return "Expected unpadded packet with length less than {}, got packet with length {}".format(
+ padded_packet_length, packet_length
+ )
+
+
@retry(retry_timeout=5)
def check_advertised_prefixes(router, lsp_id, expected_prefixes):
output = router.vtysh_cmd("show isis database detail {}".format(lsp_id))
diff --git a/tests/topotests/lib/common_config.py b/tests/topotests/lib/common_config.py
index 3e02769d87..d19d8db75c 100644
--- a/tests/topotests/lib/common_config.py
+++ b/tests/topotests/lib/common_config.py
@@ -110,6 +110,7 @@ DEBUG_LOGS = {
"debug zebra vxlan",
"debug zebra nht",
],
+ "mgmt": [],
"ospf": [
"debug ospf event",
"debug ospf ism",
@@ -450,6 +451,8 @@ def check_router_status(tgen):
result = rnode.check_router_running()
if result != "":
daemons = []
+ if "mgmtd" in result:
+ daemons.append("mgmtd")
if "bgpd" in result:
daemons.append("bgpd")
if "zebra" in result:
@@ -489,7 +492,7 @@ def save_initial_config_on_routers(tgen):
# Get all running configs in parallel
procs = {}
for rname in router_list:
- logger.info("Fetching running config for router %s", rname)
+ logger.debug("Fetching running config for router %s", rname)
procs[rname] = router_list[rname].popen(
["/usr/bin/env", "vtysh", "-c", "show running-config no-header"],
stdin=None,
@@ -545,7 +548,7 @@ def reset_config_on_routers(tgen, routerName=None):
#
procs = {}
for rname in router_list:
- logger.info("Fetching running config for router %s", rname)
+ logger.debug("Fetching running config for router %s", rname)
procs[rname] = router_list[rname].popen(
["/usr/bin/env", "vtysh", "-c", "show running-config no-header"],
stdin=None,
@@ -567,7 +570,7 @@ def reset_config_on_routers(tgen, routerName=None):
#
procs = {}
for rname in router_list:
- logger.info(
+ logger.debug(
"Generating delta for router %s to new configuration (gen %d)", rname, gen
)
procs[rname] = tgen.net.popen(
@@ -596,7 +599,7 @@ def reset_config_on_routers(tgen, routerName=None):
#
procs = {}
for rname in router_list:
- logger.info("Applying delta config on router %s", rname)
+ logger.debug("Applying delta config on router %s", rname)
procs[rname] = router_list[rname].popen(
["/usr/bin/env", "vtysh", "-f", delta_fmt.format(rname, gen)],
@@ -608,7 +611,7 @@ def reset_config_on_routers(tgen, routerName=None):
output, _ = p.communicate()
vtysh_command = "vtysh -f {}".format(delta_fmt.format(rname, gen))
if not p.returncode:
- router_list[rname].logger.info(
+ router_list[rname].logger.debug(
'\nvtysh config apply => "{}"\nvtysh output <= "{}"'.format(
vtysh_command, output
)
@@ -637,7 +640,7 @@ def reset_config_on_routers(tgen, routerName=None):
if show_router_config:
procs = {}
for rname in router_list:
- logger.info("Fetching running config for router %s", rname)
+ logger.debug("Fetching running config for router %s", rname)
procs[rname] = router_list[rname].popen(
["/usr/bin/env", "vtysh", "-c", "show running-config no-header"],
stdin=None,
@@ -654,7 +657,7 @@ def reset_config_on_routers(tgen, routerName=None):
output,
)
else:
- logger.info(
+ logger.debug(
"Configuration on router %s after reset:\n%s", rname, output
)
@@ -739,7 +742,7 @@ def load_config_to_routers(tgen, routers, save_bkup=False):
frr_cfg_bkup = frr_cfg_bkup_fmt.format(rname)
with open(frr_cfg_file, "r+") as cfg:
data = cfg.read()
- logger.info(
+ logger.debug(
"Applying following configuration on router %s (gen: %d):\n%s",
rname,
gen,
@@ -772,7 +775,7 @@ def load_config_to_routers(tgen, routers, save_bkup=False):
frr_cfg_file = frr_cfg_file_fmt.format(rname)
vtysh_command = "vtysh -f " + frr_cfg_file
if not p.returncode:
- router_list[rname].logger.info(
+ router_list[rname].logger.debug(
'\nvtysh config apply => "{}"\nvtysh output <= "{}"'.format(
vtysh_command, output
)
@@ -818,7 +821,7 @@ def load_config_to_routers(tgen, routers, save_bkup=False):
output,
)
else:
- logger.info("New configuration for router %s:\n%s", rname, output)
+ logger.debug("New configuration for router %s:\n%s", rname, output)
logger.debug("Exiting API: load_config_to_routers")
return not errors
@@ -954,10 +957,10 @@ def generate_support_bundle():
bundle_procs[rname] = tgen.net[rname].popen(gen_sup_cmd, stdin=None)
for rname, rnode in router_list.items():
- logger.info("Waiting on support bundle for %s", rname)
+ logger.debug("Waiting on support bundle for %s", rname)
output, error = bundle_procs[rname].communicate()
if output:
- logger.info(
+ logger.debug(
"Output from collecting support bundle for %s:\n%s", rname, output
)
if error:
@@ -1047,6 +1050,11 @@ def start_topology(tgen):
feature.add("ospf6")
break
+ # Loading empty mgmtd.conf file to router, to start the mgmtd daemon
+ router.load_config(
+ TopoRouter.RD_MGMTD, "{}/{}/mgmtd.conf".format(tgen.logdir, rname)
+ )
+
# Loading empty zebra.conf file to router, to start the zebra deamon
router.load_config(
TopoRouter.RD_ZEBRA, "{}/{}/zebra.conf".format(tgen.logdir, rname)
@@ -1226,15 +1234,15 @@ def add_interfaces_to_vlan(tgen, input_dict):
cmd = "ip link add link {} name {} type vlan id {}".format(
interface, vlan_intf, vlan
)
- logger.info("[DUT: %s]: Running command: %s", dut, cmd)
+ logger.debug("[DUT: %s]: Running command: %s", dut, cmd)
result = rnode.run(cmd)
- logger.info("result %s", result)
+ logger.debug("result %s", result)
# Bringing interface up
cmd = "ip link set {} up".format(vlan_intf)
- logger.info("[DUT: %s]: Running command: %s", dut, cmd)
+ logger.debug("[DUT: %s]: Running command: %s", dut, cmd)
result = rnode.run(cmd)
- logger.info("result %s", result)
+ logger.debug("result %s", result)
# Assigning IP address
ifaddr = ipaddress.ip_interface(
@@ -1246,9 +1254,9 @@ def add_interfaces_to_vlan(tgen, input_dict):
cmd = "ip -{0} a flush {1} scope global && ip a add {2} dev {1} && ip l set {1} up".format(
ifaddr.version, vlan_intf, ifaddr
)
- logger.info("[DUT: %s]: Running command: %s", dut, cmd)
+ logger.debug("[DUT: %s]: Running command: %s", dut, cmd)
result = rnode.run(cmd)
- logger.info("result %s", result)
+ logger.debug("result %s", result)
def tcpdump_capture_start(
@@ -1559,12 +1567,16 @@ def create_vrf_cfg(tgen, topo, input_dict=None, build=False):
vrf["name"], vrf["id"]
)
- logger.info("[DUT: %s]: Running kernel cmd [%s]", c_router, cmd)
+ logger.debug(
+ "[DUT: %s]: Running kernel cmd [%s]", c_router, cmd
+ )
rnode.run(cmd)
# Kernel cmd - Bring down VRF
cmd = "ip link set dev {} down".format(name)
- logger.info("[DUT: %s]: Running kernel cmd [%s]", c_router, cmd)
+ logger.debug(
+ "[DUT: %s]: Running kernel cmd [%s]", c_router, cmd
+ )
rnode.run(cmd)
else:
@@ -1573,14 +1585,14 @@ def create_vrf_cfg(tgen, topo, input_dict=None, build=False):
cmd = "ip link add {} type vrf table {}".format(
name, table_id
)
- logger.info(
+ logger.debug(
"[DUT: %s]: Running kernel cmd " "[%s]", c_router, cmd
)
rnode.run(cmd)
# Kernel cmd - Bring up VRF
cmd = "ip link set dev {} up".format(name)
- logger.info(
+ logger.debug(
"[DUT: %s]: Running kernel " "cmd [%s]", c_router, cmd
)
rnode.run(cmd)
@@ -1608,7 +1620,7 @@ def create_vrf_cfg(tgen, topo, input_dict=None, build=False):
interface_name, _vrf
)
- logger.info(
+ logger.debug(
"[DUT: %s]: Running" " kernel cmd [%s]",
c_router,
cmd,
@@ -1675,7 +1687,7 @@ def create_interface_in_kernel(
cmd = "ip -{0} a flush {1} scope global && ip a add {2} dev {1} && ip l set {1} up".format(
ifaddr.version, name, ifaddr
)
- logger.info("[DUT: %s]: Running command: %s", dut, cmd)
+ logger.debug("[DUT: %s]: Running command: %s", dut, cmd)
rnode.run(cmd)
if vrf:
@@ -1707,7 +1719,7 @@ def shutdown_bringup_interface_in_kernel(tgen, dut, intf_name, ifaceaction=False
action = "down"
cmd = "{} {} {}".format(cmd, intf_name, action)
- logger.info("[DUT: %s]: Running command: %s", dut, cmd)
+ logger.debug("[DUT: %s]: Running command: %s", dut, cmd)
rnode.run(cmd)
@@ -1960,7 +1972,7 @@ def retry(retry_timeout, initial_wait=0, expected=True, diag_pct=0.75):
)
if initial_wait > 0:
- logger.info("Waiting for [%s]s as initial delay", initial_wait)
+ logger.debug("Waiting for [%s]s as initial delay", initial_wait)
sleep(initial_wait)
invert_logic = not _expected
@@ -2019,13 +2031,13 @@ def retry(retry_timeout, initial_wait=0, expected=True, diag_pct=0.75):
return saved_failure
if saved_failure:
- logger.info(
+ logger.debug(
"RETRY DIAG: [failure] Sleeping %ds until next retry with %.1f retry time left - too see if timeout was too short",
retry_sleep,
seconds_left,
)
else:
- logger.info(
+ logger.debug(
"Sleeping %ds until next retry with %.1f retry time left",
retry_sleep,
seconds_left,
@@ -2590,7 +2602,7 @@ def create_route_maps(tgen, input_dict, build=False):
nexthop = set_data.setdefault("nexthop", None)
origin = set_data.setdefault("origin", None)
ext_comm_list = set_data.setdefault("extcommunity", {})
- metrictype = set_data.setdefault("metric-type", {})
+ metrictype = set_data.setdefault("metric-type", None)
# Local Preference
if local_preference:
@@ -3349,7 +3361,19 @@ def socat_send_mld_join(
# Run socat command to send IGMP join
logger.info("[DUT: {}]: Running command: [{}]".format(server, socat_cmd))
- output = rnode.run("set +m; {} sleep 0.5".format(socat_cmd))
+ output = rnode.run("set +m; {} echo $!".format(socat_cmd))
+
+ # Check if socat join process is running
+ if output:
+ pid = output.split()[0]
+ rnode.run("touch /var/run/frr/socat_join.pid")
+ rnode.run("echo %s >> /var/run/frr/socat_join.pid" % pid)
+ else:
+ errormsg = "Socat join is not sent for {}. Error {}".format(
+ mld_group, output
+ )
+ logger.error(output)
+ return errormsg
logger.debug("Exiting lib API: {}".format(sys._getframe().f_code.co_name))
return True
@@ -3407,7 +3431,7 @@ def socat_send_pim6_traffic(
if multicast_hops:
socat_cmd += "multicast-hops=255'"
- socat_cmd += " &>{}/socat.logs &".format(tgen.logdir)
+ socat_cmd += " >{}/socat.logs &".format(tgen.logdir)
# Run socat command to send pim6 traffic
logger.info(
@@ -3427,7 +3451,20 @@ def socat_send_pim6_traffic(
)
rnode.run("chmod 755 {}".format(traffic_shell_script))
- output = rnode.run("{} &> /dev/null".format(traffic_shell_script))
+ output = rnode.run("{} &>/dev/null & echo $!".format(traffic_shell_script))
+
+ # Check if socat traffic process is running
+ if output:
+ pid = output.split()[0]
+ rnode.run("touch /var/run/frr/socat_traffic.pid")
+ rnode.run("echo %s >> /var/run/frr/socat_traffic.pid" % pid)
+
+ else:
+ errormsg = "Socat traffic is not sent for {}. Error {}".format(
+ mld_group, output
+ )
+ logger.error(output)
+ return errormsg
logger.debug("Exiting lib API: {}".format(sys._getframe().f_code.co_name))
return True
@@ -3457,18 +3494,30 @@ def kill_socat(tgen, dut=None, action=None):
if dut is not None and router != dut:
continue
+ traffic_shell_script = "{}/{}/traffic.sh".format(tgen.logdir, router)
+ pid_socat_join = rnode.run("cat /var/run/frr/socat_join.pid")
+ pid_socat_traffic = rnode.run("cat /var/run/frr/socat_traffic.pid")
if action == "remove_mld_join":
- cmd = "ps -ef | grep socat | grep UDP6-RECV | grep {}".format(router)
+ pids = pid_socat_join
elif action == "remove_mld_traffic":
- cmd = "ps -ef | grep socat | grep UDP6-SEND | grep {}".format(router)
+ pids = pid_socat_traffic
else:
- cmd = "ps -ef | grep socat".format(router)
-
- awk_cmd = "awk -F' ' '{print $2}' | xargs kill -9 &>/dev/null &"
- cmd = "{} | {}".format(cmd, awk_cmd)
+ pids = "\n".join([pid_socat_join, pid_socat_traffic])
- logger.debug("[DUT: {}]: Running command: [{}]".format(router, cmd))
- rnode.run(cmd)
+ if os.path.exists(traffic_shell_script):
+ cmd = (
+ "ps -ef | grep %s | awk -F' ' '{print $2}' | xargs kill -9"
+ % traffic_shell_script
+ )
+ logger.debug("[DUT: {}]: Running command: [{}]".format(router, cmd))
+ rnode.run(cmd)
+
+ for pid in pids.split("\n"):
+ pid = pid.strip()
+ if pid.isdigit():
+ cmd = "set +m; kill -9 %s &> /dev/null" % pid
+ logger.debug("[DUT: {}]: Running command: [{}]".format(router, cmd))
+ rnode.run(cmd)
logger.debug("Exiting lib API: {}".format(sys._getframe().f_code.co_name))
diff --git a/tests/topotests/lib/micronet_compat.py b/tests/topotests/lib/micronet_compat.py
index 5a69c56d8d..edbd360084 100644
--- a/tests/topotests/lib/micronet_compat.py
+++ b/tests/topotests/lib/micronet_compat.py
@@ -161,12 +161,10 @@ class Mininet(Micronet):
g_mnet_inst = None
- def __init__(self, controller=None):
+ def __init__(self):
"""
Create a Micronet.
"""
- assert not controller
-
if Mininet.g_mnet_inst is not None:
Mininet.g_mnet_inst.stop()
Mininet.g_mnet_inst = self
diff --git a/tests/topotests/lib/pim.py b/tests/topotests/lib/pim.py
index e5af24d419..6878d93f37 100644
--- a/tests/topotests/lib/pim.py
+++ b/tests/topotests/lib/pim.py
@@ -4524,12 +4524,11 @@ def verify_mld_config(tgen, input_dict, stats_return=False, expected=True):
for dut in input_dict.keys():
rnode = tgen.routers()[dut]
-
- for interface, data in input_dict[dut]["igmp"]["interfaces"].items():
+ for interface, data in input_dict[dut]["mld"]["interfaces"].items():
statistics = False
report = False
- if "statistics" in input_dict[dut]["igmp"]["interfaces"][interface]["igmp"]:
+ if "statistics" in input_dict[dut]["mld"]["interfaces"][interface]["mld"]:
statistics = True
cmd = "show ipv6 mld statistics"
else:
@@ -4556,6 +4555,8 @@ def verify_mld_config(tgen, input_dict, stats_return=False, expected=True):
rnode, "{} interface {} json".format(cmd, interface), isjson=True
)
+ show_ipv6_mld_intf_json = show_ipv6_mld_intf_json["default"]
+
if not report:
if interface not in show_ipv6_mld_intf_json:
errormsg = (
@@ -4636,7 +4637,7 @@ def verify_mld_config(tgen, input_dict, stats_return=False, expected=True):
for query, value in data["mld"]["query"].items():
if query == "query-interval":
# Verifying IGMP interface query interval timer
- if intf_detail_json["timerQueryInterval"] != value:
+ if intf_detail_json["timerQueryIntervalMsec"] != value * 1000:
errormsg = (
"[DUT %s]: MLD interface: %s "
" query-interval verification "
@@ -4646,7 +4647,7 @@ def verify_mld_config(tgen, input_dict, stats_return=False, expected=True):
dut,
interface,
value,
- intf_detail_json["timerQueryInterval"],
+ intf_detail_json["timerQueryIntervalMsec"],
)
)
return errormsg
@@ -4655,13 +4656,13 @@ def verify_mld_config(tgen, input_dict, stats_return=False, expected=True):
"[DUT %s]: MLD interface: %s " "query-interval is %s",
dut,
interface,
- value,
+ value * 1000,
)
if query == "query-max-response-time":
# Verifying IGMP interface query max response timer
if (
- intf_detail_json["timerQueryResponseIntervalMsec"]
+ intf_detail_json["timerQueryResponseTimerMsec"]
!= value * 100
):
errormsg = (
@@ -4672,8 +4673,8 @@ def verify_mld_config(tgen, input_dict, stats_return=False, expected=True):
% (
dut,
interface,
- value * 1000,
- intf_detail_json["timerQueryResponseIntervalMsec"],
+ value * 100,
+ intf_detail_json["timerQueryResponseTimerMsec"],
)
)
return errormsg
@@ -4714,8 +4715,8 @@ def verify_mld_config(tgen, input_dict, stats_return=False, expected=True):
if query == "last-member-query-interval":
# Verifying IGMP interface last member query interval
if (
- intf_detail_json["timerLastMemberQueryMsec"]
- != value * 100 * intf_detail_json["lastMemberQueryCount"]
+ intf_detail_json["timerLastMemberQueryIntervalMsec"]
+ != value * 100
):
errormsg = (
"[DUT %s]: MLD interface: %s "
@@ -4725,8 +4726,10 @@ def verify_mld_config(tgen, input_dict, stats_return=False, expected=True):
% (
dut,
interface,
- value * 1000,
- intf_detail_json["timerLastMemberQueryMsec"],
+ value * 100,
+ intf_detail_json[
+ "timerLastMemberQueryIntervalMsec"
+ ],
)
)
return errormsg
@@ -4736,7 +4739,7 @@ def verify_mld_config(tgen, input_dict, stats_return=False, expected=True):
"last-member-query-interval is %s ms",
dut,
interface,
- value * intf_detail_json["lastMemberQueryCount"] * 100,
+ value * 100,
)
if "version" in data["mld"]:
@@ -4761,7 +4764,7 @@ def verify_mld_config(tgen, input_dict, stats_return=False, expected=True):
@retry(retry_timeout=60, diag_pct=0)
-def verify_pim_nexthop(tgen, topo, dut, nexthop, addr_type):
+def verify_pim_nexthop(tgen, topo, dut, nexthop, addr_type="ipv4"):
"""
Verify all PIM nexthop details using "show ip/ipv6 pim neighbor" cli
@@ -4895,6 +4898,7 @@ def verify_mroute_summary(
return True
+@retry(retry_timeout=60, diag_pct=0)
def verify_sg_traffic(tgen, dut, groups, src, addr_type="ipv4"):
"""
Verify multicast traffic by running
@@ -4907,7 +4911,7 @@ def verify_sg_traffic(tgen, dut, groups, src, addr_type="ipv4"):
Usage
-----
- result = verify_sg_traffic(tgen, "r1", igmp_groups, srcaddress)
+ result = verify_sg_traffic(tgen, "r1", igmp_groups/mld_groups, srcaddress)
Returns
-------
@@ -4973,7 +4977,7 @@ def verify_sg_traffic(tgen, dut, groups, src, addr_type="ipv4"):
after_traffic[grp] = show_mroute_sg_traffic_json[grp][src]["packets"]
for grp in groups:
- if after_traffic[grp] < before_traffic[grp]:
+ if after_traffic[grp] <= before_traffic[grp]:
errormsg = (
"[DUT %s]: Verifying igmp group %s source %s not increamenting traffic"
" [FAILED]!! " % (dut, grp, src)
@@ -4988,6 +4992,134 @@ def verify_sg_traffic(tgen, dut, groups, src, addr_type="ipv4"):
return result
+
+@retry(retry_timeout=60, diag_pct=0)
+def verify_pim6_config(tgen, input_dict, expected=True):
+ """
+ Verify pim interface details, verifying following configs:
+ drPriority
+ helloPeriod
+ helloReceived
+ helloSend
+ drAddress
+
+ Parameters
+ ----------
+ * `tgen`: topogen object
+ * `input_dict` : Input dict data, required to verify
+ timer
+ * `expected` : expected results from API, by-default True
+
+ Usage
+ -----
+ input_dict ={
+ "l1": {
+ "mld": {
+ "interfaces": {
+ "l1-i1-eth1": {
+ "pim6": {
+ "drPriority" : 10,
+ "helloPeriod" : 5
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ result = verify_pim6_config(tgen, input_dict)
+
+ Returns
+ -------
+ errormsg(str) or True
+ """
+
+ logger.debug("Entering lib API: {}".format(sys._getframe().f_code.co_name))
+
+ for dut in input_dict.keys():
+ rnode = tgen.routers()[dut]
+
+ for interface, data in input_dict[dut]["pim6"]["interfaces"].items():
+
+ logger.info(
+ "[DUT: %s]: Verifying PIM6 interface %s detail:", dut, interface
+ )
+
+ show_ipv6_pim_intf_json = run_frr_cmd(
+ rnode, "show ipv6 pim interface {} json".format(interface), isjson=True
+ )
+
+ if interface not in show_ipv6_pim_intf_json:
+ errormsg = (
+ "[DUT %s]: PIM6 interface: %s "
+ " is not present in CLI output "
+ "[FAILED]!! " % (dut, interface)
+ )
+ return errormsg
+
+ intf_detail_json = show_ipv6_pim_intf_json[interface]
+
+ for config, value in data.items():
+ if config == "helloPeriod":
+ # Verifying PIM interface helloPeriod
+ if intf_detail_json["helloPeriod"] != value:
+ errormsg = (
+ "[DUT %s]: PIM6 interface: %s "
+ " helloPeriod verification "
+ "[FAILED]!! Expected : %s,"
+ " Found : %s"
+ % (dut, interface, value, intf_detail_json["helloPeriod"])
+ )
+ return errormsg
+
+ logger.info(
+ "[DUT %s]: PIM6 interface: %s " "helloPeriod is %s",
+ dut,
+ interface,
+ value,
+ )
+
+ if config == "drPriority":
+ # Verifying PIM interface drPriority
+ if intf_detail_json["drPriority"] != value:
+ errormsg = (
+ "[DUT %s]: PIM6 interface: %s "
+ " drPriority verification "
+ "[FAILED]!! Expected : %s,"
+ " Found : %s"
+ % (dut, interface, value, intf_detail_json["drPriority"])
+ )
+ return errormsg
+
+ logger.info(
+ "[DUT %s]: PIM6 interface: %s " "drPriority is %s",
+ dut,
+ interface,
+ value,
+ )
+
+ if config == "drAddress":
+ # Verifying PIM interface drAddress
+ if intf_detail_json["drAddress"] != value:
+ errormsg = (
+ "[DUT %s]: PIM6 interface: %s "
+ " drAddress verification "
+ "[FAILED]!! Expected : %s,"
+ " Found : %s"
+ % (dut, interface, value, intf_detail_json["drAddress"])
+ )
+ return errormsg
+
+ logger.info(
+ "[DUT %s]: PIM6 interface: %s " "drAddress is %s",
+ dut,
+ interface,
+ value,
+ )
+
+ logger.debug("Exiting lib API: {}".format(sys._getframe().f_code.co_name))
+ return True
+
# def cleanup(self):
# super(McastTesterHelper, self).cleanup()
diff --git a/tests/topotests/lib/topogen.py b/tests/topotests/lib/topogen.py
index 16d89f079a..f5b3ad06d9 100644
--- a/tests/topotests/lib/topogen.py
+++ b/tests/topotests/lib/topogen.py
@@ -212,7 +212,10 @@ class Topogen(object):
# Mininet(Micronet) to build the actual topology.
assert not inspect.isclass(topodef)
- self.net = Mininet(controller=None)
+ self.net = Mininet()
+
+ # Adjust the parent namespace
+ topotest.fix_netns_limits(self.net)
# New direct way: Either a dictionary defines the topology or a build function
# is supplied, or a json filename all of which build the topology by calling
@@ -485,7 +488,7 @@ class Topogen(object):
memleak_file = os.environ.get("TOPOTESTS_CHECK_MEMLEAK") or self.config.get(
self.CONFIG_SECTION, "memleak_path"
)
- if memleak_file == "" or memleak_file == None:
+ if memleak_file == "" or memleak_file is None:
return False
return True
@@ -504,7 +507,7 @@ class Topogen(object):
def set_error(self, message, code=None):
"Sets an error message and signal other tests to skip."
- logger.info(message)
+ logger.info("setting error msg: %s", message)
# If no code is defined use a sequential number
if code is None:
@@ -713,6 +716,7 @@ class TopoRouter(TopoGear):
RD_PATH = 17
RD_SNMP = 18
RD_PIM6 = 19
+ RD_MGMTD = 20
RD = {
RD_FRR: "frr",
RD_ZEBRA: "zebra",
@@ -734,6 +738,7 @@ class TopoRouter(TopoGear):
RD_PBRD: "pbrd",
RD_PATH: "pathd",
RD_SNMP: "snmpd",
+ RD_MGMTD: "mgmtd",
}
def __init__(self, tgen, cls, name, **params):
@@ -797,7 +802,7 @@ class TopoRouter(TopoGear):
grep_cmd = "grep 'ip {}' {}".format(daemonstr, source)
else:
grep_cmd = "grep 'router {}' {}".format(daemonstr, source)
- result = self.run(grep_cmd).strip()
+ result = self.run(grep_cmd, warn=False).strip()
if result:
self.load_config(daemon)
else:
@@ -810,7 +815,7 @@ class TopoRouter(TopoGear):
TopoRouter.RD_RIPNG, TopoRouter.RD_OSPF, TopoRouter.RD_OSPF6,
TopoRouter.RD_ISIS, TopoRouter.RD_BGP, TopoRouter.RD_LDP,
TopoRouter.RD_PIM, TopoRouter.RD_PIM6, TopoRouter.RD_PBR,
- TopoRouter.RD_SNMP.
+ TopoRouter.RD_SNMP, TopoRouter.RD_MGMTD.
Possible `source` values are `None` for an empty config file, a path name which is
used directly, or a file name with no path components which is first looked for
@@ -820,7 +825,7 @@ class TopoRouter(TopoGear):
all routers.
"""
daemonstr = self.RD.get(daemon)
- self.logger.info('loading "{}" configuration: {}'.format(daemonstr, source))
+ self.logger.debug('loading "{}" configuration: {}'.format(daemonstr, source))
self.net.loadConf(daemonstr, source, param)
def check_router_running(self):
@@ -943,16 +948,16 @@ class TopoRouter(TopoGear):
vtysh_command = 'vtysh {} -c "{}" 2>/dev/null'.format(dparam, command)
- self.logger.info('vtysh command => "{}"'.format(command))
+ self.logger.debug('vtysh command => "{}"'.format(command))
output = self.run(vtysh_command)
dbgout = output.strip()
if dbgout:
if "\n" in dbgout:
dbgout = dbgout.replace("\n", "\n\t")
- self.logger.info("vtysh result:\n\t{}".format(dbgout))
+ self.logger.debug("vtysh result:\n\t{}".format(dbgout))
else:
- self.logger.info('vtysh result: "{}"'.format(dbgout))
+ self.logger.debug('vtysh result: "{}"'.format(dbgout))
if isjson is False:
return output
@@ -992,7 +997,7 @@ class TopoRouter(TopoGear):
dbgcmds = commands if is_string(commands) else "\n".join(commands)
dbgcmds = "\t" + dbgcmds.replace("\n", "\n\t")
- self.logger.info("vtysh command => FILE:\n{}".format(dbgcmds))
+ self.logger.debug("vtysh command => FILE:\n{}".format(dbgcmds))
res = self.run(vtysh_command)
os.unlink(fname)
@@ -1001,9 +1006,9 @@ class TopoRouter(TopoGear):
if dbgres:
if "\n" in dbgres:
dbgres = dbgres.replace("\n", "\n\t")
- self.logger.info("vtysh result:\n\t{}".format(dbgres))
+ self.logger.debug("vtysh result:\n\t{}".format(dbgres))
else:
- self.logger.info('vtysh result: "{}"'.format(dbgres))
+ self.logger.debug('vtysh result: "{}"'.format(dbgres))
return res
def report_memory_leaks(self, testname):
@@ -1017,7 +1022,7 @@ class TopoRouter(TopoGear):
memleak_file = (
os.environ.get("TOPOTESTS_CHECK_MEMLEAK") or self.params["memleak_path"]
)
- if memleak_file == "" or memleak_file == None:
+ if memleak_file == "" or memleak_file is None:
return
self.stop()
@@ -1174,7 +1179,7 @@ class TopoExaBGP(TopoHost):
self.run("chown -R exabgp:exabgp /etc/exabgp")
output = self.run(exacmd + " -e /etc/exabgp/exabgp.env /etc/exabgp/exabgp.cfg")
- if output == None or len(output) == 0:
+ if output is None or len(output) == 0:
output = "<none>"
logger.info("{} exabgp started, output={}".format(self.name, output))
@@ -1269,6 +1274,7 @@ def diagnose_env_linux(rundir):
"pim6d",
"ldpd",
"pbrd",
+ "mgmtd",
]:
path = os.path.join(frrdir, fname)
if not os.path.isfile(path):
@@ -1283,9 +1289,10 @@ def diagnose_env_linux(rundir):
logger.error("could not find {} in {}".format(fname, frrdir))
ret = False
else:
- if fname != "zebra":
+ if fname != "zebra" or fname != "mgmtd":
continue
+ os.system("{} -v 2>&1 >{}/frr_mgmtd.txt".format(path, rundir))
os.system("{} -v 2>&1 >{}/frr_zebra.txt".format(path, rundir))
# Test MPLS availability
diff --git a/tests/topotests/lib/topotest.py b/tests/topotests/lib/topotest.py
index 0cd60b228d..86a7f2000f 100644
--- a/tests/topotests/lib/topotest.py
+++ b/tests/topotests/lib/topotest.py
@@ -352,7 +352,7 @@ def run_and_expect(func, what, count=20, wait=3):
count, wait
)
- logger.info(
+ logger.debug(
"'{}' polling started (interval {} secs, maximum {} tries)".format(
func_name, wait, count
)
@@ -366,7 +366,7 @@ def run_and_expect(func, what, count=20, wait=3):
continue
end_time = time.time()
- logger.info(
+ logger.debug(
"'{}' succeeded after {:.2f} seconds".format(
func_name, end_time - start_time
)
@@ -409,7 +409,7 @@ def run_and_expect_type(func, etype, count=20, wait=3, avalue=None):
count, wait
)
- logger.info(
+ logger.debug(
"'{}' polling started (interval {} secs, maximum wait {} secs)".format(
func_name, wait, int(wait * count)
)
@@ -432,7 +432,7 @@ def run_and_expect_type(func, etype, count=20, wait=3, avalue=None):
continue
end_time = time.time()
- logger.info(
+ logger.debug(
"'{}' succeeded after {:.2f} seconds".format(
func_name, end_time - start_time
)
@@ -582,6 +582,7 @@ def iproute2_is_vrf_capable():
pass
return False
+
def iproute2_is_fdb_get_capable():
"""
Checks if the iproute2 version installed on the system is capable of
@@ -606,6 +607,7 @@ def iproute2_is_fdb_get_capable():
pass
return False
+
def module_present_linux(module, load):
"""
Returns whether `module` is present.
@@ -1128,7 +1130,7 @@ def _sysctl_atleast(commander, variable, min_value):
valstr = " ".join([str(x) for x in min_value])
else:
valstr = str(min_value)
- logger.info("Increasing sysctl %s from %s to %s", variable, cur_val, valstr)
+ logger.debug("Increasing sysctl %s from %s to %s", variable, cur_val, valstr)
commander.cmd_raises('sysctl -w {}="{}"\n'.format(variable, valstr))
@@ -1159,7 +1161,7 @@ def _sysctl_assure(commander, variable, value):
valstr = " ".join([str(x) for x in value])
else:
valstr = str(value)
- logger.info("Changing sysctl %s from %s to %s", variable, cur_val, valstr)
+ logger.debug("Changing sysctl %s from %s to %s", variable, cur_val, valstr)
commander.cmd_raises('sysctl -w {}="{}"\n'.format(variable, valstr))
@@ -1202,7 +1204,7 @@ def rlimit_atleast(rname, min_value, raises=False):
soft, hard = cval
if soft < min_value:
nval = (min_value, hard if min_value < hard else min_value)
- logger.info("Increasing rlimit %s from %s to %s", rname, cval, nval)
+ logger.debug("Increasing rlimit %s from %s to %s", rname, cval, nval)
resource.setrlimit(rname, nval)
except subprocess.CalledProcessError as error:
logger.warning(
@@ -1371,6 +1373,7 @@ class Router(Node):
"pbrd": 0,
"pathd": 0,
"snmpd": 0,
+ "mgmtd": 0,
}
self.daemons_options = {"zebra": ""}
self.reportCores = True
@@ -1398,6 +1401,10 @@ class Router(Node):
if not os.path.isfile(zebra_path):
raise Exception("FRR zebra binary doesn't exist at {}".format(zebra_path))
+ mgmtd_path = os.path.join(self.daemondir, "mgmtd")
+ if not os.path.isfile(mgmtd_path):
+ raise Exception("FRR MGMTD binary doesn't exist at {}".format(mgmtd_path))
+
# pylint: disable=W0221
# Some params are only meaningful for the parent class.
def config(self, **params):
@@ -1415,6 +1422,10 @@ class Router(Node):
zpath = os.path.join(self.daemondir, "zebra")
if not os.path.isfile(zpath):
raise Exception("No zebra binary found in {}".format(zpath))
+
+ cpath = os.path.join(self.daemondir, "mgmtd")
+ if not os.path.isfile(zpath):
+ raise Exception("No MGMTD binary found in {}".format(cpath))
# Allow user to specify routertype when the path was specified.
if params.get("routertype") is not None:
self.routertype = params.get("routertype")
@@ -1467,11 +1478,11 @@ class Router(Node):
logger.info("%s: stopping %s", self.name, ", ".join([x[0] for x in running]))
for name, pid in running:
- logger.info("{}: sending SIGTERM to {}".format(self.name, name))
+ logger.debug("{}: sending SIGTERM to {}".format(self.name, name))
try:
os.kill(pid, signal.SIGTERM)
except OSError as err:
- logger.info(
+ logger.debug(
"%s: could not kill %s (%s): %s", self.name, name, pid, str(err)
)
@@ -1515,7 +1526,10 @@ class Router(Node):
def removeIPs(self):
for interface in self.intfNames():
try:
- self.intf_ip_cmd(interface, "ip address flush " + interface)
+ self.intf_ip_cmd(interface, "ip -4 address flush " + interface)
+ self.intf_ip_cmd(
+ interface, "ip -6 address flush " + interface + " scope global"
+ )
except Exception as ex:
logger.error("%s can't remove IPs %s", self, str(ex))
# pdb.set_trace()
@@ -1549,7 +1563,7 @@ class Router(Node):
router_relative = os.path.join(script_dir, self.name, tail)
if self.path_exists(router_relative):
source = router_relative
- self.logger.info(
+ self.logger.debug(
"using router relative configuration: {}".format(source)
)
@@ -1567,6 +1581,10 @@ class Router(Node):
self.cmd_raises("rm -f " + conf_file)
self.cmd_raises("touch " + conf_file)
else:
+ # copy zebra.conf to mgmtd folder, which can be used during startup
+ if daemon == "zebra":
+ conf_file_mgmt = "/etc/{}/{}.conf".format(self.routertype, "mgmtd")
+ self.cmd_raises("cp {} {}".format(source, conf_file_mgmt))
self.cmd_raises("cp {} {}".format(source, conf_file))
if not self.unified_config or daemon == "frr":
@@ -1578,6 +1596,17 @@ class Router(Node):
self.cmd('echo "agentXSocket /etc/frr/agentx" >> /etc/snmp/frr.conf')
self.cmd('echo "mibs +ALL" > /etc/snmp/snmp.conf')
+ if (daemon == "zebra") and (self.daemons["mgmtd"] == 0):
+ # Add mgmtd with zebra - if it exists
+ try:
+ mgmtd_path = os.path.join(self.daemondir, "mgmtd")
+ except:
+ pdb.set_trace()
+ if os.path.isfile(mgmtd_path):
+ self.daemons["mgmtd"] = 1
+ self.daemons_options["mgmtd"] = ""
+ # Auto-Started mgmtd has no config, so it will read from zebra config
+
if (daemon == "zebra") and (self.daemons["staticd"] == 0):
# Add staticd with zebra - if it exists
try:
@@ -1589,8 +1618,9 @@ class Router(Node):
self.daemons["staticd"] = 1
self.daemons_options["staticd"] = ""
# Auto-Started staticd has no config, so it will read from zebra config
+
else:
- logger.info("No daemon {} known".format(daemon))
+ logger.warning("No daemon {} known".format(daemon))
# print "Daemons after:", self.daemons
def runInWindow(self, cmd, title=None):
@@ -1832,9 +1862,15 @@ class Router(Node):
else "",
)
else:
- logger.info("%s: %s %s started", self, self.routertype, daemon)
+ logger.debug("%s: %s %s started", self, self.routertype, daemon)
+
+ # Start mgmtd first
+ if "mgmtd" in daemons_list:
+ start_daemon("mgmtd")
+ while "mgmtd" in daemons_list:
+ daemons_list.remove("mgmtd")
- # Start Zebra first
+ # Start Zebra after mgmtd
if "zebra" in daemons_list:
start_daemon("zebra", "-s 90000000")
while "zebra" in daemons_list:
@@ -1855,15 +1891,6 @@ class Router(Node):
while "snmpd" in daemons_list:
daemons_list.remove("snmpd")
- if daemons is None:
- # Fix Link-Local Addresses on initial startup
- # Somehow (on Mininet only), Zebra removes the IPv6 Link-Local addresses on start. Fix this
- _, output, _ = self.cmd_status(
- "for i in `ls /sys/class/net/` ; do mac=`cat /sys/class/net/$i/address`; echo $i: $mac; [ -z \"$mac\" ] && continue; IFS=':'; set $mac; unset IFS; ip address add dev $i scope link fe80::$(printf %02x $((0x$1 ^ 2)))$2:${3}ff:fe$4:$5$6/64; done",
- stderr=subprocess.STDOUT,
- )
- logger.debug("Set MACs:\n%s", output)
-
# Now start all the other daemons
for daemon in daemons_list:
if self.daemons[daemon] == 0:
@@ -1901,7 +1928,7 @@ class Router(Node):
daemonpidfile = d.rstrip()
daemonpid = self.cmd("cat %s" % daemonpidfile).rstrip()
if daemonpid.isdigit() and pid_exists(int(daemonpid)):
- logger.info(
+ logger.debug(
"{}: killing {}".format(
self.name,
os.path.basename(daemonpidfile.rsplit(".", 1)[0]),
@@ -2165,7 +2192,7 @@ class Router(Node):
log = self.getStdErr(daemon)
if "memstats" in log:
# Found memory leak
- logger.info(
+ logger.warning(
"\nRouter {} {} StdErr Log:\n{}".format(self.name, daemon, log)
)
if not leakfound:
diff --git a/tests/topotests/mgmt_tests/test_yang_mgmt.py b/tests/topotests/mgmt_tests/test_yang_mgmt.py
new file mode 100644
index 0000000000..921b4e622c
--- /dev/null
+++ b/tests/topotests/mgmt_tests/test_yang_mgmt.py
@@ -0,0 +1,548 @@
+#!/usr/bin/python
+
+#
+# Copyright (c) 2021 by VMware, Inc. ("VMware")
+# Used Copyright (c) 2018 by Network Device Education Foundation,
+# Inc. ("NetDEF") in this file.
+#
+# Permission to use, copy, modify, and/or distribute this software
+# for any purpose with or without fee is hereby granted, provided
+# that the above copyright notice and this permission notice appear
+# in all copies.
+#
+# THE SOFTWARE IS PROVIDED "AS IS" AND VMWARE DISCLAIMS ALL WARRANTIES
+# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL VMWARE BE LIABLE FOR
+# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
+# DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+# WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+# ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
+# OF THIS SOFTWARE.
+#
+"""
+
+1. Verify mgmt commit check.
+2. Verify mgmt commit apply.
+3. Verify mgmt commit abort.
+4. Verify mgmt delete config.
+5. Kill mgmtd - verify that static routes are intact.
+6. Kill mgmtd - verify that watch frr restarts.
+7. Show and CLI - Execute all the newly introduced commands of mgmtd.
+8. Verify mgmt rollback functionality.
+
+"""
+import sys
+import time
+import os
+import pytest
+import platform
+
+# Save the Current Working Directory to find configuration files.
+CWD = os.path.dirname(os.path.realpath(__file__))
+sys.path.append(os.path.join(CWD, "../"))
+sys.path.append(os.path.join(CWD, "../lib/"))
+
+# pylint: disable=C0413
+# Import topogen and topotest helpers
+from lib.topogen import Topogen, get_topogen
+from lib.topotest import version_cmp
+
+# Import topoJson from lib, to create topology and initial configuration
+from lib.common_config import (
+ start_topology,
+ write_test_header,
+ write_test_footer,
+ reset_config_on_routers,
+ verify_rib,
+ create_static_routes,
+ check_address_types,
+ step,
+ shutdown_bringup_interface,
+ stop_router,
+ start_router,
+ apply_raw_config,
+ kill_router_daemons,
+ start_router_daemons,
+)
+from lib.topolog import logger
+from lib.bgp import verify_bgp_convergence, create_router_bgp, verify_bgp_rib
+from lib.topojson import build_config_from_json
+
+pytestmark = [pytest.mark.bgpd, pytest.mark.staticd]
+
+# Global variables
+ADDR_TYPES = check_address_types()
+NETWORK = {"ipv4": ["11.0.20.1/32", "11.0.20.2/32"], "ipv6": ["2::1/128", "2::2/128"]}
+NETWORK2 = {"ipv4": "11.0.20.1/32", "ipv6": "2::1/128"}
+PREFIX1 = {"ipv4": "110.0.20.1/32", "ipv6": "20::1/128"}
+
+
+def setup_module(mod):
+ """
+ Sets up the pytest environment.
+
+ * `mod`: module name
+ """
+
+ testsuite_run_time = time.asctime(time.localtime(time.time()))
+ logger.info("Testsuite start time: {}".format(testsuite_run_time))
+ logger.info("=" * 40)
+
+ logger.info("Running setup_module to create topology")
+
+ # This function initiates the topology build with Topogen...
+ json_file = "{}/yang_mgmt.json".format(CWD)
+ tgen = Topogen(json_file, mod.__name__)
+ global topo
+ topo = tgen.json_topo
+ # ... and here it calls Mininet initialization functions.
+
+ # Starting topology, create tmp files which are loaded to routers
+ # to start deamons and then start routers
+ start_topology(tgen)
+
+ # Creating configuration from JSON
+ build_config_from_json(tgen, topo)
+
+ if version_cmp(platform.release(), "4.19") < 0:
+ error_msg = (
+ 'These tests will not run. (have kernel "{}", '
+ "requires kernel >= 4.19)".format(platform.release())
+ )
+ pytest.skip(error_msg)
+
+ # Don't run this test if we have any failure.
+ if tgen.routers_have_failure():
+ pytest.skip(tgen.errors)
+
+ logger.info("Running setup_module() done")
+
+
+def teardown_module(mod):
+ """
+ Teardown the pytest environment.
+
+ * `mod`: module name
+ """
+
+ logger.info("Running teardown_module to delete topology: %s", mod)
+
+ tgen = get_topogen()
+
+ # Stop toplogy and Remove tmp files
+ tgen.stop_topology()
+
+ logger.info(
+ "Testsuite end time: {}".format(time.asctime(time.localtime(time.time())))
+ )
+ logger.info("=" * 40)
+
+
+def populate_nh():
+ """
+ Populate nexthops.
+ """
+
+ next_hop_ip = {
+ "nh1": {
+ "ipv4": topo["routers"]["r1"]["links"]["r2-link0"]["ipv4"].split("/")[0],
+ "ipv6": topo["routers"]["r1"]["links"]["r2-link0"]["ipv6"].split("/")[0],
+ },
+ "nh2": {
+ "ipv4": topo["routers"]["r1"]["links"]["r2-link1"]["ipv4"].split("/")[0],
+ "ipv6": topo["routers"]["r1"]["links"]["r2-link1"]["ipv6"].split("/")[0],
+ },
+ }
+ return next_hop_ip
+
+
+#####################################################
+#
+# Testcases
+#
+#####################################################
+
+
+def test_mgmt_commit_check(request):
+ """
+ Verify mgmt commit check.
+
+ """
+ tc_name = request.node.name
+ write_test_header(tc_name)
+ tgen = get_topogen()
+ # Don't run this test if we have any failure.
+ if tgen.routers_have_failure():
+ pytest.skip(tgen.errors)
+
+ reset_config_on_routers(tgen)
+
+ step("Mgmt Commit check")
+ raw_config = {
+ "r1": {
+ "raw_config": [
+ "mgmt set-config /frr-routing:routing/control-plane-protocols/control-plane-protocol[type='frr-staticd:staticd'][name='staticd'][vrf='default']/frr-staticd:staticd/route-list[prefix='192.1.1.2/32'][afi-safi='frr-routing:ipv4-unicast']/path-list[table-id='0'][distance='1']/frr-nexthops/nexthop[nh-type='blackhole'][vrf='default'][gateway=''][interface='(null)']/bh-type unspec",
+ "mgmt commit check",
+ ]
+ }
+ }
+
+ result = apply_raw_config(tgen, raw_config)
+ assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
+
+ step("Mgmt Commit check")
+ raw_config = {
+ "r1": {
+ "raw_config": [
+ "mgmt set-config /frr-routing:routing/control-plane-protocols/control-plane-protocol[type='frr-staticd:staticd'][name='staticd'][vrf='default']/frr-staticd:staticd/route-list[prefix='192.1.1.2/32'][afi-safi='frr-routing:ipv4-unicast']/path-list[table-id='0'][distance='1']/frr-nexthops/nexthop[nh-type='blackhole'][vrf='default'][gateway=''][interface='(null)']/bh-type unspec",
+ "mgmt commit check",
+ ]
+ }
+ }
+
+ result = apply_raw_config(tgen, raw_config)
+ assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
+
+ step("verify that the route is not configured, as commit apply not done.")
+
+ dut = "r1"
+ protocol = "static"
+ input_dict_4 = {
+ "r2": {
+ "static_routes": [
+ {
+ "network": "1192.1.1.2/32",
+ "next_hop": "Null0",
+ }
+ ]
+ }
+ }
+ result = verify_rib(
+ tgen, "ipv4", dut, input_dict_4, protocol=protocol, expected=False
+ )
+ assert (
+ result is not True
+ ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name)
+
+ write_test_footer(tc_name)
+
+
+def test_mgmt_commit_apply(request):
+ """
+ Verify mgmt commit apply.
+
+ """
+ tc_name = request.node.name
+ write_test_header(tc_name)
+ tgen = get_topogen()
+ # Don't run this test if we have any failure.
+ if tgen.routers_have_failure():
+ pytest.skip(tgen.errors)
+
+ reset_config_on_routers(tgen)
+
+ step("Mgmt Commit apply with Valid Configuration")
+ raw_config = {
+ "r1": {
+ "raw_config": [
+ "mgmt set-config /frr-routing:routing/control-plane-protocols/control-plane-protocol[type='frr-staticd:staticd'][name='staticd'][vrf='default']/frr-staticd:staticd/route-list[prefix='192.1.1.20/32'][afi-safi='frr-routing:ipv4-unicast']/path-list[table-id='0'][distance='1']/frr-nexthops/nexthop[nh-type='blackhole'][vrf='default'][gateway=''][interface='(null)']/vrf default",
+ "mgmt commit apply",
+ ]
+ }
+ }
+
+ result = apply_raw_config(tgen, raw_config)
+ assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
+
+ step("Mgmt Commit apply with Invalid Configuration")
+ raw_config = {
+ "r1": {
+ "raw_config": [
+ "mgmt set-config /frr-routing:routing/control-plane-protocols/control-plane-protocol[type='frr-staticd:staticd'][name='staticd'][vrf='default']/frr-staticd:staticd/route-list[prefix='192.1.1.20/32'][afi-safi='frr-routing:ipv4-unicast']/path-list[table-id='0'][distance='1']/frr-nexthops/nexthop[nh-type='blackhole'][vrf='default'][gateway=''][interface='(null)']/vrf default",
+ "mgmt commit apply",
+ ]
+ }
+ }
+
+ result = apply_raw_config(tgen, raw_config)
+ assert result is not True, "Testcase {} : Failed Error: {}".format(tc_name, result)
+
+ step("verify that the route is configured")
+
+ dut = "r1"
+ protocol = "static"
+ input_dict_4 = {"r2": {"static_routes": [{"network": "192.1.1.20/32"}]}}
+ result = verify_rib(tgen, "ipv4", dut, input_dict_4, protocol=protocol)
+ assert (
+ result is True
+ ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name)
+
+ write_test_footer(tc_name)
+
+
+def test_mgmt_commit_abort(request):
+ """
+ Verify mgmt commit abort.
+
+ """
+ tc_name = request.node.name
+ write_test_header(tc_name)
+ tgen = get_topogen()
+ # Don't run this test if we have any failure.
+ if tgen.routers_have_failure():
+ pytest.skip(tgen.errors)
+
+ reset_config_on_routers(tgen)
+
+ step("Mgmt Commit abort")
+ raw_config = {
+ "r1": {
+ "raw_config": [
+ "mgmt set-config /frr-routing:routing/control-plane-protocols/control-plane-protocol[type='frr-staticd:staticd'][name='staticd'][vrf='default']/frr-staticd:staticd/route-list[prefix='192.1.1.3/32'][afi-safi='frr-routing:ipv4-unicast']/path-list[table-id='0'][distance='1']/frr-nexthops/nexthop[nh-type='blackhole'][vrf='default'][gateway=''][interface='(null)']/vrf default",
+ "mgmt commit abort",
+ ]
+ }
+ }
+
+ result = apply_raw_config(tgen, raw_config)
+ assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
+
+ step("verify that the route is not configured")
+
+ dut = "r1"
+ protocol = "static"
+ input_dict_4 = {
+ "r2": {
+ "static_routes": [
+ {
+ "network": "192.1.1.3/32",
+ "next_hop": "Null0",
+ }
+ ]
+ }
+ }
+ result = verify_rib(
+ tgen, "ipv4", dut, input_dict_4, protocol=protocol, expected=False
+ )
+ assert (
+ result is not True
+ ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name)
+
+ write_test_footer(tc_name)
+
+
+def test_mgmt_delete_config(request):
+ """
+ Verify mgmt delete config.
+
+ """
+ tc_name = request.node.name
+ write_test_header(tc_name)
+ tgen = get_topogen()
+ # Don't run this test if we have any failure.
+ if tgen.routers_have_failure():
+ pytest.skip(tgen.errors)
+
+ reset_config_on_routers(tgen)
+
+ step("Mgmt - Configure a static route using commit apply")
+
+ raw_config = {
+ "r1": {
+ "raw_config": [
+ "mgmt set-config /frr-routing:routing/control-plane-protocols/control-plane-protocol[type='frr-staticd:staticd'][name='staticd'][vrf='default']/frr-staticd:staticd/route-list[prefix='192.168.1.3/32'][afi-safi='frr-routing:ipv4-unicast']/path-list[table-id='0'][distance='1']/frr-nexthops/nexthop[nh-type='blackhole'][vrf='default'][gateway=''][interface='(null)']/vrf default",
+ "mgmt commit apply",
+ ]
+ }
+ }
+
+ result = apply_raw_config(tgen, raw_config)
+ assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
+
+ step("Verify that the route is added to RIB")
+ dut = "r1"
+ protocol = "static"
+ input_dict_4 = {
+ "r2": {
+ "static_routes": [
+ {
+ "network": "192.168.1.3/32",
+ "next_hop": "Null0",
+ }
+ ]
+ }
+ }
+ result = verify_rib(tgen, "ipv4", dut, input_dict_4, protocol=protocol)
+ assert (
+ result is True
+ ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name)
+
+ step("Mgmt delete config")
+ raw_config = {
+ "r1": {
+ "raw_config": [
+ "mgmt delete-config /frr-routing:routing/control-plane-protocols/control-plane-protocol[type='frr-staticd:staticd'][name='staticd'][vrf='default']/frr-staticd:staticd/route-list[prefix='192.168.1.3/32'][afi-safi='frr-routing:ipv4-unicast']",
+ "mgmt commit apply",
+ ]
+ }
+ }
+
+ result = apply_raw_config(tgen, raw_config)
+ assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
+
+ step("Verify that the route is deleted from RIB")
+ result = verify_rib(
+ tgen, "ipv4", dut, input_dict_4, protocol=protocol, expected=False
+ )
+ assert (
+ result is not True
+ ), "Testcase {} : Failed" "Error: Routes is still present in RIB".format(tc_name)
+
+ write_test_footer(tc_name)
+
+
+def test_mgmt_chaos_stop_start_frr(request):
+ """
+ Kill mgmtd - verify that watch frr restarts.
+
+ """
+ tc_name = request.node.name
+ write_test_header(tc_name)
+ tgen = get_topogen()
+ # Don't run this test if we have any failure.
+ if tgen.routers_have_failure():
+ pytest.skip(tgen.errors)
+
+ reset_config_on_routers(tgen)
+ next_hop_ip = populate_nh()
+
+ step("Configure Static route with next hop null 0")
+
+ raw_config = {
+ "r1": {
+ "raw_config": [
+ "mgmt set-config /frr-routing:routing/control-plane-protocols/control-plane-protocol[type='frr-staticd:staticd'][name='staticd'][vrf='default']/frr-staticd:staticd/route-list[prefix='192.1.11.200/32'][afi-safi='frr-routing:ipv4-unicast']/path-list[table-id='0'][distance='1']/frr-nexthops/nexthop[nh-type='blackhole'][vrf='default'][gateway=''][interface='(null)']/bh-type unspec",
+ "mgmt commit apply",
+ ]
+ }
+ }
+
+ result = apply_raw_config(tgen, raw_config)
+ assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
+
+ step("verify that the route is configured and present in the zebra")
+
+ dut = "r1"
+ protocol = "static"
+ input_dict_4 = {"r2": {"static_routes": [{"network": "192.1.11.200/32"}]}}
+ result = verify_rib(tgen, "ipv4", dut, input_dict_4, protocol=protocol)
+ assert (
+ result is True
+ ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name)
+
+ step("Restart frr")
+ stop_router(tgen, "r1")
+ start_router(tgen, "r1")
+ step("Verify routes are intact in zebra.")
+ result = verify_rib(tgen, "ipv4", dut, input_dict_4, protocol=protocol)
+ assert (
+ result is True
+ ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name)
+
+ step("delete the configured route and ")
+ raw_config = {
+ "r1": {
+ "raw_config": [
+ "mgmt delete-config /frr-routing:routing/control-plane-protocols/control-plane-protocol[type='frr-staticd:staticd'][name='staticd'][vrf='default']/frr-staticd:staticd/route-list[prefix='192.1.11.200/32'][afi-safi='frr-routing:ipv4-unicast']",
+ "mgmt commit apply",
+ ]
+ }
+ }
+
+ result = apply_raw_config(tgen, raw_config)
+ assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
+
+ step("verify that the route is deleted and deleted from zebra")
+
+ dut = "r1"
+ protocol = "static"
+ input_dict_4 = {"r1": {"static_routes": [{"network": "192.1.11.200/32"}]}}
+ result = verify_rib(
+ tgen, "ipv4", dut, input_dict_4, protocol=protocol, expected=False
+ )
+ assert (
+ result is not True
+ ), "Testcase {} : Failed" "Error: Routes still present in RIB".format(tc_name)
+
+ write_test_footer(tc_name)
+
+
+def test_mgmt_chaos_kill_daemon(request):
+ """
+ Kill mgmtd - verify that static routes are intact
+
+ """
+ tc_name = request.node.name
+ write_test_header(tc_name)
+ tgen = get_topogen()
+ # Don't run this test if we have any failure.
+ if tgen.routers_have_failure():
+ pytest.skip(tgen.errors)
+
+ reset_config_on_routers(tgen)
+ next_hop_ip = populate_nh()
+
+ step("Configure Static route with next hop null 0")
+
+ raw_config = {
+ "r1": {
+ "raw_config": [
+ "mgmt set-config /frr-routing:routing/control-plane-protocols/control-plane-protocol[type='frr-staticd:staticd'][name='staticd'][vrf='default']/frr-staticd:staticd/route-list[prefix='192.1.11.200/32'][afi-safi='frr-routing:ipv4-unicast']/path-list[table-id='0'][distance='1']/frr-nexthops/nexthop[nh-type='blackhole'][vrf='default'][gateway=''][interface='(null)']/bh-type unspec",
+ "mgmt commit apply",
+ ]
+ }
+ }
+
+ result = apply_raw_config(tgen, raw_config)
+ assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
+
+ step("verify that the route is configured and present in the zebra")
+
+ dut = "r1"
+ protocol = "static"
+ input_dict_4 = {"r2": {"static_routes": [{"network": "192.1.11.200/32"}]}}
+ result = verify_rib(tgen, "ipv4", dut, input_dict_4, protocol=protocol)
+ assert (
+ result is True
+ ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name)
+
+ step("Kill static daemon on R2.")
+ kill_router_daemons(tgen, "r1", ["staticd"])
+
+ step("Bring up staticd daemon on R2.")
+ start_router_daemons(tgen, "r1", ["staticd"])
+
+ step("Verify routes are intact in zebra.")
+ result = verify_rib(tgen, "ipv4", dut, input_dict_4, protocol=protocol)
+ assert (
+ result is True
+ ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name)
+
+ step("Kill mgmt daemon on R2.")
+ kill_router_daemons(tgen, "r1", ["mgmtd"])
+
+ step("Bring up zebra daemon on R2.")
+ start_router_daemons(tgen, "r1", ["mgmtd"])
+
+ step("Verify routes are intact in zebra.")
+ result = verify_rib(tgen, "ipv4", dut, input_dict_4, protocol=protocol)
+ assert (
+ result is True
+ ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name)
+
+ write_test_footer(tc_name)
+
+
+if __name__ == "__main__":
+ args = ["-s"] + sys.argv[1:]
+ sys.exit(pytest.main(args))
diff --git a/tests/topotests/mgmt_tests/yang_mgmt.json b/tests/topotests/mgmt_tests/yang_mgmt.json
new file mode 100644
index 0000000000..0fe3bb1dbe
--- /dev/null
+++ b/tests/topotests/mgmt_tests/yang_mgmt.json
@@ -0,0 +1,157 @@
+{
+ "address_types": [
+ "ipv4",
+ "ipv6"
+ ],
+ "ipv4base": "10.0.0.0",
+ "ipv4mask": 30,
+ "ipv6base": "fd00::",
+ "ipv6mask": 64,
+ "link_ip_start": {
+ "ipv4": "10.0.0.0",
+ "v4mask": 30,
+ "ipv6": "fd00::",
+ "v6mask": 64
+ },
+ "lo_prefix": {
+ "ipv4": "1.0.",
+ "v4mask": 32,
+ "ipv6": "2001:db8:f::",
+ "v6mask": 128
+ },
+ "routers": {
+ "r1": {
+ "links": {
+ "lo": {
+ "ipv4": "auto",
+ "ipv6": "auto",
+ "type": "loopback"
+ },
+ "r2-link0": {
+ "ipv4": "auto",
+ "ipv6": "auto"
+ },
+ "r2-link1": {
+ "ipv4": "auto",
+ "ipv6": "auto"
+ },
+ "r3-link0": {
+ "ipv4": "auto",
+ "ipv6": "auto"
+ },
+ "r3-link1": {
+ "ipv4": "auto",
+ "ipv6": "auto"
+ }
+ }
+ },
+ "r2": {
+ "links": {
+ "lo": {
+ "ipv4": "auto",
+ "ipv6": "auto",
+ "type": "loopback"
+ },
+ "r1-link0": {
+ "ipv4": "auto",
+ "ipv6": "auto"
+ },
+ "r1-link1": {
+ "ipv4": "auto",
+ "ipv6": "auto"
+ },
+ "r3": {
+ "ipv4": "auto",
+ "ipv6": "auto"
+ }
+ },
+ "bgp": {
+ "local_as": "100",
+ "address_family": {
+ "ipv4": {
+ "unicast": {
+ "neighbor": {
+ "r3": {
+ "dest_link": {
+ "r2": {
+ "keepalivetimer": 1,
+ "holddowntimer": 4
+ }
+ }
+ }
+ }
+ }
+ },
+ "ipv6": {
+ "unicast": {
+ "neighbor": {
+ "r3": {
+ "dest_link": {
+ "r2": {
+ "keepalivetimer": 1,
+ "holddowntimer": 4
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ },
+ "r3": {
+ "links": {
+ "lo": {
+ "ipv4": "auto",
+ "ipv6": "auto",
+ "type": "loopback"
+ },
+ "r2": {
+ "ipv4": "auto",
+ "ipv6": "auto"
+ },
+ "r1-link0": {
+ "ipv4": "auto",
+ "ipv6": "auto"
+ },
+ "r1-link1": {
+ "ipv4": "auto",
+ "ipv6": "auto"
+ }
+ },
+ "bgp": {
+ "local_as": "200",
+ "address_family": {
+ "ipv4": {
+ "unicast": {
+ "neighbor": {
+ "r2": {
+ "dest_link": {
+ "r3": {
+ "keepalivetimer": 1,
+ "holddowntimer": 4
+ }
+ }
+ }
+ }
+ }
+ },
+ "ipv6": {
+ "unicast": {
+ "neighbor": {
+ "r2": {
+ "dest_link": {
+ "r3": {
+ "keepalivetimer": 1,
+ "holddowntimer": 4
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/tests/topotests/msdp_mesh_topo1/test_msdp_mesh_topo1.py b/tests/topotests/msdp_mesh_topo1/test_msdp_mesh_topo1.py
index 2f31608e64..6d9304d864 100644
--- a/tests/topotests/msdp_mesh_topo1/test_msdp_mesh_topo1.py
+++ b/tests/topotests/msdp_mesh_topo1/test_msdp_mesh_topo1.py
@@ -71,6 +71,7 @@ def setup_module(mod):
router_list = tgen.routers()
for rname, router in router_list.items():
+
daemon_file = "{}/{}/zebra.conf".format(CWD, rname)
if os.path.isfile(daemon_file):
router.load_config(TopoRouter.RD_ZEBRA, daemon_file)
diff --git a/tests/topotests/msdp_topo1/test_msdp_topo1.py b/tests/topotests/msdp_topo1/test_msdp_topo1.py
index 4a007e7d20..1af58b0a01 100755
--- a/tests/topotests/msdp_topo1/test_msdp_topo1.py
+++ b/tests/topotests/msdp_topo1/test_msdp_topo1.py
@@ -82,6 +82,7 @@ def setup_module(mod):
router_list = tgen.routers()
for rname, router in router_list.items():
+
daemon_file = "{}/{}/zebra.conf".format(CWD, rname)
if os.path.isfile(daemon_file):
router.load_config(TopoRouter.RD_ZEBRA, daemon_file)
diff --git a/tests/topotests/multicast_pim6_sm_topo1/multicast_pim6_sm_topo1.json b/tests/topotests/multicast_pim6_sm_topo1/multicast_pim6_sm_topo1.json
new file mode 100644
index 0000000000..341cd5a98e
--- /dev/null
+++ b/tests/topotests/multicast_pim6_sm_topo1/multicast_pim6_sm_topo1.json
@@ -0,0 +1,300 @@
+{
+ "address_types": ["ipv6"],
+ "ipv6base": "fd00::",
+ "ipv6mask": 64,
+ "link_ip_start": {
+ "ipv6": "fd00::",
+ "v6mask": 64
+ },
+ "lo_prefix": {
+ "ipv6": "2001:db8:f::",
+ "v6mask": 128
+ },
+ "routers": {
+ "r1": {
+ "links": {
+ "lo": {"ipv6": "auto", "type": "loopback", "pim6": "enable"},
+ "r2": {"ipv6": "auto", "pim6": "enable"},
+ "r4": {"ipv6": "auto", "pim6": "enable"},
+ "i1": {"ipv6": "auto", "pim6": "enable"},
+ "i6": {"ipv6": "auto", "pim6": "enable"},
+ "i7": {"ipv6": "auto", "pim6": "enable"}
+ },
+ "bgp": {
+ "local_as": "100",
+ "router_id": "192.168.1.1",
+ "address_family": {
+ "ipv4": {
+ "unicast": {
+ "neighbor": {
+ "r2": {
+ "dest_link": {
+ "r1": {}
+
+ }
+ },
+ "r4": {
+ "dest_link": {
+ "r1": {}
+ }
+ }
+ }
+ }
+ },
+ "ipv6": {
+ "unicast": {
+ "redistribute": [
+ {"redist_type": "static"},
+ {"redist_type": "connected"}
+ ],
+ "neighbor": {
+ "r2": {
+ "dest_link": {
+ "r1": {}
+
+ }
+ },
+ "r4": {
+ "dest_link": {
+ "r1": {}
+ }
+ }
+ }
+ }
+ }
+ }
+ },
+ "mld": {
+ "interfaces": {
+ "r1-i1-eth0" :{
+ "mld":{
+ "version": 1
+ }
+ }
+ }
+ }
+ },
+
+ "r2": {
+ "links": {
+ "lo": {"ipv6": "auto", "type": "loopback", "pim6": "enable"},
+ "r1": {"ipv6": "auto", "pim6": "enable"},
+ "r3": {"ipv6": "auto", "pim6": "enable"},
+ "i3": {"ipv6": "auto", "pim6": "enable"}
+ },
+ "bgp": {
+ "local_as": "200",
+ "router_id": "192.168.1.2",
+ "address_family": {
+ "ipv4": {
+ "unicast": {
+ "neighbor": {
+ "r1": {
+ "dest_link": {
+ "r2": {}
+ }
+ },
+ "r3": {
+ "dest_link": {
+ "r2": {}
+
+ }
+ }
+ }
+ }
+ },
+ "ipv6": {
+ "unicast": {
+ "redistribute": [
+ {"redist_type": "static"},
+ {"redist_type": "connected"}
+ ],
+ "neighbor": {
+ "r1": {
+ "dest_link": {
+ "r2": {}
+ }
+ },
+ "r3": {
+ "dest_link": {
+ "r2": {}
+
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ },
+ "r3": {
+ "links": {
+ "lo": {"ipv6": "auto", "type": "loopback", "pim6": "enable"},
+ "r2": {"ipv6": "auto", "pim6": "enable"},
+ "r5": {"ipv6": "auto", "pim6": "enable"},
+ "i2": {"ipv6": "auto", "pim6": "enable"},
+ "i8": {"ipv6": "auto", "pim6": "enable"}
+ },
+ "bgp": {
+ "local_as": "300",
+ "router_id": "192.168.1.3",
+ "address_family": {
+ "ipv4": {
+ "unicast": {
+ }
+ },
+ "ipv6": {
+ "unicast": {
+ "redistribute": [
+ {"redist_type": "static"},
+ {"redist_type": "connected"}
+ ],
+ "neighbor": {
+ "r2": {
+ "dest_link": {
+ "r3": {}
+ }
+ },
+ "r5": {
+ "dest_link": {
+ "r3": {}
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ },
+ "r4": {
+ "links": {
+ "lo": {"ipv6": "auto", "type": "loopback", "pim6": "enable"},
+ "r1": {"ipv6": "auto", "pim6": "enable"},
+ "r5": {"ipv6": "auto", "pim6": "enable"},
+ "i4": {"ipv6": "auto", "pim6": "enable"}
+ },
+ "bgp": {
+ "local_as": "400",
+ "router_id": "192.168.1.4",
+ "address_family": {
+ "ipv4": {
+ "unicast": {
+ "neighbor": {
+ "r1": {
+ "dest_link": {
+ "r4": {}
+ }
+ },
+ "r5": {
+ "dest_link": {
+ "r4": {}
+ }
+ }
+ }
+ }
+ },
+ "ipv6": {
+ "unicast": {
+ "redistribute": [
+ {"redist_type": "static"},
+ {"redist_type": "connected"}
+ ],
+ "neighbor": {
+ "r1": {
+ "dest_link": {
+ "r4": {}
+ }
+ },
+ "r5": {
+ "dest_link": {
+ "r4": {}
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ },
+
+ "r5": {
+ "links": {
+ "lo": {"ipv6": "auto", "type": "loopback", "pim6": "enable"},
+ "r3": {"ipv6": "auto", "pim6": "enable"},
+ "r4": {"ipv6": "auto", "pim6": "enable"},
+ "i5": {"ipv6": "auto", "pim6": "enable"}
+ },
+ "bgp": {
+ "local_as": "500",
+ "router_id": "192.168.1.5",
+ "address_family": {
+ "ipv4": {
+ "unicast": {
+ }
+ },
+ "ipv6": {
+ "unicast": {
+ "redistribute": [
+ {"redist_type": "static"},
+ {"redist_type": "connected"}
+ ],
+ "neighbor": {
+ "r3": {
+ "dest_link": {
+ "r5": {}
+ }
+ },
+ "r4": {
+ "dest_link": {
+ "r5": {}
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ },
+
+ "i1": {
+ "links": {
+ "r1": {"ipv6": "auto"}
+ }
+ },
+ "i2": {
+ "links": {
+ "r3": {"ipv6": "auto"}
+ }
+ },
+ "i3": {
+ "links": {
+ "r2": {"ipv6": "auto"}
+ }
+ },
+ "i4": {
+ "links": {
+ "r4": {"ipv6": "auto"}
+ }
+ },
+ "i5": {
+ "links": {
+ "r5": {"ipv6": "auto"}
+ }
+ },
+ "i6": {
+ "links": {
+ "r1": {"ipv6": "auto"}
+ }
+ },
+ "i7": {
+ "links": {
+ "r1": {"ipv6": "auto"}
+ }
+ },
+ "i8": {
+ "links": {
+ "r3": {"ipv6": "auto"}
+ }
+ }
+ }
+}
diff --git a/tests/topotests/multicast_pim6_sm_topo1/test_multicast_pim6_sm1.py b/tests/topotests/multicast_pim6_sm_topo1/test_multicast_pim6_sm1.py
new file mode 100644
index 0000000000..87b04b41be
--- /dev/null
+++ b/tests/topotests/multicast_pim6_sm_topo1/test_multicast_pim6_sm1.py
@@ -0,0 +1,1616 @@
+#!/usr/bin/env python
+# SPDX-License-Identifier: ISC
+
+#
+# Copyright (c) 2022 by VMware, Inc. ("VMware")
+# Used Copyright (c) 2018 by Network Device Education Foundation,
+# Inc. ("NetDEF") in this file.
+#
+
+"""
+Following tests are covered to test multicast pim6 sm:
+
+Test steps
+- Create topology (setup module)
+- Bring up topology
+
+Following tests are covered:
+1. Verify Multicast data traffic with static RP, (*,g) and
+(s,g) OIL updated correctly
+2. Verify mroute detail when receiver is present
+outside of FRR
+3. Verify (*,G) and (S,G) populated correctly
+when FRR is the transit router
+4. Verify (S,G) should not create if RP is not reachable
+5. Verify modification of mld query timer should get update
+accordingly
+6. Verify modification of mld max query response timer
+should get update accordingly
+7. Verify removing the RP should not impact the multicast
+data traffic
+"""
+
+import os
+import sys
+import json
+import time
+import datetime
+import pytest
+
+# Save the Current Working Directory to find configuration files.
+CWD = os.path.dirname(os.path.realpath(__file__))
+sys.path.append(os.path.join(CWD, "../"))
+sys.path.append(os.path.join(CWD, "../lib/"))
+
+# Required to instantiate the topology builder class.
+
+# pylint: disable=C0413
+# Import topogen and topotest helpers
+from lib.topogen import Topogen, get_topogen
+
+from lib.common_config import (
+ start_topology,
+ write_test_header,
+ write_test_footer,
+ step,
+ reset_config_on_routers,
+ shutdown_bringup_interface,
+ start_router,
+ stop_router,
+ create_static_routes,
+ required_linux_kernel_version,
+ socat_send_mld_join,
+ socat_send_pim6_traffic,
+ get_frr_ipv6_linklocal,
+ kill_socat,
+)
+from lib.bgp import create_router_bgp
+from lib.pim import (
+ create_pim_config,
+ create_mld_config,
+ verify_mld_groups,
+ verify_mroutes,
+ clear_pim6_interface_traffic,
+ verify_upstream_iif,
+ clear_pim6_mroute,
+ verify_pim_interface_traffic,
+ verify_pim_state,
+ McastTesterHelper,
+ verify_pim_join,
+ verify_mroute_summary,
+ verify_pim_nexthop,
+ verify_sg_traffic,
+ verify_mld_config,
+)
+
+from lib.topolog import logger
+from lib.topojson import build_config_from_json
+
+# Global variables
+GROUP_RANGE = "ff00::/8"
+
+GROUP_RANGE_1 = [
+ "ffaa::1/128",
+ "ffaa::2/128",
+ "ffaa::3/128",
+ "ffaa::4/128",
+ "ffaa::5/128",
+]
+MLD_JOIN_RANGE_1 = ["ffaa::1", "ffaa::2", "ffaa::3", "ffaa::4", "ffaa::5"]
+
+GROUP_RANGE_2 = [
+ "ffbb::1/128",
+ "ffbb::2/128",
+ "ffbb::3/128",
+ "ffbb::4/128",
+ "ffbb::5/128",
+]
+MLD_JOIN_RANGE_2 = ["ffbb::1", "ffbb::2", "ffbb::3", "ffbb::4", "ffbb::5"]
+GROUP_RANGE_3 = [
+ "ffcc::1/128",
+ "ffcc::2/128",
+ "ffcc::3/128",
+ "ffcc::4/128",
+ "ffcc::5/128",
+]
+MLD_JOIN_RANGE_3 = ["ffcc::1", "ffcc::2", "ffcc::3", "ffcc::4", "ffcc::5"]
+
+HELLO_TIMER = 1
+HOLD_TIMER = 3
+PREFERRED_NEXT_HOP = "link_local"
+ASSERT_MSG = "Testcase {} : Failed Error: {}"
+
+pytestmark = [pytest.mark.pim6d]
+
+
+def setup_module(mod):
+ """
+ Sets up the pytest environment
+
+ * `mod`: module name
+ """
+
+ # Required linux kernel version for this suite to run.
+ result = required_linux_kernel_version("4.19")
+ if result is not True:
+ pytest.skip("Kernel requirements are not met")
+
+ testsuite_run_time = time.asctime(time.localtime(time.time()))
+ logger.info("Testsuite start time: {}".format(testsuite_run_time))
+ logger.info("=" * 40)
+
+ logger.info("Running setup_module to create topology")
+
+ testdir = os.path.dirname(os.path.realpath(__file__))
+ json_file = "{}/multicast_pim6_sm_topo1.json".format(testdir)
+ tgen = Topogen(json_file, mod.__name__)
+ global topo
+ topo = tgen.json_topo
+ # ... and here it calls Mininet initialization functions.
+
+ # Starting topology, create tmp files which are loaded to routers
+ # to start deamons and then start routers
+ start_topology(tgen)
+
+ # Don"t run this test if we have any failure.
+ if tgen.routers_have_failure():
+ pytest.skip(tgen.errors)
+
+ # Creating configuration from JSON
+ build_config_from_json(tgen, tgen.json_topo)
+
+ logger.info("Running setup_module() done")
+
+
+def teardown_module():
+ """Teardown the pytest environment"""
+
+ logger.info("Running teardown_module to delete topology")
+
+ tgen = get_topogen()
+
+ # Clean up socat
+ kill_socat(tgen)
+
+ # Stop toplogy and Remove tmp files
+ tgen.stop_topology()
+
+ logger.info(
+ "Testsuite end time: {}".format(time.asctime(time.localtime(time.time())))
+ )
+ logger.info("=" * 40)
+
+
+#####################################################
+#
+# Local APIs
+#
+#####################################################
+
+
+def verify_mroute_repopulated(uptime_before, uptime_after):
+ """
+ API to compare uptime for mroutes
+
+ Parameters
+ ----------
+ * `uptime_before` : Uptime dictionary for any particular instance
+ * `uptime_after` : Uptime dictionary for any particular instance
+ """
+
+ for group in uptime_before.keys():
+ for source in uptime_before[group].keys():
+ if set(uptime_before[group]) != set(uptime_after[group]):
+ errormsg = (
+ "mroute (%s, %s) has not come"
+ " up after mroute clear [FAILED!!]" % (source, group)
+ )
+ return errormsg
+
+ d1 = datetime.datetime.strptime(uptime_before[group][source], "%H:%M:%S")
+ d2 = datetime.datetime.strptime(uptime_after[group][source], "%H:%M:%S")
+ if d2 >= d1:
+ errormsg = "mroute (%s, %s) is not " "repopulated [FAILED!!]" % (
+ source,
+ group,
+ )
+ return errormsg
+
+ logger.info("mroute (%s, %s) is " "repopulated [PASSED!!]", source, group)
+
+ return True
+
+
+def verify_state_incremented(state_before, state_after):
+ """
+ API to compare interface traffic state incrementing
+
+ Parameters
+ ----------
+ * `state_before` : State dictionary for any particular instance
+ * `state_after` : State dictionary for any particular instance
+ """
+
+ for router, state_data in state_before.items():
+ for state, value in state_data.items():
+ if state_before[router][state] >= state_after[router][state]:
+ errormsg = (
+ "[DUT: %s]: state %s value has not"
+ " incremented, Initial value: %s, "
+ "Current value: %s [FAILED!!]"
+ % (
+ router,
+ state,
+ state_before[router][state],
+ state_after[router][state],
+ )
+ )
+ return errormsg
+
+ logger.info(
+ "[DUT: %s]: State %s value is "
+ "incremented, Initial value: %s, Current value: %s"
+ " [PASSED!!]",
+ router,
+ state,
+ state_before[router][state],
+ state_after[router][state],
+ )
+
+ return True
+
+
+def next_hop_per_address_family(
+ tgen, dut, peer, addr_type, next_hop_dict, preferred_next_hop=PREFERRED_NEXT_HOP
+):
+ """
+ This function returns link_local or global next_hop per address-family
+ """
+
+ intferface = topo["routers"][peer]["links"]["{}".format(dut)]["interface"]
+ if addr_type == "ipv6" and "link_local" in preferred_next_hop:
+ next_hop = get_frr_ipv6_linklocal(tgen, peer, intf=intferface)
+ else:
+ next_hop = next_hop_dict[addr_type]
+
+ return next_hop
+
+
+#####################################################
+#
+# Testcases
+#
+#####################################################
+
+
+def test_multicast_data_traffic_static_RP_send_traffic_then_join_p0(request):
+ """
+ Verify Multicast data traffic with static RP, (*,g) and
+ (s,g) OIL updated correctly
+ """
+
+ tgen = get_topogen()
+ tc_name = request.node.name
+ write_test_header(tc_name)
+
+ # Creating configuration from JSON
+ reset_config_on_routers(tgen)
+
+ # Don"t run this test if we have any failure.
+ if tgen.routers_have_failure():
+ pytest.skip(tgen.errors)
+
+ logger.info("shut R1 to R4 and R3 to R5 link to simulate test topology")
+ r1_r4 = topo["routers"]["r1"]["links"]["r4"]["interface"]
+ r3_r5 = topo["routers"]["r3"]["links"]["r5"]["interface"]
+
+ shutdown_bringup_interface(tgen, "r1", r1_r4, False)
+ shutdown_bringup_interface(tgen, "r3", r3_r5, False)
+
+ step(
+ "Configure RP as R2 (loopback interface) for the"
+ " group range ff00::/8 on all the routers"
+ )
+
+ input_dict = {
+ "r2": {
+ "pim6": {
+ "rp": [
+ {
+ "rp_addr": topo["routers"]["r2"]["links"]["lo"]["ipv6"].split(
+ "/"
+ )[0],
+ "group_addr_range": GROUP_RANGE,
+ }
+ ]
+ }
+ }
+ }
+
+ result = create_pim_config(tgen, topo, input_dict)
+ assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
+
+ step("Start traffic first and then send the mld join")
+
+ step("Send multicast traffic from FRR3 to all the receivers" "ffaa::1-5")
+
+ intf_ip = topo["routers"]["i2"]["links"]["r3"]["ipv6"].split("/")[0]
+ intf = topo["routers"]["i2"]["links"]["r3"]["interface"]
+ result = socat_send_pim6_traffic(tgen, "i2", "UDP6-SEND", MLD_JOIN_RANGE_1, intf)
+ assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result)
+
+ source = topo["routers"]["i2"]["links"]["r3"]["ipv6"].split("/")[0]
+
+ step("verify upstream in NOT join Rej prune state on R3")
+
+ input_dict_sg = [
+ {
+ "dut": "r3",
+ "src_address": source,
+ "iif": topo["routers"]["r3"]["links"]["i2"]["interface"],
+ "oil": topo["routers"]["r3"]["links"]["r2"]["interface"],
+ }
+ ]
+
+ for data in input_dict_sg:
+ result = verify_upstream_iif(
+ tgen,
+ data["dut"],
+ data["iif"],
+ data["src_address"],
+ MLD_JOIN_RANGE_1,
+ joinState="NotJoined",
+ regState="RegPrune",
+ )
+ assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
+
+ step("joinRx value before join sent")
+ r2_r1_intf = topo["routers"]["r2"]["links"]["r1"]["interface"]
+ state_dict = {"r2": {r2_r1_intf: ["joinRx"]}}
+ state_before = verify_pim_interface_traffic(tgen, state_dict, addr_type="ipv6")
+ assert isinstance(
+ state_before, dict
+ ), "Testcase {} : Failed \n state_before is not dictionary \n " "Error: {}".format(
+ tc_name, result
+ )
+
+ step("send mld join (ffaa::1-5) to R1")
+ intf = topo["routers"]["i1"]["links"]["r1"]["interface"]
+ intf_ip = topo["routers"]["i1"]["links"]["r1"]["ipv6"].split("/")[0]
+ result = socat_send_mld_join(
+ tgen, "i1", "UDP6-RECV", MLD_JOIN_RANGE_1, intf, intf_ip
+ )
+ assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result)
+
+ step(
+ "Verify 'show ipv6 mroute' showing correct RPF and OIF"
+ " interface for (*,G) and (S,G) entries on all the nodes"
+ )
+
+ input_dict = [
+ {
+ "dut": "r1",
+ "src_address": "*",
+ "iif": topo["routers"]["r1"]["links"]["r2"]["interface"],
+ "oil": topo["routers"]["r1"]["links"]["i1"]["interface"],
+ },
+ {
+ "dut": "r1",
+ "src_address": source,
+ "iif": topo["routers"]["r1"]["links"]["r2"]["interface"],
+ "oil": topo["routers"]["r1"]["links"]["i1"]["interface"],
+ },
+ {
+ "dut": "r2",
+ "src_address": "*",
+ "iif": "lo",
+ "oil": topo["routers"]["r2"]["links"]["r1"]["interface"],
+ },
+ {
+ "dut": "r2",
+ "src_address": source,
+ "iif": topo["routers"]["r2"]["links"]["r3"]["interface"],
+ "oil": topo["routers"]["r2"]["links"]["r1"]["interface"],
+ },
+ {
+ "dut": "r3",
+ "src_address": source,
+ "iif": topo["routers"]["r3"]["links"]["i2"]["interface"],
+ "oil": topo["routers"]["r3"]["links"]["r2"]["interface"],
+ },
+ ]
+
+ for data in input_dict:
+ result = verify_mroutes(
+ tgen,
+ data["dut"],
+ data["src_address"],
+ MLD_JOIN_RANGE_1,
+ data["iif"],
+ data["oil"],
+ )
+ assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
+
+ step(
+ "Verify 'show ipv6 pim upstream' showing correct OIL and IIF"
+ " on all the nodes"
+ )
+ for data in input_dict:
+ result = verify_upstream_iif(
+ tgen, data["dut"], data["iif"], data["src_address"], MLD_JOIN_RANGE_1
+ )
+ assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
+
+ step("verify join state is joined")
+ for data in input_dict_sg:
+ result = verify_upstream_iif(
+ tgen,
+ data["dut"],
+ data["iif"],
+ data["src_address"],
+ MLD_JOIN_RANGE_1,
+ joinState="Joined",
+ regState="RegPrune",
+ )
+ assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
+
+ step("joinRx value after join sent")
+ state_after = verify_pim_interface_traffic(tgen, state_dict, addr_type="ipv6")
+ assert isinstance(
+ state_after, dict
+ ), "Testcase {} : Failed \n state_before is not dictionary \n " "Error: {}".format(
+ tc_name, result
+ )
+
+ step(
+ "r1 sent PIM (*,G) join to r2 verify using"
+ "'show ipv6 pim interface traffic' on RP connected interface"
+ )
+
+ result = verify_state_incremented(state_before, state_after)
+ assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
+
+ step("r1 sent PIM (S,G) join to r3 , verify using 'show ipv6 pim join'")
+ dut = "r3"
+ interface = topo["routers"]["r3"]["links"]["r2"]["interface"]
+ result = verify_pim_join(tgen, topo, dut, interface, MLD_JOIN_RANGE_1)
+ assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
+
+ _nexthop = topo["routers"]["r1"]["links"]["r2"]["ipv6"].split("/")[0]
+ next_hop = next_hop_per_address_family(tgen, "r1", "r2", "ipv6", _nexthop)
+
+ step("verify nexthop on r3 using 'show ipv6 pim nexthop'")
+ result = verify_pim_nexthop(tgen, topo, "r1", next_hop, "ipv6")
+ assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
+
+ step("verify mroute summary on r1 using 'show ipv6 mroute summary json'")
+ result = verify_mroute_summary(
+ tgen, "r1", sg_mroute=5, starg_mroute=5, total_mroute=10, addr_type="ipv6"
+ )
+ assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
+
+ write_test_footer(tc_name)
+
+
+def test_verify_mroute_when_receiver_is_outside_frr_p0(request):
+ """
+ Verify mroute detail when receiver is present
+ outside of FRR
+ """
+ tgen = get_topogen()
+ tc_name = request.node.name
+ write_test_header(tc_name)
+
+ # Creating configuration from JSON
+ reset_config_on_routers(tgen)
+
+ # Don"t run this test if we have any failure.
+ if tgen.routers_have_failure():
+ pytest.skip(tgen.errors)
+
+ step("Configure static RP on r4 for group range " "(ffcc::1-5) and (ffbb::1-5)")
+
+ _GROUP_RANGE = GROUP_RANGE_2 + GROUP_RANGE_3
+ _MLD_JOIN_RANGE = MLD_JOIN_RANGE_2 + MLD_JOIN_RANGE_3
+
+ input_dict = {
+ "r4": {
+ "pim6": {
+ "rp": [
+ {
+ "rp_addr": topo["routers"]["r4"]["links"]["lo"]["ipv6"].split(
+ "/"
+ )[0],
+ "group_addr_range": _GROUP_RANGE,
+ }
+ ]
+ }
+ }
+ }
+
+ result = create_pim_config(tgen, topo, input_dict)
+ assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
+
+ step("send mld join (ffaa::1-5) to R1")
+ intf = topo["routers"]["i1"]["links"]["r1"]["interface"]
+ intf_ip = topo["routers"]["i1"]["links"]["r1"]["ipv6"].split("/")[0]
+ result = socat_send_mld_join(
+ tgen, "i1", "UDP6-RECV", _MLD_JOIN_RANGE, intf, intf_ip
+ )
+ assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result)
+
+ step("verify MLD joins received on r1")
+ dut = "r1"
+ interface = topo["routers"]["r1"]["links"]["i1"]["interface"]
+ result = verify_mld_groups(tgen, dut, interface, _MLD_JOIN_RANGE)
+ assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
+
+ step("Send multicast traffic from FRR3 to all the receivers" "ffaa::1-5")
+ intf_ip = topo["routers"]["i2"]["links"]["r3"]["ipv6"].split("/")[0]
+ intf = topo["routers"]["i2"]["links"]["r3"]["interface"]
+ result = socat_send_pim6_traffic(tgen, "i2", "UDP6-SEND", _MLD_JOIN_RANGE, intf)
+ assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result)
+
+ step(
+ "Configure one more receiver in r5 enable mld and send"
+ " join (ffaa::1-5) and (ffbb::1-5)"
+ )
+ r5_i5 = topo["routers"]["r5"]["links"]["i5"]["interface"]
+
+ input_dict = {"r5": {"mld": {"interfaces": {r5_i5: {"mld": {"version": "1"}}}}}}
+ result = create_mld_config(tgen, topo, input_dict)
+ assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result)
+
+ i5_r5 = topo["routers"]["i5"]["links"]["r5"]["interface"]
+ intf_ip = topo["routers"]["i5"]["links"]["r5"]["ipv6"].split("/")[0]
+ result = socat_send_mld_join(
+ tgen, "i5", "UDP6-RECV", _MLD_JOIN_RANGE, i5_r5, intf_ip
+ )
+ assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result)
+
+ step("FRR1 has 10 (*.G) and 10 (S,G) verify using 'show ipv6 mroute'")
+ step(
+ "All the receiver are receiving traffic on FRR1 and (S,G) OIL is towards"
+ "receivers, verify using 'show mroute' 'show pim upstream'"
+ )
+ step(
+ "All the receiver are receiving traffic on r5 and (S,G) OIL is "
+ "toward receivers, verify using 'show ipv6 mroute' 'show ipv6 pim upstream'"
+ )
+
+ source = topo["routers"]["i2"]["links"]["r3"]["ipv6"].split("/")[0]
+ input_dict = [
+ {
+ "dut": "r1",
+ "src_address": "*",
+ "iif": topo["routers"]["r1"]["links"]["r4"]["interface"],
+ "oil": topo["routers"]["r1"]["links"]["i1"]["interface"],
+ },
+ {
+ "dut": "r1",
+ "src_address": source,
+ "iif": topo["routers"]["r1"]["links"]["r2"]["interface"],
+ "oil": topo["routers"]["r1"]["links"]["i1"]["interface"],
+ },
+ {
+ "dut": "r5",
+ "src_address": "*",
+ "iif": topo["routers"]["r5"]["links"]["r4"]["interface"],
+ "oil": topo["routers"]["r5"]["links"]["i5"]["interface"],
+ },
+ {
+ "dut": "r5",
+ "src_address": source,
+ "iif": topo["routers"]["r5"]["links"]["r3"]["interface"],
+ "oil": topo["routers"]["r5"]["links"]["i5"]["interface"],
+ },
+ ]
+
+ for data in input_dict:
+ result = verify_mroutes(
+ tgen,
+ data["dut"],
+ data["src_address"],
+ _MLD_JOIN_RANGE,
+ data["iif"],
+ data["oil"],
+ )
+ assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
+
+ step(
+ "FRR3 has (S,G) OIL created toward r2/r5 receiver and FRR1 receiver"
+ "'show ipv6 pim '"
+ )
+ input_dict = [
+ {
+ "dut": "r3",
+ "src_address": source,
+ "iif": topo["routers"]["r3"]["links"]["i2"]["interface"],
+ "oil": topo["routers"]["r3"]["links"]["r5"]["interface"],
+ },
+ {
+ "dut": "r3",
+ "src_address": source,
+ "iif": topo["routers"]["r3"]["links"]["i2"]["interface"],
+ "oil": topo["routers"]["r3"]["links"]["r2"]["interface"],
+ },
+ ]
+ for data in input_dict:
+ result = verify_pim_state(
+ tgen,
+ data["dut"],
+ data["iif"],
+ data["oil"],
+ _MLD_JOIN_RANGE,
+ data["src_address"],
+ )
+ assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
+
+ for data in input_dict:
+ result = verify_upstream_iif(
+ tgen,
+ data["dut"],
+ data["iif"],
+ data["src_address"],
+ _MLD_JOIN_RANGE,
+ joinState="Joined",
+ regState="RegPrune",
+ )
+ assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
+
+ step("Traffic is received fine on FRR1 and r5 " " 'show ipv6 mroute count' ")
+
+ result = verify_sg_traffic(tgen, "r1", _MLD_JOIN_RANGE, source, "ipv6")
+ assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
+
+ result = verify_sg_traffic(tgen, "r5", _MLD_JOIN_RANGE, source, "ipv6")
+ assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
+
+ write_test_footer(tc_name)
+
+
+def test_verify_mroute_when_frr_is_transit_router_p2(request):
+ """
+ Verify (*,G) and (S,G) populated correctly
+ when FRR is the transit router
+ """
+
+ tgen = get_topogen()
+ tc_name = request.node.name
+ write_test_header(tc_name)
+
+ # Creating configuration from JSON
+ reset_config_on_routers(tgen)
+
+ # Don"t run this test if we have any failure.
+ if tgen.routers_have_failure():
+ pytest.skip(tgen.errors)
+
+ step("Configure static RP for (ffaa::1-5) in r5")
+ input_dict = {
+ "r5": {
+ "pim6": {
+ "rp": [
+ {
+ "rp_addr": topo["routers"]["r5"]["links"]["lo"]["ipv6"].split(
+ "/"
+ )[0],
+ "group_addr_range": GROUP_RANGE_1,
+ }
+ ]
+ }
+ }
+ }
+
+ result = create_pim_config(tgen, topo, input_dict)
+ assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
+
+ step("Enable mld on FRR1 interface and send mld join ")
+
+ step("send mld join (ffaa::1-5) to R1")
+ intf = topo["routers"]["i1"]["links"]["r1"]["interface"]
+ intf_ip = topo["routers"]["i1"]["links"]["r1"]["ipv6"].split("/")[0]
+ result = socat_send_mld_join(
+ tgen, "i1", "UDP6-RECV", MLD_JOIN_RANGE_1, intf, intf_ip
+ )
+ assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result)
+
+ step("verify mld groups received on R1")
+ dut = "r1"
+ interface = topo["routers"]["r1"]["links"]["i1"]["interface"]
+ result = verify_mld_groups(tgen, dut, interface, MLD_JOIN_RANGE_1)
+ assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
+
+ step("Send multicast traffic from FRR3 to ffaa::1-5 receivers")
+ intf_ip = topo["routers"]["i2"]["links"]["r3"]["ipv6"].split("/")[0]
+ intf = topo["routers"]["i2"]["links"]["r3"]["interface"]
+ result = socat_send_pim6_traffic(tgen, "i2", "UDP6-SEND", MLD_JOIN_RANGE_1, intf)
+ assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result)
+
+ step("shut the direct link to R1 ")
+ intf = topo["routers"]["r1"]["links"]["r2"]["interface"]
+ shutdown_bringup_interface(tgen, dut, intf, False)
+
+ step(
+ "FRR4 has (S,G) and (*,G) ,created where incoming interface"
+ " toward FRR3 and OIL toward R2, verify using 'show ipv6 mroute'"
+ " 'show ipv6 pim state' "
+ )
+
+ source = topo["routers"]["i2"]["links"]["r3"]["ipv6"].split("/")[0]
+ input_dict = [
+ {
+ "dut": "r5",
+ "src_address": "*",
+ "iif": "lo",
+ "oil": topo["routers"]["r5"]["links"]["r4"]["interface"],
+ },
+ {
+ "dut": "r5",
+ "src_address": source,
+ "iif": topo["routers"]["r5"]["links"]["r3"]["interface"],
+ "oil": topo["routers"]["r5"]["links"]["r4"]["interface"],
+ },
+ ]
+ for data in input_dict:
+ result = verify_mroutes(
+ tgen,
+ data["dut"],
+ data["src_address"],
+ MLD_JOIN_RANGE_1,
+ data["iif"],
+ data["oil"],
+ )
+ assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
+
+ step("verify multicast traffic")
+ result = verify_sg_traffic(tgen, "r5", MLD_JOIN_RANGE_1, source, "ipv6")
+ assert (
+ result is True
+ ), "Testcase {} : Failed \n mroutes traffic " "still present \n Error: {}".format(
+ tc_name, result
+ )
+
+ step("Stop multicast traffic from FRR3")
+ dut = "i2"
+ intf = topo["routers"]["i2"]["links"]["r3"]["interface"]
+ shutdown_bringup_interface(tgen, dut, intf, False)
+
+ step("(*,G) present on R5 after source shut")
+
+ input_dict_1 = [
+ {
+ "dut": "r5",
+ "src_address": "*",
+ "iif": "lo",
+ "oil": topo["routers"]["r5"]["links"]["r4"]["interface"],
+ },
+ ]
+ for data in input_dict_1:
+ result = verify_mroutes(
+ tgen,
+ data["dut"],
+ data["src_address"],
+ MLD_JOIN_RANGE_1,
+ data["iif"],
+ data["oil"],
+ )
+ assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
+
+ step("stop mld receiver from FRR1")
+ dut = "i1"
+ intf = topo["routers"]["i1"]["links"]["r1"]["interface"]
+ shutdown_bringup_interface(tgen, dut, intf, False)
+
+ step(
+ "After stopping receiver (*, G) and (S, G) also got removed from transit"
+ " router 'show ipv6 mroute'"
+ )
+
+ for data in input_dict:
+ result = verify_mroutes(
+ tgen,
+ data["dut"],
+ data["src_address"],
+ MLD_JOIN_RANGE_1,
+ data["iif"],
+ data["oil"],
+ expected=False,
+ )
+ assert result is not True, (
+ "Testcase {} : Failed \n mroutes "
+ "not removed after removing the receivers \n Error: {}".format(
+ tc_name, result
+ )
+ )
+
+ logger.info("Expected Behavior: {}".format(result))
+
+ write_test_footer(tc_name)
+
+
+def test_verify_mroute_when_RP_unreachable_p1(request):
+ """
+ Verify (S,G) should not create if RP is not reachable
+ """
+
+ tgen = get_topogen()
+ tc_name = request.node.name
+ write_test_header(tc_name)
+
+ # Creating configuration from JSON
+ reset_config_on_routers(tgen)
+
+ # Don"t run this test if we have any failure.
+ if tgen.routers_have_failure():
+ pytest.skip(tgen.errors)
+
+ step("Configure RP on FRR2 (loopback interface) for " "the group range ffaa::1-5")
+
+ input_dict = {
+ "r2": {
+ "pim6": {
+ "rp": [
+ {
+ "rp_addr": topo["routers"]["r2"]["links"]["lo"]["ipv6"].split(
+ "/"
+ )[0],
+ "group_addr_range": GROUP_RANGE_1,
+ }
+ ]
+ }
+ }
+ }
+
+ result = create_pim_config(tgen, topo, input_dict)
+ assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
+
+ step("Enable mld on FRR1 interface and send mld join ffaa::1-5")
+
+ step("send mld join (ffaa::1-5) to R1")
+ intf = topo["routers"]["i1"]["links"]["r1"]["interface"]
+ intf_ip = topo["routers"]["i1"]["links"]["r1"]["ipv6"].split("/")[0]
+ result = socat_send_mld_join(
+ tgen, "i1", "UDP6-RECV", MLD_JOIN_RANGE_1, intf, intf_ip
+ )
+ assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result)
+
+ step("Send multicast traffic from FRR3 to ffaa::1-5 receivers")
+ intf_ip = topo["routers"]["i2"]["links"]["r3"]["ipv6"].split("/")[0]
+ intf = topo["routers"]["i2"]["links"]["r3"]["interface"]
+ result = socat_send_pim6_traffic(tgen, "i2", "UDP6-SEND", MLD_JOIN_RANGE_1, intf)
+ assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result)
+
+ step("Configure one MLD interface on FRR3 node and send MLD" " join (ffcc::1)")
+ r3_i8 = topo["routers"]["r3"]["links"]["i8"]["interface"]
+ input_dict = {"r3": {"mld": {"interfaces": {r3_i8: {"mld": {"version": "1"}}}}}}
+ result = create_mld_config(tgen, topo, input_dict)
+ assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result)
+
+ step("send mld join (ffaa::1-5) to R1")
+ intf = topo["routers"]["i8"]["links"]["r3"]["interface"]
+ intf_ip = topo["routers"]["i8"]["links"]["r3"]["ipv6"].split("/")[0]
+ result = socat_send_mld_join(
+ tgen, "i8", "UDP6-RECV", MLD_JOIN_RANGE_1, intf, intf_ip
+ )
+ assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result)
+
+ step("verify MLD groups received ")
+ dut = "r3"
+ interface = topo["routers"]["r3"]["links"]["i8"]["interface"]
+ result = verify_mld_groups(tgen, dut, interface, MLD_JOIN_RANGE_1)
+ assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
+
+ source = topo["routers"]["i2"]["links"]["r3"]["ipv6"].split("/")[0]
+ input_dict = [
+ {
+ "dut": "r3",
+ "src_address": "*",
+ "iif": topo["routers"]["r3"]["links"]["r2"]["interface"],
+ "oil": topo["routers"]["r3"]["links"]["i8"]["interface"],
+ },
+ {
+ "dut": "r3",
+ "src_address": source,
+ "iif": topo["routers"]["r3"]["links"]["i2"]["interface"],
+ "oil": topo["routers"]["r3"]["links"]["i8"]["interface"],
+ },
+ ]
+ for data in input_dict:
+ result = verify_mroutes(
+ tgen,
+ data["dut"],
+ data["src_address"],
+ MLD_JOIN_RANGE_1,
+ data["iif"],
+ data["oil"],
+ )
+ assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
+
+ step("Shut the RP connected interface from r3 ( r2 to r3) link")
+ dut = "r3"
+ intf = topo["routers"]["r3"]["links"]["r2"]["interface"]
+ shutdown_bringup_interface(tgen, dut, intf, False)
+
+ step("Clear the mroute on r3")
+ clear_pim6_mroute(tgen, "r3")
+
+ step(
+ "After Shut the RP interface and clear the mroute verify all "
+ "(*,G) and (S,G) got timeout from FRR3 node , verify using "
+ " 'show ipv6 mroute' "
+ )
+ r3_r2 = topo["routers"]["r3"]["links"]["r2"]["interface"]
+ r3_i8 = topo["routers"]["r3"]["links"]["i8"]["interface"]
+
+ result = verify_mroutes(
+ tgen, "r3", "*", MLD_JOIN_RANGE_1, r3_r2, r3_i8, expected=False
+ )
+ assert (
+ result is not True
+ ), "Testcase {} : Failed \n mroutes are" " still present \n Error: {}".format(
+ tc_name, result
+ )
+ logger.info("Expected Behavior: {}".format(result))
+
+ step("mld groups are present verify using 'show ip mld group'")
+ dut = "r1"
+ interface = topo["routers"]["r1"]["links"]["i1"]["interface"]
+ result = verify_mld_groups(tgen, dut, interface, MLD_JOIN_RANGE_1)
+ assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
+
+ write_test_footer(tc_name)
+
+
+def test_modify_mld_query_timer_p0(request):
+ """
+ Verify modification of mld query timer should get update
+ accordingly
+ """
+
+ tgen = get_topogen()
+ tc_name = request.node.name
+ write_test_header(tc_name)
+
+ # Creating configuration from JSON
+ reset_config_on_routers(tgen)
+
+ # Don"t run this test if we have any failure.
+ if tgen.routers_have_failure():
+ pytest.skip(tgen.errors)
+
+ step("send mld join (ffaa::1-5) to R1")
+ intf = topo["routers"]["i8"]["links"]["r3"]["interface"]
+ intf_ip = topo["routers"]["i8"]["links"]["r3"]["ipv6"].split("/")[0]
+ result = socat_send_mld_join(
+ tgen, "i8", "UDP6-RECV", MLD_JOIN_RANGE_1, intf, intf_ip
+ )
+ assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result)
+
+ step("Enable MLD on receiver interface")
+ intf_r3_i8 = topo["routers"]["r3"]["links"]["i8"]["interface"]
+ input_dict_1 = {
+ "r3": {"mld": {"interfaces": {intf_r3_i8: {"mld": {"version": "1"}}}}}
+ }
+
+ result = create_mld_config(tgen, topo, input_dict_1)
+ assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result)
+
+ step("verify MLD groups received ")
+ dut = "r3"
+ interface = topo["routers"]["r3"]["links"]["i8"]["interface"]
+ result = verify_mld_groups(tgen, dut, interface, MLD_JOIN_RANGE_1)
+ assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
+
+ step("Configure RP on R2 (loopback interface) for the" " group range ffaa::1-5")
+
+ input_dict = {
+ "r2": {
+ "pim6": {
+ "rp": [
+ {
+ "rp_addr": topo["routers"]["r2"]["links"]["lo"]["ipv6"].split(
+ "/"
+ )[0],
+ "group_addr_range": GROUP_RANGE_1,
+ }
+ ]
+ }
+ }
+ }
+
+ result = create_pim_config(tgen, topo, input_dict)
+ assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
+
+ step("Send multicast traffic from FRR3 to ffaa::1-5 receivers")
+ intf_ip = topo["routers"]["i2"]["links"]["r3"]["ipv6"].split("/")[0]
+ intf = topo["routers"]["i2"]["links"]["r3"]["interface"]
+ result = socat_send_pim6_traffic(tgen, "i2", "UDP6-SEND", MLD_JOIN_RANGE_1, intf)
+ assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result)
+
+ step(
+ "Verify 'show ipv6 mroute' showing correct RPF and OIF"
+ " interface for (*,G) and (S,G) entries on all the nodes"
+ )
+
+ source = topo["routers"]["i2"]["links"]["r3"]["ipv6"].split("/")[0]
+ input_dict_4 = [
+ {
+ "dut": "r3",
+ "src_address": source,
+ "iif": topo["routers"]["r3"]["links"]["i2"]["interface"],
+ "oil": topo["routers"]["r3"]["links"]["i8"]["interface"],
+ },
+ {
+ "dut": "r3",
+ "src_address": "*",
+ "iif": topo["routers"]["r3"]["links"]["r2"]["interface"],
+ "oil": topo["routers"]["r3"]["links"]["i8"]["interface"],
+ },
+ ]
+ for data in input_dict_4:
+ result = verify_mroutes(
+ tgen,
+ data["dut"],
+ data["src_address"],
+ MLD_JOIN_RANGE_1,
+ data["iif"],
+ data["oil"],
+ mwait=20,
+ )
+ assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
+
+ step(
+ "Verify 'show ipv6 pim upstream' showing correct OIL and IIF"
+ " on all the nodes"
+ )
+ for data in input_dict_4:
+ result = verify_upstream_iif(
+ tgen, data["dut"], data["iif"], data["src_address"], MLD_JOIN_RANGE_1
+ )
+ assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
+
+ step("Modify mld query interval default to other timer on FRR1" ", 3 times")
+
+ input_dict_1 = {
+ "r3": {
+ "mld": {
+ "interfaces": {intf_r3_i8: {"mld": {"query": {"query-interval": 100}}}}
+ }
+ }
+ }
+ result = create_mld_config(tgen, topo, input_dict_1)
+ assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result)
+
+ result = verify_mld_config(tgen, input_dict_1)
+ assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result)
+
+ input_dict_2 = {
+ "r3": {
+ "mld": {
+ "interfaces": {intf_r3_i8: {"mld": {"query": {"query-interval": 200}}}}
+ }
+ }
+ }
+ result = create_mld_config(tgen, topo, input_dict_2)
+ assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result)
+
+ result = verify_mld_config(tgen, input_dict_2)
+ assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result)
+
+ input_dict_3 = {
+ "r3": {
+ "mld": {
+ "interfaces": {intf_r3_i8: {"mld": {"query": {"query-interval": 300}}}}
+ }
+ }
+ }
+ result = create_mld_config(tgen, topo, input_dict_3)
+ assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result)
+
+ result = verify_mld_config(tgen, input_dict_3)
+ assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result)
+
+ input_dict_3 = {
+ "r3": {
+ "mld": {
+ "interfaces": {
+ intf_r3_i8: {
+ "mld": {"query": {"query-interval": 300, "delete": True}}
+ }
+ }
+ }
+ }
+ }
+ result = create_mld_config(tgen, topo, input_dict_3)
+ assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result)
+
+ step("veriffy mroutes after query modification")
+ for data in input_dict_4:
+ result = verify_mroutes(
+ tgen,
+ data["dut"],
+ data["src_address"],
+ MLD_JOIN_RANGE_1,
+ data["iif"],
+ data["oil"],
+ mwait=20,
+ )
+ assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
+
+ step("Verify that no core is observed")
+ if tgen.routers_have_failure():
+ assert False, "Testcase {}: Failed Error: {}".format(tc_name, result)
+
+ write_test_footer(tc_name)
+
+
+def test_modify_mld_max_query_response_timer_p0(request):
+ """
+ Verify modification of mld max query response timer
+ should get update accordingly
+ """
+
+ tgen = get_topogen()
+ tc_name = request.node.name
+ write_test_header(tc_name)
+
+ # Creating configuration from JSON
+ reset_config_on_routers(tgen)
+
+ # Don"t run this test if we have any failure.
+ if tgen.routers_have_failure():
+ pytest.skip(tgen.errors)
+
+ step("Enable mld on FRR1 interface and send MLD join")
+ step("send mld join (ffaa::1-5) to R1")
+ intf = topo["routers"]["i1"]["links"]["r1"]["interface"]
+ intf_ip = topo["routers"]["i1"]["links"]["r1"]["ipv6"].split("/")[0]
+ result = socat_send_mld_join(
+ tgen, "i1", "UDP6-RECV", MLD_JOIN_RANGE_1, intf, intf_ip
+ )
+ assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result)
+
+ r1_i1 = topo["routers"]["r1"]["links"]["i1"]["interface"]
+ step("Configure mld query response time to 10 sec on FRR1")
+ input_dict_1 = {
+ "r1": {
+ "mld": {
+ "interfaces": {
+ r1_i1: {
+ "mld": {
+ "version": "1",
+ "query": {"query-max-response-time": 10},
+ }
+ }
+ }
+ }
+ }
+ }
+ result = create_mld_config(tgen, topo, input_dict_1)
+ assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result)
+
+ result = verify_mld_config(tgen, input_dict_1)
+ assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result)
+
+ step("Configure RP on R2 (loopback interface) for the" " group range 225.0.0.0/8")
+
+ input_dict = {
+ "r2": {
+ "pim6": {
+ "rp": [
+ {
+ "rp_addr": topo["routers"]["r2"]["links"]["lo"]["ipv6"].split(
+ "/"
+ )[0],
+ "group_addr_range": GROUP_RANGE_1,
+ }
+ ]
+ }
+ }
+ }
+
+ result = create_pim_config(tgen, topo, input_dict)
+ assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
+
+ step("Send multicast traffic from FRR3 to ffaa::1-5 receivers")
+ intf_ip = topo["routers"]["i2"]["links"]["r3"]["ipv6"].split("/")[0]
+ intf = topo["routers"]["i2"]["links"]["r3"]["interface"]
+ result = socat_send_pim6_traffic(tgen, "i2", "UDP6-SEND", MLD_JOIN_RANGE_1, intf)
+ assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result)
+
+ step(
+ "Verify 'show ipv6 mroute' showing correct RPF and OIF"
+ " interface for (*,G) and (S,G) entries on all the nodes"
+ )
+
+ source = topo["routers"]["i2"]["links"]["r3"]["ipv6"].split("/")[0]
+ input_dict_5 = [
+ {
+ "dut": "r1",
+ "src_address": "*",
+ "iif": topo["routers"]["r1"]["links"]["r2"]["interface"],
+ "oil": topo["routers"]["r1"]["links"]["i1"]["interface"],
+ },
+ {
+ "dut": "r1",
+ "src_address": source,
+ "iif": topo["routers"]["r1"]["links"]["r2"]["interface"],
+ "oil": topo["routers"]["r1"]["links"]["i1"]["interface"],
+ },
+ {
+ "dut": "r3",
+ "src_address": source,
+ "iif": topo["routers"]["r3"]["links"]["i2"]["interface"],
+ "oil": topo["routers"]["r3"]["links"]["r2"]["interface"],
+ },
+ ]
+ for data in input_dict_5:
+ result = verify_mroutes(
+ tgen,
+ data["dut"],
+ data["src_address"],
+ MLD_JOIN_RANGE_1,
+ data["iif"],
+ data["oil"],
+ mwait=20,
+ )
+ assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
+
+ step(
+ "Verify 'show ipv6 pim upstream' showing correct OIL and IIF"
+ " on all the nodes"
+ )
+ for data in input_dict_5:
+ result = verify_upstream_iif(
+ tgen, data["dut"], data["iif"], data["src_address"], MLD_JOIN_RANGE_1
+ )
+ assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
+
+ step("Delete the PIM and mld on FRR1")
+ r1_i1 = topo["routers"]["r1"]["links"]["i1"]["interface"]
+ input_dict_1 = {"r1": {"pim6": {"disable": [r1_i1]}}}
+ result = create_pim_config(tgen, topo, input_dict_1)
+ assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result)
+
+ input_dict_2 = {
+ "r1": {
+ "mld": {
+ "interfaces": {
+ r1_i1: {
+ "mld": {
+ "version": "1",
+ "delete": True,
+ "query": {"query-max-response-time": 10, "delete": True},
+ }
+ }
+ }
+ }
+ }
+ }
+ result = create_mld_config(tgen, topo, input_dict_2)
+ assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result)
+
+ step("Configure PIM on FRR")
+ result = create_pim_config(tgen, topo["routers"])
+ assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result)
+
+ step("Configure max query response timer 100sec on FRR1")
+ input_dict_3 = {
+ "r1": {
+ "mld": {
+ "interfaces": {
+ r1_i1: {
+ "mld": {
+ "version": "1",
+ "query": {"query-max-response-time": 100},
+ }
+ }
+ }
+ }
+ }
+ }
+ result = create_mld_config(tgen, topo, input_dict_3)
+ assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result)
+
+ result = verify_mld_config(tgen, input_dict_3)
+ assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result)
+
+ step(
+ "Remove and add max query response timer cli with different"
+ "timer 5 times on FRR1 Enable mld and mld version 2 on FRR1"
+ " on FRR1"
+ )
+
+ input_dict_3 = {
+ "r1": {
+ "mld": {
+ "interfaces": {
+ r1_i1: {
+ "mld": {
+ "version": "1",
+ "query": {"query-max-response-time": 110},
+ }
+ }
+ }
+ }
+ }
+ }
+ result = create_mld_config(tgen, topo, input_dict_3)
+ assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result)
+
+ result = verify_mld_config(tgen, input_dict_3)
+ assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result)
+
+ input_dict_3 = {
+ "r1": {
+ "mld": {
+ "interfaces": {
+ r1_i1: {
+ "mld": {
+ "version": "1",
+ "query": {"query-max-response-time": 120},
+ }
+ }
+ }
+ }
+ }
+ }
+ result = create_mld_config(tgen, topo, input_dict_3)
+ assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result)
+
+ result = verify_mld_config(tgen, input_dict_3)
+ assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result)
+
+ input_dict_3 = {
+ "r1": {
+ "mld": {
+ "interfaces": {
+ r1_i1: {
+ "mld": {
+ "version": "1",
+ "query": {"query-max-response-time": 140},
+ }
+ }
+ }
+ }
+ }
+ }
+ result = create_mld_config(tgen, topo, input_dict_3)
+ assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result)
+
+ result = verify_mld_config(tgen, input_dict_3)
+ assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result)
+
+ input_dict_3 = {
+ "r1": {
+ "mld": {
+ "interfaces": {
+ r1_i1: {
+ "mld": {
+ "version": "1",
+ "query": {"query-max-response-time": 150},
+ }
+ }
+ }
+ }
+ }
+ }
+ result = create_mld_config(tgen, topo, input_dict_3)
+ assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result)
+
+ result = verify_mld_config(tgen, input_dict_3)
+ assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result)
+
+ step("Enable mld and mld version 2 on FRR1 on FRR1")
+
+ input_dict_4 = {"r1": {"mld": {"interfaces": {r1_i1: {"mld": {"version": "1"}}}}}}
+ result = create_mld_config(tgen, topo, input_dict_4)
+ assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result)
+
+ result = verify_mld_config(tgen, input_dict_3)
+ assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result)
+
+ step("Verify that no core is observed")
+ if tgen.routers_have_failure():
+ assert False, "Testcase {}: Failed Error: {}".format(tc_name, result)
+
+ write_test_footer(tc_name)
+
+
+def test_verify_impact_on_multicast_traffic_when_RP_removed_p0(request):
+ """
+ Verify removing the RP should not impact the multicast
+ data traffic
+ """
+
+ tgen = get_topogen()
+ tc_name = request.node.name
+ write_test_header(tc_name)
+
+ # Creating configuration from JSON
+ reset_config_on_routers(tgen)
+
+ # Don"t run this test if we have any failure.
+ if tgen.routers_have_failure():
+ pytest.skip(tgen.errors)
+
+ step("send multicast traffic for group range ffaa::1-5")
+
+ step("Send multicast traffic from FRR3 to ffaa::1-5 receivers")
+ intf_ip = topo["routers"]["i2"]["links"]["r3"]["ipv6"].split("/")[0]
+ intf = topo["routers"]["i2"]["links"]["r3"]["interface"]
+ result = socat_send_pim6_traffic(tgen, "i2", "UDP6-SEND", MLD_JOIN_RANGE_1, intf)
+ assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result)
+
+ step("Configure static RP for group (ffaa::1) on r5")
+ input_dict = {
+ "r2": {
+ "pim6": {
+ "rp": [
+ {
+ "rp_addr": topo["routers"]["r2"]["links"]["lo"]["ipv6"].split(
+ "/"
+ )[0],
+ "group_addr_range": GROUP_RANGE_1,
+ }
+ ]
+ }
+ }
+ }
+
+ result = create_pim_config(tgen, topo, input_dict)
+ assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
+
+ step("Enable mld on FRR1 interface and send MLD join")
+ step("send mld join (ffaa::1-5) to R1")
+ intf = topo["routers"]["i1"]["links"]["r1"]["interface"]
+ intf_ip = topo["routers"]["i1"]["links"]["r1"]["ipv6"].split("/")[0]
+ result = socat_send_mld_join(
+ tgen, "i1", "UDP6-RECV", MLD_JOIN_RANGE_1, intf, intf_ip
+ )
+ assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result)
+
+ step(
+ "After SPT switchover traffic is flowing (FRR3-FRR2-FRR1)"
+ " and (s,g) OIL updated correctly using 'show ipv6 mroute'"
+ " 'show ipv6 pim upstream'"
+ )
+
+ source = topo["routers"]["i2"]["links"]["r3"]["ipv6"].split("/")[0]
+ input_dict = [
+ {
+ "dut": "r3",
+ "src_address": source,
+ "iif": topo["routers"]["r3"]["links"]["i2"]["interface"],
+ "oil": topo["routers"]["r3"]["links"]["r2"]["interface"],
+ },
+ {
+ "dut": "r1",
+ "src_address": "*",
+ "iif": topo["routers"]["r1"]["links"]["r2"]["interface"],
+ "oil": topo["routers"]["r1"]["links"]["i1"]["interface"],
+ },
+ {
+ "dut": "r1",
+ "src_address": source,
+ "iif": topo["routers"]["r1"]["links"]["r2"]["interface"],
+ "oil": topo["routers"]["r1"]["links"]["i1"]["interface"],
+ },
+ ]
+
+ for data in input_dict:
+ if data["dut"] == "r1":
+ result = verify_mroutes(
+ tgen,
+ data["dut"],
+ data["src_address"],
+ MLD_JOIN_RANGE_1,
+ data["iif"],
+ data["oil"],
+ )
+ assert result is True, "Testcase {} : Failed Error: {}".format(
+ tc_name, result
+ )
+
+ for data in input_dict:
+ if data["dut"] == "r3":
+ result = verify_mroutes(
+ tgen,
+ data["dut"],
+ data["src_address"],
+ MLD_JOIN_RANGE_1,
+ data["iif"],
+ data["oil"],
+ )
+ assert result is True, "Testcase {} : Failed Error: {}".format(
+ tc_name, result
+ )
+
+ for data in input_dict:
+ result = verify_upstream_iif(
+ tgen, data["dut"], data["iif"], data["src_address"], MLD_JOIN_RANGE_1
+ )
+ assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
+
+ step("Shut and No shut RP interface in r5")
+ dut = "r5"
+ intf = "lo"
+ shutdown_bringup_interface(tgen, dut, intf, False)
+ shutdown_bringup_interface(tgen, dut, intf, True)
+
+ step(
+ "After no shut of RP verify (*,G) entries re-populated again"
+ " and uptime go reset verify using 'show ipv6 mroute'"
+ " 'show ipv6 pim state'"
+ )
+
+ for data in input_dict:
+ result = verify_mroutes(
+ tgen,
+ data["dut"],
+ data["src_address"],
+ MLD_JOIN_RANGE_1,
+ data["iif"],
+ data["oil"],
+ )
+ assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
+
+ step("Remove static RP for group (ffaa::1) on r5")
+ input_dict = {
+ "r2": {
+ "pim6": {
+ "rp": [
+ {
+ "rp_addr": topo["routers"]["r2"]["links"]["lo"]["ipv6"].split(
+ "/"
+ )[0],
+ "group_addr_range": GROUP_RANGE_1,
+ "delete": True,
+ }
+ ]
+ }
+ }
+ }
+
+ result = create_pim_config(tgen, topo, input_dict)
+ assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
+
+ step("After remove of RP verify no impact on (s,g)")
+
+ input_dict = [
+ {
+ "dut": "r3",
+ "src_address": source,
+ "iif": topo["routers"]["r3"]["links"]["i2"]["interface"],
+ "oil": topo["routers"]["r3"]["links"]["r2"]["interface"],
+ },
+ {
+ "dut": "r1",
+ "src_address": source,
+ "iif": topo["routers"]["r1"]["links"]["r2"]["interface"],
+ "oil": topo["routers"]["r1"]["links"]["i1"]["interface"],
+ },
+ ]
+
+ for data in input_dict:
+ result = verify_mroutes(
+ tgen,
+ data["dut"],
+ data["src_address"],
+ MLD_JOIN_RANGE_1,
+ data["iif"],
+ data["oil"],
+ )
+ assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
+
+ step("verify multicast traffic is flowing")
+ result = verify_sg_traffic(tgen, "r1", MLD_JOIN_RANGE_1, source, "ipv6")
+ assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
+
+ write_test_footer(tc_name)
+
+
+if __name__ == "__main__":
+ args = ["-s"] + sys.argv[1:]
+ sys.exit(pytest.main(args))
diff --git a/tests/topotests/multicast_pim6_sm_topo1/test_multicast_pim6_sm2.py b/tests/topotests/multicast_pim6_sm_topo1/test_multicast_pim6_sm2.py
new file mode 100644
index 0000000000..788a839918
--- /dev/null
+++ b/tests/topotests/multicast_pim6_sm_topo1/test_multicast_pim6_sm2.py
@@ -0,0 +1,606 @@
+#!/usr/bin/env python
+# SPDX-License-Identifier: ISC
+
+#
+# Copyright (c) 2022 by VMware, Inc. ("VMware")
+# Used Copyright (c) 2018 by Network Device Education Foundation,
+# Inc. ("NetDEF") in this file.
+#
+
+"""
+Following tests are covered to test multicast pim6 sm:
+
+Test steps
+- Create topology (setup module)
+- Bring up topology
+
+Following tests are covered:
+1. Verify (*,G) and (S,G) entry populated again after clear the
+PIM nbr and mroute from FRR node
+2. Verify SPT switchover working when RPT and SPT path is
+different
+"""
+
+import os
+import sys
+import json
+import time
+import datetime
+import pytest
+
+# Save the Current Working Directory to find configuration files.
+CWD = os.path.dirname(os.path.realpath(__file__))
+sys.path.append(os.path.join(CWD, "../"))
+sys.path.append(os.path.join(CWD, "../lib/"))
+
+# Required to instantiate the topology builder class.
+
+# pylint: disable=C0413
+# Import topogen and topotest helpers
+from lib.topogen import Topogen, get_topogen
+
+from lib.common_config import (
+ start_topology,
+ write_test_header,
+ write_test_footer,
+ step,
+ reset_config_on_routers,
+ shutdown_bringup_interface,
+ start_router,
+ stop_router,
+ create_static_routes,
+ required_linux_kernel_version,
+ socat_send_mld_join,
+ socat_send_pim6_traffic,
+ get_frr_ipv6_linklocal,
+ kill_socat,
+)
+from lib.bgp import create_router_bgp
+from lib.pim import (
+ create_pim_config,
+ create_mld_config,
+ verify_mld_groups,
+ verify_mroutes,
+ clear_pim6_interface_traffic,
+ verify_upstream_iif,
+ clear_pim6_mroute,
+ verify_pim_interface_traffic,
+ verify_pim_state,
+ McastTesterHelper,
+ verify_pim_join,
+ verify_mroute_summary,
+ verify_pim_nexthop,
+ verify_sg_traffic,
+ verify_mld_config,
+)
+
+from lib.topolog import logger
+from lib.topojson import build_config_from_json
+
+# Global variables
+GROUP_RANGE = "ff00::/8"
+
+GROUP_RANGE_1 = [
+ "ffaa::1/128",
+ "ffaa::2/128",
+ "ffaa::3/128",
+ "ffaa::4/128",
+ "ffaa::5/128",
+]
+MLD_JOIN_RANGE_1 = ["ffaa::1", "ffaa::2", "ffaa::3", "ffaa::4", "ffaa::5"]
+
+GROUP_RANGE_2 = [
+ "ffbb::1/128",
+ "ffbb::2/128",
+ "ffbb::3/128",
+ "ffbb::4/128",
+ "ffbb::5/128",
+]
+MLD_JOIN_RANGE_2 = ["ffbb::1", "ffbb::2", "ffbb::3", "ffbb::4", "ffbb::5"]
+GROUP_RANGE_3 = [
+ "ffcc::1/128",
+ "ffcc::2/128",
+ "ffcc::3/128",
+ "ffcc::4/128",
+ "ffcc::5/128",
+]
+MLD_JOIN_RANGE_3 = ["ffcc::1", "ffcc::2", "ffcc::3", "ffcc::4", "ffcc::5"]
+
+HELLO_TIMER = 1
+HOLD_TIMER = 3
+PREFERRED_NEXT_HOP = "link_local"
+ASSERT_MSG = "Testcase {} : Failed Error: {}"
+
+pytestmark = [pytest.mark.pim6d]
+
+
+def setup_module(mod):
+ """
+ Sets up the pytest environment
+
+ * `mod`: module name
+ """
+
+ # Required linux kernel version for this suite to run.
+ result = required_linux_kernel_version("4.19")
+ if result is not True:
+ pytest.skip("Kernel requirements are not met")
+
+ testsuite_run_time = time.asctime(time.localtime(time.time()))
+ logger.info("Testsuite start time: {}".format(testsuite_run_time))
+ logger.info("=" * 40)
+
+ logger.info("Running setup_module to create topology")
+
+ testdir = os.path.dirname(os.path.realpath(__file__))
+ json_file = "{}/multicast_pim6_sm_topo1.json".format(testdir)
+ tgen = Topogen(json_file, mod.__name__)
+ global topo
+ topo = tgen.json_topo
+ # ... and here it calls Mininet initialization functions.
+
+ # Starting topology, create tmp files which are loaded to routers
+ # to start deamons and then start routers
+ start_topology(tgen)
+
+ # Don"t run this test if we have any failure.
+ if tgen.routers_have_failure():
+ pytest.skip(tgen.errors)
+
+ # Creating configuration from JSON
+ build_config_from_json(tgen, tgen.json_topo)
+
+ logger.info("Running setup_module() done")
+
+
+def teardown_module():
+ """Teardown the pytest environment"""
+
+ logger.info("Running teardown_module to delete topology")
+
+ tgen = get_topogen()
+
+ # Clean up socat
+ kill_socat(tgen)
+
+ # Stop toplogy and Remove tmp files
+ tgen.stop_topology()
+
+ logger.info(
+ "Testsuite end time: {}".format(time.asctime(time.localtime(time.time())))
+ )
+ logger.info("=" * 40)
+
+
+#####################################################
+#
+# Local APIs
+#
+#####################################################
+
+
+def verify_state_incremented(state_before, state_after):
+ """
+ API to compare interface traffic state incrementing
+
+ Parameters
+ ----------
+ * `state_before` : State dictionary for any particular instance
+ * `state_after` : State dictionary for any particular instance
+ """
+
+ for router, state_data in state_before.items():
+ for state, value in state_data.items():
+ if state_before[router][state] >= state_after[router][state]:
+ errormsg = (
+ "[DUT: %s]: state %s value has not"
+ " incremented, Initial value: %s, "
+ "Current value: %s [FAILED!!]"
+ % (
+ router,
+ state,
+ state_before[router][state],
+ state_after[router][state],
+ )
+ )
+ return errormsg
+
+ logger.info(
+ "[DUT: %s]: State %s value is "
+ "incremented, Initial value: %s, Current value: %s"
+ " [PASSED!!]",
+ router,
+ state,
+ state_before[router][state],
+ state_after[router][state],
+ )
+
+ return True
+
+
+#####################################################
+#
+# Testcases
+#
+#####################################################
+
+
+def test_clear_mroute_and_verify_multicast_data_p0(request):
+ """
+ Verify (*,G) and (S,G) entry populated again after clear the
+ PIM nbr and mroute from FRR node
+ """
+ tgen = get_topogen()
+ tc_name = request.node.name
+ write_test_header(tc_name)
+
+ # Creating configuration from JSON
+ reset_config_on_routers(tgen)
+
+ # Don"t run this test if we have any failure.
+ if tgen.routers_have_failure():
+ pytest.skip(tgen.errors)
+
+ step("Configure static RP on r4 for group (ffcc::1-5)")
+ input_dict = {
+ "r4": {
+ "pim6": {
+ "rp": [
+ {
+ "rp_addr": topo["routers"]["r4"]["links"]["lo"]["ipv6"].split(
+ "/"
+ )[0],
+ "group_addr_range": GROUP_RANGE_1,
+ }
+ ]
+ }
+ }
+ }
+
+ result = create_pim_config(tgen, topo, input_dict)
+ assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
+
+ step(
+ "Enable mld on FRR1 interface and send mld join ffaa::1 "
+ "to ffaa::5 from different interfaces"
+ )
+
+ step("send mld join (ffaa::1-5) to R1")
+ intf = topo["routers"]["i1"]["links"]["r1"]["interface"]
+ intf_ip = topo["routers"]["i1"]["links"]["r1"]["ipv6"].split("/")[0]
+ result = socat_send_mld_join(
+ tgen, "i1", "UDP6-RECV", MLD_JOIN_RANGE_1, intf, intf_ip
+ )
+ assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result)
+
+ step("Send multicast traffic from FRR3 to all the receivers" "ffaa::1-5")
+
+ intf_ip = topo["routers"]["i2"]["links"]["r3"]["ipv6"].split("/")[0]
+ intf = topo["routers"]["i2"]["links"]["r3"]["interface"]
+ result = socat_send_pim6_traffic(tgen, "i2", "UDP6-SEND", MLD_JOIN_RANGE_1, intf)
+ assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result)
+
+ step("Clear the mroute on r1, wait for 5 sec")
+ result = clear_pim6_mroute(tgen, "r1")
+ assert result is True, "Testcase{}: Failed Error: {}".format(tc_name, result)
+
+ step(
+ "After clear ip mroute (*,g) entries are re-populated again"
+ " with same OIL and IIF, verify using 'show ipv6 mroute' and "
+ " 'show ipv6 pim upstream' "
+ )
+
+ source = topo["routers"]["i2"]["links"]["r3"]["ipv6"].split("/")[0]
+ input_dict = [
+ {
+ "dut": "r1",
+ "src_address": "*",
+ "iif": topo["routers"]["r1"]["links"]["r4"]["interface"],
+ "oil": topo["routers"]["r1"]["links"]["i1"]["interface"],
+ }
+ ]
+
+ for data in input_dict:
+ result = verify_mroutes(
+ tgen,
+ data["dut"],
+ data["src_address"],
+ MLD_JOIN_RANGE_1,
+ data["iif"],
+ data["oil"],
+ )
+ assert result is True, "Testcase{} : Failed Error: {}".format(tc_name, result)
+
+ step(
+ "Verify 'show ipv6 pim upstream' showing correct OIL and IIF"
+ " on all the nodes"
+ )
+ for data in input_dict:
+ result = verify_upstream_iif(
+ tgen, data["dut"], data["iif"], data["src_address"], MLD_JOIN_RANGE_1
+ )
+ assert result is True, "Testcase{} : Failed Error: {}".format(tc_name, result)
+
+ step("Clear the mroute on r3, wait for 5 sec")
+ result = clear_pim6_mroute(tgen, "r3")
+ assert result is True, "Testcase{}: Failed Error: {}".format(tc_name, result)
+
+ step(
+ "Verify 'show ipv6 mroute' showing correct RPF and OIF"
+ " interface for (*,G) and (S,G) entries on all the nodes"
+ )
+
+ input_dict = [
+ {
+ "dut": "r3",
+ "src_address": source,
+ "iif": topo["routers"]["r3"]["links"]["i2"]["interface"],
+ "oil": topo["routers"]["r3"]["links"]["r2"]["interface"],
+ }
+ ]
+
+ for data in input_dict:
+ result = verify_mroutes(
+ tgen,
+ data["dut"],
+ data["src_address"],
+ MLD_JOIN_RANGE_1,
+ data["iif"],
+ data["oil"],
+ )
+ assert result is True, "Testcase{} : Failed Error: {}".format(tc_name, result)
+
+ step(
+ "Verify 'show ipv6 pim upstream' showing correct OIL and IIF"
+ " on all the nodes"
+ )
+ for data in input_dict:
+ result = verify_upstream_iif(
+ tgen, data["dut"], data["iif"], data["src_address"], MLD_JOIN_RANGE_1
+ )
+ assert result is True, "Testcase{} : Failed Error: {}".format(tc_name, result)
+
+ step("Clear the mroute on r2, wait for 5 sec")
+ result = clear_pim6_mroute(tgen, "r2")
+ assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result)
+
+ step(
+ "Verify 'show ipv6 mroute' showing correct RPF and OIF"
+ " interface for (*,G) and (S,G) entries on all the nodes"
+ )
+
+ input_dict = [
+ {
+ "dut": "r2",
+ "src_address": source,
+ "iif": topo["routers"]["r2"]["links"]["r3"]["interface"],
+ "oil": topo["routers"]["r2"]["links"]["r1"]["interface"],
+ }
+ ]
+
+ for data in input_dict:
+ result = verify_mroutes(
+ tgen,
+ data["dut"],
+ data["src_address"],
+ MLD_JOIN_RANGE_1,
+ data["iif"],
+ data["oil"],
+ )
+ assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
+
+ step(
+ "Verify 'show ipv6 pim upstream' showing correct OIL and IIF"
+ " on all the nodes"
+ )
+ for data in input_dict:
+ result = verify_upstream_iif(
+ tgen, data["dut"], data["iif"], data["src_address"], MLD_JOIN_RANGE_1
+ )
+ assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
+
+ step("Clear the mroute on r1, r3, wait for 5 sec")
+ result = clear_pim6_mroute(tgen, "r1")
+ assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result)
+
+ result = clear_pim6_mroute(tgen, "r3")
+ assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result)
+
+ step(
+ "Verify 'show ipv6 mroute' showing correct RPF and OIF"
+ " interface for (*,G) and (S,G) entries on all the nodes"
+ )
+
+ input_dict = [
+ {
+ "dut": "r1",
+ "src_address": "*",
+ "iif": topo["routers"]["r1"]["links"]["r4"]["interface"],
+ "oil": topo["routers"]["r1"]["links"]["i1"]["interface"],
+ },
+ {
+ "dut": "r3",
+ "src_address": source,
+ "iif": topo["routers"]["r3"]["links"]["i2"]["interface"],
+ "oil": topo["routers"]["r3"]["links"]["r2"]["interface"],
+ },
+ ]
+
+ for data in input_dict:
+ result = verify_mroutes(
+ tgen,
+ data["dut"],
+ data["src_address"],
+ MLD_JOIN_RANGE_1,
+ data["iif"],
+ data["oil"],
+ )
+ assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
+
+ step(
+ "Verify 'show ipv6 pim upstream' showing correct OIL and IIF"
+ " on all the nodes"
+ )
+ for data in input_dict:
+ result = verify_upstream_iif(
+ tgen, data["dut"], data["iif"], data["src_address"], MLD_JOIN_RANGE_1
+ )
+ assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
+
+ step(
+ "multicast traffic is resume for all the receivers using "
+ " 'show ip multicast' "
+ )
+ result = verify_sg_traffic(tgen, "r1", MLD_JOIN_RANGE_1, source, "ipv6")
+ assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
+
+ write_test_footer(tc_name)
+
+
+def test_verify_SPT_switchover_when_RPT_and_SPT_path_is_different_p0(request):
+ """
+ Verify SPT switchover working when RPT and SPT path is
+ different
+ """
+
+ tgen = get_topogen()
+ tc_name = request.node.name
+ write_test_header(tc_name)
+
+ # Creating configuration from JSON
+ reset_config_on_routers(tgen)
+
+ # Don"t run this test if we have any failure.
+ if tgen.routers_have_failure():
+ pytest.skip(tgen.errors)
+
+ step("Configure static RP for (ffcc::1-5) and " "(ffbb::1-5) in r5")
+
+ _GROUP_RANGE = GROUP_RANGE_2 + GROUP_RANGE_3
+ _MLD_JOIN_RANGE = MLD_JOIN_RANGE_2 + MLD_JOIN_RANGE_3
+
+ input_dict = {
+ "r5": {
+ "pim6": {
+ "rp": [
+ {
+ "rp_addr": topo["routers"]["r5"]["links"]["lo"]["ipv6"].split(
+ "/"
+ )[0],
+ "group_addr_range": _GROUP_RANGE,
+ }
+ ]
+ }
+ }
+ }
+
+ result = create_pim_config(tgen, topo, input_dict)
+ assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
+
+ step("send mld join (ffbb::1-5, ffcc::1-5) to R1")
+ intf = topo["routers"]["i1"]["links"]["r1"]["interface"]
+ intf_ip = topo["routers"]["i1"]["links"]["r1"]["ipv6"].split("/")[0]
+ result = socat_send_mld_join(
+ tgen, "i1", "UDP6-RECV", _MLD_JOIN_RANGE, intf, intf_ip
+ )
+ assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result)
+
+ step("registerRx and registerStopTx value before traffic sent")
+ intf_r5 = topo["routers"]["r5"]["links"]["r3"]["interface"]
+ state_dict = {"r5": {intf_r5: ["registerRx", "registerStopTx"]}}
+ state_before = verify_pim_interface_traffic(tgen, state_dict, addr_type="ipv6")
+ assert isinstance(
+ state_before, dict
+ ), "Testcase {} : Failed \n state_before is not dictionary \n " "Error: {}".format(
+ tc_name, result
+ )
+
+ step(
+ "Send multicast traffic from FRR3 to all the receivers" "ffbb::1-5 , ffcc::1-5"
+ )
+ intf_ip = topo["routers"]["i2"]["links"]["r3"]["ipv6"].split("/")[0]
+ intf = topo["routers"]["i2"]["links"]["r3"]["interface"]
+ result = socat_send_pim6_traffic(tgen, "i2", "UDP6-SEND", _MLD_JOIN_RANGE, intf)
+ assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result)
+
+ step(
+ "Verify in FRR3 sending initial packet to RP using"
+ " 'show ipv6 mroute' and mroute OIL is towards RP."
+ )
+
+ source = topo["routers"]["i2"]["links"]["r3"]["ipv6"].split("/")[0]
+
+ r3_i2 = topo["routers"]["r3"]["links"]["i2"]["interface"]
+ r3_r5 = topo["routers"]["r3"]["links"]["r5"]["interface"]
+ r3_r2 = topo["routers"]["r3"]["links"]["r2"]["interface"]
+ r1_r2 = topo["routers"]["r1"]["links"]["r2"]["interface"]
+ r1_i1 = topo["routers"]["r1"]["links"]["i1"]["interface"]
+
+ result = verify_mroutes(tgen, "r3", source, _MLD_JOIN_RANGE, r3_i2, [r3_r5, r3_r2])
+ assert result is True, "Testcase {} : " "Failed Error: {}".format(tc_name, result)
+
+ result = verify_mroutes(tgen, "r3", source, _MLD_JOIN_RANGE, r3_i2, r3_r2)
+ assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
+
+ step(
+ " After spt switchover traffic is flowing between"
+ " (LHR(FRR1)-FHR(FRR3)) and (S,G) OIL is updated toward FRR1"
+ " 'show mroute' and 'show pim upstream'"
+ )
+
+ input_dict = [
+ {"dut": "r3", "src_address": source, "iif": r3_i2, "oil": r3_r2},
+ {"dut": "r1", "src_address": source, "iif": r1_r2, "oil": r1_i1},
+ ]
+ for data in input_dict:
+ result = verify_mroutes(
+ tgen,
+ data["dut"],
+ data["src_address"],
+ _MLD_JOIN_RANGE,
+ data["iif"],
+ data["oil"],
+ )
+ assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
+
+ for data in input_dict:
+ result = verify_upstream_iif(
+ tgen, data["dut"], data["iif"], data["src_address"], _MLD_JOIN_RANGE
+ )
+ assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
+
+ step("Stop the traffic to all the receivers")
+ dut = "i2"
+ intf = topo["routers"]["i2"]["links"]["r3"]["interface"]
+ shutdown_bringup_interface(tgen, dut, intf, False)
+
+ step(
+ "Null register packet being send periodically from FRR3 to RP, "
+ "verify using show ipv6 mroute on RP, have (S, G) entries null OIL"
+ " 'show ipv6 mroute' and verify show ip pim interface traffic"
+ "(In RP Register msg should be received and Register stop should"
+ " be transmitted)"
+ )
+
+ result = verify_upstream_iif(
+ tgen, "r3", "Unknown", source, _MLD_JOIN_RANGE, joinState="NotJoined"
+ )
+ assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
+
+ step("registerRx and registerStopTx value after traffic sent")
+ state_after = verify_pim_interface_traffic(tgen, state_dict, addr_type="ipv6")
+ assert isinstance(
+ state_after, dict
+ ), "Testcase {} : Failed \n state_before is not dictionary \n " "Error: {}".format(
+ tc_name, result
+ )
+
+ result = verify_state_incremented(state_before, state_after)
+ assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
+
+ write_test_footer(tc_name)
+
+
+if __name__ == "__main__":
+ args = ["-s"] + sys.argv[1:]
+ sys.exit(pytest.main(args))
diff --git a/tests/topotests/multicast_pim6_static_rp_topo1/test_multicast_pim6_static_rp1.py b/tests/topotests/multicast_pim6_static_rp_topo1/test_multicast_pim6_static_rp1.py
index 95b4004e14..977cd477c8 100755
--- a/tests/topotests/multicast_pim6_static_rp_topo1/test_multicast_pim6_static_rp1.py
+++ b/tests/topotests/multicast_pim6_static_rp_topo1/test_multicast_pim6_static_rp1.py
@@ -172,6 +172,9 @@ def teardown_module():
logger.info("Running teardown_module to delete topology")
tgen = get_topogen()
+ # Clean up socat
+ kill_socat(tgen)
+
# Stop toplogy and Remove tmp files
tgen.stop_topology()
diff --git a/tests/topotests/multicast_pim6_static_rp_topo1/test_multicast_pim6_static_rp2.py b/tests/topotests/multicast_pim6_static_rp_topo1/test_multicast_pim6_static_rp2.py
index 2fedb6e517..a61164baa2 100755
--- a/tests/topotests/multicast_pim6_static_rp_topo1/test_multicast_pim6_static_rp2.py
+++ b/tests/topotests/multicast_pim6_static_rp_topo1/test_multicast_pim6_static_rp2.py
@@ -176,6 +176,9 @@ def teardown_module():
logger.info("Running teardown_module to delete topology")
tgen = get_topogen()
+ # Clean up socat
+ kill_socat(tgen)
+
# Stop toplogy and Remove tmp files
tgen.stop_topology()
diff --git a/tests/topotests/ospf6_ecmp_inter_area/r1/ospf6d.conf b/tests/topotests/ospf6_ecmp_inter_area/r1/ospf6d.conf
index 6c7cb96240..e6e5733010 100644
--- a/tests/topotests/ospf6_ecmp_inter_area/r1/ospf6d.conf
+++ b/tests/topotests/ospf6_ecmp_inter_area/r1/ospf6d.conf
@@ -1,35 +1,35 @@
-debug ospf6 lsa all
-debug ospf6 message all
-debug ospf6 route all
-debug ospf6 spf time
-debug ospf6 spf database
-debug ospf6 zebra send
-debug ospf6 zebra recv
-
-debug ospf6 lsa router
-debug ospf6 lsa router originate
-debug ospf6 lsa router examine
-debug ospf6 lsa router flooding
-debug ospf6 lsa as-external
-debug ospf6 lsa as-external originate
-debug ospf6 lsa as-external examine
-debug ospf6 lsa as-external flooding
-debug ospf6 lsa intra-prefix
-debug ospf6 lsa intra-prefix originate
-debug ospf6 lsa intra-prefix examine
-debug ospf6 lsa intra-prefix flooding
-debug ospf6 border-routers
-debug ospf6 zebra
-debug ospf6 interface
-debug ospf6 neighbor
-debug ospf6 flooding
-debug ospf6 gr helper
-debug ospf6 spf process
-debug ospf6 route intra-area
-debug ospf6 route inter-area
-debug ospf6 abr
-debug ospf6 asbr
-debug ospf6 nssa
+!debug ospf6 lsa all
+!debug ospf6 message all
+!debug ospf6 route all
+!debug ospf6 spf time
+!debug ospf6 spf database
+!debug ospf6 zebra send
+!debug ospf6 zebra recv
+!
+!debug ospf6 lsa router
+!debug ospf6 lsa router originate
+!debug ospf6 lsa router examine
+!debug ospf6 lsa router flooding
+!debug ospf6 lsa as-external
+!debug ospf6 lsa as-external originate
+!debug ospf6 lsa as-external examine
+!debug ospf6 lsa as-external flooding
+!debug ospf6 lsa intra-prefix
+!debug ospf6 lsa intra-prefix originate
+!debug ospf6 lsa intra-prefix examine
+!debug ospf6 lsa intra-prefix flooding
+!debug ospf6 border-routers
+!debug ospf6 zebra
+!debug ospf6 interface
+!debug ospf6 neighbor
+!debug ospf6 flooding
+!debug ospf6 gr helper
+!debug ospf6 spf process
+!debug ospf6 route intra-area
+!debug ospf6 route inter-area
+!debug ospf6 abr
+!debug ospf6 asbr
+!debug ospf6 nssa
!
interface r1-eth0
ipv6 ospf6 area 0
diff --git a/tests/topotests/ospf6_topo2/test_ospf6_topo2.py b/tests/topotests/ospf6_topo2/test_ospf6_topo2.py
index 9ec0266aa0..f95f7bbe5e 100644
--- a/tests/topotests/ospf6_topo2/test_ospf6_topo2.py
+++ b/tests/topotests/ospf6_topo2/test_ospf6_topo2.py
@@ -129,6 +129,7 @@ def setup_module(mod):
router_list = tgen.routers()
for rname, router in router_list.items():
+
daemon_file = "{}/{}/zebra.conf".format(CWD, rname)
if os.path.isfile(daemon_file):
router.load_config(TopoRouter.RD_ZEBRA, daemon_file)
diff --git a/tests/topotests/ospf_basic_functionality/test_ospf_asbr_summary_topo1.py b/tests/topotests/ospf_basic_functionality/test_ospf_asbr_summary_topo1.py
index 3d15e94a51..9d7a15833c 100644
--- a/tests/topotests/ospf_basic_functionality/test_ospf_asbr_summary_topo1.py
+++ b/tests/topotests/ospf_basic_functionality/test_ospf_asbr_summary_topo1.py
@@ -140,7 +140,7 @@ def setup_module(mod):
pytest.skip(tgen.errors)
# Api call verify whether OSPF is converged
ospf_covergence = verify_ospf_neighbor(tgen, topo)
- assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
+ assert ospf_covergence is True, "setup_module :Failed \n Error {}".format(
ospf_covergence
)
@@ -260,11 +260,9 @@ def test_ospf_type5_summary_tc43_p0(request):
result = verify_rib(tgen, "ipv4", dut, input_dict_static_rtes, protocol=protocol)
assert (
result is True
- ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed. Error: Routes is missing in RIB".format(tc_name)
- step(
- "Configure External Route summary in R0 to summarise 5" " routes to one route."
- )
+ step("Configure External Route summary in R0 to summarise 5 routes to one route.")
ospf_summ_r1 = {
"r0": {
"ospf": {
@@ -290,7 +288,7 @@ def test_ospf_type5_summary_tc43_p0(request):
result = verify_rib(tgen, "ipv4", dut, input_dict_summary, protocol=protocol)
assert (
result is True
- ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed. Error: Routes is missing in RIB".format(tc_name)
step("Verify that show ip ospf summary should show the summaries.")
input_dict = {
@@ -306,7 +304,7 @@ def test_ospf_type5_summary_tc43_p0(request):
result = verify_ospf_summary(tgen, topo, dut, input_dict)
assert (
result is True
- ), "Testcase {} : Failed" "Error: Summary missing in OSPF DB".format(tc_name)
+ ), "Testcase {} : Failed. Error: Summary missing in OSPF DB".format(tc_name)
step("Change the summary address mask to lower match (ex - 16 to 8)")
ospf_summ_r1 = {
@@ -334,7 +332,7 @@ def test_ospf_type5_summary_tc43_p0(request):
result = verify_ospf_summary(tgen, topo, dut, input_dict)
assert (
result is True
- ), "Testcase {} : Failed" "Error: Summary missing in OSPF DB".format(tc_name)
+ ), "Testcase {} : Failed. Error: Summary missing in OSPF DB".format(tc_name)
step(
"Verify that external routes(static / connected) are summarised"
@@ -350,7 +348,7 @@ def test_ospf_type5_summary_tc43_p0(request):
result = verify_rib(tgen, "ipv4", dut, input_dict_summary, protocol=protocol)
assert (
result is True
- ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed. Error: Routes is missing in RIB".format(tc_name)
step("Change the summary address mask to higher match (ex - 8 to 24)")
ospf_summ_r1 = {
@@ -378,7 +376,7 @@ def test_ospf_type5_summary_tc43_p0(request):
result = verify_ospf_summary(tgen, topo, dut, input_dict)
assert (
result is True
- ), "Testcase {} : Failed" "Error: Summary missing in OSPF DB".format(tc_name)
+ ), "Testcase {} : Failed. Error: Summary missing in OSPF DB".format(tc_name)
step(
"Verify that external routes(static / connected) are summarised"
@@ -399,7 +397,7 @@ def test_ospf_type5_summary_tc43_p0(request):
result = verify_rib(tgen, "ipv4", dut, input_dict_summary, protocol=protocol)
assert (
result is True
- ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed. Error: Routes is missing in RIB".format(tc_name)
step(" Un configure one of the summary address.")
ospf_summ_r1 = {
@@ -432,7 +430,7 @@ def test_ospf_type5_summary_tc43_p0(request):
result = verify_rib(tgen, "ipv4", dut, input_dict_summary, protocol=protocol)
assert (
result is True
- ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed. Error: Routes is missing in RIB".format(tc_name)
ospf_summ_r1 = {
"r0": {
@@ -459,7 +457,7 @@ def test_ospf_type5_summary_tc43_p0(request):
result = verify_rib(tgen, "ipv4", dut, input_dict_summary, protocol=protocol)
assert (
result is True
- ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed. Error: Routes is missing in RIB".format(tc_name)
write_test_footer(tc_name)
@@ -506,11 +504,9 @@ def test_ospf_type5_summary_tc48_p0(request):
result = verify_rib(tgen, "ipv4", dut, input_dict_static_rtes, protocol=protocol)
assert (
result is True
- ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed. Error: Routes is missing in RIB".format(tc_name)
- step(
- "Configure External Route summary in R0 to summarise 5" " routes to one route."
- )
+ step("Configure External Route summary in R0 to summarise 5 routes to one route.")
ospf_summ_r1 = {
"r0": {
@@ -538,7 +534,7 @@ def test_ospf_type5_summary_tc48_p0(request):
result = verify_rib(tgen, "ipv4", dut, input_dict_summary, protocol=protocol)
assert (
result is True
- ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed. Error: Routes is missing in RIB".format(tc_name)
step("Verify that show ip ospf summary should show the summaries.")
input_dict = {
@@ -554,26 +550,26 @@ def test_ospf_type5_summary_tc48_p0(request):
result = verify_ospf_summary(tgen, topo, dut, input_dict)
assert (
result is True
- ), "Testcase {} : Failed" "Error: Summary missing in OSPF DB".format(tc_name)
+ ), "Testcase {} : Failed. Error: Summary missing in OSPF DB".format(tc_name)
- step("Verify that originally advertised routes are withdraw from there" " peer.")
+ step("Verify that originally advertised routes are withdraw from there peer.")
input_dict = {
"r0": {"static_routes": [{"network": NETWORK["ipv4"], "next_hop": "blackhole"}]}
}
dut = "r1"
result = verify_ospf_rib(tgen, dut, input_dict, expected=False)
- assert (
- result is not True
- ), "Testcase {} : Failed \n Error: " "Routes still present in OSPF RIB {}".format(
- tc_name, result
+ assert result is not True, (
+ "Testcase {} : Failed\n Expected: Routes should not be present in OSPF RIB \n Error: "
+ "Routes still present in OSPF RIB {}".format(tc_name, result)
)
result = verify_rib(
tgen, "ipv4", dut, input_dict, protocol=protocol, expected=False
)
- assert (
- result is not True
- ), "Testcase {} : Failed" "Error: Routes still present in RIB".format(tc_name)
+ assert result is not True, (
+ "Testcase {} : Failed \n Expected: Routes should not be present in RIB\n"
+ "Error: Routes still present in RIB".format(tc_name)
+ )
step(
"Configure route map and & rule to permit configured summary address,"
@@ -635,7 +631,7 @@ def test_ospf_type5_summary_tc48_p0(request):
result = verify_rib(tgen, "ipv4", dut, input_dict_summary, protocol=protocol)
assert (
result is True
- ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed. Error: Routes is missing in RIB".format(tc_name)
input_dict = {
SUMMARY["ipv4"][0]: {
@@ -650,7 +646,7 @@ def test_ospf_type5_summary_tc48_p0(request):
result = verify_ospf_summary(tgen, topo, dut, input_dict)
assert (
result is True
- ), "Testcase {} : Failed" "Error: Summary missing in OSPF DB".format(tc_name)
+ ), "Testcase {} : Failed. Error: Summary missing in OSPF DB".format(tc_name)
write_test_footer(tc_name)
@@ -697,7 +693,7 @@ def test_ospf_type5_summary_tc42_p0(request):
result = verify_rib(tgen, "ipv4", dut, input_dict_static_rtes, protocol=protocol)
assert (
result is True
- ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed. Error: Routes is missing in RIB".format(tc_name)
step(
"Configure External Route summary in R0 to summarise 5"
@@ -731,7 +727,7 @@ def test_ospf_type5_summary_tc42_p0(request):
result = verify_rib(tgen, "ipv4", dut, input_dict_summary, protocol=protocol)
assert (
result is True
- ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed. Error: Routes is missing in RIB".format(tc_name)
step("Verify that show ip ospf summary should show the summaries.")
input_dict = {
@@ -747,26 +743,26 @@ def test_ospf_type5_summary_tc42_p0(request):
result = verify_ospf_summary(tgen, topo, dut, input_dict)
assert (
result is True
- ), "Testcase {} : Failed" "Error: Summary missing in OSPF DB".format(tc_name)
+ ), "Testcase {} : Failed. Error: Summary missing in OSPF DB".format(tc_name)
- step("Verify that originally advertised routes are withdraw from there" " peer.")
+ step("Verify that originally advertised routes are withdraw from there peer.")
input_dict = {
"r0": {"static_routes": [{"network": NETWORK["ipv4"], "next_hop": "blackhole"}]}
}
dut = "r1"
result = verify_ospf_rib(tgen, dut, input_dict, expected=False)
- assert (
- result is not True
- ), "Testcase {} : Failed \n Error: " "Routes still present in OSPF RIB {}".format(
- tc_name, result
+ assert result is not True, (
+ "Testcase {} : Failed \n Expected: Routes should not be present in OSPF RIB \n Error: "
+ "Routes still present in OSPF RIB {}".format(tc_name, result)
)
result = verify_rib(
tgen, "ipv4", dut, input_dict, protocol=protocol, expected=False
)
- assert (
- result is not True
- ), "Testcase {} : Failed" "Error: Routes still present in RIB".format(tc_name)
+ assert result is not True, (
+ "Testcase {} : Failed \n Expected: Routes should not be present in RIB"
+ "Error: Routes still present in RIB".format(tc_name)
+ )
step("Delete the configured summary")
ospf_summ_r1 = {
@@ -789,19 +785,17 @@ def test_ospf_type5_summary_tc42_p0(request):
step("Verify that summary lsa is withdrawn from R1 and deleted from R0.")
dut = "r1"
result = verify_ospf_rib(tgen, dut, input_dict, expected=False)
- assert (
- result is not True
- ), "Testcase {} : Failed \n Error: " "Routes still present in OSPF RIB {}".format(
- tc_name, result
+ assert result is not True, (
+ "Testcase {} : Failed \n Expected: Routes should not be present in OSPF RIB \n Error: "
+ "Routes still present in OSPF RIB {}".format(tc_name, result)
)
result = verify_rib(
tgen, "ipv4", dut, input_dict_summary, protocol=protocol, expected=False
)
- assert (
- result is not True
- ), "Testcase {} : Failed" "Error: Summary Route still present in RIB".format(
- tc_name
+ assert result is not True, (
+ "Testcase {} : Failed \n Expected: Summary Route should not present in RIB"
+ "Error: Summary Route still present in RIB".format(tc_name)
)
step("show ip ospf summary should not have any summary address.")
@@ -816,9 +810,10 @@ def test_ospf_type5_summary_tc42_p0(request):
}
dut = "r0"
result = verify_ospf_summary(tgen, topo, dut, input_dict, expected=False)
- assert (
- result is not True
- ), "Testcase {} : Failed" "Error: Summary still present in DB".format(tc_name)
+ assert result is not True, (
+ "Testcase {} : Failed \n Expected: Summary Route should not present in OSPF DB"
+ "Error: Summary still present in DB".format(tc_name)
+ )
dut = "r1"
step("All 5 routes are advertised after deletion of configured summary.")
@@ -829,7 +824,7 @@ def test_ospf_type5_summary_tc42_p0(request):
result = verify_rib(tgen, "ipv4", dut, input_dict_static_rtes, protocol=protocol)
assert (
result is True
- ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed. Error: Routes is missing in RIB".format(tc_name)
step("configure the summary again and delete static routes .")
ospf_summ_r1 = {
@@ -857,7 +852,7 @@ def test_ospf_type5_summary_tc42_p0(request):
result = verify_ospf_summary(tgen, topo, dut, input_dict)
assert (
result is True
- ), "Testcase {} : Failed" "Error: Summary missing in OSPF DB".format(tc_name)
+ ), "Testcase {} : Failed. Error: Summary missing in OSPF DB".format(tc_name)
input_dict = {
"r0": {
@@ -874,18 +869,18 @@ def test_ospf_type5_summary_tc42_p0(request):
dut = "r1"
result = verify_ospf_rib(tgen, dut, input_dict_summary, expected=False)
- assert (
- result is not True
- ), "Testcase {} : Failed \n Error: " "Routes still present in OSPF RIB {}".format(
- tc_name, result
+ assert result is not True, (
+ "Testcase {} : Failed \n Expected: Routes should not be present in OSPF RIB \n Error: "
+ "Routes still present in OSPF RIB {}".format(tc_name, result)
)
result = verify_rib(
tgen, "ipv4", dut, input_dict_summary, protocol=protocol, expected=False
)
- assert (
- result is not True
- ), "Testcase {} : Failed" "Error: Routes still present in RIB".format(tc_name)
+ assert result is not True, (
+ "Testcase {} : Failed \n Expected: Routes should not be present in RIB\n"
+ "Error: Routes still present in RIB".format(tc_name)
+ )
step("Add back static routes.")
input_dict_static_rtes = {
@@ -901,18 +896,18 @@ def test_ospf_type5_summary_tc42_p0(request):
dut = "r1"
result = verify_ospf_rib(tgen, dut, input_dict_static_rtes, expected=False)
- assert (
- result is not True
- ), "Testcase {} : Failed \n Error: " "Routes still present in OSPF RIB {}".format(
- tc_name, result
+ assert result is not True, (
+ "Testcase {} : Failed \n Expected: Routes should not be present in OSPF RIB \n Error: "
+ "Routes still present in OSPF RIB {}".format(tc_name, result)
)
result = verify_rib(
tgen, "ipv4", dut, input_dict_static_rtes, protocol=protocol, expected=False
)
- assert (
- result is not True
- ), "Testcase {} : Failed" "Error: Routes still present in RIB".format(tc_name)
+ assert result is not True, (
+ "Testcase {} : Failed \n Expected: Routes should not be present in RIB"
+ "Error: Routes still present in RIB".format(tc_name)
+ )
input_dict_summary = {"r0": {"static_routes": [{"network": SUMMARY["ipv4"][0]}]}}
dut = "r1"
@@ -923,7 +918,7 @@ def test_ospf_type5_summary_tc42_p0(request):
result = verify_rib(tgen, "ipv4", dut, input_dict_summary, protocol=protocol)
assert (
result is True
- ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed. Error: Routes is missing in RIB".format(tc_name)
step("Verify that show ip ospf summary should show configure summaries.")
@@ -940,7 +935,7 @@ def test_ospf_type5_summary_tc42_p0(request):
result = verify_ospf_summary(tgen, topo, dut, input_dict)
assert (
result is True
- ), "Testcase {} : Failed" "Error: Summary missing in OSPF DB".format(tc_name)
+ ), "Testcase {} : Failed. Error: Summary missing in OSPF DB".format(tc_name)
step("Configure new static route which is matching configured summary.")
input_dict_static_rtes = {
@@ -1004,7 +999,7 @@ def test_ospf_type5_summary_tc42_p0(request):
result = verify_rib(tgen, "ipv4", dut, input_dict_summary, protocol=protocol)
assert (
result is True
- ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed. Error: Routes is missing in RIB".format(tc_name)
step("Shut one of the interface")
intf = topo["routers"]["r0"]["links"]["r3-link0"]["interface"]
@@ -1076,7 +1071,7 @@ def test_ospf_type5_summary_tc42_p0(request):
result = verify_ospf_summary(tgen, topo, dut, input_dict)
assert (
result is True
- ), "Testcase {} : Failed" "Error: Summary missing in OSPF DB".format(tc_name)
+ ), "Testcase {} : Failed. Error: Summary missing in OSPF DB".format(tc_name)
input_dict_summary = {"r0": {"static_routes": [{"network": SUMMARY["ipv4"][0]}]}}
@@ -1087,7 +1082,7 @@ def test_ospf_type5_summary_tc42_p0(request):
result = verify_rib(tgen, "ipv4", dut, input_dict_summary, protocol=protocol)
assert (
result is True
- ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed. Error: Routes is missing in RIB".format(tc_name)
ospf_summ_r1 = {
"r0": {
@@ -1113,18 +1108,18 @@ def test_ospf_type5_summary_tc42_p0(request):
dut = "r1"
result = verify_ospf_rib(tgen, dut, input_dict_summary, expected=False)
- assert (
- result is not True
- ), "Testcase {} : Failed \n Error: " "Routes still present in OSPF RIB {}".format(
- tc_name, result
+ assert result is not True, (
+ "Testcase {} : Failed \n Expected: Routes should not be present in OSPF RIB. \n Error: "
+ "Routes still present in OSPF RIB {}".format(tc_name, result)
)
result = verify_rib(
tgen, "ipv4", dut, input_dict_summary, protocol=protocol, expected=False
)
- assert (
- result is not True
- ), "Testcase {} : Failed" "Error: Routes still present in RIB".format(tc_name)
+ assert result is not True, (
+ "Testcase {} : Failed \n Expected: Routes should not be present in RIB"
+ "Error: Routes still present in RIB".format(tc_name)
+ )
ospf_summ_r1 = {
"r0": {
@@ -1188,11 +1183,9 @@ def test_ospf_type5_summary_tc45_p0(request):
result = verify_rib(tgen, "ipv4", dut, input_dict_static_rtes, protocol=protocol)
assert (
result is True
- ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed. Error: Routes is missing in RIB".format(tc_name)
- step(
- "Configure External Route summary in R0 to summarise 5" " routes to one route."
- )
+ step("Configure External Route summary in R0 to summarise 5 routes to one route.")
ospf_summ_r1 = {
"r0": {
"ospf": {
@@ -1224,7 +1217,7 @@ def test_ospf_type5_summary_tc45_p0(request):
result = verify_rib(tgen, "ipv4", dut, input_dict_summary, protocol=protocol)
assert (
result is True
- ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed. Error: Routes is missing in RIB".format(tc_name)
step("Verify that show ip ospf summary should show the summaries with tag.")
input_dict = {
@@ -1240,7 +1233,7 @@ def test_ospf_type5_summary_tc45_p0(request):
result = verify_ospf_summary(tgen, topo, dut, input_dict)
assert (
result is True
- ), "Testcase {} : Failed" "Error: Summary missing in OSPF DB".format(tc_name)
+ ), "Testcase {} : Failed. Error: Summary missing in OSPF DB".format(tc_name)
step("Delete the configured summary")
ospf_summ_r1 = {
@@ -1263,19 +1256,17 @@ def test_ospf_type5_summary_tc45_p0(request):
step("Verify that summary lsa is withdrawn from R1 and deleted from R0.")
dut = "r1"
result = verify_ospf_rib(tgen, dut, input_dict_summary, expected=False)
- assert (
- result is not True
- ), "Testcase {} : Failed \n Error: " "Routes still present in OSPF RIB {}".format(
- tc_name, result
+ assert result is not True, (
+ "Testcase {} : Failed \n Expected: Routes should not be present in OSPF RIB \n Error: "
+ "Routes still present in OSPF RIB {}".format(tc_name, result)
)
result = verify_rib(
tgen, "ipv4", dut, input_dict_summary, protocol=protocol, expected=False
)
- assert (
- result is not True
- ), "Testcase {} : Failed" "Error: Summary Route still present in RIB".format(
- tc_name
+ assert result is not True, (
+ "Testcase {} : Failed \n Expected: Summary Routes should not be present in RIB. \n"
+ "Error: Summary Route still present in RIB".format(tc_name)
)
step("show ip ospf summary should not have any summary address.")
@@ -1292,7 +1283,7 @@ def test_ospf_type5_summary_tc45_p0(request):
result = verify_ospf_summary(tgen, topo, dut, input_dict, expected=False)
assert (
result is not True
- ), "Testcase {} : Failed" "Error: Summary still present in DB".format(tc_name)
+ ), "Testcase {} : Failed. Error: Summary still present in DB".format(tc_name)
step("Configure Min tag value")
ospf_summ_r1 = {
@@ -1317,7 +1308,7 @@ def test_ospf_type5_summary_tc45_p0(request):
result = verify_rib(tgen, "ipv4", dut, input_dict_summary, protocol=protocol)
assert (
result is True
- ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed. Error: Routes is missing in RIB".format(tc_name)
step("Verify that show ip ospf summary should show the summaries with tag.")
input_dict = {
@@ -1333,7 +1324,7 @@ def test_ospf_type5_summary_tc45_p0(request):
result = verify_ospf_summary(tgen, topo, dut, input_dict)
assert (
result is True
- ), "Testcase {} : Failed" "Error: Summary missing in OSPF DB".format(tc_name)
+ ), "Testcase {} : Failed. Error: Summary missing in OSPF DB".format(tc_name)
step("Configure Max Tag Value")
ospf_summ_r1 = {
@@ -1363,7 +1354,7 @@ def test_ospf_type5_summary_tc45_p0(request):
result = verify_rib(tgen, "ipv4", dut, input_dict_summary, protocol=protocol)
assert (
result is True
- ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed. Error: Routes is missing in RIB".format(tc_name)
step(
"Verify that boundary values tags are used for summary route"
@@ -1382,7 +1373,7 @@ def test_ospf_type5_summary_tc45_p0(request):
result = verify_ospf_summary(tgen, topo, dut, input_dict)
assert (
result is True
- ), "Testcase {} : Failed" "Error: Summary missing in OSPF DB".format(tc_name)
+ ), "Testcase {} : Failed. Error: Summary missing in OSPF DB".format(tc_name)
step("configure new static route with different tag.")
input_dict_static_rtes_11 = {
@@ -1403,10 +1394,9 @@ def test_ospf_type5_summary_tc45_p0(request):
dut = "r1"
result = verify_ospf_rib(tgen, dut, input_dict_summary, tag="88888", expected=False)
- assert (
- result is not True
- ), "Testcase {} : Failed \n Error: " "Routes still present in OSPF RIB {}".format(
- tc_name, result
+ assert result is not True, (
+ "Testcase {} : Failed \n Expected: Routes should not be present in OSPF RIB \n Error: "
+ "Routes still present in OSPF RIB {}".format(tc_name, result)
)
result = verify_rib(
@@ -1418,9 +1408,10 @@ def test_ospf_type5_summary_tc45_p0(request):
tag="88888",
expected=False,
)
- assert (
- result is not True
- ), "Testcase {} : Failed" "Error: Routes still present in RIB".format(tc_name)
+ assert result is not True, (
+ "Testcase {} : Failed \n Expected: Routes should not be present in RIB\n"
+ "Error: Routes still present in RIB".format(tc_name)
+ )
step(
"Verify that boundary values tags are used for summary route"
@@ -1439,7 +1430,7 @@ def test_ospf_type5_summary_tc45_p0(request):
result = verify_ospf_summary(tgen, topo, dut, input_dict, expected=False)
assert (
result is not True
- ), "Testcase {} : Failed" "Error: Summary missing in OSPF DB".format(tc_name)
+ ), "Testcase {} : Failed. Error: Summary missing in OSPF DB".format(tc_name)
step("Delete the configured summary address")
ospf_summ_r1 = {
@@ -1470,24 +1461,24 @@ def test_ospf_type5_summary_tc45_p0(request):
result = verify_rib(tgen, "ipv4", dut, input_dict_static_rtes, protocol=protocol)
assert (
result is True
- ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed. Error: Routes is missing in RIB".format(tc_name)
step("Verify that summary address is flushed from neighbor.")
dut = "r1"
result = verify_ospf_rib(tgen, dut, input_dict_summary, expected=False)
- assert (
- result is not True
- ), "Testcase {} : Failed \n Error: " "Routes still present in OSPF RIB {}".format(
- tc_name, result
+ assert result is not True, (
+ "Testcase {} : Failed \n Expected: Routes should not be present in OSPF RIB \n Error: "
+ "Routes still present in OSPF RIB {}".format(tc_name, result)
)
result = verify_rib(
tgen, "ipv4", dut, input_dict_summary, protocol=protocol, expected=False
)
- assert (
- result is not True
- ), "Testcase {} : Failed" "Error: Routes still present in RIB".format(tc_name)
+ assert result is not True, (
+ "Testcase {} : Failed \n Expected: Routes should not be present in RIB\n"
+ "Error: Routes still present in RIB".format(tc_name)
+ )
step("Configure summary first & then configure matching static route.")
@@ -1589,7 +1580,7 @@ def test_ospf_type5_summary_tc45_p0(request):
assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
ospf_covergence = verify_ospf_neighbor(tgen, topo)
- assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
+ assert ospf_covergence is True, "setup_module :Failed \n Error {}".format(
ospf_covergence
)
@@ -1619,11 +1610,9 @@ def test_ospf_type5_summary_tc45_p0(request):
result = verify_rib(tgen, "ipv4", dut, input_dict_static_rtes, protocol=protocol)
assert (
result is True
- ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed. Error: Routes is missing in RIB".format(tc_name)
- step(
- "Configure External Route summary in R0 to summarise 5" " routes to one route."
- )
+ step("Configure External Route summary in R0 to summarise 5 routes to one route.")
ospf_summ_r1 = {
"r0": {
"ospf": {
@@ -1655,7 +1644,7 @@ def test_ospf_type5_summary_tc45_p0(request):
result = verify_rib(tgen, "ipv4", dut, input_dict_summary, protocol=protocol)
assert (
result is True
- ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed. Error: Routes is missing in RIB".format(tc_name)
step("Verify that show ip ospf summary should show the summaries with tag.")
input_dict = {
@@ -1691,19 +1680,17 @@ def test_ospf_type5_summary_tc45_p0(request):
step("Verify that summary lsa is withdrawn from R1 and deleted from R0.")
dut = "r1"
result = verify_ospf_rib(tgen, dut, input_dict, expected=False)
- assert (
- result is not True
- ), "Testcase {} : Failed \n Error: " "Routes still present in OSPF RIB {}".format(
- tc_name, result
+ assert result is not True, (
+ "Testcase {} : Failed \n Expected: Routes should not be present in OSPF RIB \n Error: "
+ "Routes still present in OSPF RIB {}".format(tc_name, result)
)
result = verify_rib(
tgen, "ipv4", dut, input_dict_summary, protocol=protocol, expected=False
)
- assert (
- result is not True
- ), "Testcase {} : Failed" "Error: Summary Route still present in RIB".format(
- tc_name
+ assert result is not True, (
+ "Testcase {} : Failed \n Expected: Routes should not be present in RIB "
+ "Error: Summary Route still present in RIB".format(tc_name)
)
step("show ip ospf summary should not have any summary address.")
@@ -1720,7 +1707,7 @@ def test_ospf_type5_summary_tc45_p0(request):
result = verify_ospf_summary(tgen, topo, dut, input_dict, expected=False)
assert (
result is not True
- ), "Testcase {} : Failed" "Error: Summary still present in DB".format(tc_name)
+ ), "Testcase {} : Failed. Error: Summary still present in DB".format(tc_name)
step("Configure Min tag value")
ospf_summ_r1 = {
@@ -1745,7 +1732,7 @@ def test_ospf_type5_summary_tc45_p0(request):
result = verify_rib(tgen, "ipv4", dut, input_dict_summary, protocol=protocol)
assert (
result is True
- ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed. Error: Routes is missing in RIB".format(tc_name)
step("Verify that show ip ospf summary should show the summaries with tag.")
input_dict = {
@@ -1761,7 +1748,7 @@ def test_ospf_type5_summary_tc45_p0(request):
result = verify_ospf_summary(tgen, topo, dut, input_dict)
assert (
result is True
- ), "Testcase {} : Failed" "Error: Summary missing in OSPF DB".format(tc_name)
+ ), "Testcase {} : Failed. Error: Summary missing in OSPF DB".format(tc_name)
step("Configure Max Tag Value")
ospf_summ_r1 = {
@@ -1791,7 +1778,7 @@ def test_ospf_type5_summary_tc45_p0(request):
result = verify_rib(tgen, "ipv4", dut, input_dict_summary, protocol=protocol)
assert (
result is True
- ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed. Error: Routes is missing in RIB".format(tc_name)
step(
"Verify that boundary values tags are used for summary route"
@@ -1810,7 +1797,7 @@ def test_ospf_type5_summary_tc45_p0(request):
result = verify_ospf_summary(tgen, topo, dut, input_dict)
assert (
result is True
- ), "Testcase {} : Failed" "Error: Summary missing in OSPF DB".format(tc_name)
+ ), "Testcase {} : Failed. Error: Summary missing in OSPF DB".format(tc_name)
step("configure new static route with different tag.")
input_dict_static_rtes_11 = {
@@ -1831,10 +1818,9 @@ def test_ospf_type5_summary_tc45_p0(request):
dut = "r1"
result = verify_ospf_rib(tgen, dut, input_dict_summary, tag="88888", expected=False)
- assert (
- result is not True
- ), "Testcase {} : Failed \n Error: " "Routes still present in OSPF RIB {}".format(
- tc_name, result
+ assert result is not True, (
+ "Testcase {} : Failed \n Expected: Routes should not be present in OSPF RIB \n Error: "
+ "Routes still present in OSPF RIB {}".format(tc_name, result)
)
result = verify_rib(
@@ -1846,9 +1832,10 @@ def test_ospf_type5_summary_tc45_p0(request):
tag="88888",
expected=False,
)
- assert (
- result is not True
- ), "Testcase {} : Failed" "Error: Routes still present in RIB".format(tc_name)
+ assert result is not True, (
+ "Testcase {} : Failed\n Expected: Routes should not be present in RIB.\n"
+ "Error: Routes still present in RIB".format(tc_name)
+ )
step(
"Verify that boundary values tags are used for summary route"
@@ -1867,7 +1854,7 @@ def test_ospf_type5_summary_tc45_p0(request):
result = verify_ospf_summary(tgen, topo, dut, input_dict, expected=False)
assert (
result is not True
- ), "Testcase {} : Failed" "Error: Summary missing in OSPF DB".format(tc_name)
+ ), "Testcase {} : Failed. Error: Summary missing in OSPF DB".format(tc_name)
step("Delete the configured summary address")
ospf_summ_r1 = {
@@ -1898,24 +1885,24 @@ def test_ospf_type5_summary_tc45_p0(request):
result = verify_rib(tgen, "ipv4", dut, input_dict_static_rtes, protocol=protocol)
assert (
result is True
- ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed. Error: Routes is missing in RIB".format(tc_name)
step("Verify that summary address is flushed from neighbor.")
dut = "r1"
result = verify_ospf_rib(tgen, dut, input_dict_summary, expected=False)
- assert (
- result is not True
- ), "Testcase {} : Failed \n Error: " "Routes still present in OSPF RIB {}".format(
- tc_name, result
+ assert result is not True, (
+ "Testcase {} : Failed \n Expected: Routes should not be present in OSPF RIB \n Error: "
+ "Routes still present in OSPF RIB {}".format(tc_name, result)
)
result = verify_rib(
tgen, "ipv4", dut, input_dict_summary, protocol=protocol, expected=False
)
- assert (
- result is not True
- ), "Testcase {} : Failed" "Error: Routes still present in RIB".format(tc_name)
+ assert result is not True, (
+ "Testcase {} : Failed \n Expected: Routes should not be present in RIB \n"
+ "Error: Routes still present in RIB".format(tc_name)
+ )
step("Configure summary first & then configure matching static route.")
@@ -1999,7 +1986,7 @@ def test_ospf_type5_summary_tc46_p0(request):
result = verify_rib(tgen, "ipv4", dut, input_dict_static_rtes, protocol=protocol)
assert (
result is True
- ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed. Error: Routes is missing in RIB".format(tc_name)
step(
"Configure External Route summary in R0 to summarise 5"
@@ -2031,20 +2018,20 @@ def test_ospf_type5_summary_tc46_p0(request):
dut = "r1"
result = verify_ospf_rib(tgen, dut, input_dict_summary, expected=False)
- assert (
- result is not True
- ), "Testcase {} : Failed \n Error: " "Routes still present in OSPF RIB {}".format(
- tc_name, result
+ assert result is not True, (
+ "Testcase {} : Failed \n Expected: Routes should not be present in OSPF RIB.\n Error: "
+ "Routes still present in OSPF RIB {}".format(tc_name, result)
)
result = verify_rib(
tgen, "ipv4", dut, input_dict_summary, protocol=protocol, expected=False
)
- assert (
- result is not True
- ), "Testcase {} : Failed" "Error: Routes still present in RIB".format(tc_name)
+ assert result is not True, (
+ "Testcase {} : Failed\n Expected: Routes should not be present in RIB."
+ "Error: Routes still present in RIB".format(tc_name)
+ )
- step("Verify that show ip ospf summary should show the " "configured summaries.")
+ step("Verify that show ip ospf summary should show the configured summaries.")
input_dict = {
SUMMARY["ipv4"][0]: {
"summaryAddress": SUMMARY["ipv4"][0],
@@ -2055,7 +2042,7 @@ def test_ospf_type5_summary_tc46_p0(request):
result = verify_ospf_summary(tgen, topo, dut, input_dict)
assert (
result is True
- ), "Testcase {} : Failed" "Error: Summary missing in OSPF DB".format(tc_name)
+ ), "Testcase {} : Failed. Error: Summary missing in OSPF DB".format(tc_name)
step("Delete the configured summary")
ospf_summ_r1 = {
@@ -2080,10 +2067,9 @@ def test_ospf_type5_summary_tc46_p0(request):
step("Verify that summary lsa is withdrawn from R1 and deleted from R0.")
dut = "r1"
result = verify_ospf_rib(tgen, dut, input_dict, expected=False)
- assert (
- result is not True
- ), "Testcase {} : Failed \n Error: " "Routes still present in OSPF RIB {}".format(
- tc_name, result
+ assert result is not True, (
+ "Testcase {} : Failed \n Expected: Routes should not be present in OSPF RIB. \n Error: "
+ "Routes still present in OSPF RIB {}".format(tc_name, result)
)
result = verify_rib(
@@ -2091,9 +2077,7 @@ def test_ospf_type5_summary_tc46_p0(request):
)
assert (
result is not True
- ), "Testcase {} : Failed" "Error: Summary Route still present in RIB".format(
- tc_name
- )
+ ), "Testcase {} : Failed. Error: Summary Route still present in RIB".format(tc_name)
step("show ip ospf summary should not have any summary address.")
input_dict = {
@@ -2109,7 +2093,7 @@ def test_ospf_type5_summary_tc46_p0(request):
result = verify_ospf_summary(tgen, topo, dut, input_dict, expected=False)
assert (
result is not True
- ), "Testcase {} : Failed" "Error: Summary still present in DB".format(tc_name)
+ ), "Testcase {} : Failed. Error: Summary still present in DB".format(tc_name)
step("Reconfigure summary with no advertise.")
ospf_summ_r1 = {
@@ -2138,20 +2122,20 @@ def test_ospf_type5_summary_tc46_p0(request):
dut = "r1"
result = verify_ospf_rib(tgen, dut, input_dict_summary, expected=False)
- assert (
- result is not True
- ), "Testcase {} : Failed \n Error: " "Routes still present in OSPF RIB {}".format(
- tc_name, result
+ assert result is not True, (
+ "Testcase {} : Failed \n Expected: Routes should not be present in OSPF RIB. \n Error: "
+ "Routes still present in OSPF RIB {}".format(tc_name, result)
)
result = verify_rib(
tgen, "ipv4", dut, input_dict_summary, protocol=protocol, expected=False
)
- assert (
- result is not True
- ), "Testcase {} : Failed" "Error: Routes still present in RIB".format(tc_name)
+ assert result is not True, (
+ "Testcase {} : Failed \n Expected: Routes should not be present in RIB \n"
+ "Error: Routes still present in RIB".format(tc_name)
+ )
- step("Verify that show ip ospf summary should show the " "configured summaries.")
+ step("Verify that show ip ospf summary should show the configured summaries.")
input_dict = {
SUMMARY["ipv4"][0]: {
"summaryAddress": SUMMARY["ipv4"][0],
@@ -2162,7 +2146,7 @@ def test_ospf_type5_summary_tc46_p0(request):
result = verify_ospf_summary(tgen, topo, dut, input_dict)
assert (
result is True
- ), "Testcase {} : Failed" "Error: Summary missing in OSPF DB".format(tc_name)
+ ), "Testcase {} : Failed. Error: Summary missing in OSPF DB".format(tc_name)
step(
"Change summary address from no advertise to advertise "
@@ -2211,7 +2195,7 @@ def test_ospf_type5_summary_tc46_p0(request):
result = verify_rib(tgen, "ipv4", dut, input_dict_summary, protocol=protocol)
assert (
result is True
- ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed. Error: Routes is missing in RIB".format(tc_name)
step("Verify that show ip ospf summary should show the summaries.")
input_dict = {
@@ -2227,26 +2211,26 @@ def test_ospf_type5_summary_tc46_p0(request):
result = verify_ospf_summary(tgen, topo, dut, input_dict)
assert (
result is True
- ), "Testcase {} : Failed" "Error: Summary missing in OSPF DB".format(tc_name)
+ ), "Testcase {} : Failed. Error: Summary missing in OSPF DB".format(tc_name)
- step("Verify that originally advertised routes are withdraw from there" " peer.")
+ step("Verify that originally advertised routes are withdraw from there peer.")
input_dict = {
"r0": {"static_routes": [{"network": NETWORK["ipv4"], "next_hop": "blackhole"}]}
}
dut = "r1"
result = verify_ospf_rib(tgen, dut, input_dict, expected=False)
- assert (
- result is not True
- ), "Testcase {} : Failed \n Error: " "Routes still present in OSPF RIB {}".format(
- tc_name, result
+ assert result is not True, (
+ "Testcase {} : Failed \n Expected: Routes should not be present in OSPF RIB \n Error: "
+ "Routes still present in OSPF RIB {}".format(tc_name, result)
)
result = verify_rib(
tgen, "ipv4", dut, input_dict, protocol=protocol, expected=False
)
- assert (
- result is not True
- ), "Testcase {} : Failed" "Error: Routes is present in RIB".format(tc_name)
+ assert result is not True, (
+ "Testcase {} : Failed\n Expected: Routes should not be present in RIB"
+ "Error: Routes is present in RIB".format(tc_name)
+ )
write_test_footer(tc_name)
@@ -2293,11 +2277,9 @@ def test_ospf_type5_summary_tc47_p0(request):
result = verify_rib(tgen, "ipv4", dut, input_dict_static_rtes, protocol=protocol)
assert (
result is True
- ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed. Error: Routes is missing in RIB".format(tc_name)
- step(
- "Configure External Route summary in R0 to summarise 5" " routes to one route."
- )
+ step("Configure External Route summary in R0 to summarise 5 routes to one route.")
ospf_summ_r1 = {
"r0": {
@@ -2325,7 +2307,7 @@ def test_ospf_type5_summary_tc47_p0(request):
result = verify_rib(tgen, "ipv4", dut, input_dict_summary, protocol=protocol)
assert (
result is True
- ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed. Error: Routes is missing in RIB".format(tc_name)
step("Verify that show ip ospf summary should show the summaries.")
input_dict = {
@@ -2341,26 +2323,26 @@ def test_ospf_type5_summary_tc47_p0(request):
result = verify_ospf_summary(tgen, topo, dut, input_dict)
assert (
result is True
- ), "Testcase {} : Failed" "Error: Summary missing in OSPF DB".format(tc_name)
+ ), "Testcase {} : Failed. Error: Summary missing in OSPF DB".format(tc_name)
- step("Verify that originally advertised routes are withdraw from there" " peer.")
+ step("Verify that originally advertised routes are withdraw from there peer.")
input_dict = {
"r0": {"static_routes": [{"network": NETWORK["ipv4"], "next_hop": "blackhole"}]}
}
dut = "r1"
result = verify_ospf_rib(tgen, dut, input_dict, expected=False)
- assert (
- result is not True
- ), "Testcase {} : Failed \n Error: " "Routes still present in OSPF RIB {}".format(
- tc_name, result
+ assert result is not True, (
+ "Testcase {} : Failed \n \n Expected: Routes should not be present in OSPF RIB.\n Error: "
+ "Routes still present in OSPF RIB {}".format(tc_name, result)
)
result = verify_rib(
tgen, "ipv4", dut, input_dict, protocol=protocol, expected=False
)
- assert (
- result is not True
- ), "Testcase {} : Failed" "Error: Routes still present in RIB".format(tc_name)
+ assert result is not True, (
+ "Testcase {} : Failed\n Expected: Routes should not be present in RIB.\n"
+ "Error: Routes still present in RIB".format(tc_name)
+ )
step(
"configure route map and add rule to permit configured static "
@@ -2423,7 +2405,7 @@ def test_ospf_type5_summary_tc47_p0(request):
result = verify_rib(tgen, "ipv4", dut, input_dict_summary, protocol=protocol)
assert (
result is True
- ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed. Error: Routes is missing in RIB".format(tc_name)
input_dict = {
SUMMARY["ipv4"][0]: {
@@ -2461,18 +2443,18 @@ def test_ospf_type5_summary_tc47_p0(request):
step("Verify that advertised summary route is flushed from neighbor.")
dut = "r1"
result = verify_ospf_rib(tgen, dut, input_dict_summary, expected=False)
- assert (
- result is not True
- ), "Testcase {} : Failed \n Error: " "Routes still present in OSPF RIB {}".format(
- tc_name, result
+ assert result is not True, (
+ "Testcase {} : Failed \n Expected: Routes should not be present in OSPF RIB\n Error: "
+ "Routes still present in OSPF RIB {}".format(tc_name, result)
)
result = verify_rib(
tgen, "ipv4", dut, input_dict_summary, protocol=protocol, expected=False
)
- assert (
- result is not True
- ), "Testcase {} : Failed" "Error: Routes still present in RIB".format(tc_name)
+ assert result is not True, (
+ "Testcase {} : Failed \n Expected: Routes should not be present in RIB.\n"
+ "Error: Routes still present in RIB".format(tc_name)
+ )
step("Delete the configured route map.")
@@ -2511,7 +2493,7 @@ def test_ospf_type5_summary_tc47_p0(request):
result = verify_rib(tgen, "ipv4", dut, input_dict_summary, protocol=protocol)
assert (
result is True
- ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed. Error: Routes is missing in RIB".format(tc_name)
input_dict = {
SUMMARY["ipv4"][0]: {
@@ -2526,7 +2508,7 @@ def test_ospf_type5_summary_tc47_p0(request):
result = verify_ospf_summary(tgen, topo, dut, input_dict)
assert (
result is True
- ), "Testcase {} : Failed" "Error: Summary missing in OSPF DB".format(tc_name)
+ ), "Testcase {} : Failed. Error: Summary missing in OSPF DB".format(tc_name)
step("Reconfigure the route map with denying configure summary address.")
@@ -2570,7 +2552,7 @@ def test_ospf_type5_summary_tc47_p0(request):
result = verify_rib(tgen, "ipv4", dut, input_dict_summary, protocol=protocol)
assert (
result is True
- ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed. Error: Routes is missing in RIB".format(tc_name)
step("Redistribute static/connected routes without route map.")
@@ -2606,7 +2588,7 @@ def test_ospf_type5_summary_tc47_p0(request):
result = verify_rib(tgen, "ipv4", dut, input_dict_summary, protocol=protocol)
assert (
result is True
- ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed. Error: Routes is missing in RIB".format(tc_name)
input_dict = {
SUMMARY["ipv4"][0]: {
@@ -2621,7 +2603,7 @@ def test_ospf_type5_summary_tc47_p0(request):
result = verify_ospf_summary(tgen, topo, dut, input_dict)
assert (
result is True
- ), "Testcase {} : Failed" "Error: Summary missing in OSPF DB".format(tc_name)
+ ), "Testcase {} : Failed. Error: Summary missing in OSPF DB".format(tc_name)
step(
"Configure rule to deny all the routes in route map and configure"
@@ -2672,18 +2654,18 @@ def test_ospf_type5_summary_tc47_p0(request):
step("Verify that no summary route is originated.")
dut = "r1"
result = verify_ospf_rib(tgen, dut, input_dict_summary, expected=False)
- assert (
- result is not True
- ), "Testcase {} : Failed \n Error: " "Routes still present in OSPF RIB {}".format(
- tc_name, result
+ assert result is not True, (
+ "Testcase {} : Failed \n Expected: Routes should not be present in OSPF RIB.\n Error: "
+ "Routes still present in OSPF RIB {}".format(tc_name, result)
)
result = verify_rib(
tgen, "ipv4", dut, input_dict_summary, protocol=protocol, expected=False
)
- assert (
- result is not True
- ), "Testcase {} : Failed" "Error: Routes still present in RIB".format(tc_name)
+ assert result is not True, (
+ "Testcase {} : Failed\n Expected: Routes should not be present in RIB"
+ "Error: Routes still present in RIB".format(tc_name)
+ )
routemaps = {
"r0": {
@@ -2773,7 +2755,7 @@ def test_ospf_type5_summary_tc47_p0(request):
result = verify_rib(tgen, "ipv4", dut, input_dict_summary, protocol=protocol)
assert (
result is True
- ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed. Error: Routes is missing in RIB".format(tc_name)
step("Verify that show ip ospf summary should show the summaries.")
input_dict = {
@@ -2789,7 +2771,7 @@ def test_ospf_type5_summary_tc47_p0(request):
result = verify_ospf_summary(tgen, topo, dut, input_dict)
assert (
result is True
- ), "Testcase {} : Failed" "Error: Summary missing in OSPF DB".format(tc_name)
+ ), "Testcase {} : Failed. Error: Summary missing in OSPF DB".format(tc_name)
step("Change route map rule for 1 of the routes to deny.")
# Create ip prefix list
@@ -2822,7 +2804,7 @@ def test_ospf_type5_summary_tc47_p0(request):
result = verify_rib(tgen, "ipv4", dut, input_dict_summary, protocol=protocol)
assert (
result is True
- ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed. Error: Routes is missing in RIB".format(tc_name)
step("add rule in route map to deny configured summary address.")
# Create ip prefix list
@@ -2855,7 +2837,7 @@ def test_ospf_type5_summary_tc47_p0(request):
result = verify_rib(tgen, "ipv4", dut, input_dict_summary, protocol=protocol)
assert (
result is True
- ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed. Error: Routes is missing in RIB".format(tc_name)
write_test_footer(tc_name)
@@ -2995,7 +2977,7 @@ def test_ospf_type5_summary_tc51_p2(request):
result = verify_ospf_summary(tgen, topo, dut, input_dict)
assert (
result is True
- ), "Testcase {} : Failed" "Error: Summary missing in OSPF DB".format(tc_name)
+ ), "Testcase {} : Failed. Error: Summary missing in OSPF DB".format(tc_name)
write_test_footer(tc_name)
@@ -3042,11 +3024,9 @@ def test_ospf_type5_summary_tc49_p2(request):
result = verify_rib(tgen, "ipv4", dut, input_dict_static_rtes, protocol=protocol)
assert (
result is True
- ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed. Error: Routes is missing in RIB".format(tc_name)
- step(
- "Configure External Route summary in R0 to summarise 5" " routes to one route."
- )
+ step("Configure External Route summary in R0 to summarise 5 routes to one route.")
ospf_summ_r1 = {
"r0": {
@@ -3074,7 +3054,7 @@ def test_ospf_type5_summary_tc49_p2(request):
result = verify_rib(tgen, "ipv4", dut, input_dict_summary, protocol=protocol)
assert (
result is True
- ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed. Error: Routes is missing in RIB".format(tc_name)
step("Verify that show ip ospf summary should show the summaries.")
input_dict = {
@@ -3090,26 +3070,26 @@ def test_ospf_type5_summary_tc49_p2(request):
result = verify_ospf_summary(tgen, topo, dut, input_dict)
assert (
result is True
- ), "Testcase {} : Failed" "Error: Summary missing in OSPF DB".format(tc_name)
+ ), "Testcase {} : Failed. Error: Summary missing in OSPF DB".format(tc_name)
- step("Verify that originally advertised routes are withdraw from there" " peer.")
+ step("Verify that originally advertised routes are withdraw from there peer.")
input_dict = {
"r0": {"static_routes": [{"network": NETWORK["ipv4"], "next_hop": "blackhole"}]}
}
dut = "r1"
result = verify_ospf_rib(tgen, dut, input_dict, expected=False)
- assert (
- result is not True
- ), "Testcase {} : Failed \n Error: " "Routes still present in OSPF RIB {}".format(
- tc_name, result
+ assert result is not True, (
+ "Testcase {} : Failed \n Expected: Routes should not be present in OSPF RIB.\n Error: "
+ "Routes still present in OSPF RIB {}".format(tc_name, result)
)
result = verify_rib(
tgen, "ipv4", dut, input_dict, protocol=protocol, expected=False
)
- assert (
- result is not True
- ), "Testcase {} : Failed" "Error: Routes still present in RIB".format(tc_name)
+ assert result is not True, (
+ "Testcase {} : Failed\n Expected: Routes should not be present in RIB.\n"
+ "Error: Routes still present in RIB".format(tc_name)
+ )
step("Reload the FRR router")
# stop/start -> restart FRR router and verify
@@ -3130,7 +3110,7 @@ def test_ospf_type5_summary_tc49_p2(request):
result = verify_rib(tgen, "ipv4", dut, input_dict_summary, protocol=protocol)
assert (
result is True
- ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed. Error: Routes is missing in RIB".format(tc_name)
step("Verify that show ip ospf summary should show the summaries.")
input_dict = {
@@ -3146,26 +3126,26 @@ def test_ospf_type5_summary_tc49_p2(request):
result = verify_ospf_summary(tgen, topo, dut, input_dict)
assert (
result is True
- ), "Testcase {} : Failed" "Error: Summary missing in OSPF DB".format(tc_name)
+ ), "Testcase {} : Failed. Error: Summary missing in OSPF DB".format(tc_name)
- step("Verify that originally advertised routes are withdraw from there" " peer.")
+ step("Verify that originally advertised routes are withdraw from there peer.")
input_dict = {
"r0": {"static_routes": [{"network": NETWORK["ipv4"], "next_hop": "blackhole"}]}
}
dut = "r1"
result = verify_ospf_rib(tgen, dut, input_dict, expected=False)
- assert (
- result is not True
- ), "Testcase {} : Failed \n Error: " "Routes still present in OSPF RIB {}".format(
- tc_name, result
+ assert result is not True, (
+ "Testcase {} : Failed \n Expected: Routes should not be present in OSPF RIB. \n Error: "
+ "Routes still present in OSPF RIB {}".format(tc_name, result)
)
result = verify_rib(
tgen, "ipv4", dut, input_dict, protocol=protocol, expected=False
)
- assert (
- result is not True
- ), "Testcase {} : Failed" "Error: Routes still present in RIB".format(tc_name)
+ assert result is not True, (
+ "Testcase {} : Failed\n Expected: Routes should not be present in RIB\n"
+ "Error: Routes still present in RIB".format(tc_name)
+ )
step("Kill OSPFd daemon on R0.")
kill_router_daemons(tgen, "r0", ["ospfd"])
@@ -3176,7 +3156,7 @@ def test_ospf_type5_summary_tc49_p2(request):
step("Verify OSPF neighbors are up after bringing back ospfd in R0")
# Api call verify whether OSPF is converged
ospf_covergence = verify_ospf_neighbor(tgen, topo)
- assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
+ assert ospf_covergence is True, "setup_module :Failed \n Error {}".format(
ospf_covergence
)
@@ -3194,7 +3174,7 @@ def test_ospf_type5_summary_tc49_p2(request):
result = verify_rib(tgen, "ipv4", dut, input_dict_summary, protocol=protocol)
assert (
result is True
- ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed. Error: Routes is missing in RIB".format(tc_name)
step("Verify that show ip ospf summary should show the summaries.")
input_dict = {
@@ -3210,26 +3190,26 @@ def test_ospf_type5_summary_tc49_p2(request):
result = verify_ospf_summary(tgen, topo, dut, input_dict)
assert (
result is True
- ), "Testcase {} : Failed" "Error: Summary missing in OSPF DB".format(tc_name)
+ ), "Testcase {} : Failed. Error: Summary missing in OSPF DB".format(tc_name)
- step("Verify that originally advertised routes are withdraw from there" " peer.")
+ step("Verify that originally advertised routes are withdraw from there peer.")
input_dict = {
"r0": {"static_routes": [{"network": NETWORK["ipv4"], "next_hop": "blackhole"}]}
}
dut = "r1"
result = verify_ospf_rib(tgen, dut, input_dict, expected=False)
- assert (
- result is not True
- ), "Testcase {} : Failed \n Error: " "Routes still present in OSPF RIB {}".format(
- tc_name, result
+ assert result is not True, (
+ "Testcase {} : Failed \n Expected: Routes should not be present in OSPF RIB. \n Error: "
+ "Routes still present in OSPF RIB {}".format(tc_name, result)
)
result = verify_rib(
tgen, "ipv4", dut, input_dict, protocol=protocol, expected=False
)
- assert (
- result is not True
- ), "Testcase {} : Failed" "Error: Routes still present in RIB".format(tc_name)
+ assert result is not True, (
+ "Testcase {} : Failed\n Expected: Routes should not be present in RIB\n"
+ "Error: Routes still present in RIB".format(tc_name)
+ )
step("restart zebrad")
kill_router_daemons(tgen, "r0", ["zebra"])
@@ -3251,7 +3231,7 @@ def test_ospf_type5_summary_tc49_p2(request):
result = verify_rib(tgen, "ipv4", dut, input_dict_summary, protocol=protocol)
assert (
result is True
- ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed. Error: Routes is missing in RIB".format(tc_name)
step("Verify that show ip ospf summary should show the summaries.")
input_dict = {
@@ -3267,26 +3247,26 @@ def test_ospf_type5_summary_tc49_p2(request):
result = verify_ospf_summary(tgen, topo, dut, input_dict)
assert (
result is True
- ), "Testcase {} : Failed" "Error: Summary missing in OSPF DB".format(tc_name)
+ ), "Testcase {} : Failed. Error: Summary missing in OSPF DB".format(tc_name)
- step("Verify that originally advertised routes are withdraw from there" " peer.")
+ step("Verify that originally advertised routes are withdraw from there peer.")
input_dict = {
"r0": {"static_routes": [{"network": NETWORK["ipv4"], "next_hop": "blackhole"}]}
}
dut = "r1"
result = verify_ospf_rib(tgen, dut, input_dict, expected=False)
- assert (
- result is not True
- ), "Testcase {} : Failed \n Error: " "Routes still present in OSPF RIB {}".format(
- tc_name, result
+ assert result is not True, (
+ "Testcase {} : Failed\n Expected: Routes should not be present in OSPF RIB. \n Error: "
+ "Routes still present in OSPF RIB {}".format(tc_name, result)
)
result = verify_rib(
tgen, "ipv4", dut, input_dict, protocol=protocol, expected=False
)
- assert (
- result is not True
- ), "Testcase {} : Failed" "Error: Routes still present in RIB".format(tc_name)
+ assert result is not True, (
+ "Testcase {} : Failed\n Expected: Routes should not be present in RIB.\n"
+ "Error: Routes still present in RIB".format(tc_name)
+ )
write_test_footer(tc_name)
diff --git a/tests/topotests/ospf_basic_functionality/test_ospf_asbr_summary_type7_lsa.py b/tests/topotests/ospf_basic_functionality/test_ospf_asbr_summary_type7_lsa.py
index cff59c3a40..603aeadb85 100644
--- a/tests/topotests/ospf_basic_functionality/test_ospf_asbr_summary_type7_lsa.py
+++ b/tests/topotests/ospf_basic_functionality/test_ospf_asbr_summary_type7_lsa.py
@@ -132,7 +132,7 @@ def setup_module(mod):
pytest.skip(tgen.errors)
# Api call verify whether OSPF is converged
ospf_covergence = verify_ospf_neighbor(tgen, topo)
- assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
+ assert ospf_covergence is True, "setup_module :Failed \n Error {}".format(
ospf_covergence
)
@@ -235,11 +235,9 @@ def test_ospf_type5_summary_tc44_p0(request):
result = verify_rib(tgen, "ipv4", dut, input_dict_static_rtes, protocol=protocol)
assert (
result is True
- ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed. Error: Routes is missing in RIB".format(tc_name)
- step(
- "Configure External Route summary in R0 to summarise 5" " routes to one route."
- )
+ step("Configure External Route summary in R0 to summarise 5 routes to one route.")
ospf_summ_r0 = {
"r0": {
@@ -259,9 +257,7 @@ def test_ospf_type5_summary_tc44_p0(request):
"route is sent to R1."
)
- step(
- "Configure summary & redistribute static/connected route with " "metric type 2"
- )
+ step("Configure summary & redistribute static/connected route with metric type 2")
input_dict_summary = {"r0": {"static_routes": [{"network": SUMMARY["ipv4"][3]}]}}
dut = "r1"
@@ -272,7 +268,7 @@ def test_ospf_type5_summary_tc44_p0(request):
result = verify_rib(tgen, "ipv4", dut, input_dict_summary, protocol=protocol)
assert (
result is True
- ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed. Error: Routes is missing in RIB".format(tc_name)
step("Verify that show ip ospf summary should show the summaries.")
input_dict = {
@@ -288,7 +284,7 @@ def test_ospf_type5_summary_tc44_p0(request):
result = verify_ospf_summary(tgen, topo, dut, input_dict)
assert (
result is True
- ), "Testcase {} : Failed" "Error: Summary missing in OSPF DB".format(tc_name)
+ ), "Testcase {} : Failed. Error: Summary missing in OSPF DB".format(tc_name)
step("Learn type 7 lsa from neighbours")
@@ -312,7 +308,7 @@ def test_ospf_type5_summary_tc44_p0(request):
result = verify_rib(tgen, "ipv4", dut, input_dict_static_rtes, protocol=protocol)
assert (
result is True
- ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed. Error: Routes is missing in RIB".format(tc_name)
ospf_summ_r0 = {
"r0": {
@@ -340,7 +336,7 @@ def test_ospf_type5_summary_tc44_p0(request):
result = verify_ospf_summary(tgen, topo, dut, input_dict)
assert (
result is True
- ), "Testcase {} : Failed" "Error: Summary missing in OSPF DB".format(tc_name)
+ ), "Testcase {} : Failed. Error: Summary missing in OSPF DB".format(tc_name)
step("Verify that already originated summary is intact.")
input_dict = {
@@ -356,7 +352,7 @@ def test_ospf_type5_summary_tc44_p0(request):
result = verify_ospf_summary(tgen, topo, dut, input_dict)
assert (
result is True
- ), "Testcase {} : Failed" "Error: Summary missing in OSPF DB".format(tc_name)
+ ), "Testcase {} : Failed. Error: Summary missing in OSPF DB".format(tc_name)
dut = "r1"
aggr_timer = {"r1": {"ospf": {"aggr_timer": 6}}}
diff --git a/tests/topotests/ospf_basic_functionality/test_ospf_authentication.py b/tests/topotests/ospf_basic_functionality/test_ospf_authentication.py
index 40df0b2308..88219b8400 100644
--- a/tests/topotests/ospf_basic_functionality/test_ospf_authentication.py
+++ b/tests/topotests/ospf_basic_functionality/test_ospf_authentication.py
@@ -100,7 +100,7 @@ def setup_module(mod):
pytest.skip(tgen.errors)
ospf_covergence = verify_ospf_neighbor(tgen, topo)
- assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
+ assert ospf_covergence is True, "setup_module :Failed \n Error {}".format(
ospf_covergence
)
@@ -166,7 +166,7 @@ def test_ospf_authentication_simple_pass_tc28_p1(request):
step("Verify that the neighbour is not FULL between R1 and R2.")
dut = "r1"
ospf_covergence = verify_ospf_neighbor(tgen, topo, dut=dut, expected=False)
- assert ospf_covergence is not True, "setup_module :Failed \n Error:" " {}".format(
+ assert ospf_covergence is not True, "Testcase Failed \n Error {}".format(
ospf_covergence
)
@@ -192,7 +192,7 @@ def test_ospf_authentication_simple_pass_tc28_p1(request):
dut = "r2"
ospf_covergence = verify_ospf_neighbor(tgen, topo, dut=dut)
- assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
+ assert ospf_covergence is True, "Testcase Failed \n Error {}".format(
ospf_covergence
)
@@ -223,7 +223,7 @@ def test_ospf_authentication_simple_pass_tc28_p1(request):
ospf_covergence = verify_ospf_neighbor(
tgen, topo, dut=dut, expected=False, retry_timeout=10
)
- assert ospf_covergence is not True, "setup_module :Failed \n Error:" " {}".format(
+ assert ospf_covergence is not True, "Testcase Failed \n Error {}".format(
ospf_covergence
)
@@ -245,7 +245,7 @@ def test_ospf_authentication_simple_pass_tc28_p1(request):
dut = "r2"
ospf_covergence = verify_ospf_neighbor(tgen, topo, dut=dut)
- assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
+ assert ospf_covergence is True, "Testcase Failed \n Error {}".format(
ospf_covergence
)
@@ -260,7 +260,7 @@ def test_ospf_authentication_simple_pass_tc28_p1(request):
"show ip ospf neighbor cmd."
)
ospf_covergence = verify_ospf_neighbor(tgen, topo, dut=dut, expected=False)
- assert ospf_covergence is not True, "setup_module :Failed \n Error:" " {}".format(
+ assert ospf_covergence is not True, "Testcase Failed \n Error {}".format(
ospf_covergence
)
@@ -274,7 +274,7 @@ def test_ospf_authentication_simple_pass_tc28_p1(request):
dut = "r2"
ospf_covergence = verify_ospf_neighbor(tgen, topo, dut=dut)
- assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
+ assert ospf_covergence is True, "Testcase Failed \n Error {}".format(
ospf_covergence
)
@@ -314,7 +314,7 @@ def test_ospf_authentication_simple_pass_tc28_p1(request):
dut = "r1"
ospf_covergence = verify_ospf_neighbor(tgen, topo, dut=dut)
- assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
+ assert ospf_covergence is True, "Testcase Failed \n Error {}".format(
ospf_covergence
)
@@ -361,7 +361,7 @@ def test_ospf_authentication_md5_tc29_p1(request):
ospf_covergence = verify_ospf_neighbor(
tgen, topo, dut=dut, expected=False, retry_timeout=6
)
- assert ospf_covergence is not True, "setup_module :Failed \n Error:" " {}".format(
+ assert ospf_covergence is not True, "Testcase Failed \n Error {}".format(
ospf_covergence
)
@@ -393,7 +393,7 @@ def test_ospf_authentication_md5_tc29_p1(request):
dut = "r2"
ospf_covergence = verify_ospf_neighbor(tgen, topo, dut=dut)
- assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
+ assert ospf_covergence is True, "Testcase Failed \n Error {}".format(
ospf_covergence
)
@@ -426,7 +426,7 @@ def test_ospf_authentication_md5_tc29_p1(request):
ospf_covergence = verify_ospf_neighbor(
tgen, topo, dut=dut, expected=False, retry_timeout=10
)
- assert ospf_covergence is not True, "setup_module :Failed \n Error:" " {}".format(
+ assert ospf_covergence is not True, "Testcase Failed \n Error {}".format(
ospf_covergence
)
@@ -454,7 +454,7 @@ def test_ospf_authentication_md5_tc29_p1(request):
dut = "r2"
ospf_covergence = verify_ospf_neighbor(tgen, topo, dut=dut)
- assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
+ assert ospf_covergence is True, "Testcase Failed \n Error {}".format(
ospf_covergence
)
@@ -469,7 +469,7 @@ def test_ospf_authentication_md5_tc29_p1(request):
"show ip ospf neighbor cmd."
)
ospf_covergence = verify_ospf_neighbor(tgen, topo, dut=dut, expected=False)
- assert ospf_covergence is not True, "setup_module :Failed \n Error:" " {}".format(
+ assert ospf_covergence is not True, "Testcase Failed \n Error {}".format(
ospf_covergence
)
@@ -483,7 +483,7 @@ def test_ospf_authentication_md5_tc29_p1(request):
dut = "r2"
ospf_covergence = verify_ospf_neighbor(tgen, topo, dut=dut)
- assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
+ assert ospf_covergence is True, "Testcase Failed \n Error {}".format(
ospf_covergence
)
@@ -528,7 +528,7 @@ def test_ospf_authentication_md5_tc29_p1(request):
dut = "r1"
ospf_covergence = verify_ospf_neighbor(tgen, topo, dut=dut)
- assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
+ assert ospf_covergence is True, "Testcase Failed \n Error {}".format(
ospf_covergence
)
@@ -576,7 +576,7 @@ def test_ospf_authentication_different_auths_tc30_p1(request):
ospf_covergence = verify_ospf_neighbor(
tgen, topo, dut=dut, expected=False, retry_timeout=10
)
- assert ospf_covergence is not True, "setup_module :Failed \n Error:" " {}".format(
+ assert ospf_covergence is not True, "Testcase Failed \n Error {}".format(
ospf_covergence
)
@@ -608,7 +608,7 @@ def test_ospf_authentication_different_auths_tc30_p1(request):
dut = "r2"
ospf_covergence = verify_ospf_neighbor(tgen, topo, dut=dut)
- assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
+ assert ospf_covergence is True, "Testcase Failed \n Error {}".format(
ospf_covergence
)
@@ -655,7 +655,7 @@ def test_ospf_authentication_different_auths_tc30_p1(request):
dut = "r2"
ospf_covergence = verify_ospf_neighbor(tgen, topo, dut=dut)
- assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
+ assert ospf_covergence is True, "Testcase Failed \n Error {}".format(
ospf_covergence
)
@@ -687,7 +687,7 @@ def test_ospf_authentication_different_auths_tc30_p1(request):
dut = "r2"
ospf_covergence = verify_ospf_neighbor(tgen, topo, dut=dut)
- assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
+ assert ospf_covergence is True, "Testcase Failed \n Error {}".format(
ospf_covergence
)
@@ -720,7 +720,7 @@ def test_ospf_authentication_different_auths_tc30_p1(request):
dut = "r2"
ospf_covergence = verify_ospf_neighbor(tgen, topo, dut=dut)
- assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
+ assert ospf_covergence is True, "Testcase Failed \n Error {}".format(
ospf_covergence
)
@@ -765,7 +765,7 @@ def test_ospf_authentication_different_auths_tc30_p1(request):
dut = "r2"
ospf_covergence = verify_ospf_neighbor(tgen, topo, dut=dut)
- assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
+ assert ospf_covergence is True, "Testcase Failed \n Error {}".format(
ospf_covergence
)
@@ -810,7 +810,7 @@ def test_ospf_authentication_different_auths_tc30_p1(request):
dut = "r2"
ospf_covergence = verify_ospf_neighbor(tgen, topo, dut=dut)
- assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
+ assert ospf_covergence is True, "Testcase Failed \n Error {}".format(
ospf_covergence
)
diff --git a/tests/topotests/ospf_basic_functionality/test_ospf_chaos.py b/tests/topotests/ospf_basic_functionality/test_ospf_chaos.py
index 124b36a5fa..e58f081f96 100644
--- a/tests/topotests/ospf_basic_functionality/test_ospf_chaos.py
+++ b/tests/topotests/ospf_basic_functionality/test_ospf_chaos.py
@@ -111,7 +111,7 @@ def setup_module(mod):
pytest.skip(tgen.errors)
ospf_covergence = verify_ospf_neighbor(tgen, topo)
- assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
+ assert ospf_covergence is True, "setup_module :Failed \n Error {}".format(
ospf_covergence
)
@@ -177,7 +177,7 @@ def test_ospf_chaos_tc31_p1(request):
step("Verify OSPF neighbors after base config is done.")
# Api call verify whether OSPF is converged
ospf_covergence = verify_ospf_neighbor(tgen, topo)
- assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
+ assert ospf_covergence is True, "Testcase Failed \n Error {}".format(
ospf_covergence
)
@@ -198,7 +198,7 @@ def test_ospf_chaos_tc31_p1(request):
dut = "r0"
# Api call verify whether OSPF is converged
ospf_covergence = verify_ospf_neighbor(tgen, topo, dut=dut, expected=False)
- assert ospf_covergence is not True, "setup_module :Failed \n Error:" " {}".format(
+ assert ospf_covergence is not True, "Testcase Failed \n Error {}".format(
ospf_covergence
)
@@ -208,7 +208,7 @@ def test_ospf_chaos_tc31_p1(request):
result = verify_ospf_rib(tgen, dut, input_dict, expected=False)
assert (
result is not True
- ), "Testcase {} : Failed \n " "r1: OSPF routes are present \n Error: {}".format(
+ ), "Testcase {} : Failed \n r1: OSPF routes are present \n Error: {}".format(
tc_name, result
)
@@ -217,7 +217,7 @@ def test_ospf_chaos_tc31_p1(request):
)
assert (
result is not True
- ), "Testcase {} : Failed \n " "r1: routes are still present \n Error: {}".format(
+ ), "Testcase {} : Failed \n r1: routes are still present \n Error: {}".format(
tc_name, result
)
@@ -227,7 +227,7 @@ def test_ospf_chaos_tc31_p1(request):
step("Verify OSPF neighbors are up after bringing back ospfd in R0")
# Api call verify whether OSPF is converged
ospf_covergence = verify_ospf_neighbor(tgen, topo)
- assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
+ assert ospf_covergence is True, "Testcase Failed \n Error {}".format(
ospf_covergence
)
@@ -250,7 +250,7 @@ def test_ospf_chaos_tc31_p1(request):
dut = "r1"
# Api call verify whether OSPF is converged
ospf_covergence = verify_ospf_neighbor(tgen, topo, dut=dut, expected=False)
- assert ospf_covergence is not True, "setup_module :Failed \n Error:" " {}".format(
+ assert ospf_covergence is not True, "Testcase Failed \n Error {}".format(
ospf_covergence
)
@@ -260,7 +260,7 @@ def test_ospf_chaos_tc31_p1(request):
step("Verify OSPF neighbors are up after bringing back ospfd in R1")
# Api call verify whether OSPF is converged
ospf_covergence = verify_ospf_neighbor(tgen, topo)
- assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
+ assert ospf_covergence is True, "Testcase Failed \n Error {}".format(
ospf_covergence
)
@@ -316,7 +316,7 @@ def test_ospf_chaos_tc32_p1(request):
step("Verify OSPF neighbors after base config is done.")
# Api call verify whether OSPF is converged
ospf_covergence = verify_ospf_neighbor(tgen, topo)
- assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
+ assert ospf_covergence is True, "Testcase Failed \n Error {}".format(
ospf_covergence
)
@@ -338,7 +338,7 @@ def test_ospf_chaos_tc32_p1(request):
step("Verify OSPF neighbors are up after restarting R0")
# Api call verify whether OSPF is converged
ospf_covergence = verify_ospf_neighbor(tgen, topo)
- assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
+ assert ospf_covergence is True, "Testcase Failed \n Error {}".format(
ospf_covergence
)
@@ -361,7 +361,7 @@ def test_ospf_chaos_tc32_p1(request):
step("Verify OSPF neighbors are up after restarting R1")
# Api call verify whether OSPF is converged
ospf_covergence = verify_ospf_neighbor(tgen, topo)
- assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
+ assert ospf_covergence is True, "Testcase Failed \n Error {}".format(
ospf_covergence
)
@@ -421,7 +421,7 @@ def test_ospf_chaos_tc34_p1(request):
step("Verify OSPF neighbors after base config is done.")
# Api call verify whether OSPF is converged
ospf_covergence = verify_ospf_neighbor(tgen, topo)
- assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
+ assert ospf_covergence is True, "Testcase Failed \n Error {}".format(
ospf_covergence
)
@@ -444,7 +444,7 @@ def test_ospf_chaos_tc34_p1(request):
result = verify_ospf_rib(tgen, dut, input_dict, expected=False)
assert (
result is not True
- ), "Testcase {} : Failed \n " "r1: OSPF routes are present \n Error: {}".format(
+ ), "Testcase {} : Failed \n r1: OSPF routes are present \n Error: {}".format(
tc_name, result
)
@@ -453,7 +453,7 @@ def test_ospf_chaos_tc34_p1(request):
)
assert (
result is not True
- ), "Testcase {} : Failed \n " "r1: routes are still present \n Error: {}".format(
+ ), "Testcase {} : Failed \n r1: routes are still present \n Error: {}".format(
tc_name, result
)
@@ -463,7 +463,7 @@ def test_ospf_chaos_tc34_p1(request):
step("Verify OSPF neighbors are up after bringing back ospfd in R0")
# Api call verify whether OSPF is converged
ospf_covergence = verify_ospf_neighbor(tgen, topo)
- assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
+ assert ospf_covergence is True, "Testcase Failed \n Error {}".format(
ospf_covergence
)
@@ -488,7 +488,7 @@ def test_ospf_chaos_tc34_p1(request):
step("Verify OSPF neighbors are up after bringing back ospfd in R1")
# Api call verify whether OSPF is converged
ospf_covergence = verify_ospf_neighbor(tgen, topo)
- assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
+ assert ospf_covergence is True, "Testcase Failed \n Error {}".format(
ospf_covergence
)
diff --git a/tests/topotests/ospf_basic_functionality/test_ospf_ecmp.py b/tests/topotests/ospf_basic_functionality/test_ospf_ecmp.py
index d58e2503ed..aba313db9f 100644
--- a/tests/topotests/ospf_basic_functionality/test_ospf_ecmp.py
+++ b/tests/topotests/ospf_basic_functionality/test_ospf_ecmp.py
@@ -114,7 +114,7 @@ def setup_module(mod):
pytest.skip(tgen.errors)
# Api call verify whether OSPF is converged
ospf_covergence = verify_ospf_neighbor(tgen, topo)
- assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
+ assert ospf_covergence is True, "setup_module :Failed \n Error {}".format(
ospf_covergence
)
@@ -168,7 +168,7 @@ def test_ospf_ecmp_tc16_p0(request):
step("Verify that OSPF is up with 8 neighborship sessions.")
dut = "r1"
ospf_covergence = verify_ospf_neighbor(tgen, topo, dut=dut)
- assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
+ assert ospf_covergence is True, "Testcase Failed \n Error {}".format(
ospf_covergence
)
@@ -217,7 +217,7 @@ def test_ospf_ecmp_tc16_p0(request):
result = verify_ospf_rib(tgen, dut, input_dict, next_hop=nh, expected=False)
assert (
result is not True
- ), "Testcase {} : Failed \n " "r1: OSPF routes are present \n Error: {}".format(
+ ), "Testcase {} : Failed \n r1: OSPF routes are present \n Error: {}".format(
tc_name, result
)
@@ -227,7 +227,7 @@ def test_ospf_ecmp_tc16_p0(request):
)
assert (
result is not True
- ), "Testcase {} : Failed \n " "r1: routes are still present \n Error: {}".format(
+ ), "Testcase {} : Failed \n r1: routes are still present \n Error: {}".format(
tc_name, result
)
@@ -259,7 +259,7 @@ def test_ospf_ecmp_tc16_p0(request):
step("Verify that OSPF is up with 8 neighborship sessions.")
dut = "r1"
ospf_covergence = verify_ospf_neighbor(tgen, topo, dut=dut)
- assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
+ assert ospf_covergence is True, "Testcase Failed \n Error {}".format(
ospf_covergence
)
@@ -286,7 +286,7 @@ def test_ospf_ecmp_tc16_p0(request):
)
assert (
result is not True
- ), "Testcase {} : Failed \n " "r1: OSPF routes are present \n Error: {}".format(
+ ), "Testcase {} : Failed \n r1: OSPF routes are present \n Error: {}".format(
tc_name, result
)
@@ -303,7 +303,7 @@ def test_ospf_ecmp_tc16_p0(request):
)
assert (
result is not True
- ), "Testcase {} : Failed \n " "r1: routes are still present \n Error: {}".format(
+ ), "Testcase {} : Failed \n r1: routes are still present \n Error: {}".format(
tc_name, result
)
@@ -343,7 +343,7 @@ def test_ospf_ecmp_tc17_p0(request):
step("Verify that OSPF is up with 2 neighborship sessions.")
dut = "r1"
ospf_covergence = verify_ospf_neighbor(tgen, topo, dut=dut)
- assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
+ assert ospf_covergence is True, "Testcase Failed \n Error {}".format(
ospf_covergence
)
@@ -394,7 +394,7 @@ def test_ospf_ecmp_tc17_p0(request):
)
assert (
result is not True
- ), "Testcase {} : Failed \n " "r1: OSPF routes are present \n Error: {}".format(
+ ), "Testcase {} : Failed \n r1: OSPF routes are present \n Error: {}".format(
tc_name, result
)
@@ -411,7 +411,7 @@ def test_ospf_ecmp_tc17_p0(request):
)
assert (
result is not True
- ), "Testcase {} : Failed \n " "r1: routes are still present \n Error: {}".format(
+ ), "Testcase {} : Failed \n r1: routes are still present \n Error: {}".format(
tc_name, result
)
diff --git a/tests/topotests/ospf_basic_functionality/test_ospf_ecmp_lan.py b/tests/topotests/ospf_basic_functionality/test_ospf_ecmp_lan.py
index 6a565571be..1eeb23e9f7 100644
--- a/tests/topotests/ospf_basic_functionality/test_ospf_ecmp_lan.py
+++ b/tests/topotests/ospf_basic_functionality/test_ospf_ecmp_lan.py
@@ -115,7 +115,7 @@ def setup_module(mod):
pytest.skip(tgen.errors)
# Api call verify whether OSPF is converged
ospf_covergence = verify_ospf_neighbor(tgen, topo, lan=True)
- assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
+ assert ospf_covergence is True, "setup_module :Failed \n Error {}".format(
ospf_covergence
)
@@ -169,7 +169,7 @@ def test_ospf_lan_ecmp_tc18_p0(request):
step("Verify that OSPF is up with 8 neighborship sessions.")
ospf_covergence = verify_ospf_neighbor(tgen, topo, lan=True)
- assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
+ assert ospf_covergence is True, "Testcase Failed \n Error {}".format(
ospf_covergence
)
@@ -222,7 +222,7 @@ def test_ospf_lan_ecmp_tc18_p0(request):
dut = "r0"
ospf_covergence = verify_ospf_neighbor(tgen, topo, dut=dut, lan=True)
- assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
+ assert ospf_covergence is True, "Testcase Failed \n Error {}".format(
ospf_covergence
)
@@ -231,7 +231,7 @@ def test_ospf_lan_ecmp_tc18_p0(request):
dut = "r2"
ospf_covergence = verify_ospf_neighbor(tgen, topo, dut=dut, lan=True)
- assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
+ assert ospf_covergence is True, "Testcase Failed \n Error {}".format(
ospf_covergence
)
@@ -261,7 +261,7 @@ def test_ospf_lan_ecmp_tc18_p0(request):
)
assert (
result is not True
- ), "Testcase {} : Failed \n " "r1: OSPF routes are present \n Error: {}".format(
+ ), "Testcase {} : Failed \n r1: OSPF routes are present \n Error: {}".format(
tc_name, result
)
@@ -278,7 +278,7 @@ def test_ospf_lan_ecmp_tc18_p0(request):
)
assert (
result is not True
- ), "Testcase {} : Failed \n " "r1: routes are still present \n Error: {}".format(
+ ), "Testcase {} : Failed \n r1: routes are still present \n Error: {}".format(
tc_name, result
)
diff --git a/tests/topotests/ospf_basic_functionality/test_ospf_lan.py b/tests/topotests/ospf_basic_functionality/test_ospf_lan.py
index 53b1be6d71..c166702958 100644
--- a/tests/topotests/ospf_basic_functionality/test_ospf_lan.py
+++ b/tests/topotests/ospf_basic_functionality/test_ospf_lan.py
@@ -114,7 +114,7 @@ def setup_module(mod):
pytest.skip(tgen.errors)
# Api call verify whether OSPF is converged
ospf_covergence = verify_ospf_neighbor(tgen, topo, lan=True)
- assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
+ assert ospf_covergence is True, "setup_module :Failed \n Error {}".format(
ospf_covergence
)
@@ -196,9 +196,7 @@ def test_ospf_lan_tc1_p0(request):
result = verify_ospf_neighbor(tgen, topo, dut, input_dict, lan=True)
assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
- step(
- "Configure DR pririty 100 on R0 and clear ospf neighbors " "on all the routers."
- )
+ step("Configure DR pririty 100 on R0 and clear ospf neighbors on all the routers.")
input_dict = {
"r0": {
@@ -234,9 +232,7 @@ def test_ospf_lan_tc1_p0(request):
result = verify_ospf_neighbor(tgen, topo, dut, input_dict, lan=True)
assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
- step(
- "Configure DR pririty 150 on R0 and clear ospf neighbors " "on all the routers."
- )
+ step("Configure DR pririty 150 on R0 and clear ospf neighbors on all the routers.")
input_dict = {
"r0": {
@@ -355,7 +351,7 @@ def test_ospf_lan_tc1_p0(request):
result = verify_ospf_neighbor(tgen, topo, dut, lan=True, expected=False)
assert (
result is not True
- ), "Testcase {} : Failed \n " "r0: OSPF neighbors-hip is up \n Error: {}".format(
+ ), "Testcase {} : Failed \n r0: OSPF neighbors-hip is up \n Error: {}".format(
tc_name, result
)
diff --git a/tests/topotests/ospf_basic_functionality/test_ospf_nssa.py b/tests/topotests/ospf_basic_functionality/test_ospf_nssa.py
index 0c4697cc21..d669e21d4d 100644
--- a/tests/topotests/ospf_basic_functionality/test_ospf_nssa.py
+++ b/tests/topotests/ospf_basic_functionality/test_ospf_nssa.py
@@ -112,7 +112,7 @@ def setup_module(mod):
pytest.skip(tgen.errors)
# Api call verify whether OSPF is converged
ospf_covergence = verify_ospf_neighbor(tgen, topo)
- assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
+ assert ospf_covergence is True, "setup_module :Failed \n Error {}".format(
ospf_covergence
)
@@ -220,11 +220,11 @@ def test_ospf_learning_tc15_p0(request):
assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
ospf_covergence = verify_ospf_neighbor(tgen, topo)
- assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
+ assert ospf_covergence is True, "Testcase Failed \n Error {}".format(
ospf_covergence
)
- step("Change area 1 as non nssa area (on the fly changing area" " type on DUT).")
+ step("Change area 1 as non nssa area (on the fly changing area type on DUT).")
for rtr in ["r1", "r2", "r3"]:
input_dict = {
diff --git a/tests/topotests/ospf_basic_functionality/test_ospf_routemaps.py b/tests/topotests/ospf_basic_functionality/test_ospf_routemaps.py
index dad6d915e8..c9f43cdfe4 100644
--- a/tests/topotests/ospf_basic_functionality/test_ospf_routemaps.py
+++ b/tests/topotests/ospf_basic_functionality/test_ospf_routemaps.py
@@ -127,7 +127,7 @@ def setup_module(mod):
pytest.skip(tgen.errors)
# Api call verify whether OSPF is converged
ospf_covergence = verify_ospf_neighbor(tgen, topo)
- assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
+ assert ospf_covergence is True, "setup_module :Failed \n Error {}".format(
ospf_covergence
)
@@ -201,9 +201,7 @@ def test_ospf_routemaps_functionality_tc19_p0(request):
redistribute_ospf(tgen, topo, "r0", "static", delete=True)
- step(
- "Create prefix-list in R0 to permit 10.0.20.1/32 prefix &" " deny 10.0.20.2/32"
- )
+ step("Create prefix-list in R0 to permit 10.0.20.1/32 prefix & deny 10.0.20.2/32")
# Create ip prefix list
pfx_list = {
@@ -294,7 +292,7 @@ def test_ospf_routemaps_functionality_tc19_p0(request):
result = verify_ospf_rib(tgen, dut, input_dict, expected=False)
assert (
result is not True
- ), "Testcase {} : Failed \n " "r1: OSPF routes are present \n Error: {}".format(
+ ), "Testcase {} : Failed \n r1: OSPF routes are present \n Error: {}".format(
tc_name, result
)
@@ -303,7 +301,7 @@ def test_ospf_routemaps_functionality_tc19_p0(request):
)
assert (
result is not True
- ), "Testcase {} : Failed \n " "r1: routes are present in fib \n Error: {}".format(
+ ), "Testcase {} : Failed \n r1: routes are present in fib \n Error: {}".format(
tc_name, result
)
@@ -347,7 +345,7 @@ def test_ospf_routemaps_functionality_tc19_p0(request):
result = verify_ospf_rib(tgen, dut, input_dict, expected=False)
assert (
result is not True
- ), "Testcase {} : Failed \n " "r1: OSPF routes are present \n Error: {}".format(
+ ), "Testcase {} : Failed \n r1: OSPF routes are present \n Error: {}".format(
tc_name, result
)
@@ -356,7 +354,7 @@ def test_ospf_routemaps_functionality_tc19_p0(request):
)
assert (
result is not True
- ), "Testcase {} : Failed \n " "r1: OSPF routes are present \n Error: {}".format(
+ ), "Testcase {} : Failed \n r1: OSPF routes are present \n Error: {}".format(
tc_name, result
)
@@ -404,7 +402,7 @@ def test_ospf_routemaps_functionality_tc19_p0(request):
result = verify_ospf_rib(tgen, dut, input_dict, expected=False)
assert (
result is not True
- ), "Testcase {} : Failed \n " "r1: OSPF routes are present \n Error: {}".format(
+ ), "Testcase {} : Failed \n r1: OSPF routes are present \n Error: {}".format(
tc_name, result
)
@@ -413,7 +411,7 @@ def test_ospf_routemaps_functionality_tc19_p0(request):
)
assert (
result is not True
- ), "Testcase {} : Failed \n " "r1: routes are still present \n Error: {}".format(
+ ), "Testcase {} : Failed \n r1: routes are still present \n Error: {}".format(
tc_name, result
)
@@ -464,7 +462,7 @@ def test_ospf_routemaps_functionality_tc20_p0(request):
result = verify_ospf_rib(tgen, dut, input_dict, retry_timeout=4, expected=False)
assert (
result is not True
- ), "Testcase {} : Failed \n " "r1: OSPF routes are present \n Error: {}".format(
+ ), "Testcase {} : Failed \n r1: OSPF routes are present \n Error: {}".format(
tc_name, result
)
@@ -479,7 +477,7 @@ def test_ospf_routemaps_functionality_tc20_p0(request):
)
assert (
result is not True
- ), "Testcase {} : Failed \n " "r1: routes are still present \n Error: {}".format(
+ ), "Testcase {} : Failed \n r1: routes are still present \n Error: {}".format(
tc_name, result
)
@@ -499,7 +497,7 @@ def test_ospf_routemaps_functionality_tc20_p0(request):
result = verify_ospf_rib(tgen, dut, input_dict, expected=False)
assert (
result is not True
- ), "Testcase {} : Failed \n " "r1: OSPF routes are present \n Error: {}".format(
+ ), "Testcase {} : Failed \n r1: OSPF routes are present \n Error: {}".format(
tc_name, result
)
@@ -508,7 +506,7 @@ def test_ospf_routemaps_functionality_tc20_p0(request):
)
assert (
result is not True
- ), "Testcase {} : Failed \n " "r1: routes are still present \n Error: {}".format(
+ ), "Testcase {} : Failed \n r1: routes are still present \n Error: {}".format(
tc_name, result
)
@@ -523,7 +521,7 @@ def test_ospf_routemaps_functionality_tc20_p0(request):
result = verify_ospf_rib(tgen, dut, input_dict, expected=False)
assert (
result is not True
- ), "Testcase {} : Failed \n " "r1: OSPF routes are present \n Error: {}".format(
+ ), "Testcase {} : Failed \n r1: OSPF routes are present \n Error: {}".format(
tc_name, result
)
@@ -532,7 +530,7 @@ def test_ospf_routemaps_functionality_tc20_p0(request):
)
assert (
result is not True
- ), "Testcase {} : Failed \n " "r1: routes are still present \n Error: {}".format(
+ ), "Testcase {} : Failed \n r1: routes are still present \n Error: {}".format(
tc_name, result
)
@@ -553,7 +551,7 @@ def test_ospf_routemaps_functionality_tc20_p0(request):
result = verify_ospf_rib(tgen, dut, input_dict, expected=False)
assert (
result is not True
- ), "Testcase {} : Failed \n " "r1: OSPF routes are present \n Error: {}".format(
+ ), "Testcase {} : Failed \n r1: OSPF routes are present \n Error: {}".format(
tc_name, result
)
@@ -562,7 +560,7 @@ def test_ospf_routemaps_functionality_tc20_p0(request):
)
assert (
result is not True
- ), "Testcase {} : Failed \n " "r1: routes are still present \n Error: {}".format(
+ ), "Testcase {} : Failed \n r1: routes are still present \n Error: {}".format(
tc_name, result
)
@@ -861,7 +859,7 @@ def test_ospf_routemaps_functionality_tc24_p0(request):
result = verify_prefix_lists(tgen, pfx_list)
assert (
result is not True
- ), "Testcase {} : Failed \n Prefix list not " "present. Error: {}".format(
+ ), "Testcase {} : Failed \n Prefix list not present. Error: {}".format(
tc_name, result
)
@@ -930,7 +928,7 @@ def test_ospf_routemaps_functionality_tc24_p0(request):
result = verify_prefix_lists(tgen, pfx_list)
assert (
result is not True
- ), "Testcase {} : Failed \n Prefix list not " "present. Error: {}".format(
+ ), "Testcase {} : Failed \n Prefix list not present. Error: {}".format(
tc_name, result
)
@@ -1078,7 +1076,7 @@ def test_ospf_routemaps_functionality_tc25_p0(request):
# Api call verify whether OSPF is converged
ospf_covergence = verify_ospf_neighbor(tgen, topo)
- assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
+ assert ospf_covergence is True, "Testcase Failed \n Error {}".format(
ospf_covergence
)
diff --git a/tests/topotests/ospf_basic_functionality/test_ospf_rte_calc.py b/tests/topotests/ospf_basic_functionality/test_ospf_rte_calc.py
index 63c421ec84..f0950a2db3 100644
--- a/tests/topotests/ospf_basic_functionality/test_ospf_rte_calc.py
+++ b/tests/topotests/ospf_basic_functionality/test_ospf_rte_calc.py
@@ -123,7 +123,7 @@ def setup_module(mod):
pytest.skip(tgen.errors)
# Api call verify whether OSPF is converged
ospf_covergence = verify_ospf_neighbor(tgen, topo)
- assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
+ assert ospf_covergence is True, "setup_module :Failed \n Error {}".format(
ospf_covergence
)
@@ -171,7 +171,7 @@ def test_ospf_redistribution_tc5_p0(request):
step("Verify that OSPF neighbors are FULL.")
ospf_covergence = verify_ospf_neighbor(tgen, topo)
- assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
+ assert ospf_covergence is True, "Testcase Failed \n Error {}".format(
ospf_covergence
)
@@ -295,7 +295,7 @@ def test_ospf_redistribution_tc6_p0(request):
step("Verify that OSPF neighbors are FULL.")
ospf_covergence = verify_ospf_neighbor(tgen, topo)
- assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
+ assert ospf_covergence is True, "Testcase Failed \n Error {}".format(
ospf_covergence
)
@@ -524,7 +524,7 @@ def test_ospf_redistribution_tc8_p1(request):
step("Verify that OSPF neighbours are reset and forms new adjacencies.")
# Api call verify whether OSPF is converged
ospf_covergence = verify_ospf_neighbor(tgen, topo)
- assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
+ assert ospf_covergence is True, "Testcase Failed \n Error {}".format(
ospf_covergence
)
@@ -558,7 +558,7 @@ def test_ospf_rfc2328_appendinxE_p0(request):
step("Verify that OSPF neighbours are Full.")
# Api call verify whether OSPF is converged
ospf_covergence = verify_ospf_neighbor(tgen, topo)
- assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
+ assert ospf_covergence is True, "Testcase Failed \n Error {}".format(
ospf_covergence
)
diff --git a/tests/topotests/ospf_basic_functionality/test_ospf_single_area.py b/tests/topotests/ospf_basic_functionality/test_ospf_single_area.py
index 39bbab42e7..757d6fb1d5 100644
--- a/tests/topotests/ospf_basic_functionality/test_ospf_single_area.py
+++ b/tests/topotests/ospf_basic_functionality/test_ospf_single_area.py
@@ -108,7 +108,7 @@ def setup_module(mod):
pytest.skip(tgen.errors)
ospf_covergence = verify_ospf_neighbor(tgen, topo)
- assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
+ assert ospf_covergence is True, "setup_module :Failed \n Error {}".format(
ospf_covergence
)
@@ -358,7 +358,7 @@ def test_ospf_p2p_tc3_p0(request):
# Api call verify whether BGP is converged
ospf_covergence = verify_ospf_neighbor(tgen, topo)
- assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
+ assert ospf_covergence is True, "Testcase Failed \n Error {}".format(
ospf_covergence
)
@@ -440,7 +440,7 @@ def test_ospf_hello_tc10_p0(request):
step("verify that ospf neighbours are full")
ospf_covergence = verify_ospf_neighbor(tgen, topo, dut=dut)
- assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
+ assert ospf_covergence is True, "Testcase Failed \n Error {}".format(
ospf_covergence
)
@@ -486,7 +486,7 @@ def test_ospf_hello_tc10_p0(request):
step("verify that ospf neighbours are full")
ospf_covergence = verify_ospf_neighbor(tgen, topo, dut=dut)
- assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
+ assert ospf_covergence is True, "Testcase Failed \n Error {}".format(
ospf_covergence
)
@@ -532,7 +532,7 @@ def test_ospf_hello_tc10_p0(request):
step("verify that ospf neighbours are full")
ospf_covergence = verify_ospf_neighbor(tgen, topo, dut=dut)
- assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
+ assert ospf_covergence is True, "Testcase Failed \n Error {}".format(
ospf_covergence
)
@@ -575,7 +575,7 @@ def test_ospf_hello_tc10_p0(request):
step("verify that ospf neighbours are full")
ospf_covergence = verify_ospf_neighbor(tgen, topo, dut=dut)
- assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
+ assert ospf_covergence is True, "Testcase Failed \n Error {}".format(
ospf_covergence
)
@@ -597,7 +597,7 @@ def test_ospf_show_p1(request):
reset_config_on_routers(tgen)
ospf_covergence = verify_ospf_neighbor(tgen, topo)
- assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
+ assert ospf_covergence is True, "Testcase Failed \n Error {}".format(
ospf_covergence
)
dut = "r1"
@@ -690,7 +690,7 @@ def test_ospf_dead_tc11_p0(request):
result = verify_ospf_interface(tgen, topo, dut=dut, input_dict=input_dict)
assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
- step("modify dead interval from default value to r1" "dead interval timer on r2")
+ step("modify dead interval from default value to r1 dead interval timer on r2")
topo1 = {
"r0": {
@@ -714,11 +714,11 @@ def test_ospf_dead_tc11_p0(request):
step("verify that ospf neighbours are full")
ospf_covergence = verify_ospf_neighbor(tgen, topo, dut=dut)
- assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
+ assert ospf_covergence is True, "Testcase Failed \n Error {}".format(
ospf_covergence
)
- step("reconfigure the default dead interval timer value to " "default on r1 and r2")
+ step("reconfigure the default dead interval timer value to default on r1 and r2")
topo1 = {
"r0": {
"links": {
@@ -755,7 +755,7 @@ def test_ospf_dead_tc11_p0(request):
step("verify that ospf neighbours are full")
ospf_covergence = verify_ospf_neighbor(tgen, topo, dut=dut)
- assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
+ assert ospf_covergence is True, "Testcase Failed \n Error {}".format(
ospf_covergence
)
@@ -797,7 +797,7 @@ def test_ospf_dead_tc11_p0(request):
step("verify that ospf neighbours are full")
ospf_covergence = verify_ospf_neighbor(tgen, topo, dut=dut)
- assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
+ assert ospf_covergence is True, "Testcase Failed \n Error {}".format(
ospf_covergence
)
@@ -835,9 +835,7 @@ def test_ospf_dead_tc11_p0(request):
result = create_interfaces_cfg(tgen, topo1)
assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
- step(
- "Verify that timer value is deleted from intf & " "set to default value 40 sec."
- )
+ step("Verify that timer value is deleted from intf & set to default value 40 sec.")
input_dict = {"r1": {"links": {"r0": {"ospf": {"timerDeadSecs": 40}}}}}
dut = "r1"
result = verify_ospf_interface(tgen, topo, dut=dut, input_dict=input_dict)
@@ -883,18 +881,14 @@ def test_ospf_tc4_mtu_ignore_p0(request):
clear_ospf(tgen, "r0")
- step(
- "Verify that OSPF neighborship between R0 and R1 is stuck in Exstart" " State."
- )
+ step("Verify that OSPF neighborship between R0 and R1 is stuck in Exstart State.")
result = verify_ospf_neighbor(tgen, topo, expected=False)
assert result is not True, (
"Testcase {} : Failed \n OSPF nbrs are Full "
"instead of Exstart. Error: {}".format(tc_name, result)
)
- step(
- "Verify that configured MTU value is updated in the show ip " "ospf interface."
- )
+ step("Verify that configured MTU value is updated in the show ip ospf interface.")
dut = "r0"
input_dict = {"r0": {"links": {"r1": {"ospf": {"mtuBytes": 1200}}}}}
@@ -951,9 +945,7 @@ def test_ospf_tc4_mtu_ignore_p0(request):
clear_ospf(tgen, "r0")
- step(
- "Verify that OSPF neighborship between R0 and R1 is stuck in Exstart" " State."
- )
+ step("Verify that OSPF neighborship between R0 and R1 is stuck in Exstart State.")
result = verify_ospf_neighbor(tgen, topo, expected=False)
assert result is not True, (
"Testcase {} : Failed \n OSPF nbrs are Full "
@@ -970,9 +962,7 @@ def test_ospf_tc4_mtu_ignore_p0(request):
result = verify_ospf_neighbor(tgen, topo)
assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
- step(
- "Configure ospf interface with jumbo MTU (9216)." "Reset ospf neighbors on R0."
- )
+ step("Configure ospf interface with jumbo MTU (9216). Reset ospf neighbors on R0.")
rtr0.run("ip link set {} mtu 9216".format(r0_r1_intf))
rtr1.run("ip link set {} mtu 9216".format(r1_r0_intf))
diff --git a/tests/topotests/ospf_gr_helper/test_ospf_gr_helper1.py b/tests/topotests/ospf_gr_helper/test_ospf_gr_helper1.py
index 1c26596230..9dce5a976d 100644
--- a/tests/topotests/ospf_gr_helper/test_ospf_gr_helper1.py
+++ b/tests/topotests/ospf_gr_helper/test_ospf_gr_helper1.py
@@ -119,7 +119,7 @@ def setup_module(mod):
pytest.skip(tgen.errors)
ospf_covergence = verify_ospf_neighbor(tgen, topo, lan=True)
- assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
+ assert ospf_covergence is True, "setup_module :Failed \n Error: {}".format(
ospf_covergence
)
@@ -182,9 +182,9 @@ def test_ospf_gr_helper_tc1_p0(request):
ospf_covergence = verify_ospf_neighbor(tgen, topo, lan=True)
assert (
ospf_covergence is True
- ), "OSPF is not after reset config \n Error:" " {}".format(ospf_covergence)
+ ), "OSPF is not after reset config \n Error: {}".format(ospf_covergence)
- step("Verify that GR helper route is disabled by default to the in" "the DUT.")
+ step("Verify that GR helper route is disabled by default to the in the DUT.")
input_dict = {
"helperSupport": "Disabled",
"strictLsaCheck": "Enabled",
@@ -195,7 +195,7 @@ def test_ospf_gr_helper_tc1_p0(request):
result = verify_ospf_gr_helper(tgen, topo, dut, input_dict)
assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
- step("Verify that DUT does not enter helper mode upon receiving the " "grace lsa.")
+ step("Verify that DUT does not enter helper mode upon receiving the grace lsa.")
# send grace lsa
scapy_send_raw_packet(tgen, topo, "r1", intf1, pkt)
@@ -205,7 +205,7 @@ def test_ospf_gr_helper_tc1_p0(request):
result = verify_ospf_gr_helper(tgen, topo, dut, input_dict, expected=False)
assert (
result is not True
- ), "Testcase {} : Failed. DUT entered helper role " " \n Error: {}".format(
+ ), "Testcase {} : Failed. DUT entered helper role \n Error: {}".format(
tc_name, result
)
@@ -234,7 +234,7 @@ def test_ospf_gr_helper_tc1_p0(request):
assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
step("Perform GR in RR.")
- step("Verify that DUT does enter helper mode upon receiving" " the grace lsa.")
+ step("Verify that DUT does enter helper mode upon receiving the grace lsa.")
input_dict = {"activeRestarterCnt": 1}
gracelsa_sent = False
repeat = 0
@@ -277,7 +277,7 @@ def test_ospf_gr_helper_tc1_p0(request):
result = create_router_ospf(tgen, topo, ospf_gr_r0)
assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
- step("Verify that DUT does enter helper mode upon receiving" " the grace lsa.")
+ step("Verify that DUT does enter helper mode upon receiving the grace lsa.")
input_dict = {"activeRestarterCnt": 1}
gracelsa_sent = False
repeat = 0
@@ -306,7 +306,7 @@ def test_ospf_gr_helper_tc1_p0(request):
result = create_router_ospf(tgen, topo, ospf_gr_r0)
assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
- step("Verify that GR helper router is disabled in the DUT for" " router id x.x.x.x")
+ step("Verify that GR helper router is disabled in the DUT for router id x.x.x.x")
input_dict = {"enabledRouterIds": [{"routerId": "1.1.1.1"}]}
dut = "r0"
result = verify_ospf_gr_helper(tgen, topo, dut, input_dict, expected=False)
@@ -343,7 +343,7 @@ def test_ospf_gr_helper_tc2_p0(request):
ospf_covergence = verify_ospf_neighbor(tgen, topo, lan=True)
assert (
ospf_covergence is True
- ), "OSPF is not after reset config \n Error:" " {}".format(ospf_covergence)
+ ), "OSPF is not after reset config \n Error: {}".format(ospf_covergence)
ospf_gr_r0 = {
"r0": {"ospf": {"graceful-restart": {"helper enable": [], "opaque": True}}}
}
diff --git a/tests/topotests/ospf_gr_helper/test_ospf_gr_helper2.py b/tests/topotests/ospf_gr_helper/test_ospf_gr_helper2.py
index a3ccb58d38..202afe5485 100644
--- a/tests/topotests/ospf_gr_helper/test_ospf_gr_helper2.py
+++ b/tests/topotests/ospf_gr_helper/test_ospf_gr_helper2.py
@@ -119,7 +119,7 @@ def setup_module(mod):
pytest.skip(tgen.errors)
ospf_covergence = verify_ospf_neighbor(tgen, topo, lan=True)
- assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
+ assert ospf_covergence is True, "setup_module :Failed \n Error: {}".format(
ospf_covergence
)
@@ -188,10 +188,8 @@ def test_ospf_gr_helper_tc3_p1(request):
ospf_covergence = verify_ospf_neighbor(tgen, topo, lan=True)
assert (
ospf_covergence is True
- ), "OSPF is not after reset config \n Error:" " {}".format(ospf_covergence)
- step(
- "Configure DR pririty 100 on R0 and clear ospf neighbors " "on all the routers."
- )
+ ), "OSPF is not after reset config \n Error: {}".format(ospf_covergence)
+ step("Configure DR pririty 100 on R0 and clear ospf neighbors on all the routers.")
input_dict = {
"r0": {
@@ -282,10 +280,8 @@ def test_ospf_gr_helper_tc4_p1(request):
ospf_covergence = verify_ospf_neighbor(tgen, topo, lan=True)
assert (
ospf_covergence is True
- ), "OSPF is not after reset config \n Error:" " {}".format(ospf_covergence)
- step(
- "Configure DR pririty 100 on R0 and clear ospf neighbors " "on all the routers."
- )
+ ), "OSPF is not after reset config \n Error: {}".format(ospf_covergence)
+ step("Configure DR pririty 100 on R0 and clear ospf neighbors on all the routers.")
input_dict = {
"r0": {
diff --git a/tests/topotests/ospf_gr_helper/test_ospf_gr_helper3.py b/tests/topotests/ospf_gr_helper/test_ospf_gr_helper3.py
index 64aac2fba8..3be28196d8 100644
--- a/tests/topotests/ospf_gr_helper/test_ospf_gr_helper3.py
+++ b/tests/topotests/ospf_gr_helper/test_ospf_gr_helper3.py
@@ -119,7 +119,7 @@ def setup_module(mod):
pytest.skip(tgen.errors)
ospf_covergence = verify_ospf_neighbor(tgen, topo, lan=True)
- assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
+ assert ospf_covergence is True, "setup_module :Failed \n Error: {}".format(
ospf_covergence
)
@@ -193,7 +193,7 @@ def test_ospf_gr_helper_tc7_p1(request):
ospf_covergence = verify_ospf_neighbor(tgen, topo, lan=True)
assert (
ospf_covergence is True
- ), "OSPF is not after reset config \n Error:" " {}".format(ospf_covergence)
+ ), "OSPF is not after reset config \n Error: {}".format(ospf_covergence)
ospf_gr_r0 = {
"r0": {"ospf": {"graceful-restart": {"helper enable": [], "opaque": True}}}
}
@@ -221,7 +221,7 @@ def test_ospf_gr_helper_tc7_p1(request):
result = verify_ospf_gr_helper(tgen, topo, dut, input_dict, expected=False)
assert (
result is not True
- ), "Testcase {} : Failed. DUT entered helper role " " \n Error: {}".format(
+ ), "Testcase {} : Failed. DUT entered helper role \n Error: {}".format(
tc_name, result
)
@@ -253,7 +253,7 @@ def test_ospf_gr_helper_tc8_p1(request):
ospf_covergence = verify_ospf_neighbor(tgen, topo, lan=True)
assert (
ospf_covergence is True
- ), "OSPF is not after reset config \n Error:" " {}".format(ospf_covergence)
+ ), "OSPF is not after reset config \n Error: {}".format(ospf_covergence)
ospf_gr_r0 = {
"r0": {"ospf": {"graceful-restart": {"helper enable": [], "opaque": True}}}
}
diff --git a/tests/topotests/ospf_nssa_topo1/__init__.py b/tests/topotests/ospf_nssa_topo1/__init__.py
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/tests/topotests/ospf_nssa_topo1/__init__.py
diff --git a/tests/topotests/ospf_nssa_topo1/rt1/ospfd.conf b/tests/topotests/ospf_nssa_topo1/rt1/ospfd.conf
new file mode 100644
index 0000000000..6d23c84806
--- /dev/null
+++ b/tests/topotests/ospf_nssa_topo1/rt1/ospfd.conf
@@ -0,0 +1,22 @@
+password 1
+hostname rt1
+log file ospfd.log
+!
+! debug ospf sr
+! debug ospf te
+! debug ospf event
+! debug ospf lsa
+! debug ospf zebra
+!
+interface lo
+ ip ospf area 0
+!
+interface eth-rt2
+ ip ospf network point-to-point
+ ip ospf area 0
+ ip ospf hello-interval 3
+ ip ospf dead-interval 12
+!
+router ospf
+ router-id 1.1.1.1
+!
diff --git a/tests/topotests/ospf_nssa_topo1/rt1/staticd.conf b/tests/topotests/ospf_nssa_topo1/rt1/staticd.conf
new file mode 100644
index 0000000000..7ba3dc7591
--- /dev/null
+++ b/tests/topotests/ospf_nssa_topo1/rt1/staticd.conf
@@ -0,0 +1,6 @@
+log file staticd.log
+!
+hostname rt1
+!
+line vty
+!
diff --git a/tests/topotests/ospf_nssa_topo1/rt1/step1/show_ip_ospf_route.ref b/tests/topotests/ospf_nssa_topo1/rt1/step1/show_ip_ospf_route.ref
new file mode 100644
index 0000000000..ac34417bda
--- /dev/null
+++ b/tests/topotests/ospf_nssa_topo1/rt1/step1/show_ip_ospf_route.ref
@@ -0,0 +1,115 @@
+{
+ "1.1.1.1\/32":{
+ "routeType":"N",
+ "cost":0,
+ "area":"0.0.0.0",
+ "nexthops":[
+ {
+ "ip":" ",
+ "directlyAttachedTo":"lo"
+ }
+ ]
+ },
+ "2.2.2.2\/32":{
+ "routeType":"N",
+ "cost":10,
+ "area":"0.0.0.0",
+ "nexthops":[
+ {
+ "ip":"10.0.1.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "3.3.3.3\/32":{
+ "routeType":"N IA",
+ "cost":20,
+ "area":"0.0.0.0",
+ "nexthops":[
+ {
+ "ip":"10.0.1.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "4.4.4.4\/32":{
+ "routeType":"N IA",
+ "cost":20,
+ "area":"0.0.0.0",
+ "nexthops":[
+ {
+ "ip":"10.0.1.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "10.0.1.0\/24":{
+ "routeType":"N",
+ "cost":10,
+ "area":"0.0.0.0",
+ "nexthops":[
+ {
+ "ip":" ",
+ "directlyAttachedTo":"eth-rt2"
+ }
+ ]
+ },
+ "10.0.2.0\/24":{
+ "routeType":"N IA",
+ "cost":20,
+ "area":"0.0.0.0",
+ "nexthops":[
+ {
+ "ip":"10.0.1.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "10.0.3.0\/24":{
+ "routeType":"N IA",
+ "cost":20,
+ "area":"0.0.0.0",
+ "nexthops":[
+ {
+ "ip":"10.0.1.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "2.2.2.2":{
+ "routeType":"R ",
+ "cost":10,
+ "area":"0.0.0.0",
+ "routerType":"abr",
+ "nexthops":[
+ {
+ "ip":"10.0.1.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "172.16.1.1\/32":{
+ "routeType":"N E2",
+ "cost":20,
+ "type2cost":20,
+ "tag":0,
+ "nexthops":[
+ {
+ "ip":"10.0.1.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "172.16.1.2\/32":{
+ "routeType":"N E2",
+ "cost":20,
+ "type2cost":20,
+ "tag":0,
+ "nexthops":[
+ {
+ "ip":"10.0.1.2",
+ "via":"eth-rt2"
+ }
+ ]
+ }
+}
diff --git a/tests/topotests/ospf_nssa_topo1/rt1/step10/show_ip_ospf_route.ref b/tests/topotests/ospf_nssa_topo1/rt1/step10/show_ip_ospf_route.ref
new file mode 100644
index 0000000000..ac34417bda
--- /dev/null
+++ b/tests/topotests/ospf_nssa_topo1/rt1/step10/show_ip_ospf_route.ref
@@ -0,0 +1,115 @@
+{
+ "1.1.1.1\/32":{
+ "routeType":"N",
+ "cost":0,
+ "area":"0.0.0.0",
+ "nexthops":[
+ {
+ "ip":" ",
+ "directlyAttachedTo":"lo"
+ }
+ ]
+ },
+ "2.2.2.2\/32":{
+ "routeType":"N",
+ "cost":10,
+ "area":"0.0.0.0",
+ "nexthops":[
+ {
+ "ip":"10.0.1.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "3.3.3.3\/32":{
+ "routeType":"N IA",
+ "cost":20,
+ "area":"0.0.0.0",
+ "nexthops":[
+ {
+ "ip":"10.0.1.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "4.4.4.4\/32":{
+ "routeType":"N IA",
+ "cost":20,
+ "area":"0.0.0.0",
+ "nexthops":[
+ {
+ "ip":"10.0.1.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "10.0.1.0\/24":{
+ "routeType":"N",
+ "cost":10,
+ "area":"0.0.0.0",
+ "nexthops":[
+ {
+ "ip":" ",
+ "directlyAttachedTo":"eth-rt2"
+ }
+ ]
+ },
+ "10.0.2.0\/24":{
+ "routeType":"N IA",
+ "cost":20,
+ "area":"0.0.0.0",
+ "nexthops":[
+ {
+ "ip":"10.0.1.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "10.0.3.0\/24":{
+ "routeType":"N IA",
+ "cost":20,
+ "area":"0.0.0.0",
+ "nexthops":[
+ {
+ "ip":"10.0.1.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "2.2.2.2":{
+ "routeType":"R ",
+ "cost":10,
+ "area":"0.0.0.0",
+ "routerType":"abr",
+ "nexthops":[
+ {
+ "ip":"10.0.1.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "172.16.1.1\/32":{
+ "routeType":"N E2",
+ "cost":20,
+ "type2cost":20,
+ "tag":0,
+ "nexthops":[
+ {
+ "ip":"10.0.1.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "172.16.1.2\/32":{
+ "routeType":"N E2",
+ "cost":20,
+ "type2cost":20,
+ "tag":0,
+ "nexthops":[
+ {
+ "ip":"10.0.1.2",
+ "via":"eth-rt2"
+ }
+ ]
+ }
+}
diff --git a/tests/topotests/ospf_nssa_topo1/rt1/step2/show_ip_ospf_route.ref b/tests/topotests/ospf_nssa_topo1/rt1/step2/show_ip_ospf_route.ref
new file mode 100644
index 0000000000..ac34417bda
--- /dev/null
+++ b/tests/topotests/ospf_nssa_topo1/rt1/step2/show_ip_ospf_route.ref
@@ -0,0 +1,115 @@
+{
+ "1.1.1.1\/32":{
+ "routeType":"N",
+ "cost":0,
+ "area":"0.0.0.0",
+ "nexthops":[
+ {
+ "ip":" ",
+ "directlyAttachedTo":"lo"
+ }
+ ]
+ },
+ "2.2.2.2\/32":{
+ "routeType":"N",
+ "cost":10,
+ "area":"0.0.0.0",
+ "nexthops":[
+ {
+ "ip":"10.0.1.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "3.3.3.3\/32":{
+ "routeType":"N IA",
+ "cost":20,
+ "area":"0.0.0.0",
+ "nexthops":[
+ {
+ "ip":"10.0.1.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "4.4.4.4\/32":{
+ "routeType":"N IA",
+ "cost":20,
+ "area":"0.0.0.0",
+ "nexthops":[
+ {
+ "ip":"10.0.1.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "10.0.1.0\/24":{
+ "routeType":"N",
+ "cost":10,
+ "area":"0.0.0.0",
+ "nexthops":[
+ {
+ "ip":" ",
+ "directlyAttachedTo":"eth-rt2"
+ }
+ ]
+ },
+ "10.0.2.0\/24":{
+ "routeType":"N IA",
+ "cost":20,
+ "area":"0.0.0.0",
+ "nexthops":[
+ {
+ "ip":"10.0.1.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "10.0.3.0\/24":{
+ "routeType":"N IA",
+ "cost":20,
+ "area":"0.0.0.0",
+ "nexthops":[
+ {
+ "ip":"10.0.1.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "2.2.2.2":{
+ "routeType":"R ",
+ "cost":10,
+ "area":"0.0.0.0",
+ "routerType":"abr",
+ "nexthops":[
+ {
+ "ip":"10.0.1.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "172.16.1.1\/32":{
+ "routeType":"N E2",
+ "cost":20,
+ "type2cost":20,
+ "tag":0,
+ "nexthops":[
+ {
+ "ip":"10.0.1.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "172.16.1.2\/32":{
+ "routeType":"N E2",
+ "cost":20,
+ "type2cost":20,
+ "tag":0,
+ "nexthops":[
+ {
+ "ip":"10.0.1.2",
+ "via":"eth-rt2"
+ }
+ ]
+ }
+}
diff --git a/tests/topotests/ospf_nssa_topo1/rt1/step3/show_ip_ospf_route.ref b/tests/topotests/ospf_nssa_topo1/rt1/step3/show_ip_ospf_route.ref
new file mode 100644
index 0000000000..ac34417bda
--- /dev/null
+++ b/tests/topotests/ospf_nssa_topo1/rt1/step3/show_ip_ospf_route.ref
@@ -0,0 +1,115 @@
+{
+ "1.1.1.1\/32":{
+ "routeType":"N",
+ "cost":0,
+ "area":"0.0.0.0",
+ "nexthops":[
+ {
+ "ip":" ",
+ "directlyAttachedTo":"lo"
+ }
+ ]
+ },
+ "2.2.2.2\/32":{
+ "routeType":"N",
+ "cost":10,
+ "area":"0.0.0.0",
+ "nexthops":[
+ {
+ "ip":"10.0.1.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "3.3.3.3\/32":{
+ "routeType":"N IA",
+ "cost":20,
+ "area":"0.0.0.0",
+ "nexthops":[
+ {
+ "ip":"10.0.1.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "4.4.4.4\/32":{
+ "routeType":"N IA",
+ "cost":20,
+ "area":"0.0.0.0",
+ "nexthops":[
+ {
+ "ip":"10.0.1.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "10.0.1.0\/24":{
+ "routeType":"N",
+ "cost":10,
+ "area":"0.0.0.0",
+ "nexthops":[
+ {
+ "ip":" ",
+ "directlyAttachedTo":"eth-rt2"
+ }
+ ]
+ },
+ "10.0.2.0\/24":{
+ "routeType":"N IA",
+ "cost":20,
+ "area":"0.0.0.0",
+ "nexthops":[
+ {
+ "ip":"10.0.1.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "10.0.3.0\/24":{
+ "routeType":"N IA",
+ "cost":20,
+ "area":"0.0.0.0",
+ "nexthops":[
+ {
+ "ip":"10.0.1.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "2.2.2.2":{
+ "routeType":"R ",
+ "cost":10,
+ "area":"0.0.0.0",
+ "routerType":"abr",
+ "nexthops":[
+ {
+ "ip":"10.0.1.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "172.16.1.1\/32":{
+ "routeType":"N E2",
+ "cost":20,
+ "type2cost":20,
+ "tag":0,
+ "nexthops":[
+ {
+ "ip":"10.0.1.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "172.16.1.2\/32":{
+ "routeType":"N E2",
+ "cost":20,
+ "type2cost":20,
+ "tag":0,
+ "nexthops":[
+ {
+ "ip":"10.0.1.2",
+ "via":"eth-rt2"
+ }
+ ]
+ }
+}
diff --git a/tests/topotests/ospf_nssa_topo1/rt1/step4/show_ip_ospf_route.ref b/tests/topotests/ospf_nssa_topo1/rt1/step4/show_ip_ospf_route.ref
new file mode 100644
index 0000000000..6a05555eec
--- /dev/null
+++ b/tests/topotests/ospf_nssa_topo1/rt1/step4/show_ip_ospf_route.ref
@@ -0,0 +1,103 @@
+{
+ "1.1.1.1\/32":{
+ "routeType":"N",
+ "cost":0,
+ "area":"0.0.0.0",
+ "nexthops":[
+ {
+ "ip":" ",
+ "directlyAttachedTo":"lo"
+ }
+ ]
+ },
+ "2.2.2.2\/32":{
+ "routeType":"N",
+ "cost":10,
+ "area":"0.0.0.0",
+ "nexthops":[
+ {
+ "ip":"10.0.1.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "3.3.3.3\/32":{
+ "routeType":"N IA",
+ "cost":20,
+ "area":"0.0.0.0",
+ "nexthops":[
+ {
+ "ip":"10.0.1.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "4.4.4.4\/32":{
+ "routeType":"N IA",
+ "cost":20,
+ "area":"0.0.0.0",
+ "nexthops":[
+ {
+ "ip":"10.0.1.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "10.0.1.0\/24":{
+ "routeType":"N",
+ "cost":10,
+ "area":"0.0.0.0",
+ "nexthops":[
+ {
+ "ip":" ",
+ "directlyAttachedTo":"eth-rt2"
+ }
+ ]
+ },
+ "10.0.2.0\/24":{
+ "routeType":"N IA",
+ "cost":20,
+ "area":"0.0.0.0",
+ "nexthops":[
+ {
+ "ip":"10.0.1.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "10.0.3.0\/24":{
+ "routeType":"N IA",
+ "cost":20,
+ "area":"0.0.0.0",
+ "nexthops":[
+ {
+ "ip":"10.0.1.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "2.2.2.2":{
+ "routeType":"R ",
+ "cost":10,
+ "area":"0.0.0.0",
+ "routerType":"abr",
+ "nexthops":[
+ {
+ "ip":"10.0.1.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "172.16.1.0\/24":{
+ "routeType":"N E2",
+ "cost":10,
+ "type2cost":20,
+ "tag":0,
+ "nexthops":[
+ {
+ "ip":"10.0.1.2",
+ "via":"eth-rt2"
+ }
+ ]
+ }
+}
diff --git a/tests/topotests/ospf_nssa_topo1/rt1/step5/show_ip_ospf_route.ref b/tests/topotests/ospf_nssa_topo1/rt1/step5/show_ip_ospf_route.ref
new file mode 100644
index 0000000000..6a05555eec
--- /dev/null
+++ b/tests/topotests/ospf_nssa_topo1/rt1/step5/show_ip_ospf_route.ref
@@ -0,0 +1,103 @@
+{
+ "1.1.1.1\/32":{
+ "routeType":"N",
+ "cost":0,
+ "area":"0.0.0.0",
+ "nexthops":[
+ {
+ "ip":" ",
+ "directlyAttachedTo":"lo"
+ }
+ ]
+ },
+ "2.2.2.2\/32":{
+ "routeType":"N",
+ "cost":10,
+ "area":"0.0.0.0",
+ "nexthops":[
+ {
+ "ip":"10.0.1.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "3.3.3.3\/32":{
+ "routeType":"N IA",
+ "cost":20,
+ "area":"0.0.0.0",
+ "nexthops":[
+ {
+ "ip":"10.0.1.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "4.4.4.4\/32":{
+ "routeType":"N IA",
+ "cost":20,
+ "area":"0.0.0.0",
+ "nexthops":[
+ {
+ "ip":"10.0.1.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "10.0.1.0\/24":{
+ "routeType":"N",
+ "cost":10,
+ "area":"0.0.0.0",
+ "nexthops":[
+ {
+ "ip":" ",
+ "directlyAttachedTo":"eth-rt2"
+ }
+ ]
+ },
+ "10.0.2.0\/24":{
+ "routeType":"N IA",
+ "cost":20,
+ "area":"0.0.0.0",
+ "nexthops":[
+ {
+ "ip":"10.0.1.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "10.0.3.0\/24":{
+ "routeType":"N IA",
+ "cost":20,
+ "area":"0.0.0.0",
+ "nexthops":[
+ {
+ "ip":"10.0.1.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "2.2.2.2":{
+ "routeType":"R ",
+ "cost":10,
+ "area":"0.0.0.0",
+ "routerType":"abr",
+ "nexthops":[
+ {
+ "ip":"10.0.1.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "172.16.1.0\/24":{
+ "routeType":"N E2",
+ "cost":10,
+ "type2cost":20,
+ "tag":0,
+ "nexthops":[
+ {
+ "ip":"10.0.1.2",
+ "via":"eth-rt2"
+ }
+ ]
+ }
+}
diff --git a/tests/topotests/ospf_nssa_topo1/rt1/step6/show_ip_ospf_route.ref b/tests/topotests/ospf_nssa_topo1/rt1/step6/show_ip_ospf_route.ref
new file mode 100644
index 0000000000..2d3c8c485f
--- /dev/null
+++ b/tests/topotests/ospf_nssa_topo1/rt1/step6/show_ip_ospf_route.ref
@@ -0,0 +1,91 @@
+{
+ "1.1.1.1\/32":{
+ "routeType":"N",
+ "cost":0,
+ "area":"0.0.0.0",
+ "nexthops":[
+ {
+ "ip":" ",
+ "directlyAttachedTo":"lo"
+ }
+ ]
+ },
+ "2.2.2.2\/32":{
+ "routeType":"N",
+ "cost":10,
+ "area":"0.0.0.0",
+ "nexthops":[
+ {
+ "ip":"10.0.1.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "3.3.3.3\/32":{
+ "routeType":"N IA",
+ "cost":20,
+ "area":"0.0.0.0",
+ "nexthops":[
+ {
+ "ip":"10.0.1.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "4.4.4.4\/32":{
+ "routeType":"N IA",
+ "cost":20,
+ "area":"0.0.0.0",
+ "nexthops":[
+ {
+ "ip":"10.0.1.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "10.0.1.0\/24":{
+ "routeType":"N",
+ "cost":10,
+ "area":"0.0.0.0",
+ "nexthops":[
+ {
+ "ip":" ",
+ "directlyAttachedTo":"eth-rt2"
+ }
+ ]
+ },
+ "10.0.2.0\/24":{
+ "routeType":"N IA",
+ "cost":20,
+ "area":"0.0.0.0",
+ "nexthops":[
+ {
+ "ip":"10.0.1.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "10.0.3.0\/24":{
+ "routeType":"N IA",
+ "cost":20,
+ "area":"0.0.0.0",
+ "nexthops":[
+ {
+ "ip":"10.0.1.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "2.2.2.2":{
+ "routeType":"R ",
+ "cost":10,
+ "area":"0.0.0.0",
+ "routerType":"abr",
+ "nexthops":[
+ {
+ "ip":"10.0.1.2",
+ "via":"eth-rt2"
+ }
+ ]
+ }
+}
diff --git a/tests/topotests/ospf_nssa_topo1/rt1/step7/show_ip_ospf_route.ref b/tests/topotests/ospf_nssa_topo1/rt1/step7/show_ip_ospf_route.ref
new file mode 100644
index 0000000000..6a05555eec
--- /dev/null
+++ b/tests/topotests/ospf_nssa_topo1/rt1/step7/show_ip_ospf_route.ref
@@ -0,0 +1,103 @@
+{
+ "1.1.1.1\/32":{
+ "routeType":"N",
+ "cost":0,
+ "area":"0.0.0.0",
+ "nexthops":[
+ {
+ "ip":" ",
+ "directlyAttachedTo":"lo"
+ }
+ ]
+ },
+ "2.2.2.2\/32":{
+ "routeType":"N",
+ "cost":10,
+ "area":"0.0.0.0",
+ "nexthops":[
+ {
+ "ip":"10.0.1.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "3.3.3.3\/32":{
+ "routeType":"N IA",
+ "cost":20,
+ "area":"0.0.0.0",
+ "nexthops":[
+ {
+ "ip":"10.0.1.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "4.4.4.4\/32":{
+ "routeType":"N IA",
+ "cost":20,
+ "area":"0.0.0.0",
+ "nexthops":[
+ {
+ "ip":"10.0.1.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "10.0.1.0\/24":{
+ "routeType":"N",
+ "cost":10,
+ "area":"0.0.0.0",
+ "nexthops":[
+ {
+ "ip":" ",
+ "directlyAttachedTo":"eth-rt2"
+ }
+ ]
+ },
+ "10.0.2.0\/24":{
+ "routeType":"N IA",
+ "cost":20,
+ "area":"0.0.0.0",
+ "nexthops":[
+ {
+ "ip":"10.0.1.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "10.0.3.0\/24":{
+ "routeType":"N IA",
+ "cost":20,
+ "area":"0.0.0.0",
+ "nexthops":[
+ {
+ "ip":"10.0.1.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "2.2.2.2":{
+ "routeType":"R ",
+ "cost":10,
+ "area":"0.0.0.0",
+ "routerType":"abr",
+ "nexthops":[
+ {
+ "ip":"10.0.1.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "172.16.1.0\/24":{
+ "routeType":"N E2",
+ "cost":10,
+ "type2cost":20,
+ "tag":0,
+ "nexthops":[
+ {
+ "ip":"10.0.1.2",
+ "via":"eth-rt2"
+ }
+ ]
+ }
+}
diff --git a/tests/topotests/ospf_nssa_topo1/rt1/step8/show_ip_ospf_route.ref b/tests/topotests/ospf_nssa_topo1/rt1/step8/show_ip_ospf_route.ref
new file mode 100644
index 0000000000..f41ee3b698
--- /dev/null
+++ b/tests/topotests/ospf_nssa_topo1/rt1/step8/show_ip_ospf_route.ref
@@ -0,0 +1,103 @@
+{
+ "1.1.1.1\/32":{
+ "routeType":"N",
+ "cost":0,
+ "area":"0.0.0.0",
+ "nexthops":[
+ {
+ "ip":" ",
+ "directlyAttachedTo":"lo"
+ }
+ ]
+ },
+ "2.2.2.2\/32":{
+ "routeType":"N",
+ "cost":10,
+ "area":"0.0.0.0",
+ "nexthops":[
+ {
+ "ip":"10.0.1.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "3.3.3.3\/32":{
+ "routeType":"N IA",
+ "cost":20,
+ "area":"0.0.0.0",
+ "nexthops":[
+ {
+ "ip":"10.0.1.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "4.4.4.4\/32":{
+ "routeType":"N IA",
+ "cost":20,
+ "area":"0.0.0.0",
+ "nexthops":[
+ {
+ "ip":"10.0.1.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "10.0.1.0\/24":{
+ "routeType":"N",
+ "cost":10,
+ "area":"0.0.0.0",
+ "nexthops":[
+ {
+ "ip":" ",
+ "directlyAttachedTo":"eth-rt2"
+ }
+ ]
+ },
+ "10.0.2.0\/24":{
+ "routeType":"N IA",
+ "cost":20,
+ "area":"0.0.0.0",
+ "nexthops":[
+ {
+ "ip":"10.0.1.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "10.0.3.0\/24":{
+ "routeType":"N IA",
+ "cost":20,
+ "area":"0.0.0.0",
+ "nexthops":[
+ {
+ "ip":"10.0.1.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "2.2.2.2":{
+ "routeType":"R ",
+ "cost":10,
+ "area":"0.0.0.0",
+ "routerType":"abr",
+ "nexthops":[
+ {
+ "ip":"10.0.1.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "172.16.1.0\/24":{
+ "routeType":"N E2",
+ "cost":10,
+ "type2cost":1000,
+ "tag":0,
+ "nexthops":[
+ {
+ "ip":"10.0.1.2",
+ "via":"eth-rt2"
+ }
+ ]
+ }
+}
diff --git a/tests/topotests/ospf_nssa_topo1/rt1/step9/show_ip_ospf_route.ref b/tests/topotests/ospf_nssa_topo1/rt1/step9/show_ip_ospf_route.ref
new file mode 100644
index 0000000000..2d3c8c485f
--- /dev/null
+++ b/tests/topotests/ospf_nssa_topo1/rt1/step9/show_ip_ospf_route.ref
@@ -0,0 +1,91 @@
+{
+ "1.1.1.1\/32":{
+ "routeType":"N",
+ "cost":0,
+ "area":"0.0.0.0",
+ "nexthops":[
+ {
+ "ip":" ",
+ "directlyAttachedTo":"lo"
+ }
+ ]
+ },
+ "2.2.2.2\/32":{
+ "routeType":"N",
+ "cost":10,
+ "area":"0.0.0.0",
+ "nexthops":[
+ {
+ "ip":"10.0.1.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "3.3.3.3\/32":{
+ "routeType":"N IA",
+ "cost":20,
+ "area":"0.0.0.0",
+ "nexthops":[
+ {
+ "ip":"10.0.1.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "4.4.4.4\/32":{
+ "routeType":"N IA",
+ "cost":20,
+ "area":"0.0.0.0",
+ "nexthops":[
+ {
+ "ip":"10.0.1.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "10.0.1.0\/24":{
+ "routeType":"N",
+ "cost":10,
+ "area":"0.0.0.0",
+ "nexthops":[
+ {
+ "ip":" ",
+ "directlyAttachedTo":"eth-rt2"
+ }
+ ]
+ },
+ "10.0.2.0\/24":{
+ "routeType":"N IA",
+ "cost":20,
+ "area":"0.0.0.0",
+ "nexthops":[
+ {
+ "ip":"10.0.1.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "10.0.3.0\/24":{
+ "routeType":"N IA",
+ "cost":20,
+ "area":"0.0.0.0",
+ "nexthops":[
+ {
+ "ip":"10.0.1.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "2.2.2.2":{
+ "routeType":"R ",
+ "cost":10,
+ "area":"0.0.0.0",
+ "routerType":"abr",
+ "nexthops":[
+ {
+ "ip":"10.0.1.2",
+ "via":"eth-rt2"
+ }
+ ]
+ }
+}
diff --git a/tests/topotests/ospf_nssa_topo1/rt1/zebra.conf b/tests/topotests/ospf_nssa_topo1/rt1/zebra.conf
new file mode 100644
index 0000000000..1df100564e
--- /dev/null
+++ b/tests/topotests/ospf_nssa_topo1/rt1/zebra.conf
@@ -0,0 +1,18 @@
+log file zebra.log
+!
+hostname rt1
+!
+! debug zebra kernel
+! debug zebra packet
+! debug zebra mpls
+!
+interface lo
+ ip address 1.1.1.1/32
+!
+interface eth-rt2
+ ip address 10.0.1.1/24
+!
+ip forwarding
+!
+line vty
+!
diff --git a/tests/topotests/ospf_nssa_topo1/rt2/ospfd.conf b/tests/topotests/ospf_nssa_topo1/rt2/ospfd.conf
new file mode 100644
index 0000000000..12884d2ea9
--- /dev/null
+++ b/tests/topotests/ospf_nssa_topo1/rt2/ospfd.conf
@@ -0,0 +1,35 @@
+password 1
+hostname rt2
+log file ospfd.log
+!
+! debug ospf sr
+! debug ospf te
+! debug ospf event
+! debug ospf lsa
+! debug ospf zebra
+!
+interface lo
+ ip ospf area 0
+!
+interface eth-rt1
+ ip ospf network point-to-point
+ ip ospf area 0
+ ip ospf hello-interval 3
+ ip ospf dead-interval 12
+!
+interface eth-rt3
+ ip ospf network point-to-point
+ ip ospf area 1
+ ip ospf hello-interval 3
+ ip ospf dead-interval 12
+!
+interface eth-rt4
+ ip ospf network point-to-point
+ ip ospf area 1
+ ip ospf hello-interval 3
+ ip ospf dead-interval 12
+!
+router ospf
+ router-id 2.2.2.2
+ area 1 nssa
+!
diff --git a/tests/topotests/ospf_nssa_topo1/rt2/staticd.conf b/tests/topotests/ospf_nssa_topo1/rt2/staticd.conf
new file mode 100644
index 0000000000..b6d4233a4f
--- /dev/null
+++ b/tests/topotests/ospf_nssa_topo1/rt2/staticd.conf
@@ -0,0 +1,6 @@
+log file staticd.log
+!
+hostname rt2
+!
+line vty
+!
diff --git a/tests/topotests/ospf_nssa_topo1/rt2/step1/show_ip_ospf_route.ref b/tests/topotests/ospf_nssa_topo1/rt2/step1/show_ip_ospf_route.ref
new file mode 100644
index 0000000000..c09411741a
--- /dev/null
+++ b/tests/topotests/ospf_nssa_topo1/rt2/step1/show_ip_ospf_route.ref
@@ -0,0 +1,127 @@
+{
+ "1.1.1.1\/32":{
+ "routeType":"N",
+ "cost":10,
+ "area":"0.0.0.0",
+ "nexthops":[
+ {
+ "ip":"10.0.1.1",
+ "via":"eth-rt1"
+ }
+ ]
+ },
+ "2.2.2.2\/32":{
+ "routeType":"N",
+ "cost":0,
+ "area":"0.0.0.0",
+ "nexthops":[
+ {
+ "ip":" ",
+ "directlyAttachedTo":"lo"
+ }
+ ]
+ },
+ "3.3.3.3\/32":{
+ "routeType":"N",
+ "cost":10,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.2.3",
+ "via":"eth-rt3"
+ }
+ ]
+ },
+ "4.4.4.4\/32":{
+ "routeType":"N",
+ "cost":10,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.3.4",
+ "via":"eth-rt4"
+ }
+ ]
+ },
+ "10.0.1.0\/24":{
+ "routeType":"N",
+ "cost":10,
+ "area":"0.0.0.0",
+ "nexthops":[
+ {
+ "ip":" ",
+ "directlyAttachedTo":"eth-rt1"
+ }
+ ]
+ },
+ "10.0.2.0\/24":{
+ "routeType":"N",
+ "cost":10,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":" ",
+ "directlyAttachedTo":"eth-rt3"
+ }
+ ]
+ },
+ "10.0.3.0\/24":{
+ "routeType":"N",
+ "cost":10,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":" ",
+ "directlyAttachedTo":"eth-rt4"
+ }
+ ]
+ },
+ "3.3.3.3":{
+ "routeType":"R ",
+ "cost":10,
+ "area":"0.0.0.1",
+ "routerType":"asbr",
+ "nexthops":[
+ {
+ "ip":"10.0.2.3",
+ "via":"eth-rt3"
+ }
+ ]
+ },
+ "4.4.4.4":{
+ "routeType":"R ",
+ "cost":10,
+ "area":"0.0.0.1",
+ "routerType":"asbr",
+ "nexthops":[
+ {
+ "ip":"10.0.3.4",
+ "via":"eth-rt4"
+ }
+ ]
+ },
+ "172.16.1.1\/32":{
+ "routeType":"N E2",
+ "cost":10,
+ "type2cost":20,
+ "tag":0,
+ "nexthops":[
+ {
+ "ip":"10.0.3.4",
+ "via":"eth-rt4"
+ }
+ ]
+ },
+ "172.16.1.2\/32":{
+ "routeType":"N E2",
+ "cost":10,
+ "type2cost":20,
+ "tag":0,
+ "nexthops":[
+ {
+ "ip":"10.0.3.4",
+ "via":"eth-rt4"
+ }
+ ]
+ }
+}
diff --git a/tests/topotests/ospf_nssa_topo1/rt2/step10/show_ip_ospf_route.ref b/tests/topotests/ospf_nssa_topo1/rt2/step10/show_ip_ospf_route.ref
new file mode 100644
index 0000000000..c09411741a
--- /dev/null
+++ b/tests/topotests/ospf_nssa_topo1/rt2/step10/show_ip_ospf_route.ref
@@ -0,0 +1,127 @@
+{
+ "1.1.1.1\/32":{
+ "routeType":"N",
+ "cost":10,
+ "area":"0.0.0.0",
+ "nexthops":[
+ {
+ "ip":"10.0.1.1",
+ "via":"eth-rt1"
+ }
+ ]
+ },
+ "2.2.2.2\/32":{
+ "routeType":"N",
+ "cost":0,
+ "area":"0.0.0.0",
+ "nexthops":[
+ {
+ "ip":" ",
+ "directlyAttachedTo":"lo"
+ }
+ ]
+ },
+ "3.3.3.3\/32":{
+ "routeType":"N",
+ "cost":10,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.2.3",
+ "via":"eth-rt3"
+ }
+ ]
+ },
+ "4.4.4.4\/32":{
+ "routeType":"N",
+ "cost":10,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.3.4",
+ "via":"eth-rt4"
+ }
+ ]
+ },
+ "10.0.1.0\/24":{
+ "routeType":"N",
+ "cost":10,
+ "area":"0.0.0.0",
+ "nexthops":[
+ {
+ "ip":" ",
+ "directlyAttachedTo":"eth-rt1"
+ }
+ ]
+ },
+ "10.0.2.0\/24":{
+ "routeType":"N",
+ "cost":10,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":" ",
+ "directlyAttachedTo":"eth-rt3"
+ }
+ ]
+ },
+ "10.0.3.0\/24":{
+ "routeType":"N",
+ "cost":10,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":" ",
+ "directlyAttachedTo":"eth-rt4"
+ }
+ ]
+ },
+ "3.3.3.3":{
+ "routeType":"R ",
+ "cost":10,
+ "area":"0.0.0.1",
+ "routerType":"asbr",
+ "nexthops":[
+ {
+ "ip":"10.0.2.3",
+ "via":"eth-rt3"
+ }
+ ]
+ },
+ "4.4.4.4":{
+ "routeType":"R ",
+ "cost":10,
+ "area":"0.0.0.1",
+ "routerType":"asbr",
+ "nexthops":[
+ {
+ "ip":"10.0.3.4",
+ "via":"eth-rt4"
+ }
+ ]
+ },
+ "172.16.1.1\/32":{
+ "routeType":"N E2",
+ "cost":10,
+ "type2cost":20,
+ "tag":0,
+ "nexthops":[
+ {
+ "ip":"10.0.3.4",
+ "via":"eth-rt4"
+ }
+ ]
+ },
+ "172.16.1.2\/32":{
+ "routeType":"N E2",
+ "cost":10,
+ "type2cost":20,
+ "tag":0,
+ "nexthops":[
+ {
+ "ip":"10.0.3.4",
+ "via":"eth-rt4"
+ }
+ ]
+ }
+}
diff --git a/tests/topotests/ospf_nssa_topo1/rt2/step2/show_ip_ospf_route.ref b/tests/topotests/ospf_nssa_topo1/rt2/step2/show_ip_ospf_route.ref
new file mode 100644
index 0000000000..a67dfb4685
--- /dev/null
+++ b/tests/topotests/ospf_nssa_topo1/rt2/step2/show_ip_ospf_route.ref
@@ -0,0 +1,139 @@
+{
+ "1.1.1.1\/32":{
+ "routeType":"N",
+ "cost":10,
+ "area":"0.0.0.0",
+ "nexthops":[
+ {
+ "ip":"10.0.1.1",
+ "via":"eth-rt1"
+ }
+ ]
+ },
+ "2.2.2.2\/32":{
+ "routeType":"N",
+ "cost":0,
+ "area":"0.0.0.0",
+ "nexthops":[
+ {
+ "ip":" ",
+ "directlyAttachedTo":"lo"
+ }
+ ]
+ },
+ "3.3.3.3\/32":{
+ "routeType":"N",
+ "cost":10,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.2.3",
+ "via":"eth-rt3"
+ }
+ ]
+ },
+ "4.4.4.4\/32":{
+ "routeType":"N",
+ "cost":10,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.3.4",
+ "via":"eth-rt4"
+ }
+ ]
+ },
+ "10.0.1.0\/24":{
+ "routeType":"N",
+ "cost":10,
+ "area":"0.0.0.0",
+ "nexthops":[
+ {
+ "ip":" ",
+ "directlyAttachedTo":"eth-rt1"
+ }
+ ]
+ },
+ "10.0.2.0\/24":{
+ "routeType":"N",
+ "cost":10,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":" ",
+ "directlyAttachedTo":"eth-rt3"
+ }
+ ]
+ },
+ "10.0.3.0\/24":{
+ "routeType":"N",
+ "cost":10,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":" ",
+ "directlyAttachedTo":"eth-rt4"
+ }
+ ]
+ },
+ "3.3.3.3":{
+ "routeType":"R ",
+ "cost":10,
+ "area":"0.0.0.1",
+ "routerType":"asbr",
+ "nexthops":[
+ {
+ "ip":"10.0.2.3",
+ "via":"eth-rt3"
+ }
+ ]
+ },
+ "4.4.4.4":{
+ "routeType":"R ",
+ "cost":10,
+ "area":"0.0.0.1",
+ "routerType":"asbr",
+ "nexthops":[
+ {
+ "ip":"10.0.3.4",
+ "via":"eth-rt4"
+ }
+ ]
+ },
+ "0.0.0.0\/0":{
+ "routeType":"N E2",
+ "cost":10,
+ "type2cost":1,
+ "tag":0,
+ "nexthops":[
+ {
+ "ip":"10.0.2.3",
+ "via":"eth-rt3"
+ }
+ ]
+ },
+ "172.16.1.1\/32":{
+ "routeType":"N E2",
+ "cost":10,
+ "type2cost":20,
+ "tag":0,
+ "nexthops":[
+ {
+ "ip":"10.0.3.4",
+ "via":"eth-rt4"
+ }
+ ]
+ },
+ "172.16.1.2\/32":{
+ "routeType":"N E2",
+ "cost":10,
+ "type2cost":20,
+ "tag":0,
+ "nexthops":[
+ {
+ "ip":"10.0.3.4",
+ "via":"eth-rt4"
+ }
+ ]
+ }
+}
diff --git a/tests/topotests/ospf_nssa_topo1/rt2/step3/show_ip_ospf_route.ref b/tests/topotests/ospf_nssa_topo1/rt2/step3/show_ip_ospf_route.ref
new file mode 100644
index 0000000000..c09411741a
--- /dev/null
+++ b/tests/topotests/ospf_nssa_topo1/rt2/step3/show_ip_ospf_route.ref
@@ -0,0 +1,127 @@
+{
+ "1.1.1.1\/32":{
+ "routeType":"N",
+ "cost":10,
+ "area":"0.0.0.0",
+ "nexthops":[
+ {
+ "ip":"10.0.1.1",
+ "via":"eth-rt1"
+ }
+ ]
+ },
+ "2.2.2.2\/32":{
+ "routeType":"N",
+ "cost":0,
+ "area":"0.0.0.0",
+ "nexthops":[
+ {
+ "ip":" ",
+ "directlyAttachedTo":"lo"
+ }
+ ]
+ },
+ "3.3.3.3\/32":{
+ "routeType":"N",
+ "cost":10,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.2.3",
+ "via":"eth-rt3"
+ }
+ ]
+ },
+ "4.4.4.4\/32":{
+ "routeType":"N",
+ "cost":10,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.3.4",
+ "via":"eth-rt4"
+ }
+ ]
+ },
+ "10.0.1.0\/24":{
+ "routeType":"N",
+ "cost":10,
+ "area":"0.0.0.0",
+ "nexthops":[
+ {
+ "ip":" ",
+ "directlyAttachedTo":"eth-rt1"
+ }
+ ]
+ },
+ "10.0.2.0\/24":{
+ "routeType":"N",
+ "cost":10,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":" ",
+ "directlyAttachedTo":"eth-rt3"
+ }
+ ]
+ },
+ "10.0.3.0\/24":{
+ "routeType":"N",
+ "cost":10,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":" ",
+ "directlyAttachedTo":"eth-rt4"
+ }
+ ]
+ },
+ "3.3.3.3":{
+ "routeType":"R ",
+ "cost":10,
+ "area":"0.0.0.1",
+ "routerType":"asbr",
+ "nexthops":[
+ {
+ "ip":"10.0.2.3",
+ "via":"eth-rt3"
+ }
+ ]
+ },
+ "4.4.4.4":{
+ "routeType":"R ",
+ "cost":10,
+ "area":"0.0.0.1",
+ "routerType":"asbr",
+ "nexthops":[
+ {
+ "ip":"10.0.3.4",
+ "via":"eth-rt4"
+ }
+ ]
+ },
+ "172.16.1.1\/32":{
+ "routeType":"N E2",
+ "cost":10,
+ "type2cost":20,
+ "tag":0,
+ "nexthops":[
+ {
+ "ip":"10.0.3.4",
+ "via":"eth-rt4"
+ }
+ ]
+ },
+ "172.16.1.2\/32":{
+ "routeType":"N E2",
+ "cost":10,
+ "type2cost":20,
+ "tag":0,
+ "nexthops":[
+ {
+ "ip":"10.0.3.4",
+ "via":"eth-rt4"
+ }
+ ]
+ }
+}
diff --git a/tests/topotests/ospf_nssa_topo1/rt2/step4/show_ip_ospf_route.ref b/tests/topotests/ospf_nssa_topo1/rt2/step4/show_ip_ospf_route.ref
new file mode 100644
index 0000000000..c7dd93c6e9
--- /dev/null
+++ b/tests/topotests/ospf_nssa_topo1/rt2/step4/show_ip_ospf_route.ref
@@ -0,0 +1,129 @@
+{
+ "1.1.1.1\/32":{
+ "routeType":"N",
+ "cost":10,
+ "area":"0.0.0.0",
+ "nexthops":[
+ {
+ "ip":"10.0.1.1",
+ "via":"eth-rt1"
+ }
+ ]
+ },
+ "2.2.2.2\/32":{
+ "routeType":"N",
+ "cost":0,
+ "area":"0.0.0.0",
+ "nexthops":[
+ {
+ "ip":" ",
+ "directlyAttachedTo":"lo"
+ }
+ ]
+ },
+ "3.3.3.3\/32":{
+ "routeType":"N",
+ "cost":10,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.2.3",
+ "via":"eth-rt3"
+ }
+ ]
+ },
+ "4.4.4.4\/32":{
+ "routeType":"N",
+ "cost":10,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.3.4",
+ "via":"eth-rt4"
+ }
+ ]
+ },
+ "10.0.1.0\/24":{
+ "routeType":"N",
+ "cost":10,
+ "area":"0.0.0.0",
+ "nexthops":[
+ {
+ "ip":" ",
+ "directlyAttachedTo":"eth-rt1"
+ }
+ ]
+ },
+ "10.0.2.0\/24":{
+ "routeType":"N",
+ "cost":10,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":" ",
+ "directlyAttachedTo":"eth-rt3"
+ }
+ ]
+ },
+ "10.0.3.0\/24":{
+ "routeType":"N",
+ "cost":10,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":" ",
+ "directlyAttachedTo":"eth-rt4"
+ }
+ ]
+ },
+ "172.16.1.0\/24":{
+ },
+ "3.3.3.3":{
+ "routeType":"R ",
+ "cost":10,
+ "area":"0.0.0.1",
+ "routerType":"asbr",
+ "nexthops":[
+ {
+ "ip":"10.0.2.3",
+ "via":"eth-rt3"
+ }
+ ]
+ },
+ "4.4.4.4":{
+ "routeType":"R ",
+ "cost":10,
+ "area":"0.0.0.1",
+ "routerType":"asbr",
+ "nexthops":[
+ {
+ "ip":"10.0.3.4",
+ "via":"eth-rt4"
+ }
+ ]
+ },
+ "172.16.1.1\/32":{
+ "routeType":"N E2",
+ "cost":10,
+ "type2cost":20,
+ "tag":0,
+ "nexthops":[
+ {
+ "ip":"10.0.3.4",
+ "via":"eth-rt4"
+ }
+ ]
+ },
+ "172.16.1.2\/32":{
+ "routeType":"N E2",
+ "cost":10,
+ "type2cost":20,
+ "tag":0,
+ "nexthops":[
+ {
+ "ip":"10.0.3.4",
+ "via":"eth-rt4"
+ }
+ ]
+ }
+}
diff --git a/tests/topotests/ospf_nssa_topo1/rt2/step5/show_ip_ospf_route.ref b/tests/topotests/ospf_nssa_topo1/rt2/step5/show_ip_ospf_route.ref
new file mode 100644
index 0000000000..9c3cfff6c0
--- /dev/null
+++ b/tests/topotests/ospf_nssa_topo1/rt2/step5/show_ip_ospf_route.ref
@@ -0,0 +1,117 @@
+{
+ "1.1.1.1\/32":{
+ "routeType":"N",
+ "cost":10,
+ "area":"0.0.0.0",
+ "nexthops":[
+ {
+ "ip":"10.0.1.1",
+ "via":"eth-rt1"
+ }
+ ]
+ },
+ "2.2.2.2\/32":{
+ "routeType":"N",
+ "cost":0,
+ "area":"0.0.0.0",
+ "nexthops":[
+ {
+ "ip":" ",
+ "directlyAttachedTo":"lo"
+ }
+ ]
+ },
+ "3.3.3.3\/32":{
+ "routeType":"N",
+ "cost":10,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.2.3",
+ "via":"eth-rt3"
+ }
+ ]
+ },
+ "4.4.4.4\/32":{
+ "routeType":"N",
+ "cost":10,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.3.4",
+ "via":"eth-rt4"
+ }
+ ]
+ },
+ "10.0.1.0\/24":{
+ "routeType":"N",
+ "cost":10,
+ "area":"0.0.0.0",
+ "nexthops":[
+ {
+ "ip":" ",
+ "directlyAttachedTo":"eth-rt1"
+ }
+ ]
+ },
+ "10.0.2.0\/24":{
+ "routeType":"N",
+ "cost":10,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":" ",
+ "directlyAttachedTo":"eth-rt3"
+ }
+ ]
+ },
+ "10.0.3.0\/24":{
+ "routeType":"N",
+ "cost":10,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":" ",
+ "directlyAttachedTo":"eth-rt4"
+ }
+ ]
+ },
+ "172.16.1.0\/24":{
+ },
+ "3.3.3.3":{
+ "routeType":"R ",
+ "cost":10,
+ "area":"0.0.0.1",
+ "routerType":"asbr",
+ "nexthops":[
+ {
+ "ip":"10.0.2.3",
+ "via":"eth-rt3"
+ }
+ ]
+ },
+ "4.4.4.4":{
+ "routeType":"R ",
+ "cost":10,
+ "area":"0.0.0.1",
+ "routerType":"asbr",
+ "nexthops":[
+ {
+ "ip":"10.0.3.4",
+ "via":"eth-rt4"
+ }
+ ]
+ },
+ "172.16.1.2\/32":{
+ "routeType":"N E2",
+ "cost":10,
+ "type2cost":20,
+ "tag":0,
+ "nexthops":[
+ {
+ "ip":"10.0.3.4",
+ "via":"eth-rt4"
+ }
+ ]
+ }
+}
diff --git a/tests/topotests/ospf_nssa_topo1/rt2/step6/show_ip_ospf_route.ref b/tests/topotests/ospf_nssa_topo1/rt2/step6/show_ip_ospf_route.ref
new file mode 100644
index 0000000000..f6bbdfa594
--- /dev/null
+++ b/tests/topotests/ospf_nssa_topo1/rt2/step6/show_ip_ospf_route.ref
@@ -0,0 +1,103 @@
+{
+ "1.1.1.1\/32":{
+ "routeType":"N",
+ "cost":10,
+ "area":"0.0.0.0",
+ "nexthops":[
+ {
+ "ip":"10.0.1.1",
+ "via":"eth-rt1"
+ }
+ ]
+ },
+ "2.2.2.2\/32":{
+ "routeType":"N",
+ "cost":0,
+ "area":"0.0.0.0",
+ "nexthops":[
+ {
+ "ip":" ",
+ "directlyAttachedTo":"lo"
+ }
+ ]
+ },
+ "3.3.3.3\/32":{
+ "routeType":"N",
+ "cost":10,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.2.3",
+ "via":"eth-rt3"
+ }
+ ]
+ },
+ "4.4.4.4\/32":{
+ "routeType":"N",
+ "cost":10,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.3.4",
+ "via":"eth-rt4"
+ }
+ ]
+ },
+ "10.0.1.0\/24":{
+ "routeType":"N",
+ "cost":10,
+ "area":"0.0.0.0",
+ "nexthops":[
+ {
+ "ip":" ",
+ "directlyAttachedTo":"eth-rt1"
+ }
+ ]
+ },
+ "10.0.2.0\/24":{
+ "routeType":"N",
+ "cost":10,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":" ",
+ "directlyAttachedTo":"eth-rt3"
+ }
+ ]
+ },
+ "10.0.3.0\/24":{
+ "routeType":"N",
+ "cost":10,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":" ",
+ "directlyAttachedTo":"eth-rt4"
+ }
+ ]
+ },
+ "3.3.3.3":{
+ "routeType":"R ",
+ "cost":10,
+ "area":"0.0.0.1",
+ "routerType":"asbr",
+ "nexthops":[
+ {
+ "ip":"10.0.2.3",
+ "via":"eth-rt3"
+ }
+ ]
+ },
+ "4.4.4.4":{
+ "routeType":"R ",
+ "cost":10,
+ "area":"0.0.0.1",
+ "routerType":"asbr",
+ "nexthops":[
+ {
+ "ip":"10.0.3.4",
+ "via":"eth-rt4"
+ }
+ ]
+ }
+}
diff --git a/tests/topotests/ospf_nssa_topo1/rt2/step7/show_ip_ospf_route.ref b/tests/topotests/ospf_nssa_topo1/rt2/step7/show_ip_ospf_route.ref
new file mode 100644
index 0000000000..c7dd93c6e9
--- /dev/null
+++ b/tests/topotests/ospf_nssa_topo1/rt2/step7/show_ip_ospf_route.ref
@@ -0,0 +1,129 @@
+{
+ "1.1.1.1\/32":{
+ "routeType":"N",
+ "cost":10,
+ "area":"0.0.0.0",
+ "nexthops":[
+ {
+ "ip":"10.0.1.1",
+ "via":"eth-rt1"
+ }
+ ]
+ },
+ "2.2.2.2\/32":{
+ "routeType":"N",
+ "cost":0,
+ "area":"0.0.0.0",
+ "nexthops":[
+ {
+ "ip":" ",
+ "directlyAttachedTo":"lo"
+ }
+ ]
+ },
+ "3.3.3.3\/32":{
+ "routeType":"N",
+ "cost":10,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.2.3",
+ "via":"eth-rt3"
+ }
+ ]
+ },
+ "4.4.4.4\/32":{
+ "routeType":"N",
+ "cost":10,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.3.4",
+ "via":"eth-rt4"
+ }
+ ]
+ },
+ "10.0.1.0\/24":{
+ "routeType":"N",
+ "cost":10,
+ "area":"0.0.0.0",
+ "nexthops":[
+ {
+ "ip":" ",
+ "directlyAttachedTo":"eth-rt1"
+ }
+ ]
+ },
+ "10.0.2.0\/24":{
+ "routeType":"N",
+ "cost":10,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":" ",
+ "directlyAttachedTo":"eth-rt3"
+ }
+ ]
+ },
+ "10.0.3.0\/24":{
+ "routeType":"N",
+ "cost":10,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":" ",
+ "directlyAttachedTo":"eth-rt4"
+ }
+ ]
+ },
+ "172.16.1.0\/24":{
+ },
+ "3.3.3.3":{
+ "routeType":"R ",
+ "cost":10,
+ "area":"0.0.0.1",
+ "routerType":"asbr",
+ "nexthops":[
+ {
+ "ip":"10.0.2.3",
+ "via":"eth-rt3"
+ }
+ ]
+ },
+ "4.4.4.4":{
+ "routeType":"R ",
+ "cost":10,
+ "area":"0.0.0.1",
+ "routerType":"asbr",
+ "nexthops":[
+ {
+ "ip":"10.0.3.4",
+ "via":"eth-rt4"
+ }
+ ]
+ },
+ "172.16.1.1\/32":{
+ "routeType":"N E2",
+ "cost":10,
+ "type2cost":20,
+ "tag":0,
+ "nexthops":[
+ {
+ "ip":"10.0.3.4",
+ "via":"eth-rt4"
+ }
+ ]
+ },
+ "172.16.1.2\/32":{
+ "routeType":"N E2",
+ "cost":10,
+ "type2cost":20,
+ "tag":0,
+ "nexthops":[
+ {
+ "ip":"10.0.3.4",
+ "via":"eth-rt4"
+ }
+ ]
+ }
+}
diff --git a/tests/topotests/ospf_nssa_topo1/rt2/step8/show_ip_ospf_route.ref b/tests/topotests/ospf_nssa_topo1/rt2/step8/show_ip_ospf_route.ref
new file mode 100644
index 0000000000..c7dd93c6e9
--- /dev/null
+++ b/tests/topotests/ospf_nssa_topo1/rt2/step8/show_ip_ospf_route.ref
@@ -0,0 +1,129 @@
+{
+ "1.1.1.1\/32":{
+ "routeType":"N",
+ "cost":10,
+ "area":"0.0.0.0",
+ "nexthops":[
+ {
+ "ip":"10.0.1.1",
+ "via":"eth-rt1"
+ }
+ ]
+ },
+ "2.2.2.2\/32":{
+ "routeType":"N",
+ "cost":0,
+ "area":"0.0.0.0",
+ "nexthops":[
+ {
+ "ip":" ",
+ "directlyAttachedTo":"lo"
+ }
+ ]
+ },
+ "3.3.3.3\/32":{
+ "routeType":"N",
+ "cost":10,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.2.3",
+ "via":"eth-rt3"
+ }
+ ]
+ },
+ "4.4.4.4\/32":{
+ "routeType":"N",
+ "cost":10,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.3.4",
+ "via":"eth-rt4"
+ }
+ ]
+ },
+ "10.0.1.0\/24":{
+ "routeType":"N",
+ "cost":10,
+ "area":"0.0.0.0",
+ "nexthops":[
+ {
+ "ip":" ",
+ "directlyAttachedTo":"eth-rt1"
+ }
+ ]
+ },
+ "10.0.2.0\/24":{
+ "routeType":"N",
+ "cost":10,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":" ",
+ "directlyAttachedTo":"eth-rt3"
+ }
+ ]
+ },
+ "10.0.3.0\/24":{
+ "routeType":"N",
+ "cost":10,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":" ",
+ "directlyAttachedTo":"eth-rt4"
+ }
+ ]
+ },
+ "172.16.1.0\/24":{
+ },
+ "3.3.3.3":{
+ "routeType":"R ",
+ "cost":10,
+ "area":"0.0.0.1",
+ "routerType":"asbr",
+ "nexthops":[
+ {
+ "ip":"10.0.2.3",
+ "via":"eth-rt3"
+ }
+ ]
+ },
+ "4.4.4.4":{
+ "routeType":"R ",
+ "cost":10,
+ "area":"0.0.0.1",
+ "routerType":"asbr",
+ "nexthops":[
+ {
+ "ip":"10.0.3.4",
+ "via":"eth-rt4"
+ }
+ ]
+ },
+ "172.16.1.1\/32":{
+ "routeType":"N E2",
+ "cost":10,
+ "type2cost":20,
+ "tag":0,
+ "nexthops":[
+ {
+ "ip":"10.0.3.4",
+ "via":"eth-rt4"
+ }
+ ]
+ },
+ "172.16.1.2\/32":{
+ "routeType":"N E2",
+ "cost":10,
+ "type2cost":20,
+ "tag":0,
+ "nexthops":[
+ {
+ "ip":"10.0.3.4",
+ "via":"eth-rt4"
+ }
+ ]
+ }
+}
diff --git a/tests/topotests/ospf_nssa_topo1/rt2/step9/show_ip_ospf_route.ref b/tests/topotests/ospf_nssa_topo1/rt2/step9/show_ip_ospf_route.ref
new file mode 100644
index 0000000000..c09411741a
--- /dev/null
+++ b/tests/topotests/ospf_nssa_topo1/rt2/step9/show_ip_ospf_route.ref
@@ -0,0 +1,127 @@
+{
+ "1.1.1.1\/32":{
+ "routeType":"N",
+ "cost":10,
+ "area":"0.0.0.0",
+ "nexthops":[
+ {
+ "ip":"10.0.1.1",
+ "via":"eth-rt1"
+ }
+ ]
+ },
+ "2.2.2.2\/32":{
+ "routeType":"N",
+ "cost":0,
+ "area":"0.0.0.0",
+ "nexthops":[
+ {
+ "ip":" ",
+ "directlyAttachedTo":"lo"
+ }
+ ]
+ },
+ "3.3.3.3\/32":{
+ "routeType":"N",
+ "cost":10,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.2.3",
+ "via":"eth-rt3"
+ }
+ ]
+ },
+ "4.4.4.4\/32":{
+ "routeType":"N",
+ "cost":10,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.3.4",
+ "via":"eth-rt4"
+ }
+ ]
+ },
+ "10.0.1.0\/24":{
+ "routeType":"N",
+ "cost":10,
+ "area":"0.0.0.0",
+ "nexthops":[
+ {
+ "ip":" ",
+ "directlyAttachedTo":"eth-rt1"
+ }
+ ]
+ },
+ "10.0.2.0\/24":{
+ "routeType":"N",
+ "cost":10,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":" ",
+ "directlyAttachedTo":"eth-rt3"
+ }
+ ]
+ },
+ "10.0.3.0\/24":{
+ "routeType":"N",
+ "cost":10,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":" ",
+ "directlyAttachedTo":"eth-rt4"
+ }
+ ]
+ },
+ "3.3.3.3":{
+ "routeType":"R ",
+ "cost":10,
+ "area":"0.0.0.1",
+ "routerType":"asbr",
+ "nexthops":[
+ {
+ "ip":"10.0.2.3",
+ "via":"eth-rt3"
+ }
+ ]
+ },
+ "4.4.4.4":{
+ "routeType":"R ",
+ "cost":10,
+ "area":"0.0.0.1",
+ "routerType":"asbr",
+ "nexthops":[
+ {
+ "ip":"10.0.3.4",
+ "via":"eth-rt4"
+ }
+ ]
+ },
+ "172.16.1.1\/32":{
+ "routeType":"N E2",
+ "cost":10,
+ "type2cost":20,
+ "tag":0,
+ "nexthops":[
+ {
+ "ip":"10.0.3.4",
+ "via":"eth-rt4"
+ }
+ ]
+ },
+ "172.16.1.2\/32":{
+ "routeType":"N E2",
+ "cost":10,
+ "type2cost":20,
+ "tag":0,
+ "nexthops":[
+ {
+ "ip":"10.0.3.4",
+ "via":"eth-rt4"
+ }
+ ]
+ }
+}
diff --git a/tests/topotests/ospf_nssa_topo1/rt2/zebra.conf b/tests/topotests/ospf_nssa_topo1/rt2/zebra.conf
new file mode 100644
index 0000000000..fa274ebade
--- /dev/null
+++ b/tests/topotests/ospf_nssa_topo1/rt2/zebra.conf
@@ -0,0 +1,24 @@
+log file zebra.log
+!
+hostname rt2
+!
+! debug zebra kernel
+! debug zebra packet
+! debug zebra mpls
+!
+interface lo
+ ip address 2.2.2.2/32
+!
+interface eth-rt1
+ ip address 10.0.1.2/24
+!
+interface eth-rt3
+ ip address 10.0.2.2/24
+!
+interface eth-rt4
+ ip address 10.0.3.2/24
+!
+ip forwarding
+!
+line vty
+!
diff --git a/tests/topotests/ospf_nssa_topo1/rt3/ospfd.conf b/tests/topotests/ospf_nssa_topo1/rt3/ospfd.conf
new file mode 100644
index 0000000000..9691a7c512
--- /dev/null
+++ b/tests/topotests/ospf_nssa_topo1/rt3/ospfd.conf
@@ -0,0 +1,24 @@
+password 1
+hostname rt3
+log file ospfd.log
+!
+! debug ospf sr
+! debug ospf te
+! debug ospf event
+! debug ospf lsa
+! debug ospf zebra
+!
+interface lo
+ ip ospf area 1
+!
+interface eth-rt2
+ ip ospf network point-to-point
+ ip ospf area 1
+ ip ospf hello-interval 3
+ ip ospf dead-interval 12
+!
+router ospf
+ router-id 3.3.3.3
+ area 1 nssa
+ redistribute connected
+!
diff --git a/tests/topotests/ospf_nssa_topo1/rt3/staticd.conf b/tests/topotests/ospf_nssa_topo1/rt3/staticd.conf
new file mode 100644
index 0000000000..f0edd6c9ca
--- /dev/null
+++ b/tests/topotests/ospf_nssa_topo1/rt3/staticd.conf
@@ -0,0 +1,8 @@
+log file staticd.log
+!
+hostname rt3
+!
+ip route 0.0.0.0/0 Null0
+!
+line vty
+!
diff --git a/tests/topotests/ospf_nssa_topo1/rt3/step1/show_ip_ospf_route.ref b/tests/topotests/ospf_nssa_topo1/rt3/step1/show_ip_ospf_route.ref
new file mode 100644
index 0000000000..a2d078ab13
--- /dev/null
+++ b/tests/topotests/ospf_nssa_topo1/rt3/step1/show_ip_ospf_route.ref
@@ -0,0 +1,138 @@
+{
+ "0.0.0.0\/0":{
+ "routeType":"N IA",
+ "cost":11,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.2.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "1.1.1.1\/32":{
+ "routeType":"N IA",
+ "cost":20,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.2.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "2.2.2.2\/32":{
+ "routeType":"N IA",
+ "cost":10,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.2.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "3.3.3.3\/32":{
+ "routeType":"N",
+ "cost":0,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":" ",
+ "directlyAttachedTo":"lo"
+ }
+ ]
+ },
+ "4.4.4.4\/32":{
+ "routeType":"N",
+ "cost":20,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.2.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "10.0.1.0\/24":{
+ "routeType":"N IA",
+ "cost":20,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.2.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "10.0.2.0\/24":{
+ "routeType":"N",
+ "cost":10,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":" ",
+ "directlyAttachedTo":"eth-rt2"
+ }
+ ]
+ },
+ "10.0.3.0\/24":{
+ "routeType":"N",
+ "cost":20,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.2.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "2.2.2.2":{
+ "routeType":"R ",
+ "cost":10,
+ "area":"0.0.0.1",
+ "routerType":"abr",
+ "nexthops":[
+ {
+ "ip":"10.0.2.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "4.4.4.4":{
+ "routeType":"R ",
+ "cost":20,
+ "area":"0.0.0.1",
+ "routerType":"asbr",
+ "nexthops":[
+ {
+ "ip":"10.0.2.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "172.16.1.1\/32":{
+ "routeType":"N E2",
+ "cost":20,
+ "type2cost":20,
+ "tag":0,
+ "nexthops":[
+ {
+ "ip":"10.0.2.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "172.16.1.2\/32":{
+ "routeType":"N E2",
+ "cost":20,
+ "type2cost":20,
+ "tag":0,
+ "nexthops":[
+ {
+ "ip":"10.0.2.2",
+ "via":"eth-rt2"
+ }
+ ]
+ }
+}
diff --git a/tests/topotests/ospf_nssa_topo1/rt3/step10/show_ip_ospf_route.ref b/tests/topotests/ospf_nssa_topo1/rt3/step10/show_ip_ospf_route.ref
new file mode 100644
index 0000000000..4619067abd
--- /dev/null
+++ b/tests/topotests/ospf_nssa_topo1/rt3/step10/show_ip_ospf_route.ref
@@ -0,0 +1,150 @@
+{
+ "0.0.0.0\/0":{
+ "routeType":"N IA",
+ "cost":11,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.2.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "1.1.1.1\/32":{
+ "routeType":"N IA",
+ "cost":20,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.2.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "2.2.2.2\/32":{
+ "routeType":"N IA",
+ "cost":10,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.2.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "3.3.3.3\/32":{
+ "routeType":"N",
+ "cost":0,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":" ",
+ "directlyAttachedTo":"lo"
+ }
+ ]
+ },
+ "4.4.4.4\/32":{
+ "routeType":"N",
+ "cost":20,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.2.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "10.0.1.0\/24":{
+ "routeType":"N IA",
+ "cost":20,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.2.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "10.0.2.0\/24":{
+ "routeType":"N",
+ "cost":10,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":" ",
+ "directlyAttachedTo":"eth-rt2"
+ }
+ ]
+ },
+ "10.0.3.0\/24":{
+ "routeType":"N",
+ "cost":20,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.2.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "2.2.2.2":{
+ "routeType":"R ",
+ "cost":10,
+ "area":"0.0.0.1",
+ "routerType":"abr",
+ "nexthops":[
+ {
+ "ip":"10.0.2.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "4.4.4.4":{
+ "routeType":"R ",
+ "cost":20,
+ "area":"0.0.0.1",
+ "routerType":"asbr",
+ "nexthops":[
+ {
+ "ip":"10.0.2.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "172.16.1.0\/24":{
+ "routeType":"N E2",
+ "cost":10,
+ "type2cost":1000,
+ "tag":0,
+ "nexthops":[
+ {
+ "ip":"10.0.2.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "172.16.1.1\/32":{
+ "routeType":"N E2",
+ "cost":20,
+ "type2cost":20,
+ "tag":0,
+ "nexthops":[
+ {
+ "ip":"10.0.2.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "172.16.1.2\/32":{
+ "routeType":"N E2",
+ "cost":20,
+ "type2cost":20,
+ "tag":0,
+ "nexthops":[
+ {
+ "ip":"10.0.2.2",
+ "via":"eth-rt2"
+ }
+ ]
+ }
+}
diff --git a/tests/topotests/ospf_nssa_topo1/rt3/step2/show_ip_ospf_route.ref b/tests/topotests/ospf_nssa_topo1/rt3/step2/show_ip_ospf_route.ref
new file mode 100644
index 0000000000..a2d078ab13
--- /dev/null
+++ b/tests/topotests/ospf_nssa_topo1/rt3/step2/show_ip_ospf_route.ref
@@ -0,0 +1,138 @@
+{
+ "0.0.0.0\/0":{
+ "routeType":"N IA",
+ "cost":11,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.2.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "1.1.1.1\/32":{
+ "routeType":"N IA",
+ "cost":20,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.2.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "2.2.2.2\/32":{
+ "routeType":"N IA",
+ "cost":10,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.2.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "3.3.3.3\/32":{
+ "routeType":"N",
+ "cost":0,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":" ",
+ "directlyAttachedTo":"lo"
+ }
+ ]
+ },
+ "4.4.4.4\/32":{
+ "routeType":"N",
+ "cost":20,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.2.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "10.0.1.0\/24":{
+ "routeType":"N IA",
+ "cost":20,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.2.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "10.0.2.0\/24":{
+ "routeType":"N",
+ "cost":10,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":" ",
+ "directlyAttachedTo":"eth-rt2"
+ }
+ ]
+ },
+ "10.0.3.0\/24":{
+ "routeType":"N",
+ "cost":20,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.2.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "2.2.2.2":{
+ "routeType":"R ",
+ "cost":10,
+ "area":"0.0.0.1",
+ "routerType":"abr",
+ "nexthops":[
+ {
+ "ip":"10.0.2.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "4.4.4.4":{
+ "routeType":"R ",
+ "cost":20,
+ "area":"0.0.0.1",
+ "routerType":"asbr",
+ "nexthops":[
+ {
+ "ip":"10.0.2.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "172.16.1.1\/32":{
+ "routeType":"N E2",
+ "cost":20,
+ "type2cost":20,
+ "tag":0,
+ "nexthops":[
+ {
+ "ip":"10.0.2.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "172.16.1.2\/32":{
+ "routeType":"N E2",
+ "cost":20,
+ "type2cost":20,
+ "tag":0,
+ "nexthops":[
+ {
+ "ip":"10.0.2.2",
+ "via":"eth-rt2"
+ }
+ ]
+ }
+}
diff --git a/tests/topotests/ospf_nssa_topo1/rt3/step3/show_ip_ospf_route.ref b/tests/topotests/ospf_nssa_topo1/rt3/step3/show_ip_ospf_route.ref
new file mode 100644
index 0000000000..a2d078ab13
--- /dev/null
+++ b/tests/topotests/ospf_nssa_topo1/rt3/step3/show_ip_ospf_route.ref
@@ -0,0 +1,138 @@
+{
+ "0.0.0.0\/0":{
+ "routeType":"N IA",
+ "cost":11,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.2.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "1.1.1.1\/32":{
+ "routeType":"N IA",
+ "cost":20,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.2.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "2.2.2.2\/32":{
+ "routeType":"N IA",
+ "cost":10,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.2.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "3.3.3.3\/32":{
+ "routeType":"N",
+ "cost":0,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":" ",
+ "directlyAttachedTo":"lo"
+ }
+ ]
+ },
+ "4.4.4.4\/32":{
+ "routeType":"N",
+ "cost":20,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.2.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "10.0.1.0\/24":{
+ "routeType":"N IA",
+ "cost":20,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.2.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "10.0.2.0\/24":{
+ "routeType":"N",
+ "cost":10,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":" ",
+ "directlyAttachedTo":"eth-rt2"
+ }
+ ]
+ },
+ "10.0.3.0\/24":{
+ "routeType":"N",
+ "cost":20,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.2.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "2.2.2.2":{
+ "routeType":"R ",
+ "cost":10,
+ "area":"0.0.0.1",
+ "routerType":"abr",
+ "nexthops":[
+ {
+ "ip":"10.0.2.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "4.4.4.4":{
+ "routeType":"R ",
+ "cost":20,
+ "area":"0.0.0.1",
+ "routerType":"asbr",
+ "nexthops":[
+ {
+ "ip":"10.0.2.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "172.16.1.1\/32":{
+ "routeType":"N E2",
+ "cost":20,
+ "type2cost":20,
+ "tag":0,
+ "nexthops":[
+ {
+ "ip":"10.0.2.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "172.16.1.2\/32":{
+ "routeType":"N E2",
+ "cost":20,
+ "type2cost":20,
+ "tag":0,
+ "nexthops":[
+ {
+ "ip":"10.0.2.2",
+ "via":"eth-rt2"
+ }
+ ]
+ }
+}
diff --git a/tests/topotests/ospf_nssa_topo1/rt3/step4/show_ip_ospf_route.ref b/tests/topotests/ospf_nssa_topo1/rt3/step4/show_ip_ospf_route.ref
new file mode 100644
index 0000000000..10387215b2
--- /dev/null
+++ b/tests/topotests/ospf_nssa_topo1/rt3/step4/show_ip_ospf_route.ref
@@ -0,0 +1,150 @@
+{
+ "0.0.0.0\/0":{
+ "routeType":"N IA",
+ "cost":11,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.2.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "1.1.1.1\/32":{
+ "routeType":"N IA",
+ "cost":20,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.2.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "2.2.2.2\/32":{
+ "routeType":"N IA",
+ "cost":10,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.2.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "3.3.3.3\/32":{
+ "routeType":"N",
+ "cost":0,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":" ",
+ "directlyAttachedTo":"lo"
+ }
+ ]
+ },
+ "4.4.4.4\/32":{
+ "routeType":"N",
+ "cost":20,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.2.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "10.0.1.0\/24":{
+ "routeType":"N IA",
+ "cost":20,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.2.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "10.0.2.0\/24":{
+ "routeType":"N",
+ "cost":10,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":" ",
+ "directlyAttachedTo":"eth-rt2"
+ }
+ ]
+ },
+ "10.0.3.0\/24":{
+ "routeType":"N",
+ "cost":20,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.2.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "2.2.2.2":{
+ "routeType":"R ",
+ "cost":10,
+ "area":"0.0.0.1",
+ "routerType":"abr",
+ "nexthops":[
+ {
+ "ip":"10.0.2.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "4.4.4.4":{
+ "routeType":"R ",
+ "cost":20,
+ "area":"0.0.0.1",
+ "routerType":"asbr",
+ "nexthops":[
+ {
+ "ip":"10.0.2.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "172.16.1.0\/24":{
+ "routeType":"N E2",
+ "cost":10,
+ "type2cost":20,
+ "tag":0,
+ "nexthops":[
+ {
+ "ip":"10.0.2.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "172.16.1.1\/32":{
+ "routeType":"N E2",
+ "cost":20,
+ "type2cost":20,
+ "tag":0,
+ "nexthops":[
+ {
+ "ip":"10.0.2.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "172.16.1.2\/32":{
+ "routeType":"N E2",
+ "cost":20,
+ "type2cost":20,
+ "tag":0,
+ "nexthops":[
+ {
+ "ip":"10.0.2.2",
+ "via":"eth-rt2"
+ }
+ ]
+ }
+}
diff --git a/tests/topotests/ospf_nssa_topo1/rt3/step5/show_ip_ospf_route.ref b/tests/topotests/ospf_nssa_topo1/rt3/step5/show_ip_ospf_route.ref
new file mode 100644
index 0000000000..4f8eaf1eaa
--- /dev/null
+++ b/tests/topotests/ospf_nssa_topo1/rt3/step5/show_ip_ospf_route.ref
@@ -0,0 +1,138 @@
+{
+ "0.0.0.0\/0":{
+ "routeType":"N IA",
+ "cost":11,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.2.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "1.1.1.1\/32":{
+ "routeType":"N IA",
+ "cost":20,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.2.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "2.2.2.2\/32":{
+ "routeType":"N IA",
+ "cost":10,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.2.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "3.3.3.3\/32":{
+ "routeType":"N",
+ "cost":0,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":" ",
+ "directlyAttachedTo":"lo"
+ }
+ ]
+ },
+ "4.4.4.4\/32":{
+ "routeType":"N",
+ "cost":20,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.2.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "10.0.1.0\/24":{
+ "routeType":"N IA",
+ "cost":20,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.2.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "10.0.2.0\/24":{
+ "routeType":"N",
+ "cost":10,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":" ",
+ "directlyAttachedTo":"eth-rt2"
+ }
+ ]
+ },
+ "10.0.3.0\/24":{
+ "routeType":"N",
+ "cost":20,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.2.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "2.2.2.2":{
+ "routeType":"R ",
+ "cost":10,
+ "area":"0.0.0.1",
+ "routerType":"abr",
+ "nexthops":[
+ {
+ "ip":"10.0.2.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "4.4.4.4":{
+ "routeType":"R ",
+ "cost":20,
+ "area":"0.0.0.1",
+ "routerType":"asbr",
+ "nexthops":[
+ {
+ "ip":"10.0.2.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "172.16.1.0\/24":{
+ "routeType":"N E2",
+ "cost":10,
+ "type2cost":20,
+ "tag":0,
+ "nexthops":[
+ {
+ "ip":"10.0.2.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "172.16.1.2\/32":{
+ "routeType":"N E2",
+ "cost":20,
+ "type2cost":20,
+ "tag":0,
+ "nexthops":[
+ {
+ "ip":"10.0.2.2",
+ "via":"eth-rt2"
+ }
+ ]
+ }
+}
diff --git a/tests/topotests/ospf_nssa_topo1/rt3/step6/show_ip_ospf_route.ref b/tests/topotests/ospf_nssa_topo1/rt3/step6/show_ip_ospf_route.ref
new file mode 100644
index 0000000000..41e9f6718a
--- /dev/null
+++ b/tests/topotests/ospf_nssa_topo1/rt3/step6/show_ip_ospf_route.ref
@@ -0,0 +1,126 @@
+{
+ "0.0.0.0\/0":{
+ "routeType":"N IA",
+ "cost":11,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.2.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "1.1.1.1\/32":{
+ "routeType":"N IA",
+ "cost":20,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.2.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "2.2.2.2\/32":{
+ "routeType":"N IA",
+ "cost":10,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.2.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "3.3.3.3\/32":{
+ "routeType":"N",
+ "cost":0,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":" ",
+ "directlyAttachedTo":"lo"
+ }
+ ]
+ },
+ "4.4.4.4\/32":{
+ "routeType":"N",
+ "cost":20,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.2.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "10.0.1.0\/24":{
+ "routeType":"N IA",
+ "cost":20,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.2.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "10.0.2.0\/24":{
+ "routeType":"N",
+ "cost":10,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":" ",
+ "directlyAttachedTo":"eth-rt2"
+ }
+ ]
+ },
+ "10.0.3.0\/24":{
+ "routeType":"N",
+ "cost":20,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.2.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "2.2.2.2":{
+ "routeType":"R ",
+ "cost":10,
+ "area":"0.0.0.1",
+ "routerType":"abr",
+ "nexthops":[
+ {
+ "ip":"10.0.2.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "4.4.4.4":{
+ "routeType":"R ",
+ "cost":20,
+ "area":"0.0.0.1",
+ "routerType":"asbr",
+ "nexthops":[
+ {
+ "ip":"10.0.2.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "172.16.1.0\/24":{
+ "routeType":"N E2",
+ "cost":10,
+ "type2cost":20,
+ "tag":0,
+ "nexthops":[
+ {
+ "ip":"10.0.2.2",
+ "via":"eth-rt2"
+ }
+ ]
+ }
+}
diff --git a/tests/topotests/ospf_nssa_topo1/rt3/step7/show_ip_ospf_route.ref b/tests/topotests/ospf_nssa_topo1/rt3/step7/show_ip_ospf_route.ref
new file mode 100644
index 0000000000..10387215b2
--- /dev/null
+++ b/tests/topotests/ospf_nssa_topo1/rt3/step7/show_ip_ospf_route.ref
@@ -0,0 +1,150 @@
+{
+ "0.0.0.0\/0":{
+ "routeType":"N IA",
+ "cost":11,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.2.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "1.1.1.1\/32":{
+ "routeType":"N IA",
+ "cost":20,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.2.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "2.2.2.2\/32":{
+ "routeType":"N IA",
+ "cost":10,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.2.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "3.3.3.3\/32":{
+ "routeType":"N",
+ "cost":0,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":" ",
+ "directlyAttachedTo":"lo"
+ }
+ ]
+ },
+ "4.4.4.4\/32":{
+ "routeType":"N",
+ "cost":20,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.2.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "10.0.1.0\/24":{
+ "routeType":"N IA",
+ "cost":20,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.2.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "10.0.2.0\/24":{
+ "routeType":"N",
+ "cost":10,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":" ",
+ "directlyAttachedTo":"eth-rt2"
+ }
+ ]
+ },
+ "10.0.3.0\/24":{
+ "routeType":"N",
+ "cost":20,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.2.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "2.2.2.2":{
+ "routeType":"R ",
+ "cost":10,
+ "area":"0.0.0.1",
+ "routerType":"abr",
+ "nexthops":[
+ {
+ "ip":"10.0.2.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "4.4.4.4":{
+ "routeType":"R ",
+ "cost":20,
+ "area":"0.0.0.1",
+ "routerType":"asbr",
+ "nexthops":[
+ {
+ "ip":"10.0.2.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "172.16.1.0\/24":{
+ "routeType":"N E2",
+ "cost":10,
+ "type2cost":20,
+ "tag":0,
+ "nexthops":[
+ {
+ "ip":"10.0.2.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "172.16.1.1\/32":{
+ "routeType":"N E2",
+ "cost":20,
+ "type2cost":20,
+ "tag":0,
+ "nexthops":[
+ {
+ "ip":"10.0.2.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "172.16.1.2\/32":{
+ "routeType":"N E2",
+ "cost":20,
+ "type2cost":20,
+ "tag":0,
+ "nexthops":[
+ {
+ "ip":"10.0.2.2",
+ "via":"eth-rt2"
+ }
+ ]
+ }
+}
diff --git a/tests/topotests/ospf_nssa_topo1/rt3/step8/show_ip_ospf_route.ref b/tests/topotests/ospf_nssa_topo1/rt3/step8/show_ip_ospf_route.ref
new file mode 100644
index 0000000000..4619067abd
--- /dev/null
+++ b/tests/topotests/ospf_nssa_topo1/rt3/step8/show_ip_ospf_route.ref
@@ -0,0 +1,150 @@
+{
+ "0.0.0.0\/0":{
+ "routeType":"N IA",
+ "cost":11,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.2.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "1.1.1.1\/32":{
+ "routeType":"N IA",
+ "cost":20,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.2.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "2.2.2.2\/32":{
+ "routeType":"N IA",
+ "cost":10,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.2.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "3.3.3.3\/32":{
+ "routeType":"N",
+ "cost":0,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":" ",
+ "directlyAttachedTo":"lo"
+ }
+ ]
+ },
+ "4.4.4.4\/32":{
+ "routeType":"N",
+ "cost":20,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.2.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "10.0.1.0\/24":{
+ "routeType":"N IA",
+ "cost":20,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.2.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "10.0.2.0\/24":{
+ "routeType":"N",
+ "cost":10,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":" ",
+ "directlyAttachedTo":"eth-rt2"
+ }
+ ]
+ },
+ "10.0.3.0\/24":{
+ "routeType":"N",
+ "cost":20,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.2.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "2.2.2.2":{
+ "routeType":"R ",
+ "cost":10,
+ "area":"0.0.0.1",
+ "routerType":"abr",
+ "nexthops":[
+ {
+ "ip":"10.0.2.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "4.4.4.4":{
+ "routeType":"R ",
+ "cost":20,
+ "area":"0.0.0.1",
+ "routerType":"asbr",
+ "nexthops":[
+ {
+ "ip":"10.0.2.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "172.16.1.0\/24":{
+ "routeType":"N E2",
+ "cost":10,
+ "type2cost":1000,
+ "tag":0,
+ "nexthops":[
+ {
+ "ip":"10.0.2.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "172.16.1.1\/32":{
+ "routeType":"N E2",
+ "cost":20,
+ "type2cost":20,
+ "tag":0,
+ "nexthops":[
+ {
+ "ip":"10.0.2.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "172.16.1.2\/32":{
+ "routeType":"N E2",
+ "cost":20,
+ "type2cost":20,
+ "tag":0,
+ "nexthops":[
+ {
+ "ip":"10.0.2.2",
+ "via":"eth-rt2"
+ }
+ ]
+ }
+}
diff --git a/tests/topotests/ospf_nssa_topo1/rt3/step9/show_ip_ospf_route.ref b/tests/topotests/ospf_nssa_topo1/rt3/step9/show_ip_ospf_route.ref
new file mode 100644
index 0000000000..4619067abd
--- /dev/null
+++ b/tests/topotests/ospf_nssa_topo1/rt3/step9/show_ip_ospf_route.ref
@@ -0,0 +1,150 @@
+{
+ "0.0.0.0\/0":{
+ "routeType":"N IA",
+ "cost":11,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.2.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "1.1.1.1\/32":{
+ "routeType":"N IA",
+ "cost":20,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.2.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "2.2.2.2\/32":{
+ "routeType":"N IA",
+ "cost":10,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.2.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "3.3.3.3\/32":{
+ "routeType":"N",
+ "cost":0,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":" ",
+ "directlyAttachedTo":"lo"
+ }
+ ]
+ },
+ "4.4.4.4\/32":{
+ "routeType":"N",
+ "cost":20,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.2.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "10.0.1.0\/24":{
+ "routeType":"N IA",
+ "cost":20,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.2.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "10.0.2.0\/24":{
+ "routeType":"N",
+ "cost":10,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":" ",
+ "directlyAttachedTo":"eth-rt2"
+ }
+ ]
+ },
+ "10.0.3.0\/24":{
+ "routeType":"N",
+ "cost":20,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.2.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "2.2.2.2":{
+ "routeType":"R ",
+ "cost":10,
+ "area":"0.0.0.1",
+ "routerType":"abr",
+ "nexthops":[
+ {
+ "ip":"10.0.2.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "4.4.4.4":{
+ "routeType":"R ",
+ "cost":20,
+ "area":"0.0.0.1",
+ "routerType":"asbr",
+ "nexthops":[
+ {
+ "ip":"10.0.2.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "172.16.1.0\/24":{
+ "routeType":"N E2",
+ "cost":10,
+ "type2cost":1000,
+ "tag":0,
+ "nexthops":[
+ {
+ "ip":"10.0.2.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "172.16.1.1\/32":{
+ "routeType":"N E2",
+ "cost":20,
+ "type2cost":20,
+ "tag":0,
+ "nexthops":[
+ {
+ "ip":"10.0.2.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "172.16.1.2\/32":{
+ "routeType":"N E2",
+ "cost":20,
+ "type2cost":20,
+ "tag":0,
+ "nexthops":[
+ {
+ "ip":"10.0.2.2",
+ "via":"eth-rt2"
+ }
+ ]
+ }
+}
diff --git a/tests/topotests/ospf_nssa_topo1/rt3/zebra.conf b/tests/topotests/ospf_nssa_topo1/rt3/zebra.conf
new file mode 100644
index 0000000000..d943540f3b
--- /dev/null
+++ b/tests/topotests/ospf_nssa_topo1/rt3/zebra.conf
@@ -0,0 +1,18 @@
+log file zebra.log
+!
+hostname rt3
+!
+! debug zebra kernel
+! debug zebra packet
+! debug zebra mpls
+!
+interface lo
+ ip address 3.3.3.3/32
+!
+interface eth-rt2
+ ip address 10.0.2.3/24
+!
+ip forwarding
+!
+line vty
+!
diff --git a/tests/topotests/ospf_nssa_topo1/rt4/ospfd.conf b/tests/topotests/ospf_nssa_topo1/rt4/ospfd.conf
new file mode 100644
index 0000000000..cba7cf71ed
--- /dev/null
+++ b/tests/topotests/ospf_nssa_topo1/rt4/ospfd.conf
@@ -0,0 +1,24 @@
+password 1
+hostname rt4
+log file ospfd.log
+!
+! debug ospf sr
+! debug ospf te
+! debug ospf event
+! debug ospf lsa
+! debug ospf zebra
+!
+interface lo
+ ip ospf area 1
+!
+interface eth-rt2
+ ip ospf network point-to-point
+ ip ospf area 1
+ ip ospf hello-interval 3
+ ip ospf dead-interval 12
+!
+router ospf
+ router-id 4.4.4.4
+ area 1 nssa
+ redistribute static
+!
diff --git a/tests/topotests/ospf_nssa_topo1/rt4/staticd.conf b/tests/topotests/ospf_nssa_topo1/rt4/staticd.conf
new file mode 100644
index 0000000000..e00ee5dfea
--- /dev/null
+++ b/tests/topotests/ospf_nssa_topo1/rt4/staticd.conf
@@ -0,0 +1,9 @@
+log file staticd.log
+!
+hostname rt4
+!
+ip route 172.16.1.1/32 Null0
+ip route 172.16.1.2/32 Null0
+!
+line vty
+!
diff --git a/tests/topotests/ospf_nssa_topo1/rt4/step1/show_ip_ospf_route.ref b/tests/topotests/ospf_nssa_topo1/rt4/step1/show_ip_ospf_route.ref
new file mode 100644
index 0000000000..e57f542f1c
--- /dev/null
+++ b/tests/topotests/ospf_nssa_topo1/rt4/step1/show_ip_ospf_route.ref
@@ -0,0 +1,114 @@
+{
+ "0.0.0.0\/0":{
+ "routeType":"N IA",
+ "cost":11,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.3.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "1.1.1.1\/32":{
+ "routeType":"N IA",
+ "cost":20,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.3.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "2.2.2.2\/32":{
+ "routeType":"N IA",
+ "cost":10,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.3.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "3.3.3.3\/32":{
+ "routeType":"N",
+ "cost":20,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.3.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "4.4.4.4\/32":{
+ "routeType":"N",
+ "cost":0,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":" ",
+ "directlyAttachedTo":"lo"
+ }
+ ]
+ },
+ "10.0.1.0\/24":{
+ "routeType":"N IA",
+ "cost":20,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.3.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "10.0.2.0\/24":{
+ "routeType":"N",
+ "cost":20,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.3.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "10.0.3.0\/24":{
+ "routeType":"N",
+ "cost":10,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":" ",
+ "directlyAttachedTo":"eth-rt2"
+ }
+ ]
+ },
+ "2.2.2.2":{
+ "routeType":"R ",
+ "cost":10,
+ "area":"0.0.0.1",
+ "routerType":"abr",
+ "nexthops":[
+ {
+ "ip":"10.0.3.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "3.3.3.3":{
+ "routeType":"R ",
+ "cost":20,
+ "area":"0.0.0.1",
+ "routerType":"asbr",
+ "nexthops":[
+ {
+ "ip":"10.0.3.2",
+ "via":"eth-rt2"
+ }
+ ]
+ }
+}
diff --git a/tests/topotests/ospf_nssa_topo1/rt4/step10/show_ip_ospf_route.ref b/tests/topotests/ospf_nssa_topo1/rt4/step10/show_ip_ospf_route.ref
new file mode 100644
index 0000000000..82a0e1a9b4
--- /dev/null
+++ b/tests/topotests/ospf_nssa_topo1/rt4/step10/show_ip_ospf_route.ref
@@ -0,0 +1,126 @@
+{
+ "0.0.0.0\/0":{
+ "routeType":"N IA",
+ "cost":11,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.3.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "1.1.1.1\/32":{
+ "routeType":"N IA",
+ "cost":20,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.3.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "2.2.2.2\/32":{
+ "routeType":"N IA",
+ "cost":10,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.3.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "3.3.3.3\/32":{
+ "routeType":"N",
+ "cost":20,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.3.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "4.4.4.4\/32":{
+ "routeType":"N",
+ "cost":0,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":" ",
+ "directlyAttachedTo":"lo"
+ }
+ ]
+ },
+ "10.0.1.0\/24":{
+ "routeType":"N IA",
+ "cost":20,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.3.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "10.0.2.0\/24":{
+ "routeType":"N",
+ "cost":20,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.3.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "10.0.3.0\/24":{
+ "routeType":"N",
+ "cost":10,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":" ",
+ "directlyAttachedTo":"eth-rt2"
+ }
+ ]
+ },
+ "2.2.2.2":{
+ "routeType":"R ",
+ "cost":10,
+ "area":"0.0.0.1",
+ "routerType":"abr",
+ "nexthops":[
+ {
+ "ip":"10.0.3.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "3.3.3.3":{
+ "routeType":"R ",
+ "cost":20,
+ "area":"0.0.0.1",
+ "routerType":"asbr",
+ "nexthops":[
+ {
+ "ip":"10.0.3.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "172.16.1.0\/24":{
+ "routeType":"N E2",
+ "cost":10,
+ "type2cost":1000,
+ "tag":0,
+ "nexthops":[
+ {
+ "ip":"10.0.3.2",
+ "via":"eth-rt2"
+ }
+ ]
+ }
+}
diff --git a/tests/topotests/ospf_nssa_topo1/rt4/step2/show_ip_ospf_route.ref b/tests/topotests/ospf_nssa_topo1/rt4/step2/show_ip_ospf_route.ref
new file mode 100644
index 0000000000..e57f542f1c
--- /dev/null
+++ b/tests/topotests/ospf_nssa_topo1/rt4/step2/show_ip_ospf_route.ref
@@ -0,0 +1,114 @@
+{
+ "0.0.0.0\/0":{
+ "routeType":"N IA",
+ "cost":11,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.3.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "1.1.1.1\/32":{
+ "routeType":"N IA",
+ "cost":20,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.3.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "2.2.2.2\/32":{
+ "routeType":"N IA",
+ "cost":10,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.3.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "3.3.3.3\/32":{
+ "routeType":"N",
+ "cost":20,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.3.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "4.4.4.4\/32":{
+ "routeType":"N",
+ "cost":0,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":" ",
+ "directlyAttachedTo":"lo"
+ }
+ ]
+ },
+ "10.0.1.0\/24":{
+ "routeType":"N IA",
+ "cost":20,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.3.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "10.0.2.0\/24":{
+ "routeType":"N",
+ "cost":20,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.3.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "10.0.3.0\/24":{
+ "routeType":"N",
+ "cost":10,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":" ",
+ "directlyAttachedTo":"eth-rt2"
+ }
+ ]
+ },
+ "2.2.2.2":{
+ "routeType":"R ",
+ "cost":10,
+ "area":"0.0.0.1",
+ "routerType":"abr",
+ "nexthops":[
+ {
+ "ip":"10.0.3.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "3.3.3.3":{
+ "routeType":"R ",
+ "cost":20,
+ "area":"0.0.0.1",
+ "routerType":"asbr",
+ "nexthops":[
+ {
+ "ip":"10.0.3.2",
+ "via":"eth-rt2"
+ }
+ ]
+ }
+}
diff --git a/tests/topotests/ospf_nssa_topo1/rt4/step3/show_ip_ospf_route.ref b/tests/topotests/ospf_nssa_topo1/rt4/step3/show_ip_ospf_route.ref
new file mode 100644
index 0000000000..e57f542f1c
--- /dev/null
+++ b/tests/topotests/ospf_nssa_topo1/rt4/step3/show_ip_ospf_route.ref
@@ -0,0 +1,114 @@
+{
+ "0.0.0.0\/0":{
+ "routeType":"N IA",
+ "cost":11,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.3.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "1.1.1.1\/32":{
+ "routeType":"N IA",
+ "cost":20,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.3.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "2.2.2.2\/32":{
+ "routeType":"N IA",
+ "cost":10,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.3.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "3.3.3.3\/32":{
+ "routeType":"N",
+ "cost":20,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.3.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "4.4.4.4\/32":{
+ "routeType":"N",
+ "cost":0,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":" ",
+ "directlyAttachedTo":"lo"
+ }
+ ]
+ },
+ "10.0.1.0\/24":{
+ "routeType":"N IA",
+ "cost":20,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.3.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "10.0.2.0\/24":{
+ "routeType":"N",
+ "cost":20,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.3.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "10.0.3.0\/24":{
+ "routeType":"N",
+ "cost":10,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":" ",
+ "directlyAttachedTo":"eth-rt2"
+ }
+ ]
+ },
+ "2.2.2.2":{
+ "routeType":"R ",
+ "cost":10,
+ "area":"0.0.0.1",
+ "routerType":"abr",
+ "nexthops":[
+ {
+ "ip":"10.0.3.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "3.3.3.3":{
+ "routeType":"R ",
+ "cost":20,
+ "area":"0.0.0.1",
+ "routerType":"asbr",
+ "nexthops":[
+ {
+ "ip":"10.0.3.2",
+ "via":"eth-rt2"
+ }
+ ]
+ }
+}
diff --git a/tests/topotests/ospf_nssa_topo1/rt4/step4/show_ip_ospf_route.ref b/tests/topotests/ospf_nssa_topo1/rt4/step4/show_ip_ospf_route.ref
new file mode 100644
index 0000000000..5f51b3b3b8
--- /dev/null
+++ b/tests/topotests/ospf_nssa_topo1/rt4/step4/show_ip_ospf_route.ref
@@ -0,0 +1,126 @@
+{
+ "0.0.0.0\/0":{
+ "routeType":"N IA",
+ "cost":11,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.3.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "1.1.1.1\/32":{
+ "routeType":"N IA",
+ "cost":20,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.3.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "2.2.2.2\/32":{
+ "routeType":"N IA",
+ "cost":10,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.3.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "3.3.3.3\/32":{
+ "routeType":"N",
+ "cost":20,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.3.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "4.4.4.4\/32":{
+ "routeType":"N",
+ "cost":0,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":" ",
+ "directlyAttachedTo":"lo"
+ }
+ ]
+ },
+ "10.0.1.0\/24":{
+ "routeType":"N IA",
+ "cost":20,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.3.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "10.0.2.0\/24":{
+ "routeType":"N",
+ "cost":20,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.3.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "10.0.3.0\/24":{
+ "routeType":"N",
+ "cost":10,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":" ",
+ "directlyAttachedTo":"eth-rt2"
+ }
+ ]
+ },
+ "2.2.2.2":{
+ "routeType":"R ",
+ "cost":10,
+ "area":"0.0.0.1",
+ "routerType":"abr",
+ "nexthops":[
+ {
+ "ip":"10.0.3.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "3.3.3.3":{
+ "routeType":"R ",
+ "cost":20,
+ "area":"0.0.0.1",
+ "routerType":"asbr",
+ "nexthops":[
+ {
+ "ip":"10.0.3.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "172.16.1.0\/24":{
+ "routeType":"N E2",
+ "cost":10,
+ "type2cost":20,
+ "tag":0,
+ "nexthops":[
+ {
+ "ip":"10.0.3.2",
+ "via":"eth-rt2"
+ }
+ ]
+ }
+}
diff --git a/tests/topotests/ospf_nssa_topo1/rt4/step5/show_ip_ospf_route.ref b/tests/topotests/ospf_nssa_topo1/rt4/step5/show_ip_ospf_route.ref
new file mode 100644
index 0000000000..5f51b3b3b8
--- /dev/null
+++ b/tests/topotests/ospf_nssa_topo1/rt4/step5/show_ip_ospf_route.ref
@@ -0,0 +1,126 @@
+{
+ "0.0.0.0\/0":{
+ "routeType":"N IA",
+ "cost":11,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.3.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "1.1.1.1\/32":{
+ "routeType":"N IA",
+ "cost":20,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.3.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "2.2.2.2\/32":{
+ "routeType":"N IA",
+ "cost":10,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.3.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "3.3.3.3\/32":{
+ "routeType":"N",
+ "cost":20,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.3.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "4.4.4.4\/32":{
+ "routeType":"N",
+ "cost":0,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":" ",
+ "directlyAttachedTo":"lo"
+ }
+ ]
+ },
+ "10.0.1.0\/24":{
+ "routeType":"N IA",
+ "cost":20,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.3.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "10.0.2.0\/24":{
+ "routeType":"N",
+ "cost":20,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.3.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "10.0.3.0\/24":{
+ "routeType":"N",
+ "cost":10,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":" ",
+ "directlyAttachedTo":"eth-rt2"
+ }
+ ]
+ },
+ "2.2.2.2":{
+ "routeType":"R ",
+ "cost":10,
+ "area":"0.0.0.1",
+ "routerType":"abr",
+ "nexthops":[
+ {
+ "ip":"10.0.3.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "3.3.3.3":{
+ "routeType":"R ",
+ "cost":20,
+ "area":"0.0.0.1",
+ "routerType":"asbr",
+ "nexthops":[
+ {
+ "ip":"10.0.3.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "172.16.1.0\/24":{
+ "routeType":"N E2",
+ "cost":10,
+ "type2cost":20,
+ "tag":0,
+ "nexthops":[
+ {
+ "ip":"10.0.3.2",
+ "via":"eth-rt2"
+ }
+ ]
+ }
+}
diff --git a/tests/topotests/ospf_nssa_topo1/rt4/step6/show_ip_ospf_route.ref b/tests/topotests/ospf_nssa_topo1/rt4/step6/show_ip_ospf_route.ref
new file mode 100644
index 0000000000..5f51b3b3b8
--- /dev/null
+++ b/tests/topotests/ospf_nssa_topo1/rt4/step6/show_ip_ospf_route.ref
@@ -0,0 +1,126 @@
+{
+ "0.0.0.0\/0":{
+ "routeType":"N IA",
+ "cost":11,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.3.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "1.1.1.1\/32":{
+ "routeType":"N IA",
+ "cost":20,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.3.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "2.2.2.2\/32":{
+ "routeType":"N IA",
+ "cost":10,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.3.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "3.3.3.3\/32":{
+ "routeType":"N",
+ "cost":20,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.3.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "4.4.4.4\/32":{
+ "routeType":"N",
+ "cost":0,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":" ",
+ "directlyAttachedTo":"lo"
+ }
+ ]
+ },
+ "10.0.1.0\/24":{
+ "routeType":"N IA",
+ "cost":20,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.3.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "10.0.2.0\/24":{
+ "routeType":"N",
+ "cost":20,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.3.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "10.0.3.0\/24":{
+ "routeType":"N",
+ "cost":10,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":" ",
+ "directlyAttachedTo":"eth-rt2"
+ }
+ ]
+ },
+ "2.2.2.2":{
+ "routeType":"R ",
+ "cost":10,
+ "area":"0.0.0.1",
+ "routerType":"abr",
+ "nexthops":[
+ {
+ "ip":"10.0.3.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "3.3.3.3":{
+ "routeType":"R ",
+ "cost":20,
+ "area":"0.0.0.1",
+ "routerType":"asbr",
+ "nexthops":[
+ {
+ "ip":"10.0.3.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "172.16.1.0\/24":{
+ "routeType":"N E2",
+ "cost":10,
+ "type2cost":20,
+ "tag":0,
+ "nexthops":[
+ {
+ "ip":"10.0.3.2",
+ "via":"eth-rt2"
+ }
+ ]
+ }
+}
diff --git a/tests/topotests/ospf_nssa_topo1/rt4/step7/show_ip_ospf_route.ref b/tests/topotests/ospf_nssa_topo1/rt4/step7/show_ip_ospf_route.ref
new file mode 100644
index 0000000000..5f51b3b3b8
--- /dev/null
+++ b/tests/topotests/ospf_nssa_topo1/rt4/step7/show_ip_ospf_route.ref
@@ -0,0 +1,126 @@
+{
+ "0.0.0.0\/0":{
+ "routeType":"N IA",
+ "cost":11,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.3.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "1.1.1.1\/32":{
+ "routeType":"N IA",
+ "cost":20,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.3.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "2.2.2.2\/32":{
+ "routeType":"N IA",
+ "cost":10,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.3.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "3.3.3.3\/32":{
+ "routeType":"N",
+ "cost":20,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.3.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "4.4.4.4\/32":{
+ "routeType":"N",
+ "cost":0,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":" ",
+ "directlyAttachedTo":"lo"
+ }
+ ]
+ },
+ "10.0.1.0\/24":{
+ "routeType":"N IA",
+ "cost":20,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.3.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "10.0.2.0\/24":{
+ "routeType":"N",
+ "cost":20,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.3.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "10.0.3.0\/24":{
+ "routeType":"N",
+ "cost":10,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":" ",
+ "directlyAttachedTo":"eth-rt2"
+ }
+ ]
+ },
+ "2.2.2.2":{
+ "routeType":"R ",
+ "cost":10,
+ "area":"0.0.0.1",
+ "routerType":"abr",
+ "nexthops":[
+ {
+ "ip":"10.0.3.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "3.3.3.3":{
+ "routeType":"R ",
+ "cost":20,
+ "area":"0.0.0.1",
+ "routerType":"asbr",
+ "nexthops":[
+ {
+ "ip":"10.0.3.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "172.16.1.0\/24":{
+ "routeType":"N E2",
+ "cost":10,
+ "type2cost":20,
+ "tag":0,
+ "nexthops":[
+ {
+ "ip":"10.0.3.2",
+ "via":"eth-rt2"
+ }
+ ]
+ }
+}
diff --git a/tests/topotests/ospf_nssa_topo1/rt4/step8/show_ip_ospf_route.ref b/tests/topotests/ospf_nssa_topo1/rt4/step8/show_ip_ospf_route.ref
new file mode 100644
index 0000000000..82a0e1a9b4
--- /dev/null
+++ b/tests/topotests/ospf_nssa_topo1/rt4/step8/show_ip_ospf_route.ref
@@ -0,0 +1,126 @@
+{
+ "0.0.0.0\/0":{
+ "routeType":"N IA",
+ "cost":11,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.3.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "1.1.1.1\/32":{
+ "routeType":"N IA",
+ "cost":20,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.3.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "2.2.2.2\/32":{
+ "routeType":"N IA",
+ "cost":10,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.3.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "3.3.3.3\/32":{
+ "routeType":"N",
+ "cost":20,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.3.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "4.4.4.4\/32":{
+ "routeType":"N",
+ "cost":0,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":" ",
+ "directlyAttachedTo":"lo"
+ }
+ ]
+ },
+ "10.0.1.0\/24":{
+ "routeType":"N IA",
+ "cost":20,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.3.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "10.0.2.0\/24":{
+ "routeType":"N",
+ "cost":20,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.3.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "10.0.3.0\/24":{
+ "routeType":"N",
+ "cost":10,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":" ",
+ "directlyAttachedTo":"eth-rt2"
+ }
+ ]
+ },
+ "2.2.2.2":{
+ "routeType":"R ",
+ "cost":10,
+ "area":"0.0.0.1",
+ "routerType":"abr",
+ "nexthops":[
+ {
+ "ip":"10.0.3.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "3.3.3.3":{
+ "routeType":"R ",
+ "cost":20,
+ "area":"0.0.0.1",
+ "routerType":"asbr",
+ "nexthops":[
+ {
+ "ip":"10.0.3.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "172.16.1.0\/24":{
+ "routeType":"N E2",
+ "cost":10,
+ "type2cost":1000,
+ "tag":0,
+ "nexthops":[
+ {
+ "ip":"10.0.3.2",
+ "via":"eth-rt2"
+ }
+ ]
+ }
+}
diff --git a/tests/topotests/ospf_nssa_topo1/rt4/step9/show_ip_ospf_route.ref b/tests/topotests/ospf_nssa_topo1/rt4/step9/show_ip_ospf_route.ref
new file mode 100644
index 0000000000..82a0e1a9b4
--- /dev/null
+++ b/tests/topotests/ospf_nssa_topo1/rt4/step9/show_ip_ospf_route.ref
@@ -0,0 +1,126 @@
+{
+ "0.0.0.0\/0":{
+ "routeType":"N IA",
+ "cost":11,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.3.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "1.1.1.1\/32":{
+ "routeType":"N IA",
+ "cost":20,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.3.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "2.2.2.2\/32":{
+ "routeType":"N IA",
+ "cost":10,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.3.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "3.3.3.3\/32":{
+ "routeType":"N",
+ "cost":20,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.3.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "4.4.4.4\/32":{
+ "routeType":"N",
+ "cost":0,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":" ",
+ "directlyAttachedTo":"lo"
+ }
+ ]
+ },
+ "10.0.1.0\/24":{
+ "routeType":"N IA",
+ "cost":20,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.3.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "10.0.2.0\/24":{
+ "routeType":"N",
+ "cost":20,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":"10.0.3.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "10.0.3.0\/24":{
+ "routeType":"N",
+ "cost":10,
+ "area":"0.0.0.1",
+ "nexthops":[
+ {
+ "ip":" ",
+ "directlyAttachedTo":"eth-rt2"
+ }
+ ]
+ },
+ "2.2.2.2":{
+ "routeType":"R ",
+ "cost":10,
+ "area":"0.0.0.1",
+ "routerType":"abr",
+ "nexthops":[
+ {
+ "ip":"10.0.3.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "3.3.3.3":{
+ "routeType":"R ",
+ "cost":20,
+ "area":"0.0.0.1",
+ "routerType":"asbr",
+ "nexthops":[
+ {
+ "ip":"10.0.3.2",
+ "via":"eth-rt2"
+ }
+ ]
+ },
+ "172.16.1.0\/24":{
+ "routeType":"N E2",
+ "cost":10,
+ "type2cost":1000,
+ "tag":0,
+ "nexthops":[
+ {
+ "ip":"10.0.3.2",
+ "via":"eth-rt2"
+ }
+ ]
+ }
+}
diff --git a/tests/topotests/ospf_nssa_topo1/rt4/zebra.conf b/tests/topotests/ospf_nssa_topo1/rt4/zebra.conf
new file mode 100644
index 0000000000..588febe70b
--- /dev/null
+++ b/tests/topotests/ospf_nssa_topo1/rt4/zebra.conf
@@ -0,0 +1,18 @@
+log file zebra.log
+!
+hostname rt4
+!
+! debug zebra kernel
+! debug zebra packet
+! debug zebra mpls
+!
+interface lo
+ ip address 4.4.4.4/32
+!
+interface eth-rt2
+ ip address 10.0.3.4/24
+!
+ip forwarding
+!
+line vty
+!
diff --git a/tests/topotests/ospf_nssa_topo1/test_ospf_nssa_topo1.py b/tests/topotests/ospf_nssa_topo1/test_ospf_nssa_topo1.py
new file mode 100644
index 0000000000..432ddf0986
--- /dev/null
+++ b/tests/topotests/ospf_nssa_topo1/test_ospf_nssa_topo1.py
@@ -0,0 +1,416 @@
+#!/usr/bin/env python
+# SPDX-License-Identifier: ISC
+
+#
+# test_ospf_nssa_topo1.py
+# Part of NetDEF Topology Tests
+#
+# Copyright (c) 2023 by
+# Network Device Education Foundation, Inc. ("NetDEF")
+#
+
+"""
+test_ospf_nssa_topo1.py:
+
+ +---------+
+ | RT1 |
+ | 1.1.1.1 |
+ +---------+
+ |eth-rt2
+ |
+ |10.0.1.0/24
+ |
+ |eth-rt1
+ +---------+
+ | RT2 |
+ | 2.2.2.2 |
+ +---------+
+ eth-rt3| |eth-rt4
+ | |
+ 10.0.2.0/24 | | 10.0.3.0/24
+ +---------+ +--------+
+ | |
+ |eth-rt2 |eth-rt2
+ +---------+ +---------+
+ | RT3 | | RT4 |
+ | 3.3.3.3 | | 4.4.4.4 |
+ +---------+ +---------+
+
+"""
+
+import os
+import sys
+import pytest
+import json
+from functools import partial
+
+# Save the Current Working Directory to find configuration files.
+CWD = os.path.dirname(os.path.realpath(__file__))
+sys.path.append(os.path.join(CWD, "../"))
+
+# pylint: disable=C0413
+# Import topogen and topotest helpers
+from lib import topotest
+from lib.topogen import Topogen, TopoRouter, get_topogen
+from lib.topolog import logger
+
+# Required to instantiate the topology builder class.
+
+pytestmark = [pytest.mark.ospfd]
+
+
+def build_topo(tgen):
+ "Build function"
+
+ #
+ # Define FRR Routers
+ #
+ for router in ["rt1", "rt2", "rt3", "rt4"]:
+ tgen.add_router(router)
+
+ #
+ # Define connections
+ #
+ switch = tgen.add_switch("s1")
+ switch.add_link(tgen.gears["rt1"], nodeif="eth-rt2")
+ switch.add_link(tgen.gears["rt2"], nodeif="eth-rt1")
+
+ switch = tgen.add_switch("s2")
+ switch.add_link(tgen.gears["rt2"], nodeif="eth-rt3")
+ switch.add_link(tgen.gears["rt3"], nodeif="eth-rt2")
+
+ switch = tgen.add_switch("s3")
+ switch.add_link(tgen.gears["rt2"], nodeif="eth-rt4")
+ switch.add_link(tgen.gears["rt4"], nodeif="eth-rt2")
+
+
+def setup_module(mod):
+ "Sets up the pytest environment"
+ tgen = Topogen(build_topo, mod.__name__)
+ tgen.start_topology()
+
+ router_list = tgen.routers()
+
+ # 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_STATIC, os.path.join(CWD, "{}/staticd.conf".format(rname))
+ )
+ router.load_config(
+ TopoRouter.RD_OSPF, os.path.join(CWD, "{}/ospfd.conf".format(rname))
+ )
+
+ tgen.start_router()
+
+
+def teardown_module(mod):
+ "Teardown the pytest environment"
+ tgen = get_topogen()
+
+ # This function tears down the whole topology.
+ tgen.stop_topology()
+
+
+def print_cmd_result(rname, command):
+ print(get_topogen().gears[rname].vtysh_cmd(command, isjson=False))
+
+
+def router_compare_json_output(rname, command, reference):
+ "Compare router JSON output"
+
+ logger.info('Comparing router "%s" "%s" output', rname, command)
+
+ tgen = get_topogen()
+ filename = "{}/{}/{}".format(CWD, rname, reference)
+ expected = json.loads(open(filename).read())
+
+ # 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)
+ _, 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
+
+
+#
+# Step 1
+#
+# Test initial network convergence
+#
+def test_rib_step1():
+ logger.info("Test (step 1): test initial network convergence")
+ tgen = get_topogen()
+
+ # Skip if previous fatal error condition is raised
+ if tgen.routers_have_failure():
+ pytest.skip(tgen.errors)
+
+ for rname in ["rt1", "rt2", "rt3", "rt4"]:
+ router_compare_json_output(
+ rname, "show ip ospf route json", "step1/show_ip_ospf_route.ref"
+ )
+
+
+#
+# Step 2
+#
+# Action(s):
+# -rt3: configure an NSSA default route
+#
+# Expected changes:
+# -rt2: add NSSA default route pointing to rt3
+#
+def test_rib_step2():
+ logger.info("Test (step 2): verify OSPF routes")
+ tgen = get_topogen()
+
+ # Skip if previous fatal error condition is raised
+ if tgen.routers_have_failure():
+ pytest.skip(tgen.errors)
+
+ logger.info("Adding NSSA default on rt4")
+ tgen.net["rt3"].cmd(
+ 'vtysh -c "conf t" -c "router ospf" -c "area 1 nssa default-information-originate"'
+ )
+
+ for rname in ["rt1", "rt2", "rt3", "rt4"]:
+ router_compare_json_output(
+ rname, "show ip ospf route json", "step2/show_ip_ospf_route.ref"
+ )
+
+
+#
+# Step 3
+#
+# Action(s):
+# -rt3: remove NSSA default route
+#
+# Expected changes:
+# -rt2: remove NSSA default route
+#
+def test_rib_step3():
+ logger.info("Test (step 3): verify OSPF routes")
+ tgen = get_topogen()
+
+ # Skip if previous fatal error condition is raised
+ if tgen.routers_have_failure():
+ pytest.skip(tgen.errors)
+
+ logger.info("Removing NSSA default on rt4")
+ tgen.net["rt3"].cmd(
+ 'vtysh -c "conf t" -c "router ospf" -c "area 1 nssa"'
+ )
+
+ for rname in ["rt1", "rt2", "rt3", "rt4"]:
+ router_compare_json_output(
+ rname, "show ip ospf route json", "step3/show_ip_ospf_route.ref"
+ )
+
+
+#
+# Step 4
+#
+# Action(s):
+# -rt2: configure an NSSA range for 172.16.1.0/24
+#
+# Expected changes:
+# -rt1: the 172.16.1.1/32 and 172.16.1.2/32 routes should be removed
+# -rt1: the 172.16.1.0/24 route should be added
+#
+def test_rib_step4():
+ logger.info("Test (step 4): verify OSPF routes")
+ tgen = get_topogen()
+
+ # Skip if previous fatal error condition is raised
+ if tgen.routers_have_failure():
+ pytest.skip(tgen.errors)
+
+ logger.info("Configuring NSSA range on rt2")
+ tgen.net["rt2"].cmd(
+ 'vtysh -c "conf t" -c "router ospf" -c "area 1 nssa range 172.16.1.0/24"'
+ )
+
+ for rname in ["rt1", "rt2", "rt3", "rt4"]:
+ router_compare_json_output(
+ rname, "show ip ospf route json", "step4/show_ip_ospf_route.ref"
+ )
+
+
+#
+# Step 5
+#
+# Action(s):
+# -rt4: remove the 172.16.1.1/32 static route
+#
+# Expected changes:
+# -None (the 172.16.1.0/24 range is still active because of 172.16.1.2/32)
+#
+def test_rib_step5():
+ logger.info("Test (step 5): verify OSPF routes")
+ tgen = get_topogen()
+
+ # Skip if previous fatal error condition is raised
+ if tgen.routers_have_failure():
+ pytest.skip(tgen.errors)
+
+ logger.info("Removing first static route in rt4")
+ tgen.net["rt4"].cmd('vtysh -c "conf t" -c "no ip route 172.16.1.1/32 Null0"')
+
+ for rname in ["rt1", "rt2", "rt3", "rt4"]:
+ router_compare_json_output(
+ rname, "show ip ospf route json", "step5/show_ip_ospf_route.ref"
+ )
+
+
+#
+# Step 6
+#
+# Action(s):
+# -rt4: remove the 172.16.1.2/32 static route
+#
+# Expected changes:
+# -rt1: remove the 172.16.1.0/24 route since the NSSA range is no longer active
+#
+def test_rib_step6():
+ logger.info("Test (step 6): verify OSPF routes")
+ tgen = get_topogen()
+
+ # Skip if previous fatal error condition is raised
+ if tgen.routers_have_failure():
+ pytest.skip(tgen.errors)
+
+ logger.info("Removing second static route in rt4")
+ tgen.net["rt4"].cmd('vtysh -c "conf t" -c "no ip route 172.16.1.2/32 Null0"')
+
+ for rname in ["rt1", "rt2", "rt3", "rt4"]:
+ router_compare_json_output(
+ rname, "show ip ospf route json", "step6/show_ip_ospf_route.ref"
+ )
+
+
+#
+# Step 7
+#
+# Action(s):
+# -rt4: readd the 172.16.1.1/32 and 172.16.1.2/32 static routes
+#
+# Expected changes:
+# -rt1: readd the 172.16.1.0/24 route since the NSSA range is active again
+#
+def test_rib_step7():
+ logger.info("Test (step 7): verify OSPF routes")
+ tgen = get_topogen()
+
+ # Skip if previous fatal error condition is raised
+ if tgen.routers_have_failure():
+ pytest.skip(tgen.errors)
+
+ logger.info("Readding static routes in rt4")
+ tgen.net["rt4"].cmd('vtysh -c "conf t" -c "ip route 172.16.1.1/32 Null0"')
+ tgen.net["rt4"].cmd('vtysh -c "conf t" -c "ip route 172.16.1.2/32 Null0"')
+
+ for rname in ["rt1", "rt2", "rt3", "rt4"]:
+ router_compare_json_output(
+ rname, "show ip ospf route json", "step7/show_ip_ospf_route.ref"
+ )
+
+
+#
+# Step 8
+#
+# Action(s):
+# -rt2: update the NSSA range with a static cost
+#
+# Expected changes:
+# -rt1: update the metric of the 172.16.1.0/24 route from 20 to 1000
+#
+def test_rib_step8():
+ logger.info("Test (step 8): verify OSPF routes")
+ tgen = get_topogen()
+
+ # Skip if previous fatal error condition is raised
+ if tgen.routers_have_failure():
+ pytest.skip(tgen.errors)
+
+ logger.info("Updating the NSSA range cost on rt2")
+ tgen.net["rt2"].cmd(
+ 'vtysh -c "conf t" -c "router ospf" -c "area 1 nssa range 172.16.1.0/24 cost 1000"'
+ )
+
+ for rname in ["rt1", "rt2", "rt3", "rt4"]:
+ router_compare_json_output(
+ rname, "show ip ospf route json", "step8/show_ip_ospf_route.ref"
+ )
+
+
+#
+# Step 9
+#
+# Action(s):
+# -rt2: update the NSSA range to not advertise itself
+#
+# Expected changes:
+# -rt1: the 172.16.1.0/24 route should be removed
+#
+def test_rib_step9():
+ logger.info("Test (step 9): verify OSPF routes")
+ tgen = get_topogen()
+
+ # Skip if previous fatal error condition is raised
+ if tgen.routers_have_failure():
+ pytest.skip(tgen.errors)
+
+ logger.info("Updating the NSSA range to not advertise itself")
+ tgen.net["rt2"].cmd(
+ 'vtysh -c "conf t" -c "router ospf" -c "area 1 nssa range 172.16.1.0/24 not-advertise"'
+ )
+
+ for rname in ["rt1", "rt2", "rt3", "rt4"]:
+ router_compare_json_output(
+ rname, "show ip ospf route json", "step9/show_ip_ospf_route.ref"
+ )
+
+
+#
+# Step 10
+#
+# Action(s):
+# -rt2: remove the NSSA range
+#
+# Expected changes:
+# -rt1: the 172.16.1.1/32 and 172.16.1.2/32 routes should be added
+#
+def test_rib_step10():
+ logger.info("Test (step 10): verify OSPF routes")
+ tgen = get_topogen()
+
+ # Skip if previous fatal error condition is raised
+ if tgen.routers_have_failure():
+ pytest.skip(tgen.errors)
+
+ logger.info("Removing NSSA range on rt2")
+ tgen.net["rt2"].cmd(
+ 'vtysh -c "conf t" -c "router ospf" -c "no area 1 nssa range 172.16.1.0/24"'
+ )
+
+ for rname in ["rt1", "rt2", "rt3", "rt4"]:
+ router_compare_json_output(
+ rname, "show ip ospf route json", "step10/show_ip_ospf_route.ref"
+ )
+
+
+# Memory leak test template
+def test_memory_leak():
+ "Run the memory leak test and report results."
+ tgen = get_topogen()
+ if not tgen.is_memleak_enabled():
+ pytest.skip("Memory leak test/report is disabled")
+
+ tgen.report_memory_leaks()
+
+
+if __name__ == "__main__":
+ args = ["-s"] + sys.argv[1:]
+ sys.exit(pytest.main(args))
diff --git a/tests/topotests/ospf_suppress_fa/test_ospf_suppress_fa.py b/tests/topotests/ospf_suppress_fa/test_ospf_suppress_fa.py
index 5b1a53b895..d5583ac06a 100644
--- a/tests/topotests/ospf_suppress_fa/test_ospf_suppress_fa.py
+++ b/tests/topotests/ospf_suppress_fa/test_ospf_suppress_fa.py
@@ -111,9 +111,7 @@ def ospf_unconfigure_suppress_fa(router_name, area):
tgen = get_topogen()
router = tgen.gears[router_name]
- router.vtysh_cmd(
- "conf t\nrouter ospf\nno area {} nssa suppress-fa\nexit\n".format(area)
- )
+ router.vtysh_cmd("conf t\nrouter ospf\narea {} nssa\nexit\n".format(area))
def ospf_get_lsa_type5(router_name):
diff --git a/tests/topotests/ospfv3_basic_functionality/test_ospfv3_asbr_summary_topo1.py b/tests/topotests/ospfv3_basic_functionality/test_ospfv3_asbr_summary_topo1.py
index 55166367c1..b0e56e619a 100644
--- a/tests/topotests/ospfv3_basic_functionality/test_ospfv3_asbr_summary_topo1.py
+++ b/tests/topotests/ospfv3_basic_functionality/test_ospfv3_asbr_summary_topo1.py
@@ -156,7 +156,7 @@ def setup_module(mod):
pytest.skip(tgen.errors)
# Api call verify whether OSPF is converged
ospf_covergence = verify_ospf6_neighbor(tgen, topo)
- assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
+ assert ospf_covergence is True, "setup_module :Failed \n Error: {}".format(
ospf_covergence
)
@@ -280,7 +280,7 @@ def test_ospfv3_type5_summary_tc42_p0(request):
result = verify_rib(tgen, "ipv6", dut, input_dict_static_rtes, protocol=protocol)
assert (
result is True
- ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed Error: Routes is missing in RIB".format(tc_name)
step(
"Configure External Route summary in R0 to summarise 5"
@@ -314,7 +314,7 @@ def test_ospfv3_type5_summary_tc42_p0(request):
result = verify_rib(tgen, "ipv6", dut, input_dict_summary, protocol=protocol)
assert (
result is True
- ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed Error: Routes is missing in RIB".format(tc_name)
step("Verify that show ip ospf summary should show the summaries.")
input_dict = {
@@ -330,9 +330,9 @@ def test_ospfv3_type5_summary_tc42_p0(request):
result = verify_ospf_summary(tgen, topo, dut, input_dict, ospf="ospf6")
assert (
result is True
- ), "Testcase {} : Failed" "Error: Summary missing in OSPF DB".format(tc_name)
+ ), "Testcase {} : Failed Error: Summary missing in OSPF DB".format(tc_name)
- step("Verify that originally advertised routes are withdraw from there" " peer.")
+ step("Verify that originally advertised routes are withdraw from there peer.")
input_dict = {
"r0": {"static_routes": [{"network": NETWORK["ipv6"], "next_hop": "blackhole"}]}
}
@@ -340,7 +340,7 @@ def test_ospfv3_type5_summary_tc42_p0(request):
result = verify_ospf6_rib(tgen, dut, input_dict, expected=False)
assert (
result is not True
- ), "Testcase {} : Failed \n Error: " "Routes still present in OSPF RIB {}".format(
+ ), "Testcase {} : Failed \n Error: Routes still present in OSPF RIB {}".format(
tc_name, result
)
@@ -349,7 +349,7 @@ def test_ospfv3_type5_summary_tc42_p0(request):
)
assert (
result is not True
- ), "Testcase {} : Failed" "Error: Routes still present in RIB".format(tc_name)
+ ), "Testcase {} : Failed Error: Routes still present in RIB".format(tc_name)
step("Delete the configured summary")
ospf_summ_r1 = {
@@ -374,7 +374,7 @@ def test_ospfv3_type5_summary_tc42_p0(request):
result = verify_ospf6_rib(tgen, dut, input_dict, expected=False)
assert (
result is not True
- ), "Testcase {} : Failed \n Error: " "Routes still present in OSPF RIB {}".format(
+ ), "Testcase {} : Failed \n Error: Routes still present in OSPF RIB {}".format(
tc_name, result
)
@@ -383,9 +383,7 @@ def test_ospfv3_type5_summary_tc42_p0(request):
)
assert (
result is not True
- ), "Testcase {} : Failed" "Error: Summary Route still present in RIB".format(
- tc_name
- )
+ ), "Testcase {} : Failed Error: Summary Route still present in RIB".format(tc_name)
step("show ip ospf summary should not have any summary address.")
input_dict = {
@@ -403,7 +401,7 @@ def test_ospfv3_type5_summary_tc42_p0(request):
)
assert (
result is not True
- ), "Testcase {} : Failed" "Error: Summary still present in DB".format(tc_name)
+ ), "Testcase {} : Failed Error: Summary still present in DB".format(tc_name)
dut = "r1"
step("All 5 routes are advertised after deletion of configured summary.")
@@ -414,7 +412,7 @@ def test_ospfv3_type5_summary_tc42_p0(request):
result = verify_rib(tgen, "ipv6", dut, input_dict_static_rtes, protocol=protocol)
assert (
result is True
- ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed Error: Routes is missing in RIB".format(tc_name)
step("configure the summary again and delete static routes .")
ospf_summ_r1 = {
@@ -442,7 +440,7 @@ def test_ospfv3_type5_summary_tc42_p0(request):
result = verify_ospf_summary(tgen, topo, dut, input_dict, ospf="ospf6")
assert (
result is True
- ), "Testcase {} : Failed" "Error: Summary missing in OSPF DB".format(tc_name)
+ ), "Testcase {} : Failed Error: Summary missing in OSPF DB".format(tc_name)
input_dict = {
"r0": {
@@ -461,7 +459,7 @@ def test_ospfv3_type5_summary_tc42_p0(request):
result = verify_ospf6_rib(tgen, dut, input_dict_summary, expected=False)
assert (
result is not True
- ), "Testcase {} : Failed \n Error: " "Routes still present in OSPF RIB {}".format(
+ ), "Testcase {} : Failed \n Error: Routes still present in OSPF RIB {}".format(
tc_name, result
)
@@ -470,7 +468,7 @@ def test_ospfv3_type5_summary_tc42_p0(request):
)
assert (
result is not True
- ), "Testcase {} : Failed" "Error: Routes still present in RIB".format(tc_name)
+ ), "Testcase {} : Failed Error: Routes still present in RIB".format(tc_name)
step("Add back static routes.")
input_dict_static_rtes = {
@@ -488,7 +486,7 @@ def test_ospfv3_type5_summary_tc42_p0(request):
result = verify_ospf6_rib(tgen, dut, input_dict_static_rtes, expected=False)
assert (
result is not True
- ), "Testcase {} : Failed \n Error: " "Routes still present in OSPF RIB {}".format(
+ ), "Testcase {} : Failed \n Error: Routes still present in OSPF RIB {}".format(
tc_name, result
)
@@ -497,7 +495,7 @@ def test_ospfv3_type5_summary_tc42_p0(request):
)
assert (
result is not True
- ), "Testcase {} : Failed" "Error: Routes still present in RIB".format(tc_name)
+ ), "Testcase {} : Failed Error: Routes still present in RIB".format(tc_name)
input_dict_summary = {"r0": {"static_routes": [{"network": SUMMARY["ipv6"][0]}]}}
dut = "r1"
@@ -508,7 +506,7 @@ def test_ospfv3_type5_summary_tc42_p0(request):
result = verify_rib(tgen, "ipv6", dut, input_dict_summary, protocol=protocol)
assert (
result is True
- ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed Error: Routes is missing in RIB".format(tc_name)
step("Verify that show ip ospf summary should show configure summaries.")
@@ -525,7 +523,7 @@ def test_ospfv3_type5_summary_tc42_p0(request):
result = verify_ospf_summary(tgen, topo, dut, input_dict, ospf="ospf6")
assert (
result is True
- ), "Testcase {} : Failed" "Error: Summary missing in OSPF DB".format(tc_name)
+ ), "Testcase {} : Failed Error: Summary missing in OSPF DB".format(tc_name)
step("Configure new static route which is matching configured summary.")
input_dict_static_rtes = {
@@ -591,7 +589,7 @@ def test_ospfv3_type5_summary_tc42_p0(request):
result = verify_rib(tgen, "ipv6", dut, input_dict_summary, protocol=protocol)
assert (
result is True
- ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed Error: Routes is missing in RIB".format(tc_name)
step("Shut one of the interface")
intf = topo["routers"]["r0"]["links"]["r3-link0"]["interface"]
@@ -663,7 +661,7 @@ def test_ospfv3_type5_summary_tc42_p0(request):
result = verify_ospf_summary(tgen, topo, dut, input_dict, ospf="ospf6")
assert (
result is True
- ), "Testcase {} : Failed" "Error: Summary missing in OSPF DB".format(tc_name)
+ ), "Testcase {} : Failed Error: Summary missing in OSPF DB".format(tc_name)
input_dict_summary = {"r0": {"static_routes": [{"network": SUMMARY["ipv6"][0]}]}}
@@ -674,7 +672,7 @@ def test_ospfv3_type5_summary_tc42_p0(request):
result = verify_rib(tgen, "ipv6", dut, input_dict_summary, protocol=protocol)
assert (
result is True
- ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed Error: Routes is missing in RIB".format(tc_name)
ospf_summ_r1 = {
"r0": {
@@ -702,7 +700,7 @@ def test_ospfv3_type5_summary_tc42_p0(request):
result = verify_ospf6_rib(tgen, dut, input_dict_summary, expected=False)
assert (
result is not True
- ), "Testcase {} : Failed \n Error: " "Routes still present in OSPF RIB {}".format(
+ ), "Testcase {} : Failed \n Error: Routes still present in OSPF RIB {}".format(
tc_name, result
)
@@ -711,7 +709,7 @@ def test_ospfv3_type5_summary_tc42_p0(request):
)
assert (
result is not True
- ), "Testcase {} : Failed" "Error: Routes still present in RIB".format(tc_name)
+ ), "Testcase {} : Failed Error: Routes still present in RIB".format(tc_name)
ospf_summ_r1 = {
"r0": {
@@ -774,11 +772,9 @@ def test_ospfv3_type5_summary_tc43_p0(request):
result = verify_rib(tgen, "ipv6", dut, input_dict_static_rtes, protocol=protocol)
assert (
result is True
- ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed Error: Routes is missing in RIB".format(tc_name)
- step(
- "Configure External Route summary in R0 to summarise 5" " routes to one route."
- )
+ step("Configure External Route summary in R0 to summarise 5 routes to one route.")
ospf_summ_r1 = {
"r0": {
"ospf6": {
@@ -804,7 +800,7 @@ def test_ospfv3_type5_summary_tc43_p0(request):
result = verify_rib(tgen, "ipv6", dut, input_dict_summary, protocol=protocol)
assert (
result is True
- ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed Error: Routes is missing in RIB".format(tc_name)
step("Verify that show ip ospf summary should show the summaries.")
input_dict = {
@@ -820,7 +816,7 @@ def test_ospfv3_type5_summary_tc43_p0(request):
result = verify_ospf_summary(tgen, topo, dut, input_dict, ospf="ospf6")
assert (
result is True
- ), "Testcase {} : Failed" "Error: Summary missing in OSPF DB".format(tc_name)
+ ), "Testcase {} : Failed Error: Summary missing in OSPF DB".format(tc_name)
step("Change the summary address mask to lower match (ex - 16 to 8)")
ospf_summ_r1 = {
@@ -855,7 +851,7 @@ def test_ospfv3_type5_summary_tc43_p0(request):
result = verify_ospf_summary(tgen, topo, dut, input_dict, ospf="ospf6")
assert (
result is True
- ), "Testcase {} : Failed" "Error: Summary missing in OSPF DB".format(tc_name)
+ ), "Testcase {} : Failed Error: Summary missing in OSPF DB".format(tc_name)
step(
"Verify that external routes(static / connected) are summarised"
@@ -871,7 +867,7 @@ def test_ospfv3_type5_summary_tc43_p0(request):
result = verify_rib(tgen, "ipv6", dut, input_dict_summary, protocol=protocol)
assert (
result is True
- ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed Error: Routes is missing in RIB".format(tc_name)
step("Change the summary address mask to higher match (ex - 8 to 24)")
ospf_summ_r1 = {
@@ -899,7 +895,7 @@ def test_ospfv3_type5_summary_tc43_p0(request):
result = verify_ospf_summary(tgen, topo, dut, input_dict, ospf="ospf6")
assert (
result is True
- ), "Testcase {} : Failed" "Error: Summary missing in OSPF DB".format(tc_name)
+ ), "Testcase {} : Failed Error: Summary missing in OSPF DB".format(tc_name)
step(
"Verify that external routes(static / connected) are summarised"
@@ -920,7 +916,7 @@ def test_ospfv3_type5_summary_tc43_p0(request):
result = verify_rib(tgen, "ipv6", dut, input_dict_summary, protocol=protocol)
assert (
result is True
- ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed Error: Routes is missing in RIB".format(tc_name)
step(" Un configure one of the summary address.")
ospf_summ_r1 = {
@@ -955,7 +951,7 @@ def test_ospfv3_type5_summary_tc43_p0(request):
result = verify_rib(tgen, "ipv6", dut, input_dict_summary, protocol=protocol)
assert (
result is True
- ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed Error: Routes is missing in RIB".format(tc_name)
ospf_summ_r1 = {
"r0": {
@@ -982,7 +978,7 @@ def test_ospfv3_type5_summary_tc43_p0(request):
result = verify_rib(tgen, "ipv6", dut, input_dict_summary, protocol=protocol)
assert (
result is True
- ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed Error: Routes is missing in RIB".format(tc_name)
write_test_footer(tc_name)
@@ -1030,11 +1026,9 @@ def ospfv3_type5_summary_tc45_p0(request):
result = verify_rib(tgen, "ipv6", dut, input_dict_static_rtes, protocol=protocol)
assert (
result is True
- ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed Error: Routes is missing in RIB".format(tc_name)
- step(
- "Configure External Route summary in R0 to summarise 5" " routes to one route."
- )
+ step("Configure External Route summary in R0 to summarise 5 routes to one route.")
ospf_summ_r1 = {
"r0": {
"ospf6": {
@@ -1066,7 +1060,7 @@ def ospfv3_type5_summary_tc45_p0(request):
result = verify_rib(tgen, "ipv6", dut, input_dict_summary, protocol=protocol)
assert (
result is True
- ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed Error: Routes is missing in RIB".format(tc_name)
step("Verify that show ip ospf summary should show the summaries with tag.")
input_dict = {
@@ -1082,7 +1076,7 @@ def ospfv3_type5_summary_tc45_p0(request):
result = verify_ospf_summary(tgen, topo, dut, input_dict, ospf="ospf6")
assert (
result is True
- ), "Testcase {} : Failed" "Error: Summary missing in OSPF DB".format(tc_name)
+ ), "Testcase {} : Failed Error: Summary missing in OSPF DB".format(tc_name)
step("Delete the configured summary")
ospf_summ_r1 = {
@@ -1107,7 +1101,7 @@ def ospfv3_type5_summary_tc45_p0(request):
result = verify_ospf6_rib(tgen, dut, input_dict, expected=False)
assert (
result is not True
- ), "Testcase {} : Failed \n Error: " "Routes still present in OSPF RIB {}".format(
+ ), "Testcase {} : Failed \n Error: Routes still present in OSPF RIB {}".format(
tc_name, result
)
@@ -1116,9 +1110,7 @@ def ospfv3_type5_summary_tc45_p0(request):
)
assert (
result is not True
- ), "Testcase {} : Failed" "Error: Summary Route still present in RIB".format(
- tc_name
- )
+ ), "Testcase {} : Failed Error: Summary Route still present in RIB".format(tc_name)
step("show ip ospf summary should not have any summary address.")
input_dict = {
@@ -1136,7 +1128,7 @@ def ospfv3_type5_summary_tc45_p0(request):
)
assert (
result is not True
- ), "Testcase {} : Failed" "Error: Summary still present in DB".format(tc_name)
+ ), "Testcase {} : Failed Error: Summary still present in DB".format(tc_name)
step("Configure Min tag value")
ospf_summ_r1 = {
@@ -1161,7 +1153,7 @@ def ospfv3_type5_summary_tc45_p0(request):
result = verify_rib(tgen, "ipv6", dut, input_dict_summary, protocol=protocol)
assert (
result is True
- ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed Error: Routes is missing in RIB".format(tc_name)
step("Verify that show ip ospf summary should show the summaries with tag.")
input_dict = {
@@ -1177,7 +1169,7 @@ def ospfv3_type5_summary_tc45_p0(request):
result = verify_ospf_summary(tgen, topo, dut, input_dict, ospf="ospf6")
assert (
result is True
- ), "Testcase {} : Failed" "Error: Summary missing in OSPF DB".format(tc_name)
+ ), "Testcase {} : Failed Error: Summary missing in OSPF DB".format(tc_name)
step("Configure Max Tag Value")
ospf_summ_r1 = {
@@ -1207,7 +1199,7 @@ def ospfv3_type5_summary_tc45_p0(request):
result = verify_rib(tgen, "ipv6", dut, input_dict_summary, protocol=protocol)
assert (
result is True
- ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed Error: Routes is missing in RIB".format(tc_name)
step(
"Verify that boundary values tags are used for summary route"
@@ -1226,7 +1218,7 @@ def ospfv3_type5_summary_tc45_p0(request):
result = verify_ospf_summary(tgen, topo, dut, input_dict, ospf="ospf6")
assert (
result is True
- ), "Testcase {} : Failed" "Error: Summary missing in OSPF DB".format(tc_name)
+ ), "Testcase {} : Failed Error: Summary missing in OSPF DB".format(tc_name)
step("configure new static route with different tag.")
input_dict_static_rtes_11 = {
@@ -1251,7 +1243,7 @@ def ospfv3_type5_summary_tc45_p0(request):
)
assert (
result is not True
- ), "Testcase {} : Failed \n Error: " "Routes still present in OSPF RIB {}".format(
+ ), "Testcase {} : Failed \n Error: Routes still present in OSPF RIB {}".format(
tc_name, result
)
@@ -1266,7 +1258,7 @@ def ospfv3_type5_summary_tc45_p0(request):
)
assert (
result is not True
- ), "Testcase {} : Failed" "Error: Routes still present in RIB".format(tc_name)
+ ), "Testcase {} : Failed Error: Routes still present in RIB".format(tc_name)
step(
"Verify that boundary values tags are used for summary route"
@@ -1287,7 +1279,7 @@ def ospfv3_type5_summary_tc45_p0(request):
)
assert (
result is not True
- ), "Testcase {} : Failed" "Error: Summary missing in OSPF DB".format(tc_name)
+ ), "Testcase {} : Failed Error: Summary missing in OSPF DB".format(tc_name)
step("Delete the configured summary address")
ospf_summ_r1 = {
@@ -1318,7 +1310,7 @@ def ospfv3_type5_summary_tc45_p0(request):
result = verify_rib(tgen, "ipv6", dut, input_dict_static_rtes, protocol=protocol)
assert (
result is True
- ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed Error: Routes is missing in RIB".format(tc_name)
step("Verify that summary address is flushed from neighbor.")
@@ -1326,7 +1318,7 @@ def ospfv3_type5_summary_tc45_p0(request):
result = verify_ospf6_rib(tgen, dut, input_dict_summary, expected=False)
assert (
result is not True
- ), "Testcase {} : Failed \n Error: " "Routes still present in OSPF RIB {}".format(
+ ), "Testcase {} : Failed \n Error: Routes still present in OSPF RIB {}".format(
tc_name, result
)
@@ -1335,7 +1327,7 @@ def ospfv3_type5_summary_tc45_p0(request):
)
assert (
result is not True
- ), "Testcase {} : Failed" "Error: Routes still present in RIB".format(tc_name)
+ ), "Testcase {} : Failed Error: Routes still present in RIB".format(tc_name)
step("Configure summary first & then configure matching static route.")
@@ -1467,11 +1459,9 @@ def ospfv3_type5_summary_tc45_p0(request):
result = verify_rib(tgen, "ipv6", dut, input_dict_static_rtes, protocol=protocol)
assert (
result is True
- ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed Error: Routes is missing in RIB".format(tc_name)
- step(
- "Configure External Route summary in R0 to summarise 5" " routes to one route."
- )
+ step("Configure External Route summary in R0 to summarise 5 routes to one route.")
ospf_summ_r1 = {
"r0": {
"ospf6": {
@@ -1503,7 +1493,7 @@ def ospfv3_type5_summary_tc45_p0(request):
result = verify_rib(tgen, "ipv6", dut, input_dict_summary, protocol=protocol)
assert (
result is True
- ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed Error: Routes is missing in RIB".format(tc_name)
step("Verify that show ip ospf summary should show the summaries with tag.")
input_dict = {
@@ -1541,7 +1531,7 @@ def ospfv3_type5_summary_tc45_p0(request):
result = verify_ospf6_rib(tgen, dut, input_dict, expected=False)
assert (
result is not True
- ), "Testcase {} : Failed \n Error: " "Routes still present in OSPF RIB {}".format(
+ ), "Testcase {} : Failed \n Error: Routes still present in OSPF RIB {}".format(
tc_name, result
)
@@ -1550,9 +1540,7 @@ def ospfv3_type5_summary_tc45_p0(request):
)
assert (
result is not True
- ), "Testcase {} : Failed" "Error: Summary Route still present in RIB".format(
- tc_name
- )
+ ), "Testcase {} : Failed Error: Summary Route still present in RIB".format(tc_name)
step("show ip ospf summary should not have any summary address.")
input_dict = {
@@ -1570,7 +1558,7 @@ def ospfv3_type5_summary_tc45_p0(request):
)
assert (
result is not True
- ), "Testcase {} : Failed" "Error: Summary still present in DB".format(tc_name)
+ ), "Testcase {} : Failed Error: Summary still present in DB".format(tc_name)
step("Configure Min tag value")
ospf_summ_r1 = {
@@ -1595,7 +1583,7 @@ def ospfv3_type5_summary_tc45_p0(request):
result = verify_rib(tgen, "ipv6", dut, input_dict_summary, protocol=protocol)
assert (
result is True
- ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed Error: Routes is missing in RIB".format(tc_name)
step("Verify that show ip ospf summary should show the summaries with tag.")
input_dict = {
@@ -1611,7 +1599,7 @@ def ospfv3_type5_summary_tc45_p0(request):
result = verify_ospf_summary(tgen, topo, dut, input_dict, ospf="ospf6")
assert (
result is True
- ), "Testcase {} : Failed" "Error: Summary missing in OSPF DB".format(tc_name)
+ ), "Testcase {} : Failed Error: Summary missing in OSPF DB".format(tc_name)
step("Configure Max Tag Value")
ospf_summ_r1 = {
@@ -1641,7 +1629,7 @@ def ospfv3_type5_summary_tc45_p0(request):
result = verify_rib(tgen, "ipv6", dut, input_dict_summary, protocol=protocol)
assert (
result is True
- ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed Error: Routes is missing in RIB".format(tc_name)
step(
"Verify that boundary values tags are used for summary route"
@@ -1660,7 +1648,7 @@ def ospfv3_type5_summary_tc45_p0(request):
result = verify_ospf_summary(tgen, topo, dut, input_dict, ospf="ospf6")
assert (
result is True
- ), "Testcase {} : Failed" "Error: Summary missing in OSPF DB".format(tc_name)
+ ), "Testcase {} : Failed Error: Summary missing in OSPF DB".format(tc_name)
step("configure new static route with different tag.")
input_dict_static_rtes_11 = {
@@ -1685,7 +1673,7 @@ def ospfv3_type5_summary_tc45_p0(request):
)
assert (
result is not True
- ), "Testcase {} : Failed \n Error: " "Routes still present in OSPF RIB {}".format(
+ ), "Testcase {} : Failed \n Error: Routes still present in OSPF RIB {}".format(
tc_name, result
)
@@ -1700,7 +1688,7 @@ def ospfv3_type5_summary_tc45_p0(request):
)
assert (
result is not True
- ), "Testcase {} : Failed" "Error: Routes still present in RIB".format(tc_name)
+ ), "Testcase {} : Failed Error: Routes still present in RIB".format(tc_name)
step(
"Verify that boundary values tags are used for summary route"
@@ -1721,7 +1709,7 @@ def ospfv3_type5_summary_tc45_p0(request):
)
assert (
result is not True
- ), "Testcase {} : Failed" "Error: Summary missing in OSPF DB".format(tc_name)
+ ), "Testcase {} : Failed Error: Summary missing in OSPF DB".format(tc_name)
step("Delete the configured summary address")
ospf_summ_r1 = {
@@ -1752,7 +1740,7 @@ def ospfv3_type5_summary_tc45_p0(request):
result = verify_rib(tgen, "ipv6", dut, input_dict_static_rtes, protocol=protocol)
assert (
result is True
- ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed Error: Routes is missing in RIB".format(tc_name)
step("Verify that summary address is flushed from neighbor.")
@@ -1760,7 +1748,7 @@ def ospfv3_type5_summary_tc45_p0(request):
result = verify_ospf6_rib(tgen, dut, input_dict_summary, expected=False)
assert (
result is not True
- ), "Testcase {} : Failed \n Error: " "Routes still present in OSPF RIB {}".format(
+ ), "Testcase {} : Failed \n Error: Routes still present in OSPF RIB {}".format(
tc_name, result
)
@@ -1769,7 +1757,7 @@ def ospfv3_type5_summary_tc45_p0(request):
)
assert (
result is not True
- ), "Testcase {} : Failed" "Error: Routes still present in RIB".format(tc_name)
+ ), "Testcase {} : Failed Error: Routes still present in RIB".format(tc_name)
step("Configure summary first & then configure matching static route.")
@@ -1853,7 +1841,7 @@ def test_ospfv3_type5_summary_tc46_p0(request):
result = verify_rib(tgen, "ipv6", dut, input_dict_static_rtes, protocol=protocol)
assert (
result is True
- ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed Error: Routes is missing in RIB".format(tc_name)
step(
"Configure External Route summary in R0 to summarise 5"
@@ -1887,7 +1875,7 @@ def test_ospfv3_type5_summary_tc46_p0(request):
result = verify_ospf6_rib(tgen, dut, input_dict_summary, expected=False)
assert (
result is not True
- ), "Testcase {} : Failed \n Error: " "Routes still present in OSPF RIB {}".format(
+ ), "Testcase {} : Failed \n Error: Routes still present in OSPF RIB {}".format(
tc_name, result
)
@@ -1896,9 +1884,9 @@ def test_ospfv3_type5_summary_tc46_p0(request):
)
assert (
result is not True
- ), "Testcase {} : Failed" "Error: Routes still present in RIB".format(tc_name)
+ ), "Testcase {} : Failed Error: Routes still present in RIB".format(tc_name)
- step("Verify that show ip ospf summary should show the " "configured summaries.")
+ step("Verify that show ip ospf summary should show the configured summaries.")
input_dict = {
SUMMARY["ipv6"][0]: {
"summaryAddress": SUMMARY["ipv6"][0],
@@ -1909,7 +1897,7 @@ def test_ospfv3_type5_summary_tc46_p0(request):
result = verify_ospf_summary(tgen, topo, dut, input_dict, ospf="ospf6")
assert (
result is True
- ), "Testcase {} : Failed" "Error: Summary missing in OSPF DB".format(tc_name)
+ ), "Testcase {} : Failed Error: Summary missing in OSPF DB".format(tc_name)
step("Delete the configured summary")
ospf_summ_r1 = {
@@ -1936,7 +1924,7 @@ def test_ospfv3_type5_summary_tc46_p0(request):
result = verify_ospf6_rib(tgen, dut, input_dict, expected=False)
assert (
result is not True
- ), "Testcase {} : Failed \n Error: " "Routes still present in OSPF RIB {}".format(
+ ), "Testcase {} : Failed \n Error: Routes still present in OSPF RIB {}".format(
tc_name, result
)
@@ -1945,9 +1933,7 @@ def test_ospfv3_type5_summary_tc46_p0(request):
)
assert (
result is not True
- ), "Testcase {} : Failed" "Error: Summary Route still present in RIB".format(
- tc_name
- )
+ ), "Testcase {} : Failed Error: Summary Route still present in RIB".format(tc_name)
step("show ip ospf summary should not have any summary address.")
input_dict = {
@@ -1965,7 +1951,7 @@ def test_ospfv3_type5_summary_tc46_p0(request):
)
assert (
result is not True
- ), "Testcase {} : Failed" "Error: Summary still present in DB".format(tc_name)
+ ), "Testcase {} : Failed Error: Summary still present in DB".format(tc_name)
step("Reconfigure summary with no advertise.")
ospf_summ_r1 = {
@@ -1996,7 +1982,7 @@ def test_ospfv3_type5_summary_tc46_p0(request):
result = verify_ospf6_rib(tgen, dut, input_dict_summary, expected=False)
assert (
result is not True
- ), "Testcase {} : Failed \n Error: " "Routes still present in OSPF RIB {}".format(
+ ), "Testcase {} : Failed \n Error: Routes still present in OSPF RIB {}".format(
tc_name, result
)
@@ -2005,9 +1991,9 @@ def test_ospfv3_type5_summary_tc46_p0(request):
)
assert (
result is not True
- ), "Testcase {} : Failed" "Error: Routes still present in RIB".format(tc_name)
+ ), "Testcase {} : Failed Error: Routes still present in RIB".format(tc_name)
- step("Verify that show ip ospf summary should show the " "configured summaries.")
+ step("Verify that show ip ospf summary should show the configured summaries.")
input_dict = {
SUMMARY["ipv6"][0]: {
"summaryAddress": SUMMARY["ipv6"][0],
@@ -2018,7 +2004,7 @@ def test_ospfv3_type5_summary_tc46_p0(request):
result = verify_ospf_summary(tgen, topo, dut, input_dict, ospf="ospf6")
assert (
result is True
- ), "Testcase {} : Failed" "Error: Summary missing in OSPF DB".format(tc_name)
+ ), "Testcase {} : Failed Error: Summary missing in OSPF DB".format(tc_name)
step(
"Change summary address from no advertise to advertise "
@@ -2067,7 +2053,7 @@ def test_ospfv3_type5_summary_tc46_p0(request):
result = verify_rib(tgen, "ipv6", dut, input_dict_summary, protocol=protocol)
assert (
result is True
- ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed Error: Routes is missing in RIB".format(tc_name)
step("Verify that show ip ospf summary should show the summaries.")
input_dict = {
@@ -2083,9 +2069,9 @@ def test_ospfv3_type5_summary_tc46_p0(request):
result = verify_ospf_summary(tgen, topo, dut, input_dict, ospf="ospf6")
assert (
result is True
- ), "Testcase {} : Failed" "Error: Summary missing in OSPF DB".format(tc_name)
+ ), "Testcase {} : Failed Error: Summary missing in OSPF DB".format(tc_name)
- step("Verify that originally advertised routes are withdraw from there" " peer.")
+ step("Verify that originally advertised routes are withdraw from there peer.")
output = tgen.gears["r0"].vtysh_cmd(
"show ipv6 ospf6 database as-external json", isjson=True
)
@@ -2101,7 +2087,7 @@ def test_ospfv3_type5_summary_tc46_p0(request):
result = verify_ospf6_rib(tgen, dut, input_dict, expected=False)
assert (
result is not True
- ), "Testcase {} : Failed \n Error: " "Routes still present in OSPF RIB {}".format(
+ ), "Testcase {} : Failed \n Error: Routes still present in OSPF RIB {}".format(
tc_name, result
)
@@ -2110,7 +2096,7 @@ def test_ospfv3_type5_summary_tc46_p0(request):
)
assert (
result is not True
- ), "Testcase {} : Failed" "Error: Routes is present in RIB".format(tc_name)
+ ), "Testcase {} : Failed Error: Routes is present in RIB".format(tc_name)
write_test_footer(tc_name)
@@ -2157,11 +2143,9 @@ def test_ospfv3_type5_summary_tc48_p0(request):
result = verify_rib(tgen, "ipv6", dut, input_dict_static_rtes, protocol=protocol)
assert (
result is True
- ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed Error: Routes is missing in RIB".format(tc_name)
- step(
- "Configure External Route summary in R0 to summarise 5" " routes to one route."
- )
+ step("Configure External Route summary in R0 to summarise 5 routes to one route.")
ospf_summ_r1 = {
"r0": {
@@ -2189,7 +2173,7 @@ def test_ospfv3_type5_summary_tc48_p0(request):
result = verify_rib(tgen, "ipv6", dut, input_dict_summary, protocol=protocol)
assert (
result is True
- ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed Error: Routes is missing in RIB".format(tc_name)
step("Verify that show ip ospf summary should show the summaries.")
input_dict = {
@@ -2205,9 +2189,9 @@ def test_ospfv3_type5_summary_tc48_p0(request):
result = verify_ospf_summary(tgen, topo, dut, input_dict, ospf="ospf6")
assert (
result is True
- ), "Testcase {} : Failed" "Error: Summary missing in OSPF DB".format(tc_name)
+ ), "Testcase {} : Failed Error: Summary missing in OSPF DB".format(tc_name)
- step("Verify that originally advertised routes are withdraw from there" " peer.")
+ step("Verify that originally advertised routes are withdraw from there peer.")
input_dict = {
"r0": {"static_routes": [{"network": NETWORK["ipv6"], "next_hop": "blackhole"}]}
}
@@ -2215,7 +2199,7 @@ def test_ospfv3_type5_summary_tc48_p0(request):
result = verify_ospf6_rib(tgen, dut, input_dict, expected=False)
assert (
result is not True
- ), "Testcase {} : Failed \n Error: " "Routes still present in OSPF RIB {}".format(
+ ), "Testcase {} : Failed \n Error: Routes still present in OSPF RIB {}".format(
tc_name, result
)
@@ -2224,7 +2208,7 @@ def test_ospfv3_type5_summary_tc48_p0(request):
)
assert (
result is not True
- ), "Testcase {} : Failed" "Error: Routes still present in RIB".format(tc_name)
+ ), "Testcase {} : Failed Error: Routes still present in RIB".format(tc_name)
step(
"Configure route map and & rule to permit configured summary address,"
@@ -2287,7 +2271,7 @@ def test_ospfv3_type5_summary_tc48_p0(request):
result = verify_rib(tgen, "ipv6", dut, input_dict_summary, protocol=protocol)
assert (
result is True
- ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed Error: Routes is missing in RIB".format(tc_name)
input_dict = {
SUMMARY["ipv6"][0]: {
@@ -2302,7 +2286,7 @@ def test_ospfv3_type5_summary_tc48_p0(request):
result = verify_ospf_summary(tgen, topo, dut, input_dict, ospf="ospf6")
assert (
result is True
- ), "Testcase {} : Failed" "Error: Summary missing in OSPF DB".format(tc_name)
+ ), "Testcase {} : Failed Error: Summary missing in OSPF DB".format(tc_name)
step("Configure metric type as 1 in route map.")
@@ -2339,7 +2323,7 @@ def test_ospfv3_type5_summary_tc48_p0(request):
result = verify_ospf_summary(tgen, topo, dut, input_dict, ospf="ospf6")
assert (
result is True
- ), "Testcase {} : Failed" "Error: Summary missing in OSPF DB".format(tc_name)
+ ), "Testcase {} : Failed Error: Summary missing in OSPF DB".format(tc_name)
step("Un configure metric type from route map.")
@@ -2376,7 +2360,7 @@ def test_ospfv3_type5_summary_tc48_p0(request):
result = verify_ospf_summary(tgen, topo, dut, input_dict, ospf="ospf6")
assert (
result is True
- ), "Testcase {} : Failed" "Error: Summary missing in OSPF DB".format(tc_name)
+ ), "Testcase {} : Failed Error: Summary missing in OSPF DB".format(tc_name)
step("Change rule from permit to deny in prefix list.")
pfx_list = {
@@ -2407,7 +2391,7 @@ def test_ospfv3_type5_summary_tc48_p0(request):
result = verify_ospf6_rib(tgen, dut, input_dict_summary, expected=False)
assert (
result is not True
- ), "Testcase {} : Failed \n Error: " "Routes still present in OSPF RIB {}".format(
+ ), "Testcase {} : Failed \n Error: Routes still present in OSPF RIB {}".format(
tc_name, result
)
@@ -2416,7 +2400,7 @@ def test_ospfv3_type5_summary_tc48_p0(request):
)
assert (
result is not True
- ), "Testcase {} : Failed" "Error: Routes still present in RIB".format(tc_name)
+ ), "Testcase {} : Failed Error: Routes still present in RIB".format(tc_name)
write_test_footer(tc_name)
@@ -2556,7 +2540,7 @@ def test_ospfv3_type5_summary_tc51_p2(request):
result = verify_ospf_summary(tgen, topo, dut, input_dict, ospf="ospf6")
assert (
result is True
- ), "Testcase {} : Failed" "Error: Summary missing in OSPF DB".format(tc_name)
+ ), "Testcase {} : Failed Error: Summary missing in OSPF DB".format(tc_name)
write_test_footer(tc_name)
@@ -2603,11 +2587,9 @@ def test_ospfv3_type5_summary_tc49_p2(request):
result = verify_rib(tgen, "ipv6", dut, input_dict_static_rtes, protocol=protocol)
assert (
result is True
- ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed Error: Routes is missing in RIB".format(tc_name)
- step(
- "Configure External Route summary in R0 to summarise 5" " routes to one route."
- )
+ step("Configure External Route summary in R0 to summarise 5 routes to one route.")
ospf_summ_r1 = {
"r0": {
@@ -2635,7 +2617,7 @@ def test_ospfv3_type5_summary_tc49_p2(request):
result = verify_rib(tgen, "ipv6", dut, input_dict_summary, protocol=protocol)
assert (
result is True
- ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed Error: Routes is missing in RIB".format(tc_name)
step("Verify that show ip ospf summary should show the summaries.")
input_dict = {
@@ -2651,9 +2633,9 @@ def test_ospfv3_type5_summary_tc49_p2(request):
result = verify_ospf_summary(tgen, topo, dut, input_dict, ospf="ospf6")
assert (
result is True
- ), "Testcase {} : Failed" "Error: Summary missing in OSPF DB".format(tc_name)
+ ), "Testcase {} : Failed Error: Summary missing in OSPF DB".format(tc_name)
- step("Verify that originally advertised routes are withdraw from there" " peer.")
+ step("Verify that originally advertised routes are withdraw from there peer.")
input_dict = {
"r0": {"static_routes": [{"network": NETWORK["ipv6"], "next_hop": "blackhole"}]}
}
@@ -2661,7 +2643,7 @@ def test_ospfv3_type5_summary_tc49_p2(request):
result = verify_ospf6_rib(tgen, dut, input_dict, expected=False)
assert (
result is not True
- ), "Testcase {} : Failed \n Error: " "Routes still present in OSPF RIB {}".format(
+ ), "Testcase {} : Failed \n Error: Routes still present in OSPF RIB {}".format(
tc_name, result
)
@@ -2670,7 +2652,7 @@ def test_ospfv3_type5_summary_tc49_p2(request):
)
assert (
result is not True
- ), "Testcase {} : Failed" "Error: Routes still present in RIB".format(tc_name)
+ ), "Testcase {} : Failed Error: Routes still present in RIB".format(tc_name)
step("Reload the FRR router")
# stop/start -> restart FRR router and verify
@@ -2691,7 +2673,7 @@ def test_ospfv3_type5_summary_tc49_p2(request):
result = verify_rib(tgen, "ipv6", dut, input_dict_summary, protocol=protocol)
assert (
result is True
- ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed Error: Routes is missing in RIB".format(tc_name)
step("Verify that show ip ospf summary should show the summaries.")
input_dict = {
@@ -2707,9 +2689,9 @@ def test_ospfv3_type5_summary_tc49_p2(request):
result = verify_ospf_summary(tgen, topo, dut, input_dict, ospf="ospf6")
assert (
result is True
- ), "Testcase {} : Failed" "Error: Summary missing in OSPF DB".format(tc_name)
+ ), "Testcase {} : Failed Error: Summary missing in OSPF DB".format(tc_name)
- step("Verify that originally advertised routes are withdraw from there" " peer.")
+ step("Verify that originally advertised routes are withdraw from there peer.")
input_dict = {
"r0": {"static_routes": [{"network": NETWORK["ipv6"], "next_hop": "blackhole"}]}
}
@@ -2717,7 +2699,7 @@ def test_ospfv3_type5_summary_tc49_p2(request):
result = verify_ospf6_rib(tgen, dut, input_dict, expected=False)
assert (
result is not True
- ), "Testcase {} : Failed \n Error: " "Routes still present in OSPF RIB {}".format(
+ ), "Testcase {} : Failed \n Error: Routes still present in OSPF RIB {}".format(
tc_name, result
)
@@ -2726,7 +2708,7 @@ def test_ospfv3_type5_summary_tc49_p2(request):
)
assert (
result is not True
- ), "Testcase {} : Failed" "Error: Routes still present in RIB".format(tc_name)
+ ), "Testcase {} : Failed Error: Routes still present in RIB".format(tc_name)
write_test_footer(tc_name)
diff --git a/tests/topotests/ospfv3_basic_functionality/test_ospfv3_authentication.py b/tests/topotests/ospfv3_basic_functionality/test_ospfv3_authentication.py
index 2f90c98785..58608e249b 100644
--- a/tests/topotests/ospfv3_basic_functionality/test_ospfv3_authentication.py
+++ b/tests/topotests/ospfv3_basic_functionality/test_ospfv3_authentication.py
@@ -111,7 +111,7 @@ def setup_module(mod):
pytest.skip(tgen.errors)
ospf6_covergence = verify_ospf6_neighbor(tgen, topo)
- assert ospf6_covergence is True, "setup_module :Failed \n Error:" " {}".format(
+ assert ospf6_covergence is True, "setup_module :Failed \n Error: {}".format(
ospf6_covergence
)
@@ -182,7 +182,7 @@ def test_ospf6_auth_trailer_tc1_md5(request):
ospf6_covergence = verify_ospf6_neighbor(
tgen, topo, dut=dut, expected=False, retry_timeout=3
)
- assert ospf6_covergence is not True, "Testcase {} :Failed \n Error:" " {}".format(
+ assert ospf6_covergence is not True, "Testcase {} :Failed \n Error: {}".format(
tc_name, ospf6_covergence
)
@@ -214,7 +214,7 @@ def test_ospf6_auth_trailer_tc1_md5(request):
dut = "r2"
ospf6_covergence = verify_ospf6_neighbor(tgen, topo, dut=dut)
- assert ospf6_covergence is True, "Testcase {} :Failed \n Error:" " {}".format(
+ assert ospf6_covergence is True, "Testcase {} :Failed \n Error: {}".format(
tc_name, ospf6_covergence
)
@@ -244,7 +244,7 @@ def test_ospf6_auth_trailer_tc1_md5(request):
ospf6_covergence = verify_ospf6_neighbor(
tgen, topo, dut=dut, expected=False, retry_timeout=5
)
- assert ospf6_covergence is not True, "Testcase {} :Failed \n Error:" " {}".format(
+ assert ospf6_covergence is not True, "Testcase {} :Failed \n Error: {}".format(
tc_name, ospf6_covergence
)
@@ -272,7 +272,7 @@ def test_ospf6_auth_trailer_tc1_md5(request):
dut = "r2"
ospf6_covergence = verify_ospf6_neighbor(tgen, topo, dut=dut)
- assert ospf6_covergence is True, "Testcase {} :Failed \n Error:" " {}".format(
+ assert ospf6_covergence is True, "Testcase {} :Failed \n Error: {}".format(
tc_name, ospf6_covergence
)
@@ -287,7 +287,7 @@ def test_ospf6_auth_trailer_tc1_md5(request):
"show ip ospf6 neighbor cmd."
)
ospf6_covergence = verify_ospf6_neighbor(tgen, topo, dut=dut, expected=False)
- assert ospf6_covergence is not True, "Testcase {} :Failed \n Error:" " {}".format(
+ assert ospf6_covergence is not True, "Testcase {} :Failed \n Error: {}".format(
tc_name, ospf6_covergence
)
@@ -301,7 +301,7 @@ def test_ospf6_auth_trailer_tc1_md5(request):
dut = "r2"
ospf6_covergence = verify_ospf6_neighbor(tgen, topo, dut=dut)
- assert ospf6_covergence is True, "Testcase {} :Failed \n Error:" " {}".format(
+ assert ospf6_covergence is True, "Testcase {} :Failed \n Error: {}".format(
tc_name, ospf6_covergence
)
@@ -348,7 +348,7 @@ def test_ospf6_auth_trailer_tc2_sha256(request):
ospf6_covergence = verify_ospf6_neighbor(
tgen, topo, dut=dut, expected=False, retry_timeout=3
)
- assert ospf6_covergence is not True, "Testcase {} :Failed \n Error:" " {}".format(
+ assert ospf6_covergence is not True, "Testcase {} :Failed \n Error: {}".format(
tc_name, ospf6_covergence
)
@@ -380,7 +380,7 @@ def test_ospf6_auth_trailer_tc2_sha256(request):
dut = "r2"
ospf6_covergence = verify_ospf6_neighbor(tgen, topo, dut=dut)
- assert ospf6_covergence is True, "Testcase {} :Failed \n Error:" " {}".format(
+ assert ospf6_covergence is True, "Testcase {} :Failed \n Error: {}".format(
tc_name, ospf6_covergence
)
@@ -410,7 +410,7 @@ def test_ospf6_auth_trailer_tc2_sha256(request):
ospf6_covergence = verify_ospf6_neighbor(
tgen, topo, dut=dut, expected=False, retry_timeout=5
)
- assert ospf6_covergence is not True, "Testcase {} :Failed \n Error:" " {}".format(
+ assert ospf6_covergence is not True, "Testcase {} :Failed \n Error: {}".format(
tc_name, ospf6_covergence
)
@@ -438,7 +438,7 @@ def test_ospf6_auth_trailer_tc2_sha256(request):
dut = "r2"
ospf6_covergence = verify_ospf6_neighbor(tgen, topo, dut=dut)
- assert ospf6_covergence is True, "Testcase {} :Failed \n Error:" " {}".format(
+ assert ospf6_covergence is True, "Testcase {} :Failed \n Error: {}".format(
tc_name, ospf6_covergence
)
@@ -453,7 +453,7 @@ def test_ospf6_auth_trailer_tc2_sha256(request):
"show ip ospf6 neighbor cmd."
)
ospf6_covergence = verify_ospf6_neighbor(tgen, topo, dut=dut, expected=False)
- assert ospf6_covergence is not True, "Testcase {} :Failed \n Error:" " {}".format(
+ assert ospf6_covergence is not True, "Testcase {} :Failed \n Error: {}".format(
tc_name, ospf6_covergence
)
@@ -467,7 +467,7 @@ def test_ospf6_auth_trailer_tc2_sha256(request):
dut = "r2"
ospf6_covergence = verify_ospf6_neighbor(tgen, topo, dut=dut)
- assert ospf6_covergence is True, "Testcase {} :Failed \n Error:" " {}".format(
+ assert ospf6_covergence is True, "Testcase {} :Failed \n Error: {}".format(
tc_name, ospf6_covergence
)
@@ -531,7 +531,7 @@ def test_ospf6_auth_trailer_tc3_keychain_md5(request):
ospf6_covergence = verify_ospf6_neighbor(
tgen, topo, dut=dut, expected=False, retry_timeout=3
)
- assert ospf6_covergence is not True, "Testcase {} :Failed \n Error:" " {}".format(
+ assert ospf6_covergence is not True, "Testcase {} :Failed \n Error: {}".format(
tc_name, ospf6_covergence
)
@@ -561,7 +561,7 @@ def test_ospf6_auth_trailer_tc3_keychain_md5(request):
dut = "r2"
ospf6_covergence = verify_ospf6_neighbor(tgen, topo, dut=dut)
- assert ospf6_covergence is True, "Testcase {} :Failed \n Error:" " {}".format(
+ assert ospf6_covergence is True, "Testcase {} :Failed \n Error: {}".format(
tc_name, ospf6_covergence
)
@@ -580,7 +580,7 @@ def test_ospf6_auth_trailer_tc3_keychain_md5(request):
ospf6_covergence = verify_ospf6_neighbor(
tgen, topo, dut=dut, expected=False, retry_timeout=5
)
- assert ospf6_covergence is not True, "Testcase {} :Failed \n Error:" " {}".format(
+ assert ospf6_covergence is not True, "Testcase {} :Failed \n Error: {}".format(
tc_name, ospf6_covergence
)
@@ -606,7 +606,7 @@ def test_ospf6_auth_trailer_tc3_keychain_md5(request):
dut = "r2"
ospf6_covergence = verify_ospf6_neighbor(tgen, topo, dut=dut)
- assert ospf6_covergence is True, "Testcase {} :Failed \n Error:" " {}".format(
+ assert ospf6_covergence is True, "Testcase {} :Failed \n Error: {}".format(
tc_name, ospf6_covergence
)
@@ -621,7 +621,7 @@ def test_ospf6_auth_trailer_tc3_keychain_md5(request):
"show ip ospf6 neighbor cmd."
)
ospf6_covergence = verify_ospf6_neighbor(tgen, topo, dut=dut, expected=False)
- assert ospf6_covergence is not True, "Testcase {} :Failed \n Error:" " {}".format(
+ assert ospf6_covergence is not True, "Testcase {} :Failed \n Error: {}".format(
tc_name, ospf6_covergence
)
@@ -635,7 +635,7 @@ def test_ospf6_auth_trailer_tc3_keychain_md5(request):
dut = "r2"
ospf6_covergence = verify_ospf6_neighbor(tgen, topo, dut=dut)
- assert ospf6_covergence is True, "Testcase {} :Failed \n Error:" " {}".format(
+ assert ospf6_covergence is True, "Testcase {} :Failed \n Error: {}".format(
tc_name, ospf6_covergence
)
@@ -699,7 +699,7 @@ def test_ospf6_auth_trailer_tc4_keychain_sha256(request):
ospf6_covergence = verify_ospf6_neighbor(
tgen, topo, dut=dut, expected=False, retry_timeout=3
)
- assert ospf6_covergence is not True, "Testcase {} :Failed \n Error:" " {}".format(
+ assert ospf6_covergence is not True, "Testcase {} :Failed \n Error: {}".format(
tc_name, ospf6_covergence
)
@@ -729,7 +729,7 @@ def test_ospf6_auth_trailer_tc4_keychain_sha256(request):
dut = "r2"
ospf6_covergence = verify_ospf6_neighbor(tgen, topo, dut=dut)
- assert ospf6_covergence is True, "Testcase {} :Failed \n Error:" " {}".format(
+ assert ospf6_covergence is True, "Testcase {} :Failed \n Error: {}".format(
tc_name, ospf6_covergence
)
@@ -748,7 +748,7 @@ def test_ospf6_auth_trailer_tc4_keychain_sha256(request):
ospf6_covergence = verify_ospf6_neighbor(
tgen, topo, dut=dut, expected=False, retry_timeout=5
)
- assert ospf6_covergence is not True, "Testcase {} :Failed \n Error:" " {}".format(
+ assert ospf6_covergence is not True, "Testcase {} :Failed \n Error: {}".format(
tc_name, ospf6_covergence
)
@@ -774,7 +774,7 @@ def test_ospf6_auth_trailer_tc4_keychain_sha256(request):
dut = "r2"
ospf6_covergence = verify_ospf6_neighbor(tgen, topo, dut=dut)
- assert ospf6_covergence is True, "Testcase {} :Failed \n Error:" " {}".format(
+ assert ospf6_covergence is True, "Testcase {} :Failed \n Error: {}".format(
tc_name, ospf6_covergence
)
@@ -789,7 +789,7 @@ def test_ospf6_auth_trailer_tc4_keychain_sha256(request):
"show ip ospf6 neighbor cmd."
)
ospf6_covergence = verify_ospf6_neighbor(tgen, topo, dut=dut, expected=False)
- assert ospf6_covergence is not True, "Testcase {} :Failed \n Error:" " {}".format(
+ assert ospf6_covergence is not True, "Testcase {} :Failed \n Error: {}".format(
tc_name, ospf6_covergence
)
@@ -803,7 +803,7 @@ def test_ospf6_auth_trailer_tc4_keychain_sha256(request):
dut = "r2"
ospf6_covergence = verify_ospf6_neighbor(tgen, topo, dut=dut)
- assert ospf6_covergence is True, "Testcase {} :Failed \n Error:" " {}".format(
+ assert ospf6_covergence is True, "Testcase {} :Failed \n Error: {}".format(
tc_name, ospf6_covergence
)
@@ -850,7 +850,7 @@ def test_ospf6_auth_trailer_tc5_md5_keymissmatch(request):
ospf6_covergence = verify_ospf6_neighbor(
tgen, topo, dut=dut, expected=False, retry_timeout=3
)
- assert ospf6_covergence is not True, "Testcase {} :Failed \n Error:" " {}".format(
+ assert ospf6_covergence is not True, "Testcase {} :Failed \n Error: {}".format(
tc_name, ospf6_covergence
)
@@ -887,7 +887,7 @@ def test_ospf6_auth_trailer_tc5_md5_keymissmatch(request):
ospf6_covergence = verify_ospf6_neighbor(
tgen, topo, dut=dut, expected=False, retry_timeout=3
)
- assert ospf6_covergence is not True, "Testcase {} :Failed \n Error:" " {}".format(
+ assert ospf6_covergence is not True, "Testcase {} :Failed \n Error: {}".format(
tc_name, ospf6_covergence
)
@@ -919,7 +919,7 @@ def test_ospf6_auth_trailer_tc5_md5_keymissmatch(request):
dut = "r2"
ospf6_covergence = verify_ospf6_neighbor(tgen, topo, dut=dut)
- assert ospf6_covergence is True, "Testcase {} :Failed \n Error:" " {}".format(
+ assert ospf6_covergence is True, "Testcase {} :Failed \n Error: {}".format(
tc_name, ospf6_covergence
)
@@ -966,7 +966,7 @@ def test_ospf6_auth_trailer_tc6_sha256_mismatch(request):
ospf6_covergence = verify_ospf6_neighbor(
tgen, topo, dut=dut, expected=False, retry_timeout=3
)
- assert ospf6_covergence is not True, "Testcase {} :Failed \n Error:" " {}".format(
+ assert ospf6_covergence is not True, "Testcase {} :Failed \n Error: {}".format(
tc_name, ospf6_covergence
)
@@ -998,7 +998,7 @@ def test_ospf6_auth_trailer_tc6_sha256_mismatch(request):
ospf6_covergence = verify_ospf6_neighbor(
tgen, topo, dut=dut, expected=False, retry_timeout=3
)
- assert ospf6_covergence is not True, "Testcase {} :Failed \n Error:" " {}".format(
+ assert ospf6_covergence is not True, "Testcase {} :Failed \n Error: {}".format(
tc_name, ospf6_covergence
)
@@ -1030,7 +1030,7 @@ def test_ospf6_auth_trailer_tc6_sha256_mismatch(request):
dut = "r2"
ospf6_covergence = verify_ospf6_neighbor(tgen, topo, dut=dut)
- assert ospf6_covergence is True, "Testcase {} :Failed \n Error:" " {}".format(
+ assert ospf6_covergence is True, "Testcase {} :Failed \n Error: {}".format(
tc_name, ospf6_covergence
)
@@ -1102,7 +1102,7 @@ def test_ospf6_auth_trailer_tc7_keychain_md5_missmatch(request):
ospf6_covergence = verify_ospf6_neighbor(
tgen, topo, dut=dut, expected=False, retry_timeout=3
)
- assert ospf6_covergence is not True, "Testcase {} :Failed \n Error:" " {}".format(
+ assert ospf6_covergence is not True, "Testcase {} :Failed \n Error: {}".format(
tc_name, ospf6_covergence
)
@@ -1132,7 +1132,7 @@ def test_ospf6_auth_trailer_tc7_keychain_md5_missmatch(request):
ospf6_covergence = verify_ospf6_neighbor(
tgen, topo, dut=dut, expected=False, retry_timeout=3
)
- assert ospf6_covergence is not True, "Testcase {} :Failed \n Error:" " {}".format(
+ assert ospf6_covergence is not True, "Testcase {} :Failed \n Error: {}".format(
tc_name, ospf6_covergence
)
@@ -1162,7 +1162,7 @@ def test_ospf6_auth_trailer_tc7_keychain_md5_missmatch(request):
dut = "r2"
ospf6_covergence = verify_ospf6_neighbor(tgen, topo, dut=dut)
- assert ospf6_covergence is True, "Testcase {} :Failed \n Error:" " {}".format(
+ assert ospf6_covergence is True, "Testcase {} :Failed \n Error: {}".format(
tc_name, ospf6_covergence
)
@@ -1234,7 +1234,7 @@ def test_ospf6_auth_trailer_tc8_keychain_sha256_missmatch(request):
ospf6_covergence = verify_ospf6_neighbor(
tgen, topo, dut=dut, expected=False, retry_timeout=3
)
- assert ospf6_covergence is not True, "Testcase {} :Failed \n Error:" " {}".format(
+ assert ospf6_covergence is not True, "Testcase {} :Failed \n Error: {}".format(
tc_name, ospf6_covergence
)
@@ -1264,7 +1264,7 @@ def test_ospf6_auth_trailer_tc8_keychain_sha256_missmatch(request):
ospf6_covergence = verify_ospf6_neighbor(
tgen, topo, dut=dut, expected=False, retry_timeout=3
)
- assert ospf6_covergence is not True, "Testcase {} :Failed \n Error:" " {}".format(
+ assert ospf6_covergence is not True, "Testcase {} :Failed \n Error: {}".format(
tc_name, ospf6_covergence
)
@@ -1294,7 +1294,7 @@ def test_ospf6_auth_trailer_tc8_keychain_sha256_missmatch(request):
dut = "r2"
ospf6_covergence = verify_ospf6_neighbor(tgen, topo, dut=dut)
- assert ospf6_covergence is True, "Testcase {} :Failed \n Error:" " {}".format(
+ assert ospf6_covergence is True, "Testcase {} :Failed \n Error: {}".format(
tc_name, ospf6_covergence
)
@@ -1342,7 +1342,7 @@ def test_ospf6_auth_trailer_tc9_keychain_not_configured(request):
ospf6_covergence = verify_ospf6_neighbor(
tgen, topo, dut=dut, expected=False, retry_timeout=3
)
- assert ospf6_covergence is not True, "Testcase {} :Failed \n Error:" " {}".format(
+ assert ospf6_covergence is not True, "Testcase {} :Failed \n Error: {}".format(
tc_name, ospf6_covergence
)
@@ -1372,7 +1372,7 @@ def test_ospf6_auth_trailer_tc9_keychain_not_configured(request):
ospf6_covergence = verify_ospf6_neighbor(
tgen, topo, dut=dut, expected=False, retry_timeout=3
)
- assert ospf6_covergence is not True, "Testcase {} :Failed \n Error:" " {}".format(
+ assert ospf6_covergence is not True, "Testcase {} :Failed \n Error: {}".format(
tc_name, ospf6_covergence
)
@@ -1402,7 +1402,7 @@ def test_ospf6_auth_trailer_tc10_no_auth_trailer(request):
dut = "r2"
ospf6_covergence = verify_ospf6_neighbor(tgen, topo, dut=dut)
- assert ospf6_covergence is True, "Testcase {} :Failed \n Error:" " {}".format(
+ assert ospf6_covergence is True, "Testcase {} :Failed \n Error: {}".format(
tc_name, ospf6_covergence
)
diff --git a/tests/topotests/ospfv3_basic_functionality/test_ospfv3_ecmp.py b/tests/topotests/ospfv3_basic_functionality/test_ospfv3_ecmp.py
index 472364e84f..0c1e3fa43e 100644
--- a/tests/topotests/ospfv3_basic_functionality/test_ospfv3_ecmp.py
+++ b/tests/topotests/ospfv3_basic_functionality/test_ospfv3_ecmp.py
@@ -115,7 +115,7 @@ def setup_module(mod):
pytest.skip(tgen.errors)
ospf_covergence = verify_ospf6_neighbor(tgen, topo)
- assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
+ assert ospf_covergence is True, "setup_module :Failed \n Error: {}".format(
ospf_covergence
)
@@ -257,7 +257,7 @@ def test_ospfv3_ecmp_tc16_p0(request):
step("Verify that OSPF is up with 8 neighborship sessions.")
dut = "r1"
ospf_covergence = verify_ospf6_neighbor(tgen, topo, dut=dut)
- assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
+ assert ospf_covergence is True, "Testcase Failed \n Error: {}".format(
ospf_covergence
)
@@ -352,7 +352,7 @@ def test_ospfv3_ecmp_tc16_p0(request):
step("Verify that OSPF is up with 8 neighborship sessions.")
dut = "r1"
ospf_covergence = verify_ospf6_neighbor(tgen, topo, dut=dut)
- assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
+ assert ospf_covergence is True, "Testcase Failed \n Error: {}".format(
ospf_covergence
)
@@ -390,7 +390,7 @@ def test_ospfv3_ecmp_tc17_p0(request):
step("Verify that OSPF is up with 2 neighborship sessions.")
dut = "r1"
ospf_covergence = verify_ospf6_neighbor(tgen, topo, dut=dut)
- assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
+ assert ospf_covergence is True, "Testcase Failed \n Error: {}".format(
ospf_covergence
)
diff --git a/tests/topotests/ospfv3_basic_functionality/test_ospfv3_ecmp_lan.py b/tests/topotests/ospfv3_basic_functionality/test_ospfv3_ecmp_lan.py
index 6b3e16965c..7c6773260e 100644
--- a/tests/topotests/ospfv3_basic_functionality/test_ospfv3_ecmp_lan.py
+++ b/tests/topotests/ospfv3_basic_functionality/test_ospfv3_ecmp_lan.py
@@ -128,7 +128,7 @@ def setup_module(mod):
pytest.skip(tgen.errors)
# Api call verify whether OSPF is converged
ospf_covergence = verify_ospf6_neighbor(tgen, topo, lan=True)
- assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
+ assert ospf_covergence is True, "setup_module :Failed \n Error: {}".format(
ospf_covergence
)
@@ -282,7 +282,7 @@ def test_ospfv3_lan_ecmp_tc18_p0(request):
step("Verify that OSPF is up with 8 neighborship sessions.")
ospf_covergence = verify_ospf6_neighbor(tgen, topo, lan=True)
- assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
+ assert ospf_covergence is True, "Testcase Failed \n Error: {}".format(
ospf_covergence
)
@@ -343,7 +343,7 @@ def test_ospfv3_lan_ecmp_tc18_p0(request):
dut = "r0"
ospf_covergence = verify_ospf6_neighbor(tgen, topo, dut=dut, lan=True)
- assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
+ assert ospf_covergence is True, "Testcase Failed \n Error: {}".format(
ospf_covergence
)
@@ -352,7 +352,7 @@ def test_ospfv3_lan_ecmp_tc18_p0(request):
dut = "r2"
ospf_covergence = verify_ospf6_neighbor(tgen, topo, dut=dut, lan=True)
- assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
+ assert ospf_covergence is True, "Testcase Failed \n Error: {}".format(
ospf_covergence
)
diff --git a/tests/topotests/ospfv3_basic_functionality/test_ospfv3_nssa.py b/tests/topotests/ospfv3_basic_functionality/test_ospfv3_nssa.py
index c0d8d718cc..dc4ce88830 100644
--- a/tests/topotests/ospfv3_basic_functionality/test_ospfv3_nssa.py
+++ b/tests/topotests/ospfv3_basic_functionality/test_ospfv3_nssa.py
@@ -73,7 +73,7 @@ def setup_module(mod):
pytest.skip(tgen.errors)
result = verify_ospf6_neighbor(tgen, topo)
- assert result is True, "setup_module: Failed \n Error:" " {}".format(result)
+ assert result is True, "setup_module: Failed \n Error: {}".format(result)
logger.info("Running setup_module() done")
diff --git a/tests/topotests/ospfv3_basic_functionality/test_ospfv3_nssa2.py b/tests/topotests/ospfv3_basic_functionality/test_ospfv3_nssa2.py
index 138112775f..90548fb5ce 100644
--- a/tests/topotests/ospfv3_basic_functionality/test_ospfv3_nssa2.py
+++ b/tests/topotests/ospfv3_basic_functionality/test_ospfv3_nssa2.py
@@ -138,7 +138,7 @@ def setup_module(mod):
# Api call verify whether OSPF is converged
ospf_covergence = verify_ospf6_neighbor(tgen, topo)
- assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
+ assert ospf_covergence is True, "setup_module :Failed \n Error: {}".format(
ospf_covergence
)
@@ -277,7 +277,7 @@ def test_ospfv3_nssa_tc26_p0(request):
result = verify_ospf6_neighbor(tgen, topo, dut="r2", expected=False)
assert (
result is not True
- ), "Testcase {} : Failed \n Nbrs are not down" "Error: {}".format(tc_name, result)
+ ), "Testcase {} : Failed \n Nbrs are not down Error: {}".format(tc_name, result)
step("Now configure area 0 on interface of r1 connecting to r2.")
@@ -349,7 +349,7 @@ def test_ospfv3_nssa_tc26_p0(request):
result = verify_ospf6_neighbor(tgen, topo, dut="r2", expected=False)
assert (
result is not True
- ), "Testcase {} : Failed \n Nbrs are not down" "Error: {}".format(tc_name, result)
+ ), "Testcase {} : Failed \n Nbrs are not down Error: {}".format(tc_name, result)
step("Now configure area 2 on interface of r1 connecting to r2.")
@@ -471,7 +471,7 @@ def test_ospfv3_learning_tc15_p0(request):
result = verify_ospf6_neighbor(tgen, topo)
assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
- step("Change area 1 as non nssa area (on the fly changing area" " type on DUT).")
+ step("Change area 1 as non nssa area (on the fly changing area type on DUT).")
for rtr in ["r1", "r2", "r3"]:
input_dict = {
diff --git a/tests/topotests/ospfv3_basic_functionality/test_ospfv3_routemaps.py b/tests/topotests/ospfv3_basic_functionality/test_ospfv3_routemaps.py
index b2cd0da24e..069806a3ef 100644
--- a/tests/topotests/ospfv3_basic_functionality/test_ospfv3_routemaps.py
+++ b/tests/topotests/ospfv3_basic_functionality/test_ospfv3_routemaps.py
@@ -129,7 +129,7 @@ def setup_module(mod):
pytest.skip(tgen.errors)
ospf_covergence = verify_ospf6_neighbor(tgen, topo)
- assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
+ assert ospf_covergence is True, "setup_module :Failed \n Error: {}".format(
ospf_covergence
)
@@ -212,9 +212,7 @@ def test_ospfv3_routemaps_functionality_tc19_p0(request):
result = create_router_ospf(tgen, topo, ospf_red_r1)
assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
- step(
- "Create prefix-list in R0 to permit 10.0.20.1/32 prefix &" " deny 10.0.20.2/32"
- )
+ step("Create prefix-list in R0 to permit 10.0.20.1/32 prefix & deny 10.0.20.2/32")
# Create ip prefix list
pfx_list = {
@@ -686,7 +684,7 @@ def test_ospfv3_routemaps_functionality_tc25_p0(request):
# Api call verify whether OSPF is converged
ospf_covergence = verify_ospf6_neighbor(tgen, topo)
- assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
+ assert ospf_covergence is True, "Testcase Failed \n Error: {}".format(
ospf_covergence
)
@@ -1078,7 +1076,7 @@ def test_ospfv3_routemaps_functionality_tc24_p0(request):
result = verify_prefix_lists(tgen, pfx_list)
assert (
result is not True
- ), "Testcase {} : Failed \n Prefix list not " "present. Error: {}".format(
+ ), "Testcase {} : Failed \n Prefix list not present. Error: {}".format(
tc_name, result
)
@@ -1147,7 +1145,7 @@ def test_ospfv3_routemaps_functionality_tc24_p0(request):
result = verify_prefix_lists(tgen, pfx_list)
assert (
result is not True
- ), "Testcase {} : Failed \n Prefix list not " "present. Error: {}".format(
+ ), "Testcase {} : Failed \n Prefix list not present. Error: {}".format(
tc_name, result
)
diff --git a/tests/topotests/ospfv3_basic_functionality/test_ospfv3_rte_calc.py b/tests/topotests/ospfv3_basic_functionality/test_ospfv3_rte_calc.py
index 9e7f112efb..645dea8dec 100644
--- a/tests/topotests/ospfv3_basic_functionality/test_ospfv3_rte_calc.py
+++ b/tests/topotests/ospfv3_basic_functionality/test_ospfv3_rte_calc.py
@@ -120,7 +120,7 @@ def setup_module(mod):
pytest.skip(tgen.errors)
ospf_covergence = verify_ospf6_neighbor(tgen, topo)
- assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
+ assert ospf_covergence is True, "setup_module :Failed \n Error: {}".format(
ospf_covergence
)
@@ -256,7 +256,7 @@ def test_ospfv3_redistribution_tc5_p0(request):
step("Verify that OSPF neighbors are FULL.")
ospf_covergence = verify_ospf6_neighbor(tgen, topo)
- assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
+ assert ospf_covergence is True, "Testcase Failed \n Error: {}".format(
ospf_covergence
)
@@ -616,7 +616,7 @@ def test_ospfv3_redistribution_tc8_p1(request):
step("Verify that OSPF neighbours are reset and forms new adjacencies.")
# Api call verify whether OSPF is converged
ospf_covergence = verify_ospf6_neighbor(tgen, topo)
- assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
+ assert ospf_covergence is True, "Testcase Failed \n Error: {}".format(
ospf_covergence
)
diff --git a/tests/topotests/ospfv3_basic_functionality/test_ospfv3_single_area.py b/tests/topotests/ospfv3_basic_functionality/test_ospfv3_single_area.py
index 5d5ba1480f..7199f160fe 100644
--- a/tests/topotests/ospfv3_basic_functionality/test_ospfv3_single_area.py
+++ b/tests/topotests/ospfv3_basic_functionality/test_ospfv3_single_area.py
@@ -114,7 +114,7 @@ def setup_module(mod):
pytest.skip(tgen.errors)
ospf_covergence = verify_ospf6_neighbor(tgen, topo)
- assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
+ assert ospf_covergence is True, "setup_module :Failed \n Error: {}".format(
ospf_covergence
)
@@ -460,7 +460,7 @@ def test_ospfv3_hello_tc10_p0(request):
step("verify that ospf neighbours are full")
ospf_covergence = verify_ospf6_neighbor(tgen, topo, dut=dut)
- assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
+ assert ospf_covergence is True, "Testcase Failed \n Error: {}".format(
ospf_covergence
)
@@ -513,7 +513,7 @@ def test_ospfv3_hello_tc10_p0(request):
step("verify that ospf neighbours are full")
ospf_covergence = verify_ospf6_neighbor(tgen, topo, dut=dut)
- assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
+ assert ospf_covergence is True, "Testcase Failed \n Error: {}".format(
ospf_covergence
)
@@ -566,7 +566,7 @@ def test_ospfv3_hello_tc10_p0(request):
step("verify that ospf neighbours are full")
ospf_covergence = verify_ospf6_neighbor(tgen, topo, dut=dut)
- assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
+ assert ospf_covergence is True, "Testcase Failed \n Error: {}".format(
ospf_covergence
)
@@ -618,7 +618,7 @@ def test_ospfv3_hello_tc10_p0(request):
step("verify that ospf neighbours are full")
ospf_covergence = verify_ospf6_neighbor(tgen, topo, dut=dut)
- assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
+ assert ospf_covergence is True, "Testcase Failed \n Error: {}".format(
ospf_covergence
)
@@ -709,9 +709,7 @@ def test_ospfv3_hello_tc10_p0(request):
result = create_interfaces_cfg(tgen, topo1)
assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
- step(
- "Verify that timer value is deleted from intf & " "set to default value 40 sec."
- )
+ step("Verify that timer value is deleted from intf & set to default value 40 sec.")
input_dict = {"r1": {"links": {"r0": {"ospf6": {"timerIntervalsConfigHello": 10}}}}}
dut = "r1"
result = verify_ospf6_interface(tgen, topo, dut=dut, input_dict=input_dict)
@@ -763,7 +761,7 @@ def test_ospfv3_dead_tc11_p0(request):
result = verify_ospf6_interface(tgen, topo, dut=dut, input_dict=input_dict)
assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
- step("modify dead interval from default value to r1" "dead interval timer on r2")
+ step("modify dead interval from default value to r1 dead interval timer on r2")
topo1 = {
"r0": {
@@ -799,7 +797,7 @@ def test_ospfv3_dead_tc11_p0(request):
# reconfiguring deleted ospf process by resetting the configs.
reset_config_on_routers(tgen)
- step("reconfigure the default dead interval timer value to " "default on r1 and r2")
+ step("reconfigure the default dead interval timer value to default on r1 and r2")
topo1 = {
"r0": {
"links": {
@@ -920,9 +918,7 @@ def test_ospfv3_dead_tc11_p0(request):
result = create_interfaces_cfg(tgen, topo1)
assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
- step(
- "Verify that timer value is deleted from intf & " "set to default value 40 sec."
- )
+ step("Verify that timer value is deleted from intf & set to default value 40 sec.")
input_dict = {"r1": {"links": {"r0": {"ospf6": {"timerIntervalsConfigDead": 40}}}}}
dut = "r1"
result = verify_ospf6_interface(tgen, topo, dut=dut, input_dict=input_dict)
@@ -967,18 +963,14 @@ def test_ospfv3_tc4_mtu_ignore_p0(request):
clear_ospf(tgen, "r0", ospf="ospf6")
clear_ospf(tgen, "r1", ospf="ospf6")
- step(
- "Verify that OSPF neighborship between R0 and R1 is stuck in Exstart" " State."
- )
+ step("Verify that OSPF neighborship between R0 and R1 is stuck in Exstart State.")
result = verify_ospf6_neighbor(tgen, topo, expected=False)
assert result is not True, (
"Testcase {} : Failed \n OSPF nbrs are Full "
"instead of Exstart. Error: {}".format(tc_name, result)
)
- step(
- "Verify that configured MTU value is updated in the show ip " "ospf interface."
- )
+ step("Verify that configured MTU value is updated in the show ip ospf interface.")
dut = "r0"
input_dict = {"r0": {"links": {"r1": {"ospf6": {"interfaceMtu": 1400}}}}}
@@ -1035,9 +1027,7 @@ def test_ospfv3_tc4_mtu_ignore_p0(request):
clear_ospf(tgen, "r0", ospf="ospf6")
- step(
- "Verify that OSPF neighborship between R0 and R1 is stuck in Exstart" " State."
- )
+ step("Verify that OSPF neighborship between R0 and R1 is stuck in Exstart State.")
result = verify_ospf6_neighbor(tgen, topo, expected=False)
assert result is not True, (
"Testcase {} : Failed \n OSPF nbrs are Full "
@@ -1054,9 +1044,7 @@ def test_ospfv3_tc4_mtu_ignore_p0(request):
result = verify_ospf6_neighbor(tgen, topo)
assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
- step(
- "Configure ospf interface with jumbo MTU (9216)." "Reset ospf neighbors on R0."
- )
+ step("Configure ospf interface with jumbo MTU (9216). Reset ospf neighbors on R0.")
rtr0.run("ifconfig {} mtu 9216".format(r0_r1_intf))
rtr1.run("ifconfig {} mtu 9216".format(r1_r0_intf))
@@ -1091,53 +1079,6 @@ def test_ospfv3_show_p1(request):
result = create_debug_log_config(tgen, input_dict)
- # Code coverage steps #Do Not upstream
- input_dict_config = {
- "r1": {
- "raw_config": [
- "end",
- "debug ospf6 event",
- "debug ospf6 gr helper",
- "debug ospf6 ism events",
- "debug ospf6 ism status",
- "debug ospf6 ism timers",
- "debug ospf6 nsm events",
- "debug ospf6 nsm status",
- "debug ospf6 nsm timers ",
- "debug ospf6 nssa",
- "debug ospf6 lsa aggregate",
- "debug ospf6 lsa flooding ",
- "debug ospf6 lsa generate",
- "debug ospf6 lsa install ",
- "debug ospf6 lsa refresh",
- "debug ospf6 packet all detail",
- "debug ospf6 packet all recv",
- "debug ospf6 packet all send",
- "debug ospf6 packet dd detail",
- "debug ospf6 packet dd recv",
- "debug ospf6 packet dd send ",
- "debug ospf6 packet hello detail",
- "debug ospf6 packet hello recv",
- "debug ospf6 packet hello send",
- "debug ospf6 packet ls-ack detail",
- "debug ospf6 packet ls-ack recv",
- "debug ospf6 packet ls-ack send",
- "debug ospf6 packet ls-request detail",
- "debug ospf6 packet ls-request recv",
- "debug ospf6 packet ls-request send",
- "debug ospf6 packet ls-update detail",
- "debug ospf6 packet ls-update recv",
- "debug ospf6 packet ls-update send",
- "debug ospf6 sr",
- "debug ospf6 te ",
- "debug ospf6 zebra interface",
- "debug ospf6 zebra redistribute",
- ]
- }
- }
-
- apply_raw_config(tgen, input_dict_config)
-
for rtr in topo["routers"]:
clear_ospf(tgen, rtr, ospf="ospf6")
@@ -1234,7 +1175,7 @@ def ospfv3_router_id_tc14_p2(request):
clear_ospf(tgen, rtr, ospf="ospf6")
ospf_covergence = verify_ospf6_neighbor(tgen, topo1)
- assert ospf_covergence is True, "OSPF NBRs not up.Failed \n Error:" " {}".format(
+ assert ospf_covergence is True, "OSPF NBRs not up.Failed \n Error: {}".format(
ospf_covergence
)
@@ -1260,9 +1201,9 @@ def ospfv3_router_id_tc14_p2(request):
assert result is True, "Testcase : Failed \n Error: {}".format(result)
ospf_covergence = verify_ospf6_neighbor(tgen, topo, expected=False)
- assert (
- ospf_covergence is not True
- ), "OSPF NBRs are up.Failed \n Error:" " {}".format(ospf_covergence)
+ assert ospf_covergence is not True, "OSPF NBRs are up.Failed \n Error: {}".format(
+ ospf_covergence
+ )
topo1 = {}
topo1 = deepcopy(topo)
@@ -1305,7 +1246,7 @@ def ospfv3_router_id_tc14_p2(request):
topo1["routers"]["r3"]["ospf6"]["router_id"] = "1.1.1.4"
ospf_covergence = verify_ospf6_neighbor(tgen, topo1)
- assert ospf_covergence is True, "OSPF NBRs not up.Failed \n Error:" " {}".format(
+ assert ospf_covergence is True, "OSPF NBRs not up.Failed \n Error: {}".format(
ospf_covergence
)
@@ -1313,7 +1254,7 @@ def ospfv3_router_id_tc14_p2(request):
reset_config_on_routers(tgen)
ospf_covergence = verify_ospf6_neighbor(tgen, topo)
- assert ospf_covergence is True, "OSPF NBRs not up.Failed \n Error:" " {}".format(
+ assert ospf_covergence is True, "OSPF NBRs not up.Failed \n Error: {}".format(
ospf_covergence
)
diff --git a/tests/topotests/rip_allow_ecmp/__init__.py b/tests/topotests/rip_allow_ecmp/__init__.py
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/tests/topotests/rip_allow_ecmp/__init__.py
diff --git a/tests/topotests/rip_allow_ecmp/r1/frr.conf b/tests/topotests/rip_allow_ecmp/r1/frr.conf
new file mode 100644
index 0000000000..d8eb9a31d3
--- /dev/null
+++ b/tests/topotests/rip_allow_ecmp/r1/frr.conf
@@ -0,0 +1,9 @@
+!
+int r1-eth0
+ ip address 192.168.1.1/24
+!
+router rip
+ allow-ecmp
+ network 192.168.1.0/24
+ timers basic 5 15 10
+exit
diff --git a/tests/topotests/rip_allow_ecmp/r2/frr.conf b/tests/topotests/rip_allow_ecmp/r2/frr.conf
new file mode 100644
index 0000000000..d7ea6f3102
--- /dev/null
+++ b/tests/topotests/rip_allow_ecmp/r2/frr.conf
@@ -0,0 +1,13 @@
+!
+int lo
+ ip address 10.10.10.1/32
+!
+int r2-eth0
+ ip address 192.168.1.2/24
+!
+router rip
+ network 192.168.1.0/24
+ network 10.10.10.1/32
+ timers basic 5 15 10
+exit
+
diff --git a/tests/topotests/rip_allow_ecmp/r3/frr.conf b/tests/topotests/rip_allow_ecmp/r3/frr.conf
new file mode 100644
index 0000000000..2362c47b84
--- /dev/null
+++ b/tests/topotests/rip_allow_ecmp/r3/frr.conf
@@ -0,0 +1,13 @@
+!
+int lo
+ ip address 10.10.10.1/32
+!
+int r3-eth0
+ ip address 192.168.1.3/24
+!
+router rip
+ network 192.168.1.0/24
+ network 10.10.10.1/32
+ timers basic 5 15 10
+exit
+
diff --git a/tests/topotests/rip_allow_ecmp/test_rip_allow_ecmp.py b/tests/topotests/rip_allow_ecmp/test_rip_allow_ecmp.py
new file mode 100644
index 0000000000..b0ba146984
--- /dev/null
+++ b/tests/topotests/rip_allow_ecmp/test_rip_allow_ecmp.py
@@ -0,0 +1,124 @@
+#!/usr/bin/env python
+# SPDX-License-Identifier: ISC
+
+# Copyright (c) 2023 by
+# Donatas Abraitis <donatas@opensourcerouting.org>
+#
+
+"""
+Test if RIP `allow-ecmp` command works correctly.
+"""
+
+import os
+import sys
+import json
+import pytest
+import functools
+
+CWD = os.path.dirname(os.path.realpath(__file__))
+sys.path.append(os.path.join(CWD, "../"))
+
+# pylint: disable=C0413
+from lib import topotest
+from lib.topogen import Topogen, TopoRouter, get_topogen
+
+pytestmark = [pytest.mark.ripd]
+
+
+def setup_module(mod):
+ topodef = {"s1": ("r1", "r2", "r3")}
+ tgen = Topogen(topodef, mod.__name__)
+ tgen.start_topology()
+
+ router_list = tgen.routers()
+
+ for _, (rname, router) in enumerate(router_list.items(), 1):
+ router.load_frr_config(os.path.join(CWD, "{}/frr.conf".format(rname)))
+
+ tgen.start_router()
+
+
+def teardown_module(mod):
+ tgen = get_topogen()
+ tgen.stop_topology()
+
+
+def test_rip_allow_ecmp():
+ tgen = get_topogen()
+
+ if tgen.routers_have_failure():
+ pytest.skip(tgen.errors)
+
+ r1 = tgen.gears["r1"]
+
+ def _show_rip_routes():
+ output = json.loads(
+ r1.vtysh_cmd("show yang operational-data /frr-ripd:ripd ripd")
+ )
+ try:
+ output = output["frr-ripd:ripd"]["instance"][0]["state"]["routes"]
+ except KeyError:
+ return False
+
+ expected = {
+ "route": [
+ {
+ "prefix": "10.10.10.1/32",
+ "nexthops": {
+ "nexthop": [
+ {
+ "nh-type": "ip4",
+ "protocol": "rip",
+ "rip-type": "normal",
+ "gateway": "192.168.1.2",
+ "from": "192.168.1.2",
+ "tag": 0,
+ },
+ {
+ "nh-type": "ip4",
+ "protocol": "rip",
+ "rip-type": "normal",
+ "gateway": "192.168.1.3",
+ "from": "192.168.1.3",
+ "tag": 0,
+ },
+ ]
+ },
+ "metric": 2,
+ },
+ ]
+ }
+ return topotest.json_cmp(output, expected)
+
+ test_func = functools.partial(_show_rip_routes)
+ _, result = topotest.run_and_expect(test_func, None, count=60, wait=1)
+ assert result is None, "Can't see 10.10.10.1/32 as multipath in `show ip rip`"
+
+ def _show_routes():
+ output = json.loads(r1.vtysh_cmd("show ip route json"))
+ expected = {
+ "10.10.10.1/32": [
+ {
+ "nexthops": [
+ {
+ "ip": "192.168.1.2",
+ "active": True,
+ },
+ {
+ "ip": "192.168.1.3",
+ "active": True,
+ },
+ ]
+ }
+ ]
+ }
+ return topotest.json_cmp(output, expected)
+
+ test_func = functools.partial(_show_routes)
+ _, result = topotest.run_and_expect(test_func, None, count=60, wait=1)
+ assert result is None, "Can't see 10.10.10.1/32 as multipath in `show ip route`"
+
+
+if __name__ == "__main__":
+ args = ["-s"] + sys.argv[1:]
+ sys.exit(pytest.main(args))
diff --git a/tests/topotests/static_routing_with_ebgp/test_static_routes_topo1_ebgp.py b/tests/topotests/static_routing_with_ebgp/test_static_routes_topo1_ebgp.py
index 63c0a86897..46777d7b4b 100644
--- a/tests/topotests/static_routing_with_ebgp/test_static_routes_topo1_ebgp.py
+++ b/tests/topotests/static_routing_with_ebgp/test_static_routes_topo1_ebgp.py
@@ -207,7 +207,7 @@ def test_static_route_2nh_p0_tc_1_ebgp(request):
)
assert (
result is True
- ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed Error: Routes are missing in RIB".format(tc_name)
step("Configure IBGP IPv4 peering between R2 and R3 router.")
step("Configure redistribute static in BGP on R2 router")
@@ -262,7 +262,7 @@ def test_static_route_2nh_p0_tc_1_ebgp(request):
)
assert (
result is not True
- ), "Testcase {} : Failed" "Error: Routes is still present in RIB".format(
+ ), "Testcase {} : Failed Expected: Routes should not present in RIB \nError: Routes are still present in RIB".format(
tc_name
)
@@ -272,7 +272,7 @@ def test_static_route_2nh_p0_tc_1_ebgp(request):
)
assert (
result is True
- ), "Testcase {} : Failed \nError: Routes is" " missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed \nError: Routes are missing in RIB".format(tc_name)
step("Configure the static route with nexthop N1")
@@ -293,7 +293,7 @@ def test_static_route_2nh_p0_tc_1_ebgp(request):
tc_name, result
)
- step("Remove the static route configured with nexthop N2 from" "running config")
+ step("Remove the static route configured with nexthop N2 from running config")
input_dict_4 = {
"r2": {
@@ -329,7 +329,7 @@ def test_static_route_2nh_p0_tc_1_ebgp(request):
)
assert (
result is not True
- ), "Testcase {} : Failed \nError: Routes is" " still present in RIB".format(
+ ), "Testcase {} : Failed \nExpected: Routes should not present in RIB \nError: Routes are still present in RIB".format(
tc_name
)
@@ -339,7 +339,7 @@ def test_static_route_2nh_p0_tc_1_ebgp(request):
)
assert (
result is True
- ), "Testcase {} : Failed \nError: Routes is" " missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed \nError: Routes are missing in RIB".format(tc_name)
step("Configure the static route with nexthop N2")
input_dict_4 = {
@@ -372,7 +372,7 @@ def test_static_route_2nh_p0_tc_1_ebgp(request):
)
assert (
result is True
- ), "Testcase {} : Failed \nError: Routes is" " missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed \nError: Routes are missing in RIB".format(tc_name)
nh = next_hop_ip["nh1"][addr_type]
result = verify_rib(
@@ -386,7 +386,7 @@ def test_static_route_2nh_p0_tc_1_ebgp(request):
)
assert (
result is not True
- ), "Testcase {} : Failed \nError: Routes is" " still present in RIB".format(
+ ), "Testcase {} : Failed \nExpected: Routes should not present in RIB \nError: Routes are still present in RIB".format(
tc_name
)
@@ -396,7 +396,7 @@ def test_static_route_2nh_p0_tc_1_ebgp(request):
)
assert (
result is not True
- ), "Testcase {} : Failed \nError: Route is" " still present in RIB".format(
+ ), "Testcase {} : Failed \nExpected: Routes should not present in RIB \nError: Route is still present in RIB".format(
tc_name
)
@@ -411,7 +411,7 @@ def test_static_route_2nh_p0_tc_1_ebgp(request):
)
assert (
result is not True
- ), "Testcase {} : Failed \nError: Route is" " still present in RIB".format(
+ ), "Testcase {} : Failed \n Expected: Routes should not present in RIB \nError: Route is still present in RIB".format(
tc_name
)
@@ -422,20 +422,20 @@ def test_static_route_2nh_p0_tc_1_ebgp(request):
)
assert (
result is True
- ), "Testcase {} : Failed \nError: Routes is" " missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed \nError: Routes are missing in RIB".format(tc_name)
dut = "r3"
result = verify_bgp_rib(tgen, addr_type, dut, input_dict_4)
assert (
result is True
- ), "Testcase {} : Failed \nError: Route is" " missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed \nError: Route is missing in RIB".format(tc_name)
result = verify_rib(
tgen, addr_type, dut, input_dict_4, protocol=protocol, expected=False
)
assert (
result is not True
- ), "Testcase {} : Failed \nError: Route is" " still present in RIB".format(
+ ), "Testcase {} : Failed \nExpected: Routes should not present in RIB \nError: Route is still present in RIB".format(
tc_name
)
@@ -454,7 +454,7 @@ def test_static_route_2nh_p0_tc_1_ebgp(request):
)
assert (
result is True
- ), "Testcase {} : Failed \nError: Routes is" " missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed \nError: Routes are missing in RIB".format(tc_name)
step("Shut nexthop interface N2")
intf = topo["routers"]["r2"]["links"]["r1-link1"]["interface"]
@@ -478,7 +478,7 @@ def test_static_route_2nh_p0_tc_1_ebgp(request):
)
assert (
result is not True
- ), "Testcase {} : Failed \nError: Routes is" " still present in RIB".format(
+ ), "Testcase {} : Failed \nExpected: Routes should not present in RIB \nError: Routes are still present in RIB".format(
tc_name
)
@@ -490,20 +490,20 @@ def test_static_route_2nh_p0_tc_1_ebgp(request):
)
assert (
result is True
- ), "Testcase {} : Failed \nError: Routes is" " missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed \nError: Routes are missing in RIB".format(tc_name)
dut = "r3"
result = verify_bgp_rib(tgen, addr_type, dut, input_dict_4)
assert (
result is True
- ), "Testcase {} : Failed \nError: Route is" " missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed \nError: Route is missing in RIB".format(tc_name)
result = verify_rib(
tgen, addr_type, dut, input_dict_4, protocol=protocol, expected=False
)
assert (
result is not True
- ), "Testcase {} : Failed \nError: Route is" " still present in RIB".format(
+ ), "Testcase {} : Failed \nExpected: Routes should not present in RIB \nError: Route is still present in RIB".format(
tc_name
)
@@ -522,20 +522,20 @@ def test_static_route_2nh_p0_tc_1_ebgp(request):
)
assert (
result is True
- ), "Testcase {} : Failed \nError: Routes is" " missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed \nError: Routes are missing in RIB".format(tc_name)
dut = "r3"
result = verify_bgp_rib(tgen, addr_type, dut, input_dict_4)
assert (
result is True
- ), "Testcase {} : Failed \nError: Route is" " missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed \nError: Route is missing in RIB".format(tc_name)
result = verify_rib(
tgen, addr_type, dut, input_dict_4, protocol=protocol, expected=False
)
assert (
result is not True
- ), "Testcase {} : Failed \nError: Route is" " still present in RIB".format(
+ ), "Testcase {} : Failed \nExpected: Routes should not present in RIB \nError: Route is still present in RIB".format(
tc_name
)
@@ -555,13 +555,13 @@ def test_static_route_2nh_p0_tc_1_ebgp(request):
)
assert (
result is True
- ), "Testcase {} : Failed \nError: Routes is" " missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed \nError: Routes are missing in RIB".format(tc_name)
dut = "r3"
result = verify_bgp_rib(tgen, addr_type, dut, input_dict_4)
assert (
result is True
- ), "Testcase {} : Failed \nError: Route is" " still present in RIB".format(
+ ), "Testcase {} : Failed \nError: Route is still present in RIB".format(
tc_name
)
@@ -570,7 +570,7 @@ def test_static_route_2nh_p0_tc_1_ebgp(request):
)
assert (
result is not True
- ), "Testcase {} : Failed \nError: Route is" " still present in RIB".format(
+ ), "Testcase {} : Failed \nExpected: Routes should not present in RIB \nError: Route is still present in RIB".format(
tc_name
)
@@ -646,7 +646,7 @@ def test_static_route_2nh_admin_dist_p0_tc_2_ebgp(request):
)
assert (
result is True
- ), "Testcase {} : Failed \nError: Routes is" "missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed \nError: Routes are missing in RIB".format(tc_name)
rte2_nh2 = {
"r2": {
@@ -674,7 +674,9 @@ def test_static_route_2nh_admin_dist_p0_tc_2_ebgp(request):
)
assert (
result is not True
- ), "Testcase {} : Failed \nError: Routes is" "not active in RIB".format(tc_name)
+ ), "Testcase {} : Failed \nExpected: Routes should not present in RIB \nError: Routes are not active in RIB".format(
+ tc_name
+ )
step("Configure IBGP IPv4 peering between R2 and R3 router.")
step("Explicit route is added in R3 for R2 nexthop rechability")
@@ -715,7 +717,7 @@ def test_static_route_2nh_admin_dist_p0_tc_2_ebgp(request):
tc_name, result
)
- step("Remove the static route configured with nexthop N1 from" "running config")
+ step("Remove the static route configured with nexthop N1 from running config")
rt1_nh1 = {
"r2": {
"static_routes": [
@@ -765,7 +767,9 @@ def test_static_route_2nh_admin_dist_p0_tc_2_ebgp(request):
)
assert (
result is not True
- ), "Testcase {} : Failed \nError: Routes is" "missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed \nExpected: Routes should not present in RIB \nError: Routes are missing in RIB".format(
+ tc_name
+ )
rte2_nh2 = {
"r2": {
@@ -784,7 +788,7 @@ def test_static_route_2nh_admin_dist_p0_tc_2_ebgp(request):
)
assert (
result is True
- ), "Testcase {} : Failed \nError: Routes is" "not active in RIB".format(tc_name)
+ ), "Testcase {} : Failed \nError: Routes are not active in RIB".format(tc_name)
step("Configure the static route with nexthop N1")
rte1_nh1 = {
@@ -804,7 +808,7 @@ def test_static_route_2nh_admin_dist_p0_tc_2_ebgp(request):
tc_name, result
)
- step("Remove the static route configured with nexthop N2 from" "running config")
+ step("Remove the static route configured with nexthop N2 from running config")
rte2_nh2 = {
"r2": {
"static_routes": [
@@ -839,7 +843,7 @@ def test_static_route_2nh_admin_dist_p0_tc_2_ebgp(request):
)
assert (
result is not True
- ), "Testcase {} : Failed \nError: Routes is" " still present in RIB".format(
+ ), "Testcase {} : Failed \nExpected: Routes should not present in RIB \nError: Routes are still present in RIB".format(
tc_name
)
@@ -849,7 +853,7 @@ def test_static_route_2nh_admin_dist_p0_tc_2_ebgp(request):
)
assert (
result is True
- ), "Testcase {} : Failed \nError: Routes is" " missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed \nError: Routes are missing in RIB".format(tc_name)
step("Configure the static route with nexthop N2")
rte2_nh2 = {
@@ -889,7 +893,7 @@ def test_static_route_2nh_admin_dist_p0_tc_2_ebgp(request):
)
assert (
result is not True
- ), "Testcase {} : Failed \nError: Routes is" " still present in RIB".format(
+ ), "Testcase {} : Failed \nExpected: Routes should not present in RIB \nError: Routes are still present in RIB".format(
tc_name
)
@@ -899,7 +903,7 @@ def test_static_route_2nh_admin_dist_p0_tc_2_ebgp(request):
)
assert (
result is True
- ), "Testcase {} : Failed \nError: Routes is" " missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed \nError: Routes are missing in RIB".format(tc_name)
step("No shut the nexthop interface N1")
shutdown_bringup_interface(tgen, dut, intf, True)
@@ -915,7 +919,7 @@ def test_static_route_2nh_admin_dist_p0_tc_2_ebgp(request):
)
assert (
result is True
- ), "Testcase {} : Failed \nError: Routes is" " missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed \nError: Routes are missing in RIB".format(tc_name)
step("Shut nexthop interface N2")
intf = topo["routers"]["r2"]["links"]["r1-link1"]["interface"]
@@ -939,7 +943,7 @@ def test_static_route_2nh_admin_dist_p0_tc_2_ebgp(request):
)
assert (
result is not True
- ), "Testcase {} : Failed \nError: Routes is" " still present in RIB".format(
+ ), "Testcase {} : Failed \nExpected: Routes should not present in RIB \nError: Routes are still present in RIB".format(
tc_name
)
@@ -949,7 +953,7 @@ def test_static_route_2nh_admin_dist_p0_tc_2_ebgp(request):
)
assert (
result is True
- ), "Testcase {} : Failed \nError: Routes is" " missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed \nError: Routes are missing in RIB".format(tc_name)
step("No shut nexthop interface N2")
shutdown_bringup_interface(tgen, dut, intf, True)
@@ -977,7 +981,7 @@ def test_static_route_2nh_admin_dist_p0_tc_2_ebgp(request):
)
assert (
result is True
- ), "Testcase {} : Failed \nError: Routes is" "missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed \nError: Routes are missing in RIB".format(tc_name)
rte2_nh2 = {
"r2": {
@@ -1005,7 +1009,9 @@ def test_static_route_2nh_admin_dist_p0_tc_2_ebgp(request):
)
assert (
result is not True
- ), "Testcase {} : Failed \nError: Routes is" "not active in RIB".format(tc_name)
+ ), "Testcase {} : Failed \nExpected: Routes should not active in RIB \nError: Routes are not active in RIB".format(
+ tc_name
+ )
dut = "r3"
protocol = "bgp"
@@ -1022,7 +1028,9 @@ def test_static_route_2nh_admin_dist_p0_tc_2_ebgp(request):
)
assert (
result is not True
- ), "Testcase {} : Failed \nError: Routes is" "not active in RIB".format(tc_name)
+ ), "Testcase {} : Failed \nExpected: Routes should not be active in RIB \nError: Routes are not active in RIB".format(
+ tc_name
+ )
dut = "r2"
step("Reload the FRR router")
@@ -1054,14 +1062,14 @@ def test_static_route_2nh_admin_dist_p0_tc_2_ebgp(request):
)
assert (
result is True
- ), "Testcase {} : Failed \nError: Routes is" "missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed \nError: Routes are missing in RIB".format(tc_name)
dut = "r3"
protocol = "bgp"
result = verify_bgp_rib(tgen, addr_type, dut, rte1_nh1, next_hop=nh)
assert (
result is True
- ), "Testcase {} : Failed \nError: Routes is" "missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed \nError: Routes are missing in RIB".format(tc_name)
rte2_nh2 = {
"r2": {
@@ -1089,14 +1097,16 @@ def test_static_route_2nh_admin_dist_p0_tc_2_ebgp(request):
)
assert (
result is not True
- ), "Testcase {} : Failed \nError: Routes is" "not active in RIB".format(tc_name)
+ ), "Testcase {} : Failed \nExpected: Routes should not be active in RIB \nError: Routes are not active in RIB".format(
+ tc_name
+ )
dut = "r3"
protocol = "bgp"
result = verify_bgp_rib(tgen, addr_type, dut, rte2_nh2, next_hop=nh)
assert (
result is True
- ), "Testcase {} : Failed \nError: Routes is" "not active in RIB".format(tc_name)
+ ), "Testcase {} : Failed \nError: Routes are not active in RIB".format(tc_name)
result = verify_rib(
tgen,
@@ -1110,7 +1120,9 @@ def test_static_route_2nh_admin_dist_p0_tc_2_ebgp(request):
)
assert (
result is not True
- ), "Testcase {} : Failed \nError: Routes is" "not active in RIB".format(tc_name)
+ ), "Testcase {} : Failed \nExpected: Routes should not be active in RIB \nError: Routes are not active in RIB".format(
+ tc_name
+ )
write_test_footer(tc_name)
@@ -1182,7 +1194,7 @@ def test_same_rte_from_bgp_static_p0_tc5_ebgp(request):
result = verify_bgp_rib(tgen, addr_type, dut, input_dict_4)
assert (
result is True
- ), "Testcase {} : Failed \nError: Route is" " still present in RIB".format(
+ ), "Testcase {} : Failed \nError: Route is still present in RIB".format(
tc_name
)
@@ -1191,7 +1203,7 @@ def test_same_rte_from_bgp_static_p0_tc5_ebgp(request):
result = verify_rib(tgen, addr_type, dut, input_dict_4, protocol=protocol)
assert (
result is True
- ), "Testcase {} : Failed \nError: Route is" " still present in RIB".format(
+ ), "Testcase {} : Failed \nError: Route is still present in RIB".format(
tc_name
)
@@ -1246,9 +1258,7 @@ def test_same_rte_from_bgp_static_p0_tc5_ebgp(request):
result = verify_bgp_rib(tgen, addr_type, dut, input_dict_4)
assert (
result is True
- ), "Testcase {} : Failed \nError: Route is" " missing in BGP RIB".format(
- tc_name
- )
+ ), "Testcase {} : Failed \nError: Route is missing in BGP RIB".format(tc_name)
protocol = "bgp"
result = verify_rib(
@@ -1256,9 +1266,9 @@ def test_same_rte_from_bgp_static_p0_tc5_ebgp(request):
)
assert (
result is True
- ), "Testcase {} : Failed \nError: Route is" " missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed \nError: Route is missing in RIB".format(tc_name)
- step("Remove the static route on R3 configured with active" "interface")
+ step("Remove the static route on R3 configured with active interface")
for addr_type in ADDR_TYPES:
input_dict_4 = {
"r3": {
@@ -1293,9 +1303,7 @@ def test_same_rte_from_bgp_static_p0_tc5_ebgp(request):
result = verify_bgp_rib(tgen, addr_type, dut, input_dict_4)
assert (
result is True
- ), "Testcase {} : Failed \nError: Route is" " missing in BGP RIB".format(
- tc_name
- )
+ ), "Testcase {} : Failed \nError: Route is missing in BGP RIB".format(tc_name)
protocol = "bgp"
result = verify_rib(
@@ -1303,7 +1311,7 @@ def test_same_rte_from_bgp_static_p0_tc5_ebgp(request):
)
assert (
result is True
- ), "Testcase {} : Failed \nError: Route is" " missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed \nError: Route is missing in RIB".format(tc_name)
write_test_footer(tc_name)
diff --git a/tests/topotests/static_routing_with_ebgp/test_static_routes_topo2_ebgp.py b/tests/topotests/static_routing_with_ebgp/test_static_routes_topo2_ebgp.py
index 530c49f6bf..e01351506d 100644
--- a/tests/topotests/static_routing_with_ebgp/test_static_routes_topo2_ebgp.py
+++ b/tests/topotests/static_routing_with_ebgp/test_static_routes_topo2_ebgp.py
@@ -281,7 +281,7 @@ def test_static_rte_with_8ecmp_nh_p1_tc9_ebgp(request):
)
assert (
result is True
- ), "Testcase {} : Failed \nError: Routes are" " missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed \nError: Routes are missing in RIB".format(tc_name)
step("Configure redistribute static in BGP on R2 router")
for addr_type in ADDR_TYPES:
@@ -306,7 +306,7 @@ def test_static_rte_with_8ecmp_nh_p1_tc9_ebgp(request):
result = verify_bgp_rib(tgen, addr_type, dut, input_dict_4)
assert (
result is True
- ), "Testcase {} : Failed \nError: Routes are" " missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed \nError: Routes are missing in RIB".format(tc_name)
step(
"Remove the static route configured with nexthop N1 to N8, one"
@@ -353,7 +353,7 @@ def test_static_rte_with_8ecmp_nh_p1_tc9_ebgp(request):
)
assert (
result is not True
- ), "Testcase {} : Failed\nError: Routes is" " still present in RIB".format(
+ ), "Testcase {} : Failed\nError: routes are still present in RIB".format(
tc_name
)
@@ -382,9 +382,7 @@ def test_static_rte_with_8ecmp_nh_p1_tc9_ebgp(request):
)
assert (
result is True
- ), "Testcase {} : Failed\nError: Routes are" " missing in RIB".format(
- tc_name
- )
+ ), "Testcase {} : Failed\nError: Routes are missing in RIB".format(tc_name)
protocol = "static"
step("Random shut of the nexthop interfaces")
@@ -392,7 +390,7 @@ def test_static_rte_with_8ecmp_nh_p1_tc9_ebgp(request):
# Shutdown interface
dut = "r2"
step(
- " interface which is about to be shut no shut between r1 and r2 is " "%s",
+ " interface which is about to be shut no shut between r1 and r2 is %s",
topo["routers"]["r2"]["links"]["r1-link{}".format(randnum)]["interface"],
)
intf = topo["routers"]["r2"]["links"]["r1-link{}".format(randnum)]["interface"]
@@ -430,7 +428,7 @@ def test_static_rte_with_8ecmp_nh_p1_tc9_ebgp(request):
)
assert (
result is True
- ), "Testcase {} : Failed \nError: Routes are" " missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed \nError: Routes are missing in RIB".format(tc_name)
step("Remove random static route with all the nexthop")
dut = "r2"
@@ -469,7 +467,7 @@ def test_static_rte_with_8ecmp_nh_p1_tc9_ebgp(request):
)
assert (
result is not True
- ), "Testcase {} : Failed \nError: Routes are" " missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed \nError: Routes are missing in RIB".format(tc_name)
for addr_type in ADDR_TYPES:
input_dict_4 = {
@@ -523,7 +521,7 @@ def test_static_rte_with_8ecmp_nh_p1_tc9_ebgp(request):
)
assert (
result is True
- ), "Testcase {} : Failed \nError: Routes are" " missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed \nError: Routes are missing in RIB".format(tc_name)
step("Remove the redistribute static knob")
for addr_type in ADDR_TYPES:
@@ -558,7 +556,7 @@ def test_static_rte_with_8ecmp_nh_p1_tc9_ebgp(request):
)
assert (
result is not True
- ), "Testcase {} : Failed \nError: Routes are" " still present in RIB".format(
+ ), "Testcase {} : Failed \nError: Routes are still present in RIB".format(
tc_name
)
@@ -642,7 +640,7 @@ def test_static_route_8nh_diff_AD_bgp_ecmp_p1_tc6_ebgp(request):
)
assert (
result is True
- ), "Testcase {} : Failed \nError: Routes are" " missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed \nError: Routes are missing in RIB".format(tc_name)
nh = []
for nhp in range(2, 9):
@@ -660,7 +658,7 @@ def test_static_route_8nh_diff_AD_bgp_ecmp_p1_tc6_ebgp(request):
)
assert (
result is not True
- ), "Testcase {} : Failed \nError: Routes " " are missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed \nError: Routes are missing in RIB".format(tc_name)
step(
"Remove the static route configured with nexthop N1 to N8, one"
@@ -705,9 +703,7 @@ def test_static_route_8nh_diff_AD_bgp_ecmp_p1_tc6_ebgp(request):
)
assert (
result is not True
- ), "Testcase {} : Failed \nError: Routes are" " still present in RIB".format(
- tc_name
- )
+ ), "Testcase {} : Failed \nError: Routes are still present in RIB".format(tc_name)
step("Configure the static route with nexthop N1 to N8, one by one")
@@ -755,7 +751,7 @@ def test_static_route_8nh_diff_AD_bgp_ecmp_p1_tc6_ebgp(request):
)
assert (
result is True
- ), "Testcase {} : Failed \nError: Routes are" " missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed \nError: Routes are missing in RIB".format(tc_name)
nh = []
for nhp in range(2, 9):
nh.append(NEXT_HOP_IP["nh" + str(nhp)][addr_type])
@@ -772,7 +768,7 @@ def test_static_route_8nh_diff_AD_bgp_ecmp_p1_tc6_ebgp(request):
)
assert (
result is not True
- ), "Testcase {} : Failed \nError: Routes " " are missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed \nError: Routes are missing in RIB".format(tc_name)
step("Random shut of the nexthop interfaces")
randnum = random.randint(0, 7)
@@ -801,7 +797,7 @@ def test_static_route_8nh_diff_AD_bgp_ecmp_p1_tc6_ebgp(request):
)
assert (
result is not True
- ), "Testcase {} : Failed \n" "Error: Routes are still present in RIB".format(
+ ), "Testcase {} : Failed \n Error: Routes are still present in RIB".format(
tc_name
)
@@ -815,7 +811,7 @@ def test_static_route_8nh_diff_AD_bgp_ecmp_p1_tc6_ebgp(request):
)
assert (
result is True
- ), "Testcase {} : Failed \n" "Error: Routes are missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed \n Error: Routes are missing in RIB".format(tc_name)
dut = "r2"
protocol = "static"
@@ -824,7 +820,7 @@ def test_static_route_8nh_diff_AD_bgp_ecmp_p1_tc6_ebgp(request):
result = verify_rib(tgen, addr_type, dut, input_dict_4, protocol=protocol)
assert (
result is True
- ), "Testcase {}: Failed \n " "Error: Routes are missing in RIB".format(tc_name)
+ ), "Testcase {}: Failed \n Error: Routes are missing in RIB".format(tc_name)
protocol = "bgp"
dut = "r3"
@@ -833,7 +829,7 @@ def test_static_route_8nh_diff_AD_bgp_ecmp_p1_tc6_ebgp(request):
result = verify_rib(tgen, addr_type, dut, input_dict_4, protocol=protocol)
assert (
result is True
- ), "Testcase {}: Failed \n " "Error: Routes are missing in RIB".format(tc_name)
+ ), "Testcase {}: Failed \n Error: Routes are missing in RIB".format(tc_name)
step("Reload the FRR router")
# stop/start -> restart FRR router and verify
@@ -846,7 +842,7 @@ def test_static_route_8nh_diff_AD_bgp_ecmp_p1_tc6_ebgp(request):
result = verify_rib(tgen, addr_type, dut, input_dict_4, protocol=protocol)
assert (
result is True
- ), "Testcase {} : Failed \n" "Error: Routes are still present in RIB".format(
+ ), "Testcase {} : Failed \n Error: Routes are still present in RIB".format(
tc_name
)
@@ -945,7 +941,7 @@ def test_static_route_8nh_diff_AD_ebgp_ecmp_p1_tc8_ebgp(request):
)
assert (
result is True
- ), "Testcase {} : Failed \nError: Routes are" " missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed \nError: Routes are missing in RIB".format(tc_name)
nh = []
for nhp in range(2, 9):
@@ -962,7 +958,7 @@ def test_static_route_8nh_diff_AD_ebgp_ecmp_p1_tc8_ebgp(request):
)
assert (
result is not True
- ), "Testcase {} : Failed \nError: Routes " " are missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed \nError: Routes are missing in RIB".format(tc_name)
step(
"Remove the static route configured with nexthop N1 to N8, one"
@@ -1007,9 +1003,7 @@ def test_static_route_8nh_diff_AD_ebgp_ecmp_p1_tc8_ebgp(request):
)
assert (
result is not True
- ), "Testcase {} : Failed \nError: Routes are" " still present in RIB".format(
- tc_name
- )
+ ), "Testcase {} : Failed \nError: Routes are still present in RIB".format(tc_name)
step("Configure the static route with nexthop N1 to N8, one by one")
@@ -1057,7 +1051,7 @@ def test_static_route_8nh_diff_AD_ebgp_ecmp_p1_tc8_ebgp(request):
)
assert (
result is True
- ), "Testcase {} : Failed \nError: Routes are" " missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed \nError: Routes are missing in RIB".format(tc_name)
nh = []
for nhp in range(2, 9):
nh.append(NEXT_HOP_IP["nh" + str(nhp)][addr_type])
@@ -1073,7 +1067,7 @@ def test_static_route_8nh_diff_AD_ebgp_ecmp_p1_tc8_ebgp(request):
)
assert (
result is not True
- ), "Testcase {} : Failed \nError: Routes " " are missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed \nError: Routes are missing in RIB".format(tc_name)
step("Random shut of the nexthop interfaces")
randnum = random.randint(0, 7)
@@ -1102,7 +1096,7 @@ def test_static_route_8nh_diff_AD_ebgp_ecmp_p1_tc8_ebgp(request):
)
assert (
result is not True
- ), "Testcase {} : Failed \n" "Error: Routes are still present in RIB".format(
+ ), "Testcase {} : Failed \n Error: Routes are still present in RIB".format(
tc_name
)
@@ -1116,7 +1110,7 @@ def test_static_route_8nh_diff_AD_ebgp_ecmp_p1_tc8_ebgp(request):
)
assert (
result is True
- ), "Testcase {} : Failed \n" "Error: Routes are missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed \n Error: Routes are missing in RIB".format(tc_name)
dut = "r2"
protocol = "static"
@@ -1132,7 +1126,7 @@ def test_static_route_8nh_diff_AD_ebgp_ecmp_p1_tc8_ebgp(request):
result = verify_rib(tgen, addr_type, dut, input_dict_4, protocol=protocol)
assert (
result is True
- ), "Testcase {} : Failed \n" "Error: Routes are still present in RIB".format(
+ ), "Testcase {} : Failed \n Error: Routes are still present in RIB".format(
tc_name
)
@@ -1231,7 +1225,7 @@ def test_static_route_8nh_diff_AD_bgp_ecmp_p1_tc10_ebgp(request):
)
assert (
result is True
- ), "Testcase {} : Failed \nError: Routes are" " missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed \nError: Routes are missing in RIB".format(tc_name)
step("Verify that highest AD nexthop are inactive")
nh = []
@@ -1250,7 +1244,7 @@ def test_static_route_8nh_diff_AD_bgp_ecmp_p1_tc10_ebgp(request):
)
assert (
result is not True
- ), "Testcase {} : Failed \nError: Routes " " are missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed \nError: Routes are missing in RIB".format(tc_name)
step("Configure redistribute static in BGP on R2 router")
for addr_type in ADDR_TYPES:
@@ -1314,7 +1308,7 @@ def test_static_route_8nh_diff_AD_bgp_ecmp_p1_tc10_ebgp(request):
)
assert (
result is not True
- ), "Testcase {} : Failed \nError: Routes are" " still present in RIB".format(
+ ), "Testcase {} : Failed \nError: Routes are still present in RIB".format(
tc_name
)
@@ -1345,15 +1339,7 @@ def test_static_route_8nh_diff_AD_bgp_ecmp_p1_tc10_ebgp(request):
" value and all the nexthop populated in RIB and FIB again"
)
for addr_type in ADDR_TYPES:
- input_dict_4 = {
- "r2": {
- "static_routes": [
- {
- "network": PREFIX1[addr_type],
- }
- ]
- }
- }
+ input_dict_4 = {"r2": {"static_routes": [{"network": PREFIX1[addr_type]}]}}
nh = NEXT_HOP_IP["nh1"][addr_type]
result = verify_rib(
tgen, addr_type, dut, input_dict_4, next_hop=nh, protocol=protocol, fib=True
@@ -1390,7 +1376,7 @@ def test_static_route_8nh_diff_AD_bgp_ecmp_p1_tc10_ebgp(request):
)
assert (
result is not True
- ), "Testcase {} : Failed \n" "Error: Routes are still present in RIB".format(
+ ), "Testcase {} : Failed \n Error: Routes are still present in RIB".format(
tc_name
)
@@ -1404,7 +1390,7 @@ def test_static_route_8nh_diff_AD_bgp_ecmp_p1_tc10_ebgp(request):
)
assert (
result is True
- ), "Testcase {} : Failed \n" "Error: Routes are missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed \n Error: Routes are missing in RIB".format(tc_name)
step("Remove random static route with all the nexthop")
for addr_type in ADDR_TYPES:
@@ -1494,9 +1480,7 @@ def test_static_route_8nh_diff_AD_bgp_ecmp_p1_tc10_ebgp(request):
)
assert (
result is True
- ), "Testcase {} : Failed \nError: Route " " is missing in RIB".format(
- tc_name
- )
+ ), "Testcase {} : Failed \nError: Route is missing in RIB".format(tc_name)
write_test_footer(tc_name)
@@ -1592,7 +1576,7 @@ def test_static_route_delete_p0_tc11_ebgp(request):
)
assert (
result is True
- ), "Testcase {} : Failed \nError: Routes are" " missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed \nError: Routes are missing in RIB".format(tc_name)
step("Verify that highest AD nexthop are inactive")
nh = []
@@ -1610,7 +1594,7 @@ def test_static_route_delete_p0_tc11_ebgp(request):
)
assert (
result is not True
- ), "Testcase {} : Failed \nError: Routes " " are missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed \nError: Routes are missing in RIB".format(tc_name)
step("Configure redistribute static in BGP on R2 router")
for addr_type in ADDR_TYPES:
@@ -1664,7 +1648,7 @@ def test_static_route_delete_p0_tc11_ebgp(request):
)
assert (
result is not True
- ), "Testcase {} : Failed \nError: Routes are" " still present in RIB".format(
+ ), "Testcase {} : Failed \nError: Routes are still present in RIB".format(
tc_name
)
@@ -1735,7 +1719,7 @@ def test_static_route_delete_p0_tc11_ebgp(request):
)
assert (
result is not True
- ), "Testcase {} : Failed \nError: Routes are" " still active in RIB".format(
+ ), "Testcase {} : Failed \nError: Routes are still active in RIB".format(
tc_name
)
diff --git a/tests/topotests/static_routing_with_ebgp/test_static_routes_topo3_ebgp.py b/tests/topotests/static_routing_with_ebgp/test_static_routes_topo3_ebgp.py
index 358047607a..9d35b7dcd3 100644
--- a/tests/topotests/static_routing_with_ebgp/test_static_routes_topo3_ebgp.py
+++ b/tests/topotests/static_routing_with_ebgp/test_static_routes_topo3_ebgp.py
@@ -262,7 +262,7 @@ def test_staticroute_with_ecmp_p0_tc3_ebgp(request):
)
assert (
result is True
- ), "Testcase {} : Failed \nError: Routes are" " missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed \nError: Routes are missing in RIB".format(tc_name)
step("Configure redistribute static in BGP on R2 router")
for addr_type in ADDR_TYPES:
input_dict_2 = {
@@ -317,11 +317,11 @@ def test_staticroute_with_ecmp_p0_tc3_ebgp(request):
)
assert (
result is not True
- ), "Testcase {} : Failed \nError: Routes are" " still present in RIB".format(
+ ), "Testcase {} : Failed \nError: Routes are still present in RIB".format(
tc_name
)
- step("Configure the static route with nexthop N1 to N8, one by" "one")
+ step("Configure the static route with nexthop N1 to N8, one by one")
for addr_type in ADDR_TYPES:
# add static routes
@@ -348,7 +348,7 @@ def test_staticroute_with_ecmp_p0_tc3_ebgp(request):
)
assert (
result is True
- ), "Testcase {} : Failed \nError: Routes are" " missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed \nError: Routes are missing in RIB".format(tc_name)
step("Random shut of the nexthop interfaces")
randnum = random.randint(0, 7)
@@ -377,7 +377,7 @@ def test_staticroute_with_ecmp_p0_tc3_ebgp(request):
)
assert (
result is not True
- ), "Testcase {} : Failed \n" "Error: Routes are still present in RIB".format(
+ ), "Testcase {} : Failed \n Error: Routes are still present in RIB".format(
tc_name
)
@@ -391,7 +391,7 @@ def test_staticroute_with_ecmp_p0_tc3_ebgp(request):
)
assert (
result is True
- ), "Testcase {} : Failed \n" "Error: Routes are missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed \n Error: Routes are missing in RIB".format(tc_name)
step("Reload the FRR router")
# stop/start -> restart FRR router and verify
@@ -403,7 +403,7 @@ def test_staticroute_with_ecmp_p0_tc3_ebgp(request):
)
assert (
result is True
- ), "Testcase {} : Failed \nError: Routes are" " missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed \nError: Routes are missing in RIB".format(tc_name)
write_test_footer(tc_name)
@@ -592,11 +592,9 @@ def test_staticroute_with_ecmp_with_diff_AD_p0_tc4_ebgp(request):
)
assert (
result is not True
- ), "Testcase {} : Failed \nError: Routes are" " still present in RIB".format(
- tc_name
- )
+ ), "Testcase {} : Failed \nError: Routes are still present in RIB".format(tc_name)
- step("Configure the static route with nexthop N1 to N8, one by" "one")
+ step("Configure the static route with nexthop N1 to N8, one by one")
for addr_type in ADDR_TYPES:
# add static routes
for nhp in range(1, 9):
@@ -685,7 +683,7 @@ def test_staticroute_with_ecmp_with_diff_AD_p0_tc4_ebgp(request):
)
assert (
result is not True
- ), "Testcase {} : Failed \n" "Error: Routes are still present in RIB".format(
+ ), "Testcase {} : Failed \n Error: Routes are still present in RIB".format(
tc_name
)
@@ -699,7 +697,7 @@ def test_staticroute_with_ecmp_with_diff_AD_p0_tc4_ebgp(request):
)
assert (
result is True
- ), "Testcase {} : Failed \n" "Error: Routes are missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed \n Error: Routes are missing in RIB".format(tc_name)
step("Reload the FRR router")
# stop/start -> restart FRR router and verify
@@ -812,7 +810,7 @@ def test_bgp_local_nexthop_p1_tc14_ebgp(request):
result = verify_rib(tgen, addr_type, dut, input_dict_4)
assert (
result is True
- ), "Testcase {} : Failed \nError: Routes is" " missing in RIB of R2".format(
+ ), "Testcase {} : Failed \nError: routes are missing in RIB of R2".format(
tc_name
)
@@ -820,13 +818,13 @@ def test_bgp_local_nexthop_p1_tc14_ebgp(request):
dut = "r3"
result = verify_bgp_rib(tgen, addr_type, dut, input_dict_4, expected=False)
assert result is not True, (
- "Testcase {} : Failed \nError: Routes is"
+ "Testcase {} : Failed \nError: routes are"
" still present in BGP RIB of R2".format(tc_name)
)
result = verify_rib(tgen, addr_type, dut, input_dict_4, expected=False)
assert result is not True, (
- "Testcase {} : Failed \nError: Routes is"
+ "Testcase {} : Failed \nError: routes are"
" still present in RIB of R2".format(tc_name)
)
@@ -890,7 +888,7 @@ def test_frr_intf_name_as_gw_gap_tc4_ebgp_p0(request):
)
assert (
result is True
- ), "Testcase {} : Failed \nError: Routes is" " missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed \nError: routes are missing in RIB".format(tc_name)
input_dict_nh = {
"r1": {
@@ -904,7 +902,7 @@ def test_frr_intf_name_as_gw_gap_tc4_ebgp_p0(request):
result = verify_ip_nht(tgen, input_dict_nh)
assert (
result is True
- ), "Testcase {} : Failed \nError: Nexthop is" " missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed \nError: Nexthop is missing in RIB".format(tc_name)
step(
"Shut / no shut IPv4 and IPv6 static next hop interface from"
@@ -928,7 +926,7 @@ def test_frr_intf_name_as_gw_gap_tc4_ebgp_p0(request):
)
assert (
result is not True
- ), "Testcase {} : Failed \nError: Routes is" " missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed \nError: routes are missing in RIB".format(tc_name)
shutdown_bringup_interface(tgen, dut, intf, True)
@@ -974,9 +972,7 @@ def test_frr_intf_name_as_gw_gap_tc4_ebgp_p0(request):
)
assert (
result is not True
- ), "Testcase {} : Failed \nError: Routes" " still present in RIB".format(
- tc_name
- )
+ ), "Testcase {} : Failed \nError: Routes still present in RIB".format(tc_name)
write_test_footer(tc_name)
@@ -1002,7 +998,7 @@ def test_static_route_with_tag_p0_tc_13_ebgp(request):
"Configure 2 IPv4 static route (S1 and S2) in R2 with same"
"next hop N1 28.1.1.2"
)
- step("Configure static route S1 with tag 1 and static route S2 with" "tag2")
+ step("Configure static route S1 with tag 1 and static route S2 with tag2")
step("S1= ip route 10.1.1.1/24 28.1.1.2 tag 1")
step("S2= ip route 20.1.1.1/24 28.1.1.2 tag 2")
step("Enable redistribute static in BGP with route-map")
@@ -1041,7 +1037,7 @@ def test_static_route_with_tag_p0_tc_13_ebgp(request):
)
assert (
result is True
- ), "Testcase {} : Failed \nError: Routes are" " missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed \nError: Routes are missing in RIB".format(tc_name)
step("Configure route-map on R2 with allow tag1 and deny tag2")
@@ -1229,7 +1225,7 @@ def test_static_route_with_tag_p0_tc_13_ebgp(request):
)
assert (
result is True
- ), "Testcase {} : Failed \nError: Routes are" " missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed \nError: Routes are missing in RIB".format(tc_name)
step("shut/no shut of tag1 and tag2 nexthop")
diff --git a/tests/topotests/static_routing_with_ebgp/test_static_routes_topo4_ebgp.py b/tests/topotests/static_routing_with_ebgp/test_static_routes_topo4_ebgp.py
index c1099bd97e..2efc0fdf1b 100644
--- a/tests/topotests/static_routing_with_ebgp/test_static_routes_topo4_ebgp.py
+++ b/tests/topotests/static_routing_with_ebgp/test_static_routes_topo4_ebgp.py
@@ -204,12 +204,12 @@ def test_static_routes_rmap_pfxlist_p0_tc7_ebgp(request):
)
clear_bgp(tgen, addr_type, "r2")
- step(" All BGP nbrs are down as authentication is mismatch on both" " the sides")
+ step(" All BGP nbrs are down as authentication is mismatch on both the sides")
bgp_convergence = verify_bgp_convergence(tgen, topo, expected=False)
assert (
bgp_convergence is not True
- ), "Testcase {} : " "Failed \n BGP nbrs must be down. Error: {}".format(
+ ), "Testcase {} : Failed \n BGP nbrs must be down. Error: {}".format(
tc_name, bgp_convergence
)
@@ -256,7 +256,7 @@ def test_static_routes_rmap_pfxlist_p0_tc7_ebgp(request):
step("All BGP nbrs are up as authentication is matched now")
bgp_convergence = verify_bgp_convergence(tgen, topo)
- assert bgp_convergence is True, "Testcase {} : Failed \n " "Error: {}".format(
+ assert bgp_convergence is True, "Testcase {} : Failed \n Error: {}".format(
tc_name, bgp_convergence
)
@@ -306,7 +306,7 @@ def test_static_routes_rmap_pfxlist_p0_tc7_ebgp(request):
"show ip prefix list"
)
result = verify_prefix_lists(tgen, input_dict_2)
- assert result is not True, "Testcase {} : Failed \n" " Error: {}".format(
+ assert result is not True, "Testcase {} : Failed \n Error: {}".format(
tc_name, result
)
@@ -409,7 +409,7 @@ def test_static_routes_rmap_pfxlist_p0_tc7_ebgp(request):
tc_name, result
)
- step("Apply prefix list P1 on BGP neighbors 1 2 3 4 connected from " "frr r1")
+ step("Apply prefix list P1 on BGP neighbors 1 2 3 4 connected from frr r1")
# Configure prefix list to bgp neighbor
input_dict_4 = {
"r2": {
@@ -923,7 +923,7 @@ def test_static_routes_rmap_pfxlist_p0_tc7_ebgp(request):
)
assert (
result4 is not True
- ), "Testcase {} : Failed \n" "routes are still present \n Error: {}".format(
+ ), "Testcase {} : Failed \n routes are still present \n Error: {}".format(
tc_name, result4
)
diff --git a/tests/topotests/static_routing_with_ibgp/test_static_routes_topo1_ibgp.py b/tests/topotests/static_routing_with_ibgp/test_static_routes_topo1_ibgp.py
index 176ce7e48b..abae75e76e 100644
--- a/tests/topotests/static_routing_with_ibgp/test_static_routes_topo1_ibgp.py
+++ b/tests/topotests/static_routing_with_ibgp/test_static_routes_topo1_ibgp.py
@@ -206,7 +206,7 @@ def test_static_route_2nh_p0_tc_1_ibgp(request):
)
assert (
result is True
- ), "Testcase {} : Failed \nError: Routes is" " missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed \nError: routes are missing in RIB".format(tc_name)
step("Configure IBGP IPv4 peering between R2 and R3 router.")
step("Configure redistribute static in BGP on R2 router")
@@ -261,7 +261,7 @@ def test_static_route_2nh_p0_tc_1_ibgp(request):
)
assert (
result is not True
- ), "Testcase {} : Failed \nError: Routes is" " still present in RIB".format(
+ ), "Testcase {} : Failed \nError: routes are still present in RIB".format(
tc_name
)
@@ -271,7 +271,7 @@ def test_static_route_2nh_p0_tc_1_ibgp(request):
)
assert (
result is True
- ), "Testcase {} : Failed \nError: Routes is" " missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed \nError: routes are missing in RIB".format(tc_name)
step("Configure the static route with nexthop N1")
@@ -328,7 +328,7 @@ def test_static_route_2nh_p0_tc_1_ibgp(request):
)
assert (
result is not True
- ), "Testcase {} : Failed \nError: Routes is" " still present in RIB".format(
+ ), "Testcase {} : Failed \nError: routes are still present in RIB".format(
tc_name
)
@@ -338,7 +338,7 @@ def test_static_route_2nh_p0_tc_1_ibgp(request):
)
assert (
result is True
- ), "Testcase {} : Failed \nError: Routes is" " missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed \nError: routes are missing in RIB".format(tc_name)
step("Configure the static route with nexthop N2")
input_dict_4 = {
@@ -371,7 +371,7 @@ def test_static_route_2nh_p0_tc_1_ibgp(request):
)
assert (
result is True
- ), "Testcase {} : Failed \nError: Routes is" " missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed \nError: routes are missing in RIB".format(tc_name)
nh = NEXT_HOP_IP["nh1"][addr_type]
result = verify_rib(
@@ -385,7 +385,7 @@ def test_static_route_2nh_p0_tc_1_ibgp(request):
)
assert (
result is not True
- ), "Testcase {} : Failed \nError: Routes is" " still present in RIB".format(
+ ), "Testcase {} : Failed \nError: routes are still present in RIB".format(
tc_name
)
@@ -395,7 +395,7 @@ def test_static_route_2nh_p0_tc_1_ibgp(request):
)
assert (
result is not True
- ), "Testcase {} : Failed \nError: Route is" " still present in RIB".format(
+ ), "Testcase {} : Failed \nError: Route is still present in RIB".format(
tc_name
)
@@ -410,7 +410,7 @@ def test_static_route_2nh_p0_tc_1_ibgp(request):
)
assert (
result is not True
- ), "Testcase {} : Failed \nError: Route is" " still present in RIB".format(
+ ), "Testcase {} : Failed \nError: Route is still present in RIB".format(
tc_name
)
@@ -421,20 +421,20 @@ def test_static_route_2nh_p0_tc_1_ibgp(request):
)
assert (
result is True
- ), "Testcase {} : Failed \nError: Routes is" " missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed \nError: routes are missing in RIB".format(tc_name)
dut = "r3"
result = verify_bgp_rib(tgen, addr_type, dut, input_dict_4)
assert (
result is True
- ), "Testcase {} : Failed \nError: Route is" " missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed \nError: Route is missing in RIB".format(tc_name)
result = verify_rib(
tgen, addr_type, dut, input_dict_4, protocol=protocol, expected=False
)
assert (
result is not True
- ), "Testcase {} : Failed \nError: Route is" " still present in RIB".format(
+ ), "Testcase {} : Failed \nError: Route is still present in RIB".format(
tc_name
)
@@ -453,7 +453,7 @@ def test_static_route_2nh_p0_tc_1_ibgp(request):
)
assert (
result is True
- ), "Testcase {} : Failed \nError: Routes is" " missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed \nError: routes are missing in RIB".format(tc_name)
step("Shut nexthop interface N2")
intf = topo["routers"]["r2"]["links"]["r1-link1"]["interface"]
@@ -477,7 +477,7 @@ def test_static_route_2nh_p0_tc_1_ibgp(request):
)
assert (
result is not True
- ), "Testcase {} : Failed \nError: Routes is" " still present in RIB".format(
+ ), "Testcase {} : Failed \nError: routes are still present in RIB".format(
tc_name
)
@@ -489,20 +489,20 @@ def test_static_route_2nh_p0_tc_1_ibgp(request):
)
assert (
result is True
- ), "Testcase {} : Failed \nError: Routes is" " missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed \nError: routes are missing in RIB".format(tc_name)
dut = "r3"
result = verify_bgp_rib(tgen, addr_type, dut, input_dict_4)
assert (
result is True
- ), "Testcase {} : Failed \nError: Route is" " missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed \nError: Route is missing in RIB".format(tc_name)
result = verify_rib(
tgen, addr_type, dut, input_dict_4, protocol=protocol, expected=False
)
assert (
result is not True
- ), "Testcase {} : Failed \nError: Route is" " still present in RIB".format(
+ ), "Testcase {} : Failed \nError: Route is still present in RIB".format(
tc_name
)
@@ -521,20 +521,20 @@ def test_static_route_2nh_p0_tc_1_ibgp(request):
)
assert (
result is True
- ), "Testcase {} : Failed \nError: Routes is" " missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed \nError: routes are missing in RIB".format(tc_name)
dut = "r3"
result = verify_bgp_rib(tgen, addr_type, dut, input_dict_4)
assert (
result is True
- ), "Testcase {} : Failed \nError: Route is" " missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed \nError: Route is missing in RIB".format(tc_name)
result = verify_rib(
tgen, addr_type, dut, input_dict_4, protocol=protocol, expected=False
)
assert (
result is not True
- ), "Testcase {} : Failed \nError: Route is" " still present in RIB".format(
+ ), "Testcase {} : Failed \nError: Route is still present in RIB".format(
tc_name
)
@@ -554,13 +554,13 @@ def test_static_route_2nh_p0_tc_1_ibgp(request):
)
assert (
result is True
- ), "Testcase {} : Failed \nError: Routes is" " missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed \nError: routes are missing in RIB".format(tc_name)
dut = "r3"
result = verify_bgp_rib(tgen, addr_type, dut, input_dict_4)
assert (
result is True
- ), "Testcase {} : Failed \nError: Route is" " still present in RIB".format(
+ ), "Testcase {} : Failed \nError: Route is still present in RIB".format(
tc_name
)
@@ -569,7 +569,7 @@ def test_static_route_2nh_p0_tc_1_ibgp(request):
)
assert (
result is not True
- ), "Testcase {} : Failed \nError: Route is" " still present in RIB".format(
+ ), "Testcase {} : Failed \nError: Route is still present in RIB".format(
tc_name
)
@@ -645,7 +645,7 @@ def test_static_route_2nh_admin_dist_p0_tc_2_ibgp(request):
)
assert (
result is True
- ), "Testcase {} : Failed \nError: Routes is" "missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed \nError: routes are missing in RIB".format(tc_name)
rte2_nh2 = {
"r2": {
@@ -673,7 +673,7 @@ def test_static_route_2nh_admin_dist_p0_tc_2_ibgp(request):
)
assert (
result is not True
- ), "Testcase {} : Failed \nError: Routes is" "not active in RIB".format(tc_name)
+ ), "Testcase {} : Failed \nError: routes are not active in RIB".format(tc_name)
step("Configure IBGP IPv4 peering between R2 and R3 router.")
step("Explicit route is added in R3 for R2 nexthop rechability")
@@ -764,7 +764,7 @@ def test_static_route_2nh_admin_dist_p0_tc_2_ibgp(request):
)
assert (
result is not True
- ), "Testcase {} : Failed \nError: Routes is" "missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed \nError: routes are missing in RIB".format(tc_name)
rte2_nh2 = {
"r2": {
@@ -783,7 +783,7 @@ def test_static_route_2nh_admin_dist_p0_tc_2_ibgp(request):
)
assert (
result is True
- ), "Testcase {} : Failed \nError: Routes is" "not active in RIB".format(tc_name)
+ ), "Testcase {} : Failed \nError: routes are not active in RIB".format(tc_name)
step("Configure the static route with nexthop N1")
rte1_nh1 = {
@@ -838,7 +838,7 @@ def test_static_route_2nh_admin_dist_p0_tc_2_ibgp(request):
)
assert (
result is not True
- ), "Testcase {} : Failed \nError: Routes is" " still present in RIB".format(
+ ), "Testcase {} : Failed \nError: routes are still present in RIB".format(
tc_name
)
@@ -848,7 +848,7 @@ def test_static_route_2nh_admin_dist_p0_tc_2_ibgp(request):
)
assert (
result is True
- ), "Testcase {} : Failed \nError: Routes is" " missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed \nError: routes are missing in RIB".format(tc_name)
step("Configure the static route with nexthop N2")
rte2_nh2 = {
@@ -888,7 +888,7 @@ def test_static_route_2nh_admin_dist_p0_tc_2_ibgp(request):
)
assert (
result is not True
- ), "Testcase {} : Failed \nError: Routes is" " still present in RIB".format(
+ ), "Testcase {} : Failed \nError: routes are still present in RIB".format(
tc_name
)
@@ -898,7 +898,7 @@ def test_static_route_2nh_admin_dist_p0_tc_2_ibgp(request):
)
assert (
result is True
- ), "Testcase {} : Failed \nError: Routes is" " missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed \nError: routes are missing in RIB".format(tc_name)
step("No shut the nexthop interface N1")
shutdown_bringup_interface(tgen, dut, intf, True)
@@ -914,7 +914,7 @@ def test_static_route_2nh_admin_dist_p0_tc_2_ibgp(request):
)
assert (
result is True
- ), "Testcase {} : Failed \nError: Routes is" " missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed \nError: routes are missing in RIB".format(tc_name)
step("Shut nexthop interface N2")
intf = topo["routers"]["r2"]["links"]["r1-link1"]["interface"]
@@ -938,7 +938,7 @@ def test_static_route_2nh_admin_dist_p0_tc_2_ibgp(request):
)
assert (
result is not True
- ), "Testcase {} : Failed \nError: Routes is" " still present in RIB".format(
+ ), "Testcase {} : Failed \nError: routes are still present in RIB".format(
tc_name
)
@@ -948,7 +948,7 @@ def test_static_route_2nh_admin_dist_p0_tc_2_ibgp(request):
)
assert (
result is True
- ), "Testcase {} : Failed \nError: Routes is" " missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed \nError: routes are missing in RIB".format(tc_name)
step("No shut nexthop interface N2")
shutdown_bringup_interface(tgen, dut, intf, True)
@@ -976,7 +976,7 @@ def test_static_route_2nh_admin_dist_p0_tc_2_ibgp(request):
)
assert (
result is True
- ), "Testcase {} : Failed \nError: Routes is" "missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed \nError: routes are missing in RIB".format(tc_name)
rte2_nh2 = {
"r2": {
@@ -1004,7 +1004,7 @@ def test_static_route_2nh_admin_dist_p0_tc_2_ibgp(request):
)
assert (
result is not True
- ), "Testcase {} : Failed \nError: Routes is" "not active in RIB".format(tc_name)
+ ), "Testcase {} : Failed \nError: routes are not active in RIB".format(tc_name)
dut = "r3"
protocol = "bgp"
@@ -1021,7 +1021,7 @@ def test_static_route_2nh_admin_dist_p0_tc_2_ibgp(request):
)
assert (
result is not True
- ), "Testcase {} : Failed \nError: Routes is" "not active in RIB".format(tc_name)
+ ), "Testcase {} : Failed \nError: routes are not active in RIB".format(tc_name)
dut = "r2"
step("Reload the FRR router")
@@ -1053,14 +1053,14 @@ def test_static_route_2nh_admin_dist_p0_tc_2_ibgp(request):
)
assert (
result is True
- ), "Testcase {} : Failed \nError: Routes is" "missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed \nError: routes are missing in RIB".format(tc_name)
dut = "r3"
protocol = "bgp"
result = verify_bgp_rib(tgen, addr_type, dut, rte1_nh1, next_hop=nh)
assert (
result is True
- ), "Testcase {} : Failed \nError: Routes is" "missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed \nError: routes are missing in RIB".format(tc_name)
rte2_nh2 = {
"r2": {
@@ -1088,14 +1088,14 @@ def test_static_route_2nh_admin_dist_p0_tc_2_ibgp(request):
)
assert (
result is not True
- ), "Testcase {} : Failed \nError: Routes is" "not active in RIB".format(tc_name)
+ ), "Testcase {} : Failed \nError: routes are not active in RIB".format(tc_name)
dut = "r3"
protocol = "bgp"
result = verify_bgp_rib(tgen, addr_type, dut, rte2_nh2, next_hop=nh)
assert (
result is True
- ), "Testcase {} : Failed \nError: Routes is" "not active in RIB".format(tc_name)
+ ), "Testcase {} : Failed \nError: routes are not active in RIB".format(tc_name)
result = verify_rib(
tgen,
@@ -1109,7 +1109,7 @@ def test_static_route_2nh_admin_dist_p0_tc_2_ibgp(request):
)
assert (
result is not True
- ), "Testcase {} : Failed \nError: Routes is" "not active in RIB".format(tc_name)
+ ), "Testcase {} : Failed \nError: routes are not active in RIB".format(tc_name)
write_test_footer(tc_name)
diff --git a/tests/topotests/static_routing_with_ibgp/test_static_routes_topo2_ibgp.py b/tests/topotests/static_routing_with_ibgp/test_static_routes_topo2_ibgp.py
index 20c68dc25f..820a736ad7 100644
--- a/tests/topotests/static_routing_with_ibgp/test_static_routes_topo2_ibgp.py
+++ b/tests/topotests/static_routing_with_ibgp/test_static_routes_topo2_ibgp.py
@@ -283,7 +283,7 @@ def test_static_rte_with_8ecmp_nh_p1_tc9_ibgp(request):
)
assert (
result is True
- ), "Testcase {} : Failed \nError: Routes are" " missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed \nError: Routes are missing in RIB".format(tc_name)
step("Configure redistribute static in BGP on R2 router")
for addr_type in ADDR_TYPES:
@@ -308,7 +308,7 @@ def test_static_rte_with_8ecmp_nh_p1_tc9_ibgp(request):
result = verify_bgp_rib(tgen, addr_type, dut, input_dict_4)
assert (
result is True
- ), "Testcase {} : Failed \nError: Routes are" " missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed \nError: Routes are missing in RIB".format(tc_name)
step(
"Remove the static route configured with nexthop N1 to N8, one"
@@ -355,7 +355,7 @@ def test_static_rte_with_8ecmp_nh_p1_tc9_ibgp(request):
)
assert (
result is not True
- ), "Testcase {} : Failed\nError: Routes is" " still present in RIB".format(
+ ), "Testcase {} : Failed\nError: routes are still present in RIB".format(
tc_name
)
@@ -384,9 +384,7 @@ def test_static_rte_with_8ecmp_nh_p1_tc9_ibgp(request):
)
assert (
result is True
- ), "Testcase {} : Failed\nError: Routes are" " missing in RIB".format(
- tc_name
- )
+ ), "Testcase {} : Failed\nError: Routes are missing in RIB".format(tc_name)
protocol = "static"
step("Random shut of the nexthop interfaces")
@@ -432,7 +430,7 @@ def test_static_rte_with_8ecmp_nh_p1_tc9_ibgp(request):
)
assert (
result is True
- ), "Testcase {} : Failed \nError: Routes are" " missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed \nError: Routes are missing in RIB".format(tc_name)
step("Remove random static route with all the nexthop")
dut = "r2"
@@ -471,7 +469,7 @@ def test_static_rte_with_8ecmp_nh_p1_tc9_ibgp(request):
)
assert (
result is not True
- ), "Testcase {} : Failed \nError: Routes are" " missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed \nError: Routes are missing in RIB".format(tc_name)
for addr_type in ADDR_TYPES:
input_dict_4 = {
@@ -525,7 +523,7 @@ def test_static_rte_with_8ecmp_nh_p1_tc9_ibgp(request):
)
assert (
result is True
- ), "Testcase {} : Failed \nError: Routes are" " missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed \nError: Routes are missing in RIB".format(tc_name)
step("Remove the redistribute static knob")
for addr_type in ADDR_TYPES:
@@ -560,7 +558,7 @@ def test_static_rte_with_8ecmp_nh_p1_tc9_ibgp(request):
)
assert (
result is not True
- ), "Testcase {} : Failed \nError: Routes are" " still present in RIB".format(
+ ), "Testcase {} : Failed \nError: Routes are still present in RIB".format(
tc_name
)
@@ -644,7 +642,7 @@ def test_static_route_8nh_diff_AD_bgp_ecmp_p1_tc6_ibgp(request):
)
assert (
result is True
- ), "Testcase {} : Failed \nError: Routes are" " missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed \nError: Routes are missing in RIB".format(tc_name)
nh = []
for nhp in range(2, 9):
@@ -662,7 +660,7 @@ def test_static_route_8nh_diff_AD_bgp_ecmp_p1_tc6_ibgp(request):
)
assert (
result is not True
- ), "Testcase {} : Failed \nError: Routes " " are present in RIB".format(tc_name)
+ ), "Testcase {} : Failed \nError: Routes are present in RIB".format(tc_name)
step(
"Remove the static route configured with nexthop N1 to N8, one"
@@ -707,9 +705,7 @@ def test_static_route_8nh_diff_AD_bgp_ecmp_p1_tc6_ibgp(request):
)
assert (
result is not True
- ), "Testcase {} : Failed \nError: Routes are" " still present in RIB".format(
- tc_name
- )
+ ), "Testcase {} : Failed \nError: Routes are still present in RIB".format(tc_name)
step("Configure the static route with nexthop N1 to N8, one by one")
@@ -757,7 +753,7 @@ def test_static_route_8nh_diff_AD_bgp_ecmp_p1_tc6_ibgp(request):
)
assert (
result is True
- ), "Testcase {} : Failed \nError: Routes are" " missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed \nError: Routes are missing in RIB".format(tc_name)
nh = []
for nhp in range(2, 9):
nh.append(NEXT_HOP_IP["nh" + str(nhp)][addr_type])
@@ -774,7 +770,7 @@ def test_static_route_8nh_diff_AD_bgp_ecmp_p1_tc6_ibgp(request):
)
assert (
result is not True
- ), "Testcase {} : Failed \nError: Routes " " are missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed \nError: Routes are missing in RIB".format(tc_name)
step("Random shut of the nexthop interfaces")
randnum = random.randint(0, 7)
@@ -803,7 +799,7 @@ def test_static_route_8nh_diff_AD_bgp_ecmp_p1_tc6_ibgp(request):
)
assert (
result is not True
- ), "Testcase {} : Failed \n" "Error: Routes are still present in RIB".format(
+ ), "Testcase {} : Failed \n Error: Routes are still present in RIB".format(
tc_name
)
@@ -817,7 +813,7 @@ def test_static_route_8nh_diff_AD_bgp_ecmp_p1_tc6_ibgp(request):
)
assert (
result is True
- ), "Testcase {} : Failed \n" "Error: Routes are missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed \n Error: Routes are missing in RIB".format(tc_name)
protocol = "bgp"
# this is next hop reachability route in r3 as we are using ibgp
@@ -844,7 +840,7 @@ def test_static_route_8nh_diff_AD_bgp_ecmp_p1_tc6_ibgp(request):
result = verify_rib(tgen, addr_type, dut, input_dict_4, protocol=protocol)
assert (
result is True
- ), "Testcase {} : Failed \n" "Error: Routes are missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed \n Error: Routes are missing in RIB".format(tc_name)
protocol = "static"
dut = "r2"
@@ -1051,7 +1047,7 @@ def test_static_route_8nh_diff_AD_ibgp_ecmp_p1_tc7_ibgp(request):
)
assert (
result is True
- ), "Testcase {} : Failed \nError: Routes are" " missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed \nError: Routes are missing in RIB".format(tc_name)
nh = []
for nhp in range(2, 9):
@@ -1068,7 +1064,7 @@ def test_static_route_8nh_diff_AD_ibgp_ecmp_p1_tc7_ibgp(request):
)
assert (
result is not True
- ), "Testcase {} : Failed \nError: Routes " " are missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed \nError: Routes are missing in RIB".format(tc_name)
step(
"Remove the static route configured with nexthop N1 to N8, one"
@@ -1113,9 +1109,7 @@ def test_static_route_8nh_diff_AD_ibgp_ecmp_p1_tc7_ibgp(request):
)
assert (
result is not True
- ), "Testcase {} : Failed \nError: Routes are" " still present in RIB".format(
- tc_name
- )
+ ), "Testcase {} : Failed \nError: Routes are still present in RIB".format(tc_name)
step("Configure the static route with nexthop N1 to N8, one by one")
@@ -1163,7 +1157,7 @@ def test_static_route_8nh_diff_AD_ibgp_ecmp_p1_tc7_ibgp(request):
)
assert (
result is True
- ), "Testcase {} : Failed \nError: Routes are" " missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed \nError: Routes are missing in RIB".format(tc_name)
nh = []
for nhp in range(2, 9):
nh.append(NEXT_HOP_IP["nh" + str(nhp)][addr_type])
@@ -1179,7 +1173,7 @@ def test_static_route_8nh_diff_AD_ibgp_ecmp_p1_tc7_ibgp(request):
)
assert (
result is not True
- ), "Testcase {} : Failed \nError: Routes " " are missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed \nError: Routes are missing in RIB".format(tc_name)
step("Random shut of the nexthop interfaces")
randnum = random.randint(0, 7)
@@ -1208,7 +1202,7 @@ def test_static_route_8nh_diff_AD_ibgp_ecmp_p1_tc7_ibgp(request):
)
assert (
result is not True
- ), "Testcase {} : Failed \n" "Error: Routes are still present in RIB".format(
+ ), "Testcase {} : Failed \n Error: Routes are still present in RIB".format(
tc_name
)
@@ -1222,7 +1216,7 @@ def test_static_route_8nh_diff_AD_ibgp_ecmp_p1_tc7_ibgp(request):
)
assert (
result is True
- ), "Testcase {} : Failed \n" "Error: Routes are missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed \n Error: Routes are missing in RIB".format(tc_name)
dut = "r2"
protocol = "bgp"
@@ -1251,7 +1245,7 @@ def test_static_route_8nh_diff_AD_ibgp_ecmp_p1_tc7_ibgp(request):
result = verify_rib(tgen, addr_type, dut, input_dict_4, protocol=protocol)
assert (
result is True
- ), "Testcase {} : Failed \n" "Error: Routes are missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed \n Error: Routes are missing in RIB".format(tc_name)
protocol = "static"
dut = "r2"
@@ -1458,7 +1452,7 @@ def test_static_route_8nh_diff_AD_bgp_ecmp_p1_tc10_ibgp(request):
)
assert (
result is True
- ), "Testcase {} : Failed \nError: Routes are" " missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed \nError: Routes are missing in RIB".format(tc_name)
step("Verify that highest AD nexthop are inactive")
nh = []
@@ -1477,7 +1471,7 @@ def test_static_route_8nh_diff_AD_bgp_ecmp_p1_tc10_ibgp(request):
)
assert (
result is not True
- ), "Testcase {} : Failed \nError: Routes " " are missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed \nError: Routes are missing in RIB".format(tc_name)
step("Configure redistribute static in BGP on R2 router")
for addr_type in ADDR_TYPES:
@@ -1541,7 +1535,7 @@ def test_static_route_8nh_diff_AD_bgp_ecmp_p1_tc10_ibgp(request):
)
assert (
result is not True
- ), "Testcase {} : Failed \nError: Routes are" " still present in RIB".format(
+ ), "Testcase {} : Failed \nError: Routes are still present in RIB".format(
tc_name
)
@@ -1572,15 +1566,7 @@ def test_static_route_8nh_diff_AD_bgp_ecmp_p1_tc10_ibgp(request):
" value and all the nexthop populated in RIB and FIB again"
)
for addr_type in ADDR_TYPES:
- input_dict_4 = {
- "r2": {
- "static_routes": [
- {
- "network": PREFIX1[addr_type],
- }
- ]
- }
- }
+ input_dict_4 = {"r2": {"static_routes": [{"network": PREFIX1[addr_type]}]}}
nh = NEXT_HOP_IP["nh1"][addr_type]
result = verify_rib(
tgen, addr_type, dut, input_dict_4, next_hop=nh, protocol=protocol, fib=True
@@ -1617,7 +1603,7 @@ def test_static_route_8nh_diff_AD_bgp_ecmp_p1_tc10_ibgp(request):
)
assert (
result is not True
- ), "Testcase {} : Failed \n" "Error: Routes are still present in RIB".format(
+ ), "Testcase {} : Failed \n Error: Routes are still present in RIB".format(
tc_name
)
@@ -1631,7 +1617,7 @@ def test_static_route_8nh_diff_AD_bgp_ecmp_p1_tc10_ibgp(request):
)
assert (
result is True
- ), "Testcase {} : Failed \n" "Error: Routes are missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed \n Error: Routes are missing in RIB".format(tc_name)
step("Remove random static route with all the nexthop")
for addr_type in ADDR_TYPES:
@@ -1767,7 +1753,7 @@ def test_static_route_8nh_diff_AD_bgp_ecmp_p1_tc10_ibgp(request):
)
assert (
result is not True
- ), "Testcase {} : Failed \nError: Routes are" " still present in RIB".format(
+ ), "Testcase {} : Failed \nError: Routes are still present in RIB".format(
tc_name
)
@@ -1865,7 +1851,7 @@ def test_static_route_delete_p0_tc11_ibgp(request):
)
assert (
result is True
- ), "Testcase {} : Failed \nError: Routes are" " missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed \nError: Routes are missing in RIB".format(tc_name)
step("Verify that highest AD nexthop are inactive")
nh = []
@@ -1883,7 +1869,7 @@ def test_static_route_delete_p0_tc11_ibgp(request):
)
assert (
result is not True
- ), "Testcase {} : Failed \nError: Routes " " are missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed \nError: Routes are missing in RIB".format(tc_name)
step("Configure redistribute static in BGP on R2 router")
for addr_type in ADDR_TYPES:
@@ -1937,7 +1923,7 @@ def test_static_route_delete_p0_tc11_ibgp(request):
)
assert (
result is not True
- ), "Testcase {} : Failed \nError: Routes are" " still present in RIB".format(
+ ), "Testcase {} : Failed \nError: Routes are still present in RIB".format(
tc_name
)
@@ -2008,7 +1994,7 @@ def test_static_route_delete_p0_tc11_ibgp(request):
)
assert (
result is not True
- ), "Testcase {} : Failed \nError: Routes are" " still active in RIB".format(
+ ), "Testcase {} : Failed \nError: Routes are still active in RIB".format(
tc_name
)
diff --git a/tests/topotests/static_routing_with_ibgp/test_static_routes_topo3_ibgp.py b/tests/topotests/static_routing_with_ibgp/test_static_routes_topo3_ibgp.py
index 7f35927311..1ad963f314 100644
--- a/tests/topotests/static_routing_with_ibgp/test_static_routes_topo3_ibgp.py
+++ b/tests/topotests/static_routing_with_ibgp/test_static_routes_topo3_ibgp.py
@@ -261,7 +261,7 @@ def test_staticroute_with_ecmp_p0_tc3_ibgp(request):
)
assert (
result is True
- ), "Testcase {} : Failed \nError: Routes are" " missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed \nError: Routes are missing in RIB".format(tc_name)
step("Configure redistribute static in BGP on R2 router")
for addr_type in ADDR_TYPES:
input_dict_2 = {
@@ -316,11 +316,11 @@ def test_staticroute_with_ecmp_p0_tc3_ibgp(request):
)
assert (
result is not True
- ), "Testcase {} : Failed \nError: Routes are" " still present in RIB".format(
+ ), "Testcase {} : Failed \nError: Routes are still present in RIB".format(
tc_name
)
- step("Configure the static route with nexthop N1 to N8, one by" "one")
+ step("Configure the static route with nexthop N1 to N8, one by one")
for addr_type in ADDR_TYPES:
# add static routes
@@ -347,7 +347,7 @@ def test_staticroute_with_ecmp_p0_tc3_ibgp(request):
)
assert (
result is True
- ), "Testcase {} : Failed \nError: Routes are" " missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed \nError: Routes are missing in RIB".format(tc_name)
step("Random shut of the nexthop interfaces")
randnum = random.randint(0, 7)
@@ -376,7 +376,7 @@ def test_staticroute_with_ecmp_p0_tc3_ibgp(request):
)
assert (
result is not True
- ), "Testcase {} : Failed \n" "Error: Routes are still present in RIB".format(
+ ), "Testcase {} : Failed \n Error: Routes are still present in RIB".format(
tc_name
)
@@ -390,7 +390,7 @@ def test_staticroute_with_ecmp_p0_tc3_ibgp(request):
)
assert (
result is True
- ), "Testcase {} : Failed \n" "Error: Routes are missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed \n Error: Routes are missing in RIB".format(tc_name)
step("Reload the FRR router")
# stop/start -> restart FRR router and verify
@@ -402,7 +402,7 @@ def test_staticroute_with_ecmp_p0_tc3_ibgp(request):
)
assert (
result is True
- ), "Testcase {} : Failed \nError: Routes are" " missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed \nError: Routes are missing in RIB".format(tc_name)
write_test_footer(tc_name)
@@ -591,11 +591,9 @@ def test_staticroute_with_ecmp_with_diff_AD_p0_tc4_ibgp(request):
)
assert (
result is not True
- ), "Testcase {} : Failed \nError: Routes are" " still present in RIB".format(
- tc_name
- )
+ ), "Testcase {} : Failed \nError: Routes are still present in RIB".format(tc_name)
- step("Configure the static route with nexthop N1 to N8, one by" "one")
+ step("Configure the static route with nexthop N1 to N8, one by one")
for addr_type in ADDR_TYPES:
# add static routes
for nhp in range(1, 9):
@@ -684,7 +682,7 @@ def test_staticroute_with_ecmp_with_diff_AD_p0_tc4_ibgp(request):
)
assert (
result is not True
- ), "Testcase {} : Failed \n" "Error: Routes are still present in RIB".format(
+ ), "Testcase {} : Failed \n Error: Routes are still present in RIB".format(
tc_name
)
@@ -698,7 +696,7 @@ def test_staticroute_with_ecmp_with_diff_AD_p0_tc4_ibgp(request):
)
assert (
result is True
- ), "Testcase {} : Failed \n" "Error: Routes are missing in RIB".format(tc_name)
+ ), "Testcase {} : Failed \n Error: Routes are missing in RIB".format(tc_name)
step("Reload the FRR router")
# stop/start -> restart FRR router and verify
@@ -852,7 +850,7 @@ def test_bgp_local_nexthop_p1_tc14_ibgp(request):
result = verify_rib(tgen, addr_type, dut, input_dict_4)
assert (
result is True
- ), "Testcase {} : Failed \nError: Routes is" " missing in RIB of R2".format(
+ ), "Testcase {} : Failed \nError: routes are missing in RIB of R2".format(
tc_name
)
@@ -860,13 +858,13 @@ def test_bgp_local_nexthop_p1_tc14_ibgp(request):
dut = "r3"
result = verify_bgp_rib(tgen, addr_type, dut, input_dict_4, expected=False)
assert result is not True, (
- "Testcase {} : Failed \nError: Routes is"
+ "Testcase {} : Failed \nError: routes are"
" still present in BGP RIB of R2".format(tc_name)
)
result = verify_rib(tgen, addr_type, dut, input_dict_4, expected=False)
assert result is not True, (
- "Testcase {} : Failed \nError: Routes is"
+ "Testcase {} : Failed \nError: routes are"
" still present in RIB of R2".format(tc_name)
)
diff --git a/tests/topotests/static_routing_with_ibgp/test_static_routes_topo4_ibgp.py b/tests/topotests/static_routing_with_ibgp/test_static_routes_topo4_ibgp.py
index e50362b571..0378240959 100644
--- a/tests/topotests/static_routing_with_ibgp/test_static_routes_topo4_ibgp.py
+++ b/tests/topotests/static_routing_with_ibgp/test_static_routes_topo4_ibgp.py
@@ -200,12 +200,12 @@ def test_static_routes_rmap_pfxlist_p0_tc7_ibgp(request):
)
clear_bgp(tgen, addr_type, "r2")
- step(" All BGP nbrs are down as authentication is mismatch on both" " the sides")
+ step(" All BGP nbrs are down as authentication is mismatch on both the sides")
bgp_convergence = verify_bgp_convergence(tgen, topo, expected=False)
assert (
bgp_convergence is not True
- ), "Testcase {} : " "Failed \n BGP nbrs must be down. Error: {}".format(
+ ), "Testcase {} : Failed \n BGP nbrs must be down. Error: {}".format(
tc_name, bgp_convergence
)
@@ -252,7 +252,7 @@ def test_static_routes_rmap_pfxlist_p0_tc7_ibgp(request):
step("All BGP nbrs are up as authentication is matched now")
bgp_convergence = verify_bgp_convergence(tgen, topo)
- assert bgp_convergence is True, "Testcase {} : Failed \n " "Error: {}".format(
+ assert bgp_convergence is True, "Testcase {} : Failed \n Error: {}".format(
tc_name, bgp_convergence
)
@@ -302,7 +302,7 @@ def test_static_routes_rmap_pfxlist_p0_tc7_ibgp(request):
"show ip prefix list"
)
result = verify_prefix_lists(tgen, input_dict_2)
- assert result is not True, "Testcase {} : Failed \n" " Error: {}".format(
+ assert result is not True, "Testcase {} : Failed \n Error: {}".format(
tc_name, result
)
@@ -405,7 +405,7 @@ def test_static_routes_rmap_pfxlist_p0_tc7_ibgp(request):
tc_name, result
)
- step("Apply prefix list P1 on BGP neighbors 1 2 3 4 connected from " "frr r1")
+ step("Apply prefix list P1 on BGP neighbors 1 2 3 4 connected from frr r1")
# Configure prefix list to bgp neighbor
input_dict_4 = {
"r2": {
@@ -919,7 +919,7 @@ def test_static_routes_rmap_pfxlist_p0_tc7_ibgp(request):
)
assert (
result4 is not True
- ), "Testcase {} : Failed \n" "routes are still present \n Error: {}".format(
+ ), "Testcase {} : Failed \n routes are still present \n Error: {}".format(
tc_name, result4
)
diff --git a/tests/topotests/static_simple/r1/mgmtd.conf b/tests/topotests/static_simple/r1/mgmtd.conf
new file mode 100644
index 0000000000..0f9f97ca1a
--- /dev/null
+++ b/tests/topotests/static_simple/r1/mgmtd.conf
@@ -0,0 +1 @@
+log timestamp precision 3
diff --git a/tests/topotests/static_simple/r1/staticd.conf b/tests/topotests/static_simple/r1/staticd.conf
new file mode 100644
index 0000000000..0f9f97ca1a
--- /dev/null
+++ b/tests/topotests/static_simple/r1/staticd.conf
@@ -0,0 +1 @@
+log timestamp precision 3
diff --git a/tests/topotests/static_simple/r1/zebra.conf b/tests/topotests/static_simple/r1/zebra.conf
new file mode 100644
index 0000000000..ec827617ab
--- /dev/null
+++ b/tests/topotests/static_simple/r1/zebra.conf
@@ -0,0 +1,11 @@
+log timestamp precision 3
+
+interface r1-eth0
+ ip address 101.0.0.1/24
+ ipv6 address 2101::1/64
+exit
+
+interface r1-eth1 vrf red
+ ip address 102.0.0.1/24
+ ipv6 address 2102::1/64
+exit
diff --git a/tests/topotests/static_simple/test_static_simple.py b/tests/topotests/static_simple/test_static_simple.py
new file mode 100644
index 0000000000..817336ac21
--- /dev/null
+++ b/tests/topotests/static_simple/test_static_simple.py
@@ -0,0 +1,214 @@
+#!/usr/bin/env python
+# SPDX-License-Identifier: ISC
+#
+# Copyright (c) 2021, LabN Consulting, L.L.C.
+# Copyright (c) 2019-2020 by
+# Donatas Abraitis <donatas.abraitis@gmail.com>
+#
+"""
+Test static route functionality
+"""
+
+import datetime
+import ipaddress
+import math
+import os
+import sys
+import re
+
+import pytest
+from lib.topogen import TopoRouter, Topogen, get_topogen
+from lib.topolog import logger
+from lib.common_config import retry, step
+
+pytestmark = [pytest.mark.staticd]
+
+
+@pytest.fixture(scope="module")
+def tgen(request):
+ "Setup/Teardown the environment and provide tgen argument to tests"
+
+ topodef = {"s1": ("r1",), "s2": ("r1",)}
+
+ tgen = Topogen(topodef, request.module.__name__)
+ tgen.start_topology()
+
+ router_list = tgen.routers()
+ for rname, router in router_list.items():
+ # Setup VRF red
+ router.net.add_l3vrf("red", 10)
+ router.net.add_loop("lo-red")
+ router.net.attach_iface_to_l3vrf("lo-red", "red")
+ router.net.attach_iface_to_l3vrf(rname + "-eth1", "red")
+ # and select daemons to run
+ router.load_config(TopoRouter.RD_ZEBRA, "zebra.conf")
+ router.load_config(TopoRouter.RD_MGMTD)
+ router.load_config(TopoRouter.RD_STATIC)
+
+ tgen.start_router()
+ yield tgen
+ tgen.stop_topology()
+
+
+def get_ip_networks(super_prefix, count):
+ count_log2 = math.log(count, 2)
+ if count_log2 != int(count_log2):
+ count_log2 = int(count_log2) + 1
+ else:
+ count_log2 = int(count_log2)
+ network = ipaddress.ip_network(super_prefix)
+ return tuple(network.subnets(count_log2))[0:count]
+
+
+def enable_debug(router):
+ router.vtysh_cmd("debug northbound callbacks configuration")
+
+
+def disable_debug(router):
+ router.vtysh_cmd("no debug northbound callbacks configuration")
+
+
+@retry(retry_timeout=3, initial_wait=0.1)
+def check_kernel(r1, super_prefix, count, add, is_blackhole, vrf, matchvia):
+ network = ipaddress.ip_network(super_prefix)
+ vrfstr = f" vrf {vrf}" if vrf else ""
+ if network.version == 6:
+ kernel = r1.run(f"ip -6 route show{vrfstr}")
+ else:
+ kernel = r1.run(f"ip -4 route show{vrfstr}")
+
+ logger.debug("checking kernel routing table%s:\n%s", vrfstr, kernel)
+ for i, net in enumerate(get_ip_networks(super_prefix, count)):
+ if not add:
+ assert str(net) not in kernel
+ continue
+
+ if is_blackhole:
+ route = f"blackhole {str(net)} proto (static|196) metric 20"
+ else:
+ route = (
+ f"{str(net)}(?: nhid [0-9]+)? {matchvia} "
+ "proto (static|196) metric 20"
+ )
+ assert re.search(route, kernel), f"Failed to find \n'{route}'\n in \n'{kernel}'"
+
+
+def do_config(
+ r1,
+ count,
+ add=True,
+ do_ipv6=False,
+ via=None,
+ vrf=None,
+ use_cli=False,
+):
+ optype = "adding" if add else "removing"
+ iptype = "IPv6" if do_ipv6 else "IPv4"
+
+ #
+ # Set the route details
+ #
+
+ if vrf:
+ super_prefix = "2002::/48" if do_ipv6 else "20.0.0.0/8"
+ else:
+ super_prefix = "2001::/48" if do_ipv6 else "10.0.0.0/8"
+
+ matchtype = ""
+ matchvia = ""
+ if via == "blackhole":
+ pass
+ elif via:
+ matchvia = f"dev {via}"
+ else:
+ if vrf:
+ via = "2102::2" if do_ipv6 else "102.0.0.2"
+ matchvia = f"via {via} dev r1-eth1"
+ else:
+ via = "2101::2" if do_ipv6 else "101.0.0.2"
+ matchvia = f"via {via} dev r1-eth0"
+
+ vrfdbg = " in vrf {}".format(vrf) if vrf else ""
+ logger.debug("{} {} static {} routes{}".format(optype, count, iptype, vrfdbg))
+
+ #
+ # Generate config file in a retrievable place
+ #
+
+ config_file = os.path.join(
+ r1.logdir, r1.name, "{}-routes-{}.conf".format(iptype.lower(), optype)
+ )
+ with open(config_file, "w") as f:
+ if use_cli:
+ f.write("configure terminal\n")
+ if vrf:
+ f.write("vrf {}\n".format(vrf))
+
+ for i, net in enumerate(get_ip_networks(super_prefix, count)):
+ if add:
+ f.write("ip route {} {}\n".format(net, via))
+ else:
+ f.write("no ip route {} {}\n".format(net, via))
+
+ #
+ # Load config file.
+ #
+
+ if use_cli:
+ load_command = 'vtysh < "{}"'.format(config_file)
+ else:
+ load_command = 'vtysh -f "{}"'.format(config_file)
+ tstamp = datetime.datetime.now()
+ output = r1.cmd_raises(load_command)
+ delta = (datetime.datetime.now() - tstamp).total_seconds()
+
+ #
+ # Verify the results are in the kernel
+ #
+ check_kernel(r1, super_prefix, count, add, via == "blackhole", vrf, matchvia)
+
+ optyped = "added" if add else "removed"
+ logger.debug(
+ "{} {} {} static routes under {}{} in {}s".format(
+ optyped, count, iptype.lower(), super_prefix, vrfdbg, delta
+ )
+ )
+
+
+def guts(tgen, vrf, use_cli):
+ if tgen.routers_have_failure():
+ pytest.skip(tgen.errors)
+
+ r1 = tgen.routers()["r1"]
+
+ step("add via gateway", reset=True)
+ do_config(r1, 1, True, False, vrf=vrf, use_cli=use_cli)
+ step("remove via gateway")
+ do_config(r1, 1, False, False, vrf=vrf, use_cli=use_cli)
+
+ via = f"lo-{vrf}" if vrf else "lo"
+ step("add via loopback")
+ do_config(r1, 1, True, False, via=via, vrf=vrf, use_cli=use_cli)
+ step("remove via loopback")
+ do_config(r1, 1, False, False, via=via, vrf=vrf, use_cli=use_cli)
+
+ step("add via blackhole")
+ do_config(r1, 1, True, False, via="blackhole", vrf=vrf, use_cli=use_cli)
+ step("remove via blackhole")
+ do_config(r1, 1, False, False, via="blackhole", vrf=vrf, use_cli=use_cli)
+
+
+def test_static_cli(tgen):
+ guts(tgen, "", True)
+
+
+def test_static_file(tgen):
+ guts(tgen, "", False)
+
+
+def test_static_vrf_cli(tgen):
+ guts(tgen, "red", True)
+
+
+def test_static_vrf_file(tgen):
+ guts(tgen, "red", False)
diff --git a/tests/topotests/zebra_rib/test_zebra_rib.py b/tests/topotests/zebra_rib/test_zebra_rib.py
index 6137471ea6..e2863218b0 100644
--- a/tests/topotests/zebra_rib/test_zebra_rib.py
+++ b/tests/topotests/zebra_rib/test_zebra_rib.py
@@ -51,7 +51,8 @@ def config_macvlan(tgen, r_str, device, macvlan):
def setup_module(mod):
"Sets up the pytest environment"
- topodef = {"s1": ("r1", "r1", "r1", "r1", "r1", "r1", "r1", "r1")}
+ # 8 links to 8 switches on r1
+ topodef = {"s{}".format(x): ("r1",) for x in range(1, 9)}
tgen = Topogen(topodef, mod.__name__)
tgen.start_topology()
diff --git a/tools/etc/frr/daemons b/tools/etc/frr/daemons
index 2427bfff77..c487e7e5f2 100644
--- a/tools/etc/frr/daemons
+++ b/tools/etc/frr/daemons
@@ -40,6 +40,7 @@ pathd=no
#
vtysh_enable=yes
zebra_options=" -A 127.0.0.1 -s 90000000"
+mgmtd_options=" -A 127.0.0.1"
bgpd_options=" -A 127.0.0.1"
ospfd_options=" -A 127.0.0.1"
ospf6d_options=" -A ::1"
diff --git a/tools/frr-llvm-cg.c b/tools/frr-llvm-cg.c
index 51e8fb7b7e..3a7222e421 100644
--- a/tools/frr-llvm-cg.c
+++ b/tools/frr-llvm-cg.c
@@ -271,12 +271,12 @@ static bool is_thread_sched(const char *name, size_t len)
{
#define thread_prefix "_"
static const char *const names[] = {
- thread_prefix "thread_add_read_write",
- thread_prefix "thread_add_timer",
- thread_prefix "thread_add_timer_msec",
- thread_prefix "thread_add_timer_tv",
- thread_prefix "thread_add_event",
- thread_prefix "thread_execute",
+ thread_prefix "event_add_read_write",
+ thread_prefix "event_add_timer",
+ thread_prefix "event_add_timer_msec",
+ thread_prefix "event_add_timer_tv",
+ thread_prefix "event_add_event",
+ thread_prefix "event_execute",
};
size_t i;
diff --git a/tools/frr-reload.py b/tools/frr-reload.py
index a69b0a7bf1..490e519ae9 100755
--- a/tools/frr-reload.py
+++ b/tools/frr-reload.py
@@ -1474,10 +1474,12 @@ def ignore_delete_re_add_lines(lines_to_add, lines_to_del):
lines_to_add_to_del.append((tmp_ctx_keys, line))
for (ctx_keys, line) in lines_to_del_to_del:
- lines_to_del.remove((ctx_keys, line))
+ if line is not None:
+ lines_to_del.remove((ctx_keys, line))
for (ctx_keys, line) in lines_to_add_to_del:
- lines_to_add.remove((ctx_keys, line))
+ if line is not None:
+ lines_to_add.remove((ctx_keys, line))
return (lines_to_add, lines_to_del)
diff --git a/tools/frr.in b/tools/frr.in
index 1ffdade54f..cd24a96054 100755
--- a/tools/frr.in
+++ b/tools/frr.in
@@ -17,6 +17,7 @@ PATH=/bin:/usr/bin:/sbin:/usr/sbin
D_PATH="@CFG_SBIN@" # /usr/lib/frr
C_PATH="@CFG_SYSCONF@" # /etc/frr
V_PATH="@CFG_STATE@" # /var/run/frr
+B_PATH="@CFG_BIN@"
VTYSH="@vtysh_bin@" # /usr/bin/vtysh
FRR_USER="@enable_user@" # frr
FRR_GROUP="@enable_group@" # frr
@@ -27,7 +28,7 @@ FRR_DEFAULT_PROFILE="@DFLT_NAME@" # traditional / datacenter
# Local Daemon selection may be done by using /etc/frr/daemons.
# See /usr/share/doc/frr/README.Debian.gz for further information.
# Keep zebra first and do not list watchfrr!
-DAEMONS="zebra bgpd ripd ripngd ospfd ospf6d isisd babeld pimd pim6d ldpd nhrpd eigrpd sharpd pbrd staticd bfdd fabricd vrrpd pathd"
+DAEMONS="mgmtd zebra bgpd ripd ripngd ospfd ospf6d isisd babeld pimd pim6d ldpd nhrpd eigrpd sharpd pbrd staticd bfdd fabricd vrrpd pathd"
MAX_INSTANCES=5
RELOAD_SCRIPT="$D_PATH/frr-reload.py"
@@ -582,7 +583,7 @@ case "$1" in
NEW_CONFIG_FILE="${2:-$C_PATH/frr.conf}"
[ ! -r $NEW_CONFIG_FILE ] && echo "Unable to read new configuration file $NEW_CONFIG_FILE" && exit 1
echo "Applying only incremental changes to running configuration from frr.conf"
- "$RELOAD_SCRIPT" --reload --bindir "$D_PATH" --confdir "$C_PATH" --rundir "$V_PATH" "$C_PATH/frr.conf"
+ "$RELOAD_SCRIPT" --reload --bindir "$B_PATH" --confdir "$C_PATH" --rundir "$V_PATH" "$C_PATH/frr.conf"
exit $?
;;
diff --git a/tools/frrcommon.sh.in b/tools/frrcommon.sh.in
index f1db3a73d5..f1f7011909 100755
--- a/tools/frrcommon.sh.in
+++ b/tools/frrcommon.sh.in
@@ -24,6 +24,7 @@ PATH=/bin:/usr/bin:/sbin:/usr/sbin
D_PATH="@CFG_SBIN@" # /usr/lib/frr
C_PATH="@CFG_SYSCONF@${suffix}" # /etc/frr
V_PATH="@CFG_STATE@${suffix}" # /var/run/frr
+B_PATH="@CFG_BIN@"
VTYSH="@vtysh_bin@" # /usr/bin/vtysh
FRR_USER="@enable_user@" # frr
FRR_GROUP="@enable_group@" # frr
@@ -35,7 +36,7 @@ FRR_DEFAULT_PROFILE="@DFLT_NAME@" # traditional / datacenter
# - keep zebra first
# - watchfrr does NOT belong in this list
-DAEMONS="zebra bgpd ripd ripngd ospfd ospf6d isisd babeld pimd pim6d ldpd nhrpd eigrpd sharpd pbrd staticd bfdd fabricd vrrpd pathd"
+DAEMONS="zebra mgmtd bgpd ripd ripngd ospfd ospf6d isisd babeld pimd pim6d ldpd nhrpd eigrpd sharpd pbrd staticd bfdd fabricd vrrpd pathd"
RELOAD_SCRIPT="$D_PATH/frr-reload.py"
#
@@ -99,7 +100,7 @@ daemon_list() {
for daemon in $DAEMONS; do
eval cfg=\$$daemon
eval inst=\$${daemon}_instances
- [ "$daemon" = zebra -o "$daemon" = staticd ] && cfg=yes
+ [ "$daemon" = zebra -o "$daemon" = staticd -o "$daemon" = mgmtd ] && cfg=yes
if [ -n "$cfg" -a "$cfg" != "no" -a "$cfg" != "0" ]; then
if ! daemon_prep "$daemon" "$inst"; then
continue
diff --git a/tools/frrinit.sh.in b/tools/frrinit.sh.in
index 2396b1a326..42adefb9ea 100644
--- a/tools/frrinit.sh.in
+++ b/tools/frrinit.sh.in
@@ -122,7 +122,7 @@ reload)
NEW_CONFIG_FILE="${2:-$C_PATH/frr.conf}"
[ ! -r $NEW_CONFIG_FILE ] && log_failure_msg "Unable to read new configuration file $NEW_CONFIG_FILE" && exit 1
- "$RELOAD_SCRIPT" --reload --bindir "$D_PATH" --confdir "$C_PATH" --rundir "$V_PATH" "$NEW_CONFIG_FILE" `echo $nsopt`
+ "$RELOAD_SCRIPT" --reload --bindir "$B_PATH" --confdir "$C_PATH" --rundir "$V_PATH" "$NEW_CONFIG_FILE" `echo $nsopt`
exit $?
;;
diff --git a/vrrpd/vrrp.c b/vrrpd/vrrp.c
index 5bb1d6911c..7a779307d9 100644
--- a/vrrpd/vrrp.c
+++ b/vrrpd/vrrp.c
@@ -673,8 +673,8 @@ struct vrrp_vrouter *vrrp_lookup(const struct interface *ifp, uint8_t vrid)
/* Forward decls */
static void vrrp_change_state(struct vrrp_router *r, int to);
-static void vrrp_adver_timer_expire(struct thread *thread);
-static void vrrp_master_down_timer_expire(struct thread *thread);
+static void vrrp_adver_timer_expire(struct event *thread);
+static void vrrp_master_down_timer_expire(struct event *thread);
/*
* Finds the first connected address of the appropriate family on a VRRP
@@ -900,11 +900,11 @@ static int vrrp_recv_advertisement(struct vrrp_router *r, struct ipaddr *src,
if (pkt->hdr.priority == 0) {
vrrp_send_advertisement(r);
- THREAD_OFF(r->t_adver_timer);
- thread_add_timer_msec(
- master, vrrp_adver_timer_expire, r,
- r->vr->advertisement_interval * CS2MS,
- &r->t_adver_timer);
+ EVENT_OFF(r->t_adver_timer);
+ event_add_timer_msec(master, vrrp_adver_timer_expire, r,
+ r->vr->advertisement_interval *
+ CS2MS,
+ &r->t_adver_timer);
} else if (pkt->hdr.priority > r->priority
|| ((pkt->hdr.priority == r->priority)
&& addrcmp > 0)) {
@@ -913,17 +913,17 @@ static int vrrp_recv_advertisement(struct vrrp_router *r, struct ipaddr *src,
"Received advertisement from %s w/ priority %hhu; switching to Backup",
r->vr->vrid, family2str(r->family), sipstr,
pkt->hdr.priority);
- THREAD_OFF(r->t_adver_timer);
+ EVENT_OFF(r->t_adver_timer);
if (r->vr->version == 3) {
r->master_adver_interval =
htons(pkt->hdr.v3.adver_int);
}
vrrp_recalculate_timers(r);
- THREAD_OFF(r->t_master_down_timer);
- thread_add_timer_msec(master,
- vrrp_master_down_timer_expire, r,
- r->master_down_interval * CS2MS,
- &r->t_master_down_timer);
+ EVENT_OFF(r->t_master_down_timer);
+ event_add_timer_msec(master,
+ vrrp_master_down_timer_expire, r,
+ r->master_down_interval * CS2MS,
+ &r->t_master_down_timer);
vrrp_change_state(r, VRRP_STATE_BACKUP);
} else {
/* Discard advertisement */
@@ -936,8 +936,8 @@ static int vrrp_recv_advertisement(struct vrrp_router *r, struct ipaddr *src,
break;
case VRRP_STATE_BACKUP:
if (pkt->hdr.priority == 0) {
- THREAD_OFF(r->t_master_down_timer);
- thread_add_timer_msec(
+ EVENT_OFF(r->t_master_down_timer);
+ event_add_timer_msec(
master, vrrp_master_down_timer_expire, r,
r->skew_time * CS2MS, &r->t_master_down_timer);
} else if (!r->vr->preempt_mode
@@ -947,11 +947,11 @@ static int vrrp_recv_advertisement(struct vrrp_router *r, struct ipaddr *src,
ntohs(pkt->hdr.v3.adver_int);
}
vrrp_recalculate_timers(r);
- THREAD_OFF(r->t_master_down_timer);
- thread_add_timer_msec(master,
- vrrp_master_down_timer_expire, r,
- r->master_down_interval * CS2MS,
- &r->t_master_down_timer);
+ EVENT_OFF(r->t_master_down_timer);
+ event_add_timer_msec(master,
+ vrrp_master_down_timer_expire, r,
+ r->master_down_interval * CS2MS,
+ &r->t_master_down_timer);
} else if (r->vr->preempt_mode
&& pkt->hdr.priority < r->priority) {
/* Discard advertisement */
@@ -976,9 +976,9 @@ static int vrrp_recv_advertisement(struct vrrp_router *r, struct ipaddr *src,
/*
* Read and process next IPvX datagram.
*/
-static void vrrp_read(struct thread *thread)
+static void vrrp_read(struct event *thread)
{
- struct vrrp_router *r = THREAD_ARG(thread);
+ struct vrrp_router *r = EVENT_ARG(thread);
struct vrrp_pkt *pkt;
ssize_t pktsize;
@@ -1039,7 +1039,7 @@ done:
memset(r->ibuf, 0x00, sizeof(r->ibuf));
if (resched)
- thread_add_read(master, vrrp_read, r, r->sock_rx, &r->t_read);
+ event_add_read(master, vrrp_read, r, r->sock_rx, &r->t_read);
}
/*
@@ -1405,7 +1405,7 @@ static void vrrp_change_state_backup(struct vrrp_router *r)
vrrp_zebra_radv_set(r, false);
/* Disable Adver_Timer */
- THREAD_OFF(r->t_adver_timer);
+ EVENT_OFF(r->t_adver_timer);
r->advert_pending = false;
r->garp_pending = false;
@@ -1473,9 +1473,9 @@ static void vrrp_change_state(struct vrrp_router *r, int to)
/*
* Called when Adver_Timer expires.
*/
-static void vrrp_adver_timer_expire(struct thread *thread)
+static void vrrp_adver_timer_expire(struct event *thread)
{
- struct vrrp_router *r = THREAD_ARG(thread);
+ struct vrrp_router *r = EVENT_ARG(thread);
DEBUGD(&vrrp_dbg_proto,
VRRP_LOGPFX VRRP_LOGPFX_VRID VRRP_LOGPFX_FAM
@@ -1487,9 +1487,9 @@ static void vrrp_adver_timer_expire(struct thread *thread)
vrrp_send_advertisement(r);
/* Reset the Adver_Timer to Advertisement_Interval */
- thread_add_timer_msec(master, vrrp_adver_timer_expire, r,
- r->vr->advertisement_interval * CS2MS,
- &r->t_adver_timer);
+ event_add_timer_msec(master, vrrp_adver_timer_expire, r,
+ r->vr->advertisement_interval * CS2MS,
+ &r->t_adver_timer);
} else {
zlog_err(VRRP_LOGPFX VRRP_LOGPFX_VRID VRRP_LOGPFX_FAM
"Adver_Timer expired in state '%s'; this is a bug",
@@ -1501,17 +1501,17 @@ static void vrrp_adver_timer_expire(struct thread *thread)
/*
* Called when Master_Down_Timer expires.
*/
-static void vrrp_master_down_timer_expire(struct thread *thread)
+static void vrrp_master_down_timer_expire(struct event *thread)
{
- struct vrrp_router *r = THREAD_ARG(thread);
+ struct vrrp_router *r = EVENT_ARG(thread);
zlog_info(VRRP_LOGPFX VRRP_LOGPFX_VRID VRRP_LOGPFX_FAM
"Master_Down_Timer expired",
r->vr->vrid, family2str(r->family));
- thread_add_timer_msec(master, vrrp_adver_timer_expire, r,
- r->vr->advertisement_interval * CS2MS,
- &r->t_adver_timer);
+ event_add_timer_msec(master, vrrp_adver_timer_expire, r,
+ r->vr->advertisement_interval * CS2MS,
+ &r->t_adver_timer);
vrrp_change_state(r, VRRP_STATE_MASTER);
}
@@ -1561,7 +1561,7 @@ static int vrrp_startup(struct vrrp_router *r)
}
/* Schedule listener */
- thread_add_read(master, vrrp_read, r, r->sock_rx, &r->t_read);
+ event_add_read(master, vrrp_read, r, r->sock_rx, &r->t_read);
/* Configure effective priority */
assert(listhead(r->addrs));
@@ -1583,16 +1583,16 @@ static int vrrp_startup(struct vrrp_router *r)
}
if (r->priority == VRRP_PRIO_MASTER) {
- thread_add_timer_msec(master, vrrp_adver_timer_expire, r,
- r->vr->advertisement_interval * CS2MS,
- &r->t_adver_timer);
+ event_add_timer_msec(master, vrrp_adver_timer_expire, r,
+ r->vr->advertisement_interval * CS2MS,
+ &r->t_adver_timer);
vrrp_change_state(r, VRRP_STATE_MASTER);
} else {
r->master_adver_interval = r->vr->advertisement_interval;
vrrp_recalculate_timers(r);
- thread_add_timer_msec(master, vrrp_master_down_timer_expire, r,
- r->master_down_interval * CS2MS,
- &r->t_master_down_timer);
+ event_add_timer_msec(master, vrrp_master_down_timer_expire, r,
+ r->master_down_interval * CS2MS,
+ &r->t_master_down_timer);
vrrp_change_state(r, VRRP_STATE_BACKUP);
}
@@ -1632,10 +1632,10 @@ static int vrrp_shutdown(struct vrrp_router *r)
}
/* Cancel all timers */
- THREAD_OFF(r->t_adver_timer);
- THREAD_OFF(r->t_master_down_timer);
- THREAD_OFF(r->t_read);
- THREAD_OFF(r->t_write);
+ EVENT_OFF(r->t_adver_timer);
+ EVENT_OFF(r->t_master_down_timer);
+ EVENT_OFF(r->t_read);
+ EVENT_OFF(r->t_write);
/* Protodown macvlan */
if (r->mvl_ifp)
@@ -2411,6 +2411,5 @@ void vrrp_fini(void)
list_delete(&vrs);
- hash_clean(vrrp_vrouters_hash, NULL);
- hash_free(vrrp_vrouters_hash);
+ hash_clean_and_free(&vrrp_vrouters_hash, NULL);
}
diff --git a/vrrpd/vrrp.h b/vrrpd/vrrp.h
index 9da9c8a518..0ac9b1f49c 100644
--- a/vrrpd/vrrp.h
+++ b/vrrpd/vrrp.h
@@ -18,7 +18,7 @@
#include "lib/northbound.h"
#include "lib/privs.h"
#include "lib/stream.h"
-#include "lib/thread.h"
+#include "lib/frrevent.h"
#include "lib/vty.h"
/* Global definitions */
@@ -65,7 +65,7 @@ struct vrrp_defaults {
extern struct vrrp_defaults vd;
/* threadmaster */
-extern struct thread_master *master;
+extern struct event_loop *master;
/* privileges */
extern struct zebra_privs_t vrrp_privs;
@@ -193,10 +193,10 @@ struct vrrp_router {
uint32_t trans_cnt;
} stats;
- struct thread *t_master_down_timer;
- struct thread *t_adver_timer;
- struct thread *t_read;
- struct thread *t_write;
+ struct event *t_master_down_timer;
+ struct event *t_adver_timer;
+ struct event *t_read;
+ struct event *t_write;
};
/*
diff --git a/vrrpd/vrrp_main.c b/vrrpd/vrrp_main.c
index d3d230d205..5245c74689 100644
--- a/vrrpd/vrrp_main.c
+++ b/vrrpd/vrrp_main.c
@@ -6,11 +6,12 @@
*/
#include <zebra.h>
+#include <getopt.h>
+
#include <lib/version.h>
#include "lib/command.h"
#include "lib/filter.h"
-#include "lib/getopt.h"
#include "lib/if.h"
#include "lib/libfrr.h"
#include "lib/log.h"
@@ -18,7 +19,7 @@
#include "lib/nexthop.h"
#include "lib/privs.h"
#include "lib/sigevent.h"
-#include "lib/thread.h"
+#include "lib/frrevent.h"
#include "lib/vrf.h"
#include "lib/vty.h"
@@ -50,7 +51,7 @@ struct zebra_privs_t vrrp_privs = {
struct option longopts[] = { {0} };
/* Master of threads. */
-struct thread_master *master;
+struct event_loop *master;
static struct frr_daemon_info vrrpd_di;
diff --git a/vtysh/vtysh.c b/vtysh/vtysh.c
index 200427fb6e..4d52bd036d 100644
--- a/vtysh/vtysh.c
+++ b/vtysh/vtysh.c
@@ -49,19 +49,6 @@ char *vtysh_pager_name = NULL;
/* VTY should add timestamp */
bool vtysh_add_timestamp;
-/* VTY shell client structure */
-struct vtysh_client {
- int fd;
- const char *name;
- int flag;
- char path[MAXPATHLEN];
- struct vtysh_client *next;
-
- struct thread *log_reader;
- int log_fd;
- uint32_t lost_msgs;
-};
-
static bool stderr_tty;
static bool stderr_stdout_same;
@@ -119,7 +106,12 @@ static void vtysh_pager_envdef(bool fallback)
/* --- */
+/*
+ * When updating this array, remember to change the array size here and in
+ * vtysh.h
+ */
struct vtysh_client vtysh_client[] = {
+ {.name = "mgmtd", .flag = VTYSH_MGMTD},
{.name = "zebra", .flag = VTYSH_ZEBRA},
{.name = "ripd", .flag = VTYSH_RIPD},
{.name = "ripngd", .flag = VTYSH_RIPNGD},
@@ -3544,7 +3536,7 @@ DEFUN (vtysh_copy_to_running,
int ret;
const char *fname = argv[1]->arg;
- ret = vtysh_read_config(fname, true);
+ ret = vtysh_apply_config(fname, true, false);
/* Return to enable mode - the 'read_config' api leaves us up a level */
vtysh_execute_no_pager("enable");
@@ -3727,9 +3719,9 @@ static void vtysh_log_print(struct vtysh_client *vclient,
text + textpos);
}
-static void vtysh_log_read(struct thread *thread)
+static void vtysh_log_read(struct event *thread)
{
- struct vtysh_client *vclient = THREAD_ARG(thread);
+ struct vtysh_client *vclient = EVENT_ARG(thread);
struct {
struct zlog_live_hdr hdr;
char text[4096];
@@ -3737,8 +3729,8 @@ static void vtysh_log_read(struct thread *thread)
const char *text;
ssize_t ret;
- thread_add_read(master, vtysh_log_read, vclient, vclient->log_fd,
- &vclient->log_reader);
+ event_add_read(master, vtysh_log_read, vclient, vclient->log_fd,
+ &vclient->log_reader);
ret = recv(vclient->log_fd, &buf, sizeof(buf), 0);
@@ -3768,7 +3760,7 @@ static void vtysh_log_read(struct thread *thread)
"log monitor connection closed unexpectedly");
buf.hdr.textlen = strlen(buf.text);
- THREAD_OFF(vclient->log_reader);
+ EVENT_OFF(vclient->log_reader);
close(vclient->log_fd);
vclient->log_fd = -1;
@@ -3834,9 +3826,9 @@ DEFPY (vtysh_terminal_monitor,
if (fd != -1) {
set_nonblocking(fd);
vclient->log_fd = fd;
- thread_add_read(master, vtysh_log_read, vclient,
- vclient->log_fd,
- &vclient->log_reader);
+ event_add_read(master, vtysh_log_read, vclient,
+ vclient->log_fd,
+ &vclient->log_reader);
}
if (ret != CMD_SUCCESS) {
vty_out(vty, "%% failed to enable logs on %s\n",
@@ -3890,7 +3882,7 @@ DEFPY (no_vtysh_terminal_monitor,
* a close notification...
*/
if (vclient->log_fd != -1) {
- THREAD_OFF(vclient->log_reader);
+ EVENT_OFF(vclient->log_reader);
close(vclient->log_fd);
vclient->log_fd = -1;
diff --git a/vtysh/vtysh.h b/vtysh/vtysh.h
index 538837391b..1c2cca9d90 100644
--- a/vtysh/vtysh.h
+++ b/vtysh/vtysh.h
@@ -9,9 +9,9 @@
#include "memory.h"
DECLARE_MGROUP(MVTYSH);
-struct thread_master;
+struct event_loop;
-extern struct thread_master *master;
+extern struct event_loop *master;
#define VTYSH_ZEBRA 0x00001
#define VTYSH_RIPD 0x00002
@@ -34,6 +34,7 @@ extern struct thread_master *master;
#define VTYSH_VRRPD 0x40000
#define VTYSH_PATHD 0x80000
#define VTYSH_PIM6D 0x100000
+#define VTYSH_MGMTD 0x200000
#define VTYSH_WAS_ACTIVE (-2)
@@ -42,7 +43,12 @@ extern struct thread_master *master;
/* watchfrr is not in ALL since library CLI functions should not be
* run on it (logging & co. should stay in a fixed/frozen config, and
* things like prefix lists are not even initialised) */
-#define VTYSH_ALL VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_RIPNGD|VTYSH_OSPFD|VTYSH_OSPF6D|VTYSH_LDPD|VTYSH_BGPD|VTYSH_ISISD|VTYSH_PIMD|VTYSH_PIM6D|VTYSH_NHRPD|VTYSH_EIGRPD|VTYSH_BABELD|VTYSH_SHARPD|VTYSH_PBRD|VTYSH_STATICD|VTYSH_BFDD|VTYSH_FABRICD|VTYSH_VRRPD|VTYSH_PATHD
+#define VTYSH_ALL \
+ VTYSH_ZEBRA | VTYSH_RIPD | VTYSH_RIPNGD | VTYSH_OSPFD | VTYSH_OSPF6D | \
+ VTYSH_LDPD | VTYSH_BGPD | VTYSH_ISISD | VTYSH_PIMD | \
+ VTYSH_PIM6D | VTYSH_NHRPD | VTYSH_EIGRPD | VTYSH_BABELD | \
+ VTYSH_SHARPD | VTYSH_PBRD | VTYSH_STATICD | VTYSH_BFDD | \
+ VTYSH_FABRICD | VTYSH_VRRPD | VTYSH_PATHD | VTYSH_MGMTD
#define VTYSH_ACL VTYSH_BFDD|VTYSH_BABELD|VTYSH_BGPD|VTYSH_EIGRPD|VTYSH_ISISD|VTYSH_FABRICD|VTYSH_LDPD|VTYSH_NHRPD|VTYSH_OSPF6D|VTYSH_OSPFD|VTYSH_PBRD|VTYSH_PIMD|VTYSH_PIM6D|VTYSH_RIPD|VTYSH_RIPNGD|VTYSH_VRRPD|VTYSH_ZEBRA
#define VTYSH_AFFMAP VTYSH_ZEBRA | VTYSH_ISISD
#define VTYSH_RMAP VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_RIPNGD|VTYSH_OSPFD|VTYSH_OSPF6D|VTYSH_BGPD|VTYSH_ISISD|VTYSH_PIMD|VTYSH_EIGRPD|VTYSH_FABRICD
@@ -52,7 +58,7 @@ extern struct thread_master *master;
VTYSH_EIGRPD | VTYSH_BABELD | VTYSH_PBRD | VTYSH_FABRICD | \
VTYSH_VRRPD
#define VTYSH_INTERFACE VTYSH_INTERFACE_SUBSET | VTYSH_BGPD
-#define VTYSH_VRF VTYSH_INTERFACE_SUBSET | VTYSH_STATICD
+#define VTYSH_VRF VTYSH_INTERFACE_SUBSET | VTYSH_STATICD | VTYSH_MGMTD
#define VTYSH_KEYS VTYSH_RIPD | VTYSH_EIGRPD | VTYSH_OSPF6D
/* Daemons who can process nexthop-group configs */
#define VTYSH_NH_GROUP VTYSH_PBRD|VTYSH_SHARPD
@@ -92,7 +98,7 @@ void config_add_line(struct list *, const char *);
int vtysh_mark_file(const char *filename);
-int vtysh_read_config(const char *filename, bool dry_run);
+int vtysh_apply_config(const char *config_file_path, bool dry_run, bool fork);
int vtysh_write_config_integrated(void);
void vtysh_config_parse_line(void *, const char *);
@@ -113,4 +119,18 @@ extern int user_mode;
extern bool vtysh_add_timestamp;
+struct vtysh_client {
+ int fd;
+ const char *name;
+ int flag;
+ char path[MAXPATHLEN];
+ struct vtysh_client *next;
+
+ struct event *log_reader;
+ int log_fd;
+ uint32_t lost_msgs;
+};
+
+extern struct vtysh_client vtysh_client[22];
+
#endif /* VTYSH_H */
diff --git a/vtysh/vtysh_config.c b/vtysh/vtysh_config.c
index 905761a011..2949faa427 100644
--- a/vtysh/vtysh_config.c
+++ b/vtysh/vtysh_config.c
@@ -4,6 +4,7 @@
*/
#include <zebra.h>
+#include <sys/wait.h>
#include "command.h"
#include "linklist.h"
@@ -625,18 +626,20 @@ static int vtysh_read_file(FILE *confp, bool dry_run)
return (ret);
}
-/* Read up configuration file from config_default_dir. */
-int vtysh_read_config(const char *config_default_dir, bool dry_run)
+/*
+ * Read configuration file and send it to all connected daemons
+ */
+static int vtysh_read_config(const char *config_file_path, bool dry_run)
{
FILE *confp = NULL;
bool save;
int ret;
- confp = fopen(config_default_dir, "r");
+ confp = fopen(config_file_path, "r");
if (confp == NULL) {
fprintf(stderr,
"%% Can't open configuration file %s due to '%s'.\n",
- config_default_dir, safe_strerror(errno));
+ config_file_path, safe_strerror(errno));
return CMD_ERR_NO_FILE;
}
@@ -648,7 +651,103 @@ int vtysh_read_config(const char *config_default_dir, bool dry_run)
vtysh_add_timestamp = save;
- return (ret);
+ return ret;
+}
+
+int vtysh_apply_config(const char *config_file_path, bool dry_run, bool do_fork)
+{
+ /*
+ * We need to apply the whole config file to all daemons. Instead of
+ * having one client talk to N daemons, we fork N times and let each
+ * child handle one daemon.
+ */
+ pid_t fork_pid = getpid();
+ int status = 0;
+ int ret;
+ int my_client_type;
+ char my_client[64];
+
+ if (do_fork) {
+ for (unsigned int i = 0; i < array_size(vtysh_client); i++) {
+ /* Store name of client this fork will handle */
+ strlcpy(my_client, vtysh_client[i].name,
+ sizeof(my_client));
+ my_client_type = vtysh_client[i].flag;
+ fork_pid = fork();
+
+ /* If child, break */
+ if (fork_pid == 0)
+ break;
+ }
+
+ /* parent, wait for children */
+ if (fork_pid != 0) {
+ int keep_status = 0;
+
+ fprintf(stdout,
+ "Waiting for children to finish applying config...\n");
+ while (wait(&status) > 0) {
+ if (!keep_status && WEXITSTATUS(status))
+ keep_status = WEXITSTATUS(status);
+ }
+
+ /*
+ * This will return the first status received
+ * that failed( if that happens ). This is
+ * good enough for the moment
+ */
+ return keep_status;
+ }
+
+ /*
+ * children, grow up to be cowboys
+ */
+ for (unsigned int i = 0; i < array_size(vtysh_client); i++) {
+ if (my_client_type != vtysh_client[i].flag) {
+ struct vtysh_client *cl;
+
+ /*
+ * If this is a client we aren't responsible
+ * for, disconnect
+ */
+ for (cl = &vtysh_client[i]; cl; cl = cl->next) {
+ if (cl->fd >= 0)
+ close(cl->fd);
+ cl->fd = -1;
+ }
+ } else if (vtysh_client[i].fd == -1 &&
+ vtysh_client[i].next == NULL) {
+ /*
+ * If this is the client we are responsible
+ * for, but we aren't already connected to that
+ * client, that means the client isn't up in
+ * the first place and we can exit early
+ */
+ exit(0);
+ }
+ }
+
+ fprintf(stdout, "[%d|%s] sending configuration\n", getpid(),
+ my_client);
+ }
+
+ ret = vtysh_read_config(config_file_path, dry_run);
+
+ if (ret) {
+ if (do_fork)
+ fprintf(stderr,
+ "[%d|%s] Configuration file[%s] processing failure: %d\n",
+ getpid(), my_client, frr_config, ret);
+ else
+ fprintf(stderr,
+ "Configuration file[%s] processing failure: %d\n",
+ frr_config, ret);
+ } else if (do_fork) {
+ fprintf(stderr, "[%d|%s] done\n", getpid(), my_client);
+ exit(0);
+ }
+
+ return ret;
}
/* We don't write vtysh specific into file from vtysh. vtysh.conf should
diff --git a/vtysh/vtysh_main.c b/vtysh/vtysh_main.c
index 25b667252e..860d79d5f9 100644
--- a/vtysh/vtysh_main.c
+++ b/vtysh/vtysh_main.c
@@ -7,7 +7,6 @@
#include <sys/un.h>
#include <setjmp.h>
-#include <sys/wait.h>
#include <pwd.h>
#include <sys/file.h>
#include <unistd.h>
@@ -64,7 +63,7 @@ int execute_flag = 0;
int user_mode;
/* Master of threads. */
-struct thread_master *master;
+struct event_loop *master;
/* Command logging */
FILE *logfile;
@@ -178,6 +177,8 @@ static void usage(int status)
"-u --user Run as an unprivileged user\n"
"-w, --writeconfig Write integrated config (frr.conf) and exit\n"
"-H, --histfile Override history file\n"
+ "-t, --timestamp Print a timestamp before going to shell or reading the configuration\n"
+ " --no-fork Don't fork clients to handle daemons (slower for large configs)\n"
"-h, --help Display this help and exit\n\n"
"Note that multiple commands may be executed from the command\n"
"line by passing multiple -c args, or by embedding linefeed\n"
@@ -191,6 +192,7 @@ static void usage(int status)
/* VTY shell options, we use GNU getopt library. */
#define OPTION_VTYSOCK 1000
#define OPTION_CONFDIR 1001
+#define OPTION_NOFORK 1002
struct option longopts[] = {
{"boot", no_argument, NULL, 'b'},
/* For compatibility with older zebra/quagga versions */
@@ -210,37 +212,38 @@ struct option longopts[] = {
{"pathspace", required_argument, NULL, 'N'},
{"user", no_argument, NULL, 'u'},
{"timestamp", no_argument, NULL, 't'},
+ {"no-fork", no_argument, NULL, OPTION_NOFORK},
{0}};
bool vtysh_loop_exited;
-static struct thread *vtysh_rl_read_thread;
+static struct event *vtysh_rl_read_thread;
-static void vtysh_rl_read(struct thread *thread)
+static void vtysh_rl_read(struct event *thread)
{
- thread_add_read(master, vtysh_rl_read, NULL, STDIN_FILENO,
- &vtysh_rl_read_thread);
+ event_add_read(master, vtysh_rl_read, NULL, STDIN_FILENO,
+ &vtysh_rl_read_thread);
rl_callback_read_char();
}
/* Read a string, and return a pointer to it. Returns NULL on EOF. */
static void vtysh_rl_run(void)
{
- struct thread thread;
+ struct event thread;
- master = thread_master_create(NULL);
+ master = event_master_create(NULL);
rl_callback_handler_install(vtysh_prompt(), vtysh_rl_callback);
- thread_add_read(master, vtysh_rl_read, NULL, STDIN_FILENO,
- &vtysh_rl_read_thread);
+ event_add_read(master, vtysh_rl_read, NULL, STDIN_FILENO,
+ &vtysh_rl_read_thread);
- while (!vtysh_loop_exited && thread_fetch(master, &thread))
- thread_call(&thread);
+ while (!vtysh_loop_exited && event_fetch(master, &thread))
+ event_call(&thread);
if (!vtysh_loop_exited)
rl_callback_handler_remove();
- thread_master_free(master);
+ event_master_free(master);
}
static void log_it(const char *line)
@@ -321,6 +324,7 @@ int main(int argc, char **argv, char **env)
int dryrun = 0;
int boot_flag = 0;
bool ts_flag = false;
+ bool no_fork = false;
const char *daemon_name = NULL;
const char *inputfile = NULL;
struct cmd_rec {
@@ -392,6 +396,9 @@ int main(int argc, char **argv, char **env)
ditch_suid = 1; /* option disables SUID */
snprintf(sysconfdir, sizeof(sysconfdir), "%s/", optarg);
break;
+ case OPTION_NOFORK:
+ no_fork = true;
+ break;
case 'N':
if (strchr(optarg, '/') || strchr(optarg, '.')) {
fprintf(stderr,
@@ -440,6 +447,10 @@ int main(int argc, char **argv, char **env)
}
}
+ /* No need for forks if we're talking to 1 daemon */
+ if (daemon_name)
+ no_fork = true;
+
if (ditch_suid) {
elevuid = realuid;
elevgid = realgid;
@@ -483,7 +494,7 @@ int main(int argc, char **argv, char **env)
/* Read vtysh configuration file before connecting to daemons.
* (file may not be readable to calling user in SUID mode) */
suid_on();
- vtysh_read_config(vtysh_config, dryrun);
+ vtysh_apply_config(vtysh_config, dryrun, false);
suid_off();
}
/* Error code library system */
@@ -502,9 +513,9 @@ int main(int argc, char **argv, char **env)
/* Start execution only if not in dry-run mode */
if (dryrun && !cmd) {
if (inputfile) {
- ret = vtysh_read_config(inputfile, dryrun);
+ ret = vtysh_apply_config(inputfile, dryrun, false);
} else {
- ret = vtysh_read_config(frr_config, dryrun);
+ ret = vtysh_apply_config(frr_config, dryrun, false);
}
exit(ret);
@@ -583,10 +594,17 @@ int main(int argc, char **argv, char **env)
return vtysh_write_config_integrated();
}
- if (inputfile) {
+ if (boot_flag)
+ inputfile = frr_config;
+
+ if (inputfile || boot_flag) {
vtysh_flock_config(inputfile);
- ret = vtysh_read_config(inputfile, dryrun);
+ ret = vtysh_apply_config(inputfile, dryrun, !no_fork);
vtysh_unflock_config();
+
+ if (no_error)
+ ret = 0;
+
exit(ret);
}
@@ -703,23 +721,6 @@ int main(int argc, char **argv, char **env)
exit(0);
}
- /* Boot startup configuration file. */
- if (boot_flag) {
- vtysh_flock_config(frr_config);
- ret = vtysh_read_config(frr_config, dryrun);
- vtysh_unflock_config();
- if (ret) {
- fprintf(stderr,
- "Configuration file[%s] processing failure: %d\n",
- frr_config, ret);
- if (no_error)
- exit(0);
- else
- exit(ret);
- } else
- exit(0);
- }
-
vtysh_readline_init();
vty_hello(vty);
diff --git a/watchfrr/watchfrr.c b/watchfrr/watchfrr.c
index 84f4d02a8a..89199da1af 100644
--- a/watchfrr/watchfrr.c
+++ b/watchfrr/watchfrr.c
@@ -6,7 +6,7 @@
*/
#include <zebra.h>
-#include <thread.h>
+#include "frrevent.h"
#include <log.h>
#include <network.h>
#include <sigevent.h>
@@ -53,7 +53,7 @@ DEFINE_MGROUP(WATCHFRR, "watchfrr");
DEFINE_MTYPE_STATIC(WATCHFRR, WATCHFRR_DAEMON, "watchfrr daemon entry");
/* Needs to be global, referenced somewhere inside libfrr. */
-struct thread_master *master;
+struct event_loop *master;
static bool watch_only = false;
const char *pathspace;
@@ -86,15 +86,15 @@ struct restart_info {
pid_t pid;
struct timeval time;
long interval;
- struct thread *t_kill;
+ struct event *t_kill;
int kills;
};
static struct global_state {
enum restart_phase phase;
- struct thread *t_phase_hanging;
- struct thread *t_startup_timeout;
- struct thread *t_operational;
+ struct event *t_phase_hanging;
+ struct event *t_startup_timeout;
+ struct event *t_operational;
const char *vtydir;
long period;
long timeout;
@@ -149,9 +149,9 @@ struct daemon {
int fd;
struct timeval echo_sent;
unsigned int connect_tries;
- struct thread *t_wakeup;
- struct thread *t_read;
- struct thread *t_write;
+ struct event *t_wakeup;
+ struct event *t_read;
+ struct event *t_write;
struct daemon *next;
struct restart_info restart;
@@ -195,7 +195,7 @@ static const struct option longopts[] = {
{NULL, 0, NULL, 0}};
static int try_connect(struct daemon *dmn);
-static void wakeup_send_echo(struct thread *t_wakeup);
+static void wakeup_send_echo(struct event *t_wakeup);
static void try_restart(struct daemon *dmn);
static void phase_check(void);
static void restart_done(struct daemon *dmn);
@@ -347,9 +347,9 @@ static struct timeval *time_elapsed(struct timeval *result,
return result;
}
-static void restart_kill(struct thread *t_kill)
+static void restart_kill(struct event *t_kill)
{
- struct restart_info *restart = THREAD_ARG(t_kill);
+ struct restart_info *restart = EVENT_ARG(t_kill);
struct timeval delay;
time_elapsed(&delay, &restart->time);
@@ -358,8 +358,8 @@ static void restart_kill(struct thread *t_kill)
zlog_err(
"%s %s child process appears to still be reading configuration, delaying for another %lu time",
restart->what, restart->name, gs.restart_timeout);
- thread_add_timer(master, restart_kill, restart,
- gs.restart_timeout, &restart->t_kill);
+ event_add_timer(master, restart_kill, restart,
+ gs.restart_timeout, &restart->t_kill);
return;
}
@@ -369,8 +369,8 @@ static void restart_kill(struct thread *t_kill)
(long)delay.tv_sec, (restart->kills ? SIGKILL : SIGTERM));
kill(-restart->pid, (restart->kills ? SIGKILL : SIGTERM));
restart->kills++;
- thread_add_timer(master, restart_kill, restart, gs.restart_timeout,
- &restart->t_kill);
+ event_add_timer(master, restart_kill, restart, gs.restart_timeout,
+ &restart->t_kill);
}
static struct restart_info *find_child(pid_t child)
@@ -415,7 +415,7 @@ static void sigchild(void)
what = restart->what;
restart->pid = 0;
gs.numpids--;
- thread_cancel(&restart->t_kill);
+ event_cancel(&restart->t_kill);
/* Update restart time to reflect the time the command
* completed. */
@@ -505,8 +505,8 @@ static int run_job(struct restart_info *restart, const char *cmdtype,
snprintf(cmd, sizeof(cmd), command, restart->name);
#pragma GCC diagnostic pop
if ((restart->pid = run_background(cmd)) > 0) {
- thread_add_timer(master, restart_kill, restart,
- gs.restart_timeout, &restart->t_kill);
+ event_add_timer(master, restart_kill, restart,
+ gs.restart_timeout, &restart->t_kill);
restart->what = cmdtype;
gs.numpids++;
} else
@@ -529,34 +529,34 @@ static int run_job(struct restart_info *restart, const char *cmdtype,
#define SET_READ_HANDLER(DMN) \
do { \
(DMN)->t_read = NULL; \
- thread_add_read(master, handle_read, (DMN), (DMN)->fd, \
- &(DMN)->t_read); \
+ event_add_read(master, handle_read, (DMN), (DMN)->fd, \
+ &(DMN)->t_read); \
} while (0);
#define SET_WAKEUP_DOWN(DMN) \
do { \
(DMN)->t_wakeup = NULL; \
- thread_add_timer_msec(master, wakeup_down, (DMN), \
- FUZZY(gs.period), &(DMN)->t_wakeup); \
+ event_add_timer_msec(master, wakeup_down, (DMN), \
+ FUZZY(gs.period), &(DMN)->t_wakeup); \
} while (0);
#define SET_WAKEUP_UNRESPONSIVE(DMN) \
do { \
(DMN)->t_wakeup = NULL; \
- thread_add_timer_msec(master, wakeup_unresponsive, (DMN), \
- FUZZY(gs.period), &(DMN)->t_wakeup); \
+ event_add_timer_msec(master, wakeup_unresponsive, (DMN), \
+ FUZZY(gs.period), &(DMN)->t_wakeup); \
} while (0);
#define SET_WAKEUP_ECHO(DMN) \
do { \
(DMN)->t_wakeup = NULL; \
- thread_add_timer_msec(master, wakeup_send_echo, (DMN), \
- FUZZY(gs.period), &(DMN)->t_wakeup); \
+ event_add_timer_msec(master, wakeup_send_echo, (DMN), \
+ FUZZY(gs.period), &(DMN)->t_wakeup); \
} while (0);
-static void wakeup_down(struct thread *t_wakeup)
+static void wakeup_down(struct event *t_wakeup)
{
- struct daemon *dmn = THREAD_ARG(t_wakeup);
+ struct daemon *dmn = EVENT_ARG(t_wakeup);
dmn->t_wakeup = NULL;
if (try_connect(dmn) < 0)
@@ -565,9 +565,9 @@ static void wakeup_down(struct thread *t_wakeup)
try_restart(dmn);
}
-static void wakeup_init(struct thread *t_wakeup)
+static void wakeup_init(struct event *t_wakeup)
{
- struct daemon *dmn = THREAD_ARG(t_wakeup);
+ struct daemon *dmn = EVENT_ARG(t_wakeup);
dmn->t_wakeup = NULL;
if (try_connect(dmn) < 0) {
@@ -587,13 +587,13 @@ static void restart_done(struct daemon *dmn)
dmn->name, state_str[dmn->state]);
return;
}
- THREAD_OFF(dmn->t_wakeup);
+ EVENT_OFF(dmn->t_wakeup);
if (try_connect(dmn) < 0)
SET_WAKEUP_DOWN(dmn);
}
-static void daemon_restarting_operational(struct thread *thread)
+static void daemon_restarting_operational(struct event *thread)
{
systemd_send_status("FRR Operational");
}
@@ -612,9 +612,9 @@ static void daemon_down(struct daemon *dmn, const char *why)
close(dmn->fd);
dmn->fd = -1;
}
- THREAD_OFF(dmn->t_read);
- THREAD_OFF(dmn->t_write);
- THREAD_OFF(dmn->t_wakeup);
+ EVENT_OFF(dmn->t_read);
+ EVENT_OFF(dmn->t_write);
+ EVENT_OFF(dmn->t_wakeup);
if (try_connect(dmn) < 0)
SET_WAKEUP_DOWN(dmn);
@@ -622,9 +622,9 @@ static void daemon_down(struct daemon *dmn, const char *why)
phase_check();
}
-static void handle_read(struct thread *t_read)
+static void handle_read(struct event *t_read)
{
- struct daemon *dmn = THREAD_ARG(t_read);
+ struct daemon *dmn = EVENT_ARG(t_read);
static const char resp[sizeof(PING_TOKEN) + 4] = PING_TOKEN "\n";
char buf[sizeof(resp) + 100];
ssize_t rc;
@@ -688,7 +688,7 @@ static void handle_read(struct thread *t_read)
dmn->name, (long)delay.tv_sec, (long)delay.tv_usec);
SET_READ_HANDLER(dmn);
- thread_cancel(&dmn->t_wakeup);
+ event_cancel(&dmn->t_wakeup);
SET_WAKEUP_ECHO(dmn);
}
@@ -740,19 +740,19 @@ static void daemon_up(struct daemon *dmn, const char *why)
if (gs.numdown == 0) {
daemon_send_ready(0);
- THREAD_OFF(gs.t_operational);
+ EVENT_OFF(gs.t_operational);
- thread_add_timer(master, daemon_restarting_operational, NULL,
- gs.operational_timeout, &gs.t_operational);
+ event_add_timer(master, daemon_restarting_operational, NULL,
+ gs.operational_timeout, &gs.t_operational);
}
SET_WAKEUP_ECHO(dmn);
phase_check();
}
-static void check_connect(struct thread *t_write)
+static void check_connect(struct event *t_write)
{
- struct daemon *dmn = THREAD_ARG(t_write);
+ struct daemon *dmn = EVENT_ARG(t_write);
int sockerr;
socklen_t reslen = sizeof(sockerr);
@@ -778,9 +778,9 @@ static void check_connect(struct thread *t_write)
daemon_up(dmn, "delayed connect succeeded");
}
-static void wakeup_connect_hanging(struct thread *t_wakeup)
+static void wakeup_connect_hanging(struct event *t_wakeup)
{
- struct daemon *dmn = THREAD_ARG(t_wakeup);
+ struct daemon *dmn = EVENT_ARG(t_wakeup);
char why[100];
dmn->t_wakeup = NULL;
@@ -848,10 +848,10 @@ static int try_connect(struct daemon *dmn)
zlog_debug("%s: connection in progress", dmn->name);
dmn->state = DAEMON_CONNECTING;
dmn->fd = sock;
- thread_add_write(master, check_connect, dmn, dmn->fd,
- &dmn->t_write);
- thread_add_timer(master, wakeup_connect_hanging, dmn,
- gs.timeout, &dmn->t_wakeup);
+ event_add_write(master, check_connect, dmn, dmn->fd,
+ &dmn->t_write);
+ event_add_timer(master, wakeup_connect_hanging, dmn, gs.timeout,
+ &dmn->t_wakeup);
SET_READ_HANDLER(dmn);
return 0;
}
@@ -862,7 +862,7 @@ static int try_connect(struct daemon *dmn)
return 1;
}
-static void phase_hanging(struct thread *t_hanging)
+static void phase_hanging(struct event *t_hanging)
{
gs.t_phase_hanging = NULL;
flog_err(EC_WATCHFRR_CONNECTION,
@@ -874,10 +874,10 @@ static void phase_hanging(struct thread *t_hanging)
static void set_phase(enum restart_phase new_phase)
{
gs.phase = new_phase;
- thread_cancel(&gs.t_phase_hanging);
+ event_cancel(&gs.t_phase_hanging);
- thread_add_timer(master, phase_hanging, NULL, PHASE_TIMEOUT,
- &gs.t_phase_hanging);
+ event_add_timer(master, phase_hanging, NULL, PHASE_TIMEOUT,
+ &gs.t_phase_hanging);
}
static void phase_check(void)
@@ -938,7 +938,7 @@ static void phase_check(void)
gs.start_command, 1, 0);
}
gs.phase = PHASE_NONE;
- THREAD_OFF(gs.t_phase_hanging);
+ EVENT_OFF(gs.t_phase_hanging);
zlog_notice("Phased global restart has completed.");
break;
}
@@ -985,9 +985,9 @@ static void try_restart(struct daemon *dmn)
run_job(&gs.restart, "restart", gs.restart_command, 0, 1);
}
-static void wakeup_unresponsive(struct thread *t_wakeup)
+static void wakeup_unresponsive(struct event *t_wakeup)
{
- struct daemon *dmn = THREAD_ARG(t_wakeup);
+ struct daemon *dmn = EVENT_ARG(t_wakeup);
dmn->t_wakeup = NULL;
if (dmn->state != DAEMON_UNRESPONSIVE)
@@ -1000,9 +1000,9 @@ static void wakeup_unresponsive(struct thread *t_wakeup)
}
}
-static void wakeup_no_answer(struct thread *t_wakeup)
+static void wakeup_no_answer(struct event *t_wakeup)
{
- struct daemon *dmn = THREAD_ARG(t_wakeup);
+ struct daemon *dmn = EVENT_ARG(t_wakeup);
dmn->t_wakeup = NULL;
dmn->state = DAEMON_UNRESPONSIVE;
@@ -1015,11 +1015,11 @@ static void wakeup_no_answer(struct thread *t_wakeup)
try_restart(dmn);
}
-static void wakeup_send_echo(struct thread *t_wakeup)
+static void wakeup_send_echo(struct event *t_wakeup)
{
static const char echocmd[] = "echo " PING_TOKEN;
ssize_t rc;
- struct daemon *dmn = THREAD_ARG(t_wakeup);
+ struct daemon *dmn = EVENT_ARG(t_wakeup);
dmn->t_wakeup = NULL;
if (((rc = write(dmn->fd, echocmd, sizeof(echocmd))) < 0)
@@ -1031,8 +1031,8 @@ static void wakeup_send_echo(struct thread *t_wakeup)
daemon_down(dmn, why);
} else {
gettimeofday(&dmn->echo_sent, NULL);
- thread_add_timer(master, wakeup_no_answer, dmn, gs.timeout,
- &dmn->t_wakeup);
+ event_add_timer(master, wakeup_no_answer, dmn, gs.timeout,
+ &dmn->t_wakeup);
}
}
@@ -1118,7 +1118,7 @@ static char *translate_blanks(const char *cmd, const char *blankstr)
return res;
}
-static void startup_timeout(struct thread *t_wakeup)
+static void startup_timeout(struct event *t_wakeup)
{
daemon_send_ready(1);
}
@@ -1282,8 +1282,8 @@ static void watchfrr_init(int argc, char **argv)
struct daemon *dmn, **add = &gs.daemons;
char alldaemons[512] = "", *p = alldaemons;
- thread_add_timer_msec(master, startup_timeout, NULL, STARTUP_TIMEOUT,
- &gs.t_startup_timeout);
+ event_add_timer_msec(master, startup_timeout, NULL, STARTUP_TIMEOUT,
+ &gs.t_startup_timeout);
for (i = optind; i < argc; i++) {
dmn = XCALLOC(MTYPE_WATCHFRR_DAEMON, sizeof(*dmn));
@@ -1293,8 +1293,8 @@ static void watchfrr_init(int argc, char **argv)
gs.numdaemons++;
gs.numdown++;
dmn->fd = -1;
- thread_add_timer_msec(master, wakeup_init, dmn, 0,
- &dmn->t_wakeup);
+ event_add_timer_msec(master, wakeup_init, dmn, 0,
+ &dmn->t_wakeup);
dmn->restart.interval = gs.min_restart_interval;
*add = dmn;
add = &dmn->next;
diff --git a/yang/frr-bgp-route-map.yang b/yang/frr-bgp-route-map.yang
index 8e288194ec..666f2bb235 100644
--- a/yang/frr-bgp-route-map.yang
+++ b/yang/frr-bgp-route-map.yang
@@ -474,6 +474,27 @@ module frr-bgp-route-map {
"ext-community link bandwidth types.";
}
+ typedef asn-type {
+ type union {
+ type uint32 {
+ range "1..4294967295";
+ }
+ type string {
+ pattern '(0|[1-9][0-9]{0,3}|[1-5][0-9]{4}|'
+ + '6[0-4][0-9]{3}|65[0-4][0-9]{2}|'
+ + '655[0-2][0-9]|6553[0-5])\.'
+ + '(0|[1-9][0-9]{0,3}|[1-5][0-9]{4}|6[0-4][0-9]{3}|'
+ + '65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5])' {
+ error-message "AS dot should be in the form [0..65535].[0..65535].";
+ }
+ pattern '^0\.0$' {
+ modifier "invert-match";
+ error-message "AS dot can't be equal to 0.0.";
+ }
+ }
+ }
+ }
+
augment "/frr-route-map:lib/frr-route-map:route-map/frr-route-map:entry/frr-route-map:match-condition/frr-route-map:rmap-match-condition/frr-route-map:match-condition" {
case local-preference {
when "derived-from-or-self(/frr-route-map:lib/frr-route-map:route-map/frr-route-map:entry/frr-route-map:match-condition/frr-route-map:condition, 'frr-bgp-route-map:match-local-preference')";
@@ -739,7 +760,7 @@ module frr-bgp-route-map {
when "derived-from-or-self(/frr-route-map:lib/frr-route-map:route-map/frr-route-map:entry/frr-route-map:set-action/frr-route-map:action, 'frr-bgp-route-map:distance')";
leaf distance {
type uint8 {
- range "0..255";
+ range "1..255";
}
}
}
@@ -1004,16 +1025,12 @@ module frr-bgp-route-map {
when "derived-from-or-self(/frr-route-map:lib/frr-route-map:route-map/frr-route-map:entry/frr-route-map:set-action/frr-route-map:action, 'frr-bgp-route-map:aggregator')";
container aggregator {
leaf aggregator-asn {
- type uint32 {
- range "1..4294967295";
- }
+ type asn-type;
description
"ASN of the aggregator";
}
leaf aggregator-address {
- when "../aggregator-asn > 0 or "
- + "../aggregator-asn <= 4294967295";
type inet:ipv4-address;
description
"IPv4 address of the aggregator";
diff --git a/yang/frr-isisd.yang b/yang/frr-isisd.yang
index 0c2cf232fb..de925b4823 100644
--- a/yang/frr-isisd.yang
+++ b/yang/frr-isisd.yang
@@ -116,6 +116,26 @@ module frr-isisd {
associated with an interface.";
}
+ typedef hello-padding-type {
+ type enumeration {
+ enum "always" {
+ value 0;
+ description
+ "Add padding to all hello packets.";
+ }
+ enum "disabled" {
+ value 1;
+ description
+ "Do not add any padding to hello packets.";
+ }
+ enum "during-adjacency-formation" {
+ value 2;
+ description
+ "Add padding to hello packets during adjacency formation only.";
+ }
+ }
+ }
+
typedef network-type {
type enumeration {
enum "unknown" {
@@ -605,10 +625,10 @@ module frr-isisd {
description
"Parameters related to IS-IS hello PDUs.";
leaf padding {
- type boolean;
- default "true";
+ type hello-padding-type;
+ default "always";
description
- "Add padding to IS-IS hello PDUs.";
+ "Type of padding for IS-IS hello packets.";
}
container interval {
@@ -1574,6 +1594,13 @@ module frr-isisd {
"Log changes to the IS-IS adjacencies in this area.";
}
+ leaf log-pdu-drops {
+ type boolean;
+ default "false";
+ description
+ "Log any dropped PDUs in this area.";
+ }
+
container mpls-te {
presence "Present if MPLS-TE is enabled.";
description
diff --git a/yang/frr-ripd.yang b/yang/frr-ripd.yang
index 746bf35d28..24fe588854 100644
--- a/yang/frr-ripd.yang
+++ b/yang/frr-ripd.yang
@@ -13,6 +13,9 @@ module frr-ripd {
import frr-interface {
prefix frr-interface;
}
+ import frr-nexthop {
+ prefix frr-nexthop;
+ }
import frr-vrf {
prefix frr-vrf;
}
@@ -60,6 +63,7 @@ module frr-ripd {
description
"Changed interface references to use
frr-interface:interface-ref typedef";
+ reference "FRRouting";
}
revision 2017-12-06 {
description
@@ -69,10 +73,35 @@ module frr-ripd {
RFC 2453: RIP Version 2.";
}
+ typedef rip-route-type {
+ type enumeration {
+ enum normal {
+ value 0;
+ description "Normal RIP route type.";
+ }
+ enum static {
+ value 1;
+ description "Static RIP route type.";
+ }
+ enum default {
+ value 2;
+ description "Default RIP route type.";
+ }
+ enum redistribute {
+ value 3;
+ description "Redistribute RIP route type.";
+ }
+ enum interface {
+ value 4;
+ description "Interface RIP route type.";
+ }
+ }
+ description
+ "Types of RIP routes.";
+ }
+
container ripd {
- /*
- * Routing instance configuration.
- */
+ description "rip routing instance data";
list instance {
key "vrf";
description
@@ -229,9 +258,9 @@ module frr-ripd {
"Redistributes routes learned from other routing protocols.";
leaf protocol {
type frr-route-types:frr-route-types-v4;
+ must '. != "rip"';
description
"Routing protocol.";
- must '. != "rip"';
}
leaf route-map {
type frr-route-map:route-map-ref;
@@ -291,11 +320,8 @@ module frr-ripd {
}
}
container version {
+ description "version of rip";
leaf receive {
- must
- '(. = "1" and ../send = "1") or ' +
- '(. = "2" and ../send = "2") or ' +
- '(. = "1-2" and ../send = "2")';
type enumeration {
enum "1" {
value 1;
@@ -313,15 +339,15 @@ module frr-ripd {
"Accept both RIPv1 and RIPv2 updates.";
}
}
+ must
+ '(. = "1" and ../send = "1") or ' +
+ '(. = "2" and ../send = "2") or ' +
+ '(. = "1-2" and ../send = "2")';
default "1-2";
description
"Advertisement reception - Version control.";
}
leaf send {
- must
- '(../receive = "1" and . = "1") or ' +
- '(../receive = "2" and . = "2") or ' +
- '(../receive = "1-2" and . = "2")';
type enumeration {
enum "1" {
value 1;
@@ -334,6 +360,10 @@ module frr-ripd {
"Send RIPv2 updates only.";
}
}
+ must
+ '(../receive = "1" and . = "1") or ' +
+ '(../receive = "2" and . = "2") or ' +
+ '(../receive = "1-2" and . = "2")';
default "2";
description
"Advertisement transmission - Version control.";
@@ -399,23 +429,81 @@ module frr-ripd {
separated by the slash (/) character. The range of
values for the prefix-length is 0 to 32.";
}
+ container nexthops {
+ description "container of nexthops";
+ list nexthop {
+ description "A list of nexthop objects.";
+ leaf nh-type {
+ type frr-nexthop:nexthop-type;
+ mandatory true;
+ description
+ "The nexthop type.";
+ }
+ leaf protocol {
+ type frr-route-types:frr-route-types-v4;
+ description
+ "The protocol originating this route.";
+ }
+ leaf rip-type {
+ type rip-route-type;
+ description
+ "The RIP type of route.";
+ }
+ leaf gateway {
+ type inet:ipv4-address;
+ description
+ "The nexthop gateway address.";
+ }
+ leaf interface {
+ type frr-interface:interface-ref;
+ description
+ "The nexthop egress interface.";
+ }
+ leaf from {
+ type inet:ipv4-address;
+ description
+ "The nexthop gateway address.";
+ }
+ leaf tag {
+ type uint32;
+ default "0";
+ description
+ "Route tag";
+ }
+ leaf external-metric {
+ type uint32;
+ description
+ "External metric if learned from external protocol.";
+ }
+ leaf expire-time {
+ type uint32;
+ description
+ "Seconds before route expires.";
+ }
+ }
+ }
+ leaf metric {
+ type uint8 {
+ range "0..16";
+ }
+ description
+ "Route metric.";
+ }
+ /*
+ * Replaced by container `nexthops` above.
+ */
leaf next-hop {
type inet:ipv4-address;
+ status deprecated;
description
"Next hop IPv4 address.";
}
leaf interface {
type frr-interface:interface-ref;
+ status deprecated;
description
"The interface that the route uses.";
}
- leaf metric {
- type uint8 {
- range "0..16";
- }
- description
- "Route metric.";
- }
}
}
}
@@ -426,6 +514,7 @@ module frr-ripd {
* Per-interface configuration data
*/
augment "/frr-interface:lib/frr-interface:interface" {
+ description "rip interface data";
container rip {
description
"RIP interface parameters.";
diff --git a/zebra/dpdk/zebra_dplane_dpdk.c b/zebra/dpdk/zebra_dplane_dpdk.c
index 87245f47e8..fc140b07a3 100644
--- a/zebra/dpdk/zebra_dplane_dpdk.c
+++ b/zebra/dpdk/zebra_dplane_dpdk.c
@@ -645,7 +645,7 @@ static int zd_dpdk_init(void)
zd_dpdk_vty_init();
frr_with_privs (&zserv_privs) {
- rc = rte_eal_init(ARRAY_SIZE(argv), argv);
+ rc = rte_eal_init(array_size(argv), argv);
}
if (rc < 0) {
zlog_warn("EAL init failed %s", rte_strerror(rte_errno));
@@ -694,7 +694,7 @@ static int zd_dpdk_finish(struct zebra_dplane_provider *prov, bool early)
}
-static int zd_dpdk_plugin_init(struct thread_master *tm)
+static int zd_dpdk_plugin_init(struct event_loop *tm)
{
int ret;
diff --git a/zebra/dplane_fpm_nl.c b/zebra/dplane_fpm_nl.c
index 18aed7b376..be2f55120c 100644
--- a/zebra/dplane_fpm_nl.c
+++ b/zebra/dplane_fpm_nl.c
@@ -83,22 +83,22 @@ struct fpm_nl_ctx {
/* data plane events. */
struct zebra_dplane_provider *prov;
struct frr_pthread *fthread;
- struct thread *t_connect;
- struct thread *t_read;
- struct thread *t_write;
- struct thread *t_event;
- struct thread *t_nhg;
- struct thread *t_dequeue;
+ struct event *t_connect;
+ struct event *t_read;
+ struct event *t_write;
+ struct event *t_event;
+ struct event *t_nhg;
+ struct event *t_dequeue;
/* zebra events. */
- struct thread *t_lspreset;
- struct thread *t_lspwalk;
- struct thread *t_nhgreset;
- struct thread *t_nhgwalk;
- struct thread *t_ribreset;
- struct thread *t_ribwalk;
- struct thread *t_rmacreset;
- struct thread *t_rmacwalk;
+ struct event *t_lspreset;
+ struct event *t_lspwalk;
+ struct event *t_nhgreset;
+ struct event *t_nhgwalk;
+ struct event *t_ribreset;
+ struct event *t_ribwalk;
+ struct event *t_rmacreset;
+ struct event *t_rmacwalk;
/* Statistic counters. */
struct {
@@ -156,26 +156,26 @@ enum fpm_nl_events {
};
#define FPM_RECONNECT(fnc) \
- thread_add_event((fnc)->fthread->master, fpm_process_event, (fnc), \
- FNE_INTERNAL_RECONNECT, &(fnc)->t_event)
+ event_add_event((fnc)->fthread->master, fpm_process_event, (fnc), \
+ FNE_INTERNAL_RECONNECT, &(fnc)->t_event)
#define WALK_FINISH(fnc, ev) \
- thread_add_event((fnc)->fthread->master, fpm_process_event, (fnc), \
- (ev), NULL)
+ event_add_event((fnc)->fthread->master, fpm_process_event, (fnc), \
+ (ev), NULL)
/*
* Prototypes.
*/
-static void fpm_process_event(struct thread *t);
+static void fpm_process_event(struct event *t);
static int fpm_nl_enqueue(struct fpm_nl_ctx *fnc, struct zebra_dplane_ctx *ctx);
-static void fpm_lsp_send(struct thread *t);
-static void fpm_lsp_reset(struct thread *t);
-static void fpm_nhg_send(struct thread *t);
-static void fpm_nhg_reset(struct thread *t);
-static void fpm_rib_send(struct thread *t);
-static void fpm_rib_reset(struct thread *t);
-static void fpm_rmac_send(struct thread *t);
-static void fpm_rmac_reset(struct thread *t);
+static void fpm_lsp_send(struct event *t);
+static void fpm_lsp_reset(struct event *t);
+static void fpm_nhg_send(struct event *t);
+static void fpm_nhg_reset(struct event *t);
+static void fpm_rib_send(struct event *t);
+static void fpm_rib_reset(struct event *t);
+static void fpm_rmac_send(struct event *t);
+static void fpm_rmac_reset(struct event *t);
/*
* CLI.
@@ -231,8 +231,8 @@ DEFUN(fpm_set_address, fpm_set_address_cmd,
memcpy(&sin6->sin6_addr, naddr, sizeof(sin6->sin6_addr));
ask_reconnect:
- thread_add_event(gfnc->fthread->master, fpm_process_event, gfnc,
- FNE_RECONNECT, &gfnc->t_event);
+ event_add_event(gfnc->fthread->master, fpm_process_event, gfnc,
+ FNE_RECONNECT, &gfnc->t_event);
return CMD_SUCCESS;
}
@@ -246,8 +246,8 @@ DEFUN(no_fpm_set_address, no_fpm_set_address_cmd,
"FPM remote listening server port\n"
"Remote FPM server port\n")
{
- thread_add_event(gfnc->fthread->master, fpm_process_event, gfnc,
- FNE_DISABLE, &gfnc->t_event);
+ event_add_event(gfnc->fthread->master, fpm_process_event, gfnc,
+ FNE_DISABLE, &gfnc->t_event);
return CMD_SUCCESS;
}
@@ -260,8 +260,8 @@ DEFUN(fpm_use_nhg, fpm_use_nhg_cmd,
if (gfnc->use_nhg)
return CMD_SUCCESS;
- thread_add_event(gfnc->fthread->master, fpm_process_event, gfnc,
- FNE_TOGGLE_NHG, &gfnc->t_nhg);
+ event_add_event(gfnc->fthread->master, fpm_process_event, gfnc,
+ FNE_TOGGLE_NHG, &gfnc->t_nhg);
return CMD_SUCCESS;
}
@@ -276,8 +276,8 @@ DEFUN(no_fpm_use_nhg, no_fpm_use_nhg_cmd,
if (!gfnc->use_nhg)
return CMD_SUCCESS;
- thread_add_event(gfnc->fthread->master, fpm_process_event, gfnc,
- FNE_TOGGLE_NHG, &gfnc->t_nhg);
+ event_add_event(gfnc->fthread->master, fpm_process_event, gfnc,
+ FNE_TOGGLE_NHG, &gfnc->t_nhg);
return CMD_SUCCESS;
}
@@ -288,8 +288,8 @@ DEFUN(fpm_reset_counters, fpm_reset_counters_cmd,
FPM_STR
"FPM statistic counters\n")
{
- thread_add_event(gfnc->fthread->master, fpm_process_event, gfnc,
- FNE_RESET_COUNTERS, &gfnc->t_event);
+ event_add_event(gfnc->fthread->master, fpm_process_event, gfnc,
+ FNE_RESET_COUNTERS, &gfnc->t_event);
return CMD_SUCCESS;
}
@@ -409,19 +409,19 @@ static struct cmd_node fpm_node = {
/*
* FPM functions.
*/
-static void fpm_connect(struct thread *t);
+static void fpm_connect(struct event *t);
static void fpm_reconnect(struct fpm_nl_ctx *fnc)
{
/* Cancel all zebra threads first. */
- thread_cancel_async(zrouter.master, &fnc->t_lspreset, NULL);
- thread_cancel_async(zrouter.master, &fnc->t_lspwalk, NULL);
- thread_cancel_async(zrouter.master, &fnc->t_nhgreset, NULL);
- thread_cancel_async(zrouter.master, &fnc->t_nhgwalk, NULL);
- thread_cancel_async(zrouter.master, &fnc->t_ribreset, NULL);
- thread_cancel_async(zrouter.master, &fnc->t_ribwalk, NULL);
- thread_cancel_async(zrouter.master, &fnc->t_rmacreset, NULL);
- thread_cancel_async(zrouter.master, &fnc->t_rmacwalk, NULL);
+ event_cancel_async(zrouter.master, &fnc->t_lspreset, NULL);
+ event_cancel_async(zrouter.master, &fnc->t_lspwalk, NULL);
+ event_cancel_async(zrouter.master, &fnc->t_nhgreset, NULL);
+ event_cancel_async(zrouter.master, &fnc->t_nhgwalk, NULL);
+ event_cancel_async(zrouter.master, &fnc->t_ribreset, NULL);
+ event_cancel_async(zrouter.master, &fnc->t_ribwalk, NULL);
+ event_cancel_async(zrouter.master, &fnc->t_rmacreset, NULL);
+ event_cancel_async(zrouter.master, &fnc->t_rmacwalk, NULL);
/*
* Grab the lock to empty the streams (data plane might try to
@@ -437,20 +437,20 @@ static void fpm_reconnect(struct fpm_nl_ctx *fnc)
stream_reset(fnc->ibuf);
stream_reset(fnc->obuf);
- THREAD_OFF(fnc->t_read);
- THREAD_OFF(fnc->t_write);
+ EVENT_OFF(fnc->t_read);
+ EVENT_OFF(fnc->t_write);
/* FPM is disabled, don't attempt to connect. */
if (fnc->disabled)
return;
- thread_add_timer(fnc->fthread->master, fpm_connect, fnc, 3,
- &fnc->t_connect);
+ event_add_timer(fnc->fthread->master, fpm_connect, fnc, 3,
+ &fnc->t_connect);
}
-static void fpm_read(struct thread *t)
+static void fpm_read(struct event *t)
{
- struct fpm_nl_ctx *fnc = THREAD_ARG(t);
+ struct fpm_nl_ctx *fnc = EVENT_ARG(t);
fpm_msg_hdr_t fpm;
ssize_t rv;
char buf[65535];
@@ -482,8 +482,8 @@ static void fpm_read(struct thread *t)
}
/* Schedule the next read */
- thread_add_read(fnc->fthread->master, fpm_read, fnc, fnc->socket,
- &fnc->t_read);
+ event_add_read(fnc->fthread->master, fpm_read, fnc, fnc->socket,
+ &fnc->t_read);
/* We've got an interruption. */
if (rv == -2)
@@ -610,9 +610,9 @@ static void fpm_read(struct thread *t)
stream_reset(fnc->ibuf);
}
-static void fpm_write(struct thread *t)
+static void fpm_write(struct event *t)
{
- struct fpm_nl_ctx *fnc = THREAD_ARG(t);
+ struct fpm_nl_ctx *fnc = EVENT_ARG(t);
socklen_t statuslen;
ssize_t bwritten;
int rv, status;
@@ -646,12 +646,12 @@ static void fpm_write(struct thread *t)
* Starting with LSPs walk all FPM objects, marking them
* as unsent and then replaying them.
*/
- thread_add_timer(zrouter.master, fpm_lsp_reset, fnc, 0,
- &fnc->t_lspreset);
+ event_add_timer(zrouter.master, fpm_lsp_reset, fnc, 0,
+ &fnc->t_lspreset);
/* Permit receiving messages now. */
- thread_add_read(fnc->fthread->master, fpm_read, fnc,
- fnc->socket, &fnc->t_read);
+ event_add_read(fnc->fthread->master, fpm_read, fnc, fnc->socket,
+ &fnc->t_read);
}
frr_mutex_lock_autounlock(&fnc->obuf_mutex);
@@ -708,15 +708,15 @@ static void fpm_write(struct thread *t)
/* Stream is not empty yet, we must schedule more writes. */
if (STREAM_READABLE(fnc->obuf)) {
stream_pulldown(fnc->obuf);
- thread_add_write(fnc->fthread->master, fpm_write, fnc,
- fnc->socket, &fnc->t_write);
+ event_add_write(fnc->fthread->master, fpm_write, fnc,
+ fnc->socket, &fnc->t_write);
return;
}
}
-static void fpm_connect(struct thread *t)
+static void fpm_connect(struct event *t)
{
- struct fpm_nl_ctx *fnc = THREAD_ARG(t);
+ struct fpm_nl_ctx *fnc = EVENT_ARG(t);
struct sockaddr_in *sin = (struct sockaddr_in *)&fnc->addr;
struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)&fnc->addr;
socklen_t slen;
@@ -727,8 +727,8 @@ static void fpm_connect(struct thread *t)
if (sock == -1) {
zlog_err("%s: fpm socket failed: %s", __func__,
strerror(errno));
- thread_add_timer(fnc->fthread->master, fpm_connect, fnc, 3,
- &fnc->t_connect);
+ event_add_timer(fnc->fthread->master, fpm_connect, fnc, 3,
+ &fnc->t_connect);
return;
}
@@ -753,18 +753,18 @@ static void fpm_connect(struct thread *t)
close(sock);
zlog_warn("%s: fpm connection failed: %s", __func__,
strerror(errno));
- thread_add_timer(fnc->fthread->master, fpm_connect, fnc, 3,
- &fnc->t_connect);
+ event_add_timer(fnc->fthread->master, fpm_connect, fnc, 3,
+ &fnc->t_connect);
return;
}
fnc->connecting = (errno == EINPROGRESS);
fnc->socket = sock;
if (!fnc->connecting)
- thread_add_read(fnc->fthread->master, fpm_read, fnc, sock,
- &fnc->t_read);
- thread_add_write(fnc->fthread->master, fpm_write, fnc, sock,
- &fnc->t_write);
+ event_add_read(fnc->fthread->master, fpm_read, fnc, sock,
+ &fnc->t_read);
+ event_add_write(fnc->fthread->master, fpm_write, fnc, sock,
+ &fnc->t_write);
/*
* Starting with LSPs walk all FPM objects, marking them
@@ -773,8 +773,8 @@ static void fpm_connect(struct thread *t)
* If we are not connected, then delay the objects reset/send.
*/
if (!fnc->connecting)
- thread_add_timer(zrouter.master, fpm_lsp_reset, fnc, 0,
- &fnc->t_lspreset);
+ event_add_timer(zrouter.master, fpm_lsp_reset, fnc, 0,
+ &fnc->t_lspreset);
}
/**
@@ -983,8 +983,8 @@ static int fpm_nl_enqueue(struct fpm_nl_ctx *fnc, struct zebra_dplane_ctx *ctx)
memory_order_relaxed);
/* Tell the thread to start writing. */
- thread_add_write(fnc->fthread->master, fpm_write, fnc, fnc->socket,
- &fnc->t_write);
+ event_add_write(fnc->fthread->master, fpm_write, fnc, fnc->socket,
+ &fnc->t_write);
return 0;
}
@@ -1020,10 +1020,10 @@ static int fpm_lsp_send_cb(struct hash_bucket *bucket, void *arg)
return HASHWALK_CONTINUE;
}
-static void fpm_lsp_send(struct thread *t)
+static void fpm_lsp_send(struct event *t)
{
- struct fpm_nl_ctx *fnc = THREAD_ARG(t);
- struct zebra_vrf *zvrf = vrf_info_lookup(VRF_DEFAULT);
+ struct fpm_nl_ctx *fnc = EVENT_ARG(t);
+ struct zebra_vrf *zvrf = zebra_vrf_lookup_by_id(VRF_DEFAULT);
struct fpm_lsp_arg fla;
fla.fnc = fnc;
@@ -1038,12 +1038,12 @@ static void fpm_lsp_send(struct thread *t)
WALK_FINISH(fnc, FNE_LSP_FINISHED);
/* Now move onto routes */
- thread_add_timer(zrouter.master, fpm_nhg_reset, fnc, 0,
- &fnc->t_nhgreset);
+ event_add_timer(zrouter.master, fpm_nhg_reset, fnc, 0,
+ &fnc->t_nhgreset);
} else {
/* Didn't finish - reschedule LSP walk */
- thread_add_timer(zrouter.master, fpm_lsp_send, fnc, 0,
- &fnc->t_lspwalk);
+ event_add_timer(zrouter.master, fpm_lsp_send, fnc, 0,
+ &fnc->t_lspwalk);
}
}
@@ -1080,9 +1080,9 @@ static int fpm_nhg_send_cb(struct hash_bucket *bucket, void *arg)
return HASHWALK_CONTINUE;
}
-static void fpm_nhg_send(struct thread *t)
+static void fpm_nhg_send(struct event *t)
{
- struct fpm_nl_ctx *fnc = THREAD_ARG(t);
+ struct fpm_nl_ctx *fnc = EVENT_ARG(t);
struct fpm_nhg_arg fna;
fna.fnc = fnc;
@@ -1099,19 +1099,19 @@ static void fpm_nhg_send(struct thread *t)
/* We are done sending next hops, lets install the routes now. */
if (fna.complete) {
WALK_FINISH(fnc, FNE_NHG_FINISHED);
- thread_add_timer(zrouter.master, fpm_rib_reset, fnc, 0,
- &fnc->t_ribreset);
+ event_add_timer(zrouter.master, fpm_rib_reset, fnc, 0,
+ &fnc->t_ribreset);
} else /* Otherwise reschedule next hop group again. */
- thread_add_timer(zrouter.master, fpm_nhg_send, fnc, 0,
- &fnc->t_nhgwalk);
+ event_add_timer(zrouter.master, fpm_nhg_send, fnc, 0,
+ &fnc->t_nhgwalk);
}
/**
* Send all RIB installed routes to the connected data plane.
*/
-static void fpm_rib_send(struct thread *t)
+static void fpm_rib_send(struct event *t)
{
- struct fpm_nl_ctx *fnc = THREAD_ARG(t);
+ struct fpm_nl_ctx *fnc = EVENT_ARG(t);
rib_dest_t *dest;
struct route_node *rn;
struct route_table *rt;
@@ -1141,8 +1141,8 @@ static void fpm_rib_send(struct thread *t)
/* Free the temporary allocated context. */
dplane_ctx_fini(&ctx);
- thread_add_timer(zrouter.master, fpm_rib_send,
- fnc, 1, &fnc->t_ribwalk);
+ event_add_timer(zrouter.master, fpm_rib_send,
+ fnc, 1, &fnc->t_ribwalk);
return;
}
@@ -1158,8 +1158,8 @@ static void fpm_rib_send(struct thread *t)
WALK_FINISH(fnc, FNE_RIB_FINISHED);
/* Schedule next event: RMAC reset. */
- thread_add_event(zrouter.master, fpm_rmac_reset, fnc, 0,
- &fnc->t_rmacreset);
+ event_add_event(zrouter.master, fpm_rmac_reset, fnc, 0,
+ &fnc->t_rmacreset);
}
/*
@@ -1199,8 +1199,8 @@ static void fpm_enqueue_rmac_table(struct hash_bucket *bucket, void *arg)
zrmac->fwd_info.r_vtep_ip, sticky, 0 /*nhg*/,
0 /*update_flags*/);
if (fpm_nl_enqueue(fra->fnc, fra->ctx) == -1) {
- thread_add_timer(zrouter.master, fpm_rmac_send,
- fra->fnc, 1, &fra->fnc->t_rmacwalk);
+ event_add_timer(zrouter.master, fpm_rmac_send, fra->fnc, 1,
+ &fra->fnc->t_rmacwalk);
fra->complete = false;
}
}
@@ -1214,11 +1214,11 @@ static void fpm_enqueue_l3vni_table(struct hash_bucket *bucket, void *arg)
hash_iterate(zl3vni->rmac_table, fpm_enqueue_rmac_table, zl3vni);
}
-static void fpm_rmac_send(struct thread *t)
+static void fpm_rmac_send(struct event *t)
{
struct fpm_rmac_arg fra;
- fra.fnc = THREAD_ARG(t);
+ fra.fnc = EVENT_ARG(t);
fra.ctx = dplane_ctx_alloc();
fra.complete = true;
hash_iterate(zrouter.l3vni_table, fpm_enqueue_l3vni_table, &fra);
@@ -1240,14 +1240,14 @@ static void fpm_nhg_reset_cb(struct hash_bucket *bucket, void *arg)
UNSET_FLAG(nhe->flags, NEXTHOP_GROUP_FPM);
}
-static void fpm_nhg_reset(struct thread *t)
+static void fpm_nhg_reset(struct event *t)
{
- struct fpm_nl_ctx *fnc = THREAD_ARG(t);
+ struct fpm_nl_ctx *fnc = EVENT_ARG(t);
hash_iterate(zrouter.nhgs_id, fpm_nhg_reset_cb, NULL);
/* Schedule next step: send next hop groups. */
- thread_add_event(zrouter.master, fpm_nhg_send, fnc, 0, &fnc->t_nhgwalk);
+ event_add_event(zrouter.master, fpm_nhg_send, fnc, 0, &fnc->t_nhgwalk);
}
/*
@@ -1260,23 +1260,23 @@ static void fpm_lsp_reset_cb(struct hash_bucket *bucket, void *arg)
UNSET_FLAG(lsp->flags, LSP_FLAG_FPM);
}
-static void fpm_lsp_reset(struct thread *t)
+static void fpm_lsp_reset(struct event *t)
{
- struct fpm_nl_ctx *fnc = THREAD_ARG(t);
- struct zebra_vrf *zvrf = vrf_info_lookup(VRF_DEFAULT);
+ struct fpm_nl_ctx *fnc = EVENT_ARG(t);
+ struct zebra_vrf *zvrf = zebra_vrf_lookup_by_id(VRF_DEFAULT);
hash_iterate(zvrf->lsp_table, fpm_lsp_reset_cb, NULL);
/* Schedule next step: send LSPs */
- thread_add_event(zrouter.master, fpm_lsp_send, fnc, 0, &fnc->t_lspwalk);
+ event_add_event(zrouter.master, fpm_lsp_send, fnc, 0, &fnc->t_lspwalk);
}
/**
* Resets the RIB FPM flags so we send all routes again.
*/
-static void fpm_rib_reset(struct thread *t)
+static void fpm_rib_reset(struct event *t)
{
- struct fpm_nl_ctx *fnc = THREAD_ARG(t);
+ struct fpm_nl_ctx *fnc = EVENT_ARG(t);
rib_dest_t *dest;
struct route_node *rn;
struct route_table *rt;
@@ -1295,7 +1295,7 @@ static void fpm_rib_reset(struct thread *t)
}
/* Schedule next step: send RIB routes. */
- thread_add_event(zrouter.master, fpm_rib_send, fnc, 0, &fnc->t_ribwalk);
+ event_add_event(zrouter.master, fpm_rib_send, fnc, 0, &fnc->t_ribwalk);
}
/*
@@ -1315,20 +1315,20 @@ static void fpm_unset_l3vni_table(struct hash_bucket *bucket, void *arg)
hash_iterate(zl3vni->rmac_table, fpm_unset_rmac_table, zl3vni);
}
-static void fpm_rmac_reset(struct thread *t)
+static void fpm_rmac_reset(struct event *t)
{
- struct fpm_nl_ctx *fnc = THREAD_ARG(t);
+ struct fpm_nl_ctx *fnc = EVENT_ARG(t);
hash_iterate(zrouter.l3vni_table, fpm_unset_l3vni_table, NULL);
/* Schedule next event: send RMAC entries. */
- thread_add_event(zrouter.master, fpm_rmac_send, fnc, 0,
- &fnc->t_rmacwalk);
+ event_add_event(zrouter.master, fpm_rmac_send, fnc, 0,
+ &fnc->t_rmacwalk);
}
-static void fpm_process_queue(struct thread *t)
+static void fpm_process_queue(struct event *t)
{
- struct fpm_nl_ctx *fnc = THREAD_ARG(t);
+ struct fpm_nl_ctx *fnc = EVENT_ARG(t);
struct zebra_dplane_ctx *ctx;
bool no_bufs = false;
uint64_t processed_contexts = 0;
@@ -1371,8 +1371,8 @@ static void fpm_process_queue(struct thread *t)
/* Re-schedule if we ran out of buffer space */
if (no_bufs)
- thread_add_timer(fnc->fthread->master, fpm_process_queue,
- fnc, 0, &fnc->t_dequeue);
+ event_add_timer(fnc->fthread->master, fpm_process_queue, fnc, 0,
+ &fnc->t_dequeue);
/*
* Let the dataplane thread know if there are items in the
@@ -1387,10 +1387,10 @@ static void fpm_process_queue(struct thread *t)
/**
* Handles external (e.g. CLI, data plane or others) events.
*/
-static void fpm_process_event(struct thread *t)
+static void fpm_process_event(struct event *t)
{
- struct fpm_nl_ctx *fnc = THREAD_ARG(t);
- enum fpm_nl_events event = THREAD_VAL(t);
+ struct fpm_nl_ctx *fnc = EVENT_ARG(t);
+ enum fpm_nl_events event = EVENT_VAL(t);
switch (event) {
case FNE_DISABLE:
@@ -1474,19 +1474,19 @@ static int fpm_nl_start(struct zebra_dplane_provider *prov)
static int fpm_nl_finish_early(struct fpm_nl_ctx *fnc)
{
/* Disable all events and close socket. */
- THREAD_OFF(fnc->t_lspreset);
- THREAD_OFF(fnc->t_lspwalk);
- THREAD_OFF(fnc->t_nhgreset);
- THREAD_OFF(fnc->t_nhgwalk);
- THREAD_OFF(fnc->t_ribreset);
- THREAD_OFF(fnc->t_ribwalk);
- THREAD_OFF(fnc->t_rmacreset);
- THREAD_OFF(fnc->t_rmacwalk);
- THREAD_OFF(fnc->t_event);
- THREAD_OFF(fnc->t_nhg);
- thread_cancel_async(fnc->fthread->master, &fnc->t_read, NULL);
- thread_cancel_async(fnc->fthread->master, &fnc->t_write, NULL);
- thread_cancel_async(fnc->fthread->master, &fnc->t_connect, NULL);
+ EVENT_OFF(fnc->t_lspreset);
+ EVENT_OFF(fnc->t_lspwalk);
+ EVENT_OFF(fnc->t_nhgreset);
+ EVENT_OFF(fnc->t_nhgwalk);
+ EVENT_OFF(fnc->t_ribreset);
+ EVENT_OFF(fnc->t_ribwalk);
+ EVENT_OFF(fnc->t_rmacreset);
+ EVENT_OFF(fnc->t_rmacwalk);
+ EVENT_OFF(fnc->t_event);
+ EVENT_OFF(fnc->t_nhg);
+ event_cancel_async(fnc->fthread->master, &fnc->t_read, NULL);
+ event_cancel_async(fnc->fthread->master, &fnc->t_write, NULL);
+ event_cancel_async(fnc->fthread->master, &fnc->t_connect, NULL);
if (fnc->socket != -1) {
close(fnc->socket);
@@ -1575,8 +1575,8 @@ static int fpm_nl_process(struct zebra_dplane_provider *prov)
if (atomic_load_explicit(&fnc->counters.ctxqueue_len,
memory_order_relaxed)
> 0)
- thread_add_timer(fnc->fthread->master, fpm_process_queue,
- fnc, 0, &fnc->t_dequeue);
+ event_add_timer(fnc->fthread->master, fpm_process_queue, fnc, 0,
+ &fnc->t_dequeue);
/* Ensure dataplane thread is rescheduled if we hit the work limit */
if (counter >= limit)
@@ -1585,7 +1585,7 @@ static int fpm_nl_process(struct zebra_dplane_provider *prov)
return 0;
}
-static int fpm_nl_new(struct thread_master *tm)
+static int fpm_nl_new(struct event_loop *tm)
{
struct zebra_dplane_provider *prov = NULL;
int rv;
diff --git a/zebra/if_netlink.c b/zebra/if_netlink.c
index 21cad01374..3a325df06c 100644
--- a/zebra/if_netlink.c
+++ b/zebra/if_netlink.c
@@ -33,7 +33,7 @@
#include "table.h"
#include "memory.h"
#include "rib.h"
-#include "thread.h"
+#include "frrevent.h"
#include "privs.h"
#include "nexthop.h"
#include "vrf.h"
diff --git a/zebra/interface.c b/zebra/interface.c
index 02715ef384..496a85e676 100644
--- a/zebra/interface.c
+++ b/zebra/interface.c
@@ -51,9 +51,9 @@ DEFINE_MTYPE(ZEBRA, ZIF_DESC, "Intf desc");
static void if_down_del_nbr_connected(struct interface *ifp);
-static void if_zebra_speed_update(struct thread *thread)
+static void if_zebra_speed_update(struct event *thread)
{
- struct interface *ifp = THREAD_ARG(thread);
+ struct interface *ifp = EVENT_ARG(thread);
struct zebra_if *zif = ifp->info;
uint32_t new_speed;
bool changed = false;
@@ -96,9 +96,9 @@ static void if_zebra_speed_update(struct thread *thread)
return;
zif->speed_update_count++;
- thread_add_timer(zrouter.master, if_zebra_speed_update, ifp,
- SPEED_UPDATE_SLEEP_TIME, &zif->speed_update);
- thread_ignore_late_timer(zif->speed_update);
+ event_add_timer(zrouter.master, if_zebra_speed_update, ifp,
+ SPEED_UPDATE_SLEEP_TIME, &zif->speed_update);
+ event_ignore_late_timer(zif->speed_update);
}
}
@@ -163,9 +163,9 @@ static int if_zebra_new_hook(struct interface *ifp)
* down upon startup.
*/
zebra_if->speed_update_count = 0;
- thread_add_timer(zrouter.master, if_zebra_speed_update, ifp, 15,
- &zebra_if->speed_update);
- thread_ignore_late_timer(zebra_if->speed_update);
+ event_add_timer(zrouter.master, if_zebra_speed_update, ifp, 15,
+ &zebra_if->speed_update);
+ event_ignore_late_timer(zebra_if->speed_update);
return 0;
}
@@ -225,7 +225,7 @@ static int if_zebra_delete_hook(struct interface *ifp)
XFREE(MTYPE_ZIF_DESC, zebra_if->desc);
- THREAD_OFF(zebra_if->speed_update);
+ EVENT_OFF(zebra_if->speed_update);
XFREE(MTYPE_ZINFO, zebra_if);
}
@@ -1046,9 +1046,9 @@ void if_up(struct interface *ifp, bool install_connected)
if (zif->flags & ZIF_FLAG_EVPN_MH_UPLINK)
zebra_evpn_mh_uplink_oper_update(zif);
- thread_add_timer(zrouter.master, if_zebra_speed_update, ifp, 0,
- &zif->speed_update);
- thread_ignore_late_timer(zif->speed_update);
+ event_add_timer(zrouter.master, if_zebra_speed_update, ifp, 0,
+ &zif->speed_update);
+ event_ignore_late_timer(zif->speed_update);
}
/* Interface goes down. We have to manage different behavior of based
diff --git a/zebra/interface.h b/zebra/interface.h
index 09df42bc53..e5545d6ba0 100644
--- a/zebra/interface.h
+++ b/zebra/interface.h
@@ -200,7 +200,7 @@ struct zebra_if {
struct interface *link;
uint8_t speed_update_count;
- struct thread *speed_update;
+ struct event *speed_update;
/*
* Does this interface have a v6 to v4 ll neighbor entry
diff --git a/zebra/irdp.h b/zebra/irdp.h
index 9b97bb93fa..4330734992 100644
--- a/zebra/irdp.h
+++ b/zebra/irdp.h
@@ -114,7 +114,7 @@ struct irdp_interface {
#define IF_SHUTDOWN (1<<6)
struct interface *ifp;
- struct thread *t_advertise;
+ struct event *t_advertise;
unsigned long irdp_sent;
uint16_t Lifetime;
@@ -129,10 +129,10 @@ struct Adv {
extern void irdp_if_init(void);
extern int irdp_sock_init(void);
extern int irdp_config_write(struct vty *, struct interface *);
-extern void irdp_send_thread(struct thread *t_advert);
+extern void irdp_send_thread(struct event *t_advert);
extern void irdp_advert_off(struct interface *ifp);
extern void process_solicit(struct interface *ifp);
-extern void irdp_read_raw(struct thread *r);
+extern void irdp_read_raw(struct event *r);
extern void send_packet(struct interface *ifp, struct stream *s, uint32_t dst,
struct prefix *p, uint32_t ttl);
diff --git a/zebra/irdp_interface.c b/zebra/irdp_interface.c
index 0c9b6f3d39..253e6a8dd6 100644
--- a/zebra/irdp_interface.c
+++ b/zebra/irdp_interface.c
@@ -24,7 +24,7 @@
#include "connected.h"
#include "log.h"
#include "zclient.h"
-#include "thread.h"
+#include "frrevent.h"
#include "lib_errors.h"
#include "zebra/interface.h"
#include "zebra/rtadv.h"
@@ -272,8 +272,8 @@ static void irdp_if_start(struct interface *ifp, int multicast,
timer);
irdp->t_advertise = NULL;
- thread_add_timer(zrouter.master, irdp_send_thread, ifp, timer,
- &irdp->t_advertise);
+ event_add_timer(zrouter.master, irdp_send_thread, ifp, timer,
+ &irdp->t_advertise);
}
static void irdp_if_stop(struct interface *ifp)
diff --git a/zebra/irdp_main.c b/zebra/irdp_main.c
index ddcad92bdc..6548790e9a 100644
--- a/zebra/irdp_main.c
+++ b/zebra/irdp_main.c
@@ -32,7 +32,7 @@
#include "connected.h"
#include "log.h"
#include "zclient.h"
-#include "thread.h"
+#include "frrevent.h"
#include "privs.h"
#include "libfrr.h"
#include "lib_errors.h"
@@ -56,7 +56,7 @@
extern struct zebra_privs_t zserv_privs;
-struct thread *t_irdp_raw;
+struct event *t_irdp_raw;
/* Timer interval of irdp. */
int irdp_timer_interval = IRDP_DEFAULT_INTERVAL;
@@ -97,7 +97,7 @@ int irdp_sock_init(void)
return ret;
};
- thread_add_read(zrouter.master, irdp_read_raw, NULL, sock, &t_irdp_raw);
+ event_add_read(zrouter.master, irdp_read_raw, NULL, sock, &t_irdp_raw);
return sock;
}
@@ -190,10 +190,10 @@ static void irdp_advertisement(struct interface *ifp, struct prefix *p)
stream_free(s);
}
-void irdp_send_thread(struct thread *t_advert)
+void irdp_send_thread(struct event *t_advert)
{
uint32_t timer, tmp;
- struct interface *ifp = THREAD_ARG(t_advert);
+ struct interface *ifp = EVENT_ARG(t_advert);
struct zebra_if *zi = ifp->info;
struct irdp_interface *irdp = zi->irdp;
struct prefix *p;
@@ -229,8 +229,8 @@ void irdp_send_thread(struct thread *t_advert)
timer);
irdp->t_advertise = NULL;
- thread_add_timer(zrouter.master, irdp_send_thread, ifp, timer,
- &irdp->t_advertise);
+ event_add_timer(zrouter.master, irdp_send_thread, ifp, timer,
+ &irdp->t_advertise);
}
void irdp_advert_off(struct interface *ifp)
@@ -245,7 +245,7 @@ void irdp_advert_off(struct interface *ifp)
if (!irdp)
return;
- THREAD_OFF(irdp->t_advertise);
+ EVENT_OFF(irdp->t_advertise);
if (ifp->connected)
for (ALL_LIST_ELEMENTS(ifp->connected, node, nnode, ifc)) {
@@ -280,13 +280,13 @@ void process_solicit(struct interface *ifp)
return;
irdp->flags |= IF_SOLICIT;
- THREAD_OFF(irdp->t_advertise);
+ EVENT_OFF(irdp->t_advertise);
timer = (frr_weak_random() % MAX_RESPONSE_DELAY) + 1;
irdp->t_advertise = NULL;
- thread_add_timer(zrouter.master, irdp_send_thread, ifp, timer,
- &irdp->t_advertise);
+ event_add_timer(zrouter.master, irdp_send_thread, ifp, timer,
+ &irdp->t_advertise);
}
static int irdp_finish(void)
@@ -316,7 +316,7 @@ static int irdp_finish(void)
return 0;
}
-static int irdp_init(struct thread_master *master)
+static int irdp_init(struct event_loop *master)
{
irdp_if_init();
diff --git a/zebra/irdp_packet.c b/zebra/irdp_packet.c
index 4f4f3772dc..2dfc027f1d 100644
--- a/zebra/irdp_packet.c
+++ b/zebra/irdp_packet.c
@@ -34,7 +34,7 @@
#include "sockunion.h"
#include "sockunion.h"
#include "stream.h"
-#include "thread.h"
+#include "frrevent.h"
#include "vty.h"
#include "zclient.h"
#include "lib_errors.h"
@@ -52,7 +52,7 @@
int irdp_sock = -1;
-extern struct thread *t_irdp_raw;
+extern struct event *t_irdp_raw;
static void parse_irdp_packet(char *p, int len, struct interface *ifp)
{
@@ -209,7 +209,7 @@ static int irdp_recvmsg(int sock, uint8_t *buf, int size, int *ifindex)
return ret;
}
-void irdp_read_raw(struct thread *r)
+void irdp_read_raw(struct event *r)
{
struct interface *ifp;
struct zebra_if *zi;
@@ -217,9 +217,9 @@ void irdp_read_raw(struct thread *r)
char buf[IRDP_RX_BUF];
int ret, ifindex = 0;
- int irdp_sock = THREAD_FD(r);
- thread_add_read(zrouter.master, irdp_read_raw, NULL, irdp_sock,
- &t_irdp_raw);
+ int irdp_sock = EVENT_FD(r);
+ event_add_read(zrouter.master, irdp_read_raw, NULL, irdp_sock,
+ &t_irdp_raw);
ret = irdp_recvmsg(irdp_sock, (uint8_t *)buf, IRDP_RX_BUF, &ifindex);
diff --git a/zebra/kernel_netlink.c b/zebra/kernel_netlink.c
index a980b56b33..78b1dfe276 100644
--- a/zebra/kernel_netlink.c
+++ b/zebra/kernel_netlink.c
@@ -15,7 +15,7 @@
#include "table.h"
#include "memory.h"
#include "rib.h"
-#include "thread.h"
+#include "frrevent.h"
#include "privs.h"
#include "nexthop.h"
#include "vrf.h"
@@ -156,7 +156,7 @@ static const struct message rttype_str[] = {{RTN_UNSPEC, "none"},
{RTN_XRESOLVE, "resolver"},
{0}};
-extern struct thread_master *master;
+extern struct event_loop *master;
extern struct zebra_privs_t zserv_privs;
@@ -482,9 +482,9 @@ static int dplane_netlink_information_fetch(struct nlmsghdr *h, ns_id_t ns_id,
return 0;
}
-static void kernel_read(struct thread *thread)
+static void kernel_read(struct event *thread)
{
- struct zebra_ns *zns = (struct zebra_ns *)THREAD_ARG(thread);
+ struct zebra_ns *zns = (struct zebra_ns *)EVENT_ARG(thread);
struct zebra_dplane_info dp_info;
/* Capture key info from ns struct */
@@ -493,8 +493,8 @@ static void kernel_read(struct thread *thread)
netlink_parse_info(netlink_information_fetch, &zns->netlink, &dp_info,
5, false);
- thread_add_read(zrouter.master, kernel_read, zns, zns->netlink.sock,
- &zns->t_netlink);
+ event_add_read(zrouter.master, kernel_read, zns, zns->netlink.sock,
+ &zns->t_netlink);
}
/*
@@ -1939,8 +1939,8 @@ void kernel_init(struct zebra_ns *zns)
zns->t_netlink = NULL;
- thread_add_read(zrouter.master, kernel_read, zns,
- zns->netlink.sock, &zns->t_netlink);
+ event_add_read(zrouter.master, kernel_read, zns, zns->netlink.sock,
+ &zns->t_netlink);
rt_netlink_init();
}
@@ -1959,7 +1959,7 @@ static void kernel_nlsock_fini(struct nlsock *nls)
void kernel_terminate(struct zebra_ns *zns, bool complete)
{
- THREAD_OFF(zns->t_netlink);
+ EVENT_OFF(zns->t_netlink);
kernel_nlsock_fini(&zns->netlink);
diff --git a/zebra/kernel_socket.c b/zebra/kernel_socket.c
index 915fd087fe..b8dc92b2e9 100644
--- a/zebra/kernel_socket.c
+++ b/zebra/kernel_socket.c
@@ -1255,7 +1255,7 @@ int rtm_write(int message, union sockunion *dest, union sockunion *mask,
}
-#include "thread.h"
+#include "frrevent.h"
#include "zebra/zserv.h"
/* For debug purpose. */
@@ -1281,7 +1281,7 @@ static void rtmsg_debug(struct rt_msghdr *rtm)
#endif /* RTAX_MAX */
/* Kernel routing table and interface updates via routing socket. */
-static void kernel_read(struct thread *thread)
+static void kernel_read(struct event *thread)
{
int sock;
int nbytes;
@@ -1326,7 +1326,7 @@ static void kernel_read(struct thread *thread)
} buf;
/* Fetch routing socket. */
- sock = THREAD_FD(thread);
+ sock = EVENT_FD(thread);
nbytes = read(sock, &buf, sizeof(buf));
@@ -1338,8 +1338,8 @@ static void kernel_read(struct thread *thread)
* shortage and is not harmful for consistency of
* reading the routing socket. Ignore it.
*/
- thread_add_read(zrouter.master, kernel_read, NULL, sock,
- NULL);
+ event_add_read(zrouter.master, kernel_read, NULL, sock,
+ NULL);
return;
#else
flog_err(EC_ZEBRA_RECVMSG_OVERRUN,
@@ -1362,7 +1362,7 @@ static void kernel_read(struct thread *thread)
if (nbytes == 0)
return;
- thread_add_read(zrouter.master, kernel_read, NULL, sock, NULL);
+ event_add_read(zrouter.master, kernel_read, NULL, sock, NULL);
if (IS_ZEBRA_DEBUG_KERNEL)
rtmsg_debug(&buf.r.rtm);
@@ -1465,7 +1465,7 @@ static void routing_socket(struct zebra_ns *zns)
}
/* kernel_read needs rewrite. */
- thread_add_read(zrouter.master, kernel_read, NULL, routing_sock, NULL);
+ event_add_read(zrouter.master, kernel_read, NULL, routing_sock, NULL);
}
/* Exported interface function. This function simply calls
diff --git a/zebra/label_manager.h b/zebra/label_manager.h
index c0bd8e369f..cfbb4bd169 100644
--- a/zebra/label_manager.h
+++ b/zebra/label_manager.h
@@ -14,7 +14,7 @@
#include <stdint.h>
#include "lib/linklist.h"
-#include "lib/thread.h"
+#include "frrevent.h"
#include "lib/hook.h"
#include "zebra/zserv.h"
diff --git a/zebra/main.c b/zebra/main.c
index c40a03551d..81a3066445 100644
--- a/zebra/main.c
+++ b/zebra/main.c
@@ -8,7 +8,7 @@
#include <lib/version.h>
#include "getopt.h"
#include "command.h"
-#include "thread.h"
+#include "frrevent.h"
#include "filter.h"
#include "memory.h"
#include "prefix.h"
@@ -52,7 +52,7 @@
pid_t pid;
/* Pacify zclient.o in libfrr, which expects this variable. */
-struct thread_master *master;
+struct event_loop *master;
/* Route retain mode flag. */
int retain_mode = 0;
@@ -175,11 +175,6 @@ static void sigint(void)
if (zrouter.lsp_process_q)
work_queue_free_and_null(&zrouter.lsp_process_q);
- vrf_terminate();
-
- ns_walk_func(zebra_ns_early_shutdown, NULL, NULL);
- zebra_ns_notify_close();
-
access_list_reset();
prefix_list_reset();
/*
@@ -190,6 +185,8 @@ static void sigint(void)
*/
zebra_routemap_finish();
+ rib_update_finish();
+
list_delete(&zrouter.client_list);
/* Indicate that all new dplane work has been enqueued. When that
@@ -203,10 +200,15 @@ static void sigint(void)
* Final shutdown step for the zebra main thread. This is run after all
* async update processing has completed.
*/
-void zebra_finalize(struct thread *dummy)
+void zebra_finalize(struct event *dummy)
{
zlog_info("Zebra final shutdown");
+ vrf_terminate();
+
+ ns_walk_func(zebra_ns_early_shutdown, NULL, NULL);
+ zebra_ns_notify_close();
+
/* Stop dplane thread and finish any cleanup */
zebra_dplane_shutdown();
@@ -435,8 +437,8 @@ int main(int argc, char **argv)
* we have to have route_read() called before.
*/
zrouter.startup_time = monotime(NULL);
- thread_add_timer(zrouter.master, rib_sweep_route, NULL,
- graceful_restart, &zrouter.sweeper);
+ event_add_timer(zrouter.master, rib_sweep_route, NULL, graceful_restart,
+ &zrouter.sweeper);
/* Needed for BSD routing socket. */
pid = getpid();
diff --git a/zebra/redistribute.c b/zebra/redistribute.c
index 8cdc419cce..d2fa85eb64 100644
--- a/zebra/redistribute.c
+++ b/zebra/redistribute.c
@@ -145,7 +145,7 @@ static bool zebra_redistribute_check(const struct route_node *rn,
return false;
afi = family2afi(rn->p.family);
- zvrf = vrf_info_lookup(re->vrf_id);
+ zvrf = zebra_vrf_lookup_by_id(re->vrf_id);
if (re->vrf_id == VRF_DEFAULT && zvrf->table_id != re->table)
return false;
diff --git a/zebra/rib.h b/zebra/rib.h
index 70968d3900..a56bb05d68 100644
--- a/zebra/rib.h
+++ b/zebra/rib.h
@@ -180,7 +180,7 @@ struct route_entry {
* sub-queue 9: any other origin (if any) typically those that
* don't generate routes
*/
-#define MQ_SIZE 10
+#define MQ_SIZE 11
struct meta_queue {
struct list *subq[MQ_SIZE];
uint32_t size; /* sum of lengths of all subqueues */
@@ -323,6 +323,7 @@ enum rib_update_event {
RIB_UPDATE_OTHER,
RIB_UPDATE_MAX
};
+void rib_update_finish(void);
int route_entry_update_nhe(struct route_entry *re,
struct nhg_hash_entry *new_nhghe);
@@ -402,7 +403,7 @@ extern struct route_entry *rib_lookup_ipv4(struct prefix_ipv4 *p,
extern void rib_update(enum rib_update_event event);
extern void rib_update_table(struct route_table *table,
enum rib_update_event event, int rtype);
-extern void rib_sweep_route(struct thread *t);
+extern void rib_sweep_route(struct event *t);
extern void rib_sweep_table(struct route_table *table);
extern void rib_close_table(struct route_table *table);
extern void rib_init(void);
@@ -601,6 +602,12 @@ static inline struct nexthop_group *rib_get_fib_backup_nhg(
return &(re->fib_backup_ng);
}
+extern void zebra_gr_process_client(afi_t afi, vrf_id_t vrf_id, uint8_t proto,
+ uint8_t instance);
+
+extern int rib_add_gr_run(afi_t afi, vrf_id_t vrf_id, uint8_t proto,
+ uint8_t instance);
+
extern void zebra_vty_init(void);
extern pid_t pid;
diff --git a/zebra/router-id.c b/zebra/router-id.c
index e8cb33c35c..ef87d924fe 100644
--- a/zebra/router-id.c
+++ b/zebra/router-id.c
@@ -284,7 +284,7 @@ DEFUN (ip_router_id,
argv_find(argv, argc, "NAME", &idx);
VRF_GET_ID(vrf_id, argv[idx]->arg, false);
- zvrf = vrf_info_lookup(vrf_id);
+ zvrf = zebra_vrf_lookup_by_id(vrf_id);
router_id_set(AFI_IP, &rid, zvrf);
return CMD_SUCCESS;
@@ -321,7 +321,7 @@ DEFUN (ipv6_router_id,
argv_find(argv, argc, "NAME", &idx);
VRF_GET_ID(vrf_id, argv[idx]->arg, false);
- zvrf = vrf_info_lookup(vrf_id);
+ zvrf = zebra_vrf_lookup_by_id(vrf_id);
router_id_set(AFI_IP6, &rid, zvrf);
return CMD_SUCCESS;
@@ -403,7 +403,7 @@ DEFUN (no_ip_router_id,
if (argv_find(argv, argc, "NAME", &idx))
VRF_GET_ID(vrf_id, argv[idx]->arg, false);
- zvrf = vrf_info_lookup(vrf_id);
+ zvrf = zebra_vrf_lookup_by_id(vrf_id);
router_id_set(AFI_IP, &rid, zvrf);
return CMD_SUCCESS;
@@ -437,7 +437,7 @@ DEFUN (no_ipv6_router_id,
if (argv_find(argv, argc, "NAME", &idx))
VRF_GET_ID(vrf_id, argv[idx]->arg, false);
- zvrf = vrf_info_lookup(vrf_id);
+ zvrf = zebra_vrf_lookup_by_id(vrf_id);
router_id_set(AFI_IP6, &rid, zvrf);
return CMD_SUCCESS;
@@ -514,7 +514,7 @@ DEFUN (show_ip_router_id,
vrf_name = argv[idx]->arg;
}
- zvrf = vrf_info_lookup(vrf_id);
+ zvrf = zebra_vrf_lookup_by_id(vrf_id);
if (zvrf != NULL) {
if (is_ipv6) {
diff --git a/zebra/rt_netlink.c b/zebra/rt_netlink.c
index e4ddbd95d7..de01ced411 100644
--- a/zebra/rt_netlink.c
+++ b/zebra/rt_netlink.c
@@ -38,7 +38,7 @@
#include "table.h"
#include "memory.h"
#include "rib.h"
-#include "thread.h"
+#include "frrevent.h"
#include "privs.h"
#include "nexthop.h"
#include "vrf.h"
diff --git a/zebra/rtadv.c b/zebra/rtadv.c
index 1e0769fb6d..9af41cbc39 100644
--- a/zebra/rtadv.c
+++ b/zebra/rtadv.c
@@ -9,7 +9,7 @@
#include "memory.h"
#include "sockopt.h"
-#include "thread.h"
+#include "frrevent.h"
#include "if.h"
#include "stream.h"
#include "log.h"
@@ -475,9 +475,9 @@ no_more_opts:
zif->ra_sent++;
}
-static void rtadv_timer(struct thread *thread)
+static void rtadv_timer(struct event *thread)
{
- struct zebra_vrf *zvrf = THREAD_ARG(thread);
+ struct zebra_vrf *zvrf = EVENT_ARG(thread);
struct vrf *vrf;
struct interface *ifp;
struct zebra_if *zif;
@@ -817,7 +817,7 @@ static void rtadv_process_packet(uint8_t *buf, unsigned int len,
return;
}
-static void rtadv_read(struct thread *thread)
+static void rtadv_read(struct event *thread)
{
int sock;
int len;
@@ -825,9 +825,9 @@ static void rtadv_read(struct thread *thread)
struct sockaddr_in6 from;
ifindex_t ifindex = 0;
int hoplimit = -1;
- struct zebra_vrf *zvrf = THREAD_ARG(thread);
+ struct zebra_vrf *zvrf = EVENT_ARG(thread);
- sock = THREAD_FD(thread);
+ sock = EVENT_FD(thread);
zvrf->rtadv.ra_read = NULL;
/* Register myself. */
@@ -2800,26 +2800,26 @@ static void rtadv_event(struct zebra_vrf *zvrf, enum rtadv_event event, int val)
switch (event) {
case RTADV_START:
- thread_add_read(zrouter.master, rtadv_read, zvrf, rtadv->sock,
- &rtadv->ra_read);
- thread_add_event(zrouter.master, rtadv_timer, zvrf, 0,
- &rtadv->ra_timer);
+ event_add_read(zrouter.master, rtadv_read, zvrf, rtadv->sock,
+ &rtadv->ra_read);
+ event_add_event(zrouter.master, rtadv_timer, zvrf, 0,
+ &rtadv->ra_timer);
break;
case RTADV_STOP:
- THREAD_OFF(rtadv->ra_timer);
- THREAD_OFF(rtadv->ra_read);
+ EVENT_OFF(rtadv->ra_timer);
+ EVENT_OFF(rtadv->ra_read);
break;
case RTADV_TIMER:
- thread_add_timer(zrouter.master, rtadv_timer, zvrf, val,
- &rtadv->ra_timer);
+ event_add_timer(zrouter.master, rtadv_timer, zvrf, val,
+ &rtadv->ra_timer);
break;
case RTADV_TIMER_MSEC:
- thread_add_timer_msec(zrouter.master, rtadv_timer, zvrf, val,
- &rtadv->ra_timer);
+ event_add_timer_msec(zrouter.master, rtadv_timer, zvrf, val,
+ &rtadv->ra_timer);
break;
case RTADV_READ:
- thread_add_read(zrouter.master, rtadv_read, zvrf, rtadv->sock,
- &rtadv->ra_read);
+ event_add_read(zrouter.master, rtadv_read, zvrf, rtadv->sock,
+ &rtadv->ra_read);
break;
default:
break;
diff --git a/zebra/rtadv.h b/zebra/rtadv.h
index 2338efe0bd..1ec376a106 100644
--- a/zebra/rtadv.h
+++ b/zebra/rtadv.h
@@ -30,8 +30,8 @@ struct rtadv {
struct adv_if_list_head adv_if;
struct adv_if_list_head adv_msec_if;
- struct thread *ra_read;
- struct thread *ra_timer;
+ struct event *ra_read;
+ struct event *ra_timer;
};
PREDECL_RBTREE_UNIQ(rtadv_prefixes);
diff --git a/zebra/sample_plugin.c b/zebra/sample_plugin.c
index 0ccf736f24..b5f7b88375 100644
--- a/zebra/sample_plugin.c
+++ b/zebra/sample_plugin.c
@@ -76,7 +76,7 @@ static int sample_process(struct zebra_dplane_provider *prov)
* Init entry point called during zebra startup. This is registered during
* module init.
*/
-static int init_sample_plugin(struct thread_master *tm)
+static int init_sample_plugin(struct event_loop *tm)
{
int ret;
diff --git a/zebra/table_manager.h b/zebra/table_manager.h
index deed4fa30b..f8e99a357d 100644
--- a/zebra/table_manager.h
+++ b/zebra/table_manager.h
@@ -9,7 +9,7 @@
#include <stdint.h>
#include "lib/linklist.h"
-#include "lib/thread.h"
+#include "frrevent.h"
#include "lib/ns.h"
#include "zebra/zserv.h"
diff --git a/zebra/zapi_msg.c b/zebra/zapi_msg.c
index 1ff188c76d..4c6c336d41 100644
--- a/zebra/zapi_msg.c
+++ b/zebra/zapi_msg.c
@@ -1330,7 +1330,7 @@ static void zread_fec_register(ZAPI_HANDLER_ARGS)
uint32_t label_index = MPLS_INVALID_LABEL_INDEX;
s = msg;
- zvrf = vrf_info_lookup(VRF_DEFAULT);
+ zvrf = zebra_vrf_lookup_by_id(VRF_DEFAULT);
if (!zvrf)
return;
@@ -1393,7 +1393,7 @@ static void zread_fec_unregister(ZAPI_HANDLER_ARGS)
uint16_t flags;
s = msg;
- zvrf = vrf_info_lookup(VRF_DEFAULT);
+ zvrf = zebra_vrf_lookup_by_id(VRF_DEFAULT);
if (!zvrf)
return;
@@ -2337,7 +2337,7 @@ void zsend_capabilities_all_clients(void)
struct zebra_vrf *zvrf;
struct zserv *client;
- zvrf = vrf_info_lookup(VRF_DEFAULT);
+ zvrf = zebra_vrf_lookup_by_id(VRF_DEFAULT);
for (ALL_LIST_ELEMENTS(zrouter.client_list, node, nnode, client)) {
/* Do not send unsolicited messages to synchronous clients. */
if (client->synchronous)
diff --git a/zebra/zebra_dplane.c b/zebra/zebra_dplane.c
index af1dd6b5fd..f9253ebf76 100644
--- a/zebra/zebra_dplane.c
+++ b/zebra/zebra_dplane.c
@@ -476,10 +476,10 @@ struct dplane_zns_info {
struct zebra_dplane_info info;
/* Request data from the OS */
- struct thread *t_request;
+ struct event *t_request;
/* Read event */
- struct thread *t_read;
+ struct event *t_read;
/* List linkage */
struct zns_info_list_item link;
@@ -582,13 +582,13 @@ static struct zebra_dplane_globals {
struct frr_pthread *dg_pthread;
/* Event-delivery context 'master' for the dplane */
- struct thread_master *dg_master;
+ struct event_loop *dg_master;
/* Event/'thread' pointer for queued updates */
- struct thread *dg_t_update;
+ struct event *dg_t_update;
/* Event pointer for pending shutdown check loop */
- struct thread *dg_t_shutdown_check;
+ struct event *dg_t_shutdown_check;
} zdplane_info;
@@ -609,7 +609,7 @@ DECLARE_DLIST(zns_info_list, struct dplane_zns_info, link);
#define DPLANE_PROV_UNLOCK(p) pthread_mutex_unlock(&((p)->dp_mutex))
/* Prototypes */
-static void dplane_thread_loop(struct thread *event);
+static void dplane_thread_loop(struct event *event);
static enum zebra_dplane_result lsp_update_internal(struct zebra_lsp *lsp,
enum dplane_op_e op);
static enum zebra_dplane_result pw_update_internal(struct zebra_pw *pw,
@@ -633,7 +633,7 @@ neigh_update_internal(enum dplane_op_e op, const struct interface *ifp,
*/
/* Obtain thread_master for dataplane thread */
-struct thread_master *dplane_get_thread_master(void)
+struct event_loop *dplane_get_thread_master(void)
{
return zdplane_info.dg_master;
}
@@ -5773,28 +5773,28 @@ bool dplane_provider_is_threaded(const struct zebra_dplane_provider *prov)
* Callback when an OS (netlink) incoming event read is ready. This runs
* in the dplane pthread.
*/
-static void dplane_incoming_read(struct thread *event)
+static void dplane_incoming_read(struct event *event)
{
- struct dplane_zns_info *zi = THREAD_ARG(event);
+ struct dplane_zns_info *zi = EVENT_ARG(event);
kernel_dplane_read(&zi->info);
/* Re-start read task */
- thread_add_read(zdplane_info.dg_master, dplane_incoming_read, zi,
- zi->info.sock, &zi->t_read);
+ event_add_read(zdplane_info.dg_master, dplane_incoming_read, zi,
+ zi->info.sock, &zi->t_read);
}
/*
* Callback in the dataplane pthread that requests info from the OS and
* initiates netlink reads.
*/
-static void dplane_incoming_request(struct thread *event)
+static void dplane_incoming_request(struct event *event)
{
- struct dplane_zns_info *zi = THREAD_ARG(event);
+ struct dplane_zns_info *zi = EVENT_ARG(event);
/* Start read task */
- thread_add_read(zdplane_info.dg_master, dplane_incoming_read, zi,
- zi->info.sock, &zi->t_read);
+ event_add_read(zdplane_info.dg_master, dplane_incoming_read, zi,
+ zi->info.sock, &zi->t_read);
/* Send requests */
netlink_request_netconf(zi->info.sock);
@@ -5812,9 +5812,8 @@ static void dplane_kernel_info_request(struct dplane_zns_info *zi)
* pthread is running, we'll initiate this later on.
*/
if (zdplane_info.dg_master)
- thread_add_event(zdplane_info.dg_master,
- dplane_incoming_request, zi, 0,
- &zi->t_request);
+ event_add_event(zdplane_info.dg_master, dplane_incoming_request,
+ zi, 0, &zi->t_request);
}
#endif /* HAVE_NETLINK */
@@ -5875,11 +5874,11 @@ void zebra_dplane_ns_enable(struct zebra_ns *zns, bool enabled)
/* Stop any outstanding tasks */
if (zdplane_info.dg_master) {
- thread_cancel_async(zdplane_info.dg_master,
- &zi->t_request, NULL);
+ event_cancel_async(zdplane_info.dg_master,
+ &zi->t_request, NULL);
- thread_cancel_async(zdplane_info.dg_master, &zi->t_read,
- NULL);
+ event_cancel_async(zdplane_info.dg_master, &zi->t_read,
+ NULL);
}
XFREE(MTYPE_DP_NS, zi);
@@ -5898,9 +5897,8 @@ int dplane_provider_work_ready(void)
* available.
*/
if (zdplane_info.dg_run) {
- thread_add_event(zdplane_info.dg_master,
- dplane_thread_loop, NULL, 0,
- &zdplane_info.dg_t_update);
+ event_add_event(zdplane_info.dg_master, dplane_thread_loop,
+ NULL, 0, &zdplane_info.dg_t_update);
}
return AOK;
@@ -6597,7 +6595,7 @@ static bool dplane_work_pending(void)
* final zebra shutdown.
* This runs in the dplane pthread context.
*/
-static void dplane_check_shutdown_status(struct thread *event)
+static void dplane_check_shutdown_status(struct event *event)
{
struct dplane_zns_info *zi;
@@ -6609,8 +6607,8 @@ static void dplane_check_shutdown_status(struct thread *event)
zns_info_list_del(&zdplane_info.dg_zns_list, zi);
if (zdplane_info.dg_master) {
- THREAD_OFF(zi->t_read);
- THREAD_OFF(zi->t_request);
+ EVENT_OFF(zi->t_read);
+ EVENT_OFF(zi->t_request);
}
XFREE(MTYPE_DP_NS, zi);
@@ -6618,10 +6616,9 @@ static void dplane_check_shutdown_status(struct thread *event)
if (dplane_work_pending()) {
/* Reschedule dplane check on a short timer */
- thread_add_timer_msec(zdplane_info.dg_master,
- dplane_check_shutdown_status,
- NULL, 100,
- &zdplane_info.dg_t_shutdown_check);
+ event_add_timer_msec(zdplane_info.dg_master,
+ dplane_check_shutdown_status, NULL, 100,
+ &zdplane_info.dg_t_shutdown_check);
/* TODO - give up and stop waiting after a short time? */
@@ -6629,7 +6626,7 @@ static void dplane_check_shutdown_status(struct thread *event)
/* We appear to be done - schedule a final callback event
* for the zebra main pthread.
*/
- thread_add_event(zrouter.master, zebra_finalize, NULL, 0, NULL);
+ event_add_event(zrouter.master, zebra_finalize, NULL, 0, NULL);
}
}
@@ -6648,9 +6645,8 @@ void zebra_dplane_finish(void)
if (IS_ZEBRA_DEBUG_DPLANE)
zlog_debug("Zebra dataplane fini called");
- thread_add_event(zdplane_info.dg_master,
- dplane_check_shutdown_status, NULL, 0,
- &zdplane_info.dg_t_shutdown_check);
+ event_add_event(zdplane_info.dg_master, dplane_check_shutdown_status,
+ NULL, 0, &zdplane_info.dg_t_shutdown_check);
}
/*
@@ -6664,7 +6660,7 @@ void zebra_dplane_finish(void)
* pthread can look for other pending work - such as i/o work on behalf of
* providers.
*/
-static void dplane_thread_loop(struct thread *event)
+static void dplane_thread_loop(struct event *event)
{
struct dplane_ctx_list_head work_list;
struct dplane_ctx_list_head error_list;
@@ -6857,10 +6853,6 @@ void zebra_dplane_shutdown(void)
zdplane_info.dg_run = false;
- if (zdplane_info.dg_t_update)
- thread_cancel_async(zdplane_info.dg_t_update->master,
- &zdplane_info.dg_t_update, NULL);
-
frr_pthread_stop(zdplane_info.dg_pthread, NULL);
/* Destroy pthread */
@@ -6929,14 +6921,14 @@ void zebra_dplane_start(void)
zdplane_info.dg_run = true;
/* Enqueue an initial event for the dataplane pthread */
- thread_add_event(zdplane_info.dg_master, dplane_thread_loop, NULL, 0,
- &zdplane_info.dg_t_update);
+ event_add_event(zdplane_info.dg_master, dplane_thread_loop, NULL, 0,
+ &zdplane_info.dg_t_update);
/* Enqueue requests and reads if necessary */
frr_each (zns_info_list, &zdplane_info.dg_zns_list, zi) {
#if defined(HAVE_NETLINK)
- thread_add_read(zdplane_info.dg_master, dplane_incoming_read,
- zi, zi->info.sock, &zi->t_read);
+ event_add_read(zdplane_info.dg_master, dplane_incoming_read, zi,
+ zi->info.sock, &zi->t_read);
dplane_kernel_info_request(zi);
#endif
}
diff --git a/zebra/zebra_dplane.h b/zebra/zebra_dplane.h
index 3a4f3c2174..6716c0ffb6 100644
--- a/zebra/zebra_dplane.h
+++ b/zebra/zebra_dplane.h
@@ -1006,7 +1006,7 @@ void dplane_provider_lock(struct zebra_dplane_provider *prov);
void dplane_provider_unlock(struct zebra_dplane_provider *prov);
/* Obtain thread_master for dataplane thread */
-struct thread_master *dplane_get_thread_master(void);
+struct event_loop *dplane_get_thread_master(void);
/* Providers should (generally) limit number of updates per work cycle */
int dplane_provider_get_work_limit(const struct zebra_dplane_provider *prov);
diff --git a/zebra/zebra_evpn_mac.c b/zebra/zebra_evpn_mac.c
index a2d310a10b..ccc1b61e06 100644
--- a/zebra/zebra_evpn_mac.c
+++ b/zebra/zebra_evpn_mac.c
@@ -378,7 +378,7 @@ static char *zebra_evpn_zebra_mac_flag_dump(struct zebra_mac *mac, char *buf,
return buf;
}
-static void zebra_evpn_dad_mac_auto_recovery_exp(struct thread *t)
+static void zebra_evpn_dad_mac_auto_recovery_exp(struct event *t)
{
struct zebra_vrf *zvrf = NULL;
struct zebra_mac *mac = NULL;
@@ -386,10 +386,10 @@ static void zebra_evpn_dad_mac_auto_recovery_exp(struct thread *t)
struct listnode *node = NULL;
struct zebra_neigh *nbr = NULL;
- mac = THREAD_ARG(t);
+ mac = EVENT_ARG(t);
/* since this is asynchronous we need sanity checks*/
- zvrf = vrf_info_lookup(mac->zevpn->vrf_id);
+ zvrf = zebra_vrf_lookup_by_id(mac->zevpn->vrf_id);
if (!zvrf)
return;
@@ -575,7 +575,7 @@ static void zebra_evpn_dup_addr_detect_for_mac(struct zebra_vrf *zvrf,
}
/* Start auto recovery timer for this MAC */
- THREAD_OFF(mac->dad_mac_auto_recovery_timer);
+ EVENT_OFF(mac->dad_mac_auto_recovery_timer);
if (zvrf->dad_freeze && zvrf->dad_freeze_time) {
if (IS_ZEBRA_DEBUG_VXLAN) {
char mac_buf[MAC_BUF_SIZE];
@@ -588,10 +588,10 @@ static void zebra_evpn_dup_addr_detect_for_mac(struct zebra_vrf *zvrf,
zvrf->dad_freeze_time);
}
- thread_add_timer(zrouter.master,
- zebra_evpn_dad_mac_auto_recovery_exp,
- mac, zvrf->dad_freeze_time,
- &mac->dad_mac_auto_recovery_timer);
+ event_add_timer(zrouter.master,
+ zebra_evpn_dad_mac_auto_recovery_exp,
+ mac, zvrf->dad_freeze_time,
+ &mac->dad_mac_auto_recovery_timer);
}
/* In case of local update, do not inform to client (BGPd),
@@ -615,7 +615,7 @@ void zebra_evpn_print_mac(struct zebra_mac *mac, void *ctxt, json_object *json)
struct zebra_vrf *zvrf;
struct timeval detect_start_time = {0, 0};
char timebuf[MONOTIME_STRLEN];
- char thread_buf[THREAD_TIMER_STRLEN];
+ char thread_buf[EVENT_TIMER_STRLEN];
time_t uptime;
char up_str[MONOTIME_STRLEN];
@@ -692,9 +692,9 @@ void zebra_evpn_print_mac(struct zebra_mac *mac, void *ctxt, json_object *json)
if (mac->hold_timer)
json_object_string_add(
json_mac, "peerActiveHold",
- thread_timer_to_hhmmss(thread_buf,
- sizeof(thread_buf),
- mac->hold_timer));
+ event_timer_to_hhmmss(thread_buf,
+ sizeof(thread_buf),
+ mac->hold_timer));
if (mac->es)
json_object_string_add(json_mac, "esi",
mac->es->esi_str);
@@ -784,9 +784,9 @@ void zebra_evpn_print_mac(struct zebra_mac *mac, void *ctxt, json_object *json)
vty_out(vty, " peer-active");
if (mac->hold_timer)
vty_out(vty, " (ht: %s)",
- thread_timer_to_hhmmss(thread_buf,
- sizeof(thread_buf),
- mac->hold_timer));
+ event_timer_to_hhmmss(thread_buf,
+ sizeof(thread_buf),
+ mac->hold_timer));
vty_out(vty, "\n");
vty_out(vty, " Local Seq: %u Remote Seq: %u\n", mac->loc_seq,
mac->rem_seq);
@@ -1152,7 +1152,7 @@ int zebra_evpn_mac_del(struct zebra_evpn *zevpn, struct zebra_mac *mac)
zebra_evpn_mac_stop_hold_timer(mac);
/* Cancel auto recovery */
- THREAD_OFF(mac->dad_mac_auto_recovery_timer);
+ EVENT_OFF(mac->dad_mac_auto_recovery_timer);
/* If the MAC is freed before the neigh we will end up
* with a stale pointer against the neigh.
@@ -1500,7 +1500,7 @@ void zebra_evpn_mac_send_add_del_to_client(struct zebra_mac *mac,
* external neighmgr daemon to probe existing hosts to independently
* establish their presence on the ES.
*/
-static void zebra_evpn_mac_hold_exp_cb(struct thread *t)
+static void zebra_evpn_mac_hold_exp_cb(struct event *t)
{
struct zebra_mac *mac;
bool old_bgp_ready;
@@ -1508,7 +1508,7 @@ static void zebra_evpn_mac_hold_exp_cb(struct thread *t)
bool old_static;
bool new_static;
- mac = THREAD_ARG(t);
+ mac = EVENT_ARG(t);
/* the purpose of the hold timer is to age out the peer-active
* flag
*/
@@ -1561,8 +1561,8 @@ static inline void zebra_evpn_mac_start_hold_timer(struct zebra_mac *mac)
zebra_evpn_zebra_mac_flag_dump(mac, mac_buf,
sizeof(mac_buf)));
}
- thread_add_timer(zrouter.master, zebra_evpn_mac_hold_exp_cb, mac,
- zmh_info->mac_hold_time, &mac->hold_timer);
+ event_add_timer(zrouter.master, zebra_evpn_mac_hold_exp_cb, mac,
+ zmh_info->mac_hold_time, &mac->hold_timer);
}
void zebra_evpn_mac_stop_hold_timer(struct zebra_mac *mac)
@@ -1581,7 +1581,7 @@ void zebra_evpn_mac_stop_hold_timer(struct zebra_mac *mac)
sizeof(mac_buf)));
}
- THREAD_OFF(mac->hold_timer);
+ EVENT_OFF(mac->hold_timer);
}
void zebra_evpn_sync_mac_del(struct zebra_mac *mac)
diff --git a/zebra/zebra_evpn_mac.h b/zebra/zebra_evpn_mac.h
index befb1c398d..ba612f7696 100644
--- a/zebra/zebra_evpn_mac.h
+++ b/zebra/zebra_evpn_mac.h
@@ -114,14 +114,14 @@ struct zebra_mac {
/* Duplicate mac detection */
uint32_t dad_count;
- struct thread *dad_mac_auto_recovery_timer;
+ struct event *dad_mac_auto_recovery_timer;
struct timeval detect_start_time;
time_t dad_dup_detect_time;
/* used for ageing out the PEER_ACTIVE flag */
- struct thread *hold_timer;
+ struct event *hold_timer;
/* number of neigh entries (using this mac) that have
* ZEBRA_MAC_ES_PEER_ACTIVE or ZEBRA_NEIGH_ES_PEER_PROXY
diff --git a/zebra/zebra_evpn_mh.c b/zebra/zebra_evpn_mh.c
index 334dde3b10..bf488ca316 100644
--- a/zebra/zebra_evpn_mh.c
+++ b/zebra/zebra_evpn_mh.c
@@ -2201,11 +2201,11 @@ static void zebra_evpn_mh_advertise_svi_mac(void)
zebra_evpn_acc_vl_adv_svi_mac_all();
}
-static void zebra_evpn_es_df_delay_exp_cb(struct thread *t)
+static void zebra_evpn_es_df_delay_exp_cb(struct event *t)
{
struct zebra_evpn_es *es;
- es = THREAD_ARG(t);
+ es = EVENT_ARG(t);
if (IS_ZEBRA_DEBUG_EVPN_MH_ES)
zlog_debug("es %s df-delay expired", es->esi_str);
@@ -2269,9 +2269,9 @@ static void zebra_evpn_es_local_info_set(struct zebra_evpn_es *es,
/* Start the DF delay timer on the local ES */
if (!es->df_delay_timer)
- thread_add_timer(zrouter.master, zebra_evpn_es_df_delay_exp_cb,
- es, ZEBRA_EVPN_MH_DF_DELAY_TIME,
- &es->df_delay_timer);
+ event_add_timer(zrouter.master, zebra_evpn_es_df_delay_exp_cb,
+ es, ZEBRA_EVPN_MH_DF_DELAY_TIME,
+ &es->df_delay_timer);
/* See if the local VTEP can function as DF on the ES */
if (!zebra_evpn_es_run_df_election(es, __func__)) {
@@ -2314,7 +2314,7 @@ static void zebra_evpn_es_local_info_clear(struct zebra_evpn_es **esp)
es->flags &= ~(ZEBRA_EVPNES_LOCAL | ZEBRA_EVPNES_READY_FOR_BGP);
- THREAD_OFF(es->df_delay_timer);
+ EVENT_OFF(es->df_delay_timer);
/* clear EVPN protodown flags on the access port */
zebra_evpn_mh_clear_protodown_es(es);
@@ -3139,7 +3139,7 @@ static void zebra_evpn_es_show_entry_detail(struct vty *vty,
char alg_buf[EVPN_DF_ALG_STR_LEN];
struct zebra_evpn_es_vtep *es_vtep;
struct listnode *node;
- char thread_buf[THREAD_TIMER_STRLEN];
+ char thread_buf[EVENT_TIMER_STRLEN];
if (json) {
json_object *json_vteps;
@@ -3181,9 +3181,9 @@ static void zebra_evpn_es_show_entry_detail(struct vty *vty,
if (es->df_delay_timer)
json_object_string_add(
json, "dfDelayTimer",
- thread_timer_to_hhmmss(thread_buf,
- sizeof(thread_buf),
- es->df_delay_timer));
+ event_timer_to_hhmmss(thread_buf,
+ sizeof(thread_buf),
+ es->df_delay_timer));
json_object_int_add(json, "nexthopGroup", es->nhg_id);
if (listcount(es->es_vtep_list)) {
json_vteps = json_object_new_array();
@@ -3226,9 +3226,9 @@ static void zebra_evpn_es_show_entry_detail(struct vty *vty,
: "df");
if (es->df_delay_timer)
vty_out(vty, " DF delay: %s\n",
- thread_timer_to_hhmmss(thread_buf,
- sizeof(thread_buf),
- es->df_delay_timer));
+ event_timer_to_hhmmss(thread_buf,
+ sizeof(thread_buf),
+ es->df_delay_timer));
vty_out(vty, " DF preference: %u\n", es->df_pref);
vty_out(vty, " Nexthop group: %u\n", es->nhg_id);
vty_out(vty, " VTEPs:\n");
@@ -3522,15 +3522,15 @@ DEFPY(zebra_evpn_mh_uplink, zebra_evpn_mh_uplink_cmd, "[no] evpn mh uplink",
void zebra_evpn_mh_json(json_object *json)
{
json_object *json_array;
- char thread_buf[THREAD_TIMER_STRLEN];
+ char thread_buf[EVENT_TIMER_STRLEN];
json_object_int_add(json, "macHoldtime", zmh_info->mac_hold_time);
json_object_int_add(json, "neighHoldtime", zmh_info->neigh_hold_time);
json_object_int_add(json, "startupDelay", zmh_info->startup_delay_time);
json_object_string_add(
json, "startupDelayTimer",
- thread_timer_to_hhmmss(thread_buf, sizeof(thread_buf),
- zmh_info->startup_delay_timer));
+ event_timer_to_hhmmss(thread_buf, sizeof(thread_buf),
+ zmh_info->startup_delay_timer));
json_object_int_add(json, "uplinkConfigCount",
zmh_info->uplink_cfg_cnt);
json_object_int_add(json, "uplinkActiveCount",
@@ -3555,15 +3555,15 @@ void zebra_evpn_mh_json(json_object *json)
void zebra_evpn_mh_print(struct vty *vty)
{
char pd_buf[ZEBRA_PROTODOWN_RC_STR_LEN];
- char thread_buf[THREAD_TIMER_STRLEN];
+ char thread_buf[EVENT_TIMER_STRLEN];
vty_out(vty, "EVPN MH:\n");
vty_out(vty, " mac-holdtime: %ds, neigh-holdtime: %ds\n",
zmh_info->mac_hold_time, zmh_info->neigh_hold_time);
vty_out(vty, " startup-delay: %ds, start-delay-timer: %s\n",
zmh_info->startup_delay_time,
- thread_timer_to_hhmmss(thread_buf, sizeof(thread_buf),
- zmh_info->startup_delay_timer));
+ event_timer_to_hhmmss(thread_buf, sizeof(thread_buf),
+ zmh_info->startup_delay_timer));
vty_out(vty, " uplink-cfg-cnt: %u, uplink-active-cnt: %u\n",
zmh_info->uplink_cfg_cnt, zmh_info->uplink_oper_up_cnt);
if (zmh_info->protodown_rc)
@@ -3917,7 +3917,7 @@ void zebra_evpn_mh_uplink_oper_update(struct zebra_if *zif)
new_protodown);
}
-static void zebra_evpn_mh_startup_delay_exp_cb(struct thread *t)
+static void zebra_evpn_mh_startup_delay_exp_cb(struct event *t)
{
if (IS_ZEBRA_DEBUG_EVPN_MH_ES)
zlog_debug("startup-delay expired");
@@ -3931,7 +3931,7 @@ static void zebra_evpn_mh_startup_delay_timer_start(const char *rc)
if (zmh_info->startup_delay_timer) {
if (IS_ZEBRA_DEBUG_EVPN_MH_ES)
zlog_debug("startup-delay timer cancelled");
- THREAD_OFF(zmh_info->startup_delay_timer);
+ EVENT_OFF(zmh_info->startup_delay_timer);
}
if (zmh_info->startup_delay_time) {
@@ -3939,10 +3939,10 @@ static void zebra_evpn_mh_startup_delay_timer_start(const char *rc)
zlog_debug(
"startup-delay timer started for %d sec on %s",
zmh_info->startup_delay_time, rc);
- thread_add_timer(zrouter.master,
- zebra_evpn_mh_startup_delay_exp_cb, NULL,
- zmh_info->startup_delay_time,
- &zmh_info->startup_delay_timer);
+ event_add_timer(zrouter.master,
+ zebra_evpn_mh_startup_delay_exp_cb, NULL,
+ zmh_info->startup_delay_time,
+ &zmh_info->startup_delay_timer);
zebra_evpn_mh_update_protodown(
ZEBRA_PROTODOWN_EVPN_STARTUP_DELAY, true /* set */);
} else {
diff --git a/zebra/zebra_evpn_mh.h b/zebra/zebra_evpn_mh.h
index 89a917628d..6dda30a57f 100644
--- a/zebra/zebra_evpn_mh.h
+++ b/zebra/zebra_evpn_mh.h
@@ -87,7 +87,7 @@ struct zebra_evpn_es {
* imported before running the DF election.
*/
#define ZEBRA_EVPN_MH_DF_DELAY_TIME 3 /* seconds */
- struct thread *df_delay_timer;
+ struct event *df_delay_timer;
};
RB_HEAD(zebra_es_rb_head, zebra_evpn_es);
RB_PROTOTYPE(zebra_es_rb_head, zebra_evpn_es, rb_node, zebra_es_rb_cmp);
@@ -248,7 +248,7 @@ struct zebra_evpn_mh_info {
*/
int startup_delay_time; /* seconds */
#define ZEBRA_EVPN_MH_STARTUP_DELAY_DEF (3 * 60)
- struct thread *startup_delay_timer;
+ struct event *startup_delay_timer;
/* Number of configured uplinks */
uint32_t uplink_cfg_cnt;
diff --git a/zebra/zebra_evpn_neigh.c b/zebra/zebra_evpn_neigh.c
index acd60aa08f..74141e4f34 100644
--- a/zebra/zebra_evpn_neigh.c
+++ b/zebra/zebra_evpn_neigh.c
@@ -397,7 +397,7 @@ void zebra_evpn_sync_neigh_static_chg(struct zebra_neigh *n, bool old_n_static,
* external neighmgr daemon to probe existing hosts to independently
* establish their presence on the ES.
*/
-static void zebra_evpn_neigh_hold_exp_cb(struct thread *t)
+static void zebra_evpn_neigh_hold_exp_cb(struct event *t)
{
struct zebra_neigh *n;
bool old_bgp_ready;
@@ -405,7 +405,7 @@ static void zebra_evpn_neigh_hold_exp_cb(struct thread *t)
bool old_n_static;
bool new_n_static;
- n = THREAD_ARG(t);
+ n = EVENT_ARG(t);
/* the purpose of the hold timer is to age out the peer-active
* flag
*/
@@ -444,8 +444,8 @@ static inline void zebra_evpn_neigh_start_hold_timer(struct zebra_neigh *n)
if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH)
zlog_debug("sync-neigh vni %u ip %pIA mac %pEA 0x%x hold start",
n->zevpn->vni, &n->ip, &n->emac, n->flags);
- thread_add_timer(zrouter.master, zebra_evpn_neigh_hold_exp_cb, n,
- zmh_info->neigh_hold_time, &n->hold_timer);
+ event_add_timer(zrouter.master, zebra_evpn_neigh_hold_exp_cb, n,
+ zmh_info->neigh_hold_time, &n->hold_timer);
}
static void zebra_evpn_local_neigh_deref_mac(struct zebra_neigh *n,
@@ -576,7 +576,7 @@ int zebra_evpn_neigh_del(struct zebra_evpn *zevpn, struct zebra_neigh *n)
listnode_delete(n->mac->neigh_list, n);
/* Cancel auto recovery */
- THREAD_OFF(n->dad_ip_auto_recovery_timer);
+ EVENT_OFF(n->dad_ip_auto_recovery_timer);
/* Cancel proxy hold timer */
zebra_evpn_neigh_stop_hold_timer(n);
@@ -1080,13 +1080,13 @@ static int zebra_evpn_ip_inherit_dad_from_mac(struct zebra_vrf *zvrf,
return 0;
}
-static void zebra_evpn_dad_ip_auto_recovery_exp(struct thread *t)
+static void zebra_evpn_dad_ip_auto_recovery_exp(struct event *t)
{
struct zebra_vrf *zvrf = NULL;
struct zebra_neigh *nbr = NULL;
struct zebra_evpn *zevpn = NULL;
- nbr = THREAD_ARG(t);
+ nbr = EVENT_ARG(t);
/* since this is asynchronous we need sanity checks*/
zvrf = vrf_info_lookup(nbr->zevpn->vrf_id);
@@ -1223,7 +1223,7 @@ static void zebra_evpn_dup_addr_detect_for_neigh(
nbr->dad_dup_detect_time = monotime(NULL);
/* Start auto recovery timer for this IP */
- THREAD_OFF(nbr->dad_ip_auto_recovery_timer);
+ EVENT_OFF(nbr->dad_ip_auto_recovery_timer);
if (zvrf->dad_freeze && zvrf->dad_freeze_time) {
if (IS_ZEBRA_DEBUG_VXLAN)
zlog_debug(
@@ -1231,10 +1231,10 @@ static void zebra_evpn_dup_addr_detect_for_neigh(
__func__, &nbr->emac, &nbr->ip,
nbr->flags, zvrf->dad_freeze_time);
- thread_add_timer(zrouter.master,
- zebra_evpn_dad_ip_auto_recovery_exp,
- nbr, zvrf->dad_freeze_time,
- &nbr->dad_ip_auto_recovery_timer);
+ event_add_timer(zrouter.master,
+ zebra_evpn_dad_ip_auto_recovery_exp,
+ nbr, zvrf->dad_freeze_time,
+ &nbr->dad_ip_auto_recovery_timer);
}
if (zvrf->dad_freeze)
*is_dup_detect = true;
@@ -1680,7 +1680,7 @@ void zebra_evpn_clear_dup_neigh_hash(struct hash_bucket *bucket, void *ctxt)
nbr->detect_start_time.tv_sec = 0;
nbr->detect_start_time.tv_usec = 0;
nbr->dad_dup_detect_time = 0;
- THREAD_OFF(nbr->dad_ip_auto_recovery_timer);
+ EVENT_OFF(nbr->dad_ip_auto_recovery_timer);
if (CHECK_FLAG(nbr->flags, ZEBRA_NEIGH_LOCAL)) {
zebra_evpn_neigh_send_add_to_client(zevpn->vni, &nbr->ip,
@@ -1706,7 +1706,7 @@ void zebra_evpn_print_neigh(struct zebra_neigh *n, void *ctxt,
struct zebra_vrf *zvrf = NULL;
struct timeval detect_start_time = {0, 0};
char timebuf[MONOTIME_STRLEN];
- char thread_buf[THREAD_TIMER_STRLEN];
+ char thread_buf[EVENT_TIMER_STRLEN];
time_t uptime;
char up_str[MONOTIME_STRLEN];
@@ -1746,9 +1746,9 @@ void zebra_evpn_print_neigh(struct zebra_neigh *n, void *ctxt,
}
if (n->hold_timer) {
vty_out(vty, " (ht: %s)",
- thread_timer_to_hhmmss(thread_buf,
- sizeof(thread_buf),
- n->hold_timer));
+ event_timer_to_hhmmss(thread_buf,
+ sizeof(thread_buf),
+ n->hold_timer));
sync_info = true;
}
if (!sync_info)
@@ -1769,9 +1769,9 @@ void zebra_evpn_print_neigh(struct zebra_neigh *n, void *ctxt,
if (n->hold_timer)
json_object_string_add(
json, "peerActiveHold",
- thread_timer_to_hhmmss(thread_buf,
- sizeof(thread_buf),
- n->hold_timer));
+ event_timer_to_hhmmss(thread_buf,
+ sizeof(thread_buf),
+ n->hold_timer));
}
if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_REMOTE)) {
if (n->mac->es) {
diff --git a/zebra/zebra_evpn_neigh.h b/zebra/zebra_evpn_neigh.h
index 18ef8546de..c82b3673b1 100644
--- a/zebra/zebra_evpn_neigh.h
+++ b/zebra/zebra_evpn_neigh.h
@@ -92,7 +92,7 @@ struct zebra_neigh {
/* Duplicate ip detection */
uint32_t dad_count;
- struct thread *dad_ip_auto_recovery_timer;
+ struct event *dad_ip_auto_recovery_timer;
struct timeval detect_start_time;
@@ -101,7 +101,7 @@ struct zebra_neigh {
time_t uptime;
/* used for ageing out the PEER_ACTIVE flag */
- struct thread *hold_timer;
+ struct event *hold_timer;
};
/*
@@ -158,7 +158,7 @@ static inline void zebra_evpn_neigh_stop_hold_timer(struct zebra_neigh *n)
if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH)
zlog_debug("sync-neigh vni %u ip %pIA mac %pEA 0x%x hold stop",
n->zevpn->vni, &n->ip, &n->emac, n->flags);
- THREAD_OFF(n->hold_timer);
+ EVENT_OFF(n->hold_timer);
}
void zebra_evpn_sync_neigh_static_chg(struct zebra_neigh *n, bool old_n_static,
diff --git a/zebra/zebra_fpm.c b/zebra/zebra_fpm.c
index 15765b5e18..e379a5868c 100644
--- a/zebra/zebra_fpm.c
+++ b/zebra/zebra_fpm.c
@@ -11,7 +11,7 @@
#include "log.h"
#include "libfrr.h"
#include "stream.h"
-#include "thread.h"
+#include "frrevent.h"
#include "network.h"
#include "command.h"
#include "lib/version.h"
@@ -156,7 +156,7 @@ struct zfpm_glob {
*/
enum zfpm_msg_format message_format;
- struct thread_master *master;
+ struct event_loop *master;
enum zfpm_state state;
@@ -204,15 +204,15 @@ struct zfpm_glob {
/*
* Threads for I/O.
*/
- struct thread *t_connect;
- struct thread *t_write;
- struct thread *t_read;
+ struct event *t_connect;
+ struct event *t_write;
+ struct event *t_read;
/*
* Thread to clean up after the TCP connection to the FPM goes down
* and the state that belongs to it.
*/
- struct thread *t_conn_down;
+ struct event *t_conn_down;
struct {
struct zfpm_rnodes_iter iter;
@@ -222,7 +222,7 @@ struct zfpm_glob {
* Thread to take actions once the TCP conn to the FPM comes up, and
* the state that belongs to it.
*/
- struct thread *t_conn_up;
+ struct event *t_conn_up;
struct {
struct zfpm_rnodes_iter iter;
@@ -251,7 +251,7 @@ struct zfpm_glob {
/*
* Stats interval timer.
*/
- struct thread *t_stats;
+ struct event *t_stats;
/*
* If non-zero, the last time when statistics were cleared.
@@ -269,8 +269,8 @@ static struct zfpm_glob *zfpm_g = &zfpm_glob_space;
static int zfpm_trigger_update(struct route_node *rn, const char *reason);
-static void zfpm_read_cb(struct thread *thread);
-static void zfpm_write_cb(struct thread *thread);
+static void zfpm_read_cb(struct event *thread);
+static void zfpm_write_cb(struct event *thread);
static void zfpm_set_state(enum zfpm_state state, const char *reason);
static void zfpm_start_connect_timer(const char *reason);
@@ -283,9 +283,9 @@ union g_addr ipv4ll_gateway;
/*
* zfpm_thread_should_yield
*/
-static inline int zfpm_thread_should_yield(struct thread *t)
+static inline int zfpm_thread_should_yield(struct event *t)
{
- return thread_should_yield(t);
+ return event_should_yield(t);
}
/*
@@ -460,8 +460,8 @@ static inline void zfpm_read_on(void)
assert(!zfpm_g->t_read);
assert(zfpm_g->sock >= 0);
- thread_add_read(zfpm_g->master, zfpm_read_cb, 0, zfpm_g->sock,
- &zfpm_g->t_read);
+ event_add_read(zfpm_g->master, zfpm_read_cb, 0, zfpm_g->sock,
+ &zfpm_g->t_read);
}
/*
@@ -472,8 +472,8 @@ static inline void zfpm_write_on(void)
assert(!zfpm_g->t_write);
assert(zfpm_g->sock >= 0);
- thread_add_write(zfpm_g->master, zfpm_write_cb, 0, zfpm_g->sock,
- &zfpm_g->t_write);
+ event_add_write(zfpm_g->master, zfpm_write_cb, 0, zfpm_g->sock,
+ &zfpm_g->t_write);
}
/*
@@ -481,7 +481,7 @@ static inline void zfpm_write_on(void)
*/
static inline void zfpm_read_off(void)
{
- THREAD_OFF(zfpm_g->t_read);
+ EVENT_OFF(zfpm_g->t_read);
}
/*
@@ -489,12 +489,12 @@ static inline void zfpm_read_off(void)
*/
static inline void zfpm_write_off(void)
{
- THREAD_OFF(zfpm_g->t_write);
+ EVENT_OFF(zfpm_g->t_write);
}
static inline void zfpm_connect_off(void)
{
- THREAD_OFF(zfpm_g->t_connect);
+ EVENT_OFF(zfpm_g->t_connect);
}
/*
@@ -503,7 +503,7 @@ static inline void zfpm_connect_off(void)
* Callback for actions to be taken when the connection to the FPM
* comes up.
*/
-static void zfpm_conn_up_thread_cb(struct thread *thread)
+static void zfpm_conn_up_thread_cb(struct event *thread)
{
struct route_node *rnode;
struct zfpm_rnodes_iter *iter;
@@ -542,8 +542,8 @@ static void zfpm_conn_up_thread_cb(struct thread *thread)
zfpm_g->stats.t_conn_up_yields++;
zfpm_rnodes_iter_pause(iter);
- thread_add_timer_msec(zfpm_g->master, zfpm_conn_up_thread_cb,
- NULL, 0, &zfpm_g->t_conn_up);
+ event_add_timer_msec(zfpm_g->master, zfpm_conn_up_thread_cb,
+ NULL, 0, &zfpm_g->t_conn_up);
return;
}
@@ -568,15 +568,15 @@ static void zfpm_connection_up(const char *detail)
/*
* Start thread to push existing routes to the FPM.
*/
- THREAD_OFF(zfpm_g->t_conn_up);
+ EVENT_OFF(zfpm_g->t_conn_up);
zfpm_rnodes_iter_init(&zfpm_g->t_conn_up_state.iter);
zfpm_g->fpm_mac_dump_done = false;
zfpm_debug("Starting conn_up thread");
- thread_add_timer_msec(zfpm_g->master, zfpm_conn_up_thread_cb, NULL, 0,
- &zfpm_g->t_conn_up);
+ event_add_timer_msec(zfpm_g->master, zfpm_conn_up_thread_cb, NULL, 0,
+ &zfpm_g->t_conn_up);
zfpm_g->stats.t_conn_up_starts++;
}
@@ -619,7 +619,7 @@ static void zfpm_connect_check(void)
* Callback that is invoked to clean up state after the TCP connection
* to the FPM goes down.
*/
-static void zfpm_conn_down_thread_cb(struct thread *thread)
+static void zfpm_conn_down_thread_cb(struct event *thread)
{
struct route_node *rnode;
struct zfpm_rnodes_iter *iter;
@@ -668,8 +668,8 @@ static void zfpm_conn_down_thread_cb(struct thread *thread)
zfpm_g->stats.t_conn_down_yields++;
zfpm_rnodes_iter_pause(iter);
zfpm_g->t_conn_down = NULL;
- thread_add_timer_msec(zfpm_g->master, zfpm_conn_down_thread_cb,
- NULL, 0, &zfpm_g->t_conn_down);
+ event_add_timer_msec(zfpm_g->master, zfpm_conn_down_thread_cb,
+ NULL, 0, &zfpm_g->t_conn_down);
return;
}
@@ -713,8 +713,8 @@ static void zfpm_connection_down(const char *detail)
assert(!zfpm_g->t_conn_down);
zfpm_rnodes_iter_init(&zfpm_g->t_conn_down_state.iter);
zfpm_g->t_conn_down = NULL;
- thread_add_timer_msec(zfpm_g->master, zfpm_conn_down_thread_cb, NULL, 0,
- &zfpm_g->t_conn_down);
+ event_add_timer_msec(zfpm_g->master, zfpm_conn_down_thread_cb, NULL, 0,
+ &zfpm_g->t_conn_down);
zfpm_g->stats.t_conn_down_starts++;
zfpm_set_state(ZFPM_STATE_IDLE, detail);
@@ -723,7 +723,7 @@ static void zfpm_connection_down(const char *detail)
/*
* zfpm_read_cb
*/
-static void zfpm_read_cb(struct thread *thread)
+static void zfpm_read_cb(struct event *thread)
{
size_t already;
struct stream *ibuf;
@@ -1152,7 +1152,7 @@ static void zfpm_build_updates(void)
/*
* zfpm_write_cb
*/
-static void zfpm_write_cb(struct thread *thread)
+static void zfpm_write_cb(struct event *thread)
{
struct stream *s;
int num_writes;
@@ -1234,7 +1234,7 @@ static void zfpm_write_cb(struct thread *thread)
/*
* zfpm_connect_cb
*/
-static void zfpm_connect_cb(struct thread *t)
+static void zfpm_connect_cb(struct event *t)
{
int sock, ret;
struct sockaddr_in serv;
@@ -1388,8 +1388,8 @@ static void zfpm_start_connect_timer(const char *reason)
delay_secs = zfpm_calc_connect_delay();
zfpm_debug("scheduling connect in %ld seconds", delay_secs);
- thread_add_timer(zfpm_g->master, zfpm_connect_cb, 0, delay_secs,
- &zfpm_g->t_connect);
+ event_add_timer(zfpm_g->master, zfpm_connect_cb, 0, delay_secs,
+ &zfpm_g->t_connect);
zfpm_set_state(ZFPM_STATE_ACTIVE, reason);
}
@@ -1664,7 +1664,7 @@ static void zfpm_iterate_rmac_table(struct hash_bucket *bucket, void *args)
/*
* struct zfpm_statsimer_cb
*/
-static void zfpm_stats_timer_cb(struct thread *t)
+static void zfpm_stats_timer_cb(struct event *t)
{
zfpm_g->t_stats = NULL;
@@ -1697,7 +1697,7 @@ static void zfpm_stop_stats_timer(void)
return;
zfpm_debug("Stopping existing stats timer");
- THREAD_OFF(zfpm_g->t_stats);
+ EVENT_OFF(zfpm_g->t_stats);
}
/*
@@ -1707,8 +1707,8 @@ void zfpm_start_stats_timer(void)
{
assert(!zfpm_g->t_stats);
- thread_add_timer(zfpm_g->master, zfpm_stats_timer_cb, 0,
- ZFPM_STATS_IVL_SECS, &zfpm_g->t_stats);
+ event_add_timer(zfpm_g->master, zfpm_stats_timer_cb, 0,
+ ZFPM_STATS_IVL_SECS, &zfpm_g->t_stats);
}
/*
@@ -1978,7 +1978,7 @@ static struct cmd_node zebra_node = {
*
* Returns true on success.
*/
-static int zfpm_init(struct thread_master *master)
+static int zfpm_init(struct event_loop *master)
{
int enable = 1;
uint16_t port = 0;
diff --git a/zebra/zebra_gr.c b/zebra/zebra_gr.c
index 3bd5b51fbc..cf2056b7ac 100644
--- a/zebra/zebra_gr.c
+++ b/zebra/zebra_gr.c
@@ -13,7 +13,7 @@
#include "lib/prefix.h"
#include "lib/command.h"
#include "lib/if.h"
-#include "lib/thread.h"
+#include "frrevent.h"
#include "lib/stream.h"
#include "lib/memory.h"
#include "lib/table.h"
@@ -39,11 +39,11 @@ DEFINE_MTYPE_STATIC(ZEBRA, ZEBRA_GR, "GR");
* Forward declaration.
*/
static struct zserv *zebra_gr_find_stale_client(struct zserv *client);
-static void zebra_gr_route_stale_delete_timer_expiry(struct thread *thread);
+static void zebra_gr_route_stale_delete_timer_expiry(struct event *thread);
static int32_t zebra_gr_delete_stale_routes(struct client_gr_info *info);
static void zebra_gr_process_client_stale_routes(struct zserv *client,
- vrf_id_t vrf_id);
-
+ struct client_gr_info *info);
+static void zebra_gr_delete_stale_route_table_afi(struct event *event);
/*
* Debug macros.
*/
@@ -53,7 +53,6 @@ static void zebra_gr_process_client_stale_routes(struct zserv *client,
zlog_debug(msg, ##__VA_ARGS__); \
} while (0)
-
/*
* Client connection functions
*/
@@ -80,13 +79,14 @@ void zebra_gr_stale_client_cleanup(struct list *client_list)
/* Cancel the stale timer */
if (info->t_stale_removal != NULL) {
- THREAD_OFF(info->t_stale_removal);
+ EVENT_OFF(info->t_stale_removal);
info->t_stale_removal = NULL;
+ info->do_delete = true;
/* Process the stale routes */
- thread_execute(
- zrouter.master,
- zebra_gr_route_stale_delete_timer_expiry,
- info, 1);
+ event_execute(
+ zrouter.master,
+ zebra_gr_route_stale_delete_timer_expiry,
+ info, 0);
}
}
}
@@ -101,6 +101,8 @@ static struct client_gr_info *zebra_gr_client_info_create(struct zserv *client)
info = XCALLOC(MTYPE_ZEBRA_GR, sizeof(struct client_gr_info));
+ info->stale_client_ptr = client;
+
TAILQ_INSERT_TAIL(&(client->gr_info_queue), info, gr_info);
return info;
}
@@ -108,17 +110,18 @@ static struct client_gr_info *zebra_gr_client_info_create(struct zserv *client)
/*
* A helper function to delete and destroy client info.
*/
-static void zebra_gr_client_info_delte(struct zserv *client,
- struct client_gr_info *info)
+static void zebra_gr_client_info_delete(struct zserv *client,
+ struct client_gr_info *info)
{
- TAILQ_REMOVE(&(client->gr_info_queue), info, gr_info);
+ struct vrf *vrf = vrf_lookup_by_id(info->vrf_id);
- THREAD_OFF(info->t_stale_removal);
+ TAILQ_REMOVE(&(client->gr_info_queue), info, gr_info);
- XFREE(MTYPE_ZEBRA_GR, info->current_prefix);
+ EVENT_OFF(info->t_stale_removal);
- LOG_GR("%s: Instance info is being deleted for client %s", __func__,
- zebra_route_string(client->proto));
+ LOG_GR("%s: Instance info is being deleted for client %s vrf %s(%u)",
+ __func__, zebra_route_string(client->proto), VRF_LOGNAME(vrf),
+ info->vrf_id);
/* Delete all the stale routes. */
info->do_delete = true;
@@ -154,16 +157,18 @@ int32_t zebra_gr_client_disconnect(struct zserv *client)
TAILQ_FOREACH (info, &client->gr_info_queue, gr_info) {
if (ZEBRA_CLIENT_GR_ENABLED(info->capabilities)
&& (info->t_stale_removal == NULL)) {
- thread_add_timer(
+ struct vrf *vrf = vrf_lookup_by_id(info->vrf_id);
+
+ event_add_timer(
zrouter.master,
zebra_gr_route_stale_delete_timer_expiry, info,
info->stale_removal_time,
&info->t_stale_removal);
- info->current_afi = AFI_IP;
info->stale_client_ptr = client;
info->stale_client = true;
- LOG_GR("%s: Client %s Stale timer update to %d",
+ LOG_GR("%s: Client %s vrf %s(%u) Stale timer update to %d",
__func__, zebra_route_string(client->proto),
+ VRF_LOGNAME(vrf), info->vrf_id,
info->stale_removal_time);
}
}
@@ -180,6 +185,7 @@ static void zebra_gr_delete_stale_client(struct client_gr_info *info)
{
struct client_gr_info *bgp_info;
struct zserv *s_client = NULL;
+ struct vrf *vrf = vrf_lookup_by_id(info->vrf_id);
s_client = info->stale_client_ptr;
@@ -204,8 +210,9 @@ static void zebra_gr_delete_stale_client(struct client_gr_info *info)
return;
}
- LOG_GR("%s: Client %s is being deleted", __func__,
- zebra_route_string(s_client->proto));
+ LOG_GR("%s: Client %s vrf %s(%u) is being deleted", __func__,
+ zebra_route_string(s_client->proto), VRF_LOGNAME(vrf),
+ info->vrf_id);
TAILQ_INIT(&(s_client->gr_info_queue));
listnode_delete(zrouter.stale_client_list, s_client);
@@ -279,31 +286,65 @@ void zebra_gr_client_reconnect(struct zserv *client)
zserv_client_delete(old_client);
}
+struct zebra_gr_afi_clean {
+ struct client_gr_info *info;
+ afi_t afi;
+ uint8_t proto;
+ uint8_t instance;
+
+ struct event *t_gac;
+};
+
/*
* Functions to deal with capabilities
*/
/*
- * Update the graceful restart information
- * for the client instance.
- * This function handles all the capabilities that are received.
+ * Function to decode and call appropriate functions
+ * to handle client capabilities.
*/
-static void zebra_client_update_info(struct zserv *client, struct zapi_cap *api)
+void zread_client_capabilities(ZAPI_HANDLER_ARGS)
{
+ struct zapi_cap api;
struct client_gr_info *info = NULL;
+ struct stream *s;
+ struct vrf *vrf;
+
+ s = msg;
+
+ if (zapi_capabilities_decode(s, &api)) {
+ LOG_GR("%s: Error in reading capabilities for client %s",
+ __func__, zebra_route_string(client->proto));
+ return;
+ }
+
+ vrf = vrf_lookup_by_id(api.vrf_id);
+
+ /*
+ * If this ever matters uncomment and add safi to the
+ * arrays as needed to track
+ */
+ if (api.safi != SAFI_UNICAST)
+ return;
+
+ /* GR only for dynamic clients */
+ if (client->proto <= ZEBRA_ROUTE_CONNECT) {
+ LOG_GR("%s: GR capabilities for client %s not supported",
+ __func__, zebra_route_string(client->proto));
+ return;
+ }
/* Find the bgp information for the specified vrf id */
TAILQ_FOREACH (info, &client->gr_info_queue, gr_info) {
- if (info->vrf_id == api->vrf_id)
+ if (info->vrf_id == api.vrf_id)
break;
}
-
/*
* If the command is delete, then cancel the stale timer and
* delete the bgp info
*/
- switch (api->cap) {
+ switch (api.cap) {
case ZEBRA_CLIENT_GR_DISABLE:
if (!info)
return;
@@ -315,7 +356,7 @@ static void zebra_client_update_info(struct zserv *client, struct zapi_cap *api)
if ((info->gr_enable) && (client->gr_instance_count > 0))
client->gr_instance_count--;
- zebra_gr_client_info_delte(client, info);
+ zebra_gr_client_info_delete(client, info);
break;
case ZEBRA_CLIENT_GR_CAPABILITIES:
/* Allocate bgp info */
@@ -326,13 +367,14 @@ static void zebra_client_update_info(struct zserv *client, struct zapi_cap *api)
if (!info->gr_enable) {
client->gr_instance_count++;
- LOG_GR("%s: Cient %s GR enabled count %d", __func__,
- zebra_route_string(client->proto),
+ LOG_GR("%s: Cient %s vrf %s(%u) GR enabled count %d",
+ __func__, zebra_route_string(client->proto),
+ VRF_LOGNAME(vrf), api.vrf_id,
client->gr_instance_count);
- info->capabilities = api->cap;
- info->stale_removal_time = api->stale_removal_time;
- info->vrf_id = api->vrf_id;
+ info->capabilities = api.cap;
+ info->stale_removal_time = api.stale_removal_time;
+ info->vrf_id = api.vrf_id;
info->gr_enable = true;
}
break;
@@ -343,87 +385,52 @@ static void zebra_client_update_info(struct zserv *client, struct zapi_cap *api)
/* Update the stale removal timer */
if (info && info->t_stale_removal == NULL) {
- LOG_GR("%s: Stale time: %d is now update to: %d",
- __func__, info->stale_removal_time,
- api->stale_removal_time);
+ LOG_GR("%s: vrf %s(%u) Stale time: %d is now update to: %d",
+ __func__, VRF_LOGNAME(vrf), info->vrf_id,
+ info->stale_removal_time,
+ api.stale_removal_time);
- info->stale_removal_time = api->stale_removal_time;
+ info->stale_removal_time = api.stale_removal_time;
}
break;
case ZEBRA_CLIENT_ROUTE_UPDATE_COMPLETE:
- LOG_GR(
- "%s: Client %s route update complete for AFI %d, SAFI %d",
- __func__, zebra_route_string(client->proto), api->afi,
- api->safi);
- if (info)
- info->route_sync[api->afi][api->safi] = true;
- break;
- case ZEBRA_CLIENT_ROUTE_UPDATE_PENDING:
- LOG_GR("%s: Client %s route update pending for AFI %d, SAFI %d",
- __func__, zebra_route_string(client->proto), api->afi,
- api->safi);
- if (info)
- info->af_enabled[api->afi][api->safi] = true;
- break;
- }
-}
+ if (!info) {
+ LOG_GR("%s: Client %s route update complete for AFI %d, SAFI %d, no Graceful Restart communication, returning",
+ __func__, zebra_route_string(client->proto),
+ api.afi, api.safi);
+ return;
+ }
+
+ LOG_GR("%s: Client %s vrf %s(%u) route update complete for AFI %d, SAFI %d",
+ __func__, zebra_route_string(client->proto),
+ VRF_LOGNAME(vrf), info->vrf_id, api.afi, api.safi);
+ info->route_sync[api.afi] = true;
-/*
- * Handler for capabilities that are received from client.
- */
-static void zebra_client_capabilities_handler(struct zserv *client,
- struct zapi_cap *api)
-{
- switch (api->cap) {
- case ZEBRA_CLIENT_GR_CAPABILITIES:
- case ZEBRA_CLIENT_ROUTE_UPDATE_PENDING:
- case ZEBRA_CLIENT_GR_DISABLE:
- case ZEBRA_CLIENT_RIB_STALE_TIME:
- /*
- * For all the cases we need to update the client info.
- */
- zebra_client_update_info(client, api);
- break;
- case ZEBRA_CLIENT_ROUTE_UPDATE_COMPLETE:
/*
- * After client info has been updated delete all
- * stale routes
+ * Schedule for after anything already in the meta Q
*/
- zebra_client_update_info(client, api);
- zebra_gr_process_client_stale_routes(client, api->vrf_id);
+ rib_add_gr_run(api.afi, api.vrf_id, client->proto,
+ client->instance);
+ zebra_gr_process_client_stale_routes(client, info);
break;
- }
-}
-
-/*
- * Function to decode and call appropriate functions
- * to handle client capabilities.
- */
-void zread_client_capabilities(ZAPI_HANDLER_ARGS)
-{
- struct zapi_cap api;
- struct stream *s;
-
- s = msg;
-
- if (zapi_capabilities_decode(s, &api)) {
- LOG_GR("%s: Error in reading capabilities for client %s",
- __func__, zebra_route_string(client->proto));
- return;
- }
+ case ZEBRA_CLIENT_ROUTE_UPDATE_PENDING:
+ if (!info) {
+ LOG_GR("%s: Client %s route update pending for AFI %d, SAFI %d",
+ __func__, zebra_route_string(client->proto),
+ api.afi, api.safi);
+ } else {
+ LOG_GR("%s: Client %s vrf %s(%u) route update pending for AFI %d, SAFI %d",
+ __func__, zebra_route_string(client->proto),
+ VRF_LOGNAME(vrf), info->vrf_id, api.afi,
+ api.safi);
- /* GR only for dynamic clients */
- if (client->proto <= ZEBRA_ROUTE_CONNECT) {
- LOG_GR("%s: GR capabilities for client %s not supported",
- __func__, zebra_route_string(client->proto));
- return;
+ info->af_enabled[api.afi] = true;
+ }
+ break;
}
- /* Call the capabilities handler */
- zebra_client_capabilities_handler(client, &api);
}
-
/*
* Stale route handling
*/
@@ -432,38 +439,33 @@ void zread_client_capabilities(ZAPI_HANDLER_ARGS)
* Delete all the stale routes that have not been refreshed
* post restart.
*/
-static void zebra_gr_route_stale_delete_timer_expiry(struct thread *thread)
+static void zebra_gr_route_stale_delete_timer_expiry(struct event *thread)
{
- struct client_gr_info *info;
+ struct client_gr_info *info = EVENT_ARG(thread);
int32_t cnt = 0;
struct zserv *client;
+ struct vrf *vrf = vrf_lookup_by_id(info->vrf_id);
- info = THREAD_ARG(thread);
- info->t_stale_removal = NULL;
client = (struct zserv *)info->stale_client_ptr;
- /* Set the flag to indicate all stale route deletion */
- if (thread->u.val == 1)
- info->do_delete = true;
-
cnt = zebra_gr_delete_stale_routes(info);
/* Restart the timer */
if (cnt > 0) {
- LOG_GR("%s: Client %s processed %d routes. Start timer again",
- __func__, zebra_route_string(client->proto), cnt);
+ LOG_GR("%s: Client %s vrf %s(%u) processed %d routes. Start timer again",
+ __func__, zebra_route_string(client->proto),
+ VRF_LOGNAME(vrf), info->vrf_id, cnt);
- thread_add_timer(zrouter.master,
- zebra_gr_route_stale_delete_timer_expiry, info,
- ZEBRA_DEFAULT_STALE_UPDATE_DELAY,
- &info->t_stale_removal);
+ event_add_timer(zrouter.master,
+ zebra_gr_route_stale_delete_timer_expiry, info,
+ ZEBRA_DEFAULT_STALE_UPDATE_DELAY,
+ &info->t_stale_removal);
} else {
/* No routes to delete for the VRF */
- LOG_GR("%s: Client %s all stale routes processed", __func__,
- zebra_route_string(client->proto));
+ LOG_GR("%s: Client %s vrf %s(%u) all stale routes processed",
+ __func__, zebra_route_string(client->proto),
+ VRF_LOGNAME(vrf), info->vrf_id);
- XFREE(MTYPE_ZEBRA_GR, info->current_prefix);
- info->current_afi = 0;
zebra_gr_delete_stale_client(info);
}
}
@@ -472,14 +474,13 @@ static void zebra_gr_route_stale_delete_timer_expiry(struct thread *thread)
/*
* Function to process to check if route entry is stale
* or has been updated.
+ *
+ * Returns true when a node is deleted else false
*/
-static void zebra_gr_process_route_entry(struct zserv *client,
+static bool zebra_gr_process_route_entry(struct zserv *client,
struct route_node *rn,
struct route_entry *re)
{
- if ((client == NULL) || (rn == NULL) || (re == NULL))
- return;
-
/* If the route is not refreshed after restart, delete the entry */
if (re->uptime < client->restart_time) {
if (IS_ZEBRA_DEBUG_RIB)
@@ -487,7 +488,62 @@ static void zebra_gr_process_route_entry(struct zserv *client,
__func__, zebra_route_string(client->proto),
&rn->p);
rib_delnode(rn, re);
+
+ return true;
+ }
+
+ return false;
+}
+
+static void zebra_gr_delete_stale_route_table_afi(struct event *event)
+{
+ struct zebra_gr_afi_clean *gac = EVENT_ARG(event);
+ struct route_table *table;
+ struct route_node *rn;
+ struct route_entry *re, *next;
+ struct zebra_vrf *zvrf = zebra_vrf_lookup_by_id(gac->info->vrf_id);
+ int32_t n = 0;
+
+ if (!zvrf)
+ goto done;
+
+ table = zvrf->table[gac->afi][SAFI_UNICAST];
+ if (!table)
+ goto done;
+
+ for (rn = route_top(table); rn; rn = srcdest_route_next(rn)) {
+ RNODE_FOREACH_RE_SAFE (rn, re, next) {
+ if (CHECK_FLAG(re->status, ROUTE_ENTRY_REMOVED))
+ continue;
+
+ /* If the route refresh is received
+ * after restart then do not delete
+ * the route
+ */
+
+ if (re->type == gac->proto &&
+ re->instance == gac->instance &&
+ zebra_gr_process_route_entry(
+ gac->info->stale_client_ptr, rn, re))
+ n++;
+
+ /* If the max route count is reached
+ * then timer thread will be restarted
+ * Store the current prefix and afi
+ */
+ if ((n >= ZEBRA_MAX_STALE_ROUTE_COUNT) &&
+ (gac->info->do_delete == false)) {
+ event_add_timer(
+ zrouter.master,
+ zebra_gr_delete_stale_route_table_afi,
+ gac, ZEBRA_DEFAULT_STALE_UPDATE_DELAY,
+ &gac->t_gac);
+ }
+ }
}
+
+done:
+ XFREE(MTYPE_ZEBRA_GR, gac);
}
/*
@@ -498,90 +554,32 @@ static void zebra_gr_process_route_entry(struct zserv *client,
static int32_t zebra_gr_delete_stale_route(struct client_gr_info *info,
struct zebra_vrf *zvrf)
{
- struct route_node *rn, *curr;
- struct route_entry *re;
- struct route_entry *next;
- struct route_table *table;
- int32_t n = 0;
- afi_t afi, curr_afi;
+ afi_t afi;
uint8_t proto;
uint16_t instance;
struct zserv *s_client;
- if ((info == NULL) || (zvrf == NULL))
- return -1;
-
s_client = info->stale_client_ptr;
if (s_client == NULL) {
- LOG_GR("%s: Stale client not present", __func__);
+ LOG_GR("%s: Stale client %s(%u) not present", __func__,
+ zvrf->vrf->name, zvrf->vrf->vrf_id);
return -1;
}
proto = s_client->proto;
instance = s_client->instance;
- curr_afi = info->current_afi;
- LOG_GR("%s: Client %s stale routes are being deleted", __func__,
- zebra_route_string(proto));
+ LOG_GR("%s: Client %s %s(%u) stale routes are being deleted", __func__,
+ zebra_route_string(proto), zvrf->vrf->name, zvrf->vrf->vrf_id);
/* Process routes for all AFI */
- for (afi = curr_afi; afi < AFI_MAX; afi++) {
- table = zvrf->table[afi][SAFI_UNICAST];
+ for (afi = AFI_IP; afi < AFI_MAX; afi++) {
- if (table) {
- /*
- * If the current prefix is NULL then get the first
- * route entry in the table
- */
- if (info->current_prefix == NULL) {
- rn = route_top(table);
- if (rn == NULL)
- continue;
- curr = rn;
- } else
- /* Get the next route entry */
- curr = route_table_get_next(
- table, info->current_prefix);
-
- for (rn = curr; rn; rn = srcdest_route_next(rn)) {
- RNODE_FOREACH_RE_SAFE (rn, re, next) {
- if (CHECK_FLAG(re->status,
- ROUTE_ENTRY_REMOVED))
- continue;
- /* If the route refresh is received
- * after restart then do not delete
- * the route
- */
- if (re->type == proto
- && re->instance == instance) {
- zebra_gr_process_route_entry(
- s_client, rn, re);
- n++;
- }
-
- /* If the max route count is reached
- * then timer thread will be restarted
- * Store the current prefix and afi
- */
- if ((n >= ZEBRA_MAX_STALE_ROUTE_COUNT)
- && (info->do_delete == false)) {
- info->current_afi = afi;
- info->current_prefix = XCALLOC(
- MTYPE_ZEBRA_GR,
- sizeof(struct prefix));
- prefix_copy(
- info->current_prefix,
- &rn->p);
- return n;
- }
- }
- }
- }
/*
- * Reset the current prefix to indicate processing completion
- * of the current AFI
+ * Schedule for immediately after anything in the
+ * meta-Q
*/
- XFREE(MTYPE_ZEBRA_GR, info->current_prefix);
+ rib_add_gr_run(afi, info->vrf_id, proto, instance);
}
return 0;
}
@@ -592,23 +590,15 @@ static int32_t zebra_gr_delete_stale_route(struct client_gr_info *info,
*/
static int32_t zebra_gr_delete_stale_routes(struct client_gr_info *info)
{
- struct vrf *vrf;
struct zebra_vrf *zvrf;
uint64_t cnt = 0;
if (info == NULL)
return -1;
- /* Get the current VRF */
- vrf = vrf_lookup_by_id(info->vrf_id);
- if (vrf == NULL) {
- LOG_GR("%s: Invalid VRF %d", __func__, info->vrf_id);
- return -1;
- }
-
- zvrf = vrf->info;
+ zvrf = zebra_vrf_lookup_by_id(info->vrf_id);
if (zvrf == NULL) {
- LOG_GR("%s: Invalid VRF entry %d", __func__, info->vrf_id);
+ LOG_GR("%s: Invalid VRF entry %u", __func__, info->vrf_id);
return -1;
}
@@ -621,44 +611,63 @@ static int32_t zebra_gr_delete_stale_routes(struct client_gr_info *info)
* and cancels the stale timer
*/
static void zebra_gr_process_client_stale_routes(struct zserv *client,
- vrf_id_t vrf_id)
+ struct client_gr_info *info)
{
- struct client_gr_info *info = NULL;
afi_t afi;
- safi_t safi;
-
- TAILQ_FOREACH (info, &client->gr_info_queue, gr_info) {
- if (info->vrf_id == vrf_id)
- break;
- }
if (info == NULL)
return;
/* Check if route update completed for all AFI, SAFI */
- FOREACH_AFI_SAFI_NSF (afi, safi) {
- if (info->af_enabled[afi][safi]) {
- if (!info->route_sync[afi][safi]) {
- LOG_GR("%s: Client %s route update not completed for AFI %d, SAFI %d",
- __func__,
- zebra_route_string(client->proto), afi,
- safi);
- return;
- }
+ for (afi = AFI_IP; afi < AFI_MAX; afi++) {
+ if (info->af_enabled[afi] && !info->route_sync[afi]) {
+ struct vrf *vrf = vrf_lookup_by_id(info->vrf_id);
+
+ LOG_GR("%s: Client %s vrf: %s(%u) route update not completed for AFI %d",
+ __func__, zebra_route_string(client->proto),
+ VRF_LOGNAME(vrf), info->vrf_id, afi);
+ return;
}
}
/*
* Route update completed for all AFI, SAFI
- * Cancel the stale timer and process the routes
+ * Cancel the stale timer, routes are already being processed
*/
if (info->t_stale_removal) {
- LOG_GR("%s: Client %s canceled stale delete timer vrf %d",
+ struct vrf *vrf = vrf_lookup_by_id(info->vrf_id);
+
+ LOG_GR("%s: Client %s canceled stale delete timer vrf %s(%d)",
__func__, zebra_route_string(client->proto),
- info->vrf_id);
- THREAD_OFF(info->t_stale_removal);
- thread_execute(zrouter.master,
- zebra_gr_route_stale_delete_timer_expiry, info,
- 0);
+ VRF_LOGNAME(vrf), info->vrf_id);
+ EVENT_OFF(info->t_stale_removal);
}
}
+
+void zebra_gr_process_client(afi_t afi, vrf_id_t vrf_id, uint8_t proto,
+ uint8_t instance)
+{
+ struct zserv *client = zserv_find_client(proto, instance);
+ struct client_gr_info *info = NULL;
+ struct zebra_gr_afi_clean *gac;
+
+ if (client == NULL)
+ return;
+
+ TAILQ_FOREACH (info, &client->gr_info_queue, gr_info) {
+ if (info->vrf_id == vrf_id)
+ break;
+ }
+
+ if (info == NULL)
+ return;
+
+ gac = XCALLOC(MTYPE_ZEBRA_GR, sizeof(*gac));
+ gac->info = info;
+ gac->afi = afi;
+ gac->proto = proto;
+ gac->instance = instance;
+
+ event_add_event(zrouter.master, zebra_gr_delete_stale_route_table_afi,
+ gac, 0, &gac->t_gac);
+}
diff --git a/zebra/zebra_l2_bridge_if.c b/zebra/zebra_l2_bridge_if.c
index b85d39bcd6..00450ddd36 100644
--- a/zebra/zebra_l2_bridge_if.c
+++ b/zebra/zebra_l2_bridge_if.c
@@ -142,10 +142,7 @@ static void *zebra_l2_bridge_vlan_alloc(void *p)
static void zebra_l2_bridge_vlan_table_destroy(struct hash *vlan_table)
{
- if (vlan_table) {
- hash_clean(vlan_table, zebra_l2_bridge_vlan_free);
- hash_free(vlan_table);
- }
+ hash_clean_and_free(&vlan_table, zebra_l2_bridge_vlan_free);
}
static struct hash *zebra_l2_bridge_vlan_table_create(void)
diff --git a/zebra/zebra_mlag.c b/zebra/zebra_mlag.c
index b4a0c575a2..6713dbc967 100644
--- a/zebra/zebra_mlag.c
+++ b/zebra/zebra_mlag.c
@@ -36,8 +36,8 @@ uint8_t mlag_rd_buffer[ZEBRA_MLAG_BUF_LIMIT];
static bool test_mlag_in_progress;
static int zebra_mlag_signal_write_thread(void);
-static void zebra_mlag_terminate_pthread(struct thread *event);
-static void zebra_mlag_post_data_from_main_thread(struct thread *thread);
+static void zebra_mlag_terminate_pthread(struct event *event);
+static void zebra_mlag_post_data_from_main_thread(struct event *thread);
static void zebra_mlag_publish_process_state(struct zserv *client,
zebra_message_types_t msg_type);
@@ -114,8 +114,8 @@ void zebra_mlag_process_mlag_data(uint8_t *data, uint32_t len)
* additional four bytes are for message type
*/
stream_putl_at(s, 0, msg_type);
- thread_add_event(zrouter.master, zebra_mlag_post_data_from_main_thread,
- s, 0, NULL);
+ event_add_event(zrouter.master, zebra_mlag_post_data_from_main_thread,
+ s, 0, NULL);
}
/**********************End of MLAG Interaction********************************/
@@ -132,7 +132,7 @@ void zebra_mlag_process_mlag_data(uint8_t *data, uint32_t len)
* This thread reads the clients data from the Global queue and encodes with
* protobuf and pass on to the MLAG socket.
*/
-static void zebra_mlag_client_msg_handler(struct thread *event)
+static void zebra_mlag_client_msg_handler(struct event *event)
{
struct stream *s;
uint32_t wr_count = 0;
@@ -173,9 +173,9 @@ static void zebra_mlag_client_msg_handler(struct thread *event)
* main thread.
*/
if (msg_type == MLAG_DEREGISTER) {
- thread_add_event(zrouter.master,
- zebra_mlag_terminate_pthread,
- NULL, 0, NULL);
+ event_add_event(zrouter.master,
+ zebra_mlag_terminate_pthread,
+ NULL, 0, NULL);
}
}
@@ -237,9 +237,9 @@ static int zebra_mlag_signal_write_thread(void)
* during Zebra Init/after MLAG thread is destroyed.
* so it is safe to use without any locking
*/
- thread_add_event(zrouter.mlag_info.th_master,
- zebra_mlag_client_msg_handler, NULL, 0,
- &zrouter.mlag_info.t_write);
+ event_add_event(zrouter.mlag_info.th_master,
+ zebra_mlag_client_msg_handler, NULL, 0,
+ &zrouter.mlag_info.t_write);
return 0;
}
@@ -279,8 +279,8 @@ static void zebra_mlag_publish_process_state(struct zserv *client,
s = stream_new(ZEBRA_HEADER_SIZE + ZEBRA_MLAG_METADATA_LEN);
stream_putl(s, ZEBRA_MLAG_MSG_BCAST);
zclient_create_header(s, msg_type, VRF_DEFAULT);
- thread_add_event(zrouter.master, zebra_mlag_post_data_from_main_thread,
- s, 0, NULL);
+ event_add_event(zrouter.master, zebra_mlag_post_data_from_main_thread,
+ s, 0, NULL);
}
/**************************End of Multi-entrant Apis**************************/
@@ -292,9 +292,9 @@ static void zebra_mlag_publish_process_state(struct zserv *client,
* main thread, because for that access was needed for clients list.
* so instead of forcing the locks, messages will be posted from main thread.
*/
-static void zebra_mlag_post_data_from_main_thread(struct thread *thread)
+static void zebra_mlag_post_data_from_main_thread(struct event *thread)
{
- struct stream *s = THREAD_ARG(thread);
+ struct stream *s = EVENT_ARG(thread);
struct stream *zebra_s = NULL;
struct listnode *node;
struct zserv *client;
@@ -376,7 +376,7 @@ static void zebra_mlag_spawn_pthread(void)
* all clients are un-registered for MLAG Updates, terminate the
* MLAG write thread
*/
-static void zebra_mlag_terminate_pthread(struct thread *event)
+static void zebra_mlag_terminate_pthread(struct event *event)
{
if (IS_ZEBRA_DEBUG_MLAG)
zlog_debug("Zebra MLAG write thread terminate called");
diff --git a/zebra/zebra_mlag_private.c b/zebra/zebra_mlag_private.c
index 334eb6dc46..f348c50755 100644
--- a/zebra/zebra_mlag_private.c
+++ b/zebra/zebra_mlag_private.c
@@ -12,7 +12,7 @@
#include "hook.h"
#include "module.h"
-#include "thread.h"
+#include "frrevent.h"
#include "frr_pthread.h"
#include "libfrr.h"
#include "lib/version.h"
@@ -32,11 +32,11 @@
*
*/
-static struct thread_master *zmlag_master;
+static struct event_loop *zmlag_master;
static int mlag_socket;
-static void zebra_mlag_connect(struct thread *thread);
-static void zebra_mlag_read(struct thread *thread);
+static void zebra_mlag_connect(struct event *thread);
+static void zebra_mlag_read(struct event *thread);
/*
* Write the data to MLAGD
@@ -55,11 +55,11 @@ static int zebra_mlag_private_write_data(uint8_t *data, uint32_t len)
static void zebra_mlag_sched_read(void)
{
- thread_add_read(zmlag_master, zebra_mlag_read, NULL, mlag_socket,
- &zrouter.mlag_info.t_read);
+ event_add_read(zmlag_master, zebra_mlag_read, NULL, mlag_socket,
+ &zrouter.mlag_info.t_read);
}
-static void zebra_mlag_read(struct thread *thread)
+static void zebra_mlag_read(struct event *thread)
{
static uint32_t mlag_rd_buf_offset;
uint32_t *msglen;
@@ -151,7 +151,7 @@ static void zebra_mlag_read(struct thread *thread)
zebra_mlag_sched_read();
}
-static void zebra_mlag_connect(struct thread *thread)
+static void zebra_mlag_connect(struct event *thread)
{
struct sockaddr_un svr = {0};
@@ -173,8 +173,8 @@ static void zebra_mlag_connect(struct thread *thread)
svr.sun_path);
close(mlag_socket);
zrouter.mlag_info.timer_running = true;
- thread_add_timer(zmlag_master, zebra_mlag_connect, NULL, 10,
- &zrouter.mlag_info.t_read);
+ event_add_timer(zmlag_master, zebra_mlag_connect, NULL, 10,
+ &zrouter.mlag_info.t_read);
return;
}
@@ -184,8 +184,8 @@ static void zebra_mlag_connect(struct thread *thread)
zlog_debug("%s: Connection with MLAG is established ",
__func__);
- thread_add_read(zmlag_master, zebra_mlag_read, NULL, mlag_socket,
- &zrouter.mlag_info.t_read);
+ event_add_read(zmlag_master, zebra_mlag_read, NULL, mlag_socket,
+ &zrouter.mlag_info.t_read);
/*
* Connection is established with MLAGD, post to clients
*/
@@ -197,8 +197,8 @@ static void zebra_mlag_connect(struct thread *thread)
*/
static int zebra_mlag_private_monitor_state(void)
{
- thread_add_event(zmlag_master, zebra_mlag_connect, NULL, 0,
- &zrouter.mlag_info.t_read);
+ event_add_event(zmlag_master, zebra_mlag_connect, NULL, 0,
+ &zrouter.mlag_info.t_read);
return 0;
}
@@ -225,8 +225,8 @@ static int zebra_mlag_private_open_channel(void)
/*
* Connect only if any clients are showing interest
*/
- thread_add_event(zmlag_master, zebra_mlag_connect, NULL, 0,
- &zrouter.mlag_info.t_read);
+ event_add_event(zmlag_master, zebra_mlag_connect, NULL, 0,
+ &zrouter.mlag_info.t_read);
}
return 0;
}
diff --git a/zebra/zebra_mpls.c b/zebra/zebra_mpls.c
index d25505839c..f1a99d89ce 100644
--- a/zebra/zebra_mpls.c
+++ b/zebra/zebra_mpls.c
@@ -13,7 +13,7 @@
#include "log.h"
#include "sockunion.h"
#include "linklist.h"
-#include "thread.h"
+#include "frrevent.h"
#include "workqueue.h"
#include "prefix.h"
#include "routemap.h"
@@ -887,7 +887,7 @@ static wq_item_status lsp_process(struct work_queue *wq, void *data)
struct zebra_lsp *lsp;
struct zebra_nhlfe *oldbest, *newbest;
char buf[BUFSIZ], buf2[BUFSIZ];
- struct zebra_vrf *zvrf = vrf_info_lookup(VRF_DEFAULT);
+ struct zebra_vrf *zvrf = zebra_vrf_lookup_by_id(VRF_DEFAULT);
enum zebra_dplane_result res;
lsp = (struct zebra_lsp *)data;
@@ -1028,7 +1028,7 @@ static void lsp_processq_del(struct work_queue *wq, void *data)
if (zebra_router_in_shutdown())
return;
- zvrf = vrf_info_lookup(VRF_DEFAULT);
+ zvrf = zebra_vrf_lookup_by_id(VRF_DEFAULT);
assert(zvrf);
lsp_table = zvrf->lsp_table;
@@ -1776,7 +1776,7 @@ void zebra_mpls_lsp_dplane_result(struct zebra_dplane_ctx *ctx)
case DPLANE_OP_LSP_INSTALL:
case DPLANE_OP_LSP_UPDATE:
/* Look for zebra LSP object */
- zvrf = vrf_info_lookup(VRF_DEFAULT);
+ zvrf = zebra_vrf_lookup_by_id(VRF_DEFAULT);
if (zvrf == NULL)
break;
@@ -2092,7 +2092,7 @@ void zebra_mpls_process_dplane_notify(struct zebra_dplane_ctx *ctx)
dplane_ctx_get_in_label(ctx));
/* Look for zebra LSP object */
- zvrf = vrf_info_lookup(VRF_DEFAULT);
+ zvrf = zebra_vrf_lookup_by_id(VRF_DEFAULT);
if (zvrf == NULL)
return;
@@ -2467,7 +2467,7 @@ int zebra_mpls_fec_unregister(struct zebra_vrf *zvrf, struct prefix *p,
*/
static int zebra_mpls_cleanup_fecs_for_client(struct zserv *client)
{
- struct zebra_vrf *zvrf = vrf_info_lookup(VRF_DEFAULT);
+ struct zebra_vrf *zvrf = zebra_vrf_lookup_by_id(VRF_DEFAULT);
struct route_node *rn;
struct zebra_fec *fec;
struct listnode *node;
@@ -3730,14 +3730,20 @@ void zebra_mpls_print_lsp(struct vty *vty, struct zebra_vrf *zvrf,
/* Lookup table. */
lsp_table = zvrf->lsp_table;
- if (!lsp_table)
+ if (!lsp_table) {
+ if (use_json)
+ vty_out(vty, "{}\n");
return;
+ }
/* If entry is not present, exit. */
tmp_ile.in_label = label;
lsp = hash_lookup(lsp_table, &tmp_ile);
- if (!lsp)
+ if (!lsp) {
+ if (use_json)
+ vty_out(vty, "{}\n");
return;
+ }
if (use_json) {
json = lsp_json(lsp);
@@ -4052,10 +4058,8 @@ static void lsp_table_free(void *p)
void zebra_mpls_close_tables(struct zebra_vrf *zvrf)
{
hash_iterate(zvrf->lsp_table, lsp_uninstall_from_kernel, NULL);
- hash_clean(zvrf->lsp_table, lsp_table_free);
- hash_free(zvrf->lsp_table);
- hash_clean(zvrf->slsp_table, lsp_table_free);
- hash_free(zvrf->slsp_table);
+ hash_clean_and_free(&zvrf->lsp_table, lsp_table_free);
+ hash_clean_and_free(&zvrf->slsp_table, lsp_table_free);
route_table_finish(zvrf->fec_table[AFI_IP]);
route_table_finish(zvrf->fec_table[AFI_IP6]);
}
diff --git a/zebra/zebra_mpls_vty.c b/zebra/zebra_mpls_vty.c
index 7e3cdd738e..6b8859e0ca 100644
--- a/zebra/zebra_mpls_vty.c
+++ b/zebra/zebra_mpls_vty.c
@@ -41,7 +41,7 @@ static int zebra_mpls_transit_lsp(struct vty *vty, int add_cmd,
return CMD_WARNING_CONFIG_FAILED;
}
- zvrf = vrf_info_lookup(VRF_DEFAULT);
+ zvrf = zebra_vrf_lookup_by_id(VRF_DEFAULT);
if (!zvrf) {
vty_out(vty, "%% Default VRF does not exist\n");
return CMD_WARNING_CONFIG_FAILED;
@@ -185,7 +185,7 @@ static int zebra_mpls_bind(struct vty *vty, int add_cmd, const char *prefix,
uint32_t label;
int ret;
- zvrf = vrf_info_lookup(VRF_DEFAULT);
+ zvrf = zebra_vrf_lookup_by_id(VRF_DEFAULT);
if (!zvrf) {
vty_out(vty, "%% Default VRF does not exist\n");
return CMD_WARNING_CONFIG_FAILED;
@@ -273,7 +273,7 @@ static int zebra_mpls_config(struct vty *vty)
int write = 0;
struct zebra_vrf *zvrf;
- zvrf = vrf_info_lookup(VRF_DEFAULT);
+ zvrf = zebra_vrf_lookup_by_id(VRF_DEFAULT);
if (!zvrf)
return 0;
@@ -296,7 +296,7 @@ DEFUN (show_mpls_fec,
struct prefix p;
int ret;
- zvrf = vrf_info_lookup(VRF_DEFAULT);
+ zvrf = zebra_vrf_lookup_by_id(VRF_DEFAULT);
if (!zvrf)
return 0;
@@ -326,7 +326,7 @@ DEFUN (show_mpls_table,
struct zebra_vrf *zvrf;
bool uj = use_json(argc, argv);
- zvrf = vrf_info_lookup(VRF_DEFAULT);
+ zvrf = zebra_vrf_lookup_by_id(VRF_DEFAULT);
zebra_mpls_print_lsp_table(vty, zvrf, uj);
return CMD_SUCCESS;
}
@@ -344,7 +344,7 @@ DEFUN (show_mpls_table_lsp,
struct zebra_vrf *zvrf;
bool uj = use_json(argc, argv);
- zvrf = vrf_info_lookup(VRF_DEFAULT);
+ zvrf = zebra_vrf_lookup_by_id(VRF_DEFAULT);
label = atoi(argv[3]->arg);
zebra_mpls_print_lsp(vty, zvrf, label, uj);
return CMD_SUCCESS;
diff --git a/zebra/zebra_netns_notify.c b/zebra/zebra_netns_notify.c
index cdba0c21ab..4260d29c43 100644
--- a/zebra/zebra_netns_notify.c
+++ b/zebra/zebra_netns_notify.c
@@ -17,7 +17,7 @@
#include <sys/inotify.h>
#include <sys/stat.h>
-#include "thread.h"
+#include "frrevent.h"
#include "ns.h"
#include "command.h"
#include "memory.h"
@@ -41,18 +41,18 @@
#define ZEBRA_NS_POLLING_MAX_RETRIES 200
DEFINE_MTYPE_STATIC(ZEBRA, NETNS_MISC, "ZebraNetNSInfo");
-static struct thread *zebra_netns_notify_current;
+static struct event *zebra_netns_notify_current;
struct zebra_netns_info {
const char *netnspath;
unsigned int retries;
};
-static void zebra_ns_ready_read(struct thread *t);
+static void zebra_ns_ready_read(struct event *t);
static void zebra_ns_notify_create_context_from_entry_name(const char *name);
static int zebra_ns_continue_read(struct zebra_netns_info *zns_info,
int stop_retry);
-static void zebra_ns_notify_read(struct thread *t);
+static void zebra_ns_notify_read(struct event *t);
static struct vrf *vrf_handler_create(struct vty *vty, const char *vrfname)
{
@@ -133,9 +133,9 @@ static int zebra_ns_continue_read(struct zebra_netns_info *zns_info,
XFREE(MTYPE_NETNS_MISC, zns_info);
return 0;
}
- thread_add_timer_msec(zrouter.master, zebra_ns_ready_read,
- (void *)zns_info, ZEBRA_NS_POLLING_INTERVAL_MSEC,
- NULL);
+ event_add_timer_msec(zrouter.master, zebra_ns_ready_read,
+ (void *)zns_info, ZEBRA_NS_POLLING_INTERVAL_MSEC,
+ NULL);
return 0;
}
@@ -165,6 +165,17 @@ static int zebra_ns_delete(char *name)
if_down(ifp);
}
+ if (IS_ZEBRA_IF_BOND(ifp))
+ zebra_l2if_update_bond(ifp, false);
+ if (IS_ZEBRA_IF_BOND_SLAVE(ifp))
+ zebra_l2if_update_bond_slave(ifp, IFINDEX_INTERNAL,
+ false);
+ /* Special handling for bridge or VxLAN interfaces. */
+ if (IS_ZEBRA_IF_BRIDGE(ifp))
+ zebra_l2_bridge_del(ifp);
+ else if (IS_ZEBRA_IF_VXLAN(ifp))
+ zebra_l2_vxlanif_del(ifp);
+
UNSET_FLAG(ifp->flags, IFF_UP);
if_delete_update(&ifp);
}
@@ -218,9 +229,9 @@ static bool zebra_ns_notify_is_default_netns(const char *name)
return false;
}
-static void zebra_ns_ready_read(struct thread *t)
+static void zebra_ns_ready_read(struct event *t)
{
- struct zebra_netns_info *zns_info = THREAD_ARG(t);
+ struct zebra_netns_info *zns_info = EVENT_ARG(t);
const char *netnspath;
int err, stop_retry = 0;
@@ -269,16 +280,16 @@ static void zebra_ns_ready_read(struct thread *t)
zebra_ns_continue_read(zns_info, 1);
}
-static void zebra_ns_notify_read(struct thread *t)
+static void zebra_ns_notify_read(struct event *t)
{
- int fd_monitor = THREAD_FD(t);
+ int fd_monitor = EVENT_FD(t);
struct inotify_event *event;
char buf[BUFSIZ];
ssize_t len;
char event_name[NAME_MAX + 1];
- thread_add_read(zrouter.master, zebra_ns_notify_read, NULL, fd_monitor,
- &zebra_netns_notify_current);
+ event_add_read(zrouter.master, zebra_ns_notify_read, NULL, fd_monitor,
+ &zebra_netns_notify_current);
len = read(fd_monitor, buf, sizeof(buf));
if (len < 0) {
flog_err_sys(EC_ZEBRA_NS_NOTIFY_READ,
@@ -350,8 +361,8 @@ static void zebra_ns_notify_read(struct thread *t)
sizeof(struct zebra_netns_info));
netnsinfo->retries = ZEBRA_NS_POLLING_MAX_RETRIES;
netnsinfo->netnspath = netnspath;
- thread_add_timer_msec(zrouter.master, zebra_ns_ready_read,
- (void *)netnsinfo, 0, NULL);
+ event_add_timer_msec(zrouter.master, zebra_ns_ready_read,
+ (void *)netnsinfo, 0, NULL);
}
}
@@ -416,8 +427,8 @@ void zebra_ns_notify_init(void)
"NS notify watch: failed to add watch (%s)",
safe_strerror(errno));
}
- thread_add_read(zrouter.master, zebra_ns_notify_read, NULL, fd_monitor,
- &zebra_netns_notify_current);
+ event_add_read(zrouter.master, zebra_ns_notify_read, NULL, fd_monitor,
+ &zebra_netns_notify_current);
}
void zebra_ns_notify_close(void)
@@ -431,7 +442,7 @@ void zebra_ns_notify_close(void)
fd = zebra_netns_notify_current->u.fd;
if (zebra_netns_notify_current->master != NULL)
- THREAD_OFF(zebra_netns_notify_current);
+ EVENT_OFF(zebra_netns_notify_current);
/* auto-removal of notify items */
if (fd > 0)
diff --git a/zebra/zebra_nhg.c b/zebra/zebra_nhg.c
index 654cf50d49..8616b14050 100644
--- a/zebra/zebra_nhg.c
+++ b/zebra/zebra_nhg.c
@@ -1619,7 +1619,7 @@ void zebra_nhg_free(struct nhg_hash_entry *nhe)
nhe->nhg.nexthop);
}
- THREAD_OFF(nhe->timer);
+ EVENT_OFF(nhe->timer);
zebra_nhg_free_members(nhe);
@@ -1644,7 +1644,7 @@ void zebra_nhg_hash_free(void *p)
nhe->nhg.nexthop);
}
- THREAD_OFF(nhe->timer);
+ EVENT_OFF(nhe->timer);
nexthops_free(nhe->nhg.nexthop);
@@ -1683,9 +1683,9 @@ void zebra_nhg_hash_free_zero_id(struct hash_bucket *b, void *arg)
}
}
-static void zebra_nhg_timer(struct thread *thread)
+static void zebra_nhg_timer(struct event *thread)
{
- struct nhg_hash_entry *nhe = THREAD_ARG(thread);
+ struct nhg_hash_entry *nhe = EVENT_ARG(thread);
if (IS_ZEBRA_DEBUG_NHG_DETAIL)
zlog_debug("Nexthop Timer for nhe: %pNG", nhe);
@@ -1707,8 +1707,8 @@ void zebra_nhg_decrement_ref(struct nhg_hash_entry *nhe)
!CHECK_FLAG(nhe->flags, NEXTHOP_GROUP_KEEP_AROUND)) {
nhe->refcnt = 1;
SET_FLAG(nhe->flags, NEXTHOP_GROUP_KEEP_AROUND);
- thread_add_timer(zrouter.master, zebra_nhg_timer, nhe,
- zrouter.nhg_keep, &nhe->timer);
+ event_add_timer(zrouter.master, zebra_nhg_timer, nhe,
+ zrouter.nhg_keep, &nhe->timer);
return;
}
@@ -1727,8 +1727,8 @@ void zebra_nhg_increment_ref(struct nhg_hash_entry *nhe)
nhe->refcnt++;
- if (thread_is_scheduled(nhe->timer)) {
- THREAD_OFF(nhe->timer);
+ if (event_is_scheduled(nhe->timer)) {
+ EVENT_OFF(nhe->timer);
nhe->refcnt--;
UNSET_FLAG(nhe->flags, NEXTHOP_GROUP_KEEP_AROUND);
}
@@ -3507,7 +3507,7 @@ struct nhg_hash_entry *zebra_nhg_proto_add(uint32_t id, int type,
/* Dont call the dec API, we dont want to uninstall the ID */
old->refcnt = 0;
- THREAD_OFF(old->timer);
+ EVENT_OFF(old->timer);
zebra_nhg_free(old);
old = NULL;
}
diff --git a/zebra/zebra_nhg.h b/zebra/zebra_nhg.h
index 5830952d5a..b178007b4e 100644
--- a/zebra/zebra_nhg.h
+++ b/zebra/zebra_nhg.h
@@ -89,7 +89,7 @@ struct nhg_hash_entry {
*/
struct nhg_connected_tree_head nhg_depends, nhg_dependents;
- struct thread *timer;
+ struct event *timer;
/*
* Is this nexthop group valid, ie all nexthops are fully resolved.
diff --git a/zebra/zebra_ns.h b/zebra/zebra_ns.h
index 5e8764854e..e759d522fa 100644
--- a/zebra/zebra_ns.h
+++ b/zebra/zebra_ns.h
@@ -46,7 +46,7 @@ struct zebra_ns {
*/
struct nlsock netlink_dplane_out;
struct nlsock netlink_dplane_in;
- struct thread *t_netlink;
+ struct event *t_netlink;
#endif
struct route_table *if_table;
diff --git a/zebra/zebra_opaque.c b/zebra/zebra_opaque.c
index 7cfb3294eb..8ceb1f8dc5 100644
--- a/zebra/zebra_opaque.c
+++ b/zebra/zebra_opaque.c
@@ -77,10 +77,10 @@ static struct zebra_opaque_globals {
struct frr_pthread *pthread;
/* Event-delivery context 'master' for the module */
- struct thread_master *master;
+ struct event_loop *master;
/* Event/'thread' pointer for queued zapi messages */
- struct thread *t_msgs;
+ struct event *t_msgs;
/* Input fifo queue to the module, and lock to protect it. */
pthread_mutex_t mutex;
@@ -94,7 +94,7 @@ static const char LOG_NAME[] = "Zebra Opaque";
/* Prototypes */
/* Main event loop, processing incoming message queue */
-static void process_messages(struct thread *event);
+static void process_messages(struct event *event);
static int handle_opq_registration(const struct zmsghdr *hdr,
struct stream *msg);
static int handle_opq_unregistration(const struct zmsghdr *hdr,
@@ -148,8 +148,8 @@ void zebra_opaque_start(void)
atomic_store_explicit(&zo_info.run, 1, memory_order_relaxed);
/* Enqueue an initial event for the pthread */
- thread_add_event(zo_info.master, process_messages, NULL, 0,
- &zo_info.t_msgs);
+ event_add_event(zo_info.master, process_messages, NULL, 0,
+ &zo_info.t_msgs);
/* And start the pthread */
frr_pthread_run(zo_info.pthread, NULL);
@@ -248,8 +248,8 @@ uint32_t zebra_opaque_enqueue_batch(struct stream_fifo *batch)
if (IS_ZEBRA_DEBUG_RECV && IS_ZEBRA_DEBUG_DETAIL)
zlog_debug("%s: received %u messages",
__func__, counter);
- thread_add_event(zo_info.master, process_messages, NULL, 0,
- &zo_info.t_msgs);
+ event_add_event(zo_info.master, process_messages, NULL, 0,
+ &zo_info.t_msgs);
}
return counter;
@@ -258,7 +258,7 @@ uint32_t zebra_opaque_enqueue_batch(struct stream_fifo *batch)
/*
* Pthread event loop, process the incoming message queue.
*/
-static void process_messages(struct thread *event)
+static void process_messages(struct event *event)
{
struct stream_fifo fifo;
struct stream *msg;
@@ -317,8 +317,8 @@ done:
if (need_resched) {
atomic_fetch_add_explicit(&zo_info.yields, 1,
memory_order_relaxed);
- thread_add_event(zo_info.master, process_messages, NULL, 0,
- &zo_info.t_msgs);
+ event_add_event(zo_info.master, process_messages, NULL, 0,
+ &zo_info.t_msgs);
}
/* This will also free any leftover messages, in the shutdown case */
diff --git a/zebra/zebra_ptm.c b/zebra/zebra_ptm.c
index a8f4953d5a..a1fee840df 100644
--- a/zebra/zebra_ptm.c
+++ b/zebra/zebra_ptm.c
@@ -84,7 +84,7 @@ static ptm_lib_handle_t *ptm_hdl;
struct zebra_ptm_cb ptm_cb;
static int zebra_ptm_socket_init(void);
-void zebra_ptm_sock_read(struct thread *thread);
+void zebra_ptm_sock_read(struct event *thread);
static void zebra_ptm_install_commands(void);
static int zebra_ptm_handle_msg_cb(void *arg, void *in_ctxt);
void zebra_bfd_peer_replay_req(void);
@@ -141,9 +141,9 @@ void zebra_ptm_finish(void)
free(ptm_cb.in_data);
/* Cancel events. */
- THREAD_OFF(ptm_cb.t_read);
- THREAD_OFF(ptm_cb.t_write);
- THREAD_OFF(ptm_cb.t_timer);
+ EVENT_OFF(ptm_cb.t_read);
+ EVENT_OFF(ptm_cb.t_write);
+ EVENT_OFF(ptm_cb.t_timer);
if (ptm_cb.wb)
buffer_free(ptm_cb.wb);
@@ -152,7 +152,7 @@ void zebra_ptm_finish(void)
close(ptm_cb.ptm_sock);
}
-static void zebra_ptm_flush_messages(struct thread *thread)
+static void zebra_ptm_flush_messages(struct event *thread)
{
ptm_cb.t_write = NULL;
@@ -169,13 +169,13 @@ static void zebra_ptm_flush_messages(struct thread *thread)
ptm_cb.ptm_sock = -1;
zebra_ptm_reset_status(0);
ptm_cb.t_timer = NULL;
- thread_add_timer(zrouter.master, zebra_ptm_connect, NULL,
- ptm_cb.reconnect_time, &ptm_cb.t_timer);
+ event_add_timer(zrouter.master, zebra_ptm_connect, NULL,
+ ptm_cb.reconnect_time, &ptm_cb.t_timer);
return;
case BUFFER_PENDING:
ptm_cb.t_write = NULL;
- thread_add_write(zrouter.master, zebra_ptm_flush_messages, NULL,
- ptm_cb.ptm_sock, &ptm_cb.t_write);
+ event_add_write(zrouter.master, zebra_ptm_flush_messages, NULL,
+ ptm_cb.ptm_sock, &ptm_cb.t_write);
break;
case BUFFER_EMPTY:
break;
@@ -193,22 +193,22 @@ static int zebra_ptm_send_message(char *data, int size)
ptm_cb.ptm_sock = -1;
zebra_ptm_reset_status(0);
ptm_cb.t_timer = NULL;
- thread_add_timer(zrouter.master, zebra_ptm_connect, NULL,
- ptm_cb.reconnect_time, &ptm_cb.t_timer);
+ event_add_timer(zrouter.master, zebra_ptm_connect, NULL,
+ ptm_cb.reconnect_time, &ptm_cb.t_timer);
return -1;
case BUFFER_EMPTY:
- THREAD_OFF(ptm_cb.t_write);
+ EVENT_OFF(ptm_cb.t_write);
break;
case BUFFER_PENDING:
- thread_add_write(zrouter.master, zebra_ptm_flush_messages, NULL,
- ptm_cb.ptm_sock, &ptm_cb.t_write);
+ event_add_write(zrouter.master, zebra_ptm_flush_messages, NULL,
+ ptm_cb.ptm_sock, &ptm_cb.t_write);
break;
}
return 0;
}
-void zebra_ptm_connect(struct thread *t)
+void zebra_ptm_connect(struct event *t)
{
int init = 0;
@@ -220,8 +220,8 @@ void zebra_ptm_connect(struct thread *t)
if (ptm_cb.ptm_sock != -1) {
if (init) {
ptm_cb.t_read = NULL;
- thread_add_read(zrouter.master, zebra_ptm_sock_read,
- NULL, ptm_cb.ptm_sock, &ptm_cb.t_read);
+ event_add_read(zrouter.master, zebra_ptm_sock_read,
+ NULL, ptm_cb.ptm_sock, &ptm_cb.t_read);
zebra_bfd_peer_replay_req();
}
zebra_ptm_send_status_req();
@@ -232,8 +232,8 @@ void zebra_ptm_connect(struct thread *t)
ptm_cb.reconnect_time = ZEBRA_PTM_RECONNECT_TIME_MAX;
ptm_cb.t_timer = NULL;
- thread_add_timer(zrouter.master, zebra_ptm_connect, NULL,
- ptm_cb.reconnect_time, &ptm_cb.t_timer);
+ event_add_timer(zrouter.master, zebra_ptm_connect, NULL,
+ ptm_cb.reconnect_time, &ptm_cb.t_timer);
} else if (ptm_cb.reconnect_time >= ZEBRA_PTM_RECONNECT_TIME_MAX) {
ptm_cb.reconnect_time = ZEBRA_PTM_RECONNECT_TIME_INITIAL;
}
@@ -629,13 +629,13 @@ static int zebra_ptm_handle_msg_cb(void *arg, void *in_ctxt)
}
}
-void zebra_ptm_sock_read(struct thread *thread)
+void zebra_ptm_sock_read(struct event *thread)
{
int sock;
int rc;
errno = 0;
- sock = THREAD_FD(thread);
+ sock = EVENT_FD(thread);
if (sock == -1)
return;
@@ -656,15 +656,14 @@ void zebra_ptm_sock_read(struct thread *thread)
ptm_cb.ptm_sock = -1;
zebra_ptm_reset_status(0);
ptm_cb.t_timer = NULL;
- thread_add_timer(zrouter.master, zebra_ptm_connect, NULL,
- ptm_cb.reconnect_time,
- &ptm_cb.t_timer);
+ event_add_timer(zrouter.master, zebra_ptm_connect, NULL,
+ ptm_cb.reconnect_time, &ptm_cb.t_timer);
return;
}
ptm_cb.t_read = NULL;
- thread_add_read(zrouter.master, zebra_ptm_sock_read, NULL,
- ptm_cb.ptm_sock, &ptm_cb.t_read);
+ event_add_read(zrouter.master, zebra_ptm_sock_read, NULL,
+ ptm_cb.ptm_sock, &ptm_cb.t_read);
}
/* BFD peer/dst register/update */
@@ -698,8 +697,8 @@ void zebra_ptm_bfd_dst_register(ZAPI_HANDLER_ARGS)
if (ptm_cb.ptm_sock == -1) {
ptm_cb.t_timer = NULL;
- thread_add_timer(zrouter.master, zebra_ptm_connect, NULL,
- ptm_cb.reconnect_time, &ptm_cb.t_timer);
+ event_add_timer(zrouter.master, zebra_ptm_connect, NULL,
+ ptm_cb.reconnect_time, &ptm_cb.t_timer);
return;
}
@@ -857,8 +856,8 @@ void zebra_ptm_bfd_dst_deregister(ZAPI_HANDLER_ARGS)
if (ptm_cb.ptm_sock == -1) {
ptm_cb.t_timer = NULL;
- thread_add_timer(zrouter.master, zebra_ptm_connect, NULL,
- ptm_cb.reconnect_time, &ptm_cb.t_timer);
+ event_add_timer(zrouter.master, zebra_ptm_connect, NULL,
+ ptm_cb.reconnect_time, &ptm_cb.t_timer);
return;
}
@@ -985,8 +984,8 @@ void zebra_ptm_bfd_client_register(ZAPI_HANDLER_ARGS)
if (ptm_cb.ptm_sock == -1) {
ptm_cb.t_timer = NULL;
- thread_add_timer(zrouter.master, zebra_ptm_connect, NULL,
- ptm_cb.reconnect_time, &ptm_cb.t_timer);
+ event_add_timer(zrouter.master, zebra_ptm_connect, NULL,
+ ptm_cb.reconnect_time, &ptm_cb.t_timer);
return;
}
@@ -1044,8 +1043,8 @@ int zebra_ptm_bfd_client_deregister(struct zserv *client)
if (ptm_cb.ptm_sock == -1) {
ptm_cb.t_timer = NULL;
- thread_add_timer(zrouter.master, zebra_ptm_connect, NULL,
- ptm_cb.reconnect_time, &ptm_cb.t_timer);
+ event_add_timer(zrouter.master, zebra_ptm_connect, NULL,
+ ptm_cb.reconnect_time, &ptm_cb.t_timer);
return 0;
}
diff --git a/zebra/zebra_ptm.h b/zebra/zebra_ptm.h
index 9cea96555b..1b2f7a02d4 100644
--- a/zebra/zebra_ptm.h
+++ b/zebra/zebra_ptm.h
@@ -26,9 +26,9 @@ struct zebra_ptm_cb {
struct buffer *wb; /* Buffer of data waiting to be written to ptm. */
- struct thread *t_read; /* Thread for read */
- struct thread *t_write; /* Thread for write */
- struct thread *t_timer; /* Thread for timer */
+ struct event *t_read; /* Thread for read */
+ struct event *t_write; /* Thread for write */
+ struct event *t_timer; /* Thread for timer */
char *out_data;
char *in_data;
@@ -57,7 +57,7 @@ struct zebra_ptm_cb {
void zebra_ptm_init(void);
void zebra_ptm_finish(void);
-void zebra_ptm_connect(struct thread *t);
+void zebra_ptm_connect(struct event *t);
void zebra_ptm_write(struct vty *vty);
int zebra_ptm_get_enable_state(void);
diff --git a/zebra/zebra_pw.c b/zebra/zebra_pw.c
index dc56ba3c30..12dcac1de5 100644
--- a/zebra/zebra_pw.c
+++ b/zebra/zebra_pw.c
@@ -7,7 +7,7 @@
#include "log.h"
#include "memory.h"
-#include "thread.h"
+#include "frrevent.h"
#include "command.h"
#include "vrf.h"
#include "lib/json.h"
@@ -33,7 +33,7 @@ DEFINE_HOOK(pw_uninstall, (struct zebra_pw * pw), (pw));
static int zebra_pw_enabled(struct zebra_pw *);
static void zebra_pw_install(struct zebra_pw *);
static void zebra_pw_uninstall(struct zebra_pw *);
-static void zebra_pw_install_retry(struct thread *thread);
+static void zebra_pw_install_retry(struct event *thread);
static int zebra_pw_check_reachability(const struct zebra_pw *);
static void zebra_pw_update_status(struct zebra_pw *, int);
@@ -89,7 +89,7 @@ void zebra_pw_del(struct zebra_vrf *zvrf, struct zebra_pw *pw)
dplane_pw_uninstall(pw);
}
- THREAD_OFF(pw->install_retry_timer);
+ EVENT_OFF(pw->install_retry_timer);
/* unlink and release memory */
RB_REMOVE(zebra_pw_head, &zvrf->pseudowires, pw);
@@ -207,16 +207,16 @@ void zebra_pw_install_failure(struct zebra_pw *pw, int pwstatus)
pw->vrf_id, pw->ifname, PW_INSTALL_RETRY_INTERVAL);
/* schedule to retry later */
- THREAD_OFF(pw->install_retry_timer);
- thread_add_timer(zrouter.master, zebra_pw_install_retry, pw,
- PW_INSTALL_RETRY_INTERVAL, &pw->install_retry_timer);
+ EVENT_OFF(pw->install_retry_timer);
+ event_add_timer(zrouter.master, zebra_pw_install_retry, pw,
+ PW_INSTALL_RETRY_INTERVAL, &pw->install_retry_timer);
zebra_pw_update_status(pw, pwstatus);
}
-static void zebra_pw_install_retry(struct thread *thread)
+static void zebra_pw_install_retry(struct event *thread)
{
- struct zebra_pw *pw = THREAD_ARG(thread);
+ struct zebra_pw *pw = EVENT_ARG(thread);
zebra_pw_install(pw);
}
@@ -407,7 +407,7 @@ DEFUN_NOSH (pseudowire_if,
const char *ifname;
int idx = 0;
- zvrf = vrf_info_lookup(VRF_DEFAULT);
+ zvrf = zebra_vrf_lookup_by_id(VRF_DEFAULT);
if (!zvrf)
return CMD_WARNING;
@@ -439,7 +439,7 @@ DEFUN (no_pseudowire_if,
const char *ifname;
int idx = 0;
- zvrf = vrf_info_lookup(VRF_DEFAULT);
+ zvrf = zebra_vrf_lookup_by_id(VRF_DEFAULT);
if (!zvrf)
return CMD_WARNING;
@@ -563,7 +563,7 @@ DEFUN (show_pseudowires,
struct zebra_vrf *zvrf;
struct zebra_pw *pw;
- zvrf = vrf_info_lookup(VRF_DEFAULT);
+ zvrf = zebra_vrf_lookup_by_id(VRF_DEFAULT);
if (!zvrf)
return 0;
@@ -602,7 +602,7 @@ static void vty_show_mpls_pseudowire_detail(struct vty *vty)
struct nexthop *nexthop;
struct nexthop_group *nhg;
- zvrf = vrf_info_lookup(VRF_DEFAULT);
+ zvrf = zebra_vrf_lookup_by_id(VRF_DEFAULT);
if (!zvrf)
return;
@@ -758,7 +758,7 @@ static void vty_show_mpls_pseudowire_detail_json(struct vty *vty)
struct zebra_vrf *zvrf;
struct zebra_pw *pw;
- zvrf = vrf_info_lookup(VRF_DEFAULT);
+ zvrf = zebra_vrf_lookup_by_id(VRF_DEFAULT);
if (!zvrf)
return;
@@ -794,7 +794,7 @@ static int zebra_pw_config(struct vty *vty)
struct zebra_vrf *zvrf;
struct zebra_pw *pw;
- zvrf = vrf_info_lookup(VRF_DEFAULT);
+ zvrf = zebra_vrf_lookup_by_id(VRF_DEFAULT);
if (!zvrf)
return 0;
diff --git a/zebra/zebra_pw.h b/zebra/zebra_pw.h
index d939cc07ea..fd94d5e5ed 100644
--- a/zebra/zebra_pw.h
+++ b/zebra/zebra_pw.h
@@ -38,7 +38,7 @@ struct zebra_pw {
uint8_t protocol;
struct zserv *client;
struct rnh *rnh;
- struct thread *install_retry_timer;
+ struct event *install_retry_timer;
QOBJ_FIELDS;
};
DECLARE_QOBJ_TYPE(zebra_pw);
diff --git a/zebra/zebra_rib.c b/zebra/zebra_rib.c
index 6c499b77d7..32cfa4d04c 100644
--- a/zebra/zebra_rib.c
+++ b/zebra/zebra_rib.c
@@ -18,7 +18,7 @@
#include "sockunion.h"
#include "srcdest_table.h"
#include "table.h"
-#include "thread.h"
+#include "frrevent.h"
#include "vrf.h"
#include "workqueue.h"
#include "nexthop_group_private.h"
@@ -56,7 +56,7 @@ DEFINE_MTYPE_STATIC(ZEBRA, WQ_WRAPPER, "WQ wrapper");
* Event, list, and mutex for delivery of dataplane results
*/
static pthread_mutex_t dplane_mutex;
-static struct thread *t_dplane;
+static struct event *t_dplane;
static struct dplane_ctx_list_head rib_dplane_q;
DEFINE_HOOK(rib_update, (struct route_node * rn, const char *reason),
@@ -64,7 +64,12 @@ DEFINE_HOOK(rib_update, (struct route_node * rn, const char *reason),
DEFINE_HOOK(rib_shutdown, (struct route_node * rn), (rn));
-/* Meta Q's specific names */
+/*
+ * Meta Q's specific names
+ *
+ * If you add something here ensure that you
+ * change MQ_SIZE as well over in rib.h
+ */
enum meta_queue_indexes {
META_QUEUE_NHG,
META_QUEUE_EVPN,
@@ -76,6 +81,7 @@ enum meta_queue_indexes {
META_QUEUE_NOTBGP,
META_QUEUE_BGP,
META_QUEUE_OTHER,
+ META_QUEUE_GR_RUN,
};
/* Each route type's string and default distance value. */
@@ -250,6 +256,8 @@ static const char *subqueue2str(enum meta_queue_indexes index)
return "BGP Routes";
case META_QUEUE_OTHER:
return "Other Routes";
+ case META_QUEUE_GR_RUN:
+ return "Graceful Restart";
}
return "Unknown";
@@ -632,7 +640,7 @@ void rib_install_kernel(struct route_node *rn, struct route_entry *re,
{
struct nexthop *nexthop;
struct rib_table_info *info = srcdest_rnode_table_info(rn);
- struct zebra_vrf *zvrf = vrf_info_lookup(re->vrf_id);
+ struct zebra_vrf *zvrf = zebra_vrf_lookup_by_id(re->vrf_id);
const struct prefix *p, *src_p;
enum zebra_dplane_result ret;
@@ -715,7 +723,7 @@ void rib_uninstall_kernel(struct route_node *rn, struct route_entry *re)
{
struct nexthop *nexthop;
struct rib_table_info *info = srcdest_rnode_table_info(rn);
- struct zebra_vrf *zvrf = vrf_info_lookup(re->vrf_id);
+ struct zebra_vrf *zvrf = zebra_vrf_lookup_by_id(re->vrf_id);
if (info->safi != SAFI_UNICAST) {
UNSET_FLAG(re->status, ROUTE_ENTRY_INSTALLED);
@@ -1410,7 +1418,7 @@ static void rib_process(struct route_node *rn)
static void zebra_rib_evaluate_mpls(struct route_node *rn)
{
rib_dest_t *dest = rib_dest_from_rnode(rn);
- struct zebra_vrf *zvrf = vrf_info_lookup(VRF_DEFAULT);
+ struct zebra_vrf *zvrf = zebra_vrf_lookup_by_id(VRF_DEFAULT);
if (!dest)
return;
@@ -1898,7 +1906,7 @@ static void rib_process_result(struct zebra_dplane_ctx *ctx)
struct rib_table_info *info;
bool rt_delete = false;
- zvrf = vrf_info_lookup(dplane_ctx_get_vrf(ctx));
+ zvrf = zebra_vrf_lookup_by_id(dplane_ctx_get_vrf(ctx));
vrf = vrf_lookup_by_id(dplane_ctx_get_vrf(ctx));
/* Locate rn and re(s) from ctx */
@@ -2566,7 +2574,7 @@ static void process_subq_early_label(struct listnode *lnode)
if (!w)
return;
- zvrf = vrf_info_lookup(w->vrf_id);
+ zvrf = zebra_vrf_lookup_by_id(w->vrf_id);
if (!zvrf) {
XFREE(MTYPE_WQ_WRAPPER, w);
return;
@@ -3089,6 +3097,23 @@ static void process_subq_early_route(struct listnode *lnode)
process_subq_early_route_add(ere);
}
+struct meta_q_gr_run {
+ afi_t afi;
+ vrf_id_t vrf_id;
+ uint8_t proto;
+ uint8_t instance;
+};
+
+static void process_subq_gr_run(struct listnode *lnode)
+{
+ struct meta_q_gr_run *gr_run = listgetdata(lnode);
+
+ zebra_gr_process_client(gr_run->afi, gr_run->vrf_id, gr_run->proto,
+ gr_run->instance);
+
+ XFREE(MTYPE_WQ_WRAPPER, gr_run);
+}
+
/*
* Examine the specified subqueue; process one entry and return 1 if
* there is a node, return 0 otherwise.
@@ -3122,6 +3147,9 @@ static unsigned int process_subq(struct list *subq,
case META_QUEUE_OTHER:
process_subq_route(lnode, qindex);
break;
+ case META_QUEUE_GR_RUN:
+ process_subq_gr_run(lnode);
+ break;
}
list_delete_node(subq, lnode);
@@ -3727,6 +3755,20 @@ static void early_route_meta_queue_free(struct meta_queue *mq, struct list *l,
}
}
+static void rib_meta_queue_gr_run_free(struct meta_queue *mq, struct list *l,
+ struct zebra_vrf *zvrf)
+{
+ struct meta_q_gr_run *gr_run;
+ struct listnode *node, *nnode;
+
+ for (ALL_LIST_ELEMENTS(l, node, nnode, gr_run)) {
+ if (zvrf && zvrf->vrf->vrf_id != gr_run->vrf_id)
+ continue;
+
+ XFREE(MTYPE_WQ_WRAPPER, gr_run);
+ }
+}
+
void meta_queue_free(struct meta_queue *mq, struct zebra_vrf *zvrf)
{
enum meta_queue_indexes i;
@@ -3754,6 +3796,9 @@ void meta_queue_free(struct meta_queue *mq, struct zebra_vrf *zvrf)
case META_QUEUE_OTHER:
rib_meta_queue_free(mq, mq->subq[i], zvrf);
break;
+ case META_QUEUE_GR_RUN:
+ rib_meta_queue_gr_run_free(mq, mq->subq[i], zvrf);
+ break;
}
if (!zvrf)
list_delete(&mq->subq[i]);
@@ -4094,6 +4139,17 @@ void _route_entry_dump(const char *func, union prefixconstptr pp,
zlog_debug("%s: dump complete", straddr);
}
+static int rib_meta_queue_gr_run_add(struct meta_queue *mq, void *data)
+{
+ listnode_add(mq->subq[META_QUEUE_GR_RUN], data);
+ mq->size++;
+
+ if (IS_ZEBRA_DEBUG_RIB_DETAILED)
+ zlog_debug("Graceful Run adding");
+
+ return 0;
+}
+
static int rib_meta_queue_early_route_add(struct meta_queue *mq, void *data)
{
struct zebra_early_route *ere = data;
@@ -4110,6 +4166,20 @@ static int rib_meta_queue_early_route_add(struct meta_queue *mq, void *data)
return 0;
}
+int rib_add_gr_run(afi_t afi, vrf_id_t vrf_id, uint8_t proto, uint8_t instance)
+{
+ struct meta_q_gr_run *gr_run;
+
+ gr_run = XCALLOC(MTYPE_WQ_WRAPPER, sizeof(*gr_run));
+
+ gr_run->afi = afi;
+ gr_run->proto = proto;
+ gr_run->vrf_id = vrf_id;
+ gr_run->instance = instance;
+
+ return mq_add_handler(gr_run, rib_meta_queue_gr_run_add);
+}
+
struct route_entry *zebra_rib_route_entry_new(vrf_id_t vrf_id, int type,
uint8_t instance, uint32_t flags,
uint32_t nhe_id,
@@ -4393,11 +4463,11 @@ static void rib_update_ctx_fini(struct rib_update_ctx **ctx)
XFREE(MTYPE_RIB_UPDATE_CTX, *ctx);
}
-static void rib_update_handler(struct thread *thread)
+static void rib_update_handler(struct event *thread)
{
struct rib_update_ctx *ctx;
- ctx = THREAD_ARG(thread);
+ ctx = EVENT_ARG(thread);
rib_update_handle_vrf_all(ctx->event, ZEBRA_ROUTE_ALL);
@@ -4408,20 +4478,39 @@ static void rib_update_handler(struct thread *thread)
* Thread list to ensure we don't schedule a ton of events
* if interfaces are flapping for instance.
*/
-static struct thread *t_rib_update_threads[RIB_UPDATE_MAX];
+static struct event *t_rib_update_threads[RIB_UPDATE_MAX];
+
+void rib_update_finish(void)
+{
+ int i;
+
+ for (i = RIB_UPDATE_KERNEL; i < RIB_UPDATE_MAX; i++) {
+ if (event_is_scheduled(t_rib_update_threads[i])) {
+ struct rib_update_ctx *ctx;
+
+ ctx = EVENT_ARG(t_rib_update_threads[i]);
+
+ rib_update_ctx_fini(&ctx);
+ EVENT_OFF(t_rib_update_threads[i]);
+ }
+ }
+}
/* Schedule a RIB update event for all vrfs */
void rib_update(enum rib_update_event event)
{
struct rib_update_ctx *ctx;
- if (thread_is_scheduled(t_rib_update_threads[event]))
+ if (event_is_scheduled(t_rib_update_threads[event]))
+ return;
+
+ if (zebra_router_in_shutdown())
return;
ctx = rib_update_ctx_init(0, event);
- thread_add_event(zrouter.master, rib_update_handler, ctx, 0,
- &t_rib_update_threads[event]);
+ event_add_event(zrouter.master, rib_update_handler, ctx, 0,
+ &t_rib_update_threads[event]);
if (IS_ZEBRA_DEBUG_EVENT)
zlog_debug("%s: Scheduled VRF (ALL), event %s", __func__,
@@ -4494,7 +4583,7 @@ void rib_sweep_table(struct route_table *table)
}
/* Sweep all RIB tables. */
-void rib_sweep_route(struct thread *t)
+void rib_sweep_route(struct event *t)
{
struct vrf *vrf;
struct zebra_vrf *zvrf;
@@ -4606,7 +4695,7 @@ static void handle_pw_result(struct zebra_dplane_ctx *ctx)
* Handle results from the dataplane system. Dequeue update context
* structs, dispatch to appropriate internal handlers.
*/
-static void rib_process_dplane_results(struct thread *thread)
+static void rib_process_dplane_results(struct event *thread)
{
struct zebra_dplane_ctx *ctx;
struct dplane_ctx_list_head ctxlist;
@@ -4793,8 +4882,8 @@ static int rib_dplane_results(struct dplane_ctx_list_head *ctxlist)
}
/* Ensure event is signalled to zebra main pthread */
- thread_add_event(zrouter.master, rib_process_dplane_results, NULL, 0,
- &t_dplane);
+ event_add_event(zrouter.master, rib_process_dplane_results, NULL, 0,
+ &t_dplane);
return 0;
}
diff --git a/zebra/zebra_rnh.c b/zebra/zebra_rnh.c
index 2666dc232f..3bbcd38d1c 100644
--- a/zebra/zebra_rnh.c
+++ b/zebra/zebra_rnh.c
@@ -13,7 +13,7 @@
#include "log.h"
#include "sockunion.h"
#include "linklist.h"
-#include "thread.h"
+#include "frrevent.h"
#include "workqueue.h"
#include "prefix.h"
#include "routemap.h"
@@ -326,7 +326,7 @@ void zebra_register_rnh_pseudowire(vrf_id_t vrf_id, struct zebra_pw *pw,
*nht_exists = false;
- zvrf = vrf_info_lookup(vrf_id);
+ zvrf = zebra_vrf_lookup_by_id(vrf_id);
if (!zvrf)
return;
diff --git a/zebra/zebra_routemap.c b/zebra/zebra_routemap.c
index c5bccd05a6..142501b149 100644
--- a/zebra/zebra_routemap.c
+++ b/zebra/zebra_routemap.c
@@ -28,7 +28,7 @@
#include "zebra/zebra_routemap_clippy.c"
static uint32_t zebra_rmap_update_timer = ZEBRA_RMAP_DEFAULT_UPDATE_TIMER;
-static struct thread *zebra_t_rmap_update = NULL;
+static struct event *zebra_t_rmap_update = NULL;
char *zebra_import_table_routemap[AFI_MAX][ZEBRA_KERNEL_TABLE_MAX];
struct nh_rmap_obj {
@@ -1041,7 +1041,7 @@ route_match_ip_next_hop(void *rule, const struct prefix *prefix, void *object)
}
alist = access_list_lookup(AFI_IP, (char *)rule);
if (alist == NULL) {
- if (CHECK_FLAG(rmap_debug, DEBUG_ROUTEMAP_DETAIL))
+ if (unlikely(CHECK_FLAG(rmap_debug, DEBUG_ROUTEMAP_DETAIL)))
zlog_debug(
"%s: Access-List Specified: %s does not exist defaulting to NO_MATCH",
__func__, (char *)rule);
@@ -1104,7 +1104,7 @@ route_match_ip_next_hop_prefix_list(void *rule, const struct prefix *prefix,
}
plist = prefix_list_lookup(AFI_IP, (char *)rule);
if (plist == NULL) {
- if (CHECK_FLAG(rmap_debug, DEBUG_ROUTEMAP_DETAIL))
+ if (unlikely(CHECK_FLAG(rmap_debug, DEBUG_ROUTEMAP_DETAIL)))
zlog_debug(
"%s: Prefix List %s specified does not exist defaulting to NO_MATCH",
__func__, (char *)rule);
@@ -1145,7 +1145,7 @@ route_match_address(afi_t afi, void *rule, const struct prefix *prefix,
alist = access_list_lookup(afi, (char *)rule);
if (alist == NULL) {
- if (CHECK_FLAG(rmap_debug, DEBUG_ROUTEMAP_DETAIL))
+ if (unlikely(CHECK_FLAG(rmap_debug, DEBUG_ROUTEMAP_DETAIL)))
zlog_debug(
"%s: Access-List Specified: %s does not exist defaulting to NO_MATCH",
__func__, (char *)rule);
@@ -1207,7 +1207,7 @@ route_match_address_prefix_list(void *rule, const struct prefix *prefix,
plist = prefix_list_lookup(afi, (char *)rule);
if (plist == NULL) {
- if (CHECK_FLAG(rmap_debug, DEBUG_ROUTEMAP_DETAIL))
+ if (unlikely(CHECK_FLAG(rmap_debug, DEBUG_ROUTEMAP_DETAIL)))
zlog_debug(
"%s: Prefix List %s specified does not exist defaulting to NO_MATCH",
__func__, (char *)rule);
@@ -1722,7 +1722,7 @@ static void zebra_route_map_process_update_cb(char *rmap_name)
zebra_nht_rm_update(rmap_name);
}
-static void zebra_route_map_update_timer(struct thread *thread)
+static void zebra_route_map_update_timer(struct event *thread)
{
if (IS_ZEBRA_DEBUG_EVENT)
zlog_debug("Event driven route-map update triggered");
@@ -1747,7 +1747,7 @@ static void zebra_route_map_set_delay_timer(uint32_t value)
if (!value && zebra_t_rmap_update) {
/* Event driven route map updates is being disabled */
/* But there's a pending timer. Fire it off now */
- THREAD_OFF(zebra_t_rmap_update);
+ EVENT_OFF(zebra_t_rmap_update);
zebra_route_map_update_timer(NULL);
}
}
@@ -1757,7 +1757,7 @@ void zebra_routemap_finish(void)
/* Set zebra_rmap_update_timer to 0 so that it wont schedule again */
zebra_rmap_update_timer = 0;
/* Thread off if any scheduled already */
- THREAD_OFF(zebra_t_rmap_update);
+ EVENT_OFF(zebra_t_rmap_update);
route_map_finish();
}
@@ -1874,10 +1874,10 @@ static void zebra_route_map_mark_update(const char *rmap_name)
{
/* rmap_update_timer of 0 means don't do route updates */
if (zebra_rmap_update_timer)
- THREAD_OFF(zebra_t_rmap_update);
+ EVENT_OFF(zebra_t_rmap_update);
- thread_add_timer(zrouter.master, zebra_route_map_update_timer,
- NULL, zebra_rmap_update_timer, &zebra_t_rmap_update);
+ event_add_timer(zrouter.master, zebra_route_map_update_timer, NULL,
+ zebra_rmap_update_timer, &zebra_t_rmap_update);
}
static void zebra_route_map_add(const char *rmap_name)
diff --git a/zebra/zebra_router.c b/zebra/zebra_router.c
index 21e09a81f7..a477287913 100644
--- a/zebra/zebra_router.c
+++ b/zebra/zebra_router.c
@@ -218,7 +218,7 @@ void zebra_router_terminate(void)
{
struct zebra_router_table *zrt, *tmp;
- THREAD_OFF(zrouter.sweeper);
+ EVENT_OFF(zrouter.sweeper);
RB_FOREACH_SAFE (zrt, zebra_router_table_head, &zrouter.tables, tmp)
zebra_router_free_table(zrt);
@@ -232,20 +232,15 @@ void zebra_router_terminate(void)
/* Free NHE in ID table only since it has unhashable entries as well */
hash_iterate(zrouter.nhgs_id, zebra_nhg_hash_free_zero_id, NULL);
- hash_clean(zrouter.nhgs_id, zebra_nhg_hash_free);
- hash_free(zrouter.nhgs_id);
- hash_clean(zrouter.nhgs, NULL);
- hash_free(zrouter.nhgs);
-
- hash_clean(zrouter.rules_hash, zebra_pbr_rules_free);
- hash_free(zrouter.rules_hash);
-
- hash_clean(zrouter.ipset_entry_hash, zebra_pbr_ipset_entry_free),
- hash_clean(zrouter.ipset_hash, zebra_pbr_ipset_free);
- hash_free(zrouter.ipset_hash);
- hash_free(zrouter.ipset_entry_hash);
- hash_clean(zrouter.iptable_hash, zebra_pbr_iptable_free);
- hash_free(zrouter.iptable_hash);
+ hash_clean_and_free(&zrouter.nhgs_id, zebra_nhg_hash_free);
+ hash_clean_and_free(&zrouter.nhgs, NULL);
+
+ hash_clean_and_free(&zrouter.rules_hash, zebra_pbr_rules_free);
+
+ hash_clean_and_free(&zrouter.ipset_entry_hash,
+ zebra_pbr_ipset_entry_free);
+ hash_clean_and_free(&zrouter.ipset_hash, zebra_pbr_ipset_free);
+ hash_clean_and_free(&zrouter.iptable_hash, zebra_pbr_iptable_free);
#ifdef HAVE_SCRIPTING
zebra_script_destroy();
diff --git a/zebra/zebra_router.h b/zebra/zebra_router.h
index 3112fcab46..d81c7df589 100644
--- a/zebra/zebra_router.h
+++ b/zebra/zebra_router.h
@@ -110,7 +110,7 @@ struct zebra_mlag_info {
struct frr_pthread *zebra_pth_mlag;
/* MLAG Thread context 'master' */
- struct thread_master *th_master;
+ struct event_loop *th_master;
/*
* Event for Initial MLAG Connection setup & Data Read
@@ -118,16 +118,16 @@ struct zebra_mlag_info {
* so no issues.
*
*/
- struct thread *t_read;
+ struct event *t_read;
/* Event for MLAG write */
- struct thread *t_write;
+ struct event *t_write;
};
struct zebra_router {
atomic_bool in_shutdown;
/* Thread master */
- struct thread_master *master;
+ struct event_loop *master;
/* Lists of clients who have connected to us */
struct list *client_list;
@@ -194,7 +194,7 @@ struct zebra_router {
* Time for when we sweep the rib from old routes
*/
time_t startup_time;
- struct thread *sweeper;
+ struct event *sweeper;
/*
* The hash of nexthop groups associated with this router
diff --git a/zebra/zebra_snmp.c b/zebra/zebra_snmp.c
index c8b652f54a..e06733cb8c 100644
--- a/zebra/zebra_snmp.c
+++ b/zebra/zebra_snmp.c
@@ -536,7 +536,7 @@ static uint8_t *ipCidrTable(struct variable *v, oid objid[], size_t *objid_len,
return NULL;
}
-static int zebra_snmp_init(struct thread_master *tm)
+static int zebra_snmp_init(struct event_loop *tm)
{
smux_init(tm);
REGISTER_MIB("mibII/ipforward", zebra_variables, variable, ipfw_oid);
diff --git a/zebra/zebra_vty.c b/zebra/zebra_vty.c
index 6d61430029..d100dc0e69 100644
--- a/zebra/zebra_vty.c
+++ b/zebra/zebra_vty.c
@@ -566,7 +566,7 @@ static void vty_show_ip_route_detail(struct vty *vty, struct route_node *rn,
if (re->mtu)
vty_out(vty, ", mtu %u", re->mtu);
if (re->vrf_id != VRF_DEFAULT) {
- zvrf = vrf_info_lookup(re->vrf_id);
+ zvrf = zebra_vrf_lookup_by_id(re->vrf_id);
vty_out(vty, ", vrf %s", zvrf_name(zvrf));
}
if (CHECK_FLAG(re->flags, ZEBRA_FLAG_SELECTED))
@@ -1179,12 +1179,12 @@ static void show_nexthop_group_out(struct vty *vty, struct nhg_hash_entry *nhe,
json_object_string_add(json, "type",
zebra_route_string(nhe->type));
json_object_int_add(json, "refCount", nhe->refcnt);
- if (thread_is_scheduled(nhe->timer))
+ if (event_is_scheduled(nhe->timer))
json_object_string_add(
json, "timeToDeletion",
- thread_timer_to_hhmmss(time_left,
- sizeof(time_left),
- nhe->timer));
+ event_timer_to_hhmmss(time_left,
+ sizeof(time_left),
+ nhe->timer));
json_object_string_add(json, "uptime", up_str);
json_object_string_add(json, "vrf",
vrf_id_to_name(nhe->vrf_id));
@@ -1193,11 +1193,11 @@ static void show_nexthop_group_out(struct vty *vty, struct nhg_hash_entry *nhe,
vty_out(vty, "ID: %u (%s)\n", nhe->id,
zebra_route_string(nhe->type));
vty_out(vty, " RefCnt: %u", nhe->refcnt);
- if (thread_is_scheduled(nhe->timer))
+ if (event_is_scheduled(nhe->timer))
vty_out(vty, " Time to Deletion: %s",
- thread_timer_to_hhmmss(time_left,
- sizeof(time_left),
- nhe->timer));
+ event_timer_to_hhmmss(time_left,
+ sizeof(time_left),
+ nhe->timer));
vty_out(vty, "\n");
vty_out(vty, " Uptime: %s\n", up_str);
@@ -2706,7 +2706,7 @@ DEFUN (default_vrf_vni_mapping,
struct zebra_vrf *zvrf = NULL;
int filter = 0;
- zvrf = vrf_info_lookup(VRF_DEFAULT);
+ zvrf = zebra_vrf_lookup_by_id(VRF_DEFAULT);
if (!zvrf)
return CMD_WARNING;
@@ -2745,7 +2745,7 @@ DEFUN (no_default_vrf_vni_mapping,
vni_t vni = strtoul(argv[2]->arg, NULL, 10);
struct zebra_vrf *zvrf = NULL;
- zvrf = vrf_info_lookup(VRF_DEFAULT);
+ zvrf = zebra_vrf_lookup_by_id(VRF_DEFAULT);
if (!zvrf)
return CMD_WARNING;
diff --git a/zebra/zebra_vxlan.c b/zebra/zebra_vxlan.c
index 19f1839ac7..36290f99e0 100644
--- a/zebra/zebra_vxlan.c
+++ b/zebra/zebra_vxlan.c
@@ -2582,19 +2582,18 @@ void zebra_vxlan_print_specific_rmac_l3vni(struct vty *vty, vni_t l3vni,
struct zebra_mac *zrmac = NULL;
json_object *json = NULL;
+ if (use_json)
+ json = json_object_new_object();
+
if (!is_evpn_enabled()) {
- if (use_json)
- vty_out(vty, "{}\n");
+ vty_json(vty, json);
return;
}
- if (use_json)
- json = json_object_new_object();
-
zl3vni = zl3vni_lookup(l3vni);
if (!zl3vni) {
if (use_json)
- vty_out(vty, "{}\n");
+ vty_json(vty, json);
else
vty_out(vty, "%% L3-VNI %u doesn't exist\n", l3vni);
return;
@@ -2603,7 +2602,7 @@ void zebra_vxlan_print_specific_rmac_l3vni(struct vty *vty, vni_t l3vni,
zrmac = zl3vni_rmac_lookup(zl3vni, rmac);
if (!zrmac) {
if (use_json)
- vty_out(vty, "{}\n");
+ vty_json(vty, json);
else
vty_out(vty,
"%% Requested RMAC doesn't exist in L3-VNI %u\n",
@@ -2624,13 +2623,18 @@ void zebra_vxlan_print_rmacs_l3vni(struct vty *vty, vni_t l3vni, bool use_json)
struct rmac_walk_ctx wctx;
json_object *json = NULL;
- if (!is_evpn_enabled())
+ if (use_json)
+ json = json_object_new_object();
+
+ if (!is_evpn_enabled()) {
+ vty_json(vty, json);
return;
+ }
zl3vni = zl3vni_lookup(l3vni);
if (!zl3vni) {
if (use_json)
- vty_out(vty, "{}\n");
+ vty_json(vty, json);
else
vty_out(vty, "%% L3-VNI %u does not exist\n", l3vni);
return;
@@ -2639,9 +2643,6 @@ void zebra_vxlan_print_rmacs_l3vni(struct vty *vty, vni_t l3vni, bool use_json)
if (!num_rmacs)
return;
- if (use_json)
- json = json_object_new_object();
-
memset(&wctx, 0, sizeof(wctx));
wctx.vty = vty;
wctx.json = json;
@@ -2663,15 +2664,14 @@ void zebra_vxlan_print_rmacs_all_l3vni(struct vty *vty, bool use_json)
json_object *json = NULL;
void *args[2];
+ if (use_json)
+ json = json_object_new_object();
+
if (!is_evpn_enabled()) {
- if (use_json)
- vty_out(vty, "{}\n");
+ vty_json(vty, json);
return;
}
- if (use_json)
- json = json_object_new_object();
-
args[0] = vty;
args[1] = json;
hash_iterate(zrouter.l3vni_table,
@@ -2690,15 +2690,14 @@ void zebra_vxlan_print_specific_nh_l3vni(struct vty *vty, vni_t l3vni,
struct zebra_neigh *n = NULL;
json_object *json = NULL;
+ if (use_json)
+ json = json_object_new_object();
+
if (!is_evpn_enabled()) {
- if (use_json)
- vty_out(vty, "{}\n");
+ vty_json(vty, json);
return;
}
- if (use_json)
- json = json_object_new_object();
-
/* If vni=0 passed, assume svd lookup */
if (!l3vni)
n = svd_nh_lookup(ip);
@@ -2799,15 +2798,14 @@ void zebra_vxlan_print_nh_all_l3vni(struct vty *vty, bool use_json)
json_object *json = NULL;
void *args[2];
+ if (use_json)
+ json = json_object_new_object();
+
if (!is_evpn_enabled()) {
- if (use_json)
- vty_out(vty, "{}\n");
+ vty_json(vty, json);
return;
}
- if (use_json)
- json = json_object_new_object();
-
args[0] = vty;
args[1] = json;
hash_iterate(zrouter.l3vni_table,
@@ -2828,24 +2826,23 @@ void zebra_vxlan_print_l3vni(struct vty *vty, vni_t vni, bool use_json)
json_object *json = NULL;
struct zebra_l3vni *zl3vni = NULL;
+ if (use_json)
+ json = json_object_new_object();
+
if (!is_evpn_enabled()) {
- if (use_json)
- vty_out(vty, "{}\n");
+ vty_json(vty, json);
return;
}
zl3vni = zl3vni_lookup(vni);
if (!zl3vni) {
if (use_json)
- vty_out(vty, "{}\n");
+ vty_json(vty, json);
else
vty_out(vty, "%% VNI %u does not exist\n", vni);
return;
}
- if (use_json)
- json = json_object_new_object();
-
args[0] = vty;
args[1] = json;
zl3vni_print(zl3vni, (void *)args);
@@ -2900,12 +2897,18 @@ void zebra_vxlan_print_neigh_vni(struct vty *vty, struct zebra_vrf *zvrf,
struct neigh_walk_ctx wctx;
json_object *json = NULL;
- if (!is_evpn_enabled())
+ if (use_json)
+ json = json_object_new_object();
+
+ if (!is_evpn_enabled()) {
+ vty_json(vty, json);
return;
+ }
+
zevpn = zebra_evpn_lookup(vni);
if (!zevpn) {
if (use_json)
- vty_out(vty, "{}\n");
+ vty_json(vty, json);
else
vty_out(vty, "%% VNI %u does not exist\n", vni);
return;
@@ -2914,9 +2917,6 @@ void zebra_vxlan_print_neigh_vni(struct vty *vty, struct zebra_vrf *zvrf,
if (!num_neigh)
return;
- if (use_json)
- json = json_object_new_object();
-
/* Since we have IPv6 addresses to deal with which can vary widely in
* size, we try to be a bit more elegant in display by first computing
* the maximum width.
@@ -2951,12 +2951,14 @@ void zebra_vxlan_print_neigh_all_vni(struct vty *vty, struct zebra_vrf *zvrf,
json_object *json = NULL;
void *args[3];
- if (!is_evpn_enabled())
- return;
-
if (use_json)
json = json_object_new_object();
+ if (!is_evpn_enabled()) {
+ vty_json(vty, json);
+ return;
+ }
+
args[0] = vty;
args[1] = json;
args[2] = (void *)(ptrdiff_t)print_dup;
@@ -2979,12 +2981,14 @@ void zebra_vxlan_print_neigh_all_vni_detail(struct vty *vty,
json_object *json = NULL;
void *args[3];
- if (!is_evpn_enabled())
- return;
-
if (use_json)
json = json_object_new_object();
+ if (!is_evpn_enabled()) {
+ vty_json(vty, json);
+ return;
+ }
+
args[0] = vty;
args[1] = json;
args[2] = (void *)(ptrdiff_t)print_dup;
@@ -3008,12 +3012,18 @@ void zebra_vxlan_print_specific_neigh_vni(struct vty *vty,
struct zebra_neigh *n;
json_object *json = NULL;
- if (!is_evpn_enabled())
+ if (use_json)
+ json = json_object_new_object();
+
+ if (!is_evpn_enabled()) {
+ vty_json(vty, json);
return;
+ }
+
zevpn = zebra_evpn_lookup(vni);
if (!zevpn) {
if (use_json)
- vty_out(vty, "{}\n");
+ vty_json(vty, json);
else
vty_out(vty, "%% VNI %u does not exist\n", vni);
return;
@@ -3026,8 +3036,6 @@ void zebra_vxlan_print_specific_neigh_vni(struct vty *vty,
vni);
return;
}
- if (use_json)
- json = json_object_new_object();
zebra_evpn_print_neigh(n, vty, json);
@@ -3048,12 +3056,18 @@ void zebra_vxlan_print_neigh_vni_vtep(struct vty *vty, struct zebra_vrf *zvrf,
struct neigh_walk_ctx wctx;
json_object *json = NULL;
- if (!is_evpn_enabled())
+ if (use_json)
+ json = json_object_new_object();
+
+ if (!is_evpn_enabled()) {
+ vty_json(vty, json);
return;
+ }
+
zevpn = zebra_evpn_lookup(vni);
if (!zevpn) {
if (use_json)
- vty_out(vty, "{}\n");
+ vty_json(vty, json);
else
vty_out(vty, "%% VNI %u does not exist\n", vni);
return;
@@ -3062,9 +3076,6 @@ void zebra_vxlan_print_neigh_vni_vtep(struct vty *vty, struct zebra_vrf *zvrf,
if (!num_neigh)
return;
- if (use_json)
- json = json_object_new_object();
-
memset(&wctx, 0, sizeof(wctx));
wctx.zevpn = zevpn;
wctx.vty = vty;
@@ -3094,12 +3105,20 @@ void zebra_vxlan_print_neigh_vni_dad(struct vty *vty,
struct neigh_walk_ctx wctx;
json_object *json = NULL;
- if (!is_evpn_enabled())
+ if (use_json)
+ json = json_object_new_object();
+
+ if (!is_evpn_enabled()) {
+ vty_json(vty, json);
return;
+ }
zevpn = zebra_evpn_lookup(vni);
if (!zevpn) {
- vty_out(vty, "%% VNI %u does not exist\n", vni);
+ if (use_json)
+ vty_json(vty, json);
+ else
+ vty_out(vty, "%% VNI %u does not exist\n", vni);
return;
}
@@ -3111,9 +3130,6 @@ void zebra_vxlan_print_neigh_vni_dad(struct vty *vty,
if (!num_neigh)
return;
- if (use_json)
- json = json_object_new_object();
-
/* Since we have IPv6 addresses to deal with which can vary widely in
* size, we try to be a bit more elegant in display by first computing
* the maximum width.
@@ -3155,8 +3171,12 @@ void zebra_vxlan_print_macs_vni(struct vty *vty, struct zebra_vrf *zvrf,
json_object *json = NULL;
json_object *json_mac = NULL;
- if (!is_evpn_enabled())
+ if (!is_evpn_enabled()) {
+ if (use_json)
+ vty_out(vty, "{}\n");
return;
+ }
+
zevpn = zebra_evpn_lookup(vni);
if (!zevpn) {
if (use_json)
@@ -3218,13 +3238,13 @@ void zebra_vxlan_print_macs_all_vni(struct vty *vty, struct zebra_vrf *zvrf,
struct mac_walk_ctx wctx;
json_object *json = NULL;
+ if (use_json)
+ json = json_object_new_object();
+
if (!is_evpn_enabled()) {
- if (use_json)
- vty_out(vty, "{}\n");
+ vty_json(vty, json);
return;
}
- if (use_json)
- json = json_object_new_object();
memset(&wctx, 0, sizeof(wctx));
wctx.vty = vty;
@@ -3246,13 +3266,13 @@ void zebra_vxlan_print_macs_all_vni_detail(struct vty *vty,
struct mac_walk_ctx wctx;
json_object *json = NULL;
+ if (use_json)
+ json = json_object_new_object();
+
if (!is_evpn_enabled()) {
- if (use_json)
- vty_out(vty, "{}\n");
+ vty_json(vty, json);
return;
}
- if (use_json)
- json = json_object_new_object();
memset(&wctx, 0, sizeof(wctx));
wctx.vty = vty;
@@ -3275,12 +3295,14 @@ void zebra_vxlan_print_macs_all_vni_vtep(struct vty *vty,
struct mac_walk_ctx wctx;
json_object *json = NULL;
- if (!is_evpn_enabled())
- return;
-
if (use_json)
json = json_object_new_object();
+ if (!is_evpn_enabled()) {
+ vty_json(vty, json);
+ return;
+ }
+
memset(&wctx, 0, sizeof(wctx));
wctx.vty = vty;
wctx.flags = SHOW_REMOTE_MAC_FROM_VTEP;
@@ -3303,13 +3325,18 @@ void zebra_vxlan_print_specific_mac_vni(struct vty *vty, struct zebra_vrf *zvrf,
struct zebra_mac *mac;
json_object *json = NULL;
- if (!is_evpn_enabled())
+ if (use_json)
+ json = json_object_new_object();
+
+ if (!is_evpn_enabled()) {
+ vty_json(vty, json);
return;
+ }
zevpn = zebra_evpn_lookup(vni);
if (!zevpn) {
if (use_json)
- vty_out(vty, "{}\n");
+ vty_json(vty, json);
else
vty_out(vty, "%% VNI %u does not exist\n", vni);
return;
@@ -3317,7 +3344,7 @@ void zebra_vxlan_print_specific_mac_vni(struct vty *vty, struct zebra_vrf *zvrf,
mac = zebra_evpn_mac_lookup(zevpn, macaddr);
if (!mac) {
if (use_json)
- vty_out(vty, "{}\n");
+ vty_json(vty, json);
else
vty_out(vty,
"%% Requested MAC does not exist in VNI %u\n",
@@ -3325,10 +3352,8 @@ void zebra_vxlan_print_specific_mac_vni(struct vty *vty, struct zebra_vrf *zvrf,
return;
}
- if (use_json)
- json = json_object_new_object();
-
zebra_evpn_print_mac(mac, vty, json);
+
if (use_json)
vty_json(vty, json);
}
@@ -3449,7 +3474,7 @@ int zebra_vxlan_clear_dup_detect_vni_mac(struct zebra_vrf *zvrf, vni_t vni,
mac->detect_start_time.tv_sec = 0;
mac->detect_start_time.tv_usec = 0;
mac->dad_dup_detect_time = 0;
- THREAD_OFF(mac->dad_mac_auto_recovery_timer);
+ EVENT_OFF(mac->dad_mac_auto_recovery_timer);
/* warn-only action return */
if (!zvrf->dad_freeze)
@@ -3531,7 +3556,7 @@ int zebra_vxlan_clear_dup_detect_vni_ip(struct zebra_vrf *zvrf, vni_t vni,
nbr->detect_start_time.tv_sec = 0;
nbr->detect_start_time.tv_usec = 0;
nbr->dad_dup_detect_time = 0;
- THREAD_OFF(nbr->dad_ip_auto_recovery_timer);
+ EVENT_OFF(nbr->dad_ip_auto_recovery_timer);
if (!!CHECK_FLAG(nbr->flags, ZEBRA_NEIGH_LOCAL)) {
zebra_evpn_neigh_send_add_to_client(zevpn->vni, ip, &nbr->emac,
@@ -3566,7 +3591,7 @@ static void zevpn_clear_dup_mac_hash(struct hash_bucket *bucket, void *ctxt)
mac->detect_start_time.tv_sec = 0;
mac->detect_start_time.tv_usec = 0;
mac->dad_dup_detect_time = 0;
- THREAD_OFF(mac->dad_mac_auto_recovery_timer);
+ EVENT_OFF(mac->dad_mac_auto_recovery_timer);
/* Remove all IPs as duplicate associcated with this MAC */
for (ALL_LIST_ELEMENTS_RO(mac->neigh_list, node, nbr)) {
@@ -3693,8 +3718,11 @@ void zebra_vxlan_print_macs_vni_vtep(struct vty *vty, struct zebra_vrf *zvrf,
json_object *json = NULL;
json_object *json_mac = NULL;
- if (!is_evpn_enabled())
+ if (!is_evpn_enabled()) {
+ vty_json(vty, json);
return;
+ }
+
zevpn = zebra_evpn_lookup(vni);
if (!zevpn) {
if (use_json)
@@ -3745,12 +3773,14 @@ void zebra_vxlan_print_vni(struct vty *vty, struct zebra_vrf *zvrf, vni_t vni,
struct zebra_l3vni *zl3vni = NULL;
struct zebra_evpn *zevpn = NULL;
- if (!is_evpn_enabled())
- return;
-
if (use_json)
json = json_object_new_object();
+ if (!is_evpn_enabled()) {
+ vty_json(vty, json);
+ return;
+ }
+
args[0] = vty;
args[1] = json;
@@ -3787,8 +3817,13 @@ void zebra_vxlan_print_evpn(struct vty *vty, bool uj)
json_object *json = NULL;
struct zebra_vrf *zvrf = NULL;
- if (!is_evpn_enabled())
+ if (uj)
+ json = json_object_new_object();
+
+ if (!is_evpn_enabled()) {
+ vty_json(vty, json);
return;
+ }
zvrf = zebra_vrf_get_evpn();
@@ -3797,7 +3832,6 @@ void zebra_vxlan_print_evpn(struct vty *vty, bool uj)
num_vnis = num_l2vnis + num_l3vnis;
if (uj) {
- json = json_object_new_object();
json_object_string_add(json, "advertiseGatewayMacip",
zvrf->advertise_gw_macip ? "Yes" : "No");
json_object_string_add(json, "advertiseSviMacip",
@@ -3819,6 +3853,8 @@ void zebra_vxlan_print_evpn(struct vty *vty, bool uj)
json_object_int_add(json, "detectionTime", zvrf->dad_time);
json_object_int_add(json, "detectionFreezeTime",
zvrf->dad_freeze_time);
+ json_object_boolean_add(json, "isDetectionFreeze",
+ zvrf->dad_freeze);
zebra_evpn_mh_json(json);
} else {
vty_out(vty, "L2 VNIs: %u\n", num_l2vnis);
@@ -3858,12 +3894,15 @@ void zebra_vxlan_print_vnis(struct vty *vty, struct zebra_vrf *zvrf,
json_object *json = NULL;
void *args[2];
- if (!is_evpn_enabled())
- return;
-
if (use_json)
json = json_object_new_object();
- else
+
+ if (!is_evpn_enabled()) {
+ vty_json(vty, json);
+ return;
+ }
+
+ if (!use_json)
vty_out(vty, "%-10s %-4s %-21s %-8s %-8s %-15s %-37s\n", "VNI",
"Type", "VxLAN IF", "# MACs", "# ARPs",
"# Remote VTEPs", "Tenant VRF");
@@ -3941,8 +3980,11 @@ void zebra_vxlan_print_vnis_detail(struct vty *vty, struct zebra_vrf *zvrf,
struct zebra_ns *zns = NULL;
struct zebra_evpn_show zes;
- if (!is_evpn_enabled())
+ if (!is_evpn_enabled()) {
+ if (use_json)
+ vty_out(vty, "{}\n");
return;
+ }
zns = zebra_ns_lookup(NS_DEFAULT);
if (!zns)
diff --git a/zebra/zebra_vxlan_if.c b/zebra/zebra_vxlan_if.c
index 08e07b60a2..3cc7e499bf 100644
--- a/zebra/zebra_vxlan_if.c
+++ b/zebra/zebra_vxlan_if.c
@@ -610,10 +610,7 @@ struct hash *zebra_vxlan_vni_table_create(void)
void zebra_vxlan_vni_table_destroy(struct hash *vni_table)
{
- if (vni_table) {
- hash_clean(vni_table, zebra_vxlan_vni_free);
- hash_free(vni_table);
- }
+ hash_clean_and_free(&vni_table, zebra_vxlan_vni_free);
}
int zebra_vxlan_if_vni_table_destroy(struct zebra_if *zif)
diff --git a/zebra/zserv.c b/zebra/zserv.c
index e064c27ad1..6abd49310c 100644
--- a/zebra/zserv.c
+++ b/zebra/zserv.c
@@ -34,7 +34,7 @@
#include "lib/sockopt.h" /* for setsockopt_so_recvbuf, setsockopt... */
#include "lib/sockunion.h" /* for sockopt_reuseaddr, sockopt_reuseport */
#include "lib/stream.h" /* for STREAM_SIZE, stream (ptr only), ... */
-#include "lib/thread.h" /* for thread (ptr only), THREAD_ARG, ... */
+#include "frrevent.h" /* for thread (ptr only), EVENT_ARG, ... */
#include "lib/vrf.h" /* for vrf_info_lookup, VRF_DEFAULT */
#include "lib/vty.h" /* for vty_out, vty (ptr only) */
#include "lib/zclient.h" /* for zmsghdr, ZEBRA_HEADER_SIZE, ZEBRA... */
@@ -100,7 +100,7 @@ enum zserv_event {
/*
* Zebra server event driver for all client threads.
*
- * This is essentially a wrapper around thread_add_event() that centralizes
+ * This is essentially a wrapper around event_add_event() that centralizes
* those scheduling calls into one place.
*
* All calls to this function schedule an event on the pthread running the
@@ -118,7 +118,7 @@ static void zserv_client_event(struct zserv *client,
/*
* Zebra server event driver for the main thread.
*
- * This is essentially a wrapper around thread_add_event() that centralizes
+ * This is essentially a wrapper around event_add_event() that centralizes
* those scheduling calls into one place.
*
* All calls to this function schedule an event on Zebra's main pthread.
@@ -188,8 +188,8 @@ static void zserv_client_fail(struct zserv *client)
atomic_store_explicit(&client->pthread->running, false,
memory_order_relaxed);
- THREAD_OFF(client->t_read);
- THREAD_OFF(client->t_write);
+ EVENT_OFF(client->t_read);
+ EVENT_OFF(client->t_write);
zserv_event(client, ZSERV_HANDLE_CLIENT_FAIL);
}
@@ -213,9 +213,9 @@ static void zserv_client_fail(struct zserv *client)
* allows us to expose information about input and output queues to the user in
* terms of number of packets rather than size of data.
*/
-static void zserv_write(struct thread *thread)
+static void zserv_write(struct event *thread)
{
- struct zserv *client = THREAD_ARG(thread);
+ struct zserv *client = EVENT_ARG(thread);
struct stream *msg;
uint32_t wcmd = 0;
struct stream_fifo *cache;
@@ -306,9 +306,9 @@ zwrite_fail:
*
* Any failure in any of these actions is handled by terminating the client.
*/
-static void zserv_read(struct thread *thread)
+static void zserv_read(struct event *thread)
{
- struct zserv *client = THREAD_ARG(thread);
+ struct zserv *client = EVENT_ARG(thread);
int sock;
size_t already;
struct stream_fifo *cache;
@@ -321,7 +321,7 @@ static void zserv_read(struct thread *thread)
memory_order_relaxed);
cache = stream_fifo_new();
p2p = p2p_orig;
- sock = THREAD_FD(thread);
+ sock = EVENT_FD(thread);
while (p2p) {
ssize_t nb;
@@ -462,12 +462,12 @@ static void zserv_client_event(struct zserv *client,
{
switch (event) {
case ZSERV_CLIENT_READ:
- thread_add_read(client->pthread->master, zserv_read, client,
- client->sock, &client->t_read);
+ event_add_read(client->pthread->master, zserv_read, client,
+ client->sock, &client->t_read);
break;
case ZSERV_CLIENT_WRITE:
- thread_add_write(client->pthread->master, zserv_write, client,
- client->sock, &client->t_write);
+ event_add_write(client->pthread->master, zserv_write, client,
+ client->sock, &client->t_write);
break;
}
}
@@ -491,9 +491,9 @@ static void zserv_client_event(struct zserv *client,
* rely on the read thread to handle queuing this task enough times to process
* everything on the input queue.
*/
-static void zserv_process_messages(struct thread *thread)
+static void zserv_process_messages(struct event *thread)
{
- struct zserv *client = THREAD_ARG(thread);
+ struct zserv *client = EVENT_ARG(thread);
struct stream *msg;
struct stream_fifo *cache = stream_fifo_new();
uint32_t p2p = zrouter.packets_to_process;
@@ -570,7 +570,7 @@ DEFINE_KOOH(zserv_client_close, (struct zserv *client), (client));
* - Free associated resources
* - Free client structure
*
- * This does *not* take any action on the struct thread * fields. These are
+ * This does *not* take any action on the struct event * fields. These are
* managed by the owning pthread and any tasks associated with them must have
* been stopped prior to invoking this function.
*/
@@ -670,9 +670,9 @@ void zserv_close_client(struct zserv *client)
zlog_debug("Closing client '%s'",
zebra_route_string(client->proto));
- thread_cancel_event(zrouter.master, client);
- THREAD_OFF(client->t_cleanup);
- THREAD_OFF(client->t_process);
+ event_cancel_event(zrouter.master, client);
+ EVENT_OFF(client->t_cleanup);
+ EVENT_OFF(client->t_process);
/* destroy pthread */
frr_pthread_destroy(client->pthread);
@@ -709,9 +709,9 @@ void zserv_close_client(struct zserv *client)
* already have been closed and the thread will most likely have died, but its
* resources still need to be cleaned up.
*/
-static void zserv_handle_client_fail(struct thread *thread)
+static void zserv_handle_client_fail(struct event *thread)
{
- struct zserv *client = THREAD_ARG(thread);
+ struct zserv *client = EVENT_ARG(thread);
zserv_close_client(client);
}
@@ -831,9 +831,9 @@ void zserv_release_client(struct zserv *client)
* main pthread.
*/
if (client->is_closed)
- thread_add_event(zrouter.master,
- zserv_handle_client_fail,
- client, 0, &client->t_cleanup);
+ event_add_event(zrouter.master,
+ zserv_handle_client_fail,
+ client, 0, &client->t_cleanup);
}
}
@@ -846,14 +846,14 @@ void zserv_release_client(struct zserv *client)
/*
* Accept socket connection.
*/
-static void zserv_accept(struct thread *thread)
+static void zserv_accept(struct event *thread)
{
int accept_sock;
int client_sock;
struct sockaddr_in client;
socklen_t len;
- accept_sock = THREAD_FD(thread);
+ accept_sock = EVENT_FD(thread);
/* Reregister myself. */
zserv_event(NULL, ZSERV_ACCEPT);
@@ -953,16 +953,15 @@ void zserv_event(struct zserv *client, enum zserv_event event)
{
switch (event) {
case ZSERV_ACCEPT:
- thread_add_read(zrouter.master, zserv_accept, NULL, zsock,
- NULL);
+ event_add_read(zrouter.master, zserv_accept, NULL, zsock, NULL);
break;
case ZSERV_PROCESS_MESSAGES:
- thread_add_event(zrouter.master, zserv_process_messages, client,
- 0, &client->t_process);
+ event_add_event(zrouter.master, zserv_process_messages, client,
+ 0, &client->t_process);
break;
case ZSERV_HANDLE_CLIENT_FAIL:
- thread_add_event(zrouter.master, zserv_handle_client_fail,
- client, 0, &client->t_cleanup);
+ event_add_event(zrouter.master, zserv_handle_client_fail,
+ client, 0, &client->t_cleanup);
}
}
@@ -1149,14 +1148,10 @@ static void zebra_show_stale_client_detail(struct vty *vty,
if (info->t_stale_removal) {
vty_out(vty,
"Stale delete timer: %ld sec\n",
- thread_timer_remain_second(
+ event_timer_remain_second(
info->t_stale_removal));
}
}
- vty_out(vty, "Current AFI : %d\n", info->current_afi);
- if (info->current_prefix)
- vty_out(vty, "Current prefix : %pFX\n",
- info->current_prefix);
}
}
vty_out(vty, "\n");
diff --git a/zebra/zserv.h b/zebra/zserv.h
index 1226cd7115..90aa4d53f4 100644
--- a/zebra/zserv.h
+++ b/zebra/zserv.h
@@ -19,7 +19,7 @@
#include "lib/vrf.h" /* for vrf_bitmap_t */
#include "lib/zclient.h" /* for redist_proto */
#include "lib/stream.h" /* for stream, stream_fifo */
-#include "lib/thread.h" /* for thread, thread_master */
+#include "frrevent.h" /* for thread, thread_master */
#include "lib/linklist.h" /* for list */
#include "lib/workqueue.h" /* for work_queue */
#include "lib/hook.h" /* for DECLARE_HOOK, DECLARE_KOOH */
@@ -51,9 +51,6 @@ struct client_gr_info {
/* VRF for which GR enabled */
vrf_id_t vrf_id;
- /* AFI */
- afi_t current_afi;
-
/* Stale time and GR cap */
uint32_t stale_removal_time;
enum zserv_client_capabilities capabilities;
@@ -64,13 +61,12 @@ struct client_gr_info {
bool stale_client;
/* Route sync and enable flags for AFI/SAFI */
- bool af_enabled[AFI_MAX][SAFI_MAX];
- bool route_sync[AFI_MAX][SAFI_MAX];
+ bool af_enabled[AFI_MAX];
+ bool route_sync[AFI_MAX];
/* Book keeping */
- struct prefix *current_prefix;
void *stale_client_ptr;
- struct thread *t_stale_removal;
+ struct event *t_stale_removal;
TAILQ_ENTRY(client_gr_info) gr_info;
};
@@ -105,14 +101,14 @@ struct zserv {
struct buffer *wb;
/* Threads for read/write. */
- struct thread *t_read;
- struct thread *t_write;
+ struct event *t_read;
+ struct event *t_write;
/* Event for message processing, for the main pthread */
- struct thread *t_process;
+ struct event *t_process;
/* Event for the main pthread */
- struct thread *t_cleanup;
+ struct event *t_cleanup;
/* This client's redistribute flag. */
struct redist_proto mi_redist[AFI_MAX][ZEBRA_ROUTE_MAX];
@@ -378,7 +374,7 @@ void zserv_log_message(const char *errmsg, struct stream *msg,
struct zmsghdr *hdr);
/* TODO */
-__attribute__((__noreturn__)) void zebra_finalize(struct thread *event);
+__attribute__((__noreturn__)) void zebra_finalize(struct event *event);
/*
* Graceful restart functions.