1 package org.umu.cops.ospdp;
3 import org.umu.cops.prpdp.COPSPdpMsgSender;
4 import org.umu.cops.stack.*;
5 import org.umu.cops.stack.COPSContext.RType;
6 import org.umu.cops.stack.COPSDecision.Command;
7 import org.umu.cops.stack.COPSHeader.Flag;
9 import java.io.IOException;
10 import java.net.Socket;
14 * COPS message transceiver class for outsourcing connections at the PDP side.
16 * TODO - change all references of Vector to List<>
18 public class COPSPdpOSMsgSender extends COPSPdpMsgSender {
21 * Creates a COPSPepMsgSender
23 * @param clientType COPS client-type
24 * @param clientHandle Client handle
25 * @param sock Socket to the PEP
27 public COPSPdpOSMsgSender(final short clientType, final COPSHandle clientHandle, final Socket sock) {
28 super(clientType, clientHandle, sock);
32 * Sends a decision message which was requested by the PEP
33 * @param removeDecs Decisions to be removed
34 * @param installDecs Decisions to be installed
35 * @throws COPSPdpException
36 * TODO - Add type to List once we know what it should be.
38 public void sendSolicitedDecision(final List removeDecs, final List installDecs) throws COPSPdpException {
39 sendDecision(removeDecs, installDecs, true);
43 * Sends a decision message which was not requested by the PEP
44 * @param removeDecs Decisions to be removed
45 * @param installDecs Decisions to be installed
46 * @throws COPSPdpException
47 * TODO - Add type to List once we know what it should be.
49 public void sendUnsolicitedDecision(final List removeDecs, final List installDecs) throws COPSPdpException {
50 sendDecision(removeDecs, installDecs, false);
54 * Sends a decision message to the PEP
55 * @param removeDecs Decisions to be removed
56 * @param installDecs Decisions to be installed
57 * @param solicited <tt>true</tt> if the PEP requested this decision, <tt>false</tt> otherwise
58 * @throws COPSPdpException
59 * TODO - Add type to List once we know what it should be.
61 public void sendDecision(final List removeDecs, final List installDecs, boolean solicited) throws COPSPdpException {
62 // Common Header holding the same ClientType as the request
67 flag = Flag.UNSOLICITED;
69 final Map<COPSContext, Set<COPSDecision>> decisions = new HashMap<>();
71 // Decisions (no flags supplied)
73 final COPSContext cntxt = new COPSContext(RType.CONFIG, (short)0);
77 final COPSDecision rdec1;
78 if (installDecs.size() == 0)
79 rdec1 = new COPSDecision(Command.REMOVE);
81 rdec1 = new COPSDecision(Command.INSTALL);
83 if (decisions.get(cntxt) == null) {
84 final Set<COPSDecision> decisionSet = new HashSet<>();
85 decisionSet.add(rdec1);
86 decisions.put(cntxt, decisionSet);
88 decisions.get(cntxt).add(rdec1);
91 // Client Handle with the same clientHandle as the request
92 final COPSDecisionMsg decisionMsg = new COPSDecisionMsg(1, flag, getClientType(), _handle, decisions,
98 decisionMsg.writeData(_sock);
99 } catch (IOException e) {
100 throw new COPSPdpException("Failed to send the decision, reason: " + e.getMessage());