Shashikanth VH
Committed by Gerrit Code Review

BGP flow spec system test update message parsing issues fix.

Change-Id: Ic2d615e1f449e93d937802ce3f9f33e468d42423
......@@ -59,7 +59,12 @@ public class BgpFlowSpecPrefix implements Comparable<Object> {
if (obj instanceof BgpFlowSpecPrefix) {
BgpFlowSpecPrefix other = (BgpFlowSpecPrefix) obj;
if (this.destinationPrefix.equals(other.destinationPrefix)) {
if ((this.destinationPrefix != null) && (this.sourcePrefix != null)
&& (this.destinationPrefix.equals(other.destinationPrefix))) {
return this.sourcePrefix.equals(other.sourcePrefix);
} else if (this.destinationPrefix != null) {
return this.destinationPrefix.equals(other.destinationPrefix);
} else if (this.sourcePrefix != null) {
return this.sourcePrefix.equals(other.sourcePrefix);
}
return false;
......@@ -106,7 +111,7 @@ public class BgpFlowSpecPrefix implements Comparable<Object> {
if (o instanceof BgpFlowSpecPrefix) {
BgpFlowSpecPrefix that = (BgpFlowSpecPrefix) o;
if (this.destinationPrefix() != null) {
if (this.destinationPrefix().prefixLength() == that.destinationPrefix().prefixLength()) {
ByteBuffer value1 = ByteBuffer.wrap(this.destinationPrefix().address().toOctets());
ByteBuffer value2 = ByteBuffer.wrap(that.destinationPrefix().address().toOctets());
......@@ -121,7 +126,8 @@ public class BgpFlowSpecPrefix implements Comparable<Object> {
return -1;
}
}
}
if (this.sourcePrefix() != null) {
if (this.sourcePrefix().prefixLength() == that.sourcePrefix().prefixLength()) {
ByteBuffer value1 = ByteBuffer.wrap(this.sourcePrefix().address().toOctets());
ByteBuffer value2 = ByteBuffer.wrap(that.sourcePrefix().address().toOctets());
......@@ -134,6 +140,8 @@ public class BgpFlowSpecPrefix implements Comparable<Object> {
return -1;
}
}
return 0;
}
return 1;
}
}
......
......@@ -105,11 +105,11 @@ public class BgpExtendedCommunity implements BgpValueType {
default: log.debug("Other type Not Supported:" + actionType);
break;
}
}
if (fsActionTlv != null) {
fsActionTlvs.add(fsActionTlv);
}
}
}
return new BgpExtendedCommunity(fsActionTlvs);
}
......
......@@ -30,6 +30,7 @@ public class BgpFsActionReDirect implements BgpValueType {
public static final short TYPE = Constants.BGP_FLOWSPEC_ACTION_TRAFFIC_REDIRECT;
private byte[] routeTarget;
public static final byte ROUTE_TARGET_LEN = 6;
/**
* Constructor to initialize the value.
......@@ -82,9 +83,8 @@ public class BgpFsActionReDirect implements BgpValueType {
*/
public static BgpFsActionReDirect read(ChannelBuffer cb) throws BgpParseException {
byte[] routeTarget;
ChannelBuffer tempCb = cb.copy();
routeTarget = tempCb.readBytes(tempCb.readableBytes()).array();
routeTarget = cb.readBytes(ROUTE_TARGET_LEN).array();
return new BgpFsActionReDirect(routeTarget);
}
......
......@@ -30,6 +30,7 @@ public class BgpFsActionTrafficAction implements BgpValueType {
public static final short TYPE = Constants.BGP_FLOWSPEC_ACTION_TRAFFIC_ACTION;
private byte[] bitMask;
public static final byte BIT_MASK_LEN = 6;
/**
* Constructor to initialize the value.
......@@ -82,9 +83,8 @@ public class BgpFsActionTrafficAction implements BgpValueType {
*/
public static BgpFsActionTrafficAction read(ChannelBuffer cb) throws BgpParseException {
byte[] bitMask;
ChannelBuffer tempCb = cb.copy();
bitMask = tempCb.readBytes(tempCb.readableBytes()).array();
bitMask = cb.readBytes(BIT_MASK_LEN).array();
return new BgpFsActionTrafficAction(bitMask);
}
......
......@@ -30,6 +30,7 @@ public class BgpFsActionTrafficMarking implements BgpValueType {
public static final short TYPE = Constants.BGP_FLOWSPEC_ACTION_TRAFFIC_MARKING;
private byte[] dscpValue;
public static final byte DSCP_LEN = 6;
/**
* Constructor to initialize the value.
......@@ -82,9 +83,8 @@ public class BgpFsActionTrafficMarking implements BgpValueType {
*/
public static BgpFsActionTrafficMarking read(ChannelBuffer cb) throws BgpParseException {
byte[] dscpValue;
ChannelBuffer tempCb = cb.copy();
dscpValue = tempCb.readBytes(tempCb.readableBytes()).array();
dscpValue = cb.readBytes(DSCP_LEN).array();
return new BgpFsActionTrafficMarking(dscpValue);
}
......
......@@ -86,10 +86,9 @@ public class BgpFsActionTrafficRate implements BgpValueType {
public static BgpFsActionTrafficRate read(ChannelBuffer cb) throws BgpParseException {
short asn;
float rate;
ChannelBuffer tempCb = cb.copy();
asn = tempCb.readShort();
rate = tempCb.readFloat();
asn = cb.readShort();
rate = cb.readFloat();
return new BgpFsActionTrafficRate(asn, rate);
}
......
......@@ -239,7 +239,7 @@ public class MpReachNlri implements BgpValueType {
flowSpecComponent = BgpFsIcmpType.read(tempBuf);
break;
case Constants.BGP_FLOWSPEC_ICMP_CD:
flowSpecComponent = BgpFsIcmpType.read(tempBuf);
flowSpecComponent = BgpFsIcmpCode.read(tempBuf);
break;
case Constants.BGP_FLOWSPEC_TCP_FLAGS:
flowSpecComponent = BgpFsTcpFlags.read(tempBuf);
......
......@@ -59,9 +59,9 @@ public final class Constants {
public static final byte BGP_FLOWSPEC_ICMP_TP = 0x07;
public static final byte BGP_FLOWSPEC_ICMP_CD = 0x08;
public static final byte BGP_FLOWSPEC_TCP_FLAGS = 0x09;
public static final byte BGP_FLOWSPEC_PCK_LEN = 0x10;
public static final byte BGP_FLOWSPEC_DSCP = 0x11;
public static final byte BGP_FLOWSPEC_FRAGMENT = 0x12;
public static final byte BGP_FLOWSPEC_PCK_LEN = 0x0a;
public static final byte BGP_FLOWSPEC_DSCP = 0x0b;
public static final byte BGP_FLOWSPEC_FRAGMENT = 0x0c;
public static final short BGP_FLOWSPEC_ACTION_TRAFFIC_RATE = (short) 0x8006;
public static final short BGP_FLOWSPEC_ACTION_TRAFFIC_ACTION = (short) 0x8007;
......
......@@ -40,18 +40,106 @@ public class MpReachNlriTest {
public void mpReachNlriTest1() throws BgpParseException {
// BGP flow spec Message
byte[] flowSpecMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff,
byte[] flowSpecMsg = 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, 0x00, 0x4a, 0x02, 0x00, 0x00, 0x00,
0x33, 0x40, 0x01, 0x01, 0x00, 0x40, 0x02, 0x04,
0x02, 0x01, 0x00, 0x64, (byte) 0x80, 0x04, 0x04, 0x00,
0x00, 0x00, 0x00, (byte) 0xc0, 0x10, 0x08, (byte) 0x80, 0x06,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, (byte) 0x90, 0x0e,
0x00, 0x12, 0x00, 0x01, (byte) 0x85, 0x00, 0x00, 0x0c,
0x02, 0x20, (byte) 0xc0, (byte) 0xa8, 0x07, 0x36, 0x03, (byte) 0x81,
0x67, 0x04, (byte) 0x81, 0x01};
(byte) 0xff, (byte) 0xff, 0x00, 0x4a, 0x02, 0x00, 0x00, 0x00,
0x33, 0x40, 0x01, 0x01, 0x00, 0x40, 0x02, 0x04, 0x02, 0x01,
0x00, 0x64, (byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00,
(byte) 0xc0, 0x10, 0x08, (byte) 0x80, 0x06, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, (byte) 0x90, 0x0e, 0x00, 0x12, 0x00, 0x01,
(byte) 0x85, 0x00, 0x00, 0x0c, 0x02, 0x20, (byte) 0xc0,
(byte) 0xa8, 0x07, 0x36, 0x03, (byte) 0x81, 0x67, 0x04,
(byte) 0x81, 0x01 };
byte[] testFsMsg;
ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
buffer.writeBytes(flowSpecMsg);
BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader();
BgpMessage message;
BgpHeader bgpHeader = new BgpHeader();
message = reader.readFrom(buffer, bgpHeader);
assertThat(message, instanceOf(BgpUpdateMsgVer4.class));
ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
message.writeTo(buf);
int readLen = buf.writerIndex();
testFsMsg = new byte[readLen];
buf.readBytes(testFsMsg, 0, readLen);
assertThat(testFsMsg, is(flowSpecMsg));
}
/**
* This testcase checks BGP update message.
*/
@Test
public void mpReachNlriTest2() throws BgpParseException {
// BGP flow spec Message
byte[] flowSpecMsg = 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, 0x52, 0x02, 0x00, 0x00, 0x00,
0x3b, 0x40, 0x01, 0x01, 0x01, 0x40, 0x02, 0x04, 0x02, 0x01,
0x00, (byte) 0xc8, (byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00,
0x00, (byte) 0xc0, 0x10, 0x10, (byte) 0x80, 0x06, 0x00, 0x7b,
0x40, 0x60, 0x00, 0x00, (byte) 0x80, 0x09, 0x00, 0x00, 0x00,
0x00, 0x00, 0x0f, (byte) 0x90, 0x0e, 0x00, 0x12, 0x00, 0x01,
(byte) 0x85, 0x00, 0x00, 0x0c, 0x01, 0x1e, (byte) 0xc0,
(byte) 0xa8, 0x02, 0x00, 0x02, 0x1e, (byte) 0xc0, (byte) 0xa8,
0x01, 0x00 };
byte[] testFsMsg;
ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
buffer.writeBytes(flowSpecMsg);
BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader();
BgpMessage message;
BgpHeader bgpHeader = new BgpHeader();
message = reader.readFrom(buffer, bgpHeader);
assertThat(message, instanceOf(BgpUpdateMsgVer4.class));
ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
message.writeTo(buf);
int readLen = buf.writerIndex();
testFsMsg = new byte[readLen];
buf.readBytes(testFsMsg, 0, readLen);
assertThat(testFsMsg, is(flowSpecMsg));
}
/**
* This testcase checks BGP update message.
*/
@Test
public void mpReachNlriTest3() throws BgpParseException {
// BGP flow spec Message
byte[] flowSpecMsg = 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, 0x71, 0x02, 0x00, 0x00, 0x00,
0x5a, 0x40, 0x01, 0x01, 0x01, 0x40, 0x02, 0x04, 0x02, 0x01,
0x00, (byte) 0xc8, (byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00,
0x00, (byte) 0xc0, 0x10, 0x10, (byte) 0x80, 0x06, 0x00, 0x7b,
0x40, 0x60, 0x00, 0x00, (byte) 0x80, 0x09, 0x00, 0x00, 0x00,
0x00, 0x00, 0x0f, (byte) 0x90, 0x0e, 0x00, 0x31, 0x00, 0x01,
(byte) 0x85, 0x00, 0x00, 0x2b, 0x01, 0x1e, (byte) 0xc0,
(byte) 0xa8, 0x02, 0x00, 0x02, 0x1e, (byte) 0xc0, (byte) 0xa8,
0x01, 0x00, 0x03, (byte) 0x80, 0x04, 0x04, (byte) 0x80,
(byte) 0xb3, 0x05, (byte) 0x80, (byte) 0xc8, 0x06, (byte) 0x80,
0x64, 0x07, (byte) 0x80, 0x7b, 0x08, (byte) 0x80, (byte) 0xea,
0x09, (byte) 0x80, 0x7b, 0x0a, (byte) 0x90, 0x03, (byte) 0xe8,
0x0b, (byte) 0x80, 0x7b, 0x0c, (byte) 0x80, 0x02 };
byte[] testFsMsg;
ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
......