7 import org.pcmm.gates.IGateID;
8 import org.pcmm.gates.IPCMMGate;
9 import org.pcmm.gates.ITransactionID;
10 import org.pcmm.gates.impl.PCMMError;
11 import org.pcmm.gates.impl.PCMMGateReq;
12 import org.slf4j.Logger;
13 import org.slf4j.LoggerFactory;
14 import org.umu.cops.prpdp.COPSPdpException;
15 import org.umu.cops.prpdp.COPSPdpReqStateMan;
16 import org.umu.cops.stack.*;
17 import org.umu.cops.stack.COPSReportType.ReportType;
19 import java.net.Socket;
20 import java.util.Arrays;
21 import java.util.HashMap;
25 * State manager class for provisioning requests, at the PDP side.
27 public class PCMMPdpReqStateMan extends COPSPdpReqStateMan {
29 private final static Logger logger = LoggerFactory.getLogger(PCMMPdpReqStateMan.class);
32 * Object for performing policy data processing
34 protected final PCMMPdpDataProcess _thisProcess;
36 /** COPS message transceiver used to send COPS messages */
37 protected final PCMMPdpMsgSender _sender;
40 * Creates a request state manager
41 * @param clientType Client-type
42 * @param clientHandle Client handle
44 // TODO - consider sending in the COPSHandle object instead
45 public PCMMPdpReqStateMan(final short clientType, final COPSHandle clientHandle, final PCMMPdpDataProcess process,
46 final Socket socket) {
47 super(clientType, clientHandle, process, socket);
48 this._thisProcess = process;
49 _sender = new PCMMPdpMsgSender(_clientType, _handle, _socket);
51 _status = Status.ST_INIT;
55 public void processRequest(final COPSReqMsg msg) throws COPSPdpException {
56 // TODO - Implement me - see commented out code from history prior to May 4, 2015...
59 // TODO - break apart this method
61 protected void processReport(final COPSReportMsg msg) throws COPSPdpException {
63 final COPSReportType rtypemsg = msg.getReport();
65 if (msg.getClientSI() != null) {
66 final COPSClientSI clientSI = msg.getClientSI();
68 final byte[] data = Arrays.copyOfRange(clientSI.getData().getData(), 0, clientSI.getData().getData().length);
70 // PCMMUtils.WriteBinaryDump("COPSReportClientSI", data);
71 logger.info("PCMMGateReq Parse Gate Message");
72 final PCMMGateReq gateMsg = new PCMMGateReq(data);
74 // TODO FIXME - Why is this Map being filled but never used???
75 final Map<String, String> repSIs = new HashMap<>();
76 String strobjprid = "";
77 final COPSPrObjBase obj = new COPSPrObjBase(clientSI.getData().getData());
78 switch (obj.getSNum()) {
79 case COPSPrObjBase.PR_PRID:
80 logger.info("COPSPrObjBase.PR_PRID");
81 // TODO FIXME - this value is never used
82 strobjprid = obj.getData().str();
84 case COPSPrObjBase.PR_EPD:
85 logger.info("COPSPrObjBase.PR_EPD");
86 // TODO FIXME - strobjprid is always empty
87 repSIs.put(strobjprid, obj.getData().str());
88 logger.info("PRID: " + strobjprid);
89 logger.info("EPD: " + obj.getData().str());
92 logger.error("Object s-num: " + obj.getSNum() + "stype " + obj.getSType());
93 logger.error("PRID: " + strobjprid);
94 logger.error("EPD: " + obj.getData().str());
98 logger.info("rtypemsg process");
99 //** Here we must act in accordance with
100 //** the report received
102 // retrieve and remove the transactionId to gate request map entry
103 // see PCMMPdpMsgSender.sendGateSet(IPCMMGate gate)
104 final ITransactionID trID = gateMsg.getTransactionID();
105 final Short trIDnum = trID.getTransactionIdentifier();
107 logger.info("Removing gate from cache with key - " + trIDnum);
108 final IPCMMGate gate = PCMMGlobalConfig.transactionGateMap.remove(trIDnum);
110 // capture the "error" message if any
111 gate.setError(gateMsg.getError());
112 logger.info("Setting error on gate - " + gateMsg.getError());
114 logger.error("processReport(): gateReq not found for transactionID {}", trIDnum);
118 if (rtypemsg.getReportType().equals(ReportType.SUCCESS)) {
119 logger.info("rtypemsg success");
120 _status = Status.ST_REPORT;
121 final IGateID gateID = gateMsg.getGateID();
122 logger.info("Setting gate ID on gate object - " + gateID);
123 gate.setGateID(gateID);
124 if (_thisProcess != null)
125 _thisProcess.successReport(this, gateMsg);
127 final String cmdType;
128 if ( trID.getGateCommandType() == ITransactionID.GateDeleteAck ) {
129 cmdType = "GateDeleteAck";
130 } else if ( trID.getGateCommandType() == ITransactionID.GateSetAck ) {
131 cmdType = "GateSetAck";
132 } else cmdType = null;
133 // capture the gateId from the response message
134 final IGateID gateID = gateMsg.getGateID();
135 logger.info("Setting gate ID on gate object - " + gateID);
136 gate.setGateID(gateID);
138 if (gateID != null) {
139 int gateIdInt = gateID.getGateID();
140 String gateIdHex = String.format("%08x", gateIdInt);
141 logger.info(getClass().getName() + ": " + cmdType + ": GateID = " + gateIdHex);
143 logger.warn("Gate ID is null");
146 if (rtypemsg.getReportType().equals(ReportType.FAILURE)) {
147 logger.info("rtypemsg failure");
148 _status = Status.ST_REPORT;
149 if (_thisProcess != null)
150 _thisProcess.failReport(this, gateMsg);
152 if (gateMsg.getError() != null)
153 logger.info("Gate message error - " + gateMsg.getError().toString());
155 final PCMMError error = new PCMMError();
156 // TODO - figure out correct error code
157 error.setErrorCode((short)19);
158 gate.setError(error);
159 logger.warn("Gate request failed without an error, setting one - " + error);
161 } else if (rtypemsg.getReportType().equals(ReportType.ACCOUNTING)) {
162 logger.info("rtypemsg account");
163 _status = Status.ST_ACCT;
164 if (_thisProcess != null)
165 _thisProcess.acctReport(this, gateMsg);
168 // let the waiting gateSet/gateDelete sender proceed
169 // TODO - see PCMMService#processReport() gate.notify(). Should determine a better means to
170 // TODO - handle this synchronization.
171 logger.info("Notify gate request has been updated with ID - " + gate.getGateID());
175 logger.info("Out processReport");