Пример #1
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);
        }
Пример #2
0
        /// <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);
        }