blob: 54838c5a4c805a47610d458d5571e9aaf1163f87 [file] [log] [blame]
Vince Lehmanb8b18062015-07-14 13:07:22 -05001# -*- Mode:python; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2#
Alexander Lane9944cf52018-05-17 12:16:50 -05003# Copyright (C) 2015-2018, The University of Memphis,
Ashlesh Gawande0cccdb82016-08-15 12:58:06 -05004# Arizona Board of Regents,
5# Regents of the University of California.
Vince Lehmanb8b18062015-07-14 13:07:22 -05006#
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/>.
ashu7b6ba182015-04-17 15:02:37 -050023
24from Tkinter import *
25
26LOG_LEVELS = [
27 "NONE",
28 "ERROR",
29 "WARN",
30 "INFO",
31 "DEBUG",
32 "TRACE",
33 "ALL"
34]
35
36class GuiFrame(Frame):
Ashlesh Gawandeab087da2015-07-09 15:10:02 -050037 def __init__(self, notebook, prefValues, appId):
ashu7b6ba182015-04-17 15:02:37 -050038 Frame.__init__(self, notebook)
39
Ashlesh Gawandeab087da2015-07-09 15:10:02 -050040 self.prefValues = prefValues
41 self.appId = appId
42
ashu7b6ba182015-04-17 15:02:37 -050043 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 Gawandeab087da2015-07-09 15:10:02 -050065 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
ashu7b6ba182015-04-17 15:02:37 -050071class NfdFrame(GuiFrame):
Ashlesh Gawandeab087da2015-07-09 15:10:02 -050072 def __init__(self, notebook, prefValues):
73 GuiFrame.__init__(self, notebook, prefValues, "nfd")
ashu7b6ba182015-04-17 15:02:37 -050074
75 self.frameLabel = "NFD"
76
77 # log-level
78 self.logLevel = StringVar(self)
Ashlesh Gawandeab087da2015-07-09 15:10:02 -050079 self.addDropDown("Log level:",
80 self.logLevel,
81 LOG_LEVELS,
82 self.getPreferredOrDefaultValue("log-level", LOG_LEVELS[3]))
ashu7b6ba182015-04-17 15:02:37 -050083
Ashlesh Gawande3a4afb12015-07-09 09:23:30 -050084 def getValues(self):
85 return {
86 "log-level": self.logLevel.get()
87 }
88
ashu7b6ba182015-04-17 15:02:37 -050089class NlsrFrame(GuiFrame):
90
91 HYPERBOLIC_STATES = [
92 "off",
93 "on",
94 "dry-run"
95 ]
96
Ashlesh Gawandeab087da2015-07-09 15:10:02 -050097 def __init__(self, notebook, prefValues):
98 GuiFrame.__init__(self, notebook, prefValues, "nlsr")
ashu7b6ba182015-04-17 15:02:37 -050099
100 self.frameLabel = "NLSR"
101
102 # general: network
103 self.network = StringVar(self)
Ashlesh Gawandeab087da2015-07-09 15:10:02 -0500104 self.addEntryBox("Network:",
105 self.network,
106 self.getPreferredOrDefaultValue("network", "/ndn"))
ashu7b6ba182015-04-17 15:02:37 -0500107
108 # general: site
109 self.site = StringVar(self)
Ashlesh Gawandeab087da2015-07-09 15:10:02 -0500110 self.addEntryBox("Site:", self.site, self.getPreferredOrDefaultValue("site", "/edu/site"))
ashu7b6ba182015-04-17 15:02:37 -0500111
112 # general: router
113 self.router = StringVar(self)
Ashlesh Gawandeab087da2015-07-09 15:10:02 -0500114 self.addEntryBox("Router:",
115 self.router,
116 self.getPreferredOrDefaultValue("router", "/%C1.Router/cs/host"))
ashu7b6ba182015-04-17 15:02:37 -0500117
118 # general: log-level
119 self.logLevel = StringVar(self)
Ashlesh Gawandeab087da2015-07-09 15:10:02 -0500120 self.addDropDown("Log level:",
121 self.logLevel,
122 LOG_LEVELS,
123 self.getPreferredOrDefaultValue("log-level", LOG_LEVELS[3]))
ashu7b6ba182015-04-17 15:02:37 -0500124
125 # hyperbolic: state
126 self.hyperbolicState = StringVar(self)
Ashlesh Gawandeab087da2015-07-09 15:10:02 -0500127 self.addDropDown("Hyperbolic routing:",
128 self.hyperbolicState,
129 self.HYPERBOLIC_STATES,
130 self.getPreferredOrDefaultValue("hyperbolic-state", self.HYPERBOLIC_STATES[0]))
ashu7b6ba182015-04-17 15:02:37 -0500131
132 # hyperbolic: angle
133 self.angle = StringVar(self)
Ashlesh Gawandeab087da2015-07-09 15:10:02 -0500134 self.addEntryBox("Angle:", self.angle, self.getPreferredOrDefaultValue("angle", "0.0"))
ashu7b6ba182015-04-17 15:02:37 -0500135
136 # hyperbolic: radius
137 self.radius = StringVar(self)
Ashlesh Gawandeab087da2015-07-09 15:10:02 -0500138 self.addEntryBox("Radius:", self.radius, self.getPreferredOrDefaultValue("radius", "0.0"))
ashu7b6ba182015-04-17 15:02:37 -0500139
140 # fib: max-faces-per-prefix
141 self.maxFaces = StringVar(self)
Ashlesh Gawandeab087da2015-07-09 15:10:02 -0500142 self.addEntryBox("Max faces per prefix:",
143 self.maxFaces,
144 self.getPreferredOrDefaultValue("max-faces-per-prefix", "0"))
ashu7b6ba182015-04-17 15:02:37 -0500145
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 }