Whamcloud - gitweb
LU-1434 utils: Add build functionality for wireshark and Lustre/LNet plugins
authorfrank <Frank.Heckes@intel.com>
Sat, 23 Feb 2013 15:58:04 +0000 (07:58 -0800)
committerOleg Drokin <oleg.drokin@intel.com>
Wed, 10 Apr 2013 18:26:49 +0000 (14:26 -0400)
Add build script `wsbuild' to create RPMs for wireshark and Lustre/LNet
plugins. Set-up of the download and compile environment for the desired
wireshark version will be handled via configuration file `wsconfig.sh'.
Intention is to use the script for Jenkins builds.

Signed-off-by: frank <Frank.Heckes@intel.com>
Change-Id: I3e00c5df102f2e52f0abf7c2d48488ccfb38a3ca
Reviewed-on: http://review.whamcloud.com/5520
Tested-by: Hudson
Tested-by: Maloo <whamcloud.maloo@gmail.com>
Reviewed-by: Nathaniel Clark <nathaniel.l.clark@intel.com>
Reviewed-by: Chris Gearing <chris.gearing@intel.com>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
lustre/contrib/wireshark/Makefile
lustre/contrib/wireshark/README
lustre/contrib/wireshark/lustre-wireshark-plugins-template.spec [new file with mode: 0644]
lustre/contrib/wireshark/wsbuild [new file with mode: 0755]
lustre/contrib/wireshark/wsconfig.sh [new file with mode: 0644]

index 9caa4f0..5c215ff 100644 (file)
@@ -1,6 +1,46 @@
-# Modify to point to your Wireshark and glib include directories
-#INCS = -I$(HOME)/wireshark-1.6.8 `pkg-config --libs --cflags glib-2.0`
-INCS = `pkg-config --libs --cflags wireshark`
+# Makefile to create the Lustre/LNet plugins for Wireshark.
+# It is intended to be used by script `wsbuild┬┤ that will buil
+# a RPM for wireshark and a separate RPM for the Lustre/LNet plugins.
+#
+# All configuration should be performed with help of shell script
+# `wsconfigs.sh' (see can-edit sections).
+#
+# When using as a stand-alone makefile, set the macros WS_HOME,
+# PLUGIN_DIR and PLUGIN_COMPILE_FLAGS to the values associated with
+# your wireshark installation.
+# Alternatively modify `wsconfigs.sh┬┤ accordingly to your wireshar
+# installation, source wsconfigs.sh and build with help of:
+#
+#      make -e -f Makefile
+#
+
+
+# Installation directory of the Wireshark source code
+#    Note: Leave the macro undefined when using the wsbuild script.
+#
+# WS_HOME =
+WS_HOME = 
+
+# Installation directory for the (compiled) Wireshark plugins
+#    Change the value of the following macro to the installation directory
+#    of the Wireshark plugins for your installation 
+#
+#    Note: When using the cbuild script leave the macro undefined
+#    (default: /usr/lib/wireshark/plugins/$(WS_VERSION))
+#
+#    For non-root and  non-rpmbuilds you might want to set the value to ${HOME}/.wireshark/plugins
+PLUGIN_DIR =
+
+CFLAGS = -DINET6 -D_U_=__attribute__\(\(unused\)\) -Wall -Wpointer-arith -g -DXTHREADS -D_REENTRANT -DXUSE_MTSAFE_API -fPIC -DPIC
+
+ifdef WS_HOME
+#INCS = $(shell echo "-I${WS_HOME} `pkg-config --libs --cflags glib-2.0`")
+INCS = $(shell echo "-I${WS_HOME} $(PLUGIN_COMPILE_FLAGS)") -DHAVE_CONFIG_H 
+else
+INCS = $(shell pkg-config --libs --cflags wireshark) $(shell echo "$(PLUGIN_COMPILE_FLAGS)")
+endif
+
+CFLAGS += $(INCS)
 
 SRCS_LNET = packet-lnet.c
 SRCS_LUSTRE = packet-lustre.c
@@ -12,22 +52,36 @@ OBJS_LUSTRE = $(foreach src, $(SRCS_LUSTRE), $(src:.c=.o))
 
 PLUGINS=lnet.so lustre.so
 
-ifeq ($(shell id -u), 0)
-WS_CONFIG=$(shell pkg-config --variable=includedir wireshark)/wireshark/config.h
-WS_VERSION:=$(shell sed "s/^.define VERSION //p;d" ${WS_CONFIG})
-PLUGIN_DIR = /usr/local/lib/wireshark/plugins/$(WS_VERSION)
-else
-PLUGIN_DIR = ${HOME}/.wireshark/plugins
+ifneq ($(shell id -u), 0)
+  ifndef DESTDIR
+    PLUGIN_DIR = ${HOME}/.wireshark/plugins
+  endif
+endif
+
+ifndef PLUGIN_DIR
+  ifndef WS_VERSION
+    ifndef WS_HOME
+      $(error "WS_HOME not defined")
+    endif
+    WS_CONFIG=$(WS_HOME)/config.h
+    WS_VERSION:=$(shell sed "s/^.define[[:space:]]*VERSION[[:space:]]*\"\(.*\)\"/\1/p;d" ${WS_CONFIG})
+   endif
+   ifeq ($(shell if [ -r /etc/SuSE-release ] ; then echo 0; else echo 1; fi ), 0)
+     PLUGIN_DIR = $(DESTDIR)/usr/lib64/wireshark/plugins/$(WS_VERSION)
+   else
+     PLUGIN_DIR = $(DESTDIR)/usr/lib/wireshark/plugins/$(WS_VERSION)
+  endif 
 endif
 
-CFLAGS = -DHAVE_CONFIG_H $(INCS) -DINET6 -D_U_=__attribute__\(\(unused\)\) -Wall -Wpointer-arith -g -DXTHREADS -D_REENTRANT -DXUSE_MTSAFE_API -fPIC -DPIC
 
 all: $(PLUGINS)
 
 lustre.so: $(OBJS_LUSTRE)
+       @echo "Running $(INCS)"
        $(CC) -shared $(OBJS_LUSTRE) -o $@
 
 lnet.so: $(OBJS_LNET)
+       @echo $(INCS)
        $(CC) -shared $(OBJS_LNET) -o $@
 
 install: $(PLUGINS)
index 8e1cfe2..e486f98 100644 (file)
@@ -1,6 +1,56 @@
 Instructions for Building Lustre/LNet Wireshark Support
 -------------------------------------------------------
 
+To compile the RPMs for Wireshark and the Lustre/LNet wireshark
+plugins, please follow the instruction in paragraph
+'Build with packaging support'.
+
+In case you prefer a lightweight compilation and installation without
+any packging 'overhead', please follow the instruction in paragraph 
+'Build without packaging support'.
+
+
+Supported distributions:
+
+    CentOS 6.3   i686, x86_64
+    SLES 11 SP1        x86_64
+    SLES 11 SP2        x86_64
+
+
+Software Pre-requisits:
+To run and compile wirkshark the following software needs to be installed
+    gtk2
+    gtk2-devel
+    glib2
+    libpcap
+    libpcap-devel
+    perl
+
+
+Build with packaging support
+-------------------------------
+Simply type ./wsbuild on a node that match one of the disribution specified
+above to create the RPMs for wirkshark and the associated Lustre/LNet plugins.
+
+Upon successs the build results can be found in directory
+'wireshark-<version>/packaging/rpm/RPMS/x86_64' relative to this directory.
+The RPMs are:
+
+    wireshark-<version>-2.x86_64.rpm
+    lustre-wireshark-plugins-<version>-2.x86_64.rpm
+
+If one of the software components that need to be available for
+compilation (see 'Software Pre-requisits:' above) is missing the script will
+print an appropiate error message. The wireshark 'configure' script might also
+detect missing pre-requisite software. In both cases the software needs to be
+installed before.
+
+The build can be configured with help of the source file 'wsconfig.sh', but should
+out of the box.
+
+
+Build without packaging support
+-------------------------------
 Pre-requisits:
 
 - source tree for Wireshark (recommend version 1.6.8)
diff --git a/lustre/contrib/wireshark/lustre-wireshark-plugins-template.spec b/lustre/contrib/wireshark/lustre-wireshark-plugins-template.spec
new file mode 100644 (file)
index 0000000..82a4824
--- /dev/null
@@ -0,0 +1,35 @@
+%define ver      XXX-LUSTRE-PLUGIN-VERSION-XXX
+%define rel      2
+%define prefix   /usr
+
+Summary:        Lustre plugins for wireshark
+Name:           XXX-LUSTRE-PLUGIN-RPM-NAME-XXX
+Version:        %ver
+Release:        %rel
+License:        GPL
+Group:          Networking/Utilities
+Source:         http://www.whamcloud.com/download/automated/src/%{name}-%{version}.tar.bz2
+URL:            http://www.whamcloud.com/
+BuildRoot:      XXX-TOP-LEVEL-BUILD-DIR-XXX/lustre-wireshark-%{PACKAGE_VERSION}-root
+Requires:       wireshark
+
+%description
+Plugins for wireshark to enable monitoring of Lustre/LNet network traffic.
+
+%prep
+%setup
+make -e -f Makefile all > make-plugins.log 2>&1
+
+%install
+rm -rf \${RPM_BUILD_ROOT}
+make DESTDIR=\${RPM_BUILD_ROOT} -e -f Makefile install
+
+%clean
+rm -rf \${RPM_BUILD_ROOT}
+
+%files
+%defattr(-, root, root)
+%doc README*
+XXX-LUSTRE-PLUGIN-LIBDIR-XXX
+
+%changelog
diff --git a/lustre/contrib/wireshark/wsbuild b/lustre/contrib/wireshark/wsbuild
new file mode 100755 (executable)
index 0000000..108b464
--- /dev/null
@@ -0,0 +1,243 @@
+#!/bin/sh -vx
+
+#
+# Script creates wireshark RPM and an separate  RPM with the wireshare lnet/lustre plugins,
+# installs and test whether the plugins can be selected as filters.
+
+
+#
+#       H E L P E R    F U N C T I O N S
+#
+
+
+error() {
+    local msg="$1"
+
+    [ -n "$msg" ] && echo -e "\n${0##*/}: $msg" >&1
+
+}
+
+fatal() {
+#    cleanup
+    error "$2"
+    exit $1
+}
+
+    # Wipe away the temporary build / install directory + content
+cleanup () {
+
+    echo "Cleanup ${BUILD_DIR}"
+    cd ${BUILD_DIR}
+    if [ $? -ne 0 ] ; then
+        echo "Can't change to ${BUILD_DIR} for clean-up. No clean-up performed."
+       exit 1
+    fi
+        # remove wireshark source directory and tarball and auxiliary directory to tar plugin sources
+    rm -rf wireshark-${WS_VERSION} wireshark-${WS_VERSION}.tar.bz2 ${PLUGIN_RPM_NAME}-${WS_VERSION}/ ${PLUGIN_RPM_NAME}-${WS_VERSION}-root/
+}
+
+
+#
+#       M A I N 
+#
+
+    # Enable download and compile environment settings
+source ${0%/wsbuild}/wsconfig.sh
+if [ $? -ne 0 ] ; then
+    echo "FAILED"
+    fatal 1 "Can't source download and compile evironmnent defined in ${0%/wsbuild}/wsconfig.sh"
+fi
+
+    # Check whether prereqisited software is installed
+echo "Prerequisite software installations:"
+for pkg in $PREREQUISITE_RPMS
+do
+    echo -e "\tPackage '$pkg'\t installed: \c"
+    rpm -q $pkg > /dev/null 2>&1
+    if [ $? -ne 0 ] ; then
+        echo "NO"
+        fatal 1 "RPM (software) '$pkg' not installed. Can't compile wireshark."
+    fi
+    echo "YES"
+
+done
+
+    # Change CWD to top level build directory
+echo -e "Change to top level builddir: \c"
+cd $BUILD_DIR
+if [ $? -ne 0 ] ; then
+    echo "FAILED"
+    fatal 1 "Can't change to directory '${BUILD_DIR}'. Make sure that directory exist."
+fi
+echo "OK"
+
+
+    # Download wireshark
+if [ ! -x /usr/bin/curl ] ; then
+    fatal 1 "curl not installed. Can't download wireshark."
+fi
+ws_file_name=`basename ${WS_SOURCE_URL}`
+# echo "ws_file_name: $ws_file_name"
+echo -e "Download wireshare source tarball: \c"
+    # Download desired wireshark tarball
+/usr/bin/curl ${WS_SOURCE_URL} --output ${BUILD_DIR}/${ws_file_name}
+if [ $? -ne 0 ] ; then
+    echo "FAILED"
+    fatal 1 "Can't download wireshark version ${WS_VERSION}. Check configuration."
+fi
+echo "OK"
+
+
+
+echo -e "Inflating wireshark tarball: \c"
+${UNTAR} ${ws_file_name}
+if [ $? -ne 0 ] ; then
+    echo "FAILED"
+    fatal 1 "Can't untar file '${ws_file_name}'."
+fi
+echo "OK"
+
+
+    # Build wireshark software
+cd ${BUILD_DIR}/wireshark-${WS_VERSION}
+if [ $? -ne 0 ] ; then
+    fatal 1 "Can't change to directory '${BUILD_DIR}/wireshark-${WS_VERSION}'."
+fi
+
+
+    # Executing configure first to create the make file and 
+    # rpm spec file. Procedure is a bit ood, since `make rpm-package' 
+    # is running configure again.
+echo -e "Execute wireshark's configure script: \c"
+./configure
+if [ $? -ne 0 ] ; then
+    echo "FAILED"
+    echo "----------- configure output ---------------------"
+    cat Configure-$$.log
+    echo "--------------------------------"
+    fatal 1 "configure script in ${BUILD_DIR}/wireshark-${WS_VERSION} stops with errors"
+fi
+echo "OK"
+
+
+    # Currently code works distribution using RPM for package management only, i.e.:
+    # for RHEL/CentOS, SLES (suse)
+    #
+    # Code to support distributions using debian software packaging
+    # have to be added.
+
+    # SLES SP1, 2 specific handling
+if [ -r /etc/SuSE-release ] ; then
+
+        # Correct RPM spec file to build correctly:
+        # Note: changes are based on wireshark version 1.6.8
+        #
+        # -1- Adjust BuildRoot macro. 
+        #    Otherwise packaging will fail since SuSe expand BuildRoot to '/tmp/...'
+        #    Files can't be found by packaging program
+        #
+        # -2- Correct libdir macro.
+        #    Set library prefix to '/usr/lib64'
+        #
+        # -3- Correct file globing used for packaging library files
+        #    Globbing pattern set to '%prefix/lib64/*' in %files section
+        #    to capture the accordingly to change -2-
+        #
+    sed -e "s#\(BuildRoot:[[:space:]]*\)/[a-zA-Z0-9_]*\(/wireshark-%{PACKAGE_VERSION}-root\)#\1${BUILD_DIR}packaging/rpm/BUILD\2#" \
+        -e 's#\(.* \./configure .*\)#\1 --libdir=/usr/lib64#' \
+        -e 's#^\(%prefix/lib\)/\*#\164/\*#' ./packaging/rpm/SPECS/wireshark.spec > new-$$.spec
+        if [ $? -ne 0 ] ; then
+            fatal 1 "Can't modify wireshark SPEC file to build under SLES"
+        fi
+            # Move modified SPEC into effect
+        mv new-$$.spec ./packaging/rpm/SPECS/wireshark.spec
+        if [ $? -ne 0 ] ; then
+            fatal 1 "Can't copy modified wireshark SPEC file (SLES to ${BUILD_DIR}/packaging/rpm/SPECS/wireshark.spec"
+        fi
+
+fi
+
+    
+echo -e "Create wireshark RPM: \c"
+make rpm-package
+if [ $? -ne 0 ] ; then
+    echo "FAILED"
+    echo "----------- make rpm-package output ---------------------"
+    cat make-rpm-$$.log
+    echo "--------------------------------"
+    fatal 1 "make rmp-package failed in  ${BUILD_DIR}/wireshark-${WS_VERSION}"
+fi
+# Package successfully built in ${BUILD_DIR}/wireshark-${WS_VERSION}/packaging/rpm/RPMS.
+echo "OK"
+
+
+cd ${BUILD_DIR}
+if [ $? -ne 0 ] ; then
+    fatal 1 "Can't change into directory ${BUILD_DIR}"
+fi
+
+PLUGINS_LIBDIR=''
+    # SLES SP1, 2 installs 64Bit libs and binaries into /usr/lib64
+    # 
+if [ -r /etc/SuSE-release ] ; then
+
+    PLUGINS_LIBDIR='/usr/lib64/wireshark/plugins/%ver/*'
+else
+    PLUGINS_LIBDIR='/usr/lib/wireshark/plugins/%ver/*'
+fi
+
+echo -e "Create Lustre/LNet wireshark plugin RPM: \c"
+
+    # Insert the associated version, name and build directory info
+    # to the SPEC template. Use '#' 
+    # as delimiters since path info will be substituted
+sed -e "s#XXX-TOP-LEVEL-BUILD-DIR-XXX#${BUILD_DIR}#" \
+    -e "s#XXX-LUSTRE-PLUGIN-VERSION-XXX#${WS_VERSION}#" \
+    -e "s#XXX-LUSTRE-PLUGIN-RPM-NAME-XXX#${PLUGIN_RPM_NAME}#" \
+    -e "s#XXX-LUSTRE-PLUGIN-LIBDIR-XXX#${PLUGINS_LIBDIR}#" \
+    lustre-wireshark-plugins-template.spec > ${PLUGIN_RPM_NAME}.spec
+if [ $? -ne 0 ] ; then
+    echo "FAILED"
+    fatal 1 "Can't create SPEC file for Lustre/LNet wireshark plugins"
+fi
+
+
+    # Create tarball containing source files plugins to be used rpmbuid mechanism
+if [ -d ${PLUGIN_RPM_NAME}-${WS_VERSION} ] ; then
+    rm -rf lustre-wireshark-plugins-1.6.8
+    if [ $? -ne 0 ] ; then
+        fatal 1 "Can't cleanup auxiliary directory to create tarball of Lustre/LNet plugins"
+    fi
+fi
+    # Create auxiliary directory
+mkdir ${PLUGIN_RPM_NAME}-${WS_VERSION}
+if [ $? -ne 0 ] ; then
+    echo "FAILED"
+    fatal 1 "Can't create packaging directory to create source tarball for lustre wireshark plugins"
+fi
+cp README Makefile packet-lnet.c packet-lustre.c ${PLUGIN_RPM_NAME}-${WS_VERSION}
+if [ $? -ne 0 ] ; then
+    echo "FAILED"
+    fatal 1 "Can't copy files for rpm source tar ball into helper directory for Lustre/LNet wireshark plugins"
+fi
+
+$TAR ${PLUGIN_RPM_NAME}-${WS_VERSION}.tar.bz2 ${PLUGIN_RPM_NAME}-${WS_VERSION}/
+if [ $? -ne 0 ] ; then
+    echo "FAILED"
+    fatal 1 "Can't create rpm source tar ball for Lustre/LNet wireshark plugins"
+fi
+
+    # install source tarball into build directory
+cp ${PLUGIN_RPM_NAME}-${WS_VERSION}.tar.bz2 ${BUILD_DIR}/wireshark-${WS_VERSION}/packaging/rpm/SOURCES
+if [ $? -ne 0 ] ; then
+    echo "FAILED"
+    fatal 1 "Can't copy source tar ball for Lustre/LNet wireshark plugins build directory"
+fi
+
+rpmbuild -bb --define "_topdir ${BUILD_DIR}/wireshark-${WS_VERSION}/packaging/rpm" ${PLUGIN_RPM_NAME}.spec
+if [ $? -ne 0 ] ; then
+    echo "FAILED"
+    fatal 1 "Can't create RPM for Lustre/LNet wireshark plugins"
+fi
+
+exit 0
diff --git a/lustre/contrib/wireshark/wsconfig.sh b/lustre/contrib/wireshark/wsconfig.sh
new file mode 100644 (file)
index 0000000..78c4904
--- /dev/null
@@ -0,0 +1,65 @@
+# This file contain all configuration information to build
+# `lustre-release/lustre/contrib/wireshark'
+
+###########################################################################
+#                                                                         #
+#    DOWNLOAD CONFIGURATION
+#                                                                         #
+###########################################################################
+
+##   BEGIN: -can-edit   ##
+    # URL of directory containing all source tar balls
+export WS_DOWNLOAD_BASE_URL='http://wiresharkdownloads.riverbed.com/wireshark/src/all-versions'
+
+    # wireshark verion to be used
+export WS_VERSION='1.6.8'
+##   END  : -can-edit   ##
+
+    # URL of the wireshark source code tarball
+    # Implicit assumption: Wireshark release names follow the nameing
+    # convention coded in the content of the following varialble
+export WS_SOURCE_URL="${WS_DOWNLOAD_BASE_URL}/wireshark-${WS_VERSION}.tar.bz2"
+
+
+###########################################################################
+#                                                                         #
+#                   BUILD ENVIRONMENT                                     #
+#                                                                         #
+###########################################################################
+
+##   BEGIN: -can-edit   ##
+    # Space separate list of RPMs needed to be installed for 
+    # compilation of wireshark
+
+    # Package name(s) (can) vary between differnt distributions
+    # If distributions 'marked' by same release file, content has to
+    # parsed and variable PREREQUISITE_RPMS has to be set accoringly to
+    # package name(s) used for each distro.
+if [ -r /etc/redhat-release ] ; then
+    export PREREQUISITE_RPMS='gtk2 gtk2-devel glib2 libpcap libpcap-devel perl'
+elif [ -r /etc/SuSE-release ] ; then
+    export PREREQUISITE_RPMS='gtk2 gtk2-devel glib2 libpcap0 libpcap-devel perl'
+fi
+
+    # Include and linker flags needed to Lustre/LNet
+    # Only version indepent information should be added here
+    # (Back ticked expression will be evaluated by make command)
+export PLUGIN_COMPILE_FLAGS='`pkg-config --libs --cflags glib-2.0`'
+##   END  : -can-edit   ##
+
+    # Top-level directory to be used to unpack/compile/install wireshark/lustre-git-repo
+export BUILD_DIR=`pwd`
+
+    # Directory location of wireshark source code
+export WS_HOME="${BUILD_DIR}/wireshark-${WS_VERSION}"
+
+    # (Relative) path of the wireshark contribution directory
+export LUSTRE_WS_DIR='lustre-release/lustre/contrib/wireshark'
+
+    # RPM internal name for the Lustre/LNet plugins
+export PLUGIN_RPM_NAME='lustre-wireshark-plugins'
+
+    # TAR command + options to be used to create a bzip2 tarball
+export TAR='/bin/tar jcpf '
+    # TAR command + options to be used to unpack a bzip2 tarball
+export UNTAR='/bin/tar jxpf '