2 * Copyright (c) 2004 University of Murcia. All rights reserved.
3 * --------------------------------------------------------------
4 * For more information, please see <http://www.umu.euro6ix.org/>.
7 package org.umu.cops.prpdp;
9 import org.slf4j.Logger;
10 import org.slf4j.LoggerFactory;
11 import org.umu.cops.COPSStateMan;
12 import org.umu.cops.stack.*;
14 import java.net.Socket;
15 import java.util.HashMap;
19 * State manager class for provisioning requests, at the PDP side.
21 public class COPSPdpReqStateMan extends COPSStateMan {
23 private final static Logger logger = LoggerFactory.getLogger(COPSPdpReqStateMan.class);
26 * Object for performing policy data processing
28 private final COPSPdpDataProcess _process;
30 /** COPS message transceiver used to send COPS messages */
31 protected transient COPSPdpMsgSender _sender;
34 * Creates a request state manager
35 * @param clientType Client-type
36 * @param clientHandle Client handle
38 public COPSPdpReqStateMan(final short clientType, final COPSHandle clientHandle, final COPSPdpDataProcess process,
39 final Socket socket) {
40 super(clientType, clientHandle, socket);
41 this._process = process;
42 _sender = new COPSPdpMsgSender(_clientType, _handle, _socket);
43 _status = Status.ST_INIT;
47 * Processes a COPS request
48 * @param msg COPS request received from the PEP
49 * @throws COPSException
51 protected void processRequest(final COPSReqMsg msg) throws COPSException {
52 // TODO - Implement me - see commented out code from history prior to May 4, 2015...
57 * @param msg Report message from the PEP
58 * @throws COPSException
60 protected void processReport(final COPSReportMsg msg) throws COPSException {
61 if (msg.getClientSI() != null) {
63 final COPSReportType rtypemsg = msg.getReport();
64 final Map<String, String> repSIs = new HashMap<>();
65 String strobjprid = "";
66 final COPSPrObjBase obj = new COPSPrObjBase(msg.getClientSI().getData().getData());
67 switch (obj.getSNum()) {
68 case COPSPrObjBase.PR_PRID:
69 strobjprid = obj.getData().str();
71 case COPSPrObjBase.PR_EPD:
72 // TODO FIXME - strobjprid is always empty here???
73 repSIs.put(strobjprid, obj.getData().str());
74 logger.info("PRID: " + strobjprid);
75 logger.info("EPD: " + obj.getData().str());
81 //** Here we must act in accordance with
82 //** the report received
83 switch (rtypemsg.getReportType()) {
85 _status = Status.ST_REPORT;
86 _process.successReport(this, repSIs);
89 _status = Status.ST_REPORT;
90 _process.failReport(this, repSIs);
93 _status = Status.ST_ACCT;
94 _process.acctReport(this, repSIs);
101 * Called when connection is closed
102 * @param error Reason
103 * @throws COPSPdpException
105 public void processClosedConnection(final COPSError error) throws COPSException {
106 if (_process != null)
107 _process.notifyClosedConnection(this, error);
109 _status = Status.ST_CCONN;
113 * Called when no keep-alive is received
114 * @throws COPSPdpException
116 public void processNoKAConnection() throws COPSException {
117 if (_process != null)
118 _process.notifyNoKAliveReceived(this);
120 _status = Status.ST_NOKA;
124 * Deletes the request state
125 * @throws COPSPdpException
127 protected void finalizeRequestState() throws COPSException {
128 _sender.sendDeleteRequestState();
129 _status = Status.ST_FINAL;
133 * Asks for a COPS sync
134 * @throws COPSPdpException
136 public void syncRequestState() throws COPSException {
137 _sender.sendSyncRequestState();
138 _status = Status.ST_SYNC;
142 * Opens a new request state
143 * @throws COPSPdpException
145 protected void openNewRequestState() throws COPSException {
146 _sender.sendOpenNewRequestState();
147 _status = Status.ST_NEW;
151 * Processes a COPS delete message
152 * @param dMsg <tt>COPSDeleteMsg</tt> received from the PEP
153 * @throws COPSPdpException
155 public void processDeleteRequestState(final COPSDeleteMsg dMsg) throws COPSException {
156 if (_process != null)
157 _process.closeRequestState(this);
159 _status = Status.ST_DEL;