2 * Copyright (c) 2015 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.flowspec.extended.communities;
11 import io.netty.buffer.ByteBuf;
12 import io.netty.buffer.Unpooled;
13 import org.junit.After;
14 import org.junit.Assert;
15 import org.junit.Before;
16 import org.junit.Test;
17 import org.opendaylight.protocol.bgp.flowspec.BGPActivator;
18 import org.opendaylight.protocol.bgp.flowspec.FlowspecActivator;
19 import org.opendaylight.protocol.bgp.flowspec.SimpleFlowspecExtensionProviderContext;
20 import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
21 import org.opendaylight.protocol.bgp.parser.BGPParsingException;
22 import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionProviderContext;
23 import org.opendaylight.protocol.bgp.parser.spi.extended.community.ExtendedCommunityRegistry;
24 import org.opendaylight.protocol.bgp.parser.spi.pojo.SimpleBGPExtensionProviderContext;
25 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber;
26 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddressNoZone;
27 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone;
28 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6AddressNoZone;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.Dscp;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.redirect.as4.extended.community.RedirectAs4Builder;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.redirect.extended.community.RedirectExtendedCommunityBuilder;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.redirect.ip.nh.extended.community.RedirectIpNhExtendedCommunityBuilder;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.redirect.ipv4.extended.community.RedirectIpv4Builder;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.redirect.ipv6.extended.community.RedirectIpv6Builder;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.traffic.action.extended.community.TrafficActionExtendedCommunityBuilder;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.traffic.marking.extended.community.TrafficMarkingExtendedCommunityBuilder;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.traffic.rate.extended.community.TrafficRateExtendedCommunityBuilder;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.update.attributes.extended.communities.extended.community.RedirectAs4ExtendedCommunityCase;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.update.attributes.extended.communities.extended.community.RedirectAs4ExtendedCommunityCaseBuilder;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.update.attributes.extended.communities.extended.community.RedirectExtendedCommunityCase;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.update.attributes.extended.communities.extended.community.RedirectExtendedCommunityCaseBuilder;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.update.attributes.extended.communities.extended.community.RedirectIpNhExtendedCommunityCase;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.update.attributes.extended.communities.extended.community.RedirectIpNhExtendedCommunityCaseBuilder;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.update.attributes.extended.communities.extended.community.RedirectIpv4ExtendedCommunityCaseBuilder;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.update.attributes.extended.communities.extended.community.RedirectIpv6ExtendedCommunityCaseBuilder;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.update.attributes.extended.communities.extended.community.TrafficActionExtendedCommunityCase;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.update.attributes.extended.communities.extended.community.TrafficActionExtendedCommunityCaseBuilder;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.update.attributes.extended.communities.extended.community.TrafficMarkingExtendedCommunityCase;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.update.attributes.extended.communities.extended.community.TrafficMarkingExtendedCommunityCaseBuilder;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.update.attributes.extended.communities.extended.community.TrafficRateExtendedCommunityCase;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.update.attributes.extended.communities.extended.community.TrafficRateExtendedCommunityCaseBuilder;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.attributes.ExtendedCommunities;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.attributes.ExtendedCommunitiesBuilder;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.ShortAsNumber;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.Bandwidth;
56 import org.opendaylight.yangtools.yang.common.Uint16;
57 import org.opendaylight.yangtools.yang.common.Uint32;
58 import org.opendaylight.yangtools.yang.common.Uint8;
60 public class FSExtendedCommunitiesTest {
62 private static final byte[] TRAFFIC_RATE = {(byte)128, 6, 0, 72, 0, 1, 2, 3};
64 private static final byte[] TRAFFIC_ACTION = {(byte)128, 7, 0, 0, 0, 0, 0, 3};
66 private static final byte[] REDIRECT_AS_2BYTES = {(byte)128, 8, 0, 35, 4, 2, 8, 7};
68 private static final byte[] TRAFFIC_MARKING = {(byte)128, 9, 0, 0, 0, 0, 0, 63};
70 private static final byte[] REDIRECT_IPV6 =
71 {(byte)128, 11, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 1, 2};
73 private static final byte[] REDIRECT_AS_4BYTES = {(byte)130, 8, 0, 0, 0x19, (byte) 0x94, 0, 126};
75 private static final byte[] REDIRECT_IPV4 = {(byte)129, 8, 127, 0, 0, 1, 0, 126};
77 private static final byte[] REDIRECT_NH_IPV4 = {8, 0, 127, 0, 0, 1, 0, 1};
79 private static final byte[] REDIRECT_NH_IPV6 = {8, 0, 0x20, (byte) 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
80 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0, 0};
82 private ExtendedCommunityRegistry registry;
83 private BGPActivator act;
86 public void setUp() throws Exception {
87 final SimpleFlowspecExtensionProviderContext fsContext = new SimpleFlowspecExtensionProviderContext();
88 final FlowspecActivator activator = new FlowspecActivator(fsContext);
90 this.act = new BGPActivator(activator);
91 final BGPExtensionProviderContext context = new SimpleBGPExtensionProviderContext();
92 this.act.start(context);
93 this.registry = context.getExtendedCommunityRegistry();
97 public void tearDown() {
102 public void testTrafficRateParser() throws BGPDocumentedException, BGPParsingException {
103 final TrafficRateExtendedCommunityCase trafficRate = new TrafficRateExtendedCommunityCaseBuilder()
104 .setTrafficRateExtendedCommunity(new TrafficRateExtendedCommunityBuilder()
105 .setInformativeAs(new ShortAsNumber(Uint32.valueOf(72)))
106 .setLocalAdministrator(new Bandwidth(new byte[] { 0, 1, 2, 3 })).build()).build();
107 final ExtendedCommunities expected = new ExtendedCommunitiesBuilder().setExtendedCommunity(trafficRate)
108 .setTransitive(true).build();
110 final ExtendedCommunities parsed = this.registry.parseExtendedCommunity(Unpooled.copiedBuffer(TRAFFIC_RATE));
111 Assert.assertEquals(expected, parsed);
115 public void testTrafficRateSerializer() throws BGPDocumentedException, BGPParsingException {
116 final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.bgp.rib.route
117 .attributes.extended.communities.extended.community.TrafficRateExtendedCommunityCase trafficRate =
118 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.bgp.rib
119 .route.attributes.extended.communities.extended.community.TrafficRateExtendedCommunityCaseBuilder()
120 .setTrafficRateExtendedCommunity(new TrafficRateExtendedCommunityBuilder()
121 .setInformativeAs(new ShortAsNumber(Uint32.valueOf(72)))
122 .setLocalAdministrator(new Bandwidth(new byte[] { 0, 1, 2, 3 })).build()).build();
123 final ExtendedCommunities expected = new ExtendedCommunitiesBuilder().setExtendedCommunity(trafficRate)
124 .setTransitive(true).build();
126 final ByteBuf output = Unpooled.buffer(TRAFFIC_RATE.length);
127 this.registry.serializeExtendedCommunity(expected, output);
128 Assert.assertArrayEquals(TRAFFIC_RATE, output.array());
132 public void testTrafficActionParser() throws BGPDocumentedException, BGPParsingException {
133 final TrafficActionExtendedCommunityCase trafficAction = new TrafficActionExtendedCommunityCaseBuilder()
134 .setTrafficActionExtendedCommunity(new TrafficActionExtendedCommunityBuilder().setSample(true)
135 .setTerminalAction(true).build()).build();
136 final ExtendedCommunities expected = new ExtendedCommunitiesBuilder().setExtendedCommunity(trafficAction)
137 .setTransitive(true).build();
139 final ExtendedCommunities parsed = this.registry.parseExtendedCommunity(Unpooled.copiedBuffer(TRAFFIC_ACTION));
140 Assert.assertEquals(expected, parsed);
144 public void testTrafficActionSerializer() throws BGPDocumentedException, BGPParsingException {
145 final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.bgp.rib.route
146 .attributes.extended.communities.extended.community.TrafficActionExtendedCommunityCase trafficAction =
147 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.bgp.rib
148 .route.attributes.extended.communities.extended.community
149 .TrafficActionExtendedCommunityCaseBuilder().setTrafficActionExtendedCommunity(
150 new TrafficActionExtendedCommunityBuilder().setSample(true).setTerminalAction(true).build())
152 final ExtendedCommunities expected = new ExtendedCommunitiesBuilder().setExtendedCommunity(trafficAction)
153 .setTransitive(true).build();
155 final ByteBuf output = Unpooled.buffer(TRAFFIC_ACTION.length);
156 this.registry.serializeExtendedCommunity(expected, output);
157 Assert.assertArrayEquals(TRAFFIC_ACTION, output.array());
161 public void testTrafficMarkingParser() throws BGPDocumentedException, BGPParsingException {
162 final TrafficMarkingExtendedCommunityCase trafficMarking = new TrafficMarkingExtendedCommunityCaseBuilder()
163 .setTrafficMarkingExtendedCommunity(new TrafficMarkingExtendedCommunityBuilder()
164 .setGlobalAdministrator(new Dscp(Uint8.valueOf(63))).build()).build();
165 final ExtendedCommunities expected = new ExtendedCommunitiesBuilder().setExtendedCommunity(trafficMarking)
166 .setTransitive(true).build();
168 final ExtendedCommunities parsed = this.registry.parseExtendedCommunity(Unpooled.copiedBuffer(TRAFFIC_MARKING));
169 Assert.assertEquals(expected, parsed);
173 public void testTrafficMarkingSerializer() throws BGPDocumentedException, BGPParsingException {
174 final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.bgp.rib.route
175 .attributes.extended.communities.extended.community.TrafficMarkingExtendedCommunityCase trafficMarking =
176 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.bgp.rib
177 .route.attributes.extended.communities.extended.community
178 .TrafficMarkingExtendedCommunityCaseBuilder().setTrafficMarkingExtendedCommunity(
179 new TrafficMarkingExtendedCommunityBuilder()
180 .setGlobalAdministrator(new Dscp(Uint8.valueOf(63))).build()).build();
181 final ExtendedCommunities expected = new ExtendedCommunitiesBuilder().setExtendedCommunity(trafficMarking)
182 .setTransitive(true).build();
184 final ByteBuf output = Unpooled.buffer(TRAFFIC_MARKING.length);
185 this.registry.serializeExtendedCommunity(expected, output);
186 Assert.assertArrayEquals(TRAFFIC_MARKING, output.array());
190 public void testRedirect2bParser() throws BGPDocumentedException, BGPParsingException {
191 final RedirectExtendedCommunityCase redirect = new RedirectExtendedCommunityCaseBuilder()
192 .setRedirectExtendedCommunity(new RedirectExtendedCommunityBuilder()
193 .setGlobalAdministrator(new ShortAsNumber(Uint32.valueOf(35)))
194 .setLocalAdministrator(new byte[] { 4, 2, 8, 7 }).build()).build();
195 final ExtendedCommunities expected = new ExtendedCommunitiesBuilder().setExtendedCommunity(redirect)
196 .setTransitive(true).build();
198 final ExtendedCommunities parsed = this.registry.parseExtendedCommunity(
199 Unpooled.copiedBuffer(REDIRECT_AS_2BYTES));
200 Assert.assertEquals(expected, parsed);
204 public void testredirect2bSerializer() throws BGPDocumentedException, BGPParsingException {
205 final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.bgp.rib.route
206 .attributes.extended.communities.extended.community.RedirectExtendedCommunityCase redirect =
207 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.bgp.rib
208 .route.attributes.extended.communities.extended.community.RedirectExtendedCommunityCaseBuilder()
209 .setRedirectExtendedCommunity(new RedirectExtendedCommunityBuilder()
210 .setGlobalAdministrator(new ShortAsNumber(Uint32.valueOf(35)))
211 .setLocalAdministrator(new byte[] { 4, 2, 8, 7 }).build()).build();
212 final ExtendedCommunities expected = new ExtendedCommunitiesBuilder().setExtendedCommunity(redirect)
213 .setTransitive(true).build();
215 final ByteBuf output = Unpooled.buffer(REDIRECT_AS_2BYTES.length);
216 this.registry.serializeExtendedCommunity(expected, output);
217 Assert.assertArrayEquals(REDIRECT_AS_2BYTES, output.array());
221 public void testRedirectIpv6Parser() throws BGPDocumentedException, BGPParsingException {
222 final ExtendedCommunities expected = new ExtendedCommunitiesBuilder()
223 .setExtendedCommunity(new RedirectIpv6ExtendedCommunityCaseBuilder()
224 .setRedirectIpv6(new RedirectIpv6Builder()
225 .setGlobalAdministrator(new Ipv6AddressNoZone("102:304:506:708:90a:b0c:d0e:f10"))
226 .setLocalAdministrator(Uint16.valueOf(258))
232 final ExtendedCommunities parsed = this.registry.parseExtendedCommunity(Unpooled.copiedBuffer(REDIRECT_IPV6));
233 Assert.assertEquals(expected, parsed);
237 public void testRedirectIpv6Serializer() {
238 final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.bgp.rib.route
239 .attributes.extended.communities.extended.community.RedirectIpv6ExtendedCommunityCase redirect =
240 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.bgp.rib
241 .route.attributes.extended.communities.extended.community.RedirectIpv6ExtendedCommunityCaseBuilder()
242 .setRedirectIpv6(new RedirectIpv6Builder()
243 .setGlobalAdministrator(new Ipv6AddressNoZone("102:304:506:708:90a:b0c:d0e:f10"))
244 .setLocalAdministrator(Uint16.valueOf(258)).build()).build();
245 final ExtendedCommunities expected = new ExtendedCommunitiesBuilder().setExtendedCommunity(redirect)
246 .setTransitive(true).build();
248 final ByteBuf output = Unpooled.buffer(REDIRECT_IPV6.length);
249 this.registry.serializeExtendedCommunity(expected, output);
250 Assert.assertArrayEquals(REDIRECT_IPV6, output.array());
254 public void testRedirect4bParser() throws BGPDocumentedException, BGPParsingException {
255 final RedirectAs4ExtendedCommunityCase redirect = new RedirectAs4ExtendedCommunityCaseBuilder()
256 .setRedirectAs4(new RedirectAs4Builder()
257 .setGlobalAdministrator(new AsNumber(Uint32.valueOf(6548)))
258 .setLocalAdministrator(Uint16.valueOf(126))
262 final ExtendedCommunities expected = new ExtendedCommunitiesBuilder().setExtendedCommunity(redirect)
263 .setTransitive(true).build();
265 final ExtendedCommunities parsed = this.registry.parseExtendedCommunity(
266 Unpooled.copiedBuffer(REDIRECT_AS_4BYTES));
267 Assert.assertEquals(expected, parsed);
271 public void testredirect4bSerializer() throws BGPDocumentedException, BGPParsingException {
272 final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.bgp.rib.route
273 .attributes.extended.communities.extended.community.RedirectAs4ExtendedCommunityCase redirect =
274 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.bgp.rib
275 .route.attributes.extended.communities.extended.community.RedirectAs4ExtendedCommunityCaseBuilder()
276 .setRedirectAs4(new RedirectAs4Builder().setGlobalAdministrator(new AsNumber(Uint32.valueOf(6548)))
277 .setLocalAdministrator(Uint16.valueOf(126)).build()).build();
279 final ExtendedCommunities expected = new ExtendedCommunitiesBuilder().setExtendedCommunity(redirect)
280 .setTransitive(true).build();
282 final ByteBuf output = Unpooled.buffer(REDIRECT_AS_4BYTES.length);
283 this.registry.serializeExtendedCommunity(expected, output);
284 Assert.assertArrayEquals(REDIRECT_AS_4BYTES, output.array());
288 public void testRedirectIpv4Parser() throws BGPDocumentedException, BGPParsingException {
289 final ExtendedCommunities expected = new ExtendedCommunitiesBuilder()
290 .setExtendedCommunity(new RedirectIpv4ExtendedCommunityCaseBuilder()
291 .setRedirectIpv4(new RedirectIpv4Builder()
292 .setGlobalAdministrator(new Ipv4AddressNoZone("127.0.0.1"))
293 .setLocalAdministrator(Uint16.valueOf(126))
299 final ExtendedCommunities parsed = this.registry.parseExtendedCommunity(Unpooled.copiedBuffer(REDIRECT_IPV4));
300 Assert.assertEquals(expected, parsed);
304 public void testredirectIpv4Serializer() throws BGPDocumentedException, BGPParsingException {
305 final ExtendedCommunities expected = new ExtendedCommunitiesBuilder()
306 .setExtendedCommunity(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec
307 .rev180329.bgp.rib.route.attributes.extended.communities.extended.community
308 .RedirectIpv4ExtendedCommunityCaseBuilder()
309 .setRedirectIpv4(new RedirectIpv4Builder()
310 .setGlobalAdministrator(new Ipv4AddressNoZone("127.0.0.1"))
311 .setLocalAdministrator(Uint16.valueOf(126))
317 final ByteBuf output = Unpooled.buffer(REDIRECT_IPV4.length);
318 this.registry.serializeExtendedCommunity(expected, output);
319 Assert.assertArrayEquals(REDIRECT_IPV4, output.array());
323 public void testRedirectIpv4NhParser() throws BGPDocumentedException, BGPParsingException {
324 final ExtendedCommunities expected = new ExtendedCommunitiesBuilder()
325 .setExtendedCommunity(new RedirectIpNhExtendedCommunityCaseBuilder()
326 .setRedirectIpNhExtendedCommunity(new RedirectIpNhExtendedCommunityBuilder()
327 .setNextHopAddress(new IpAddressNoZone(new Ipv4AddressNoZone("127.0.0.1")))
334 final ExtendedCommunities parsed = this.registry.parseExtendedCommunity(
335 Unpooled.copiedBuffer(REDIRECT_NH_IPV4));
336 Assert.assertEquals(expected, parsed);
340 public void testredirectIpv4NhSerializer() throws BGPDocumentedException, BGPParsingException {
341 final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.bgp.rib.route
342 .attributes.extended.communities.extended.community.RedirectIpNhExtendedCommunityCase redirect =
343 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.bgp.rib
344 .route.attributes.extended.communities.extended.community.RedirectIpNhExtendedCommunityCaseBuilder()
345 .setRedirectIpNhExtendedCommunity(new RedirectIpNhExtendedCommunityBuilder()
346 .setNextHopAddress(new IpAddressNoZone(new Ipv4AddressNoZone("127.0.0.1")))
351 final ExtendedCommunities expected = new ExtendedCommunitiesBuilder().setExtendedCommunity(redirect)
352 .setTransitive(true).build();
354 final ByteBuf output = Unpooled.buffer(REDIRECT_NH_IPV4.length);
355 this.registry.serializeExtendedCommunity(expected, output);
356 Assert.assertArrayEquals(REDIRECT_NH_IPV4, output.array());
360 public void testRedirectIpv6NhParser() throws BGPDocumentedException, BGPParsingException {
361 final RedirectIpNhExtendedCommunityCase redirect = new RedirectIpNhExtendedCommunityCaseBuilder()
362 .setRedirectIpNhExtendedCommunity(new RedirectIpNhExtendedCommunityBuilder()
363 .setNextHopAddress(new IpAddressNoZone(new Ipv6AddressNoZone("2001::1")))
368 final ExtendedCommunities expected = new ExtendedCommunitiesBuilder().setExtendedCommunity(redirect)
369 .setTransitive(true).build();
371 final ExtendedCommunities parsed = this.registry.parseExtendedCommunity(
372 Unpooled.copiedBuffer(REDIRECT_NH_IPV6));
373 Assert.assertEquals(expected, parsed);
377 public void testredirectIpv6NhSerializer() throws BGPDocumentedException, BGPParsingException {
378 final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.bgp.rib.route
379 .attributes.extended.communities.extended.community.RedirectIpNhExtendedCommunityCase redirect =
380 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.bgp.rib
381 .route.attributes.extended.communities.extended.community.RedirectIpNhExtendedCommunityCaseBuilder()
382 .setRedirectIpNhExtendedCommunity(new RedirectIpNhExtendedCommunityBuilder()
383 .setNextHopAddress(new IpAddressNoZone(new Ipv6AddressNoZone("2001::1"))).build()).build();
385 final ExtendedCommunities expected = new ExtendedCommunitiesBuilder().setExtendedCommunity(redirect)
386 .setTransitive(true).build();
388 final ByteBuf output = Unpooled.buffer(REDIRECT_NH_IPV6.length);
389 this.registry.serializeExtendedCommunity(expected, output);
390 Assert.assertArrayEquals(REDIRECT_NH_IPV6, output.array());