Your IP : 18.189.170.65


Current Path : /usr/lib/python3.6/site-packages/tuned/plugins/__pycache__/
Upload File :
Current File : //usr/lib/python3.6/site-packages/tuned/plugins/__pycache__/plugin_net.cpython-36.pyc

3

�<�e�Z�@spddlZddlmZddlTddlZddlmZddlm	Z	ddl
Z
ddlZejj
�ZdZGdd	�d	ej�ZdS)
�N�)�hotplug)�*)�ethcard)�commandsZpumbagsdcs.eZdZdZ�fdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
edd��Zedd��Z
edd��Zedd��Zedd��Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zed(d)��Zed*d+d,�d-d.��Zed*�did0d1��Zed2�d3d4��Zed2�d5d6��Zgfd7d8�Zdjd:d;�Z ed<d+d,�d=d>��Z!d?d@�Z"ed<�dkdAdB��Z#edCd+d,�dDdE��Z$edC�dldFdG��Z%dHdI�Z&dJdK�Z'dLdM�Z(dNdO�Z)dPdQ�Z*dRdS�Z+dTdU�Z,dmdVdW�Z-dXdY�Z.e/dZd+d,�d[d\��Z0e/d]d+d,�d^d_��Z1e/d`d+d,�dadb��Z2e/dcd+d,�ddde��Z3e/dfd+d,�dgdh��Z4�Z5S)n�NetTuningPlugina�
	`net`::
	
	Configures network driver, hardware and Netfilter settings.
	Dynamic change of the interface speed according to the interface
	utilization is also supported. The dynamic tuning is controlled by
	the [option]`dynamic` and the global [option]`dynamic_tuning`
	option in `tuned-main.conf`.
	+
	The [option]`wake_on_lan` option sets wake-on-lan to the specified
	value as when using the `ethtool` utility.
	+
	.Set Wake-on-LAN for device eth0 on MagicPacket(TM)
	====
	----
	[net]
	devices=eth0
	wake_on_lan=g
	----
	====
	+
	The [option]`coalesce` option allows changing coalescing settings
	for the specified network devices. The syntax is:
	+
	[subs="+quotes,+macros"]
	----
	coalesce=__param1__ __value1__ __param2__ __value2__ ... __paramN__ __valueN__
	----
	Note that not all the coalescing parameters are supported by all
	network cards. For the list of coalescing parameters of your network
	device, use `ethtool -c device`.
	+	
	.Setting coalescing parameters rx/tx-usecs for all network devices
	====
	----
	[net]
	coalesce=rx-usecs 3 tx-usecs 16
	----
	====
	+
	The [option]`features` option allows changing 
	the offload parameters and other features for the specified
	network devices. To query the features of your network device,
	use `ethtool -k device`. The syntax of the option is the same as
	the [option]`coalesce` option.
	+
	.Turn off TX checksumming, generic segmentation and receive offload 
	====
	----
	[net]
	features=tx off gso off gro off
	----
	====
	The [option]`pause` option allows changing the pause parameters for
	the specified network devices. To query the pause parameters of your
	network device, use `ethtool -a device`. The syntax of the option
	is the same as the [option]`coalesce` option.
	+
	.Disable autonegotiation
	====
	----
	[net]
	pause=autoneg off
	----
	====
	+
	The [option]`ring` option allows changing the rx/tx ring parameters
	for the specified network devices. To query the ring parameters of your
	network device, use `ethtool -g device`. The syntax of the option
	is the same as the [option]`coalesce` option.
	+	
	.Change the number of ring entries for the Rx/Tx rings to 1024/512 respectively
	=====
	-----
	[net]
	ring=rx 1024 tx 512
	-----
	=====
	+
	The [option]`channels` option allows changing the numbers of channels
	for the specified network device. A channel is an IRQ and the set
	of queues that can trigger that IRQ. To query the channels parameters of your
	network device, use `ethtool -l device`. The syntax of the option
	is the same as the [option]`coalesce` option.
	+
	.Set the number of multi-purpose channels to 16
	=====
	-----
	[net]
	channels=combined 16
	-----
	=====
	+   
	A network device either supports rx/tx or combined queue
	mode. The [option]`channels` option automatically adjusts the
	parameters based on the mode supported by the device as long as a
	valid configuration is requested.
	+
	The [option]`nf_conntrack_hashsize` option sets the size of the hash
	table which stores lists of conntrack entries by writing to
	`/sys/module/nf_conntrack/parameters/hashsize`.
	+
	.Adjust the size of the conntrack hash table
	====
	----
	[net]
	nf_conntrack_hashsize=131072
	----
	====
	+
	The [option]`txqueuelen` option allows changing txqueuelen (the length
	of the transmit queue). It uses `ip` utility that is in package	iproute
	recommended for TuneD, so the package needs to be installed for its correct
	functionality. To query the txqueuelen parameters of your network device
	use `ip link show` and the current value is shown after the qlen column.
	+
	.Adjust the length of the transmit queue
	====
	----
	[net]
	txqueuelen=5000
	----
	====
	+
	The [option]`mtu` option allows changing MTU (Maximum Transmission Unit).
	It uses `ip` utility that is in package	iproute recommended for TuneD, so
	the package needs to be installed for its correct functionality. To query
	the MTU parameters of your network device use `ip link show` and the
	current value is shown after the MTU column.
	+
	.Adjust the size of the MTU
	====
	----
	[net]
	mtu=9000
	----
	====
	cs6tt|�j||�d|_d|_t�|_i|_d|_dS)Ng�������?�T)	�superr�__init__�_load_smallest�_level_stepsr�_cmd�_re_ip_link_show�_use_ip)�self�args�kwargs)�	__class__�� /usr/lib/python3.6/plugin_net.pyr
�szNetTuningPlugin.__init__cCshd|_t�|_t�|_tjd�}x.|jjd�D]}|j|j	�r.|jj
|j�q.Wtj
dt|j��dS)NTz(?!.*/virtual/.*)�netzdevices: %s)Z_devices_supported�setZ
_free_devicesZ_assigned_devices�re�compile�_hardware_inventoryZget_devices�matchZdevice_path�addZsys_name�log�debug�str)rZre_not_virtual�devicerrr�
_init_devices�s
zNetTuningPlugin._init_devicescs�fdd�|D�S)Ncsg|]}�jjd|��qS)r)rZ
get_device)�.0�x)rrr�
<listcomp>�sz7NetTuningPlugin._get_device_objects.<locals>.<listcomp>r)rZdevicesr)rr�_get_device_objects�sz#NetTuningPlugin._get_device_objectscCsXd|_|j|jd�r<d|_|jjd|j�|_i|_i|_	nd|_d|_d|_d|_	dS)NT�dynamicrF)
Z_has_static_tuningZ_option_boolZoptionsZ_has_dynamic_tuning�_monitors_repositoryZcreateZassigned_devices�
_load_monitor�_idle�_stats)r�instancerrr�_instance_init�szNetTuningPlugin._instance_initcCs"|jdk	r|jj|j�d|_dS)N)r(r'�delete)rr+rrr�_instance_cleanup�s
z!NetTuningPlugin._instance_cleanupcCs|j||�dS)N)�_instance_update_dynamic)rr+r rrr�_instance_apply_dynamic�sz'NetTuningPlugin._instance_apply_dynamiccCs<dd�|jj|�D�}|dkr"dS||jkr8|j||�|j|||�|j||�|j|}|j|}|ddkr�|d|jkr�|d|jkr�d|d<tj	d|�t
|�jd	�nF|ddkr�|ddks�|ddkr�d|d<tj	d
|�t
|�j�tj
d||d|df�tj
d||d|d|df�dS)
NcSsg|]}t|��qSr)�int)r"�valuerrrr$�sz<NetTuningPlugin._instance_update_dynamic.<locals>.<listcomp>�levelr�read�writerz%s: setting 100Mbps�dz%s: setting max speedz %s load: read %0.2f, write %0.2fz$%s idle: read %d, write %d, level %d)r(Zget_device_loadr*�_init_stats_and_idle�
_update_stats�_update_idler)rr�inforZ	set_speed�
set_max_speedr)rr+r �loadZstatsZidlerrrr/�s&


($z(NetTuningPlugin._instance_update_dynamiccCs2ddddddddddddddddddddddd�S)N)zadaptive-rxzadaptive-txzrx-usecsz	rx-frameszrx-usecs-irqz
rx-frames-irqztx-usecsz	tx-framesztx-usecs-irqz
tx-frames-irqzstats-block-usecszpkt-rate-lowzrx-usecs-lowz
rx-frames-lowztx-usecs-lowz
tx-frames-lowz
pkt-rate-highz
rx-usecs-highzrx-frames-highz
tx-usecs-highztx-frames-highzsample-intervalr)�clsrrr�_get_config_options_coalesce�s,z,NetTuningPlugin._get_config_options_coalescecCsdddd�S)N)�autoneg�rx�txr)r=rrr�_get_config_options_pause�sz)NetTuningPlugin._get_config_options_pausecCsddddd�S)N)r@zrx-minizrx-jumborAr)r=rrr�_get_config_options_ringsz(NetTuningPlugin._get_config_options_ringcCsddddd�S)N)r@rA�other�combinedr)r=rrr�_get_config_options_channelssz,NetTuningPlugin._get_config_options_channelscCsddddddddddd�
S)NT)
r&�wake_on_lan�nf_conntrack_hashsize�features�coalesce�pause�ring�channels�
txqueuelen�mtur)r=rrr�_get_config_optionssz#NetTuningPlugin._get_config_optionscCsF|jt|�j��}ddgd|dgd�|j|<dddd�|j|<dS)N�r�r)�new�max)r3r4r5)�_calc_speedrZ
get_max_speedr*r))rr+r Z	max_speedrrrr7sz$NetTuningPlugin._init_stats_and_idlecCs�|j|d|j|d<}||j|d<dd�t||�D�}||j|d<|j|d}dd�t||�D�}||j|d<t|d�t|d�|j|d	<t|d
�t|d
�|j|d<dS)NrS�oldcSsg|]}|d|d�qS)rrr)r"Znew_oldrrrr$(sz1NetTuningPlugin._update_stats.<locals>.<listcomp>�diffrTcSsg|]}t|��qSr)rT)r"Zpairrrrr$-srr4rRr5)r*�zip�float)rr+r Znew_loadZold_loadrWZold_max_loadZmax_loadrrrr8"s"zNetTuningPlugin._update_statscCsLxFdD]>}|j|||jkr6|j||d7<qd|j||<qWdS)Nr4r5rr)r4r5)r*rr))rr+r Z	operationrrrr94s
zNetTuningPlugin._update_idlecCsH||jkrD|j|ddkrDd|j|d<tjd|�t|�j�dS)Nr3rz%s: setting max speed)r)rr:rr;)rr+r rrr�_instance_unapply_dynamic<sz)NetTuningPlugin._instance_unapply_dynamiccCstd|d�S)Ng333333�?i�g333333�@g333333#A)r1)rZspeedrrrrUBszNetTuningPlugin._calc_speedcCs�|jj|�}ttjdd|��j�}t|�}|ddkrPtjd|t|�f�dS|dkr^t	�St	t
t|ddd�|ddd����S)Nz (:\s*)|(\s+)|(\s*;\s*)|(\s*,\s*)� rRrzinvalid %s parameter: '%s'r)Z
_variables�expandrr�sub�split�lenr�error�dict�listrX)rr2�context�vZlvrrr�_parse_config_parametersKsz(NetTuningPlugin._parse_config_parameterscCs||jjddddddddd	d
ddd
dddddd�|�}dd�|jd�D�}t|�dkrXdStdd�dd�|dd�D�D��S)Nzadaptive-rx:z
adaptive-tx:zrx-frames-low:zrx-frames-high:ztx-frames-low:ztx-frames-high:zlro:zrx:ztx:zsg:ztso:zufo:zgso:zgro:zrxvlan:ztxvlan:zntuple:zrxhash:)zAdaptive RX:z\s+TX:z
rx-frame-low:zrx-frame-high:z
tx-frame-low:ztx-frame-high:zlarge-receive-offload:zrx-checksumming:ztx-checksumming:zscatter-gather:ztcp-segmentation-offload:zudp-fragmentation-offload:zgeneric-segmentation-offload:zgeneric-receive-offload:zrx-vlan-offload:ztx-vlan-offload:zntuple-filters:zreceive-hashing:cSs2g|]*}tt|��dkrtjdt|��r|�qS)rz
\[fixed\]$)r`rr�search)r"rerrrr$ssz<NetTuningPlugin._parse_device_parameters.<locals>.<listcomp>�
rRcSsg|]}t|�dkr|�qS)rR)r`)r"�urrrr$xscSsg|]}tjdt|���qS)z:\s*)rr_r)r"rerrrr$xsr)r
�multiple_re_replacer_r`rb)rr2Zvlrrr�_parse_device_parametersZs0z(NetTuningPlugin._parse_device_parameterscCsdS)Nz,/sys/module/nf_conntrack/parameters/hashsizer)rrrr�_nf_conntrack_hashsize_pathzsz+NetTuningPlugin._nf_conntrack_hashsize_pathrGT)Z
per_devicecCs^|dkrdStjddt|��}tjdtd|�s@tjd�dS|sZ|jjdd|d|g�|S)	N�0�dz^[z]+$zIncorrect 'wake_on_lan' value.�ethtoolz-sZwol)	rr^rr�
WOL_VALUESr�warnr
�execute)rr2r �sim�removerrr�_set_wake_on_lan~s
z NetTuningPlugin._set_wake_on_lanFcCsXd}y:tjdtd|jjd|g�dtj�}|r<|jd�}Wntk
rRYnX|S)Nz.*Wake-on:\s*([z]+).*ror)rrrpr
rr�S�group�IOError)rr �ignore_missingr2�mrrr�_get_wake_on_lan�s(z NetTuningPlugin._get_wake_on_lanrHcCsN|dkrdSt|�}|dkrF|sB|jj|j�||r:tjgndd�|SdSdS)NrF)Zno_error)r1r
Z
write_to_filerl�errno�ENOENT)rr2rsrtZhashsizerrr�_set_nf_conntrack_hashsize�sz*NetTuningPlugin._set_nf_conntrack_hashsizecCs(|jj|j��}t|�dkr$t|�SdS)Nr)r
Z	read_filerlr`r1)rr2rrr�_get_nf_conntrack_hashsize�sz*NetTuningPlugin._get_nf_conntrack_hashsizecCsz|js
dSddg|}|jj|tjgdd�\}}}|tjkrRtjd�d|_dS|rvtjd�tjd||f�dS|S)	NZip�linkT)�	no_errorsZ
return_errz0ip command not found, ignoring for other devicesFzProblem calling ip commandz(rc: %s, msg: '%s'))	rr
rrr|r}rrqr:r)rrZrc�outZerr_msgrrr�
_call_ip_link�s

zNetTuningPlugin._call_ip_linkNcCsdg}|r|j|�|j|�S)NZshow)�appendr�)rr rrrr�
_ip_link_show�s
zNetTuningPlugin._ip_link_showrNcCsr|dkrdSyt|�Wn"tk
r:tjd|�dSX|sn|jdd|d|g�}|dkrntjd|�dS|S)Nz$txqueuelen value '%s' is not integerr�devrNz%Cannot set txqueuelen for device '%s')r1�
ValueErrorrrqr�)rr2r rsrt�resrrr�_set_txqueuelen�szNetTuningPlugin._set_txqueuelencCs(||jkrtjd|�|j|<|j|S)z@
		Return regex for int arg value from "ip link show" command
		z.*\s+%s\s+(\d+))rrr)r�argrrr�_get_re_ip_link_show�s
z$NetTuningPlugin._get_re_ip_link_showcCs`|j|�}|dkr(|s$tjd|�dS|jd�j|�}|dkrV|sRtjd|�dS|jd�S)NzECannot get 'ip link show' result for txqueuelen value for device '%s'ZqlenzFCannot get txqueuelen value from 'ip link show' result for device '%s'r)r�rr:r�rgrw)rr ryr�r�rrr�_get_txqueuelen�s
zNetTuningPlugin._get_txqueuelenrOcCsr|dkrdSyt|�Wn"tk
r:tjd|�dSX|sn|jdd|d|g�}|dkrntjd|�dS|S)Nzmtu value '%s' is not integerrr�rOzCannot set mtu for device '%s')r1r�rrqr�)rr2r rsrtr�rrr�_set_mtu�szNetTuningPlugin._set_mtucCs`|j|�}|dkr(|s$tjd|�dS|jd�j|�}|dkrV|sRtjd|�dS|jd�S)Nz>Cannot get 'ip link show' result for mtu value for device '%s'rOz?Cannot get mtu value from 'ip link show' result for device '%s'r)r�rr:r�rgrw)rr ryr�r�rrr�_get_mtu�s
zNetTuningPlugin._get_mtucCsl|dkrdSt|j��}|j|j|j|jd�}t||�j��}|j|�shtjd|t	||�f�dSdS)NrIT)rJrKrLrMzunknown %s parameter(s): %sF)
r�keysr>rBrCrF�issubsetrrar)rrdrnZparamsZsupported_getterZ	supportedrrr�_check_parameters
s

z!NetTuningPlugin._check_parameterscCsR|jjdddd�|�}|jd�dd�}dd�|D�}td	d�d
d�|D�D��S)Nr?r@rA)Z
Autonegotiate�RX�TXrhrcSs&g|]}|dkrtjd|�r|�qS)�z	\[fixed\])rrg)r"r#rrrr$sz;NetTuningPlugin._parse_pause_parameters.<locals>.<listcomp>cSsg|]}t|�dkr|�qS)rR)r`)r"r#rrrr$ scSsg|]}tjd|��qS)z:\s*)rr_)r"r#rrrr$ s)r
rjr_rb)r�s�lrrr�_parse_pause_parameterssz'NetTuningPlugin._parse_pause_parameterscCsjtjd|tjd�}|d}|jjddddd�|�}|jd	�}d
d�|D�}dd�d
d�|D�D�}t|�S)Nz^Current hardware settings:$)�flagsrr@zrx-minizrx-jumborA)r�zRX MinizRX Jumbor�rhcSsg|]}|dkr|�qS)r�r)r"r#rrrr$,sz:NetTuningPlugin._parse_ring_parameters.<locals>.<listcomp>cSsg|]}t|�dkr|�qS)rR)r`)r"r#rrrr$-scSsg|]}tjd|��qS)z:\s*)rr_)r"r#rrrr$-s)rr_�	MULTILINEr
rjrb)rr��ar�rrr�_parse_ring_parameters#s
z&NetTuningPlugin._parse_ring_parameterscCsjtjd|tjd�}|d}|jjddddd�|�}|jd	�}d
d�|D�}dd�d
d�|D�D�}t|�S)Nz^Current hardware settings:$)r�rr@rArDrE)r�r�ZOtherZCombinedrhcSsg|]}|dkr|�qS)r�r)r"r#rrrr$:sz>NetTuningPlugin._parse_channels_parameters.<locals>.<listcomp>cSsg|]}t|�dkr|�qS)rR)r`)r"r#rrrr$;scSsg|]}tjd|��qS)z:\s*)rr_)r"r#rrrr$;s)rr_r�r
rjrb)rr�r�r�rrr�_parse_channels_parameters1s
z*NetTuningPlugin._parse_channels_parameterscCszg}d|kr(|jd|dd|dg�n,ttt|d�t|d���}|jd|g�ttt|ddd�|ddd����S)NrEr@rrA�rR)�extendrrTr1rbrcrX)rrdZparams_list�
dev_paramsZmod_params_listZcntrrr�_replace_channels_parameters>sz,NetTuningPlugin._replace_channels_parametersc	CsRt|j��}t|j��}||}x,|D]$}tjd|||f�|j|d�q&WdS)aFilter unsupported parameters and log warnings about it

		Positional parameters:
		context -- context of change
		parameters -- parameters to change
		device -- name of device on which should be parameters set
		dev_params -- dictionary of currently known parameters of device
		z-%s parameter %s is not supported by device %sN)rr�rZwarning�pop)	rrdZ
parametersr r�Zsupported_parametersZparameters_to_changeZunsupported_parameters�paramrrr�_check_device_supportGs	

z%NetTuningPlugin._check_device_supportc
Cs�dddddd�}||}|jjd||g�\}}|dksBt|�dkrFdS|j|j|j|j|jd�}||}||�}	|d	kr�|j||	�r�dS|	S)
Nz-cz-kz-az-gz-l)rJrIrKrLrMrorrJ)r
rrr`rkr�r�r�r�)
rrdr �context2opt�opt�retr2Zcontext2parser�parserrnrrr�_get_device_parameters^s 
z&NetTuningPlugin._get_device_parametersc	Cs�|dkst|�dkrdS|j||�}|dks:|j||�r>iS|r�|j||||�|dkr�t|tt|���dkr�|j||jj	|�|�}|r�t|�dkr�t
jd|t|�f�dddd	d
d�}||}|jjd||g|jj	|�d
gd�|S)NrrM�n/armzsetting %s: %sz-Cz-Kz-Az-Gz-L)rJrIrKrLrMro�P)r�)r�rm)
r`rfr�r�r�next�iterr�r
�	dict2listrrrr)	rrdr2r rsr�rnr�r�rrr�_set_device_parametersps  $z&NetTuningPlugin._set_device_parameterscs�|j||d�}|r�|j||�}|dks2t|�dkr6dS|j|||||d���dks^t��dkrbdS�fdd�|j�D�}t|�}|r�|jj��|jj|�k}	|j||	�||d�|	S|j	j
|dj|jj|���n|j	j|�}
|j||
|d�dS)	N)Zcommand_nameZdevice_namerF)r�cs g|]\}}|�kr||f�qSrr)r"r�r2)�
params_setrrr$�sz6NetTuningPlugin._custom_parameters.<locals>.<listcomp>)r r\)
Z_storage_keyr�r`r��itemsrbr
r�Z_log_verification_resultZ_storager�join�get)rrd�startr2r �verifyZstorage_keyZparams_currentZrelevant_params_currentr��original_valuer)r�r�_custom_parameters�s:

z"NetTuningPlugin._custom_parametersrIcCs|jd||||�S)NrI)r�)rr�r2r r�ryrrr�	_features�szNetTuningPlugin._featuresrJcCs|jd||||�S)NrJ)r�)rr�r2r r�ryrrr�	_coalesce�szNetTuningPlugin._coalescerKcCs|jd||||�S)NrK)r�)rr�r2r r�ryrrr�_pause�szNetTuningPlugin._pauserLcCs|jd||||�S)NrL)r�)rr�r2r r�ryrrr�_ring�szNetTuningPlugin._ringrMcCs|jd||||�S)NrM)r�)rr�r2r r�ryrrr�	_channels�szNetTuningPlugin._channels)F)N)F)F)N)6�__name__�
__module__�__qualname__�__doc__r
r!r%r,r.r0r/�classmethodr>rBrCrFrPr7r8r9rZrUrfrkrlZcommand_setruZcommand_getr{r~rr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�Zcommand_customr�r�r�r�r��
__classcell__rr)rrrsd
	 



	
&r)r|r�rZ
decoratorsZ
tuned.logsZtunedZtuned.utils.nettoolrZtuned.utils.commandsr�osrZlogsr�rrpZPluginrrrrr�<module>s


?>