# (c) 1996-99 Bay Networks

# For Accelar1k devices
set Dm_ID(1.3.6.1.4.1.2272.2)	dmsCheckVersion
set Dm_ID(1.3.6.1.4.1.2272.6)	dmsCheckVersion
set Dm_ID(1.3.6.1.4.1.2272.7)	dmsCheckVersion
set Dm_ID(1.3.6.1.4.1.2272.8)	dmsCheckVersion
set Dm_ID(1.3.6.1.4.1.2272.9)	dmsCheckVersion

proc dmsCheckVersion {objId sysDescr} {
	global Dm_Path Dm_Launcher Dm_Pref

	if $Dm_Pref(trace) {
		puts "sysDescr=$sysDescr"
	}
	set v ??
	if {[regexp {\([0-9]+.[\.0-9]+\)} $sysDescr v]} {
		# The matching agent has to be equal the required version.
		set ver [string range $v 1 [expr [string length $v] - 2]]
		if {[set n [scan $ver %d.%d.%d a1 a2 a3]] == 3} { 
			if {$a1 == "1"} {
				if {$a2 == "1"} {
					set vdir v114
				} elseif {$a2 == 2 || ($a2 == 3 && $a3 == 0)} {
					set vdir v120
				} elseif {$a2 == 3 && $a3 <= 2} {
					set vdir v131
				} else {
					set vdir v134
				}
			} elseif {$a1 == 2} {
				if {$a2 == "0" && $a3 < 4} {
					set vdir v200
				} elseif {$a3 == "4"} {
					set vdir v204
				} else {
					set vdir v205
				}
			} elseif {$a1 > 2} {
				set vdir v205
			} else {
				error "Accelar SNMP agent is version $v.\nThis DM is not\
					compatiable with it.\n"
				return
			}

			set Dm_Launcher(newmib) ${Dm_Path}/dmdb/accelar1k/${vdir}/mibs/mib.dat
			if {[set devType [lindex [split $objId .] end]] == 2} {
				return "accelar1k/${vdir}/1100.dms"
			} elseif {$devType == 6} {
				return "accelar1k/${vdir}/1250.dms"
			} elseif {$devType == 7} {
				return "accelar1k/${vdir}/1150.dms"
			} elseif {$devType == 8} {
				return "accelar1k/${vdir}/1200.dms"
			} else {
				return "accelar1k/${vdir}/1050.dms"
			}
		} else { 
			# for earlier releases
			if {$ver == "70.0"} { 
				# temp, to be removed later
				set vdir v114
			} elseif {$ver == "46.0"} {
				set vdir v104
				set Dm_Launcher(newmib) ${Dm_Path}/dmdb/accelar1k/${vdir}/mibs/mib.dat
				if {[set devType [lindex [split $objId .] end]] == 2} {
					return "accelar1k/${vdir}/200.dms"
				} elseif {$devType == 6} {
					return "accelar1k/${vdir}/600.dms"
				} elseif {$devType == 7} {
					return "accelar1k/${vdir}/800.dms"
				} elseif {$devType == 8} {
					return "accelar1k/${vdir}/1200.dms"
				} else {
					# not supported
					error "Not supported"
				}
			}
		}
	}
	error "Accelar SNMP agent is version $v.\nThis DM is not compatiable\
               with it.\n"  
}


# For Chameleon devices
set Dm_ID(1.3.6.1.4.1.45.3.30.2) dmsCheckCham350Version
set Dm_ID(1.3.6.1.4.1.45.3.35.1) dmsCheckCham450Version
set Dm_ID(1.3.6.1.4.1.45.3.36.1) dmsCheckCham410Version

proc dmsCheckCham410Version {objId sysDescr} {
	global Dm_Path Dm_Launcher Dm_Pref

	if $Dm_Pref(trace) {
		puts "sysObjectId=$objId\nsysDescr=$sysDescr"
	}
	set v ??
	if {[regexp {SW:[VEve][0-9]+.[\.0-9]+} $sysDescr v]} { 
		set ver [string range $v 4 end]
		if {[set n [scan $ver %d.%d.%d.%d v1 v2 v3 v4]] == 4} { 
			set vnum $v1$v2$v3
			# This dm support agent 1.0.0.3 and above
			if {$vnum > 120 || ($vnum == 120 && $v4 >= 8)} {
				set Dm_Launcher(newmib) ${Dm_Path}/dmdb/chameleon/v1208/mibs/mib.dat
				set agentVer v1208
			} else {
				error "BayStack 410 SNMP agent is version $v.\nThis\
				DM is not compatiable with it.\n"  
				return
			}
		} else {
			error "BayStack 410 SNMP agent is version $v.\nThis\
				DM is not compatiable with it.\n"  
			return
		}
	} else {
		# if sysDescr doesn't have SW:[VE] format, 
		# assume the agent has the lastest version.
		set Dm_Launcher(newmib) ${Dm_Path}/dmdb/chameleon/v1208/mibs/mib.dat
		set agentVer v1208
	}
	return "chameleon/${agentVer}/450_200S.dms"
} 

proc dmsCheckCham450Version {objId sysDescr} {
	global Dm_Path Dm_Launcher Dm_Pref

	if $Dm_Pref(trace) {
		puts "sysObjectId=$objId\nsysDescr=$sysDescr"
	}
	set v ??
	if {[regexp {SW:[VEve][0-9]+.[\.0-9]+} $sysDescr v]} { 
		set ver [string range $v 4 end]
		if {[set n [scan $ver %d.%d.%d.%d v1 v2 v3 v4]] == 4} { 
			set vnum $v1$v2$v3
			# This dm support agent 1.0.0.3 and above
			if {$vnum > 120 || ($vnum == 120 && $v4 >= 8)} {
				set Dm_Launcher(newmib) ${Dm_Path}/dmdb/chameleon/v1208/mibs/mib.dat
				set agentVer v1208
				if $Dm_Pref(trace) {
					puts "dms1ameleon/${agentVer}/450_200S.dms"
				}
				return "chameleon/${agentVer}/450_200S.dms"
			} elseif {$vnum > 110 || ($vnum == 110 && $v4 >= 5)} {
				set Dm_Launcher(newmib) ${Dm_Path}/dmdb/chameleon/v1105/mibs/mib.dat
				set agentVer v1105
				return "chameleon/${agentVer}/450S.dms"
			} elseif {$vnum > 100 || ($vnum == 100 && $v4 >= 3)} {
				set Dm_Launcher(newmib) ${Dm_Path}/dmdb/chameleon/v1003/mibs/mib.dat
				set agentVer v1003
			} else {
				error "BayStack 450 SNMP agent is version $v.\nThis\
				DM is not compatiable with it.\n"  
				return
			}
		} else {
			error "BayStack 450 SNMP agent is version $v.\nThis\
				DM is not compatiable with it.\n"  
			return
		}
	} else {
		# if sysDescr doesn't have SW:[VE] format, 
		# assume the agent has the lastest version.
		set Dm_Launcher(newmib) ${Dm_Path}/dmdb/chameleon/v1208/mibs/mib.dat
		set agentVer v1208
	}

	# read the chassis type for the nonstackable 450
	set vbl {1.3.6.1.4.1.45.1.6.3.3.1.1.4.3.1.0}
	if [catch {set resp [Sess0 get null $vbl]} resp] {
		Sess0 destroy
		if {[set reason [rlindex resp 2]] == "timeout"} {
			error "timeout.  This could be due to:\n\n1: No route to device.\n2:
				Network is busy (increase timeout).\n3: Invalid read community.\n4: No SNMP agent on device."
		} else {
			error "unmanageable ($reason)"
			return
		}
	}
	set vbl [rlindex resp 4] 
	set s5ChasComType [lindex [rlindex vbl 0] 2]
	set chasType [lindex [split $s5ChasComType .] end]
	if $Dm_Pref(trace) {
		puts "chassis type=$chasType"
	}
	if {$chasType == "653"} {
		# 450-24T
		if $Dm_Pref(trace) {
			puts "dms1ameleon/${agentVer}/450_200S.dms"
		}
		return "chameleon/${agentVer}/450_24.dms"
	} elseif {$chasType == "654"} {
		# 450-12T
		if $Dm_Pref(trace) {
			puts "dms1ameleon/${agentVer}/450_200S.dms"
		}
		return "chameleon/${agentVer}/450_12.dms"
	} elseif {$chasType == "681"} {
		# 450F-12T
		if $Dm_Pref(trace) {
			puts "dms1ameleon/${agentVer}/450_200S.dms"
		}
		return "chameleon/${agentVer}/450_12.dms"
	} else {
		error "Not supported"
		retrun
	}
} 

proc dmsCheckCham350Version {objId sysDescr} {
	global Dm_Path Dm_Launcher Dm_Pref

	if $Dm_Pref(trace) {
		puts "sysObjectId=$objId\nsysDescr=$sysDescr"
	}
	set v ??
	if {[regexp {SW:[VEve][0-9]+.[\.0-9]+} $sysDescr v]} { 
		set ver [string range $v 4 end]
		if {[set n [scan $ver %d.%d.%d.%d v1 v2 v3 v4]] == 4} { 
			set vnum $v1$v2$v3
			# This dm support agent 1.0.0.2 and above
			if {$vnum > 120 || ($vnum == 120 && $v4 >= 8)} {
				set Dm_Launcher(newmib) ${Dm_Path}/dmdb/chameleon/v1208/mibs/mib.dat
				set agentVer v1208
				set vbl 1.3.6.1.4.1.45.1.6.3.3.1.1.4.3.5.0
			} elseif {$vnum > 100 || ($vnum == 100 && $v4 >= 2)} {
				set Dm_Launcher(newmib) ${Dm_Path}/dmdb/chameleon/v1003/mibs/mib.dat
				set agentVer v1003
				set vbl 1.3.6.1.4.1.45.1.6.3.3.1.1.4.3.5.0
				#set vbl 1.3.6.1.4.1.45.1.6.3.3.1.1.4.3.1.0
			} else {
				error "BayStack 350 SNMP agent is version $v.\nThis\
					DM is not compatiable with it.\n"  
				return
			}
		} else {
			error "BayStack 350 SNMP agent is version $v.\nThis\
				DM is not compatiable with it.\n"  
			return
		}
	} else {
		# if sysDescr doesn't have SW:[VE] format, 
		# assume the agent has the lastest version.
		set Dm_Launcher(newmib) ${Dm_Path}/dmdb/chameleon/v1003/mibs/mib.dat
		set agentVer v1003
	}

	# read the chassis type 
	if [catch {set resp [Sess0 get null $vbl]} resp] {
puts "resp=$resp"
		Sess0 destroy
		if {[set reason [rlindex resp 2]] == "timeout"} {
			error "timeout.  This could be due to:\n\n1: No route to device.\n2:
				Network is busy (increase timeout).\n3: Invalid read community.\n4: No SNMP agent on device."
		} else {
puts "reason=$reason"
			error "unmanageable ($reason)"
			return
		}
	}
	set vbl [rlindex resp 4] 
	set s5ChasComType [lindex [rlindex vbl 0] 2]
	set chasType [lindex [split $s5ChasComType .] end]
	if $Dm_Pref(trace) {
		puts "chassis type=$chasType"
		puts "mib path=$Dm_Launcher(newmib)"
	}
	if {$chasType == "671"} {
		# 350-24T
		return "chameleon/${agentVer}/350_24.dms"
	} elseif {$chasType == "672"} {
		# 350-12T
		return "chameleon/${agentVer}/350_12.dms"
	} elseif {$chasType == "675"} {
		# 350-24T
		return "chameleon/${agentVer}/350_200_24.dms"
	} elseif {$chasType == "676"} {
		# 350-12T
		return "chameleon/${agentVer}/350_200_12.dms"
	} else {
		error "Not supported"
		retrun
	}
} 

# For 310 Hurricane devices
set Dm_ID(1.3.6.1.4.1.45.3.32.2) dmsCheckHurricaneVersion
 
proc dmsCheckHurricaneVersion {objId sysDescr} {
	global Dm_Path Dm_Launcher Dm_Pref
 
	if $Dm_Pref(trace) {
		puts "sysObjectId=$objId\nsysDescr=$sysDescr"
	}
	set v ??
	if {[set i [string last "Rev: " $sysDescr]] != -1} {
		set v [string range $sysDescr [expr $i + 5] end]
		regexp {[0-9]+[-\.0-9]+} $v v2
		if {[set b [string first - $v2]] != -1} {
			set v2 [string range $v2 [expr $b + 1] end]
		}
		if {[set n [scan $v2 %d.%d.%d.%d a1 a2 a3 a4]] == 4} { 
			if {$a1 == "1"} {
				if {$a2 == "0"} {
					set vdir v1020
				}
			}
			set Dm_Launcher(newmib) ${Dm_Path}/dmdb/hurricane/${vdir}/mibs/mib.dat
			return "hurricane/${vdir}/310_24.dms"
		} else {
			error "BayStack 310 SNMP agent is version $v.\nThis\
				DM is not compatiable with it.\n"  
		}
	} else {
		error "Hurricane SNMP agent is not compatiable with DM.\n"
	}
}

set Dm_Launcher(curmib) ""
