Cleanup deprecation warnings in bgp/extensions/mvpn
[bgpcep.git] / bgp / extensions / mvpn / src / test / java / org / opendaylight / protocol / bgp / mvpn / impl / attributes / PEDistinguisherLabelsAttributeHandlerTest.java
1 /*
2  * Copyright (c) 2018 AT&T Intellectual Property. 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.mvpn.impl.attributes;
9
10 import static org.junit.Assert.assertArrayEquals;
11 import static org.junit.Assert.assertEquals;
12
13 import io.netty.buffer.ByteBuf;
14 import io.netty.buffer.Unpooled;
15 import java.util.ArrayList;
16 import java.util.List;
17 import org.junit.Before;
18 import org.junit.Test;
19 import org.opendaylight.protocol.bgp.mvpn.impl.BGPActivator;
20 import org.opendaylight.protocol.bgp.parser.spi.AttributeRegistry;
21 import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionProviderContext;
22 import org.opendaylight.protocol.bgp.parser.spi.pojo.SimpleBGPExtensionProviderContext;
23 import org.opendaylight.protocol.util.ByteArray;
24 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddressNoZone;
25 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.Attributes;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.AttributesBuilder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.mvpn.rev200120.bgp.rib.route.PeDistinguisherLabelsAttributeAugmentationBuilder;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.mvpn.rev200120.pe.distinguisher.labels.attribute.PeDistinguisherLabelsAttributeBuilder;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.mvpn.rev200120.pe.distinguisher.labels.attribute.pe.distinguisher.labels.attribute.PeDistinguisherLabelAttribute;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.mvpn.rev200120.pe.distinguisher.labels.attribute.pe.distinguisher.labels.attribute.PeDistinguisherLabelAttributeBuilder;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.MplsLabel;
33 import org.opendaylight.yangtools.yang.common.Uint32;
34
35 public final class PEDistinguisherLabelsAttributeHandlerTest {
36     /**
37      * ATT - TYPE - ATT LENGTH.
38      * PE ADDRESS - MPLS LABEL
39      * PE ADDRESS - MPLS LABEL
40      */
41     private static final byte[] PE_DISTINGUISHER_LABELS = {
42         (byte) 0xC0, (byte) 0x1B, (byte) 0x0e,
43         (byte) 0x7F, (byte) 0x00, (byte) 0x00, (byte) 0x01,
44         (byte) 0x00, (byte) 0x00, (byte) 0x10,
45         (byte) 0x7F, (byte) 0x00, (byte) 0x00, (byte) 0x02,
46         (byte) 0x00, (byte) 0x00, (byte) 0x20,
47     };
48     private AttributeRegistry handler;
49
50     @Before
51     public void setUp() {
52         final BGPExtensionProviderContext ctx = new SimpleBGPExtensionProviderContext();
53
54         final org.opendaylight.protocol.bgp.parser.impl.BGPActivator inetActivator =
55                 new org.opendaylight.protocol.bgp.parser.impl.BGPActivator();
56         inetActivator.start(ctx);
57         final BGPActivator bgpActivator = new BGPActivator();
58         bgpActivator.start(ctx);
59         this.handler = ctx.getAttributeRegistry();
60     }
61
62     @Test
63     public void testPEDistinguisherLabelsHandler() throws Exception {
64         final Attributes expected = buildPEDistinguisherLabelsAttributAttribute();
65         final ByteBuf actual = Unpooled.buffer();
66         this.handler.serializeAttribute(expected, actual);
67         assertArrayEquals(PE_DISTINGUISHER_LABELS, ByteArray.readAllBytes(actual));
68         final Attributes actualAttr = this.handler.parseAttributes(
69                 Unpooled.wrappedBuffer(PE_DISTINGUISHER_LABELS), null).getAttributes();
70         assertEquals(expected, actualAttr);
71     }
72
73     private static Attributes buildPEDistinguisherLabelsAttributAttribute() {
74         final List<PeDistinguisherLabelAttribute> peAtt = new ArrayList<>(2);
75
76         peAtt.add(new PeDistinguisherLabelAttributeBuilder()
77                 .setPeAddress(new IpAddressNoZone(new Ipv4AddressNoZone("127.0.0.1")))
78                 .setMplsLabel(new MplsLabel(Uint32.ONE))
79                 .build());
80         peAtt.add(new PeDistinguisherLabelAttributeBuilder()
81                 .setPeAddress(new IpAddressNoZone(new Ipv4AddressNoZone("127.0.0.2")))
82                 .setMplsLabel(new MplsLabel(Uint32.TWO))
83                 .build());
84         return new AttributesBuilder()
85                 .addAugmentation(new PeDistinguisherLabelsAttributeAugmentationBuilder()
86                     .setPeDistinguisherLabelsAttribute(new PeDistinguisherLabelsAttributeBuilder()
87                         .setPeDistinguisherLabelAttribute(peAtt).build()).build()).build();
88     }
89 }