pongsim_resources
index
u:\f\project - pongsim\pongsim850\pongsim_resources.py

PONGsim (Python Overlay Network Graphical Simulator)
Resource module of the PONGsim framework
 
Version: 1.65
 
Nicklas Beijar, nbeijar@netlab.tkk.fi
Networking Laboratory, Helsinki University of Technology
 
######################################################################
 
PONGsim (Python Overlay Network Graphical Simulator)
 
Copyright (c) 2005-2010 Nicklas Beijar
 
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or
sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
 
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
 
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
 
######################################################################

 
Modules
       
pongsim_zipf
random

 
Classes
       
AvailableResources
InitialResources
Resources

 
class AvailableResources
    A simulator-wide register for the resources available at different nodes.
 
Used to assist searching so that a search will be directed to a resource that
1) exists 
2) is at any node.
 
  Methods defined here:
__init__(self)
Init the AvailableResrouce storage.
 
The default distribution is uniform.
deregister(self, resource, node)
Deregister a given resource that was available at the given node.
random(self, exclude=None)
Returns a random resource that can be available at any node.
 
If argument exclude is given, a resource found in the excluded node will not be selected.
register(self, resource, node)
Register a given resource that is available at the given node.
zipfdistribution(self, skew=1.0)
Use a zipf distribution with the given skew.

 
class InitialResources
    A class for generating the resources that initially are available.
 
  Methods defined here:
__init__(self, nodes)
Initialize the InitialResources for the given number of nodes.
 
The default distribution is uniform.
generate(self, numberofresources, mincopies=1, maxcopies=1)
Generate the given number of resources and allocate them to the nodes.
 
The number of copies of a resource is random between the given limits.
get(self)
Return the initial resources for the node that calls this function.
zipfdistribution(self, skew=1.0)
Use a zipf distribution with the given skew.

 
class Resources
    Node-specific class for generating resources and search requests.
 
Should be subclassed together with an Application or SILApplication class.
 
  Methods defined here:
addresource(self, dummy=None)
Add a resource to the node. 
 
Adds a random resource, id defined by the scenario-parameters dynamicresourcefrom and dynamicresourceto.
If dynamicresourceto is undefined, nrofresources is used as upper limit. 
Schedules itself again after interval defined in the scenario-parameter indexaddinterval.
Schedules removal of the added resource after interval defined in the scenario-parameter indexremoveinterval
(or in indexaddinterval if indexremoveinterval is undefined).
generate_search(self, dummy=None)
Generate a search request, which is flooded on the search links. 
 
Scheduled calling, with rescheduling.
generateresources(self, count=None)
init(self, log, searchinterval, indexaddinterval, indexremoveinterval, removeinitialresources, searchtimeout, dynamicresourcefrom, dynamicresourceto, postponeremoval, valuecounter)
Initialize the Resources module.
 
Arguments:
log - A Log for storing and displaying warning messages. 
searchinterval - The average interval between successive search requests. 
indexaddinterval -  The average interval between sucessive resource additions. None = resources are never added dynamically. 
indexremoveinterval - The average time the resource is available at the node. None = resources are never removed.
removeinitialresources - True if the initial resources should be removed after a indexremoveinterval.
searchtimeout - The time period after which the search results are examined. 
dynamicresourcefrom - The start of the number range of resource numbers added dynamically. 
dynamicresourceto - The end of the number range of resources added dynamically. 
postponeremoval - True if removal of resources should be delayed until the following addition of resources.
valuecounter - A StatisticsCounter that counts the delays and number of replies.
initialresources(self, resources)
Add the given resources as the initial resources.
on_added_resource(self, resource)
Handles an added resource.
 
Called by the Resources class when a resource has been added. The Application can then
perform necessary functions, such as distributing index updates. To be subclassed.
on_removed_resource(self, resource)
Handles an removed resource.
 
Called by the Resources class when a resource has been removed. The Application can then
perform necessary functions, such as distributing index updates. To be subclassed.
on_search_request(self, resource, searchid)
Handles a search request generated by the node. 
 
Called by the Resources class when a resource request is generated. The application can then e.g. 
forward the request to other nodes. To be overrided.
removeresource(self, resource)
Remove a resource from the node.
reportfound(self, searchid, where)
Reports a found resource and collect statistics.
timeoutsearch(self, searchid)
Examine the search results collected during the search, and collect statistics about the search.
 
Called when a given time has expired since the search was initiated. A search request timed out with either results or without results.

Data and other attributes defined here:
nextsearchid = 1