DHCP Server¶
- class trex.emu.emu_plugins.emu_plugin_dhcpsrv.DHCPSRVPlugin(emu_client)[source]¶
Defines DHCP Server plugin based on DHCP
Implemented based on RFC 2131 Server
- INIT_JSON_NS = {'dhcpsrv': {}}¶
- Parameters
Empty.
- INIT_JSON_CLIENT = {'dhcpsrv': 'Pointer to INIT_JSON_NS below'}¶
- Parameters
- default_lease: uint32
Default lease time in seconds to offer to DHCP clients. Defaults to 300 seconds, 5 mins.
- max_lease: uint32
Maximal lease time in seconds that the server is willing to offer the client in case he requests a specific lease. If default_lease is provided and greater than an unprovided max_lease, then max_lease will be overridden by default_lease. Defaults to 600 seconds, 10 mins.
- min_lease: uint32
Minimal lease time in seconds that the server is willing to offer the client in case he requests a specific lease. If default_lease is provided and less than an unprovided min_lease, then min_lease will be overridden by default_lease. Defaults to 60 seconds, 1 min.
- next_server_ip: str
IPv4 address of the next server as a field. In case you provide it, the server will write the IPv4 as the next server IPv4 in the packets it sends. Defaults to 0.0.0.0.
- pools: list
List of dictionaries that represent IPv4 pools or otherwise known as scopes. At lease one pool must be provided. Each dictionary is composed of:
- min
str
Minimal IPv4 address of the pool. If this happens to be the Network Id, this address will be skipped.
- max
str
Maximal IPv4 address of the pool. If this happens to be the Broadcast Id, this address will be skipped.
- prefix
uint8
Subnet Mask represented as a prefix, an unsigned integer between (0, 32) non exclusive.
- exclude
list
List of IPv4 strings that are excluded from the pool and can’t be offered to the client.
Note
Two different pools cannot be in the same subnet. If two pools share the same subnet, with the current implementation we will always offer an IP from the first pool in the list.
"pools": [ { "min": "192.168.0.0", "max": "192.168.0.100", "prefix": 24, "exclude": ["192.168.0.1", "192.168.0.2"] }, { "min": "10.0.0.2", "max": "10.0.255.255", "prefix": 8 } ]
- options: dict
Dictionary that contains DHCP Options. There are three keys possible: offer, ack and nak. Each key represents a DHCP Response that the server can send.
Each key’s value is a list. The list is composed by dictionaries, where each dictionary represents a DHCP option.
Options are represented by their type (byte), and their value (byte list).
In the following example, we add the following options to offer and ack responses.
Type: 6 (DNS Server) -> Value (8.8.8.8)
Type: 15 (Domain Name) -> Value cisco.com
"options": { "offer": [ { "type": 6, "data": [8, 8, 8, 8] }, { "type": 15, "data": [99, 105, 115, 99, 111, 46, 99, 111, 109] } ] "ack": [ { "type": 6, "data": [8, 8, 8, 8] }, { "type": 15, "data": [99, 105, 115, 99, 111, 46, 99, 111, 109] } ] }
- get_counters(c_key, cnt_filter=None, zero=True, verbose=True)[source]¶
Get the DHCPSRV 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
- tear_down_ns(ns_key)¶
This function will be called before removing this plugin from namespace.
- parameters
- ns_key: EMUNamespaceKey
- clear_counters(c_key)[source]¶
Clear the DHCPSRV 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
- trex.emu.emu_plugins.emu_plugin_dhcpsrv.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.