from sfa.client.sfi import Sfi
from sfa.util.sfalogging import logger, DEBUG
from sfa.client.sfaserverproxy import SfaServerProxy
from sfa.client.sfi import Sfi
from sfa.util.sfalogging import logger, DEBUG
from sfa.client.sfaserverproxy import SfaServerProxy
### assuming everything is sequential, as simple as it gets
### { url -> (timestamp,version)}
class VersionCache:
### assuming everything is sequential, as simple as it gets
### { url -> (timestamp,version)}
class VersionCache:
def __init__ (self, filename=None, expires=60*60):
# default is to store cache in the same dir as argv[0]
if filename is None:
def __init__ (self, filename=None, expires=60*60):
# default is to store cache in the same dir as argv[0]
if filename is None:
key_values=self.url2version.items()
def old_first (kv1,kv2): return int(kv1[1][0]-kv2[1][0])
key_values.sort(old_first)
key_values=self.url2version.items()
def old_first (kv1,kv2): return int(kv1[1][0]-kv2[1][0])
key_values.sort(old_first)
(timestamp,version) = tuple
how_old = time.time()-timestamp
if how_old<=self.expires:
(timestamp,version) = tuple
how_old = time.time()-timestamp
if how_old<=self.expires:
- print "OUTDATED",url,"(%d seconds ago, expires=%d)"%(how_old,self.expires)
+ print("OUTDATED",url,"(%d seconds ago, expires=%d)"%(how_old,self.expires))
# turns out we might have trailing slashes or not
def normalize (self, url):
# turns out we might have trailing slashes or not
def normalize (self, url):
- self.ip=socket.gethostbyname(self.hostname)
- self.probed=False
+ # look for ip in the cache
+ tuple=cache.get(key)
+ if tuple:
+ (self.hostname, self.ip, self.port) = tuple
+ else:
+ self.ip=socket.gethostbyname(self.hostname)
+
+ cache.set(key, (self.hostname, self.ip, self.port,) )
+ cache.save()
+ self.probed=False
+
+ # mark unknown interfaces as probed to avoid unnecessary attempts
+ if self.hostname=='unknown':
logger.debug("searching in version cache %s"%self.url())
cached_version = VersionCache().get(self.url())
if cached_version is not None:
logger.debug("searching in version cache %s"%self.url())
cached_version = VersionCache().get(self.url())
if cached_version is not None:
logger.debug("using key %s & cert %s"%(key_file,cert_file))
url=self.url()
logger.info('issuing GetVersion at %s'%url)
# setting timeout here seems to get the call to fail - even though the response time is fast
#server=SfaServerProxy(url, key_file, cert_file, verbose=self.verbose, timeout=options.timeout)
server=SfaServerProxy(url, key_file, cert_file, verbose=self.verbose)
logger.debug("using key %s & cert %s"%(key_file,cert_file))
url=self.url()
logger.info('issuing GetVersion at %s'%url)
# setting timeout here seems to get the call to fail - even though the response time is fast
#server=SfaServerProxy(url, key_file, cert_file, verbose=self.verbose, timeout=options.timeout)
server=SfaServerProxy(url, key_file, cert_file, verbose=self.verbose)
- ### fill color to outline wrongly configured bodies
- if 'geni_api' not in version and 'sfa' not in version:
+ ### fill color to outline wrongly configured or unreachable bodies
+ # as of sfa-2.0 registry doesn't have 'sfa' not 'geni_api', but have peers
+ # slicemgr and aggregate have 'geni_api' and 'sfa'
+ if 'geni_api' not in version and 'peers' not in version:
logger.debug(k)
for (k1,v1) in v.iteritems():
logger.debug("\r\t\t%s:%s"%(k1,v1))
logger.debug(k)
for (k1,v1) in v.iteritems():
logger.debug("\r\t\t%s:%s"%(k1,v1))
- # 'geni_api' is expected if the call succeeded at all
- # 'peers' is needed as well as AMs typically don't have peers
- if 'geni_api' in version and 'peers' in version:
- # proceed with neighbours
+ # proceed with neighbours
+ if 'peers' in version:
# locate or create node in graph
try:
# if found, we're good with this one
# locate or create node in graph
try:
# if found, we're good with this one
if not options.outfiles:
options.outfiles=SfaScan.default_outfiles
scanner=Scanner(left_to_right=options.left_to_right, verbose=bool_verbose)
if not options.outfiles:
options.outfiles=SfaScan.default_outfiles
scanner=Scanner(left_to_right=options.left_to_right, verbose=bool_verbose)