You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@metron.apache.org by ce...@apache.org on 2016/03/21 18:05:54 UTC

[12/43] incubator-metron git commit: METRON-55 (nickwallen via cestella) closes apache/incubator-metron#32

METRON-55 (nickwallen via cestella) closes apache/incubator-metron#32


Project: http://git-wip-us.apache.org/repos/asf/incubator-metron/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-metron/commit/a7e3879e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-metron/tree/a7e3879e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-metron/diff/a7e3879e

Branch: refs/heads/Metron_0.1BETA
Commit: a7e3879ed35200ff004351825ec594041f75f5d6
Parents: 0e1055a
Author: nickwallen <ni...@nickallen.org>
Authored: Tue Mar 1 11:59:32 2016 -0500
Committer: cstella <ce...@gmail.com>
Committed: Tue Mar 1 11:59:32 2016 -0500

----------------------------------------------------------------------
 deployment/roles/pcap_replay/README.md          | 27 ++++--
 deployment/roles/pcap_replay/files/pcap-replay  | 90 -------------------
 deployment/roles/pcap_replay/meta/main.yml      | 34 ++++++++
 deployment/roles/pcap_replay/tasks/main.yml     |  4 +-
 deployment/roles/pcap_replay/tasks/service.yml  | 14 +--
 .../roles/pcap_replay/tasks/tcpreplay.yml       |  4 +-
 .../roles/pcap_replay/templates/pcap-replay     | 92 ++++++++++++++++++++
 deployment/roles/pcap_replay/vars/main.yml      |  4 +-
 8 files changed, 159 insertions(+), 110 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-metron/blob/a7e3879e/deployment/roles/pcap_replay/README.md
----------------------------------------------------------------------
diff --git a/deployment/roles/pcap_replay/README.md b/deployment/roles/pcap_replay/README.md
index d6691a4..8bc92c9 100644
--- a/deployment/roles/pcap_replay/README.md
+++ b/deployment/roles/pcap_replay/README.md
@@ -1,23 +1,29 @@
 Pcap Replay
 ===========
 
-This will install components necessary to easily replay packet capture data to support functional performance, and load testing of Metron.
+This project enables packet capture data to be replayed through a network interface to simulate live network traffic.  This can be used to support functional, performance, and load testing of Apache Metron.
 
 Getting Started
 ---------------
 
-Pcap Replay is installed as a System V service at `/etc/init.d/pcap-replay`.  To start the service, run the following command.
+To replay packet capture data, simply start the `pcap-replay` SysV service.  To do this run the following command.
 
 ```
 service pcap-replay start
 ```
 
-An example packet capture file has been installed at `/opt/pcap-replay/example.pcap`.  By default, the network traffic contained within this file is continually replayed.  That's right, it will never, ever stop.  
+All additional options accepted by `tcpreplay` can be passed to the service script to modify how the network data is replayed.  For example, this makes it simple to control the amount and rate of data replayed during functional, performance and load testing.
 
-To replay your own packet capture data, simply add any number of files containing `libpcap` formatted packet capture data to `/opt/pcap-replay`.  The files must end with the `.pcap` file extension.  To pick up newly installed files, simply restart the service.
+Example: Replay data at a rate of 10 mbps.
 
 ```
-service pcap-replay restart
+service pcap-replay start --mbps 10
+```
+
+Example: Replay data at a rate of 10 packets per second.
+
+```
+service pcap-replay start --pps 10
 ```
 
 All nodes on the same subnet with their network interface set to promiscuous mode will then be able to capture the network traffic being replayed.  To validate, simply run something like the following.
@@ -25,3 +31,14 @@ All nodes on the same subnet with their network interface set to promiscuous mod
 ```
 tcpdump -i eth1
 ```
+
+Data
+----
+
+An example packet capture file has been installed at `/opt/pcap-replay/example.pcap`.  By default, the network traffic contained within this file is continually replayed.   
+
+To replay your own packet capture data, simply add any number of files containing `libpcap` formatted packet capture data to `/opt/pcap-replay`.  The files must end with the `.pcap` extension.  To pick up newly installed files, simply restart the service.
+
+```
+service pcap-replay restart
+```

http://git-wip-us.apache.org/repos/asf/incubator-metron/blob/a7e3879e/deployment/roles/pcap_replay/files/pcap-replay
----------------------------------------------------------------------
diff --git a/deployment/roles/pcap_replay/files/pcap-replay b/deployment/roles/pcap_replay/files/pcap-replay
deleted file mode 100644
index 87259b5..0000000
--- a/deployment/roles/pcap_replay/files/pcap-replay
+++ /dev/null
@@ -1,90 +0,0 @@
-#!/usr/bin/env bash
-#
-#  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.
-
-# pcap replay daemon
-# chkconfig: 345 20 80
-# description: Replays packet capture data stored in libpcap format
-# processname: pcap-replay
-#
-
-DAEMON_PATH="/opt/pcap-replay"
-PCAPIN=`ls $DAEMON_PATH/*.pcap 2> /dev/null`
-IFACE="{{ pcap_replay_interface | default("eth0") }}"
-DAEMON=/usr/local/bin/tcpreplay
-DAEMONOPTS="--intf1=$IFACE --loop=0 $PCAPIN"
-
-NAME=pcap-replay
-DESC="Replays packet capture data stored in libpcap format"
-PIDFILE=/var/run/$NAME.pid
-SCRIPTNAME=/etc/init.d/$NAME
-
-case "$1" in
-  start)
-    printf "%-50s" "Starting $NAME..."
-
-    # ensure that a pcap file exists to replay
-    if [ -z "$PCAPIN" ]; then
-      printf "%s: %s\n" "Fail: No pcap files found" $DAEMON_PATH
-    else
-      # kick-off the daemon
-      cd $DAEMON_PATH
-      PID=`$DAEMON $DAEMONOPTS > /dev/null 2>&1 & echo $!`
-      if [ -z $PID ]; then
-          printf "%s\n" "Fail"
-      else
-          echo $PID > $PIDFILE
-          printf "%s\n" "Ok"
-      fi
-    fi
-  ;;
-
-  status)
-    printf "%-50s" "Checking $NAME..."
-    if [ -f $PIDFILE ]; then
-      PID=`cat $PIDFILE`
-      if [ -z "`ps axf | grep ${PID} | grep -v grep`" ]; then
-        printf "%s\n" "Process dead but pidfile exists"
-      else
-        echo "Running"
-      fi
-    else
-      printf "%s\n" "Service not running"
-    fi
-  ;;
-
-  stop)
-    printf "%-50s" "Stopping $NAME"
-    PID=`cat $PIDFILE`
-    cd $DAEMON_PATH
-    if [ -f $PIDFILE ]; then
-        kill -HUP $PID
-        printf "%s\n" "Ok"
-        rm -f $PIDFILE
-    else
-        printf "%s\n" "pidfile not found"
-    fi
-  ;;
-
-  restart)
-    $0 stop
-    $0 start
-  ;;
-
-  *)
-    echo "Usage: $0 {status|start|stop|restart}"
-    exit 1
-esac

http://git-wip-us.apache.org/repos/asf/incubator-metron/blob/a7e3879e/deployment/roles/pcap_replay/meta/main.yml
----------------------------------------------------------------------
diff --git a/deployment/roles/pcap_replay/meta/main.yml b/deployment/roles/pcap_replay/meta/main.yml
new file mode 100644
index 0000000..2df379c
--- /dev/null
+++ b/deployment/roles/pcap_replay/meta/main.yml
@@ -0,0 +1,34 @@
+#
+#  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.
+#
+---
+galaxy_info:
+  author: Nick Allen
+  description:
+  company: Metron
+
+  license: license (Apache, CC-BY, Nick Allen)
+  min_ansible_version: 1.2
+
+  platforms:
+  - name: CentOS
+    versions:
+      - 6
+
+  categories:
+  - networking
+
+dependencies: []

http://git-wip-us.apache.org/repos/asf/incubator-metron/blob/a7e3879e/deployment/roles/pcap_replay/tasks/main.yml
----------------------------------------------------------------------
diff --git a/deployment/roles/pcap_replay/tasks/main.yml b/deployment/roles/pcap_replay/tasks/main.yml
index 842bb84..449710e 100644
--- a/deployment/roles/pcap_replay/tasks/main.yml
+++ b/deployment/roles/pcap_replay/tasks/main.yml
@@ -15,10 +15,12 @@
 #  limitations under the License.
 #
 ---
+- name: Install prerequisites
+  yum: name=libselinux-python
 
 - include: tcpreplay.yml
 
 - include: service.yml
 
 - name: Start the pcap-replay service
-  service: name=pcap-replay state=started
+  service: name=pcap-replay state=restarted

http://git-wip-us.apache.org/repos/asf/incubator-metron/blob/a7e3879e/deployment/roles/pcap_replay/tasks/service.yml
----------------------------------------------------------------------
diff --git a/deployment/roles/pcap_replay/tasks/service.yml b/deployment/roles/pcap_replay/tasks/service.yml
index ce52f50..8a549f7 100644
--- a/deployment/roles/pcap_replay/tasks/service.yml
+++ b/deployment/roles/pcap_replay/tasks/service.yml
@@ -16,18 +16,10 @@
 #
 ---
 - name: Create pcap directory
-  file: path={{ pcap_replay_path }} state=directory mode=0755
+  file: path={{ pcap_path }} state=directory mode=0755
 
 - name: Install init.d service script
-  template:
-    src: "../roles/pcap_replay/files/pcap-replay"
-    dest: "/etc/init.d/pcap-replay"
-    mode: 0755
-    owner: "root"
-    group: "root"
-
-- name: Set permissions on service script
-  file: path=/etc/init.d/pcap-replay mode=0755
+  template: src=pcap-replay dest=/etc/init.d/pcap-replay mode=0755
 
 - name: Install example pcap file
-  copy: src=example.pcap dest={{ pcap_replay_path }}/
+  copy: src=example.pcap dest={{ pcap_path }}/

http://git-wip-us.apache.org/repos/asf/incubator-metron/blob/a7e3879e/deployment/roles/pcap_replay/tasks/tcpreplay.yml
----------------------------------------------------------------------
diff --git a/deployment/roles/pcap_replay/tasks/tcpreplay.yml b/deployment/roles/pcap_replay/tasks/tcpreplay.yml
index 73be4ab..851a6ae 100644
--- a/deployment/roles/pcap_replay/tasks/tcpreplay.yml
+++ b/deployment/roles/pcap_replay/tasks/tcpreplay.yml
@@ -38,8 +38,8 @@
   shell: "{{ item }}"
   args:
     chdir: "/opt/tcpreplay-{{ tcpreplay_version }}"
-    creates: /usr/local/bin/tcpreplay
+    creates: "{{ tcpreplay_prefix }}/bin/tcpreplay"
   with_items:
-    - ./configure
+    - "./configure --prefix={{ tcpreplay_prefix }}"
     - make
     - make install

http://git-wip-us.apache.org/repos/asf/incubator-metron/blob/a7e3879e/deployment/roles/pcap_replay/templates/pcap-replay
----------------------------------------------------------------------
diff --git a/deployment/roles/pcap_replay/templates/pcap-replay b/deployment/roles/pcap_replay/templates/pcap-replay
new file mode 100644
index 0000000..56dc40c
--- /dev/null
+++ b/deployment/roles/pcap_replay/templates/pcap-replay
@@ -0,0 +1,92 @@
+#!/usr/bin/env bash
+#
+# 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.
+#
+# pcap replay daemon
+# chkconfig: 345 20 80
+# description: Replays packet capture data stored in libpcap format
+# processname: pcap-replay
+#
+
+DAEMON_PATH="{{ pcap_path }}"
+PCAPIN=`ls $DAEMON_PATH/*.pcap 2> /dev/null`
+IFACE="{{ pcap_replay_interface | default("eth0") }}"
+EXTRA_ARGS="${@:2}"
+DAEMON="{{ tcpreplay_prefix }}/bin/tcpreplay"
+DAEMONOPTS="--intf1=$IFACE --loop=0 $EXTRA_ARGS $PCAPIN"
+
+NAME=pcap-replay
+DESC="Replay packet capture data"
+PIDFILE=/var/run/$NAME.pid
+SCRIPTNAME=/etc/init.d/$NAME
+
+case "$1" in
+  start)
+    printf "%-50s" "Starting $NAME..."
+
+    # ensure that a pcap file exists to replay
+    if [ -z "$PCAPIN" ]; then
+      printf "%s: %s\n" "Fail: No pcap files found at " $DAEMON_PATH
+    else
+      # kick-off the daemon
+      cd $DAEMON_PATH
+      PID=`$DAEMON $DAEMONOPTS > /dev/null 2>&1 & echo $!`
+      if [ -z $PID ]; then
+          printf "%s\n" "Fail"
+      else
+          echo $PID > $PIDFILE
+          printf "%s\n" "Ok"
+      fi
+    fi
+  ;;
+
+  status)
+    printf "%-50s" "Checking $NAME..."
+    if [ -f $PIDFILE ]; then
+      PID=`cat $PIDFILE`
+      if [ -z "`ps axf | grep ${PID} | grep -v grep`" ]; then
+        printf "%s\n" "Process dead but pidfile exists"
+      else
+        echo "Running"
+      fi
+    else
+      printf "%s\n" "Service not running"
+    fi
+  ;;
+
+  stop)
+    printf "%-50s" "Stopping $NAME"
+    PID=`cat $PIDFILE`
+    cd $DAEMON_PATH
+    if [ -f $PIDFILE ]; then
+        kill -HUP $PID
+        printf "%s\n" "Ok"
+        rm -f $PIDFILE
+    else
+        printf "%s\n" "pidfile not found"
+    fi
+  ;;
+
+  restart)
+    $0 stop
+    $0 start
+  ;;
+
+  *)
+    echo "Usage: $0 {status|start|stop|restart}"
+    exit 1
+esac

http://git-wip-us.apache.org/repos/asf/incubator-metron/blob/a7e3879e/deployment/roles/pcap_replay/vars/main.yml
----------------------------------------------------------------------
diff --git a/deployment/roles/pcap_replay/vars/main.yml b/deployment/roles/pcap_replay/vars/main.yml
index a2bb5c2..b1fae1e 100644
--- a/deployment/roles/pcap_replay/vars/main.yml
+++ b/deployment/roles/pcap_replay/vars/main.yml
@@ -15,5 +15,7 @@
 #  limitations under the License.
 #
 ---
+pcap_replay_interface: eth0
+pcap_path: /opt/pcap-replay
 tcpreplay_version: 4.1.1
-pcap_replay_path: /opt/pcap-replay
+tcpreplay_prefix: /opt