Cleanup of state managers' interfaces (constructor and init). 56/20056/2
authorSteven Pisarski <s.pisarski@cablelabs.com>
Mon, 11 May 2015 21:34:13 +0000 (15:34 -0600)
committerSteve Pisarski <s.pisarski@cablelabs.com>
Wed, 13 May 2015 21:25:51 +0000 (21:25 +0000)
All state managers now will be constructed with a socket object and removed the socket from the initialization routine for PEP managers and removed the initialization routine completely from the PDP managers. Additionally, moved out the logic to process a gate request placed in earlier into COPSPepReqStateMan while testing the packetcable-policy-server. In lieu of removing the aformentioned logic, I also deactivated the PCMMServiceTest#testAddAndRemoveUpGate() test case which will be reactivated after CmtsPepReqStateMan is checked in with additional PCMMService tests.

Change-Id: I2b4c65efd35957f1d2d25aefa0270f95d1800559
Signed-off-by: Steven Pisarski <s.pisarski@cablelabs.com>
16 files changed:
packetcable-driver/src/main/java/org/pcmm/PCMMPdpAgent.java
packetcable-driver/src/main/java/org/pcmm/PCMMPdpConnection.java
packetcable-driver/src/main/java/org/pcmm/PCMMPdpMsgSender.java
packetcable-driver/src/main/java/org/pcmm/PCMMPdpReqStateMan.java
packetcable-driver/src/main/java/org/pcmm/rcd/impl/CMTS.java
packetcable-driver/src/main/java/org/umu/cops/COPSStateMan.java
packetcable-driver/src/main/java/org/umu/cops/ospdp/COPSPdpOSConnection.java
packetcable-driver/src/main/java/org/umu/cops/ospdp/COPSPdpOSReqStateMan.java
packetcable-driver/src/main/java/org/umu/cops/ospep/COPSPepOSConnection.java
packetcable-driver/src/main/java/org/umu/cops/ospep/COPSPepOSReqStateMan.java
packetcable-driver/src/main/java/org/umu/cops/prpdp/COPSPdpAgent.java
packetcable-driver/src/main/java/org/umu/cops/prpdp/COPSPdpConnection.java
packetcable-driver/src/main/java/org/umu/cops/prpdp/COPSPdpReqStateMan.java
packetcable-driver/src/main/java/org/umu/cops/prpep/COPSPepConnection.java
packetcable-driver/src/main/java/org/umu/cops/prpep/COPSPepReqStateMan.java
packetcable-policy-server/src/test/java/org/opendaylight/controller/packetcable/provider/PCMMServiceTest.java

index 1cbe6d244a8a39e6f9488075087bc2a08a635126..22486b7ff562a269a8b01caa78e6d85e6db51760 100644 (file)
@@ -8,7 +8,6 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.umu.cops.prpdp.COPSPdpAgent;
 import org.umu.cops.prpdp.COPSPdpConnection;
-import org.umu.cops.prpdp.COPSPdpException;
 import org.umu.cops.stack.COPSHandle;
 
 import java.net.Socket;
@@ -46,13 +45,8 @@ public class PCMMPdpAgent extends COPSPdpAgent {
     protected COPSPdpConnection setputPdpConnection(final Socket conn, final COPSHandle handle) {
         logger.debug("PDPCOPSConnection");
         final PCMMPdpConnection pdpConn = new PCMMPdpConnection(_pepId, conn, _thisProcess, _kaTimer, _acctTimer);
-        final PCMMPdpReqStateMan man = new PCMMPdpReqStateMan(_clientType, handle, _thisProcess);
+        final PCMMPdpReqStateMan man = new PCMMPdpReqStateMan(_clientType, handle, _thisProcess, conn);
         pdpConn.addStateMan(handle, man);
-        try {
-            man.initRequestState(conn);
-        } catch (COPSPdpException unae) {
-            logger.error("Unexpected error initializing state", unae);
-        }
         // XXX - End handleRequestMsg
 
         logger.info("Starting PDP connection thread to - " + _host);
index 5c50667c5c37cbe1b92d0e5ecb8e960ebde8451b..f9961c404bb938c7d8795e136de52c8514ec3918 100644 (file)
@@ -42,7 +42,8 @@ public class PCMMPdpConnection extends COPSPdpConnection {
      * @return - the state manager
      */
     protected COPSPdpReqStateMan createStateManager(final COPSReqMsg reqMsg) {
-        return new PCMMPdpReqStateMan(reqMsg.getHeader().getClientType(), reqMsg.getClientHandle(), _thisProcess);
+        return new PCMMPdpReqStateMan(reqMsg.getHeader().getClientType(), reqMsg.getClientHandle(), _thisProcess,
+                _sock);
     }
 
 }
index 6ed55206509efd316a63d8dae7ed4db66f48da46..da1be394e942e58a769efcfd80103bb30045b6c2 100644 (file)
@@ -65,13 +65,12 @@ public class PCMMPdpMsgSender extends COPSMsgSender {
      * @param sock
      *            Socket to the PEP
      */
-    public PCMMPdpMsgSender(final short clientType, final COPSHandle clientHandle, final Socket sock)
-            throws COPSPdpException {
+    public PCMMPdpMsgSender(final short clientType, final COPSHandle clientHandle, final Socket sock) {
         this(clientType, (short)0, clientHandle, sock);
     }
 
     public PCMMPdpMsgSender(final short clientType, final short tID, final COPSHandle clientHandle,
-                            final Socket sock) throws COPSPdpException {
+                            final Socket sock) {
         super(clientType, clientHandle, sock);
         _transactionID = tID;
         _classifierID = 0;
index 5e5f6300d9f86a0cdaa44778fe2166de1893b5d0..79470ff80f3bcbe0af86327a5eebecc4519a28e3 100644 (file)
@@ -7,6 +7,7 @@ package org.pcmm;
 import org.pcmm.gates.IGateID;
 import org.pcmm.gates.IPCMMGate;
 import org.pcmm.gates.ITransactionID;
+import org.pcmm.gates.impl.PCMMError;
 import org.pcmm.gates.impl.PCMMGateReq;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -33,7 +34,7 @@ public class PCMMPdpReqStateMan extends COPSPdpReqStateMan {
     protected final PCMMPdpDataProcess _thisProcess;
 
     /** COPS message transceiver used to send COPS messages */
-    protected transient PCMMPdpMsgSender _sender;
+    protected final PCMMPdpMsgSender _sender;
 
     /**
      * Creates a request state manager
@@ -41,35 +42,22 @@ public class PCMMPdpReqStateMan extends COPSPdpReqStateMan {
      * @param clientHandle  Client handle
      */
     // TODO - consider sending in the COPSHandle object instead
-    public PCMMPdpReqStateMan(final short clientType, final COPSHandle clientHandle, final PCMMPdpDataProcess process) {
-        super(clientType, clientHandle, process);
+    public PCMMPdpReqStateMan(final short clientType, final COPSHandle clientHandle, final PCMMPdpDataProcess process,
+                              final Socket socket) {
+        super(clientType, clientHandle, process, socket);
         this._thisProcess = process;
-    }
-
-    @Override
-    protected void initRequestState(final Socket sock) throws COPSPdpException {
-        // Inits an object for sending COPS messages to the PEP
-        _sender = new PCMMPdpMsgSender(_clientType, _handle, sock);
-
+        _sender = new PCMMPdpMsgSender(_clientType, _handle, _socket);
         // Initial state
         _status = Status.ST_INIT;
     }
 
-    /**
-     * Processes a COPS request
-     * @param msg   COPS request received from the PEP
-     * @throws COPSPdpException
-     */
+    @Override
     public void processRequest(final COPSReqMsg msg) throws COPSPdpException {
         // TODO - Implement me - see commented out code from history prior to May 4, 2015...
     }
 
-    /**
-     * Processes a report
-     * @param msg   Report message from the PEP
-     * @throws COPSPdpException
-     * TODO - break apart this method
-     */
+     // TODO - break apart this method
+    @Override
     protected void processReport(final COPSReportMsg msg) throws COPSPdpException {
         // Report Type
         final COPSReportType rtypemsg = msg.getReport();
@@ -146,9 +134,14 @@ public class PCMMPdpReqStateMan extends COPSPdpReqStateMan {
                 final IGateID gateID = gateMsg.getGateID();
                 logger.info("Setting gate ID on gate object - " + gateID);
                 gate.setGateID(gateID);
-                int gateIdInt = gateID.getGateID();
-                String gateIdHex = String.format("%08x", gateIdInt);
-                logger.info(getClass().getName() + ": " + cmdType + ": GateID = " + gateIdHex);
+
+                if (gateID != null) {
+                    int gateIdInt = gateID.getGateID();
+                    String gateIdHex = String.format("%08x", gateIdInt);
+                    logger.info(getClass().getName() + ": " + cmdType + ": GateID = " + gateIdHex);
+                } else {
+                    logger.warn("Gate ID is null");
+                }
             }
             if (rtypemsg.getReportType().equals(ReportType.FAILURE)) {
                 logger.info("rtypemsg failure");
@@ -156,7 +149,15 @@ public class PCMMPdpReqStateMan extends COPSPdpReqStateMan {
                 if (_thisProcess != null)
                     _thisProcess.failReport(this, gateMsg);
                 else
-                    logger.info("Gate message error - " + gateMsg.getError().toString());
+                    if (gateMsg.getError() != null)
+                        logger.info("Gate message error - " + gateMsg.getError().toString());
+                    else {
+                        final PCMMError error = new PCMMError();
+                        // TODO - figure out correct error code
+                        error.setErrorCode((short)19);
+                        gate.setError(error);
+                        logger.warn("Gate request failed without an error, setting one - " + error);
+                    }
             } else if (rtypemsg.getReportType().equals(ReportType.ACCOUNTING)) {
                     logger.info("rtypemsg account");
                     _status = Status.ST_ACCT;
index 09ae644047cf0700e7439d4ad25d0fba468998d7..4a89bad0e0733d9a740dc43778746299db1a80a8 100644 (file)
@@ -144,79 +144,6 @@ public class CMTS extends AbstractPCMMServer implements ICMTS {
                }
        }
 
-       class PCMMPSReqStateMan extends COPSPepReqStateMan {
-
-               public PCMMPSReqStateMan(final short clientType, final COPSHandle clientHandle) {
-                       super(clientType, clientHandle, new CmtsDataProcessor());
-               }
-
-               @Override
-               protected void processDecision(final COPSDecisionMsg dMsg, final Socket socket) throws COPSPepException {
-            final Map<String, String> removeDecs = new HashMap<>();
-                       final Map<String, String> installDecs = new HashMap<>();
-                       final Map<String, String> errorDecs = new HashMap<>();
-
-                       for (final Set<COPSDecision> copsDecisions : dMsg.getDecisions().values()) {
-                               final COPSDecision cmddecision = copsDecisions.iterator().next();
-
-                               // cmddecision --> we must check whether it is an error!
-                String prid = "";
-                switch (cmddecision.getCommand()) {
-                    case INSTALL:
-                        for (final COPSDecision decision : copsDecisions) {
-                                                       final COPSPrObjBase obj = new COPSPrObjBase(decision.getData().getData());
-                            switch (obj.getSNum()) {
-                                // TODO when there is install request only the PR_PRID
-                                // is git but the ClientSI object containing the PR_EPD
-                                // is null??? this is why the tests fail and so I set
-                                // the assertion to NOT true....
-                                case COPSPrObjBase.PR_PRID:
-                                    prid = obj.getData().str();
-                                    break;
-                                case COPSPrObjBase.PR_EPD:
-                                    installDecs.put(prid, obj.getData().str());
-                                    break;
-                                default:
-                                    break;
-                            }
-                        }
-                    case REMOVE:
-                        for (final COPSDecision decision : copsDecisions) {
-                                                       final COPSPrObjBase obj = new COPSPrObjBase(decision.getData().getData());
-                            switch (obj.getSNum()) {
-                                // TODO when there is install request only the PR_PRID
-                                // is git but the ClientSI object containing the PR_EPD
-                                // is null??? this is why the tests fail and so I set
-                                // the assertion to NOT true....
-                                case COPSPrObjBase.PR_PRID:
-                                    prid = obj.getData().str();
-                                    break;
-                                case COPSPrObjBase.PR_EPD:
-                                    removeDecs.put(prid, obj.getData().str());
-                                    break;
-                                default:
-                                    break;
-                            }
-                        }
-                }
-            }
-
-                       if (_process != null) {
-                               // ** Apply decisions to the configuration
-                               _process.setDecisions(this, removeDecs, installDecs, errorDecs);
-                               _status = Status.ST_DECS;
-                               if (_process.isFailReport(this)) {
-                                       // COPSDebug.out(getClass().getName(),"Sending FAIL Report\n");
-                                       _sender.sendFailReport(_process.getReportData(this));
-                               } else {
-                                       // COPSDebug.out(getClass().getName(),"Sending SUCCESS Report\n");
-                                       _sender.sendSuccessReport(_process.getReportData(this));
-                               }
-                               _status = Status.ST_REPORT;
-                       }
-               }
-       }
-
        class CmtsDataProcessor implements COPSPepDataProcess {
 
                private Map<String, String> removeDecs;
index 2b742f6c70f766e7543188fec033ed00e9215088..c6d6a252c08f6ffb07bcc44190ff91cc7b2c988e 100644 (file)
@@ -24,6 +24,11 @@ public abstract class COPSStateMan {
      */
     protected final COPSHandle _handle;
 
+    /**
+     * The socket connection. Value set when initRequestState is called
+     */
+    protected final Socket _socket;
+
     /**
      *  Current state of the request being managed
      */
@@ -34,9 +39,13 @@ public abstract class COPSStateMan {
      * @param clientType - the client type
      * @param clientHandle - the unique handle to the client
      */
-    public COPSStateMan(final short clientType, final COPSHandle clientHandle) {
+    protected COPSStateMan(final short clientType, final COPSHandle clientHandle, final Socket socket) {
+        if (clientHandle == null) throw new IllegalArgumentException("Client handle must not be null");
+        if (socket == null) throw new IllegalArgumentException("Socket connection must not be null");
+        if (!socket.isConnected()) throw new IllegalArgumentException("Socket connection must be connected");
         this._clientType = clientType;
         this._handle = clientHandle;
+        this._socket = socket;
         this._status = Status.ST_CREATE;
     }
 
@@ -74,13 +83,6 @@ public abstract class COPSStateMan {
         // TODO - maybe we should notifySyncComplete ...
     }
 
-    /**
-     * Initializes a new request state over a socket
-     * @param sock  Socket to the PEP
-     * @throws COPSPdpException
-     */
-    protected abstract void initRequestState(final Socket sock) throws COPSException;
-
     /**
      * The different state manager statuses
      */
index 73bb342d10759e270ed7360f52e6020f616a6055..236d0cdf61a34093dfb338588eae654d2a3bfff5 100644 (file)
@@ -33,7 +33,8 @@ public class COPSPdpOSConnection extends COPSPdpConnection {
 
     @Override
     protected COPSPdpReqStateMan createStateManager(final COPSReqMsg reqMsg) {
-        return new COPSPdpOSReqStateMan(reqMsg.getHeader().getClientType(), reqMsg.getClientHandle(), _thisProcess);
+        return new COPSPdpOSReqStateMan(reqMsg.getHeader().getClientType(), reqMsg.getClientHandle(), _thisProcess,
+                _sock);
     }
 
 }
index e28438e1b21ac783595103ef98472b8a1785eff6..ea70b050f3747f01a11070a6f17b9eccaa51318c 100644 (file)
@@ -17,7 +17,7 @@ public class COPSPdpOSReqStateMan extends COPSPdpReqStateMan {
     private final COPSPdpOSDataProcess _thisProcess;
 
     /** COPS message transceiver used to send COPS messages */
-    private transient COPSPdpOSMsgSender _sender;
+    private final COPSPdpOSMsgSender _sender;
 
     /**
      * Creates a request state manager
@@ -25,17 +25,11 @@ public class COPSPdpOSReqStateMan extends COPSPdpReqStateMan {
      * @param clientHandle  Client handle
      * @param process       The PDP OS Data Processor
      */
-    public COPSPdpOSReqStateMan(final short clientType, final COPSHandle clientHandle, final COPSPdpOSDataProcess process) {
-        super(clientType, clientHandle, process);
+    public COPSPdpOSReqStateMan(final short clientType, final COPSHandle clientHandle,
+                                final COPSPdpOSDataProcess process, final Socket socket) {
+        super(clientType, clientHandle, process, socket);
         this._thisProcess = process;
-    }
-
-    @Override
-    protected void initRequestState(final Socket sock) throws COPSException {
-        // Inits an object for sending COPS messages to the PDP
-        _sender = new COPSPdpOSMsgSender(_clientType, _handle, sock);
-
-        // Initial state
+        this._sender = new COPSPdpOSMsgSender(_clientType, _handle, _socket);
         _status = Status.ST_INIT;
     }
 
index 8a2eb863101ef559d21454e8811e1ec8cc21843d..ad10ccc87bf52e6024ecde27e0df276f0a48fcb5 100644 (file)
@@ -7,7 +7,7 @@ import org.umu.cops.stack.COPSException;
 import org.umu.cops.stack.COPSHandle;
 
 import java.net.Socket;
-import java.util.List;
+import java.util.Collection;
 
 /**
  * COPSPepConnection represents a PEP-PDP Connection Manager.
@@ -39,12 +39,12 @@ public class COPSPepOSConnection extends COPSPepConnection {
      * @throws COPSException
      */
     protected COPSPepOSReqStateMan addRequestState(final COPSHandle handle, final COPSPepOSDataProcess process,
-                                                   final List<COPSClientSI> clientSIs) throws COPSException {
-        final COPSPepOSReqStateMan manager = new COPSPepOSReqStateMan(_clientType, handle, process, clientSIs);
+                                                   final Collection<COPSClientSI> clientSIs) throws COPSException {
+        final COPSPepOSReqStateMan manager = new COPSPepOSReqStateMan(_clientType, handle, process, clientSIs, _sock);
         if (_managerMap.get(handle) != null)
             throw new COPSPepException("Duplicate Handle, rejecting " + handle.getId().str());
         _managerMap.put(handle, manager);
-        manager.initRequestState(_sock);
+        manager.initRequestState();
         return manager;
     }
 
index fe7c891197275b97ac4caaa3ad4390ea1281ab2e..a272d64e904a5b6b1700575a402013a5d3623d25 100644 (file)
@@ -15,11 +15,6 @@ public class COPSPepOSReqStateMan extends COPSPepReqStateMan {
 
     private final static Logger logger = LoggerFactory.getLogger(COPSPepOSReqStateMan.class);
 
-    /**
-     * ClientSI data from signaling.
-     */
-    protected final Set<COPSClientSI> _clientSIs;
-
     /**
         Object for performing policy data processing
      */
@@ -28,38 +23,45 @@ public class COPSPepOSReqStateMan extends COPSPepReqStateMan {
     /**
         COPS message transceiver used to send COPS messages
      */
-    protected transient COPSPepOSMsgSender _thisSender;
+    protected final COPSPepOSMsgSender _thisSender;
 
     /**
-     * Creates a state request manager
-     * @param    clientType Client-type
-     * @param   clientHandle    Client's <tt>COPSHandle</tt>
+     * ClientSI data populated when initRequestState() is called.
      */
-    public COPSPepOSReqStateMan(final short clientType, final COPSHandle clientHandle, final COPSPepOSDataProcess process,
-                                final Collection<COPSClientSI> clientSIs) {
-        super(clientType, clientHandle, process);
+    protected transient Set<COPSClientSI> _clientSIs;
+
+    /**
+     * Constructor
+     * @param clientType - the PEP client type
+     * @param clientHandle - the client-handle
+     * @param process - the data processor
+     * @param clientSIs - the known client SI objects
+     * @param socket - the socket connection
+     */
+    public COPSPepOSReqStateMan(final short clientType, final COPSHandle clientHandle,
+                                final COPSPepOSDataProcess process, final Collection<COPSClientSI> clientSIs,
+                                final Socket socket) {
+        super(clientType, clientHandle, process, socket, new COPSPepOSMsgSender(clientType, clientHandle, socket));
         this._thisProcess = process;
-        this._clientSIs = new HashSet<>(clientSIs);
-    }
+        if (clientSIs == null)
+            this._clientSIs = new HashSet<>();
+        else this._clientSIs = new HashSet<>(clientSIs);
 
-    @Override
-    protected void initRequestState(final Socket sock) throws COPSException {
         // Inits an object for sending COPS messages to the PDP
-        _thisSender = new COPSPepOSMsgSender(_clientType, _handle, sock);
-        _sender = _thisSender;
+        _thisSender = new COPSPepOSMsgSender(_clientType, _handle, _socket);
+    }
 
+    @Override
+    public void initRequestState() throws COPSException {
+        _clientSIs.addAll(_thisProcess.getClientData(this));
         // Send the request
-        _thisSender.sendRequest(_clientSIs);
+        _thisSender.sendRequest(new HashSet<>(_clientSIs));
 
         // Initial state
         _status = Status.ST_INIT;
     }
 
-    /**
-     * Processes the decision message
-     * @param    dMsg Decision message from the PDP
-     * @throws   COPSPepException
-     */
+    @Override
     protected void processDecision(final COPSDecisionMsg dMsg) throws COPSException {
         //** Applies decisions to the configuration
         //_thisProcess.setDecisions(this, removeDecs, installDecs, errorDecs);
@@ -78,7 +80,7 @@ public class COPSPepOSReqStateMan extends COPSPepReqStateMan {
         _status = Status.ST_REPORT;
 
         if (!_syncState) {
-            _sender.sendSyncComplete();
+            _thisSender.sendSyncComplete();
             _syncState = true;
             _status = Status.ST_SYNCALL;
         }
index 637d84d22e2ee31910c610d15689ae3c8266974b..c7c0ec7eec32a1849ef706bafe80a7f8849afd8b 100644 (file)
@@ -250,7 +250,6 @@ public class COPSPdpAgent {
      * @param conn - the socket connection
      * @param errorType - the error type to send
      * @param msg - the error message to log
-     * @throws COPSException
      */
     private void sendCloseMessage(final Socket conn, final ErrorTypes errorType, final ErrorTypes errorSubType,
                                   final String msg) {
@@ -323,13 +322,8 @@ public class COPSPdpAgent {
 
         // XXX - handleRequestMsg
         // XXX - check handle is valid
-        final COPSPdpReqStateMan man = new COPSPdpReqStateMan(_clientType, handle, _process);
+        final COPSPdpReqStateMan man = new COPSPdpReqStateMan(_clientType, handle, _process, conn);
         pdpConn.addStateMan(handle, man);
-        try {
-            man.initRequestState(conn);
-        } catch (COPSException unae) {
-            logger.error("Unexpected error initializing state", unae);
-        }
         // XXX - End handleRequestMsg
 
         logger.info("Starting PDP connection thread to - " + _host);
index 2248a9e416ba939111b0fc9fa1c359aadceb73f6..fec4fd2f7d2db4b646234799649f914d1c152aae 100644 (file)
@@ -230,7 +230,6 @@ public class COPSPdpConnection extends COPSConnection {
 
             man = createStateManager(reqMsg);
             _managerMap.put(reqMsg.getClientHandle(), man);
-            man.initRequestState(_sock);
 
             logger.info("createHandler called, clientType=" + header.getClientType() + " msgType=" + ", connId=" +
                     conn.toString());
@@ -246,7 +245,7 @@ public class COPSPdpConnection extends COPSConnection {
      * @return - the state manager
      */
     protected COPSPdpReqStateMan createStateManager(final COPSReqMsg reqMsg) {
-        return new COPSPdpReqStateMan(reqMsg.getHeader().getClientType(), reqMsg.getClientHandle(), _process);
+        return new COPSPdpReqStateMan(reqMsg.getHeader().getClientType(), reqMsg.getClientHandle(), _process, _sock);
     }
 
     /**
index 49a24fce8e86c960bf1aafe3d8cb6df3b886fa9f..72fdccc491e8245b31e867c12750da1993066d26 100644 (file)
@@ -35,17 +35,11 @@ public class COPSPdpReqStateMan extends COPSStateMan {
      * @param clientType    Client-type
      * @param clientHandle  Client handle
      */
-    public COPSPdpReqStateMan(final short clientType, final COPSHandle clientHandle, final COPSPdpDataProcess process) {
-        super(clientType, clientHandle);
+    public COPSPdpReqStateMan(final short clientType, final COPSHandle clientHandle, final COPSPdpDataProcess process,
+                              final Socket socket) {
+        super(clientType, clientHandle, socket);
         this._process = process;
-    }
-
-    @Override
-    protected void initRequestState(final Socket sock) throws COPSException {
-        // Inits an object for sending COPS messages to the PEP
-        _sender = new COPSPdpMsgSender(_clientType, _handle, sock);
-
-        // Initial state
+        _sender = new COPSPdpMsgSender(_clientType, _handle, _socket);
         _status = Status.ST_INIT;
     }
 
index 341857529aa3c4aeb035a5ea76a730834bebe66d..66455eb27b025a60b7a2c177230a5ddc4c9fb36a 100644 (file)
@@ -202,7 +202,7 @@ public class COPSPepConnection extends COPSConnection {
                         handleOpenNewRequestStateMsg(handle);
                 } else
                     // Decision
-                    manager.processDecision(dMsg, _sock);
+                    manager.processDecision(dMsg);
             }
         }
     }
@@ -246,13 +246,13 @@ public class COPSPepConnection extends COPSConnection {
      */
     public COPSPepReqStateMan addRequestState(final COPSHandle clientHandle, final COPSPepDataProcess process)
             throws COPSException {
-        final COPSPepReqStateMan manager = new COPSPepReqStateMan(_clientType, clientHandle, process);
+        final COPSPepReqStateMan manager = new COPSPepReqStateMan(_clientType, clientHandle, process, _sock);
         if (_managerMap.get(clientHandle) != null)
             throw new COPSPepException("Duplicate Handle, rejecting " + clientHandle);
 
         _managerMap.put(clientHandle, manager);
         logger.info("Added state manager with key - " + clientHandle);
-        manager.initRequestState(_sock);
+        manager.initRequestState();
         return manager;
     }
 
index 6cbe8a1063e740087ed226b6610475f897411c7f..532b573de3c81bf891adccd90ba84917de795113 100644 (file)
@@ -6,20 +6,15 @@
 
 package org.umu.cops.prpep;
 
-import org.pcmm.gates.impl.GateID;
-import org.pcmm.gates.impl.PCMMGateReq;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.umu.cops.COPSStateMan;
 import org.umu.cops.stack.*;
-import org.umu.cops.stack.COPSDecision.DecisionFlag;
-import org.umu.cops.stack.COPSObjHeader.CNum;
-import org.umu.cops.stack.COPSObjHeader.CType;
-import org.umu.cops.stack.COPSReportType.ReportType;
 
-import java.io.IOException;
 import java.net.Socket;
-import java.util.*;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
 
 /**
  * COPSPepReqStateMan manages Request State using Client Handle (RFC 2748 pag. 21)
@@ -55,7 +50,7 @@ public class COPSPepReqStateMan extends COPSStateMan {
     /**
         The Msg Sender is used to send COPS messages
      */
-    protected transient COPSPepMsgSender _sender;
+    private final COPSPepMsgSender _sender;
 
     /**
      * Sync State
@@ -63,27 +58,40 @@ public class COPSPepReqStateMan extends COPSStateMan {
     protected transient boolean _syncState;
 
     /**
-     * Create a State Request Manager
-     *
-     * @param    clientHandle                a Client Handle
-     *
+     * Constructor for this class
+     * @param clientType - the PEP client type
+     * @param clientHandle - the client-handle
+     * @param process - the data processor
+     * @param socket - the socket connection
      */
-    public COPSPepReqStateMan(final short clientType, final COPSHandle clientHandle, final COPSPepDataProcess process) {
-        super(clientType, clientHandle);
+    public COPSPepReqStateMan(final short clientType, final COPSHandle clientHandle, final COPSPepDataProcess process,
+                              final Socket socket) {
+        this(clientType, clientHandle, process, socket, new COPSPepMsgSender(clientType, clientHandle, socket));
+    }
+
+    /**
+     * Constructor for sub-classes
+     * @param clientType - the PEP client type
+     * @param clientHandle - the client-handle
+     * @param process - the data processor
+     * @param socket - the socket connection
+     * @param sender - responsible for sending COPS messages to the PEP
+     */
+    protected COPSPepReqStateMan(final short clientType, final COPSHandle clientHandle, final COPSPepDataProcess process,
+                                 final Socket socket, final COPSPepMsgSender sender) {
+
+        super(clientType, clientHandle, socket);
         this._process = process;
         _syncState = true;
+        // Inits an object for sending COPS messages to the PDP
+        _sender = sender;
     }
 
     /**
      * Init Request State
-     *
      * @throws   COPSPepException
-     *
      */
-    protected void initRequestState(final Socket sock) throws COPSException {
-        // Inits an object for sending COPS messages to the PDP
-        _sender = new COPSPepMsgSender(_clientType, _handle, sock);
-
+    public void initRequestState() throws COPSException {
         // If an object for retrieving PEP features exists,
         // use it for retrieving them
         final Map<String, String> clientSIs;
@@ -113,13 +121,10 @@ public class COPSPepReqStateMan extends COPSStateMan {
 
     /**
      * Process the message Decision
-     *
      * @param    dMsg                a  COPSDecisionMsg
-     *
      * @throws   COPSPepException
-     *
      */
-    protected void processDecision(final COPSDecisionMsg dMsg, final Socket socket) throws COPSException {
+    protected void processDecision(final COPSDecisionMsg dMsg) throws COPSException {
         logger.info("Processing decision message - " + dMsg);
         final Map<COPSContext, Set<COPSDecision>> decisions = dMsg.getDecisions();
 
@@ -131,68 +136,17 @@ public class COPSPepReqStateMan extends COPSStateMan {
             String prid = "";
             switch (cmddecision.getCommand()) {
                 case INSTALL:
-                    // TODO - break up this block
                     for (final COPSDecision decision : copsDecisions) {
-                        if (decision.getData().getData().length != 0) {
-                            final COPSPrObjBase obj = new COPSPrObjBase(decision.getData().getData());
-                            switch (obj.getSNum()) {
-                                case COPSPrObjBase.PR_PRID:
-                                    prid = obj.getData().str();
-                                    break;
-                                case COPSPrObjBase.PR_EPD:
-                                    installDecs.put(prid, obj.getData().str());
-                                    break;
-                            }
-                        }
-                        if (decision.getFlag().equals(DecisionFlag.REQERROR)) {
-                            // This is assuming a gate set right or wrong
-                            if (dMsg.getDecisions().size() == 1 && dMsg.getDecSI() != null) {
-                                final PCMMGateReq gateReq = new PCMMGateReq(dMsg.getDecSI().getData().getData());
-                                // TODO - Check and/or Set state here
-                                // Gate ADD gateReq.getTrafficProfile() != null
-                                // Gate REMOVE gateReq.getTrafficProfile() == null
-//                                    final String gateName = trafficProfile.getData().str();
-//                                    final Direction gateDir = gateReq.getGateSpec().getDirection();
-                                final boolean success = true;
-
-                                // Set response
-                                final List<Byte> data = new ArrayList<>();
-                                for (final byte val : gateReq.getTransactionID().getAsBinaryArray())
-                                    data.add(val);
-                                for (final byte val : gateReq.getAMID().getAsBinaryArray())
-                                    data.add(val);
-                                for (final byte val : gateReq.getSubscriberID().getAsBinaryArray())
-                                    data.add(val);
-
-                                // Assign a gate ID
-                                final GateID gateID = new GateID();
-                                gateID.setGateID(UUID.randomUUID().hashCode());
-                                for (final byte val : gateID.getAsBinaryArray())
-                                    data.add(val);
-
-
-                                final byte[] csiArr = new byte[data.size()];
-                                for (int i = 0; i < data.size(); i++) {
-                                    csiArr[i] = data.get(i);
-                                }
-                                final COPSClientSI si = new COPSClientSI(CNum.CSI, CType.DEF, new COPSData(csiArr, 0, csiArr.length));
-
-                                final COPSReportMsg reportMsg;
-                                // TODO FIXME - success is always true
-                                if (success) {
-                                    reportMsg = new COPSReportMsg(_clientType, getClientHandle(),
-                                            new COPSReportType(ReportType.SUCCESS), si, null);
-                                } else {
-                                    reportMsg = new COPSReportMsg(_clientType, getClientHandle(),
-                                            new COPSReportType(ReportType.FAILURE), si, null);
-                                }
-
-                                try {
-                                    reportMsg.writeData(socket);
-                                } catch (IOException e) {
-                                    throw new COPSPepException("Error writing gate set SUCCESS Report", e);
-                                }
-                            }
+                        final COPSPrObjBase obj = new COPSPrObjBase(decision.getData().getData());
+                        switch (obj.getSNum()) {
+                            case COPSPrObjBase.PR_PRID:
+                                prid = obj.getData().str();
+                                break;
+                            case COPSPrObjBase.PR_EPD:
+                                installDecs.put(prid, obj.getData().str());
+                                break;
+                            default:
+                                break;
                         }
                     }
                     break;
@@ -223,10 +177,10 @@ public class COPSPepReqStateMan extends COPSStateMan {
 
 
         if (_process.isFailReport(this)) {
-            // COPSDebug.out(getClass().getName(),"Sending FAIL Report\n");
+            logger.info("Sending FAIL report");
             _sender.sendFailReport(_process.getReportData(this));
         } else {
-            // COPSDebug.out(getClass().getName(),"Sending SUCCESS Report\n");
+            logger.info("Sending SUCCESS report");
             _sender.sendSuccessReport(_process.getReportData(this));
         }
         _status = Status.ST_REPORT;
@@ -240,12 +194,9 @@ public class COPSPepReqStateMan extends COPSStateMan {
 
     /**
      * Process the message NewRequestState
-     *
      * @throws   COPSPepException
-     *
      */
     protected void processOpenNewRequestState() throws COPSPepException {
-
         if (_process != null)
             _process.newRequestState(this);
 
@@ -254,11 +205,8 @@ public class COPSPepReqStateMan extends COPSStateMan {
 
     /**
      * Process the message DeleteRequestState
-     *
      * @param    dMsg                a  COPSDecisionMsg
-     *
      * @throws   COPSPepException
-     *
      */
     protected void processDeleteRequestState(final COPSDecisionMsg dMsg) throws COPSPepException {
         if (_process != null)
@@ -272,11 +220,8 @@ public class COPSPepReqStateMan extends COPSStateMan {
      * The message SycnStateRequest indicates that the remote PDP
      * wishes the client (which appears in the common header)
      * to re-send its state.
-     *
      * @param    ssMsg               a  COPSSyncStateMsg
-     *
      * @throws   COPSPepException
-     *
      */
     protected void processSyncStateRequest(final COPSSyncStateMsg ssMsg) throws COPSException {
         _syncState = false;
@@ -309,6 +254,10 @@ public class COPSPepReqStateMan extends COPSStateMan {
         _status = Status.ST_NOKA;
     }
 
+    /**
+     * Creates and sends an accounting report
+     * @throws COPSException
+     */
     public void processAcctReport() throws COPSException {
         final Map<String, String> report;
         if (_process != null) report = _process.getAcctData(this);
index 73de401e0ce543239e9679fd6d22c4bb0041babf..936fdeb4b809aa7d09f6c426ad9468b3db9c192f 100644 (file)
@@ -92,7 +92,7 @@ public class PCMMServiceTest {
         service.disconect();
     }
 
-    @Test
+//    @Test
     public void testAddAndRemoveUpGate() throws Exception {
 
         // TODO - Use this block to test against a real CMTS