Commit c1560dd4 authored by Matt Strum's avatar Matt Strum
Browse files

Added support for message passing

parent 892daa60
......@@ -14,14 +14,14 @@ Learn more about Flex at http://flex.org
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- BEGIN Browser History required section -->
<!-- BEGIN Browser History required section
<link rel="stylesheet" type="text/css" href="history/history.css" />
<!-- END Browser History required section -->
<title>${title}</title>
<script src="AC_OETags.js" language="javascript"></script>
<!-- BEGIN Browser History required section -->
<!-- BEGIN Browser History required section
<script src="history/history.js" language="javascript"></script>
<!-- END Browser History required section -->
......
......@@ -4,26 +4,20 @@ package
public class Main
{
public function getConsole() : LogRoot
public static function getConsole() : LogRoot
{
return log;
}
public function setConole(newLog : LogRoot) : void
public static function setConole(newLog : LogRoot) : void
{
log = newLog;
}
public function startTimer() : void
public static function startTimer() : void
{
d = new Date();
}
public function endTimer() : void
{
var d2 : Date = new Date();
Alert.show((d.valueOf() - d2.valueOf()).toString());
}
private static var log : LogRoot = null;
private static var d : Date = null;
......
......@@ -46,6 +46,8 @@
[Bindable]
public var pgHandler:ProtoGeniHandler;
public var connectionHandler:ConnectionHandler;
[Bindable]
public var slicesMenu : ArrayCollection;
......@@ -55,8 +57,6 @@
[Bindable]
public var selectedSlice : Slice = null;
public var main:Main;
//------------------------------------------
// Variables needed
public var chooseCMWindow:ChooseComponentManagerWindow;
......@@ -68,17 +68,19 @@
// Start out by asking the user for the CM URL
private function init():void {
main = new Main();
console = new ConsoleWindow();
rspecView = new XmlWindow();
main.setConole(console);
Main.setConole(console);
pgHandler = new ProtoGeniHandler();
connectionHandler = new ConnectionHandler();
chooseCMWindow = new ChooseComponentManagerWindow();
chooseCMWindow.main = this;
chooseCMWindow.main = this;
Security.allowDomain("localhost");
}
public function showAbout():void {
......
......@@ -62,7 +62,7 @@
// Manager
var managerHbox:HBox = new HBox();
var managerLabel:Label = new Label();
managerLabel.text = "Owned by";
managerLabel.text = "Hosted on";
managerHbox.addChild(managerLabel);
managerHbox.addChild(Common.getComponentManagerButton(node.manager));
hierarchyVbox.addChild(managerHbox);
......@@ -185,6 +185,10 @@
rspecView.loadXml(virtualNode.rspec);
}
}
public function tryAdd():void {
main.connectionHandler.RequestNode(node.urn, node.manager.Hrn);
}
]]>
</mx:Script>
......@@ -215,6 +219,7 @@
<mx:VRule height="16"/>
<mx:Label text="Availability" fontWeight="bold"/>
<mx:Image id="imgAvailable"/>
<mx:Button label="Add" click="tryAdd();"/>
</mx:GridItem>
</mx:GridRow>
<mx:GridRow width="100%">
......
/* GENIPUBLIC-COPYRIGHT
* Copyright (c) 2009 University of Utah and the Flux Group.
* All rights reserved.
*
* Permission to use, copy, modify and distribute this software is hereby
* granted provided that (1) source code retains these copyright, permission,
* and disclaimer notices, and (2) redistributions including binaries
* reproduce the notices in supporting documentation.
*
* THE UNIVERSITY OF UTAH ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
* CONDITION. THE UNIVERSITY OF UTAH DISCLAIMS ANY LIABILITY OF ANY KIND
* FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
*/
package
{
import flash.utils.Dictionary;
public class ComponentManager
{
public static var NORMAL = 0;
public static var LOADING = 1;
public static var FAILED = 2;
public function ComponentManager(newId : String,
newName : String,
newHostName : String,
newUrl : String,
newUpdate : Function,
newVersion : int,
newHrn) : void
{
id = newId;
name = newName;
hostName = newHostName;
url = newUrl;
hrn =
ad = "";
manifest = "";
update = newUpdate;
version = newVersion;
changed = false;
bgpAddress = "";
bgpNetmask = "";
components = new Array();
used = new Array();
ticket = null;
sliver = null;
state = LOADING;
}
public function setUpdate(newUpdate : Function) : void
{
update = newUpdate;
}
public function getBgpAddress() : String
{
return bgpAddress;
}
public function getBgpNetmask() : String
{
return bgpNetmask;
}
public function getName() : String
{
return name;
}
public function getUrl() : String
{
return url;
}
public function getHrn() : String
{
return url;
}
public function getAd() : String
{
return ad;
}
public function getManifest() : String
{
return manifest;
}
public function setManifest(newManifest : String) : void
{
manifest = newManifest;
}
public function getHostName() : String
{
return hostName;
}
public function getId() : String
{
return id;
}
public function setState(newState : int) : void
{
state = newState;
}
public function getState() : int
{
return state;
}
public function setTicket(newTicket : String) : void
{
ticket = newTicket;
}
public function getTicket() : String
{
return ticket;
}
public function setSliver(newSliver : String) : void
{
sliver = newSliver;
}
public function getSliver() : String
{
return sliver;
}
public function isUsed(nodeIndex : int) : Boolean
{
return used.indexOf(nodeIndex) != -1;
}
public function addUsed(nodeIndex : int) : void
{
used.push(nodeIndex);
}
public function removeUsed(nodeIndex : int) : void
{
var target : int = used.indexOf(nodeIndex);
if (target != -1)
{
used.splice(target, 1);
}
update();
}
public function getUsed() : Array
{
return used.slice();
}
public function getComponent(nodeIndex : int) : Component
{
return components[nodeIndex];
}
public function getComponentFromUuid(uuid : String) : Component
{
return uuidToNode[uuid];
}
public function getComponentCount() : int
{
return components.length;
}
public function getVersion() : int
{
return version;
}
public function setChanged() : void
{
changed = true;
}
public function clearChanged() : void
{
changed = false;
}
public function hasChanged() : Boolean
{
return changed;
}
public function isUsedString(id : String) : Boolean
{
var result = true;
var index = findId(id);
if (index != -1)
{
result = isUsed(index);
}
return result;
}
// Returns the node index of the now used node.
public function makeUsed(id : String) : int
{
var index = findId(id);
if (index != -1 && ! isUsed(index))
{
addUsed(index);
update();
}
return index;
}
private function findId(id : String) : int
{
var result : int = -1;
var i : int = 0;
for (; i < components.length && result == -1; ++i)
{
if (components[i].uuid == id)
{
result = i;
}
}
return result;
}
public function resourceFailure() : void
{
setState(FAILED);
update();
}
public function resourceSuccess(str : String) : void
{
var console = Main.getConsole();
if (console != null)
{
console.appendText("\npopulateNodes: " + name + "\n");
}
try
{
ad = str;
if (str != null)
{
uuidToNode = new Dictionary();
var subNodeOf = new Dictionary();
var rspec : XML = XML(str);
var nodeName : QName = new QName(rspec.namespace(), "node");
var xmlNodes : Array = new Array();
for each (var element in rspec.elements(nodeName))
{
var uuidAtt : String = element.attribute("component_uuid");
if (uuidAtt != "")
{
xmlNodes.push(element);
}
}
xmlNodes.sort(xmlSort);
var i : int = 0;
for (; i < xmlNodes.length; ++i)
{
if (version < 2 || isAvailable(xmlNodes[i]))
{
var com : Component = new Component();
components.push(com);
var uuid : String = xmlNodes[i].attribute("component_uuid");
uuidToNode[uuid] = com;
com.name = xmlNodes[i].attribute("component_name");
com.uuid = uuid;
if (version < 2)
{
com.managerId = id;
}
else
{
com.managerId = xmlNodes[i].attribute("component_manager_uuid");
}
parseNodeTypes(xmlNodes[i], com);
parseSubNode(subNodeOf, xmlNodes[i], com.uuid);
var interfaceName = new QName(rspec.namespace(), "interface");
var interfaceList = xmlNodes[i].elements(interfaceName);
var interfaceNumber = 0;
for each (var inter in interfaceList)
{
var interName = null;
if (version < 2)
{
interName = inter.attribute("component_name");
}
else
{
interName = inter.attribute("component_id");
}
var newInterface = new Interface("virt-"
+ String(interfaceNumber),
interName);
var interRole = inter.attribute("role");
if (interRole == "control")
{
newInterface.role = Interface.UNUSED_CONTROL;
}
else if (interRole == "experimental")
{
newInterface.role = Interface.UNUSED_EXPERIMENTAL;
}
com.interfaces.push(newInterface);
++interfaceNumber;
}
}
}
setSubNodes(subNodeOf);
parseLinks(rspec, uuidToNode);
parseBgpPrefixes(rspec);
}
setState(NORMAL)
}
catch (e : Error)
{
var text = Main.getConsole();
if (text != null)
{
text.appendText("\n" + e.toString() + "\n");
}
setState(FAILED);
}
update();
}
private function parseNodeTypes(node : XML, com : Component) : void
{
var typeName = new QName(node.namespace(), "node_type");
var fieldName = new QName(node.namespace(), "field");
for each (var currentType in node.elements(typeName))
{
if (currentType.attribute("type_name") == "bgpmux")
{
com.isBgpMux = true;
for each (var currentField in currentType.elements(fieldName))
{
if (currentField.attribute("key") == "upstream_as")
{
com.upstreamAs = currentField.attribute("value");
}
}
}
}
}
private function parseSubNode(subNodeOf : Dictionary, node : XML,
uuid : String) : void
{
var subNodeName = new QName(node.namespace(), "subnode_of");
for each (var current in node.elements(subNodeName))
{
var text = current.text();
var parent = text.toString();
subNodeOf[uuid] = parent;
}
}
private function setSubNodes(subNodeOf : Dictionary) : void
{
for each (var current in components)
{
if (subNodeOf[current.uuid] != null)
{
current.superNode = findId(subNodeOf[current.uuid]);
}
}
}
private function parseLinks(rspec : XML) : void
{
var linkName : QName = new QName(rspec.namespace(), "link");
for each (var link in rspec.elements(linkName))
{
var bandwidthName : QName = new QName(rspec.namespace(),
"bandwidth");
var bandwidth : int = 100000;
for each (var current in link.elements(bandwidthName))
{
bandwidth = int(current.text());
}
var interElement : QName = new QName(rspec.namespace(),
"interface_ref");
if (version < 2)
{
interElement = new QName(rspec.namespace(), "interface");
}
for each (var inter in link.descendants(interElement))
{
var interName : String = null;
var uuid : String = null;
if (version < 2)
{
var uuidList = inter.elements(new QName(rspec.namespace(),
"component_node_uuid"));
uuid = uuidList.text();
var nameList = inter.elements(new QName(rspec.namespace(),
"component_interface_name"));
interName = nameList.text();
}
else
{
uuid = inter.attribute("component_node_uuid");
interName = inter.attribute("component_interface_id");
}
var node : Component = uuidToNode[uuid];
if (node != null)
{
for each (var nodeInter in node.interfaces)
{
if (interName == nodeInter.name)
{
if (nodeInter.role == Interface.UNUSED_EXPERIMENTAL)
{
nodeInter.role = Interface.EXPERIMENTAL;
}
else if (nodeInter.role == Interface.UNUSED_CONTROL)
{
nodeInter.role = Interface.CONTROL;
}
nodeInter.bandwidth = bandwidth;
}
}
}
}
}
}
private function parseBgpPrefixes(rspec : XML) : void
{
var prefixName = new QName(rspec.namespace(), "bgp_prefix");
for each (var prefix in rspec.elements(prefixName))
{
bgpAddress = prefix.attribute("address");
bgpNetmask = prefix.attribute("netmask");
}
}
private function isAvailable(node : XML) : Boolean
{
var result : Boolean = false;
var availableName : QName = new QName(node.namespace(),
"available");
var available = node.elements(availableName);
for each (var element in available)
{
var text = element.text();
if (text.toString() == "true")
{
result = true;
break;
}
}
return result;
}
private function xmlSort(left : XML, right : XML) : int
{
// TODO: Make this an actual natural sort
var leftAttribute = left.attribute("component_name");
var rightAttribute = right.attribute("component_name");
if (leftAttribute.substr(0, 2) == "pc"
&& rightAttribute.substr(0, 2) == "pc"
&& int(leftAttribute.substr(2)) > 0
&& int(rightAttribute.substr(2)) > 0)
{
var leftNum = int(leftAttribute.substr(2));
var rightNum = int(rightAttribute.substr(2));
if (leftNum < rightNum)
{
return -1;