1 package org.umu.cops.ospep;
3 import org.umu.cops.stack.*;
4 import org.umu.cops.stack.COPSHeader.ClientType;
6 import java.net.Socket;
9 import java.util.Vector;
12 * State manager class for outsourcing requests, at the PEP side.
14 public class COPSPepOSReqStateMan {
16 * Request State created
18 public final static short ST_CREATE = 1;
22 public final static short ST_INIT = 2;
26 public final static short ST_DECS = 3;
30 public final static short ST_REPORT = 4;
32 * Request State finalized
34 public final static short ST_FINAL = 5;
36 * New Request State solicited
38 public final static short ST_NEW = 6;
40 * Delete Request State solicited
42 public final static short ST_DEL = 7;
44 * SYNC request received
46 public final static short ST_SYNC = 8;
50 public final static short ST_SYNCALL = 9;
52 * Close connection received
54 public final static short ST_CCONN = 10;
58 public final static short ST_NOKA = 11;
62 public final static short ST_ACCT = 12;
65 * COPS client-type that identifies the policy client
67 protected ClientType _clientType;
70 * COPS client handle used to uniquely identify a particular
71 * PEP's request for a client-type
73 protected COPSHandle _handle;
76 Object for performing policy data processing
78 protected COPSPepOSDataProcess _process;
81 * ClientSI data from signaling.
83 protected final Set<COPSClientSI> _clientSIs;
86 * Current state of the request being managed
88 protected short _status;
91 COPS message transceiver used to send COPS messages
93 protected COPSPepOSMsgSender _sender;
98 protected boolean _syncState;
101 * Creates a state request manager
102 * @param clientType Client-type
103 * @param clientHandle Client's <tt>COPSHandle</tt>
105 public COPSPepOSReqStateMan(final ClientType clientType, final String clientHandle) {
107 _handle = new COPSHandle(new COPSData(clientHandle));
108 _clientType = clientType;
115 * Gets the client handle
116 * @return Client's <tt>COPSHandle</tt>
118 public COPSHandle getClientHandle() {
123 * Sets the client SI data.
124 * @param someClientSIs Client SI data built by the event listener
126 public void setClientSI(final List<COPSClientSI> someClientSIs) {
127 _clientSIs.addAll(someClientSIs);
131 * Gets the client-type
132 * @return Client-type value
134 public ClientType getClientType() {
139 * Gets the request status
140 * @return Request status value
142 public short getStatus() {
147 * Gets the policy data processing object
149 * @return Policy data processing object
152 public COPSPepOSDataProcess getDataProcess() {
157 * Sets the policy data processing object
159 * @param process Policy data processing object
162 public void setDataProcess(COPSPepOSDataProcess process) {
167 * Initializes a new request state over a socket
168 * @param sock Socket to the PDP
169 * @throws COPSPepException
171 protected void initRequestState(Socket sock) throws COPSPepException {
172 // Inits an object for sending COPS messages to the PDP
173 _sender = new COPSPepOSMsgSender(_clientType, _handle, sock);
175 // If an object exists for retrieving the PEP features,
176 // use it for retrieving them.
177 /* Hashtable clientSIs;
178 if (_process != null)
179 clientSIs = _process.getClientData(this);
184 _sender.sendRequest(_clientSIs);
191 * Deletes the request state
192 * @throws COPSPepException
194 protected void finalizeRequestState() throws COPSPepException {
195 _sender.sendDeleteRequest();
200 * Processes the decision message
201 * @param dMsg Decision message from the PDP
202 * @throws COPSPepException
204 protected void processDecision(COPSDecisionMsg dMsg) throws COPSPepException {
205 // COPSDebug.out(getClass().getName(), "ClientId:" + getClientHandle().getId().str());
207 //Hashtable decisionsPerContext = dMsg.getDecisions();
209 //** Applies decisions to the configuration
210 //_process.setDecisions(this, removeDecs, installDecs, errorDecs);
211 // second param changed to dMsg so that the data processor
212 // can check the 'solicited' flag
213 boolean isFailReport = _process.setDecisions(this, dMsg /*decisionsPerContext*/);
217 // COPSDebug.out(getClass().getName(),"Sending FAIL Report\n");
218 _sender.sendFailReport(_process.getReportData(this));
220 // COPSDebug.out(getClass().getName(),"Sending SUCCESS Report\n");
221 _sender.sendSuccessReport(_process.getReportData(this));
226 _sender.sendSyncComplete();
228 _status = ST_SYNCALL;
234 * Processes a COPS delete message
235 * @param dMsg <tt>COPSDeleteMsg</tt> received from the PDP
236 * @throws COPSPepException
238 protected void processDeleteRequestState(COPSDecisionMsg dMsg) throws COPSPepException {
239 if (_process != null)
240 _process.closeRequestState(this);
246 * Processes the message SycnStateRequest.
247 * The message SycnStateRequest indicates that the remote PDP
248 * wishes the client (which appears in the common header)
249 * to re-send its state.
251 * @param ssMsg The sync request from the PDP
253 * @throws COPSPepException
256 protected void processSyncStateRequest(COPSSyncStateMsg ssMsg) throws COPSPepException {
258 // If an object exists for retrieving the PEP features,
259 // use it for retrieving them.
262 _sender.sendRequest(_clientSIs);
268 * Called when connection is closed
269 * @param error Reason
270 * @throws COPSPepException
272 protected void processClosedConnection(COPSError error) throws COPSPepException {
273 if (_process != null)
274 _process.notifyClosedConnection(this, error);
280 * Called when no keep-alive is received
281 * @throws COPSPepException
283 protected void processNoKAConnection() throws COPSPepException {
284 if (_process != null)
285 _process.notifyNoKAliveReceived(this);
291 * Processes the accounting report
292 * @throws COPSPepException
294 protected void processAcctReport() throws COPSPepException {
295 Vector report = new Vector();
297 if (_process != null)
298 report = _process.getAcctData(this);
300 _sender.sendAcctReport(report);