Miscellaneous driver fixes found while migrating and testing the new Arris API submis... 27/19327/2
authorSteven Pisarski <s.pisarski@cablelabs.com>
Wed, 29 Apr 2015 18:16:50 +0000 (12:16 -0600)
committerThomas Kee <xsited@yahoo.com>
Fri, 8 May 2015 19:51:57 +0000 (12:51 -0700)
Change-Id: I9c56c26faf8b59e5f9e48027e8a3b351d25ebb03
Signed-off-by: Steven Pisarski <s.pisarski@cablelabs.com>
17 files changed:
packetcable-driver/src/main/java/org/pcmm/PCMMGlobalConfig.java
packetcable-driver/src/main/java/org/pcmm/PCMMPdpAgent.java
packetcable-driver/src/main/java/org/pcmm/PCMMPdpConnection.java
packetcable-driver/src/main/java/org/pcmm/PCMMPdpMsgSender.java
packetcable-driver/src/main/java/org/pcmm/PCMMPdpReqStateMan.java
packetcable-driver/src/main/java/org/pcmm/gates/IClassifier.java
packetcable-driver/src/main/java/org/pcmm/gates/IGateSpec.java
packetcable-driver/src/main/java/org/pcmm/gates/IIPv6Classifier.java
packetcable-driver/src/main/java/org/pcmm/gates/impl/Classifier.java
packetcable-driver/src/main/java/org/pcmm/gates/impl/DOCSISServiceClassNameTrafficProfile.java
packetcable-driver/src/main/java/org/pcmm/gates/impl/ExtendedClassifier.java
packetcable-driver/src/main/java/org/pcmm/gates/impl/GateSpec.java
packetcable-driver/src/main/java/org/pcmm/gates/impl/IPv6Classifier.java [new file with mode: 0644]
packetcable-driver/src/main/java/org/pcmm/rcd/impl/PCMMPolicyServer.java
packetcable-driver/src/main/java/org/umu/cops/prpdp/COPSPdpAgent.java
packetcable-driver/src/main/java/org/umu/cops/prpdp/COPSPdpException.java
packetcable-provider/src/main/java/org/opendaylight/controller/packetcable/provider/processors/PCMMDataProcessor.java

index 3d141d69b042a9815aefd6ad9569dc2f28c3086e..0c6ade508335ee475c6ab96c9cf51bc4c798026d 100644 (file)
@@ -4,6 +4,14 @@
 
 package org.pcmm;
 
+import org.pcmm.gates.IPCMMGate;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * TODO - Remove all uses of this class which is evil as it contains environmental settings
+ */
 public class PCMMGlobalConfig {
     // System
     public static int Debug = 0;
@@ -93,6 +101,13 @@ public class PCMMGlobalConfig {
     public static int getGateID2() {
         return GateID2;
     }
+
+    /**
+     * Global TransactionId to Gate Request map allows recovery of CCAP GateIds
+     * TODO - need to find a better means to store shared state.
+     */
+
+    public static Map<Short, IPCMMGate> transactionGateMap = new ConcurrentHashMap<>();
 }
 
 /*
index 28eae315d5b20a003d9618b6a0e6e2f7edb24625..ab32ab01a1c4ca2e38e62b74a09b69206b7121ce 100644 (file)
@@ -16,75 +16,53 @@ import org.umu.cops.stack.COPSHeader.OPCode;
 import java.io.IOException;
 import java.net.InetAddress;
 import java.net.Socket;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
 
 /**
  * Core PDP agent for provisioning
  */
 public class PCMMPdpAgent extends COPSPdpAgent {
 
-    public final static Logger logger = LoggerFactory.getLogger(PCMMPdpAgent.class);
+    private static final Logger logger = LoggerFactory.getLogger(PCMMPdpAgent.class);
 
     /** Well-known port for PCMM */
     public static final int WELL_KNOWN_PDP_PORT = 3918;
 
-    private COPSPepId _pepId;
-    private String _pepIdString;
     /**
      * PEP host name
      */
-    private String psHost;
+    private final String psHost;
 
     /**
      * PEP port
      */
-    private int psPort;
-
-    private Socket socket;
+    private final int psPort;
 
     /**
      * Policy data processing object
      */
-    private PCMMPdpDataProcess _process;
-    private COPSHandle _handle;
-//    private short _transactionID;
-
-    /**
-     * Temporary until can refactor PdpAgent classes
-     */
-    @Deprecated
-    private final Map<String, PCMMPdpConnection> _connectionMap;
+    private final PCMMPdpDataProcess _process;
 
+    // Next two attributes are initialized when connected
     /**
-     * Creates a PDP Agent
-     *
-     * @param clientType
-     *            COPS Client-type
-     * @param process
-     *            Object to perform policy data processing
+     * The Socket connection to the PEP
      */
-    public PCMMPdpAgent(short clientType, PCMMPdpDataProcess process) {
-        this(clientType, null, WELL_KNOWN_PDP_PORT, process);
-    }
+    private transient Socket socket;
+    private transient COPSHandle _handle;
 
     /**
      * Creates a PDP Agent
      *
-     * @param clientType
-     *            COPS Client-type
-     * @param psHost
-     *            Host to connect to
-     * @param psPort
-     *            Port to connect to
-     * @param process
-     *            Object to perform policy data processing
+     * @param clientType - COPS Client-type
+     * @param psHost - Host to connect to
+     * @param psPort - Port to connect to
+     * @param process - Object to perform policy data processing
      */
-    public PCMMPdpAgent(short clientType, String psHost, int psPort, PCMMPdpDataProcess process) {
+    public PCMMPdpAgent(final short clientType, final String psHost, final int psPort,
+                        final PCMMPdpDataProcess process) {
         super(psPort, clientType, null);
         this._process = process;
         this.psHost = psHost;
-        this._connectionMap = new ConcurrentHashMap<>();
+        this.psPort = psPort;
     }
 
     /**
@@ -97,30 +75,19 @@ public class PCMMPdpAgent extends COPSPdpAgent {
     /**
      * Connects to a PDP
      *
-     * @param psHost
-     *            CMTS host name
-     * @param psPort
-     *            CMTS port
      * @return <tt>true</tt> if PDP accepts the connection; <tt>false</tt>
      *         otherwise
      * @throws java.net.UnknownHostException
      * @throws java.io.IOException
      * @throws COPSException
-     * @throws COPSPdpException
      */
-    public boolean connect(String psHost, int psPort) throws IOException, COPSException, COPSPdpException {
-
-        this.psHost = psHost;
-        this.psPort = psPort;
+    public boolean connect() throws IOException, COPSException, COPSPdpException {
         // Create Socket and send OPN
-        InetAddress addr = InetAddress.getByName(psHost);
-        try {
-            socket = new Socket(addr, psPort);
-        } catch (IOException e) {
-            logger.error("Error creating socket connection", e);
-            return (false);
-        }
-        logger.info("PDP Socket Opened");
+        final InetAddress addr = InetAddress.getByName(psHost);
+        // caller will catch IOExceptions
+        socket = new Socket(addr, psPort);
+        logger.debug("{} {}", getClass().getName(), "PDP Socket Opened");
+        //        COPSDebug.err(getClass().getName(), "PDP Socket Opened");
         // Loop through for Incoming messages
 
         // server infinite loop
@@ -129,23 +96,24 @@ public class PCMMPdpAgent extends COPSPdpAgent {
 
             // We're waiting for an message
             try {
-                logger.info("PDP  COPSTransceiver.receiveMsg");
-                COPSMsg msg = COPSTransceiver.receiveMsg(socket);
+                logger.debug("Waiting to receiveMsg");
+                final COPSMsg msg = COPSTransceiver.receiveMsg(socket);
+                logger.debug("Message received of type - " + msg.getHeader().getOpCode());
                 if (msg.getHeader().getOpCode().equals(OPCode.OPN)) {
-                    logger.info("PDP msg.getHeader().isAClientOpen");
                     handleClientOpenMsg(socket, msg);
                 } else {
                     try {
                         socket.close();
                     } catch (Exception ex) {
-                        logger.error("Unexpected exception closing socket", ex);
+                        logger.error("Unexpected error closing socket", ex);
                     }
                 }
-            } catch (Exception e) { // COPSException, IOException
+            } catch (Exception e) {
+                logger.error("Unexpected error handing client open message", e);
                 try {
                     socket.close();
                 } catch (Exception ex) {
-                    logger.error("Unexpected exception closing socket", ex);
+                    logger.error("Unexpected error closing socket", ex);
                 }
                 return true;
             }
@@ -153,61 +121,72 @@ public class PCMMPdpAgent extends COPSPdpAgent {
         return false;
     }
 
-    /**
-     * Handles a COPS client-open message
-     *
-     * @param conn
-     *            Socket to the PEP
-     * @param msg
-     *            <tt>COPSMsg</tt> holding the client-open message
-     * @throws COPSException
-     * @throws IOException
-     */
-    private void handleClientOpenMsg(final Socket conn, final COPSMsg msg) throws COPSException, IOException {
+    // TODO - remove and let super handle after DataProcess & PdpConnection classes are properly refactored
+    @Override
+    public void disconnect (final String pepID, final COPSError error) throws COPSException, IOException {
+        final PCMMPdpConnection pdpConn = (PCMMPdpConnection) _connectionMap.get(pepID);
+        if (pdpConn != null) {
+            final COPSClientCloseMsg closeMsg = new COPSClientCloseMsg(getClientType(), error, null, null);
+            closeMsg.writeData(pdpConn.getSocket());
+            pdpConn.close();
+        }
+
+        final Thread thread = threadMap.remove(pepID);
+        if (thread != null) thread.interrupt();
+    }
+
+    @Override
+    protected void handleClientOpenMsg(final Socket conn, final COPSMsg msg) throws COPSException, IOException {
+        logger.info("Processing client open message");
         final COPSClientOpenMsg cMsg = (COPSClientOpenMsg) msg;
-        final COPSPepId pepId = cMsg.getPepId();
+        _pepId = cMsg.getPepId();
 
         // Validate Client Type
+        // TODO - Need to fix this logic. Currently the client type being set is the CCAP AMID.type mapped to the
+        // enumeration's ordinal value
+/*
         if (msg.getHeader().getClientType() != getClientType()) {
             // Unsupported client type
-            final COPSClientCloseMsg closeMsg = new COPSClientCloseMsg(msg.getHeader().getClientType(),
+            final COPSClientCloseMsg closeMsg = new COPSClientCloseMsg(getClientType(),
                     new COPSError(ErrorTypes.UNSUPPORTED_CLIENT_TYPE, ErrorTypes.NA), null, null);
             try {
                 closeMsg.writeData(conn);
             } catch (IOException unae) {
-                logger.error("Unexpected error writing COPS data", unae);
+                logger.error("Unexpected error writing data", unae);
             }
 
             throw new COPSException("Unsupported client type");
         }
+*/
 
         // PEPId is mandatory
-        if (pepId == null) {
+        if (_pepId == null) {
             // Mandatory COPS object missing
-            final COPSClientCloseMsg closeMsg = new COPSClientCloseMsg(msg.getHeader().getClientType(),
+            final COPSClientCloseMsg closeMsg = new COPSClientCloseMsg(getClientType(),
                     new COPSError(ErrorTypes.MANDATORY_OBJECT_MISSING, ErrorTypes.NA), null, null);
             try {
                 closeMsg.writeData(conn);
             } catch (IOException unae) {
-                logger.error("Unexpected error writing COPS data", unae);
+                logger.error("Unexpected error closing socket", unae);
             }
 
             throw new COPSException("Mandatory COPS object missing (PEPId)");
         }
-        setPepId(pepId);
+
         // Support
         if ((cMsg.getClientSI() != null) ) {
             final MMVersionInfo _mminfo = new MMVersionInfo(cMsg.getClientSI().getData().getData());
-            logger.info("CMTS sent MMVersion info : major:" + _mminfo.getMajorVersionNB() + "  minor:" +
+            logger.debug("CMTS sent MMVersion info : major:" + _mminfo.getMajorVersionNB() + "  minor:" +
                     _mminfo.getMinorVersionNB());
 
         } else {
-            final COPSClientCloseMsg closeMsg = new COPSClientCloseMsg(msg.getHeader().getClientType(),
+            // Unsupported objects
+            final COPSClientCloseMsg closeMsg = new COPSClientCloseMsg(getClientType(),
                     new COPSError(ErrorTypes.UNKNOWN_OBJECT, ErrorTypes.NA), null, null);
             try {
                 closeMsg.writeData(conn);
             } catch (IOException unae) {
-                logger.error("Unexpected error writing COPS data", unae);
+                logger.error("Unexpected error writing data", unae);
             }
 
             throw new COPSException("Unsupported objects (PdpAddress, Integrity)");
@@ -216,29 +195,29 @@ public class PCMMPdpAgent extends COPSPdpAgent {
         */
 
         // Connection accepted
-        final COPSKATimer katimer = new COPSKATimer(getKaTimer());
-        final COPSAcctTimer acctTimer = new COPSAcctTimer(getAcctTimer());
         final COPSClientAcceptMsg acceptMsg;
         if (getAcctTimer() != 0)
-            acceptMsg = new COPSClientAcceptMsg(msg.getHeader().getClientType(), katimer, acctTimer, null);
+            acceptMsg = new COPSClientAcceptMsg(getClientType(), new COPSKATimer(getKaTimer()),
+                    new COPSAcctTimer(getAcctTimer()), null);
         else
-            acceptMsg = new COPSClientAcceptMsg(msg.getHeader().getClientType(), katimer, null, null);
-
+            acceptMsg = new COPSClientAcceptMsg(getClientType(), new COPSKATimer(getKaTimer()), null, null);
         acceptMsg.writeData(conn);
         // XXX - handleRequestMsg
         try {
-            logger.info("PDP COPSTransceiver.receiveMsg");
-            COPSMsg rmsg = COPSTransceiver.receiveMsg(socket);
+            logger.debug("handleClientOpenMsg() - Waiting to receive message");
+            final COPSMsg rmsg = COPSTransceiver.receiveMsg(socket);
+            logger.debug("Received message of type - " + rmsg.getHeader().getOpCode());
             // Client-Close
             if (rmsg.getHeader().getOpCode().equals(OPCode.CC)) {
-                logger.info("Client close description - " + ((COPSClientCloseMsg) rmsg).getError().getDescription());
+                System.out.println(((COPSClientCloseMsg) rmsg)
+                        .getError().getDescription());
                 // close the socket
-                final COPSClientCloseMsg closeMsg = new COPSClientCloseMsg(msg.getHeader().getClientType(),
+                final COPSClientCloseMsg closeMsg = new COPSClientCloseMsg(getClientType(),
                         new COPSError(ErrorTypes.UNKNOWN_OBJECT, ErrorTypes.NA), null, null);
                 try {
                     closeMsg.writeData(conn);
                 } catch (IOException unae) {
-                    logger.error("Unexpected exception writing COPS data", unae);
+                    logger.error("Unexpected error writing data", unae);
                 }
                 throw new COPSException("CMTS requetsed Client-Close");
             } else {
@@ -248,131 +227,51 @@ public class PCMMPdpAgent extends COPSPdpAgent {
                     _handle = rMsg.getClientHandle();
                 } else
                     throw new COPSException("Can't understand request");
-
             }
         } catch (Exception e) { // COPSException, IOException
-            throw new COPSException("Error COPSTransceiver.receiveMsg");
+            throw new COPSException("Error COPSTransceiver.receiveMsg", e);
         }
 
-        logger.info("PDPCOPSConnection");
-        PCMMPdpConnection pdpConn = new PCMMPdpConnection(pepId, conn, _process);
+        logger.debug("PDPCOPSConnection");
+        final PCMMPdpConnection pdpConn = new PCMMPdpConnection(_pepId, conn, _process);
         pdpConn.setKaTimer(getKaTimer());
         if (getAcctTimer() != 0)
             pdpConn.setAccTimer(getAcctTimer());
 
         // XXX - handleRequestMsg
         // XXX - check handle is valid
-        PCMMPdpReqStateMan man = new PCMMPdpReqStateMan(getClientType(), _handle.getId().str());
-        pdpConn.getReqStateMans().put(_handle.getId().str(),man);
+        final PCMMPdpReqStateMan man = new PCMMPdpReqStateMan(getClientType(), _handle.getId().str());
+        pdpConn.addStateMan(_handle.getId().str(), man);
         man.setDataProcess(_process);
         try {
             man.initRequestState(conn);
         } catch (COPSPdpException unae) {
-            logger.error("Error initializing the state manager's request state");
+            logger.error("Unexpected error initializing state", unae);
         }
         // XXX - End handleRequestMsg
 
-        logger.info("PDP Thread(pdpConn).start");
-        new Thread(pdpConn).start();
-        _connectionMap.put(pepId.getData().str(), pdpConn);
-    }
+        logger.info("Starting PDP connection thread to - " + psHost);
 
-    /**
-     * @return the _psHost
-     */
-    public String getPsHost() {
-        return psHost;
-    }
-
-    /**
-     * TODO - make the host immutable
-     * @param _psHost
-     *            the _psHost to set
-     */
-    @Deprecated
-    public void setPsHost(String _psHost) {
-        this.psHost = _psHost;
+        // TODO - store the thread reference so it is possible to manage.
+        final Thread thread = new Thread(pdpConn, "Agent for - " + psHost);
+        thread.start();
+        threadMap.put(_pepId.getData().str(), thread);
+        _connectionMap.put(_pepId.getData().str(), pdpConn);
     }
 
-    /**
-     * @return the _psPort
-     */
-    public int getPsPort() {
-        return psPort;
-    }
-
-    /**
-     * TODO - make the port immutable
-     * @param _psPort
-     *            the _psPort to set
-     */
-    @Deprecated
-    public void setPsPort(int _psPort) {
-        this.psPort = _psPort;
-    }
-
-    /**
-     * @return the socket
-     */
     public Socket getSocket() {
         return socket;
     }
-
-    /**
-     * TODO - Ensure socket is not overly transient
-     * @param socket
-     *            the socket to set
-     */
-    @Deprecated
-    public void setSocket(Socket socket) {
-        this.socket = socket;
-    }
-
-    /**
-     * @return the _process
-     */
     public PCMMPdpDataProcess getProcess() {
         return _process;
     }
-
-    /**
-     * @param _process
-     *            the _process to set
-     */
-    public void setProcess(PCMMPdpDataProcess _process) {
-        this._process = _process;
-    }
-
-    /**
-      * Gets the client handle
-      * @return   Client's <tt>COPSHandle</tt>
-      */
     public COPSHandle getClientHandle() {
         return _handle;
     }
-
-    /**
-      * Gets the PepId
-      * @return   <tt>COPSPepId</tt>
-      */
-    public COPSPepId getPepId() {
-        return _pepId;
-    }
-
     public String getPepIdString() {
-        return _pepIdString;
+        return _pepId.getData().str();
     }
 
-    /**
-     * Sets the PepId
-     * TODO - make PEP ID and the associate string immutable or remove altogether
-     * @param   pepId - COPSPepId
-     */
-    @Deprecated
-    public void setPepId(COPSPepId pepId) {
-        _pepId = pepId;
-        _pepIdString = pepId.getData().str();
-     }
     /*
      * (non-Javadoc)
      *
@@ -384,3 +283,4 @@ public class PCMMPdpAgent extends COPSPdpAgent {
 
 
 }
+
index 2967f811eff51b1379dd4c95cd990a371f68f531..fc08d6ac24d35a2b4ee19bef91ea9a9083a6ad07 100644 (file)
@@ -8,7 +8,6 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.umu.cops.prpdp.COPSPdpException;
 import org.umu.cops.stack.*;
-import org.umu.cops.stack.COPSHeader.OPCode;
 
 import java.io.IOException;
 import java.net.Socket;
@@ -80,6 +79,10 @@ public class PCMMPdpConnection implements Runnable {
         _process = process;
     }
 
+    public void addStateMan(final String key, final PCMMPdpReqStateMan man) {
+        _managerMap.put(key, man);
+    }
+
     /**
      * Sets the keep-alive timer value
      * @param kaTimer Keep-alive timer value (secs)
@@ -142,12 +145,15 @@ public class PCMMPdpConnection implements Runnable {
      * Main loop
      */
     public void run () {
+        logger.info("Starting socket listener.");
         Date _lastSendKa = new Date();
         _lastRecKa = new Date();
         try {
             while (!_sock.isClosed()) {
                 if (_sock.getInputStream().available() != 0) {
+                    logger.info("Waiting to process socket messages");
                     processMessage(_sock);
+                    logger.info("Message processed");
                     _lastRecKa = new Date();
                 }
 
@@ -170,7 +176,9 @@ public class PCMMPdpConnection implements Runnable {
                     if ((cTime - _startTime) > ((_kaTimer*3/4)*1000)) {
                         // TODO - determine what is the client type to be used here?
                         final COPSKAMsg msg = new COPSKAMsg(null);
+                        logger.info("Sending KA message to CCAP");
                         COPSTransceiver.sendMsg(msg, _sock);
+                        logger.info("Sent KA message gto CCAP");
                         _lastSendKa = new Date();
                     }
                 }
@@ -178,7 +186,8 @@ public class PCMMPdpConnection implements Runnable {
                 try {
                     Thread.sleep(500);
                 } catch (Exception e) {
-                    logger.error("Unexpected exception while sleeping", e);
+                    logger.info("Shutting down", e);
+                    break;
                 }
 
             }
@@ -209,20 +218,29 @@ public class PCMMPdpConnection implements Runnable {
     private void processMessage(final Socket conn) throws COPSPdpException, COPSException, IOException {
         final COPSMsg msg = COPSTransceiver.receiveMsg(conn);
 
-        if (msg.getHeader().getOpCode().equals(OPCode.CC)) {
-            handleClientCloseMsg(conn, msg);
-        } else if (msg.getHeader().getOpCode().equals(OPCode.KA)) {
-            handleKeepAliveMsg(conn, msg);
-        } else if (msg.getHeader().getOpCode().equals(OPCode.REQ)) {
-            handleRequestMsg(conn, msg);
-        } else if (msg.getHeader().getOpCode().equals(OPCode.RPT)) {
-            handleReportMsg(conn, msg);
-        } else if (msg.getHeader().getOpCode().equals(OPCode.DRQ)) {
-            handleDeleteRequestMsg(conn, msg);
-        } else if (msg.getHeader().getOpCode().equals(OPCode.SSQ)) {
-            handleSyncComplete(conn, msg);
-        } else {
-            throw new COPSPdpException("Message not expected (" + msg.getHeader().getOpCode() + ").");
+        logger.info("Processing message received of type - " + msg.getHeader().getOpCode());
+
+        switch (msg.getHeader().getOpCode()) {
+            case CC:
+                handleClientCloseMsg(conn, msg);
+                break;
+            case KA:
+                handleKeepAliveMsg(conn, msg);
+                break;
+            case REQ:
+                handleRequestMsg(conn, msg);
+                break;
+            case RPT:
+                handleReportMsg(conn, msg);
+                break;
+            case DRQ:
+                handleDeleteRequestMsg(conn, msg);
+                break;
+            case SSQ:
+                handleSyncComplete(conn, msg);
+                break;
+            default:
+                throw new COPSPdpException("Message not expected (" + msg.getHeader().getOpCode() + ").");
         }
     }
 
@@ -243,6 +261,7 @@ public class PCMMPdpConnection implements Runnable {
     private void handleClientCloseMsg(Socket conn, COPSMsg msg) {
         COPSClientCloseMsg cMsg = (COPSClientCloseMsg) msg;
         _error = cMsg.getError();
+        logger.info("Closing client with error - " + _error.getDescription());
         try {
             // Support
             if (cMsg.getIntegrity() != null) {
index 1740ded9eeab4b625191c7d67719df5097f63b7c..ab71aeeb1cb529dfdd469d44d4d30eb3578fde16 100644 (file)
@@ -12,10 +12,12 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.umu.cops.prpdp.COPSPdpException;
 import org.umu.cops.stack.*;
+import org.umu.cops.stack.COPSClientSI.CSIType;
 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;
@@ -51,26 +53,26 @@ public class PCMMPdpMsgSender {
     /**
      * Socket connected to PEP
      */
-    protected Socket _sock;
+    protected final Socket _sock;
 
     /**
      * COPS client-type that identifies the policy client
      */
-    protected short _clientType;
+    protected final short _clientType;
 
     /**
      * COPS client handle used to uniquely identify a particular PEP's request
      * for a client-type
      */
-    protected COPSHandle _handle;
+    protected final COPSHandle _handle;
 
     /**
      *
      */
     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
@@ -82,18 +84,15 @@ public class PCMMPdpMsgSender {
      * @param sock
      *            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;
+    public PCMMPdpMsgSender(final short clientType, final COPSHandle clientHandle, final Socket sock)
+            throws COPSPdpException {
+        this(clientType, (short)0, clientHandle, sock);
     }
 
     public PCMMPdpMsgSender(final short clientType, final short tID, final COPSHandle clientHandle,
-                            final Socket sock) {
+                            final Socket sock) throws COPSPdpException {
+        if (clientHandle == null) throw new COPSPdpException("Client handle must not be null");
+        if (sock == null) throw new COPSPdpException("Socket must not be null");
         // COPS Handle
         _handle = clientHandle;
         _clientType = clientType;
@@ -102,15 +101,6 @@ public class PCMMPdpMsgSender {
         _sock = sock;
     }
 
-    /**
-     * Gets the client handle
-     *
-     * @return Client's <tt>COPSHandle</tt>
-     */
-    public COPSHandle getClientHandle() {
-        return _handle;
-    }
-
     /**
      * Gets the client-type
      *
@@ -129,6 +119,14 @@ public class PCMMPdpMsgSender {
         return _transactionID;
     }
 
+    /**
+     * Gets the gate-id
+     *
+     * @return the gate-id value
+     */
+    public IGateID getGateID() {
+        return _gateID;
+    }
 
     /**
      * Sends a PCMM GateSet COPS Decision message
@@ -144,7 +142,11 @@ public class PCMMPdpMsgSender {
         trID.setTransactionIdentifier(_transactionID);
 
         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 - " + trIDnum);
+        PCMMGlobalConfig.transactionGateMap.put(trIDnum, gate);
 
         // new pcmm specific clientsi
         final byte[] data = gate.getData();
@@ -152,15 +154,16 @@ 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)));
+        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 COPSDecisionMsg decisionMsg = new COPSDecisionMsg(_clientType, new COPSHandle(getClientHandle().getId()),
-                decisionMap, null, null);
+        final COPSClientSI clientSD = new COPSClientSI(CNum.DEC, CType.CSI, new COPSData(data, 0, data.length));
+
+        final COPSDecisionMsg decisionMsg = new COPSDecisionMsg(_clientType, new COPSHandle(_handle.getId()),
+                decisionMap, null, clientSD);
+
         // ** Send the GateSet Decision
-        // **
         try {
             decisionMsg.writeData(_sock);
         } catch (IOException e) {
@@ -254,7 +257,7 @@ public class PCMMPdpMsgSender {
         // TODO - Use some variable here or remove...
         if (true) {
             //eclassifier.setProtocol(IClassifier.Protocol.NONE);
-            eclassifier.setProtocol(IClassifier.Protocol.TCP);
+//            eclassifier.setProtocol(IClassifier.Protocol.TCP);
             try {
                 InetAddress subIP = InetAddress
                                     .getByName(PCMMGlobalConfig.SubscriberID);
@@ -291,7 +294,7 @@ public class PCMMPdpMsgSender {
             eclassifier.setPriority((byte) 65);
 
         } else {
-            classifier.setProtocol(IClassifier.Protocol.TCP);
+//            classifier.setProtocol(IClassifier.Protocol.TCP);
             try {
                 InetAddress subIP = InetAddress
                                     .getByName(PCMMGlobalConfig.SubscriberID);
@@ -319,15 +322,15 @@ public class PCMMPdpMsgSender {
         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.NA, 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(CSIType.NAMED, new COPSData(data, 0, data.length));
 
         // 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, null);
+                new COPSHandle(_handle.getId()), decisionMap, null, clientSD);
 
         // ** Send the GateSet Decision
         // **
@@ -414,7 +417,7 @@ public class PCMMPdpMsgSender {
         // 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);
+//            eclassifier.setProtocol(IClassifier.Protocol.TCP);
             try {
                 InetAddress subIP = InetAddress
                                     .getByName(PCMMGlobalConfig.SubscriberID);
@@ -451,7 +454,7 @@ public class PCMMPdpMsgSender {
             eclassifier.setPriority((byte) 65);
 
         } else {
-            classifier.setProtocol(IClassifier.Protocol.TCP);
+//            classifier.setProtocol(IClassifier.Protocol.TCP);
             try {
                 InetAddress subIP = InetAddress
                                     .getByName(PCMMGlobalConfig.SubscriberID);
@@ -479,15 +482,15 @@ public class PCMMPdpMsgSender {
         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.CSI, 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(CSIType.NAMED, new COPSData(data, 0, data.length));
 
         // 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, null);
+        final COPSDecisionMsg decisionMsg = new COPSDecisionMsg(_clientType, new COPSHandle(_handle.getId()),
+                decisionMap, null, clientSD);
 
         // ** Send the GateSet Decision
         // **
@@ -516,7 +519,7 @@ public class PCMMPdpMsgSender {
                     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;
@@ -524,7 +527,7 @@ public class PCMMPdpMsgSender {
             }
             return false;
         } catch (Exception e) { // COPSException, IOException
-            throw new COPSPdpException("Error COPSTransceiver.receiveMsg");
+            throw new COPSPdpException("Error COPSTransceiver.receiveMsg", e);
         }
     }
 
@@ -579,7 +582,7 @@ public class PCMMPdpMsgSender {
          * .setServiceClassName("S_up");
          */
 
-        classifier.setProtocol(IClassifier.Protocol.TCP);
+//        classifier.setProtocol(IClassifier.Protocol.TCP);
         try {
             InetAddress subIP = InetAddress.getByName(PCMMGlobalConfig.SubscriberID);
             InetAddress srcIP = InetAddress.getByName(PCMMGlobalConfig.srcIP);
@@ -603,14 +606,15 @@ public class PCMMPdpMsgSender {
         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.CSI, 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(CSIType.NAMED, new COPSData(data, 0, data.length));
+
         // Client Handle with the same clientHandle as the request
         final COPSDecisionMsg decisionMsg = new COPSDecisionMsg(getClientType(),
-                new COPSHandle(getClientHandle().getId()), decisionMap, null, null);
+                new COPSHandle(_handle.getId()), decisionMap, null, clientSD);
 
         // ** Send the GateSet Decision
         // **
@@ -619,7 +623,6 @@ public class PCMMPdpMsgSender {
         } catch (IOException e) {
             logger.error("Failed to send the decision", e);
         }
-
     }
 
     /**
@@ -627,54 +630,35 @@ public class PCMMPdpMsgSender {
      *
      * @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 IGateID gateID = new GateID();
-
+    public void sendGateDelete(final IPCMMGate gate) throws COPSPdpException {
         // set transaction ID to gate set
+        final ITransactionID trID = new TransactionID();
         trID.setGateCommandType(ITransactionID.GateDelete);
         _transactionID = (_transactionID == 0 ? (short) (Math.random() * hashCode()) : _transactionID);
         trID.setTransactionIdentifier(_transactionID);
+        gate.setTransactionID(trID);
 
-        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);
-        }
+        Short trIDnum = trID.getTransactionIdentifier();
+        PCMMGlobalConfig.transactionGateMap.put(trIDnum, gate);
 
-        gate.setTransactionID(trID);
-        gate.setAMID(amid);
-        gate.setSubscriberID(subscriberID);
-        gate.setGateID(gateID);
+        // 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.setClassifier(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, null);
+                new COPSHandle(_handle.getId()), decisionMap, null, clientSD);
 
         // ** Send the GateDelete Decision
         // **
@@ -709,9 +693,7 @@ public class PCMMPdpMsgSender {
         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);
         }
     }
 
@@ -728,9 +710,7 @@ public class PCMMPdpMsgSender {
         try {
             msg.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);
         }
     }
 
@@ -750,9 +730,7 @@ public class PCMMPdpMsgSender {
         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
index a8ab70568e546bb171af269586329c3e3e9b4443..5aa29265520a024ab373e24f459ed7748f0d583e 100644 (file)
@@ -4,6 +4,8 @@
 
 package org.pcmm;
 
+import org.pcmm.gates.IGateID;
+import org.pcmm.gates.IPCMMGate;
 import org.pcmm.gates.ITransactionID;
 import org.pcmm.gates.impl.PCMMGateReq;
 import org.slf4j.Logger;
@@ -22,7 +24,7 @@ import java.util.Map;
  */
 public class PCMMPdpReqStateMan {
 
-    public final static Logger logger = LoggerFactory.getLogger(PCMMPdpReqStateMan.class);
+    private final static Logger logger = LoggerFactory.getLogger(PCMMPdpReqStateMan.class);
 
     /**
      * Request State created
@@ -120,7 +122,7 @@ public class PCMMPdpReqStateMan {
      * Gets the client-type
      * @return   Client-type value
      */
-    public int getClientType() {
+    public short getClientType() {
         return _clientType;
     }
 
@@ -288,27 +290,45 @@ public class PCMMPdpReqStateMan {
             logger.info("rtypemsg process");
             //** Here we must act in accordance with
             //** the report received
+
+            // retrieve and remove the transactionId to gate request map entry
+            // see PCMMPdpMsgSender.sendGateSet(IPCMMGate gate)
+            final ITransactionID trID = gateMsg.getTransactionID();
+            final Short trIDnum = trID.getTransactionIdentifier();
+
+            logger.info("Removing gate from cache with key - " + trIDnum);
+            final IPCMMGate gate = PCMMGlobalConfig.transactionGateMap.remove(trIDnum);
+            if (gate != null) {
+                // capture the "error" message if any
+                gate.setError(gateMsg.getError());
+                logger.info("Setting error on gate - " + gateMsg.getError());
+            }else {
+                logger.error("processReport(): gateReq not found for transactionID {}", trIDnum);
+                return;
+            }
+
             if (rtypemsg.getReportType().equals(ReportType.SUCCESS)) {
                 logger.info("rtypemsg success");
                 _status = ST_REPORT;
+                final IGateID gateID = gateMsg.getGateID();
+                logger.info("Setting gate ID on gate object - " + gateID);
+                gate.setGateID(gateID);
                 if (_process != null)
                     _process.successReport(this, gateMsg);
             } else {
-                if (gateMsg.getTransactionID().getGateCommandType() == ITransactionID.GateDeleteAck) {
-                    logger.info("GateDeleteAck: GateID = " + gateMsg.getGateID().getGateID());
-                    if (gateMsg.getGateID().getGateID() == PCMMGlobalConfig.getGateID1())
-                        PCMMGlobalConfig.setGateID1(0);
-                    if (gateMsg.getGateID().getGateID() == PCMMGlobalConfig.getGateID2())
-                        PCMMGlobalConfig.setGateID2(0);
-
-                }
-                if (gateMsg.getTransactionID().getGateCommandType() == ITransactionID.GateSetAck) {
-                    logger.info("GateSetAck: GateID = " + gateMsg.getGateID().getGateID());
-                    if (0 == PCMMGlobalConfig.getGateID1())
-                        PCMMGlobalConfig.setGateID1(gateMsg.getGateID().getGateID());
-                    if (0 == PCMMGlobalConfig.getGateID2())
-                        PCMMGlobalConfig.setGateID2(gateMsg.getGateID().getGateID());
-                }
+                final String cmdType;
+                if ( trID.getGateCommandType() == ITransactionID.GateDeleteAck ) {
+                    cmdType = "GateDeleteAck";
+                } else if ( trID.getGateCommandType() == ITransactionID.GateSetAck ) {
+                    cmdType = "GateSetAck";
+                } else cmdType = null;
+                // capture the gateId from the response message
+                final IGateID gateID = gateMsg.getGateID();
+                logger.info("Setting gate ID on gate object - " + gateID);
+                gate.setGateID(gateID);
+                int gateIdInt = gateID.getGateID();
+                String gateIdHex = String.format("%08x", gateIdInt);
+                logger.info(getClass().getName() + ": " + cmdType + ": GateID = " + gateIdHex);
             }
             if (rtypemsg.getReportType().equals(ReportType.FAILURE)) {
                 logger.info("rtypemsg failure");
@@ -317,13 +337,21 @@ public class PCMMPdpReqStateMan {
                     _process.failReport(this, gateMsg);
                 else
                     logger.info("Gate message error - " + gateMsg.getError().toString());
-            } else
-                if (rtypemsg.getReportType().equals(ReportType.ACCOUNTING)) {
+            } else if (rtypemsg.getReportType().equals(ReportType.ACCOUNTING)) {
                     logger.info("rtypemsg account");
                     _status = ST_ACCT;
                     if (_process != null)
                         _process.acctReport(this, gateMsg);
-                }
+            }
+
+            // let the waiting gateSet/gateDelete sender proceed
+            // TODO - see PCMMService#processReport() gate.notify(). Should determine a better means to
+            // TODO - handle this synchronization.
+            logger.info("Notify gate request has been updated with ID - " + gate.getGateID());
+            synchronized(gate) {
+                gate.notify();
+            }
+            logger.info("Out processReport");
         }
     }
 
index 6aea0ae67e2a627d79fe62d6a7d566717b9dfd00..3226f50fe7538afebc321cebda0d0c6def2c4600 100644 (file)
@@ -5,10 +5,10 @@
 
 package org.pcmm.gates;
 
-import java.net.InetAddress;
-
 import org.pcmm.base.IPCMMBaseObject;
 
+import java.net.InetAddress;
+
 /**
  *
  *
@@ -16,11 +16,11 @@ import org.pcmm.base.IPCMMBaseObject;
  */
 public interface IClassifier extends IPCMMBaseObject {
 
-    static final short LENGTH = 24;
-    static final byte SNUM = 6;
-    static final byte STYPE = 1;
+    short LENGTH = 24;
+    byte SNUM = 6;
+    byte STYPE = 1;
 
-    static enum Protocol {
+    enum Protocol {
         /*ICMP((short) 1), IGMP((short) 2), */
         NONE((short)0), TCP((short) 6), UDP((short) 17);
 
@@ -87,14 +87,14 @@ public interface IClassifier extends IPCMMBaseObject {
      *
      * @return the protocol.
      */
-    Protocol getProtocol();
+    short getProtocol();
 
     /**
      * @see <a
      *      href="http://www.iana.org/assignments/protocol-numbers/protocol-numbers.txt">protocols</a>
-     * @param p
+     * @param p - the protocol value
      */
-    void setProtocol(Protocol p);
+    void setProtocol(short p);
 
     /**
      * Priority may be used to distinguish between multiple classifiers that
index 10f4500318fde856d441a1fe4c1ce37f2473f998..e81d1dc98cca2b6b8417378aebb23020c79c6f26 100644 (file)
@@ -13,16 +13,12 @@ import org.pcmm.base.IPCMMBaseObject;
  * information regarding the treatment of other objects specified in the Gate
  * message.
  * </p>
- *
- *
- *
- *
  */
 public interface IGateSpec extends IPCMMBaseObject {
 
-    static final byte SNUM = 5;
-    static final byte STYPE = 1;
-    static final short LENGTH = 16;
+    byte SNUM = 5;
+    byte STYPE = 1;
+    short LENGTH = 16;
 
     /**
      * <p>
@@ -34,11 +30,11 @@ public interface IGateSpec extends IPCMMBaseObject {
      *
      *
      */
-    public enum Direction {
+    enum Direction {
 
         UPSTREAM((byte) 1), DOWNSTREAM((byte) 0);
 
-        private Direction(byte value) {
+        Direction(byte value) {
             this.value = value;
         }
 
@@ -69,16 +65,16 @@ public interface IGateSpec extends IPCMMBaseObject {
             }
         }
 
-    };
+    }
 
     /**
      *
      */
-    public enum DSCPTOS {
+    enum DSCPTOS {
 
-        ENABLE((byte) 1), OVERRIDE((byte) 0);
+        ENABLE((byte) 2), OVERRIDE((byte) 0);
 
-        private DSCPTOS(byte value) {
+        DSCPTOS(byte value) {
             this.value = value;
         }
 
@@ -109,7 +105,7 @@ public interface IGateSpec extends IPCMMBaseObject {
 
         private byte value;
 
-    };
+    }
 
     /**
      * <p>
@@ -221,10 +217,13 @@ public interface IGateSpec extends IPCMMBaseObject {
 
     /**
      *
-     * @param dscpTos
+     * @param dscpTos - the object used to overwrite
      */
     void setDSCP_TOSOverwrite(DSCPTOS dscpTos);
 
+    // set the DSCP_TOS value
+    void setDSCP_TOSOverwrite(byte dscpTos);
+
     /**
      *
      * @return DSCP/TOS
@@ -233,7 +232,7 @@ public interface IGateSpec extends IPCMMBaseObject {
 
     /**
      *
-     * @return
+     * @return - the mask
      */
     byte getDSCP_TOSMask();
 
index a9d689f158a2d501986761957edfc5800c732304..1a026dab958f608977eecf1293c76397d14536e1 100644 (file)
@@ -5,27 +5,82 @@
 
 package org.pcmm.gates;
 
+import java.net.InetAddress;
+
 public interface IIPv6Classifier extends IExtendedClassifier {
-    static final short LENGTH = 64;
-    static final byte SNUM = 6;
-    static final byte STYPE = 3;
+    short LENGTH = 64;
+    byte SNUM = 6;
+    byte STYPE = 3;
+
+    // flags: Flow Label match enable flag
+    void setFlowLabelEnableFlag(byte flag);
+    byte getFlowLabelEnableFlag();
 
     // Tc-low
+    void setTcLow(byte tcLow);
+    byte getTcLow();
+
     // Tc-high
+    void setTcHigh(byte tcHigh);
+    byte getTcHigh();
+
     // Tc-mask
+    void setTcMask(byte tcHigh);
+    byte getTcMask();
+
     // Flow Label
+    void setFlowLabel(Long flowLabel);
+    int getFlowLabel();
+
     // Next Header Type
+    void setNextHdr(short nxtHdr);
+    short getNextHdr();
+
     // Source Prefix Length
+    void setSourcePrefixLen(byte srcPrefixLen);
+    byte getSourcePrefixLen();
+
     // Destination Prefix Length
+    void setDestinationPrefixLen(byte dstPrefixLen);
+    byte getDestinationPrefixLen();
+
     // IPv6 Source Address
+    void setSourceIPAddress(InetAddress a);
+    InetAddress getSourceIPAddress();
+
     // IPv6 Destination Address
+    void setDestinationIPAddress(InetAddress a);
+    InetAddress getDestinationIPAddress();
+
     // Source Port Start
+    short getSourcePortStart();
+    void setSourcePortStart(short p);
+
     // Source Port End
+    short getSourcePortEnd();
+    void setSourcePortEnd(short p);
+
     // Destination Port Start
+    short getDestinationPortStart();
+    void setDestinationPortStart(short p);
+
     // Destination Port End
+    short getDestinationPortEnd();
+    void setDestinationPortEnd(short p);
+
     // ClassifierID
+    short getClassifierID();
+    void setClassifierID(short p);
+
     // Priority
+    void setPriority(byte p);
+    byte getPriority();
+
     // Activation State
-    // Action
+    void setActivationState(byte s);
+    byte getActivationState();
 
+    // Action
+    void setAction(byte a);
+    byte getAction();
 }
index 838472200d32d2b61fac0f43b9804d93c1a01763..6fa5d79a8bbdba0f9523ba243a247e8a61f1b536 100644 (file)
@@ -3,15 +3,15 @@
  */
 package org.pcmm.gates.impl;
 
+import org.pcmm.base.impl.PCMMBaseObject;
+import org.pcmm.gates.IClassifier;
+
 import java.net.Inet4Address;
 import java.net.InetAddress;
 import java.net.UnknownHostException;
 
-import org.pcmm.base.impl.PCMMBaseObject;
-import org.pcmm.gates.IClassifier;
-
 /**
- *
+ * TODO - Cleanup this interface
  */
 public class Classifier extends PCMMBaseObject implements IClassifier {
 
@@ -23,16 +23,16 @@ public class Classifier extends PCMMBaseObject implements IClassifier {
     }
 
     /**
-     * @param data
+     * @param data - the data to add
      */
     public Classifier(byte[] data) {
         super(data);
     }
 
     /**
-     * @param len
-     * @param sType
-     * @param sNum
+     * @param len - the classifier's length
+     * @param sType - the sType value
+     * @param sNum - the sNum value
      */
     public Classifier(short len, byte sType, byte sNum) {
         super(len, sType, sNum);
@@ -134,8 +134,8 @@ public class Classifier extends PCMMBaseObject implements IClassifier {
      * @see org.pcmm.gates.IClassifier#getProtocol()
      */
     @Override
-    public Protocol getProtocol() {
-        return Protocol.valueOf(getShort((short) 0));
+    public short getProtocol() {
+        return getShort((short) 0);
     }
 
     /*
@@ -144,8 +144,8 @@ public class Classifier extends PCMMBaseObject implements IClassifier {
      * @see org.pcmm.gates.IClassifier#setProtocol(short)
      */
     @Override
-    public void setProtocol(Protocol p) {
-        setShort(p.getValue(), (short) 0);
+    public void setProtocol(short p) {
+        setShort(p, (short) 0);
     }
 
     /*
index 854d54327db642fbe525f79da045ee3fde815723..382b08a3df81e764673cb06e8ec25a87028ad6cc 100644 (file)
@@ -13,7 +13,7 @@ public class DOCSISServiceClassNameTrafficProfile extends PCMMBaseObject
             implements ITrafficProfile {
 
     public static final byte STYPE = 2;
-    public static final short LENGTH = 12;
+    public static final short LENGTH = 24;
 
     /**
      *
@@ -23,16 +23,16 @@ public class DOCSISServiceClassNameTrafficProfile extends PCMMBaseObject
     }
 
     /**
-     * @param data
+     * @param data - the data bytes to parse
      */
     public DOCSISServiceClassNameTrafficProfile(byte[] data) {
         super(data);
     }
 
     /**
-     * @param len
-     * @param sType
-     * @param sNum
+     * @param len - the classifier's length
+     * @param sType - the sType value
+     * @param sNum - the sNum value
      */
     public DOCSISServiceClassNameTrafficProfile(short len, byte sType, byte sNum) {
         super(len, sType, sNum);
index 0e68f50934961159f413748aa03b8d1ee33e3085..2ebc2bcdb45b656b46fc2ae516129f4aedd01f23 100644 (file)
@@ -3,12 +3,12 @@
  */
 package org.pcmm.gates.impl;
 
-import java.net.InetAddress;
-import java.net.UnknownHostException;
-
 import org.pcmm.base.impl.PCMMBaseObject;
 import org.pcmm.gates.IExtendedClassifier;
 
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+
 /**
  *
  */
@@ -20,16 +20,16 @@ public class ExtendedClassifier extends PCMMBaseObject implements
     }
 
     /**
-     * @param data
+     * @param data - the data bytes to parse
      */
     public ExtendedClassifier(byte[] data) {
         super(data);
     }
 
     /**
-     * @param len
-     * @param sType
-     * @param sNum
+     * @param len - the classifier's length
+     * @param sType - the sType value
+     * @param sNum - the sNum value
      */
     public ExtendedClassifier(short len, byte sType, byte sNum) {
         super(len, sType, sNum);
@@ -132,8 +132,8 @@ public class ExtendedClassifier extends PCMMBaseObject implements
      * @see org.pcmm.gates.IClassifier#getProtocol()
      */
     @Override
-    public Protocol getProtocol() {
-        return Protocol.valueOf(getShort((short) 0));
+    public short getProtocol() {
+        return getShort((short) 0);
     }
 
     /*
@@ -142,8 +142,8 @@ public class ExtendedClassifier extends PCMMBaseObject implements
      * @see org.pcmm.gates.IClassifier#setProtocol(short)
      */
     @Override
-    public void setProtocol(Protocol p) {
-        setShort(p.getValue(), (short) 0);
+    public void setProtocol(short p) {
+        setShort(p, (short) 0);
     }
 
     /*
index dce286e99b4d4252bd0d42edf8c9254f1b093bfc..914855852403819e6b32cf194e6f62d2eeb5c97c 100644 (file)
@@ -12,6 +12,9 @@ import org.pcmm.gates.ISessionClassID;
  */
 public class GateSpec extends PCMMBaseObject implements IGateSpec {
 
+    // GateSpec flags are Direction (bit 0) and DSCPTOS overwrite enable (bit 1)
+    private byte flags = 0;
+
     public GateSpec() {
         super(LENGTH, STYPE, SNUM);
     }
@@ -37,7 +40,9 @@ public class GateSpec extends PCMMBaseObject implements IGateSpec {
 
     @Override
     public void setDirection(Direction direction) {
-        setByte(direction.getValue(), (short) 0);
+        // OR in the Direction flag with the DSCPTOS enable flag
+        flags |= direction.getValue();
+        setByte(flags, (short) 0);
     }
 
     @Override
@@ -84,9 +89,17 @@ public class GateSpec extends PCMMBaseObject implements IGateSpec {
 
     @Override
     public void setDSCP_TOSOverwrite(DSCPTOS dscpTos) {
-        setByte(dscpTos.getValue(), (short) 1);
+        // OR in the DSCPTOS enable flag with the Direction flag
+        flags |= dscpTos.getValue();
+        setByte(flags, (short) 0);
     }
 
+    @Override
+    public void setDSCP_TOSOverwrite(byte dscpTos) {
+        setByte(dscpTos, (short) 1);
+    }
+
+
     @Override
     public DSCPTOS getDSCP_TOSOverwrite() {
         return DSCPTOS.valueOf(getByte((short) 1));
diff --git a/packetcable-driver/src/main/java/org/pcmm/gates/impl/IPv6Classifier.java b/packetcable-driver/src/main/java/org/pcmm/gates/impl/IPv6Classifier.java
new file mode 100644 (file)
index 0000000..1280865
--- /dev/null
@@ -0,0 +1,347 @@
+/**
+
+ * Copyright (c) 2014 CableLabs.  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.gates.impl;
+
+import org.pcmm.base.impl.PCMMBaseObject;
+import org.pcmm.gates.IIPv6Classifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+
+/**
+ *
+ */
+public class IPv6Classifier extends PCMMBaseObject implements
+        IIPv6Classifier {
+
+    private Logger logger = LoggerFactory.getLogger(IPv6Classifier.class);
+
+    public IPv6Classifier() {
+        this(LENGTH, STYPE, SNUM);
+    }
+
+    /**
+     * @param data - the data bytes to parse
+     */
+    public IPv6Classifier(byte[] data) {
+        super(data);
+    }
+
+    /**
+     * @param len - the classifier's length
+     * @param sType - the sType value
+     * @param sNum - the sNum value
+     */
+    public IPv6Classifier(short len, byte sType, byte sNum) {
+        super(len, sType, sNum);
+    }
+
+    // offset:length Field Name: Description
+    // 00:01 Flags: 0000.0001 Flow Label enable match
+    // 01:01 Tc-low
+    // 02:01 Tc-high
+    // 03:01 Tc-mask
+    // 04:04 Flow Label: low order 20 bits; high order 12 bits ignored
+    // 08:02 Next Header Type
+    // 10:01 Source Prefix Length
+    // 11:01 Destination Prefix Length
+    // 12:16 IPv6 Source Address
+    // 28:16 IPv6 Destination Address
+    // 44:02 Source Port Start
+    // 46:02 Source Port End
+    // 48:02 Destination Port Start
+    // 50:02 Destination Port End
+    // 52:02 ClassifierID
+    // 54:01 Priority
+    // 55:01 Activation State
+    // 56:01 Action
+    // 57:03 Reserved
+
+    // 00:01 Flags: 0000.0001 Flow Label enable match
+    @Override
+    public void setFlowLabelEnableFlag(byte flag) {
+        setByte(flag, (short) 0);
+    }
+    @Override
+    public byte getFlowLabelEnableFlag() {
+        return getByte((short) 0);
+    }
+
+    // 01:01 Tc-low
+    @Override
+    public void setTcLow(byte tcLow) {
+        setByte(tcLow, (short) 1);
+    }
+    @Override
+    public byte getTcLow() {
+        return getByte((short) 1);
+    }
+
+    // 02:01 Tc-high
+    @Override
+    public void setTcHigh(byte tcHigh) {
+        setByte(tcHigh, (short) 2);
+    }
+    @Override
+    public byte getTcHigh() {
+        return getByte((short) 2);
+    }
+
+    // 03:01 Tc-mask
+    @Override
+    public void setTcMask(byte tcMask) {
+        setByte(tcMask, (short) 3);
+    }
+    @Override
+    public byte getTcMask() {
+        return getByte((short) 3);
+    }
+
+    // 04:04 Flow Label: low order 20 bits; high order 12 bits ignored
+    @Override
+    public void setFlowLabel(Long flowLabel) {
+        setInt(flowLabel.intValue(), (short) 4);
+    }
+    @Override
+    public int getFlowLabel() {
+        return getInt((short) 4);
+    }
+
+    // 08:02 Next Header Type
+    @Override
+    public void setNextHdr(short nxtHdr) {
+        setShort(nxtHdr, (short) 8);
+    }
+    @Override
+    public short getNextHdr() {
+        return getShort((short) 8);
+    }
+
+    // 10:01 Source Prefix Length
+    @Override
+    public void setSourcePrefixLen(byte srcPrefixLen) {
+        setByte(srcPrefixLen, (short) 10);
+    }
+    @Override
+    public byte getSourcePrefixLen() {
+        return getByte((short) 10);
+    }
+
+    // 11:01 Destination Prefix Length
+    @Override
+    public void setDestinationPrefixLen(byte dstPrefixLen) {
+        setByte(dstPrefixLen, (short) 11);
+    }
+    @Override
+    public byte getDestinationPrefixLen() {
+        return getByte((short) 11);
+    }
+
+    // 12:16 IPv6 Source Address
+    @Override
+    public void setSourceIPAddress(InetAddress a) {
+        setBytes(a.getAddress(), (short) 12);
+    }
+    @Override
+    public InetAddress getSourceIPAddress() {
+        try {
+            return InetAddress.getByAddress(getBytes((short) 12, (short) 16));
+        } catch (UnknownHostException e) {
+            logger.error("getSourceIPAddress(): Malformed IPv6 address: {}", e.getMessage());
+        }
+        return null;
+    }
+
+    // 28:16 IPv6 Destination Address
+    @Override
+    public void setDestinationIPAddress(InetAddress a) {
+        setBytes(a.getAddress(), (short) 28);
+    }
+    @Override
+    public InetAddress getDestinationIPAddress() {
+        try {
+            return InetAddress.getByAddress(getBytes((short) 28, (short) 16));
+        } catch (UnknownHostException e) {
+            logger.error("getDestinationIPAddress(): Malformed IPv6 address: {}", e.getMessage());
+        }
+        return null;
+    }
+    // 44:02 Source Port Start
+    @Override
+    public short getSourcePortStart() {
+        return getShort((short) 44);
+    }
+    @Override
+    public void setSourcePortStart(short p) {
+        setShort(p, (short) 44);
+    }
+
+    // 46:02 Source Port End
+    @Override
+    public short getSourcePortEnd() {
+        return getShort((short) 46);
+    }
+    @Override
+    public void setSourcePortEnd(short p) {
+        setShort(p, (short) 46);
+    }
+
+    // 48:02 Destination Port Start
+    @Override
+    public short getDestinationPortStart() {
+        return getShort((short) 48);
+    }
+    @Override
+    public void setDestinationPortStart(short p) {
+        setShort(p, (short) 48);
+    }
+
+    // 50:02 Destination Port End
+    @Override
+    public short getDestinationPortEnd() {
+        return getShort((short) 50);
+    }
+    @Override
+    public void setDestinationPortEnd(short p) {
+        setShort(p, (short) 50);
+    }
+
+    // 52:02 ClassifierID
+    @Override
+    public short getClassifierID() {
+        return getShort((short) 52);
+    }
+
+    @Override
+    public void setClassifierID(short p) {
+        setShort(p, (short) 52);
+    }
+
+    // 54:01 Priority
+    @Override
+    public void setPriority(byte p) {
+        setByte(p, (short) 54);
+    }
+    @Override
+    public byte getPriority() {
+        return getByte((short) 54);
+    }
+
+    // 55:01 Activation State
+    @Override
+    public void setActivationState(byte s) {
+        setByte(s, (short) 55);
+    }
+    @Override
+    public byte getActivationState() {
+        return getByte((short) 55);
+    }
+
+    // 56:01 Action
+    @Override
+    public void setAction(byte a) {
+        setByte(a, (short) 56);
+    }
+    @Override
+    public byte getAction() {
+        return getByte((short) 56);
+    }
+
+
+
+    // baggage from IExtendedClassifier
+    // not used in IPv6 classifiers
+    @Override
+    public void setIPSourceMask(InetAddress a) {
+        // TODO Auto-generated method stub
+
+    }
+
+    @Override
+    public void setIPDestinationMask(InetAddress m) {
+        // TODO Auto-generated method stub
+
+    }
+
+    @Override
+    public InetAddress getIPSourceMask() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public InetAddress getIPDestinationMask() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public short getDestinationPort() {
+        // TODO Auto-generated method stub
+        return 0;
+    }
+
+    @Override
+    public void setDestinationPort(short p) {
+        // TODO Auto-generated method stub
+
+    }
+
+    @Override
+    public short getSourcePort() {
+        // TODO Auto-generated method stub
+        return 0;
+    }
+
+    @Override
+    public void setSourcePort(short p) {
+        // TODO Auto-generated method stub
+
+    }
+
+    @Override
+    public short getProtocol() {
+        // TODO Auto-generated method stub
+        return 0;
+    }
+
+    @Override
+    public void setProtocol(short p) {
+        // TODO Auto-generated method stub
+
+    }
+
+    @Override
+    public byte getDSCPTOS() {
+        // TODO Auto-generated method stub
+        return 0;
+    }
+
+    @Override
+    public void setDSCPTOS(byte v) {
+        // TODO Auto-generated method stub
+
+    }
+
+    @Override
+    public byte getDSCPTOSMask() {
+        // TODO Auto-generated method stub
+        return 0;
+    }
+
+    @Override
+    public void setDSCPTOSMask(byte v) {
+        // TODO Auto-generated method stub
+
+    }
+
+}
index 1b2ee2aaece391803ba7d5d8cbf0fde4aa23f5ba..8c3127097570c4f870a35706543e05e3c3a8a756 100644 (file)
@@ -534,7 +534,7 @@ public class PCMMPolicyServer extends AbstractPCMMServer implements IPCMMPolicyS
             if (getVersionInfo().getMajorVersionNB() >= 4) {
                 classifier = new ExtendedClassifier();
                 // eclassifier.setProtocol(IClassifier.Protocol.NONE);
-                classifier.setProtocol(IClassifier.Protocol.TCP);
+//                classifier.setProtocol(IClassifier.Protocol.TCP);
                 try {
                     InetAddress subIP = InetAddress.getByName(PCMMGlobalConfig.SubscriberID);
                     InetAddress srcIP = InetAddress.getByName(PCMMGlobalConfig.srcIP);
@@ -569,7 +569,7 @@ public class PCMMPolicyServer extends AbstractPCMMServer implements IPCMMPolicyS
 
             } else {
                 classifier = new Classifier();
-                classifier.setProtocol(IClassifier.Protocol.TCP);
+//                classifier.setProtocol(IClassifier.Protocol.TCP);
                 try {
                     InetAddress subIP = InetAddress.getByName(PCMMGlobalConfig.SubscriberID);
                     InetAddress srcIP = InetAddress.getByName(PCMMGlobalConfig.srcIP);
index a5c9dd6ef029d4af43ca701ca16dd010cce8dbba..d71b8ec4d4b9702e51a73eae352dc85a0c532ace 100644 (file)
@@ -23,39 +23,45 @@ import java.util.concurrent.ConcurrentHashMap;
  */
 public class COPSPdpAgent extends Thread {
 
-    public final static Logger logger = LoggerFactory.getLogger(COPSPdpAgent.class);
+    private static final Logger logger = LoggerFactory.getLogger(COPSPdpAgent.class);
 
     /** Well-known port for COPS */
-    public static final int WELL_KNOWN_PDP_PORT = 3288;
+    //    public static final int WELL_KNOWN_PDP_PORT = 3288;
     /** Default keep-alive timer value (secs) */
     public static final short KA_TIMER_VALUE = 30;
     /** Default accounting timer value (secs) */
     public static final short ACCT_TIMER_VALUE = 0;
 
     /**
-        PDP host port
+     * PDP host port
      */
     private int _serverPort;
 
     /**
-        Client-type of connecting PEP
+     * Client-type of connecting PEP
      */
     private short _clientType;
 
     /**
-        Accounting timer (secs)
+     * Accounting timer (secs)
      */
     private short _acctTimer;
 
     /**
-        Keep-alive timer (secs)
+     * Keep-alive timer (secs)
      */
     private short _kaTimer;
 
     /**
-        Maps a PEP-ID to a connection
+     * The PEP ID
      */
-    private final Map<String, COPSPdpConnection> _connectionMap;
+    protected transient COPSPepId _pepId;
+
+    /**
+     *   Maps a PEP-ID to a connection
+     *   TODO - Refactor COPSPdpConnection to extend PCMMPdpConnection. Until then, the value must remain an Object
+     */
+    protected Map<String, Object> _connectionMap;
     // map < String(PEPID), COPSPdpConnection > ConnectionMap;
 
     /**
@@ -64,20 +70,9 @@ public class COPSPdpAgent extends Thread {
     private COPSPdpDataProcess _process;
 
     /**
-     * Creates a PDP Agent
-     *
-     * @param clientType    COPS Client-type
-     * @param process       Object to perform policy data processing
+     * Holds all of the threads to manage by PEP ID
      */
-    public COPSPdpAgent(final short clientType, final COPSPdpDataProcess process) {
-        _serverPort = WELL_KNOWN_PDP_PORT;
-        _kaTimer = KA_TIMER_VALUE;
-        _acctTimer = ACCT_TIMER_VALUE;
-
-        _clientType = clientType;
-        _connectionMap = new ConcurrentHashMap<>();
-        _process = process;
-    }
+    protected final Map<String, Thread> threadMap;
 
     /**
      * Creates a PDP Agent
@@ -95,22 +90,7 @@ public class COPSPdpAgent extends Thread {
         _clientType = clientType;
         _connectionMap = new ConcurrentHashMap<>();
         _process = process;
-    }
-
-    /**
-     * Sets the keep-alive timer value
-     * @param    kaTimer    Keep alive timer value (secs)
-     */
-    public void setKaTimer (short kaTimer) {
-        _kaTimer = kaTimer;
-    }
-
-    /**
-     * Sets the accounting timer value
-     * @param    acctTimer  Accounting timer value (secs)
-     */
-    public void setAcctTimer (short acctTimer) {
-        _acctTimer = acctTimer;
+        this.threadMap = new ConcurrentHashMap<>();
     }
 
     /**
@@ -145,7 +125,7 @@ public class COPSPdpAgent extends Thread {
      * @throws IOException
      */
     public void disconnect(final String pepID, final COPSError error) throws COPSException, IOException {
-        final COPSPdpConnection pdpConn = _connectionMap.get(pepID);
+        final COPSPdpConnection pdpConn = (COPSPdpConnection)_connectionMap.get(pepID);
         final COPSClientCloseMsg closeMsg = new COPSClientCloseMsg(_clientType, error, null, null);
         closeMsg.writeData(pdpConn.getSocket());
         pdpConn.close();
@@ -157,10 +137,8 @@ public class COPSPdpAgent extends Thread {
      * @throws COPSException
      * @throws COPSPdpException
      */
-    public void sync (String pepID)
-    throws COPSException, COPSPdpException {
-
-        COPSPdpConnection pdpConn = _connectionMap.get(pepID);
+    public void sync(final String pepID) throws COPSException, COPSPdpException {
+        COPSPdpConnection pdpConn = (COPSPdpConnection) _connectionMap.get(pepID);
         pdpConn.syncAllRequestState();
     }
 
@@ -168,7 +146,7 @@ public class COPSPdpAgent extends Thread {
      * Removes a PEP from the connection map
      * @param pepID PEP-ID of the PEP to be removed
      */
-    public void delete (String pepID) {
+    public void delete(final String pepID) {
         _connectionMap.remove(pepID);
     }
 
@@ -181,12 +159,10 @@ public class COPSPdpAgent extends Thread {
             final ServerSocket serverSocket = new ServerSocket (_serverPort);
 
             //Loop through for Incoming messages
-
             // server infinite loop
             while (true) {
-
                 // Wait for an incoming connection from a PEP
-                Socket socket = serverSocket.accept();
+                final Socket socket = serverSocket.accept();
 
                 // COPSDebug.out(getClass().getName(),"New connection accepted " +
                 //           socket.getInetAddress() +
@@ -195,14 +171,15 @@ public class COPSPdpAgent extends Thread {
                 // We're waiting for an OPN message
                 try {
                     final COPSMsg msg = COPSTransceiver.receiveMsg(socket);
+                    logger.info("Message received - " + msg);
                     if (msg.getHeader().getOpCode().equals(OPCode.OPN)) {
                         handleClientOpenMsg(socket, msg);
                     } else {
-                        // COPSDebug.err(getClass().getName(), COPSDebug.ERROR_NOEXPECTEDMSG);
+                        logger.error("Not an open message, closing socket");
                         try {
                             socket.close();
                         } catch (Exception ex) {
-                            logger.error("Error closing socket", ex);
+                            logger.error("Unexpected exception closing socket", ex);
                         }
                     }
                 } catch (Exception e) { // COPSException, IOException
@@ -211,7 +188,7 @@ public class COPSPdpAgent extends Thread {
                     try {
                         socket.close();
                     } catch (Exception ex) {
-                        logger.error("Error closing socket", ex);
+                        logger.error("Unexpected exception closing socket", ex);
                     }
                 }
             }
@@ -221,74 +198,73 @@ public class COPSPdpAgent extends Thread {
     }
 
     /**
-      * Handles a COPS client-open message
-      * @param    conn Socket to the PEP
-      * @param    msg <tt>COPSMsg</tt> holding the client-open message
-      * @throws COPSException
-      * @throws IOException
-      */
-    private void handleClientOpenMsg(final Socket conn, final COPSMsg msg) throws COPSException, IOException {
+     * Handles a COPS client-open message
+     * @param    conn Socket to the PEP
+     * @param    msg <tt>COPSMsg</tt> holding the client-open message
+     * @throws COPSException
+     * @throws IOException
+     * TODO - Refactor PCMMPdpAgent#handleClientOpenMsg() as it contains much of this same logic
+     */
+    protected void handleClientOpenMsg(final Socket conn, final COPSMsg msg) throws COPSException, IOException {
         final COPSClientOpenMsg cMsg = (COPSClientOpenMsg) msg;
-        final COPSPepId pepId = cMsg.getPepId();
+        _pepId = cMsg.getPepId();
 
         // Validate Client Type
-        if (msg.getHeader().getClientType() == _clientType) {
+        if (msg.getHeader().getClientType() != _clientType) {
             // Unsupported client type
-            final COPSClientCloseMsg closeMsg = new COPSClientCloseMsg(msg.getHeader().getClientType(),
+            final COPSClientCloseMsg closeMsg = new COPSClientCloseMsg(_clientType,
                     new COPSError(ErrorTypes.UNSUPPORTED_CLIENT_TYPE, ErrorTypes.NA), null, null);
             try {
                 closeMsg.writeData(conn);
             } catch (IOException unae) {
-                logger.error("Error writing COPS data", unae);
+                logger.error("Unexpected exception writing data", unae);
             }
 
             throw new COPSException("Unsupported client type");
         }
 
         // PEPId is mandatory
-        if (pepId == null) {
+        if (_pepId == null) {
             // Mandatory COPS object missing
-            final COPSClientCloseMsg closeMsg = new COPSClientCloseMsg(msg.getHeader().getClientType(),
+            final COPSClientCloseMsg closeMsg = new COPSClientCloseMsg(_clientType,
                     new COPSError(ErrorTypes.MANDATORY_OBJECT_MISSING, ErrorTypes.NA), null, null);
             try {
                 closeMsg.writeData(conn);
             } catch (IOException unae) {
-                logger.error("Error writing close message", unae);
+                logger.error("Unexpected exception writing data", unae);
             }
 
             throw new COPSException("Mandatory COPS object missing (PEPId)");
         }
 
         // Support
-        if ( (cMsg.getClientSI() != null) ||
-                (cMsg.getPdpAddress() != null) ||
-                (cMsg.getIntegrity() != null)) {
-
+        if ( (cMsg.getClientSI() != null) || (cMsg.getPdpAddress() != null) || (cMsg.getIntegrity() != null)) {
             // Unsupported objects
-            final COPSClientCloseMsg closeMsg = new COPSClientCloseMsg(msg.getHeader().getClientType(),
+            final COPSClientCloseMsg closeMsg = new COPSClientCloseMsg(_clientType,
                     new COPSError(ErrorTypes.UNKNOWN_OBJECT, ErrorTypes.NA), null, null);
             try {
                 closeMsg.writeData(conn);
             } catch (IOException unae) {
-                logger.error("Error writing close message", unae);
+                logger.error("Exception writing data", unae);
             }
 
             throw new COPSException("Unsupported objects (ClientSI, PdpAddress, Integrity)");
         }
 
         // Connection accepted
-        final COPSKATimer katimer = new COPSKATimer(_kaTimer);
         final COPSClientAcceptMsg acceptMsg;
-        if (_acctTimer != 0) acceptMsg = new COPSClientAcceptMsg(msg.getHeader().getClientType(), katimer, null, null);
-        else acceptMsg = new COPSClientAcceptMsg(msg.getHeader().getClientType(), katimer,
+        if (_acctTimer != 0)
+            acceptMsg = new COPSClientAcceptMsg(_clientType, new COPSKATimer(_kaTimer),
                 new COPSAcctTimer(_acctTimer), null);
+        else
+            acceptMsg = new COPSClientAcceptMsg(_clientType, new COPSKATimer(_kaTimer),null, null);
         acceptMsg.writeData(conn);
 
-        final COPSPdpConnection pdpConn = new COPSPdpConnection(pepId,conn,_process);
+        final COPSPdpConnection pdpConn = new COPSPdpConnection(_pepId, conn,  _process);
         pdpConn.setKaTimer(_kaTimer);
         if (_acctTimer != 0) pdpConn.setAccTimer(_acctTimer);
         new Thread(pdpConn).start();
-        _connectionMap.put(pepId.getData().str(),pdpConn);
+        _connectionMap.put(_pepId.getData().str(), pdpConn);
     }
 
 }
index fc4c74d45c1a60a17faae24da95b034d4c6a7302..f54744c9d36b5d0b6cb5c1c6c4aae5d8e81c303d 100644 (file)
@@ -1,48 +1,57 @@
-/*\r
- * Copyright (c) 2004 University of Murcia.  All rights reserved.\r
- * --------------------------------------------------------------\r
- * For more information, please see <http://www.umu.euro6ix.org/>.\r
- */\r
-\r
-package org.umu.cops.prpdp;\r
-\r
-/**\r
- * Exception class for PDP errors\r
- *\r
- * @version COPSPdpException.java, v 2.00 2004\r
- *\r
- */\r
-\r
-public class COPSPdpException extends Exception {\r
-\r
-    private int rc;\r
-    final static int GENERAL_ERROR = 0x00000001;\r
-\r
-    /**\r
-    * Creates a <tt>COPSPdpException</tt> with the given message.\r
-    * @param msg    Exception message\r
-    */\r
-    public COPSPdpException(String msg) {\r
-        super(msg);\r
-        rc=0;\r
-    }\r
-\r
-    /**\r
-     * Creates a <tt>COPSPdpException</tt> with the given message and return code.\r
-     * @param msg       Exception message\r
-     * @param retCode   Return code\r
-     */\r
-    public COPSPdpException(String msg, int retCode) {\r
-        super(msg);\r
-        rc = retCode;\r
-    }\r
-\r
-    /**\r
-     * Gets the return code of the exception\r
-     * @return    Exception's return code\r
-     */\r
-    public int returnCode() {\r
-        return rc;\r
-    }\r
-\r
-}\r
+/*
+ * Copyright (c) 2004 University of Murcia.  All rights reserved.
+ * --------------------------------------------------------------
+ * For more information, please see <http://www.umu.euro6ix.org/>.
+ */
+
+package org.umu.cops.prpdp;
+
+/**
+ * Exception class for PDP errors
+ *
+ * @version COPSPdpException.java, v 2.00 2004
+ *
+ */
+
+public class COPSPdpException extends Exception {
+
+    private int rc;
+    final static int GENERAL_ERROR = 0x00000001;
+
+    /**
+    * Creates a <tt>COPSPdpException</tt> with the given message.
+    * @param msg    Exception message
+    */
+    public COPSPdpException(String msg) {
+        super(msg);
+        rc=0;
+    }
+
+    /**
+     * Creates a <tt>COPSPdpException</tt> with the given message and return code.
+     * @param msg       Exception message
+     * @param retCode   Return code
+     */
+    public COPSPdpException(String msg, int retCode) {
+        super(msg);
+        rc = retCode;
+    }
+
+    /**
+     * Creates a <tt>COPSPdpException</tt> with the given message and throwable.
+     * @param msg       Exception message
+     * @param t         the Throwable
+     */
+    public COPSPdpException(String msg, Throwable t) {
+        super(msg, t);
+    }
+
+    /**
+     * Gets the return code of the exception
+     * @return    Exception's return code
+     */
+    public int returnCode() {
+        return rc;
+    }
+
+}
index 92a06bda8264a13613cf5ef00e539069c6508456..924c65088ce7549829b3aaae18538aa1b190a307 100644 (file)
@@ -3,9 +3,6 @@
  */
 package org.opendaylight.controller.packetcable.provider.processors;
 
-import java.net.InetAddress;
-import java.net.UnknownHostException;
-
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Address;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber;
@@ -16,11 +13,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.traffic.profile.rev140
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.traffic.profile.rev140908.traffic.profile.best.effort.attributes.BeCommittedEnvelope;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.traffic.profile.rev140908.traffic.profile.best.effort.attributes.BeReservedEnvelope;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.packetcable.match.types.rev140909.SubscriberIdRpcAddFlow;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.packetcable.match.types.rev140909.TcpMatchRangesAttributes;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.packetcable.match.types.rev140909.TcpMatchRangesRpcAddFlow;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.packetcable.match.types.rev140909.UdpMatchRangesAttributes;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.packetcable.match.types.rev140909.UdpMatchRangesRpcAddFlow;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.packetcable.match.types.rev140909.*;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.packetcable.match.types.rev140909.tcp.match.ranges.attributes.TcpMatchRanges;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.packetcable.match.types.rev140909.udp.match.ranges.attributes.UpdMatchRanges;
 import org.pcmm.gates.IClassifier;
@@ -33,6 +26,9 @@ import org.pcmm.gates.impl.ExtendedClassifier;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+
 /**
  * 
  * PacketCable data processor
@@ -64,7 +60,7 @@ public class PCMMDataProcessor {
 
        public IClassifier process(Match match) {
                ExtendedClassifier classifier = new ExtendedClassifier();
-               classifier.setProtocol(IClassifier.Protocol.NONE);
+//             classifier.setProtocol(IClassifier.Protocol.NONE);
                getUdpMatchRangeValues(match.getAugmentation(UdpMatchRangesRpcAddFlow.class), classifier);
                getTcpMatchRangesValues(match.getAugmentation(TcpMatchRangesRpcAddFlow.class), classifier);
                SubscriberIdRpcAddFlow subId = match.getAugmentation(SubscriberIdRpcAddFlow.class);
@@ -145,7 +141,7 @@ public class PCMMDataProcessor {
                short srcPortStart, srcPortEnd, dstPortStart, dstPortEnd;
                srcPortStart = srcPortEnd = dstPortStart = dstPortEnd = 0;
                if (tcpRange != null) {
-                       classifier.setProtocol(IClassifier.Protocol.TCP);
+//                     classifier.setProtocol(IClassifier.Protocol.TCP);
                        TcpMatchRanges tcpMatchRanges = tcpRange.getTcpMatchRanges();
                        PortNumber tcpDestinationPortStart = tcpMatchRanges.getTcpDestinationPortStart();
                        if (tcpDestinationPortStart != null && tcpDestinationPortStart.getValue() != null)
@@ -170,7 +166,7 @@ public class PCMMDataProcessor {
                short srcPortStart, srcPortEnd, dstPortStart, dstPortEnd;
                srcPortStart = srcPortEnd = dstPortStart = dstPortEnd = 0;
                if (updRange != null) {
-                       classifier.setProtocol(IClassifier.Protocol.UDP);
+//                     classifier.setProtocol(IClassifier.Protocol.UDP);
                        UpdMatchRanges updMatchRanges = updRange.getUpdMatchRanges();
                        PortNumber udpDestinationPortStart = updMatchRanges.getUdpDestinationPortStart();
                        if (udpDestinationPortStart != null && udpDestinationPortStart.getValue() != null)