from pox.core import core 
import pox.openflow.libopenflow_01 as of
from forwarding.l2_learning import * 

from tkinter import *

from project.firewall import TestFW
from project.ui import UI

def setup():
    top = Toplevel()

    # quit POX when window is killed
    top.protocol("WM_DELETE_WINDOW", core.quit) 

    top.title("firewall thing") 

    frame = Frame(top, padding="3") 
    frame.grid()

    disp = Label(frame, text="hmm").grid(column=0, row=0)
    
    def reload():
        conn = core.openflow.getConnection(1)
        disp.configure(str(dir(conn)))

    b_reload = Button(frame, text="reload", command=reload).grid(column=0, row=1)
    b_quit = Button(frame, text="quit", command=top.destroy).grid(column=0, row=2)


def launch():
    fw_list_dpid = [51, 52] 
    srv_list = {"web" : ['10.0.0.100']}

    # register firewall 
    core.registerNew(TestFW, fw_list_dpid[0], srv_list)

    # just use L2 learning switch for others 
    core.registerNew(l2_learning, False) 

    #core.registerNew(UI)


    def start_ui():
        core.tk.do(setup)
        
    core.call_when_ready(start_ui, ['openflow', 'tk'])

[((36, 4, 36, 55), 'pox.core.core.registerNew', 'core.registerNew', ({(36, 21, 36, 27): 'TestFW', (36, 29, 36, 44): 'fw_list_dpid[0]', (36, 46, 36, 54): 'srv_list'}, {}), '(TestFW, fw_list_dpid[0], srv_list)', False, 'from pox.core import core\n'), ((39, 4, 39, 40), 'pox.core.core.registerNew', 'core.registerNew', ({(39, 21, 39, 32): 'l2_learning', (39, 34, 39, 39): '(False)'}, {}), '(l2_learning, False)', False, 'from pox.core import core\n'), ((47, 4, 47, 54), 'pox.core.core.call_when_ready', 'core.call_when_ready', ({(47, 25, 47, 33): 'start_ui', (47, 35, 47, 53): "['openflow', 'tk']"}, {}), "(start_ui, ['openflow', 'tk'])", False, 'from pox.core import core\n'), ((24, 15, 24, 45), 'pox.core.core.openflow.getConnection', 'core.openflow.getConnection', ({(24, 43, 24, 44): '1'}, {}), '(1)', False, 'from pox.core import core\n'), ((45, 8, 45, 25), 'pox.core.core.tk.do', 'core.tk.do', ({(45, 19, 45, 24): 'setup'}, {}), '(setup)', False, 'from pox.core import core\n')]