simnet
Class Utils

java.lang.Object
  extended bysimnet.Utils

public class Utils
extends java.lang.Object

Contains generic methods that are not simulation instance specific.


Field Summary
static int os_count
          How many times was getObjectSize called (for debugging).
 
Constructor Summary
Utils()
           
 
Method Summary
static void ancestorClone(java.lang.Object dest, java.lang.Object source)
          For all of the fields in all of the superclasses that source and dest have in common, if the field is not static or transent, and the value in source is not null, copy that value into dest.
static java.lang.String chomp(java.lang.String line, int n)
          Returns the first 'n' words of a line.
static java.lang.Class findCommonBaseClass(java.lang.Class a, java.lang.Class b)
          Return the class that both arguments have as superclasses in common, including the two classes itself.
static java.lang.String[] getArgsFromInt(int i)
          For convienence, to convert a single integer to the first element of a string array.
static int getIPFromString(java.lang.String name)
          Determines the ID of the Node by IP address string
static int getNetworkPart(int ip, int fixed_bits)
          Returns the network part of an ip address with the given fixed bits (fixed_bits is number of leading bits that are part of network address).
static int getObjectSize(java.lang.Object object)
          Returns the size of the given object, using reflection.
protected static int getObjectSize(java.lang.Object object, java.lang.Class base_class, java.lang.String prefix, java.util.HashSet processed)
          Returns the size of the given object using reflection (actual implementation).
static int getPrimitiveSize(java.lang.Object o)
          For a given object, if is a primitive type or a wrapper for a primitive type, return the size of that object.
static java.lang.String getRIPEntryString(RIPEntry re)
          Returns a string representation of a RIPEntry.
static java.lang.String getRIPMessageString(RIPMessage rm)
          Returns a string represenation of a RIPMessage.
static java.lang.String getStringFromArgs(java.lang.String[] args)
          Return a comma delimited string of the arguments passed to it.
static java.lang.String getStringFromIP(int ip)
          Convert an 32-bit integer IP into a string.
static boolean inSameSubnet(int ip1, int ip2, int fixed_bits)
          Returns if two IP addresses are in the same network of the specified size.
static boolean isIPString(java.lang.String name)
          Checks whether a string can be an IP address.
static boolean isNATtedAddress(int ip)
          Utility method to determine whether or not an IP address is NATted.
static boolean isParent(java.lang.Class newclass, java.lang.String parentname)
          Determines whether the specified class is a descendant of the class with the specified name (or that class itself).
static java.lang.String makeAbsoluteDNSName(java.lang.String name, java.lang.String zone)
          Converts a domain name in the specified zone into a fully qualified domain name (with trailing dot).
static java.lang.String peek(java.lang.String line)
          Returns the first word of a line.
static void printout(java.lang.String string)
          Prints out a string and flushes the output buffer.
static java.lang.String toHexString(byte[] b)
          Returns a string representing the Hex encoding of b
static java.lang.String toShortString(java.lang.Object o, int len)
          Returns a short string representation of the specified object.
static java.lang.String trim(java.lang.String str, int len)
          Method to reduce the length of the String representation for some objects, like BigIntegers.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

os_count

public static int os_count
How many times was getObjectSize called (for debugging).

Constructor Detail

Utils

public Utils()
Method Detail

toHexString

public static java.lang.String toHexString(byte[] b)
Returns a string representing the Hex encoding of b


peek

public static java.lang.String peek(java.lang.String line)
Returns the first word of a line.


chomp

public static java.lang.String chomp(java.lang.String line,
                                     int n)
Returns the first 'n' words of a line.

Parameters:
line - line to chomp
n - number of workds to chomp

printout

public static void printout(java.lang.String string)
Prints out a string and flushes the output buffer. All printouts should go through here.

Parameters:
string - the string to print out

getNetworkPart

public static int getNetworkPart(int ip,
                                 int fixed_bits)
Returns the network part of an ip address with the given fixed bits (fixed_bits is number of leading bits that are part of network address).


inSameSubnet

public static boolean inSameSubnet(int ip1,
                                   int ip2,
                                   int fixed_bits)
Returns if two IP addresses are in the same network of the specified size.


getObjectSize

public static int getObjectSize(java.lang.Object object)
Returns the size of the given object, using reflection.


getObjectSize

protected static int getObjectSize(java.lang.Object object,
                                   java.lang.Class base_class,
                                   java.lang.String prefix,
                                   java.util.HashSet processed)
                            throws java.lang.Exception
Returns the size of the given object using reflection (actual implementation). Note that this method will fail (circular reference) if called on an inner class.

Throws:
java.lang.Exception

getPrimitiveSize

public static int getPrimitiveSize(java.lang.Object o)
For a given object, if is a primitive type or a wrapper for a primitive type, return the size of that object. For null objects, returns null. If the object is not primitive, -1 is returned. For strings, the length is returned.


findCommonBaseClass

public static java.lang.Class findCommonBaseClass(java.lang.Class a,
                                                  java.lang.Class b)
Return the class that both arguments have as superclasses in common, including the two classes itself. If a class in java.lang is the only common class, then null will be returned. If either class is an interface, null will be returned (arguable, this should be an exception)


ancestorClone

public static void ancestorClone(java.lang.Object dest,
                                 java.lang.Object source)
For all of the fields in all of the superclasses that source and dest have in common, if the field is not static or transent, and the value in source is not null, copy that value into dest.


toShortString

public static java.lang.String toShortString(java.lang.Object o,
                                             int len)
Returns a short string representation of the specified object. A non-positive length will cause the string to not be truncated.


getArgsFromInt

public static java.lang.String[] getArgsFromInt(int i)
For convienence, to convert a single integer to the first element of a string array.


getStringFromArgs

public static java.lang.String getStringFromArgs(java.lang.String[] args)
Return a comma delimited string of the arguments passed to it.


isParent

public static boolean isParent(java.lang.Class newclass,
                               java.lang.String parentname)
Determines whether the specified class is a descendant of the class with the specified name (or that class itself).

Parameters:
newclass - the class whose inheritence is to be determined
parentname - the name of the parent class
Returns:
TRUE if the specified class is a descendant of (or equal to) the specified parent class; FALSE otherwise

isIPString

public static boolean isIPString(java.lang.String name)
Checks whether a string can be an IP address.

Parameters:
name - the string to check
Returns:
true if it is an IP address, false otherwise

getIPFromString

public static int getIPFromString(java.lang.String name)
Determines the ID of the Node by IP address string

Parameters:
name - a dotted decimal IP address string
Returns:
the int representation of the specified IP; -1 if it cannot be parsed

getStringFromIP

public static java.lang.String getStringFromIP(int ip)
Convert an 32-bit integer IP into a string.

Parameters:
ip - the integer ip address
Returns:
the string representation of the IP

getRIPEntryString

public static java.lang.String getRIPEntryString(RIPEntry re)
Returns a string representation of a RIPEntry.


getRIPMessageString

public static java.lang.String getRIPMessageString(RIPMessage rm)
Returns a string represenation of a RIPMessage.


isNATtedAddress

public static boolean isNATtedAddress(int ip)
Utility method to determine whether or not an IP address is NATted. E.g., is it a 10.0.0.0/8 address?

Parameters:
ip - The ip address to check
Returns:
whether or not this is a NATted address

makeAbsoluteDNSName

public static java.lang.String makeAbsoluteDNSName(java.lang.String name,
                                                   java.lang.String zone)
Converts a domain name in the specified zone into a fully qualified domain name (with trailing dot).

Parameters:
name - The name of the node
zone - The zone the nods is in.
Returns:
A fully qualified domain name.

trim

public static java.lang.String trim(java.lang.String str,
                                    int len)
Method to reduce the length of the String representation for some objects, like BigIntegers.

Parameters:
str - The string to reduce
len - The number of characters in the string that will remain