Vince Lehman | b8b1806 | 2015-07-14 13:07:22 -0500 | [diff] [blame] | 1 | # -*- Mode:python; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
| 2 | # |
Ashlesh Gawande | 0cccdb8 | 2016-08-15 12:58:06 -0500 | [diff] [blame] | 3 | # Copyright (C) 2015-2016, The University of Memphis, |
| 4 | # Arizona Board of Regents, |
| 5 | # Regents of the University of California. |
Vince Lehman | b8b1806 | 2015-07-14 13:07:22 -0500 | [diff] [blame] | 6 | # |
| 7 | # This file is part of Mini-NDN. |
| 8 | # See AUTHORS.md for a complete list of Mini-NDN authors and contributors. |
| 9 | # |
| 10 | # Mini-NDN is free software: you can redistribute it and/or modify |
| 11 | # it under the terms of the GNU General Public License as published by |
| 12 | # the Free Software Foundation, either version 3 of the License, or |
| 13 | # (at your option) any later version. |
| 14 | # |
| 15 | # Mini-NDN is distributed in the hope that it will be useful, |
| 16 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | # GNU General Public License for more details. |
| 19 | # |
| 20 | # You should have received a copy of the GNU General Public License |
| 21 | # along with Mini-NDN, e.g., in COPYING.md file. |
| 22 | # If not, see <http://www.gnu.org/licenses/>. |
ashu | 7b6ba18 | 2015-04-17 15:02:37 -0500 | [diff] [blame] | 23 | |
| 24 | from Tkinter import * |
| 25 | |
| 26 | LOG_LEVELS = [ |
| 27 | "NONE", |
| 28 | "ERROR", |
| 29 | "WARN", |
| 30 | "INFO", |
| 31 | "DEBUG", |
| 32 | "TRACE", |
| 33 | "ALL" |
| 34 | ] |
| 35 | |
| 36 | class GuiFrame(Frame): |
Ashlesh Gawande | ab087da | 2015-07-09 15:10:02 -0500 | [diff] [blame] | 37 | def __init__(self, notebook, prefValues, appId): |
ashu | 7b6ba18 | 2015-04-17 15:02:37 -0500 | [diff] [blame] | 38 | Frame.__init__(self, notebook) |
| 39 | |
Ashlesh Gawande | ab087da | 2015-07-09 15:10:02 -0500 | [diff] [blame] | 40 | self.prefValues = prefValues |
| 41 | self.appId = appId |
| 42 | |
ashu | 7b6ba18 | 2015-04-17 15:02:37 -0500 | [diff] [blame] | 43 | self.row = 0 |
| 44 | self.column = 0 |
| 45 | |
| 46 | def addEntryBox(self, label, variable, defaultValue=""): |
| 47 | variable.set(defaultValue) |
| 48 | |
| 49 | Label(self, text=label).grid(row=self.row, sticky=E) |
| 50 | entry = Entry(self, textvariable=variable) |
| 51 | entry.grid(row=self.row, column=1) |
| 52 | |
| 53 | self.row += 1 |
| 54 | |
| 55 | def addDropDown(self, label, variable, values, defaultValue=""): |
| 56 | variable.set(defaultValue) |
| 57 | |
| 58 | Label(self, text=label).grid(row=self.row, sticky=E) |
| 59 | |
| 60 | self.entry = apply(OptionMenu, (self, variable) + tuple(values)) |
| 61 | self.entry.grid(row=self.row, column=1) |
| 62 | |
| 63 | self.row += 1 |
| 64 | |
Ashlesh Gawande | ab087da | 2015-07-09 15:10:02 -0500 | [diff] [blame] | 65 | def getPreferredOrDefaultValue(self, key, defaultValue): |
| 66 | if self.appId in self.prefValues: |
| 67 | return self.prefValues[self.appId][key] |
| 68 | else: |
| 69 | return defaultValue |
| 70 | |
ashu | 7b6ba18 | 2015-04-17 15:02:37 -0500 | [diff] [blame] | 71 | class NfdFrame(GuiFrame): |
Ashlesh Gawande | ab087da | 2015-07-09 15:10:02 -0500 | [diff] [blame] | 72 | def __init__(self, notebook, prefValues): |
| 73 | GuiFrame.__init__(self, notebook, prefValues, "nfd") |
ashu | 7b6ba18 | 2015-04-17 15:02:37 -0500 | [diff] [blame] | 74 | |
| 75 | self.frameLabel = "NFD" |
| 76 | |
| 77 | # log-level |
| 78 | self.logLevel = StringVar(self) |
Ashlesh Gawande | ab087da | 2015-07-09 15:10:02 -0500 | [diff] [blame] | 79 | self.addDropDown("Log level:", |
| 80 | self.logLevel, |
| 81 | LOG_LEVELS, |
| 82 | self.getPreferredOrDefaultValue("log-level", LOG_LEVELS[3])) |
ashu | 7b6ba18 | 2015-04-17 15:02:37 -0500 | [diff] [blame] | 83 | |
Ashlesh Gawande | 3a4afb1 | 2015-07-09 09:23:30 -0500 | [diff] [blame] | 84 | def getValues(self): |
| 85 | return { |
| 86 | "log-level": self.logLevel.get() |
| 87 | } |
| 88 | |
ashu | 7b6ba18 | 2015-04-17 15:02:37 -0500 | [diff] [blame] | 89 | class NlsrFrame(GuiFrame): |
| 90 | |
| 91 | HYPERBOLIC_STATES = [ |
| 92 | "off", |
| 93 | "on", |
| 94 | "dry-run" |
| 95 | ] |
| 96 | |
Ashlesh Gawande | ab087da | 2015-07-09 15:10:02 -0500 | [diff] [blame] | 97 | def __init__(self, notebook, prefValues): |
| 98 | GuiFrame.__init__(self, notebook, prefValues, "nlsr") |
ashu | 7b6ba18 | 2015-04-17 15:02:37 -0500 | [diff] [blame] | 99 | |
| 100 | self.frameLabel = "NLSR" |
| 101 | |
| 102 | # general: network |
| 103 | self.network = StringVar(self) |
Ashlesh Gawande | ab087da | 2015-07-09 15:10:02 -0500 | [diff] [blame] | 104 | self.addEntryBox("Network:", |
| 105 | self.network, |
| 106 | self.getPreferredOrDefaultValue("network", "/ndn")) |
ashu | 7b6ba18 | 2015-04-17 15:02:37 -0500 | [diff] [blame] | 107 | |
| 108 | # general: site |
| 109 | self.site = StringVar(self) |
Ashlesh Gawande | ab087da | 2015-07-09 15:10:02 -0500 | [diff] [blame] | 110 | self.addEntryBox("Site:", self.site, self.getPreferredOrDefaultValue("site", "/edu/site")) |
ashu | 7b6ba18 | 2015-04-17 15:02:37 -0500 | [diff] [blame] | 111 | |
| 112 | # general: router |
| 113 | self.router = StringVar(self) |
Ashlesh Gawande | ab087da | 2015-07-09 15:10:02 -0500 | [diff] [blame] | 114 | self.addEntryBox("Router:", |
| 115 | self.router, |
| 116 | self.getPreferredOrDefaultValue("router", "/%C1.Router/cs/host")) |
ashu | 7b6ba18 | 2015-04-17 15:02:37 -0500 | [diff] [blame] | 117 | |
| 118 | # general: log-level |
| 119 | self.logLevel = StringVar(self) |
Ashlesh Gawande | ab087da | 2015-07-09 15:10:02 -0500 | [diff] [blame] | 120 | self.addDropDown("Log level:", |
| 121 | self.logLevel, |
| 122 | LOG_LEVELS, |
| 123 | self.getPreferredOrDefaultValue("log-level", LOG_LEVELS[3])) |
ashu | 7b6ba18 | 2015-04-17 15:02:37 -0500 | [diff] [blame] | 124 | |
| 125 | # hyperbolic: state |
| 126 | self.hyperbolicState = StringVar(self) |
Ashlesh Gawande | ab087da | 2015-07-09 15:10:02 -0500 | [diff] [blame] | 127 | self.addDropDown("Hyperbolic routing:", |
| 128 | self.hyperbolicState, |
| 129 | self.HYPERBOLIC_STATES, |
| 130 | self.getPreferredOrDefaultValue("hyperbolic-state", self.HYPERBOLIC_STATES[0])) |
ashu | 7b6ba18 | 2015-04-17 15:02:37 -0500 | [diff] [blame] | 131 | |
| 132 | # hyperbolic: angle |
| 133 | self.angle = StringVar(self) |
Ashlesh Gawande | ab087da | 2015-07-09 15:10:02 -0500 | [diff] [blame] | 134 | self.addEntryBox("Angle:", self.angle, self.getPreferredOrDefaultValue("angle", "0.0")) |
ashu | 7b6ba18 | 2015-04-17 15:02:37 -0500 | [diff] [blame] | 135 | |
| 136 | # hyperbolic: radius |
| 137 | self.radius = StringVar(self) |
Ashlesh Gawande | ab087da | 2015-07-09 15:10:02 -0500 | [diff] [blame] | 138 | self.addEntryBox("Radius:", self.radius, self.getPreferredOrDefaultValue("radius", "0.0")) |
ashu | 7b6ba18 | 2015-04-17 15:02:37 -0500 | [diff] [blame] | 139 | |
| 140 | # fib: max-faces-per-prefix |
| 141 | self.maxFaces = StringVar(self) |
Ashlesh Gawande | ab087da | 2015-07-09 15:10:02 -0500 | [diff] [blame] | 142 | self.addEntryBox("Max faces per prefix:", |
| 143 | self.maxFaces, |
| 144 | self.getPreferredOrDefaultValue("max-faces-per-prefix", "0")) |
ashu | 7b6ba18 | 2015-04-17 15:02:37 -0500 | [diff] [blame] | 145 | |
| 146 | def getValues(self): |
| 147 | return { |
| 148 | "network": self.network.get(), |
| 149 | "site": self.site.get(), |
| 150 | "router": self.router.get(), |
| 151 | "log-level": self.logLevel.get(), |
| 152 | "hyperbolic-state": self.hyperbolicState.get(), |
| 153 | "angle": self.angle.get(), |
| 154 | "radius": self.radius.get(), |
| 155 | "max-faces-per-prefix": self.maxFaces.get() |
| 156 | } |
| 157 | |