Refactor exception handling in the OSPF protocol

- removed unnecessary throws of Exception from methods
- converted throws of generic Exception to specific OspfParseException

Change-Id: I9d07167d92f221a234e9eba4c6082deb165afc0b
diff --git a/protocols/ospf/ctl/src/main/java/org/onosproject/ospf/controller/area/OspfAreaImpl.java b/protocols/ospf/ctl/src/main/java/org/onosproject/ospf/controller/area/OspfAreaImpl.java
index b598d86..7a74637 100644
--- a/protocols/ospf/ctl/src/main/java/org/onosproject/ospf/controller/area/OspfAreaImpl.java
+++ b/protocols/ospf/ctl/src/main/java/org/onosproject/ospf/controller/area/OspfAreaImpl.java
@@ -29,6 +29,7 @@
 import org.onosproject.ospf.controller.OspfNeighborState;
 import org.onosproject.ospf.controller.impl.OspfNbrImpl;
 import org.onosproject.ospf.controller.lsdb.OspfLsdbImpl;
+import org.onosproject.ospf.exceptions.OspfParseException;
 import org.onosproject.ospf.protocol.lsa.LsaHeader;
 import org.onosproject.ospf.protocol.lsa.subtypes.OspfLsaLink;
 import org.onosproject.ospf.protocol.lsa.types.NetworkLsa;
@@ -41,6 +42,7 @@
 import org.slf4j.LoggerFactory;
 
 import java.net.InetAddress;
+import java.net.UnknownHostException;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Iterator;
@@ -203,9 +205,9 @@
      * @param interfaceIp interface IP address
      * @param mask        interface network mask
      * @return NetworkLsa instance
-     * @throws Exception might throws exception
+     * @throws OspfParseException might throws exception
      */
-    public NetworkLsa buildNetworkLsa(Ip4Address interfaceIp, Ip4Address mask) throws Exception {
+    public NetworkLsa buildNetworkLsa(Ip4Address interfaceIp, Ip4Address mask) throws OspfParseException {
         // generate the Router-LSA for this Area.
         NetworkLsa networkLsa = new NetworkLsa();
         networkLsa.setAdvertisingRouter(routerId);
@@ -254,9 +256,9 @@
      *
      * @param ospfInterface Interface instance
      * @return routerLsa Router LSA instance
-     * @throws Exception might throws exception
+     * @throws OspfParseException might throws exception
      */
-    public RouterLsa buildRouterLsa(OspfInterface ospfInterface) throws Exception {
+    public RouterLsa buildRouterLsa(OspfInterface ospfInterface) throws OspfParseException {
         // generate the Router-LSA for this Area.
         RouterLsa routerLsa = new RouterLsa();
         routerLsa.setAdvertisingRouter(routerId);
@@ -480,17 +482,22 @@
      * @param linkStateID       link state id to form the key
      * @param advertisingRouter advertising router to form the key
      * @return lsa wrapper instance which contains the Lsa
-     * @throws Exception might throws exception
      */
-    public LsaWrapper getLsa(int lsType, String linkStateID, String advertisingRouter) throws Exception {
+    public LsaWrapper getLsa(int lsType, String linkStateID, String advertisingRouter) {
         String lsaKey = lsType + "-" + linkStateID + "-" + advertisingRouter;
         if (lsType == OspfParameters.LINK_LOCAL_OPAQUE_LSA || lsType == OspfParameters.AREA_LOCAL_OPAQUE_LSA ||
                 lsType == OspfParameters.AS_OPAQUE_LSA) {
-            byte[] linkStateAsBytes = InetAddress.getByName(linkStateID).getAddress();
-            int opaqueType = linkStateAsBytes[0];
-            int opaqueId = OspfUtil.byteToInteger(Arrays.copyOfRange(linkStateAsBytes, 1,
+            try {
+                byte[] linkStateAsBytes = InetAddress.getByName(linkStateID).getAddress();
+
+                int opaqueType = linkStateAsBytes[0];
+                int opaqueId = OspfUtil.byteToInteger(Arrays.copyOfRange(linkStateAsBytes, 1,
                                                                      linkStateAsBytes.length));
-            lsaKey = lsType + "-" + opaqueType + opaqueId + "-" + advertisingRouter;
+                lsaKey = lsType + "-" + opaqueType + opaqueId + "-" + advertisingRouter;
+            } catch (UnknownHostException uhe) {
+                log.warn("Can't resolve host in Lsa wrapper", uhe);
+                return null;
+            }
         }
         return database.findLsa(lsType, lsaKey);
     }
@@ -524,9 +531,8 @@
      *
      * @param ospfLsa       OSPF LSA instance
      * @param ospfInterface OSPF interface instance
-     * @throws Exception on error
      */
-    public void addLsa(OspfLsa ospfLsa, OspfInterface ospfInterface) throws Exception {
+    public void addLsa(OspfLsa ospfLsa, OspfInterface ospfInterface) {
         //second param is false as lsa from network
         database.addLsa((LsaHeader) ospfLsa, false, ospfInterface);
     }
@@ -537,10 +543,8 @@
      * @param ospfLsa          OSPF LSA instance
      * @param isSelfOriginated true if the LSA is self originated. Else false
      * @param ospfInterface    OSPF interface instance
-     * @throws Exception on error
      */
-    public void addLsa(OspfLsa ospfLsa, boolean isSelfOriginated, OspfInterface ospfInterface)
-            throws Exception {
+    public void addLsa(OspfLsa ospfLsa, boolean isSelfOriginated, OspfInterface ospfInterface) {
         database.addLsa((LsaHeader) ospfLsa, isSelfOriginated, ospfInterface);
     }
 
diff --git a/protocols/ospf/ctl/src/main/java/org/onosproject/ospf/controller/area/OspfInterfaceImpl.java b/protocols/ospf/ctl/src/main/java/org/onosproject/ospf/controller/area/OspfInterfaceImpl.java
index 7c1626b..be503c2 100644
--- a/protocols/ospf/ctl/src/main/java/org/onosproject/ospf/controller/area/OspfInterfaceImpl.java
+++ b/protocols/ospf/ctl/src/main/java/org/onosproject/ospf/controller/area/OspfInterfaceImpl.java
@@ -40,6 +40,7 @@
 import org.onosproject.ospf.controller.lsdb.OspfLsdbImpl;
 import org.onosproject.ospf.controller.util.OspfEligibleRouter;
 import org.onosproject.ospf.controller.util.OspfInterfaceType;
+import org.onosproject.ospf.exceptions.OspfParseException;
 import org.onosproject.ospf.protocol.lsa.LsaHeader;
 import org.onosproject.ospf.protocol.lsa.OpaqueLsaHeader;
 import org.onosproject.ospf.protocol.ospfpacket.OspfMessageWriter;
@@ -517,11 +518,9 @@
 
     /**
      * Represents an interface is up and connected.
-     *
-     * @throws Exception might throws exception
      */
     @Override
-    public void interfaceUp() throws Exception {
+    public void interfaceUp() {
         log.debug("OSPFInterfaceChannelHandler::interfaceUp...!!!");
         if (interfaceType() == OspfInterfaceType.POINT_TO_POINT.value()) {
             setState(OspfInterfaceState.POINT2POINT);
@@ -552,9 +551,8 @@
      * Gets called when a BDR was detected before the wait timer expired.
      *
      * @param ch channel instance
-     * @throws Exception might throws exception
      */
-    public void backupSeen(Channel ch) throws Exception {
+    public void backupSeen(Channel ch) {
         log.debug("OSPFInterfaceChannelHandler::backupSeen ");
         if (state() == OspfInterfaceState.WAITING) {
             electRouter(ch);
@@ -565,9 +563,8 @@
      * Gets called when no hello message received for particular period.
      *
      * @param ch channel instance
-     * @throws Exception might throws exception
      */
-    public void waitTimer(Channel ch) throws Exception {
+    public void waitTimer(Channel ch) {
         log.debug("OSPFInterfaceChannelHandler::waitTimer ");
         //According to RFC-2328 section 9.4
         if (state() == OspfInterfaceState.WAITING) {
@@ -579,9 +576,8 @@
      * Initiates DR election process.
      *
      * @param ch netty channel instance
-     * @throws Exception might throws exception
      */
-    public void callDrElection(Channel ch) throws Exception {
+    public void callDrElection(Channel ch) {
         log.debug("OSPFInterfaceChannelHandler::callDrElection ");
         //call when timer expired
         //no hello message received for particular interval
@@ -592,10 +588,8 @@
 
     /**
      * Neighbor change event is triggered when the router priority gets changed.
-     *
-     * @throws Exception might throws exception
      */
-    public void neighborChange() throws Exception {
+    public void neighborChange() {
         log.debug("OSPFInterfaceChannelHandler::neighborChange ");
         if (state() == OspfInterfaceState.DR || state() == OspfInterfaceState.BDR ||
                 state() == OspfInterfaceState.DROTHER) {
@@ -623,35 +617,38 @@
      *
      * @param ospfMessage received OSPF message
      * @param ctx         channel handler context instance.
-     * @throws Exception might throws exception
      */
     @Override
-    public void processOspfMessage(OspfMessage ospfMessage, ChannelHandlerContext ctx) throws Exception {
+    public void processOspfMessage(OspfMessage ospfMessage, ChannelHandlerContext ctx) {
         log.debug("OspfChannelHandler::processOspfMessage...!!!");
 
         if (!validateMessage(ospfMessage)) {
             return;
         }
 
-        switch (ospfMessage.ospfMessageType().value()) {
-            case OspfParameters.HELLO:
-                processHelloMessage(ospfMessage, ctx);
-                break;
-            case OspfParameters.DD:
-                processDdMessage(ospfMessage, ctx);
-                break;
-            case OspfParameters.LSREQUEST:
-                processLsRequestMessage(ospfMessage, ctx);
-                break;
-            case OspfParameters.LSUPDATE:
-                processLsUpdateMessage(ospfMessage, ctx);
-                break;
-            case OspfParameters.LSACK:
-                processLsAckMessage(ospfMessage, ctx);
-                break;
-            default:
-                log.debug("Unknown packet to process...!!!");
-                break;
+        try {
+            switch (ospfMessage.ospfMessageType().value()) {
+                case OspfParameters.HELLO:
+                    processHelloMessage(ospfMessage, ctx);
+                    break;
+                case OspfParameters.DD:
+                    processDdMessage(ospfMessage, ctx);
+                    break;
+                case OspfParameters.LSREQUEST:
+                    processLsRequestMessage(ospfMessage, ctx);
+                    break;
+                case OspfParameters.LSUPDATE:
+                    processLsUpdateMessage(ospfMessage, ctx);
+                    break;
+                case OspfParameters.LSACK:
+                    processLsAckMessage(ospfMessage, ctx);
+                    break;
+                default:
+                    log.debug("Unknown packet to process...!!!");
+                    break;
+            }
+        } catch (OspfParseException ope) {
+            log.debug("Error parsing packet", ope);
         }
     }
 
@@ -660,9 +657,8 @@
      *
      * @param ospfMessage OSPF message.
      * @return true if it is a valid else false.
-     * @throws Exception might throws exception
      */
-    private boolean validateMessage(OspfMessage ospfMessage) throws Exception {
+    private boolean validateMessage(OspfMessage ospfMessage) {
         boolean isValid = true;
         OspfPacketHeader header = (OspfPacketHeader) ospfMessage;
 
@@ -688,7 +684,7 @@
             }
 
             //According to RFC-2328 (8.2)
-            /**
+            /*
              * ABR should receive packets from backbone 0.0.0.0 as we are not acting as ABR
              * we are rejecting the packet.
              */
@@ -715,9 +711,8 @@
      *
      * @param ospfMessage OSPF message instance.
      * @param ctx         context instance.
-     * @throws Exception might throws exception
      */
-    void processHelloMessage(OspfMessage ospfMessage, ChannelHandlerContext ctx) throws Exception {
+    void processHelloMessage(OspfMessage ospfMessage, ChannelHandlerContext ctx) {
         Channel channel = ctx.getChannel();
         log.debug("OspfChannelHandler::processHelloMessage...!!!");
         HelloPacket helloPacket = (HelloPacket) ospfMessage;
@@ -902,9 +897,8 @@
      *
      * @param ospfMessage OSPF message instance.
      * @param ctx         channel handler context instance
-     * @throws Exception might throws exception
      */
-    void processDdMessage(OspfMessage ospfMessage, ChannelHandlerContext ctx) throws Exception {
+    void processDdMessage(OspfMessage ospfMessage, ChannelHandlerContext ctx) {
         log.debug("OspfChannelHandler::processDdMessage...!!!");
         Channel channel = ctx.getChannel();
         DdPacket ddPacket = (DdPacket) ospfMessage;
@@ -1075,9 +1069,8 @@
      *
      * @param ospfMessage OSPF message instance.
      * @param ctx         channel handler context instance.
-     * @throws Exception might throws exception
      */
-    void processLsRequestMessage(OspfMessage ospfMessage, ChannelHandlerContext ctx) throws Exception {
+    void processLsRequestMessage(OspfMessage ospfMessage, ChannelHandlerContext ctx) {
         log.debug("OspfChannelHandler::processLsRequestMessage...!!!");
         Channel channel = ctx.getChannel();
         LsRequest lsrPacket = (LsRequest) ospfMessage;
@@ -1114,18 +1107,20 @@
                         // to verify length of the LSA
                         LsaWrapper wrapper = ospfArea.getLsa(lsRequest.lsType(), lsRequest.linkStateId(),
                                                              lsRequest.ownRouterId());
-                        OspfLsa ospflsa = wrapper.ospfLsa();
-                        if ((currentLength + ((LsaWrapperImpl) wrapper).lsaHeader().lsPacketLen()) >= maxSize) {
-                            listItr.previous();
-                            break;
-                        }
-                        if (ospflsa != null) {
-                            lsupdate.addLsa(ospflsa);
-                            noLsa++;
+                        if (wrapper != null) {
+                            OspfLsa ospflsa = wrapper.ospfLsa();
+                            if ((currentLength + ((LsaWrapperImpl) wrapper).lsaHeader().lsPacketLen()) >= maxSize) {
+                                listItr.previous();
+                                break;
+                            }
+                            if (ospflsa != null) {
+                                lsupdate.addLsa(ospflsa);
+                                noLsa++;
 
-                            currentLength = currentLength + ((LsaWrapperImpl) wrapper).lsaHeader().lsPacketLen();
-                        } else {
-                            nbr.badLSReq(channel);
+                                currentLength = currentLength + ((LsaWrapperImpl) wrapper).lsaHeader().lsPacketLen();
+                            } else {
+                                nbr.badLSReq(channel);
+                            }
                         }
                     }
                     lsupdate.setNumberOfLsa(noLsa);
@@ -1149,9 +1144,9 @@
      *
      * @param ospfMessage OSPF message instance.
      * @param ctx         channel handler context instance.
-     * @throws Exception might throws exception
+     * @throws OspfParseException on parsing error
      */
-    void processLsUpdateMessage(OspfMessage ospfMessage, ChannelHandlerContext ctx) throws Exception {
+    void processLsUpdateMessage(OspfMessage ospfMessage, ChannelHandlerContext ctx) throws OspfParseException {
         log.debug("OspfChannelHandler::processLsUpdateMessage");
         LsUpdate lsUpdate = (LsUpdate) ospfMessage;
         String neighbourId = lsUpdate.routerId().toString();
@@ -1182,9 +1177,8 @@
      *
      * @param ospfMessage OSPF message instance.
      * @param ctx         channel handler context instance.
-     * @throws Exception might throws exception
      */
-    void processLsAckMessage(OspfMessage ospfMessage, ChannelHandlerContext ctx) throws Exception {
+    void processLsAckMessage(OspfMessage ospfMessage, ChannelHandlerContext ctx) {
         log.debug("OspfChannelHandler::processLsAckMessage");
         LsAcknowledge lsAckPacket = (LsAcknowledge) ospfMessage;
         //check it is present in listOfNeighbors
@@ -1307,9 +1301,8 @@
      * Performs DR election.
      *
      * @param ch Netty Channel instance.
-     * @throws Exception might throws exception
      */
-    public void electRouter(Channel ch) throws Exception {
+    public void electRouter(Channel ch) {
 
         Ip4Address currentDr = dr();
         Ip4Address currentBdr = bdr();
diff --git a/protocols/ospf/ctl/src/main/java/org/onosproject/ospf/controller/impl/Controller.java b/protocols/ospf/ctl/src/main/java/org/onosproject/ospf/controller/impl/Controller.java
index 3816806..8e8e5f3 100644
--- a/protocols/ospf/ctl/src/main/java/org/onosproject/ospf/controller/impl/Controller.java
+++ b/protocols/ospf/ctl/src/main/java/org/onosproject/ospf/controller/impl/Controller.java
@@ -78,9 +78,8 @@
      * Updates the processes configuration.
      *
      * @param ospfProcesses list of OSPF process instances
-     * @throws Exception might throws parse exception
      */
-    public void updateConfig(List<OspfProcess> ospfProcesses) throws Exception {
+    public void updateConfig(List<OspfProcess> ospfProcesses) {
         log.debug("Controller::UpdateConfig called");
         configPacket = new byte[OspfUtil.CONFIG_LENGTH];
         byte numberOfInterface = 0; // number of interfaces to configure
@@ -343,7 +342,7 @@
             try {
                 peerBootstrap.connect(connectToSocket).addListener(new ChannelFutureListener() {
                     @Override
-                    public void operationComplete(ChannelFuture future) throws Exception {
+                    public void operationComplete(ChannelFuture future) {
                         if (!future.isSuccess()) {
                             connectRetryCounter++;
                             log.error("Connection failed, ConnectRetryCounter {} remote host {}", connectRetryCounter,
diff --git a/protocols/ospf/ctl/src/main/java/org/onosproject/ospf/controller/impl/OspfInterfaceChannelHandler.java b/protocols/ospf/ctl/src/main/java/org/onosproject/ospf/controller/impl/OspfInterfaceChannelHandler.java
index 1a47a0c..5ac63b1 100644
--- a/protocols/ospf/ctl/src/main/java/org/onosproject/ospf/controller/impl/OspfInterfaceChannelHandler.java
+++ b/protocols/ospf/ctl/src/main/java/org/onosproject/ospf/controller/impl/OspfInterfaceChannelHandler.java
@@ -69,10 +69,8 @@
 
     /**
      * Initializes the interface map with interface details.
-     *
-     * @throws Exception might throws exception
      */
-    public void initializeInterfaceMap() throws Exception {
+    public void initializeInterfaceMap()  {
         for (OspfProcess process : processes) {
             for (OspfArea area : process.areas()) {
                 for (OspfInterface ospfInterface : area.ospfInterfaceList()) {
@@ -99,9 +97,8 @@
      * Updates the interface map with interface details.
      *
      * @param ospfProcesses updated process instances
-     * @throws Exception might throws exception
      */
-    public void updateInterfaceMap(List<OspfProcess> ospfProcesses) throws Exception {
+    public void updateInterfaceMap(List<OspfProcess> ospfProcesses) {
         for (OspfProcess ospfUpdatedProcess : ospfProcesses) {
             for (OspfArea updatedArea : ospfUpdatedProcess.areas()) {
                 for (OspfInterface ospfUpdatedInterface : updatedArea.ospfInterfaceList()) {
@@ -152,7 +149,7 @@
     /**
      * Initialize channel, start hello sender and initialize LSDB.
      */
-    private void initialize() throws Exception {
+    private void initialize() {
         log.debug("OspfChannelHandler initialize..!!!");
         if (configPacket != null) {
             log.debug("OspfChannelHandler initialize -> sentConfig packet of length ::"
@@ -163,7 +160,7 @@
     }
 
     @Override
-    public void channelConnected(ChannelHandlerContext ctx, ChannelStateEvent evt) throws Exception {
+    public void channelConnected(ChannelHandlerContext ctx, ChannelStateEvent evt) {
         log.info("OSPF channelConnected from {}", evt.getChannel().getRemoteAddress());
         this.channel = evt.getChannel();
         initialize();
@@ -187,8 +184,7 @@
     }
 
     @Override
-    public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent
-            e) throws Exception {
+    public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) {
         log.debug("[exceptionCaught]: " + e.toString());
         if (e.getCause() instanceof ReadTimeoutException) {
             log.debug("Disconnecting device {} due to read timeout", e.getChannel().getRemoteAddress());
@@ -213,8 +209,7 @@
     }
 
     @Override
-    public void messageReceived(ChannelHandlerContext ctx, MessageEvent
-            e) throws Exception {
+    public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) {
         log.debug("OspfChannelHandler::messageReceived...!!!");
         Object message = e.getMessage();
         if (message instanceof List) {
@@ -239,10 +234,9 @@
      *
      * @param ospfMessage received OSPF message
      * @param ctx         channel handler context instance.
-     * @throws Exception might throws exception
      */
-    public void processOspfMessage(OspfMessage
-                                           ospfMessage, ChannelHandlerContext ctx) throws Exception {
+    private void processOspfMessage(OspfMessage
+                                           ospfMessage, ChannelHandlerContext ctx) {
         log.debug("OspfChannelHandler::processOspfMessage...!!!");
         int interfaceIndex = ospfMessage.interfaceIndex();
         OspfInterface ospfInterface = ospfInterfaceMap.get(interfaceIndex);
diff --git a/protocols/ospf/ctl/src/main/java/org/onosproject/ospf/controller/impl/OspfMessageDecoder.java b/protocols/ospf/ctl/src/main/java/org/onosproject/ospf/controller/impl/OspfMessageDecoder.java
index 621ebc3..0446e09 100644
--- a/protocols/ospf/ctl/src/main/java/org/onosproject/ospf/controller/impl/OspfMessageDecoder.java
+++ b/protocols/ospf/ctl/src/main/java/org/onosproject/ospf/controller/impl/OspfMessageDecoder.java
@@ -21,6 +21,7 @@
 import org.jboss.netty.handler.codec.frame.FrameDecoder;
 import org.onlab.packet.Ip4Address;
 import org.onosproject.ospf.controller.OspfMessage;
+import org.onosproject.ospf.exceptions.OspfParseException;
 import org.onosproject.ospf.protocol.ospfpacket.OspfMessageReader;
 import org.onosproject.ospf.protocol.util.OspfUtil;
 import org.slf4j.Logger;
@@ -37,7 +38,8 @@
     private static final Logger log = LoggerFactory.getLogger(OspfMessageDecoder.class);
 
     @Override
-    protected Object decode(ChannelHandlerContext ctx, Channel channel, ChannelBuffer buffer) throws Exception {
+    protected Object decode(ChannelHandlerContext ctx, Channel channel, ChannelBuffer buffer)
+              throws OspfParseException {
         log.debug("OspfMessageDecoder::Message received <:> length {}", buffer.readableBytes());
         if (!channel.isConnected()) {
             log.info("Channel is not connected.");
diff --git a/protocols/ospf/ctl/src/main/java/org/onosproject/ospf/controller/impl/OspfMessageEncoder.java b/protocols/ospf/ctl/src/main/java/org/onosproject/ospf/controller/impl/OspfMessageEncoder.java
index 98b6a6d..c457725 100644
--- a/protocols/ospf/ctl/src/main/java/org/onosproject/ospf/controller/impl/OspfMessageEncoder.java
+++ b/protocols/ospf/ctl/src/main/java/org/onosproject/ospf/controller/impl/OspfMessageEncoder.java
@@ -32,7 +32,7 @@
     private static final Logger log = LoggerFactory.getLogger(OspfMessageEncoder.class);
 
     @Override
-    protected Object encode(ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception {
+    protected Object encode(ChannelHandlerContext ctx, Channel channel, Object msg) {
 
         byte[] byteMsg = (byte[]) msg;
         log.debug("Encoding ospfMessage of length {}", byteMsg.length);
diff --git a/protocols/ospf/ctl/src/main/java/org/onosproject/ospf/controller/impl/OspfNbrImpl.java b/protocols/ospf/ctl/src/main/java/org/onosproject/ospf/controller/impl/OspfNbrImpl.java
index ff3f75b..0f7a91c 100644
--- a/protocols/ospf/ctl/src/main/java/org/onosproject/ospf/controller/impl/OspfNbrImpl.java
+++ b/protocols/ospf/ctl/src/main/java/org/onosproject/ospf/controller/impl/OspfNbrImpl.java
@@ -38,6 +38,7 @@
 import org.onosproject.ospf.controller.area.OspfInterfaceImpl;
 import org.onosproject.ospf.controller.lsdb.LsaWrapperImpl;
 import org.onosproject.ospf.controller.util.OspfInterfaceType;
+import org.onosproject.ospf.exceptions.OspfParseException;
 import org.onosproject.ospf.protocol.lsa.LsaHeader;
 import org.onosproject.ospf.protocol.lsa.OpaqueLsaHeader;
 import org.onosproject.ospf.protocol.lsa.types.OpaqueLsa10;
@@ -144,23 +145,23 @@
     /**
      * The list of LSAs that have to be flooded.
      */
-    private Map<String, OspfLsa> reTxList = new LinkedHashMap();
+    private Map<String, OspfLsa> reTxList = new LinkedHashMap<>();
 
     /**
      * The list of LSAs that have been flooded but not yet acknowledged on this adjacency.
      */
-    private Map<String, OspfLsa> pendingReTxList = new LinkedHashMap();
+    private Map<String, OspfLsa> pendingReTxList = new LinkedHashMap<>();
 
     /**
      * List of LSAs which are failed to received ACK.
      */
-    private Map failedTxList = new HashMap();
+    private Map failedTxList = new HashMap<>();
 
     /**
      * The complete list of LSAs that make up the area link-state database, at the moment the.
      * neighbor goes into Database Exchange state (EXCHANGE).
      */
-    private List<LsaHeader> ddSummaryList = new CopyOnWriteArrayList();
+    private List<LsaHeader> ddSummaryList = new CopyOnWriteArrayList<>();
 
     /**
      * LSA Request List from Neighbor.
@@ -283,9 +284,8 @@
      *
      * @param ospfMessage ospf message instance
      * @param channel     netty channel instance
-     * @throws Exception might throws exception
      */
-    public void twoWayReceived(OspfMessage ospfMessage, Channel channel) throws Exception {
+    public void twoWayReceived(OspfMessage ospfMessage, Channel channel) {
         log.debug("OSPFNbr::twoWayReceived...!!!");
         stopInactivityTimeCheck();
         startInactivityTimeCheck();
@@ -367,10 +367,9 @@
      * @param neighborIsMaster neighbor is master or slave
      * @param payload          contains the LSAs to add in Dd Packet
      * @param ch               netty channel instance
-     * @throws Exception might throws exception
      */
     public void negotiationDone(OspfMessage ospfMessage,
-                                boolean neighborIsMaster, List payload, Channel ch) throws Exception {
+                                boolean neighborIsMaster, List payload, Channel ch) {
         stopRxMtDdTimer();
         OspfPacketHeader packet = (OspfPacketHeader) ospfMessage;
         DdPacket ddPacketForCheck = (DdPacket) packet;
@@ -461,9 +460,8 @@
      * Process the LSA Headers received in the last received Database Description OSPFMessage.
      *
      * @param ddPayload LSA headers to process
-     * @throws Exception might throws exception
      */
-    public void processLsas(List ddPayload) throws Exception {
+    public void processLsas(List ddPayload) {
         log.debug("OSPFNbr::processLsas...!!!");
         OspfLsa nextLsa;
         Iterator lsas = ddPayload.iterator();
@@ -503,9 +501,8 @@
      *
      * @param reason a string represents the mismatch reason
      * @return OSPF message instance
-     * @throws Exception might throws exception
      */
-    public OspfMessage seqNumMismatch(String reason) throws Exception {
+    public OspfMessage seqNumMismatch(String reason) {
         log.debug("OSPFNbr::seqNumMismatch...{} ", reason);
         stopRxMtDdTimer();
 
@@ -560,10 +557,9 @@
      * In addition, stop the possibly activated re transmission timer.
      *
      * @param ch netty channel instance
-     * @throws Exception on error
      */
     @Override
-    public void badLSReq(Channel ch) throws Exception {
+    public void badLSReq(Channel ch) {
         log.debug("OSPFNbr::badLSReq...!!!");
 
         if (state.getValue() >= OspfNeighborState.EXCHANGE.getValue()) {
@@ -622,10 +618,9 @@
      * @param neighborIsMaster true if neighbor is master else false
      * @param dataDescPkt      DdPacket instance
      * @param ch               netty channel instance
-     * @throws Exception might throws exception
      */
     public void processDdPacket(boolean neighborIsMaster, DdPacket dataDescPkt,
-                                Channel ch) throws Exception {
+                                Channel ch) {
         log.debug("OSPFNbr::neighborIsMaster.{}", neighborIsMaster);
 
         if (!neighborIsMaster) {
@@ -902,9 +897,9 @@
      * @param lsUpdPkt LS Update Packet received while Neighbor state was EXCHANGE or
      *                 LOADING
      * @param ch       netty channel instance
-     * @throws Exception might throws exception
+     * @throws OspfParseException on parsing error
      */
-    public void processLsUpdate(LsUpdate lsUpdPkt, Channel ch) throws Exception {
+    public void processLsUpdate(LsUpdate lsUpdPkt, Channel ch) throws OspfParseException {
         stopRxMtLsrTimer();
         log.debug("OSPFNbr::processLsUpdate...!!!");
 
@@ -946,10 +941,8 @@
 
     /***
      * Method gets called when no more ls request list and moving to FULL State.
-     *
-     * @throws Exception might throws exception
      */
-    public void loadingDone() throws Exception {
+    public void loadingDone() {
         stopRxMtLsrTimer();
         stopRxMtDdTimer();
         log.debug("OSPFNbr::loadingDone...!!!");
@@ -1051,12 +1044,12 @@
      * @param receivedViaFlooding received via flooding or not
      * @param ch                  channel instance
      * @param sourceIp            source of this Lsa
+     * @throws OspfParseException on parsing error
      * @return true to remove it from lsReqList else false
-     * @throws Exception might throws exception
      */
     public boolean processReceivedLsa(LsaHeader recLsa,
                                       boolean receivedViaFlooding, Channel ch, Ip4Address sourceIp)
-            throws Exception {
+                    throws OspfParseException {
         log.debug("OSPFNbr::processReceivedLsa(recLsa, receivedViaFlooding, ch)...!!!");
 
         //Validate the lsa checksum RFC 2328 13 (1)
@@ -1282,10 +1275,8 @@
     /**
      * RFC 2328 section 13.4
      * Processing self-originated LSAs.
-     *
-     * @throws Exception might throws exception
      */
-    public void processSelfOriginatedLsa() throws Exception {
+    public void processSelfOriginatedLsa() {
         ospfArea.refreshArea(ospfInterface);
     }
 
@@ -1349,10 +1340,8 @@
 
     /**
      * Called when neighbor is down.
-     *
-     * @throws Exception might throws exception
      */
-    public void neighborDown() throws Exception {
+    public void neighborDown() {
         log.debug("Neighbor Down {} and NeighborId {}", neighborIpAddr,
                   neighborId);
         stopInactivityTimeCheck();
diff --git a/protocols/ospf/ctl/src/main/java/org/onosproject/ospf/controller/impl/OspfPipelineFactory.java b/protocols/ospf/ctl/src/main/java/org/onosproject/ospf/controller/impl/OspfPipelineFactory.java
index cb1829a..f98f54c 100644
--- a/protocols/ospf/ctl/src/main/java/org/onosproject/ospf/controller/impl/OspfPipelineFactory.java
+++ b/protocols/ospf/ctl/src/main/java/org/onosproject/ospf/controller/impl/OspfPipelineFactory.java
@@ -35,7 +35,7 @@
     }
 
     @Override
-    public ChannelPipeline getPipeline() throws Exception {
+    public ChannelPipeline getPipeline() {
         ChannelPipeline pipeline = Channels.pipeline();
         pipeline.addLast("encoder", new OspfMessageDecoder());
         pipeline.addLast("decoder", new OspfMessageEncoder());
diff --git a/protocols/ospf/ctl/src/main/java/org/onosproject/ospf/controller/lsdb/LsaQueueConsumer.java b/protocols/ospf/ctl/src/main/java/org/onosproject/ospf/controller/lsdb/LsaQueueConsumer.java
index 02a4fb1..94d232c 100644
--- a/protocols/ospf/ctl/src/main/java/org/onosproject/ospf/controller/lsdb/LsaQueueConsumer.java
+++ b/protocols/ospf/ctl/src/main/java/org/onosproject/ospf/controller/lsdb/LsaQueueConsumer.java
@@ -22,6 +22,7 @@
 import org.onosproject.ospf.controller.OspfLsaType;
 import org.onosproject.ospf.controller.area.OspfAreaImpl;
 import org.onosproject.ospf.controller.area.OspfInterfaceImpl;
+import org.onosproject.ospf.exceptions.OspfParseException;
 import org.onosproject.ospf.protocol.lsa.LsaHeader;
 import org.onosproject.ospf.protocol.lsa.types.NetworkLsa;
 import org.onosproject.ospf.protocol.lsa.types.RouterLsa;
@@ -97,7 +98,7 @@
      *
      * @param wrapper LSA wrapper instance
      */
-    private void processVerifyChecksum(LsaWrapper wrapper) throws Exception {
+    private void processVerifyChecksum(LsaWrapper wrapper) throws OspfParseException {
         ChecksumCalculator checkSum = new ChecksumCalculator();
         if (!checkSum.isValidLsaCheckSum(wrapper.ospfLsa(), ((LsaWrapperImpl) wrapper).lsaHeader().lsType(),
                                          OspfUtil.LSAPACKET_CHECKSUM_POS1,
@@ -116,7 +117,7 @@
      *
      * @param wrapper LSA wrapper instance
      */
-    private void processRefreshLsa(LsaWrapper wrapper) throws Exception {
+    private void processRefreshLsa(LsaWrapper wrapper) throws OspfParseException {
         if (wrapper.isSelfOriginated()) { //self originated
             //set the destination
             OspfInterface ospfInterface = wrapper.ospfInterface();