1 package org.umu.cops.ospep;
\r
3 import java.io.IOException;
\r
4 import java.net.Socket;
\r
5 import java.util.Enumeration;
\r
6 import java.util.Vector;
\r
8 import org.umu.cops.stack.COPSClientSI;
\r
9 import org.umu.cops.stack.COPSContext;
\r
10 import org.umu.cops.stack.COPSDeleteMsg;
\r
11 import org.umu.cops.stack.COPSException;
\r
12 import org.umu.cops.stack.COPSHandle;
\r
13 import org.umu.cops.stack.COPSHeader;
\r
14 import org.umu.cops.stack.COPSReason;
\r
15 import org.umu.cops.stack.COPSReportMsg;
\r
16 import org.umu.cops.stack.COPSReportType;
\r
17 import org.umu.cops.stack.COPSReqMsg;
\r
18 import org.umu.cops.stack.COPSSyncStateMsg;
\r
21 * COPS message transceiver class for outsourcing connections at the PEP side.
\r
23 public class COPSPepOSMsgSender {
\r
25 * Socket connection to PDP
\r
27 protected Socket _sock;
\r
30 * COPS client-type that identifies the policy client
\r
32 protected short _clientType;
\r
35 * COPS client handle used to uniquely identify a particular
\r
36 * PEP's request for a client-type
\r
38 protected COPSHandle _handle;
\r
41 * Creates a COPSPepMsgSender
\r
43 * @param clientType Client-type
\r
44 * @param clientHandle Client handle
\r
45 * @param sock Socket connected to the PDP
\r
47 public COPSPepOSMsgSender (short clientType, COPSHandle clientHandle, Socket sock) {
\r
49 _handle = clientHandle;
\r
50 _clientType = clientType;
\r
56 * Gets the client handle
\r
57 * @return Client's <tt>COPSHandle</tt>
\r
59 public COPSHandle getClientHandle() {
\r
64 * Gets the client-type
\r
65 * @return Client-type value
\r
67 public short getClientType() {
\r
72 * Sends a request to the PDP.
\r
73 * The PEP establishes a request state client handle for which the
\r
74 * remote PDP may maintain state.
\r
75 * @param clientSIs Client data
\r
76 * @throws COPSPepException
\r
78 public void sendRequest(Vector clientSIs) throws COPSPepException {
\r
79 // Create COPS Message
\r
80 COPSHeader hdr = new COPSHeader(COPSHeader.COPS_OP_REQ, _clientType);
\r
82 COPSContext cntxt = new COPSContext(COPSContext.CONFIG , (short) 0);
\r
84 COPSHandle handle = _handle;
\r
86 COPSReqMsg msg = new COPSReqMsg();
\r
92 Enumeration clientSIEnum = clientSIs.elements();
\r
93 while (clientSIEnum.hasMoreElements())
\r
94 msg.add( (COPSClientSI) clientSIEnum.nextElement());
\r
95 } catch (COPSException e) {
\r
96 throw new COPSPepException("Error making Request Msg, reason: " + e.getMessage());
\r
101 msg.writeData(_sock);
\r
102 } catch (IOException e) {
\r
103 throw new COPSPepException("Failed to send the request, reason: " + e.getMessage());
\r
108 * Sends a failure report to the PDP. This report message notifies the PDP
\r
109 * of failure when carrying out the PDP's decision, or when reporting
\r
110 * an accounting related state change.
\r
111 * @param clientSIs Report data
\r
112 * @throws COPSPepException
\r
114 public void sendFailReport(Vector clientSIs) throws COPSPepException {
\r
115 COPSReportMsg msg = new COPSReportMsg();
\r
118 COPSHeader hdr = new COPSHeader(COPSHeader.COPS_OP_RPT, _clientType);
\r
119 COPSHandle hnd = _handle;
\r
121 COPSReportType report = new COPSReportType(COPSReportType.FAILURE);
\r
127 Enumeration clientSIEnum = clientSIs.elements();
\r
128 while (clientSIEnum.hasMoreElements())
\r
129 msg.add( (COPSClientSI) clientSIEnum.nextElement());
\r
130 } catch (COPSException ex) {
\r
131 throw new COPSPepException("Error making Msg");
\r
135 msg.writeData(_sock);
\r
136 } catch (IOException e) {
\r
137 throw new COPSPepException("Failed to send the report, reason: " + e.getMessage());
\r
142 * Sends a success report to the PDP. This report message notifies the PDP
\r
143 * of success when carrying out the PDP's decision, or when reporting
\r
144 * an accounting related state change.
\r
145 * @param clientSIs Report data
\r
146 * @throws COPSPepException
\r
148 public void sendSuccessReport(Vector clientSIs) throws COPSPepException {
\r
149 COPSReportMsg msg = new COPSReportMsg();
\r
152 COPSHeader hdr = new COPSHeader(COPSHeader.COPS_OP_RPT, _clientType);
\r
153 COPSHandle hnd = _handle;
\r
155 COPSReportType report = new COPSReportType(COPSReportType.SUCCESS);
\r
161 Enumeration clientSIEnum = clientSIs.elements();
\r
162 while (clientSIEnum.hasMoreElements())
\r
163 msg.add( (COPSClientSI) clientSIEnum.nextElement());
\r
164 } catch (COPSException ex) {
\r
165 throw new COPSPepException("Error making Msg");
\r
169 msg.writeData(_sock);
\r
170 } catch (IOException e) {
\r
171 throw new COPSPepException("Failed to send the report, reason: " + e.getMessage());
\r
176 * Sends an accounting report to the PDP
\r
177 * @param clientSIs Report data
\r
178 * @throws COPSPepException
\r
180 public void sendAcctReport(Vector clientSIs) throws COPSPepException {
\r
181 COPSReportMsg msg = new COPSReportMsg();
\r
184 COPSHeader hdr = new COPSHeader(COPSHeader.COPS_OP_RPT, _clientType);
\r
185 COPSHandle hnd = _handle;
\r
187 COPSReportType report = new COPSReportType(COPSReportType.ACCT);
\r
193 Enumeration clientSIEnum = clientSIs.elements();
\r
194 while (clientSIEnum.hasMoreElements())
\r
195 msg.add( (COPSClientSI) clientSIEnum.nextElement());
\r
196 } catch (COPSException ex) {
\r
197 throw new COPSPepException("Error making Msg");
\r
201 msg.writeData(_sock);
\r
202 } catch (IOException e) {
\r
203 throw new COPSPepException("Failed to send the report, reason: " + e.getMessage());
\r
208 * Sends a sync-complete message to the PDP. This indicates the
\r
209 * end of a synchronization requested by the PDP.
\r
210 * @throws COPSPepException
\r
212 public void sendSyncComplete() throws COPSPepException {
\r
213 // Common Header with the same ClientType as the request
\r
214 COPSHeader hdr = new COPSHeader (COPSHeader.COPS_OP_SSC, _clientType);
\r
216 // Client Handle with the same clientHandle as the request
\r
217 COPSHandle clienthandle = _handle;
\r
219 COPSSyncStateMsg msg = new COPSSyncStateMsg();
\r
222 msg.add(clienthandle);
\r
223 } catch (Exception e) {
\r
224 throw new COPSPepException("Error making Msg");
\r
228 msg.writeData(_sock);
\r
229 } catch (IOException e) {
\r
230 throw new COPSPepException("Failed to send the sync state request, reason: " + e.getMessage());
\r
235 * Sends a delete request to the PDP.
\r
236 * When sent from the PEP this message indicates to the remote PDP that
\r
237 * the state identified by the client handle is no longer
\r
238 * available/relevant.
\r
239 * @throws COPSPepException
\r
241 public void sendDeleteRequest() throws COPSPepException {
\r
242 COPSHeader hdr = new COPSHeader(COPSHeader.COPS_OP_DRQ, _clientType);
\r
243 COPSHandle handle = _handle;
\r
245 // *** TODO: use real reason codes
\r
246 COPSReason reason = new COPSReason((short) 234, (short) 345);
\r
248 COPSDeleteMsg msg = new COPSDeleteMsg();
\r
253 msg.writeData(_sock);
\r
254 } catch (COPSException ex) {
\r
255 throw new COPSPepException("Error making Msg");
\r
256 } catch (IOException e) {
\r
257 throw new COPSPepException("Failed to send the delete request, reason: " + e.getMessage());
\r