1 package org.umu.cops.ospdp;
\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.COPSDeleteMsg;
\r
8 import org.umu.cops.stack.COPSError;
\r
9 import org.umu.cops.stack.COPSHandle;
\r
10 import org.umu.cops.stack.COPSReportMsg;
\r
11 import org.umu.cops.stack.COPSReportType;
\r
12 import org.umu.cops.stack.COPSReqMsg;
\r
13 import org.umu.cops.stack.COPSSyncStateMsg;
\r
16 * State manager class for outsourcing requests, at the PDP side.
\r
18 public class COPSPdpOSReqStateMan {
\r
20 * Request State created
\r
22 public final static short ST_CREATE = 1;
\r
26 public final static short ST_INIT = 2;
\r
30 public final static short ST_DECS = 3;
\r
34 public final static short ST_REPORT = 4;
\r
36 * Request state finalized
\r
38 public final static short ST_FINAL = 5;
\r
40 * New request state solicited
\r
42 public final static short ST_NEW = 6;
\r
44 * Delete request state solicited
\r
46 public final static short ST_DEL = 7;
\r
50 public final static short ST_SYNC = 8;
\r
54 public final static short ST_SYNCALL = 9;
\r
56 * Close connection received
\r
58 public final static short ST_CCONN = 10;
\r
60 * Keep-alive timeout
\r
62 public final static short ST_NOKA = 11;
\r
64 * Accounting timeout
\r
66 public final static short ST_ACCT = 12;
\r
69 * COPS client-type that identifies the policy client
\r
71 protected short _clientType;
\r
74 * COPS client handle used to uniquely identify a particular
\r
75 * PEP's request for a client-type
\r
77 protected COPSHandle _handle;
\r
80 * Object for performing policy data processing
\r
82 protected COPSPdpOSDataProcess _process;
\r
85 * Current state of the request being managed
\r
87 protected short _status;
\r
89 /** COPS message transceiver used to send COPS messages */
\r
90 protected COPSPdpOSMsgSender _sender;
\r
93 * Creates a request state manager
\r
94 * @param clientType Client-type
\r
95 * @param clientHandle Client handle
\r
97 public COPSPdpOSReqStateMan(short clientType, String clientHandle) {
\r
99 _handle = new COPSHandle();
\r
100 COPSData id = new COPSData(clientHandle);
\r
103 _clientType = clientType;
\r
105 _status = ST_CREATE;
\r
109 * Gets the client handle
\r
110 * @return Client's <tt>COPSHandle</tt>
\r
112 public COPSHandle getClientHandle() {
\r
117 * Gets the client-type
\r
118 * @return Client-type value
\r
120 public short getClientType() {
\r
121 return _clientType;
\r
125 * Gets the status of the request
\r
126 * @return Request state value
\r
128 public short getStatus() {
\r
133 * Gets the policy data processing object
\r
134 * @return Policy data processing object
\r
136 public COPSPdpOSDataProcess getDataProcess() {
\r
141 * Sets the policy data processing object
\r
142 * @param process Policy data processing object
\r
144 public void setDataProcess(COPSPdpOSDataProcess process) {
\r
145 _process = process;
\r
149 * Called when COPS sync is completed
\r
150 * @param repMsg COPS sync message
\r
151 * @throws COPSPdpException
\r
153 protected void processSyncComplete(COPSSyncStateMsg repMsg)
\r
154 throws COPSPdpException {
\r
156 _status = ST_SYNCALL;
\r
158 // maybe we should notifySyncComplete ...
\r
162 * Initializes a new request state over a socket
\r
163 * @param sock Socket to the PEP
\r
164 * @throws COPSPdpException
\r
166 protected void initRequestState(Socket sock)
\r
167 throws COPSPdpException {
\r
168 // Inits an object for sending COPS messages to the PDP
\r
169 _sender = new COPSPdpOSMsgSender(_clientType, _handle, sock);
\r
176 * Processes a COPS request
\r
177 * @param msg COPS request received from the PEP
\r
178 * @throws COPSPdpException
\r
180 protected void processRequest(COPSReqMsg msg) throws COPSPdpException {
\r
181 Vector clientSIs = msg.getClientSI();
\r
183 //** Here we must retrieve a decision depending on the
\r
184 //** supplied ClientSIs
\r
185 /*Vector removeDecs = new Vector();
\r
186 Vector installDecs = new Vector();*/
\r
187 _process.setClientData(this, clientSIs);
\r
189 Vector removeDecs = _process.getRemovePolicy(this);
\r
190 Vector installDecs = _process.getInstallPolicy(this);
\r
192 //** We create a SOLICITED decision
\r
194 _sender.sendSolicitedDecision(removeDecs, installDecs);
\r
199 * Processes a report
\r
200 * @param msg Report message from the PEP
\r
201 * @throws COPSPdpException
\r
203 protected void processReport(COPSReportMsg msg) throws COPSPdpException {
\r
204 //** Analyze the report
\r
208 * <Report State> ::= <Common Header>
\r
211 * *(<Named ClientSI>)
\r
213 * <Named ClientSI: Report> ::= <[<GPERR>] *(<report>)>
\r
214 * <report> ::= <ErrorPRID> <CPERR> *(<PRID><EPD>)
\r
216 * Important, <Named ClientSI> is not parsed
\r
219 // COPSHeader hdrmsg = msg.getHeader();
\r
220 // COPSHandle handlemsg = msg.getClientHandle();
\r
223 COPSReportType rtypemsg = msg.getReport();
\r
226 Vector clientSIs = msg.getClientSI();
\r
228 //** We should act here in accordance with
\r
229 //** the received report
\r
230 if (rtypemsg.isSuccess()) {
\r
231 _status = ST_REPORT;
\r
232 _process.successReport(this, clientSIs);
\r
233 } else if (rtypemsg.isFailure()) {
\r
234 _status = ST_REPORT;
\r
235 _process.failReport(this, clientSIs);
\r
236 } else if (rtypemsg.isAccounting()) {
\r
238 _process.acctReport(this, clientSIs);
\r
243 * Called when connection is closed
\r
244 * @param error Reason
\r
245 * @throws COPSPdpException
\r
247 protected void processClosedConnection(COPSError error)
\r
248 throws COPSPdpException {
\r
249 if (_process != null)
\r
250 _process.notifyClosedConnection(this, error);
\r
252 _status = ST_CCONN;
\r
256 * Called when no keep-alive is received
\r
257 * @throws COPSPdpException
\r
259 protected void processNoKAConnection()
\r
260 throws COPSPdpException {
\r
261 if (_process != null)
\r
262 _process.notifyNoKAliveReceived(this);
\r
268 * Deletes the request state
\r
269 * @throws COPSPdpException
\r
271 protected void finalizeRequestState()
\r
272 throws COPSPdpException {
\r
273 _sender.sendDeleteRequestState();
\r
274 _status = ST_FINAL;
\r
278 * Asks for a COPS sync
\r
279 * @throws COPSPdpException
\r
281 protected void syncRequestState()
\r
282 throws COPSPdpException {
\r
283 _sender.sendSyncRequestState();
\r
288 * Opens a new request state
\r
289 * @throws COPSPdpException
\r
291 protected void openNewRequestState()//FIXME: unused?
\r
292 throws COPSPdpException {
\r
293 _sender.sendOpenNewRequestState();
\r
298 * Processes a COPS delete message
\r
299 * @param dMsg <tt>COPSDeleteMsg</tt> received from the PEP
\r
300 * @throws COPSPdpException
\r
302 protected void processDeleteRequestState(COPSDeleteMsg dMsg)
\r
303 throws COPSPdpException {
\r
304 if (_process != null)
\r
305 _process.closeRequestState(this);
\r