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


Python Filter.tc_del_filter方法代码示例

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


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

示例1: TShapper

# 需要导入模块: from filter import Filter [as 别名]
# 或者: from filter.Filter import tc_del_filter [as 别名]

#.........这里部分代码省略.........

	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))+"/"+\
				str(self.max_devices['Number'])+" at "+\
				str(self.max_devices['Time'])+" TokensUsed:"+\
				str(self.N_TOKENS - len(self.tokens))+" ActiveFilters:"+\
				str(self.active_filters)+self.get_speed(), 'green')


	def clean_old_devices(self):
		for device_mac, obj in self.devices.items():
			if (datetime.now() - obj["last_seen"]).total_seconds() > self.OLD_DEVICES_TIMEOUT:
				#obj = self.devices[device_mac]
				token = obj["token"]

				#Delete Filters
				for ip in obj["ips"]:
					self.filter.tc_del_filter(token, ip, obj)
					self.active_filters -= 2

				#Delete Class
				self.filter.tc_del_class(token, obj)
				del self.devices[device_mac]
				self.release_token(token)

	def update_device(self, device_mac, ips):

		#Add new Device
		if device_mac not in self.devices.keys():
			obj	  = { 	"mac":device_mac,
					"token":self.get_token(),
					"ips":ips,
					"last_seen":datetime.now(),
					"prefs": { "lan": dict(), "wan": dict() }
					}

			self.devices[device_mac] = obj
			self.filter.tc_add_device(obj)

			for ip in ips:
				self.filter.tc_add_filter(obj['token'], ip, obj)
				self.active_filters += 2

		#Modify Existing Device Rules
		else:
			old_ips = set(self.devices[device_mac]["ips"])
			discovered_ips = set(ips)
			ips_to_delete = old_ips - discovered_ips
			ips_to_add = discovered_ips - old_ips
开发者ID:ABalanuta,项目名称:TrafficShapingRouter,代码行数:69,代码来源:trottle.py


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