Code clean up
[bgpcep.git] / bgp / flowspec / src / test / java / org / opendaylight / protocol / bgp / flowspec / AbstractFlowspecNlriParserTest.java
1 /*
2  * Copyright (c) 2017 Brocade Communications Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.protocol.bgp.flowspec;
9
10 import static org.junit.Assert.assertEquals;
11
12 import io.netty.buffer.ByteBuf;
13 import io.netty.buffer.Unpooled;
14 import java.nio.ByteBuffer;
15 import org.junit.Test;
16
17 public class AbstractFlowspecNlriParserTest {
18
19     @Test(expected = IllegalStateException.class)
20     public void zeroNlriLengthTest() throws Exception {
21         // invalid zero NRLI length
22         AbstractFlowspecNlriParser.readNlriLength(Unpooled.wrappedBuffer(new byte[]{0x00, 0x0}));
23     }
24
25     @Test
26     public void readNlriLength() throws Exception {
27         final ByteBuffer byteBuffer = ByteBuffer.allocate(5003);
28         byteBuffer.put(new byte[]{(byte) 0x01});   // length = 1
29         byteBuffer.put(new byte[]{(byte) 0xf0, (byte) 0xf0});   // length = 240
30         byteBuffer.put(new byte[]{(byte) 0xf0, (byte) 0xf1});   // length = 241
31         byteBuffer.put(new byte[]{(byte) 0xff, (byte) 0xff});   // length = 4095
32         byteBuffer.rewind();
33         final ByteBuf byteBuf = Unpooled.wrappedBuffer(byteBuffer);
34         assertEquals(1, AbstractFlowspecNlriParser.readNlriLength(byteBuf));
35         assertEquals(240, AbstractFlowspecNlriParser.readNlriLength(byteBuf));
36         assertEquals(241, AbstractFlowspecNlriParser.readNlriLength(byteBuf));
37         assertEquals(4095, AbstractFlowspecNlriParser.readNlriLength(byteBuf));
38     }
39
40 }