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


Python Filter.tc_add_filter方法代码示例

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


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

示例1: TShapper

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

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


	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

			self.devices[device_mac]["ips"] = list(discovered_ips)
			self.devices[device_mac]["last_seen"] = datetime.now()

			if len(ips_to_add) > 0:
				for ip in ips_to_add:
					self.filter.tc_add_filter(\
											self.devices[device_mac]['token'],
											ip, self.devices[device_mac])
					self.active_filters += 2

			#if len(ips_to_delete) > 0 and self.filter_delete_counter > self.FILTER_DELETE_INTERVAL:
			#	for ip in ips_to_delete:
			#		self.filter.tc_del_filter(self.devices[device_mac]['token'], ip, self.devices[device_mac])
			#		self.active_filters -= 2
			#	self.filter_delete_counter = 0
			#else:
			#	self.filter_delete_counter += 1


	def print_devices(self):
		for device, obj in self.devices.items():
			print "\n"+device
			for name, value in obj.items():
开发者ID:ABalanuta,项目名称:TrafficShapingRouter,代码行数:70,代码来源:trottle.py


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