Created abstract super class for all COPS Message Senders as each contained duplicate...
[packetcable.git] / packetcable-driver / src / main / java / org / umu / cops / prpdp / COPSPdpMsgSender.java
index af246724bef142b8890a9f058252f90cb4ee022f..677ff8c0287e41cd970bcd70b4cfaf0427796996 100644 (file)
@@ -6,6 +6,7 @@
 
 package org.umu.cops.prpdp;
 
+import org.umu.cops.COPSMsgSender;
 import org.umu.cops.stack.*;
 import org.umu.cops.stack.COPSContext.RType;
 import org.umu.cops.stack.COPSDecision.Command;
@@ -24,23 +25,7 @@ import java.util.Set;
  *
  * TODO - Need to continue refactoring by removing all instances of Hashtable (change to Map<>)
  */
-public class COPSPdpMsgSender {
-
-    /**
-     * Socket connected to PEP
-     */
-    protected final Socket _sock;
-
-    /**
-     * COPS client-type that identifies the policy client
-     */
-    protected final short _clientType;
-
-    /**
-     * COPS client handle used to uniquely identify a particular
-     * PEP's request for a client-type
-     */
-    protected final COPSHandle _handle;
+public class COPSPdpMsgSender extends COPSMsgSender {
 
     /**
      * Creates a COPSPepMsgSender
@@ -50,27 +35,7 @@ public class COPSPdpMsgSender {
      * @param sock              Socket to the PEP
      */
     public COPSPdpMsgSender (final short clientType, final COPSHandle clientHandle, final Socket sock) {
-        // COPS Handle
-        _handle = clientHandle;
-        _clientType = clientType;
-
-        _sock = sock;
-    }
-
-    /**
-     * Gets the client handle
-     * @return   Client's <tt>COPSHandle</tt>
-     */
-    public COPSHandle getClientHandle() {
-        return _handle;
-    }
-
-    /**
-     * Gets the client-type
-     * @return   Client-type value
-     */
-    public short getClientType() {
-        return _clientType;
+        super(clientType, clientHandle, sock);
     }
 
     /**
@@ -81,24 +46,6 @@ public class COPSPdpMsgSender {
      */
     public void sendDecision(final Map<String, String> removeDecs, Map<String, String> installDecs)
             throws COPSPdpException {
-        /* <Decision Message> ::= <Common Header: Flag SOLICITED>
-         *                          <Client Handle>
-         *                          *(<Decision>) | <Error>
-         *                          [<Integrity>]
-         * <Decision> ::= <Context>
-         *                  <Decision: Flags>
-         *                  [<Named Decision Data: Provisioning>]
-         * <Decision: Flags> ::= <Command-Code> NULLFlag
-         * <Command-Code> ::= NULLDecision | Install | Remove
-         * <Named Decision Data> ::= <<Install Decision> | <Remove Decision>>
-         * <Install Decision> ::= *(<PRID> <EPD>)
-         * <Remove Decision> ::= *(<PRID> | <PPRID>)
-         *
-         * Very important, this is actually being treated like this:
-         * <Install Decision> ::= <PRID> | <EPD>
-         * <Remove Decision> ::= <PRID> | <PPRID>
-         *
-        */
 
         final Map<COPSContext, Set<COPSDecision>> decisionMap = new HashMap<>();
 
@@ -147,11 +94,9 @@ public class COPSPdpMsgSender {
 
         // 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, _handle, decisionMap, null, null);
 
         //** Send the decision
-        //**
         try {
             decisionMsg.writeData(_sock);
         } catch (IOException e) {
@@ -167,28 +112,6 @@ public class COPSPdpMsgSender {
      */
     public void sendUnsolicitedDecision(final Map<String, String> removeDecs, final Map<String, String> installDecs)
             throws COPSPdpException {
-        //** Example of an UNSOLICITED decision
-        //**
-
-        /* <Decision Message> ::= <Common Header: Flag UNSOLICITED>
-         *                          <Client Handle>
-         *                          *(<Decision>) | <Error>
-         *                          [<Integrity>]
-         * <Decision> ::= <Context>
-         *                  <Decision: Flags>
-         *                  [<Named Decision Data: Provisioning>]
-         * <Decision: Flags> ::= <Command-Code> NULLFlag
-         * <Command-Code> ::= NULLDecision | Install | Remove
-         * <Named Decision Data> ::= <<Install Decision> | <Remove Decision>>
-         * <Install Decision> ::= *(<PRID> <EPD>)
-         * <Remove Decision> ::= *(<PRID> | <PPRID>)
-         *
-         * Very important, this is actually being treated like this:
-         * <Install Decision> ::= <PRID> | <EPD>
-         * <Remove Decision> ::= <PRID> | <PPRID>
-         *
-        */
-
         // Common Header with the same ClientType as the request
         // Client Handle with the same clientHandle as the request
         final Map<COPSContext, Set<COPSDecision>> decisionMap = new HashMap<>();
@@ -241,11 +164,9 @@ public class COPSPdpMsgSender {
         decisionMsg.add(intr);
         /**/
 
-        final COPSDecisionMsg decisionMsg = new COPSDecisionMsg(_clientType, new COPSHandle(getClientHandle().getId()),
-                decisionMap, null, null);
+        final COPSDecisionMsg decisionMsg = new COPSDecisionMsg(_clientType, _handle, decisionMap, null, null);
 
         //** Send the decision
-        //**
         try {
             decisionMsg.writeData(_sock);
         } catch (IOException e) {
@@ -258,27 +179,13 @@ public class COPSPdpMsgSender {
      * @throws   COPSPdpException
      */
     public void sendDeleteRequestState() throws COPSPdpException {
-        /* <Decision Message> ::= <Common Header: Flag UNSOLICITED>
-         *                          <Client Handle>
-         *                          *(<Decision>)
-         *                          [<Integrity>]
-         * <Decision> ::= <Context>
-         *                  <Decision: Flags>
-         * <Decision: Flags> ::= Remove Request-State
-         *
-        */
-
-        // Decisions
-        //  <Context>
-        //  <Decision: Flags>
         final COPSDecision dec = new COPSDecision(Command.REMOVE, DecisionFlag.REQSTATE);
         final Map<COPSContext, Set<COPSDecision>> decisionMap = new HashMap<>();
         final Set<COPSDecision> decisionSet = new HashSet<>();
         decisionSet.add(dec);
         decisionMap.put(new COPSContext(RType.CONFIG, (short)0), decisionSet);
 
-        final COPSDecisionMsg decisionMsg = new COPSDecisionMsg(getClientType(), new COPSHandle(_handle.getId()),
-                decisionMap, null, null);
+        final COPSDecisionMsg decisionMsg = new COPSDecisionMsg(getClientType(), _handle, decisionMap, null, null);
         try {
             decisionMsg.writeData(_sock);
         } catch (IOException e) {
@@ -290,27 +197,14 @@ public class COPSPdpMsgSender {
      * Sends a request asking that a new request state be created
      * @throws   COPSPdpException
      */
-    public void sendOpenNewRequestState()
-    throws COPSPdpException {
-        /* <Decision Message> ::= <Common Header: Flag UNSOLICITED>
-         *                          <Client Handle>
-         *                          *(<Decision>)
-         *                          [<Integrity>]
-         * <Decision> ::= <Context>
-         *                  <Decision: Flags>
-         * <Decision: Flags> ::= Install Request-State
-         *
-        */
-
-        //  <Decision: Flags>
+    public void sendOpenNewRequestState() throws COPSPdpException {
         final COPSDecision dec = new COPSDecision(Command.INSTALL, DecisionFlag.REQSTATE);
         final Map<COPSContext, Set<COPSDecision>> decisionMap = new HashMap<>();
         final Set<COPSDecision> decisionSet = new HashSet<>();
         decisionSet.add(dec);
         decisionMap.put(new COPSContext(RType.CONFIG, (short)0), decisionSet);
 
-        final COPSDecisionMsg decisionMsg = new COPSDecisionMsg(_clientType, new COPSHandle(_handle.getId()),
-                decisionMap, null, null);
+        final COPSDecisionMsg decisionMsg = new COPSDecisionMsg(_clientType, _handle, decisionMap, null, null);
 
         try {
             decisionMsg.writeData(_sock);
@@ -323,14 +217,8 @@ public class COPSPdpMsgSender {
      * Sends a message asking for a COPS sync operation
      * @throws COPSPdpException
      */
-    public void sendSyncRequestState()
-    throws COPSPdpException {
-        /* <Synchronize State Request>  ::= <Common Header>
-         *                                  [<Client Handle>]
-         *                                  [<Integrity>]
-         */
-
-        final COPSSyncStateMsg msg = new COPSSyncStateMsg(_clientType, new COPSHandle(_handle.getId()), null);
+    public void sendSyncRequestState() throws COPSPdpException {
+        final COPSSyncStateMsg msg = new COPSSyncStateMsg(_clientType, _handle, null);
         try {
             msg.writeData(_sock);
         } catch (IOException e) {