[ 
https://issues.apache.org/jira/browse/DRILL-7385?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16948649#comment-16948649
 ] 

ASF GitHub Bot commented on DRILL-7385:
---------------------------------------

cgivre commented on pull request #1862: DRILL-7385: Convert PCAP Format Plugin 
to EVF
URL: https://github.com/apache/drill/pull/1862#discussion_r333559761
 
 

 ##########
 File path: 
exec/java-exec/src/main/java/org/apache/drill/exec/store/pcap/PcapBatchReader.java
 ##########
 @@ -0,0 +1,323 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.drill.exec.store.pcap;
+
+import org.apache.drill.common.exceptions.UserException;
+import 
org.apache.drill.exec.physical.impl.scan.file.FileScanFramework.FileSchemaNegotiator;
+import org.apache.drill.exec.physical.impl.scan.framework.ManagedReader;
+import org.apache.drill.exec.physical.resultSet.ResultSetLoader;
+import org.apache.drill.exec.physical.resultSet.RowSetLoader;
+import org.apache.drill.exec.record.metadata.SchemaBuilder;
+import org.apache.drill.exec.record.metadata.TupleMetadata;
+import org.apache.drill.exec.store.pcap.decoder.Packet;
+import org.apache.drill.exec.store.pcap.decoder.PacketDecoder;
+import org.apache.drill.exec.store.pcap.schema.Schema;
+import org.apache.drill.exec.vector.accessor.ScalarWriter;
+import org.apache.hadoop.fs.FSDataInputStream;
+import org.apache.hadoop.mapred.FileSplit;
+import org.joda.time.Instant;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+
+import org.apache.hadoop.fs.Path;
+
+import static 
org.apache.drill.exec.store.pcap.PcapFormatUtils.parseBytesToASCII;
+
+public class PcapBatchReader implements ManagedReader<FileSchemaNegotiator> {
+
+  static final int BUFFER_SIZE = 500_000;
+
+  private static final Logger logger = 
LoggerFactory.getLogger(PcapBatchReader.class);
+
+  private FileSplit split;
+
+  private PcapReaderConfig readerConfig;
+
+  private PacketDecoder decoder;
+
+  private ResultSetLoader loader;
+
+  private FSDataInputStream fsStream;
+
+  private Schema pcapSchema;
+
+  private RowSetLoader rowWriter;
+
+  private int validBytes;
+
+  private byte[] buffer;
+
+  private int offset;
+
+  private ScalarWriter typeWriter;
+
+  private ScalarWriter timestampWriter;
+
+  private ScalarWriter timestampMicroWriter;
+
+  private ScalarWriter networkWriter;
+
+  private ScalarWriter srcMacAddressWriter;
+
+  private ScalarWriter dstMacAddressWriter;
+
+  private ScalarWriter dstIPWriter;
+
+  private ScalarWriter srcIPWriter;
+
+  private ScalarWriter srcPortWriter;
+
+  private ScalarWriter dstPortWriter;
+
+  private ScalarWriter packetLengthWriter;
+
+  private ScalarWriter tcpSessionWriter;
+
+  private ScalarWriter tcpSequenceWriter;
+
+  private ScalarWriter tcpAckNumberWriter;
+
+  private ScalarWriter tcpFlagsWriter;
+
+  private ScalarWriter tcpParsedFlagsWriter;
+
+  private ScalarWriter tcpNsWriter;
+
+  private ScalarWriter tcpCwrWriter;
+
+  private ScalarWriter tcpEceWriter;
+
+  private ScalarWriter tcpFlagsEceEcnCapableWriter;
+
+  private ScalarWriter tcpFlagsCongestionWriter;
+
+  private ScalarWriter tcpUrgWriter;
+
+  private ScalarWriter tcpAckWriter;
+
+  private ScalarWriter tcpPshWriter;
+
+  private ScalarWriter tcpRstWriter;
+
+  private ScalarWriter tcpSynWriter;
+
+  private ScalarWriter tcpFinWriter;
+
+  private ScalarWriter dataWriter;
+
+  private ScalarWriter isCorruptWriter;
+
+
+  public static class PcapReaderConfig {
+
+    protected final PcapFormatPlugin plugin;
+
+    public PcapReaderConfig(PcapFormatPlugin plugin) {
+      this.plugin = plugin;
+    }
+  }
+
+  public PcapBatchReader(PcapReaderConfig readerConfig) {
+    this.readerConfig = readerConfig;
+  }
+
+  @Override
+  public boolean open(FileSchemaNegotiator negotiator) {
+    split = negotiator.split();
+    openFile(negotiator);
+    SchemaBuilder builder = new SchemaBuilder();
+    pcapSchema = new Schema();
+    TupleMetadata schema = pcapSchema.buildSchema(builder);
+    negotiator.setTableSchema(schema, false);
+    loader = negotiator.build();
+
+    // Creates writers for all fields (Since schema is known)
+    rowWriter = loader.writer();
+    typeWriter = rowWriter.scalar("type");
+    timestampWriter = rowWriter.scalar("packet_timestamp");
+    timestampMicroWriter = rowWriter.scalar("timestamp_micro");
+    networkWriter = rowWriter.scalar("network");
+    srcMacAddressWriter = rowWriter.scalar("src_mac_address");
+    dstMacAddressWriter = rowWriter.scalar("dst_mac_address");
+    dstIPWriter = rowWriter.scalar("dst_ip");
+    srcIPWriter = rowWriter.scalar("src_ip");
+    srcPortWriter = rowWriter.scalar("src_port");
+    dstPortWriter = rowWriter.scalar("dst_port");
+    packetLengthWriter = rowWriter.scalar("packet_length");
+
+    //Writers for TCP Packets
+    tcpSessionWriter = rowWriter.scalar("tcp_session");
+    tcpSequenceWriter = rowWriter.scalar("tcp_sequence");
+    tcpAckNumberWriter = rowWriter.scalar("tcp_ack");
+    tcpFlagsWriter = rowWriter.scalar("tcp_flags");
+    tcpParsedFlagsWriter = rowWriter.scalar("tcp_parsed_flags");
+    tcpNsWriter = rowWriter.scalar("tcp_flags_ns");
+    tcpCwrWriter = rowWriter.scalar("tcp_flags_cwr");
+    tcpEceWriter = rowWriter.scalar("tcp_flags_ece");
+    tcpFlagsEceEcnCapableWriter = 
rowWriter.scalar("tcp_flags_ece_ecn_capable");
+    tcpFlagsCongestionWriter = 
rowWriter.scalar("tcp_flags_ece_congestion_experienced");
+
+    tcpUrgWriter = rowWriter.scalar("tcp_flags_urg");
+    tcpAckWriter = rowWriter.scalar("tcp_flags_ack");
+    tcpPshWriter = rowWriter.scalar("tcp_flags_psh");
+    tcpRstWriter = rowWriter.scalar("tcp_flags_rst");
+    tcpSynWriter = rowWriter.scalar("tcp_flags_syn");
+    tcpFinWriter = rowWriter.scalar("tcp_flags_fin");
+
+    dataWriter = rowWriter.scalar("data");
+    isCorruptWriter = rowWriter.scalar("is_corrupt");
+
+    return true;
+  }
+
+  @Override
+  public boolean next() {
+    while (!rowWriter.isFull()) {
+      if (!parseNextPacket(rowWriter)) {
+        return false;
+      }
+    }
+    return true;
+  }
+
+  @Override
+  public void close() {
+    try {
+      fsStream.close();
+    } catch (IOException e) {
+      throw UserException.
+        dataReadError().addContext("Error closing InputStream: " + 
e.getMessage()).build(logger);
 
 Review comment:
   Fixed
 
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> Convert PCAP Format Plugin to EVF
> ---------------------------------
>
>                 Key: DRILL-7385
>                 URL: https://issues.apache.org/jira/browse/DRILL-7385
>             Project: Apache Drill
>          Issue Type: Improvement
>    Affects Versions: 1.16.0
>            Reporter: Charles Givre
>            Assignee: Charles Givre
>            Priority: Major
>             Fix For: 1.17.0
>
>
> The PCAP format plugin has the possibility of extracting considerably more 
> data out of PCAP files.  To facilitate this, this PR updates the plugin to 
> use the new Enhanced Vector Framework.  No changes in functionality should 
> occur.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to