#!/bin/tcsh
#
#	ini-manage
#
#	vi: set autoindent tabstop=4 shiftwidth=4 :
#
#	to connect the UNH reference initiator to a target
#
if ( ! -e /proc/scsi/iscsi_initiator ) then
	echo "/proc/scsi/iscsi_initiator does not exist"
	echo "load the initiator module with ini-install"
	exit 1
endif
#
foreach hostno (/proc/scsi/iscsi_initiator/*)
	if ( ! -f $hostno ) continue
	set hostno = $hostno:t
#
#	set the target's ip address or DNS name to connect to
set ip = 100::38
#
#	example of an IPv6 address
#set ip = fe80::2e0:29ff:fe6c:70dc
#
#	set the port number on the target to connect to
set portno = 5000
#
#	set the lun to bring up
set lun = 0
#
#	set the connection id to bring up
set cid = 0
#
#	set this to determine initiator's local target slot to use
set localtargetno = 0
#
#	if connecting to the unh reference target emulator, set its target number
set remotetargetno = 0
#
echo "local initiator host" $hostno "initiator's target slot" $localtargetno
echo "lun" $lun "connection id" $cid
echo "remote target number for UNH target" $remotetargetno
#
#
./iscsi_manage init restore host=$hostno target=$localtargetno
./iscsi_manage init set TargetName=iqn.2002-10.edu.unh.iol.iscsi.draft20-target:$remotetargetno host=$hostno target=$localtargetno
./iscsi_manage init set InitiatorName=iqn.1999-11.edu.unh.iol.iscsi.draft20-initiator host=$hostno target=$localtargetno
./iscsi_manage init set InitiatorAlias=UNH-Draft20-Initiator host=$hostno target=$localtargetno
#
# force initiator to offer security stage, even if it has no keys to send
#./iscsi_manage init force s host=$hostno target=$localtargetno
#
# force initiator to offer operational stage, even if it has no keys to send
#./iscsi_manage init force o host=$hostno target=$localtargetno
#
# to turn on CHAP Authentication -- also need to define names and secrets (next)
#./iscsi_manage init set AuthMethod=CHAP,None host=$hostno target=$localtargetno
#
# for the UNH reference target CHAP Authentication
#./iscsi_manage init force b t cl=256 lx="wild_cat_and_dog" ln=UNH-reference-Target px="UNH cowhampshire" pn=anonymous-user-of-UNH-reference-Target host=$hostno target=$localtargetno
#
# for the UNH TARGET target.t script CHAP Authentication in both directions
#./iscsi_manage init force b t cl=256 lx="When will it begin?" ln=UNH-TESTOR-Target px="This should work now!" pn=anonymous-user-of-UNH-TESTOR-Target host=$hostno target=$localtargetno
#
# for the UNH TARGET target.t script CHAP Authentication initiator only
#./iscsi_manage init force b cl=256 px="This should work now!" pn=anonymous-user-of-UNH-TESTOR-Target host=$hostno target=$localtargetno
#
# to turn on SRP Authentication -- also need to define names and secrets (next)
#./iscsi_manage init set AuthMethod=SRP,None host=$hostno target=$localtargetno
#
#./iscsi_manage init force b t host=$hostno target=$localtargetno
#./iscsi_manage init force sx="old_man_of_the_mountain" host=$hostno target=$localtargetno
#./iscsi_manage init force sn=UNH-IOL-user-name host=$hostno target=$localtargetno
#
# uncomment only 1 of the following 5 lines to configure the SRP group
# larger groups take correspondingly longer to compute
#./iscsi_manage init force sg=SRP-768 host=$hostno target=$localtargetno
#./iscsi_manage init force sg=SRP-1024 host=$hostno target=$localtargetno
#./iscsi_manage init force sg=SRP-1280 host=$hostno target=$localtargetno
#./iscsi_manage init force sg=SRP-1536 host=$hostno target=$localtargetno
#./iscsi_manage init force sg=SRP-2048 host=$hostno target=$localtargetno
#
# uncomment the following 2 lines to get initiator to ask for digests
#./iscsi_manage init set HeaderDigest=CRC32C,None host=$hostno target=$localtargetno
#./iscsi_manage init set DataDigest=CRC32C,None host=$hostno target=$localtargetno
#
./iscsi_manage init set MaxConnections=6 host=$hostno target=$localtargetno
./iscsi_manage init set MaxOutstandingR2T=10 host=$hostno target=$localtargetno
#
#### performance usually better the larger these numbers are
#### but larger numbers may cause bigger buffers to be preallocated on target
#### and that can cause memory starvation when memory on the target is low
#### besides, beyond a certain point increasing the buffer side gains nothing
#
# the defaults from RFC 3720
#./iscsi_manage init set MaxRecvDataSegmentLength=8192 host=$hostno target=$localtargetno
#./iscsi_manage init set MaxBurstLength=262144 host=$hostno target=$localtargetno
#./iscsi_manage init set FirstBurstLength=65536 host=$hostno target=$localtargetno
#
# some reasonable settings for Linux
./iscsi_manage init set MaxRecvDataSegmentLength=32768 host=$hostno target=$localtargetno
./iscsi_manage init set MaxBurstLength=131072 host=$hostno target=$localtargetno
./iscsi_manage init set FirstBurstLength=32768 host=$hostno target=$localtargetno
#
# some settings that can cause irregular pieces
#./iscsi_manage init set MaxRecvDataSegmentLength=12288 host=$hostno target=$localtargetno
#./iscsi_manage init set MaxBurstLength=32768 host=$hostno target=$localtargetno
#./iscsi_manage init set FirstBurstLength=16384 host=$hostno target=$localtargetno
#
# all settings very large (can never be achieved in Linux)
#./iscsi_manage init set MaxRecvDataSegmentLength=16773120 host=$hostno target=$localtargetno
#./iscsi_manage init set MaxBurstLength=16773120 host=$hostno target=$localtargetno
#./iscsi_manage init set FirstBurstLength=16773120 host=$hostno target=$localtargetno
#
# all settings equal and at the maximum feasible for Linux
#./iscsi_manage init set MaxRecvDataSegmentLength=131072 host=$hostno target=$localtargetno
#./iscsi_manage init set MaxBurstLength=131072 host=$hostno target=$localtargetno
#./iscsi_manage init set FirstBurstLength=131072 host=$hostno target=$localtargetno
#
# another set of all settings equal and feasible for Linux
#./iscsi_manage init set MaxRecvDataSegmentLength=65536 host=$hostno target=$localtargetno
#./iscsi_manage init set MaxBurstLength=65536 host=$hostno target=$localtargetno
#./iscsi_manage init set FirstBurstLength=65536 host=$hostno target=$localtargetno
#
#### the combination InitalR2T=No and ImmediateData=No
#### with a FirstBurstLength equal to the target's MaxRecvDataSegmentLength
#### allows each write to send one unsolicited DataOut PDU immediately after
#### the write command (which itself has no immediate data).  This allows
#### the transmission of that DataOut PDU to overlap the processing of the
#### write command on the target and the target's sending back of the first
#### R2T for the rest of the data.  The result seems to be the most parallelism
#### possible without undue target buffering and copying of unsolicited data.
./iscsi_manage init set InitialR2T=No host=$hostno target=$localtargetno
./iscsi_manage init set ImmediateData=No host=$hostno target=$localtargetno
#
#### However, on some targets unsolicited data requires extra buffering and
#### copying and/or delay in processing the write.
#### In that case, the combination InitialR2T=Yes and ImmediateData=No
#### forces all DataOut PDUs to be solicited by R2Ts from the target.
#./iscsi_manage init set InitialR2T=Yes host=$hostno target=$localtargetno
#./iscsi_manage init set ImmediateData=No host=$hostno target=$localtargetno
#
#### performance usually better when everything goes in order
#./iscsi_manage init set DataPDUInOrder=No host=$hostno target=$localtargetno
#./iscsi_manage init set DataSequenceInOrder=No host=$hostno target=$localtargetno
#
##### markers not supported yet anyway
#./iscsi_manage init set OFMarker=No host=$hostno target=$localtargetno
#./iscsi_manage init set IFMarker=No host=$hostno target=$localtargetno
#./iscsi_manage init set IFMarkInt=4096~32768 host=$hostno target=$localtargetno
#./iscsi_manage init set OFMarkInt=4096~4096 host=$hostno target=$localtargetno
#./iscsi_manage init set DefaultTime2Wait=10 host=$hostno target=$localtargetno
#./iscsi_manage init set DefaultTime2Retain=6 host=$hostno target=$localtargetno
#
#./iscsi_manage init set ErrorRecoveryLevel=1 host=$hostno target=$localtargetno
#
#	set the command retransmit interval to 4 seconds
#	(when ErrorRecoverLevel is greater than 0)
./iscsi_manage init force p=4 host=$hostno target=$localtargetno
#
#	uncomment the following to enable initiator to send SNACKs to target
#	(when ErrorRecoverLevel is greater than 0)
./iscsi_manage init snack d=y host=$hostno target=$localtargetno
./iscsi_manage init snack s=y host=$hostno target=$localtargetno
#
#	uncomment the following two lines to get a discovery session
#./iscsi_manage init set SessionType=Discovery host=$hostno target=$localtargetno
#./iscsi_manage init setp SendTargets=All host=$hostno target=$localtargetno
#
#	uncomment these to force offer/reply in Disco of config'd but irrel params
#./iscsi_manage init force i host=$hostno target=$localtargetno
#./iscsi_manage init force I host=$hostno target=$localtargetno
#
#	uncomment the following to try an X-extension key
#./iscsi_manage init set X-edu.unh.iol-extension-key-1=hello_over_there host=$hostno target=$localtargetno
#
#	sch=1 to force round-robin scheduling if there are multiple connections
#	sch=2 to force lun-assigned-to-connection scheduling on multiple luns/conns
#		(when using sch=2, connections must be brought up before the luns)
./iscsi_manage init force sch=1 host=$hostno target=$localtargetno
#
#	force nop pings to be sent to target every 20 seconds
#./iscsi_manage init force n=10 host=$hostno target=$localtargetno
#
#	force flat-space lun addressing (default is peripheral device addressing)
#./iscsi_manage init force f host=$hostno target=$localtargetno
#
#	force a response to a key negotiation even when it is optional
#./iscsi_manage init force r host=$hostno target=$localtargetno
#
#	force X- and X# keys offered by other side to be reflected as is
#	back to other side (instead of sending back NotUnderstood)
#./iscsi_manage init force xok host=$hostno target=$localtargetno
#
#### set run-time debug printout
#	turn on TRACE_ERROR_RECOVERY with 0x200
#	turn on TRACE_ISCSI with 0x004
#	turn on TRACE_ISCSI_FULL with 0x002
#	for other bits, see common/debug.h
#./iscsi_manage init force V=0x006 host=$hostno target=$localtargetno
#
#	finally, bring up the connection to the target
./iscsi_config up ip=$ip port=$portno host=$hostno cid=$cid lun=$lun target=$localtargetno
#
# attempt this only once
break
end
