pub struct NodeRegistration<N: Node, const N_NEXT_NODES: usize> { /* private fields */ }Expand description
Registration information for a VPP node
Used for registering and unregistering nodes with VPP.
This is typically created automatically using the vpp_plugin_macros::vlib_node macro.
Implementations§
Source§impl<N: Node, const N_NEXT_NODES: usize> NodeRegistration<N, N_NEXT_NODES>
impl<N: Node, const N_NEXT_NODES: usize> NodeRegistration<N, N_NEXT_NODES>
Sourcepub const fn new(
registration: _vlib_node_registration<[*mut c_char; N_NEXT_NODES]>,
) -> Self
pub const fn new( registration: _vlib_node_registration<[*mut c_char; N_NEXT_NODES]>, ) -> Self
Creates a new NodeRegistration from the given registration data
Sourcepub unsafe fn register(&'static self)
pub unsafe fn register(&'static self)
Registers the node with VPP
§Safety
- Must be called only once for this node registration.
- Must be called from a constructor function that is invoked before VPP initialises.
- The following pointers in the registration data must be valid:
name(must be a valid, nul-terminated string)function(must point to a valid node function)error_descriptions(must point to an array ofn_errorsvalidvlib_error_desc_tentries)next_nodes(each entry must be a valid nul-terminated string and length must be at leastn_next_nodes)
- Other pointers in the registration data must be either valid or null as appropriate.
vector_size,scalar_size, andaux_sizemust match the sizes of the corresponding types inN.
Sourcepub unsafe fn unregister(&self)
pub unsafe fn unregister(&self)
Unregisters the node from VPP
§Safety
- Must be called only once for this node registration.
- Must be called from a destructor function that is invoked after VPP uninitialises.
- The node must have been previously registered with VPP using
Self::register.
Sourcepub unsafe fn register_node_fn(&self, node_fn: *mut vlib_node_fn_registration_t)
pub unsafe fn register_node_fn(&self, node_fn: *mut vlib_node_fn_registration_t)
Registers a node function with VPP
§Safety
- The
node_fnpointer must be valid and point to a properly initialisedvlib_node_fn_registration_t. - The
node_fnmust not have been previously registered with VPP.
Sourcepub unsafe fn node_runtime_from_ptr<'a>(
&self,
ptr: *mut vlib_node_runtime_t,
) -> &'a mut NodeRuntimeRef<N>
pub unsafe fn node_runtime_from_ptr<'a>( &self, ptr: *mut vlib_node_runtime_t, ) -> &'a mut NodeRuntimeRef<N>
Creates a &mut NodeRuntimeRef directly from a pointer
This is a convenience method that calls NodeRuntimeRef::from_ptr_mut, for code that
has an instance of NodeRegistration, but doesn’t know the name of the type for the node.
As such, self isn’t used, it’s just taken so that the generic types are known.
§Safety
- The same preconditions as
NodeRuntimeRef::from_ptr_mutapply.
Sourcepub unsafe fn frame_from_ptr<'a>(
&self,
ptr: *mut vlib_frame_t,
) -> &'a mut FrameRef<N>
pub unsafe fn frame_from_ptr<'a>( &self, ptr: *mut vlib_frame_t, ) -> &'a mut FrameRef<N>
Creates a &mut FrameRef directly from a pointer
This is a convenience method that calls FrameRef::from_ptr_mut, for code that
has an instance of NodeRegistration, but doesn’t know the name of the type for the node.
As such, self isn’t used, it’s just taken so that the generic types are known.
§Safety
- The same preconditions as
FrameRef::from_ptr_mutapply.
Sourcepub unsafe fn node_from_ptr<'a>(
&self,
ptr: *mut vlib_node_t,
) -> &'a mut NodeRef<N>
pub unsafe fn node_from_ptr<'a>( &self, ptr: *mut vlib_node_t, ) -> &'a mut NodeRef<N>
Creates a &mut NodeRef directly from a pointer
This is a convenience method that calls NodeRef::from_ptr_mut, for code that
has an instance of NodeRegistration, but doesn’t know the name of the type for the node.
As such, self isn’t used, it’s just taken so that the generic types are known.
§Safety
- The same preconditions as
NodeRef::from_ptr_mutapply.