use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.FlowspecBuilder in project bgpcep by opendaylight.
the class AbstractFlowspecNlriParser method extractFlowspec.
public final List<Flowspec> extractFlowspec(final DataContainerNode<?> route) {
requireNonNull(route, "Cannot extract flowspec from null route.");
final List<Flowspec> fsList = new ArrayList<>();
final Optional<DataContainerChild<? extends PathArgument, ?>> flowspecs = route.getChild(FLOWSPEC_NID);
if (flowspecs.isPresent()) {
for (final UnkeyedListEntryNode flowspec : ((UnkeyedListNode) flowspecs.get()).getValue()) {
final FlowspecBuilder fsBuilder = new FlowspecBuilder();
final Optional<DataContainerChild<?, ?>> flowspecType = flowspec.getChild(FLOWSPEC_TYPE_NID);
if (flowspecType.isPresent()) {
final ChoiceNode fsType = (ChoiceNode) flowspecType.get();
processFlowspecType(fsType, fsBuilder);
}
fsList.add(fsBuilder.build());
}
}
return fsList;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.FlowspecBuilder 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(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.rev200120.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.rev200120.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(new AttributesUnreachBuilder().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.fsParser.stringNlri(flows));
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.FlowspecBuilder in project bgpcep by opendaylight.
the class FlowspecL3vpnIpv4NlriParserTest method testExtractFlowspecProtocolIps.
@Test
public void testExtractFlowspecProtocolIps() {
final DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> entry = Builders.mapEntryBuilder();
entry.withNodeIdentifier(NodeIdentifierWithPredicates.of(FlowspecRoute.QNAME, FlowspecRoute.QNAME, entry));
entry.withChild(Builders.unkeyedListBuilder().withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_NID).withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_NID).withChild(Builders.choiceBuilder().withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_TYPE_NID).withChild(Builders.unkeyedListBuilder().withNodeIdentifier(PROTOCOL_IP_NID).withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(PROTOCOL_IP_NID).withChild(Builders.leafBuilder().withNodeIdentifier(FlowspecL3vpnIpv4NlriParser.OP_NID).withValue(Sets.newHashSet(AbstractOperandParser.END_OF_LIST_VALUE, AbstractOperandParser.AND_BIT_VALUE)).build()).withChild(Builders.leafBuilder().withNodeIdentifier(FlowspecL3vpnIpv4NlriParser.VALUE_NID).withValue(Uint8.valueOf(100)).build()).build()).withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(PROTOCOL_IP_NID).withChild(Builders.leafBuilder().withNodeIdentifier(FlowspecL3vpnIpv4NlriParser.OP_NID).withValue(Sets.newHashSet(AbstractOperandParser.AND_BIT_VALUE)).build()).withChild(Builders.leafBuilder().withNodeIdentifier(FlowspecL3vpnIpv4NlriParser.VALUE_NID).withValue(Uint8.valueOf(200)).build()).build()).withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(PROTOCOL_IP_NID).withChild(Builders.leafBuilder().withNodeIdentifier(FlowspecL3vpnIpv4NlriParser.OP_NID).withValue(Sets.newHashSet(AbstractOperandParser.END_OF_LIST_VALUE, AbstractOperandParser.AND_BIT_VALUE, AbstractNumericOperandParser.EQUALS_VALUE)).build()).withChild(Builders.leafBuilder().withNodeIdentifier(FlowspecL3vpnIpv4NlriParser.VALUE_NID).withValue(Uint8.valueOf(240)).build()).build()).build()).build()).build()).build());
final FlowspecBuilder expectedFS = new FlowspecBuilder().setFlowspecType(new ProtocolIpCaseBuilder().setProtocolIps(Lists.newArrayList(new ProtocolIpsBuilder().setValue(Uint8.valueOf(100)).setOp(new NumericOperand(true, true, false, false, false)).build(), new ProtocolIpsBuilder().setValue(Uint8.valueOf(200)).setOp(new NumericOperand(true, false, false, false, false)).build(), new ProtocolIpsBuilder().setValue(Uint8.valueOf(240)).setOp(new NumericOperand(true, true, true, false, false)).build())).build());
final List<Flowspec> expected = new ArrayList<>();
expected.add(expectedFS.build());
assertEquals(expected, this.fsParser.extractFlowspec(entry.build()));
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.FlowspecBuilder 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(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.rev200120.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.rev200120.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(new AttributesReachBuilder().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.fsParser.stringNlri(flows));
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.FlowspecBuilder in project bgpcep by opendaylight.
the class FlowspecL3vpnIpv4NlriParserTest method testExtractFlowspecSourcePrefix.
@Test
public void testExtractFlowspecSourcePrefix() {
final DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> entry = Builders.mapEntryBuilder();
entry.withNodeIdentifier(NodeIdentifierWithPredicates.of(FlowspecRoute.QNAME, FlowspecRoute.QNAME, entry));
entry.withChild(Builders.unkeyedListBuilder().withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_NID).withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_NID).withChild(Builders.choiceBuilder().withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_TYPE_NID).withChild(Builders.leafBuilder().withNodeIdentifier(AbstractFlowspecNlriParser.SOURCE_PREFIX_NID).withValue("127.0.0.6/32").build()).build()).build()).build());
final FlowspecBuilder expectedFS = new FlowspecBuilder();
expectedFS.setFlowspecType(new SourcePrefixCaseBuilder().setSourcePrefix(new Ipv4Prefix("127.0.0.6/32")).build());
final List<Flowspec> expected = new ArrayList<>();
expected.add(expectedFS.build());
assertEquals(expected, this.fsParser.extractFlowspec(entry.build()));
}
Aggregations