edu.virginia.cs.mng.hypercast.HC
Class HC_Neighborhood

java.lang.Object
  |
  +--edu.virginia.cs.mng.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


Field Summary
(package private)  HC_AddressPair HRoot
          AddressPair of the HRoot
(package private)  int HRootSeqNum
          HRoot sequence number
(package private)  int MNTimeOut
          MissingNeighbor Time
(package private)  HC_AddressPair[] NView
          AddressPair array of all neighbors
private  HC_Node parent
          Hypercast node object
 
Constructor Summary
HC_Neighborhood(HC_Node hcnode)
          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
 
Method Summary
 int ageNeighborhood()
          Checks the age of all the Neighborhood.
 boolean empty()
          Checks if the neighborhood is empty.
 HC_AddressPair getHRoot()
          Gets HRoot's AddressPair
 int getHRootSeqNum()
          Gets HRoot's sequence number
 HC_AddressPair getNeighborPair(HC_LogicalAddress laddr)
          Gets the AddressPair of a neighbor with a logical address
 HC_AddressPair[] getNeighbors()
          Gets all neighbor's AddressPair
 HC_AddressPair getNthNeighbor(int n)
          Gets the AddressPair of the Nth neighbor
 int getNumOfNeighbors()
          Returns the number of neighbors in neighbor table
 boolean register(HC_AddressPair addrpair)
          Registers the HC_AddressPair to the node's neighborhood table Algorithm:
1.
 boolean remove(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
 void resetNeighborhood()
          Resets the neighborhood table
 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.
 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.
 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(HC_LogicalAddress laddr, int curseqnum)
          Updates HRoot with HRoot HC_LogicalAddress and sequence number
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, wait, wait, wait
 

Field Detail

NView

HC_AddressPair[] NView
AddressPair array of all neighbors

HRoot

HC_AddressPair HRoot
AddressPair of the HRoot

HRootSeqNum

int HRootSeqNum
HRoot sequence number

MNTimeOut

int MNTimeOut
MissingNeighbor Time

parent

private HC_Node parent
Hypercast node object
Constructor Detail

HC_Neighborhood

public HC_Neighborhood(HC_Node hcnode)
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:
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(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(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(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 HC_AddressPair getNthNeighbor(int n)
Gets the AddressPair of the Nth neighbor
Parameters:
integer - representing the Index of neighbor
Returns:
a copy of the HC_AddressPair of the requested neighbor

getNeighborPair

public HC_AddressPair getNeighborPair(HC_LogicalAddress laddr)
Gets the AddressPair of a neighbor with a logical address
Parameters:
a - Neighbor's HC_LogicalAddress
Returns:
returns a copy of the HC_AddressPair of the requested neighbor

getNeighbors

public HC_AddressPair[] getNeighbors()
Gets all neighbor's AddressPair
Returns:
returns an array of HC_AddressPair of all neighbors

getHRoot

public 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:
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
Returns:
string representation of the object
Overrides:
toString in class java.lang.Object