Priyanka B
Committed by Gerrit Code Review

[ONOS-2613] Unit test the BGP Update message(LinkStateAttribute)

Change-Id: Id9545296612bed858459c8386368c66cb2159173
......@@ -34,9 +34,9 @@ public final class BgpId {
private final IpAddress ipAddress;
/**
* Private constructor.
* Constructor to initialize ipAddress.
*/
private BgpId(IpAddress ipAddress) {
public BgpId(IpAddress ipAddress) {
this.ipAddress = ipAddress;
}
......
......@@ -24,6 +24,7 @@ import org.onosproject.bgpio.types.As4Path;
import org.onosproject.bgpio.types.AsPath;
import org.onosproject.bgpio.types.BgpErrorType;
import org.onosproject.bgpio.types.BgpValueType;
import org.onosproject.bgpio.types.LinkStateAttributes;
import org.onosproject.bgpio.types.LocalPref;
import org.onosproject.bgpio.types.Med;
import org.onosproject.bgpio.types.NextHop;
......@@ -54,7 +55,7 @@ public class BgpPathAttributes {
*/
protected static final Logger log = LoggerFactory.getLogger(BgpPathAttributes.class);
public static final int LINK_STATE_ATTRIBUTE_TYPE = 50;
public static final int LINK_STATE_ATTRIBUTE_TYPE = 29;
public static final int MPREACHNLRI_TYPE = 14;
public static final int MPUNREACHNLRI_TYPE = 15;
......@@ -139,7 +140,7 @@ public class BgpPathAttributes {
.isMpUnReachNlriSet();
break;
case LINK_STATE_ATTRIBUTE_TYPE:
//TODO: To be merged later
pathAttribute = LinkStateAttributes.read(cb);
break;
default:
//skip bytes for unsupported attribute types
......
......@@ -89,7 +89,7 @@ public class LinkStateAttributes implements BgpValueType {
public static final short ATTR_PREFIX_OSPF_FWD_ADDR = 1156;
public static final short ATTR_PREFIX_OPAQUE_ATTR = 1157;
public static final byte LINKSTATE_ATTRIB_TYPE = 50;
public static final byte LINKSTATE_ATTRIB_TYPE = 29;
public static final byte TYPE_AND_LEN = 4;
private boolean isLinkStateAttribute = false;
private List<BgpValueType> linkStateAttribList;
......@@ -139,14 +139,14 @@ public class LinkStateAttributes implements BgpValueType {
public static LinkStateAttributes read(ChannelBuffer cb)
throws BgpParseException {
ChannelBuffer tempBuf = cb;
ChannelBuffer tempBuf = cb.copy();
Validation parseFlags = Validation.parseAttributeHeader(cb);
int len = parseFlags.isShort() ? parseFlags.getLength() + TYPE_AND_LEN
: parseFlags.getLength() + 3;
ChannelBuffer data = tempBuf.readBytes(len);
if (!parseFlags.getFirstBit() || parseFlags.getSecondBit()
|| parseFlags.getThirdBit()) {
if (!parseFlags.getFirstBit() && parseFlags.getSecondBit()
&& parseFlags.getThirdBit()) {
throw new BgpParseException(BgpErrorType.UPDATE_MESSAGE_ERROR,
BgpErrorType.ATTRIBUTE_FLAGS_ERROR,
data);
......
......@@ -56,7 +56,7 @@ public final class BgpAttrNodeFlagBitTlv implements BgpValueType {
* @param bExternalBit External bit
* @param bAbrBit ABR Bit
*/
private BgpAttrNodeFlagBitTlv(boolean bOverloadBit, boolean bAttachedBit,
public BgpAttrNodeFlagBitTlv(boolean bOverloadBit, boolean bAttachedBit,
boolean bExternalBit, boolean bAbrBit) {
this.bOverloadBit = bOverloadBit;
this.bAttachedBit = bAttachedBit;
......
......@@ -21,9 +21,8 @@ import org.jboss.netty.buffer.ChannelBuffer;
import org.onosproject.bgpio.exceptions.BgpParseException;
import org.onosproject.bgpio.types.BgpErrorType;
import org.onosproject.bgpio.types.BgpValueType;
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;
......@@ -31,166 +30,103 @@ import com.google.common.base.MoreObjects;
* Implements BGP link protection type attribute.
*/
public final class BgpLinkAttrProtectionType implements BgpValueType {
protected static final Logger log = LoggerFactory
.getLogger(BgpLinkAttrProtectionType.class);
public static final int ATTRLINK_PROTECTIONTYPE = 1093;
public static final int LINK_PROTECTION_LEN = 2;
public static final int EXTRA_TRAFFIC = 0x01;
public static final int UNPROTECTED = 0x02;
public static final int SHARED = 0x04;
public static final int DEDICATED_ONE_ISTO_ONE = 0x08;
public static final int DEDICATED_ONE_PLUS_ONE = 0x10;
public static final int ENHANCED = 0x20;
/* Link Protection type flags */
private final boolean bExtraTraffic;
private final boolean bUnprotected;
private final boolean bShared;
private final boolean bDedOneIstoOne;
private final boolean bDedOnePlusOne;
private final boolean bEnhanced;
private byte linkProtectionType;
/**
* Constructor to initialize the value.
*
* @param bExtraTraffic Extra Traffic
* @param bUnprotected Unprotected
* @param bShared Shared
* @param bDedOneIstoOne Dedicated 1:1
* @param bDedOnePlusOne Dedicated 1+1
* @param bEnhanced Enhanced
* Enum to provide Link protection types.
*/
private BgpLinkAttrProtectionType(boolean bExtraTraffic,
boolean bUnprotected,
boolean bShared, boolean bDedOneIstoOne,
boolean bDedOnePlusOne, boolean bEnhanced) {
this.bExtraTraffic = bExtraTraffic;
this.bUnprotected = bUnprotected;
this.bShared = bShared;
this.bDedOneIstoOne = bDedOneIstoOne;
this.bDedOnePlusOne = bDedOnePlusOne;
this.bEnhanced = bEnhanced;
}
public enum ProtectionType {
EXTRA_TRAFFIC(1), UNPROTECTED(2), SHARED(4), DEDICATED_ONE_ISTO_ONE(8),
DEDICATED_ONE_PLUS_ONE(0x10), ENHANCED(0x20), RESERVED(0x40);
int value;
/**
* Returns object of this class with specified values.
* Assign val with the value as the link protection type.
*
* @param bExtraTraffic Extra Traffic
* @param bUnprotected Unprotected
* @param bShared Shared
* @param bDedOneIstoOne Dedicated 1:1
* @param bDedOnePlusOne Dedicated 1+1
* @param bEnhanced Enhanced
* @return object of BgpLinkAttrProtectionType
* @param val link protection
*/
public static BgpLinkAttrProtectionType of(boolean bExtraTraffic,
boolean bUnprotected,
boolean bShared,
boolean bDedOneIstoOne,
boolean bDedOnePlusOne,
boolean bEnhanced) {
return new BgpLinkAttrProtectionType(bExtraTraffic, bUnprotected,
bShared, bDedOneIstoOne,
bDedOnePlusOne, bEnhanced);
ProtectionType(int val) {
value = val;
}
/**
* Reads the BGP link attributes protection type.
* Returns value of link protection type.
*
* @param cb Channel buffer
* @return object of type BgpLinkAttrProtectionType
* @throws BgpParseException while parsing BgpLinkAttrProtectionType
* @return link protection type
*/
public static BgpLinkAttrProtectionType read(ChannelBuffer cb)
throws BgpParseException {
short linkProtectionType;
byte higherByte;
short lsAttrLength = cb.readShort();
boolean bExtraTraffic;
boolean bUnprotected;
boolean bShared;
boolean bDedOneIstoOne;
boolean bDedOnePlusOne;
boolean bEnhanced;
if ((lsAttrLength != LINK_PROTECTION_LEN)
|| (cb.readableBytes() < lsAttrLength)) {
Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR,
BgpErrorType.ATTRIBUTE_LENGTH_ERROR,
lsAttrLength);
public byte type() {
return (byte) value;
}
linkProtectionType = cb.readShort();
higherByte = (byte) (linkProtectionType >> 8);
bExtraTraffic = ((higherByte & (byte) EXTRA_TRAFFIC) == EXTRA_TRAFFIC);
bUnprotected = ((higherByte & (byte) UNPROTECTED) == UNPROTECTED);
bShared = ((higherByte & (byte) SHARED) == SHARED);
bDedOneIstoOne = ((higherByte & (byte) DEDICATED_ONE_ISTO_ONE) == DEDICATED_ONE_ISTO_ONE);
bDedOnePlusOne = ((higherByte & (byte) DEDICATED_ONE_PLUS_ONE) == DEDICATED_ONE_PLUS_ONE);
bEnhanced = ((higherByte & (byte) ENHANCED) == ENHANCED);
return BgpLinkAttrProtectionType.of(bExtraTraffic, bUnprotected,
bShared, bDedOneIstoOne,
bDedOnePlusOne, bEnhanced);
}
/**
* Returns ExtraTraffic Bit.
* Constructor to initialize the value.
*
* @return ExtraTraffic Bit
* @param linkProtectionType link protection type
*/
public boolean extraTraffic() {
return bExtraTraffic;
public BgpLinkAttrProtectionType(byte linkProtectionType) {
this.linkProtectionType = linkProtectionType;
}
/**
* Returns Unprotected Bit.
* Returns object of this class with specified values.
*
* @return Unprotected Bit
* @param linkProtectionType link protection type
* @return object of BgpLinkAttrProtectionType
*/
public boolean unprotected() {
return bUnprotected;
public static BgpLinkAttrProtectionType of(byte linkProtectionType) {
return new BgpLinkAttrProtectionType(linkProtectionType);
}
/**
* Returns Shared Bit.
* Reads the BGP link attributes protection type.
*
* @return Shared Bit
* @param cb Channel buffer
* @return object of type BgpLinkAttrProtectionType
* @throws BgpParseException while parsing BgpLinkAttrProtectionType
*/
public boolean shared() {
return bShared;
}
public static BgpLinkAttrProtectionType read(ChannelBuffer cb)
throws BgpParseException {
short lsAttrLength = cb.readShort();
/**
* Returns DedOneIstoOne Bit.
*
* @return DedOneIstoOne Bit
*/
public boolean dedOneIstoOne() {
return bDedOneIstoOne;
if ((lsAttrLength != LINK_PROTECTION_LEN) || (cb.readableBytes() < lsAttrLength)) {
Validation
.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.ATTRIBUTE_LENGTH_ERROR, lsAttrLength);
}
/**
* Returns DedOnePlusOne Bit.
*
* @return DedOnePlusOne Bit
*/
public boolean dedOnePlusOne() {
return bDedOnePlusOne;
byte linkProtectionType = cb.readByte();
byte reserved = cb.readByte();
return BgpLinkAttrProtectionType.of(linkProtectionType);
}
/**
* Returns Enhanced Bit.
* Returns Link Protection Type.
*
* @return Enhanced Bit
* @return Link Protection Type
*/
public boolean enhanced() {
return bEnhanced;
public ProtectionType protectionType() throws BgpParseException {
switch (linkProtectionType) {
case Constants.EXTRA_TRAFFIC:
return ProtectionType.EXTRA_TRAFFIC;
case Constants.UNPROTECTED:
return ProtectionType.UNPROTECTED;
case Constants.SHARED:
return ProtectionType.SHARED;
case Constants.DEDICATED_ONE_ISTO_ONE:
return ProtectionType.DEDICATED_ONE_ISTO_ONE;
case Constants.DEDICATED_ONE_PLUS_ONE:
return ProtectionType.DEDICATED_ONE_PLUS_ONE;
case Constants.ENHANCED:
return ProtectionType.ENHANCED;
case Constants.RESERVED:
return ProtectionType.RESERVED;
default:
throw new BgpParseException("Got another type " + linkProtectionType);
}
}
@Override
......@@ -200,8 +136,7 @@ public final class BgpLinkAttrProtectionType implements BgpValueType {
@Override
public int hashCode() {
return Objects.hash(bExtraTraffic, bUnprotected, bShared,
bDedOneIstoOne, bDedOnePlusOne, bEnhanced);
return Objects.hash(linkProtectionType);
}
@Override
......@@ -212,12 +147,7 @@ public final class BgpLinkAttrProtectionType implements BgpValueType {
if (obj instanceof BgpLinkAttrProtectionType) {
BgpLinkAttrProtectionType other = (BgpLinkAttrProtectionType) obj;
return Objects.equals(bExtraTraffic, other.bExtraTraffic)
&& Objects.equals(bUnprotected, other.bUnprotected)
&& Objects.equals(bShared, other.bShared)
&& Objects.equals(bDedOneIstoOne, other.bDedOneIstoOne)
&& Objects.equals(bDedOnePlusOne, other.bDedOnePlusOne)
&& Objects.equals(bEnhanced, other.bEnhanced);
return Objects.equals(linkProtectionType, other.linkProtectionType);
}
return false;
}
......@@ -231,11 +161,8 @@ public final class BgpLinkAttrProtectionType implements BgpValueType {
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass())
.add("bExtraTraffic", bExtraTraffic)
.add("bUnprotected", bUnprotected).add("bShared", bShared)
.add("bDedOneIstoOne", bDedOneIstoOne)
.add("bDedOnePlusOne", bDedOnePlusOne)
.add("bEnhanced", bEnhanced).toString();
.add("linkProtectionType", linkProtectionType)
.toString();
}
@Override
......
......@@ -33,6 +33,7 @@ import com.google.common.base.MoreObjects;
public class BgpLinkAttrSrlg implements BgpValueType {
public static final short ATTRNODE_SRLG = 1097;
public static final short SIZE = 4;
/* Shared Risk Link Group */
private List<Integer> sRlg = new ArrayList<Integer>();
......@@ -69,7 +70,7 @@ public class BgpLinkAttrSrlg implements BgpValueType {
ArrayList<Integer> sRlg = new ArrayList<Integer>();
short lsAttrLength = cb.readShort();
int len = lsAttrLength / Integer.SIZE; // each element is of 4 octets
int len = lsAttrLength / SIZE; // each element is of 4 octets
if (cb.readableBytes() < lsAttrLength) {
Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR,
......
......@@ -57,7 +57,7 @@ public final class BgpPrefixAttrIgpFlags implements BgpValueType {
* @param bOspfLclAddrBit OSPF local address Bit
* @param bOspfNSSABit OSPF propagate NSSA Bit
*/
BgpPrefixAttrIgpFlags(boolean bisisUpDownBit,
public BgpPrefixAttrIgpFlags(boolean bisisUpDownBit,
boolean bOspfNoUnicastBit,
boolean bOspfLclAddrBit, boolean bOspfNSSABit) {
this.bisisUpDownBit = bisisUpDownBit;
......
......@@ -38,6 +38,7 @@ public class BgpPrefixAttrRouteTag implements BgpValueType {
.getLogger(BgpPrefixAttrRouteTag.class);
public static final short ATTR_PREFIX_ROUTETAG = 1153;
public static final short SIZE = 4;
/* Prefix Route Tag */
private List<Integer> pfxRouteTag = new ArrayList<Integer>();
......@@ -74,7 +75,7 @@ public class BgpPrefixAttrRouteTag implements BgpValueType {
ArrayList<Integer> pfxRouteTag = new ArrayList<Integer>();
short lsAttrLength = cb.readShort();
int len = lsAttrLength / Integer.SIZE;
int len = lsAttrLength / SIZE;
if (cb.readableBytes() < lsAttrLength) {
Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR,
......
......@@ -34,4 +34,11 @@ public final class Constants {
public static final short AFI_VALUE = 16388;
public static final byte VPN_SAFI_VALUE = (byte) 0x80;
public static final byte SAFI_VALUE = 71;
public static final int EXTRA_TRAFFIC = 0x01;
public static final int UNPROTECTED = 0x02;
public static final int SHARED = 0x04;
public static final int DEDICATED_ONE_ISTO_ONE = 0x08;
public static final int DEDICATED_ONE_PLUS_ONE = 0x10;
public static final int ENHANCED = 0x20;
public static final int RESERVED = 0x40;
}
\ No newline at end of file
......
......@@ -23,6 +23,7 @@ import static org.hamcrest.core.Is.is;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;
import org.junit.Test;
import org.onlab.packet.Ip4Address;
import org.onlab.packet.IpAddress;
import org.onlab.packet.IpPrefix;
import org.onosproject.bgpio.exceptions.BgpParseException;
......@@ -41,6 +42,7 @@ import org.onosproject.bgpio.types.BgpValueType;
import org.onosproject.bgpio.types.IPReachabilityInformationTlv;
import org.onosproject.bgpio.types.IsIsNonPseudonode;
import org.onosproject.bgpio.types.IsIsPseudonode;
import org.onosproject.bgpio.types.LinkStateAttributes;
import org.onosproject.bgpio.types.Med;
import org.onosproject.bgpio.types.MpReachNlri;
import org.onosproject.bgpio.types.MpUnReachNlri;
......@@ -48,6 +50,10 @@ import org.onosproject.bgpio.types.Origin;
import org.onosproject.bgpio.types.NextHop;
import org.onosproject.bgpio.types.LocalPref;
import org.onosproject.bgpio.types.Origin.ORIGINTYPE;
import org.onosproject.bgpio.types.attr.BgpAttrRouterIdV4;
import org.onosproject.bgpio.types.attr.BgpLinkAttrName;
import org.onosproject.bgpio.types.attr.BgpPrefixAttrExtRouteTag;
import org.onosproject.bgpio.types.attr.BgpPrefixAttrIgpFlags;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -1493,4 +1499,498 @@ public class BgpUpdateMsgTest {
assertThat(message, instanceOf(BgpUpdateMsg.class));
}
//Negative scenarios
/**
* Wrong length BgpAttrRouterIdV4.
*/
@Test(expected = BgpParseException.class)
public void bgpUpdateMessageTest35() throws BgpParseException {
byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
(byte) 0xff, (byte) 0xff, 0x00, (byte) 0x95,
0x02, 0x00, 0x04,
0x18, 0x0a, 0x01, 0x01, //withdrawn routes
0x00, 0x7A, //path attribute len
0x04, 0x01, 0x01, 0x00, //origin
0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9, //as_path
(byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, //med
(byte) 0x80, 0x0e, 0x53, 0x40, 0x04, 0x47, //mpreach
0x04, 0x04, 0x00, 0x00, 0x01, //nexthop
0x00, //reserved
0x00, 0x02, 0x00, 0x46, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x1b, 0x02, 0x00, 0x00,
0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, 0x04,
0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x07, 0x19, 0x00,
(byte) 0x95, 0x02, 0x50, 0x21, 0x03, 0x01, 0x01, 0x00, 0x1a, 0x02,
0x00, 0x00, 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00,
0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x06, 0x19,
0x00, (byte) 0x95, 0x02, 0x50, 0x21, //link nlri
(byte) 0x80, 0x1d, 0x0f, //linkstate attr
0x04, 0x04, 0x00, 0x06, (byte) 0xbd, 0x59, 0x4c, 0x62, //BgpAttrRouterIdV4
0x04, 0x47, 0x00, 0x03, 0x00, 0x00, 0x0a}; //BgpLinkAttrIGPMetric
ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
buffer.writeBytes(updateMsg);
BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader();
BgpHeader bgpHeader = new BgpHeader();
reader.readFrom(buffer, bgpHeader);
}
/**
* Wrong length BgpLinkAttrIGPMetric.
*/
@Test(expected = BgpParseException.class)
public void bgpUpdateMessageTest36() throws BgpParseException {
byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
(byte) 0xff, (byte) 0xff, 0x00, (byte) 0x95,
0x02, 0x00, 0x04,
0x18, 0x0a, 0x01, 0x01, //withdrawn routes
0x00, 0x7A, //path attribute len
0x04, 0x01, 0x01, 0x00, //origin
0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9, //as_path
(byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, //med
(byte) 0x80, 0x0e, 0x53, 0x40, 0x04, 0x47, //mpreach
0x04, 0x04, 0x00, 0x00, 0x01, //nexthop
0x00, //reserved
0x00, 0x02, 0x00, 0x46, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x1b, 0x02, 0x00, 0x00,
0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, 0x04,
0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x07, 0x19, 0x00,
(byte) 0x95, 0x02, 0x50, 0x21, 0x03, 0x01, 0x01, 0x00, 0x1a, 0x02,
0x00, 0x00, 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00,
0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x06, 0x19,
0x00, (byte) 0x95, 0x02, 0x50, 0x21, //link nlri
(byte) 0x80, 0x1d, 0x0f, //linkstate attr
0x04, 0x04, 0x00, 0x04, (byte) 0xbd, 0x59, 0x4c, 0x62, //BgpAttrRouterIdV4
0x04, 0x47, 0x00, 0x02, 0x00, 0x00, 0x0a}; //BgpLinkAttrIGPMetric
ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
buffer.writeBytes(updateMsg);
BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader();
BgpHeader bgpHeader = new BgpHeader();
reader.readFrom(buffer, bgpHeader);
}
/**
* Wrong length BgpPrefixAttrMetric.
*/
@Test(expected = BgpParseException.class)
public void bgpUpdateMessageTest37() throws BgpParseException {
byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
(byte) 0xff, (byte) 0xff, 0x00, (byte) 0x96,
0x02, 0x00, 0x04,
0x18, 0x0a, 0x01, 0x01, //withdrawn routes
0x00, 0x7b, //path attribute len
0x04, 0x01, 0x01, 0x00, //origin
0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9, //as_path
(byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, //med
(byte) 0x80, 0x0e, 0x53, 0x40, 0x04, 0x47, //mpreach
0x04, 0x04, 0x00, 0x00, 0x01, //nexthop
0x00, //reserved
0x00, 0x02, 0x00, 0x46, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x1b, 0x02, 0x00, 0x00,
0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, 0x04,
0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x07, 0x19, 0x00,
(byte) 0x95, 0x02, 0x50, 0x21, 0x03, 0x01, 0x01, 0x00, 0x1a, 0x02,
0x00, 0x00, 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00,
0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x06, 0x19,
0x00, (byte) 0x95, 0x02, 0x50, 0x21, //link nlri
(byte) 0x80, 0x1d, 0x10, //linkstate attr
0x04, 0x04, 0x00, 0x04, (byte) 0x15, 0x15, 0x15, 0x15, //BgpAttrRouterIdV4
0x04, (byte) 0x83, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00}; //BgpPrefixAttrMetric
ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
buffer.writeBytes(updateMsg);
BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader();
BgpHeader bgpHeader = new BgpHeader();
reader.readFrom(buffer, bgpHeader);
}
/**
* Wrong length BgpPrefixAttrMetric.
*/
@Test(expected = BgpParseException.class)
public void bgpUpdateMessageTest38() throws BgpParseException {
byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
(byte) 0xff, (byte) 0xff, 0x00, (byte) 0x96,
0x02, 0x00, 0x04,
0x18, 0x0a, 0x01, 0x01, //withdrawn routes
0x00, 0x7b, //path attribute len
0x04, 0x01, 0x01, 0x00, //origin
0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9, //as_path
(byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, //med
(byte) 0x80, 0x0e, 0x53, 0x40, 0x04, 0x47, //mpreach
0x04, 0x04, 0x00, 0x00, 0x01, //nexthop
0x00, //reserved
0x00, 0x02, 0x00, 0x46, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x1b, 0x02, 0x00, 0x00,
0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, 0x04,
0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x07, 0x19, 0x00,
(byte) 0x95, 0x02, 0x50, 0x21, 0x03, 0x01, 0x01, 0x00, 0x1a, 0x02,
0x00, 0x00, 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00,
0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x06, 0x19,
0x00, (byte) 0x95, 0x02, 0x50, 0x21, //link nlri
(byte) 0x80, 0x1d, 0x10, //linkstate attr
0x04, 0x04, 0x00, 0x04, (byte) 0x15, 0x15, 0x15, 0x15, //BgpAttrRouterIdV4
0x04, (byte) 0x83, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00}; //BgpPrefixAttrMetric
ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
buffer.writeBytes(updateMsg);
BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader();
BgpHeader bgpHeader = new BgpHeader();
reader.readFrom(buffer, bgpHeader);
}
/**
* Wrong length BgpPrefixAttrOpaqueData.
*/
@Test(expected = BgpParseException.class)
public void bgpUpdateMessageTest39() throws BgpParseException {
byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
(byte) 0xff, (byte) 0xff, 0x00, (byte) 0x96,
0x02, 0x00, 0x04,
0x18, 0x0a, 0x01, 0x01, //withdrawn routes
0x00, 0x7B, //path attribute len
0x04, 0x01, 0x01, 0x00, //origin
0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9, //as_path
(byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, //med
(byte) 0x80, 0x0e, 0x53, 0x40, 0x04, 0x47, //mpreach
0x04, 0x04, 0x00, 0x00, 0x01, //nexthop
0x00, //reserved
0x00, 0x02, 0x00, 0x46, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x1b, 0x02, 0x00, 0x00,
0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, 0x04,
0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x07, 0x19, 0x00,
(byte) 0x95, 0x02, 0x50, 0x21, 0x03, 0x01, 0x01, 0x00, 0x1a, 0x02,
0x00, 0x00, 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00,
0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x06, 0x19,
0x00, (byte) 0x95, 0x02, 0x50, 0x21, //link nlri
(byte) 0x80, 0x1d, 0x10, //linkstate attr
0x04, 0x04, 0x00, 0x04, 0x15, 0x15, 0x15, 0x15, //BgpAttrRouterIdV4
0x04, (byte) 0x85, 0x00, 0x06, 0x0a, 0x0a, 0x0a, 0x0a}; //BgpPrefixAttrOpaqueData
ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
buffer.writeBytes(updateMsg);
BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader();
BgpHeader bgpHeader = new BgpHeader();
reader.readFrom(buffer, bgpHeader);
}
/**
* Test for LinkStateattribute BgpAttrNodeRouterId and BgpLinkAttrName.
*
* @throws BgpParseException while parsing update message
*/
@Test
public void bgpUpdateMessageTest40() throws BgpParseException {
byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
(byte) 0xff, (byte) 0xff, 0x00, (byte) 0x9A,
0x02, 0x00, 0x04,
0x18, 0x0a, 0x01, 0x01, //withdrawn routes
0x00, 0x7F, //path attribute len
0x04, 0x01, 0x01, 0x00, //origin
0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9, //as_path
(byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, //med
(byte) 0x80, 0x0e, 0x53, 0x40, 0x04, 0x47, //mpreach
0x04, 0x04, 0x00, 0x00, 0x01, //nexthop
0x00, //reserved
0x00, 0x02, 0x00, 0x46, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x1b, 0x02, 0x00, 0x00,
0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, 0x04,
0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x07, 0x19, 0x00,
(byte) 0x95, 0x02, 0x50, 0x21, 0x03, 0x01, 0x01, 0x00, 0x1a, 0x02,
0x00, 0x00, 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00,
0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x06, 0x19,
0x00, (byte) 0x95, 0x02, 0x50, 0x21, //link nlri
(byte) 0x80, 0x1d, 0x14, //linkstate attr
0x04, 0x04, 0x00, 0x04, (byte) 0x15, 0x15, 0x15, 0x15, //BgpAttrRouterIdV4
0x04, 0x4A, 0x00, 0x08, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x0b}; //BgpLinkAttrName
ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
buffer.writeBytes(updateMsg);
BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader();
BgpMessage message = null;
BgpHeader bgpHeader = new BgpHeader();
message = reader.readFrom(buffer, bgpHeader);
assertThat(message, instanceOf(BgpUpdateMsg.class));
BgpUpdateMsg other = (BgpUpdateMsg) message;
byte[] marker = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
(byte) 0xff, (byte) 0xff, (byte) 0xff };
assertThat(other.getHeader().getMarker(), is(marker));
assertThat(other.getHeader().getType(), is((byte) 2));
assertThat(other.getHeader().getLength(), is((short) 154));
ListIterator<IpPrefix> listIterator1 = other.withdrawnRoutes().listIterator();
byte[] prefix = new byte[] {0x0a, 0x01, 0x01, 0x00};
while (listIterator1.hasNext()) {
IpPrefix testPrefixValue = listIterator1.next();
assertThat(testPrefixValue.prefixLength(), is((int) 24));
assertThat(testPrefixValue.address().toOctets(), is(prefix));
}
BgpValueType testPathAttribute = null;
Origin origin;
AsPath aspath;
Med med;
MpReachNlri mpReach;
LinkStateAttributes linkStateAttr;
List<BgpValueType> pathAttributeList = new LinkedList<>();
BgpPathAttributes pathAttribute = other.bgpPathAttributes();
pathAttributeList = pathAttribute.pathAttributes();
ListIterator<BgpValueType> listIterator = pathAttributeList.listIterator();
ORIGINTYPE originValue = org.onosproject.bgpio.types.Origin.ORIGINTYPE.IGP;
testPathAttribute = listIterator.next();
origin = (Origin) testPathAttribute;
assertThat(origin.origin(), is(originValue));
testPathAttribute = listIterator.next();
aspath = (AsPath) testPathAttribute;
ListIterator<Short> listIterator2 = aspath.asPathSeq().listIterator();
assertThat(listIterator2.next(), is((short) 65001));
testPathAttribute = listIterator.next();
med = (Med) testPathAttribute;
assertThat(med.med(), is(0));
testPathAttribute = listIterator.next();
mpReach = (MpReachNlri) testPathAttribute;
assertThat(mpReach.mpReachNlriLen(), is((int) 83));
assertThat(mpReach.getType(), is((short) 14));
List<BgpLSNlri> testMpReachNlri = new LinkedList<>();
testMpReachNlri = mpReach.mpReachNlri();
ListIterator<BgpLSNlri> list1 = testMpReachNlri.listIterator();
BgpLSNlri testnlri = list1.next();
NlriType nlriType = org.onosproject.bgpio.protocol.NlriType.LINK;
ProtocolType protocolId = org.onosproject.bgpio.protocol.linkstate.
BgpNodeLSNlriVer4.ProtocolType.ISIS_LEVEL_TWO;
assertThat(testnlri.getIdentifier(), is((long) 0));
assertThat(testnlri.getNlriType(), is(nlriType));
assertThat(testnlri.getProtocolId(), is(protocolId));
testPathAttribute = listIterator.next();
linkStateAttr = (LinkStateAttributes) testPathAttribute;
assertThat(linkStateAttr.getType(), is((short) 29));
ListIterator<BgpValueType> list = linkStateAttr.linkStateAttributes().listIterator();
byte[] ipBytes = new byte[] {(byte) 0x15, 0x15, 0x15, 0x15 };
Ip4Address ip4RouterId = Ip4Address.valueOf(ipBytes);
assertThat(((BgpAttrRouterIdV4) list.next()).attrRouterId(), is(ip4RouterId));
byte[] linkName = new byte[] {0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x0b };
assertThat(((BgpLinkAttrName) list.next()).attrLinkName(), is(linkName));
}
/**
* Test for LinkStateattribute BgpAttrNodeRouterId and BgpPrefixAttrIGPFlags.
*
* @throws BgpParseException while parsing update message
*/
@Test
public void bgpUpdateMessageTest41() throws BgpParseException {
byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
(byte) 0xff, (byte) 0xff, 0x00, (byte) 0x93,
0x02, 0x00, 0x04,
0x18, 0x0a, 0x01, 0x01, //withdrawn routes
0x00, 0x78, //path attribute len
0x04, 0x01, 0x01, 0x00, //origin
0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9, //as_path
(byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, //med
(byte) 0x80, 0x0e, 0x53, 0x40, 0x04, 0x47, //mpreach
0x04, 0x04, 0x00, 0x00, 0x01, //nexthop
0x00, //reserved
0x00, 0x02, 0x00, 0x46, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x1b, 0x02, 0x00, 0x00,
0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, 0x04,
0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x07, 0x19, 0x00,
(byte) 0x95, 0x02, 0x50, 0x21, 0x03, 0x01, 0x01, 0x00, 0x1a, 0x02,
0x00, 0x00, 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00,
0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x06, 0x19,
0x00, (byte) 0x95, 0x02, 0x50, 0x21, //link nlri
(byte) 0x80, 0x1d, 0x0D, //linkstate attr
0x04, 0x04, 0x00, 0x04, (byte) 0x15, 0x15, 0x15, 0x15, //BgpAttrRouterIdV4
0x04, (byte) 0x80, 0x00, 0x01, (byte) 0xA0}; //BgpPrefixAttrIGPFlags
ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
buffer.writeBytes(updateMsg);
BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader();
BgpMessage message = null;
BgpHeader bgpHeader = new BgpHeader();
message = reader.readFrom(buffer, bgpHeader);
assertThat(message, instanceOf(BgpUpdateMsg.class));
BgpUpdateMsg other = (BgpUpdateMsg) message;
byte[] marker = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
(byte) 0xff, (byte) 0xff, (byte) 0xff };
assertThat(other.getHeader().getMarker(), is(marker));
assertThat(other.getHeader().getType(), is((byte) 2));
assertThat(other.getHeader().getLength(), is((short) 147));
BgpValueType testPathAttribute = null;
Origin origin;
AsPath aspath;
Med med;
MpReachNlri mpReach;
LinkStateAttributes linkStateAttr;
List<BgpValueType> pathAttributeList = new LinkedList<>();
BgpPathAttributes pathAttribute = other.bgpPathAttributes();
pathAttributeList = pathAttribute.pathAttributes();
ListIterator<BgpValueType> listIterator = pathAttributeList.listIterator();
ORIGINTYPE originValue = org.onosproject.bgpio.types.Origin.ORIGINTYPE.IGP;
testPathAttribute = listIterator.next();
origin = (Origin) testPathAttribute;
assertThat(origin.origin(), is(originValue));
testPathAttribute = listIterator.next();
aspath = (AsPath) testPathAttribute;
ListIterator<Short> listIterator2 = aspath.asPathSeq().listIterator();
assertThat(listIterator2.next(), is((short) 65001));
testPathAttribute = listIterator.next();
med = (Med) testPathAttribute;
assertThat(med.med(), is(0));
testPathAttribute = listIterator.next();
mpReach = (MpReachNlri) testPathAttribute;
List<BgpLSNlri> testMpReachNlri = new LinkedList<>();
testMpReachNlri = mpReach.mpReachNlri();
ListIterator<BgpLSNlri> list1 = testMpReachNlri.listIterator();
BgpLSNlri testnlri = list1.next();
NlriType nlriType = org.onosproject.bgpio.protocol.NlriType.LINK;
ProtocolType protocolId = org.onosproject.bgpio.protocol.linkstate.
BgpNodeLSNlriVer4.ProtocolType.ISIS_LEVEL_TWO;
assertThat(testnlri.getIdentifier(), is((long) 0));
assertThat(testnlri.getNlriType(), is(nlriType));
assertThat(testnlri.getProtocolId(), is(protocolId));
testPathAttribute = listIterator.next();
linkStateAttr = (LinkStateAttributes) testPathAttribute;
assertThat(linkStateAttr.getType(), is((short) 29));
ListIterator<BgpValueType> list = linkStateAttr.linkStateAttributes().listIterator();
byte[] ipBytes = new byte[] {(byte) 0x15, 0x15, 0x15, 0x15 };
Ip4Address ip4RouterId = Ip4Address.valueOf(ipBytes);
assertThat(((BgpAttrRouterIdV4) list.next()).attrRouterId(), is(ip4RouterId));
BgpPrefixAttrIgpFlags obj = new BgpPrefixAttrIgpFlags(true, false, true, false);
assertThat(((BgpPrefixAttrIgpFlags) list.next()).equals(obj), is(true));
}
/**
* Test for LinkStateattribute BgpAttrNodeRouterId and BgpPrefixAttrExtRouteTag.
*
* @throws BgpParseException while parsing update message
*/
@Test
public void bgpUpdateMessageTest42() throws BgpParseException {
byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
(byte) 0xff, (byte) 0xff, 0x00, (byte) 0xA2, 0x02, 0x00, 0x04,
0x18, 0x0a, 0x01, 0x01, 0x00, (byte) 0x87, 0x04, 0x01, 0x01, 0x00, //origin
0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9, //as_path
(byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, //med
(byte) 0x80, 0x0e, 0x53, 0x40, 0x04, 0x47, //mpreach
0x04, 0x04, 0x00, 0x00, 0x01, 0x00, //reserved
0x00, 0x02, 0x00, 0x46, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x1b, 0x02, 0x00, 0x00,
0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, 0x04,
0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x07, 0x19, 0x00,
(byte) 0x95, 0x02, 0x50, 0x21, 0x03, 0x01, 0x01, 0x00, 0x1a, 0x02,
0x00, 0x00, 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00,
0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x06, 0x19,
0x00, (byte) 0x95, 0x02, 0x50, 0x21, (byte) 0x80, 0x1d, 0x1C, //linkstate attr
0x04, 0x04, 0x00, 0x04, (byte) 0x15, 0x15, 0x15, 0x15, //BgpAttrNodeRouterId
0x04, (byte) 0x82, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x02, (byte) 0xBB, (byte) 0xE9, 0x0B,
0x00, 0x00, 0x00, 0x00, 0x03, 0x20, 0x6E, 0x1B}; //BgpPrefixAttrExtRouteTag
ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
buffer.writeBytes(updateMsg);
BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader();
BgpMessage message = null;
BgpHeader bgpHeader = new BgpHeader();
message = reader.readFrom(buffer, bgpHeader);
assertThat(message, instanceOf(BgpUpdateMsg.class));
BgpUpdateMsg other = (BgpUpdateMsg) message;
byte[] marker = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
(byte) 0xff, (byte) 0xff, (byte) 0xff };
assertThat(other.getHeader().getMarker(), is(marker));
assertThat(other.getHeader().getType(), is((byte) 2));
assertThat(other.getHeader().getLength(), is((short) 162));
BgpValueType testPathAttribute = null;
Origin origin;
AsPath aspath;
Med med;
MpReachNlri mpReach;
LinkStateAttributes linkStateAttr;
List<BgpValueType> pathAttributeList = new LinkedList<>();
BgpPathAttributes pathAttribute = other.bgpPathAttributes();
pathAttributeList = pathAttribute.pathAttributes();
ListIterator<BgpValueType> listIterator = pathAttributeList.listIterator();
ORIGINTYPE originValue = org.onosproject.bgpio.types.Origin.ORIGINTYPE.IGP;
testPathAttribute = listIterator.next();
origin = (Origin) testPathAttribute;
assertThat(origin.origin(), is(originValue));
testPathAttribute = listIterator.next();
aspath = (AsPath) testPathAttribute;
ListIterator<Short> listIterator2 = aspath.asPathSeq().listIterator();
assertThat(listIterator2.next(), is((short) 65001));
testPathAttribute = listIterator.next();
med = (Med) testPathAttribute;
assertThat(med.med(), is(0));
testPathAttribute = listIterator.next();
mpReach = (MpReachNlri) testPathAttribute;
List<BgpLSNlri> testMpReachNlri = new LinkedList<>();
testMpReachNlri = mpReach.mpReachNlri();
ListIterator<BgpLSNlri> list1 = testMpReachNlri.listIterator();
BgpLSNlri testnlri = list1.next();
ProtocolType protocolId = org.onosproject.bgpio.protocol.linkstate.
BgpNodeLSNlriVer4.ProtocolType.ISIS_LEVEL_TWO;
assertThat(testnlri.getProtocolId(), is(protocolId));
testPathAttribute = listIterator.next();
linkStateAttr = (LinkStateAttributes) testPathAttribute;
assertThat(linkStateAttr.getType(), is((short) 29));
ListIterator<BgpValueType> list = linkStateAttr.linkStateAttributes().listIterator();
byte[] ipBytes = new byte[] {(byte) 0x15, 0x15, 0x15, 0x15 };
Ip4Address ip4RouterId = Ip4Address.valueOf(ipBytes);
assertThat(((BgpAttrRouterIdV4) list.next()).attrRouterId(), is(ip4RouterId));
List<Long> extRouteTag = new LinkedList<>();
extRouteTag.add(45869323L);
extRouteTag.add(52456987L);
assertThat(((BgpPrefixAttrExtRouteTag) list.next()).pfxExtRouteTag(), is(extRouteTag));
}
}
......
......@@ -20,37 +20,20 @@ import org.junit.Test;
import com.google.common.testing.EqualsTester;
/**
* Test for MPLS protocol mask attribute.
* Test for Protection Type attribute.
*/
public class BgpLinkAttrProtectionTypeTest {
boolean bExtraTraffic = true;
boolean bUnprotected = true;
boolean bShared = true;
boolean bDedOneIstoOne = true;
boolean bDedOnePlusOne = true;
boolean bEnhanced = true;
private final byte linkProtectionType1 = 0x04;
private final byte linkProtectionType2 = 0x40;
boolean bExtraTraffic1 = false;
boolean bUnprotected1 = false;
boolean bShared1 = false;
boolean bDedOneIstoOne1 = false;
boolean bDedOnePlusOne1 = false;
boolean bEnhanced1 = false;
private final BgpLinkAttrProtectionType data = BgpLinkAttrProtectionType
.of(bExtraTraffic, bUnprotected, bShared, bDedOneIstoOne,
bDedOnePlusOne, bEnhanced);
private final BgpLinkAttrProtectionType sameAsData = BgpLinkAttrProtectionType
.of(bExtraTraffic, bUnprotected, bShared, bDedOneIstoOne,
bDedOnePlusOne, bEnhanced);
private final BgpLinkAttrProtectionType diffData = BgpLinkAttrProtectionType
.of(bExtraTraffic1, bUnprotected1, bShared1, bDedOneIstoOne1,
bDedOnePlusOne1, bEnhanced1);
private final BgpLinkAttrProtectionType attr1 = BgpLinkAttrProtectionType.of(linkProtectionType1);
private final BgpLinkAttrProtectionType sameAsAttr1 = BgpLinkAttrProtectionType.of(linkProtectionType1);
private final BgpLinkAttrProtectionType attr2 = BgpLinkAttrProtectionType.of(linkProtectionType2);
@Test
public void basics() {
new EqualsTester().addEqualityGroup(data, sameAsData)
.addEqualityGroup(diffData).testEquals();
public void testEquality() {
new EqualsTester().addEqualityGroup(attr1, sameAsAttr1)
.addEqualityGroup(attr2)
.testEquals();
}
}
......