1 package org.umu.cops.ospdp;
3 import org.umu.cops.COPSStateMan;
4 import org.umu.cops.stack.*;
6 import java.net.Socket;
7 import java.util.Vector;
10 * State manager class for outsourcing requests, at the PDP side.
12 public class COPSPdpOSReqStateMan extends COPSStateMan {
15 * Object for performing policy data processing
17 private final COPSPdpOSDataProcess _process;
19 /** COPS message transceiver used to send COPS messages */
20 private transient COPSPdpOSMsgSender _sender;
23 * Creates a request state manager
24 * @param clientType Client-type
25 * @param clientHandle Client handle
27 // TODO - consider sending in the COPSHandle object instead
28 public COPSPdpOSReqStateMan(final short clientType, final COPSHandle clientHandle, final COPSPdpOSDataProcess process) {
29 super(clientType, clientHandle);
30 this._process = process;
34 protected void initRequestState(final Socket sock) throws COPSException {
35 // Inits an object for sending COPS messages to the PDP
36 _sender = new COPSPdpOSMsgSender(_clientType, _handle, sock);
39 _status = Status.ST_INIT;
43 * Processes a COPS request
44 * @param msg COPS request received from the PEP
45 * @throws COPSException
47 protected void processRequest(COPSReqMsg msg) throws COPSException {
48 //** Here we must retrieve a decision depending on the
49 //** supplied ClientSIs
50 /*Vector removeDecs = new Vector();
51 Vector installDecs = new Vector();*/
52 if (msg.getClientSI() != null)
53 _process.setClientData(this, msg.getClientSI().toArray(new COPSClientSI[msg.getClientSI().size()]));
55 Vector removeDecs = _process.getRemovePolicy(this);
56 Vector installDecs = _process.getInstallPolicy(this);
58 //** We create a SOLICITED decision
60 _sender.sendSolicitedDecision(removeDecs, installDecs);
61 _status = Status.ST_DECS;
66 * @param msg Report message from the PEP
67 * @throws COPSPdpException
69 protected void processReport(final COPSReportMsg msg) throws COPSPdpException {
70 //** Analyze the report
74 * <Report State> ::= <Common Header>
79 * <Named ClientSI: Report> ::= <[<GPERR>] *(<report>)>
80 * <report> ::= <ErrorPRID> <CPERR> *(<PRID><EPD>)
82 * Important, <Named ClientSI> is not parsed
85 // COPSHeader hdrmsg = msg.getHeader();
86 // COPSHandle handlemsg = msg.getClientHandle();
89 final COPSReportType rtypemsg = msg.getReport();
92 if (msg.getClientSI() != null) {
93 //** Here we must act in accordance with
94 //** the report received
95 switch (rtypemsg.getReportType()) {
97 _status = Status.ST_REPORT;
98 _process.successReport(this, msg.getClientSI());
101 _status = Status.ST_REPORT;
102 _process.failReport(this, msg.getClientSI());
105 _status = Status.ST_ACCT;
106 _process.acctReport(this, msg.getClientSI());
114 * Called when connection is closed
115 * @param error Reason
116 * @throws COPSPdpException
118 protected void processClosedConnection(final COPSError error) throws COPSPdpException {
119 if (_process != null)
120 _process.notifyClosedConnection(this, error);
122 _status = Status.ST_CCONN;
126 * Called when no keep-alive is received
127 * @throws COPSPdpException
129 protected void processNoKAConnection() throws COPSPdpException {
130 if (_process != null)
131 _process.notifyNoKAliveReceived(this);
133 _status = Status.ST_NOKA;
137 * Deletes the request state
138 * @throws COPSPdpException
140 protected void finalizeRequestState() throws COPSException {
141 _sender.sendDeleteRequestState();
142 _status = Status.ST_FINAL;
146 * Asks for a COPS sync
147 * @throws COPSPdpException
149 protected void syncRequestState() throws COPSException {
150 _sender.sendSyncRequestState();
151 _status = Status.ST_SYNC;
155 * Opens a new request state
156 * @throws COPSPdpException
158 protected void openNewRequestState() throws COPSException {
159 _sender.sendOpenNewRequestState();
160 _status = Status.ST_NEW;
164 * Processes a COPS delete message
165 * @param dMsg <tt>COPSDeleteMsg</tt> received from the PEP
166 * @throws COPSPdpException
168 protected void processDeleteRequestState(final COPSDeleteMsg dMsg) throws COPSPdpException {
169 if (_process != null)
170 _process.closeRequestState(this);
172 _status = Status.ST_DEL;