hypercast.HC
Class HC_Neighborhood

java.lang.Object
  |
  +--hypercast.HC.HC_Neighborhood

public final class HC_Neighborhood
extends java.lang.Object

This class encapsulates the HC_Neighborhood and do all functions regarding that

Specifically, it should do the following jobs:
ageNeighborhood : Should be able to age data and remove stale data
empty : Should be able to check if the HC_Neighborhood is empty
register: It should be able to take a PhysicalAddress-LogicalAddress < pair and return true if it was able to install it/reset its age and false otherwise
remove : Remove a neighbor if the physical address matches the one in the HC_Neighborhood entry
searchTear: Should return the HC_LogicalAddress of the lowest tear, and HC_Global.MaxAddress if none exists. The tear reported is Ttimeout + Tmissing time units old
searchLittleTear: Should return the HC_LogicalAddress of the lowest tear, and HC_Global.MaxAddress if none exists. This differs from searchTear in that tears which are only Ttimeout old are reported
getNthNeighbor: Gets the HC_AddressPair of the Nth neighbor
resetNeighborhood: Removes all entries from the neighborhood table


Constructor Summary
HC_Neighborhood(hypercast.HC.HC_Node hcnode, hypercast.StatsProcessor sPro)
          Constructs HC_Neighborhood objects with an initialization object and a HC_Node object
 
Method Summary
 int ageNeighborhood()
          Checks the age of all the Neighborhood.
 boolean contains(hypercast.I_LogicalAddress laa)
          Check if there exists a neighbor with a specified logical address
 boolean empty()
          Checks if the neighborhood is empty.
 hypercast.HC.HC_AddressPair getHRoot()
          Gets HRoot's AddressPair
 int getHRootSeqNum()
          Gets HRoot's sequence number
 hypercast.HC.HC_AddressPair getNeighborPair(hypercast.HC.HC_LogicalAddress laddr)
          Gets the AddressPair of a neighbor with a logical address
 hypercast.HC.HC_AddressPair[] getNeighbors()
          Gets all neighbor's AddressPair
 hypercast.HC.HC_AddressPair getNthNeighbor(int n)
          Gets the AddressPair of the Nth neighbor
 int getNumOfNeighbors()
          Returns the number of neighbors in neighbor table
 boolean register(hypercast.HC.HC_AddressPair addrpair)
          Registers the HC_AddressPair to the node's neighborhood table
 boolean remove(hypercast.HC.HC_AddressPair addrpair)
          Removes a HC_AddressPair from the neighborhood table
 void resetNeighborhood()
          Resets the neighborhood table
 int searchLittleTear()
          Searches Little Tear in all the neighborhood
 int searchTear()
          Searches a Tear in all neighborhood
 void setHRootSeqNum(int newseqnum)
          Set HRoot sequence number to a new value
 java.lang.String toString()
          Converts the HC_Neighborhood object to String format
 boolean updateHRoot(hypercast.HC.HC_LogicalAddress laddr, int curseqnum)
          Updates HRoot with HRoot HC_LogicalAddress and sequence number
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

HC_Neighborhood

public HC_Neighborhood(hypercast.HC.HC_Node hcnode,
                       hypercast.StatsProcessor sPro)
Constructs HC_Neighborhood objects with an initialization object and a HC_Node object

Initialize each of the entries in the HC_Neighborhood table to be "unknown", that is, Physical Address is null in each of those HC_AddressPair objects

Parameters:
hcnode - a HC_Node object with respect to which the neighborhood will be constructed.
Method Detail

ageNeighborhood

public int ageNeighborhood()
Checks the age of all the Neighborhood. Ages all the valid data and removes any data that has become stale

Returns:
1 if all neighbors have expired, 0 otherwise

empty

public boolean empty()
Checks if the neighborhood is empty. Checks if all the entries in the array are null. If yes, it returns true, else it returns false.

Returns:
true or false, depending on whether the neighborhood is empty or not

getNumOfNeighbors

public int getNumOfNeighbors()
Returns the number of neighbors in neighbor table


register

public boolean register(hypercast.HC.HC_AddressPair addrpair)
Registers the HC_AddressPair to the node's neighborhood table

Algorithm:
1. Calculate the index of the HC_LogicalAddress in the Neighborhood View
(a) If it is not a neighbor return false
2. Check if the index is occupied;
(a) If it is, check if the PhysicalAddress is the same
(i) If it is, reset the age, and return true
(ii) If it is not, return false
(b) If it is not, install the Pair, and return true

Parameters:
addrpair - a LogicalAddress/PhysicalAddress pair
Returns:
true or false

updateHRoot

public boolean updateHRoot(hypercast.HC.HC_LogicalAddress laddr,
                           int curseqnum)
Updates HRoot with HRoot HC_LogicalAddress and sequence number

Parameters:
laddr - a HC_LogicalAddress object
curseqnum - current sequence number
Returns:
true or false

remove

public boolean remove(hypercast.HC.HC_AddressPair addrpair)
Removes a HC_AddressPair from the neighborhood table

Algorithm:
Find the Index and check if physical address is the same
(a) If yes, remove and make that point unknown
(b) If no, make it false

Parameters:
addrpair - a Node Address
Returns:
true if it was able to remove the data, false otherwise

searchTear

public int searchTear()
Searches a Tear in all neighborhood

Algorithm:
The tear found is one where the neighborhood table entry has been missing
Check each neighbor in turn, in increasing logical address order.
Stop when the neighbor's LA exceeds that of the known HRoot.
If a neighbor is found to be absent, report it as a tear.

Returns:
The index of a tear if there is one, and HC_Global.MaxAddress otherwise.

searchLittleTear

public int searchLittleTear()
Searches Little Tear in all the neighborhood

Algorithm:
The tear found is one where the neighborhood table entry has been missing for Ttimeout time.
Check each neighbor in turn, in increasing logical address order.
Stop when the neighbor's LA exceeds that of the known HRoot.
If a neighbor is found to be absent, report it as a tear.

Returns:
The index of a tear if there is one, and HC_Global.MaxAddress otherwise.

getNthNeighbor

public hypercast.HC.HC_AddressPair getNthNeighbor(int n)
Gets the AddressPair of the Nth neighbor

Parameters:
n - integer representing the Index of neighbor
Returns:
a copy of the HC_AddressPair of the requested neighbor

getNeighborPair

public hypercast.HC.HC_AddressPair getNeighborPair(hypercast.HC.HC_LogicalAddress laddr)
Gets the AddressPair of a neighbor with a logical address

Parameters:
laddr - a Neighbor's HC_LogicalAddress
Returns:
returns a copy of the HC_AddressPair of the requested neighbor

contains

public boolean contains(hypercast.I_LogicalAddress laa)
Check if there exists a neighbor with a specified logical address

Parameters:
laa - a I_LogicalAddress
Returns:
returns true if finding a neighbor with logical address la; otherwise flase.

getNeighbors

public hypercast.HC.HC_AddressPair[] getNeighbors()
Gets all neighbor's AddressPair

Returns:
returns an array of HC_AddressPair of all neighbors

getHRoot

public hypercast.HC.HC_AddressPair getHRoot()
Gets HRoot's AddressPair

Returns:
the HC_AddressPair of the HRoot

getHRootSeqNum

public int getHRootSeqNum()
Gets HRoot's sequence number

Returns:
an integer representing the sequence number

setHRootSeqNum

public void setHRootSeqNum(int newseqnum)
Set HRoot sequence number to a new value

Parameters:
newseqnum - an integer representing the new sequence number

resetNeighborhood

public void resetNeighborhood()
Resets the neighborhood table


toString

public java.lang.String toString()
Converts the HC_Neighborhood object to String format

Overrides:
toString in class java.lang.Object
Returns:
string representation of the object