use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.group.ipv6.flowspec.flowspec.type.flow.label._case.FlowLabelBuilder in project bgpcep by opendaylight.
the class FSIpv6FlowLabelHandler method parseFlowLabel.
private static List<FlowLabel> parseFlowLabel(final ByteBuf nlri) {
final List<FlowLabel> labels = new ArrayList<>();
boolean end = false;
// we can do this as all fields will be rewritten in the cycle
final FlowLabelBuilder builder = new FlowLabelBuilder();
while (!end) {
final byte b = nlri.readByte();
final NumericOperand op = NumericOneByteOperandParser.INSTANCE.parse(b);
builder.setOp(op);
final short length = AbstractOperandParser.parseLength(b);
builder.setValue(Uint32.valueOf(ByteArray.bytesToLong(ByteArray.readBytes(nlri, length))));
end = op.getEndOfList();
labels.add(builder.build());
}
return labels;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.group.ipv6.flowspec.flowspec.type.flow.label._case.FlowLabelBuilder in project bgpcep by opendaylight.
the class SimpleFlowspecIpv6NlriParserTest method testExtractFlowspecFlowLabels.
@Test
public void testExtractFlowspecFlowLabels() {
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(FLOW_LABEL_NID).withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(FLOW_LABEL_NID).withChild(Builders.leafBuilder().withNodeIdentifier(AbstractFlowspecNlriParser.OP_NID).withValue(Sets.newHashSet(AbstractOperandParser.END_OF_LIST_VALUE, AbstractOperandParser.AND_BIT_VALUE)).build()).withChild(Builders.leafBuilder().withNodeIdentifier(AbstractFlowspecNlriParser.VALUE_NID).withValue(Uint32.valueOf(100)).build()).build()).withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(FLOW_LABEL_NID).withChild(Builders.leafBuilder().withNodeIdentifier(AbstractFlowspecNlriParser.OP_NID).withValue(Sets.newHashSet(AbstractOperandParser.AND_BIT_VALUE)).build()).withChild(Builders.leafBuilder().withNodeIdentifier(AbstractFlowspecNlriParser.VALUE_NID).withValue(Uint32.valueOf(200)).build()).build()).build()).build()).build()).build());
final FlowspecBuilder expectedFS = new FlowspecBuilder();
expectedFS.setFlowspecType(new FlowLabelCaseBuilder().setFlowLabel(Lists.newArrayList(new FlowLabelBuilder().setValue(Uint32.valueOf(100)).setOp(new NumericOperand(true, true, false, false, false)).build(), new FlowLabelBuilder().setValue(Uint32.valueOf(200)).setOp(new NumericOperand(true, false, false, false, false)).build())).build());
final List<Flowspec> expectedValue = new ArrayList<>();
expectedValue.add(expectedFS.build());
assertEquals(expectedValue, this.fsParser.extractFlowspec(entry.build()));
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.group.ipv6.flowspec.flowspec.type.flow.label._case.FlowLabelBuilder in project bgpcep by opendaylight.
the class FlowspecL3vpnIpv6NlriParserTest method testExtractFlowspecFlowLabels.
@Test
public void testExtractFlowspecFlowLabels() {
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(FLOW_LABEL_NID).withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(FLOW_LABEL_NID).withChild(Builders.leafBuilder().withNodeIdentifier(FlowspecL3vpnIpv6NlriParser.OP_NID).withValue(Sets.newHashSet(AbstractOperandParser.END_OF_LIST_VALUE, AbstractOperandParser.AND_BIT_VALUE)).build()).withChild(Builders.leafBuilder().withNodeIdentifier(FlowspecL3vpnIpv6NlriParser.VALUE_NID).withValue(Uint32.valueOf(100)).build()).build()).withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(FLOW_LABEL_NID).withChild(Builders.leafBuilder().withNodeIdentifier(FlowspecL3vpnIpv6NlriParser.OP_NID).withValue(Sets.newHashSet(AbstractOperandParser.AND_BIT_VALUE)).build()).withChild(Builders.leafBuilder().withNodeIdentifier(FlowspecL3vpnIpv6NlriParser.VALUE_NID).withValue(Uint32.valueOf(200)).build()).build()).build()).build()).build()).build());
final FlowspecBuilder expectedFS = new FlowspecBuilder();
expectedFS.setFlowspecType(new FlowLabelCaseBuilder().setFlowLabel(Lists.newArrayList(new FlowLabelBuilder().setValue(Uint32.valueOf(100)).setOp(new NumericOperand(true, true, false, false, false)).build(), new FlowLabelBuilder().setValue(Uint32.valueOf(200)).setOp(new NumericOperand(true, false, false, false, false)).build())).build());
final List<Flowspec> expectedValue = new ArrayList<>();
expectedValue.add(expectedFS.build());
assertEquals(expectedValue, this.fsParser.extractFlowspec(entry.build()));
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.group.ipv6.flowspec.flowspec.type.flow.label._case.FlowLabelBuilder in project bgpcep by opendaylight.
the class FlowspecIpv6NlriParserHelper method createFlowLabels.
private static List<FlowLabel> createFlowLabels(final UnkeyedListNode flowLabelsData) {
final List<FlowLabel> flowLabels = new ArrayList<>();
for (final UnkeyedListEntryNode node : flowLabelsData.body()) {
final FlowLabelBuilder flowLabelsBuilder = new FlowLabelBuilder();
node.findChildByArg(AbstractFlowspecNlriParser.OP_NID).ifPresent(dataContainerChild -> flowLabelsBuilder.setOp(NumericOneByteOperandParser.INSTANCE.create((Set<String>) dataContainerChild.body())));
node.findChildByArg(AbstractFlowspecNlriParser.VALUE_NID).ifPresent(dataContainerChild -> flowLabelsBuilder.setValue((Uint32) dataContainerChild.body()));
flowLabels.add(flowLabelsBuilder.build());
}
return flowLabels;
}
Aggregations