1 package org.umu.cops.ospep;
3 import org.umu.cops.stack.*;
4 import org.umu.cops.stack.COPSContext.RType;
5 import org.umu.cops.stack.COPSReason.ReasonCode;
6 import org.umu.cops.stack.COPSReportType.ReportType;
8 import java.io.IOException;
9 import java.net.Socket;
10 import java.util.List;
14 * COPS message transceiver class for outsourcing connections at the PEP side.
16 public class COPSPepOSMsgSender {
18 * Socket connection to PDP
20 protected Socket _sock;
23 * COPS client-type that identifies the policy client
25 protected short _clientType;
28 * COPS client handle used to uniquely identify a particular
29 * PEP's request for a client-type
31 protected COPSHandle _handle;
34 * Creates a COPSPepMsgSender
36 * @param clientType Client-type
37 * @param clientHandle Client handle
38 * @param sock Socket connected to the PDP
40 public COPSPepOSMsgSender (final short clientType, final COPSHandle clientHandle, final Socket sock) {
42 _handle = clientHandle;
43 _clientType = clientType;
49 * Gets the client handle
50 * @return Client's <tt>COPSHandle</tt>
52 public COPSHandle getClientHandle() {
57 * Gets the client-type
58 * @return Client-type value
60 public int getClientType() {
65 * Sends a request to the PDP.
66 * The PEP establishes a request state client handle for which the
67 * remote PDP may maintain state.
68 * @param clientSIs Client data
69 * @throws COPSPepException
71 public void sendRequest(final Set<COPSClientSI> clientSIs) throws COPSPepException {
72 // Create COPS Message
73 final COPSReqMsg msg = new COPSReqMsg(_clientType, _handle, new COPSContext(RType.CONFIG, (short)0), null,
74 null, null, clientSIs, null);
79 } catch (IOException e) {
80 throw new COPSPepException("Failed to send the request, reason: " + e.getMessage());
85 * Sends a failure report to the PDP. This report message notifies the PDP
86 * of failure when carrying out the PDP's decision, or when reporting
87 * an accounting related state change.
88 * @param clientSIs Report data
89 * @throws COPSPepException
91 public void sendFailReport(final List<COPSClientSI> clientSIs) throws COPSPepException {
92 sendReport(clientSIs, new COPSReportType(ReportType.FAILURE));
96 * Sends a success report to the PDP. This report message notifies the PDP
97 * of success when carrying out the PDP's decision, or when reporting
98 * an accounting related state change.
99 * @param clientSIs Report data
100 * @throws COPSPepException
102 public void sendSuccessReport(final List<COPSClientSI> clientSIs) throws COPSPepException {
103 sendReport(clientSIs, new COPSReportType(ReportType.SUCCESS));
107 * Sends an accounting report to the PDP
108 * @param clientSIs Report data
109 * @throws COPSPepException
111 public void sendAcctReport(final List<COPSClientSI> clientSIs) throws COPSPepException {
112 sendReport(clientSIs, new COPSReportType(ReportType.ACCOUNTING));
115 private void sendReport(final List<COPSClientSI> clientSIs, final COPSReportType type) throws COPSPepException {
116 // Change back to old way if it is ultimately determined that a report may contain more than one COPSClientSI
117 final COPSReportMsg msg = new COPSReportMsg(_clientType, _handle, type, null, null);
119 msg.writeData(_sock);
120 } catch (IOException e) {
121 throw new COPSPepException("Failed to send the report, reason: " + e.getMessage());
126 * Sends a sync-complete message to the PDP. This indicates the
127 * end of a synchronization requested by the PDP.
128 * @throws COPSPepException
130 public void sendSyncComplete() throws COPSPepException {
131 // Common Header with the same ClientType as the request
132 // Client Handle with the same clientHandle as the request
133 final COPSSyncStateMsg msg = new COPSSyncStateMsg(_clientType, _handle, null);
135 msg.writeData(_sock);
136 } catch (IOException e) {
137 throw new COPSPepException("Failed to send the sync state request, reason: " + e.getMessage());
142 * Sends a delete request to the PDP.
143 * When sent from the PEP this message indicates to the remote PDP that
144 * the state identified by the client handle is no longer
145 * available/relevant.
146 * @throws COPSPepException
148 public void sendDeleteRequest() throws COPSPepException {
149 // *** TODO: use real reason codes
150 COPSReason reason = new COPSReason(ReasonCode.UNSPECIFIED, ReasonCode.NA);
152 final COPSDeleteMsg msg = new COPSDeleteMsg(_clientType, _handle, reason, null);
154 msg.writeData(_sock);
155 } catch (IOException e) {
156 throw new COPSPepException("Failed to send the delete request, reason: " + e.getMessage());