TR 069是DSL Fourm提出來的一種協議,即CWMP協議,主要是對 使用者終端裝置的管理。
其功能主要有兩塊組成ACS(Auto Config Server)和CPE(Customer Pression Equalment)。其具體功能請參考TR-069協議,網路上也有介紹,在此不再多說了。
最近公司接到了一個項目,主要是對電信的AP(Access Point)裝置進行效能監控和管理。我也是項目組的開發人員,主要是負責ACS的搭建。
根據協議的描述 CPE會定時呼叫ACS,ACS也可以呼叫CPE。ACS呼叫CPE的時候,其實是
向CPE發送一個ConnectionRequest,經過授權認證等過程後,CPE會發個Inform給ACS,
其中包含了EventCode,根據EnventCode我們就可已知道是CPE主動呼叫的,還是ACS呼叫後,CPE才建立的串連。TR-069規定響應ACS的呼叫後的Inform Event Code是6 Connection Request。
我也是第一次進行通訊方面的開發,以前沒有接觸過的東西。首先得要下個協議,在這裡我有個感受,就是要下個原版的TR-069協議,自己去慢慢的理解,不懂單詞要查,雖然是全英文的,但是也是最權威的,也是原滋原味的。
可
能看了協議後會覺得很蒙,很多代名詞都不懂。SOAP,RPC。SOAP和PRC感覺有點像WebService,其實我也沒有webservice的開
發經驗,但是我覺得在TR-069協議中,ACS通過SOAP協議指定要調用CPE的哪些方法,以及需要的參數。然後通過RPC在CPE端執行指定的方
法,返回方法執行後的結果。然後在通過SOAP協議返回執行後的結果給CPE。
假如A系統有個查詢手機號碼的歸屬地的功能,那麼B
系統中也要實現這個功能,那麼兩個系統可以通過通訊的方式進行資料互動。B系統通過SOAP協議指定需要執行的功能(方法)和參數(手機號碼),然後發送
給A系統。A系統接受了SOAP協議包含的XML,開始解析,然後調用自身的method,然後將執行後的結果封裝成XML
格式的資料後發給B系統,B系統解析後擷取執行的結果。總之,最重要的是通訊。
ACS和CPE都是支援HTTP協議,
所有ACS只需要有HTTP容器就可以了。所以很自然的,我們就想到了Servlet來實現。我也不知道是啥格式的XML,但是公司催的緊,所有趕緊開工
了。既然不知道怎麼實現,但是CPE會定時呼叫的,所有先把它呼叫後的東西接收過來看看,到底是什麼。
目前測試的CPE是H3C的AP。
第一,建立ACSServlet,準備接收訊息。
代碼如下:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.util.HashMap;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import com.seahigh.tyt.acs.util.AcsUtil;
/**
* ACS serverImp
*
* @author 汪心利
* @Create Time 2009-1-4下午04:34:42 (c)copy right seahigh 2009
*/
public class ACSServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException {
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// session 記住已執行的method
InputStream in = request.getInputStream();
String ip = request.getRemoteAddr();
InputStreamReader ir = new InputStreamReader(request.getInputStream());
BufferedReader input = new BufferedReader(ir);
String line;
String xml = "";
while ((line = input.readLine()) != null) {
if (line.trim().length() <= 0)
continue;
xml += line;
}
in.close();
input.close();
System.out.println(ip+"Post:"+xml);
}
}
然後在web.xml中配置Servlet了
<soap:Envelope 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"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
<soap:Header>
<cwmp:ID soap:mustUnderstand="1">1</cwmp:ID>
</soap:Header>
<soap:Body>
<cwmp:Inform>
<DeviceId>
<Manufacturer>H3C</Manufacturer>
<OUI>000FE2</OUI>
<ProductClass>Gateway</ProductClass>
<SerialNumber>210235A32MC085003208</SerialNumber>
</DeviceId>
<Event soapenc:arrayType="cwmp:EventStruct[1]">
<EventStruct>
<EventCode>0 BOOTSTRAP</EventCode>
<CommandKey></CommandKey>
</EventStruct>
</Event>
<MaxEnvelopes>1</MaxEnvelopes>
<CurrentTime>2000-05-10T09:55:50</CurrentTime>
<RetryCount>0</RetryCount>
<ParameterList soapenc:arrayType="cwmp:ParameterValueStruct[8]">
<ParameterValueStruct>
<Name>InternetGatewayDevice.DeviceSummary</Name>
<Value soap:type="soap:string">InternetGatewayDevice:1.0[](Baseline:1)</Value>
</ParameterValueStruct>
<ParameterValueStruct>
<Name>InternetGatewayDevice.DeviceInfo.SpecVersion</Name>
<Value soap:type="soap:string">1.0</Value>
</ParameterValueStruct>
<ParameterValueStruct>
<Name>InternetGatewayDevice.DeviceInfo.HardwareVersion</Name>
<Value soap:type="soap:string">Ver.A</Value>
</ParameterValueStruct>
<ParameterValueStruct>
<Name>InternetGatewayDevice.DeviceInfo.SoftwareVersion</Name>
<Value soap:type="soap:string">V100R001B47D011SP01</Value>
</ParameterValueStruct>
<ParameterValueStruct>
<Name>InternetGatewayDevice.DeviceInfo.ProvisioningCode</Name>
<Value soap:type="soap:string">ProvisioningCode</Value>
</ParameterValueStruct>
<ParameterValueStruct>
<Name>InternetGatewayDevice.ManagementServer.ConnectionRequestURL</Name>
<Value soap:type="soap:string">http://192.168.1.200:7547/cpe
</Value>
</ParameterValueStruct>
<ParameterValueStruct>
<Name>InternetGatewayDevice.ManagementServer.ParameterKey</Name>
<Value soap:type="soap:string"></Value>
</ParameterValueStruct>
<ParameterValueStruct>
<Name>InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANPPPConnection.1.ExternalIPAddress</Name>
<Value soap:type="soap:string">192.168.1.200</Value>
</ParameterValueStruct>
</ParameterList>
</cwmp:Inform>
</soap:Body>
</soap:Envelope>
更多內容詳見: http://www.tr069bbs.com