-/*\r
- * Copyright (c) 2004 University of Murcia. All rights reserved.\r
- * --------------------------------------------------------------\r
- * For more information, please see <http://www.umu.euro6ix.org/>.\r
- */\r
-\r
-package org.umu.cops.prpdp;\r
-\r
-import org.slf4j.Logger;\r
-import org.slf4j.LoggerFactory;\r
-import org.umu.cops.stack.*;\r
-\r
-import java.io.IOException;\r
-import java.net.Socket;\r
-import java.util.Date;\r
-import java.util.Map;\r
-import java.util.concurrent.ConcurrentHashMap;\r
-\r
-/**\r
- * Class for managing an provisioning connection at the PDP side.\r
- */\r
-public class COPSPdpConnection implements Runnable {\r
-\r
- public final static Logger logger = LoggerFactory.getLogger(COPSPdpConnection.class);\r
-\r
- /**\r
- Socket connected to PEP\r
- */\r
- private Socket _sock;\r
-\r
- /**\r
- PEP identifier\r
- */\r
- private COPSPepId _pepId;\r
-\r
- /**\r
- Time of the latest keep-alive sent\r
- */\r
- private Date _lastKa;\r
-\r
- /**\r
- Opcode of the latest message sent\r
- */\r
- private byte _lastmessage;\r
-\r
- /**\r
- * Time of the latest keep-alive received\r
- */\r
- protected Date _lastRecKa;\r
-\r
- /**\r
- Maps a Client Handle to a Handler\r
- */\r
- protected final Map<String, COPSPdpReqStateMan> _managerMap;\r
- // map < String(COPSHandle), COPSPdpHandler> HandlerMap;\r
-\r
- /**\r
- * PDP policy data processor class\r
- */\r
- protected COPSPdpDataProcess _process;\r
-\r
- /**\r
- Accounting timer value (secs)\r
- */\r
- protected short _acctTimer;\r
-\r
- /**\r
- Keep-alive timer value (secs)\r
- */\r
- protected short _kaTimer;\r
-\r
- /**\r
- COPS error returned by PEP\r
- */\r
- protected COPSError _error;\r
-\r
- /**\r
- * Creates a new PDP connection\r
- *\r
- * @param pepId PEP-ID of the connected PEP\r
- * @param sock Socket connected to PEP\r
- * @param process Object for processing policy data\r
- */\r
- public COPSPdpConnection(COPSPepId pepId, Socket sock, COPSPdpDataProcess process) {\r
- _sock = sock;\r
- _pepId = pepId;\r
-\r
- _lastKa = new Date();\r
- _lastmessage = COPSHeader.COPS_OP_OPN;\r
- _managerMap = new ConcurrentHashMap<>();\r
-\r
- _kaTimer = 0;\r
- _process = process;\r
- }\r
-\r
- /**\r
- * Gets the time of that latest keep-alive sent\r
- * @return Time of that latest keep-alive sent\r
- */\r
- public Date getLastKAlive() {\r
- return _lastKa;\r
- }\r
-\r
- /**\r
- * Sets the keep-alive timer value\r
- * @param kaTimer Keep-alive timer value (secs)\r
- */\r
- public void setKaTimer(short kaTimer) {\r
- _kaTimer = kaTimer;\r
- }\r
-\r
- /**\r
- * Gets the keep-alive timer value\r
- * @return Keep-alive timer value (secs)\r
- */\r
- public short getKaTimer() {\r
- return _kaTimer;\r
- }\r
-\r
- /**\r
- * Sets the accounting timer value\r
- * @param acctTimer Accounting timer value (secs)\r
- */\r
- public void setAccTimer(short acctTimer) {\r
- _acctTimer = acctTimer;\r
- }\r
-\r
- /**\r
- * Gets the accounting timer value\r
- * @return Accounting timer value (secs)\r
- */\r
- public short getAcctTimer() {\r
- return _acctTimer;\r
- }\r
-\r
- /**\r
- * Gets the latest COPS message\r
- * @return Code of the latest message sent\r
- */\r
- public byte getLastMessage() {\r
- return _lastmessage;\r
- }\r
-\r
- /**\r
- * Gets the PEP-ID\r
- * @return The ID of the PEP, as a <tt>String</tt>\r
- */\r
- public String getPepId() {\r
- return _pepId.getData().str();\r
- }\r
-\r
- /**\r
- * Checks whether the socket to the PEP is closed or not\r
- * @return <tt>true</tt> if closed, <tt>false</tt> otherwise\r
- */\r
- public boolean isClosed() {\r
- return _sock.isClosed();\r
- }\r
-\r
- /**\r
- * Closes the socket to the PEP\r
- * @throws IOException\r
- */\r
- protected void close()\r
- throws IOException {\r
- _sock.close();\r
- }\r
-\r
- /**\r
- * Gets the socket to the PEP\r
- * @return Socket connected to the PEP\r
- */\r
- public Socket getSocket() {\r
- return _sock;\r
- }\r
-\r
- /**\r
- * Main loop\r
- */\r
- public void run () {\r
- Date _lastSendKa = new Date();\r
- _lastRecKa = new Date();\r
- try {\r
- while (!_sock.isClosed()) {\r
- if (_sock.getInputStream().available() != 0) {\r
- _lastmessage = processMessage(_sock);\r
- _lastRecKa = new Date();\r
- }\r
-\r
- // Keep Alive\r
- if (_kaTimer > 0) {\r
- // Timeout at PDP\r
- int _startTime = (int) (_lastRecKa.getTime());\r
- int cTime = (int) (new Date().getTime());\r
-\r
- if ((cTime - _startTime) > _kaTimer * 1000) {\r
- _sock.close();\r
- // Notify all Request State Managers\r
- notifyNoKAAllReqStateMan();\r
- }\r
-\r
- // Send to PEP\r
- _startTime = (int) (_lastSendKa.getTime());\r
- cTime = (int) (new Date().getTime());\r
-\r
- if ((cTime - _startTime) > ((_kaTimer * 3/4) * 1000)) {\r
- COPSHeader hdr = new COPSHeader(COPSHeader.COPS_OP_KA);\r
- COPSKAMsg msg = new COPSKAMsg();\r
-\r
- msg.add(hdr);\r
-\r
- COPSTransceiver.sendMsg(msg, _sock);\r
- _lastSendKa = new Date();\r
- }\r
- }\r
-\r
- try {\r
- Thread.sleep(500);\r
- } catch (Exception e) {\r
- logger.error("Exception thrown while sleeping", e);\r
- }\r
-\r
- }\r
- } catch (Exception e) {\r
- logger.error("Error while processing socket messages", e);\r
- }\r
-\r
- // connection closed by server\r
- // COPSDebug.out(getClass().getName(),"Connection closed by client");\r
- try {\r
- _sock.close();\r
- } catch (IOException e) {\r
- logger.error("Error closing socket", e);\r
- }\r
-\r
- // Notify all Request State Managers\r
- try {\r
- notifyCloseAllReqStateMan();\r
- } catch (COPSPdpException e) {\r
- logger.error("Error closing state managers");\r
- }\r
- }\r
-\r
- /**\r
- * Gets a COPS message from the socket and processes it\r
- * @param conn Socket connected to the PEP\r
- * @return Type of COPS message\r
- */\r
- private byte processMessage(Socket conn)\r
- throws COPSPdpException, COPSException, IOException {\r
- COPSMsg msg = COPSTransceiver.receiveMsg(conn);\r
-\r
- if (msg.getHeader().isAClientClose()) {\r
- handleClientCloseMsg(conn, msg);\r
- return COPSHeader.COPS_OP_CC;\r
- } else if (msg.getHeader().isAKeepAlive()) {\r
- handleKeepAliveMsg(conn, msg);\r
- return COPSHeader.COPS_OP_KA;\r
- } else if (msg.getHeader().isARequest()) {\r
- handleRequestMsg(conn, msg);\r
- return COPSHeader.COPS_OP_REQ;\r
- } else if (msg.getHeader().isAReport()) {\r
- handleReportMsg(conn, msg);\r
- return COPSHeader.COPS_OP_RPT;\r
- } else if (msg.getHeader().isADeleteReq()) {\r
- handleDeleteRequestMsg(conn, msg);\r
- return COPSHeader.COPS_OP_DRQ;\r
- } else if (msg.getHeader().isASyncComplete()) {\r
- handleSyncComplete(conn, msg);\r
- return COPSHeader.COPS_OP_SSC;\r
- } else {\r
- throw new COPSPdpException("Message not expected (" + msg.getHeader().getOpCode() + ").");\r
- }\r
- }\r
-\r
- /**\r
- * Handle Client Close Message, close the passed connection\r
- *\r
- * @param conn a Socket\r
- * @param msg a COPSMsg\r
- *\r
- *\r
- * <Client-Close> ::= <Common Header>\r
- * <Error>\r
- * [<Integrity>]\r
- *\r
- * Not support [<Integrity>]\r
- *\r
- */\r
- private void handleClientCloseMsg(Socket conn, COPSMsg msg) {\r
- COPSClientCloseMsg cMsg = (COPSClientCloseMsg) msg;\r
- _error = cMsg.getError();\r
-\r
- // COPSDebug.out(getClass().getName(),"Got close request, closing connection " +\r
- // conn.getInetAddress() + ":" + conn.getPort() + ":[Error " + _error.getDescription() + "]");\r
-\r
- try {\r
- // Support\r
- if (cMsg.getIntegrity() != null) {\r
- logger.warn("Unsupported objects (Integrity) to connection " + conn.getInetAddress());\r
- }\r
-\r
- conn.close();\r
- } catch (Exception unae) {\r
- logger.error("Unexpected exception closing connection", unae);\r
- }\r
- }\r
-\r
- /**\r
- * Gets the occurred COPS Error\r
- * @return <tt>COPSError</tt> object\r
- */\r
- protected COPSError getError() {\r
- return _error;\r
- }\r
-\r
- /**\r
- * Handle Keep Alive Message\r
- *\r
- * <Keep-Alive> ::= <Common Header>\r
- * [<Integrity>]\r
- *\r
- * Not support [<Integrity>]\r
- *\r
- * @param conn a Socket\r
- * @param msg a COPSMsg\r
- *\r
- */\r
- private void handleKeepAliveMsg(Socket conn, COPSMsg msg) {\r
- COPSKAMsg cMsg = (COPSKAMsg) msg;\r
-\r
- COPSKAMsg kaMsg = (COPSKAMsg) msg;\r
- try {\r
- // Support\r
- if (cMsg.getIntegrity() != null) {\r
- logger.warn("Unsupported objects (Integrity) to connection " + conn.getInetAddress());\r
- }\r
- kaMsg.writeData(conn);\r
- } catch (Exception unae) {\r
- logger.error("Unexpected exception while writing COPS data", unae);\r
- }\r
- }\r
-\r
- /**\r
- * Handle Delete Request Message\r
- *\r
- * <Delete Request> ::= <Common Header>\r
- * <Client Handle>\r
- * <Reason>\r
- * [<Integrity>]\r
- *\r
- * Not support [<Integrity>]\r
- *\r
- * @param conn a Socket\r
- * @param msg a COPSMsg\r
- *\r
- */\r
- private void handleDeleteRequestMsg(Socket conn, COPSMsg msg)\r
- throws COPSPdpException {\r
- COPSDeleteMsg cMsg = (COPSDeleteMsg) msg;\r
- // COPSDebug.out(getClass().getName(),"Removing ClientHandle for " +\r
- // conn.getInetAddress() + ":" + conn.getPort() + ":[Reason " + cMsg.getReason().getDescription() + "]");\r
-\r
- // Support\r
- if (cMsg.getIntegrity() != null) {\r
- logger.warn("Unsupported objects (Integrity) to connection " + conn.getInetAddress());\r
- }\r
-\r
- // Delete clientHandler\r
- if (_managerMap.remove(cMsg.getClientHandle().getId().str()) == null) {\r
- // COPSDebug.out(getClass().getName(),"Missing for ClientHandle " +\r
- // cMsg.getClientHandle().getId().getData());\r
- }\r
-\r
- COPSPdpReqStateMan man = _managerMap.get(cMsg.getClientHandle().getId().str());\r
- if (man == null) {\r
- logger.warn("No state manager found with ID - " + cMsg.getClientHandle().getId().str());\r
- } else {\r
- man.processDeleteRequestState(cMsg);\r
- }\r
-\r
- }\r
-\r
- /**\r
- * Handle Request Message\r
- *\r
- * <Request> ::= <Common Header>\r
- * <Client Handle>\r
- * <Context>\r
- * *(<Named ClientSI>)\r
- * [<Integrity>]\r
- * <Named ClientSI> ::= <*(<PRID> <EPD>)>\r
- *\r
- * Not support [<Integrity>]\r
- *\r
- * @param conn a Socket\r
- * @param msg a COPSMsg\r
- *\r
- */\r
- private void handleRequestMsg(Socket conn, COPSMsg msg)\r
- throws COPSPdpException {\r
-\r
- COPSReqMsg reqMsg = (COPSReqMsg) msg;\r
- COPSContext cntxt = reqMsg.getContext();\r
- COPSHeader header = reqMsg.getHeader();\r
- //short reqType = cntxt.getRequestType();\r
- short cType = header.getClientType();\r
-\r
- // Support\r
- if (reqMsg.getIntegrity() != null) {\r
- logger.warn("Unsupported objects (Integrity) to connection " + conn.getInetAddress());\r
- }\r
-\r
- COPSPdpReqStateMan man;\r
- man = (COPSPdpReqStateMan) _managerMap.get(reqMsg.getClientHandle().getId().str());\r
- if (man == null) {\r
-\r
- man = new COPSPdpReqStateMan(cType, reqMsg.getClientHandle().getId().str());\r
- _managerMap.put(reqMsg.getClientHandle().getId().str(),man);\r
- man.setDataProcess(_process);\r
- man.initRequestState(_sock);\r
-\r
- // COPSDebug.out(getClass().getName(),"createHandler called, clientType=" +\r
- // header.getClientType() + " msgType=" +\r
- // cntxt.getMessageType() + ", connId=" + conn.toString());\r
- }\r
-\r
- man.processRequest(reqMsg);\r
- }\r
-\r
- /**\r
- * Handle Report Message\r
- *\r
- * <Report State> ::= <Common Header>\r
- * <Client Handle>\r
- * <Report Type>\r
- * *(<Named ClientSI>)\r
- * [<Integrity>]\r
- *\r
- * Not support [<Integrity>]\r
- *\r
- * @param conn a Socket\r
- * @param msg a COPSMsg\r
- *\r
- */\r
- private void handleReportMsg(Socket conn, COPSMsg msg)\r
- throws COPSPdpException {\r
- COPSReportMsg repMsg = (COPSReportMsg) msg;\r
- // COPSHandle handle = repMsg.getClientHandle();\r
- // COPSHeader header = repMsg.getHeader();\r
-\r
- // Support\r
- if (repMsg.getIntegrity() != null) {\r
- logger.warn("Unsupported objects (Integrity) to connection " + conn.getInetAddress());\r
- }\r
-\r
- COPSPdpReqStateMan man = (COPSPdpReqStateMan) _managerMap.get(repMsg.getClientHandle().getId().str());\r
- if (man == null) {\r
- logger.warn("No state manager found with ID - " + repMsg.getClientHandle().getId().str());\r
- } else {\r
- man.processReport(repMsg);\r
- }\r
- }\r
-\r
- /**\r
- * Method handleSyncComplete\r
- *\r
- * @param conn a Socket\r
- * @param msg a COPSMsg\r
- *\r
- */\r
- private void handleSyncComplete(Socket conn, COPSMsg msg)\r
- throws COPSPdpException {\r
- COPSSyncStateMsg cMsg = (COPSSyncStateMsg) msg;\r
- // COPSHandle handle = cMsg.getClientHandle();\r
- // COPSHeader header = cMsg.getHeader();\r
-\r
- // Support\r
- if (cMsg.getIntegrity() != null) {\r
- logger.warn("Unsupported objects (Integrity) to connection " + conn.getInetAddress());\r
- }\r
-\r
- COPSPdpReqStateMan man = (COPSPdpReqStateMan) _managerMap.get(cMsg.getClientHandle().getId().str());\r
- if (man == null) {\r
- logger.warn("No state manager found with ID - " + cMsg.getClientHandle().getId().str());\r
- } else {\r
- man.processSyncComplete(cMsg);\r
- }\r
- }\r
-\r
- /**\r
- * Requests a COPS sync from the PEP\r
- * @throws COPSException\r
- * @throws COPSPdpException\r
- */\r
- protected void syncAllRequestState() throws COPSException, COPSPdpException {\r
- for (final COPSPdpReqStateMan man : _managerMap.values()) {\r
- man.syncRequestState();\r
- }\r
- }\r
-\r
- private void notifyCloseAllReqStateMan() throws COPSPdpException {\r
- for (final COPSPdpReqStateMan man : _managerMap.values()) {\r
- man.processClosedConnection(_error);\r
- }\r
- }\r
-\r
- private void notifyNoKAAllReqStateMan() throws COPSPdpException {\r
- for (final COPSPdpReqStateMan man : _managerMap.values()) {\r
- man.processNoKAConnection();\r
- }\r
- }\r
-\r
-}\r
-\r
+/*
+ * Copyright (c) 2004 University of Murcia. All rights reserved.
+ * --------------------------------------------------------------
+ * For more information, please see <http://www.umu.euro6ix.org/>.
+ */
+
+package org.umu.cops.prpdp;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.umu.cops.COPSConnection;
+import org.umu.cops.stack.*;
+
+import javax.annotation.concurrent.ThreadSafe;
+import java.io.IOException;
+import java.net.Socket;
+import java.util.Date;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * Class for managing an provisioning connection at the PDP side.
+ */
+@ThreadSafe
+public class COPSPdpConnection extends COPSConnection {
+
+ public final static Logger logger = LoggerFactory.getLogger(COPSPdpConnection.class);
+
+ /**
+ * PEP identifier
+ * TODO FIXME - Why is this member never being used?
+ */
+ private final COPSPepId _pepId;
+
+ /**
+ * Time of the latest keep-alive sent
+ * TODO FIXME - Why is this member never being used?
+ */
+ private volatile Date _lastKa;
+
+ /**
+ * Maps a Client Handle to a Handler
+ */
+ protected final Map<COPSHandle, COPSPdpReqStateMan> _managerMap;
+
+ /**
+ * PDP policy data processor class
+ */
+ protected final COPSPdpDataProcess _process;
+
+ /**
+ * Creates a new PDP connection
+ *
+ * @param pepId PEP-ID of the connected PEP
+ * @param sock Socket connected to PEP
+ * @param process Object for processing policy data
+ */
+ public COPSPdpConnection(final COPSPepId pepId, Socket sock, final COPSPdpDataProcess process) {
+ this(pepId, sock, process, (short)0, (short)0);
+ }
+
+ /**
+ * Constructor for this or extended classes
+ * @param pepId - PEP-ID of the connected PEP
+ * @param sock - Socket connected to PEP
+ * @param process - Object for processing policy data
+ * @param kaTimer - the Keep-alive timer value
+ * @param acctTimer - the accounting timer value
+ */
+ protected COPSPdpConnection(final COPSPepId pepId, Socket sock, final COPSPdpDataProcess process,
+ final short kaTimer, final short acctTimer) {
+ super(sock, kaTimer, acctTimer);
+ _pepId = pepId;
+ _process = process;
+ _lastKa = new Date();
+ _managerMap = new ConcurrentHashMap<>();
+ }
+
+ public void addStateMan(final COPSHandle handle, final COPSPdpReqStateMan man) {
+ _managerMap.put(handle, man);
+ }
+
+ /**
+ * Main loop
+ */
+ public void run () {
+ Date lastSendKa = new Date();
+ Date lastRecKa = new Date();
+ while (!_sock.isClosed()) {
+ try {
+ if (_sock.getInputStream().available() != 0) {
+ processMessage(_sock);
+ lastRecKa = new Date();
+ }
+
+ // Keep Alive
+ if (_kaTimer > 0) {
+ // Timeout at PDP
+ int _startTime = (int) (lastRecKa.getTime());
+ int cTime = (int) (new Date().getTime());
+
+ if ((cTime - _startTime) > _kaTimer*1000) {
+ _sock.close();
+ // Notify all Request State Managers
+ notifyNoKAAllReqStateMan();
+ }
+
+ // Send to PEP
+ _startTime = (int) (lastSendKa.getTime());
+ cTime = (int) (new Date().getTime());
+
+ if ((cTime - _startTime) > ((_kaTimer*3/4)*1000)) {
+ // TODO - what should the real clientType be here???
+ final COPSKAMsg msg = new COPSKAMsg(null);
+ COPSTransceiver.sendMsg(msg, _sock);
+ lastSendKa = new Date();
+ }
+ }
+
+ try {
+ Thread.sleep(500);
+ } catch (InterruptedException e) {
+ logger.warn("Thread interrupted, shutting down", e);
+ break;
+ }
+ } catch (Exception e) {
+ logger.error("Error while processing socket messages, continue processing", e);
+ }
+ }
+
+ // connection closed by server
+ try {
+ logger.info("Closing socket");
+ _sock.close();
+ } catch (IOException e) {
+ logger.error("Error closing socket", e);
+ }
+
+ // Notify all Request State Managers
+ try {
+ logger.info("Notifying state managers that PDP connection is closing");
+ notifyCloseAllReqStateMan();
+ } catch (COPSException e) {
+ logger.error("Error closing state managers");
+ }
+ }
+
+ /**
+ * Gets a COPS message from the socket and processes it
+ * @param conn Socket connected to the PEP
+ */
+ private void processMessage(final Socket conn) throws COPSException, IOException {
+ final COPSMsg msg = COPSTransceiver.receiveMsg(conn);
+ switch (msg.getHeader().getOpCode()) {
+ case CC:
+ handleClientCloseMsg(conn, (COPSClientCloseMsg)msg);
+ break;
+ case KA:
+ handleKeepAliveMsg(conn, (COPSKAMsg)msg);
+ break;
+ case REQ:
+ handleRequestMsg(conn, (COPSReqMsg)msg);
+ break;
+ case RPT:
+ handleReportMsg(conn, (COPSReportMsg)msg);
+ break;
+ case DRQ:
+ handleDeleteRequestMsg(conn, (COPSDeleteMsg)msg);
+ break;
+ case SSC:
+ handleSyncComplete(conn, (COPSSyncStateMsg)msg);
+ break;
+ default:
+ throw new COPSPdpException("Message not expected (" + msg.getHeader().getOpCode() + ").");
+ }
+ }
+
+ /**
+ * Handle Keep Alive Message
+ * @param conn a Socket
+ * @param kaMsg a COPSKAMsg
+ */
+ private void handleKeepAliveMsg(final Socket conn, final COPSKAMsg kaMsg) {
+ try {
+ // Support
+ if (kaMsg.getIntegrity() != null) {
+ logger.warn("Unsupported objects (Integrity) to connection " + conn.getInetAddress());
+ }
+ kaMsg.writeData(conn);
+ _lastKa = new Date();
+ } catch (Exception unae) {
+ logger.error("Unexpected exception while writing COPS data", unae);
+ }
+ }
+
+ /**
+ * Handle Delete Request Message
+ * @param conn a Socket
+ * @param cMsg a COPSDeleteMsg
+ */
+ private void handleDeleteRequestMsg(final Socket conn, final COPSDeleteMsg cMsg) throws COPSException {
+ // Support
+ if (cMsg.getIntegrity() != null) {
+ logger.warn("Unsupported objects (Integrity) to connection " + conn.getInetAddress());
+ }
+
+ final COPSPdpReqStateMan man = _managerMap.remove(cMsg.getClientHandle());
+ if (man == null) {
+ logger.warn("No state manager found with ID - " + cMsg.getClientHandle().getId().str());
+ } else {
+ man.processDeleteRequestState(cMsg);
+ }
+ }
+
+ /**
+ * Handle Request Message
+ * @param conn a Socket
+ * @param reqMsg a COPSReqMsg
+ */
+ protected void handleRequestMsg(final Socket conn, final COPSReqMsg reqMsg) throws COPSException {
+ final COPSHeader header = reqMsg.getHeader();
+
+ // Support
+ if (reqMsg.getIntegrity() != null) {
+ logger.warn("Unsupported objects (Integrity) to connection " + conn.getInetAddress());
+ }
+
+ final COPSPdpReqStateMan man;
+ if (_managerMap.get(reqMsg.getClientHandle()) == null) {
+
+ man = createStateManager(reqMsg);
+ _managerMap.put(reqMsg.getClientHandle(), man);
+ man.initRequestState(_sock);
+
+ logger.info("createHandler called, clientType=" + header.getClientType() + " msgType=" + ", connId=" +
+ conn.toString());
+ } else {
+ man = _managerMap.get(reqMsg.getClientHandle());
+ }
+ man.processRequest(reqMsg);
+ }
+
+ /**
+ * Returns an instance of a COPSPdpReqStateMan
+ * @param reqMsg - the request on which to create the state manager
+ * @return - the state manager
+ */
+ protected COPSPdpReqStateMan createStateManager(final COPSReqMsg reqMsg) {
+ return new COPSPdpReqStateMan(reqMsg.getHeader().getClientType(), reqMsg.getClientHandle(), _process);
+ }
+
+ /**
+ * Handle Report Message
+ * @param conn a Socket
+ * @param repMsg a COPSReportMsg
+ */
+ private void handleReportMsg(final Socket conn, final COPSReportMsg repMsg) throws COPSException {
+ // Support
+ if (repMsg.getIntegrity() != null) {
+ logger.warn("Unsupported objects (Integrity) to connection " + conn.getInetAddress());
+ }
+
+ final COPSPdpReqStateMan man = _managerMap.get(repMsg.getClientHandle());
+ if (man == null) {
+ logger.warn("No state manager found with ID - " + repMsg.getClientHandle().getId().str());
+ } else {
+ man.processReport(repMsg);
+ }
+ }
+
+ /**
+ * Method handleSyncComplete
+ * @param conn a Socket
+ * @param cMsg a COPSSyncStateMsg
+ */
+ private void handleSyncComplete(final Socket conn, final COPSSyncStateMsg cMsg) throws COPSException {
+ // Support
+ if (cMsg.getIntegrity() != null) {
+ logger.warn("Unsupported objects (Integrity) to connection " + conn.getInetAddress());
+ }
+
+ final COPSPdpReqStateMan man = _managerMap.get(cMsg.getClientHandle());
+ if (man == null) {
+ logger.warn("No state manager found with ID - " + cMsg.getClientHandle().getId().str());
+ } else {
+ man.processSyncComplete(cMsg);
+ }
+ }
+
+ /**
+ * Requests a COPS sync from the PEP
+ * @throws COPSException
+ * @throws COPSPdpException
+ */
+ public void syncAllRequestState() throws COPSException {
+ for (final COPSPdpReqStateMan man : _managerMap.values()) {
+ man.syncRequestState();
+ }
+ }
+
+ private void notifyCloseAllReqStateMan() throws COPSException {
+ for (final COPSPdpReqStateMan man : _managerMap.values()) {
+ man.processClosedConnection(_error);
+ }
+ }
+
+ private void notifyNoKAAllReqStateMan() throws COPSException {
+ for (final COPSPdpReqStateMan man : _managerMap.values()) {
+ man.processNoKAConnection();
+ }
+ }
+
+}
+