bmv2
Designing your own switch target with bmv2
Public Member Functions | List of all members
bm::Switch Class Reference
Inheritance diagram for bm::Switch:
Inheritance graph
[legend]

Public Member Functions

 Switch (bool enable_swap=false)
 See SwitchWContexts::SwitchWContexts() More...
 
bool field_exists (const std::string &header_name, const std::string &field_name) const
 
std::unique_ptr< Packetnew_packet_ptr (port_t ingress_port, packet_id_t id, int ingress_length, PacketBuffer &&buffer)
 
Packet new_packet (port_t ingress_port, packet_id_t id, int ingress_length, PacketBuffer &&buffer)
 
Pipelineget_pipeline (const std::string &name)
 
Parserget_parser (const std::string &name)
 
Deparserget_deparser (const std::string &name)
 
FieldListget_field_list (const p4object_id_t field_list_id)
 
LearnEngineIfaceget_learn_engine ()
 Obtain a pointer to the LearnEngine for this Switch instance. More...
 
ErrorCodeMap get_error_codes () const
 
template<typename T >
bool add_component (std::shared_ptr< T > ptr)
 
template<typename T >
std::shared_ptr< T > get_component ()
 
bool field_exists (cxt_id_t cxt_id, const std::string &header_name, const std::string &field_name) const
 
std::unique_ptr< Packetnew_packet_ptr (cxt_id_t cxt_id, port_t ingress_port, packet_id_t id, int ingress_length, PacketBuffer &&buffer)
 Construct and return a Packet instance for the given cxt_id. More...
 
Packet new_packet (cxt_id_t cxt_id, port_t ingress_port, packet_id_t id, int ingress_length, PacketBuffer &&buffer)
 
LearnEngineIfaceget_learn_engine (cxt_id_t cxt_id)
 Obtain a pointer to the LearnEngine for a given Context. More...
 
ConfigOptionMap get_config_options (cxt_id_t cxt_id) const
 
ErrorCodeMap get_error_codes (cxt_id_t cxt_id) const
 
- Public Member Functions inherited from bm::SwitchWContexts
 SwitchWContexts (size_t nb_cxts=1u, bool enable_swap=false)
 
Contextget_context (cxt_id_t cxt_id=0u)
 
void start_and_return ()
 
int get_runtime_port () const
 Returns the Thrift port used for the runtime RPC server. More...
 
device_id_t get_device_id () const
 Returns the device id for this switch instance. More...
 
std::string get_notifications_addr () const
 Returns the nanomsg IPC address for this switch. More...
 
void enable_config_swap ()
 Enable JSON config swapping for the switch. More...
 
void disable_config_swap ()
 Disable JSON config swapping for the switch. More...
 
void add_required_field (const std::string &header_name, const std::string &field_name)
 
bool field_exists (cxt_id_t cxt_id, const std::string &header_name, const std::string &field_name) const
 
void force_arith_field (const std::string &header_name, const std::string &field_name)
 
void force_arith_header (const std::string &header_name)
 
bool set_group_selector (cxt_id_t cxt_id, const std::string &act_prof_name, std::shared_ptr< ActionProfile::GroupSelectionIface > selector)
 
size_t get_nb_cxts ()
 Get the number of contexts included in this switch. More...
 
int init_from_command_line_options (int argc, char *argv[], TargetParserIface *tp=nullptr, std::shared_ptr< TransportIface > my_transport=nullptr, std::unique_ptr< DevMgrIface > my_dev_mgr=nullptr)
 
int init_from_options_parser (const OptionsParser &parser, std::shared_ptr< TransportIface > my_transport=nullptr, std::unique_ptr< DevMgrIface > my_dev_mgr=nullptr)
 
template<typename T >
std::shared_ptr< T > get_component ()
 
template<typename T >
std::shared_ptr< T > get_cxt_component (cxt_id_t cxt_id)
 
int swap_requested ()
 
int do_swap ()
 
void block_until_no_more_packets ()
 
std::unique_ptr< Packetnew_packet_ptr (cxt_id_t cxt_id, port_t ingress_port, packet_id_t id, int ingress_length, PacketBuffer &&buffer)
 Construct and return a Packet instance for the given cxt_id. More...
 
Packet new_packet (cxt_id_t cxt_id, port_t ingress_port, packet_id_t id, int ingress_length, PacketBuffer &&buffer)
 Construct and return a Packet instance for the given cxt_id. More...
 
LearnEngineIfaceget_learn_engine (cxt_id_t cxt_id)
 Obtain a pointer to the LearnEngine for a given Context. More...
 
ConfigOptionMap get_config_options (cxt_id_t cxt_id) const
 
ErrorCodeMap get_error_codes (cxt_id_t cxt_id) const
 
- Public Member Functions inherited from bm::DevMgr
void transmit_fn (port_t port_num, const char *buffer, int len)
 Transmits a data packet out of port port_num. More...
 
ReturnCode register_status_cb (const PortStatus &type, const PortStatusCb &port_cb)
 

Additional Inherited Members

- Public Types inherited from bm::DevMgr
using port_t = PortMonitorIface::port_t
 Representation of a port number. More...
 
using PortStatus = PortMonitorIface::PortStatus
 Represents the status of a port. More...
 
using PortStatusCb = PortMonitorIface::PortStatusCb
 Signature of the cb function to call when a port status changes. More...
 
- Protected Member Functions inherited from bm::SwitchWContexts
template<typename T >
bool add_component (std::shared_ptr< T > ptr)
 
template<typename T >
bool add_cxt_component (cxt_id_t cxt_id, std::shared_ptr< T > ptr)
 

Detailed Description

Convenience subclass of SwitchWContexts for targets with a single Context. This is the base class for the standard simple switch target implementation.

Constructor & Destructor Documentation

◆ Switch()

bm::Switch::Switch ( bool  enable_swap = false)
explicit

Member Function Documentation

◆ add_component()

template<typename T >
bool bm::Switch::add_component ( std::shared_ptr< T >  ptr)
inline

Add a component to this Switch. Each Switch maintains a map T -> shared_ptr<T>, which maps a type (using typeid) to a shared pointer to an object of the same type. The pointer can be retrieved at a later time by using get_component().

◆ field_exists() [1/2]

bool bm::Switch::field_exists ( const std::string &  header_name,
const std::string &  field_name 
) const
inline

Checks that the given field was defined in the input JSON used to configure the switch

◆ field_exists() [2/2]

bool bm::SwitchWContexts::field_exists
inline

Checks that the given field exists for context cxt_id, i.e. checks that the field was defined in the input JSON used to configure that context.

◆ get_component()

template<typename T >
std::shared_ptr<T> bm::Switch::get_component ( )
inline

Retrieve the shared pointer to an object of type T previously added to the Switch using add_component().

◆ get_config_options()

ConfigOptionMap bm::SwitchWContexts::get_config_options
inline

Return string-to-string map of the target-specific options included in the input config JSON for a given context.

◆ get_deparser()

Deparser* bm::Switch::get_deparser ( const std::string &  name)
inline

Return a raw, non-owning pointer to Deparser name. This pointer will be invalidated if a configuration swap is performed by the target. See switch.h documentation for details. Return a nullptr if there is no deparser with this name.

◆ get_error_codes() [1/2]

ErrorCodeMap bm::Switch::get_error_codes ( ) const
inline

Return a copy of the error codes map (a bi-directional map between an error code's integral value and its name / description) for the switch.

◆ get_error_codes() [2/2]

ErrorCodeMap bm::SwitchWContexts::get_error_codes
inline

Return a copy of the error codes map (a bi-directional map between an error code's integral value and its name / description) for a given context.

◆ get_field_list()

FieldList* bm::Switch::get_field_list ( const p4object_id_t  field_list_id)
inline

Return a raw, non-owning pointer to the FieldList with id field_list_id. This pointer will be invalidated if a configuration swap is performed by the target. See switch.h documentation for details.

◆ get_learn_engine() [1/2]

LearnEngineIface* bm::Switch::get_learn_engine ( )
inline

Obtain a pointer to the LearnEngine for this Switch instance.

◆ get_learn_engine() [2/2]

LearnEngineIface* bm::SwitchWContexts::get_learn_engine
inline

Obtain a pointer to the LearnEngine for a given Context.

◆ get_parser()

Parser* bm::Switch::get_parser ( const std::string &  name)
inline

Return a raw, non-owning pointer to Parser name. This pointer will be invalidated if a configuration swap is performed by the target. See switch.h documentation for details. Return a nullptr if there is no parser with this name.

◆ get_pipeline()

Pipeline* bm::Switch::get_pipeline ( const std::string &  name)
inline

Return a raw, non-owning pointer to Pipeline name. This pointer will be invalidated if a configuration swap is performed by the target. See switch.h documentation for details. Return a nullptr if there is no pipeline with this name.

◆ new_packet() [1/2]

Packet bm::SwitchWContexts::new_packet

Convenience wrapper around SwitchWContexts::new_packet_ptr() for a single context switch.

◆ new_packet() [2/2]

Packet bm::Switch::new_packet ( port_t  ingress_port,
packet_id_t  id,
int  ingress_length,
PacketBuffer &&  buffer 
)

Convenience wrapper around SwitchWContexts::new_packet() for a single context switch.

◆ new_packet_ptr() [1/2]

std::unique_ptr<Packet> bm::SwitchWContexts::new_packet_ptr

Construct and return a Packet instance for the given cxt_id.

◆ new_packet_ptr() [2/2]

std::unique_ptr<Packet> bm::Switch::new_packet_ptr ( port_t  ingress_port,
packet_id_t  id,
int  ingress_length,
PacketBuffer &&  buffer 
)

Convenience wrapper around SwitchWContexts::new_packet_ptr() for a single context switch.


The documentation for this class was generated from the following file: