diff options
author | Hyun Jae Moon <hyunjaemoon@google.com> | 2023-04-19 16:49:47 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2023-04-19 16:49:47 +0000 |
commit | 70346f739ef33b9791bc69ef9e8ba3045a099e0e (patch) | |
tree | ed1d080cbb5501dff77f1e17a81644bd9b142fc4 | |
parent | 490eae762711589284ababac1dae57b04421f511 (diff) | |
parent | c275d5ee4d19454990d230aeac77af1d3d1ba8eb (diff) | |
download | netsim-70346f739ef33b9791bc69ef9e8ba3045a099e0e.tar.gz |
Merge "Pcap --> Capture cleanup" am: c275d5ee4d
Original change: https://android-review.googlesource.com/c/platform/tools/netsim/+/2545633
Change-Id: I3def6a62946c81f12ef0914e7fbfb16d287c292a
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
26 files changed, 489 insertions, 494 deletions
diff --git a/rust/frontend-client-cxx/src/lib.rs b/rust/frontend-client-cxx/src/lib.rs index e2c8455b..5a1a2e84 100644 --- a/rust/frontend-client-cxx/src/lib.rs +++ b/rust/frontend-client-cxx/src/lib.rs @@ -39,9 +39,9 @@ pub mod ffi { PatchDevice, GetDevices, Reset, - ListPcap, - PatchPcap, - GetPcap, + ListCapture, + PatchCapture, + GetCapture, } extern "Rust" { @@ -62,8 +62,8 @@ pub mod ffi { pub fn NewFrontendClient() -> UniquePtr<FrontendClient>; #[allow(dead_code)] - #[rust_name = "get_pcap"] - pub fn GetPcap( + #[rust_name = "get_capture"] + pub fn GetCapture( self: &FrontendClient, request: &Vec<u8>, client_reader: &ClientResponseReader, diff --git a/rust/frontend-proto/src/frontend.rs b/rust/frontend-proto/src/frontend.rs index aaf7bb6e..469a4161 100644 --- a/rust/frontend-proto/src/frontend.rs +++ b/rust/frontend-proto/src/frontend.rs @@ -955,26 +955,26 @@ impl ::protobuf::reflect::ProtobufValue for SetPacketCaptureRequest { } #[derive(PartialEq,Clone,Default,Debug)] -// @@protoc_insertion_point(message:netsim.frontend.PatchPcapRequest) -pub struct PatchPcapRequest { +// @@protoc_insertion_point(message:netsim.frontend.PatchCaptureRequest) +pub struct PatchCaptureRequest { // message fields - // @@protoc_insertion_point(field:netsim.frontend.PatchPcapRequest.id) + // @@protoc_insertion_point(field:netsim.frontend.PatchCaptureRequest.id) pub id: i32, - // @@protoc_insertion_point(field:netsim.frontend.PatchPcapRequest.patch) - pub patch: ::protobuf::MessageField<patch_pcap_request::PcapPatch>, + // @@protoc_insertion_point(field:netsim.frontend.PatchCaptureRequest.patch) + pub patch: ::protobuf::MessageField<patch_capture_request::PatchCapture>, // special fields - // @@protoc_insertion_point(special_field:netsim.frontend.PatchPcapRequest.special_fields) + // @@protoc_insertion_point(special_field:netsim.frontend.PatchCaptureRequest.special_fields) pub special_fields: ::protobuf::SpecialFields, } -impl<'a> ::std::default::Default for &'a PatchPcapRequest { - fn default() -> &'a PatchPcapRequest { - <PatchPcapRequest as ::protobuf::Message>::default_instance() +impl<'a> ::std::default::Default for &'a PatchCaptureRequest { + fn default() -> &'a PatchCaptureRequest { + <PatchCaptureRequest as ::protobuf::Message>::default_instance() } } -impl PatchPcapRequest { - pub fn new() -> PatchPcapRequest { +impl PatchCaptureRequest { + pub fn new() -> PatchCaptureRequest { ::std::default::Default::default() } @@ -983,24 +983,24 @@ impl PatchPcapRequest { let mut oneofs = ::std::vec::Vec::with_capacity(0); fields.push(::protobuf::reflect::rt::v2::make_simpler_field_accessor::<_, _>( "id", - |m: &PatchPcapRequest| { &m.id }, - |m: &mut PatchPcapRequest| { &mut m.id }, + |m: &PatchCaptureRequest| { &m.id }, + |m: &mut PatchCaptureRequest| { &mut m.id }, )); - fields.push(::protobuf::reflect::rt::v2::make_message_field_accessor::<_, patch_pcap_request::PcapPatch>( + fields.push(::protobuf::reflect::rt::v2::make_message_field_accessor::<_, patch_capture_request::PatchCapture>( "patch", - |m: &PatchPcapRequest| { &m.patch }, - |m: &mut PatchPcapRequest| { &mut m.patch }, + |m: &PatchCaptureRequest| { &m.patch }, + |m: &mut PatchCaptureRequest| { &mut m.patch }, )); - ::protobuf::reflect::GeneratedMessageDescriptorData::new_2::<PatchPcapRequest>( - "PatchPcapRequest", + ::protobuf::reflect::GeneratedMessageDescriptorData::new_2::<PatchCaptureRequest>( + "PatchCaptureRequest", fields, oneofs, ) } } -impl ::protobuf::Message for PatchPcapRequest { - const NAME: &'static str = "PatchPcapRequest"; +impl ::protobuf::Message for PatchCaptureRequest { + const NAME: &'static str = "PatchCaptureRequest"; fn is_initialized(&self) -> bool { true @@ -1058,8 +1058,8 @@ impl ::protobuf::Message for PatchPcapRequest { &mut self.special_fields } - fn new() -> PatchPcapRequest { - PatchPcapRequest::new() + fn new() -> PatchCaptureRequest { + PatchCaptureRequest::new() } fn clear(&mut self) { @@ -1068,8 +1068,8 @@ impl ::protobuf::Message for PatchPcapRequest { self.special_fields.clear(); } - fn default_instance() -> &'static PatchPcapRequest { - static instance: PatchPcapRequest = PatchPcapRequest { + fn default_instance() -> &'static PatchCaptureRequest { + static instance: PatchCaptureRequest = PatchCaptureRequest { id: 0, patch: ::protobuf::MessageField::none(), special_fields: ::protobuf::SpecialFields::new(), @@ -1078,44 +1078,44 @@ impl ::protobuf::Message for PatchPcapRequest { } } -impl ::protobuf::MessageFull for PatchPcapRequest { +impl ::protobuf::MessageFull for PatchCaptureRequest { fn descriptor() -> ::protobuf::reflect::MessageDescriptor { static descriptor: ::protobuf::rt::Lazy<::protobuf::reflect::MessageDescriptor> = ::protobuf::rt::Lazy::new(); - descriptor.get(|| file_descriptor().message_by_package_relative_name("PatchPcapRequest").unwrap()).clone() + descriptor.get(|| file_descriptor().message_by_package_relative_name("PatchCaptureRequest").unwrap()).clone() } } -impl ::std::fmt::Display for PatchPcapRequest { +impl ::std::fmt::Display for PatchCaptureRequest { fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { ::protobuf::text_format::fmt(self, f) } } -impl ::protobuf::reflect::ProtobufValue for PatchPcapRequest { +impl ::protobuf::reflect::ProtobufValue for PatchCaptureRequest { type RuntimeType = ::protobuf::reflect::rt::RuntimeTypeMessage<Self>; } -/// Nested message and enums of message `PatchPcapRequest` -pub mod patch_pcap_request { +/// Nested message and enums of message `PatchCaptureRequest` +pub mod patch_capture_request { #[derive(PartialEq,Clone,Default,Debug)] - // @@protoc_insertion_point(message:netsim.frontend.PatchPcapRequest.PcapPatch) - pub struct PcapPatch { + // @@protoc_insertion_point(message:netsim.frontend.PatchCaptureRequest.PatchCapture) + pub struct PatchCapture { // message fields - // @@protoc_insertion_point(field:netsim.frontend.PatchPcapRequest.PcapPatch.state) + // @@protoc_insertion_point(field:netsim.frontend.PatchCaptureRequest.PatchCapture.state) pub state: ::protobuf::EnumOrUnknown<super::super::model::State>, // special fields - // @@protoc_insertion_point(special_field:netsim.frontend.PatchPcapRequest.PcapPatch.special_fields) + // @@protoc_insertion_point(special_field:netsim.frontend.PatchCaptureRequest.PatchCapture.special_fields) pub special_fields: ::protobuf::SpecialFields, } - impl<'a> ::std::default::Default for &'a PcapPatch { - fn default() -> &'a PcapPatch { - <PcapPatch as ::protobuf::Message>::default_instance() + impl<'a> ::std::default::Default for &'a PatchCapture { + fn default() -> &'a PatchCapture { + <PatchCapture as ::protobuf::Message>::default_instance() } } - impl PcapPatch { - pub fn new() -> PcapPatch { + impl PatchCapture { + pub fn new() -> PatchCapture { ::std::default::Default::default() } @@ -1124,19 +1124,19 @@ pub mod patch_pcap_request { let mut oneofs = ::std::vec::Vec::with_capacity(0); fields.push(::protobuf::reflect::rt::v2::make_simpler_field_accessor::<_, _>( "state", - |m: &PcapPatch| { &m.state }, - |m: &mut PcapPatch| { &mut m.state }, + |m: &PatchCapture| { &m.state }, + |m: &mut PatchCapture| { &mut m.state }, )); - ::protobuf::reflect::GeneratedMessageDescriptorData::new_2::<PcapPatch>( - "PatchPcapRequest.PcapPatch", + ::protobuf::reflect::GeneratedMessageDescriptorData::new_2::<PatchCapture>( + "PatchCaptureRequest.PatchCapture", fields, oneofs, ) } } - impl ::protobuf::Message for PcapPatch { - const NAME: &'static str = "PcapPatch"; + impl ::protobuf::Message for PatchCapture { + const NAME: &'static str = "PatchCapture"; fn is_initialized(&self) -> bool { true @@ -1184,8 +1184,8 @@ pub mod patch_pcap_request { &mut self.special_fields } - fn new() -> PcapPatch { - PcapPatch::new() + fn new() -> PatchCapture { + PatchCapture::new() } fn clear(&mut self) { @@ -1193,8 +1193,8 @@ pub mod patch_pcap_request { self.special_fields.clear(); } - fn default_instance() -> &'static PcapPatch { - static instance: PcapPatch = PcapPatch { + fn default_instance() -> &'static PatchCapture { + static instance: PatchCapture = PatchCapture { state: ::protobuf::EnumOrUnknown::from_i32(0), special_fields: ::protobuf::SpecialFields::new(), }; @@ -1202,43 +1202,43 @@ pub mod patch_pcap_request { } } - impl ::protobuf::MessageFull for PcapPatch { + impl ::protobuf::MessageFull for PatchCapture { fn descriptor() -> ::protobuf::reflect::MessageDescriptor { static descriptor: ::protobuf::rt::Lazy<::protobuf::reflect::MessageDescriptor> = ::protobuf::rt::Lazy::new(); - descriptor.get(|| super::file_descriptor().message_by_package_relative_name("PatchPcapRequest.PcapPatch").unwrap()).clone() + descriptor.get(|| super::file_descriptor().message_by_package_relative_name("PatchCaptureRequest.PatchCapture").unwrap()).clone() } } - impl ::std::fmt::Display for PcapPatch { + impl ::std::fmt::Display for PatchCapture { fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { ::protobuf::text_format::fmt(self, f) } } - impl ::protobuf::reflect::ProtobufValue for PcapPatch { + impl ::protobuf::reflect::ProtobufValue for PatchCapture { type RuntimeType = ::protobuf::reflect::rt::RuntimeTypeMessage<Self>; } } #[derive(PartialEq,Clone,Default,Debug)] -// @@protoc_insertion_point(message:netsim.frontend.ListPcapResponse) -pub struct ListPcapResponse { +// @@protoc_insertion_point(message:netsim.frontend.ListCaptureResponse) +pub struct ListCaptureResponse { // message fields - // @@protoc_insertion_point(field:netsim.frontend.ListPcapResponse.pcaps) - pub pcaps: ::std::vec::Vec<super::model::Pcap>, + // @@protoc_insertion_point(field:netsim.frontend.ListCaptureResponse.captures) + pub captures: ::std::vec::Vec<super::model::Capture>, // special fields - // @@protoc_insertion_point(special_field:netsim.frontend.ListPcapResponse.special_fields) + // @@protoc_insertion_point(special_field:netsim.frontend.ListCaptureResponse.special_fields) pub special_fields: ::protobuf::SpecialFields, } -impl<'a> ::std::default::Default for &'a ListPcapResponse { - fn default() -> &'a ListPcapResponse { - <ListPcapResponse as ::protobuf::Message>::default_instance() +impl<'a> ::std::default::Default for &'a ListCaptureResponse { + fn default() -> &'a ListCaptureResponse { + <ListCaptureResponse as ::protobuf::Message>::default_instance() } } -impl ListPcapResponse { - pub fn new() -> ListPcapResponse { +impl ListCaptureResponse { + pub fn new() -> ListCaptureResponse { ::std::default::Default::default() } @@ -1246,20 +1246,20 @@ impl ListPcapResponse { let mut fields = ::std::vec::Vec::with_capacity(1); let mut oneofs = ::std::vec::Vec::with_capacity(0); fields.push(::protobuf::reflect::rt::v2::make_vec_simpler_accessor::<_, _>( - "pcaps", - |m: &ListPcapResponse| { &m.pcaps }, - |m: &mut ListPcapResponse| { &mut m.pcaps }, + "captures", + |m: &ListCaptureResponse| { &m.captures }, + |m: &mut ListCaptureResponse| { &mut m.captures }, )); - ::protobuf::reflect::GeneratedMessageDescriptorData::new_2::<ListPcapResponse>( - "ListPcapResponse", + ::protobuf::reflect::GeneratedMessageDescriptorData::new_2::<ListCaptureResponse>( + "ListCaptureResponse", fields, oneofs, ) } } -impl ::protobuf::Message for ListPcapResponse { - const NAME: &'static str = "ListPcapResponse"; +impl ::protobuf::Message for ListCaptureResponse { + const NAME: &'static str = "ListCaptureResponse"; fn is_initialized(&self) -> bool { true @@ -1269,7 +1269,7 @@ impl ::protobuf::Message for ListPcapResponse { while let Some(tag) = is.read_raw_tag_or_eof()? { match tag { 10 => { - self.pcaps.push(is.read_message()?); + self.captures.push(is.read_message()?); }, tag => { ::protobuf::rt::read_unknown_or_skip_group(tag, is, self.special_fields.mut_unknown_fields())?; @@ -1283,7 +1283,7 @@ impl ::protobuf::Message for ListPcapResponse { #[allow(unused_variables)] fn compute_size(&self) -> u64 { let mut my_size = 0; - for value in &self.pcaps { + for value in &self.captures { let len = value.compute_size(); my_size += 1 + ::protobuf::rt::compute_raw_varint64_size(len) + len; }; @@ -1293,7 +1293,7 @@ impl ::protobuf::Message for ListPcapResponse { } fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::Result<()> { - for v in &self.pcaps { + for v in &self.captures { ::protobuf::rt::write_message_field_with_cached_size(1, v, os)?; }; os.write_unknown_fields(self.special_fields.unknown_fields())?; @@ -1308,60 +1308,60 @@ impl ::protobuf::Message for ListPcapResponse { &mut self.special_fields } - fn new() -> ListPcapResponse { - ListPcapResponse::new() + fn new() -> ListCaptureResponse { + ListCaptureResponse::new() } fn clear(&mut self) { - self.pcaps.clear(); + self.captures.clear(); self.special_fields.clear(); } - fn default_instance() -> &'static ListPcapResponse { - static instance: ListPcapResponse = ListPcapResponse { - pcaps: ::std::vec::Vec::new(), + fn default_instance() -> &'static ListCaptureResponse { + static instance: ListCaptureResponse = ListCaptureResponse { + captures: ::std::vec::Vec::new(), special_fields: ::protobuf::SpecialFields::new(), }; &instance } } -impl ::protobuf::MessageFull for ListPcapResponse { +impl ::protobuf::MessageFull for ListCaptureResponse { fn descriptor() -> ::protobuf::reflect::MessageDescriptor { static descriptor: ::protobuf::rt::Lazy<::protobuf::reflect::MessageDescriptor> = ::protobuf::rt::Lazy::new(); - descriptor.get(|| file_descriptor().message_by_package_relative_name("ListPcapResponse").unwrap()).clone() + descriptor.get(|| file_descriptor().message_by_package_relative_name("ListCaptureResponse").unwrap()).clone() } } -impl ::std::fmt::Display for ListPcapResponse { +impl ::std::fmt::Display for ListCaptureResponse { fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { ::protobuf::text_format::fmt(self, f) } } -impl ::protobuf::reflect::ProtobufValue for ListPcapResponse { +impl ::protobuf::reflect::ProtobufValue for ListCaptureResponse { type RuntimeType = ::protobuf::reflect::rt::RuntimeTypeMessage<Self>; } #[derive(PartialEq,Clone,Default,Debug)] -// @@protoc_insertion_point(message:netsim.frontend.GetPcapRequest) -pub struct GetPcapRequest { +// @@protoc_insertion_point(message:netsim.frontend.GetCaptureRequest) +pub struct GetCaptureRequest { // message fields - // @@protoc_insertion_point(field:netsim.frontend.GetPcapRequest.id) + // @@protoc_insertion_point(field:netsim.frontend.GetCaptureRequest.id) pub id: i32, // special fields - // @@protoc_insertion_point(special_field:netsim.frontend.GetPcapRequest.special_fields) + // @@protoc_insertion_point(special_field:netsim.frontend.GetCaptureRequest.special_fields) pub special_fields: ::protobuf::SpecialFields, } -impl<'a> ::std::default::Default for &'a GetPcapRequest { - fn default() -> &'a GetPcapRequest { - <GetPcapRequest as ::protobuf::Message>::default_instance() +impl<'a> ::std::default::Default for &'a GetCaptureRequest { + fn default() -> &'a GetCaptureRequest { + <GetCaptureRequest as ::protobuf::Message>::default_instance() } } -impl GetPcapRequest { - pub fn new() -> GetPcapRequest { +impl GetCaptureRequest { + pub fn new() -> GetCaptureRequest { ::std::default::Default::default() } @@ -1370,19 +1370,19 @@ impl GetPcapRequest { let mut oneofs = ::std::vec::Vec::with_capacity(0); fields.push(::protobuf::reflect::rt::v2::make_simpler_field_accessor::<_, _>( "id", - |m: &GetPcapRequest| { &m.id }, - |m: &mut GetPcapRequest| { &mut m.id }, + |m: &GetCaptureRequest| { &m.id }, + |m: &mut GetCaptureRequest| { &mut m.id }, )); - ::protobuf::reflect::GeneratedMessageDescriptorData::new_2::<GetPcapRequest>( - "GetPcapRequest", + ::protobuf::reflect::GeneratedMessageDescriptorData::new_2::<GetCaptureRequest>( + "GetCaptureRequest", fields, oneofs, ) } } -impl ::protobuf::Message for GetPcapRequest { - const NAME: &'static str = "GetPcapRequest"; +impl ::protobuf::Message for GetCaptureRequest { + const NAME: &'static str = "GetCaptureRequest"; fn is_initialized(&self) -> bool { true @@ -1430,8 +1430,8 @@ impl ::protobuf::Message for GetPcapRequest { &mut self.special_fields } - fn new() -> GetPcapRequest { - GetPcapRequest::new() + fn new() -> GetCaptureRequest { + GetCaptureRequest::new() } fn clear(&mut self) { @@ -1439,8 +1439,8 @@ impl ::protobuf::Message for GetPcapRequest { self.special_fields.clear(); } - fn default_instance() -> &'static GetPcapRequest { - static instance: GetPcapRequest = GetPcapRequest { + fn default_instance() -> &'static GetCaptureRequest { + static instance: GetCaptureRequest = GetCaptureRequest { id: 0, special_fields: ::protobuf::SpecialFields::new(), }; @@ -1448,42 +1448,42 @@ impl ::protobuf::Message for GetPcapRequest { } } -impl ::protobuf::MessageFull for GetPcapRequest { +impl ::protobuf::MessageFull for GetCaptureRequest { fn descriptor() -> ::protobuf::reflect::MessageDescriptor { static descriptor: ::protobuf::rt::Lazy<::protobuf::reflect::MessageDescriptor> = ::protobuf::rt::Lazy::new(); - descriptor.get(|| file_descriptor().message_by_package_relative_name("GetPcapRequest").unwrap()).clone() + descriptor.get(|| file_descriptor().message_by_package_relative_name("GetCaptureRequest").unwrap()).clone() } } -impl ::std::fmt::Display for GetPcapRequest { +impl ::std::fmt::Display for GetCaptureRequest { fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { ::protobuf::text_format::fmt(self, f) } } -impl ::protobuf::reflect::ProtobufValue for GetPcapRequest { +impl ::protobuf::reflect::ProtobufValue for GetCaptureRequest { type RuntimeType = ::protobuf::reflect::rt::RuntimeTypeMessage<Self>; } #[derive(PartialEq,Clone,Default,Debug)] -// @@protoc_insertion_point(message:netsim.frontend.GetPcapResponse) -pub struct GetPcapResponse { +// @@protoc_insertion_point(message:netsim.frontend.GetCaptureResponse) +pub struct GetCaptureResponse { // message fields - // @@protoc_insertion_point(field:netsim.frontend.GetPcapResponse.capture_stream) + // @@protoc_insertion_point(field:netsim.frontend.GetCaptureResponse.capture_stream) pub capture_stream: ::std::vec::Vec<u8>, // special fields - // @@protoc_insertion_point(special_field:netsim.frontend.GetPcapResponse.special_fields) + // @@protoc_insertion_point(special_field:netsim.frontend.GetCaptureResponse.special_fields) pub special_fields: ::protobuf::SpecialFields, } -impl<'a> ::std::default::Default for &'a GetPcapResponse { - fn default() -> &'a GetPcapResponse { - <GetPcapResponse as ::protobuf::Message>::default_instance() +impl<'a> ::std::default::Default for &'a GetCaptureResponse { + fn default() -> &'a GetCaptureResponse { + <GetCaptureResponse as ::protobuf::Message>::default_instance() } } -impl GetPcapResponse { - pub fn new() -> GetPcapResponse { +impl GetCaptureResponse { + pub fn new() -> GetCaptureResponse { ::std::default::Default::default() } @@ -1492,19 +1492,19 @@ impl GetPcapResponse { let mut oneofs = ::std::vec::Vec::with_capacity(0); fields.push(::protobuf::reflect::rt::v2::make_simpler_field_accessor::<_, _>( "capture_stream", - |m: &GetPcapResponse| { &m.capture_stream }, - |m: &mut GetPcapResponse| { &mut m.capture_stream }, + |m: &GetCaptureResponse| { &m.capture_stream }, + |m: &mut GetCaptureResponse| { &mut m.capture_stream }, )); - ::protobuf::reflect::GeneratedMessageDescriptorData::new_2::<GetPcapResponse>( - "GetPcapResponse", + ::protobuf::reflect::GeneratedMessageDescriptorData::new_2::<GetCaptureResponse>( + "GetCaptureResponse", fields, oneofs, ) } } -impl ::protobuf::Message for GetPcapResponse { - const NAME: &'static str = "GetPcapResponse"; +impl ::protobuf::Message for GetCaptureResponse { + const NAME: &'static str = "GetCaptureResponse"; fn is_initialized(&self) -> bool { true @@ -1552,8 +1552,8 @@ impl ::protobuf::Message for GetPcapResponse { &mut self.special_fields } - fn new() -> GetPcapResponse { - GetPcapResponse::new() + fn new() -> GetCaptureResponse { + GetCaptureResponse::new() } fn clear(&mut self) { @@ -1561,8 +1561,8 @@ impl ::protobuf::Message for GetPcapResponse { self.special_fields.clear(); } - fn default_instance() -> &'static GetPcapResponse { - static instance: GetPcapResponse = GetPcapResponse { + fn default_instance() -> &'static GetCaptureResponse { + static instance: GetCaptureResponse = GetCaptureResponse { capture_stream: ::std::vec::Vec::new(), special_fields: ::protobuf::SpecialFields::new(), }; @@ -1570,20 +1570,20 @@ impl ::protobuf::Message for GetPcapResponse { } } -impl ::protobuf::MessageFull for GetPcapResponse { +impl ::protobuf::MessageFull for GetCaptureResponse { fn descriptor() -> ::protobuf::reflect::MessageDescriptor { static descriptor: ::protobuf::rt::Lazy<::protobuf::reflect::MessageDescriptor> = ::protobuf::rt::Lazy::new(); - descriptor.get(|| file_descriptor().message_by_package_relative_name("GetPcapResponse").unwrap()).clone() + descriptor.get(|| file_descriptor().message_by_package_relative_name("GetCaptureResponse").unwrap()).clone() } } -impl ::std::fmt::Display for GetPcapResponse { +impl ::std::fmt::Display for GetCaptureResponse { fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { ::protobuf::text_format::fmt(self, f) } } -impl ::protobuf::reflect::ProtobufValue for GetPcapResponse { +impl ::protobuf::reflect::ProtobufValue for GetCaptureResponse { type RuntimeType = ::protobuf::reflect::rt::RuntimeTypeMessage<Self>; } @@ -1759,30 +1759,30 @@ static file_descriptor_proto_data: &'static [u8] = b"\ \x14.netsim.model.DeviceR\x07devices\"&\n\x0cNetCatStream\x12\x16\n\x06r\ esult\x18\x01\x20\x03(\tR\x06result\"X\n\x17SetPacketCaptureRequest\x12\ \x18\n\x07capture\x18\x01\x20\x01(\x08R\x07capture\x12#\n\rdevice_serial\ - \x18\x02\x20\x01(\tR\x0cdeviceSerial\"\x9d\x01\n\x10PatchPcapRequest\x12\ - \x0e\n\x02id\x18\x01\x20\x01(\x05R\x02id\x12A\n\x05patch\x18\x02\x20\x01\ - (\x0b2+.netsim.frontend.PatchPcapRequest.PcapPatchR\x05patch\x1a6\n\tPca\ - pPatch\x12)\n\x05state\x18\x01\x20\x01(\x0e2\x13.netsim.model.StateR\x05\ - state\"<\n\x10ListPcapResponse\x12(\n\x05pcaps\x18\x01\x20\x03(\x0b2\x12\ - .netsim.model.PcapR\x05pcaps\"\x20\n\x0eGetPcapRequest\x12\x0e\n\x02id\ - \x18\x01\x20\x01(\x05R\x02id\"8\n\x0fGetPcapResponse\x12%\n\x0ecapture_s\ - tream\x18\x01\x20\x01(\x0cR\rcaptureStream\"`\n\rErrorResponse\x12\x12\n\ - \x04code\x18\x01\x20\x01(\x05R\x04code\x12#\n\rerror_message\x18\x02\x20\ - \x01(\tR\x0cerrorMessage\x12\x16\n\x06status\x18\x03\x20\x01(\tR\x06stat\ - us2\xdb\x05\n\x0fFrontendService\x12F\n\nGetVersion\x12\x16.google.proto\ - buf.Empty\x1a\x20.netsim.frontend.VersionResponse\x12B\n\x0eRegisterEven\ - ts\x12\x16.google.protobuf.Empty\x1a\x16.netsim.frontend.Event0\x01\x12I\ - \n\nGetDevices\x12\x16.google.protobuf.Empty\x1a#.netsim.frontend.GetDev\ - icesResponse\x12J\n\x0bPatchDevice\x12#.netsim.frontend.PatchDeviceReque\ - st\x1a\x16.google.protobuf.Empty\x127\n\x05Reset\x12\x16.google.protobuf\ - .Empty\x1a\x16.google.protobuf.Empty\x12J\n\x0bSetLinkLoss\x12#.netsim.f\ - rontend.SetLinkLossRequest\x1a\x16.google.protobuf.Empty\x12A\n\x06NetCa\ - t\x12\x16.google.protobuf.Empty\x1a\x1d.netsim.frontend.NetCatStream0\ - \x01\x12F\n\tPatchPcap\x12!.netsim.frontend.PatchPcapRequest\x1a\x16.goo\ - gle.protobuf.Empty\x12E\n\x08ListPcap\x12\x16.google.protobuf.Empty\x1a!\ - .netsim.frontend.ListPcapResponse\x12N\n\x07GetPcap\x12\x1f.netsim.front\ - end.GetPcapRequest\x1a\x20.netsim.frontend.GetPcapResponse0\x01b\x06prot\ - o3\ + \x18\x02\x20\x01(\tR\x0cdeviceSerial\"\xa9\x01\n\x13PatchCaptureRequest\ + \x12\x0e\n\x02id\x18\x01\x20\x01(\x05R\x02id\x12G\n\x05patch\x18\x02\x20\ + \x01(\x0b21.netsim.frontend.PatchCaptureRequest.PatchCaptureR\x05patch\ + \x1a9\n\x0cPatchCapture\x12)\n\x05state\x18\x01\x20\x01(\x0e2\x13.netsim\ + .model.StateR\x05state\"H\n\x13ListCaptureResponse\x121\n\x08captures\ + \x18\x01\x20\x03(\x0b2\x15.netsim.model.CaptureR\x08captures\"#\n\x11Get\ + CaptureRequest\x12\x0e\n\x02id\x18\x01\x20\x01(\x05R\x02id\";\n\x12GetCa\ + ptureResponse\x12%\n\x0ecapture_stream\x18\x01\x20\x01(\x0cR\rcaptureStr\ + eam\"`\n\rErrorResponse\x12\x12\n\x04code\x18\x01\x20\x01(\x05R\x04code\ + \x12#\n\rerror_message\x18\x02\x20\x01(\tR\x0cerrorMessage\x12\x16\n\x06\ + status\x18\x03\x20\x01(\tR\x06status2\xf0\x05\n\x0fFrontendService\x12F\ + \n\nGetVersion\x12\x16.google.protobuf.Empty\x1a\x20.netsim.frontend.Ver\ + sionResponse\x12B\n\x0eRegisterEvents\x12\x16.google.protobuf.Empty\x1a\ + \x16.netsim.frontend.Event0\x01\x12I\n\nGetDevices\x12\x16.google.protob\ + uf.Empty\x1a#.netsim.frontend.GetDevicesResponse\x12J\n\x0bPatchDevice\ + \x12#.netsim.frontend.PatchDeviceRequest\x1a\x16.google.protobuf.Empty\ + \x127\n\x05Reset\x12\x16.google.protobuf.Empty\x1a\x16.google.protobuf.E\ + mpty\x12J\n\x0bSetLinkLoss\x12#.netsim.frontend.SetLinkLossRequest\x1a\ + \x16.google.protobuf.Empty\x12A\n\x06NetCat\x12\x16.google.protobuf.Empt\ + y\x1a\x1d.netsim.frontend.NetCatStream0\x01\x12L\n\x0cPatchCapture\x12$.\ + netsim.frontend.PatchCaptureRequest\x1a\x16.google.protobuf.Empty\x12K\n\ + \x0bListCapture\x12\x16.google.protobuf.Empty\x1a$.netsim.frontend.ListC\ + aptureResponse\x12W\n\nGetCapture\x12\".netsim.frontend.GetCaptureReques\ + t\x1a#.netsim.frontend.GetCaptureResponse0\x01b\x06proto3\ "; /// `FileDescriptorProto` object which was a source for this generated file @@ -1810,12 +1810,12 @@ pub fn file_descriptor() -> &'static ::protobuf::reflect::FileDescriptor { messages.push(GetDevicesResponse::generated_message_descriptor_data()); messages.push(NetCatStream::generated_message_descriptor_data()); messages.push(SetPacketCaptureRequest::generated_message_descriptor_data()); - messages.push(PatchPcapRequest::generated_message_descriptor_data()); - messages.push(ListPcapResponse::generated_message_descriptor_data()); - messages.push(GetPcapRequest::generated_message_descriptor_data()); - messages.push(GetPcapResponse::generated_message_descriptor_data()); + messages.push(PatchCaptureRequest::generated_message_descriptor_data()); + messages.push(ListCaptureResponse::generated_message_descriptor_data()); + messages.push(GetCaptureRequest::generated_message_descriptor_data()); + messages.push(GetCaptureResponse::generated_message_descriptor_data()); messages.push(ErrorResponse::generated_message_descriptor_data()); - messages.push(patch_pcap_request::PcapPatch::generated_message_descriptor_data()); + messages.push(patch_capture_request::PatchCapture::generated_message_descriptor_data()); let mut enums = ::std::vec::Vec::with_capacity(0); ::protobuf::reflect::GeneratedFileDescriptor::new_generated( file_descriptor_proto(), diff --git a/rust/frontend-proto/src/model.rs b/rust/frontend-proto/src/model.rs index b94949ab..370bf067 100644 --- a/rust/frontend-proto/src/model.rs +++ b/rust/frontend-proto/src/model.rs @@ -1454,101 +1454,94 @@ impl ::protobuf::reflect::ProtobufValue for Scene { } #[derive(PartialEq,Clone,Default,Debug)] -// @@protoc_insertion_point(message:netsim.model.Pcap) -pub struct Pcap { +// @@protoc_insertion_point(message:netsim.model.Capture) +pub struct Capture { // message fields - // @@protoc_insertion_point(field:netsim.model.Pcap.id) + // @@protoc_insertion_point(field:netsim.model.Capture.id) pub id: i32, - // @@protoc_insertion_point(field:netsim.model.Pcap.chip_kind) + // @@protoc_insertion_point(field:netsim.model.Capture.chip_kind) pub chip_kind: ::protobuf::EnumOrUnknown<super::common::ChipKind>, - // @@protoc_insertion_point(field:netsim.model.Pcap.chip_id) - pub chip_id: i32, - // @@protoc_insertion_point(field:netsim.model.Pcap.device_name) + // @@protoc_insertion_point(field:netsim.model.Capture.device_name) pub device_name: ::std::string::String, - // @@protoc_insertion_point(field:netsim.model.Pcap.state) + // @@protoc_insertion_point(field:netsim.model.Capture.state) pub state: ::protobuf::EnumOrUnknown<State>, - // @@protoc_insertion_point(field:netsim.model.Pcap.size) + // @@protoc_insertion_point(field:netsim.model.Capture.size) pub size: i32, - // @@protoc_insertion_point(field:netsim.model.Pcap.records) + // @@protoc_insertion_point(field:netsim.model.Capture.records) pub records: i32, - // @@protoc_insertion_point(field:netsim.model.Pcap.timestamp) + // @@protoc_insertion_point(field:netsim.model.Capture.timestamp) pub timestamp: ::protobuf::MessageField<::protobuf::well_known_types::timestamp::Timestamp>, - // @@protoc_insertion_point(field:netsim.model.Pcap.valid) + // @@protoc_insertion_point(field:netsim.model.Capture.valid) pub valid: bool, // special fields - // @@protoc_insertion_point(special_field:netsim.model.Pcap.special_fields) + // @@protoc_insertion_point(special_field:netsim.model.Capture.special_fields) pub special_fields: ::protobuf::SpecialFields, } -impl<'a> ::std::default::Default for &'a Pcap { - fn default() -> &'a Pcap { - <Pcap as ::protobuf::Message>::default_instance() +impl<'a> ::std::default::Default for &'a Capture { + fn default() -> &'a Capture { + <Capture as ::protobuf::Message>::default_instance() } } -impl Pcap { - pub fn new() -> Pcap { +impl Capture { + pub fn new() -> Capture { ::std::default::Default::default() } fn generated_message_descriptor_data() -> ::protobuf::reflect::GeneratedMessageDescriptorData { - let mut fields = ::std::vec::Vec::with_capacity(9); + let mut fields = ::std::vec::Vec::with_capacity(8); let mut oneofs = ::std::vec::Vec::with_capacity(0); fields.push(::protobuf::reflect::rt::v2::make_simpler_field_accessor::<_, _>( "id", - |m: &Pcap| { &m.id }, - |m: &mut Pcap| { &mut m.id }, + |m: &Capture| { &m.id }, + |m: &mut Capture| { &mut m.id }, )); fields.push(::protobuf::reflect::rt::v2::make_simpler_field_accessor::<_, _>( "chip_kind", - |m: &Pcap| { &m.chip_kind }, - |m: &mut Pcap| { &mut m.chip_kind }, - )); - fields.push(::protobuf::reflect::rt::v2::make_simpler_field_accessor::<_, _>( - "chip_id", - |m: &Pcap| { &m.chip_id }, - |m: &mut Pcap| { &mut m.chip_id }, + |m: &Capture| { &m.chip_kind }, + |m: &mut Capture| { &mut m.chip_kind }, )); fields.push(::protobuf::reflect::rt::v2::make_simpler_field_accessor::<_, _>( "device_name", - |m: &Pcap| { &m.device_name }, - |m: &mut Pcap| { &mut m.device_name }, + |m: &Capture| { &m.device_name }, + |m: &mut Capture| { &mut m.device_name }, )); fields.push(::protobuf::reflect::rt::v2::make_simpler_field_accessor::<_, _>( "state", - |m: &Pcap| { &m.state }, - |m: &mut Pcap| { &mut m.state }, + |m: &Capture| { &m.state }, + |m: &mut Capture| { &mut m.state }, )); fields.push(::protobuf::reflect::rt::v2::make_simpler_field_accessor::<_, _>( "size", - |m: &Pcap| { &m.size }, - |m: &mut Pcap| { &mut m.size }, + |m: &Capture| { &m.size }, + |m: &mut Capture| { &mut m.size }, )); fields.push(::protobuf::reflect::rt::v2::make_simpler_field_accessor::<_, _>( "records", - |m: &Pcap| { &m.records }, - |m: &mut Pcap| { &mut m.records }, + |m: &Capture| { &m.records }, + |m: &mut Capture| { &mut m.records }, )); fields.push(::protobuf::reflect::rt::v2::make_message_field_accessor::<_, ::protobuf::well_known_types::timestamp::Timestamp>( "timestamp", - |m: &Pcap| { &m.timestamp }, - |m: &mut Pcap| { &mut m.timestamp }, + |m: &Capture| { &m.timestamp }, + |m: &mut Capture| { &mut m.timestamp }, )); fields.push(::protobuf::reflect::rt::v2::make_simpler_field_accessor::<_, _>( "valid", - |m: &Pcap| { &m.valid }, - |m: &mut Pcap| { &mut m.valid }, + |m: &Capture| { &m.valid }, + |m: &mut Capture| { &mut m.valid }, )); - ::protobuf::reflect::GeneratedMessageDescriptorData::new_2::<Pcap>( - "Pcap", + ::protobuf::reflect::GeneratedMessageDescriptorData::new_2::<Capture>( + "Capture", fields, oneofs, ) } } -impl ::protobuf::Message for Pcap { - const NAME: &'static str = "Pcap"; +impl ::protobuf::Message for Capture { + const NAME: &'static str = "Capture"; fn is_initialized(&self) -> bool { true @@ -1563,25 +1556,22 @@ impl ::protobuf::Message for Pcap { 16 => { self.chip_kind = is.read_enum_or_unknown()?; }, - 24 => { - self.chip_id = is.read_int32()?; - }, - 34 => { + 26 => { self.device_name = is.read_string()?; }, - 40 => { + 32 => { self.state = is.read_enum_or_unknown()?; }, - 48 => { + 40 => { self.size = is.read_int32()?; }, - 56 => { + 48 => { self.records = is.read_int32()?; }, - 66 => { + 58 => { ::protobuf::rt::read_singular_message_into_field(is, &mut self.timestamp)?; }, - 72 => { + 64 => { self.valid = is.read_bool()?; }, tag => { @@ -1602,20 +1592,17 @@ impl ::protobuf::Message for Pcap { if self.chip_kind != ::protobuf::EnumOrUnknown::new(super::common::ChipKind::UNSPECIFIED) { my_size += ::protobuf::rt::int32_size(2, self.chip_kind.value()); } - if self.chip_id != 0 { - my_size += ::protobuf::rt::int32_size(3, self.chip_id); - } if !self.device_name.is_empty() { - my_size += ::protobuf::rt::string_size(4, &self.device_name); + my_size += ::protobuf::rt::string_size(3, &self.device_name); } if self.state != ::protobuf::EnumOrUnknown::new(State::UNKNOWN) { - my_size += ::protobuf::rt::int32_size(5, self.state.value()); + my_size += ::protobuf::rt::int32_size(4, self.state.value()); } if self.size != 0 { - my_size += ::protobuf::rt::int32_size(6, self.size); + my_size += ::protobuf::rt::int32_size(5, self.size); } if self.records != 0 { - my_size += ::protobuf::rt::int32_size(7, self.records); + my_size += ::protobuf::rt::int32_size(6, self.records); } if let Some(v) = self.timestamp.as_ref() { let len = v.compute_size(); @@ -1636,26 +1623,23 @@ impl ::protobuf::Message for Pcap { if self.chip_kind != ::protobuf::EnumOrUnknown::new(super::common::ChipKind::UNSPECIFIED) { os.write_enum(2, ::protobuf::EnumOrUnknown::value(&self.chip_kind))?; } - if self.chip_id != 0 { - os.write_int32(3, self.chip_id)?; - } if !self.device_name.is_empty() { - os.write_string(4, &self.device_name)?; + os.write_string(3, &self.device_name)?; } if self.state != ::protobuf::EnumOrUnknown::new(State::UNKNOWN) { - os.write_enum(5, ::protobuf::EnumOrUnknown::value(&self.state))?; + os.write_enum(4, ::protobuf::EnumOrUnknown::value(&self.state))?; } if self.size != 0 { - os.write_int32(6, self.size)?; + os.write_int32(5, self.size)?; } if self.records != 0 { - os.write_int32(7, self.records)?; + os.write_int32(6, self.records)?; } if let Some(v) = self.timestamp.as_ref() { - ::protobuf::rt::write_message_field_with_cached_size(8, v, os)?; + ::protobuf::rt::write_message_field_with_cached_size(7, v, os)?; } if self.valid != false { - os.write_bool(9, self.valid)?; + os.write_bool(8, self.valid)?; } os.write_unknown_fields(self.special_fields.unknown_fields())?; ::std::result::Result::Ok(()) @@ -1669,14 +1653,13 @@ impl ::protobuf::Message for Pcap { &mut self.special_fields } - fn new() -> Pcap { - Pcap::new() + fn new() -> Capture { + Capture::new() } fn clear(&mut self) { self.id = 0; self.chip_kind = ::protobuf::EnumOrUnknown::new(super::common::ChipKind::UNSPECIFIED); - self.chip_id = 0; self.device_name.clear(); self.state = ::protobuf::EnumOrUnknown::new(State::UNKNOWN); self.size = 0; @@ -1686,11 +1669,10 @@ impl ::protobuf::Message for Pcap { self.special_fields.clear(); } - fn default_instance() -> &'static Pcap { - static instance: Pcap = Pcap { + fn default_instance() -> &'static Capture { + static instance: Capture = Capture { id: 0, chip_kind: ::protobuf::EnumOrUnknown::from_i32(0), - chip_id: 0, device_name: ::std::string::String::new(), state: ::protobuf::EnumOrUnknown::from_i32(0), size: 0, @@ -1703,20 +1685,20 @@ impl ::protobuf::Message for Pcap { } } -impl ::protobuf::MessageFull for Pcap { +impl ::protobuf::MessageFull for Capture { fn descriptor() -> ::protobuf::reflect::MessageDescriptor { static descriptor: ::protobuf::rt::Lazy<::protobuf::reflect::MessageDescriptor> = ::protobuf::rt::Lazy::new(); - descriptor.get(|| file_descriptor().message_by_package_relative_name("Pcap").unwrap()).clone() + descriptor.get(|| file_descriptor().message_by_package_relative_name("Capture").unwrap()).clone() } } -impl ::std::fmt::Display for Pcap { +impl ::std::fmt::Display for Capture { fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { ::protobuf::text_format::fmt(self, f) } } -impl ::protobuf::reflect::ProtobufValue for Pcap { +impl ::protobuf::reflect::ProtobufValue for Capture { type RuntimeType = ::protobuf::reflect::rt::RuntimeTypeMessage<Self>; } @@ -1876,19 +1858,18 @@ static file_descriptor_proto_data: &'static [u8] = b"\ orientation\x18\x05\x20\x01(\x0b2\x19.netsim.model.OrientationR\x0borien\ tation\x12(\n\x05chips\x18\x06\x20\x03(\x0b2\x12.netsim.model.ChipR\x05c\ hips\"7\n\x05Scene\x12.\n\x07devices\x18\x01\x20\x03(\x0b2\x14.netsim.mo\ - del.DeviceR\x07devices\"\xaf\x02\n\x04Pcap\x12\x0e\n\x02id\x18\x01\x20\ - \x01(\x05R\x02id\x124\n\tchip_kind\x18\x02\x20\x01(\x0e2\x17.netsim.comm\ - on.ChipKindR\x08chipKind\x12\x17\n\x07chip_id\x18\x03\x20\x01(\x05R\x06c\ - hipId\x12\x1f\n\x0bdevice_name\x18\x04\x20\x01(\tR\ndeviceName\x12)\n\ - \x05state\x18\x05\x20\x01(\x0e2\x13.netsim.model.StateR\x05state\x12\x12\ - \n\x04size\x18\x06\x20\x01(\x05R\x04size\x12\x18\n\x07records\x18\x07\ - \x20\x01(\x05R\x07records\x128\n\ttimestamp\x18\x08\x20\x01(\x0b2\x1a.go\ - ogle.protobuf.TimestampR\ttimestamp\x12\x14\n\x05valid\x18\t\x20\x01(\ - \x08R\x05valid*e\n\x07PhyKind\x12\x08\n\x04NONE\x10\0\x12\x15\n\x11BLUET\ - OOTH_CLASSIC\x10\x01\x12\x18\n\x14BLUETOOTH_LOW_ENERGY\x10\x02\x12\x08\n\ - \x04WIFI\x10\x03\x12\x07\n\x03UWB\x10\x04\x12\x0c\n\x08WIFI_RTT\x10\x05*\ - %\n\x05State\x12\x0b\n\x07UNKNOWN\x10\0\x12\x06\n\x02ON\x10\x01\x12\x07\ - \n\x03OFF\x10\x02b\x06proto3\ + del.DeviceR\x07devices\"\x99\x02\n\x07Capture\x12\x0e\n\x02id\x18\x01\ + \x20\x01(\x05R\x02id\x124\n\tchip_kind\x18\x02\x20\x01(\x0e2\x17.netsim.\ + common.ChipKindR\x08chipKind\x12\x1f\n\x0bdevice_name\x18\x03\x20\x01(\t\ + R\ndeviceName\x12)\n\x05state\x18\x04\x20\x01(\x0e2\x13.netsim.model.Sta\ + teR\x05state\x12\x12\n\x04size\x18\x05\x20\x01(\x05R\x04size\x12\x18\n\ + \x07records\x18\x06\x20\x01(\x05R\x07records\x128\n\ttimestamp\x18\x07\ + \x20\x01(\x0b2\x1a.google.protobuf.TimestampR\ttimestamp\x12\x14\n\x05va\ + lid\x18\x08\x20\x01(\x08R\x05valid*e\n\x07PhyKind\x12\x08\n\x04NONE\x10\ + \0\x12\x15\n\x11BLUETOOTH_CLASSIC\x10\x01\x12\x18\n\x14BLUETOOTH_LOW_ENE\ + RGY\x10\x02\x12\x08\n\x04WIFI\x10\x03\x12\x07\n\x03UWB\x10\x04\x12\x0c\n\ + \x08WIFI_RTT\x10\x05*%\n\x05State\x12\x0b\n\x07UNKNOWN\x10\0\x12\x06\n\ + \x02ON\x10\x01\x12\x07\n\x03OFF\x10\x02b\x06proto3\ "; /// `FileDescriptorProto` object which was a source for this generated file @@ -1914,7 +1895,7 @@ pub fn file_descriptor() -> &'static ::protobuf::reflect::FileDescriptor { messages.push(Chip::generated_message_descriptor_data()); messages.push(Device::generated_message_descriptor_data()); messages.push(Scene::generated_message_descriptor_data()); - messages.push(Pcap::generated_message_descriptor_data()); + messages.push(Capture::generated_message_descriptor_data()); messages.push(chip::Radio::generated_message_descriptor_data()); messages.push(chip::Bluetooth::generated_message_descriptor_data()); let mut enums = ::std::vec::Vec::with_capacity(2); diff --git a/rust/netsim-cli/src/args.rs b/rust/netsim-cli/src/args.rs index d04b0503..5cae64e6 100644 --- a/rust/netsim-cli/src/args.rs +++ b/rust/netsim-cli/src/args.rs @@ -16,7 +16,7 @@ use clap::{Args, Parser, Subcommand, ValueEnum}; use frontend_client_cxx::ffi::{FrontendClient, GrpcMethod}; use frontend_proto::common::ChipKind; use frontend_proto::frontend; -use frontend_proto::frontend::patch_pcap_request::PcapPatch; +use frontend_proto::frontend::patch_capture_request::PatchCapture as PatchCaptureProto; use frontend_proto::model; use frontend_proto::model::chip::{Bluetooth as Chip_Bluetooth, Radio as Chip_Radio}; use frontend_proto::model::{Chip, State}; @@ -137,39 +137,39 @@ impl Command { match self { Command::Pcap(Pcap::Patch(cmd)) => { let mut reqs = Vec::new(); - let filtered_pcaps = Self::get_filtered_pcaps(client, &cmd.patterns); - // Create a request for each pcap - for pcap in &filtered_pcaps { - let mut result = frontend::PatchPcapRequest::new(); - result.id = pcap.id; + let filtered_captures = Self::get_filtered_captures(client, &cmd.patterns); + // Create a request for each capture + for capture in &filtered_captures { + let mut result = frontend::PatchCaptureRequest::new(); + result.id = capture.id; let capture_state = match cmd.state { OnOffState::On => State::ON, OnOffState::Off => State::OFF, }; - let mut pcap_patch = PcapPatch::new(); - pcap_patch.state = capture_state.into(); - result.patch = Some(pcap_patch).into(); + let mut patch_capture = PatchCaptureProto::new(); + patch_capture.state = capture_state.into(); + result.patch = Some(patch_capture).into(); reqs.push(result.write_to_bytes().unwrap()) } reqs } Command::Pcap(Pcap::Get(cmd)) => { let mut reqs = Vec::new(); - let filtered_pcaps = Self::get_filtered_pcaps(client, &cmd.patterns); - // Create a request for each pcap - for pcap in &filtered_pcaps { - let mut result = frontend::GetPcapRequest::new(); - result.id = pcap.id; + let filtered_captures = Self::get_filtered_captures(client, &cmd.patterns); + // Create a request for each capture + for capture in &filtered_captures { + let mut result = frontend::GetCaptureRequest::new(); + result.id = capture.id; reqs.push(result.write_to_bytes().unwrap()); let time_display = TimeDisplay::new( - pcap.timestamp.get_or_default().seconds, - pcap.timestamp.get_or_default().nanos as u32, + capture.timestamp.get_or_default().seconds, + capture.timestamp.get_or_default().nanos as u32, ); cmd.filenames.push(format!( "{:?}-{}-{}-{}", - pcap.id, - pcap.device_name.to_owned().replace(' ', "_"), - Self::chip_kind_to_string(pcap.chip_kind.enum_value_or_default()), + capture.id, + capture.device_name.to_owned().replace(' ', "_"), + Self::chip_kind_to_string(capture.chip_kind.enum_value_or_default()), time_display.utc_display() )); } @@ -183,23 +183,23 @@ impl Command { } } - fn get_filtered_pcaps( + fn get_filtered_captures( client: &cxx::UniquePtr<FrontendClient>, patterns: &Vec<String>, - ) -> Vec<model::Pcap> { - // Get list of pcaps - let result = client.send_grpc(&GrpcMethod::ListPcap, &Vec::new()); + ) -> Vec<model::Capture> { + // Get list of captures + let result = client.send_grpc(&GrpcMethod::ListCapture, &Vec::new()); if !result.is_ok() { eprintln!("Grpc call error: {}", result.err()); return Vec::new(); } let mut response = - frontend::ListPcapResponse::parse_from_bytes(result.byte_vec().as_slice()).unwrap(); + frontend::ListCaptureResponse::parse_from_bytes(result.byte_vec().as_slice()).unwrap(); if !patterns.is_empty() { - // Filter out list of pcaps with matching patterns - Self::filter_pcaps(&mut response.pcaps, patterns) + // Filter out list of captures with matching patterns + Self::filter_captures(&mut response.captures, patterns) } - response.pcaps + response.captures } } @@ -268,34 +268,34 @@ pub enum OnOffState { #[derive(Debug, Subcommand)] pub enum Pcap { - /// List currently available Pcaps (packet captures) - List(ListPcap), - /// Patch a Pcap source to turn packet capture on/off - Patch(PatchPcap), + /// List currently available Captures (packet captures) + List(ListCapture), + /// Patch a Capture source to turn packet capture on/off + Patch(PatchCapture), /// Download the packet capture content - Get(GetPcap), + Get(GetCapture), } #[derive(Debug, Args)] -pub struct ListPcap { - /// Optional strings of pattern for pcaps to list. Possible filter fields include Pcap ID, Device Name, and Chip Kind +pub struct ListCapture { + /// Optional strings of pattern for captures to list. Possible filter fields include Capture ID, Device Name, and Chip Kind pub patterns: Vec<String>, } #[derive(Debug, Args)] -pub struct PatchPcap { +pub struct PatchCapture { /// Packet capture state #[arg(value_enum, ignore_case = true)] pub state: OnOffState, - /// Optional strings of pattern for pcaps to patch. Possible filter fields include Pcap ID, Device Name, and Chip Kind + /// Optional strings of pattern for captures to patch. Possible filter fields include Capture ID, Device Name, and Chip Kind pub patterns: Vec<String>, } #[derive(Debug, Args)] -pub struct GetPcap { - /// Optional strings of pattern for pcaps to get. Possible filter fields include Pcap ID, Device Name, and Chip Kind +pub struct GetCapture { + /// Optional strings of pattern for captures to get. Possible filter fields include Capture ID, Device Name, and Chip Kind pub patterns: Vec<String>, - /// Directory to store downloaded pcap(s) + /// Directory to store downloaded capture(s) #[arg(short = 'o', long)] pub location: Option<String>, #[arg(skip)] diff --git a/rust/netsim-cli/src/lib.rs b/rust/netsim-cli/src/lib.rs index 3b15f310..a2f382c9 100644 --- a/rust/netsim-cli/src/lib.rs +++ b/rust/netsim-cli/src/lib.rs @@ -24,17 +24,17 @@ use std::env; use std::fs::File; use std::path::PathBuf; -use args::{BinaryProtobuf, GetPcap, NetsimArgs}; +use args::{BinaryProtobuf, GetCapture, NetsimArgs}; use clap::Parser; use cxx::UniquePtr; use frontend_client_cxx::ffi::{new_frontend_client, ClientResult, FrontendClient, GrpcMethod}; use frontend_client_cxx::ClientResponseReader; -use pcap_handler::PcapHandler; +use pcap_handler::CaptureHandler; // helper function to process streaming Grpc request fn perform_streaming_request( client: &cxx::UniquePtr<FrontendClient>, - cmd: &GetPcap, + cmd: &GetCapture, req: &BinaryProtobuf, filename: &str, ) -> UniquePtr<ClientResult> { @@ -50,10 +50,10 @@ fn perform_streaming_request( idx += 1; output_file = dir.join(format!("{}_{}.pcap", filename, idx)); } - client.get_pcap( + client.get_capture( req, &ClientResponseReader { - handler: Box::new(PcapHandler { + handler: Box::new(CaptureHandler { file: File::create(&output_file).unwrap_or_else(|_| { panic!("Failed to create file: {}", &output_file.display()) }), diff --git a/rust/netsim-cli/src/pcap_handler.rs b/rust/netsim-cli/src/pcap_handler.rs index eaa8af50..e28349d6 100644 --- a/rust/netsim-cli/src/pcap_handler.rs +++ b/rust/netsim-cli/src/pcap_handler.rs @@ -18,12 +18,12 @@ use std::fs::File; use std::io::Write; use std::path::PathBuf; -pub struct PcapHandler { +pub struct CaptureHandler { pub file: File, pub path: PathBuf, } -impl ClientResponseReadable for PcapHandler { +impl ClientResponseReadable for CaptureHandler { // function to handle writing each chunk to file fn handle_chunk(&self, chunk: &[u8]) { (&self.file) diff --git a/rust/netsim-cli/src/requests.rs b/rust/netsim-cli/src/requests.rs index 4ebf4a7c..e2d3f399 100644 --- a/rust/netsim-cli/src/requests.rs +++ b/rust/netsim-cli/src/requests.rs @@ -25,9 +25,9 @@ impl args::Command { Command::Devices(_) => GrpcMethod::GetDevices, Command::Reset => GrpcMethod::Reset, Command::Pcap(cmd) => match cmd { - args::Pcap::List(_) => GrpcMethod::ListPcap, - args::Pcap::Get(_) => GrpcMethod::GetPcap, - args::Pcap::Patch(_) => GrpcMethod::PatchPcap, + args::Pcap::List(_) => GrpcMethod::ListCapture, + args::Pcap::Get(_) => GrpcMethod::GetCapture, + args::Pcap::Patch(_) => GrpcMethod::PatchCapture, }, Command::Gui => { panic!("No GrpcMethod for Ui Command."); @@ -242,7 +242,7 @@ mod tests { #[test] fn test_pcap_list() { - test_command("netsim-cli pcap list", GrpcMethod::ListPcap, Vec::new()) + test_command("netsim-cli pcap list", GrpcMethod::ListCapture, Vec::new()) } //TODO: Add pcap patch and get tests once able to run tests with cxx definitions diff --git a/rust/netsim-cli/src/response.rs b/rust/netsim-cli/src/response.rs index 17662fa8..3f626e0b 100644 --- a/rust/netsim-cli/src/response.rs +++ b/rust/netsim-cli/src/response.rs @@ -17,7 +17,7 @@ use std::cmp::max; use crate::args::{self, Command, OnOffState, Pcap}; use frontend_proto::{ common::ChipKind, - frontend::{GetDevicesResponse, ListPcapResponse, VersionResponse}, + frontend::{GetDevicesResponse, ListCaptureResponse, VersionResponse}, model::{self, chip::Chip as Chip_oneof_chip, State}, }; use protobuf::Message; @@ -61,14 +61,17 @@ impl args::Command { println!("All devices have been reset."); } } - Command::Pcap(Pcap::List(cmd)) => Self::print_list_pcap_response( - ListPcapResponse::parse_from_bytes(response).unwrap(), + Command::Pcap(Pcap::List(cmd)) => Self::print_list_capture_response( + ListCaptureResponse::parse_from_bytes(response).unwrap(), verbose, cmd.patterns.to_owned(), ), Command::Pcap(Pcap::Patch(cmd)) => { if verbose { - println!("Patched Pcap state to {}", Self::on_off_state_to_string(cmd.state),); + println!( + "Patched Capture state to {}", + Self::on_off_state_to_string(cmd.state), + ); } } Command::Pcap(Pcap::Get(_)) => { @@ -260,30 +263,30 @@ impl args::Command { println!("Netsim version: {}", response.version); } - /// Helper function to format and print ListPcapResponse - fn print_list_pcap_response( - mut response: ListPcapResponse, + /// Helper function to format and print ListCaptureResponse + fn print_list_capture_response( + mut response: ListCaptureResponse, verbose: bool, patterns: Vec<String>, ) { - if response.pcaps.is_empty() { + if response.captures.is_empty() { if verbose { - println!("No available Pcap found."); + println!("No available Capture found."); } return; } if patterns.is_empty() { - println!("List of Pcaps:"); + println!("List of Captures:"); } else { - // Filter out list of pcaps with matching patterns - Self::filter_pcaps(&mut response.pcaps, &patterns); - if response.pcaps.is_empty() { + // Filter out list of captures with matching patterns + Self::filter_captures(&mut response.captures, &patterns); + if response.captures.is_empty() { if verbose { - println!("No available Pcap found matching pattern(s) `{:?}`:", patterns); + println!("No available Capture found matching pattern(s) `{:?}`:", patterns); } return; } - println!("List of Pcaps matching pattern(s) `{:?}`:", patterns); + println!("List of Captures matching pattern(s) `{:?}`:", patterns); } // Create the header row and determine column widths let id_hdr = "ID"; @@ -291,25 +294,25 @@ impl args::Command { let chipkind_hdr = "Chip Kind"; let state_hdr = "State"; let size_hdr = "Size"; - let id_width = 4; // ID width of 4 since Pcap id starts at 4000 + let id_width = 4; // ID width of 4 since capture id (=chip_id) starts at 1000 let state_width = 7; // State width of 7 for 'unknown' let chipkind_width = 11; // ChipKind width 11 for 'UNSPECIFIED' let name_width = max( - (response.pcaps.iter().max_by_key(|x| x.device_name.len())) + (response.captures.iter().max_by_key(|x| x.device_name.len())) .unwrap_or_default() .device_name .len(), name_hdr.len(), ); let size_width = max( - (response.pcaps.iter().max_by_key(|x| x.size)) + (response.captures.iter().max_by_key(|x| x.size)) .unwrap_or_default() .size .to_string() .len(), size_hdr.len(), ); - // Print header for pcap list + // Print header for capture list println!( "{}", if verbose { @@ -327,25 +330,25 @@ impl args::Command { ) } ); - // Print information of each Pcap - for pcap in &response.pcaps { + // Print information of each Capture + for capture in &response.captures { println!( "{}", if verbose { format!("{:id_width$} | {:name_width$} | {:chipkind_width$} | {:state_width$} | {:size_width$} |", - pcap.id.to_string(), - pcap.device_name, - Self::chip_kind_to_string(pcap.chip_kind.enum_value_or_default()), - Self::capture_state_to_string(pcap.state.enum_value_or_default()), - pcap.size, + capture.id.to_string(), + capture.device_name, + Self::chip_kind_to_string(capture.chip_kind.enum_value_or_default()), + Self::capture_state_to_string(capture.state.enum_value_or_default()), + capture.size, ) } else { format!( "{:name_width$} | {:chipkind_width$} | {:state_width$} | {:size_width$} |", - pcap.device_name, - Self::chip_kind_to_string(pcap.chip_kind.enum_value_or_default()), - Self::capture_state_to_string(pcap.state.enum_value_or_default()), - pcap.size, + capture.device_name, + Self::chip_kind_to_string(capture.chip_kind.enum_value_or_default()), + Self::capture_state_to_string(capture.state.enum_value_or_default()), + capture.size, ) } ); @@ -361,13 +364,13 @@ impl args::Command { } } - pub fn filter_pcaps(pcaps: &mut Vec<model::Pcap>, keys: &[String]) { - // Filter out list of pcaps with matching pattern - pcaps.retain(|pcap| { + pub fn filter_captures(captures: &mut Vec<model::Capture>, keys: &[String]) { + // Filter out list of captures with matching pattern + captures.retain(|capture| { keys.iter().map(|key| key.to_uppercase()).all(|key| { - pcap.id.to_string().contains(&key) - || pcap.device_name.to_uppercase().contains(&key) - || Self::chip_kind_to_string(pcap.chip_kind.enum_value_or_default()) + capture.id.to_string().contains(&key) + || capture.device_name.to_uppercase().contains(&key) + || Self::chip_kind_to_string(capture.chip_kind.enum_value_or_default()) .contains(&key) }) }); @@ -377,107 +380,113 @@ impl args::Command { #[cfg(test)] mod tests { use super::*; - fn test_filter_pcaps_helper(patterns: Vec<String>, expected_pcaps: Vec<model::Pcap>) { - let mut pcaps = all_test_pcaps(); - Command::filter_pcaps(&mut pcaps, &patterns); - assert_eq!(pcaps, expected_pcaps); + fn test_filter_captures_helper(patterns: Vec<String>, expected_captures: Vec<model::Capture>) { + let mut captures = all_test_captures(); + Command::filter_captures(&mut captures, &patterns); + assert_eq!(captures, expected_captures); } - fn pcap_1() -> model::Pcap { - model::Pcap { + fn capture_1() -> model::Capture { + model::Capture { id: 4001, chip_kind: ChipKind::BLUETOOTH.into(), device_name: "device 1".to_string(), ..Default::default() } } - fn pcap_1_wifi() -> model::Pcap { - model::Pcap { + fn capture_1_wifi() -> model::Capture { + model::Capture { id: 4002, chip_kind: ChipKind::WIFI.into(), device_name: "device 1".to_string(), ..Default::default() } } - fn pcap_2() -> model::Pcap { - model::Pcap { + fn capture_2() -> model::Capture { + model::Capture { id: 4003, chip_kind: ChipKind::BLUETOOTH.into(), device_name: "device 2".to_string(), ..Default::default() } } - fn pcap_3() -> model::Pcap { - model::Pcap { + fn capture_3() -> model::Capture { + model::Capture { id: 4004, chip_kind: ChipKind::WIFI.into(), device_name: "device 3".to_string(), ..Default::default() } } - fn pcap_4_uwb() -> model::Pcap { - model::Pcap { + fn capture_4_uwb() -> model::Capture { + model::Capture { id: 4005, chip_kind: ChipKind::UWB.into(), device_name: "device 4".to_string(), ..Default::default() } } - fn all_test_pcaps() -> Vec<model::Pcap> { - vec![pcap_1(), pcap_1_wifi(), pcap_2(), pcap_3(), pcap_4_uwb()] + fn all_test_captures() -> Vec<model::Capture> { + vec![capture_1(), capture_1_wifi(), capture_2(), capture_3(), capture_4_uwb()] } #[test] fn test_no_match() { - test_filter_pcaps_helper(vec!["test".to_string()], vec![]); + test_filter_captures_helper(vec!["test".to_string()], vec![]); } #[test] fn test_all_match() { - test_filter_pcaps_helper(vec!["device".to_string()], all_test_pcaps()); + test_filter_captures_helper(vec!["device".to_string()], all_test_captures()); } #[test] - fn test_match_pcap_id() { - test_filter_pcaps_helper(vec!["4001".to_string()], vec![pcap_1()]); - test_filter_pcaps_helper(vec!["03".to_string()], vec![pcap_2()]); - test_filter_pcaps_helper(vec!["40".to_string()], all_test_pcaps()); + fn test_match_capture_id() { + test_filter_captures_helper(vec!["4001".to_string()], vec![capture_1()]); + test_filter_captures_helper(vec!["03".to_string()], vec![capture_2()]); + test_filter_captures_helper(vec!["40".to_string()], all_test_captures()); } #[test] fn test_match_device_name() { - test_filter_pcaps_helper(vec!["device 1".to_string()], vec![pcap_1(), pcap_1_wifi()]); - test_filter_pcaps_helper(vec![" 2".to_string()], vec![pcap_2()]); + test_filter_captures_helper( + vec!["device 1".to_string()], + vec![capture_1(), capture_1_wifi()], + ); + test_filter_captures_helper(vec![" 2".to_string()], vec![capture_2()]); } #[test] fn test_match_device_name_case_insensitive() { - test_filter_pcaps_helper(vec!["DEVICE 1".to_string()], vec![pcap_1(), pcap_1_wifi()]); + test_filter_captures_helper( + vec!["DEVICE 1".to_string()], + vec![capture_1(), capture_1_wifi()], + ); } #[test] fn test_match_wifi() { - test_filter_pcaps_helper(vec!["wifi".to_string()], vec![pcap_1_wifi(), pcap_3()]); - test_filter_pcaps_helper(vec!["WIFI".to_string()], vec![pcap_1_wifi(), pcap_3()]); + test_filter_captures_helper(vec!["wifi".to_string()], vec![capture_1_wifi(), capture_3()]); + test_filter_captures_helper(vec!["WIFI".to_string()], vec![capture_1_wifi(), capture_3()]); } #[test] fn test_match_uwb() { - test_filter_pcaps_helper(vec!["uwb".to_string()], vec![pcap_4_uwb()]); - test_filter_pcaps_helper(vec!["UWB".to_string()], vec![pcap_4_uwb()]); + test_filter_captures_helper(vec!["uwb".to_string()], vec![capture_4_uwb()]); + test_filter_captures_helper(vec!["UWB".to_string()], vec![capture_4_uwb()]); } #[test] fn test_match_bt() { - test_filter_pcaps_helper(vec!["BLUETOOTH".to_string()], vec![pcap_1(), pcap_2()]); - test_filter_pcaps_helper(vec!["blue".to_string()], vec![pcap_1(), pcap_2()]); + test_filter_captures_helper(vec!["BLUETOOTH".to_string()], vec![capture_1(), capture_2()]); + test_filter_captures_helper(vec!["blue".to_string()], vec![capture_1(), capture_2()]); } #[test] fn test_match_name_and_chip() { - test_filter_pcaps_helper( + test_filter_captures_helper( vec!["device 1".to_string(), "wifi".to_string()], - vec![pcap_1_wifi()], + vec![capture_1_wifi()], ); } } diff --git a/rust/netsim-cxx/src/pcap/capture.rs b/rust/netsim-cxx/src/captures/capture.rs index adf5e6ac..a04cbea8 100644 --- a/rust/netsim-cxx/src/pcap/capture.rs +++ b/rust/netsim-cxx/src/captures/capture.rs @@ -27,7 +27,7 @@ use std::time::{SystemTime, UNIX_EPOCH}; use frontend_proto::{ common::ChipKind, - model::{Pcap as ProtoPcap, State}, + model::{Capture as ProtoCapture, State}, }; use protobuf::well_known_types::timestamp::Timestamp; @@ -41,7 +41,7 @@ pub type FacadeId = i32; pub struct CaptureInfo { facade_id: FacadeId, pub file: Option<File>, - // Following items will be returned as ProtoPcap. (state: file.is_some()) + // Following items will be returned as ProtoCapture. (state: file.is_some()) id: ChipId, pub chip_kind: ChipKind, pub device_name: String, @@ -54,13 +54,13 @@ pub struct CaptureInfo { // Captures contains a recent copy of all chips and their ChipKind, chip_id, // and owning device name. Information for any recent or ongoing captures is -// also stored in the ProtoPcap. +// also stored in the ProtoCapture. // facade_key_to_capture allows for fast lookups when handle_request, handle_response // is invoked from packet_hub. pub struct Captures { pub facade_key_to_capture: HashMap<(ChipKind, FacadeId), Arc<Mutex<CaptureInfo>>>, // BTreeMap is used for chip_id_to_capture, so that the CaptureInfo can always be - // ordered by ChipId. ListPcapResponse will produce a ordered list of CaptureInfos. + // ordered by ChipId. ListCaptureResponse will produce a ordered list of CaptureInfos. pub chip_id_to_capture: BTreeMap<ChipId, Arc<Mutex<CaptureInfo>>>, } @@ -80,7 +80,7 @@ impl CaptureInfo { } } - // Creates a Pcap file with headers and store it under temp directory + // Creates a pcap file with headers and store it under temp directory // The lifecycle of the file is NOT tied to the lifecycle of the struct // Format: /tmp/netsim-pcaps/{chip_id}-{device_name}-{chip_kind}.pcap pub fn start_capture(&mut self) -> Result<()> { @@ -104,7 +104,7 @@ impl CaptureInfo { // Closes file by removing ownership of self.file // Capture info will still retain the size and record count - // So it can be downloaded easily when GetPcap is invoked. + // So it can be downloaded easily when GetCapture is invoked. pub fn stop_capture(&mut self) { self.file = None; } @@ -117,13 +117,12 @@ impl CaptureInfo { CaptureInfo::new_facade_key(self.chip_kind, self.facade_id) } - pub fn get_capture_proto(&self) -> ProtoPcap { + pub fn get_capture_proto(&self) -> ProtoCapture { let timestamp = Timestamp { seconds: self.seconds, nanos: self.nanos, ..Default::default() }; - ProtoPcap { + ProtoCapture { id: self.id, chip_kind: self.chip_kind.into(), - chip_id: self.id, device_name: self.device_name.clone(), state: match self.file.is_some() { true => State::ON.into(), @@ -178,7 +177,7 @@ impl Captures { capture.stop_capture(); } } else { - println!("key does not exist in Pcaps"); + println!("key does not exist in Captures"); return; } self.chip_id_to_capture.remove(key); diff --git a/rust/netsim-cxx/src/pcap/handlers.rs b/rust/netsim-cxx/src/captures/handlers.rs index bbd09a34..3dc6c37b 100644 --- a/rust/netsim-cxx/src/pcap/handlers.rs +++ b/rust/netsim-cxx/src/captures/handlers.rs @@ -14,11 +14,11 @@ //! Packet Capture handlers and singleton for HTTP and gRPC server. //! -//! This module implements a handler for GET, PATCH, LIST pcap +//! This module implements a handler for GET, PATCH, LIST capture //! //! /v1/captures --> handle_capture_list //! /v1/captures/{id} --> handle_capture_patch, handle_capture_get -//! handle_pcap_cxx calls handle_capture, which calls handle_capture_* based on uri +//! handle_capture_cxx calls handle_capture, which calls handle_capture_* based on uri //! handle_packet_request and handle_packet_response is invoked by packet_hub //! to write packets to files if capture state is on. @@ -27,7 +27,7 @@ use cxx::CxxVector; use frontend_proto::common::ChipKind; -use frontend_proto::frontend::{GetDevicesResponse, ListPcapResponse}; +use frontend_proto::frontend::{GetDevicesResponse, ListCaptureResponse}; use lazy_static::lazy_static; use netsim_common::util::time_display::TimeDisplay; use protobuf::Message; @@ -39,10 +39,10 @@ use std::pin::Pin; use std::sync::RwLock; use std::time::{SystemTime, UNIX_EPOCH}; +use crate::captures::capture::{Captures, ChipId}; use crate::ffi::{get_devices_bytes, CxxServerResponseWriter}; use crate::http_server::http_request::{HttpHeaders, HttpRequest}; use crate::http_server::server_response::ResponseWritable; -use crate::pcap::capture::{Captures, ChipId}; use crate::CxxServerResponseWriterWrapper; use super::capture::CaptureInfo; @@ -63,7 +63,7 @@ lazy_static! { } // Update the Captures collection to reflect the currently connected devices. -// This function removes entries from Pcaps when devices/chips +// This function removes entries from Captures when devices/chips // go away and adds entries when new devices/chips connect. // // Note: if a device disconnects and there is captured data, the entry @@ -73,7 +73,7 @@ fn update_captures(captures: &mut Captures) { // Print error and return empty hashmap if GetDevicesBytes fails. let mut vec = Vec::<u8>::new(); if !get_devices_bytes(&mut vec) { - println!("netsim error: GetDevicesBytes failed - returning an empty set of pcaps"); + println!("netsim error: GetDevicesBytes failed - returning an empty set of captures"); return; } @@ -104,7 +104,7 @@ fn update_captures(captures: &mut Captures) { Unused(ChipId), // type ChipId = i32 } - // Check if the active_pcap entry still exists in the chips. + // Check if the active_capture entry still exists in the chips. let mut removal = Vec::<RemovalIndicator>::new(); for (chip_id, capture) in captures.iter() { let lock = capture.lock().unwrap(); @@ -118,7 +118,7 @@ fn update_captures(captures: &mut Captures) { } } - // Now remove/update the pcaps based on the loop above + // Now remove/update the captures based on the loop above for indicator in removal { match indicator { RemovalIndicator::Unused(key) => captures.remove(&key), @@ -139,10 +139,10 @@ fn get_file(id: ChipId, device_name: String, chip_kind: ChipKind) -> Result<File File::open(filename) } -// TODO: GetPcap should return the information of the pcap. Need to reconsider +// TODO: GetCapture should return the information of the capture. Need to reconsider // uri hierarchy. -// GET /pcap/id/{id} --> Get Pcap informatiojn -// GET /pcap/contents/{id} --> Download Pcap file +// GET /captures/id/{id} --> Get Capture information +// GET /captures/contents/{id} --> Download Pcap file pub fn handle_capture_get(writer: ResponseWritable, captures: &mut Captures, id: ChipId) { // Get the most updated active captures update_captures(captures); @@ -176,7 +176,7 @@ pub fn handle_capture_get(writer: ResponseWritable, captures: &mut Captures, id: writer.put_error(404, "Cannot open Capture file"); } } else { - writer.put_error(404, "Cannot access Pcap Resource") + writer.put_error(404, "Cannot access Capture Resource") } } @@ -184,10 +184,10 @@ pub fn handle_capture_list(writer: ResponseWritable, captures: &mut Captures) { // Get the most updated active captures update_captures(captures); - // Instantiate ListPcapResponse and add Captures - let mut response = ListPcapResponse::new(); + // Instantiate ListCaptureResponse and add Captures + let mut response = ListCaptureResponse::new(); for capture in captures.values() { - response.pcaps.push(capture.lock().unwrap().get_capture_proto()); + response.captures.push(capture.lock().unwrap().get_capture_proto()); } // Perform protobuf-json-mapping with the given protobuf @@ -246,7 +246,7 @@ pub fn handle_capture(request: &HttpRequest, param: &str, writer: ResponseWritab let id = match param.parse::<i32>() { Ok(num) => num, Err(_) => { - writer.put_error(404, "Incorrect ID type for pcap, ID should be i32."); + writer.put_error(404, "Incorrect ID type for capture, ID should be i32."); return; } }; @@ -257,7 +257,7 @@ pub fn handle_capture(request: &HttpRequest, param: &str, writer: ResponseWritab let id = match param.parse::<i32>() { Ok(num) => num, Err(_) => { - writer.put_error(404, "Incorrect ID type for pcap, ID should be i32."); + writer.put_error(404, "Incorrect ID type for capture, ID should be i32."); return; } }; @@ -266,7 +266,7 @@ pub fn handle_capture(request: &HttpRequest, param: &str, writer: ResponseWritab match state.as_str() { "1" => handle_capture_patch(writer, &mut captures, id, true), "2" => handle_capture_patch(writer, &mut captures, id, false), - _ => writer.put_error(404, "Incorrect state for PatchPcap"), + _ => writer.put_error(404, "Incorrect state for PatchCapture"), } } _ => writer.put_error(404, "Not found."), @@ -274,8 +274,8 @@ pub fn handle_capture(request: &HttpRequest, param: &str, writer: ResponseWritab } } -/// pcap handle cxx for grpc server to call -pub fn handle_pcap_cxx( +/// capture handle cxx for grpc server to call +pub fn handle_capture_cxx( responder: Pin<&mut CxxServerResponseWriter>, method: String, param: String, @@ -318,19 +318,21 @@ fn handle_packet( packet_type: u32, direction: PacketDirection, ) { - let pcaps = RESOURCE.read().unwrap(); + let captures = RESOURCE.read().unwrap(); let facade_key = CaptureInfo::new_facade_key(int_to_chip_kind(kind), facade_id as i32); - if let Some(mut pcap) = - pcaps.facade_key_to_capture.get(&facade_key).map(|arc_pcap| arc_pcap.lock().unwrap()) + if let Some(mut capture) = captures + .facade_key_to_capture + .get(&facade_key) + .map(|arc_capture| arc_capture.lock().unwrap()) { - if let Some(ref mut file) = pcap.file { + if let Some(ref mut file) = capture.file { if int_to_chip_kind(kind) == ChipKind::BLUETOOTH { let timestamp = SystemTime::now().duration_since(UNIX_EPOCH).expect("Time went backwards"); match append_record(timestamp, file, direction, packet_type, packet.as_slice()) { Ok(size) => { - pcap.size += size; - pcap.records += 1; + capture.size += size; + capture.records += 1; } Err(err) => { println!("netsimd: {err:?}"); diff --git a/rust/netsim-cxx/src/pcap/mod.rs b/rust/netsim-cxx/src/captures/mod.rs index 52311f56..52311f56 100644 --- a/rust/netsim-cxx/src/pcap/mod.rs +++ b/rust/netsim-cxx/src/captures/mod.rs diff --git a/rust/netsim-cxx/src/pcap/pcap_util.rs b/rust/netsim-cxx/src/captures/pcap_util.rs index e0a7bab7..eecc52ea 100644 --- a/rust/netsim-cxx/src/pcap/pcap_util.rs +++ b/rust/netsim-cxx/src/captures/pcap_util.rs @@ -79,7 +79,7 @@ pub fn append_record( mod tests { use std::{fs::File, io::Read, time::Duration}; - use crate::pcap::pcap_util::{append_record, PacketDirection}; + use crate::captures::pcap_util::{append_record, PacketDirection}; use super::write_pcap_header; diff --git a/rust/netsim-cxx/src/pcap/sample.pcap b/rust/netsim-cxx/src/captures/sample.pcap Binary files differindex 26bad5b0..26bad5b0 100644 --- a/rust/netsim-cxx/src/pcap/sample.pcap +++ b/rust/netsim-cxx/src/captures/sample.pcap diff --git a/rust/netsim-cxx/src/http_server/mod.rs b/rust/netsim-cxx/src/http_server/mod.rs index d912f54e..0347cf42 100644 --- a/rust/netsim-cxx/src/http_server/mod.rs +++ b/rust/netsim-cxx/src/http_server/mod.rs @@ -18,12 +18,12 @@ mod http_router; pub(crate) mod server_response; mod thread_pool; +use crate::captures::handlers::*; use crate::http_server::http_request::HttpRequest; use crate::http_server::http_router::Router; use crate::http_server::server_response::{ ResponseWritable, ServerResponseWritable, ServerResponseWriter, }; -use crate::pcap::handlers::*; use crate::version::VERSION; use crate::http_server::thread_pool::ThreadPool; diff --git a/rust/netsim-cxx/src/http_server/server_response.rs b/rust/netsim-cxx/src/http_server/server_response.rs index 58fd950c..f3355fca 100644 --- a/rust/netsim-cxx/src/http_server/server_response.rs +++ b/rust/netsim-cxx/src/http_server/server_response.rs @@ -17,7 +17,7 @@ //! This module implements a basic response writer that can pass //! chunked http responses between a uri handler and the network. //! -//! The main use is for streaming large files from the pcap_handler() +//! The main use is for streaming large files from the capture_handler() //! to the Http client. //! //! This library is intended solely for serving netsim clients. diff --git a/rust/netsim-cxx/src/lib.rs b/rust/netsim-cxx/src/lib.rs index 6fdb3a9b..06e363c4 100644 --- a/rust/netsim-cxx/src/lib.rs +++ b/rust/netsim-cxx/src/lib.rs @@ -16,8 +16,8 @@ #![allow(dead_code)] +mod captures; mod http_server; -mod pcap; mod ranging; mod transport; mod uwb; @@ -33,8 +33,10 @@ use http_server::server_response::ServerResponseWritable; use crate::transport::fd::handle_response; use crate::transport::fd::run_fd_transport; +use crate::captures::handlers::{ + handle_capture_cxx, handle_packet_request, handle_packet_response, +}; use crate::http_server::run_http_server; -use crate::pcap::handlers::{handle_packet_request, handle_packet_response, handle_pcap_cxx}; use crate::ranging::*; use crate::uwb::facade::*; use crate::version::*; @@ -60,10 +62,10 @@ mod ffi { #[cxx_name = "GetVersion"] fn get_version() -> String; - // handle_pcap_cxx translates each argument into an appropriate Rust type + // handle_capture_cxx translates each argument into an appropriate Rust type - #[cxx_name = "HandlePcapCxx"] - fn handle_pcap_cxx( + #[cxx_name = "HandleCaptureCxx"] + fn handle_capture_cxx( responder: Pin<&mut CxxServerResponseWriter>, method: String, param: String, @@ -76,7 +78,7 @@ mod ffi { #[namespace = "netsim::fd"] fn handle_response(kind: u32, facade_id: u32, packet: &CxxVector<u8>, packet_type: u8); - // Pcap Resource + // Capture Resource #[cxx_name = HandleRequest] #[namespace = "netsim::pcap"] diff --git a/src/frontend/frontend_client.cc b/src/frontend/frontend_client.cc index b4821957..4a89324e 100644 --- a/src/frontend/frontend_client.cc +++ b/src/frontend/frontend_client.cc @@ -124,49 +124,51 @@ class FrontendClientImpl : public FrontendClient { return make_result(status, response); } - // Get the list of Pcap information - std::unique_ptr<ClientResult> ListPcap() const override { - frontend::ListPcapResponse response; + // Get the list of Capture information + std::unique_ptr<ClientResult> ListCapture() const override { + frontend::ListCaptureResponse response; grpc::ClientContext context_; - auto status = stub_->ListPcap(&context_, {}, &response); + auto status = stub_->ListCapture(&context_, {}, &response); return make_result(status, response); } - // Patch the Pcap - std::unique_ptr<ClientResult> PatchPcap( + // Patch the Capture + std::unique_ptr<ClientResult> PatchCapture( rust::Vec<::rust::u8> const &request_byte_vec) const override { google::protobuf::Empty response; grpc::ClientContext context_; - frontend::PatchPcapRequest request; + frontend::PatchCaptureRequest request; if (!request.ParseFromArray(request_byte_vec.data(), request_byte_vec.size())) { return make_result( grpc::Status( grpc::StatusCode::INVALID_ARGUMENT, - "Error parsing PatchPcap request protobuf. request size:" + + "Error parsing PatchCapture request protobuf. request size:" + std::to_string(request_byte_vec.size())), response); }; - auto status = stub_->PatchPcap(&context_, request, &response); + auto status = stub_->PatchCapture(&context_, request, &response); return make_result(status, response); } - // Download pcap file by using ClientResponseReader to handle streaming grpc - std::unique_ptr<ClientResult> GetPcap( + // Download capture file by using ClientResponseReader to handle streaming + // grpc + std::unique_ptr<ClientResult> GetCapture( rust::Vec<::rust::u8> const &request_byte_vec, ClientResponseReader const &client_reader) const override { grpc::ClientContext context_; - frontend::GetPcapRequest request; + frontend::GetCaptureRequest request; if (!request.ParseFromArray(request_byte_vec.data(), request_byte_vec.size())) { return make_result( - grpc::Status(grpc::StatusCode::INVALID_ARGUMENT, - "Error parsing GetPcap request protobuf. request size:" + - std::to_string(request_byte_vec.size())), + grpc::Status( + grpc::StatusCode::INVALID_ARGUMENT, + "Error parsing GetCapture request protobuf. request size:" + + std::to_string(request_byte_vec.size())), google::protobuf::Empty()); }; - auto reader = stub_->GetPcap(&context_, request); - frontend::GetPcapResponse chunk; + auto reader = stub_->GetCapture(&context_, request); + frontend::GetCaptureResponse chunk; // Read every available chunks from grpc reader while (reader->Read(&chunk)) { // Using a mutable protobuf here so the move iterator can move @@ -195,10 +197,10 @@ class FrontendClientImpl : public FrontendClient { return GetDevices(); case frontend::GrpcMethod::Reset: return Reset(); - case frontend::GrpcMethod::ListPcap: - return ListPcap(); - case frontend::GrpcMethod::PatchPcap: - return PatchPcap(request_byte_vec); + case frontend::GrpcMethod::ListCapture: + return ListCapture(); + case frontend::GrpcMethod::PatchCapture: + return PatchCapture(request_byte_vec); default: return make_result(grpc::Status(grpc::StatusCode::INVALID_ARGUMENT, "Unknown GrpcMethod found."), diff --git a/src/frontend/frontend_client.h b/src/frontend/frontend_client.h index ad95d0ff..3c57d659 100644 --- a/src/frontend/frontend_client.h +++ b/src/frontend/frontend_client.h @@ -57,10 +57,10 @@ class FrontendClient { virtual std::unique_ptr<ClientResult> PatchDevice( rust::Vec<rust::u8> const &request_byte_vec) const = 0; virtual std::unique_ptr<ClientResult> Reset() const = 0; - virtual std::unique_ptr<ClientResult> ListPcap() const = 0; - virtual std::unique_ptr<ClientResult> PatchPcap( + virtual std::unique_ptr<ClientResult> ListCapture() const = 0; + virtual std::unique_ptr<ClientResult> PatchCapture( rust::Vec<rust::u8> const &request_byte_vec) const = 0; - virtual std::unique_ptr<ClientResult> GetPcap( + virtual std::unique_ptr<ClientResult> GetCapture( rust::Vec<::rust::u8> const &request_byte_vec, ClientResponseReader const &client_reader) const = 0; }; diff --git a/src/frontend/frontend_server.cc b/src/frontend/frontend_server.cc index 6f13136e..fd32c4ad 100644 --- a/src/frontend/frontend_server.cc +++ b/src/frontend/frontend_server.cc @@ -40,7 +40,7 @@ class CxxServerResponseWritable : public frontend::CxxServerResponseWriter { CxxServerResponseWritable() : grpc_writer_(nullptr), err(""), is_ok(false), body(""), length(0){}; CxxServerResponseWritable( - grpc::ServerWriter<netsim::frontend::GetPcapResponse> *grpc_writer) + grpc::ServerWriter<netsim::frontend::GetCaptureResponse> *grpc_writer) : grpc_writer_(grpc_writer), err(""), is_ok(false), body(""), length(0){}; void put_error(unsigned int error_code, @@ -56,7 +56,7 @@ class CxxServerResponseWritable : public frontend::CxxServerResponseWriter { } void put_chunk(rust::Slice<const uint8_t> chunk) const override { - netsim::frontend::GetPcapResponse response; + netsim::frontend::GetCaptureResponse response; response.set_capture_stream(std::string(chunk.begin(), chunk.end())); is_ok = grpc_writer_->Write(response); } @@ -67,7 +67,8 @@ class CxxServerResponseWritable : public frontend::CxxServerResponseWriter { is_ok = true; } - mutable grpc::ServerWriter<netsim::frontend::GetPcapResponse> *grpc_writer_; + mutable grpc::ServerWriter<netsim::frontend::GetCaptureResponse> + *grpc_writer_; mutable std::string err; mutable bool is_ok; mutable std::string body; @@ -124,11 +125,11 @@ class FrontendServer final : public frontend::FrontendService::Service { return grpc::Status::OK; } - grpc::Status ListPcap(grpc::ServerContext *context, - const google::protobuf::Empty *empty, - frontend::ListPcapResponse *reply) { + grpc::Status ListCapture(grpc::ServerContext *context, + const google::protobuf::Empty *empty, + frontend::ListCaptureResponse *reply) { CxxServerResponseWritable writer; - HandlePcapCxx(writer, "GET", "", ""); + HandleCaptureCxx(writer, "GET", "", ""); if (writer.is_ok) { google::protobuf::util::JsonStringToMessage(writer.body, reply); return grpc::Status::OK; @@ -136,23 +137,23 @@ class FrontendServer final : public frontend::FrontendService::Service { return grpc::Status(grpc::StatusCode::UNKNOWN, writer.err); } - grpc::Status PatchPcap(grpc::ServerContext *context, - const frontend::PatchPcapRequest *request, - google::protobuf::Empty *response) { + grpc::Status PatchCapture(grpc::ServerContext *context, + const frontend::PatchCaptureRequest *request, + google::protobuf::Empty *response) { CxxServerResponseWritable writer; - HandlePcapCxx(writer, "PATCH", std::to_string(request->id()), - std::to_string(request->patch().state())); + HandleCaptureCxx(writer, "PATCH", std::to_string(request->id()), + std::to_string(request->patch().state())); if (writer.is_ok) { return grpc::Status::OK; } return grpc::Status(grpc::StatusCode::UNKNOWN, writer.err); } - grpc::Status GetPcap( + grpc::Status GetCapture( grpc::ServerContext *context, - const netsim::frontend::GetPcapRequest *request, - grpc::ServerWriter<netsim::frontend::GetPcapResponse> *grpc_writer) { + const netsim::frontend::GetCaptureRequest *request, + grpc::ServerWriter<netsim::frontend::GetCaptureResponse> *grpc_writer) { CxxServerResponseWritable writer(grpc_writer); - HandlePcapCxx(writer, "GET", std::to_string(request->id()), ""); + HandleCaptureCxx(writer, "GET", std::to_string(request->id()), ""); if (writer.is_ok) { return grpc::Status::OK; } diff --git a/src/frontend/server_response_writable.h b/src/frontend/server_response_writable.h index 5569e09e..cb23cf33 100644 --- a/src/frontend/server_response_writable.h +++ b/src/frontend/server_response_writable.h @@ -27,7 +27,7 @@ class CxxServerResponseWriter { public: CxxServerResponseWriter(){}; CxxServerResponseWriter( - grpc::ServerWriter<netsim::frontend::GetPcapResponse> *grpc_writer_){}; + grpc::ServerWriter<netsim::frontend::GetCaptureResponse> *grpc_writer_){}; virtual ~CxxServerResponseWriter() = default; virtual void put_error(unsigned int error_code, const std::string &response) const = 0; diff --git a/src/proto/frontend.proto b/src/proto/frontend.proto index e6c1d558..edb7c630 100644 --- a/src/proto/frontend.proto +++ b/src/proto/frontend.proto @@ -60,15 +60,15 @@ service FrontendService { // Register for network logs rpc NetCat(google.protobuf.Empty) returns (stream NetCatStream); - // Patch a Pcap source to turn capture on/off. + // Patch a Capture source to turn capture on/off. // When turned on the old capture contents are replaced. - rpc PatchPcap(PatchPcapRequest) returns (google.protobuf.Empty); + rpc PatchCapture(PatchCaptureRequest) returns (google.protobuf.Empty); - // List all Pcaps currently connected on netsim. - rpc ListPcap(google.protobuf.Empty) returns (ListPcapResponse); + // List all Captures currently connected on netsim. + rpc ListCapture(google.protobuf.Empty) returns (ListCaptureResponse); // Retrieve the contents of the packet capture as streaming bytes - rpc GetPcap(GetPcapRequest) returns (stream GetPcapResponse); + rpc GetCapture(GetCaptureRequest) returns (stream GetCaptureResponse); } message VersionResponse { @@ -115,27 +115,27 @@ message SetPacketCaptureRequest { string device_serial = 2; } -message PatchPcapRequest { +message PatchCaptureRequest { int32 id = 1; - // Body of PcapPatch that will be channeled into - // body for HandlePcapCxx - message PcapPatch { + // Body of PatchCapture that will be channeled into + // body for HandleCaptureCxx + message PatchCapture { netsim.model.State state = 1; } - PcapPatch patch = 2; + PatchCapture patch = 2; } -message ListPcapResponse { - repeated netsim.model.Pcap pcaps = 1; +message ListCaptureResponse { + repeated netsim.model.Capture captures = 1; } -message GetPcapRequest { +message GetCaptureRequest { int32 id = 1; } -message GetPcapResponse { +message GetCaptureResponse { bytes capture_stream = 1; } diff --git a/src/proto/model.proto b/src/proto/model.proto index 37aff0da..896b09c2 100644 --- a/src/proto/model.proto +++ b/src/proto/model.proto @@ -93,18 +93,17 @@ message Scene { repeated Device devices = 1; } -message Pcap { - int32 id = 1; +message Capture { + int32 id = 1; // same as chip_id netsim.common.ChipKind chip_kind = 2; - int32 chip_id = 3; // device AVD name - string device_name = 4; + string device_name = 3; // capture state - State state = 5; + State state = 4; // size of current capture - int32 size = 6; + int32 size = 5; // number of records in current capture - int32 records = 7; - google.protobuf.Timestamp timestamp = 8; - bool valid = 9; + int32 records = 6; + google.protobuf.Timestamp timestamp = 7; + bool valid = 8; } diff --git a/ui/dist/js/device-observer.js b/ui/dist/js/device-observer.js index 5201ee60..13a6c325 100644 --- a/ui/dist/js/device-observer.js +++ b/ui/dist/js/device-observer.js @@ -1 +1 @@ -import{State as e}from"./model.js";const i="./v1/devices",t="./v1/captures";class s{constructor(e){this.device=e}get name(){return this.device.name}set name(e){this.device.name=e}get position(){const e={x:0,y:0,z:0};return"position"in this.device&&this.device.position&&"object"==typeof this.device.position&&("x"in this.device.position&&"number"==typeof this.device.position.x&&(e.x=this.device.position.x),"y"in this.device.position&&"number"==typeof this.device.position.y&&(e.y=this.device.position.y),"z"in this.device.position&&"number"==typeof this.device.position.z&&(e.z=this.device.position.z)),e}set position(e){this.device.position=e}get orientation(){const e={yaw:0,pitch:0,roll:0};return"orientation"in this.device&&this.device.orientation&&"object"==typeof this.device.orientation&&("yaw"in this.device.orientation&&"number"==typeof this.device.orientation.yaw&&(e.yaw=this.device.orientation.yaw),"pitch"in this.device.orientation&&"number"==typeof this.device.orientation.pitch&&(e.pitch=this.device.orientation.pitch),"roll"in this.device.orientation&&"number"==typeof this.device.orientation.roll&&(e.roll=this.device.orientation.roll)),e}set orientation(e){this.device.orientation=e}get chips(){var e;return null!==(e=this.device.chips)&&void 0!==e?e:[]}set chips(e){this.device.chips=e}get visible(){var e;return null===(e=this.device.visible)||void 0===e||e}set visible(e){this.device.visible=e}toggleChipState(i,t){if("bt"in i&&i.bt){if(void 0===t)return void console.log("netsim-ui: must specify lowEnergy or classic for Bluetooth");"lowEnergy"===t&&"lowEnergy"in i.bt&&i.bt.lowEnergy&&"state"in i.bt.lowEnergy&&(i.bt.lowEnergy.state=i.bt.lowEnergy.state===e.ON?e.OFF:e.ON),"classic"===t&&"classic"in i.bt&&i.bt.classic&&"state"in i.bt.classic&&(i.bt.classic.state=i.bt.classic.state===e.ON?e.OFF:e.ON)}"wifi"in i&&i.wifi&&"state"in i.wifi&&(i.wifi.state=i.wifi.state===e.ON?e.OFF:e.ON),"uwb"in i&&i.uwb&&"state"in i.uwb&&(i.uwb.state=i.uwb.state===e.ON?e.OFF:e.ON)}toggleCapture(i,t){"capture"in t&&t.capture&&(t.capture=t.capture===e.ON?e.OFF:e.ON,o.patchDevice({device:{name:i.name,chips:i.chips}}))}}const o=new class{constructor(){this.observers=[],this.simulationInfo={devices:[],captures:[],selectedId:"",dimension:{x:10,y:10,z:0}},this.invokeGetDevice(),this.invokeListCaptures()}invokeGetDevice(){fetch(i,{method:"GET"}).then((e=>e.json())).then((e=>{this.fetchDevice(e.devices)})).catch((e=>{console.log("Cannot connect to netsim web server",e)}))}invokeListCaptures(){fetch(t,{method:"GET"}).then((e=>e.json())).then((e=>{this.simulationInfo.captures=e.pcaps})).catch((e=>{console.log("Cannot connect to netsim web server",e)}))}fetchDevice(e){this.simulationInfo.devices=[];for(const i of e)this.simulationInfo.devices.push(new s(i));this.notifyObservers()}patchSelected(e){this.simulationInfo.selectedId=e,this.notifyObservers()}handleDrop(e,i,t){for(const s of this.simulationInfo.devices)if(e===s.name){s.position={x:i,y:t,z:s.position.z},this.patchDevice({device:{name:s.name,position:s.position}});break}}patchCapture(e,i){fetch(t+"/"+e,{method:"PATCH",headers:{"Content-Type":"text/plain","Content-Length":i.length.toString()},body:i}),this.notifyObservers()}patchDevice(e){const t=JSON.stringify(e);fetch(i,{method:"PATCH",headers:{"Content-Type":"application/json","Content-Length":t.length.toString()},body:t}).then((e=>e.json())).catch((e=>{console.error("Error:",e)})),this.notifyObservers()}registerObserver(e){this.observers.push(e),e.onNotify(this.simulationInfo)}removeObserver(e){const i=this.observers.indexOf(e);this.observers.splice(i,1)}notifyObservers(){for(const e of this.observers)e.onNotify(this.simulationInfo)}getDeviceList(){return this.simulationInfo.devices}};!async function(){const e=e=>new Promise((i=>setTimeout(i,e)));for(;;)o.invokeGetDevice(),o.invokeListCaptures(),await e(1e3)}();export{s as Device,o as simulationState}; +import{State as e}from"./model.js";const i="./v1/devices",t="./v1/captures";class s{constructor(e){this.device=e}get name(){return this.device.name}set name(e){this.device.name=e}get position(){const e={x:0,y:0,z:0};return"position"in this.device&&this.device.position&&"object"==typeof this.device.position&&("x"in this.device.position&&"number"==typeof this.device.position.x&&(e.x=this.device.position.x),"y"in this.device.position&&"number"==typeof this.device.position.y&&(e.y=this.device.position.y),"z"in this.device.position&&"number"==typeof this.device.position.z&&(e.z=this.device.position.z)),e}set position(e){this.device.position=e}get orientation(){const e={yaw:0,pitch:0,roll:0};return"orientation"in this.device&&this.device.orientation&&"object"==typeof this.device.orientation&&("yaw"in this.device.orientation&&"number"==typeof this.device.orientation.yaw&&(e.yaw=this.device.orientation.yaw),"pitch"in this.device.orientation&&"number"==typeof this.device.orientation.pitch&&(e.pitch=this.device.orientation.pitch),"roll"in this.device.orientation&&"number"==typeof this.device.orientation.roll&&(e.roll=this.device.orientation.roll)),e}set orientation(e){this.device.orientation=e}get chips(){var e;return null!==(e=this.device.chips)&&void 0!==e?e:[]}set chips(e){this.device.chips=e}get visible(){var e;return null===(e=this.device.visible)||void 0===e||e}set visible(e){this.device.visible=e}toggleChipState(i,t){if("bt"in i&&i.bt){if(void 0===t)return void console.log("netsim-ui: must specify lowEnergy or classic for Bluetooth");"lowEnergy"===t&&"lowEnergy"in i.bt&&i.bt.lowEnergy&&"state"in i.bt.lowEnergy&&(i.bt.lowEnergy.state=i.bt.lowEnergy.state===e.ON?e.OFF:e.ON),"classic"===t&&"classic"in i.bt&&i.bt.classic&&"state"in i.bt.classic&&(i.bt.classic.state=i.bt.classic.state===e.ON?e.OFF:e.ON)}"wifi"in i&&i.wifi&&"state"in i.wifi&&(i.wifi.state=i.wifi.state===e.ON?e.OFF:e.ON),"uwb"in i&&i.uwb&&"state"in i.uwb&&(i.uwb.state=i.uwb.state===e.ON?e.OFF:e.ON)}toggleCapture(i,t){"capture"in t&&t.capture&&(t.capture=t.capture===e.ON?e.OFF:e.ON,o.patchDevice({device:{name:i.name,chips:i.chips}}))}}const o=new class{constructor(){this.observers=[],this.simulationInfo={devices:[],captures:[],selectedId:"",dimension:{x:10,y:10,z:0}},this.invokeGetDevice(),this.invokeListCaptures()}invokeGetDevice(){fetch(i,{method:"GET"}).then((e=>e.json())).then((e=>{this.fetchDevice(e.devices)})).catch((e=>{console.log("Cannot connect to netsim web server",e)}))}invokeListCaptures(){fetch(t,{method:"GET"}).then((e=>e.json())).then((e=>{this.simulationInfo.captures=e.captures})).catch((e=>{console.log("Cannot connect to netsim web server",e)}))}fetchDevice(e){this.simulationInfo.devices=[];for(const i of e)this.simulationInfo.devices.push(new s(i));this.notifyObservers()}patchSelected(e){this.simulationInfo.selectedId=e,this.notifyObservers()}handleDrop(e,i,t){for(const s of this.simulationInfo.devices)if(e===s.name){s.position={x:i,y:t,z:s.position.z},this.patchDevice({device:{name:s.name,position:s.position}});break}}patchCapture(e,i){fetch(t+"/"+e,{method:"PATCH",headers:{"Content-Type":"text/plain","Content-Length":i.length.toString()},body:i}),this.notifyObservers()}patchDevice(e){const t=JSON.stringify(e);fetch(i,{method:"PATCH",headers:{"Content-Type":"application/json","Content-Length":t.length.toString()},body:t}).then((e=>e.json())).catch((e=>{console.error("Error:",e)})),this.notifyObservers()}registerObserver(e){this.observers.push(e),e.onNotify(this.simulationInfo)}removeObserver(e){const i=this.observers.indexOf(e);this.observers.splice(i,1)}notifyObservers(){for(const e of this.observers)e.onNotify(this.simulationInfo)}getDeviceList(){return this.simulationInfo.devices}};!async function(){const e=e=>new Promise((i=>setTimeout(i,e)));for(;;)o.invokeGetDevice(),o.invokeListCaptures(),await e(1e3)}();export{s as Device,o as simulationState}; diff --git a/ui/ts/device-observer.ts b/ui/ts/device-observer.ts index e0f5683e..e7ad0c49 100644 --- a/ui/ts/device-observer.ts +++ b/ui/ts/device-observer.ts @@ -1,4 +1,4 @@ -import {Chip, Device as ProtoDevice, Pcap, State} from './model.js'; +import {Capture, Chip, Device as ProtoDevice, State} from './model.js'; // URL for netsim const DEVICES_URL = './v1/devices'; @@ -150,7 +150,7 @@ export class Device { */ export interface SimulationInfo { devices: Device[]; - captures: Pcap[]; + captures: Capture[]; selectedId: string; dimension: {x: number; y: number; z: number;}; } @@ -196,7 +196,7 @@ class SimulationState implements Observable { }) .then(response => response.json()) .then(data => { - this.simulationInfo.captures = data.pcaps; + this.simulationInfo.captures = data.captures; }) .catch(error => { console.log('Cannot connect to netsim web server', error); diff --git a/ui/ts/model.ts b/ui/ts/model.ts index d6c12387..8b540155 100644 --- a/ui/ts/model.ts +++ b/ui/ts/model.ts @@ -82,10 +82,10 @@ export interface Scene { devices: Device[]; } -export interface Pcap { +export interface Capture { + /** same as chip_id */ id: number; chipKind: ChipKind; - chipId: number; /** device AVD name */ deviceName: string; /** capture state */ diff --git a/ui/ts/packet-info.ts b/ui/ts/packet-info.ts index 05509073..83fcbe82 100644 --- a/ui/ts/packet-info.ts +++ b/ui/ts/packet-info.ts @@ -2,14 +2,14 @@ import {css, html, LitElement} from 'lit'; import {customElement, property} from 'lit/decorators.js'; import {Device, Notifiable, SimulationInfo, simulationState,} from './device-observer.js'; -import {Pcap, State} from './model.js'; +import {Capture, State} from './model.js'; @customElement('ns-packet-info') export class PacketInformation extends LitElement implements Notifiable { /** * List of captures currently on the netsim. */ - @property() captureData: Pcap[] = []; + @property() captureData: Capture[] = []; /** * List of devices currently on the netsim. @@ -161,7 +161,7 @@ export class PacketInformation extends LitElement implements Notifiable { this.requestUpdate(); } - toggleCapture(capture: Pcap) { + toggleCapture(capture: Capture) { let id = capture.id.toString(); let state = capture.state === State.OFF ? '1' : '2'; simulationState.patchCapture(id, state); @@ -223,7 +223,7 @@ export class PacketInformation extends LitElement implements Notifiable { `; } - private handleListCaptures(capture: Pcap) { + private handleListCaptures(capture: Capture) { return html` <tr> <td>${capture.deviceName}</td> |