From 6336e615fcfed04d012edfe7d8e4c36566338e39 Mon Sep 17 00:00:00 2001 From: Steven Pisarski Date: Mon, 11 May 2015 15:34:13 -0600 Subject: [PATCH] Cleanup of state managers' interfaces (constructor and init). 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 --- .../src/main/java/org/pcmm/PCMMPdpAgent.java | 8 +- .../main/java/org/pcmm/PCMMPdpConnection.java | 3 +- .../main/java/org/pcmm/PCMMPdpMsgSender.java | 5 +- .../java/org/pcmm/PCMMPdpReqStateMan.java | 51 ++++--- .../src/main/java/org/pcmm/rcd/impl/CMTS.java | 73 --------- .../main/java/org/umu/cops/COPSStateMan.java | 18 ++- .../umu/cops/ospdp/COPSPdpOSConnection.java | 3 +- .../umu/cops/ospdp/COPSPdpOSReqStateMan.java | 16 +- .../umu/cops/ospep/COPSPepOSConnection.java | 8 +- .../umu/cops/ospep/COPSPepOSReqStateMan.java | 52 ++++--- .../java/org/umu/cops/prpdp/COPSPdpAgent.java | 8 +- .../org/umu/cops/prpdp/COPSPdpConnection.java | 3 +- .../umu/cops/prpdp/COPSPdpReqStateMan.java | 14 +- .../org/umu/cops/prpep/COPSPepConnection.java | 6 +- .../umu/cops/prpep/COPSPepReqStateMan.java | 143 ++++++------------ .../packetcable/provider/PCMMServiceTest.java | 2 +- 16 files changed, 135 insertions(+), 278 deletions(-) diff --git a/packetcable-driver/src/main/java/org/pcmm/PCMMPdpAgent.java b/packetcable-driver/src/main/java/org/pcmm/PCMMPdpAgent.java index 1cbe6d2..22486b7 100644 --- a/packetcable-driver/src/main/java/org/pcmm/PCMMPdpAgent.java +++ b/packetcable-driver/src/main/java/org/pcmm/PCMMPdpAgent.java @@ -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); diff --git a/packetcable-driver/src/main/java/org/pcmm/PCMMPdpConnection.java b/packetcable-driver/src/main/java/org/pcmm/PCMMPdpConnection.java index 5c50667..f9961c4 100644 --- a/packetcable-driver/src/main/java/org/pcmm/PCMMPdpConnection.java +++ b/packetcable-driver/src/main/java/org/pcmm/PCMMPdpConnection.java @@ -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); } } diff --git a/packetcable-driver/src/main/java/org/pcmm/PCMMPdpMsgSender.java b/packetcable-driver/src/main/java/org/pcmm/PCMMPdpMsgSender.java index 6ed5520..da1be39 100644 --- a/packetcable-driver/src/main/java/org/pcmm/PCMMPdpMsgSender.java +++ b/packetcable-driver/src/main/java/org/pcmm/PCMMPdpMsgSender.java @@ -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; diff --git a/packetcable-driver/src/main/java/org/pcmm/PCMMPdpReqStateMan.java b/packetcable-driver/src/main/java/org/pcmm/PCMMPdpReqStateMan.java index 5e5f630..79470ff 100644 --- a/packetcable-driver/src/main/java/org/pcmm/PCMMPdpReqStateMan.java +++ b/packetcable-driver/src/main/java/org/pcmm/PCMMPdpReqStateMan.java @@ -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; diff --git a/packetcable-driver/src/main/java/org/pcmm/rcd/impl/CMTS.java b/packetcable-driver/src/main/java/org/pcmm/rcd/impl/CMTS.java index 09ae644..4a89bad 100644 --- a/packetcable-driver/src/main/java/org/pcmm/rcd/impl/CMTS.java +++ b/packetcable-driver/src/main/java/org/pcmm/rcd/impl/CMTS.java @@ -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 removeDecs = new HashMap<>(); - final Map installDecs = new HashMap<>(); - final Map errorDecs = new HashMap<>(); - - for (final Set 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 removeDecs; diff --git a/packetcable-driver/src/main/java/org/umu/cops/COPSStateMan.java b/packetcable-driver/src/main/java/org/umu/cops/COPSStateMan.java index 2b742f6..c6d6a25 100644 --- a/packetcable-driver/src/main/java/org/umu/cops/COPSStateMan.java +++ b/packetcable-driver/src/main/java/org/umu/cops/COPSStateMan.java @@ -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 */ diff --git a/packetcable-driver/src/main/java/org/umu/cops/ospdp/COPSPdpOSConnection.java b/packetcable-driver/src/main/java/org/umu/cops/ospdp/COPSPdpOSConnection.java index 73bb342..236d0cd 100644 --- a/packetcable-driver/src/main/java/org/umu/cops/ospdp/COPSPdpOSConnection.java +++ b/packetcable-driver/src/main/java/org/umu/cops/ospdp/COPSPdpOSConnection.java @@ -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); } } diff --git a/packetcable-driver/src/main/java/org/umu/cops/ospdp/COPSPdpOSReqStateMan.java b/packetcable-driver/src/main/java/org/umu/cops/ospdp/COPSPdpOSReqStateMan.java index e28438e..ea70b05 100644 --- a/packetcable-driver/src/main/java/org/umu/cops/ospdp/COPSPdpOSReqStateMan.java +++ b/packetcable-driver/src/main/java/org/umu/cops/ospdp/COPSPdpOSReqStateMan.java @@ -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; } diff --git a/packetcable-driver/src/main/java/org/umu/cops/ospep/COPSPepOSConnection.java b/packetcable-driver/src/main/java/org/umu/cops/ospep/COPSPepOSConnection.java index 8a2eb86..ad10ccc 100644 --- a/packetcable-driver/src/main/java/org/umu/cops/ospep/COPSPepOSConnection.java +++ b/packetcable-driver/src/main/java/org/umu/cops/ospep/COPSPepOSConnection.java @@ -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 clientSIs) throws COPSException { - final COPSPepOSReqStateMan manager = new COPSPepOSReqStateMan(_clientType, handle, process, clientSIs); + final Collection 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; } diff --git a/packetcable-driver/src/main/java/org/umu/cops/ospep/COPSPepOSReqStateMan.java b/packetcable-driver/src/main/java/org/umu/cops/ospep/COPSPepOSReqStateMan.java index fe7c891..a272d64 100644 --- a/packetcable-driver/src/main/java/org/umu/cops/ospep/COPSPepOSReqStateMan.java +++ b/packetcable-driver/src/main/java/org/umu/cops/ospep/COPSPepOSReqStateMan.java @@ -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 _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 COPSHandle + * ClientSI data populated when initRequestState() is called. */ - public COPSPepOSReqStateMan(final short clientType, final COPSHandle clientHandle, final COPSPepOSDataProcess process, - final Collection clientSIs) { - super(clientType, clientHandle, process); + protected transient Set _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 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; } diff --git a/packetcable-driver/src/main/java/org/umu/cops/prpdp/COPSPdpAgent.java b/packetcable-driver/src/main/java/org/umu/cops/prpdp/COPSPdpAgent.java index 637d84d..c7c0ec7 100644 --- a/packetcable-driver/src/main/java/org/umu/cops/prpdp/COPSPdpAgent.java +++ b/packetcable-driver/src/main/java/org/umu/cops/prpdp/COPSPdpAgent.java @@ -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); diff --git a/packetcable-driver/src/main/java/org/umu/cops/prpdp/COPSPdpConnection.java b/packetcable-driver/src/main/java/org/umu/cops/prpdp/COPSPdpConnection.java index 2248a9e..fec4fd2 100644 --- a/packetcable-driver/src/main/java/org/umu/cops/prpdp/COPSPdpConnection.java +++ b/packetcable-driver/src/main/java/org/umu/cops/prpdp/COPSPdpConnection.java @@ -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); } /** diff --git a/packetcable-driver/src/main/java/org/umu/cops/prpdp/COPSPdpReqStateMan.java b/packetcable-driver/src/main/java/org/umu/cops/prpdp/COPSPdpReqStateMan.java index 49a24fc..72fdccc 100644 --- a/packetcable-driver/src/main/java/org/umu/cops/prpdp/COPSPdpReqStateMan.java +++ b/packetcable-driver/src/main/java/org/umu/cops/prpdp/COPSPdpReqStateMan.java @@ -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; } diff --git a/packetcable-driver/src/main/java/org/umu/cops/prpep/COPSPepConnection.java b/packetcable-driver/src/main/java/org/umu/cops/prpep/COPSPepConnection.java index 3418575..66455eb 100644 --- a/packetcable-driver/src/main/java/org/umu/cops/prpep/COPSPepConnection.java +++ b/packetcable-driver/src/main/java/org/umu/cops/prpep/COPSPepConnection.java @@ -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; } diff --git a/packetcable-driver/src/main/java/org/umu/cops/prpep/COPSPepReqStateMan.java b/packetcable-driver/src/main/java/org/umu/cops/prpep/COPSPepReqStateMan.java index 6cbe8a1..532b573 100644 --- a/packetcable-driver/src/main/java/org/umu/cops/prpep/COPSPepReqStateMan.java +++ b/packetcable-driver/src/main/java/org/umu/cops/prpep/COPSPepReqStateMan.java @@ -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 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> 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 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 report; if (_process != null) report = _process.getAcctData(this); diff --git a/packetcable-policy-server/src/test/java/org/opendaylight/controller/packetcable/provider/PCMMServiceTest.java b/packetcable-policy-server/src/test/java/org/opendaylight/controller/packetcable/provider/PCMMServiceTest.java index 73de401..936fdeb 100644 --- a/packetcable-policy-server/src/test/java/org/opendaylight/controller/packetcable/provider/PCMMServiceTest.java +++ b/packetcable-policy-server/src/test/java/org/opendaylight/controller/packetcable/provider/PCMMServiceTest.java @@ -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 -- 2.36.6