通信是可以了,但是现在是单向的呼叫,即AP呼叫ACS,那么ACS怎么呼叫AP呢?
在TR-069协议3.2中规定了如何向AP发送连接请求,让AP创建连接。注意协议中规定是ACS向AP发送连接请求,AP鉴权通过后才会创建连接到ACS,所以ACS是不会连接到AP的,只是会发送连接请求,请求AP链接到ACS。
下面是一种实现方式,使用了HTTPClient模拟发送GET请求到AP,其中AP的请求URL包含在Inform中了,也就是InternetGatewayDevice.ManagementServer.Connection
RequestURL对应的Value,用户名和密码就是上篇文章提到的 cwmp cep username XXX
password xxxx对应的value了。
具体不多说,先看协议再看代码了。
package com.seahigh;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.UsernamePasswordCredentials;
import org.apache.commons.httpclient.auth.AuthPolicy;
import org.apache.commons.httpclient.auth.AuthScope;p
import org.apache.commons.httpclient.methods.GetMethod;
/**
*
* @author 汪心利
* @Create Time 2009-1-6上午10:15:20
* @CopyRight (C) seahigh 2009
*/
public class ConnectionRequest {
public static void main(String[] arg) throws HttpException, IOException {
callCPE("http://192.168.1.200:7547/cpe", "admin", "admin");
}
/**
* ACS CALL CPE
*
* @param connectionRequestURL
* 访问CPE的URL 如:http://192.168.1.200:7547/cpe
* @param cepAccount
* 连接CPE用户名
* @param cpePWD
* 访问CPE的密码
*/
public static void callCPE(String connectionRequestURL, String cpeAccount,
String cpePWD) {
GetMethod get = new GetMethod(connectionRequestURL);
int result = 0;
try {
HttpClient httpclient = new HttpClient();
List authPrefs = new ArrayList(1);
// Digest Auth
authPrefs.add(AuthPolicy.DIGEST);
httpclient.getParams().setParameter(
AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs);
// add CPE access param
httpclient.getState().setCredentials(AuthScope.ANY,
new UsernamePasswordCredentials(cpeAccount, cpePWD));
result = httpclient.executeMethod(get);
} catch (HttpException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
// relaseConnection
get.releaseConnection();
}
System.out.println("Response status code: " + result);
System.out.println("Response body: ");
}
}
执行下程序,就可以看到AP向ACS发送Inform了,仔细查看inform的消息,就会发现
enent-code 6 Connection Request了,这就是说是ACS请求建立会话而创建的连接了.
结果如下:
<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">2</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>6 CONNECTION REQUEST</EventCode> <CommandKey></CommandKey> </EventStruct> </Event> <MaxEnvelopes>1</MaxEnvelopes> <CurrentTime>2000-04-28T06:11:26</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>