예제 #1
0
  def test_summaries(self):
    print("--test_summaries--")
    os.chdir(os.path.dirname(os.path.realpath(__file__)))
    summaries_file = "test_summaries_file.txt"
    measurement = Measurement(1001, summaries_file)
    summary, local_hit = measurement._get_summary(summaries_file)

    self.assertEqual(summary, measurement.summary)
    self.assertTrue(local_hit)

    local_dict = measurement._get_dict_from_nonempty_file(summaries_file)
    local_summary = local_dict["1001"]

    self.assertEqual(local_summary, measurement.summary)
예제 #2
0
  def test0(self):
    '''
    start with empty summaries_file, instantiate a measurement, check that summary got added to file
    '''
    print("--test0--")
    i = 0
    summaries_dict = self.measurements[i]._get_dict_from_nonempty_file(self.fname)
    
    self.assertEqual(summaries_dict[str(self.measurement_ids[i])]["msm_id"], self.measurement_ids[i])
    self.assertEqual(self.measurements[i].local_hit, self.USE_LOCAL_SUMMARIES)
    self.assertEqual(self.measurements[i].type, "ping")

    measurement2 = Measurement(self.measurement_ids[i], self.fname)
    self.assertTrue(measurement2.local_hit)

    self._make_dir_if_nonexists("data")
    curr_path = os.path.dirname(os.path.realpath(__file__))
    data_path = os.path.join(curr_path, "data")
    os.chdir(data_path)
    file1 = measurement2._fetch_to_local(1446336000, 1446336100)
    file2 = measurement2._fetch_to_local(1446422400, 1446422500)
    list_of_entries = os.listdir(data_path)
    list_of_files = [f for f in list_of_entries if os.path.isfile(os.path.join(data_path, f))]
    self.assertEqual(len(list_of_files), 2)

    os.chdir(curr_path)
    ping_data = Ping_Data(measurement2.measurement_id, file1, self.fname)
    self.assertTrue(ping_data.local_hit)

    list_of_headings = Ping_Data.get_ping_headings()
    csv_file = "test.csv"
    gold_file = "gold.csv"
    ping_data.prep_csv_file(csv_file, list_of_headings)
    ping_data.write_data_to_csv(csv_file, probe_id = 10008)

    with open(csv_file) as csv_file_obj:
      with open(gold_file) as gold_file_obj:
        self.assertMultiLineEqual(csv_file_obj.read(), gold_file_obj.read())

    i = 1
    summaries_dict = self.measurements[i]._get_dict_from_nonempty_file(self.fname)
    
    self.assertEqual(summaries_dict[str(self.measurement_ids[i])]["msm_id"], self.measurement_ids[i])
    self.assertEqual(self.measurements[i].local_hit, self.USE_LOCAL_SUMMARIES)
    self.assertEqual(self.measurements[i].type, "dns")

    measurement2 = Measurement(self.measurement_ids[i], self.fname)
    self.assertTrue(measurement2.local_hit)

    i = 2
    summaries_dict = self.measurements[i]._get_dict_from_nonempty_file(self.fname)
    
    self.assertEqual(summaries_dict[str(self.measurement_ids[i])]["msm_id"], self.measurement_ids[i])
    self.assertEqual(self.measurements[i].local_hit, self.USE_LOCAL_SUMMARIES)
    self.assertEqual(self.measurements[i].type, "traceroute")

    measurement2 = Measurement(self.measurement_ids[i], self.fname)
    self.assertTrue(measurement2.local_hit)
예제 #3
0
import My_RIPE
from My_RIPE import Measurement, Measurement_Data


d = Measurement._get_dict_from_nonempty_file('test_dict_all.out')

total_shorter = 0
total_longer = 0
ipv4_only = 0
ipv6_only = 0
both = 0
neither = 0

# loop through probes
for probe in d:
	ipv4 = 0
	ipv6 = 0
	shorter = 0
	longer = 0

	# loop through origins
	for origin in d[probe]['origins']:
		length = len(origin)
		if length < 4+3 and origin != "":
			shorter += 1
			print(origin)
		elif length >= 4+3 and length <= 3*4+3:
			ipv4 +=1
		elif length > 3*4+3 and length <= 8*4+7:
			ipv6 +=1
		elif length > 8*4+7:
예제 #4
0
import My_RIPE
from My_RIPE import Measurement, Measurement_Data
import numpy as np
import matplotlib.mlab as mlab
import matplotlib.pyplot as plt
import json
from collections import Counter

d = Measurement._get_dict_from_nonempty_file('probe-target_dict_all.txt')

pings_1 = []
pings_2 = []
dns_1 = []
dns_2 = []
traceroutes_1 = []
traceroutes_2 = []

for k in d:
	if len(d[k]['origins']) == 1:
		pings_1.append(d[k]['ping'])
		dns_1.append(d[k]['dns'])
		traceroutes_1.append(d[k]['traceroute'])
	elif len(d[k]['origins']) == 2:
		pings_2.append(d[k]['ping'])
		dns_2.append(d[k]['dns'])
		traceroutes_2.append(d[k]['traceroute'])

out_dict = {}
out_dict['pings_1'] = pings_1
out_dict['pings_2'] = pings_2
out_dict['dns_1'] = dns_1
예제 #5
0
import My_RIPE
from My_RIPE import Measurement, Measurement_Data

d = Measurement._get_dict_from_nonempty_file('test_dict_all.out')

total_shorter = 0
total_longer = 0
ipv4_only = 0
ipv6_only = 0
both = 0
neither = 0

# loop through probes
for probe in d:
    ipv4 = 0
    ipv6 = 0
    shorter = 0
    longer = 0

    # loop through origins
    for origin in d[probe]['origins']:
        length = len(origin)
        if length < 4 + 3 and origin != "":
            shorter += 1
            print(origin)
        elif length >= 4 + 3 and length <= 3 * 4 + 3:
            ipv4 += 1
        elif length > 3 * 4 + 3 and length <= 8 * 4 + 7:
            ipv6 += 1
        elif length > 8 * 4 + 7:
            longer += 1
예제 #6
0
    parser.add_argument('--summaries', type=str,
                    help="A local file containing dictionary of measurment_id : measurement_summary.  Faster than requesting from web.  If omitted, summaries are obtained from web.")
    return parser.parse_args()


# Call the script by typing:
#	$ python download_time_window.py start_time end_time [measurement_id1, measurement_id2, ...]
# where arguments 2 and onward is a ripe atlas measurement id
if __name__ == "__main__":
    args = parse_args()
    # get time stamps
    start_time = args.start_time
    end_time = args.end_time
    summaries_file = args.summaries

    if (end_time - start_time) > 60*60*24:
        # if time window is longer than 1 day
        # for each day in the time window
        for t1,t2 in My_RIPE.days(start_time, end_time):
            # loop through measurement ids
            for measurement_id in args.measurement:
                measurement = Measurement(measurement_id, summaries_file)
                measurement._fetch_to_local(t1, t2)
    else:
        # if time windows is less than 1 day
        # loop through measurement ids
        for measurement_id in args.measurement:
            measurement = Measurement(measurement_id, summaries_file)
            measurement._fetch_to_local(start_time, end_time)

예제 #7
0
    return parser.parse_args()


# Call the script by typing:
#	$ python download_time_window.py start_time end_time [measurement_id1, measurement_id2, ...]
# where arguments 2 and onward is a ripe atlas measurement id
if __name__ == "__main__":
    # get args
    args = parse_args()
    start_time = int(args.start_time)
    end_time = int(args.end_time)
    measurements = args.measurements
    summaries_file = args.summaries

    measurement_id_list = map(int, open(measurements, 'r').read().splitlines())

    if (end_time - start_time) > 60 * 60 * 24:
        # if time window is longer than 1 day
        # for each day in the time window
        for t1, t2 in My_RIPE.days(start_time, end_time):
            # loop through measurement ids
            for measurement_id in measurement_id_list:
                measurement = Measurement(measurement_id, summaries_file)
                measurement.fetch_range_to_hdfs(t1, t2)
    else:
        # if time windows is less than 1 day
        # loop through measurement ids
        for measurement_id in measurement_id_list:
            measurement = Measurement(measurement_id, summaries_file)
            measurement.fetch_range_to_hdfs(start_time, end_time)
예제 #8
0
import My_RIPE
from My_RIPE import Measurement, Measurement_Data
import numpy as np
import matplotlib.mlab as mlab
import matplotlib.pyplot as plt
import json
from collections import Counter

d = Measurement._get_dict_from_nonempty_file('probe-target_dict_all.txt')

pings_1 = []
pings_2 = []
dns_1 = []
dns_2 = []
traceroutes_1 = []
traceroutes_2 = []

for k in d:
    if len(d[k]['origins']) == 1:
        pings_1.append(d[k]['ping'])
        dns_1.append(d[k]['dns'])
        traceroutes_1.append(d[k]['traceroute'])
    elif len(d[k]['origins']) == 2:
        pings_2.append(d[k]['ping'])
        dns_2.append(d[k]['dns'])
        traceroutes_2.append(d[k]['traceroute'])

out_dict = {}
out_dict['pings_1'] = pings_1
out_dict['pings_2'] = pings_2
out_dict['dns_1'] = dns_1
예제 #9
0
 def _add_measurements(self):
   for this_id in self.measurement_ids:
     self.measurements.append(Measurement(this_id, self.fname))
예제 #10
0

# Call the script by typing:
#	$ python download_time_window.py start_time end_time [measurement_id1, measurement_id2, ...]
# where arguments 2 and onward is a ripe atlas measurement id
if __name__ == "__main__":
    # get args
    args = parse_args()
    start_time = int(args.start_time)
    end_time = int(args.end_time)
    measurements = args.measurements
    summaries_file = args.summaries

    measurement_id_list = map(int, open(measurements, 'r').read().splitlines())

    if (end_time - start_time) > 60*60*24:
        # if time window is longer than 1 day
        # for each day in the time window
        for t1,t2 in My_RIPE.days(start_time, end_time):
            # loop through measurement ids
            for measurement_id in measurement_id_list:
                measurement = Measurement(measurement_id, summaries_file)
                measurement.fetch_range_to_hdfs(t1, t2)
    else:
        # if time windows is less than 1 day
        # loop through measurement ids
        for measurement_id in measurement_id_list:
            measurement = Measurement(measurement_id, summaries_file)
            measurement.fetch_range_to_hdfs(start_time, end_time)