#!/bin/sh
#
# $Id: dag62start 918 2004-12-09 02:57:11Z sfd $
#
# Startup and capture script for Dag6.2
#
#
# 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 </usr/local/share/dag/xilinx/dag62pcix-erf.bit
#dagrom -d /dev/dag1 -vryp </usr/local/share/dag/xilinx/dag62pcix-erf.bit
dagld -x -d /dev/dag0 /usr/local/share/dag/xilinx/dag62rx-erf.bit
#dagld -x -d /dev/dag1 /usr/local/share/dag/xilinx/dag62rx-erf.bit


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

#
# Capture (snap) length fixed to 48 bytes, varlen mode.
#

#
# Apply PHY changes, as needed.
#
#dagsix -d /dev/dag0 
#dagsix -d /dev/dag1 

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

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

#
# 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 &
#
# Wait here until both dagsnaps have finished
#
wait

#
# For longer trace files and machines with 2GB file limit,
# split trace into 1GB files. Names will be /one/capture0001.erf,
# /one/capture0002.erf etc
#
#dagconvert $ver -d /dev/dag0 -r 1g -o /one/capture &
#dagconvert $ver -d /dev/dag1 -r 1g -o /two/capture &
#wait

#
# To record libpcap format files as read by tcpdump, ethereal etc,
# use dagconvert.
#
# dagconvert $ver -d /dev/dag0 -Tdag:pcap -o /one/capture.pcap &
# dagconvert $ver -d /dev/dag1 -Tdag:pcap -o /two/capture.pcap &
# wait

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

#
# Inspecting the trace file
#
#dagbits -vvc print <~dag/$stime-0

#
# Analysis of ERF format traces with tcpdump without converting file on disk
#
#dagconvert -T erf:pcap </one/$stime-0 | tcpdump -nr -	# no DNS name lookup
#dagconvert -T erf:pcap </one/$stime-0 | tcpdump -r -	# DNS lookup, may hang at times
