objects.logic.entity.entityManager.entityManager Class Reference

The entityManager class maintains two dictionaries of entities in the form of:. More...

Inherits objects::logic::common::observerInterface::observerInterface.

List of all members.

Public Member Functions

def __init__
def removeAllEntities
 Clears the internal networkEntity dictionaries.
def getEntityCollectionSize
def intializeIPDatabase
 Initialize the MaxMind GEO IP Database.
def getSafeEntityCollectionByPK
def getSafeFilteredEntityCollectionByPK
 Returns a subset of the "master" networkEntity Dictionary filtered by the supplied "filter" object.
def getSafeFilteredEntityCollectionByGeoLoc
 Returns a subset of the networkEntity dictionary keyed by Geographical location.
def __getattr__
def getHostIPList
 Pcapy lacks the ability to derive any meaningful information (like an IP address) from a NPF device name.
def update
 Implementation of observer method.
def extractSelfIPAddress
 Looks at decoded packet Dictionary, and tried to guess which IP address is the one assigned to the current PC.
def processDataPacket
 processes a single decoded packet Dictionary.

Public Attributes

 entityCollection
 stats
 filteredColl
 filteredCollByLoc
 currentIPAddress
 selfIPList
 selfIPAddress
 lck
 geoIP
 xportTableDict
 decoder
 cnt
 hostIPList


Detailed Description

The entityManager class maintains two dictionaries of entities in the form of:.

{[ip,dstPort]: networkEntity} and {(lon, lat): networkEntityList()}.

The first dictionary is optimized for fast lookup of an individual networkEntiry, since the dictionary is a 1-1 match. The second dictionary is optimized for the map Drawing cycle. Both dictionaries are built on the fly for performance reasons. The entityManager class is also one of the consumers of the networkMonitor objects, building the dictionary as it is fed new packets.

Definition at line 44 of file entityManager.py.


Member Function Documentation

def objects.logic.entity.entityManager.entityManager.__getattr__ (   self,
  name 
)

Definition at line 196 of file entityManager.py.

00196                                :    
00197         if name == 'geoIP':
00198             return self.geoIP
00199         
00200         logger.log(__name__ + ": Cannot get [" + name + "] attribute")
00201         raise AttributeError, name
00202         
00203     

def objects.logic.entity.entityManager.entityManager.__init__ (   self  ) 

Definition at line 45 of file entityManager.py.

00045                       :
00046         
00047         #{[destIP,destPost]: entity}
00048         self.entityCollection = dict()
00049         self.stats            = entityStatistics()
00050         
00051         # a filtered dictionary, by its primary key        
00052         self.filteredColl         = dict()
00053         # a filtered dictionary, by location
00054         self.filteredCollByLoc    = dict()
00055         
00056         self.currentIPAddress = None
00057         self.selfIPList       = None
00058         self.selfIPAddress    = None
00059         
00060         self.lck              = RLock()
00061         
00062         self.geoIP            = None
00063         
00064         self.getHostIPList()  
00065         self.intializeIPDatabase()
00066         
00067         self.xportTableDict = extXportTableDict()
00068         
00069         self.decoder = packetDecoder()
00070         self.decoder.setDefaultReader()
00071         
00072         self.cnt = 0
00073     
00074     
    ## Clears the internal networkEntity dictionaries 

def objects.logic.entity.entityManager.entityManager.extractSelfIPAddress (   self,
  decodedPackeDict 
)

Looks at decoded packet Dictionary, and tried to guess which IP address is the one assigned to the current PC.

Parameters:
decodedPackeDict Dictionary
Returns:
Either the source or destination IP Address. Whichever is the "Self" Address.

Definition at line 240 of file entityManager.py.

00240                                                     :
00241         if decodedPackeDict['sourceIP'] in self.hostIPList:
00242             return decodedPackeDict['sourceIP']
00243         
00244         if decodedPackeDict['destIP'] in self.hostIPList:
00245             return decodedPackeDict['destIP']
00246         
00247         raise exception("Could not identify the IP Address of this device.", True)
00248     
00249     
00250     
    ## processes a single decoded packet Dictionary.

def objects.logic.entity.entityManager.entityManager.getEntityCollectionSize (   self  ) 

Definition at line 85 of file entityManager.py.

00085                                      :
00086         return len(self.entityCollection)
00087     
00088     
    ## Initialize the MaxMind GEO IP Database.    

def objects.logic.entity.entityManager.entityManager.getHostIPList (   self  ) 

Pcapy lacks the ability to derive any meaningful information (like an IP address) from a NPF device name.

This functions will retrieve all IP addresses allocated by the system. This list will then be used to "guess" to source IP (as the this Computer's IP) by looking at the rest of the IP traffic.

Definition at line 207 of file entityManager.py.

00207                            :
00208         hostnameInfo = socket.gethostbyname_ex(socket.gethostname())
00209                 
00210         self.hostIPList = hostnameInfo[2] 
00211         print self.hostIPList
00212         
    ## Implementation of observer method. this class is an observer of the networkMonitor class

def objects.logic.entity.entityManager.entityManager.getSafeEntityCollectionByPK (   self  ) 

Definition at line 101 of file entityManager.py.

00101                                          :        
00102         newDict = None
00103         # lock the object
00104         self.lck.acquire(1)                    
00105         try:
00106             newDict =  self.entityCollection.copy()                
00107         finally:
00108             self.lck.release()
00109         
00110         return newDict
00111 
00112     

def objects.logic.entity.entityManager.entityManager.getSafeFilteredEntityCollectionByGeoLoc (   self,
  filter 
)

Returns a subset of the networkEntity dictionary keyed by Geographical location.

This is done to keep track of of multiple entities at distinct locations which facilitate the main Map redraw cycle. This list will essentially contain the same information as a filtered entity collection, but it will be keyed by location rather than its primary key.

The key of the dictionary is the longitude/latitude pair. the value is an small list of all entities at that particular location.

Parameters:
filter baseFilter derived filter object
Returns:
Dictionary in the form of: {(lon, lat): entityList() }

Definition at line 158 of file entityManager.py.

00158                                                              :
00159         
00160         start = time.time()
00161         
00162         insertIntoList = True
00163           
00164         if filter == None:
00165             return copy.copy(self.filteredCollByLoc)
00166         
00167         else:        
00168             # lock the object
00169             self.lck.acquire(1)
00170             try:
00171                 self.filteredCollByLoc.clear()
00172                 
00173                 for key, netEnt in self.entityCollection.iteritems():
00174                         if filter.shouldDisplayEntity(netEnt):
00175                             
00176                             lon = netEnt.foreignLongitude
00177                             lat = netEnt.foreignLatitude
00178                                                         
00179                             newKey = (lon, lat)
00180                             if not self.filteredCollByLoc.has_key(newKey):                                
00181                                 self.filteredCollByLoc[newKey] = list()  
00182                                  
00183                             self.filteredCollByLoc[newKey].append(netEnt)
00184                                     
00185                                          
00186             finally:
00187                 self.lck.release()
00188                 
00189             end = time.time()
00190             msg = "getSafeFilteredEntityCollectionByGeoLoc: %3.4f to process %d Items" % (end - start, len(self.entityCollection))
00191             #print msg
00192                         
00193             return copy.copy(self.filteredCollByLoc)
00194     
00195     
    def __getattr__(self, name):    

def objects.logic.entity.entityManager.entityManager.getSafeFilteredEntityCollectionByPK (   self,
  filter 
)

Returns a subset of the "master" networkEntity Dictionary filtered by the supplied "filter" object.

If "filter" is None, then just return a copy of the previously filtered collection. This is done to reduce the nummber of filtering operations, since this can become time consuming if the Dictionary becomes large. Since The entity collection is indexed by its primary key, so each dictionary key has exactly one element.

Parameters:
filter baseFilter derived filter object
Returns:
Dictionary in the form of: {[ip,dstPort]: networkEntity}.

Definition at line 120 of file entityManager.py.

00120                                                          :
00121         
00122         start = time.time()
00123           
00124         if filter == None:
00125             return self.filteredColl.copy() 
00126         
00127         else:        
00128             # lock the object
00129             self.lck.acquire(1)
00130             try:                
00131                 self.filteredDict.clear()
00132                 
00133                 for key, netEnt in self.entityCollection.iteritems():
00134                     if filter.shouldDisplayEntity(netEnt):                    
00135                         self.filteredColl[key] = netEnt                
00136             finally:
00137                 self.lck.release()
00138         
00139         end = time.time()
00140         msg = "getSafeFilteredEntityCollectionByPK: %3.4f to process %d Items" % (end - start, len(self.entityCollection))
00141         #print msg
00142         
00143         return self.filteredColl.copy()    
00144                         
00145     
00146     
    ## Returns a subset of the networkEntity dictionary keyed by Geographical location. 

def objects.logic.entity.entityManager.entityManager.intializeIPDatabase (   self  ) 

Initialize the MaxMind GEO IP Database.

TODO -- handle exceptions caused by the DLL not being properly installed DLL is installted by copying GeoIpComEx.dll to the windows/system32 folder (or windows/syswow64 for 64 bit version of windows) and then registering it.

Definition at line 93 of file entityManager.py.

00093                                  :        
00094         self.geoIP = win32com.client.Dispatch("GeoIPCOMEx.GeoIPEx")        
00095         geoIPDBLocation = os.sep.join([os.path.dirname(__file__), globalStrings.geoIPDBLocation()])
00096         
00097         
00098         print geoIPDBLocation
00099         self.geoIP.set_db_path(geoIPDBLocation)
00100         

def objects.logic.entity.entityManager.entityManager.processDataPacket (   self,
  decodedPacketDict 
)

processes a single decoded packet Dictionary.

Parameters:
decodedPacketDict Decoded packet Dictionary

Definition at line 253 of file entityManager.py.

00253                                                   : 
00254                        
00255         if self.selfIPAddress == None:
00256             self.selfIPAddress = self.extractSelfIPAddress(decodedPacketDict)
00257             logger.log(__name__ + ":" + self.selfIPAddress)
00258         
00259         # lock the object
00260         self.lck.acquire(1)
00261         
00262         try:
00263             # create a list used as s key for the entity dictionary        
00264             key = list()
00265 
00266             if self.selfIPAddress == decodedPacketDict['sourceIP']:
00267                 NodeInfo, procState = self.xportTableDict.getXportTableInfo(decodedPacketDict['sourcePort'])
00268                 
00269                 if NodeInfo == None:
00270                     Pid = "0"
00271                 else:
00272                     Pid = "%d" % NodeInfo["Pid"]
00273         
00274                 key = (decodedPacketDict['destIP'], Pid)                            
00275             else:
00276                 NodeInfo, procState = self.xportTableDict.getXportTableInfo(decodedPacketDict['destPort'])
00277                 
00278                 if NodeInfo == None:
00279                     Pid = "0"
00280                 else:
00281                     Pid = "%d" % NodeInfo["Pid"]
00282             
00283                 key = (decodedPacketDict['sourceIP'], Pid)
00284             
00285             if not self.entityCollection.has_key(key):            
00286                 self.entityCollection[key] = networkEntity(self.selfIPAddress, decodedPacketDict, self.geoIP, self.xportTableDict)
00287             
00288             # process the packet 
00289             self.entityCollection[key].computeStatistics(decodedPacketDict)
00290             
00291         except Exception, ex:
00292                 logger.log(__name__ + ": There was an exception processing decoded packet")
00293                 logger.log(ex)
00294         finally:
00295             self.lck.release()
00296                 
00297                 

def objects.logic.entity.entityManager.entityManager.removeAllEntities (   self  ) 

Clears the internal networkEntity dictionaries.

Definition at line 76 of file entityManager.py.

00076                                :
00077         self.lck.acquire(1)                    
00078         try:
00079             self.entityCollection     = dict() 
00080             self.filteredColl         = dict()        
00081             self.filteredCollByLoc    = dict()              
00082         finally:
00083             self.lck.release()
00084     
    def getEntityCollectionSize(self):

def objects.logic.entity.entityManager.entityManager.update (   self,
  header,
  data 
)

Implementation of observer method.

this class is an observer of the networkMonitor class

Reimplemented from objects.logic.common.observerInterface.observerInterface.

Definition at line 214 of file entityManager.py.

00214                                   :    
00215         
00216         #self.cnt += 1
00217         #print "%d" % (self.cnt)  
00218           
00219         decodedPacketDict = self.decoder.decodePacket(header, data)
00220         
00221         if decodedPacketDict == None:
00222             logger.log(__name__ + "Will not process packet because could not decode")
00223             return
00224         
00225         # in case of an ICMP packet, only Ping type requests should be allowed to
00226         # be displayed as entities
00227         if self.decoder.getXportProtocolString(decodedPacketDict['transportProtocol']) == 'ICMP':
00228             if not self.decoder.isPing(decodedPacketDict['networkHeader'], decodedPacketDict['transportHeader']):
00229                 return    
00230         try:
00231             self.processDataPacket(decodedPacketDict);
00232         except exception, ex:
00233             pass
00234 
00235         
00236     


Member Data Documentation

Definition at line 72 of file entityManager.py.

Definition at line 56 of file entityManager.py.

Definition at line 69 of file entityManager.py.

Definition at line 48 of file entityManager.py.

Definition at line 52 of file entityManager.py.

Definition at line 54 of file entityManager.py.

Definition at line 62 of file entityManager.py.

Definition at line 210 of file entityManager.py.

Definition at line 60 of file entityManager.py.

Definition at line 58 of file entityManager.py.

Definition at line 57 of file entityManager.py.

Definition at line 49 of file entityManager.py.

Definition at line 67 of file entityManager.py.


The documentation for this class was generated from the following file:

Generated on Mon Mar 30 00:26:41 2009 for EyeSpy by  doxygen 1.5.8