#!/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
Written for
CS 6250
All documents for this subject (37)
Seller
Follow
ExamsConnoisseur
Reviews received
Content preview
#!/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/
The benefits of buying summaries with Stuvia:
Guaranteed quality through customer reviews
Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.
Quick and easy check-out
You can quickly pay through credit card or Stuvia-credit for the summaries. There is no membership needed.
Focus on what matters
Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!
Frequently asked questions
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.
Satisfaction guarantee: how does it work?
Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.
Who am I buying these notes 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 these notes for $7.99. You're not tied to anything after your purchase.