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;
13 import com.google.common.collect.Lists;
14 import com.google.common.collect.Sets;
15 import io.netty.buffer.ByteBuf;
16 import io.netty.buffer.Unpooled;
17 import java.util.ArrayList;
18 import java.util.List;
19 import java.util.Optional;
20 import org.junit.Before;
21 import org.junit.Test;
22 import org.mockito.Mock;
23 import org.mockito.Mockito;
24 import org.mockito.MockitoAnnotations;
25 import org.opendaylight.protocol.bgp.flowspec.handlers.AbstractNumericOperandParser;
26 import org.opendaylight.protocol.bgp.flowspec.handlers.AbstractOperandParser;
27 import org.opendaylight.protocol.bgp.flowspec.handlers.BitmaskOperandParser;
28 import org.opendaylight.protocol.bgp.parser.BGPParsingException;
29 import org.opendaylight.protocol.bgp.parser.spi.MultiPathSupport;
30 import org.opendaylight.protocol.bgp.parser.spi.PeerSpecificParserConstraint;
31 import org.opendaylight.protocol.util.ByteArray;
32 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.BitmaskOperand;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.Dscp;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.FlowspecSubsequentAddressFamily;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.Fragment;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.NumericOperand;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.Flowspec;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.FlowspecBuilder;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.FlowspecType;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.DestinationPortCaseBuilder;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.DscpCaseBuilder;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.FragmentCaseBuilder;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.IcmpCodeCaseBuilder;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.IcmpTypeCaseBuilder;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.PacketLengthCase;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.PacketLengthCaseBuilder;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.PortCase;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.PortCaseBuilder;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.SourcePortCaseBuilder;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.TcpFlagsCase;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.TcpFlagsCaseBuilder;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.destination.port._case.DestinationPorts;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.destination.port._case.DestinationPortsBuilder;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.dscp._case.Dscps;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.dscp._case.DscpsBuilder;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.fragment._case.Fragments;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.fragment._case.FragmentsBuilder;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.icmp.code._case.Codes;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.icmp.code._case.CodesBuilder;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.icmp.type._case.Types;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.icmp.type._case.TypesBuilder;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.packet.length._case.PacketLengths;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.packet.length._case.PacketLengthsBuilder;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.port._case.Ports;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.port._case.PortsBuilder;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.source.port._case.SourcePorts;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.source.port._case.SourcePortsBuilder;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.tcp.flags._case.TcpFlags;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.tcp.flags._case.TcpFlagsBuilder;
71 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.group.ipv4.flowspec.flowspec.type.DestinationPrefixCase;
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.group.ipv4.flowspec.flowspec.type.DestinationPrefixCaseBuilder;
73 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.group.ipv4.flowspec.flowspec.type.ProtocolIpCaseBuilder;
74 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.group.ipv4.flowspec.flowspec.type.SourcePrefixCase;
75 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.group.ipv4.flowspec.flowspec.type.SourcePrefixCaseBuilder;
76 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.group.ipv4.flowspec.flowspec.type.protocol.ip._case.ProtocolIps;
77 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.group.ipv4.flowspec.flowspec.type.protocol.ip._case.ProtocolIpsBuilder;
78 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.ipv4.DestinationFlowspecBuilder;
79 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.ipv4.route.FlowspecRoute;
80 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.PathId;
81 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.AttributesBuilder;
82 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.Attributes1;
83 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.Attributes1Builder;
84 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.Attributes2;
85 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.Attributes2Builder;
86 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.MpReachNlriBuilder;
87 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.MpUnreachNlriBuilder;
88 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.mp.reach.nlri.AdvertizedRoutesBuilder;
89 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.mp.unreach.nlri.WithdrawnRoutesBuilder;
90 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv4AddressFamily;
91 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
92 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
93 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
94 import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
95 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeAttrBuilder;
97 public class SimpleFlowspecIpv4NlriParserTest {
99 private static final NodeIdentifier PROTOCOL_IP_NID = new NodeIdentifier(ProtocolIps.QNAME);
101 static final PathId PATH_ID = new PathId(1L);
103 private PeerSpecificParserConstraint constraint;
105 private MultiPathSupport muliPathSupport;
107 private static final byte[] REACHED_NLRI = new byte[] {
108 0x21, // NLRI length: 33
109 01, 0x20, 0x0a, 00, 01, 00,
110 02, 0x20, 01, 02, 03, 04,
112 04, 03, (byte) 0x89, 0x45, (byte) 0x8b, (byte) 0x91, 0x1f, (byte) 0x90,
113 05, 0x12, 0x0f, (byte) 0xf9, (byte) 0x81, (byte) 0xb3,
114 06, (byte) 0x91, 0x1f, (byte) 0x90
117 private static final byte[] REACHED_NLRI_ADD_PATH = new byte[] {
119 0x21, // NLRI length: 33
120 01, 0x20, 0x0a, 00, 01, 00,
121 02, 0x20, 01, 02, 03, 04,
123 04, 03, (byte) 0x89, 0x45, (byte) 0x8b, (byte) 0x91, 0x1f, (byte) 0x90,
124 05, 0x12, 0x0f, (byte) 0xf9, (byte) 0x81, (byte) 0xb3,
125 06, (byte) 0x91, 0x1f, (byte) 0x90
128 private static final byte[] UNREACHED_NLRI = new byte[] {
129 0x1B, // NLRI length: 27
130 07, 4, 2, (byte) 0x84, 3,
131 0x08, 4, 04, (byte) 0x80, 05,
132 0x09, 0x12, 04, 01, (byte) 0x91, 0x56, (byte) 0xb1,
133 0x0a, (byte) 0x94, (byte) 0xde, (byte) 0xad,
134 0x0b, (byte) 0x82, 0x2a,
135 0x0c, (byte) 0x81, (byte) 0x0e
138 private static final byte[] UNREACHED_NLRI_ADD_PATH = new byte[] {
140 0x1B, // NLRI length: 27
141 07, 4, 2, (byte) 0x84, 3,
142 0x08, 4, 04, (byte) 0x80, 05,
143 0x09, 0x12, 04, 01, (byte) 0x91, 0x56, (byte) 0xb1,
144 0x0a, (byte) 0x94, (byte) 0xde, (byte) 0xad,
145 0x0b, (byte) 0x82, 0x2a,
146 0x0c, (byte) 0x81, (byte) 0x0e
149 private final SimpleFlowspecExtensionProviderContext flowspecContext = new SimpleFlowspecExtensionProviderContext();
150 private final FlowspecActivator fsa = new FlowspecActivator(flowspecContext);
151 private final SimpleFlowspecIpv4NlriParser FS_PARSER = new SimpleFlowspecIpv4NlriParser(flowspecContext.getFlowspecTypeRegistry(SimpleFlowspecExtensionProviderContext.AFI.IPV4, SimpleFlowspecExtensionProviderContext.SAFI.FLOWSPEC));
154 public void setUp() {
155 MockitoAnnotations.initMocks(this);
156 Mockito.doReturn(Optional.of(this.muliPathSupport)).when(constraint).getPeerConstraint(Mockito.any());
157 Mockito.doReturn(true).when(this.muliPathSupport).isTableTypeSupported(Mockito.any());
161 public void testParseMpReachNlri() throws BGPParsingException {
162 final List<Flowspec> fs = new ArrayList<>();
163 final MpReachNlriBuilder mp = new MpReachNlriBuilder();
165 final FlowspecBuilder builder = new FlowspecBuilder();
166 final DestinationPrefixCase destinationPrefix = new DestinationPrefixCaseBuilder().setDestinationPrefix(new Ipv4Prefix("10.0.1.0/32")).build();
167 builder.setFlowspecType(destinationPrefix);
168 fs.add(builder.build());
169 final SourcePrefixCase sourcePrefix = new SourcePrefixCaseBuilder().setSourcePrefix(new Ipv4Prefix("1.2.3.4/32")).build();
170 builder.setFlowspecType(sourcePrefix);
171 fs.add(builder.build());
173 final FlowspecType prots = createProts();
174 builder.setFlowspecType(prots);
175 fs.add(builder.build());
177 final PortCase ps = createPorts();
178 builder.setFlowspecType(ps);
179 fs.add(builder.build());
181 final FlowspecType dps = createDps();
182 builder.setFlowspecType(dps);
183 fs.add(builder.build());
185 final FlowspecType sps = createSps();
186 builder.setFlowspecType(sps);
187 fs.add(builder.build());
189 mp.setAdvertizedRoutes(
190 new AdvertizedRoutesBuilder().setDestinationType(
191 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationFlowspecCaseBuilder()
192 .setDestinationFlowspec(
193 new DestinationFlowspecBuilder()
200 final SimpleFlowspecIpv4NlriParser parser = new SimpleFlowspecIpv4NlriParser(flowspecContext.getFlowspecTypeRegistry(SimpleFlowspecExtensionProviderContext.AFI.IPV4, SimpleFlowspecExtensionProviderContext.SAFI.FLOWSPEC));
202 final MpReachNlriBuilder result = new MpReachNlriBuilder();
203 result.setAfi(Ipv4AddressFamily.class);
204 result.setSafi(FlowspecSubsequentAddressFamily.class);
205 parser.parseNlri(Unpooled.wrappedBuffer(REACHED_NLRI), result);
207 final List<Flowspec> flows = ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationFlowspecCase) (result.getAdvertizedRoutes().getDestinationType()))
208 .getDestinationFlowspec()
210 testFlows(flows, destinationPrefix, sourcePrefix, prots, prots, ps, dps, sps);
212 final ByteBuf buffer = Unpooled.buffer();
213 parser.serializeAttribute(new AttributesBuilder().addAugmentation(Attributes1.class, new Attributes1Builder().setMpReachNlri(mp.setAfi(Ipv4AddressFamily.class).build()).build()).build(), buffer);
214 assertArrayEquals(REACHED_NLRI, ByteArray.readAllBytes(buffer));
216 assertEquals("all packets to 10.0.1.0/32 AND from 1.2.3.4/32 AND where IP protocol equals to 6 AND where port is greater than or equals to 137 and is less than or equals to 139 or equals to 8080 AND where destination port is greater than 4089 or equals to 179 AND where source port equals to 8080 ", FS_PARSER.stringNlri(flows));
219 private void testFlows(final List<Flowspec> flows, final DestinationPrefixCase destinationPrefix, final SourcePrefixCase sourcePrefix, final FlowspecType prots, final FlowspecType flowspecType, final PortCase ps, final FlowspecType dps, final FlowspecType sps) {
220 assertEquals(6, flows.size());
221 assertEquals(destinationPrefix, flows.get(0).getFlowspecType());
222 assertEquals(sourcePrefix, flows.get(1).getFlowspecType());
223 assertEquals(prots, flows.get(2).getFlowspecType());
224 assertEquals(ps, flows.get(3).getFlowspecType());
225 assertEquals(dps, flows.get(4).getFlowspecType());
226 assertEquals(sps, flows.get(5).getFlowspecType());
229 private FlowspecType createSps() {
230 final List<SourcePorts> sports = Lists.newArrayList(new SourcePortsBuilder().setOp(new NumericOperand(false, true, true, false, false)).setValue(8080).build());
231 return new SourcePortCaseBuilder().setSourcePorts(sports).build();
234 private FlowspecType createProts() {
235 final List<ProtocolIps> protocols = Lists.newArrayList(new ProtocolIpsBuilder().setOp(new NumericOperand(false, true, true, false, false)).setValue((short) 6).build());
236 return new ProtocolIpCaseBuilder().setProtocolIps(protocols).build();
239 private FlowspecType createDps() {
240 final List<DestinationPorts> destports = Lists.newArrayList(new DestinationPortsBuilder().setOp(new NumericOperand(false, false, false, true, false)).setValue(4089).build(),
241 new DestinationPortsBuilder().setOp(new NumericOperand(false, true, true, false, false)).setValue(179).build());
242 return new DestinationPortCaseBuilder().setDestinationPorts(destports).build();
246 public void testParseMpReachNlriConstraint() throws BGPParsingException {
247 final List<Flowspec> fs = new ArrayList<>();
248 final MpReachNlriBuilder mp = new MpReachNlriBuilder();
250 final FlowspecBuilder builder = new FlowspecBuilder();
251 final DestinationPrefixCase destinationPrefix = new DestinationPrefixCaseBuilder().setDestinationPrefix(new Ipv4Prefix("10.0.1.0/32")).build();
252 builder.setFlowspecType(destinationPrefix);
253 fs.add(builder.build());
254 final SourcePrefixCase sourcePrefix = new SourcePrefixCaseBuilder().setSourcePrefix(new Ipv4Prefix("1.2.3.4/32")).build();
255 builder.setFlowspecType(sourcePrefix);
256 fs.add(builder.build());
258 final FlowspecType prots = createProts();
259 builder.setFlowspecType(prots);
260 fs.add(builder.build());
262 final PortCase ps = createPorts();
263 builder.setFlowspecType(ps);
264 fs.add(builder.build());
266 final FlowspecType dps = createDps();
267 builder.setFlowspecType(dps);
268 fs.add(builder.build());
270 final FlowspecType sps = createSps();
271 builder.setFlowspecType(sps);
272 fs.add(builder.build());
274 mp.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(
275 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationFlowspecCaseBuilder()
276 .setDestinationFlowspec(
277 new DestinationFlowspecBuilder()
285 final SimpleFlowspecIpv4NlriParser parser = new SimpleFlowspecIpv4NlriParser(flowspecContext.getFlowspecTypeRegistry(SimpleFlowspecExtensionProviderContext.AFI.IPV4, SimpleFlowspecExtensionProviderContext.SAFI.FLOWSPEC));
287 final MpReachNlriBuilder result = new MpReachNlriBuilder();
288 result.setAfi(Ipv4AddressFamily.class);
289 result.setSafi(FlowspecSubsequentAddressFamily.class);
290 parser.parseNlri(Unpooled.wrappedBuffer(REACHED_NLRI_ADD_PATH), result, this.constraint);
292 final List<Flowspec> flows = ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationFlowspecCase) (result.getAdvertizedRoutes().getDestinationType()))
293 .getDestinationFlowspec()
295 testFlows(flows, destinationPrefix, sourcePrefix, prots, prots, ps, dps, sps);
297 final ByteBuf buffer = Unpooled.buffer();
298 parser.serializeAttribute(new AttributesBuilder().addAugmentation(Attributes1.class, new Attributes1Builder().setMpReachNlri(mp.setAfi(Ipv4AddressFamily.class).build()).build()).build(), buffer);
299 assertArrayEquals(REACHED_NLRI_ADD_PATH, ByteArray.readAllBytes(buffer));
301 assertEquals("all packets to 10.0.1.0/32 AND from 1.2.3.4/32 AND where IP protocol equals to 6 AND where port is greater than or equals to 137 and is less than or equals to 139 or equals to 8080 AND where destination port is greater than 4089 or equals to 179 AND where source port equals to 8080 ", FS_PARSER.stringNlri(flows));
304 private PortCase createPorts() {
305 final List<Ports> ports = Lists.newArrayList(new PortsBuilder().setOp(new NumericOperand(false, false, true, true, false)).setValue(137).build(),
306 new PortsBuilder().setOp(new NumericOperand(true, false, true, false, true)).setValue(139).build(),
307 new PortsBuilder().setOp(new NumericOperand(false, true, true, false, false)).setValue(8080).build());
309 return new PortCaseBuilder().setPorts(ports).build();
313 public void testParseMpUnreachNlri() throws BGPParsingException {
314 final List<Flowspec> fs = new ArrayList<>();
315 final MpUnreachNlriBuilder mp = new MpUnreachNlriBuilder();
317 final FlowspecBuilder builder = new FlowspecBuilder();
319 final FlowspecType icmpType = createIcmpType();
320 builder.setFlowspecType(icmpType);
321 fs.add(builder.build());
323 final FlowspecType icmpCode = createIcmpCode();
324 builder.setFlowspecType(icmpCode);
325 fs.add(builder.build());
327 final TcpFlagsCase tcp = createTcp();
328 builder.setFlowspecType(tcp);
329 fs.add(builder.build());
331 final PacketLengthCase packet = createPackets();
332 builder.setFlowspecType(packet);
333 fs.add(builder.build());
335 final FlowspecType dscp = createDscp();
336 builder.setFlowspecType(dscp);
337 fs.add(builder.build());
339 final FlowspecType fragment = createFragment();
340 builder.setFlowspecType(fragment);
341 fs.add(builder.build());
343 mp.setAfi(Ipv4AddressFamily.class).setWithdrawnRoutes(new WithdrawnRoutesBuilder().setDestinationType(
344 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationFlowspecCaseBuilder()
345 .setDestinationFlowspec(
346 new DestinationFlowspecBuilder()
353 final SimpleFlowspecIpv4NlriParser parser = new SimpleFlowspecIpv4NlriParser(flowspecContext.getFlowspecTypeRegistry(SimpleFlowspecExtensionProviderContext.AFI.IPV4, SimpleFlowspecExtensionProviderContext.SAFI.FLOWSPEC));
355 final MpUnreachNlriBuilder result = new MpUnreachNlriBuilder();
356 result.setAfi(Ipv4AddressFamily.class);
357 result.setSafi(FlowspecSubsequentAddressFamily.class);
358 parser.parseNlri(Unpooled.wrappedBuffer(UNREACHED_NLRI), result);
360 final List<Flowspec> flows = ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationFlowspecCase) (result.getWithdrawnRoutes().getDestinationType()))
361 .getDestinationFlowspec()
363 checkUnreachFlows(flows, icmpType, icmpCode, tcp, packet, dscp, fragment);
365 final ByteBuf buffer = Unpooled.buffer();
366 parser.serializeNlri(new Object[] {flows}, null, buffer);
367 assertArrayEquals(UNREACHED_NLRI, ByteArray.readAllBytes(buffer));
369 parser.serializeAttribute(new AttributesBuilder().addAugmentation(Attributes2.class, new Attributes2Builder().setMpUnreachNlri(mp.build()).build()).build(), buffer);
370 assertArrayEquals(UNREACHED_NLRI, ByteArray.readAllBytes(buffer));
372 assertEquals("all packets where ICMP type is less than 2 or is less than 3 AND where ICMP code is less than 4 or 5 AND where TCP flags is not 1025 or does match 22193 AND where packet length is less than 57005 AND where DSCP is greater than 42 AND where fragment does match 'IS FIRST' 'IS LAST' 'IS A' ", FS_PARSER.stringNlri(flows));
376 private FlowspecType createFragment() {
377 final List<Fragments> fragments = Lists.newArrayList(new FragmentsBuilder().setOp(new BitmaskOperand(false, true, true, false)).setValue(new Fragment(false, true, true, true)).build());
378 return new FragmentCaseBuilder().setFragments(fragments).build();
381 private FlowspecType createDscp() {
382 final List<Dscps> dscps = Lists.newArrayList(new DscpsBuilder().setOp(new NumericOperand(false, true, false, true, false)).setValue(new Dscp((short) 42)).build());
383 return new DscpCaseBuilder().setDscps(dscps).build();
386 private PacketLengthCase createPackets() {
387 final List<PacketLengths> packets = Lists.newArrayList(new PacketLengthsBuilder().setOp(new NumericOperand(false, true, false, false, true))
388 .setValue(57005).build());
389 return new PacketLengthCaseBuilder().setPacketLengths(packets).build();
392 private TcpFlagsCase createTcp() {
393 final List<TcpFlags> flags = Lists.newArrayList(new TcpFlagsBuilder().setOp(new BitmaskOperand(false, false, false, true)).setValue(1025).build(),
394 new TcpFlagsBuilder().setOp(new BitmaskOperand(false, true, true, false)).setValue(22193).build());
395 return new TcpFlagsCaseBuilder().setTcpFlags(flags).build();
398 private FlowspecType createIcmpCode() {
399 final List<Codes> codes = Lists.newArrayList(new CodesBuilder().setOp(new NumericOperand(false, false, false, false, true)).setValue((short) 4).build(),
400 new CodesBuilder().setOp(new NumericOperand(false, true, false, false, false)).setValue((short) 5).build());
401 return new IcmpCodeCaseBuilder().setCodes(codes).build();
404 private FlowspecType createIcmpType() {
405 final List<Types> types = Lists.newArrayList(new TypesBuilder().setOp(new NumericOperand(false, false, false, false, true)).setValue((short) 2).build(),
406 new TypesBuilder().setOp(new NumericOperand(false, true, false, false, true)).setValue((short) 3).build());
407 return new IcmpTypeCaseBuilder().setTypes(types).build();
410 private void checkUnreachFlows(final List<Flowspec> flows, final FlowspecType icmpType, final FlowspecType icmpCode, final TcpFlagsCase tcp,
411 final PacketLengthCase packet, final FlowspecType dscp, final FlowspecType fragment) {
412 assertEquals(6, flows.size());
413 assertEquals(icmpType, flows.get(0).getFlowspecType());
414 assertEquals(icmpCode, flows.get(1).getFlowspecType());
415 assertEquals(tcp, flows.get(2).getFlowspecType());
416 assertEquals(packet, flows.get(3).getFlowspecType());
417 assertEquals(dscp, flows.get(4).getFlowspecType());
418 assertEquals(fragment, flows.get(5).getFlowspecType());
422 public void testParseMpUnreachNlriConstraint() throws BGPParsingException {
423 final List<Flowspec> fs = new ArrayList<>();
424 final MpUnreachNlriBuilder mp = new MpUnreachNlriBuilder();
426 final FlowspecBuilder builder = new FlowspecBuilder();
428 final FlowspecType icmpType = createIcmpType();
429 builder.setFlowspecType(icmpType);
430 fs.add(builder.build());
432 final FlowspecType icmpCode = createIcmpCode();
433 builder.setFlowspecType(icmpCode);
434 fs.add(builder.build());
436 final TcpFlagsCase tcp = createTcp();
437 builder.setFlowspecType(tcp);
438 fs.add(builder.build());
440 final PacketLengthCase packet = createPackets();
441 builder.setFlowspecType(packet);
442 fs.add(builder.build());
444 final FlowspecType dscp = createDscp();
445 builder.setFlowspecType(dscp);
446 fs.add(builder.build());
448 final FlowspecType fragment = createFragment();
449 builder.setFlowspecType(fragment);
450 fs.add(builder.build());
452 mp.setAfi(Ipv4AddressFamily.class).setWithdrawnRoutes(new WithdrawnRoutesBuilder().setDestinationType(
453 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationFlowspecCaseBuilder()
454 .setDestinationFlowspec(
455 new DestinationFlowspecBuilder()
463 final SimpleFlowspecIpv4NlriParser parser = new SimpleFlowspecIpv4NlriParser(flowspecContext.getFlowspecTypeRegistry(SimpleFlowspecExtensionProviderContext.AFI.IPV4, SimpleFlowspecExtensionProviderContext.SAFI.FLOWSPEC));
465 final MpUnreachNlriBuilder result = new MpUnreachNlriBuilder();
466 result.setAfi(Ipv4AddressFamily.class);
467 result.setSafi(FlowspecSubsequentAddressFamily.class);
468 parser.parseNlri(Unpooled.wrappedBuffer(UNREACHED_NLRI_ADD_PATH), result, this.constraint);
470 final List<Flowspec> flows = ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationFlowspecCase) (result.getWithdrawnRoutes().getDestinationType()))
471 .getDestinationFlowspec()
473 checkUnreachFlows(flows, icmpType, icmpCode, tcp, packet, dscp, fragment);
476 final ByteBuf buffer = Unpooled.buffer();
477 parser.serializeNlri(new Object[] {flows}, PATH_ID, buffer);
478 assertArrayEquals(UNREACHED_NLRI_ADD_PATH, ByteArray.readAllBytes(buffer));
480 parser.serializeAttribute(new AttributesBuilder().addAugmentation(Attributes2.class, new Attributes2Builder().setMpUnreachNlri(mp.build()).build()).build(), buffer);
481 assertArrayEquals(UNREACHED_NLRI_ADD_PATH, ByteArray.readAllBytes(buffer));
483 assertEquals("all packets where ICMP type is less than 2 or is less than 3 AND where ICMP code is less than 4 or 5 AND where TCP flags is not 1025 or does match 22193 AND where packet length is less than 57005 AND where DSCP is greater than 42 AND where fragment does match 'IS FIRST' 'IS LAST' 'IS A' ", FS_PARSER.stringNlri(flows));
488 public void testExtractFlowspecDestPrefix() {
489 final DataContainerNodeAttrBuilder<NodeIdentifierWithPredicates, MapEntryNode> entry = Builders.mapEntryBuilder();
490 entry.withNodeIdentifier(new NodeIdentifierWithPredicates(FlowspecRoute.QNAME, FlowspecRoute.QNAME, entry));
491 entry.withChild(Builders.unkeyedListBuilder()
492 .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_NID)
493 .withChild(Builders.unkeyedListEntryBuilder()
494 .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_NID)
495 .withChild(Builders.choiceBuilder()
496 .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_TYPE_NID)
497 .withChild(Builders.leafBuilder().withNodeIdentifier(AbstractFlowspecNlriParser.DEST_PREFIX_NID).withValue("127.0.0.5/32").build()).build()).build()).build());
499 final FlowspecBuilder expectedFS = new FlowspecBuilder();
500 expectedFS.setFlowspecType(new DestinationPrefixCaseBuilder().setDestinationPrefix(new Ipv4Prefix("127.0.0.5/32")).build());
501 final List<Flowspec> expected = new ArrayList<>();
502 expected.add(expectedFS.build());
503 assertEquals(expected, FS_PARSER.extractFlowspec(entry.build()));
507 public void testExtractFlowspecSourcePrefix() {
508 final DataContainerNodeAttrBuilder<NodeIdentifierWithPredicates, MapEntryNode> entry = Builders.mapEntryBuilder();
509 entry.withNodeIdentifier(new NodeIdentifierWithPredicates(FlowspecRoute.QNAME, FlowspecRoute.QNAME, entry));
510 entry.withChild(Builders.unkeyedListBuilder()
511 .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_NID)
512 .withChild(Builders.unkeyedListEntryBuilder()
513 .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_NID)
514 .withChild(Builders.choiceBuilder()
515 .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_TYPE_NID)
516 .withChild(Builders.leafBuilder().withNodeIdentifier(AbstractFlowspecNlriParser.SOURCE_PREFIX_NID).withValue("127.0.0.6/32").build()).build()).build()).build());
518 final FlowspecBuilder expectedFS = new FlowspecBuilder();
519 expectedFS.setFlowspecType(new SourcePrefixCaseBuilder().setSourcePrefix(new Ipv4Prefix("127.0.0.6/32")).build());
520 final List<Flowspec> expected = new ArrayList<>();
521 expected.add(expectedFS.build());
522 assertEquals(expected, FS_PARSER.extractFlowspec(entry.build()));
526 public void testExtractFlowspecProtocolIps() {
527 final DataContainerNodeAttrBuilder<NodeIdentifierWithPredicates, MapEntryNode> entry = Builders.mapEntryBuilder();
528 entry.withNodeIdentifier(new NodeIdentifierWithPredicates(FlowspecRoute.QNAME, FlowspecRoute.QNAME, entry));
529 entry.withChild(Builders.unkeyedListBuilder()
530 .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_NID)
531 .withChild(Builders.unkeyedListEntryBuilder()
532 .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_NID)
533 .withChild(Builders.choiceBuilder()
534 .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_TYPE_NID)
535 .withChild(Builders.unkeyedListBuilder().withNodeIdentifier(PROTOCOL_IP_NID)
536 .withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(PROTOCOL_IP_NID)
537 .withChild(Builders.leafBuilder().withNodeIdentifier(AbstractFlowspecNlriParser.OP_NID).withValue(Sets.<String>newHashSet(AbstractOperandParser.END_OF_LIST_VALUE, AbstractOperandParser.AND_BIT_VALUE)).build())
538 .withChild(Builders.leafBuilder().withNodeIdentifier(AbstractFlowspecNlriParser.VALUE_NID).withValue((short) 100).build()).build())
539 .withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(PROTOCOL_IP_NID)
540 .withChild(Builders.leafBuilder().withNodeIdentifier(AbstractFlowspecNlriParser.OP_NID).withValue(Sets.<String>newHashSet(AbstractOperandParser.AND_BIT_VALUE)).build())
541 .withChild(Builders.leafBuilder().withNodeIdentifier(AbstractFlowspecNlriParser.VALUE_NID).withValue((short) 200).build()).build())
542 .withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(PROTOCOL_IP_NID)
543 .withChild(Builders.leafBuilder().withNodeIdentifier(AbstractFlowspecNlriParser.OP_NID).withValue(Sets.<String>newHashSet(AbstractOperandParser.END_OF_LIST_VALUE, AbstractOperandParser.AND_BIT_VALUE, AbstractNumericOperandParser.EQUALS_VALUE)).build())
544 .withChild(Builders.leafBuilder().withNodeIdentifier(AbstractFlowspecNlriParser.VALUE_NID).withValue((short) 240).build()).build())
545 .build()).build()).build()).build());
547 final FlowspecBuilder expectedFS = new FlowspecBuilder();
548 expectedFS.setFlowspecType(new ProtocolIpCaseBuilder().setProtocolIps(Lists.<ProtocolIps>newArrayList(
549 new ProtocolIpsBuilder().setValue((short) 100).setOp(new NumericOperand(true, true, false, false, false)).build(),
550 new ProtocolIpsBuilder().setValue((short) 200).setOp(new NumericOperand(true, false, false, false, false)).build(),
551 new ProtocolIpsBuilder().setValue((short) 240).setOp(new NumericOperand(true, true, true, false, false)).build())).build());
552 final List<Flowspec> expected = new ArrayList<>();
553 expected.add(expectedFS.build());
554 assertEquals(expected, FS_PARSER.extractFlowspec(entry.build()));
558 public void testExtractFlowspecPorts() {
559 final DataContainerNodeAttrBuilder<NodeIdentifierWithPredicates, MapEntryNode> entry = Builders.mapEntryBuilder();
560 entry.withNodeIdentifier(new NodeIdentifierWithPredicates(FlowspecRoute.QNAME, FlowspecRoute.QNAME, entry));
561 entry.withChild(Builders.unkeyedListBuilder()
562 .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_NID)
563 .withChild(Builders.unkeyedListEntryBuilder()
564 .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_NID)
565 .withChild(Builders.choiceBuilder()
566 .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_TYPE_NID)
567 .withChild(Builders.unkeyedListBuilder().withNodeIdentifier(AbstractFlowspecNlriParser.PORTS_NID)
568 .withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(PROTOCOL_IP_NID)
569 .withChild(Builders.leafBuilder().withNodeIdentifier(AbstractFlowspecNlriParser.OP_NID).withValue(Sets.<String>newHashSet(AbstractOperandParser.END_OF_LIST_VALUE, AbstractOperandParser.AND_BIT_VALUE, AbstractNumericOperandParser.LESS_THAN_VALUE)).build())
570 .withChild(Builders.leafBuilder().withNodeIdentifier(AbstractFlowspecNlriParser.VALUE_NID).withValue(100).build()).build())
571 .build()).build()).build()).build());
573 final FlowspecBuilder expectedFS = new FlowspecBuilder();
574 expectedFS.setFlowspecType(new PortCaseBuilder().setPorts(Lists.<Ports>newArrayList(new PortsBuilder().setValue(100).setOp(new NumericOperand(true, true, false, false, true)).build())).build());
575 final List<Flowspec> expected = new ArrayList<>();
576 expected.add(expectedFS.build());
577 assertEquals(expected, FS_PARSER.extractFlowspec(entry.build()));
581 public void testExtractFlowspecDestinationPorts() {
582 final DataContainerNodeAttrBuilder<NodeIdentifierWithPredicates, MapEntryNode> entry = Builders.mapEntryBuilder();
583 entry.withNodeIdentifier(new NodeIdentifierWithPredicates(FlowspecRoute.QNAME, FlowspecRoute.QNAME, entry));
584 entry.withChild(Builders.unkeyedListBuilder()
585 .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_NID)
586 .withChild(Builders.unkeyedListEntryBuilder()
587 .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_NID)
588 .withChild(Builders.choiceBuilder()
589 .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_TYPE_NID)
590 .withChild(Builders.unkeyedListBuilder().withNodeIdentifier(AbstractFlowspecNlriParser.DEST_PORT_NID)
591 .withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(AbstractFlowspecNlriParser.OP_NID)
592 .withChild(Builders.leafBuilder().withNodeIdentifier(AbstractFlowspecNlriParser.OP_NID).withValue(Sets.<String>newHashSet(AbstractOperandParser.END_OF_LIST_VALUE, AbstractNumericOperandParser.EQUALS_VALUE)).build())
593 .withChild(Builders.leafBuilder().withNodeIdentifier(AbstractFlowspecNlriParser.VALUE_NID).withValue(1024).build()).build())
594 .build()).build()).build()).build());
595 final FlowspecBuilder expectedFS = new FlowspecBuilder();
596 expectedFS.setFlowspecType(new DestinationPortCaseBuilder().setDestinationPorts(Lists.<DestinationPorts>newArrayList(new DestinationPortsBuilder().setValue(1024).setOp(new NumericOperand(false, true, true, false, false)).build())).build());
597 final List<Flowspec> expected = new ArrayList<>();
598 expected.add(expectedFS.build());
599 assertEquals(expected, FS_PARSER.extractFlowspec(entry.build()));
603 public void testExtractFlowspecSourcePorts() {
604 final DataContainerNodeAttrBuilder<NodeIdentifierWithPredicates, MapEntryNode> entry = Builders.mapEntryBuilder();
605 entry.withNodeIdentifier(new NodeIdentifierWithPredicates(FlowspecRoute.QNAME, FlowspecRoute.QNAME, entry));
606 entry.withChild(Builders.unkeyedListBuilder()
607 .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_NID)
608 .withChild(Builders.unkeyedListEntryBuilder()
609 .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_NID)
610 .withChild(Builders.choiceBuilder()
611 .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_TYPE_NID)
612 .withChild(Builders.unkeyedListBuilder().withNodeIdentifier(AbstractFlowspecNlriParser.SOURCE_PORT_NID)
613 .withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(AbstractFlowspecNlriParser.OP_NID)
614 .withChild(Builders.leafBuilder().withNodeIdentifier(AbstractFlowspecNlriParser.OP_NID).withValue(Sets.<String>newHashSet(AbstractOperandParser.AND_BIT_VALUE, AbstractOperandParser.END_OF_LIST_VALUE, AbstractNumericOperandParser.EQUALS_VALUE, AbstractNumericOperandParser.GREATER_THAN_VALUE, AbstractNumericOperandParser.LESS_THAN_VALUE)).build())
615 .withChild(Builders.leafBuilder().withNodeIdentifier(AbstractFlowspecNlriParser.VALUE_NID).withValue(8080).build()).build())
616 .build()).build()).build()).build());
617 final FlowspecBuilder expectedFS = new FlowspecBuilder();
618 expectedFS.setFlowspecType(new SourcePortCaseBuilder().setSourcePorts(Lists.<SourcePorts>newArrayList(new SourcePortsBuilder().setValue(8080).setOp(new NumericOperand(true, true, true, true, true)).build())).build());
619 final List<Flowspec> expected = new ArrayList<>();
620 expected.add(expectedFS.build());
621 assertEquals(expected, FS_PARSER.extractFlowspec(entry.build()));
625 public void testExtractFlowspecSourceTypes() {
626 final DataContainerNodeAttrBuilder<NodeIdentifierWithPredicates, MapEntryNode> entry = Builders.mapEntryBuilder();
627 entry.withNodeIdentifier(new NodeIdentifierWithPredicates(FlowspecRoute.QNAME, FlowspecRoute.QNAME, entry));
628 entry.withChild(Builders.unkeyedListBuilder()
629 .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_NID)
630 .withChild(Builders.unkeyedListEntryBuilder()
631 .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_NID)
632 .withChild(Builders.choiceBuilder()
633 .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_TYPE_NID)
634 .withChild(Builders.unkeyedListBuilder().withNodeIdentifier(AbstractFlowspecNlriParser.ICMP_TYPE_NID)
635 .withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(AbstractFlowspecNlriParser.OP_NID)
636 .withChild(Builders.leafBuilder().withNodeIdentifier(AbstractFlowspecNlriParser.OP_NID).withValue(Sets.<String>newHashSet(AbstractOperandParser.AND_BIT_VALUE, AbstractOperandParser.END_OF_LIST_VALUE, AbstractNumericOperandParser.EQUALS_VALUE, AbstractNumericOperandParser.GREATER_THAN_VALUE, AbstractNumericOperandParser.LESS_THAN_VALUE)).build())
637 .withChild(Builders.leafBuilder().withNodeIdentifier(AbstractFlowspecNlriParser.VALUE_NID).withValue((short) 22).build()).build())
638 .build()).build()).build()).build());
639 final FlowspecBuilder expectedFS = new FlowspecBuilder();
640 expectedFS.setFlowspecType(new IcmpTypeCaseBuilder().setTypes(Lists.<Types>newArrayList(new TypesBuilder().setValue((short) 22).setOp(new NumericOperand(true, true, true, true, true)).build())).build());
641 final List<Flowspec> expected = new ArrayList<>();
642 expected.add(expectedFS.build());
643 assertEquals(expected, FS_PARSER.extractFlowspec(entry.build()));
647 public void testExtractFlowspecSourceCodes() {
648 final DataContainerNodeAttrBuilder<NodeIdentifierWithPredicates, MapEntryNode> entry = Builders.mapEntryBuilder();
649 entry.withNodeIdentifier(new NodeIdentifierWithPredicates(FlowspecRoute.QNAME, FlowspecRoute.QNAME, entry));
650 entry.withChild(Builders.unkeyedListBuilder()
651 .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_NID)
652 .withChild(Builders.unkeyedListEntryBuilder()
653 .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_NID)
654 .withChild(Builders.choiceBuilder()
655 .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_TYPE_NID)
656 .withChild(Builders.unkeyedListBuilder().withNodeIdentifier(AbstractFlowspecNlriParser.ICMP_CODE_NID)
657 .withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(AbstractFlowspecNlriParser.OP_NID)
658 .withChild(Builders.leafBuilder().withNodeIdentifier(AbstractFlowspecNlriParser.OP_NID).withValue(Sets.<String>newHashSet()).build())
659 .withChild(Builders.leafBuilder().withNodeIdentifier(AbstractFlowspecNlriParser.VALUE_NID).withValue((short) 23).build()).build())
660 .build()).build()).build()).build());
661 final FlowspecBuilder expectedFS = new FlowspecBuilder();
662 expectedFS.setFlowspecType(new IcmpCodeCaseBuilder().setCodes(Lists.<Codes>newArrayList(new CodesBuilder().setValue((short) 23).setOp(new NumericOperand(false, false, false, false, false)).build())).build());
663 final List<Flowspec> expected = new ArrayList<>();
664 expected.add(expectedFS.build());
665 assertEquals(expected, FS_PARSER.extractFlowspec(entry.build()));
669 public void testExtractFlowspecSourceTcpFlags() {
670 final DataContainerNodeAttrBuilder<NodeIdentifierWithPredicates, MapEntryNode> entry = Builders.mapEntryBuilder();
671 entry.withNodeIdentifier(new NodeIdentifierWithPredicates(FlowspecRoute.QNAME, FlowspecRoute.QNAME, entry));
672 entry.withChild(Builders.unkeyedListBuilder()
673 .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_NID)
674 .withChild(Builders.unkeyedListEntryBuilder()
675 .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_NID)
676 .withChild(Builders.choiceBuilder()
677 .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_TYPE_NID)
678 .withChild(Builders.unkeyedListBuilder().withNodeIdentifier(AbstractFlowspecNlriParser.TCP_FLAGS_NID)
679 .withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(AbstractFlowspecNlriParser.OP_NID)
680 .withChild(Builders.leafBuilder().withNodeIdentifier(AbstractFlowspecNlriParser.OP_NID).withValue(Sets.<String>newHashSet(AbstractOperandParser.AND_BIT_VALUE, AbstractOperandParser.END_OF_LIST_VALUE)).build())
681 .withChild(Builders.leafBuilder().withNodeIdentifier(AbstractFlowspecNlriParser.VALUE_NID).withValue(99).build()).build())
682 .build()).build()).build()).build());
683 final FlowspecBuilder expectedFS = new FlowspecBuilder();
684 expectedFS.setFlowspecType(new TcpFlagsCaseBuilder().setTcpFlags(Lists.<TcpFlags>newArrayList(new TcpFlagsBuilder().setValue(99).setOp(new BitmaskOperand(true, true, false, false)).build())).build());
685 final List<Flowspec> expected = new ArrayList<>();
686 expected.add(expectedFS.build());
687 assertEquals(expected, FS_PARSER.extractFlowspec(entry.build()));
691 public void testExtractFlowspecPacketLengths() {
692 final DataContainerNodeAttrBuilder<NodeIdentifierWithPredicates, MapEntryNode> entry = Builders.mapEntryBuilder();
693 entry.withNodeIdentifier(new NodeIdentifierWithPredicates(FlowspecRoute.QNAME, FlowspecRoute.QNAME, entry));
694 entry.withChild(Builders.unkeyedListBuilder()
695 .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_NID)
696 .withChild(Builders.unkeyedListEntryBuilder()
697 .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_NID)
698 .withChild(Builders.choiceBuilder()
699 .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_TYPE_NID)
700 .withChild(Builders.unkeyedListBuilder().withNodeIdentifier(AbstractFlowspecNlriParser.PACKET_LENGTHS_NID)
701 .withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(AbstractFlowspecNlriParser.OP_NID)
702 .withChild(Builders.leafBuilder().withNodeIdentifier(AbstractFlowspecNlriParser.OP_NID).withValue(Sets.<String>newHashSet(AbstractOperandParser.AND_BIT_VALUE, AbstractNumericOperandParser.GREATER_THAN_VALUE)).build())
703 .withChild(Builders.leafBuilder().withNodeIdentifier(AbstractFlowspecNlriParser.VALUE_NID).withValue(101).build()).build())
704 .build()).build()).build()).build());
705 final FlowspecBuilder expectedFS = new FlowspecBuilder();
706 expectedFS.setFlowspecType(new PacketLengthCaseBuilder().setPacketLengths(Lists.<PacketLengths>newArrayList(new PacketLengthsBuilder().setValue(101).setOp(new NumericOperand(true, false, false, true, false)).build())).build());
707 final List<Flowspec> expected = new ArrayList<>();
708 expected.add(expectedFS.build());
709 assertEquals(expected, FS_PARSER.extractFlowspec(entry.build()));
713 public void testExtractFlowspecDscps() {
714 final DataContainerNodeAttrBuilder<NodeIdentifierWithPredicates, MapEntryNode> entry = Builders.mapEntryBuilder();
715 entry.withNodeIdentifier(new NodeIdentifierWithPredicates(FlowspecRoute.QNAME, FlowspecRoute.QNAME, entry));
716 entry.withChild(Builders.unkeyedListBuilder()
717 .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_NID)
718 .withChild(Builders.unkeyedListEntryBuilder()
719 .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_NID)
720 .withChild(Builders.choiceBuilder()
721 .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_TYPE_NID)
722 .withChild(Builders.unkeyedListBuilder().withNodeIdentifier(AbstractFlowspecNlriParser.DSCP_NID)
723 .withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(AbstractFlowspecNlriParser.OP_NID)
724 .withChild(Builders.leafBuilder().withNodeIdentifier(AbstractFlowspecNlriParser.OP_NID).withValue(Sets.<String>newHashSet(AbstractOperandParser.AND_BIT_VALUE, AbstractOperandParser.END_OF_LIST_VALUE, AbstractNumericOperandParser.GREATER_THAN_VALUE)).build())
725 .withChild(Builders.leafBuilder().withNodeIdentifier(AbstractFlowspecNlriParser.VALUE_NID).withValue((short) 15).build()).build())
726 .build()).build()).build()).build());
727 final FlowspecBuilder expectedFS = new FlowspecBuilder();
728 expectedFS.setFlowspecType(new DscpCaseBuilder().setDscps(Lists.<Dscps>newArrayList(new DscpsBuilder().setValue(new Dscp((short) 15)).setOp(new NumericOperand(true, true, false, true, false)).build())).build());
729 final List<Flowspec> expected = new ArrayList<>();
730 expected.add(expectedFS.build());
731 assertEquals(expected, FS_PARSER.extractFlowspec(entry.build()));
735 public void testExtractFlowspecFragments() {
736 final DataContainerNodeAttrBuilder<NodeIdentifierWithPredicates, MapEntryNode> entry = Builders.mapEntryBuilder();
737 entry.withNodeIdentifier(new NodeIdentifierWithPredicates(FlowspecRoute.QNAME, FlowspecRoute.QNAME, entry));
738 entry.withChild(Builders.unkeyedListBuilder()
739 .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_NID)
740 .withChild(Builders.unkeyedListEntryBuilder()
741 .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_NID)
742 .withChild(Builders.choiceBuilder()
743 .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_TYPE_NID)
744 .withChild(Builders.unkeyedListBuilder().withNodeIdentifier(AbstractFlowspecNlriParser.FRAGMENT_NID)
745 .withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(AbstractFlowspecNlriParser.OP_NID)
746 .withChild(Builders.leafBuilder().withNodeIdentifier(AbstractFlowspecNlriParser.OP_NID).withValue(Sets.<String>newHashSet(AbstractOperandParser.AND_BIT_VALUE, AbstractOperandParser.END_OF_LIST_VALUE, BitmaskOperandParser.MATCH_VALUE, BitmaskOperandParser.NOT_VALUE)).build())
747 .withChild(Builders.leafBuilder().withNodeIdentifier(AbstractFlowspecNlriParser.VALUE_NID).withValue(Sets.newHashSet(AbstractFlowspecNlriParser.DO_NOT_VALUE, AbstractFlowspecNlriParser.FIRST_VALUE, AbstractFlowspecNlriParser.IS_A_VALUE, AbstractFlowspecNlriParser.LAST_VALUE)).build()).build())
748 .build()).build()).build()).build());
749 final FlowspecBuilder expectedFS = new FlowspecBuilder();
750 expectedFS.setFlowspecType(new FragmentCaseBuilder().setFragments(Lists.<Fragments>newArrayList(new FragmentsBuilder().setValue(new Fragment(true, true, true, true)).setOp(new BitmaskOperand(true, true, true, true)).build())).build());
751 final List<Flowspec> expected = new ArrayList<>();
752 expected.add(expectedFS.build());
753 assertEquals(expected, FS_PARSER.extractFlowspec(entry.build()));