use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.NumericOperand in project bgpcep by opendaylight.
the class SimpleFlowspecIpv4NlriParserTest method testExtractFlowspecDscps.
@Test
public void testExtractFlowspecDscps() {
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(AbstractFlowspecNlriParser.DSCP_NID).withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(AbstractFlowspecNlriParser.OP_NID).withChild(Builders.leafBuilder().withNodeIdentifier(AbstractFlowspecNlriParser.OP_NID).withValue(Sets.newHashSet(AbstractOperandParser.AND_BIT_VALUE, AbstractOperandParser.END_OF_LIST_VALUE, AbstractNumericOperandParser.GREATER_THAN_VALUE)).build()).withChild(Builders.leafBuilder().withNodeIdentifier(AbstractFlowspecNlriParser.VALUE_NID).withValue(Uint8.valueOf(15)).build()).build()).build()).build()).build()).build());
final FlowspecBuilder expectedFS = new FlowspecBuilder();
expectedFS.setFlowspecType(new DscpCaseBuilder().setDscps(Lists.newArrayList(new DscpsBuilder().setValue(new Dscp(Uint8.valueOf(15))).setOp(new NumericOperand(true, true, false, true, 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.NumericOperand in project bgpcep by opendaylight.
the class NumericOperandParserTest method testSerializeOneByte.
@Test
public void testSerializeOneByte() {
final ByteBuf nlriByteBuf = Unpooled.buffer();
final List<Codes> codes = new ArrayList<>();
// create 3 ports without end-of-list bit set
for (int i = 0; i < 3; i++) {
codes.add(new CodesBuilder().setOp(new NumericOperand(false, false, true, false, false)).setValue(Uint8.valueOf(100 + i)).build());
}
NumericOneByteOperandParser.INSTANCE.serialize(codes, nlriByteBuf);
assertArrayEquals(ONE_BYTE_CODE_LIST, ByteArray.readAllBytes(nlriByteBuf));
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.NumericOperand in project bgpcep by opendaylight.
the class SimpleFlowspecIpv4NlriParserTest method testExtractFlowspecSourcePorts.
@Test
public void testExtractFlowspecSourcePorts() {
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(AbstractFlowspecNlriParser.SOURCE_PORT_NID).withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(AbstractFlowspecNlriParser.OP_NID).withChild(Builders.leafBuilder().withNodeIdentifier(AbstractFlowspecNlriParser.OP_NID).withValue(Sets.newHashSet(AbstractOperandParser.AND_BIT_VALUE, AbstractOperandParser.END_OF_LIST_VALUE, AbstractNumericOperandParser.EQUALS_VALUE, AbstractNumericOperandParser.GREATER_THAN_VALUE, AbstractNumericOperandParser.LESS_THAN_VALUE)).build()).withChild(Builders.leafBuilder().withNodeIdentifier(AbstractFlowspecNlriParser.VALUE_NID).withValue(Uint16.valueOf(8080)).build()).build()).build()).build()).build()).build());
final FlowspecBuilder expectedFS = new FlowspecBuilder();
expectedFS.setFlowspecType(new SourcePortCaseBuilder().setSourcePorts(Lists.newArrayList(new SourcePortsBuilder().setValue(Uint16.valueOf(8080)).setOp(new NumericOperand(true, true, true, true, true)).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.NumericOperand 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.NumericOperand in project bgpcep by opendaylight.
the class FSIpv6NextHeaderHandler method parseNextHeader.
private static List<NextHeaders> parseNextHeader(final ByteBuf nlri) {
final List<NextHeaders> headers = new ArrayList<>();
boolean end = false;
// we can do this as all fields will be rewritten in the cycle
final NextHeadersBuilder builder = new NextHeadersBuilder();
while (!end) {
final byte b = nlri.readByte();
final NumericOperand op = NumericOneByteOperandParser.INSTANCE.parse(b);
builder.setOp(op);
builder.setValue(ByteBufUtils.readUint8(nlri));
end = op.getEndOfList();
headers.add(builder.build());
}
return headers;
}
Aggregations