#!/usr/bin/env python
from collections import defaultdict
import datetime, glob
from matplotlib import pyplot as plt
from ical_distribution import ECDF
import pybgpstream
"""Code file for CS 6250 BGPM Project
Edit this file according to docstrings.
Do not change the existing function name o...
usrbinenv python from collections import defaultdict import datetime
glob from matplotlib import pyplot as plt from statsmodelsdistributio
Escuela, estudio y materia
CS 6250
Todos documentos para esta materia (37)
Vendedor
Seguir
ExamsConnoisseur
Comentarios recibidos
Vista previa del contenido
#!/usr/bin/env python
from collections import defaultdict
import datetime, glob
from matplotlib import pyplot as plt
from statsmodels.distributions.empirical_distribution import ECDF
import pybgpstream
"""Code file for CS 6250 BGPM Project
Edit this file according to docstrings.
Do not change the existing function name or arguments in any way.
"""
# Task 1 Part A.
def calculateUniqueIPAddresses(cache_files):
"""Retrieve the number of unique IP prefixes from input BGP data.
Args:
cache_files: A list of absolute file paths.
File paths may not be in order but will end with a timestamp that can be
used for sorting.
For example: ["/rib_files_final/1357027200.120.cache",
"/rib_files_final/1483257600.120.cache"]
Returns:
A list containing the number of unique IP prefixes for each input cache
file.
For example: [2, 5]
"""
files = sorted(cache_files)
unique_prefixes = []
for file in files:
stream = pybgpstream.BGPStream(data_interface="singlefile")
stream.set_data_interface_option("singlefile","rib-file",file)
prefixes = []
for elem in stream:
prefixes.append(elem.fields['prefix'])
prefixes = list(set(prefixes))
unique_prefixes.append(len(prefixes))
return unique_prefixes
# Task 1 Part B.
def calculateUniqueAses(cache_files):
"""Retrieve the number of unique ASes from input BGP data.
Args:
cache_files: A list of absolute file paths.
File paths may not be in order but will end with a timestamp that can be
used for sorting.
For example: ["/rib_files_final/1357027200.120.cache",
"/rib_files_final/1483257600.120.cache"]
Returns:
A list containing the number of the number of unique AS for each input
file.
This study source was downloaded by 100000850872992 from CourseHero.com on 03-29-2023 08:29:41 GMT -05:00
https://www.coursehero.com/file/142684040/bgpmpy/
, For example: [2, 5]
"""
files = sorted(cache_files)
unique_ases = []
for file in files:
stream = pybgpstream.BGPStream(data_interface="singlefile")
stream.set_data_interface_option("singlefile","rib-file",file)
ases = []
for elem in stream:
for _as in elem.fields['as-path'].split(' '):
ases.append(_as)
ases = list(set(ases))
unique_ases.append(len(ases))
return unique_ases
# Task 1 Part C.
def examinePrefixes(cache_files):
"""
Args:
cache_files: A list of absolute file paths.
File paths may not be in order but will end with a timestamp that can be
used for sorting.
For example: ["/rib_files_final/1357027200.120.cache",
"/rib_files_final/1483257600.120.cache"]
Returns:
A list of the top 10 origin ASes according to percentage increase of the
advertised prefixes.
See assignment description for details.
"""
files = sorted(cache_files)
ds = {}
final_list = []
ases = []
for file in files:
stream = pybgpstream.BGPStream(data_interface="singlefile")
stream.set_data_interface_option("singlefile","rib-file",file)
time = datetime.datetime.fromtimestamp(int(file.split('.')[-3]))
for elem in stream:
origin = elem.fields['as-path'].split(' ')[-1]
if origin in ds.keys():
if time in ds[origin].keys():
ds[origin][time].append(elem.fields['prefix'])
else:
ds[origin][time] = [elem.fields['prefix']]
else:
ds[origin] = {}
ds[origin][time] = [elem.fields['prefix']]
for _as in ds.keys():
dates = sorted(list(ds[_as].keys()))
if len(dates) < 2:
final_list.append((_as,0.0))
continue
else:
unique_prefixes_start = list(set(ds[_as][dates[0]]))
unique_prefixes_end = list(set(ds[_as][dates[-1]]))
calc = ((len(unique_prefixes_end) -
len(unique_prefixes_start))/len(unique_prefixes_start)) * 100
This study source was downloaded by 100000850872992 from CourseHero.com on 03-29-2023 08:29:41 GMT -05:00
https://www.coursehero.com/file/142684040/bgpmpy/
Los beneficios de comprar resúmenes en Stuvia estan en línea:
Garantiza la calidad de los comentarios
Compradores de Stuvia evaluaron más de 700.000 resúmenes. Así estas seguro que compras los mejores documentos!
Compra fácil y rápido
Puedes pagar rápidamente y en una vez con iDeal, tarjeta de crédito o con tu crédito de Stuvia. Sin tener que hacerte miembro.
Enfócate en lo más importante
Tus compañeros escriben los resúmenes. Por eso tienes la seguridad que tienes un resumen actual y confiable.
Así llegas a la conclusión rapidamente!
Preguntas frecuentes
What do I get when I buy this document?
You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.
100% de satisfacción garantizada: ¿Cómo funciona?
Nuestra garantía de satisfacción le asegura que siempre encontrará un documento de estudio a tu medida. Tu rellenas un formulario y nuestro equipo de atención al cliente se encarga del resto.
Who am I buying this summary from?
Stuvia is a marketplace, so you are not buying this document from us, but from seller ExamsConnoisseur. Stuvia facilitates payment to the seller.
Will I be stuck with a subscription?
No, you only buy this summary for 7,59 €. You're not tied to anything after your purchase.