#!/bin/sh
#
# $Id: dag42gestart 2598 2005-11-25 00:28:45Z pam $
#
# Startup and capture script for Dag4.23ge cards
#
#
# First load the driver
#
# sudo dag/drv/dagload

#
# Make sure the Dags are in reset state
#
dagreset -d /dev/dag0

#
# Upload the latest Xilinx FPGA images
#
dagrom -d /dev/dag0 -vryp <xilinx/dag423eth-erf.bit

#
# Set PHY defaults.
#
dagfour -d /dev/dag0 default

#
# Set capture (snap) length
#
# First option, full packet capture
#
dagfour -d /dev/dag0 slen=1536

#
# Second otion, emulate classic header capture
# with fixed 64 byte records
#
#dagfour -d /dev/dag0 slen=44 novarlen

#
# Apply PHY changes, as needed.
#
#dagfour -d /dev/dag0 nonic

#
# For Dag-Dag synchronization enable Dag0 -> Dag1 PPS output
#
#dagclock -oo

#
# Synchronize system time with NTP server, as required
#
#sudo ntpdate -b ntpserver.company.com

#
# Wait for DUCK health / PPS synchronization -k
# Clear DUCK health statistics -x
#
#dagclock -d /dev/dag0 -kx	# only with GPS/CDMA sync

#
# Ready for capture
#

ver=-v

stime=$(date +%Y%m%d-%H%M%S)

#
# The traffic can be severe, make sure both trace files end up on
# different file systems, here /one and /two. Better have software
# raid0 enabled on a set of 2-3 drives each, see raidtools (man 8 mkraid).
#
dagsnap -d /dev/dag0 $ver $dur -o /one/$stime-0 &

#
# For longer trace files and machines with 2GB file limit split traces by time
#
#dagsnap $ver -d /dev/dag0 | dagsplit -vb180 '/one/%Y%m%d-%H%M%S-0' &

#
# Wait here until both dagsnaps have finished
#
wait

#
# Stopping the capture when running
#
# Option 1: foreground: hit Control-C
# Option 2: background: killall -9 dagsnap

#
# Inspecting a trace file
#
#dagbits -vvc print </one/$stime-0

#
# Analysis with tcpdump
#
#dagconvert -T erf:pcap </one/$stime-0 | tcpdump -nr -	# no DNS name lookup
#or
#dagconvert -T erf:pcap </one/$stime-0 | tcpdump -r -	# DNS lookup, may hang at times
