1 from pyjamas.ui.VerticalPanel import VerticalPanel
2 from pyjamas.ui.Grid import Grid
3 from pyjamas.ui.DockPanel import DockPanel
4 from pyjamas.ui.HorizontalPanel import HorizontalPanel
5 from pyjamas.ui.CaptionPanel import CaptionPanel
6 from pyjamas.ui.CheckBox import CheckBox
7 from pyjamas.ui.TextBox import TextBox
8 from pyjamas.ui.Button import Button
9 from pyjamas.ui.HTML import HTML
10 from pyjamas.ui.Image import Image
11 from pyjamas.ui import HasAlignment
13 class TopPanel(DockPanel):
14 def __init__(self, top, bw, active = False):
15 DockPanel.__init__(self)
18 self.cb = CheckBox("Use virtual topology")
19 self.cb.setChecked(active)
20 self.cb.addClickListener(self)
21 hp = HorizontalPanel()
23 self.tb.setVisibleLength(8)
24 self.tb.setTextAlignment(self.tb.ALIGN_RIGHT)
26 hp.add(HTML("Default bandwidth: "))
30 self.add(self.cb, DockPanel.WEST)
31 self.add(hp, DockPanel.EAST)
32 self.setCellHorizontalAlignment(hp, HasAlignment.ALIGN_RIGHT)
34 def onClick(self, sender):
36 if sender.isChecked():
37 self.top.build_topology()
40 self.top.clear_vlinks()
41 ## Unset vini_topo attribute?
44 def getDefaultBW(self):
45 bw = self.tb.getText()
48 class VlinkPanel(DockPanel):
49 def __init__(self, top, handle, description, bw):
50 DockPanel.__init__(self)
52 self.description = description
56 hp1 = HorizontalPanel()
57 delete = Image("./images/cancel.png")
58 delete.addClickListener(self)
60 hp1.add(HTML(" %s" % self.description))
62 hp2 = HorizontalPanel()
64 tb.setVisibleLength(8)
65 tb.setTextAlignment(tb.ALIGN_RIGHT)
68 hp2.add(HTML(" kbps"))
70 self.add(hp1, DockPanel.WEST)
71 self.setCellHorizontalAlignment(hp1, HasAlignment.ALIGN_LEFT)
72 self.setCellWidth(hp1, "100%")
74 self.add(hp2, DockPanel.EAST)
75 self.setCellHorizontalAlignment(hp2, HasAlignment.ALIGN_RIGHT)
78 def onClick(self, sender):
79 self.top.rspec.remove_vlink(self.handle)
83 class LinkPanel(VerticalPanel):
84 def __init__(self, sfadata, rspec):
85 VerticalPanel.__init__(self)
93 vlinks = self.rspec.get_vlink_list()
95 self.toppanel = TopPanel(self, self.defaultbw, (len(vlinks) > 0))
96 self.add(self.toppanel)
98 cp = CaptionPanel("Virtual links")
101 for (handle, desc, bw) in vlinks:
102 vp.add(VlinkPanel(self, handle, desc, bw))
106 def clear_vlinks(self):
107 vlinks = self.rspec.get_vlink_list()
108 for (handle, desc, bw) in vlinks:
109 self.rspec.remove_vlink(handle)
111 def build_topology(self):
112 nodes = self.rspec.get_sliver_list()
113 links = self.rspec.get_link_list()
114 self.defaultbw = self.toppanel.getDefaultBW()
116 for (name, end1nodes, end2nodes) in links:
117 for node1 in end1nodes:
118 for node2 in end2nodes:
119 if (node1 in nodes) and (node2 in nodes):
120 self.rspec.add_vlink(node1, node2, self.defaultbw)