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