retis 1.5.0__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 (33) hide show
  1. retis-1.5.0/PKG-INFO +39 -0
  2. retis-1.5.0/PYTHON_LIB_README.md +16 -0
  3. retis-1.5.0/pyproject.toml +36 -0
  4. retis-1.5.0/retis-derive/.gitignore +2 -0
  5. retis-1.5.0/retis-derive/Cargo.toml +14 -0
  6. retis-1.5.0/retis-derive/src/lib.rs +180 -0
  7. retis-1.5.0/retis-events/.gitignore +2 -0
  8. retis-1.5.0/retis-events/Cargo.lock +822 -0
  9. retis-1.5.0/retis-events/Cargo.toml +25 -0
  10. retis-1.5.0/retis-events/PYTHON_LIB_README.md +16 -0
  11. retis-1.5.0/retis-events/pytests/test_reader.py +61 -0
  12. retis-1.5.0/retis-events/python/__init__.py +1 -0
  13. retis-1.5.0/retis-events/src/.lib.rs.swp +0 -0
  14. retis-1.5.0/retis-events/src/common.rs +75 -0
  15. retis-1.5.0/retis-events/src/ct.rs +234 -0
  16. retis-1.5.0/retis-events/src/display.rs +325 -0
  17. retis-1.5.0/retis-events/src/events.rs +423 -0
  18. retis-1.5.0/retis-events/src/file.rs +119 -0
  19. retis-1.5.0/retis-events/src/helpers.rs +124 -0
  20. retis-1.5.0/retis-events/src/kernel.rs +60 -0
  21. retis-1.5.0/retis-events/src/lib.rs +58 -0
  22. retis-1.5.0/retis-events/src/nft.rs +44 -0
  23. retis-1.5.0/retis-events/src/ovs.rs +674 -0
  24. retis-1.5.0/retis-events/src/python.rs +397 -0
  25. retis-1.5.0/retis-events/src/python_embed.rs +51 -0
  26. retis-1.5.0/retis-events/src/skb.rs +507 -0
  27. retis-1.5.0/retis-events/src/skb_drop.rs +23 -0
  28. retis-1.5.0/retis-events/src/skb_tracking.rs +102 -0
  29. retis-1.5.0/retis-events/src/time.rs +124 -0
  30. retis-1.5.0/retis-events/src/user.rs +31 -0
  31. retis-1.5.0/retis-events/test_data/test_events.json +4 -0
  32. retis-1.5.0/retis-events/test_data/test_events_sorted.json +3 -0
  33. retis-1.5.0/retis-events/tox.ini +12 -0
retis-1.5.0/PKG-INFO ADDED
@@ -0,0 +1,39 @@
1
+ Metadata-Version: 2.3
2
+ Name: retis
3
+ Version: 1.5.0
4
+ Classifier: Development Status :: 4 - Beta
5
+ Classifier: Intended Audience :: Developers
6
+ Classifier: Operating System :: POSIX :: Linux
7
+ Classifier: Programming Language :: Python :: 3
8
+ Classifier: Programming Language :: Python :: 3.8
9
+ Classifier: Programming Language :: Python :: 3.9
10
+ Classifier: Programming Language :: Python :: 3.10
11
+ Classifier: Programming Language :: Python :: 3.11
12
+ Classifier: Programming Language :: Python :: 3.12
13
+ Classifier: Programming Language :: Python :: 3.13
14
+ Classifier: Programming Language :: Python
15
+ Classifier: Programming Language :: Rust
16
+ Classifier: License :: OSI Approved :: GNU General Public License v2 (GPLv2)
17
+ Summary: Python bindings for Retis events
18
+ Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
19
+ Project-URL: HomePage, https://github.com/retis-org/retis
20
+ Project-URL: Documentation, https://retis.readthedocs.io/
21
+ Project-URL: Repository, https://github.com/retis-org/retis
22
+
23
+ # retis
24
+
25
+ Python bindings for [retis](https://retis.readthedocs.io/en/stable/) events.
26
+
27
+ This python library can be used to read and post-process retis events.
28
+
29
+ Example:
30
+
31
+ ```python
32
+ from retis import EventFile
33
+
34
+ reader = EventFile("retis.data")
35
+
36
+ for e in reader.events():
37
+ print(e.show())
38
+ ```
39
+
@@ -0,0 +1,16 @@
1
+ # retis
2
+
3
+ Python bindings for [retis](https://retis.readthedocs.io/en/stable/) events.
4
+
5
+ This python library can be used to read and post-process retis events.
6
+
7
+ Example:
8
+
9
+ ```python
10
+ from retis import EventFile
11
+
12
+ reader = EventFile("retis.data")
13
+
14
+ for e in reader.events():
15
+ print(e.show())
16
+ ```
@@ -0,0 +1,36 @@
1
+ [build-system]
2
+ requires = ["maturin>=1.0"]
3
+ build-backend = "maturin"
4
+
5
+ [tool.maturin]
6
+ bindings = "pyo3"
7
+ features = ["python-lib"]
8
+ manifest-path = "retis-events/Cargo.toml"
9
+
10
+ [project]
11
+ name = "retis"
12
+ classifiers = [
13
+ "Development Status :: 4 - Beta",
14
+ "Intended Audience :: Developers",
15
+
16
+ "Operating System :: POSIX :: Linux",
17
+
18
+ "Programming Language :: Python :: 3",
19
+ "Programming Language :: Python :: 3.8",
20
+ "Programming Language :: Python :: 3.9",
21
+ "Programming Language :: Python :: 3.10",
22
+ "Programming Language :: Python :: 3.11",
23
+ "Programming Language :: Python :: 3.12",
24
+ "Programming Language :: Python :: 3.13",
25
+ "Programming Language :: Python",
26
+ "Programming Language :: Rust",
27
+
28
+ "License :: OSI Approved :: GNU General Public License v2 (GPLv2)",
29
+ ]
30
+ description = "Python bindings for Retis events"
31
+ readme = "PYTHON_LIB_README.md"
32
+
33
+ [project.urls]
34
+ HomePage = "https://github.com/retis-org/retis"
35
+ Documentation = "https://retis.readthedocs.io/"
36
+ Repository = "https://github.com/retis-org/retis"
@@ -0,0 +1,2 @@
1
+ /target
2
+ /Cargo.lock
@@ -0,0 +1,14 @@
1
+ [package]
2
+ name = "retis-derive"
3
+ version = "1.5.0"
4
+ edition = "2021"
5
+
6
+ [features]
7
+ python = []
8
+
9
+ [lib]
10
+ proc-macro = true
11
+
12
+ [dependencies]
13
+ quote = "1.0"
14
+ syn = {version="2.0", features = ["derive"]}
@@ -0,0 +1,180 @@
1
+ use quote::quote;
2
+ use syn::{parse_macro_input, Fields, Ident, Item, ItemStruct};
3
+
4
+ #[proc_macro_attribute]
5
+ pub fn event_section(
6
+ args: proc_macro::TokenStream,
7
+ item: proc_macro::TokenStream,
8
+ ) -> proc_macro::TokenStream {
9
+ let input: Item = parse_macro_input!(item);
10
+ let ident = match input {
11
+ Item::Struct(ref item) => item.ident.clone(),
12
+ Item::Enum(ref item) => item.ident.clone(),
13
+ _ => panic!("event types must be enums or structs"),
14
+ };
15
+
16
+ let id: syn::Expr = syn::parse(args).expect("Invalid event id");
17
+
18
+ let output = quote! {
19
+ #[crate::event_type]
20
+ #input
21
+
22
+ impl #ident {
23
+ pub(crate) const SECTION_ID: u8 = #id as u8;
24
+ }
25
+
26
+ impl EventSectionInternal for #ident {
27
+ fn id(&self) -> u8 {
28
+ Self::SECTION_ID
29
+ }
30
+
31
+ fn as_any(&self) -> &dyn std::any::Any
32
+ where Self: Sized,
33
+ {
34
+ self
35
+ }
36
+
37
+ fn as_any_mut(&mut self) -> &mut dyn std::any::Any
38
+ where Self: Sized,
39
+ {
40
+ self
41
+ }
42
+
43
+ fn to_json(&self) -> serde_json::Value
44
+ where Self: serde::Serialize,
45
+ {
46
+ serde_json::json!(self)
47
+ }
48
+
49
+ #[cfg(feature = "python")]
50
+ fn to_py(&self, py: pyo3::Python<'_>) -> pyo3::PyObject {
51
+ use pyo3::IntoPyObject;
52
+ self.clone().into_pyobject(py).unwrap().into_any().unbind()
53
+ }
54
+ }
55
+
56
+ #[cfg_attr(feature = "python", pyo3::pymethods)]
57
+ #[cfg(feature = "python")]
58
+ impl #ident {
59
+ fn raw(&self, py: pyo3::Python<'_>) -> pyo3::PyObject {
60
+ crate::python::to_pyobject(&self.to_json(), py)
61
+ }
62
+
63
+ fn show(&self) -> String {
64
+ let format = crate::DisplayFormat::new().multiline(true);
65
+ format!("{}", self.display(&format, &crate::FormatterConf::new()))
66
+ }
67
+ }
68
+ };
69
+ output.into()
70
+ }
71
+
72
+ struct EventTypeProps {
73
+ ident: Ident,
74
+ enum_is_simple: bool,
75
+ named_fields: bool,
76
+ }
77
+
78
+ fn item_get_props(item: &Item) -> EventTypeProps {
79
+ let mut enum_is_simple = false;
80
+ let named_fields;
81
+
82
+ let ident = match item {
83
+ Item::Struct(item) => {
84
+ named_fields = matches!(&item.fields, Fields::Named(_));
85
+ item.ident.clone()
86
+ }
87
+ Item::Enum(item) => {
88
+ named_fields = item
89
+ .variants
90
+ .iter()
91
+ .all(|v| matches!(v.fields, Fields::Named(_)));
92
+ enum_is_simple = item.variants.iter().all(|v| v.fields == Fields::Unit);
93
+ item.ident.clone()
94
+ }
95
+ _ => panic!("event types must be enums or structs"),
96
+ };
97
+ EventTypeProps {
98
+ ident,
99
+ enum_is_simple,
100
+ named_fields,
101
+ }
102
+ }
103
+
104
+ #[proc_macro_attribute]
105
+ pub fn event_type(
106
+ _args: proc_macro::TokenStream,
107
+ item: proc_macro::TokenStream,
108
+ ) -> proc_macro::TokenStream {
109
+ let input: Item = parse_macro_input!(item);
110
+ let props = item_get_props(&input);
111
+ let mut pyclass_args = Vec::new();
112
+ let mut derives = vec![
113
+ quote!(Clone),
114
+ quote!(Debug),
115
+ quote!(serde::Serialize),
116
+ quote!(serde::Deserialize),
117
+ ];
118
+
119
+ if props.enum_is_simple {
120
+ // Simple enums need to be passed extra arguments so equality is implemented
121
+ // using underlying integers: See https://pyo3.rs/main/doc/pyo3/attr.pyclass.html.
122
+ pyclass_args.push(quote!(eq));
123
+ pyclass_args.push(quote!(eq_int));
124
+ derives.push(quote!(PartialEq))
125
+ } else if props.named_fields {
126
+ // Generate getters to all named fields.
127
+ pyclass_args.push(quote!(get_all));
128
+ }
129
+ let ident = &props.ident;
130
+
131
+ let output = quote! {
132
+ #[cfg_attr(feature = "python", pyo3::pyclass(#(#pyclass_args),*))]
133
+ #[serde_with::skip_serializing_none]
134
+ #[derive(#(#derives),*)]
135
+ #input
136
+
137
+ #[cfg_attr(feature = "python", pyo3::pymethods)]
138
+ #[cfg(feature = "python")]
139
+ impl #ident {
140
+ fn __repr__(&self, py: pyo3::Python<'_>) -> String {
141
+ format!("{:?}", self)
142
+ }
143
+
144
+ }
145
+ };
146
+ output.into()
147
+ }
148
+
149
+ #[proc_macro_attribute]
150
+ pub fn event_section_factory(
151
+ args: proc_macro::TokenStream,
152
+ item: proc_macro::TokenStream,
153
+ ) -> proc_macro::TokenStream {
154
+ let input: ItemStruct = parse_macro_input!(item);
155
+ let ident = &input.ident;
156
+
157
+ let id: syn::Expr = syn::parse(args).expect("Invalid factory id");
158
+
159
+ let output = quote! {
160
+ #input
161
+
162
+ impl #ident {
163
+ pub(crate) const FACTORY_ID: u8 = #id as u8;
164
+
165
+ }
166
+
167
+ impl EventSectionFactory for #ident {
168
+ fn id(&self) -> u8 {
169
+ Self::FACTORY_ID
170
+ }
171
+
172
+ fn as_any_mut(&mut self) -> &mut dyn std::any::Any
173
+ where Self: Sized,
174
+ {
175
+ self
176
+ }
177
+ }
178
+ };
179
+ output.into()
180
+ }
@@ -0,0 +1,2 @@
1
+ /target
2
+ /Cargo.lock