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.flowspec.l3vpn.ipv4.FlowspecL3vpnIpv4NlriParser;
29 import org.opendaylight.protocol.bgp.parser.BGPParsingException;
30 import org.opendaylight.protocol.bgp.parser.spi.MultiPathSupport;
31 import org.opendaylight.protocol.bgp.parser.spi.PeerSpecificParserConstraint;
32 import org.opendaylight.protocol.util.ByteArray;
33 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.BitmaskOperand;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.Dscp;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.FlowspecL3vpnSubsequentAddressFamily;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.Fragment;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.NumericOperand;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.Flowspec;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.FlowspecBuilder;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.FlowspecType;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.DestinationPortCaseBuilder;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.DscpCaseBuilder;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.FragmentCaseBuilder;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.IcmpCodeCaseBuilder;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.IcmpTypeCaseBuilder;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.PacketLengthCase;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.PacketLengthCaseBuilder;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.PortCase;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.PortCaseBuilder;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.SourcePortCaseBuilder;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.TcpFlagsCase;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.TcpFlagsCaseBuilder;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.destination.port._case.DestinationPorts;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.destination.port._case.DestinationPortsBuilder;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.dscp._case.Dscps;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.dscp._case.DscpsBuilder;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.fragment._case.Fragments;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.fragment._case.FragmentsBuilder;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.icmp.code._case.Codes;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.icmp.code._case.CodesBuilder;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.icmp.type._case.Types;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.icmp.type._case.TypesBuilder;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.packet.length._case.PacketLengths;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.packet.length._case.PacketLengthsBuilder;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.port._case.Ports;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.port._case.PortsBuilder;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.source.port._case.SourcePorts;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.source.port._case.SourcePortsBuilder;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.tcp.flags._case.TcpFlags;
71 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.tcp.flags._case.TcpFlagsBuilder;
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.group.ipv4.flowspec.flowspec.type.DestinationPrefixCase;
73 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.group.ipv4.flowspec.flowspec.type.DestinationPrefixCaseBuilder;
74 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.group.ipv4.flowspec.flowspec.type.ProtocolIpCaseBuilder;
75 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.group.ipv4.flowspec.flowspec.type.SourcePrefixCase;
76 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.group.ipv4.flowspec.flowspec.type.SourcePrefixCaseBuilder;
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.ProtocolIps;
78 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;
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.flowspec.rev150807.flowspec.l3vpn.destination.ipv4.DestinationFlowspecL3vpnIpv4;
81 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.l3vpn.destination.ipv4.DestinationFlowspecL3vpnIpv4Builder;
82 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.PathId;
83 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.AttributesBuilder;
84 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.Attributes1;
85 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.Attributes1Builder;
86 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.Attributes2;
87 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.Attributes2Builder;
88 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.MpReachNlriBuilder;
89 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.MpUnreachNlriBuilder;
90 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.mp.reach.nlri.AdvertizedRoutesBuilder;
91 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.mp.unreach.nlri.WithdrawnRoutesBuilder;
92 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv4AddressFamily;
93 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.RouteDistinguisher;
94 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.RouteDistinguisherBuilder;
95 import org.opendaylight.yangtools.yang.common.QName;
96 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
97 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
98 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
99 import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
100 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeAttrBuilder;
102 public class FlowspecL3vpnIpv4NlriParserTest {
104 private static final NodeIdentifier RD_NID = new NodeIdentifier(QName.create(Flowspec.QNAME.getNamespace(), Flowspec.QNAME.getRevision(), "route-distinguisher"));
105 private static final NodeIdentifier PROTOCOL_IP_NID = new NodeIdentifier(ProtocolIps.QNAME);
107 private static final String ROUTE_DISTINGUISHER = "1.2.3.4:10";
109 private static final PathId PATH_ID = new PathId(1L);
112 private PeerSpecificParserConstraint constraint;
114 private MultiPathSupport muliPathSupport;
116 private static final byte[] REACHED_NLRI = new byte[] {
117 0x29, // NLRI length: 8+33=41
118 0, 1, 1, 2, 3, 4, 0, 10, // route distinguisher: 1.2.3.4:10
119 0x01, 0x20, 0x0a, 0x00, 0x01, 0x00,
120 0x02, 0x20, 0x01, 0x02, 0x03, 0x04,
121 0x03, (byte) 0x81, 0x06,
122 0x04, 0x03, (byte) 0x89, 0x45, (byte) 0x8b, (byte) 0x91, 0x1f, (byte) 0x90,
123 0x05, 0x12, 0x0f, (byte) 0xf9, (byte) 0x81, (byte) 0xb3,
124 0x06, (byte) 0x91, 0x1f, (byte) 0x90
127 private static final byte[] REACHED_NLRI_ADD_PATH = new byte[] {
129 0x29, // NLRI length: 8+33=41
130 0, 1, 1, 2, 3, 4, 0, 10, // route distinguisher: 1.2.3.4:10
131 0x01, 0x20, 0x0a, 0x00, 0x01, 0x00,
132 0x02, 0x20, 0x01, 0x02, 0x03, 0x04,
133 0x03, (byte) 0x81, 0x06,
134 0x04, 0x03, (byte) 0x89, 0x45, (byte) 0x8b, (byte) 0x91, 0x1f, (byte) 0x90,
135 0x05, 0x12, 0x0f, (byte) 0xf9, (byte) 0x81, (byte) 0xb3,
136 0x06, (byte) 0x91, 0x1f, (byte) 0x90
139 private static final byte[] UNREACHED_NLRI = new byte[] {
140 0x23, // NLRI length: 8+33=41
141 0, 1, 1, 2, 3, 4, 0, 10, // route distinguisher: 1.2.3.4:10
142 0x07, 4, 2, (byte) 0x84, 3,
143 0x08, 4, 4, (byte) 0x80, 5,
144 0x09, 0x12, 4, 1, (byte) 0x91, 0x56, (byte) 0xb1,
145 0x0a, (byte) 0x94, (byte) 0xde, (byte) 0xad,
146 0x0b, (byte) 0x82, 0x2a,
147 0x0c, (byte) 0x81, (byte) 0x0e
150 private static final byte[] UNREACHED_NLRI_ADD_PATH = new byte[] {
152 0x23, // NLRI length: 8+27=35
153 0, 1, 1, 2, 3, 4, 0, 10, // route distinguisher: 1.2.3.4:10
154 0x07, 4, 2, (byte) 0x84, 3,
155 0x08, 4, 4, (byte) 0x80, 5,
156 0x09, 0x12, 4, 1, (byte) 0x91, 0x56, (byte) 0xb1,
157 0x0a, (byte) 0x94, (byte) 0xde, (byte) 0xad,
158 0x0b, (byte) 0x82, 0x2a,
159 0x0c, (byte) 0x81, (byte) 0x0e
162 private final SimpleFlowspecExtensionProviderContext flowspecContext = new SimpleFlowspecExtensionProviderContext();
163 private final FlowspecActivator fsa = new FlowspecActivator(flowspecContext);
164 private final FlowspecL3vpnIpv4NlriParser FS_PARSER = new FlowspecL3vpnIpv4NlriParser(flowspecContext.getFlowspecTypeRegistry(SimpleFlowspecExtensionProviderContext.AFI.IPV4, SimpleFlowspecExtensionProviderContext.SAFI.FLOWSPEC_VPN));
167 public void setUp() {
168 MockitoAnnotations.initMocks(this);
169 Mockito.doReturn(Optional.of(this.muliPathSupport)).when(constraint).getPeerConstraint(Mockito.any());
170 Mockito.doReturn(true).when(this.muliPathSupport).isTableTypeSupported(Mockito.any());
174 public void testParseMpReachNlri() throws BGPParsingException {
175 final List<Flowspec> fs = new ArrayList<>();
176 final MpReachNlriBuilder mp = new MpReachNlriBuilder();
178 final FlowspecBuilder builder = new FlowspecBuilder();
179 final DestinationPrefixCase destinationPrefix = new DestinationPrefixCaseBuilder().setDestinationPrefix(new Ipv4Prefix("10.0.1.0/32")).build();
180 builder.setFlowspecType(destinationPrefix);
181 fs.add(builder.build());
182 final SourcePrefixCase sourcePrefix = new SourcePrefixCaseBuilder().setSourcePrefix(new Ipv4Prefix("1.2.3.4/32")).build();
183 builder.setFlowspecType(sourcePrefix);
184 fs.add(builder.build());
186 final FlowspecType prots = createProts();
187 builder.setFlowspecType(prots);
188 fs.add(builder.build());
190 final PortCase ps = createPorts();
191 builder.setFlowspecType(ps);
192 fs.add(builder.build());
194 final FlowspecType dps = createDps();
195 builder.setFlowspecType(dps);
196 fs.add(builder.build());
198 final FlowspecType sps = createSps();
199 builder.setFlowspecType(sps);
200 fs.add(builder.build());
202 final FlowspecL3vpnIpv4NlriParser parser = new FlowspecL3vpnIpv4NlriParser(flowspecContext.getFlowspecTypeRegistry(SimpleFlowspecExtensionProviderContext.AFI.IPV4, SimpleFlowspecExtensionProviderContext.SAFI.FLOWSPEC_VPN));
204 final MpReachNlriBuilder result = new MpReachNlriBuilder();
205 result.setAfi(Ipv4AddressFamily.class);
206 result.setSafi(FlowspecL3vpnSubsequentAddressFamily.class);
207 parser.parseNlri(Unpooled.wrappedBuffer(REACHED_NLRI), result);
209 final DestinationFlowspecL3vpnIpv4 flowspecDst = ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationFlowspecL3vpnIpv4Case) (result.getAdvertizedRoutes().getDestinationType()))
210 .getDestinationFlowspecL3vpnIpv4();
211 final List<Flowspec> flows = flowspecDst.getFlowspec();
212 final RouteDistinguisher rd = flowspecDst.getRouteDistinguisher();
214 testFlows(flows, destinationPrefix, sourcePrefix, prots, rd, ps, dps, sps);
216 mp.setAdvertizedRoutes(
217 new AdvertizedRoutesBuilder().setDestinationType(
218 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationFlowspecL3vpnIpv4CaseBuilder()
219 .setDestinationFlowspecL3vpnIpv4(
220 new DestinationFlowspecL3vpnIpv4Builder()
221 .setRouteDistinguisher(rd)
228 final ByteBuf buffer = Unpooled.buffer();
229 parser.serializeAttribute(new AttributesBuilder().addAugmentation(Attributes1.class, new Attributes1Builder().setMpReachNlri(mp.setAfi(Ipv4AddressFamily.class).build()).build()).build(), buffer);
230 assertArrayEquals(REACHED_NLRI, ByteArray.readAllBytes(buffer));
232 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));
235 private void testFlows(
236 final List<Flowspec> flows,
237 final DestinationPrefixCase destinationPrefix,
238 final SourcePrefixCase sourcePrefix,
239 final FlowspecType prots,
240 final RouteDistinguisher rd,
242 final FlowspecType dps,
243 final FlowspecType sps
245 assertEquals(6, flows.size());
246 assertEquals(ROUTE_DISTINGUISHER, new String(rd.getValue()));
247 assertEquals(destinationPrefix, flows.get(0).getFlowspecType());
248 assertEquals(sourcePrefix, flows.get(1).getFlowspecType());
249 assertEquals(prots, flows.get(2).getFlowspecType());
250 assertEquals(ps, flows.get(3).getFlowspecType());
251 assertEquals(dps, flows.get(4).getFlowspecType());
252 assertEquals(sps, flows.get(5).getFlowspecType());
255 private FlowspecType createSps() {
256 final List<SourcePorts> sports = Lists.newArrayList(new SourcePortsBuilder().setOp(new NumericOperand(false, true, true, false, false)).setValue(8080).build());
257 return new SourcePortCaseBuilder().setSourcePorts(sports).build();
260 private FlowspecType createProts() {
261 final List<ProtocolIps> protocols = Lists.newArrayList(new ProtocolIpsBuilder().setOp(new NumericOperand(false, true, true, false, false)).setValue((short) 6).build());
262 return new ProtocolIpCaseBuilder().setProtocolIps(protocols).build();
265 private FlowspecType createDps() {
266 final List<DestinationPorts> destports = Lists.newArrayList(new DestinationPortsBuilder().setOp(new NumericOperand(false, false, false, true, false)).setValue(4089).build(),
267 new DestinationPortsBuilder().setOp(new NumericOperand(false, true, true, false, false)).setValue(179).build());
268 return new DestinationPortCaseBuilder().setDestinationPorts(destports).build();
272 public void testParseMpReachNlriConstraint() throws BGPParsingException {
273 final List<Flowspec> fs = new ArrayList<>();
274 final MpReachNlriBuilder mp = new MpReachNlriBuilder();
276 final FlowspecBuilder builder = new FlowspecBuilder();
277 final DestinationPrefixCase destinationPrefix = new DestinationPrefixCaseBuilder().setDestinationPrefix(new Ipv4Prefix("10.0.1.0/32")).build();
278 builder.setFlowspecType(destinationPrefix);
279 fs.add(builder.build());
280 final SourcePrefixCase sourcePrefix = new SourcePrefixCaseBuilder().setSourcePrefix(new Ipv4Prefix("1.2.3.4/32")).build();
281 builder.setFlowspecType(sourcePrefix);
282 fs.add(builder.build());
284 final FlowspecType prots = createProts();
285 builder.setFlowspecType(prots);
286 fs.add(builder.build());
288 final PortCase ps = createPorts();
289 builder.setFlowspecType(ps);
290 fs.add(builder.build());
292 final FlowspecType dps = createDps();
293 builder.setFlowspecType(dps);
294 fs.add(builder.build());
296 final FlowspecType sps = createSps();
297 builder.setFlowspecType(sps);
298 fs.add(builder.build());
300 final FlowspecL3vpnIpv4NlriParser parser = new FlowspecL3vpnIpv4NlriParser(flowspecContext.getFlowspecTypeRegistry(SimpleFlowspecExtensionProviderContext.AFI.IPV4, SimpleFlowspecExtensionProviderContext.SAFI.FLOWSPEC_VPN));
302 final MpReachNlriBuilder result = new MpReachNlriBuilder();
303 result.setAfi(Ipv4AddressFamily.class);
304 result.setSafi(FlowspecL3vpnSubsequentAddressFamily.class);
305 parser.parseNlri(Unpooled.wrappedBuffer(REACHED_NLRI_ADD_PATH), result, this.constraint);
307 final DestinationFlowspecL3vpnIpv4 flowspecDst = ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationFlowspecL3vpnIpv4Case) (result.getAdvertizedRoutes().getDestinationType()))
308 .getDestinationFlowspecL3vpnIpv4();
309 final List<Flowspec> flows = flowspecDst.getFlowspec();
310 final RouteDistinguisher rd = flowspecDst.getRouteDistinguisher();
312 testFlows(flows, destinationPrefix, sourcePrefix, prots, rd, ps, dps, sps);
314 mp.setAdvertizedRoutes(
315 new AdvertizedRoutesBuilder().setDestinationType(
316 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationFlowspecL3vpnIpv4CaseBuilder()
317 .setDestinationFlowspecL3vpnIpv4(
318 new DestinationFlowspecL3vpnIpv4Builder()
319 .setRouteDistinguisher(rd)
327 final ByteBuf buffer = Unpooled.buffer();
328 parser.serializeAttribute(new AttributesBuilder().addAugmentation(Attributes1.class, new Attributes1Builder().setMpReachNlri(mp.setAfi(Ipv4AddressFamily.class).build()).build()).build(), buffer);
329 assertArrayEquals(REACHED_NLRI_ADD_PATH, ByteArray.readAllBytes(buffer));
331 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));
334 private PortCase createPorts() {
335 final List<Ports> ports = Lists.newArrayList(new PortsBuilder().setOp(new NumericOperand(false, false, true, true, false)).setValue(137).build(),
336 new PortsBuilder().setOp(new NumericOperand(true, false, true, false, true)).setValue(139).build(),
337 new PortsBuilder().setOp(new NumericOperand(false, true, true, false, false)).setValue(8080).build());
339 return new PortCaseBuilder().setPorts(ports).build();
343 public void testParseMpUnreachNlri() throws BGPParsingException {
344 final List<Flowspec> fs = new ArrayList<>();
345 final MpUnreachNlriBuilder mp = new MpUnreachNlriBuilder();
347 final FlowspecBuilder builder = new FlowspecBuilder();
349 final FlowspecType icmpType = createIcmpType();
350 builder.setFlowspecType(icmpType);
351 fs.add(builder.build());
353 final FlowspecType icmpCode = createIcmpCode();
354 builder.setFlowspecType(icmpCode);
355 fs.add(builder.build());
357 final TcpFlagsCase tcp = createTcp();
358 builder.setFlowspecType(tcp);
359 fs.add(builder.build());
361 final PacketLengthCase packet = createPackets();
362 builder.setFlowspecType(packet);
363 fs.add(builder.build());
365 final FlowspecType dscp = createDscp();
366 builder.setFlowspecType(dscp);
367 fs.add(builder.build());
369 final FlowspecType fragment = createFragment();
370 builder.setFlowspecType(fragment);
371 fs.add(builder.build());
373 final FlowspecL3vpnIpv4NlriParser parser = new FlowspecL3vpnIpv4NlriParser(flowspecContext.getFlowspecTypeRegistry(SimpleFlowspecExtensionProviderContext.AFI.IPV4, SimpleFlowspecExtensionProviderContext.SAFI.FLOWSPEC_VPN));
375 final MpUnreachNlriBuilder result = new MpUnreachNlriBuilder();
376 result.setAfi(Ipv4AddressFamily.class);
377 result.setSafi(FlowspecL3vpnSubsequentAddressFamily.class);
378 parser.parseNlri(Unpooled.wrappedBuffer(UNREACHED_NLRI), result);
380 DestinationFlowspecL3vpnIpv4 flowspecDst = ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationFlowspecL3vpnIpv4Case) (result.getWithdrawnRoutes().getDestinationType()))
381 .getDestinationFlowspecL3vpnIpv4();
382 final List<Flowspec> flows = flowspecDst.getFlowspec();
383 checkUnreachFlows(flows, icmpType, icmpCode, tcp, packet, dscp, fragment);
385 final RouteDistinguisher rd = flowspecDst.getRouteDistinguisher();
387 mp.setAfi(Ipv4AddressFamily.class).setWithdrawnRoutes(new WithdrawnRoutesBuilder().setDestinationType(
388 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationFlowspecL3vpnIpv4CaseBuilder()
389 .setDestinationFlowspecL3vpnIpv4(
390 new DestinationFlowspecL3vpnIpv4Builder()
391 .setRouteDistinguisher(rd)
398 final ByteBuf buffer = Unpooled.buffer();
399 parser.serializeNlri(new Object[] {rd, flows}, null, buffer);
400 assertArrayEquals(UNREACHED_NLRI, ByteArray.readAllBytes(buffer));
402 parser.serializeAttribute(new AttributesBuilder().addAugmentation(Attributes2.class, new Attributes2Builder().setMpUnreachNlri(mp.build()).build()).build(), buffer);
403 assertArrayEquals(UNREACHED_NLRI, ByteArray.readAllBytes(buffer));
405 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));
409 private FlowspecType createFragment() {
410 final List<Fragments> fragments = Lists.newArrayList(new FragmentsBuilder().setOp(new BitmaskOperand(false, true, true, false)).setValue(new Fragment(false, true, true, true)).build());
411 return new FragmentCaseBuilder().setFragments(fragments).build();
414 private FlowspecType createDscp() {
415 final List<Dscps> dscps = Lists.newArrayList(new DscpsBuilder().setOp(new NumericOperand(false, true, false, true, false)).setValue(new Dscp((short) 42)).build());
416 return new DscpCaseBuilder().setDscps(dscps).build();
419 private PacketLengthCase createPackets() {
420 final List<PacketLengths> packets = Lists.newArrayList(new PacketLengthsBuilder().setOp(new NumericOperand(false, true, false, false, true))
421 .setValue(57005).build());
422 return new PacketLengthCaseBuilder().setPacketLengths(packets).build();
425 private TcpFlagsCase createTcp() {
426 final List<TcpFlags> flags = Lists.newArrayList(new TcpFlagsBuilder().setOp(new BitmaskOperand(false, false, false, true)).setValue(1025).build(),
427 new TcpFlagsBuilder().setOp(new BitmaskOperand(false, true, true, false)).setValue(22193).build());
428 return new TcpFlagsCaseBuilder().setTcpFlags(flags).build();
431 private FlowspecType createIcmpCode() {
432 final List<Codes> codes = Lists.newArrayList(new CodesBuilder().setOp(new NumericOperand(false, false, false, false, true)).setValue((short) 4).build(),
433 new CodesBuilder().setOp(new NumericOperand(false, true, false, false, false)).setValue((short) 5).build());
434 return new IcmpCodeCaseBuilder().setCodes(codes).build();
437 private FlowspecType createIcmpType() {
438 final List<Types> types = Lists.newArrayList(new TypesBuilder().setOp(new NumericOperand(false, false, false, false, true)).setValue((short) 2).build(),
439 new TypesBuilder().setOp(new NumericOperand(false, true, false, false, true)).setValue((short) 3).build());
440 return new IcmpTypeCaseBuilder().setTypes(types).build();
443 private void checkUnreachFlows(final List<Flowspec> flows, final FlowspecType icmpType, final FlowspecType icmpCode, final TcpFlagsCase tcp,
444 final PacketLengthCase packet, final FlowspecType dscp, final FlowspecType fragment) {
445 assertEquals(6, flows.size());
446 assertEquals(icmpType, flows.get(0).getFlowspecType());
447 assertEquals(icmpCode, flows.get(1).getFlowspecType());
448 assertEquals(tcp, flows.get(2).getFlowspecType());
449 assertEquals(packet, flows.get(3).getFlowspecType());
450 assertEquals(dscp, flows.get(4).getFlowspecType());
451 assertEquals(fragment, flows.get(5).getFlowspecType());
455 public void testParseMpUnreachNlriConstraint() throws BGPParsingException {
456 final List<Flowspec> fs = new ArrayList<>();
457 final MpUnreachNlriBuilder mp = new MpUnreachNlriBuilder();
459 final FlowspecBuilder builder = new FlowspecBuilder();
461 final FlowspecType icmpType = createIcmpType();
462 builder.setFlowspecType(icmpType);
463 fs.add(builder.build());
465 final FlowspecType icmpCode = createIcmpCode();
466 builder.setFlowspecType(icmpCode);
467 fs.add(builder.build());
469 final TcpFlagsCase tcp = createTcp();
470 builder.setFlowspecType(tcp);
471 fs.add(builder.build());
473 final PacketLengthCase packet = createPackets();
474 builder.setFlowspecType(packet);
475 fs.add(builder.build());
477 final FlowspecType dscp = createDscp();
478 builder.setFlowspecType(dscp);
479 fs.add(builder.build());
481 final FlowspecType fragment = createFragment();
482 builder.setFlowspecType(fragment);
483 fs.add(builder.build());
485 final FlowspecL3vpnIpv4NlriParser parser = new FlowspecL3vpnIpv4NlriParser(flowspecContext.getFlowspecTypeRegistry(SimpleFlowspecExtensionProviderContext.AFI.IPV4, SimpleFlowspecExtensionProviderContext.SAFI.FLOWSPEC_VPN));
487 final MpUnreachNlriBuilder result = new MpUnreachNlriBuilder();
488 result.setAfi(Ipv4AddressFamily.class);
489 result.setSafi(FlowspecL3vpnSubsequentAddressFamily.class);
490 parser.parseNlri(Unpooled.wrappedBuffer(UNREACHED_NLRI_ADD_PATH), result, this.constraint);
492 DestinationFlowspecL3vpnIpv4 flowspecDst = ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationFlowspecL3vpnIpv4Case) (result.getWithdrawnRoutes().getDestinationType()))
493 .getDestinationFlowspecL3vpnIpv4();
494 final List<Flowspec> flows = flowspecDst.getFlowspec();
495 checkUnreachFlows(flows, icmpType, icmpCode, tcp, packet, dscp, fragment);
497 final RouteDistinguisher rd = flowspecDst.getRouteDistinguisher();
499 mp.setAfi(Ipv4AddressFamily.class).setWithdrawnRoutes(new WithdrawnRoutesBuilder().setDestinationType(
500 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationFlowspecL3vpnIpv4CaseBuilder()
501 .setDestinationFlowspecL3vpnIpv4(
502 new DestinationFlowspecL3vpnIpv4Builder()
503 .setRouteDistinguisher(rd)
511 final ByteBuf buffer = Unpooled.buffer();
512 parser.serializeNlri(new Object[] {rd, flows}, PATH_ID, buffer);
513 assertArrayEquals(UNREACHED_NLRI_ADD_PATH, ByteArray.readAllBytes(buffer));
515 parser.serializeAttribute(new AttributesBuilder().addAugmentation(Attributes2.class, new Attributes2Builder().setMpUnreachNlri(mp.build()).build()).build(), buffer);
516 assertArrayEquals(UNREACHED_NLRI_ADD_PATH, ByteArray.readAllBytes(buffer));
518 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));
523 public void testExtractFlowspecDestPrefix() {
524 final DataContainerNodeAttrBuilder<NodeIdentifierWithPredicates, MapEntryNode> entry = Builders.mapEntryBuilder();
525 entry.withNodeIdentifier(new NodeIdentifierWithPredicates(FlowspecRoute.QNAME, FlowspecRoute.QNAME, entry));
526 entry.withChild(Builders.unkeyedListBuilder()
527 .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_NID)
528 .withChild(Builders.unkeyedListEntryBuilder()
529 .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_NID)
530 .withChild(Builders.choiceBuilder()
531 .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_TYPE_NID)
532 .withChild(Builders.leafBuilder().withNodeIdentifier(AbstractFlowspecNlriParser.DEST_PREFIX_NID).withValue("127.0.0.5/32").build()).build()).build()).build());
534 final FlowspecBuilder expectedFS = new FlowspecBuilder();
535 expectedFS.setFlowspecType(new DestinationPrefixCaseBuilder().setDestinationPrefix(new Ipv4Prefix("127.0.0.5/32")).build());
536 final List<Flowspec> expected = new ArrayList<>();
537 expected.add(expectedFS.build());
538 assertEquals(expected, FS_PARSER.extractFlowspec(entry.build()));
542 public void testExtractFlowspecSourcePrefix() {
543 final DataContainerNodeAttrBuilder<NodeIdentifierWithPredicates, MapEntryNode> entry = Builders.mapEntryBuilder();
544 entry.withNodeIdentifier(new NodeIdentifierWithPredicates(FlowspecRoute.QNAME, FlowspecRoute.QNAME, entry));
545 entry.withChild(Builders.unkeyedListBuilder()
546 .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_NID)
547 .withChild(Builders.unkeyedListEntryBuilder()
548 .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_NID)
549 .withChild(Builders.choiceBuilder()
550 .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_TYPE_NID)
551 .withChild(Builders.leafBuilder().withNodeIdentifier(AbstractFlowspecNlriParser.SOURCE_PREFIX_NID).withValue("127.0.0.6/32").build()).build()).build()).build());
553 final FlowspecBuilder expectedFS = new FlowspecBuilder();
554 expectedFS.setFlowspecType(new SourcePrefixCaseBuilder().setSourcePrefix(new Ipv4Prefix("127.0.0.6/32")).build());
555 final List<Flowspec> expected = new ArrayList<>();
556 expected.add(expectedFS.build());
557 assertEquals(expected, FS_PARSER.extractFlowspec(entry.build()));
561 public void testExtractFlowspecProtocolIps() {
562 final DataContainerNodeAttrBuilder<NodeIdentifierWithPredicates, MapEntryNode> entry = Builders.mapEntryBuilder();
563 entry.withNodeIdentifier(new NodeIdentifierWithPredicates(FlowspecRoute.QNAME, FlowspecRoute.QNAME, entry));
564 entry.withChild(Builders.unkeyedListBuilder()
565 .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_NID)
566 .withChild(Builders.unkeyedListEntryBuilder()
567 .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_NID)
568 .withChild(Builders.choiceBuilder()
569 .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_TYPE_NID)
570 .withChild(Builders.unkeyedListBuilder().withNodeIdentifier(PROTOCOL_IP_NID)
571 .withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(PROTOCOL_IP_NID)
572 .withChild(Builders.leafBuilder().withNodeIdentifier(FlowspecL3vpnIpv4NlriParser.OP_NID).withValue(Sets.newHashSet(AbstractOperandParser.END_OF_LIST_VALUE, AbstractOperandParser.AND_BIT_VALUE)).build())
573 .withChild(Builders.leafBuilder().withNodeIdentifier(FlowspecL3vpnIpv4NlriParser.VALUE_NID).withValue((short) 100).build()).build())
574 .withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(PROTOCOL_IP_NID)
575 .withChild(Builders.leafBuilder().withNodeIdentifier(FlowspecL3vpnIpv4NlriParser.OP_NID).withValue(Sets.newHashSet(AbstractOperandParser.AND_BIT_VALUE)).build())
576 .withChild(Builders.leafBuilder().withNodeIdentifier(FlowspecL3vpnIpv4NlriParser.VALUE_NID).withValue((short) 200).build()).build())
577 .withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(PROTOCOL_IP_NID)
578 .withChild(Builders.leafBuilder().withNodeIdentifier(FlowspecL3vpnIpv4NlriParser.OP_NID).withValue(Sets.newHashSet(AbstractOperandParser.END_OF_LIST_VALUE, AbstractOperandParser.AND_BIT_VALUE, AbstractNumericOperandParser.EQUALS_VALUE)).build())
579 .withChild(Builders.leafBuilder().withNodeIdentifier(FlowspecL3vpnIpv4NlriParser.VALUE_NID).withValue((short) 240).build()).build())
580 .build()).build()).build()).build());
582 final FlowspecBuilder expectedFS = new FlowspecBuilder();
583 expectedFS.setFlowspecType(new ProtocolIpCaseBuilder().setProtocolIps(Lists.newArrayList(
584 new ProtocolIpsBuilder().setValue((short) 100).setOp(new NumericOperand(true, true, false, false, false)).build(),
585 new ProtocolIpsBuilder().setValue((short) 200).setOp(new NumericOperand(true, false, false, false, false)).build(),
586 new ProtocolIpsBuilder().setValue((short) 240).setOp(new NumericOperand(true, true, true, false, false)).build())).build());
587 final List<Flowspec> expected = new ArrayList<>();
588 expected.add(expectedFS.build());
589 assertEquals(expected, FS_PARSER.extractFlowspec(entry.build()));
593 public void testExtractFlowspecPorts() {
594 final DataContainerNodeAttrBuilder<NodeIdentifierWithPredicates, MapEntryNode> entry = Builders.mapEntryBuilder();
595 entry.withNodeIdentifier(new NodeIdentifierWithPredicates(FlowspecRoute.QNAME, FlowspecRoute.QNAME, entry));
596 entry.withChild(Builders.unkeyedListBuilder()
597 .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_NID)
598 .withChild(Builders.unkeyedListEntryBuilder()
599 .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_NID)
600 .withChild(Builders.choiceBuilder()
601 .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_TYPE_NID)
602 .withChild(Builders.unkeyedListBuilder().withNodeIdentifier(AbstractFlowspecNlriParser.PORTS_NID)
603 .withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(PROTOCOL_IP_NID)
604 .withChild(Builders.leafBuilder().withNodeIdentifier(FlowspecL3vpnIpv4NlriParser.OP_NID).withValue(Sets.newHashSet(AbstractOperandParser.END_OF_LIST_VALUE, AbstractOperandParser.AND_BIT_VALUE, AbstractNumericOperandParser.LESS_THAN_VALUE)).build())
605 .withChild(Builders.leafBuilder().withNodeIdentifier(FlowspecL3vpnIpv4NlriParser.VALUE_NID).withValue(100).build()).build())
606 .build()).build()).build()).build());
608 final FlowspecBuilder expectedFS = new FlowspecBuilder();
609 expectedFS.setFlowspecType(new PortCaseBuilder().setPorts(Lists.newArrayList(new PortsBuilder().setValue(100).setOp(new NumericOperand(true, true, false, false, true)).build())).build());
610 final List<Flowspec> expected = new ArrayList<>();
611 expected.add(expectedFS.build());
612 assertEquals(expected, FS_PARSER.extractFlowspec(entry.build()));
616 public void testExtractFlowspecDestinationPorts() {
617 final DataContainerNodeAttrBuilder<NodeIdentifierWithPredicates, MapEntryNode> entry = Builders.mapEntryBuilder();
618 entry.withNodeIdentifier(new NodeIdentifierWithPredicates(FlowspecRoute.QNAME, FlowspecRoute.QNAME, entry));
619 entry.withChild(Builders.unkeyedListBuilder()
620 .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_NID)
621 .withChild(Builders.unkeyedListEntryBuilder()
622 .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_NID)
623 .withChild(Builders.choiceBuilder()
624 .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_TYPE_NID)
625 .withChild(Builders.unkeyedListBuilder().withNodeIdentifier(AbstractFlowspecNlriParser.DEST_PORT_NID)
626 .withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(AbstractFlowspecNlriParser.OP_NID)
627 .withChild(Builders.leafBuilder().withNodeIdentifier(AbstractFlowspecNlriParser.OP_NID).withValue(Sets.newHashSet(AbstractOperandParser.END_OF_LIST_VALUE, AbstractNumericOperandParser.EQUALS_VALUE)).build())
628 .withChild(Builders.leafBuilder().withNodeIdentifier(AbstractFlowspecNlriParser.VALUE_NID).withValue(1024).build()).build())
629 .build()).build()).build()).build());
630 final FlowspecBuilder expectedFS = new FlowspecBuilder();
631 expectedFS.setFlowspecType(new DestinationPortCaseBuilder().setDestinationPorts(Lists.newArrayList(new DestinationPortsBuilder().setValue(1024).setOp(new NumericOperand(false, true, true, false, false)).build())).build());
632 final List<Flowspec> expected = new ArrayList<>();
633 expected.add(expectedFS.build());
634 assertEquals(expected, FS_PARSER.extractFlowspec(entry.build()));
638 public void testExtractFlowspecSourcePorts() {
639 final DataContainerNodeAttrBuilder<NodeIdentifierWithPredicates, MapEntryNode> entry = Builders.mapEntryBuilder();
640 entry.withNodeIdentifier(new NodeIdentifierWithPredicates(FlowspecRoute.QNAME, FlowspecRoute.QNAME, entry));
641 entry.withChild(Builders.unkeyedListBuilder()
642 .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_NID)
643 .withChild(Builders.unkeyedListEntryBuilder()
644 .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_NID)
645 .withChild(Builders.choiceBuilder()
646 .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_TYPE_NID)
647 .withChild(Builders.unkeyedListBuilder().withNodeIdentifier(AbstractFlowspecNlriParser.SOURCE_PORT_NID)
648 .withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(FlowspecL3vpnIpv4NlriParser.OP_NID)
649 .withChild(Builders.leafBuilder().withNodeIdentifier(FlowspecL3vpnIpv4NlriParser.OP_NID).withValue(Sets.newHashSet(AbstractOperandParser.AND_BIT_VALUE, AbstractOperandParser.END_OF_LIST_VALUE, AbstractNumericOperandParser.EQUALS_VALUE, AbstractNumericOperandParser.GREATER_THAN_VALUE, AbstractNumericOperandParser.LESS_THAN_VALUE)).build())
650 .withChild(Builders.leafBuilder().withNodeIdentifier(FlowspecL3vpnIpv4NlriParser.VALUE_NID).withValue(8080).build()).build())
651 .build()).build()).build()).build());
652 final FlowspecBuilder expectedFS = new FlowspecBuilder();
653 expectedFS.setFlowspecType(new SourcePortCaseBuilder().setSourcePorts(Lists.newArrayList(new SourcePortsBuilder().setValue(8080).setOp(new NumericOperand(true, true, true, true, true)).build())).build());
654 final List<Flowspec> expected = new ArrayList<>();
655 expected.add(expectedFS.build());
656 assertEquals(expected, FS_PARSER.extractFlowspec(entry.build()));
660 public void testExtractFlowspecSourceTypes() {
661 final DataContainerNodeAttrBuilder<NodeIdentifierWithPredicates, MapEntryNode> entry = Builders.mapEntryBuilder();
662 entry.withNodeIdentifier(new NodeIdentifierWithPredicates(FlowspecRoute.QNAME, FlowspecRoute.QNAME, entry));
663 entry.withChild(Builders.unkeyedListBuilder()
664 .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_NID)
665 .withChild(Builders.unkeyedListEntryBuilder()
666 .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_NID)
667 .withChild(Builders.choiceBuilder()
668 .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_TYPE_NID)
669 .withChild(Builders.unkeyedListBuilder().withNodeIdentifier(AbstractFlowspecNlriParser.ICMP_TYPE_NID)
670 .withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(FlowspecL3vpnIpv4NlriParser.OP_NID)
671 .withChild(Builders.leafBuilder().withNodeIdentifier(FlowspecL3vpnIpv4NlriParser.OP_NID).withValue(Sets.newHashSet(AbstractOperandParser.AND_BIT_VALUE, AbstractOperandParser.END_OF_LIST_VALUE, AbstractNumericOperandParser.EQUALS_VALUE, AbstractNumericOperandParser.GREATER_THAN_VALUE, AbstractNumericOperandParser.LESS_THAN_VALUE)).build())
672 .withChild(Builders.leafBuilder().withNodeIdentifier(FlowspecL3vpnIpv4NlriParser.VALUE_NID).withValue((short) 22).build()).build())
673 .build()).build()).build()).build());
674 final FlowspecBuilder expectedFS = new FlowspecBuilder();
675 expectedFS.setFlowspecType(new IcmpTypeCaseBuilder().setTypes(Lists.newArrayList(new TypesBuilder().setValue((short) 22).setOp(new NumericOperand(true, true, true, true, true)).build())).build());
676 final List<Flowspec> expected = new ArrayList<>();
677 expected.add(expectedFS.build());
678 assertEquals(expected, FS_PARSER.extractFlowspec(entry.build()));
682 public void testExtractFlowspecSourceCodes() {
683 final DataContainerNodeAttrBuilder<NodeIdentifierWithPredicates, MapEntryNode> entry = Builders.mapEntryBuilder();
684 entry.withNodeIdentifier(new NodeIdentifierWithPredicates(FlowspecRoute.QNAME, FlowspecRoute.QNAME, entry));
685 entry.withChild(Builders.unkeyedListBuilder()
686 .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_NID)
687 .withChild(Builders.unkeyedListEntryBuilder()
688 .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_NID)
689 .withChild(Builders.choiceBuilder()
690 .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_TYPE_NID)
691 .withChild(Builders.unkeyedListBuilder().withNodeIdentifier(AbstractFlowspecNlriParser.ICMP_CODE_NID)
692 .withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(FlowspecL3vpnIpv4NlriParser.OP_NID)
693 .withChild(Builders.leafBuilder().withNodeIdentifier(FlowspecL3vpnIpv4NlriParser.OP_NID).withValue(Sets.newHashSet()).build())
694 .withChild(Builders.leafBuilder().withNodeIdentifier(FlowspecL3vpnIpv4NlriParser.VALUE_NID).withValue((short) 23).build()).build())
695 .build()).build()).build()).build());
696 final FlowspecBuilder expectedFS = new FlowspecBuilder();
697 expectedFS.setFlowspecType(new IcmpCodeCaseBuilder().setCodes(Lists.newArrayList(new CodesBuilder().setValue((short) 23).setOp(new NumericOperand(false, false, false, false, false)).build())).build());
698 final List<Flowspec> expected = new ArrayList<>();
699 expected.add(expectedFS.build());
700 assertEquals(expected, FS_PARSER.extractFlowspec(entry.build()));
704 public void testExtractFlowspecSourceTcpFlags() {
705 final DataContainerNodeAttrBuilder<NodeIdentifierWithPredicates, MapEntryNode> entry = Builders.mapEntryBuilder();
706 entry.withNodeIdentifier(new NodeIdentifierWithPredicates(FlowspecRoute.QNAME, FlowspecRoute.QNAME, entry));
707 entry.withChild(Builders.unkeyedListBuilder()
708 .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_NID)
709 .withChild(Builders.unkeyedListEntryBuilder()
710 .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_NID)
711 .withChild(Builders.choiceBuilder()
712 .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_TYPE_NID)
713 .withChild(Builders.unkeyedListBuilder().withNodeIdentifier(AbstractFlowspecNlriParser.TCP_FLAGS_NID)
714 .withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(FlowspecL3vpnIpv4NlriParser.OP_NID)
715 .withChild(Builders.leafBuilder().withNodeIdentifier(FlowspecL3vpnIpv4NlriParser.OP_NID).withValue(Sets.newHashSet(AbstractOperandParser.AND_BIT_VALUE, AbstractOperandParser.END_OF_LIST_VALUE)).build())
716 .withChild(Builders.leafBuilder().withNodeIdentifier(FlowspecL3vpnIpv4NlriParser.VALUE_NID).withValue(99).build()).build())
717 .build()).build()).build()).build());
718 final FlowspecBuilder expectedFS = new FlowspecBuilder();
719 expectedFS.setFlowspecType(new TcpFlagsCaseBuilder().setTcpFlags(Lists.newArrayList(new TcpFlagsBuilder().setValue(99).setOp(new BitmaskOperand(true, true, false, false)).build())).build());
720 final List<Flowspec> expected = new ArrayList<>();
721 expected.add(expectedFS.build());
722 assertEquals(expected, FS_PARSER.extractFlowspec(entry.build()));
726 public void testExtractFlowspecPacketLengths() {
727 final DataContainerNodeAttrBuilder<NodeIdentifierWithPredicates, MapEntryNode> entry = Builders.mapEntryBuilder();
728 entry.withNodeIdentifier(new NodeIdentifierWithPredicates(FlowspecRoute.QNAME, FlowspecRoute.QNAME, entry));
729 entry.withChild(Builders.unkeyedListBuilder()
730 .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_NID)
731 .withChild(Builders.unkeyedListEntryBuilder()
732 .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_NID)
733 .withChild(Builders.choiceBuilder()
734 .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_TYPE_NID)
735 .withChild(Builders.unkeyedListBuilder().withNodeIdentifier(AbstractFlowspecNlriParser.PACKET_LENGTHS_NID)
736 .withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(FlowspecL3vpnIpv4NlriParser.OP_NID)
737 .withChild(Builders.leafBuilder().withNodeIdentifier(FlowspecL3vpnIpv4NlriParser.OP_NID).withValue(Sets.newHashSet(AbstractOperandParser.AND_BIT_VALUE, AbstractNumericOperandParser.GREATER_THAN_VALUE)).build())
738 .withChild(Builders.leafBuilder().withNodeIdentifier(FlowspecL3vpnIpv4NlriParser.VALUE_NID).withValue(101).build()).build())
739 .build()).build()).build()).build());
740 final FlowspecBuilder expectedFS = new FlowspecBuilder();
741 expectedFS.setFlowspecType(new PacketLengthCaseBuilder().setPacketLengths(Lists.newArrayList(new PacketLengthsBuilder().setValue(101).setOp(new NumericOperand(true, false, false, true, false)).build())).build());
742 final List<Flowspec> expected = new ArrayList<>();
743 expected.add(expectedFS.build());
744 assertEquals(expected, FS_PARSER.extractFlowspec(entry.build()));
748 public void testExtractFlowspecDscps() {
749 final DataContainerNodeAttrBuilder<NodeIdentifierWithPredicates, MapEntryNode> entry = Builders.mapEntryBuilder();
750 entry.withNodeIdentifier(new NodeIdentifierWithPredicates(FlowspecRoute.QNAME, FlowspecRoute.QNAME, entry));
751 entry.withChild(Builders.unkeyedListBuilder()
752 .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_NID)
753 .withChild(Builders.unkeyedListEntryBuilder()
754 .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_NID)
755 .withChild(Builders.choiceBuilder()
756 .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_TYPE_NID)
757 .withChild(Builders.unkeyedListBuilder().withNodeIdentifier(AbstractFlowspecNlriParser.DSCP_NID)
758 .withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(FlowspecL3vpnIpv4NlriParser.OP_NID)
759 .withChild(Builders.leafBuilder().withNodeIdentifier(FlowspecL3vpnIpv4NlriParser.OP_NID).withValue(Sets.newHashSet(AbstractOperandParser.AND_BIT_VALUE, AbstractOperandParser.END_OF_LIST_VALUE, AbstractNumericOperandParser.GREATER_THAN_VALUE)).build())
760 .withChild(Builders.leafBuilder().withNodeIdentifier(FlowspecL3vpnIpv4NlriParser.VALUE_NID).withValue((short) 15).build()).build())
761 .build()).build()).build()).build());
762 final FlowspecBuilder expectedFS = new FlowspecBuilder();
763 expectedFS.setFlowspecType(new DscpCaseBuilder().setDscps(Lists.newArrayList(new DscpsBuilder().setValue(new Dscp((short) 15)).setOp(new NumericOperand(true, true, false, true, false)).build())).build());
764 final List<Flowspec> expected = new ArrayList<>();
765 expected.add(expectedFS.build());
766 assertEquals(expected, FS_PARSER.extractFlowspec(entry.build()));
770 public void testExtractFlowspecFragments() {
771 final DataContainerNodeAttrBuilder<NodeIdentifierWithPredicates, MapEntryNode> entry = Builders.mapEntryBuilder();
772 entry.withNodeIdentifier(new NodeIdentifierWithPredicates(FlowspecRoute.QNAME, FlowspecRoute.QNAME, entry));
773 entry.withChild(Builders.unkeyedListBuilder()
774 .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_NID)
775 .withChild(Builders.unkeyedListEntryBuilder()
776 .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_NID)
777 .withChild(Builders.choiceBuilder()
778 .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_TYPE_NID)
779 .withChild(Builders.unkeyedListBuilder().withNodeIdentifier(AbstractFlowspecNlriParser.FRAGMENT_NID)
780 .withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(FlowspecL3vpnIpv4NlriParser.OP_NID)
781 .withChild(Builders.leafBuilder().withNodeIdentifier(FlowspecL3vpnIpv4NlriParser.OP_NID).withValue(Sets.newHashSet(AbstractOperandParser.AND_BIT_VALUE, AbstractOperandParser.END_OF_LIST_VALUE, BitmaskOperandParser.MATCH_VALUE, BitmaskOperandParser.NOT_VALUE)).build())
782 .withChild(Builders.leafBuilder().withNodeIdentifier(FlowspecL3vpnIpv4NlriParser.VALUE_NID).withValue(Sets.newHashSet(AbstractFlowspecNlriParser.DO_NOT_VALUE, AbstractFlowspecNlriParser.FIRST_VALUE, AbstractFlowspecNlriParser.IS_A_VALUE, AbstractFlowspecNlriParser.LAST_VALUE)).build()).build())
783 .build()).build()).build()).build());
784 final FlowspecBuilder expectedFS = new FlowspecBuilder();
785 expectedFS.setFlowspecType(new FragmentCaseBuilder().setFragments(Lists.newArrayList(new FragmentsBuilder().setValue(new Fragment(true, true, true, true)).setOp(new BitmaskOperand(true, true, true, true)).build())).build());
786 final List<Flowspec> expected = new ArrayList<>();
787 expected.add(expectedFS.build());
788 assertEquals(expected, FS_PARSER.extractFlowspec(entry.build()));
792 public void testExtractFlowspecRouteDistinguisher() {
793 final DataContainerNodeAttrBuilder<NodeIdentifierWithPredicates, MapEntryNode> entry = Builders.mapEntryBuilder();
794 entry.withNodeIdentifier(new NodeIdentifierWithPredicates(FlowspecRoute.QNAME, FlowspecRoute.QNAME, entry));
796 Builders.leafBuilder()
797 .withNodeIdentifier(RD_NID)
799 RouteDistinguisherBuilder.getDefaultInstance(ROUTE_DISTINGUISHER)
803 RouteDistinguisher rd = RouteDistinguisherBuilder.getDefaultInstance(ROUTE_DISTINGUISHER);
804 assertEquals(rd, FS_PARSER.extractRouteDistinguisher(entry.build()));