[ONOS-8098][VOL-3128] Implement multipart PORT_DESC processing in ACTIVE state

Change-Id: Icb82a0856ca0388ee27151d3a90e50a07e49965a
diff --git a/protocols/openflow/ctl/src/main/java/org/onosproject/openflow/controller/impl/OFChannelHandler.java b/protocols/openflow/ctl/src/main/java/org/onosproject/openflow/controller/impl/OFChannelHandler.java
index a7a74f0..9f78a11 100644
--- a/protocols/openflow/ctl/src/main/java/org/onosproject/openflow/controller/impl/OFChannelHandler.java
+++ b/protocols/openflow/ctl/src/main/java/org/onosproject/openflow/controller/impl/OFChannelHandler.java
@@ -445,9 +445,11 @@
                     h.portDescReplies.add((OFPortDescStatsReply) m);
                 }
                 //h.portDescReply = (OFPortDescStatsReply) m; // temp store
-                log.debug("Received port desc reply for switch at {}: {}",
-                         h.getSwitchInfoString(),
-                         ((OFPortDescStatsReply) m).getEntries());
+                if (log.isDebugEnabled()) {
+                    log.debug("Received port desc reply for switch at {}: {}",
+                              h.getSwitchInfoString(),
+                              ((OFPortDescStatsReply) m).getEntries());
+                }
                 try {
                     h.sendHandshakeSetConfig();
                 } catch (IOException e) {
@@ -600,21 +602,23 @@
                     return;
                 }
 
+                // set switch information
                 h.sw.setOFVersion(h.ofVersion);
                 h.sw.setFeaturesReply(h.featuresReply);
                 h.sw.setPortDescReplies(h.portDescReplies);
                 h.sw.setMeterFeaturesReply(h.meterFeaturesReply);
                 h.sw.setConnected(true);
                 h.sw.setChannel(h);
+
+                //Port Description List has served its purpose, clearing.
+                h.portDescReplies.clear();
+
 //                boolean success = h.sw.connectSwitch();
 //
 //                if (!success) {
 //                    disconnectDuplicate(h);
 //                    return;
 //                }
-                // set switch information
-
-
 
                 log.debug("Switch {} bound to class {}, description {}",
                         h.sw, h.sw.getClass(), drep);
@@ -861,10 +865,29 @@
             void processOFStatisticsReply(OFChannelHandler h,
                     OFStatsReply m) {
                 if (m.getStatsType().equals(OFStatsType.PORT_DESC)) {
-                    log.debug("Received port desc message from {}: {}",
-                             h.sw.getDpid(),
-                             ((OFPortDescStatsReply) m).getEntries());
-                    h.sw.setPortDescReply((OFPortDescStatsReply) m);
+                    if (log.isDebugEnabled()) {
+                        log.debug("Received port desc message from {}: {}",
+                                  h.sw.getDpid(),
+                                  ((OFPortDescStatsReply) m).getEntries());
+                    }
+                    if (m.getFlags().contains(OFStatsReplyFlags.REPLY_MORE)) {
+                        log.debug("Active Stats reply indicates more stats from sw {} for "
+                                          + "port description",
+                                  h.getSwitchInfoString());
+                        h.portDescReplies.add((OFPortDescStatsReply) m);
+                        h.dispatchMessage(m);
+                        return;
+                    }
+
+                    h.portDescReplies.add((OFPortDescStatsReply) m);
+                    if (log.isDebugEnabled()) {
+                        log.debug("Adding all Port Desc Active Replies to {}: {}",
+                                  h.sw.getDpid(),
+                                  h.portDescReplies);
+                    }
+                    h.sw.setPortDescReplies(h.portDescReplies);
+                    //clearing to wait for next full response
+                    h.portDescReplies.clear();
                 }
                 h.dispatchMessage(m);
             }