2d3229b24b86768a4325dfe70695a27eaad1f305
[bgpcep.git] / bgp / extensions / flowspec / src / test / java / org / opendaylight / protocol / bgp / flowspec / extended / communities / FSExtendedCommunitiesTest.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.protocol.bgp.flowspec.extended.communities;
10
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.IpAddress;
27 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
28 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address;
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.RedirectIpv4ExtendedCommunityCase;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.update.attributes.extended.communities.extended.community.RedirectIpv4ExtendedCommunityCaseBuilder;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.update.attributes.extended.communities.extended.community.RedirectIpv6ExtendedCommunityCase;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.update.attributes.extended.communities.extended.community.RedirectIpv6ExtendedCommunityCaseBuilder;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.update.attributes.extended.communities.extended.community.TrafficActionExtendedCommunityCase;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.update.attributes.extended.communities.extended.community.TrafficActionExtendedCommunityCaseBuilder;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.update.attributes.extended.communities.extended.community.TrafficMarkingExtendedCommunityCase;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.update.attributes.extended.communities.extended.community.TrafficMarkingExtendedCommunityCaseBuilder;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.update.attributes.extended.communities.extended.community.TrafficRateExtendedCommunityCase;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.update.attributes.extended.communities.extended.community.TrafficRateExtendedCommunityCaseBuilder;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.attributes.ExtendedCommunities;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.attributes.ExtendedCommunitiesBuilder;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.ShortAsNumber;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.Bandwidth;
58 import org.opendaylight.yangtools.yang.common.Uint16;
59 import org.opendaylight.yangtools.yang.common.Uint32;
60 import org.opendaylight.yangtools.yang.common.Uint8;
61
62 public class FSExtendedCommunitiesTest {
63
64     private static final byte[] TRAFFIC_RATE = {(byte)128, 6, 0, 72, 0, 1, 2, 3};
65
66     private static final byte[] TRAFFIC_ACTION = {(byte)128, 7, 0, 0, 0, 0, 0, 3};
67
68     private static final byte[] REDIRECT_AS_2BYTES = {(byte)128, 8, 0, 35, 4, 2, 8, 7};
69
70     private static final byte[] TRAFFIC_MARKING = {(byte)128, 9, 0, 0, 0, 0, 0, 63};
71
72     private static final byte[] REDIRECT_IPV6 =
73         {(byte)128, 11, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 1, 2};
74
75     private static final byte[] REDIRECT_AS_4BYTES = {(byte)130, 8, 0, 0, 0x19, (byte) 0x94, 0, 126};
76
77     private static final byte[] REDIRECT_IPV4 = {(byte)129, 8, 127, 0, 0, 1, 0, 126};
78
79     private static final byte[] REDIRECT_NH_IPV4 = {8, 0, 127, 0, 0, 1, 0, 1};
80
81     private static final byte[] REDIRECT_NH_IPV6 = {8, 0, 0x20, (byte) 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
82         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0, 0};
83
84     private ExtendedCommunityRegistry registry;
85     private BGPActivator act;
86
87     @Before
88     public void setUp() throws Exception {
89         final SimpleFlowspecExtensionProviderContext fsContext = new SimpleFlowspecExtensionProviderContext();
90         final FlowspecActivator activator = new FlowspecActivator(fsContext);
91
92         this.act = new BGPActivator(activator);
93         final BGPExtensionProviderContext context = new SimpleBGPExtensionProviderContext();
94         this.act.start(context);
95         this.registry = context.getExtendedCommunityRegistry();
96     }
97
98     @After
99     public void tearDown() {
100         this.act.close();
101     }
102
103     @Test
104     public void testTrafficRateParser() throws BGPDocumentedException, BGPParsingException {
105         final TrafficRateExtendedCommunityCase trafficRate = new TrafficRateExtendedCommunityCaseBuilder()
106                 .setTrafficRateExtendedCommunity(new TrafficRateExtendedCommunityBuilder()
107                     .setInformativeAs(new ShortAsNumber(Uint32.valueOf(72)))
108                     .setLocalAdministrator(new Bandwidth(new byte[] { 0, 1, 2, 3 })).build()).build();
109         final ExtendedCommunities expected = new ExtendedCommunitiesBuilder().setExtendedCommunity(trafficRate)
110                 .setTransitive(true).build();
111
112         final ExtendedCommunities parsed = this.registry.parseExtendedCommunity(Unpooled.copiedBuffer(TRAFFIC_RATE));
113         Assert.assertEquals(expected, parsed);
114     }
115
116     @Test
117     public void testTrafficRateSerializer() throws BGPDocumentedException, BGPParsingException {
118         final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.bgp.rib.route
119             .attributes.extended.communities.extended.community.TrafficRateExtendedCommunityCase trafficRate =
120                 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.bgp.rib
121                     .route.attributes.extended.communities.extended.community.TrafficRateExtendedCommunityCaseBuilder()
122                     .setTrafficRateExtendedCommunity(new TrafficRateExtendedCommunityBuilder()
123                         .setInformativeAs(new ShortAsNumber(Uint32.valueOf(72)))
124                         .setLocalAdministrator(new Bandwidth(new byte[] { 0, 1, 2, 3 })).build()).build();
125         final ExtendedCommunities expected = new ExtendedCommunitiesBuilder().setExtendedCommunity(trafficRate)
126                 .setTransitive(true).build();
127
128         final ByteBuf output = Unpooled.buffer(TRAFFIC_RATE.length);
129         this.registry.serializeExtendedCommunity(expected, output);
130         Assert.assertArrayEquals(TRAFFIC_RATE, output.array());
131     }
132
133     @Test
134     public void testTrafficActionParser() throws BGPDocumentedException, BGPParsingException {
135         final TrafficActionExtendedCommunityCase trafficAction = new TrafficActionExtendedCommunityCaseBuilder()
136                 .setTrafficActionExtendedCommunity(new TrafficActionExtendedCommunityBuilder().setSample(true)
137                     .setTerminalAction(true).build()).build();
138         final ExtendedCommunities expected = new ExtendedCommunitiesBuilder().setExtendedCommunity(trafficAction)
139                 .setTransitive(true).build();
140
141         final ExtendedCommunities parsed = this.registry.parseExtendedCommunity(Unpooled.copiedBuffer(TRAFFIC_ACTION));
142         Assert.assertEquals(expected, parsed);
143     }
144
145     @Test
146     public void testTrafficActionSerializer() throws BGPDocumentedException, BGPParsingException {
147         final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.bgp.rib.route
148             .attributes.extended.communities.extended.community.TrafficActionExtendedCommunityCase trafficAction =
149                 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.bgp.rib
150                     .route.attributes.extended.communities.extended.community
151                     .TrafficActionExtendedCommunityCaseBuilder().setTrafficActionExtendedCommunity(
152                         new TrafficActionExtendedCommunityBuilder().setSample(true).setTerminalAction(true).build())
153                     .build();
154         final ExtendedCommunities expected = new ExtendedCommunitiesBuilder().setExtendedCommunity(trafficAction)
155                 .setTransitive(true).build();
156
157         final ByteBuf output = Unpooled.buffer(TRAFFIC_ACTION.length);
158         this.registry.serializeExtendedCommunity(expected, output);
159         Assert.assertArrayEquals(TRAFFIC_ACTION, output.array());
160     }
161
162     @Test
163     public void testTrafficMarkingParser() throws BGPDocumentedException, BGPParsingException {
164         final TrafficMarkingExtendedCommunityCase trafficMarking = new TrafficMarkingExtendedCommunityCaseBuilder()
165                 .setTrafficMarkingExtendedCommunity(new TrafficMarkingExtendedCommunityBuilder()
166                     .setGlobalAdministrator(new Dscp(Uint8.valueOf(63))).build()).build();
167         final ExtendedCommunities expected = new ExtendedCommunitiesBuilder().setExtendedCommunity(trafficMarking)
168                 .setTransitive(true).build();
169
170         final ExtendedCommunities parsed = this.registry.parseExtendedCommunity(Unpooled.copiedBuffer(TRAFFIC_MARKING));
171         Assert.assertEquals(expected, parsed);
172     }
173
174     @Test
175     public void testTrafficMarkingSerializer() throws BGPDocumentedException, BGPParsingException {
176         final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.bgp.rib.route
177             .attributes.extended.communities.extended.community.TrafficMarkingExtendedCommunityCase trafficMarking =
178                 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.bgp.rib
179                     .route.attributes.extended.communities.extended.community
180                     .TrafficMarkingExtendedCommunityCaseBuilder().setTrafficMarkingExtendedCommunity(
181                         new TrafficMarkingExtendedCommunityBuilder()
182                         .setGlobalAdministrator(new Dscp(Uint8.valueOf(63))).build()).build();
183         final ExtendedCommunities expected = new ExtendedCommunitiesBuilder().setExtendedCommunity(trafficMarking)
184                 .setTransitive(true).build();
185
186         final ByteBuf output = Unpooled.buffer(TRAFFIC_MARKING.length);
187         this.registry.serializeExtendedCommunity(expected, output);
188         Assert.assertArrayEquals(TRAFFIC_MARKING, output.array());
189     }
190
191     @Test
192     public void testRedirect2bParser() throws BGPDocumentedException, BGPParsingException {
193         final RedirectExtendedCommunityCase redirect = new RedirectExtendedCommunityCaseBuilder()
194                 .setRedirectExtendedCommunity(new RedirectExtendedCommunityBuilder()
195                     .setGlobalAdministrator(new ShortAsNumber(Uint32.valueOf(35)))
196                     .setLocalAdministrator(new byte[] { 4, 2, 8, 7 }).build()).build();
197         final ExtendedCommunities expected = new ExtendedCommunitiesBuilder().setExtendedCommunity(redirect)
198                 .setTransitive(true).build();
199
200         final ExtendedCommunities parsed = this.registry.parseExtendedCommunity(
201             Unpooled.copiedBuffer(REDIRECT_AS_2BYTES));
202         Assert.assertEquals(expected, parsed);
203     }
204
205     @Test
206     public void testredirect2bSerializer() throws BGPDocumentedException, BGPParsingException {
207         final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.bgp.rib.route
208             .attributes.extended.communities.extended.community.RedirectExtendedCommunityCase redirect =
209                 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.bgp.rib
210                     .route.attributes.extended.communities.extended.community.RedirectExtendedCommunityCaseBuilder()
211                     .setRedirectExtendedCommunity(new RedirectExtendedCommunityBuilder()
212                         .setGlobalAdministrator(new ShortAsNumber(Uint32.valueOf(35)))
213                         .setLocalAdministrator(new byte[] { 4, 2, 8, 7 }).build()).build();
214         final ExtendedCommunities expected = new ExtendedCommunitiesBuilder().setExtendedCommunity(redirect)
215                 .setTransitive(true).build();
216
217         final ByteBuf output = Unpooled.buffer(REDIRECT_AS_2BYTES.length);
218         this.registry.serializeExtendedCommunity(expected, output);
219         Assert.assertArrayEquals(REDIRECT_AS_2BYTES, output.array());
220     }
221
222     @Test
223     public void testRedirectIpv6Parser() throws BGPDocumentedException, BGPParsingException {
224         final RedirectIpv6ExtendedCommunityCase redirect = new RedirectIpv6ExtendedCommunityCaseBuilder()
225                 .setRedirectIpv6(new RedirectIpv6Builder()
226                         .setGlobalAdministrator(new Ipv6Address("102:304:506:708:90a:b0c:d0e:f10"))
227                         .setLocalAdministrator(Uint16.valueOf(258)).build()).build();
228         final ExtendedCommunities expected = new ExtendedCommunitiesBuilder().setExtendedCommunity(redirect)
229                 .setTransitive(true).build();
230
231         final ExtendedCommunities parsed = this.registry.parseExtendedCommunity(Unpooled.copiedBuffer(REDIRECT_IPV6));
232         Assert.assertEquals(expected, parsed);
233     }
234
235     @Test
236     public void testRedirectIpv6Serializer() {
237         final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.bgp.rib.route
238             .attributes.extended.communities.extended.community.RedirectIpv6ExtendedCommunityCase redirect =
239                 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.bgp.rib
240                     .route.attributes.extended.communities.extended.community.RedirectIpv6ExtendedCommunityCaseBuilder()
241                     .setRedirectIpv6(new RedirectIpv6Builder()
242                         .setGlobalAdministrator(new Ipv6Address("102:304:506:708:90a:b0c:d0e:f10"))
243                         .setLocalAdministrator(Uint16.valueOf(258)).build()).build();
244         final ExtendedCommunities expected = new ExtendedCommunitiesBuilder().setExtendedCommunity(redirect)
245                 .setTransitive(true).build();
246
247         final ByteBuf output = Unpooled.buffer(REDIRECT_IPV6.length);
248         this.registry.serializeExtendedCommunity(expected, output);
249         Assert.assertArrayEquals(REDIRECT_IPV6, output.array());
250     }
251
252     @Test
253     public void testRedirect4bParser() throws BGPDocumentedException, BGPParsingException {
254         final RedirectAs4ExtendedCommunityCase redirect = new RedirectAs4ExtendedCommunityCaseBuilder()
255                 .setRedirectAs4(new RedirectAs4Builder()
256                     .setGlobalAdministrator(new AsNumber(Uint32.valueOf(6548)))
257                     .setLocalAdministrator(Uint16.valueOf(126))
258                     .build())
259                 .build();
260
261         final ExtendedCommunities expected = new ExtendedCommunitiesBuilder().setExtendedCommunity(redirect)
262                 .setTransitive(true).build();
263
264         final ExtendedCommunities parsed = this.registry.parseExtendedCommunity(
265             Unpooled.copiedBuffer(REDIRECT_AS_4BYTES));
266         Assert.assertEquals(expected, parsed);
267     }
268
269     @Test
270     public void testredirect4bSerializer() throws BGPDocumentedException, BGPParsingException {
271         final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.bgp.rib.route
272             .attributes.extended.communities.extended.community.RedirectAs4ExtendedCommunityCase redirect =
273                 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.bgp.rib
274                     .route.attributes.extended.communities.extended.community.RedirectAs4ExtendedCommunityCaseBuilder()
275                     .setRedirectAs4(new RedirectAs4Builder().setGlobalAdministrator(new AsNumber(Uint32.valueOf(6548)))
276                         .setLocalAdministrator(Uint16.valueOf(126)).build()).build();
277
278         final ExtendedCommunities expected = new ExtendedCommunitiesBuilder().setExtendedCommunity(redirect)
279                 .setTransitive(true).build();
280
281         final ByteBuf output = Unpooled.buffer(REDIRECT_AS_4BYTES.length);
282         this.registry.serializeExtendedCommunity(expected, output);
283         Assert.assertArrayEquals(REDIRECT_AS_4BYTES, output.array());
284     }
285
286     @Test
287     public void testRedirectIpv4Parser() throws BGPDocumentedException, BGPParsingException {
288         final RedirectIpv4ExtendedCommunityCase redirect = new RedirectIpv4ExtendedCommunityCaseBuilder()
289                 .setRedirectIpv4(new RedirectIpv4Builder().setGlobalAdministrator(new Ipv4Address("127.0.0.1"))
290                     .setLocalAdministrator(Uint16.valueOf(126)).build()).build();
291
292         final ExtendedCommunities expected = new ExtendedCommunitiesBuilder().setExtendedCommunity(redirect)
293                 .setTransitive(true).build();
294
295         final ExtendedCommunities parsed = this.registry.parseExtendedCommunity(Unpooled.copiedBuffer(REDIRECT_IPV4));
296         Assert.assertEquals(expected, parsed);
297     }
298
299     @Test
300     public void testredirectIpv4Serializer() throws BGPDocumentedException, BGPParsingException {
301         final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.bgp.rib.route
302             .attributes.extended.communities.extended.community.RedirectIpv4ExtendedCommunityCase redirect =
303                 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.bgp.rib
304                     .route.attributes.extended.communities.extended.community.RedirectIpv4ExtendedCommunityCaseBuilder()
305                         .setRedirectIpv4(new RedirectIpv4Builder().setGlobalAdministrator(new Ipv4Address("127.0.0.1"))
306                             .setLocalAdministrator(Uint16.valueOf(126)).build()).build();
307
308         final ExtendedCommunities expected = new ExtendedCommunitiesBuilder().setExtendedCommunity(redirect)
309                 .setTransitive(true).build();
310
311         final ByteBuf output = Unpooled.buffer(REDIRECT_IPV4.length);
312         this.registry.serializeExtendedCommunity(expected, output);
313         Assert.assertArrayEquals(REDIRECT_IPV4, output.array());
314     }
315
316     @Test
317     public void testRedirectIpv4NhParser() throws BGPDocumentedException, BGPParsingException {
318         final RedirectIpNhExtendedCommunityCase redirect = new RedirectIpNhExtendedCommunityCaseBuilder()
319                 .setRedirectIpNhExtendedCommunity(new RedirectIpNhExtendedCommunityBuilder()
320                     .setNextHopAddress(new IpAddress(new Ipv4Address("127.0.0.1"))).setCopy(true).build()).build();
321
322         final ExtendedCommunities expected = new ExtendedCommunitiesBuilder().setExtendedCommunity(redirect)
323                 .setTransitive(true).build();
324
325         final ExtendedCommunities parsed = this.registry.parseExtendedCommunity(
326             Unpooled.copiedBuffer(REDIRECT_NH_IPV4));
327         Assert.assertEquals(expected, parsed);
328     }
329
330     @Test
331     public void testredirectIpv4NhSerializer() throws BGPDocumentedException, BGPParsingException {
332         final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.bgp.rib.route
333             .attributes.extended.communities.extended.community.RedirectIpNhExtendedCommunityCase redirect =
334                 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.bgp.rib
335                     .route.attributes.extended.communities.extended.community.RedirectIpNhExtendedCommunityCaseBuilder()
336                     .setRedirectIpNhExtendedCommunity(new RedirectIpNhExtendedCommunityBuilder()
337                         .setNextHopAddress(new IpAddress(new Ipv4Address("127.0.0.1"))).setCopy(true).build()).build();
338
339         final ExtendedCommunities expected = new ExtendedCommunitiesBuilder().setExtendedCommunity(redirect)
340                 .setTransitive(true).build();
341
342         final ByteBuf output = Unpooled.buffer(REDIRECT_NH_IPV4.length);
343         this.registry.serializeExtendedCommunity(expected, output);
344         Assert.assertArrayEquals(REDIRECT_NH_IPV4, output.array());
345     }
346
347     @Test
348     public void testRedirectIpv6NhParser() throws BGPDocumentedException, BGPParsingException {
349         final RedirectIpNhExtendedCommunityCase redirect = new RedirectIpNhExtendedCommunityCaseBuilder()
350                 .setRedirectIpNhExtendedCommunity(new RedirectIpNhExtendedCommunityBuilder()
351                     .setNextHopAddress(new IpAddress(new Ipv6Address("2001::1"))).setCopy(false).build()).build();
352
353         final ExtendedCommunities expected = new ExtendedCommunitiesBuilder().setExtendedCommunity(redirect)
354                 .setTransitive(true).build();
355
356         final ExtendedCommunities parsed = this.registry.parseExtendedCommunity(
357             Unpooled.copiedBuffer(REDIRECT_NH_IPV6));
358         Assert.assertEquals(expected, parsed);
359     }
360
361     @Test
362     public void testredirectIpv6NhSerializer() throws BGPDocumentedException, BGPParsingException {
363         final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.bgp.rib.route
364             .attributes.extended.communities.extended.community.RedirectIpNhExtendedCommunityCase redirect =
365                 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.bgp.rib
366                     .route.attributes.extended.communities.extended.community.RedirectIpNhExtendedCommunityCaseBuilder()
367                     .setRedirectIpNhExtendedCommunity(new RedirectIpNhExtendedCommunityBuilder()
368                         .setNextHopAddress(new IpAddress(new Ipv6Address("2001::1"))).build()).build();
369
370         final ExtendedCommunities expected = new ExtendedCommunitiesBuilder().setExtendedCommunity(redirect)
371                 .setTransitive(true).build();
372
373         final ByteBuf output = Unpooled.buffer(REDIRECT_NH_IPV6.length);
374         this.registry.serializeExtendedCommunity(expected, output);
375         Assert.assertArrayEquals(REDIRECT_NH_IPV6, output.array());
376     }
377
378 }