Fetching topologies using timestamp-callback map
View Patent ↗Examples described herein relate to fetching network device topologies using a timestamp-callback map. The timestamp-callback map includes timestamps paired with references to unique callback functions that fetch topologies for network devices when executed. Examples include setting an alarm for each timestamp in the timestamp-callback map. When an alarm generates a notification, examples create worker threads of a network profiler service. Each worker thread executes a respective unique callback function to fetch a topology for a network device from a topology service. Examples describe different implementations of the timestamp-callback map that can be optimized in various embodiments.
1 . A device, comprising:
one or more processors; and
a non-transitory machine-readable storage medium storing programming for execution by one or more processors, the programming comprising instructions to:
identify, from a plurality of entries of a timestamp-callback map, an entry that comprises a timestamp that meets a criterion, wherein each entry of the plurality of entries of the timestamp-callback map comprises a respective timestamp and a respective set of unique callback functions;
set, in a timer, an alarm for the timestamp that meets the criterion, wherein the alarm is configured to generate a notification at a time according to the timestamp that meets the criterion; and
spawn, in response to the notification, respective worker threads to invoke the unique callback functions at the time according to the timestamp that meets the criterion to fetch topologies for network devices from a topology service.
2 . The device of claim 1 , wherein:
the instructions to identify, from the plurality of entries in the timestamp-callback map, the entry that comprises the timestamp that meets the criterion comprise instructions to identify, from the plurality of entries in the timestamp-callback map, the entry comprising a lowest timestamp, wherein the lowest timestamp indicates an earliest time value; and
the instructions to set, in the timer, the alarm for the timestamp that meets the criterion, comprise instructions to set, in the timer, the alarm for the lowest timestamp, wherein the alarm being configured to generate the notification at the time according to the timestamp that meets the criterion comprises the alarm being configured to generate the notification at a time corresponding to the earliest time value.
3 . The device of claim 1 , wherein the programming further comprises instructions to:
receive a port configuration message for a port of a network device;
determine a timestamp for a callback function, wherein the callback function is configured to fetch, from the topology service, a topology for the network device; and
insert a reference to the callback function in an entry of the timestamp-callback map.
4 . The device of claim 3 , wherein the instructions to insert the reference to the callback function comprise instructions to:
identify, from the plurality of entries, an entry that comprises a timestamp indicating a first time that is within a predetermined interval from a time indicated in the timestamp for the callback function; and
insert the reference to the callback function in the entry identified as comprising a timestamp indicating the time that is within the predetermined interval from the time indicated in the timestamp for the callback function.
5 . The device of claim 3 , wherein the instructions to insert the reference to the callback function comprise instructions to, in response to determining that timestamp-callback map lacks an entry that includes a time that is within a predetermined interval from a time indicated in the timestamp for the callback function:
create a new entry in the timestamp-callback map; and
insert, in the new entry, the timestamp and the reference to the callback function associated with the timestamp.
6 . The device of claim 1 , wherein the timestamp-callback map is a binary search tree and each entry in the timestamp-callback map is a node in the binary search tree.
7 . The device of claim 1 , wherein:
the instructions to identify, from the plurality of entries of the timestamp-callback map, the entry that comprises the timestamp that meets the criterion comprise instructions to identify, in the timestamp-callback map, multiple entries that each include a timestamp that meets the criterion; and
the instructions to set, in the timer, the alarm for the timestamp that meets the criterion comprise instructions to set an alarm for each timestamp included in the multiple entries.
8 . The device of claim 1 , wherein the programming further comprises instructions to:
set a time-limit for a worker thread of the respective worker threads; and
remove, in response to expiry of the time-limit, remove one or more resources allocated to the worker thread of the respective worker threads.
9 . The device of claim 1 , wherein the programming further comprises instructions to:
generate a profile for each port of the network devices based on the topologies, wherein the profile indicates a role of the port; and
distribute the profile to the network devices.
10 . A method comprising:
determining, by a processing resource, a timestamp for a callback function;
inserting, by the processing resource, a reference to the callback function into an entry of a timestamp-callback map, wherein the entry comprises a set of references to unique callback functions associated with the timestamp; and
for the unique callback functions, creating, by the processing resource, respective worker threads at a time indicated in the timestamp, wherein the respective worker threads invoke the unique callback functions, wherein the timestamp-callback map is a binary search tree; and the binary search tree comprises a plurality of nodes, each node storing a respective timestamp and a respective list of unique callback functions.
11 . A non-transitory machine-readable storage medium storing programming for execution by one or more processors, the programming comprising instructions to:
determine a timestamp for a callback function, wherein the callback function is to fetch a topology for a network device from a topology service;
insert a reference to the callback function into an entry of a timestamp-callback map, wherein the entry comprises a list of references to unique callback functions associated with the timestamp; and
create, for the unique callback functions, respective worker threads at a time indicated in the timestamp, wherein the respective worker threads invoke the unique callback functions to fetch topologies for network devices from the topology service.
12 . The non-transitory machine-readable storage medium of claim 11 , wherein:
the programming further comprises instructions to set an alarm for the timestamp in a timer, the alarm configured to generate a notification at the time indicated in the timestamp; and
the instructions to create the respective worker threads for the unique callback functions at the time indicated in the timestamp comprise instructions to:
determine whether the alarm generates the notification; and
create, in response to determining that the alarm generates the notification, the respective worker threads to invoke the unique callback functions at the time.
13 . The non-transitory machine-readable storage medium of claim 12 , wherein invoking the unique callback functions comprises:
extracting the list of references to the unique callback functions associated with the timestamp from the timestamp-callback map; and
executing the unique callback functions associated with the timestamps, executing the unique callback functions comprising:
sending requests to the topology service; and
fetching the topologies for the network devices from the topology service.