2 * Copyright (c) 2016 Brocade Communications 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.l3vpn.ipv6;
10 import com.google.common.collect.Lists;
11 import io.netty.buffer.ByteBuf;
12 import io.netty.buffer.Unpooled;
13 import java.util.List;
14 import org.junit.Assert;
15 import org.junit.Test;
16 import org.opendaylight.protocol.bgp.parser.BGPParsingException;
17 import org.opendaylight.protocol.util.ByteArray;
18 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix;
19 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev171207.labeled.unicast.LabelStack;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev171207.labeled.unicast.LabelStackBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.AttributesBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.Attributes1;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.Attributes1Builder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.Attributes2;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.Attributes2Builder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.update.attributes.MpReachNlri;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.update.attributes.MpReachNlriBuilder;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.update.attributes.MpUnreachNlri;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.update.attributes.MpUnreachNlriBuilder;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.update.attributes.mp.reach.nlri.AdvertizedRoutesBuilder;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.update.attributes.mp.unreach.nlri.WithdrawnRoutesBuilder;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv6AddressFamily;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.RouteDistinguisher;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.RouteDistinguisherBuilder;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.vpn.ipv6.rev171207.l3vpn.ipv6.destination.VpnIpv6DestinationBuilder;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.vpn.rev171207.l3vpn.ip.destination.type.VpnDestination;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.vpn.rev171207.l3vpn.ip.destination.type.VpnDestinationBuilder;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.MplsLabel;
44 public class VpnIpv6NlriParserTest {
46 private static final VpnIpv6NlriParser PARSER = new VpnIpv6NlriParser();
48 /* Reach NLRI prefix value.
52 * 00 16 3 <- labelValue 355
54 * 00 01 <- routeDistinguisher Type=1
55 * 01 02 03 04 <- routeDistinguisher IPV4=1.2.3.4
56 * 01 02 <- routeDistinguisher AS=258
57 * 20 01 23 45 56 89 <- prefixType IPV6=2001:2345:5689::/48
59 private static final byte[] REACH_NLRI = new byte[] {
61 (byte) 0x00, (byte) 0x16, (byte) 0x31,
62 0, 1, 1, 2, 3, 4, 1, 2,
63 (byte) 0x20, (byte) 0x01, (byte) 0x23, (byte) 0x45, (byte) 0x56, (byte) 0x89
66 /* Unreach NLRI prefix value.
70 * 80 00 00 <- labelValue for withdraw
71 * 00 01 <- routeDistinguisher Type=1
72 * 01 02 03 04 <- routeDistinguisher IPV4=1.2.3.4
73 * 01 02 <- routeDistinguisher AS=258
74 * 20 01 23 45 56 89 <- prefixType IPV6=2001:2345:5689::/48
76 private static final byte[] UNREACH_NLRI = new byte[] {
78 (byte) 0x80, (byte) 0x00, (byte) 0x00,
79 0, 1, 1, 2, 3, 4, 1, 2,
80 (byte) 0x20, (byte) 0x01, (byte) 0x23, (byte) 0x45, (byte) 0x56, (byte) 0x89
83 static final IpPrefix IPv6_PREFIX = new IpPrefix(new Ipv6Prefix("2001:2345:5689::/48"));
84 static final List<LabelStack> LABEL_STACK = Lists.newArrayList(
85 new LabelStackBuilder().setLabelValue(new MplsLabel(355L)).build());
86 static final RouteDistinguisher DISTINGUISHER = RouteDistinguisherBuilder.getDefaultInstance("1.2.3.4:258");
87 static final VpnDestination IPV6_VPN = new VpnDestinationBuilder().setRouteDistinguisher(DISTINGUISHER).setPrefix(IPv6_PREFIX).setLabelStack(LABEL_STACK).build();
88 private static final VpnDestination IPV6_VPN_WITHOUT_LABELS = new VpnDestinationBuilder().setRouteDistinguisher(DISTINGUISHER).setPrefix(IPv6_PREFIX).build();
91 public void testMpReachNlri() throws BGPParsingException {
92 final MpReachNlriBuilder mpBuilder = new MpReachNlriBuilder();
93 mpBuilder.setAfi(Ipv6AddressFamily.class);
94 mpBuilder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(
95 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.vpn.ipv6.rev171207.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationVpnIpv6CaseBuilder().setVpnIpv6Destination(
96 new VpnIpv6DestinationBuilder().setVpnDestination(Lists.newArrayList(IPV6_VPN)).build()
101 final MpReachNlri mpReachExpected = mpBuilder.build();
103 final MpReachNlriBuilder testBuilder = new MpReachNlriBuilder();
104 testBuilder.setAfi(Ipv6AddressFamily.class);
105 PARSER.parseNlri(Unpooled.copiedBuffer(REACH_NLRI), testBuilder);
106 Assert.assertEquals(mpReachExpected, testBuilder.build());
108 final ByteBuf output = Unpooled.buffer();
109 PARSER.serializeAttribute(
110 new AttributesBuilder().addAugmentation(Attributes1.class,
111 new Attributes1Builder().setMpReachNlri(mpReachExpected).build()
114 Assert.assertArrayEquals(REACH_NLRI, ByteArray.readAllBytes(output));
118 public void testMpUnreachNlri() throws BGPParsingException {
119 final MpUnreachNlriBuilder mpBuilder = new MpUnreachNlriBuilder();
120 mpBuilder.setAfi(Ipv6AddressFamily.class);
122 mpBuilder.setWithdrawnRoutes(
123 new WithdrawnRoutesBuilder().setDestinationType(
124 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.vpn.ipv6.rev171207.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationVpnIpv6CaseBuilder().setVpnIpv6Destination(
125 new VpnIpv6DestinationBuilder().setVpnDestination(Lists.newArrayList(IPV6_VPN_WITHOUT_LABELS)).build()
129 final MpUnreachNlri mpUnreachExpected1 = mpBuilder.build();
131 mpBuilder.setWithdrawnRoutes(
132 new WithdrawnRoutesBuilder().setDestinationType(
133 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.vpn.ipv6.rev171207.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationVpnIpv6CaseBuilder().setVpnIpv6Destination(
134 new VpnIpv6DestinationBuilder().setVpnDestination(Lists.newArrayList(IPV6_VPN)).build()
138 final MpUnreachNlri mpUnreachExpected2 = mpBuilder.build();
140 final MpUnreachNlriBuilder testBuilder = new MpUnreachNlriBuilder();
141 testBuilder.setAfi(Ipv6AddressFamily.class);
142 PARSER.parseNlri(Unpooled.copiedBuffer(UNREACH_NLRI), testBuilder);
143 Assert.assertEquals(mpUnreachExpected1, testBuilder.build());
145 final ByteBuf output = Unpooled.buffer();
146 PARSER.serializeAttribute(
147 new AttributesBuilder().addAugmentation(Attributes2.class,
148 new Attributes2Builder().setMpUnreachNlri(mpUnreachExpected2).build()
151 Assert.assertArrayEquals(UNREACH_NLRI, ByteArray.readAllBytes(output));