Example #1
0
def query_traceroute(accessPoint, src, dst):
    url_parse = urlparse(accessPoint)
    client = SimpleClient(host=url_parse.hostname,
                          port=url_parse.port,
                          uri=url_parse.path)
    query = make_traceroute_msg(src, dst)
    response = client.send_request(query)
    return parse_traceroute_response(response)
Example #2
0
def get_lamp_topology():

    # GFR: When using the lamp@slice certificate
    #   there's no need for credential
    #
    #slice_cred = get_slice_cred(cred_file)
    #body = make_UNISQueryCred_message(slice_cred)

    # Note that UNIS will return only the slice view for the Query All
    body = make_UNISQueryAll_message()

    try:
        client = SimpleClient(host=host,
                              port=port,
                              uri=uri,
                              cert=cert_file,
                              key=key_file)
        response = client.send_request(body, useSSL=True)
    except:
        print "Error contacting UNIS"
        return

    print response

    #t = create_from_xml_file(tfile)
    t = create_from_xml_string(response)

    if not t:
        print "Could not parse any topologies"
        return

    save_parsed_elements(t[0])

    types = ['in', 'out', 'cpu', 'mem']
    slices = []
    for d in t[0].get_domains():
        id_fields = get_urn_value(d.unis_id, 'domain').split('+')
        if len(id_fields) == 3 and id_fields[1] == 'slice':
            slices.append(id_fields[2] + '@' + id_fields[0])

        for n in d.get_nodes():
            for p in n.get_ports():
                pa = PortAddresses.objects.filter(port__unis_id=p.unis_id,
                                                  address__type='ipv4')
                #pn = NetworkObjectNames.objects.filter(networkobject=p)

                for type in types:
                    urn = UrnStub(urn=pa[0].address.value + '-' + type,
                                  ifName=get_urn_value(p.unis_id, 'port'),
                                  ifHost=get_urn_value(n.unis_id, 'node'),
                                  ifAddress=pa[0].address.value,
                                  type=type,
                                  source='MA')
                    urn.save()

    t[0].unis_id = "Topology for slice " + slices[0]
    t[0].save()
Example #3
0
def get_all_ma(host, port, uri, period, window=None, type="default"):
    """
    Get all values measurements values from the measurement archive.
    """
    urns = UrnStub.objects.filter(source="MA")
    
    curr_time = int(time.time())

    if (window == None):
        start = curr_time - period
        drop_time = datetime.fromtimestamp(float(start))
    else:
        start = curr_time - window
        drop_time = datetime.fromtimestamp(float(curr_time - period))
    
    print "Getting new data for ma", datetime.fromtimestamp(float(start)), "to", datetime.fromtimestamp(float(curr_time)) 

    for u in urns:
        
        if (type == "lamp"):
            body = makeSNMPMA_lamp_message(ifAddress=u.ifAddress, type=u.type, startTime=start)
        else:
            body = makeSNMPMAmessage(ifAddress=u.ifAddress, ifIndex=u.ifIndex, ifName=u.ifName, startTime=start)    

        response=None

        try:
            client = SimpleClient(host=host, port=port, uri=uri)
            if type == "lamp":
                response = client.send_request(body)
            else:
                response = client.send_request(body.tostring())
        except:
            print "could not poll ma!"
            continue

        values = parse_snmp_response(response, type)
        
        event = EventTypes.objects.get(event_type='http://ggf.org/ns/nmwg/characteristic/utilization/2.0')
        
        unit= None
        if len(values) > 0:
            if type=="lamp":
                unit = Units.objects.get(unit="psed")
            else:
                unit = Units.objects.get(unit=values[0]['valueUnits'])
            
        for v in values:
            m = Data(urn=u.urn, event_type=event, time=v['timeValue'], value=v['value'], units=unit)
            m.save()

    measurement_data = Data.objects.filter(time__lt=drop_time)
    for data in measurement_data:
        data.delete()

    print "Dropped measurements older than", drop_time
Example #4
0
def get_lamp_topology():
    
    # GFR: When using the lamp@slice certificate 
    #   there's no need for credential
    #
    #slice_cred = get_slice_cred(cred_file)
    #body = make_UNISQueryCred_message(slice_cred)
    
    # Note that UNIS will return only the slice view for the Query All
    body = make_UNISQueryAll_message()

    try:
        client = SimpleClient(host=host, port=port, uri=uri, cert=cert_file, key=key_file)
        response = client.send_request(body, useSSL=True)
    except:
        print "Error contacting UNIS"
        return
    
    print response

    #t = create_from_xml_file(tfile)
    t = create_from_xml_string(response)
    
    if not t:
        print "Could not parse any topologies"
        return

    save_parsed_elements(t[0])

    types = ['in', 'out', 'cpu', 'mem']
    slices = []
    for d in t[0].get_domains():
        id_fields = get_urn_value(d.unis_id, 'domain').split('+')
        if len(id_fields) == 3 and id_fields[1] == 'slice':
            slices.append(id_fields[2] + '@' + id_fields[0])

        for n in d.get_nodes():
            for p in n.get_ports():
                pa = PortAddresses.objects.filter(port__unis_id=p.unis_id, address__type='ipv4')
                #pn = NetworkObjectNames.objects.filter(networkobject=p)
                
                for type in types:
                    urn = UrnStub(urn=pa[0].address.value + '-' + type,
                                  ifName=get_urn_value(p.unis_id, 'port'),
                                  ifHost=get_urn_value(n.unis_id, 'node'),
                                  ifAddress=pa[0].address.value,
                                  type=type,
                                  source='MA')
                    urn.save()

    t[0].unis_id = "Topology for slice " + slices[0]
    t[0].save()
Example #5
0
def query_psservice(service, message, cert=None, key=None, useSSL=False):
    accessPoint = get_service_accesspoint(service)
    parse = urlparse(accessPoint)
    
    if cert is None and key is None:
        client = SimpleClient(host=parse.hostname, port=parse.port, uri=parse.path)
    else:
        client = SimpleClient(host=parse.hostname, port=parse.port, uri=parse.path,
                              cert=settings.SSL_CERT_FILE, key=settings.SSL_KEY_FILE)
        
    logger.info("Send query to: '%s'" % accessPoint) 
    response = client.send_request(message, useSSL=useSSL)
    logger.info("Received result from: '%s'" % accessPoint) 
    
    return response
Example #6
0
def query_psservice(service, message):
    try:
        psservice = psServiceProperties.objects.get(parent=service)
    except psServiceProperties.DoesNotExist:
        logger.error("No psServiceProperties for service (" + service.unis_id + ")")
        return None
    
    try:
        url = urlparse(psservice.accessPoint)
        
        client = SimpleClient(host=url.hostname, port=url.port, uri=url.path)
        response = client.send_request(message)
    except:
        logger.error("Error contacting service at " + psservice.accessPoint);
        return None
    
    return response
Example #7
0
def query_psservice(service, message):
    try:
        psservice = psServiceProperties.objects.get(parent=service)
    except psServiceProperties.DoesNotExist:
        logger.error("No psServiceProperties for service (" + service.unis_id +
                     ")")
        return None

    try:
        url = urlparse(psservice.accessPoint)

        client = SimpleClient(host=url.hostname, port=url.port, uri=url.path)
        response = client.send_request(message)
    except:
        logger.error("Error contacting service at " + psservice.accessPoint)
        return None

    return response
Example #8
0
def query_psservice(service, message, cert=None, key=None, useSSL=False):
    accessPoint = get_service_accesspoint(service)
    parse = urlparse(accessPoint)

    if cert is None and key is None:
        client = SimpleClient(host=parse.hostname,
                              port=parse.port,
                              uri=parse.path)
    else:
        client = SimpleClient(host=parse.hostname,
                              port=parse.port,
                              uri=parse.path,
                              cert=settings.SSL_CERT_FILE,
                              key=settings.SSL_KEY_FILE)

    logger.info("Send query to: '%s'" % accessPoint)
    response = client.send_request(message, useSSL=useSSL)
    logger.info("Received result from: '%s'" % accessPoint)

    return response
def query_traceroute(accessPoint, src, dst):
    url_parse = urlparse(accessPoint)
    client = SimpleClient(host=url_parse.hostname, port=url_parse.port, uri=url_parse.path)
    query = make_traceroute_msg(src, dst)
    response = client.send_request(query)
    return parse_traceroute_response(response)
Example #10
0
def get_all_mp(host, port, uri, period, window=None):
    """
    Get all values measurements values from the measurement point.
    """
    urns = UrnStub.objects.all()
    active_paths = PathDataModel.objects.filter(status="active")

    if (len(active_paths) < 1):
        return

    curr_time = int(time.time())

    if (window == None):
        start = curr_time - period
        drop_time = datetime.fromtimestamp(float(start))
    else:
        start = curr_time - window
        drop_time = datetime.fromtimestamp(float(curr_time - period))

    print "Getting new data for mp", datetime.fromtimestamp(
        float(start)), "to", datetime.fromtimestamp(float(curr_time))

    # this is horrible, but for now we assume the only interface we monitor is netqos02->qtr2 (GigabitEthernet9/23)
    # eventually we need a clean way to get the interface that the MP should query based on the path source
    for a in active_paths:
        ids = a.path_id
        ids += " GigabitEthernet9/23"

        #ids = ids[:-1]

        mp_query = msg_mp % ("198.124.220.3", "show terapaths", ids)

        try:
            client = SimpleClient(host=host, port=port, uri=uri)
            response = client.send_request(mp_query)
        except:
            print "could not poll mp!"
            return

        reader = psMessageReader(response)
        values = []
        for i in reader.getDataBlockIds():
            d = reader.getData(i)
            values = d.datumValues

            event = EventTypes.objects.get(
                event_type='http://ggf.org/ns/nmwg/tools/ciscossh/2.0/')

            unit = None
            if len(values) > 0:
                unit = Units.objects.get(id=0)

                # the MP is now returning packets that matched the policy-map on Qtr2
                # Qtr1 gives bytes in the reverse direction only...*sigh*
                # MTU is 1500, so we do some rough calculation to get bytes
                i = 0
                for v in values:
                    rate = None
                    prev = None

                    try:
                        prev = RawData.objects.filter(
                            urn=a.path_id).latest('time')
                    except (RawData.DoesNotExist):
                        print "no previous raw path measurement"

                    if ((not prev) or (v['value'] == 0)):
                        rate = 0
                    elif (v['value'] < prev.value):
                        rate = 0
                    else:
                        if ((float(curr_time) -
                             time.mktime(prev.time.timetuple())) < 30):
                            return
                        rate = ((float(v['value']) - float(prev.value)) *
                                1500) / (float(v['timeValue']) -
                                         time.mktime(prev.time.timetuple()))

                    m = Data(urn=a.path_id,
                             event_type=event,
                             time=datetime.fromtimestamp(float(
                                 v['timeValue'])),
                             value=rate,
                             units=unit)
                    m.save()

                    m = RawData(urn=a.path_id,
                                event_type=event,
                                time=datetime.fromtimestamp(
                                    float(v['timeValue'])),
                                value=v['value'],
                                units=unit)

                    m.save()
Example #11
0
def get_all_ma(host, port, uri, period, window=None, type="default"):
    """
    Get all values measurements values from the measurement archive.
    """
    urns = UrnStub.objects.filter(source="MA")

    curr_time = int(time.time())

    if (window == None):
        start = curr_time - period
        drop_time = datetime.fromtimestamp(float(start))
    else:
        start = curr_time - window
        drop_time = datetime.fromtimestamp(float(curr_time - period))

    print "Getting new data for ma", datetime.fromtimestamp(
        float(start)), "to", datetime.fromtimestamp(float(curr_time))

    for u in urns:

        if (type == "lamp"):
            body = makeSNMPMA_lamp_message(ifAddress=u.ifAddress,
                                           type=u.type,
                                           startTime=start)
        else:
            body = makeSNMPMAmessage(ifAddress=u.ifAddress,
                                     ifIndex=u.ifIndex,
                                     ifName=u.ifName,
                                     startTime=start)

        response = None

        try:
            client = SimpleClient(host=host, port=port, uri=uri)
            if type == "lamp":
                response = client.send_request(body)
            else:
                response = client.send_request(body.tostring())
        except:
            print "could not poll ma!"
            continue

        values = parse_snmp_response(response, type)

        event = EventTypes.objects.get(
            event_type='http://ggf.org/ns/nmwg/characteristic/utilization/2.0')

        unit = None
        if len(values) > 0:
            if type == "lamp":
                unit = Units.objects.get(unit="psed")
            else:
                unit = Units.objects.get(unit=values[0]['valueUnits'])

        for v in values:
            m = Data(urn=u.urn,
                     event_type=event,
                     time=v['timeValue'],
                     value=v['value'],
                     units=unit)
            m.save()

    measurement_data = Data.objects.filter(time__lt=drop_time)
    for data in measurement_data:
        data.delete()

    print "Dropped measurements older than", drop_time
Example #12
0
        for line in unis_dom.toprettyxml().split("\n"):
            if line.strip() != '' and not line.lstrip().startswith('<?xml '):
                unis_str += line + "\n"

        credential = None
        if credential_xml:
            credential = get_slice_cred(credential_xml)

        # Don't do the above on messages with credentials!
        message = make_UNISTSReplace_message(unis_str, credential)
        print message
        print "\n\n"
        try:
            client = SimpleClient(host=host,
                                  port=port,
                                  uri=uri,
                                  cert=cert_file,
                                  key=key_file)
            response = client.send_request(message, useSSL=True)
        except Exception, err:
            print "Error contacting UNIS: " + str(err)
            return

        print "Received:\n"
        print response

    except Usage, err:
        print >> sys.stderr, err.msg
        print >> sys.stderr, "Usage: <manifest> <slice> [credential]"
        return 2
Example #13
0
        # Clean spurious empty lines in message (toprettyxml() abuses them)
        unis_str = ""
        for line in unis_dom.toprettyxml().split("\n"):
            if line.strip() != '' and not line.lstrip().startswith('<?xml '):
                unis_str += line + "\n"
        
        credential = None
        if credential_xml:
            credential = get_slice_cred(credential_xml)
        
        # Don't do the above on messages with credentials!
        message = make_UNISTSReplace_message(unis_str, credential)
        print message
        print "\n\n"
        try:
            client = SimpleClient(host=host, port=port, uri=uri, cert=cert_file, key=key_file)
            response = client.send_request(message, useSSL=True)
        except Exception, err:
            print "Error contacting UNIS: " + str(err)
            return
        
        print "Received:\n"
        print response
        
    except Usage, err:
        print >>sys.stderr, err.msg
        print >>sys.stderr, "Usage: <manifest> <slice> [credential]"
        return 2
    
if __name__ == "__main__":
    sys.exit(main())
Example #14
0
def get_all_mp(host, port, uri,period, window=None):
    """
    Get all values measurements values from the measurement point.
    """
    urns = UrnStub.objects.all()
    active_paths = PathDataModel.objects.filter(status="active");

    if (len(active_paths) < 1):
        return

    curr_time = int(time.time())
    
    if (window == None):
        start = curr_time - period
        drop_time = datetime.fromtimestamp(float(start))
    else:
        start = curr_time - window
        drop_time = datetime.fromtimestamp(float(curr_time - period))

    print "Getting new data for mp", datetime.fromtimestamp(float(start)), "to", datetime.fromtimestamp(float(curr_time)) 

    # this is horrible, but for now we assume the only interface we monitor is netqos02->qtr2 (GigabitEthernet9/23)
    # eventually we need a clean way to get the interface that the MP should query based on the path source
    for a in active_paths:
        ids = a.path_id
        ids += " GigabitEthernet9/23"

        #ids = ids[:-1]

        mp_query = msg_mp % ("198.124.220.3", "show terapaths", ids)

        try:
            client = SimpleClient(host=host, port=port, uri=uri)
            response = client.send_request(mp_query)
        except: 
            print "could not poll mp!"
            return

        reader= psMessageReader(response)
        values = []
        for i in reader.getDataBlockIds():
            d = reader.getData(i)
            values = d.datumValues
                
            event = EventTypes.objects.get(event_type='http://ggf.org/ns/nmwg/tools/ciscossh/2.0/')
            
            unit = None
            if len(values) > 0:
                unit = Units.objects.get(id=0)
                
                # the MP is now returning packets that matched the policy-map on Qtr2
                # Qtr1 gives bytes in the reverse direction only...*sigh*
                # MTU is 1500, so we do some rough calculation to get bytes
                i = 0              
                for v in values:
                    rate=None
                    prev=None

                    try:
                        prev = RawData.objects.filter(urn=a.path_id).latest('time')
                    except (RawData.DoesNotExist):
                        print "no previous raw path measurement"

                    if ((not prev) or (v['value'] == 0)):
                        rate = 0
                    elif (v['value'] < prev.value):
                        rate = 0
                    else:
                        if ((float(curr_time) - time.mktime(prev.time.timetuple())) < 30):
                            return
                        rate = ((float(v['value'])-float(prev.value))*1500)/(float(v['timeValue'])-time.mktime(prev.time.timetuple()))
                        
                    m = Data(urn=a.path_id, 
                             event_type=event, 
                             time=datetime.fromtimestamp(float(v['timeValue'])),
                             value=rate,
                             units=unit)
                    m.save()

                    m = RawData(urn=a.path_id,
                                event_type=event,
                                time=datetime.fromtimestamp(float(v['timeValue'])),
                                value=v['value'],
                                units=unit)

                    m.save()