Utils
Class Utils

java.lang.Object
  extended by Utils.Utils

public class Utils
extends java.lang.Object

Class holding different utility methods for the application

Author:
Ioannis Kakavas, Spyridon Dossis

Field Summary
(package private) static byte[] HEX_CHAR_TABLE
           
 
Constructor Summary
Utils()
           
 
Method Summary
static java.util.Hashtable<com.adventnet.snmp.snmp2.SnmpOID,com.adventnet.snmp.snmp2.SnmpVar> createInterfaceList(com.adventnet.snmp.snmp2.SnmpSession session, java.lang.String userName)
          Creates a hashtable holding all the router's interfaces
static java.util.Hashtable<com.adventnet.snmp.snmp2.SnmpOID,com.adventnet.snmp.snmp2.SnmpVar> createIpList(com.adventnet.snmp.snmp2.SnmpSession session, java.lang.String userName)
          Creates a Hashtable containing the IP Addresses
static java.util.Vector<java.lang.String> createNeighborsList(com.adventnet.snmp.snmp2.SnmpSession session, java.lang.String userName)
          Creates a Vector holding all the IP addresses in the routing table referring to other machines.
static void createRouterConnections(RouterCollection r)
          Creates a .dot file containing all the information needed to create a graph of the router topology using some external tool like neato (Graphviz packet)
static java.lang.String determineRouterID(java.util.Vector<com.adventnet.snmp.snmp2.SnmpVarBind> addresses)
          Gets all the IP addresses of the router, and returns the lower one
static java.lang.String getHexString(byte[] raw)
           
static double getRouterLoad(java.util.Vector<java.lang.Long> samples, long pollingDuration)
           
static long inOctetsSum(java.util.Vector<com.adventnet.snmp.snmp2.SnmpVarBind> v)
          Calculates the sum of inOctets for all the interfaces of the router
static void printHashtable(java.util.Hashtable<com.adventnet.snmp.snmp2.SnmpOID,com.adventnet.snmp.snmp2.SnmpVar> hashTable)
           
static void printSnmpVarBindVectors(java.util.Vector<com.adventnet.snmp.snmp2.SnmpVarBind> v)
           
static void writeToFile(RouterCollection r, java.lang.String filename)
          Writes the information about the discovered routers in a file in logs directory.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

HEX_CHAR_TABLE

static final byte[] HEX_CHAR_TABLE
Constructor Detail

Utils

public Utils()
Method Detail

determineRouterID

public static java.lang.String determineRouterID(java.util.Vector<com.adventnet.snmp.snmp2.SnmpVarBind> addresses)
Gets all the IP addresses of the router, and returns the lower one

Parameters:
addresses - - Vector holding the ip addresses of the router interfaces
Returns:
String routerID

createInterfaceList

public static java.util.Hashtable<com.adventnet.snmp.snmp2.SnmpOID,com.adventnet.snmp.snmp2.SnmpVar> createInterfaceList(com.adventnet.snmp.snmp2.SnmpSession session,
                                                                                                                         java.lang.String userName)
Creates a hashtable holding all the router's interfaces

Parameters:
session -
userName -
Returns:
Hashtable

createIpList

public static java.util.Hashtable<com.adventnet.snmp.snmp2.SnmpOID,com.adventnet.snmp.snmp2.SnmpVar> createIpList(com.adventnet.snmp.snmp2.SnmpSession session,
                                                                                                                  java.lang.String userName)
Creates a Hashtable containing the IP Addresses

Parameters:
session -
Returns:
Hashtable

createNeighborsList

public static java.util.Vector<java.lang.String> createNeighborsList(com.adventnet.snmp.snmp2.SnmpSession session,
                                                                     java.lang.String userName)
Creates a Vector holding all the IP addresses in the routing table referring to other machines.

Parameters:
session -
Returns:

inOctetsSum

public static long inOctetsSum(java.util.Vector<com.adventnet.snmp.snmp2.SnmpVarBind> v)
Calculates the sum of inOctets for all the interfaces of the router

Parameters:
v - Vector holding the SnmpVar Bindings for a specified router concerning inOctets for all its interfaces
Returns:
The sum of incoming bytes in all the router's interfaces

getRouterLoad

public static double getRouterLoad(java.util.Vector<java.lang.Long> samples,
                                   long pollingDuration)
Parameters:
samples -
pollingDuration -
Returns:

printSnmpVarBindVectors

public static void printSnmpVarBindVectors(java.util.Vector<com.adventnet.snmp.snmp2.SnmpVarBind> v)

printHashtable

public static void printHashtable(java.util.Hashtable<com.adventnet.snmp.snmp2.SnmpOID,com.adventnet.snmp.snmp2.SnmpVar> hashTable)

writeToFile

public static void writeToFile(RouterCollection r,
                               java.lang.String filename)
Writes the information about the discovered routers in a file in logs directory. Used when DiscoverTopology is called with the "-w" option

Parameters:
r - The RouterCollection of the Discovered routers
filename - The name of the file to save the information to.

createRouterConnections

public static void createRouterConnections(RouterCollection r)
Creates a .dot file containing all the information needed to create a graph of the router topology using some external tool like neato (Graphviz packet)

Parameters:
r - The RouterCollection of the discovered routers

getHexString

public static java.lang.String getHexString(byte[] raw)
                                     throws java.io.UnsupportedEncodingException
Throws:
java.io.UnsupportedEncodingException