import io.netty.buffer.Unpooled;
import java.util.ArrayList;
import java.util.List;
+import java.util.Optional;
+import org.junit.Before;
import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
import org.opendaylight.protocol.bgp.flowspec.handlers.AbstractNumericOperandParser;
import org.opendaylight.protocol.bgp.flowspec.handlers.AbstractOperandParser;
import org.opendaylight.protocol.bgp.flowspec.handlers.BitmaskOperandParser;
import org.opendaylight.protocol.bgp.parser.BGPParsingException;
+import org.opendaylight.protocol.bgp.parser.spi.MultiPathSupport;
+import org.opendaylight.protocol.bgp.parser.spi.PeerSpecificParserConstraint;
import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.BitmaskOperand;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.Dscp;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.FlowspecSubsequentAddressFamily;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.Fragment;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.NumericOperand;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.Flowspec;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.FlowspecBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.DestinationPortCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.FlowspecType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.DestinationPortCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.DscpCase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.DscpCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.FragmentCase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.FragmentCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.IcmpCodeCase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.IcmpCodeCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.IcmpTypeCase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.IcmpTypeCaseBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.PacketLengthCase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.PacketLengthCaseBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.PortCase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.PortCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.SourcePortCase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.SourcePortCaseBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.TcpFlagsCase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.TcpFlagsCaseBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.tcp.flags._case.TcpFlagsBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.ipv4.flowspec.flowspec.type.DestinationPrefixCase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.ipv4.flowspec.flowspec.type.DestinationPrefixCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.ipv4.flowspec.flowspec.type.ProtocolIpCase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.ipv4.flowspec.flowspec.type.ProtocolIpCaseBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.ipv4.flowspec.flowspec.type.SourcePrefixCase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.ipv4.flowspec.flowspec.type.SourcePrefixCaseBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationFlowspecCase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationFlowspecCaseBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.update.attributes.mp.reach.nlri.advertized.routes.destination.type.destination.flowspec._case.DestinationFlowspecBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.PathId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.AttributesBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.Attributes1;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.Attributes1Builder;
public class SimpleFlowspecIpv4NlriParserTest {
- private static final byte[] REACHED_NLRI = new byte[] { 0x21,
+ static final PathId PATH_ID = new PathId(1L);
+ @Mock
+ private PeerSpecificParserConstraint constraint;
+ @Mock
+ private MultiPathSupport muliPathSupport;
+
+ private static final byte[] REACHED_NLRI = new byte[] {
+ 0x21,
+ 01, 0x20, 0x0a, 00, 01, 00,
+ 02, 0x20, 01, 02, 03, 04,
+ 03, (byte) 0x81, 06,
+ 04, 03, (byte) 0x89, 0x45, (byte) 0x8b, (byte) 0x91, 0x1f, (byte) 0x90,
+ 05, 0x12, 0x0f, (byte) 0xf9, (byte) 0x81, (byte) 0xb3,
+ 06, (byte) 0x91, 0x1f, (byte) 0x90
+ };
+
+ private static final byte[] REACHED_NLRI_ADD_PATH = new byte[] {
+ 0x0, 0x0, 0x0, 0x1,
+ 0x21,
01, 0x20, 0x0a, 00, 01, 00,
02, 0x20, 01, 02, 03, 04,
03, (byte) 0x81, 06,
04, 03, (byte) 0x89, 0x45, (byte) 0x8b, (byte) 0x91, 0x1f, (byte) 0x90,
05, 0x12, 0x0f, (byte) 0xf9, (byte) 0x81, (byte) 0xb3,
- 06, (byte) 0x91, 0x1f, (byte) 0x90 };
+ 06, (byte) 0x91, 0x1f, (byte) 0x90
+ };
+
+ private static final byte[] UNREACHED_NLRI = new byte[] {
+ 0x1B,
+ 07, 4, 2, (byte) 0x84, 3,
+ 0x08, 4, 04, (byte) 0x80, 05,
+ 0x09, 0x12, 04, 01, (byte) 0x91, 0x56, (byte) 0xb1,
+ 0x0a, (byte) 0x94, (byte) 0xde, (byte) 0xad,
+ 0x0b, (byte) 0x82, 0x2a,
+ 0x0c, (byte) 0x81, (byte) 0x0e
+ };
- private static final byte[] UNREACHED_NLRI = new byte[] { 0x1B,
+ private static final byte[] UNREACHED_NLRI_ADD_PATH = new byte[] {
+ 0x0, 0x0, 0x0, 0x1,
+ 0x1B,
07, 4, 2, (byte) 0x84, 3,
0x08, 4, 04, (byte) 0x80, 05,
0x09, 0x12, 04, 01, (byte) 0x91, 0x56, (byte) 0xb1,
0x0a, (byte) 0x94, (byte) 0xde, (byte) 0xad,
0x0b, (byte) 0x82, 0x2a,
- 0x0c, (byte) 0x81, (byte) 0x0e};
+ 0x0c, (byte) 0x81, (byte) 0x0e
+ };
private final SimpleFlowspecExtensionProviderContext flowspecContext = new SimpleFlowspecExtensionProviderContext();
private final FlowspecActivator fsa = new FlowspecActivator(flowspecContext);
private final SimpleFlowspecIpv4NlriParser FS_PARSER = new SimpleFlowspecIpv4NlriParser(flowspecContext.getFlowspecIpv4TypeRegistry());
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ Mockito.doReturn(Optional.of(this.muliPathSupport)).when(constraint).getPeerConstraint(Mockito.any());
+ Mockito.doReturn(true).when(this.muliPathSupport).isTableTypeSupported(Mockito.any());
+ }
+
@Test
public void testParseMpReachNlri() throws BGPParsingException {
final List<Flowspec> fs = new ArrayList<>();
builder.setFlowspecType(sourcePrefix);
fs.add(builder.build());
- final List<ProtocolIps> protocols = Lists.newArrayList(new ProtocolIpsBuilder().setOp(new NumericOperand(false, true, true, false, false)).setValue((short)6).build());
- final ProtocolIpCase prots = new ProtocolIpCaseBuilder().setProtocolIps(protocols).build();
+ final FlowspecType prots = createProts();
builder.setFlowspecType(prots);
fs.add(builder.build());
- final List<Ports> ports = Lists.newArrayList(new PortsBuilder().setOp(new NumericOperand(false, false, true, true, false)).setValue(137).build(),
- new PortsBuilder().setOp(new NumericOperand(true, false, true, false, true)).setValue(139).build(),
- new PortsBuilder().setOp(new NumericOperand(false, true, true, false, false)).setValue(8080).build());
- final PortCase ps = new PortCaseBuilder().setPorts(ports).build();
+ final PortCase ps = createPorts();
builder.setFlowspecType(ps);
fs.add(builder.build());
- final List<DestinationPorts> destports = Lists.newArrayList(new DestinationPortsBuilder().setOp(new NumericOperand(false, false, false, true, false)).setValue(4089).build(),
- new DestinationPortsBuilder().setOp(new NumericOperand(false, true, true, false, false)).setValue(179).build());
- final DestinationPortCase dps = new DestinationPortCaseBuilder().setDestinationPorts(destports).build();
+ final FlowspecType dps = createDps();
builder.setFlowspecType(dps);
fs.add(builder.build());
- final List<SourcePorts> sports = Lists.newArrayList(new SourcePortsBuilder().setOp(new NumericOperand(false, true, true, false, false)).setValue(8080).build());
- final SourcePortCase sps = new SourcePortCaseBuilder().setSourcePorts(sports).build();
+ final FlowspecType sps = createSps();
builder.setFlowspecType(sps);
fs.add(builder.build());
- mp.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(new DestinationFlowspecCaseBuilder().setDestinationFlowspec(new DestinationFlowspecBuilder().setFlowspec(fs).build()).build()).build());
+ mp.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(new DestinationFlowspecCaseBuilder().setDestinationFlowspec(new
+ DestinationFlowspecBuilder().setFlowspec(fs).build()).build()).build());
final SimpleFlowspecIpv4NlriParser parser = new SimpleFlowspecIpv4NlriParser(flowspecContext.getFlowspecIpv4TypeRegistry());
final MpReachNlriBuilder result = new MpReachNlriBuilder();
result.setAfi(Ipv4AddressFamily.class);
+ result.setSafi(FlowspecSubsequentAddressFamily.class);
parser.parseNlri(Unpooled.wrappedBuffer(REACHED_NLRI), result);
final List<Flowspec> flows = ((DestinationFlowspecCase) (result.getAdvertizedRoutes().getDestinationType())).getDestinationFlowspec().getFlowspec();
+ testFlows(flows, destinationPrefix, sourcePrefix, prots, prots, ps, dps, sps);
+
+ final ByteBuf buffer = Unpooled.buffer();
+ parser.serializeAttribute(new AttributesBuilder().addAugmentation(Attributes1.class, new Attributes1Builder().setMpReachNlri(mp.setAfi(Ipv4AddressFamily.class).build()).build()).build(), buffer);
+ assertArrayEquals(REACHED_NLRI, ByteArray.readAllBytes(buffer));
+
+ 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));
+ }
+
+ 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) {
assertEquals(6, flows.size());
assertEquals(destinationPrefix, flows.get(0).getFlowspecType());
assertEquals(sourcePrefix, flows.get(1).getFlowspecType());
assertEquals(ps, flows.get(3).getFlowspecType());
assertEquals(dps, flows.get(4).getFlowspecType());
assertEquals(sps, flows.get(5).getFlowspecType());
+ }
+
+ private FlowspecType createSps() {
+ final List<SourcePorts> sports = Lists.newArrayList(new SourcePortsBuilder().setOp(new NumericOperand(false, true, true, false, false)).setValue(8080).build());
+ return new SourcePortCaseBuilder().setSourcePorts(sports).build();
+ }
+
+ private FlowspecType createProts() {
+ final List<ProtocolIps> protocols = Lists.newArrayList(new ProtocolIpsBuilder().setOp(new NumericOperand(false, true, true, false, false)).setValue((short)6).build());
+ return new ProtocolIpCaseBuilder().setProtocolIps(protocols).build();
+ }
+
+ private FlowspecType createDps() {
+ final List<DestinationPorts> destports = Lists.newArrayList(new DestinationPortsBuilder().setOp(new NumericOperand(false, false, false, true, false)).setValue(4089).build(),
+ new DestinationPortsBuilder().setOp(new NumericOperand(false, true, true, false, false)).setValue(179).build());
+ return new DestinationPortCaseBuilder().setDestinationPorts(destports).build();
+ }
+
+ @Test
+ public void testParseMpReachNlriConstraint() throws BGPParsingException {
+ final List<Flowspec> fs = new ArrayList<>();
+ final MpReachNlriBuilder mp = new MpReachNlriBuilder();
+
+ final FlowspecBuilder builder = new FlowspecBuilder();
+ final DestinationPrefixCase destinationPrefix = new DestinationPrefixCaseBuilder().setDestinationPrefix(new Ipv4Prefix("10.0.1.0/32")).build();
+ builder.setFlowspecType(destinationPrefix);
+ fs.add(builder.build());
+ final SourcePrefixCase sourcePrefix = new SourcePrefixCaseBuilder().setSourcePrefix(new Ipv4Prefix("1.2.3.4/32")).build();
+ builder.setFlowspecType(sourcePrefix);
+ fs.add(builder.build());
+
+ final FlowspecType prots = createProts();
+ builder.setFlowspecType(prots);
+ fs.add(builder.build());
+
+ final PortCase ps = createPorts();
+ builder.setFlowspecType(ps);
+ fs.add(builder.build());
+
+ final FlowspecType dps = createDps();
+ builder.setFlowspecType(dps);
+ fs.add(builder.build());
+
+ final FlowspecType sps = createSps();
+ builder.setFlowspecType(sps);
+ fs.add(builder.build());
+
+ mp.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(new DestinationFlowspecCaseBuilder().setDestinationFlowspec(new
+ DestinationFlowspecBuilder().setPathId(PATH_ID).setFlowspec(fs).build()).build()).build());
+
+ final SimpleFlowspecIpv4NlriParser parser = new SimpleFlowspecIpv4NlriParser(flowspecContext.getFlowspecIpv4TypeRegistry());
+
+ final MpReachNlriBuilder result = new MpReachNlriBuilder();
+ result.setAfi(Ipv4AddressFamily.class);
+ result.setSafi(FlowspecSubsequentAddressFamily.class);
+ parser.parseNlri(Unpooled.wrappedBuffer(REACHED_NLRI_ADD_PATH), result, this.constraint);
+
+ final List<Flowspec> flows = ((DestinationFlowspecCase) (result.getAdvertizedRoutes().getDestinationType())).getDestinationFlowspec().getFlowspec();
+ testFlows(flows, destinationPrefix, sourcePrefix, prots, prots, ps,dps, sps);
final ByteBuf buffer = Unpooled.buffer();
parser.serializeAttribute(new AttributesBuilder().addAugmentation(Attributes1.class, new Attributes1Builder().setMpReachNlri(mp.setAfi(Ipv4AddressFamily.class).build()).build()).build(), buffer);
- assertArrayEquals(REACHED_NLRI, ByteArray.readAllBytes(buffer));
+ assertArrayEquals(REACHED_NLRI_ADD_PATH, ByteArray.readAllBytes(buffer));
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));
}
+ private PortCase createPorts() {
+ final List<Ports> ports = Lists.newArrayList(new PortsBuilder().setOp(new NumericOperand(false, false, true, true, false)).setValue(137).build(),
+ new PortsBuilder().setOp(new NumericOperand(true, false, true, false, true)).setValue(139).build(),
+ new PortsBuilder().setOp(new NumericOperand(false, true, true, false, false)).setValue(8080).build());
+
+ return new PortCaseBuilder().setPorts(ports).build();
+ }
+
@Test
public void testParseMpUnreachNlri() throws BGPParsingException {
final List<Flowspec> fs = new ArrayList<>();
final FlowspecBuilder builder = new FlowspecBuilder();
- final List<Types> types = Lists.newArrayList(new TypesBuilder().setOp(new NumericOperand(false, false, false, false, true)).setValue((short) 2).build(),
- new TypesBuilder().setOp(new NumericOperand(false, true, false, false, true)).setValue((short) 3).build());
- final IcmpTypeCase icmpType = new IcmpTypeCaseBuilder().setTypes(types).build();
+ final FlowspecType icmpType = createIcmpType();
builder.setFlowspecType(icmpType);
fs.add(builder.build());
- final List<Codes> codes = Lists.newArrayList(new CodesBuilder().setOp(new NumericOperand(false, false, false, false, true)).setValue((short) 4).build(),
- new CodesBuilder().setOp(new NumericOperand(false, true, false, false, false)).setValue((short) 5).build());
- final IcmpCodeCase icmpCode = new IcmpCodeCaseBuilder().setCodes(codes).build();
+ final FlowspecType icmpCode = createIcmpCode();
builder.setFlowspecType(icmpCode);
fs.add(builder.build());
- final List<TcpFlags> flags = Lists.newArrayList(new TcpFlagsBuilder().setOp(new BitmaskOperand(false, false, false, true)).setValue(1025).build(),
- new TcpFlagsBuilder().setOp(new BitmaskOperand(false, true, true, false)).setValue(22193).build());
- final TcpFlagsCase tcp = new TcpFlagsCaseBuilder().setTcpFlags(flags).build();
+ final TcpFlagsCase tcp = createTcp();
builder.setFlowspecType(tcp);
fs.add(builder.build());
- final List<PacketLengths> packets = Lists.newArrayList(new PacketLengthsBuilder().setOp(new NumericOperand(false, true, false, false, true)).setValue(57005).build());
- final PacketLengthCase packet = new PacketLengthCaseBuilder().setPacketLengths(packets).build();
+ final PacketLengthCase packet = createPackets();
builder.setFlowspecType(packet);
fs.add(builder.build());
- final List<Dscps> dscps = Lists.newArrayList(new DscpsBuilder().setOp(new NumericOperand(false, true, false, true, false)).setValue(new Dscp((short) 42)).build());
- final DscpCase dscp = new DscpCaseBuilder().setDscps(dscps).build();
+ final FlowspecType dscp = createDscp();
builder.setFlowspecType(dscp);
fs.add(builder.build());
- final List<Fragments> fragments = Lists.newArrayList(new FragmentsBuilder().setOp(new BitmaskOperand(false, true, true, false)).setValue(new Fragment(false, true, true, true)).build());
- final FragmentCase fragment = new FragmentCaseBuilder().setFragments(fragments).build();
+ final FlowspecType fragment = createFragment();
builder.setFlowspecType(fragment);
fs.add(builder.build());
mp.setAfi(Ipv4AddressFamily.class).setWithdrawnRoutes(new WithdrawnRoutesBuilder().setDestinationType(
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().setDestinationFlowspec(
- new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.destination.flowspec._case.DestinationFlowspecBuilder().setFlowspec(fs).build()).build()).build());
+ new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.destination.flowspec._case.DestinationFlowspecBuilder()
+ .setFlowspec(fs).build()).build()).build());
final SimpleFlowspecIpv4NlriParser parser = new SimpleFlowspecIpv4NlriParser(flowspecContext.getFlowspecIpv4TypeRegistry());
final MpUnreachNlriBuilder result = new MpUnreachNlriBuilder();
result.setAfi(Ipv4AddressFamily.class);
+ result.setSafi(FlowspecSubsequentAddressFamily.class);
parser.parseNlri(Unpooled.wrappedBuffer(UNREACHED_NLRI), result);
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())).getDestinationFlowspec().getFlowspec();
+ checkUnreachFlows(flows, icmpType, icmpCode, tcp, packet, dscp, fragment);
+
+ final ByteBuf buffer = Unpooled.buffer();
+ parser.serializeNlri(flows, null, buffer);
+ assertArrayEquals(UNREACHED_NLRI, ByteArray.readAllBytes(buffer));
+
+ parser.serializeAttribute(new AttributesBuilder().addAugmentation(Attributes2.class, new Attributes2Builder().setMpUnreachNlri(mp.build()).build()).build(), buffer);
+ assertArrayEquals(UNREACHED_NLRI, ByteArray.readAllBytes(buffer));
+
+ 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));
+
+ }
+
+ private FlowspecType createFragment() {
+ final List<Fragments> fragments = Lists.newArrayList(new FragmentsBuilder().setOp(new BitmaskOperand(false, true, true, false)).setValue(new Fragment(false, true, true, true)).build());
+ return new FragmentCaseBuilder().setFragments(fragments).build();
+ }
+
+ private FlowspecType createDscp() {
+ final List<Dscps> dscps = Lists.newArrayList(new DscpsBuilder().setOp(new NumericOperand(false, true, false, true, false)).setValue(new Dscp((short) 42)).build());
+ return new DscpCaseBuilder().setDscps(dscps).build();
+ }
+
+ private PacketLengthCase createPackets() {
+ final List<PacketLengths> packets = Lists.newArrayList(new PacketLengthsBuilder().setOp(new NumericOperand(false, true, false, false, true))
+ .setValue(57005).build());
+ return new PacketLengthCaseBuilder().setPacketLengths(packets).build();
+ }
+
+ private TcpFlagsCase createTcp() {
+ final List<TcpFlags> flags = Lists.newArrayList(new TcpFlagsBuilder().setOp(new BitmaskOperand(false, false, false, true)).setValue(1025).build(),
+ new TcpFlagsBuilder().setOp(new BitmaskOperand(false, true, true, false)).setValue(22193).build());
+ return new TcpFlagsCaseBuilder().setTcpFlags(flags).build();
+ }
+
+ private FlowspecType createIcmpCode() {
+ final List<Codes> codes = Lists.newArrayList(new CodesBuilder().setOp(new NumericOperand(false, false, false, false, true)).setValue((short) 4).build(),
+ new CodesBuilder().setOp(new NumericOperand(false, true, false, false, false)).setValue((short) 5).build());
+ return new IcmpCodeCaseBuilder().setCodes(codes).build();
+ }
+
+ private FlowspecType createIcmpType() {
+ final List<Types> types = Lists.newArrayList(new TypesBuilder().setOp(new NumericOperand(false, false, false, false, true)).setValue((short) 2).build(),
+ new TypesBuilder().setOp(new NumericOperand(false, true, false, false, true)).setValue((short) 3).build());
+ return new IcmpTypeCaseBuilder().setTypes(types).build();
+ }
+
+ private void checkUnreachFlows(final List<Flowspec> flows, final FlowspecType icmpType, final FlowspecType icmpCode, final TcpFlagsCase tcp,
+ final PacketLengthCase packet, final FlowspecType dscp, final FlowspecType fragment) {
assertEquals(6, flows.size());
assertEquals(icmpType, flows.get(0).getFlowspecType());
assertEquals(icmpCode, flows.get(1).getFlowspecType());
assertEquals(packet, flows.get(3).getFlowspecType());
assertEquals(dscp, flows.get(4).getFlowspecType());
assertEquals(fragment, flows.get(5).getFlowspecType());
+ }
+
+ @Test
+ public void testParseMpUnreachNlriConstraint() throws BGPParsingException {
+ final List<Flowspec> fs = new ArrayList<>();
+ final MpUnreachNlriBuilder mp = new MpUnreachNlriBuilder();
+
+ final FlowspecBuilder builder = new FlowspecBuilder();
+
+ final FlowspecType icmpType = createIcmpType();
+ builder.setFlowspecType(icmpType);
+ fs.add(builder.build());
+
+ final FlowspecType icmpCode = createIcmpCode();
+ builder.setFlowspecType(icmpCode);
+ fs.add(builder.build());
+
+ final TcpFlagsCase tcp = createTcp();
+ builder.setFlowspecType(tcp);
+ fs.add(builder.build());
+
+ final PacketLengthCase packet = createPackets();
+ builder.setFlowspecType(packet);
+ fs.add(builder.build());
+
+ final FlowspecType dscp = createDscp();
+ builder.setFlowspecType(dscp);
+ fs.add(builder.build());
+
+ final FlowspecType fragment = createFragment();
+ builder.setFlowspecType(fragment);
+ fs.add(builder.build());
+
+ mp.setAfi(Ipv4AddressFamily.class).setWithdrawnRoutes(new WithdrawnRoutesBuilder().setDestinationType(
+ 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().setDestinationFlowspec(
+ new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.destination.flowspec._case.DestinationFlowspecBuilder()
+ .setPathId(PATH_ID).setFlowspec(fs).build()).build()).build());
+
+ final SimpleFlowspecIpv4NlriParser parser = new SimpleFlowspecIpv4NlriParser(flowspecContext.getFlowspecIpv4TypeRegistry());
+
+ final MpUnreachNlriBuilder result = new MpUnreachNlriBuilder();
+ result.setAfi(Ipv4AddressFamily.class);
+ result.setSafi(FlowspecSubsequentAddressFamily.class);
+ parser.parseNlri(Unpooled.wrappedBuffer(UNREACHED_NLRI_ADD_PATH), result, this.constraint);
+
+ 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())).getDestinationFlowspec().getFlowspec();
+ checkUnreachFlows(flows, icmpType, icmpCode, tcp, packet, dscp, fragment);
+
final ByteBuf buffer = Unpooled.buffer();
- parser.serializeNlri(flows, buffer);
- assertArrayEquals(UNREACHED_NLRI, ByteArray.readAllBytes(buffer));
+ parser.serializeNlri(flows, PATH_ID, buffer);
+ assertArrayEquals(UNREACHED_NLRI_ADD_PATH, ByteArray.readAllBytes(buffer));
parser.serializeAttribute(new AttributesBuilder().addAugmentation(Attributes2.class, new Attributes2Builder().setMpUnreachNlri(mp.build()).build()).build(), buffer);
- assertArrayEquals(UNREACHED_NLRI, ByteArray.readAllBytes(buffer));
+ assertArrayEquals(UNREACHED_NLRI_ADD_PATH, ByteArray.readAllBytes(buffer));
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));
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
+import static org.opendaylight.protocol.bgp.flowspec.SimpleFlowspecIpv4NlriParserTest.PATH_ID;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import io.netty.buffer.Unpooled;
import java.util.ArrayList;
import java.util.List;
+import java.util.Optional;
+import org.junit.Before;
import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
import org.opendaylight.protocol.bgp.flowspec.handlers.AbstractNumericOperandParser;
import org.opendaylight.protocol.bgp.flowspec.handlers.AbstractOperandParser;
import org.opendaylight.protocol.bgp.flowspec.handlers.BitmaskOperandParser;
import org.opendaylight.protocol.bgp.parser.BGPParsingException;
+import org.opendaylight.protocol.bgp.parser.spi.MultiPathSupport;
+import org.opendaylight.protocol.bgp.parser.spi.PeerSpecificParserConstraint;
import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Prefix;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.BitmaskOperand;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.FlowspecSubsequentAddressFamily;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.Fragment;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.NumericOperand;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.Flowspec;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.FlowspecBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.FlowspecType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.FragmentCase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.FragmentCaseBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.fragment._case.Fragments;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.fragment._case.FragmentsBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.ipv6.flowspec.flowspec.type.DestinationIpv6PrefixCase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.ipv6.flowspec.flowspec.type.DestinationIpv6PrefixCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.ipv6.flowspec.flowspec.type.FlowLabelCase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.ipv6.flowspec.flowspec.type.FlowLabelCaseBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.ipv6.flowspec.flowspec.type.NextHeaderCase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.ipv6.flowspec.flowspec.type.NextHeaderCaseBuilder;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeAttrBuilder;
public class SimpleFlowspecIpv6NlriParserTest {
-
+ @Mock
+ private PeerSpecificParserConstraint constraint;
+ @Mock
+ private MultiPathSupport muliPathSupport;
private final SimpleFlowspecExtensionProviderContext flowspecContext = new SimpleFlowspecExtensionProviderContext();
private final FlowspecActivator fsa = new FlowspecActivator(flowspecContext);
private final SimpleFlowspecIpv6NlriParser FS_PARSER = new SimpleFlowspecIpv6NlriParser(flowspecContext.getFlowspecIpv6TypeRegistry());
- private static final byte[] REACHED_NLRI = new byte[] { 0x13,
+ private static final byte[] REACHED_NLRI = new byte[] {
+ 0x13,
+ 1, 0x28, 0, 1, 2, 3, 4, 5,
+ 2, 0x28, 0, 1, 2, 3, 4, 6,
+ 03, (byte) 0x81, 06 };
+
+ private static final byte[] REACHED_NLRI_ADD_PATH = new byte[] {
+ 0x0, 0x0, 0x0, 0x1,
+ 0x13,
1, 0x28, 0, 1, 2, 3, 4, 5,
2, 0x28, 0, 1, 2, 3, 4, 6,
03, (byte) 0x81, 06 };
- private static final byte[] UNREACHED_NLRI = new byte[] { 0x0c,
+ private static final byte[] UNREACHED_NLRI = new byte[] {
+ 0x0c,
0x0c, (byte) 0x81, 0x0e,
- 0x0d, (byte) 0x21, 1, 0, 0, 6, (byte) 0x91, 1, 2 };
+ 0x0d, (byte) 0x21, 1, 0, 0, 6, (byte) 0x91, 1, 2
+ };
+
+ private static final byte[] UNREACHED_NLRI_ADD_PATH = new byte[] {
+ 0x0, 0x0, 0x0, 0x1,
+ 0x0c,
+ 0x0c, (byte) 0x81, 0x0e,
+ 0x0d, (byte) 0x21, 1, 0, 0, 6, (byte) 0x91, 1, 2
+ };
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ Mockito.doReturn(Optional.of(this.muliPathSupport)).when(constraint).getPeerConstraint(Mockito.any());
+ Mockito.doReturn(true).when(this.muliPathSupport).isTableTypeSupported(Mockito.any());
+ }
@Test
public void testParseMpReachNlri() throws BGPParsingException {
fs.add(builder.build());
- mp.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(new DestinationFlowspecIpv6CaseBuilder().setDestinationFlowspec(new DestinationFlowspecBuilder().setFlowspec(fs).build()).build()).build());
+ mp.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(new DestinationFlowspecIpv6CaseBuilder().setDestinationFlowspec(
+ new DestinationFlowspecBuilder().setFlowspec(fs).build()).build()).build());
final MpReachNlriBuilder result = new MpReachNlriBuilder();
result.setAfi(Ipv6AddressFamily.class);
+ result.setSafi(FlowspecSubsequentAddressFamily.class);
FS_PARSER.parseNlri(Unpooled.wrappedBuffer(REACHED_NLRI), result);
final List<Flowspec> flows = ((DestinationFlowspecIpv6Case) (result.getAdvertizedRoutes().getDestinationType())).getDestinationFlowspec().getFlowspec();
assertEquals("all packets to 102:304:500::/40 AND from 102:304:600::/40 AND where next header equals to 6 ", FS_PARSER.stringNlri(flows));
}
+ @Test
+ public void testParseMpReachNlriConstraint() throws BGPParsingException {
+ final List<Flowspec> fs = new ArrayList<>();
+ final MpReachNlriBuilder mp = new MpReachNlriBuilder();
+
+ final FlowspecBuilder builder = new FlowspecBuilder();
+ final DestinationIpv6PrefixCase destinationPrefix = new DestinationIpv6PrefixCaseBuilder().setDestinationPrefix(new Ipv6Prefix("102:304:500::/40")).build();
+ builder.setFlowspecType(destinationPrefix);
+ fs.add(builder.build());
+
+ final SourceIpv6PrefixCase sourcePrefix = new SourceIpv6PrefixCaseBuilder().setSourcePrefix(new Ipv6Prefix("102:304:600::/40")).build();
+ builder.setFlowspecType(sourcePrefix);
+ fs.add(builder.build());
+
+ final List<NextHeaders> nextheaders = Lists.newArrayList(new NextHeadersBuilder().setOp(new NumericOperand(false, true, true, false, false)).setValue((short) 6).build());
+ final NextHeaderCase headersCase = new NextHeaderCaseBuilder().setNextHeaders(nextheaders).build();
+ builder.setFlowspecType(headersCase);
+ fs.add(builder.build());
+
+
+ mp.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(new DestinationFlowspecIpv6CaseBuilder().setDestinationFlowspec(
+ new DestinationFlowspecBuilder().setPathId(PATH_ID).setFlowspec(fs).build()).build()).build());
+
+ final MpReachNlriBuilder result = new MpReachNlriBuilder();
+ result.setAfi(Ipv6AddressFamily.class);
+ result.setSafi(FlowspecSubsequentAddressFamily.class);
+ FS_PARSER.parseNlri(Unpooled.wrappedBuffer(REACHED_NLRI_ADD_PATH), result, this.constraint);
+
+ final List<Flowspec> flows = ((DestinationFlowspecIpv6Case) (result.getAdvertizedRoutes().getDestinationType())).getDestinationFlowspec().getFlowspec();
+ assertEquals(3, flows.size());
+ assertEquals(destinationPrefix, flows.get(0).getFlowspecType());
+ assertEquals(sourcePrefix, flows.get(1).getFlowspecType());
+ assertEquals(headersCase, flows.get(2).getFlowspecType());
+
+ final ByteBuf buffer = Unpooled.buffer();
+ FS_PARSER.serializeAttribute(new AttributesBuilder().addAugmentation(Attributes1.class, new Attributes1Builder().setMpReachNlri(mp.setAfi(Ipv6AddressFamily.class).build()).build()).build(), buffer);
+ assertArrayEquals(REACHED_NLRI_ADD_PATH, ByteArray.readAllBytes(buffer));
+
+ assertEquals("all packets to 102:304:500::/40 AND from 102:304:600::/40 AND where next header equals to 6 ", FS_PARSER.stringNlri(flows));
+ }
+
@Test
public void testParseMpUnreachNlri() throws BGPParsingException {
final List<Flowspec> fs = new ArrayList<>();
final FlowspecBuilder builder = new FlowspecBuilder();
- final List<Fragments> fragments = Lists.newArrayList(new FragmentsBuilder().setOp(new BitmaskOperand(false, true, true, false)).setValue(new Fragment(false, true, true, true)).build());
- final FragmentCase fragment = new FragmentCaseBuilder().setFragments(fragments).build();
+ final FragmentCase fragment = createFragment();
builder.setFlowspecType(fragment);
fs.add(builder.build());
- final List<FlowLabel> labels = Lists.newArrayList();
- labels.add(new FlowLabelBuilder().setOp(new NumericOperand(false, false, true, false, false)).setValue(new Long(16777222L)).build());
- labels.add(new FlowLabelBuilder().setOp(new NumericOperand(false, true, true, false, false)).setValue(new Long(258L)).build());
- final FlowLabelCase label = new FlowLabelCaseBuilder().setFlowLabel(labels).build();
+ final FlowspecType label = createLabel();
builder.setFlowspecType(label);
fs.add(builder.build());
final MpUnreachNlriBuilder result = new MpUnreachNlriBuilder();
result.setAfi(Ipv6AddressFamily.class);
+ result.setSafi(FlowspecSubsequentAddressFamily.class);
FS_PARSER.parseNlri(Unpooled.wrappedBuffer(UNREACHED_NLRI), result);
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.DestinationFlowspecIpv6Case) (result.getWithdrawnRoutes().getDestinationType())).getDestinationFlowspec().getFlowspec();
assertEquals("all packets where fragment does match 'IS FIRST' 'IS LAST' 'IS A' AND where flow label equals to 16777222 or equals to 258 ", FS_PARSER.stringNlri(flows));
}
+ private FragmentCase createFragment() {
+ final List<Fragments> fragments = Lists.newArrayList(new FragmentsBuilder().setOp(new BitmaskOperand(false, true, true, false)).setValue(new Fragment(false, true, true, true)).build());
+ return new FragmentCaseBuilder().setFragments(fragments).build();
+ }
+
+ private FlowspecType createLabel() {
+ final List<FlowLabel> labels = Lists.newArrayList();
+ labels.add(new FlowLabelBuilder().setOp(new NumericOperand(false, false, true, false, false)).setValue(new Long(16777222L)).build());
+ labels.add(new FlowLabelBuilder().setOp(new NumericOperand(false, true, true, false, false)).setValue(new Long(258L)).build());
+ return new FlowLabelCaseBuilder().setFlowLabel(labels).build();
+ }
+
+ @Test
+ public void testParseMpUnreachNlriConstraint() throws BGPParsingException {
+ final List<Flowspec> fs = new ArrayList<>();
+ final MpUnreachNlriBuilder mp = new MpUnreachNlriBuilder();
+
+ final FlowspecBuilder builder = new FlowspecBuilder();
+ final FragmentCase fragment = createFragment();
+
+ builder.setFlowspecType(fragment);
+ fs.add(builder.build());
+
+ final FlowspecType label = createLabel();
+ builder.setFlowspecType(label);
+ fs.add(builder.build());
+
+ mp.setAfi(Ipv6AddressFamily.class).setWithdrawnRoutes(new WithdrawnRoutesBuilder().setDestinationType(
+ new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationFlowspecIpv6CaseBuilder().setDestinationFlowspec(
+ new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.destination.flowspec.ipv6._case.DestinationFlowspecBuilder().setPathId(PATH_ID).setFlowspec(fs).build()).build()).build());
+
+ final MpUnreachNlriBuilder result = new MpUnreachNlriBuilder();
+ result.setAfi(Ipv6AddressFamily.class);
+ result.setSafi(FlowspecSubsequentAddressFamily.class);
+ FS_PARSER.parseNlri(Unpooled.wrappedBuffer(UNREACHED_NLRI_ADD_PATH), result, this.constraint);
+
+ 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.DestinationFlowspecIpv6Case) (result.getWithdrawnRoutes().getDestinationType())).getDestinationFlowspec().getFlowspec();
+ assertEquals(2, flows.size());
+ assertEquals(fragment, flows.get(0).getFlowspecType());
+ assertEquals(label, flows.get(1).getFlowspecType());
+
+ final ByteBuf buffer = Unpooled.buffer();
+ FS_PARSER.serializeAttribute(new AttributesBuilder().addAugmentation(Attributes2.class, new Attributes2Builder().setMpUnreachNlri(mp.build()).build()).build(), buffer);
+
+ assertArrayEquals(UNREACHED_NLRI_ADD_PATH, ByteArray.readAllBytes(buffer));
+
+ assertEquals("all packets where fragment does match 'IS FIRST' 'IS LAST' 'IS A' AND where flow label equals to 16777222 or equals to 258 ", FS_PARSER.stringNlri(flows));
+ }
+
@Test
public void testExtractFlowspecFragments() {
final DataContainerNodeAttrBuilder<NodeIdentifierWithPredicates, MapEntryNode> entry = Builders.mapEntryBuilder();