Dns

class trex.emu.emu_plugins.emu_plugin_dns.DNSPlugin(emu_client)[source]

Defines a DNS - Domain Name System plugin based on DNS

Implemented based on RFCs 1034, 1035

Initialize a DNSPlugin.

parameters
emu_client: trex.emu.trex_emu_client.EMUClient

Valid EMU client.

INIT_JSON_NS = {'dns': '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.

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.

"program": {
    "00:00:01:00:00:01": {
        "hostnames": ["AppleTV"],
        "type": "TXT",
        "class": "Any"
    }
}
{
    "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 = {'dns': 'Pointer to INIT_JSON_CLIENT below'}
Parameters
name_server: bool

Indicate if client is represents a DNS Name Server. Name Servers answer queries based on a database. Default is False.

dns_server_ip: string

IPv4 or IPv6 of a DNS Name Server. Provide this only if the client is not a Name Server.

database: Dict[str, list]

Dictionary that represents the Name Server database. Provide this only if the client is a Name Server.

The keys are domain that can be queried. The database can have multiple answers for each domain, and these answers are aggregated in a list.

Each list is comprised of Dns entries, which are dictionaries.

Dns Entry

type: string

Dns Type. Supported values at the moment are A, AAAA, PTR and TXT. Defaults to A.

class: string

Dns Class. Defaults to IN.

answer: string

Answer for the domain if a query arrives with the correct type and class.

A simple database looks like this:

"database": {
    "trex-tgn.cisco.com": [
        {
            "type": "A",
            "class": "IN",
            "answer": "173.36.109.208"
        }
    ],
    "cisco.com": [
        {
            "type": "A",
            "class": "IN",
            "answer": "72.163.4.185"
        },
        {
            "type": "A",
            "class": "IN",
            "answer": "72.163.4.161"
        },
        {
            "type": "AAAA",
            "class": "IN",
            "answer": "2001:420:1101:1::185"
        }
    ]
}
get_client_counters(c_key, cnt_filter=None, zero=True, verbose=True)[source]

Get the DNS 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.

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 DNS counters of a client.

Parameters
c_key: trex.emu.trex_emu_profile.EMUClientKey

EMUClientKey

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 DNS 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.

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 DNS counters of a namespace.

Parameters
ns_key: trex.emu.trex_emu_profile.EMUNamespaceKey

EMUNamespaceKey

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 Dns query from a Dns Resolver to the Dns Name Server specified in the resolver’s init json.

Parameters
c_key: EMUClientKey

see trex.emu.trex_emu_profile.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 Dns query, supported types are A, AAAA, PTR, TXT. Default is A.

dns_class: string

Class of the Dns query. Default is IN.

Raises

TRexError

get_domains(c_key)[source]

Get registered domains in a DNS Name Server.

Parameters
c_key: EMUClientKey

see trex.emu.trex_emu_profile.EMUClientKey. Note that it must be a Name Server.

Returns

List of string, where each string is a domain.

get_domain_entries(c_key, domain)[source]

Get Dns entries for a domain from a DNS Name Server.

Parameters
c_key: EMUClientKey

see trex.emu.trex_emu_profile.EMUClientKey. Note that it must be a Name Server.

domain: str

Domain whose entries we are looking to get.

Returns

List of dictionaries, where each dictionary is a Dns Entry.

[
    {
        "type": "A",
        "class": "IN",
        "answer": "72.163.4.161"
    },
    {
        "type": "AAAA",
        "class": "IN",
        "answer": "2001:420:1101:1::185"
    }
]

add_domain_entries(c_key, domain, entries)[source]

Add domain entries to a DNS Name Server.

Parameters
c_key: EMUClientKey

see trex.emu.trex_emu_profile.EMUClientKey. Note that it must be a Name Server.

domain: str

Domain whose entries we are looking to add.

entries: list

List of Dns Entries.

[
    {
        "type": "A",
        "class": "IN",
        "answer": "72.163.4.161"
    },
    {
        "type": "AAAA",
        "class": "IN",
        "answer": "2001:420:1101:1::185"
    }
]
Returns

None

remove_domain_entries(c_key, domain, entries)[source]

Remove domain entries from a DNS Name Server.

Parameters
c_key: EMUClientKey

see trex.emu.trex_emu_profile.EMUClientKey. Note that it must be a Name Server.

domain: str

Domain whose entries we are looking to remove.

entries: list

List of Dns Entries.

[
    {
        "type": "A",
        "class": "IN",
        "answer": "72.163.4.161"
    },
    {
        "type": "AAAA",
        "class": "IN",
        "answer": "2001:420:1101:1::185"
    }
]
Returns

None

get_cache(c_key)[source]

Get resolved domains cache from a Dns Resolver.

Parameters
c_key: EMUClientKey

see trex.emu.trex_emu_profile.EMUClientKey. Note that it must be a Dns Resolver (not Name Server).

Returns

List of dictionaries

[
    {
        'dns_class': 'IN',
        'dns_type': 'A',
        'answer': '72.163.4.185',
        'name': 'cisco.com',
        'ttl': 240,
        'time_left': 238
    },
    {
        'dns_class': 'PTR',
        'dns_type': 'A',
        'answer': 'google.com',
        'name': '8.8.8.8.in-addr.arpa',
        'ttl': 40,
        'time_left': 211
    }
]

flush_cache(c_key)[source]

Flush Dns Resolver cache of resolved domains.

Parameters
c_key: EMUClientKey

see trex.emu.trex_emu_profile.EMUClientKey. Note that it must be a Dns Resolver (not Name Server).

dns_show_client_counters_line(line)[source]

Show DNS client counters.

dns_show_ns_counters_line(line)[source]

Show DNS namespace counters.

dns_query_line(line)[source]

Dns Query for Dns Resolver.

dns_show_domains_line(line)[source]

Show domains a Name Server holds.

dns_show_domain_entries_line(line)[source]

Show entries of Dns Domain in the Name Server.

tear_down_ns(ns_key)

This function will be called before removing this plugin from namespace.

parameters
ns_key: EMUNamespaceKey

see trex.emu.trex_emu_profile.EMUNamespaceKey

dns_show_cache_line(line)[source]

Show resolved domains for a Dns Resolver

dns_flush_cache_line(line)[source]

Flush Dns Resolver cache.

trex.emu.emu_plugins.emu_plugin_dns.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.