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 super(clientType, clientHandle);
40 this._process = process;
44 protected void initRequestState(final Socket sock) throws COPSException {
45 // Inits an object for sending COPS messages to the PEP
46 _sender = new COPSPdpMsgSender(_clientType, _handle, sock);
49 _status = Status.ST_INIT;
53 * Processes a COPS request
54 * @param msg COPS request received from the PEP
55 * @throws COPSException
57 protected void processRequest(final COPSReqMsg msg) throws COPSException {
58 // TODO - Implement me - see commented out code from history prior to May 4, 2015...
63 * @param msg Report message from the PEP
64 * @throws COPSException
66 protected void processReport(final COPSReportMsg msg) throws COPSException {
67 if (msg.getClientSI() != null) {
69 final COPSReportType rtypemsg = msg.getReport();
70 final Map<String, String> repSIs = new HashMap<>();
71 String strobjprid = "";
72 final COPSPrObjBase obj = new COPSPrObjBase(msg.getClientSI().getData().getData());
73 switch (obj.getSNum()) {
74 case COPSPrObjBase.PR_PRID:
75 strobjprid = obj.getData().str();
77 case COPSPrObjBase.PR_EPD:
78 // TODO FIXME - strobjprid is always empty here???
79 repSIs.put(strobjprid, obj.getData().str());
80 logger.info("PRID: " + strobjprid);
81 logger.info("EPD: " + obj.getData().str());
87 //** Here we must act in accordance with
88 //** the report received
89 switch (rtypemsg.getReportType()) {
91 _status = Status.ST_REPORT;
92 _process.successReport(this, repSIs);
95 _status = Status.ST_REPORT;
96 _process.failReport(this, repSIs);
99 _status = Status.ST_ACCT;
100 _process.acctReport(this, repSIs);
107 * Called when connection is closed
108 * @param error Reason
109 * @throws COPSPdpException
111 public void processClosedConnection(final COPSError error) throws COPSException {
112 if (_process != null)
113 _process.notifyClosedConnection(this, error);
115 _status = Status.ST_CCONN;
119 * Called when no keep-alive is received
120 * @throws COPSPdpException
122 public void processNoKAConnection() throws COPSException {
123 if (_process != null)
124 _process.notifyNoKAliveReceived(this);
126 _status = Status.ST_NOKA;
130 * Deletes the request state
131 * @throws COPSPdpException
133 protected void finalizeRequestState() throws COPSException {
134 _sender.sendDeleteRequestState();
135 _status = Status.ST_FINAL;
139 * Asks for a COPS sync
140 * @throws COPSPdpException
142 public void syncRequestState() throws COPSException {
143 _sender.sendSyncRequestState();
144 _status = Status.ST_SYNC;
148 * Opens a new request state
149 * @throws COPSPdpException
151 protected void openNewRequestState() throws COPSException {
152 _sender.sendOpenNewRequestState();
153 _status = Status.ST_NEW;
157 * Processes a COPS delete message
158 * @param dMsg <tt>COPSDeleteMsg</tt> received from the PEP
159 * @throws COPSPdpException
161 public void processDeleteRequestState(final COPSDeleteMsg dMsg) throws COPSException {
162 if (_process != null)
163 _process.closeRequestState(this);
165 _status = Status.ST_DEL;