2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.protocol.bgp.inet;
10 import static org.junit.Assert.assertArrayEquals;
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertTrue;
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;
22 public final class Ipv6BgpPrefixSidParserTest {
24 private final Ipv6BgpPrefixSidParser handler = new Ipv6BgpPrefixSidParser();
26 private final byte[] expected = new byte[] {0, (byte)0x80, 0};
28 @Test(expected=IllegalArgumentException.class)
29 public void testWrongTlvType() {
30 this.handler.serializeBgpPrefixSidTlv(new BgpPrefixSidTlv() {
32 public Class<? extends DataContainer> getImplementedInterface() {
33 return BgpPrefixSidTlv.class;
35 }, Unpooled.EMPTY_BUFFER);
39 public void testHandling() {
40 final Ipv6SidTlvBuilder tlv = new Ipv6SidTlvBuilder();
41 tlv.setProcessIpv6HeadAbility(Boolean.TRUE);
42 final ByteBuf serialized = Unpooled.buffer(3);
43 this.handler.serializeBgpPrefixSidTlv(tlv.build(), serialized);
44 assertArrayEquals(this.expected, serialized.array());
45 assertTrue(this.handler.parseBgpPrefixSidTlv(serialized).isProcessIpv6HeadAbility());
49 public void testType() {
50 assertEquals(2, this.handler.getType());