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
37 public void sendSolicitedDecision(Vector removeDecs, Vector installDecs) throws COPSPdpException {
38 sendDecision(removeDecs, installDecs, true);
42 * Sends a decision message which was not requested by the PEP
43 * @param removeDecs Decisions to be removed
44 * @param installDecs Decisions to be installed
45 * @throws COPSPdpException
47 public void sendUnsolicitedDecision(Vector removeDecs, Vector installDecs) throws COPSPdpException {
48 sendDecision(removeDecs, installDecs, false);
52 * Sends a decision message to the PEP
53 * @param removeDecs Decisions to be removed
54 * @param installDecs Decisions to be installed
55 * @param solicited <tt>true</tt> if the PEP requested this decision, <tt>false</tt> otherwise
56 * @throws COPSPdpException
58 public void sendDecision(Vector removeDecs, Vector installDecs, boolean solicited) throws COPSPdpException {
59 // Common Header holding the same ClientType as the request
64 flag = Flag.UNSOLICITED;
66 final Map<COPSContext, Set<COPSDecision>> decisions = new HashMap<>();
68 // Decisions (no flags supplied)
70 final COPSContext cntxt = new COPSContext(RType.CONFIG, (short)0);
74 final COPSDecision rdec1;
75 if (installDecs.size() == 0)
76 rdec1 = new COPSDecision(Command.REMOVE);
78 rdec1 = new COPSDecision(Command.INSTALL);
80 if (decisions.get(cntxt) == null) {
81 final Set<COPSDecision> decisionSet = new HashSet<>();
82 decisionSet.add(rdec1);
83 decisions.put(cntxt, decisionSet);
85 decisions.get(cntxt).add(rdec1);
88 // Client Handle with the same clientHandle as the request
89 final COPSDecisionMsg decisionMsg = new COPSDecisionMsg(1, flag, getClientType(), _handle, decisions,
95 decisionMsg.writeData(_sock);
96 } catch (IOException e) {
97 throw new COPSPdpException("Failed to send the decision, reason: " + e.getMessage());