blob: afd1896ace9f1a0f9027adef2828bcf5b98f952f [file] [log] [blame]
Shashikanth VH58260662016-02-13 01:12:02 +05301/*
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 */
16package org.onosproject.bgpio.types;
17
18import static org.hamcrest.MatcherAssert.assertThat;
19import static org.hamcrest.Matchers.instanceOf;
20import static org.hamcrest.core.Is.is;
21
22import org.jboss.netty.buffer.ChannelBuffer;
23import org.jboss.netty.buffer.ChannelBuffers;
24import org.junit.Test;
25import org.onosproject.bgpio.exceptions.BgpParseException;
26import org.onosproject.bgpio.protocol.BgpFactories;
27import org.onosproject.bgpio.protocol.BgpMessage;
28import org.onosproject.bgpio.protocol.BgpMessageReader;
29import org.onosproject.bgpio.protocol.ver4.BgpUpdateMsgVer4;
30
31/**
32 * Test for MP unreach NLRI encoding and decoding.
33 */
34public 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}