'Load command.'

def loadTopology(self):

    c = self.canvas
    myFormats = [('Mininet    Topology', '*.mn'), ('All    Files', '*')]
    f = tkFileDialog.askopenfile(filetypes=myFormats, mode='rb')
    if (f == None):
        return
    self.newTopology()
    loadedTopology = self.convertJsonUnicode(json.load(f))
    if ('application' in loadedTopology):
        self.appPrefs = dict((self.appPrefs.items() + loadedTopology['application'].items()))
        if ('ovsOf10' not in self.appPrefs['openFlowVersions']):
            self.appPrefs['openFlowVersions']['ovsOf10'] = '0'
        if ('ovsOf11' not in self.appPrefs['openFlowVersions']):
            self.appPrefs['openFlowVersions']['ovsOf11'] = '0'
        if ('ovsOf12' not in self.appPrefs['openFlowVersions']):
            self.appPrefs['openFlowVersions']['ovsOf12'] = '0'
        if ('ovsOf13' not in self.appPrefs['openFlowVersions']):
            self.appPrefs['openFlowVersions']['ovsOf13'] = '0'
        if ('sflow' not in self.appPrefs):
            self.appPrefs['sflow'] = self.sflowDefaults
        if ('netflow' not in self.appPrefs):
            self.appPrefs['netflow'] = self.nflowDefaults
    if ('controllers' in loadedTopology):
        if (loadedTopology['version'] == '1'):
            hostname = 'c0'
            self.controllers = {}
            self.controllers[hostname] = loadedTopology['controllers']['c0']
            self.controllers[hostname]['hostname'] = hostname
            self.addNode('Controller', 0, float(30), float(30), name=hostname)
            icon = self.findWidgetByName(hostname)
            icon.bind('<Button-3>', self.do_controllerPopup)
        else:
            controllers = loadedTopology['controllers']
            for controller in controllers:
                hostname = controller['opts']['hostname']
                x = controller['x']
                y = controller['y']
                self.addNode('Controller', 0, float(x), float(y), name=hostname)
                self.controllers[hostname] = controller['opts']
                icon = self.findWidgetByName(hostname)
                icon.bind('<Button-3>', self.do_controllerPopup)
    hosts = loadedTopology['hosts']
    for host in hosts:
        nodeNum = host['number']
        hostname = ('h' + nodeNum)
        if ('hostname' in host['opts']):
            hostname = host['opts']['hostname']
        else:
            host['opts']['hostname'] = hostname
        if ('nodeNum' not in host['opts']):
            host['opts']['nodeNum'] = int(nodeNum)
        x = host['x']
        y = host['y']
        self.addNode('Host', nodeNum, float(x), float(y), name=hostname)
        if ('privateDirectory' in host['opts']):
            newDirList = []
            for privateDir in host['opts']['privateDirectory']:
                if isinstance(privateDir, list):
                    newDirList.append((privateDir[0], privateDir[1]))
                else:
                    newDirList.append(privateDir)
            host['opts']['privateDirectory'] = newDirList
        self.hostOpts[hostname] = host['opts']
        icon = self.findWidgetByName(hostname)
        icon.bind('<Button-3>', self.do_hostPopup)
    switches = loadedTopology['switches']
    for switch in switches:
        nodeNum = switch['number']
        hostname = ('s' + nodeNum)
        if ('controllers' not in switch['opts']):
            switch['opts']['controllers'] = []
        if ('switchType' not in switch['opts']):
            switch['opts']['switchType'] = 'default'
        if ('hostname' in switch['opts']):
            hostname = switch['opts']['hostname']
        else:
            switch['opts']['hostname'] = hostname
        if ('nodeNum' not in switch['opts']):
            switch['opts']['nodeNum'] = int(nodeNum)
        x = switch['x']
        y = switch['y']
        if (switch['opts']['switchType'] == 'legacyRouter'):
            self.addNode('LegacyRouter', nodeNum, float(x), float(y), name=hostname)
            icon = self.findWidgetByName(hostname)
            icon.bind('<Button-3>', self.do_legacyRouterPopup)
        elif (switch['opts']['switchType'] == 'legacySwitch'):
            self.addNode('LegacySwitch', nodeNum, float(x), float(y), name=hostname)
            icon = self.findWidgetByName(hostname)
            icon.bind('<Button-3>', self.do_legacySwitchPopup)
        else:
            self.addNode('Switch', nodeNum, float(x), float(y), name=hostname)
            icon = self.findWidgetByName(hostname)
            icon.bind('<Button-3>', self.do_switchPopup)
        self.switchOpts[hostname] = switch['opts']
        if (int(loadedTopology['version']) > 1):
            controllers = self.switchOpts[hostname]['controllers']
            for controller in controllers:
                dest = self.findWidgetByName(controller)
                (dx, dy) = self.canvas.coords(self.widgetToItem[dest])
                self.link = self.canvas.create_line(float(x), float(y), dx, dy, width=4, fill='red', dash=(6, 4, 2, 4), tag='link')
                c.itemconfig(self.link, tags=(c.gettags(self.link) + ('control',)))
                self.addLink(icon, dest, linktype='control')
                self.createControlLinkBindings()
                self.link = self.linkWidget = None
        else:
            dest = self.findWidgetByName('c0')
            (dx, dy) = self.canvas.coords(self.widgetToItem[dest])
            self.link = self.canvas.create_line(float(x), float(y), dx, dy, width=4, fill='red', dash=(6, 4, 2, 4), tag='link')
            c.itemconfig(self.link, tags=(c.gettags(self.link) + ('control',)))
            self.addLink(icon, dest, linktype='control')
            self.createControlLinkBindings()
            self.link = self.linkWidget = None
    links = loadedTopology['links']
    for link in links:
        srcNode = link['src']
        src = self.findWidgetByName(srcNode)
        (sx, sy) = self.canvas.coords(self.widgetToItem[src])
        destNode = link['dest']
        dest = self.findWidgetByName(destNode)
        (dx, dy) = self.canvas.coords(self.widgetToItem[dest])
        self.link = self.canvas.create_line(sx, sy, dx, dy, width=4, fill='blue', tag='link')
        c.itemconfig(self.link, tags=(c.gettags(self.link) + ('data',)))
        self.addLink(src, dest, linkopts=link['opts'])
        self.createDataLinkBindings()
        self.link = self.linkWidget = None
    f.close()
