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
8 package org.opendaylight.protocol.bgp.flowspec;
10 import static org.junit.Assert.assertArrayEquals;
11 import static org.junit.Assert.assertEquals;
12 import static org.mockito.ArgumentMatchers.any;
13 import static org.mockito.Mockito.doReturn;
14 import static org.opendaylight.protocol.bgp.flowspec.SimpleFlowspecIpv4NlriParserTest.PATH_ID;
16 import com.google.common.collect.Lists;
17 import com.google.common.collect.Sets;
18 import io.netty.buffer.ByteBuf;
19 import io.netty.buffer.Unpooled;
20 import java.util.ArrayList;
21 import java.util.List;
22 import java.util.Optional;
23 import org.junit.Before;
24 import org.junit.Test;
25 import org.junit.runner.RunWith;
26 import org.mockito.Mock;
27 import org.mockito.junit.MockitoJUnitRunner;
28 import org.opendaylight.protocol.bgp.flowspec.handlers.AbstractNumericOperandParser;
29 import org.opendaylight.protocol.bgp.flowspec.handlers.AbstractOperandParser;
30 import org.opendaylight.protocol.bgp.flowspec.handlers.BitmaskOperandParser;
31 import org.opendaylight.protocol.bgp.parser.BGPParsingException;
32 import org.opendaylight.protocol.bgp.parser.spi.MultiPathSupport;
33 import org.opendaylight.protocol.bgp.parser.spi.PeerSpecificParserConstraint;
34 import org.opendaylight.protocol.util.ByteArray;
35 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.BitmaskOperand;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.FlowspecSubsequentAddressFamily;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.Fragment;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.NumericOperand;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.Flowspec;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.FlowspecBuilder;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.flowspec.FlowspecType;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.flowspec.flowspec.type.FragmentCase;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.flowspec.flowspec.type.FragmentCaseBuilder;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.flowspec.flowspec.type.fragment._case.Fragments;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.flowspec.flowspec.type.fragment._case.FragmentsBuilder;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.group.ipv6.flowspec.flowspec.type.DestinationIpv6PrefixCase;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.group.ipv6.flowspec.flowspec.type.DestinationIpv6PrefixCaseBuilder;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.group.ipv6.flowspec.flowspec.type.FlowLabelCaseBuilder;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.group.ipv6.flowspec.flowspec.type.NextHeaderCase;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.group.ipv6.flowspec.flowspec.type.NextHeaderCaseBuilder;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.group.ipv6.flowspec.flowspec.type.SourceIpv6PrefixCase;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.group.ipv6.flowspec.flowspec.type.SourceIpv6PrefixCaseBuilder;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.group.ipv6.flowspec.flowspec.type.flow.label._case.FlowLabel;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.group.ipv6.flowspec.flowspec.type.flow.label._case.FlowLabelBuilder;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.group.ipv6.flowspec.flowspec.type.next.header._case.NextHeaders;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.group.ipv6.flowspec.flowspec.type.next.header._case.NextHeadersBuilder;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.ipv6.DestinationFlowspecIpv6Builder;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.ipv6.route.FlowspecRoute;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.AttributesBuilder;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.Attributes1Builder;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.Attributes2Builder;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.update.attributes.MpReachNlriBuilder;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.update.attributes.MpUnreachNlriBuilder;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.update.attributes.mp.reach.nlri.AdvertizedRoutesBuilder;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.update.attributes.mp.unreach.nlri.WithdrawnRoutesBuilder;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.Ipv6AddressFamily;
68 import org.opendaylight.yangtools.yang.common.Uint32;
69 import org.opendaylight.yangtools.yang.common.Uint8;
70 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
71 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
72 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
73 import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
74 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeBuilder;
76 @RunWith(MockitoJUnitRunner.StrictStubs.class)
77 public class SimpleFlowspecIpv6NlriParserTest {
78 private static final NodeIdentifier NEXT_HEADER_NID = new NodeIdentifier(NextHeaders.QNAME);
79 private static final NodeIdentifier FLOW_LABEL_NID = new NodeIdentifier(FlowLabel.QNAME);
82 private PeerSpecificParserConstraint constraint;
84 private MultiPathSupport muliPathSupport;
85 private final SimpleFlowspecExtensionProviderContext flowspecContext = new SimpleFlowspecExtensionProviderContext();
86 private final FlowspecActivator fsa = new FlowspecActivator(this.flowspecContext);
87 private final SimpleFlowspecIpv6NlriParser fsParser = new SimpleFlowspecIpv6NlriParser(
88 this.flowspecContext.getFlowspecTypeRegistry(SimpleFlowspecExtensionProviderContext.AFI.IPV6,
89 SimpleFlowspecExtensionProviderContext.SAFI.FLOWSPEC));
91 private static final byte[] REACHED_NLRI = new byte[] {
93 1, 0x28, 0, 1, 2, 3, 4, 5,
94 2, 0x28, 0, 1, 2, 3, 4, 6,
97 private static final byte[] REACHED_NLRI_ADD_PATH = new byte[] {
100 1, 0x28, 0, 1, 2, 3, 4, 5,
101 2, 0x28, 0, 1, 2, 3, 4, 6,
102 03, (byte) 0x81, 06};
104 private static final byte[] UNREACHED_NLRI = new byte[] {
106 0x0c, (byte) 0x81, 0x0e,
107 0x0d, (byte) 0x21, 1, 0, 0, 6, (byte) 0x91, 1, 2
110 private static final byte[] UNREACHED_NLRI_ADD_PATH = new byte[] {
113 0x0c, (byte) 0x81, 0x0e,
114 0x0d, (byte) 0x21, 1, 0, 0, 6, (byte) 0x91, 1, 2
118 public void setUp() {
119 doReturn(Optional.of(this.muliPathSupport)).when(this.constraint).getPeerConstraint(any());
120 doReturn(true).when(this.muliPathSupport).isTableTypeSupported(any());
124 public void testParseMpReachNlri() throws BGPParsingException {
125 final List<Flowspec> fs = new ArrayList<>();
126 final MpReachNlriBuilder mp = new MpReachNlriBuilder();
128 final FlowspecBuilder builder = new FlowspecBuilder();
129 final DestinationIpv6PrefixCase destinationPrefix = new DestinationIpv6PrefixCaseBuilder()
130 .setDestinationPrefix(new Ipv6Prefix("102:304:500::/40")).build();
131 builder.setFlowspecType(destinationPrefix);
132 fs.add(builder.build());
134 final SourceIpv6PrefixCase sourcePrefix = new SourceIpv6PrefixCaseBuilder().setSourcePrefix(
135 new Ipv6Prefix("102:304:600::/40")).build();
136 builder.setFlowspecType(sourcePrefix);
137 fs.add(builder.build());
139 final List<NextHeaders> nextheaders = Lists.newArrayList(new NextHeadersBuilder().setOp(
140 new NumericOperand(false, true, true, false, false)).setValue(Uint8.valueOf(6)).build());
141 final NextHeaderCase headersCase = new NextHeaderCaseBuilder().setNextHeaders(nextheaders).build();
142 builder.setFlowspecType(headersCase);
143 fs.add(builder.build());
146 mp.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(new org.opendaylight.yang.gen.v1.urn
147 .opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.update.attributes.mp.reach.nlri.advertized.routes
148 .destination.type.DestinationFlowspecIpv6CaseBuilder()
149 .setDestinationFlowspecIpv6(
150 new DestinationFlowspecIpv6Builder()
158 final MpReachNlriBuilder result = new MpReachNlriBuilder();
159 result.setAfi(Ipv6AddressFamily.class);
160 result.setSafi(FlowspecSubsequentAddressFamily.class);
161 this.fsParser.parseNlri(Unpooled.wrappedBuffer(REACHED_NLRI), result, null);
163 final List<Flowspec> flows = ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang
164 .bgp.flowspec.rev200120.update.attributes.mp.reach.nlri.advertized.routes.destination.type
165 .DestinationFlowspecIpv6Case) result.getAdvertizedRoutes().getDestinationType())
166 .getDestinationFlowspecIpv6().getFlowspec();
167 assertEquals(3, flows.size());
168 assertEquals(destinationPrefix, flows.get(0).getFlowspecType());
169 assertEquals(sourcePrefix, flows.get(1).getFlowspecType());
170 assertEquals(headersCase, flows.get(2).getFlowspecType());
172 final ByteBuf buffer = Unpooled.buffer();
173 this.fsParser.serializeAttribute(new AttributesBuilder()
174 .addAugmentation(new Attributes1Builder()
175 .setMpReachNlri(mp.setAfi(Ipv6AddressFamily.class).build())
178 assertArrayEquals(REACHED_NLRI, ByteArray.readAllBytes(buffer));
180 assertEquals("all packets to 102:304:500::/40 AND from 102:304:600::/40 AND where next header equals to 6 ",
181 this.fsParser.stringNlri(flows));
185 public void testParseMpReachNlriConstraint() throws BGPParsingException {
186 final List<Flowspec> fs = new ArrayList<>();
187 final MpReachNlriBuilder mp = new MpReachNlriBuilder();
189 final FlowspecBuilder builder = new FlowspecBuilder();
190 final DestinationIpv6PrefixCase destinationPrefix = new DestinationIpv6PrefixCaseBuilder().setDestinationPrefix(
191 new Ipv6Prefix("102:304:500::/40")).build();
192 builder.setFlowspecType(destinationPrefix);
193 fs.add(builder.build());
195 final SourceIpv6PrefixCase sourcePrefix = new SourceIpv6PrefixCaseBuilder().setSourcePrefix(
196 new Ipv6Prefix("102:304:600::/40")).build();
197 builder.setFlowspecType(sourcePrefix);
198 fs.add(builder.build());
200 final List<NextHeaders> nextheaders = Lists.newArrayList(new NextHeadersBuilder().setOp(
201 new NumericOperand(false, true, true, false, false)).setValue(Uint8.valueOf(6)).build());
202 final NextHeaderCase headersCase = new NextHeaderCaseBuilder().setNextHeaders(nextheaders).build();
203 builder.setFlowspecType(headersCase);
204 fs.add(builder.build());
207 mp.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(new org.opendaylight.yang.gen.v1.urn
208 .opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.update.attributes.mp.reach.nlri.advertized.routes
209 .destination.type.DestinationFlowspecIpv6CaseBuilder()
210 .setDestinationFlowspecIpv6(
211 new DestinationFlowspecIpv6Builder()
219 final MpReachNlriBuilder result = new MpReachNlriBuilder();
220 result.setAfi(Ipv6AddressFamily.class);
221 result.setSafi(FlowspecSubsequentAddressFamily.class);
222 this.fsParser.parseNlri(Unpooled.wrappedBuffer(REACHED_NLRI_ADD_PATH), result, this.constraint);
224 final List<Flowspec> flows = ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang
225 .bgp.flowspec.rev200120.update.attributes.mp.reach.nlri.advertized.routes.destination.type
226 .DestinationFlowspecIpv6Case) result.getAdvertizedRoutes().getDestinationType())
227 .getDestinationFlowspecIpv6().getFlowspec();
228 assertEquals(3, flows.size());
229 assertEquals(destinationPrefix, flows.get(0).getFlowspecType());
230 assertEquals(sourcePrefix, flows.get(1).getFlowspecType());
231 assertEquals(headersCase, flows.get(2).getFlowspecType());
233 final ByteBuf buffer = Unpooled.buffer();
234 this.fsParser.serializeAttribute(new AttributesBuilder()
235 .addAugmentation(new Attributes1Builder()
236 .setMpReachNlri(mp.setAfi(Ipv6AddressFamily.class).build())
239 assertArrayEquals(REACHED_NLRI_ADD_PATH, ByteArray.readAllBytes(buffer));
241 assertEquals("all packets to 102:304:500::/40 AND from 102:304:600::/40 AND where next header equals to 6 ",
242 this.fsParser.stringNlri(flows));
246 public void testParseMpUnreachNlri() throws BGPParsingException {
247 final List<Flowspec> fs = new ArrayList<>();
248 final MpUnreachNlriBuilder mp = new MpUnreachNlriBuilder();
250 final FlowspecBuilder builder = new FlowspecBuilder();
252 final FragmentCase fragment = createFragment();
253 builder.setFlowspecType(fragment);
254 fs.add(builder.build());
256 final FlowspecType label = createLabel();
257 builder.setFlowspecType(label);
258 fs.add(builder.build());
260 mp.setAfi(Ipv6AddressFamily.class).setWithdrawnRoutes(new WithdrawnRoutesBuilder().setDestinationType(
261 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.update
262 .attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationFlowspecIpv6CaseBuilder()
263 .setDestinationFlowspecIpv6(
264 new DestinationFlowspecIpv6Builder()
271 final MpUnreachNlriBuilder result = new MpUnreachNlriBuilder();
272 result.setAfi(Ipv6AddressFamily.class);
273 result.setSafi(FlowspecSubsequentAddressFamily.class);
274 this.fsParser.parseNlri(Unpooled.wrappedBuffer(UNREACHED_NLRI), result, null);
276 final List<Flowspec> flows = ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang
277 .bgp.flowspec.rev200120.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type
278 .DestinationFlowspecIpv6Case) result.getWithdrawnRoutes().getDestinationType())
279 .getDestinationFlowspecIpv6().getFlowspec();
280 assertEquals(2, flows.size());
281 assertEquals(fragment, flows.get(0).getFlowspecType());
282 assertEquals(label, flows.get(1).getFlowspecType());
284 final ByteBuf buffer = Unpooled.buffer();
285 this.fsParser.serializeAttribute(new AttributesBuilder()
286 .addAugmentation(new Attributes2Builder().setMpUnreachNlri(mp.build()).build())
289 assertArrayEquals(UNREACHED_NLRI, ByteArray.readAllBytes(buffer));
291 assertEquals("all packets where fragment does match 'IS FIRST' 'IS LAST' 'IS A' AND where flow label equals to "
292 + "16777222 or equals to 258 ", this.fsParser.stringNlri(flows));
295 private static FragmentCase createFragment() {
296 final List<Fragments> fragments = Lists.newArrayList(new FragmentsBuilder().setOp(
297 new BitmaskOperand(false, true, true, false)).setValue(new Fragment(false, true, true, true)).build());
298 return new FragmentCaseBuilder().setFragments(fragments).build();
301 private static FlowspecType createLabel() {
302 final List<FlowLabel> labels = new ArrayList<>(2);
303 labels.add(new FlowLabelBuilder().setOp(new NumericOperand(false, false, true, false, false))
304 .setValue(Uint32.valueOf(16777222)).build());
305 labels.add(new FlowLabelBuilder().setOp(new NumericOperand(false, true, true, false, false))
306 .setValue(Uint32.valueOf(258)).build());
307 return new FlowLabelCaseBuilder().setFlowLabel(labels).build();
311 public void testParseMpUnreachNlriConstraint() throws BGPParsingException {
312 final List<Flowspec> fs = new ArrayList<>();
313 final MpUnreachNlriBuilder mp = new MpUnreachNlriBuilder();
315 final FlowspecBuilder builder = new FlowspecBuilder();
316 final FragmentCase fragment = createFragment();
318 builder.setFlowspecType(fragment);
319 fs.add(builder.build());
321 final FlowspecType label = createLabel();
322 builder.setFlowspecType(label);
323 fs.add(builder.build());
325 mp.setAfi(Ipv6AddressFamily.class).setWithdrawnRoutes(new WithdrawnRoutesBuilder().setDestinationType(
326 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.update
327 .attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationFlowspecIpv6CaseBuilder()
328 .setDestinationFlowspecIpv6(
329 new DestinationFlowspecIpv6Builder()
337 final MpUnreachNlriBuilder result = new MpUnreachNlriBuilder();
338 result.setAfi(Ipv6AddressFamily.class);
339 result.setSafi(FlowspecSubsequentAddressFamily.class);
340 this.fsParser.parseNlri(Unpooled.wrappedBuffer(UNREACHED_NLRI_ADD_PATH), result, this.constraint);
342 final List<Flowspec> flows = ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang
343 .bgp.flowspec.rev200120.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type
344 .DestinationFlowspecIpv6Case) result.getWithdrawnRoutes().getDestinationType())
345 .getDestinationFlowspecIpv6().getFlowspec();
346 assertEquals(2, flows.size());
347 assertEquals(fragment, flows.get(0).getFlowspecType());
348 assertEquals(label, flows.get(1).getFlowspecType());
350 final ByteBuf buffer = Unpooled.buffer();
351 this.fsParser.serializeAttribute(new AttributesBuilder()
352 .addAugmentation(new Attributes2Builder().setMpUnreachNlri(mp.build()).build())
355 assertArrayEquals(UNREACHED_NLRI_ADD_PATH, ByteArray.readAllBytes(buffer));
357 assertEquals("all packets where fragment does match 'IS FIRST' 'IS LAST' 'IS A' AND where flow label equals to "
358 + "16777222 or equals to 258 ", this.fsParser.stringNlri(flows));
362 public void testExtractFlowspecFragments() {
363 final DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> entry =
364 Builders.mapEntryBuilder();
365 entry.withNodeIdentifier(NodeIdentifierWithPredicates.of(FlowspecRoute.QNAME, FlowspecRoute.QNAME, entry));
366 entry.withChild(Builders.unkeyedListBuilder()
367 .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_NID)
368 .withChild(Builders.unkeyedListEntryBuilder()
369 .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_NID)
370 .withChild(Builders.choiceBuilder()
371 .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_TYPE_NID)
372 .withChild(Builders.unkeyedListBuilder()
373 .withNodeIdentifier(AbstractFlowspecNlriParser.FRAGMENT_NID)
374 .withChild(Builders.unkeyedListEntryBuilder()
375 .withNodeIdentifier(AbstractFlowspecNlriParser.OP_NID)
376 .withChild(Builders.leafBuilder().withNodeIdentifier(AbstractFlowspecNlriParser.OP_NID)
377 .withValue(Sets.newHashSet(AbstractOperandParser.AND_BIT_VALUE,
378 AbstractOperandParser.END_OF_LIST_VALUE, BitmaskOperandParser.MATCH_VALUE,
379 BitmaskOperandParser.NOT_VALUE)).build())
380 .withChild(Builders.leafBuilder().withNodeIdentifier(AbstractFlowspecNlriParser.VALUE_NID)
381 .withValue(Sets.newHashSet(AbstractFlowspecNlriParser.DO_NOT_VALUE,
382 AbstractFlowspecNlriParser.FIRST_VALUE, AbstractFlowspecNlriParser.IS_A_VALUE,
383 AbstractFlowspecNlriParser.LAST_VALUE)).build()).build())
384 .build()).build()).build()).build());
385 final FlowspecBuilder expectedFS = new FlowspecBuilder();
386 expectedFS.setFlowspecType(new FragmentCaseBuilder().setFragments(Lists.newArrayList(new FragmentsBuilder()
387 .setValue(new Fragment(true, true, true, true)).setOp(new BitmaskOperand(true, true, true, true)).build()))
389 final List<Flowspec> expectedValue = new ArrayList<>();
390 expectedValue.add(expectedFS.build());
391 assertEquals(expectedValue, this.fsParser.extractFlowspec(entry.build()));
395 public void testExtractFlowspecNextHeaders() {
396 final DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> entry =
397 Builders.mapEntryBuilder();
398 entry.withNodeIdentifier(NodeIdentifierWithPredicates.of(FlowspecRoute.QNAME, FlowspecRoute.QNAME, entry));
399 entry.withChild(Builders.unkeyedListBuilder()
400 .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_NID)
401 .withChild(Builders.unkeyedListEntryBuilder()
402 .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_NID)
403 .withChild(Builders.choiceBuilder()
404 .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_TYPE_NID)
405 .withChild(Builders.unkeyedListBuilder().withNodeIdentifier(NEXT_HEADER_NID)
406 .withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(NEXT_HEADER_NID)
407 .withChild(Builders.leafBuilder().withNodeIdentifier(AbstractFlowspecNlriParser.OP_NID)
408 .withValue(Sets.newHashSet(AbstractOperandParser.END_OF_LIST_VALUE,
409 AbstractOperandParser.AND_BIT_VALUE)).build())
410 .withChild(Builders.leafBuilder().withNodeIdentifier(AbstractFlowspecNlriParser.VALUE_NID)
411 .withValue(Uint8.valueOf(100)).build()).build())
412 .withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(NEXT_HEADER_NID)
413 .withChild(Builders.leafBuilder().withNodeIdentifier(AbstractFlowspecNlriParser.OP_NID)
414 .withValue(Sets.newHashSet(AbstractOperandParser.AND_BIT_VALUE)).build())
415 .withChild(Builders.leafBuilder().withNodeIdentifier(AbstractFlowspecNlriParser.VALUE_NID)
416 .withValue(Uint8.valueOf(200)).build()).build())
417 .withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(NEXT_HEADER_NID)
418 .withChild(Builders.leafBuilder().withNodeIdentifier(AbstractFlowspecNlriParser.OP_NID)
419 .withValue(Sets.newHashSet(AbstractOperandParser.END_OF_LIST_VALUE,
420 AbstractOperandParser.AND_BIT_VALUE, AbstractNumericOperandParser.EQUALS_VALUE))
422 .withChild(Builders.leafBuilder().withNodeIdentifier(AbstractFlowspecNlriParser.VALUE_NID)
423 .withValue(Uint8.valueOf(210)).build()).build())
424 .build()).build()).build()).build());
426 final FlowspecBuilder expectedFS = new FlowspecBuilder();
427 expectedFS.setFlowspecType(new NextHeaderCaseBuilder().setNextHeaders(Lists.newArrayList(
428 new NextHeadersBuilder().setValue(Uint8.valueOf(100))
429 .setOp(new NumericOperand(true, true, false, false, false)).build(),
430 new NextHeadersBuilder().setValue(Uint8.valueOf(200))
431 .setOp(new NumericOperand(true, false, false, false, false)).build(),
432 new NextHeadersBuilder().setValue(Uint8.valueOf(210))
433 .setOp(new NumericOperand(true, true, true, false, false)).build()))
435 final List<Flowspec> expectedValue = new ArrayList<>();
436 expectedValue.add(expectedFS.build());
437 assertEquals(expectedValue, this.fsParser.extractFlowspec(entry.build()));
441 public void testExtractFlowspecFlowLabels() {
442 final DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> entry =
443 Builders.mapEntryBuilder();
444 entry.withNodeIdentifier(NodeIdentifierWithPredicates.of(FlowspecRoute.QNAME, FlowspecRoute.QNAME, entry));
445 entry.withChild(Builders.unkeyedListBuilder()
446 .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_NID)
447 .withChild(Builders.unkeyedListEntryBuilder()
448 .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_NID)
449 .withChild(Builders.choiceBuilder()
450 .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_TYPE_NID)
451 .withChild(Builders.unkeyedListBuilder().withNodeIdentifier(FLOW_LABEL_NID)
452 .withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(FLOW_LABEL_NID)
453 .withChild(Builders.leafBuilder().withNodeIdentifier(AbstractFlowspecNlriParser.OP_NID)
454 .withValue(Sets.newHashSet(AbstractOperandParser.END_OF_LIST_VALUE,
455 AbstractOperandParser.AND_BIT_VALUE)).build())
456 .withChild(Builders.leafBuilder().withNodeIdentifier(AbstractFlowspecNlriParser.VALUE_NID)
457 .withValue(Uint32.valueOf(100)).build()).build())
458 .withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(FLOW_LABEL_NID)
459 .withChild(Builders.leafBuilder().withNodeIdentifier(AbstractFlowspecNlriParser.OP_NID)
460 .withValue(Sets.newHashSet(AbstractOperandParser.AND_BIT_VALUE)).build())
461 .withChild(Builders.leafBuilder().withNodeIdentifier(AbstractFlowspecNlriParser.VALUE_NID)
462 .withValue(Uint32.valueOf(200)).build()).build())
463 .build()).build()).build()).build());
465 final FlowspecBuilder expectedFS = new FlowspecBuilder();
466 expectedFS.setFlowspecType(new FlowLabelCaseBuilder().setFlowLabel(Lists.newArrayList(
467 new FlowLabelBuilder().setValue(Uint32.valueOf(100))
468 .setOp(new NumericOperand(true, true, false, false, false)).build(),
469 new FlowLabelBuilder().setValue(Uint32.valueOf(200))
470 .setOp(new NumericOperand(true, false, false, false, false)).build()))
472 final List<Flowspec> expectedValue = new ArrayList<>();
473 expectedValue.add(expectedFS.build());
474 assertEquals(expectedValue, this.fsParser.extractFlowspec(entry.build()));
478 public void testExtractFlowspecDestPrefix() {
479 final DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> entry =
480 Builders.mapEntryBuilder();
481 entry.withNodeIdentifier(NodeIdentifierWithPredicates.of(FlowspecRoute.QNAME, FlowspecRoute.QNAME, entry));
482 entry.withChild(Builders.unkeyedListBuilder()
483 .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_NID)
484 .withChild(Builders.unkeyedListEntryBuilder()
485 .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_NID)
486 .withChild(Builders.choiceBuilder()
487 .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_TYPE_NID)
488 .withChild(Builders.leafBuilder().withNodeIdentifier(AbstractFlowspecNlriParser.DEST_PREFIX_NID)
489 .withValue("102:304:500::/40").build()).build()).build()).build());
490 final FlowspecBuilder expectedFS = new FlowspecBuilder();
491 expectedFS.setFlowspecType(new DestinationIpv6PrefixCaseBuilder().setDestinationPrefix(
492 new Ipv6Prefix("102:304:500::/40")).build());
493 final List<Flowspec> expectedValue = new ArrayList<>();
494 expectedValue.add(expectedFS.build());
495 assertEquals(expectedValue, this.fsParser.extractFlowspec(entry.build()));
499 public void testExtractFlowspecSourcePrefix() {
500 final DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> entry =
501 Builders.mapEntryBuilder();
502 entry.withNodeIdentifier(NodeIdentifierWithPredicates.of(FlowspecRoute.QNAME, FlowspecRoute.QNAME, entry));
503 entry.withChild(Builders.unkeyedListBuilder()
504 .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_NID)
505 .withChild(Builders.unkeyedListEntryBuilder()
506 .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_NID)
507 .withChild(Builders.choiceBuilder()
508 .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_TYPE_NID)
509 .withChild(Builders.leafBuilder().withNodeIdentifier(SimpleFlowspecIpv4NlriParser.SOURCE_PREFIX_NID)
510 .withValue("102:304:600::/40").build()).build()).build()).build());
511 final FlowspecBuilder expectedFS = new FlowspecBuilder();
512 expectedFS.setFlowspecType(new SourceIpv6PrefixCaseBuilder().setSourcePrefix(
513 new Ipv6Prefix("102:304:600::/40")).build());
514 final List<Flowspec> expectedValue = new ArrayList<>();
515 expectedValue.add(expectedFS.build());
516 assertEquals(expectedValue, this.fsParser.extractFlowspec(entry.build()));