/// <summary> /// 异步Set操作 /// </summary> /// <param name="lmtPdu"></param> /// <param name="requestId"></param> /// <param name="strIpAddr"></param> /// <returns></returns> public int SnmpSetAsync(CDTLmtbPdu lmtPdu, out long requestId, string strIpAddr) { requestId = 0; Log.Debug("========== SnmpGetSync() Start =========="); string msg = string.Format("pars: lmtPdu={0}, requestId={1}, strIpAddr={2}" , lmtPdu, requestId, strIpAddr); Log.Debug(msg); if (string.IsNullOrEmpty(strIpAddr)) { Log.Error("参数strIpAddr为空"); return(-1); } if (lmtPdu == null) { Log.Error("参数lmtPdu为空"); return(-1); } // TODO: 根据基站ip获取Lmtor信息 //LMTORINFO* pLmtorInfo = CDTAppStatusInfo::GetInstance()->GetLmtorInfo(remoteIpAddr); SnmpHelper snmp = m_SnmpAsync; if (null == snmp) { msg = string.Format("基站[{0}]的snmp连接不存在,无法下发snmp命令"); Log.Error(msg); return(-1); } // TODO lmtPdu.setReqMsgType((int)PduType.Set); Pdu pdu = new Pdu(); requestId = pdu.RequestId; // TODO: bool rs = LmtPdu2SnmpPdu(out pdu, lmtPdu, strIpAddr); if (!rs) { Log.Error("LmtPdu2SnmpPdu()转换错误"); } SnmpAsyncResponse snmpCallback = new SnmpAsyncResponse(this.SnmpCallbackFun); rs = snmp.SetRequestAsync(pdu, snmpCallback); if (!rs) { Log.Error("SNMP 异步请求错误"); return(-1); } return(0); }
/// <summary> /// 创建snmp回话,包括同步、异步两这个snmp连接 /// </summary> /// <param name="isIpV6"></param> /// <returns></returns> public int CreateSnmpSession(string commnuity, string destIpAddr, bool isIpV6) { int status = 0; // 同步snmp连接 m_SnmpSync = new SnmpHelperV2c(commnuity, destIpAddr); // 异步snmp连接 m_SnmpAsync = new SnmpHelperV2c(commnuity, destIpAddr); return(status); }
/// <summary> /// 同步Set操作 /// </summary> /// <param name="lmtPdu"></param> /// <param name="requestId"></param> /// <param name="strIpAddr"></param> /// <param name="timeOut"></param> /// <returns></returns> public int SnmpSetSync(CDTLmtbPdu lmtPdu, out long requestId, string strIpAddr, long timeOut) { requestId = 0; Log.Debug("========== SnmpGetSync() Start =========="); string msg = string.Format("pars: lmtPdu={0}, requestId={1}, strIpAddr={2}, timeOut={3}" , lmtPdu, requestId, strIpAddr, timeOut); Log.Debug(msg); if (string.IsNullOrEmpty(strIpAddr)) { Log.Error("参数strIpAddr为空"); return(-1); } if (lmtPdu == null) { Log.Error("参数lmtPdu为空"); return(-1); } // TODO: 根据基站ip获取Lmtor信息 //LMTORINFO* pLmtorInfo = CDTAppStatusInfo::GetInstance()->GetLmtorInfo(remoteIpAddr); SnmpHelper snmp = m_SnmpSync; if (null == snmp) { msg = string.Format("基站[{0}]的snmp连接不存在,无法下发snmp命令"); Log.Error(msg); return(-1); } // TODO lmtPdu.setReqMsgType((int)PduType.Set); Pdu pdu = new Pdu(); // TODO: string community = "private"; bool rs = LmtPdu2SnmpPdu(out pdu, lmtPdu, strIpAddr); SnmpV2Packet result = snmp.SetRequest(pdu); if (result == null) { Log.Error("SNMP request error, response is null."); return(-1); } rs = SnmpPdu2LmtPdu(result, snmp.m_target, lmtPdu, 0, false); return(0); }
/// <summary> /// 同步Get操作 /// </summary> /// <param name="lmtPdu"></param> /// <param name="requestId"></param> /// <param name="strIpAddr"></param> /// <param name="timeOut"></param> /// <returns></returns> public int SnmpGetSync(CDTLmtbPdu lmtPdu, out long requestId, string strIpAddr, long timeOut) { requestId = 0; Log.Debug("========== SnmpGetSync() Start =========="); string msg = string.Format("pars: lmtPdu={0}, requestId={1}, strIpAddr={2}, timeOut={3}" , lmtPdu, requestId, strIpAddr, timeOut); Log.Debug(msg); if (string.IsNullOrEmpty(strIpAddr)) { Log.Error("strIpAddr is null"); return(-1); } if (lmtPdu == null) { Log.Error("参数lmtPdu为空"); return(-1); } // TODO: 根据基站ip获取Lmtor信息 //LMTORINFO* pLmtorInfo = CDTAppStatusInfo::GetInstance()->GetLmtorInfo(remoteIpAddr); SnmpHelper snmp = m_SnmpSync; if (null == snmp) { msg = string.Format("基站[{0}]的snmp连接不存在,无法下发snmp命令"); Log.Error(msg); return(-1); } /* * List<string> vbList = new List<string>(); * * int vbCount = lmtPdu.VbCount(); * * for (int i = 0; i < vbCount; i++) * { * CDTLmtbVb lmtVb = lmtPdu.GetVbByIndexEx(i); * string oid = lmtVb.get_Oid(); * vbList.Add(oid); * } */ // SnmpV2Packet result = snmp.GetRequest(vbList); Pdu pdu; bool rs = LmtPdu2SnmpPdu(out pdu, lmtPdu, strIpAddr); if (!rs) { Log.Error("LmtPdu2SnmpPdu()转换错误"); return(-1); } SnmpV2Packet result = snmp.GetRequest(pdu); if (result == null) { Log.Error("SNMP request error, response is null."); return(-1); } requestId = result.Pdu.RequestId; rs = SnmpPdu2LmtPdu(result, snmp.m_target, lmtPdu, 0, false); return(0); }