【问题标题】:process of making a CWMP (tr-069 protocol) to get info from devices制作 CWMP(tr-069 协议)以从设备获取信息的过程
【发布时间】:2020-06-03 22:50:46
【问题描述】:

我正在尝试在我的工作中构建 c# 软件,以从具有 tr-069(CWMP) 的设备获取信息。 有人可以告诉我如何进一步构建这个吗? 也有人可以告诉我如何从 CPE 获取肥皂消息

我已经做了这个。 第一个功能仅适用于肥皂

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using System.Xml.Linq;
using System.Xml.Serialization;

namespace SoapToClassData

{
    class Program
    {
        static void Main(string[] args)
        {
            Execute();
        }

        public static void Execute()
        {
            HttpWebRequest request = CreateWebRequest();
            XmlDocument soapEnvelopeXml = new XmlDocument();
            // soap 
            soapEnvelopeXml.LoadXml(@"<?xml version=""1.0"" encoding=""utf-8""?>
                <SOAP-ENV:Envelope
                xmlns:SOAP-ENV=""http://schemas.xmlsoap.org/soap/envelope/""
                xmlns:SOAP-ENC=""http://schemas.xmlsoap.org/soap/encoding/""
                xmlns:xsd=""http://www.w3.org/2001/XMLSchema""
                xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance""
                xmlns:cwmp=""urn:dslforum-org:cwmp-1-0"">
                <SOAP-ENV:Header>
                    <cwmp:ID SOAP-ENV:mustUnderstand=""1"">279384</cwmp:ID>
                </SOAP-ENV:Header>
                <SOAP-ENV:Body>
                    <cwmp:Inform>
                        <DeviceId>
                            <Manufacturer>DrayTek Corp.</Manufacturer>
                            <OUI>00507F</OUI>
                            <ProductClass>EG8040H5</ProductClass>
                            <SerialNumber>001DAA18E148</SerialNumber>
                        </DeviceId>
                        <Event SOAP-ENC:arrayType=""cwmp: EventStruct[04]""> 
                            <EventStruct> 
                                <EventCode>0 BOOTSTRAP</EventCode> 
                                <CommandKey></CommandKey> 
                            </EventStruct> 
                            <EventStruct> 
                                <EventCode>1 BOOT</EventCode> 
                                <CommandKey></CommandKey> 
                            </EventStruct> 
                            <EventStruct> 
                                <EventCode>2 PERIODIC</EventCode> 
                                <CommandKey></CommandKey> 
                            </EventStruct>  
                            <EventStruct> 
                                <EventCode>4 VALUE CHANGE</EventCode> 
                                <CommandKey></CommandKey> 
                            </EventStruct> 
                        </Event>
                        <MaxEnvelopes>1</MaxEnvelopes>
                        <CurrentTime>2020-02-17T14:30:33+00:00</CurrentTime>
                        <RetryCount>0</RetryCount>
                        <ParameterList SOAP-ENC:arrayType=""cwmp:ParameterValueStruct[9]"">
                            <ParameterValueStruct>
                                <Name>InternetGatewayDevice.ManagementServer.ParameterKey</Name>
                                <Value xsi:type=""xsd:string""/>
                            </ParameterValueStruct>
                            <ParameterValueStruct>
                                <Name>InternetGatewayDevice.ManagementServer.ConnectionRequestURL</Name>
                                <Value xsi:type=""xsd:string"">http://ip:8069/cwm/CRN.html</Value>
                            </ParameterValueStruct>
                            <ParameterValueStruct>
                                <Name>InternetGatewayDevice.DeviceSummary</Name>
                                <Value xsi:type=""xsd:string"">InternetGatewayDevice:1.4[](Baseline:1, EthernetLAN:1, WiFiLAN:2, Time:1, IPPing:1, DeviceAssociation:1)</Value>
                            </ParameterValueStruct>
                            <ParameterValueStruct>
                                <Name>InternetGatewayDevice.DeviceInfo.SerialNumber</Name>
                                <Value xsi:type=""xsd:string"">001DAA18E148</Value>
                            </ParameterValueStruct>
                            <ParameterValueStruct>
                                <Name>InternetGatewayDevice.DeviceInfo.SpecVersion</Name>
                                <Value xsi:type=""xsd:string"">1.0</Value>
                            </ParameterValueStruct>
                            <ParameterValueStruct>
                                <Name>InternetGatewayDevice.DeviceInfo.HardwareVersion</Name>
                                <Value xsi:type=""xsd:string"">e</Value>
                            </ParameterValueStruct>
                            <ParameterValueStruct>
                                <Name>InternetGatewayDevice.DeviceInfo.SoftwareVersion</Name>
                                <Value xsi:type=""xsd:string"">3.9.1.1</Value>
                            </ParameterValueStruct>
                            <ParameterValueStruct>
                                <Name>InternetGatewayDevice.DeviceInfo.ProvisioningCode</Name>
                                <Value xsi:type=""xsd:string""/>
                            </ParameterValueStruct>
                            <ParameterValueStruct>
                                <Name>InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.1.ExternalIPAddress</Name>
                                <Value xsi:type=""xsd:string"">213.125.61.108</Value>
                            </ParameterValueStruct>
                        </ParameterList>
                    </cwmp:Inform>
                    <SOAP-ENV:Fault>
                        <faultcode>SOAP-ENV:Client</faultcode>
                        <faultstring>CWMP fault</faultstring>
                        <detail>
                            <cwmp:fault>
                                <FaultCode>9005</FaultCode>
                                <FaultString>Invalid parameter Name</FaultString>
                            </cwmp:fault>
                        </detail>
                    </SOAP-ENV:Fault>
                </SOAP-ENV:Body>
            </SOAP-ENV:Envelope>");

            using (Stream stream = request.GetRequestStream())
            {
                soapEnvelopeXml.Save(stream);
            }

            using (WebResponse response = request.GetResponse())
            {
                using (StreamReader rd = new StreamReader(response.GetResponseStream()))
                {
                    string soapResult = rd.ReadToEnd();
                    // I get here the soap that i've typed here above
                    Console.WriteLine(soapResult);
                }
            }
        }

在这里,我与 acs 建立连接并发送肥皂

        // connection with the acs
        public static HttpWebRequest CreateWebRequest()
        {
            string action = "https://acsnoc.hompes.nl:443/ACSServer/services/ACSServlet";

            HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(@"https://acsnoc.hompes.nl:443/ACSServer/services/ACSServlet");
            webRequest.Credentials = new NetworkCredential("username", "password");
            webRequest.Headers.Add("SOAPAction", action);
            webRequest.ContentType = "text/xml;charset=\"utf-8\"";
            webRequest.Accept = "text/xml";
            webRequest.Method = "POST";
            return webRequest;
        }
    }
}

【问题讨论】:

    标签: c# soap protocols


    【解决方案1】:

    您需要更好地了解协议,我建议您花一些时间在这里https://www.qacafe.com/tr-069-training/session-overview/,他们有关于该主题的大量资料。

    至于你的代码......你会在观看培训后理解,如果你想与 CPE 交谈......你不能......不能直接。

    可以这么说,协议有点倒退。通信始终由 CPE 发起。您想与 CPE 交谈,使用正确的凭据,您执行“连接请求”,这只是一个 HTTP GET 请求。您可以将其视为“戳”……“嘿,我需要和你谈谈”。但是,它不会与“你”对话,它会与配置的 ACS 对话。

    通信从 CPE 发送“通知”开始,这基本上类似于您在那里的 XML 块,作为 SOAP 请求发送。
    在一些“类似 heanshake”的响应和请求之后,CPE 将发送和“空 POST”(没有任何有效负载的 POST 请求......除了标题)。这是在告诉 ACS “我在等待指示”。

    再次,如前所述,协议有点倒退,这就是我的意思...
    来自 ACS 的“请求”(无论是用于读取还是设置信息)在 HTTP 响应的正文中,从第一个空 POST 开始,一个接一个地转到 CPE。然后 CPE 用另一个 POST 响应第一个请求的数据,ACS 在 HTTP 响应中发送下一个“请求”......等等。

    当 ACS 无话可说时,它会对他收到的最后一个 POST 做出响应,并以“HTTP 204 No Content”的方式告诉 CPE“我无话可说”,因此 CPE 关闭HTTP 会话。 红色箭头是从 CPE 发送的 HTTP POST 请求。 绿色箭头是对这些请求的 HTTP 响应。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-11-23
      • 1970-01-01
      • 2023-03-11
      • 1970-01-01
      • 1970-01-01
      • 2023-02-26
      • 1970-01-01
      • 2021-10-13
      相关资源
      最近更新 更多