import org.opendaylight.protocol.util.BitArray;
import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.protocol.util.ByteBufWriteUtil;
-import org.opendaylight.protocol.util.Ipv4Util;
import org.opendaylight.protocol.util.Values;
-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.rev150114.BitmaskOperand;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.ComponentType;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.Dscp;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.Fragment;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.NumericOneByteValue;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.NumericOperand;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.NumericTwoByteValue;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.flowspec.destination.Flowspec;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.flowspec.destination.FlowspecBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.flowspec.destination.flowspec.FlowspecType;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.flowspec.destination.flowspec.flowspec.type.DestinationPortCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.flowspec.destination.flowspec.flowspec.type.DestinationPortCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.flowspec.destination.flowspec.flowspec.type.DestinationPrefixCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.flowspec.destination.flowspec.flowspec.type.DestinationPrefixCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.flowspec.destination.flowspec.flowspec.type.DscpCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.flowspec.destination.flowspec.flowspec.type.DscpCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.flowspec.destination.flowspec.flowspec.type.FragmentCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.flowspec.destination.flowspec.flowspec.type.FragmentCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.flowspec.destination.flowspec.flowspec.type.IcmpCodeCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.flowspec.destination.flowspec.flowspec.type.IcmpCodeCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.flowspec.destination.flowspec.flowspec.type.IcmpTypeCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.flowspec.destination.flowspec.flowspec.type.IcmpTypeCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.flowspec.destination.flowspec.flowspec.type.PacketLengthCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.flowspec.destination.flowspec.flowspec.type.PacketLengthCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.flowspec.destination.flowspec.flowspec.type.PortCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.flowspec.destination.flowspec.flowspec.type.PortCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.flowspec.destination.flowspec.flowspec.type.ProtocolIpCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.flowspec.destination.flowspec.flowspec.type.ProtocolIpCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.flowspec.destination.flowspec.flowspec.type.SourcePortCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.flowspec.destination.flowspec.flowspec.type.SourcePortCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.flowspec.destination.flowspec.flowspec.type.SourcePrefixCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.flowspec.destination.flowspec.flowspec.type.SourcePrefixCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.flowspec.destination.flowspec.flowspec.type.TcpFlagsCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.flowspec.destination.flowspec.flowspec.type.TcpFlagsCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.flowspec.destination.flowspec.flowspec.type.destination.port._case.DestinationPorts;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.flowspec.destination.flowspec.flowspec.type.destination.port._case.DestinationPortsBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.flowspec.destination.flowspec.flowspec.type.dscp._case.Dscps;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.flowspec.destination.flowspec.flowspec.type.dscp._case.DscpsBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.flowspec.destination.flowspec.flowspec.type.fragment._case.Fragments;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.flowspec.destination.flowspec.flowspec.type.fragment._case.FragmentsBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.flowspec.destination.flowspec.flowspec.type.icmp.code._case.Codes;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.flowspec.destination.flowspec.flowspec.type.icmp.code._case.CodesBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.flowspec.destination.flowspec.flowspec.type.icmp.type._case.Types;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.flowspec.destination.flowspec.flowspec.type.icmp.type._case.TypesBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.flowspec.destination.flowspec.flowspec.type.packet.length._case.PacketLengths;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.flowspec.destination.flowspec.flowspec.type.packet.length._case.PacketLengthsBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.flowspec.destination.flowspec.flowspec.type.port._case.Ports;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.flowspec.destination.flowspec.flowspec.type.port._case.PortsBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.flowspec.destination.flowspec.flowspec.type.protocol.ip._case.ProtocolIps;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.flowspec.destination.flowspec.flowspec.type.protocol.ip._case.ProtocolIpsBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.flowspec.destination.flowspec.flowspec.type.source.port._case.SourcePorts;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.flowspec.destination.flowspec.flowspec.type.source.port._case.SourcePortsBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.flowspec.destination.flowspec.flowspec.type.tcp.flags._case.TcpFlags;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.flowspec.destination.flowspec.flowspec.type.tcp.flags._case.TcpFlagsBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationFlowspecCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationFlowspecCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.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.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.NumericOneByteValue;
+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.NumericTwoByteValue;
+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.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.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.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.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.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.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.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.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.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.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;
+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;
+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;
+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;
+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;
+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;
+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;
+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;
+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;
+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.SourcePrefixCase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.Attributes;
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;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.MpReachNlriBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.MpUnreachNlri;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.MpUnreachNlriBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.mp.reach.nlri.AdvertizedRoutes;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.mp.reach.nlri.AdvertizedRoutesBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.mp.unreach.nlri.WithdrawnRoutesBuilder;
import org.opendaylight.yangtools.yang.binding.DataObject;
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;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-public class FSNlriParser implements NlriParser, NlriSerializer {
- private static final Logger LOG = LoggerFactory.getLogger(FSNlriParser.class);
-
- private static final NodeIdentifier FLOWSPEC_TYPE_NID = new NodeIdentifier(FlowspecType.QNAME);
- @VisibleForTesting
- static final NodeIdentifier COMPONENT_TYPE_NID = new NodeIdentifier(QName.cachedReference(QName.create(Flowspec.QNAME, "component-type")));
+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;
+
+ protected static final NodeIdentifier FLOWSPEC_TYPE_NID = new NodeIdentifier(FlowspecType.QNAME);
@VisibleForTesting
static final NodeIdentifier DEST_PREFIX_NID = new NodeIdentifier(QName.cachedReference(QName.create(DestinationPrefixCase.QNAME, "destination-prefix")));
@VisibleForTesting
static final NodeIdentifier SOURCE_PREFIX_NID = new NodeIdentifier(QName.cachedReference(QName.create(SourcePrefixCase.QNAME, "source-prefix")));
@VisibleForTesting
- static final NodeIdentifier PROTOCOL_IP_NID = new NodeIdentifier(ProtocolIps.QNAME);
- @VisibleForTesting
static final NodeIdentifier PORTS_NID = new NodeIdentifier(Ports.QNAME);
@VisibleForTesting
static final NodeIdentifier DEST_PORT_NID = new NodeIdentifier(DestinationPorts.QNAME);
@VisibleForTesting
static final NodeIdentifier FRAGMENT_NID = new NodeIdentifier(Fragments.QNAME);
@VisibleForTesting
- static final NodeIdentifier OP_NID = new NodeIdentifier(QName.create("urn:opendaylight:params:xml:ns:yang:bgp-flowspec","2015-01-14","op"));
+ static final NodeIdentifier OP_NID = new NodeIdentifier(QName.create("urn:opendaylight:params:xml:ns:yang:bgp-flowspec","2015-08-07","op"));
@VisibleForTesting
- static final NodeIdentifier VALUE_NID = new NodeIdentifier(QName.create("urn:opendaylight:params:xml:ns:yang:bgp-flowspec","2015-01-14","value"));
+ static final NodeIdentifier VALUE_NID = new NodeIdentifier(QName.create("urn:opendaylight:params:xml:ns:yang:bgp-flowspec","2015-08-07","value"));
- private static final int NLRI_LENGTH = 1;
- private static final int NLRI_LENGTH_EXTENDED = 2;
+ protected static final int NLRI_LENGTH = 1;
+ protected static final int NLRI_LENGTH_EXTENDED = 2;
+
+ private static final int OPERAND_LENGTH = 8;
+
+ private static final int END_OF_LIST = 0;
+ private static final int AND_BIT = 1;
+ private static final int LENGTH_BITMASK = 48;
+ private static final int LENGTH_SHIFT = 4;
+ private static final int LESS_THAN = 5;
+ private static final int GREATER_THAN = 6;
+ private static final int EQUAL = 7;
+ private static final int NOT = 6;
+ private static final int MATCH = 7;
+
+ /**
+ * Add this constant to length value to achieve all ones in the leftmost nibble.
+ */
+ private static final int LENGTH_MAGIC = 61440;
+ private static final int MAX_NLRI_LENGTH = 4095;
+ private static final int MAX_NLRI_LENGTH_ONE_BYTE = 240;
@VisibleForTesting
static final String AND_BIT_VALUE = "and-bit";
@VisibleForTesting
static final String IS_A_VALUE = "is-a";
- /**
- * Add this constant to length value to achieve all ones in the leftmost nibble.
- */
- private static final int LENGTH_MAGIC = 61440;
+ 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 int OPERAND_LENGTH = 8;
+ protected abstract void serializeMpReachNlri(final Attributes1 pathAttributes, final ByteBuf byteAggregator);
- private static final int END_OF_LIST = 0;
- private static final int AND_BIT = 1;
- private static final int LENGTH_BITMASK = 48;
- private static final int LENGTH_SHIFT = 4;
- private static final int LESS_THAN = 5;
- private static final int GREATER_THAN = 6;
- private static final int EQUAL = 7;
+ protected abstract void serializeMpUnreachNlri(final Attributes2 pathAttributes, final ByteBuf byteAggregator);
- private static final int NOT = 6;
- private static final int MATCH = 7;
+ protected abstract void serializeSpecificFSType(final FlowspecType fsType, final ByteBuf nlriByteBuf);
- private static final int LAST_FRAGMENT = 4;
- private static final int FIRST_FRAGMENT = 5;
- private static final int IS_A_FRAGMENT = 6;
- private static final int DONT_FRAGMENT = 7;
+ protected abstract byte serializeFragment(final Fragment fragment);
- private static final int MAX_NLRI_LENGTH = 4095;
- private static final int MAX_NLRI_LENGTH_ONE_BYTE = 240;
+ 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<Flowspec> dst);
+
+ abstract DestinationType createAdvertizedRoutesDestinationType(final List<Flowspec> dst);
+
+ protected abstract void stringSpecificFSNlriType(final FlowspecType value, final StringBuilder buffer);
@Override
- public void serializeAttribute(final DataObject attribute, final ByteBuf byteAggregator) {
+ public final void serializeAttribute(final DataObject attribute, final ByteBuf byteAggregator) {
Preconditions.checkArgument(attribute instanceof Attributes, "Attribute parameter is not a PathAttribute object.");
final Attributes pathAttributes = (Attributes) attribute;
final Attributes1 pathAttributes1 = pathAttributes.getAugmentation(Attributes1.class);
final Attributes2 pathAttributes2 = pathAttributes.getAugmentation(Attributes2.class);
- if (pathAttributes1 != null) {
- final AdvertizedRoutes routes = (pathAttributes1.getMpReachNlri()).getAdvertizedRoutes();
- if (routes != null && routes.getDestinationType() instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationFlowspecCase) {
- final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationFlowspecCase flowspecCase = (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationFlowspecCase) routes.getDestinationType();
- serializeNlri(flowspecCase.getDestinationFlowspec().getFlowspec(), byteAggregator);
- }
- } else if (pathAttributes2 != null) {
- final MpUnreachNlri mpUnreachNlri = pathAttributes2.getMpUnreachNlri();
- if (mpUnreachNlri.getWithdrawnRoutes() != null && mpUnreachNlri.getWithdrawnRoutes().getDestinationType() instanceof DestinationFlowspecCase) {
- final DestinationFlowspecCase flowspecCase = (DestinationFlowspecCase) mpUnreachNlri.getWithdrawnRoutes().getDestinationType();
- serializeNlri(flowspecCase.getDestinationFlowspec().getFlowspec(), byteAggregator);
- }
- }
+ serializeMpReachNlri(pathAttributes1, byteAggregator);
+ serializeMpUnreachNlri(pathAttributes2, byteAggregator);
}
- /**
- * Serializes Flowspec component type that has maximum of 2B sized value field and numeric operand.
- *
- * @param list of items to be serialized
- * @param nlriByteBuf where the items will be serialized
- */
- private static <T extends NumericTwoByteValue> void serializeNumericTwoByteValue(final List<T> list, final ByteBuf nlriByteBuf) {
- for (final T item : list) {
- final ByteBuf protoBuf = Unpooled.buffer();
- writeShortest(item.getValue(), protoBuf);
- serializeNumericOperand(item.getOp(), protoBuf.readableBytes(), nlriByteBuf);
- nlriByteBuf.writeBytes(protoBuf);
+ @Override
+ public final void parseNlri(final ByteBuf nlri, final MpUnreachNlriBuilder builder) throws BGPParsingException {
+ if (!nlri.isReadable()) {
+ return;
}
+ final List<Flowspec> dst = parseNlri(nlri);
+
+ builder.setWithdrawnRoutes(new WithdrawnRoutesBuilder().setDestinationType(createWidthdrawnDestinationType(dst)).build());
}
- /**
- * Serializes Flowspec component type that has maximum of 1B sized value field and numeric operand.
- *
- * @param list of items to be serialized
- * @param nlriByteBuf where the items will be serialized
- */
- private static <T extends NumericOneByteValue> void serializeNumericOneByteValue(final List<T> list, final ByteBuf nlriByteBuf) {
- for (final T type : list) {
- serializeNumericOperand(type.getOp(), 1, nlriByteBuf);
- writeShortest(type.getValue(), nlriByteBuf);
+ @Override
+ public final void parseNlri(final ByteBuf nlri, final MpReachNlriBuilder builder) throws BGPParsingException {
+ if (!nlri.isReadable()) {
+ return;
}
+ final List<Flowspec> dst = parseNlri(nlri);
+ builder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(createAdvertizedRoutesDestinationType(dst)).build());
}
/**
* @param flows flowspec NLRI to be serialized
* @param buffer where flowspec NLRI will be serialized
*/
- public static void serializeNlri(final List<Flowspec> flows, final ByteBuf buffer) {
+ public final void serializeNlri(final List<Flowspec> flows, final ByteBuf buffer) {
final ByteBuf nlriByteBuf = Unpooled.buffer();
for (final Flowspec flow : flows) {
serializeFlowspec(flow, nlriByteBuf);
buffer.writeBytes(nlriByteBuf);
}
- private static void serializeFlowspec(final Flowspec flow, final ByteBuf nlriByteBuf) {
- nlriByteBuf.writeByte(flow.getComponentType().getIntValue());
- final FlowspecType value = flow.getFlowspecType();
- switch (flow.getComponentType()) {
- case DestinationPrefix:
- nlriByteBuf.writeBytes(Ipv4Util.bytesForPrefixBegin(((DestinationPrefixCase) value).getDestinationPrefix()));
- break;
- case SourcePrefix:
- nlriByteBuf.writeBytes(Ipv4Util.bytesForPrefixBegin(((SourcePrefixCase) value).getSourcePrefix()));
- break;
- case ProtocolIp:
- serializeNumericTwoByteValue(((ProtocolIpCase) value).getProtocolIps(), nlriByteBuf);
- break;
- case Port:
- serializeNumericTwoByteValue(((PortCase) value).getPorts(), nlriByteBuf);
- break;
- case DestinationPort:
- serializeNumericTwoByteValue(((DestinationPortCase) value).getDestinationPorts(), nlriByteBuf);
- break;
- case SourcePort:
- serializeNumericTwoByteValue(((SourcePortCase) value).getSourcePorts(), nlriByteBuf);
- break;
- case IcmpType:
- serializeNumericOneByteValue(((IcmpTypeCase) value).getTypes(), nlriByteBuf);
- break;
- case IcmpCode:
- serializeNumericOneByteValue(((IcmpCodeCase) value).getCodes(), nlriByteBuf);
- break;
- case TcpFlags:
- serializeTcpFlags(((TcpFlagsCase) value).getTcpFlags(), nlriByteBuf);
- break;
- case PacketLength:
- serializeNumericTwoByteValue(((PacketLengthCase) value).getPacketLengths(), nlriByteBuf);
- break;
- case Dscp:
- serializeDscps(((DscpCase) value).getDscps(), nlriByteBuf);
- break;
- case Fragment:
- serializeFragments(((FragmentCase) value).getFragments(), nlriByteBuf);
- break;
- default:
- LOG.warn("Unknown Component Type.");
- break;
+ /**
+ * Serializes Flowspec component type that has maximum of 2B sized value field and numeric operand.
+ *
+ * @param list of items to be serialized
+ * @param nlriByteBuf where the items will be serialized
+ */
+ protected static final <T extends NumericTwoByteValue> void serializeNumericTwoByteValue(final List<T> list, final ByteBuf nlriByteBuf) {
+ for (final T item : list) {
+ final ByteBuf protoBuf = Unpooled.buffer();
+ writeShortest(item.getValue(), protoBuf);
+ serializeNumericOperand(item.getOp(), protoBuf.readableBytes(), nlriByteBuf);
+ nlriByteBuf.writeBytes(protoBuf);
+ }
+ }
+
+ /**
+ * Serializes Flowspec component type that has maximum of 1B sized value field and numeric operand.
+ *
+ * @param list of items to be serialized
+ * @param nlriByteBuf where the items will be serialized
+ */
+ protected static final <T extends NumericOneByteValue> void serializeNumericOneByteValue(final List<T> list, final ByteBuf nlriByteBuf) {
+ for (final T type : list) {
+ serializeNumericOperand(type.getOp(), 1, nlriByteBuf);
+ writeShortest(type.getValue(), nlriByteBuf);
}
}
* @param value integer to be written
* @param buffer ByteBuf where the value will be written
*/
- private static void writeShortest(final int value, final ByteBuf buffer) {
+ protected static final void writeShortest(final int value, final ByteBuf buffer) {
if (value <= Values.UNSIGNED_BYTE_MAX_VALUE) {
buffer.writeByte(UnsignedBytes.checkedCast(value));
} else if (value <= Values.UNSIGNED_SHORT_MAX_VALUE) {
}
}
- private static void serializeNumericOperand(final NumericOperand op, final int length, final ByteBuf buffer) {
+ protected static final void serializeNumericOperand(final NumericOperand op, final int length, final ByteBuf buffer) {
final BitArray bs = new BitArray(OPERAND_LENGTH);
bs.set(END_OF_LIST, op.isEndOfList());
bs.set(AND_BIT, op.isAndBit());
buffer.writeByte(bs.toByte() | len);
}
- private static void serializeBitmaskOperand(final BitmaskOperand op, final int length, final ByteBuf buffer) {
+ protected static final void serializeBitmaskOperand(final BitmaskOperand op, final int length, final ByteBuf buffer) {
final BitArray bs = new BitArray(OPERAND_LENGTH);
bs.set(END_OF_LIST, op.isEndOfList());
bs.set(AND_BIT, op.isAndBit());
buffer.writeByte(bs.toByte() | len);
}
- private static void serializeTcpFlags(final List<TcpFlags> flags, final ByteBuf nlriByteBuf) {
+ protected static final void serializeTcpFlags(final List<TcpFlags> flags, final ByteBuf nlriByteBuf) {
for (final TcpFlags flag : flags) {
final ByteBuf flagsBuf = Unpooled.buffer();
writeShortest(flag.getValue(), flagsBuf);
}
}
- private static void serializeDscps(final List<Dscps> dscps, final ByteBuf nlriByteBuf) {
+ protected static final void serializeDscps(final List<Dscps> dscps, final ByteBuf nlriByteBuf) {
for (final Dscps dscp : dscps) {
serializeNumericOperand(dscp.getOp(), 1, nlriByteBuf);
writeShortest(dscp.getValue().getValue(), nlriByteBuf);
}
}
- private static void serializeFragments(final List<Fragments> fragments, final ByteBuf nlriByteBuf) {
+ protected final void serializeFragments(final List<Fragments> fragments, final ByteBuf nlriByteBuf) {
for (final Fragments fragment : fragments) {
serializeBitmaskOperand(fragment.getOp(), 1, nlriByteBuf);
nlriByteBuf.writeByte(serializeFragment(fragment.getValue()));
}
}
- @Override
- public void parseNlri(final ByteBuf nlri, final MpUnreachNlriBuilder builder) throws BGPParsingException {
- if (!nlri.isReadable()) {
- return;
- }
- final List<Flowspec> dst = parseNlri(nlri);
-
- builder.setWithdrawnRoutes(new WithdrawnRoutesBuilder().setDestinationType(
- new DestinationFlowspecCaseBuilder().setDestinationFlowspec(
- new DestinationFlowspecBuilder().setFlowspec(
- dst).build()).build()).build());
- }
-
- @Override
- public void parseNlri(final ByteBuf nlri, final MpReachNlriBuilder builder) throws BGPParsingException {
- if (!nlri.isReadable()) {
- return;
+ protected final void serializeFlowspec(final Flowspec flow, final ByteBuf nlriByteBuf) {
+ final FlowspecType fsType = flow.getFlowspecType();
+ if (fsType instanceof PortCase) {
+ nlriByteBuf.writeByte(PORT_VALUE);
+ serializeNumericTwoByteValue(((PortCase) fsType).getPorts(), nlriByteBuf);
+ } else if (fsType instanceof DestinationPortCase) {
+ nlriByteBuf.writeByte(DESTINATION_PORT_VALUE);
+ serializeNumericTwoByteValue(((DestinationPortCase) fsType).getDestinationPorts(), nlriByteBuf);
+ } else if (fsType instanceof SourcePortCase) {
+ nlriByteBuf.writeByte(SOURCE_PORT_VALUE);
+ serializeNumericTwoByteValue(((SourcePortCase) fsType).getSourcePorts(), nlriByteBuf);
+ } else if (fsType instanceof IcmpTypeCase) {
+ nlriByteBuf.writeByte(ICMP_TYPE_VALUE);
+ serializeNumericOneByteValue(((IcmpTypeCase) fsType).getTypes(), nlriByteBuf);
+ } else if (fsType instanceof IcmpCodeCase) {
+ nlriByteBuf.writeByte(ICMP_CODE_VALUE);
+ serializeNumericOneByteValue(((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);
+ serializeNumericTwoByteValue(((PacketLengthCase) fsType).getPacketLengths(), nlriByteBuf);
+ } else if (fsType instanceof DscpCase) {
+ nlriByteBuf.writeByte(DSCP_VALUE);
+ serializeDscps(((DscpCase) fsType).getDscps(), nlriByteBuf);
+ } else {
+ serializeSpecificFSType(fsType, nlriByteBuf);
}
- final List<Flowspec> dst = parseNlri(nlri);
-
- builder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(
- new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationFlowspecCaseBuilder()
- .setDestinationFlowspec(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.update.attributes.mp.reach.nlri.advertized.routes.destination.type.destination.flowspec._case.DestinationFlowspecBuilder()
- .setFlowspec(dst).build()).build()).build());
}
/**
* @param nlri byte representation of NLRI which will be parsed
* @return list of Flowspec
*/
- public static List<Flowspec> parseNlri(final ByteBuf nlri) throws BGPParsingException {
+ public final List<Flowspec> parseNlri(final ByteBuf nlri) throws BGPParsingException {
if (!nlri.isReadable()) {
return null;
}
while (nlri.isReadable()) {
final FlowspecBuilder builder = new FlowspecBuilder();
- final ComponentType type = ComponentType.forValue(nlri.readUnsignedByte());
- builder.setComponentType(type);
+ final short type = nlri.readUnsignedByte();
setFlowspecType(builder, type, nlri);
fss.add(builder.build());
}
return fss;
}
- private static void setFlowspecType(final FlowspecBuilder builder, final ComponentType type, final ByteBuf nlri) {
+ protected final void setFlowspecType(final FlowspecBuilder builder, final short type, final ByteBuf nlri) {
switch (type) {
- case DestinationPrefix:
- builder.setFlowspecType(new DestinationPrefixCaseBuilder().setDestinationPrefix(Ipv4Util.prefixForByteBuf(nlri)).build());
- break;
- case SourcePrefix:
- builder.setFlowspecType(new SourcePrefixCaseBuilder().setSourcePrefix(Ipv4Util.prefixForByteBuf(nlri)).build());
- break;
- case ProtocolIp:
- builder.setFlowspecType(new ProtocolIpCaseBuilder().setProtocolIps(parseProtocolIp(nlri)).build());
- break;
- case Port:
+ case PORT_VALUE:
builder.setFlowspecType(new PortCaseBuilder().setPorts(parsePort(nlri)).build());
break;
- case DestinationPort:
+ case DESTINATION_PORT_VALUE:
builder.setFlowspecType(new DestinationPortCaseBuilder().setDestinationPorts(parseDestinationPort(nlri)).build());
break;
- case SourcePort:
+ case SOURCE_PORT_VALUE:
builder.setFlowspecType(new SourcePortCaseBuilder().setSourcePorts(parseSourcePort(nlri)).build());
break;
- case IcmpType:
+ case ICMP_TYPE_VALUE:
builder.setFlowspecType(new IcmpTypeCaseBuilder().setTypes(parseIcmpType(nlri)).build());
break;
- case IcmpCode:
+ case ICMP_CODE_VALUE:
builder.setFlowspecType(new IcmpCodeCaseBuilder().setCodes(parseIcmpCode(nlri)).build());
break;
- case TcpFlags:
+ case TCP_FLAGS_VALUE:
builder.setFlowspecType(new TcpFlagsCaseBuilder().setTcpFlags(parseTcpFlags(nlri)).build());
break;
- case PacketLength:
+ case PACKET_LENGTH_VALUE:
builder.setFlowspecType(new PacketLengthCaseBuilder().setPacketLengths(parsePacketLength(nlri)).build());
break;
- case Dscp:
+ case DSCP_VALUE:
builder.setFlowspecType(new DscpCaseBuilder().setDscps(parseDscp(nlri)).build());
break;
- case Fragment:
- builder.setFlowspecType(new FragmentCaseBuilder().setFragments(parseFragment(nlri)).build());
- break;
default:
+ setSpecificFlowspecType(builder, type, nlri);
break;
}
}
- private static List<ProtocolIps> parseProtocolIp(final ByteBuf nlri) {
- final List<ProtocolIps> 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 = parseNumeric(b);
- builder.setOp(op);
- final short length = parseLength(b);
- builder.setValue(ByteArray.bytesToInt(ByteArray.readBytes(nlri, length)));
- end = op.isEndOfList();
- ips.add(builder.build());
- }
- return ips;
- }
-
private static List<Ports> parsePort(final ByteBuf nlri) {
final List<Ports> ports = new ArrayList<>();
boolean end = false;
// RFC does not specify operator
final NumericOperand op = parseNumeric(b);
builder.setOp(op);
- builder.setValue(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.Dscp(nlri.readUnsignedByte()));
+ 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;
}
- private static List<Fragments> parseFragment(final ByteBuf nlri) {
+ protected final List<Fragments> parseFragment(final ByteBuf nlri) {
final List<Fragments> fragments = new ArrayList<>();
boolean end = false;
// we can do this as all fields will be rewritten in the cycle
return fragments;
}
- private static NumericOperand parseNumeric(final byte op) {
+ protected static final NumericOperand parseNumeric(final byte op) {
final BitArray bs = BitArray.valueOf(op);
return new NumericOperand(bs.get(AND_BIT), bs.get(END_OF_LIST), bs.get(EQUAL), bs.get(GREATER_THAN), bs.get(LESS_THAN));
}
- private static BitmaskOperand parseBitmask(final byte op) {
+ protected static final BitmaskOperand parseBitmask(final byte op) {
final BitArray bs = BitArray.valueOf(op);
return new BitmaskOperand(bs.get(AND_BIT), bs.get(END_OF_LIST), bs.get(MATCH), bs.get(NOT));
}
@VisibleForTesting
- public static short parseLength(final byte op) {
+ public static final short parseLength(final byte op) {
return (short) (1 << ((op & LENGTH_BITMASK) >> LENGTH_SHIFT));
}
- private static org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.Fragment parseFragment(final byte fragment) {
- final BitArray bs = BitArray.valueOf(fragment);
- return new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.Fragment(bs.get(DONT_FRAGMENT), bs.get(FIRST_FRAGMENT), bs.get(IS_A_FRAGMENT), bs.get(LAST_FRAGMENT));
- }
-
- private static byte serializeFragment(final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.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();
- }
-
- public static String stringNlri(final DataContainerNode<?> flowspec) {
+ public final String stringNlri(final DataContainerNode<?> flowspec) {
return stringNlri(extractFlowspec((MapEntryNode) flowspec));
}
- public static Flowspec extractFlowspec(final MapEntryNode route) {
- final FlowspecBuilder fs = new FlowspecBuilder();
- final Optional<DataContainerChild<? extends PathArgument, ?>> compType = route.getChild(COMPONENT_TYPE_NID);
- if (compType.isPresent()) {
- fs.setComponentType(componentTypeValue((String) compType.get().getValue()));
- }
- final ChoiceNode fsType = (ChoiceNode) route.getChild(FLOWSPEC_TYPE_NID).get();
- if (fsType.getChild(DEST_PREFIX_NID).isPresent()) {
- fs.setFlowspecType(new DestinationPrefixCaseBuilder().setDestinationPrefix(
- new Ipv4Prefix((String) fsType.getChild(DEST_PREFIX_NID).get().getValue())).build());
- } else if (fsType.getChild(SOURCE_PREFIX_NID).isPresent()) {
- fs.setFlowspecType(new SourcePrefixCaseBuilder().setSourcePrefix(new Ipv4Prefix((String) fsType.getChild(SOURCE_PREFIX_NID).get().getValue()))
- .build());
- } else if (fsType.getChild(PROTOCOL_IP_NID).isPresent()) {
- fs.setFlowspecType(new ProtocolIpCaseBuilder().setProtocolIps(createProtocolsIps((UnkeyedListNode) fsType.getChild(PROTOCOL_IP_NID).get())).build());
- } else if (fsType.getChild(PORTS_NID).isPresent()) {
- fs.setFlowspecType(new PortCaseBuilder().setPorts(createPorts((UnkeyedListNode) fsType.getChild(PORTS_NID).get())).build());
- } else if (fsType.getChild(DEST_PORT_NID).isPresent()) {
- fs.setFlowspecType(new DestinationPortCaseBuilder().setDestinationPorts(createDestinationPorts((UnkeyedListNode) fsType.getChild(DEST_PORT_NID).get())).build());
- } else if (fsType.getChild(SOURCE_PORT_NID).isPresent()) {
- fs.setFlowspecType(new SourcePortCaseBuilder().setSourcePorts(createSourcePorts((UnkeyedListNode) fsType.getChild(SOURCE_PORT_NID).get())).build());
- } else if (fsType.getChild(ICMP_TYPE_NID).isPresent()) {
- fs.setFlowspecType(new IcmpTypeCaseBuilder().setTypes(createTypes((UnkeyedListNode) fsType.getChild(ICMP_TYPE_NID).get())).build());
- } else if (fsType.getChild(ICMP_CODE_NID).isPresent()) {
- fs.setFlowspecType(new IcmpCodeCaseBuilder().setCodes(createCodes((UnkeyedListNode) fsType.getChild(ICMP_CODE_NID).get())).build());
- } else if (fsType.getChild(TCP_FLAGS_NID).isPresent()) {
- fs.setFlowspecType(new TcpFlagsCaseBuilder().setTcpFlags(createTcpFlags((UnkeyedListNode) fsType.getChild(TCP_FLAGS_NID).get())).build());
- } else if (fsType.getChild(PACKET_LENGTHS_NID).isPresent()) {
- fs.setFlowspecType(new PacketLengthCaseBuilder().setPacketLengths(createPacketLengths((UnkeyedListNode) fsType.getChild(PACKET_LENGTHS_NID).get())).build());
- } else if (fsType.getChild(DSCP_NID).isPresent()) {
- fs.setFlowspecType(new DscpCaseBuilder().setDscps(createDscpsLengths((UnkeyedListNode) fsType.getChild(DSCP_NID).get())).build());
- } else if (fsType.getChild(FRAGMENT_NID).isPresent()) {
- fs.setFlowspecType(new FragmentCaseBuilder().setFragments(createFragments((UnkeyedListNode) fsType.getChild(FRAGMENT_NID).get())).build());
- }
- return fs.build();
- }
-
- private static NumericOperand createNumericOperand(final Set<String> opValues) {
- return new NumericOperand(opValues.contains(AND_BIT_VALUE), opValues.contains(END_OF_LIST_VALUE), opValues.contains(EQUALS_VALUE), opValues.contains(GREATER_THAN_VALUE), opValues.contains(LESS_THAN_VALUE));
- }
-
- private static BitmaskOperand createBitmaskOperand(final Set<String> opValues) {
- return new BitmaskOperand(opValues.contains(AND_BIT_VALUE), opValues.contains(END_OF_LIST_VALUE), opValues.contains(MATCH_VALUE), opValues.contains(NOT_VALUE));
- }
-
- private static Fragment createFragment(final Set<String> data) {
- return new Fragment(data.contains(DO_NOT_VALUE), data.contains(FIRST_VALUE), data.contains(IS_A_VALUE), data.contains(LAST_VALUE));
- }
-
- private static List<ProtocolIps> createProtocolsIps(final UnkeyedListNode protocolIpsData) {
- final List<ProtocolIps> protocolIps = new ArrayList<>();
-
- for (final UnkeyedListEntryNode node : protocolIpsData.getValue()) {
- final ProtocolIpsBuilder ipsBuilder = new ProtocolIpsBuilder();
- final Optional<DataContainerChild<? extends PathArgument, ?>> opValue = node.getChild(OP_NID);
- if (opValue.isPresent()) {
- ipsBuilder.setOp(createNumericOperand((Set<String>) opValue.get().getValue()));
- }
- final Optional<DataContainerChild<? extends PathArgument, ?>> valueNode = node.getChild(VALUE_NID);
- if (valueNode.isPresent()) {
- ipsBuilder.setValue((Integer) valueNode.get().getValue());
+ public final Flowspec extractFlowspec(final MapEntryNode route) {
+ final FlowspecBuilder fsBuilder = new FlowspecBuilder();
+ final Optional<DataContainerChild<?, ?>> flowspecType = route.getChild(FLOWSPEC_TYPE_NID);
+ if (flowspecType.isPresent()) {
+ final ChoiceNode fsType = (ChoiceNode) flowspecType.get();
+ if (fsType.getChild(PORTS_NID).isPresent()) {
+ fsBuilder.setFlowspecType(new PortCaseBuilder().setPorts(createPorts((UnkeyedListNode) fsType.getChild(PORTS_NID).get())).build());
+ } else if (fsType.getChild(DEST_PORT_NID).isPresent()) {
+ fsBuilder.setFlowspecType(new DestinationPortCaseBuilder().setDestinationPorts(createDestinationPorts((UnkeyedListNode) fsType.getChild(DEST_PORT_NID).get())).build());
+ } else if (fsType.getChild(SOURCE_PORT_NID).isPresent()) {
+ fsBuilder.setFlowspecType(new SourcePortCaseBuilder().setSourcePorts(createSourcePorts((UnkeyedListNode) fsType.getChild(SOURCE_PORT_NID).get())).build());
+ } else if (fsType.getChild(ICMP_TYPE_NID).isPresent()) {
+ fsBuilder.setFlowspecType(new IcmpTypeCaseBuilder().setTypes(createTypes((UnkeyedListNode) fsType.getChild(ICMP_TYPE_NID).get())).build());
+ } else if (fsType.getChild(ICMP_CODE_NID).isPresent()) {
+ fsBuilder.setFlowspecType(new IcmpCodeCaseBuilder().setCodes(createCodes((UnkeyedListNode) fsType.getChild(ICMP_CODE_NID).get())).build());
+ } else if (fsType.getChild(TCP_FLAGS_NID).isPresent()) {
+ fsBuilder.setFlowspecType(new TcpFlagsCaseBuilder().setTcpFlags(createTcpFlags((UnkeyedListNode) fsType.getChild(TCP_FLAGS_NID).get())).build());
+ } else if (fsType.getChild(PACKET_LENGTHS_NID).isPresent()) {
+ fsBuilder.setFlowspecType(new PacketLengthCaseBuilder().setPacketLengths(createPacketLengths((UnkeyedListNode) fsType.getChild(PACKET_LENGTHS_NID).get())).build());
+ } else if (fsType.getChild(DSCP_NID).isPresent()) {
+ fsBuilder.setFlowspecType(new DscpCaseBuilder().setDscps(createDscpsLengths((UnkeyedListNode) fsType.getChild(DSCP_NID).get())).build());
+ } else if (fsType.getChild(FRAGMENT_NID).isPresent()) {
+ fsBuilder.setFlowspecType(new FragmentCaseBuilder().setFragments(createFragments((UnkeyedListNode) fsType.getChild(FRAGMENT_NID).get())).build());
+ } else {
+ extractSpecificFlowspec(fsType, fsBuilder);
}
- protocolIps.add(ipsBuilder.build());
}
-
- return protocolIps;
+ return fsBuilder.build();
}
private static List<Ports> createPorts(final UnkeyedListNode portsData) {
return fragments;
}
- // FIXME: use codec
- private static ComponentType componentTypeValue(final String compType) {
- switch (compType) {
- case "destination-prefix":
- return ComponentType.DestinationPrefix;
- case "source-prefix":
- return ComponentType.SourcePrefix;
- case "protocol-ip":
- return ComponentType.ProtocolIp;
- case "port":
- return ComponentType.Port;
- case "destination-port":
- return ComponentType.DestinationPort;
- case "source-port":
- return ComponentType.SourcePort;
- case "icmp-type":
- return ComponentType.IcmpType;
- case "icmp-code":
- return ComponentType.IcmpCode;
- case "tcp-flags":
- return ComponentType.TcpFlags;
- case "packet-length":
- return ComponentType.PacketLength;
- case "dscp":
- return ComponentType.Dscp;
- case "fragment":
- return ComponentType.Fragment;
- default:
- return null;
- }
+ private static Fragment createFragment(final Set<String> data) {
+ return new Fragment(data.contains(DO_NOT_VALUE), data.contains(FIRST_VALUE), data.contains(IS_A_VALUE), data.contains(LAST_VALUE));
+ }
+
+ protected static final NumericOperand createNumericOperand(final Set<String> opValues) {
+ return new NumericOperand(opValues.contains(AND_BIT_VALUE), opValues.contains(END_OF_LIST_VALUE), opValues.contains(EQUALS_VALUE), opValues.contains(GREATER_THAN_VALUE), opValues.contains(LESS_THAN_VALUE));
+ }
+
+ private static BitmaskOperand createBitmaskOperand(final Set<String> opValues) {
+ return new BitmaskOperand(opValues.contains(AND_BIT_VALUE), opValues.contains(END_OF_LIST_VALUE), opValues.contains(MATCH_VALUE), opValues.contains(NOT_VALUE));
}
@VisibleForTesting
- static final String stringNlri(final Flowspec flow) {
+ final String stringNlri(final Flowspec flow) {
final StringBuilder buffer = new StringBuilder("all packets ");
final FlowspecType value = flow.getFlowspecType();
- switch (flow.getComponentType()) {
- case DestinationPrefix:
- buffer.append("to ");
- buffer.append(((DestinationPrefixCase) value).getDestinationPrefix().getValue());
- break;
- case SourcePrefix:
- buffer.append("from ");
- buffer.append(((SourcePrefixCase) value).getSourcePrefix().getValue());
- break;
- case ProtocolIp:
- buffer.append("where protocol ");
- buffer.append(stringNumericTwo(((ProtocolIpCase) value).getProtocolIps()));
- break;
- case Port:
+ if (value instanceof PortCase) {
buffer.append("where port ");
buffer.append(stringNumericTwo(((PortCase) value).getPorts()));
- break;
- case DestinationPort:
+ } else if (value instanceof DestinationPortCase) {
buffer.append("where destination port ");
buffer.append(stringNumericTwo(((DestinationPortCase) value).getDestinationPorts()));
- break;
- case SourcePort:
+ } else if (value instanceof SourcePortCase) {
buffer.append("where source port ");
buffer.append(stringNumericTwo(((SourcePortCase) value).getSourcePorts()));
- break;
- case IcmpType:
+ } else if (value instanceof IcmpTypeCase) {
buffer.append("where ICMP type ");
buffer.append(stringNumericOne(((IcmpTypeCase) value).getTypes()));
- break;
- case IcmpCode:
+ } else if (value instanceof IcmpCodeCase) {
buffer.append("where ICMP code ");
buffer.append(stringNumericOne(((IcmpCodeCase) value).getCodes()));
- break;
- case TcpFlags:
+ } else if (value instanceof TcpFlagsCase) {
buffer.append(stringTcpFlags(((TcpFlagsCase) value).getTcpFlags()));
- break;
- case PacketLength:
+ } else if (value instanceof PacketLengthCase) {
buffer.append("where packet length ");
buffer.append(stringNumericTwo(((PacketLengthCase) value).getPacketLengths()));
- break;
- case Dscp:
+ } else if (value instanceof DscpCase) {
buffer.append(stringDscp(((DscpCase) value).getDscps()));
- break;
- case Fragment:
+ } else if (value instanceof FragmentCase) {
buffer.append(stringFragment(((FragmentCase) value).getFragments()));
- break;
- default:
- LOG.warn("Skipping unhandled component type {}" , flow.getComponentType());
- break;
+ } else {
+ stringSpecificFSNlriType(value, buffer);
}
return buffer.toString();
}
return buffer.toString();
}
- private static <T extends NumericOneByteValue> String stringNumericOne(final List<T> list) {
+ protected static final <T extends NumericOneByteValue> String stringNumericOne(final List<T> list) {
final StringBuilder buffer = new StringBuilder();
boolean isFirst = true;
for (final T item : list) {
return buffer.toString();
}
- private static String stringNumericOperand(final NumericOperand op, final boolean isFirst) {
+ protected static final String stringNumericOperand(final NumericOperand op, final boolean isFirst) {
final StringBuilder buffer = new StringBuilder();
if (!op.isAndBit() && !isFirst) {
buffer.append("or ");
return buffer.toString();
}
- private static String stringFragment(final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.Fragment fragment) {
+ private static String stringFragment(final Fragment fragment) {
final StringBuilder buffer = new StringBuilder();
if (fragment.isDoNot()) {
buffer.append("'DO NOT' ");
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
import org.opendaylight.protocol.bgp.rib.spi.AbstractRIBSupport;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.FlowspecSubsequentAddressFamily;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.bgp.rib.rib.loc.rib.tables.routes.FlowspecRoutesCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.flowspec.destination.Flowspec;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.flowspec.routes.FlowspecRoutes;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.flowspec.routes.flowspec.routes.FlowspecRoute;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationFlowspecCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.update.attributes.mp.reach.nlri.advertized.routes.destination.type.destination.flowspec._case.DestinationFlowspec;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.update.attributes.mp.reach.nlri.advertized.routes.destination.type.destination.flowspec._case.DestinationFlowspecBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.FlowspecSubsequentAddressFamily;
+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.ipv6.routes.flowspec.ipv6.routes.FlowspecRoute;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.MpReachNlri;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.MpReachNlriBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.MpUnreachNlri;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.MpUnreachNlriBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.mp.reach.nlri.AdvertizedRoutesBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.mp.unreach.nlri.WithdrawnRoutesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.Route;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.tables.Routes;
-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.AddressFamily;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.CNextHop;
import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
-import org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode;
import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
import org.opendaylight.yangtools.yang.data.api.schema.DataContainerNode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-final class FlowspecRIBSupport extends AbstractRIBSupport {
+public abstract class AbstractFlowspecRIBSupport extends AbstractRIBSupport {
- private abstract static class ApplyRoute {
+ protected abstract static class ApplyRoute {
abstract void apply(DOMDataWriteTransaction tx, YangInstanceIdentifier base, NodeIdentifierWithPredicates routeKey, DataContainerNode<?> route, final ContainerNode attributes);
}
- private static final class DeleteRoute extends ApplyRoute {
+ protected static final class DeleteRoute extends ApplyRoute {
@Override
void apply(final DOMDataWriteTransaction tx, final YangInstanceIdentifier base, final NodeIdentifierWithPredicates routeKey, final DataContainerNode<?> route, final ContainerNode attributes) {
tx.delete(LogicalDatastoreType.OPERATIONAL, base.node(routeKey));
}
}
- private final class PutRoute extends ApplyRoute {
+ protected final class PutRoute extends ApplyRoute {
@Override
void apply(final DOMDataWriteTransaction tx, final YangInstanceIdentifier base, final NodeIdentifierWithPredicates routeKey,
final DataContainerNode<?> route, final ContainerNode attributes) {
}
}
- private static final Logger LOG = LoggerFactory.getLogger(FlowspecRIBSupport.class);
-
+ private static final Logger LOG = LoggerFactory.getLogger(AbstractFlowspecRIBSupport.class);
private static final QName ROUTE_KEY = QName.cachedReference(QName.create(FlowspecRoute.QNAME, "route-key"));
- private static final FlowspecRIBSupport SINGLETON = new FlowspecRIBSupport();
private static final ApplyRoute DELETE_ROUTE = new DeleteRoute();
-
- private final ChoiceNode emptyRoutes = Builders.choiceBuilder()
- .withNodeIdentifier(new NodeIdentifier(Routes.QNAME))
- .addChild(Builders.containerBuilder()
- .withNodeIdentifier(new NodeIdentifier(FlowspecRoutes.QNAME))
- .addChild(ImmutableNodes.mapNodeBuilder(FlowspecRoute.QNAME).build()).build()).build();
- private final NodeIdentifier destination = new NodeIdentifier(DestinationFlowspec.QNAME);
- private final NodeIdentifier route = new NodeIdentifier(FlowspecRoute.QNAME);
- private final NodeIdentifier nlriRoutesList = new NodeIdentifier(Flowspec.QNAME);
+ private final NodeIdentifier nlriRoutesListNid = new NodeIdentifier(Flowspec.QNAME);
private final ApplyRoute putRoute = new PutRoute();
- private FlowspecRIBSupport() {
- super(FlowspecRoutesCase.class, FlowspecRoutes.class, FlowspecRoute.class);
+ protected AbstractFlowspecRIBSupport(final Class<? extends Routes> cazeClass, final Class<? extends DataObject> containerClass,
+ final Class<? extends Route> listClass) {
+ super(cazeClass, containerClass, listClass);
}
- static FlowspecRIBSupport getInstance() {
- return SINGLETON;
- }
+ protected abstract NodeIdentifier routeIdentifier();
- @Override
- public ChoiceNode emptyRoutes() {
- return this.emptyRoutes;
- }
+ protected abstract AbstractFSNlriParser getParser();
+
+ protected abstract Class<? extends AddressFamily> getAfiClass();
@Override
- public ImmutableCollection<Class<? extends DataObject>> cacheableAttributeObjects() {
+ public final ImmutableCollection<Class<? extends DataObject>> cacheableAttributeObjects() {
return ImmutableSet.of();
}
@Override
- public ImmutableCollection<Class<? extends DataObject>> cacheableNlriObjects() {
+ public final ImmutableCollection<Class<? extends DataObject>> cacheableNlriObjects() {
return ImmutableSet.of();
}
@Override
- public boolean isComplexRoute() {
+ public final boolean isComplexRoute() {
return true;
}
@Override
- protected NodeIdentifier destinationContainerIdentifier() {
- return this.destination;
+ protected final void putDestinationRoutes(final DOMDataWriteTransaction tx, final YangInstanceIdentifier tablePath,
+ final ContainerNode destination, final ContainerNode attributes, final NodeIdentifier routesNodeId) {
+ processDestination(tx, tablePath.node(routesNodeId), destination, attributes, this.putRoute);
+ }
+
+ @Override
+ protected final void deleteDestinationRoutes(final DOMDataWriteTransaction tx, final YangInstanceIdentifier tablePath,
+ final ContainerNode destination, final NodeIdentifier routesNodeId) {
+ processDestination(tx, tablePath.node(routesNodeId), destination, null, DELETE_ROUTE);
}
private void processDestination(final DOMDataWriteTransaction tx, final YangInstanceIdentifier routesPath,
final ContainerNode destination, final ContainerNode attributes, final ApplyRoute function) {
if (destination != null) {
- final Optional<DataContainerChild<? extends PathArgument, ?>> maybeRoutes = destination.getChild(this.nlriRoutesList);
+ final Optional<DataContainerChild<? extends PathArgument, ?>> maybeRoutes = destination.getChild(this.nlriRoutesListNid);
if (maybeRoutes.isPresent()) {
final DataContainerChild<? extends PathArgument, ?> routes = maybeRoutes.get();
if (routes instanceof UnkeyedListNode) {
- final YangInstanceIdentifier base = routesPath.node(routesContainerIdentifier()).node(this.route);
+ final YangInstanceIdentifier base = routesPath.node(routesContainerIdentifier()).node(routeIdentifier());
for (final UnkeyedListEntryNode e : ((UnkeyedListNode)routes).getValue()) {
- final NodeIdentifierWithPredicates routeKey = new NodeIdentifierWithPredicates(FlowspecRoute.QNAME, ROUTE_KEY, FSNlriParser.stringNlri(e));
+ final NodeIdentifierWithPredicates routeKey = new NodeIdentifierWithPredicates(FlowspecRoute.QNAME, ROUTE_KEY, getParser().stringNlri(e));
function.apply(tx, base, routeKey, e, attributes);
}
} else {
}
@Override
- protected void deleteDestinationRoutes(final DOMDataWriteTransaction tx, final YangInstanceIdentifier tablePath,
- final ContainerNode destination, final NodeIdentifier routesNodeId) {
- processDestination(tx, tablePath.node(routesNodeId), destination, null, DELETE_ROUTE);
- }
-
- @Override
- protected void putDestinationRoutes(final DOMDataWriteTransaction tx, final YangInstanceIdentifier tablePath,
- final ContainerNode destination, final ContainerNode attributes, final NodeIdentifier routesNodeId) {
- processDestination(tx, tablePath.node(routesNodeId), destination, attributes, this.putRoute);
- }
-
- @Override
- protected MpReachNlri buildReach(final Collection<MapEntryNode> routes, final CNextHop hop) {
+ protected final MpReachNlri buildReach(final Collection<MapEntryNode> routes, final CNextHop hop) {
final MpReachNlriBuilder mb = new MpReachNlriBuilder();
- mb.setAfi(Ipv4AddressFamily.class);
+ mb.setAfi(getAfiClass());
mb.setSafi(FlowspecSubsequentAddressFamily.class);
mb.setCNextHop(hop);
final List<Flowspec> dests = new ArrayList<>(routes.size());
for (final MapEntryNode reachRoute : routes) {
- dests.add(FSNlriParser.extractFlowspec(reachRoute));
+ dests.add(getParser().extractFlowspec(reachRoute));
}
- mb.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(
- new DestinationFlowspecCaseBuilder().setDestinationFlowspec(
- new DestinationFlowspecBuilder().setFlowspec(dests).build()).build()).build());
+ mb.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(getParser().createAdvertizedRoutesDestinationType(dests)).build());
return mb.build();
}
@Override
- protected MpUnreachNlri buildUnreach(final Collection<MapEntryNode> routes) {
+ protected final MpUnreachNlri buildUnreach(final Collection<MapEntryNode> routes) {
final MpUnreachNlriBuilder mb = new MpUnreachNlriBuilder();
- mb.setAfi(Ipv4AddressFamily.class);
+ mb.setAfi(getAfiClass());
mb.setSafi(FlowspecSubsequentAddressFamily.class);
final List<Flowspec> dests = new ArrayList<>(routes.size());
for (final MapEntryNode unreachRoute : routes) {
- dests.add(FSNlriParser.extractFlowspec(unreachRoute));
+ dests.add(getParser().extractFlowspec(unreachRoute));
}
- mb.setWithdrawnRoutes(new WithdrawnRoutesBuilder().setDestinationType(
- new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.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.rev150114.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.destination.flowspec._case.DestinationFlowspecBuilder().setFlowspec(dests).build()).build()).build());
+ mb.setWithdrawnRoutes(new WithdrawnRoutesBuilder().setDestinationType(getParser().createWidthdrawnDestinationType(dests)).build());
return mb.build();
}
}
import org.opendaylight.protocol.bgp.parser.impl.message.update.ExtendedCommunitiesAttributeParser;
import org.opendaylight.protocol.bgp.parser.spi.AbstractBGPExtensionProviderActivator;
import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionProviderContext;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.FlowspecSubsequentAddressFamily;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.flowspec.routes.FlowspecRoutes;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.FlowspecSubsequentAddressFamily;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.ipv6.routes.FlowspecIpv6Routes;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.routes.FlowspecRoutes;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.attributes.ExtendedCommunities;
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 final class BGPActivator extends AbstractBGPExtensionProviderActivator {
regs.add(context.registerSubsequentAddressFamily(FlowspecSubsequentAddressFamily.class, FLOWSPEC_SAFI));
- regs.add(context.registerNlriParser(Ipv4AddressFamily.class, FlowspecSubsequentAddressFamily.class,
- new FSNlriParser()));
- regs.add(context.registerNlriSerializer(FlowspecRoutes.class, new FSNlriParser()));
+ final FSIpv4NlriParser ipv4Handler = new FSIpv4NlriParser();
+ final FSIpv6NlriParser ipv6Handler = new FSIpv6NlriParser();
+ regs.add(context.registerNlriParser(Ipv4AddressFamily.class, FlowspecSubsequentAddressFamily.class, ipv4Handler));
+ regs.add(context.registerNlriParser(Ipv6AddressFamily.class, FlowspecSubsequentAddressFamily.class, ipv6Handler));
+ regs.add(context.registerNlriSerializer(FlowspecRoutes.class, ipv4Handler));
+ regs.add(context.registerNlriSerializer(FlowspecIpv6Routes.class, ipv6Handler));
final ExtendedCommunitiesAttributeParser extendedCommunitiesAttributeParser = new FSExtendedCommunitiesAttributeParser(context.getReferenceCache());
regs.add(context.registerAttributeSerializer(ExtendedCommunities.class, extendedCommunitiesAttributeParser));
import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.protocol.util.ByteBufWriteUtil;
import org.opendaylight.protocol.util.ReferenceCache;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.Dscp;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.update.attributes.extended.communities.extended.community.RedirectExtendedCommunityCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.update.attributes.extended.communities.extended.community.RedirectExtendedCommunityCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.update.attributes.extended.communities.extended.community.TrafficActionExtendedCommunityCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.update.attributes.extended.communities.extended.community.TrafficActionExtendedCommunityCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.update.attributes.extended.communities.extended.community.TrafficMarkingExtendedCommunityCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.update.attributes.extended.communities.extended.community.TrafficMarkingExtendedCommunityCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.update.attributes.extended.communities.extended.community.TrafficRateExtendedCommunityCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.update.attributes.extended.communities.extended.community.TrafficRateExtendedCommunityCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.update.attributes.extended.communities.extended.community.redirect.extended.community._case.RedirectExtendedCommunity;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.update.attributes.extended.communities.extended.community.redirect.extended.community._case.RedirectExtendedCommunityBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.update.attributes.extended.communities.extended.community.traffic.action.extended.community._case.TrafficActionExtendedCommunity;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.update.attributes.extended.communities.extended.community.traffic.action.extended.community._case.TrafficActionExtendedCommunityBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.update.attributes.extended.communities.extended.community.traffic.marking.extended.community._case.TrafficMarkingExtendedCommunity;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.update.attributes.extended.communities.extended.community.traffic.marking.extended.community._case.TrafficMarkingExtendedCommunityBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.update.attributes.extended.communities.extended.community.traffic.rate.extended.community._case.TrafficRateExtendedCommunity;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.update.attributes.extended.communities.extended.community.traffic.rate.extended.community._case.TrafficRateExtendedCommunityBuilder;
+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.update.attributes.extended.communities.extended.community.RedirectExtendedCommunityCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.update.attributes.extended.communities.extended.community.RedirectExtendedCommunityCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.update.attributes.extended.communities.extended.community.TrafficActionExtendedCommunityCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.update.attributes.extended.communities.extended.community.TrafficActionExtendedCommunityCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.update.attributes.extended.communities.extended.community.TrafficMarkingExtendedCommunityCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.update.attributes.extended.communities.extended.community.TrafficMarkingExtendedCommunityCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.update.attributes.extended.communities.extended.community.TrafficRateExtendedCommunityCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.update.attributes.extended.communities.extended.community.TrafficRateExtendedCommunityCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.update.attributes.extended.communities.extended.community.redirect.extended.community._case.RedirectExtendedCommunity;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.update.attributes.extended.communities.extended.community.redirect.extended.community._case.RedirectExtendedCommunityBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.update.attributes.extended.communities.extended.community.traffic.action.extended.community._case.TrafficActionExtendedCommunity;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.update.attributes.extended.communities.extended.community.traffic.action.extended.community._case.TrafficActionExtendedCommunityBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.update.attributes.extended.communities.extended.community.traffic.marking.extended.community._case.TrafficMarkingExtendedCommunity;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.update.attributes.extended.communities.extended.community.traffic.marking.extended.community._case.TrafficMarkingExtendedCommunityBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.update.attributes.extended.communities.extended.community.traffic.rate.extended.community._case.TrafficRateExtendedCommunity;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.update.attributes.extended.communities.extended.community.traffic.rate.extended.community._case.TrafficRateExtendedCommunityBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.attributes.ExtendedCommunities;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.attributes.ExtendedCommunitiesBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.ShortAsNumber;
}
@Override
- public ExtendedCommunities parseExtendedCommunity(final ReferenceCache refCache, final ExtendedCommunitiesBuilder comm, final ByteBuf buffer) throws BGPDocumentedException {
+ public ExtendedCommunities parseExtendedCommunity(final ReferenceCache refCache, final ExtendedCommunitiesBuilder communitiesBuilder, final ByteBuf buffer) throws BGPDocumentedException {
ExtendedCommunity c = null;
- if (comm.getCommType().equals(FS_TYPE)) {
- switch (comm.getCommSubType()) {
+ if (communitiesBuilder.getCommType().equals(FS_TYPE)) {
+ switch (communitiesBuilder.getCommSubType()) {
case TRAFFIC_RATE_SUBTYPE:
final ShortAsNumber as = new ShortAsNumber((long) buffer.readUnsignedShort());
final Bandwidth value = new Bandwidth(ByteArray.readBytes(buffer, TRAFFIC_RATE_SIZE));
c = new TrafficMarkingExtendedCommunityCaseBuilder().setTrafficMarkingExtendedCommunity(new TrafficMarkingExtendedCommunityBuilder().setGlobalAdministrator(dscp).build()).build();
break;
default:
- throw new BGPDocumentedException("Could not parse Flowspec Extended Community type: " + comm.getCommSubType(), BGPError.OPT_ATTR_ERROR);
+ throw new BGPDocumentedException("Could not parse Flowspec Extended Community type: " + communitiesBuilder.getCommSubType(), BGPError.OPT_ATTR_ERROR);
}
}
if (c == null) {
LOG.debug("Extended community is not from Flowspec, fallback to original communities.");
- return super.parseExtendedCommunity(refCache, comm, buffer);
+ return super.parseExtendedCommunity(refCache, communitiesBuilder, buffer);
}
- return comm.setExtendedCommunity(c).build();
+ return communitiesBuilder.setExtendedCommunity(c).build();
}
@Override
--- /dev/null
+/*
+ * 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.annotations.VisibleForTesting;
+import com.google.common.base.Optional;
+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.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;
+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.SourcePrefixCase;
+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.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;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.MpUnreachNlri;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.mp.reach.nlri.AdvertizedRoutes;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
+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.UnkeyedListEntryNode;
+import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListNode;
+
+public final class FSIpv4NlriParser extends AbstractFSNlriParser {
+
+ private static final int IP_PROTOCOL_VALUE = 3;
+
+ @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);
+ serializeNumericOneByteValue(((ProtocolIpCase) value).getProtocolIps(), nlriByteBuf);
+ } else if (value instanceof FragmentCase) {
+ nlriByteBuf.writeByte(FRAGMENT_VALUE);
+ serializeFragments(((FragmentCase) value).getFragments(), nlriByteBuf);
+ }
+ }
+
+ @Override
+ DestinationType createWidthdrawnDestinationType(final List<Flowspec> dst) {
+ return new DestinationFlowspecCaseBuilder().setDestinationFlowspec(
+ new DestinationFlowspecBuilder().setFlowspec(
+ dst).build()).build();
+ }
+
+ @Override
+ DestinationType createAdvertizedRoutesDestinationType(final List<Flowspec> 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.DestinationFlowspecCaseBuilder()
+ .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._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 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;
+ }
+ }
+
+ private static List<ProtocolIps> parseProtocolIp(final ByteBuf nlri) {
+ final List<ProtocolIps> 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 = parseNumeric(b);
+ builder.setOp(op);
+ builder.setValue(nlri.readUnsignedByte());
+ end = op.isEndOfList();
+ ips.add(builder.build());
+ }
+ 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
+ public void extractSpecificFlowspec(final ChoiceNode fsType, final FlowspecBuilder fsBuilder) {
+ if (fsType.getChild(DEST_PREFIX_NID).isPresent()) {
+ fsBuilder.setFlowspecType(new DestinationPrefixCaseBuilder().setDestinationPrefix(
+ new Ipv4Prefix((String) fsType.getChild(DEST_PREFIX_NID).get().getValue())).build());
+ } else if (fsType.getChild(SOURCE_PREFIX_NID).isPresent()) {
+ fsBuilder.setFlowspecType(new SourcePrefixCaseBuilder().setSourcePrefix(new Ipv4Prefix((String) fsType.getChild(SOURCE_PREFIX_NID).get().getValue()))
+ .build());
+ } else if (fsType.getChild(PROTOCOL_IP_NID).isPresent()) {
+ fsBuilder.setFlowspecType(new ProtocolIpCaseBuilder().setProtocolIps(createProtocolsIps((UnkeyedListNode) fsType.getChild(PROTOCOL_IP_NID).get())).build());
+ }
+ }
+
+ private static List<ProtocolIps> createProtocolsIps(final UnkeyedListNode protocolIpsData) {
+ final List<ProtocolIps> protocolIps = new ArrayList<>();
+
+ for (final UnkeyedListEntryNode node : protocolIpsData.getValue()) {
+ final ProtocolIpsBuilder ipsBuilder = new ProtocolIpsBuilder();
+ final Optional<DataContainerChild<? extends PathArgument, ?>> opValue = node.getChild(OP_NID);
+ if (opValue.isPresent()) {
+ ipsBuilder.setOp(createNumericOperand((Set<String>) opValue.get().getValue()));
+ }
+ final Optional<DataContainerChild<? extends PathArgument, ?>> valueNode = node.getChild(VALUE_NID);
+ if (valueNode.isPresent()) {
+ ipsBuilder.setValue((Short) valueNode.get().getValue());
+ }
+ protocolIps.add(ipsBuilder.build());
+ }
+
+ return protocolIps;
+ }
+
+ @Override
+ protected void stringSpecificFSNlriType(final FlowspecType value, final StringBuilder buffer) {
+ if (value instanceof DestinationPrefixCase) {
+ buffer.append("to ");
+ buffer.append(((DestinationPrefixCase) value).getDestinationPrefix().getValue());
+ } else if (value instanceof SourcePrefixCase) {
+ buffer.append("from ");
+ buffer.append(((SourcePrefixCase) value).getSourcePrefix().getValue());
+ } else if (value instanceof ProtocolIpCase) {
+ buffer.append("where IP protocol ");
+ buffer.append(stringNumericOne(((ProtocolIpCase) value).getProtocolIps()));
+ }
+ }
+
+}
--- /dev/null
+/*
+ * 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.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.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;
+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.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.SourceIpv6PrefixCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.ipv6.flowspec.flowspec.type.SourceIpv6PrefixCaseBuilder;
+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.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;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.MpUnreachNlri;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.mp.reach.nlri.AdvertizedRoutes;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
+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.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;
+
+ 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);
+ serializeNumericOneByteValue(((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<FlowLabel> list, final ByteBuf nlriByteBuf) {
+ for (final FlowLabel item : list) {
+ final ByteBuf protoBuf = Unpooled.buffer();
+ writeShortest(item.getValue().intValue(), protoBuf);
+ serializeNumericOperand(item.getOp(), protoBuf.readableBytes(), nlriByteBuf);
+ nlriByteBuf.writeBytes(protoBuf);
+ }
+ }
+
+ private static byte[] insertOffsetByte(final byte[] ipPrefix) {
+ // income <len, prefix>
+ return Bytes.concat(new byte[] { ipPrefix[0] }, new byte[] { 0 }, ByteArray.subByte(ipPrefix, 1 , ipPrefix.length-1));
+ }
+
+ @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<Flowspec> dst) {
+ return new DestinationFlowspecIpv6CaseBuilder().setDestinationFlowspec(
+ new DestinationFlowspecBuilder().setFlowspec(
+ dst).build()).build();
+ }
+
+ @Override
+ DestinationType createAdvertizedRoutesDestinationType(final List<Flowspec> 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();
+ }
+
+ @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.readByte();
+ final int offset = nlri.readByte();
+ nlri.readBytes(offset);
+ 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<NextHeaders> parseNextHeader(final ByteBuf nlri) {
+ final List<NextHeaders> headers = new ArrayList<>();
+ boolean end = false;
+ // we can do this as all fields will be rewritten in the cycle
+ final NextHeadersBuilder builder = new NextHeadersBuilder();
+ while (!end) {
+ final byte b = nlri.readByte();
+ final NumericOperand op = parseNumeric(b);
+ builder.setOp(op);
+ builder.setValue(nlri.readUnsignedByte());
+ end = op.isEndOfList();
+ headers.add(builder.build());
+ }
+ return headers;
+ }
+
+ private static List<FlowLabel> parseFlowLabel(final ByteBuf nlri) {
+ final List<FlowLabel> labels = new ArrayList<>();
+ boolean end = false;
+ // we can do this as all fields will be rewritten in the cycle
+ final FlowLabelBuilder builder = new FlowLabelBuilder();
+ while (!end) {
+ final byte b = nlri.readByte();
+ final NumericOperand op = parseNumeric(b);
+ builder.setOp(op);
+ final short length = parseLength(b);
+ builder.setValue(ByteArray.bytesToLong(ByteArray.readBytes(nlri, length)));
+ end = op.isEndOfList();
+ labels.add(builder.build());
+ }
+ return labels;
+ }
+
+ @Override
+ public void extractSpecificFlowspec(final ChoiceNode fsType, final FlowspecBuilder fsBuilder) {
+ if (fsType.getChild(DEST_PREFIX_NID).isPresent()) {
+ fsBuilder.setFlowspecType(new DestinationIpv6PrefixCaseBuilder()
+ .setDestinationPrefix(new Ipv6Prefix((String) fsType.getChild(DEST_PREFIX_NID).get().getValue()))
+ .build());
+ } else if (fsType.getChild(SOURCE_PREFIX_NID).isPresent()) {
+ fsBuilder.setFlowspecType(new SourceIpv6PrefixCaseBuilder()
+ .setSourcePrefix(new Ipv6Prefix((String) fsType.getChild(SOURCE_PREFIX_NID).get().getValue()))
+ .build());
+ } else if (fsType.getChild(NEXT_HEADER_NID).isPresent()) {
+ fsBuilder.setFlowspecType(new NextHeaderCaseBuilder().setNextHeaders(createNextHeaders((UnkeyedListNode) fsType.getChild(NEXT_HEADER_NID).get())).build());
+ } else if (fsType.getChild(FLOW_LABEL_NID).isPresent()) {
+ fsBuilder.setFlowspecType(new FlowLabelCaseBuilder().setFlowLabel(createFlowLabels((UnkeyedListNode) fsType.getChild(FLOW_LABEL_NID).get())).build());
+ }
+ }
+
+ private List<NextHeaders> createNextHeaders(final UnkeyedListNode nextHeadersData) {
+ final List<NextHeaders> nextHeaders = new ArrayList<>();
+
+ for (final UnkeyedListEntryNode node : nextHeadersData.getValue()) {
+ final NextHeadersBuilder nextHeadersBuilder = new NextHeadersBuilder();
+ final Optional<DataContainerChild<? extends PathArgument, ?>> opValue = node.getChild(OP_NID);
+ if (opValue.isPresent()) {
+ nextHeadersBuilder.setOp(createNumericOperand((Set<String>) opValue.get().getValue()));
+ }
+ final Optional<DataContainerChild<? extends PathArgument, ?>> valueNode = node.getChild(VALUE_NID);
+ if (valueNode.isPresent()) {
+ nextHeadersBuilder.setValue((Short) valueNode.get().getValue());
+ }
+ nextHeaders.add(nextHeadersBuilder.build());
+ }
+
+ return nextHeaders;
+ }
+
+ private List<FlowLabel> createFlowLabels(final UnkeyedListNode flowLabelsData) {
+ final List<FlowLabel> flowLabels = new ArrayList<>();
+
+ for (final UnkeyedListEntryNode node : flowLabelsData.getValue()) {
+ final FlowLabelBuilder flowLabelsBuilder = new FlowLabelBuilder();
+ final Optional<DataContainerChild<? extends PathArgument, ?>> opValue = node.getChild(OP_NID);
+ if (opValue.isPresent()) {
+ flowLabelsBuilder.setOp(createNumericOperand((Set<String>) opValue.get().getValue()));
+ }
+ final Optional<DataContainerChild<? extends PathArgument, ?>> valueNode = node.getChild(VALUE_NID);
+ if (valueNode.isPresent()) {
+ flowLabelsBuilder.setValue((Long) valueNode.get().getValue());
+ }
+ flowLabels.add(flowLabelsBuilder.build());
+ }
+
+ return flowLabels;
+ }
+
+ @Override
+ protected void stringSpecificFSNlriType(final FlowspecType value, final StringBuilder buffer) {
+ if (value instanceof DestinationIpv6PrefixCase) {
+ buffer.append("to ");
+ buffer.append(((DestinationIpv6PrefixCase) value).getDestinationPrefix().getValue());
+ } else if (value instanceof SourceIpv6PrefixCase) {
+ buffer.append("from ");
+ buffer.append(((SourceIpv6PrefixCase) value).getSourcePrefix().getValue());
+ } else if (value instanceof NextHeaderCase) {
+ buffer.append("where next header ");
+ buffer.append(stringNumericOne(((NextHeaderCase) value).getNextHeaders()));
+ } else if (value instanceof FlowLabelCase) {
+ buffer.append("where flow label ");
+ buffer.append(stringFlowLabel(((FlowLabelCase) value).getFlowLabel()));
+ }
+ }
+
+ private static String stringFlowLabel(final List<FlowLabel> list) {
+ final StringBuilder buffer = new StringBuilder();
+ boolean isFirst = true;
+ for (final FlowLabel item : list) {
+ buffer.append(stringNumericOperand(item.getOp(), isFirst));
+ buffer.append(item.getValue());
+ buffer.append(' ');
+ if (isFirst) {
+ isFirst = false;
+ }
+ }
+ return buffer.toString();
+ }
+
+}
--- /dev/null
+/*
+ * 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.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.bgp.rib.rib.loc.rib.tables.routes.FlowspecRoutesCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.routes.FlowspecRoutes;
+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.destination.flowspec._case.DestinationFlowspec;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.tables.Routes;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.AddressFamily;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv4AddressFamily;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
+import org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode;
+import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
+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 final NodeIdentifier destinationNid = new NodeIdentifier(DestinationFlowspec.QNAME);
+ private final NodeIdentifier routeNid = new NodeIdentifier(FlowspecRoute.QNAME);
+ private final ChoiceNode emptyRoutes = Builders.choiceBuilder()
+ .withNodeIdentifier(new NodeIdentifier(Routes.QNAME))
+ .addChild(Builders.containerBuilder()
+ .withNodeIdentifier(new NodeIdentifier(FlowspecRoutes.QNAME))
+ .addChild(ImmutableNodes.mapNodeBuilder(FlowspecRoute.QNAME).build()).build()).build();
+
+ private FlowspecIpv4RIBSupport() {
+ super(FlowspecRoutesCase.class, FlowspecRoutes.class, FlowspecRoute.class);
+ }
+
+ static FlowspecIpv4RIBSupport getInstance() {
+ return SINGLETON;
+ }
+
+ @Override
+ public ChoiceNode emptyRoutes() {
+ return this.emptyRoutes;
+ }
+
+ @Override
+ protected NodeIdentifier destinationContainerIdentifier() {
+ return this.destinationNid;
+ }
+
+ @Override
+ protected NodeIdentifier routeIdentifier() {
+ return this.routeNid;
+ }
+
+ @Override
+ protected AbstractFSNlriParser getParser() {
+ return FS_PARSER;
+ }
+
+ @Override
+ protected Class<? extends AddressFamily> getAfiClass() {
+ return Ipv4AddressFamily.class;
+ }
+
+}
--- /dev/null
+/*
+ * 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.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.bgp.rib.rib.loc.rib.tables.routes.FlowspecIpv6RoutesCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.ipv6.routes.FlowspecIpv6Routes;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.ipv6.routes.flowspec.ipv6.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.destination.flowspec.ipv6._case.DestinationFlowspec;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.tables.Routes;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.AddressFamily;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv6AddressFamily;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
+import org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode;
+import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
+import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
+
+public class FlowspecIpv6RIBSupport extends AbstractFlowspecRIBSupport {
+
+ private static final FSIpv6NlriParser FS_PARSER = new FSIpv6NlriParser();
+
+ private static final FlowspecIpv6RIBSupport SINGLETON = new FlowspecIpv6RIBSupport();
+
+ private final NodeIdentifier destinationNid = new NodeIdentifier(DestinationFlowspec.QNAME);
+ private final NodeIdentifier routeNid = new NodeIdentifier(FlowspecRoute.QNAME);
+ private final ChoiceNode emptyRoutes = Builders.choiceBuilder()
+ .withNodeIdentifier(new NodeIdentifier(Routes.QNAME))
+ .addChild(Builders.containerBuilder()
+ .withNodeIdentifier(new NodeIdentifier(FlowspecIpv6Routes.QNAME))
+ .addChild(ImmutableNodes.mapNodeBuilder(FlowspecRoute.QNAME).build()).build()).build();
+
+ private FlowspecIpv6RIBSupport() {
+ super(FlowspecIpv6RoutesCase.class, FlowspecIpv6Routes.class, FlowspecRoute.class);
+ }
+
+ static FlowspecIpv6RIBSupport getInstance() {
+ return SINGLETON;
+ }
+
+ @Override
+ public ChoiceNode emptyRoutes() {
+ return this.emptyRoutes;
+ }
+
+ @Override
+ protected NodeIdentifier destinationContainerIdentifier() {
+ return this.destinationNid;
+ }
+
+ @Override
+ protected NodeIdentifier routeIdentifier() {
+ return this.routeNid;
+ }
+
+ @Override
+ protected AbstractFSNlriParser getParser() {
+ return FS_PARSER;
+ }
+
+ @Override
+ protected Class<? extends AddressFamily> getAfiClass() {
+ return Ipv6AddressFamily.class;
+ }
+
+}
*/
package org.opendaylight.protocol.bgp.flowspec;
-import com.google.common.collect.Lists;
+import java.util.ArrayList;
import java.util.List;
import org.opendaylight.protocol.bgp.rib.spi.AbstractRIBExtensionProviderActivator;
import org.opendaylight.protocol.bgp.rib.spi.RIBExtensionProviderContext;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.FlowspecSubsequentAddressFamily;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.FlowspecSubsequentAddressFamily;
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 {
@Override
protected List<AutoCloseable> startRIBExtensionProviderImpl(final RIBExtensionProviderContext context) {
- return Lists.newArrayList((AutoCloseable)context.registerRIBSupport(Ipv4AddressFamily.class, FlowspecSubsequentAddressFamily.class, FlowspecRIBSupport.getInstance()));
+ final List<AutoCloseable> regs = new ArrayList<>();
+ regs.add(context.registerRIBSupport(Ipv4AddressFamily.class, FlowspecSubsequentAddressFamily.class, FlowspecIpv4RIBSupport.getInstance()));
+ regs.add(context.registerRIBSupport(Ipv6AddressFamily.class, FlowspecSubsequentAddressFamily.class, FlowspecIpv6RIBSupport.getInstance()));
+ return regs;
}
}
accompanies this distribution, and is available at
http://www.eclipse.org/legal/epl-v10.html";
+ revision "2015-08-07" {
+ description
+ "IPv6 support";
+ reference "https://tools.ietf.org/html/draft-ietf-idr-flow-spec-v6-06";
+ }
+
revision "2015-01-14" {
description
"Initial revision.";
base bgp-t:subsequent-address-family;
}
- typedef component-type {
- reference "http://tools.ietf.org/html/rfc5575#section-4";
- type enumeration {
- enum destination-prefix {
- value 1;
- }
- enum source-prefix {
- value 2;
- }
- enum protocol-ip {
- value 3;
- }
- enum port {
- value 4;
- }
- enum destination-port {
- value 5;
- }
- enum source-port {
- value 6;
- }
- enum icmp-type {
- value 7;
- }
- enum icmp-code {
- value 8;
- }
- enum tcp-flags {
- value 9;
- }
- enum packet-length {
- value 10;
- }
- enum dscp {
- value 11;
- }
- enum fragment {
- value 12;
- }
- }
- }
-
typedef fragment {
reference "http://tools.ietf.org/html/rfc5575#section-4";
type bits {
grouping flowspec-destination {
reference "http://tools.ietf.org/html/rfc5575#section-4";
list flowspec {
- leaf component-type {
- type component-type;
- }
choice flowspec-type {
- case destination-prefix-case {
- when "../component-type = destination-prefix";
- leaf destination-prefix {
- type inet:ipv4-prefix;
- }
- }
- case source-prefix-case {
- when "../component-type = source-prefix";
- leaf source-prefix {
- type inet:ipv4-prefix;
- }
- }
- case protocol-ip-case {
- when "../component-type = protocol-ip";
- list protocol-ips {
- uses numeric-two-byte-value;
- }
- }
case port-case {
- when "../component-type = port";
list ports {
uses numeric-two-byte-value;
}
}
case destination-port-case {
- when "../component-type = destination-port";
list destination-ports {
uses numeric-two-byte-value;
}
}
case source-port-case {
- when "../component-type = source-port";
list source-ports {
uses numeric-two-byte-value;
}
}
case icmp-type-case {
- when "../component-type = icmp-type";
list types {
uses numeric-one-byte-value;
}
}
case icmp-code-case {
- when "../component-type = icmp-code";
list codes {
uses numeric-one-byte-value;
}
}
case tcp-flags-case {
- when "../component-type = tcp-flags";
list tcp-flags {
uses bitmask-two-byte-value;
}
}
case packet-length-case {
- when "../component-type = packet-length";
list packet-lengths {
uses numeric-two-byte-value;
}
}
case dscp-case {
- when "../component-type = dscp";
list dscps {
uses dscp-value;
}
}
case fragment-case {
- when "../component-type = fragment";
list fragments {
uses fragment-value;
}
}
}
+ grouping flowspec-destination-ipv4 {
+ reference "http://tools.ietf.org/html/rfc5575#section-4";
+ uses flowspec-destination {
+ augment "flowspec/flowspec-type" {
+ case destination-prefix-case {
+ leaf destination-prefix {
+ type inet:ipv4-prefix;
+ }
+ }
+ case source-prefix-case {
+ leaf source-prefix {
+ type inet:ipv4-prefix;
+ }
+ }
+ case protocol-ip-case {
+ list protocol-ips {
+ uses numeric-one-byte-value;
+ }
+ }
+ }
+ }
+ }
+
+ grouping flow-label-value {
+ reference "https://tools.ietf.org/html/draft-ietf-idr-flow-spec-v6-06#section-3";
+ leaf op {
+ type numeric-operand;
+ }
+ leaf value {
+ type uint32;
+ }
+ }
+
+ grouping flowspec-destination-ipv6 {
+ reference "https://tools.ietf.org/html/draft-ietf-idr-flow-spec-v6-06#section-3.1";
+ uses flowspec-destination {
+ augment "flowspec/flowspec-type" {
+ case destination-ipv6-prefix-case {
+ leaf destination-prefix {
+ type inet:ipv6-prefix;
+ }
+ }
+ case source-ipv6-prefix-case {
+ leaf source-prefix {
+ type inet:ipv6-prefix;
+ }
+ }
+ case next-header-case {
+ list next-headers {
+ uses numeric-one-byte-value;
+ }
+ }
+ case flow-label-case {
+ list flow-label {
+ uses flow-label-value;
+ }
+ }
+ }
+ }
+ }
+
augment "/bgp-msg:update/bgp-msg:attributes/bgp-mp:mp-reach-nlri/bgp-mp:advertized-routes/bgp-mp:destination-type" {
case destination-flowspec-case {
container destination-flowspec {
- uses flowspec-destination;
+ uses flowspec-destination-ipv4;
+ }
+ }
+ case destination-flowspec-ipv6-case {
+ container destination-flowspec {
+ uses flowspec-destination-ipv6;
}
}
}
augment "/bgp-msg:update/bgp-msg:attributes/bgp-mp:mp-unreach-nlri/bgp-mp:withdrawn-routes/bgp-mp:destination-type" {
case destination-flowspec-case {
container destination-flowspec {
- uses flowspec-destination;
+ uses flowspec-destination-ipv4;
+ }
+ }
+ case destination-flowspec-ipv6-case {
+ container destination-flowspec {
+ uses flowspec-destination-ipv6;
}
}
}
}
key "route-key";
- uses flowspec-destination;
+ uses flowspec-destination-ipv4;
+
+ uses bgp-rib:route;
+ }
+ }
+ }
+
+ grouping flowspec-ipv6-routes {
+ container flowspec-ipv6-routes {
+ list flowspec-route {
+ leaf route-key {
+ description
+ "The sole function of this leaf
+ to act as the key in the list.
+ Its format does not form the
+ API contract of this model.";
+ type string;
+ }
+ key "route-key";
+
+ uses flowspec-destination-ipv6;
uses bgp-rib:route;
}
case flowspec-routes-case {
uses flowspec-routes;
}
+ case flowspec-ipv6-routes-case {
+ uses flowspec-ipv6-routes;
+ }
}
augment "/bgp-rib:bgp-rib/bgp-rib:rib/bgp-rib:loc-rib/bgp-rib:tables/bgp-rib:routes" {
case flowspec-routes-case {
uses flowspec-routes;
}
+ case flowspec-ipv6-routes-case {
+ uses flowspec-ipv6-routes;
+ }
}
augment "/bgp-rib:bgp-rib/bgp-rib:rib/bgp-rib:peer/bgp-rib:adj-rib-in/bgp-rib:tables/bgp-rib:routes" {
case flowspec-routes-case {
uses flowspec-routes;
}
+ case flowspec-ipv6-routes-case {
+ uses flowspec-ipv6-routes;
+ }
}
augment "/bgp-rib:bgp-rib/bgp-rib:rib/bgp-rib:peer/bgp-rib:effective-rib-in/bgp-rib:tables/bgp-rib:routes" {
case flowspec-routes-case {
uses flowspec-routes;
}
+ case flowspec-ipv6-routes-case {
+ uses flowspec-ipv6-routes;
+ }
}
augment "/bgp-rib:bgp-rib/bgp-rib:rib/bgp-rib:peer/bgp-rib:adj-rib-out/bgp-rib:tables/bgp-rib:routes" {
case flowspec-routes-case {
uses flowspec-routes;
}
+ case flowspec-ipv6-routes-case {
+ uses flowspec-ipv6-routes;
+ }
}
augment "/bmp-mon:bmp-monitor/bmp-mon:monitor/bmp-mon:router/bmp-mon:peer/bmp-mon:pre-policy-rib/bmp-mon:tables/bmp-mon:routes" {
case flowspec-routes-case {
uses flowspec-routes;
}
+ case flowspec-ipv6-routes-case {
+ uses flowspec-ipv6-routes;
+ }
}
augment "/bmp-mon:bmp-monitor/bmp-mon:monitor/bmp-mon:router/bmp-mon:peer/bmp-mon:post-policy-rib/bmp-mon:tables/bmp-mon:routes" {
case flowspec-routes-case {
uses flowspec-routes;
}
+ case flowspec-ipv6-routes-case {
+ uses flowspec-ipv6-routes;
+ }
}
}
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
-
import org.junit.Test;
import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionProviderContext;
import org.opendaylight.protocol.bgp.parser.spi.pojo.SimpleBGPExtensionProviderContext;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.FlowspecSubsequentAddressFamily;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.FlowspecSubsequentAddressFamily;
public class ActivatorTest {
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
-
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import org.junit.Test;
import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.protocol.util.NoopReferenceCache;
import org.opendaylight.protocol.util.ReferenceCache;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.Dscp;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.update.attributes.extended.communities.extended.community.RedirectExtendedCommunityCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.update.attributes.extended.communities.extended.community.RedirectExtendedCommunityCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.update.attributes.extended.communities.extended.community.TrafficActionExtendedCommunityCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.update.attributes.extended.communities.extended.community.TrafficActionExtendedCommunityCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.update.attributes.extended.communities.extended.community.TrafficMarkingExtendedCommunityCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.update.attributes.extended.communities.extended.community.TrafficMarkingExtendedCommunityCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.update.attributes.extended.communities.extended.community.TrafficRateExtendedCommunityCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.update.attributes.extended.communities.extended.community.TrafficRateExtendedCommunityCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.update.attributes.extended.communities.extended.community.redirect.extended.community._case.RedirectExtendedCommunityBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.update.attributes.extended.communities.extended.community.traffic.action.extended.community._case.TrafficActionExtendedCommunityBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.update.attributes.extended.communities.extended.community.traffic.marking.extended.community._case.TrafficMarkingExtendedCommunityBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.update.attributes.extended.communities.extended.community.traffic.rate.extended.community._case.TrafficRateExtendedCommunityBuilder;
+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.update.attributes.extended.communities.extended.community.RedirectExtendedCommunityCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.update.attributes.extended.communities.extended.community.RedirectExtendedCommunityCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.update.attributes.extended.communities.extended.community.TrafficActionExtendedCommunityCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.update.attributes.extended.communities.extended.community.TrafficActionExtendedCommunityCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.update.attributes.extended.communities.extended.community.TrafficMarkingExtendedCommunityCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.update.attributes.extended.communities.extended.community.TrafficMarkingExtendedCommunityCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.update.attributes.extended.communities.extended.community.TrafficRateExtendedCommunityCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.update.attributes.extended.communities.extended.community.TrafficRateExtendedCommunityCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.update.attributes.extended.communities.extended.community.redirect.extended.community._case.RedirectExtendedCommunityBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.update.attributes.extended.communities.extended.community.traffic.action.extended.community._case.TrafficActionExtendedCommunityBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.update.attributes.extended.communities.extended.community.traffic.marking.extended.community._case.TrafficMarkingExtendedCommunityBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.update.attributes.extended.communities.extended.community.traffic.rate.extended.community._case.TrafficRateExtendedCommunityBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.AttributesBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.attributes.ExtendedCommunities;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.ShortAsNumber;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
-
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import io.netty.buffer.ByteBuf;
import org.opendaylight.protocol.bgp.parser.BGPParsingException;
import org.opendaylight.protocol.util.ByteArray;
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.rev150114.BitmaskOperand;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.ComponentType;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.Dscp;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.Fragment;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.NumericOperand;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.flowspec.destination.Flowspec;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.flowspec.destination.FlowspecBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.flowspec.destination.flowspec.FlowspecType;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.flowspec.destination.flowspec.flowspec.type.DestinationPortCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.flowspec.destination.flowspec.flowspec.type.DestinationPortCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.flowspec.destination.flowspec.flowspec.type.DestinationPrefixCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.flowspec.destination.flowspec.flowspec.type.DestinationPrefixCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.flowspec.destination.flowspec.flowspec.type.DscpCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.flowspec.destination.flowspec.flowspec.type.DscpCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.flowspec.destination.flowspec.flowspec.type.FragmentCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.flowspec.destination.flowspec.flowspec.type.FragmentCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.flowspec.destination.flowspec.flowspec.type.IcmpCodeCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.flowspec.destination.flowspec.flowspec.type.IcmpCodeCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.flowspec.destination.flowspec.flowspec.type.IcmpTypeCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.flowspec.destination.flowspec.flowspec.type.IcmpTypeCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.flowspec.destination.flowspec.flowspec.type.PacketLengthCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.flowspec.destination.flowspec.flowspec.type.PacketLengthCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.flowspec.destination.flowspec.flowspec.type.PortCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.flowspec.destination.flowspec.flowspec.type.PortCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.flowspec.destination.flowspec.flowspec.type.ProtocolIpCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.flowspec.destination.flowspec.flowspec.type.ProtocolIpCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.flowspec.destination.flowspec.flowspec.type.SourcePortCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.flowspec.destination.flowspec.flowspec.type.SourcePortCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.flowspec.destination.flowspec.flowspec.type.SourcePrefixCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.flowspec.destination.flowspec.flowspec.type.SourcePrefixCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.flowspec.destination.flowspec.flowspec.type.TcpFlagsCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.flowspec.destination.flowspec.flowspec.type.TcpFlagsCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.flowspec.destination.flowspec.flowspec.type.destination.port._case.DestinationPorts;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.flowspec.destination.flowspec.flowspec.type.destination.port._case.DestinationPortsBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.flowspec.destination.flowspec.flowspec.type.dscp._case.Dscps;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.flowspec.destination.flowspec.flowspec.type.dscp._case.DscpsBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.flowspec.destination.flowspec.flowspec.type.fragment._case.Fragments;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.flowspec.destination.flowspec.flowspec.type.fragment._case.FragmentsBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.flowspec.destination.flowspec.flowspec.type.icmp.code._case.Codes;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.flowspec.destination.flowspec.flowspec.type.icmp.code._case.CodesBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.flowspec.destination.flowspec.flowspec.type.icmp.type._case.Types;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.flowspec.destination.flowspec.flowspec.type.icmp.type._case.TypesBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.flowspec.destination.flowspec.flowspec.type.packet.length._case.PacketLengths;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.flowspec.destination.flowspec.flowspec.type.packet.length._case.PacketLengthsBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.flowspec.destination.flowspec.flowspec.type.port._case.Ports;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.flowspec.destination.flowspec.flowspec.type.port._case.PortsBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.flowspec.destination.flowspec.flowspec.type.protocol.ip._case.ProtocolIps;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.flowspec.destination.flowspec.flowspec.type.protocol.ip._case.ProtocolIpsBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.flowspec.destination.flowspec.flowspec.type.source.port._case.SourcePorts;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.flowspec.destination.flowspec.flowspec.type.source.port._case.SourcePortsBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.flowspec.destination.flowspec.flowspec.type.tcp.flags._case.TcpFlags;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.flowspec.destination.flowspec.flowspec.type.tcp.flags._case.TcpFlagsBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationFlowspecCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationFlowspecCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.update.attributes.mp.reach.nlri.advertized.routes.destination.type.destination.flowspec._case.DestinationFlowspecBuilder;
+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;
+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.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.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.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.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.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.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.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.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.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;
+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;
+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;
+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;
+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;
+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;
+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;
+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;
+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;
+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;
+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.SourcePrefixCase;
+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.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;
+import 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._case.DestinationFlowspecBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.AttributesBuilder;
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.Attributes1Builder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.MpUnreachNlriBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.mp.reach.nlri.AdvertizedRoutesBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.mp.unreach.nlri.WithdrawnRoutesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv4AddressFamily;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
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 FSNlriParserTest {
+public class FSIpv4NlriParserTest {
- private static final byte[] nlri = new byte[] { 0x1D, 01, 0x18, 0x0a, 00, 01, 02, 0x08, (byte) 0xc0,
- 03, (byte) 0x81, 06, 04, 03, (byte) 0x89, 0x45, (byte) 0x8b, (byte) 0x91, 0x1f, (byte) 0x90,
+ private static final byte[] REACHED_NLRI = new byte[] { 0x21,
+ 01, 0x20, 0x0a, 00, 01, 00,
+ 02, 0x20, 01, 02, 03, 04,
+ 03, (byte) 0x81, 06,
+ 04, 03, (byte) 0x89, 0x45, (byte) 0x8b, (byte) 0x91, 0x1f, (byte) 0x90,
05, 0x12, 0x0f, (byte) 0xf9, (byte) 0x81, (byte) 0xb3,
06, (byte) 0x91, 0x1f, (byte) 0x90 };
- private static final byte[] unnlri = new byte[] { 0x1B, 07, 4, 2, (byte) 0x84, 3,
+ private static final byte[] UNREACHED_NLRI = new byte[] { 0x1B,
+ 07, 4, 2, (byte) 0x84, 3,
0x08, 06, 04, (byte) 0x80, 05,
0x09, 0x12, 04, 01, (byte) 0x91, 0x56, (byte) 0xb1,
0x0a, (byte) 0x96, (byte) 0xde, (byte) 0xad,
0x0b, (byte) 0x86, 0x2a,
- 0x0c, (byte) 0x81, (byte) 0x0f };
+ 0x0c, (byte) 0x81, (byte) 0x0e};
+
+ private static final FSIpv4NlriParser FS_PARSER = new FSIpv4NlriParser();
@Test
public void testParseLength() {
// 00-00-0000 = 1
- assertEquals(1, FSNlriParser.parseLength((byte) 0x00));
+ assertEquals(1, FSIpv4NlriParser.parseLength((byte) 0x00));
// 00-01-0000 = 2
- assertEquals(2, FSNlriParser.parseLength((byte) 16));
+ assertEquals(2, FSIpv4NlriParser.parseLength((byte) 16));
// 00-10-0000 = 4
- assertEquals(4, FSNlriParser.parseLength((byte) 32));
+ assertEquals(4, FSIpv4NlriParser.parseLength((byte) 32));
// 00-11-0000 = 8
- assertEquals(8, FSNlriParser.parseLength((byte) 48));
+ assertEquals(8, FSIpv4NlriParser.parseLength((byte) 48));
}
@Test
final MpReachNlriBuilder mp = new MpReachNlriBuilder();
final FlowspecBuilder builder = new FlowspecBuilder();
- builder.setComponentType(ComponentType.DestinationPrefix);
- final DestinationPrefixCase destinationPrefix = new DestinationPrefixCaseBuilder().setDestinationPrefix(new Ipv4Prefix("10.0.1.0/24")).build();
+ final DestinationPrefixCase destinationPrefix = new DestinationPrefixCaseBuilder().setDestinationPrefix(new Ipv4Prefix("10.0.1.0/32")).build();
builder.setFlowspecType(destinationPrefix);
fs.add(builder.build());
- builder.setComponentType(ComponentType.SourcePrefix);
- final SourcePrefixCase sourcePrefix = new SourcePrefixCaseBuilder().setSourcePrefix(new Ipv4Prefix("192.0.0.0/8")).build();
+ final SourcePrefixCase sourcePrefix = new SourcePrefixCaseBuilder().setSourcePrefix(new Ipv4Prefix("1.2.3.4/32")).build();
builder.setFlowspecType(sourcePrefix);
fs.add(builder.build());
- builder.setComponentType(ComponentType.ProtocolIp);
- final List<ProtocolIps> protocols = Lists.newArrayList(new ProtocolIpsBuilder().setOp(new NumericOperand(false, true, true, false, false)).setValue(6).build());
+ final List<ProtocolIps> protocols = Lists.newArrayList(new ProtocolIpsBuilder().setOp(new NumericOperand(false, true, true, false, false)).setValue((short)6).build());
final ProtocolIpCase prots = new ProtocolIpCaseBuilder().setProtocolIps(protocols).build();
builder.setFlowspecType(prots);
fs.add(builder.build());
- builder.setComponentType(ComponentType.Port);
final List<Ports> ports = Lists.newArrayList(new PortsBuilder().setOp(new NumericOperand(false, false, true, true, false)).setValue(137).build(),
new PortsBuilder().setOp(new NumericOperand(true, false, true, false, true)).setValue(139).build(),
new PortsBuilder().setOp(new NumericOperand(false, true, true, false, false)).setValue(8080).build());
builder.setFlowspecType(ps);
fs.add(builder.build());
- builder.setComponentType(ComponentType.DestinationPort);
final List<DestinationPorts> destports = Lists.newArrayList(new DestinationPortsBuilder().setOp(new NumericOperand(false, false, false, true, false)).setValue(4089).build(),
new DestinationPortsBuilder().setOp(new NumericOperand(false, true, true, false, false)).setValue(179).build());
final DestinationPortCase dps = new DestinationPortCaseBuilder().setDestinationPorts(destports).build();
builder.setFlowspecType(dps);
fs.add(builder.build());
- builder.setComponentType(ComponentType.SourcePort);
final List<SourcePorts> sports = Lists.newArrayList(new SourcePortsBuilder().setOp(new NumericOperand(false, true, true, false, false)).setValue(8080).build());
final SourcePortCase sps = new SourcePortCaseBuilder().setSourcePorts(sports).build();
builder.setFlowspecType(sps);
mp.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(new DestinationFlowspecCaseBuilder().setDestinationFlowspec(new DestinationFlowspecBuilder().setFlowspec(fs).build()).build()).build());
- final FSNlriParser parser = new FSNlriParser();
+ final FSIpv4NlriParser parser = new FSIpv4NlriParser();
final MpReachNlriBuilder result = new MpReachNlriBuilder();
- parser.parseNlri(Unpooled.wrappedBuffer(nlri), result);
+ result.setAfi(Ipv4AddressFamily.class);
+ parser.parseNlri(Unpooled.wrappedBuffer(REACHED_NLRI), result);
final List<Flowspec> flows = ((DestinationFlowspecCase) (result.getAdvertizedRoutes().getDestinationType())).getDestinationFlowspec().getFlowspec();
assertEquals(6, flows.size());
assertEquals(sps, flows.get(5).getFlowspecType());
final ByteBuf buffer = Unpooled.buffer();
- parser.serializeAttribute(new AttributesBuilder().addAugmentation(Attributes1.class, new Attributes1Builder().setMpReachNlri(mp.build()).build()).build(), buffer);
- assertArrayEquals(nlri, ByteArray.readAllBytes(buffer));
-
- assertEquals("all packets to 10.0.1.0/24", FSNlriParser.stringNlri(flows.get(0)));
- assertEquals("all packets from 192.0.0.0/8", FSNlriParser.stringNlri(flows.get(1)));
- assertEquals("all packets where protocol equals to 6 ", FSNlriParser.stringNlri(flows.get(2)));
- assertEquals("all packets where port is greater than or equal to 137 and is less than or equal to 139 or equals to 8080 ", FSNlriParser.stringNlri(flows.get(3)));
- assertEquals("all packets where destination port is greater than 4089 or equals to 179 ", FSNlriParser.stringNlri(flows.get(4)));
- assertEquals("all packets where source port equals to 8080 ", FSNlriParser.stringNlri(flows.get(5)));
+ parser.serializeAttribute(new AttributesBuilder().addAugmentation(Attributes1.class, new Attributes1Builder().setMpReachNlri(mp.setAfi(Ipv4AddressFamily.class).build()).build()).build(), buffer);
+ assertArrayEquals(REACHED_NLRI, ByteArray.readAllBytes(buffer));
+
+ assertEquals("all packets to 10.0.1.0/32", FS_PARSER.stringNlri(flows.get(0)));
+ assertEquals("all packets from 1.2.3.4/32", FS_PARSER.stringNlri(flows.get(1)));
+ assertEquals("all packets where IP protocol equals to 6 ", FS_PARSER.stringNlri(flows.get(2)));
+ assertEquals("all packets where port is greater than or equal to 137 and is less than or equal to 139 or equals to 8080 ", FS_PARSER.stringNlri(flows.get(3)));
+ assertEquals("all packets where destination port is greater than 4089 or equals to 179 ", FS_PARSER.stringNlri(flows.get(4)));
+ assertEquals("all packets where source port equals to 8080 ", FS_PARSER.stringNlri(flows.get(5)));
}
@Test
final FlowspecBuilder builder = new FlowspecBuilder();
- builder.setComponentType(ComponentType.IcmpType);
final List<Types> types = Lists.newArrayList(new TypesBuilder().setOp(new NumericOperand(false, false, false, false, true)).setValue((short) 2).build(),
new TypesBuilder().setOp(new NumericOperand(false, true, false, false, true)).setValue((short) 3).build());
final IcmpTypeCase icmpType = new IcmpTypeCaseBuilder().setTypes(types).build();
builder.setFlowspecType(icmpType);
fs.add(builder.build());
- builder.setComponentType(ComponentType.IcmpCode);
final List<Codes> codes = Lists.newArrayList(new CodesBuilder().setOp(new NumericOperand(false, false, false, true, true)).setValue((short) 4).build(),
new CodesBuilder().setOp(new NumericOperand(false, true, false, false, false)).setValue((short) 5).build());
final IcmpCodeCase icmpCode = new IcmpCodeCaseBuilder().setCodes(codes).build();
builder.setFlowspecType(icmpCode);
fs.add(builder.build());
- builder.setComponentType(ComponentType.TcpFlags);
final List<TcpFlags> flags = Lists.newArrayList(new TcpFlagsBuilder().setOp(new BitmaskOperand(false, false, false, true)).setValue(1025).build(),
new TcpFlagsBuilder().setOp(new BitmaskOperand(false, true, true, false)).setValue(22193).build());
final TcpFlagsCase tcp = new TcpFlagsCaseBuilder().setTcpFlags(flags).build();
builder.setFlowspecType(tcp);
fs.add(builder.build());
- builder.setComponentType(ComponentType.PacketLength);
final List<PacketLengths> packets = Lists.newArrayList(new PacketLengthsBuilder().setOp(new NumericOperand(false, true, false, true, true)).setValue(57005).build());
final PacketLengthCase packet = new PacketLengthCaseBuilder().setPacketLengths(packets).build();
builder.setFlowspecType(packet);
fs.add(builder.build());
- builder.setComponentType(ComponentType.Dscp);
final List<Dscps> dscps = Lists.newArrayList(new DscpsBuilder().setOp(new NumericOperand(false, true, false, true, true)).setValue(new Dscp((short) 42)).build());
final DscpCase dscp = new DscpCaseBuilder().setDscps(dscps).build();
builder.setFlowspecType(dscp);
fs.add(builder.build());
- builder.setComponentType(ComponentType.Fragment);
- final List<Fragments> fragments = Lists.newArrayList(new FragmentsBuilder().setOp(new BitmaskOperand(false, true, true, false)).setValue(new Fragment(true, true, true, true)).build());
+ final List<Fragments> fragments = Lists.newArrayList(new FragmentsBuilder().setOp(new BitmaskOperand(false, true, true, false)).setValue(new Fragment(false, true, true, true)).build());
final FragmentCase fragment = new FragmentCaseBuilder().setFragments(fragments).build();
builder.setFlowspecType(fragment);
fs.add(builder.build());
- mp.setWithdrawnRoutes(new WithdrawnRoutesBuilder().setDestinationType(
- new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.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.rev150114.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.destination.flowspec._case.DestinationFlowspecBuilder().setFlowspec(fs).build()).build()).build());
+ final List<FlowLabel> 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 FSNlriParser parser = new FSNlriParser();
+ final FSIpv4NlriParser parser = new FSIpv4NlriParser();
final MpUnreachNlriBuilder result = new MpUnreachNlriBuilder();
- parser.parseNlri(Unpooled.wrappedBuffer(unnlri), result);
+ result.setAfi(Ipv4AddressFamily.class);
+ parser.parseNlri(Unpooled.wrappedBuffer(UNREACHED_NLRI), result);
- final List<Flowspec> flows = ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150114.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationFlowspecCase) (result.getWithdrawnRoutes().getDestinationType())).getDestinationFlowspec().getFlowspec();
+ final List<Flowspec> flows = ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationFlowspecCase) (result.getWithdrawnRoutes().getDestinationType())).getDestinationFlowspec().getFlowspec();
assertEquals(6, flows.size());
assertEquals(icmpType, flows.get(0).getFlowspecType());
assertEquals(icmpCode, flows.get(1).getFlowspecType());
final ByteBuf buffer = Unpooled.buffer();
parser.serializeAttribute(new AttributesBuilder().addAugmentation(Attributes2.class, new Attributes2Builder().setMpUnreachNlri(mp.build()).build()).build(), buffer);
- assertArrayEquals(unnlri, ByteArray.readAllBytes(buffer));
-
- assertEquals("all packets where ICMP type is less than 2 or is less than 3 ", FSNlriParser.stringNlri(flows.get(0)));
- assertEquals("all packets where ICMP code is less than is greater than 4 or 5 ", FSNlriParser.stringNlri(flows.get(1)));
- assertEquals("all packets where TCP flags is not 1025 or does match 22193 ", FSNlriParser.stringNlri(flows.get(2)));
- assertEquals("all packets where packet length is less than is greater than 57005 ", FSNlriParser.stringNlri(flows.get(3)));
- assertEquals("all packets where DSCP is less than is greater than 42 ", FSNlriParser.stringNlri(flows.get(4)));
- assertEquals("all packets where fragment does match 'DO NOT' 'IS FIRST' 'IS LAST' 'IS A' ", FSNlriParser.stringNlri(flows.get(5)));
+ assertArrayEquals(UNREACHED_NLRI, ByteArray.readAllBytes(buffer));
+
+ assertEquals("all packets where ICMP type is less than 2 or is less than 3 ", FS_PARSER.stringNlri(flows.get(0)));
+ assertEquals("all packets where ICMP code is less than is greater than 4 or 5 ", FS_PARSER.stringNlri(flows.get(1)));
+ assertEquals("all packets where TCP flags is not 1025 or does match 22193 ", FS_PARSER.stringNlri(flows.get(2)));
+ assertEquals("all packets where packet length is less than is greater than 57005 ", FS_PARSER.stringNlri(flows.get(3)));
+ assertEquals("all packets where DSCP is less than is greater than 42 ", FS_PARSER.stringNlri(flows.get(4)));
+ assertEquals("all packets where fragment does match 'IS FIRST' 'IS LAST' 'IS A' ", FS_PARSER.stringNlri(flows.get(5)));
}
@Test
public void testExtractFlowspecDestPrefix() {
final DataContainerNodeAttrBuilder<NodeIdentifierWithPredicates, MapEntryNode> entry = Builders.mapEntryBuilder();
entry.withNodeIdentifier(new NodeIdentifierWithPredicates(Flowspec.QNAME, Flowspec.QNAME, entry));
- entry.withChild(Builders.leafBuilder().withNodeIdentifier(FSNlriParser.COMPONENT_TYPE_NID).withValue("destination-prefix").build());
entry.withChild(Builders.choiceBuilder().withNodeIdentifier(new NodeIdentifier(FlowspecType.QNAME))
- .withChild(Builders.leafBuilder().withNodeIdentifier(FSNlriParser.DEST_PREFIX_NID).withValue("127.0.0.5/32").build()).build());
+ .withChild(Builders.leafBuilder().withNodeIdentifier(FSIpv4NlriParser.DEST_PREFIX_NID).withValue("127.0.0.5/32").build()).build());
final FlowspecBuilder expected = new FlowspecBuilder();
- expected.setComponentType(ComponentType.DestinationPrefix);
expected.setFlowspecType(new DestinationPrefixCaseBuilder().setDestinationPrefix(new Ipv4Prefix("127.0.0.5/32")).build());
- assertEquals(expected.build(), FSNlriParser.extractFlowspec(entry.build()));
+ assertEquals(expected.build(), FS_PARSER.extractFlowspec(entry.build()));
}
@Test
public void testExtractFlowspecSourcePrefix() {
final DataContainerNodeAttrBuilder<NodeIdentifierWithPredicates, MapEntryNode> entry = Builders.mapEntryBuilder();
entry.withNodeIdentifier(new NodeIdentifierWithPredicates(Flowspec.QNAME, Flowspec.QNAME, entry));
- entry.withChild(Builders.leafBuilder().withNodeIdentifier(FSNlriParser.COMPONENT_TYPE_NID).withValue("source-prefix").build());
entry.withChild(Builders.choiceBuilder().withNodeIdentifier(new NodeIdentifier(FlowspecType.QNAME))
- .withChild(Builders.leafBuilder().withNodeIdentifier(FSNlriParser.SOURCE_PREFIX_NID).withValue("127.0.0.6/32").build()).build());
+ .withChild(Builders.leafBuilder().withNodeIdentifier(FSIpv4NlriParser.SOURCE_PREFIX_NID).withValue("127.0.0.6/32").build()).build());
final FlowspecBuilder expected = new FlowspecBuilder();
- expected.setComponentType(ComponentType.SourcePrefix);
expected.setFlowspecType(new SourcePrefixCaseBuilder().setSourcePrefix(new Ipv4Prefix("127.0.0.6/32")).build());
- assertEquals(expected.build(), FSNlriParser.extractFlowspec(entry.build()));
+ assertEquals(expected.build(), FS_PARSER.extractFlowspec(entry.build()));
}
@Test
public void testExtractFlowspecProtocolIps() {
final DataContainerNodeAttrBuilder<NodeIdentifierWithPredicates, MapEntryNode> entry = Builders.mapEntryBuilder();
entry.withNodeIdentifier(new NodeIdentifierWithPredicates(Flowspec.QNAME, Flowspec.QNAME, entry));
- entry.withChild(Builders.leafBuilder().withNodeIdentifier(FSNlriParser.COMPONENT_TYPE_NID).withValue("protocol-ips").build());
entry.withChild(Builders.choiceBuilder().withNodeIdentifier(new NodeIdentifier(FlowspecType.QNAME))
- .withChild(Builders.unkeyedListBuilder().withNodeIdentifier(FSNlriParser.PROTOCOL_IP_NID)
- .withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(FSNlriParser.PROTOCOL_IP_NID)
- .withChild(Builders.leafBuilder().withNodeIdentifier(FSNlriParser.OP_NID).withValue(Sets.<String>newHashSet(FSNlriParser.END_OF_LIST_VALUE, FSNlriParser.AND_BIT_VALUE)).build())
- .withChild(Builders.leafBuilder().withNodeIdentifier(FSNlriParser.VALUE_NID).withValue(100).build()).build())
- .withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(FSNlriParser.PROTOCOL_IP_NID)
- .withChild(Builders.leafBuilder().withNodeIdentifier(FSNlriParser.OP_NID).withValue(Sets.<String>newHashSet(FSNlriParser.AND_BIT_VALUE)).build())
- .withChild(Builders.leafBuilder().withNodeIdentifier(FSNlriParser.VALUE_NID).withValue(200).build()).build())
- .withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(FSNlriParser.PROTOCOL_IP_NID)
- .withChild(Builders.leafBuilder().withNodeIdentifier(FSNlriParser.OP_NID).withValue(Sets.<String>newHashSet(FSNlriParser.END_OF_LIST_VALUE, FSNlriParser.AND_BIT_VALUE, FSNlriParser.EQUALS_VALUE)).build())
- .withChild(Builders.leafBuilder().withNodeIdentifier(FSNlriParser.VALUE_NID).withValue(300).build()).build())
+ .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.<String>newHashSet(FSIpv4NlriParser.END_OF_LIST_VALUE, FSIpv4NlriParser.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.<String>newHashSet(FSIpv4NlriParser.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.<String>newHashSet(FSIpv4NlriParser.END_OF_LIST_VALUE, FSIpv4NlriParser.AND_BIT_VALUE, FSIpv4NlriParser.EQUALS_VALUE)).build())
+ .withChild(Builders.leafBuilder().withNodeIdentifier(FSIpv4NlriParser.VALUE_NID).withValue((short) 240).build()).build())
.build()).build());
final FlowspecBuilder expected = new FlowspecBuilder();
expected.setFlowspecType(new ProtocolIpCaseBuilder().setProtocolIps(Lists.<ProtocolIps>newArrayList(
- new ProtocolIpsBuilder().setValue(100).setOp(new NumericOperand(true, true, false, false, false)).build(),
- new ProtocolIpsBuilder().setValue(200).setOp(new NumericOperand(true, false, false, false, false)).build(),
- new ProtocolIpsBuilder().setValue(300).setOp(new NumericOperand(true, true, true, false, false)).build())).build());
- assertEquals(expected.build(), FSNlriParser.extractFlowspec(entry.build()));
+ new ProtocolIpsBuilder().setValue((short) 100).setOp(new NumericOperand(true, true, false, false, false)).build(),
+ new ProtocolIpsBuilder().setValue((short) 200).setOp(new NumericOperand(true, false, false, false, false)).build(),
+ new ProtocolIpsBuilder().setValue((short) 240).setOp(new NumericOperand(true, true, true, false, false)).build())).build());
+ assertEquals(expected.build(), FS_PARSER.extractFlowspec(entry.build()));
}
@Test
public void testExtractFlowspecPorts() {
final DataContainerNodeAttrBuilder<NodeIdentifierWithPredicates, MapEntryNode> entry = Builders.mapEntryBuilder();
entry.withNodeIdentifier(new NodeIdentifierWithPredicates(Flowspec.QNAME, Flowspec.QNAME, entry));
- entry.withChild(Builders.leafBuilder().withNodeIdentifier(FSNlriParser.COMPONENT_TYPE_NID).withValue("ports").build());
entry.withChild(Builders.choiceBuilder().withNodeIdentifier(new NodeIdentifier(FlowspecType.QNAME))
- .withChild(Builders.unkeyedListBuilder().withNodeIdentifier(FSNlriParser.PORTS_NID)
- .withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(FSNlriParser.PROTOCOL_IP_NID)
- .withChild(Builders.leafBuilder().withNodeIdentifier(FSNlriParser.OP_NID).withValue(Sets.<String>newHashSet(FSNlriParser.END_OF_LIST_VALUE, FSNlriParser.AND_BIT_VALUE, FSNlriParser.LESS_THAN_VALUE)).build())
- .withChild(Builders.leafBuilder().withNodeIdentifier(FSNlriParser.VALUE_NID).withValue(100).build()).build())
+ .withChild(Builders.unkeyedListBuilder().withNodeIdentifier(FSIpv4NlriParser.PORTS_NID)
+ .withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(FSIpv4NlriParser.PROTOCOL_IP_NID)
+ .withChild(Builders.leafBuilder().withNodeIdentifier(FSIpv4NlriParser.OP_NID).withValue(Sets.<String>newHashSet(FSIpv4NlriParser.END_OF_LIST_VALUE, FSIpv4NlriParser.AND_BIT_VALUE, FSIpv4NlriParser.LESS_THAN_VALUE)).build())
+ .withChild(Builders.leafBuilder().withNodeIdentifier(FSIpv4NlriParser.VALUE_NID).withValue(100).build()).build())
.build()).build()).build();
final FlowspecBuilder expected = new FlowspecBuilder();
expected.setFlowspecType(new PortCaseBuilder().setPorts(Lists.<Ports>newArrayList(new PortsBuilder().setValue(100).setOp(new NumericOperand(true, true, false, false, true)).build())).build());
- assertEquals(expected.build(), FSNlriParser.extractFlowspec(entry.build()));
+ assertEquals(expected.build(), FS_PARSER.extractFlowspec(entry.build()));
}
@Test
public void testExtractFlowspecDestinationPorts() {
final DataContainerNodeAttrBuilder<NodeIdentifierWithPredicates, MapEntryNode> entry = Builders.mapEntryBuilder();
entry.withNodeIdentifier(new NodeIdentifierWithPredicates(Flowspec.QNAME, Flowspec.QNAME, entry));
- entry.withChild(Builders.leafBuilder().withNodeIdentifier(FSNlriParser.COMPONENT_TYPE_NID).withValue("destination-ports").build());
entry.withChild(Builders.choiceBuilder().withNodeIdentifier(new NodeIdentifier(FlowspecType.QNAME))
- .withChild(Builders.unkeyedListBuilder().withNodeIdentifier(FSNlriParser.DEST_PORT_NID)
- .withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(FSNlriParser.OP_NID)
- .withChild(Builders.leafBuilder().withNodeIdentifier(FSNlriParser.OP_NID).withValue(Sets.<String>newHashSet(FSNlriParser.END_OF_LIST_VALUE, FSNlriParser.EQUALS_VALUE)).build())
- .withChild(Builders.leafBuilder().withNodeIdentifier(FSNlriParser.VALUE_NID).withValue(1024).build()).build())
+ .withChild(Builders.unkeyedListBuilder().withNodeIdentifier(FSIpv4NlriParser.DEST_PORT_NID)
+ .withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(FSIpv4NlriParser.OP_NID)
+ .withChild(Builders.leafBuilder().withNodeIdentifier(FSIpv4NlriParser.OP_NID).withValue(Sets.<String>newHashSet(FSIpv4NlriParser.END_OF_LIST_VALUE, FSIpv4NlriParser.EQUALS_VALUE)).build())
+ .withChild(Builders.leafBuilder().withNodeIdentifier(FSIpv4NlriParser.VALUE_NID).withValue(1024).build()).build())
.build()).build()).build();
final FlowspecBuilder expected = new FlowspecBuilder();
expected.setFlowspecType(new DestinationPortCaseBuilder().setDestinationPorts(Lists.<DestinationPorts>newArrayList(new DestinationPortsBuilder().setValue(1024).setOp(new NumericOperand(false, true, true, false, false)).build())).build());
- assertEquals(expected.build(), FSNlriParser.extractFlowspec(entry.build()));
+ assertEquals(expected.build(), FS_PARSER.extractFlowspec(entry.build()));
}
@Test
public void testExtractFlowspecSourcePorts() {
final DataContainerNodeAttrBuilder<NodeIdentifierWithPredicates, MapEntryNode> entry = Builders.mapEntryBuilder();
entry.withNodeIdentifier(new NodeIdentifierWithPredicates(Flowspec.QNAME, Flowspec.QNAME, entry));
- entry.withChild(Builders.leafBuilder().withNodeIdentifier(FSNlriParser.COMPONENT_TYPE_NID).withValue("source-ports").build());
entry.withChild(Builders.choiceBuilder().withNodeIdentifier(new NodeIdentifier(FlowspecType.QNAME))
- .withChild(Builders.unkeyedListBuilder().withNodeIdentifier(FSNlriParser.SOURCE_PORT_NID)
- .withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(FSNlriParser.OP_NID)
- .withChild(Builders.leafBuilder().withNodeIdentifier(FSNlriParser.OP_NID).withValue(Sets.<String>newHashSet(FSNlriParser.AND_BIT_VALUE, FSNlriParser.END_OF_LIST_VALUE, FSNlriParser.EQUALS_VALUE, FSNlriParser.GREATER_THAN_VALUE, FSNlriParser.LESS_THAN_VALUE)).build())
- .withChild(Builders.leafBuilder().withNodeIdentifier(FSNlriParser.VALUE_NID).withValue(8080).build()).build())
+ .withChild(Builders.unkeyedListBuilder().withNodeIdentifier(FSIpv4NlriParser.SOURCE_PORT_NID)
+ .withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(FSIpv4NlriParser.OP_NID)
+ .withChild(Builders.leafBuilder().withNodeIdentifier(FSIpv4NlriParser.OP_NID).withValue(Sets.<String>newHashSet(FSIpv4NlriParser.AND_BIT_VALUE, FSIpv4NlriParser.END_OF_LIST_VALUE, FSIpv4NlriParser.EQUALS_VALUE, FSIpv4NlriParser.GREATER_THAN_VALUE, FSIpv4NlriParser.LESS_THAN_VALUE)).build())
+ .withChild(Builders.leafBuilder().withNodeIdentifier(FSIpv4NlriParser.VALUE_NID).withValue(8080).build()).build())
.build()).build()).build();
final FlowspecBuilder expected = new FlowspecBuilder();
expected.setFlowspecType(new SourcePortCaseBuilder().setSourcePorts(Lists.<SourcePorts>newArrayList(new SourcePortsBuilder().setValue(8080).setOp(new NumericOperand(true, true, true, true, true)).build())).build());
- assertEquals(expected.build(), FSNlriParser.extractFlowspec(entry.build()));
+ assertEquals(expected.build(), FS_PARSER.extractFlowspec(entry.build()));
}
@Test
public void testExtractFlowspecSourceTypes() {
final DataContainerNodeAttrBuilder<NodeIdentifierWithPredicates, MapEntryNode> entry = Builders.mapEntryBuilder();
entry.withNodeIdentifier(new NodeIdentifierWithPredicates(Flowspec.QNAME, Flowspec.QNAME, entry));
- entry.withChild(Builders.leafBuilder().withNodeIdentifier(FSNlriParser.COMPONENT_TYPE_NID).withValue("types").build());
entry.withChild(Builders.choiceBuilder().withNodeIdentifier(new NodeIdentifier(FlowspecType.QNAME))
- .withChild(Builders.unkeyedListBuilder().withNodeIdentifier(FSNlriParser.ICMP_TYPE_NID)
- .withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(FSNlriParser.OP_NID)
- .withChild(Builders.leafBuilder().withNodeIdentifier(FSNlriParser.OP_NID).withValue(Sets.<String>newHashSet(FSNlriParser.AND_BIT_VALUE, FSNlriParser.END_OF_LIST_VALUE, FSNlriParser.EQUALS_VALUE, FSNlriParser.GREATER_THAN_VALUE, FSNlriParser.LESS_THAN_VALUE)).build())
- .withChild(Builders.leafBuilder().withNodeIdentifier(FSNlriParser.VALUE_NID).withValue((short) 22).build()).build())
+ .withChild(Builders.unkeyedListBuilder().withNodeIdentifier(FSIpv4NlriParser.ICMP_TYPE_NID)
+ .withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(FSIpv4NlriParser.OP_NID)
+ .withChild(Builders.leafBuilder().withNodeIdentifier(FSIpv4NlriParser.OP_NID).withValue(Sets.<String>newHashSet(FSIpv4NlriParser.AND_BIT_VALUE, FSIpv4NlriParser.END_OF_LIST_VALUE, FSIpv4NlriParser.EQUALS_VALUE, FSIpv4NlriParser.GREATER_THAN_VALUE, FSIpv4NlriParser.LESS_THAN_VALUE)).build())
+ .withChild(Builders.leafBuilder().withNodeIdentifier(FSIpv4NlriParser.VALUE_NID).withValue((short) 22).build()).build())
.build()).build()).build();
final FlowspecBuilder expected = new FlowspecBuilder();
expected.setFlowspecType(new IcmpTypeCaseBuilder().setTypes(Lists.<Types>newArrayList(new TypesBuilder().setValue((short) 22).setOp(new NumericOperand(true, true, true, true, true)).build())).build());
- assertEquals(expected.build(), FSNlriParser.extractFlowspec(entry.build()));
+ assertEquals(expected.build(), FS_PARSER.extractFlowspec(entry.build()));
}
@Test
public void testExtractFlowspecSourceCodes() {
final DataContainerNodeAttrBuilder<NodeIdentifierWithPredicates, MapEntryNode> entry = Builders.mapEntryBuilder();
entry.withNodeIdentifier(new NodeIdentifierWithPredicates(Flowspec.QNAME, Flowspec.QNAME, entry));
- entry.withChild(Builders.leafBuilder().withNodeIdentifier(FSNlriParser.COMPONENT_TYPE_NID).withValue("codes").build());
entry.withChild(Builders.choiceBuilder().withNodeIdentifier(new NodeIdentifier(FlowspecType.QNAME))
- .withChild(Builders.unkeyedListBuilder().withNodeIdentifier(FSNlriParser.ICMP_CODE_NID)
- .withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(FSNlriParser.OP_NID)
- .withChild(Builders.leafBuilder().withNodeIdentifier(FSNlriParser.OP_NID).withValue(Sets.<String>newHashSet()).build())
- .withChild(Builders.leafBuilder().withNodeIdentifier(FSNlriParser.VALUE_NID).withValue((short) 23).build()).build())
+ .withChild(Builders.unkeyedListBuilder().withNodeIdentifier(FSIpv4NlriParser.ICMP_CODE_NID)
+ .withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(FSIpv4NlriParser.OP_NID)
+ .withChild(Builders.leafBuilder().withNodeIdentifier(FSIpv4NlriParser.OP_NID).withValue(Sets.<String>newHashSet()).build())
+ .withChild(Builders.leafBuilder().withNodeIdentifier(FSIpv4NlriParser.VALUE_NID).withValue((short) 23).build()).build())
.build()).build()).build();
final FlowspecBuilder expected = new FlowspecBuilder();
expected.setFlowspecType(new IcmpCodeCaseBuilder().setCodes(Lists.<Codes>newArrayList(new CodesBuilder().setValue((short) 23).setOp(new NumericOperand(false, false, false, false, false)).build())).build());
- assertEquals(expected.build(), FSNlriParser.extractFlowspec(entry.build()));
+ assertEquals(expected.build(), FS_PARSER.extractFlowspec(entry.build()));
}
@Test
public void testExtractFlowspecSourceTcpFlags() {
final DataContainerNodeAttrBuilder<NodeIdentifierWithPredicates, MapEntryNode> entry = Builders.mapEntryBuilder();
entry.withNodeIdentifier(new NodeIdentifierWithPredicates(Flowspec.QNAME, Flowspec.QNAME, entry));
- entry.withChild(Builders.leafBuilder().withNodeIdentifier(FSNlriParser.COMPONENT_TYPE_NID).withValue("tcp-flags").build());
entry.withChild(Builders.choiceBuilder().withNodeIdentifier(new NodeIdentifier(FlowspecType.QNAME))
- .withChild(Builders.unkeyedListBuilder().withNodeIdentifier(FSNlriParser.TCP_FLAGS_NID)
- .withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(FSNlriParser.OP_NID)
- .withChild(Builders.leafBuilder().withNodeIdentifier(FSNlriParser.OP_NID).withValue(Sets.<String>newHashSet(FSNlriParser.AND_BIT_VALUE, FSNlriParser.END_OF_LIST_VALUE)).build())
- .withChild(Builders.leafBuilder().withNodeIdentifier(FSNlriParser.VALUE_NID).withValue(99).build()).build())
+ .withChild(Builders.unkeyedListBuilder().withNodeIdentifier(FSIpv4NlriParser.TCP_FLAGS_NID)
+ .withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(FSIpv4NlriParser.OP_NID)
+ .withChild(Builders.leafBuilder().withNodeIdentifier(FSIpv4NlriParser.OP_NID).withValue(Sets.<String>newHashSet(FSIpv4NlriParser.AND_BIT_VALUE, FSIpv4NlriParser.END_OF_LIST_VALUE)).build())
+ .withChild(Builders.leafBuilder().withNodeIdentifier(FSIpv4NlriParser.VALUE_NID).withValue(99).build()).build())
.build()).build()).build();
final FlowspecBuilder expected = new FlowspecBuilder();
- expected.setComponentType(ComponentType.TcpFlags).setFlowspecType(new TcpFlagsCaseBuilder().setTcpFlags(Lists.<TcpFlags>newArrayList(new TcpFlagsBuilder().setValue(99).setOp(new BitmaskOperand(true, true, false, false)).build())).build());
- assertEquals(expected.build(), FSNlriParser.extractFlowspec(entry.build()));
+ expected.setFlowspecType(new TcpFlagsCaseBuilder().setTcpFlags(Lists.<TcpFlags>newArrayList(new TcpFlagsBuilder().setValue(99).setOp(new BitmaskOperand(true, true, false, false)).build())).build());
+ assertEquals(expected.build(), FS_PARSER.extractFlowspec(entry.build()));
}
@Test
public void testExtractFlowspecPacketLengths() {
final DataContainerNodeAttrBuilder<NodeIdentifierWithPredicates, MapEntryNode> entry = Builders.mapEntryBuilder();
entry.withNodeIdentifier(new NodeIdentifierWithPredicates(Flowspec.QNAME, Flowspec.QNAME, entry));
- entry.withChild(Builders.leafBuilder().withNodeIdentifier(FSNlriParser.COMPONENT_TYPE_NID).withValue("packet-lengths").build());
entry.withChild(Builders.choiceBuilder().withNodeIdentifier(new NodeIdentifier(FlowspecType.QNAME))
- .withChild(Builders.unkeyedListBuilder().withNodeIdentifier(FSNlriParser.PACKET_LENGTHS_NID)
- .withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(FSNlriParser.OP_NID)
- .withChild(Builders.leafBuilder().withNodeIdentifier(FSNlriParser.OP_NID).withValue(Sets.<String>newHashSet(FSNlriParser.AND_BIT_VALUE, FSNlriParser.GREATER_THAN_VALUE)).build())
- .withChild(Builders.leafBuilder().withNodeIdentifier(FSNlriParser.VALUE_NID).withValue(101).build()).build())
+ .withChild(Builders.unkeyedListBuilder().withNodeIdentifier(FSIpv4NlriParser.PACKET_LENGTHS_NID)
+ .withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(FSIpv4NlriParser.OP_NID)
+ .withChild(Builders.leafBuilder().withNodeIdentifier(FSIpv4NlriParser.OP_NID).withValue(Sets.<String>newHashSet(FSIpv4NlriParser.AND_BIT_VALUE, FSIpv4NlriParser.GREATER_THAN_VALUE)).build())
+ .withChild(Builders.leafBuilder().withNodeIdentifier(FSIpv4NlriParser.VALUE_NID).withValue(101).build()).build())
.build()).build()).build();
final FlowspecBuilder expected = new FlowspecBuilder();
expected.setFlowspecType(new PacketLengthCaseBuilder().setPacketLengths(Lists.<PacketLengths>newArrayList(new PacketLengthsBuilder().setValue(101).setOp(new NumericOperand(true, false, false, true, false)).build())).build());
- assertEquals(expected.build(), FSNlriParser.extractFlowspec(entry.build()));
+ assertEquals(expected.build(), FS_PARSER.extractFlowspec(entry.build()));
}
@Test
public void testExtractFlowspecDscps() {
final DataContainerNodeAttrBuilder<NodeIdentifierWithPredicates, MapEntryNode> entry = Builders.mapEntryBuilder();
entry.withNodeIdentifier(new NodeIdentifierWithPredicates(Flowspec.QNAME, Flowspec.QNAME, entry));
- entry.withChild(Builders.leafBuilder().withNodeIdentifier(FSNlriParser.COMPONENT_TYPE_NID).withValue("packet-lengths").build());
entry.withChild(Builders.choiceBuilder().withNodeIdentifier(new NodeIdentifier(FlowspecType.QNAME))
- .withChild(Builders.unkeyedListBuilder().withNodeIdentifier(FSNlriParser.DSCP_NID)
- .withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(FSNlriParser.OP_NID)
- .withChild(Builders.leafBuilder().withNodeIdentifier(FSNlriParser.OP_NID).withValue(Sets.<String>newHashSet(FSNlriParser.AND_BIT_VALUE, FSNlriParser.END_OF_LIST_VALUE, FSNlriParser.GREATER_THAN_VALUE)).build())
- .withChild(Builders.leafBuilder().withNodeIdentifier(FSNlriParser.VALUE_NID).withValue((short)15).build()).build())
+ .withChild(Builders.unkeyedListBuilder().withNodeIdentifier(FSIpv4NlriParser.DSCP_NID)
+ .withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(FSIpv4NlriParser.OP_NID)
+ .withChild(Builders.leafBuilder().withNodeIdentifier(FSIpv4NlriParser.OP_NID).withValue(Sets.<String>newHashSet(FSIpv4NlriParser.AND_BIT_VALUE, FSIpv4NlriParser.END_OF_LIST_VALUE, FSIpv4NlriParser.GREATER_THAN_VALUE)).build())
+ .withChild(Builders.leafBuilder().withNodeIdentifier(FSIpv4NlriParser.VALUE_NID).withValue((short)15).build()).build())
.build()).build()).build();
final FlowspecBuilder expected = new FlowspecBuilder();
expected.setFlowspecType(new DscpCaseBuilder().setDscps(Lists.<Dscps>newArrayList(new DscpsBuilder().setValue(new Dscp((short)15)).setOp(new NumericOperand(true, true, false, true, false)).build())).build());
- assertEquals(expected.build(), FSNlriParser.extractFlowspec(entry.build()));
+ assertEquals(expected.build(), FS_PARSER.extractFlowspec(entry.build()));
}
@Test
public void testExtractFlowspecFragments() {
final DataContainerNodeAttrBuilder<NodeIdentifierWithPredicates, MapEntryNode> entry = Builders.mapEntryBuilder();
entry.withNodeIdentifier(new NodeIdentifierWithPredicates(Flowspec.QNAME, Flowspec.QNAME, entry));
- entry.withChild(Builders.leafBuilder().withNodeIdentifier(FSNlriParser.COMPONENT_TYPE_NID).withValue("packet-lengths").build());
entry.withChild(Builders.choiceBuilder().withNodeIdentifier(new NodeIdentifier(FlowspecType.QNAME))
- .withChild(Builders.unkeyedListBuilder().withNodeIdentifier(FSNlriParser.FRAGMENT_NID)
- .withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(FSNlriParser.OP_NID)
- .withChild(Builders.leafBuilder().withNodeIdentifier(FSNlriParser.OP_NID).withValue(Sets.<String>newHashSet(FSNlriParser.AND_BIT_VALUE, FSNlriParser.END_OF_LIST_VALUE, FSNlriParser.MATCH_VALUE, FSNlriParser.NOT_VALUE)).build())
- .withChild(Builders.leafBuilder().withNodeIdentifier(FSNlriParser.VALUE_NID).withValue(Sets.newHashSet(FSNlriParser.DO_NOT_VALUE, FSNlriParser.FIRST_VALUE, FSNlriParser.IS_A_VALUE, FSNlriParser.LAST_VALUE)).build()).build())
+ .withChild(Builders.unkeyedListBuilder().withNodeIdentifier(FSIpv4NlriParser.FRAGMENT_NID)
+ .withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(FSIpv4NlriParser.OP_NID)
+ .withChild(Builders.leafBuilder().withNodeIdentifier(FSIpv4NlriParser.OP_NID).withValue(Sets.<String>newHashSet(FSIpv4NlriParser.AND_BIT_VALUE, FSIpv4NlriParser.END_OF_LIST_VALUE, FSIpv4NlriParser.MATCH_VALUE, FSIpv4NlriParser.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())
.build()).build()).build();
final FlowspecBuilder expected = new FlowspecBuilder();
expected.setFlowspecType(new FragmentCaseBuilder().setFragments(Lists.<Fragments>newArrayList(new FragmentsBuilder().setValue(new Fragment(true, true, true, true)).setOp(new BitmaskOperand(true, true, true, true)).build())).build());
- assertEquals(expected.build(), FSNlriParser.extractFlowspec(entry.build()));
+ assertEquals(expected.build(), FS_PARSER.extractFlowspec(entry.build()));
}
}
--- /dev/null
+/*
+ * 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 static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Sets;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import java.util.ArrayList;
+import java.util.List;
+import org.junit.Test;
+import org.opendaylight.protocol.bgp.parser.BGPParsingException;
+import org.opendaylight.protocol.util.ByteArray;
+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.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.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.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;
+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;
+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.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.SourceIpv6PrefixCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.ipv6.flowspec.flowspec.type.SourceIpv6PrefixCaseBuilder;
+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.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.reach.nlri.advertized.routes.destination.type.DestinationFlowspecIpv6Case;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationFlowspecIpv6CaseBuilder;
+import 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;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.AttributesBuilder;
+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.Attributes1Builder;
+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.Attributes2Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.MpReachNlriBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.MpUnreachNlriBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.mp.reach.nlri.AdvertizedRoutesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.mp.unreach.nlri.WithdrawnRoutesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv6AddressFamily;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
+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 {
+
+ private static final FSIpv6NlriParser FS_PARSER = new FSIpv6NlriParser();
+
+ 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 };
+
+ private static final byte[] UNREACHED_NLRI = new byte[] { 0x0c,
+ 0x0c, (byte) 0x81, 0x0e,
+ 0x0d, (byte) 0x21, 1, 0, 0, 6, (byte) 0x91, 1, 2 };
+
+ @Test
+ public void testParseMpReachNlri() throws BGPParsingException {
+ final List<Flowspec> fs = new ArrayList<>();
+ final MpReachNlriBuilder mp = new MpReachNlriBuilder();
+
+ final FlowspecBuilder builder = new FlowspecBuilder();
+ 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());
+
+ final List<NextHeaders> nextheaders = Lists.newArrayList(new NextHeadersBuilder().setOp(new NumericOperand(false, true, true, false, false)).setValue((short) 6).build());
+ final NextHeaderCase headersCase = new NextHeaderCaseBuilder().setNextHeaders(nextheaders).build();
+ builder.setFlowspecType(headersCase);
+ fs.add(builder.build());
+
+
+ mp.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(new DestinationFlowspecIpv6CaseBuilder().setDestinationFlowspec(new DestinationFlowspecBuilder().setFlowspec(fs).build()).build()).build());
+
+ final MpReachNlriBuilder result = new MpReachNlriBuilder();
+ result.setAfi(Ipv6AddressFamily.class);
+ FS_PARSER.parseNlri(Unpooled.wrappedBuffer(REACHED_NLRI), result);
+
+ final List<Flowspec> flows = ((DestinationFlowspecIpv6Case) (result.getAdvertizedRoutes().getDestinationType())).getDestinationFlowspec().getFlowspec();
+ assertEquals(3, flows.size());
+ assertEquals(destinationPrefix, flows.get(0).getFlowspecType());
+ assertEquals(sourcePrefix, flows.get(1).getFlowspecType());
+ assertEquals(headersCase, flows.get(2).getFlowspecType());
+
+ final ByteBuf buffer = Unpooled.buffer();
+ FS_PARSER.serializeAttribute(new AttributesBuilder().addAugmentation(Attributes1.class, new Attributes1Builder().setMpReachNlri(mp.setAfi(Ipv6AddressFamily.class).build()).build()).build(), buffer);
+ assertArrayEquals(REACHED_NLRI, ByteArray.readAllBytes(buffer));
+
+ assertEquals("all packets to 102:304:500::/40", FS_PARSER.stringNlri(flows.get(0)));
+ assertEquals("all packets from 102:304:600::/40", FS_PARSER.stringNlri(flows.get(1)));
+ assertEquals("all packets where next header equals to 6 ", FS_PARSER.stringNlri(flows.get(2)));
+ }
+
+ @Test
+ public void testParseMpUnreachNlri() throws BGPParsingException {
+ final List<Flowspec> fs = new ArrayList<>();
+ final MpUnreachNlriBuilder mp = new MpUnreachNlriBuilder();
+
+ final FlowspecBuilder builder = new FlowspecBuilder();
+
+ final List<Fragments> fragments = Lists.newArrayList(new FragmentsBuilder().setOp(new BitmaskOperand(false, true, true, false)).setValue(new Fragment(false, true, true, true)).build());
+ final FragmentCase fragment = new FragmentCaseBuilder().setFragments(fragments).build();
+ builder.setFlowspecType(fragment);
+ fs.add(builder.build());
+
+ final List<FlowLabel> labels = Lists.newArrayList();
+ labels.add(new FlowLabelBuilder().setOp(new NumericOperand(false, false, true, false, false)).setValue(new Long(16777222L)).build());
+ labels.add(new FlowLabelBuilder().setOp(new NumericOperand(false, true, true, false, false)).setValue(new Long(258L)).build());
+ final FlowLabelCase label = new FlowLabelCaseBuilder().setFlowLabel(labels).build();
+ builder.setFlowspecType(label);
+ fs.add(builder.build());
+
+ mp.setAfi(Ipv6AddressFamily.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.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(fs).build()).build()).build());
+
+ final MpUnreachNlriBuilder result = new MpUnreachNlriBuilder();
+ result.setAfi(Ipv6AddressFamily.class);
+ FS_PARSER.parseNlri(Unpooled.wrappedBuffer(UNREACHED_NLRI), result);
+
+ final List<Flowspec> flows = ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationFlowspecIpv6Case) (result.getWithdrawnRoutes().getDestinationType())).getDestinationFlowspec().getFlowspec();
+ assertEquals(2, flows.size());
+ assertEquals(fragment, flows.get(0).getFlowspecType());
+ assertEquals(label, flows.get(1).getFlowspecType());
+
+ final ByteBuf buffer = Unpooled.buffer();
+ FS_PARSER.serializeAttribute(new AttributesBuilder().addAugmentation(Attributes2.class, new Attributes2Builder().setMpUnreachNlri(mp.build()).build()).build(), buffer);
+
+ assertArrayEquals(UNREACHED_NLRI, ByteArray.readAllBytes(buffer));
+
+ assertEquals("all packets where fragment does match 'IS FIRST' 'IS LAST' 'IS A' ", FS_PARSER.stringNlri(flows.get(0)));
+ assertEquals("all packets where flow label equals to 16777222 or equals to 258 ", FS_PARSER.stringNlri(flows.get(1)));
+ }
+
+ @Test
+ public void testExtractFlowspecFragments() {
+ final DataContainerNodeAttrBuilder<NodeIdentifierWithPredicates, MapEntryNode> entry = Builders.mapEntryBuilder();
+ entry.withNodeIdentifier(new NodeIdentifierWithPredicates(Flowspec.QNAME, Flowspec.QNAME, entry));
+ entry.withChild(Builders.choiceBuilder().withNodeIdentifier(new NodeIdentifier(FlowspecType.QNAME))
+ .withChild(Builders.unkeyedListBuilder().withNodeIdentifier(FSIpv6NlriParser.FRAGMENT_NID)
+ .withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(FSIpv6NlriParser.OP_NID)
+ .withChild(Builders.leafBuilder().withNodeIdentifier(FSIpv6NlriParser.OP_NID).withValue(Sets.<String>newHashSet(FSIpv6NlriParser.AND_BIT_VALUE, FSIpv6NlriParser.END_OF_LIST_VALUE, FSIpv6NlriParser.MATCH_VALUE, FSIpv6NlriParser.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())
+ .build()).build()).build();
+ final FlowspecBuilder expected = new FlowspecBuilder();
+ expected.setFlowspecType(new FragmentCaseBuilder().setFragments(Lists.<Fragments>newArrayList(new FragmentsBuilder().setValue(new Fragment(true, true, true, true)).setOp(new BitmaskOperand(true, true, true, true)).build())).build());
+ assertEquals(expected.build(), FS_PARSER.extractFlowspec(entry.build()));
+ }
+
+ @Test
+ public void testExtractFlowspecNextHeaders() {
+ final DataContainerNodeAttrBuilder<NodeIdentifierWithPredicates, MapEntryNode> entry = Builders.mapEntryBuilder();
+ entry.withNodeIdentifier(new NodeIdentifierWithPredicates(Flowspec.QNAME, Flowspec.QNAME, entry));
+ entry.withChild(Builders.choiceBuilder().withNodeIdentifier(new NodeIdentifier(FlowspecType.QNAME))
+ .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.<String>newHashSet(FSIpv4NlriParser.END_OF_LIST_VALUE, FSIpv4NlriParser.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.<String>newHashSet(FSIpv4NlriParser.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.<String>newHashSet(FSIpv4NlriParser.END_OF_LIST_VALUE, FSIpv4NlriParser.AND_BIT_VALUE, FSIpv4NlriParser.EQUALS_VALUE)).build())
+ .withChild(Builders.leafBuilder().withNodeIdentifier(FSIpv6NlriParser.VALUE_NID).withValue((short) 210).build()).build())
+ .build()).build());
+
+ final FlowspecBuilder expected = new FlowspecBuilder();
+ expected.setFlowspecType(new NextHeaderCaseBuilder().setNextHeaders(Lists.<NextHeaders>newArrayList(
+ new NextHeadersBuilder().setValue((short) 100).setOp(new NumericOperand(true, true, false, false, false)).build(),
+ new NextHeadersBuilder().setValue((short) 200).setOp(new NumericOperand(true, false, false, false, false)).build(),
+ new NextHeadersBuilder().setValue((short) 210).setOp(new NumericOperand(true, true, true, false, false)).build())).build());
+ assertEquals(expected.build(), FS_PARSER.extractFlowspec(entry.build()));
+ }
+
+ @Test
+ public void testExtractFlowspecFlowLabels() {
+ final DataContainerNodeAttrBuilder<NodeIdentifierWithPredicates, MapEntryNode> entry = Builders.mapEntryBuilder();
+ entry.withNodeIdentifier(new NodeIdentifierWithPredicates(Flowspec.QNAME, Flowspec.QNAME, entry));
+ entry.withChild(Builders.choiceBuilder().withNodeIdentifier(new NodeIdentifier(FlowspecType.QNAME))
+ .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.<String>newHashSet(FSIpv4NlriParser.END_OF_LIST_VALUE, FSIpv4NlriParser.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.<String>newHashSet(FSIpv4NlriParser.AND_BIT_VALUE)).build())
+ .withChild(Builders.leafBuilder().withNodeIdentifier(FSIpv6NlriParser.VALUE_NID).withValue(200L).build()).build())
+ .build()).build());
+
+ final FlowspecBuilder expected = new FlowspecBuilder();
+ expected.setFlowspecType(new FlowLabelCaseBuilder().setFlowLabel(Lists.<FlowLabel>newArrayList(
+ new FlowLabelBuilder().setValue(100L).setOp(new NumericOperand(true, true, false, false, false)).build(),
+ new FlowLabelBuilder().setValue(200L).setOp(new NumericOperand(true, false, false, false, false)).build())).build());
+ assertEquals(expected.build(), FS_PARSER.extractFlowspec(entry.build()));
+ }
+
+ @Test
+ public void testExtractFlowspecDestPrefix() {
+ final DataContainerNodeAttrBuilder<NodeIdentifierWithPredicates, MapEntryNode> entry = Builders.mapEntryBuilder();
+ entry.withNodeIdentifier(new NodeIdentifierWithPredicates(Flowspec.QNAME, Flowspec.QNAME, entry));
+ entry.withChild(Builders.choiceBuilder().withNodeIdentifier(new NodeIdentifier(FlowspecType.QNAME))
+ .withChild(Builders.leafBuilder().withNodeIdentifier(FSIpv6NlriParser.DEST_PREFIX_NID).withValue("102:304:500::/40").build()).build());
+ final FlowspecBuilder expected = new FlowspecBuilder();
+ expected.setFlowspecType(new DestinationIpv6PrefixCaseBuilder().setDestinationPrefix(new Ipv6Prefix("102:304:500::/40")).build());
+ assertEquals(expected.build(), FS_PARSER.extractFlowspec(entry.build()));
+ }
+
+ @Test
+ public void testExtractFlowspecSourcePrefix() {
+ final DataContainerNodeAttrBuilder<NodeIdentifierWithPredicates, MapEntryNode> entry = Builders.mapEntryBuilder();
+ entry.withNodeIdentifier(new NodeIdentifierWithPredicates(Flowspec.QNAME, Flowspec.QNAME, entry));
+ entry.withChild(Builders.choiceBuilder().withNodeIdentifier(new NodeIdentifier(FlowspecType.QNAME))
+ .withChild(Builders.leafBuilder().withNodeIdentifier(FSIpv4NlriParser.SOURCE_PREFIX_NID).withValue("102:304:600::/40").build()).build());
+ final FlowspecBuilder expected = new FlowspecBuilder();
+ expected.setFlowspecType(new SourceIpv6PrefixCaseBuilder().setSourcePrefix(new Ipv6Prefix("102:304:600::/40")).build());
+ assertEquals(expected.build(), FS_PARSER.extractFlowspec(entry.build()));
+ }
+}
/**
* Maximum unsigned Integer value (2147483648);
*/
- public static final long UNSIGNED_INT_MAX_VALUE = Integer.MAX_VALUE + 1;
+ public static final long UNSIGNED_INT_MAX_VALUE = (long) Integer.MAX_VALUE + 1;
/**
* Maximum unsigned Byte value in hex (0xFF).