Bump to odlparent 3.1.0 and yangtools 2.0.3
[packetcable.git] / packetcable-driver / src / main / java / org / pcmm / PCMMPdpMsgSender.java
index 770a578fadd5b80989dfcde8329524cb981e1234..aa86745462ab5276577d4e8f7465e0c546501cba 100644 (file)
@@ -1,34 +1,38 @@
-/**
- @header@
+/*
+ * Copyright (c) 2014, 2015 Cable Television Laboratories, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
 
 package org.pcmm;
 
-import org.pcmm.gates.*;
-import org.pcmm.gates.IGateSpec.DSCPTOS;
-import org.pcmm.gates.IGateSpec.Direction;
-import org.pcmm.gates.impl.*;
+import org.pcmm.gates.IGateID;
+import org.pcmm.gates.IPCMMGate;
+import org.pcmm.gates.ITransactionID;
+import org.pcmm.gates.ITransactionID.GateCommandType;
+import org.pcmm.gates.impl.PCMMGateReq;
+import org.pcmm.gates.impl.TransactionID;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.umu.cops.COPSMsgSender;
 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.OPCode;
+import org.umu.cops.stack.COPSObjHeader.CNum;
 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
 /*
  * Example of an UNSOLICITED decision
  *
@@ -44,33 +48,16 @@ import java.util.Set;
 /**
  * COPS message transceiver class for provisioning connections at the PDP side.
  */
-public class PCMMPdpMsgSender {
+public class PCMMPdpMsgSender extends COPSMsgSender {
 
     public final static Logger logger = LoggerFactory.getLogger(PCMMPdpMsgSender.class);
-
-    /**
-     * Socket connected to PEP
-     */
-    protected Socket _sock;
-
-    /**
-     * COPS client-type that identifies the policy client
-     */
-    protected short _clientType;
-
-    /**
-     * COPS client handle used to uniquely identify a particular PEP's request
-     * for a client-type
-     */
-    protected COPSHandle _handle;
-
-    /**
-     *
-     */
+       private static final int MAX_TRANSACTION_ID = 65_536;
+       
     protected short _transactionID;
-    protected short _classifierID;
+    protected final short _classifierID;
+
     // XXX - this does not need to be here
-    protected int _gateID;
+    protected IGateID _gateID;
 
     /**
      * Creates a PCMMPdpMsgSender
@@ -83,68 +70,42 @@ public class PCMMPdpMsgSender {
      *            Socket to the PEP
      */
     public PCMMPdpMsgSender(final short clientType, final COPSHandle clientHandle, final Socket sock) {
-        // COPS Handle
-        _handle = clientHandle;
-        _clientType = clientType;
-
-        _transactionID = 0;
-        _classifierID = 0;
-        _sock = sock;
+        this(clientType, (short)0, clientHandle, sock);
     }
 
     public PCMMPdpMsgSender(final short clientType, final short tID, final COPSHandle clientHandle,
                             final Socket sock) {
-        // COPS Handle
-        _handle = clientHandle;
-        _clientType = clientType;
-        _transactionID = tID;
+        super(clientType, clientHandle, sock);
+        _transactionID = tID == 0 ? generateNewTransactionID() : tID;
         _classifierID = 0;
-        _sock = sock;
-    }
-
-    /**
-     * Gets the client handle
-     *
-     * @return Client's <tt>COPSHandle</tt>
-     */
-    public COPSHandle getClientHandle() {
-        return _handle;
     }
 
     /**
-     * Gets the client-type
+     * Gets the gate-id
      *
-     * @return Client-type value
+     * @return the gate-id value
      */
-    public short getClientType() {
-        return _clientType;
+    public IGateID getGateID() {
+        return _gateID;
     }
 
-    /**
-     * Gets the transaction-id
-     *
-     * @return transaction-id value
-     */
-    public short getTransactionID() {
-        return _transactionID;
-    }
-
-
     /**
      * Sends a PCMM GateSet COPS Decision message
      * @param gate - the gate
      * @throws COPSPdpException
      */
     public void sendGateSet(final IPCMMGate gate) throws COPSPdpException {
-        final ITransactionID trID = new TransactionID();
-
         // set transaction ID to gate set
-        trID.setGateCommandType(ITransactionID.GateSet);
-        _transactionID = (_transactionID == 0 ? (short) (Math.random() * hashCode()) : _transactionID);
-        trID.setTransactionIdentifier(_transactionID);
-
+       // generate a new TransactionID
+       _transactionID = generateNewTransactionID();
+        final ITransactionID trID = new TransactionID(_transactionID, GateCommandType.GATE_SET);
+       
         gate.setTransactionID(trID);
-
+        // retain the transactitrIDnumonId to gate request mapping for gateID recovery after response
+        // see PCMMPdpReqStateMan.processReport()
+        final Short trIDnum = trID.getTransactionIdentifier();
+        logger.info("Adding gate to cache - " + gate + " with key - " + (int) (trIDnum & 0xffff));
+        PCMMGlobalConfig.transactionGateMap.put(trIDnum, gate);
 
         // new pcmm specific clientsi
         final byte[] data = gate.getData();
@@ -152,350 +113,14 @@ public class PCMMPdpMsgSender {
         // 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) {
-            logger.error("Failed to send the decision", e);
-        }
-
-    }
-
-    /**
-     * Sends a PCMM GateSet COPS Decision message
-     *
-     * @param num - the number
-     * @throws COPSPdpException
-     */
-    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;
-        else
-            trafficRate =   PCMMGlobalConfig.DefaultLowBestEffortTrafficRate;
-
-        final ITrafficProfile trafficProfile = new BestEffortService(
-            (byte) 7); //BestEffortService.DEFAULT_ENVELOP);
-        ((BestEffortService) trafficProfile).getAuthorizedEnvelop()
-        .setTrafficPriority(BestEffortService.DEFAULT_TRAFFIC_PRIORITY);
-        ((BestEffortService) trafficProfile).getAuthorizedEnvelop()
-        .setMaximumTrafficBurst(
-            BestEffortService.DEFAULT_MAX_TRAFFIC_BURST);
-        ((BestEffortService) trafficProfile).getAuthorizedEnvelop()
-        .setRequestTransmissionPolicy(
-            PCMMGlobalConfig.BETransmissionPolicy);
-        ((BestEffortService) trafficProfile).getAuthorizedEnvelop()
-        .setMaximumSustainedTrafficRate(
-            trafficRate);
-        //  PCMMGlobalConfig.DefaultLowBestEffortTrafficRate );
-        //  PCMMGlobalConfig.DefaultBestEffortTrafficRate);
-
-        ((BestEffortService) trafficProfile).getReservedEnvelop()
-        .setTrafficPriority(BestEffortService.DEFAULT_TRAFFIC_PRIORITY);
-        ((BestEffortService) trafficProfile).getReservedEnvelop()
-        .setMaximumTrafficBurst(
-            BestEffortService.DEFAULT_MAX_TRAFFIC_BURST);
-        ((BestEffortService) trafficProfile).getReservedEnvelop()
-        .setRequestTransmissionPolicy(
-            PCMMGlobalConfig.BETransmissionPolicy);
-        ((BestEffortService) trafficProfile).getReservedEnvelop()
-        .setMaximumSustainedTrafficRate(
-            trafficRate);
-        //  PCMMGlobalConfig.DefaultLowBestEffortTrafficRate );
-        //  PCMMGlobalConfig.DefaultBestEffortTrafficRate);
-
-
-        ((BestEffortService) trafficProfile).getCommittedEnvelop()
-        .setTrafficPriority(BestEffortService.DEFAULT_TRAFFIC_PRIORITY);
-        ((BestEffortService) trafficProfile).getCommittedEnvelop()
-        .setMaximumTrafficBurst(
-            BestEffortService.DEFAULT_MAX_TRAFFIC_BURST);
-        ((BestEffortService) trafficProfile).getCommittedEnvelop()
-        .setRequestTransmissionPolicy(
-            PCMMGlobalConfig.BETransmissionPolicy);
-        ((BestEffortService) trafficProfile).getCommittedEnvelop()
-        .setMaximumSustainedTrafficRate(
-            trafficRate);
-        //  PCMMGlobalConfig.DefaultLowBestEffortTrafficRate );
-        //  PCMMGlobalConfig.DefaultBestEffortTrafficRate);
-
-
-
-        // set transaction ID to gate set
-        trID.setGateCommandType(ITransactionID.GateSet);
-        _transactionID = (_transactionID == 0 ? (short) (Math.random() * hashCode()) : _transactionID);
-        trID.setTransactionIdentifier(_transactionID);
-
-        amid.setApplicationType((short) 1);
-        amid.setApplicationMgrTag((short) 1);
-        gateSpec.setDirection(Direction.UPSTREAM);
-        gateSpec.setDSCP_TOSOverwrite(DSCPTOS.OVERRIDE);
-        gateSpec.setTimerT1(PCMMGlobalConfig.GateT1);
-        gateSpec.setTimerT2(PCMMGlobalConfig.GateT2);
-        gateSpec.setTimerT3(PCMMGlobalConfig.GateT3);
-        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);
-            try {
-                InetAddress subIP = InetAddress
-                                    .getByName(PCMMGlobalConfig.SubscriberID);
-                InetAddress srcIP = InetAddress
-                                    .getByName(PCMMGlobalConfig.srcIP);
-                InetAddress dstIP = InetAddress
-                                    .getByName(PCMMGlobalConfig.dstIP);
-                InetAddress mask = InetAddress.getByName("0.0.0.0");
-                subscriberID.setSourceIPAddress(subIP);
-                eclassifier.setSourceIPAddress(srcIP);
-                eclassifier.setDestinationIPAddress(dstIP);
-                eclassifier.setIPDestinationMask(mask);
-                eclassifier.setIPSourceMask(mask);
-            } catch (UnknownHostException unae) {
-                logger.error("Error getByName", unae);
-            }
-            eclassifier.setSourcePortStart(PCMMGlobalConfig.srcPort);
-            eclassifier.setSourcePortEnd(PCMMGlobalConfig.srcPort);
-            eclassifier.setDestinationPortStart(PCMMGlobalConfig.dstPort);
-            eclassifier.setDestinationPortEnd(PCMMGlobalConfig.dstPort);
-            eclassifier.setActivationState((byte) 0x01);
-            // check if we have a stored value of classifierID else we just
-            // create
-            // one
-            // eclassifier.setClassifierID((short) 0x01);
-            eclassifier.setClassifierID((short) (_classifierID == 0 ? Math
-                                                 .random() * hashCode() : _classifierID));
-            // XXX - testie
-            // eclassifier.setClassifierID((short) 1);
-
-            eclassifier.setAction((byte) 0x00);
-            // XXX - temp default until Gate Modify is hacked in
-            // eclassifier.setPriority(PCMMGlobalConfig.EClassifierPriority);
-            eclassifier.setPriority((byte) 65);
-
-        } else {
-            classifier.setProtocol(IClassifier.Protocol.TCP);
-            try {
-                InetAddress subIP = InetAddress
-                                    .getByName(PCMMGlobalConfig.SubscriberID);
-                InetAddress srcIP = InetAddress
-                                    .getByName(PCMMGlobalConfig.srcIP);
-                InetAddress dstIP = InetAddress
-                                    .getByName(PCMMGlobalConfig.dstIP);
-                subscriberID.setSourceIPAddress(subIP);
-                classifier.setSourceIPAddress(srcIP);
-                classifier.setDestinationIPAddress(dstIP);
-            } catch (UnknownHostException unae) {
-                logger.error("Error getByName", unae);
-            }
-            classifier.setSourcePort(PCMMGlobalConfig.srcPort);
-            classifier.setDestinationPort(PCMMGlobalConfig.dstPort);
-        }
-
-        gate.setTransactionID(trID);
-        gate.setAMID(amid);
-        gate.setSubscriberID(subscriberID);
-        gate.setGateSpec(gateSpec);
-        gate.setTrafficProfile(trafficProfile);
-        gate.setClassifier(eclassifier);
-
-        final byte[] data = gate.getData();
-
-        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) {
-            logger.error("Failed to send the decision", e);
-        }
-
-    }
-    /**
-     * Sends a PCMM GateSet COPS Decision message
-     * @throws COPSPdpException
-     */
-    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
-        //
-        final ITrafficProfile trafficProfile = new BestEffortService(
-            (byte) 7); //BestEffortService.DEFAULT_ENVELOP);
-        ((BestEffortService) trafficProfile).getAuthorizedEnvelop()
-        .setTrafficPriority(BestEffortService.DEFAULT_TRAFFIC_PRIORITY);
-        ((BestEffortService) trafficProfile).getAuthorizedEnvelop()
-        .setMaximumTrafficBurst(
-            BestEffortService.DEFAULT_MAX_TRAFFIC_BURST);
-        ((BestEffortService) trafficProfile).getAuthorizedEnvelop()
-        .setRequestTransmissionPolicy(
-            PCMMGlobalConfig.BETransmissionPolicy);
-        ((BestEffortService) trafficProfile).getAuthorizedEnvelop()
-        .setMaximumSustainedTrafficRate(
-            PCMMGlobalConfig.DefaultLowBestEffortTrafficRate );
-        //  PCMMGlobalConfig.DefaultBestEffortTrafficRate);
-
-        ((BestEffortService) trafficProfile).getReservedEnvelop()
-        .setTrafficPriority(BestEffortService.DEFAULT_TRAFFIC_PRIORITY);
-        ((BestEffortService) trafficProfile).getReservedEnvelop()
-        .setMaximumTrafficBurst(
-            BestEffortService.DEFAULT_MAX_TRAFFIC_BURST);
-        ((BestEffortService) trafficProfile).getReservedEnvelop()
-        .setRequestTransmissionPolicy(
-            PCMMGlobalConfig.BETransmissionPolicy);
-        ((BestEffortService) trafficProfile).getReservedEnvelop()
-        .setMaximumSustainedTrafficRate(
-            PCMMGlobalConfig.DefaultLowBestEffortTrafficRate );
-        //  PCMMGlobalConfig.DefaultBestEffortTrafficRate);
-
-
-        ((BestEffortService) trafficProfile).getCommittedEnvelop()
-        .setTrafficPriority(BestEffortService.DEFAULT_TRAFFIC_PRIORITY);
-        ((BestEffortService) trafficProfile).getCommittedEnvelop()
-        .setMaximumTrafficBurst(
-            BestEffortService.DEFAULT_MAX_TRAFFIC_BURST);
-        ((BestEffortService) trafficProfile).getCommittedEnvelop()
-        .setRequestTransmissionPolicy(
-            PCMMGlobalConfig.BETransmissionPolicy);
-        ((BestEffortService) trafficProfile).getCommittedEnvelop()
-        .setMaximumSustainedTrafficRate(
-            PCMMGlobalConfig.DefaultLowBestEffortTrafficRate );
-        //  PCMMGlobalConfig.DefaultBestEffortTrafficRate);
-
-
-
-        // set transaction ID to gate set
-        trID.setGateCommandType(ITransactionID.GateSet);
-        _transactionID = (_transactionID == 0 ? (short) (Math.random() * hashCode()) : _transactionID);
-        trID.setTransactionIdentifier(_transactionID);
-
-        amid.setApplicationType((short) 1);
-        amid.setApplicationMgrTag((short) 1);
-        gateSpec.setDirection(Direction.UPSTREAM);
-        gateSpec.setDSCP_TOSOverwrite(DSCPTOS.OVERRIDE);
-        gateSpec.setTimerT1(PCMMGlobalConfig.GateT1);
-        gateSpec.setTimerT2(PCMMGlobalConfig.GateT2);
-        gateSpec.setTimerT3(PCMMGlobalConfig.GateT3);
-        gateSpec.setTimerT4(PCMMGlobalConfig.GateT4);
-
-        // XXX - if the version major is less than 4 we need to use Classifier
-        if (true) {
-            //eclassifier.setProtocol(IClassifier.Protocol.NONE);
-            eclassifier.setProtocol(IClassifier.Protocol.TCP);
-            try {
-                InetAddress subIP = InetAddress
-                                    .getByName(PCMMGlobalConfig.SubscriberID);
-                InetAddress srcIP = InetAddress
-                                    .getByName(PCMMGlobalConfig.srcIP);
-                InetAddress dstIP = InetAddress
-                                    .getByName(PCMMGlobalConfig.dstIP);
-                InetAddress mask = InetAddress.getByName("0.0.0.0");
-                subscriberID.setSourceIPAddress(subIP);
-                eclassifier.setSourceIPAddress(srcIP);
-                eclassifier.setDestinationIPAddress(dstIP);
-                eclassifier.setIPDestinationMask(mask);
-                eclassifier.setIPSourceMask(mask);
-            } catch (UnknownHostException unae) {
-                logger.error("Error getByName", unae);
-            }
-            eclassifier.setSourcePortStart(PCMMGlobalConfig.srcPort);
-            eclassifier.setSourcePortEnd(PCMMGlobalConfig.srcPort);
-            eclassifier.setDestinationPortStart(PCMMGlobalConfig.dstPort);
-            eclassifier.setDestinationPortEnd(PCMMGlobalConfig.dstPort);
-            eclassifier.setActivationState((byte) 0x01);
-            // check if we have a stored value of classifierID else we just
-            // create
-            // one
-            // eclassifier.setClassifierID((short) 0x01);
-            eclassifier.setClassifierID((short) (_classifierID == 0 ? Math
-                                                 .random() * hashCode() : _classifierID));
-            // XXX - testie
-            // eclassifier.setClassifierID((short) 1);
-
-            eclassifier.setAction((byte) 0x00);
-            // XXX - temp default until Gate Modify is hacked in
-            // eclassifier.setPriority(PCMMGlobalConfig.EClassifierPriority);
-            eclassifier.setPriority((byte) 65);
-
-        } else {
-            classifier.setProtocol(IClassifier.Protocol.TCP);
-            try {
-                InetAddress subIP = InetAddress
-                                    .getByName(PCMMGlobalConfig.SubscriberID);
-                InetAddress srcIP = InetAddress
-                                    .getByName(PCMMGlobalConfig.srcIP);
-                InetAddress dstIP = InetAddress
-                                    .getByName(PCMMGlobalConfig.dstIP);
-                subscriberID.setSourceIPAddress(subIP);
-                classifier.setSourceIPAddress(srcIP);
-                classifier.setDestinationIPAddress(dstIP);
-            } catch (UnknownHostException unae) {
-                logger.error("Error getByName", unae);
-            }
-            classifier.setSourcePort(PCMMGlobalConfig.srcPort);
-            classifier.setDestinationPort(PCMMGlobalConfig.dstPort);
-        }
-
-        gate.setTransactionID(trID);
-        gate.setAMID(amid);
-        gate.setSubscriberID(subscriberID);
-        gate.setGateSpec(gateSpec);
-        gate.setTrafficProfile(trafficProfile);
-        gate.setClassifier(eclassifier);
-
-        byte[] data = gate.getData();
-
-        final Set<COPSDecision> decisionSet = new HashSet<>();
-        decisionSet.add(new COPSDecision(CType.CSI, Command.INSTALL, DecisionFlag.REQERROR, new COPSData(data, 0, data.length)));
+        decisionSet.add(new COPSDecision(CType.DEF, Command.INSTALL, DecisionFlag.REQERROR));
         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???
+        final COPSClientSI clientSD = new COPSClientSI(CNum.DEC, CType.CSI, new COPSData(data, 0, data.length));
+        final COPSDecisionMsg decisionMsg = new COPSDecisionMsg(_clientType, _handle, decisionMap, null, clientSD);
 
         // ** Send the GateSet Decision
-        // **
         try {
             decisionMsg.writeData(_sock);
         } catch (IOException e) {
@@ -504,7 +129,6 @@ public class PCMMPdpMsgSender {
 
     }
 
-
     public boolean handleGateReport(final Socket socket) throws COPSPdpException {
         try {
             // waits for the gate-set-ack or error
@@ -515,13 +139,13 @@ public class PCMMPdpMsgSender {
                 if (reportMsg.getClientSI() == null) {
                     return false;
                 }
-                final IPCMMGate responseGate = new PCMMGateReq(reportMsg.getClientSI().getData().getData());
+                final IPCMMGate responseGate = PCMMGateReq.parse(reportMsg.getClientSI().getData().getData());
                 if (responseGate.getTransactionID() != null
-                        && responseGate.getTransactionID().getGateCommandType() == ITransactionID.GateSetAck) {
+                        && responseGate.getTransactionID().getGateCommandType().equals(GateCommandType.GATE_SET_ACK)) {
                     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();
+                    _gateID = responseGate.getGateID();
                     return true;
                 } else {
                     return false;
@@ -529,162 +153,44 @@ public class PCMMPdpMsgSender {
             }
             return false;
         } catch (Exception e) { // COPSException, IOException
-            throw new COPSPdpException("Error COPSTransceiver.receiveMsg");
+            throw new COPSPdpException("Error COPSTransceiver.receiveMsg", e);
         }
     }
 
 
-    /**
-     * Sends a PCMM GateSet COPS Decision message
-     *
-     * @throws COPSPdpException
-     */
-    public void sendGateSet() throws COPSPdpException {
-        // Common Header with the same ClientType as the request
-
-        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();
-        // XXX check if other values should be provided
-        final ITrafficProfile trafficProfile = new BestEffortService(
-            BestEffortService.DEFAULT_ENVELOP);
-        ((BestEffortService) trafficProfile).getAuthorizedEnvelop()
-        .setTrafficPriority(BestEffortService.DEFAULT_TRAFFIC_PRIORITY);
-        ((BestEffortService) trafficProfile).getAuthorizedEnvelop()
-        .setMaximumTrafficBurst(
-            BestEffortService.DEFAULT_MAX_TRAFFIC_BURST);
-        ((BestEffortService) trafficProfile).getAuthorizedEnvelop()
-        .setRequestTransmissionPolicy(
-            PCMMGlobalConfig.BETransmissionPolicy);
-
-        // byte[] content = "1234".getBytes();
-
-        // handle.setId(new COPSData(content, 0, content.length));
-
-        // set transaction ID to gate set
-        trID.setGateCommandType(ITransactionID.GateSet);
-        _transactionID = (_transactionID == 0 ? (short) (Math.random() * hashCode()) : _transactionID);
-        trID.setTransactionIdentifier(_transactionID);
-
-        amid.setApplicationType((short) 1);
-        amid.setApplicationMgrTag((short) 1);
-        gateSpec.setDirection(Direction.UPSTREAM);
-        gateSpec.setDSCP_TOSOverwrite(DSCPTOS.OVERRIDE);
-        gateSpec.setTimerT1(PCMMGlobalConfig.GateT1);
-        gateSpec.setTimerT2(PCMMGlobalConfig.GateT2);
-        gateSpec.setTimerT3(PCMMGlobalConfig.GateT3);
-        gateSpec.setTimerT4(PCMMGlobalConfig.GateT4);
-
-        /*
-         * ((DOCSISServiceClassNameTrafficProfile) trafficProfile)
-         * .setServiceClassName("S_up");
-         */
-
-        classifier.setProtocol(IClassifier.Protocol.TCP);
-        try {
-            InetAddress subIP = InetAddress.getByName(PCMMGlobalConfig.SubscriberID);
-            InetAddress srcIP = InetAddress.getByName(PCMMGlobalConfig.srcIP);
-            InetAddress dstIP = InetAddress.getByName(PCMMGlobalConfig.dstIP);
-            subscriberID.setSourceIPAddress(subIP);
-            classifier.setSourceIPAddress(srcIP);
-            classifier.setDestinationIPAddress(dstIP);
-        } catch (UnknownHostException unae) {
-            logger.error("Error getByName", unae);
-        }
-        classifier.setSourcePort(PCMMGlobalConfig.srcPort);
-        classifier.setDestinationPort(PCMMGlobalConfig.dstPort);
-
-        gate.setTransactionID(trID);
-        gate.setAMID(amid);
-        gate.setSubscriberID(subscriberID);
-        gate.setGateSpec(gateSpec);
-        gate.setTrafficProfile(trafficProfile);
-        gate.setClassifier(classifier);
-
-        final byte[] data = gate.getData();
-
-        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);
-
-        // 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) {
-            logger.error("Failed to send the decision", e);
-        }
-
-    }
-
     /**
      * Sends a message asking that the request state be deleted
      *
      * @throws COPSPdpException
      */
-    public void sendGateDelete(int gID) throws COPSPdpException {
-        /*
-         * Example of an UNSOLICITED decision <Gate Control Command> = <COPS
-         * Common Header> <Client Handle> <Context> <Decision Flags> <ClientSI
-         * Data> <ClientSI Data> = <Gate-Set> | <Gate-Info> | <Gate-Delete> |
-         * <PDP-Config> | <Synch-Request> | <Msg-Receipt> <Gate-Delete> =
-         * <Decision Header> <TransactionID> <AMID> <SubscriberID> <GateID>
-         */
-        // Common Header with the same ClientType as the request
-        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 IGateID gateID = new GateID();
-
+    public void sendGateDelete(final IPCMMGate gate) throws COPSPdpException {
         // set transaction ID to gate set
-        trID.setGateCommandType(ITransactionID.GateDelete);
-        _transactionID = (_transactionID == 0 ? (short) (Math.random() * hashCode()) : _transactionID);
-        trID.setTransactionIdentifier(_transactionID);
-
-        amid.setApplicationType((short) 1);
-        amid.setApplicationMgrTag((short) 1);
-        gateID.setGateID(gID);
-
-        try {
-            InetAddress subIP = InetAddress.getByName(PCMMGlobalConfig.SubscriberID);
-            subscriberID.setSourceIPAddress(subIP);
-        } catch (UnknownHostException unae) {
-            logger.error("Error getByName", unae);
-        }
-
-        gate.setTransactionID(trID);
-        gate.setAMID(amid);
-        gate.setSubscriberID(subscriberID);
-        gate.setGateID(gateID);
+        // generate a new TransactionID
+       short _transactionID = generateNewTransactionID();
+        final ITransactionID trID = new TransactionID(_transactionID, GateCommandType.GATE_DELETE);
+        
+       gate.setTransactionID(trID);
+
+        Short trIDnum = trID.getTransactionIdentifier();
+        PCMMGlobalConfig.transactionGateMap.put(trIDnum, gate);
+
+        // gateDelete only requires AMID, subscriberID, and gateID
+        // remove the gateSpec, traffic profile, and classifiers from original gate request
+        gate.setGateSpec(null);
+        gate.setTrafficProfile(null);
+        gate.setClassifiers(null);
+        // clear the error object
+        gate.setError(null);
 
         // XXX - GateID
         final byte[] data = gate.getData();
-
         final Set<COPSDecision> decisionSet = new HashSet<>();
-        decisionSet.add(new COPSDecision(CType.CSI, Command.INSTALL, DecisionFlag.REQERROR,
-                new COPSData(data, 0, data.length)));
+        decisionSet.add(new COPSDecision(CType.DEF, Command.INSTALL, DecisionFlag.REQERROR));
         final Map<COPSContext, Set<COPSDecision>> decisionMap = new HashMap<>();
-        decisionMap.put(new COPSContext(RType.CONFIG, (short) 0), decisionSet);
+        decisionMap.put(new COPSContext(RType.CONFIG, (short)0), decisionSet);
+        final COPSClientSI clientSD = new COPSClientSI(CNum.DEC, CType.CSI, new COPSData(data, 0, data.length));
 
-        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));
+        final COPSDecisionMsg decisionMsg = new COPSDecisionMsg(getClientType(), _handle, decisionMap, null, clientSD);
 
         // ** Send the GateDelete Decision
         // **
@@ -713,15 +219,12 @@ public class PCMMPdpMsgSender {
         final Map<COPSContext, Set<COPSDecision>> decisionMap = new HashMap<>();
         decisionMap.put(new COPSContext(RType.CONFIG, (short)0), decisionSet);
 
-        final COPSDecisionMsg decisionMsg = new COPSDecisionMsg(getClientType(), new COPSHandle(_handle.getId()),
-                decisionMap, null);
+        final COPSDecisionMsg decisionMsg = new COPSDecisionMsg(getClientType(), _handle, decisionMap, null, null);
 
         try {
             decisionMsg.writeData(_sock);
         } catch (IOException e) {
-            throw new COPSPdpException(
-                "Failed to send the open new request state, reason: "
-                + e.getMessage());
+            throw new COPSPdpException("Failed to send the open new request state", e);
         }
     }
 
@@ -730,17 +233,49 @@ public class PCMMPdpMsgSender {
      *
      * @throws COPSPdpException
      */
-    public void sendGateInfo() throws COPSPdpException {
+    public void sendGateInfo(final IPCMMGate gate) throws COPSPdpException {
         /*
          * <Gate-Info> ::= <Common Header> [<Client Handle>] [<Integrity>]
          */
-        final COPSSyncStateMsg msg = new COPSSyncStateMsg(getClientType(), new COPSHandle(_handle.getId()), null);
+       
+       // added
+        // generate a new TransactionID
+       short _transactionID = generateNewTransactionID();
+       final ITransactionID trID = new TransactionID(_transactionID, GateCommandType.GATE_INFO);
+        
+        
+        gate.setTransactionID(trID);
+        // retain the transactionId to gate request mapping for gateID recovery after response
+        // see PCMMPdpReqStateMan.processReport()
+        final Short trIDnum = trID.getTransactionIdentifier();
+        logger.info("Adding gate to cache - " + gate + " with key - " + (int) (trIDnum & 0xffff));
+        PCMMGlobalConfig.transactionGateMap.put(trIDnum, gate);
+        
+        // gateDelete only requires AMID, subscriberID, and gateID
+        // remove the gateSpec, traffic profile, and classifiers from original gate request
+        gate.setGateSpec(null);
+        gate.setTrafficProfile(null);
+        gate.setClassifiers(null);
+        // clear the error object
+        gate.setError(null);
+        
+        
+        // XXX - GateID
+        final byte[] data = gate.getData();
+        final Set<COPSDecision> decisionSet = new HashSet<>();
+        decisionSet.add(new COPSDecision(CType.DEF, Command.INSTALL, DecisionFlag.REQERROR));
+        final Map<COPSContext, Set<COPSDecision>> decisionMap = new HashMap<>();
+        decisionMap.put(new COPSContext(RType.CONFIG, (short)0), decisionSet);
+        final COPSClientSI clientSD = new COPSClientSI(CNum.DEC, CType.CSI, new COPSData(data, 0, data.length));
+       
+        //final COPSSyncStateMsg msg = new COPSSyncStateMsg(getClientType(), _handle, null);
+        final COPSDecisionMsg decisionMsg = new COPSDecisionMsg(getClientType(), _handle, decisionMap, null, clientSD);
+        
         try {
-            msg.writeData(_sock);
+            //msg.writeData(_sock);
+            decisionMsg.writeData(_sock);
         } catch (IOException e) {
-            throw new COPSPdpException(
-                "Failed to send the GateInfo request, reason: "
-                + e.getMessage());
+            throw new COPSPdpException("Failed to send the GateInfo request", e);
         }
     }
 
@@ -756,13 +291,11 @@ public class PCMMPdpMsgSender {
          */
 
         // Client Handle with the same clientHandle as the request
-        final COPSSyncStateMsg msg = new COPSSyncStateMsg(getClientType(), new COPSHandle(_handle.getId()), null);
+        final COPSSyncStateMsg msg = new COPSSyncStateMsg(getClientType(), _handle, null);
         try {
             msg.writeData(_sock);
         } catch (IOException e) {
-            throw new COPSPdpException(
-                "Failed to send the sync state request, reason: "
-                + e.getMessage());
+            throw new COPSPdpException("Failed to send the sync state request", e);
         }
     }
     // XXX - Temp
@@ -771,4 +304,7 @@ public class PCMMPdpMsgSender {
     // XXX - Temp
     public void sendDeleteRequestState() throws COPSPdpException {
     }
+       private static short generateNewTransactionID() {
+           return (short) (Math.random() * MAX_TRANSACTION_ID);
+       }
 }