--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/contrib/mvc-controller/attr.py Thu Mar 11 18:50:34 2010 -0800
@@ -0,0 +1,106 @@
+#!/usr/bin/env python
+"""The glue between a user interface's notion of a generic attribute (the view)
+and the ns-3 notion of an attribute (the model).
+"""
+
+__author__ = "Craig Dowell"
+__copyright__ = "Copyright 2010 University of Washington"
+__version__ = "0.0.1"
+__maintainer__ = "Craig Dowell"
+__email__ = "craigdo@ee.washington.edu"
+__status__ = "Prototype"
+
+import sys
+import ns3
+
+class Entry:
+ """A local representation of an ns-3 attribute."""
+ def __init__ (self, name, help, type, initial):
+ self.__name = name
+ self.__help = help
+ self.__type = type
+ self.__initial = initial
+
+ def GetName (self):
+ """Return the name of the ns-3 attribute described by this Entry."""
+ return self.__name
+
+ def GetHelp (self):
+ """Return the help string of the ns-3 attribute described by this
+ Entry.
+ """
+ return self.__help
+
+ def GetType (self):
+ """Return the underlying type of the ns-3 attribute described by this
+ Entry.
+ """
+ return self.__type
+
+ def GetInitial (self):
+ """Return the initial value of the ns-3 attribute described by this
+ Entry.
+ """
+ return self.__initial
+
+class Attributes:
+ """A local representation of a collection of ns-3 attributes. Typically the
+ attributes of an ns3 Object
+ """
+ def __init__ (self, object):
+ """Initialize the local collection of attributes to echo the attributes
+ of the underlying ns-3 object.
+ """
+ self.__object = object
+ self.__attributeEntries = []
+ self.__num = object.GetTypeId ().GetAttributeN ()
+ for i in range (self.__num):
+ name = object.GetTypeId ().GetAttributeName (i)
+ help = object.GetTypeId ().GetAttributeHelp (i)
+ initial = object.GetTypeId ().GetAttributeInitialValue (i)
+ type = object.GetTypeId ().GetAttributeChecker (i).GetValueTypeName ()
+ self.__attributeEntries.extend ([Entry (name, help, type, initial)])
+
+ def GetNumberAttributes (self):
+ """Return the number of attributes managed in this collection."""
+ return self.__num
+
+ def GetValue (self, i):
+ """Return the current value of the ns-3 attribute described by the ith
+ entry in the collection.
+ """
+ #
+ # We need to provide an ns3.AttributeValue for the call to
+ # ns3.GetAttribute. We can get at the type name which returns for
+ # example, "ns3::UintegerValue". We need to turn taht into something
+ # like ns3.UntegerValue and then create a variable of that type.
+ #
+ type = self.__attributeEntries[i].GetType ()
+ s = "value = %s ()" % type.replace ('::', '.')
+ exec s
+ self.__object.GetAttribute (self.__attributeEntries[i].GetName (), value)
+ return value.Get()
+
+ def GetName (self, i):
+ """Return the name of the ns-3 attribute described by the ith entry
+ in the collection.
+ """
+ return self.__attributeEntries[i].GetName ()
+
+ def GetHelp (self, i):
+ """Return the help string of the ns-3 attribute described by the ith
+ entry in the collection.
+ """
+ return self.__attributeEntries[i].GetHelp ()
+
+ def GetType (self, i):
+ """Return the type of the ns-3 AttributeValue subclass typename of the
+ attribute described by the ith entry in the collection.
+ """
+ return self.__attributeEntries[i].GetType ()
+
+ def GetInitial (self, i):
+ """Return the initial value of the ns-3 attribute described by the ith
+ entry in the collection.
+ """
+ return self.__attributeEntries[i].GetInitial ().Get ()
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/contrib/mvc-controller/node.py Thu Mar 11 18:50:34 2010 -0800
@@ -0,0 +1,66 @@
+#!/usr/bin/env python
+"""The glue between a user interface's notion of a Node (the view) and the ns-3
+ notion of an attribute (the model).
+"""
+
+__author__ = "Craig Dowell"
+__copyright__ = "Copyright 2010 University of Washington"
+__version__ = "0.0.1"
+__maintainer__ = "Craig Dowell"
+__email__ = "craigdo@ee.washington.edu"
+__status__ = "Prototype"
+
+import sys
+import ns3
+import attr
+
+class Node:
+ """The entity (controller) that acts as an adapter between a user interface
+ notion of a generic computing node (the view) and the ns-3 notion of a
+ node (the model).
+ """
+
+ def __init__ (self):
+ """Create a controller element that represents an ns-3 Node, and also
+ the actual underlying ns-3 Node.
+ """
+ self.__node = ns3.Node ()
+ self.__attributes = attr.Attributes (self.__node)
+
+ def GetNumberAttributes (self):
+ """Return the number of attributes available in this Node."""
+ return self.__attributes.GetNumberAttributes ()
+
+ def GetAttributeValue (self, i):
+ """Return the current value of the ns-3 attribute described by the ith
+ entry in this Node.
+ """
+ return self.__attributes.GetValue (i)
+
+ def GetAttributeName (self, i):
+ """Return the name of the ns-3 attribute described by the ith entry in
+ this Node.
+ """
+ return self.__attributes.GetName (i)
+
+ def GetAttributeHelp (self, i):
+ """Return the help string of the ns-3 attribute described by the ith
+ entry in this Node.
+ """
+ return self.__attributes.GetHelp (i)
+
+ def GetAttributeType (self, i):
+ """Return the underlying type of the ns-3 attribute described by the
+ ith entry in this Node.
+ """
+ return self.__attributes.GetType (i)
+
+ def GetAttributeInitial (self, i):
+ """Return the initial value of the ns-3 attribute described by the ith
+ entry in this Node.
+ """
+ return self.__attributes.GetInitial (i)
+
+
+
+