Priyanka B
Committed by Gerrit Code Review

[ONOS-2602] use of Constants variables

Change-Id: I22dd05c5b5c1ac99edce106ab43b00e4b333c177
......@@ -21,6 +21,7 @@ import java.util.Objects;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onosproject.bgpio.exceptions.BGPParseException;
import org.onosproject.bgpio.util.Constants;
import org.onosproject.bgpio.util.Validation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -34,8 +35,6 @@ 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 int TYPE_AND_LEN_AS_SHORT = 4;
public static final int TYPE_AND_LEN_AS_BYTE = 3;
private List<Integer> as4pathSet;
private List<Integer> as4pathSeq;
......@@ -77,8 +76,8 @@ public class As4Path implements BGPValueType {
validation.getLength());
}
//if fourth bit is set length is read as short otherwise as byte , len includes type, length and value
int len = validation.isShort() ? validation.getLength() + TYPE_AND_LEN_AS_SHORT : validation
.getLength() + TYPE_AND_LEN_AS_BYTE;
int len = validation.isShort() ? validation.getLength() + Constants.TYPE_AND_LEN_AS_SHORT : validation
.getLength() + Constants.TYPE_AND_LEN_AS_BYTE;
ChannelBuffer data = tempCb.readBytes(len);
if (validation.getFirstBit() && !validation.getSecondBit() && validation.getThirdBit()) {
throw new BGPParseException(BGPErrorType.UPDATE_MESSAGE_ERROR, BGPErrorType.ATTRIBUTE_FLAGS_ERROR, data);
......
......@@ -22,6 +22,7 @@ import java.util.Objects;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onosproject.bgpio.exceptions.BGPParseException;
import org.onosproject.bgpio.util.Constants;
import org.onosproject.bgpio.util.Validation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -53,7 +54,7 @@ public class AsPath implements BGPValueType {
*
* @return AS type
*/
public byte getType() {
public byte type() {
return (byte) value;
}
}
......@@ -63,8 +64,6 @@ 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 int TYPE_AND_LEN_AS_SHORT = 4;
public static final int TYPE_AND_LEN_AS_BYTE = 3;
private boolean isAsPath = false;
private List<Short> aspathSet;
......@@ -108,8 +107,8 @@ public class AsPath implements BGPValueType {
validation.getLength());
}
//if fourth bit is set, length is read as short otherwise as byte , len includes type, length and value
int len = validation.isShort() ? validation.getLength() + TYPE_AND_LEN_AS_SHORT : validation
.getLength() + TYPE_AND_LEN_AS_BYTE;
int len = validation.isShort() ? validation.getLength() + Constants.TYPE_AND_LEN_AS_SHORT : validation
.getLength() + Constants.TYPE_AND_LEN_AS_BYTE;
ChannelBuffer data = tempCb.readBytes(len);
if (validation.getFirstBit() && !validation.getSecondBit() && validation.getThirdBit()) {
throw new BGPParseException(BGPErrorType.UPDATE_MESSAGE_ERROR, BGPErrorType.ATTRIBUTE_FLAGS_ERROR, data);
......
......@@ -19,9 +19,8 @@ import java.util.Objects;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onosproject.bgpio.exceptions.BGPParseException;
import org.onosproject.bgpio.util.Constants;
import org.onosproject.bgpio.util.Validation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.base.MoreObjects;
......@@ -29,11 +28,7 @@ import com.google.common.base.MoreObjects;
* Provides implementation of LocalPref BGP Path Attribute.
*/
public class LocalPref implements BGPValueType {
private static final Logger log = LoggerFactory.getLogger(LocalPref.class);
public static final byte LOCAL_PREF_TYPE = 5;
public static final int TYPE_AND_LEN_AS_SHORT = 4;
public static final int TYPE_AND_LEN_AS_BYTE = 3;
public static final byte LOCAL_PREF_MAX_LEN = 4;
private int localPref;
......@@ -72,8 +67,8 @@ public class LocalPref implements BGPValueType {
parseFlags.getLength());
}
int len = parseFlags.isShort() ? parseFlags.getLength() + TYPE_AND_LEN_AS_SHORT : parseFlags.getLength()
+ TYPE_AND_LEN_AS_BYTE;
int len = parseFlags.isShort() ? parseFlags.getLength() +
Constants.TYPE_AND_LEN_AS_SHORT : parseFlags.getLength() + Constants.TYPE_AND_LEN_AS_BYTE;
ChannelBuffer data = tempCb.readBytes(len);
if (parseFlags.getFirstBit()) {
throw new BGPParseException(BGPErrorType.UPDATE_MESSAGE_ERROR, BGPErrorType.ATTRIBUTE_FLAGS_ERROR, data);
......
......@@ -19,9 +19,8 @@ import java.util.Objects;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onosproject.bgpio.exceptions.BGPParseException;
import org.onosproject.bgpio.util.Constants;
import org.onosproject.bgpio.util.Validation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.base.MoreObjects;
......@@ -29,10 +28,7 @@ import com.google.common.base.MoreObjects;
* Provides Implementation of Med BGP Path Attribute.
*/
public class Med implements BGPValueType {
private static final Logger log = LoggerFactory.getLogger(Med.class);
public static final byte MED_TYPE = 4;
public static final int TYPE_AND_LEN_AS_SHORT = 4;
public static final int TYPE_AND_LEN_AS_BYTE = 3;
public static final byte MED_MAX_LEN = 4;
private int med;
......@@ -71,8 +67,8 @@ public class Med implements BGPValueType {
Validation.validateLen(BGPErrorType.UPDATE_MESSAGE_ERROR, BGPErrorType.ATTRIBUTE_LENGTH_ERROR,
parseFlags.getLength());
}
int len = parseFlags.isShort() ? parseFlags.getLength() + TYPE_AND_LEN_AS_SHORT : parseFlags
.getLength() + TYPE_AND_LEN_AS_BYTE;
int len = parseFlags.isShort() ? parseFlags.getLength() + Constants.TYPE_AND_LEN_AS_SHORT : parseFlags
.getLength() + Constants.TYPE_AND_LEN_AS_BYTE;
ChannelBuffer data = tempCb.readBytes(len);
if (!parseFlags.getFirstBit() && parseFlags.getSecondBit() && parseFlags.getThirdBit()) {
throw new BGPParseException(BGPErrorType.UPDATE_MESSAGE_ERROR, BGPErrorType.ATTRIBUTE_FLAGS_ERROR, data);
......