use of org.opendaylight.protocol.bgp.flowspec.l3vpn.ipv4.FlowspecL3vpnIpv4NlriParser in project bgpcep by opendaylight.
the class BGPActivator method startImpl.
@Override
protected List<AutoCloseable> startImpl(final BGPExtensionProviderContext context) {
final List<AutoCloseable> regs = new ArrayList<>();
final SimpleFlowspecExtensionProviderContext flowspecContext = this.activator.getContext();
regs.add(context.registerSubsequentAddressFamily(FlowspecSubsequentAddressFamily.class, FLOWSPEC_SAFI));
regs.add(context.registerSubsequentAddressFamily(FlowspecL3vpnSubsequentAddressFamily.class, FLOWSPEC_L3VPN_SAFI));
final Ipv4NextHopParserSerializer ipv4NextHopParser = new Ipv4NextHopParserSerializer();
final Ipv6NextHopParserSerializer ipv6NextHopParser = new Ipv6NextHopParserSerializer();
final SimpleFlowspecIpv4NlriParser fsIpv4Handler = new SimpleFlowspecIpv4NlriParser(flowspecContext.getFlowspecTypeRegistry(SimpleFlowspecExtensionProviderContext.AFI.IPV4, SimpleFlowspecExtensionProviderContext.SAFI.FLOWSPEC));
final SimpleFlowspecIpv6NlriParser fsIpv6Handler = new SimpleFlowspecIpv6NlriParser(flowspecContext.getFlowspecTypeRegistry(SimpleFlowspecExtensionProviderContext.AFI.IPV6, SimpleFlowspecExtensionProviderContext.SAFI.FLOWSPEC));
regs.add(context.registerNlriParser(Ipv4AddressFamily.class, FlowspecSubsequentAddressFamily.class, fsIpv4Handler, ipv4NextHopParser, Ipv4NextHopCase.class));
regs.add(context.registerNlriParser(Ipv6AddressFamily.class, FlowspecSubsequentAddressFamily.class, fsIpv6Handler, ipv6NextHopParser, Ipv6NextHopCase.class));
regs.add(context.registerNlriSerializer(FlowspecRoutes.class, fsIpv4Handler));
regs.add(context.registerNlriSerializer(FlowspecIpv6Routes.class, fsIpv6Handler));
final FlowspecL3vpnIpv4NlriParser fsL3vpnIpv4Handler = new FlowspecL3vpnIpv4NlriParser(flowspecContext.getFlowspecTypeRegistry(SimpleFlowspecExtensionProviderContext.AFI.IPV4, SimpleFlowspecExtensionProviderContext.SAFI.FLOWSPEC_VPN));
final FlowspecL3vpnIpv6NlriParser fsL3vpnIpv6Handler = new FlowspecL3vpnIpv6NlriParser(flowspecContext.getFlowspecTypeRegistry(SimpleFlowspecExtensionProviderContext.AFI.IPV6, SimpleFlowspecExtensionProviderContext.SAFI.FLOWSPEC_VPN));
regs.add(context.registerNlriParser(Ipv4AddressFamily.class, FlowspecL3vpnSubsequentAddressFamily.class, fsL3vpnIpv4Handler, ipv4NextHopParser, Ipv4NextHopCase.class));
regs.add(context.registerNlriParser(Ipv6AddressFamily.class, FlowspecL3vpnSubsequentAddressFamily.class, fsL3vpnIpv6Handler, ipv6NextHopParser, Ipv6NextHopCase.class));
regs.add(context.registerNlriSerializer(FlowspecL3vpnIpv4Routes.class, fsL3vpnIpv4Handler));
regs.add(context.registerNlriSerializer(FlowspecL3vpnIpv6Routes.class, fsL3vpnIpv6Handler));
final RedirectAsTwoOctetEcHandler redirect2bHandler = new RedirectAsTwoOctetEcHandler();
regs.add(context.registerExtendedCommunityParser(redirect2bHandler.getType(true), redirect2bHandler.getSubType(), redirect2bHandler));
regs.add(context.registerExtendedCommunitySerializer(RedirectExtendedCommunityCase.class, redirect2bHandler));
final TrafficActionEcHandler trafficActionHandler = new TrafficActionEcHandler();
regs.add(context.registerExtendedCommunityParser(trafficActionHandler.getType(true), trafficActionHandler.getSubType(), trafficActionHandler));
regs.add(context.registerExtendedCommunitySerializer(TrafficActionExtendedCommunityCase.class, trafficActionHandler));
final TrafficMarkingEcHandler trafficMarkingHandler = new TrafficMarkingEcHandler();
regs.add(context.registerExtendedCommunityParser(trafficMarkingHandler.getType(true), trafficMarkingHandler.getSubType(), trafficMarkingHandler));
regs.add(context.registerExtendedCommunitySerializer(TrafficMarkingExtendedCommunityCase.class, trafficMarkingHandler));
final TrafficRateEcHandler trafficRateEcHandler = new TrafficRateEcHandler();
regs.add(context.registerExtendedCommunityParser(trafficRateEcHandler.getType(true), trafficRateEcHandler.getSubType(), trafficRateEcHandler));
regs.add(context.registerExtendedCommunitySerializer(TrafficRateExtendedCommunityCase.class, trafficRateEcHandler));
final RedirectIpv6EcHandler redirectIpv6EcHandler = new RedirectIpv6EcHandler();
regs.add(context.registerExtendedCommunityParser(redirectIpv6EcHandler.getType(true), redirectIpv6EcHandler.getSubType(), redirectIpv6EcHandler));
regs.add(context.registerExtendedCommunitySerializer(RedirectIpv6ExtendedCommunityCase.class, redirectIpv6EcHandler));
final RedirectAsFourOctetEcHandler redirect4bHandler = new RedirectAsFourOctetEcHandler();
regs.add(context.registerExtendedCommunityParser(redirect4bHandler.getType(true), redirect4bHandler.getSubType(), redirect4bHandler));
regs.add(context.registerExtendedCommunitySerializer(RedirectAs4ExtendedCommunityCase.class, redirect4bHandler));
final RedirectIpv4EcHandler redirectIpv4Handler = new RedirectIpv4EcHandler();
regs.add(context.registerExtendedCommunityParser(redirectIpv4Handler.getType(true), redirectIpv4Handler.getSubType(), redirectIpv4Handler));
regs.add(context.registerExtendedCommunitySerializer(RedirectIpv4ExtendedCommunityCase.class, redirectIpv4Handler));
final RedirectIpNextHopEcHandler redirectIpNhHandler = new RedirectIpNextHopEcHandler();
regs.add(context.registerExtendedCommunityParser(redirectIpNhHandler.getType(true), redirectIpNhHandler.getSubType(), redirectIpNhHandler));
regs.add(context.registerExtendedCommunitySerializer(RedirectIpNhExtendedCommunityCase.class, redirectIpNhHandler));
return regs;
}
use of org.opendaylight.protocol.bgp.flowspec.l3vpn.ipv4.FlowspecL3vpnIpv4NlriParser in project bgpcep by opendaylight.
the class FlowspecL3vpnIpv4NlriParserTest method testParseMpUnreachNlriConstraint.
@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());
final FlowspecL3vpnIpv4NlriParser parser = new FlowspecL3vpnIpv4NlriParser(this.flowspecContext.getFlowspecTypeRegistry(SimpleFlowspecExtensionProviderContext.AFI.IPV4, SimpleFlowspecExtensionProviderContext.SAFI.FLOWSPEC_VPN));
final MpUnreachNlriBuilder result = new MpUnreachNlriBuilder();
result.setAfi(Ipv4AddressFamily.class);
result.setSafi(FlowspecL3vpnSubsequentAddressFamily.class);
parser.parseNlri(Unpooled.wrappedBuffer(UNREACHED_NLRI_ADD_PATH), result, this.constraint);
DestinationFlowspecL3vpnIpv4 flowspecDst = ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationFlowspecL3vpnIpv4Case) result.getWithdrawnRoutes().getDestinationType()).getDestinationFlowspecL3vpnIpv4();
final List<Flowspec> flows = flowspecDst.getFlowspec();
checkUnreachFlows(flows, icmpType, icmpCode, tcp, packet, dscp, fragment);
final RouteDistinguisher rd = flowspecDst.getRouteDistinguisher();
mp.setAfi(Ipv4AddressFamily.class).setWithdrawnRoutes(new WithdrawnRoutesBuilder().setDestinationType(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationFlowspecL3vpnIpv4CaseBuilder().setDestinationFlowspecL3vpnIpv4(new DestinationFlowspecL3vpnIpv4Builder().setRouteDistinguisher(rd).setPathId(PATH_ID).setFlowspec(fs).build()).build()).build());
final ByteBuf buffer = Unpooled.buffer();
parser.serializeNlri(new Object[] { rd, 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_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' ", this.FS_PARSER.stringNlri(flows));
}
use of org.opendaylight.protocol.bgp.flowspec.l3vpn.ipv4.FlowspecL3vpnIpv4NlriParser in project bgpcep by opendaylight.
the class FlowspecL3vpnIpv4NlriParserTest method testParseMpUnreachNlri.
@Test
public void testParseMpUnreachNlri() 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());
final FlowspecL3vpnIpv4NlriParser parser = new FlowspecL3vpnIpv4NlriParser(this.flowspecContext.getFlowspecTypeRegistry(SimpleFlowspecExtensionProviderContext.AFI.IPV4, SimpleFlowspecExtensionProviderContext.SAFI.FLOWSPEC_VPN));
final MpUnreachNlriBuilder result = new MpUnreachNlriBuilder();
result.setAfi(Ipv4AddressFamily.class);
result.setSafi(FlowspecL3vpnSubsequentAddressFamily.class);
parser.parseNlri(Unpooled.wrappedBuffer(UNREACHED_NLRI), result);
DestinationFlowspecL3vpnIpv4 flowspecDst = ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationFlowspecL3vpnIpv4Case) result.getWithdrawnRoutes().getDestinationType()).getDestinationFlowspecL3vpnIpv4();
final List<Flowspec> flows = flowspecDst.getFlowspec();
checkUnreachFlows(flows, icmpType, icmpCode, tcp, packet, dscp, fragment);
final RouteDistinguisher rd = flowspecDst.getRouteDistinguisher();
mp.setAfi(Ipv4AddressFamily.class).setWithdrawnRoutes(new WithdrawnRoutesBuilder().setDestinationType(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationFlowspecL3vpnIpv4CaseBuilder().setDestinationFlowspecL3vpnIpv4(new DestinationFlowspecL3vpnIpv4Builder().setRouteDistinguisher(rd).setFlowspec(fs).build()).build()).build());
final ByteBuf buffer = Unpooled.buffer();
parser.serializeNlri(new Object[] { rd, 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' ", this.FS_PARSER.stringNlri(flows));
}
use of org.opendaylight.protocol.bgp.flowspec.l3vpn.ipv4.FlowspecL3vpnIpv4NlriParser in project bgpcep by opendaylight.
the class FlowspecL3vpnIpv4NlriParserTest method testParseMpReachNlriConstraint.
@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());
final FlowspecL3vpnIpv4NlriParser parser = new FlowspecL3vpnIpv4NlriParser(this.flowspecContext.getFlowspecTypeRegistry(SimpleFlowspecExtensionProviderContext.AFI.IPV4, SimpleFlowspecExtensionProviderContext.SAFI.FLOWSPEC_VPN));
final MpReachNlriBuilder result = new MpReachNlriBuilder();
result.setAfi(Ipv4AddressFamily.class);
result.setSafi(FlowspecL3vpnSubsequentAddressFamily.class);
parser.parseNlri(Unpooled.wrappedBuffer(REACHED_NLRI_ADD_PATH), result, this.constraint);
final DestinationFlowspecL3vpnIpv4 flowspecDst = ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationFlowspecL3vpnIpv4Case) result.getAdvertizedRoutes().getDestinationType()).getDestinationFlowspecL3vpnIpv4();
final List<Flowspec> flows = flowspecDst.getFlowspec();
final RouteDistinguisher rd = flowspecDst.getRouteDistinguisher();
testFlows(flows, destinationPrefix, sourcePrefix, prots, rd, ps, dps, sps);
mp.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationFlowspecL3vpnIpv4CaseBuilder().setDestinationFlowspecL3vpnIpv4(new DestinationFlowspecL3vpnIpv4Builder().setRouteDistinguisher(rd).setPathId(PATH_ID).setFlowspec(fs).build()).build()).build());
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_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 ", this.FS_PARSER.stringNlri(flows));
}
use of org.opendaylight.protocol.bgp.flowspec.l3vpn.ipv4.FlowspecL3vpnIpv4NlriParser in project bgpcep by opendaylight.
the class FlowspecL3vpnIpv4NlriParserTest method testParseMpReachNlri.
@Test
public void testParseMpReachNlri() 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());
final FlowspecL3vpnIpv4NlriParser parser = new FlowspecL3vpnIpv4NlriParser(this.flowspecContext.getFlowspecTypeRegistry(SimpleFlowspecExtensionProviderContext.AFI.IPV4, SimpleFlowspecExtensionProviderContext.SAFI.FLOWSPEC_VPN));
final MpReachNlriBuilder result = new MpReachNlriBuilder();
result.setAfi(Ipv4AddressFamily.class);
result.setSafi(FlowspecL3vpnSubsequentAddressFamily.class);
parser.parseNlri(Unpooled.wrappedBuffer(REACHED_NLRI), result);
final DestinationFlowspecL3vpnIpv4 flowspecDst = ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationFlowspecL3vpnIpv4Case) result.getAdvertizedRoutes().getDestinationType()).getDestinationFlowspecL3vpnIpv4();
final List<Flowspec> flows = flowspecDst.getFlowspec();
final RouteDistinguisher rd = flowspecDst.getRouteDistinguisher();
testFlows(flows, destinationPrefix, sourcePrefix, prots, rd, ps, dps, sps);
mp.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationFlowspecL3vpnIpv4CaseBuilder().setDestinationFlowspecL3vpnIpv4(new DestinationFlowspecL3vpnIpv4Builder().setRouteDistinguisher(rd).setFlowspec(fs).build()).build()).build());
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 ", this.FS_PARSER.stringNlri(flows));
}
Aggregations