-package org.umu.cops.ospdp;\r
-\r
-import org.umu.cops.stack.*;\r
-\r
-import java.net.Socket;\r
-import java.util.Vector;\r
-\r
-/**\r
- * State manager class for outsourcing requests, at the PDP side.\r
- */\r
-public class COPSPdpOSReqStateMan {\r
- /**\r
- * Request State created\r
- */\r
- public final static short ST_CREATE = 1;\r
- /**\r
- * Request received\r
- */\r
- public final static short ST_INIT = 2;\r
- /**\r
- * Decisions sent\r
- */\r
- public final static short ST_DECS = 3;\r
- /**\r
- * Report received\r
- */\r
- public final static short ST_REPORT = 4;\r
- /**\r
- * Request state finalized\r
- */\r
- public final static short ST_FINAL = 5;\r
- /**\r
- * New request state solicited\r
- */\r
- public final static short ST_NEW = 6;\r
- /**\r
- * Delete request state solicited\r
- */\r
- public final static short ST_DEL = 7;\r
- /**\r
- * SYNC request sent\r
- */\r
- public final static short ST_SYNC = 8;\r
- /**\r
- * SYNC completed\r
- */\r
- public final static short ST_SYNCALL = 9;\r
- /**\r
- * Close connection received\r
- */\r
- public final static short ST_CCONN = 10;\r
- /**\r
- * Keep-alive timeout\r
- */\r
- public final static short ST_NOKA = 11;\r
- /**\r
- * Accounting timeout\r
- */\r
- public final static short ST_ACCT = 12;\r
-\r
- /**\r
- * COPS client-type that identifies the policy client\r
- */\r
- protected short _clientType;\r
-\r
- /**\r
- * COPS client handle used to uniquely identify a particular\r
- * PEP's request for a client-type\r
- */\r
- protected COPSHandle _handle;\r
-\r
- /**\r
- * Object for performing policy data processing\r
- */\r
- protected COPSPdpOSDataProcess _process;\r
-\r
- /**\r
- * Current state of the request being managed\r
- */\r
- protected short _status;\r
-\r
- /** COPS message transceiver used to send COPS messages */\r
- protected COPSPdpOSMsgSender _sender;\r
-\r
- /**\r
- * Creates a request state manager\r
- * @param clientType Client-type\r
- * @param clientHandle Client handle\r
- */\r
- public COPSPdpOSReqStateMan(short clientType, String clientHandle) {\r
- _handle = new COPSHandle(new COPSData(clientHandle));\r
- _clientType = clientType;\r
- _status = ST_CREATE;\r
- }\r
-\r
- /**\r
- * Gets the client handle\r
- * @return Client's <tt>COPSHandle</tt>\r
- */\r
- public COPSHandle getClientHandle() {\r
- return _handle;\r
- }\r
-\r
- /**\r
- * Gets the client-type\r
- * @return Client-type value\r
- */\r
- public short getClientType() {\r
- return _clientType;\r
- }\r
-\r
- /**\r
- * Gets the status of the request\r
- * @return Request state value\r
- */\r
- public short getStatus() {\r
- return _status;\r
- }\r
-\r
- /**\r
- * Gets the policy data processing object\r
- * @return Policy data processing object\r
- */\r
- public COPSPdpOSDataProcess getDataProcess() {\r
- return _process;\r
- }\r
-\r
- /**\r
- * Sets the policy data processing object\r
- * @param process Policy data processing object\r
- */\r
- public void setDataProcess(COPSPdpOSDataProcess process) {\r
- _process = process;\r
- }\r
-\r
- /**\r
- * Called when COPS sync is completed\r
- * @param repMsg COPS sync message\r
- * @throws COPSPdpException\r
- */\r
- protected void processSyncComplete(COPSSyncStateMsg repMsg)\r
- throws COPSPdpException {\r
-\r
- _status = ST_SYNCALL;\r
-\r
- // maybe we should notifySyncComplete ...\r
- }\r
-\r
- /**\r
- * Initializes a new request state over a socket\r
- * @param sock Socket to the PEP\r
- * @throws COPSPdpException\r
- */\r
- protected void initRequestState(Socket sock)\r
- throws COPSPdpException {\r
- // Inits an object for sending COPS messages to the PDP\r
- _sender = new COPSPdpOSMsgSender(_clientType, _handle, sock);\r
-\r
- // Initial state\r
- _status = ST_INIT;\r
- }\r
-\r
- /**\r
- * Processes a COPS request\r
- * @param msg COPS request received from the PEP\r
- * @throws COPSPdpException\r
- */\r
- protected void processRequest(COPSReqMsg msg) throws COPSPdpException {\r
- Vector clientSIs = msg.getClientSI();\r
-\r
- //** Here we must retrieve a decision depending on the\r
- //** supplied ClientSIs\r
- /*Vector removeDecs = new Vector();\r
- Vector installDecs = new Vector();*/\r
- _process.setClientData(this, clientSIs);\r
-\r
- Vector removeDecs = _process.getRemovePolicy(this);\r
- Vector installDecs = _process.getInstallPolicy(this);\r
-\r
- //** We create a SOLICITED decision\r
- //**\r
- _sender.sendSolicitedDecision(removeDecs, installDecs);\r
- _status = ST_DECS;\r
- }\r
-\r
- /**\r
- * Processes a report\r
- * @param msg Report message from the PEP\r
- * @throws COPSPdpException\r
- */\r
- protected void processReport(COPSReportMsg msg) throws COPSPdpException {\r
- //** Analyze the report\r
- //**\r
-\r
- /*\r
- * <Report State> ::= <Common Header>\r
- * <Client Handle>\r
- * <Report Type>\r
- * *(<Named ClientSI>)\r
- * [<Integrity>]\r
- * <Named ClientSI: Report> ::= <[<GPERR>] *(<report>)>\r
- * <report> ::= <ErrorPRID> <CPERR> *(<PRID><EPD>)\r
- *\r
- * Important, <Named ClientSI> is not parsed\r
- */\r
-\r
- // COPSHeader hdrmsg = msg.getHeader();\r
- // COPSHandle handlemsg = msg.getClientHandle();\r
-\r
- // Report Type\r
- COPSReportType rtypemsg = msg.getReport();\r
-\r
- // Named ClientSI\r
- Vector clientSIs = msg.getClientSI();\r
-\r
- //** We should act here in accordance with\r
- //** the received report\r
- if (rtypemsg.isSuccess()) {\r
- _status = ST_REPORT;\r
- _process.successReport(this, clientSIs);\r
- } else if (rtypemsg.isFailure()) {\r
- _status = ST_REPORT;\r
- _process.failReport(this, clientSIs);\r
- } else if (rtypemsg.isAccounting()) {\r
- _status = ST_ACCT;\r
- _process.acctReport(this, clientSIs);\r
- }\r
- }\r
-\r
- /**\r
- * Called when connection is closed\r
- * @param error Reason\r
- * @throws COPSPdpException\r
- */\r
- protected void processClosedConnection(COPSError error)\r
- throws COPSPdpException {\r
- if (_process != null)\r
- _process.notifyClosedConnection(this, error);\r
-\r
- _status = ST_CCONN;\r
- }\r
-\r
- /**\r
- * Called when no keep-alive is received\r
- * @throws COPSPdpException\r
- */\r
- protected void processNoKAConnection()\r
- throws COPSPdpException {\r
- if (_process != null)\r
- _process.notifyNoKAliveReceived(this);\r
-\r
- _status = ST_NOKA;\r
- }\r
-\r
- /**\r
- * Deletes the request state\r
- * @throws COPSPdpException\r
- */\r
- protected void finalizeRequestState()\r
- throws COPSPdpException {\r
- _sender.sendDeleteRequestState();\r
- _status = ST_FINAL;\r
- }\r
-\r
- /**\r
- * Asks for a COPS sync\r
- * @throws COPSPdpException\r
- */\r
- protected void syncRequestState()\r
- throws COPSPdpException {\r
- _sender.sendSyncRequestState();\r
- _status = ST_SYNC;\r
- }\r
-\r
- /**\r
- * Opens a new request state\r
- * @throws COPSPdpException\r
- */\r
- protected void openNewRequestState()//FIXME: unused?\r
- throws COPSPdpException {\r
- _sender.sendOpenNewRequestState();\r
- _status = ST_NEW;\r
- }\r
-\r
- /**\r
- * Processes a COPS delete message\r
- * @param dMsg <tt>COPSDeleteMsg</tt> received from the PEP\r
- * @throws COPSPdpException\r
- */\r
- protected void processDeleteRequestState(COPSDeleteMsg dMsg)\r
- throws COPSPdpException {\r
- if (_process != null)\r
- _process.closeRequestState(this);\r
-\r
- _status = ST_DEL;\r
- }\r
-\r
-}\r
+package org.umu.cops.ospdp;
+
+import org.umu.cops.stack.*;
+
+import java.net.Socket;
+import java.util.Vector;
+
+/**
+ * State manager class for outsourcing requests, at the PDP side.
+ */
+public class COPSPdpOSReqStateMan {
+ /**
+ * Request State created
+ */
+ public final static short ST_CREATE = 1;
+ /**
+ * Request received
+ */
+ public final static short ST_INIT = 2;
+ /**
+ * Decisions sent
+ */
+ public final static short ST_DECS = 3;
+ /**
+ * Report received
+ */
+ public final static short ST_REPORT = 4;
+ /**
+ * Request state finalized
+ */
+ public final static short ST_FINAL = 5;
+ /**
+ * New request state solicited
+ */
+ public final static short ST_NEW = 6;
+ /**
+ * Delete request state solicited
+ */
+ public final static short ST_DEL = 7;
+ /**
+ * SYNC request sent
+ */
+ public final static short ST_SYNC = 8;
+ /**
+ * SYNC completed
+ */
+ public final static short ST_SYNCALL = 9;
+ /**
+ * Close connection received
+ */
+ public final static short ST_CCONN = 10;
+ /**
+ * Keep-alive timeout
+ */
+ public final static short ST_NOKA = 11;
+ /**
+ * Accounting timeout
+ */
+ public final static short ST_ACCT = 12;
+
+ /**
+ * COPS client-type that identifies the policy client
+ */
+ protected short _clientType;
+
+ /**
+ * COPS client handle used to uniquely identify a particular
+ * PEP's request for a client-type
+ */
+ protected COPSHandle _handle;
+
+ /**
+ * Object for performing policy data processing
+ */
+ protected COPSPdpOSDataProcess _process;
+
+ /**
+ * Current state of the request being managed
+ */
+ protected short _status;
+
+ /** COPS message transceiver used to send COPS messages */
+ protected COPSPdpOSMsgSender _sender;
+
+ /**
+ * Creates a request state manager
+ * @param clientType Client-type
+ * @param clientHandle Client handle
+ */
+ public COPSPdpOSReqStateMan(short clientType, String clientHandle) {
+ _handle = new COPSHandle(new COPSData(clientHandle));
+ _clientType = clientType;
+ _status = ST_CREATE;
+ }
+
+ /**
+ * Gets the client handle
+ * @return Client's <tt>COPSHandle</tt>
+ */
+ public COPSHandle getClientHandle() {
+ return _handle;
+ }
+
+ /**
+ * Gets the client-type
+ * @return Client-type value
+ */
+ public short getClientType() {
+ return _clientType;
+ }
+
+ /**
+ * Gets the status of the request
+ * @return Request state value
+ */
+ public short getStatus() {
+ return _status;
+ }
+
+ /**
+ * Gets the policy data processing object
+ * @return Policy data processing object
+ */
+ public COPSPdpOSDataProcess getDataProcess() {
+ return _process;
+ }
+
+ /**
+ * Sets the policy data processing object
+ * @param process Policy data processing object
+ */
+ public void setDataProcess(COPSPdpOSDataProcess process) {
+ _process = process;
+ }
+
+ /**
+ * Called when COPS sync is completed
+ * @param repMsg COPS sync message
+ * @throws COPSPdpException
+ */
+ protected void processSyncComplete(COPSSyncStateMsg repMsg)
+ throws COPSPdpException {
+
+ _status = ST_SYNCALL;
+
+ // maybe we should notifySyncComplete ...
+ }
+
+ /**
+ * Initializes a new request state over a socket
+ * @param sock Socket to the PEP
+ * @throws COPSPdpException
+ */
+ protected void initRequestState(Socket sock)
+ throws COPSPdpException {
+ // Inits an object for sending COPS messages to the PDP
+ _sender = new COPSPdpOSMsgSender(_clientType, _handle, sock);
+
+ // Initial state
+ _status = ST_INIT;
+ }
+
+ /**
+ * Processes a COPS request
+ * @param msg COPS request received from the PEP
+ * @throws COPSPdpException
+ */
+ protected void processRequest(COPSReqMsg msg) throws COPSPdpException {
+ Vector clientSIs = msg.getClientSI();
+
+ //** Here we must retrieve a decision depending on the
+ //** supplied ClientSIs
+ /*Vector removeDecs = new Vector();
+ Vector installDecs = new Vector();*/
+ _process.setClientData(this, clientSIs);
+
+ Vector removeDecs = _process.getRemovePolicy(this);
+ Vector installDecs = _process.getInstallPolicy(this);
+
+ //** We create a SOLICITED decision
+ //**
+ _sender.sendSolicitedDecision(removeDecs, installDecs);
+ _status = ST_DECS;
+ }
+
+ /**
+ * Processes a report
+ * @param msg Report message from the PEP
+ * @throws COPSPdpException
+ */
+ protected void processReport(COPSReportMsg msg) throws COPSPdpException {
+ //** Analyze the report
+ //**
+
+ /*
+ * <Report State> ::= <Common Header>
+ * <Client Handle>
+ * <Report Type>
+ * *(<Named ClientSI>)
+ * [<Integrity>]
+ * <Named ClientSI: Report> ::= <[<GPERR>] *(<report>)>
+ * <report> ::= <ErrorPRID> <CPERR> *(<PRID><EPD>)
+ *
+ * Important, <Named ClientSI> is not parsed
+ */
+
+ // COPSHeader hdrmsg = msg.getHeader();
+ // COPSHandle handlemsg = msg.getClientHandle();
+
+ // Report Type
+ COPSReportType rtypemsg = msg.getReport();
+
+ // Named ClientSI
+ Vector clientSIs = msg.getClientSI();
+
+ //** We should act here in accordance with
+ //** the received report
+ switch (rtypemsg.getReportType()) {
+ case SUCCESS:
+ _status = ST_REPORT;
+ _process.successReport(this, clientSIs);
+ break;
+ case FAILURE:
+ _status = ST_REPORT;
+ _process.failReport(this, clientSIs);
+ break;
+ case ACCOUNTING:
+ _status = ST_ACCT;
+ _process.acctReport(this, clientSIs);
+ break;
+ }
+ }
+
+ /**
+ * Called when connection is closed
+ * @param error Reason
+ * @throws COPSPdpException
+ */
+ protected void processClosedConnection(COPSError error)
+ throws COPSPdpException {
+ if (_process != null)
+ _process.notifyClosedConnection(this, error);
+
+ _status = ST_CCONN;
+ }
+
+ /**
+ * Called when no keep-alive is received
+ * @throws COPSPdpException
+ */
+ protected void processNoKAConnection()
+ throws COPSPdpException {
+ if (_process != null)
+ _process.notifyNoKAliveReceived(this);
+
+ _status = ST_NOKA;
+ }
+
+ /**
+ * Deletes the request state
+ * @throws COPSPdpException
+ */
+ protected void finalizeRequestState()
+ throws COPSPdpException {
+ _sender.sendDeleteRequestState();
+ _status = ST_FINAL;
+ }
+
+ /**
+ * Asks for a COPS sync
+ * @throws COPSPdpException
+ */
+ protected void syncRequestState()
+ throws COPSPdpException {
+ _sender.sendSyncRequestState();
+ _status = ST_SYNC;
+ }
+
+ /**
+ * Opens a new request state
+ * @throws COPSPdpException
+ */
+ protected void openNewRequestState()//FIXME: unused?
+ throws COPSPdpException {
+ _sender.sendOpenNewRequestState();
+ _status = ST_NEW;
+ }
+
+ /**
+ * Processes a COPS delete message
+ * @param dMsg <tt>COPSDeleteMsg</tt> received from the PEP
+ * @throws COPSPdpException
+ */
+ protected void processDeleteRequestState(COPSDeleteMsg dMsg)
+ throws COPSPdpException {
+ if (_process != null)
+ _process.closeRequestState(this);
+
+ _status = ST_DEL;
+ }
+
+}