use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.flowspec.destination.FlowspecBuilder in project bgpcep by opendaylight.
the class AbstractFlowspecNlriParser method parseNlriFlowspecList.
/**
* Parses Flowspec NLRI into list of Flowspec.
*
* @param nlri byte representation of NLRI which will be parsed
* @return list of Flowspec
*/
protected final List<Flowspec> parseNlriFlowspecList(@Nonnull final ByteBuf nlri) throws BGPParsingException {
if (!nlri.isReadable()) {
return null;
}
final List<Flowspec> fss = new ArrayList<>();
while (nlri.isReadable()) {
int nlriLength = readNlriLength(nlri);
Preconditions.checkState(nlriLength > 0 && nlriLength <= nlri.readableBytes(), "Invalid flowspec NLRI length %s", nlriLength);
LOG.trace("Flowspec NLRI length is {}", nlriLength);
while (nlriLength > 0) {
final int readableLength = nlri.readableBytes();
final FlowspecBuilder builder = new FlowspecBuilder();
builder.setFlowspecType(this.flowspecTypeRegistry.parseFlowspecType(nlri));
fss.add(builder.build());
final int flowspecTypeLength = readableLength - nlri.readableBytes();
nlriLength -= flowspecTypeLength;
}
Preconditions.checkState(nlriLength == 0, "Remain NLRI length should be 0 instead of %s", nlriLength);
}
return fss;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.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.rev171207.flowspec.destination.FlowspecBuilder in project bgpcep by opendaylight.
the class FlowspecL3vpnIpv6NlriParserTest method testExtractFlowspecSourcePrefix.
@Test
public void testExtractFlowspecSourcePrefix() {
final DataContainerNodeAttrBuilder<NodeIdentifierWithPredicates, MapEntryNode> entry = Builders.mapEntryBuilder();
entry.withNodeIdentifier(new NodeIdentifierWithPredicates(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(SimpleFlowspecIpv4NlriParser.SOURCE_PREFIX_NID).withValue("102:304:600::/40").build()).build()).build()).build());
final FlowspecBuilder expectedFS = new FlowspecBuilder();
expectedFS.setFlowspecType(new SourceIpv6PrefixCaseBuilder().setSourcePrefix(new Ipv6Prefix("102:304:600::/40")).build());
final List<Flowspec> expectedValue = new ArrayList<>();
expectedValue.add(expectedFS.build());
assertEquals(expectedValue, this.FS_PARSER.extractFlowspec(entry.build()));
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.flowspec.destination.FlowspecBuilder in project bgpcep by opendaylight.
the class FlowspecL3vpnIpv6NlriParserTest 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 FragmentCase fragment = createFragment();
builder.setFlowspecType(fragment);
fs.add(builder.build());
final FlowspecType label = createLabel();
builder.setFlowspecType(label);
fs.add(builder.build());
final MpUnreachNlriBuilder result = new MpUnreachNlriBuilder();
result.setAfi(Ipv6AddressFamily.class);
result.setSafi(FlowspecL3vpnSubsequentAddressFamily.class);
this.FS_PARSER.parseNlri(Unpooled.wrappedBuffer(UNREACHED_NLRI), result);
final DestinationFlowspecL3vpnIpv6 flowspecDst = ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationFlowspecL3vpnIpv6Case) result.getWithdrawnRoutes().getDestinationType()).getDestinationFlowspecL3vpnIpv6();
final List<Flowspec> flows = flowspecDst.getFlowspec();
final RouteDistinguisher rd = flowspecDst.getRouteDistinguisher();
assertEquals(2, flows.size());
assertEquals(ROUTE_DISTINGUISHER, new String(rd.getValue()));
assertEquals(fragment, flows.get(0).getFlowspecType());
assertEquals(label, flows.get(1).getFlowspecType());
mp.setAfi(Ipv6AddressFamily.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.DestinationFlowspecL3vpnIpv6CaseBuilder().setDestinationFlowspecL3vpnIpv6(new DestinationFlowspecL3vpnIpv6Builder().setRouteDistinguisher(rd).setFlowspec(fs).build()).build()).build());
final ByteBuf buffer = Unpooled.buffer();
this.FS_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 fragment does match 'IS FIRST' 'IS LAST' 'IS A' AND where flow label equals to 16777222 or equals to 258 ", this.FS_PARSER.stringNlri(flows));
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.flowspec.destination.FlowspecBuilder in project bgpcep by opendaylight.
the class FlowspecL3vpnIpv6NlriParserTest method testExtractFlowspecFragments.
@Test
public void testExtractFlowspecFragments() {
final DataContainerNodeAttrBuilder<NodeIdentifierWithPredicates, MapEntryNode> entry = Builders.mapEntryBuilder();
entry.withNodeIdentifier(new NodeIdentifierWithPredicates(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(AbstractFlowspecNlriParser.FRAGMENT_NID).withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(FlowspecL3vpnIpv6NlriParser.OP_NID).withChild(Builders.leafBuilder().withNodeIdentifier(FlowspecL3vpnIpv6NlriParser.OP_NID).withValue(Sets.newHashSet(AbstractOperandParser.AND_BIT_VALUE, AbstractOperandParser.END_OF_LIST_VALUE, BitmaskOperandParser.MATCH_VALUE, BitmaskOperandParser.NOT_VALUE)).build()).withChild(Builders.leafBuilder().withNodeIdentifier(FlowspecL3vpnIpv6NlriParser.VALUE_NID).withValue(Sets.newHashSet(AbstractFlowspecNlriParser.DO_NOT_VALUE, AbstractFlowspecNlriParser.FIRST_VALUE, AbstractFlowspecNlriParser.IS_A_VALUE, AbstractFlowspecNlriParser.LAST_VALUE)).build()).build()).build()).build()).build()).build());
final FlowspecBuilder expectedFS = new FlowspecBuilder();
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());
final List<Flowspec> expectedValue = new ArrayList<>();
expectedValue.add(expectedFS.build());
assertEquals(expectedValue, this.FS_PARSER.extractFlowspec(entry.build()));
}
Aggregations