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

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

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

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

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

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

#
# Apply PHY changes, as needed.
#
# Warning! Turning on the laser is normally not required
# and can be quite dangerous, watch your eyes!
#
#dagfour -d /dev/dag0 laser
#dagfour -d /dev/dag1 laser

#
# 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
#dagclock -d /dev/dag1 -kx	# in most cases

#
# 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 &
dagsnap -d /dev/dag1 $ver $dur -o /two/$stime-1 &

#
# 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' &
#dagsnap $ver -d /dev/dag1 | dagsplit -vb180 '/two/%Y%m%d-%H%M%S-1' &

#
# 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
