Fairness.Nodes
Class Node

java.lang.Object
  extended by Fairness.Nodes.Node

public class Node
extends java.lang.Object

The Node class is the center of the program design. It contains all of the information for its participation in the trees, for which there is one tree per stripe. A Node is typically in multiple trees at the same time, depending on its amount of inbound bandwidth. The NodeBehavior class is utilized to implement a freeloader or a freeloader detector of our two different types (ancestor rating or debt maintenance). When packets are received there is a report made to the NodeMonitor.


Constructor Summary
Node(Simulation sim, int nodeId, int outboundBW, int inboundBW, NodeMonitor monitor, NodeBehavior nodeBehavior, TreeBehavior treeBehavior)
          Constructs a new Node.
 
Method Summary
 boolean allowChild(Node candidateChild)
          Returns whether a Node is willing to accept a given child.
 int getAvailableOutboundBW(SimulationParameters params)
          Returns the amount of available outbound bandwidth.
 int getInboundBW()
           
 int getNodeId()
           
 int getOutboundBW()
           
 Node getParent(int stripeId)
          Returns this Node's parent for a given stripe ID.
 java.util.List<Node> getPathToRoot(int stripeId)
          Returns a List of all Nodes to and including the root Node for a given stripe tree.
 int getStripeId()
          Gets the stripe ID of the primary stripe for this Node.
 java.util.Set<java.lang.Integer> getStripes()
          Returns a Set of all stripe IDs this Node is currently in.
 TreeInfo getTreeInfo(int stripeId)
          Returns the tree information for this Node's participation in the given stripe.
 TreeInfo makeTreeInfo(int stripeId)
          Creates if needed, and returns the tree information for this Node's participation in the given stripe.
 void processPacket(Simulation sim, NodePacket packet)
          Processes a NodePacket that is being received by this Node during a Simulation.
 boolean receivesStripe(int stripeId)
          Returns true if Node currently receives specified stripe.
 void resetNetwork()
          Resets all network information for this Node by clearing its tree information for all stripes.
 void setLossRate(double lossRate)
          Sets the percentage of packets received or sent that are lost due to network errors.
 void setStripeId(int stripeId)
          Sets the stripe ID to be the primary stripe for this Node.
 java.lang.String toString()
          Returns a string representation of this node: "Node [node ID in hex]"
 boolean wantsJoin()
          Returns true if this Node wants to join another stripe.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Node

public Node(Simulation sim,
            int nodeId,
            int outboundBW,
            int inboundBW,
            NodeMonitor monitor,
            NodeBehavior nodeBehavior,
            TreeBehavior treeBehavior)
Constructs a new Node. After construction there still may be more setup to perform using the setLossRate(double) method.

Parameters:
sim - non-null Simulation this Node will be part of
nodeId - Node ID as assigned from the TreeManager
outboundBW - outbound bandwidth
inboundBW - inbound bandwidth
monitor - non-null NodeMonitor
nodeBehavior - non-null NodeBehavior
treeBehavior - non-null TreeBehavior
Method Detail

setLossRate

public void setLossRate(double lossRate)
Sets the percentage of packets received or sent that are lost due to network errors.

Parameters:
lossRate - a percentage (0 to 1) of packet loss.

processPacket

public void processPacket(Simulation sim,
                          NodePacket packet)
Processes a NodePacket that is being received by this Node during a Simulation. The NodePacket belongs to a stripe and its source should equal the parent for that stripe.

Node reports to the NodeMonitor whether the given packet is received or lost.

A Node will route its packet to all of its children, with the sent and lost flags set appropriately. The NodeBehavior for this Node is queried to see if the packet should be sent to the node.

Parameters:
sim - non-null Simulation
packet - non-null NodePacket

getTreeInfo

public TreeInfo getTreeInfo(int stripeId)
Returns the tree information for this Node's participation in the given stripe. The returned TreeInfo may be modified.

Parameters:
stripeId - stripe to get information about.
Returns:
nullable TreeInfo, null if this Node is not in the stripe, or non-null otherwise.

makeTreeInfo

public TreeInfo makeTreeInfo(int stripeId)
Creates if needed, and returns the tree information for this Node's participation in the given stripe. The returned TreeInfo may be modified. If a TreeInfo was created, then it has no parent and no children.

Parameters:
stripeId - stripe to get information about
Returns:
non-null TreeInfo

resetNetwork

public void resetNetwork()
Resets all network information for this Node by clearing its tree information for all stripes.


getNodeId

public int getNodeId()

getInboundBW

public int getInboundBW()

getOutboundBW

public int getOutboundBW()

getStripeId

public int getStripeId()
Gets the stripe ID of the primary stripe for this Node.


receivesStripe

public boolean receivesStripe(int stripeId)
Returns true if Node currently receives specified stripe. A Node is a participant if its makeTreeInfo method has been called for this stripe ID.

Parameters:
stripeId - stripe ID to query about
Returns:
true if Node is in this stripe

getParent

public Node getParent(int stripeId)
Returns this Node's parent for a given stripe ID.

Parameters:
stripeId - stripe ID to query about
Returns:
nullable Node parent
Throws:
java.lang.IllegalArgumentException - if this Node is not in the stripe tree

getPathToRoot

public java.util.List<Node> getPathToRoot(int stripeId)
Returns a List of all Nodes to and including the root Node for a given stripe tree. This Node is not included in the list. The immediate parent is the first element and the list continues in order to the root, which is the last element.

Parameters:
stripeId - stripe ID to query about
Returns:
non-null List of 0 or more non-null Node
Throws:
java.lang.IllegalArgumentException - if this Node is not in the stripe tree

allowChild

public boolean allowChild(Node candidateChild)
Returns whether a Node is willing to accept a given child.

Parameters:
candidateChild - non-null Node
Returns:
true if this Node is willing to accept, false otherwise

setStripeId

public void setStripeId(int stripeId)
Sets the stripe ID to be the primary stripe for this Node.


toString

public java.lang.String toString()
Returns a string representation of this node: "Node [node ID in hex]"

Overrides:
toString in class java.lang.Object

getAvailableOutboundBW

public int getAvailableOutboundBW(SimulationParameters params)
Returns the amount of available outbound bandwidth. When this node has children in a stripe, its available outbound bandwidth is decreased from the maximum.

Parameters:
params - non-null SimulationParameters (to get stripe size)
Returns:
amount of outbound bandwidth remaining

getStripes

public java.util.Set<java.lang.Integer> getStripes()
Returns a Set of all stripe IDs this Node is currently in.


wantsJoin

public boolean wantsJoin()
Returns true if this Node wants to join another stripe.