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