da00cf72ba196c0c1d7f909e97be05509cd6404c
[bgpcep.git] / bgp / inet / src / test / java / org / opendaylight / protocol / bgp / inet / Ipv6BgpPrefixSidParserTest.java
1 /*
2  * Copyright (c) 2016 Cisco 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.inet;
9
10 import static org.junit.Assert.assertArrayEquals;
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertTrue;
13
14 import io.netty.buffer.ByteBuf;
15 import io.netty.buffer.Unpooled;
16 import org.junit.Test;
17 import org.opendaylight.protocol.bgp.inet.codec.Ipv6BgpPrefixSidParser;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.update.attributes.bgp.prefix.sid.bgp.prefix.sid.tlvs.bgp.prefix.sid.tlv.Ipv6SidTlvBuilder;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.attributes.bgp.prefix.sid.bgp.prefix.sid.tlvs.BgpPrefixSidTlv;
20 import org.opendaylight.yangtools.yang.binding.DataContainer;
21
22 public final class Ipv6BgpPrefixSidParserTest {
23
24     private final Ipv6BgpPrefixSidParser handler = new Ipv6BgpPrefixSidParser();
25
26     private final byte[] expected = new byte[] {0, (byte)0x80, 0};
27
28     @Test(expected=IllegalArgumentException.class)
29     public void testWrongTlvType() {
30         this.handler.serializeBgpPrefixSidTlv(() -> BgpPrefixSidTlv.class, Unpooled.EMPTY_BUFFER);
31     }
32
33     @Test
34     public void testHandling() {
35         final Ipv6SidTlvBuilder tlv = new Ipv6SidTlvBuilder();
36         tlv.setProcessIpv6HeadAbility(Boolean.TRUE);
37         final ByteBuf serialized = Unpooled.buffer(3);
38         this.handler.serializeBgpPrefixSidTlv(tlv.build(), serialized);
39         assertArrayEquals(this.expected, serialized.array());
40         assertTrue(this.handler.parseBgpPrefixSidTlv(serialized).isProcessIpv6HeadAbility());
41     }
42
43     @Test
44     public void testType() {
45         assertEquals(2, this.handler.getType());
46     }
47 }