Exemplo n.º 1
0
    def __init__(self, host, community="aspiringvision", version=2, rt=None):
        self.host = host
        self.community = community
        self.version = version
        self.session = Session(hostname=self.host, community=self.community, version=self.version)
        self.neighbors = []
        
        self.osiris_service_manifest = [
                { 'name': 'snmpd',       'desc': 'SNMP daemon.',                       'unis_name': 'snmp',       'unis_service_type': 'host:snmp'},
                { 'name': 'ryu-manager', 'desc': 'RYU SDN Controller.',                'unis_name': 'ryu',        'unis_service_type': 'nmal:tools:ryu'},
                { 'name': 'lldpd',       'desc': 'LLDP daemon.',                       'unis_name': 'lldp',       'unis_service_type': 'host:lldp'},
                { 'name': 'periscoped',  'desc': 'UNIS network resource database.',    'unis_name': 'periscope',  'unis_service_type': 'ps:tools:periscope'},
                { 'name': 'node',        'desc': 'NodeJS web application.',            'unis_name': 'nodejs',     'unis_service_type': 'host:node'},
                { 'name': 'blippd',      'desc': 'BLIPP performance monitoring tool.', 'unis_name': 'blipp',      'unis_service_type': 'ps:tools:blipp'},
                { 'name': 'ntpd',        'desc': 'Network Time Protocol Daemon',       'unis_name': 'ntp',        'unis_service_type': 'host:ntp'},
                { 'name': 'schedular',   'desc': 'PSchedular Service',                 'unis_name': 'pschedular', 'unis_service_type': 'ps:tools:pschedular'},
                { 'name': 'archiver',    'desc': 'PerfSONAR Esmond Archive utility',   'unis_name': 'esmond',     'unis_service_type': 'ps:tools:esmond'},
                { 'name': 'owampd',      'desc': 'OWAMP web server',                   'unis_name': 'owamp',      'unis_service_type': 'host:owamp'}]


        # TODO: make runtime element from config, hardcode placeholder for now
        if rt is None:
            self.rt = Runtime('http://172.18.0.25:9000')
        else:
            self.rt = rt
Exemplo n.º 2
0
def _get_app(unis, layout, size=None):
    conf = {"auth": True, "secret": "a4534asdfsberwregoifgjh948u12"}
    db = _Database()
    rt = Runtime(unis, proxy={'defer_update': True})
    rt.addService(UnisGrapher)
    if size:
        _build_graph(rt, size)
    else:
        rt.nodes.load()
        rt.links.load()

    if not layout or not rt.graph.load(layout):
        rt.graph.spring(30)
        rt.graph.dump('layout.json')

    auth = AuthHandler(conf, db)
    compiler = CompileHandler(conf, db, rt)
    validator = ValidateHandler(conf, db, rt)
    sketches = SketchHandler(conf, db)
    graph = GraphHandler(conf, db, rt)
    #subscribe = SubscriptionHandler(conf)

    ensure_ssl = SSLCheck(conf)

    #app = falcon.API(middleware=[ensure_ssl])
    app = falcon.API()
    app.add_route('/', graph)
    app.add_route('/c', compiler)
    app.add_route('/a', auth)
    app.add_route('/v', validator)
    app.add_route('/l', sketches)
    app.add_route('/l/{usr}', sketches)
    #app.add_route('/s', subscribe)

    return app
Exemplo n.º 3
0
 def _setup_runtime(self, host_rt):
     # Setting up RT sources
     rt = Runtime(host_rt)
     topo_dict = rt.topologies[0].to_JSON()
     hrefs = []
     for item in topo_dict['domains']:
         href = item['href'].split('/domains')[0]
         if href not in hrefs:
             hrefs.append(href)
     print("Href list: ", hrefs)
     return  Runtime(hrefs, name="host")
Exemplo n.º 4
0
 def on_post(self, req, resp):
     rt = Runtime(self._uri, proxy={"subscribe": False})
     form = req.get_media()
     for part in form:
         if part.filename:
             ex = Exnode({
                 'name': part.secure_filename,
                 'mode': 'file',
                 'created': int(time.time() * 1000000),
                 'modified': int(time.time() * 1000000),
                 'parent': None,
                 'owner': 'wdln',
                 'group': 'wdln',
                 'permission': '744'
             })
             try:
                 with DLTFile(ex, "w", bs=self._bs,
                              dest=self._stage) as dest:
                     part.stream.pipe(dest)
             except AllocationError as exp:
                 resp.status = falcon.HTTP_500
                 resp.text = {"errorcode": 1, "msg": esp.msg}
             rt.insert(ex, commit=True)
             for a in ex.extents:
                 rt.insert(a, commit=True)
             rt.flush()
     resp.cache_control = ['no-cache', 'no-store']
     resp.status = falcon.HTTP_201
     resp.text = {"fid": ex.id, "status": "GOOD", "size": ex.size}
Exemplo n.º 5
0
def main():
    parser = argparse.ArgumentParser(description="Prunes dead dlt allocations")
    parser.add_argument("-H", "--unis", type=str, default="http://localhost:9000")
    parser.add_argument("-p", "--period", type=int, default=60)
    parser.add_argument("-n", "--name", type=str, required=True)
    opts = parser.parse_args()
    local_ibp = f"ibp://{opts.name}:6714"
    rt = Runtime(opts.unis, proxy={"subscribe": False})
    while True:
        print(f"[{datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')}] Interrogaing allocations...")
        r = {s.accessPoint: is_reachable(s.accessPoint) for s in rt.services}
        if local_ibp not in r: r[local_ibp] = is_reachable(local_ibp)
        remove_expiring(r, rt, opts.period)
        rt.flush()
        time.sleep(opts.period)
Exemplo n.º 6
0
    def __init__(self,
                 unis_host=None,
                 unis_server=None,
                 interval=None,
                 config=None,
                 log_file='topod.log'):

        logging.basicConfig(filename=log_file, level=logging.INFO)
        logging.info('Log Initialized.')

        # If config is specified, pull from it, otherwise use parameters given.
        if config is not None:
            self._conf_from_file(config)
        else:
            self.unis_host = unis_host
            self.unis_server = unis_server

        self.log_file = log_file
        self.rt = Runtime(self.unis_host)

        # if no interval is set, default to global interval.
        if interval is None:
            self.discovery_interval = DEFAULT_DISCOVERY_INTERVAL
        else:
            self.discovery_interval = interval

        return
Exemplo n.º 7
0
 def __init__(self, runtime_url=None, domain_name=None):
     
     # Connect to runtime
     try:
         if runtime_url is not None:
             self.rt = Runtime(runtime_url, name="zof")
         else:
             print("Connecting to localhost...")
             self.rt = Runtime("http://localhost:8888")
     except Exception as e:
         print(e)
         raise Exception("Could not connect to runtime.")
     
     self.switches = []
     self.util         = UnisUtil(self.rt)
     self.link_handler = LinkHandler(self.rt) 
Exemplo n.º 8
0
    def __init__(self, host_rt=None, remote_rt=None, host_node_name=None):
        # TODO: read in defaults from a config.
        '''if host_rt == None:
            self.host_rt = Runtime("http://iu-ps01.osris.org:8888", name = "host")
        else:
            self.host_rt = host_rt
        '''
        self.host_rt = self._setup_runtime(host_rt)
        print(self.host_rt)
        if remote_rt == None:
            self.remote_rt = Runtime("http://iu-ps01.osris.org:8888", name = "remote")
        else:
            self.host_rt = remote_rt

        if host_node_name == None:
            try:
                # TODO: fix hard code host node
                self.host_node = next(self.host_rt.nodes.where({"name":"switch:647020279235264"}))
            except:
                traceback.print_exc()
                print("Not a valid node name. Exitting..")
                sys.exit(0)
        else:
            try:
                self.host_node = next(self.host_rt.nodes.where({"name":host_node_name}))
            except:
                print("Not a valid node name. Exitting..")
                sys.exit(0)

        self._register_to_topology()
        self.tc = Traceroute()
        

        return
Exemplo n.º 9
0
 def __init__(self, source):
     if not self.__runtime__:
         if isinstance(source, Runtime):
             type(self).__runtime__ = source
         else:
             conf = {'runtime': {'services': ['unis.services.graph.UnisGrapher']},
                     'cache': {'preload': ['nodes', 'links']}}
             type(self).__runtime__ = Runtime(source, **conf)
Exemplo n.º 10
0
    def _setup(self):
        '''
			Setup the main service. 
			- read and apply config in Meshconfig document.
			- connect to Runtime
			Exit if configuration fails.
        '''

        try:
            self.rt = Runtime(self.unis)
            self.rt.addService("unis.services.data.DataService")
        except Exception as e:
            print(e)
            logging.info("COULD NOT CONNECT TO UNIS")
            raise AttributeError("COULD NOT CONNECT TO UNIS")
            sys.exit(0)

        self._handle_mesh()
        return
Exemplo n.º 11
0
    def on_get(self, req, resp, fileid):
        e = Runtime(self._uri, proxy={
            "subscribe": False
        }).exnodes.first_where({"id": fileid})
        if not e: raise falcon.HTTPBadRequest(description="Unknown exnode id")

        resp.downloadable_as = e.name
        resp.content_length = e.size
        resp.content_type = mimetypes.guess_type(e.name)[0]

        with DLTFile(e, "r") as stream:
            resp.stream = stream
Exemplo n.º 12
0
 def _filelist(self):
     rt = Runtime(self._uri, proxy={"subscribe": False})
     files = []
     for ex in rt.exnodes:
         info = ExnodeInfo(ex, remote_validate=False)
         if info.is_complete():
             ts = ex.modified / 1000000
             files.append({
                 "id":
                 ex.id,
                 "name":
                 ex.name,
                 "size":
                 ex.size,
                 "date":
                 datetime.datetime.fromtimestamp(ts).strftime(
                     "%d-%b-%Y %H:%M")
             })
     return files
def example2():
    rt = Runtime('http://localhost:8888')  # Create runtime
    
    try:
        md = next(rt.metadata.where({'id': mid})) # Get the metadata object
    except StopIteration:
        print("No metadata by that ID")
        return

    md.data.attachFunction(MyFunction(), 'half_sum')  # Create a 'half_sum'
                                                      # property for the data

    # print each new value
    prev = md.data.half_sum
    while True:
        new = md.data.half_sum
        if prev != new:
            print(md.data.half_sum)
            prev = new
def example1():
    rt = Runtime('http://localhost:8888')  # Create runtime

    try:
        md = next(rt.metadata.where({'id': mid})) # Get the metadata object
    except StopIteration:
        print("No metadata by that ID")
        return

    md.data.attachFunction(Last())  # Create a 'last' property for the data
                                    # which prints the last measurement

    # print each new value
    prev = md.data.last
    while True:
        new = md.data.last
        if prev != new:
            print(md.data.last)
            prev = new
Exemplo n.º 15
0
        except Exception as e:
            print("IN EXCEPTION")
            print(e)
            logging.info("Could not find metadata for - %s", subject.selfRef)

            meta = self.rt.insert(Metadata({
                "eventType": event_type,
                "subject": subject,
                "parameters": {
                    "source": "",
                    "destination": "",
                    "archive": ""
                }
            }),
                                  commit=True)
            print(meta)
            logging.info("Creating metadata obj - %s ", meta.selfRef)

        meta.parameters.source = kwargs['src']
        meta.parameters.destination = kwargs['dst']
        meta.parameters.archive = kwargs['archive'][0]['url']
        self.rt.flush()
        print("Returning metadata")
        return meta.data


if __name__ == "__main__":
    util = UnisUtil(rt=Runtime("http://iu-ps01.osris.org:8888"))
    links = util.check_create_virtual_link("192.168.10.202", "192.168.10.204")
    print(util.check_create_metadata(links[0], event="throughput"))
Exemplo n.º 16
0
        ##
        #  Check service entries
        ##
        services = list(filter(lambda x: x['type'][0] == "service", data))
        for entry in services:

            # ensure service is registered to a known node in UNIS
            known_host = any(list(map(lambda s: entry['service-host'][0] == s['uri'], hosts)))
            
            # if a service is found that does not belong to a known host, add the host as a node into UNIS.
            if not known_host:
                host = self.get(self.default_base_url + '/' + entry['service-host'][0]).json()
                node = self.validate_node(node_name = host[0]['host-name'][1], node_addr = host[0]['host-name'][0])
        
            # handle service.
            self.validate_service(entry)
            

        return

'''
    Test case
'''
if __name__ == "__main__":
    sls = SLS_Manager(rt=Runtime(['http://um-ps01.osris.org:8888', 'http://iu-ps01.osris.org:8888']))
    res = sls.query('group-communities=OSIRIS')
    sls.integrate(res)
    for item in res:
        print(item['type'])
    sls.rt.shutdown()
Exemplo n.º 17
0
class SNMP_Manager():

    def __init__(self, host, community="aspiringvision", version=2, rt=None):
        self.host = host
        self.community = community
        self.version = version
        self.session = Session(hostname=self.host, community=self.community, version=self.version)
        self.neighbors = []
        
        self.osiris_service_manifest = [
                { 'name': 'snmpd',       'desc': 'SNMP daemon.',                       'unis_name': 'snmp',       'unis_service_type': 'host:snmp'},
                { 'name': 'ryu-manager', 'desc': 'RYU SDN Controller.',                'unis_name': 'ryu',        'unis_service_type': 'nmal:tools:ryu'},
                { 'name': 'lldpd',       'desc': 'LLDP daemon.',                       'unis_name': 'lldp',       'unis_service_type': 'host:lldp'},
                { 'name': 'periscoped',  'desc': 'UNIS network resource database.',    'unis_name': 'periscope',  'unis_service_type': 'ps:tools:periscope'},
                { 'name': 'node',        'desc': 'NodeJS web application.',            'unis_name': 'nodejs',     'unis_service_type': 'host:node'},
                { 'name': 'blippd',      'desc': 'BLIPP performance monitoring tool.', 'unis_name': 'blipp',      'unis_service_type': 'ps:tools:blipp'},
                { 'name': 'ntpd',        'desc': 'Network Time Protocol Daemon',       'unis_name': 'ntp',        'unis_service_type': 'host:ntp'},
                { 'name': 'schedular',   'desc': 'PSchedular Service',                 'unis_name': 'pschedular', 'unis_service_type': 'ps:tools:pschedular'},
                { 'name': 'archiver',    'desc': 'PerfSONAR Esmond Archive utility',   'unis_name': 'esmond',     'unis_service_type': 'ps:tools:esmond'},
                { 'name': 'owampd',      'desc': 'OWAMP web server',                   'unis_name': 'owamp',      'unis_service_type': 'host:owamp'}]


        # TODO: make runtime element from config, hardcode placeholder for now
        if rt is None:
            self.rt = Runtime('http://172.18.0.25:9000')
        else:
            self.rt = rt

    #
    #    SNMP Query Helpers
    #
    ################
    
    '''
        SNMP Query a Host for its IP Routing Table. This OID corresponds to link layer `arp -a` command.
    
        Returns a list of IP/Mac address values styled {'ip': <ip address value>, 'dict':<mac address value>}
    '''
    def get_ip_routes(self, host=None):

        if host is not None:
            self.session = Session(hostname=host, community=self.community, version=self.version)

        ret = self.session.walk(ip_table_oid)
        result = []

        for item in ret:
            mac = self.convert_mac_addr(item.value)
            ip  = self.parse_ip_addr(item.oid_index)
            ip_mac_dict = { 'ip': ip, 'mac': mac}
            result.append(ip_mac_dict)

            self.neighbors.append(ip_mac_dict)
        
        return result

    def get_services_list(self, host=None):

        session = Session(hostname=host, community=self.community, version=self.version)        
        
        try:
            query = session.walk(running_procs_oid)
        except Exception as e: 
            print(e)
            print('SNMP Service Query Failed')
            return

        result = []
        s_name_track = []

        for item in query:
            s = self.service_in_manifest(item.value) 
            if len(s) == 1:
                if s[0]['name'] not in s_name_track:
                    s_name_track.append(s[0]['name'])
                    result.append(s[0])

        return result

    #
    #    Use SNMP information to update resources.
    #
    ##############

    '''
        Takes a dict { ip: <val>, mac: <val>}.

        Generates a new node resource to be added to the topology. Handle link generation.
        Links are based off the mac address
    '''
    def add_discovered_node(self, ip_mac_dict):
        
        ip = ip_mac_dict['ip']
        mac = ip_mac_dict['ip']

        node = Node({
                'name': ip,
                'description': ('Discovered by ' + self.host + ' via SNMP'),
                'properties': {
                        'mgmtaddr': ip
                    }
            })
        
        port = Port({
                    'name': ip + ':' + mac,
                    'address' : {
                            'type':'mac',
                            'address': mac
                        },
                    'properties':{
                            'type':'virtual_link',
                            
                        }
                })

        try:
            node.ports.append(port) 
            node = self.rt.insert(node, commit=True)
            port = self.rt.insert(port, commit=True) 
            self.rt.domains[0].nodes.append(node)
            self.rt.domains[0].ports.append(port)
            self.rt.domains[0].commit()
            self.rt.flush()
        except:
            raise AttributeError("Could not commit Object to Domain")
        return node
    
    '''
        The SNMP query will give the local routing table for a given resource.

        If a node is discovered, ensure there is a valid link for it given the namescheme. 
        If there is no link describing this connection, make one.
    '''
    def test_link(self, test_node):
        
        host_node = self.check_node_exists(ip=self.host)
        
        print("Testing for links between ", host_node.name, " and ", test_node.name) 
       
            
        for host_port in host_node.ports:
            for test_port in test_node.ports:
                test_link_name = host_port.id + ':' + test_port.id
                test_link_name2 = test_port.id + ':' + host_port.id
                for link in self.rt.links:
                    if link.name == test_link_name or link.name == test_link_name2:
                        print("FOUND LINK connecting ", host_node.name, " and ", test_node.name)
                        return link

        print("Could not find link connecting ", host_node.name," and ", test_node.name, " - CREATING LINK.")

        # need to determine specific ports for link generation, TODO
        link = Link({
                'name': host_node.ports[0].id + ':' + test_node.ports[0].id,
                'endpoints': [test_node.ports[0], host_node.ports[0]],
                'directed': False,
                'properties': {
                        'type':'arp',
                    }
            })

        self.rt.insert(link, commit=True)
        self.rt.domains[0].links.append(link)
        self.rt.domains[0].commit()
        self.rt.flush()
        print("New link created.")

        return link

    '''
        Query the currently running services for a given host.

        Test to see if the service exists. If it does, poke the timestamp.
        If it does not, create a new service entry and push it to UNIS.

        If there is a service entry no longer running on the Host set the service to 
        not running.
    '''
    def update_services(self, ip):
        services_list = self.get_services_list(host=ip)
        print("Service List for ", ip, " - ", services_list)
        
        node = self.check_node_exists(ip=ip)
        unis_services = []
        
        if node is not None:
            services = self.rt.services.where({'runningOn':  node, 'status':'ON' })
            
            try:
                for s in services:
                    unis_services.append(s) 
            except:
                print('Could not find any existing UNIS entries for services at host ' + node.name)
 
            # check if service exists in UNIS, if not create one
            for item in services_list:
                 
                matches = list(filter(lambda s: s.name == item['unis_name'], unis_services))
                
                if len(matches) > 0: # if there are matches, touch
                    print("Found existing service for " + item['unis_name'] + " at host " + node.name + ". Updating timestamp.")
                    map(lambda s: s.touch(), matches)
                else:
                    # create new services
                    print('Creating new service for ' + item['unis_name'] + ' at host ' + node.name)
                    service = Service({'name':item['unis_name'], 'runningOn': {'href': node.selfRef, 'rel': 'full'}, 'status':'ON', 'serviceType': item['unis_service_type']})
                    self.rt.insert(service, commit=True)

            self.rt.flush()

        else:
            print('Node not found for ' + ip + ', continuing.')

        return

    '''
       
        apply_snmp_nodes will search through a list of dicts { ip: <val>, mac: <val>} to see if a corresponding node
        exists in UNIS. if the node does not exist it will register the node in UNIS.

        Once all dicts in the supplied list have been processed, query the SNMP query the ip and repeat the function
    
    '''
    def apply_snmp_nodes(self, ip_mac_list):
        
        for i in ip_mac_list:
             
            print('Checking - IP: ', i['ip'], " | Mac: ", i['mac'])
            n = self.check_node_exists(ip = i['ip'], mac = i['mac'])
            
            if n is None:
                print("Node with IP address ", i['ip'], " not found. CREATING NEW NODE resource.")
                n = self.add_discovered_node(i)
            else:
                print("FOUND NODE with IP address ", n.properties.mgmtaddr) 
            
            # see if there is a valid link in UNIS for this node.
            self.test_link(n)

        # find and update service entries in UNIS for this host.
        self.update_services(self.host) 
   
        return
    
    '''
        Main function for learning about the network.
    '''
    def discover(self):
        
        print("BEGIN discovery of base host ", self.host)
        snmp_ip_mac_list = self.get_ip_routes()
        self.apply_snmp_nodes(snmp_ip_mac_list)
    
    def discover_neighbors(self):
        for ip_mac_dict in self.neighbors:
            try:
                
                print("Trying to query ", ip_mac_dict['ip'])
                snmp_q = SNMP_Manager(host=ip_mac_dict['ip'], rt=self.rt)
                snmp_q.discover()

                print("Successful Query of ", ip_mac_dict['ip']) 
            except:
                print("Error querying SNMP for , ", ip_mac_dict["ip"], " - continuing.")
                continue
    #
    #   Helper Functions for processing SNMP Results
    #
    ##########

    def convert_mac_addr(self, mac_str):
        byte_from_string = mac_str.encode()
        return byte_from_string.hex()

    def parse_ip_addr(self, ip_oid):
        ip_addr = '.'.join(ip_oid.split('.')[-4:])
        print(ip_addr)
        return ip_addr

    def service_in_manifest(self, service_string):
        result = list(filter(lambda s: s['name'] == service_string, self.osiris_service_manifest))
        return result

    #
    #   UNIS Integration
    #
    #########

    def check_node_exists(self, ip = None, mac = None):
        if ip is None and mac is None:
            raise ValueError('Function check_node_exists must be given an ip=<ip address> or mac=<mac address> parameter.')
        
        for n in self.rt.nodes:
            if n.properties.mgmtaddr == ip:
                return n
        
        return None
Exemplo n.º 18
0
 def __init__(self, local_runtime, remote_runtime_url):
     self.local_rt = local_runtime
     self.remote_rt = Runtime(remote_runtime_url, name="Remote")
Exemplo n.º 19
0
def main():
    rt = Runtime(conf['uri'])
    app = falcon.App()
    app.add_route("/web/", ListFiles(rt, **conf))
    app.add_route("/web/{fileid}", GetFile(rt))
    return app
Exemplo n.º 20
0
class TestingDaemon:
    def __init__(self, conf, log_file="logs/esmond_uploader.log"):
        self.conf = conf
        self.archive_url = conf['archive_url']
        self.log_file = conf['log_file']
        self.unis = conf['unis']
        self.mesh_config = conf['mesh_config']
        self.jobs = []
        self.threads = []
        logging.basicConfig(filename=self.log_file, level=logging.INFO)
        logging.info('Log Initialized.')

        return

    def begin(self):
        logger = logging.getLogger()
        fh = logging.FileHandler(self.log_file)
        logger.addHandler(fh)

        self._setup()

        #with daemon.DaemonContext(files_preserve = [fh.stream]):
        logging.info("********** Esmond Uploader Utility **********")

        logging.info(
            "MAIN THREAD \nConfig - \n\
				Archive Host:%s\n\
				Unis: %s\n\
				Mesh: %s", self.archive_url, self.unis, self.mesh_config)
        logging.info("Starting jobs")

        for job in self.jobs:

            self._log("Init thread for " + job['description'])

            if len(job['members']['members']) > 2:
                members = job['members']['members']
                pairs = [(member1, member2) for member1 in members
                         for member2 in members]
                [print(p) for p in pairs]

                for p in pairs:
                    test_thread = Thread(target=self._init_test_thread,
                                         args=(
                                             job,
                                             p[0],
                                             p[1],
                                             self.conf,
                                         )).start()
                    time.sleep(2)
                    if test_thread is not None:
                        self.threads.append(test_thread)
                    else:
                        print("Thread for " + p[0] + "-" + p[1] +
                              " none type thread")

        return

    def _setup(self):
        '''
			Setup the main service. 
			- read and apply config in Meshconfig document.
			- connect to Runtime
			Exit if configuration fails.
        '''

        try:
            self.rt = Runtime(self.unis)
            self.rt.addService("unis.services.data.DataService")
        except Exception as e:
            print(e)
            logging.info("COULD NOT CONNECT TO UNIS")
            raise AttributeError("COULD NOT CONNECT TO UNIS")
            sys.exit(0)

        self._handle_mesh()
        return

    def _handle_mesh(self):

        try:
            mesh = requests.get(self.mesh_config).json()
        except:
            print("could not get mesh config. ensure url is correct.")

        self.mesh = mesh
        for test in mesh['tests']:
            self.jobs.append(test)

        return

    def _log(self, msg):
        now = strftime("%Y-%m-%d %H:%M:%S", gmtime())
        return logging.info(msg + " | " + now)

    def _init_test_thread(self, job, member1, member2, conf):
        source = member1
        destination = member2
        test_type = job['description']
        interval = job['parameters']['interval'] if 'interval' in job[
            'parameters'] else 120

        logging.info("Trying test for %s - %s", source, destination)

        try:
            if test_type not in TESTS.keys():
                return

            run = TESTS[test_type](self.archive_url,
                                   source=source,
                                   destination=destination,
                                   runtime=self.rt)
            self._log("THREAD OK")
        except Exception as e:
            self._log("Test not defined for " + test_type + "| " + source +
                      " - " + destination + ". Could not start thread")
            return

        logging.info(
            "LOG: %s test thread - updating every %s seconds.\n Src: %s, Dst: %s",
            test_type, interval, source, destination)
        while True:
            print("Attempting to fetch " + test_type + " from " + source +
                  " -> " + destination)
            data = run.fetch(time_range=3600, upload=True)
            if data is None:
                return print("Bad Thread")
            print("Fetch routine done, waiting for next interval")
            time.sleep(interval)
Exemplo n.º 21
0
class SDN_Handler(object):
    
    def __init__(self, runtime_url=None, domain_name=None):
        
        # Connect to runtime
        try:
            if runtime_url is not None:
                self.rt = Runtime(runtime_url, name="zof")
            else:
                print("Connecting to localhost...")
                self.rt = Runtime("http://localhost:8888")
        except Exception as e:
            print(e)
            raise Exception("Could not connect to runtime.")
        
        self.switches = []
        self.util         = UnisUtil(self.rt)
        self.link_handler = LinkHandler(self.rt) 

    def handle_switch_enter(self, event):
        try:
            dpid   = event['datapath'].id
            switch = self.util.check_switch_exists(dpid)
        except:
            switch = None
            dpid   = event['datapath_id']

        if switch is None:
            print("Could not find Unis resource for , creating new resource")
            switch = self.util.create_new_switch(event) 
        else: 
            print("Found Unis resource for Datapath ID %s." % (switch.datapathid))
        
        print("Checking ports")
        self.util.check_switch_ports(switch, event) 
        self.util.check_node_in_domain(switch, self.local_domain)

        self.rt.flush()

        return
    
    def handle_lldp(self, event):
        
        in_port = event['msg']['in_port']

        # checks to see if a node exists, and the corresponding port discovered via lldp
        node = self.util.check_lldp_msg(event['msg'], event['datapath_id'])
        port_name = node.name + ":" + event['msg']['pkt']['x_lldp_port_descr']
        node_port = self.util.check_update_node(node, event['msg'])
       
        #node_port.touch()
        node.touch() 
        self.util.check_node_in_domain(node, self.local_domain)
       
        print("DATAPATH ID: ", event['datapath_id'])
        switch_node = self.rt.nodes.first_where({"name": "switch:" + str(event['datapath'].id)})
        switch_port = self.util.find_port_in_node_by_port_num(switch_node, in_port)

        if switch_port is None:
            print("Could not find port in Switch. Continuing.")
            return
        if node_port is None:
            print("Could not find port in Node. Creating..")
            node_port = Port({"name":port_name, "properties":{"type":"virtual"}})
            self.rt.insert(node_port, commit=True)
            node.ports.append(node_port)
            self.domain.ports.append(node_port)
            self.rt.flush()
            return

        # checks to see if a link between the src/dst ports via lldp exist.
        link = self.link_handler.check_link_connecting_ports(switch_port, node_port)

        if link is None:
            link = self.link_handler.create_new_link(switch_port, node_port) 
            self.rt.insert(link, commit=True)
            
            print("New link created between %s and %s" % (switch_port.name, node_port.name))
        
        self.rt.flush() 
        link.touch()  
        self.util.check_link_in_domain(link, self.local_domain)
        
        
        print("Finished LLDP Update.")

        return
Exemplo n.º 22
0
class RegistrationHandler(object):
    def __init__(self, local_runtime, remote_runtime_url):
        self.local_rt = local_runtime
        self.remote_rt = Runtime(remote_runtime_url, name="Remote")

    def check_local_topology(self, topology_name):

        local_topology = self.local_rt.topologies.first_where(
            {"name": topology_name})

        if local_topology is not None:
            print("Found Local Topology", topology_name)
        else:
            print("Local Topology not found. Creating new entry in local UNIS")

            local_topology = Topology({"name": topology_name})

            self.local_rt.insert(local_topology, commit=True)
            self.local_rt.flush()

        return local_topology

    def check_local_domain(self, domain_name, local_topology):

        local_domain = self.local_rt.domains.first_where({"name": domain_name})
        if local_domain is not None:
            print("Found Local Domain - ", domain_name)
        else:
            print("Local Domain - ", domain_name,
                  ", not found. Creating new entry in local UNIS")

            local_domain = Domain({"name": domain_name})

            self.local_rt.insert(local_domain, commit=True)
            self.local_rt.flush()

        for domain in local_topology.domains:
            if domain.id == local_domain.id:
                return local_domain

        print("Domain not in local topology, adding..")
        local_topology.domains.append(local_domain)
        self.local_rt.flush()

        return local_domain

    '''
        Upload local topology domain to remote UNIS instance.
        If no remote UNIS exists create the remote topology instance.
    '''

    def register_remote(self, topology_name, domain):

        remote_topology = self.remote_rt.topologies.first_where(
            {"name": topology_name})

        if remote_topology is None:
            remote_topology = self.add_remote_topology(topology_name)

        for d in remote_topology.domains:
            if d.id == domain.id:
                print("Found domain " + domain.name + " in remote topology " +
                      remote_topology.name + ".")
                return remote_topology

        print("Domain " + domain.name + " not found in remote topology " +
              remote_topology.name + ", adding it to remote topology.")
        remote_topology.domains.append(domain)
        self.remote_rt.flush()

        return remote_topology

    def add_remote_topology(self, topology_name):

        remote_topology = Topology({"name": topology_name})
        self.remote_rt.insert(remote_topology, commit=True)
        self.remote_rt.flush()

        return remote_topology

    def clean_up(self):
        self.local_rt.flush()
        self.remote_rt.flush()
Exemplo n.º 23
0
            temp_total = temp_total + (float(k) * v)
            packet_total = packet_total + int(v)

        avg = temp_total / packet_total

        res = {"val": avg, "ts": data["ts"]}
        if self.upload:
            try:
                self.upload_data(res,
                                 self.src,
                                 self.dst,
                                 event_type="histogram-owdelay")
            except:
                logging.info(
                    "Could not upload data for histogram-owdelay | src: %s, dst: %s",
                    self.src, self.dst)
        return res


if __name__ == "__main__":
    rt = Runtime("http://iu-ps01.osris.org:8888")
    throughput = ThroughputTest("http://iu-ps01.osris.org",
                                source="192.168.10.202",
                                destination="192.168.10.204",
                                runtime=rt)
    data = throughput.fetch(time_range=3600, upload=True)

    #latency    = HistogramOWDelayTest("http://iu-ps01.osris.org", source="192.168.10.202", destination="192.168.10.204", runtime=rt)
    #data       = latency.fetch(time_range=300, upload=True)
    print(data)