需要定义名称为“ attacked_switches”的全局变量

时间:2018-12-13 20:52:10

标签: python sdn ddos

我正在使用来自GitHub的代码,以使用Floodlight Controller中的反应流规则来缓解DDoS攻击。我无法运行该程序,因为未定义全局变量def validate_columns(self, columns): if not columns: raise serializers.ValidationError("Leaderboards require at least 1 column") # Make sure all column indexes are unique indexes = [column['index'] for column in columns] if len(set(indexes)) != len(columns): raise serializers.ValidationError("Columns must have unique indexes!") # Make sure all column keys are unique keys = [column["key"] for column in columns] if len(set(keys)) != len(columns): raise serializers.ValidationError("Columns must have unique keys!") # Validate that column.computation_indexes points to valid columns for column in columns: if 'computation_indexes' in column and column['computation_indexes']: for index in column['computation_indexes'].split(","): try: if int(index) not in indexes: raise serializers.ValidationError(f"Column index {index} does not exist in available indexes {indexes}") except ValueError: raise serializers.ValidationError(f"Bad value for index, should be an integer but received: {index}.") return columns ,但是我不知道该怎么做。有人可以帮我吗?

From GitHub

From YouTube

Images

var counter = 0; 
	
$(yourselector).each(function(index,element){
			
        counter++; 

        if( counter == $(yourselector).length )
        {
            // Last Element
        }
        else
        {
           // Not last Element
        }
			
 });

1 个答案:

答案 0 :(得分:0)

您只需在变量名之前(变量的第一个赋值之前)键入global即可定义全局变量。所以:

global attacked_switches

例如参见here

编辑:查看github代码,将attacked_switches分配为全局变量将无济于事。您引用的代码有attacked_switches.add(dpid)行,但是我找不到attacked_switches的定义位置。