1 package org.umu.cops.ospep;
3 import org.umu.cops.COPSMsgSender;
4 import org.umu.cops.stack.*;
5 import org.umu.cops.stack.COPSContext.RType;
6 import org.umu.cops.stack.COPSReason.ReasonCode;
7 import org.umu.cops.stack.COPSReportType.ReportType;
9 import java.io.IOException;
10 import java.net.Socket;
11 import java.util.List;
15 * COPS message transceiver class for outsourcing connections at the PEP side.
17 public class COPSPepOSMsgSender extends COPSMsgSender {
20 * Creates a COPSPepMsgSender
22 * @param clientType Client-type
23 * @param clientHandle Client handle
24 * @param sock Socket connected to the PDP
26 public COPSPepOSMsgSender(final short clientType, final COPSHandle clientHandle, final Socket sock) {
27 super(clientType, clientHandle, sock);
31 * Sends a request to the PDP.
32 * The PEP establishes a request state client handle for which the
33 * remote PDP may maintain state.
34 * @param clientSIs Client data
35 * @throws COPSPepException
37 public void sendRequest(final Set<COPSClientSI> clientSIs) throws COPSPepException {
38 // Create COPS Message
39 final COPSReqMsg msg = new COPSReqMsg(_clientType, _handle, new COPSContext(RType.CONFIG, (short)0), null,
40 null, null, clientSIs, null);
45 } catch (IOException e) {
46 throw new COPSPepException("Failed to send the request, reason: " + e.getMessage());
51 * Sends a failure report to the PDP. This report message notifies the PDP
52 * of failure when carrying out the PDP's decision, or when reporting
53 * an accounting related state change.
54 * @param clientSIs Report data
55 * @throws COPSPepException
57 public void sendFailReport(final List<COPSClientSI> clientSIs) throws COPSPepException {
58 sendReport(clientSIs, new COPSReportType(ReportType.FAILURE));
62 * Sends a success report to the PDP. This report message notifies the PDP
63 * of success when carrying out the PDP's decision, or when reporting
64 * an accounting related state change.
65 * @param clientSIs Report data
66 * @throws COPSPepException
68 public void sendSuccessReport(final List<COPSClientSI> clientSIs) throws COPSPepException {
69 sendReport(clientSIs, new COPSReportType(ReportType.SUCCESS));
73 * Sends an accounting report to the PDP
74 * @param clientSIs Report data
75 * @throws COPSPepException
77 public void sendAcctReport(final List<COPSClientSI> clientSIs) throws COPSPepException {
78 sendReport(clientSIs, new COPSReportType(ReportType.ACCOUNTING));
81 private void sendReport(final List<COPSClientSI> clientSIs, final COPSReportType type) throws COPSPepException {
82 // Change back to old way if it is ultimately determined that a report may contain more than one COPSClientSI
83 final COPSReportMsg msg = new COPSReportMsg(_clientType, _handle, type, null, null);
86 } catch (IOException e) {
87 throw new COPSPepException("Failed to send the report, reason: " + e.getMessage());
92 * Sends a sync-complete message to the PDP. This indicates the
93 * end of a synchronization requested by the PDP.
94 * @throws COPSPepException
96 public void sendSyncComplete() throws COPSPepException {
97 // Common Header with the same ClientType as the request
98 // Client Handle with the same clientHandle as the request
99 final COPSSyncStateMsg msg = new COPSSyncStateMsg(_clientType, _handle, null);
101 msg.writeData(_sock);
102 } catch (IOException e) {
103 throw new COPSPepException("Failed to send the sync state request, reason: " + e.getMessage());
108 * Sends a delete request to the PDP.
109 * When sent from the PEP this message indicates to the remote PDP that
110 * the state identified by the client handle is no longer
111 * available/relevant.
112 * @throws COPSPepException
114 public void sendDeleteRequest() throws COPSPepException {
115 // *** TODO: use real reason codes
116 COPSReason reason = new COPSReason(ReasonCode.UNSPECIFIED, ReasonCode.NA);
118 final COPSDeleteMsg msg = new COPSDeleteMsg(_clientType, _handle, reason, null);
120 msg.writeData(_sock);
121 } catch (IOException e) {
122 throw new COPSPepException("Failed to send the delete request, reason: " + e.getMessage());