Shashikanth VH
Committed by Gerrit Code Review

[ONOS-3857] BGP flow specification components encode and decode test.

Change-Id: I2830cd4d26ca044332a16845643ea99e11381209
...@@ -189,6 +189,8 @@ public class MpReachNlri implements BgpValueType { ...@@ -189,6 +189,8 @@ public class MpReachNlri implements BgpValueType {
189 && ((safi == Constants.SAFI_FLOWSPEC_VALUE) 189 && ((safi == Constants.SAFI_FLOWSPEC_VALUE)
190 || (safi == Constants.VPN_SAFI_FLOWSPEC_VALUE))) { 190 || (safi == Constants.VPN_SAFI_FLOWSPEC_VALUE))) {
191 List<BgpValueType> flowSpecComponents = new LinkedList<>(); 191 List<BgpValueType> flowSpecComponents = new LinkedList<>();
192 +
193 + if (tempCb.readableBytes() > 0) {
192 BgpValueType flowSpecComponent = null; 194 BgpValueType flowSpecComponent = null;
193 195
194 byte nextHopLen = tempCb.readByte(); 196 byte nextHopLen = tempCb.readByte();
...@@ -257,6 +259,7 @@ public class MpReachNlri implements BgpValueType { ...@@ -257,6 +259,7 @@ public class MpReachNlri implements BgpValueType {
257 } 259 }
258 flowSpecComponents.add(flowSpecComponent); 260 flowSpecComponents.add(flowSpecComponent);
259 } 261 }
262 + }
260 return new MpReachNlri(new BgpFlowSpecDetails(flowSpecComponents), afi, safi); 263 return new MpReachNlri(new BgpFlowSpecDetails(flowSpecComponents), afi, safi);
261 } else { 264 } else {
262 throw new BgpParseException("Not Supporting afi " + afi + "safi " + safi); 265 throw new BgpParseException("Not Supporting afi " + afi + "safi " + safi);
......
...@@ -154,8 +154,9 @@ public class MpUnReachNlri implements BgpValueType { ...@@ -154,8 +154,9 @@ public class MpUnReachNlri implements BgpValueType {
154 && ((safi == Constants.SAFI_FLOWSPEC_VALUE) 154 && ((safi == Constants.SAFI_FLOWSPEC_VALUE)
155 || (safi == Constants.VPN_SAFI_FLOWSPEC_VALUE))) { 155 || (safi == Constants.VPN_SAFI_FLOWSPEC_VALUE))) {
156 List<BgpValueType> flowSpecComponents = new LinkedList<>(); 156 List<BgpValueType> flowSpecComponents = new LinkedList<>();
157 - BgpValueType flowSpecComponent = null;
158 157
158 + if (tempCb.readableBytes() > 0) {
159 + BgpValueType flowSpecComponent = null;
159 short totNlriLen = tempCb.getByte(tempCb.readerIndex()); 160 short totNlriLen = tempCb.getByte(tempCb.readerIndex());
160 if (totNlriLen >= FLOW_SPEC_LEN) { 161 if (totNlriLen >= FLOW_SPEC_LEN) {
161 totNlriLen = tempCb.readShort(); 162 totNlriLen = tempCb.readShort();
...@@ -212,6 +213,7 @@ public class MpUnReachNlri implements BgpValueType { ...@@ -212,6 +213,7 @@ public class MpUnReachNlri implements BgpValueType {
212 } 213 }
213 flowSpecComponents.add(flowSpecComponent); 214 flowSpecComponents.add(flowSpecComponent);
214 } 215 }
216 + }
215 return new MpUnReachNlri(new BgpFlowSpecDetails(flowSpecComponents), afi, safi); 217 return new MpUnReachNlri(new BgpFlowSpecDetails(flowSpecComponents), afi, safi);
216 } else { 218 } else {
217 //TODO: check with the values got from capability 219 //TODO: check with the values got from capability
......
1 +/*
2 + * Copyright 2016 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.bgpio.types;
17 +
18 +import static org.hamcrest.MatcherAssert.assertThat;
19 +import static org.hamcrest.Matchers.instanceOf;
20 +import static org.hamcrest.core.Is.is;
21 +
22 +import org.jboss.netty.buffer.ChannelBuffer;
23 +import org.jboss.netty.buffer.ChannelBuffers;
24 +import org.junit.Test;
25 +import org.onosproject.bgpio.exceptions.BgpParseException;
26 +import org.onosproject.bgpio.protocol.BgpFactories;
27 +import org.onosproject.bgpio.protocol.BgpMessage;
28 +import org.onosproject.bgpio.protocol.BgpMessageReader;
29 +import org.onosproject.bgpio.protocol.ver4.BgpUpdateMsgVer4;
30 +
31 +/**
32 + * Test for MP reach NLRI encoding and decoding.
33 + */
34 +public class MpReachNlriTest {
35 +
36 + /**
37 + * This testcase checks BGP update message.
38 + */
39 + @Test
40 + public void mpReachNlriTest1() throws BgpParseException {
41 +
42 + // BGP flow spec Message
43 + byte[] flowSpecMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff,
44 + (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,
47 + (byte) 0xff, 0x00, 0x4a, 0x02, 0x00, 0x00, 0x00,
48 + 0x33, 0x40, 0x01, 0x01, 0x00, 0x40, 0x02, 0x04,
49 + 0x02, 0x01, 0x00, 0x64, (byte) 0x80, 0x04, 0x04, 0x00,
50 + 0x00, 0x00, 0x00, (byte) 0xc0, 0x10, 0x08, (byte) 0x80, 0x06,
51 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, (byte) 0x90, 0x0e,
52 + 0x00, 0x12, 0x00, 0x01, (byte) 0x85, 0x00, 0x00, 0x0c,
53 + 0x02, 0x20, (byte) 0xc0, (byte) 0xa8, 0x07, 0x36, 0x03, (byte) 0x81,
54 + 0x67, 0x04, (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 +}
1 +/*
2 + * Copyright 2016 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.bgpio.types;
17 +
18 +import static org.hamcrest.MatcherAssert.assertThat;
19 +import static org.hamcrest.Matchers.instanceOf;
20 +import static org.hamcrest.core.Is.is;
21 +
22 +import org.jboss.netty.buffer.ChannelBuffer;
23 +import org.jboss.netty.buffer.ChannelBuffers;
24 +import org.junit.Test;
25 +import org.onosproject.bgpio.exceptions.BgpParseException;
26 +import org.onosproject.bgpio.protocol.BgpFactories;
27 +import org.onosproject.bgpio.protocol.BgpMessage;
28 +import org.onosproject.bgpio.protocol.BgpMessageReader;
29 +import org.onosproject.bgpio.protocol.ver4.BgpUpdateMsgVer4;
30 +
31 +/**
32 + * Test for MP unreach NLRI encoding and decoding.
33 + */
34 +public class MpUnReachNlriTest {
35 +
36 + /**
37 + * This testcase checks BGP update message.
38 + */
39 + @Test
40 + public void mpUnReachNlriTest() throws BgpParseException {
41 +
42 + // BGP flow spec Message
43 + byte[] flowSpecMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff,
44 + (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,
47 + (byte) 0xff, 0x00, 0x2b, 0x02, 0x00, 0x00, 0x00, 0x14,
48 + (byte) 0x90, 0x0f, 0x00, 0x10, 0x00, 0x01, (byte) 0x85,
49 + 0x0c, 0x02, 0x20, (byte) 0xc0, (byte) 0xa8, 0x07, 0x36,
50 + 0x03, (byte) 0x81, 0x67, 0x04, (byte) 0x81, 0x01};
51 +
52 + byte[] testFsMsg;
53 + ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
54 + buffer.writeBytes(flowSpecMsg);
55 +
56 + BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader();
57 + BgpMessage message;
58 + BgpHeader bgpHeader = new BgpHeader();
59 +
60 + message = reader.readFrom(buffer, bgpHeader);
61 +
62 + assertThat(message, instanceOf(BgpUpdateMsgVer4.class));
63 + ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
64 + message.writeTo(buf);
65 +
66 + int readLen = buf.writerIndex();
67 + testFsMsg = new byte[readLen];
68 + buf.readBytes(testFsMsg, 0, readLen);
69 +
70 + assertThat(testFsMsg, is(flowSpecMsg));
71 + }
72 +}
...@@ -43,6 +43,7 @@ import org.onosproject.bgpio.protocol.linkstate.BgpPrefixIPv4LSNlriVer4; ...@@ -43,6 +43,7 @@ import org.onosproject.bgpio.protocol.linkstate.BgpPrefixIPv4LSNlriVer4;
43 import org.onosproject.bgpio.protocol.linkstate.PathAttrNlriDetails; 43 import org.onosproject.bgpio.protocol.linkstate.PathAttrNlriDetails;
44 import org.onosproject.bgpio.types.AsPath; 44 import org.onosproject.bgpio.types.AsPath;
45 import org.onosproject.bgpio.types.As4Path; 45 import org.onosproject.bgpio.types.As4Path;
46 +import org.onosproject.bgpio.types.BgpExtendedCommunity;
46 import org.onosproject.bgpio.types.BgpValueType; 47 import org.onosproject.bgpio.types.BgpValueType;
47 import org.onosproject.bgpio.types.LocalPref; 48 import org.onosproject.bgpio.types.LocalPref;
48 import org.onosproject.bgpio.types.Med; 49 import org.onosproject.bgpio.types.Med;
...@@ -227,7 +228,7 @@ public class BgpPeerImpl implements BgpPeer { ...@@ -227,7 +228,7 @@ public class BgpPeerImpl implements BgpPeer {
227 attributesList.add(new LocalPref(100)); 228 attributesList.add(new LocalPref(100));
228 } 229 }
229 230
230 - // TODO: Update flow spec action 231 + attributesList.add(new BgpExtendedCommunity(flowSpec.fsActionTlv()));
231 232
232 if (operType == FlowSpecOperation.ADD) { 233 if (operType == FlowSpecOperation.ADD) {
233 attributesList.add(new MpReachNlri(flowSpec, Constants.AFI_FLOWSPEC_VALUE, sAfi)); 234 attributesList.add(new MpReachNlri(flowSpec, Constants.AFI_FLOWSPEC_VALUE, sAfi));
......