netkitty 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.json +53 -0
- package/.idea/codeStyles/Project.xml +18 -0
- package/.idea/codeStyles/codeStyleConfig.xml +5 -0
- package/.idea/inspectionProfiles/Project_Default.xml +10 -0
- package/.idea/modules.xml +8 -0
- package/.idea/netkitty.iml +13 -0
- package/.idea/vcs.xml +6 -0
- package/LICENSE +21 -0
- package/README.md +2 -0
- package/binding.gyp +5 -0
- package/build/NetKitty.d.ts +31 -0
- package/build/NetKitty.d.ts.map +1 -0
- package/build/NetKitty.js +33 -0
- package/build/errors/ActionNotFoundError.d.ts +5 -0
- package/build/errors/ActionNotFoundError.d.ts.map +1 -0
- package/build/errors/ActionNotFoundError.js +12 -0
- package/build/errors/CodecSchemaValidateError.d.ts +5 -0
- package/build/errors/CodecSchemaValidateError.d.ts.map +1 -0
- package/build/errors/CodecSchemaValidateError.js +12 -0
- package/build/errors/DeviceNotFoundError.d.ts +5 -0
- package/build/errors/DeviceNotFoundError.d.ts.map +1 -0
- package/build/errors/DeviceNotFoundError.js +12 -0
- package/build/errors/NoAvailableCodecError.d.ts +5 -0
- package/build/errors/NoAvailableCodecError.d.ts.map +1 -0
- package/build/errors/NoAvailableCodecError.js +12 -0
- package/build/errors/NpcapLoadError.d.ts +5 -0
- package/build/errors/NpcapLoadError.d.ts.map +1 -0
- package/build/errors/NpcapLoadError.js +12 -0
- package/build/errors/SocketDownError.d.ts +5 -0
- package/build/errors/SocketDownError.d.ts.map +1 -0
- package/build/errors/SocketDownError.js +12 -0
- package/build/errors/UnknownPipeMessageTypeError.d.ts +5 -0
- package/build/errors/UnknownPipeMessageTypeError.d.ts.map +1 -0
- package/build/errors/UnknownPipeMessageTypeError.js +12 -0
- package/build/errors/common/ErrorCode.d.ts +31 -0
- package/build/errors/common/ErrorCode.d.ts.map +1 -0
- package/build/errors/common/ErrorCode.js +33 -0
- package/build/lib/GeneratePipeAddress.d.ts +7 -0
- package/build/lib/GeneratePipeAddress.d.ts.map +1 -0
- package/build/lib/GeneratePipeAddress.js +23 -0
- package/build/lib/GetBinding.d.ts +2 -0
- package/build/lib/GetBinding.d.ts.map +1 -0
- package/build/lib/GetBinding.js +6 -0
- package/build/lib/GetCaptureTemporaryDirectory.d.ts +7 -0
- package/build/lib/GetCaptureTemporaryDirectory.d.ts.map +1 -0
- package/build/lib/GetCaptureTemporaryDirectory.js +15 -0
- package/build/lib/GetDeviceCaptureTemporaryFilename.d.ts +8 -0
- package/build/lib/GetDeviceCaptureTemporaryFilename.d.ts.map +1 -0
- package/build/lib/GetDeviceCaptureTemporaryFilename.js +18 -0
- package/build/lib/codec/Codec.d.ts +33 -0
- package/build/lib/codec/Codec.d.ts.map +1 -0
- package/build/lib/codec/Codec.js +166 -0
- package/build/lib/codec/abstracts/BaseHeader.d.ts +204 -0
- package/build/lib/codec/abstracts/BaseHeader.d.ts.map +1 -0
- package/build/lib/codec/abstracts/BaseHeader.js +339 -0
- package/build/lib/codec/headers/ARP.d.ts +9 -0
- package/build/lib/codec/headers/ARP.d.ts.map +1 -0
- package/build/lib/codec/headers/ARP.js +223 -0
- package/build/lib/codec/headers/EthernetII.d.ts +9 -0
- package/build/lib/codec/headers/EthernetII.d.ts.map +1 -0
- package/build/lib/codec/headers/EthernetII.js +80 -0
- package/build/lib/codec/headers/Goose.d.ts +12 -0
- package/build/lib/codec/headers/Goose.d.ts.map +1 -0
- package/build/lib/codec/headers/Goose.js +701 -0
- package/build/lib/codec/headers/IEC61850SampledValues.d.ts +12 -0
- package/build/lib/codec/headers/IEC61850SampledValues.d.ts.map +1 -0
- package/build/lib/codec/headers/IEC61850SampledValues.js +369 -0
- package/build/lib/codec/headers/IPv4.d.ts +15 -0
- package/build/lib/codec/headers/IPv4.d.ts.map +1 -0
- package/build/lib/codec/headers/IPv4.js +338 -0
- package/build/lib/codec/headers/RawData.d.ts +9 -0
- package/build/lib/codec/headers/RawData.d.ts.map +1 -0
- package/build/lib/codec/headers/RawData.js +34 -0
- package/build/lib/codec/headers/TCP.d.ts +15 -0
- package/build/lib/codec/headers/TCP.d.ts.map +1 -0
- package/build/lib/codec/headers/TCP.js +897 -0
- package/build/lib/codec/headers/UDP.d.ts +15 -0
- package/build/lib/codec/headers/UDP.d.ts.map +1 -0
- package/build/lib/codec/headers/UDP.js +191 -0
- package/build/lib/codec/headers/VLAN_802dot1Q.d.ts +9 -0
- package/build/lib/codec/headers/VLAN_802dot1Q.d.ts.map +1 -0
- package/build/lib/codec/headers/VLAN_802dot1Q.js +77 -0
- package/build/lib/codec/lib/BufferToHex.d.ts +2 -0
- package/build/lib/codec/lib/BufferToHex.d.ts.map +1 -0
- package/build/lib/codec/lib/BufferToHex.js +6 -0
- package/build/lib/codec/lib/BufferToIP.d.ts +13 -0
- package/build/lib/codec/lib/BufferToIP.d.ts.map +1 -0
- package/build/lib/codec/lib/BufferToIP.js +21 -0
- package/build/lib/codec/lib/BufferToNumber.d.ts +10 -0
- package/build/lib/codec/lib/BufferToNumber.d.ts.map +1 -0
- package/build/lib/codec/lib/BufferToNumber.js +22 -0
- package/build/lib/codec/lib/FixHexString.d.ts +7 -0
- package/build/lib/codec/lib/FixHexString.d.ts.map +1 -0
- package/build/lib/codec/lib/FixHexString.js +11 -0
- package/build/lib/codec/lib/FlexibleObject.d.ts +28 -0
- package/build/lib/codec/lib/FlexibleObject.d.ts.map +1 -0
- package/build/lib/codec/lib/FlexibleObject.js +102 -0
- package/build/lib/codec/lib/HexToNumber.d.ts +10 -0
- package/build/lib/codec/lib/HexToNumber.d.ts.map +1 -0
- package/build/lib/codec/lib/HexToNumber.js +39 -0
- package/build/lib/codec/lib/IPToBuffer.d.ts +13 -0
- package/build/lib/codec/lib/IPToBuffer.d.ts.map +1 -0
- package/build/lib/codec/lib/IPToBuffer.js +28 -0
- package/build/lib/codec/lib/NumberToBERBuffer.d.ts +9 -0
- package/build/lib/codec/lib/NumberToBERBuffer.d.ts.map +1 -0
- package/build/lib/codec/lib/NumberToBERBuffer.js +20 -0
- package/build/lib/codec/lib/NumberToBERHex.d.ts +9 -0
- package/build/lib/codec/lib/NumberToBERHex.d.ts.map +1 -0
- package/build/lib/codec/lib/NumberToBERHex.js +23 -0
- package/build/lib/codec/lib/NumberToBuffer.d.ts +10 -0
- package/build/lib/codec/lib/NumberToBuffer.d.ts.map +1 -0
- package/build/lib/codec/lib/NumberToBuffer.js +22 -0
- package/build/lib/codec/lib/NumberToHex.d.ts +10 -0
- package/build/lib/codec/lib/NumberToHex.d.ts.map +1 -0
- package/build/lib/codec/lib/NumberToHex.js +26 -0
- package/build/lib/codec/lib/ProcessPacketPostHandlers.d.ts +14 -0
- package/build/lib/codec/lib/ProcessPacketPostHandlers.d.ts.map +1 -0
- package/build/lib/codec/lib/ProcessPacketPostHandlers.js +53 -0
- package/build/lib/codec/lib/SortPostHandlers.d.ts +8 -0
- package/build/lib/codec/lib/SortPostHandlers.d.ts.map +1 -0
- package/build/lib/codec/lib/SortPostHandlers.js +11 -0
- package/build/lib/codec/lib/StringContentEncodingEnum.d.ts +8 -0
- package/build/lib/codec/lib/StringContentEncodingEnum.d.ts.map +1 -0
- package/build/lib/codec/lib/StringContentEncodingEnum.js +11 -0
- package/build/lib/codec/types/CodecData.d.ts +7 -0
- package/build/lib/codec/types/CodecData.d.ts.map +1 -0
- package/build/lib/codec/types/CodecData.js +2 -0
- package/build/lib/codec/types/CodecDecodeResult.d.ts +9 -0
- package/build/lib/codec/types/CodecDecodeResult.d.ts.map +1 -0
- package/build/lib/codec/types/CodecDecodeResult.js +2 -0
- package/build/lib/codec/types/CodecEncodeInput.d.ts +5 -0
- package/build/lib/codec/types/CodecEncodeInput.d.ts.map +1 -0
- package/build/lib/codec/types/CodecEncodeInput.js +2 -0
- package/build/lib/codec/types/CodecEncodeResult.d.ts +6 -0
- package/build/lib/codec/types/CodecEncodeResult.d.ts.map +1 -0
- package/build/lib/codec/types/CodecEncodeResult.js +2 -0
- package/build/lib/codec/types/CodecErrorInfo.d.ts +6 -0
- package/build/lib/codec/types/CodecErrorInfo.d.ts.map +1 -0
- package/build/lib/codec/types/CodecErrorInfo.js +2 -0
- package/build/lib/codec/types/CodecModule.d.ts +3 -0
- package/build/lib/codec/types/CodecModule.d.ts.map +1 -0
- package/build/lib/codec/types/CodecModule.js +2 -0
- package/build/lib/codec/types/CodecModuleConstructor.d.ts +3 -0
- package/build/lib/codec/types/CodecModuleConstructor.d.ts.map +1 -0
- package/build/lib/codec/types/CodecModuleConstructor.js +2 -0
- package/build/lib/codec/types/CodecSchema.d.ts +7 -0
- package/build/lib/codec/types/CodecSchema.d.ts.map +1 -0
- package/build/lib/codec/types/CodecSchema.js +2 -0
- package/build/lib/codec/types/HeaderTreeNode.d.ts +5 -0
- package/build/lib/codec/types/HeaderTreeNode.d.ts.map +1 -0
- package/build/lib/codec/types/HeaderTreeNode.js +2 -0
- package/build/lib/codec/types/PostHandlerItem.d.ts +5 -0
- package/build/lib/codec/types/PostHandlerItem.d.ts.map +1 -0
- package/build/lib/codec/types/PostHandlerItem.js +2 -0
- package/build/lib/nodepcap/Capture.d.ts +75 -0
- package/build/lib/nodepcap/Capture.d.ts.map +1 -0
- package/build/lib/nodepcap/Capture.js +309 -0
- package/build/lib/nodepcap/GetNetworkInterfaces.d.ts +7 -0
- package/build/lib/nodepcap/GetNetworkInterfaces.d.ts.map +1 -0
- package/build/lib/nodepcap/GetNetworkInterfaces.js +22 -0
- package/build/lib/nodepcap/interfaces/IBindingCapture.d.ts +16 -0
- package/build/lib/nodepcap/interfaces/IBindingCapture.d.ts.map +1 -0
- package/build/lib/nodepcap/interfaces/IBindingCapture.js +2 -0
- package/build/lib/nodepcap/interfaces/IBindingCaptureOptions.d.ts +5 -0
- package/build/lib/nodepcap/interfaces/IBindingCaptureOptions.d.ts.map +1 -0
- package/build/lib/nodepcap/interfaces/IBindingCaptureOptions.js +2 -0
- package/build/lib/nodepcap/interfaces/ICaptureOptions.d.ts +19 -0
- package/build/lib/nodepcap/interfaces/ICaptureOptions.d.ts.map +1 -0
- package/build/lib/nodepcap/interfaces/ICaptureOptions.js +2 -0
- package/build/lib/nodepcap/interfaces/INetworkInterface.d.ts +5 -0
- package/build/lib/nodepcap/interfaces/INetworkInterface.d.ts.map +1 -0
- package/build/lib/nodepcap/interfaces/INetworkInterface.js +2 -0
- package/build/lib/nodepcap/lib/BindingCapture.d.ts +15 -0
- package/build/lib/nodepcap/lib/BindingCapture.d.ts.map +1 -0
- package/build/lib/nodepcap/lib/BindingCapture.js +35 -0
- package/build/lib/nodepcap/lib/GetNodePcapBinding.d.ts +2 -0
- package/build/lib/nodepcap/lib/GetNodePcapBinding.d.ts.map +1 -0
- package/build/lib/nodepcap/lib/GetNodePcapBinding.js +55 -0
- package/build/lib/nodepcap/lib/GetNodePcapBindingCapture.d.ts +3 -0
- package/build/lib/nodepcap/lib/GetNodePcapBindingCapture.d.ts.map +1 -0
- package/build/lib/nodepcap/lib/GetNodePcapBindingCapture.js +18 -0
- package/build/lib/nodepcap/workers/CaptureWorker.d.ts +2 -0
- package/build/lib/nodepcap/workers/CaptureWorker.d.ts.map +1 -0
- package/build/lib/nodepcap/workers/CaptureWorker.js +25 -0
- package/build/lib/pcap/PCAPGenerator.d.ts +34 -0
- package/build/lib/pcap/PCAPGenerator.d.ts.map +1 -0
- package/build/lib/pcap/PCAPGenerator.js +95 -0
- package/build/lib/pcap/PcapParser.d.ts +27 -0
- package/build/lib/pcap/PcapParser.d.ts.map +1 -0
- package/build/lib/pcap/PcapParser.js +149 -0
- package/build/lib/pcap/PcapReader.d.ts +87 -0
- package/build/lib/pcap/PcapReader.d.ts.map +1 -0
- package/build/lib/pcap/PcapReader.js +207 -0
- package/build/lib/pcap/PcapWriter.d.ts +29 -0
- package/build/lib/pcap/PcapWriter.d.ts.map +1 -0
- package/build/lib/pcap/PcapWriter.js +80 -0
- package/build/lib/pcap/interfaces/IPcapPacketInfo.d.ts +13 -0
- package/build/lib/pcap/interfaces/IPcapPacketInfo.d.ts.map +1 -0
- package/build/lib/pcap/interfaces/IPcapPacketInfo.js +2 -0
- package/build/lib/pipe/PipeClient.d.ts +35 -0
- package/build/lib/pipe/PipeClient.d.ts.map +1 -0
- package/build/lib/pipe/PipeClient.js +71 -0
- package/build/lib/pipe/PipeClientSocket.d.ts +39 -0
- package/build/lib/pipe/PipeClientSocket.d.ts.map +1 -0
- package/build/lib/pipe/PipeClientSocket.js +82 -0
- package/build/lib/pipe/PipeMessage.d.ts +27 -0
- package/build/lib/pipe/PipeMessage.d.ts.map +1 -0
- package/build/lib/pipe/PipeMessage.js +61 -0
- package/build/lib/pipe/PipeMessageHandler.d.ts +16 -0
- package/build/lib/pipe/PipeMessageHandler.d.ts.map +1 -0
- package/build/lib/pipe/PipeMessageHandler.js +95 -0
- package/build/lib/pipe/PipeServer.d.ts +25 -0
- package/build/lib/pipe/PipeServer.d.ts.map +1 -0
- package/build/lib/pipe/PipeServer.js +59 -0
- package/build/lib/schema/ProtocolFieldJSONSchema.d.ts +35 -0
- package/build/lib/schema/ProtocolFieldJSONSchema.d.ts.map +1 -0
- package/build/lib/schema/ProtocolFieldJSONSchema.js +2 -0
- package/build/lib/schema/ProtocolFieldJSONSchemaDefinition.d.ts +3 -0
- package/build/lib/schema/ProtocolFieldJSONSchemaDefinition.d.ts.map +1 -0
- package/build/lib/schema/ProtocolFieldJSONSchemaDefinition.js +2 -0
- package/build/lib/schema/ProtocolJSONSchema.d.ts +32 -0
- package/build/lib/schema/ProtocolJSONSchema.d.ts.map +1 -0
- package/build/lib/schema/ProtocolJSONSchema.js +2 -0
- package/build/tests/Test.spec.d.ts +2 -0
- package/build/tests/Test.spec.d.ts.map +1 -0
- package/build/tests/Test.spec.js +25 -0
- package/build/tests/units/CaptureTest.spec.d.ts +2 -0
- package/build/tests/units/CaptureTest.spec.d.ts.map +1 -0
- package/build/tests/units/CaptureTest.spec.js +31 -0
- package/build/tests/units/Codec.spec.d.ts +2 -0
- package/build/tests/units/Codec.spec.d.ts.map +1 -0
- package/build/tests/units/Codec.spec.js +70 -0
- package/cpp/nodepcap/deps/include/Packet32.h +429 -0
- package/cpp/nodepcap/deps/include/pcap/bluetooth.h +56 -0
- package/cpp/nodepcap/deps/include/pcap/bpf.h +292 -0
- package/cpp/nodepcap/deps/include/pcap/can_socketcan.h +56 -0
- package/cpp/nodepcap/deps/include/pcap/compiler-tests.h +163 -0
- package/cpp/nodepcap/deps/include/pcap/dlt.h +1514 -0
- package/cpp/nodepcap/deps/include/pcap/funcattrs.h +325 -0
- package/cpp/nodepcap/deps/include/pcap/ipnet.h +43 -0
- package/cpp/nodepcap/deps/include/pcap/namedb.h +84 -0
- package/cpp/nodepcap/deps/include/pcap/nflog.h +94 -0
- package/cpp/nodepcap/deps/include/pcap/pcap-inttypes.h +101 -0
- package/cpp/nodepcap/deps/include/pcap/pcap.h +1219 -0
- package/cpp/nodepcap/deps/include/pcap/sll.h +149 -0
- package/cpp/nodepcap/deps/include/pcap/socket.h +84 -0
- package/cpp/nodepcap/deps/include/pcap/usb.h +143 -0
- package/cpp/nodepcap/deps/include/pcap/vlan.h +46 -0
- package/cpp/nodepcap/deps/include/pcap-bpf.h +45 -0
- package/cpp/nodepcap/deps/include/pcap-namedb.h +40 -0
- package/cpp/nodepcap/deps/include/pcap.h +43 -0
- package/cpp/nodepcap/deps/lib/ARM64/Packet.lib +0 -0
- package/cpp/nodepcap/deps/lib/Packet.lib +0 -0
- package/cpp/nodepcap/deps/lib/wpcap.lib +0 -0
- package/cpp/nodepcap/deps/lib/x64/Packet.lib +0 -0
- package/cpp/nodepcap/deps/lib/x64/wpcap.lib +0 -0
- package/cpp/nodepcap/nodepcap.gypi +104 -0
- package/cpp/nodepcap/src/binding.cc +14 -0
- package/cpp/nodepcap/src/capture.cc +400 -0
- package/cpp/nodepcap/src/capture.h +53 -0
- package/cpp/nodepcap/src/utils.cc +218 -0
- package/cpp/nodepcap/src/utils.h +13 -0
- package/package.json +65 -0
- package/src/NetKitty.ts +31 -0
- package/src/errors/ActionNotFoundError.ts +6 -0
- package/src/errors/CodecSchemaValidateError.ts +6 -0
- package/src/errors/DeviceNotFoundError.ts +6 -0
- package/src/errors/NoAvailableCodecError.ts +6 -0
- package/src/errors/NpcapLoadError.ts +6 -0
- package/src/errors/SocketDownError.ts +6 -0
- package/src/errors/UnknownPipeMessageTypeError.ts +6 -0
- package/src/errors/common/ErrorCode.ts +30 -0
- package/src/lib/GeneratePipeAddress.ts +17 -0
- package/src/lib/GetBinding.ts +3 -0
- package/src/lib/GetCaptureTemporaryDirectory.ts +12 -0
- package/src/lib/GetDeviceCaptureTemporaryFilename.ts +13 -0
- package/src/lib/codec/Codec.ts +181 -0
- package/src/lib/codec/abstracts/BaseHeader.ts +413 -0
- package/src/lib/codec/headers/ARP.ts +218 -0
- package/src/lib/codec/headers/EthernetII.ts +77 -0
- package/src/lib/codec/headers/Goose.ts +658 -0
- package/src/lib/codec/headers/IEC61850SampledValues.ts +359 -0
- package/src/lib/codec/headers/IPv4.ts +329 -0
- package/src/lib/codec/headers/RawData.ts +34 -0
- package/src/lib/codec/headers/TCP.ts +931 -0
- package/src/lib/codec/headers/UDP.ts +180 -0
- package/src/lib/codec/headers/VLAN_802dot1Q.ts +74 -0
- package/src/lib/codec/lib/BufferToHex.ts +3 -0
- package/src/lib/codec/lib/BufferToIP.ts +19 -0
- package/src/lib/codec/lib/BufferToNumber.ts +31 -0
- package/src/lib/codec/lib/FixHexString.ts +8 -0
- package/src/lib/codec/lib/FlexibleObject.ts +100 -0
- package/src/lib/codec/lib/HexToNumber.ts +25 -0
- package/src/lib/codec/lib/IPToBuffer.ts +25 -0
- package/src/lib/codec/lib/NumberToBERBuffer.ts +19 -0
- package/src/lib/codec/lib/NumberToBERHex.ts +13 -0
- package/src/lib/codec/lib/NumberToBuffer.ts +21 -0
- package/src/lib/codec/lib/NumberToHex.ts +15 -0
- package/src/lib/codec/lib/ProcessPacketPostHandlers.ts +53 -0
- package/src/lib/codec/lib/SortPostHandlers.ts +10 -0
- package/src/lib/codec/lib/StringContentEncodingEnum.ts +7 -0
- package/src/lib/codec/types/CodecData.ts +7 -0
- package/src/lib/codec/types/CodecDecodeResult.ts +9 -0
- package/src/lib/codec/types/CodecEncodeInput.ts +5 -0
- package/src/lib/codec/types/CodecEncodeResult.ts +6 -0
- package/src/lib/codec/types/CodecErrorInfo.ts +5 -0
- package/src/lib/codec/types/CodecModule.ts +3 -0
- package/src/lib/codec/types/CodecModuleConstructor.ts +3 -0
- package/src/lib/codec/types/CodecSchema.ts +7 -0
- package/src/lib/codec/types/HeaderTreeNode.ts +5 -0
- package/src/lib/codec/types/PostHandlerItem.ts +4 -0
- package/src/lib/nodepcap/Capture.ts +291 -0
- package/src/lib/nodepcap/GetNetworkInterfaces.ts +18 -0
- package/src/lib/nodepcap/interfaces/IBindingCapture.ts +27 -0
- package/src/lib/nodepcap/interfaces/IBindingCaptureOptions.ts +4 -0
- package/src/lib/nodepcap/interfaces/ICaptureOptions.ts +19 -0
- package/src/lib/nodepcap/interfaces/INetworkInterface.ts +4 -0
- package/src/lib/nodepcap/lib/BindingCapture.ts +46 -0
- package/src/lib/nodepcap/lib/GetNodePcapBinding.ts +17 -0
- package/src/lib/nodepcap/lib/GetNodePcapBindingCapture.ts +15 -0
- package/src/lib/nodepcap/workers/CaptureWorker.ts +30 -0
- package/src/lib/pcap/PCAPGenerator.ts +118 -0
- package/src/lib/pcap/PcapParser.ts +170 -0
- package/src/lib/pcap/PcapReader.ts +239 -0
- package/src/lib/pcap/PcapWriter.ts +93 -0
- package/src/lib/pcap/interfaces/IPcapPacketInfo.ts +12 -0
- package/src/lib/pipe/PipeClient.ts +91 -0
- package/src/lib/pipe/PipeClientSocket.ts +99 -0
- package/src/lib/pipe/PipeMessage.ts +74 -0
- package/src/lib/pipe/PipeMessageHandler.ts +91 -0
- package/src/lib/pipe/PipeServer.ts +74 -0
- package/src/lib/schema/ProtocolFieldJSONSchema.ts +45 -0
- package/src/lib/schema/ProtocolFieldJSONSchemaDefinition.ts +3 -0
- package/src/lib/schema/ProtocolJSONSchema.ts +37 -0
- package/src/tests/Test.spec.ts +22 -0
- package/src/tests/units/CaptureTest.spec.ts +30 -0
- package/src/tests/units/Codec.spec.ts +85 -0
- package/tsconfig.json +41 -0
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BaseHeader = void 0;
|
|
4
|
+
const SortPostHandlers_1 = require("../lib/SortPostHandlers");
|
|
5
|
+
const FlexibleObject_1 = require("../lib/FlexibleObject");
|
|
6
|
+
const ajv_1 = require("ajv");
|
|
7
|
+
const CodecSchemaValidateError_1 = require("../../../errors/CodecSchemaValidateError");
|
|
8
|
+
const CONSTRUCTOR_VALIDATE_KEY = '__validate';
|
|
9
|
+
class BaseHeader {
|
|
10
|
+
static get CODEC_INSTANCE() {
|
|
11
|
+
return new this();
|
|
12
|
+
}
|
|
13
|
+
static CREATE_CODEC_INSTANCE_WITCH_CODEC_MODULES(codecModules) {
|
|
14
|
+
return new this(undefined, codecModules, []);
|
|
15
|
+
}
|
|
16
|
+
static get PROTOCOL_ID() {
|
|
17
|
+
return this.CODEC_INSTANCE.id;
|
|
18
|
+
}
|
|
19
|
+
static get PROTOCOL_NAME() {
|
|
20
|
+
return this.CODEC_INSTANCE.name;
|
|
21
|
+
}
|
|
22
|
+
static get PROTOCOL_SCHEMA() {
|
|
23
|
+
const schema = JSON.parse(JSON.stringify(this.CODEC_INSTANCE.SCHEMA));
|
|
24
|
+
if (!Object.hasOwn(this, CONSTRUCTOR_VALIDATE_KEY)) {
|
|
25
|
+
const validate = new ajv_1.Ajv({
|
|
26
|
+
strict: false,
|
|
27
|
+
useDefaults: true,
|
|
28
|
+
coerceTypes: true
|
|
29
|
+
}).compile(schema);
|
|
30
|
+
Object.defineProperty(this, CONSTRUCTOR_VALIDATE_KEY, {
|
|
31
|
+
enumerable: false,
|
|
32
|
+
configurable: false,
|
|
33
|
+
value: validate
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
return schema;
|
|
37
|
+
}
|
|
38
|
+
static MATCH(codecModules) {
|
|
39
|
+
return this.CREATE_CODEC_INSTANCE_WITCH_CODEC_MODULES(codecModules ? codecModules : []).match();
|
|
40
|
+
}
|
|
41
|
+
static CREATE_INSTANCE(codecData, codecModules) {
|
|
42
|
+
return new this(codecData, codecModules);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Entire packet buffer data getter
|
|
46
|
+
*/
|
|
47
|
+
get packet() {
|
|
48
|
+
return this.codecData.packet;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Entire packet buffer data setter
|
|
52
|
+
* @param packet
|
|
53
|
+
*/
|
|
54
|
+
set packet(packet) {
|
|
55
|
+
this.codecData.packet = packet;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* The end position of this header in the entire packet's buffer
|
|
59
|
+
*/
|
|
60
|
+
get endPos() {
|
|
61
|
+
return this.startPos + this.headerLength;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Readonly Header length
|
|
65
|
+
*/
|
|
66
|
+
get length() {
|
|
67
|
+
return this.headerLength;
|
|
68
|
+
}
|
|
69
|
+
get postPacketHandlers() {
|
|
70
|
+
if (this.codecData.postHandlers[this.headerIndex] === undefined)
|
|
71
|
+
this.codecData.postHandlers[this.headerIndex] = [];
|
|
72
|
+
return this.codecData.postHandlers[this.headerIndex];
|
|
73
|
+
}
|
|
74
|
+
constructor(codecData, codecModules) {
|
|
75
|
+
/**
|
|
76
|
+
* Encode/Decode error info objects
|
|
77
|
+
*/
|
|
78
|
+
this.errors = [];
|
|
79
|
+
/**
|
|
80
|
+
* Header schema instance
|
|
81
|
+
*/
|
|
82
|
+
this.instance = new FlexibleObject_1.FlexibleObject();
|
|
83
|
+
/**
|
|
84
|
+
* The start position of this header in the entire packet's buffer
|
|
85
|
+
*/
|
|
86
|
+
this.startPos = 0;
|
|
87
|
+
/**
|
|
88
|
+
* Header length
|
|
89
|
+
* @protected
|
|
90
|
+
*/
|
|
91
|
+
this.headerLength = 0;
|
|
92
|
+
/**
|
|
93
|
+
* Current header index in packet headers
|
|
94
|
+
* @protected
|
|
95
|
+
*/
|
|
96
|
+
this.headerIndex = 0;
|
|
97
|
+
/**
|
|
98
|
+
* Registered post encode handlers (CodecModule)
|
|
99
|
+
* @protected
|
|
100
|
+
*/
|
|
101
|
+
this.postSelfEncodeHandlers = [];
|
|
102
|
+
/**
|
|
103
|
+
* Registered post decode handlers (CodecModule)
|
|
104
|
+
* @protected
|
|
105
|
+
*/
|
|
106
|
+
this.postSelfDecodeHandlers = [];
|
|
107
|
+
this.codecData = codecData;
|
|
108
|
+
this.startPos = codecData?.startPos ? codecData.startPos : 0;
|
|
109
|
+
codecModules = codecModules ? codecModules : [];
|
|
110
|
+
this.codecModules = codecModules;
|
|
111
|
+
this.prevCodecModules = [...codecModules];
|
|
112
|
+
const prevCodecModuleIndex = this.prevCodecModules.length - 1;
|
|
113
|
+
this.prevCodecModule = this.prevCodecModules[prevCodecModuleIndex > -1 ? prevCodecModuleIndex : 0];
|
|
114
|
+
this.headerIndex = this.prevCodecModules.length;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Get packet data offset
|
|
118
|
+
* @param offset
|
|
119
|
+
* @protected
|
|
120
|
+
*/
|
|
121
|
+
getPacketOffset(offset) {
|
|
122
|
+
return this.startPos + offset;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Internal read bytes from buffer
|
|
126
|
+
* @param offset
|
|
127
|
+
* @param length
|
|
128
|
+
* @param expandBufferLength
|
|
129
|
+
* @private
|
|
130
|
+
*/
|
|
131
|
+
#readBytes(offset, length, expandBufferLength) {
|
|
132
|
+
const packetOffset = this.getPacketOffset(offset);
|
|
133
|
+
const readEndPos = packetOffset + length;
|
|
134
|
+
if (this.packet.length < readEndPos && expandBufferLength)
|
|
135
|
+
this.packet = Buffer.concat([this.packet, Buffer.alloc(readEndPos - this.packet.length, 0)]);
|
|
136
|
+
const headerLength = readEndPos - this.startPos;
|
|
137
|
+
this.headerLength = this.headerLength < headerLength ? headerLength : this.headerLength;
|
|
138
|
+
return this.packet.subarray(packetOffset, packetOffset + length);
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Read bytes from buffer
|
|
142
|
+
* @param offset
|
|
143
|
+
* @param length
|
|
144
|
+
* @protected
|
|
145
|
+
*/
|
|
146
|
+
readBytes(offset, length) {
|
|
147
|
+
return this.#readBytes(offset, length, false);
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Write bytes to buffer
|
|
151
|
+
* @param offset
|
|
152
|
+
* @param buffer
|
|
153
|
+
* @protected
|
|
154
|
+
*/
|
|
155
|
+
writeBytes(offset, buffer) {
|
|
156
|
+
const packetOffset = this.getPacketOffset(offset);
|
|
157
|
+
const writeEndPos = packetOffset + buffer.length;
|
|
158
|
+
this.#readBytes(offset, buffer.length, true);
|
|
159
|
+
this.packet.fill(buffer, packetOffset, writeEndPos);
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Read bits from buffer
|
|
163
|
+
* @param offset
|
|
164
|
+
* @param length
|
|
165
|
+
* @param bitOffset
|
|
166
|
+
* @param bitLength
|
|
167
|
+
* @protected
|
|
168
|
+
*/
|
|
169
|
+
readBits(offset, length, bitOffset, bitLength) {
|
|
170
|
+
const buffer = this.#readBytes(offset, length, false);
|
|
171
|
+
const bitString = parseInt(buffer.toString('hex'), 16).toString(2).padStart(length * 8, '0');
|
|
172
|
+
return parseInt(bitString.substring(bitOffset, bitOffset + bitLength), 2);
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Write bits to buffer
|
|
176
|
+
* @param offset
|
|
177
|
+
* @param length
|
|
178
|
+
* @param bitOffset
|
|
179
|
+
* @param bitLength
|
|
180
|
+
* @param value
|
|
181
|
+
* @protected
|
|
182
|
+
*/
|
|
183
|
+
writeBits(offset, length, bitOffset, bitLength, value) {
|
|
184
|
+
const buffer = this.#readBytes(offset, length, true);
|
|
185
|
+
let bitArray = Array.from(parseInt(buffer.toString('hex'), 16).toString(2).padStart(buffer.length * 8, '0'));
|
|
186
|
+
const valueBitArray = Array.from(value.toString(2).padStart(bitLength, '0'));
|
|
187
|
+
bitArray = bitArray.map((bit, index) => {
|
|
188
|
+
if (index < bitOffset)
|
|
189
|
+
return bit;
|
|
190
|
+
if (index >= (bitOffset + bitLength))
|
|
191
|
+
return bit;
|
|
192
|
+
return valueBitArray[index - bitOffset];
|
|
193
|
+
});
|
|
194
|
+
this.writeBytes(offset, Buffer.from(parseInt(bitArray.join(''), 2).toString(16).padStart(buffer.length * 2, '0'), 'hex'));
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Get field codecs from schema tree
|
|
198
|
+
* @param schema
|
|
199
|
+
* @param codecName
|
|
200
|
+
* @param execBeforeSubCodecs
|
|
201
|
+
* @param codecs
|
|
202
|
+
* @protected
|
|
203
|
+
*/
|
|
204
|
+
getFieldCodecs(schema, codecName, execBeforeSubCodecs, codecs = []) {
|
|
205
|
+
if (!schema.properties)
|
|
206
|
+
return codecs;
|
|
207
|
+
for (const propertyName of Object.keys(schema.properties)) {
|
|
208
|
+
const fieldSchema = schema.properties[propertyName];
|
|
209
|
+
let codec = fieldSchema[codecName];
|
|
210
|
+
if (!codec)
|
|
211
|
+
codec = async () => (void (0));
|
|
212
|
+
if (execBeforeSubCodecs)
|
|
213
|
+
codecs.push(async () => await codec());
|
|
214
|
+
if (fieldSchema.properties)
|
|
215
|
+
this.getFieldCodecs(fieldSchema, codecName, execBeforeSubCodecs, codecs);
|
|
216
|
+
if (!execBeforeSubCodecs)
|
|
217
|
+
codecs.push(async () => await codec());
|
|
218
|
+
}
|
|
219
|
+
return codecs;
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Record encode/decode error
|
|
223
|
+
* @param path
|
|
224
|
+
* @param message
|
|
225
|
+
* @protected
|
|
226
|
+
*/
|
|
227
|
+
recordError(path, message) {
|
|
228
|
+
this.errors.push({
|
|
229
|
+
id: this.id,
|
|
230
|
+
path: path,
|
|
231
|
+
message: message
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Register post encode handler for current codec
|
|
236
|
+
* @param handler
|
|
237
|
+
* @param priority
|
|
238
|
+
* @protected
|
|
239
|
+
*/
|
|
240
|
+
addPostSelfEncodeHandler(handler, priority = 0) {
|
|
241
|
+
this.postSelfEncodeHandlers.push({
|
|
242
|
+
priority: priority,
|
|
243
|
+
handler: handler
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Register post decode handler for current codec
|
|
248
|
+
* @param handler
|
|
249
|
+
* @param priority
|
|
250
|
+
* @protected
|
|
251
|
+
*/
|
|
252
|
+
addPostSelfDecodeHandler(handler, priority = 0) {
|
|
253
|
+
this.postSelfDecodeHandlers.push({
|
|
254
|
+
priority: priority,
|
|
255
|
+
handler: handler
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Register post encode handler for packet
|
|
260
|
+
* @description Registered handler call sequence: LIFO (Last In First Out)
|
|
261
|
+
* @param handler
|
|
262
|
+
* @param priority
|
|
263
|
+
* @protected
|
|
264
|
+
*/
|
|
265
|
+
addPostPacketEncodeHandler(handler, priority = 0) {
|
|
266
|
+
this.postPacketHandlers.push({
|
|
267
|
+
priority: priority,
|
|
268
|
+
handler: handler
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* Register post decode handler for packet
|
|
273
|
+
* @description Registered handler call sequence: FIFO (First In First Out)
|
|
274
|
+
* @param handler
|
|
275
|
+
* @param priority
|
|
276
|
+
* @protected
|
|
277
|
+
*/
|
|
278
|
+
addPostPacketDecodeHandler(handler, priority = 0) {
|
|
279
|
+
this.postPacketHandlers.push({
|
|
280
|
+
priority: priority,
|
|
281
|
+
handler: handler
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Validate input json node is valid
|
|
286
|
+
* @param headerTreeNode
|
|
287
|
+
*/
|
|
288
|
+
validate(headerTreeNode) {
|
|
289
|
+
let validate = this.constructor[CONSTRUCTOR_VALIDATE_KEY];
|
|
290
|
+
if (!validate) {
|
|
291
|
+
validate = new ajv_1.Ajv({
|
|
292
|
+
strict: false,
|
|
293
|
+
useDefaults: true,
|
|
294
|
+
coerceTypes: true
|
|
295
|
+
}).compile(this.SCHEMA);
|
|
296
|
+
this.constructor[CONSTRUCTOR_VALIDATE_KEY] = validate;
|
|
297
|
+
}
|
|
298
|
+
const isValid = validate(headerTreeNode);
|
|
299
|
+
if (!isValid) {
|
|
300
|
+
let errorObject;
|
|
301
|
+
if (validate.errors)
|
|
302
|
+
errorObject = validate.errors[0];
|
|
303
|
+
const errorMessage = errorObject?.message ? errorObject.message : 'Unknown Error';
|
|
304
|
+
throw new CodecSchemaValidateError_1.CodecSchemaValidateError(errorMessage);
|
|
305
|
+
}
|
|
306
|
+
return headerTreeNode;
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* Decode packet header field by field
|
|
310
|
+
*/
|
|
311
|
+
async decode() {
|
|
312
|
+
const decodes = this.getFieldCodecs(this.SCHEMA, 'decode', true);
|
|
313
|
+
for (const decode of decodes) {
|
|
314
|
+
await decode();
|
|
315
|
+
}
|
|
316
|
+
const postSelfDecodeHandlers = (0, SortPostHandlers_1.SortPostHandlers)(this.postSelfDecodeHandlers);
|
|
317
|
+
let postDecodeHandler = postSelfDecodeHandlers.shift();
|
|
318
|
+
while (postDecodeHandler) {
|
|
319
|
+
await postDecodeHandler.handler();
|
|
320
|
+
postDecodeHandler = postSelfDecodeHandlers.shift();
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
/**
|
|
324
|
+
* Encode packet header field by field
|
|
325
|
+
*/
|
|
326
|
+
async encode() {
|
|
327
|
+
const encodes = this.getFieldCodecs(this.SCHEMA, 'encode', false);
|
|
328
|
+
for (const encode of encodes) {
|
|
329
|
+
await encode();
|
|
330
|
+
}
|
|
331
|
+
const postSelfEncodeHandlers = (0, SortPostHandlers_1.SortPostHandlers)(this.postSelfEncodeHandlers);
|
|
332
|
+
let postEncodeHandler = postSelfEncodeHandlers.shift();
|
|
333
|
+
while (postEncodeHandler) {
|
|
334
|
+
await postEncodeHandler.handler();
|
|
335
|
+
postEncodeHandler = postSelfEncodeHandlers.shift();
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
exports.BaseHeader = BaseHeader;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ProtocolJSONSchema } from '../../schema/ProtocolJSONSchema';
|
|
2
|
+
import { BaseHeader } from '../abstracts/BaseHeader';
|
|
3
|
+
export declare class ARP extends BaseHeader {
|
|
4
|
+
SCHEMA: ProtocolJSONSchema;
|
|
5
|
+
id: string;
|
|
6
|
+
name: string;
|
|
7
|
+
match(): boolean;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=ARP.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ARP.d.ts","sourceRoot":"","sources":["../../../../src/lib/codec/headers/ARP.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,kBAAkB,EAAC,MAAM,iCAAiC,CAAA;AAClE,OAAO,EAAC,UAAU,EAAC,MAAM,yBAAyB,CAAA;AAUlD,qBAAa,GAAI,SAAQ,UAAU;IAExB,MAAM,EAAE,kBAAkB,CAiMhC;IAEM,EAAE,EAAE,MAAM,CAAQ;IAElB,IAAI,EAAE,MAAM,CAAgC;IAE5C,KAAK,IAAI,OAAO;CAK1B"}
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ARP = void 0;
|
|
4
|
+
const BaseHeader_1 = require("../abstracts/BaseHeader");
|
|
5
|
+
const NumberToHex_1 = require("../lib/NumberToHex");
|
|
6
|
+
const StringContentEncodingEnum_1 = require("../lib/StringContentEncodingEnum");
|
|
7
|
+
const HexToNumber_1 = require("../lib/HexToNumber");
|
|
8
|
+
const BufferToNumber_1 = require("../lib/BufferToNumber");
|
|
9
|
+
const BufferToHex_1 = require("../lib/BufferToHex");
|
|
10
|
+
const NumberToBuffer_1 = require("../lib/NumberToBuffer");
|
|
11
|
+
const BufferToIP_1 = require("../lib/BufferToIP");
|
|
12
|
+
const IPToBuffer_1 = require("../lib/IPToBuffer");
|
|
13
|
+
class ARP extends BaseHeader_1.BaseHeader {
|
|
14
|
+
constructor() {
|
|
15
|
+
super(...arguments);
|
|
16
|
+
this.SCHEMA = {
|
|
17
|
+
type: 'object',
|
|
18
|
+
properties: {
|
|
19
|
+
hardware: {
|
|
20
|
+
type: 'object',
|
|
21
|
+
label: 'Hardware',
|
|
22
|
+
properties: {
|
|
23
|
+
type: {
|
|
24
|
+
type: 'number',
|
|
25
|
+
label: 'Type',
|
|
26
|
+
minimum: 0,
|
|
27
|
+
maximum: 65535,
|
|
28
|
+
decode: () => {
|
|
29
|
+
this.instance.hardware.type.setValue((0, BufferToNumber_1.BufferToInt16)(this.readBytes(0, 2)));
|
|
30
|
+
},
|
|
31
|
+
encode: () => {
|
|
32
|
+
let hwType = this.instance.hardware.type.getValue(0, (nodePath) => this.recordError(nodePath, 'Not Found'));
|
|
33
|
+
if (hwType > 65535) {
|
|
34
|
+
this.recordError(this.instance.hardware.type.getPath(), 'Maximum value is 65535');
|
|
35
|
+
hwType = 65535;
|
|
36
|
+
}
|
|
37
|
+
if (hwType < 0) {
|
|
38
|
+
this.recordError(this.instance.hardware.type.getPath(), 'Minimum value is 0');
|
|
39
|
+
hwType = 0;
|
|
40
|
+
}
|
|
41
|
+
this.instance.hardware.type.setValue(hwType);
|
|
42
|
+
this.writeBytes(0, (0, NumberToBuffer_1.UInt16ToBuffer)(hwType));
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
size: {
|
|
46
|
+
type: 'number',
|
|
47
|
+
label: 'Size',
|
|
48
|
+
minimum: 0,
|
|
49
|
+
maximum: 255,
|
|
50
|
+
decode: () => {
|
|
51
|
+
this.instance.hardware.size.setValue((0, BufferToNumber_1.BufferToUInt8)(this.readBytes(4, 1)));
|
|
52
|
+
},
|
|
53
|
+
encode: () => {
|
|
54
|
+
let hwSize = this.instance.hardware.size.getValue(0, (nodePath) => this.recordError(nodePath, 'Not Found'));
|
|
55
|
+
if (hwSize > 255) {
|
|
56
|
+
this.recordError(this.instance.hardware.size.getPath(), 'Maximum value is 255');
|
|
57
|
+
hwSize = 255;
|
|
58
|
+
}
|
|
59
|
+
if (hwSize < 0) {
|
|
60
|
+
this.recordError(this.instance.hardware.size.getPath(), 'Minimum value is 0');
|
|
61
|
+
hwSize = 0;
|
|
62
|
+
}
|
|
63
|
+
this.instance.hardware.size.setValue(hwSize);
|
|
64
|
+
this.writeBytes(4, (0, NumberToBuffer_1.UInt8ToBuffer)(hwSize));
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
protocol: {
|
|
70
|
+
type: 'object',
|
|
71
|
+
label: 'Protocol',
|
|
72
|
+
properties: {
|
|
73
|
+
type: {
|
|
74
|
+
type: 'string',
|
|
75
|
+
label: 'Type',
|
|
76
|
+
minLength: 4,
|
|
77
|
+
maxLength: 4,
|
|
78
|
+
contentEncoding: StringContentEncodingEnum_1.StringContentEncodingEnum.HEX,
|
|
79
|
+
decode: () => {
|
|
80
|
+
this.instance.protocol.type.setValue((0, BufferToHex_1.BufferToHex)(this.readBytes(2, 2)));
|
|
81
|
+
},
|
|
82
|
+
encode: () => {
|
|
83
|
+
let protoTypeHex = this.instance.protocol.type.getValue('0000', (nodePath) => this.recordError(nodePath, 'Not Found'));
|
|
84
|
+
let protoType = (0, HexToNumber_1.HexToUInt16)(protoTypeHex);
|
|
85
|
+
if (isNaN(protoType)) {
|
|
86
|
+
this.recordError(this.instance.protocol.type.getPath(), 'Invalid hex value');
|
|
87
|
+
protoType = 0;
|
|
88
|
+
}
|
|
89
|
+
this.instance.protocol.type.setValue(protoType);
|
|
90
|
+
this.writeBytes(2, (0, NumberToBuffer_1.UInt16ToBuffer)(protoType));
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
size: {
|
|
94
|
+
type: 'number',
|
|
95
|
+
label: 'Size',
|
|
96
|
+
minimum: 0,
|
|
97
|
+
maximum: 255,
|
|
98
|
+
decode: () => {
|
|
99
|
+
this.instance.protocol.size.setValue((0, BufferToNumber_1.BufferToUInt8)(this.readBytes(5, 1)));
|
|
100
|
+
},
|
|
101
|
+
encode: () => {
|
|
102
|
+
let protoSize = this.instance.protocol.size.getValue(0, (nodePath) => this.recordError(nodePath, 'Not Found'));
|
|
103
|
+
if (protoSize > 255) {
|
|
104
|
+
this.recordError(this.instance.protocol.size.getPath(), 'Maximum value is 255');
|
|
105
|
+
protoSize = 255;
|
|
106
|
+
}
|
|
107
|
+
if (protoSize < 0) {
|
|
108
|
+
this.recordError(this.instance.protocol.size.getPath(), 'Minimum value is 0');
|
|
109
|
+
protoSize = 0;
|
|
110
|
+
}
|
|
111
|
+
this.instance.protocol.size.setValue(protoSize);
|
|
112
|
+
this.writeBytes(5, (0, NumberToBuffer_1.UInt8ToBuffer)(protoSize));
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
opcode: {
|
|
118
|
+
type: 'number',
|
|
119
|
+
label: 'Opcode',
|
|
120
|
+
enum: [1, 2, 3, 4],
|
|
121
|
+
decode: () => {
|
|
122
|
+
this.instance.opcode.setValue((0, BufferToNumber_1.BufferToUInt16)(this.readBytes(6, 2)));
|
|
123
|
+
if (![1, 2, 3, 4].includes(this.instance.opcode.getValue()))
|
|
124
|
+
this.recordError(this.instance.opcode.getPath(), 'Opcode should be 1, 2, 3 or 4');
|
|
125
|
+
},
|
|
126
|
+
encode: () => {
|
|
127
|
+
let opcode = this.instance.opcode.getValue(0, (nodePath) => this.recordError(nodePath, 'Not Found'));
|
|
128
|
+
if (![1, 2, 3, 4].includes(opcode))
|
|
129
|
+
this.recordError(this.instance.opcode.getPath(), 'Opcode should be 1, 2, 3 or 4');
|
|
130
|
+
this.instance.opcode.setValue(opcode);
|
|
131
|
+
this.writeBytes(6, (0, NumberToBuffer_1.UInt16ToBuffer)(opcode));
|
|
132
|
+
}
|
|
133
|
+
},
|
|
134
|
+
sender: {
|
|
135
|
+
type: 'object',
|
|
136
|
+
label: 'Sender',
|
|
137
|
+
properties: {
|
|
138
|
+
mac: {
|
|
139
|
+
type: 'string',
|
|
140
|
+
label: 'MAC address',
|
|
141
|
+
minLength: 17,
|
|
142
|
+
maxLength: 17,
|
|
143
|
+
contentEncoding: StringContentEncodingEnum_1.StringContentEncodingEnum.UTF8,
|
|
144
|
+
decode: () => {
|
|
145
|
+
const macAddrBuffer = Buffer.alloc(6, this.readBytes(8, 6));
|
|
146
|
+
this.instance.sender.mac.setValue(Array.from(macAddrBuffer).map((value) => (0, NumberToHex_1.UInt8ToHex)(value)).join(':'));
|
|
147
|
+
},
|
|
148
|
+
encode: () => {
|
|
149
|
+
let macStr = this.instance.sender.mac.getValue();
|
|
150
|
+
const rawMacBuffer = Buffer.from(macStr.split(':').map((value) => parseInt(value, 16)).map((value) => value ? value : 0));
|
|
151
|
+
if (rawMacBuffer.length !== 6)
|
|
152
|
+
this.recordError(this.instance.sender.mac.getPath(), 'Invalid MAC address length');
|
|
153
|
+
this.writeBytes(8, Buffer.alloc(6, rawMacBuffer));
|
|
154
|
+
}
|
|
155
|
+
},
|
|
156
|
+
ipv4: {
|
|
157
|
+
type: 'string',
|
|
158
|
+
label: 'IP address',
|
|
159
|
+
minLength: 7,
|
|
160
|
+
maxLength: 15,
|
|
161
|
+
contentEncoding: StringContentEncodingEnum_1.StringContentEncodingEnum.UTF8,
|
|
162
|
+
decode: () => {
|
|
163
|
+
const ipv4Buffer = Buffer.alloc(4, this.readBytes(14, 4));
|
|
164
|
+
this.instance.sender.ipv4.setValue((0, BufferToIP_1.BufferToIPv4)(ipv4Buffer));
|
|
165
|
+
},
|
|
166
|
+
encode: () => {
|
|
167
|
+
let ipv4Str = this.instance.sender.ipv4.getValue();
|
|
168
|
+
this.writeBytes(14, (0, IPToBuffer_1.IPv4ToBuffer)(ipv4Str));
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
},
|
|
173
|
+
target: {
|
|
174
|
+
type: 'object',
|
|
175
|
+
label: 'Target',
|
|
176
|
+
properties: {
|
|
177
|
+
mac: {
|
|
178
|
+
type: 'string',
|
|
179
|
+
label: 'MAC address',
|
|
180
|
+
minLength: 17,
|
|
181
|
+
maxLength: 17,
|
|
182
|
+
contentEncoding: StringContentEncodingEnum_1.StringContentEncodingEnum.UTF8,
|
|
183
|
+
decode: () => {
|
|
184
|
+
const macAddrBuffer = Buffer.alloc(6, this.readBytes(18, 6));
|
|
185
|
+
this.instance.target.mac.setValue(Array.from(macAddrBuffer).map((value) => (0, NumberToHex_1.UInt8ToHex)(value)).join(':'));
|
|
186
|
+
},
|
|
187
|
+
encode: () => {
|
|
188
|
+
let macStr = this.instance.target.mac.getValue();
|
|
189
|
+
const rawMacBuffer = Buffer.from(macStr.split(':').map((value) => parseInt(value, 16)).map((value) => value ? value : 0));
|
|
190
|
+
if (rawMacBuffer.length !== 6)
|
|
191
|
+
this.recordError(this.instance.target.mac.getPath(), 'Invalid MAC address length');
|
|
192
|
+
this.writeBytes(18, Buffer.alloc(6, rawMacBuffer));
|
|
193
|
+
}
|
|
194
|
+
},
|
|
195
|
+
ipv4: {
|
|
196
|
+
type: 'string',
|
|
197
|
+
label: 'IP address',
|
|
198
|
+
minLength: 7,
|
|
199
|
+
maxLength: 15,
|
|
200
|
+
contentEncoding: StringContentEncodingEnum_1.StringContentEncodingEnum.UTF8,
|
|
201
|
+
decode: () => {
|
|
202
|
+
const ipv4Buffer = Buffer.alloc(4, this.readBytes(24, 4));
|
|
203
|
+
this.instance.target.ipv4.setValue((0, BufferToIP_1.BufferToIPv4)(ipv4Buffer));
|
|
204
|
+
},
|
|
205
|
+
encode: () => {
|
|
206
|
+
let ipv4Str = this.instance.target.ipv4.getValue();
|
|
207
|
+
this.writeBytes(24, (0, IPToBuffer_1.IPv4ToBuffer)(ipv4Str));
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
this.id = 'arp';
|
|
215
|
+
this.name = 'Address Resolution Protocol';
|
|
216
|
+
}
|
|
217
|
+
match() {
|
|
218
|
+
if (!this.prevCodecModule)
|
|
219
|
+
return false;
|
|
220
|
+
return this.prevCodecModule.instance.etherType.getValue() === (0, NumberToHex_1.UInt16ToHex)(0x0806);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
exports.ARP = ARP;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { BaseHeader } from '../abstracts/BaseHeader';
|
|
2
|
+
import { ProtocolJSONSchema } from '../../schema/ProtocolJSONSchema';
|
|
3
|
+
export declare class EthernetII extends BaseHeader {
|
|
4
|
+
readonly id: string;
|
|
5
|
+
readonly name: string;
|
|
6
|
+
readonly SCHEMA: ProtocolJSONSchema;
|
|
7
|
+
match(): boolean;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=EthernetII.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EthernetII.d.ts","sourceRoot":"","sources":["../../../../src/lib/codec/headers/EthernetII.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,yBAAyB,CAAA;AAClD,OAAO,EAAC,kBAAkB,EAAC,MAAM,iCAAiC,CAAA;AAIlE,qBAAa,UAAW,SAAQ,UAAU;IAEtC,SAAgB,EAAE,EAAE,MAAM,CAAQ;IAElC,SAAgB,IAAI,EAAE,MAAM,CAAgB;IAE5C,SAAgB,MAAM,EAAE,kBAAkB,CA0DzC;IAEM,KAAK,IAAI,OAAO;CAK1B"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EthernetII = void 0;
|
|
4
|
+
const BaseHeader_1 = require("../abstracts/BaseHeader");
|
|
5
|
+
const NumberToHex_1 = require("../lib/NumberToHex");
|
|
6
|
+
const StringContentEncodingEnum_1 = require("../lib/StringContentEncodingEnum");
|
|
7
|
+
class EthernetII extends BaseHeader_1.BaseHeader {
|
|
8
|
+
constructor() {
|
|
9
|
+
super(...arguments);
|
|
10
|
+
this.id = 'eth';
|
|
11
|
+
this.name = 'Ethernet II';
|
|
12
|
+
this.SCHEMA = {
|
|
13
|
+
type: 'object',
|
|
14
|
+
properties: {
|
|
15
|
+
dmac: {
|
|
16
|
+
type: 'string',
|
|
17
|
+
minLength: 17,
|
|
18
|
+
maxLength: 17,
|
|
19
|
+
label: 'Destination',
|
|
20
|
+
contentEncoding: StringContentEncodingEnum_1.StringContentEncodingEnum.UTF8,
|
|
21
|
+
decode: () => {
|
|
22
|
+
this.instance.dmac.setValue(Array.from(this.readBytes(0, 6)).map(value => value.toString(16).padStart(2, '0')).join(':'));
|
|
23
|
+
},
|
|
24
|
+
encode: () => {
|
|
25
|
+
const dmac = this.instance.dmac
|
|
26
|
+
.getValue('00:00:00:00:00:00', (nodePath) => this.recordError(nodePath, 'Not Found'))
|
|
27
|
+
.toString()
|
|
28
|
+
.split(':')
|
|
29
|
+
.map((value) => parseInt(value, 16))
|
|
30
|
+
.map((value) => value ? value : 0);
|
|
31
|
+
this.writeBytes(0, Buffer.alloc(6, Buffer.from(dmac)));
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
smac: {
|
|
35
|
+
type: 'string',
|
|
36
|
+
minLength: 17,
|
|
37
|
+
maxLength: 17,
|
|
38
|
+
label: 'Source',
|
|
39
|
+
contentEncoding: StringContentEncodingEnum_1.StringContentEncodingEnum.UTF8,
|
|
40
|
+
decode: () => {
|
|
41
|
+
this.instance.smac.setValue(Array.from(this.readBytes(6, 6)).map(value => value.toString(16).padStart(2, '0')).join(':'));
|
|
42
|
+
},
|
|
43
|
+
encode: () => {
|
|
44
|
+
const smac = this.instance.smac
|
|
45
|
+
.getValue('00:00:00:00:00:00', (nodePath) => this.recordError(nodePath, 'Not Found'))
|
|
46
|
+
.toString()
|
|
47
|
+
.split(':')
|
|
48
|
+
.map((value) => parseInt(value, 16))
|
|
49
|
+
.map((value) => value ? value : 0);
|
|
50
|
+
this.writeBytes(6, Buffer.alloc(6, Buffer.from(smac)));
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
etherType: {
|
|
54
|
+
type: 'string',
|
|
55
|
+
minLength: 4,
|
|
56
|
+
maxLength: 4,
|
|
57
|
+
label: 'EtherType',
|
|
58
|
+
contentEncoding: StringContentEncodingEnum_1.StringContentEncodingEnum.HEX,
|
|
59
|
+
decode: () => {
|
|
60
|
+
this.instance.etherType.setValue(this.readBytes(12, 2).toString('hex').padStart(4, '0'));
|
|
61
|
+
},
|
|
62
|
+
encode: () => {
|
|
63
|
+
let etherType = this.instance.etherType.getValue((0, NumberToHex_1.UInt16ToHex)(0x0000), (nodePath) => this.recordError(nodePath, 'Not Found'));
|
|
64
|
+
const typeBuffer = Buffer.from(etherType, 'hex');
|
|
65
|
+
if (typeBuffer.length < 2)
|
|
66
|
+
typeBuffer.fill(0, 0, 1);
|
|
67
|
+
this.writeBytes(12, typeBuffer.subarray(0, 2));
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
match() {
|
|
74
|
+
const specialScenes = ['trill', 'vxlan', 'nvgre', 'mpls', 'qinq', 'gre', 'geneve'];
|
|
75
|
+
if (this.prevCodecModule && !specialScenes.includes(this.prevCodecModule.id))
|
|
76
|
+
return false;
|
|
77
|
+
return true;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
exports.EthernetII = EthernetII;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ProtocolJSONSchema } from '../../schema/ProtocolJSONSchema';
|
|
2
|
+
import { BaseHeader } from '../abstracts/BaseHeader';
|
|
3
|
+
import TLV from 'node-tlv';
|
|
4
|
+
export declare class Goose extends BaseHeader {
|
|
5
|
+
protected TLVInstance: TLV;
|
|
6
|
+
protected TLVChild: TLV[];
|
|
7
|
+
SCHEMA: ProtocolJSONSchema;
|
|
8
|
+
id: string;
|
|
9
|
+
name: string;
|
|
10
|
+
match(): boolean;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=Goose.d.ts.map
|