traffic-taffy 0.5.8__tar.gz → 0.6.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. traffic_taffy-0.6.1/LICENSE.txt +204 -0
  2. {traffic_taffy-0.5.8 → traffic_taffy-0.6.1}/PKG-INFO +11 -2
  3. {traffic_taffy-0.5.8 → traffic_taffy-0.6.1}/README.md +8 -0
  4. {traffic_taffy-0.5.8 → traffic_taffy-0.6.1}/pyproject.toml +4 -2
  5. traffic_taffy-0.6.1/traffic_taffy/__init__.py +1 -0
  6. {traffic_taffy-0.5.8 → traffic_taffy-0.6.1}/traffic_taffy/compare.py +86 -54
  7. traffic_taffy-0.6.1/traffic_taffy/comparison.py +34 -0
  8. {traffic_taffy-0.5.8 → traffic_taffy-0.6.1}/traffic_taffy/dissection.py +31 -17
  9. {traffic_taffy-0.5.8 → traffic_taffy-0.6.1}/traffic_taffy/dissectmany.py +52 -27
  10. {traffic_taffy-0.5.8 → traffic_taffy-0.6.1}/traffic_taffy/dissector.py +22 -1
  11. {traffic_taffy-0.5.8 → traffic_taffy-0.6.1}/traffic_taffy/dissector_engine/__init__.py +24 -1
  12. traffic_taffy-0.6.1/traffic_taffy/dissector_engine/dnstap.py +121 -0
  13. traffic_taffy-0.6.1/traffic_taffy/dissector_engine/dpkt.py +264 -0
  14. {traffic_taffy-0.5.8 → traffic_taffy-0.6.1}/traffic_taffy/dissector_engine/scapy.py +27 -32
  15. {traffic_taffy-0.5.8 → traffic_taffy-0.6.1}/traffic_taffy/graph.py +22 -13
  16. {traffic_taffy-0.5.8 → traffic_taffy-0.6.1}/traffic_taffy/output/__init__.py +36 -20
  17. {traffic_taffy-0.5.8 → traffic_taffy-0.6.1}/traffic_taffy/output/console.py +32 -17
  18. {traffic_taffy-0.5.8 → traffic_taffy-0.6.1}/traffic_taffy/output/fsdb.py +17 -12
  19. traffic_taffy-0.6.1/traffic_taffy/output/memory.py +58 -0
  20. traffic_taffy-0.6.1/traffic_taffy/tests/test_compare_results.py +54 -0
  21. traffic_taffy-0.6.1/traffic_taffy/tests/test_dpkt_engine.py +15 -0
  22. {traffic_taffy-0.5.8 → traffic_taffy-0.6.1}/traffic_taffy/tests/test_pcap_dissector.py +4 -4
  23. {traffic_taffy-0.5.8 → traffic_taffy-0.6.1}/traffic_taffy/tests/test_pcap_splitter.py +0 -1
  24. {traffic_taffy-0.5.8 → traffic_taffy-0.6.1}/traffic_taffy/tools/cache_info.py +10 -7
  25. {traffic_taffy-0.5.8 → traffic_taffy-0.6.1}/traffic_taffy/tools/compare.py +10 -16
  26. {traffic_taffy-0.5.8 → traffic_taffy-0.6.1}/traffic_taffy/tools/dissect.py +8 -6
  27. {traffic_taffy-0.5.8 → traffic_taffy-0.6.1}/traffic_taffy/tools/explore.py +20 -46
  28. {traffic_taffy-0.5.8 → traffic_taffy-0.6.1}/traffic_taffy/tools/graph.py +6 -5
  29. traffic_taffy-0.5.8/traffic_taffy/__init__.py +0 -1
  30. traffic_taffy-0.5.8/traffic_taffy/comparison.py +0 -26
  31. traffic_taffy-0.5.8/traffic_taffy/dissector_engine/dpkt.py +0 -98
  32. traffic_taffy-0.5.8/traffic_taffy/dissectorresults.py +0 -21
  33. traffic_taffy-0.5.8/traffic_taffy/output/memory.py +0 -51
  34. traffic_taffy-0.5.8/traffic_taffy/tests/test_compare_results.py +0 -54
  35. traffic_taffy-0.5.8/traffic_taffy/tests/test_result_storage.py +0 -16
  36. {traffic_taffy-0.5.8 → traffic_taffy-0.6.1}/.gitignore +0 -0
  37. {traffic_taffy-0.5.8 → traffic_taffy-0.6.1}/traffic_taffy/graphdata.py +0 -0
  38. {traffic_taffy-0.5.8 → traffic_taffy-0.6.1}/traffic_taffy/tests/test_dict_merge.py +0 -0
  39. {traffic_taffy-0.5.8 → traffic_taffy-0.6.1}/traffic_taffy/tests/test_normalize.py +0 -0
  40. {traffic_taffy-0.5.8 → traffic_taffy-0.6.1}/traffic_taffy/tests/test_value_printing.py +0 -0
  41. {traffic_taffy-0.5.8 → traffic_taffy-0.6.1}/traffic_taffy/tools/__init__.py +0 -0
  42. {traffic_taffy-0.5.8 → traffic_taffy-0.6.1}/traffic_taffy/tools/export.py +0 -0
@@ -0,0 +1,204 @@
1
+ Copyright 2023-2024 USC/ISI
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
14
+
15
+
16
+ The Apache 2.0 LICENSE:
17
+
18
+ Apache License
19
+ Version 2.0, January 2004
20
+ http://www.apache.org/licenses/
21
+
22
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
23
+
24
+ 1. Definitions.
25
+
26
+ "License" shall mean the terms and conditions for use, reproduction,
27
+ and distribution as defined by Sections 1 through 9 of this document.
28
+
29
+ "Licensor" shall mean the copyright owner or entity authorized by
30
+ the copyright owner that is granting the License.
31
+
32
+ "Legal Entity" shall mean the union of the acting entity and all
33
+ other entities that control, are controlled by, or are under common
34
+ control with that entity. For the purposes of this definition,
35
+ "control" means (i) the power, direct or indirect, to cause the
36
+ direction or management of such entity, whether by contract or
37
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
38
+ outstanding shares, or (iii) beneficial ownership of such entity.
39
+
40
+ "You" (or "Your") shall mean an individual or Legal Entity
41
+ exercising permissions granted by this License.
42
+
43
+ "Source" form shall mean the preferred form for making modifications,
44
+ including but not limited to software source code, documentation
45
+ source, and configuration files.
46
+
47
+ "Object" form shall mean any form resulting from mechanical
48
+ transformation or translation of a Source form, including but
49
+ not limited to compiled object code, generated documentation,
50
+ and conversions to other media types.
51
+
52
+ "Work" shall mean the work of authorship, whether in Source or
53
+ Object form, made available under the License, as indicated by a
54
+ copyright notice that is included in or attached to the work
55
+ (an example is provided in the Appendix below).
56
+
57
+ "Derivative Works" shall mean any work, whether in Source or Object
58
+ form, that is based on (or derived from) the Work and for which the
59
+ editorial revisions, annotations, elaborations, or other modifications
60
+ represent, as a whole, an original work of authorship. For the purposes
61
+ of this License, Derivative Works shall not include works that remain
62
+ separable from, or merely link (or bind by name) to the interfaces of,
63
+ the Work and Derivative Works thereof.
64
+
65
+ "Contribution" shall mean any work of authorship, including
66
+ the original version of the Work and any modifications or additions
67
+ to that Work or Derivative Works thereof, that is intentionally
68
+ submitted to Licensor for inclusion in the Work by the copyright owner
69
+ or by an individual or Legal Entity authorized to submit on behalf of
70
+ the copyright owner. For the purposes of this definition, "submitted"
71
+ means any form of electronic, verbal, or written communication sent
72
+ to the Licensor or its representatives, including but not limited to
73
+ communication on electronic mailing lists, source code control systems,
74
+ and issue tracking systems that are managed by, or on behalf of, the
75
+ Licensor for the purpose of discussing and improving the Work, but
76
+ excluding communication that is conspicuously marked or otherwise
77
+ designated in writing by the copyright owner as "Not a Contribution."
78
+
79
+ "Contributor" shall mean Licensor and any individual or Legal Entity
80
+ on behalf of whom a Contribution has been received by Licensor and
81
+ subsequently incorporated within the Work.
82
+
83
+ 2. Grant of Copyright License. Subject to the terms and conditions of
84
+ this License, each Contributor hereby grants to You a perpetual,
85
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
86
+ copyright license to reproduce, prepare Derivative Works of,
87
+ publicly display, publicly perform, sublicense, and distribute the
88
+ Work and such Derivative Works in Source or Object form.
89
+
90
+ 3. Grant of Patent License. Subject to the terms and conditions of
91
+ this License, each Contributor hereby grants to You a perpetual,
92
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
93
+ (except as stated in this section) patent license to make, have made,
94
+ use, offer to sell, sell, import, and otherwise transfer the Work,
95
+ where such license applies only to those patent claims licensable
96
+ by such Contributor that are necessarily infringed by their
97
+ Contribution(s) alone or by combination of their Contribution(s)
98
+ with the Work to which such Contribution(s) was submitted. If You
99
+ institute patent litigation against any entity (including a
100
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
101
+ or a Contribution incorporated within the Work constitutes direct
102
+ or contributory patent infringement, then any patent licenses
103
+ granted to You under this License for that Work shall terminate
104
+ as of the date such litigation is filed.
105
+
106
+ 4. Redistribution. You may reproduce and distribute copies of the
107
+ Work or Derivative Works thereof in any medium, with or without
108
+ modifications, and in Source or Object form, provided that You
109
+ meet the following conditions:
110
+
111
+ (a) You must give any other recipients of the Work or
112
+ Derivative Works a copy of this License; and
113
+
114
+ (b) You must cause any modified files to carry prominent notices
115
+ stating that You changed the files; and
116
+
117
+ (c) You must retain, in the Source form of any Derivative Works
118
+ that You distribute, all copyright, patent, trademark, and
119
+ attribution notices from the Source form of the Work,
120
+ excluding those notices that do not pertain to any part of
121
+ the Derivative Works; and
122
+
123
+ (d) If the Work includes a "NOTICE" text file as part of its
124
+ distribution, then any Derivative Works that You distribute must
125
+ include a readable copy of the attribution notices contained
126
+ within such NOTICE file, excluding those notices that do not
127
+ pertain to any part of the Derivative Works, in at least one
128
+ of the following places: within a NOTICE text file distributed
129
+ as part of the Derivative Works; within the Source form or
130
+ documentation, if provided along with the Derivative Works; or,
131
+ within a display generated by the Derivative Works, if and
132
+ wherever such third-party notices normally appear. The contents
133
+ of the NOTICE file are for informational purposes only and
134
+ do not modify the License. You may add Your own attribution
135
+ notices within Derivative Works that You distribute, alongside
136
+ or as an addendum to the NOTICE text from the Work, provided
137
+ that such additional attribution notices cannot be construed
138
+ as modifying the License.
139
+
140
+ You may add Your own copyright statement to Your modifications and
141
+ may provide additional or different license terms and conditions
142
+ for use, reproduction, or distribution of Your modifications, or
143
+ for any such Derivative Works as a whole, provided Your use,
144
+ reproduction, and distribution of the Work otherwise complies with
145
+ the conditions stated in this License.
146
+
147
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
148
+ any Contribution intentionally submitted for inclusion in the Work
149
+ by You to the Licensor shall be under the terms and conditions of
150
+ this License, without any additional terms or conditions.
151
+ Notwithstanding the above, nothing herein shall supersede or modify
152
+ the terms of any separate license agreement you may have executed
153
+ with Licensor regarding such Contributions.
154
+
155
+ 6. Trademarks. This License does not grant permission to use the trade
156
+ names, trademarks, service marks, or product names of the Licensor,
157
+ except as required for reasonable and customary use in describing the
158
+ origin of the Work and reproducing the content of the NOTICE file.
159
+
160
+ 7. Disclaimer of Warranty. Unless required by applicable law or
161
+ agreed to in writing, Licensor provides the Work (and each
162
+ Contributor provides its Contributions) on an "AS IS" BASIS,
163
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
164
+ implied, including, without limitation, any warranties or conditions
165
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
166
+ PARTICULAR PURPOSE. You are solely responsible for determining the
167
+ appropriateness of using or redistributing the Work and assume any
168
+ risks associated with Your exercise of permissions under this License.
169
+
170
+ 8. Limitation of Liability. In no event and under no legal theory,
171
+ whether in tort (including negligence), contract, or otherwise,
172
+ unless required by applicable law (such as deliberate and grossly
173
+ negligent acts) or agreed to in writing, shall any Contributor be
174
+ liable to You for damages, including any direct, indirect, special,
175
+ incidental, or consequential damages of any character arising as a
176
+ result of this License or out of the use or inability to use the
177
+ Work (including but not limited to damages for loss of goodwill,
178
+ work stoppage, computer failure or malfunction, or any and all
179
+ other commercial damages or losses), even if such Contributor
180
+ has been advised of the possibility of such damages.
181
+
182
+ 9. Accepting Warranty or Additional Liability. While redistributing
183
+ the Work or Derivative Works thereof, You may choose to offer,
184
+ and charge a fee for, acceptance of support, warranty, indemnity,
185
+ or other liability obligations and/or rights consistent with this
186
+ License. However, in accepting such obligations, You may act only
187
+ on Your own behalf and on Your sole responsibility, not on behalf
188
+ of any other Contributor, and only if You agree to indemnify,
189
+ defend, and hold each Contributor harmless for any liability
190
+ incurred by, or claims asserted against, such Contributor by reason
191
+ of your accepting any such warranty or additional liability.
192
+
193
+ END OF TERMS AND CONDITIONS
194
+
195
+ APPENDIX: How to apply the Apache License to your work.
196
+
197
+ To apply the Apache License to your work, attach the following
198
+ boilerplate notice, with the fields enclosed by brackets "[]"
199
+ replaced with your own identifying information. (Don't include
200
+ the brackets!) The text should be enclosed in the appropriate
201
+ comment syntax for the file format. We also recommend that a
202
+ file or class name and description of purpose be included on the
203
+ same "printed page" as the copyright notice for easier
204
+ identification within third-party archives.
@@ -1,9 +1,10 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: traffic-taffy
3
- Version: 0.5.8
3
+ Version: 0.6.1
4
4
  Summary: A tool for doing differential analysis of pcap files
5
- Project-URL: Homepage, https://github.com/hardaker/traffic-taffy
5
+ Project-URL: Homepage, https://traffic-taffy.github.io/
6
6
  Author-email: Wes Hardaker <opensource@hardakers.net>
7
+ License-File: LICENSE.txt
7
8
  Classifier: Operating System :: OS Independent
8
9
  Classifier: Programming Language :: Python :: 3
9
10
  Requires-Python: >=3.7
@@ -40,6 +41,14 @@ This tool is designed to do just that.
40
41
  See the online [readthedocs
41
42
  documentation](https://traffic-taffy.readthedocs.io/).
42
43
 
44
+ ## Development
45
+
46
+ Traffic-taffy is under very rapid development with a fair amount of
47
+ refactoring as time goes on into better class architectures. If you
48
+ are considering looking at portions of the code and submitting pull
49
+ requests, please reach out to Wes ahead of time to check what changes
50
+ might be coming that will cause merge conflicts.
51
+
43
52
  # Copyright and License
44
53
 
45
54
  This project is copyrighted by the University of Southern California,
@@ -18,6 +18,14 @@ This tool is designed to do just that.
18
18
  See the online [readthedocs
19
19
  documentation](https://traffic-taffy.readthedocs.io/).
20
20
 
21
+ ## Development
22
+
23
+ Traffic-taffy is under very rapid development with a fair amount of
24
+ refactoring as time goes on into better class architectures. If you
25
+ are considering looking at portions of the code and submitting pull
26
+ requests, please reach out to Wes ahead of time to check what changes
27
+ might be coming that will cause merge conflicts.
28
+
21
29
  # Copyright and License
22
30
 
23
31
  This project is copyrighted by the University of Southern California,
@@ -39,7 +39,7 @@ taffy-graph = "traffic_taffy.tools.graph:main"
39
39
  taffy-export = "traffic_taffy.tools.export:main"
40
40
 
41
41
  [project.urls]
42
- Homepage = "https://github.com/hardaker/traffic-taffy"
42
+ Homepage = "https://traffic-taffy.github.io/"
43
43
 
44
44
  [tool.hatch.version]
45
45
  path = "traffic_taffy/__init__.py"
@@ -65,7 +65,9 @@ ignore = ["E501", "I001", "PLR0913", "ANN101", "ANN204",
65
65
  # complaining about simple if/else
66
66
  "SIM108",
67
67
  # allow blind exceptions
68
- "BLE001"
68
+ "BLE001",
69
+ # allow for loop variable overrides
70
+ "PLW2901",
69
71
  ]
70
72
  fixable = ["ALL"] # gulp
71
73
  # select = ["ALL"]
@@ -0,0 +1 @@
1
+ __VERSION__ = "0.6.1"
@@ -1,16 +1,35 @@
1
+ """The primary statistical packet comparison engine."""
2
+
3
+ from __future__ import annotations
1
4
  from logging import debug, error
2
- from typing import List
5
+ from typing import List, TYPE_CHECKING
3
6
  import datetime as dt
4
7
  from datetime import datetime
5
8
 
9
+ if TYPE_CHECKING:
10
+ from argparse import ArgumentParser, Namespace
11
+
6
12
  from traffic_taffy.comparison import Comparison
7
13
  from traffic_taffy.dissectmany import PCAPDissectMany
8
14
  from traffic_taffy.dissector import PCAPDissectorLevel
9
15
  from traffic_taffy.dissection import Dissection
10
16
 
17
+ from dataclasses import dataclass
18
+
19
+
20
+ @dataclass
21
+ class Report:
22
+ delta_percentage: float
23
+ delta_absolute: int
24
+ total: int
25
+ left_count: int
26
+ right_count: int
27
+ left_percentage: float
28
+ right_percentage: float
29
+
11
30
 
12
31
  class PcapCompare:
13
- "Takes a set of PCAPs to then perform various comparisons upon"
32
+ """Take a set of PCAPs to then perform various comparisons upon."""
14
33
 
15
34
  REPORT_VERSION: int = 2
16
35
 
@@ -25,11 +44,12 @@ class PcapCompare:
25
44
  bin_size: int | None = None,
26
45
  dissection_level: PCAPDissectorLevel = PCAPDissectorLevel.COUNT_ONLY,
27
46
  between_times: List[int] | None = None,
28
- ignore_list: List[str] = [],
47
+ ignore_list: List[str] | None = None,
29
48
  layers: List[str] | None = None,
30
49
  force_load: bool = False,
31
50
  force_overwrite: bool = False,
32
51
  ) -> None:
52
+ """Create a compare object."""
33
53
  self.pcap_files = pcap_files
34
54
  self.deep = deep
35
55
  self.maximum_count = maximum_count
@@ -39,30 +59,31 @@ class PcapCompare:
39
59
  self.between_times = between_times
40
60
  self.bin_size = bin_size
41
61
  self.cache_file_suffix = cache_file_suffix
42
- self.ignore_list = ignore_list
62
+ self.ignore_list = ignore_list or []
43
63
  self.layers = layers
44
64
  self.force_overwrite = force_overwrite
45
65
  self.force_load = force_load
46
66
 
47
67
  @property
48
- def pcap_files(self):
68
+ def pcap_files(self) -> List[str]:
69
+ """List of pcap files being compared."""
49
70
  return self._pcap_files
50
71
 
51
72
  @pcap_files.setter
52
- def pcap_files(self, new_pcap_files):
73
+ def pcap_files(self, new_pcap_files: List[str]) -> None:
53
74
  self._pcap_files = new_pcap_files
54
75
 
55
76
  @property
56
- def reports(self):
77
+ def reports(self) -> List[dict]:
78
+ """List of reports generated by the comparison."""
57
79
  return self._reports
58
80
 
59
81
  @reports.setter
60
- def reports(self, newvalue):
82
+ def reports(self, newvalue: List[dict]) -> None:
61
83
  self._reports = newvalue
62
84
 
63
85
  def compare_dissections(self, left_side: dict, right_side: dict) -> dict:
64
- "compares the results from two reports"
65
-
86
+ """Compare two dissections."""
66
87
  report = {}
67
88
 
68
89
  keys = set(left_side.keys())
@@ -79,7 +100,7 @@ class PcapCompare:
79
100
  right_side_total = sum(right_side[key].values())
80
101
 
81
102
  new_left_count = 0
82
- for subkey in left_side[key].keys():
103
+ for subkey in left_side[key]:
83
104
  delta_percentage = 0.0
84
105
  total = 0
85
106
  if subkey in right_side[key]:
@@ -99,18 +120,18 @@ class PcapCompare:
99
120
  new_left_count += 1
100
121
 
101
122
  delta_absolute = right_count - left_count
102
- report[key][subkey] = {
103
- "delta_percentage": delta_percentage,
104
- "delta_absolute": delta_absolute,
105
- "total": total,
106
- "left_count": left_count,
107
- "right_count": right_count,
108
- "left_percentage": left_percentage,
109
- "right_percentage": right_percentage,
110
- }
123
+ report[key][subkey] = Report(
124
+ delta_percentage=delta_percentage,
125
+ delta_absolute=delta_absolute,
126
+ total=total,
127
+ left_count=left_count,
128
+ right_count=right_count,
129
+ left_percentage=left_percentage,
130
+ right_percentage=right_percentage,
131
+ )
111
132
 
112
133
  new_right_count = 0
113
- for subkey in right_side[key].keys():
134
+ for subkey in right_side[key]:
114
135
  if subkey not in report[key]:
115
136
  delta_percentage = 1.0
116
137
  total = right_side[key][subkey]
@@ -120,15 +141,15 @@ class PcapCompare:
120
141
  right_percentage = right_side[key][subkey] / right_side_total
121
142
  new_right_count += 1 # this value wasn't in the left
122
143
 
123
- report[key][subkey] = {
124
- "delta_percentage": delta_percentage,
125
- "delta_absolute": right_count,
126
- "total": total,
127
- "left_count": left_count,
128
- "right_count": right_count,
129
- "left_percentage": left_percentage,
130
- "right_percentage": right_percentage,
131
- }
144
+ report[key][subkey] = Report(
145
+ delta_percentage=delta_percentage,
146
+ delta_absolute=right_count,
147
+ total=total,
148
+ left_count=left_count,
149
+ right_count=right_count,
150
+ left_percentage=left_percentage,
151
+ right_percentage=right_percentage,
152
+ )
132
153
 
133
154
  if right_side_total == 0:
134
155
  right_percent = 100
@@ -140,19 +161,20 @@ class PcapCompare:
140
161
  else:
141
162
  left_percent = new_left_count / left_side_total
142
163
 
143
- report[key][Dissection.NEW_RIGHT_SUBKEY] = {
144
- "delta_absolute": new_right_count - new_left_count,
145
- "total": new_left_count + new_right_count,
146
- "left_count": new_left_count,
147
- "right_count": new_right_count,
148
- "left_percentage": left_percent,
149
- "right_percentage": right_percent,
150
- "delta_percentage": right_percent - left_percent,
151
- }
164
+ report[key][Dissection.NEW_RIGHT_SUBKEY] = Report(
165
+ delta_absolute=new_right_count - new_left_count,
166
+ total=new_left_count + new_right_count,
167
+ left_count=new_left_count,
168
+ right_count=new_right_count,
169
+ left_percentage=left_percent,
170
+ right_percentage=right_percent,
171
+ delta_percentage=right_percent - left_percent,
172
+ )
152
173
 
153
174
  return Comparison(report)
154
175
 
155
176
  def load_pcaps(self) -> None:
177
+ """Load all pcaps into memory and dissect them."""
156
178
  # load the first as a reference pcap
157
179
  pdm = PCAPDissectMany(
158
180
  self.pcap_files,
@@ -167,17 +189,16 @@ class PcapCompare:
167
189
  force_load=self.force_load,
168
190
  force_overwrite=self.force_overwrite,
169
191
  )
170
- results = pdm.load_all()
171
- return results
192
+ return pdm.load_all()
172
193
 
173
194
  def compare(self) -> List[Comparison]:
174
- "Compares each pcap against the original source"
175
-
195
+ """Compare each pcap as requested."""
176
196
  dissections = self.load_pcaps()
177
197
  self.compare_all(dissections)
178
198
  return self.reports
179
199
 
180
- def compare_all(self, dissections) -> List[Comparison]:
200
+ def compare_all(self, dissections: List[Dissection]) -> List[Comparison]:
201
+ """Compare all loaded pcaps."""
181
202
  reports = []
182
203
  if len(self.pcap_files) > 1:
183
204
  # multiple file comparison
@@ -197,9 +218,8 @@ class PcapCompare:
197
218
  error(
198
219
  "the requested pcap data was not long enough to compare against itself"
199
220
  )
200
- raise ValueError(
201
- "not enough of a single capture file to time-bin the results"
202
- )
221
+ errorstr: str = "not large enough pcap file"
222
+ raise ValueError(errorstr)
203
223
  debug(
204
224
  f"found {len(timestamps)} timestamps from {timestamps[2]} to {timestamps[-1]}"
205
225
  )
@@ -249,7 +269,10 @@ class PcapCompare:
249
269
  return reports
250
270
 
251
271
 
252
- def compare_add_parseargs(compare_parser, add_subgroup: bool = True):
272
+ def compare_add_parseargs(
273
+ compare_parser: ArgumentParser, add_subgroup: bool = True
274
+ ) -> ArgumentParser:
275
+ """Add common comparison arguments."""
253
276
  if add_subgroup:
254
277
  compare_parser = compare_parser.add_argument_group("Comparison result options")
255
278
 
@@ -285,17 +308,26 @@ def compare_add_parseargs(compare_parser, add_subgroup: bool = True):
285
308
  )
286
309
 
287
310
  compare_parser.add_argument(
288
- "-T",
289
- "--between-times",
290
- nargs=2,
291
- type=int,
292
- help="For single files, only display results between these timestamps",
311
+ "-s",
312
+ "--sort-by",
313
+ default="delta%",
314
+ type=str,
315
+ help="Sort report entries by this column",
293
316
  )
294
317
 
318
+ # compare_parser.add_argument(
319
+ # "-T",
320
+ # "--between-times",
321
+ # nargs=2,
322
+ # type=int,
323
+ # help="For single files, only display results between these timestamps",
324
+ # )
325
+
295
326
  return compare_parser
296
327
 
297
328
 
298
- def get_comparison_args(args):
329
+ def get_comparison_args(args: Namespace) -> dict:
330
+ """Return a dict of comparison parameters from arguments."""
299
331
  return {
300
332
  "maximum_count": args.packet_count or 0,
301
333
  "print_threshold": float(args.print_threshold) / 100.0,
@@ -0,0 +1,34 @@
1
+ """A simple data storage module to hold comparison data."""
2
+
3
+ from __future__ import annotations
4
+ from typing import Dict, Any
5
+
6
+
7
+ class Comparison:
8
+ """A simple data storage class to hold comparison data."""
9
+
10
+ def __init__(self, contents: list, title: str = ""):
11
+ """Create a Comparison class from contents."""
12
+ self.contents = contents
13
+ self.title: str = title
14
+ self.printing_arguments: Dict[str, Any] = {}
15
+
16
+ # title
17
+ @property
18
+ def title(self) -> str:
19
+ """The title of this comparison."""
20
+ return self._title
21
+
22
+ @title.setter
23
+ def title(self, new_title: str) -> None:
24
+ self._title = new_title
25
+
26
+ # report contents -- actual data
27
+ @property
28
+ def contents(self) -> None:
29
+ """The contents of this comparison."""
30
+ return self._contents
31
+
32
+ @contents.setter
33
+ def contents(self, new_contents: str) -> None:
34
+ self._contents = new_contents