1 package org.umu.cops.ospep;
\r
3 import org.umu.cops.stack.*;
\r
5 import java.net.Socket;
\r
6 import java.util.Vector;
\r
9 * State manager class for outsourcing requests, at the PEP side.
\r
11 public class COPSPepOSReqStateMan {
\r
13 * Request State created
\r
15 public final static short ST_CREATE = 1;
\r
19 public final static short ST_INIT = 2;
\r
21 * Decisions received
\r
23 public final static short ST_DECS = 3;
\r
27 public final static short ST_REPORT = 4;
\r
29 * Request State finalized
\r
31 public final static short ST_FINAL = 5;
\r
33 * New Request State solicited
\r
35 public final static short ST_NEW = 6;
\r
37 * Delete Request State solicited
\r
39 public final static short ST_DEL = 7;
\r
41 * SYNC request received
\r
43 public final static short ST_SYNC = 8;
\r
47 public final static short ST_SYNCALL = 9;
\r
49 * Close connection received
\r
51 public final static short ST_CCONN = 10;
\r
53 * Keep-alive timeout
\r
55 public final static short ST_NOKA = 11;
\r
57 * Accounting timeout
\r
59 public final static short ST_ACCT = 12;
\r
62 * COPS client-type that identifies the policy client
\r
64 protected short _clientType;
\r
67 * COPS client handle used to uniquely identify a particular
\r
68 * PEP's request for a client-type
\r
70 protected COPSHandle _handle;
\r
73 Object for performing policy data processing
\r
75 protected COPSPepOSDataProcess _process;
\r
78 * ClientSI data from signaling.
\r
80 protected Vector _clientSIs;
\r
83 * Current state of the request being managed
\r
85 protected short _status;
\r
88 COPS message transceiver used to send COPS messages
\r
90 protected COPSPepOSMsgSender _sender;
\r
95 protected boolean _syncState;
\r
98 * Creates a state request manager
\r
99 * @param clientType Client-type
\r
100 * @param clientHandle Client's <tt>COPSHandle</tt>
\r
102 public COPSPepOSReqStateMan(short clientType, String clientHandle) {
\r
104 _handle = new COPSHandle(new COPSData(clientHandle));
\r
105 _clientType = clientType;
\r
107 _status = ST_CREATE;
\r
112 * Gets the client handle
\r
113 * @return Client's <tt>COPSHandle</tt>
\r
115 public COPSHandle getClientHandle() {
\r
120 * Sets the client SI data.
\r
121 * @param someClientSIs Client SI data built by the event listener
\r
123 public void setClientSI(Vector someClientSIs) {
\r
124 _clientSIs = someClientSIs;
\r
128 * Gets the client-type
\r
129 * @return Client-type value
\r
131 public short getClientType() {
\r
132 return _clientType;
\r
136 * Gets the request status
\r
137 * @return Request status value
\r
139 public short getStatus() {
\r
144 * Gets the policy data processing object
\r
146 * @return Policy data processing object
\r
149 public COPSPepOSDataProcess getDataProcess() {
\r
154 * Sets the policy data processing object
\r
156 * @param process Policy data processing object
\r
159 public void setDataProcess(COPSPepOSDataProcess process) {
\r
160 _process = process;
\r
164 * Initializes a new request state over a socket
\r
165 * @param sock Socket to the PDP
\r
166 * @throws COPSPepException
\r
168 protected void initRequestState(Socket sock) throws COPSPepException {
\r
169 // Inits an object for sending COPS messages to the PDP
\r
170 _sender = new COPSPepOSMsgSender(_clientType, _handle, sock);
\r
172 // If an object exists for retrieving the PEP features,
\r
173 // use it for retrieving them.
\r
174 /* Hashtable clientSIs;
\r
175 if (_process != null)
\r
176 clientSIs = _process.getClientData(this);
\r
178 clientSIs = null;*/
\r
180 // Semd the request
\r
181 _sender.sendRequest(_clientSIs);
\r
188 * Deletes the request state
\r
189 * @throws COPSPepException
\r
191 protected void finalizeRequestState() throws COPSPepException {
\r
192 _sender.sendDeleteRequest();
\r
193 _status = ST_FINAL;
\r
197 * Processes the decision message
\r
198 * @param dMsg Decision message from the PDP
\r
199 * @throws COPSPepException
\r
201 protected void processDecision(COPSDecisionMsg dMsg) throws COPSPepException {
\r
202 // COPSDebug.out(getClass().getName(), "ClientId:" + getClientHandle().getId().str());
\r
204 //Hashtable decisionsPerContext = dMsg.getDecisions();
\r
206 //** Applies decisions to the configuration
\r
207 //_process.setDecisions(this, removeDecs, installDecs, errorDecs);
\r
208 // second param changed to dMsg so that the data processor
\r
209 // can check the 'solicited' flag
\r
210 boolean isFailReport = _process.setDecisions(this, dMsg /*decisionsPerContext*/);
\r
213 if (isFailReport) {
\r
214 // COPSDebug.out(getClass().getName(),"Sending FAIL Report\n");
\r
215 _sender.sendFailReport(_process.getReportData(this));
\r
217 // COPSDebug.out(getClass().getName(),"Sending SUCCESS Report\n");
\r
218 _sender.sendSuccessReport(_process.getReportData(this));
\r
220 _status = ST_REPORT;
\r
223 _sender.sendSyncComplete();
\r
225 _status = ST_SYNCALL;
\r
231 * Processes a COPS delete message
\r
232 * @param dMsg <tt>COPSDeleteMsg</tt> received from the PDP
\r
233 * @throws COPSPepException
\r
235 protected void processDeleteRequestState(COPSDecisionMsg dMsg) throws COPSPepException {
\r
236 if (_process != null)
\r
237 _process.closeRequestState(this);
\r
243 * Processes the message SycnStateRequest.
\r
244 * The message SycnStateRequest indicates that the remote PDP
\r
245 * wishes the client (which appears in the common header)
\r
246 * to re-send its state.
\r
248 * @param ssMsg The sync request from the PDP
\r
250 * @throws COPSPepException
\r
253 protected void processSyncStateRequest(COPSSyncStateMsg ssMsg) throws COPSPepException {
\r
254 _syncState = false;
\r
255 // If an object exists for retrieving the PEP features,
\r
256 // use it for retrieving them.
\r
258 // Send the request
\r
259 _sender.sendRequest(_clientSIs);
\r
265 * Called when connection is closed
\r
266 * @param error Reason
\r
267 * @throws COPSPepException
\r
269 protected void processClosedConnection(COPSError error) throws COPSPepException {
\r
270 if (_process != null)
\r
271 _process.notifyClosedConnection(this, error);
\r
273 _status = ST_CCONN;
\r
277 * Called when no keep-alive is received
\r
278 * @throws COPSPepException
\r
280 protected void processNoKAConnection() throws COPSPepException {
\r
281 if (_process != null)
\r
282 _process.notifyNoKAliveReceived(this);
\r
288 * Processes the accounting report
\r
289 * @throws COPSPepException
\r
291 protected void processAcctReport() throws COPSPepException {
\r
292 Vector report = new Vector();
\r
294 if (_process != null)
\r
295 report = _process.getAcctData(this);
\r
297 _sender.sendAcctReport(report);
\r