Exemplo n.º 1
0
def query_metakey(service, src, dst):
    msg = """
<nmwg:message type="MetadataKeyRequest" id="metadataKeyRequest1"
              xmlns:iperf= "http://ggf.org/ns/nmwg/tools/iperf/2.0/"
              xmlns:nmwg="http://ggf.org/ns/nmwg/base/2.0/"
              xmlns:select="http://ggf.org/ns/nmwg/ops/select/2.0/"
              xmlns:nmwgt="http://ggf.org/ns/nmwg/topology/2.0/"
              xmlns:nmtm="http://ggf.org/ns/nmwg/time/2.0/"> 
  <nmwg:metadata id="meta1" xmlns:nmwg="http://ggf.org/ns/nmwg/base/2.0/"> 
    <iperf:subject xmlns:iperf= "http://ggf.org/ns/nmwg/tools/iperf/2.0/" id="s-in-iperf-1"> 
      <nmwgt:endPointPair xmlns:nmwgt="http://ggf.org/ns/nmwg/topology/2.0/"> 
        <nmwgt:src value="%s" /> 
        <nmwgt:dst value="%s" /> 
      </nmwgt:endPointPair> 
    </iperf:subject> 
    <nmwg:eventType>http://ggf.org/ns/nmwg/tools/iperf/2.0</nmwg:eventType> 
    <nmwg:parameters id="parameters-0">
        <nmwg:parameter name="protocol">TCP</nmwg:parameter>
    </nmwg:parameters>
  </nmwg:metadata> 
  <nmwg:data id="data1" metadataIdRef="meta1" xmlns:nmwg="http://ggf.org/ns/nmwg/base/2.0/"/> 
  </nmwg:message>
"""
    
    result = query_psservice(service, msg % (src, dst))
    root = etree.fromstring(result)
    meta = root.find(".//{%s}parameter[@name=\"maKey\"]" % NMWG)
    if meta == None:
        return None
    else:
        return meta.text
Exemplo n.º 2
0
def query_metakey(service, src, dst):
    msg = """
<nmwg:message type="MetadataKeyRequest" id="metadataKeyRequest1"
              xmlns:iperf= "http://ggf.org/ns/nmwg/tools/iperf/2.0/"
              xmlns:nmwg="http://ggf.org/ns/nmwg/base/2.0/"
              xmlns:select="http://ggf.org/ns/nmwg/ops/select/2.0/"
              xmlns:nmwgt="http://ggf.org/ns/nmwg/topology/2.0/"
              xmlns:nmtm="http://ggf.org/ns/nmwg/time/2.0/"> 
  <nmwg:metadata id="meta1" xmlns:nmwg="http://ggf.org/ns/nmwg/base/2.0/"> 
    <iperf:subject xmlns:iperf= "http://ggf.org/ns/nmwg/tools/iperf/2.0/" id="s-in-iperf-1"> 
      <nmwgt:endPointPair xmlns:nmwgt="http://ggf.org/ns/nmwg/topology/2.0/"> 
        <nmwgt:src value="%s" /> 
        <nmwgt:dst value="%s" /> 
      </nmwgt:endPointPair> 
    </iperf:subject> 
    <nmwg:eventType>http://ggf.org/ns/nmwg/tools/iperf/2.0</nmwg:eventType> 
    <nmwg:parameters id="parameters-0">
        <nmwg:parameter name="protocol">TCP</nmwg:parameter>
    </nmwg:parameters>
  </nmwg:metadata> 
  <nmwg:data id="data1" metadataIdRef="meta1" xmlns:nmwg="http://ggf.org/ns/nmwg/base/2.0/"/> 
  </nmwg:message>
"""

    result = query_psservice(service, msg % (src, dst))
    root = etree.fromstring(result)
    meta = root.find(".//{%s}parameter[@name=\"maKey\"]" % NMWG)
    if meta == None:
        return None
    else:
        return meta.text
Exemplo n.º 3
0
def poll_snmp_data(start_time, end_time):
    sent = EventType.objects.get(value='http://ggf.org/ns/nmwg/characteristic/network/utilization/bytes/sent/2.0')
    recv = EventType.objects.get(value='http://ggf.org/ns/nmwg/characteristic/network/utilization/bytes/received/2.0')
            
    metadata = Metadata.objects.filter(poll=True, event_type=sent)
    metadata_recv = Metadata.objects.filter(poll=True, event_type=recv)
    services = {}
    for m in metadata:
        if m.service not in services:
            services[m.service] = {'meta': {}}
        services[m.service]['meta'][m] = None
        
    for service in services:
        services[service]['request'] = ''
        for m in services[service]['meta']:
            result = make_snmp_request(m.subject, start_time, end_time)
            services[service]['meta'][m] = result['metaid']
            services[service]['request'] += result['xml']
            
        services[service]['request'] = """
<nmwg:message xmlns:netutil="http://ggf.org/ns/nmwg/characteristic/utilization/2.0/"
              xmlns:nmwg="http://ggf.org/ns/nmwg/base/2.0/"
              xmlns:nmwgt="http://ggf.org/ns/nmwg/topology/2.0/"
              xmlns:select="http://ggf.org/ns/nmwg/ops/select/2.0/"
              type="SetupDataRequest" id="SetupDataRequest1">
              """ + services[service]['request'] + "\n</nmwg:message>"
        
    for service in services:
        sss = time.time()
        response = query_psservice(service, services[service]['request'])
        eee = time.time()
        print "query time: %f" % (eee - sss)
        root = etree.fromstring(response)
        for m in services[service]['meta']:
            metas = root.findall(".//{%s}metadata[@metadataIdRef=\"%s\"]" % (NMWG, services[service]['meta'][m]))
            if metas == None:
                continue
            direction = metas[0].find(".//{%s}direction" % (NMWGT))
            
            if direction.text == 'out':
                meta_out = metas[0]
                meta_in = metas[1]
            else:
                meta_out = metas[1]
                meta_in = metas[0]
            
            meta_in_id = meta_in.attrib['id']
            meta_out_id = meta_out.attrib['id']
            
            data_in = root.find(".//{%s}data[@metadataIdRef=\"%s\"]" % (NMWG, meta_in_id))
            data_out = root.find(".//{%s}data[@metadataIdRef=\"%s\"]" % (NMWG, meta_out_id))
            
            parsed_in = parse_snmp_response_data(data_in)
            parsed_out = parse_snmp_response_data(data_out)
            save_data(m, parsed_out)
            recv_meta = metadata_recv.get(objectID=m.subject.id)
            save_data(recv_meta, parsed_in)
Exemplo n.º 4
0
def poll_snmp_data(start_time, end_time):
    sent = EventType.objects.get(
        value=
        'http://ggf.org/ns/nmwg/characteristic/network/utilization/bytes/sent/2.0'
    )
    recv = EventType.objects.get(
        value=
        'http://ggf.org/ns/nmwg/characteristic/network/utilization/bytes/received/2.0'
    )

    metadata = Metadata.objects.filter(poll=True, event_type=sent)
    metadata_recv = Metadata.objects.filter(poll=True, event_type=recv)
    services = {}
    for m in metadata:
        if m.service not in services:
            services[m.service] = {'meta': {}}
        services[m.service]['meta'][m] = None

    for service in services:
        services[service]['request'] = ''
        for m in services[service]['meta']:
            result = make_snmp_request(m.subject, start_time, end_time)
            services[service]['meta'][m] = result['metaid']
            services[service]['request'] += result['xml']

        services[service]['request'] = """
<nmwg:message xmlns:netutil="http://ggf.org/ns/nmwg/characteristic/utilization/2.0/"
              xmlns:nmwg="http://ggf.org/ns/nmwg/base/2.0/"
              xmlns:nmwgt="http://ggf.org/ns/nmwg/topology/2.0/"
              xmlns:select="http://ggf.org/ns/nmwg/ops/select/2.0/"
              type="SetupDataRequest" id="SetupDataRequest1">
              """ + services[service]['request'] + "\n</nmwg:message>"

    for service in services:
        sss = time.time()
        response = query_psservice(service, services[service]['request'])
        eee = time.time()
        print "query time: %f" % (eee - sss)
        root = etree.fromstring(response)
        for m in services[service]['meta']:
            metas = root.findall(".//{%s}metadata[@metadataIdRef=\"%s\"]" %
                                 (NMWG, services[service]['meta'][m]))
            if metas == None:
                continue
            direction = metas[0].find(".//{%s}direction" % (NMWGT))

            if direction.text == 'out':
                meta_out = metas[0]
                meta_in = metas[1]
            else:
                meta_out = metas[1]
                meta_in = metas[0]

            meta_in_id = meta_in.attrib['id']
            meta_out_id = meta_out.attrib['id']

            data_in = root.find(".//{%s}data[@metadataIdRef=\"%s\"]" %
                                (NMWG, meta_in_id))
            data_out = root.find(".//{%s}data[@metadataIdRef=\"%s\"]" %
                                 (NMWG, meta_out_id))

            parsed_in = parse_snmp_response_data(data_in)
            parsed_out = parse_snmp_response_data(data_out)
            save_data(m, parsed_out)
            recv_meta = metadata_recv.get(objectID=m.subject.id)
            save_data(recv_meta, parsed_in)