svnno****@sourc*****
svnno****@sourc*****
2010年 1月 13日 (水) 11:02:50 JST
Revision: 89 http://sourceforge.jp/projects/ngms/svn/view?view=rev&revision=89 Author: takayah Date: 2010-01-13 11:02:50 +0900 (Wed, 13 Jan 2010) Log Message: ----------- [NMNetWalker] rename calss name Modified Paths: -------------- trunk/source/NMNetWalker/test/info/ngms/nmnetwalker/NetWalkerFacadeTest.scala Added Paths: ----------- trunk/source/NMNetWalker/src/info/ngms/nmnetwalker/NMBasicNodeInfo.scala trunk/source/NMNetWalker/src/info/ngms/nmnetwalker/NMNetWalkerFacade.scala trunk/source/NMNetWalker/src/info/ngms/nmnetwalker/NMNetWalkerParameter.scala trunk/source/NMNetWalker/src/info/ngms/nmnetwalker/NMNetWalkerResult.scala trunk/source/NMNetWalker/src/info/ngms/nmnetwalker/NMNetWalkerType.scala trunk/source/NMNetWalker/src/info/ngms/nmnetwalker/NMResponseStatus.scala trunk/source/NMNetWalker/src/info/ngms/nmnetwalker/lldp/NMLLDPNetWalker.scala trunk/source/NMNetWalker/src/info/ngms/nmnetwalker/lldp/NMLLDPNetWalkerParameter.scala trunk/source/NMNetWalker/src/info/ngms/nmnetwalker/snmp/NMSNMPNetWalker.scala trunk/source/NMNetWalker/src/info/ngms/nmnetwalker/snmp/NMSNMPNetWalkerParameter.scala Removed Paths: ------------- trunk/source/NMNetWalker/src/info/ngms/nmnetwalker/BasicNodeInfo.scala trunk/source/NMNetWalker/src/info/ngms/nmnetwalker/NetWalkerFacade.scala trunk/source/NMNetWalker/src/info/ngms/nmnetwalker/NetWalkerParameter.scala trunk/source/NMNetWalker/src/info/ngms/nmnetwalker/NetWalkerResult.scala trunk/source/NMNetWalker/src/info/ngms/nmnetwalker/NetWalkerType.scala trunk/source/NMNetWalker/src/info/ngms/nmnetwalker/ResponseStatus.scala trunk/source/NMNetWalker/src/info/ngms/nmnetwalker/lldp/LLDPNetWalker.scala trunk/source/NMNetWalker/src/info/ngms/nmnetwalker/lldp/LLDPNetWalkerParameter.scala trunk/source/NMNetWalker/src/info/ngms/nmnetwalker/snmp/SNMPNetWalker.scala trunk/source/NMNetWalker/src/info/ngms/nmnetwalker/snmp/SNMPNetWalkerParameter.scala Deleted: trunk/source/NMNetWalker/src/info/ngms/nmnetwalker/BasicNodeInfo.scala =================================================================== --- trunk/source/NMNetWalker/src/info/ngms/nmnetwalker/BasicNodeInfo.scala 2010-01-13 01:49:39 UTC (rev 88) +++ trunk/source/NMNetWalker/src/info/ngms/nmnetwalker/BasicNodeInfo.scala 2010-01-13 02:02:50 UTC (rev 89) @@ -1,19 +0,0 @@ -/* - * Next Generation Management System Project - * Copyright(c) 2009, NGMS Project Team All Rights Reserved. - */ -package info.ngms.nmnetwalker - -import java.net.InetAddress -import java.net.InterfaceAddress - -/** - * IP アドレスを持つノードの基本情報クラス - * @version $Id$ - * @author - */ -class BasicNodeInfo(val address: InetAddress, val hostname: String) { - // FIXME - //val physical: Option[InterfaceAddress] = null -} - Copied: trunk/source/NMNetWalker/src/info/ngms/nmnetwalker/NMBasicNodeInfo.scala (from rev 85, trunk/source/NMNetWalker/src/info/ngms/nmnetwalker/BasicNodeInfo.scala) =================================================================== --- trunk/source/NMNetWalker/src/info/ngms/nmnetwalker/NMBasicNodeInfo.scala (rev 0) +++ trunk/source/NMNetWalker/src/info/ngms/nmnetwalker/NMBasicNodeInfo.scala 2010-01-13 02:02:50 UTC (rev 89) @@ -0,0 +1,19 @@ +/* + * Next Generation Management System Project + * Copyright(c) 2009, NGMS Project Team All Rights Reserved. + */ +package info.ngms.nmnetwalker + +import java.net.InetAddress +import java.net.InterfaceAddress + +/** + * IP アドレスを持つノードの基本情報クラス + * @version $Id$ + * @author + */ +class NMBasicNodeInfo(val address: InetAddress, val hostname: String) { + // FIXME + //val physical: Option[InterfaceAddress] = null +} + Copied: trunk/source/NMNetWalker/src/info/ngms/nmnetwalker/NMNetWalkerFacade.scala (from rev 86, trunk/source/NMNetWalker/src/info/ngms/nmnetwalker/NetWalkerFacade.scala) =================================================================== --- trunk/source/NMNetWalker/src/info/ngms/nmnetwalker/NMNetWalkerFacade.scala (rev 0) +++ trunk/source/NMNetWalker/src/info/ngms/nmnetwalker/NMNetWalkerFacade.scala 2010-01-13 02:02:50 UTC (rev 89) @@ -0,0 +1,30 @@ +/* + * Next Generation Management System Project + * Copyright(c) 2009, NGMS Project Team All Rights Reserved. + */ +package info.ngms.nmnetwalker + +import info.ngms.nmnetwalker.snmp.NMSNMPNetWalker +import info.ngms.nmnetwalker.snmp.NMSNMPNetWalkerParameter +import info.ngms.nmnetwalker.lldp.NMLLDPNetWalker +import info.ngms.nmnetwalker.lldp.NMLLDPNetWalkerParameter + +/** + * 自動取得結果を返却するクラス + * @version $Id$ + * @author + */ +private[nmnetwalker] object NMNetWalkerFacade { + def walk(netWalkerType: NMNetWalkerType, params: Map[String, String]): NMNetWalkerResult = { + netWalkerType match { + case NMSNMPNetWalkerType => + val param = NMSNMPNetWalkerParameter.fromMap(params) + NMSNMPNetWalker.walk(param) + case NMLLDPNetWalkerType => + val param = NMLLDPNetWalkerParameter.fromMap(params) + NMLLDPNetWalker.walk(param) + case _ => throw new IllegalArgumentException("invalid NMNetWalkerType") + } + } +} + Copied: trunk/source/NMNetWalker/src/info/ngms/nmnetwalker/NMNetWalkerParameter.scala (from rev 85, trunk/source/NMNetWalker/src/info/ngms/nmnetwalker/NetWalkerParameter.scala) =================================================================== --- trunk/source/NMNetWalker/src/info/ngms/nmnetwalker/NMNetWalkerParameter.scala (rev 0) +++ trunk/source/NMNetWalker/src/info/ngms/nmnetwalker/NMNetWalkerParameter.scala 2010-01-13 02:02:50 UTC (rev 89) @@ -0,0 +1,20 @@ +/* + * Next Generation Management System Project + * Copyright(c) 2009, NGMS Project Team All Rights Reserved. + */ +package info.ngms.nmnetwalker + +/** + * 情報を収集するのに必要なパラメータークラス + * + * @version $Id$ + * @author + */ +private[nmnetwalker] trait NMNetWalkerParameter { + import java.net.InetAddress + + val address: InetAddress + val timeout: Long + val retry: Int +} + Copied: trunk/source/NMNetWalker/src/info/ngms/nmnetwalker/NMNetWalkerResult.scala (from rev 85, trunk/source/NMNetWalker/src/info/ngms/nmnetwalker/NetWalkerResult.scala) =================================================================== --- trunk/source/NMNetWalker/src/info/ngms/nmnetwalker/NMNetWalkerResult.scala (rev 0) +++ trunk/source/NMNetWalker/src/info/ngms/nmnetwalker/NMNetWalkerResult.scala 2010-01-13 02:02:50 UTC (rev 89) @@ -0,0 +1,46 @@ +/* + * Next Generation Management System Project + * Copyright(c) 2009, NGMS Project Team All Rights Reserved. + */ +package info.ngms.nmnetwalker + +/** + * 自動取得で得られた情報クラス + * + * @version $Id$ + * @author + */ +class NMNetWalkerResult(val results: List[NMResponseStatus]) { + import info.ngms.nmtree.NMDescription + import info.ngms.nmtree.NMDescriptions + + def toNMDescriptions(): NMDescriptions = { + val descriptions = new NMDescriptions + for (result <- results) { + result match { + case Found(node) => + val addressStr = node.address.getHostAddress() + val addDesc = NMDescription.make(addressStr, addressStr) + descriptions.header += (addDesc.tag -> addDesc) + + // FIXME +// for (element <- node.physical.elements) { +// val physicalDesc = NMDescription.make(element.toString(), element.toString()) +// descriptions.header += (physicalDesc.tag -> physicalDesc) +// } + case Timeout(address) => + val addressStr = address.getHostAddress() + val timeoutDesc = NMDescription.make("timeout" + addressStr, addressStr) + descriptions.header += (timeoutDesc.tag -> timeoutDesc) + case ConnDeny(address) => + val addressStr = address.getHostAddress() + val connDenyDesc = NMDescription.make("conndeny" + addressStr, addressStr) + descriptions.header += (connDenyDesc.tag -> connDenyDesc) + case _ => + throw new IllegalArgumentException("invalid NMResponseStatus") + } + } + descriptions + } +} + Copied: trunk/source/NMNetWalker/src/info/ngms/nmnetwalker/NMNetWalkerType.scala (from rev 85, trunk/source/NMNetWalker/src/info/ngms/nmnetwalker/NetWalkerType.scala) =================================================================== --- trunk/source/NMNetWalker/src/info/ngms/nmnetwalker/NMNetWalkerType.scala (rev 0) +++ trunk/source/NMNetWalker/src/info/ngms/nmnetwalker/NMNetWalkerType.scala 2010-01-13 02:02:50 UTC (rev 89) @@ -0,0 +1,15 @@ +/* + * Next Generation Management System Project + * Copyright(c) 2009, NGMS Project Team All Rights Reserved. + */ +package info.ngms.nmnetwalker + +/** + * NetWalker のタイプを表すクラス + * @version $Id$ + * @author + */ +abstract class NMNetWalkerType +case object NMSNMPNetWalkerType extends NMNetWalkerType +case object NMLLDPNetWalkerType extends NMNetWalkerType + Copied: trunk/source/NMNetWalker/src/info/ngms/nmnetwalker/NMResponseStatus.scala (from rev 85, trunk/source/NMNetWalker/src/info/ngms/nmnetwalker/ResponseStatus.scala) =================================================================== --- trunk/source/NMNetWalker/src/info/ngms/nmnetwalker/NMResponseStatus.scala (rev 0) +++ trunk/source/NMNetWalker/src/info/ngms/nmnetwalker/NMResponseStatus.scala 2010-01-13 02:02:50 UTC (rev 89) @@ -0,0 +1,19 @@ +/* + * Next Generation Management System Project + * Copyright(c) 2009, NGMS Project Team All Rights Reserved. + */ +package info.ngms.nmnetwalker + +import java.net.InetAddress + +/** + * 自動取得で取得した結果の状態クラス + * + * @version $Id$ + * @author + */ +abstract class NMResponseStatus +case class Found(node: NMBasicNodeInfo) extends NMResponseStatus +case class Timeout(address: InetAddress) extends NMResponseStatus +case class ConnDeny(address: InetAddress) extends NMResponseStatus + Deleted: trunk/source/NMNetWalker/src/info/ngms/nmnetwalker/NetWalkerFacade.scala =================================================================== --- trunk/source/NMNetWalker/src/info/ngms/nmnetwalker/NetWalkerFacade.scala 2010-01-13 01:49:39 UTC (rev 88) +++ trunk/source/NMNetWalker/src/info/ngms/nmnetwalker/NetWalkerFacade.scala 2010-01-13 02:02:50 UTC (rev 89) @@ -1,30 +0,0 @@ -/* - * Next Generation Management System Project - * Copyright(c) 2009, NGMS Project Team All Rights Reserved. - */ -package info.ngms.nmnetwalker - -import info.ngms.nmnetwalker.snmp.SNMPNetWalker -import info.ngms.nmnetwalker.snmp.SNMPNetWalkerParameter -import info.ngms.nmnetwalker.lldp.LLDPNetWalker -import info.ngms.nmnetwalker.lldp.LLDPNetWalkerParameter - -/** - * 自動取得結果を返却するクラス - * @version $Id$ - * @author - */ -private[nmnetwalker] object NetWalkerFacade { - def walk(netWalkerType: NetWalkerType, params: Map[String, String]): NetWalkerResult = { - netWalkerType match { - case SNMPNetWalkerType => - val param = SNMPNetWalkerParameter.fromMap(params) - SNMPNetWalker.walk(param) - case LLDPNetWalkerType => - val param = LLDPNetWalkerParameter.fromMap(params) - LLDPNetWalker.walk(param) - case _ => throw new IllegalArgumentException("invalid NetWalkerType") - } - } -} - Deleted: trunk/source/NMNetWalker/src/info/ngms/nmnetwalker/NetWalkerParameter.scala =================================================================== --- trunk/source/NMNetWalker/src/info/ngms/nmnetwalker/NetWalkerParameter.scala 2010-01-13 01:49:39 UTC (rev 88) +++ trunk/source/NMNetWalker/src/info/ngms/nmnetwalker/NetWalkerParameter.scala 2010-01-13 02:02:50 UTC (rev 89) @@ -1,20 +0,0 @@ -/* - * Next Generation Management System Project - * Copyright(c) 2009, NGMS Project Team All Rights Reserved. - */ -package info.ngms.nmnetwalker - -/** - * 情報を収集するのに必要なパラメータークラス - * - * @version $Id$ - * @author - */ -private[nmnetwalker] trait NetWalkerParameter { - import java.net.InetAddress - - val address: InetAddress - val timeout: Long - val retry: Int -} - Deleted: trunk/source/NMNetWalker/src/info/ngms/nmnetwalker/NetWalkerResult.scala =================================================================== --- trunk/source/NMNetWalker/src/info/ngms/nmnetwalker/NetWalkerResult.scala 2010-01-13 01:49:39 UTC (rev 88) +++ trunk/source/NMNetWalker/src/info/ngms/nmnetwalker/NetWalkerResult.scala 2010-01-13 02:02:50 UTC (rev 89) @@ -1,46 +0,0 @@ -/* - * Next Generation Management System Project - * Copyright(c) 2009, NGMS Project Team All Rights Reserved. - */ -package info.ngms.nmnetwalker - -/** - * 自動取得で得られた情報クラス - * - * @version $Id$ - * @author - */ -class NetWalkerResult(val results: List[ResponseStatus]) { - import info.ngms.nmtree.NMDescription - import info.ngms.nmtree.NMDescriptions - - def toNMDescriptions(): NMDescriptions = { - val descriptions = new NMDescriptions - for (result <- results) { - result match { - case Found(node) => - val addressStr = node.address.getHostAddress() - val addDesc = NMDescription.make(addressStr, addressStr) - descriptions.header += (addDesc.tag -> addDesc) - - // FIXME -// for (element <- node.physical.elements) { -// val physicalDesc = NMDescription.make(element.toString(), element.toString()) -// descriptions.header += (physicalDesc.tag -> physicalDesc) -// } - case Timeout(address) => - val addressStr = address.getHostAddress() - val timeoutDesc = NMDescription.make("timeout" + addressStr, addressStr) - descriptions.header += (timeoutDesc.tag -> timeoutDesc) - case ConnDeny(address) => - val addressStr = address.getHostAddress() - val connDenyDesc = NMDescription.make("conndeny" + addressStr, addressStr) - descriptions.header += (connDenyDesc.tag -> connDenyDesc) - case _ => - throw new IllegalArgumentException("invalid ResponseStatus") - } - } - descriptions - } -} - Deleted: trunk/source/NMNetWalker/src/info/ngms/nmnetwalker/NetWalkerType.scala =================================================================== --- trunk/source/NMNetWalker/src/info/ngms/nmnetwalker/NetWalkerType.scala 2010-01-13 01:49:39 UTC (rev 88) +++ trunk/source/NMNetWalker/src/info/ngms/nmnetwalker/NetWalkerType.scala 2010-01-13 02:02:50 UTC (rev 89) @@ -1,15 +0,0 @@ -/* - * Next Generation Management System Project - * Copyright(c) 2009, NGMS Project Team All Rights Reserved. - */ -package info.ngms.nmnetwalker - -/** - * NetWalker のタイプを表すクラス - * @version $Id$ - * @author - */ -abstract class NetWalkerType -case object SNMPNetWalkerType extends NetWalkerType -case object LLDPNetWalkerType extends NetWalkerType - Deleted: trunk/source/NMNetWalker/src/info/ngms/nmnetwalker/ResponseStatus.scala =================================================================== --- trunk/source/NMNetWalker/src/info/ngms/nmnetwalker/ResponseStatus.scala 2010-01-13 01:49:39 UTC (rev 88) +++ trunk/source/NMNetWalker/src/info/ngms/nmnetwalker/ResponseStatus.scala 2010-01-13 02:02:50 UTC (rev 89) @@ -1,19 +0,0 @@ -/* - * Next Generation Management System Project - * Copyright(c) 2009, NGMS Project Team All Rights Reserved. - */ -package info.ngms.nmnetwalker - -import java.net.InetAddress - -/** - * 自動取得で取得した結果の状態クラス - * - * @version $Id$ - * @author - */ -abstract class ResponseStatus -case class Found(node: BasicNodeInfo) extends ResponseStatus -case class Timeout(address: InetAddress) extends ResponseStatus -case class ConnDeny(address: InetAddress) extends ResponseStatus - Deleted: trunk/source/NMNetWalker/src/info/ngms/nmnetwalker/lldp/LLDPNetWalker.scala =================================================================== --- trunk/source/NMNetWalker/src/info/ngms/nmnetwalker/lldp/LLDPNetWalker.scala 2010-01-13 01:49:39 UTC (rev 88) +++ trunk/source/NMNetWalker/src/info/ngms/nmnetwalker/lldp/LLDPNetWalker.scala 2010-01-13 02:02:50 UTC (rev 89) @@ -1,19 +0,0 @@ -/* - * Next Generation Management System Project - * Copyright(c) 2009, NGMS Project Team All Rights Reserved. - */ -package info.ngms.nmnetwalker.lldp - -/** - * LLDP を使用して設定を取得するオブジェクト - * - * @version $Id$ - * @author - */ -private[nmnetwalker] object LLDPNetWalker { - def walk(param: LLDPNetWalkerParameter): NetWalkerResult = { - // FIXME - null - } -} - Deleted: trunk/source/NMNetWalker/src/info/ngms/nmnetwalker/lldp/LLDPNetWalkerParameter.scala =================================================================== --- trunk/source/NMNetWalker/src/info/ngms/nmnetwalker/lldp/LLDPNetWalkerParameter.scala 2010-01-13 01:49:39 UTC (rev 88) +++ trunk/source/NMNetWalker/src/info/ngms/nmnetwalker/lldp/LLDPNetWalkerParameter.scala 2010-01-13 02:02:50 UTC (rev 89) @@ -1,33 +0,0 @@ -/* - * Next Generation Management System Project - * Copyright(c) 2009, NGMS Project Team All Rights Reserved. - */ -package info.ngms.nmnetwalker.lldp - -import java.net.InetAddress - -/** - * LLDP でネットワークから情報を収集するのに必要な - * パラメーターを生成するオブジェクト - * - * @version $Id$ - * @author - */ -private[nmnetwalker] object LLDPNetWalkerParameter { - def fromMap(param: Map[String, String]): LLDPNetWalkerParameter = { - // - null - } -} - -/** - * LLDP でネットワークから情報を収集するのに必要な - * パラメータークラス - * - * @version $Id$ - * @author - */ -private[nmnetwalker] class LLDPNetWalkerParameter(val address: InetAddress, - val timeout: Long, - val retry: Int) extends NetWalkerParameter - Copied: trunk/source/NMNetWalker/src/info/ngms/nmnetwalker/lldp/NMLLDPNetWalker.scala (from rev 86, trunk/source/NMNetWalker/src/info/ngms/nmnetwalker/lldp/LLDPNetWalker.scala) =================================================================== --- trunk/source/NMNetWalker/src/info/ngms/nmnetwalker/lldp/NMLLDPNetWalker.scala (rev 0) +++ trunk/source/NMNetWalker/src/info/ngms/nmnetwalker/lldp/NMLLDPNetWalker.scala 2010-01-13 02:02:50 UTC (rev 89) @@ -0,0 +1,19 @@ +/* + * Next Generation Management System Project + * Copyright(c) 2009, NGMS Project Team All Rights Reserved. + */ +package info.ngms.nmnetwalker.lldp + +/** + * LLDP を使用して設定を取得するオブジェクト + * + * @version $Id$ + * @author + */ +private[nmnetwalker] object NMLLDPNetWalker { + def walk(param: NMLLDPNetWalkerParameter): NMNetWalkerResult = { + // FIXME + null + } +} + Copied: trunk/source/NMNetWalker/src/info/ngms/nmnetwalker/lldp/NMLLDPNetWalkerParameter.scala (from rev 86, trunk/source/NMNetWalker/src/info/ngms/nmnetwalker/lldp/LLDPNetWalkerParameter.scala) =================================================================== --- trunk/source/NMNetWalker/src/info/ngms/nmnetwalker/lldp/NMLLDPNetWalkerParameter.scala (rev 0) +++ trunk/source/NMNetWalker/src/info/ngms/nmnetwalker/lldp/NMLLDPNetWalkerParameter.scala 2010-01-13 02:02:50 UTC (rev 89) @@ -0,0 +1,33 @@ +/* + * Next Generation Management System Project + * Copyright(c) 2009, NGMS Project Team All Rights Reserved. + */ +package info.ngms.nmnetwalker.lldp + +import java.net.InetAddress + +/** + * LLDP でネットワークから情報を収集するのに必要な + * パラメーターを生成するオブジェクト + * + * @version $Id$ + * @author + */ +private[nmnetwalker] object NMLLDPNetWalkerParameter { + def fromMap(param: Map[String, String]): NMLLDPNetWalkerParameter = { + // + null + } +} + +/** + * LLDP でネットワークから情報を収集するのに必要な + * パラメータークラス + * + * @version $Id$ + * @author + */ +private[nmnetwalker] class NMLLDPNetWalkerParameter(val address: InetAddress, + val timeout: Long, + val retry: Int) extends NMNetWalkerParameter + Copied: trunk/source/NMNetWalker/src/info/ngms/nmnetwalker/snmp/NMSNMPNetWalker.scala (from rev 86, trunk/source/NMNetWalker/src/info/ngms/nmnetwalker/snmp/SNMPNetWalker.scala) =================================================================== --- trunk/source/NMNetWalker/src/info/ngms/nmnetwalker/snmp/NMSNMPNetWalker.scala (rev 0) +++ trunk/source/NMNetWalker/src/info/ngms/nmnetwalker/snmp/NMSNMPNetWalker.scala 2010-01-13 02:02:50 UTC (rev 89) @@ -0,0 +1,115 @@ +/* + * Next Generation Management System Project + * Copyright(c) 2009, NGMS Project Team All Rights Reserved. + */ +package info.ngms.nmnetwalker.snmp + +/** + * SNMP を使用して設定を取得するオブジェクト + * + * @version $Id$ + * @author + */ +private[nmnetwalker] object NMSNMPNetWalker { + import java.net.InetAddress + + import org.snmp4j.CommunityTarget + import org.snmp4j.MessageDispatcher + import org.snmp4j.MessageDispatcherImpl + import org.snmp4j.PDU + import org.snmp4j.Snmp + import org.snmp4j.TransportMapping + import org.snmp4j.event.ResponseEvent + import org.snmp4j.mp.MPv1 + import org.snmp4j.mp.MPv2c + import org.snmp4j.mp.MPv3 + import org.snmp4j.mp.SnmpConstants + import org.snmp4j.smi.Address + import org.snmp4j.smi.GenericAddress + import org.snmp4j.smi.OID + import org.snmp4j.smi.OctetString + import org.snmp4j.smi.VariableBinding + import org.snmp4j.transport.DefaultUdpTransportMapping + + import info.ngms.nmtree.NMDescription + import info.ngms.nmtree.NMDescriptions + + var SYSNAMEOID = "1.3.6.1.2.1.1.5.0" + + def walk(param: NMSNMPNetWalkerParameter): NMNetWalkerResult = { + var results = List[NMResponseStatus]() + + val snmp = createSnmp() + try { + val pdu = createPDU(param) + val target = createCommunityTarget(param) + + val resEvent = snmp.get(pdu, target) + + if (resEvent != null && resEvent.getResponse() != null) { + val vbs = resEvent.getResponse().getVariableBindings() + + for (i <- (0 to (vbs.size() - 1))) { + val vb = vbs.elementAt(i); + val resultStr = vb.toString() + val index = resultStr.indexOf("=") + + val key = resultStr.substring(0, index).trim + val value = resultStr.substring(index + 1).trim + + if (key == SYSNAMEOID) { + val response = new Found(new NMBasicNodeInfo(param.address, value)) + results = response :: results + } else { + // FIXME + } + } + } + } finally { + if (snmp != null) { + snmp.close() + } + } + + new NMNetWalkerResult(results) + } + + private def createSnmp(): Snmp = { + val msgDispatcher = new MessageDispatcherImpl() + msgDispatcher.addMessageProcessingModel(new MPv1()) + msgDispatcher.addMessageProcessingModel(new MPv2c()) + msgDispatcher.addMessageProcessingModel(new MPv3()) +// SecurityProtocols.getInstance().addDefaultProtocols() + val transport = new DefaultUdpTransportMapping() + val snmp = new Snmp(msgDispatcher, transport) + + transport.listen() + + snmp + } + + private def createCommunityTarget(param: NMSNMPNetWalkerParameter): CommunityTarget = { + val convertedAddress = String.format("udp:%s/161", param.address.getHostAddress()) + val targetAddress = GenericAddress.parse(convertedAddress) + + val target = new CommunityTarget() + target.setCommunity(new OctetString(param.community)) + target.setAddress(targetAddress) + target.setRetries(param.retry) + target.setTimeout(param.timeout) + target.setVersion(param.version) + + target + } + + private def createPDU(param: NMSNMPNetWalkerParameter): PDU = { + val pdu = new PDU() + pdu.setType(PDU.GET) + for (oid <- param.oids) { + pdu.add(new VariableBinding(new OID(oid.trim))) + } + + pdu + } +} + Copied: trunk/source/NMNetWalker/src/info/ngms/nmnetwalker/snmp/NMSNMPNetWalkerParameter.scala (from rev 86, trunk/source/NMNetWalker/src/info/ngms/nmnetwalker/snmp/SNMPNetWalkerParameter.scala) =================================================================== --- trunk/source/NMNetWalker/src/info/ngms/nmnetwalker/snmp/NMSNMPNetWalkerParameter.scala (rev 0) +++ trunk/source/NMNetWalker/src/info/ngms/nmnetwalker/snmp/NMSNMPNetWalkerParameter.scala 2010-01-13 02:02:50 UTC (rev 89) @@ -0,0 +1,70 @@ +/* + * Next Generation Management System Project + * Copyright(c) 2009, NGMS Project Team All Rights Reserved. + */ +package info.ngms.nmnetwalker.snmp + +import java.net.InetAddress + +/** + * SNMP でネットワークから情報を収集するのに必要な + * パラメーターを生成するオブジェクト + * + * @version $Id$ + * @author + */ +private[nmnetwalker] object NMSNMPNetWalkerParameter { + // param key + val ADDRESS: String = "address" + val TIMEOUT: String = "timeout" + val RETRY: String = "retry" + val COMMUNITY: String = "community" + val VERSION: String = "version" + val OIDS: String = "oids" + + /** + * + */ + def fromMap(params: Map[String, String]): NMSNMPNetWalkerParameter = { + val addressStr = params(ADDRESS) + require((addressStr != null) && (addressStr.length() >= 1), "address is null") + val address = InetAddress.getByName(addressStr) + + val timeoutStr = params(TIMEOUT) + require((timeoutStr != null) && (timeoutStr.length() >= 1), "timeout is null") + val timeout = timeoutStr.toLong + + val retryStr = params(RETRY) + require((retryStr != null) && (retryStr.length() >= 1), "retry is null") + val retry = retryStr.toInt + + val communityStr = params(COMMUNITY) + require((communityStr != null) && (communityStr.length() >= 1), "community is null") + val community = communityStr + + val versionStr = params(VERSION) + require((versionStr != null) && (versionStr.length() >= 1), "version is null") + val version = versionStr.toInt + + val oidsStr = params(OIDS) + require((oidsStr!= null) && (oidsStr.length() >= 1), "oids is null") + val oids = oidsStr.split(",").toList + + new NMSNMPNetWalkerParameter(address, timeout, retry, community, version, oids) + } +} + +/** + * SNMP でネットワークから情報を収集するのに必要な + * パラメータークラス + * + * @version $Id$ + * @author + */ +private[nmnetwalker] class NMSNMPNetWalkerParameter(val address: InetAddress, + val timeout: Long, + val retry: Int, + val community: String, + val version: Int, + val oids: List[String]) extends NMNetWalkerParameter + Deleted: trunk/source/NMNetWalker/src/info/ngms/nmnetwalker/snmp/SNMPNetWalker.scala =================================================================== --- trunk/source/NMNetWalker/src/info/ngms/nmnetwalker/snmp/SNMPNetWalker.scala 2010-01-13 01:49:39 UTC (rev 88) +++ trunk/source/NMNetWalker/src/info/ngms/nmnetwalker/snmp/SNMPNetWalker.scala 2010-01-13 02:02:50 UTC (rev 89) @@ -1,115 +0,0 @@ -/* - * Next Generation Management System Project - * Copyright(c) 2009, NGMS Project Team All Rights Reserved. - */ -package info.ngms.nmnetwalker.snmp - -/** - * SNMP を使用して設定を取得するオブジェクト - * - * @version $Id$ - * @author - */ -private[nmnetwalker] object SNMPNetWalker { - import java.net.InetAddress - - import org.snmp4j.CommunityTarget - import org.snmp4j.MessageDispatcher - import org.snmp4j.MessageDispatcherImpl - import org.snmp4j.PDU - import org.snmp4j.Snmp - import org.snmp4j.TransportMapping - import org.snmp4j.event.ResponseEvent - import org.snmp4j.mp.MPv1 - import org.snmp4j.mp.MPv2c - import org.snmp4j.mp.MPv3 - import org.snmp4j.mp.SnmpConstants - import org.snmp4j.smi.Address - import org.snmp4j.smi.GenericAddress - import org.snmp4j.smi.OID - import org.snmp4j.smi.OctetString - import org.snmp4j.smi.VariableBinding - import org.snmp4j.transport.DefaultUdpTransportMapping - - import info.ngms.nmtree.NMDescription - import info.ngms.nmtree.NMDescriptions - - var SYSNAMEOID = "1.3.6.1.2.1.1.5.0" - - def walk(param: SNMPNetWalkerParameter): NetWalkerResult = { - var results = List[ResponseStatus]() - - val snmp = createSnmp() - try { - val pdu = createPDU(param) - val target = createCommunityTarget(param) - - val resEvent = snmp.get(pdu, target) - - if (resEvent != null && resEvent.getResponse() != null) { - val vbs = resEvent.getResponse().getVariableBindings() - - for (i <- (0 to (vbs.size() - 1))) { - val vb = vbs.elementAt(i); - val resultStr = vb.toString() - val index = resultStr.indexOf("=") - - val key = resultStr.substring(0, index).trim - val value = resultStr.substring(index + 1).trim - - if (key == SYSNAMEOID) { - val response = new Found(new BasicNodeInfo(param.address, value)) - results = response :: results - } else { - // FIXME - } - } - } - } finally { - if (snmp != null) { - snmp.close() - } - } - - new NetWalkerResult(results) - } - - private def createSnmp(): Snmp = { - val msgDispatcher = new MessageDispatcherImpl() - msgDispatcher.addMessageProcessingModel(new MPv1()) - msgDispatcher.addMessageProcessingModel(new MPv2c()) - msgDispatcher.addMessageProcessingModel(new MPv3()) -// SecurityProtocols.getInstance().addDefaultProtocols() - val transport = new DefaultUdpTransportMapping() - val snmp = new Snmp(msgDispatcher, transport) - - transport.listen() - - snmp - } - - private def createCommunityTarget(param: SNMPNetWalkerParameter): CommunityTarget = { - val convertedAddress = String.format("udp:%s/161", param.address.getHostAddress()) - val targetAddress = GenericAddress.parse(convertedAddress) - - val target = new CommunityTarget() - target.setCommunity(new OctetString(param.community)) - target.setAddress(targetAddress) - target.setRetries(param.retry) - target.setTimeout(param.timeout) - target.setVersion(param.version) - - target - } - - private def createPDU(param: SNMPNetWalkerParameter): PDU = { - val pdu = new PDU() - pdu.setType(PDU.GET) - for (oid <- param.oids) { - pdu.add(new VariableBinding(new OID(oid.trim))) - } - - pdu - } -} - Deleted: trunk/source/NMNetWalker/src/info/ngms/nmnetwalker/snmp/SNMPNetWalkerParameter.scala =================================================================== --- trunk/source/NMNetWalker/src/info/ngms/nmnetwalker/snmp/SNMPNetWalkerParameter.scala 2010-01-13 01:49:39 UTC (rev 88) +++ trunk/source/NMNetWalker/src/info/ngms/nmnetwalker/snmp/SNMPNetWalkerParameter.scala 2010-01-13 02:02:50 UTC (rev 89) @@ -1,70 +0,0 @@ -/* - * Next Generation Management System Project - * Copyright(c) 2009, NGMS Project Team All Rights Reserved. - */ -package info.ngms.nmnetwalker.snmp - -import java.net.InetAddress - -/** - * SNMP でネットワークから情報を収集するのに必要な - * パラメーターを生成するオブジェクト - * - * @version $Id$ - * @author - */ -private[nmnetwalker] object SNMPNetWalkerParameter { - // param key - val ADDRESS: String = "address" - val TIMEOUT: String = "timeout" - val RETRY: String = "retry" - val COMMUNITY: String = "community" - val VERSION: String = "version" - val OIDS: String = "oids" - - /** - * - */ - def fromMap(params: Map[String, String]): SNMPNetWalkerParameter = { - val addressStr = params(ADDRESS) - require((addressStr != null) && (addressStr.length() >= 1), "address is null") - val address = InetAddress.getByName(addressStr) - - val timeoutStr = params(TIMEOUT) - require((timeoutStr != null) && (timeoutStr.length() >= 1), "timeout is null") - val timeout = timeoutStr.toLong - - val retryStr = params(RETRY) - require((retryStr != null) && (retryStr.length() >= 1), "retry is null") - val retry = retryStr.toInt - - val communityStr = params(COMMUNITY) - require((communityStr != null) && (communityStr.length() >= 1), "community is null") - val community = communityStr - - val versionStr = params(VERSION) - require((versionStr != null) && (versionStr.length() >= 1), "version is null") - val version = versionStr.toInt - - val oidsStr = params(OIDS) - require((oidsStr!= null) && (oidsStr.length() >= 1), "oids is null") - val oids = oidsStr.split(",").toList - - new SNMPNetWalkerParameter(address, timeout, retry, community, version, oids) - } -} - -/** - * SNMP でネットワークから情報を収集するのに必要な - * パラメータークラス - * - * @version $Id$ - * @author - */ -private[nmnetwalker] class SNMPNetWalkerParameter(val address: InetAddress, - val timeout: Long, - val retry: Int, - val community: String, - val version: Int, - val oids: List[String]) extends NetWalkerParameter - Modified: trunk/source/NMNetWalker/test/info/ngms/nmnetwalker/NetWalkerFacadeTest.scala =================================================================== --- trunk/source/NMNetWalker/test/info/ngms/nmnetwalker/NetWalkerFacadeTest.scala 2010-01-13 01:49:39 UTC (rev 88) +++ trunk/source/NMNetWalker/test/info/ngms/nmnetwalker/NetWalkerFacadeTest.scala 2010-01-13 02:02:50 UTC (rev 89) @@ -29,14 +29,14 @@ "timeout" -> "1000", "community" -> "public") - val netWalkerResult = NetWalkerFacade.walk(SNMPNetWalkerType, params) + val netWalkerResult = NMNetWalkerFacade.walk(NMSNMPNetWalkerType, params) for (result <- netWalkerResult.results) { result match { case Found(node) => printf("hostname: %s\n", node.hostname) case Timeout(address) => printf("timeout: %s\n", address.getHostAddress()) case ConnDeny(address) => printf("connection deny: %s\n", address.getHostAddress()) - case _ => throw new IllegalArgumentException("invalid NetWalkerResult") + case _ => throw new IllegalArgumentException("invalid NMNetWalkerResult") } } }