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

PONGsim (Python Overlay Network Graphical Simulator)
Module simulating clustered search applications
 
Version: 7.10
 
Nicklas Beijar, nbeijar@netlab.tkk.fi
Networking Laboratory, Helsinki University of Technology
 
Contibutions by:
Jouni Soitinaho
 
######################################################################
 
Simulator for search algorithms in unstructured peer-to-peer networks
 
Copyright (c) 2005-2007 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.
 
######################################################################
 
To do:
- Much

 
Modules
       
math
pongsim
pongsim_resources
pongsim_sil
random
string

 
Classes
       
pongsim_resources.Resources
ClusteredApplication(pongsim_sil.SILApplication, pongsim_resources.Resources)
pongsim_sil.SILApplication(pongsim.Application)
ClusteredApplication(pongsim_sil.SILApplication, pongsim_resources.Resources)

 
class ClusteredApplication(pongsim_sil.SILApplication, pongsim_resources.Resources)
    ####################################################################
###   S I L A p p l i c a t i o n
####################################################################
 
 
Method resolution order:
ClusteredApplication
pongsim_sil.SILApplication
pongsim.Application
pongsim_resources.Resources

Methods defined here:
connectsearchlink(self, params)
Send a connect request to another cluster for connecting a search link.
generatehello(self)
Send a hello message on all outgoing index links.
generateindexupdate(self, dummy=None)
Generate a periodical index update. 
 
Schedules itself after time defined in scenario-parameter indexupdateinterval.
getdetailedinfo(self)
Return the the node's description that is written in a separate window when the node is examined.
getdisplayinfo(self)
Return the text written beside the node.
hellointerval(self, dummy=None)
Perform the functions that are done periodically at each hello interval.
init(self)
Initialize the application.
on_added_resource(self, resource)
Handle an added resource.
 
Called by the Resources class when a resource has been added. 
The floodindex application floods an update.
on_receive_response(self, msg)
Handle a received search reply.
on_removed_resource(self, resource)
Handle an removed resource.
 
Called by the Resources class when a resource has been removed. 
The floodindex application floods an update.
on_search_request(self, resource, searchid)
Handle a search request generated by the node. 
 
Called by the Resources class when a resource request is generated.
outofbanddata(self, key, value)
Set the data that is agreed without any protocol (operator agreements) or manually configured.
 
Corresponds to the user/administrator configuring the application.
received_connectrep(self, msg)
Handle a received connect reply and adds the new search link.
received_connectreq(self, msg)
Handle a received connect request. 
 
Forward to a neighbor with a lower load if possible. Otherwise answer to the request with a connect reply.
received_hello(self, msg)
Handle a received hello message. 
 
Store the load of this neighbor.
receivegeneral(self, ttl, type, id, msg)
Handle reception of a general message and call the corresponding handler. 
 
Called by the SIL framework.
receiveindex(self, ttl, msg, destinations, firsthop=False, prevnode=None)
Handle received index updates.
 
Called by the SIL framework. 
Determines the nodes to which the message is forwarded from the candidate destinations based on the index strategy.
receivesearch(self, ttl, msg, destinations, firsthop=False, prevnode=None)
Handle received search requests.
 
Called by the SIL framework. 
Determines the nodes to which the message is forwarded from the candidate destinations based on the search strategy. 
Maintains clusterpath and clusterstack if configured so.
replysearch(self, searcher, searchid, sendtime, where)
Send a search reply.

Methods inherited from pongsim_sil.SILApplication:
addindexlink(self, dest, ttl=255)
Add a index link from this node to the destination node.
addlink(self, dest, index, search, indexttl=255, searchttl=255)
Add a search or index link (or both) from this node to the destination node.  
 
For an index link: index = True, indexttl defined (default 255)
For a search link: search = True, searchttl defined (default 255)
If there already exists a link to the given node, that is updated.
addsearchlink(self, dest, ttl=255)
Add a search link from this node to the destination node.
draw(self, canvas, x, y)
Draw the application-specific details - here the search and index links.
floodindex(self, msg, ttl=None, id=None)
Send a index update message using flooding. 
 
If no ttl is specified, the link-specific one is used. If no id is specified, a random one is generated. 
NOT to be subclassed.
floodsearch(self, msg, ttl=None, id=None)
Send a search message using flooding. 
 
If no ttl is specified, the link-specific one is used. If no id is specified, a random one is generated. 
NOT to be subclassed.
forwardindex(self, msg, destinations, ttl=None, id=None)
Forward a previously received index update message using flooding.
 
If no ttl is specified, the link-specific one is used. NOT to be subclassed.
forwardsearch(self, msg, destinations, ttl=None, id=None)
Forward a previously received search message using flooding.
 
If no ttl is specified, the link-specific one is used. NOT to be subclassed.
getindexneighbors(self, exclude=None)
Return the neighbors to which this node has an index link, excluding an optional node.
getsearchneighbors(self, exclude=None)
Return the neighbors to which this node has a search link, excluding an optional node.
isnew(self, id)
Returns True if the message with the given id has been forwarded earlier by this node.
 
Remembers the current id. NOT recommended to be subclassed, but CAN be subclassed to skip checking.
receive(self, packedmsg)
Handle received message.
 
This function is called by the Node when a message is received. The SIL framework handles
index, search and generic messages separately. NOT to be subclassed.
remove(self)
Remove node.
removealllinks(self)
removeindexlink(self, dest)
Remove a index link from this node to the destination node.
removelinks(self, dest)
Remove a search link from this node to the destination node.
removesearchlink(self, dest)
Remove a search link from this node to the destination node.
sendgeneral(self, msg, dest, type=0, ttl=None, id=None)
Send a message of other type to a specified node.
 
Messages are sent directly to the destination - there is no need for a search/index link path to the destination. 
TTL and ID defaults to None, since these messages are not affected by flooding. They can be used for 
an application-specific purpose. Type can be any integer, except for the reserved values (1 and 2), defaulting to 0. 
NOT recommended to be subclassed.

Methods inherited from pongsim.Application:
__init__(self, node)
Initiate the application.
 
The original function MUST be called from an overriding function. A better approach
is to override the init() function.
send(self, message, destination=None)
Send the given message to the given destination.

Methods inherited from pongsim_resources.Resources:
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)
initialresources(self, resources)
Add the given resources as the initial resources.
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 inherited from pongsim_resources.Resources:
nextsearchid = 1

 
Data
        CLUSTER_STATUS_CONNECTED = 2
CLUSTER_STATUS_CONNECTING = 1
CLUSTER_STATUS_UNCONNECTED = 0
CONNECT_REP_FIELD_CLUSTER = 1
CONNECT_REP_FIELD_NODE = 0
CONNECT_REQ_FIELD_CLUSTER = 1
CONNECT_REQ_FIELD_NODE = 0
CONNECT_REQ_FIELD_TTL = 2
MSG_CONNECT_REP = 11
MSG_CONNECT_REQ = 10
MSG_HELLO = 12
MSG_SEARCH_REP = 13