#!/bin/tcsh
#
#	ini-manage
#
#	vi: set autoindent tabstop=4 shiftwidth=4 :
#
#	to connect the UNH reference initiator to a target
#
#	this command file can be run on a platform whose initiator loads as
#	host 0-9 (i.e., 1 digit)
#
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
#
set hostno = /proc/scsi/iscsi_initiator/?
set hostno = $hostno:t
#
#	set the target's ip address or DNS name to connect to
set ip = 127.0.0.1
#	example of an IPv6 address
#set ip = fe80::2e0:29ff:fe6c:70dc
#
#	set the port number on the target to connect to
set portno = 3260
#
#	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
#./iscsi_manage init set MaxRecvDataSegmentLength=12288 host=$hostno target=$localtargetno
#./iscsi_manage init set FirstBurstLength=16384 host=$hostno target=$localtargetno
#./iscsi_manage init set MaxBurstLength=32768 host=$hostno target=$localtargetno
#./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
#
#### performance usually better when all write data goes immediate/unsolicited
#### (which is the combination InitialR2T=No and ImmediateData=Yes)
#./iscsi_manage init set InitialR2T=No 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 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
#
#	finally, bring up the connection to the target
./iscsi_config up ip=$ip port=$portno host=$hostno cid=$cid lun=$lun target=$localtargetno
