Shashikanth VH
Committed by Gerrit Code Review

[ONOS-3857] BGP flow spec encoding for mandatory attributes

Change-Id: I58f19deca56464557214d02717a1562ac64d0407
......@@ -34,6 +34,7 @@ public class As4Path implements BgpValueType {
private static final Logger log = LoggerFactory.getLogger(AsPath.class);
public static final byte AS4PATH_TYPE = 17;
public static final byte ASNUM_SIZE = 4;
public static final byte FLAGS = (byte) 0x40;
private List<Integer> as4pathSet;
private List<Integer> as4pathSeq;
......@@ -162,8 +163,27 @@ public class As4Path implements BgpValueType {
@Override
public int write(ChannelBuffer cb) {
//Not required to Implement as of now
return 0;
int iLenStartIndex = cb.writerIndex();
cb.writeByte(FLAGS);
cb.writeByte(getType());
if ((as4pathSet != null) && (as4pathSeq != null)) {
int iAsLenIndex = cb.writerIndex();
cb.writeByte(0);
cb.writeByte(AsPath.ASPATH_SEQ_TYPE);
cb.writeByte(as4pathSeq.size());
for (int j = 0; j < as4pathSeq.size(); j++) {
cb.writeInt(as4pathSeq.get(j));
}
int asLen = cb.writerIndex() - iAsLenIndex;
cb.setByte(iAsLenIndex, (byte) (asLen - 1));
} else {
cb.writeByte(0);
}
return cb.writerIndex() - iLenStartIndex;
}
@Override
......
......@@ -63,6 +63,7 @@ public class AsPath implements BgpValueType {
public static final byte ASPATH_SET_TYPE = 1;
public static final byte ASPATH_SEQ_TYPE = 2;
public static final byte ASNUM_SIZE = 2;
public static final byte FLAGS = (byte) 0x40;
private boolean isAsPath = false;
private List<Short> aspathSet;
......@@ -201,8 +202,25 @@ public class AsPath implements BgpValueType {
@Override
public int write(ChannelBuffer cb) {
//Not required to Implement as of now
return 0;
int iLenStartIndex = cb.writerIndex();
cb.writeByte(FLAGS);
cb.writeByte(getType());
if (isaspathSet()) {
int iAsLenIndex = cb.writerIndex();
cb.writeByte(0);
cb.writeByte(ASPATH_SEQ_TYPE);
cb.writeByte(aspathSeq.size());
for (int j = 0; j < aspathSeq.size(); j++) {
cb.writeShort(aspathSeq.get(j));
}
int asLen = cb.writerIndex() - iAsLenIndex;
cb.setByte(iAsLenIndex, (byte) (asLen - 1));
} else {
cb.writeByte(0);
}
return cb.writerIndex() - iLenStartIndex;
}
@Override
......
......@@ -30,6 +30,7 @@ import com.google.common.base.MoreObjects;
public class LocalPref implements BgpValueType {
public static final byte LOCAL_PREF_TYPE = 5;
public static final byte LOCAL_PREF_MAX_LEN = 4;
public static final byte FLAGS = (byte) 0x40;
private int localPref;
......@@ -109,8 +110,12 @@ public class LocalPref implements BgpValueType {
@Override
public int write(ChannelBuffer cb) {
//Not to implement as of now
return 0;
int iLenStartIndex = cb.writerIndex();
cb.writeByte(FLAGS);
cb.writeByte(getType());
cb.writeByte(4);
cb.writeInt(localPref());
return cb.writerIndex() - iLenStartIndex;
}
@Override
......
......@@ -30,6 +30,7 @@ import com.google.common.base.MoreObjects;
public class Med implements BgpValueType {
public static final byte MED_TYPE = 4;
public static final byte MED_MAX_LEN = 4;
public static final byte FLAGS = (byte) 0x80;
private int med;
......@@ -109,8 +110,12 @@ public class Med implements BgpValueType {
@Override
public int write(ChannelBuffer cb) {
//Not to implement as of now
return 0;
int iLenStartIndex = cb.writerIndex();
cb.writeByte(FLAGS);
cb.writeByte(getType());
cb.writeByte(4);
cb.writeInt(med());
return cb.writerIndex() - iLenStartIndex;
}
@Override
......
......@@ -55,6 +55,7 @@ public class Origin implements BgpValueType {
public static final byte ORIGIN_TYPE = 1;
public static final byte ORIGIN_VALUE_LEN = 1;
public static final byte FLAGS = (byte) 0x40;
private boolean isOrigin = false;
private byte origin;
......@@ -131,8 +132,12 @@ public class Origin implements BgpValueType {
@Override
public int write(ChannelBuffer cb) {
//Not required to Implement as of now
return 0;
int iLenStartIndex = cb.writerIndex();
cb.writeByte(FLAGS);
cb.writeByte(ORIGIN_TYPE);
cb.writeByte(1);
cb.writeByte(origin().value);
return cb.writerIndex() - iLenStartIndex;
}
@Override
......