BGP routepolicy distribution bug fixes.

Change-Id: I2176e3872391658263d6817ac8850a3390de00de
diff --git a/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/AsPath.java b/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/AsPath.java
index 2c0f0b8..f6442d9 100644
--- a/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/AsPath.java
+++ b/protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/AsPath.java
@@ -208,15 +208,16 @@
         if (isaspathSet()) {
             int iAsLenIndex = cb.writerIndex();
             cb.writeByte(0);
-            cb.writeByte(ASPATH_SEQ_TYPE);
-            cb.writeByte(aspathSeq.size());
+            if (aspathSeq.size() != 0) {
+                cb.writeByte(ASPATH_SEQ_TYPE);
+                cb.writeByte(aspathSeq.size());
 
-            for (int j = 0; j < aspathSeq.size(); j++) {
-                cb.writeShort(aspathSeq.get(j));
+                for (int j = 0; j < aspathSeq.size(); j++) {
+                    cb.writeShort(aspathSeq.get(j));
+                }
+                int asLen = cb.writerIndex() - iAsLenIndex;
+                cb.setByte(iAsLenIndex, (byte) (asLen - 1));
             }
-
-            int asLen = cb.writerIndex() - iAsLenIndex;
-            cb.setByte(iAsLenIndex, (byte) (asLen - 1));
         } else {
             cb.writeByte(0);
         }