Sim
Class World

java.lang.Object
  extended by Sim.World

public class World
extends java.lang.Object

World implements a world of Nodes. The World also simulates the physical transmission of packets, and whether a packet is lost due to noise.


Constructor Summary
World(edu.rit.numeric.prob.BooleanPrng noisePrng)
          Constructs a new World, using the given BooleanPrng to determine packet loss.
World(double noiseRatio, java.util.Random rng)
          Constructs a new World with the given amount of noise.
 
Method Summary
 void addNode(Node n)
          Adds a Node into the World that is capable of receiving frames.
 Node getNode(int address)
          Returns the Node whose address matches the address given, if it is part of this World.
 Node getRandomNode(java.util.Random rng)
          Returns a Node in the World at random, with an equal probability of returning any specific Node.
 boolean removeNode(int address)
          Removes a Node (by giving its unique address) from the World.
 void sendFrame(HardwareFrame frame, Location transmissionPoint, double distance)
          Sends a frame to all Nodes within listening range of the transmission point given.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

World

public World(double noiseRatio,
             java.util.Random rng)
Constructs a new World with the given amount of noise. noiseRatio percent of packets will be lost on average. The loss occurs at the receiving end, if it does occur, so if a Node sends a packet, it is possible for some of its neighbors to receive it and some to not receive it.

Parameters:
noiseRatio - a percentage from 0 (no loss) to 1 (total loss)
rng - non-null source of randomness to use for packet loss

World

public World(edu.rit.numeric.prob.BooleanPrng noisePrng)
Constructs a new World, using the given BooleanPrng to determine packet loss. The loss occurs at the receiving end, if it does occur, so if a Node sends a packet, it is possible for some of its neighbors to receive it and some to not receive it.

Parameters:
noisePrng - a percentage from 0 (no loss) to 1 (total loss)
Method Detail

addNode

public void addNode(Node n)
Adds a Node into the World that is capable of receiving frames. There cannot be more than one Node with the same address in a World.

Parameters:
n - non-null Node with unique (to this World) address

getNode

public Node getNode(int address)
Returns the Node whose address matches the address given, if it is part of this World.

Parameters:
address - address of Node to return
Returns:
non-null if a Node with the address exists

getRandomNode

public Node getRandomNode(java.util.Random rng)
Returns a Node in the World at random, with an equal probability of returning any specific Node.

Parameters:
rng - non-null source of randomness, from which a single integer will be pulled.
Returns:
non-null Node in this World

removeNode

public boolean removeNode(int address)
Removes a Node (by giving its unique address) from the World. That Node will no longer receive any frames.

Parameters:
address - address of Node to remove
Returns:
true if a Node was removed (address was valid)

sendFrame

public void sendFrame(HardwareFrame frame,
                      Location transmissionPoint,
                      double distance)
Sends a frame to all Nodes within listening range of the transmission point given.

Parameters:
frame - non-null HardwareFrame
transmissionPoint - non-null Location
distance - distance in which frame can be received.