mDNS¶
- class trex.emu.emu_plugins.emu_plugin_mdns.MDNSPlugin(emu_client)[source]¶
Defines a mDNS (Multicast DNS) plugin based on mDNS
Implemented based on RFC 6762
Initialize a MDnsPlugin.
- parameters
- emu_client:
trex.emu.trex_emu_client.EMUClient Valid EMU client.
- emu_client:
- INIT_JSON_NS = {'mdns': 'Pointer to INIT_JSON_NS below'}¶
- Parameters
- auto_play: bool
Indicate if should automatically start generating traffic. Defaults to False.
- auto_play_params: dictionary.
Dictionary specifying the paramaters of auto play, should be provided only in case autoplay is defined.
- auto_play_params
- rate: float
Rate in seconds between two consequent queries. Defaults to 1.0.
- query_amount: uint64
Amount of queries to send. Defaults to 0. The default value (zero) means infinite amount of queries.
- min_client: string
String representing the MAC address of the first client in the range of clients that will query. For example “00:00:00:70:00:01”.
- max_client: string
String representing the MAC address of the last client in the range of clients that will query.
- client_step: uint16
Incremental step between two consecutive clients. Defaults to 1.
- hostname_template: string
String that will be used as template format for hostname in queries. One number will be injected in it. The number should be represented with %v, because the backend is in Golang.
- min_hostname: uint16
Unsigned integer representing the minimal value that can be applied to hostname_template.
- max_hostname: uint16
Unsigned integer representing the maximal value that can be applied to hostname_template.
- init_hostname: uint16
Unsigned integer representing the initial value that can be applied to hostname_template. Defaults to min_hostname.
- hostname_step: uint16
Incremental step between two consecutive hostnames. Defaults to 1.
- type: string
Dns Type. Allowed values are A, AAA, PTR and TXT. Defaults to A.
- class: string
Dns Class. Defaults to IN.
- ipv6: bool
Indicate if should send IPv6 traffic. Defaults to False.
- program: dictionary
Dictionary representing special/uncommon queries for clients. If a client entry is specified here, this has precedence over the standard query.
- key
string MAC address of the client that sends the query.
- value
dictionary
- hostnames: list
List of strings that specifies which hostnames to query.
- type: string
Dns Type. Allowed values are A, AAA, PTR and TXT. Defaults to A.
- class: string
Dns Class. Defaults to IN.
- ipv6: bool
Indicate if should send IPv6 traffic. Defaults to False.
"program": { "00:00:01:00:00:01": { "hostnames": ["AppleTV"], "type": "TXT", "ipv6": true } }
{ "auto_play": true, "auto_play_params": { "rate": 1.0, "query_amount": 5, "min_client": "00:00:01:00:00:00", "max_client": "00:00:01:00:00:02", "hostname_template": "client-%v" "min_hostname": 0, "max_hostname": 2, "init_hostname": 1, "hostname_step": 1, "program": { "00:00:01:00:00:02": { "hostnames": ["UCS", "AppleTV"], "type": "TXT", } } } }
- INIT_JSON_CLIENT = {'mdns': 'Pointer to INIT_JSON_CLIENT below'}¶
- Parameters
- hosts: list
List of hosts (strings) this client owns.
- ttl: uint32
Time to live to set in mDNS replies. Defaults to 240.
- domain_name: string
Domain Name to set in PTR replies.
- txt: list
List of dictionaries that define the data in a TXT reply. Each dictionary looks like:
- dictionary
field: string
Field like HW, OS etc.
value: string
Value of the field.
"txt": [ { "field": "HW", "value": "Cisco UCS 220M5" }, { "field": "OS", "value": "Ubuntu 20.04", } ]
- get_client_counters(c_key, cnt_filter=None, zero=True, verbose=True)[source]¶
Get the mDNS counters of a client.
- Parameters
- c_key:
trex.emu.trex_emu_profile.EMUClientKey EMUClientKey
- cnt_filter: list
List of counters types as strings. i.e: [‘INFO’, ‘ERROR’, ‘WARNING’]. Default is None, means no filter. If verbosity is off, this filter can’t be used.
- zero: bool
Get zero values, default is True.
- verbose: bool
Show verbose version of each counter, default is True.
- c_key:
- Returns
Dictionary of all wanted counters. When verbose is True, each plugin contains a list of counter dictionaries.
{'pluginName': [{'help': 'Explanation 1', 'info': 'INFO', 'name': 'counterOne', 'unit': 'pkts', 'value': 8, 'zero': False}, {'help': 'Explanation 2', 'info': 'ERROR', 'name': 'counterTwo', 'unit': 'pkts', 'value': 6, 'zero': False}]}
When verbose is False, each plugins returns a dictionary of counterName, value pairs.
{'pluginName': {'counterOne': 8, 'counterTwo': 6}}
- Raises
TRexError
- clear_client_counters(c_key)[source]¶
Clear the mDNS counters of a client.
- Parameters
- c_key:
trex.emu.trex_emu_profile.EMUClientKey EMUClientKey
- c_key:
- Returns
- Boolean indicating if clearing was successful.
True: Clearing was successful.
False: Clearing was not successful.
- Raises
TRexError
- get_ns_counters(ns_key, cnt_filter=None, zero=True, verbose=True)[source]¶
Get the mDNS counters of a namespace.
- Parameters
- ns_key:
trex.emu.trex_emu_profile.EMUNamespaceKey EMUNamespaceKey
- cnt_filter: list
List of counters types as strings. i.e: [‘INFO’, ‘ERROR’, ‘WARNING’]. Default is None, means no filter. If verbosity is off, this filter can’t be used.
- zero: bool
Get zero values, default is True.
- verbose: bool
Show verbose version of each counter, default is True.
- ns_key:
- Returns
Dictionary of all wanted counters. When verbose is True, each plugin contains a list of counter dictionaries.
{'pluginName': [{'help': 'Explanation 1', 'info': 'INFO', 'name': 'counterOne', 'unit': 'pkts', 'value': 8, 'zero': False}, {'help': 'Explanation 2', 'info': 'ERROR', 'name': 'counterTwo', 'unit': 'pkts', 'value': 6, 'zero': False}]}
When verbose is False, each plugins returns a dictionary of counterName, value pairs.
{'pluginName': {'counterOne': 8, 'counterTwo': 6}}
- Raises
TRexError
- clear_ns_counters(ns_key)[source]¶
Clear the mDNS counters of a namespace.
- Parameters
- ns_key:
trex.emu.trex_emu_profile.EMUNamespaceKey EMUNamespaceKey
- ns_key:
- Returns
- Boolean indicating if clearing was successful.
True: Clearing was successful.
False: Clearing was not successful.
- Raises
TRexError
- query(c_key, queries)[source]¶
Send a mDNS query.
- Parameters
- c_key: EMUClientKey
- queries: list
List of query, where each query is represented by:
- query
- name: string
Name of the host we are querying.
- dns_type: string
Type of the mDNS query, supported types are A, AAAA, PTR, TXT. Default is “A”.
- dns_class: string
Class of the mDNS query. Default is “IN”.
- ipv6: bool
Indicate if the query should be sent using IPv6.
- Raises
TRexError
- add_remove_hosts(c_key, op, hosts)[source]¶
Add or Remove hosts (hostnames) from a mDNS client.
- Parameters
- c_key: EMUClientKey
- op: bool
- Operation:
False to add.
True to remove.
- hosts: list
List of strings, where each string represents a hostname to add or remove.
- Returns
In case of add, the already existing hosts (as a list) or a string if only one.
In case of remove, the non existing hosts (as a list) or a string if only one.
None otherwise.
- get_client_hosts(c_key)[source]¶
Get hostnames of a mDNS client.
- Parameters
- c_key: EMUClientKey
- Returns
- Hostnames the client owns:
List of strings in case there are many
String in case there is only one hostname
None in case there are no hostnames.
- get_cache(ns_key)[source]¶
Get resolved hosts (hostnames) cache from a mDNS namespace.
- Parameters
- ns_key: EMUNamespaceKey
- Returns
List of dictionaries
[ { 'dns_class': 'IN', 'dns_type': 'A', 'answer': '1.1.1.6', 'name': 'trex', 'ttl': 240, 'time_left': 238 }, { 'dns_class': 'IN', 'dns_type': 'A', 'answer': '1.1.1.5', 'name': 'UCS', 'ttl': 240, 'time_left': 211 } ]
- flush_cache(ns_key)[source]¶
Flush mDNS namespace cache of resolved hostnames.
- Parameters
- ns_key: EMUNamespaceKey
- tear_down_ns(ns_key)¶
This function will be called before removing this plugin from namespace.
- parameters
- ns_key: EMUNamespaceKey
- trex.emu.emu_plugins.emu_plugin_mdns.wraps(func)¶
Replaces functools.wraps in order to undo wrapping.
Can be used to preserve the decorated function’s signature in the documentation generated by Sphinx.