#!/bin/sh
#
# $Id: dag43start 918 2004-12-09 02:57:11Z sfd $
#
# Startup and capture script for Dag4.3 OC48c cards
#
#
# First load the driver
#
# sudo 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/dag43pcix-erf.bit
dagrom -d /dev/dag1 -vryp </usr/local/share/dag/xilinx/dag43pcix-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 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

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

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