1 package org.umu.cops.ospep;
3 import org.slf4j.Logger;
4 import org.slf4j.LoggerFactory;
5 import org.umu.cops.prpep.COPSPepReqStateMan;
6 import org.umu.cops.stack.*;
8 import java.net.Socket;
12 * State manager class for outsourcing requests, at the PEP side.
14 public class COPSPepOSReqStateMan extends COPSPepReqStateMan {
16 private final static Logger logger = LoggerFactory.getLogger(COPSPepOSReqStateMan.class);
19 Object for performing policy data processing
21 protected final COPSPepOSDataProcess _thisProcess;
24 COPS message transceiver used to send COPS messages
26 protected final COPSPepOSMsgSender _thisSender;
29 * ClientSI data populated when initRequestState() is called.
31 protected transient Set<COPSClientSI> _clientSIs;
35 * @param clientType - the PEP client type
36 * @param clientHandle - the client-handle
37 * @param process - the data processor
38 * @param clientSIs - the known client SI objects
39 * @param socket - the socket connection
41 public COPSPepOSReqStateMan(final short clientType, final COPSHandle clientHandle,
42 final COPSPepOSDataProcess process, final Collection<COPSClientSI> clientSIs,
43 final Socket socket) {
44 super(clientType, clientHandle, process, socket, new COPSPepOSMsgSender(clientType, clientHandle, socket));
45 this._thisProcess = process;
46 if (clientSIs == null)
47 this._clientSIs = new HashSet<>();
48 else this._clientSIs = new HashSet<>(clientSIs);
50 // Inits an object for sending COPS messages to the PDP
51 _thisSender = new COPSPepOSMsgSender(_clientType, _handle, _socket);
55 public void initRequestState() throws COPSException {
56 _clientSIs.addAll(_thisProcess.getClientData(this));
58 _thisSender.sendRequest(new HashSet<>(_clientSIs));
61 _status = Status.ST_INIT;
65 protected void processDecision(final COPSDecisionMsg dMsg) throws COPSException {
66 //** Applies decisions to the configuration
67 //_thisProcess.setDecisions(this, removeDecs, installDecs, errorDecs);
68 // second param changed to dMsg so that the data processor
69 // can check the 'solicited' flag
70 final boolean isFailReport = _thisProcess.setDecisions(this, dMsg);
71 _status = Status.ST_DECS;
74 logger.info("Sending FAIL Report");
75 _thisSender.sendFailReport(_thisProcess.getReportData(this));
77 logger.info("Sending SUCCESS Report");
78 _thisSender.sendSuccessReport(_thisProcess.getReportData(this));
80 _status = Status.ST_REPORT;
83 _thisSender.sendSyncComplete();
85 _status = Status.ST_SYNCALL;
90 protected void processSyncStateRequest(final COPSSyncStateMsg ssMsg) throws COPSException {
92 // If an object exists for retrieving the PEP features,
93 // use it for retrieving them.
96 _thisSender.sendRequest(_clientSIs);
98 _status = Status.ST_SYNC;
102 public void processAcctReport() throws COPSPepException {
103 final List<COPSClientSI> report;
104 if (_thisProcess != null) report = new ArrayList<>(_thisProcess.getAcctData(this));
105 else report = new ArrayList<>();
107 _thisSender.sendAcctReport(report);
109 _status = Status.ST_ACCT;