### TempCov: Toolkit for investigating temperature covert channels
### Copyright (C) 2006 Steven J. Murdoch <http://www.cl.cam.ac.uk/users/sjm217/>
###
### This program is free software; you can redistribute it and/or modify
### it under the terms of the GNU General Public License as published by
### the Free Software Foundation; either version 2 of the License, or
### (at your option) any later version.
###
### This program is distributed in the hope that it will be useful,
### but WITHOUT ANY WARRANTY; without even the implied warranty of
### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
### GNU General Public License for more details.
###
### You should have received a copy of the GNU General Public License along
### with this program; if not, write to the Free Software Foundation, Inc.,
### 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
###
### $Id: Makefile 3381 2006-12-25 18:07:55Z sjm217 $

all: example4s0.pdf example6s0.pdf

## R source code used
SRC = common.R example.R plot_offset_skew.R util.R
## Data files for run 4
RUN4 = run4b_burn.data run4b_icmp_128.232.110.64.data run4b_tcp_128.232.110.64.data
## Data files for run 6
RUN6 = run6b_burn.data run6b_icmp_128.232.8.129.data run6b_temp.data

## How to call R
RCMD = time R CMD BATCH --vanilla
## Go to end of file, where the error is
PAGER = less +G

example4s0.pdf: $(SRC) $(RUN4)
	HOSTS=128.232.110.64 FNPREFIX=run4b OUTPREFIX=4s PLOTTEMP=1 PLOTONOFF=1\
         $(RCMD) example.R || ($(PAGER) example.Rout; false)

example6s0.pdf: $(SRC) $(RUN6)
	HOSTS=128.232.8.129 FNPREFIX=run6b OUTPREFIX=6s PLOTTEMP=1 PLOTONOFF=1\
         $(RCMD) example.R || ($(PAGER) example.Rout; false)

## Example of a test run
## Where probe packets should be sent
PROBEDST = 192.168.0.42
## The hostname of the probe computer
PROBESRC = probe.example.com
## Port to where packets should be sent
PORT = 22
## Prefix for data files created
XPREFIX = runX

exampleXs0.pdf: $(SRC) \
                $(XPREFIX)b_tcp_$(PROBEDST).data \
                $(XPREFIX)b_icmp_$(PROBEDST).data
	HOSTS=$(PROBEDST) FNPREFIX=$(XPREFIX)b OUTPREFIX=Xs PLOTTEMP=0 PLOTONOFF=0\
         $(RCMD) example.R || ($(PAGER) example.Rout; false)

## run and stop are a bit of a kludge, and are only examples
run: pcap dpkt
	sudo python probe-receiver.py $(XPREFIX)b_ $(PORT)\
         "src $(PROBESRC) or dst $(PROBESRC)" &
	sleep 2
	## This will take ~12 hours, but to get reasonable results takes a long time
	sudo python probe-sender.py $(XPREFIX)a_ $(PORT) 28800 $(PROBEDST) &

stop:
	sudo pkill -KILL -f "^python probe-sender.py" || true
	sleep 2
	sudo pkill -INT -f "^python probe-receiver.py" || true

dpkt:
	cd dpkt-1.6; make

pcap:
	cd pypcap-1.1; make

clean:
	rm -f *.Rout *~ example.pdf .RData *.pyc
	cd pypcap-1.1; make clean
	cd dpkt-1.6; make clean

reallyclean: clean
	rm -f example4s0.pdf example6s0.pdf exampleXs0.pdf
	rm -f $(XPREFIX)b_icmp_$(PROBEDST).data $(XPREFIX)b_tcp_$(PROBEDST).data \
              $(XPREFIX)a_delayed.data $(XPREFIX)a_unans.data
	cd pypcap-1.1; make cleandir
	cd dpkt-1.6; make cleandir

VERSION=0.01
dist: 
	rm -rf /tmp/tempcov-$(VERSION)
	cp -R . /tmp/tempcov-$(VERSION)
	tar -C /tmp -czvf tempcov-$(VERSION).tar.gz tempcov-$(VERSION)

.PHONY: all clean reallyclean pcap dpkt dist
