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

PONGsim (Python Overlay Network Graphical Simulator)
Module simulating zone index search applications
 
Version: 2.60
 
Nicklas Beijar, nbeijar@netlab.tkk.fi
Networking Laboratory, Helsinki University of Technology
 
######################################################################
 
Simulator for search algorithms in unstructured peer-to-peer networks
 
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
       
math
pongsim
pongsim_resources
pongsim_sil
random
string

 
Classes
       
pongsim_resources.Resources
ZoneIndexApplication(pongsim_sil.SILApplication, pongsim_resources.Resources)
pongsim_sil.SILApplication(pongsim.Application)
ZoneIndexApplication(pongsim_sil.SILApplication, pongsim_resources.Resources)
ConstantZoneSize
DynamicZoneSize1
DynamicZoneSize2
DynamicZoneSize3
DynamicZoneSize4
DynamicZoneSize5
Msg_Ack
Msg_IAmYourPredecessor
Msg_Index
Msg_Join
Msg_JoinReply
Msg_Leave
Msg_Load
Msg_Rejoin
Msg_ReverseRejoin
Msg_Search
Msg_SearchReply
Msg_Shortcut

 
class ConstantZoneSize
    ####################################################################
###    C o n s t a n t Z o n e S i z e
####################################################################
 
  Methods defined here:
__init__(self, zonesize)
ackmessagefields(self)
ackmessageparse(self, resizedata)
getdetailedinfo(self)
getzonesize(self)
indexmessagefields(self, forward)
indexmessageparse(self, resizedata, firsthop)
loadmessagefields(self)
loadmessageparse(self, resizedata)
reportindex(self)
reportsearch(self)
setzonesize(self, zonesize)
stopforwarding(self, resizedata)

 
class DynamicZoneSize1(ConstantZoneSize)
    ####################################################################
###   D y n a m i c Z o n e S i z e 1
####################################################################
 
  Methods defined here:
__init__(self, node, scheduler, adjustmentspeed, loadstatinterval, sizeupdatedelaymax, allowedneighborvariation)
ackmessagefields(self)
ackmessageparse(self, resizedata)
calcglobbal(self)
calcloadstat(self, dummy)
Calculate the load meters sptu and iptu periodically.
        
Reschedules itself.
calcpredbali(self)
calcpredbals(self)
calcsuccbali(self)
calcsuccbals(self)
getdetailedinfo(self)
indexmessagefields(self, forward)
indexmessageparse(self, resizedata, firsthop)
reportindex(self)
reportsearch(self)
setzonesize(self, zonesize)
sizeupdate(self)

Methods inherited from ConstantZoneSize:
getzonesize(self)
loadmessagefields(self)
loadmessageparse(self, resizedata)
stopforwarding(self, resizedata)

 
class DynamicZoneSize2(ConstantZoneSize)
    ####################################################################
###   D y n a m i c Z o n e S i z e 2
####################################################################
 
  Methods defined here:
__init__(self, node, scheduler, adjustmentspeed, loadstatinterval, sizeupdatedelaymax, allowedneighborvariation)
ackmessagefields(self)
ackmessageparse(self, resizedata)
calcpredbali(self)
calcpredbals(self)
calcsuccbali(self)
calcsuccbals(self)
getdetailedinfo(self)
indexmessagefields(self, forward)
indexmessageparse(self, resizedata, firsthop)
reportindex(self)
reportsearch(self)
setzonesize(self, zonesize)
sizeupdate(self)

Methods inherited from ConstantZoneSize:
getzonesize(self)
loadmessagefields(self)
loadmessageparse(self, resizedata)
stopforwarding(self, resizedata)

 
class DynamicZoneSize3(ConstantZoneSize)
    ####################################################################
###   D y n a m i c Z o n e S i z e 3
####################################################################
 
  Methods defined here:
__init__(self, node, scheduler, adjustmentspeed, loadstatinterval, sizeupdatedelaymax, allowedneighborvariation)
getdetailedinfo(self)
indexmessagefields(self, forward)
indexmessageparse(self, resizedata, firsthop)
loadmessagefields(self)
loadmessageparse(self, resizedata)
reportindex(self)
reportsearch(self)
setzonesize(self, zonesize)
sizeupdate(self)

Methods inherited from ConstantZoneSize:
ackmessagefields(self)
ackmessageparse(self, resizedata)
getzonesize(self)
stopforwarding(self, resizedata)

 
class DynamicZoneSize4(ConstantZoneSize)
    ####################################################################
###   D y n a m i c Z o n e S i z e 4
###   Very experimental
####################################################################
 
  Methods defined here:
__init__(self, node, scheduler, adjustmentspeed, loadstatinterval, sizeupdatedelaymax, allowedneighborvariation)
getdetailedinfo(self)
getzonesize(self)
indexmessagefields(self, forward)
indexmessageparse(self, resizedata, firsthop)
reportindex(self)
reportsearch(self)
setzonesize(self, zonesize)
sizeupdate(self)
stopforwarding(self, resizedata)

Methods inherited from ConstantZoneSize:
ackmessagefields(self)
ackmessageparse(self, resizedata)
loadmessagefields(self)
loadmessageparse(self, resizedata)

 
class DynamicZoneSize5(ConstantZoneSize)
    ####################################################################
###   D y n a m i c Z o n e S i z e 5
####################################################################
 
  Methods defined here:
__init__(self, node, scheduler, adjustmentspeed, loadstatinterval, sizeupdatedelaymax, allowedneighborvariation)
getdetailedinfo(self)
indexmessagefields(self, forward)
indexmessageparse(self, resizedata, firsthop)
loadmessagefields(self)
loadmessageparse(self, resizedata)
reportindex(self)
reportsearch(self)
setzonesize(self, zonesize)
sizeupdate(self)

Methods inherited from ConstantZoneSize:
ackmessagefields(self)
ackmessageparse(self, resizedata)
getzonesize(self)
stopforwarding(self, resizedata)

 
class Msg_Ack
     Methods defined here:
__init__(self, node, resizefields)
__repr__(self)
fields(self)
type(self)

 
class Msg_IAmYourPredecessor
     Methods defined here:
__init__(self, node, onleave=False)
__repr__(self)
fields(self)
type(self)

 
class Msg_Index
    ####################################################################
###    M e s s a g e s
####################################################################
 
  Methods defined here:
__init__(self, node, predecessor, additions, deletes, distance, resizefields)
__repr__(self)
fields(self)

 
class Msg_Join
     Methods defined here:
__init__(self, node, deadnodes, rejoinretry)
__repr__(self)
fields(self)
type(self)

 
class Msg_JoinReply
     Methods defined here:
__init__(self, node, successor, zonesize)
__repr__(self)
fields(self)
type(self)

 
class Msg_Leave
     Methods defined here:
__init__(self, node, successor)
__repr__(self)
fields(self)
type(self)

 
class Msg_Load
     Methods defined here:
__init__(self, node, resizedata)
__repr__(self)
fields(self)
type(self)

 
class Msg_Rejoin
     Methods defined here:
__init__(self, node, destination)
__repr__(self)
fields(self)
type(self)

 
class Msg_ReverseRejoin
     Methods defined here:
__init__(self, node, destination)
__repr__(self)
fields(self)
type(self)

 
class Msg_Search
     Methods defined here:
__init__(self, node, searchid, resource, stopnode, shortcutinterval, hops)
__repr__(self)
fields(self)

 
class Msg_SearchReply
     Methods defined here:
__init__(self, searchid, where)
__repr__(self)
fields(self)
type(self)

 
class Msg_Shortcut
     Methods defined here:
__init__(self, node)
__repr__(self)
fields(self)
type(self)

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

Methods defined here:
checkindextimeout(self, dummy)
# SCHEDULED
checktimeout(self)
Check the entry for each indexed node and remove the entry if it has not been updated within its refresh time.
delete(self, graceful=False)
delindexed(self, node)
Delete the entry for the given indexed node and also delete all remote resources of that node.
determinetimeout(self)
generateindexupdate(self, dummy=None)
Sends an update message either periodically or when resources are updated.
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.
init(self)
Initialize the application.
logsearch(self, searchid, msg)
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_iamyourpredecessor(self, msg)
on_receive_join(self, msg)
on_receive_joinreply(self, msg)
on_receive_leave(self, msg)
on_receive_rejoin(self, msg)
on_receive_response(self, msg)
Handle a received search reply.
on_receive_reverse_rejoin(self, msg)
on_receive_shortcut(self, msg)
Handle a received shortcut-link message.
on_received_ack(self, msg)
on_received_load(self, msg)
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. 
 
Available keys:
zonesize - the initial zone size
predecessor - the predecessor (not recommended)
successor - the successor (not recommended)
knownnode - a known node already in the overlay to which the current node will try to send a join request
perform_join(self, dummy)
# SCHEDULED
placenode(self)
preventtimeout(self)
Add the maximum refresh time to the entry for each indexed node in order to temporarily prevent timeout in the near future.
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, previoushop)
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, previoushop)
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, where)
Send a search reply.
resettimeout(self)
sendiamyourpredec(self, (sender, param1, receiver))
sendshortcut(self, searcher)
Send a shortcut-link message.
setpredecessor(self, predecessor)
setsearchlink(self)
Examine which node should be a border node, and which nodes are the real indexed nodes.
setsuccessor(self, successor)
timed_index_update(self, dummy=None)
Generate a periodical index update. 
 
Schedules itself after time defined in scenario-parameter indexupdateinterval.

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
        MSG_ACK = 11
MSG_IAMYOURPREDECESSOR = 19
MSG_JOIN = 15
MSG_JOIN_REPLY = 16
MSG_LEAVE = 17
MSG_LOAD = 12
MSG_REJOIN = 18
MSG_REVERSE_REJOIN = 20
MSG_SEARCH_REP = 13
MSG_SHORTCUT = 14