#!/bin/sh
#
# First load the driver
#
# sudo dagload

#
# Make sure the Dag is in reset state
#
dagreset -d /dev/dag0

#
# Upload the latest Xilinx FPGA images
#
dagrom -rpd /dev/dag0 </usr/local/share/dag/xilinx/dag36epci-erf.bit
dagld -d /dev/dag0 -x /usr/local/share/dag/xilinx/dag36epp-erf.bit

#
# Configure PHY layer settings
#
dagthree -d /dev/dag0 default

#
# Set capture (snap) length
#
# First option, full packet capture, notice slen has no effect for ATM
#
dagthree -d /dev/dag0 slen=1536 varlen

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


#dur="-s 60"
#dur=
dur="-s 10"

#ver=
ver=-v

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

dagsnap -d /dev/dag0 $ver $dur -o $stime-0

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

# 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

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

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

#
# Analysis with tcpdump
#
#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
