1 package org.umu.cops.ospep;
3 import org.slf4j.Logger;
4 import org.slf4j.LoggerFactory;
5 import org.umu.cops.prpep.COPSPepReqStateMan;
6 import org.umu.cops.stack.*;
8 import java.net.Socket;
12 * State manager class for outsourcing requests, at the PEP side.
14 public class COPSPepOSReqStateMan extends COPSPepReqStateMan {
16 private final static Logger logger = LoggerFactory.getLogger(COPSPepOSReqStateMan.class);
19 * ClientSI data from signaling.
21 protected final Set<COPSClientSI> _clientSIs;
24 Object for performing policy data processing
26 protected final COPSPepOSDataProcess _process;
29 COPS message transceiver used to send COPS messages
31 protected transient COPSPepOSMsgSender _sender;
36 protected transient boolean _syncState;
39 * Creates a state request manager
40 * @param clientType Client-type
41 * @param clientHandle Client's <tt>COPSHandle</tt>
43 public COPSPepOSReqStateMan(final short clientType, final COPSHandle clientHandle, final COPSPepOSDataProcess process,
44 final Collection<COPSClientSI> clientSIs) {
45 super(clientType, clientHandle, process);
46 this._process = process;
47 this._clientSIs = new HashSet<>(clientSIs);
52 protected void initRequestState(final Socket sock) throws COPSException {
53 // Inits an object for sending COPS messages to the PDP
54 _sender = new COPSPepOSMsgSender(_clientType, _handle, sock);
56 // If an object exists for retrieving the PEP features,
57 // use it for retrieving them.
58 /* Hashtable clientSIs;
60 clientSIs = _process.getClientData(this);
65 _sender.sendRequest(_clientSIs);
68 _status = Status.ST_INIT;
72 * Deletes the request state
73 * @throws COPSPepException
75 protected void finalizeRequestState() throws COPSException {
76 _sender.sendDeleteRequest();
77 _status = Status.ST_FINAL;
81 * Processes the decision message
82 * @param dMsg Decision message from the PDP
83 * @throws COPSPepException
85 protected void processDecision(final COPSDecisionMsg dMsg) throws COPSException {
86 //** Applies decisions to the configuration
87 //_process.setDecisions(this, removeDecs, installDecs, errorDecs);
88 // second param changed to dMsg so that the data processor
89 // can check the 'solicited' flag
90 final boolean isFailReport = _process.setDecisions(this, dMsg);
91 _status = Status.ST_DECS;
94 logger.info("Sending FAIL Report");
95 _sender.sendFailReport(_process.getReportData(this));
97 logger.info("Sending SUCCESS Report");
98 _sender.sendSuccessReport(_process.getReportData(this));
100 _status = Status.ST_REPORT;
103 _sender.sendSyncComplete();
105 _status = Status.ST_SYNCALL;
111 * Processes a COPS delete message
112 * @param dMsg <tt>COPSDeleteMsg</tt> received from the PDP
113 * @throws COPSPepException
115 protected void processDeleteRequestState(final COPSDecisionMsg dMsg) throws COPSPepException {
116 if (_process != null)
117 _process.closeRequestState(this);
119 _status = Status.ST_DEL;
123 * Processes the message SycnStateRequest.
124 * The message SycnStateRequest indicates that the remote PDP
125 * wishes the client (which appears in the common header)
126 * to re-send its state.
128 * @param ssMsg The sync request from the PDP
130 * @throws COPSPepException
133 protected void processSyncStateRequest(final COPSSyncStateMsg ssMsg) throws COPSException {
135 // If an object exists for retrieving the PEP features,
136 // use it for retrieving them.
139 _sender.sendRequest(_clientSIs);
141 _status = Status.ST_SYNC;
145 * Called when connection is closed
146 * @param error Reason
147 * @throws COPSPepException
149 protected void processClosedConnection(final COPSError error) throws COPSPepException {
150 if (_process != null)
151 _process.notifyClosedConnection(this, error);
153 _status = Status.ST_CCONN;
157 * Called when no keep-alive is received
158 * @throws COPSPepException
160 protected void processNoKAConnection() throws COPSPepException {
161 if (_process != null)
162 _process.notifyNoKAliveReceived(this);
164 _status = Status.ST_NOKA;
168 * Processes the accounting report
169 * @throws COPSPepException
171 protected void processAcctReport() throws COPSPepException {
172 final List<COPSClientSI> report;
173 if (_process != null) report = new ArrayList<>(_process.getAcctData(this));
174 else report = new ArrayList<>();
176 _sender.sendAcctReport(report);
178 _status = Status.ST_ACCT;