Skip to content

Commit

Permalink
ospfd: Draft - Replace LSDB callbacks with LSA Update/Delete hooks.
Browse files Browse the repository at this point in the history
Replace the LSDB callbacks with LSA update and delete hooks using the
the FRR hook mechanism. Also cleaup of the debugging by separating
out opaque-lsa debugging from the overloaded event debugging.

Signed-off-by: Acee Lindem <[email protected]>
  • Loading branch information
aceelindem committed Feb 6, 2025
1 parent ce20b8c commit 46bb398
Show file tree
Hide file tree
Showing 10 changed files with 193 additions and 156 deletions.
43 changes: 17 additions & 26 deletions doc/user/ospfd.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1284,76 +1284,67 @@ Debugging OSPF

.. clicmd:: debug ospf [(1-65535)] client-api

Show debug information for the OSPF opaque data client API.
Enable or disable debugging for the OSPF opaque data client API.

.. clicmd:: debug ospf [(1-65535)] default-information

Show debug information of default information
Enable or disable debugging of default information origination

.. clicmd:: debug ospf [(1-65535)] packet (hello|dd|ls-request|ls-update|ls-ack|all) (send|recv) [detail]


Dump Packet for debugging
Enable or disable debugging for received and transmitted OSPF packets

.. clicmd:: debug ospf [(1-65535)] ism [status|events|timers]



Show debug information of Interface State Machine
Enable or disable debugging of Interface State Machine

.. clicmd:: debug ospf [(1-65535)] nsm [status|events|timers]



Show debug information of Network State Machine
Enable or disable debugging of Neighbor State Machine transitions

.. clicmd:: debug ospf [(1-65535)] event


Show debug information of OSPF event
Enable or disable debugging of OSPF events

.. clicmd:: debug ospf [(1-65535)] nssa


Show debug information about Not So Stub Area
Enable or disable debugging about Not-So-Stubby-Areas (NSSAs)

.. clicmd:: debug ospf [(1-65535)] ldp-sync

Show debug information about LDP-Sync
Enable or disable debugging about LDP-Sync

.. clicmd:: debug ospf [(1-65535)] lsa [aggregate|flooding|generate|install|refresh]



Show debug detail of Link State messages
Enable or disable detail debuggin of Link State Advertisements (LSAs)

.. clicmd:: debug ospf [(1-65535)] sr

Show debug information about Segment Routing
Enable or disable debugging about Segment Routing

.. clicmd:: debug ospf [(1-65535)] te


Show debug information about Traffic Engineering LSA
Enable or disable debugging about MPLS Traffic Engineering LSA

.. clicmd:: debug ospf [(1-65535)] ti-lfa

Show debug information about SR TI-LFA
Enable or disable debugging about SR TI-LFA

.. clicmd:: debug ospf [(1-65535)] zebra [interface|redistribute]

Enable or disable debugging of ZEBRA API

.. clicmd:: debug ospf [(1-65535)] graceful-restart

Show debug information of ZEBRA API
Enable or disable debugying for OSPF Graceful Restart Helper

.. clicmd:: debug ospf [(1-65535)] graceful-restart


Enable/disable debug information for OSPF Graceful Restart Helper
Enable or disable debugging for OSPF Opaque LSA processing

.. clicmd:: show debugging ospf


Show enabled OSPF debugging options

Sample Configuration
====================
Expand Down
80 changes: 38 additions & 42 deletions ospfd/ospf_apiserver.c
Original file line number Diff line number Diff line change
Expand Up @@ -234,26 +234,6 @@ static struct ospf_apiserver *lookup_apiserver_by_lsa(struct ospf_lsa *lsa)
return found;
}

/* -----------------------------------------------------------
* Following are functions to manage client connections.
* -----------------------------------------------------------
*/
static int ospf_apiserver_new_lsa_hook(struct ospf_lsa *lsa)
{
if (IS_DEBUG_OSPF_EVENT)
zlog_debug("API: Put LSA(%p)[%s] into reserve, total=%ld",
(void *)lsa, dump_lsa_key(lsa), lsa->lsdb->total);
return 0;
}

static int ospf_apiserver_del_lsa_hook(struct ospf_lsa *lsa)
{
if (IS_DEBUG_OSPF_EVENT)
zlog_debug("API: Get LSA(%p)[%s] from reserve, total=%ld",
(void *)lsa, dump_lsa_key(lsa), lsa->lsdb->total);
return 0;
}

/* Allocate new connection structure. */
struct ospf_apiserver *ospf_apiserver_new(int fd_sync, int fd_async)
{
Expand All @@ -270,12 +250,11 @@ struct ospf_apiserver *ospf_apiserver_new(int fd_sync, int fd_async)
new->opaque_types = list_new();

/* Initialize temporary strage for LSA instances to be refreshed. */
if (IS_DEBUG_OSPF_CLIENT_API)
zlog_debug("API: Initiallize the reserve LSDB");
memset(&new->reserve, 0, sizeof(struct ospf_lsdb));
ospf_lsdb_init(&new->reserve);

new->reserve.new_lsa_hook = ospf_apiserver_new_lsa_hook; /* debug */
new->reserve.del_lsa_hook = ospf_apiserver_del_lsa_hook; /* debug */

new->out_sync_fifo = msg_fifo_new();
new->out_async_fifo = msg_fifo_new();
new->t_sync_read = NULL;
Expand Down Expand Up @@ -363,6 +342,9 @@ void ospf_apiserver_free(struct ospf_apiserver *apiserv)
msg_fifo_free(apiserv->out_async_fifo);

/* Clear temporary strage for LSA instances to be refreshed. */
if (IS_DEBUG_OSPF_CLIENT_API)
zlog_debug("API: Delete all LSAs from reserve LSDB, total=%ld",
apiserv->reserve.total);
ospf_lsdb_delete_all(&apiserv->reserve);
ospf_lsdb_cleanup(&apiserv->reserve);

Expand All @@ -371,7 +353,7 @@ void ospf_apiserver_free(struct ospf_apiserver *apiserv)

XFREE(MTYPE_APISERVER_MSGFILTER, apiserv->filter);

if (IS_DEBUG_OSPF_EVENT)
if (IS_DEBUG_OSPF_CLIENT_API)
zlog_debug("API: Delete apiserv(%p), total#(%d)",
(void *)apiserv, apiserver_list->count);

Expand All @@ -393,7 +375,7 @@ void ospf_apiserver_read(struct event *thread)
event = OSPF_APISERVER_SYNC_READ;
apiserv->t_sync_read = NULL;

if (IS_DEBUG_OSPF_EVENT)
if (IS_DEBUG_OSPF_CLIENT_API)
zlog_debug("API: %s: Peer: %pI4/%u", __func__,
&apiserv->peer_sync.sin_addr,
ntohs(apiserv->peer_sync.sin_port));
Expand All @@ -403,7 +385,7 @@ void ospf_apiserver_read(struct event *thread)
event = OSPF_APISERVER_ASYNC_READ;
apiserv->t_async_read = NULL;

if (IS_DEBUG_OSPF_EVENT)
if (IS_DEBUG_OSPF_CLIENT_API)
zlog_debug("API: %s: Peer: %pI4/%u", __func__,
&apiserv->peer_async.sin_addr,
ntohs(apiserv->peer_async.sin_port));
Expand All @@ -426,7 +408,7 @@ void ospf_apiserver_read(struct event *thread)
return;
}

if (IS_DEBUG_OSPF_EVENT)
if (IS_DEBUG_OSPF_CLIENT_API)
msg_print(msg);

/* Dispatch to corresponding message handler. */
Expand Down Expand Up @@ -457,7 +439,7 @@ void ospf_apiserver_sync_write(struct event *thread)
goto out;
}

if (IS_DEBUG_OSPF_EVENT)
if (IS_DEBUG_OSPF_CLIENT_API)
zlog_debug("API: %s: Peer: %pI4/%u", __func__,
&apiserv->peer_sync.sin_addr,
ntohs(apiserv->peer_sync.sin_port));
Expand All @@ -469,7 +451,7 @@ void ospf_apiserver_sync_write(struct event *thread)
return;
}

if (IS_DEBUG_OSPF_EVENT)
if (IS_DEBUG_OSPF_CLIENT_API)
msg_print(msg);

rc = msg_write(fd, msg);
Expand Down Expand Up @@ -517,7 +499,7 @@ void ospf_apiserver_async_write(struct event *thread)
goto out;
}

if (IS_DEBUG_OSPF_EVENT)
if (IS_DEBUG_OSPF_CLIENT_API)
zlog_debug("API: %s: Peer: %pI4/%u", __func__,
&apiserv->peer_async.sin_addr,
ntohs(apiserv->peer_async.sin_port));
Expand All @@ -529,7 +511,7 @@ void ospf_apiserver_async_write(struct event *thread)
return;
}

if (IS_DEBUG_OSPF_EVENT)
if (IS_DEBUG_OSPF_CLIENT_API)
msg_print(msg);

rc = msg_write(fd, msg);
Expand Down Expand Up @@ -639,7 +621,7 @@ void ospf_apiserver_accept(struct event *thread)
return;
}

if (IS_DEBUG_OSPF_EVENT)
if (IS_DEBUG_OSPF_CLIENT_API)
zlog_debug("API: %s: New peer: %pI4/%u", __func__,
&peer_sync.sin_addr, ntohs(peer_sync.sin_port));

Expand Down Expand Up @@ -701,7 +683,7 @@ void ospf_apiserver_accept(struct event *thread)
apiserv);
#endif /* USE_ASYNC_READ */

if (IS_DEBUG_OSPF_EVENT)
if (IS_DEBUG_OSPF_CLIENT_API)
zlog_debug("API: New apiserv(%p), total#(%d)", (void *)apiserv,
apiserver_list->count);
}
Expand Down Expand Up @@ -888,7 +870,7 @@ int ospf_apiserver_register_opaque_type(struct ospf_apiserver *apiserv,
/* Add to list of registered opaque types */
listnode_add(apiserv->opaque_types, regtype);

if (IS_DEBUG_OSPF_EVENT)
if (IS_DEBUG_OSPF_CLIENT_API)
zlog_debug(
"API: Add LSA-type(%d)/Opaque-type(%d) into apiserv(%p), total#(%d)",
lsa_type, opaque_type, (void *)apiserv,
Expand Down Expand Up @@ -919,7 +901,7 @@ int ospf_apiserver_unregister_opaque_type(struct ospf_apiserver *apiserv,
listnode_delete(apiserv->opaque_types, regtype);

XFREE(MTYPE_APISERVER, regtype);
if (IS_DEBUG_OSPF_EVENT)
if (IS_DEBUG_OSPF_CLIENT_API)
zlog_debug(
"API: Del LSA-type(%d)/Opaque-type(%d) from apiserv(%p), total#(%d)",
lsa_type, opaque_type, (void *)apiserv,
Expand Down Expand Up @@ -1553,7 +1535,7 @@ struct ospf_lsa *ospf_apiserver_opaque_lsa_new(struct ospf_area *area,

options |= OSPF_OPTION_O; /* Don't forget to set option bit */

if (IS_DEBUG_OSPF(lsa, LSA_GENERATE)) {
if (IS_DEBUG_OSPF_CLIENT_API) {
zlog_debug("LSA[Type%d:%pI4]: Creating an Opaque-LSA instance",
protolsa->type, &protolsa->id);
}
Expand Down Expand Up @@ -1716,6 +1698,9 @@ int ospf_apiserver_handle_originate_request(struct ospf_apiserver *apiserv,
*/
new->lsdb = &apiserv->reserve;
ospf_lsdb_add(&apiserv->reserve, new);
if (IS_DEBUG_OSPF_CLIENT_API)
zlog_debug("API: Add LSA(%p)[%s] into reserve LSDB, total=%ld", (void *)new,
dump_lsa_key(new), new->lsdb->total);

/* Kick the scheduler function. */
ospf_opaque_lsa_refresh_schedule(old);
Expand Down Expand Up @@ -1878,7 +1863,7 @@ struct ospf_lsa *ospf_apiserver_lsa_refresher(struct ospf_lsa *lsa)
ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
assert(ospf);

if (IS_DEBUG_OSPF(lsa, LSA_GENERATE)) {
if (IS_DEBUG_OSPF_CLIENT_API) {
zlog_debug("LSA[Type%d:%pI4]: OSPF API Server LSA Refresher",
lsa->data->type, &lsa->data->id);
}
Expand Down Expand Up @@ -1909,6 +1894,9 @@ struct ospf_lsa *ospf_apiserver_lsa_refresher(struct ospf_lsa *lsa)
}
} else {
/* This is a forcible refresh, requested by OSPF-API client. */
if (IS_DEBUG_OSPF_CLIENT_API)
zlog_debug("API: Delete LSA(%p)[%s] from reserve LSDB, total=%ld",
(void *)new, dump_lsa_key(new), new->lsdb->total);
ospf_lsdb_delete(&apiserv->reserve, new);
new->lsdb = NULL;
}
Expand Down Expand Up @@ -2597,18 +2585,26 @@ static int apiserver_clients_lsa_change_notify(uint8_t msgtype,

int ospf_apiserver_lsa_update(struct ospf_lsa *lsa)
{
if (IS_DEBUG_OSPF_CLIENT_API)
zlog_debug("API: LSA Update Hook Type-%u Opaque-LSA: [opaque-type=%u, opaque-id=%x]%s",
lsa->data->type, GET_OPAQUE_TYPE(ntohl(lsa->data->id.s_addr)),
GET_OPAQUE_ID(ntohl(lsa->data->id.s_addr)),
IS_LSA_MAXAGE(lsa) ? "MaxAged " : "");

/* Only notify this update if the LSA's age is smaller than
MAXAGE. Otherwise clients would see LSA updates with max age just
before they are deleted from the LSDB. LSA delete messages have
MAXAGE too but should not be filtered. */
/* If the LSA has an age of MAXAGE, treat it as a delete notification. */
if (IS_LSA_MAXAGE(lsa))
return 0;
return apiserver_clients_lsa_change_notify(MSG_LSA_DELETE_NOTIFY, lsa);
return apiserver_clients_lsa_change_notify(MSG_LSA_UPDATE_NOTIFY, lsa);
}

int ospf_apiserver_lsa_delete(struct ospf_lsa *lsa)
{
if (IS_DEBUG_OSPF_CLIENT_API)
zlog_debug("API: LSA Update Hook Type-%u Opaque-LSA: [opaque-type=%u, opaque-id=%x]%s",
lsa->data->type, GET_OPAQUE_TYPE(ntohl(lsa->data->id.s_addr)),
GET_OPAQUE_ID(ntohl(lsa->data->id.s_addr)),
IS_LSA_MAXAGE(lsa) ? "MaxAged " : "");

return apiserver_clients_lsa_change_notify(MSG_LSA_DELETE_NOTIFY, lsa);
}

Expand Down
Loading

0 comments on commit 46bb398

Please sign in to comment.