public int GetVbByIndex(int index, ref CDTLmtbVb obj) { if (VbCount() == 0) { return(-1); } if (index < 0 || VbCount() < index) { return(-1); } obj = m_VbTable[index]; return(0); }
/// <summary> /// 将snmp类型的pdu转换为LmtSnmp的pdu /// </summary> /// <param name="snmpPackage"></param> /// <param name="target"></param> /// <param name="lmtPdu"></param> /// <param name="reason"></param> /// <param name="isAsync"></param> private bool SnmpPdu2LmtPdu(SnmpV2Packet snmpPackage, UdpTarget target , CDTLmtbPdu lmtPdu, int reason, bool isAsync) { string logMsg; if (lmtPdu == null) { Log.Error("参数[lmtPdu]为空"); return(false); } // TODO // stru_LmtbPduAppendInfo appendInfo; logMsg = string.Format("snmpPackage.Pdu.Type = {0}", snmpPackage.Pdu.Type); Log.Debug(logMsg); logMsg = string.Format("PduType.V2Trap={0}", PduType.V2Trap); // TODO if (snmpPackage.Pdu.Type != PduType.V2Trap) // Trap { } else { } lmtPdu.Clear(); lmtPdu.set_LastErrorIndex(snmpPackage.Pdu.ErrorIndex); lmtPdu.set_LastErrorStatus(snmpPackage.Pdu.ErrorStatus); lmtPdu.SetRequestId(snmpPackage.Pdu.RequestId); // ip and port IPAddress srcIpAddr = target.Address; int port = target.Port; lmtPdu.set_SourceIp(srcIpAddr.ToString()); lmtPdu.set_SourcePort(port); lmtPdu.set_Reason(reason); //lmtPdu.SetPduType(snmpPackage.Pdu.Type); // TODO /* * LMTORINFO* pLmtorInfo = CDTAppStatusInfo::GetInstance()->GetLmtorInfo(csIpAddr); * if (pLmtorInfo != NULL && pLmtorInfo->m_isSimpleConnect && pdu.get_type() == sNMP_PDU_TRAP) * { * Oid id; * pdu.get_notify_id(id); * CString strTrapOid = id.get_printable(); * if (strTrapOid != "1.3.6.1.4.1.5105.100.1.2.2.3.1.1") * { * //如果是简单连接网元的非文件传输结果事件,就不要往上层抛送了 * return FALSE; * } * } */ //如果是错误的响应,则直接返回 if (lmtPdu.get_LastErrorStatus() != 0 || reason == -5) { return(true); } // 转换vb // 对于Trap消息,我们自己额外构造两个Vb,用来装载时间戳和trap Id if (snmpPackage.Pdu.Type == PduType.V2Trap) // Trap { // TODO: } foreach (Vb vb in snmpPackage.Pdu.VbList) { logMsg = string.Format("ObjectName={0}, Type={1}, Value={2}" , vb.Oid.ToString(), SnmpConstants.GetTypeName(vb.Value.Type), vb.Value.ToString()); Log.Debug(logMsg); CDTLmtbVb lmtVb = new CDTLmtbVb(); lmtVb.set_Oid(vb.Oid.ToString()); // SnmpConstants.GetSyntaxObject(AsnType.OCTETSTRING); // SnmpConstants.GetTypeName(vb.Value.Type); // TODO // lmtVb.set_Syntax(vb.Value.GetType()); // TODO:不确定对不对??????? if (AsnType.OCTETSTRING == vb.Value.Type) { /*对于像inetipAddress和DateandTime需要做一下特殊处理,把内存值转换为显示文本*/ // CString strNodeType = GetNodeTypeByOIDInCache(csIpAddr, strOID, strMIBPrefix); string strNodeType = ""; if ("DateandTime".Equals(strNodeType)) { } else if ("inetaddress".Equals(strNodeType)) { } else if ("MacAddress".Equals(strNodeType)) { } else if ("Unsigned32Array".Equals(strNodeType)) { } else if ("Integer32Array".Equals(strNodeType) || "".Equals(strNodeType)) { } else if ("MncMccType".Equals(strNodeType)) { } } string value = vb.Value.ToString(); lmtVb.set_Value(value); lmtPdu.AddVb(lmtVb); } // end foreach //如果得到的LmtbPdu对象里的vb个数为0,说明是是getbulk响应,并且没有任何实例 //为方便后面统一处理,将错误码设为资源不可得 if (lmtPdu.VbCount() == 0) { // TODO: SNMP_ERROR_RESOURCE_UNAVAIL lmtPdu.set_LastErrorStatus(13); lmtPdu.set_LastErrorIndex(1); } return(true); }
/// <summary> /// 将LmtPdu转换为snmpPdu /// </summary> /// <param name="pdu"></param> /// <param name="lmtPdu"></param> /// <param name="strRemoteIp"></param> /// <returns></returns> private bool LmtPdu2SnmpPdu(out Pdu pdu, CDTLmtbPdu lmtPdu, string strRemoteIp) { pdu = new Pdu(); string strMibPreFix = ""; string strOid; string strTmpOid; string strValue; SNMP_SYNTAX_TYPE strSyntaxType; int lmtVbCount = lmtPdu.VbCount(); for (int i = 0; i < lmtVbCount; i++) { CDTLmtbVb cDTLmtbVb = lmtPdu.GetVbByIndexEx(i); strTmpOid = cDTLmtbVb.get_Oid(); strSyntaxType = cDTLmtbVb.get_Syntax(); strValue = cDTLmtbVb.get_Value(); if (SNMP_SYNTAX_TYPE.SNMP_SYNTAX_OCTETS == strSyntaxType) { /*对于像inetipAddress和DateandTime需要做一下特殊处理,把内存值转换为显示文本*/ // CString strNodeType = GetNodeTypeByOIDInCache(csIpAddr, strOID, strMIBPrefix); string strNodeType = ""; if ("DateandTime".Equals(strNodeType)) { // TODO // strValue = strValue; } else if ("inetaddress".Equals(strNodeType)) { } else if ("MacAddress".Equals(strNodeType)) { } else if ("Unsigned32Array".Equals(strNodeType)) { } else if ("Integer32Array".Equals(strNodeType) || "".Equals(strNodeType)) { } else if ("MncMccType".Equals(strNodeType)) { } } // TODO Vb vb = new Vb(new Oid(strTmpOid)); SetVbValue(ref vb, strSyntaxType, strValue); pdu.VbList.Add(vb); } // end for return(true); }
/// <summary> /// 执行一条类型为Get的同步操作命令 /// </summary> /// <param name="cmdName"></param> /// <param name="requestId"></param> /// <param name="strIndex"></param> /// <param name="strIpAddr"></param> /// <param name="lmtPdu"></param> /// <returns></returns> public int CmdGetSync(string cmdName, out long requestId, string strIndex , string strIpAddr, ref CDTLmtbPdu lmtPdu, bool isPrint = false , bool needCheck = false, long timeOut = 0) { requestId = 0; Log.Info("CmdGetSync() start"); string msg = string.Format("cmdName={0},requestId={1},strIndex={2}, strIpAddr={3}" , cmdName, requestId, strIndex, strIpAddr); Log.Info(msg); if (string.IsNullOrEmpty(cmdName) || string.IsNullOrEmpty(strIpAddr)) { return(-1); } // TODO: 数据库先打桩 string strMibList = ""; // test if (cmdName.Equals("aaa")) { strMibList = "100.1.9.1.1|100.1.9.1.2"; } else { strMibList = "100.1.2.1.1.1.5.3"; } if (string.IsNullOrEmpty(strMibList)) { return(-1); } // 转换为oid数组 string[] mibList = StringToArray(strMibList); if (mibList == null) { return(-1); } // TODO : bNeedCheck if (needCheck) { } // TODO: // 获取oid的前缀 string strPreFixOid = "1.3.6.1.4.1.5105"; StringBuilder sbOid = new StringBuilder(); foreach (string v in mibList) { sbOid.Clear(); sbOid.AppendFormat("{0}.{1}{2}", strPreFixOid, v, strIndex); CDTLmtbVb vb = new CDTLmtbVb(); vb.set_Oid(sbOid.ToString()); lmtPdu.AddVb(vb); } lmtPdu.setCmdName(cmdName); lmtPdu.setPrintId(isPrint); lmtPdu.setSyncId(true); // 根据ip获取当前基站的snmp实例 LmtbSnmpEx lmtbSnmpEx = DTLinkPathMgr.GetInstance().getSnmpByIp(strIpAddr); int rs = lmtbSnmpEx.SnmpGetSync(lmtPdu, out requestId, strIpAddr, timeOut); if (rs != 0) { Log.Error("执行lmtbSnmpEx.SnmpGetSync()方法错误"); } return(0); }
/// <summary> /// 执行一条类型为Set的异步操作命令 /// </summary> /// <param name="cmdName"></param> /// <param name="requestId"></param> /// <param name="name2Value"></param> /// <param name="strIndex"></param> /// <param name="strIpAddr"></param> /// <param name="lmtPdu"></param> /// <param name="isPrint"></param> /// <param name="needCheck"></param> /// <param name="timeOut"></param> /// <returns></returns> public int CmdSetAsync(String cmdName, out long requestId, Dictionary <string, string> name2Value , string strIndex, string strIpAddr, bool isPrint = false, bool needCheck = false) { requestId = 0; int rs = 0; CDTLmtbPdu lmtPdu = new CDTLmtbPdu(); // TODO: 从数据库获取命令对应的oid string strMibList = "100.1.2.2.2.1.2|100.1.2.2.2.1.3|100.1.2.2.2.1.4|100.1.2.2.2.1.5|100.1.2.2.2.1.6|100.1.2.2.2.1.7"; if (string.IsNullOrEmpty(strMibList)) { return(-1); } // 将字符串转换为oid数组 string[] mibList = StringToArray(strMibList); if (mibList == null) { return(-1); } string strIndexFmt = string.Format(".{0}", strIndex.Trim('.')); // TODO if (needCheck) { } // 获取oid的前缀 string strPreFixOid = "1.3.6.1.4.1.5105"; StringBuilder sbOid = new StringBuilder(); string strMibValue; string strTyep; string strMibName; foreach (string v in mibList) { sbOid.Clear(); sbOid.AppendFormat("{0}.{1}{2}", strPreFixOid, v, strIndexFmt); CDTLmtbVb vb = new CDTLmtbVb(); vb.set_Oid(sbOid.ToString()); strTyep = ""; strMibName = ""; strMibValue = ""; // TODO: 从数据库中获取oid的名称和数据类型 MibNodeInfoTest mibNodeInfoTest = GetMibNodeInfoByOID(strIpAddr, v); strTyep = mibNodeInfoTest.strType; strMibName = mibNodeInfoTest.strMibName; if (name2Value.ContainsKey(strMibName)) { strMibValue = name2Value[strMibName]; } else { continue; } vb.set_Value(strMibValue); // TODO: vb.set_Syntax(GetAsnTypeByMibType(strTyep)); lmtPdu.AddVb(vb); } // end foreach lmtPdu.setCmdName(cmdName); lmtPdu.setPrintId(isPrint); lmtPdu.setSyncId(true); LmtbSnmpEx lmtbSnmpEx = DTLinkPathMgr.GetInstance().getSnmpByIp(strIpAddr); rs = lmtbSnmpEx.SnmpSetAsync(lmtPdu, out requestId, strIpAddr); if (rs != 0) { Log.Error("执行lmtbSnmpEx.SnmpSetAsync()方法错误"); } return(rs); }
public void Copy(out CDTLmtbVb pVb) { pVb = this; }
//在Pdu里田间Vb public void AddVb(CDTLmtbVb pLmtbVb) { m_VbTable.Add(pLmtbVb); }