-
Notifications
You must be signed in to change notification settings - Fork 4
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
Added cyberpandas support #12
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 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 |
---|---|---|
|
@@ -19,6 +19,7 @@ requirements: | |
- intake | ||
- python | ||
- pandas | ||
- cyberpandas | ||
- dask | ||
- pcapy | ||
|
||
|
This file contains 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 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 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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
intake | ||
pandas | ||
cyberpandas | ||
dask | ||
libpcap | ||
pcapy |
This file contains 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 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 |
---|---|---|
@@ -1,41 +1,41 @@ | ||
from .utils import dataframe_has_required_columns | ||
from .utils import assert_dataframe_has_required_columns | ||
|
||
|
||
def test_offline_unfiltered(ping_stream): | ||
df = ping_stream.to_dataframe() | ||
assert dataframe_has_required_columns(df, payload=False) | ||
assert_dataframe_has_required_columns(df, payload=False) | ||
assert len(df) == 96 | ||
|
||
|
||
def test_offline_filter_tcp(http_stream): | ||
http_stream.set_filter("tcp") | ||
df = http_stream.to_dataframe() | ||
assert dataframe_has_required_columns(df, payload=False) | ||
assert_dataframe_has_required_columns(df, payload=False) | ||
assert len(df) == 41 | ||
|
||
|
||
def test_offline_filter_udp(http_stream): | ||
http_stream.set_filter("udp") | ||
df = http_stream.to_dataframe() | ||
assert dataframe_has_required_columns(df, payload=False) | ||
assert_dataframe_has_required_columns(df, payload=False) | ||
assert len(df) == 2 | ||
|
||
|
||
def test_offline_filter_icmp(http_stream): | ||
http_stream.set_filter("icmp") | ||
df = http_stream.to_dataframe() | ||
assert dataframe_has_required_columns(df, payload=False) | ||
assert_dataframe_has_required_columns(df, payload=False) | ||
assert len(df) == 0 | ||
|
||
|
||
def test_offline_limit(http_stream): | ||
df = http_stream.to_dataframe(n=10) | ||
assert dataframe_has_required_columns(df, payload=False) | ||
assert_dataframe_has_required_columns(df, payload=False) | ||
assert len(df) == 10 | ||
|
||
|
||
def test_offline_filter_vlan(vlan_stream): | ||
vlan_stream.set_filter("tcp") | ||
df = vlan_stream.to_dataframe() | ||
assert dataframe_has_required_columns(df, payload=False) | ||
assert_dataframe_has_required_columns(df, payload=False) | ||
assert len(df) == 18 |
This file contains 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 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 |
---|---|---|
@@ -1,5 +1,21 @@ | ||
def dataframe_has_required_columns(df, payload): | ||
columns = ['time', 'src_host', 'src_port', 'dst_host', 'dst_port', 'protocol'] | ||
import pandas as pd | ||
import pandas.util.testing as tm | ||
|
||
|
||
def assert_dataframe_has_required_columns(df, payload): | ||
items = [ | ||
('time', 'datetime64[ns]'), | ||
('src_host', 'ip'), | ||
('src_port', 'u4'), | ||
('dst_host', 'ip'), | ||
('dst_port', 'u4'), | ||
('protocol', object) | ||
] | ||
|
||
if payload: | ||
columns.append("payload") | ||
return set(df.columns) == set(columns) | ||
items.append(("payload", 'object')) | ||
|
||
names, types = zip(*items) | ||
|
||
expected = pd.Series(types, index=names) | ||
tm.assert_series_equal(df.dtypes, expected) |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the input
df['src_host']
here? Are we parsing text, bytes or just copying binary data? Seems like there ought to be a way of making this not-slow.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAICT, at this point
src_host
anddst_host
are strings.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One issue is that the fastest way to build an IPArray is from a columar 64-bit aligned bytestring, whereas these seem to be record based. I'll look a bit deeper (after profiling things).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the input is not already an array of the right structure (e.g., with
.view()
), it may be useful here to build the new columns using empty arrays and fill them, perhaps in a tight numba loop.That will be generally true for the rest of the dataframe too.