Committed by
Gerrit Code Review
[ONOS-3857] BGP flow spec encoding for mandatory attributes
Change-Id: I58f19deca56464557214d02717a1562ac64d0407
Showing
5 changed files
with
63 additions
and
10 deletions
| ... | @@ -34,6 +34,7 @@ public class As4Path implements BgpValueType { | ... | @@ -34,6 +34,7 @@ public class As4Path implements BgpValueType { |
| 34 | private static final Logger log = LoggerFactory.getLogger(AsPath.class); | 34 | private static final Logger log = LoggerFactory.getLogger(AsPath.class); |
| 35 | public static final byte AS4PATH_TYPE = 17; | 35 | public static final byte AS4PATH_TYPE = 17; |
| 36 | public static final byte ASNUM_SIZE = 4; | 36 | public static final byte ASNUM_SIZE = 4; |
| 37 | + public static final byte FLAGS = (byte) 0x40; | ||
| 37 | 38 | ||
| 38 | private List<Integer> as4pathSet; | 39 | private List<Integer> as4pathSet; |
| 39 | private List<Integer> as4pathSeq; | 40 | private List<Integer> as4pathSeq; |
| ... | @@ -162,8 +163,27 @@ public class As4Path implements BgpValueType { | ... | @@ -162,8 +163,27 @@ public class As4Path implements BgpValueType { |
| 162 | 163 | ||
| 163 | @Override | 164 | @Override |
| 164 | public int write(ChannelBuffer cb) { | 165 | public int write(ChannelBuffer cb) { |
| 165 | - //Not required to Implement as of now | 166 | + |
| 166 | - return 0; | 167 | + int iLenStartIndex = cb.writerIndex(); |
| 168 | + | ||
| 169 | + cb.writeByte(FLAGS); | ||
| 170 | + cb.writeByte(getType()); | ||
| 171 | + if ((as4pathSet != null) && (as4pathSeq != null)) { | ||
| 172 | + int iAsLenIndex = cb.writerIndex(); | ||
| 173 | + cb.writeByte(0); | ||
| 174 | + cb.writeByte(AsPath.ASPATH_SEQ_TYPE); | ||
| 175 | + cb.writeByte(as4pathSeq.size()); | ||
| 176 | + | ||
| 177 | + for (int j = 0; j < as4pathSeq.size(); j++) { | ||
| 178 | + cb.writeInt(as4pathSeq.get(j)); | ||
| 179 | + } | ||
| 180 | + | ||
| 181 | + int asLen = cb.writerIndex() - iAsLenIndex; | ||
| 182 | + cb.setByte(iAsLenIndex, (byte) (asLen - 1)); | ||
| 183 | + } else { | ||
| 184 | + cb.writeByte(0); | ||
| 185 | + } | ||
| 186 | + return cb.writerIndex() - iLenStartIndex; | ||
| 167 | } | 187 | } |
| 168 | 188 | ||
| 169 | @Override | 189 | @Override | ... | ... |
| ... | @@ -63,6 +63,7 @@ public class AsPath implements BgpValueType { | ... | @@ -63,6 +63,7 @@ public class AsPath implements BgpValueType { |
| 63 | public static final byte ASPATH_SET_TYPE = 1; | 63 | public static final byte ASPATH_SET_TYPE = 1; |
| 64 | public static final byte ASPATH_SEQ_TYPE = 2; | 64 | public static final byte ASPATH_SEQ_TYPE = 2; |
| 65 | public static final byte ASNUM_SIZE = 2; | 65 | public static final byte ASNUM_SIZE = 2; |
| 66 | + public static final byte FLAGS = (byte) 0x40; | ||
| 66 | 67 | ||
| 67 | private boolean isAsPath = false; | 68 | private boolean isAsPath = false; |
| 68 | private List<Short> aspathSet; | 69 | private List<Short> aspathSet; |
| ... | @@ -201,8 +202,25 @@ public class AsPath implements BgpValueType { | ... | @@ -201,8 +202,25 @@ public class AsPath implements BgpValueType { |
| 201 | 202 | ||
| 202 | @Override | 203 | @Override |
| 203 | public int write(ChannelBuffer cb) { | 204 | public int write(ChannelBuffer cb) { |
| 204 | - //Not required to Implement as of now | 205 | + int iLenStartIndex = cb.writerIndex(); |
| 205 | - return 0; | 206 | + cb.writeByte(FLAGS); |
| 207 | + cb.writeByte(getType()); | ||
| 208 | + if (isaspathSet()) { | ||
| 209 | + int iAsLenIndex = cb.writerIndex(); | ||
| 210 | + cb.writeByte(0); | ||
| 211 | + cb.writeByte(ASPATH_SEQ_TYPE); | ||
| 212 | + cb.writeByte(aspathSeq.size()); | ||
| 213 | + | ||
| 214 | + for (int j = 0; j < aspathSeq.size(); j++) { | ||
| 215 | + cb.writeShort(aspathSeq.get(j)); | ||
| 216 | + } | ||
| 217 | + | ||
| 218 | + int asLen = cb.writerIndex() - iAsLenIndex; | ||
| 219 | + cb.setByte(iAsLenIndex, (byte) (asLen - 1)); | ||
| 220 | + } else { | ||
| 221 | + cb.writeByte(0); | ||
| 222 | + } | ||
| 223 | + return cb.writerIndex() - iLenStartIndex; | ||
| 206 | } | 224 | } |
| 207 | 225 | ||
| 208 | @Override | 226 | @Override | ... | ... |
| ... | @@ -30,6 +30,7 @@ import com.google.common.base.MoreObjects; | ... | @@ -30,6 +30,7 @@ import com.google.common.base.MoreObjects; |
| 30 | public class LocalPref implements BgpValueType { | 30 | public class LocalPref implements BgpValueType { |
| 31 | public static final byte LOCAL_PREF_TYPE = 5; | 31 | public static final byte LOCAL_PREF_TYPE = 5; |
| 32 | public static final byte LOCAL_PREF_MAX_LEN = 4; | 32 | public static final byte LOCAL_PREF_MAX_LEN = 4; |
| 33 | + public static final byte FLAGS = (byte) 0x40; | ||
| 33 | 34 | ||
| 34 | private int localPref; | 35 | private int localPref; |
| 35 | 36 | ||
| ... | @@ -109,8 +110,12 @@ public class LocalPref implements BgpValueType { | ... | @@ -109,8 +110,12 @@ public class LocalPref implements BgpValueType { |
| 109 | 110 | ||
| 110 | @Override | 111 | @Override |
| 111 | public int write(ChannelBuffer cb) { | 112 | public int write(ChannelBuffer cb) { |
| 112 | - //Not to implement as of now | 113 | + int iLenStartIndex = cb.writerIndex(); |
| 113 | - return 0; | 114 | + cb.writeByte(FLAGS); |
| 115 | + cb.writeByte(getType()); | ||
| 116 | + cb.writeByte(4); | ||
| 117 | + cb.writeInt(localPref()); | ||
| 118 | + return cb.writerIndex() - iLenStartIndex; | ||
| 114 | } | 119 | } |
| 115 | 120 | ||
| 116 | @Override | 121 | @Override | ... | ... |
| ... | @@ -30,6 +30,7 @@ import com.google.common.base.MoreObjects; | ... | @@ -30,6 +30,7 @@ import com.google.common.base.MoreObjects; |
| 30 | public class Med implements BgpValueType { | 30 | public class Med implements BgpValueType { |
| 31 | public static final byte MED_TYPE = 4; | 31 | public static final byte MED_TYPE = 4; |
| 32 | public static final byte MED_MAX_LEN = 4; | 32 | public static final byte MED_MAX_LEN = 4; |
| 33 | + public static final byte FLAGS = (byte) 0x80; | ||
| 33 | 34 | ||
| 34 | private int med; | 35 | private int med; |
| 35 | 36 | ||
| ... | @@ -109,8 +110,12 @@ public class Med implements BgpValueType { | ... | @@ -109,8 +110,12 @@ public class Med implements BgpValueType { |
| 109 | 110 | ||
| 110 | @Override | 111 | @Override |
| 111 | public int write(ChannelBuffer cb) { | 112 | public int write(ChannelBuffer cb) { |
| 112 | - //Not to implement as of now | 113 | + int iLenStartIndex = cb.writerIndex(); |
| 113 | - return 0; | 114 | + cb.writeByte(FLAGS); |
| 115 | + cb.writeByte(getType()); | ||
| 116 | + cb.writeByte(4); | ||
| 117 | + cb.writeInt(med()); | ||
| 118 | + return cb.writerIndex() - iLenStartIndex; | ||
| 114 | } | 119 | } |
| 115 | 120 | ||
| 116 | @Override | 121 | @Override | ... | ... |
| ... | @@ -55,6 +55,7 @@ public class Origin implements BgpValueType { | ... | @@ -55,6 +55,7 @@ public class Origin implements BgpValueType { |
| 55 | 55 | ||
| 56 | public static final byte ORIGIN_TYPE = 1; | 56 | public static final byte ORIGIN_TYPE = 1; |
| 57 | public static final byte ORIGIN_VALUE_LEN = 1; | 57 | public static final byte ORIGIN_VALUE_LEN = 1; |
| 58 | + public static final byte FLAGS = (byte) 0x40; | ||
| 58 | 59 | ||
| 59 | private boolean isOrigin = false; | 60 | private boolean isOrigin = false; |
| 60 | private byte origin; | 61 | private byte origin; |
| ... | @@ -131,8 +132,12 @@ public class Origin implements BgpValueType { | ... | @@ -131,8 +132,12 @@ public class Origin implements BgpValueType { |
| 131 | 132 | ||
| 132 | @Override | 133 | @Override |
| 133 | public int write(ChannelBuffer cb) { | 134 | public int write(ChannelBuffer cb) { |
| 134 | - //Not required to Implement as of now | 135 | + int iLenStartIndex = cb.writerIndex(); |
| 135 | - return 0; | 136 | + cb.writeByte(FLAGS); |
| 137 | + cb.writeByte(ORIGIN_TYPE); | ||
| 138 | + cb.writeByte(1); | ||
| 139 | + cb.writeByte(origin().value); | ||
| 140 | + return cb.writerIndex() - iLenStartIndex; | ||
| 136 | } | 141 | } |
| 137 | 142 | ||
| 138 | @Override | 143 | @Override | ... | ... |
-
Please register or login to post a comment