from pyjamas.ui.VerticalPanel import VerticalPanel from pyjamas.ui.Grid import Grid from pyjamas.ui.DockPanel import DockPanel from pyjamas.ui.HorizontalPanel import HorizontalPanel from pyjamas.ui.CaptionPanel import CaptionPanel from pyjamas.ui.CheckBox import CheckBox from pyjamas.ui.TextBox import TextBox from pyjamas.ui.Button import Button from pyjamas.ui.HTML import HTML from pyjamas.ui.Image import Image from pyjamas.ui import HasAlignment class TopPanel(DockPanel): def __init__(self, top, bw, active = False): DockPanel.__init__(self) self.top = top self.setWidth("100%") self.cb = CheckBox("Use virtual topology") self.cb.setChecked(active) self.cb.addClickListener(self) hp = HorizontalPanel() self.tb = TextBox() self.tb.setVisibleLength(8) self.tb.setTextAlignment(self.tb.ALIGN_RIGHT) self.tb.setText(bw) hp.add(HTML("Default bandwidth: ")) hp.add(self.tb) hp.add(HTML(" kbps")) self.add(self.cb, DockPanel.WEST) self.add(hp, DockPanel.EAST) self.setCellHorizontalAlignment(hp, HasAlignment.ALIGN_RIGHT) def onClick(self, sender): if sender == self.cb: if sender.isChecked(): self.top.build_topology() self.top.refresh() else: self.top.clear_vlinks() ## Unset vini_topo attribute? self.top.refresh() def getDefaultBW(self): bw = self.tb.getText() return bw class VlinkPanel(DockPanel): def __init__(self, top, handle, description, bw): DockPanel.__init__(self) self.handle = handle self.description = description self.bw = bw self.top = top hp1 = HorizontalPanel() delete = Image("./images/cancel.png") delete.addClickListener(self) hp1.add(delete) hp1.add(HTML(" %s" % self.description)) hp2 = HorizontalPanel() tb = TextBox() tb.setVisibleLength(8) tb.setTextAlignment(tb.ALIGN_RIGHT) tb.setText(bw) hp2.add(tb) hp2.add(HTML(" kbps")) self.add(hp1, DockPanel.WEST) self.setCellHorizontalAlignment(hp1, HasAlignment.ALIGN_LEFT) self.setCellWidth(hp1, "100%") self.add(hp2, DockPanel.EAST) self.setCellHorizontalAlignment(hp2, HasAlignment.ALIGN_RIGHT) self.setWidth("100%") def onClick(self, sender): rspec = self.top.sfadata.getRSpec() rspec.remove_vlink(self.handle) self.top.refresh() class LinkPanel(VerticalPanel): def __init__(self, sfadata): VerticalPanel.__init__(self) self.sfadata = sfadata self.defaultbw = 1000 self.setStyleName("ks-layouts") self.refresh() def refresh(self): self.clear() rspec = self.sfadata.getRSpec() vlinks = rspec.get_vlink_list() self.toppanel = TopPanel(self, self.defaultbw, (len(vlinks) > 0)) self.add(self.toppanel) cp = CaptionPanel("Virtual links") vp = VerticalPanel() vp.setWidth("100%") for (handle, desc, bw) in vlinks: vp.add(VlinkPanel(self, handle, desc, bw)) cp.add(vp) self.add(cp) def clear_vlinks(self): rspec = self.sfadata.getRSpec() vlinks = rspec.get_vlink_list() for (handle, desc, bw) in vlinks: rspec.remove_vlink(handle) def build_topology(self): rspec = self.sfadata.getRSpec() nodes = rspec.get_sliver_list() links = rspec.get_link_list() self.defaultbw = self.toppanel.getDefaultBW() for (name, end1nodes, end2nodes) in links: for node1 in end1nodes: for node2 in end2nodes: if (node1 in nodes) and (node2 in nodes): rspec.add_vlink(node1, node2, self.defaultbw)