-
Notifications
You must be signed in to change notification settings - Fork 6
Change architecture to separate parser logic from server logic (untested) #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jacobdunefsky
wants to merge
12
commits into
main
Choose a base branch
from
task2-arch-fix-untested
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
f108381
Add support for task 2
emiapwil a31d5d3
Add support to return ECS for ipv4 addresses
emiapwil 477fc88
Use dataclasses_json for automatica serialization/deserialization
emiapwil ff332ab
Make the client print JSON
emiapwil 04a2a1f
Create G2Parser class (untested!)
jacobdunefsky 3fccd7e
Refactoring for network independence (untested!)
jacobdunefsky 116ae4a
Fixed indentation typo
jacobdunefsky 43010fe
addressed Jordi's review, refactored code into Jensen's solver file
jacobdunefsky 6c1b021
added docstrings
jacobdunefsky 0e7e712
Move do_request to get_throughput in client.py
jacobdunefsky 0c33b02
Move do_request in estimator.py to get_throughput
jacobdunefsky afb27ba
tabs to spaces
jacobdunefsky File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
""" | ||
alto-estimator.py | ||
|
||
Estimates the throughput of a number of different flows. | ||
|
||
Can be used as a standalone script. --alto-server gives the hostname | ||
of the ALTO server, and --flows gives a path to an input file. | ||
The flows file is of the form | ||
SRC1 -> DST1 DST2 DST3 ... | ||
SRC2 -> DST4 DST5 DST6 ... | ||
... | ||
""" | ||
|
||
import json | ||
import requests | ||
|
||
def input_to_json(input_str): | ||
"""Converts a string, representing a list of flows, | ||
into a dict that can be converted to JSON and sent to an ALTO server. | ||
|
||
Args: | ||
input_str (str): A string representing a list of flows. | ||
The list of flows should be of the form: | ||
SRC1 -> DST1 DST2 DST3 ... | ||
SRC2 -> DST4 DST5 DST6 ... | ||
... | ||
|
||
Returns: | ||
A list of flows. | ||
""" | ||
input_lines = input_str.splitlines() | ||
""" | ||
TODO: add compression. https://github.com/openalto/alto/issues/7 | ||
What does "compression" mean in this context? As was decided during a | ||
meeting before the hackathon (although I can't find the Google Doc | ||
in which this decision was made), the format of requests should | ||
allow flows to be specified by specifying a many-to-many relationship | ||
between sources and destinations. An example is as follows: | ||
|
||
{"srcs": ["src1", "src2", "src3"], "dsts": ["dst1", "dst2"]} | ||
|
||
The above dict defines six flows: one flow from each source to each | ||
destination. | ||
|
||
Now, this format was chosen to allow for the compression of requests. | ||
However, the input format groups flows by source. Thus, an input like | ||
|
||
SRC1 -> DST1 DST2 | ||
SRC2 -> DST1 DST2 | ||
SRC3 -> DST1 DST2 | ||
|
||
can be compressed to the dictionary given above. But this code doesn't | ||
currently do that. The problem of finding an optimal compression | ||
strikes me as NP-hard (although I haven't actually thought it through). | ||
Thus, the current code simply naively translates the input string into | ||
a dict. | ||
""" | ||
ef_arr = [] | ||
for line in input_lines: | ||
line_split = line.split("->") | ||
src = line_split[0].strip() | ||
dst_arr = line_split[1].strip().split(" ") | ||
dst_arr = list(filter(lambda a: a != 0, dst_arr)) | ||
|
||
ef_arr.append({"srcs": [src], "dsts": dst_arr}) | ||
return ef_arr | ||
|
||
from alto.client import Client | ||
|
||
def do_request_from_str(input_str, alto_server): | ||
"""Obtains ALTO throughput data for an input string representing flows | ||
of interest. | ||
|
||
Args: | ||
input_str (str): A string representing a list of flows. | ||
The list of flows should be of the form: | ||
SRC1 -> DST1 DST2 DST3 ... | ||
SRC2 -> DST4 DST5 DST6 ... | ||
... | ||
|
||
alto_server (str): The base URL for the ALTO server. This URL cannot | ||
end in a "/". | ||
|
||
Returns: | ||
A JSON string representing the throughput for each flow | ||
""" | ||
c = Client() | ||
return c.get_throughput(input_to_json(input_str), url=alto_server+"/endpoint/cost") | ||
|
||
if __name__ == "__main__": | ||
"""Obtains ALTO throughput data for an input file representing flows | ||
of interest. | ||
|
||
Args: | ||
--flows (str): A path to a list of flows. | ||
The list of flows should be of the form: | ||
SRC1 -> DST1 DST2 DST3 ... | ||
SRC2 -> DST4 DST5 DST6 ... | ||
... | ||
|
||
--alto-server (str): The base URL for the ALTO server. This URL cannot | ||
end in a "/". | ||
|
||
Returns: | ||
A JSON string representing the throughput for each flow | ||
""" | ||
import argparse | ||
import sys | ||
|
||
parser = argparse.ArgumentParser(description="Estimate throughput for flows") | ||
parser.add_argument('--alto-server', required=True) | ||
parser.add_argument('--flows', required=True) | ||
args = parser.parse_args(sys.argv[1:]) | ||
|
||
alto_server = args.alto_server | ||
|
||
fp = open(args.flows, "r") | ||
input_str = fp.read() | ||
fp.close() | ||
|
||
print(do_request_from_str(input_str, alto_server)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.