def add_data(traffic_data):
  gpudb = GPUdb(encoding='BINARY',gpudb_ip='10.1.10.31',gpudb_port='9191')

  # Add more fileds as needed for the analysis  
  type_definition = """{
                         "type":"record",
                         "name":"gen_pt",
                         "fields":[
                             {"name":"x","type":"double"},
                             {"name":"y","type":"double"},
                             {"name":"src","type":"string"},
                             {"name":"dst","type":"string"},
                             {"name":"payload","type":"string"}
                          ]
                       }"""
  
  retobj = gpudb.do_register_type(type_definition,"","point-type","POINT")
  type_id = retobj['type_id']
  
  set_id = str(uuid.uuid1())
  retobj = gpudb.do_new_set(type_id,set_id)
 
  x = 1;y = 1 
  encoded_datums = []
  for e in traffic_data: 
    datum = ordereddict.OrderedDict([('x',x), ('y',y), ('src',e[0]),('dst',e[1]),('payload',e[2])])
    encoded_datum = gpudb.encode_datum(type_definition,datum)
    encoded_datums.append(encoded_datum)
    x+=1;y+=1
     
  gpudb.do_bulk_add(set_id, encoded_datums)

  return set_id,gpudb
示例#2
0
def add_data(traffic_data):
    gpudb = GPUdb(encoding='BINARY', gpudb_ip='10.1.10.31', gpudb_port='9191')

    # Add more fileds as needed for the analysis
    type_definition = """{
                         "type":"record",
                         "name":"gen_pt",
                         "fields":[
                             {"name":"x","type":"double"},
                             {"name":"y","type":"double"},
                             {"name":"src","type":"string"},
                             {"name":"dst","type":"string"},
                             {"name":"payload","type":"string"}
                          ]
                       }"""

    retobj = gpudb.do_register_type(type_definition, "", "point-type", "POINT")
    type_id = retobj['type_id']

    set_id = str(uuid.uuid1())
    retobj = gpudb.do_new_set(type_id, set_id)

    x = 1
    y = 1
    encoded_datums = []
    for e in traffic_data:
        datum = ordereddict.OrderedDict([('x', x), ('y', y), ('src', e[0]),
                                         ('dst', e[1]), ('payload', e[2])])
        encoded_datum = gpudb.encode_datum(type_definition, datum)
        encoded_datums.append(encoded_datum)
        x += 1
        y += 1

    gpudb.do_bulk_add(set_id, encoded_datums)

    return set_id, gpudb
  Transform pcap fields into json 
  objects and store it in GPUdb  
  '''
    capture_traffic_rt()
    print "Data stored at GPUdb"

    # Query GPUdb server
    #query(set_id, gpudb)

    retobj = gpudb.do_clear("")
    print "Cleared all the sets"


#TODO: make packet capture real time
# callback function - called for every packet
retobj = gpudb.do_register_type(type_definition, "", "point-type", "POINT")
type_id = retobj['type_id']

set_id = str(uuid.uuid1())
retobj = gpudb.do_new_set(type_id, set_id)
x = 1
y = 1


def traffic_monitor_callback(p):
    global x
    global y
    if IP in p:
        datum = ordereddict.OrderedDict([
            ('x', x), ('y', y), ('src', p[IP].src), ('dst', p[IP].dst),
            ('payload', (str(p[IP].payload)).encode('utf-8').strip())
  Transform pcap fields into json 
  objects and store it in GPUdb  
  '''
  capture_traffic_rt()
  print "Data stored at GPUdb"

  # Query GPUdb server
  #query(set_id, gpudb)
 
  retobj = gpudb.do_clear("")
  print "Cleared all the sets"


#TODO: make packet capture real time
# callback function - called for every packet
retobj = gpudb.do_register_type(type_definition,"","point-type","POINT")
type_id = retobj['type_id']

set_id = str(uuid.uuid1())
retobj = gpudb.do_new_set(type_id,set_id)
x = 1;y = 1 

def traffic_monitor_callback(p):
  global x; global y 
  if IP in p:
    datum = ordereddict.OrderedDict([('x',x), ('y',y), ('src',p[IP].src),('dst',p[IP].dst),('payload',(str(p[IP].payload)).encode('utf-8').strip())])
    encoded_datum = gpudb.encode_datum(type_definition,datum)
    gpudb.do_add(set_id, encoded_datum)
    x+=1;y+=1

# capture traffic for 10 seconds