Completed COPS Message refactoring. Was planning on one additional patch starting...
[packetcable.git] / packetcable-driver / src / main / java / org / pcmm / PCMMPdpMsgSender.java
index a13ec99f44e7fccaac0189c935cc12d96c54c9f0..79ca1a8f98a4b83dd60b5025aed620025a1a9ebd 100644 (file)
@@ -8,13 +8,25 @@ import org.pcmm.gates.*;
 import org.pcmm.gates.IGateSpec.DSCPTOS;
 import org.pcmm.gates.IGateSpec.Direction;
 import org.pcmm.gates.impl.*;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.umu.cops.prpdp.COPSPdpException;
 import org.umu.cops.stack.*;
+import org.umu.cops.stack.COPSContext.RType;
+import org.umu.cops.stack.COPSDecision.Command;
+import org.umu.cops.stack.COPSDecision.DecisionFlag;
+import org.umu.cops.stack.COPSHeader.ClientType;
+import org.umu.cops.stack.COPSHeader.OPCode;
+import org.umu.cops.stack.COPSObjHeader.CType;
 
 import java.io.IOException;
 import java.net.InetAddress;
 import java.net.Socket;
 import java.net.UnknownHostException;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
 
 //temp
 //pcmm
@@ -35,6 +47,8 @@ import java.net.UnknownHostException;
  */
 public class PCMMPdpMsgSender {
 
+    public final static Logger logger = LoggerFactory.getLogger(PCMMPdpMsgSender.class);
+
     /**
      * Socket connected to PEP
      */
@@ -43,7 +57,7 @@ public class PCMMPdpMsgSender {
     /**
      * COPS client-type that identifies the policy client
      */
-    protected short _clientType;
+    protected ClientType _clientType;
 
     /**
      * COPS client handle used to uniquely identify a particular PEP's request
@@ -69,8 +83,7 @@ public class PCMMPdpMsgSender {
      * @param sock
      *            Socket to the PEP
      */
-    public PCMMPdpMsgSender(short clientType, COPSHandle clientHandle,
-                            Socket sock) {
+    public PCMMPdpMsgSender(final ClientType clientType, final COPSHandle clientHandle, final Socket sock) {
         // COPS Handle
         _handle = clientHandle;
         _clientType = clientType;
@@ -80,8 +93,8 @@ public class PCMMPdpMsgSender {
         _sock = sock;
     }
 
-    public PCMMPdpMsgSender(short clientType, short tID,
-                            COPSHandle clientHandle, Socket sock) {
+    public PCMMPdpMsgSender(final ClientType clientType, final short tID, final COPSHandle clientHandle,
+                            final Socket sock) {
         // COPS Handle
         _handle = clientHandle;
         _clientType = clientType;
@@ -104,7 +117,7 @@ public class PCMMPdpMsgSender {
      *
      * @return Client-type value
      */
-    public short getClientType() {
+    public ClientType getClientType() {
         return _clientType;
     }
 
@@ -120,64 +133,41 @@ public class PCMMPdpMsgSender {
 
     /**
      * Sends a PCMM GateSet COPS Decision message
-     *
-     * @param
+     * @param gate - the gate
      * @throws COPSPdpException
      */
-    public void sendGateSet(IPCMMGate gate)
-    throws COPSPdpException {
-        // Common Header with the same ClientType as the request
-
-        COPSHeader hdr = new COPSHeader(COPSHeader.COPS_OP_DEC, getClientType());
-
-        // Client Handle with the same clientHandle as the request
-        final COPSHandle handle = new COPSHandle(getClientHandle().getId());
-        COPSDecisionMsg decisionMsg = new COPSDecisionMsg();
-        ITransactionID trID = new TransactionID();
+    public void sendGateSet(final IPCMMGate gate) throws COPSPdpException {
+        final ITransactionID trID = new TransactionID();
 
         // set transaction ID to gate set
         trID.setGateCommandType(ITransactionID.GateSet);
-        _transactionID = (short) (_transactionID == 0 ? (short) (Math.random() * hashCode())
-                                  : _transactionID);
+        _transactionID = (_transactionID == 0 ? (short) (Math.random() * hashCode()) : _transactionID);
         trID.setTransactionIdentifier(_transactionID);
 
         gate.setTransactionID(trID);
 
 
         // new pcmm specific clientsi
-        COPSClientSI clientSD = new COPSClientSI(COPSObjHeader.COPS_DEC, (byte) 4);
-        byte[] data = gate.getData();
-        clientSD.setData(new COPSData(data, 0, data.length));
-        try {
-            decisionMsg.add(hdr);
-            decisionMsg.add(handle);
-            // Decisions (no flags supplied)
-            // <Context>
-            COPSContext cntxt = new COPSContext(COPSContext.CONFIG, (short) 0);
-            COPSDecision install = new COPSDecision();
-            install.setCmdCode(COPSDecision.DEC_INSTALL);
-            install.setFlags(COPSDecision.F_REQERROR);
-            decisionMsg.addDecision(install, cntxt);
-            decisionMsg.add(clientSD); // setting up the gate
-            /*
-                        try {
-                            decisionMsg.dump(System.out);
-                        } catch (IOException unae) {
-                            System.out.println("Error dumping " + unae.getMessage());
-                        }
-            */
-
-        } catch (COPSException e) {
-            System.out.println("Error making Msg" + e.getMessage());
-        }
+        final byte[] data = gate.getData();
+        // Common Header with the same ClientType as the request
+        // Client Handle with the same clientHandle as the request
 
+        final Set<COPSDecision> decisionSet = new HashSet<>();
+        decisionSet.add(new COPSDecision(CType.CSI, Command.INSTALL, DecisionFlag.REQERROR,
+                new COPSData(data, 0, data.length)));
+        final Map<COPSContext, Set<COPSDecision>> decisionMap = new HashMap<>();
+        decisionMap.put(new COPSContext(RType.CONFIG, (short)0), decisionSet);
+
+        final COPSDecisionMsg decisionMsg = new COPSDecisionMsg(_clientType, new COPSHandle(getClientHandle().getId()),
+                decisionMap, null);
+//                new COPSClientSI(CSIType.SIGNALED, new COPSData(data, 0, data.length)), decisionMap);
+        //                new COPSClientSI(CNum.DEC, (byte) 4, new COPSData(data, 0, data.length), null));
         // ** Send the GateSet Decision
         // **
         try {
             decisionMsg.writeData(_sock);
         } catch (IOException e) {
-            System.out.println("Failed to send the decision, reason: "
-                               + e.getMessage());
+            logger.error("Failed to send the decision", e);
         }
 
     }
@@ -185,35 +175,24 @@ public class PCMMPdpMsgSender {
     /**
      * Sends a PCMM GateSet COPS Decision message
      *
-     * @param
+     * @param num - the number
      * @throws COPSPdpException
      */
-    public void sendGateSetDemo(int num)
-    throws COPSPdpException {
-
-        // Common Header with the same ClientType as the request
-
-        COPSHeader hdr = new COPSHeader(COPSHeader.COPS_OP_DEC, getClientType());
-
-        // Client Handle with the same clientHandle as the request
-        COPSDecisionMsg decisionMsg = new COPSDecisionMsg();
-
-        IPCMMGate gate = new PCMMGateReq();
-        ITransactionID trID = new TransactionID();
-
-        IAMID amid = new AMID();
-        ISubscriberID subscriberID = new SubscriberID();
-        IGateSpec gateSpec = new GateSpec();
-        IClassifier classifier = new Classifier();
-        IExtendedClassifier eclassifier = new ExtendedClassifier();
-        int TrafficRate = 0;
-
+    public void sendGateSetDemo(int num) throws COPSPdpException {
+        final IPCMMGate gate = new PCMMGateReq();
+        final ITransactionID trID = new TransactionID();
+        final IAMID amid = new AMID();
+        final ISubscriberID subscriberID = new SubscriberID();
+        final IGateSpec gateSpec = new GateSpec();
+        final IClassifier classifier = new Classifier();
+        final IExtendedClassifier eclassifier = new ExtendedClassifier();
+        final int trafficRate;
         if (num == 1)
-            TrafficRate =   PCMMGlobalConfig.DefaultBestEffortTrafficRate;
+            trafficRate =   PCMMGlobalConfig.DefaultBestEffortTrafficRate;
         else
-            TrafficRate =   PCMMGlobalConfig.DefaultLowBestEffortTrafficRate;
+            trafficRate =   PCMMGlobalConfig.DefaultLowBestEffortTrafficRate;
 
-        ITrafficProfile trafficProfile = new BestEffortService(
+        final ITrafficProfile trafficProfile = new BestEffortService(
             (byte) 7); //BestEffortService.DEFAULT_ENVELOP);
         ((BestEffortService) trafficProfile).getAuthorizedEnvelop()
         .setTrafficPriority(BestEffortService.DEFAULT_TRAFFIC_PRIORITY);
@@ -225,7 +204,7 @@ public class PCMMPdpMsgSender {
             PCMMGlobalConfig.BETransmissionPolicy);
         ((BestEffortService) trafficProfile).getAuthorizedEnvelop()
         .setMaximumSustainedTrafficRate(
-            TrafficRate);
+            trafficRate);
         //  PCMMGlobalConfig.DefaultLowBestEffortTrafficRate );
         //  PCMMGlobalConfig.DefaultBestEffortTrafficRate);
 
@@ -239,7 +218,7 @@ public class PCMMPdpMsgSender {
             PCMMGlobalConfig.BETransmissionPolicy);
         ((BestEffortService) trafficProfile).getReservedEnvelop()
         .setMaximumSustainedTrafficRate(
-            TrafficRate);
+            trafficRate);
         //  PCMMGlobalConfig.DefaultLowBestEffortTrafficRate );
         //  PCMMGlobalConfig.DefaultBestEffortTrafficRate);
 
@@ -254,21 +233,15 @@ public class PCMMPdpMsgSender {
             PCMMGlobalConfig.BETransmissionPolicy);
         ((BestEffortService) trafficProfile).getCommittedEnvelop()
         .setMaximumSustainedTrafficRate(
-            TrafficRate);
+            trafficRate);
         //  PCMMGlobalConfig.DefaultLowBestEffortTrafficRate );
         //  PCMMGlobalConfig.DefaultBestEffortTrafficRate);
 
 
 
-        // new pcmm specific clientsi
-        COPSClientSI clientSD = new COPSClientSI(COPSObjHeader.COPS_DEC, (byte) 4);
-
-        final COPSHandle handle = new COPSHandle(getClientHandle().getId());
-
         // set transaction ID to gate set
         trID.setGateCommandType(ITransactionID.GateSet);
-        _transactionID = (short) (_transactionID == 0 ? (short) (Math.random() * hashCode())
-                                  : _transactionID);
+        _transactionID = (_transactionID == 0 ? (short) (Math.random() * hashCode()) : _transactionID);
         trID.setTransactionIdentifier(_transactionID);
 
         amid.setApplicationType((short) 1);
@@ -281,6 +254,7 @@ public class PCMMPdpMsgSender {
         gateSpec.setTimerT4(PCMMGlobalConfig.GateT4);
 
         // XXX - if the version major is less than 4 we need to use Classifier
+        // TODO - Use some variable here or remove...
         if (true) {
             //eclassifier.setProtocol(IClassifier.Protocol.NONE);
             eclassifier.setProtocol(IClassifier.Protocol.TCP);
@@ -298,7 +272,7 @@ public class PCMMPdpMsgSender {
                 eclassifier.setIPDestinationMask(mask);
                 eclassifier.setIPSourceMask(mask);
             } catch (UnknownHostException unae) {
-                System.out.println("Error getByName" + unae.getMessage());
+                logger.error("Error getByName", unae);
             }
             eclassifier.setSourcePortStart(PCMMGlobalConfig.srcPort);
             eclassifier.setSourcePortEnd(PCMMGlobalConfig.srcPort);
@@ -332,7 +306,7 @@ public class PCMMPdpMsgSender {
                 classifier.setSourceIPAddress(srcIP);
                 classifier.setDestinationIPAddress(dstIP);
             } catch (UnknownHostException unae) {
-                System.out.println("Error getByName" + unae.getMessage());
+                logger.error("Error getByName", unae);
             }
             classifier.setSourcePort(PCMMGlobalConfig.srcPort);
             classifier.setDestinationPort(PCMMGlobalConfig.dstPort);
@@ -345,69 +319,46 @@ public class PCMMPdpMsgSender {
         gate.setTrafficProfile(trafficProfile);
         gate.setClassifier(eclassifier);
 
-        byte[] data = gate.getData();
+        final byte[] data = gate.getData();
 
-        // new pcmm specific clientsi
-        clientSD.setData(new COPSData(data, 0, data.length));
-        try {
-            decisionMsg.add(hdr);
-            decisionMsg.add(handle);
-            // Decisions (no flags supplied)
-            // <Context>
-            COPSContext cntxt = new COPSContext(COPSContext.CONFIG, (short) 0);
-            COPSDecision install = new COPSDecision();
-            install.setCmdCode(COPSDecision.DEC_INSTALL);
-            install.setFlags(COPSDecision.F_REQERROR);
-            decisionMsg.addDecision(install, cntxt);
-            decisionMsg.add(clientSD); // setting up the gate
-            /*
-                        try {
-                            decisionMsg.dump(System.out);
-                        } catch (IOException unae) {
-                            System.out.println("Error dumping " + unae.getMessage());
-                        }
-            */
-
-        } catch (COPSException e) {
-            System.out.println("Error making Msg" + e.getMessage());
-        }
+        final Set<COPSDecision> decisionSet = new HashSet<>();
+        decisionSet.add(new COPSDecision(CType.CSI, Command.INSTALL, DecisionFlag.REQERROR,
+                new COPSData(data, 0, data.length)));
+        final Map<COPSContext, Set<COPSDecision>> decisionMap = new HashMap<>();
+        decisionMap.put(new COPSContext(RType.CONFIG, (short)0), decisionSet);
+
+        // Common Header with the same ClientType as the request
+        // Client Handle with the same clientHandle as the request
+        final COPSDecisionMsg decisionMsg = new COPSDecisionMsg(getClientType(),
+                new COPSHandle(getClientHandle().getId()), decisionMap, null);
+//                new COPSClientSI(CSIType.SIGNALED, new COPSData(data, 0, data.length)), decisionMap);
+                //                new COPSClientSI(CNum.DEC, (byte) 4, new COPSData(data, 0, data.length))); TODO - what does the value of 4 mean here???
 
         // ** Send the GateSet Decision
         // **
         try {
             decisionMsg.writeData(_sock);
         } catch (IOException e) {
-            System.out.println("Failed to send the decision, reason: "
-                               + e.getMessage());
+            logger.error("Failed to send the decision", e);
         }
 
     }
     /**
      * Sends a PCMM GateSet COPS Decision message
-     *
-     * @param
      * @throws COPSPdpException
      */
-    public void sendGateSetBestEffortWithExtendedClassifier()
-    throws COPSPdpException {
-        // Common Header with the same ClientType as the request
-
-        COPSHeader hdr = new COPSHeader(COPSHeader.COPS_OP_DEC, getClientType());
-
-        COPSDecisionMsg decisionMsg = new COPSDecisionMsg();
-
-        IPCMMGate gate = new PCMMGateReq();
-        ITransactionID trID = new TransactionID();
-
-        IAMID amid = new AMID();
-        ISubscriberID subscriberID = new SubscriberID();
-        IGateSpec gateSpec = new GateSpec();
-        IClassifier classifier = new Classifier();
-        IExtendedClassifier eclassifier = new ExtendedClassifier();
+    public void sendGateSetBestEffortWithExtendedClassifier() throws COPSPdpException {
+        final IPCMMGate gate = new PCMMGateReq();
+        final ITransactionID trID = new TransactionID();
+        final IAMID amid = new AMID();
+        final ISubscriberID subscriberID = new SubscriberID();
+        final IGateSpec gateSpec = new GateSpec();
+        final IClassifier classifier = new Classifier();
+        final IExtendedClassifier eclassifier = new ExtendedClassifier();
 
         // XXX check if other values should be provided
         //
-        ITrafficProfile trafficProfile = new BestEffortService(
+        final ITrafficProfile trafficProfile = new BestEffortService(
             (byte) 7); //BestEffortService.DEFAULT_ENVELOP);
         ((BestEffortService) trafficProfile).getAuthorizedEnvelop()
         .setTrafficPriority(BestEffortService.DEFAULT_TRAFFIC_PRIORITY);
@@ -451,17 +402,9 @@ public class PCMMPdpMsgSender {
 
 
 
-        // new pcmm specific clientsi
-        COPSClientSI clientSD = new COPSClientSI(COPSObjHeader.COPS_DEC,
-                (byte) 4);
-
-        // Client Handle with the same clientHandle as the request
-        final COPSHandle handle = new COPSHandle(getClientHandle().getId());
-
         // set transaction ID to gate set
         trID.setGateCommandType(ITransactionID.GateSet);
-        _transactionID = (short) (_transactionID == 0 ? (short) (Math.random() * hashCode())
-                                  : _transactionID);
+        _transactionID = (_transactionID == 0 ? (short) (Math.random() * hashCode()) : _transactionID);
         trID.setTransactionIdentifier(_transactionID);
 
         amid.setApplicationType((short) 1);
@@ -491,7 +434,7 @@ public class PCMMPdpMsgSender {
                 eclassifier.setIPDestinationMask(mask);
                 eclassifier.setIPSourceMask(mask);
             } catch (UnknownHostException unae) {
-                System.out.println("Error getByName" + unae.getMessage());
+                logger.error("Error getByName", unae);
             }
             eclassifier.setSourcePortStart(PCMMGlobalConfig.srcPort);
             eclassifier.setSourcePortEnd(PCMMGlobalConfig.srcPort);
@@ -525,7 +468,7 @@ public class PCMMPdpMsgSender {
                 classifier.setSourceIPAddress(srcIP);
                 classifier.setDestinationIPAddress(dstIP);
             } catch (UnknownHostException unae) {
-                System.out.println("Error getByName" + unae.getMessage());
+                logger.error("Error getByName", unae);
             }
             classifier.setSourcePort(PCMMGlobalConfig.srcPort);
             classifier.setDestinationPort(PCMMGlobalConfig.dstPort);
@@ -540,60 +483,43 @@ public class PCMMPdpMsgSender {
 
         byte[] data = gate.getData();
 
-        // new pcmm specific clientsi
-        clientSD.setData(new COPSData(data, 0, data.length));
-        try {
-            decisionMsg.add(hdr);
-            decisionMsg.add(handle);
-            // Decisions (no flags supplied)
-            // <Context>
-            COPSContext cntxt = new COPSContext(COPSContext.CONFIG, (short) 0);
-            COPSDecision install = new COPSDecision();
-            install.setCmdCode(COPSDecision.DEC_INSTALL);
-            install.setFlags(COPSDecision.F_REQERROR);
-            decisionMsg.addDecision(install, cntxt);
-            decisionMsg.add(clientSD); // setting up the gate
-            /*
-                        try {
-                            decisionMsg.dump(System.out);
-                        } catch (IOException unae) {
-                            System.out.println("Error dumping " + unae.getMessage());
-                        }
-            */
-
-        } catch (COPSException e) {
-            System.out.println("Error making Msg" + e.getMessage());
-        }
+        final Set<COPSDecision> decisionSet = new HashSet<>();
+        decisionSet.add(new COPSDecision(CType.CSI, Command.INSTALL, DecisionFlag.REQERROR, new COPSData(data, 0, data.length)));
+        final Map<COPSContext, Set<COPSDecision>> decisionMap = new HashMap<>();
+        decisionMap.put(new COPSContext(RType.CONFIG, (short)0), decisionSet);
+
+        // Common Header with the same ClientType as the request
+        // Client Handle with the same clientHandle as the request
+        final COPSDecisionMsg decisionMsg = new COPSDecisionMsg(_clientType, new COPSHandle(getClientHandle().getId()),
+                decisionMap, null);
+//                new COPSClientSI(CSIType.SIGNALED, new COPSData(data, 0, data.length)), decisionMap);
+        //                new COPSClientSI(CNum.DEC, (byte) 4, new COPSData(data, 0, data.length), null)); TODO - what does the value of 4 mean here???
 
         // ** Send the GateSet Decision
         // **
         try {
             decisionMsg.writeData(_sock);
         } catch (IOException e) {
-            System.out.println("Failed to send the decision, reason: "
-                               + e.getMessage());
+            logger.error("Failed to send the decision", e);
         }
 
     }
 
 
-    public boolean handleGateReport(Socket socket) throws COPSPdpException {
+    public boolean handleGateReport(final Socket socket) throws COPSPdpException {
         try {
             // waits for the gate-set-ack or error
-            COPSMsg responseMsg = COPSTransceiver.receiveMsg(socket);
-            if (responseMsg.getHeader().isAReport()) {
-                System.out.println("processing received report from CMTS");
-                COPSReportMsg reportMsg = (COPSReportMsg) responseMsg;
-                if (reportMsg.getClientSI().size() == 0) {
+            final COPSMsg responseMsg = COPSTransceiver.receiveMsg(socket);
+            if (responseMsg.getHeader().getOpCode().equals(OPCode.RPT)) {
+                logger.info("processing received report from CMTS");
+                final COPSReportMsg reportMsg = (COPSReportMsg) responseMsg;
+                if (reportMsg.getClientSI() == null) {
                     return false;
                 }
-                COPSClientSI clientSI = (COPSClientSI) reportMsg.getClientSI()
-                                        .elementAt(0);
-                IPCMMGate responseGate = new PCMMGateReq(clientSI.getData()
-                        .getData());
+                final IPCMMGate responseGate = new PCMMGateReq(reportMsg.getClientSI().getData().getData());
                 if (responseGate.getTransactionID() != null
                         && responseGate.getTransactionID().getGateCommandType() == ITransactionID.GateSetAck) {
-                    System.out.println("the CMTS has sent a Gate-Set-Ack response");
+                    logger.info("the CMTS has sent a Gate-Set-Ack response");
                     // here CMTS responded that he acknowledged the Gate-Set
                     // TODO do further check of Gate-Set-Ack GateID etc...
                     _gateID = responseGate.getGateID().getGateID();
@@ -612,25 +538,20 @@ public class PCMMPdpMsgSender {
     /**
      * Sends a PCMM GateSet COPS Decision message
      *
-     * @param
      * @throws COPSPdpException
      */
     public void sendGateSet() throws COPSPdpException {
         // Common Header with the same ClientType as the request
 
-        COPSHeader hdr = new COPSHeader(COPSHeader.COPS_OP_DEC, getClientType());
+        final IPCMMGate gate = new PCMMGateReq();
+        final ITransactionID trID = new TransactionID();
 
-        COPSDecisionMsg decisionMsg = new COPSDecisionMsg();
-
-        IPCMMGate gate = new PCMMGateReq();
-        ITransactionID trID = new TransactionID();
-
-        IAMID amid = new AMID();
-        ISubscriberID subscriberID = new SubscriberID();
-        IGateSpec gateSpec = new GateSpec();
-        IClassifier classifier = new Classifier();
+        final IAMID amid = new AMID();
+        final ISubscriberID subscriberID = new SubscriberID();
+        final IGateSpec gateSpec = new GateSpec();
+        final IClassifier classifier = new Classifier();
         // XXX check if other values should be provided
-        ITrafficProfile trafficProfile = new BestEffortService(
+        final ITrafficProfile trafficProfile = new BestEffortService(
             BestEffortService.DEFAULT_ENVELOP);
         ((BestEffortService) trafficProfile).getAuthorizedEnvelop()
         .setTrafficPriority(BestEffortService.DEFAULT_TRAFFIC_PRIORITY);
@@ -641,20 +562,13 @@ public class PCMMPdpMsgSender {
         .setRequestTransmissionPolicy(
             PCMMGlobalConfig.BETransmissionPolicy);
 
-        // new pcmm specific clientsi
-        COPSClientSI clientSD = new COPSClientSI(COPSObjHeader.COPS_DEC,
-                (byte) 4);
-
-        // Client Handle with the same clientHandle as the request
-        final COPSHandle handle = new COPSHandle(getClientHandle().getId());
         // byte[] content = "1234".getBytes();
 
         // handle.setId(new COPSData(content, 0, content.length));
 
         // set transaction ID to gate set
         trID.setGateCommandType(ITransactionID.GateSet);
-        _transactionID = (short) (_transactionID == 0 ? (short) (Math.random() * hashCode())
-                                  : _transactionID);
+        _transactionID = (_transactionID == 0 ? (short) (Math.random() * hashCode()) : _transactionID);
         trID.setTransactionIdentifier(_transactionID);
 
         amid.setApplicationType((short) 1);
@@ -680,7 +594,7 @@ public class PCMMPdpMsgSender {
             classifier.setSourceIPAddress(srcIP);
             classifier.setDestinationIPAddress(dstIP);
         } catch (UnknownHostException unae) {
-            System.out.println("Error getByName" + unae.getMessage());
+            logger.error("Error getByName", unae);
         }
         classifier.setSourcePort(PCMMGlobalConfig.srcPort);
         classifier.setDestinationPort(PCMMGlobalConfig.dstPort);
@@ -692,41 +606,26 @@ public class PCMMPdpMsgSender {
         gate.setTrafficProfile(trafficProfile);
         gate.setClassifier(classifier);
 
-        byte[] data = gate.getData();
+        final byte[] data = gate.getData();
 
-        // new pcmm specific clientsi
-        clientSD.setData(new COPSData(data, 0, data.length));
+        final Set<COPSDecision> decisionSet = new HashSet<>();
+        decisionSet.add(new COPSDecision(CType.CSI, Command.INSTALL,
+                DecisionFlag.REQERROR, new COPSData(data, 0, data.length)));
+        final Map<COPSContext, Set<COPSDecision>> decisionMap = new HashMap<>();
+        decisionMap.put(new COPSContext(RType.CONFIG, (short)0), decisionSet);
 
-        try {
-            decisionMsg.add(hdr);
-            decisionMsg.add(handle);
-            // Decisions (no flags supplied)
-            // <Context>
-            COPSContext cntxt = new COPSContext(COPSContext.CONFIG, (short) 0);
-            COPSDecision install = new COPSDecision();
-            install.setCmdCode(COPSDecision.DEC_INSTALL);
-            install.setFlags(COPSDecision.F_REQERROR);
-            decisionMsg.addDecision(install, cntxt);
-            decisionMsg.add(clientSD); // setting up the gate
-            /*
-                        try {
-                            decisionMsg.dump(System.out);
-                        } catch (IOException unae) {
-                            System.out.println("Error dumping " + unae.getMessage());
-                        }
-            */
-
-        } catch (COPSException e) {
-            System.out.println("Error making Msg" + e.getMessage());
-        }
+        // Client Handle with the same clientHandle as the request
+        final COPSDecisionMsg decisionMsg = new COPSDecisionMsg(getClientType(),
+                new COPSHandle(getClientHandle().getId()), decisionMap, null);
+//                new COPSClientSI(CSIType.SIGNALED, new COPSData(data, 0, data.length)), decisionMap);
+        //                new COPSClientSI(CNum.DEC, (byte) 4, new COPSData(data, 0, data.length), null));
 
         // ** Send the GateSet Decision
         // **
         try {
             decisionMsg.writeData(_sock);
         } catch (IOException e) {
-            System.out.println("Failed to send the decision, reason: "
-                               + e.getMessage());
+            logger.error("Failed to send the decision", e);
         }
 
     }
@@ -745,28 +644,17 @@ public class PCMMPdpMsgSender {
          * <Decision Header> <TransactionID> <AMID> <SubscriberID> <GateID>
          */
         // Common Header with the same ClientType as the request
-        COPSHeader hdr = new COPSHeader(COPSHeader.COPS_OP_DEC, getClientType());
-
-        // Client Handle with the same clientHandle as the request
-        COPSDecisionMsg decisionMsg = new COPSDecisionMsg();
-
-        IPCMMGate gate = new PCMMGateReq();
-        ITransactionID trID = new TransactionID();
+        final IPCMMGate gate = new PCMMGateReq();
+        final ITransactionID trID = new TransactionID();
 
-        IAMID amid = new AMID();
-        ISubscriberID subscriberID = new SubscriberID();
-        IGateSpec gateSpec = new GateSpec();
-        IGateID gateID = new GateID();
-
-        // new pcmm specific clientsi
-        COPSClientSI clientSD = new COPSClientSI(COPSObjHeader.COPS_DEC, (byte) 4);
-
-        final COPSHandle handle = new COPSHandle(getClientHandle().getId());
+        final IAMID amid = new AMID();
+        final ISubscriberID subscriberID = new SubscriberID();
+        final IGateSpec gateSpec = new GateSpec();
+        final IGateID gateID = new GateID();
 
         // set transaction ID to gate set
         trID.setGateCommandType(ITransactionID.GateDelete);
-        _transactionID = (short) (_transactionID == 0 ? (short) (Math.random() * hashCode())
-                                  : _transactionID);
+        _transactionID = (_transactionID == 0 ? (short) (Math.random() * hashCode()) : _transactionID);
         trID.setTransactionIdentifier(_transactionID);
 
         amid.setApplicationType((short) 1);
@@ -777,7 +665,7 @@ public class PCMMPdpMsgSender {
             InetAddress subIP = InetAddress.getByName(PCMMGlobalConfig.SubscriberID);
             subscriberID.setSourceIPAddress(subIP);
         } catch (UnknownHostException unae) {
-            System.out.println("Error getByName" + unae.getMessage());
+            logger.error("Error getByName", unae);
         }
 
         gate.setTransactionID(trID);
@@ -786,33 +674,18 @@ public class PCMMPdpMsgSender {
         gate.setGateID(gateID);
 
         // XXX - GateID
-        byte[] data = gate.getData();
+        final byte[] data = gate.getData();
 
-        // new pcmm specific clientsi
-        clientSD.setData(new COPSData(data, 0, data.length));
+        final Set<COPSDecision> decisionSet = new HashSet<>();
+        decisionSet.add(new COPSDecision(CType.CSI, Command.INSTALL, DecisionFlag.REQERROR,
+                new COPSData(data, 0, data.length)));
+        final Map<COPSContext, Set<COPSDecision>> decisionMap = new HashMap<>();
+        decisionMap.put(new COPSContext(RType.CONFIG, (short)0), decisionSet);
 
-        try {
-            decisionMsg.add(hdr);
-            decisionMsg.add(handle);
-            // Decisions (no flags supplied)
-            // <Context>
-            COPSContext cntxt = new COPSContext(COPSContext.CONFIG, (short) 0);
-            COPSDecision install = new COPSDecision();
-            install.setCmdCode(COPSDecision.DEC_INSTALL);
-            install.setFlags(COPSDecision.F_REQERROR);
-            decisionMsg.addDecision(install, cntxt);
-            decisionMsg.add(clientSD); // setting up the gate
-            /*
-                        try {
-                            decisionMsg.dump(System.out);
-                        } catch (IOException unae) {
-                            System.out.println("Error dumping " + unae.getMessage());
-                        }
-            */
-
-        } catch (COPSException e) {
-            System.out.println("Error making Msg" + e.getMessage());
-        }
+        final COPSDecisionMsg decisionMsg = new COPSDecisionMsg(getClientType(),
+                new COPSHandle(getClientHandle().getId()), decisionMap, null);
+//                new COPSClientSI(CSIType.SIGNALED, new COPSData(data, 0, data.length)), decisionMap);
+        //                new COPSClientSI(CNum.DEC, (byte) 4, new COPSData(data, 0, data.length), null));
 
         // ** Send the GateDelete Decision
         // **
@@ -820,8 +693,7 @@ public class PCMMPdpMsgSender {
             decisionMsg.writeData(_sock);
             // decisionMsg.writeData(socket_id);
         } catch (IOException e) {
-            System.out.println("Failed to send the decision, reason: "
-                               + e.getMessage());
+            logger.error("Failed to send the decision", e);
         }
     }
 
@@ -837,29 +709,13 @@ public class PCMMPdpMsgSender {
          * <Decision: Flags> <Decision: Flags> ::= Install Request-State
          */
 
-        // Common Header with the same ClientType as the request (default
-        // UNSOLICITED)
-        COPSHeader hdr = new COPSHeader(COPSHeader.COPS_OP_DEC, getClientType());
-
-        // Client Handle with the same clientHandle as the request
-        final COPSHandle clienthandle = new COPSHandle(_handle.getId());
+        final Set<COPSDecision> decisionSet = new HashSet<>();
+        decisionSet.add(new COPSDecision(Command.INSTALL, DecisionFlag.REQSTATE));
+        final Map<COPSContext, Set<COPSDecision>> decisionMap = new HashMap<>();
+        decisionMap.put(new COPSContext(RType.CONFIG, (short)0), decisionSet);
 
-        // Decisions
-        // <Context>
-        COPSContext cntxt = new COPSContext(COPSContext.CONFIG, (short) 0);
-        // <Decision: Flags>
-        COPSDecision dec = new COPSDecision();
-        dec.setCmdCode(COPSDecision.DEC_INSTALL);
-        dec.setFlags(COPSDecision.F_REQSTATE);
-
-        COPSDecisionMsg decisionMsg = new COPSDecisionMsg();
-        try {
-            decisionMsg.add(hdr);
-            decisionMsg.add(clienthandle);
-            decisionMsg.addDecision(dec, cntxt);
-        } catch (COPSException e) {
-            throw new COPSPdpException("Error making Msg");
-        }
+        final COPSDecisionMsg decisionMsg = new COPSDecisionMsg(getClientType(), new COPSHandle(_handle.getId()),
+                decisionMap, null);
 
         try {
             decisionMsg.writeData(_sock);
@@ -879,21 +735,7 @@ public class PCMMPdpMsgSender {
         /*
          * <Gate-Info> ::= <Common Header> [<Client Handle>] [<Integrity>]
          */
-
-        // Common Header with the same ClientType as the request
-        COPSHeader hdr = new COPSHeader(COPSHeader.COPS_OP_SSQ, getClientType());
-
-        // Client Handle with the same clientHandle as the request
-        final COPSHandle clienthandle = new COPSHandle(_handle.getId());
-
-        COPSSyncStateMsg msg = new COPSSyncStateMsg();
-        try {
-            msg.add(hdr);
-            msg.add(clienthandle);
-        } catch (Exception e) {
-            throw new COPSPdpException("Error making Msg");
-        }
-
+        final COPSSyncStateMsg msg = new COPSSyncStateMsg(getClientType(), new COPSHandle(_handle.getId()), null);
         try {
             msg.writeData(_sock);
         } catch (IOException e) {
@@ -914,20 +756,8 @@ public class PCMMPdpMsgSender {
          * [<Integrity>]
          */
 
-        // Common Header with the same ClientType as the request
-        COPSHeader hdr = new COPSHeader(COPSHeader.COPS_OP_SSQ, getClientType());
-
         // Client Handle with the same clientHandle as the request
-        final COPSHandle clienthandle = new COPSHandle(_handle.getId());
-
-        COPSSyncStateMsg msg = new COPSSyncStateMsg();
-        try {
-            msg.add(hdr);
-            msg.add(clienthandle);
-        } catch (Exception e) {
-            throw new COPSPdpException("Error making Msg");
-        }
-
+        final COPSSyncStateMsg msg = new COPSSyncStateMsg(getClientType(), new COPSHandle(_handle.getId()), null);
         try {
             msg.writeData(_sock);
         } catch (IOException e) {