0

I'm using code from GitHub for mitigation of DDoS attacks using reactive flow rules in Floodlight Controller. I can't run the program because the global variable attacked_switches is not defined, but I don't know how to do that. Can anybody help me?

From GitHub

From YouTube

Images

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
iff_or
  • 880
  • 1
  • 11
  • 24

1 Answers1

0

you can define a global variable simply by typing global before the variable name (before the first asignment of the variable). so:

global attacked_switches

See for example here

Edit: Looking at the github-code, assigning attacked_switches as a global variable won't help you. The code you reference has the line attacked_switches.add(dpid), but I can't find where attacked_switches is defined.

Niels Henkens
  • 2,553
  • 1
  • 12
  • 27
  • Help you with what? With how to make attacked_switches global, that is easy and explained above. But the Github-code you showed in the link doesn't define attacked_switches anywhere. So you would have to define it somewhere (e.g. `attacked_switches = []`), but that where and how depends on what it is needed for. – Niels Henkens Dec 13 '18 at 21:23