当前位置: 首页>>代码示例>>Python>>正文


Python Filter.init_tc_rules方法代码示例

本文整理汇总了Python中filter.Filter.init_tc_rules方法的典型用法代码示例。如果您正苦于以下问题:Python Filter.init_tc_rules方法的具体用法?Python Filter.init_tc_rules怎么用?Python Filter.init_tc_rules使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在filter.Filter的用法示例。


在下文中一共展示了Filter.init_tc_rules方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: TShapper

# 需要导入模块: from filter import Filter [as 别名]
# 或者: from filter.Filter import init_tc_rules [as 别名]
class TShapper(Thread):

	N_TOKENS        		= 8000
	SLEEP_INTERVAL  		= 2		#Seconds
	FILTER_DELETE_INTERVAL	= 30 		#Seconds
	OLD_DEVICES_TIMEOUT 	= 300 		#Seconds
	USE_SNMP				= False

	def __init__(self):
		Thread.__init__(self)
		logging.basicConfig(filename='trottle.log',level=logging.DEBUG)
		logging.basicConfig(format='%(asctime)s %(levelname)s %(message)s',\
						 	datefmt='%m/%d/%Y %I:%M:%S %p')

		self.stopped = False
		self.active_filters = 0
		self.filter_delete_counter = 0
		self.tokens			= list()
		self.devices 		= dict()
		self.max_devices 	= {
								'Number': 0,
								'Time'  : datetime.now()
								}
		self.speed 			= {
								'Down'			: 0,
								'Up'			: 0,
								'Last_Update'	: datetime.now()
								}

		self.filter = Filter()
		self.generate_tokens()
		if self.USE_SNMP:
			self.SNMPDetector = SNMPDetector()
			self.SNMPDetector.start()

	def generate_tokens(self):
		for i in range(1, self.N_TOKENS+1):
			self.tokens.append(i)

	def get_token(self):
		return self.tokens.pop(0)

	def release_token(self, token):
		self.tokens.append(token)

	def stop(self):
		self.stopped = True

		#Deletes the TC Rules
		self.filter.destroy_tc_rules()

		if self.USE_SNMP:
			self.SNMPDetector.stop()

	def restart(self):
		#Deletes the TC Rules
		self.filter.destroy_tc_rules()

		#Restarts Objects
		self.__init__()

		#Starts the new TC Rules
		self.filter.init_tc_rules()

	def run(self):

		#Starts the new TC Rules
		self.filter.init_tc_rules()

		#Updates the TC Rules
		while not self.stopped:

			try:
				self.update()
			except KernelError as e:
				cprint("KERNEL ERROR: Restarting ", 'red')
				logging.warning("KernelError:"+str(e))
				sleep(2)
				self.restart()

			sleep(self.SLEEP_INTERVAL)

	def update(self):
		#cprint("Update", 'white')

		if self.USE_SNMP:
			updated_devices = self.get_devices_adresses_from_snmp()
		else:
			updated_devices = self.get_devices_adresses()
		
		for device_mac, ips in updated_devices.items():
			self.update_device(device_mac, ips)

		self.clean_old_devices()

		if len(self.devices) > self.max_devices['Number']:
			self.max_devices['Number'] = len(self.devices)
			self.max_devices['Time'] = datetime.now()

		cprint("Current Clients/Max:"+str(len(self.devices))+"/"+\
#.........这里部分代码省略.........
开发者ID:ABalanuta,项目名称:TrafficShapingRouter,代码行数:103,代码来源:trottle.py


注:本文中的filter.Filter.init_tc_rules方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。