Click
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | List of all members
NameInfo Class Reference

Manages Click name databases. More...

Public Types

enum  DBType {
  T_NONE = 0 , T_SCHEDULEINFO = 0x00000001 , T_ANNOTATION = 0x00000002 , T_SCRIPT_INSN = 0x00000003 ,
  T_SIGNO = 0x00000004 , T_SPINLOCK = 0x00000005 , T_ETHERNET_ADDR = 0x01000001 , T_IP_ADDR = 0x04000001 ,
  T_IP_PREFIX = 0x04000002 , T_IP_PROTO = 0x04000003 , T_IPFILTER_TYPE = 0x04000004 , T_TCP_OPT = 0x04000005 ,
  T_IPREWRITER_PATTERN = 0x04000006 , T_ICMP_TYPE = 0x04010000 , T_ICMP_CODE = 0x04010100 , T_IP_PORT = 0x04020000 ,
  T_TCP_PORT = 0x04020006 , T_UDP_PORT = 0x04020011 , T_IP_FIELDNAME = 0x04030000 , T_ICMP_FIELDNAME = 0x04030001 ,
  T_TCP_FIELDNAME = 0x04030006 , T_UDP_FIELDNAME = 0x04030011 , T_IP6_ADDR = 0x06000001 , T_IP6_PREFIX = 0x06000002
}
 Known name database types. More...
 

Public Member Functions

 NameInfo ()
 Construct a NameInfo element.
 
 ~NameInfo ()
 Destroy a NameInfo object.
 

Static Public Member Functions

static void static_initialize ()
 Static initialization for NameInfo.
 
static void static_cleanup ()
 Static cleanup for NameInfo.
 
static NameDB * getdb (uint32_t type, const Element *context, size_t value_size, bool create)
 Find or create a name database.
 
static void installdb (NameDB *db, const Element *context)
 Install a name database.
 
static void uninstalldb (NameDB *db)
 Uninstall a name database.
 
static bool query (uint32_t type, const Element *context, const String &name, void *value_store, size_t value_size)
 Query installed databases for name.
 
static bool query_int (uint32_t type, const Element *context, const String &name, int32_t *value_store)
 Query installed databases for name, returning a 32-bit integer value.
 
static bool query_int (uint32_t type, const Element *context, const String &name, uint32_t *value_store)
 
static String revquery (uint32_t type, const Element *context, const void *value, size_t value_size)
 Query installed databases for value.
 
static String revquery_int (uint32_t type, const Element *context, int32_t value)
 Query installed databases for a 32-bit integer value.
 
static bool define (uint32_t type, const Element *context, const String &name, const void *value, size_t value_size)
 Define name to equal value in the installed databases.
 
static bool define_int (uint32_t type, const Element *context, const String &name, int32_t value)
 Define name to equal 32-bit integer value in the installed databases.
 

Detailed Description

Manages Click name databases.

NameInfo is the user interface to Click's name databases, a general mechanism for mapping names to values. NameInfo and NameDB implement generally useful properties like names local to a compound element context.

Every name database maps names, which are nonempty strings, to values, which are sequences of bytes. A database is identified by its type, which indicates the kind of name stored in the database, and, optionally, its compound element context, which is a pair of router and element name prefix. The database is used for queries that take place in the given context. A query bubbles up through the databases, starting with the most specific context and getting more general, until it succeeds. A database stores values with a fixed size; it is an error to query a database with the wrong size.

Many common types are defined in the NameDB::DBType enumeration, but NameInfo allows arbitrary other types to be added at run time.

Here's an example of how to query NameInfo:

EtherAddress ethaddr;
if (NameInfo::query(NameInfo::T_ETHERNET_ADDR, this, name, &ethaddr, 6))
click_chatter("Found address!");
else
click_chatter("Didn't find address.");
An Ethernet address.
Definition etheraddress.hh:9
static bool query(uint32_t type, const Element *context, const String &name, void *value_store, size_t value_size)
Query installed databases for name.
Definition nameinfo.cc:500
@ T_ETHERNET_ADDR
Ethernet address names database.
Definition nameinfo.hh:45

Many elements also add their own databases to NameInfo; see, for example, the IPNameInfo or IPFilter elements for examples.

Member Enumeration Documentation

◆ DBType

Known name database types.

Enumerator
T_NONE 

Nonexistent names database.

T_SCHEDULEINFO 

ScheduleInfo database.

T_ANNOTATION 

Packet annotation database.

T_SCRIPT_INSN 

Script instruction names database.

T_SIGNO 

User-level signal names database.

T_SPINLOCK 

Spinlock names database.

T_ETHERNET_ADDR 

Ethernet address names database.

T_IP_ADDR 

IP address names database.

T_IP_PREFIX 

IP prefix names database.

T_IP_PROTO 

IP protocol names database.

T_IPFILTER_TYPE 

IPFilter instruction names database.

T_TCP_OPT 

TCP option names database.

T_IPREWRITER_PATTERN 

IPRewriterPattern database.

T_ICMP_TYPE 

ICMP type names database.

T_ICMP_CODE 

ICMP code names database.

T_IP_PORT 

Starting point for IP per-protocol port names databases.

T_TCP_PORT 

TCP port names database.

T_UDP_PORT 

UDP port names database.

T_IP_FIELDNAME 

Starting point for IP per-protocol field names databases.

T_ICMP_FIELDNAME 

ICMP field names database.

T_TCP_FIELDNAME 

TCP field names database.

T_UDP_FIELDNAME 

UDP field names database.

T_IP6_ADDR 

IPv6 address names database.

T_IP6_PREFIX 

IPv6 prefix names database.

Constructor & Destructor Documentation

◆ NameInfo()

NameInfo::NameInfo ( )

Construct a NameInfo element.

Users never need to call this.

◆ ~NameInfo()

NameInfo::~NameInfo ( )

Destroy a NameInfo object.

Also destroys all NameDB objects installed on this NameInfo.

Users never need to call this.

Member Function Documentation

◆ static_initialize()

void NameInfo::static_initialize ( )
static

Static initialization for NameInfo.

Creates the global NameInfo used for databases unconnected to any router. Users never need to call this.

◆ static_cleanup()

void NameInfo::static_cleanup ( )
static

Static cleanup for NameInfo.

Destroys the global NameInfo used for databases unconnected to any router. Users never need to call this.

◆ getdb()

NameDB * NameInfo::getdb ( uint32_t  type,
const Element *  context,
size_t  value_size,
bool  create 
)
static

Find or create a name database.

Parameters
typedatabase type
contextcompound element context
value_sizesize of values stored in database
createwhether to create a DynamicNameDB if no database exists

Returns an installed name database matching type and context. (If context is non-null, then the database matches the implied router and compound element context. Otherwise, the database is the unique global database for the given type.) If create is true, and no database exists exactly matching type and context, then a DynamicNameDB is created and installed with that type, context, and value_size. Otherwise, the search bubbles up through the prefixes of context until an installed database is found.

Returns null if no installed database is found. value_size must match the value size in the returned database.

Most users will use query() and define() directly, not call getdb().

◆ installdb()

void NameInfo::installdb ( NameDB *  db,
const Element *  context 
)
static

Install a name database.

Parameters
dbname database
contextcompound element context

Installs the given name database for the compound element context implied by context. (If context is non-null, then the database is installed for the implied router and compound element context. If it is null, the database is installed globally.) The query() and define() operations apply only to installed databases.

It is an error to install a database that has already been installed. It is also an error to install a database for a compound element context that already has a different database installed. An installed NameDB is automatically destroyed when its containing NameInfo is destroyed (for example, when context's router is destroyed).

◆ uninstalldb()

void NameInfo::uninstalldb ( NameDB *  db)
static

Uninstall a name database.

Parameters
dbname database

Undoes the effects of installdb(). The given database will no longer be used for query() and define() operations.

◆ query()

bool NameInfo::query ( uint32_t  type,
const Element *  context,
const String &  name,
void *  value_store,
size_t  value_size 
)
static

Query installed databases for name.

Parameters
typedatabase type
contextcompound element context
namename to look up
value_storevalue storage
value_sizesize of value storage
Returns
true iff the query succeeded

Queries all installed type databases that apply to the compound element context, returning the most specific value matching name. The value is stored in value_store. The installed databases must have the given value_size.

◆ query_int() [1/2]

bool NameInfo::query_int ( uint32_t  type,
const Element *  context,
const String &  name,
int32_t *  value_store 
)
static

Query installed databases for name, returning a 32-bit integer value.

Parameters
typedatabase type
contextcompound element context
namename to look up
value_storevalue storage
Returns
true iff the query succeeded

Queries all installed type databases that apply to the compound element context, returning the most specific value matching name. The value is stored in value_store. The installed databases must have a value size of 4.

If no matching name is found, query_int checks whether name unparses into a 32-bit integer value (for example, "30"). If so, *value_store is set to the corresponding integer and true is returned. Otherwise, false is returned.

◆ query_int() [2/2]

bool NameInfo::query_int ( uint32_t  type,
const Element *  context,
const String &  name,
uint32_t *  value_store 
)
static

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ revquery()

String NameInfo::revquery ( uint32_t  type,
const Element *  context,
const void *  value,
size_t  value_size 
)
static

Query installed databases for value.

Parameters
typedatabase type
contextcompound element context
valuepoints to value to look up
value_sizesize of value
Returns
the name, or the empty string if the query failed

Queries all installed type databases that apply to the compound element context, returning the name in the most specific database whose value matches value, or the empty string if the relevant databases don't support reverse queries or no such value exists. The installed databases must have the given value_size.

◆ revquery_int()

String NameInfo::revquery_int ( uint32_t  type,
const Element *  context,
int32_t  value 
)
inlinestatic

Query installed databases for a 32-bit integer value.

Parameters
typedatabase type
contextcompound element context
valuevalue to look up
Returns
the name, or the empty string if the query failed

Queries all installed type databases that apply to the compound element context, returning the name in the most specific database whose value matches value, or the empty string if the relevant databases don't support reverse queries or no such value exists. The installed databases must have value size 4.

◆ define()

bool NameInfo::define ( uint32_t  type,
const Element *  context,
const String &  name,
const void *  value,
size_t  value_size 
)
inlinestatic

Define name to equal value in the installed databases.

Parameters
typedatabase type
contextcompound element context
namename to define
valuepoints to defined value
value_sizesize of value
Returns
true iff the name was defined

Defines the given name to value in the installed type database with compound element context. If no database exists exactly matching that type and context, a new DynamicNameDB is created and installed with those values (and the given value_size). A name might not be defined if the existing database for that type and context doesn't support definitions, or if no new database can be created. If any database exists, it must match the given value_size.

◆ define_int()

bool NameInfo::define_int ( uint32_t  type,
const Element *  context,
const String &  name,
int32_t  value 
)
inlinestatic

Define name to equal 32-bit integer value in the installed databases.

Parameters
typedatabase type
contextcompound element context
namename to define
valuedefined value
Returns
true iff the value was defined

Defines the given name to value in the installed type database with compound element context. If no database exists exactly matching that type and context, a new DynamicNameDB is created and installed with those values (and value size 4). A name might not be defined if the existing database for that type and context doesn't support definitions, or if no new database can be created. If any database exists, it must have value size 4.


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