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.mvpn.impl.attributes;
10 import static org.junit.Assert.assertArrayEquals;
11 import static org.junit.Assert.assertEquals;
12 import static org.opendaylight.protocol.bgp.mvpn.impl.attributes.PMSITunnelAttributeHandlerTestUtil.BIDIR_PIM_EXPECTED;
13 import static org.opendaylight.protocol.bgp.mvpn.impl.attributes.PMSITunnelAttributeHandlerTestUtil.INGRESS_REPLICATION_EXPECTED;
14 import static org.opendaylight.protocol.bgp.mvpn.impl.attributes.PMSITunnelAttributeHandlerTestUtil.M_LDP_MP_2_MP_LSP_EXPECTED;
15 import static org.opendaylight.protocol.bgp.mvpn.impl.attributes.PMSITunnelAttributeHandlerTestUtil.M_LDP_MP_2_MP_LSP_WRONG;
16 import static org.opendaylight.protocol.bgp.mvpn.impl.attributes.PMSITunnelAttributeHandlerTestUtil.M_LDP_P2MP_LSP_EXPECTED_IPV4;
17 import static org.opendaylight.protocol.bgp.mvpn.impl.attributes.PMSITunnelAttributeHandlerTestUtil.M_LDP_P2MP_LSP_EXPECTED_IPV4_2;
18 import static org.opendaylight.protocol.bgp.mvpn.impl.attributes.PMSITunnelAttributeHandlerTestUtil.M_LDP_P2MP_LSP_EXPECTED_IPV6;
19 import static org.opendaylight.protocol.bgp.mvpn.impl.attributes.PMSITunnelAttributeHandlerTestUtil.M_LDP_P2MP_LSP_EXPECTED_L2VPN;
20 import static org.opendaylight.protocol.bgp.mvpn.impl.attributes.PMSITunnelAttributeHandlerTestUtil.M_LDP_P2MP_LSP_EXPECTED_WRONG_FAMILY;
21 import static org.opendaylight.protocol.bgp.mvpn.impl.attributes.PMSITunnelAttributeHandlerTestUtil.NO_TUNNEL_INFORMATION_PRESENT_EXPECTED;
22 import static org.opendaylight.protocol.bgp.mvpn.impl.attributes.PMSITunnelAttributeHandlerTestUtil.PIM_SM_TREE_EXPECTED;
23 import static org.opendaylight.protocol.bgp.mvpn.impl.attributes.PMSITunnelAttributeHandlerTestUtil.PIM_SSM_TREE_EXPECTED;
24 import static org.opendaylight.protocol.bgp.mvpn.impl.attributes.PMSITunnelAttributeHandlerTestUtil.RSVP_TE_P2MP_LSP_LSP_EXPECTED;
25 import static org.opendaylight.protocol.bgp.mvpn.impl.attributes.PMSITunnelAttributeHandlerTestUtil.buildBidirPimTreeAttribute;
26 import static org.opendaylight.protocol.bgp.mvpn.impl.attributes.PMSITunnelAttributeHandlerTestUtil.buildIngressReplicationAttribute;
27 import static org.opendaylight.protocol.bgp.mvpn.impl.attributes.PMSITunnelAttributeHandlerTestUtil.buildMLDpMp2mPLspAttribute;
28 import static org.opendaylight.protocol.bgp.mvpn.impl.attributes.PMSITunnelAttributeHandlerTestUtil.buildMldpMP2mpLspWrongAttribute;
29 import static org.opendaylight.protocol.bgp.mvpn.impl.attributes.PMSITunnelAttributeHandlerTestUtil.buildMldpP2mpLspIpv4Attribute;
30 import static org.opendaylight.protocol.bgp.mvpn.impl.attributes.PMSITunnelAttributeHandlerTestUtil.buildMldpP2mpLspIpv6Attribute;
31 import static org.opendaylight.protocol.bgp.mvpn.impl.attributes.PMSITunnelAttributeHandlerTestUtil.buildMldpp2MPLspL2vpnAttribute;
32 import static org.opendaylight.protocol.bgp.mvpn.impl.attributes.PMSITunnelAttributeHandlerTestUtil.buildNoSupportedFamilyAttribute;
33 import static org.opendaylight.protocol.bgp.mvpn.impl.attributes.PMSITunnelAttributeHandlerTestUtil.buildNoSupportedOpaqueAttribute;
34 import static org.opendaylight.protocol.bgp.mvpn.impl.attributes.PMSITunnelAttributeHandlerTestUtil.buildPimSMTreeAttribute;
35 import static org.opendaylight.protocol.bgp.mvpn.impl.attributes.PMSITunnelAttributeHandlerTestUtil.buildPimSSMTreeAttribute;
36 import static org.opendaylight.protocol.bgp.mvpn.impl.attributes.PMSITunnelAttributeHandlerTestUtil.buildRsvpTep2MPLspAttribute;
37 import static org.opendaylight.protocol.bgp.mvpn.impl.attributes.PMSITunnelAttributeHandlerTestUtil.buildWOTunnelInfAttribute;
39 import io.netty.buffer.ByteBuf;
40 import io.netty.buffer.Unpooled;
41 import org.junit.Before;
42 import org.junit.Test;
43 import org.opendaylight.protocol.bgp.mvpn.impl.BGPActivator;
44 import org.opendaylight.protocol.bgp.parser.spi.AttributeRegistry;
45 import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionProviderContext;
46 import org.opendaylight.protocol.bgp.parser.spi.pojo.SimpleBGPExtensionProviderContext;
47 import org.opendaylight.protocol.util.ByteArray;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.Attributes;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.AttributesBuilder;
51 public final class PMSITunnelAttributeHandlerTest {
53 private AttributeRegistry handler;
57 final BGPExtensionProviderContext ctx = new SimpleBGPExtensionProviderContext();
59 final org.opendaylight.protocol.bgp.parser.impl.BGPActivator inetActivator =
60 new org.opendaylight.protocol.bgp.parser.impl.BGPActivator();
61 inetActivator.start(ctx);
62 final BGPActivator bgpActivator = new BGPActivator();
63 bgpActivator.start(ctx);
64 this.handler = ctx.getAttributeRegistry();
68 public void testBidirPimTree() throws Exception {
69 final Attributes attributes = buildBidirPimTreeAttribute();
70 final ByteBuf actual = Unpooled.buffer();
71 this.handler.serializeAttribute(attributes, actual);
72 assertArrayEquals(BIDIR_PIM_EXPECTED, ByteArray.readAllBytes(actual));
73 final Attributes expected = buildBidirPimTreeAttribute();
74 final Attributes actualAttr = this.handler.parseAttributes(
75 Unpooled.wrappedBuffer(BIDIR_PIM_EXPECTED), null).getAttributes();
76 assertEquals(expected, actualAttr);
80 public void testPimSMTree() throws Exception {
81 final Attributes attributes = buildPimSMTreeAttribute();
82 final ByteBuf actual = Unpooled.buffer();
83 this.handler.serializeAttribute(attributes, actual);
84 assertArrayEquals(PIM_SM_TREE_EXPECTED, ByteArray.readAllBytes(actual));
85 final Attributes expected = buildPimSMTreeAttribute();
86 final Attributes actualAttr = this.handler.parseAttributes(
87 Unpooled.wrappedBuffer(PIM_SM_TREE_EXPECTED), null).getAttributes();
88 assertEquals(expected, actualAttr);
92 public void serializePimSSMTree() {
93 final Attributes attributes = buildPimSSMTreeAttribute();
94 final ByteBuf actual = Unpooled.buffer();
95 this.handler.serializeAttribute(attributes, actual);
96 assertArrayEquals(PIM_SSM_TREE_EXPECTED, ByteArray.readAllBytes(actual));
100 public void parsePimSSMTree() throws Exception {
101 final Attributes expected = buildPimSSMTreeAttribute();
102 final Attributes actual = this.handler.parseAttributes(
103 Unpooled.wrappedBuffer(PIM_SSM_TREE_EXPECTED), null).getAttributes();
104 assertEquals(expected, actual);
108 public void testMldpP2MpLsp() throws Exception {
109 final Attributes expectedIpv4Att = buildMldpP2mpLspIpv4Attribute();
110 final ByteBuf actualIpv4 = Unpooled.buffer();
111 this.handler.serializeAttribute(expectedIpv4Att, actualIpv4);
112 assertArrayEquals(M_LDP_P2MP_LSP_EXPECTED_IPV4, ByteArray.readAllBytes(actualIpv4));
114 final Attributes actualIpv4Attribute = this.handler.parseAttributes(
115 Unpooled.wrappedBuffer(M_LDP_P2MP_LSP_EXPECTED_IPV4_2), null).getAttributes();
116 assertEquals(expectedIpv4Att, actualIpv4Attribute);
118 final Attributes expectedIpv6Att = buildMldpP2mpLspIpv6Attribute();
119 final ByteBuf actualIpv6 = Unpooled.buffer();
120 this.handler.serializeAttribute(expectedIpv6Att, actualIpv6);
121 assertArrayEquals(M_LDP_P2MP_LSP_EXPECTED_IPV6, ByteArray.readAllBytes(actualIpv6));
123 final Attributes actualIpv6Attribute = this.handler.parseAttributes(
124 Unpooled.wrappedBuffer(M_LDP_P2MP_LSP_EXPECTED_IPV6), null).getAttributes();
125 assertEquals(expectedIpv6Att, actualIpv6Attribute);
127 final ByteBuf actualL2vpn = Unpooled.buffer();
128 this.handler.serializeAttribute(buildNoSupportedFamilyAttribute(), actualL2vpn);
129 assertArrayEquals(new byte[0], ByteArray.readAllBytes(actualIpv4));
132 final Attributes actualWrongFamily = this.handler.parseAttributes(
133 Unpooled.wrappedBuffer(M_LDP_P2MP_LSP_EXPECTED_WRONG_FAMILY), null).getAttributes();
134 assertEquals(buildWOTunnelInfAttribute(), actualWrongFamily);
136 final Attributes expectedL2vpnAtt = buildMldpp2MPLspL2vpnAttribute();
138 final Attributes actualL2vpnAttribute = this.handler.parseAttributes(
139 Unpooled.wrappedBuffer(M_LDP_P2MP_LSP_EXPECTED_L2VPN), null).getAttributes();
140 assertEquals(expectedL2vpnAtt, actualL2vpnAttribute);
142 final ByteBuf actualL2vp = Unpooled.buffer();
143 this.handler.serializeAttribute(expectedL2vpnAtt, actualL2vp);
144 assertArrayEquals(M_LDP_P2MP_LSP_EXPECTED_L2VPN, ByteArray.readAllBytes(actualL2vp));
146 final ByteBuf actualNonSupportedOpaques = Unpooled.buffer();
147 this.handler.serializeAttribute(buildNoSupportedOpaqueAttribute(), actualNonSupportedOpaques);
148 assertArrayEquals(NO_TUNNEL_INFORMATION_PRESENT_EXPECTED, ByteArray.readAllBytes(actualNonSupportedOpaques));
152 public void testRsvpteP2MplspLsp() throws Exception {
153 final Attributes expected = buildRsvpTep2MPLspAttribute();
154 final ByteBuf actual = Unpooled.buffer();
155 this.handler.serializeAttribute(expected, actual);
156 assertArrayEquals(RSVP_TE_P2MP_LSP_LSP_EXPECTED, ByteArray.readAllBytes(actual));
157 final Attributes actualAttr = this.handler.parseAttributes(
158 Unpooled.wrappedBuffer(RSVP_TE_P2MP_LSP_LSP_EXPECTED), null).getAttributes();
159 assertEquals(expected, actualAttr);
163 public void testIngressReplication() throws Exception {
164 final Attributes expected = buildIngressReplicationAttribute();
165 final ByteBuf actual = Unpooled.buffer();
166 this.handler.serializeAttribute(expected, actual);
167 assertArrayEquals(INGRESS_REPLICATION_EXPECTED, ByteArray.readAllBytes(actual));
168 final Attributes actualAttr = this.handler.parseAttributes(
169 Unpooled.wrappedBuffer(INGRESS_REPLICATION_EXPECTED), null).getAttributes();
170 assertEquals(expected, actualAttr);
174 public void testMldpmP2MpLsp() throws Exception {
175 final Attributes expected = buildMLDpMp2mPLspAttribute();
176 final ByteBuf actual = Unpooled.buffer();
177 this.handler.serializeAttribute(expected, actual);
178 assertArrayEquals(M_LDP_MP_2_MP_LSP_EXPECTED, ByteArray.readAllBytes(actual));
180 final Attributes actualAttr = this.handler.parseAttributes(
181 Unpooled.wrappedBuffer(M_LDP_MP_2_MP_LSP_EXPECTED), null).getAttributes();
182 assertEquals(expected, actualAttr);
184 final Attributes actualWrong = this.handler.parseAttributes(
185 Unpooled.wrappedBuffer(M_LDP_MP_2_MP_LSP_WRONG), null).getAttributes();
186 assertEquals(buildWOTunnelInfAttribute(), actualWrong);
188 final Attributes wrongAttribute = buildMldpMP2mpLspWrongAttribute();
189 final ByteBuf actualWrongBuf = Unpooled.buffer();
190 this.handler.serializeAttribute(wrongAttribute, actualWrongBuf);
191 assertArrayEquals(NO_TUNNEL_INFORMATION_PRESENT_EXPECTED, ByteArray.readAllBytes(actualWrongBuf));
196 public void serializeNoTunnelInfPresentExpected() throws Exception {
197 final Attributes attributes = buildWOTunnelInfAttribute();
198 final ByteBuf actual = Unpooled.buffer();
199 this.handler.serializeAttribute(attributes, actual);
200 assertArrayEquals(NO_TUNNEL_INFORMATION_PRESENT_EXPECTED, ByteArray.readAllBytes(actual));
201 final Attributes expected = buildWOTunnelInfAttribute();
202 final Attributes actualAttr = this.handler.parseAttributes(
203 Unpooled.wrappedBuffer(NO_TUNNEL_INFORMATION_PRESENT_EXPECTED), null).getAttributes();
204 assertEquals(expected, actualAttr);
208 public void testPMSITunnelAttributeParser() {
209 final PMSITunnelAttributeHandler pmsiHandler = new PMSITunnelAttributeHandler();
210 assertEquals(22, pmsiHandler.getType());
211 final AttributesBuilder builder = new AttributesBuilder();
212 final ByteBuf emptyBuffer = Unpooled.buffer();
213 pmsiHandler.parseAttribute(emptyBuffer, builder, null);
214 final Attributes emptyAttributes = new AttributesBuilder().build();
215 assertEquals(emptyAttributes, builder.build());
216 pmsiHandler.serializeAttribute(emptyAttributes, emptyBuffer);
217 assertEquals(Unpooled.buffer(), emptyBuffer);