我正在使用GitHub的代码,通过泛光灯控制器中的反应流规则来缓解DDoS攻击。我无法运行该程序,因为没有定义全局变量attacked_switches
,但我不知道如何执行该操作。有人能帮我吗
def start():
try:
number_of_switches, number_of_hosts = topology_info()
switch_dpids = list()
hosts = dict()
switch_dpids = switch_info(number_of_switches, switch_dpids)
hosts = host_info(number_of_hosts, hosts)
dpid = switch_byte(number_of_switches, switch_dpids)
print 'dpid= ', dpid
if dpid != 0:
print'calling flow pusher'
global attack
attack = True
attacked_switches.add(dpid)
T2 = threading.Thread(target=Flowpusher, args=[dpid])
T2.start()
elif attack:
T3 = threading.Thread(target=Flowremover, args=[dpid])
T3.start()
except Exception as e:
print'Error occured:', e
您只需在变量名之前(变量的第一个asignment之前)键入
global
即可定义全局变量。因此:参见示例here
编辑:查看github代码,将
attacked_switches
指定为全局变量对您没有帮助。您引用的代码有attacked_switches.add(dpid)
行,但我找不到attacked_switches
的定义位置相关问题 更多 >
编程相关推荐