1 package org.umu.cops.ospep;
\r
3 import java.net.Socket;
\r
4 import java.util.Vector;
\r
6 import org.umu.cops.stack.COPSData;
\r
7 import org.umu.cops.stack.COPSDecisionMsg;
\r
8 import org.umu.cops.stack.COPSError;
\r
9 import org.umu.cops.stack.COPSHandle;
\r
10 import org.umu.cops.stack.COPSSyncStateMsg;
\r
13 * State manager class for outsourcing requests, at the PEP side.
\r
15 public class COPSPepOSReqStateMan {
\r
17 * Request State created
\r
19 public final static short ST_CREATE = 1;
\r
23 public final static short ST_INIT = 2;
\r
25 * Decisions received
\r
27 public final static short ST_DECS = 3;
\r
31 public final static short ST_REPORT = 4;
\r
33 * Request State finalized
\r
35 public final static short ST_FINAL = 5;
\r
37 * New Request State solicited
\r
39 public final static short ST_NEW = 6;
\r
41 * Delete Request State solicited
\r
43 public final static short ST_DEL = 7;
\r
45 * SYNC request received
\r
47 public final static short ST_SYNC = 8;
\r
51 public final static short ST_SYNCALL = 9;
\r
53 * Close connection received
\r
55 public final static short ST_CCONN = 10;
\r
57 * Keep-alive timeout
\r
59 public final static short ST_NOKA = 11;
\r
61 * Accounting timeout
\r
63 public final static short ST_ACCT = 12;
\r
66 * COPS client-type that identifies the policy client
\r
68 protected short _clientType;
\r
71 * COPS client handle used to uniquely identify a particular
\r
72 * PEP's request for a client-type
\r
74 protected COPSHandle _handle;
\r
77 Object for performing policy data processing
\r
79 protected COPSPepOSDataProcess _process;
\r
82 * ClientSI data from signaling.
\r
84 protected Vector _clientSIs;
\r
87 * Current state of the request being managed
\r
89 protected short _status;
\r
92 COPS message transceiver used to send COPS messages
\r
94 protected COPSPepOSMsgSender _sender;
\r
99 protected boolean _syncState;
\r
102 * Creates a state request manager
\r
103 * @param clientType Client-type
\r
104 * @param clientHandle Client's <tt>COPSHandle</tt>
\r
106 public COPSPepOSReqStateMan(short clientType, String clientHandle) {
\r
108 _handle = new COPSHandle();
\r
109 COPSData id = new COPSData(clientHandle);
\r
112 _clientType = clientType;
\r
114 _status = ST_CREATE;
\r
119 * Gets the client handle
\r
120 * @return Client's <tt>COPSHandle</tt>
\r
122 public COPSHandle getClientHandle() {
\r
127 * Sets the client SI data.
\r
128 * @param someClientSIs Client SI data built by the event listener
\r
130 public void setClientSI(Vector someClientSIs) {
\r
131 _clientSIs = someClientSIs;
\r
135 * Gets the client-type
\r
136 * @return Client-type value
\r
138 public short getClientType() {
\r
139 return _clientType;
\r
143 * Gets the request status
\r
144 * @return Request status value
\r
146 public short getStatus() {
\r
151 * Gets the policy data processing object
\r
153 * @return Policy data processing object
\r
156 public COPSPepOSDataProcess getDataProcess() {
\r
161 * Sets the policy data processing object
\r
163 * @param process Policy data processing object
\r
166 public void setDataProcess(COPSPepOSDataProcess process) {
\r
167 _process = process;
\r
171 * Initializes a new request state over a socket
\r
172 * @param sock Socket to the PDP
\r
173 * @throws COPSPepException
\r
175 protected void initRequestState(Socket sock) throws COPSPepException {
\r
176 // Inits an object for sending COPS messages to the PDP
\r
177 _sender = new COPSPepOSMsgSender(_clientType, _handle, sock);
\r
179 // If an object exists for retrieving the PEP features,
\r
180 // use it for retrieving them.
\r
181 /* Hashtable clientSIs;
\r
182 if (_process != null)
\r
183 clientSIs = _process.getClientData(this);
\r
185 clientSIs = null;*/
\r
187 // Semd the request
\r
188 _sender.sendRequest(_clientSIs);
\r
195 * Deletes the request state
\r
196 * @throws COPSPepException
\r
198 protected void finalizeRequestState() throws COPSPepException {
\r
199 _sender.sendDeleteRequest();
\r
200 _status = ST_FINAL;
\r
204 * Processes the decision message
\r
205 * @param dMsg Decision message from the PDP
\r
206 * @throws COPSPepException
\r
208 protected void processDecision(COPSDecisionMsg dMsg) throws COPSPepException {
\r
209 // COPSDebug.out(getClass().getName(), "ClientId:" + getClientHandle().getId().str());
\r
211 //Hashtable decisionsPerContext = dMsg.getDecisions();
\r
213 //** Applies decisions to the configuration
\r
214 //_process.setDecisions(this, removeDecs, installDecs, errorDecs);
\r
215 // second param changed to dMsg so that the data processor
\r
216 // can check the 'solicited' flag
\r
217 boolean isFailReport = _process.setDecisions(this, dMsg /*decisionsPerContext*/);
\r
220 if (isFailReport) {
\r
221 // COPSDebug.out(getClass().getName(),"Sending FAIL Report\n");
\r
222 _sender.sendFailReport(_process.getReportData(this));
\r
224 // COPSDebug.out(getClass().getName(),"Sending SUCCESS Report\n");
\r
225 _sender.sendSuccessReport(_process.getReportData(this));
\r
227 _status = ST_REPORT;
\r
230 _sender.sendSyncComplete();
\r
232 _status = ST_SYNCALL;
\r
238 * Processes a COPS delete message
\r
239 * @param dMsg <tt>COPSDeleteMsg</tt> received from the PDP
\r
240 * @throws COPSPepException
\r
242 protected void processDeleteRequestState(COPSDecisionMsg dMsg) throws COPSPepException {
\r
243 if (_process != null)
\r
244 _process.closeRequestState(this);
\r
250 * Processes the message SycnStateRequest.
\r
251 * The message SycnStateRequest indicates that the remote PDP
\r
252 * wishes the client (which appears in the common header)
\r
253 * to re-send its state.
\r
255 * @param ssMsg The sync request from the PDP
\r
257 * @throws COPSPepException
\r
260 protected void processSyncStateRequest(COPSSyncStateMsg ssMsg) throws COPSPepException {
\r
261 _syncState = false;
\r
262 // If an object exists for retrieving the PEP features,
\r
263 // use it for retrieving them.
\r
265 // Send the request
\r
266 _sender.sendRequest(_clientSIs);
\r
272 * Called when connection is closed
\r
273 * @param error Reason
\r
274 * @throws COPSPepException
\r
276 protected void processClosedConnection(COPSError error) throws COPSPepException {
\r
277 if (_process != null)
\r
278 _process.notifyClosedConnection(this, error);
\r
280 _status = ST_CCONN;
\r
284 * Called when no keep-alive is received
\r
285 * @throws COPSPepException
\r
287 protected void processNoKAConnection() throws COPSPepException {
\r
288 if (_process != null)
\r
289 _process.notifyNoKAliveReceived(this);
\r
295 * Processes the accounting report
\r
296 * @throws COPSPepException
\r
298 protected void processAcctReport() throws COPSPepException {
\r
299 Vector report = new Vector();
\r
301 if (_process != null)
\r
302 report = _process.getAcctData(this);
\r
304 _sender.sendAcctReport(report);
\r