#!/bin/sh
#
# 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
#
dagld -d /dev/dag0 -x dag/xilinx/dag35pci-erf.bit:dag/xilinx/dag35pp-erf.bit
dagld -d /dev/dag1 -x dag/xilinx/dag35pci-erf.bit:dag/xilinx/dag35pp-erf.bit

#
# Configure PHY layer settings
#
dagthree -d /dev/dag0 oc3 pos
dagthree -d /dev/dag1 oc3 pos

#
# Alternative for ATM OC12c
#
#dagthree -d /dev/dag0 oc12 atm
#dagthree -d /dev/dag1 oc12 atm

#
# For fibre chaining - SONET facility loopback on the card
#
# dagthree -d /dev/dag0 fcl

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

#
# Second otion, emulate classic header capture
# with fixed 64 byte records, notice slen has no effect for ATM
#
#dagthree -d /dev/dag0 slen=48 novarlen
#dagthree -d /dev/dag1 slen=48 novarlen

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


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

#
# Alternative for ATM capture
# 
#dagsnap -d /dev/dag0 $ver $dur -o $stime-0 ncells=2 lcell &
#dagsnap -d /dev/dag1 $ver $dur -o $stime-1 ncells=2 lcell &

#
# 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 the trace file
#
#dagbits -vvc print <~dag/$stime-0

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