From 8e84a69882a6af1dc7409e85d9bd3da87a25355c Mon Sep 17 00:00:00 2001 From: Jeff Liu Date: Mon, 16 Nov 2015 16:16:04 -0800 Subject: [PATCH] BUG-4175 component registry in BGP FS Add flowspec registry that allows registration of component and its handlers Change-Id: I9098f809dd9d7add2323415b9673ca2bec16182c Signed-off-by: Jeff Liu --- .../yang/bgp/flowspec/FlowspecModule.java | 9 +- ...r.java => AbstractFlowspecNlriParser.java} | 347 +++--------------- .../flowspec/AbstractFlowspecRIBSupport.java | 4 +- .../protocol/bgp/flowspec/BGPActivator.java | 23 +- .../flowspec/FSDestinationPortHandler.java | 56 +++ .../protocol/bgp/flowspec/FSDscpHandler.java | 62 ++++ .../bgp/flowspec/FSIcmpCodeHandler.java | 55 +++ .../bgp/flowspec/FSIcmpTypeHandler.java | 54 +++ .../bgp/flowspec/FSIpProtocolHandler.java | 54 +++ .../bgp/flowspec/FSIpv6FlowLabelHandler.java | 65 ++++ .../bgp/flowspec/FSIpv6NextHeaderHandler.java | 56 +++ .../bgp/flowspec/FSPacketLengthHandler.java | 56 +++ .../protocol/bgp/flowspec/FSPortHandler.java | 59 +++ .../bgp/flowspec/FSSourcePortHandler.java | 56 +++ .../bgp/flowspec/FSTcpFlagsHandler.java | 66 ++++ .../bgp/flowspec/FlowspecActivator.java | 180 +++++++++ .../bgp/flowspec/FlowspecIpv4RIBSupport.java | 13 +- .../bgp/flowspec/FlowspecIpv6RIBSupport.java | 13 +- .../protocol/bgp/flowspec/RIBActivator.java | 14 +- ...impleFlowspecExtensionProviderContext.java | 44 +++ ...java => SimpleFlowspecIpv4NlriParser.java} | 125 ++----- ...java => SimpleFlowspecIpv6NlriParser.java} | 177 ++------- .../flowspec/SimpleFlowspecTypeRegistry.java | 54 +++ .../handlers/AbstractFSFragmentHandler.java | 74 ++++ .../FSIpv4DestinationPrefixHandler.java | 34 ++ .../handlers/FSIpv4FragmentHandler.java | 30 ++ .../handlers/FSIpv4SourcePrefixHandler.java | 34 ++ .../FSIpv6DestinationPrefixHandler.java | 48 +++ .../handlers/FSIpv6FragmentHandler.java | 30 ++ .../handlers/FSIpv6SourcePrefixHandler.java | 48 +++ .../bgp/flowspec/handlers/FlowspecParser.java | 15 + .../flowspec/handlers/FlowspecSerializer.java | 15 + .../flowspec/handlers/FlowspecTypeParser.java | 15 + .../handlers/FlowspecTypeSerializer.java | 15 + .../protocol/bgp/flowspec/ActivatorTest.java | 4 +- ... => SimpleFlowspecIpv4NlriParserTest.java} | 191 +++++----- ... => SimpleFlowspecIpv6NlriParserTest.java} | 85 ++--- .../FSExtendedCommunitiesTest.java | 7 +- 38 files changed, 1566 insertions(+), 721 deletions(-) rename bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/{AbstractFSNlriParser.java => AbstractFlowspecNlriParser.java} (70%) create mode 100644 bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/FSDestinationPortHandler.java create mode 100644 bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/FSDscpHandler.java create mode 100644 bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/FSIcmpCodeHandler.java create mode 100644 bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/FSIcmpTypeHandler.java create mode 100644 bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/FSIpProtocolHandler.java create mode 100644 bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/FSIpv6FlowLabelHandler.java create mode 100644 bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/FSIpv6NextHeaderHandler.java create mode 100644 bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/FSPacketLengthHandler.java create mode 100644 bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/FSPortHandler.java create mode 100644 bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/FSSourcePortHandler.java create mode 100644 bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/FSTcpFlagsHandler.java create mode 100644 bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/FlowspecActivator.java create mode 100644 bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/SimpleFlowspecExtensionProviderContext.java rename bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/{FSIpv4NlriParser.java => SimpleFlowspecIpv4NlriParser.java} (65%) rename bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/{FSIpv6NlriParser.java => SimpleFlowspecIpv6NlriParser.java} (60%) create mode 100644 bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/SimpleFlowspecTypeRegistry.java create mode 100644 bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/handlers/AbstractFSFragmentHandler.java create mode 100644 bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/handlers/FSIpv4DestinationPrefixHandler.java create mode 100644 bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/handlers/FSIpv4FragmentHandler.java create mode 100644 bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/handlers/FSIpv4SourcePrefixHandler.java create mode 100644 bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/handlers/FSIpv6DestinationPrefixHandler.java create mode 100644 bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/handlers/FSIpv6FragmentHandler.java create mode 100644 bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/handlers/FSIpv6SourcePrefixHandler.java create mode 100644 bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/handlers/FlowspecParser.java create mode 100644 bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/handlers/FlowspecSerializer.java create mode 100644 bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/handlers/FlowspecTypeParser.java create mode 100644 bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/handlers/FlowspecTypeSerializer.java rename bgp/flowspec/src/test/java/org/opendaylight/protocol/bgp/flowspec/{FSIpv4NlriParserTest.java => SimpleFlowspecIpv4NlriParserTest.java} (79%) rename bgp/flowspec/src/test/java/org/opendaylight/protocol/bgp/flowspec/{FSIpv6NlriParserTest.java => SimpleFlowspecIpv6NlriParserTest.java} (81%) diff --git a/bgp/flowspec/src/main/java/org/opendaylight/controller/config/yang/bgp/flowspec/FlowspecModule.java b/bgp/flowspec/src/main/java/org/opendaylight/controller/config/yang/bgp/flowspec/FlowspecModule.java index 871cf05c8d..0b4bd3ef46 100644 --- a/bgp/flowspec/src/main/java/org/opendaylight/controller/config/yang/bgp/flowspec/FlowspecModule.java +++ b/bgp/flowspec/src/main/java/org/opendaylight/controller/config/yang/bgp/flowspec/FlowspecModule.java @@ -8,7 +8,9 @@ package org.opendaylight.controller.config.yang.bgp.flowspec; import org.opendaylight.protocol.bgp.flowspec.BGPActivator; +import org.opendaylight.protocol.bgp.flowspec.FlowspecActivator; import org.opendaylight.protocol.bgp.flowspec.RIBActivator; +import org.opendaylight.protocol.bgp.flowspec.SimpleFlowspecExtensionProviderContext; import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionProviderActivator; import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionProviderContext; import org.opendaylight.protocol.bgp.rib.spi.RIBExtensionProviderActivator; @@ -31,8 +33,10 @@ public class FlowspecModule extends org.opendaylight.controller.config.yang.bgp. @Override public java.lang.AutoCloseable createInstance() { final class FlowspecExtension implements AutoCloseable, BGPExtensionProviderActivator, RIBExtensionProviderActivator { - private final BGPExtensionProviderActivator bgpact = new BGPActivator(); - private final RIBExtensionProviderActivator ribact = new RIBActivator(); + private final SimpleFlowspecExtensionProviderContext flowspecContext = new SimpleFlowspecExtensionProviderContext(); + private final FlowspecActivator fsActivator = new FlowspecActivator(flowspecContext); + private final BGPActivator bgpact = new BGPActivator(flowspecContext, fsActivator); + private final RIBExtensionProviderActivator ribact = new RIBActivator(flowspecContext); @Override public void close() { @@ -62,6 +66,7 @@ public class FlowspecModule extends org.opendaylight.controller.config.yang.bgp. @Override public void stop() { this.bgpact.stop(); + this.fsActivator.close(); } } return new FlowspecExtension(); diff --git a/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/AbstractFSNlriParser.java b/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/AbstractFlowspecNlriParser.java similarity index 70% rename from bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/AbstractFSNlriParser.java rename to bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/AbstractFlowspecNlriParser.java index 858cc34a44..41ae43c32d 100644 --- a/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/AbstractFSNlriParser.java +++ b/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/AbstractFlowspecNlriParser.java @@ -21,11 +21,8 @@ import java.util.Set; import org.opendaylight.protocol.bgp.parser.BGPParsingException; import org.opendaylight.protocol.bgp.parser.spi.NlriParser; import org.opendaylight.protocol.bgp.parser.spi.NlriSerializer; -import org.opendaylight.protocol.util.ByteArray; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.BitmaskOperand; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.Dscp; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.Fragment; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.NumericOperand; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.Flowspec; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.FlowspecBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.FlowspecType; @@ -82,23 +79,11 @@ import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgum import org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode; import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild; import org.opendaylight.yangtools.yang.data.api.schema.DataContainerNode; +import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode; import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListEntryNode; import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListNode; -public abstract class AbstractFSNlriParser implements NlriParser, NlriSerializer { - - // component types values - protected static final int DESTINATION_PREFIX_VALUE = 1; - protected static final int SOURCE_PREFIX_VALUE = 2; - protected static final int PORT_VALUE = 4; - protected static final int DESTINATION_PORT_VALUE = 5; - protected static final int SOURCE_PORT_VALUE = 6; - protected static final int ICMP_TYPE_VALUE = 7; - protected static final int ICMP_CODE_VALUE = 8; - protected static final int TCP_FLAGS_VALUE = 9; - protected static final int PACKET_LENGTH_VALUE = 10; - protected static final int DSCP_VALUE = 11; - protected static final int FRAGMENT_VALUE = 12; +public abstract class AbstractFlowspecNlriParser implements NlriParser, NlriSerializer { @VisibleForTesting static final NodeIdentifier FLOWSPEC_NID = new NodeIdentifier(Flowspec.QNAME); @@ -134,6 +119,8 @@ public abstract class AbstractFSNlriParser implements NlriParser, NlriSerializer protected static final int NLRI_LENGTH = 1; protected static final int NLRI_LENGTH_EXTENDED = 2; + protected SimpleFlowspecTypeRegistry flowspecTypeRegistry; + /** * Add this constant to length value to achieve all ones in the leftmost nibble. */ @@ -150,32 +137,19 @@ public abstract class AbstractFSNlriParser implements NlriParser, NlriSerializer @VisibleForTesting static final String IS_A_VALUE = "is-a"; - protected static final int LAST_FRAGMENT = 4; - protected static final int FIRST_FRAGMENT = 5; - protected static final int IS_A_FRAGMENT = 6; - protected static final int DONT_FRAGMENT = 7; - private static final String FLOW_SEPARATOR = " AND "; protected abstract void serializeMpReachNlri(final Attributes1 pathAttributes, final ByteBuf byteAggregator); protected abstract void serializeMpUnreachNlri(final Attributes2 pathAttributes, final ByteBuf byteAggregator); - protected abstract void serializeSpecificFSType(final FlowspecType fsType, final ByteBuf nlriByteBuf); - - protected abstract byte serializeFragment(final Fragment fragment); - - protected abstract Fragment parseFragment(final byte fragment); - - protected abstract void setSpecificFlowspecType(final FlowspecBuilder builder, final short type, final ByteBuf nlri); - public abstract void extractSpecificFlowspec(final ChoiceNode fsType, final FlowspecBuilder fsBuilder); - abstract DestinationType createWidthdrawnDestinationType(final List dst); + protected abstract void stringSpecificFSNlriType(final FlowspecType value, final StringBuilder buffer); - abstract DestinationType createAdvertizedRoutesDestinationType(final List dst); + abstract DestinationType createWithdrawnDestinationType(final List dst); - protected abstract void stringSpecificFSNlriType(final FlowspecType value, final StringBuilder buffer); + abstract DestinationType createAdvertizedRoutesDestinationType(final List dst); @Override public final void serializeAttribute(final DataObject attribute, final ByteBuf byteAggregator) { @@ -194,7 +168,7 @@ public abstract class AbstractFSNlriParser implements NlriParser, NlriSerializer } final List dst = parseNlri(nlri); - builder.setWithdrawnRoutes(new WithdrawnRoutesBuilder().setDestinationType(createWidthdrawnDestinationType(dst)).build()); + builder.setWithdrawnRoutes(new WithdrawnRoutesBuilder().setDestinationType(createWithdrawnDestinationType(dst)).build()); } @Override @@ -215,7 +189,7 @@ public abstract class AbstractFSNlriParser implements NlriParser, NlriSerializer public final void serializeNlri(final List flows, final ByteBuf buffer) { final ByteBuf nlriByteBuf = Unpooled.buffer(); for (final Flowspec flow : flows) { - serializeFlowspec(flow, nlriByteBuf); + this.flowspecTypeRegistry.serializeFlowspecType(flow.getFlowspecType(), nlriByteBuf); } Preconditions.checkState(nlriByteBuf.readableBytes() <= MAX_NLRI_LENGTH, "Maximum length of Flowspec NLRI reached."); if (nlriByteBuf.readableBytes() <= MAX_NLRI_LENGTH_ONE_BYTE) { @@ -226,271 +200,8 @@ public abstract class AbstractFSNlriParser implements NlriParser, NlriSerializer buffer.writeBytes(nlriByteBuf); } - protected static final void serializeTcpFlags(final List flags, final ByteBuf nlriByteBuf) { - for (final TcpFlags flag : flags) { - final ByteBuf flagsBuf = Unpooled.buffer(); - Util.writeShortest(flag.getValue(), flagsBuf); - BitmaskOperandParser.INSTANCE.serialize(flag.getOp(), flagsBuf.readableBytes(), nlriByteBuf); - nlriByteBuf.writeBytes(flagsBuf); - } - } - - protected static final void serializeDscps(final List dscps, final ByteBuf nlriByteBuf) { - for (final Dscps dscp : dscps) { - NumericOneByteOperandParser.INSTANCE.serialize(dscp.getOp(), 1, nlriByteBuf); - Util.writeShortest(dscp.getValue().getValue(), nlriByteBuf); - } - } - - protected final void serializeFragments(final List fragments, final ByteBuf nlriByteBuf) { - for (final Fragments fragment : fragments) { - BitmaskOperandParser.INSTANCE.serialize(fragment.getOp(), 1, nlriByteBuf); - nlriByteBuf.writeByte(serializeFragment(fragment.getValue())); - } - } - - protected final void serializeFlowspec(final Flowspec flow, final ByteBuf nlriByteBuf) { - final FlowspecType fsType = flow.getFlowspecType(); - if (fsType instanceof PortCase) { - nlriByteBuf.writeByte(PORT_VALUE); - NumericTwoByteOperandParser.INSTANCE.serialize(((PortCase) fsType).getPorts(), nlriByteBuf); - } else if (fsType instanceof DestinationPortCase) { - nlriByteBuf.writeByte(DESTINATION_PORT_VALUE); - NumericTwoByteOperandParser.INSTANCE.serialize(((DestinationPortCase) fsType).getDestinationPorts(), nlriByteBuf); - } else if (fsType instanceof SourcePortCase) { - nlriByteBuf.writeByte(SOURCE_PORT_VALUE); - NumericTwoByteOperandParser.INSTANCE.serialize(((SourcePortCase) fsType).getSourcePorts(), nlriByteBuf); - } else if (fsType instanceof IcmpTypeCase) { - nlriByteBuf.writeByte(ICMP_TYPE_VALUE); - NumericOneByteOperandParser.INSTANCE.serialize(((IcmpTypeCase) fsType).getTypes(), nlriByteBuf); - } else if (fsType instanceof IcmpCodeCase) { - nlriByteBuf.writeByte(ICMP_CODE_VALUE); - NumericOneByteOperandParser.INSTANCE.serialize(((IcmpCodeCase) fsType).getCodes(), nlriByteBuf); - } else if (fsType instanceof TcpFlagsCase) { - nlriByteBuf.writeByte(TCP_FLAGS_VALUE); - serializeTcpFlags(((TcpFlagsCase) fsType).getTcpFlags(), nlriByteBuf); - } else if (fsType instanceof PacketLengthCase) { - nlriByteBuf.writeByte(PACKET_LENGTH_VALUE); - NumericTwoByteOperandParser.INSTANCE.serialize(((PacketLengthCase) fsType).getPacketLengths(), nlriByteBuf); - } else if (fsType instanceof DscpCase) { - nlriByteBuf.writeByte(DSCP_VALUE); - serializeDscps(((DscpCase) fsType).getDscps(), nlriByteBuf); - } else { - serializeSpecificFSType(fsType, nlriByteBuf); - } - } - - /** - * Parses Flowspec NLRI into list of Flowspec. - * - * @param nlri byte representation of NLRI which will be parsed - * @return list of Flowspec - */ - public final List parseNlri(final ByteBuf nlri) throws BGPParsingException { - if (!nlri.isReadable()) { - return null; - } - final List fss = new ArrayList<>(); - - // length field can be one or two bytes (if needed) - // check the length of nlri to see how many bytes we can skip - final int length = nlri.readableBytes(); - nlri.skipBytes(length > MAX_NLRI_LENGTH_ONE_BYTE ? NLRI_LENGTH_EXTENDED : NLRI_LENGTH); - - while (nlri.isReadable()) { - final FlowspecBuilder builder = new FlowspecBuilder(); - final short type = nlri.readUnsignedByte(); - setFlowspecType(builder, type, nlri); - fss.add(builder.build()); - } - return fss; - } - - protected final void setFlowspecType(final FlowspecBuilder builder, final short type, final ByteBuf nlri) { - switch (type) { - case PORT_VALUE: - builder.setFlowspecType(new PortCaseBuilder().setPorts(parsePort(nlri)).build()); - break; - case DESTINATION_PORT_VALUE: - builder.setFlowspecType(new DestinationPortCaseBuilder().setDestinationPorts(parseDestinationPort(nlri)).build()); - break; - case SOURCE_PORT_VALUE: - builder.setFlowspecType(new SourcePortCaseBuilder().setSourcePorts(parseSourcePort(nlri)).build()); - break; - case ICMP_TYPE_VALUE: - builder.setFlowspecType(new IcmpTypeCaseBuilder().setTypes(parseIcmpType(nlri)).build()); - break; - case ICMP_CODE_VALUE: - builder.setFlowspecType(new IcmpCodeCaseBuilder().setCodes(parseIcmpCode(nlri)).build()); - break; - case TCP_FLAGS_VALUE: - builder.setFlowspecType(new TcpFlagsCaseBuilder().setTcpFlags(parseTcpFlags(nlri)).build()); - break; - case PACKET_LENGTH_VALUE: - builder.setFlowspecType(new PacketLengthCaseBuilder().setPacketLengths(parsePacketLength(nlri)).build()); - break; - case DSCP_VALUE: - builder.setFlowspecType(new DscpCaseBuilder().setDscps(parseDscp(nlri)).build()); - break; - default: - setSpecificFlowspecType(builder, type, nlri); - break; - } - } - - private static List parsePort(final ByteBuf nlri) { - final List ports = new ArrayList<>(); - boolean end = false; - // we can do this as all fields will be rewritten in the cycle - final PortsBuilder builder = new PortsBuilder(); - 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(ByteArray.bytesToInt(ByteArray.readBytes(nlri, length))); - end = op.isEndOfList(); - ports.add(builder.build()); - } - return ports; - } - - private static List parseDestinationPort(final ByteBuf nlri) { - final List ports = new ArrayList<>(); - boolean end = false; - // we can do this as all fields will be rewritten in the cycle - final DestinationPortsBuilder builder = new DestinationPortsBuilder(); - 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(ByteArray.bytesToInt(ByteArray.readBytes(nlri, length))); - end = op.isEndOfList(); - ports.add(builder.build()); - } - return ports; - } - - private static List parseSourcePort(final ByteBuf nlri) { - final List ports = new ArrayList<>(); - boolean end = false; - // we can do this as all fields will be rewritten in the cycle - final SourcePortsBuilder builder = new SourcePortsBuilder(); - 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(ByteArray.bytesToInt(ByteArray.readBytes(nlri, length))); - end = op.isEndOfList(); - ports.add(builder.build()); - } - return ports; - } - - private static List parseIcmpType(final ByteBuf nlri) { - final List types = new ArrayList<>(); - boolean end = false; - // we can do this as all fields will be rewritten in the cycle - final TypesBuilder builder = new TypesBuilder(); - while (!end) { - final byte b = nlri.readByte(); - final NumericOperand op = NumericOneByteOperandParser.INSTANCE.parse(b); - builder.setOp(op); - builder.setValue(nlri.readUnsignedByte()); - end = op.isEndOfList(); - types.add(builder.build()); - } - return types; - } - - private static List parseIcmpCode(final ByteBuf nlri) { - final List codes = new ArrayList<>(); - boolean end = false; - // we can do this as all fields will be rewritten in the cycle - final CodesBuilder builder = new CodesBuilder(); - while (!end) { - final byte b = nlri.readByte(); - final NumericOperand op = NumericOneByteOperandParser.INSTANCE.parse(b); - builder.setOp(op); - builder.setValue(nlri.readUnsignedByte()); - end = op.isEndOfList(); - codes.add(builder.build()); - } - return codes; - } - - private static List parseTcpFlags(final ByteBuf nlri) { - final List flags = new ArrayList<>(); - boolean end = false; - // we can do this as all fields will be rewritten in the cycle - final TcpFlagsBuilder builder = new TcpFlagsBuilder(); - while (!end) { - final byte b = nlri.readByte(); - final BitmaskOperand op = BitmaskOperandParser.INSTANCE.parse(b); - builder.setOp(op); - final short length = AbstractOperandParser.parseLength(b); - builder.setValue(ByteArray.bytesToInt(ByteArray.readBytes(nlri, length))); - end = op.isEndOfList(); - flags.add(builder.build()); - } - return flags; - } - - private static List parsePacketLength(final ByteBuf nlri) { - final List plengths = new ArrayList<>(); - boolean end = false; - // we can do this as all fields will be rewritten in the cycle - final PacketLengthsBuilder builder = new PacketLengthsBuilder(); - while (!end) { - final byte b = nlri.readByte(); - // RFC does not specify which operand to use - final NumericOperand op = NumericTwoByteOperandParser.INSTANCE.parse(b); - builder.setOp(op); - final short length = AbstractOperandParser.parseLength(b); - builder.setValue(ByteArray.bytesToInt(ByteArray.readBytes(nlri, length))); - end = op.isEndOfList(); - plengths.add(builder.build()); - } - return plengths; - } - - private static List parseDscp(final ByteBuf nlri) { - final List dscps = new ArrayList<>(); - boolean end = false; - // we can do this as all fields will be rewritten in the cycle - final DscpsBuilder builder = new DscpsBuilder(); - while (!end) { - final byte b = nlri.readByte(); - // RFC does not specify operator - final NumericOperand op = NumericOneByteOperandParser.INSTANCE.parse(b); - builder.setOp(op); - builder.setValue(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.Dscp(nlri.readUnsignedByte())); - end = op.isEndOfList(); - dscps.add(builder.build()); - } - return dscps; - } - - protected final List parseFragment(final ByteBuf nlri) { - final List fragments = new ArrayList<>(); - boolean end = false; - // we can do this as all fields will be rewritten in the cycle - final FragmentsBuilder builder = new FragmentsBuilder(); - while (!end) { - final byte b = nlri.readByte(); - final BitmaskOperand op = BitmaskOperandParser.INSTANCE.parse(b); - builder.setOp(op); - builder.setValue(parseFragment(nlri.readByte())); - end = op.isEndOfList(); - fragments.add(builder.build()); - } - return fragments; - } - - public final String stringNlri(final DataContainerNode route) { - return stringNlri(extractFlowspec(route)); + public final String stringNlri(final DataContainerNode flowspec) { + return stringNlri(extractFlowspec((MapEntryNode) flowspec)); } public final List extractFlowspec(final DataContainerNode route) { @@ -558,9 +269,11 @@ public abstract class AbstractFSNlriParser implements NlriParser, NlriSerializer for (final UnkeyedListEntryNode node : destinationPortsData.getValue()) { final DestinationPortsBuilder destPortsBuilder = new DestinationPortsBuilder(); - final Optional> opValue = node.getChild(OP_NID); - if (opValue.isPresent()) { - destPortsBuilder.setOp(NumericTwoByteOperandParser.INSTANCE.create((Set) opValue.get().getValue())); + if (node.getNodeType().getLocalName().equals("op")) { + final Optional> opValue = node.getChild(OP_NID); + if (opValue.isPresent()) { + destPortsBuilder.setOp(NumericTwoByteOperandParser.INSTANCE.create((Set) opValue.get().getValue())); + } } final Optional> valueNode = node.getChild(VALUE_NID); if (valueNode.isPresent()) { @@ -722,7 +435,7 @@ public abstract class AbstractFSNlriParser implements NlriParser, NlriSerializer } @VisibleForTesting - private String encodeFlow(final Flowspec flow) { + final String encodeFlow(final Flowspec flow) { final StringBuilder buffer = new StringBuilder(); final FlowspecType value = flow.getFlowspecType(); if (value instanceof PortCase) { @@ -812,4 +525,30 @@ public abstract class AbstractFSNlriParser implements NlriParser, NlriSerializer } return buffer.toString(); } + + /** + * Parses Flowspec NLRI into list of Flowspec. + * + * @param nlri byte representation of NLRI which will be parsed + * @return list of Flowspec + */ + public final List parseNlri(final ByteBuf nlri) throws BGPParsingException { + if (!nlri.isReadable()) { + return null; + } + final List fss = new ArrayList<>(); + + // length field can be one or two bytes (if needed) + // check the length of nlri to see how many bytes we can skip + final int length = nlri.readableBytes(); + nlri.skipBytes(length > MAX_NLRI_LENGTH_ONE_BYTE ? NLRI_LENGTH_EXTENDED : NLRI_LENGTH); + + while (nlri.isReadable()) { + final FlowspecBuilder builder = new FlowspecBuilder(); + builder.setFlowspecType(this.flowspecTypeRegistry.parseFlowspecType(nlri)); + fss.add(builder.build()); + } + return fss; + } + } diff --git a/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/AbstractFlowspecRIBSupport.java b/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/AbstractFlowspecRIBSupport.java index 0cbe7c3d56..6b5b547c6b 100644 --- a/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/AbstractFlowspecRIBSupport.java +++ b/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/AbstractFlowspecRIBSupport.java @@ -84,7 +84,7 @@ public abstract class AbstractFlowspecRIBSupport extends AbstractRIBSupport { protected abstract NodeIdentifier routeIdentifier(); - protected abstract AbstractFSNlriParser getParser(); + protected abstract AbstractFlowspecNlriParser getParser(); protected abstract Class getAfiClass(); @@ -144,7 +144,7 @@ public abstract class AbstractFlowspecRIBSupport extends AbstractRIBSupport { mb.setSafi(FlowspecSubsequentAddressFamily.class); mb.setWithdrawnRoutes(new WithdrawnRoutesBuilder().setDestinationType( - getParser().createWidthdrawnDestinationType( + getParser().createWithdrawnDestinationType( getParser().extractFlowspec(Iterables.getOnlyElement(routes)))).build()); return mb.build(); } diff --git a/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/BGPActivator.java b/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/BGPActivator.java index fb04f4f776..7d86636c69 100644 --- a/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/BGPActivator.java +++ b/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/BGPActivator.java @@ -41,22 +41,33 @@ public final class BGPActivator extends AbstractBGPExtensionProviderActivator { private static final int FLOWSPEC_SAFI = 133; + private final SimpleFlowspecExtensionProviderContext flowspecContext; + private final FlowspecActivator fsActivator; + + public BGPActivator(final SimpleFlowspecExtensionProviderContext fsc, FlowspecActivator fsa) { + this.flowspecContext = fsc; + this.fsActivator = fsa; + } + @Override protected List startImpl(final BGPExtensionProviderContext context) { + final List regs = new ArrayList<>(); regs.add(context.registerSubsequentAddressFamily(FlowspecSubsequentAddressFamily.class, FLOWSPEC_SAFI)); - final FSIpv4NlriParser ipv4Handler = new FSIpv4NlriParser(); - final FSIpv6NlriParser ipv6Handler = new FSIpv6NlriParser(); + final SimpleFlowspecIpv4NlriParser fsIpv4Handler = new SimpleFlowspecIpv4NlriParser(this.flowspecContext.getFlowspecIpv4TypeRegistry()); + final SimpleFlowspecIpv6NlriParser fsIpv6Handler = new SimpleFlowspecIpv6NlriParser(this.flowspecContext.getFlowspecIpv6TypeRegistry()); + final Ipv4NextHopParserSerializer ipv4NextHopParser = new Ipv4NextHopParserSerializer(); final Ipv6NextHopParserSerializer ipv6NextHopParser = new Ipv6NextHopParserSerializer(); + regs.add(context.registerNlriParser(Ipv4AddressFamily.class, FlowspecSubsequentAddressFamily.class, - ipv4Handler, ipv4NextHopParser, Ipv4NextHopCase.class)); + fsIpv4Handler, ipv4NextHopParser, Ipv4NextHopCase.class)); regs.add(context.registerNlriParser(Ipv6AddressFamily.class, FlowspecSubsequentAddressFamily.class, - ipv6Handler, ipv6NextHopParser, Ipv6NextHopCase.class)); - regs.add(context.registerNlriSerializer(FlowspecRoutes.class, ipv4Handler)); - regs.add(context.registerNlriSerializer(FlowspecIpv6Routes.class, ipv6Handler)); + fsIpv6Handler, ipv6NextHopParser, Ipv6NextHopCase.class)); + regs.add(context.registerNlriSerializer(FlowspecRoutes.class, fsIpv4Handler)); + regs.add(context.registerNlriSerializer(FlowspecIpv6Routes.class, fsIpv6Handler)); final RedirectAsTwoOctetEcHandler redirect2bHandler = new RedirectAsTwoOctetEcHandler(); regs.add(context.registerExtendedCommunityParser(redirect2bHandler.getType(true), redirect2bHandler.getSubType(), redirect2bHandler)); diff --git a/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/FSDestinationPortHandler.java b/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/FSDestinationPortHandler.java new file mode 100644 index 0000000000..2225973c82 --- /dev/null +++ b/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/FSDestinationPortHandler.java @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.protocol.bgp.flowspec; + +import com.google.common.base.Preconditions; +import io.netty.buffer.ByteBuf; +import java.util.ArrayList; +import java.util.List; +import org.opendaylight.protocol.bgp.flowspec.handlers.FlowspecTypeParser; +import org.opendaylight.protocol.bgp.flowspec.handlers.FlowspecTypeSerializer; +import org.opendaylight.protocol.util.ByteArray; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.NumericOperand; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.FlowspecType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.DestinationPortCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.DestinationPortCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.destination.port._case.DestinationPorts; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.destination.port._case.DestinationPortsBuilder; + +public final class FSDestinationPortHandler implements FlowspecTypeParser, FlowspecTypeSerializer { + public static final int DESTINATION_PORT_VALUE = 5; + + @Override + public void serializeType(FlowspecType fsType, ByteBuf output) { + Preconditions.checkArgument(fsType instanceof DestinationPortCase, "DestinationPortCase class is mandatory!"); + output.writeByte(DESTINATION_PORT_VALUE); + NumericTwoByteOperandParser.INSTANCE.serialize(((DestinationPortCase) fsType).getDestinationPorts(), output); + } + + @Override + public FlowspecType parseType(ByteBuf buffer) { + Preconditions.checkNotNull(buffer, "input buffer is null, missing data to parse."); + return new DestinationPortCaseBuilder().setDestinationPorts(parseDestinationPort(buffer)).build(); + } + + private static List parseDestinationPort(final ByteBuf nlri) { + final List ports = new ArrayList<>(); + boolean end = false; + // we can do this as all fields will be rewritten in the cycle + final DestinationPortsBuilder builder = new DestinationPortsBuilder(); + 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(ByteArray.bytesToInt(ByteArray.readBytes(nlri, length))); + end = op.isEndOfList(); + ports.add(builder.build()); + } + return ports; + } +} diff --git a/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/FSDscpHandler.java b/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/FSDscpHandler.java new file mode 100644 index 0000000000..6bfe74f73a --- /dev/null +++ b/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/FSDscpHandler.java @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.protocol.bgp.flowspec; + +import com.google.common.base.Preconditions; +import io.netty.buffer.ByteBuf; +import java.util.ArrayList; +import java.util.List; +import org.opendaylight.protocol.bgp.flowspec.handlers.FlowspecTypeParser; +import org.opendaylight.protocol.bgp.flowspec.handlers.FlowspecTypeSerializer; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.NumericOperand; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.FlowspecType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.DscpCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.DscpCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.dscp._case.Dscps; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.dscp._case.DscpsBuilder; + +public final class FSDscpHandler implements FlowspecTypeParser, FlowspecTypeSerializer { + public static final int DSCP_VALUE = 11; + + @Override + public void serializeType(FlowspecType fsType, ByteBuf output) { + Preconditions.checkArgument(fsType instanceof DscpCase, "DscpCase class is mandatory!"); + output.writeByte(DSCP_VALUE); + serializeDscps(((DscpCase) fsType).getDscps(), output); + } + + @Override + public FlowspecType parseType(ByteBuf buffer) { + Preconditions.checkNotNull(buffer, "input buffer is null, missing data to parse."); + return new DscpCaseBuilder().setDscps(parseDscps(buffer)).build(); + } + + private static final void serializeDscps(final List dscps, final ByteBuf nlriByteBuf) { + for (final Dscps dscp : dscps) { + NumericOneByteOperandParser.INSTANCE.serialize(dscp.getOp(), 1, nlriByteBuf); + Util.writeShortest(dscp.getValue().getValue(), nlriByteBuf); + } + } + + private static List parseDscps(final ByteBuf nlri) { + final List dscps = new ArrayList<>(); + boolean end = false; + // we can do this as all fields will be rewritten in the cycle + final DscpsBuilder builder = new DscpsBuilder(); + while (!end) { + final byte b = nlri.readByte(); + // RFC does not specify operator + final NumericOperand op = NumericOneByteOperandParser.INSTANCE.parse(b); + builder.setOp(op); + builder.setValue(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.Dscp(nlri.readUnsignedByte())); + end = op.isEndOfList(); + dscps.add(builder.build()); + } + return dscps; + } +} diff --git a/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/FSIcmpCodeHandler.java b/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/FSIcmpCodeHandler.java new file mode 100644 index 0000000000..d2beddaa8f --- /dev/null +++ b/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/FSIcmpCodeHandler.java @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.protocol.bgp.flowspec; + +import com.google.common.base.Preconditions; +import io.netty.buffer.ByteBuf; +import java.util.ArrayList; +import java.util.List; +import org.opendaylight.protocol.bgp.flowspec.NumericOneByteOperandParser; +import org.opendaylight.protocol.bgp.flowspec.handlers.FlowspecTypeParser; +import org.opendaylight.protocol.bgp.flowspec.handlers.FlowspecTypeSerializer; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.NumericOperand; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.FlowspecType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.IcmpCodeCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.IcmpCodeCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.icmp.code._case.Codes; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.icmp.code._case.CodesBuilder; + +public final class FSIcmpCodeHandler implements FlowspecTypeParser, FlowspecTypeSerializer { + public static final int ICMP_CODE_VALUE = 8; + + @Override + public void serializeType(FlowspecType fsType, ByteBuf output) { + Preconditions.checkArgument(fsType instanceof IcmpCodeCase, "IcmpCodeCase class is mandatory!"); + output.writeByte(ICMP_CODE_VALUE); + NumericOneByteOperandParser.INSTANCE.serialize(((IcmpCodeCase) fsType).getCodes(), output); + } + + @Override + public FlowspecType parseType(ByteBuf buffer) { + Preconditions.checkNotNull(buffer, "input buffer is null, missing data to parse."); + return new IcmpCodeCaseBuilder().setCodes(parseIcmpCode(buffer)).build(); + } + + private static List parseIcmpCode(final ByteBuf nlri) { + final List codes = new ArrayList<>(); + boolean end = false; + // we can do this as all fields will be rewritten in the cycle + final CodesBuilder builder = new CodesBuilder(); + while (!end) { + final byte b = nlri.readByte(); + final NumericOperand op = NumericOneByteOperandParser.INSTANCE.parse(b); + builder.setOp(op); + builder.setValue(nlri.readUnsignedByte()); + end = op.isEndOfList(); + codes.add(builder.build()); + } + return codes; + } +} diff --git a/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/FSIcmpTypeHandler.java b/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/FSIcmpTypeHandler.java new file mode 100644 index 0000000000..18ceec7388 --- /dev/null +++ b/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/FSIcmpTypeHandler.java @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.protocol.bgp.flowspec; + +import com.google.common.base.Preconditions; +import io.netty.buffer.ByteBuf; +import java.util.ArrayList; +import java.util.List; +import org.opendaylight.protocol.bgp.flowspec.handlers.FlowspecTypeParser; +import org.opendaylight.protocol.bgp.flowspec.handlers.FlowspecTypeSerializer; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.NumericOperand; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.FlowspecType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.IcmpTypeCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.IcmpTypeCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.icmp.type._case.Types; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.icmp.type._case.TypesBuilder; + +public final class FSIcmpTypeHandler implements FlowspecTypeParser, FlowspecTypeSerializer { + public static final int ICMP_TYPE_VALUE = 7; + + @Override + public void serializeType(FlowspecType fsType, ByteBuf output) { + Preconditions.checkArgument(fsType instanceof IcmpTypeCase, "IcmpTypeCase class is mandatory!"); + output.writeByte(ICMP_TYPE_VALUE); + NumericOneByteOperandParser.INSTANCE.serialize(((IcmpTypeCase) fsType).getTypes(), output); + } + + @Override + public FlowspecType parseType(ByteBuf buffer) { + Preconditions.checkNotNull(buffer, "input buffer is null, missing data to parse."); + return new IcmpTypeCaseBuilder().setTypes(parseIcmpType(buffer)).build(); + } + + private static List parseIcmpType(final ByteBuf nlri) { + final List icmps = new ArrayList<>(); + boolean end = false; + // we can do this as all fields will be rewritten in the cycle + final TypesBuilder builder = new TypesBuilder(); + while (!end) { + final byte b = nlri.readByte(); + final NumericOperand op = NumericOneByteOperandParser.INSTANCE.parse(b); + builder.setOp(op); + builder.setValue(nlri.readUnsignedByte()); + end = op.isEndOfList(); + icmps.add(builder.build()); + } + return icmps; + } +} diff --git a/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/FSIpProtocolHandler.java b/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/FSIpProtocolHandler.java new file mode 100644 index 0000000000..22a6dc2b73 --- /dev/null +++ b/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/FSIpProtocolHandler.java @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.protocol.bgp.flowspec; + +import com.google.common.base.Preconditions; +import io.netty.buffer.ByteBuf; +import java.util.ArrayList; +import java.util.List; +import org.opendaylight.protocol.bgp.flowspec.handlers.FlowspecTypeParser; +import org.opendaylight.protocol.bgp.flowspec.handlers.FlowspecTypeSerializer; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.NumericOperand; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.FlowspecType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.ipv4.flowspec.flowspec.type.ProtocolIpCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.ipv4.flowspec.flowspec.type.ProtocolIpCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.ipv4.flowspec.flowspec.type.protocol.ip._case.ProtocolIps; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.ipv4.flowspec.flowspec.type.protocol.ip._case.ProtocolIpsBuilder; + +public final class FSIpProtocolHandler implements FlowspecTypeParser, FlowspecTypeSerializer { + public static final int IP_PROTOCOL_VALUE = 3; + + @Override + public void serializeType(FlowspecType fsType, ByteBuf output) { + Preconditions.checkArgument(fsType instanceof ProtocolIpCase, "ProtocolIpCase class is mandatory!"); + output.writeByte(IP_PROTOCOL_VALUE); + NumericOneByteOperandParser.INSTANCE.serialize(((ProtocolIpCase) fsType).getProtocolIps(), output); + } + + @Override + public FlowspecType parseType(ByteBuf buffer) { + Preconditions.checkNotNull(buffer, "input buffer is null, missing data to parse."); + return new ProtocolIpCaseBuilder().setProtocolIps(parseProtocolIp(buffer)).build(); + } + + private static List parseProtocolIp(final ByteBuf nlri) { + final List ips = new ArrayList<>(); + boolean end = false; + // we can do this as all fields will be rewritten in the cycle + final ProtocolIpsBuilder builder = new ProtocolIpsBuilder(); + while (!end) { + final byte b = nlri.readByte(); + final NumericOperand op = NumericOneByteOperandParser.INSTANCE.parse(b); + builder.setOp(op); + builder.setValue(nlri.readUnsignedByte()); + end = op.isEndOfList(); + ips.add(builder.build()); + } + return ips; + } +} diff --git a/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/FSIpv6FlowLabelHandler.java b/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/FSIpv6FlowLabelHandler.java new file mode 100644 index 0000000000..337eeccf04 --- /dev/null +++ b/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/FSIpv6FlowLabelHandler.java @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.protocol.bgp.flowspec; + +import com.google.common.base.Preconditions; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.Unpooled; +import java.util.ArrayList; +import java.util.List; +import org.opendaylight.protocol.bgp.flowspec.handlers.FlowspecTypeParser; +import org.opendaylight.protocol.bgp.flowspec.handlers.FlowspecTypeSerializer; +import org.opendaylight.protocol.util.ByteArray; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.NumericOperand; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.FlowspecType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.ipv6.flowspec.flowspec.type.FlowLabelCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.ipv6.flowspec.flowspec.type.FlowLabelCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.ipv6.flowspec.flowspec.type.flow.label._case.FlowLabel; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.ipv6.flowspec.flowspec.type.flow.label._case.FlowLabelBuilder; + +public final class FSIpv6FlowLabelHandler implements FlowspecTypeParser, FlowspecTypeSerializer { + public static final int FLOW_LABEL_VALUE = 13; + + @Override + public void serializeType(FlowspecType fsType, ByteBuf output) { + Preconditions.checkArgument(fsType instanceof FlowLabelCase, "FlowLabelCase class is mandatory!"); + output.writeByte(FLOW_LABEL_VALUE); + serializeNumericFourByteValue(((FlowLabelCase) fsType).getFlowLabel(), output); + } + + @Override + public FlowspecType parseType(ByteBuf buffer) { + return new FlowLabelCaseBuilder().setFlowLabel(parseFlowLabel(buffer)).build(); + } + + private static void serializeNumericFourByteValue(final List list, final ByteBuf nlriByteBuf) { + for (final FlowLabel item : list) { + final ByteBuf protoBuf = Unpooled.buffer(); + Util.writeShortest(item.getValue().intValue(), protoBuf); + NumericOneByteOperandParser.INSTANCE.serialize(item.getOp(), protoBuf.readableBytes(), nlriByteBuf); + nlriByteBuf.writeBytes(protoBuf); + } + } + + private static List parseFlowLabel(final ByteBuf nlri) { + final List 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(ByteArray.bytesToLong(ByteArray.readBytes(nlri, length))); + end = op.isEndOfList(); + labels.add(builder.build()); + } + return labels; + } +} diff --git a/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/FSIpv6NextHeaderHandler.java b/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/FSIpv6NextHeaderHandler.java new file mode 100644 index 0000000000..2fd7df214e --- /dev/null +++ b/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/FSIpv6NextHeaderHandler.java @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.protocol.bgp.flowspec; + +import com.google.common.base.Preconditions; +import io.netty.buffer.ByteBuf; +import java.util.ArrayList; +import java.util.List; +import org.opendaylight.protocol.bgp.flowspec.handlers.FlowspecTypeParser; +import org.opendaylight.protocol.bgp.flowspec.handlers.FlowspecTypeSerializer; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.NumericOperand; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.FlowspecType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.ipv6.flowspec.flowspec.type.NextHeaderCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.ipv6.flowspec.flowspec.type.NextHeaderCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.ipv6.flowspec.flowspec.type.next.header._case.NextHeaders; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.ipv6.flowspec.flowspec.type.next.header._case.NextHeadersBuilder; + +public final class FSIpv6NextHeaderHandler implements FlowspecTypeParser, FlowspecTypeSerializer { + public static final int NEXT_HEADER_VALUE = 3; + + @Override + public void serializeType(FlowspecType value, ByteBuf output) { + Preconditions.checkArgument(value instanceof NextHeaderCase, "NextHeaderCase class is mandatory!"); + output.writeByte(NEXT_HEADER_VALUE); + NumericOneByteOperandParser.INSTANCE.serialize(((NextHeaderCase) value).getNextHeaders(), output); + } + + @Override + public FlowspecType parseType(ByteBuf buffer) { + if (buffer == null) { + return null; + } + return new NextHeaderCaseBuilder().setNextHeaders(parseNextHeader(buffer)).build(); + } + + private static List parseNextHeader(final ByteBuf nlri) { + final List 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(nlri.readUnsignedByte()); + end = op.isEndOfList(); + headers.add(builder.build()); + } + return headers; + } +} diff --git a/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/FSPacketLengthHandler.java b/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/FSPacketLengthHandler.java new file mode 100644 index 0000000000..29822f8b5b --- /dev/null +++ b/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/FSPacketLengthHandler.java @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.protocol.bgp.flowspec; + +import com.google.common.base.Preconditions; +import io.netty.buffer.ByteBuf; +import java.util.ArrayList; +import java.util.List; +import org.opendaylight.protocol.bgp.flowspec.handlers.FlowspecTypeParser; +import org.opendaylight.protocol.bgp.flowspec.handlers.FlowspecTypeSerializer; +import org.opendaylight.protocol.util.ByteArray; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.NumericOperand; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.FlowspecType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.PacketLengthCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.PacketLengthCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.packet.length._case.PacketLengths; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.packet.length._case.PacketLengthsBuilder; + +public final class FSPacketLengthHandler implements FlowspecTypeParser, FlowspecTypeSerializer { + public static final int PACKET_LENGTH_VALUE = 10; + + @Override + public void serializeType(FlowspecType fsType, ByteBuf output) { + Preconditions.checkArgument(fsType instanceof PacketLengthCase, "PacketLengthCase class is mandatory!"); + output.writeByte(PACKET_LENGTH_VALUE); + NumericTwoByteOperandParser.INSTANCE.serialize(((PacketLengthCase) fsType).getPacketLengths(), output); + } + + @Override + public FlowspecType parseType(ByteBuf buffer) { + Preconditions.checkNotNull(buffer, "input buffer is null, missing data to parse."); + return new PacketLengthCaseBuilder().setPacketLengths(parsePacketLength(buffer)).build(); + } + + private static List parsePacketLength(final ByteBuf nlri) { + final List packetLengths = new ArrayList<>(); + boolean end = false; + // we can do this as all fields will be rewritten in the cycle + final PacketLengthsBuilder builder = new PacketLengthsBuilder(); + 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(ByteArray.bytesToInt(ByteArray.readBytes(nlri, length))); + end = op.isEndOfList(); + packetLengths.add(builder.build()); + } + return packetLengths; + } +} diff --git a/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/FSPortHandler.java b/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/FSPortHandler.java new file mode 100644 index 0000000000..09835d9173 --- /dev/null +++ b/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/FSPortHandler.java @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.protocol.bgp.flowspec; + +import com.google.common.base.Preconditions; +import io.netty.buffer.ByteBuf; +import java.util.ArrayList; +import java.util.List; +import org.opendaylight.protocol.bgp.flowspec.AbstractOperandParser; +import org.opendaylight.protocol.bgp.flowspec.NumericOneByteOperandParser; +import org.opendaylight.protocol.bgp.flowspec.NumericTwoByteOperandParser; +import org.opendaylight.protocol.bgp.flowspec.handlers.FlowspecTypeParser; +import org.opendaylight.protocol.bgp.flowspec.handlers.FlowspecTypeSerializer; +import org.opendaylight.protocol.util.ByteArray; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.NumericOperand; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.FlowspecType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.PortCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.PortCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.port._case.Ports; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.port._case.PortsBuilder; + +public final class FSPortHandler implements FlowspecTypeParser, FlowspecTypeSerializer { + public static final int PORT_VALUE = 4; + + @Override + public void serializeType(FlowspecType fsType, ByteBuf output) { + Preconditions.checkArgument(fsType instanceof PortCase, "PortCase class is mandatory!"); + output.writeByte(PORT_VALUE); + NumericTwoByteOperandParser.INSTANCE.serialize(((PortCase) fsType).getPorts(), output); + } + + @Override + public FlowspecType parseType(ByteBuf buffer) { + Preconditions.checkNotNull(buffer, "input buffer is null, missing data to parse."); + return new PortCaseBuilder().setPorts(parsePort(buffer)).build(); + } + + private static List parsePort(final ByteBuf nlri) { + final List ports = new ArrayList<>(); + boolean end = false; + // we can do this as all fields will be rewritten in the cycle + final PortsBuilder builder = new PortsBuilder(); + 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(ByteArray.bytesToInt(ByteArray.readBytes(nlri, length))); + end = op.isEndOfList(); + ports.add(builder.build()); + } + return ports; + } +} diff --git a/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/FSSourcePortHandler.java b/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/FSSourcePortHandler.java new file mode 100644 index 0000000000..89c8796246 --- /dev/null +++ b/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/FSSourcePortHandler.java @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.protocol.bgp.flowspec; + +import com.google.common.base.Preconditions; +import io.netty.buffer.ByteBuf; +import java.util.ArrayList; +import java.util.List; +import org.opendaylight.protocol.bgp.flowspec.handlers.FlowspecTypeParser; +import org.opendaylight.protocol.bgp.flowspec.handlers.FlowspecTypeSerializer; +import org.opendaylight.protocol.util.ByteArray; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.NumericOperand; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.FlowspecType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.SourcePortCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.SourcePortCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.source.port._case.SourcePorts; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.source.port._case.SourcePortsBuilder; + +public final class FSSourcePortHandler implements FlowspecTypeParser, FlowspecTypeSerializer { + public static final int SOURCE_PORT_VALUE = 6; + + @Override + public void serializeType(FlowspecType fsType, ByteBuf output) { + Preconditions.checkArgument(fsType instanceof SourcePortCase, "SourcePortCase class is mandatory!"); + output.writeByte(SOURCE_PORT_VALUE); + NumericTwoByteOperandParser.INSTANCE.serialize(((SourcePortCase) fsType).getSourcePorts(), output); + } + + @Override + public FlowspecType parseType(ByteBuf buffer) { + Preconditions.checkNotNull(buffer, "input buffer is null, missing data to parse."); + return new SourcePortCaseBuilder().setSourcePorts(parseSourcePort(buffer)).build(); + } + + private static List parseSourcePort(final ByteBuf nlri) { + final List ports = new ArrayList<>(); + boolean end = false; + // we can do this as all fields will be rewritten in the cycle + final SourcePortsBuilder builder = new SourcePortsBuilder(); + 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(ByteArray.bytesToInt(ByteArray.readBytes(nlri, length))); + end = op.isEndOfList(); + ports.add(builder.build()); + } + return ports; + } +} diff --git a/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/FSTcpFlagsHandler.java b/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/FSTcpFlagsHandler.java new file mode 100644 index 0000000000..91b684e970 --- /dev/null +++ b/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/FSTcpFlagsHandler.java @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.protocol.bgp.flowspec; + +import com.google.common.base.Preconditions; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.Unpooled; +import java.util.ArrayList; +import java.util.List; +import org.opendaylight.protocol.bgp.flowspec.handlers.FlowspecTypeParser; +import org.opendaylight.protocol.bgp.flowspec.handlers.FlowspecTypeSerializer; +import org.opendaylight.protocol.util.ByteArray; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.BitmaskOperand; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.FlowspecType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.TcpFlagsCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.TcpFlagsCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.tcp.flags._case.TcpFlags; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.tcp.flags._case.TcpFlagsBuilder; + +public final class FSTcpFlagsHandler implements FlowspecTypeParser, FlowspecTypeSerializer { + public static final int TCP_FLAGS_VALUE = 9; + + @Override + public void serializeType(FlowspecType fsType, ByteBuf output) { + Preconditions.checkArgument(fsType instanceof TcpFlagsCase, "TcpFlagsCase class is mandatory!"); + output.writeByte(TCP_FLAGS_VALUE); + serializeTcpFlags(((TcpFlagsCase) fsType).getTcpFlags(), output); + } + + @Override + public FlowspecType parseType(ByteBuf buffer) { + Preconditions.checkNotNull(buffer, "input buffer is null, missing data to parse."); + return new TcpFlagsCaseBuilder().setTcpFlags(parseTcpFlags(buffer)).build(); + } + + private static final void serializeTcpFlags(final List flags, final ByteBuf nlriByteBuf) { + for (final TcpFlags flag : flags) { + final ByteBuf flagsBuf = Unpooled.buffer(); + Util.writeShortest(flag.getValue(), flagsBuf); + BitmaskOperandParser.INSTANCE.serialize(flag.getOp(), flagsBuf.readableBytes(), nlriByteBuf); + nlriByteBuf.writeBytes(flagsBuf); + } + } + + private static List parseTcpFlags(final ByteBuf nlri) { + final List flags = new ArrayList<>(); + boolean end = false; + // we can do this as all fields will be rewritten in the cycle + final TcpFlagsBuilder builder = new TcpFlagsBuilder(); + while (!end) { + final byte b = nlri.readByte(); + final BitmaskOperand op = BitmaskOperandParser.INSTANCE.parse(b); + builder.setOp(op); + final short length = AbstractOperandParser.parseLength(b); + builder.setValue(ByteArray.bytesToInt(ByteArray.readBytes(nlri, length))); + end = op.isEndOfList(); + flags.add(builder.build()); + } + return flags; + } +} diff --git a/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/FlowspecActivator.java b/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/FlowspecActivator.java new file mode 100644 index 0000000000..35faf91039 --- /dev/null +++ b/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/FlowspecActivator.java @@ -0,0 +1,180 @@ +/* + * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.protocol.bgp.flowspec; + +import java.util.ArrayList; +import java.util.List; +import org.opendaylight.protocol.bgp.flowspec.FSDestinationPortHandler; +import org.opendaylight.protocol.bgp.flowspec.FSDscpHandler; +import org.opendaylight.protocol.bgp.flowspec.FSIcmpCodeHandler; +import org.opendaylight.protocol.bgp.flowspec.FSIcmpTypeHandler; +import org.opendaylight.protocol.bgp.flowspec.FSIpProtocolHandler; +import org.opendaylight.protocol.bgp.flowspec.FSIpv6FlowLabelHandler; +import org.opendaylight.protocol.bgp.flowspec.FSIpv6NextHeaderHandler; +import org.opendaylight.protocol.bgp.flowspec.FSPacketLengthHandler; +import org.opendaylight.protocol.bgp.flowspec.FSPortHandler; +import org.opendaylight.protocol.bgp.flowspec.FSSourcePortHandler; +import org.opendaylight.protocol.bgp.flowspec.FSTcpFlagsHandler; +import org.opendaylight.protocol.bgp.flowspec.SimpleFlowspecExtensionProviderContext; +import org.opendaylight.protocol.bgp.flowspec.handlers.FSIpv4DestinationPrefixHandler; +import org.opendaylight.protocol.bgp.flowspec.handlers.FSIpv4FragmentHandler; +import org.opendaylight.protocol.bgp.flowspec.handlers.FSIpv4SourcePrefixHandler; +import org.opendaylight.protocol.bgp.flowspec.handlers.FSIpv6DestinationPrefixHandler; +import org.opendaylight.protocol.bgp.flowspec.handlers.FSIpv6FragmentHandler; +import org.opendaylight.protocol.bgp.flowspec.handlers.FSIpv6SourcePrefixHandler; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.DestinationPortCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.DscpCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.FragmentCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.IcmpCodeCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.IcmpTypeCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.PacketLengthCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.PortCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.SourcePortCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.TcpFlagsCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.ipv4.flowspec.flowspec.type.DestinationPrefixCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.ipv4.flowspec.flowspec.type.ProtocolIpCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.ipv4.flowspec.flowspec.type.SourcePrefixCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.ipv6.flowspec.flowspec.type.DestinationIpv6PrefixCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.ipv6.flowspec.flowspec.type.FlowLabelCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.ipv6.flowspec.flowspec.type.NextHeaderCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.ipv6.flowspec.flowspec.type.SourceIpv6PrefixCase; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public final class FlowspecActivator implements AutoCloseable { + private static final Logger LOG = LoggerFactory.getLogger(FlowspecActivator.class); + + private List registrations; + + public FlowspecActivator(final SimpleFlowspecExtensionProviderContext context) { + + final List regs = new ArrayList<>(); + registerIpv4FlowspecTypeHandlers(regs, context); + registerIpv6FlowspecTypeHandlers(regs, context); + } + + protected void registerIpv4FlowspecTypeHandlers(final List regs, SimpleFlowspecExtensionProviderContext context) { + + final FSIpv4DestinationPrefixHandler destinationPrefixHandler = new FSIpv4DestinationPrefixHandler(); + regs.add(context.registerFlowspecIpv4TypeParser(FSIpv4DestinationPrefixHandler.DESTINATION_PREFIX_VALUE, destinationPrefixHandler)); + regs.add(context.registerFlowspecIpv4TypeSerializer(DestinationPrefixCase.class, destinationPrefixHandler)); + + final FSIpv4SourcePrefixHandler sourcePrefixHandler = new FSIpv4SourcePrefixHandler(); + regs.add(context.registerFlowspecIpv4TypeParser(FSIpv4SourcePrefixHandler.SOURCE_PREFIX_VALUE, sourcePrefixHandler)); + regs.add(context.registerFlowspecIpv4TypeSerializer(SourcePrefixCase.class, sourcePrefixHandler)); + + final FSIpProtocolHandler ipProtocolHandler = new FSIpProtocolHandler(); + regs.add(context.registerFlowspecIpv4TypeParser(FSIpProtocolHandler.IP_PROTOCOL_VALUE, ipProtocolHandler)); + regs.add(context.registerFlowspecIpv4TypeSerializer(ProtocolIpCase.class, ipProtocolHandler)); + + final FSPortHandler portHandler = new FSPortHandler(); + regs.add(context.registerFlowspecIpv4TypeParser(FSPortHandler.PORT_VALUE, portHandler)); + regs.add(context.registerFlowspecIpv4TypeSerializer(PortCase.class, portHandler)); + + final FSDestinationPortHandler destinationPortHandler = new FSDestinationPortHandler(); + regs.add(context.registerFlowspecIpv4TypeParser(FSDestinationPortHandler.DESTINATION_PORT_VALUE, destinationPortHandler)); + regs.add(context.registerFlowspecIpv4TypeSerializer(DestinationPortCase.class, destinationPortHandler)); + + final FSSourcePortHandler sourcePortHandler = new FSSourcePortHandler(); + regs.add(context.registerFlowspecIpv4TypeParser(FSSourcePortHandler.SOURCE_PORT_VALUE, sourcePortHandler)); + regs.add(context.registerFlowspecIpv4TypeSerializer(SourcePortCase.class, sourcePortHandler)); + + final FSIcmpTypeHandler icmpTypeHandler = new FSIcmpTypeHandler(); + regs.add(context.registerFlowspecIpv4TypeParser(FSIcmpTypeHandler.ICMP_TYPE_VALUE, icmpTypeHandler)); + regs.add(context.registerFlowspecIpv4TypeSerializer(IcmpTypeCase.class, icmpTypeHandler)); + + final FSIcmpCodeHandler icmpCodeHandler = new FSIcmpCodeHandler(); + regs.add(context.registerFlowspecIpv4TypeParser(FSIcmpCodeHandler.ICMP_CODE_VALUE, icmpCodeHandler)); + regs.add(context.registerFlowspecIpv4TypeSerializer(IcmpCodeCase.class, icmpCodeHandler)); + + final FSTcpFlagsHandler tcpFlagsHandler = new FSTcpFlagsHandler(); + regs.add(context.registerFlowspecIpv4TypeParser(FSTcpFlagsHandler.TCP_FLAGS_VALUE, tcpFlagsHandler)); + regs.add(context.registerFlowspecIpv4TypeSerializer(TcpFlagsCase.class, tcpFlagsHandler)); + + final FSPacketLengthHandler packetlengthHandler = new FSPacketLengthHandler(); + regs.add(context.registerFlowspecIpv4TypeParser(FSPacketLengthHandler.PACKET_LENGTH_VALUE, packetlengthHandler)); + regs.add(context.registerFlowspecIpv4TypeSerializer(PacketLengthCase.class, packetlengthHandler)); + + final FSDscpHandler dscpHandler = new FSDscpHandler(); + regs.add(context.registerFlowspecIpv4TypeParser(FSDscpHandler.DSCP_VALUE, dscpHandler)); + regs.add(context.registerFlowspecIpv4TypeSerializer(DscpCase.class, dscpHandler)); + + final FSIpv4FragmentHandler fragmentHandler = new FSIpv4FragmentHandler(); + regs.add(context.registerFlowspecIpv4TypeParser(FSIpv4FragmentHandler.FRAGMENT_VALUE, fragmentHandler)); + regs.add(context.registerFlowspecIpv4TypeSerializer(FragmentCase.class, fragmentHandler)); + } + + protected void registerIpv6FlowspecTypeHandlers(final List regs, SimpleFlowspecExtensionProviderContext context) { + + final FSIpv6DestinationPrefixHandler destinationPrefixHandler = new FSIpv6DestinationPrefixHandler(); + regs.add(context.registerFlowspecIpv6TypeParser(FSIpv6DestinationPrefixHandler.IPV6_DESTINATION_PREFIX_VALUE, destinationPrefixHandler)); + regs.add(context.registerFlowspecIpv6TypeSerializer(DestinationIpv6PrefixCase.class, destinationPrefixHandler)); + + final FSIpv6SourcePrefixHandler sourcePrefixHandler = new FSIpv6SourcePrefixHandler(); + regs.add(context.registerFlowspecIpv6TypeParser(FSIpv6SourcePrefixHandler.SOURCE_PREFIX_VALUE, sourcePrefixHandler)); + regs.add(context.registerFlowspecIpv6TypeSerializer(SourceIpv6PrefixCase.class, sourcePrefixHandler)); + + final FSIpv6NextHeaderHandler nextHeaderHandler = new FSIpv6NextHeaderHandler(); + regs.add(context.registerFlowspecIpv6TypeParser(FSIpv6NextHeaderHandler.NEXT_HEADER_VALUE, nextHeaderHandler)); + regs.add(context.registerFlowspecIpv6TypeSerializer(NextHeaderCase.class, nextHeaderHandler)); + + final FSPortHandler portHandler = new FSPortHandler(); + regs.add(context.registerFlowspecIpv6TypeParser(FSPortHandler.PORT_VALUE, portHandler)); + regs.add(context.registerFlowspecIpv6TypeSerializer(PortCase.class, portHandler)); + + final FSDestinationPortHandler destinationPortHandler = new FSDestinationPortHandler(); + regs.add(context.registerFlowspecIpv6TypeParser(FSDestinationPortHandler.DESTINATION_PORT_VALUE, destinationPortHandler)); + regs.add(context.registerFlowspecIpv6TypeSerializer(DestinationPortCase.class, destinationPortHandler)); + + final FSSourcePortHandler sourcePortHandler = new FSSourcePortHandler(); + regs.add(context.registerFlowspecIpv6TypeParser(FSSourcePortHandler.SOURCE_PORT_VALUE, sourcePortHandler)); + regs.add(context.registerFlowspecIpv6TypeSerializer(SourcePortCase.class, sourcePortHandler)); + + final FSIcmpTypeHandler icmpTypeHandler = new FSIcmpTypeHandler(); + regs.add(context.registerFlowspecIpv6TypeParser(FSIcmpTypeHandler.ICMP_TYPE_VALUE, icmpTypeHandler)); + regs.add(context.registerFlowspecIpv6TypeSerializer(IcmpTypeCase.class, icmpTypeHandler)); + + final FSIcmpCodeHandler icmpCodeHandler = new FSIcmpCodeHandler(); + regs.add(context.registerFlowspecIpv6TypeParser(FSIcmpCodeHandler.ICMP_CODE_VALUE, icmpCodeHandler)); + regs.add(context.registerFlowspecIpv6TypeSerializer(IcmpCodeCase.class, icmpCodeHandler)); + + final FSTcpFlagsHandler tcpFlagsHandler = new FSTcpFlagsHandler(); + regs.add(context.registerFlowspecIpv6TypeParser(FSTcpFlagsHandler.TCP_FLAGS_VALUE, tcpFlagsHandler)); + regs.add(context.registerFlowspecIpv6TypeSerializer(TcpFlagsCase.class, tcpFlagsHandler)); + + final FSPacketLengthHandler packetlengthHandler = new FSPacketLengthHandler(); + regs.add(context.registerFlowspecIpv6TypeParser(FSPacketLengthHandler.PACKET_LENGTH_VALUE, packetlengthHandler)); + regs.add(context.registerFlowspecIpv6TypeSerializer(PacketLengthCase.class, packetlengthHandler)); + + final FSDscpHandler dscpHandler = new FSDscpHandler(); + regs.add(context.registerFlowspecIpv6TypeParser(FSDscpHandler.DSCP_VALUE, dscpHandler)); + regs.add(context.registerFlowspecIpv6TypeSerializer(DscpCase.class, dscpHandler)); + + final FSIpv6FragmentHandler fragmentHandler = new FSIpv6FragmentHandler(); + regs.add(context.registerFlowspecIpv6TypeParser(FSIpv6FragmentHandler.FRAGMENT_VALUE, fragmentHandler)); + regs.add(context.registerFlowspecIpv6TypeSerializer(FragmentCase.class, fragmentHandler)); + + final FSIpv6FlowLabelHandler flowlabelHandler = new FSIpv6FlowLabelHandler(); + regs.add(context.registerFlowspecIpv6TypeParser(FSIpv6FlowLabelHandler.FLOW_LABEL_VALUE, flowlabelHandler)); + regs.add(context.registerFlowspecIpv6TypeSerializer(FlowLabelCase.class, flowlabelHandler)); + } + + @Override + public void close() { + if (this.registrations == null) { + return; + } + for (final AutoCloseable r : this.registrations) { + try { + r.close(); + } catch (final Exception e) { + LOG.warn("Failed to close registration", e); + } + } + } +} diff --git a/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/FlowspecIpv4RIBSupport.java b/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/FlowspecIpv4RIBSupport.java index 08a998e4e7..6505de904a 100644 --- a/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/FlowspecIpv4RIBSupport.java +++ b/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/FlowspecIpv4RIBSupport.java @@ -21,9 +21,7 @@ import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes; final class FlowspecIpv4RIBSupport extends AbstractFlowspecRIBSupport { - private static final FSIpv4NlriParser FS_PARSER = new FSIpv4NlriParser(); - - private static final FlowspecIpv4RIBSupport SINGLETON = new FlowspecIpv4RIBSupport(); + private SimpleFlowspecIpv4NlriParser FS_PARSER; private final NodeIdentifier destinationNid = new NodeIdentifier(DestinationFlowspec.QNAME); private final NodeIdentifier routeNid = new NodeIdentifier(FlowspecRoute.QNAME); @@ -33,12 +31,13 @@ final class FlowspecIpv4RIBSupport extends AbstractFlowspecRIBSupport { .withNodeIdentifier(new NodeIdentifier(FlowspecRoutes.QNAME)) .addChild(ImmutableNodes.mapNodeBuilder(FlowspecRoute.QNAME).build()).build()).build(); - private FlowspecIpv4RIBSupport() { + public FlowspecIpv4RIBSupport(SimpleFlowspecExtensionProviderContext context) { super(FlowspecRoutesCase.class, FlowspecRoutes.class, FlowspecRoute.class); + FS_PARSER = new SimpleFlowspecIpv4NlriParser(context.getFlowspecIpv4TypeRegistry()); } - static FlowspecIpv4RIBSupport getInstance() { - return SINGLETON; + static FlowspecIpv4RIBSupport getInstance(SimpleFlowspecExtensionProviderContext context) { + return new FlowspecIpv4RIBSupport(context); } @Override @@ -57,7 +56,7 @@ final class FlowspecIpv4RIBSupport extends AbstractFlowspecRIBSupport { } @Override - protected AbstractFSNlriParser getParser() { + protected AbstractFlowspecNlriParser getParser() { return FS_PARSER; } diff --git a/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/FlowspecIpv6RIBSupport.java b/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/FlowspecIpv6RIBSupport.java index 443558b8bd..c5dfa7adac 100644 --- a/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/FlowspecIpv6RIBSupport.java +++ b/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/FlowspecIpv6RIBSupport.java @@ -21,9 +21,7 @@ import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes; public final class FlowspecIpv6RIBSupport extends AbstractFlowspecRIBSupport { - private static final FSIpv6NlriParser FS_PARSER = new FSIpv6NlriParser(); - - private static final FlowspecIpv6RIBSupport SINGLETON = new FlowspecIpv6RIBSupport(); + private SimpleFlowspecIpv6NlriParser FS_PARSER; private final NodeIdentifier destinationNid = new NodeIdentifier(DestinationFlowspec.QNAME); private final NodeIdentifier routeNid = new NodeIdentifier(FlowspecRoute.QNAME); @@ -33,12 +31,13 @@ public final class FlowspecIpv6RIBSupport extends AbstractFlowspecRIBSupport { .withNodeIdentifier(new NodeIdentifier(FlowspecIpv6Routes.QNAME)) .addChild(ImmutableNodes.mapNodeBuilder(FlowspecRoute.QNAME).build()).build()).build(); - private FlowspecIpv6RIBSupport() { + public FlowspecIpv6RIBSupport(SimpleFlowspecExtensionProviderContext context) { super(FlowspecIpv6RoutesCase.class, FlowspecIpv6Routes.class, FlowspecRoute.class); + FS_PARSER = new SimpleFlowspecIpv6NlriParser(context.getFlowspecIpv6TypeRegistry()); } - static FlowspecIpv6RIBSupport getInstance() { - return SINGLETON; + static FlowspecIpv6RIBSupport getInstance(SimpleFlowspecExtensionProviderContext context) { + return new FlowspecIpv6RIBSupport(context); } @Override @@ -57,7 +56,7 @@ public final class FlowspecIpv6RIBSupport extends AbstractFlowspecRIBSupport { } @Override - protected AbstractFSNlriParser getParser() { + protected AbstractFlowspecNlriParser getParser() { return FS_PARSER; } diff --git a/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/RIBActivator.java b/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/RIBActivator.java index 569267b266..48d480da52 100644 --- a/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/RIBActivator.java +++ b/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/RIBActivator.java @@ -15,12 +15,20 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flow import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv4AddressFamily; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv6AddressFamily; -public class RIBActivator extends AbstractRIBExtensionProviderActivator { +public final class RIBActivator extends AbstractRIBExtensionProviderActivator { + + private final SimpleFlowspecExtensionProviderContext fs_context; + + public RIBActivator(SimpleFlowspecExtensionProviderContext context) { + super(); + this.fs_context = context; + } + @Override protected List startRIBExtensionProviderImpl(final RIBExtensionProviderContext context) { final List regs = new ArrayList<>(); - regs.add(context.registerRIBSupport(Ipv4AddressFamily.class, FlowspecSubsequentAddressFamily.class, FlowspecIpv4RIBSupport.getInstance())); - regs.add(context.registerRIBSupport(Ipv6AddressFamily.class, FlowspecSubsequentAddressFamily.class, FlowspecIpv6RIBSupport.getInstance())); + regs.add(context.registerRIBSupport(Ipv4AddressFamily.class, FlowspecSubsequentAddressFamily.class, FlowspecIpv4RIBSupport.getInstance(fs_context))); + regs.add(context.registerRIBSupport(Ipv6AddressFamily.class, FlowspecSubsequentAddressFamily.class, FlowspecIpv6RIBSupport.getInstance(fs_context))); return regs; } } diff --git a/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/SimpleFlowspecExtensionProviderContext.java b/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/SimpleFlowspecExtensionProviderContext.java new file mode 100644 index 0000000000..4b8219de2d --- /dev/null +++ b/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/SimpleFlowspecExtensionProviderContext.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.protocol.bgp.flowspec; + +import org.opendaylight.protocol.bgp.flowspec.SimpleFlowspecTypeRegistry; +import org.opendaylight.protocol.bgp.flowspec.handlers.FlowspecTypeParser; +import org.opendaylight.protocol.bgp.flowspec.handlers.FlowspecTypeSerializer; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.FlowspecType; + +public class SimpleFlowspecExtensionProviderContext { + + private final SimpleFlowspecTypeRegistry flowspecIpv4TypeRegistry = new SimpleFlowspecTypeRegistry(); + + private final SimpleFlowspecTypeRegistry flowspecIpv6TypeRegistry = new SimpleFlowspecTypeRegistry(); + + public AutoCloseable registerFlowspecIpv4TypeParser(final int type, final FlowspecTypeParser parser) { + return this.flowspecIpv4TypeRegistry.registerFlowspecTypeParser(type, parser); + } + + public AutoCloseable registerFlowspecIpv4TypeSerializer(final Class typeClass, final FlowspecTypeSerializer serializer) { + return this.flowspecIpv4TypeRegistry.registerFlowspecTypeSerializer(typeClass, serializer); + } + + public AutoCloseable registerFlowspecIpv6TypeParser(final int type, final FlowspecTypeParser parser) { + return this.flowspecIpv6TypeRegistry.registerFlowspecTypeParser(type, parser); + } + + public AutoCloseable registerFlowspecIpv6TypeSerializer(final Class typeClass, final FlowspecTypeSerializer serializer) { + return this.flowspecIpv6TypeRegistry.registerFlowspecTypeSerializer(typeClass, serializer); + } + + public SimpleFlowspecTypeRegistry getFlowspecIpv4TypeRegistry() { + return this.flowspecIpv4TypeRegistry; + } + + public SimpleFlowspecTypeRegistry getFlowspecIpv6TypeRegistry() { + return this.flowspecIpv6TypeRegistry; + } +} diff --git a/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/FSIpv4NlriParser.java b/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/SimpleFlowspecIpv4NlriParser.java similarity index 65% rename from bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/FSIpv4NlriParser.java rename to bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/SimpleFlowspecIpv4NlriParser.java index 6dbb184885..65329ac7ce 100644 --- a/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/FSIpv4NlriParser.java +++ b/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/SimpleFlowspecIpv4NlriParser.java @@ -13,16 +13,11 @@ import io.netty.buffer.ByteBuf; import java.util.ArrayList; import java.util.List; import java.util.Set; -import org.opendaylight.protocol.util.BitArray; -import org.opendaylight.protocol.util.Ipv4Util; +import org.opendaylight.protocol.bgp.flowspec.SimpleFlowspecTypeRegistry; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.Fragment; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.NumericOperand; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.Flowspec; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.FlowspecBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.FlowspecType; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.FragmentCase; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.FragmentCaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.ipv4.flowspec.flowspec.type.DestinationPrefixCase; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.ipv4.flowspec.flowspec.type.DestinationPrefixCaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.ipv4.flowspec.flowspec.type.ProtocolIpCase; @@ -32,8 +27,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flow import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.ipv4.flowspec.flowspec.type.protocol.ip._case.ProtocolIps; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.ipv4.flowspec.flowspec.type.protocol.ip._case.ProtocolIpsBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationFlowspecCase; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationFlowspecCaseBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.destination.flowspec._case.DestinationFlowspecBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.Attributes1; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.Attributes2; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.destination.DestinationType; @@ -46,58 +39,19 @@ import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild; import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListEntryNode; import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListNode; -public final class FSIpv4NlriParser extends AbstractFSNlriParser { - - private static final int IP_PROTOCOL_VALUE = 3; +public final class SimpleFlowspecIpv4NlriParser extends AbstractFlowspecNlriParser { @VisibleForTesting static final NodeIdentifier PROTOCOL_IP_NID = new NodeIdentifier(ProtocolIps.QNAME); - @Override - protected void serializeMpReachNlri(final Attributes1 pathAttributes, final ByteBuf byteAggregator) { - if (pathAttributes == null) { - return; - } - final AdvertizedRoutes routes = (pathAttributes.getMpReachNlri()).getAdvertizedRoutes(); - if (routes != null && routes.getDestinationType() instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationFlowspecCase) { - final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationFlowspecCase flowspecCase = (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationFlowspecCase) routes.getDestinationType(); - serializeNlri(flowspecCase.getDestinationFlowspec().getFlowspec(), byteAggregator); - } - } - - @Override - protected void serializeMpUnreachNlri(final Attributes2 pathAttributes, final ByteBuf byteAggregator) { - if (pathAttributes == null) { - return; - } - final MpUnreachNlri mpUnreachNlri = pathAttributes.getMpUnreachNlri(); - if (mpUnreachNlri.getWithdrawnRoutes() != null && mpUnreachNlri.getWithdrawnRoutes().getDestinationType() instanceof DestinationFlowspecCase) { - final DestinationFlowspecCase flowspecCase = (DestinationFlowspecCase) mpUnreachNlri.getWithdrawnRoutes().getDestinationType(); - serializeNlri(flowspecCase.getDestinationFlowspec().getFlowspec(), byteAggregator); - } - } - - @Override - protected void serializeSpecificFSType(final FlowspecType value, final ByteBuf nlriByteBuf) { - if (value instanceof DestinationPrefixCase) { - nlriByteBuf.writeByte(DESTINATION_PREFIX_VALUE); - nlriByteBuf.writeBytes(Ipv4Util.bytesForPrefixBegin(((DestinationPrefixCase) value).getDestinationPrefix())); - } else if (value instanceof SourcePrefixCase) { - nlriByteBuf.writeByte(SOURCE_PREFIX_VALUE); - nlriByteBuf.writeBytes(Ipv4Util.bytesForPrefixBegin(((SourcePrefixCase) value).getSourcePrefix())); - } else if (value instanceof ProtocolIpCase) { - nlriByteBuf.writeByte(IP_PROTOCOL_VALUE); - NumericOneByteOperandParser.INSTANCE.serialize(((ProtocolIpCase) value).getProtocolIps(), nlriByteBuf); - } else if (value instanceof FragmentCase) { - nlriByteBuf.writeByte(FRAGMENT_VALUE); - serializeFragments(((FragmentCase) value).getFragments(), nlriByteBuf); - } + public SimpleFlowspecIpv4NlriParser(SimpleFlowspecTypeRegistry flowspecTypeRegistry) { + this.flowspecTypeRegistry = flowspecTypeRegistry; } @Override - DestinationType createWidthdrawnDestinationType(final List dst) { - return new DestinationFlowspecCaseBuilder().setDestinationFlowspec( - new DestinationFlowspecBuilder().setFlowspec( + DestinationType createWithdrawnDestinationType(final List dst) { + return new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationFlowspecCaseBuilder().setDestinationFlowspec( + new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.destination.flowspec._case.DestinationFlowspecBuilder().setFlowspec( dst).build()).build(); } @@ -109,55 +63,15 @@ public final class FSIpv4NlriParser extends AbstractFSNlriParser { } @Override - protected void setSpecificFlowspecType(final FlowspecBuilder builder, final short type, final ByteBuf nlri) { - switch (type) { - case DESTINATION_PREFIX_VALUE: - builder.setFlowspecType(new DestinationPrefixCaseBuilder().setDestinationPrefix(Ipv4Util.prefixForByteBuf(nlri)).build()); - break; - case SOURCE_PREFIX_VALUE: - builder.setFlowspecType(new SourcePrefixCaseBuilder().setSourcePrefix(Ipv4Util.prefixForByteBuf(nlri)).build()); - break; - case IP_PROTOCOL_VALUE: - builder.setFlowspecType(new ProtocolIpCaseBuilder().setProtocolIps(parseProtocolIp(nlri)).build()); - break; - case FRAGMENT_VALUE: - builder.setFlowspecType(new FragmentCaseBuilder().setFragments(parseFragment(nlri)).build()); - break; - default: - break; + protected void serializeMpReachNlri(final Attributes1 pathAttributes, final ByteBuf byteAggregator) { + if (pathAttributes == null) { + return; } - } - - private static List parseProtocolIp(final ByteBuf nlri) { - final List ips = new ArrayList<>(); - boolean end = false; - // we can do this as all fields will be rewritten in the cycle - final ProtocolIpsBuilder builder = new ProtocolIpsBuilder(); - while (!end) { - final byte b = nlri.readByte(); - final NumericOperand op = NumericOneByteOperandParser.INSTANCE.parse(b); - builder.setOp(op); - builder.setValue(nlri.readUnsignedByte()); - end = op.isEndOfList(); - ips.add(builder.build()); + final AdvertizedRoutes routes = (pathAttributes.getMpReachNlri()).getAdvertizedRoutes(); + if (routes != null && routes.getDestinationType() instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationFlowspecCase) { + final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationFlowspecCase flowspecCase = (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationFlowspecCase) routes.getDestinationType(); + serializeNlri(flowspecCase.getDestinationFlowspec().getFlowspec(), byteAggregator); } - return ips; - } - - @Override - protected Fragment parseFragment(final byte fragment) { - final BitArray bs = BitArray.valueOf(fragment); - return new Fragment(bs.get(DONT_FRAGMENT), bs.get(FIRST_FRAGMENT), bs.get(IS_A_FRAGMENT), bs.get(LAST_FRAGMENT)); - } - - @Override - protected byte serializeFragment(final Fragment fragment) { - final BitArray bs = new BitArray(Byte.SIZE); - bs.set(DONT_FRAGMENT, fragment.isDoNot()); - bs.set(FIRST_FRAGMENT, fragment.isFirst()); - bs.set(IS_A_FRAGMENT, fragment.isIsA()); - bs.set(LAST_FRAGMENT, fragment.isLast()); - return bs.toByte(); } @Override @@ -206,4 +120,15 @@ public final class FSIpv4NlriParser extends AbstractFSNlriParser { } } + @Override + protected void serializeMpUnreachNlri(final Attributes2 pathAttributes, final ByteBuf byteAggregator) { + if (pathAttributes == null) { + return; + } + final MpUnreachNlri mpUnreachNlri = pathAttributes.getMpUnreachNlri(); + if (mpUnreachNlri.getWithdrawnRoutes() != null && mpUnreachNlri.getWithdrawnRoutes().getDestinationType() instanceof DestinationFlowspecCase) { + final DestinationFlowspecCase flowspecCase = (DestinationFlowspecCase) mpUnreachNlri.getWithdrawnRoutes().getDestinationType(); + serializeNlri(flowspecCase.getDestinationFlowspec().getFlowspec(), byteAggregator); + } + } } diff --git a/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/FSIpv6NlriParser.java b/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/SimpleFlowspecIpv6NlriParser.java similarity index 60% rename from bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/FSIpv6NlriParser.java rename to bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/SimpleFlowspecIpv6NlriParser.java index 13864c6fb7..bbbfc7b68a 100644 --- a/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/FSIpv6NlriParser.java +++ b/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/SimpleFlowspecIpv6NlriParser.java @@ -8,23 +8,15 @@ package org.opendaylight.protocol.bgp.flowspec; import com.google.common.base.Optional; -import com.google.common.primitives.Bytes; import io.netty.buffer.ByteBuf; -import io.netty.buffer.Unpooled; import java.util.ArrayList; import java.util.List; import java.util.Set; -import org.opendaylight.protocol.util.BitArray; -import org.opendaylight.protocol.util.ByteArray; -import org.opendaylight.protocol.util.Ipv6Util; +import org.opendaylight.protocol.bgp.flowspec.SimpleFlowspecTypeRegistry; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Prefix; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.Fragment; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.NumericOperand; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.Flowspec; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.FlowspecBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.FlowspecType; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.FragmentCase; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.FragmentCaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.ipv6.flowspec.flowspec.type.DestinationIpv6PrefixCase; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.ipv6.flowspec.flowspec.type.DestinationIpv6PrefixCaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.ipv6.flowspec.flowspec.type.FlowLabelCase; @@ -38,8 +30,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flow import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.ipv6.flowspec.flowspec.type.next.header._case.NextHeaders; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.ipv6.flowspec.flowspec.type.next.header._case.NextHeadersBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationFlowspecIpv6Case; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationFlowspecIpv6CaseBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.destination.flowspec.ipv6._case.DestinationFlowspecBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.Attributes1; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.Attributes2; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.destination.DestinationType; @@ -52,163 +42,39 @@ import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild; import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListEntryNode; import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListNode; -public final class FSIpv6NlriParser extends AbstractFSNlriParser { - - private static final int NEXT_HEADER_VALUE = 3; - private static final int FLOW_LABLE_VALUE = 13; +public final class SimpleFlowspecIpv6NlriParser extends AbstractFlowspecNlriParser { static final NodeIdentifier NEXT_HEADER_NID = new NodeIdentifier(NextHeaders.QNAME); static final NodeIdentifier FLOW_LABEL_NID = new NodeIdentifier(FlowLabel.QNAME); - @Override - protected void serializeMpReachNlri(final Attributes1 pathAttributes, final ByteBuf byteAggregator) { - if (pathAttributes == null) { - return; - } - final AdvertizedRoutes routes = (pathAttributes.getMpReachNlri()).getAdvertizedRoutes(); - if (routes != null && routes.getDestinationType() instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationFlowspecIpv6Case) { - final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationFlowspecIpv6Case flowspecCase = (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationFlowspecIpv6Case) routes.getDestinationType(); - serializeNlri(flowspecCase.getDestinationFlowspec().getFlowspec(), byteAggregator); - } - } - - @Override - protected void serializeMpUnreachNlri(final Attributes2 pathAttributes, final ByteBuf byteAggregator) { - if (pathAttributes == null) { - return; - } - final MpUnreachNlri mpUnreachNlri = pathAttributes.getMpUnreachNlri(); - if (mpUnreachNlri.getWithdrawnRoutes() != null && mpUnreachNlri.getWithdrawnRoutes().getDestinationType() instanceof DestinationFlowspecIpv6Case) { - final DestinationFlowspecIpv6Case flowspecCase = (DestinationFlowspecIpv6Case) mpUnreachNlri.getWithdrawnRoutes().getDestinationType(); - serializeNlri(flowspecCase.getDestinationFlowspec().getFlowspec(), byteAggregator); - } - } - - @Override - protected void serializeSpecificFSType(final FlowspecType value, final ByteBuf nlriByteBuf) { - if (value instanceof DestinationIpv6PrefixCase) { - nlriByteBuf.writeByte(DESTINATION_PREFIX_VALUE); - nlriByteBuf.writeBytes(insertOffsetByte(Ipv6Util.bytesForPrefixBegin(((DestinationIpv6PrefixCase) value).getDestinationPrefix()))); - } else if (value instanceof SourceIpv6PrefixCase) { - nlriByteBuf.writeByte(SOURCE_PREFIX_VALUE); - nlriByteBuf.writeBytes(insertOffsetByte(Ipv6Util.bytesForPrefixBegin(((SourceIpv6PrefixCase) value).getSourcePrefix()))); - } else if (value instanceof NextHeaderCase) { - nlriByteBuf.writeByte(NEXT_HEADER_VALUE); - NumericOneByteOperandParser.INSTANCE.serialize(((NextHeaderCase) value).getNextHeaders(), nlriByteBuf); - } else if (value instanceof FragmentCase) { - nlriByteBuf.writeByte(FRAGMENT_VALUE); - serializeFragments(((FragmentCase) value).getFragments(), nlriByteBuf); - } else if (value instanceof FlowLabelCase) { - nlriByteBuf.writeByte(FLOW_LABLE_VALUE); - serializeNumericFourByteValue(((FlowLabelCase) value).getFlowLabel(), nlriByteBuf); - } - } - - private static void serializeNumericFourByteValue(final List list, final ByteBuf nlriByteBuf) { - for (final FlowLabel item : list) { - final ByteBuf protoBuf = Unpooled.buffer(); - Util.writeShortest(item.getValue().intValue(), protoBuf); - NumericOneByteOperandParser.INSTANCE.serialize(item.getOp(), protoBuf.readableBytes(), nlriByteBuf); - nlriByteBuf.writeBytes(protoBuf); - } - } - - private static byte[] insertOffsetByte(final byte[] ipPrefix) { - // income - return Bytes.concat(new byte[] { ipPrefix[0] }, new byte[] { 0 }, ByteArray.subByte(ipPrefix, 1 , ipPrefix.length-1)); + public SimpleFlowspecIpv6NlriParser(SimpleFlowspecTypeRegistry flowspecTypeRegistry) { + this.flowspecTypeRegistry = flowspecTypeRegistry; } @Override - protected byte serializeFragment(final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.Fragment fragment) { - final BitArray bs = new BitArray(Byte.SIZE); - bs.set(DONT_FRAGMENT, Boolean.FALSE); - bs.set(FIRST_FRAGMENT, fragment.isFirst()); - bs.set(IS_A_FRAGMENT, fragment.isIsA()); - bs.set(LAST_FRAGMENT, fragment.isLast()); - return bs.toByte(); - } - - @Override - DestinationType createWidthdrawnDestinationType(final List dst) { - return new DestinationFlowspecIpv6CaseBuilder().setDestinationFlowspec( - new DestinationFlowspecBuilder().setFlowspec( + DestinationType createWithdrawnDestinationType(final List dst) { + return new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationFlowspecIpv6CaseBuilder().setDestinationFlowspec( + new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.destination.flowspec.ipv6._case.DestinationFlowspecBuilder().setFlowspec( dst).build()).build(); } @Override DestinationType createAdvertizedRoutesDestinationType(final List dst) { return new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationFlowspecIpv6CaseBuilder() - .setDestinationFlowspec(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.update.attributes.mp.reach.nlri.advertized.routes.destination.type.destination.flowspec.ipv6._case.DestinationFlowspecBuilder() - .setFlowspec(dst).build()).build(); + .setDestinationFlowspec(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.update.attributes.mp.reach.nlri.advertized.routes.destination.type.destination.flowspec.ipv6._case.DestinationFlowspecBuilder() + .setFlowspec(dst).build()).build(); } @Override - protected void setSpecificFlowspecType(final FlowspecBuilder builder, final short type, final ByteBuf nlri) { - switch (type) { - case DESTINATION_PREFIX_VALUE: - builder.setFlowspecType(new DestinationIpv6PrefixCaseBuilder().setDestinationPrefix(parseIpv6Prefix(nlri)).build()); - break; - case SOURCE_PREFIX_VALUE: - builder.setFlowspecType(new SourceIpv6PrefixCaseBuilder().setSourcePrefix(parseIpv6Prefix(nlri)).build()); - break; - case NEXT_HEADER_VALUE: - builder.setFlowspecType(new NextHeaderCaseBuilder().setNextHeaders(parseNextHeader(nlri)).build()); - break; - case FRAGMENT_VALUE: - builder.setFlowspecType(new FragmentCaseBuilder().setFragments(parseFragment(nlri)).build()); - break; - case FLOW_LABLE_VALUE: - builder.setFlowspecType(new FlowLabelCaseBuilder().setFlowLabel(parseFlowLabel(nlri)).build()); - break; - default: - break; - } - } - - private static Ipv6Prefix parseIpv6Prefix(final ByteBuf nlri) { - final int bitLength = nlri.readUnsignedByte(); - // in case of ipv6 prefix we don't need to skip offset - nlri.readUnsignedByte(); - return Ipv6Util.prefixForBytes(ByteArray.readBytes(nlri, bitLength / Byte.SIZE), bitLength); - } - - @Override - protected Fragment parseFragment(final byte fragment) { - final BitArray bs = BitArray.valueOf(fragment); - return new Fragment(Boolean.FALSE, bs.get(FIRST_FRAGMENT), bs.get(IS_A_FRAGMENT), bs.get(LAST_FRAGMENT)); - } - - private static List parseNextHeader(final ByteBuf nlri) { - final List 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(nlri.readUnsignedByte()); - end = op.isEndOfList(); - headers.add(builder.build()); + protected void serializeMpReachNlri(final Attributes1 pathAttributes, final ByteBuf byteAggregator) { + if (pathAttributes == null) { + return; } - return headers; - } - - private static List parseFlowLabel(final ByteBuf nlri) { - final List 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(ByteArray.bytesToLong(ByteArray.readBytes(nlri, length))); - end = op.isEndOfList(); - labels.add(builder.build()); + final AdvertizedRoutes routes = (pathAttributes.getMpReachNlri()).getAdvertizedRoutes(); + if (routes != null && routes.getDestinationType() instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationFlowspecIpv6Case) { + final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationFlowspecIpv6Case flowspecCase = (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationFlowspecIpv6Case) routes.getDestinationType(); + serializeNlri(flowspecCase.getDestinationFlowspec().getFlowspec(), byteAggregator); } - return labels; } @Override @@ -297,4 +163,15 @@ public final class FSIpv6NlriParser extends AbstractFSNlriParser { return buffer.toString(); } + @Override + protected void serializeMpUnreachNlri(final Attributes2 pathAttributes, final ByteBuf byteAggregator) { + if (pathAttributes == null) { + return; + } + final MpUnreachNlri mpUnreachNlri = pathAttributes.getMpUnreachNlri(); + if (mpUnreachNlri.getWithdrawnRoutes() != null && mpUnreachNlri.getWithdrawnRoutes().getDestinationType() instanceof DestinationFlowspecIpv6Case) { + final DestinationFlowspecIpv6Case flowspecCase = (DestinationFlowspecIpv6Case) mpUnreachNlri.getWithdrawnRoutes().getDestinationType(); + serializeNlri(flowspecCase.getDestinationFlowspec().getFlowspec(), byteAggregator); + } + } } diff --git a/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/SimpleFlowspecTypeRegistry.java b/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/SimpleFlowspecTypeRegistry.java new file mode 100644 index 0000000000..c770eb0cea --- /dev/null +++ b/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/SimpleFlowspecTypeRegistry.java @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.protocol.bgp.flowspec; + +import com.google.common.base.Preconditions; +import io.netty.buffer.ByteBuf; +import org.opendaylight.protocol.bgp.flowspec.handlers.FlowspecTypeParser; +import org.opendaylight.protocol.bgp.flowspec.handlers.FlowspecTypeSerializer; +import org.opendaylight.protocol.concepts.HandlerRegistry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.FlowspecType; +import org.opendaylight.yangtools.yang.binding.DataContainer; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class SimpleFlowspecTypeRegistry { + + private static final Logger LOG = LoggerFactory.getLogger(SimpleFlowspecTypeRegistry.class); + + private final HandlerRegistry handlers = new HandlerRegistry<>(); + + public FlowspecTypeParser getFlowspecTypeParser(final short type) { + return this.handlers.getParser(type); + } + + public FlowspecTypeSerializer getFlowspecTypeSerializer(final FlowspecType fsType) { + return this.handlers.getSerializer(fsType.getImplementedInterface()); + } + + public void serializeFlowspecType(final FlowspecType fsType, final ByteBuf output) { + final FlowspecTypeSerializer serializer = this.handlers.getSerializer(fsType.getImplementedInterface()); + Preconditions.checkNotNull(serializer, "serializer for flowspec type {} is not registered.", fsType); + serializer.serializeType(fsType, output); + } + + public FlowspecType parseFlowspecType(ByteBuf buffer) { + final short type = buffer.readUnsignedByte(); + final FlowspecTypeParser parser = this.handlers.getParser(type); + Preconditions.checkNotNull(parser, "parser for flowspec type {} is not registered", type); + return parser.parseType(buffer); + } + + public AutoCloseable registerFlowspecTypeParser(final int type, final FlowspecTypeParser parser) { + return this.handlers.registerParser(type, parser); + } + + public AutoCloseable registerFlowspecTypeSerializer(final Class typeClass, final FlowspecTypeSerializer serializer) { + return this.handlers.registerSerializer(typeClass, serializer); + } +} diff --git a/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/handlers/AbstractFSFragmentHandler.java b/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/handlers/AbstractFSFragmentHandler.java new file mode 100644 index 0000000000..80ea291bc3 --- /dev/null +++ b/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/handlers/AbstractFSFragmentHandler.java @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.protocol.bgp.flowspec.handlers; + +import com.google.common.base.Preconditions; +import io.netty.buffer.ByteBuf; +import java.util.ArrayList; +import java.util.List; +import org.opendaylight.protocol.bgp.flowspec.BitmaskOperandParser; +import org.opendaylight.protocol.bgp.flowspec.handlers.FlowspecTypeParser; +import org.opendaylight.protocol.bgp.flowspec.handlers.FlowspecTypeSerializer; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.BitmaskOperand; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.Fragment; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.FlowspecType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.FragmentCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.FragmentCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.fragment._case.Fragments; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.flowspec.type.fragment._case.FragmentsBuilder; + +public abstract class AbstractFSFragmentHandler implements FlowspecTypeParser, FlowspecTypeSerializer { + + public static final int FRAGMENT_VALUE = 12; + + protected static final int LAST_FRAGMENT = 4; + protected static final int FIRST_FRAGMENT = 5; + protected static final int IS_A_FRAGMENT = 6; + protected static final int DONT_FRAGMENT = 7; + + protected abstract Fragment parseFragment(final byte fragment); + protected abstract byte serializeFragment(final Fragment fragment); + + @Override + public void serializeType(FlowspecType fsType, ByteBuf output) { + Preconditions.checkArgument(fsType instanceof FragmentCase, "FragmentCase class is mandatory!"); + output.writeByte(FRAGMENT_VALUE); + serializeFragments(((FragmentCase) fsType).getFragments(), output); + } + + @Override + public FlowspecType parseType(ByteBuf buffer) { + if (buffer == null) { + return null; + } + return new FragmentCaseBuilder().setFragments(parseFragments(buffer)).build(); + } + + protected final void serializeFragments(final List fragments, final ByteBuf nlriByteBuf) { + for (final Fragments fragment : fragments) { + BitmaskOperandParser.INSTANCE.serialize(fragment.getOp(), 1, nlriByteBuf); + nlriByteBuf.writeByte(serializeFragment(fragment.getValue())); + } + } + + protected final List parseFragments(final ByteBuf nlri) { + final List fragments = new ArrayList<>(); + boolean end = false; + // we can do this as all fields will be rewritten in the cycle + final FragmentsBuilder builder = new FragmentsBuilder(); + while (!end) { + final byte b = nlri.readByte(); + final BitmaskOperand op = BitmaskOperandParser.INSTANCE.parse(b); + builder.setOp(op); + builder.setValue(parseFragment(nlri.readByte())); + end = op.isEndOfList(); + fragments.add(builder.build()); + } + return fragments; + } +} diff --git a/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/handlers/FSIpv4DestinationPrefixHandler.java b/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/handlers/FSIpv4DestinationPrefixHandler.java new file mode 100644 index 0000000000..a2cff5e663 --- /dev/null +++ b/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/handlers/FSIpv4DestinationPrefixHandler.java @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.protocol.bgp.flowspec.handlers; + +import com.google.common.base.Preconditions; +import io.netty.buffer.ByteBuf; +import org.opendaylight.protocol.bgp.flowspec.handlers.FlowspecTypeParser; +import org.opendaylight.protocol.bgp.flowspec.handlers.FlowspecTypeSerializer; +import org.opendaylight.protocol.util.Ipv4Util; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.FlowspecType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.ipv4.flowspec.flowspec.type.DestinationPrefixCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.ipv4.flowspec.flowspec.type.DestinationPrefixCaseBuilder; + +public final class FSIpv4DestinationPrefixHandler implements FlowspecTypeParser, FlowspecTypeSerializer { + public static final int DESTINATION_PREFIX_VALUE = 1; + + @Override + public void serializeType(FlowspecType value, ByteBuf output) { + Preconditions.checkArgument(value instanceof DestinationPrefixCase, "DestinationPrefixCase class is mandatory!"); + output.writeByte(DESTINATION_PREFIX_VALUE); + output.writeBytes(Ipv4Util.bytesForPrefixBegin(((DestinationPrefixCase) value).getDestinationPrefix())); + } + + @Override + public FlowspecType parseType(ByteBuf buffer) { + Preconditions.checkNotNull(buffer, "input buffer is null, missing data to parse."); + return new DestinationPrefixCaseBuilder().setDestinationPrefix(Ipv4Util.prefixForByteBuf(buffer)).build(); + } +} diff --git a/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/handlers/FSIpv4FragmentHandler.java b/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/handlers/FSIpv4FragmentHandler.java new file mode 100644 index 0000000000..c3baa88b2a --- /dev/null +++ b/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/handlers/FSIpv4FragmentHandler.java @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.protocol.bgp.flowspec.handlers; + +import org.opendaylight.protocol.util.BitArray; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.Fragment; + +public class FSIpv4FragmentHandler extends AbstractFSFragmentHandler { + + @Override + protected final Fragment parseFragment(final byte fragment) { + final BitArray bs = BitArray.valueOf(fragment); + return new Fragment(bs.get(DONT_FRAGMENT), bs.get(FIRST_FRAGMENT), bs.get(IS_A_FRAGMENT), bs.get(LAST_FRAGMENT)); + } + + @Override + protected final byte serializeFragment(final Fragment fragment) { + final BitArray bs = new BitArray(Byte.SIZE); + bs.set(DONT_FRAGMENT, fragment.isDoNot()); + bs.set(FIRST_FRAGMENT, fragment.isFirst()); + bs.set(IS_A_FRAGMENT, fragment.isIsA()); + bs.set(LAST_FRAGMENT, fragment.isLast()); + return bs.toByte(); + } +} diff --git a/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/handlers/FSIpv4SourcePrefixHandler.java b/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/handlers/FSIpv4SourcePrefixHandler.java new file mode 100644 index 0000000000..d5f12b8410 --- /dev/null +++ b/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/handlers/FSIpv4SourcePrefixHandler.java @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.protocol.bgp.flowspec.handlers; + +import com.google.common.base.Preconditions; +import io.netty.buffer.ByteBuf; +import org.opendaylight.protocol.bgp.flowspec.handlers.FlowspecTypeParser; +import org.opendaylight.protocol.bgp.flowspec.handlers.FlowspecTypeSerializer; +import org.opendaylight.protocol.util.Ipv4Util; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.FlowspecType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.ipv4.flowspec.flowspec.type.SourcePrefixCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.ipv4.flowspec.flowspec.type.SourcePrefixCaseBuilder; + +public final class FSIpv4SourcePrefixHandler implements FlowspecTypeParser, FlowspecTypeSerializer { + public static final int SOURCE_PREFIX_VALUE = 2; + + @Override + public void serializeType(FlowspecType value, ByteBuf output) { + Preconditions.checkArgument(value instanceof SourcePrefixCase, "SourcePrefixCase class is mandatory!"); + output.writeByte(SOURCE_PREFIX_VALUE); + output.writeBytes(Ipv4Util.bytesForPrefixBegin(((SourcePrefixCase) value).getSourcePrefix())); + } + + @Override + public FlowspecType parseType(ByteBuf buffer) { + Preconditions.checkNotNull(buffer, "input buffer is null, missing data to parse."); + return new SourcePrefixCaseBuilder().setSourcePrefix(Ipv4Util.prefixForByteBuf(buffer)).build(); + } +} diff --git a/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/handlers/FSIpv6DestinationPrefixHandler.java b/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/handlers/FSIpv6DestinationPrefixHandler.java new file mode 100644 index 0000000000..90c7805f5f --- /dev/null +++ b/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/handlers/FSIpv6DestinationPrefixHandler.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.protocol.bgp.flowspec.handlers; + +import com.google.common.base.Preconditions; +import com.google.common.primitives.Bytes; +import io.netty.buffer.ByteBuf; +import org.opendaylight.protocol.bgp.flowspec.handlers.FlowspecTypeParser; +import org.opendaylight.protocol.bgp.flowspec.handlers.FlowspecTypeSerializer; +import org.opendaylight.protocol.util.ByteArray; +import org.opendaylight.protocol.util.Ipv6Util; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Prefix; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.FlowspecType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.ipv6.flowspec.flowspec.type.DestinationIpv6PrefixCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.ipv6.flowspec.flowspec.type.DestinationIpv6PrefixCaseBuilder; + +public final class FSIpv6DestinationPrefixHandler implements FlowspecTypeParser, FlowspecTypeSerializer { + public static final int IPV6_DESTINATION_PREFIX_VALUE = 1; + + @Override + public void serializeType(FlowspecType value, ByteBuf output) { + Preconditions.checkArgument(value instanceof DestinationIpv6PrefixCase, "DestinationIpv6PrefixCase class is mandatory!"); + output.writeByte(IPV6_DESTINATION_PREFIX_VALUE); + output.writeBytes(insertOffsetByte(Ipv6Util.bytesForPrefixBegin(((DestinationIpv6PrefixCase) value).getDestinationPrefix()))); + } + + @Override + public FlowspecType parseType(ByteBuf buffer) { + Preconditions.checkNotNull(buffer, "input buffer is null, missing data to parse."); + return new DestinationIpv6PrefixCaseBuilder().setDestinationPrefix(parseIpv6Prefix(buffer)).build(); + } + + private static Ipv6Prefix parseIpv6Prefix(final ByteBuf nlri) { + final int bitLength = nlri.readUnsignedByte(); + nlri.readUnsignedByte(); + return Ipv6Util.prefixForBytes(ByteArray.readBytes(nlri, bitLength / Byte.SIZE), bitLength); + } + + private static byte[] insertOffsetByte(final byte[] ipPrefix) { + // income + return Bytes.concat(new byte[] { ipPrefix[0] }, new byte[] { 0 }, ByteArray.subByte(ipPrefix, 1 , ipPrefix.length-1)); + } +} diff --git a/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/handlers/FSIpv6FragmentHandler.java b/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/handlers/FSIpv6FragmentHandler.java new file mode 100644 index 0000000000..a327c86ee5 --- /dev/null +++ b/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/handlers/FSIpv6FragmentHandler.java @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.protocol.bgp.flowspec.handlers; + +import org.opendaylight.protocol.util.BitArray; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.Fragment; + +public class FSIpv6FragmentHandler extends AbstractFSFragmentHandler { + + @Override + protected final Fragment parseFragment(final byte fragment) { + final BitArray bs = BitArray.valueOf(fragment); + return new Fragment(Boolean.FALSE, bs.get(FIRST_FRAGMENT), bs.get(IS_A_FRAGMENT), bs.get(LAST_FRAGMENT)); + } + + @Override + protected final byte serializeFragment(final Fragment fragment) { + final BitArray bs = new BitArray(Byte.SIZE); + bs.set(DONT_FRAGMENT, Boolean.FALSE); + bs.set(FIRST_FRAGMENT, fragment.isFirst()); + bs.set(IS_A_FRAGMENT, fragment.isIsA()); + bs.set(LAST_FRAGMENT, fragment.isLast()); + return bs.toByte(); + } +} diff --git a/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/handlers/FSIpv6SourcePrefixHandler.java b/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/handlers/FSIpv6SourcePrefixHandler.java new file mode 100644 index 0000000000..1c84ad2e87 --- /dev/null +++ b/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/handlers/FSIpv6SourcePrefixHandler.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.protocol.bgp.flowspec.handlers; + +import com.google.common.base.Preconditions; +import com.google.common.primitives.Bytes; +import io.netty.buffer.ByteBuf; +import org.opendaylight.protocol.bgp.flowspec.handlers.FlowspecTypeParser; +import org.opendaylight.protocol.bgp.flowspec.handlers.FlowspecTypeSerializer; +import org.opendaylight.protocol.util.ByteArray; +import org.opendaylight.protocol.util.Ipv6Util; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Prefix; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.FlowspecType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.ipv6.flowspec.flowspec.type.SourceIpv6PrefixCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.ipv6.flowspec.flowspec.type.SourceIpv6PrefixCaseBuilder; + +public final class FSIpv6SourcePrefixHandler implements FlowspecTypeParser, FlowspecTypeSerializer { + public static final int SOURCE_PREFIX_VALUE = 2; + + @Override + public void serializeType(FlowspecType value, ByteBuf output) { + Preconditions.checkArgument(value instanceof SourceIpv6PrefixCase, "SourceIpv6PrefixCase class is mandatory!"); + output.writeByte(SOURCE_PREFIX_VALUE); + output.writeBytes(insertOffsetByte(Ipv6Util.bytesForPrefixBegin(((SourceIpv6PrefixCase) value).getSourcePrefix()))); + } + + @Override + public FlowspecType parseType(ByteBuf buffer) { + Preconditions.checkNotNull(buffer, "input buffer is null, missing data to parse."); + return new SourceIpv6PrefixCaseBuilder().setSourcePrefix(parseIpv6Prefix(buffer)).build(); + } + + private static Ipv6Prefix parseIpv6Prefix(final ByteBuf nlri) { + final int bitLength = nlri.readUnsignedByte(); + nlri.readUnsignedByte(); + return Ipv6Util.prefixForBytes(ByteArray.readBytes(nlri, bitLength / Byte.SIZE), bitLength); + } + + private static byte[] insertOffsetByte(final byte[] ipPrefix) { + // income + return Bytes.concat(new byte[] { ipPrefix[0] }, new byte[] { 0 }, ByteArray.subByte(ipPrefix, 1 , ipPrefix.length-1)); + } +} diff --git a/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/handlers/FlowspecParser.java b/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/handlers/FlowspecParser.java new file mode 100644 index 0000000000..7296bb2c4e --- /dev/null +++ b/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/handlers/FlowspecParser.java @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.protocol.bgp.flowspec.handlers; + +import io.netty.buffer.ByteBuf; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.Flowspec; + +public interface FlowspecParser { + Flowspec parseFlowspec(ByteBuf buffer); +} diff --git a/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/handlers/FlowspecSerializer.java b/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/handlers/FlowspecSerializer.java new file mode 100644 index 0000000000..962e6c8088 --- /dev/null +++ b/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/handlers/FlowspecSerializer.java @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.protocol.bgp.flowspec.handlers; + +import io.netty.buffer.ByteBuf; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.Flowspec; + +public interface FlowspecSerializer { + void serializeFlowspec(Flowspec value, ByteBuf output); +} diff --git a/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/handlers/FlowspecTypeParser.java b/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/handlers/FlowspecTypeParser.java new file mode 100644 index 0000000000..2d8efa06d4 --- /dev/null +++ b/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/handlers/FlowspecTypeParser.java @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.protocol.bgp.flowspec.handlers; + +import io.netty.buffer.ByteBuf; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.FlowspecType; + +public interface FlowspecTypeParser { + FlowspecType parseType(ByteBuf buffer); +} diff --git a/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/handlers/FlowspecTypeSerializer.java b/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/handlers/FlowspecTypeSerializer.java new file mode 100644 index 0000000000..a7d8509f4b --- /dev/null +++ b/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/handlers/FlowspecTypeSerializer.java @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.protocol.bgp.flowspec.handlers; + +import io.netty.buffer.ByteBuf; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.flowspec.FlowspecType; + +public interface FlowspecTypeSerializer { + void serializeType(FlowspecType value, ByteBuf output); +} diff --git a/bgp/flowspec/src/test/java/org/opendaylight/protocol/bgp/flowspec/ActivatorTest.java b/bgp/flowspec/src/test/java/org/opendaylight/protocol/bgp/flowspec/ActivatorTest.java index 46f0a20f44..47b7d7936a 100644 --- a/bgp/flowspec/src/test/java/org/opendaylight/protocol/bgp/flowspec/ActivatorTest.java +++ b/bgp/flowspec/src/test/java/org/opendaylight/protocol/bgp/flowspec/ActivatorTest.java @@ -19,7 +19,9 @@ public class ActivatorTest { @Test public void testActivator() throws Exception { - final BGPActivator act = new BGPActivator(); + final SimpleFlowspecExtensionProviderContext fs_context = new SimpleFlowspecExtensionProviderContext(); + final FlowspecActivator activator = new FlowspecActivator(fs_context); + final BGPActivator act = new BGPActivator(fs_context, activator); final BGPExtensionProviderContext context = new SimpleBGPExtensionProviderContext(); assertNull(context.getSubsequentAddressFamilyRegistry().classForFamily(133)); act.start(context); diff --git a/bgp/flowspec/src/test/java/org/opendaylight/protocol/bgp/flowspec/FSIpv4NlriParserTest.java b/bgp/flowspec/src/test/java/org/opendaylight/protocol/bgp/flowspec/SimpleFlowspecIpv4NlriParserTest.java similarity index 79% rename from bgp/flowspec/src/test/java/org/opendaylight/protocol/bgp/flowspec/FSIpv4NlriParserTest.java rename to bgp/flowspec/src/test/java/org/opendaylight/protocol/bgp/flowspec/SimpleFlowspecIpv4NlriParserTest.java index 0f8ecc4465..3615725967 100644 --- a/bgp/flowspec/src/test/java/org/opendaylight/protocol/bgp/flowspec/FSIpv4NlriParserTest.java +++ b/bgp/flowspec/src/test/java/org/opendaylight/protocol/bgp/flowspec/SimpleFlowspecIpv4NlriParserTest.java @@ -69,10 +69,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flow import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.ipv4.flowspec.flowspec.type.SourcePrefixCaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.ipv4.flowspec.flowspec.type.protocol.ip._case.ProtocolIps; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.ipv4.flowspec.flowspec.type.protocol.ip._case.ProtocolIpsBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.ipv6.flowspec.flowspec.type.FlowLabelCase; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.ipv6.flowspec.flowspec.type.FlowLabelCaseBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.ipv6.flowspec.flowspec.type.flow.label._case.FlowLabel; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.ipv6.flowspec.flowspec.type.flow.label._case.FlowLabelBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.routes.flowspec.routes.FlowspecRoute; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationFlowspecCase; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationFlowspecCaseBuilder; @@ -92,7 +88,7 @@ import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode; import org.opendaylight.yangtools.yang.data.impl.schema.Builders; import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeAttrBuilder; -public class FSIpv4NlriParserTest { +public class SimpleFlowspecIpv4NlriParserTest { private static final byte[] REACHED_NLRI = new byte[] { 0x21, 01, 0x20, 0x0a, 00, 01, 00, @@ -110,7 +106,9 @@ public class FSIpv4NlriParserTest { 0x0b, (byte) 0x82, 0x2a, 0x0c, (byte) 0x81, (byte) 0x0e}; - private static final FSIpv4NlriParser FS_PARSER = new FSIpv4NlriParser(); + private final SimpleFlowspecExtensionProviderContext flowspecContext = new SimpleFlowspecExtensionProviderContext(); + private final FlowspecActivator fsa = new FlowspecActivator(flowspecContext); + private final SimpleFlowspecIpv4NlriParser FS_PARSER = new SimpleFlowspecIpv4NlriParser(flowspecContext.getFlowspecIpv4TypeRegistry()); @Test public void testParseMpReachNlri() throws BGPParsingException { @@ -150,7 +148,7 @@ public class FSIpv4NlriParserTest { mp.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(new DestinationFlowspecCaseBuilder().setDestinationFlowspec(new DestinationFlowspecBuilder().setFlowspec(fs).build()).build()).build()); - final FSIpv4NlriParser parser = new FSIpv4NlriParser(); + final SimpleFlowspecIpv4NlriParser parser = new SimpleFlowspecIpv4NlriParser(flowspecContext.getFlowspecIpv4TypeRegistry()); final MpReachNlriBuilder result = new MpReachNlriBuilder(); result.setAfi(Ipv4AddressFamily.class); @@ -212,16 +210,11 @@ public class FSIpv4NlriParserTest { builder.setFlowspecType(fragment); fs.add(builder.build()); - final List labels = Lists.newArrayList(new FlowLabelBuilder().setOp(new NumericOperand(false, true, true, false, false)).setValue(new Long(16777222L)).build()); - final FlowLabelCase label = new FlowLabelCaseBuilder().setFlowLabel(labels).build(); - builder.setFlowspecType(label); - fs.add(builder.build()); - mp.setAfi(Ipv4AddressFamily.class).setWithdrawnRoutes(new WithdrawnRoutesBuilder().setDestinationType( new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationFlowspecCaseBuilder().setDestinationFlowspec( new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.destination.flowspec._case.DestinationFlowspecBuilder().setFlowspec(fs).build()).build()).build()); - final FSIpv4NlriParser parser = new FSIpv4NlriParser(); + final SimpleFlowspecIpv4NlriParser parser = new SimpleFlowspecIpv4NlriParser(flowspecContext.getFlowspecIpv4TypeRegistry()); final MpUnreachNlriBuilder result = new MpUnreachNlriBuilder(); result.setAfi(Ipv4AddressFamily.class); @@ -237,10 +230,14 @@ public class FSIpv4NlriParserTest { assertEquals(fragment, flows.get(5).getFlowspecType()); final ByteBuf buffer = Unpooled.buffer(); + parser.serializeNlri(flows, 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' ", FS_PARSER.stringNlri(flows)); + } @Test @@ -248,12 +245,12 @@ public class FSIpv4NlriParserTest { final DataContainerNodeAttrBuilder entry = Builders.mapEntryBuilder(); entry.withNodeIdentifier(new NodeIdentifierWithPredicates(FlowspecRoute.QNAME, FlowspecRoute.QNAME, entry)); entry.withChild(Builders.unkeyedListBuilder() - .withNodeIdentifier(AbstractFSNlriParser.FLOWSPEC_NID) + .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_NID) .withChild(Builders.unkeyedListEntryBuilder() - .withNodeIdentifier(AbstractFSNlriParser.FLOWSPEC_NID) + .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_NID) .withChild(Builders.choiceBuilder() - .withNodeIdentifier(AbstractFSNlriParser.FLOWSPEC_TYPE_NID) - .withChild(Builders.leafBuilder().withNodeIdentifier(AbstractFSNlriParser.DEST_PREFIX_NID).withValue("127.0.0.5/32").build()).build()).build()).build()); + .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_TYPE_NID) + .withChild(Builders.leafBuilder().withNodeIdentifier(AbstractFlowspecNlriParser.DEST_PREFIX_NID).withValue("127.0.0.5/32").build()).build()).build()).build()); final FlowspecBuilder expectedFS = new FlowspecBuilder(); expectedFS.setFlowspecType(new DestinationPrefixCaseBuilder().setDestinationPrefix(new Ipv4Prefix("127.0.0.5/32")).build()); @@ -267,12 +264,12 @@ public class FSIpv4NlriParserTest { final DataContainerNodeAttrBuilder entry = Builders.mapEntryBuilder(); entry.withNodeIdentifier(new NodeIdentifierWithPredicates(FlowspecRoute.QNAME, FlowspecRoute.QNAME, entry)); entry.withChild(Builders.unkeyedListBuilder() - .withNodeIdentifier(AbstractFSNlriParser.FLOWSPEC_NID) + .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_NID) .withChild(Builders.unkeyedListEntryBuilder() - .withNodeIdentifier(AbstractFSNlriParser.FLOWSPEC_NID) + .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_NID) .withChild(Builders.choiceBuilder() - .withNodeIdentifier(AbstractFSNlriParser.FLOWSPEC_TYPE_NID) - .withChild(Builders.leafBuilder().withNodeIdentifier(AbstractFSNlriParser.SOURCE_PREFIX_NID).withValue("127.0.0.6/32").build()).build()).build()).build()); + .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()); @@ -286,21 +283,21 @@ public class FSIpv4NlriParserTest { final DataContainerNodeAttrBuilder entry = Builders.mapEntryBuilder(); entry.withNodeIdentifier(new NodeIdentifierWithPredicates(FlowspecRoute.QNAME, FlowspecRoute.QNAME, entry)); entry.withChild(Builders.unkeyedListBuilder() - .withNodeIdentifier(AbstractFSNlriParser.FLOWSPEC_NID) + .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_NID) .withChild(Builders.unkeyedListEntryBuilder() - .withNodeIdentifier(AbstractFSNlriParser.FLOWSPEC_NID) + .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_NID) .withChild(Builders.choiceBuilder() - .withNodeIdentifier(AbstractFSNlriParser.FLOWSPEC_TYPE_NID) - .withChild(Builders.unkeyedListBuilder().withNodeIdentifier(FSIpv4NlriParser.PROTOCOL_IP_NID) - .withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(FSIpv4NlriParser.PROTOCOL_IP_NID) - .withChild(Builders.leafBuilder().withNodeIdentifier(FSIpv4NlriParser.OP_NID).withValue(Sets.newHashSet(AbstractOperandParser.END_OF_LIST_VALUE, AbstractOperandParser.AND_BIT_VALUE)).build()) - .withChild(Builders.leafBuilder().withNodeIdentifier(FSIpv4NlriParser.VALUE_NID).withValue((short) 100).build()).build()) - .withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(FSIpv4NlriParser.PROTOCOL_IP_NID) - .withChild(Builders.leafBuilder().withNodeIdentifier(FSIpv4NlriParser.OP_NID).withValue(Sets.newHashSet(AbstractOperandParser.AND_BIT_VALUE)).build()) - .withChild(Builders.leafBuilder().withNodeIdentifier(FSIpv4NlriParser.VALUE_NID).withValue((short) 200).build()).build()) - .withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(FSIpv4NlriParser.PROTOCOL_IP_NID) - .withChild(Builders.leafBuilder().withNodeIdentifier(FSIpv4NlriParser.OP_NID).withValue(Sets.newHashSet(AbstractOperandParser.END_OF_LIST_VALUE, AbstractOperandParser.AND_BIT_VALUE, AbstractNumericOperandParser.EQUALS_VALUE)).build()) - .withChild(Builders.leafBuilder().withNodeIdentifier(FSIpv4NlriParser.VALUE_NID).withValue((short) 240).build()).build()) + .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_TYPE_NID) + .withChild(Builders.unkeyedListBuilder().withNodeIdentifier(SimpleFlowspecIpv4NlriParser.PROTOCOL_IP_NID) + .withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(SimpleFlowspecIpv4NlriParser.PROTOCOL_IP_NID) + .withChild(Builders.leafBuilder().withNodeIdentifier(SimpleFlowspecIpv4NlriParser.OP_NID).withValue(Sets.newHashSet(AbstractOperandParser.END_OF_LIST_VALUE, AbstractOperandParser.AND_BIT_VALUE)).build()) + .withChild(Builders.leafBuilder().withNodeIdentifier(SimpleFlowspecIpv4NlriParser.VALUE_NID).withValue((short) 100).build()).build()) + .withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(SimpleFlowspecIpv4NlriParser.PROTOCOL_IP_NID) + .withChild(Builders.leafBuilder().withNodeIdentifier(SimpleFlowspecIpv4NlriParser.OP_NID).withValue(Sets.newHashSet(AbstractOperandParser.AND_BIT_VALUE)).build()) + .withChild(Builders.leafBuilder().withNodeIdentifier(SimpleFlowspecIpv4NlriParser.VALUE_NID).withValue((short) 200).build()).build()) + .withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(SimpleFlowspecIpv4NlriParser.PROTOCOL_IP_NID) + .withChild(Builders.leafBuilder().withNodeIdentifier(SimpleFlowspecIpv4NlriParser.OP_NID).withValue(Sets.newHashSet(AbstractOperandParser.END_OF_LIST_VALUE, AbstractOperandParser.AND_BIT_VALUE, AbstractNumericOperandParser.EQUALS_VALUE)).build()) + .withChild(Builders.leafBuilder().withNodeIdentifier(SimpleFlowspecIpv4NlriParser.VALUE_NID).withValue((short) 240).build()).build()) .build()).build()).build()).build()); final FlowspecBuilder expectedFS = new FlowspecBuilder(); @@ -318,15 +315,15 @@ public class FSIpv4NlriParserTest { final DataContainerNodeAttrBuilder entry = Builders.mapEntryBuilder(); entry.withNodeIdentifier(new NodeIdentifierWithPredicates(FlowspecRoute.QNAME, FlowspecRoute.QNAME, entry)); entry.withChild(Builders.unkeyedListBuilder() - .withNodeIdentifier(AbstractFSNlriParser.FLOWSPEC_NID) + .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_NID) .withChild(Builders.unkeyedListEntryBuilder() - .withNodeIdentifier(AbstractFSNlriParser.FLOWSPEC_NID) + .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_NID) .withChild(Builders.choiceBuilder() - .withNodeIdentifier(AbstractFSNlriParser.FLOWSPEC_TYPE_NID) - .withChild(Builders.unkeyedListBuilder().withNodeIdentifier(FSIpv4NlriParser.PORTS_NID) - .withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(FSIpv4NlriParser.PROTOCOL_IP_NID) - .withChild(Builders.leafBuilder().withNodeIdentifier(FSIpv4NlriParser.OP_NID).withValue(Sets.newHashSet(AbstractOperandParser.END_OF_LIST_VALUE, AbstractOperandParser.AND_BIT_VALUE, AbstractNumericOperandParser.LESS_THAN_VALUE)).build()) - .withChild(Builders.leafBuilder().withNodeIdentifier(FSIpv4NlriParser.VALUE_NID).withValue(100).build()).build()) + .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_TYPE_NID) + .withChild(Builders.unkeyedListBuilder().withNodeIdentifier(SimpleFlowspecIpv4NlriParser.PORTS_NID) + .withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(SimpleFlowspecIpv4NlriParser.PROTOCOL_IP_NID) + .withChild(Builders.leafBuilder().withNodeIdentifier(SimpleFlowspecIpv4NlriParser.OP_NID).withValue(Sets.newHashSet(AbstractOperandParser.END_OF_LIST_VALUE, AbstractOperandParser.AND_BIT_VALUE, AbstractNumericOperandParser.LESS_THAN_VALUE)).build()) + .withChild(Builders.leafBuilder().withNodeIdentifier(SimpleFlowspecIpv4NlriParser.VALUE_NID).withValue(100).build()).build()) .build()).build()).build()).build()); final FlowspecBuilder expectedFS = new FlowspecBuilder(); @@ -341,15 +338,15 @@ public class FSIpv4NlriParserTest { final DataContainerNodeAttrBuilder entry = Builders.mapEntryBuilder(); entry.withNodeIdentifier(new NodeIdentifierWithPredicates(FlowspecRoute.QNAME, FlowspecRoute.QNAME, entry)); entry.withChild(Builders.unkeyedListBuilder() - .withNodeIdentifier(AbstractFSNlriParser.FLOWSPEC_NID) + .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_NID) .withChild(Builders.unkeyedListEntryBuilder() - .withNodeIdentifier(AbstractFSNlriParser.FLOWSPEC_NID) + .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_NID) .withChild(Builders.choiceBuilder() - .withNodeIdentifier(AbstractFSNlriParser.FLOWSPEC_TYPE_NID) - .withChild(Builders.unkeyedListBuilder().withNodeIdentifier(FSIpv4NlriParser.DEST_PORT_NID) - .withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(FSIpv4NlriParser.OP_NID) - .withChild(Builders.leafBuilder().withNodeIdentifier(FSIpv4NlriParser.OP_NID).withValue(Sets.newHashSet(AbstractOperandParser.END_OF_LIST_VALUE, AbstractNumericOperandParser.EQUALS_VALUE)).build()) - .withChild(Builders.leafBuilder().withNodeIdentifier(FSIpv4NlriParser.VALUE_NID).withValue(1024).build()).build()) + .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_TYPE_NID) + .withChild(Builders.unkeyedListBuilder().withNodeIdentifier(SimpleFlowspecIpv4NlriParser.DEST_PORT_NID) + .withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(SimpleFlowspecIpv4NlriParser.OP_NID) + .withChild(Builders.leafBuilder().withNodeIdentifier(SimpleFlowspecIpv4NlriParser.OP_NID).withValue(Sets.newHashSet(AbstractOperandParser.END_OF_LIST_VALUE, AbstractNumericOperandParser.EQUALS_VALUE)).build()) + .withChild(Builders.leafBuilder().withNodeIdentifier(SimpleFlowspecIpv4NlriParser.VALUE_NID).withValue(1024).build()).build()) .build()).build()).build()).build()); final FlowspecBuilder expectedFS = new FlowspecBuilder(); expectedFS.setFlowspecType(new DestinationPortCaseBuilder().setDestinationPorts(Lists.newArrayList(new DestinationPortsBuilder().setValue(1024).setOp(new NumericOperand(false, true, true, false, false)).build())).build()); @@ -363,15 +360,15 @@ public class FSIpv4NlriParserTest { final DataContainerNodeAttrBuilder entry = Builders.mapEntryBuilder(); entry.withNodeIdentifier(new NodeIdentifierWithPredicates(FlowspecRoute.QNAME, FlowspecRoute.QNAME, entry)); entry.withChild(Builders.unkeyedListBuilder() - .withNodeIdentifier(AbstractFSNlriParser.FLOWSPEC_NID) + .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_NID) .withChild(Builders.unkeyedListEntryBuilder() - .withNodeIdentifier(AbstractFSNlriParser.FLOWSPEC_NID) + .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_NID) .withChild(Builders.choiceBuilder() - .withNodeIdentifier(AbstractFSNlriParser.FLOWSPEC_TYPE_NID) - .withChild(Builders.unkeyedListBuilder().withNodeIdentifier(FSIpv4NlriParser.SOURCE_PORT_NID) - .withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(FSIpv4NlriParser.OP_NID) - .withChild(Builders.leafBuilder().withNodeIdentifier(FSIpv4NlriParser.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(FSIpv4NlriParser.VALUE_NID).withValue(8080).build()).build()) + .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_TYPE_NID) + .withChild(Builders.unkeyedListBuilder().withNodeIdentifier(SimpleFlowspecIpv4NlriParser.SOURCE_PORT_NID) + .withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(SimpleFlowspecIpv4NlriParser.OP_NID) + .withChild(Builders.leafBuilder().withNodeIdentifier(SimpleFlowspecIpv4NlriParser.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(SimpleFlowspecIpv4NlriParser.VALUE_NID).withValue(8080).build()).build()) .build()).build()).build()).build()); final FlowspecBuilder expectedFS = new FlowspecBuilder(); expectedFS.setFlowspecType(new SourcePortCaseBuilder().setSourcePorts(Lists.newArrayList(new SourcePortsBuilder().setValue(8080).setOp(new NumericOperand(true, true, true, true, true)).build())).build()); @@ -385,15 +382,15 @@ public class FSIpv4NlriParserTest { final DataContainerNodeAttrBuilder entry = Builders.mapEntryBuilder(); entry.withNodeIdentifier(new NodeIdentifierWithPredicates(FlowspecRoute.QNAME, FlowspecRoute.QNAME, entry)); entry.withChild(Builders.unkeyedListBuilder() - .withNodeIdentifier(AbstractFSNlriParser.FLOWSPEC_NID) + .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_NID) .withChild(Builders.unkeyedListEntryBuilder() - .withNodeIdentifier(AbstractFSNlriParser.FLOWSPEC_NID) + .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_NID) .withChild(Builders.choiceBuilder() - .withNodeIdentifier(AbstractFSNlriParser.FLOWSPEC_TYPE_NID) - .withChild(Builders.unkeyedListBuilder().withNodeIdentifier(FSIpv4NlriParser.ICMP_TYPE_NID) - .withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(FSIpv4NlriParser.OP_NID) - .withChild(Builders.leafBuilder().withNodeIdentifier(FSIpv4NlriParser.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(FSIpv4NlriParser.VALUE_NID).withValue((short) 22).build()).build()) + .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_TYPE_NID) + .withChild(Builders.unkeyedListBuilder().withNodeIdentifier(SimpleFlowspecIpv4NlriParser.ICMP_TYPE_NID) + .withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(SimpleFlowspecIpv4NlriParser.OP_NID) + .withChild(Builders.leafBuilder().withNodeIdentifier(SimpleFlowspecIpv4NlriParser.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(SimpleFlowspecIpv4NlriParser.VALUE_NID).withValue((short) 22).build()).build()) .build()).build()).build()).build()); final FlowspecBuilder expectedFS = new FlowspecBuilder(); expectedFS.setFlowspecType(new IcmpTypeCaseBuilder().setTypes(Lists.newArrayList(new TypesBuilder().setValue((short) 22).setOp(new NumericOperand(true, true, true, true, true)).build())).build()); @@ -407,15 +404,15 @@ public class FSIpv4NlriParserTest { final DataContainerNodeAttrBuilder entry = Builders.mapEntryBuilder(); entry.withNodeIdentifier(new NodeIdentifierWithPredicates(FlowspecRoute.QNAME, FlowspecRoute.QNAME, entry)); entry.withChild(Builders.unkeyedListBuilder() - .withNodeIdentifier(AbstractFSNlriParser.FLOWSPEC_NID) + .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_NID) .withChild(Builders.unkeyedListEntryBuilder() - .withNodeIdentifier(AbstractFSNlriParser.FLOWSPEC_NID) + .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_NID) .withChild(Builders.choiceBuilder() - .withNodeIdentifier(AbstractFSNlriParser.FLOWSPEC_TYPE_NID) - .withChild(Builders.unkeyedListBuilder().withNodeIdentifier(FSIpv4NlriParser.ICMP_CODE_NID) - .withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(FSIpv4NlriParser.OP_NID) - .withChild(Builders.leafBuilder().withNodeIdentifier(FSIpv4NlriParser.OP_NID).withValue(Sets.newHashSet()).build()) - .withChild(Builders.leafBuilder().withNodeIdentifier(FSIpv4NlriParser.VALUE_NID).withValue((short) 23).build()).build()) + .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_TYPE_NID) + .withChild(Builders.unkeyedListBuilder().withNodeIdentifier(SimpleFlowspecIpv4NlriParser.ICMP_CODE_NID) + .withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(SimpleFlowspecIpv4NlriParser.OP_NID) + .withChild(Builders.leafBuilder().withNodeIdentifier(SimpleFlowspecIpv4NlriParser.OP_NID).withValue(Sets.newHashSet()).build()) + .withChild(Builders.leafBuilder().withNodeIdentifier(SimpleFlowspecIpv4NlriParser.VALUE_NID).withValue((short) 23).build()).build()) .build()).build()).build()).build()); final FlowspecBuilder expectedFS = new FlowspecBuilder(); expectedFS.setFlowspecType(new IcmpCodeCaseBuilder().setCodes(Lists.newArrayList(new CodesBuilder().setValue((short) 23).setOp(new NumericOperand(false, false, false, false, false)).build())).build()); @@ -429,15 +426,15 @@ public class FSIpv4NlriParserTest { final DataContainerNodeAttrBuilder entry = Builders.mapEntryBuilder(); entry.withNodeIdentifier(new NodeIdentifierWithPredicates(FlowspecRoute.QNAME, FlowspecRoute.QNAME, entry)); entry.withChild(Builders.unkeyedListBuilder() - .withNodeIdentifier(AbstractFSNlriParser.FLOWSPEC_NID) + .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_NID) .withChild(Builders.unkeyedListEntryBuilder() - .withNodeIdentifier(AbstractFSNlriParser.FLOWSPEC_NID) + .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_NID) .withChild(Builders.choiceBuilder() - .withNodeIdentifier(AbstractFSNlriParser.FLOWSPEC_TYPE_NID) - .withChild(Builders.unkeyedListBuilder().withNodeIdentifier(FSIpv4NlriParser.TCP_FLAGS_NID) - .withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(FSIpv4NlriParser.OP_NID) - .withChild(Builders.leafBuilder().withNodeIdentifier(FSIpv4NlriParser.OP_NID).withValue(Sets.newHashSet(AbstractOperandParser.AND_BIT_VALUE, AbstractOperandParser.END_OF_LIST_VALUE)).build()) - .withChild(Builders.leafBuilder().withNodeIdentifier(FSIpv4NlriParser.VALUE_NID).withValue(99).build()).build()) + .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_TYPE_NID) + .withChild(Builders.unkeyedListBuilder().withNodeIdentifier(SimpleFlowspecIpv4NlriParser.TCP_FLAGS_NID) + .withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(SimpleFlowspecIpv4NlriParser.OP_NID) + .withChild(Builders.leafBuilder().withNodeIdentifier(SimpleFlowspecIpv4NlriParser.OP_NID).withValue(Sets.newHashSet(AbstractOperandParser.AND_BIT_VALUE, AbstractOperandParser.END_OF_LIST_VALUE)).build()) + .withChild(Builders.leafBuilder().withNodeIdentifier(SimpleFlowspecIpv4NlriParser.VALUE_NID).withValue(99).build()).build()) .build()).build()).build()).build()); final FlowspecBuilder expectedFS = new FlowspecBuilder(); expectedFS.setFlowspecType(new TcpFlagsCaseBuilder().setTcpFlags(Lists.newArrayList(new TcpFlagsBuilder().setValue(99).setOp(new BitmaskOperand(true, true, false, false)).build())).build()); @@ -451,15 +448,15 @@ public class FSIpv4NlriParserTest { final DataContainerNodeAttrBuilder entry = Builders.mapEntryBuilder(); entry.withNodeIdentifier(new NodeIdentifierWithPredicates(FlowspecRoute.QNAME, FlowspecRoute.QNAME, entry)); entry.withChild(Builders.unkeyedListBuilder() - .withNodeIdentifier(AbstractFSNlriParser.FLOWSPEC_NID) + .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_NID) .withChild(Builders.unkeyedListEntryBuilder() - .withNodeIdentifier(AbstractFSNlriParser.FLOWSPEC_NID) + .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_NID) .withChild(Builders.choiceBuilder() - .withNodeIdentifier(AbstractFSNlriParser.FLOWSPEC_TYPE_NID) - .withChild(Builders.unkeyedListBuilder().withNodeIdentifier(FSIpv4NlriParser.PACKET_LENGTHS_NID) - .withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(FSIpv4NlriParser.OP_NID) - .withChild(Builders.leafBuilder().withNodeIdentifier(FSIpv4NlriParser.OP_NID).withValue(Sets.newHashSet(AbstractOperandParser.AND_BIT_VALUE, AbstractNumericOperandParser.GREATER_THAN_VALUE)).build()) - .withChild(Builders.leafBuilder().withNodeIdentifier(FSIpv4NlriParser.VALUE_NID).withValue(101).build()).build()) + .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_TYPE_NID) + .withChild(Builders.unkeyedListBuilder().withNodeIdentifier(SimpleFlowspecIpv4NlriParser.PACKET_LENGTHS_NID) + .withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(SimpleFlowspecIpv4NlriParser.OP_NID) + .withChild(Builders.leafBuilder().withNodeIdentifier(SimpleFlowspecIpv4NlriParser.OP_NID).withValue(Sets.newHashSet(AbstractOperandParser.AND_BIT_VALUE, AbstractNumericOperandParser.GREATER_THAN_VALUE)).build()) + .withChild(Builders.leafBuilder().withNodeIdentifier(SimpleFlowspecIpv4NlriParser.VALUE_NID).withValue(101).build()).build()) .build()).build()).build()).build()); final FlowspecBuilder expectedFS = new FlowspecBuilder(); expectedFS.setFlowspecType(new PacketLengthCaseBuilder().setPacketLengths(Lists.newArrayList(new PacketLengthsBuilder().setValue(101).setOp(new NumericOperand(true, false, false, true, false)).build())).build()); @@ -473,15 +470,15 @@ public class FSIpv4NlriParserTest { final DataContainerNodeAttrBuilder entry = Builders.mapEntryBuilder(); entry.withNodeIdentifier(new NodeIdentifierWithPredicates(FlowspecRoute.QNAME, FlowspecRoute.QNAME, entry)); entry.withChild(Builders.unkeyedListBuilder() - .withNodeIdentifier(AbstractFSNlriParser.FLOWSPEC_NID) + .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_NID) .withChild(Builders.unkeyedListEntryBuilder() - .withNodeIdentifier(AbstractFSNlriParser.FLOWSPEC_NID) + .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_NID) .withChild(Builders.choiceBuilder() - .withNodeIdentifier(AbstractFSNlriParser.FLOWSPEC_TYPE_NID) - .withChild(Builders.unkeyedListBuilder().withNodeIdentifier(FSIpv4NlriParser.DSCP_NID) - .withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(FSIpv4NlriParser.OP_NID) - .withChild(Builders.leafBuilder().withNodeIdentifier(FSIpv4NlriParser.OP_NID).withValue(Sets.newHashSet(AbstractOperandParser.AND_BIT_VALUE, AbstractOperandParser.END_OF_LIST_VALUE, AbstractNumericOperandParser.GREATER_THAN_VALUE)).build()) - .withChild(Builders.leafBuilder().withNodeIdentifier(FSIpv4NlriParser.VALUE_NID).withValue((short)15).build()).build()) + .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_TYPE_NID) + .withChild(Builders.unkeyedListBuilder().withNodeIdentifier(SimpleFlowspecIpv4NlriParser.DSCP_NID) + .withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(SimpleFlowspecIpv4NlriParser.OP_NID) + .withChild(Builders.leafBuilder().withNodeIdentifier(SimpleFlowspecIpv4NlriParser.OP_NID).withValue(Sets.newHashSet(AbstractOperandParser.AND_BIT_VALUE, AbstractOperandParser.END_OF_LIST_VALUE, AbstractNumericOperandParser.GREATER_THAN_VALUE)).build()) + .withChild(Builders.leafBuilder().withNodeIdentifier(SimpleFlowspecIpv4NlriParser.VALUE_NID).withValue((short)15).build()).build()) .build()).build()).build()).build()); final FlowspecBuilder expectedFS = new FlowspecBuilder(); expectedFS.setFlowspecType(new DscpCaseBuilder().setDscps(Lists.newArrayList(new DscpsBuilder().setValue(new Dscp((short)15)).setOp(new NumericOperand(true, true, false, true, false)).build())).build()); @@ -495,15 +492,15 @@ public class FSIpv4NlriParserTest { final DataContainerNodeAttrBuilder entry = Builders.mapEntryBuilder(); entry.withNodeIdentifier(new NodeIdentifierWithPredicates(FlowspecRoute.QNAME, FlowspecRoute.QNAME, entry)); entry.withChild(Builders.unkeyedListBuilder() - .withNodeIdentifier(AbstractFSNlriParser.FLOWSPEC_NID) + .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_NID) .withChild(Builders.unkeyedListEntryBuilder() - .withNodeIdentifier(AbstractFSNlriParser.FLOWSPEC_NID) + .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_NID) .withChild(Builders.choiceBuilder() - .withNodeIdentifier(AbstractFSNlriParser.FLOWSPEC_TYPE_NID) - .withChild(Builders.unkeyedListBuilder().withNodeIdentifier(FSIpv4NlriParser.FRAGMENT_NID) - .withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(FSIpv4NlriParser.OP_NID) - .withChild(Builders.leafBuilder().withNodeIdentifier(FSIpv4NlriParser.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(FSIpv4NlriParser.VALUE_NID).withValue(Sets.newHashSet(FSIpv4NlriParser.DO_NOT_VALUE, FSIpv4NlriParser.FIRST_VALUE, FSIpv4NlriParser.IS_A_VALUE, FSIpv4NlriParser.LAST_VALUE)).build()).build()) + .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_TYPE_NID) + .withChild(Builders.unkeyedListBuilder().withNodeIdentifier(SimpleFlowspecIpv4NlriParser.FRAGMENT_NID) + .withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(SimpleFlowspecIpv4NlriParser.OP_NID) + .withChild(Builders.leafBuilder().withNodeIdentifier(SimpleFlowspecIpv4NlriParser.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(SimpleFlowspecIpv4NlriParser.VALUE_NID).withValue(Sets.newHashSet(SimpleFlowspecIpv4NlriParser.DO_NOT_VALUE, SimpleFlowspecIpv4NlriParser.FIRST_VALUE, SimpleFlowspecIpv4NlriParser.IS_A_VALUE, SimpleFlowspecIpv4NlriParser.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()); diff --git a/bgp/flowspec/src/test/java/org/opendaylight/protocol/bgp/flowspec/FSIpv6NlriParserTest.java b/bgp/flowspec/src/test/java/org/opendaylight/protocol/bgp/flowspec/SimpleFlowspecIpv6NlriParserTest.java similarity index 81% rename from bgp/flowspec/src/test/java/org/opendaylight/protocol/bgp/flowspec/FSIpv6NlriParserTest.java rename to bgp/flowspec/src/test/java/org/opendaylight/protocol/bgp/flowspec/SimpleFlowspecIpv6NlriParserTest.java index 297a367834..d3d6a4a17b 100644 --- a/bgp/flowspec/src/test/java/org/opendaylight/protocol/bgp/flowspec/FSIpv6NlriParserTest.java +++ b/bgp/flowspec/src/test/java/org/opendaylight/protocol/bgp/flowspec/SimpleFlowspecIpv6NlriParserTest.java @@ -59,11 +59,13 @@ import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode; import org.opendaylight.yangtools.yang.data.impl.schema.Builders; import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeAttrBuilder; -public class FSIpv6NlriParserTest { +public class SimpleFlowspecIpv6NlriParserTest { - private static final FSIpv6NlriParser FS_PARSER = new FSIpv6NlriParser(); + private final SimpleFlowspecExtensionProviderContext flowspecContext = new SimpleFlowspecExtensionProviderContext(); + private final FlowspecActivator fsa = new FlowspecActivator(flowspecContext); + private final SimpleFlowspecIpv6NlriParser FS_PARSER = new SimpleFlowspecIpv6NlriParser(flowspecContext.getFlowspecIpv6TypeRegistry()); - private static final byte[] REACHED_NLRI = new byte[] { 0x13, + private static final byte[] REACHED_NLRI = new byte[] { 0x13, 1, 0x28, 0, 1, 2, 3, 4, 5, 2, 0x28, 0, 1, 2, 3, 4, 6, 03, (byte) 0x81, 06 }; @@ -81,6 +83,7 @@ public class FSIpv6NlriParserTest { final DestinationIpv6PrefixCase destinationPrefix = new DestinationIpv6PrefixCaseBuilder().setDestinationPrefix(new Ipv6Prefix("102:304:500::/40")).build(); builder.setFlowspecType(destinationPrefix); fs.add(builder.build()); + final SourceIpv6PrefixCase sourcePrefix = new SourceIpv6PrefixCaseBuilder().setSourcePrefix(new Ipv6Prefix("102:304:600::/40")).build(); builder.setFlowspecType(sourcePrefix); fs.add(builder.build()); @@ -155,15 +158,15 @@ public class FSIpv6NlriParserTest { final DataContainerNodeAttrBuilder entry = Builders.mapEntryBuilder(); entry.withNodeIdentifier(new NodeIdentifierWithPredicates(FlowspecRoute.QNAME, FlowspecRoute.QNAME, entry)); entry.withChild(Builders.unkeyedListBuilder() - .withNodeIdentifier(AbstractFSNlriParser.FLOWSPEC_NID) + .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_NID) .withChild(Builders.unkeyedListEntryBuilder() - .withNodeIdentifier(AbstractFSNlriParser.FLOWSPEC_NID) + .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_NID) .withChild(Builders.choiceBuilder() - .withNodeIdentifier(AbstractFSNlriParser.FLOWSPEC_TYPE_NID) - .withChild(Builders.unkeyedListBuilder().withNodeIdentifier(FSIpv6NlriParser.FRAGMENT_NID) - .withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(FSIpv6NlriParser.OP_NID) - .withChild(Builders.leafBuilder().withNodeIdentifier(FSIpv6NlriParser.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(FSIpv6NlriParser.VALUE_NID).withValue(Sets.newHashSet(FSIpv6NlriParser.DO_NOT_VALUE, FSIpv6NlriParser.FIRST_VALUE, FSIpv6NlriParser.IS_A_VALUE, FSIpv6NlriParser.LAST_VALUE)).build()).build()) + .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_TYPE_NID) + .withChild(Builders.unkeyedListBuilder().withNodeIdentifier(SimpleFlowspecIpv6NlriParser.FRAGMENT_NID) + .withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(SimpleFlowspecIpv6NlriParser.OP_NID) + .withChild(Builders.leafBuilder().withNodeIdentifier(SimpleFlowspecIpv6NlriParser.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(SimpleFlowspecIpv6NlriParser.VALUE_NID).withValue(Sets.newHashSet(SimpleFlowspecIpv6NlriParser.DO_NOT_VALUE, SimpleFlowspecIpv6NlriParser.FIRST_VALUE, SimpleFlowspecIpv6NlriParser.IS_A_VALUE, SimpleFlowspecIpv6NlriParser.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()); @@ -177,21 +180,21 @@ public class FSIpv6NlriParserTest { final DataContainerNodeAttrBuilder entry = Builders.mapEntryBuilder(); entry.withNodeIdentifier(new NodeIdentifierWithPredicates(FlowspecRoute.QNAME, FlowspecRoute.QNAME, entry)); entry.withChild(Builders.unkeyedListBuilder() - .withNodeIdentifier(AbstractFSNlriParser.FLOWSPEC_NID) + .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_NID) .withChild(Builders.unkeyedListEntryBuilder() - .withNodeIdentifier(AbstractFSNlriParser.FLOWSPEC_NID) + .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_NID) .withChild(Builders.choiceBuilder() - .withNodeIdentifier(AbstractFSNlriParser.FLOWSPEC_TYPE_NID) - .withChild(Builders.unkeyedListBuilder().withNodeIdentifier(FSIpv6NlriParser.NEXT_HEADER_NID) - .withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(FSIpv6NlriParser.NEXT_HEADER_NID) - .withChild(Builders.leafBuilder().withNodeIdentifier(FSIpv6NlriParser.OP_NID).withValue(Sets.newHashSet(AbstractOperandParser.END_OF_LIST_VALUE, AbstractOperandParser.AND_BIT_VALUE)).build()) - .withChild(Builders.leafBuilder().withNodeIdentifier(FSIpv6NlriParser.VALUE_NID).withValue((short) 100).build()).build()) - .withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(FSIpv6NlriParser.NEXT_HEADER_NID) - .withChild(Builders.leafBuilder().withNodeIdentifier(FSIpv6NlriParser.OP_NID).withValue(Sets.newHashSet(AbstractOperandParser.AND_BIT_VALUE)).build()) - .withChild(Builders.leafBuilder().withNodeIdentifier(FSIpv6NlriParser.VALUE_NID).withValue((short) 200).build()).build()) - .withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(FSIpv6NlriParser.NEXT_HEADER_NID) - .withChild(Builders.leafBuilder().withNodeIdentifier(FSIpv6NlriParser.OP_NID).withValue(Sets.newHashSet(AbstractOperandParser.END_OF_LIST_VALUE, AbstractOperandParser.AND_BIT_VALUE, AbstractNumericOperandParser.EQUALS_VALUE)).build()) - .withChild(Builders.leafBuilder().withNodeIdentifier(FSIpv6NlriParser.VALUE_NID).withValue((short) 210).build()).build()) + .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_TYPE_NID) + .withChild(Builders.unkeyedListBuilder().withNodeIdentifier(SimpleFlowspecIpv6NlriParser.NEXT_HEADER_NID) + .withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(SimpleFlowspecIpv6NlriParser.NEXT_HEADER_NID) + .withChild(Builders.leafBuilder().withNodeIdentifier(SimpleFlowspecIpv6NlriParser.OP_NID).withValue(Sets.newHashSet(AbstractOperandParser.END_OF_LIST_VALUE, AbstractOperandParser.AND_BIT_VALUE)).build()) + .withChild(Builders.leafBuilder().withNodeIdentifier(SimpleFlowspecIpv6NlriParser.VALUE_NID).withValue((short) 100).build()).build()) + .withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(SimpleFlowspecIpv6NlriParser.NEXT_HEADER_NID) + .withChild(Builders.leafBuilder().withNodeIdentifier(SimpleFlowspecIpv6NlriParser.OP_NID).withValue(Sets.newHashSet(AbstractOperandParser.AND_BIT_VALUE)).build()) + .withChild(Builders.leafBuilder().withNodeIdentifier(SimpleFlowspecIpv6NlriParser.VALUE_NID).withValue((short) 200).build()).build()) + .withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(SimpleFlowspecIpv6NlriParser.NEXT_HEADER_NID) + .withChild(Builders.leafBuilder().withNodeIdentifier(SimpleFlowspecIpv6NlriParser.OP_NID).withValue(Sets.newHashSet(AbstractOperandParser.END_OF_LIST_VALUE, AbstractOperandParser.AND_BIT_VALUE, AbstractNumericOperandParser.EQUALS_VALUE)).build()) + .withChild(Builders.leafBuilder().withNodeIdentifier(SimpleFlowspecIpv6NlriParser.VALUE_NID).withValue((short) 210).build()).build()) .build()).build()).build()).build()); final FlowspecBuilder expectedFS = new FlowspecBuilder(); @@ -209,18 +212,18 @@ public class FSIpv6NlriParserTest { final DataContainerNodeAttrBuilder entry = Builders.mapEntryBuilder(); entry.withNodeIdentifier(new NodeIdentifierWithPredicates(FlowspecRoute.QNAME, FlowspecRoute.QNAME, entry)); entry.withChild(Builders.unkeyedListBuilder() - .withNodeIdentifier(AbstractFSNlriParser.FLOWSPEC_NID) + .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_NID) .withChild(Builders.unkeyedListEntryBuilder() - .withNodeIdentifier(AbstractFSNlriParser.FLOWSPEC_NID) + .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_NID) .withChild(Builders.choiceBuilder() - .withNodeIdentifier(AbstractFSNlriParser.FLOWSPEC_TYPE_NID) - .withChild(Builders.unkeyedListBuilder().withNodeIdentifier(FSIpv6NlriParser.FLOW_LABEL_NID) - .withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(FSIpv6NlriParser.FLOW_LABEL_NID) - .withChild(Builders.leafBuilder().withNodeIdentifier(FSIpv6NlriParser.OP_NID).withValue(Sets.newHashSet(AbstractOperandParser.END_OF_LIST_VALUE, AbstractOperandParser.AND_BIT_VALUE)).build()) - .withChild(Builders.leafBuilder().withNodeIdentifier(FSIpv6NlriParser.VALUE_NID).withValue(100L).build()).build()) - .withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(FSIpv6NlriParser.FLOW_LABEL_NID) - .withChild(Builders.leafBuilder().withNodeIdentifier(FSIpv6NlriParser.OP_NID).withValue(Sets.newHashSet(AbstractOperandParser.AND_BIT_VALUE)).build()) - .withChild(Builders.leafBuilder().withNodeIdentifier(FSIpv6NlriParser.VALUE_NID).withValue(200L).build()).build()) + .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_TYPE_NID) + .withChild(Builders.unkeyedListBuilder().withNodeIdentifier(SimpleFlowspecIpv6NlriParser.FLOW_LABEL_NID) + .withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(SimpleFlowspecIpv6NlriParser.FLOW_LABEL_NID) + .withChild(Builders.leafBuilder().withNodeIdentifier(SimpleFlowspecIpv6NlriParser.OP_NID).withValue(Sets.newHashSet(AbstractOperandParser.END_OF_LIST_VALUE, AbstractOperandParser.AND_BIT_VALUE)).build()) + .withChild(Builders.leafBuilder().withNodeIdentifier(SimpleFlowspecIpv6NlriParser.VALUE_NID).withValue(100L).build()).build()) + .withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(SimpleFlowspecIpv6NlriParser.FLOW_LABEL_NID) + .withChild(Builders.leafBuilder().withNodeIdentifier(SimpleFlowspecIpv6NlriParser.OP_NID).withValue(Sets.newHashSet(AbstractOperandParser.AND_BIT_VALUE)).build()) + .withChild(Builders.leafBuilder().withNodeIdentifier(SimpleFlowspecIpv6NlriParser.VALUE_NID).withValue(200L).build()).build()) .build()).build()).build()).build()); final FlowspecBuilder expectedFS = new FlowspecBuilder(); @@ -237,12 +240,12 @@ public class FSIpv6NlriParserTest { final DataContainerNodeAttrBuilder entry = Builders.mapEntryBuilder(); entry.withNodeIdentifier(new NodeIdentifierWithPredicates(FlowspecRoute.QNAME, FlowspecRoute.QNAME, entry)); entry.withChild(Builders.unkeyedListBuilder() - .withNodeIdentifier(AbstractFSNlriParser.FLOWSPEC_NID) + .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_NID) .withChild(Builders.unkeyedListEntryBuilder() - .withNodeIdentifier(AbstractFSNlriParser.FLOWSPEC_NID) + .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_NID) .withChild(Builders.choiceBuilder() - .withNodeIdentifier(AbstractFSNlriParser.FLOWSPEC_TYPE_NID) - .withChild(Builders.leafBuilder().withNodeIdentifier(FSIpv6NlriParser.DEST_PREFIX_NID).withValue("102:304:500::/40").build()).build()).build()).build()); + .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_TYPE_NID) + .withChild(Builders.leafBuilder().withNodeIdentifier(SimpleFlowspecIpv6NlriParser.DEST_PREFIX_NID).withValue("102:304:500::/40").build()).build()).build()).build()); final FlowspecBuilder expectedFS = new FlowspecBuilder(); expectedFS.setFlowspecType(new DestinationIpv6PrefixCaseBuilder().setDestinationPrefix(new Ipv6Prefix("102:304:500::/40")).build()); final List expectedValue = new ArrayList<>(); @@ -255,12 +258,12 @@ public class FSIpv6NlriParserTest { final DataContainerNodeAttrBuilder entry = Builders.mapEntryBuilder(); entry.withNodeIdentifier(new NodeIdentifierWithPredicates(FlowspecRoute.QNAME, FlowspecRoute.QNAME, entry)); entry.withChild(Builders.unkeyedListBuilder() - .withNodeIdentifier(AbstractFSNlriParser.FLOWSPEC_NID) + .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_NID) .withChild(Builders.unkeyedListEntryBuilder() - .withNodeIdentifier(AbstractFSNlriParser.FLOWSPEC_NID) + .withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_NID) .withChild(Builders.choiceBuilder() - .withNodeIdentifier(AbstractFSNlriParser.FLOWSPEC_TYPE_NID) - .withChild(Builders.leafBuilder().withNodeIdentifier(FSIpv4NlriParser.SOURCE_PREFIX_NID).withValue("102:304:600::/40").build()).build()).build()).build()); + .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 expectedValue = new ArrayList<>(); diff --git a/bgp/flowspec/src/test/java/org/opendaylight/protocol/bgp/flowspec/extended/communities/FSExtendedCommunitiesTest.java b/bgp/flowspec/src/test/java/org/opendaylight/protocol/bgp/flowspec/extended/communities/FSExtendedCommunitiesTest.java index d576dace4a..0aea85f8cf 100644 --- a/bgp/flowspec/src/test/java/org/opendaylight/protocol/bgp/flowspec/extended/communities/FSExtendedCommunitiesTest.java +++ b/bgp/flowspec/src/test/java/org/opendaylight/protocol/bgp/flowspec/extended/communities/FSExtendedCommunitiesTest.java @@ -15,6 +15,8 @@ import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.opendaylight.protocol.bgp.flowspec.BGPActivator; +import org.opendaylight.protocol.bgp.flowspec.FlowspecActivator; +import org.opendaylight.protocol.bgp.flowspec.SimpleFlowspecExtensionProviderContext; import org.opendaylight.protocol.bgp.parser.BGPDocumentedException; import org.opendaylight.protocol.bgp.parser.BGPParsingException; import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionProviderContext; @@ -80,7 +82,10 @@ public class FSExtendedCommunitiesTest { @Before public void setUp() throws Exception { - this.act = new BGPActivator(); + final SimpleFlowspecExtensionProviderContext fs_context = new SimpleFlowspecExtensionProviderContext(); + final FlowspecActivator activator = new FlowspecActivator(fs_context); + + this.act= new BGPActivator(fs_context, activator); final BGPExtensionProviderContext context = new SimpleBGPExtensionProviderContext(); act.start(context); registry = context.getExtendedCommunityReistry(); -- 2.36.6