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> { ...@@ -59,7 +59,12 @@ public class BgpFlowSpecPrefix implements Comparable<Object> {
59 if (obj instanceof BgpFlowSpecPrefix) { 59 if (obj instanceof BgpFlowSpecPrefix) {
60 BgpFlowSpecPrefix other = (BgpFlowSpecPrefix) obj; 60 BgpFlowSpecPrefix other = (BgpFlowSpecPrefix) obj;
61 61
62 - if (this.destinationPrefix.equals(other.destinationPrefix)) { 62 + if ((this.destinationPrefix != null) && (this.sourcePrefix != null)
63 + && (this.destinationPrefix.equals(other.destinationPrefix))) {
64 + return this.sourcePrefix.equals(other.sourcePrefix);
65 + } else if (this.destinationPrefix != null) {
66 + return this.destinationPrefix.equals(other.destinationPrefix);
67 + } else if (this.sourcePrefix != null) {
63 return this.sourcePrefix.equals(other.sourcePrefix); 68 return this.sourcePrefix.equals(other.sourcePrefix);
64 } 69 }
65 return false; 70 return false;
...@@ -106,33 +111,36 @@ public class BgpFlowSpecPrefix implements Comparable<Object> { ...@@ -106,33 +111,36 @@ public class BgpFlowSpecPrefix implements Comparable<Object> {
106 111
107 if (o instanceof BgpFlowSpecPrefix) { 112 if (o instanceof BgpFlowSpecPrefix) {
108 BgpFlowSpecPrefix that = (BgpFlowSpecPrefix) o; 113 BgpFlowSpecPrefix that = (BgpFlowSpecPrefix) o;
109 - 114 + if (this.destinationPrefix() != null) {
110 - if (this.destinationPrefix().prefixLength() == that.destinationPrefix().prefixLength()) { 115 + if (this.destinationPrefix().prefixLength() == that.destinationPrefix().prefixLength()) {
111 - ByteBuffer value1 = ByteBuffer.wrap(this.destinationPrefix().address().toOctets()); 116 + ByteBuffer value1 = ByteBuffer.wrap(this.destinationPrefix().address().toOctets());
112 - ByteBuffer value2 = ByteBuffer.wrap(that.destinationPrefix().address().toOctets()); 117 + ByteBuffer value2 = ByteBuffer.wrap(that.destinationPrefix().address().toOctets());
113 - int cmpVal = value1.compareTo(value2); 118 + int cmpVal = value1.compareTo(value2);
114 - if (cmpVal != 0) { 119 + if (cmpVal != 0) {
115 - return cmpVal; 120 + return cmpVal;
121 + }
122 + } else {
123 + if (this.destinationPrefix().prefixLength() > that.destinationPrefix().prefixLength()) {
124 + return 1;
125 + } else if (this.destinationPrefix().prefixLength() < that.destinationPrefix().prefixLength()) {
126 + return -1;
127 + }
116 } 128 }
117 - } else { 129 + }
118 - if (this.destinationPrefix().prefixLength() > that.destinationPrefix().prefixLength()) { 130 + if (this.sourcePrefix() != null) {
131 + if (this.sourcePrefix().prefixLength() == that.sourcePrefix().prefixLength()) {
132 + ByteBuffer value1 = ByteBuffer.wrap(this.sourcePrefix().address().toOctets());
133 + ByteBuffer value2 = ByteBuffer.wrap(that.sourcePrefix().address().toOctets());
134 + return value1.compareTo(value2);
135 + }
136 +
137 + if (this.sourcePrefix().prefixLength() > that.sourcePrefix().prefixLength()) {
119 return 1; 138 return 1;
120 - } else if (this.destinationPrefix().prefixLength() < that.destinationPrefix().prefixLength()) { 139 + } else if (this.sourcePrefix().prefixLength() < that.sourcePrefix().prefixLength()) {
121 return -1; 140 return -1;
122 } 141 }
123 } 142 }
124 - 143 + return 0;
125 - if (this.sourcePrefix().prefixLength() == that.sourcePrefix().prefixLength()) {
126 - ByteBuffer value1 = ByteBuffer.wrap(this.sourcePrefix().address().toOctets());
127 - ByteBuffer value2 = ByteBuffer.wrap(that.sourcePrefix().address().toOctets());
128 - return value1.compareTo(value2);
129 - }
130 -
131 - if (this.sourcePrefix().prefixLength() > that.sourcePrefix().prefixLength()) {
132 - return 1;
133 - } else if (this.sourcePrefix().prefixLength() < that.sourcePrefix().prefixLength()) {
134 - return -1;
135 - }
136 } 144 }
137 return 1; 145 return 1;
138 } 146 }
......
...@@ -105,9 +105,9 @@ public class BgpExtendedCommunity implements BgpValueType { ...@@ -105,9 +105,9 @@ public class BgpExtendedCommunity implements BgpValueType {
105 default: log.debug("Other type Not Supported:" + actionType); 105 default: log.debug("Other type Not Supported:" + actionType);
106 break; 106 break;
107 } 107 }
108 - } 108 + if (fsActionTlv != null) {
109 - if (fsActionTlv != null) { 109 + fsActionTlvs.add(fsActionTlv);
110 - fsActionTlvs.add(fsActionTlv); 110 + }
111 } 111 }
112 } 112 }
113 return new BgpExtendedCommunity(fsActionTlvs); 113 return new BgpExtendedCommunity(fsActionTlvs);
......
...@@ -30,6 +30,7 @@ public class BgpFsActionReDirect implements BgpValueType { ...@@ -30,6 +30,7 @@ public class BgpFsActionReDirect implements BgpValueType {
30 30
31 public static final short TYPE = Constants.BGP_FLOWSPEC_ACTION_TRAFFIC_REDIRECT; 31 public static final short TYPE = Constants.BGP_FLOWSPEC_ACTION_TRAFFIC_REDIRECT;
32 private byte[] routeTarget; 32 private byte[] routeTarget;
33 + public static final byte ROUTE_TARGET_LEN = 6;
33 34
34 /** 35 /**
35 * Constructor to initialize the value. 36 * Constructor to initialize the value.
...@@ -82,9 +83,8 @@ public class BgpFsActionReDirect implements BgpValueType { ...@@ -82,9 +83,8 @@ public class BgpFsActionReDirect implements BgpValueType {
82 */ 83 */
83 public static BgpFsActionReDirect read(ChannelBuffer cb) throws BgpParseException { 84 public static BgpFsActionReDirect read(ChannelBuffer cb) throws BgpParseException {
84 byte[] routeTarget; 85 byte[] routeTarget;
85 - ChannelBuffer tempCb = cb.copy();
86 86
87 - routeTarget = tempCb.readBytes(tempCb.readableBytes()).array(); 87 + routeTarget = cb.readBytes(ROUTE_TARGET_LEN).array();
88 return new BgpFsActionReDirect(routeTarget); 88 return new BgpFsActionReDirect(routeTarget);
89 } 89 }
90 90
......
...@@ -30,6 +30,7 @@ public class BgpFsActionTrafficAction implements BgpValueType { ...@@ -30,6 +30,7 @@ public class BgpFsActionTrafficAction implements BgpValueType {
30 30
31 public static final short TYPE = Constants.BGP_FLOWSPEC_ACTION_TRAFFIC_ACTION; 31 public static final short TYPE = Constants.BGP_FLOWSPEC_ACTION_TRAFFIC_ACTION;
32 private byte[] bitMask; 32 private byte[] bitMask;
33 + public static final byte BIT_MASK_LEN = 6;
33 34
34 /** 35 /**
35 * Constructor to initialize the value. 36 * Constructor to initialize the value.
...@@ -82,9 +83,8 @@ public class BgpFsActionTrafficAction implements BgpValueType { ...@@ -82,9 +83,8 @@ public class BgpFsActionTrafficAction implements BgpValueType {
82 */ 83 */
83 public static BgpFsActionTrafficAction read(ChannelBuffer cb) throws BgpParseException { 84 public static BgpFsActionTrafficAction read(ChannelBuffer cb) throws BgpParseException {
84 byte[] bitMask; 85 byte[] bitMask;
85 - ChannelBuffer tempCb = cb.copy();
86 86
87 - bitMask = tempCb.readBytes(tempCb.readableBytes()).array(); 87 + bitMask = cb.readBytes(BIT_MASK_LEN).array();
88 return new BgpFsActionTrafficAction(bitMask); 88 return new BgpFsActionTrafficAction(bitMask);
89 } 89 }
90 90
......
...@@ -30,6 +30,7 @@ public class BgpFsActionTrafficMarking implements BgpValueType { ...@@ -30,6 +30,7 @@ public class BgpFsActionTrafficMarking implements BgpValueType {
30 30
31 public static final short TYPE = Constants.BGP_FLOWSPEC_ACTION_TRAFFIC_MARKING; 31 public static final short TYPE = Constants.BGP_FLOWSPEC_ACTION_TRAFFIC_MARKING;
32 private byte[] dscpValue; 32 private byte[] dscpValue;
33 + public static final byte DSCP_LEN = 6;
33 34
34 /** 35 /**
35 * Constructor to initialize the value. 36 * Constructor to initialize the value.
...@@ -82,9 +83,8 @@ public class BgpFsActionTrafficMarking implements BgpValueType { ...@@ -82,9 +83,8 @@ public class BgpFsActionTrafficMarking implements BgpValueType {
82 */ 83 */
83 public static BgpFsActionTrafficMarking read(ChannelBuffer cb) throws BgpParseException { 84 public static BgpFsActionTrafficMarking read(ChannelBuffer cb) throws BgpParseException {
84 byte[] dscpValue; 85 byte[] dscpValue;
85 - ChannelBuffer tempCb = cb.copy();
86 86
87 - dscpValue = tempCb.readBytes(tempCb.readableBytes()).array(); 87 + dscpValue = cb.readBytes(DSCP_LEN).array();
88 return new BgpFsActionTrafficMarking(dscpValue); 88 return new BgpFsActionTrafficMarking(dscpValue);
89 } 89 }
90 90
......
...@@ -86,10 +86,9 @@ public class BgpFsActionTrafficRate implements BgpValueType { ...@@ -86,10 +86,9 @@ public class BgpFsActionTrafficRate implements BgpValueType {
86 public static BgpFsActionTrafficRate read(ChannelBuffer cb) throws BgpParseException { 86 public static BgpFsActionTrafficRate read(ChannelBuffer cb) throws BgpParseException {
87 short asn; 87 short asn;
88 float rate; 88 float rate;
89 - ChannelBuffer tempCb = cb.copy();
90 89
91 - asn = tempCb.readShort(); 90 + asn = cb.readShort();
92 - rate = tempCb.readFloat(); 91 + rate = cb.readFloat();
93 return new BgpFsActionTrafficRate(asn, rate); 92 return new BgpFsActionTrafficRate(asn, rate);
94 } 93 }
95 94
......
...@@ -239,7 +239,7 @@ public class MpReachNlri implements BgpValueType { ...@@ -239,7 +239,7 @@ public class MpReachNlri implements BgpValueType {
239 flowSpecComponent = BgpFsIcmpType.read(tempBuf); 239 flowSpecComponent = BgpFsIcmpType.read(tempBuf);
240 break; 240 break;
241 case Constants.BGP_FLOWSPEC_ICMP_CD: 241 case Constants.BGP_FLOWSPEC_ICMP_CD:
242 - flowSpecComponent = BgpFsIcmpType.read(tempBuf); 242 + flowSpecComponent = BgpFsIcmpCode.read(tempBuf);
243 break; 243 break;
244 case Constants.BGP_FLOWSPEC_TCP_FLAGS: 244 case Constants.BGP_FLOWSPEC_TCP_FLAGS:
245 flowSpecComponent = BgpFsTcpFlags.read(tempBuf); 245 flowSpecComponent = BgpFsTcpFlags.read(tempBuf);
......
...@@ -59,9 +59,9 @@ public final class Constants { ...@@ -59,9 +59,9 @@ public final class Constants {
59 public static final byte BGP_FLOWSPEC_ICMP_TP = 0x07; 59 public static final byte BGP_FLOWSPEC_ICMP_TP = 0x07;
60 public static final byte BGP_FLOWSPEC_ICMP_CD = 0x08; 60 public static final byte BGP_FLOWSPEC_ICMP_CD = 0x08;
61 public static final byte BGP_FLOWSPEC_TCP_FLAGS = 0x09; 61 public static final byte BGP_FLOWSPEC_TCP_FLAGS = 0x09;
62 - public static final byte BGP_FLOWSPEC_PCK_LEN = 0x10; 62 + public static final byte BGP_FLOWSPEC_PCK_LEN = 0x0a;
63 - public static final byte BGP_FLOWSPEC_DSCP = 0x11; 63 + public static final byte BGP_FLOWSPEC_DSCP = 0x0b;
64 - public static final byte BGP_FLOWSPEC_FRAGMENT = 0x12; 64 + public static final byte BGP_FLOWSPEC_FRAGMENT = 0x0c;
65 65
66 public static final short BGP_FLOWSPEC_ACTION_TRAFFIC_RATE = (short) 0x8006; 66 public static final short BGP_FLOWSPEC_ACTION_TRAFFIC_RATE = (short) 0x8006;
67 public static final short BGP_FLOWSPEC_ACTION_TRAFFIC_ACTION = (short) 0x8007; 67 public static final short BGP_FLOWSPEC_ACTION_TRAFFIC_ACTION = (short) 0x8007;
......
...@@ -39,19 +39,107 @@ public class MpReachNlriTest { ...@@ -39,19 +39,107 @@ public class MpReachNlriTest {
39 @Test 39 @Test
40 public void mpReachNlriTest1() throws BgpParseException { 40 public void mpReachNlriTest1() throws BgpParseException {
41 41
42 - // BGP flow spec Message 42 + // BGP flow spec Message
43 - byte[] flowSpecMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, 43 + byte[] flowSpecMsg = new byte[] {(byte) 0xff, (byte) 0xff,
44 (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, 44 (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
45 (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, 45 (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
46 (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, 46 (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
47 - (byte) 0xff, 0x00, 0x4a, 0x02, 0x00, 0x00, 0x00, 47 + (byte) 0xff, (byte) 0xff, 0x00, 0x4a, 0x02, 0x00, 0x00, 0x00,
48 - 0x33, 0x40, 0x01, 0x01, 0x00, 0x40, 0x02, 0x04, 48 + 0x33, 0x40, 0x01, 0x01, 0x00, 0x40, 0x02, 0x04, 0x02, 0x01,
49 - 0x02, 0x01, 0x00, 0x64, (byte) 0x80, 0x04, 0x04, 0x00, 49 + 0x00, 0x64, (byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00,
50 - 0x00, 0x00, 0x00, (byte) 0xc0, 0x10, 0x08, (byte) 0x80, 0x06, 50 + (byte) 0xc0, 0x10, 0x08, (byte) 0x80, 0x06, 0x00, 0x00, 0x00,
51 - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, (byte) 0x90, 0x0e, 51 + 0x00, 0x00, 0x00, (byte) 0x90, 0x0e, 0x00, 0x12, 0x00, 0x01,
52 - 0x00, 0x12, 0x00, 0x01, (byte) 0x85, 0x00, 0x00, 0x0c, 52 + (byte) 0x85, 0x00, 0x00, 0x0c, 0x02, 0x20, (byte) 0xc0,
53 - 0x02, 0x20, (byte) 0xc0, (byte) 0xa8, 0x07, 0x36, 0x03, (byte) 0x81, 53 + (byte) 0xa8, 0x07, 0x36, 0x03, (byte) 0x81, 0x67, 0x04,
54 - 0x67, 0x04, (byte) 0x81, 0x01}; 54 + (byte) 0x81, 0x01 };
55 +
56 + byte[] testFsMsg;
57 + ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
58 + buffer.writeBytes(flowSpecMsg);
59 +
60 + BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader();
61 + BgpMessage message;
62 + BgpHeader bgpHeader = new BgpHeader();
63 +
64 + message = reader.readFrom(buffer, bgpHeader);
65 +
66 + assertThat(message, instanceOf(BgpUpdateMsgVer4.class));
67 + ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
68 + message.writeTo(buf);
69 +
70 + int readLen = buf.writerIndex();
71 + testFsMsg = new byte[readLen];
72 + buf.readBytes(testFsMsg, 0, readLen);
73 +
74 + assertThat(testFsMsg, is(flowSpecMsg));
75 + }
76 +
77 + /**
78 + * This testcase checks BGP update message.
79 + */
80 + @Test
81 + public void mpReachNlriTest2() throws BgpParseException {
82 +
83 + // BGP flow spec Message
84 + byte[] flowSpecMsg = new byte[] {(byte) 0xff, (byte) 0xff,
85 + (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
86 + (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
87 + (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
88 + (byte) 0xff, (byte) 0xff, 0x00, 0x52, 0x02, 0x00, 0x00, 0x00,
89 + 0x3b, 0x40, 0x01, 0x01, 0x01, 0x40, 0x02, 0x04, 0x02, 0x01,
90 + 0x00, (byte) 0xc8, (byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00,
91 + 0x00, (byte) 0xc0, 0x10, 0x10, (byte) 0x80, 0x06, 0x00, 0x7b,
92 + 0x40, 0x60, 0x00, 0x00, (byte) 0x80, 0x09, 0x00, 0x00, 0x00,
93 + 0x00, 0x00, 0x0f, (byte) 0x90, 0x0e, 0x00, 0x12, 0x00, 0x01,
94 + (byte) 0x85, 0x00, 0x00, 0x0c, 0x01, 0x1e, (byte) 0xc0,
95 + (byte) 0xa8, 0x02, 0x00, 0x02, 0x1e, (byte) 0xc0, (byte) 0xa8,
96 + 0x01, 0x00 };
97 +
98 + byte[] testFsMsg;
99 + ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
100 + buffer.writeBytes(flowSpecMsg);
101 +
102 + BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader();
103 + BgpMessage message;
104 + BgpHeader bgpHeader = new BgpHeader();
105 +
106 + message = reader.readFrom(buffer, bgpHeader);
107 +
108 + assertThat(message, instanceOf(BgpUpdateMsgVer4.class));
109 + ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
110 + message.writeTo(buf);
111 +
112 + int readLen = buf.writerIndex();
113 + testFsMsg = new byte[readLen];
114 + buf.readBytes(testFsMsg, 0, readLen);
115 +
116 + assertThat(testFsMsg, is(flowSpecMsg));
117 + }
118 +
119 + /**
120 + * This testcase checks BGP update message.
121 + */
122 + @Test
123 + public void mpReachNlriTest3() throws BgpParseException {
124 +
125 + // BGP flow spec Message
126 + byte[] flowSpecMsg = new byte[] {(byte) 0xff, (byte) 0xff,
127 + (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
128 + (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
129 + (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
130 + (byte) 0xff, (byte) 0xff, 0x00, 0x71, 0x02, 0x00, 0x00, 0x00,
131 + 0x5a, 0x40, 0x01, 0x01, 0x01, 0x40, 0x02, 0x04, 0x02, 0x01,
132 + 0x00, (byte) 0xc8, (byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00,
133 + 0x00, (byte) 0xc0, 0x10, 0x10, (byte) 0x80, 0x06, 0x00, 0x7b,
134 + 0x40, 0x60, 0x00, 0x00, (byte) 0x80, 0x09, 0x00, 0x00, 0x00,
135 + 0x00, 0x00, 0x0f, (byte) 0x90, 0x0e, 0x00, 0x31, 0x00, 0x01,
136 + (byte) 0x85, 0x00, 0x00, 0x2b, 0x01, 0x1e, (byte) 0xc0,
137 + (byte) 0xa8, 0x02, 0x00, 0x02, 0x1e, (byte) 0xc0, (byte) 0xa8,
138 + 0x01, 0x00, 0x03, (byte) 0x80, 0x04, 0x04, (byte) 0x80,
139 + (byte) 0xb3, 0x05, (byte) 0x80, (byte) 0xc8, 0x06, (byte) 0x80,
140 + 0x64, 0x07, (byte) 0x80, 0x7b, 0x08, (byte) 0x80, (byte) 0xea,
141 + 0x09, (byte) 0x80, 0x7b, 0x0a, (byte) 0x90, 0x03, (byte) 0xe8,
142 + 0x0b, (byte) 0x80, 0x7b, 0x0c, (byte) 0x80, 0x02 };
55 143
56 byte[] testFsMsg; 144 byte[] testFsMsg;
57 ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); 145 ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
......